mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Experimental JS plugin API for topic summary HTML (#20963)
This commit is contained in:
parent
a3801a9e16
commit
087ee8c5e2
@ -69,6 +69,7 @@ import { addQuickAccessProfileItem } from "discourse/widgets/quick-access-profil
|
|||||||
import { addTagsHtmlCallback } from "discourse/lib/render-tags";
|
import { addTagsHtmlCallback } from "discourse/lib/render-tags";
|
||||||
import { addToolbarCallback } from "discourse/components/d-editor";
|
import { addToolbarCallback } from "discourse/components/d-editor";
|
||||||
import { addTopicParticipantClassesCallback } from "discourse/widgets/topic-map";
|
import { addTopicParticipantClassesCallback } from "discourse/widgets/topic-map";
|
||||||
|
import { addTopicSummaryCallback } from "discourse/widgets/toggle-topic-summary";
|
||||||
import { addTopicTitleDecorator } from "discourse/components/topic-title";
|
import { addTopicTitleDecorator } from "discourse/components/topic-title";
|
||||||
import { addUserMenuGlyph } from "discourse/widgets/user-menu";
|
import { addUserMenuGlyph } from "discourse/widgets/user-menu";
|
||||||
import { addUsernameSelectorDecorator } from "discourse/helpers/decorate-username-selector";
|
import { addUsernameSelectorDecorator } from "discourse/helpers/decorate-username-selector";
|
||||||
@ -1022,6 +1023,28 @@ class PluginApi {
|
|||||||
addTopicParticipantClassesCallback(callback);
|
addTopicParticipantClassesCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EXPERIMENTAL. Do not use.
|
||||||
|
* Adds a callback to be topic summary widget markup that can be used, for example,
|
||||||
|
* to add an extra button to the topic summary widget.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* api.addTopicSummaryCallback((html, attrs, widget) => {
|
||||||
|
* html.push(
|
||||||
|
* widget.attach("button", {
|
||||||
|
* className: "btn btn-primary",
|
||||||
|
* icon: "magic",
|
||||||
|
* title: "discourse_ai.ai_helper.title",
|
||||||
|
* label: "discourse_ai.ai_helper.title",
|
||||||
|
* action: "showAiSummary",
|
||||||
|
* })
|
||||||
|
* );
|
||||||
|
**/
|
||||||
|
addTopicSummaryCallback(callback) {
|
||||||
|
addTopicSummaryCallback(callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Adds a callback to be executed on the "transformed" post that is passed to the post
|
* Adds a callback to be executed on the "transformed" post that is passed to the post
|
||||||
|
@ -31,10 +31,16 @@ createWidget("toggle-summary-description", {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let topicSummaryCallbacks = null;
|
||||||
|
export function addTopicSummaryCallback(callback) {
|
||||||
|
topicSummaryCallbacks = topicSummaryCallbacks || [];
|
||||||
|
topicSummaryCallbacks.push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
export default createWidget("toggle-topic-summary", {
|
export default createWidget("toggle-topic-summary", {
|
||||||
tagName: "section.information.toggle-summary",
|
tagName: "section.information.toggle-summary",
|
||||||
html(attrs) {
|
html(attrs) {
|
||||||
return [
|
let html = [
|
||||||
this.attach("toggle-summary-description", attrs),
|
this.attach("toggle-summary-description", attrs),
|
||||||
this.attach("button", {
|
this.attach("button", {
|
||||||
className: "btn btn-primary",
|
className: "btn btn-primary",
|
||||||
@ -44,5 +50,13 @@ export default createWidget("toggle-topic-summary", {
|
|||||||
action: attrs.topicSummaryEnabled ? "cancelFilter" : "showSummary",
|
action: attrs.topicSummaryEnabled ? "cancelFilter" : "showSummary",
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (topicSummaryCallbacks) {
|
||||||
|
topicSummaryCallbacks.forEach((callback) => {
|
||||||
|
html = callback(html, attrs, this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user