@frontify/fondue
Version:
Design system of Frontify
85 lines (84 loc) • 2.47 kB
JavaScript
var r = Object.defineProperty;
var u = (i, t, s) => t in i ? r(i, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[t] = s;
var l = (i, t, s) => u(i, typeof t != "symbol" ? t + "" : t, s);
import { ToolbarPositionWithButtons as a } from "../components/Toolbar/ToolbarPositionWithButtons.es.js";
class h {
constructor(t) {
l(this, "platePlugins", /* @__PURE__ */ new Map());
l(this, "markupElements", {});
l(this, "inlineElements", []);
l(this, "toolbarButtons", new a());
l(this, "styles", {});
this.props = t;
}
setPlugin(...t) {
for (const s of t) {
const n = Array.isArray(s) ? s : [s];
for (const e of n)
this.addElement(e.markupElement), this.addElement(e.markupInputElement), this.addLeafElements(e.leafMarkupElements), this.addPlugin(e), this.addInline(e.inline()), e.styles && this.addStyles(e.styles, e.id), e.textStyles && this.addTextStylesOfSubPlugins(e.textStyles);
this.hasToolbar && this.toolbarButtons.createGroupOfButtons(n);
}
return this;
}
addTextStylesOfSubPlugins(t) {
for (const s of t)
s.styles && this.addStyles(s.styles, s.id);
}
addLeafElements(t) {
if (t === void 0)
return;
const s = Array.isArray(t) ? t : [t];
for (const n of s)
this.addElement(n);
}
addElement(t) {
if (t === void 0)
return;
const s = t.getId(), n = t.getNode();
n && !this.markupElements[s] && (this.markupElements[s] = n);
}
addPlugin(t) {
t.id && !this.platePlugins.has(t.id) && this.platePlugins.set(t.id, t.plugins());
}
addInline(t) {
t && this.inlineElements.push(t);
}
addStyles(t, s) {
this.styles[s] = t;
}
get elements() {
return { ...this.defaultElementsFromPlugins, ...this.markupElements };
}
get defaultElementsFromPlugins() {
const t = {};
for (const s of this.platePlugins.values())
for (const n of s) {
const { key: e, component: o } = n;
o && (t[e] = o);
}
return t;
}
get plugins() {
const t = [];
for (const s of this.platePlugins.values())
t.push(...s);
return t;
}
get buttons() {
return this.toolbarButtons;
}
get inline() {
return this.inlineElements;
}
get hasToolbar() {
var t;
return !((t = this.props) != null && t.noToolbar);
}
get getStyles() {
return this.styles;
}
}
export {
h as PluginComposer
};
//# sourceMappingURL=PluginComposer.es.js.map