@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.js CHANGED
@@ -1,12 +1,343 @@
1
1
  // src/index.ts
2
- import { createEditor } from "@novaprose/core";
2
+ import { createEditor, registerHtmlRules } from "@novaprose/core";
3
+ import { htmlRules } from "@novaprose/core/html-rules";
4
+
5
+ // src/options.ts
6
+ import {
7
+ isPluginRegistered
8
+ } from "@novaprose/core";
9
+ var BUILT_IN = /* @__PURE__ */ new Set([
10
+ "lists",
11
+ "link",
12
+ "image",
13
+ "table",
14
+ "code",
15
+ "codesample",
16
+ "preview",
17
+ "searchreplace",
18
+ "fullscreen",
19
+ "help",
20
+ "wordcount",
21
+ "paste",
22
+ "hr",
23
+ "print",
24
+ "textcolor",
25
+ "colorpicker",
26
+ "contextmenu",
27
+ "tabfocus",
28
+ "textpattern",
29
+ "imagetools",
30
+ "powerpaste",
31
+ "importcss",
32
+ "accordion"
33
+ ]);
34
+ var RENAMED = {
35
+ tinycomments: "comments"
36
+ };
37
+ var IGNORED = /* @__PURE__ */ new Set([
38
+ "selector",
39
+ "target",
40
+ "license_key",
41
+ "api_key",
42
+ "branding",
43
+ "promotion",
44
+ "skin",
45
+ "skin_url",
46
+ "content_css",
47
+ "icons",
48
+ "icons_url",
49
+ "theme",
50
+ "theme_url",
51
+ "base_url",
52
+ "suffix",
53
+ "referrer_policy",
54
+ "convert_urls",
55
+ "relative_urls",
56
+ "remove_script_host",
57
+ "document_base_url",
58
+ "entity_encoding",
59
+ "height",
60
+ "min_height",
61
+ "max_height",
62
+ "width",
63
+ "resize",
64
+ "content_style",
65
+ "setup",
66
+ "init_instance_callback",
67
+ "inline",
68
+ "plugins",
69
+ "toolbar",
70
+ "menubar",
71
+ "statusbar",
72
+ "placeholder",
73
+ "readonly",
74
+ "disabled",
75
+ "block_formats",
76
+ "file_picker_callback",
77
+ "formats",
78
+ "style_formats",
79
+ "style_formats_merge",
80
+ "valid_classes",
81
+ "table_class_list",
82
+ "table_cell_class_list",
83
+ "file_picker_types",
84
+ "language",
85
+ "images_upload_handler",
86
+ "paste_as_text",
87
+ "paste_preprocess",
88
+ "paste_postprocess",
89
+ "invalid_elements",
90
+ "valid_elements",
91
+ "directionality",
92
+ "extended_valid_elements",
93
+ "custom_elements",
94
+ "valid_styles",
95
+ "toolbar_mode",
96
+ "toolbar_sticky",
97
+ "font_family_formats",
98
+ "font_size_formats",
99
+ "line_height_formats",
100
+ "color_map",
101
+ "autosave_interval",
102
+ "autosave_retention",
103
+ "autosave_prefix",
104
+ "quickbars_selection_toolbar",
105
+ "quickbars_insert_toolbar",
106
+ "mentions_fetch",
107
+ "tinycomments_author",
108
+ "tinycomments_author_name"
109
+ ]);
110
+ var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
111
+ function parseFormats(value) {
112
+ if (typeof value !== "string") return void 0;
113
+ return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
114
+ const [label, css] = item.includes("=") ? item.split("=") : [item, item];
115
+ return { label: label.trim(), value: (css ?? label).trim() };
116
+ });
117
+ }
118
+ function blobInfo(file) {
119
+ let base64 = "";
120
+ const ready = new Promise((resolve) => {
121
+ const reader = new FileReader();
122
+ reader.onload = () => {
123
+ base64 = String(reader.result).replace(/^data:[^,]*,/, "");
124
+ resolve();
125
+ };
126
+ reader.onerror = () => resolve();
127
+ reader.readAsDataURL(file);
128
+ });
129
+ let uri = "";
130
+ return {
131
+ ready,
132
+ info: {
133
+ id: () => file.name.replace(/\.[^.]+$/, "") || "image",
134
+ name: () => file.name.replace(/\.[^.]+$/, "") || "image",
135
+ filename: () => file.name || "image",
136
+ blob: () => file,
137
+ base64: () => base64,
138
+ blobUri: () => uri ||= URL.createObjectURL(file),
139
+ uri: () => void 0
140
+ }
141
+ };
142
+ }
143
+ var BLOCKS = /* @__PURE__ */ new Set(["p", "h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "pre"]);
144
+ var INLINES = /* @__PURE__ */ new Set([
145
+ "span",
146
+ "strong",
147
+ "b",
148
+ "em",
149
+ "i",
150
+ "u",
151
+ "s",
152
+ "strike",
153
+ "del",
154
+ "code",
155
+ "sub",
156
+ "sup"
157
+ ]);
158
+ function toFormatSpecs(value) {
159
+ const list2 = Array.isArray(value) ? value : [value];
160
+ const out = [];
161
+ for (const item of list2) {
162
+ if (!item || typeof item !== "object") continue;
163
+ const raw = item;
164
+ const spec = {};
165
+ if (typeof raw.block === "string" && BLOCKS.has(raw.block.toLowerCase()))
166
+ spec.block = raw.block.toLowerCase();
167
+ if (typeof raw.inline === "string" && INLINES.has(raw.inline.toLowerCase()))
168
+ spec.inline = raw.inline.toLowerCase();
169
+ if (typeof raw.selector === "string") spec.selector = raw.selector;
170
+ if (typeof raw.classes === "string" || Array.isArray(raw.classes))
171
+ spec.classes = raw.classes;
172
+ if (raw.styles && typeof raw.styles === "object")
173
+ spec.styles = Object.fromEntries(
174
+ Object.entries(raw.styles).filter(([, v]) => typeof v === "string" && !v.includes("%")).map(([k, v]) => [k.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`), v])
175
+ );
176
+ if (spec.block || spec.inline || spec.selector) out.push(spec);
177
+ }
178
+ return out;
179
+ }
180
+ function toStyleFormats(value) {
181
+ if (!Array.isArray(value)) return [];
182
+ return value.flatMap((item) => {
183
+ if (!item || typeof item !== "object") return [];
184
+ const raw = item;
185
+ const title = String(raw.title ?? "");
186
+ if (!title) return [];
187
+ if (Array.isArray(raw.items)) return [{ title, items: toStyleFormats(raw.items) }];
188
+ if (typeof raw.format === "string") return [{ title, format: raw.format }];
189
+ const [spec] = toFormatSpecs(raw);
190
+ return spec ? [{ title, ...spec }] : [];
191
+ });
192
+ }
193
+ function mapOptions(config) {
194
+ const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
195
+ const plugins = [];
196
+ const missingPlugins = [];
197
+ for (const name of list(config.plugins)) {
198
+ const target = RENAMED[name] ?? name;
199
+ if (BUILT_IN.has(name)) continue;
200
+ if (isPluginRegistered(target)) plugins.push(target);
201
+ else missingPlugins.push(name);
202
+ }
203
+ const options = { plugins };
204
+ if (config.toolbar === false) options.toolbar = false;
205
+ else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
206
+ else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
207
+ if (config.menubar !== void 0) options.menubar = config.menubar;
208
+ if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
209
+ if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
210
+ if (config.readonly === true) options.editable = false;
211
+ if (typeof config.content_style === "string") options.contentStyle = config.content_style;
212
+ const classList = (value) => Array.isArray(value) ? value.filter(
213
+ (o) => !!o && typeof o.title === "string" && typeof o.value === "string"
214
+ ).map(({ title, value: value2 }) => ({ title, value: value2 })) : void 0;
215
+ const tableClasses = classList(config.table_class_list);
216
+ if (tableClasses) options.tableClassList = tableClasses;
217
+ const cellClasses = classList(config.table_cell_class_list);
218
+ if (cellClasses) options.tableCellClassList = cellClasses;
219
+ if (config.formats && typeof config.formats === "object") {
220
+ options.formats = Object.fromEntries(
221
+ Object.entries(config.formats).map(([name, value]) => [name, toFormatSpecs(value)]).filter(([, specs]) => specs.length)
222
+ );
223
+ }
224
+ if (Array.isArray(config.style_formats)) {
225
+ options.styleFormats = toStyleFormats(config.style_formats);
226
+ if (config.style_formats_merge === true) options.styleFormatsMerge = true;
227
+ }
228
+ if (typeof config.valid_classes === "string") options.validClasses = list(config.valid_classes);
229
+ else if (config.valid_classes && typeof config.valid_classes === "object")
230
+ options.validClasses = Object.values(config.valid_classes).flatMap(
231
+ (v) => list(v)
232
+ );
233
+ else options.validClasses = true;
234
+ if (config.content_css !== void 0 && config.content_css !== false) {
235
+ const skins = /* @__PURE__ */ new Set(["default", "dark", "document", "writer", "tinymce-5", "tinymce-5-dark"]);
236
+ 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));
237
+ if (files.length) options.contentCss = files;
238
+ }
239
+ if (config.disabled === true) options.disabled = true;
240
+ if (config.resize !== false) options.resize = config.resize === "both" ? "both" : true;
241
+ const blocks = parseFormats(config.block_formats);
242
+ if (blocks) {
243
+ const known = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "pre"];
244
+ options.blockFormats = blocks.map(({ label, value }) => ({ label, block: value.toLowerCase() })).filter((f) => known.includes(f.block));
245
+ }
246
+ if (typeof config.language === "string") options.language = config.language.replace("_", "-");
247
+ if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
248
+ options.toolbarMode = config.toolbar_mode;
249
+ } else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
250
+ options.toolbarMode = "sliding";
251
+ }
252
+ if (config.inline === true) options.mode = "inline";
253
+ if (config.paste_as_text === true) options.pasteAsText = true;
254
+ if (typeof config.paste_preprocess === "function") {
255
+ const fn = config.paste_preprocess;
256
+ options.pastePreprocess = (html, editor) => {
257
+ const args = { content: html };
258
+ fn(editor, args);
259
+ return args.content;
260
+ };
261
+ }
262
+ if (typeof config.invalid_elements === "string")
263
+ options.invalidElements = config.invalid_elements;
264
+ if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
265
+ if (typeof config.extended_valid_elements === "string")
266
+ options.extendedValidElements = config.extended_valid_elements;
267
+ if (typeof config.custom_elements === "string") options.customElements = config.custom_elements;
268
+ if (config.directionality === "rtl" || config.directionality === "ltr")
269
+ options.direction = config.directionality;
270
+ if (config.valid_styles) options.validStyles = config.valid_styles;
271
+ const fonts = parseFormats(config.font_family_formats);
272
+ if (fonts) options.fontFamilies = fonts;
273
+ const sizes = parseFormats(config.font_size_formats);
274
+ if (sizes) options.fontSizes = sizes.map((s) => s.value);
275
+ const heights = parseFormats(config.line_height_formats);
276
+ if (heights) options.lineHeights = heights.map((s) => s.value);
277
+ if (Array.isArray(config.color_map)) {
278
+ options.colors = config.color_map.filter((_, i) => i % 2 === 0).map((c) => c.startsWith("#") ? c : `#${c}`);
279
+ }
280
+ if (typeof config.images_upload_handler === "function") {
281
+ const handler = config.images_upload_handler;
282
+ const upload = async (file, progress) => {
283
+ const { ready, info } = blobInfo(file);
284
+ await ready;
285
+ return handler(info, progress);
286
+ };
287
+ options.uploadImage = upload;
288
+ }
289
+ if (typeof config.file_picker_callback === "function") {
290
+ const pick = config.file_picker_callback;
291
+ if (typeof config.file_picker_types === "string") {
292
+ options.filePickerTypes = list(config.file_picker_types).filter(
293
+ (type) => type === "file" || type === "image" || type === "media"
294
+ );
295
+ }
296
+ options.filePicker = ({ type, value }) => new Promise(
297
+ (resolve) => pick((url, meta = {}) => resolve({ url, ...meta }), value, {
298
+ filetype: type,
299
+ fieldname: "src"
300
+ })
301
+ );
302
+ }
303
+ const pluginOptions = {};
304
+ if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
305
+ const seconds = (value) => parseInt(String(value), 10);
306
+ pluginOptions.autosave = {
307
+ ...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
308
+ ...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
309
+ ...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
310
+ };
311
+ }
312
+ if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
313
+ pluginOptions.quickbars = {
314
+ ...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
315
+ ...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
316
+ };
317
+ }
318
+ if (typeof config.mentions_fetch === "function") {
319
+ const fetch = config.mentions_fetch;
320
+ pluginOptions.mentions = {
321
+ fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
322
+ };
323
+ }
324
+ if (config.tinycomments_author) {
325
+ pluginOptions.comments = {
326
+ author: {
327
+ id: String(config.tinycomments_author),
328
+ name: String(config.tinycomments_author_name ?? config.tinycomments_author)
329
+ }
330
+ };
331
+ }
332
+ if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
333
+ return { options, unknown, missingPlugins };
334
+ }
3
335
 
4
336
  // src/editor.ts
5
337
  import {
6
338
  getStyle,
7
339
  HTMLSerializer,
8
340
  icons,
9
- parserFor,
10
341
  setStyle
11
342
  } from "@novaprose/core";
12
343
 
@@ -304,26 +635,8 @@ function openSpecDialog(editor, spec, reopen) {
304
635
  }
305
636
 
306
637
  // src/editor.ts
307
- import { Slice } from "prosemirror-model";
308
- import { AllSelection, TextSelection } from "prosemirror-state";
638
+ import { AllSelection, NodeSelection, TextSelection } from "prosemirror-state";
309
639
  var serializer = new HTMLSerializer();
310
- var BLOCK_TAGS = /* @__PURE__ */ new Set([
311
- "P",
312
- "H1",
313
- "H2",
314
- "H3",
315
- "H4",
316
- "H5",
317
- "H6",
318
- "UL",
319
- "OL",
320
- "TABLE",
321
- "BLOCKQUOTE",
322
- "PRE",
323
- "HR",
324
- "DIV",
325
- "FIGURE"
326
- ]);
327
640
  var COMMANDS = {
328
641
  bold: "bold",
329
642
  italic: "italic",
@@ -522,15 +835,7 @@ var CompatEditor = class {
522
835
  * ссылок и разметки, что при загрузке содержимого.
523
836
  */
524
837
  insertContent(content) {
525
- const template = document.createElement("template");
526
- template.innerHTML = content;
527
- const container = document.createElement("div");
528
- container.append(template.content);
529
- const parser = parserFor(this.core.schema);
530
- const hasBlocks = [...container.children].some((el2) => BLOCK_TAGS.has(el2.tagName));
531
- const slice = hasBlocks ? new Slice(parser.parse(container).content, 0, 0) : parser.parseSlice(container);
532
- const { state, dispatch } = this.core.view;
533
- dispatch(state.tr.replaceSelection(slice).scrollIntoView());
838
+ this.core.insertContent(content);
534
839
  }
535
840
  resetContent(content) {
536
841
  this.core.setContent(content ?? this.settings.__initialContent ?? "", {
@@ -557,6 +862,11 @@ var CompatEditor = class {
557
862
  return this.core.root.ownerDocument.defaultView;
558
863
  }
559
864
  // ---------- команды ----------
865
+ /** Значение команды: ToggleSidebar — имя открытой боковой панели. */
866
+ queryCommandValue(command) {
867
+ if (command.toLowerCase() === "togglesidebar") return this.core.ui.sidebar.active ?? "";
868
+ return "";
869
+ }
560
870
  execCommand(command, _ui, value) {
561
871
  const name = command.toLowerCase();
562
872
  let done = false;
@@ -567,6 +877,9 @@ var CompatEditor = class {
567
877
  } else if (name === "mceinsertcontent" || name === "inserthtml") {
568
878
  this.insertContent(String(value ?? ""));
569
879
  done = true;
880
+ } else if (name === "togglesidebar") {
881
+ void this.core.ui.sidebar.toggle(String(value ?? ""));
882
+ done = true;
570
883
  } else if (name === "mcesetcontent") {
571
884
  this.setContent(String(value ?? ""));
572
885
  done = true;
@@ -700,6 +1013,7 @@ var CompatEditor = class {
700
1013
  get: (name) => this.settings[name],
701
1014
  set: (name, value) => {
702
1015
  this.settings[name] = value;
1016
+ if (name === "disabled") this.core.setDisabled(value === true);
703
1017
  return true;
704
1018
  },
705
1019
  isSet: (name) => name in this.settings,
@@ -746,6 +1060,23 @@ var CompatEditor = class {
746
1060
  const { state, dispatch } = this.core.view;
747
1061
  const pos = toStart ? state.selection.from : state.selection.to;
748
1062
  dispatch(state.tr.setSelection(TextSelection.near(state.doc.resolve(pos))));
1063
+ },
1064
+ /** Курсор в узел DOM редактора (по умолчанию — в начало). */
1065
+ setCursorLocation: (node, offset = 0) => {
1066
+ const { view } = this.core;
1067
+ if (!node || !view.dom.contains(node)) return;
1068
+ const pos = view.posAtDOM(node, offset);
1069
+ view.dispatch(view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(pos))));
1070
+ },
1071
+ /** Выделить элемент: content = true — только его содержимое. */
1072
+ select: (node, content = false) => {
1073
+ const { view } = this.core;
1074
+ if (!view.dom.contains(node)) return;
1075
+ const from = view.posAtDOM(node, 0);
1076
+ const to = view.posAtDOM(node, node.childNodes.length);
1077
+ const { doc } = view.state;
1078
+ const selection = !content && node instanceof HTMLImageElement ? NodeSelection.create(doc, Math.max(0, from - (doc.resolve(from).nodeAfter ? 0 : 1))) : TextSelection.between(doc.resolve(from), doc.resolve(to));
1079
+ view.dispatch(view.state.tr.setSelection(selection));
749
1080
  }
750
1081
  };
751
1082
  notificationManager = {
@@ -835,6 +1166,26 @@ var CompatEditor = class {
835
1166
  }
836
1167
  });
837
1168
  },
1169
+ /**
1170
+ * Боковая панель: onSetup(api) рисует содержимое в api.element() (один раз), onShow/onHide —
1171
+ * при показе. Кнопка-переключатель с именем панели — для toolbar; ToggleSidebar — командой.
1172
+ */
1173
+ addSidebar: (name, spec) => {
1174
+ let element = null;
1175
+ const api = { element: () => element };
1176
+ const icon = resolveIcon(spec.icon);
1177
+ this.core.ui.registry.addSidebar(name, {
1178
+ title: spec.tooltip ?? name,
1179
+ ...icon ? { icon } : {},
1180
+ render: (container) => {
1181
+ element = container;
1182
+ const cleanup = spec.onSetup?.(api);
1183
+ return typeof cleanup === "function" ? cleanup : void 0;
1184
+ },
1185
+ onShow: () => spec.onShow?.(api),
1186
+ onHide: () => spec.onHide?.(api)
1187
+ });
1188
+ },
838
1189
  addContextForm: () => {
839
1190
  console.warn("[nova] tinymce-compat: addContextForm is not supported yet");
840
1191
  },
@@ -926,6 +1277,7 @@ var CompatEditor = class {
926
1277
  remove: (name) => this.applyFormat(name, {}, "remove"),
927
1278
  toggle: (name, vars = {}) => this.applyFormat(name, vars, this.formatter.match(name) ? "remove" : "apply"),
928
1279
  match: (name) => {
1280
+ if (this.core.formatter.has(name)) return this.core.formatter.match(name);
929
1281
  const key = name.toLowerCase();
930
1282
  if (TAG_FORMATS.has(key)) return this.blockMatches(key);
931
1283
  const command = FORMAT_COMMANDS[key];
@@ -937,10 +1289,17 @@ var CompatEditor = class {
937
1289
  const type = state.schema.marks[style];
938
1290
  return empty || !type ? getStyle(state, style) !== null : state.doc.rangeHasMark(from, to, type);
939
1291
  },
940
- canApply: (name) => name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
941
- register: (name) => {
942
- console.warn(`[nova] tinymce-compat: formatter.register("${name}") is not supported yet`);
943
- }
1292
+ canApply: (name) => this.core.formatter.has(name) || name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
1293
+ register: (name, spec) => {
1294
+ const entries = typeof name === "string" ? [[name, spec]] : Object.entries(name);
1295
+ for (const [key, value] of entries) {
1296
+ const specs = toFormatSpecs(value);
1297
+ if (specs.length) this.core.formatter.register(key, specs);
1298
+ else console.warn(`[nova] tinymce-compat: format "${key}" is not supported yet`);
1299
+ }
1300
+ },
1301
+ unregister: (name) => this.core.formatter.unregister(name),
1302
+ get: (name) => this.core.formatter.get(name)
944
1303
  };
945
1304
  blockMatches(key) {
946
1305
  const { $from } = this.core.view.state.selection;
@@ -968,6 +1327,11 @@ var CompatEditor = class {
968
1327
  return false;
969
1328
  }
970
1329
  applyFormat(name, vars, action) {
1330
+ if (this.core.formatter.has(name)) {
1331
+ if (action === "apply") this.core.formatter.apply(name);
1332
+ else this.core.formatter.remove(name);
1333
+ return;
1334
+ }
971
1335
  const key = name.toLowerCase();
972
1336
  const command = FORMAT_COMMANDS[key];
973
1337
  if (command) {
@@ -1006,218 +1370,6 @@ var CompatEditor = class {
1006
1370
  }
1007
1371
  };
1008
1372
 
1009
- // src/options.ts
1010
- import { isPluginRegistered } from "@novaprose/core";
1011
- var BUILT_IN = /* @__PURE__ */ new Set([
1012
- "lists",
1013
- "link",
1014
- "image",
1015
- "table",
1016
- "code",
1017
- "codesample",
1018
- "preview",
1019
- "searchreplace",
1020
- "fullscreen",
1021
- "help",
1022
- "wordcount",
1023
- "paste",
1024
- "hr",
1025
- "print",
1026
- "textcolor",
1027
- "colorpicker",
1028
- "contextmenu",
1029
- "tabfocus",
1030
- "textpattern",
1031
- "imagetools",
1032
- "powerpaste",
1033
- "importcss",
1034
- "accordion"
1035
- ]);
1036
- var RENAMED = {
1037
- tinycomments: "comments"
1038
- };
1039
- var IGNORED = /* @__PURE__ */ new Set([
1040
- "selector",
1041
- "target",
1042
- "license_key",
1043
- "api_key",
1044
- "branding",
1045
- "promotion",
1046
- "skin",
1047
- "skin_url",
1048
- "content_css",
1049
- "icons",
1050
- "icons_url",
1051
- "theme",
1052
- "theme_url",
1053
- "base_url",
1054
- "suffix",
1055
- "referrer_policy",
1056
- "convert_urls",
1057
- "relative_urls",
1058
- "remove_script_host",
1059
- "document_base_url",
1060
- "entity_encoding",
1061
- "height",
1062
- "min_height",
1063
- "max_height",
1064
- "width",
1065
- "resize",
1066
- "content_style",
1067
- "setup",
1068
- "init_instance_callback",
1069
- "inline",
1070
- "plugins",
1071
- "toolbar",
1072
- "menubar",
1073
- "statusbar",
1074
- "placeholder",
1075
- "readonly",
1076
- "language",
1077
- "images_upload_handler",
1078
- "paste_as_text",
1079
- "paste_preprocess",
1080
- "paste_postprocess",
1081
- "invalid_elements",
1082
- "valid_elements",
1083
- "valid_styles",
1084
- "toolbar_mode",
1085
- "toolbar_sticky",
1086
- "font_family_formats",
1087
- "font_size_formats",
1088
- "line_height_formats",
1089
- "color_map",
1090
- "autosave_interval",
1091
- "autosave_retention",
1092
- "autosave_prefix",
1093
- "quickbars_selection_toolbar",
1094
- "quickbars_insert_toolbar",
1095
- "mentions_fetch",
1096
- "tinycomments_author",
1097
- "tinycomments_author_name"
1098
- ]);
1099
- var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
1100
- function parseFormats(value) {
1101
- if (typeof value !== "string") return void 0;
1102
- return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
1103
- const [label, css] = item.includes("=") ? item.split("=") : [item, item];
1104
- return { label: label.trim(), value: (css ?? label).trim() };
1105
- });
1106
- }
1107
- function blobInfo(file) {
1108
- let base64 = "";
1109
- const ready = new Promise((resolve) => {
1110
- const reader = new FileReader();
1111
- reader.onload = () => {
1112
- base64 = String(reader.result).replace(/^data:[^,]*,/, "");
1113
- resolve();
1114
- };
1115
- reader.onerror = () => resolve();
1116
- reader.readAsDataURL(file);
1117
- });
1118
- let uri = "";
1119
- return {
1120
- ready,
1121
- info: {
1122
- id: () => file.name.replace(/\.[^.]+$/, "") || "image",
1123
- name: () => file.name.replace(/\.[^.]+$/, "") || "image",
1124
- filename: () => file.name || "image",
1125
- blob: () => file,
1126
- base64: () => base64,
1127
- blobUri: () => uri ||= URL.createObjectURL(file),
1128
- uri: () => void 0
1129
- }
1130
- };
1131
- }
1132
- function mapOptions(config) {
1133
- const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
1134
- const plugins = [];
1135
- const missingPlugins = [];
1136
- for (const name of list(config.plugins)) {
1137
- const target = RENAMED[name] ?? name;
1138
- if (BUILT_IN.has(name)) continue;
1139
- if (isPluginRegistered(target)) plugins.push(target);
1140
- else missingPlugins.push(name);
1141
- }
1142
- const options = { plugins };
1143
- if (config.toolbar === false) options.toolbar = false;
1144
- else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
1145
- else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
1146
- if (config.menubar !== void 0) options.menubar = config.menubar;
1147
- if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
1148
- if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
1149
- if (config.readonly === true) options.editable = false;
1150
- if (typeof config.language === "string") options.language = config.language.replace("_", "-");
1151
- if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
1152
- options.toolbarMode = config.toolbar_mode;
1153
- } else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
1154
- options.toolbarMode = "sliding";
1155
- }
1156
- if (config.inline === true) options.mode = "inline";
1157
- if (config.paste_as_text === true) options.pasteAsText = true;
1158
- if (typeof config.paste_preprocess === "function") {
1159
- const fn = config.paste_preprocess;
1160
- options.pastePreprocess = (html, editor) => {
1161
- const args = { content: html };
1162
- fn(editor, args);
1163
- return args.content;
1164
- };
1165
- }
1166
- if (typeof config.invalid_elements === "string")
1167
- options.invalidElements = config.invalid_elements;
1168
- if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
1169
- if (config.valid_styles) options.validStyles = config.valid_styles;
1170
- const fonts = parseFormats(config.font_family_formats);
1171
- if (fonts) options.fontFamilies = fonts;
1172
- const sizes = parseFormats(config.font_size_formats);
1173
- if (sizes) options.fontSizes = sizes.map((s) => s.value);
1174
- const heights = parseFormats(config.line_height_formats);
1175
- if (heights) options.lineHeights = heights.map((s) => s.value);
1176
- if (Array.isArray(config.color_map)) {
1177
- options.colors = config.color_map.filter((_, i) => i % 2 === 0).map((c) => c.startsWith("#") ? c : `#${c}`);
1178
- }
1179
- if (typeof config.images_upload_handler === "function") {
1180
- const handler = config.images_upload_handler;
1181
- const upload = async (file, progress) => {
1182
- const { ready, info } = blobInfo(file);
1183
- await ready;
1184
- return handler(info, progress);
1185
- };
1186
- options.uploadImage = upload;
1187
- }
1188
- const pluginOptions = {};
1189
- if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
1190
- const seconds = (value) => parseInt(String(value), 10);
1191
- pluginOptions.autosave = {
1192
- ...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
1193
- ...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
1194
- ...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
1195
- };
1196
- }
1197
- if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
1198
- pluginOptions.quickbars = {
1199
- ...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
1200
- ...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
1201
- };
1202
- }
1203
- if (typeof config.mentions_fetch === "function") {
1204
- const fetch = config.mentions_fetch;
1205
- pluginOptions.mentions = {
1206
- fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
1207
- };
1208
- }
1209
- if (config.tinycomments_author) {
1210
- pluginOptions.comments = {
1211
- author: {
1212
- id: String(config.tinycomments_author),
1213
- name: String(config.tinycomments_author_name ?? config.tinycomments_author)
1214
- }
1215
- };
1216
- }
1217
- if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
1218
- return { options, unknown, missingPlugins };
1219
- }
1220
-
1221
1373
  // src/index.ts
1222
1374
  var warned = /* @__PURE__ */ new Set();
1223
1375
  function warnOnce(message) {
@@ -1226,16 +1378,9 @@ function warnOnce(message) {
1226
1378
  console.warn(`[nova] tinymce-compat: ${message}`);
1227
1379
  }
1228
1380
  var counter = 0;
1229
- function applyContentStyle(core, css) {
1230
- const scope = `nova-compat-${++counter}`;
1231
- core.root.classList.add(scope);
1232
- const style = document.createElement("style");
1233
- style.setAttribute("data-nova-compat", scope);
1234
- style.textContent = `.${scope} .nova-prosemirror { ${css.replace(/\b(html|body)\b/g, "&")} }`;
1235
- core.root.prepend(style);
1236
- }
1237
1381
  var px = (value) => typeof value === "number" ? `${value}px` : String(value);
1238
1382
  function createTinymce() {
1383
+ registerHtmlRules(htmlRules);
1239
1384
  const all = [];
1240
1385
  const plugins = /* @__PURE__ */ new Map();
1241
1386
  let active = null;
@@ -1286,7 +1431,6 @@ function createTinymce() {
1286
1431
  if (config.min_height !== void 0) core.root.style.minHeight = px(config.min_height);
1287
1432
  if (config.max_height !== void 0) core.root.style.maxHeight = px(config.max_height);
1288
1433
  if (config.width !== void 0) core.root.style.width = px(config.width);
1289
- if (typeof config.content_style === "string") applyContentStyle(core, config.content_style);
1290
1434
  let changedSinceFocus = false;
1291
1435
  core.on("change", () => {
1292
1436
  compat.setDirty(true);