@novaprose/tinymce-compat 0.5.3 → 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/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 +2 -2
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,329 @@ __export(src_exports, {
|
|
|
28
28
|
module.exports = __toCommonJS(src_exports);
|
|
29
29
|
var import_core3 = require("@novaprose/core");
|
|
30
30
|
|
|
31
|
-
// src/
|
|
31
|
+
// src/options.ts
|
|
32
32
|
var import_core = require("@novaprose/core");
|
|
33
|
+
var BUILT_IN = /* @__PURE__ */ new Set([
|
|
34
|
+
"lists",
|
|
35
|
+
"link",
|
|
36
|
+
"image",
|
|
37
|
+
"table",
|
|
38
|
+
"code",
|
|
39
|
+
"codesample",
|
|
40
|
+
"preview",
|
|
41
|
+
"searchreplace",
|
|
42
|
+
"fullscreen",
|
|
43
|
+
"help",
|
|
44
|
+
"wordcount",
|
|
45
|
+
"paste",
|
|
46
|
+
"hr",
|
|
47
|
+
"print",
|
|
48
|
+
"textcolor",
|
|
49
|
+
"colorpicker",
|
|
50
|
+
"contextmenu",
|
|
51
|
+
"tabfocus",
|
|
52
|
+
"textpattern",
|
|
53
|
+
"imagetools",
|
|
54
|
+
"powerpaste",
|
|
55
|
+
"importcss",
|
|
56
|
+
"accordion"
|
|
57
|
+
]);
|
|
58
|
+
var RENAMED = {
|
|
59
|
+
tinycomments: "comments"
|
|
60
|
+
};
|
|
61
|
+
var IGNORED = /* @__PURE__ */ new Set([
|
|
62
|
+
"selector",
|
|
63
|
+
"target",
|
|
64
|
+
"license_key",
|
|
65
|
+
"api_key",
|
|
66
|
+
"branding",
|
|
67
|
+
"promotion",
|
|
68
|
+
"skin",
|
|
69
|
+
"skin_url",
|
|
70
|
+
"content_css",
|
|
71
|
+
"icons",
|
|
72
|
+
"icons_url",
|
|
73
|
+
"theme",
|
|
74
|
+
"theme_url",
|
|
75
|
+
"base_url",
|
|
76
|
+
"suffix",
|
|
77
|
+
"referrer_policy",
|
|
78
|
+
"convert_urls",
|
|
79
|
+
"relative_urls",
|
|
80
|
+
"remove_script_host",
|
|
81
|
+
"document_base_url",
|
|
82
|
+
"entity_encoding",
|
|
83
|
+
"height",
|
|
84
|
+
"min_height",
|
|
85
|
+
"max_height",
|
|
86
|
+
"width",
|
|
87
|
+
"resize",
|
|
88
|
+
"content_style",
|
|
89
|
+
"setup",
|
|
90
|
+
"init_instance_callback",
|
|
91
|
+
"inline",
|
|
92
|
+
"plugins",
|
|
93
|
+
"toolbar",
|
|
94
|
+
"menubar",
|
|
95
|
+
"statusbar",
|
|
96
|
+
"placeholder",
|
|
97
|
+
"readonly",
|
|
98
|
+
"disabled",
|
|
99
|
+
"block_formats",
|
|
100
|
+
"file_picker_callback",
|
|
101
|
+
"formats",
|
|
102
|
+
"style_formats",
|
|
103
|
+
"style_formats_merge",
|
|
104
|
+
"valid_classes",
|
|
105
|
+
"table_class_list",
|
|
106
|
+
"table_cell_class_list",
|
|
107
|
+
"file_picker_types",
|
|
108
|
+
"language",
|
|
109
|
+
"images_upload_handler",
|
|
110
|
+
"paste_as_text",
|
|
111
|
+
"paste_preprocess",
|
|
112
|
+
"paste_postprocess",
|
|
113
|
+
"invalid_elements",
|
|
114
|
+
"valid_elements",
|
|
115
|
+
"valid_styles",
|
|
116
|
+
"toolbar_mode",
|
|
117
|
+
"toolbar_sticky",
|
|
118
|
+
"font_family_formats",
|
|
119
|
+
"font_size_formats",
|
|
120
|
+
"line_height_formats",
|
|
121
|
+
"color_map",
|
|
122
|
+
"autosave_interval",
|
|
123
|
+
"autosave_retention",
|
|
124
|
+
"autosave_prefix",
|
|
125
|
+
"quickbars_selection_toolbar",
|
|
126
|
+
"quickbars_insert_toolbar",
|
|
127
|
+
"mentions_fetch",
|
|
128
|
+
"tinycomments_author",
|
|
129
|
+
"tinycomments_author_name"
|
|
130
|
+
]);
|
|
131
|
+
var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
|
|
132
|
+
function parseFormats(value) {
|
|
133
|
+
if (typeof value !== "string") return void 0;
|
|
134
|
+
return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
|
|
135
|
+
const [label, css] = item.includes("=") ? item.split("=") : [item, item];
|
|
136
|
+
return { label: label.trim(), value: (css ?? label).trim() };
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function blobInfo(file) {
|
|
140
|
+
let base64 = "";
|
|
141
|
+
const ready = new Promise((resolve) => {
|
|
142
|
+
const reader = new FileReader();
|
|
143
|
+
reader.onload = () => {
|
|
144
|
+
base64 = String(reader.result).replace(/^data:[^,]*,/, "");
|
|
145
|
+
resolve();
|
|
146
|
+
};
|
|
147
|
+
reader.onerror = () => resolve();
|
|
148
|
+
reader.readAsDataURL(file);
|
|
149
|
+
});
|
|
150
|
+
let uri = "";
|
|
151
|
+
return {
|
|
152
|
+
ready,
|
|
153
|
+
info: {
|
|
154
|
+
id: () => file.name.replace(/\.[^.]+$/, "") || "image",
|
|
155
|
+
name: () => file.name.replace(/\.[^.]+$/, "") || "image",
|
|
156
|
+
filename: () => file.name || "image",
|
|
157
|
+
blob: () => file,
|
|
158
|
+
base64: () => base64,
|
|
159
|
+
blobUri: () => uri ||= URL.createObjectURL(file),
|
|
160
|
+
uri: () => void 0
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
var BLOCKS = /* @__PURE__ */ new Set(["p", "h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "pre"]);
|
|
165
|
+
var INLINES = /* @__PURE__ */ new Set([
|
|
166
|
+
"span",
|
|
167
|
+
"strong",
|
|
168
|
+
"b",
|
|
169
|
+
"em",
|
|
170
|
+
"i",
|
|
171
|
+
"u",
|
|
172
|
+
"s",
|
|
173
|
+
"strike",
|
|
174
|
+
"del",
|
|
175
|
+
"code",
|
|
176
|
+
"sub",
|
|
177
|
+
"sup"
|
|
178
|
+
]);
|
|
179
|
+
function toFormatSpecs(value) {
|
|
180
|
+
const list2 = Array.isArray(value) ? value : [value];
|
|
181
|
+
const out = [];
|
|
182
|
+
for (const item of list2) {
|
|
183
|
+
if (!item || typeof item !== "object") continue;
|
|
184
|
+
const raw = item;
|
|
185
|
+
const spec = {};
|
|
186
|
+
if (typeof raw.block === "string" && BLOCKS.has(raw.block.toLowerCase()))
|
|
187
|
+
spec.block = raw.block.toLowerCase();
|
|
188
|
+
if (typeof raw.inline === "string" && INLINES.has(raw.inline.toLowerCase()))
|
|
189
|
+
spec.inline = raw.inline.toLowerCase();
|
|
190
|
+
if (typeof raw.selector === "string") spec.selector = raw.selector;
|
|
191
|
+
if (typeof raw.classes === "string" || Array.isArray(raw.classes))
|
|
192
|
+
spec.classes = raw.classes;
|
|
193
|
+
if (raw.styles && typeof raw.styles === "object")
|
|
194
|
+
spec.styles = Object.fromEntries(
|
|
195
|
+
Object.entries(raw.styles).filter(([, v]) => typeof v === "string" && !v.includes("%")).map(([k, v]) => [k.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`), v])
|
|
196
|
+
);
|
|
197
|
+
if (spec.block || spec.inline || spec.selector) out.push(spec);
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
function toStyleFormats(value) {
|
|
202
|
+
if (!Array.isArray(value)) return [];
|
|
203
|
+
return value.flatMap((item) => {
|
|
204
|
+
if (!item || typeof item !== "object") return [];
|
|
205
|
+
const raw = item;
|
|
206
|
+
const title = String(raw.title ?? "");
|
|
207
|
+
if (!title) return [];
|
|
208
|
+
if (Array.isArray(raw.items)) return [{ title, items: toStyleFormats(raw.items) }];
|
|
209
|
+
if (typeof raw.format === "string") return [{ title, format: raw.format }];
|
|
210
|
+
const [spec] = toFormatSpecs(raw);
|
|
211
|
+
return spec ? [{ title, ...spec }] : [];
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function mapOptions(config) {
|
|
215
|
+
const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
|
|
216
|
+
const plugins = [];
|
|
217
|
+
const missingPlugins = [];
|
|
218
|
+
for (const name of list(config.plugins)) {
|
|
219
|
+
const target = RENAMED[name] ?? name;
|
|
220
|
+
if (BUILT_IN.has(name)) continue;
|
|
221
|
+
if ((0, import_core.isPluginRegistered)(target)) plugins.push(target);
|
|
222
|
+
else missingPlugins.push(name);
|
|
223
|
+
}
|
|
224
|
+
const options = { plugins };
|
|
225
|
+
if (config.toolbar === false) options.toolbar = false;
|
|
226
|
+
else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
|
|
227
|
+
else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
|
|
228
|
+
if (config.menubar !== void 0) options.menubar = config.menubar;
|
|
229
|
+
if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
|
|
230
|
+
if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
|
|
231
|
+
if (config.readonly === true) options.editable = false;
|
|
232
|
+
if (typeof config.content_style === "string") options.contentStyle = config.content_style;
|
|
233
|
+
const classList = (value) => Array.isArray(value) ? value.filter(
|
|
234
|
+
(o) => !!o && typeof o.title === "string" && typeof o.value === "string"
|
|
235
|
+
).map(({ title, value: value2 }) => ({ title, value: value2 })) : void 0;
|
|
236
|
+
const tableClasses = classList(config.table_class_list);
|
|
237
|
+
if (tableClasses) options.tableClassList = tableClasses;
|
|
238
|
+
const cellClasses = classList(config.table_cell_class_list);
|
|
239
|
+
if (cellClasses) options.tableCellClassList = cellClasses;
|
|
240
|
+
if (config.formats && typeof config.formats === "object") {
|
|
241
|
+
options.formats = Object.fromEntries(
|
|
242
|
+
Object.entries(config.formats).map(([name, value]) => [name, toFormatSpecs(value)]).filter(([, specs]) => specs.length)
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (Array.isArray(config.style_formats)) {
|
|
246
|
+
options.styleFormats = toStyleFormats(config.style_formats);
|
|
247
|
+
if (config.style_formats_merge === true) options.styleFormatsMerge = true;
|
|
248
|
+
}
|
|
249
|
+
if (typeof config.valid_classes === "string") options.validClasses = list(config.valid_classes);
|
|
250
|
+
else if (config.valid_classes && typeof config.valid_classes === "object")
|
|
251
|
+
options.validClasses = Object.values(config.valid_classes).flatMap(
|
|
252
|
+
(v) => list(v)
|
|
253
|
+
);
|
|
254
|
+
else options.validClasses = true;
|
|
255
|
+
if (config.content_css !== void 0 && config.content_css !== false) {
|
|
256
|
+
const skins = /* @__PURE__ */ new Set(["default", "dark", "document", "writer", "tinymce-5", "tinymce-5-dark"]);
|
|
257
|
+
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));
|
|
258
|
+
if (files.length) options.contentCss = files;
|
|
259
|
+
}
|
|
260
|
+
if (config.disabled === true) options.disabled = true;
|
|
261
|
+
if (config.resize !== false) options.resize = config.resize === "both" ? "both" : true;
|
|
262
|
+
const blocks = parseFormats(config.block_formats);
|
|
263
|
+
if (blocks) {
|
|
264
|
+
const known = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "pre"];
|
|
265
|
+
options.blockFormats = blocks.map(({ label, value }) => ({ label, block: value.toLowerCase() })).filter((f) => known.includes(f.block));
|
|
266
|
+
}
|
|
267
|
+
if (typeof config.language === "string") options.language = config.language.replace("_", "-");
|
|
268
|
+
if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
|
|
269
|
+
options.toolbarMode = config.toolbar_mode;
|
|
270
|
+
} else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
|
|
271
|
+
options.toolbarMode = "sliding";
|
|
272
|
+
}
|
|
273
|
+
if (config.inline === true) options.mode = "inline";
|
|
274
|
+
if (config.paste_as_text === true) options.pasteAsText = true;
|
|
275
|
+
if (typeof config.paste_preprocess === "function") {
|
|
276
|
+
const fn = config.paste_preprocess;
|
|
277
|
+
options.pastePreprocess = (html, editor) => {
|
|
278
|
+
const args = { content: html };
|
|
279
|
+
fn(editor, args);
|
|
280
|
+
return args.content;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if (typeof config.invalid_elements === "string")
|
|
284
|
+
options.invalidElements = config.invalid_elements;
|
|
285
|
+
if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
|
|
286
|
+
if (config.valid_styles) options.validStyles = config.valid_styles;
|
|
287
|
+
const fonts = parseFormats(config.font_family_formats);
|
|
288
|
+
if (fonts) options.fontFamilies = fonts;
|
|
289
|
+
const sizes = parseFormats(config.font_size_formats);
|
|
290
|
+
if (sizes) options.fontSizes = sizes.map((s) => s.value);
|
|
291
|
+
const heights = parseFormats(config.line_height_formats);
|
|
292
|
+
if (heights) options.lineHeights = heights.map((s) => s.value);
|
|
293
|
+
if (Array.isArray(config.color_map)) {
|
|
294
|
+
options.colors = config.color_map.filter((_, i) => i % 2 === 0).map((c) => c.startsWith("#") ? c : `#${c}`);
|
|
295
|
+
}
|
|
296
|
+
if (typeof config.images_upload_handler === "function") {
|
|
297
|
+
const handler = config.images_upload_handler;
|
|
298
|
+
const upload = async (file, progress) => {
|
|
299
|
+
const { ready, info } = blobInfo(file);
|
|
300
|
+
await ready;
|
|
301
|
+
return handler(info, progress);
|
|
302
|
+
};
|
|
303
|
+
options.uploadImage = upload;
|
|
304
|
+
}
|
|
305
|
+
if (typeof config.file_picker_callback === "function") {
|
|
306
|
+
const pick = config.file_picker_callback;
|
|
307
|
+
if (typeof config.file_picker_types === "string") {
|
|
308
|
+
options.filePickerTypes = list(config.file_picker_types).filter(
|
|
309
|
+
(type) => type === "file" || type === "image" || type === "media"
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
options.filePicker = ({ type, value }) => new Promise(
|
|
313
|
+
(resolve) => pick((url, meta = {}) => resolve({ url, ...meta }), value, {
|
|
314
|
+
filetype: type,
|
|
315
|
+
fieldname: "src"
|
|
316
|
+
})
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
const pluginOptions = {};
|
|
320
|
+
if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
|
|
321
|
+
const seconds = (value) => parseInt(String(value), 10);
|
|
322
|
+
pluginOptions.autosave = {
|
|
323
|
+
...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
|
|
324
|
+
...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
|
|
325
|
+
...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
|
|
329
|
+
pluginOptions.quickbars = {
|
|
330
|
+
...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
|
|
331
|
+
...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
if (typeof config.mentions_fetch === "function") {
|
|
335
|
+
const fetch = config.mentions_fetch;
|
|
336
|
+
pluginOptions.mentions = {
|
|
337
|
+
fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (config.tinycomments_author) {
|
|
341
|
+
pluginOptions.comments = {
|
|
342
|
+
author: {
|
|
343
|
+
id: String(config.tinycomments_author),
|
|
344
|
+
name: String(config.tinycomments_author_name ?? config.tinycomments_author)
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
|
|
349
|
+
return { options, unknown, missingPlugins };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/editor.ts
|
|
353
|
+
var import_core2 = require("@novaprose/core");
|
|
33
354
|
|
|
34
355
|
// src/dialog.ts
|
|
35
356
|
var uid = 0;
|
|
@@ -325,26 +646,8 @@ function openSpecDialog(editor, spec, reopen) {
|
|
|
325
646
|
}
|
|
326
647
|
|
|
327
648
|
// src/editor.ts
|
|
328
|
-
var import_prosemirror_model = require("prosemirror-model");
|
|
329
649
|
var import_prosemirror_state = require("prosemirror-state");
|
|
330
|
-
var serializer = new
|
|
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
|
-
]);
|
|
650
|
+
var serializer = new import_core2.HTMLSerializer();
|
|
348
651
|
var COMMANDS = {
|
|
349
652
|
bold: "bold",
|
|
350
653
|
italic: "italic",
|
|
@@ -472,8 +775,8 @@ var customIcons = /* @__PURE__ */ new Map();
|
|
|
472
775
|
function resolveIcon(name) {
|
|
473
776
|
if (typeof name !== "string" || !name) return void 0;
|
|
474
777
|
if (customIcons.has(name)) return customIcons.get(name);
|
|
475
|
-
const own = ICON_NAMES[name] ?? (name in
|
|
476
|
-
return own ?
|
|
778
|
+
const own = ICON_NAMES[name] ?? (name in import_core2.icons ? name : void 0);
|
|
779
|
+
return own ? import_core2.icons[own] : void 0;
|
|
477
780
|
}
|
|
478
781
|
function buttonApi(compat) {
|
|
479
782
|
let active = false;
|
|
@@ -543,15 +846,7 @@ var CompatEditor = class {
|
|
|
543
846
|
* ссылок и разметки, что при загрузке содержимого.
|
|
544
847
|
*/
|
|
545
848
|
insertContent(content) {
|
|
546
|
-
|
|
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());
|
|
849
|
+
this.core.insertContent(content);
|
|
555
850
|
}
|
|
556
851
|
resetContent(content) {
|
|
557
852
|
this.core.setContent(content ?? this.settings.__initialContent ?? "", {
|
|
@@ -721,6 +1016,7 @@ var CompatEditor = class {
|
|
|
721
1016
|
get: (name) => this.settings[name],
|
|
722
1017
|
set: (name, value) => {
|
|
723
1018
|
this.settings[name] = value;
|
|
1019
|
+
if (name === "disabled") this.core.setDisabled(value === true);
|
|
724
1020
|
return true;
|
|
725
1021
|
},
|
|
726
1022
|
isSet: (name) => name in this.settings,
|
|
@@ -767,6 +1063,23 @@ var CompatEditor = class {
|
|
|
767
1063
|
const { state, dispatch } = this.core.view;
|
|
768
1064
|
const pos = toStart ? state.selection.from : state.selection.to;
|
|
769
1065
|
dispatch(state.tr.setSelection(import_prosemirror_state.TextSelection.near(state.doc.resolve(pos))));
|
|
1066
|
+
},
|
|
1067
|
+
/** Курсор в узел DOM редактора (по умолчанию — в начало). */
|
|
1068
|
+
setCursorLocation: (node, offset = 0) => {
|
|
1069
|
+
const { view } = this.core;
|
|
1070
|
+
if (!node || !view.dom.contains(node)) return;
|
|
1071
|
+
const pos = view.posAtDOM(node, offset);
|
|
1072
|
+
view.dispatch(view.state.tr.setSelection(import_prosemirror_state.TextSelection.near(view.state.doc.resolve(pos))));
|
|
1073
|
+
},
|
|
1074
|
+
/** Выделить элемент: content = true — только его содержимое. */
|
|
1075
|
+
select: (node, content = false) => {
|
|
1076
|
+
const { view } = this.core;
|
|
1077
|
+
if (!view.dom.contains(node)) return;
|
|
1078
|
+
const from = view.posAtDOM(node, 0);
|
|
1079
|
+
const to = view.posAtDOM(node, node.childNodes.length);
|
|
1080
|
+
const { doc } = view.state;
|
|
1081
|
+
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));
|
|
1082
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
770
1083
|
}
|
|
771
1084
|
};
|
|
772
1085
|
notificationManager = {
|
|
@@ -947,6 +1260,7 @@ var CompatEditor = class {
|
|
|
947
1260
|
remove: (name) => this.applyFormat(name, {}, "remove"),
|
|
948
1261
|
toggle: (name, vars = {}) => this.applyFormat(name, vars, this.formatter.match(name) ? "remove" : "apply"),
|
|
949
1262
|
match: (name) => {
|
|
1263
|
+
if (this.core.formatter.has(name)) return this.core.formatter.match(name);
|
|
950
1264
|
const key = name.toLowerCase();
|
|
951
1265
|
if (TAG_FORMATS.has(key)) return this.blockMatches(key);
|
|
952
1266
|
const command = FORMAT_COMMANDS[key];
|
|
@@ -956,12 +1270,19 @@ var CompatEditor = class {
|
|
|
956
1270
|
const { state } = this.core.view;
|
|
957
1271
|
const { from, to, empty } = state.selection;
|
|
958
1272
|
const type = state.schema.marks[style];
|
|
959
|
-
return empty || !type ? (0,
|
|
1273
|
+
return empty || !type ? (0, import_core2.getStyle)(state, style) !== null : state.doc.rangeHasMark(from, to, type);
|
|
960
1274
|
},
|
|
961
|
-
canApply: (name) => name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
|
|
962
|
-
register: (name) => {
|
|
963
|
-
|
|
964
|
-
|
|
1275
|
+
canApply: (name) => this.core.formatter.has(name) || name.toLowerCase() in FORMAT_COMMANDS || name.toLowerCase() in STYLE_FORMATS,
|
|
1276
|
+
register: (name, spec) => {
|
|
1277
|
+
const entries = typeof name === "string" ? [[name, spec]] : Object.entries(name);
|
|
1278
|
+
for (const [key, value] of entries) {
|
|
1279
|
+
const specs = toFormatSpecs(value);
|
|
1280
|
+
if (specs.length) this.core.formatter.register(key, specs);
|
|
1281
|
+
else console.warn(`[nova] tinymce-compat: format "${key}" is not supported yet`);
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
unregister: (name) => this.core.formatter.unregister(name),
|
|
1285
|
+
get: (name) => this.core.formatter.get(name)
|
|
965
1286
|
};
|
|
966
1287
|
blockMatches(key) {
|
|
967
1288
|
const { $from } = this.core.view.state.selection;
|
|
@@ -989,6 +1310,11 @@ var CompatEditor = class {
|
|
|
989
1310
|
return false;
|
|
990
1311
|
}
|
|
991
1312
|
applyFormat(name, vars, action) {
|
|
1313
|
+
if (this.core.formatter.has(name)) {
|
|
1314
|
+
if (action === "apply") this.core.formatter.apply(name);
|
|
1315
|
+
else this.core.formatter.remove(name);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
992
1318
|
const key = name.toLowerCase();
|
|
993
1319
|
const command = FORMAT_COMMANDS[key];
|
|
994
1320
|
if (command) {
|
|
@@ -1003,7 +1329,7 @@ var CompatEditor = class {
|
|
|
1003
1329
|
}
|
|
1004
1330
|
const style = STYLE_FORMATS[key];
|
|
1005
1331
|
if (style) {
|
|
1006
|
-
this.core.exec((0,
|
|
1332
|
+
this.core.exec((0, import_core2.setStyle)(style, action === "apply" ? vars.value ?? null : null));
|
|
1007
1333
|
return;
|
|
1008
1334
|
}
|
|
1009
1335
|
console.warn(`[nova] tinymce-compat: format "${name}" is not supported yet`);
|
|
@@ -1027,218 +1353,6 @@ var CompatEditor = class {
|
|
|
1027
1353
|
}
|
|
1028
1354
|
};
|
|
1029
1355
|
|
|
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
1356
|
// src/index.ts
|
|
1243
1357
|
var warned = /* @__PURE__ */ new Set();
|
|
1244
1358
|
function warnOnce(message) {
|
|
@@ -1247,14 +1361,6 @@ function warnOnce(message) {
|
|
|
1247
1361
|
console.warn(`[nova] tinymce-compat: ${message}`);
|
|
1248
1362
|
}
|
|
1249
1363
|
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
1364
|
var px = (value) => typeof value === "number" ? `${value}px` : String(value);
|
|
1259
1365
|
function createTinymce() {
|
|
1260
1366
|
const all = [];
|
|
@@ -1307,7 +1413,6 @@ function createTinymce() {
|
|
|
1307
1413
|
if (config.min_height !== void 0) core.root.style.minHeight = px(config.min_height);
|
|
1308
1414
|
if (config.max_height !== void 0) core.root.style.maxHeight = px(config.max_height);
|
|
1309
1415
|
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
1416
|
let changedSinceFocus = false;
|
|
1312
1417
|
core.on("change", () => {
|
|
1313
1418
|
compat.setDirty(true);
|