@novaprose/core 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +51 -17
  2. package/dist/{advlist-FH3K3AAQ.js → advlist-K2U3VPH2.js} +3 -3
  3. package/dist/{autolink-IDJWAL2V.js → autolink-XWDTLY37.js} +2 -2
  4. package/dist/{autoresize-4ZEPQCHP.js → autoresize-UB3GOA6D.js} +2 -2
  5. package/dist/{autosave-DH7SO4UQ.js → autosave-MWNRUNU3.js} +3 -3
  6. package/dist/{charmap-F7EVJ56K.js → charmap-ADLYOIB3.js} +3 -3
  7. package/dist/{chunk-6AL2IS6V.js → chunk-435CRWKA.js} +69 -8
  8. package/dist/chunk-435CRWKA.js.map +1 -0
  9. package/dist/{chunk-55LD2TT2.js → chunk-46RIM5KP.js} +932 -32
  10. package/dist/chunk-46RIM5KP.js.map +1 -0
  11. package/dist/{chunk-YZPJQB3I.js → chunk-7ON7PR5R.js} +106 -25
  12. package/dist/chunk-7ON7PR5R.js.map +1 -0
  13. package/dist/{chunk-6GWG2BLC.js → chunk-HPLT3XRZ.js} +1 -1
  14. package/dist/chunk-HPLT3XRZ.js.map +1 -0
  15. package/dist/{chunk-MOO4PJGI.js → chunk-NPKAIW34.js} +11 -1
  16. package/dist/{chunk-MOO4PJGI.js.map → chunk-NPKAIW34.js.map} +1 -1
  17. package/dist/{directionality-MF5HDXH3.js → directionality-XOHJFSL6.js} +3 -3
  18. package/dist/{emoticons-SONBUCFV.js → emoticons-TP4N4ZGY.js} +3 -3
  19. package/dist/index.cjs +1424 -162
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +248 -11
  22. package/dist/index.d.ts +248 -11
  23. package/dist/index.js +212 -25
  24. package/dist/index.js.map +1 -1
  25. package/dist/{insertdatetime-X2T4ZY6R.js → insertdatetime-T4SEMQWP.js} +3 -3
  26. package/dist/{nonbreaking-PP4KIJSR.js → nonbreaking-HG5HV6AL.js} +3 -3
  27. package/dist/{quickbars-3WKHLKAR.js → quickbars-4NU4SIPL.js} +5 -5
  28. package/dist/{revisionhistory-FYRVDGRA.js → revisionhistory-3YQPLPLM.js} +6 -6
  29. package/dist/{visualblocks-NPTMWFXD.js → visualblocks-RTAYJOGR.js} +3 -3
  30. package/package.json +1 -1
  31. package/src/style.css +106 -0
  32. package/dist/chunk-55LD2TT2.js.map +0 -1
  33. package/dist/chunk-6AL2IS6V.js.map +0 -1
  34. package/dist/chunk-6GWG2BLC.js.map +0 -1
  35. package/dist/chunk-YZPJQB3I.js.map +0 -1
  36. /package/dist/{advlist-FH3K3AAQ.js.map → advlist-K2U3VPH2.js.map} +0 -0
  37. /package/dist/{autolink-IDJWAL2V.js.map → autolink-XWDTLY37.js.map} +0 -0
  38. /package/dist/{autoresize-4ZEPQCHP.js.map → autoresize-UB3GOA6D.js.map} +0 -0
  39. /package/dist/{autosave-DH7SO4UQ.js.map → autosave-MWNRUNU3.js.map} +0 -0
  40. /package/dist/{charmap-F7EVJ56K.js.map → charmap-ADLYOIB3.js.map} +0 -0
  41. /package/dist/{directionality-MF5HDXH3.js.map → directionality-XOHJFSL6.js.map} +0 -0
  42. /package/dist/{emoticons-SONBUCFV.js.map → emoticons-TP4N4ZGY.js.map} +0 -0
  43. /package/dist/{insertdatetime-X2T4ZY6R.js.map → insertdatetime-T4SEMQWP.js.map} +0 -0
  44. /package/dist/{nonbreaking-PP4KIJSR.js.map → nonbreaking-HG5HV6AL.js.map} +0 -0
  45. /package/dist/{quickbars-3WKHLKAR.js.map → quickbars-4NU4SIPL.js.map} +0 -0
  46. /package/dist/{revisionhistory-FYRVDGRA.js.map → revisionhistory-3YQPLPLM.js.map} +0 -0
  47. /package/dist/{visualblocks-NPTMWFXD.js.map → visualblocks-RTAYJOGR.js.map} +0 -0
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  DEFAULT_MENUBAR,
4
4
  DEFAULT_MENUS,
5
5
  Editor,
6
+ Formatter,
6
7
  HTMLSerializer,
7
8
  KNOWN_STYLES,
8
9
  KNOWN_TAGS,
@@ -40,7 +41,7 @@ import {
40
41
  setSearch,
41
42
  setStyle,
42
43
  toggleFullscreen
43
- } from "./chunk-55LD2TT2.js";
44
+ } from "./chunk-46RIM5KP.js";
44
45
  import {
45
46
  COMMENT_ID_RE,
46
47
  COMMENT_MAX_LENGTH,
@@ -51,6 +52,7 @@ import {
51
52
  } from "./chunk-Z3ELZ77W.js";
52
53
  import {
53
54
  applyLink,
55
+ attachFilePicker,
54
56
  createTable,
55
57
  getSelectedImage,
56
58
  hasHeaderColumn,
@@ -68,13 +70,13 @@ import {
68
70
  tableCommands,
69
71
  textField,
70
72
  uploadImages
71
- } from "./chunk-6AL2IS6V.js";
73
+ } from "./chunk-435CRWKA.js";
72
74
  import {
73
75
  createSchema,
74
76
  cssValue,
75
77
  imageSize,
76
78
  schema
77
- } from "./chunk-YZPJQB3I.js";
79
+ } from "./chunk-7ON7PR5R.js";
78
80
  import {
79
81
  pickLabels
80
82
  } from "./chunk-6RJENZXT.js";
@@ -83,7 +85,7 @@ import {
83
85
  } from "./chunk-HZRIBOPW.js";
84
86
  import {
85
87
  icons
86
- } from "./chunk-MOO4PJGI.js";
88
+ } from "./chunk-NPKAIW34.js";
87
89
  import {
88
90
  commands,
89
91
  getActiveAlign,
@@ -102,7 +104,7 @@ import {
102
104
  definePlugin,
103
105
  isPluginRegistered,
104
106
  registerPlugin
105
- } from "./chunk-6GWG2BLC.js";
107
+ } from "./chunk-HPLT3XRZ.js";
106
108
 
107
109
  // src/plugins/anchor.ts
108
110
  import { NodeSelection } from "prosemirror-state";
@@ -670,6 +672,186 @@ var comments_default = definePlugin({
670
672
  }
671
673
  });
672
674
 
675
+ // src/plugins/mergetags.ts
676
+ import { Plugin as PMPlugin } from "prosemirror-state";
677
+ var LABELS4 = {
678
+ en: {
679
+ insert: "Insert variable",
680
+ search: "Variables",
681
+ empty: "No variables found",
682
+ unknown: "Unknown variable"
683
+ },
684
+ ru: {
685
+ insert: "\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u043F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u0443\u044E",
686
+ search: "\u041F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u044B\u0435",
687
+ empty: "\u041F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u044B\u0435 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u044B",
688
+ unknown: "\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u0430\u044F"
689
+ }
690
+ };
691
+ var KEY_RE = /^[\w.:-]{1,100}$/;
692
+ var ATTR_RE = /^data-[a-z0-9-]{1,40}$/;
693
+ function optionsOf(editor) {
694
+ return editor.options.pluginOptions?.mergetags ?? {};
695
+ }
696
+ function attributeOf(editor) {
697
+ const attribute = optionsOf(editor).attribute ?? "data-mergetag";
698
+ if (ATTR_RE.test(attribute)) return attribute;
699
+ console.warn(
700
+ `[nova] mergetags: attribute "${attribute}" must look like data-name; using data-mergetag`
701
+ );
702
+ return "data-mergetag";
703
+ }
704
+ var isGroup = (entry) => Array.isArray(entry.items);
705
+ function flatList(editor) {
706
+ return (optionsOf(editor).list ?? []).flatMap(
707
+ (entry) => isGroup(entry) ? entry.items : [entry]
708
+ );
709
+ }
710
+ function labelFor(editor, key) {
711
+ return flatList(editor).find((tag) => tag.key === key)?.label;
712
+ }
713
+ function buildNodes(editor) {
714
+ const attribute = attributeOf(editor);
715
+ return {
716
+ mergetag: {
717
+ group: "inline",
718
+ inline: true,
719
+ atom: true,
720
+ selectable: true,
721
+ draggable: true,
722
+ // Свой style «фишки» (цвет, фон, жирность) — оформление, а не формат текста вокруг.
723
+ ignoreStyles: true,
724
+ attrs: { key: {}, label: { default: "" } },
725
+ parseDOM: [
726
+ {
727
+ tag: `span[${attribute}]`,
728
+ // Выше марок и стилей: переменная — целый узел, а не span с форматированием.
729
+ priority: 60,
730
+ getAttrs: (dom) => {
731
+ const el = dom;
732
+ const key = el.getAttribute(attribute) ?? "";
733
+ if (!KEY_RE.test(key)) return false;
734
+ return { key, label: labelFor(editor, key) ?? el.textContent?.trim() ?? key };
735
+ }
736
+ }
737
+ ],
738
+ // Документ мог прийти из JSON — ключ проверяем и на выходе.
739
+ toDOM: (node) => {
740
+ const key = KEY_RE.test(node.attrs.key) ? node.attrs.key : "";
741
+ const label = node.attrs.label || key;
742
+ return ["span", { [attribute]: key, contenteditable: "false" }, label];
743
+ }
744
+ }
745
+ };
746
+ }
747
+ var MergeTagView = class {
748
+ constructor(node, editor, unknownTitle) {
749
+ this.node = node;
750
+ this.editor = editor;
751
+ this.unknownTitle = unknownTitle;
752
+ this.dom = document.createElement("span");
753
+ this.dom.className = "nova-mergetag";
754
+ this.dom.contentEditable = "false";
755
+ this.render();
756
+ }
757
+ node;
758
+ editor;
759
+ unknownTitle;
760
+ dom;
761
+ render() {
762
+ const key = this.node.attrs.key;
763
+ const known = labelFor(this.editor, key);
764
+ this.dom.textContent = known ?? (this.node.attrs.label || key);
765
+ this.dom.dataset.key = key;
766
+ const list = optionsOf(this.editor).list;
767
+ const unknown = !!list?.length && known === void 0;
768
+ this.dom.classList.toggle("is-unknown", unknown);
769
+ this.dom.title = unknown ? `${this.unknownTitle}: ${key}` : key;
770
+ }
771
+ update(node) {
772
+ if (node.type !== this.node.type) return false;
773
+ this.node = node;
774
+ this.render();
775
+ return true;
776
+ }
777
+ selectNode() {
778
+ this.dom.classList.add("is-selected");
779
+ }
780
+ deselectNode() {
781
+ this.dom.classList.remove("is-selected");
782
+ }
783
+ stopEvent() {
784
+ return false;
785
+ }
786
+ ignoreMutation() {
787
+ return true;
788
+ }
789
+ };
790
+ function insertTag(editor, tag, range) {
791
+ const { state, dispatch } = editor.view;
792
+ const node = editor.schema.nodes.mergetag.create({ key: tag.key, label: tag.label });
793
+ const tr = range ? state.tr.replaceWith(range.from, range.to, node) : state.tr.replaceSelectionWith(node, false);
794
+ dispatch(tr.scrollIntoView());
795
+ editor.focus();
796
+ }
797
+ var mergetags_default = definePlugin({
798
+ name: "mergetags",
799
+ toolbar: "mergetags",
800
+ nodes: buildNodes,
801
+ prosemirrorPlugins: (editor) => {
802
+ const labels = pickLabels(editor, LABELS4);
803
+ return [
804
+ new PMPlugin({
805
+ props: {
806
+ nodeViews: {
807
+ mergetag: (node, _view) => new MergeTagView(node, editor, labels.unknown)
808
+ }
809
+ }
810
+ })
811
+ ];
812
+ },
813
+ setup(editor) {
814
+ const labels = pickLabels(editor, LABELS4);
815
+ editor.ui.registry.addMenuButton("mergetags", {
816
+ icon: icons.mergeTags,
817
+ tooltip: labels.insert,
818
+ isEnabled: (e) => e.isEditable() && flatList(e).length > 0,
819
+ items: (e) => {
820
+ const entries = [];
821
+ const item = (tag, id) => ({
822
+ id,
823
+ label: tag.label,
824
+ onSelect: () => insertTag(e, tag)
825
+ });
826
+ (optionsOf(e).list ?? []).forEach((entry, index) => {
827
+ if (isGroup(entry)) {
828
+ if (entries.length) entries.push({ type: "separator" });
829
+ entries.push({ type: "heading", label: entry.title });
830
+ entry.items.forEach((tag, i) => entries.push(item(tag, `mergetag-${index}-${i}`)));
831
+ } else {
832
+ entries.push(item(entry, `mergetag-${index}`));
833
+ }
834
+ });
835
+ return entries;
836
+ }
837
+ });
838
+ editor.ui.registry.addAutocompleter("mergetags", {
839
+ trigger: "{{",
840
+ label: labels.search,
841
+ emptyText: labels.empty,
842
+ maxResults: 12,
843
+ fetch: (query, e) => {
844
+ const q = query.toLowerCase();
845
+ return flatList(e).filter((tag) => tag.label.toLowerCase().includes(q) || tag.key.toLowerCase().includes(q)).map((tag) => ({ value: tag.key, label: tag.label, detail: tag.key }));
846
+ },
847
+ onSelect: (item, range, e) => {
848
+ const tag = flatList(e).find((t) => t.key === item.value);
849
+ if (tag) insertTag(e, tag, range);
850
+ }
851
+ });
852
+ }
853
+ });
854
+
673
855
  // src/plugins/suggestions.ts
674
856
  import {
675
857
  Fragment,
@@ -685,7 +867,7 @@ import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "pros
685
867
  import { keymap as keymap2 } from "prosemirror-keymap";
686
868
  var ID_RE2 = /^[A-Za-z0-9_-]{1,64}$/;
687
869
  var USER_ID_RE = /^[\w.@:+-]{1,128}$/;
688
- var LABELS4 = {
870
+ var LABELS5 = {
689
871
  en: {
690
872
  toggle: "Suggest edits",
691
873
  review: "Review suggestions",
@@ -970,7 +1152,7 @@ var suggestions_default = definePlugin({
970
1152
  attributes: (state) => suggestionsKey.getState(state)?.enabled ? { class: "nova-suggesting" } : {},
971
1153
  decorations(state) {
972
1154
  if (cache?.doc === state.doc) return cache.set;
973
- const labels = pickLabels(editor, LABELS4);
1155
+ const labels = pickLabels(editor, LABELS5);
974
1156
  const time = new Intl.DateTimeFormat(editor.options.language ?? "en", {
975
1157
  dateStyle: "medium",
976
1158
  timeStyle: "short"
@@ -1006,7 +1188,7 @@ var suggestions_default = definePlugin({
1006
1188
  transformTransaction(tr, state, editor) {
1007
1189
  if (!isSuggesting(state)) return tr;
1008
1190
  const options = editor.options.pluginOptions?.suggestions ?? {};
1009
- const labels = pickLabels(editor, LABELS4);
1191
+ const labels = pickLabels(editor, LABELS5);
1010
1192
  const author = {
1011
1193
  id: USER_ID_RE.test(options.author?.id ?? "") ? options.author.id : "guest",
1012
1194
  name: String(options.author?.name || labels.guest).slice(0, 80)
@@ -1015,7 +1197,7 @@ var suggestions_default = definePlugin({
1015
1197
  },
1016
1198
  setup(editor) {
1017
1199
  const options = editor.options.pluginOptions?.suggestions ?? {};
1018
- const labels = pickLabels(editor, LABELS4);
1200
+ const labels = pickLabels(editor, LABELS5);
1019
1201
  const canReview = options.canReview !== false;
1020
1202
  const dispatch = (tr) => editor.view.dispatch(tr);
1021
1203
  const current = () => suggestionAt(editor.view.state);
@@ -1117,7 +1299,7 @@ function parseMediaUrl(url) {
1117
1299
  return null;
1118
1300
  }
1119
1301
  var ICON2 = icons.media;
1120
- var LABELS5 = {
1302
+ var LABELS6 = {
1121
1303
  en: {
1122
1304
  title: "Video",
1123
1305
  url: "Video URL",
@@ -1237,7 +1419,7 @@ var media_default = definePlugin({
1237
1419
  })
1238
1420
  ],
1239
1421
  setup(editor) {
1240
- const labels = pickLabels(editor, LABELS5);
1422
+ const labels = pickLabels(editor, LABELS6);
1241
1423
  const selected = () => {
1242
1424
  const { selection } = editor.view.state;
1243
1425
  return selection instanceof NodeSelection2 && selection.node.type.name === "media" ? selection : null;
@@ -1255,6 +1437,9 @@ var media_default = definePlugin({
1255
1437
  label: labels.name,
1256
1438
  value: current?.node.attrs.title ?? ""
1257
1439
  });
1440
+ attachFilePicker(editor, url, "media", (picked) => {
1441
+ if (picked.title) title.input.value = picked.title;
1442
+ });
1258
1443
  editor.ui.openDialog({
1259
1444
  title: labels.title,
1260
1445
  body: h("div", { className: "nova-form" }, url.el, title.el),
@@ -1288,7 +1473,7 @@ var media_default = definePlugin({
1288
1473
 
1289
1474
  // src/plugins/pagebreak.ts
1290
1475
  var ICON3 = icons.pageBreak;
1291
- var LABELS6 = { en: { title: "Page break" }, ru: { title: "\u0420\u0430\u0437\u0440\u044B\u0432 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B" } };
1476
+ var LABELS7 = { en: { title: "Page break" }, ru: { title: "\u0420\u0430\u0437\u0440\u044B\u0432 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B" } };
1292
1477
  var pagebreak_default = definePlugin({
1293
1478
  name: "pagebreak",
1294
1479
  toolbar: "pagebreak",
@@ -1313,7 +1498,7 @@ var pagebreak_default = definePlugin({
1313
1498
  }
1314
1499
  },
1315
1500
  setup(editor) {
1316
- const { title } = pickLabels(editor, LABELS6);
1501
+ const { title } = pickLabels(editor, LABELS7);
1317
1502
  const insert = () => {
1318
1503
  const { state, dispatch } = editor.view;
1319
1504
  const type = editor.schema.nodes.pagebreak;
@@ -1331,29 +1516,31 @@ var pagebreak_default = definePlugin({
1331
1516
  });
1332
1517
 
1333
1518
  // src/plugins/index.ts
1334
- registerPlugin("insertdatetime", () => import("./insertdatetime-X2T4ZY6R.js"));
1335
- registerPlugin("quickbars", () => import("./quickbars-3WKHLKAR.js"));
1336
- registerPlugin("charmap", () => import("./charmap-F7EVJ56K.js"));
1337
- registerPlugin("emoticons", () => import("./emoticons-SONBUCFV.js"));
1338
- registerPlugin("nonbreaking", () => import("./nonbreaking-PP4KIJSR.js"));
1339
- registerPlugin("autolink", () => import("./autolink-IDJWAL2V.js"));
1340
- registerPlugin("autosave", () => import("./autosave-DH7SO4UQ.js"));
1341
- registerPlugin("autoresize", () => import("./autoresize-4ZEPQCHP.js"));
1342
- registerPlugin("visualblocks", () => import("./visualblocks-NPTMWFXD.js"));
1519
+ registerPlugin("insertdatetime", () => import("./insertdatetime-T4SEMQWP.js"));
1520
+ registerPlugin("quickbars", () => import("./quickbars-4NU4SIPL.js"));
1521
+ registerPlugin("charmap", () => import("./charmap-ADLYOIB3.js"));
1522
+ registerPlugin("emoticons", () => import("./emoticons-TP4N4ZGY.js"));
1523
+ registerPlugin("nonbreaking", () => import("./nonbreaking-HG5HV6AL.js"));
1524
+ registerPlugin("autolink", () => import("./autolink-XWDTLY37.js"));
1525
+ registerPlugin("autosave", () => import("./autosave-MWNRUNU3.js"));
1526
+ registerPlugin("autoresize", () => import("./autoresize-UB3GOA6D.js"));
1527
+ registerPlugin("visualblocks", () => import("./visualblocks-RTAYJOGR.js"));
1343
1528
  registerPlugin("anchor", anchor_default);
1344
1529
  registerPlugin("pagebreak", pagebreak_default);
1345
1530
  registerPlugin("media", media_default);
1346
1531
  registerPlugin("comments", comments_default);
1347
1532
  registerPlugin("mentions", mentions_default);
1533
+ registerPlugin("mergetags", mergetags_default);
1348
1534
  registerPlugin("suggestions", suggestions_default);
1349
- registerPlugin("directionality", () => import("./directionality-MF5HDXH3.js"));
1350
- registerPlugin("advlist", () => import("./advlist-FH3K3AAQ.js"));
1351
- registerPlugin("revisionhistory", () => import("./revisionhistory-FYRVDGRA.js"));
1535
+ registerPlugin("directionality", () => import("./directionality-XOHJFSL6.js"));
1536
+ registerPlugin("advlist", () => import("./advlist-K2U3VPH2.js"));
1537
+ registerPlugin("revisionhistory", () => import("./revisionhistory-3YQPLPLM.js"));
1352
1538
  export {
1353
1539
  ContentRules,
1354
1540
  DEFAULT_MENUBAR,
1355
1541
  DEFAULT_MENUS,
1356
1542
  Editor,
1543
+ Formatter,
1357
1544
  HTMLSerializer,
1358
1545
  KNOWN_STYLES,
1359
1546
  KNOWN_TAGS,