DEV: Switch theme to use new addComposerToolbarPopupMenuOption api (#61)

Why this change?

The new API is better and allows us to avoid modifying the composer
service.
This commit is contained in:
Alan Guo Xiang Tan
2023-10-06 09:20:09 +08:00
committed by GitHub
parent 566d79fa39
commit d59dc7caf4
3 changed files with 28 additions and 24 deletions
@@ -5,7 +5,7 @@ export default {
name: "disco-toc-composer",
initialize() {
withPluginApi("1.0.0", (api) => {
withPluginApi("1.14.0", (api) => {
const currentUser = api.getCurrentUser();
if (!currentUser) {
return;
@@ -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"),
};
});
}
});