DEV: Use composerEventPrefix for paste in textarea-text-manipulation (#16262)
In the commit d678ba1103
we added
gif parsing support on paste, but we also slightly changed the
isComposer check there, along with a change in chat this caused
isComposer to be true (which is correct), however the event we fire
is composer:insert-text which the chat composer does not pick up.
Instead, we should use composerEventPrefix if it is present to
fire the insert-text event, and if it is not present (e.g. for
some custom composer that someone has implemented) fall back to
the default. There is a companion commit for chat to handle this
change there.
This commit is contained in:
parent
99a6f32554
commit
1341baaeba
|
@ -103,7 +103,10 @@ export default Component.extend(ComposerUploadUppy, {
|
||||||
editorClass: ".d-editor",
|
editorClass: ".d-editor",
|
||||||
fileUploadElementId: "file-uploader",
|
fileUploadElementId: "file-uploader",
|
||||||
mobileFileUploaderId: "mobile-file-upload",
|
mobileFileUploaderId: "mobile-file-upload",
|
||||||
|
|
||||||
|
// TODO (martin) Remove this once the chat plugin is using the new composerEventPrefix
|
||||||
eventPrefix: "composer",
|
eventPrefix: "composer",
|
||||||
|
composerEventPrefix: "composer",
|
||||||
uploadType: "composer",
|
uploadType: "composer",
|
||||||
uppyId: "composer-editor-uppy",
|
uppyId: "composer-editor-uppy",
|
||||||
composerModel: alias("composer"),
|
composerModel: alias("composer"),
|
||||||
|
|
|
@ -67,9 +67,9 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
|
|
||||||
this.editorEl?.removeEventListener("paste", this.pasteEventListener);
|
this.editorEl?.removeEventListener("paste", this.pasteEventListener);
|
||||||
|
|
||||||
this.appEvents.off(`${this.eventPrefix}:add-files`, this._addFiles);
|
this.appEvents.off(`${this.composerEventPrefix}:add-files`, this._addFiles);
|
||||||
this.appEvents.off(
|
this.appEvents.off(
|
||||||
`${this.eventPrefix}:cancel-upload`,
|
`${this.composerEventPrefix}:cancel-upload`,
|
||||||
this._cancelSingleUpload
|
this._cancelSingleUpload
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
},
|
},
|
||||||
|
|
||||||
_abortAndReset() {
|
_abortAndReset() {
|
||||||
this.appEvents.trigger(`${this.eventPrefix}:uploads-aborted`);
|
this.appEvents.trigger(`${this.composerEventPrefix}:uploads-aborted`);
|
||||||
this._reset();
|
this._reset();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
@ -97,9 +97,9 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
this.fileInputEl = document.getElementById(this.fileUploadElementId);
|
this.fileInputEl = document.getElementById(this.fileUploadElementId);
|
||||||
const isPrivateMessage = this.get("composerModel.privateMessage");
|
const isPrivateMessage = this.get("composerModel.privateMessage");
|
||||||
|
|
||||||
this.appEvents.on(`${this.eventPrefix}:add-files`, this._addFiles);
|
this.appEvents.on(`${this.composerEventPrefix}:add-files`, this._addFiles);
|
||||||
this.appEvents.on(
|
this.appEvents.on(
|
||||||
`${this.eventPrefix}:cancel-upload`,
|
`${this.composerEventPrefix}:cancel-upload`,
|
||||||
this._cancelSingleUpload
|
this._cancelSingleUpload
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isUploading) {
|
if (!isUploading) {
|
||||||
this.appEvents.trigger(`${this.eventPrefix}:uploads-aborted`);
|
this.appEvents.trigger(`${this.composerEventPrefix}:uploads-aborted`);
|
||||||
}
|
}
|
||||||
return isUploading;
|
return isUploading;
|
||||||
},
|
},
|
||||||
|
@ -290,11 +290,11 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
uploadPlaceholder: placeholder,
|
uploadPlaceholder: placeholder,
|
||||||
};
|
};
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:insert-text`,
|
`${this.composerEventPrefix}:insert-text`,
|
||||||
placeholder
|
placeholder
|
||||||
);
|
);
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:upload-started`,
|
`${this.composerEventPrefix}:upload-started`,
|
||||||
file.name
|
file.name
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -316,14 +316,14 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
cacheShortUploadUrl(upload.short_url, upload);
|
cacheShortUploadUrl(upload.short_url, upload);
|
||||||
|
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:replace-text`,
|
`${this.composerEventPrefix}:replace-text`,
|
||||||
this.placeholders[file.id].uploadPlaceholder.trim(),
|
this.placeholders[file.id].uploadPlaceholder.trim(),
|
||||||
markdown
|
markdown
|
||||||
);
|
);
|
||||||
|
|
||||||
this._resetUpload(file, { removePlaceholder: false });
|
this._resetUpload(file, { removePlaceholder: false });
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:upload-success`,
|
`${this.composerEventPrefix}:upload-success`,
|
||||||
file.name,
|
file.name,
|
||||||
upload
|
upload
|
||||||
);
|
);
|
||||||
|
@ -334,7 +334,9 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
|
|
||||||
this._uppyInstance.on("complete", () => {
|
this._uppyInstance.on("complete", () => {
|
||||||
run(() => {
|
run(() => {
|
||||||
this.appEvents.trigger(`${this.eventPrefix}:all-uploads-complete`);
|
this.appEvents.trigger(
|
||||||
|
`${this.composerEventPrefix}:all-uploads-complete`
|
||||||
|
);
|
||||||
this._reset();
|
this._reset();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -346,7 +348,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
Object.values(this.placeholders).forEach((data) => {
|
Object.values(this.placeholders).forEach((data) => {
|
||||||
run(() => {
|
run(() => {
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:replace-text`,
|
`${this.composerEventPrefix}:replace-text`,
|
||||||
data.uploadPlaceholder,
|
data.uploadPlaceholder,
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
|
@ -356,7 +358,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
this.set("userCancelled", false);
|
this.set("userCancelled", false);
|
||||||
this._reset();
|
this._reset();
|
||||||
|
|
||||||
this.appEvents.trigger(`${this.eventPrefix}:uploads-cancelled`);
|
this.appEvents.trigger(`${this.composerEventPrefix}:uploads-cancelled`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -381,7 +383,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
|
|
||||||
if (!this.userCancelled) {
|
if (!this.userCancelled) {
|
||||||
displayErrorForUpload(response || error, this.siteSettings, file.name);
|
displayErrorForUpload(response || error, this.siteSettings, file.name);
|
||||||
this.appEvents.trigger(`${this.eventPrefix}:upload-error`, file);
|
this.appEvents.trigger(`${this.composerEventPrefix}:upload-error`, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.inProgressUploads.length === 0) {
|
if (this.inProgressUploads.length === 0) {
|
||||||
|
@ -434,7 +436,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
)}]()\n`;
|
)}]()\n`;
|
||||||
|
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:replace-text`,
|
`${this.composerEventPrefix}:replace-text`,
|
||||||
placeholderData.uploadPlaceholder,
|
placeholderData.uploadPlaceholder,
|
||||||
placeholderData.processingPlaceholder
|
placeholderData.processingPlaceholder
|
||||||
);
|
);
|
||||||
|
@ -445,7 +447,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
run(() => {
|
run(() => {
|
||||||
let placeholderData = this.placeholders[file.id];
|
let placeholderData = this.placeholders[file.id];
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:replace-text`,
|
`${this.composerEventPrefix}:replace-text`,
|
||||||
placeholderData.processingPlaceholder,
|
placeholderData.processingPlaceholder,
|
||||||
placeholderData.uploadPlaceholder
|
placeholderData.uploadPlaceholder
|
||||||
);
|
);
|
||||||
|
@ -458,7 +460,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
isCancellable: true,
|
isCancellable: true,
|
||||||
});
|
});
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:uploads-preprocessing-complete`
|
`${this.composerEventPrefix}:uploads-preprocessing-complete`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -536,7 +538,7 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
_resetUpload(file, opts) {
|
_resetUpload(file, opts) {
|
||||||
if (opts.removePlaceholder) {
|
if (opts.removePlaceholder) {
|
||||||
this.appEvents.trigger(
|
this.appEvents.trigger(
|
||||||
`${this.eventPrefix}:replace-text`,
|
`${this.composerEventPrefix}:replace-text`,
|
||||||
this.placeholders[file.id].uploadPlaceholder,
|
this.placeholders[file.id].uploadPlaceholder,
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
|
|
|
@ -34,6 +34,13 @@ export function getHead(head, prev) {
|
||||||
export default Mixin.create({
|
export default Mixin.create({
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
|
// fallback in the off chance someone has implemented a custom composer
|
||||||
|
// which does not define this
|
||||||
|
if (!this.composerEventPrefix) {
|
||||||
|
this.composerEventPrefix = "composer";
|
||||||
|
}
|
||||||
|
|
||||||
generateLinkifyFunction(this.markdownOptions || {}).then((linkify) => {
|
generateLinkifyFunction(this.markdownOptions || {}).then((linkify) => {
|
||||||
// When pasting links, we should use the same rules to match links as we do when creating links for a cooked post.
|
// When pasting links, we should use the same rules to match links as we do when creating links for a cooked post.
|
||||||
this._cachedLinkify = linkify;
|
this._cachedLinkify = linkify;
|
||||||
|
@ -456,7 +463,10 @@ export default Mixin.create({
|
||||||
plainText = plainText.replace(/\r/g, "");
|
plainText = plainText.replace(/\r/g, "");
|
||||||
const table = this._extractTable(plainText);
|
const table = this._extractTable(plainText);
|
||||||
if (table) {
|
if (table) {
|
||||||
this.appEvents.trigger("composer:insert-text", table);
|
this.appEvents.trigger(
|
||||||
|
`${this.composerEventPrefix}:insert-text`,
|
||||||
|
table
|
||||||
|
);
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,7 +518,10 @@ export default Mixin.create({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isComposer) {
|
if (isComposer) {
|
||||||
this.appEvents.trigger("composer:insert-text", markdown);
|
this.appEvents.trigger(
|
||||||
|
`${this.composerEventPrefix}:insert-text`,
|
||||||
|
markdown
|
||||||
|
);
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue