@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
|
@@ -5,7 +5,11 @@ import {
|
|
|
5
5
|
PluginKey,
|
|
6
6
|
TextSelection
|
|
7
7
|
} from "prosemirror-state";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
Mapping,
|
|
10
|
+
ReplaceAroundStep,
|
|
11
|
+
ReplaceStep
|
|
12
|
+
} from "prosemirror-transform";
|
|
9
13
|
import { docxSchema } from "../../schema/index.js";
|
|
10
14
|
import {
|
|
11
15
|
controlAttrs,
|
|
@@ -15,6 +19,7 @@ import {
|
|
|
15
19
|
OWN_CONTROL_ATTRS
|
|
16
20
|
} from "../../schema/controlAttrs.js";
|
|
17
21
|
import { displayOnly } from "../../schema/displayDerivation.js";
|
|
22
|
+
import { isEmptyRun } from "../../schema/emptyRuns.js";
|
|
18
23
|
import {
|
|
19
24
|
controlKept,
|
|
20
25
|
controlLifted,
|
|
@@ -27,6 +32,7 @@ import {
|
|
|
27
32
|
wrapperMarks,
|
|
28
33
|
wrappersOf
|
|
29
34
|
} from "../../schema/wrappers.js";
|
|
35
|
+
import { formatSourceAt, sameRun } from "../formatSource.js";
|
|
30
36
|
var controlContentsKey = new PluginKey(
|
|
31
37
|
"docxEditorControlContents"
|
|
32
38
|
);
|
|
@@ -82,29 +88,88 @@ function controlsContinued(doc, pos) {
|
|
|
82
88
|
(control) => kept(control) && !after.some((other) => other.eq(control))
|
|
83
89
|
);
|
|
84
90
|
}
|
|
85
|
-
function
|
|
91
|
+
function insertionOf(step) {
|
|
92
|
+
if (step instanceof ReplaceStep) {
|
|
93
|
+
return { from: step.from, to: step.to, slice: step.slice };
|
|
94
|
+
}
|
|
95
|
+
if (step instanceof ReplaceAroundStep) {
|
|
96
|
+
return { from: step.from, to: step.gapFrom, slice: step.slice };
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
function writtenStretches(transactions, continuing, storedBefore) {
|
|
86
101
|
const maps = transactions.flatMap((tr) => tr.mapping.maps);
|
|
87
|
-
const
|
|
102
|
+
const writes = { written: [], filled: [] };
|
|
88
103
|
let index = 0;
|
|
104
|
+
let stored = storedBefore;
|
|
89
105
|
for (const tr of transactions) {
|
|
90
106
|
const edit = userEdit(tr);
|
|
107
|
+
const restyles = stored === null || pasted(tr);
|
|
108
|
+
stored = tr.storedMarks;
|
|
91
109
|
tr.steps.forEach((step, stepIndex) => {
|
|
92
110
|
const at = index;
|
|
93
111
|
index += 1;
|
|
94
|
-
|
|
112
|
+
const insertion = edit ? insertionOf(step) : null;
|
|
113
|
+
if (insertion === null) return;
|
|
95
114
|
const doc = tr.docs[stepIndex] ?? tr.doc;
|
|
96
|
-
const found = stepControls(doc, step, continuing, maps.slice(0, at));
|
|
97
|
-
if (found === null) return;
|
|
98
115
|
const rest = new Mapping(maps.slice(at + 1));
|
|
99
|
-
const from = rest.map(
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
const from = rest.map(insertion.from, 1);
|
|
117
|
+
const writtenTo = Math.max(
|
|
118
|
+
from,
|
|
119
|
+
rest.map(insertion.from + insertion.slice.size, -1)
|
|
120
|
+
);
|
|
121
|
+
const fill = stepFill(doc, insertion);
|
|
122
|
+
if (fill !== null) {
|
|
123
|
+
const through = new Mapping(maps.slice(at));
|
|
124
|
+
writes.filled.push({
|
|
125
|
+
runs: {
|
|
126
|
+
from: through.map(fill.runs.from, 1),
|
|
127
|
+
to: through.map(fill.runs.to, -1)
|
|
128
|
+
},
|
|
129
|
+
written: { from, to: writtenTo },
|
|
130
|
+
run: fill.run,
|
|
131
|
+
restyles
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const found = step instanceof ReplaceStep ? stepControls(doc, step, continuing, maps.slice(0, at)) : null;
|
|
135
|
+
const into = found ?? fill;
|
|
136
|
+
if (into === null || into.controls.length === 0) return;
|
|
137
|
+
writes.written.push({
|
|
138
|
+
controls: into.controls,
|
|
139
|
+
first: into.first,
|
|
102
140
|
from,
|
|
103
|
-
to:
|
|
141
|
+
to: writtenTo
|
|
104
142
|
});
|
|
105
143
|
});
|
|
106
144
|
}
|
|
107
|
-
return
|
|
145
|
+
return writes;
|
|
146
|
+
}
|
|
147
|
+
function writesText(slice) {
|
|
148
|
+
let found = false;
|
|
149
|
+
slice.content.descendants((node) => {
|
|
150
|
+
if (node.isText) found = true;
|
|
151
|
+
return !found;
|
|
152
|
+
});
|
|
153
|
+
return found;
|
|
154
|
+
}
|
|
155
|
+
function pasted(tr) {
|
|
156
|
+
const event = tr.getMeta("uiEvent");
|
|
157
|
+
return event === "paste" || event === "drop";
|
|
158
|
+
}
|
|
159
|
+
function stepFill(doc, insertion) {
|
|
160
|
+
if (insertion.from !== insertion.to || !writesText(insertion.slice)) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const source = formatSourceAt(doc, insertion.from);
|
|
164
|
+
const runs = source?.fills ?? null;
|
|
165
|
+
const first = runs === null ? null : doc.nodeAt(runs.from);
|
|
166
|
+
if (source === null || runs === null || first === null) return null;
|
|
167
|
+
return {
|
|
168
|
+
runs,
|
|
169
|
+
run: source.run,
|
|
170
|
+
controls: controlsOf(first).filter(kept),
|
|
171
|
+
first
|
|
172
|
+
};
|
|
108
173
|
}
|
|
109
174
|
function stepControls(doc, step, continuing, before) {
|
|
110
175
|
if (step.from < step.to) {
|
|
@@ -203,6 +268,45 @@ function dropRefilled(tr, written) {
|
|
|
203
268
|
}
|
|
204
269
|
for (const { from, to } of refilled.reverse()) tr.delete(from, to);
|
|
205
270
|
}
|
|
271
|
+
function restyleFilled(tr, filled) {
|
|
272
|
+
const runType = docxSchema.marks.run;
|
|
273
|
+
for (const { written, run, restyles } of filled) {
|
|
274
|
+
if (!restyles) continue;
|
|
275
|
+
const from = tr.mapping.map(written.from, 1);
|
|
276
|
+
const $from = tr.doc.resolve(from);
|
|
277
|
+
if (!$from.parent.inlineContent) continue;
|
|
278
|
+
const to = Math.min(tr.mapping.map(written.to, -1), $from.end());
|
|
279
|
+
const differing = [];
|
|
280
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
281
|
+
if (!node.isText && !(node.isInline && node.type.allowsMarkType(runType))) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (sameRun(runType.isInSet(node.marks) ?? null, run)) return;
|
|
285
|
+
differing.push({
|
|
286
|
+
from: Math.max(pos, from),
|
|
287
|
+
to: Math.min(pos + node.nodeSize, to)
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
for (const range of differing) {
|
|
291
|
+
tr.removeMark(range.from, range.to, runType);
|
|
292
|
+
if (run !== null) tr.addMark(range.from, range.to, run);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function dropFilled(tr, filled) {
|
|
297
|
+
const runs = /* @__PURE__ */ new Map();
|
|
298
|
+
for (const { runs: stretch } of filled) {
|
|
299
|
+
const from = tr.mapping.map(stretch.from, 1);
|
|
300
|
+
const to = tr.mapping.map(stretch.to, -1);
|
|
301
|
+
if (from >= to) continue;
|
|
302
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
303
|
+
if (isEmptyRun(node)) runs.set(pos, pos + node.nodeSize);
|
|
304
|
+
return node.isBlock;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const lastFirst = [...runs].sort(([a], [b]) => b - a);
|
|
308
|
+
for (const [from, to] of lastFirst) tr.delete(from, to);
|
|
309
|
+
}
|
|
206
310
|
function continuingAfter(tr, written, previous) {
|
|
207
311
|
const caret = tr.selection instanceof TextSelection ? tr.selection.$cursor : null;
|
|
208
312
|
if (!caret || controlsContinued(tr.doc, caret.pos).length === 0) {
|
|
@@ -235,14 +339,17 @@ function controlContents() {
|
|
|
235
339
|
},
|
|
236
340
|
appendTransaction(transactions, oldState, newState) {
|
|
237
341
|
if (!transactions.some(userEdit)) return null;
|
|
238
|
-
const written = writtenStretches(
|
|
342
|
+
const { written, filled } = writtenStretches(
|
|
239
343
|
transactions,
|
|
240
|
-
controlContentsKey.getState(oldState) ?? null
|
|
344
|
+
controlContentsKey.getState(oldState) ?? null,
|
|
345
|
+
oldState.storedMarks
|
|
241
346
|
);
|
|
242
347
|
const previous = controlContentsKey.getState(newState) ?? null;
|
|
243
348
|
const tr = newState.tr.setMeta(controlKept, true);
|
|
244
349
|
const stored = keepControls(tr, written);
|
|
245
350
|
dropRefilled(tr, written);
|
|
351
|
+
restyleFilled(tr, filled);
|
|
352
|
+
dropFilled(tr, filled);
|
|
246
353
|
if (stored !== null && live?.composing !== true) {
|
|
247
354
|
tr.setStoredMarks(stored);
|
|
248
355
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Plugin } from "prosemirror-state";
|
|
2
|
+
/**
|
|
3
|
+
* Puts the caret after a run holding no characters when the blank it is drawn as is pressed.
|
|
4
|
+
*
|
|
5
|
+
* Text takes its formatting from the nearest character shown before the caret (`../formatSource`),
|
|
6
|
+
* so a caret dropped on the left half of the blank would carry on the words before it rather than
|
|
7
|
+
* fill the blank. After it, what is written there takes the blank's formatting and fills it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function emptyRunPointer(): Plugin;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/editor/plugins/emptyRunPointer.ts
|
|
2
|
+
import { Plugin, TextSelection } from "prosemirror-state";
|
|
3
|
+
import { isEmptyRun } from "../../schema/emptyRuns.js";
|
|
4
|
+
function emptyRunPointer() {
|
|
5
|
+
return new Plugin({
|
|
6
|
+
props: {
|
|
7
|
+
handleClickOn(view, _pos, node, nodePos, _event, direct) {
|
|
8
|
+
if (!direct || !isEmptyRun(node)) return false;
|
|
9
|
+
const { state } = view;
|
|
10
|
+
view.dispatch(
|
|
11
|
+
state.tr.setSelection(
|
|
12
|
+
TextSelection.create(state.doc, nodePos + node.nodeSize)
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
emptyRunPointer
|
|
22
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from "prosemirror-state";
|
|
2
|
+
/**
|
|
3
|
+
* The plugins that draw the inline leaves of a story and place the caret around them, shared by the
|
|
4
|
+
* body and every side story so a leaf behaves alike wherever it stands.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inlinePlugins(): Plugin[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/editor/plugins/inlinePlugins.ts
|
|
2
|
+
import { emptyRunPointer } from "./emptyRunPointer.js";
|
|
3
|
+
import { tabCaret } from "./tabCaret.js";
|
|
4
|
+
import { tabDecorations } from "./tabDecorations.js";
|
|
5
|
+
import { tabLayout } from "./tabLayout.js";
|
|
6
|
+
import { tabPointer } from "./tabPointer.js";
|
|
7
|
+
function inlinePlugins() {
|
|
8
|
+
return [
|
|
9
|
+
// Adjacent text tabs still need separate DOM ranges for layout and pointer selection
|
|
10
|
+
tabDecorations(),
|
|
11
|
+
tabPointer(),
|
|
12
|
+
tabLayout(),
|
|
13
|
+
tabCaret(),
|
|
14
|
+
emptyRunPointer()
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
inlinePlugins
|
|
19
|
+
};
|
|
@@ -6,6 +6,7 @@ import { EditorState } from "prosemirror-state";
|
|
|
6
6
|
import { tableEditing } from "prosemirror-tables";
|
|
7
7
|
import { docxClipboard } from "../clipboard/plugin.js";
|
|
8
8
|
import { editorDocument } from "../editorDocument.js";
|
|
9
|
+
import { caretFormat } from "../plugins/caretFormat.js";
|
|
9
10
|
import { compositionSelection } from "../plugins/compositionSelection.js";
|
|
10
11
|
import { controlContents } from "../plugins/controlContents.js";
|
|
11
12
|
import { controlLifecycle } from "../plugins/controlLifecycle.js";
|
|
@@ -14,13 +15,10 @@ import {
|
|
|
14
15
|
withDerivedDisplay
|
|
15
16
|
} from "../plugins/displayDerivation.js";
|
|
16
17
|
import { documentProtection } from "../plugins/documentProtection.js";
|
|
18
|
+
import { inlinePlugins } from "../plugins/inlinePlugins.js";
|
|
17
19
|
import { docxKeymap, NOTE_KEYS } from "../plugins/keymap.js";
|
|
18
20
|
import { lockedContent } from "../plugins/lockedContent.js";
|
|
19
21
|
import { numberingMarkers } from "../plugins/numberingDecorations.js";
|
|
20
|
-
import { tabCaret } from "../plugins/tabCaret.js";
|
|
21
|
-
import { tabDecorations } from "../plugins/tabDecorations.js";
|
|
22
|
-
import { tabLayout } from "../plugins/tabLayout.js";
|
|
23
|
-
import { tabPointer } from "../plugins/tabPointer.js";
|
|
24
22
|
var CAPABILITY_KEYS = {
|
|
25
23
|
"Mod-k": "link",
|
|
26
24
|
[NOTE_KEYS.footnote]: "note",
|
|
@@ -53,6 +51,7 @@ function storyEditorState({
|
|
|
53
51
|
documentProtection({ protection, author: null, editableComments: "own" }),
|
|
54
52
|
compositionSelection(),
|
|
55
53
|
controlContents(),
|
|
54
|
+
caretFormat(),
|
|
56
55
|
// A kind's own key rule stands ahead of the keymaps below: the base keymap answers
|
|
57
56
|
// Backspace and Enter for every document, so a rule about an empty story would never be
|
|
58
57
|
// asked behind it
|
|
@@ -63,10 +62,7 @@ function storyEditorState({
|
|
|
63
62
|
dropCursor(),
|
|
64
63
|
docxClipboard({ normalizers }),
|
|
65
64
|
tableEditing(),
|
|
66
|
-
|
|
67
|
-
tabPointer(),
|
|
68
|
-
tabLayout(),
|
|
69
|
-
tabCaret(),
|
|
65
|
+
...inlinePlugins(),
|
|
70
66
|
controlLifecycle(),
|
|
71
67
|
displayDerivation(),
|
|
72
68
|
numberingMarkers()
|
|
@@ -7,8 +7,11 @@
|
|
|
7
7
|
* to this editor are the ones that apply.
|
|
8
8
|
*
|
|
9
9
|
* The span is built from the same spec `toDOM` returns and rendered by the same
|
|
10
|
-
* renderer, so with the default fallbacks the DOM is
|
|
11
|
-
*
|
|
10
|
+
* renderer, so with the default fallbacks the DOM is what the schema would have
|
|
11
|
+
* drawn, but for one attribute: a run whose own properties paint a background says
|
|
12
|
+
* so, which draws a run holding no characters inside it as a blank
|
|
13
|
+
* (`styles/editor.css`). Its own properties are read apart from what it inherits by
|
|
14
|
+
* the import's reader, which the schema stands below.
|
|
12
15
|
*/
|
|
13
16
|
import type { MarkViewConstructor } from "prosemirror-view";
|
|
14
17
|
import type { FontFallbacks } from "../../styles/fontStack";
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
// src/editor/views/runMarkView.ts
|
|
2
2
|
import { DOMSerializer } from "prosemirror-model";
|
|
3
|
+
import { ownBackground } from "../../docx/runProps.js";
|
|
3
4
|
import { runMarkSpec } from "../../schema/index.js";
|
|
5
|
+
import { editorAttributes } from "../../styles/classNames.js";
|
|
4
6
|
function runMarkView(fontFallbacks) {
|
|
5
|
-
return (mark) =>
|
|
7
|
+
return (mark) => {
|
|
8
|
+
const view = DOMSerializer.renderSpec(
|
|
9
|
+
document,
|
|
10
|
+
runMarkSpec(mark.attrs, fontFallbacks)
|
|
11
|
+
);
|
|
12
|
+
if (ownBackground(mark) !== null && view.dom instanceof HTMLElement) {
|
|
13
|
+
view.dom.setAttribute(editorAttributes.paintsBackground, "");
|
|
14
|
+
}
|
|
15
|
+
return view;
|
|
16
|
+
};
|
|
6
17
|
}
|
|
7
18
|
export {
|
|
8
19
|
runMarkView
|
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" },
|
|
@@ -160,6 +162,7 @@ var NODE_ATTR_ROLES = {
|
|
|
160
162
|
// renumbered around an edit is the same reference it was
|
|
161
163
|
label: { role: "display", class: "derived" }
|
|
162
164
|
},
|
|
165
|
+
emptyRun: { xml: { role: "source", class: "preserved" } },
|
|
163
166
|
rawRunContent: {
|
|
164
167
|
xml: { role: "source", class: "preserved" },
|
|
165
168
|
// What the fragment is and how it is drawn are read off the preservation table when the
|
package/dist/schema/clipboard.js
CHANGED
|
@@ -167,6 +167,9 @@ var CLIPBOARD_NODES = {
|
|
|
167
167
|
},
|
|
168
168
|
toClipboardText: noteLabel
|
|
169
169
|
},
|
|
170
|
+
// A run holding no characters holds nothing a copy could carry, its formatting being a place to
|
|
171
|
+
// write rather than text
|
|
172
|
+
emptyRun: WRITES_NOTHING,
|
|
170
173
|
rawRunContent: PRESERVED_SPEC,
|
|
171
174
|
rawInline: PRESERVED_SPEC,
|
|
172
175
|
text: {
|
|
@@ -23,4 +23,4 @@ export declare function isPageBreak(brAttrs: unknown): boolean;
|
|
|
23
23
|
* ends the line where it stood, and `chip` draws a small box naming the element.
|
|
24
24
|
*/
|
|
25
25
|
export type PreservedDisplay = "hidden" | "text" | "break" | "chip";
|
|
26
|
-
export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "sdtBlock" | "sdtEmpty" | "sdtEmptyInline" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
|
|
26
|
+
export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "emptyRun" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "sdtBlock" | "sdtEmpty" | "sdtEmptyInline" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
|
|
@@ -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
|
}
|
|
@@ -1059,6 +1066,47 @@ var docxSchema = new Schema({
|
|
|
1059
1066
|
}
|
|
1060
1067
|
]
|
|
1061
1068
|
},
|
|
1069
|
+
/**
|
|
1070
|
+
* A run holding no characters (`<w:r>` with nothing but its properties and empty `w:t`).
|
|
1071
|
+
*
|
|
1072
|
+
* It wears the run mark, so its formatting stays in the model as a place text can be written
|
|
1073
|
+
* into (`editor/formatSource`). Where its own properties paint a background it is drawn as a
|
|
1074
|
+
* short blank in that colour, which Word does not draw (`spec/notes/formattingHierarchy.md`);
|
|
1075
|
+
* any other takes no width.
|
|
1076
|
+
*/
|
|
1077
|
+
emptyRun: {
|
|
1078
|
+
group: "inline",
|
|
1079
|
+
inline: true,
|
|
1080
|
+
atom: true,
|
|
1081
|
+
marks: "run wrapper",
|
|
1082
|
+
// It holds nothing to select: a click puts the caret beside it, where text written fills it
|
|
1083
|
+
selectable: false,
|
|
1084
|
+
attrs: {
|
|
1085
|
+
/**
|
|
1086
|
+
* The run as it came, written back as it stands while the run mark is the one it was read
|
|
1087
|
+
* with. null for one the file did not hold
|
|
1088
|
+
*/
|
|
1089
|
+
xml: { default: null }
|
|
1090
|
+
},
|
|
1091
|
+
toDOM(node) {
|
|
1092
|
+
return [
|
|
1093
|
+
"span",
|
|
1094
|
+
{
|
|
1095
|
+
class: editorClassNames.emptyRun,
|
|
1096
|
+
"data-xml": text(node.attrs.xml)
|
|
1097
|
+
}
|
|
1098
|
+
];
|
|
1099
|
+
},
|
|
1100
|
+
parseDOM: [
|
|
1101
|
+
{
|
|
1102
|
+
tag: `span.${editorClassNames.emptyRun}`,
|
|
1103
|
+
getAttrs: (dom) => {
|
|
1104
|
+
const xml = rawXml(dom, "data-xml", ELEMENT("r"));
|
|
1105
|
+
return xml === false ? false : { xml };
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
]
|
|
1109
|
+
},
|
|
1062
1110
|
/** The node that carries a non-run element inside a paragraph (a bookmark, for instance) exactly as it came */
|
|
1063
1111
|
rawInline: {
|
|
1064
1112
|
group: "inline",
|
|
@@ -1067,7 +1115,7 @@ var docxSchema = new Schema({
|
|
|
1067
1115
|
marks: "wrapper",
|
|
1068
1116
|
attrs: {
|
|
1069
1117
|
xml: { default: null },
|
|
1070
|
-
/** The local name of the element
|
|
1118
|
+
/** The local name of the element */
|
|
1071
1119
|
element: { default: null },
|
|
1072
1120
|
display: { default: "hidden" },
|
|
1073
1121
|
text: { default: null },
|