@portone/docx-editor 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +174 -0
- package/CONTRIBUTING.md +9 -1
- package/dist/DocxEditor.d.ts +6 -0
- package/dist/DocxEditor.js +12 -29
- package/dist/core.d.ts +23 -8
- package/dist/core.js +9 -4
- package/dist/docx/cloning.d.ts +38 -0
- package/dist/docx/cloning.js +74 -0
- package/dist/docx/commentOnlyChange.d.ts +14 -7
- package/dist/docx/commentOnlyChange.js +9 -139
- package/dist/docx/comments/constants.d.ts +3 -4
- package/dist/docx/comments/constants.js +4 -5
- package/dist/docx/comments/grammar.d.ts +86 -0
- package/dist/docx/comments/grammar.js +223 -0
- package/dist/docx/comments/parts.d.ts +52 -0
- package/dist/docx/comments/parts.js +279 -0
- package/dist/docx/comments/people.d.ts +11 -2
- package/dist/docx/comments/people.js +28 -106
- package/dist/docx/comments/policy.d.ts +7 -0
- package/dist/docx/comments/policy.js +43 -0
- package/dist/docx/comments/reading.d.ts +5 -3
- package/dist/docx/comments/reading.js +30 -29
- package/dist/docx/comments/writing.d.ts +19 -7
- package/dist/docx/comments/writing.js +105 -137
- package/dist/docx/documentSettings.d.ts +7 -0
- package/dist/docx/documentSettings.js +10 -2
- package/dist/docx/exportDocx.d.ts +40 -5
- package/dist/docx/exportDocx.js +71 -72
- package/dist/docx/exportRefs.d.ts +5 -2
- package/dist/docx/exportRefs.js +3 -1
- package/dist/docx/fidelity.d.ts +43 -0
- package/dist/docx/fidelity.js +64 -0
- package/dist/docx/formatting/attrs.d.ts +27 -0
- package/dist/docx/formatting/attrs.js +31 -0
- package/dist/docx/formatting/context.d.ts +31 -0
- package/dist/docx/formatting/context.js +42 -0
- package/dist/docx/formatting/direct.d.ts +6 -5
- package/dist/docx/formatting/direct.js +52 -81
- package/dist/docx/formatting/resolve.d.ts +45 -0
- package/dist/docx/formatting/resolve.js +140 -0
- package/dist/docx/formatting/runProperties.d.ts +93 -0
- package/dist/docx/formatting/runProperties.js +316 -0
- package/dist/docx/formatting/styles.js +3 -3
- package/dist/docx/formatting/tabStops.js +7 -22
- package/dist/docx/formatting.d.ts +4 -1
- package/dist/docx/formatting.js +4 -1
- package/dist/docx/headersFooters.js +13 -22
- package/dist/docx/identities.d.ts +67 -0
- package/dist/docx/identities.js +174 -0
- package/dist/docx/importDocx.d.ts +12 -1
- package/dist/docx/importDocx.js +72 -79
- package/dist/docx/importParagraph.d.ts +1 -1
- package/dist/docx/importParagraph.js +4 -3
- package/dist/docx/importTable.d.ts +1 -1
- package/dist/docx/importTable.js +17 -1
- package/dist/docx/invariants.d.ts +33 -0
- package/dist/docx/invariants.js +256 -0
- package/dist/docx/media.d.ts +6 -4
- package/dist/docx/media.js +6 -37
- package/dist/docx/newLists.d.ts +20 -0
- package/dist/docx/newLists.js +36 -0
- package/dist/docx/notes.js +6 -12
- package/dist/docx/numberingPlanner.d.ts +8 -0
- package/dist/docx/numberingPlanner.js +19 -0
- package/dist/docx/packageParts.d.ts +42 -0
- package/dist/docx/packageParts.js +135 -0
- package/dist/docx/pageGeometry.d.ts +2 -0
- package/dist/docx/pageGeometry.js +18 -9
- package/dist/docx/paraProps.d.ts +10 -22
- package/dist/docx/paraProps.js +75 -99
- package/dist/docx/partPlan.d.ts +36 -0
- package/dist/docx/partPlan.js +59 -0
- package/dist/docx/protectionPolicy.d.ts +127 -0
- package/dist/docx/protectionPolicy.js +169 -0
- package/dist/docx/relationships.d.ts +1 -1
- package/dist/docx/relationships.js +15 -15
- package/dist/docx/runProps.d.ts +9 -22
- package/dist/docx/runProps.js +15 -168
- package/dist/docx/scan.js +20 -52
- package/dist/docx/sdt.js +14 -37
- package/dist/docx/sdtProps.d.ts +8 -1
- package/dist/docx/sdtProps.js +10 -0
- package/dist/docx/serializeBlock.d.ts +2 -0
- package/dist/docx/serializeBlock.js +9 -7
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +25 -14
- package/dist/docx/serializeTable.js +63 -32
- package/dist/docx/session.d.ts +42 -14
- package/dist/docx/session.js +43 -17
- package/dist/docx/storyProjection.d.ts +36 -0
- package/dist/docx/storyProjection.js +23 -0
- package/dist/docx/tableFormatting/editing.js +130 -185
- package/dist/docx/tableFormatting/reading.d.ts +16 -6
- package/dist/docx/tableFormatting/reading.js +40 -20
- package/dist/docx/tableTemplate.js +37 -5
- package/dist/docx/theme.d.ts +0 -6
- package/dist/docx/theme.js +0 -8
- package/dist/download.d.ts +8 -5
- package/dist/download.js +2 -0
- package/dist/editor/clipboard/images.js +17 -3
- package/dist/editor/clipboard/inlineFormatting.d.ts +7 -0
- package/dist/editor/clipboard/inlineFormatting.js +20 -30
- package/dist/editor/commands/breakCommands.js +4 -3
- package/dist/editor/commands/canRunCommand.d.ts +2 -2
- package/dist/editor/commands/canRunCommand.js +1 -1
- package/dist/editor/commands/comments/editing.d.ts +6 -2
- package/dist/editor/commands/comments/editing.js +21 -36
- package/dist/editor/commands/exportQueries.d.ts +15 -0
- package/dist/editor/commands/exportQueries.js +14 -0
- package/dist/editor/commands/fidelityQueries.d.ts +12 -0
- package/dist/editor/commands/fidelityQueries.js +8 -0
- package/dist/editor/commands/formatting/editing.d.ts +2 -2
- package/dist/editor/commands/formatting/editing.js +26 -108
- package/dist/editor/commands/formatting/propertyCommands.d.ts +21 -0
- package/dist/editor/commands/formatting/propertyCommands.js +103 -0
- package/dist/editor/commands/formatting/shared.d.ts +3 -3
- package/dist/editor/commands/formatting/shared.js +5 -2
- package/dist/editor/commands/historyCommands.js +2 -1
- package/dist/editor/commands/indentCommands.js +5 -4
- package/dist/editor/commands/index.d.ts +11 -0
- package/dist/editor/commands/index.js +5 -0
- package/dist/editor/commands/linkCommands.js +5 -6
- package/dist/editor/commands/listCommands.js +8 -10
- package/dist/editor/commands/lockCommands.d.ts +7 -1
- package/dist/editor/commands/lockCommands.js +35 -37
- package/dist/editor/commands/paragraphCommands.js +28 -31
- package/dist/editor/commands/spacingCommands.js +1 -1
- package/dist/editor/commands/tabCommands.js +4 -3
- package/dist/editor/createEditor.d.ts +17 -29
- package/dist/editor/createEditor.js +61 -67
- package/dist/editor/documentStyles.d.ts +11 -35
- package/dist/editor/documentStyles.js +9 -52
- package/dist/editor/editorDocument.d.ts +56 -0
- package/dist/editor/editorDocument.js +74 -0
- package/dist/editor/externalClipboard.js +166 -33
- package/dist/editor/insertImage.js +4 -3
- package/dist/editor/insertTable.js +4 -3
- package/dist/editor/paragraphEdits.d.ts +11 -18
- package/dist/editor/paragraphEdits.js +7 -16
- package/dist/editor/plugins/displayDerivation.d.ts +47 -0
- package/dist/editor/plugins/displayDerivation.js +78 -0
- package/dist/editor/plugins/documentProtection.d.ts +3 -3
- package/dist/editor/plugins/imagePaste.js +4 -3
- package/dist/editor/plugins/keymap.js +18 -3
- package/dist/editor/plugins/lockedContent.d.ts +4 -4
- package/dist/editor/plugins/lockedContent.js +1 -1
- package/dist/editor/plugins/numberingDecorations.d.ts +5 -11
- package/dist/editor/plugins/numberingDecorations.js +7 -17
- package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
- package/dist/editor/plugins/paragraphDisplay.js +51 -0
- package/dist/editor/plugins/tabLayout.js +1 -1
- package/dist/editor/plugins/tableDisplay.d.ts +6 -0
- package/dist/editor/plugins/tableDisplay.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/model/format.d.ts +30 -8
- package/dist/model/format.js +35 -22
- package/dist/model/tabStops.d.ts +9 -0
- package/dist/model/tabStops.js +18 -0
- package/dist/numbering/listTemplate.js +49 -10
- package/dist/numbering/parseNumbering.d.ts +14 -1
- package/dist/numbering/parseNumbering.js +35 -22
- package/dist/numbering/writeNumbering.d.ts +3 -4
- package/dist/numbering/writeNumbering.js +14 -25
- package/dist/ooxml/childOrder.d.ts +34 -0
- package/dist/ooxml/childOrder.js +496 -0
- package/dist/ooxml/element.d.ts +65 -0
- package/dist/ooxml/element.js +68 -0
- package/dist/ooxml/errors.d.ts +3 -2
- package/dist/ooxml/fragment.d.ts +53 -0
- package/dist/ooxml/fragment.js +76 -0
- package/dist/ooxml/image.d.ts +4 -0
- package/dist/ooxml/image.js +3 -5
- package/dist/ooxml/names.d.ts +27 -0
- package/dist/ooxml/names.js +29 -0
- package/dist/ooxml/partSplice.d.ts +67 -0
- package/dist/ooxml/partSplice.js +169 -0
- package/dist/ooxml/precedence.d.ts +31 -0
- package/dist/ooxml/precedence.js +51 -0
- package/dist/ooxml/props.d.ts +112 -0
- package/dist/ooxml/props.js +214 -0
- package/dist/ooxml/simpleTypes.d.ts +103 -0
- package/dist/ooxml/simpleTypes.js +182 -0
- package/dist/ooxml/tabStops.js +8 -27
- package/dist/ooxml/tagScan.d.ts +34 -0
- package/dist/ooxml/tagScan.js +108 -0
- package/dist/ooxml/units.d.ts +25 -13
- package/dist/ooxml/units.js +65 -31
- package/dist/ooxml/xml.d.ts +52 -0
- package/dist/ooxml/xml.js +64 -5
- package/dist/page/blockKinds.d.ts +103 -0
- package/dist/page/blockKinds.js +11 -0
- package/dist/page/kinds/index.d.ts +6 -0
- package/dist/page/kinds/index.js +10 -0
- package/dist/page/kinds/paragraphKind.d.ts +10 -0
- package/dist/page/kinds/paragraphKind.js +71 -0
- package/dist/page/kinds/tableKind.d.ts +10 -0
- package/dist/page/kinds/tableKind.js +178 -0
- package/dist/page/measureBlocks.d.ts +3 -1
- package/dist/page/measureBlocks.js +24 -25
- package/dist/page/pageDecorations.d.ts +27 -28
- package/dist/page/pageDecorations.js +70 -151
- package/dist/page/pageLayout.d.ts +10 -62
- package/dist/page/pageLayout.js +60 -53
- package/dist/page/usePageLayout.d.ts +2 -2
- package/dist/page/usePageLayout.js +3 -11
- package/dist/schema/attrRoles.d.ts +42 -0
- package/dist/schema/attrRoles.js +141 -0
- package/dist/schema/displayDerivation.d.ts +82 -0
- package/dist/schema/displayDerivation.js +130 -0
- package/dist/schema/docxSchema.d.ts +9 -0
- package/dist/schema/docxSchema.js +237 -114
- package/dist/schema/editGuard.d.ts +99 -0
- package/dist/schema/editGuard.js +43 -0
- package/dist/schema/guards.d.ts +91 -0
- package/dist/schema/guards.js +108 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/locks.d.ts +17 -77
- package/dist/schema/locks.js +26 -70
- package/dist/schema/preservedGuards.d.ts +50 -0
- package/dist/schema/preservedGuards.js +80 -0
- package/dist/schema/protection.d.ts +17 -4
- package/dist/schema/protection.js +4 -2
- package/dist/schema/sourceEquality.d.ts +19 -0
- package/dist/schema/sourceEquality.js +39 -0
- package/dist/styles/inlineStyle.js +15 -6
- package/dist/table/cellFormatting.d.ts +8 -1
- package/dist/table/cellFormatting.js +10 -17
- package/dist/table/commands.d.ts +2 -2
- package/dist/table/commands.js +20 -18
- package/dist/table/format.d.ts +3 -0
- package/dist/table/format.js +3 -9
- package/dist/table/gridBorders.d.ts +14 -16
- package/dist/table/gridBorders.js +3 -41
- package/dist/table/index.d.ts +2 -2
- package/dist/table/merge.d.ts +4 -8
- package/dist/table/merge.js +5 -5
- package/package.json +10 -3
- package/dist/docx/comments/contentTypes.d.ts +0 -7
- package/dist/docx/comments/contentTypes.js +0 -38
- package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
- package/dist/docx/formatting/effectiveParagraph.js +0 -81
- package/dist/docx/propsXml.d.ts +0 -49
- package/dist/docx/propsXml.js +0 -302
- package/dist/docx/uniqueControls.d.ts +0 -14
- package/dist/docx/uniqueControls.js +0 -62
- package/dist/editor/plugins/bookmarkProtection.d.ts +0 -3
- package/dist/editor/plugins/bookmarkProtection.js +0 -28
- package/dist/editor/plugins/commentReservations.d.ts +0 -5
- package/dist/editor/plugins/commentReservations.js +0 -26
- package/dist/editor/plugins/noteProtection.d.ts +0 -3
- package/dist/editor/plugins/noteProtection.js +0 -25
- package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
- package/dist/editor/plugins/styledParagraphs.js +0 -65
- package/dist/page/tableMeasurements.d.ts +0 -10
- package/dist/page/tableMeasurements.js +0 -115
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/schema/displayDerivation.ts
|
|
2
|
+
import {
|
|
3
|
+
Mark
|
|
4
|
+
} from "prosemirror-model";
|
|
5
|
+
import { PluginKey } from "prosemirror-state";
|
|
6
|
+
import {
|
|
7
|
+
AddMarkStep,
|
|
8
|
+
AttrStep,
|
|
9
|
+
ReplaceAroundStep
|
|
10
|
+
} from "prosemirror-transform";
|
|
11
|
+
import { attrRole } from "./attrRoles.js";
|
|
12
|
+
function ownersByType(schema, derivers) {
|
|
13
|
+
const owners = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const deriver of derivers) {
|
|
15
|
+
for (const name of deriver.nodeTypes) {
|
|
16
|
+
const type = schema.nodes[name];
|
|
17
|
+
if (type === void 0 || type.isInline) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`${deriver.name} answers for ${name}, which the walk over the blocks never reaches`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const owning = owners.get(name) ?? [];
|
|
23
|
+
owning.push(deriver);
|
|
24
|
+
owners.set(name, owning);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return owners;
|
|
28
|
+
}
|
|
29
|
+
function displayLaidOver(standing, derived) {
|
|
30
|
+
const attrs = { ...standing.attrs };
|
|
31
|
+
for (const [name, value] of Object.entries(derived)) {
|
|
32
|
+
if (attrRole(standing.type, name) === "display") attrs[name] = value;
|
|
33
|
+
}
|
|
34
|
+
return attrs;
|
|
35
|
+
}
|
|
36
|
+
function nodeStanding(doc, pos) {
|
|
37
|
+
const node = doc.nodeAt(pos);
|
|
38
|
+
if (node === null) throw new Error(`no node stands at ${pos}`);
|
|
39
|
+
return node;
|
|
40
|
+
}
|
|
41
|
+
function deriveDisplay(transform, context, derivers, previousOf) {
|
|
42
|
+
const owners = ownersByType(transform.doc.type.schema, derivers);
|
|
43
|
+
const spots = [];
|
|
44
|
+
transform.doc.descendants((node, pos) => {
|
|
45
|
+
const owning = owners.get(node.type.name);
|
|
46
|
+
if (owning !== void 0) spots.push({ pos, owners: owning });
|
|
47
|
+
return !node.isTextblock;
|
|
48
|
+
});
|
|
49
|
+
for (const spot of spots) {
|
|
50
|
+
for (const deriver of spot.owners) {
|
|
51
|
+
const node = nodeStanding(transform.doc, spot.pos);
|
|
52
|
+
const derived = deriver.derive(
|
|
53
|
+
node,
|
|
54
|
+
spot.pos,
|
|
55
|
+
transform.doc,
|
|
56
|
+
context,
|
|
57
|
+
previousOf(node, spot.pos)
|
|
58
|
+
);
|
|
59
|
+
for (const { pos, attrs, mark: target } of derived) {
|
|
60
|
+
const standing = nodeStanding(transform.doc, pos);
|
|
61
|
+
if (target !== void 0) {
|
|
62
|
+
const mark = target.type.isInSet(standing.marks);
|
|
63
|
+
if (!standing.isInline || mark === void 0) continue;
|
|
64
|
+
const end = pos + standing.nodeSize - transform.doc.resolve(pos).textOffset;
|
|
65
|
+
if (target.to <= pos || target.to > end) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"a display mark update must stay within its inline node"
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
const next2 = target.type.create(displayLaidOver(mark, attrs));
|
|
71
|
+
if (!mark.eq(next2)) {
|
|
72
|
+
transform.step(new AddMarkStep(pos, target.to, next2));
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const next = displayLaidOver(standing, attrs);
|
|
77
|
+
if (!standing.hasMarkup(standing.type, next, standing.marks)) {
|
|
78
|
+
transform.setNodeMarkup(pos, null, next);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var displayOnly = new PluginKey("docxEditorDisplayOnly");
|
|
85
|
+
function sameOutsideDisplay(type, was, now) {
|
|
86
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(was), ...Object.keys(now)]);
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
if (attrRole(type, name) === "display") continue;
|
|
89
|
+
if (was[name] !== now[name]) return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
function rewrittenNode(step, doc) {
|
|
94
|
+
const was = doc.nodeAt(step.from);
|
|
95
|
+
const now = step.slice.content.firstChild;
|
|
96
|
+
if (was === null || now === null || step.slice.content.childCount !== 1 || step.slice.openStart !== 0 || step.slice.openEnd !== 0 || now.content.size !== 0 || step.insert !== 1 || step.gapFrom !== step.from + 1 || step.to !== step.from + was.nodeSize || step.gapTo !== step.to - 1) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return { was, now };
|
|
100
|
+
}
|
|
101
|
+
function changesOnlyDisplayAttrs(step, doc) {
|
|
102
|
+
if (step instanceof AddMarkStep) {
|
|
103
|
+
let touched = false;
|
|
104
|
+
let allowed = true;
|
|
105
|
+
doc.nodesBetween(step.from, step.to, (node, _pos, parent) => {
|
|
106
|
+
if (!node.isInline) return true;
|
|
107
|
+
if (!parent?.type.allowsMarkType(step.mark.type)) return false;
|
|
108
|
+
touched = true;
|
|
109
|
+
const previous = step.mark.type.isInSet(node.marks);
|
|
110
|
+
if (!previous || !sameOutsideDisplay(step.mark.type, previous.attrs, step.mark.attrs))
|
|
111
|
+
allowed = false;
|
|
112
|
+
return false;
|
|
113
|
+
});
|
|
114
|
+
return touched && allowed;
|
|
115
|
+
}
|
|
116
|
+
if (step instanceof AttrStep) {
|
|
117
|
+
const node = doc.nodeAt(step.pos);
|
|
118
|
+
return node !== null && attrRole(node.type, step.attr) === "display";
|
|
119
|
+
}
|
|
120
|
+
if (!(step instanceof ReplaceAroundStep)) return false;
|
|
121
|
+
const rewritten = rewrittenNode(step, doc);
|
|
122
|
+
if (rewritten === null) return false;
|
|
123
|
+
const { was, now } = rewritten;
|
|
124
|
+
return was.type === now.type && Mark.sameSet(was.marks, now.marks) && sameOutsideDisplay(was.type, was.attrs, now.attrs);
|
|
125
|
+
}
|
|
126
|
+
export {
|
|
127
|
+
changesOnlyDisplayAttrs,
|
|
128
|
+
deriveDisplay,
|
|
129
|
+
displayOnly
|
|
130
|
+
};
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ProseMirror schema joining preserved DOCX fragments with validated display values. Original XML
|
|
3
3
|
* remains on nodes and marks so untouched content can round-trip verbatim.
|
|
4
|
+
*
|
|
5
|
+
* Every block sits in one of two groups beside `block`. A `modelled` block is one the editor
|
|
6
|
+
* takes apart and writes back out itself, so the writer decides what it says; a `preserved` one
|
|
7
|
+
* goes back out as the XML it arrived as. Which of the two a block is decides how it is written
|
|
8
|
+
* (`docx/serializeBlock`) and how a submitted file is compared against the original
|
|
9
|
+
* (`docx/storyProjection`), so a new block node has to name one of them.
|
|
10
|
+
*
|
|
11
|
+
* `./attrRoles` declares each attr's provenance and comparison role; `attrClasses.test.ts`
|
|
12
|
+
* checks coverage. The plugin guide defines the supported public surface.
|
|
4
13
|
*/
|
|
5
14
|
import { Schema } from "prosemirror-model";
|
|
6
15
|
export { imageNodeSpec, runMarkSpec } from "./rendering";
|