@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.
Files changed (132) hide show
  1. package/README.md +7 -4
  2. package/dist/{advlist-K2U3VPH2.js → advlist-5FNKPLUX.js} +10 -19
  3. package/dist/advlist-5FNKPLUX.js.map +1 -0
  4. package/dist/{autolink-XWDTLY37.js → autolink-45LTODWB.js} +6 -3
  5. package/dist/{autolink-XWDTLY37.js.map → autolink-45LTODWB.js.map} +1 -1
  6. package/dist/{autosave-MWNRUNU3.js → autosave-GMWJ5BPE.js} +6 -10
  7. package/dist/autosave-GMWJ5BPE.js.map +1 -0
  8. package/dist/{charmap-ADLYOIB3.js → charmap-2GC7LF7G.js} +6 -11
  9. package/dist/charmap-2GC7LF7G.js.map +1 -0
  10. package/dist/{chunk-NPKAIW34.js → chunk-5AW2HHG6.js} +6 -1
  11. package/dist/chunk-5AW2HHG6.js.map +1 -0
  12. package/dist/{chunk-46RIM5KP.js → chunk-DWZLSZDG.js} +689 -974
  13. package/dist/chunk-DWZLSZDG.js.map +1 -0
  14. package/dist/{chunk-7ON7PR5R.js → chunk-FCMZ7TUQ.js} +213 -20
  15. package/dist/chunk-FCMZ7TUQ.js.map +1 -0
  16. package/dist/{chunk-HZRIBOPW.js → chunk-JPJVTB45.js} +38 -2
  17. package/dist/chunk-JPJVTB45.js.map +1 -0
  18. package/dist/{chunk-435CRWKA.js → chunk-KPE3QRPB.js} +163 -422
  19. package/dist/chunk-KPE3QRPB.js.map +1 -0
  20. package/dist/chunk-KWXFL4WS.js +174 -0
  21. package/dist/chunk-KWXFL4WS.js.map +1 -0
  22. package/dist/chunk-ND2CWNVG.js +51 -0
  23. package/dist/chunk-ND2CWNVG.js.map +1 -0
  24. package/dist/chunk-PVFKXRID.js +27 -0
  25. package/dist/chunk-PVFKXRID.js.map +1 -0
  26. package/dist/chunk-R2UMUCVI.js +351 -0
  27. package/dist/chunk-R2UMUCVI.js.map +1 -0
  28. package/dist/{chunk-GHEFKKRC.js → chunk-T3GY6IVK.js} +41 -24
  29. package/dist/chunk-T3GY6IVK.js.map +1 -0
  30. package/dist/{comments-panel-FYJE3U64.js → comments-panel-HXMWSRAW.js} +5 -3
  31. package/dist/comments-panel-HXMWSRAW.js.map +1 -0
  32. package/dist/{directionality-XOHJFSL6.js → directionality-5JLWQGP2.js} +12 -10
  33. package/dist/directionality-5JLWQGP2.js.map +1 -0
  34. package/dist/editor-CXkltf1R.d.ts +1886 -0
  35. package/dist/editor-CgSBFTke.d.cts +1886 -0
  36. package/dist/{emoticons-TP4N4ZGY.js → emoticons-ZD6ZRIWG.js} +6 -11
  37. package/dist/emoticons-ZD6ZRIWG.js.map +1 -0
  38. package/dist/form-dialog-QH6KAERD.js +180 -0
  39. package/dist/form-dialog-QH6KAERD.js.map +1 -0
  40. package/dist/html-rules-api-D3fKQi-R.d.cts +40 -0
  41. package/dist/html-rules-api-D3fKQi-R.d.ts +40 -0
  42. package/dist/html-rules.cjs +480 -0
  43. package/dist/html-rules.cjs.map +1 -0
  44. package/dist/html-rules.d.cts +87 -0
  45. package/dist/html-rules.d.ts +87 -0
  46. package/dist/html-rules.js +413 -0
  47. package/dist/html-rules.js.map +1 -0
  48. package/dist/i18n/de.cjs +324 -0
  49. package/dist/i18n/de.cjs.map +1 -0
  50. package/dist/i18n/de.d.cts +9 -0
  51. package/dist/i18n/de.d.ts +9 -0
  52. package/dist/i18n/de.js +303 -0
  53. package/dist/i18n/de.js.map +1 -0
  54. package/dist/i18n/es.cjs +324 -0
  55. package/dist/i18n/es.cjs.map +1 -0
  56. package/dist/i18n/es.d.cts +9 -0
  57. package/dist/i18n/es.d.ts +9 -0
  58. package/dist/i18n/es.js +303 -0
  59. package/dist/i18n/es.js.map +1 -0
  60. package/dist/i18n/fr.cjs +324 -0
  61. package/dist/i18n/fr.cjs.map +1 -0
  62. package/dist/i18n/fr.d.cts +9 -0
  63. package/dist/i18n/fr.d.ts +9 -0
  64. package/dist/i18n/fr.js +303 -0
  65. package/dist/i18n/fr.js.map +1 -0
  66. package/dist/i18n/it.cjs +324 -0
  67. package/dist/i18n/it.cjs.map +1 -0
  68. package/dist/i18n/it.d.cts +9 -0
  69. package/dist/i18n/it.d.ts +9 -0
  70. package/dist/i18n/it.js +303 -0
  71. package/dist/i18n/it.js.map +1 -0
  72. package/dist/i18n/pt-BR.cjs +324 -0
  73. package/dist/i18n/pt-BR.cjs.map +1 -0
  74. package/dist/i18n/pt-BR.d.cts +9 -0
  75. package/dist/i18n/pt-BR.d.ts +9 -0
  76. package/dist/i18n/pt-BR.js +303 -0
  77. package/dist/i18n/pt-BR.js.map +1 -0
  78. package/dist/i18n/ru.cjs +324 -0
  79. package/dist/i18n/ru.cjs.map +1 -0
  80. package/dist/i18n/ru.d.cts +10 -0
  81. package/dist/i18n/ru.d.ts +10 -0
  82. package/dist/i18n/ru.js +303 -0
  83. package/dist/i18n/ru.js.map +1 -0
  84. package/dist/index-C603bU6r.d.cts +216 -0
  85. package/dist/index-C603bU6r.d.ts +216 -0
  86. package/dist/index.cjs +2159 -1178
  87. package/dist/index.cjs.map +1 -1
  88. package/dist/index.d.cts +46 -1788
  89. package/dist/index.d.ts +46 -1788
  90. package/dist/index.js +96 -152
  91. package/dist/index.js.map +1 -1
  92. package/dist/{insertdatetime-T4SEMQWP.js → insertdatetime-CRO7TJAQ.js} +9 -15
  93. package/dist/insertdatetime-CRO7TJAQ.js.map +1 -0
  94. package/dist/markdown.cjs +273 -0
  95. package/dist/markdown.cjs.map +1 -0
  96. package/dist/markdown.d.cts +23 -0
  97. package/dist/markdown.d.ts +23 -0
  98. package/dist/markdown.js +241 -0
  99. package/dist/markdown.js.map +1 -0
  100. package/dist/{nonbreaking-HG5HV6AL.js → nonbreaking-66LFZV2W.js} +7 -6
  101. package/dist/nonbreaking-66LFZV2W.js.map +1 -0
  102. package/dist/paste-office-F3QW4WWO.js +440 -0
  103. package/dist/paste-office-F3QW4WWO.js.map +1 -0
  104. package/dist/{quickbars-4NU4SIPL.js → quickbars-7E2QRS7J.js} +12 -8
  105. package/dist/quickbars-7E2QRS7J.js.map +1 -0
  106. package/dist/{revisionhistory-3YQPLPLM.js → revisionhistory-DXE7KU4R.js} +17 -31
  107. package/dist/revisionhistory-DXE7KU4R.js.map +1 -0
  108. package/dist/table-SSNABG5W.js +301 -0
  109. package/dist/table-SSNABG5W.js.map +1 -0
  110. package/dist/{visualblocks-RTAYJOGR.js → visualblocks-6DLBXYOA.js} +7 -6
  111. package/dist/visualblocks-6DLBXYOA.js.map +1 -0
  112. package/package.json +45 -5
  113. package/src/style.css +187 -31
  114. package/dist/advlist-K2U3VPH2.js.map +0 -1
  115. package/dist/autosave-MWNRUNU3.js.map +0 -1
  116. package/dist/charmap-ADLYOIB3.js.map +0 -1
  117. package/dist/chunk-435CRWKA.js.map +0 -1
  118. package/dist/chunk-46RIM5KP.js.map +0 -1
  119. package/dist/chunk-6RJENZXT.js +0 -104
  120. package/dist/chunk-6RJENZXT.js.map +0 -1
  121. package/dist/chunk-7ON7PR5R.js.map +0 -1
  122. package/dist/chunk-GHEFKKRC.js.map +0 -1
  123. package/dist/chunk-HZRIBOPW.js.map +0 -1
  124. package/dist/chunk-NPKAIW34.js.map +0 -1
  125. package/dist/comments-panel-FYJE3U64.js.map +0 -1
  126. package/dist/directionality-XOHJFSL6.js.map +0 -1
  127. package/dist/emoticons-TP4N4ZGY.js.map +0 -1
  128. package/dist/insertdatetime-T4SEMQWP.js.map +0 -1
  129. package/dist/nonbreaking-HG5HV6AL.js.map +0 -1
  130. package/dist/quickbars-4NU4SIPL.js.map +0 -1
  131. package/dist/revisionhistory-3YQPLPLM.js.map +0 -1
  132. package/dist/visualblocks-RTAYJOGR.js.map +0 -1
@@ -1,66 +1,88 @@
1
1
  import {
2
- createTableGridPanel,
3
2
  embeddedImageUploadPlugin,
4
- getCellProps,
3
+ exitImageCaption,
5
4
  getSelectedImage,
6
- getTableProps,
7
- hasHeaderColumn,
8
- hasHeaderRow,
5
+ hasImageCaption,
9
6
  imageDropPastePlugin,
10
- insertTable,
11
- isInTable,
12
7
  openDialog,
13
8
  openImageAltDialog,
14
9
  openImageDialog,
15
10
  openLinkDialog,
16
11
  removeLink,
17
12
  selectField,
18
- setCellBackground,
19
- setCellProps,
20
13
  setImageAttrs,
21
14
  setImageWidthFraction,
15
+ textField,
16
+ toggleImageCaption
17
+ } from "./chunk-KPE3QRPB.js";
18
+ import {
19
+ commands,
20
+ getActiveAlign,
21
+ getLinkAt,
22
+ isCommandActive,
23
+ isMarkActive,
24
+ isNodeActive,
25
+ listIndent,
26
+ listOutdent,
27
+ markRange,
28
+ marksOf,
29
+ nodesOf
30
+ } from "./chunk-T3GY6IVK.js";
31
+ import {
32
+ createTableGridPanel,
33
+ getCellProps,
34
+ getTableProps,
35
+ hasHeaderColumn,
36
+ hasHeaderRow,
37
+ insertTable,
38
+ loadTables,
39
+ setCellBackground,
40
+ setCellProps,
22
41
  setTableProps,
23
42
  sortTable,
24
43
  tableCommands,
25
- tablePlugins,
26
- tableRect,
27
- textField
28
- } from "./chunk-435CRWKA.js";
44
+ tableRect
45
+ } from "./chunk-KWXFL4WS.js";
29
46
  import {
30
47
  ALIGNMENTS,
31
48
  classAttr,
32
49
  createSchema,
33
50
  cssValue,
34
51
  imageSize,
52
+ isInTable,
35
53
  schema
36
- } from "./chunk-7ON7PR5R.js";
54
+ } from "./chunk-FCMZ7TUQ.js";
37
55
  import {
38
- formatShortcut,
39
- h,
40
- icon,
41
- uniqueId
42
- } from "./chunk-HZRIBOPW.js";
56
+ createTranslator
57
+ } from "./chunk-R2UMUCVI.js";
43
58
  import {
44
59
  icons
45
- } from "./chunk-NPKAIW34.js";
46
- import {
47
- commands,
48
- getActiveAlign,
49
- getLinkAt,
50
- isCommandActive,
51
- isMarkActive,
52
- isNodeActive,
53
- isSafeImageUrl,
54
- isSafeLinkUrl,
55
- markRange,
56
- marksOf,
57
- nodesOf
58
- } from "./chunk-GHEFKKRC.js";
60
+ } from "./chunk-5AW2HHG6.js";
59
61
  import {
60
62
  loadPlugin,
61
63
  orderPlugins,
62
64
  resolveEntries
63
65
  } from "./chunk-HPLT3XRZ.js";
66
+ import {
67
+ FOCUSABLE,
68
+ activeElement,
69
+ formatShortcut,
70
+ h,
71
+ icon,
72
+ isRtl,
73
+ listenDocument,
74
+ logicalKey,
75
+ uniqueId
76
+ } from "./chunk-JPJVTB45.js";
77
+ import {
78
+ OWN_STYLE,
79
+ htmlRulesFor,
80
+ safeAttr
81
+ } from "./chunk-ND2CWNVG.js";
82
+ import {
83
+ isSafeImageUrl,
84
+ isSafeLinkUrl
85
+ } from "./chunk-PVFKXRID.js";
64
86
 
65
87
  // src/formats.ts
66
88
  import { NodeSelection } from "prosemirror-state";
@@ -332,7 +354,7 @@ function applySpec(state, tr, spec) {
332
354
  }
333
355
  return wrapIn(nodes.blockquote, { class: withClasses(null, classes) })(
334
356
  state,
335
- (wrapped) => wrapped.steps.forEach((step) => tr.step(step))
357
+ (wrapped2) => wrapped2.steps.forEach((step) => tr.step(step))
336
358
  );
337
359
  }
338
360
  if (spec.block === "pre") {
@@ -463,819 +485,10 @@ function removeSpec(state, tr, spec) {
463
485
  }
464
486
  }
465
487
 
466
- // src/i18n/en.ts
467
- var en = {
468
- "toolbar.label": "Formatting",
469
- "toolbar.options": "options",
470
- "editor.label": "Rich text editor",
471
- "editor.required": "Please fill in this field.",
472
- undo: "Undo",
473
- redo: "Redo",
474
- bold: "Bold",
475
- italic: "Italic",
476
- underline: "Underline",
477
- strike: "Strikethrough",
478
- code: "Inline code",
479
- subscript: "Subscript",
480
- superscript: "Superscript",
481
- link: "Link",
482
- unlink: "Remove link",
483
- image: "Image",
484
- bulletList: "Bulleted list",
485
- orderedList: "Numbered list",
486
- indent: "Increase indent",
487
- outdent: "Decrease indent",
488
- align: "Alignment",
489
- alignLeft: "Align left",
490
- alignCenter: "Align center",
491
- alignRight: "Align right",
492
- alignJustify: "Justify",
493
- blockquote: "Quote",
494
- codeBlock: "Code block",
495
- horizontalRule: "Horizontal line",
496
- clearFormatting: "Clear formatting",
497
- more: "More",
498
- moreFormats: "More formatting",
499
- blocks: "Text style",
500
- styles: "Formats",
501
- "styles.headings": "Headings",
502
- "styles.inline": "Inline",
503
- "styles.blocks": "Blocks",
504
- "styles.align": "Align",
505
- paragraph: "Paragraph",
506
- h1: "Heading 1",
507
- h2: "Heading 2",
508
- h3: "Heading 3",
509
- h4: "Heading 4",
510
- h5: "Heading 5",
511
- h6: "Heading 6",
512
- fontFamily: "Font",
513
- fontSize: "Font size",
514
- lineHeight: "Line height",
515
- default: "Default",
516
- textColor: "Text color",
517
- backgroundColor: "Highlight color",
518
- removeColor: "Remove color",
519
- customColor: "Custom color",
520
- "dialog.cancel": "Cancel",
521
- "dialog.save": "Save",
522
- "dialog.insert": "Insert",
523
- "dialog.close": "Close",
524
- "link.title": "Insert link",
525
- "link.editTitle": "Edit link",
526
- "link.url": "URL",
527
- "link.text": "Text to display",
528
- "link.tooltip": "Title (tooltip)",
529
- "link.newTab": "Open in new tab",
530
- "link.open": "Open link",
531
- "link.edit": "Edit link",
532
- "link.copy": "Copy link",
533
- "link.copied": "Link copied",
534
- "link.invalid": "This URL is not allowed",
535
- "image.title": "Insert image",
536
- "image.url": "Image URL",
537
- "image.alt": "Alternative text",
538
- "image.altHint": "Describe the image for people using screen readers",
539
- "image.upload": "Upload",
540
- "image.drop": "Drop an image here or click to choose",
541
- "image.uploading": "Uploading image\u2026",
542
- "image.uploadFailed": "Image upload failed",
543
- "image.invalid": "This image URL is not allowed",
544
- "image.or": "or",
545
- "image.toolbar": "Image options",
546
- "image.alignLeft": "Float left",
547
- "image.alignCenter": "Center",
548
- "image.alignRight": "Float right",
549
- "image.editAlt": "Alternative text",
550
- "image.size": "Size",
551
- "image.sizeSmall": "Small (25%)",
552
- "image.sizeMedium": "Medium (50%)",
553
- "image.sizeLarge": "Large (75%)",
554
- "image.sizeFull": "Full width",
555
- "image.sizeOriginal": "Original size",
556
- "image.delete": "Remove image",
557
- "status.words": "{count} words",
558
- "status.resize": "Resize editor",
559
- "dialog.browse": "Browse",
560
- pasteAsText: "Paste as text",
561
- "menu.label": "Menu",
562
- "menu.file": "File",
563
- "menu.edit": "Edit",
564
- "menu.view": "View",
565
- "menu.insert": "Insert",
566
- "menu.format": "Format",
567
- "menu.table": "Table",
568
- "menu.help": "Help",
569
- selectAll: "Select all",
570
- print: "Print",
571
- "table.rows": "Rows",
572
- "table.cols": "Columns",
573
- "table.invalidSize": "Enter a number from 1 to 50",
574
- "quickbars.selection": "Quick formatting",
575
- "quickbars.insert": "Quick insert",
576
- "search.title": "Find and replace",
577
- "search.find": "Find",
578
- "search.replace": "Replace with",
579
- "search.next": "Next match",
580
- "search.prev": "Previous match",
581
- "search.replaceOne": "Replace",
582
- "search.replaceAll": "Replace all",
583
- "search.matchCase": "Match case",
584
- "search.wholeWord": "Whole words only",
585
- "search.count": "{current} of {total}",
586
- "search.none": "No results",
587
- fullscreen: "Fullscreen",
588
- preview: "Preview",
589
- sourceCode: "Source code",
590
- help: "Keyboard shortcuts",
591
- "help.formatting": "Text formatting",
592
- "help.blocks": "Paragraphs and lists",
593
- "help.editing": "Editing",
594
- "help.navigation": "Navigation",
595
- "help.slash": "Insert block (slash commands)",
596
- "help.toMenubar": "Move to the menu bar",
597
- "help.toToolbar": "Move to the toolbar",
598
- "help.toContextToolbar": "Move to the image/table toolbar",
599
- "help.toEditor": "Back to the text",
600
- "help.nextCell": "Next table cell",
601
- table: "Table",
602
- "table.insert": "Insert table",
603
- "table.size": "{rows} \xD7 {cols}",
604
- "table.toolbar": "Table options",
605
- "table.rowBefore": "Insert row above",
606
- "table.rowAfter": "Insert row below",
607
- "table.rowDelete": "Delete row",
608
- "table.colBefore": "Insert column left",
609
- "table.colAfter": "Insert column right",
610
- "table.colDelete": "Delete column",
611
- "table.merge": "Merge cells",
612
- "table.split": "Split cell",
613
- "table.rowHeader": "Header row",
614
- "table.colHeader": "Header column",
615
- "table.cellBackground": "Cell background",
616
- "table.delete": "Delete table",
617
- "table.sort": "Sort",
618
- "table.sortAsc": "Sort A \u2192 Z, 1 \u2192 9",
619
- "table.sortDesc": "Sort Z \u2192 A, 9 \u2192 1",
620
- "table.props": "Table properties",
621
- "table.style": "Style",
622
- "table.styleDefault": "Default",
623
- "table.width": "Width",
624
- "table.widthHint": "For example 100% or 600px. Leave empty to fit the content.",
625
- "table.invalidWidth": "Enter a width such as 100% or 600px",
626
- "table.align": "Alignment on the page",
627
- "table.alignDefault": "Default",
628
- "table.alignCenter": "Center",
629
- "table.alignRight": "Right",
630
- "table.cellProps": "Cell properties",
631
- "table.valign": "Vertical alignment",
632
- "table.valignTop": "Top",
633
- "table.valignMiddle": "Middle",
634
- "table.valignBottom": "Bottom",
635
- "table.cellType": "Cell type",
636
- "table.cellData": "Data cell",
637
- "table.cellHeader": "Header cell",
638
- "table.colWidth": "Column width, px",
639
- "table.colWidthHint": "Leave empty to fit the content.",
640
- "table.invalidColWidth": "Enter a number from 24 to 4000",
641
- "slash.label": "Commands",
642
- "slash.empty": "No matching commands"
643
- };
644
-
645
- // src/i18n/ru.ts
646
- var ru = {
647
- "toolbar.label": "\u0424\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435",
648
- "toolbar.options": "\u0432\u0430\u0440\u0438\u0430\u043D\u0442\u044B",
649
- "editor.label": "\u0422\u0435\u043A\u0441\u0442\u043E\u0432\u044B\u0439 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440",
650
- "editor.required": "\u0417\u0430\u043F\u043E\u043B\u043D\u0438\u0442\u0435 \u044D\u0442\u043E \u043F\u043E\u043B\u0435.",
651
- undo: "\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C",
652
- redo: "\u041F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C",
653
- bold: "\u0416\u0438\u0440\u043D\u044B\u0439",
654
- italic: "\u041A\u0443\u0440\u0441\u0438\u0432",
655
- underline: "\u041F\u043E\u0434\u0447\u0451\u0440\u043A\u043D\u0443\u0442\u044B\u0439",
656
- strike: "\u0417\u0430\u0447\u0451\u0440\u043A\u043D\u0443\u0442\u044B\u0439",
657
- code: "\u041A\u043E\u0434 \u0432 \u0441\u0442\u0440\u043E\u043A\u0435",
658
- subscript: "\u041F\u043E\u0434\u0441\u0442\u0440\u043E\u0447\u043D\u044B\u0439",
659
- superscript: "\u041D\u0430\u0434\u0441\u0442\u0440\u043E\u0447\u043D\u044B\u0439",
660
- link: "\u0421\u0441\u044B\u043B\u043A\u0430",
661
- unlink: "\u0423\u0431\u0440\u0430\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443",
662
- image: "\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435",
663
- bulletList: "\u041C\u0430\u0440\u043A\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A",
664
- orderedList: "\u041D\u0443\u043C\u0435\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A",
665
- indent: "\u0423\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F",
666
- outdent: "\u0423\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F",
667
- align: "\u0412\u044B\u0440\u0430\u0432\u043D\u0438\u0432\u0430\u043D\u0438\u0435",
668
- alignLeft: "\u041F\u043E \u043B\u0435\u0432\u043E\u043C\u0443 \u043A\u0440\u0430\u044E",
669
- alignCenter: "\u041F\u043E \u0446\u0435\u043D\u0442\u0440\u0443",
670
- alignRight: "\u041F\u043E \u043F\u0440\u0430\u0432\u043E\u043C\u0443 \u043A\u0440\u0430\u044E",
671
- alignJustify: "\u041F\u043E \u0448\u0438\u0440\u0438\u043D\u0435",
672
- blockquote: "\u0426\u0438\u0442\u0430\u0442\u0430",
673
- codeBlock: "\u0411\u043B\u043E\u043A \u043A\u043E\u0434\u0430",
674
- horizontalRule: "\u0413\u043E\u0440\u0438\u0437\u043E\u043D\u0442\u0430\u043B\u044C\u043D\u0430\u044F \u043B\u0438\u043D\u0438\u044F",
675
- clearFormatting: "\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435",
676
- more: "\u0415\u0449\u0451",
677
- moreFormats: "\u0415\u0449\u0451 \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435",
678
- blocks: "\u0421\u0442\u0438\u043B\u044C \u0442\u0435\u043A\u0441\u0442\u0430",
679
- styles: "\u0424\u043E\u0440\u043C\u0430\u0442\u044B",
680
- "styles.headings": "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0438",
681
- "styles.inline": "\u0422\u0435\u043A\u0441\u0442",
682
- "styles.blocks": "\u0411\u043B\u043E\u043A\u0438",
683
- "styles.align": "\u0412\u044B\u0440\u0430\u0432\u043D\u0438\u0432\u0430\u043D\u0438\u0435",
684
- paragraph: "\u041E\u0431\u044B\u0447\u043D\u044B\u0439 \u0442\u0435\u043A\u0441\u0442",
685
- h1: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 1",
686
- h2: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 2",
687
- h3: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 3",
688
- h4: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 4",
689
- h5: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 5",
690
- h6: "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A 6",
691
- fontFamily: "\u0428\u0440\u0438\u0444\u0442",
692
- fontSize: "\u0420\u0430\u0437\u043C\u0435\u0440 \u0448\u0440\u0438\u0444\u0442\u0430",
693
- lineHeight: "\u041C\u0435\u0436\u0441\u0442\u0440\u043E\u0447\u043D\u044B\u0439 \u0438\u043D\u0442\u0435\u0440\u0432\u0430\u043B",
694
- default: "\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E",
695
- textColor: "\u0426\u0432\u0435\u0442 \u0442\u0435\u043A\u0441\u0442\u0430",
696
- backgroundColor: "\u0426\u0432\u0435\u0442 \u0432\u044B\u0434\u0435\u043B\u0435\u043D\u0438\u044F",
697
- removeColor: "\u0423\u0431\u0440\u0430\u0442\u044C \u0446\u0432\u0435\u0442",
698
- customColor: "\u0421\u0432\u043E\u0439 \u0446\u0432\u0435\u0442",
699
- "dialog.cancel": "\u041E\u0442\u043C\u0435\u043D\u0430",
700
- "dialog.save": "\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C",
701
- "dialog.insert": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C",
702
- "dialog.close": "\u0417\u0430\u043A\u0440\u044B\u0442\u044C",
703
- "link.title": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443",
704
- "link.editTitle": "\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443",
705
- "link.url": "\u0410\u0434\u0440\u0435\u0441",
706
- "link.text": "\u0422\u0435\u043A\u0441\u0442 \u0441\u0441\u044B\u043B\u043A\u0438",
707
- "link.tooltip": "\u041F\u043E\u0434\u0441\u043A\u0430\u0437\u043A\u0430 (title)",
708
- "link.newTab": "\u041E\u0442\u043A\u0440\u044B\u0432\u0430\u0442\u044C \u0432 \u043D\u043E\u0432\u043E\u0439 \u0432\u043A\u043B\u0430\u0434\u043A\u0435",
709
- "link.open": "\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443",
710
- "link.edit": "\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443",
711
- "link.copy": "\u041A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443",
712
- "link.copied": "\u0421\u0441\u044B\u043B\u043A\u0430 \u0441\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u0430",
713
- "link.invalid": "\u0422\u0430\u043A\u043E\u0439 \u0430\u0434\u0440\u0435\u0441 \u043D\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043D",
714
- "image.title": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435",
715
- "image.url": "\u0410\u0434\u0440\u0435\u0441 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F",
716
- "image.alt": "\u0410\u043B\u044C\u0442\u0435\u0440\u043D\u0430\u0442\u0438\u0432\u043D\u044B\u0439 \u0442\u0435\u043A\u0441\u0442",
717
- "image.altHint": "\u041E\u043F\u0438\u0448\u0438\u0442\u0435 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0434\u043B\u044F \u043B\u044E\u0434\u0435\u0439, \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u044E\u0449\u0438\u0445 \u044D\u043A\u0440\u0430\u043D\u043D\u044B\u0439 \u0434\u0438\u043A\u0442\u043E\u0440",
718
- "image.upload": "\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C",
719
- "image.drop": "\u041F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0441\u044E\u0434\u0430 \u0438\u043B\u0438 \u043D\u0430\u0436\u043C\u0438\u0442\u0435, \u0447\u0442\u043E\u0431\u044B \u0432\u044B\u0431\u0440\u0430\u0442\u044C",
720
- "image.uploading": "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F\u2026",
721
- "image.uploadFailed": "\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435",
722
- "image.invalid": "\u0422\u0430\u043A\u043E\u0439 \u0430\u0434\u0440\u0435\u0441 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u043D\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043D",
723
- "image.or": "\u0438\u043B\u0438",
724
- "image.toolbar": "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F",
725
- "image.alignLeft": "\u041E\u0431\u0442\u0435\u043A\u0430\u043D\u0438\u0435, \u0441\u043B\u0435\u0432\u0430",
726
- "image.alignCenter": "\u041F\u043E \u0446\u0435\u043D\u0442\u0440\u0443",
727
- "image.alignRight": "\u041E\u0431\u0442\u0435\u043A\u0430\u043D\u0438\u0435, \u0441\u043F\u0440\u0430\u0432\u0430",
728
- "image.editAlt": "\u0410\u043B\u044C\u0442\u0435\u0440\u043D\u0430\u0442\u0438\u0432\u043D\u044B\u0439 \u0442\u0435\u043A\u0441\u0442",
729
- "image.size": "\u0420\u0430\u0437\u043C\u0435\u0440",
730
- "image.sizeSmall": "\u041C\u0430\u043B\u0435\u043D\u044C\u043A\u0438\u0439 (25%)",
731
- "image.sizeMedium": "\u0421\u0440\u0435\u0434\u043D\u0438\u0439 (50%)",
732
- "image.sizeLarge": "\u0411\u043E\u043B\u044C\u0448\u043E\u0439 (75%)",
733
- "image.sizeFull": "\u0412\u043E \u0432\u0441\u044E \u0448\u0438\u0440\u0438\u043D\u0443",
734
- "image.sizeOriginal": "\u0418\u0441\u0445\u043E\u0434\u043D\u044B\u0439 \u0440\u0430\u0437\u043C\u0435\u0440",
735
- "image.delete": "\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435",
736
- "status.words": "\u0421\u043B\u043E\u0432: {count}",
737
- "status.resize": "\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C \u0440\u0430\u0437\u043C\u0435\u0440 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440\u0430",
738
- "dialog.browse": "\u041E\u0431\u0437\u043E\u0440",
739
- pasteAsText: "\u0412\u0441\u0442\u0430\u0432\u043B\u044F\u0442\u044C \u043A\u0430\u043A \u0442\u0435\u043A\u0441\u0442",
740
- "menu.label": "\u041C\u0435\u043D\u044E",
741
- "menu.file": "\u0424\u0430\u0439\u043B",
742
- "menu.edit": "\u041F\u0440\u0430\u0432\u043A\u0430",
743
- "menu.view": "\u0412\u0438\u0434",
744
- "menu.insert": "\u0412\u0441\u0442\u0430\u0432\u043A\u0430",
745
- "menu.format": "\u0424\u043E\u0440\u043C\u0430\u0442",
746
- "menu.table": "\u0422\u0430\u0431\u043B\u0438\u0446\u0430",
747
- "menu.help": "\u0421\u043F\u0440\u0430\u0432\u043A\u0430",
748
- selectAll: "\u0412\u044B\u0434\u0435\u043B\u0438\u0442\u044C \u0432\u0441\u0451",
749
- print: "\u041F\u0435\u0447\u0430\u0442\u044C",
750
- "table.rows": "\u0421\u0442\u0440\u043E\u043A\u0438",
751
- "table.cols": "\u0421\u0442\u043E\u043B\u0431\u0446\u044B",
752
- "table.invalidSize": "\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043B\u043E \u043E\u0442 1 \u0434\u043E 50",
753
- "quickbars.selection": "\u0411\u044B\u0441\u0442\u0440\u043E\u0435 \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435",
754
- "quickbars.insert": "\u0411\u044B\u0441\u0442\u0440\u0430\u044F \u0432\u0441\u0442\u0430\u0432\u043A\u0430",
755
- "search.title": "\u041D\u0430\u0439\u0442\u0438 \u0438 \u0437\u0430\u043C\u0435\u043D\u0438\u0442\u044C",
756
- "search.find": "\u041D\u0430\u0439\u0442\u0438",
757
- "search.replace": "\u0417\u0430\u043C\u0435\u043D\u0438\u0442\u044C \u043D\u0430",
758
- "search.next": "\u0421\u043B\u0435\u0434\u0443\u044E\u0449\u0435\u0435 \u0441\u043E\u0432\u043F\u0430\u0434\u0435\u043D\u0438\u0435",
759
- "search.prev": "\u041F\u0440\u0435\u0434\u044B\u0434\u0443\u0449\u0435\u0435 \u0441\u043E\u0432\u043F\u0430\u0434\u0435\u043D\u0438\u0435",
760
- "search.replaceOne": "\u0417\u0430\u043C\u0435\u043D\u0438\u0442\u044C",
761
- "search.replaceAll": "\u0417\u0430\u043C\u0435\u043D\u0438\u0442\u044C \u0432\u0441\u0435",
762
- "search.matchCase": "\u0423\u0447\u0438\u0442\u044B\u0432\u0430\u0442\u044C \u0440\u0435\u0433\u0438\u0441\u0442\u0440",
763
- "search.wholeWord": "\u0422\u043E\u043B\u044C\u043A\u043E \u0441\u043B\u043E\u0432\u043E \u0446\u0435\u043B\u0438\u043A\u043E\u043C",
764
- "search.count": "{current} \u0438\u0437 {total}",
765
- "search.none": "\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E",
766
- fullscreen: "\u041D\u0430 \u0432\u0435\u0441\u044C \u044D\u043A\u0440\u0430\u043D",
767
- preview: "\u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440",
768
- sourceCode: "HTML-\u043A\u043E\u0434",
769
- help: "\u0413\u043E\u0440\u044F\u0447\u0438\u0435 \u043A\u043B\u0430\u0432\u0438\u0448\u0438",
770
- "help.formatting": "\u0424\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0442\u0435\u043A\u0441\u0442\u0430",
771
- "help.blocks": "\u0410\u0431\u0437\u0430\u0446\u044B \u0438 \u0441\u043F\u0438\u0441\u043A\u0438",
772
- "help.editing": "\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435",
773
- "help.navigation": "\u041D\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044F",
774
- "help.slash": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0431\u043B\u043E\u043A (\u0441\u043B\u044D\u0448-\u043A\u043E\u043C\u0430\u043D\u0434\u044B)",
775
- "help.toMenubar": "\u041F\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u0433\u043B\u0430\u0432\u043D\u043E\u0435 \u043C\u0435\u043D\u044E",
776
- "help.toToolbar": "\u041F\u0435\u0440\u0435\u0439\u0442\u0438 \u043D\u0430 \u043F\u0430\u043D\u0435\u043B\u044C \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u043E\u0432",
777
- "help.toContextToolbar": "\u041F\u0435\u0440\u0435\u0439\u0442\u0438 \u043D\u0430 \u043F\u0430\u043D\u0435\u043B\u044C \u043A\u0430\u0440\u0442\u0438\u043D\u043A\u0438/\u0442\u0430\u0431\u043B\u0438\u0446\u044B",
778
- "help.toEditor": "\u0412\u0435\u0440\u043D\u0443\u0442\u044C\u0441\u044F \u0432 \u0442\u0435\u043A\u0441\u0442",
779
- "help.nextCell": "\u0421\u043B\u0435\u0434\u0443\u044E\u0449\u0430\u044F \u044F\u0447\u0435\u0439\u043A\u0430 \u0442\u0430\u0431\u043B\u0438\u0446\u044B",
780
- table: "\u0422\u0430\u0431\u043B\u0438\u0446\u0430",
781
- "table.insert": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0442\u0430\u0431\u043B\u0438\u0446\u0443",
782
- "table.size": "{rows} \xD7 {cols}",
783
- "table.toolbar": "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0442\u0430\u0431\u043B\u0438\u0446\u044B",
784
- "table.rowBefore": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443 \u0432\u044B\u0448\u0435",
785
- "table.rowAfter": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443 \u043D\u0438\u0436\u0435",
786
- "table.rowDelete": "\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u0443",
787
- "table.colBefore": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446 \u0441\u043B\u0435\u0432\u0430",
788
- "table.colAfter": "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446 \u0441\u043F\u0440\u0430\u0432\u0430",
789
- "table.colDelete": "\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u043E\u043B\u0431\u0435\u0446",
790
- "table.merge": "\u041E\u0431\u044A\u0435\u0434\u0438\u043D\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0438",
791
- "table.split": "\u0420\u0430\u0437\u0434\u0435\u043B\u0438\u0442\u044C \u044F\u0447\u0435\u0439\u043A\u0443",
792
- "table.rowHeader": "\u0421\u0442\u0440\u043E\u043A\u0430 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u043E\u0432",
793
- "table.colHeader": "\u0421\u0442\u043E\u043B\u0431\u0435\u0446 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u043E\u0432",
794
- "table.cellBackground": "\u0424\u043E\u043D \u044F\u0447\u0435\u0439\u043A\u0438",
795
- "table.delete": "\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0442\u0430\u0431\u043B\u0438\u0446\u0443",
796
- "table.sort": "\u0421\u043E\u0440\u0442\u0438\u0440\u043E\u0432\u043A\u0430",
797
- "table.sortAsc": "\u0421\u043E\u0440\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0410 \u2192 \u042F, 1 \u2192 9",
798
- "table.sortDesc": "\u0421\u043E\u0440\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u042F \u2192 \u0410, 9 \u2192 1",
799
- "table.props": "\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430 \u0442\u0430\u0431\u043B\u0438\u0446\u044B",
800
- "table.style": "\u0421\u0442\u0438\u043B\u044C",
801
- "table.styleDefault": "\u041E\u0431\u044B\u0447\u043D\u044B\u0439",
802
- "table.width": "\u0428\u0438\u0440\u0438\u043D\u0430",
803
- "table.widthHint": "\u041D\u0430\u043F\u0440\u0438\u043C\u0435\u0440, 100% \u0438\u043B\u0438 600px. \u041F\u0443\u0441\u0442\u043E \u2014 \u043F\u043E \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u043C\u0443.",
804
- "table.invalidWidth": "\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u0448\u0438\u0440\u0438\u043D\u0443, \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 100% \u0438\u043B\u0438 600px",
805
- "table.align": "\u0412\u044B\u0440\u0430\u0432\u043D\u0438\u0432\u0430\u043D\u0438\u0435 \u043D\u0430 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0435",
806
- "table.alignDefault": "\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E",
807
- "table.alignCenter": "\u041F\u043E \u0446\u0435\u043D\u0442\u0440\u0443",
808
- "table.alignRight": "\u0421\u043F\u0440\u0430\u0432\u0430",
809
- "table.cellProps": "\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430 \u044F\u0447\u0435\u0439\u043A\u0438",
810
- "table.valign": "\u0412\u0435\u0440\u0442\u0438\u043A\u0430\u043B\u044C\u043D\u043E\u0435 \u0432\u044B\u0440\u0430\u0432\u043D\u0438\u0432\u0430\u043D\u0438\u0435",
811
- "table.valignTop": "\u0421\u0432\u0435\u0440\u0445\u0443",
812
- "table.valignMiddle": "\u041F\u043E \u0446\u0435\u043D\u0442\u0440\u0443",
813
- "table.valignBottom": "\u0421\u043D\u0438\u0437\u0443",
814
- "table.cellType": "\u0422\u0438\u043F \u044F\u0447\u0435\u0439\u043A\u0438",
815
- "table.cellData": "\u041E\u0431\u044B\u0447\u043D\u0430\u044F",
816
- "table.cellHeader": "\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A",
817
- "table.colWidth": "\u0428\u0438\u0440\u0438\u043D\u0430 \u0441\u0442\u043E\u043B\u0431\u0446\u0430, px",
818
- "table.colWidthHint": "\u041F\u0443\u0441\u0442\u043E \u2014 \u043F\u043E \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u043C\u0443.",
819
- "table.invalidColWidth": "\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043B\u043E \u043E\u0442 24 \u0434\u043E 4000",
820
- "slash.label": "\u041A\u043E\u043C\u0430\u043D\u0434\u044B",
821
- "slash.empty": "\u041D\u0435\u0442 \u043F\u043E\u0434\u0445\u043E\u0434\u044F\u0449\u0438\u0445 \u043A\u043E\u043C\u0430\u043D\u0434"
822
- };
823
-
824
- // src/i18n/index.ts
825
- var builtin = { en, ru };
826
- function registerLanguage(code, messages) {
827
- builtin[code.toLowerCase()] = { ...en, ...messages };
828
- }
829
- function createTranslator(language = "en", overrides = {}) {
830
- const code = language.toLowerCase();
831
- const pack = builtin[code] ?? builtin[code.split("-")[0]] ?? en;
832
- const messages = { ...en, ...pack, ...overrides };
833
- return (key3, params) => {
834
- const template = messages[key3] ?? key3;
835
- if (!params) return template;
836
- return template.replace(/\{(\w+)\}/g, (_, name) => String(params[name] ?? `{${name}}`));
837
- };
838
- }
839
-
840
488
  // src/paste.ts
841
489
  import { Slice } from "prosemirror-model";
842
490
  import { Plugin, PluginKey } from "prosemirror-state";
843
491
 
844
- // src/paste-office.ts
845
- function detectPasteSource(html) {
846
- if (/data-pm-slice=/.test(html)) return "nova";
847
- if (/<google-sheets-html-origin|data-sheets-(root|value)/i.test(html)) return "google-sheets";
848
- if (/id="docs-internal-guid-/.test(html)) return "google-docs";
849
- if (/urn:schemas-microsoft-com:office:excel|ProgId"?\s+content="?Excel\.Sheet/i.test(html))
850
- return "excel";
851
- if (/urn:schemas-microsoft-com:office:word|class="?Mso|mso-list:|content="?Microsoft Word/i.test(
852
- html
853
- ))
854
- return "word";
855
- if (/class="[^"]*\b(TextRun|OutlineElement|EOP|SCXW\d+|BCX\d+)\b|data-ccp-props|paraid=/.test(html))
856
- return "word-online";
857
- if (/content="?LibreOffice|content="?OpenOffice/i.test(html)) return "libreoffice";
858
- return "web";
859
- }
860
- function cleanPastedHTML(html, styles = "clean") {
861
- const source = detectPasteSource(html);
862
- if (source === "nova") return html;
863
- const template = document.createElement("template");
864
- template.innerHTML = html;
865
- const root = document.createElement("div");
866
- root.append(template.content);
867
- inlineClassStyles(root);
868
- removeJunk(root);
869
- if (source === "word") convertWordLists(root);
870
- if (source === "google-docs") unwrapGoogleDocsWrapper(root);
871
- normalizeLists(root);
872
- convertWordParagraphStyles(root);
873
- root.querySelectorAll("[style]").forEach((el) => cleanStyle(el, styles));
874
- if (styles === "clean") stripLayoutAttributes(root);
875
- unwrapMeaningless(root);
876
- removeBreaksBetweenBlocks(root);
877
- normalizeEmptyParagraphs(root);
878
- wrapCellContent(root);
879
- if (source !== "web")
880
- root.querySelectorAll("[class]").forEach((el) => el.removeAttribute("class"));
881
- return root.innerHTML;
882
- }
883
- function parseDeclarations(css) {
884
- const out = /* @__PURE__ */ new Map();
885
- for (const part of css.split(";")) {
886
- const colon = part.indexOf(":");
887
- if (colon < 0) continue;
888
- const name = part.slice(0, colon).trim().toLowerCase();
889
- const value = part.slice(colon + 1).trim().replace(/\s*!important$/i, "");
890
- if (name && value) out.set(name, value);
891
- }
892
- return out;
893
- }
894
- function serializeDeclarations(decls) {
895
- return [...decls].map(([name, value]) => `${name}: ${value}`).join("; ");
896
- }
897
- function inlineClassStyles(root) {
898
- const sheets = [...root.querySelectorAll("style")].map((s) => s.textContent ?? "");
899
- if (!sheets.length) return;
900
- const rules = [];
901
- const css = sheets.join("\n").replace(/\/\*[\s\S]*?\*\//g, "").replace(/<!--|-->/g, "");
902
- for (const match of css.matchAll(/([^{}@]+)\{([^{}]*)\}/g)) {
903
- const decls = parseDeclarations(match[2]);
904
- for (const selector of match[1].split(",")) {
905
- const m = selector.trim().match(/^([a-z][a-z0-9]*)?\.([\w-]+)$/i);
906
- if (m) rules.push({ tag: (m[1] ?? "").toLowerCase(), cls: m[2], decls });
907
- }
908
- }
909
- if (!rules.length) return;
910
- root.querySelectorAll("[class]").forEach((el) => {
911
- const classes = el.className.split(/\s+/).filter(Boolean);
912
- const merged = /* @__PURE__ */ new Map();
913
- for (const rule of rules) {
914
- if (!classes.includes(rule.cls)) continue;
915
- if (rule.tag && rule.tag !== el.tagName.toLowerCase()) continue;
916
- rule.decls.forEach((value, name) => merged.set(name, value));
917
- }
918
- if (!merged.size) return;
919
- parseDeclarations(el.getAttribute("style") ?? "").forEach(
920
- (value, name) => merged.set(name, value)
921
- );
922
- el.setAttribute("style", serializeDeclarations(merged));
923
- });
924
- }
925
- var DROP_TAGS = /^(STYLE|SCRIPT|META|LINK|TITLE|XML|HEAD|NOSCRIPT|TEMPLATE)$/;
926
- function removeJunk(root) {
927
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
928
- const comments = [];
929
- while (walker.nextNode()) comments.push(walker.currentNode);
930
- comments.forEach((c) => c.parentNode?.removeChild(c));
931
- for (const el of [...root.querySelectorAll("*")]) {
932
- if (!root.contains(el)) continue;
933
- const tag = el.tagName.toUpperCase();
934
- if (DROP_TAGS.test(tag)) {
935
- el.remove();
936
- continue;
937
- }
938
- if (tag.includes(":")) {
939
- const prefix = tag.split(":")[0];
940
- if (prefix === "O" || prefix === "V") el.remove();
941
- else unwrap(el);
942
- }
943
- }
944
- root.querySelectorAll("span.EOP").forEach((span) => {
945
- if (/^\s*$/.test(span.textContent ?? "")) span.remove();
946
- });
947
- root.querySelectorAll("a").forEach((a) => {
948
- const href = a.getAttribute("href") ?? "";
949
- const redirect = href.match(/^https?:\/\/(www\.)?google\.[a-z.]+\/url\?(.*)$/i);
950
- if (redirect) {
951
- const target = new URLSearchParams(redirect[2]).get("q");
952
- if (target) a.setAttribute("href", target);
953
- }
954
- if (!href || /^#_(ftn|edn|msocom|Toc|Ref)/i.test(href)) unwrap(a);
955
- });
956
- root.querySelectorAll('br[style*="page-break"]').forEach((br) => br.remove());
957
- root.querySelectorAll(
958
- '[style*="mso-element:footnote-list"], [style*="mso-element:comment-list"], [style*="mso-element:endnote-list"]'
959
- ).forEach((el) => el.remove());
960
- }
961
- var ORDERED_MARKER = /^[([]?(\d+(\.\d+)*[.)\]]?|[a-z]{1,4}[.)\]])$/i;
962
- function readWordListItem(el) {
963
- const css = el.getAttribute("style") ?? "";
964
- const match = css.match(/mso-list:\s*(l\d+)\s+level(\d+)/i);
965
- if (!match) return null;
966
- const markerEl = [...el.querySelectorAll("[style]")].find(
967
- (s) => /mso-list:\s*Ignore/i.test(s.getAttribute("style") ?? "")
968
- );
969
- const marker = (markerEl?.textContent ?? "").replace(/\s+/g, "");
970
- markerEl?.remove();
971
- const ordered = ORDERED_MARKER.test(marker);
972
- const { style, start } = ordered ? numbering(marker) : { style: bulletStyle(marker), start: 1 };
973
- return {
974
- el,
975
- level: Math.max(1, Math.min(9, Number(match[2]))),
976
- ordered,
977
- start,
978
- style
979
- };
980
- }
981
- var ROMAN = /^(i|ii|iii|iv|v|vi|vii|viii|ix|x|xi|xii)$/i;
982
- var ROMAN_VALUES = { i: 1, v: 5, x: 10 };
983
- function romanToNumber(roman) {
984
- let total = 0;
985
- const chars = roman.toLowerCase();
986
- for (let i = 0; i < chars.length; i++) {
987
- const value = ROMAN_VALUES[chars[i]];
988
- const next = ROMAN_VALUES[chars[i + 1] ?? ""] ?? 0;
989
- total += value < next ? -value : value;
990
- }
991
- return total;
992
- }
993
- function numbering(marker) {
994
- const digits = marker.match(/\d+/);
995
- if (digits) return { style: null, start: Number(digits[0]) };
996
- const letters = marker.replace(/[^a-z]/gi, "");
997
- if (ROMAN.test(letters)) {
998
- return {
999
- style: letters === letters.toLowerCase() ? "lower-roman" : "upper-roman",
1000
- start: romanToNumber(letters)
1001
- };
1002
- }
1003
- const lower = letters === letters.toLowerCase();
1004
- return {
1005
- style: lower ? "lower-alpha" : "upper-alpha",
1006
- start: letters.toLowerCase().charCodeAt(0) - 96
1007
- };
1008
- }
1009
- function bulletStyle(marker) {
1010
- if (marker === "o") return "circle";
1011
- if (/^[§▪■]$/.test(marker)) return "square";
1012
- return null;
1013
- }
1014
- function convertWordLists(root) {
1015
- const candidates = [
1016
- ...root.querySelectorAll("p, div, h1, h2, h3, h4, h5, h6")
1017
- ].filter((el) => /mso-list:\s*l\d+\s+level\d+/i.test(el.getAttribute("style") ?? ""));
1018
- for (const heading of candidates.filter((el) => /^H[1-6]$/.test(el.tagName))) {
1019
- heading.querySelectorAll("[style]").forEach((s) => {
1020
- if (!/mso-list:\s*Ignore/i.test(s.getAttribute("style") ?? "")) return;
1021
- const marker = (s.textContent ?? "").replace(/\s+/g, "");
1022
- s.replaceWith(s.ownerDocument.createTextNode(`${marker} `));
1023
- });
1024
- }
1025
- const paragraphs = candidates.filter((el) => !/^H[1-6]$/.test(el.tagName));
1026
- const done = /* @__PURE__ */ new Set();
1027
- for (const first of paragraphs) {
1028
- if (done.has(first)) continue;
1029
- const run = [];
1030
- let node = first;
1031
- while (node instanceof HTMLElement && paragraphs.includes(node)) {
1032
- const item = readWordListItem(node);
1033
- if (!item) break;
1034
- run.push(item);
1035
- done.add(node);
1036
- node = nextElement(node);
1037
- }
1038
- if (run.length) buildNestedList(run);
1039
- }
1040
- }
1041
- function nextElement(el) {
1042
- let next = el.nextSibling;
1043
- while (next && next.nodeType === Node.TEXT_NODE && !next.textContent?.trim())
1044
- next = next.nextSibling;
1045
- return next instanceof Element ? next : null;
1046
- }
1047
- function buildNestedList(run) {
1048
- const doc = run[0].el.ownerDocument;
1049
- const anchor = run[0].el;
1050
- const stack = [];
1051
- let top = null;
1052
- for (const item of run) {
1053
- while (stack.length && stack[stack.length - 1].level > item.level) stack.pop();
1054
- let current = stack[stack.length - 1];
1055
- if (!current || current.level < item.level) {
1056
- const list = doc.createElement(item.ordered ? "ol" : "ul");
1057
- if (item.ordered && item.start !== 1) list.setAttribute("start", String(item.start));
1058
- if (item.style) list.style.listStyleType = item.style;
1059
- if (current) {
1060
- const parentItem = current.list.lastElementChild ?? current.list.appendChild(doc.createElement("li"));
1061
- parentItem.appendChild(list);
1062
- } else top = list;
1063
- current = { list, level: item.level };
1064
- stack.push(current);
1065
- }
1066
- const li = doc.createElement("li");
1067
- const p = doc.createElement("p");
1068
- while (item.el.firstChild) p.appendChild(item.el.firstChild);
1069
- li.appendChild(p);
1070
- current.list.appendChild(li);
1071
- }
1072
- anchor.replaceWith(top);
1073
- run.slice(1).forEach((item) => item.el.remove());
1074
- }
1075
- function levelOf(li) {
1076
- const raw = li.getAttribute("aria-level") ?? li.getAttribute("data-aria-level");
1077
- const n = raw ? Number(raw) : NaN;
1078
- return Number.isFinite(n) && n >= 1 ? Math.min(9, n) : null;
1079
- }
1080
- function normalizeLists(root) {
1081
- root.querySelectorAll("div").forEach((div) => {
1082
- const only = div.children.length === 1 ? div.firstElementChild : null;
1083
- if (only && /^(UL|OL)$/.test(only.tagName) && !div.textContent?.replace(only.textContent ?? "", "").trim())
1084
- unwrap(div);
1085
- });
1086
- root.querySelectorAll("ul > ul, ul > ol, ol > ul, ol > ol").forEach((list) => {
1087
- const prev = list.previousElementSibling;
1088
- if (prev?.tagName === "LI") prev.appendChild(list);
1089
- });
1090
- const lists = [...root.querySelectorAll("ul, ol")].filter(
1091
- (l) => !l.parentElement?.closest("ul, ol") && l.querySelector("li[aria-level], li[data-aria-level]")
1092
- );
1093
- const done = /* @__PURE__ */ new Set();
1094
- for (const first of lists) {
1095
- if (done.has(first) || !root.contains(first)) continue;
1096
- const run = [];
1097
- let node = first;
1098
- while (node && /^(UL|OL)$/.test(node.tagName)) {
1099
- done.add(node);
1100
- collectListItems(node, 1, run);
1101
- const next = nextElement(node);
1102
- if (node !== first) node.remove();
1103
- node = next;
1104
- }
1105
- if (!run.length) continue;
1106
- const placeholder = first.ownerDocument.createElement("div");
1107
- first.replaceWith(placeholder);
1108
- buildNestedListFromBlocks(run, placeholder);
1109
- }
1110
- }
1111
- function collectListItems(list, depth, run) {
1112
- for (const li of [...list.children]) {
1113
- if (li.tagName !== "LI") continue;
1114
- const level = levelOf(li) ?? depth;
1115
- const nested = [...li.children].filter((c) => /^(UL|OL)$/.test(c.tagName));
1116
- nested.forEach((n) => n.remove());
1117
- const holder = li.ownerDocument.createElement("div");
1118
- while (li.firstChild) holder.appendChild(li.firstChild);
1119
- run.push({
1120
- el: holder,
1121
- level,
1122
- ordered: list.tagName === "OL",
1123
- start: Number(list.getAttribute("start") ?? 1) || 1
1124
- });
1125
- nested.forEach((n) => collectListItems(n, level + 1, run));
1126
- }
1127
- }
1128
- function buildNestedListFromBlocks(run, placeholder) {
1129
- const doc = placeholder.ownerDocument;
1130
- const stack = [];
1131
- let top = null;
1132
- for (const item of run) {
1133
- while (stack.length && stack[stack.length - 1].level > item.level) stack.pop();
1134
- let current = stack[stack.length - 1];
1135
- if (!current || current.level < item.level) {
1136
- const list = doc.createElement(item.ordered ? "ol" : "ul");
1137
- if (item.ordered && item.start !== 1 && !current)
1138
- list.setAttribute("start", String(item.start));
1139
- if (current) {
1140
- const parentItem = current.list.lastElementChild ?? current.list.appendChild(doc.createElement("li"));
1141
- parentItem.appendChild(list);
1142
- } else top = list;
1143
- current = { list, level: item.level };
1144
- stack.push(current);
1145
- }
1146
- const li = doc.createElement("li");
1147
- while (item.el.firstChild) li.appendChild(item.el.firstChild);
1148
- current.list.appendChild(li);
1149
- }
1150
- placeholder.replaceWith(top);
1151
- }
1152
- function unwrapGoogleDocsWrapper(root) {
1153
- root.querySelectorAll('[id^="docs-internal-guid-"]').forEach(unwrap);
1154
- root.querySelectorAll('li[role="checkbox"]').forEach((li) => {
1155
- li.removeAttribute("role");
1156
- li.removeAttribute("aria-checked");
1157
- });
1158
- }
1159
- function convertWordParagraphStyles(root) {
1160
- root.querySelectorAll('p.MsoTitle, p[class*="Title"]').forEach((p) => {
1161
- if (!/\bMsoTitle\b|^Title$/.test(p.className)) return;
1162
- renameElement(p, "h1");
1163
- });
1164
- root.querySelectorAll('div.WordSection1, div[class^="WordSection"], div.Section1').forEach(unwrap);
1165
- }
1166
- var DEFAULT_TEXT_COLORS = /^(black|windowtext|auto|#000|#000000|rgb\(0,\s*0,\s*0\)|initial|inherit)$/i;
1167
- var DEFAULT_BACKGROUNDS = /^(transparent|white|window|auto|none|#fff|#ffffff|rgba?\(255,\s*255,\s*255(,\s*1)?\)|rgba\(\d+,\s*\d+,\s*\d+,\s*0\)|initial|inherit)$/i;
1168
- var CLEAN_DROP = /^(font|font-family|font-size|line-height|margin|margin-.+|padding|padding-.+|text-indent|letter-spacing|word-spacing|white-space|height|width|min-height|border|border-.+|tab-stops|layout-grid-mode|page-break-.+|break-.+|orphans|widows|direction|unicode-bidi|font-variant.*|text-transform)$/i;
1169
- function cleanStyle(el, mode) {
1170
- const decls = parseDeclarations(el.getAttribute("style") ?? "");
1171
- const out = /* @__PURE__ */ new Map();
1172
- decls.forEach((value, name) => {
1173
- if (name.startsWith("mso-")) {
1174
- if (name === "mso-highlight" && !DEFAULT_BACKGROUNDS.test(value) && !decls.has("background-color"))
1175
- out.set("background-color", value);
1176
- return;
1177
- }
1178
- if (name.startsWith("-webkit-") || name.startsWith("-moz-")) return;
1179
- if (name === "background") {
1180
- const color2 = value.split(/\s+/)[0];
1181
- if (/^(#[0-9a-f]{3,8}|rgba?\([^)]*\)|[a-z]+)$/i.test(color2) && !out.has("background-color"))
1182
- out.set("background-color", color2);
1183
- return;
1184
- }
1185
- if (name === "text-decoration" || name === "text-decoration-line") {
1186
- if (/underline/.test(value)) out.set("text-decoration", "underline");
1187
- else if (/line-through/.test(value)) out.set("text-decoration", "line-through");
1188
- return;
1189
- }
1190
- if (mode === "clean" && CLEAN_DROP.test(name)) return;
1191
- if (mode === "clean" && name === "vertical-align" && /^(TD|TH)$/.test(el.tagName)) return;
1192
- out.set(name, value);
1193
- });
1194
- const color = out.get("color");
1195
- if (color && DEFAULT_TEXT_COLORS.test(color.trim()) && mode === "clean") out.delete("color");
1196
- const background = out.get("background-color");
1197
- if (background && DEFAULT_BACKGROUNDS.test(background.trim())) out.delete("background-color");
1198
- if (out.get("font-weight") === "normal" && el.tagName !== "B") out.delete("font-weight");
1199
- if (out.get("font-style") === "normal") out.delete("font-style");
1200
- if (out.get("text-decoration") === "none") out.delete("text-decoration");
1201
- if (out.get("vertical-align") === "baseline") out.delete("vertical-align");
1202
- if (/^(left|start)$/i.test(out.get("text-align") ?? "")) out.delete("text-align");
1203
- if (mode === "clean" && el.closest("a")) {
1204
- out.delete("color");
1205
- if (out.get("text-decoration") === "underline") out.delete("text-decoration");
1206
- }
1207
- if (out.size) el.setAttribute("style", serializeDeclarations(out));
1208
- else el.removeAttribute("style");
1209
- }
1210
- function stripLayoutAttributes(root) {
1211
- root.querySelectorAll("table, tr, td, th, col, colgroup").forEach((el) => {
1212
- el.removeAttribute("width");
1213
- el.removeAttribute("height");
1214
- el.removeAttribute("valign");
1215
- });
1216
- }
1217
- function unwrapMeaningless(root) {
1218
- for (const el of [...root.querySelectorAll("span, font")].reverse()) {
1219
- if (!root.contains(el)) continue;
1220
- const hasFormatting = el.hasAttribute("style") || el.tagName === "FONT" && el.hasAttribute("color");
1221
- if (!hasFormatting) unwrap(el);
1222
- }
1223
- root.querySelectorAll("[class]").forEach((el) => el.removeAttribute("class"));
1224
- root.querySelectorAll("[lang]").forEach((el) => el.removeAttribute("lang"));
1225
- root.querySelectorAll("[dir]").forEach((el) => {
1226
- if (!/^rtl$/i.test(el.getAttribute("dir") ?? "")) el.removeAttribute("dir");
1227
- });
1228
- }
1229
- var BLOCK = /^(P|DIV|H[1-6]|UL|OL|TABLE|BLOCKQUOTE|PRE|HR)$/;
1230
- function removeBreaksBetweenBlocks(root) {
1231
- root.querySelectorAll("br").forEach((br) => {
1232
- const parent = br.parentElement;
1233
- if (!parent || !(parent === root || parent.tagName === "DIV" || parent.tagName === "TD" || parent.tagName === "LI"))
1234
- return;
1235
- const prev = siblingElement(br, -1);
1236
- const next = siblingElement(br, 1);
1237
- if (prev && BLOCK.test(prev.tagName) || next && BLOCK.test(next.tagName) || !prev && !next && parent === root)
1238
- br.remove();
1239
- });
1240
- }
1241
- function siblingElement(node, dir) {
1242
- let s = dir < 0 ? node.previousSibling : node.nextSibling;
1243
- while (s && s.nodeType === Node.TEXT_NODE && !s.textContent?.trim())
1244
- s = dir < 0 ? s.previousSibling : s.nextSibling;
1245
- return s instanceof Element ? s : null;
1246
- }
1247
- function normalizeEmptyParagraphs(root) {
1248
- root.querySelectorAll("p").forEach((p) => {
1249
- if (p.children.length === 0 && /^\s*$/.test(p.textContent ?? "")) p.textContent = "";
1250
- });
1251
- }
1252
- function wrapCellContent(root) {
1253
- root.querySelectorAll("td, th").forEach((cell) => {
1254
- const align = cell.style.textAlign;
1255
- const hasBlock = [...cell.children].some((c) => BLOCK.test(c.tagName));
1256
- if (!align || hasBlock || !cell.textContent?.trim()) return;
1257
- const p = cell.ownerDocument.createElement("p");
1258
- p.style.textAlign = align;
1259
- while (cell.firstChild) p.appendChild(cell.firstChild);
1260
- cell.appendChild(p);
1261
- cell.style.removeProperty("text-align");
1262
- if (!cell.getAttribute("style")) cell.removeAttribute("style");
1263
- });
1264
- }
1265
- function unwrap(el) {
1266
- const parent = el.parentNode;
1267
- if (!parent) return;
1268
- while (el.firstChild) parent.insertBefore(el.firstChild, el);
1269
- parent.removeChild(el);
1270
- }
1271
- function renameElement(el, tag) {
1272
- const next = el.ownerDocument.createElement(tag);
1273
- for (const attr of [...el.attributes]) next.setAttribute(attr.name, attr.value);
1274
- while (el.firstChild) next.appendChild(el.firstChild);
1275
- el.replaceWith(next);
1276
- return next;
1277
- }
1278
-
1279
492
  // src/paste-rtf.ts
1280
493
  function groupEnd(rtf, start) {
1281
494
  let depth = 0;
@@ -1358,6 +571,18 @@ function replaceLocalImages(html, images) {
1358
571
  }
1359
572
 
1360
573
  // src/paste.ts
574
+ var cleaner = null;
575
+ var loading = null;
576
+ function loadPasteCleaner() {
577
+ loading ??= import("./paste-office-F3QW4WWO.js").then(
578
+ (module) => cleaner = module,
579
+ () => {
580
+ loading = null;
581
+ return null;
582
+ }
583
+ );
584
+ return loading;
585
+ }
1361
586
  var key = new PluginKey("nova-paste");
1362
587
  function htmlToPlainText(html) {
1363
588
  const template = document.createElement("template");
@@ -1407,7 +632,7 @@ function pastePlugin(editor) {
1407
632
  transformPastedHTML(html) {
1408
633
  const { pastePreprocess, pastePostprocess, pasteStyles } = editor.options;
1409
634
  let result = pastePreprocess ? pastePreprocess(html, editor) : html;
1410
- result = cleanPastedHTML(result, pasteStyles ?? "clean");
635
+ if (cleaner) result = cleaner.cleanPastedHTML(result, pasteStyles ?? "clean");
1411
636
  if (pastePostprocess) {
1412
637
  const template = document.createElement("template");
1413
638
  template.innerHTML = result;
@@ -1418,6 +643,32 @@ function pastePlugin(editor) {
1418
643
  }
1419
644
  return result;
1420
645
  },
646
+ handleDOMEvents: {
647
+ /**
648
+ * Вставка HTML раньше, чем догрузилась очистка (первые миллисекунды после создания или
649
+ * медленная сеть): забираем данные буфера сейчас (после события они недоступны), ждём чанк
650
+ * и вставляем как обычно — через transformPastedHTML уже с очисткой.
651
+ */
652
+ paste(view, event) {
653
+ if (cleaner || reentrant || editor.isPasteAsText()) return false;
654
+ const data = event.clipboardData;
655
+ const html = data?.getData("text/html");
656
+ if (!html) return false;
657
+ const rtf = hasLocalFileImages(html) ? data?.getData("text/rtf") ?? "" : "";
658
+ event.preventDefault();
659
+ void loadPasteCleaner().then(() => {
660
+ if (view.isDestroyed) return;
661
+ const withImages = rtf && editor.isAllowed("image") ? replaceLocalImages(html, extractRtfImages(rtf)) : html;
662
+ reentrant = true;
663
+ try {
664
+ view.pasteHTML(withImages);
665
+ } finally {
666
+ reentrant = false;
667
+ }
668
+ });
669
+ return true;
670
+ }
671
+ },
1421
672
  handlePaste(view, event, slice) {
1422
673
  if (reentrant) return false;
1423
674
  const html = event.clipboardData?.getData("text/html");
@@ -1453,8 +704,22 @@ import {
1453
704
  DOMParser
1454
705
  } from "prosemirror-model";
1455
706
  var CELL_BG_ATTR = "data-nova-cell-bg";
707
+ var HTML_NS = "http://www.w3.org/1999/xhtml";
708
+ var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
709
+ function replaceForeignElements(root) {
710
+ const foreign = [...root.querySelectorAll("*")].filter(
711
+ // Только самые внешние: родитель — HTML-элемент или сам фрагмент (parentElement = null).
712
+ (el) => el.namespaceURI !== HTML_NS && (el.parentElement?.namespaceURI ?? HTML_NS) === HTML_NS
713
+ );
714
+ for (const el of foreign) {
715
+ const text = el.namespaceURI === MATHML_NS ? el.textContent ?? "" : "";
716
+ el.replaceWith(el.ownerDocument.createTextNode(text));
717
+ }
718
+ }
1456
719
  function preprocessDOM(root) {
720
+ replaceForeignElements(root);
1457
721
  root.querySelectorAll("td, th").forEach((cell) => {
722
+ if (!cell.style) return;
1458
723
  const bg = cell.style.backgroundColor;
1459
724
  if (!bg) return;
1460
725
  cell.setAttribute(CELL_BG_ATTR, bg);
@@ -1464,8 +729,18 @@ function preprocessDOM(root) {
1464
729
  }
1465
730
  var NovaDOMParser = class extends DOMParser {
1466
731
  atomSelector;
732
+ ownStyleSelector;
1467
733
  prepare(dom) {
1468
734
  preprocessDOM(dom);
735
+ this.ownStyleSelector ??= Object.values(this.schema.nodes).flatMap((type) => type.spec.ownStyleTags ?? []).join(", ");
736
+ if (this.ownStyleSelector && "querySelectorAll" in dom) {
737
+ dom.querySelectorAll(this.ownStyleSelector).forEach((el) => {
738
+ const style = el.getAttribute("style");
739
+ if (style === null) return;
740
+ el.setAttribute(OWN_STYLE, style);
741
+ el.removeAttribute("style");
742
+ });
743
+ }
1469
744
  this.atomSelector ??= Object.values(this.schema.nodes).filter((type) => type.spec.ignoreStyles).flatMap((type) => (type.spec.parseDOM ?? []).map((rule) => rule.tag)).filter((tag) => !!tag).join(", ");
1470
745
  if (!this.atomSelector || !("querySelectorAll" in dom)) return;
1471
746
  dom.querySelectorAll(this.atomSelector).forEach((el) => {
@@ -1541,7 +816,7 @@ function createMenu(entries, onDone, label) {
1541
816
  };
1542
817
  menu.addEventListener("keydown", (event) => {
1543
818
  const list = enabled();
1544
- const current = list.indexOf(document.activeElement);
819
+ const current = list.indexOf(activeElement(menu));
1545
820
  switch (event.key) {
1546
821
  case "ArrowDown":
1547
822
  event.preventDefault();
@@ -1642,9 +917,10 @@ function createMenubar(editor, host, config, menus) {
1642
917
  if (!items.length) return;
1643
918
  const menu = createMenu(items, () => editor.ui.closePopover(), title(def));
1644
919
  menu.addEventListener("keydown", (event) => {
1645
- if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
920
+ const key3 = logicalKey(event, menu);
921
+ if (key3 !== "ArrowLeft" && key3 !== "ArrowRight") return;
1646
922
  event.preventDefault();
1647
- const next = (index + (event.key === "ArrowRight" ? 1 : -1) + buttons.length) % buttons.length;
923
+ const next = (index + (key3 === "ArrowRight" ? 1 : -1) + buttons.length) % buttons.length;
1648
924
  openMenu(next, true);
1649
925
  });
1650
926
  button.setAttribute("aria-expanded", "true");
@@ -1692,7 +968,7 @@ function createMenubar(editor, host, config, menus) {
1692
968
  host.addEventListener(
1693
969
  "keydown",
1694
970
  (event) => {
1695
- const index = buttons.indexOf(document.activeElement);
971
+ const index = buttons.indexOf(activeElement(host));
1696
972
  if (index < 0) return;
1697
973
  const move = (to) => {
1698
974
  event.preventDefault();
@@ -1700,8 +976,9 @@ function createMenubar(editor, host, config, menus) {
1700
976
  buttons.forEach((b, i) => b.tabIndex = i === next ? 0 : -1);
1701
977
  buttons[next].focus();
1702
978
  };
1703
- if (event.key === "ArrowRight") move(index + 1);
1704
- else if (event.key === "ArrowLeft") move(index - 1);
979
+ const key3 = logicalKey(event, host);
980
+ if (key3 === "ArrowRight") move(index + 1);
981
+ else if (key3 === "ArrowLeft") move(index - 1);
1705
982
  else if (event.key === "Home") move(0);
1706
983
  else if (event.key === "End") move(buttons.length - 1);
1707
984
  else if (event.key === "ArrowDown") {
@@ -1833,7 +1110,8 @@ var ALIASES = {
1833
1110
  tfoot: "table",
1834
1111
  caption: "table",
1835
1112
  colgroup: "table",
1836
- col: "table"
1113
+ col: "table",
1114
+ figcaption: "figure"
1837
1115
  };
1838
1116
  var KNOWN_TAGS = [
1839
1117
  "p",
@@ -1850,6 +1128,7 @@ var KNOWN_TAGS = [
1850
1128
  "ol",
1851
1129
  "li",
1852
1130
  "img",
1131
+ "figure",
1853
1132
  "br",
1854
1133
  "table",
1855
1134
  "tr",
@@ -1959,6 +1238,7 @@ var ContentRules = class {
1959
1238
  const valid = parseList(options.validElements);
1960
1239
  const invalid = parseList(options.invalidElements) ?? /* @__PURE__ */ new Set();
1961
1240
  const tags = new Set(valid ?? KNOWN_TAGS);
1241
+ if (valid) for (const tag of parseList(options.extendedValidElements) ?? []) tags.add(tag);
1962
1242
  if (tags.has("ul") || tags.has("ol")) tags.add("li");
1963
1243
  if (tags.has("table")) {
1964
1244
  tags.add("tr");
@@ -2019,7 +1299,8 @@ var ContentRules = class {
2019
1299
  return {
2020
1300
  ...attrs,
2021
1301
  ...this.isStyleAllowed("text-align") ? {} : { align: null },
2022
- ...this.isStyleAllowed("line-height") ? {} : { lineHeight: null }
1302
+ ...this.isStyleAllowed("line-height") ? {} : { lineHeight: null },
1303
+ ...this.isStyleAllowed("margin-left") ? {} : { indent: 0 }
2023
1304
  };
2024
1305
  }
2025
1306
  /** Привести узел к правилам. Возвращает 0…n узлов (запрещённый блок может «раствориться»). */
@@ -2041,6 +1322,18 @@ var ContentRules = class {
2041
1322
  marks
2042
1323
  )
2043
1324
  ];
1325
+ case nodes.figure: {
1326
+ const caption = node.childCount > 1 ? node.child(1).content : null;
1327
+ const captionBlocks = caption?.size ? [nodes.paragraph.create(null, this.normalizeChildren(caption))] : [];
1328
+ const image = node.firstChild;
1329
+ if (!this.isTagAllowed("img") || !image) return captionBlocks;
1330
+ const align = this.isStyleAllowed("float") ? node.attrs.align : null;
1331
+ if (!this.isTagAllowed("figure")) {
1332
+ const inline = nodes.image.create({ ...image.attrs, align });
1333
+ return [nodes.paragraph.create(null, inline), ...captionBlocks];
1334
+ }
1335
+ return [nodes.figure.create({ ...node.attrs, align }, node.content)];
1336
+ }
2044
1337
  case nodes.hard_break:
2045
1338
  return this.isTagAllowed("br") ? [node.mark(marks)] : [schema2.text(" ", marks)];
2046
1339
  case nodes.horizontal_rule:
@@ -2393,7 +1686,9 @@ var SHORTCUTS = [
2393
1686
  { label: "h3", keys: "Mod-Alt-3" },
2394
1687
  { label: "bulletList", keys: "Mod-Shift-8" },
2395
1688
  { label: "orderedList", keys: "Mod-Shift-7" },
2396
- { label: "alignCenter", keys: "Mod-Shift-e" }
1689
+ { label: "alignCenter", keys: "Mod-Shift-e" },
1690
+ { label: "indent", keys: "Mod-]" },
1691
+ { label: "outdent", keys: "Mod-[" }
2397
1692
  ]
2398
1693
  },
2399
1694
  {
@@ -2470,6 +1765,41 @@ var NBSP = new RegExp(String.fromCharCode(160), "g");
2470
1765
  function escapeText(text) {
2471
1766
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(NBSP, "&nbsp;");
2472
1767
  }
1768
+ var NBSP_CHAR = "\xA0";
1769
+ function protectSpaces(fragment) {
1770
+ let result = null;
1771
+ let collapsible = true;
1772
+ const count = fragment.childCount;
1773
+ for (let i = 0; i < count; i++) {
1774
+ const node = fragment.child(i);
1775
+ if (!node.isText) {
1776
+ collapsible = node.type.name === "hard_break" || !node.isInline;
1777
+ continue;
1778
+ }
1779
+ const text = node.text ?? "";
1780
+ if (!text.includes(" ")) {
1781
+ collapsible = false;
1782
+ continue;
1783
+ }
1784
+ const lineEndsAfter = i === count - 1 || !fragment.child(i + 1).isInline;
1785
+ let out = "";
1786
+ for (let k = 0; k < text.length; k++) {
1787
+ const ch = text[k];
1788
+ if (ch !== " ") {
1789
+ out += ch;
1790
+ collapsible = false;
1791
+ } else if (collapsible || lineEndsAfter && k === text.length - 1) {
1792
+ out += NBSP_CHAR;
1793
+ collapsible = false;
1794
+ } else {
1795
+ out += " ";
1796
+ collapsible = true;
1797
+ }
1798
+ }
1799
+ if (out !== text) (result ??= /* @__PURE__ */ new Map()).set(i, out);
1800
+ }
1801
+ return result;
1802
+ }
2473
1803
  function escapeAttr(value) {
2474
1804
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(NBSP, "&nbsp;");
2475
1805
  }
@@ -2488,21 +1818,6 @@ var FORBIDDEN_TAGS = /* @__PURE__ */ new Set([
2488
1818
  "template",
2489
1819
  "noscript"
2490
1820
  ]);
2491
- var LINK_ATTRS = /* @__PURE__ */ new Set(["href", "xlink:href", "action", "formaction", "cite"]);
2492
- var RESOURCE_ATTRS = /* @__PURE__ */ new Set(["src", "poster", "data", "background"]);
2493
- var UNSAFE_CSS = /url\s*\(|expression\s*\(|javascript:|@import|behavior\s*:|-moz-binding/i;
2494
- function safeAttr(name, value) {
2495
- const lower = name.toLowerCase();
2496
- if (lower.startsWith("on")) return null;
2497
- if (LINK_ATTRS.has(lower)) return isSafeLinkUrl(value) ? value : null;
2498
- if (RESOURCE_ATTRS.has(lower)) return isSafeImageUrl(value) ? value : null;
2499
- if (lower === "srcset") {
2500
- const urls = value.split(",").map((part) => part.trim().split(/\s+/)[0] ?? "");
2501
- return urls.every((url) => isSafeImageUrl(url)) ? value : null;
2502
- }
2503
- if (lower === "style") return UNSAFE_CSS.test(value) ? null : value;
2504
- return value;
2505
- }
2506
1821
  var reported = /* @__PURE__ */ new Set();
2507
1822
  function reportForbidden(tag) {
2508
1823
  if (reported.has(tag)) return;
@@ -2514,6 +1829,10 @@ function reportForbidden(tag) {
2514
1829
  var ATTR_RE = /^[a-z_:][a-z0-9_.:-]*$/i;
2515
1830
  function renderSpec(spec) {
2516
1831
  if (typeof spec === "string") return { open: "", close: "", hole: false, html: escapeText(spec) };
1832
+ if (typeof spec === "number" || typeof spec === "boolean") {
1833
+ return { open: "", close: "", hole: false, html: escapeText(String(spec)) };
1834
+ }
1835
+ if (spec == null) return { open: "", close: "", hole: false, html: "" };
2517
1836
  if (!Array.isArray(spec)) {
2518
1837
  throw new Error("[nova] serializer supports only array/string toDOM specs");
2519
1838
  }
@@ -2566,8 +1885,13 @@ function renderSpec(spec) {
2566
1885
  return { open: open + before, close: after + close, hole, html: open + before + after + close };
2567
1886
  }
2568
1887
  var HTMLSerializer = class {
2569
- cache = /* @__PURE__ */ new Map();
2570
- serializeFragment(fragment) {
1888
+ /**
1889
+ * Кэш отрисовки марок — свой у каждого типа марки: сериализатор общий для всех редакторов страницы,
1890
+ * а вывод одноимённой марки зависит от схемы редактора (правила атрибутов, плагины).
1891
+ */
1892
+ cache = /* @__PURE__ */ new WeakMap();
1893
+ serializeFragment(fragment, { pre = false } = {}) {
1894
+ const texts = pre ? null : protectSpaces(fragment);
2571
1895
  let out = "";
2572
1896
  let active = [];
2573
1897
  let closers = [];
@@ -2577,7 +1901,7 @@ var HTMLSerializer = class {
2577
1901
  active.pop();
2578
1902
  }
2579
1903
  };
2580
- fragment.forEach((node) => {
1904
+ fragment.forEach((node, _offset, index) => {
2581
1905
  if (!node.isInline) {
2582
1906
  closeTo(0);
2583
1907
  out += this.serializeNode(node);
@@ -2594,7 +1918,7 @@ var HTMLSerializer = class {
2594
1918
  closers.push(r.close);
2595
1919
  active.push(mark);
2596
1920
  }
2597
- out += node.isText ? escapeText(node.text ?? "") : this.serializeNode(node);
1921
+ out += node.isText ? escapeText(texts?.get(index) ?? node.text ?? "") : this.serializeNode(node);
2598
1922
  });
2599
1923
  closeTo(0);
2600
1924
  active = [];
@@ -2606,17 +1930,20 @@ var HTMLSerializer = class {
2606
1930
  if (!toDOM) throw new Error(`[nova] node "${node.type.name}" has no toDOM`);
2607
1931
  const r = renderSpec(toDOM(node));
2608
1932
  if (!r.hole) return r.html;
2609
- return r.open + this.serializeFragment(node.content) + r.close;
1933
+ const pre = !!node.type.spec.code || node.type.spec.whitespace === "pre";
1934
+ return r.open + this.serializeFragment(node.content, { pre }) + r.close;
2610
1935
  }
2611
1936
  renderMark(mark, inline) {
2612
1937
  const toDOM = mark.type.spec.toDOM;
2613
1938
  if (!toDOM) throw new Error(`[nova] mark "${mark.type.name}" has no toDOM`);
2614
- const key3 = `${mark.type.name}:${JSON.stringify(mark.attrs)}`;
2615
- let r = this.cache.get(key3);
1939
+ let cache = this.cache.get(mark.type);
1940
+ if (!cache) this.cache.set(mark.type, cache = /* @__PURE__ */ new Map());
1941
+ const key3 = JSON.stringify(mark.attrs);
1942
+ let r = cache.get(key3);
2616
1943
  if (!r) {
2617
1944
  r = renderSpec(toDOM(mark, inline));
2618
- if (this.cache.size > 500) this.cache.clear();
2619
- this.cache.set(key3, r);
1945
+ if (cache.size > 500) cache.clear();
1946
+ cache.set(key3, r);
2620
1947
  }
2621
1948
  return r;
2622
1949
  }
@@ -2719,6 +2046,7 @@ function createColorPanel(options) {
2719
2046
  const swatches = [];
2720
2047
  const current = options.current?.toLowerCase() ?? null;
2721
2048
  const grid = h("div", { className: "nova-swatches", role: "grid", "aria-label": options.label });
2049
+ let row = null;
2722
2050
  for (const color of options.colors) {
2723
2051
  const selected = current === color.toLowerCase();
2724
2052
  const swatch = h(
@@ -2737,14 +2065,18 @@ function createColorPanel(options) {
2737
2065
  swatch.style.setProperty("--swatch", color);
2738
2066
  swatch.addEventListener("click", () => options.onPick(color));
2739
2067
  swatches.push(swatch);
2740
- grid.append(swatch);
2068
+ if (!row || row.childElementCount === COLUMNS) {
2069
+ row = h("div", { className: "nova-swatch-row", role: "row" });
2070
+ grid.append(row);
2071
+ }
2072
+ row.append(swatch);
2741
2073
  }
2742
2074
  (swatches.find((s) => s.getAttribute("aria-selected") === "true") ?? swatches[0])?.setAttribute(
2743
2075
  "tabindex",
2744
2076
  "0"
2745
2077
  );
2746
2078
  grid.addEventListener("keydown", (event) => {
2747
- const index = swatches.indexOf(document.activeElement);
2079
+ const index = swatches.indexOf(activeElement(grid));
2748
2080
  if (index < 0) return;
2749
2081
  const delta = {
2750
2082
  ArrowRight: 1,
@@ -2752,7 +2084,7 @@ function createColorPanel(options) {
2752
2084
  ArrowDown: COLUMNS,
2753
2085
  ArrowUp: -COLUMNS
2754
2086
  };
2755
- const step = delta[event.key];
2087
+ const step = delta[logicalKey(event, grid)];
2756
2088
  if (step === void 0) return;
2757
2089
  event.preventDefault();
2758
2090
  const next = swatches[Math.min(swatches.length - 1, Math.max(0, index + step))];
@@ -3012,6 +2344,8 @@ var SHORTCUTS2 = {
3012
2344
  alignCenter: "Mod-Shift-e",
3013
2345
  alignRight: "Mod-Shift-r",
3014
2346
  alignJustify: "Mod-Shift-j",
2347
+ indent: "Mod-]",
2348
+ outdent: "Mod-[",
3015
2349
  clearFormatting: "Mod-\\",
3016
2350
  paragraph: "Mod-Alt-0",
3017
2351
  h1: "Mod-Alt-1",
@@ -3039,7 +2373,7 @@ var GENERIC_FONTS = {
3039
2373
  "ui-monospace": "Monospace"
3040
2374
  };
3041
2375
  function prettyFontName(family) {
3042
- const first = family.split(",")[0].trim().replace(/["']/g, "");
2376
+ const first = String(family).split(",")[0].trim().replace(/["']/g, "");
3043
2377
  return GENERIC_FONTS[first.toLowerCase()] ?? first;
3044
2378
  }
3045
2379
  function pxToPt(px) {
@@ -3047,7 +2381,7 @@ function pxToPt(px) {
3047
2381
  if (!Number.isFinite(value) || value <= 0) return null;
3048
2382
  return `${Math.round(value * 0.75 * 2) / 2}pt`;
3049
2383
  }
3050
- var sameFont = (a, b) => a !== null && a.replace(/["'\s]/g, "").toLowerCase() === b.replace(/["'\s]/g, "").toLowerCase();
2384
+ var sameFont = (a, b) => typeof a === "string" && a.replace(/["'\s]/g, "").toLowerCase() === b.replace(/["'\s]/g, "").toLowerCase();
3051
2385
  function registerBuiltins(editor) {
3052
2386
  const { registry, t } = editor.ui;
3053
2387
  const state = () => editor.view.state;
@@ -3438,7 +2772,7 @@ function registerBuiltins(editor) {
3438
2772
  tooltip: t("image"),
3439
2773
  onAction: (e) => openImageDialog(e)
3440
2774
  });
3441
- const imageAlign = () => getSelectedImage(state())?.node.attrs.align ?? null;
2775
+ const imageAlign = () => getSelectedImage(state())?.attrs.align ?? null;
3442
2776
  const imageAlignButton = (name, align, svg, label) => registry.addToggleButton(name, {
3443
2777
  icon: svg,
3444
2778
  tooltip: t(label),
@@ -3470,12 +2804,19 @@ function registerBuiltins(editor) {
3470
2804
  tooltip: t("image.editAlt"),
3471
2805
  onAction: (e) => openImageAltDialog(e)
3472
2806
  });
2807
+ registry.addToggleButton("imagecaption", {
2808
+ icon: icons.imageCaption,
2809
+ tooltip: t("image.caption"),
2810
+ isActive: (e) => hasImageCaption(e.view.state),
2811
+ onAction: (e) => e.exec(toggleImageCaption)
2812
+ });
3473
2813
  registry.addButton("imagedelete", {
3474
2814
  icon: icons.trash,
3475
2815
  tooltip: t("image.delete"),
3476
2816
  onAction: (e) => e.exec((s, dispatch) => {
3477
- if (!getSelectedImage(s)) return false;
3478
- dispatch?.(s.tr.deleteSelection().scrollIntoView());
2817
+ const image = getSelectedImage(s);
2818
+ if (!image) return false;
2819
+ dispatch?.(s.tr.delete(image.pos, image.pos + image.node.nodeSize).scrollIntoView());
3479
2820
  return true;
3480
2821
  })
3481
2822
  });
@@ -3512,7 +2853,13 @@ function registerBuiltins(editor) {
3512
2853
  registry.addContextToolbar("image", {
3513
2854
  label: t("image.toolbar"),
3514
2855
  predicate: (e) => !!getSelectedImage(e.view.state),
3515
- items: "imagealignleft imagealigncenter imagealignright | imagesize imagealt | imagedelete"
2856
+ items: "imagealignleft imagealigncenter imagealignright | imagesize imagealt imagecaption | imagedelete",
2857
+ // Над картинкой (и с подписью — над всей figure, даже когда курсор в подписи).
2858
+ anchor: (e) => {
2859
+ const image = getSelectedImage(e.view.state);
2860
+ const dom = image ? e.view.nodeDOM(image.pos) : null;
2861
+ return dom?.getBoundingClientRect() ?? null;
2862
+ }
3516
2863
  });
3517
2864
  }
3518
2865
 
@@ -3522,13 +2869,16 @@ var VIEWPORT_PADDING = 8;
3522
2869
  function positionFloating(floating, anchorRect, placement) {
3523
2870
  const vw = window.innerWidth;
3524
2871
  const vh = window.innerHeight;
3525
- const { width, height } = floating.getBoundingClientRect();
2872
+ const width = floating.offsetWidth;
2873
+ const height = floating.offsetHeight;
3526
2874
  const spaceBelow = vh - anchorRect.bottom;
3527
2875
  const spaceAbove = anchorRect.top;
3528
2876
  const preferTop = placement === "top-start";
3529
2877
  const placeTop = preferTop ? spaceAbove >= height + GAP || spaceAbove > spaceBelow : spaceBelow < height + GAP && spaceAbove > spaceBelow;
3530
2878
  let top = placeTop ? anchorRect.top - height - GAP : anchorRect.bottom + GAP;
3531
- let left = placement === "bottom-end" ? anchorRect.right - width : placement === "bottom" ? anchorRect.left + anchorRect.width / 2 - width / 2 : anchorRect.left;
2879
+ const rtl = isRtl(floating);
2880
+ const alignEnd = placement === "bottom-end" !== rtl;
2881
+ let left = placement === "bottom" ? anchorRect.left + anchorRect.width / 2 - width / 2 : alignEnd ? anchorRect.right - width : anchorRect.left;
3532
2882
  left = Math.max(VIEWPORT_PADDING, Math.min(left, vw - width - VIEWPORT_PADDING));
3533
2883
  top = Math.max(VIEWPORT_PADDING, Math.min(top, vh - height - VIEWPORT_PADDING));
3534
2884
  floating.style.left = `${Math.round(left)}px`;
@@ -3540,6 +2890,7 @@ var Popover = class {
3540
2890
  el;
3541
2891
  options;
3542
2892
  closed = false;
2893
+ unlisten = [];
3543
2894
  constructor(options) {
3544
2895
  this.options = options;
3545
2896
  this.el = document.createElement("div");
@@ -3547,8 +2898,10 @@ var Popover = class {
3547
2898
  this.el.append(options.content);
3548
2899
  options.host.append(this.el);
3549
2900
  this.reposition();
3550
- document.addEventListener("keydown", this.onKeyDown, true);
3551
- document.addEventListener("pointerdown", this.onPointerDown, true);
2901
+ this.unlisten = [
2902
+ listenDocument(this.el, "keydown", this.onKeyDown),
2903
+ listenDocument(this.el, "pointerdown", this.onPointerDown)
2904
+ ];
3552
2905
  openStack.push(this);
3553
2906
  window.addEventListener("resize", this.reposition);
3554
2907
  window.addEventListener("scroll", this.reposition, true);
@@ -3566,8 +2919,7 @@ var Popover = class {
3566
2919
  if (this.closed) return;
3567
2920
  this.closed = true;
3568
2921
  openStack.splice(openStack.indexOf(this), 1);
3569
- document.removeEventListener("keydown", this.onKeyDown, true);
3570
- document.removeEventListener("pointerdown", this.onPointerDown, true);
2922
+ this.unlisten.forEach((stop) => stop());
3571
2923
  window.removeEventListener("resize", this.reposition);
3572
2924
  window.removeEventListener("scroll", this.reposition, true);
3573
2925
  this.el.remove();
@@ -3575,18 +2927,17 @@ var Popover = class {
3575
2927
  }
3576
2928
  /** Был ли фокус внутри панели в момент закрытия (тогда его надо вернуть на кнопку). */
3577
2929
  focusWasInside = false;
3578
- onKeyDown = (event) => {
2930
+ onKeyDown = (event, target) => {
3579
2931
  if (event.key !== "Escape" || event.defaultPrevented) return;
3580
2932
  if (openStack[openStack.length - 1] !== this) return;
3581
- if (event.target?.closest?.(".nova-dialog")) return;
2933
+ if (target?.closest?.(".nova-dialog")) return;
3582
2934
  event.preventDefault();
3583
2935
  event.stopPropagation();
3584
- this.focusWasInside = this.el.contains(document.activeElement);
2936
+ this.focusWasInside = this.el.contains(activeElement(this.el));
3585
2937
  this.close("escape");
3586
2938
  };
3587
- onPointerDown = (event) => {
2939
+ onPointerDown = (_event, target) => {
3588
2940
  if (this.options.dismissOnOutside === false) return;
3589
- const target = event.target;
3590
2941
  if (this.el.contains(target)) return;
3591
2942
  if (this.options.ignore?.some((el) => el.contains(target))) return;
3592
2943
  this.close("outside");
@@ -3725,11 +3076,12 @@ function createToolbar(editor, host, config, mode, { warnUnknown = true } = {})
3725
3076
  "keydown",
3726
3077
  (event) => {
3727
3078
  const list = focusables();
3728
- const index = list.indexOf(document.activeElement);
3079
+ const index = list.indexOf(activeElement(host));
3729
3080
  if (index < 0) return;
3730
3081
  let next = null;
3731
- if (event.key === "ArrowRight") next = index + 1;
3732
- else if (event.key === "ArrowLeft") next = index - 1;
3082
+ const key3 = logicalKey(event, host);
3083
+ if (key3 === "ArrowRight") next = index + 1;
3084
+ else if (key3 === "ArrowLeft") next = index - 1;
3733
3085
  else if (event.key === "Home") next = 0;
3734
3086
  else if (event.key === "End") next = list.length - 1;
3735
3087
  else if (event.key === "Escape") {
@@ -3753,12 +3105,13 @@ function createToolbar(editor, host, config, mode, { warnUnknown = true } = {})
3753
3105
  const list = [...overflowBox.querySelectorAll("button")].filter(
3754
3106
  (b) => !b.disabled
3755
3107
  );
3756
- const index = list.indexOf(document.activeElement);
3108
+ const index = list.indexOf(activeElement(overflowBox));
3757
3109
  if (index < 0) return;
3758
- if (event.key === "ArrowRight" || event.key === "ArrowDown") {
3110
+ const key3 = logicalKey(event, overflowBox);
3111
+ if (key3 === "ArrowRight" || key3 === "ArrowDown") {
3759
3112
  event.preventDefault();
3760
3113
  list[(index + 1) % list.length].focus();
3761
- } else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
3114
+ } else if (key3 === "ArrowLeft" || key3 === "ArrowUp") {
3762
3115
  event.preventDefault();
3763
3116
  list[(index - 1 + list.length) % list.length].focus();
3764
3117
  }
@@ -3858,7 +3211,14 @@ function renderControl(editor, name, spec) {
3858
3211
  el.classList.toggle("is-active", active);
3859
3212
  if (spec.type === "button") el.setAttribute("aria-pressed", String(active));
3860
3213
  }
3861
- if (label && spec.type === "menu") label.textContent = spec.label?.(editor) ?? spec.text ?? "";
3214
+ if (label && spec.type === "menu") {
3215
+ const text = spec.label?.(editor) ?? spec.text ?? "";
3216
+ label.textContent = text;
3217
+ el.setAttribute(
3218
+ "aria-label",
3219
+ text && text !== spec.tooltip ? `${text}, ${spec.tooltip}` : spec.tooltip ?? text
3220
+ );
3221
+ }
3862
3222
  if (colorBar && spec.type === "panel" && spec.indicator) {
3863
3223
  const color = spec.indicator(editor);
3864
3224
  colorBar.style.background = color ?? "";
@@ -4050,9 +3410,11 @@ var MARK_TAGS = {
4050
3410
  subscript: "sub",
4051
3411
  superscript: "sup"
4052
3412
  };
3413
+ var CJK = String.raw`\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}`;
3414
+ var LETTER = String.raw`(?:(?![${CJK}])[\p{L}\p{N}])`;
3415
+ var WORD = new RegExp(`[${CJK}]|${LETTER}+(?:['\u2019-]${LETTER}+)*`, "gu");
4053
3416
  function countWords(text) {
4054
- const matches = text.match(/[\p{L}\p{N}]+(?:['’-][\p{L}\p{N}]+)*/gu);
4055
- return matches ? matches.length : 0;
3417
+ return text.match(WORD)?.length ?? 0;
4056
3418
  }
4057
3419
  function createStatusbar(editor, host) {
4058
3420
  host.className = "nova-statusbar";
@@ -4082,7 +3444,12 @@ function createStatusbar(editor, host) {
4082
3444
  const tag = MARK_TAGS[mark.type.name];
4083
3445
  if (tag) parts.push(tag);
4084
3446
  }
4085
- path.textContent = parts.join(" \u203A ");
3447
+ path.replaceChildren(
3448
+ ...parts.flatMap((tag, i) => [
3449
+ ...i ? [" \u203A "] : [],
3450
+ h("span", { className: "nova-path-item" }, tag)
3451
+ ])
3452
+ );
4086
3453
  if (docChanged) {
4087
3454
  if (timer) clearTimeout(timer);
4088
3455
  timer = setTimeout(updateWords, 250);
@@ -4137,7 +3504,8 @@ function createResizeHandle(editor, host, both) {
4137
3504
  };
4138
3505
  const onMove = (event) => {
4139
3506
  if (!start) return;
4140
- setSize(start.height + event.clientY - start.y, start.width + event.clientX - start.x);
3507
+ const dx = (event.clientX - start.x) * (isRtl(root) ? -1 : 1);
3508
+ setSize(start.height + event.clientY - start.y, start.width + dx);
4141
3509
  };
4142
3510
  const onUp = (event) => {
4143
3511
  if (!start) return;
@@ -4146,7 +3514,8 @@ function createResizeHandle(editor, host, both) {
4146
3514
  };
4147
3515
  const onKey = (event) => {
4148
3516
  const dy = event.key === "ArrowDown" ? KEY_STEP : event.key === "ArrowUp" ? -KEY_STEP : 0;
4149
- const dx = both ? event.key === "ArrowRight" ? KEY_STEP : event.key === "ArrowLeft" ? -KEY_STEP : 0 : 0;
3517
+ const key3 = logicalKey(event, root);
3518
+ const dx = both ? key3 === "ArrowRight" ? KEY_STEP : key3 === "ArrowLeft" ? -KEY_STEP : 0 : 0;
4150
3519
  if (!dx && !dy) return;
4151
3520
  event.preventDefault();
4152
3521
  setSize(root.offsetHeight + dy, root.offsetWidth + dx);
@@ -4393,14 +3762,65 @@ function buildKeymap(resolve = (name) => commands[name]) {
4393
3762
  "Mod-Shift-j": commands.alignJustify,
4394
3763
  "Mod-\\": commands.clearFormatting,
4395
3764
  "Shift-Enter": insertHardBreak,
4396
- Enter: (state, dispatch) => splitListItem(nodesOf(state).list_item)(state, dispatch),
4397
- Tab: commands.indent,
4398
- "Shift-Tab": commands.outdent
3765
+ Enter: chainCommands(
3766
+ exitImageCaption,
3767
+ (state, dispatch) => splitListItem(nodesOf(state).list_item)(state, dispatch)
3768
+ ),
3769
+ // Tab — только для списков (в абзаце остаётся переходом фокуса). Отступ абзаца — Mod-] / Mod-[.
3770
+ Tab: listIndent,
3771
+ "Shift-Tab": listOutdent,
3772
+ "Mod-]": commands.indent,
3773
+ "Mod-[": commands.outdent
4399
3774
  };
4400
3775
  if (!mac) keys["Mod-y"] = byName(resolve, "redo");
4401
3776
  return [keymap(keys), keymap(baseKeymap)];
4402
3777
  }
4403
3778
 
3779
+ // src/plugin-views.ts
3780
+ var reconfiguring = /* @__PURE__ */ new WeakSet();
3781
+ var kept = /* @__PURE__ */ new WeakMap();
3782
+ var wrapped = /* @__PURE__ */ new WeakSet();
3783
+ function keepPluginViews(plugins) {
3784
+ for (const plugin of plugins) {
3785
+ const spec = plugin.spec;
3786
+ const create = spec.view;
3787
+ if (!create || wrapped.has(plugin)) continue;
3788
+ wrapped.add(plugin);
3789
+ spec.view = (view) => {
3790
+ let views = kept.get(view);
3791
+ if (!views) kept.set(view, views = /* @__PURE__ */ new Map());
3792
+ let inner = views.get(plugin);
3793
+ if (!inner) views.set(plugin, inner = create(view));
3794
+ const current = inner;
3795
+ return {
3796
+ update: (v, prev) => current.update?.(v, prev),
3797
+ destroy: () => {
3798
+ if (reconfiguring.has(view)) return;
3799
+ views.delete(plugin);
3800
+ current.destroy?.();
3801
+ }
3802
+ };
3803
+ };
3804
+ }
3805
+ }
3806
+ function reconfigurePlugins(view, plugins) {
3807
+ keepPluginViews(plugins);
3808
+ reconfiguring.add(view);
3809
+ try {
3810
+ view.updateState(view.state.reconfigure({ plugins }));
3811
+ } finally {
3812
+ reconfiguring.delete(view);
3813
+ }
3814
+ const views = kept.get(view);
3815
+ if (!views) return;
3816
+ for (const [plugin, inner] of views) {
3817
+ if (!plugins.includes(plugin)) {
3818
+ views.delete(plugin);
3819
+ inner.destroy?.();
3820
+ }
3821
+ }
3822
+ }
3823
+
4404
3824
  // src/ui/search-bar.ts
4405
3825
  function createSearchBar(editor, before) {
4406
3826
  const { t } = editor.ui;
@@ -4638,7 +4058,7 @@ function linkBubblePlugin(editor) {
4638
4058
  const update = () => {
4639
4059
  const state = view.state;
4640
4060
  const link = getLinkAt(state);
4641
- const focused = view.hasFocus() || el.contains(document.activeElement);
4061
+ const focused = view.hasFocus() || el.contains(activeElement(el));
4642
4062
  if (!link || !focused || !editor.isEditable() || editor.ui.activeDialog || !state.selection.empty) {
4643
4063
  hide();
4644
4064
  return;
@@ -4741,10 +4161,10 @@ function contextToolbarPlugin(editor) {
4741
4161
  setTimeout(() => update(view), 0);
4742
4162
  };
4743
4163
  view.dom.addEventListener("pointerdown", onPointerDown);
4744
- document.addEventListener("pointerup", onPointerUp);
4164
+ const stopPointerUp = listenDocument(container, "pointerup", onPointerUp);
4745
4165
  const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
4746
4166
  const update = (v) => {
4747
- const focused = v.hasFocus() || container.contains(document.activeElement);
4167
+ const focused = v.hasFocus() || container.contains(activeElement(container));
4748
4168
  if (!focused || !editor.isEditable() || editor.ui.activeDialog || dragging) return hide();
4749
4169
  const match = editor.ui.registry.getContextToolbars().find(([, spec2]) => spec2.predicate(editor));
4750
4170
  if (!match) return hide();
@@ -4768,13 +4188,13 @@ function contextToolbarPlugin(editor) {
4768
4188
  });
4769
4189
  container.addEventListener("keydown", (event) => {
4770
4190
  const buttons = [...container.querySelectorAll("button:not(:disabled)")];
4771
- const index = buttons.indexOf(document.activeElement);
4191
+ const index = buttons.indexOf(activeElement(container));
4772
4192
  if (event.key === "Escape") {
4773
4193
  event.preventDefault();
4774
4194
  editor.focus();
4775
4195
  } else if (index >= 0 && (event.key === "ArrowRight" || event.key === "ArrowLeft")) {
4776
4196
  event.preventDefault();
4777
- const step = event.key === "ArrowRight" ? 1 : -1;
4197
+ const step = logicalKey(event, container) === "ArrowRight" ? 1 : -1;
4778
4198
  buttons[(index + step + buttons.length) % buttons.length].focus();
4779
4199
  }
4780
4200
  });
@@ -4798,7 +4218,7 @@ function contextToolbarPlugin(editor) {
4798
4218
  destroy() {
4799
4219
  view.dom.removeEventListener("blur", onBlur);
4800
4220
  view.dom.removeEventListener("pointerdown", onPointerDown);
4801
- document.removeEventListener("pointerup", onPointerUp);
4221
+ stopPointerUp();
4802
4222
  window.removeEventListener("scroll", reposition, true);
4803
4223
  window.removeEventListener("resize", reposition);
4804
4224
  container.remove();
@@ -4971,7 +4391,7 @@ function autocompleterPlugin(editor) {
4971
4391
  items = [];
4972
4392
  view.dom.removeAttribute("aria-activedescendant");
4973
4393
  view.dom.removeAttribute("aria-controls");
4974
- view.dom.setAttribute("aria-expanded", "false");
4394
+ view.dom.removeAttribute("aria-expanded");
4975
4395
  };
4976
4396
  const select = (view, index) => {
4977
4397
  const item = items[index];
@@ -5013,7 +4433,6 @@ function autocompleterPlugin(editor) {
5013
4433
  });
5014
4434
  list.hidden = false;
5015
4435
  view.dom.setAttribute("aria-controls", listId);
5016
- view.dom.setAttribute("aria-expanded", "true");
5017
4436
  setActive(view, Math.min(active, Math.max(0, items.length - 1)));
5018
4437
  const coords = view.coordsAtPos(match.from);
5019
4438
  positionFloating(
@@ -5116,6 +4535,9 @@ var Notifications = class {
5116
4535
  { type: "button", className: "nova-btn", "aria-label": this.closeLabel },
5117
4536
  icon(icons.close)
5118
4537
  );
4538
+ const actions = (options.actions ?? []).map(
4539
+ (action) => h("button", { type: "button", className: "nova-btn nova-notification-action" }, action.label)
4540
+ );
5119
4541
  const el = h(
5120
4542
  "div",
5121
4543
  {
@@ -5123,16 +4545,32 @@ var Notifications = class {
5123
4545
  role: type === "error" ? "alert" : "status"
5124
4546
  },
5125
4547
  text,
4548
+ ...actions,
5126
4549
  closeBtn
5127
4550
  );
5128
4551
  this.region.append(el);
5129
4552
  let timer = null;
4553
+ let closed = false;
5130
4554
  const close = () => {
4555
+ if (closed) return;
4556
+ closed = true;
5131
4557
  if (timer) clearTimeout(timer);
5132
4558
  el.remove();
5133
4559
  };
5134
- closeBtn.addEventListener("click", close);
5135
- if (timeout > 0) timer = setTimeout(close, timeout);
4560
+ const dismiss = () => {
4561
+ if (closed) return;
4562
+ close();
4563
+ options.onClose?.();
4564
+ };
4565
+ actions.forEach(
4566
+ (button, i) => button.addEventListener("click", () => {
4567
+ close();
4568
+ options.actions[i].onAction();
4569
+ })
4570
+ );
4571
+ closeBtn.addEventListener("click", dismiss);
4572
+ if (timeout > 0) timer = setTimeout(dismiss, timeout);
4573
+ actions[0]?.focus({ preventScroll: true });
5136
4574
  return { close, setText: (value) => text.textContent = value };
5137
4575
  }
5138
4576
  destroy() {
@@ -5141,6 +4579,7 @@ var Notifications = class {
5141
4579
  };
5142
4580
 
5143
4581
  // src/ui/registry.ts
4582
+ var sidebarIcon = icons.sidebar;
5144
4583
  var Registry = class {
5145
4584
  controls = /* @__PURE__ */ new Map();
5146
4585
  addButton(name, spec) {
@@ -5189,6 +4628,24 @@ var Registry = class {
5189
4628
  contextToolbars = /* @__PURE__ */ new Map();
5190
4629
  autocompleters = /* @__PURE__ */ new Map();
5191
4630
  /** Автокомплитер по символу-триггеру: '/' — команды, '@' — упоминания, ':' — эмодзи. */
4631
+ sidebars = /* @__PURE__ */ new Map();
4632
+ /**
4633
+ * Боковая панель (показ — editor.ui.sidebar). Если имя свободно, добавляется и кнопка-переключатель
4634
+ * с этим именем для тулбара и меню (`button: false` — без неё).
4635
+ */
4636
+ addSidebar(name, spec) {
4637
+ this.sidebars.set(name, spec);
4638
+ if (spec.button === false || this.has(name)) return;
4639
+ this.addToggleButton(name, {
4640
+ tooltip: spec.tooltip ?? spec.title,
4641
+ icon: spec.icon ?? sidebarIcon,
4642
+ isActive: (editor) => editor.ui.sidebar.isOpen(name),
4643
+ onAction: (editor) => void editor.ui.sidebar.toggle(name)
4644
+ });
4645
+ }
4646
+ getSidebar(name) {
4647
+ return this.sidebars.get(name);
4648
+ }
5192
4649
  addAutocompleter(name, spec) {
5193
4650
  this.autocompleters.set(name.toLowerCase(), spec);
5194
4651
  }
@@ -5213,6 +4670,148 @@ var Registry = class {
5213
4670
  }
5214
4671
  };
5215
4672
 
4673
+ // src/ui/sidebar.ts
4674
+ var Sidebars = class {
4675
+ constructor(editor) {
4676
+ this.editor = editor;
4677
+ }
4678
+ editor;
4679
+ current = null;
4680
+ mounted = /* @__PURE__ */ new Map();
4681
+ column = null;
4682
+ opening = Promise.resolve();
4683
+ destroyed = false;
4684
+ /** Имя открытой панели или null. */
4685
+ get active() {
4686
+ return this.current;
4687
+ }
4688
+ isOpen(name) {
4689
+ return this.current === name;
4690
+ }
4691
+ /**
4692
+ * Показать панель (другая открытая закрывается). \`focus\` — перевести фокус в панель
4693
+ * (например, когда её открыли с клавиатуры, чтобы сразу работать с ней).
4694
+ */
4695
+ async show(name, options = {}) {
4696
+ const spec = this.editor.ui.registry.getSidebar(name);
4697
+ if (!spec) {
4698
+ console.warn(`[nova] sidebar "${name}" is not registered`);
4699
+ return;
4700
+ }
4701
+ if (this.current !== name) {
4702
+ this.hide({ restoreFocus: false });
4703
+ this.editor.ui.closeOverlays();
4704
+ this.current = name;
4705
+ const mounted = this.mount(name, spec);
4706
+ this.opening = mounted.ready.then((ok) => {
4707
+ if (!ok || this.current !== name || this.destroyed) {
4708
+ if (this.current === name) this.current = null;
4709
+ return;
4710
+ }
4711
+ mounted.el.hidden = false;
4712
+ this.editor.root.classList.add("nova-sidebar-open");
4713
+ spec.onShow?.(this.editor);
4714
+ this.editor.updateUI();
4715
+ });
4716
+ }
4717
+ await this.opening;
4718
+ if (options.focus && this.current === name) {
4719
+ const el = this.mounted.get(name).el;
4720
+ (el.querySelector(FOCUSABLE) ?? el).focus();
4721
+ }
4722
+ }
4723
+ /** Закрыть открытую панель. Фокус из неё возвращается в текст. */
4724
+ hide(options = {}) {
4725
+ const name = this.current;
4726
+ if (!name) return;
4727
+ this.current = null;
4728
+ const mounted = this.mounted.get(name);
4729
+ if (!mounted) return;
4730
+ const hadFocus = mounted.el.contains(activeElement(mounted.el));
4731
+ mounted.el.hidden = true;
4732
+ this.editor.root.classList.remove("nova-sidebar-open");
4733
+ this.editor.ui.registry.getSidebar(name)?.onHide?.(this.editor);
4734
+ this.editor.updateUI();
4735
+ if (hadFocus && options.restoreFocus !== false) this.editor.focus();
4736
+ }
4737
+ toggle(name, options = {}) {
4738
+ if (this.current === name) {
4739
+ this.hide();
4740
+ return Promise.resolve();
4741
+ }
4742
+ return this.show(name, options);
4743
+ }
4744
+ destroy() {
4745
+ this.destroyed = true;
4746
+ this.mounted.forEach((mounted) => mounted.cleanup?.());
4747
+ this.mounted.clear();
4748
+ }
4749
+ /** Колонка «текст + панель»: создаётся при первой панели, без панелей разметка не меняется. */
4750
+ host() {
4751
+ if (this.column) return this.column;
4752
+ const content = this.editor.view.dom.parentElement;
4753
+ const column = h("div", { className: "nova-body" });
4754
+ content.before(column);
4755
+ column.append(content);
4756
+ this.column = column;
4757
+ return column;
4758
+ }
4759
+ mount(name, spec) {
4760
+ const existing = this.mounted.get(name);
4761
+ if (existing) return existing;
4762
+ const titleId = uniqueId("nova-sidebar-title");
4763
+ const body = h("div", { className: "nova-sidebar-body" });
4764
+ const close = h(
4765
+ "button",
4766
+ {
4767
+ type: "button",
4768
+ className: "nova-btn nova-sidebar-close",
4769
+ "aria-label": this.editor.ui.t("dialog.close"),
4770
+ onClick: () => this.hide()
4771
+ },
4772
+ icon(icons.close)
4773
+ );
4774
+ const header = spec.header === false ? null : h(
4775
+ "div",
4776
+ { className: "nova-sidebar-head" },
4777
+ h("h2", { id: titleId, className: "nova-sidebar-title" }, spec.title),
4778
+ close
4779
+ );
4780
+ const el = h(
4781
+ "div",
4782
+ {
4783
+ className: `nova-sidebar${header ? "" : " nova-sidebar-bare"}`,
4784
+ hidden: true,
4785
+ "data-sidebar": name,
4786
+ ...header ? { role: "complementary", "aria-labelledby": titleId } : {},
4787
+ onKeydown: ((event) => {
4788
+ if (event.key !== "Escape" || event.defaultPrevented) return;
4789
+ event.preventDefault();
4790
+ this.hide();
4791
+ })
4792
+ },
4793
+ header,
4794
+ body
4795
+ );
4796
+ this.host().append(el);
4797
+ const mounted = { el, ready: Promise.resolve(false) };
4798
+ mounted.ready = (async () => {
4799
+ try {
4800
+ const cleanup = await spec.render(body, this.editor);
4801
+ if (typeof cleanup === "function") mounted.cleanup = cleanup;
4802
+ return true;
4803
+ } catch (error) {
4804
+ console.error(`[nova] sidebar "${name}" failed to render`, error);
4805
+ el.remove();
4806
+ this.mounted.delete(name);
4807
+ return false;
4808
+ }
4809
+ })();
4810
+ this.mounted.set(name, mounted);
4811
+ return mounted;
4812
+ }
4813
+ };
4814
+
5216
4815
  // src/ui/tooltip.ts
5217
4816
  var SHOW_DELAY = 450;
5218
4817
  var Tooltip = class {
@@ -5270,13 +4869,14 @@ var Tooltip = class {
5270
4869
 
5271
4870
  // src/ui/manager.ts
5272
4871
  var UiManager = class {
5273
- constructor(root, t, focusEditor) {
4872
+ constructor(root, t, focusEditor, editor) {
5274
4873
  this.focusEditor = focusEditor;
5275
4874
  this.t = t;
5276
4875
  this.overlayHost = h("div", { className: "nova-overlays" });
5277
4876
  root.append(this.overlayHost);
5278
4877
  this.tooltip = new Tooltip(this.overlayHost);
5279
4878
  this.notifications = new Notifications(root, t("dialog.close"));
4879
+ this.sidebar = new Sidebars(editor);
5280
4880
  }
5281
4881
  focusEditor;
5282
4882
  registry = new Registry();
@@ -5284,9 +4884,19 @@ var UiManager = class {
5284
4884
  /** Слой для всех плавающих элементов. Лежит внутри .nova-editor, поэтому наследует тему. */
5285
4885
  overlayHost;
5286
4886
  tooltip;
4887
+ /** Боковые панели плагинов: show / hide / toggle (регистрация — registry.addSidebar). */
4888
+ sidebar;
5287
4889
  notifications;
5288
4890
  popover = null;
5289
- dialog = null;
4891
+ currentDialog = null;
4892
+ /**
4893
+ * Диалог по описанию полей (для плагинов): проверка, ошибки у полей, доступность.
4894
+ * Возвращает данные или null, если диалог закрыли. Реализация грузится при первом открытии.
4895
+ */
4896
+ async dialog(spec) {
4897
+ const { openFormDialog } = await import("./form-dialog-QH6KAERD.js");
4898
+ return openFormDialog(spec, this.t, (options) => this.openDialog(options));
4899
+ }
5290
4900
  /** Открыть поповер; одновременно открыт только один (кроме панели переполнения тулбара). */
5291
4901
  openPopover(options) {
5292
4902
  this.closePopover();
@@ -5329,7 +4939,7 @@ var UiManager = class {
5329
4939
  openDialog(options) {
5330
4940
  this.closePopover();
5331
4941
  this.dialogListeners.forEach((listener) => listener());
5332
- this.dialog?.close();
4942
+ this.currentDialog?.close();
5333
4943
  const handle = openDialog({
5334
4944
  cancelLabel: this.t("dialog.cancel"),
5335
4945
  closeLabel: this.t("dialog.close"),
@@ -5337,22 +4947,23 @@ var UiManager = class {
5337
4947
  host: this.overlayHost,
5338
4948
  returnFocus: this.focusEditor,
5339
4949
  onClose: () => {
5340
- if (this.dialog === handle) this.dialog = null;
4950
+ if (this.currentDialog === handle) this.currentDialog = null;
5341
4951
  options.onClose?.();
5342
4952
  }
5343
4953
  });
5344
- this.dialog = handle;
4954
+ this.currentDialog = handle;
5345
4955
  return handle;
5346
4956
  }
5347
4957
  get activeDialog() {
5348
- return this.dialog;
4958
+ return this.currentDialog;
5349
4959
  }
5350
4960
  notify(options) {
5351
4961
  return this.notifications.open(typeof options === "string" ? { text: options } : options);
5352
4962
  }
5353
4963
  destroy() {
4964
+ this.sidebar.destroy();
5354
4965
  this.closePopover();
5355
- this.dialog?.close();
4966
+ this.currentDialog?.close();
5356
4967
  this.tooltip.destroy();
5357
4968
  this.notifications.destroy();
5358
4969
  this.overlayHost.remove();
@@ -5360,7 +4971,13 @@ var UiManager = class {
5360
4971
  };
5361
4972
 
5362
4973
  // src/editor.ts
4974
+ var RTL_LANGUAGES = /* @__PURE__ */ new Set(["ar", "he", "iw", "fa", "ur", "ps", "sd", "ug", "yi", "dv", "ckb"]);
4975
+ function isRtlLanguage(language) {
4976
+ return !!language && RTL_LANGUAGES.has(language.toLowerCase().split(/[-_]/)[0]);
4977
+ }
5363
4978
  var htmlSerializer = new HTMLSerializer();
4979
+ var REMOTE_CHANGE_META = "nova:remote";
4980
+ var API_CHANGE_META = "nova:api";
5364
4981
  var INSERT_BLOCK_TAGS = new Set(
5365
4982
  "P H1 H2 H3 H4 H5 H6 UL OL TABLE BLOCKQUOTE PRE HR DIV FIGURE".split(" ")
5366
4983
  );
@@ -5377,6 +4994,8 @@ var Editor = class {
5377
4994
  toolbarHost;
5378
4995
  menubar;
5379
4996
  mode;
4997
+ /** Направление письма редактора (опция direction, язык или dir страницы). */
4998
+ direction;
5380
4999
  pluginsByName = /* @__PURE__ */ new Map();
5381
5000
  commandOverrides = /* @__PURE__ */ new Map();
5382
5001
  transactionTransforms = [];
@@ -5397,6 +5016,9 @@ var Editor = class {
5397
5016
  this.options = options;
5398
5017
  this.root = document.createElement("div");
5399
5018
  this.root.className = "nova-editor";
5019
+ const direction = options.direction ?? (isRtlLanguage(options.language) ? "rtl" : void 0);
5020
+ if (direction) this.root.dir = direction;
5021
+ this.direction = direction ?? (options.element.closest("[dir]")?.getAttribute("dir") === "rtl" ? "rtl" : "ltr");
5400
5022
  options.element.appendChild(this.root);
5401
5023
  const toolbarHost = document.createElement("div");
5402
5024
  const contentHost = document.createElement("div");
@@ -5415,14 +5037,20 @@ var Editor = class {
5415
5037
  this.root.addEventListener("focusin", () => this.root.classList.add("is-focused"));
5416
5038
  this.root.addEventListener("focusout", () => {
5417
5039
  setTimeout(() => {
5418
- if (!this.root.contains(document.activeElement)) this.root.classList.remove("is-focused");
5040
+ if (!this.root.contains(activeElement(this.root)))
5041
+ this.root.classList.remove("is-focused");
5419
5042
  }, 0);
5420
5043
  });
5421
5044
  }
5422
5045
  this.ui = new UiManager(
5423
5046
  this.root,
5424
5047
  createTranslator(options.language, options.translations),
5425
- () => this.focus()
5048
+ () => this.focus(),
5049
+ this
5050
+ );
5051
+ this.root.style.setProperty(
5052
+ "--nova-caption-placeholder",
5053
+ JSON.stringify(this.ui.t("image.captionPlaceholder"))
5426
5054
  );
5427
5055
  const editorKeys = keymap2({
5428
5056
  "Mod-k": () => (openLinkDialog(this), true),
@@ -5466,38 +5094,44 @@ var Editor = class {
5466
5094
  (o) => o.value.split(/\s+/).filter(Boolean)
5467
5095
  )
5468
5096
  ]);
5097
+ const htmlRules = htmlRulesFor(options);
5098
+ const allClasses = options.validClasses === true || options.validClasses === void 0 && !!htmlRules?.classOnBuiltIn;
5469
5099
  this.schema = this.buildSchema(
5470
5100
  syncPlugins,
5471
- options.validClasses === true ? () => true : (name) => allowedClasses.has(name)
5101
+ allClasses ? () => true : (name) => allowedClasses.has(name),
5102
+ htmlRules
5472
5103
  );
5473
5104
  this.formatter = new Formatter(this, allowedClasses);
5474
5105
  for (const [name, spec] of Object.entries(options.formats ?? {}))
5475
5106
  this.formatter.register(name, spec);
5476
5107
  syncPlugins.forEach((plugin) => this.registerCommands(plugin));
5477
5108
  const initialDoc = parseContent(this.schema, options.content ?? "");
5109
+ const tablesAnchor = searchPlugin();
5110
+ const initialPlugins = [
5111
+ // Первым: при открытом списке Enter/Tab/стрелки принадлежат автокомплитеру, а не раскладке клавиш.
5112
+ autocompleterPlugin(this),
5113
+ buildInputRules((name) => this.isAllowed(name), this.schema),
5114
+ editorKeys,
5115
+ // Сюда (до общей раскладки) встанут плагины таблиц после загрузки механики: Tab в таблице —
5116
+ // следующая ячейка, а не отступ списка. См. installTables().
5117
+ tablesAnchor,
5118
+ ...buildKeymap((name) => this.resolveCommand(name)),
5119
+ ...syncPlugins.some((plugin) => plugin.replaceHistory) ? [] : [history()],
5120
+ dropCursor({ color: "var(--nova-accent)", width: 2 }),
5121
+ gapCursor(),
5122
+ imageDropPastePlugin(this),
5123
+ embeddedImageUploadPlugin(this),
5124
+ pastePlugin(this),
5125
+ linkBubblePlugin(this),
5126
+ contextToolbarPlugin(this),
5127
+ ...this.contentRules ? [contentRulesPlugin(this.contentRules)] : [],
5128
+ ...pluginPm,
5129
+ ...options.prosemirrorPlugins ?? []
5130
+ ];
5131
+ keepPluginViews(initialPlugins);
5478
5132
  const state = EditorState.create({
5479
5133
  doc: this.contentRules ? this.contentRules.normalizeDoc(initialDoc) : initialDoc,
5480
- plugins: [
5481
- // Первым: при открытом списке Enter/Tab/стрелки принадлежат автокомплитеру, а не раскладке клавиш.
5482
- autocompleterPlugin(this),
5483
- buildInputRules((name) => this.isAllowed(name), this.schema),
5484
- editorKeys,
5485
- // Таблицы до общей раскладки: Tab в таблице — следующая ячейка, а не отступ списка.
5486
- ...tablePlugins(),
5487
- searchPlugin(),
5488
- ...buildKeymap((name) => this.resolveCommand(name)),
5489
- ...syncPlugins.some((plugin) => plugin.replaceHistory) ? [] : [history()],
5490
- dropCursor({ color: "var(--nova-accent)", width: 2 }),
5491
- gapCursor(),
5492
- imageDropPastePlugin(this),
5493
- embeddedImageUploadPlugin(this),
5494
- pastePlugin(this),
5495
- linkBubblePlugin(this),
5496
- contextToolbarPlugin(this),
5497
- ...this.contentRules ? [contentRulesPlugin(this.contentRules)] : [],
5498
- ...pluginPm,
5499
- ...options.prosemirrorPlugins ?? []
5500
- ]
5134
+ plugins: initialPlugins
5501
5135
  });
5502
5136
  this.editable = options.editable ?? true;
5503
5137
  this.disabled = options.disabled ?? false;
@@ -5525,8 +5159,12 @@ var Editor = class {
5525
5159
  image: (node, view, getPos) => new ImageView(node, view, getPos, this)
5526
5160
  },
5527
5161
  handleDOMEvents: {
5528
- focus: () => (this.emit("focus"), false),
5529
- blur: () => (this.emit("blur"), false)
5162
+ focus: (_view, event) => (this.emit("focus", { event }), false),
5163
+ blur: (_view, event) => (this.emit("blur", { event }), false)
5164
+ },
5165
+ handleKeyDown: (_view, event) => {
5166
+ this.emit("keydown", { event });
5167
+ return event.defaultPrevented;
5530
5168
  }
5531
5169
  });
5532
5170
  this.root.classList.toggle("nova-readonly", !this.editable);
@@ -5558,8 +5196,28 @@ var Editor = class {
5558
5196
  const contentCss = this.applyContentStyles();
5559
5197
  this.ready = Promise.all([
5560
5198
  resolved.loaders.length ? this.loadLazyPlugins(resolved.loaders) : void 0,
5561
- contentCss
5562
- ]).then(() => void 0);
5199
+ contentCss,
5200
+ // Очистка вставки из Office — отдельный чанк, грузится в фоне (см. paste.ts).
5201
+ loadPasteCleaner(),
5202
+ // Механика таблиц — отдельный чанк (~10 КБ gzip), грузится в фоне (см. tables.ts).
5203
+ this.installTables(tablesAnchor)
5204
+ ]).then(() => {
5205
+ if (!this.destroyed) this.emit("init");
5206
+ });
5207
+ }
5208
+ /**
5209
+ * Подключить механику таблиц (выделение ячеек, ширина колонок, Tab по ячейкам) после её загрузки —
5210
+ * на место перед `anchor`, как если бы плагины были в начальном состоянии.
5211
+ */
5212
+ async installTables(anchor) {
5213
+ const tables = await loadTables();
5214
+ if (!tables || this.destroyed) return;
5215
+ const { state } = this.view;
5216
+ const at = state.plugins.indexOf(anchor);
5217
+ const plugins = [...state.plugins];
5218
+ plugins.splice(at < 0 ? plugins.length : at, 0, ...tables.tablePlugins());
5219
+ reconfigurePlugins(this.view, plugins);
5220
+ this.updateUI();
5563
5221
  }
5564
5222
  /** contentStyle сразу, contentCss — по мере загрузки. Каждый редактор — своя область. */
5565
5223
  applyContentStyles() {
@@ -5602,7 +5260,7 @@ var Editor = class {
5602
5260
  * Схема с узлами и марками плагинов. Конфликт имён — ошибка конфигурации: сообщаем и работаем
5603
5261
  * на базовой схеме, чтобы редактор всё равно открылся.
5604
5262
  */
5605
- buildSchema(plugins, classFilter) {
5263
+ buildSchema(plugins, classFilter, htmlRules) {
5606
5264
  const nodes = {};
5607
5265
  const marks = {};
5608
5266
  for (const plugin of plugins) {
@@ -5617,10 +5275,10 @@ var Editor = class {
5617
5275
  }
5618
5276
  }
5619
5277
  try {
5620
- return createSchema({ nodes, marks }, classFilter);
5278
+ return createSchema({ nodes, marks }, classFilter, htmlRules, this.direction);
5621
5279
  } catch (error) {
5622
5280
  reportPluginError("Failed to build the document schema from plugins", error);
5623
- return createSchema({}, classFilter);
5281
+ return createSchema({}, classFilter, htmlRules, this.direction);
5624
5282
  }
5625
5283
  }
5626
5284
  collectPmPlugins(plugin) {
@@ -5665,8 +5323,7 @@ var Editor = class {
5665
5323
  errors.forEach((message) => reportPluginError(message));
5666
5324
  const extraPm = ordered.flatMap((plugin) => this.collectPmPlugins(plugin));
5667
5325
  if (extraPm.length) {
5668
- const state = this.view.state;
5669
- this.view.updateState(state.reconfigure({ plugins: [...state.plugins, ...extraPm] }));
5326
+ reconfigurePlugins(this.view, [...this.view.state.plugins, ...extraPm]);
5670
5327
  }
5671
5328
  ordered.forEach((plugin) => {
5672
5329
  this.registerCommands(plugin);
@@ -5708,8 +5365,14 @@ var Editor = class {
5708
5365
  this.statusbar?.update(tr.docChanged);
5709
5366
  this.searchBar?.update();
5710
5367
  this.updatePlaceholder();
5711
- if (tr.docChanged) this.emit("change");
5712
- if (tr.selectionSet || tr.docChanged) this.emit("selectionChange");
5368
+ if (tr.docChanged) {
5369
+ this.emit("change", { transaction: tr });
5370
+ const programmatic = tr.getMeta(API_CHANGE_META) || tr.getMeta(REMOTE_CHANGE_META);
5371
+ if (!programmatic && tr.getMeta("addToHistory") !== false) {
5372
+ this.emit("input", { transaction: tr });
5373
+ }
5374
+ }
5375
+ if (tr.selectionSet || tr.docChanged) this.emit("selectionChange", { transaction: tr });
5713
5376
  }
5714
5377
  updatePlaceholder() {
5715
5378
  const doc = this.view.state.doc;
@@ -5729,10 +5392,14 @@ var Editor = class {
5729
5392
  }
5730
5393
  /** Заменить содержимое. По умолчанию попадает в историю undo. */
5731
5394
  setContent(content, { addToHistory = true } = {}) {
5732
- const doc = parseContent(this.schema, content);
5395
+ const detail = { content };
5396
+ this.emit("beforeSetContent", detail);
5397
+ const doc = parseContent(this.schema, detail.content);
5733
5398
  const tr = this.view.state.tr.replaceWith(0, this.view.state.doc.content.size, doc.content);
5399
+ tr.setMeta(API_CHANGE_META, true);
5734
5400
  if (!addToHistory) tr.setMeta("addToHistory", false);
5735
5401
  this.view.dispatch(tr);
5402
+ this.emit("setContent", { content: detail.content });
5736
5403
  }
5737
5404
  /**
5738
5405
  * Вставить HTML в позицию курсора (как insertContent в TinyMCE). HTML разбирается схемой
@@ -5764,7 +5431,7 @@ var Editor = class {
5764
5431
  }
5765
5432
  }
5766
5433
  const tr = hasTable && tableDepth ? state.tr.insert($from.after(tableDepth), slice.content) : state.tr.replaceSelection(slice);
5767
- this.view.dispatch(tr.scrollIntoView());
5434
+ this.view.dispatch(tr.setMeta(API_CHANGE_META, true).scrollIntoView());
5768
5435
  return true;
5769
5436
  }
5770
5437
  isEmpty() {
@@ -5797,6 +5464,13 @@ var Editor = class {
5797
5464
  isActive(command) {
5798
5465
  return isCommandActive(this.view.state, command);
5799
5466
  }
5467
+ /**
5468
+ * Состояние именованной команды для своего тулбара: активна ли (подсветка кнопки) и доступна ли
5469
+ * сейчас. Аналог queryCommandState / queryCommandEnabled.
5470
+ */
5471
+ getCommandState(command) {
5472
+ return { active: this.isActive(command), enabled: this.isEditable() && this.can(command) };
5473
+ }
5800
5474
  focus() {
5801
5475
  if (!this.destroyed) this.view.focus();
5802
5476
  }
@@ -5861,8 +5535,14 @@ var Editor = class {
5861
5535
  off(event, listener) {
5862
5536
  this.listeners.get(event)?.delete(listener);
5863
5537
  }
5864
- emit(event) {
5865
- for (const listener of this.listeners.get(event) ?? []) listener(this);
5538
+ emit(event, ...[detail]) {
5539
+ for (const listener of this.listeners.get(event) ?? []) {
5540
+ try {
5541
+ listener(this, detail);
5542
+ } catch (error) {
5543
+ reportPluginError(`Listener for "${event}" failed`, error);
5544
+ }
5545
+ }
5866
5546
  }
5867
5547
  destroy() {
5868
5548
  if (this.destroyed) return;
@@ -5889,8 +5569,45 @@ var Editor = class {
5889
5569
  function reportPluginError(message, error) {
5890
5570
  console.error(`[nova] ${message}`, ...error === void 0 ? [] : [error]);
5891
5571
  }
5572
+ function attrValid(spec, value) {
5573
+ const validate = spec?.validate;
5574
+ if (!validate) return true;
5575
+ if (typeof validate === "function") {
5576
+ try {
5577
+ validate(value);
5578
+ return true;
5579
+ } catch {
5580
+ return false;
5581
+ }
5582
+ }
5583
+ const type = value === null ? "null" : typeof value;
5584
+ return validate.split("|").includes(type);
5585
+ }
5586
+ function sanitizeAttrs(specs, attrs) {
5587
+ if (!attrs || typeof attrs !== "object" || !specs) return attrs;
5588
+ return Object.fromEntries(
5589
+ Object.entries(attrs).filter(([name, value]) => attrValid(specs[name], value))
5590
+ );
5591
+ }
5592
+ function sanitizeJSON(schema2, json) {
5593
+ const type = schema2.nodes[json.type];
5594
+ const out = { ...json };
5595
+ if (type) out.attrs = sanitizeAttrs(type.spec.attrs, json.attrs);
5596
+ if (Array.isArray(json.marks)) {
5597
+ out.marks = json.marks.map((mark) => {
5598
+ const markType = mark && schema2.marks[mark.type];
5599
+ return markType ? { ...mark, attrs: sanitizeAttrs(markType.spec.attrs, mark.attrs) } : mark;
5600
+ });
5601
+ }
5602
+ if (Array.isArray(json.content)) {
5603
+ out.content = json.content.map(
5604
+ (child) => child && typeof child === "object" ? sanitizeJSON(schema2, child) : child
5605
+ );
5606
+ }
5607
+ return out;
5608
+ }
5892
5609
  function parseContent(schema2, content) {
5893
- if (typeof content !== "string") return PMNode.fromJSON(schema2, content);
5610
+ if (typeof content !== "string") return PMNode.fromJSON(schema2, sanitizeJSON(schema2, content));
5894
5611
  const container = document.createElement("div");
5895
5612
  const template = document.createElement("template");
5896
5613
  template.innerHTML = content;
@@ -5903,10 +5620,6 @@ function createEditor(options) {
5903
5620
 
5904
5621
  export {
5905
5622
  Formatter,
5906
- en,
5907
- ru,
5908
- registerLanguage,
5909
- createTranslator,
5910
5623
  htmlToPlainText,
5911
5624
  parserFor,
5912
5625
  DEFAULT_MENUS,
@@ -5942,8 +5655,10 @@ export {
5942
5655
  defaultSlashCommands,
5943
5656
  rankSlashCommands,
5944
5657
  countWords,
5658
+ REMOTE_CHANGE_META,
5659
+ API_CHANGE_META,
5945
5660
  Editor,
5946
5661
  parseContent,
5947
5662
  createEditor
5948
5663
  };
5949
- //# sourceMappingURL=chunk-46RIM5KP.js.map
5664
+ //# sourceMappingURL=chunk-DWZLSZDG.js.map