@portone/docx-editor 0.6.4 → 0.6.6
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 +47 -0
- package/CONTRIBUTING.md +4 -4
- package/dist/DocxEditor.d.ts +11 -0
- package/dist/DocxEditor.js +7 -3
- 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/importParagraph.js +5 -3
- 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/sequenceDiff.d.ts +56 -0
- package/dist/docx/sequenceDiff.js +252 -0
- 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/commands/comments/editing.js +56 -20
- package/dist/editor/commands/comments/model.d.ts +3 -1
- package/dist/editor/createEditor.d.ts +4 -1
- package/dist/editor/createEditor.js +14 -2
- package/dist/editor/editRefusal.d.ts +68 -0
- package/dist/editor/editRefusal.js +177 -0
- package/dist/editor/editorDocument.d.ts +4 -0
- package/dist/editor/editorDocument.js +10 -0
- package/dist/editor/plugins/commentDecorations.js +6 -2
- package/dist/editor/plugins/controlContents.d.ts +24 -0
- package/dist/editor/plugins/controlContents.js +260 -0
- package/dist/editor/plugins/controlLifecycle.js +3 -5
- package/dist/editor/stories/storyState.js +2 -0
- package/dist/index.d.ts +2 -0
- 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 +3 -1
- package/dist/schema/controlAttrs.d.ts +6 -0
- package/dist/schema/controlAttrs.js +4 -0
- package/dist/schema/docxSchema.js +10 -3
- package/dist/schema/guards.d.ts +8 -2
- package/dist/schema/guards.js +14 -8
- package/dist/schema/locks.d.ts +25 -2
- package/dist/schema/locks.js +67 -11
- package/dist/schema/protection.js +2 -1
- package/dist/styles/classNames.d.ts +2 -0
- package/dist/styles/classNames.js +2 -0
- package/dist/styles.css +65 -14
- package/dist/ui/CommentsPanel.js +8 -13
- package/dist/ui/MenuNote.d.ts +12 -0
- package/dist/ui/MenuNote.js +14 -0
- package/dist/ui/TableMenu.js +38 -19
- package/dist/ui/TextMenu.js +31 -25
- package/dist/ui/comments/commentDate.d.ts +7 -0
- package/dist/ui/comments/commentDate.js +17 -0
- package/package.json +7 -7
package/dist/ooxml/errors.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface ExportProblemStory {
|
|
|
52
52
|
readonly id: string;
|
|
53
53
|
}
|
|
54
54
|
/** A part the export writes beside the body, named after what it holds */
|
|
55
|
-
export type ExportPartName = "media" | "numbering" | "comments" | "commentsExtended" | "people" | "footnotes" | "endnotes";
|
|
55
|
+
export type ExportPartName = "media" | "numbering" | "comments" | "commentsExtended" | "people" | "commentsIds" | "commentsExtensible" | "footnotes" | "endnotes";
|
|
56
56
|
/**
|
|
57
57
|
* What a refusal is actually about.
|
|
58
58
|
*
|
package/dist/ooxml/names.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare const NAMESPACES: {
|
|
|
26
26
|
readonly r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
27
27
|
readonly w14: "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
28
28
|
readonly w15: "http://schemas.microsoft.com/office/word/2012/wordml";
|
|
29
|
+
readonly w16cid: "http://schemas.microsoft.com/office/word/2016/wordml/cid";
|
|
30
|
+
readonly w16cex: "http://schemas.microsoft.com/office/word/2018/wordml/cex";
|
|
29
31
|
readonly mc: "http://schemas.openxmlformats.org/markup-compatibility/2006";
|
|
30
32
|
readonly wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
|
|
31
33
|
readonly a: "http://schemas.openxmlformats.org/drawingml/2006/main";
|
package/dist/ooxml/names.js
CHANGED
|
@@ -8,6 +8,8 @@ var NAMESPACES = {
|
|
|
8
8
|
r: R_NS,
|
|
9
9
|
w14: "http://schemas.microsoft.com/office/word/2010/wordml",
|
|
10
10
|
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
|
|
11
|
+
w16cid: "http://schemas.microsoft.com/office/word/2016/wordml/cid",
|
|
12
|
+
w16cex: "http://schemas.microsoft.com/office/word/2018/wordml/cex",
|
|
11
13
|
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
|
12
14
|
wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
|
13
15
|
a: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
@@ -8,22 +8,32 @@
|
|
|
8
8
|
* comment for the end of the part, and miss the root altogether when it is written under a
|
|
9
9
|
* prefix or closes on itself.
|
|
10
10
|
*/
|
|
11
|
+
import { type XmlAttr } from "./element";
|
|
11
12
|
import { type KnownPrefix } from "./names";
|
|
12
13
|
/** One child to put into a part, named by the local part of its tag so the child order can place it */
|
|
13
14
|
export interface PartChild {
|
|
14
15
|
name: string;
|
|
15
16
|
xml: string;
|
|
16
17
|
}
|
|
18
|
+
/** A child the part already holds, as `keep` is handed it */
|
|
19
|
+
export interface HeldChild extends PartChild {
|
|
20
|
+
/** As its tag spells them, and null where they cannot be read */
|
|
21
|
+
attrs: readonly XmlAttr[] | null;
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* What goes into a part's root. Every field is optional and they compose: the children are
|
|
19
|
-
* replaced first, then the
|
|
20
|
-
* either end, and last the opening tag is rewritten.
|
|
25
|
+
* replaced first, then the ones `keep` turns down are taken out, then the inserts are placed among
|
|
26
|
+
* them, then the prepend and the append go on either end, and last the opening tag is rewritten.
|
|
21
27
|
*/
|
|
22
28
|
export interface PartSplice {
|
|
23
29
|
/** The root's local name. Any prefix, a self-closing root, a prolog and comments are all handled */
|
|
24
30
|
root: string;
|
|
25
|
-
/**
|
|
31
|
+
/** Takes out each child this answers false for, leaving the text between children */
|
|
32
|
+
keep?: (child: HeldChild) => boolean;
|
|
33
|
+
/** Children put at the spot `order` lays down, ahead of the first child that order puts after them */
|
|
26
34
|
insert?: readonly PartChild[];
|
|
35
|
+
/** The order `insert` places by, for a root outside `wml.xsd`, which `CHILD_ORDER` is held to */
|
|
36
|
+
order?: readonly string[];
|
|
27
37
|
/** Put in as the last children */
|
|
28
38
|
append?: string;
|
|
29
39
|
/** Put in right after the opening tag */
|
package/dist/ooxml/partSplice.js
CHANGED
|
@@ -38,6 +38,11 @@ function partRootProblem(xml, root) {
|
|
|
38
38
|
const reading = readRoot(xml, root);
|
|
39
39
|
return "problem" in reading ? reading.problem : null;
|
|
40
40
|
}
|
|
41
|
+
function tagAttributes(text, tag) {
|
|
42
|
+
return parseAttrs(
|
|
43
|
+
text.slice(tag.nameEnd, tag.end - (tag.kind === "empty" ? 2 : 1))
|
|
44
|
+
);
|
|
45
|
+
}
|
|
41
46
|
function directChildren(inner) {
|
|
42
47
|
const children = [];
|
|
43
48
|
let depth = 0;
|
|
@@ -48,29 +53,55 @@ function directChildren(inner) {
|
|
|
48
53
|
const tag = readTag(inner, lt);
|
|
49
54
|
if (tag === null) return children;
|
|
50
55
|
if (depth === 0 && (tag.kind === "open" || tag.kind === "empty")) {
|
|
51
|
-
children.push({
|
|
56
|
+
children.push({
|
|
57
|
+
name: localPart(tag.name),
|
|
58
|
+
at: lt,
|
|
59
|
+
end: tag.end,
|
|
60
|
+
open: tag
|
|
61
|
+
});
|
|
52
62
|
}
|
|
53
63
|
if (tag.kind === "open") depth += 1;
|
|
54
|
-
if (tag.kind === "close")
|
|
64
|
+
if (tag.kind === "close") {
|
|
65
|
+
depth -= 1;
|
|
66
|
+
const last = children.at(-1);
|
|
67
|
+
if (depth === 0 && last !== void 0) last.end = tag.end;
|
|
68
|
+
}
|
|
55
69
|
at = tag.end;
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
|
-
function
|
|
72
|
+
function withoutChildren(inner, keep) {
|
|
73
|
+
let out = "";
|
|
74
|
+
let from = 0;
|
|
75
|
+
for (const { name, at, end, open } of directChildren(inner)) {
|
|
76
|
+
const xml = inner.slice(at, end);
|
|
77
|
+
if (keep({ name, xml, attrs: tagAttributes(inner, open) })) continue;
|
|
78
|
+
out += inner.slice(from, at);
|
|
79
|
+
from = end;
|
|
80
|
+
}
|
|
81
|
+
return out + inner.slice(from);
|
|
82
|
+
}
|
|
83
|
+
function insertionAt(children, name, order, root, end, fromRegistry) {
|
|
59
84
|
const target = order.indexOf(name);
|
|
60
85
|
if (target === -1) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
86
|
+
const fix = fromRegistry ? "; add it to CHILD_ORDER" : "";
|
|
87
|
+
throw new Error(`${name} is not a child the order of ${root} knows${fix}`);
|
|
64
88
|
}
|
|
65
89
|
const after = children.find((child) => order.indexOf(child.name) > target);
|
|
66
90
|
return after === void 0 ? end : after.at;
|
|
67
91
|
}
|
|
68
|
-
function withInserted(inner, inserts, root) {
|
|
92
|
+
function withInserted(inner, inserts, root, given) {
|
|
69
93
|
if (inserts.length === 0) return inner;
|
|
70
|
-
const order = childOrderOf(root);
|
|
94
|
+
const order = given ?? childOrderOf(root);
|
|
71
95
|
const children = directChildren(inner);
|
|
72
96
|
const placed = inserts.map((child) => ({
|
|
73
|
-
at: insertionAt(
|
|
97
|
+
at: insertionAt(
|
|
98
|
+
children,
|
|
99
|
+
child.name,
|
|
100
|
+
order,
|
|
101
|
+
root,
|
|
102
|
+
inner.length,
|
|
103
|
+
given === void 0
|
|
104
|
+
),
|
|
74
105
|
xml: child.xml,
|
|
75
106
|
rank: order.indexOf(child.name)
|
|
76
107
|
})).sort((a, b) => a.at - b.at || a.rank - b.rank);
|
|
@@ -89,11 +120,9 @@ function splicePart(xml, splice) {
|
|
|
89
120
|
}
|
|
90
121
|
const { openAt, open, closeAt } = reading.root;
|
|
91
122
|
const inner = closeAt === null ? "" : xml.slice(open.end, closeAt);
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
splice.root
|
|
96
|
-
) + (splice.append ?? "");
|
|
123
|
+
const replaced = splice.replaceChildren ?? inner;
|
|
124
|
+
const kept = splice.keep === void 0 ? replaced : withoutChildren(replaced, splice.keep);
|
|
125
|
+
const children = (splice.prepend ?? "") + withInserted(kept, splice.insert ?? [], splice.root, splice.order) + (splice.append ?? "");
|
|
97
126
|
const openTag = xml.slice(openAt, open.end);
|
|
98
127
|
const opened = closeAt === null && children !== "" ? `${openTag.slice(0, -2)}>` : openTag;
|
|
99
128
|
const head = xml.slice(0, openAt) + (splice.rootTag?.(opened) ?? opened);
|
|
@@ -124,16 +153,14 @@ function rootBindingConflict(xml, declarations) {
|
|
|
124
153
|
const at = rootTagAt(xml);
|
|
125
154
|
const tag = at === -1 ? null : readTag(xml, at);
|
|
126
155
|
if (tag === null || tag.kind === "close") return null;
|
|
127
|
-
const attrs =
|
|
128
|
-
xml.slice(tag.nameEnd, tag.end - (tag.kind === "empty" ? 2 : 1))
|
|
129
|
-
);
|
|
156
|
+
const attrs = tagAttributes(xml, tag);
|
|
130
157
|
return attrs === null ? null : conflictingPrefix(new Map(attrs), declarations);
|
|
131
158
|
}
|
|
132
159
|
function withDeclarations(openTag, declarations) {
|
|
133
160
|
const { namespaces, ignorable } = declarations;
|
|
134
161
|
const tag = readTag(openTag, 0);
|
|
135
162
|
const closeLength = tag?.kind === "empty" ? 2 : 1;
|
|
136
|
-
const attrs = tag === null ? null :
|
|
163
|
+
const attrs = tag === null ? null : tagAttributes(openTag, tag);
|
|
137
164
|
if (tag === null || attrs === null) {
|
|
138
165
|
throw new DocxExportError(
|
|
139
166
|
"malformed-xml",
|
package/dist/schema/attrRoles.js
CHANGED
|
@@ -148,7 +148,9 @@ var NODE_ATTR_ROLES = {
|
|
|
148
148
|
extensionXml: { role: "source", class: "preserved" },
|
|
149
149
|
replies: { role: "source", class: "model" },
|
|
150
150
|
// Read to decide whether the extended comment part is rewritten at all; it is never written
|
|
151
|
-
threadImported: { role: "session", class: "derived" }
|
|
151
|
+
threadImported: { role: "session", class: "derived" },
|
|
152
|
+
durableId: { role: "source", class: "identity" },
|
|
153
|
+
dateUtc: { role: "source", class: "model" }
|
|
152
154
|
},
|
|
153
155
|
noteReference: {
|
|
154
156
|
kind: { role: "source", class: "model" },
|
|
@@ -43,6 +43,12 @@ export interface ControlFacts {
|
|
|
43
43
|
/** Whether `w:showingPlcHdr` says what stands inside is placeholder text (§17.5.2.39) */
|
|
44
44
|
showingPlaceholder: boolean;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether the first edit of its contents takes the control away. `w:temporary` (§17.5.2.43) says
|
|
48
|
+
* it goes and a lock against deletion (§17.5.2.23) that it may not, and the lock wins
|
|
49
|
+
* (`spec/notes/contentControls.md`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function goesWithEdit(control: ControlFacts): boolean;
|
|
46
52
|
/** Everything a control states other than the opening XML the carrier preserves */
|
|
47
53
|
export type ControlFlags = Omit<ControlFacts, "prefix">;
|
|
48
54
|
/** The control's own names, which the mark and the block-level container both carry */
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
var SDT_BLOCK_NODE = "sdtBlock";
|
|
3
3
|
var SDT_EMPTY_BLOCK_NODE = "sdtEmpty";
|
|
4
4
|
var SDT_EMPTY_INLINE_NODE = "sdtEmptyInline";
|
|
5
|
+
function goesWithEdit(control) {
|
|
6
|
+
return control.temporary && !control.deletionLocked;
|
|
7
|
+
}
|
|
5
8
|
var OWN_CONTROL_ATTRS = {
|
|
6
9
|
prefix: "sdtPrefix",
|
|
7
10
|
contentsLocked: "contentsLocked",
|
|
@@ -131,6 +134,7 @@ export {
|
|
|
131
134
|
controlClassName,
|
|
132
135
|
controlFactsOf,
|
|
133
136
|
controlToDom,
|
|
137
|
+
goesWithEdit,
|
|
134
138
|
isBlockControl,
|
|
135
139
|
isEmptyBlockControl,
|
|
136
140
|
isEmptyInlineControl
|
|
@@ -864,7 +864,10 @@ var docxSchema = new Schema({
|
|
|
864
864
|
resolved: { default: false },
|
|
865
865
|
extensionXml: { default: null },
|
|
866
866
|
threadImported: { default: false },
|
|
867
|
-
replies: { default: [] }
|
|
867
|
+
replies: { default: [] },
|
|
868
|
+
// `date` is the author's wall clock and `dateUtc` the instant (`docx/comments/dates`)
|
|
869
|
+
durableId: { default: null },
|
|
870
|
+
dateUtc: { default: null }
|
|
868
871
|
},
|
|
869
872
|
toDOM(node) {
|
|
870
873
|
return [
|
|
@@ -882,7 +885,9 @@ var docxSchema = new Schema({
|
|
|
882
885
|
"data-comment-resolved": node.attrs.resolved === true ? "1" : void 0,
|
|
883
886
|
"data-comment-extension-xml": text(node.attrs.extensionXml),
|
|
884
887
|
"data-comment-thread-imported": node.attrs.threadImported === true ? "1" : void 0,
|
|
885
|
-
"data-comment-replies": JSON.stringify(node.attrs.replies ?? [])
|
|
888
|
+
"data-comment-replies": JSON.stringify(node.attrs.replies ?? []),
|
|
889
|
+
"data-comment-durable-id": text(node.attrs.durableId),
|
|
890
|
+
"data-comment-date-utc": text(node.attrs.dateUtc)
|
|
886
891
|
}
|
|
887
892
|
];
|
|
888
893
|
},
|
|
@@ -915,7 +920,9 @@ var docxSchema = new Schema({
|
|
|
915
920
|
resolved: dom.getAttribute("data-comment-resolved") === "1",
|
|
916
921
|
extensionXml,
|
|
917
922
|
threadImported: dom.getAttribute("data-comment-thread-imported") === "1",
|
|
918
|
-
replies
|
|
923
|
+
replies,
|
|
924
|
+
durableId: dom.getAttribute("data-comment-durable-id"),
|
|
925
|
+
dateUtc: dom.getAttribute("data-comment-date-utc")
|
|
919
926
|
};
|
|
920
927
|
}
|
|
921
928
|
}
|
package/dist/schema/guards.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* is open at all, which is a question about the editor rather than about an edit.
|
|
23
23
|
*/
|
|
24
24
|
import type { Command, EditorState, Selection, Transaction } from "prosemirror-state";
|
|
25
|
-
import { type EditGuard, type EditIntent } from "./editGuard";
|
|
25
|
+
import { type EditGuard, type EditGuardName, type EditIntent } from "./editGuard";
|
|
26
26
|
import { type ProtectionState } from "./protection";
|
|
27
27
|
export type { EditGuard, EditGuardName, EditIntent } from "./editGuard";
|
|
28
28
|
export { stepReaches } from "./editGuard";
|
|
@@ -42,7 +42,8 @@ export declare function transactionTouchesComments(tr: Transaction): boolean;
|
|
|
42
42
|
export declare function protectionAllowsTransaction(tr: Transaction, rules: ProtectionState): boolean;
|
|
43
43
|
export declare const EDIT_GUARDS: readonly EditGuard[];
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* The first guard that would turn this transaction down, decided and nothing else. Null when every
|
|
46
|
+
* guard lets it through.
|
|
46
47
|
*
|
|
47
48
|
* The refusal a guard itself answers with carries a side effect - the composition it ends
|
|
48
49
|
* (`editor/plugins/lockedContent`) - which a query about a button's state may not set off, so the
|
|
@@ -53,7 +54,12 @@ export declare const EDIT_GUARDS: readonly EditGuard[];
|
|
|
53
54
|
* whole-change judgements then come first and take no pass, since a pass lifts one guard's
|
|
54
55
|
* reading of a step rather than another guard's reading of the change. What is left is judged
|
|
55
56
|
* step by step, each step over the document it was built against.
|
|
57
|
+
*
|
|
58
|
+
* Which guard answers is what a refusal is reported under (`editor/editRefusal`), so the list is
|
|
59
|
+
* asked in its own order and the first refusal is the one named.
|
|
56
60
|
*/
|
|
61
|
+
export declare function transactionRefusal(tr: Transaction, state: EditorState): EditGuardName | null;
|
|
62
|
+
/** Whether every guard would let this transaction through (`transactionRefusal`) */
|
|
57
63
|
export declare function transactionAllowed(tr: Transaction, state: EditorState): boolean;
|
|
58
64
|
/**
|
|
59
65
|
* Whether any guard shuts this intent where it stands.
|
package/dist/schema/guards.js
CHANGED
|
@@ -52,16 +52,17 @@ function displayOnlyTransaction(tr, state) {
|
|
|
52
52
|
(step, index) => changesOnlyDisplayAttrs(step, tr.docs[index] ?? state.doc)
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (!tr.docChanged) return
|
|
57
|
-
if (displayOnlyTransaction(tr, state)) return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
function transactionRefusal(tr, state) {
|
|
56
|
+
if (!tr.docChanged) return null;
|
|
57
|
+
if (displayOnlyTransaction(tr, state)) return null;
|
|
58
|
+
const changeRefusal = EDIT_GUARDS.find(
|
|
59
|
+
(guard) => guard.change?.(tr, state) === false
|
|
60
|
+
);
|
|
61
|
+
if (changeRefusal) return changeRefusal.name;
|
|
62
|
+
const stepRefusal = EDIT_GUARDS.filter(judgesSteps).filter((guard) => !lifted(guard, tr)).find(
|
|
62
63
|
(guard) => (
|
|
63
64
|
// Each step counts positions in the document it was built against, which `docs` holds
|
|
64
|
-
tr.steps.every(
|
|
65
|
+
!tr.steps.every(
|
|
65
66
|
(step, index) => guard.step(
|
|
66
67
|
step,
|
|
67
68
|
tr.docs[index] ?? state.doc,
|
|
@@ -71,6 +72,10 @@ function transactionAllowed(tr, state) {
|
|
|
71
72
|
)
|
|
72
73
|
)
|
|
73
74
|
);
|
|
75
|
+
return stepRefusal?.name ?? null;
|
|
76
|
+
}
|
|
77
|
+
function transactionAllowed(tr, state) {
|
|
78
|
+
return transactionRefusal(tr, state) === null;
|
|
74
79
|
}
|
|
75
80
|
function editShut(state, intent) {
|
|
76
81
|
return EDIT_GUARDS.some((guard) => guard.shuts(intent, state));
|
|
@@ -105,5 +110,6 @@ export {
|
|
|
105
110
|
selectionIntents,
|
|
106
111
|
stepReaches,
|
|
107
112
|
transactionAllowed,
|
|
113
|
+
transactionRefusal,
|
|
108
114
|
transactionTouchesComments
|
|
109
115
|
};
|
package/dist/schema/locks.d.ts
CHANGED
|
@@ -37,6 +37,18 @@ export declare const historyReplay: PluginKey<boolean>;
|
|
|
37
37
|
* (`spec/notes/contentControls.md`).
|
|
38
38
|
*/
|
|
39
39
|
export declare const controlLifted: PluginKey<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* The pass the transaction that keeps an inline control through an edit of its contents carries
|
|
42
|
+
* (`editor/plugins/controlContents`).
|
|
43
|
+
*
|
|
44
|
+
* Writing over everything a control holds is an edit of its contents rather than its deletion
|
|
45
|
+
* (`controlsWrittenInto`), and that transaction is what keeps the control standing: it lays the
|
|
46
|
+
* control back over what was written, or leaves the control standing as one holding nothing. When
|
|
47
|
+
* the caret then writes into a control it emptied, the node it stood as goes, since the control
|
|
48
|
+
* stands as the new text instead. That removal is the one step here a lock against deletion would
|
|
49
|
+
* refuse, and it removes no control.
|
|
50
|
+
*/
|
|
51
|
+
export declare const controlKept: PluginKey<boolean>;
|
|
40
52
|
/** The stretch a judgement or an edit runs over */
|
|
41
53
|
export interface StepRange {
|
|
42
54
|
from: number;
|
|
@@ -91,6 +103,16 @@ export declare function controlSpans(block: Textblock): ControlSpan[];
|
|
|
91
103
|
* (`editor/commands/lockCommands`).
|
|
92
104
|
*/
|
|
93
105
|
export declare function coversWhole(range: StepRange, span: StepRange): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The inline controls replacing this stretch writes into rather than takes away, each as the
|
|
108
|
+
* whole stretch it covers, outermost first.
|
|
109
|
+
*
|
|
110
|
+
* These are the controls the stretch stands within (`standsWithin`) whose contents no lock of
|
|
111
|
+
* their own shuts, which is what the lock guard reads as an edit of the contents rather than a
|
|
112
|
+
* deletion. What takes the stretch's place belongs inside each of them, and a control the
|
|
113
|
+
* replacement leaves holding nothing still stands (`editor/plugins/controlContents`).
|
|
114
|
+
*/
|
|
115
|
+
export declare function controlsWrittenInto(doc: PMNode, from: number, to: number): ControlSpan[];
|
|
94
116
|
/** One content control holding nothing, standing as a node of its own, as the one spot it covers */
|
|
95
117
|
export interface EmptyControl {
|
|
96
118
|
node: PMNode;
|
|
@@ -125,7 +147,8 @@ export declare function selectionShut(selection: Selection, doc: PMNode): boolea
|
|
|
125
147
|
/**
|
|
126
148
|
* The locks the document carries, as `./guards` registers them.
|
|
127
149
|
*
|
|
128
|
-
*
|
|
129
|
-
* history replays is the reverse of a step that passed the guard when it was made
|
|
150
|
+
* Every pass lifts it: unlocking is the one edit that may reach into a lock, every step the
|
|
151
|
+
* history replays is the reverse of a step that passed the guard when it was made, and the other
|
|
152
|
+
* two carry what an edit that passed does to a control (`controlLifted`, `controlKept`).
|
|
130
153
|
*/
|
|
131
154
|
export declare const lockGuard: StepGuard;
|
package/dist/schema/locks.js
CHANGED
|
@@ -19,6 +19,7 @@ import { wrappersOf } from "./wrappers.js";
|
|
|
19
19
|
var unlockAllowed = new PluginKey("docxEditorUnlockAllowed");
|
|
20
20
|
var historyReplay = new PluginKey("docxEditorHistoryReplay");
|
|
21
21
|
var controlLifted = new PluginKey("docxEditorControlLifted");
|
|
22
|
+
var controlKept = new PluginKey("docxEditorControlKept");
|
|
22
23
|
var OPEN = { contents: false, deletion: false, group: false };
|
|
23
24
|
function shutsContents(locks, inner) {
|
|
24
25
|
return locks.contents || locks.group && !inner;
|
|
@@ -126,8 +127,68 @@ function coversWhole(range, span) {
|
|
|
126
127
|
function overlaps(range, span) {
|
|
127
128
|
return range.from < span.to && range.to > span.from;
|
|
128
129
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
130
|
+
function drawsNothing(node) {
|
|
131
|
+
switch (node.type.name) {
|
|
132
|
+
case "commentStart":
|
|
133
|
+
case "commentEnd":
|
|
134
|
+
return true;
|
|
135
|
+
case "rawInline":
|
|
136
|
+
case "rawRunContent":
|
|
137
|
+
return node.attrs.display === "hidden";
|
|
138
|
+
default:
|
|
139
|
+
return isEmptyInlineControl(node);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function visibleStretch(block, range, span) {
|
|
143
|
+
let { from, to } = range;
|
|
144
|
+
const children = [];
|
|
145
|
+
block.node.forEach((node, offset) => {
|
|
146
|
+
children.push({ node, at: block.start + offset });
|
|
147
|
+
});
|
|
148
|
+
for (const { node, at } of children) {
|
|
149
|
+
if (at === from && from < span.from && drawsNothing(node)) {
|
|
150
|
+
from = at + node.nodeSize;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const { node, at } of children.reverse()) {
|
|
154
|
+
if (at + node.nodeSize === to && to > span.to && drawsNothing(node)) {
|
|
155
|
+
to = at;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { from, to };
|
|
159
|
+
}
|
|
160
|
+
function standsWithin(block, range, span) {
|
|
161
|
+
if (range.from >= range.to) return false;
|
|
162
|
+
const end = block.start + block.node.content.size;
|
|
163
|
+
if (range.from < block.start || range.to > end) return false;
|
|
164
|
+
const visible = visibleStretch(block, range, span);
|
|
165
|
+
return visible.from >= span.from && visible.to <= span.to;
|
|
166
|
+
}
|
|
167
|
+
function shuts(locks, range, span, inner, within) {
|
|
168
|
+
const open = !shutsContents(locks, inner);
|
|
169
|
+
return range.takesAway && coversWhole(range, span) && !(within && open) ? locks.deletion : !open && overlaps(range, span);
|
|
170
|
+
}
|
|
171
|
+
function spanShut(block, spans, span, range) {
|
|
172
|
+
return shuts(
|
|
173
|
+
markLocks(span.mark),
|
|
174
|
+
range,
|
|
175
|
+
span,
|
|
176
|
+
supersededSpan(spans, span, range),
|
|
177
|
+
standsWithin(block, range, span)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function controlsWrittenInto(doc, from, to) {
|
|
181
|
+
if (from >= to) return [];
|
|
182
|
+
const $from = doc.resolve(from);
|
|
183
|
+
if (!$from.parent.isTextblock || !$from.sameParent(doc.resolve(to))) {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
const block = { node: $from.parent, start: $from.start() };
|
|
187
|
+
const range = { from, to };
|
|
188
|
+
const spans = controlSpans(block);
|
|
189
|
+
return spans.filter(
|
|
190
|
+
(span) => standsWithin(block, range, span) && !shutsContents(markLocks(span.mark), supersededSpan(spans, span, range))
|
|
191
|
+
);
|
|
131
192
|
}
|
|
132
193
|
function supersededSpan(spans, span, range) {
|
|
133
194
|
return spans.some(
|
|
@@ -162,14 +223,7 @@ function rangeShut(doc, range) {
|
|
|
162
223
|
if (!node.isTextblock) return true;
|
|
163
224
|
const block = { node, start: pos + 1 };
|
|
164
225
|
const spans = controlSpans(block);
|
|
165
|
-
shut ||= spans.some(
|
|
166
|
-
(span) => shuts(
|
|
167
|
-
markLocks(span.mark),
|
|
168
|
-
range,
|
|
169
|
-
span,
|
|
170
|
-
supersededSpan(spans, span, range)
|
|
171
|
-
)
|
|
172
|
-
);
|
|
226
|
+
shut ||= spans.some((span) => spanShut(block, spans, span, range));
|
|
173
227
|
shut ||= emptyControlsIn(block).some(
|
|
174
228
|
(control) => containerShut(control.node, control.span, range)
|
|
175
229
|
);
|
|
@@ -275,14 +329,16 @@ function intentShut(doc, intent) {
|
|
|
275
329
|
}
|
|
276
330
|
var lockGuard = {
|
|
277
331
|
name: "lock",
|
|
278
|
-
liftedBy: [unlockAllowed, historyReplay, controlLifted],
|
|
332
|
+
liftedBy: [unlockAllowed, historyReplay, controlLifted, controlKept],
|
|
279
333
|
step: (step, before) => stepAllowed(step, before),
|
|
280
334
|
shuts: (intent, state) => intentShut(state.doc, intent)
|
|
281
335
|
};
|
|
282
336
|
export {
|
|
283
337
|
carriesLock,
|
|
338
|
+
controlKept,
|
|
284
339
|
controlLifted,
|
|
285
340
|
controlSpans,
|
|
341
|
+
controlsWrittenInto,
|
|
286
342
|
coversWhole,
|
|
287
343
|
emptyControlsIn,
|
|
288
344
|
historyReplay,
|
|
@@ -39,6 +39,7 @@ function bodyOf(attrs, doc) {
|
|
|
39
39
|
author: stringOrNull(attrs.author),
|
|
40
40
|
initials: stringOrNull(attrs.initials),
|
|
41
41
|
date: stringOrNull(attrs.date),
|
|
42
|
+
dateUtc: stringOrNull(attrs.dateUtc),
|
|
42
43
|
body: id === null ? null : storyNodeOf(doc, storyKey("comment", id))
|
|
43
44
|
};
|
|
44
45
|
}
|
|
@@ -100,7 +101,7 @@ function sameIdentity(was, now) {
|
|
|
100
101
|
return was.authorId === now.authorId && was.author === now.author;
|
|
101
102
|
}
|
|
102
103
|
function sameWords(was, now) {
|
|
103
|
-
return sameStory(was.body, now.body) && was.initials === now.initials && was.date === now.date;
|
|
104
|
+
return sameStory(was.body, now.body) && was.initials === now.initials && was.date === now.date && was.dateUtc === now.dateUtc;
|
|
104
105
|
}
|
|
105
106
|
function commentIdentitiesKept(before, after) {
|
|
106
107
|
const now = threadsIn(after);
|
|
@@ -122,6 +122,8 @@ export declare const editorClassNames: {
|
|
|
122
122
|
/** The keyboard shortcut written on the right of a menu row */
|
|
123
123
|
readonly menuHint: "docx-editor-menu-hint";
|
|
124
124
|
readonly menuSeparator: "docx-editor-menu-sep";
|
|
125
|
+
/** The line at the head of a menu saying why its editing entries stand disabled */
|
|
126
|
+
readonly menuNote: "docx-editor-menu-note";
|
|
125
127
|
/** The panel that reads and writes a link's address, floated over the selection */
|
|
126
128
|
readonly linkPanel: "docx-editor-link-panel";
|
|
127
129
|
/** The field the address is typed into */
|
|
@@ -118,6 +118,8 @@ var editorClassNames = {
|
|
|
118
118
|
/** The keyboard shortcut written on the right of a menu row */
|
|
119
119
|
menuHint: `${PREFIX}-menu-hint`,
|
|
120
120
|
menuSeparator: `${PREFIX}-menu-sep`,
|
|
121
|
+
/** The line at the head of a menu saying why its editing entries stand disabled */
|
|
122
|
+
menuNote: `${PREFIX}-menu-note`,
|
|
121
123
|
/** The panel that reads and writes a link's address, floated over the selection */
|
|
122
124
|
linkPanel: `${PREFIX}-link-panel`,
|
|
123
125
|
/** The field the address is typed into */
|
package/dist/styles.css
CHANGED
|
@@ -629,9 +629,6 @@ button.docx-editor-comment-body {
|
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
-
@media (max-width: 420px) {
|
|
633
|
-
}
|
|
634
|
-
|
|
635
632
|
.docx-editor-sheet {
|
|
636
633
|
/*
|
|
637
634
|
* The paper size, and the margins printed inside it.
|
|
@@ -1004,21 +1001,39 @@ button.docx-editor-comment-body {
|
|
|
1004
1001
|
}
|
|
1005
1002
|
|
|
1006
1003
|
/*
|
|
1007
|
-
* A content control that
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1004
|
+
* A content control that shuts its contents (`editor/plugins/lockedContent` refuses the edits), and
|
|
1005
|
+
* one that leaves them open, each drawn from a pair of properties a host may set (`--docx-editor-
|
|
1006
|
+
* locked-*`, `--docx-editor-control-*`).
|
|
1007
|
+
*
|
|
1008
|
+
* The tint is painted as a background image rather than a background colour: a run, a paragraph
|
|
1009
|
+
* and a cell write the document's own shading as an inline `background-color`, which would win
|
|
1010
|
+
* over a colour set here - a cell whose `w:shd` says `auto` draws as `transparent` - while an
|
|
1011
|
+
* image layer is painted over it. The default tint is a translucent yellow that lands on #fff59d
|
|
1012
|
+
* over white paper, so a shaded cell's own colour still shows through it.
|
|
1013
|
+
* A run's own shading is a box inside the control and paints over the tint, so an outline is drawn
|
|
1014
|
+
* as well: outlines go on last, whatever the content paints. An open control is not marked unless
|
|
1015
|
+
* the host asks for it.
|
|
1011
1016
|
*/
|
|
1012
1017
|
.docx-editor-sdt-locked {
|
|
1013
|
-
background:
|
|
1014
|
-
|
|
1018
|
+
background-image: linear-gradient(
|
|
1019
|
+
var(--docx-editor-locked-background, rgb(255 235 59 / 50%)) 0 0
|
|
1020
|
+
);
|
|
1021
|
+
outline: var(--docx-editor-locked-outline, 1px solid #f9a825);
|
|
1015
1022
|
cursor: not-allowed;
|
|
1016
1023
|
}
|
|
1017
1024
|
|
|
1025
|
+
.docx-editor-sdt:not(.docx-editor-sdt-locked),
|
|
1026
|
+
.docx-editor-sdt-block:not(.docx-editor-sdt-locked) {
|
|
1027
|
+
background-image: linear-gradient(
|
|
1028
|
+
var(--docx-editor-control-background, transparent) 0 0
|
|
1029
|
+
);
|
|
1030
|
+
outline: var(--docx-editor-control-outline, none);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1018
1033
|
/*
|
|
1019
1034
|
* A content control that holds nothing occupies nothing on the page: the file says a clause is not
|
|
1020
1035
|
* there, and a box drawn for it would be a clause of its own.
|
|
1021
|
-
* A shut control wears the
|
|
1036
|
+
* A shut control wears the marks above beside this class, and an outline is painted outside the
|
|
1022
1037
|
* box rather than clipped by it, so a zero height alone would leave a 1px rule across the page.
|
|
1023
1038
|
*/
|
|
1024
1039
|
.docx-editor-sdt-empty {
|
|
@@ -1057,17 +1072,46 @@ button.docx-editor-comment-body {
|
|
|
1057
1072
|
|
|
1058
1073
|
/*
|
|
1059
1074
|
* A whole cell shut by the control around it, and the cells of a whole row shut by the control
|
|
1060
|
-
* around the row, which carry no lock of their own. The same
|
|
1061
|
-
* border so the mark follows the cell rather than the text standing in it.
|
|
1075
|
+
* around the row, which carry no lock of their own. The same marks as above, outlined just inside
|
|
1076
|
+
* the cell border so the mark follows the cell rather than the text standing in it. A cell or a row
|
|
1077
|
+
* carries the control's opening XML only when a control stands around it.
|
|
1062
1078
|
*/
|
|
1063
1079
|
.docx-editor-tc-locked,
|
|
1064
1080
|
.docx-editor-tr-locked > .docx-editor-tc {
|
|
1065
|
-
background:
|
|
1066
|
-
|
|
1081
|
+
background-image: linear-gradient(
|
|
1082
|
+
var(--docx-editor-locked-background, rgb(255 235 59 / 50%)) 0 0
|
|
1083
|
+
);
|
|
1084
|
+
outline: var(--docx-editor-locked-outline, 1px solid #f9a825);
|
|
1067
1085
|
outline-offset: -1px;
|
|
1068
1086
|
cursor: not-allowed;
|
|
1069
1087
|
}
|
|
1070
1088
|
|
|
1089
|
+
.docx-editor-tc[data-sdt-prefix]:not(.docx-editor-tc-locked),
|
|
1090
|
+
.docx-editor-tr[data-sdt-prefix]:not(.docx-editor-tr-locked)
|
|
1091
|
+
> .docx-editor-tc:not(.docx-editor-tc-locked) {
|
|
1092
|
+
background-image: linear-gradient(
|
|
1093
|
+
var(--docx-editor-control-background, transparent) 0 0
|
|
1094
|
+
);
|
|
1095
|
+
outline: var(--docx-editor-control-outline, none);
|
|
1096
|
+
outline-offset: -1px;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/*
|
|
1100
|
+
* A lock shuts every control inside it (`spec/notes/contentControls.md`), so an open control there
|
|
1101
|
+
* is drawn as the shut content around it rather than as a place to type. A group is superseded by
|
|
1102
|
+
* the controls it holds, and draws them as open.
|
|
1103
|
+
*/
|
|
1104
|
+
[data-sdt-contents-locked] .docx-editor-sdt:not(.docx-editor-sdt-locked),
|
|
1105
|
+
[data-sdt-contents-locked] .docx-editor-sdt-block:not(.docx-editor-sdt-locked),
|
|
1106
|
+
[data-sdt-contents-locked]
|
|
1107
|
+
.docx-editor-tc[data-sdt-prefix]:not(.docx-editor-tc-locked),
|
|
1108
|
+
[data-sdt-contents-locked]
|
|
1109
|
+
.docx-editor-tr[data-sdt-prefix]:not(.docx-editor-tr-locked)
|
|
1110
|
+
> .docx-editor-tc:not(.docx-editor-tc-locked) {
|
|
1111
|
+
background-image: none;
|
|
1112
|
+
outline: none;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1071
1115
|
/*
|
|
1072
1116
|
* A preserved fragment inside a paragraph or inside a run. What it draws is the `display` the
|
|
1073
1117
|
* preservation rule gave it (`docx/importPolicy`), so the rule is read here as an attribute
|
|
@@ -1696,6 +1740,13 @@ button.docx-editor-comment-body {
|
|
|
1696
1740
|
border-top: 1px solid #e6e6e6;
|
|
1697
1741
|
}
|
|
1698
1742
|
|
|
1743
|
+
.docx-editor-menu-note {
|
|
1744
|
+
margin: 0 0 4px;
|
|
1745
|
+
padding: 6px 10px;
|
|
1746
|
+
border-bottom: 1px solid #e6e6e6;
|
|
1747
|
+
color: #5f6368;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1699
1750
|
@media (max-width: 720px) {
|
|
1700
1751
|
.docx-editor-popover,
|
|
1701
1752
|
.docx-editor-menu,
|