@novaprose/tinymce-compat 0.5.2 → 0.6.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.
- package/README.md +10 -5
- package/THIRD_PARTY_NOTICES.md +50 -0
- package/dist/index.cjs +363 -258
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +360 -254
- package/dist/index.js.map +1 -1
- package/dist/novaprose.css +106 -0
- package/dist/tinymce.global.js +26 -23
- package/dist/tinymce.global.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,12 +1,334 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createEditor } from "@novaprose/core";
|
|
3
3
|
|
|
4
|
+
// src/options.ts
|
|
5
|
+
import {
|
|
6
|
+
isPluginRegistered
|
|
7
|
+
} from "@novaprose/core";
|
|
8
|
+
var BUILT_IN = /* @__PURE__ */ new Set([
|
|
9
|
+
"lists",
|
|
10
|
+
"link",
|
|
11
|
+
"image",
|
|
12
|
+
"table",
|
|
13
|
+
"code",
|
|
14
|
+
"codesample",
|
|
15
|
+
"preview",
|
|
16
|
+
"searchreplace",
|
|
17
|
+
"fullscreen",
|
|
18
|
+
"help",
|
|
19
|
+
"wordcount",
|
|
20
|
+
"paste",
|
|
21
|
+
"hr",
|
|
22
|
+
"print",
|
|
23
|
+
"textcolor",
|
|
24
|
+
"colorpicker",
|
|
25
|
+
"contextmenu",
|
|
26
|
+
"tabfocus",
|
|
27
|
+
"textpattern",
|
|
28
|
+
"imagetools",
|
|
29
|
+
"powerpaste",
|
|
30
|
+
"importcss",
|
|
31
|
+
"accordion"
|
|
32
|
+
]);
|
|
33
|
+
var RENAMED = {
|
|
34
|
+
tinycomments: "comments"
|
|
35
|
+
};
|
|
36
|
+
var IGNORED = /* @__PURE__ */ new Set([
|
|
37
|
+
"selector",
|
|
38
|
+
"target",
|
|
39
|
+
"license_key",
|
|
40
|
+
"api_key",
|
|
41
|
+
"branding",
|
|
42
|
+
"promotion",
|
|
43
|
+
"skin",
|
|
44
|
+
"skin_url",
|
|
45
|
+
"content_css",
|
|
46
|
+
"icons",
|
|
47
|
+
"icons_url",
|
|
48
|
+
"theme",
|
|
49
|
+
"theme_url",
|
|
50
|
+
"base_url",
|
|
51
|
+
"suffix",
|
|
52
|
+
"referrer_policy",
|
|
53
|
+
"convert_urls",
|
|
54
|
+
"relative_urls",
|
|
55
|
+
"remove_script_host",
|
|
56
|
+
"document_base_url",
|
|
57
|
+
"entity_encoding",
|
|
58
|
+
"height",
|
|
59
|
+
"min_height",
|
|
60
|
+
"max_height",
|
|
61
|
+
"width",
|
|
62
|
+
"resize",
|
|
63
|
+
"content_style",
|
|
64
|
+
"setup",
|
|
65
|
+
"init_instance_callback",
|
|
66
|
+
"inline",
|
|
67
|
+
"plugins",
|
|
68
|
+
"toolbar",
|
|
69
|
+
"menubar",
|
|
70
|
+
"statusbar",
|
|
71
|
+
"placeholder",
|
|
72
|
+
"readonly",
|
|
73
|
+
"disabled",
|
|
74
|
+
"block_formats",
|
|
75
|
+
"file_picker_callback",
|
|
76
|
+
"formats",
|
|
77
|
+
"style_formats",
|
|
78
|
+
"style_formats_merge",
|
|
79
|
+
"valid_classes",
|
|
80
|
+
"table_class_list",
|
|
81
|
+
"table_cell_class_list",
|
|
82
|
+
"file_picker_types",
|
|
83
|
+
"language",
|
|
84
|
+
"images_upload_handler",
|
|
85
|
+
"paste_as_text",
|
|
86
|
+
"paste_preprocess",
|
|
87
|
+
"paste_postprocess",
|
|
88
|
+
"invalid_elements",
|
|
89
|
+
"valid_elements",
|
|
90
|
+
"valid_styles",
|
|
91
|
+
"toolbar_mode",
|
|
92
|
+
"toolbar_sticky",
|
|
93
|
+
"font_family_formats",
|
|
94
|
+
"font_size_formats",
|
|
95
|
+
"line_height_formats",
|
|
96
|
+
"color_map",
|
|
97
|
+
"autosave_interval",
|
|
98
|
+
"autosave_retention",
|
|
99
|
+
"autosave_prefix",
|
|
100
|
+
"quickbars_selection_toolbar",
|
|
101
|
+
"quickbars_insert_toolbar",
|
|
102
|
+
"mentions_fetch",
|
|
103
|
+
"tinycomments_author",
|
|
104
|
+
"tinycomments_author_name"
|
|
105
|
+
]);
|
|
106
|
+
var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
|
|
107
|
+
function parseFormats(value) {
|
|
108
|
+
if (typeof value !== "string") return void 0;
|
|
109
|
+
return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
|
|
110
|
+
const [label, css] = item.includes("=") ? item.split("=") : [item, item];
|
|
111
|
+
return { label: label.trim(), value: (css ?? label).trim() };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function blobInfo(file) {
|
|
115
|
+
let base64 = "";
|
|
116
|
+
const ready = new Promise((resolve) => {
|
|
117
|
+
const reader = new FileReader();
|
|
118
|
+
reader.onload = () => {
|
|
119
|
+
base64 = String(reader.result).replace(/^data:[^,]*,/, "");
|
|
120
|
+
resolve();
|
|
121
|
+
};
|
|
122
|
+
reader.onerror = () => resolve();
|
|
123
|
+
reader.readAsDataURL(file);
|
|
124
|
+
});
|
|
125
|
+
let uri = "";
|
|
126
|
+
return {
|
|
127
|
+
ready,
|
|
128
|
+
info: {
|
|
129
|
+
id: () => file.name.replace(/\.[^.]+$/, "") || "image",
|
|
130
|
+
name: () => file.name.replace(/\.[^.]+$/, "") || "image",
|
|
131
|
+
filename: () => file.name || "image",
|
|
132
|
+
blob: () => file,
|
|
133
|
+
base64: () => base64,
|
|
134
|
+
blobUri: () => uri ||= URL.createObjectURL(file),
|
|
135
|
+
uri: () => void 0
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
var BLOCKS = /* @__PURE__ */ new Set(["p", "h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "pre"]);
|
|
140
|
+
var INLINES = /* @__PURE__ */ new Set([
|
|
141
|
+
"span",
|
|
142
|
+
"strong",
|
|
143
|
+
"b",
|
|
144
|
+
"em",
|
|
145
|
+
"i",
|
|
146
|
+
"u",
|
|
147
|
+
"s",
|
|
148
|
+
"strike",
|
|
149
|
+
"del",
|
|
150
|
+
"code",
|
|
151
|
+
"sub",
|
|
152
|
+
"sup"
|
|
153
|
+
]);
|
|
154
|
+
function toFormatSpecs(value) {
|
|
155
|
+
const list2 = Array.isArray(value) ? value : [value];
|
|
156
|
+
const out = [];
|
|
157
|
+
for (const item of list2) {
|
|
158
|
+
if (!item || typeof item !== "object") continue;
|
|
159
|
+
const raw = item;
|
|
160
|
+
const spec = {};
|
|
161
|
+
if (typeof raw.block === "string" && BLOCKS.has(raw.block.toLowerCase()))
|
|
162
|
+
spec.block = raw.block.toLowerCase();
|
|
163
|
+
if (typeof raw.inline === "string" && INLINES.has(raw.inline.toLowerCase()))
|
|
164
|
+
spec.inline = raw.inline.toLowerCase();
|
|
165
|
+
if (typeof raw.selector === "string") spec.selector = raw.selector;
|
|
166
|
+
if (typeof raw.classes === "string" || Array.isArray(raw.classes))
|
|
167
|
+
spec.classes = raw.classes;
|
|
168
|
+
if (raw.styles && typeof raw.styles === "object")
|
|
169
|
+
spec.styles = Object.fromEntries(
|
|
170
|
+
Object.entries(raw.styles).filter(([, v]) => typeof v === "string" && !v.includes("%")).map(([k, v]) => [k.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`), v])
|
|
171
|
+
);
|
|
172
|
+
if (spec.block || spec.inline || spec.selector) out.push(spec);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
function toStyleFormats(value) {
|
|
177
|
+
if (!Array.isArray(value)) return [];
|
|
178
|
+
return value.flatMap((item) => {
|
|
179
|
+
if (!item || typeof item !== "object") return [];
|
|
180
|
+
const raw = item;
|
|
181
|
+
const title = String(raw.title ?? "");
|
|
182
|
+
if (!title) return [];
|
|
183
|
+
if (Array.isArray(raw.items)) return [{ title, items: toStyleFormats(raw.items) }];
|
|
184
|
+
if (typeof raw.format === "string") return [{ title, format: raw.format }];
|
|
185
|
+
const [spec] = toFormatSpecs(raw);
|
|
186
|
+
return spec ? [{ title, ...spec }] : [];
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function mapOptions(config) {
|
|
190
|
+
const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
|
|
191
|
+
const plugins = [];
|
|
192
|
+
const missingPlugins = [];
|
|
193
|
+
for (const name of list(config.plugins)) {
|
|
194
|
+
const target = RENAMED[name] ?? name;
|
|
195
|
+
if (BUILT_IN.has(name)) continue;
|
|
196
|
+
if (isPluginRegistered(target)) plugins.push(target);
|
|
197
|
+
else missingPlugins.push(name);
|
|
198
|
+
}
|
|
199
|
+
const options = { plugins };
|
|
200
|
+
if (config.toolbar === false) options.toolbar = false;
|
|
201
|
+
else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
|
|
202
|
+
else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
|
|
203
|
+
if (config.menubar !== void 0) options.menubar = config.menubar;
|
|
204
|
+
if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
|
|
205
|
+
if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
|
|
206
|
+
if (config.readonly === true) options.editable = false;
|
|
207
|
+
if (typeof config.content_style === "string") options.contentStyle = config.content_style;
|
|
208
|
+
const classList = (value) => Array.isArray(value) ? value.filter(
|
|
209
|
+
(o) => !!o && typeof o.title === "string" && typeof o.value === "string"
|
|
210
|
+
).map(({ title, value: value2 }) => ({ title, value: value2 })) : void 0;
|
|
211
|
+
const tableClasses = classList(config.table_class_list);
|
|
212
|
+
if (tableClasses) options.tableClassList = tableClasses;
|
|
213
|
+
const cellClasses = classList(config.table_cell_class_list);
|
|
214
|
+
if (cellClasses) options.tableCellClassList = cellClasses;
|
|
215
|
+
if (config.formats && typeof config.formats === "object") {
|
|
216
|
+
options.formats = Object.fromEntries(
|
|
217
|
+
Object.entries(config.formats).map(([name, value]) => [name, toFormatSpecs(value)]).filter(([, specs]) => specs.length)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
if (Array.isArray(config.style_formats)) {
|
|
221
|
+
options.styleFormats = toStyleFormats(config.style_formats);
|
|
222
|
+
if (config.style_formats_merge === true) options.styleFormatsMerge = true;
|
|
223
|
+
}
|
|
224
|
+
if (typeof config.valid_classes === "string") options.validClasses = list(config.valid_classes);
|
|
225
|
+
else if (config.valid_classes && typeof config.valid_classes === "object")
|
|
226
|
+
options.validClasses = Object.values(config.valid_classes).flatMap(
|
|
227
|
+
(v) => list(v)
|
|
228
|
+
);
|
|
229
|
+
else options.validClasses = true;
|
|
230
|
+
if (config.content_css !== void 0 && config.content_css !== false) {
|
|
231
|
+
const skins = /* @__PURE__ */ new Set(["default", "dark", "document", "writer", "tinymce-5", "tinymce-5-dark"]);
|
|
232
|
+
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));
|
|
233
|
+
if (files.length) options.contentCss = files;
|
|
234
|
+
}
|
|
235
|
+
if (config.disabled === true) options.disabled = true;
|
|
236
|
+
if (config.resize !== false) options.resize = config.resize === "both" ? "both" : true;
|
|
237
|
+
const blocks = parseFormats(config.block_formats);
|
|
238
|
+
if (blocks) {
|
|
239
|
+
const known = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "pre"];
|
|
240
|
+
options.blockFormats = blocks.map(({ label, value }) => ({ label, block: value.toLowerCase() })).filter((f) => known.includes(f.block));
|
|
241
|
+
}
|
|
242
|
+
if (typeof config.language === "string") options.language = config.language.replace("_", "-");
|
|
243
|
+
if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
|
|
244
|
+
options.toolbarMode = config.toolbar_mode;
|
|
245
|
+
} else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
|
|
246
|
+
options.toolbarMode = "sliding";
|
|
247
|
+
}
|
|
248
|
+
if (config.inline === true) options.mode = "inline";
|
|
249
|
+
if (config.paste_as_text === true) options.pasteAsText = true;
|
|
250
|
+
if (typeof config.paste_preprocess === "function") {
|
|
251
|
+
const fn = config.paste_preprocess;
|
|
252
|
+
options.pastePreprocess = (html, editor) => {
|
|
253
|
+
const args = { content: html };
|
|
254
|
+
fn(editor, args);
|
|
255
|
+
return args.content;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (typeof config.invalid_elements === "string")
|
|
259
|
+
options.invalidElements = config.invalid_elements;
|
|
260
|
+
if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
|
|
261
|
+
if (config.valid_styles) options.validStyles = config.valid_styles;
|
|
262
|
+
const fonts = parseFormats(config.font_family_formats);
|
|
263
|
+
if (fonts) options.fontFamilies = fonts;
|
|
264
|
+
const sizes = parseFormats(config.font_size_formats);
|
|
265
|
+
if (sizes) options.fontSizes = sizes.map((s) => s.value);
|
|
266
|
+
const heights = parseFormats(config.line_height_formats);
|
|
267
|
+
if (heights) options.lineHeights = heights.map((s) => s.value);
|
|
268
|
+
if (Array.isArray(config.color_map)) {
|
|
269
|
+
options.colors = config.color_map.filter((_, i) => i % 2 === 0).map((c) => c.startsWith("#") ? c : `#${c}`);
|
|
270
|
+
}
|
|
271
|
+
if (typeof config.images_upload_handler === "function") {
|
|
272
|
+
const handler = config.images_upload_handler;
|
|
273
|
+
const upload = async (file, progress) => {
|
|
274
|
+
const { ready, info } = blobInfo(file);
|
|
275
|
+
await ready;
|
|
276
|
+
return handler(info, progress);
|
|
277
|
+
};
|
|
278
|
+
options.uploadImage = upload;
|
|
279
|
+
}
|
|
280
|
+
if (typeof config.file_picker_callback === "function") {
|
|
281
|
+
const pick = config.file_picker_callback;
|
|
282
|
+
if (typeof config.file_picker_types === "string") {
|
|
283
|
+
options.filePickerTypes = list(config.file_picker_types).filter(
|
|
284
|
+
(type) => type === "file" || type === "image" || type === "media"
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
options.filePicker = ({ type, value }) => new Promise(
|
|
288
|
+
(resolve) => pick((url, meta = {}) => resolve({ url, ...meta }), value, {
|
|
289
|
+
filetype: type,
|
|
290
|
+
fieldname: "src"
|
|
291
|
+
})
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
const pluginOptions = {};
|
|
295
|
+
if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
|
|
296
|
+
const seconds = (value) => parseInt(String(value), 10);
|
|
297
|
+
pluginOptions.autosave = {
|
|
298
|
+
...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
|
|
299
|
+
...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
|
|
300
|
+
...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
|
|
304
|
+
pluginOptions.quickbars = {
|
|
305
|
+
...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
|
|
306
|
+
...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
if (typeof config.mentions_fetch === "function") {
|
|
310
|
+
const fetch = config.mentions_fetch;
|
|
311
|
+
pluginOptions.mentions = {
|
|
312
|
+
fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (config.tinycomments_author) {
|
|
316
|
+
pluginOptions.comments = {
|
|
317
|
+
author: {
|
|
318
|
+
id: String(config.tinycomments_author),
|
|
319
|
+
name: String(config.tinycomments_author_name ?? config.tinycomments_author)
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
|
|
324
|
+
return { options, unknown, missingPlugins };
|
|
325
|
+
}
|
|
326
|
+
|
|
4
327
|
// src/editor.ts
|
|
5
328
|
import {
|
|
6
329
|
getStyle,
|
|
7
330
|
HTMLSerializer,
|
|
8
331
|
icons,
|
|
9
|
-
parserFor,
|
|
10
332
|
setStyle
|
|
11
333
|
} from "@novaprose/core";
|
|
12
334
|
|
|
@@ -304,26 +626,8 @@ function openSpecDialog(editor, spec, reopen) {
|
|
|
304
626
|
}
|
|
305
627
|
|
|
306
628
|
// src/editor.ts
|
|
307
|
-
import {
|
|
308
|
-
import { AllSelection, TextSelection } from "prosemirror-state";
|
|
629
|
+
import { AllSelection, NodeSelection, TextSelection } from "prosemirror-state";
|
|
309
630
|
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
631
|
var COMMANDS = {
|
|
328
632
|
bold: "bold",
|
|
329
633
|
italic: "italic",
|
|
@@ -522,15 +826,7 @@ var CompatEditor = class {
|
|
|
522
826
|
* ссылок и разметки, что при загрузке содержимого.
|
|
523
827
|
*/
|
|
524
828
|
insertContent(content) {
|
|
525
|
-
|
|
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());
|
|
829
|
+
this.core.insertContent(content);
|
|
534
830
|
}
|
|
535
831
|
resetContent(content) {
|
|
536
832
|
this.core.setContent(content ?? this.settings.__initialContent ?? "", {
|
|
@@ -700,6 +996,7 @@ var CompatEditor = class {
|
|
|
700
996
|
get: (name) => this.settings[name],
|
|
701
997
|
set: (name, value) => {
|
|
702
998
|
this.settings[name] = value;
|
|
999
|
+
if (name === "disabled") this.core.setDisabled(value === true);
|
|
703
1000
|
return true;
|
|
704
1001
|
},
|
|
705
1002
|
isSet: (name) => name in this.settings,
|
|
@@ -746,6 +1043,23 @@ var CompatEditor = class {
|
|
|
746
1043
|
const { state, dispatch } = this.core.view;
|
|
747
1044
|
const pos = toStart ? state.selection.from : state.selection.to;
|
|
748
1045
|
dispatch(state.tr.setSelection(TextSelection.near(state.doc.resolve(pos))));
|
|
1046
|
+
},
|
|
1047
|
+
/** Курсор в узел DOM редактора (по умолчанию — в начало). */
|
|
1048
|
+
setCursorLocation: (node, offset = 0) => {
|
|
1049
|
+
const { view } = this.core;
|
|
1050
|
+
if (!node || !view.dom.contains(node)) return;
|
|
1051
|
+
const pos = view.posAtDOM(node, offset);
|
|
1052
|
+
view.dispatch(view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(pos))));
|
|
1053
|
+
},
|
|
1054
|
+
/** Выделить элемент: content = true — только его содержимое. */
|
|
1055
|
+
select: (node, content = false) => {
|
|
1056
|
+
const { view } = this.core;
|
|
1057
|
+
if (!view.dom.contains(node)) return;
|
|
1058
|
+
const from = view.posAtDOM(node, 0);
|
|
1059
|
+
const to = view.posAtDOM(node, node.childNodes.length);
|
|
1060
|
+
const { doc } = view.state;
|
|
1061
|
+
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));
|
|
1062
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
749
1063
|
}
|
|
750
1064
|
};
|
|
751
1065
|
notificationManager = {
|
|
@@ -926,6 +1240,7 @@ var CompatEditor = class {
|
|
|
926
1240
|
remove: (name) => this.applyFormat(name, {}, "remove"),
|
|
927
1241
|
toggle: (name, vars = {}) => this.applyFormat(name, vars, this.formatter.match(name) ? "remove" : "apply"),
|
|
928
1242
|
match: (name) => {
|
|
1243
|
+
if (this.core.formatter.has(name)) return this.core.formatter.match(name);
|
|
929
1244
|
const key = name.toLowerCase();
|
|
930
1245
|
if (TAG_FORMATS.has(key)) return this.blockMatches(key);
|
|
931
1246
|
const command = FORMAT_COMMANDS[key];
|
|
@@ -937,10 +1252,17 @@ var CompatEditor = class {
|
|
|
937
1252
|
const type = state.schema.marks[style];
|
|
938
1253
|
return empty || !type ? getStyle(state, style) !== null : state.doc.rangeHasMark(from, to, type);
|
|
939
1254
|
},
|
|
940
|
-
canApply: (name) => name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
|
|
941
|
-
register: (name) => {
|
|
942
|
-
|
|
943
|
-
|
|
1255
|
+
canApply: (name) => this.core.formatter.has(name) || name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
|
|
1256
|
+
register: (name, spec) => {
|
|
1257
|
+
const entries = typeof name === "string" ? [[name, spec]] : Object.entries(name);
|
|
1258
|
+
for (const [key, value] of entries) {
|
|
1259
|
+
const specs = toFormatSpecs(value);
|
|
1260
|
+
if (specs.length) this.core.formatter.register(key, specs);
|
|
1261
|
+
else console.warn(`[nova] tinymce-compat: format "${key}" is not supported yet`);
|
|
1262
|
+
}
|
|
1263
|
+
},
|
|
1264
|
+
unregister: (name) => this.core.formatter.unregister(name),
|
|
1265
|
+
get: (name) => this.core.formatter.get(name)
|
|
944
1266
|
};
|
|
945
1267
|
blockMatches(key) {
|
|
946
1268
|
const { $from } = this.core.view.state.selection;
|
|
@@ -968,6 +1290,11 @@ var CompatEditor = class {
|
|
|
968
1290
|
return false;
|
|
969
1291
|
}
|
|
970
1292
|
applyFormat(name, vars, action) {
|
|
1293
|
+
if (this.core.formatter.has(name)) {
|
|
1294
|
+
if (action === "apply") this.core.formatter.apply(name);
|
|
1295
|
+
else this.core.formatter.remove(name);
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
971
1298
|
const key = name.toLowerCase();
|
|
972
1299
|
const command = FORMAT_COMMANDS[key];
|
|
973
1300
|
if (command) {
|
|
@@ -1006,218 +1333,6 @@ var CompatEditor = class {
|
|
|
1006
1333
|
}
|
|
1007
1334
|
};
|
|
1008
1335
|
|
|
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
1336
|
// src/index.ts
|
|
1222
1337
|
var warned = /* @__PURE__ */ new Set();
|
|
1223
1338
|
function warnOnce(message) {
|
|
@@ -1226,14 +1341,6 @@ function warnOnce(message) {
|
|
|
1226
1341
|
console.warn(`[nova] tinymce-compat: ${message}`);
|
|
1227
1342
|
}
|
|
1228
1343
|
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
1344
|
var px = (value) => typeof value === "number" ? `${value}px` : String(value);
|
|
1238
1345
|
function createTinymce() {
|
|
1239
1346
|
const all = [];
|
|
@@ -1286,7 +1393,6 @@ function createTinymce() {
|
|
|
1286
1393
|
if (config.min_height !== void 0) core.root.style.minHeight = px(config.min_height);
|
|
1287
1394
|
if (config.max_height !== void 0) core.root.style.maxHeight = px(config.max_height);
|
|
1288
1395
|
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
1396
|
let changedSinceFocus = false;
|
|
1291
1397
|
core.on("change", () => {
|
|
1292
1398
|
compat.setDirty(true);
|