@novaprose/core 0.5.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +57 -20
  2. package/dist/{advlist-FH3K3AAQ.js → advlist-5FNKPLUX.js} +11 -20
  3. package/dist/advlist-5FNKPLUX.js.map +1 -0
  4. package/dist/{autolink-IDJWAL2V.js → autolink-45LTODWB.js} +7 -4
  5. package/dist/{autolink-IDJWAL2V.js.map → autolink-45LTODWB.js.map} +1 -1
  6. package/dist/{autoresize-4ZEPQCHP.js → autoresize-UB3GOA6D.js} +2 -2
  7. package/dist/{autosave-DH7SO4UQ.js → autosave-GMWJ5BPE.js} +7 -11
  8. package/dist/autosave-GMWJ5BPE.js.map +1 -0
  9. package/dist/{charmap-F7EVJ56K.js → charmap-2GC7LF7G.js} +7 -12
  10. package/dist/charmap-2GC7LF7G.js.map +1 -0
  11. package/dist/{chunk-MOO4PJGI.js → chunk-5AW2HHG6.js} +16 -1
  12. package/dist/chunk-5AW2HHG6.js.map +1 -0
  13. package/dist/{chunk-55LD2TT2.js → chunk-DWZLSZDG.js} +1550 -935
  14. package/dist/chunk-DWZLSZDG.js.map +1 -0
  15. package/dist/{chunk-YZPJQB3I.js → chunk-FCMZ7TUQ.js} +308 -34
  16. package/dist/chunk-FCMZ7TUQ.js.map +1 -0
  17. package/dist/{chunk-6GWG2BLC.js → chunk-HPLT3XRZ.js} +1 -1
  18. package/dist/chunk-HPLT3XRZ.js.map +1 -0
  19. package/dist/{chunk-HZRIBOPW.js → chunk-JPJVTB45.js} +38 -2
  20. package/dist/chunk-JPJVTB45.js.map +1 -0
  21. package/dist/{chunk-6AL2IS6V.js → chunk-KPE3QRPB.js} +206 -404
  22. package/dist/chunk-KPE3QRPB.js.map +1 -0
  23. package/dist/chunk-KWXFL4WS.js +174 -0
  24. package/dist/chunk-KWXFL4WS.js.map +1 -0
  25. package/dist/chunk-ND2CWNVG.js +51 -0
  26. package/dist/chunk-ND2CWNVG.js.map +1 -0
  27. package/dist/chunk-PVFKXRID.js +27 -0
  28. package/dist/chunk-PVFKXRID.js.map +1 -0
  29. package/dist/chunk-R2UMUCVI.js +351 -0
  30. package/dist/chunk-R2UMUCVI.js.map +1 -0
  31. package/dist/{chunk-GHEFKKRC.js → chunk-T3GY6IVK.js} +41 -24
  32. package/dist/chunk-T3GY6IVK.js.map +1 -0
  33. package/dist/{comments-panel-FYJE3U64.js → comments-panel-HXMWSRAW.js} +5 -3
  34. package/dist/comments-panel-HXMWSRAW.js.map +1 -0
  35. package/dist/{directionality-MF5HDXH3.js → directionality-5JLWQGP2.js} +13 -11
  36. package/dist/directionality-5JLWQGP2.js.map +1 -0
  37. package/dist/editor-CXkltf1R.d.ts +1886 -0
  38. package/dist/editor-CgSBFTke.d.cts +1886 -0
  39. package/dist/{emoticons-SONBUCFV.js → emoticons-ZD6ZRIWG.js} +7 -12
  40. package/dist/emoticons-ZD6ZRIWG.js.map +1 -0
  41. package/dist/form-dialog-QH6KAERD.js +180 -0
  42. package/dist/form-dialog-QH6KAERD.js.map +1 -0
  43. package/dist/html-rules-api-D3fKQi-R.d.cts +40 -0
  44. package/dist/html-rules-api-D3fKQi-R.d.ts +40 -0
  45. package/dist/html-rules.cjs +480 -0
  46. package/dist/html-rules.cjs.map +1 -0
  47. package/dist/html-rules.d.cts +87 -0
  48. package/dist/html-rules.d.ts +87 -0
  49. package/dist/html-rules.js +413 -0
  50. package/dist/html-rules.js.map +1 -0
  51. package/dist/i18n/de.cjs +324 -0
  52. package/dist/i18n/de.cjs.map +1 -0
  53. package/dist/i18n/de.d.cts +9 -0
  54. package/dist/i18n/de.d.ts +9 -0
  55. package/dist/i18n/de.js +303 -0
  56. package/dist/i18n/de.js.map +1 -0
  57. package/dist/i18n/es.cjs +324 -0
  58. package/dist/i18n/es.cjs.map +1 -0
  59. package/dist/i18n/es.d.cts +9 -0
  60. package/dist/i18n/es.d.ts +9 -0
  61. package/dist/i18n/es.js +303 -0
  62. package/dist/i18n/es.js.map +1 -0
  63. package/dist/i18n/fr.cjs +324 -0
  64. package/dist/i18n/fr.cjs.map +1 -0
  65. package/dist/i18n/fr.d.cts +9 -0
  66. package/dist/i18n/fr.d.ts +9 -0
  67. package/dist/i18n/fr.js +303 -0
  68. package/dist/i18n/fr.js.map +1 -0
  69. package/dist/i18n/it.cjs +324 -0
  70. package/dist/i18n/it.cjs.map +1 -0
  71. package/dist/i18n/it.d.cts +9 -0
  72. package/dist/i18n/it.d.ts +9 -0
  73. package/dist/i18n/it.js +303 -0
  74. package/dist/i18n/it.js.map +1 -0
  75. package/dist/i18n/pt-BR.cjs +324 -0
  76. package/dist/i18n/pt-BR.cjs.map +1 -0
  77. package/dist/i18n/pt-BR.d.cts +9 -0
  78. package/dist/i18n/pt-BR.d.ts +9 -0
  79. package/dist/i18n/pt-BR.js +303 -0
  80. package/dist/i18n/pt-BR.js.map +1 -0
  81. package/dist/i18n/ru.cjs +324 -0
  82. package/dist/i18n/ru.cjs.map +1 -0
  83. package/dist/i18n/ru.d.cts +10 -0
  84. package/dist/i18n/ru.d.ts +10 -0
  85. package/dist/i18n/ru.js +303 -0
  86. package/dist/i18n/ru.js.map +1 -0
  87. package/dist/index-C603bU6r.d.cts +216 -0
  88. package/dist/index-C603bU6r.d.ts +216 -0
  89. package/dist/index.cjs +3422 -1179
  90. package/dist/index.cjs.map +1 -1
  91. package/dist/index.d.cts +50 -1555
  92. package/dist/index.d.ts +50 -1555
  93. package/dist/index.js +278 -147
  94. package/dist/index.js.map +1 -1
  95. package/dist/{insertdatetime-X2T4ZY6R.js → insertdatetime-CRO7TJAQ.js} +10 -16
  96. package/dist/insertdatetime-CRO7TJAQ.js.map +1 -0
  97. package/dist/markdown.cjs +273 -0
  98. package/dist/markdown.cjs.map +1 -0
  99. package/dist/markdown.d.cts +23 -0
  100. package/dist/markdown.d.ts +23 -0
  101. package/dist/markdown.js +241 -0
  102. package/dist/markdown.js.map +1 -0
  103. package/dist/{nonbreaking-PP4KIJSR.js → nonbreaking-66LFZV2W.js} +8 -7
  104. package/dist/nonbreaking-66LFZV2W.js.map +1 -0
  105. package/dist/paste-office-F3QW4WWO.js +440 -0
  106. package/dist/paste-office-F3QW4WWO.js.map +1 -0
  107. package/dist/{quickbars-3WKHLKAR.js → quickbars-7E2QRS7J.js} +13 -9
  108. package/dist/quickbars-7E2QRS7J.js.map +1 -0
  109. package/dist/{revisionhistory-FYRVDGRA.js → revisionhistory-DXE7KU4R.js} +18 -32
  110. package/dist/revisionhistory-DXE7KU4R.js.map +1 -0
  111. package/dist/table-SSNABG5W.js +301 -0
  112. package/dist/table-SSNABG5W.js.map +1 -0
  113. package/dist/{visualblocks-NPTMWFXD.js → visualblocks-6DLBXYOA.js} +8 -7
  114. package/dist/visualblocks-6DLBXYOA.js.map +1 -0
  115. package/package.json +45 -5
  116. package/src/style.css +291 -29
  117. package/dist/advlist-FH3K3AAQ.js.map +0 -1
  118. package/dist/autosave-DH7SO4UQ.js.map +0 -1
  119. package/dist/charmap-F7EVJ56K.js.map +0 -1
  120. package/dist/chunk-55LD2TT2.js.map +0 -1
  121. package/dist/chunk-6AL2IS6V.js.map +0 -1
  122. package/dist/chunk-6GWG2BLC.js.map +0 -1
  123. package/dist/chunk-6RJENZXT.js +0 -104
  124. package/dist/chunk-6RJENZXT.js.map +0 -1
  125. package/dist/chunk-GHEFKKRC.js.map +0 -1
  126. package/dist/chunk-HZRIBOPW.js.map +0 -1
  127. package/dist/chunk-MOO4PJGI.js.map +0 -1
  128. package/dist/chunk-YZPJQB3I.js.map +0 -1
  129. package/dist/comments-panel-FYJE3U64.js.map +0 -1
  130. package/dist/directionality-MF5HDXH3.js.map +0 -1
  131. package/dist/emoticons-SONBUCFV.js.map +0 -1
  132. package/dist/insertdatetime-X2T4ZY6R.js.map +0 -1
  133. package/dist/nonbreaking-PP4KIJSR.js.map +0 -1
  134. package/dist/quickbars-3WKHLKAR.js.map +0 -1
  135. package/dist/revisionhistory-FYRVDGRA.js.map +0 -1
  136. package/dist/visualblocks-NPTMWFXD.js.map +0 -1
  137. /package/dist/{autoresize-4ZEPQCHP.js.map → autoresize-UB3GOA6D.js.map} +0 -0
@@ -1,29 +1,65 @@
1
1
  import {
2
- cssValue,
3
- schema
4
- } from "./chunk-YZPJQB3I.js";
2
+ getLinkAt,
3
+ insertImage,
4
+ markRange,
5
+ marksOf,
6
+ nodesOf
7
+ } from "./chunk-T3GY6IVK.js";
8
+ import {
9
+ icons
10
+ } from "./chunk-5AW2HHG6.js";
5
11
  import {
6
12
  FOCUSABLE,
13
+ activeElement,
7
14
  h,
8
15
  icon,
16
+ listenDocument,
9
17
  uniqueId
10
- } from "./chunk-HZRIBOPW.js";
11
- import {
12
- icons
13
- } from "./chunk-MOO4PJGI.js";
18
+ } from "./chunk-JPJVTB45.js";
14
19
  import {
15
- getLinkAt,
16
- insertImage,
17
20
  isSafeImageUrl,
18
- isSafeLinkUrl,
19
- markRange,
20
- marksOf,
21
- nodesOf
22
- } from "./chunk-GHEFKKRC.js";
21
+ isSafeLinkUrl
22
+ } from "./chunk-PVFKXRID.js";
23
+
24
+ // src/ui/file-picker.ts
25
+ function attachFilePicker(editor, field, type, onPick) {
26
+ const { filePicker: picker, filePickerTypes: types } = editor.options;
27
+ if (!picker || types && !types.includes(type)) return;
28
+ const { input } = field;
29
+ const button = h(
30
+ "button",
31
+ {
32
+ type: "button",
33
+ className: "nova-btn nova-input-action",
34
+ "aria-label": editor.ui.t("dialog.browse"),
35
+ title: editor.ui.t("dialog.browse")
36
+ },
37
+ icon(icons.browse)
38
+ );
39
+ const group = h("div", { className: "nova-input-group" });
40
+ input.replaceWith(group);
41
+ group.append(input, button);
42
+ button.addEventListener("click", async () => {
43
+ button.disabled = true;
44
+ try {
45
+ const result = await picker({ type, value: input.value });
46
+ if (!result?.url) return;
47
+ input.value = result.url;
48
+ input.removeAttribute("aria-invalid");
49
+ onPick?.(result);
50
+ } catch (error) {
51
+ console.error("[nova] filePicker failed:", error);
52
+ } finally {
53
+ button.disabled = false;
54
+ if (input.isConnected) input.focus();
55
+ }
56
+ });
57
+ }
23
58
 
24
59
  // src/image.ts
25
60
  import {
26
61
  NodeSelection,
62
+ TextSelection,
27
63
  Plugin,
28
64
  PluginKey
29
65
  } from "prosemirror-state";
@@ -68,7 +104,7 @@ function openDialog(options) {
68
104
  if (closed) return;
69
105
  closed = true;
70
106
  backdrop.remove();
71
- document.removeEventListener("focusin", keepFocusInside, true);
107
+ stopKeepFocus();
72
108
  options.onClose?.();
73
109
  options.returnFocus?.();
74
110
  };
@@ -109,21 +145,20 @@ function openDialog(options) {
109
145
  const first2 = focusable[0];
110
146
  const last = focusable[focusable.length - 1];
111
147
  if (!first2 || !last) return;
112
- if (event.shiftKey && document.activeElement === first2) {
148
+ if (event.shiftKey && activeElement(form) === first2) {
113
149
  event.preventDefault();
114
150
  last.focus();
115
- } else if (!event.shiftKey && document.activeElement === last) {
151
+ } else if (!event.shiftKey && activeElement(form) === last) {
116
152
  event.preventDefault();
117
153
  first2.focus();
118
154
  }
119
155
  }
120
156
  });
121
- const keepFocusInside = (event) => {
122
- if (!form.contains(event.target)) {
157
+ const stopKeepFocus = listenDocument(form, "focusin", (_event, target) => {
158
+ if (!form.contains(target)) {
123
159
  (form.querySelector(FOCUSABLE) ?? form).focus();
124
160
  }
125
- };
126
- document.addEventListener("focusin", keepFocusInside, true);
161
+ });
127
162
  const first = options.initialFocus ?? form.querySelector(".nova-dialog-body input, .nova-dialog-body textarea");
128
163
  (first ?? (options.submitLabel ? submit : cancel)).focus();
129
164
  return { el: form, close, setError, setBusy };
@@ -213,31 +248,57 @@ function uploadImages(editor, files, pos) {
213
248
  if (pos !== void 0) tr.insert(Math.min(pos, tr.doc.content.size), node);
214
249
  else tr.replaceSelectionWith(node);
215
250
  view.dispatch(tr.scrollIntoView());
216
- const handler = editor.options.uploadImage;
217
- const notice = handler ? editor.ui.notify({ text: editor.ui.t("image.uploading"), timeout: 0 }) : null;
218
- const upload = handler ? handler(
219
- file,
220
- (percent) => notice?.setText(`${editor.ui.t("image.uploading")} ${Math.round(percent)}%`)
221
- ) : readAsDataUrl(file);
222
- upload.then((url) => {
223
- if (!isSafeImageUrl(url)) throw new Error(`Unsafe image URL returned: ${url}`);
224
- const at = findImage(view, blobUrl);
225
- if (at === null) return;
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) {
226
273
  const current = view.state.doc.nodeAt(at);
227
274
  view.dispatch(
228
275
  view.state.tr.setNodeMarkup(at, void 0, { ...current.attrs, src: url }).setMeta("addToHistory", false)
229
276
  );
230
- }).catch((error) => {
231
- console.error("[nova] image upload failed", error);
232
- const at = findImage(view, blobUrl);
233
- if (at !== null)
234
- view.dispatch(view.state.tr.delete(at, at + 1).setMeta("addToHistory", false));
235
- editor.ui.notify({ text: editor.ui.t("image.uploadFailed"), type: "error" });
236
- }).finally(() => {
237
- notice?.close();
238
- URL.revokeObjectURL(blobUrl);
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
239
300
  });
240
- }
301
+ }).finally(() => notice?.close());
241
302
  }
242
303
  var DATA_IMAGE = /^data:(image\/(?:png|jpe?g|gif|webp|avif|bmp));base64,(.+)$/i;
243
304
  function dataUrlToFile(src, name = "pasted-image") {
@@ -277,7 +338,16 @@ async function uploadEmbeddedImage(editor, src) {
277
338
  replaceImageSrc(editor.view, src, url);
278
339
  } catch (error) {
279
340
  console.error("[nova] embedded image upload failed", error);
280
- editor.ui.notify({ text: editor.ui.t("image.uploadFailed"), type: "error" });
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
+ });
281
351
  } finally {
282
352
  notice.close();
283
353
  }
@@ -339,7 +409,10 @@ function openImageDialog(editor) {
339
409
  type: "file",
340
410
  accept: "image/png,image/jpeg,image/gif,image/webp,image/avif",
341
411
  className: "nova-visually-hidden",
342
- tabindex: "-1"
412
+ tabindex: "-1",
413
+ // Выбор файла — через видимую зону ниже; само поле скрыто, но подпись у него обязана быть.
414
+ "aria-label": t("image.drop"),
415
+ "aria-hidden": "true"
343
416
  });
344
417
  const dropzone = h(
345
418
  "button",
@@ -349,6 +422,9 @@ function openImageDialog(editor) {
349
422
  );
350
423
  const url = textField({ label: t("image.url"), type: "url", placeholder: "https://" });
351
424
  const alt = textField({ label: t("image.alt"), hint: t("image.altHint") });
425
+ attachFilePicker(editor, url, "image", (picked) => {
426
+ if (picked.alt) alt.input.value = picked.alt;
427
+ });
352
428
  const body = h(
353
429
  "div",
354
430
  { className: "nova-form" },
@@ -395,18 +471,89 @@ function openImageDialog(editor) {
395
471
  }
396
472
  function getSelectedImage(state) {
397
473
  const { selection } = state;
398
- if (selection instanceof NodeSelection && selection.node.type === nodesOf(state).image) {
399
- return { node: selection.node, pos: selection.from };
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));
400
483
  }
401
484
  return null;
402
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
+ };
403
538
  function setImageAttrs(attrs) {
404
539
  return (state, dispatch) => {
405
540
  const image = getSelectedImage(state);
406
541
  if (!image) return false;
407
542
  if (dispatch) {
408
- const tr = state.tr.setNodeMarkup(image.pos, void 0, { ...image.node.attrs, ...attrs });
409
- tr.setSelection(NodeSelection.create(tr.doc, image.pos));
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
+ }
410
557
  dispatch(tr);
411
558
  }
412
559
  return true;
@@ -430,10 +577,10 @@ function openImageAltDialog(editor) {
430
577
  const { t } = editor.ui;
431
578
  const alt = textField({
432
579
  label: t("image.alt"),
433
- value: image.node.attrs.alt ?? "",
580
+ value: String(image.attrs.alt ?? ""),
434
581
  hint: t("image.altHint")
435
582
  });
436
- const title = textField({ label: t("link.tooltip"), value: image.node.attrs.title ?? "" });
583
+ const title = textField({ label: t("link.tooltip"), value: String(image.attrs.title ?? "") });
437
584
  editor.ui.openDialog({
438
585
  title: t("image.editAlt"),
439
586
  body: h("div", { className: "nova-form" }, alt.el, title.el),
@@ -515,6 +662,10 @@ function openLinkDialog(editor) {
515
662
  const text = textField({ label: t("link.text"), value: selectedText });
516
663
  const title = textField({ label: t("link.tooltip"), value: existing?.title ?? "" });
517
664
  const newTab = checkboxField(t("link.newTab"), existing?.target === "_blank");
665
+ attachFilePicker(editor, url, "file", (picked) => {
666
+ if (picked.text && !text.input.value.trim()) text.input.value = picked.text;
667
+ if (picked.title) title.input.value = picked.title;
668
+ });
518
669
  const body = h(
519
670
  "div",
520
671
  { className: "nova-form" },
@@ -548,375 +699,26 @@ function openLinkDialog(editor) {
548
699
  });
549
700
  }
550
701
 
551
- // src/table.ts
552
- import { keymap } from "prosemirror-keymap";
553
- import { Fragment } from "prosemirror-model";
554
- import { TextSelection } from "prosemirror-state";
555
- import {
556
- addColumnAfter,
557
- addColumnBefore,
558
- addRowAfter,
559
- addRowBefore,
560
- CellSelection,
561
- columnResizing,
562
- deleteColumn,
563
- deleteRow,
564
- deleteTable,
565
- findTable,
566
- goToNextCell,
567
- isInTable,
568
- mergeCells,
569
- selectedRect,
570
- setCellAttr,
571
- splitCell,
572
- tableEditing,
573
- TableView,
574
- toggleHeader
575
- } from "prosemirror-tables";
576
- var MAX_GRID = 10;
577
- function createTable(rows, cols, withHeader = true, schema2 = schema) {
578
- const { table, table_row, table_cell, table_header, paragraph } = schema2.nodes;
579
- const rowNodes = [];
580
- for (let r = 0; r < rows; r++) {
581
- const cellType = withHeader && r === 0 ? table_header : table_cell;
582
- const cells = [];
583
- for (let c = 0; c < cols; c++) cells.push(cellType.create(null, paragraph.create()));
584
- rowNodes.push(table_row.create(null, cells));
585
- }
586
- return table.create(null, rowNodes);
587
- }
588
- function insertTable(rows, cols, withHeader = true) {
589
- return (state, dispatch) => {
590
- if (rows < 1 || cols < 1 || rows > 100 || cols > 50) return false;
591
- if (isInTable(state)) return false;
592
- if (dispatch) {
593
- const node = createTable(rows, cols, withHeader, state.schema);
594
- const tr = state.tr.replaceSelectionWith(node);
595
- let tablePos = -1;
596
- tr.doc.descendants((n, pos) => {
597
- if (n === node) tablePos = pos;
598
- return tablePos < 0;
599
- });
600
- if (tablePos >= 0) tr.setSelection(TextSelection.near(tr.doc.resolve(tablePos + 3)));
601
- dispatch(tr.scrollIntoView());
602
- }
603
- return true;
604
- };
605
- }
606
- var nextCellOrNewRow = (state, dispatch, view) => {
607
- if (!isInTable(state)) return false;
608
- if (goToNextCell(1)(state, dispatch, view)) return true;
609
- if (!dispatch) return true;
610
- let next = state;
611
- addRowAfter(state, (tr) => {
612
- next = state.apply(tr);
613
- dispatch(tr);
614
- });
615
- return goToNextCell(1)(next, dispatch, view);
616
- };
617
- function tablePlugins() {
618
- return [
619
- columnResizing({ cellMinWidth: 48, View: NovaTableView }),
620
- tableEditing(),
621
- keymap({
622
- Tab: nextCellOrNewRow,
623
- "Shift-Tab": goToNextCell(-1)
624
- })
625
- ];
626
- }
627
- var tableCommands = {
628
- addRowBefore,
629
- addRowAfter,
630
- deleteRow,
631
- addColumnBefore,
632
- addColumnAfter,
633
- deleteColumn,
634
- mergeCells,
635
- splitCell,
636
- // Без устаревшей логики (та смотрит на угловую ячейку и путает строку/столбец заголовков).
637
- toggleHeaderRow: toggleHeader("row"),
638
- toggleHeaderColumn: toggleHeader("column"),
639
- deleteTable
640
- };
641
- function setCellBackground(color) {
642
- return setCellAttr("background", color);
643
- }
644
- function hasHeaderRow(state) {
645
- if (!isInTable(state)) return false;
646
- const firstRow = findTable(state.selection.$from)?.node.firstChild;
647
- if (!firstRow || firstRow.childCount === 0) return false;
648
- let all = true;
649
- firstRow.forEach((cell) => {
650
- if (cell.type !== state.schema.nodes.table_header) all = false;
651
- });
652
- return all;
653
- }
654
- function hasHeaderColumn(state) {
655
- if (!isInTable(state)) return false;
656
- const table = findTable(state.selection.$from)?.node;
657
- if (!table) return false;
658
- let all = true;
659
- table.forEach((row) => {
660
- if (row.firstChild?.type !== state.schema.nodes.table_header) all = false;
661
- });
662
- return all;
663
- }
664
- function tableRect(editor) {
665
- const { state } = editor.view;
666
- if (!isInTable(state)) return null;
667
- const table = findTable(state.selection.$from);
668
- if (!table) return null;
669
- const dom = editor.view.nodeDOM(table.pos);
670
- return dom?.getBoundingClientRect() ?? null;
671
- }
672
- function createTableGridPanel(onPick, label, gridLabel) {
673
- let rows = 1;
674
- let cols = 1;
675
- const cells = [];
676
- const caption = h("div", { className: "nova-grid-caption", "aria-live": "polite" });
677
- const grid = h("div", { className: "nova-grid", role: "grid", "aria-label": gridLabel });
678
- const paint = () => {
679
- for (const cell of cells) {
680
- const r = Number(cell.dataset.row);
681
- const c = Number(cell.dataset.col);
682
- cell.classList.toggle("is-on", r <= rows && c <= cols);
683
- cell.tabIndex = r === rows && c === cols ? 0 : -1;
684
- }
685
- caption.textContent = label(rows, cols);
686
- };
687
- for (let r = 1; r <= MAX_GRID; r++) {
688
- for (let c = 1; c <= MAX_GRID; c++) {
689
- const cell = h("button", {
690
- type: "button",
691
- className: "nova-grid-cell",
692
- role: "gridcell",
693
- "aria-label": label(r, c),
694
- "data-row": String(r),
695
- "data-col": String(c)
696
- });
697
- cell.addEventListener("mouseenter", () => {
698
- rows = r;
699
- cols = c;
700
- paint();
701
- });
702
- cell.addEventListener("click", () => onPick(r, c));
703
- cells.push(cell);
704
- grid.append(cell);
705
- }
706
- }
707
- grid.addEventListener("keydown", (event) => {
708
- const moves = {
709
- ArrowRight: [0, 1],
710
- ArrowLeft: [0, -1],
711
- ArrowDown: [1, 0],
712
- ArrowUp: [-1, 0]
713
- };
714
- const move = moves[event.key];
715
- if (!move) return;
716
- event.preventDefault();
717
- rows = Math.min(MAX_GRID, Math.max(1, rows + move[0]));
718
- cols = Math.min(MAX_GRID, Math.max(1, cols + move[1]));
719
- paint();
720
- cells[(rows - 1) * MAX_GRID + (cols - 1)].focus();
721
- });
722
- paint();
723
- return h("div", { className: "nova-grid-panel" }, grid, caption);
724
- }
725
- function numericValue(text) {
726
- const cleaned = text.replace(/\s/g, "").replace(/^[^\d+-]+|[^\d]+$/g, "").replace(/,(?=\d{3}(?:\D|$))/g, "").replace(",", ".");
727
- if (!/^[+-]?\d+(\.\d+)?$/.test(cleaned)) return null;
728
- return Number(cleaned);
729
- }
730
- function sortTarget(state) {
731
- if (!isInTable(state)) return null;
732
- const rect = selectedRect(state);
733
- const table = rect.table;
734
- let merged = false;
735
- table.descendants((node) => {
736
- if (node.attrs.colspan > 1 || node.attrs.rowspan > 1) merged = true;
737
- return !merged && node.type.spec.tableRole !== "cell" && node.type.spec.tableRole !== "header_cell";
738
- });
739
- if (merged) return null;
740
- const nodes = state.schema.nodes;
741
- let headerRows = 0;
742
- for (let i = 0; i < table.childCount; i++) {
743
- let allHeaders = true;
744
- table.child(i).forEach((cell) => {
745
- if (cell.type !== nodes.table_header) allHeaders = false;
746
- });
747
- if (!allHeaders) break;
748
- headerRows++;
749
- }
750
- if (table.childCount - headerRows < 2) return null;
751
- return { pos: rect.tableStart - 1, table, column: rect.left, headerRows };
752
- }
753
- function sortTable(direction, locale) {
754
- return (state, dispatch) => {
755
- const target = sortTarget(state);
756
- if (!target) return false;
757
- if (dispatch) {
758
- const { table, column, headerRows, pos } = target;
759
- const rows = [];
760
- table.forEach((row) => rows.push(row));
761
- const head = rows.slice(0, headerRows);
762
- const body = rows.slice(headerRows);
763
- const texts = body.map(
764
- (row) => column < row.childCount ? row.child(column).textContent.trim() : ""
765
- );
766
- const numbers = texts.map(numericValue);
767
- const numeric = texts.every((t, i) => t === "" || numbers[i] !== null);
768
- const collator = new Intl.Collator(locale, { numeric: true, sensitivity: "base" });
769
- const order = body.map((row, i) => ({ row, i })).sort((a, b) => {
770
- const ta = texts[a.i];
771
- const tb = texts[b.i];
772
- if (!ta || !tb) return ta ? -1 : tb ? 1 : a.i - b.i;
773
- const cmp = numeric ? numbers[a.i] - numbers[b.i] : collator.compare(ta, tb);
774
- return (direction === "asc" ? cmp : -cmp) || a.i - b.i;
775
- }).map(({ row }) => row);
776
- const sorted = table.copy(Fragment.from([...head, ...order]));
777
- dispatch(state.tr.replaceWith(pos, pos + table.nodeSize, sorted).scrollIntoView());
778
- }
779
- return true;
780
- };
781
- }
782
- var NovaTableView = class extends TableView {
783
- constructor(node, cellMinWidth) {
784
- super(node, cellMinWidth);
785
- this.apply(node);
786
- }
787
- update(node) {
788
- if (!super.update(node)) return false;
789
- this.apply(node);
790
- return true;
791
- }
792
- apply(node) {
793
- const width = cssValue.length(node.attrs.width);
794
- if (width) {
795
- this.table.style.width = width;
796
- this.table.style.minWidth = "";
797
- }
798
- const align = node.attrs.align;
799
- this.table.style.marginLeft = align ? "auto" : "";
800
- this.table.style.marginRight = align === "center" ? "auto" : "";
801
- }
802
- };
803
- function getTableProps(state) {
804
- const found = findTable(state.selection.$from);
805
- return found ? { width: found.node.attrs.width ?? null, align: found.node.attrs.align ?? null } : null;
806
- }
807
- function setTableProps(props) {
808
- return (state, dispatch) => {
809
- const found = findTable(state.selection.$from);
810
- if (!found) return false;
811
- if (props.width !== null && !cssValue.length(props.width)) return false;
812
- dispatch?.(state.tr.setNodeMarkup(found.pos, void 0, { ...found.node.attrs, ...props }));
813
- return true;
814
- };
815
- }
816
- function selectedCells(state) {
817
- const out = [];
818
- if (state.selection instanceof CellSelection) {
819
- state.selection.forEachCell((node, pos) => out.push({ node, pos }));
820
- return out;
821
- }
822
- const { $from } = state.selection;
823
- for (let depth = $from.depth; depth > 0; depth--) {
824
- const node = $from.node(depth);
825
- const role = node.type.spec.tableRole;
826
- if (role === "cell" || role === "header_cell") {
827
- out.push({ node, pos: $from.before(depth) });
828
- break;
829
- }
830
- }
831
- return out;
832
- }
833
- function getCellProps(state) {
834
- const cell = selectedCells(state)[0];
835
- if (!cell) return null;
836
- const widths = cell.node.attrs.colwidth;
837
- return {
838
- valign: cell.node.attrs.valign ?? null,
839
- header: cell.node.type === state.schema.nodes.table_header,
840
- width: widths?.[0] ?? null
841
- };
842
- }
843
- function setCellProps(props) {
844
- return (state, dispatch) => {
845
- const cells = selectedCells(state);
846
- if (!cells.length) return false;
847
- if (props.width != null && !(props.width >= 24 && props.width <= 4e3)) return false;
848
- if (!dispatch) return true;
849
- const nodes = state.schema.nodes;
850
- const tr = state.tr;
851
- for (const { pos, node } of cells) {
852
- const type = props.header === void 0 ? node.type : props.header ? nodes.table_header : nodes.table_cell;
853
- const attrs = {
854
- ...node.attrs,
855
- ...props.valign !== void 0 ? { valign: props.valign } : {}
856
- };
857
- tr.setNodeMarkup(pos, type, attrs);
858
- }
859
- if (props.width !== void 0) {
860
- const rect = selectedRect(state);
861
- const map = rect.map;
862
- const seen = /* @__PURE__ */ new Set();
863
- for (let col = rect.left; col < rect.right; col++) {
864
- for (let row = 0; row < map.height; row++) {
865
- const cellPos = map.map[row * map.width + col];
866
- const key = cellPos * 1e3 + col;
867
- if (seen.has(key)) continue;
868
- seen.add(key);
869
- const absolute = rect.tableStart + cellPos;
870
- const cell = tr.doc.nodeAt(absolute);
871
- if (!cell) continue;
872
- const index = col - map.colCount(cellPos);
873
- const widths = [
874
- ...cell.attrs.colwidth ?? new Array(cell.attrs.colspan).fill(0)
875
- ];
876
- widths[index] = props.width ?? 0;
877
- tr.setNodeMarkup(absolute, void 0, {
878
- ...cell.attrs,
879
- colwidth: widths.every((w) => !w) ? null : widths
880
- });
881
- }
882
- }
883
- }
884
- dispatch(tr);
885
- return true;
886
- };
887
- }
888
-
889
702
  export {
890
703
  openDialog,
891
704
  textField,
892
705
  selectField,
706
+ attachFilePicker,
893
707
  isSupportedImage,
894
708
  uploadImages,
895
709
  embeddedImageUploadPlugin,
896
710
  imageDropPastePlugin,
897
711
  openImageDialog,
898
712
  getSelectedImage,
713
+ hasImageCaption,
714
+ toggleImageCaption,
715
+ exitImageCaption,
899
716
  setImageAttrs,
900
717
  setImageWidthFraction,
901
718
  openImageAltDialog,
902
719
  normalizeUrl,
903
720
  applyLink,
904
721
  removeLink,
905
- openLinkDialog,
906
- isInTable,
907
- createTable,
908
- insertTable,
909
- tablePlugins,
910
- tableCommands,
911
- setCellBackground,
912
- hasHeaderRow,
913
- hasHeaderColumn,
914
- tableRect,
915
- createTableGridPanel,
916
- sortTable,
917
- getTableProps,
918
- setTableProps,
919
- getCellProps,
920
- setCellProps
722
+ openLinkDialog
921
723
  };
922
- //# sourceMappingURL=chunk-6AL2IS6V.js.map
724
+ //# sourceMappingURL=chunk-KPE3QRPB.js.map