@novaprose/core 0.3.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{advlist-DEJUHLI6.js → advlist-FH3K3AAQ.js} +2 -2
- package/dist/{autolink-ZVHNOOS7.js → autolink-IDJWAL2V.js} +2 -2
- package/dist/{autoresize-WT4ONZKK.js → autoresize-4ZEPQCHP.js} +2 -2
- package/dist/{autosave-2KI5WGV5.js → autosave-WODRZ7L6.js} +2 -2
- package/dist/{charmap-3LM5LZCC.js → charmap-LWA7TL3K.js} +2 -2
- package/dist/{chunk-BGG3UVGZ.js → chunk-2A3IYKPE.js} +5 -2
- package/dist/chunk-2A3IYKPE.js.map +1 -0
- package/dist/{chunk-F6TSOU5U.js → chunk-6GWG2BLC.js} +1 -1
- package/dist/chunk-6GWG2BLC.js.map +1 -0
- package/dist/{directionality-MTLAIFIQ.js → directionality-N62ZB7CF.js} +2 -2
- package/dist/{emoticons-YVGVA76P.js → emoticons-WQ3K4J6G.js} +2 -2
- package/dist/index.cjs +591 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +129 -2
- package/dist/index.d.ts +129 -2
- package/dist/index.js +461 -20
- package/dist/index.js.map +1 -1
- package/dist/{insertdatetime-QYWZUYO4.js → insertdatetime-2RZ3UUQE.js} +2 -2
- package/dist/{nonbreaking-SIACL5V6.js → nonbreaking-L6GNDHVO.js} +2 -2
- package/dist/{quickbars-TYJG6WTF.js → quickbars-TIRY3RH4.js} +2 -2
- package/dist/{revisionhistory-ZCRBPP33.js → revisionhistory-GDTOULKS.js} +3 -3
- package/dist/{visualblocks-WB6NAEGB.js → visualblocks-V4CQ4XMF.js} +2 -2
- package/package.json +1 -1
- package/src/style.css +111 -0
- package/dist/chunk-BGG3UVGZ.js.map +0 -1
- package/dist/chunk-F6TSOU5U.js.map +0 -1
- /package/dist/{advlist-DEJUHLI6.js.map → advlist-FH3K3AAQ.js.map} +0 -0
- /package/dist/{autolink-ZVHNOOS7.js.map → autolink-IDJWAL2V.js.map} +0 -0
- /package/dist/{autoresize-WT4ONZKK.js.map → autoresize-4ZEPQCHP.js.map} +0 -0
- /package/dist/{autosave-2KI5WGV5.js.map → autosave-WODRZ7L6.js.map} +0 -0
- /package/dist/{charmap-3LM5LZCC.js.map → charmap-LWA7TL3K.js.map} +0 -0
- /package/dist/{directionality-MTLAIFIQ.js.map → directionality-N62ZB7CF.js.map} +0 -0
- /package/dist/{emoticons-YVGVA76P.js.map → emoticons-WQ3K4J6G.js.map} +0 -0
- /package/dist/{insertdatetime-QYWZUYO4.js.map → insertdatetime-2RZ3UUQE.js.map} +0 -0
- /package/dist/{nonbreaking-SIACL5V6.js.map → nonbreaking-L6GNDHVO.js.map} +0 -0
- /package/dist/{quickbars-TYJG6WTF.js.map → quickbars-TIRY3RH4.js.map} +0 -0
- /package/dist/{revisionhistory-ZCRBPP33.js.map → revisionhistory-GDTOULKS.js.map} +0 -0
- /package/dist/{visualblocks-WB6NAEGB.js.map → visualblocks-V4CQ4XMF.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
|
+
HTMLSerializer,
|
|
6
7
|
KNOWN_STYLES,
|
|
7
8
|
KNOWN_TAGS,
|
|
8
9
|
clearSearch,
|
|
@@ -39,7 +40,7 @@ import {
|
|
|
39
40
|
setSearch,
|
|
40
41
|
setStyle,
|
|
41
42
|
toggleFullscreen
|
|
42
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-2A3IYKPE.js";
|
|
43
44
|
import {
|
|
44
45
|
COMMENT_ID_RE,
|
|
45
46
|
COMMENT_MAX_LENGTH,
|
|
@@ -54,6 +55,7 @@ import {
|
|
|
54
55
|
getSelectedImage,
|
|
55
56
|
hasHeaderColumn,
|
|
56
57
|
hasHeaderRow,
|
|
58
|
+
icons,
|
|
57
59
|
insertTable,
|
|
58
60
|
isInTable,
|
|
59
61
|
normalizeUrl,
|
|
@@ -98,7 +100,7 @@ import {
|
|
|
98
100
|
definePlugin,
|
|
99
101
|
isPluginRegistered,
|
|
100
102
|
registerPlugin
|
|
101
|
-
} from "./chunk-
|
|
103
|
+
} from "./chunk-6GWG2BLC.js";
|
|
102
104
|
|
|
103
105
|
// src/plugins/anchor.ts
|
|
104
106
|
import { NodeSelection } from "prosemirror-state";
|
|
@@ -666,8 +668,439 @@ var comments_default = definePlugin({
|
|
|
666
668
|
}
|
|
667
669
|
});
|
|
668
670
|
|
|
671
|
+
// src/plugins/suggestions.ts
|
|
672
|
+
import {
|
|
673
|
+
Fragment,
|
|
674
|
+
Slice
|
|
675
|
+
} from "prosemirror-model";
|
|
676
|
+
import {
|
|
677
|
+
Plugin as Plugin2,
|
|
678
|
+
PluginKey as PluginKey2,
|
|
679
|
+
TextSelection
|
|
680
|
+
} from "prosemirror-state";
|
|
681
|
+
import { ReplaceStep } from "prosemirror-transform";
|
|
682
|
+
import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "prosemirror-view";
|
|
683
|
+
import { keymap as keymap2 } from "prosemirror-keymap";
|
|
684
|
+
var ID_RE2 = /^[A-Za-z0-9_-]{1,64}$/;
|
|
685
|
+
var USER_ID_RE = /^[\w.@:+-]{1,128}$/;
|
|
686
|
+
var LABELS4 = {
|
|
687
|
+
en: {
|
|
688
|
+
toggle: "Suggest edits",
|
|
689
|
+
review: "Review suggestions",
|
|
690
|
+
accept: "Accept",
|
|
691
|
+
reject: "Reject",
|
|
692
|
+
acceptAll: "Accept all suggestions",
|
|
693
|
+
rejectAll: "Reject all suggestions",
|
|
694
|
+
next: "Next suggestion",
|
|
695
|
+
previous: "Previous suggestion",
|
|
696
|
+
inserted: "Inserted by {name}",
|
|
697
|
+
deleted: "Deleted by {name}",
|
|
698
|
+
toolbar: "Suggestion",
|
|
699
|
+
guest: "Guest",
|
|
700
|
+
none: "No suggestions"
|
|
701
|
+
},
|
|
702
|
+
ru: {
|
|
703
|
+
toggle: "\u041F\u0440\u0435\u0434\u043B\u0430\u0433\u0430\u0442\u044C \u043F\u0440\u0430\u0432\u043A\u0438",
|
|
704
|
+
review: "\u041F\u0440\u0430\u0432\u043A\u0438",
|
|
705
|
+
accept: "\u041F\u0440\u0438\u043D\u044F\u0442\u044C",
|
|
706
|
+
reject: "\u041E\u0442\u043A\u043B\u043E\u043D\u0438\u0442\u044C",
|
|
707
|
+
acceptAll: "\u041F\u0440\u0438\u043D\u044F\u0442\u044C \u0432\u0441\u0435 \u043F\u0440\u0430\u0432\u043A\u0438",
|
|
708
|
+
rejectAll: "\u041E\u0442\u043A\u043B\u043E\u043D\u0438\u0442\u044C \u0432\u0441\u0435 \u043F\u0440\u0430\u0432\u043A\u0438",
|
|
709
|
+
next: "\u0421\u043B\u0435\u0434\u0443\u044E\u0449\u0430\u044F \u043F\u0440\u0430\u0432\u043A\u0430",
|
|
710
|
+
previous: "\u041F\u0440\u0435\u0434\u044B\u0434\u0443\u0449\u0430\u044F \u043F\u0440\u0430\u0432\u043A\u0430",
|
|
711
|
+
inserted: "\u0412\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u043E: {name}",
|
|
712
|
+
deleted: "\u0423\u0434\u0430\u043B\u0435\u043D\u043E: {name}",
|
|
713
|
+
toolbar: "\u041F\u0440\u0430\u0432\u043A\u0430",
|
|
714
|
+
guest: "\u0413\u043E\u0441\u0442\u044C",
|
|
715
|
+
none: "\u041F\u0440\u0430\u0432\u043E\u043A \u043D\u0435\u0442"
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
var ICON_TOGGLE = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/></svg>';
|
|
719
|
+
var ICON_REVIEW = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 11l3 3 8-8"/><path d="M20 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/></svg>';
|
|
720
|
+
var ICON_ACCEPT = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>';
|
|
721
|
+
var ICON_REJECT = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>';
|
|
722
|
+
var suggestionsKey = new PluginKey2("nova-suggestions");
|
|
723
|
+
var OWN = "nova-suggestions-own";
|
|
724
|
+
var PALETTE = ["#1a7f37", "#8250df", "#bf3989", "#0969da", "#bc4c00", "#1b7c83"];
|
|
725
|
+
function colorFor(key) {
|
|
726
|
+
let hash = 0;
|
|
727
|
+
for (const ch of key) hash = hash * 31 + ch.charCodeAt(0) | 0;
|
|
728
|
+
return PALETTE[Math.abs(hash) % PALETTE.length];
|
|
729
|
+
}
|
|
730
|
+
function newId() {
|
|
731
|
+
const bytes = new Uint8Array(9);
|
|
732
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
733
|
+
return "s" + Array.from(bytes, (b) => (b % 36).toString(36)).join("");
|
|
734
|
+
}
|
|
735
|
+
function markSpec(kind) {
|
|
736
|
+
const tag = kind === "insert" ? "ins" : "del";
|
|
737
|
+
return {
|
|
738
|
+
attrs: { id: {}, author: { default: "" }, name: { default: "" }, time: { default: 0 } },
|
|
739
|
+
inclusive: false,
|
|
740
|
+
excludes: "",
|
|
741
|
+
parseDOM: [
|
|
742
|
+
{
|
|
743
|
+
tag: `${tag}[data-suggestion]`,
|
|
744
|
+
// Раньше правила зачёркивания (<del> без data-suggestion — обычное зачёркивание).
|
|
745
|
+
priority: 60,
|
|
746
|
+
getAttrs: (dom) => {
|
|
747
|
+
const el = dom;
|
|
748
|
+
const id = el.getAttribute("data-suggestion") ?? "";
|
|
749
|
+
if (!ID_RE2.test(id)) return false;
|
|
750
|
+
const author = el.getAttribute("data-author") ?? "";
|
|
751
|
+
return {
|
|
752
|
+
id,
|
|
753
|
+
author: USER_ID_RE.test(author) ? author : "",
|
|
754
|
+
name: (el.getAttribute("data-name") ?? "").slice(0, 80),
|
|
755
|
+
time: Number(el.getAttribute("data-time")) || 0
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
],
|
|
760
|
+
toDOM: (mark) => [
|
|
761
|
+
tag,
|
|
762
|
+
{
|
|
763
|
+
"data-suggestion": ID_RE2.test(mark.attrs.id) ? mark.attrs.id : null,
|
|
764
|
+
"data-author": USER_ID_RE.test(mark.attrs.author) ? mark.attrs.author : null,
|
|
765
|
+
"data-name": String(mark.attrs.name ?? "").slice(0, 80) || null,
|
|
766
|
+
"data-time": Number(mark.attrs.time) || null
|
|
767
|
+
},
|
|
768
|
+
0
|
|
769
|
+
]
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
var typesOf = (schema2) => ({
|
|
773
|
+
insert: schema2.marks.suggestion_insert,
|
|
774
|
+
delete: schema2.marks.suggestion_delete
|
|
775
|
+
});
|
|
776
|
+
function isTracked(tr) {
|
|
777
|
+
if (!tr.docChanged || tr.getMeta(OWN)) return false;
|
|
778
|
+
if (tr.getMeta("addToHistory") === false) return false;
|
|
779
|
+
if (tr.getMeta("history$")) return false;
|
|
780
|
+
const ySync = tr.getMeta("y-sync$");
|
|
781
|
+
if (ySync?.isChangeOrigin) return false;
|
|
782
|
+
return tr.steps.every((step) => step instanceof ReplaceStep);
|
|
783
|
+
}
|
|
784
|
+
function neighbourMark(doc, pos, type, authorId) {
|
|
785
|
+
const $pos = doc.resolve(pos);
|
|
786
|
+
for (const node of [$pos.nodeBefore, $pos.nodeAfter]) {
|
|
787
|
+
const mark = node?.marks.find((m) => m.type === type && m.attrs.author === authorId);
|
|
788
|
+
if (mark) return mark;
|
|
789
|
+
}
|
|
790
|
+
return null;
|
|
791
|
+
}
|
|
792
|
+
function withMark(fragment, mark, parent) {
|
|
793
|
+
const nodes = [];
|
|
794
|
+
fragment.forEach((node) => {
|
|
795
|
+
if (node.isInline) {
|
|
796
|
+
nodes.push(
|
|
797
|
+
parent && !parent.allowsMarkType(mark.type) ? node : node.mark(mark.addToSet(node.marks))
|
|
798
|
+
);
|
|
799
|
+
} else {
|
|
800
|
+
nodes.push(node.copy(withMark(node.content, mark, node.type)));
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
return Fragment.from(nodes);
|
|
804
|
+
}
|
|
805
|
+
function suggestTransaction(tr, state, author) {
|
|
806
|
+
if (!isTracked(tr)) return tr;
|
|
807
|
+
const types = typesOf(state.schema);
|
|
808
|
+
const out = state.tr;
|
|
809
|
+
const time = Date.now();
|
|
810
|
+
let toOut = (pos) => pos;
|
|
811
|
+
let forwardDeleteEnd = null;
|
|
812
|
+
let insertEnd = null;
|
|
813
|
+
tr.steps.forEach((rawStep) => {
|
|
814
|
+
const step = rawStep;
|
|
815
|
+
const outStart = out.steps.length;
|
|
816
|
+
const prev = toOut;
|
|
817
|
+
let from = prev(step.from);
|
|
818
|
+
let to = Math.max(from, prev(step.to));
|
|
819
|
+
if (to > from) {
|
|
820
|
+
const own = [];
|
|
821
|
+
const plain = [];
|
|
822
|
+
out.doc.nodesBetween(from, to, (node, pos) => {
|
|
823
|
+
if (!node.isInline) return true;
|
|
824
|
+
const start = Math.max(pos, from);
|
|
825
|
+
const end = Math.min(pos + node.nodeSize, to);
|
|
826
|
+
if (start >= end) return false;
|
|
827
|
+
const mine = node.marks.some(
|
|
828
|
+
(m) => m.type === types.insert && m.attrs.author === author.id
|
|
829
|
+
);
|
|
830
|
+
if (mine) own.push({ from: start, to: end });
|
|
831
|
+
else if (!types.delete.isInSet(node.marks)) plain.push({ from: start, to: end });
|
|
832
|
+
return false;
|
|
833
|
+
});
|
|
834
|
+
if (plain.length) {
|
|
835
|
+
const first = plain[0];
|
|
836
|
+
const mark = neighbourMark(out.doc, first.from, types.delete, author.id) ?? neighbourMark(out.doc, plain[plain.length - 1].to, types.delete, author.id) ?? types.delete.create({ id: newId(), author: author.id, name: author.name, time });
|
|
837
|
+
for (const range of plain) out.addMark(range.from, range.to, mark);
|
|
838
|
+
}
|
|
839
|
+
for (const range of own.reverse()) out.delete(range.from, range.to);
|
|
840
|
+
const map = out.mapping.slice(outStart);
|
|
841
|
+
from = map.map(from, 1);
|
|
842
|
+
to = map.map(to, -1);
|
|
843
|
+
const sel = state.selection;
|
|
844
|
+
if (tr.steps.length === 1 && step.slice.size === 0 && sel.empty && sel.from === step.from && tr.selection.head === step.from) {
|
|
845
|
+
forwardDeleteEnd = to;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (step.slice.size > 0) {
|
|
849
|
+
let at = to;
|
|
850
|
+
if (!step.slice.openStart) {
|
|
851
|
+
for (let next = out.doc.resolve(at).nodeAfter; next && types.delete.isInSet(next.marks); ) {
|
|
852
|
+
at += next.nodeSize;
|
|
853
|
+
next = out.doc.resolve(at).nodeAfter;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const mark = neighbourMark(out.doc, at, types.insert, author.id) ?? types.insert.create({ id: newId(), author: author.id, name: author.name, time });
|
|
857
|
+
const $at = out.doc.resolve(at);
|
|
858
|
+
const content = withMark(
|
|
859
|
+
step.slice.content,
|
|
860
|
+
mark,
|
|
861
|
+
step.slice.openStart ? null : $at.parent.type
|
|
862
|
+
);
|
|
863
|
+
out.replace(at, at, new Slice(content, step.slice.openStart, step.slice.openEnd));
|
|
864
|
+
if (tr.steps.length === 1) insertEnd = at + step.slice.size;
|
|
865
|
+
}
|
|
866
|
+
const inverse = step.getMap().invert();
|
|
867
|
+
const outMap = out.mapping.slice(outStart);
|
|
868
|
+
toOut = (pos) => outMap.map(prev(inverse.map(pos, -1)), 1);
|
|
869
|
+
});
|
|
870
|
+
if (forwardDeleteEnd !== null) {
|
|
871
|
+
out.setSelection(TextSelection.create(out.doc, forwardDeleteEnd));
|
|
872
|
+
} else if (insertEnd !== null && tr.selection.empty) {
|
|
873
|
+
out.setSelection(TextSelection.create(out.doc, insertEnd));
|
|
874
|
+
} else {
|
|
875
|
+
const anchor = toOut(tr.selection.anchor);
|
|
876
|
+
const head = toOut(tr.selection.head);
|
|
877
|
+
try {
|
|
878
|
+
out.setSelection(TextSelection.create(out.doc, anchor, head));
|
|
879
|
+
} catch {
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
for (const key of ["addToHistory", "uiEvent", "paste", "scrollIntoView"]) {
|
|
883
|
+
const value = tr.getMeta(key);
|
|
884
|
+
if (value !== void 0) out.setMeta(key, value);
|
|
885
|
+
}
|
|
886
|
+
if (tr.scrolledIntoView) out.scrollIntoView();
|
|
887
|
+
return out;
|
|
888
|
+
}
|
|
889
|
+
function listSuggestions(doc) {
|
|
890
|
+
const types = typesOf(doc.type.schema);
|
|
891
|
+
const result = [];
|
|
892
|
+
doc.descendants((node, pos) => {
|
|
893
|
+
if (!node.isInline) return true;
|
|
894
|
+
for (const mark of node.marks) {
|
|
895
|
+
const kind = mark.type === types.insert ? "insert" : mark.type === types.delete ? "delete" : null;
|
|
896
|
+
if (!kind) continue;
|
|
897
|
+
const last = result[result.length - 1];
|
|
898
|
+
const text = node.isText ? node.text : "";
|
|
899
|
+
if (last && last.id === mark.attrs.id && last.kind === kind && last.to === pos) {
|
|
900
|
+
last.to = pos + node.nodeSize;
|
|
901
|
+
last.text += text;
|
|
902
|
+
} else {
|
|
903
|
+
result.push({
|
|
904
|
+
id: mark.attrs.id,
|
|
905
|
+
kind,
|
|
906
|
+
author: { id: mark.attrs.author, name: mark.attrs.name },
|
|
907
|
+
time: Number(mark.attrs.time) || 0,
|
|
908
|
+
from: pos,
|
|
909
|
+
to: pos + node.nodeSize,
|
|
910
|
+
text
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return false;
|
|
915
|
+
});
|
|
916
|
+
return result;
|
|
917
|
+
}
|
|
918
|
+
function resolveSuggestions(state, action, ids) {
|
|
919
|
+
const types = typesOf(state.schema);
|
|
920
|
+
const tr = state.tr.setMeta(OWN, true);
|
|
921
|
+
const chosen = listSuggestions(state.doc).filter((s) => !ids || ids.includes(s.id));
|
|
922
|
+
for (const s of [...chosen].sort((a, b) => b.from - a.from)) {
|
|
923
|
+
const remove = s.kind === "insert" === (action === "reject");
|
|
924
|
+
if (remove) tr.delete(s.from, s.to);
|
|
925
|
+
else tr.removeMark(s.from, s.to, s.kind === "insert" ? types.insert : types.delete);
|
|
926
|
+
}
|
|
927
|
+
return tr;
|
|
928
|
+
}
|
|
929
|
+
function suggestionsResult(editor, action) {
|
|
930
|
+
return resolveSuggestions(editor.view.state, action).doc;
|
|
931
|
+
}
|
|
932
|
+
function suggestionAt(state) {
|
|
933
|
+
const { from } = state.selection;
|
|
934
|
+
return listSuggestions(state.doc).find(
|
|
935
|
+
(s) => from >= s.from && from <= s.to && (s.to > from || s.from < from)
|
|
936
|
+
) ?? null;
|
|
937
|
+
}
|
|
938
|
+
function isSuggesting(state) {
|
|
939
|
+
return suggestionsKey.getState(state)?.enabled ?? false;
|
|
940
|
+
}
|
|
941
|
+
function setSuggesting(editor, enabled) {
|
|
942
|
+
const { state, dispatch } = editor.view;
|
|
943
|
+
dispatch(state.tr.setMeta(suggestionsKey, { enabled }).setMeta(OWN, true));
|
|
944
|
+
editor.updateUI();
|
|
945
|
+
}
|
|
946
|
+
var suggestions_default = definePlugin({
|
|
947
|
+
name: "suggestions",
|
|
948
|
+
toolbar: "suggestions reviewsuggestions",
|
|
949
|
+
marks: {
|
|
950
|
+
suggestion_insert: markSpec("insert"),
|
|
951
|
+
suggestion_delete: markSpec("delete")
|
|
952
|
+
},
|
|
953
|
+
prosemirrorPlugins: (editor) => {
|
|
954
|
+
const options = editor.options.pluginOptions?.suggestions ?? {};
|
|
955
|
+
let cache = null;
|
|
956
|
+
return [
|
|
957
|
+
new Plugin2({
|
|
958
|
+
key: suggestionsKey,
|
|
959
|
+
state: {
|
|
960
|
+
init: () => ({ enabled: !!(options.enabled || options.force) }),
|
|
961
|
+
apply(tr, value) {
|
|
962
|
+
const meta = tr.getMeta(suggestionsKey);
|
|
963
|
+
if (!meta) return value;
|
|
964
|
+
return { enabled: options.force ? true : meta.enabled };
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
props: {
|
|
968
|
+
attributes: (state) => suggestionsKey.getState(state)?.enabled ? { class: "nova-suggesting" } : {},
|
|
969
|
+
decorations(state) {
|
|
970
|
+
if (cache?.doc === state.doc) return cache.set;
|
|
971
|
+
const labels = pickLabels(editor, LABELS4);
|
|
972
|
+
const time = new Intl.DateTimeFormat(editor.options.language ?? "en", {
|
|
973
|
+
dateStyle: "medium",
|
|
974
|
+
timeStyle: "short"
|
|
975
|
+
});
|
|
976
|
+
const set = DecorationSet2.create(
|
|
977
|
+
state.doc,
|
|
978
|
+
listSuggestions(state.doc).map(
|
|
979
|
+
(s) => Decoration2.inline(s.from, s.to, {
|
|
980
|
+
title: (s.kind === "insert" ? labels.inserted : labels.deleted).replace(
|
|
981
|
+
"{name}",
|
|
982
|
+
s.author.name || labels.guest
|
|
983
|
+
) + (s.time ? ` \xB7 ${time.format(s.time)}` : ""),
|
|
984
|
+
class: s.kind === "insert" ? "nova-sugg-insert" : "nova-sugg-delete",
|
|
985
|
+
style: `--nova-suggestion: ${colorFor(s.author.id || s.author.name)}`
|
|
986
|
+
})
|
|
987
|
+
)
|
|
988
|
+
);
|
|
989
|
+
cache = { doc: state.doc, set };
|
|
990
|
+
return set;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}),
|
|
994
|
+
keymap2({
|
|
995
|
+
// Ctrl/Cmd+Alt+Shift+E — переключить режим правок.
|
|
996
|
+
"Mod-Alt-Shift-e": () => {
|
|
997
|
+
if (options.force) return false;
|
|
998
|
+
setSuggesting(editor, !isSuggesting(editor.view.state));
|
|
999
|
+
return true;
|
|
1000
|
+
}
|
|
1001
|
+
})
|
|
1002
|
+
];
|
|
1003
|
+
},
|
|
1004
|
+
transformTransaction(tr, state, editor) {
|
|
1005
|
+
if (!isSuggesting(state)) return tr;
|
|
1006
|
+
const options = editor.options.pluginOptions?.suggestions ?? {};
|
|
1007
|
+
const labels = pickLabels(editor, LABELS4);
|
|
1008
|
+
const author = {
|
|
1009
|
+
id: USER_ID_RE.test(options.author?.id ?? "") ? options.author.id : "guest",
|
|
1010
|
+
name: String(options.author?.name || labels.guest).slice(0, 80)
|
|
1011
|
+
};
|
|
1012
|
+
return suggestTransaction(tr, state, author);
|
|
1013
|
+
},
|
|
1014
|
+
setup(editor) {
|
|
1015
|
+
const options = editor.options.pluginOptions?.suggestions ?? {};
|
|
1016
|
+
const labels = pickLabels(editor, LABELS4);
|
|
1017
|
+
const canReview = options.canReview !== false;
|
|
1018
|
+
const dispatch = (tr) => editor.view.dispatch(tr);
|
|
1019
|
+
const current = () => suggestionAt(editor.view.state);
|
|
1020
|
+
const resolveCurrent = (action) => {
|
|
1021
|
+
const s = current();
|
|
1022
|
+
if (s) dispatch(resolveSuggestions(editor.view.state, action, [s.id]));
|
|
1023
|
+
editor.focus();
|
|
1024
|
+
};
|
|
1025
|
+
const go = (direction) => {
|
|
1026
|
+
const { state } = editor.view;
|
|
1027
|
+
const list = listSuggestions(state.doc);
|
|
1028
|
+
const pos = state.selection.from;
|
|
1029
|
+
const target = direction === 1 ? list.find((s) => s.from > pos) ?? list[0] : [...list].reverse().find((s) => s.to < pos) ?? list[list.length - 1];
|
|
1030
|
+
if (!target) {
|
|
1031
|
+
editor.ui.notify(labels.none);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
dispatch(
|
|
1035
|
+
state.tr.setSelection(TextSelection.create(state.doc, target.from)).scrollIntoView()
|
|
1036
|
+
);
|
|
1037
|
+
editor.focus();
|
|
1038
|
+
};
|
|
1039
|
+
const hasAny = () => listSuggestions(editor.view.state.doc).length > 0;
|
|
1040
|
+
editor.ui.registry.addToggleButton("suggestions", {
|
|
1041
|
+
icon: ICON_TOGGLE,
|
|
1042
|
+
tooltip: labels.toggle,
|
|
1043
|
+
shortcut: "Mod-Alt-Shift-e",
|
|
1044
|
+
isActive: (e) => isSuggesting(e.view.state),
|
|
1045
|
+
isEnabled: () => !options.force,
|
|
1046
|
+
onAction: (e) => setSuggesting(e, !isSuggesting(e.view.state))
|
|
1047
|
+
});
|
|
1048
|
+
editor.ui.registry.addMenuButton("reviewsuggestions", {
|
|
1049
|
+
icon: ICON_REVIEW,
|
|
1050
|
+
tooltip: labels.review,
|
|
1051
|
+
isEnabled: hasAny,
|
|
1052
|
+
items: () => [
|
|
1053
|
+
{ id: "next", label: labels.next, onSelect: () => go(1) },
|
|
1054
|
+
{ id: "previous", label: labels.previous, onSelect: () => go(-1) },
|
|
1055
|
+
...canReview ? [
|
|
1056
|
+
{ type: "separator" },
|
|
1057
|
+
{
|
|
1058
|
+
id: "accept-all",
|
|
1059
|
+
label: labels.acceptAll,
|
|
1060
|
+
onSelect: () => dispatch(resolveSuggestions(editor.view.state, "accept"))
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
id: "reject-all",
|
|
1064
|
+
label: labels.rejectAll,
|
|
1065
|
+
onSelect: () => dispatch(resolveSuggestions(editor.view.state, "reject"))
|
|
1066
|
+
}
|
|
1067
|
+
] : []
|
|
1068
|
+
]
|
|
1069
|
+
});
|
|
1070
|
+
if (canReview) {
|
|
1071
|
+
editor.ui.registry.addButton("acceptsuggestion", {
|
|
1072
|
+
icon: ICON_ACCEPT,
|
|
1073
|
+
text: labels.accept,
|
|
1074
|
+
tooltip: labels.accept,
|
|
1075
|
+
onAction: () => resolveCurrent("accept")
|
|
1076
|
+
});
|
|
1077
|
+
editor.ui.registry.addButton("rejectsuggestion", {
|
|
1078
|
+
icon: ICON_REJECT,
|
|
1079
|
+
text: labels.reject,
|
|
1080
|
+
tooltip: labels.reject,
|
|
1081
|
+
onAction: () => resolveCurrent("reject")
|
|
1082
|
+
});
|
|
1083
|
+
editor.ui.registry.addContextToolbar("suggestion", {
|
|
1084
|
+
label: labels.toolbar,
|
|
1085
|
+
predicate: (e) => suggestionAt(e.view.state) !== null,
|
|
1086
|
+
items: "acceptsuggestion rejectsuggestion",
|
|
1087
|
+
position: "selection",
|
|
1088
|
+
placement: "bottom-start",
|
|
1089
|
+
priority: 20
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
editor.ui.registry.addMenuItem("suggestions", {
|
|
1093
|
+
text: labels.toggle,
|
|
1094
|
+
icon: ICON_TOGGLE,
|
|
1095
|
+
isActive: (e) => isSuggesting(e.view.state),
|
|
1096
|
+
isEnabled: () => !options.force,
|
|
1097
|
+
onAction: (e) => setSuggesting(e, !isSuggesting(e.view.state))
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
|
|
669
1102
|
// src/plugins/media.ts
|
|
670
|
-
import { NodeSelection as NodeSelection2, Plugin as
|
|
1103
|
+
import { NodeSelection as NodeSelection2, Plugin as Plugin3 } from "prosemirror-state";
|
|
671
1104
|
var YOUTUBE = /^https?:\/\/(?:www\.|m\.)?(?:youtube(?:-nocookie)?\.com\/(?:watch\?(?:[^#]*&)?v=|embed\/|shorts\/|live\/)|youtu\.be\/)([\w-]{11})(?:[?&#]|$)/i;
|
|
672
1105
|
var VIMEO = /^https?:\/\/(?:www\.|player\.)?vimeo\.com\/(?:video\/)?(\d{1,12})(?:[/?#]|$)/i;
|
|
673
1106
|
var VIDEO_FILE = /^https:\/\/[^\s"'<>]+\.(?:mp4|webm|ogv|ogg)(?:\?[^\s"'<>#]*)?$/i;
|
|
@@ -682,7 +1115,7 @@ function parseMediaUrl(url) {
|
|
|
682
1115
|
return null;
|
|
683
1116
|
}
|
|
684
1117
|
var ICON2 = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="5" width="20" height="14" rx="2"/><path d="m10 9 5 3-5 3z"/></svg>';
|
|
685
|
-
var
|
|
1118
|
+
var LABELS5 = {
|
|
686
1119
|
en: {
|
|
687
1120
|
title: "Video",
|
|
688
1121
|
url: "Video URL",
|
|
@@ -783,7 +1216,7 @@ var media_default = definePlugin({
|
|
|
783
1216
|
}
|
|
784
1217
|
},
|
|
785
1218
|
prosemirrorPlugins: () => [
|
|
786
|
-
new
|
|
1219
|
+
new Plugin3({
|
|
787
1220
|
props: {
|
|
788
1221
|
nodeViews: {
|
|
789
1222
|
// В редакторе плеер закрыт прозрачным слоем: клик выделяет блок, а не запускает видео.
|
|
@@ -802,7 +1235,7 @@ var media_default = definePlugin({
|
|
|
802
1235
|
})
|
|
803
1236
|
],
|
|
804
1237
|
setup(editor) {
|
|
805
|
-
const labels = pickLabels(editor,
|
|
1238
|
+
const labels = pickLabels(editor, LABELS5);
|
|
806
1239
|
const selected = () => {
|
|
807
1240
|
const { selection } = editor.view.state;
|
|
808
1241
|
return selection instanceof NodeSelection2 && selection.node.type.name === "media" ? selection : null;
|
|
@@ -853,7 +1286,7 @@ var media_default = definePlugin({
|
|
|
853
1286
|
|
|
854
1287
|
// src/plugins/pagebreak.ts
|
|
855
1288
|
var ICON3 = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3v5h12V3M6 21v-5h12v5"/><path d="M3 12h2M9 12h2M15 12h2M21 12h-0"/></svg>';
|
|
856
|
-
var
|
|
1289
|
+
var LABELS6 = { en: { title: "Page break" }, ru: { title: "\u0420\u0430\u0437\u0440\u044B\u0432 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B" } };
|
|
857
1290
|
var pagebreak_default = definePlugin({
|
|
858
1291
|
name: "pagebreak",
|
|
859
1292
|
toolbar: "pagebreak",
|
|
@@ -878,7 +1311,7 @@ var pagebreak_default = definePlugin({
|
|
|
878
1311
|
}
|
|
879
1312
|
},
|
|
880
1313
|
setup(editor) {
|
|
881
|
-
const { title } = pickLabels(editor,
|
|
1314
|
+
const { title } = pickLabels(editor, LABELS6);
|
|
882
1315
|
const insert = () => {
|
|
883
1316
|
const { state, dispatch } = editor.view;
|
|
884
1317
|
const type = editor.schema.nodes.pagebreak;
|
|
@@ -896,28 +1329,30 @@ var pagebreak_default = definePlugin({
|
|
|
896
1329
|
});
|
|
897
1330
|
|
|
898
1331
|
// src/plugins/index.ts
|
|
899
|
-
registerPlugin("insertdatetime", () => import("./insertdatetime-
|
|
900
|
-
registerPlugin("quickbars", () => import("./quickbars-
|
|
901
|
-
registerPlugin("charmap", () => import("./charmap-
|
|
902
|
-
registerPlugin("emoticons", () => import("./emoticons-
|
|
903
|
-
registerPlugin("nonbreaking", () => import("./nonbreaking-
|
|
904
|
-
registerPlugin("autolink", () => import("./autolink-
|
|
905
|
-
registerPlugin("autosave", () => import("./autosave-
|
|
906
|
-
registerPlugin("autoresize", () => import("./autoresize-
|
|
907
|
-
registerPlugin("visualblocks", () => import("./visualblocks-
|
|
1332
|
+
registerPlugin("insertdatetime", () => import("./insertdatetime-2RZ3UUQE.js"));
|
|
1333
|
+
registerPlugin("quickbars", () => import("./quickbars-TIRY3RH4.js"));
|
|
1334
|
+
registerPlugin("charmap", () => import("./charmap-LWA7TL3K.js"));
|
|
1335
|
+
registerPlugin("emoticons", () => import("./emoticons-WQ3K4J6G.js"));
|
|
1336
|
+
registerPlugin("nonbreaking", () => import("./nonbreaking-L6GNDHVO.js"));
|
|
1337
|
+
registerPlugin("autolink", () => import("./autolink-IDJWAL2V.js"));
|
|
1338
|
+
registerPlugin("autosave", () => import("./autosave-WODRZ7L6.js"));
|
|
1339
|
+
registerPlugin("autoresize", () => import("./autoresize-4ZEPQCHP.js"));
|
|
1340
|
+
registerPlugin("visualblocks", () => import("./visualblocks-V4CQ4XMF.js"));
|
|
908
1341
|
registerPlugin("anchor", anchor_default);
|
|
909
1342
|
registerPlugin("pagebreak", pagebreak_default);
|
|
910
1343
|
registerPlugin("media", media_default);
|
|
911
1344
|
registerPlugin("comments", comments_default);
|
|
912
1345
|
registerPlugin("mentions", mentions_default);
|
|
913
|
-
registerPlugin("
|
|
914
|
-
registerPlugin("
|
|
915
|
-
registerPlugin("
|
|
1346
|
+
registerPlugin("suggestions", suggestions_default);
|
|
1347
|
+
registerPlugin("directionality", () => import("./directionality-N62ZB7CF.js"));
|
|
1348
|
+
registerPlugin("advlist", () => import("./advlist-FH3K3AAQ.js"));
|
|
1349
|
+
registerPlugin("revisionhistory", () => import("./revisionhistory-GDTOULKS.js"));
|
|
916
1350
|
export {
|
|
917
1351
|
ContentRules,
|
|
918
1352
|
DEFAULT_MENUBAR,
|
|
919
1353
|
DEFAULT_MENUS,
|
|
920
1354
|
Editor,
|
|
1355
|
+
HTMLSerializer,
|
|
921
1356
|
KNOWN_STYLES,
|
|
922
1357
|
KNOWN_TAGS,
|
|
923
1358
|
MENTION_ID_RE,
|
|
@@ -953,6 +1388,7 @@ export {
|
|
|
953
1388
|
hasHeaderColumn,
|
|
954
1389
|
hasHeaderRow,
|
|
955
1390
|
htmlToPlainText,
|
|
1391
|
+
icons,
|
|
956
1392
|
imageSize,
|
|
957
1393
|
insertImage,
|
|
958
1394
|
insertTable,
|
|
@@ -964,6 +1400,8 @@ export {
|
|
|
964
1400
|
isPluginRegistered,
|
|
965
1401
|
isSafeImageUrl,
|
|
966
1402
|
isSafeLinkUrl,
|
|
1403
|
+
isSuggesting,
|
|
1404
|
+
listSuggestions,
|
|
967
1405
|
marksOf,
|
|
968
1406
|
newCommentId,
|
|
969
1407
|
nodesOf,
|
|
@@ -983,6 +1421,7 @@ export {
|
|
|
983
1421
|
removeLink,
|
|
984
1422
|
replaceAll,
|
|
985
1423
|
replaceCurrent,
|
|
1424
|
+
resolveSuggestions,
|
|
986
1425
|
ru,
|
|
987
1426
|
sanitizeThread,
|
|
988
1427
|
schema,
|
|
@@ -993,6 +1432,8 @@ export {
|
|
|
993
1432
|
setLink,
|
|
994
1433
|
setSearch,
|
|
995
1434
|
setStyle,
|
|
1435
|
+
setSuggesting,
|
|
1436
|
+
suggestionsResult,
|
|
996
1437
|
tableCommands,
|
|
997
1438
|
toggleFullscreen,
|
|
998
1439
|
uploadImages
|