@portone/docx-editor 0.6.5 → 0.6.7
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/CHANGELOG.md +35 -0
- package/CONTRIBUTING.md +4 -4
- package/dist/core.d.ts +7 -0
- package/dist/core.js +2 -0
- package/dist/docx/commentOnlyChange.d.ts +4 -4
- package/dist/docx/comments/constants.d.ts +7 -0
- package/dist/docx/comments/constants.js +13 -1
- package/dist/docx/comments/dates.d.ts +22 -0
- package/dist/docx/comments/dates.js +102 -0
- package/dist/docx/comments/durable.d.ts +22 -0
- package/dist/docx/comments/durable.js +138 -0
- package/dist/docx/comments/grammar.d.ts +10 -1
- package/dist/docx/comments/grammar.js +49 -2
- package/dist/docx/comments/model.d.ts +10 -2
- package/dist/docx/comments/model.js +38 -8
- package/dist/docx/comments/parts.d.ts +53 -7
- package/dist/docx/comments/parts.js +163 -20
- package/dist/docx/comments/people.d.ts +1 -1
- package/dist/docx/comments/people.js +5 -15
- package/dist/docx/comments/reading.d.ts +26 -0
- package/dist/docx/comments/reading.js +109 -49
- package/dist/docx/comments/writing.d.ts +2 -7
- package/dist/docx/comments/writing.js +30 -43
- package/dist/docx/compareDocx.d.ts +154 -0
- package/dist/docx/compareDocx.js +218 -0
- package/dist/docx/fidelity.js +2 -4
- package/dist/docx/importParagraph.js +6 -9
- package/dist/docx/invariants.js +19 -6
- package/dist/docx/packageParts.d.ts +2 -0
- package/dist/docx/packageParts.js +5 -1
- package/dist/docx/partPlan.d.ts +12 -0
- package/dist/docx/partPlan.js +19 -1
- package/dist/docx/protectionPolicy.d.ts +33 -5
- package/dist/docx/protectionPolicy.js +93 -47
- package/dist/docx/runProps.d.ts +3 -0
- package/dist/docx/runProps.js +9 -0
- package/dist/docx/sequenceDiff.d.ts +56 -0
- package/dist/docx/sequenceDiff.js +252 -0
- package/dist/docx/serializeParagraph.js +29 -3
- package/dist/docx/storyProjection.d.ts +2 -0
- package/dist/docx/storyProjection.js +10 -9
- package/dist/docx/textDiff.d.ts +24 -0
- package/dist/docx/textDiff.js +38 -0
- package/dist/editor/blockControlEdits.js +4 -4
- package/dist/editor/commands/comments/editing.js +59 -22
- package/dist/editor/commands/comments/model.d.ts +3 -1
- package/dist/editor/createEditor.js +6 -9
- package/dist/editor/editorDocument.d.ts +4 -0
- package/dist/editor/editorDocument.js +10 -0
- package/dist/editor/formatSource.d.ts +17 -0
- package/dist/editor/formatSource.js +74 -0
- package/dist/editor/plugins/caretFormat.d.ts +10 -0
- package/dist/editor/plugins/caretFormat.js +39 -0
- package/dist/editor/plugins/commentDecorations.js +6 -2
- package/dist/editor/plugins/controlContents.d.ts +5 -0
- package/dist/editor/plugins/controlContents.js +120 -13
- package/dist/editor/plugins/emptyRunPointer.d.ts +9 -0
- package/dist/editor/plugins/emptyRunPointer.js +22 -0
- package/dist/editor/plugins/inlinePlugins.d.ts +6 -0
- package/dist/editor/plugins/inlinePlugins.js +19 -0
- package/dist/editor/stories/storyState.js +4 -8
- package/dist/editor/views/runMarkView.d.ts +5 -2
- package/dist/editor/views/runMarkView.js +12 -1
- package/dist/ooxml/errors.d.ts +1 -1
- package/dist/ooxml/names.d.ts +2 -0
- package/dist/ooxml/names.js +2 -0
- package/dist/ooxml/partSplice.d.ts +13 -3
- package/dist/ooxml/partSplice.js +45 -18
- package/dist/schema/attrRoles.js +4 -1
- package/dist/schema/clipboard.js +3 -0
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +52 -4
- package/dist/schema/emptyRuns.d.ts +3 -0
- package/dist/schema/emptyRuns.js +7 -0
- package/dist/schema/locks.d.ts +11 -0
- package/dist/schema/locks.js +2 -0
- package/dist/schema/protection.js +2 -1
- package/dist/styles/classNames.d.ts +4 -0
- package/dist/styles/classNames.js +4 -0
- package/dist/styles/inlineStyle.d.ts +2 -0
- package/dist/styles/inlineStyle.js +10 -4
- package/dist/styles.css +15 -0
- package/dist/ui/CommentsPanel.js +8 -13
- package/dist/ui/comments/commentDate.d.ts +7 -0
- package/dist/ui/comments/commentDate.js +17 -0
- package/package.json +7 -7
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The characters two texts share and the ones each has alone, as the shortest edit between them
|
|
3
|
+
* (`./sequenceDiff`).
|
|
4
|
+
*
|
|
5
|
+
* The texts are compared a grapheme cluster at a time, so an edit never splits a character a
|
|
6
|
+
* reader sees as one: a surrogate pair, a flag, an emoji with its skin tone, a letter with its
|
|
7
|
+
* combining accent.
|
|
8
|
+
*/
|
|
9
|
+
/** One stretch of the edit: `kept` and `removed` spell the original, `kept` and `added` the revision */
|
|
10
|
+
export type TextEdit = {
|
|
11
|
+
kind: "kept";
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "added";
|
|
15
|
+
text: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "removed";
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The shortest edit from one text to the other. Between two kept stretches the removed text comes
|
|
22
|
+
* first and the added text after it, each as one stretch, and no stretch is empty.
|
|
23
|
+
*/
|
|
24
|
+
export declare function diffText(original: string, revised: string): TextEdit[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/docx/textDiff.ts
|
|
2
|
+
import { commonSubsequence } from "./sequenceDiff.js";
|
|
3
|
+
var graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
4
|
+
function charactersOf(text) {
|
|
5
|
+
return Array.from(graphemes.segment(text), ({ segment }) => segment);
|
|
6
|
+
}
|
|
7
|
+
function diffText(original, revised) {
|
|
8
|
+
const was = charactersOf(original);
|
|
9
|
+
const now = charactersOf(revised);
|
|
10
|
+
const edits = [];
|
|
11
|
+
const push = (kind, text) => {
|
|
12
|
+
if (text === "") return;
|
|
13
|
+
const last = edits.at(-1);
|
|
14
|
+
if (last?.kind === kind) {
|
|
15
|
+
edits[edits.length - 1] = { kind, text: last.text + text };
|
|
16
|
+
} else {
|
|
17
|
+
edits.push({ kind, text });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
let from = 0;
|
|
21
|
+
let to = 0;
|
|
22
|
+
const matches = commonSubsequence(
|
|
23
|
+
was.length,
|
|
24
|
+
now.length,
|
|
25
|
+
(i, j) => was[i] === now[j]
|
|
26
|
+
);
|
|
27
|
+
for (const [i, j] of [...matches, [was.length, now.length]]) {
|
|
28
|
+
push("removed", was.slice(from, i).join(""));
|
|
29
|
+
push("added", now.slice(to, j).join(""));
|
|
30
|
+
if (i < was.length) push("kept", was[i]);
|
|
31
|
+
from = i + 1;
|
|
32
|
+
to = j + 1;
|
|
33
|
+
}
|
|
34
|
+
return edits;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
diffText
|
|
38
|
+
};
|
|
@@ -33,7 +33,7 @@ function caretAtEdge(selection, dir) {
|
|
|
33
33
|
const at = dir < 0 ? 0 : $cursor.parent.content.size;
|
|
34
34
|
return $cursor.parentOffset === at ? $cursor : null;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function emptyControlsBeside(selection, dir) {
|
|
37
37
|
const $cursor = caretAtEdge(selection, dir);
|
|
38
38
|
if (!$cursor) return null;
|
|
39
39
|
const depth = $cursor.depth;
|
|
@@ -52,7 +52,7 @@ function emptyRunBeside(selection, dir) {
|
|
|
52
52
|
}
|
|
53
53
|
function skipEmptyControls(dir) {
|
|
54
54
|
const move = guardedCommand((state) => {
|
|
55
|
-
const beyond =
|
|
55
|
+
const beyond = emptyControlsBeside(state.selection, dir)?.beyond;
|
|
56
56
|
if (beyond === null || beyond === void 0) return null;
|
|
57
57
|
const $cursor = state.selection instanceof TextSelection ? state.selection.$cursor : null;
|
|
58
58
|
if ($cursor && isEmptyParagraph($cursor.parent)) {
|
|
@@ -65,9 +65,9 @@ function skipEmptyControls(dir) {
|
|
|
65
65
|
return state.tr.setSelection(Selection.near(state.doc.resolve(beyond), dir)).scrollIntoView();
|
|
66
66
|
});
|
|
67
67
|
return (state, dispatch, view) => (
|
|
68
|
-
// With nothing beyond the
|
|
68
|
+
// With nothing beyond the row there is nowhere to pass to, and the key still may not take the
|
|
69
69
|
// control away, so it is reported handled and the document is left as it stood.
|
|
70
|
-
move(state, dispatch, view) ||
|
|
70
|
+
move(state, dispatch, view) || emptyControlsBeside(state.selection, dir) !== null
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
var skipEmptyBlockControlBefore = skipEmptyControls(-1);
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
TextSelection
|
|
4
4
|
} from "prosemirror-state";
|
|
5
|
-
import {
|
|
5
|
+
import { seededHexId } from "../../../docx/comments.js";
|
|
6
|
+
import { writtenCommentDates } from "../../../docx/comments/dates.js";
|
|
7
|
+
import { HIGHEST_DURABLE_ID } from "../../../docx/comments/grammar.js";
|
|
8
|
+
import { durableIdKey } from "../../../docx/comments/reading.js";
|
|
6
9
|
import {
|
|
7
10
|
sameStory,
|
|
8
11
|
setStory,
|
|
@@ -14,8 +17,10 @@ import {
|
|
|
14
17
|
} from "../../../docx/story.js";
|
|
15
18
|
import { docxSchema } from "../../../schema/index.js";
|
|
16
19
|
import { guardedCommand } from "../../../schema/guards.js";
|
|
20
|
+
import { isCommentNode } from "../../../schema/protection.js";
|
|
17
21
|
import { isWrapperType } from "../../../schema/wrappers.js";
|
|
18
22
|
import {
|
|
23
|
+
reservedCommentDurableIds,
|
|
19
24
|
reservedCommentIds,
|
|
20
25
|
reservedCommentParaIds
|
|
21
26
|
} from "../../editorDocument.js";
|
|
@@ -52,7 +57,7 @@ function nextCommentId(state) {
|
|
|
52
57
|
reserve(id);
|
|
53
58
|
}
|
|
54
59
|
state.doc.descendants((node) => {
|
|
55
|
-
if (node
|
|
60
|
+
if (isCommentNode(node)) {
|
|
56
61
|
const id = stringAttr(node.attrs.id);
|
|
57
62
|
if (id !== null) reserve(id);
|
|
58
63
|
}
|
|
@@ -70,25 +75,48 @@ function nextCommentId(state) {
|
|
|
70
75
|
}
|
|
71
76
|
return (max + 1n).toString();
|
|
72
77
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
var hexId = (value) => value.toString(16).toUpperCase().padStart(8, "0");
|
|
79
|
+
function nextHexId(taken, seed, highest) {
|
|
80
|
+
const hashed = Number.parseInt(seededHexId(seed), 16);
|
|
81
|
+
let candidate = hashed > highest ? 1 : hashed;
|
|
82
|
+
while (taken.has(hexId(candidate))) {
|
|
83
|
+
candidate = candidate === highest ? 1 : candidate + 1;
|
|
84
|
+
}
|
|
85
|
+
return hexId(candidate);
|
|
86
|
+
}
|
|
87
|
+
function idsInDocument(state, key) {
|
|
88
|
+
const ids = [];
|
|
89
|
+
const take = (value) => {
|
|
90
|
+
const id = stringAttr(value);
|
|
91
|
+
if (id !== null) ids.push(id);
|
|
92
|
+
};
|
|
77
93
|
state.doc.descendants((node) => {
|
|
78
94
|
if (node.type.name !== "commentReference") return true;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
for (const reply of repliesAttr(node.attrs.replies)) {
|
|
82
|
-
taken.add(reply.paraId.toUpperCase());
|
|
83
|
-
}
|
|
95
|
+
take(node.attrs[key]);
|
|
96
|
+
for (const reply of repliesAttr(node.attrs.replies)) take(reply[key]);
|
|
84
97
|
return true;
|
|
85
98
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
return ids;
|
|
100
|
+
}
|
|
101
|
+
function nextCommentParaId(state, seed, additional = []) {
|
|
102
|
+
const taken = new Set(
|
|
103
|
+
[
|
|
104
|
+
...reservedCommentParaIds(state),
|
|
105
|
+
...idsInDocument(state, "paraId"),
|
|
106
|
+
...additional
|
|
107
|
+
].map((id) => id.toUpperCase())
|
|
108
|
+
);
|
|
109
|
+
return nextHexId(taken, seed, 2147483647);
|
|
110
|
+
}
|
|
111
|
+
function nextCommentDurableId(state, seed, dateUtc) {
|
|
112
|
+
if (dateUtc === null) return null;
|
|
113
|
+
const taken = new Set(
|
|
114
|
+
[
|
|
115
|
+
...reservedCommentDurableIds(state),
|
|
116
|
+
...idsInDocument(state, "durableId")
|
|
117
|
+
].map(durableIdKey)
|
|
118
|
+
);
|
|
119
|
+
return nextHexId(taken, `${seed}-${dateUtc}`, HIGHEST_DURABLE_ID);
|
|
92
120
|
}
|
|
93
121
|
function wrapperMarksAt(state, pos, side) {
|
|
94
122
|
const resolved = state.doc.resolve(pos);
|
|
@@ -101,7 +129,7 @@ function addCommentTransaction(state, comment, at) {
|
|
|
101
129
|
const range = commentedRange(state, at);
|
|
102
130
|
if (range === null || comment.text.trim().length === 0) return null;
|
|
103
131
|
const id = nextCommentId(state);
|
|
104
|
-
const
|
|
132
|
+
const { date, dateUtc } = writtenCommentDates(comment.date);
|
|
105
133
|
const paraId = nextCommentParaId(state, `comment-${id}-${date}`);
|
|
106
134
|
const { from, to } = range;
|
|
107
135
|
const startMarks = wrapperMarksAt(state, from, "after");
|
|
@@ -123,7 +151,9 @@ function addCommentTransaction(state, comment, at) {
|
|
|
123
151
|
resolved: false,
|
|
124
152
|
extensionXml: null,
|
|
125
153
|
threadImported: true,
|
|
126
|
-
replies: []
|
|
154
|
+
replies: [],
|
|
155
|
+
durableId: nextCommentDurableId(state, `durable-${id}`, dateUtc),
|
|
156
|
+
dateUtc
|
|
127
157
|
},
|
|
128
158
|
null,
|
|
129
159
|
endMarks
|
|
@@ -222,7 +252,12 @@ function addCommentReply(id, reply) {
|
|
|
222
252
|
return (state, dispatch) => {
|
|
223
253
|
if (reply.text.trim().length === 0) return false;
|
|
224
254
|
const replyId = nextCommentId(state);
|
|
225
|
-
const
|
|
255
|
+
const { date, dateUtc } = writtenCommentDates(reply.date);
|
|
256
|
+
const durableId = nextCommentDurableId(
|
|
257
|
+
state,
|
|
258
|
+
`durable-${replyId}`,
|
|
259
|
+
dateUtc
|
|
260
|
+
);
|
|
226
261
|
return updateReference(
|
|
227
262
|
id,
|
|
228
263
|
(node) => {
|
|
@@ -246,7 +281,9 @@ function addCommentReply(id, reply) {
|
|
|
246
281
|
date,
|
|
247
282
|
paraId,
|
|
248
283
|
parentParaId,
|
|
249
|
-
extensionXml: null
|
|
284
|
+
extensionXml: null,
|
|
285
|
+
durableId,
|
|
286
|
+
dateUtc
|
|
250
287
|
}
|
|
251
288
|
]
|
|
252
289
|
};
|
|
@@ -320,7 +357,7 @@ function removeComment(id) {
|
|
|
320
357
|
const positions = [];
|
|
321
358
|
const bodies = /* @__PURE__ */ new Set([id]);
|
|
322
359
|
state.doc.descendants((node, pos) => {
|
|
323
|
-
if ((node
|
|
360
|
+
if (isCommentNode(node) && stringAttr(node.attrs.id) === id) {
|
|
324
361
|
positions.push({ pos, size: node.nodeSize });
|
|
325
362
|
}
|
|
326
363
|
if (node.type.name === "commentReference" && stringAttr(node.attrs.id) === id) {
|
|
@@ -24,7 +24,7 @@ export interface NewComment {
|
|
|
24
24
|
/** The identity behind `author`. A comment written without one belongs to nobody in particular */
|
|
25
25
|
authorId?: string;
|
|
26
26
|
initials?: string;
|
|
27
|
-
/** ISO 8601
|
|
27
|
+
/** ISO 8601 instant, kept to the second. The current time is used when omitted. */
|
|
28
28
|
date?: string;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -36,6 +36,7 @@ export interface DocumentComment {
|
|
|
36
36
|
readonly author: string | null;
|
|
37
37
|
readonly authorId: string | null;
|
|
38
38
|
readonly initials: string | null;
|
|
39
|
+
/** ISO 8601 instant in UTC. A value that is not a readable date is returned as written. */
|
|
39
40
|
readonly date: string | null;
|
|
40
41
|
/** What it says, as plain text. The formatting behind it is `setCommentBody`'s to write */
|
|
41
42
|
readonly text: string;
|
|
@@ -57,6 +58,7 @@ export interface DocumentCommentReply {
|
|
|
57
58
|
readonly author: string | null;
|
|
58
59
|
readonly authorId: string | null;
|
|
59
60
|
readonly initials: string | null;
|
|
61
|
+
/** Read the way `DocumentComment.date` is */
|
|
60
62
|
readonly date: string | null;
|
|
61
63
|
readonly text: string;
|
|
62
64
|
}
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from "./editorDocument.js";
|
|
26
26
|
import { editRefusal } from "./editRefusal.js";
|
|
27
27
|
import { imageFiles } from "./imageFiles.js";
|
|
28
|
+
import { caretFormat } from "./plugins/caretFormat.js";
|
|
28
29
|
import { columnResize } from "./plugins/columnResize.js";
|
|
29
30
|
import { commentComposer } from "./plugins/commentComposer.js";
|
|
30
31
|
import { commentDecorations } from "./plugins/commentDecorations.js";
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
} from "./plugins/displayDerivation.js";
|
|
39
40
|
import { documentProtection } from "./plugins/documentProtection.js";
|
|
40
41
|
import { imagePaste } from "./plugins/imagePaste.js";
|
|
42
|
+
import { inlinePlugins } from "./plugins/inlinePlugins.js";
|
|
41
43
|
import { docxKeymap, historyKeys } from "./plugins/keymap.js";
|
|
42
44
|
import { linkPanel } from "./plugins/linkPanel.js";
|
|
43
45
|
import { listInputRules } from "./plugins/listInputRules.js";
|
|
@@ -47,11 +49,7 @@ import { noteNavigation } from "./plugins/noteNavigation.js";
|
|
|
47
49
|
import { noteNumbering } from "./plugins/noteNumbering.js";
|
|
48
50
|
import { numberingMarkers } from "./plugins/numberingDecorations.js";
|
|
49
51
|
import { rowResize } from "./plugins/rowResize.js";
|
|
50
|
-
import { tabCaret } from "./plugins/tabCaret.js";
|
|
51
|
-
import { tabDecorations } from "./plugins/tabDecorations.js";
|
|
52
|
-
import { tabLayout } from "./plugins/tabLayout.js";
|
|
53
52
|
import { tableContextMenu } from "./plugins/tableContextMenu.js";
|
|
54
|
-
import { tabPointer } from "./plugins/tabPointer.js";
|
|
55
53
|
import { textContextMenu } from "./plugins/textContextMenu.js";
|
|
56
54
|
import { ImageNodeView } from "./views/imageResize.js";
|
|
57
55
|
import { runMarkView } from "./views/runMarkView.js";
|
|
@@ -93,6 +91,9 @@ function createEditorState(doc, options = {}) {
|
|
|
93
91
|
// plugin appending to an edit, which then sees the control it kept, and behind the one above,
|
|
94
92
|
// whose deletion it keeps the control through before a composition opens
|
|
95
93
|
controlContents(),
|
|
94
|
+
// What the caret writes with, behind the one above so the marks it gives a caret it keeps
|
|
95
|
+
// inside a control win
|
|
96
|
+
caretFormat(),
|
|
96
97
|
history(),
|
|
97
98
|
keymap(docxKeymap),
|
|
98
99
|
historyKeys(),
|
|
@@ -130,11 +131,7 @@ function createEditorState(doc, options = {}) {
|
|
|
130
131
|
// What the notes under the page are, worked out from the document the same way
|
|
131
132
|
noteProjection.plugin,
|
|
132
133
|
noteNavigation(),
|
|
133
|
-
|
|
134
|
-
tabDecorations(),
|
|
135
|
-
tabPointer(),
|
|
136
|
-
tabLayout(),
|
|
137
|
-
tabCaret(),
|
|
134
|
+
...inlinePlugins(),
|
|
138
135
|
// Works the display values out again after every edit: the lines of a table's cells, and
|
|
139
136
|
// the style values of the paragraphs the edit built or rewrote
|
|
140
137
|
displayDerivation(),
|
|
@@ -43,6 +43,8 @@ export interface EditorDocument {
|
|
|
43
43
|
readonly reservedCommentIds: ReadonlySet<string>;
|
|
44
44
|
/** Every paragraph id present in the opened comment parts, including orphan extension entries */
|
|
45
45
|
readonly reservedCommentParaIds: ReadonlySet<string>;
|
|
46
|
+
/** Every durable id the opened comment parts name, including orphan entries */
|
|
47
|
+
readonly reservedCommentDurableIds: ReadonlySet<string>;
|
|
46
48
|
/** How the document counts its footnotes and endnotes, which the note labels are spelled in */
|
|
47
49
|
readonly noteNumbering: NoteNumbering;
|
|
48
50
|
/** The note entries that lay out the page rather than number a note: separators and the continuation notice */
|
|
@@ -79,3 +81,5 @@ export declare function storyDocument(document: EditorDocument, geometry: PageGe
|
|
|
79
81
|
export declare function reservedCommentIds(state: EditorState): ReadonlySet<string>;
|
|
80
82
|
/** The paragraph ids the opened comment parts already spent */
|
|
81
83
|
export declare function reservedCommentParaIds(state: EditorState): ReadonlySet<string>;
|
|
84
|
+
/** The durable ids the opened comment parts already spent */
|
|
85
|
+
export declare function reservedCommentDurableIds(state: EditorState): ReadonlySet<string>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/editor/editorDocument.ts
|
|
2
2
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
3
|
+
import { spentDurableIds } from "../docx/comments/reading.js";
|
|
3
4
|
import { DEFAULT_TAB_STOP_PT } from "../docx/documentSettings.js";
|
|
4
5
|
import {
|
|
5
6
|
NO_DOCUMENT_DEFAULTS,
|
|
@@ -29,6 +30,7 @@ var NO_DOCUMENT = {
|
|
|
29
30
|
defaultTabStopPt: DEFAULT_TAB_STOP_PT,
|
|
30
31
|
reservedCommentIds: NO_IDS,
|
|
31
32
|
reservedCommentParaIds: NO_IDS,
|
|
33
|
+
reservedCommentDurableIds: NO_IDS,
|
|
32
34
|
noteNumbering: DEFAULT_NOTE_NUMBERING,
|
|
33
35
|
specialNotes: NO_NOTE_KEYS,
|
|
34
36
|
reservedNoteKeys: NO_NOTE_KEYS
|
|
@@ -41,6 +43,9 @@ function reservedParaIds(session) {
|
|
|
41
43
|
for (const extension of session.comments.extendedOrdered) {
|
|
42
44
|
paraIds.add(extension.paraId);
|
|
43
45
|
}
|
|
46
|
+
for (const entry of session.comments.ids.ordered) {
|
|
47
|
+
paraIds.add(entry.paraId);
|
|
48
|
+
}
|
|
44
49
|
return paraIds;
|
|
45
50
|
}
|
|
46
51
|
function formattingWithNewLists(formatting, doc) {
|
|
@@ -62,6 +67,7 @@ function editorDocumentOf(session, doc) {
|
|
|
62
67
|
defaultTabStopPt: session.defaultTabStopPt,
|
|
63
68
|
reservedCommentIds: new Set(session.comments.byId.keys()),
|
|
64
69
|
reservedCommentParaIds: reservedParaIds(session),
|
|
70
|
+
reservedCommentDurableIds: spentDurableIds(session.comments),
|
|
65
71
|
noteNumbering: session.noteNumbering,
|
|
66
72
|
specialNotes: session.specialNotes,
|
|
67
73
|
reservedNoteKeys: new Set(
|
|
@@ -105,11 +111,15 @@ function reservedCommentIds(state) {
|
|
|
105
111
|
function reservedCommentParaIds(state) {
|
|
106
112
|
return documentOf(state).reservedCommentParaIds;
|
|
107
113
|
}
|
|
114
|
+
function reservedCommentDurableIds(state) {
|
|
115
|
+
return documentOf(state).reservedCommentDurableIds;
|
|
116
|
+
}
|
|
108
117
|
export {
|
|
109
118
|
NO_DOCUMENT,
|
|
110
119
|
documentOf,
|
|
111
120
|
editorDocument,
|
|
112
121
|
editorDocumentOf,
|
|
122
|
+
reservedCommentDurableIds,
|
|
113
123
|
reservedCommentIds,
|
|
114
124
|
reservedCommentParaIds,
|
|
115
125
|
storyDocument
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Mark, type Node as PMNode } from "prosemirror-model";
|
|
2
|
+
import { type StepRange } from "../schema/locks";
|
|
3
|
+
export interface FormatSource {
|
|
4
|
+
/** The run mark what is written takes, null for none */
|
|
5
|
+
run: Mark | null;
|
|
6
|
+
/** The runs holding no characters what is written fills, where one of them gave the formatting */
|
|
7
|
+
fills: StepRange | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function sameRun(a: Mark | null, b: Mark | null): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Word's rule: the nearest character the paragraph shows, before the caret else after it, and a run
|
|
12
|
+
* holding no characters only where the paragraph shows none. null in a paragraph holding nothing.
|
|
13
|
+
*
|
|
14
|
+
* A run holding no characters gives the formatting only where what is written fills it, so a blank
|
|
15
|
+
* the text cannot take the place of is passed over and never stands painted twice.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatSourceAt(doc: PMNode, pos: number): FormatSource | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/editor/formatSource.ts
|
|
2
|
+
import { Mark } from "prosemirror-model";
|
|
3
|
+
import { ownBackground } from "../docx/runProps.js";
|
|
4
|
+
import { docxSchema } from "../schema/index.js";
|
|
5
|
+
import { isEmptyRun } from "../schema/emptyRuns.js";
|
|
6
|
+
import {
|
|
7
|
+
controlsWrittenInto,
|
|
8
|
+
drawsNothing
|
|
9
|
+
} from "../schema/locks.js";
|
|
10
|
+
import { wrapperMarks } from "../schema/wrappers.js";
|
|
11
|
+
function runOf(node) {
|
|
12
|
+
return docxSchema.marks.run.isInSet(node.marks) ?? null;
|
|
13
|
+
}
|
|
14
|
+
function sameRun(a, b) {
|
|
15
|
+
return a === null || b === null ? a === b : a.eq(b);
|
|
16
|
+
}
|
|
17
|
+
function fillable(doc, pos, node) {
|
|
18
|
+
if (!isEmptyRun(node)) return false;
|
|
19
|
+
const open = controlsWrittenInto(doc, pos, pos + node.nodeSize).map(
|
|
20
|
+
(span) => span.mark
|
|
21
|
+
);
|
|
22
|
+
return wrapperMarks(node).every(
|
|
23
|
+
(wrapper) => wrapper.type === docxSchema.marks.sdt && open.some((control) => control.eq(wrapper))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function shows(doc, node, pos) {
|
|
27
|
+
if (!drawsNothing(node)) return true;
|
|
28
|
+
const run = runOf(node);
|
|
29
|
+
return run !== null && ownBackground(run) !== null && fillable(doc, pos, node);
|
|
30
|
+
}
|
|
31
|
+
function nearest($pos, matches) {
|
|
32
|
+
const parent = $pos.parent;
|
|
33
|
+
const index = $pos.index();
|
|
34
|
+
const at = (child) => matches(parent.child(child), $pos.posAtIndex(child));
|
|
35
|
+
for (let child = index - 1; child >= 0; child -= 1) {
|
|
36
|
+
if (at(child)) return child;
|
|
37
|
+
}
|
|
38
|
+
for (let child = index; child < parent.childCount; child += 1) {
|
|
39
|
+
if (at(child)) return child;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function filledFrom($pos, index) {
|
|
44
|
+
const parent = $pos.parent;
|
|
45
|
+
const source = parent.child(index);
|
|
46
|
+
const joins = (at) => {
|
|
47
|
+
const node = parent.maybeChild(at);
|
|
48
|
+
return node !== null && isEmptyRun(node) && sameRun(runOf(node), runOf(source)) && Mark.sameSet(wrapperMarks(node), wrapperMarks(source));
|
|
49
|
+
};
|
|
50
|
+
let first = index;
|
|
51
|
+
while (joins(first - 1)) first -= 1;
|
|
52
|
+
let last = index;
|
|
53
|
+
while (joins(last + 1)) last += 1;
|
|
54
|
+
return { from: $pos.posAtIndex(first), to: $pos.posAtIndex(last + 1) };
|
|
55
|
+
}
|
|
56
|
+
function formatSourceAt(doc, pos) {
|
|
57
|
+
const $pos = doc.resolve(pos);
|
|
58
|
+
const parent = $pos.parent;
|
|
59
|
+
if (!parent.inlineContent) return null;
|
|
60
|
+
if ($pos.textOffset > 0) {
|
|
61
|
+
return { run: runOf(parent.child($pos.index())), fills: null };
|
|
62
|
+
}
|
|
63
|
+
const source = nearest($pos, (node2, at) => shows(doc, node2, at)) ?? nearest($pos, (node2, at) => fillable(doc, at, node2));
|
|
64
|
+
if (source === null) return null;
|
|
65
|
+
const node = parent.child(source);
|
|
66
|
+
return {
|
|
67
|
+
run: runOf(node),
|
|
68
|
+
fills: isEmptyRun(node) ? filledFrom($pos, source) : null
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
formatSourceAt,
|
|
73
|
+
sameRun
|
|
74
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from "prosemirror-state";
|
|
2
|
+
/**
|
|
3
|
+
* Gives a caret the formatting of the character the rule in `../formatSource` finds, where a mark
|
|
4
|
+
* the caret was given on purpose does not stand: a caret beside something that draws nothing
|
|
5
|
+
* carries on the text the rule finds, and one beside a blank takes the blank's formatting, which
|
|
6
|
+
* `controlContents` then fills.
|
|
7
|
+
*
|
|
8
|
+
* It stands behind `controlContents`, whose stored marks for a caret left inside a control win.
|
|
9
|
+
*/
|
|
10
|
+
export declare function caretFormat(): Plugin;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/editor/plugins/caretFormat.ts
|
|
2
|
+
import { Plugin, TextSelection } from "prosemirror-state";
|
|
3
|
+
import { docxSchema } from "../../schema/index.js";
|
|
4
|
+
import { formatSourceAt, sameRun } from "../formatSource.js";
|
|
5
|
+
function caretMarks(tr) {
|
|
6
|
+
const caret = tr.selection instanceof TextSelection ? tr.selection.$cursor : null;
|
|
7
|
+
const source = caret ? formatSourceAt(tr.doc, caret.pos) : null;
|
|
8
|
+
if (!caret || source === null) return null;
|
|
9
|
+
const own = caret.marks();
|
|
10
|
+
const runType = docxSchema.marks.run;
|
|
11
|
+
if (sameRun(runType.isInSet(own) ?? null, source.run)) return null;
|
|
12
|
+
const others = runType.removeFromSet(own);
|
|
13
|
+
return source.run === null ? others : source.run.addToSet(others);
|
|
14
|
+
}
|
|
15
|
+
function caretFormat() {
|
|
16
|
+
let live = null;
|
|
17
|
+
return new Plugin({
|
|
18
|
+
view(view) {
|
|
19
|
+
live = view;
|
|
20
|
+
return {
|
|
21
|
+
destroy() {
|
|
22
|
+
live = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
appendTransaction(transactions, _oldState, newState) {
|
|
27
|
+
const moved = transactions.some((tr2) => tr2.docChanged || tr2.selectionSet);
|
|
28
|
+
if (!moved || newState.storedMarks !== null || live?.composing === true) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const tr = newState.tr;
|
|
32
|
+
const marks = caretMarks(tr);
|
|
33
|
+
return marks === null ? null : tr.setStoredMarks(marks);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
caretFormat
|
|
39
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/editor/plugins/commentDecorations.ts
|
|
2
2
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
3
|
+
import { commentInstant } from "../../docx/comments/dates.js";
|
|
3
4
|
import { storyKey, storyOf, storyText } from "../../docx/story.js";
|
|
4
5
|
import { editorClassNames } from "../../styles/classNames.js";
|
|
5
6
|
import {
|
|
@@ -41,7 +42,10 @@ function commentsIn(doc) {
|
|
|
41
42
|
author: stringAttr(node.attrs.author),
|
|
42
43
|
authorId: stringAttr(node.attrs.authorId),
|
|
43
44
|
initials: stringAttr(node.attrs.initials),
|
|
44
|
-
date:
|
|
45
|
+
date: commentInstant(
|
|
46
|
+
stringAttr(node.attrs.date),
|
|
47
|
+
stringAttr(node.attrs.dateUtc)
|
|
48
|
+
),
|
|
45
49
|
text: bodyText(doc, id),
|
|
46
50
|
from: anchored ? start + 1 : point,
|
|
47
51
|
to: anchored ? end : point,
|
|
@@ -53,7 +57,7 @@ function commentsIn(doc) {
|
|
|
53
57
|
author: reply.author,
|
|
54
58
|
authorId: reply.authorId,
|
|
55
59
|
initials: reply.initials,
|
|
56
|
-
date: reply.date,
|
|
60
|
+
date: commentInstant(stringAttr(reply.date), stringAttr(reply.dateUtc)),
|
|
57
61
|
text: bodyText(doc, reply.id)
|
|
58
62
|
}))
|
|
59
63
|
};
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* left beside a control the edit emptied: what is typed, composed or pasted there next goes into
|
|
17
17
|
* the control rather than beside it, until the caret moves. A caret the user places against the
|
|
18
18
|
* edge of a control still stands outside it.
|
|
19
|
+
*
|
|
20
|
+
* What is written where a run holding no characters gave the formatting (`../formatSource`) takes
|
|
21
|
+
* that run's formatting and fills it, a paste included: the run goes, and where it stood inside
|
|
22
|
+
* open controls, the controls are laid over what was written, so a caret placed in a control's
|
|
23
|
+
* blank writes into the control.
|
|
19
24
|
*/
|
|
20
25
|
import { Plugin } from "prosemirror-state";
|
|
21
26
|
/** Where the caret keeps writing into the controls it wrote into, while it stays there */
|