@novaprose/core 0.6.0 → 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.
- package/README.md +7 -4
- package/dist/{advlist-K2U3VPH2.js → advlist-5FNKPLUX.js} +10 -19
- package/dist/advlist-5FNKPLUX.js.map +1 -0
- package/dist/{autolink-XWDTLY37.js → autolink-45LTODWB.js} +6 -3
- package/dist/{autolink-XWDTLY37.js.map → autolink-45LTODWB.js.map} +1 -1
- package/dist/{autosave-MWNRUNU3.js → autosave-GMWJ5BPE.js} +6 -10
- package/dist/autosave-GMWJ5BPE.js.map +1 -0
- package/dist/{charmap-ADLYOIB3.js → charmap-2GC7LF7G.js} +6 -11
- package/dist/charmap-2GC7LF7G.js.map +1 -0
- package/dist/{chunk-NPKAIW34.js → chunk-5AW2HHG6.js} +6 -1
- package/dist/chunk-5AW2HHG6.js.map +1 -0
- package/dist/{chunk-46RIM5KP.js → chunk-DWZLSZDG.js} +689 -974
- package/dist/chunk-DWZLSZDG.js.map +1 -0
- package/dist/{chunk-7ON7PR5R.js → chunk-FCMZ7TUQ.js} +213 -20
- package/dist/chunk-FCMZ7TUQ.js.map +1 -0
- package/dist/{chunk-HZRIBOPW.js → chunk-JPJVTB45.js} +38 -2
- package/dist/chunk-JPJVTB45.js.map +1 -0
- package/dist/{chunk-435CRWKA.js → chunk-KPE3QRPB.js} +163 -422
- package/dist/chunk-KPE3QRPB.js.map +1 -0
- package/dist/chunk-KWXFL4WS.js +174 -0
- package/dist/chunk-KWXFL4WS.js.map +1 -0
- package/dist/chunk-ND2CWNVG.js +51 -0
- package/dist/chunk-ND2CWNVG.js.map +1 -0
- package/dist/chunk-PVFKXRID.js +27 -0
- package/dist/chunk-PVFKXRID.js.map +1 -0
- package/dist/chunk-R2UMUCVI.js +351 -0
- package/dist/chunk-R2UMUCVI.js.map +1 -0
- package/dist/{chunk-GHEFKKRC.js → chunk-T3GY6IVK.js} +41 -24
- package/dist/chunk-T3GY6IVK.js.map +1 -0
- package/dist/{comments-panel-FYJE3U64.js → comments-panel-HXMWSRAW.js} +5 -3
- package/dist/comments-panel-HXMWSRAW.js.map +1 -0
- package/dist/{directionality-XOHJFSL6.js → directionality-5JLWQGP2.js} +12 -10
- package/dist/directionality-5JLWQGP2.js.map +1 -0
- package/dist/editor-CXkltf1R.d.ts +1886 -0
- package/dist/editor-CgSBFTke.d.cts +1886 -0
- package/dist/{emoticons-TP4N4ZGY.js → emoticons-ZD6ZRIWG.js} +6 -11
- package/dist/emoticons-ZD6ZRIWG.js.map +1 -0
- package/dist/form-dialog-QH6KAERD.js +180 -0
- package/dist/form-dialog-QH6KAERD.js.map +1 -0
- package/dist/html-rules-api-D3fKQi-R.d.cts +40 -0
- package/dist/html-rules-api-D3fKQi-R.d.ts +40 -0
- package/dist/html-rules.cjs +480 -0
- package/dist/html-rules.cjs.map +1 -0
- package/dist/html-rules.d.cts +87 -0
- package/dist/html-rules.d.ts +87 -0
- package/dist/html-rules.js +413 -0
- package/dist/html-rules.js.map +1 -0
- package/dist/i18n/de.cjs +324 -0
- package/dist/i18n/de.cjs.map +1 -0
- package/dist/i18n/de.d.cts +9 -0
- package/dist/i18n/de.d.ts +9 -0
- package/dist/i18n/de.js +303 -0
- package/dist/i18n/de.js.map +1 -0
- package/dist/i18n/es.cjs +324 -0
- package/dist/i18n/es.cjs.map +1 -0
- package/dist/i18n/es.d.cts +9 -0
- package/dist/i18n/es.d.ts +9 -0
- package/dist/i18n/es.js +303 -0
- package/dist/i18n/es.js.map +1 -0
- package/dist/i18n/fr.cjs +324 -0
- package/dist/i18n/fr.cjs.map +1 -0
- package/dist/i18n/fr.d.cts +9 -0
- package/dist/i18n/fr.d.ts +9 -0
- package/dist/i18n/fr.js +303 -0
- package/dist/i18n/fr.js.map +1 -0
- package/dist/i18n/it.cjs +324 -0
- package/dist/i18n/it.cjs.map +1 -0
- package/dist/i18n/it.d.cts +9 -0
- package/dist/i18n/it.d.ts +9 -0
- package/dist/i18n/it.js +303 -0
- package/dist/i18n/it.js.map +1 -0
- package/dist/i18n/pt-BR.cjs +324 -0
- package/dist/i18n/pt-BR.cjs.map +1 -0
- package/dist/i18n/pt-BR.d.cts +9 -0
- package/dist/i18n/pt-BR.d.ts +9 -0
- package/dist/i18n/pt-BR.js +303 -0
- package/dist/i18n/pt-BR.js.map +1 -0
- package/dist/i18n/ru.cjs +324 -0
- package/dist/i18n/ru.cjs.map +1 -0
- package/dist/i18n/ru.d.cts +10 -0
- package/dist/i18n/ru.d.ts +10 -0
- package/dist/i18n/ru.js +303 -0
- package/dist/i18n/ru.js.map +1 -0
- package/dist/index-C603bU6r.d.cts +216 -0
- package/dist/index-C603bU6r.d.ts +216 -0
- package/dist/index.cjs +2159 -1178
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -1788
- package/dist/index.d.ts +46 -1788
- package/dist/index.js +96 -152
- package/dist/index.js.map +1 -1
- package/dist/{insertdatetime-T4SEMQWP.js → insertdatetime-CRO7TJAQ.js} +9 -15
- package/dist/insertdatetime-CRO7TJAQ.js.map +1 -0
- package/dist/markdown.cjs +273 -0
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.d.cts +23 -0
- package/dist/markdown.d.ts +23 -0
- package/dist/markdown.js +241 -0
- package/dist/markdown.js.map +1 -0
- package/dist/{nonbreaking-HG5HV6AL.js → nonbreaking-66LFZV2W.js} +7 -6
- package/dist/nonbreaking-66LFZV2W.js.map +1 -0
- package/dist/paste-office-F3QW4WWO.js +440 -0
- package/dist/paste-office-F3QW4WWO.js.map +1 -0
- package/dist/{quickbars-4NU4SIPL.js → quickbars-7E2QRS7J.js} +12 -8
- package/dist/quickbars-7E2QRS7J.js.map +1 -0
- package/dist/{revisionhistory-3YQPLPLM.js → revisionhistory-DXE7KU4R.js} +17 -31
- package/dist/revisionhistory-DXE7KU4R.js.map +1 -0
- package/dist/table-SSNABG5W.js +301 -0
- package/dist/table-SSNABG5W.js.map +1 -0
- package/dist/{visualblocks-RTAYJOGR.js → visualblocks-6DLBXYOA.js} +7 -6
- package/dist/visualblocks-6DLBXYOA.js.map +1 -0
- package/package.json +45 -5
- package/src/style.css +187 -31
- package/dist/advlist-K2U3VPH2.js.map +0 -1
- package/dist/autosave-MWNRUNU3.js.map +0 -1
- package/dist/charmap-ADLYOIB3.js.map +0 -1
- package/dist/chunk-435CRWKA.js.map +0 -1
- package/dist/chunk-46RIM5KP.js.map +0 -1
- package/dist/chunk-6RJENZXT.js +0 -104
- package/dist/chunk-6RJENZXT.js.map +0 -1
- package/dist/chunk-7ON7PR5R.js.map +0 -1
- package/dist/chunk-GHEFKKRC.js.map +0 -1
- package/dist/chunk-HZRIBOPW.js.map +0 -1
- package/dist/chunk-NPKAIW34.js.map +0 -1
- package/dist/comments-panel-FYJE3U64.js.map +0 -1
- package/dist/directionality-XOHJFSL6.js.map +0 -1
- package/dist/emoticons-TP4N4ZGY.js.map +0 -1
- package/dist/insertdatetime-T4SEMQWP.js.map +0 -1
- package/dist/nonbreaking-HG5HV6AL.js.map +0 -1
- package/dist/quickbars-4NU4SIPL.js.map +0 -1
- package/dist/revisionhistory-3YQPLPLM.js.map +0 -1
- package/dist/visualblocks-RTAYJOGR.js.map +0 -1
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
getLinkAt,
|
|
3
|
+
insertImage,
|
|
4
|
+
markRange,
|
|
5
|
+
marksOf,
|
|
6
|
+
nodesOf
|
|
7
|
+
} from "./chunk-T3GY6IVK.js";
|
|
8
|
+
import {
|
|
9
|
+
icons
|
|
10
|
+
} from "./chunk-5AW2HHG6.js";
|
|
6
11
|
import {
|
|
7
12
|
FOCUSABLE,
|
|
13
|
+
activeElement,
|
|
8
14
|
h,
|
|
9
15
|
icon,
|
|
16
|
+
listenDocument,
|
|
10
17
|
uniqueId
|
|
11
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-JPJVTB45.js";
|
|
12
19
|
import {
|
|
13
|
-
icons
|
|
14
|
-
} from "./chunk-NPKAIW34.js";
|
|
15
|
-
import {
|
|
16
|
-
getLinkAt,
|
|
17
|
-
insertImage,
|
|
18
20
|
isSafeImageUrl,
|
|
19
|
-
isSafeLinkUrl
|
|
20
|
-
|
|
21
|
-
marksOf,
|
|
22
|
-
nodesOf
|
|
23
|
-
} from "./chunk-GHEFKKRC.js";
|
|
21
|
+
isSafeLinkUrl
|
|
22
|
+
} from "./chunk-PVFKXRID.js";
|
|
24
23
|
|
|
25
24
|
// src/ui/file-picker.ts
|
|
26
25
|
function attachFilePicker(editor, field, type, onPick) {
|
|
@@ -60,6 +59,7 @@ function attachFilePicker(editor, field, type, onPick) {
|
|
|
60
59
|
// src/image.ts
|
|
61
60
|
import {
|
|
62
61
|
NodeSelection,
|
|
62
|
+
TextSelection,
|
|
63
63
|
Plugin,
|
|
64
64
|
PluginKey
|
|
65
65
|
} from "prosemirror-state";
|
|
@@ -104,7 +104,7 @@ function openDialog(options) {
|
|
|
104
104
|
if (closed) return;
|
|
105
105
|
closed = true;
|
|
106
106
|
backdrop.remove();
|
|
107
|
-
|
|
107
|
+
stopKeepFocus();
|
|
108
108
|
options.onClose?.();
|
|
109
109
|
options.returnFocus?.();
|
|
110
110
|
};
|
|
@@ -145,21 +145,20 @@ function openDialog(options) {
|
|
|
145
145
|
const first2 = focusable[0];
|
|
146
146
|
const last = focusable[focusable.length - 1];
|
|
147
147
|
if (!first2 || !last) return;
|
|
148
|
-
if (event.shiftKey &&
|
|
148
|
+
if (event.shiftKey && activeElement(form) === first2) {
|
|
149
149
|
event.preventDefault();
|
|
150
150
|
last.focus();
|
|
151
|
-
} else if (!event.shiftKey &&
|
|
151
|
+
} else if (!event.shiftKey && activeElement(form) === last) {
|
|
152
152
|
event.preventDefault();
|
|
153
153
|
first2.focus();
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
-
const
|
|
158
|
-
if (!form.contains(
|
|
157
|
+
const stopKeepFocus = listenDocument(form, "focusin", (_event, target) => {
|
|
158
|
+
if (!form.contains(target)) {
|
|
159
159
|
(form.querySelector(FOCUSABLE) ?? form).focus();
|
|
160
160
|
}
|
|
161
|
-
};
|
|
162
|
-
document.addEventListener("focusin", keepFocusInside, true);
|
|
161
|
+
});
|
|
163
162
|
const first = options.initialFocus ?? form.querySelector(".nova-dialog-body input, .nova-dialog-body textarea");
|
|
164
163
|
(first ?? (options.submitLabel ? submit : cancel)).focus();
|
|
165
164
|
return { el: form, close, setError, setBusy };
|
|
@@ -249,31 +248,57 @@ function uploadImages(editor, files, pos) {
|
|
|
249
248
|
if (pos !== void 0) tr.insert(Math.min(pos, tr.doc.content.size), node);
|
|
250
249
|
else tr.replaceSelectionWith(node);
|
|
251
250
|
view.dispatch(tr.scrollIntoView());
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
251
|
+
startUpload(editor, file, blobUrl, 0);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
var UPLOAD_RETRY_DELAYS = [1e3, 3e3];
|
|
255
|
+
var UnsafeUploadUrl = class extends Error {
|
|
256
|
+
};
|
|
257
|
+
function startUpload(editor, file, blobUrl, attempt) {
|
|
258
|
+
const view = editor.view;
|
|
259
|
+
const { t } = editor.ui;
|
|
260
|
+
const handler = editor.options.uploadImage;
|
|
261
|
+
const notice = handler ? editor.ui.notify({ text: t("image.uploading"), timeout: 0 }) : null;
|
|
262
|
+
const upload = handler ? handler(file, (percent) => notice?.setText(`${t("image.uploading")} ${Math.round(percent)}%`)) : readAsDataUrl(file);
|
|
263
|
+
const release = () => URL.revokeObjectURL(blobUrl);
|
|
264
|
+
const remove = () => {
|
|
265
|
+
const at = view.isDestroyed ? null : findImage(view, blobUrl);
|
|
266
|
+
if (at !== null) view.dispatch(view.state.tr.delete(at, at + 1).setMeta("addToHistory", false));
|
|
267
|
+
release();
|
|
268
|
+
};
|
|
269
|
+
upload.then((url) => {
|
|
270
|
+
if (!isSafeImageUrl(url)) throw new UnsafeUploadUrl(`Unsafe image URL returned: ${url}`);
|
|
271
|
+
const at = view.isDestroyed ? null : findImage(view, blobUrl);
|
|
272
|
+
if (at !== null) {
|
|
262
273
|
const current = view.state.doc.nodeAt(at);
|
|
263
274
|
view.dispatch(
|
|
264
275
|
view.state.tr.setNodeMarkup(at, void 0, { ...current.attrs, src: url }).setMeta("addToHistory", false)
|
|
265
276
|
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
277
|
+
}
|
|
278
|
+
release();
|
|
279
|
+
}).catch((error) => {
|
|
280
|
+
if (view.isDestroyed || findImage(view, blobUrl) === null) return release();
|
|
281
|
+
const delay = UPLOAD_RETRY_DELAYS[attempt];
|
|
282
|
+
if (handler && delay !== void 0 && !(error instanceof UnsafeUploadUrl)) {
|
|
283
|
+
const waiting = editor.ui.notify({ text: t("image.retrying"), timeout: 0 });
|
|
284
|
+
setTimeout(() => {
|
|
285
|
+
waiting.close();
|
|
286
|
+
if (view.isDestroyed) return release();
|
|
287
|
+
startUpload(editor, file, blobUrl, attempt + 1);
|
|
288
|
+
}, delay);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
console.error("[nova] image upload failed", error);
|
|
292
|
+
editor.ui.notify({
|
|
293
|
+
text: t("image.uploadFailed"),
|
|
294
|
+
type: "error",
|
|
295
|
+
actions: [
|
|
296
|
+
{ label: t("image.retry"), onAction: () => startUpload(editor, file, blobUrl, 0) },
|
|
297
|
+
{ label: t("image.delete"), onAction: remove }
|
|
298
|
+
],
|
|
299
|
+
onClose: remove
|
|
275
300
|
});
|
|
276
|
-
}
|
|
301
|
+
}).finally(() => notice?.close());
|
|
277
302
|
}
|
|
278
303
|
var DATA_IMAGE = /^data:(image\/(?:png|jpe?g|gif|webp|avif|bmp));base64,(.+)$/i;
|
|
279
304
|
function dataUrlToFile(src, name = "pasted-image") {
|
|
@@ -313,7 +338,16 @@ async function uploadEmbeddedImage(editor, src) {
|
|
|
313
338
|
replaceImageSrc(editor.view, src, url);
|
|
314
339
|
} catch (error) {
|
|
315
340
|
console.error("[nova] embedded image upload failed", error);
|
|
316
|
-
editor.ui.notify({
|
|
341
|
+
editor.ui.notify({
|
|
342
|
+
text: editor.ui.t("image.uploadFailed"),
|
|
343
|
+
type: "error",
|
|
344
|
+
actions: [
|
|
345
|
+
{
|
|
346
|
+
label: editor.ui.t("image.retry"),
|
|
347
|
+
onAction: () => void uploadEmbeddedImage(editor, src)
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
});
|
|
317
351
|
} finally {
|
|
318
352
|
notice.close();
|
|
319
353
|
}
|
|
@@ -375,7 +409,10 @@ function openImageDialog(editor) {
|
|
|
375
409
|
type: "file",
|
|
376
410
|
accept: "image/png,image/jpeg,image/gif,image/webp,image/avif",
|
|
377
411
|
className: "nova-visually-hidden",
|
|
378
|
-
tabindex: "-1"
|
|
412
|
+
tabindex: "-1",
|
|
413
|
+
// Выбор файла — через видимую зону ниже; само поле скрыто, но подпись у него обязана быть.
|
|
414
|
+
"aria-label": t("image.drop"),
|
|
415
|
+
"aria-hidden": "true"
|
|
379
416
|
});
|
|
380
417
|
const dropzone = h(
|
|
381
418
|
"button",
|
|
@@ -434,18 +471,89 @@ function openImageDialog(editor) {
|
|
|
434
471
|
}
|
|
435
472
|
function getSelectedImage(state) {
|
|
436
473
|
const { selection } = state;
|
|
437
|
-
|
|
438
|
-
|
|
474
|
+
const nodes = nodesOf(state);
|
|
475
|
+
const result = (node, pos) => node.type === nodes.figure ? { node, pos, attrs: { ...node.firstChild?.attrs, align: node.attrs.align } } : { node, pos, attrs: node.attrs };
|
|
476
|
+
if (selection instanceof NodeSelection && (selection.node.type === nodes.image || selection.node.type === nodes.figure)) {
|
|
477
|
+
return result(selection.node, selection.from);
|
|
478
|
+
}
|
|
479
|
+
const { $from } = selection;
|
|
480
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
481
|
+
if ($from.node(depth).type === nodes.figure)
|
|
482
|
+
return result($from.node(depth), $from.before(depth));
|
|
439
483
|
}
|
|
440
484
|
return null;
|
|
441
485
|
}
|
|
486
|
+
function hasImageCaption(state) {
|
|
487
|
+
return getSelectedImage(state)?.node.type === nodesOf(state).figure;
|
|
488
|
+
}
|
|
489
|
+
var IMAGE_ATTRS = ["src", "alt", "title", "width", "height"];
|
|
490
|
+
var pick = (attrs) => Object.fromEntries(IMAGE_ATTRS.map((name) => [name, attrs[name] ?? null]));
|
|
491
|
+
var toggleImageCaption = (state, dispatch) => {
|
|
492
|
+
const image = getSelectedImage(state);
|
|
493
|
+
if (!image) return false;
|
|
494
|
+
const nodes = nodesOf(state);
|
|
495
|
+
const { pos, node, attrs } = image;
|
|
496
|
+
if (!dispatch) return true;
|
|
497
|
+
const tr = state.tr;
|
|
498
|
+
if (node.type === nodes.figure) {
|
|
499
|
+
const inline = nodes.image.create({ ...pick(attrs), align: attrs.align ?? null });
|
|
500
|
+
const blocks = [nodes.paragraph.create(null, inline)];
|
|
501
|
+
const caption = node.child(1);
|
|
502
|
+
if (caption.content.size) blocks.push(nodes.paragraph.create(null, caption.content));
|
|
503
|
+
tr.replaceWith(pos, pos + node.nodeSize, blocks);
|
|
504
|
+
tr.setSelection(NodeSelection.create(tr.doc, pos + 1));
|
|
505
|
+
dispatch(tr.scrollIntoView());
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
const $pos = state.doc.resolve(pos);
|
|
509
|
+
const blockStart = $pos.before($pos.depth);
|
|
510
|
+
const blockEnd = $pos.after($pos.depth);
|
|
511
|
+
const figure = nodes.figure.create({ align: attrs.align ?? null }, [
|
|
512
|
+
nodes.figure_image.create(pick(attrs)),
|
|
513
|
+
nodes.figcaption.create()
|
|
514
|
+
]);
|
|
515
|
+
const CAPTION = 3;
|
|
516
|
+
if ($pos.parent.childCount === 1) {
|
|
517
|
+
tr.replaceWith(blockStart, blockEnd, figure);
|
|
518
|
+
tr.setSelection(TextSelection.create(tr.doc, blockStart + CAPTION));
|
|
519
|
+
} else {
|
|
520
|
+
tr.insert(blockEnd, figure);
|
|
521
|
+
tr.delete(pos, pos + node.nodeSize);
|
|
522
|
+
tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(blockEnd, -1) + CAPTION));
|
|
523
|
+
}
|
|
524
|
+
dispatch(tr.scrollIntoView());
|
|
525
|
+
return true;
|
|
526
|
+
};
|
|
527
|
+
var exitImageCaption = (state, dispatch) => {
|
|
528
|
+
const { $from } = state.selection;
|
|
529
|
+
if ($from.parent.type !== nodesOf(state).figcaption) return false;
|
|
530
|
+
if (dispatch) {
|
|
531
|
+
const after = $from.after($from.depth - 1);
|
|
532
|
+
const tr = state.tr.insert(after, nodesOf(state).paragraph.create());
|
|
533
|
+
tr.setSelection(TextSelection.create(tr.doc, after + 1));
|
|
534
|
+
dispatch(tr.scrollIntoView());
|
|
535
|
+
}
|
|
536
|
+
return true;
|
|
537
|
+
};
|
|
442
538
|
function setImageAttrs(attrs) {
|
|
443
539
|
return (state, dispatch) => {
|
|
444
540
|
const image = getSelectedImage(state);
|
|
445
541
|
if (!image) return false;
|
|
446
542
|
if (dispatch) {
|
|
447
|
-
const tr = state.tr
|
|
448
|
-
|
|
543
|
+
const tr = state.tr;
|
|
544
|
+
if (image.node.type === nodesOf(state).figure) {
|
|
545
|
+
const { align, ...rest } = attrs;
|
|
546
|
+
if (align !== void 0) {
|
|
547
|
+
tr.setNodeMarkup(image.pos, void 0, { ...image.node.attrs, align });
|
|
548
|
+
}
|
|
549
|
+
if (Object.keys(rest).length) {
|
|
550
|
+
const inner = image.node.firstChild;
|
|
551
|
+
tr.setNodeMarkup(image.pos + 1, void 0, { ...inner.attrs, ...rest });
|
|
552
|
+
}
|
|
553
|
+
} else {
|
|
554
|
+
tr.setNodeMarkup(image.pos, void 0, { ...image.node.attrs, ...attrs });
|
|
555
|
+
tr.setSelection(NodeSelection.create(tr.doc, image.pos));
|
|
556
|
+
}
|
|
449
557
|
dispatch(tr);
|
|
450
558
|
}
|
|
451
559
|
return true;
|
|
@@ -469,10 +577,10 @@ function openImageAltDialog(editor) {
|
|
|
469
577
|
const { t } = editor.ui;
|
|
470
578
|
const alt = textField({
|
|
471
579
|
label: t("image.alt"),
|
|
472
|
-
value: image.
|
|
580
|
+
value: String(image.attrs.alt ?? ""),
|
|
473
581
|
hint: t("image.altHint")
|
|
474
582
|
});
|
|
475
|
-
const title = textField({ label: t("link.tooltip"), value: image.
|
|
583
|
+
const title = textField({ label: t("link.tooltip"), value: String(image.attrs.title ?? "") });
|
|
476
584
|
editor.ui.openDialog({
|
|
477
585
|
title: t("image.editAlt"),
|
|
478
586
|
body: h("div", { className: "nova-form" }, alt.el, title.el),
|
|
@@ -591,361 +699,6 @@ function openLinkDialog(editor) {
|
|
|
591
699
|
});
|
|
592
700
|
}
|
|
593
701
|
|
|
594
|
-
// src/table.ts
|
|
595
|
-
import { keymap } from "prosemirror-keymap";
|
|
596
|
-
import { Fragment } from "prosemirror-model";
|
|
597
|
-
import { TextSelection } from "prosemirror-state";
|
|
598
|
-
import {
|
|
599
|
-
addColumnAfter,
|
|
600
|
-
addColumnBefore,
|
|
601
|
-
addRowAfter,
|
|
602
|
-
addRowBefore,
|
|
603
|
-
CellSelection,
|
|
604
|
-
columnResizing,
|
|
605
|
-
deleteColumn,
|
|
606
|
-
deleteRow,
|
|
607
|
-
deleteTable,
|
|
608
|
-
findTable,
|
|
609
|
-
goToNextCell,
|
|
610
|
-
isInTable,
|
|
611
|
-
mergeCells,
|
|
612
|
-
selectedRect,
|
|
613
|
-
setCellAttr,
|
|
614
|
-
splitCell,
|
|
615
|
-
tableEditing,
|
|
616
|
-
TableView,
|
|
617
|
-
toggleHeader
|
|
618
|
-
} from "prosemirror-tables";
|
|
619
|
-
var MAX_GRID = 10;
|
|
620
|
-
function createTable(rows, cols, withHeader = true, schema2 = schema) {
|
|
621
|
-
const { table, table_row, table_cell, table_header, paragraph } = schema2.nodes;
|
|
622
|
-
const rowNodes = [];
|
|
623
|
-
for (let r = 0; r < rows; r++) {
|
|
624
|
-
const cellType = withHeader && r === 0 ? table_header : table_cell;
|
|
625
|
-
const cells = [];
|
|
626
|
-
for (let c = 0; c < cols; c++) cells.push(cellType.create(null, paragraph.create()));
|
|
627
|
-
rowNodes.push(table_row.create(null, cells));
|
|
628
|
-
}
|
|
629
|
-
return table.create(null, rowNodes);
|
|
630
|
-
}
|
|
631
|
-
function insertTable(rows, cols, withHeader = true) {
|
|
632
|
-
return (state, dispatch) => {
|
|
633
|
-
if (rows < 1 || cols < 1 || rows > 100 || cols > 50) return false;
|
|
634
|
-
if (isInTable(state)) return false;
|
|
635
|
-
if (dispatch) {
|
|
636
|
-
const node = createTable(rows, cols, withHeader, state.schema);
|
|
637
|
-
const tr = state.tr.replaceSelectionWith(node);
|
|
638
|
-
let tablePos = -1;
|
|
639
|
-
tr.doc.descendants((n, pos) => {
|
|
640
|
-
if (n === node) tablePos = pos;
|
|
641
|
-
return tablePos < 0;
|
|
642
|
-
});
|
|
643
|
-
if (tablePos >= 0) tr.setSelection(TextSelection.near(tr.doc.resolve(tablePos + 3)));
|
|
644
|
-
dispatch(tr.scrollIntoView());
|
|
645
|
-
}
|
|
646
|
-
return true;
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
var nextCellOrNewRow = (state, dispatch, view) => {
|
|
650
|
-
if (!isInTable(state)) return false;
|
|
651
|
-
if (goToNextCell(1)(state, dispatch, view)) return true;
|
|
652
|
-
if (!dispatch) return true;
|
|
653
|
-
let next = state;
|
|
654
|
-
addRowAfter(state, (tr) => {
|
|
655
|
-
next = state.apply(tr);
|
|
656
|
-
dispatch(tr);
|
|
657
|
-
});
|
|
658
|
-
return goToNextCell(1)(next, dispatch, view);
|
|
659
|
-
};
|
|
660
|
-
function tablePlugins() {
|
|
661
|
-
return [
|
|
662
|
-
// defaultCellMinWidth — минимум для столбцов без заданной ширины (по умолчанию 100px:
|
|
663
|
-
// таблица из 5+ столбцов раньше времени вылезала за край узкого редактора).
|
|
664
|
-
columnResizing({ cellMinWidth: 48, defaultCellMinWidth: 48, View: NovaTableView }),
|
|
665
|
-
tableEditing(),
|
|
666
|
-
keymap({
|
|
667
|
-
Tab: nextCellOrNewRow,
|
|
668
|
-
"Shift-Tab": goToNextCell(-1)
|
|
669
|
-
})
|
|
670
|
-
];
|
|
671
|
-
}
|
|
672
|
-
var tableCommands = {
|
|
673
|
-
addRowBefore,
|
|
674
|
-
addRowAfter,
|
|
675
|
-
deleteRow,
|
|
676
|
-
addColumnBefore,
|
|
677
|
-
addColumnAfter,
|
|
678
|
-
deleteColumn,
|
|
679
|
-
mergeCells,
|
|
680
|
-
splitCell,
|
|
681
|
-
// Без устаревшей логики (та смотрит на угловую ячейку и путает строку/столбец заголовков).
|
|
682
|
-
toggleHeaderRow: toggleHeader("row"),
|
|
683
|
-
toggleHeaderColumn: toggleHeader("column"),
|
|
684
|
-
deleteTable
|
|
685
|
-
};
|
|
686
|
-
function setCellBackground(color) {
|
|
687
|
-
return setCellAttr("background", color);
|
|
688
|
-
}
|
|
689
|
-
function hasHeaderRow(state) {
|
|
690
|
-
if (!isInTable(state)) return false;
|
|
691
|
-
const firstRow = findTable(state.selection.$from)?.node.firstChild;
|
|
692
|
-
if (!firstRow || firstRow.childCount === 0) return false;
|
|
693
|
-
let all = true;
|
|
694
|
-
firstRow.forEach((cell) => {
|
|
695
|
-
if (cell.type !== state.schema.nodes.table_header) all = false;
|
|
696
|
-
});
|
|
697
|
-
return all;
|
|
698
|
-
}
|
|
699
|
-
function hasHeaderColumn(state) {
|
|
700
|
-
if (!isInTable(state)) return false;
|
|
701
|
-
const table = findTable(state.selection.$from)?.node;
|
|
702
|
-
if (!table) return false;
|
|
703
|
-
let all = true;
|
|
704
|
-
table.forEach((row) => {
|
|
705
|
-
if (row.firstChild?.type !== state.schema.nodes.table_header) all = false;
|
|
706
|
-
});
|
|
707
|
-
return all;
|
|
708
|
-
}
|
|
709
|
-
function tableRect(editor) {
|
|
710
|
-
const { state } = editor.view;
|
|
711
|
-
if (!isInTable(state)) return null;
|
|
712
|
-
const table = findTable(state.selection.$from);
|
|
713
|
-
if (!table) return null;
|
|
714
|
-
const dom = editor.view.nodeDOM(table.pos);
|
|
715
|
-
return dom?.getBoundingClientRect() ?? null;
|
|
716
|
-
}
|
|
717
|
-
function createTableGridPanel(onPick, label, gridLabel) {
|
|
718
|
-
let rows = 1;
|
|
719
|
-
let cols = 1;
|
|
720
|
-
const cells = [];
|
|
721
|
-
const caption = h("div", { className: "nova-grid-caption", "aria-live": "polite" });
|
|
722
|
-
const grid = h("div", { className: "nova-grid", role: "grid", "aria-label": gridLabel });
|
|
723
|
-
const paint = () => {
|
|
724
|
-
for (const cell of cells) {
|
|
725
|
-
const r = Number(cell.dataset.row);
|
|
726
|
-
const c = Number(cell.dataset.col);
|
|
727
|
-
cell.classList.toggle("is-on", r <= rows && c <= cols);
|
|
728
|
-
cell.tabIndex = r === rows && c === cols ? 0 : -1;
|
|
729
|
-
}
|
|
730
|
-
caption.textContent = label(rows, cols);
|
|
731
|
-
};
|
|
732
|
-
for (let r = 1; r <= MAX_GRID; r++) {
|
|
733
|
-
for (let c = 1; c <= MAX_GRID; c++) {
|
|
734
|
-
const cell = h("button", {
|
|
735
|
-
type: "button",
|
|
736
|
-
className: "nova-grid-cell",
|
|
737
|
-
role: "gridcell",
|
|
738
|
-
"aria-label": label(r, c),
|
|
739
|
-
"data-row": String(r),
|
|
740
|
-
"data-col": String(c)
|
|
741
|
-
});
|
|
742
|
-
cell.addEventListener("mouseenter", () => {
|
|
743
|
-
rows = r;
|
|
744
|
-
cols = c;
|
|
745
|
-
paint();
|
|
746
|
-
});
|
|
747
|
-
cell.addEventListener("click", () => onPick(r, c));
|
|
748
|
-
cells.push(cell);
|
|
749
|
-
grid.append(cell);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
grid.addEventListener("keydown", (event) => {
|
|
753
|
-
const moves = {
|
|
754
|
-
ArrowRight: [0, 1],
|
|
755
|
-
ArrowLeft: [0, -1],
|
|
756
|
-
ArrowDown: [1, 0],
|
|
757
|
-
ArrowUp: [-1, 0]
|
|
758
|
-
};
|
|
759
|
-
const move = moves[event.key];
|
|
760
|
-
if (!move) return;
|
|
761
|
-
event.preventDefault();
|
|
762
|
-
rows = Math.min(MAX_GRID, Math.max(1, rows + move[0]));
|
|
763
|
-
cols = Math.min(MAX_GRID, Math.max(1, cols + move[1]));
|
|
764
|
-
paint();
|
|
765
|
-
cells[(rows - 1) * MAX_GRID + (cols - 1)].focus();
|
|
766
|
-
});
|
|
767
|
-
paint();
|
|
768
|
-
return h("div", { className: "nova-grid-panel" }, grid, caption);
|
|
769
|
-
}
|
|
770
|
-
function numericValue(text) {
|
|
771
|
-
const cleaned = text.replace(/\s/g, "").replace(/^[^\d+-]+|[^\d]+$/g, "").replace(/,(?=\d{3}(?:\D|$))/g, "").replace(",", ".");
|
|
772
|
-
if (!/^[+-]?\d+(\.\d+)?$/.test(cleaned)) return null;
|
|
773
|
-
return Number(cleaned);
|
|
774
|
-
}
|
|
775
|
-
function sortTarget(state) {
|
|
776
|
-
if (!isInTable(state)) return null;
|
|
777
|
-
const rect = selectedRect(state);
|
|
778
|
-
const table = rect.table;
|
|
779
|
-
let merged = false;
|
|
780
|
-
table.descendants((node) => {
|
|
781
|
-
if (node.attrs.colspan > 1 || node.attrs.rowspan > 1) merged = true;
|
|
782
|
-
return !merged && node.type.spec.tableRole !== "cell" && node.type.spec.tableRole !== "header_cell";
|
|
783
|
-
});
|
|
784
|
-
if (merged) return null;
|
|
785
|
-
const nodes = state.schema.nodes;
|
|
786
|
-
let headerRows = 0;
|
|
787
|
-
for (let i = 0; i < table.childCount; i++) {
|
|
788
|
-
let allHeaders = true;
|
|
789
|
-
table.child(i).forEach((cell) => {
|
|
790
|
-
if (cell.type !== nodes.table_header) allHeaders = false;
|
|
791
|
-
});
|
|
792
|
-
if (!allHeaders) break;
|
|
793
|
-
headerRows++;
|
|
794
|
-
}
|
|
795
|
-
if (table.childCount - headerRows < 2) return null;
|
|
796
|
-
return { pos: rect.tableStart - 1, table, column: rect.left, headerRows };
|
|
797
|
-
}
|
|
798
|
-
function sortTable(direction, locale) {
|
|
799
|
-
return (state, dispatch) => {
|
|
800
|
-
const target = sortTarget(state);
|
|
801
|
-
if (!target) return false;
|
|
802
|
-
if (dispatch) {
|
|
803
|
-
const { table, column, headerRows, pos } = target;
|
|
804
|
-
const rows = [];
|
|
805
|
-
table.forEach((row) => rows.push(row));
|
|
806
|
-
const head = rows.slice(0, headerRows);
|
|
807
|
-
const body = rows.slice(headerRows);
|
|
808
|
-
const texts = body.map(
|
|
809
|
-
(row) => column < row.childCount ? row.child(column).textContent.trim() : ""
|
|
810
|
-
);
|
|
811
|
-
const numbers = texts.map(numericValue);
|
|
812
|
-
const numeric = texts.every((t, i) => t === "" || numbers[i] !== null);
|
|
813
|
-
const collator = new Intl.Collator(locale, { numeric: true, sensitivity: "base" });
|
|
814
|
-
const order = body.map((row, i) => ({ row, i })).sort((a, b) => {
|
|
815
|
-
const ta = texts[a.i];
|
|
816
|
-
const tb = texts[b.i];
|
|
817
|
-
if (!ta || !tb) return ta ? -1 : tb ? 1 : a.i - b.i;
|
|
818
|
-
const cmp = numeric ? numbers[a.i] - numbers[b.i] : collator.compare(ta, tb);
|
|
819
|
-
return (direction === "asc" ? cmp : -cmp) || a.i - b.i;
|
|
820
|
-
}).map(({ row }) => row);
|
|
821
|
-
const sorted = table.copy(Fragment.from([...head, ...order]));
|
|
822
|
-
dispatch(state.tr.replaceWith(pos, pos + table.nodeSize, sorted).scrollIntoView());
|
|
823
|
-
}
|
|
824
|
-
return true;
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
var NovaTableView = class extends TableView {
|
|
828
|
-
constructor(node, cellMinWidth) {
|
|
829
|
-
super(node, cellMinWidth);
|
|
830
|
-
this.apply(node);
|
|
831
|
-
}
|
|
832
|
-
update(node) {
|
|
833
|
-
if (!super.update(node)) return false;
|
|
834
|
-
this.apply(node);
|
|
835
|
-
return true;
|
|
836
|
-
}
|
|
837
|
-
apply(node) {
|
|
838
|
-
const width = cssValue.length(node.attrs.width);
|
|
839
|
-
if (width) {
|
|
840
|
-
this.table.style.width = width;
|
|
841
|
-
this.table.style.minWidth = "";
|
|
842
|
-
}
|
|
843
|
-
const align = node.attrs.align;
|
|
844
|
-
this.table.style.marginLeft = align ? "auto" : "";
|
|
845
|
-
this.table.style.marginRight = align === "center" ? "auto" : "";
|
|
846
|
-
const cls = classAttr(node.attrs.class).class;
|
|
847
|
-
if (cls) this.table.setAttribute("class", cls);
|
|
848
|
-
else this.table.removeAttribute("class");
|
|
849
|
-
}
|
|
850
|
-
};
|
|
851
|
-
function getTableProps(state) {
|
|
852
|
-
const found = findTable(state.selection.$from);
|
|
853
|
-
return found ? {
|
|
854
|
-
width: found.node.attrs.width ?? null,
|
|
855
|
-
align: found.node.attrs.align ?? null,
|
|
856
|
-
class: found.node.attrs.class ?? null
|
|
857
|
-
} : null;
|
|
858
|
-
}
|
|
859
|
-
function setTableProps(props) {
|
|
860
|
-
return (state, dispatch) => {
|
|
861
|
-
const found = findTable(state.selection.$from);
|
|
862
|
-
if (!found) return false;
|
|
863
|
-
if (props.width !== null && !cssValue.length(props.width)) return false;
|
|
864
|
-
const attrs = {
|
|
865
|
-
...found.node.attrs,
|
|
866
|
-
width: props.width,
|
|
867
|
-
align: props.align
|
|
868
|
-
};
|
|
869
|
-
if (props.class !== void 0) attrs.class = classAttr(props.class).class ?? null;
|
|
870
|
-
dispatch?.(state.tr.setNodeMarkup(found.pos, void 0, attrs));
|
|
871
|
-
return true;
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
function selectedCells(state) {
|
|
875
|
-
const out = [];
|
|
876
|
-
if (state.selection instanceof CellSelection) {
|
|
877
|
-
state.selection.forEachCell((node, pos) => out.push({ node, pos }));
|
|
878
|
-
return out;
|
|
879
|
-
}
|
|
880
|
-
const { $from } = state.selection;
|
|
881
|
-
for (let depth = $from.depth; depth > 0; depth--) {
|
|
882
|
-
const node = $from.node(depth);
|
|
883
|
-
const role = node.type.spec.tableRole;
|
|
884
|
-
if (role === "cell" || role === "header_cell") {
|
|
885
|
-
out.push({ node, pos: $from.before(depth) });
|
|
886
|
-
break;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
return out;
|
|
890
|
-
}
|
|
891
|
-
function getCellProps(state) {
|
|
892
|
-
const cell = selectedCells(state)[0];
|
|
893
|
-
if (!cell) return null;
|
|
894
|
-
const widths = cell.node.attrs.colwidth;
|
|
895
|
-
return {
|
|
896
|
-
valign: cell.node.attrs.valign ?? null,
|
|
897
|
-
header: cell.node.type === state.schema.nodes.table_header,
|
|
898
|
-
width: widths?.[0] ?? null,
|
|
899
|
-
class: cell.node.attrs.class ?? null
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
function setCellProps(props) {
|
|
903
|
-
return (state, dispatch) => {
|
|
904
|
-
const cells = selectedCells(state);
|
|
905
|
-
if (!cells.length) return false;
|
|
906
|
-
if (props.width != null && !(props.width >= 24 && props.width <= 4e3)) return false;
|
|
907
|
-
if (!dispatch) return true;
|
|
908
|
-
const nodes = state.schema.nodes;
|
|
909
|
-
const tr = state.tr;
|
|
910
|
-
for (const { pos, node } of cells) {
|
|
911
|
-
const type = props.header === void 0 ? node.type : props.header ? nodes.table_header : nodes.table_cell;
|
|
912
|
-
const attrs = {
|
|
913
|
-
...node.attrs,
|
|
914
|
-
...props.valign !== void 0 ? { valign: props.valign } : {},
|
|
915
|
-
...props.class !== void 0 ? { class: classAttr(props.class).class ?? null } : {}
|
|
916
|
-
};
|
|
917
|
-
tr.setNodeMarkup(pos, type, attrs);
|
|
918
|
-
}
|
|
919
|
-
if (props.width !== void 0) {
|
|
920
|
-
const rect = selectedRect(state);
|
|
921
|
-
const map = rect.map;
|
|
922
|
-
const seen = /* @__PURE__ */ new Set();
|
|
923
|
-
for (let col = rect.left; col < rect.right; col++) {
|
|
924
|
-
for (let row = 0; row < map.height; row++) {
|
|
925
|
-
const cellPos = map.map[row * map.width + col];
|
|
926
|
-
const key = cellPos * 1e3 + col;
|
|
927
|
-
if (seen.has(key)) continue;
|
|
928
|
-
seen.add(key);
|
|
929
|
-
const absolute = rect.tableStart + cellPos;
|
|
930
|
-
const cell = tr.doc.nodeAt(absolute);
|
|
931
|
-
if (!cell) continue;
|
|
932
|
-
const index = col - map.colCount(cellPos);
|
|
933
|
-
const widths = [
|
|
934
|
-
...cell.attrs.colwidth ?? new Array(cell.attrs.colspan).fill(0)
|
|
935
|
-
];
|
|
936
|
-
widths[index] = props.width ?? 0;
|
|
937
|
-
tr.setNodeMarkup(absolute, void 0, {
|
|
938
|
-
...cell.attrs,
|
|
939
|
-
colwidth: widths.every((w) => !w) ? null : widths
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
dispatch(tr);
|
|
945
|
-
return true;
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
|
|
949
702
|
export {
|
|
950
703
|
openDialog,
|
|
951
704
|
textField,
|
|
@@ -957,27 +710,15 @@ export {
|
|
|
957
710
|
imageDropPastePlugin,
|
|
958
711
|
openImageDialog,
|
|
959
712
|
getSelectedImage,
|
|
713
|
+
hasImageCaption,
|
|
714
|
+
toggleImageCaption,
|
|
715
|
+
exitImageCaption,
|
|
960
716
|
setImageAttrs,
|
|
961
717
|
setImageWidthFraction,
|
|
962
718
|
openImageAltDialog,
|
|
963
719
|
normalizeUrl,
|
|
964
720
|
applyLink,
|
|
965
721
|
removeLink,
|
|
966
|
-
openLinkDialog
|
|
967
|
-
isInTable,
|
|
968
|
-
createTable,
|
|
969
|
-
insertTable,
|
|
970
|
-
tablePlugins,
|
|
971
|
-
tableCommands,
|
|
972
|
-
setCellBackground,
|
|
973
|
-
hasHeaderRow,
|
|
974
|
-
hasHeaderColumn,
|
|
975
|
-
tableRect,
|
|
976
|
-
createTableGridPanel,
|
|
977
|
-
sortTable,
|
|
978
|
-
getTableProps,
|
|
979
|
-
setTableProps,
|
|
980
|
-
getCellProps,
|
|
981
|
-
setCellProps
|
|
722
|
+
openLinkDialog
|
|
982
723
|
};
|
|
983
|
-
//# sourceMappingURL=chunk-
|
|
724
|
+
//# sourceMappingURL=chunk-KPE3QRPB.js.map
|