DEV: Switch to new addComposerToolbarPopupMenuOption plugin API (#65)

Why this change?

`api.addToolbarPopupMenuOptionsCallback` has been deprecated in 913fd3a7b3
This commit is contained in:
Alan Guo Xiang Tan 2023-10-23 08:09:06 +08:00 committed by GitHub
parent 0f2a0e73e6
commit f2f309b552
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 22 deletions

View File

@ -1,3 +1,4 @@
< 3.2.0.beta2: 0f2a0e73e6c2924f2b44d3241931f2bd5f77a9ae
3.1.999: 323bd485b08889360edcae826d6272fd8e77d180
2.7.13: 5b2f5a455e1adf8ce5e8c1cfb7fbc3c388d3d82a
2.6.0.beta3: 68d40fe9f5b625cf465adc31b502a54e16d02cc6

View File

@ -19,27 +19,19 @@ export default {
}
I18n.translations[I18n.currentLocale()].js.composer.contains_dtoc = " ";
api.modifyClass("controller:composer", {
pluginId: "DiscoTOC",
actions: {
insertDtoc() {
this.get("toolbarEvent").applySurround(
`<div data-theme-toc="true">`,
`</div>`,
"contains_dtoc"
);
},
api.addComposerToolbarPopupMenuOption({
action: (toolbarEvent) => {
toolbarEvent.applySurround(
`<div data-theme-toc="true">`,
`</div>`,
"contains_dtoc"
);
},
icon: "align-left",
label: themePrefix("insert_table_of_contents"),
condition: (composer) => {
return composer.model.topicFirstPost;
},
});
api.addToolbarPopupMenuOptionsCallback((controller) => {
return {
action: "insertDtoc",
icon: "align-left",
label: themePrefix("insert_table_of_contents"),
condition: controller.get("model.topicFirstPost"),
};
});
}
});

View File

@ -1,3 +1,4 @@
import I18n from "discourse-i18n";
import {
acceptance,
exists,
@ -19,7 +20,9 @@ acceptance("DiscoTOC - Composer", function (needs) {
await click("#create-topic");
const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options");
await toolbarPopupMenu.expand();
await toolbarPopupMenu.selectRowByValue("insertDtoc");
await toolbarPopupMenu.selectRowByName(
I18n.t(themePrefix("insert_table_of_contents"))
);
assert.ok(query(".d-editor-input").value.includes('data-theme-toc="true"'));
});
@ -33,7 +36,9 @@ acceptance("DiscoTOC - Composer", function (needs) {
const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options");
await toolbarPopupMenu.expand();
await toolbarPopupMenu.selectRowByValue("insertDtoc");
await toolbarPopupMenu.selectRowByName(
I18n.t(themePrefix("insert_table_of_contents"))
);
assert.ok(query(".d-editor-input").value.includes('data-theme-toc="true"'));
});