0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-10-18 20:02:38 +02:00

COMPATIBILITY: Convert actions in wizard composer editor

Dieser Commit ist enthalten in:
Angus McLeod 2024-10-09 10:15:13 +02:00
Ursprung c1db1442b7
Commit b78f3aad09
2 geänderte Dateien mit 73 neuen und 69 gelöschten Zeilen

Datei anzeigen

@ -14,6 +14,7 @@ import { uploadIcon } from "discourse/lib/uploads";
import { dasherize } from "@ember/string"; import { dasherize } from "@ember/string";
import InsertHyperlink from "discourse/components/modal/insert-hyperlink"; import InsertHyperlink from "discourse/components/modal/insert-hyperlink";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import { action } from "@ember/object";
const IMAGE_MARKDOWN_REGEX = const IMAGE_MARKDOWN_REGEX =
/!\[(.*?)\|(\d{1,4}x\d{1,4})(,\s*\d{1,3}%)?(.*?)\]\((upload:\/\/.*?)\)(?!(.*`))/g; /!\[(.*?)\|(\d{1,4}x\d{1,4})(,\s*\d{1,3}%)?(.*?)\]\((upload:\/\/.*?)\)(?!(.*`))/g;
@ -119,82 +120,85 @@ export default ComposerEditor.extend({
); );
}, },
actions: { @action
extraButtons(toolbar) { extraButtons(toolbar) {
const component = this; const component = this;
if (this.allowUpload && this.uploadIcon) { if (this.allowUpload && this.uploadIcon) {
toolbar.addButton({ toolbar.addButton({
id: "upload", id: "upload",
group: "insertions", group: "insertions",
icon: this.uploadIcon, icon: this.uploadIcon,
title: "upload", title: "upload",
sendAction: (event) => component.send("showUploadModal", event), sendAction: (event) => component.send("showUploadModal", event),
}); });
} }
toolbar.addButton({
id: "link",
icon: "link",
group: "insertions",
shortcut: "K",
trimLeading: true,
unshift: true,
sendAction: (event) => component.send("showLinkModal", event),
});
if (this.siteSettings.mentionables_enabled) {
const { SEPARATOR } = requirejs(
"discourse/plugins/discourse-mentionables/discourse/lib/discourse-markdown/mentionable-items"
);
toolbar.addButton({ toolbar.addButton({
id: "link", id: "insert-mentionable",
group: "insertions", group: "extras",
shortcut: "K", icon: this.siteSettings.mentionables_composer_button_icon,
trimLeading: true, title: "mentionables.composer.insert.title",
unshift: true, perform: () => {
sendAction: (event) => component.send("showLinkModal", event), this.appEvents.trigger("wizard-editor:insert-text", {
fieldId: this.field.id,
text: SEPARATOR,
});
const $textarea = $(
document.querySelector(
`.composer-field.${this.field.id} textarea.d-editor-input`
)
);
$textarea.trigger("keyup.autocomplete");
},
}); });
}
},
if (this.siteSettings.mentionables_enabled) { @action
const { SEPARATOR } = requirejs( previewUpdated(preview) {
"discourse/plugins/discourse-mentionables/discourse/lib/discourse-markdown/mentionable-items" highlightSyntax(preview, this.siteSettings, this.session);
);
toolbar.addButton({ if (this.siteSettings.mentionables_enabled) {
id: "insert-mentionable", const { linkSeenMentionableItems } = requirejs(
group: "extras", "discourse/plugins/discourse-mentionables/discourse/lib/mentionable-items-preview-styling"
icon: this.siteSettings.mentionables_composer_button_icon, );
title: "mentionables.composer.insert.title", linkSeenMentionableItems(preview, this.siteSettings);
perform: () => { }
this.appEvents.trigger("wizard-editor:insert-text", { this._super(...arguments);
fieldId: this.field.id, },
text: SEPARATOR,
});
const $textarea = $(
document.querySelector(
`.composer-field.${this.field.id} textarea.d-editor-input`
)
);
$textarea.trigger("keyup.autocomplete");
},
});
}
},
previewUpdated(preview) { @action
highlightSyntax(preview, this.siteSettings, this.session); showLinkModal(toolbarEvent) {
let linkText = "";
this._lastSel = toolbarEvent.selected;
if (this.siteSettings.mentionables_enabled) { if (this._lastSel) {
const { linkSeenMentionableItems } = requirejs( linkText = this._lastSel.value;
"discourse/plugins/discourse-mentionables/discourse/lib/mentionable-items-preview-styling" }
); this.modal.show(InsertHyperlink, {
linkSeenMentionableItems(preview, this.siteSettings); model: { linkText, toolbarEvent },
} });
this._super(...arguments); },
},
showLinkModal(toolbarEvent) { @action
let linkText = ""; showUploadModal() {
this._lastSel = toolbarEvent.selected; this.session.set("wizardEventFieldId", this.field.id);
document.getElementById(this.fileUploadElementId).click();
if (this._lastSel) {
linkText = this._lastSel.value;
}
this.modal.show(InsertHyperlink, {
model: { linkText, toolbarEvent },
});
},
showUploadModal() {
this.session.set("wizardEventFieldId", this.field.id);
document.getElementById(this.fileUploadElementId).click();
},
}, },
}); });

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# name: discourse-custom-wizard # name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.8.6 # version: 2.8.7
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos
# url: https://github.com/paviliondev/discourse-custom-wizard # url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech # contact_emails: development@pavilion.tech