@novaprose/tinymce-compat 0.5.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +20 -8
  2. package/dist/index.cjs +401 -258
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +29 -8
  5. package/dist/index.d.ts +29 -8
  6. package/dist/index.js +399 -255
  7. package/dist/index.js.map +1 -1
  8. package/dist/novaprose.css +291 -29
  9. package/dist/tinymce-chunks/advlist-7a360f16.js +2 -0
  10. package/dist/tinymce-chunks/advlist-7a360f16.js.map +7 -0
  11. package/dist/tinymce-chunks/autolink-7e2e7be2.js +2 -0
  12. package/dist/tinymce-chunks/autolink-7e2e7be2.js.map +7 -0
  13. package/dist/tinymce-chunks/autoresize-d6c9537b.js +2 -0
  14. package/dist/tinymce-chunks/autoresize-d6c9537b.js.map +7 -0
  15. package/dist/tinymce-chunks/autosave-4fd46720.js +2 -0
  16. package/dist/tinymce-chunks/autosave-4fd46720.js.map +7 -0
  17. package/dist/tinymce-chunks/charmap-4b14307a.js +2 -0
  18. package/dist/tinymce-chunks/charmap-4b14307a.js.map +7 -0
  19. package/dist/tinymce-chunks/comments-panel-37cba890.js +2 -0
  20. package/dist/tinymce-chunks/comments-panel-37cba890.js.map +7 -0
  21. package/dist/tinymce-chunks/directionality-60dba768.js +2 -0
  22. package/dist/tinymce-chunks/directionality-60dba768.js.map +7 -0
  23. package/dist/tinymce-chunks/emoticons-7e6da0b6.js +2 -0
  24. package/dist/tinymce-chunks/emoticons-7e6da0b6.js.map +7 -0
  25. package/dist/tinymce-chunks/form-dialog-9cde0ef7.js +2 -0
  26. package/dist/tinymce-chunks/form-dialog-9cde0ef7.js.map +7 -0
  27. package/dist/tinymce-chunks/insertdatetime-e0dbcf63.js +2 -0
  28. package/dist/tinymce-chunks/insertdatetime-e0dbcf63.js.map +7 -0
  29. package/dist/tinymce-chunks/nonbreaking-49bdb0d2.js +2 -0
  30. package/dist/tinymce-chunks/nonbreaking-49bdb0d2.js.map +7 -0
  31. package/dist/tinymce-chunks/paste-office-a38659d6.js +3 -0
  32. package/dist/tinymce-chunks/paste-office-a38659d6.js.map +7 -0
  33. package/dist/tinymce-chunks/quickbars-d937e10a.js +2 -0
  34. package/dist/tinymce-chunks/quickbars-d937e10a.js.map +7 -0
  35. package/dist/tinymce-chunks/revisionhistory-d6306426.js +2 -0
  36. package/dist/tinymce-chunks/revisionhistory-d6306426.js.map +7 -0
  37. package/dist/tinymce-chunks/table-80284f6f.js +2 -0
  38. package/dist/tinymce-chunks/table-80284f6f.js.map +7 -0
  39. package/dist/tinymce-chunks/visualblocks-58c88e5d.js +2 -0
  40. package/dist/tinymce-chunks/visualblocks-58c88e5d.js.map +7 -0
  41. package/dist/tinymce.global.js +27 -24
  42. package/dist/tinymce.global.js.map +7 -1
  43. package/package.json +11 -6
package/dist/index.cjs CHANGED
@@ -27,9 +27,339 @@ __export(src_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(src_exports);
29
29
  var import_core3 = require("@novaprose/core");
30
+ var import_html_rules = require("@novaprose/core/html-rules");
30
31
 
31
- // src/editor.ts
32
+ // src/options.ts
32
33
  var import_core = require("@novaprose/core");
34
+ var BUILT_IN = /* @__PURE__ */ new Set([
35
+ "lists",
36
+ "link",
37
+ "image",
38
+ "table",
39
+ "code",
40
+ "codesample",
41
+ "preview",
42
+ "searchreplace",
43
+ "fullscreen",
44
+ "help",
45
+ "wordcount",
46
+ "paste",
47
+ "hr",
48
+ "print",
49
+ "textcolor",
50
+ "colorpicker",
51
+ "contextmenu",
52
+ "tabfocus",
53
+ "textpattern",
54
+ "imagetools",
55
+ "powerpaste",
56
+ "importcss",
57
+ "accordion"
58
+ ]);
59
+ var RENAMED = {
60
+ tinycomments: "comments"
61
+ };
62
+ var IGNORED = /* @__PURE__ */ new Set([
63
+ "selector",
64
+ "target",
65
+ "license_key",
66
+ "api_key",
67
+ "branding",
68
+ "promotion",
69
+ "skin",
70
+ "skin_url",
71
+ "content_css",
72
+ "icons",
73
+ "icons_url",
74
+ "theme",
75
+ "theme_url",
76
+ "base_url",
77
+ "suffix",
78
+ "referrer_policy",
79
+ "convert_urls",
80
+ "relative_urls",
81
+ "remove_script_host",
82
+ "document_base_url",
83
+ "entity_encoding",
84
+ "height",
85
+ "min_height",
86
+ "max_height",
87
+ "width",
88
+ "resize",
89
+ "content_style",
90
+ "setup",
91
+ "init_instance_callback",
92
+ "inline",
93
+ "plugins",
94
+ "toolbar",
95
+ "menubar",
96
+ "statusbar",
97
+ "placeholder",
98
+ "readonly",
99
+ "disabled",
100
+ "block_formats",
101
+ "file_picker_callback",
102
+ "formats",
103
+ "style_formats",
104
+ "style_formats_merge",
105
+ "valid_classes",
106
+ "table_class_list",
107
+ "table_cell_class_list",
108
+ "file_picker_types",
109
+ "language",
110
+ "images_upload_handler",
111
+ "paste_as_text",
112
+ "paste_preprocess",
113
+ "paste_postprocess",
114
+ "invalid_elements",
115
+ "valid_elements",
116
+ "directionality",
117
+ "extended_valid_elements",
118
+ "custom_elements",
119
+ "valid_styles",
120
+ "toolbar_mode",
121
+ "toolbar_sticky",
122
+ "font_family_formats",
123
+ "font_size_formats",
124
+ "line_height_formats",
125
+ "color_map",
126
+ "autosave_interval",
127
+ "autosave_retention",
128
+ "autosave_prefix",
129
+ "quickbars_selection_toolbar",
130
+ "quickbars_insert_toolbar",
131
+ "mentions_fetch",
132
+ "tinycomments_author",
133
+ "tinycomments_author_name"
134
+ ]);
135
+ var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
136
+ function parseFormats(value) {
137
+ if (typeof value !== "string") return void 0;
138
+ return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
139
+ const [label, css] = item.includes("=") ? item.split("=") : [item, item];
140
+ return { label: label.trim(), value: (css ?? label).trim() };
141
+ });
142
+ }
143
+ function blobInfo(file) {
144
+ let base64 = "";
145
+ const ready = new Promise((resolve) => {
146
+ const reader = new FileReader();
147
+ reader.onload = () => {
148
+ base64 = String(reader.result).replace(/^data:[^,]*,/, "");
149
+ resolve();
150
+ };
151
+ reader.onerror = () => resolve();
152
+ reader.readAsDataURL(file);
153
+ });
154
+ let uri = "";
155
+ return {
156
+ ready,
157
+ info: {
158
+ id: () => file.name.replace(/\.[^.]+$/, "") || "image",
159
+ name: () => file.name.replace(/\.[^.]+$/, "") || "image",
160
+ filename: () => file.name || "image",
161
+ blob: () => file,
162
+ base64: () => base64,
163
+ blobUri: () => uri ||= URL.createObjectURL(file),
164
+ uri: () => void 0
165
+ }
166
+ };
167
+ }
168
+ var BLOCKS = /* @__PURE__ */ new Set(["p", "h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "pre"]);
169
+ var INLINES = /* @__PURE__ */ new Set([
170
+ "span",
171
+ "strong",
172
+ "b",
173
+ "em",
174
+ "i",
175
+ "u",
176
+ "s",
177
+ "strike",
178
+ "del",
179
+ "code",
180
+ "sub",
181
+ "sup"
182
+ ]);
183
+ function toFormatSpecs(value) {
184
+ const list2 = Array.isArray(value) ? value : [value];
185
+ const out = [];
186
+ for (const item of list2) {
187
+ if (!item || typeof item !== "object") continue;
188
+ const raw = item;
189
+ const spec = {};
190
+ if (typeof raw.block === "string" && BLOCKS.has(raw.block.toLowerCase()))
191
+ spec.block = raw.block.toLowerCase();
192
+ if (typeof raw.inline === "string" && INLINES.has(raw.inline.toLowerCase()))
193
+ spec.inline = raw.inline.toLowerCase();
194
+ if (typeof raw.selector === "string") spec.selector = raw.selector;
195
+ if (typeof raw.classes === "string" || Array.isArray(raw.classes))
196
+ spec.classes = raw.classes;
197
+ if (raw.styles && typeof raw.styles === "object")
198
+ spec.styles = Object.fromEntries(
199
+ Object.entries(raw.styles).filter(([, v]) => typeof v === "string" && !v.includes("%")).map(([k, v]) => [k.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`), v])
200
+ );
201
+ if (spec.block || spec.inline || spec.selector) out.push(spec);
202
+ }
203
+ return out;
204
+ }
205
+ function toStyleFormats(value) {
206
+ if (!Array.isArray(value)) return [];
207
+ return value.flatMap((item) => {
208
+ if (!item || typeof item !== "object") return [];
209
+ const raw = item;
210
+ const title = String(raw.title ?? "");
211
+ if (!title) return [];
212
+ if (Array.isArray(raw.items)) return [{ title, items: toStyleFormats(raw.items) }];
213
+ if (typeof raw.format === "string") return [{ title, format: raw.format }];
214
+ const [spec] = toFormatSpecs(raw);
215
+ return spec ? [{ title, ...spec }] : [];
216
+ });
217
+ }
218
+ function mapOptions(config) {
219
+ const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
220
+ const plugins = [];
221
+ const missingPlugins = [];
222
+ for (const name of list(config.plugins)) {
223
+ const target = RENAMED[name] ?? name;
224
+ if (BUILT_IN.has(name)) continue;
225
+ if ((0, import_core.isPluginRegistered)(target)) plugins.push(target);
226
+ else missingPlugins.push(name);
227
+ }
228
+ const options = { plugins };
229
+ if (config.toolbar === false) options.toolbar = false;
230
+ else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
231
+ else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
232
+ if (config.menubar !== void 0) options.menubar = config.menubar;
233
+ if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
234
+ if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
235
+ if (config.readonly === true) options.editable = false;
236
+ if (typeof config.content_style === "string") options.contentStyle = config.content_style;
237
+ const classList = (value) => Array.isArray(value) ? value.filter(
238
+ (o) => !!o && typeof o.title === "string" && typeof o.value === "string"
239
+ ).map(({ title, value: value2 }) => ({ title, value: value2 })) : void 0;
240
+ const tableClasses = classList(config.table_class_list);
241
+ if (tableClasses) options.tableClassList = tableClasses;
242
+ const cellClasses = classList(config.table_cell_class_list);
243
+ if (cellClasses) options.tableCellClassList = cellClasses;
244
+ if (config.formats && typeof config.formats === "object") {
245
+ options.formats = Object.fromEntries(
246
+ Object.entries(config.formats).map(([name, value]) => [name, toFormatSpecs(value)]).filter(([, specs]) => specs.length)
247
+ );
248
+ }
249
+ if (Array.isArray(config.style_formats)) {
250
+ options.styleFormats = toStyleFormats(config.style_formats);
251
+ if (config.style_formats_merge === true) options.styleFormatsMerge = true;
252
+ }
253
+ if (typeof config.valid_classes === "string") options.validClasses = list(config.valid_classes);
254
+ else if (config.valid_classes && typeof config.valid_classes === "object")
255
+ options.validClasses = Object.values(config.valid_classes).flatMap(
256
+ (v) => list(v)
257
+ );
258
+ else options.validClasses = true;
259
+ if (config.content_css !== void 0 && config.content_css !== false) {
260
+ const skins = /* @__PURE__ */ new Set(["default", "dark", "document", "writer", "tinymce-5", "tinymce-5-dark"]);
261
+ const files = (Array.isArray(config.content_css) ? config.content_css : String(config.content_css).split(",")).map((file) => String(file).trim()).filter((file) => file && !skins.has(file));
262
+ if (files.length) options.contentCss = files;
263
+ }
264
+ if (config.disabled === true) options.disabled = true;
265
+ if (config.resize !== false) options.resize = config.resize === "both" ? "both" : true;
266
+ const blocks = parseFormats(config.block_formats);
267
+ if (blocks) {
268
+ const known = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "pre"];
269
+ options.blockFormats = blocks.map(({ label, value }) => ({ label, block: value.toLowerCase() })).filter((f) => known.includes(f.block));
270
+ }
271
+ if (typeof config.language === "string") options.language = config.language.replace("_", "-");
272
+ if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
273
+ options.toolbarMode = config.toolbar_mode;
274
+ } else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
275
+ options.toolbarMode = "sliding";
276
+ }
277
+ if (config.inline === true) options.mode = "inline";
278
+ if (config.paste_as_text === true) options.pasteAsText = true;
279
+ if (typeof config.paste_preprocess === "function") {
280
+ const fn = config.paste_preprocess;
281
+ options.pastePreprocess = (html, editor) => {
282
+ const args = { content: html };
283
+ fn(editor, args);
284
+ return args.content;
285
+ };
286
+ }
287
+ if (typeof config.invalid_elements === "string")
288
+ options.invalidElements = config.invalid_elements;
289
+ if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
290
+ if (typeof config.extended_valid_elements === "string")
291
+ options.extendedValidElements = config.extended_valid_elements;
292
+ if (typeof config.custom_elements === "string") options.customElements = config.custom_elements;
293
+ if (config.directionality === "rtl" || config.directionality === "ltr")
294
+ options.direction = config.directionality;
295
+ if (config.valid_styles) options.validStyles = config.valid_styles;
296
+ const fonts = parseFormats(config.font_family_formats);
297
+ if (fonts) options.fontFamilies = fonts;
298
+ const sizes = parseFormats(config.font_size_formats);
299
+ if (sizes) options.fontSizes = sizes.map((s) => s.value);
300
+ const heights = parseFormats(config.line_height_formats);
301
+ if (heights) options.lineHeights = heights.map((s) => s.value);
302
+ if (Array.isArray(config.color_map)) {
303
+ options.colors = config.color_map.filter((_, i) => i % 2 === 0).map((c) => c.startsWith("#") ? c : `#${c}`);
304
+ }
305
+ if (typeof config.images_upload_handler === "function") {
306
+ const handler = config.images_upload_handler;
307
+ const upload = async (file, progress) => {
308
+ const { ready, info } = blobInfo(file);
309
+ await ready;
310
+ return handler(info, progress);
311
+ };
312
+ options.uploadImage = upload;
313
+ }
314
+ if (typeof config.file_picker_callback === "function") {
315
+ const pick = config.file_picker_callback;
316
+ if (typeof config.file_picker_types === "string") {
317
+ options.filePickerTypes = list(config.file_picker_types).filter(
318
+ (type) => type === "file" || type === "image" || type === "media"
319
+ );
320
+ }
321
+ options.filePicker = ({ type, value }) => new Promise(
322
+ (resolve) => pick((url, meta = {}) => resolve({ url, ...meta }), value, {
323
+ filetype: type,
324
+ fieldname: "src"
325
+ })
326
+ );
327
+ }
328
+ const pluginOptions = {};
329
+ if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
330
+ const seconds = (value) => parseInt(String(value), 10);
331
+ pluginOptions.autosave = {
332
+ ...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
333
+ ...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
334
+ ...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
335
+ };
336
+ }
337
+ if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
338
+ pluginOptions.quickbars = {
339
+ ...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
340
+ ...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
341
+ };
342
+ }
343
+ if (typeof config.mentions_fetch === "function") {
344
+ const fetch = config.mentions_fetch;
345
+ pluginOptions.mentions = {
346
+ fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
347
+ };
348
+ }
349
+ if (config.tinycomments_author) {
350
+ pluginOptions.comments = {
351
+ author: {
352
+ id: String(config.tinycomments_author),
353
+ name: String(config.tinycomments_author_name ?? config.tinycomments_author)
354
+ }
355
+ };
356
+ }
357
+ if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
358
+ return { options, unknown, missingPlugins };
359
+ }
360
+
361
+ // src/editor.ts
362
+ var import_core2 = require("@novaprose/core");
33
363
 
34
364
  // src/dialog.ts
35
365
  var uid = 0;
@@ -325,26 +655,8 @@ function openSpecDialog(editor, spec, reopen) {
325
655
  }
326
656
 
327
657
  // src/editor.ts
328
- var import_prosemirror_model = require("prosemirror-model");
329
658
  var import_prosemirror_state = require("prosemirror-state");
330
- var serializer = new import_core.HTMLSerializer();
331
- var BLOCK_TAGS = /* @__PURE__ */ new Set([
332
- "P",
333
- "H1",
334
- "H2",
335
- "H3",
336
- "H4",
337
- "H5",
338
- "H6",
339
- "UL",
340
- "OL",
341
- "TABLE",
342
- "BLOCKQUOTE",
343
- "PRE",
344
- "HR",
345
- "DIV",
346
- "FIGURE"
347
- ]);
659
+ var serializer = new import_core2.HTMLSerializer();
348
660
  var COMMANDS = {
349
661
  bold: "bold",
350
662
  italic: "italic",
@@ -472,8 +784,8 @@ var customIcons = /* @__PURE__ */ new Map();
472
784
  function resolveIcon(name) {
473
785
  if (typeof name !== "string" || !name) return void 0;
474
786
  if (customIcons.has(name)) return customIcons.get(name);
475
- const own = ICON_NAMES[name] ?? (name in import_core.icons ? name : void 0);
476
- return own ? import_core.icons[own] : void 0;
787
+ const own = ICON_NAMES[name] ?? (name in import_core2.icons ? name : void 0);
788
+ return own ? import_core2.icons[own] : void 0;
477
789
  }
478
790
  function buttonApi(compat) {
479
791
  let active = false;
@@ -543,15 +855,7 @@ var CompatEditor = class {
543
855
  * ссылок и разметки, что при загрузке содержимого.
544
856
  */
545
857
  insertContent(content) {
546
- const template = document.createElement("template");
547
- template.innerHTML = content;
548
- const container = document.createElement("div");
549
- container.append(template.content);
550
- const parser = (0, import_core.parserFor)(this.core.schema);
551
- const hasBlocks = [...container.children].some((el2) => BLOCK_TAGS.has(el2.tagName));
552
- const slice = hasBlocks ? new import_prosemirror_model.Slice(parser.parse(container).content, 0, 0) : parser.parseSlice(container);
553
- const { state, dispatch } = this.core.view;
554
- dispatch(state.tr.replaceSelection(slice).scrollIntoView());
858
+ this.core.insertContent(content);
555
859
  }
556
860
  resetContent(content) {
557
861
  this.core.setContent(content ?? this.settings.__initialContent ?? "", {
@@ -578,6 +882,11 @@ var CompatEditor = class {
578
882
  return this.core.root.ownerDocument.defaultView;
579
883
  }
580
884
  // ---------- команды ----------
885
+ /** Значение команды: ToggleSidebar — имя открытой боковой панели. */
886
+ queryCommandValue(command) {
887
+ if (command.toLowerCase() === "togglesidebar") return this.core.ui.sidebar.active ?? "";
888
+ return "";
889
+ }
581
890
  execCommand(command, _ui, value) {
582
891
  const name = command.toLowerCase();
583
892
  let done = false;
@@ -588,6 +897,9 @@ var CompatEditor = class {
588
897
  } else if (name === "mceinsertcontent" || name === "inserthtml") {
589
898
  this.insertContent(String(value ?? ""));
590
899
  done = true;
900
+ } else if (name === "togglesidebar") {
901
+ void this.core.ui.sidebar.toggle(String(value ?? ""));
902
+ done = true;
591
903
  } else if (name === "mcesetcontent") {
592
904
  this.setContent(String(value ?? ""));
593
905
  done = true;
@@ -721,6 +1033,7 @@ var CompatEditor = class {
721
1033
  get: (name) => this.settings[name],
722
1034
  set: (name, value) => {
723
1035
  this.settings[name] = value;
1036
+ if (name === "disabled") this.core.setDisabled(value === true);
724
1037
  return true;
725
1038
  },
726
1039
  isSet: (name) => name in this.settings,
@@ -767,6 +1080,23 @@ var CompatEditor = class {
767
1080
  const { state, dispatch } = this.core.view;
768
1081
  const pos = toStart ? state.selection.from : state.selection.to;
769
1082
  dispatch(state.tr.setSelection(import_prosemirror_state.TextSelection.near(state.doc.resolve(pos))));
1083
+ },
1084
+ /** Курсор в узел DOM редактора (по умолчанию — в начало). */
1085
+ setCursorLocation: (node, offset = 0) => {
1086
+ const { view } = this.core;
1087
+ if (!node || !view.dom.contains(node)) return;
1088
+ const pos = view.posAtDOM(node, offset);
1089
+ view.dispatch(view.state.tr.setSelection(import_prosemirror_state.TextSelection.near(view.state.doc.resolve(pos))));
1090
+ },
1091
+ /** Выделить элемент: content = true — только его содержимое. */
1092
+ select: (node, content = false) => {
1093
+ const { view } = this.core;
1094
+ if (!view.dom.contains(node)) return;
1095
+ const from = view.posAtDOM(node, 0);
1096
+ const to = view.posAtDOM(node, node.childNodes.length);
1097
+ const { doc } = view.state;
1098
+ const selection = !content && node instanceof HTMLImageElement ? import_prosemirror_state.NodeSelection.create(doc, Math.max(0, from - (doc.resolve(from).nodeAfter ? 0 : 1))) : import_prosemirror_state.TextSelection.between(doc.resolve(from), doc.resolve(to));
1099
+ view.dispatch(view.state.tr.setSelection(selection));
770
1100
  }
771
1101
  };
772
1102
  notificationManager = {
@@ -856,6 +1186,26 @@ var CompatEditor = class {
856
1186
  }
857
1187
  });
858
1188
  },
1189
+ /**
1190
+ * Боковая панель: onSetup(api) рисует содержимое в api.element() (один раз), onShow/onHide —
1191
+ * при показе. Кнопка-переключатель с именем панели — для toolbar; ToggleSidebar — командой.
1192
+ */
1193
+ addSidebar: (name, spec) => {
1194
+ let element = null;
1195
+ const api = { element: () => element };
1196
+ const icon = resolveIcon(spec.icon);
1197
+ this.core.ui.registry.addSidebar(name, {
1198
+ title: spec.tooltip ?? name,
1199
+ ...icon ? { icon } : {},
1200
+ render: (container) => {
1201
+ element = container;
1202
+ const cleanup = spec.onSetup?.(api);
1203
+ return typeof cleanup === "function" ? cleanup : void 0;
1204
+ },
1205
+ onShow: () => spec.onShow?.(api),
1206
+ onHide: () => spec.onHide?.(api)
1207
+ });
1208
+ },
859
1209
  addContextForm: () => {
860
1210
  console.warn("[nova] tinymce-compat: addContextForm is not supported yet");
861
1211
  },
@@ -947,6 +1297,7 @@ var CompatEditor = class {
947
1297
  remove: (name) => this.applyFormat(name, {}, "remove"),
948
1298
  toggle: (name, vars = {}) => this.applyFormat(name, vars, this.formatter.match(name) ? "remove" : "apply"),
949
1299
  match: (name) => {
1300
+ if (this.core.formatter.has(name)) return this.core.formatter.match(name);
950
1301
  const key = name.toLowerCase();
951
1302
  if (TAG_FORMATS.has(key)) return this.blockMatches(key);
952
1303
  const command = FORMAT_COMMANDS[key];
@@ -956,12 +1307,19 @@ var CompatEditor = class {
956
1307
  const { state } = this.core.view;
957
1308
  const { from, to, empty } = state.selection;
958
1309
  const type = state.schema.marks[style];
959
- return empty || !type ? (0, import_core.getStyle)(state, style) !== null : state.doc.rangeHasMark(from, to, type);
1310
+ return empty || !type ? (0, import_core2.getStyle)(state, style) !== null : state.doc.rangeHasMark(from, to, type);
960
1311
  },
961
- canApply: (name) => name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
962
- register: (name) => {
963
- console.warn(`[nova] tinymce-compat: formatter.register("${name}") is not supported yet`);
964
- }
1312
+ canApply: (name) => this.core.formatter.has(name) || name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
1313
+ register: (name, spec) => {
1314
+ const entries = typeof name === "string" ? [[name, spec]] : Object.entries(name);
1315
+ for (const [key, value] of entries) {
1316
+ const specs = toFormatSpecs(value);
1317
+ if (specs.length) this.core.formatter.register(key, specs);
1318
+ else console.warn(`[nova] tinymce-compat: format "${key}" is not supported yet`);
1319
+ }
1320
+ },
1321
+ unregister: (name) => this.core.formatter.unregister(name),
1322
+ get: (name) => this.core.formatter.get(name)
965
1323
  };
966
1324
  blockMatches(key) {
967
1325
  const { $from } = this.core.view.state.selection;
@@ -989,6 +1347,11 @@ var CompatEditor = class {
989
1347
  return false;
990
1348
  }
991
1349
  applyFormat(name, vars, action) {
1350
+ if (this.core.formatter.has(name)) {
1351
+ if (action === "apply") this.core.formatter.apply(name);
1352
+ else this.core.formatter.remove(name);
1353
+ return;
1354
+ }
992
1355
  const key = name.toLowerCase();
993
1356
  const command = FORMAT_COMMANDS[key];
994
1357
  if (command) {
@@ -1003,7 +1366,7 @@ var CompatEditor = class {
1003
1366
  }
1004
1367
  const style = STYLE_FORMATS[key];
1005
1368
  if (style) {
1006
- this.core.exec((0, import_core.setStyle)(style, action === "apply" ? vars.value ?? null : null));
1369
+ this.core.exec((0, import_core2.setStyle)(style, action === "apply" ? vars.value ?? null : null));
1007
1370
  return;
1008
1371
  }
1009
1372
  console.warn(`[nova] tinymce-compat: format "${name}" is not supported yet`);
@@ -1027,218 +1390,6 @@ var CompatEditor = class {
1027
1390
  }
1028
1391
  };
1029
1392
 
1030
- // src/options.ts
1031
- var import_core2 = require("@novaprose/core");
1032
- var BUILT_IN = /* @__PURE__ */ new Set([
1033
- "lists",
1034
- "link",
1035
- "image",
1036
- "table",
1037
- "code",
1038
- "codesample",
1039
- "preview",
1040
- "searchreplace",
1041
- "fullscreen",
1042
- "help",
1043
- "wordcount",
1044
- "paste",
1045
- "hr",
1046
- "print",
1047
- "textcolor",
1048
- "colorpicker",
1049
- "contextmenu",
1050
- "tabfocus",
1051
- "textpattern",
1052
- "imagetools",
1053
- "powerpaste",
1054
- "importcss",
1055
- "accordion"
1056
- ]);
1057
- var RENAMED = {
1058
- tinycomments: "comments"
1059
- };
1060
- var IGNORED = /* @__PURE__ */ new Set([
1061
- "selector",
1062
- "target",
1063
- "license_key",
1064
- "api_key",
1065
- "branding",
1066
- "promotion",
1067
- "skin",
1068
- "skin_url",
1069
- "content_css",
1070
- "icons",
1071
- "icons_url",
1072
- "theme",
1073
- "theme_url",
1074
- "base_url",
1075
- "suffix",
1076
- "referrer_policy",
1077
- "convert_urls",
1078
- "relative_urls",
1079
- "remove_script_host",
1080
- "document_base_url",
1081
- "entity_encoding",
1082
- "height",
1083
- "min_height",
1084
- "max_height",
1085
- "width",
1086
- "resize",
1087
- "content_style",
1088
- "setup",
1089
- "init_instance_callback",
1090
- "inline",
1091
- "plugins",
1092
- "toolbar",
1093
- "menubar",
1094
- "statusbar",
1095
- "placeholder",
1096
- "readonly",
1097
- "language",
1098
- "images_upload_handler",
1099
- "paste_as_text",
1100
- "paste_preprocess",
1101
- "paste_postprocess",
1102
- "invalid_elements",
1103
- "valid_elements",
1104
- "valid_styles",
1105
- "toolbar_mode",
1106
- "toolbar_sticky",
1107
- "font_family_formats",
1108
- "font_size_formats",
1109
- "line_height_formats",
1110
- "color_map",
1111
- "autosave_interval",
1112
- "autosave_retention",
1113
- "autosave_prefix",
1114
- "quickbars_selection_toolbar",
1115
- "quickbars_insert_toolbar",
1116
- "mentions_fetch",
1117
- "tinycomments_author",
1118
- "tinycomments_author_name"
1119
- ]);
1120
- var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
1121
- function parseFormats(value) {
1122
- if (typeof value !== "string") return void 0;
1123
- return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
1124
- const [label, css] = item.includes("=") ? item.split("=") : [item, item];
1125
- return { label: label.trim(), value: (css ?? label).trim() };
1126
- });
1127
- }
1128
- function blobInfo(file) {
1129
- let base64 = "";
1130
- const ready = new Promise((resolve) => {
1131
- const reader = new FileReader();
1132
- reader.onload = () => {
1133
- base64 = String(reader.result).replace(/^data:[^,]*,/, "");
1134
- resolve();
1135
- };
1136
- reader.onerror = () => resolve();
1137
- reader.readAsDataURL(file);
1138
- });
1139
- let uri = "";
1140
- return {
1141
- ready,
1142
- info: {
1143
- id: () => file.name.replace(/\.[^.]+$/, "") || "image",
1144
- name: () => file.name.replace(/\.[^.]+$/, "") || "image",
1145
- filename: () => file.name || "image",
1146
- blob: () => file,
1147
- base64: () => base64,
1148
- blobUri: () => uri ||= URL.createObjectURL(file),
1149
- uri: () => void 0
1150
- }
1151
- };
1152
- }
1153
- function mapOptions(config) {
1154
- const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
1155
- const plugins = [];
1156
- const missingPlugins = [];
1157
- for (const name of list(config.plugins)) {
1158
- const target = RENAMED[name] ?? name;
1159
- if (BUILT_IN.has(name)) continue;
1160
- if ((0, import_core2.isPluginRegistered)(target)) plugins.push(target);
1161
- else missingPlugins.push(name);
1162
- }
1163
- const options = { plugins };
1164
- if (config.toolbar === false) options.toolbar = false;
1165
- else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
1166
- else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
1167
- if (config.menubar !== void 0) options.menubar = config.menubar;
1168
- if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
1169
- if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
1170
- if (config.readonly === true) options.editable = false;
1171
- if (typeof config.language === "string") options.language = config.language.replace("_", "-");
1172
- if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
1173
- options.toolbarMode = config.toolbar_mode;
1174
- } else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
1175
- options.toolbarMode = "sliding";
1176
- }
1177
- if (config.inline === true) options.mode = "inline";
1178
- if (config.paste_as_text === true) options.pasteAsText = true;
1179
- if (typeof config.paste_preprocess === "function") {
1180
- const fn = config.paste_preprocess;
1181
- options.pastePreprocess = (html, editor) => {
1182
- const args = { content: html };
1183
- fn(editor, args);
1184
- return args.content;
1185
- };
1186
- }
1187
- if (typeof config.invalid_elements === "string")
1188
- options.invalidElements = config.invalid_elements;
1189
- if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
1190
- if (config.valid_styles) options.validStyles = config.valid_styles;
1191
- const fonts = parseFormats(config.font_family_formats);
1192
- if (fonts) options.fontFamilies = fonts;
1193
- const sizes = parseFormats(config.font_size_formats);
1194
- if (sizes) options.fontSizes = sizes.map((s) => s.value);
1195
- const heights = parseFormats(config.line_height_formats);
1196
- if (heights) options.lineHeights = heights.map((s) => s.value);
1197
- if (Array.isArray(config.color_map)) {
1198
- options.colors = config.color_map.filter((_, i) => i % 2 === 0).map((c) => c.startsWith("#") ? c : `#${c}`);
1199
- }
1200
- if (typeof config.images_upload_handler === "function") {
1201
- const handler = config.images_upload_handler;
1202
- const upload = async (file, progress) => {
1203
- const { ready, info } = blobInfo(file);
1204
- await ready;
1205
- return handler(info, progress);
1206
- };
1207
- options.uploadImage = upload;
1208
- }
1209
- const pluginOptions = {};
1210
- if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
1211
- const seconds = (value) => parseInt(String(value), 10);
1212
- pluginOptions.autosave = {
1213
- ...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
1214
- ...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
1215
- ...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
1216
- };
1217
- }
1218
- if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
1219
- pluginOptions.quickbars = {
1220
- ...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
1221
- ...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
1222
- };
1223
- }
1224
- if (typeof config.mentions_fetch === "function") {
1225
- const fetch = config.mentions_fetch;
1226
- pluginOptions.mentions = {
1227
- fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
1228
- };
1229
- }
1230
- if (config.tinycomments_author) {
1231
- pluginOptions.comments = {
1232
- author: {
1233
- id: String(config.tinycomments_author),
1234
- name: String(config.tinycomments_author_name ?? config.tinycomments_author)
1235
- }
1236
- };
1237
- }
1238
- if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
1239
- return { options, unknown, missingPlugins };
1240
- }
1241
-
1242
1393
  // src/index.ts
1243
1394
  var warned = /* @__PURE__ */ new Set();
1244
1395
  function warnOnce(message) {
@@ -1247,16 +1398,9 @@ function warnOnce(message) {
1247
1398
  console.warn(`[nova] tinymce-compat: ${message}`);
1248
1399
  }
1249
1400
  var counter = 0;
1250
- function applyContentStyle(core, css) {
1251
- const scope = `nova-compat-${++counter}`;
1252
- core.root.classList.add(scope);
1253
- const style = document.createElement("style");
1254
- style.setAttribute("data-nova-compat", scope);
1255
- style.textContent = `.${scope} .nova-prosemirror { ${css.replace(/\b(html|body)\b/g, "&")} }`;
1256
- core.root.prepend(style);
1257
- }
1258
1401
  var px = (value) => typeof value === "number" ? `${value}px` : String(value);
1259
1402
  function createTinymce() {
1403
+ (0, import_core3.registerHtmlRules)(import_html_rules.htmlRules);
1260
1404
  const all = [];
1261
1405
  const plugins = /* @__PURE__ */ new Map();
1262
1406
  let active = null;
@@ -1307,7 +1451,6 @@ function createTinymce() {
1307
1451
  if (config.min_height !== void 0) core.root.style.minHeight = px(config.min_height);
1308
1452
  if (config.max_height !== void 0) core.root.style.maxHeight = px(config.max_height);
1309
1453
  if (config.width !== void 0) core.root.style.width = px(config.width);
1310
- if (typeof config.content_style === "string") applyContentStyle(core, config.content_style);
1311
1454
  let changedSinceFocus = false;
1312
1455
  core.on("change", () => {
1313
1456
  compat.setDirty(true);