@portone/docx-editor 0.6.3 → 0.6.4
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 +29 -0
- package/dist/docx/comments/writing.d.ts +8 -0
- package/dist/docx/comments/writing.js +9 -2
- package/dist/docx/headersFooters.d.ts +7 -0
- package/dist/docx/headersFooters.js +4 -1
- package/dist/docx/identities.d.ts +4 -3
- package/dist/docx/identities.js +14 -1
- package/dist/docx/importDocx.js +2 -0
- package/dist/docx/importParagraph.d.ts +4 -0
- package/dist/docx/importParagraph.js +2 -0
- package/dist/docx/importSdtBlock.d.ts +2 -3
- package/dist/docx/importSdtBlock.js +7 -16
- package/dist/docx/invariants.js +60 -3
- package/dist/docx/numberingPlanner.d.ts +3 -0
- package/dist/docx/numberingPlanner.js +8 -2
- package/dist/docx/packageParts.d.ts +9 -0
- package/dist/docx/packageParts.js +16 -0
- package/dist/docx/packagePrefixes.d.ts +12 -0
- package/dist/docx/packagePrefixes.js +18 -0
- package/dist/docx/partPlan.js +3 -5
- package/dist/docx/sdt.d.ts +27 -0
- package/dist/docx/sdt.js +14 -1
- package/dist/docx/serializeBlock.js +4 -3
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +6 -1
- package/dist/docx/serializeSdtBlock.d.ts +0 -8
- package/dist/docx/serializeSdtBlock.js +1 -5
- package/dist/docx/storyParts.d.ts +3 -0
- package/dist/docx/storyParts.js +4 -1
- package/dist/docx/wrappers.d.ts +23 -8
- package/dist/docx/wrappers.js +33 -2
- package/dist/editor/blockControlEdits.d.ts +2 -2
- package/dist/editor/blockControlEdits.js +6 -6
- package/dist/editor/commands/lockCommands.js +25 -5
- package/dist/editor/inlineControlEdits.d.ts +20 -0
- package/dist/editor/inlineControlEdits.js +69 -0
- package/dist/editor/plugins/keymap.js +18 -7
- package/dist/ooxml/element.js +3 -2
- package/dist/ooxml/errors.d.ts +11 -0
- package/dist/ooxml/fragment.js +3 -2
- package/dist/ooxml/names.d.ts +4 -0
- package/dist/ooxml/names.js +8 -2
- package/dist/ooxml/partPrefixes.d.ts +21 -0
- package/dist/ooxml/partPrefixes.js +164 -0
- package/dist/ooxml/partSplice.d.ts +6 -1
- package/dist/ooxml/partSplice.js +30 -10
- package/dist/ooxml/tagScan.d.ts +24 -2
- package/dist/ooxml/tagScan.js +26 -7
- package/dist/ooxml/xml.d.ts +8 -0
- package/dist/ooxml/xml.js +27 -5
- package/dist/schema/attrRoles.js +11 -0
- package/dist/schema/clipboard.js +2 -0
- package/dist/schema/controlAttrs.d.ts +27 -13
- package/dist/schema/controlAttrs.js +14 -6
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +60 -5
- package/dist/schema/locks.d.ts +37 -5
- package/dist/schema/locks.js +33 -15
- package/dist/styles/classNames.d.ts +2 -0
- package/dist/styles/classNames.js +2 -0
- package/dist/styles.css +13 -0
- package/package.json +1 -1
|
@@ -14,11 +14,3 @@ import type { ExportRefs } from "./exportRefs";
|
|
|
14
14
|
/** How the level around a control writes one block of it */
|
|
15
15
|
export type BlockWriter = (block: PMNode, refs: ExportRefs) => string;
|
|
16
16
|
export declare function serializeSdtBlock(node: PMNode, refs: ExportRefs, writeBlock: BlockWriter): string;
|
|
17
|
-
/**
|
|
18
|
-
* A control holding nothing, which is the same opening around a content tag with nothing in it.
|
|
19
|
-
*
|
|
20
|
-
* A control that arrived writing no content element at all gains one here. The two shapes state
|
|
21
|
-
* the same thing - §17.5.2.34 makes the element a cache of what stood inside - and only a control
|
|
22
|
-
* something rewrote reaches this at all; one nobody touched goes out as the bytes it arrived as.
|
|
23
|
-
*/
|
|
24
|
-
export declare function serializeSdtEmpty(node: PMNode): string;
|
|
@@ -6,10 +6,6 @@ function serializeSdtBlock(node, refs, writeBlock) {
|
|
|
6
6
|
node.children.map((block) => writeBlock(block, refs)).join("")
|
|
7
7
|
);
|
|
8
8
|
}
|
|
9
|
-
function serializeSdtEmpty(node) {
|
|
10
|
-
return sdtXml(node.attrs.sdtPrefix, "");
|
|
11
|
-
}
|
|
12
9
|
export {
|
|
13
|
-
serializeSdtBlock
|
|
14
|
-
serializeSdtEmpty
|
|
10
|
+
serializeSdtBlock
|
|
15
11
|
};
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Node as PMNode } from "prosemirror-model";
|
|
9
9
|
import type { DocxExportErrorCode, ExportPartName, ExportProblemReason } from "../ooxml/errors";
|
|
10
|
+
import { type RootDeclarations } from "../ooxml/partSplice";
|
|
10
11
|
import { type StoryKey, type StoryKind } from "../schema/stories";
|
|
11
12
|
import { type StoryToSettle } from "./identities";
|
|
12
13
|
import type { PartPlanner } from "./partPlan";
|
|
@@ -121,6 +122,8 @@ export interface StoryPartProblem {
|
|
|
121
122
|
* the content types part, which the export does not write from nothing.
|
|
122
123
|
*/
|
|
123
124
|
export declare function storyEntriesProblems(part: StoryEntriesPart, doc: PMNode, session: SessionStore): readonly StoryPartProblem[];
|
|
125
|
+
/** What a rewritten or created part declares: every entry this writer puts out is spelled under `w` */
|
|
126
|
+
export declare const ENTRY_MARKUP: RootDeclarations;
|
|
124
127
|
/**
|
|
125
128
|
* A planner for a part holding one entry per story.
|
|
126
129
|
*
|
package/dist/docx/storyParts.js
CHANGED
|
@@ -170,7 +170,9 @@ function storyEntriesProblems(part, doc, session) {
|
|
|
170
170
|
}
|
|
171
171
|
];
|
|
172
172
|
}
|
|
173
|
-
var ENTRY_MARKUP = {
|
|
173
|
+
var ENTRY_MARKUP = {
|
|
174
|
+
namespaces: { w: NAMESPACES.w }
|
|
175
|
+
};
|
|
174
176
|
var XML_DECLARATION = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
175
177
|
function containerOf(part, id) {
|
|
176
178
|
const name = wName(part.entry);
|
|
@@ -302,6 +304,7 @@ function storyEntriesPlanner(part) {
|
|
|
302
304
|
};
|
|
303
305
|
}
|
|
304
306
|
export {
|
|
307
|
+
ENTRY_MARKUP,
|
|
305
308
|
EVERY_STORY_CHANGE,
|
|
306
309
|
rewrittenStories,
|
|
307
310
|
storyChangesOf,
|
package/dist/docx/wrappers.d.ts
CHANGED
|
@@ -7,18 +7,20 @@
|
|
|
7
7
|
* export rebuilds it from the marks (`schema/wrappers` holds the order, `docx/importParagraph`
|
|
8
8
|
* reads, `docx/serializeParagraph` writes).
|
|
9
9
|
*
|
|
10
|
-
* A kind knows
|
|
11
|
-
* what opens
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `schema/
|
|
16
|
-
* and
|
|
10
|
+
* A kind knows four things and nothing about either walk: what a mark reads out of one element,
|
|
11
|
+
* what one holding nothing opens as instead, what opens the element again, and what closes it. A
|
|
12
|
+
* wrapper holding nothing leaves a mark nothing to sit on, so the kind says whether it has a node
|
|
13
|
+
* of its own for that shape. Tracked changes (`w:ins`, `w:del`) and simple fields (`w:fldSimple`)
|
|
14
|
+
* are wrappers of the same shape. Registering one is an entry here and a mark spec in
|
|
15
|
+
* `schema/docxSchema` carrying `WRAPPER_ATTRS`; its attrs also want a row in `schema/attrRoles`,
|
|
16
|
+
* and two test lists name the kinds outright (`WRAPPERS_READS` in `schema/attrClasses.test.ts`,
|
|
17
|
+
* the kind list in `schema/wrappers.test.ts`). Neither paragraph walk and neither policy table has
|
|
18
|
+
* to be touched.
|
|
17
19
|
*
|
|
18
20
|
* The opening tag is the verbatim string the file wrote wherever there is one, so a wrapper nobody
|
|
19
21
|
* edited goes back out byte for byte; only the closing tag is written from scratch.
|
|
20
22
|
*/
|
|
21
|
-
import type { Mark } from "prosemirror-model";
|
|
23
|
+
import type { Mark, Node as PMNode } from "prosemirror-model";
|
|
22
24
|
import type { ExportRefs } from "./exportRefs";
|
|
23
25
|
import type { ImportSources } from "./importParagraph";
|
|
24
26
|
/** A wrapper read off the file: the mark its content wears, and the element that content stands in */
|
|
@@ -37,6 +39,14 @@ export interface WrapperKind {
|
|
|
37
39
|
* not write back ourselves, which leaves the element preserved whole where it stood.
|
|
38
40
|
*/
|
|
39
41
|
read(el: Element, depth: number, sources: ImportSources): WrapperReading | null;
|
|
42
|
+
/**
|
|
43
|
+
* One of these the file wrote with nothing inside it as the inline node it stands as, wearing
|
|
44
|
+
* the `wrappers` it stands inside. null for an element holding something, and for a kind with no
|
|
45
|
+
* node of that shape, which leaves the wrapper preserved whole where it stood.
|
|
46
|
+
*/
|
|
47
|
+
readEmpty(el: Element, wrappers: readonly Mark[]): PMNode | null;
|
|
48
|
+
/** That node back out as the wrapper it came from, and null for a node of another kind */
|
|
49
|
+
writeEmpty(node: PMNode): string | null;
|
|
40
50
|
/** The opening XML this mark goes back out as */
|
|
41
51
|
open(mark: Mark, refs: ExportRefs): string;
|
|
42
52
|
/** What closes it again */
|
|
@@ -57,6 +67,11 @@ export declare function nextKey(kind: string, el: Element): number;
|
|
|
57
67
|
export declare const WRAPPER_KINDS: readonly WrapperKind[];
|
|
58
68
|
/** The kind this element is one of, undefined for an element no kind reads */
|
|
59
69
|
export declare function wrapperKindFor(el: Element): WrapperKind | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* One inline node a wrapper holding nothing opened as, back out as that wrapper. null for every
|
|
72
|
+
* other inline node, which is what the paragraph writer goes on to render as a run.
|
|
73
|
+
*/
|
|
74
|
+
export declare function emptyWrapperXml(node: PMNode): string | null;
|
|
60
75
|
/**
|
|
61
76
|
* Whether a wrapper of this kind may be read inside the wrappers already around it.
|
|
62
77
|
*
|
package/dist/docx/wrappers.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
// src/docx/wrappers.ts
|
|
2
2
|
import { DocxExportError } from "../ooxml/errors.js";
|
|
3
3
|
import { docxSchema } from "../schema/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
controlAttrs,
|
|
6
|
+
isEmptyInlineControl,
|
|
7
|
+
OWN_CONTROL_ATTRS
|
|
8
|
+
} from "../schema/controlAttrs.js";
|
|
5
9
|
import { readHyperlinkWrapper, relIdIn, withRelId } from "./hyperlink.js";
|
|
6
10
|
import {
|
|
7
11
|
controlFactsFrom,
|
|
12
|
+
readSdtContents,
|
|
8
13
|
readSdtWrapper,
|
|
9
14
|
SDT_CLOSING_XML,
|
|
10
|
-
sdtOpeningXml
|
|
15
|
+
sdtOpeningXml,
|
|
16
|
+
serializeEmptyControl
|
|
11
17
|
} from "./sdt.js";
|
|
12
18
|
var counts = /* @__PURE__ */ new WeakMap();
|
|
13
19
|
function nextKey(kind, el) {
|
|
@@ -32,6 +38,19 @@ var SDT = {
|
|
|
32
38
|
content: wrapper.content
|
|
33
39
|
};
|
|
34
40
|
},
|
|
41
|
+
readEmpty(el, wrappers) {
|
|
42
|
+
const read = readSdtContents(el);
|
|
43
|
+
if (read?.kind !== "nothing") return null;
|
|
44
|
+
return docxSchema.nodes.sdtEmptyInline.create(
|
|
45
|
+
{
|
|
46
|
+
key: nextKey(SDT.mark, el),
|
|
47
|
+
...controlAttrs(OWN_CONTROL_ATTRS, read.facts)
|
|
48
|
+
},
|
|
49
|
+
null,
|
|
50
|
+
wrappers
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
writeEmpty: (node) => isEmptyInlineControl(node) ? serializeEmptyControl(node) : null,
|
|
35
54
|
open: (mark) => sdtOpeningXml(mark.attrs.sdtPrefix),
|
|
36
55
|
close: () => SDT_CLOSING_XML
|
|
37
56
|
};
|
|
@@ -51,6 +70,10 @@ var LINK = {
|
|
|
51
70
|
content: el
|
|
52
71
|
};
|
|
53
72
|
},
|
|
73
|
+
// A link holding nothing is a link to nowhere the user could stand, and there is no node for it
|
|
74
|
+
// to open as: it stays the preserved element it always was, wearing the wrappers around it
|
|
75
|
+
readEmpty: () => null,
|
|
76
|
+
writeEmpty: () => null,
|
|
54
77
|
open(mark, refs) {
|
|
55
78
|
const prefix = mark.attrs.linkPrefix;
|
|
56
79
|
const original = typeof prefix === "string" ? prefix : null;
|
|
@@ -81,6 +104,13 @@ var WRAPPER_KINDS = [SDT, LINK];
|
|
|
81
104
|
function wrapperKindFor(el) {
|
|
82
105
|
return WRAPPER_KINDS.find((kind) => kind.element === el.localName);
|
|
83
106
|
}
|
|
107
|
+
function emptyWrapperXml(node) {
|
|
108
|
+
for (const kind of WRAPPER_KINDS) {
|
|
109
|
+
const xml = kind.writeEmpty(node);
|
|
110
|
+
if (xml !== null) return xml;
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
84
114
|
function wrapperFits(kind, wrappers) {
|
|
85
115
|
const type = docxSchema.marks[kind.mark];
|
|
86
116
|
if (!type.excludes(type)) return true;
|
|
@@ -98,6 +128,7 @@ function wrapperKindOf(mark) {
|
|
|
98
128
|
}
|
|
99
129
|
export {
|
|
100
130
|
WRAPPER_KINDS,
|
|
131
|
+
emptyWrapperXml,
|
|
101
132
|
nextKey,
|
|
102
133
|
wrapperFits,
|
|
103
134
|
wrapperKindFor,
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
import { type Command } from "prosemirror-state";
|
|
11
11
|
export declare const removeEmptyBlockControl: Command;
|
|
12
12
|
/** Backspace passing over the controls holding nothing that stand before the caret */
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const skipEmptyBlockControlBefore: Command;
|
|
14
14
|
/** Delete passing over the controls holding nothing that stand after the caret */
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const skipEmptyBlockControlAfter: Command;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/editor/blockControlEdits.ts
|
|
2
2
|
import { Selection, TextSelection } from "prosemirror-state";
|
|
3
3
|
import { docxSchema } from "../schema/index.js";
|
|
4
|
-
import { isBlockControl,
|
|
4
|
+
import { isBlockControl, isEmptyBlockControl } from "../schema/controlAttrs.js";
|
|
5
5
|
import { guardedCommand } from "../schema/guards.js";
|
|
6
6
|
function soleEmptyControl($cursor) {
|
|
7
7
|
if ($cursor.parent.content.size > 0) return null;
|
|
@@ -42,7 +42,7 @@ function emptyRunBeside(selection, dir) {
|
|
|
42
42
|
let pos = dir < 0 ? $cursor.before(depth) : $cursor.after(depth);
|
|
43
43
|
let index = first;
|
|
44
44
|
let sibling = container.maybeChild(index);
|
|
45
|
-
while (sibling &&
|
|
45
|
+
while (sibling && isEmptyBlockControl(sibling)) {
|
|
46
46
|
pos += dir * sibling.nodeSize;
|
|
47
47
|
index += dir;
|
|
48
48
|
sibling = container.maybeChild(index);
|
|
@@ -70,10 +70,10 @@ function skipEmptyControls(dir) {
|
|
|
70
70
|
move(state, dispatch, view) || emptyRunBeside(state.selection, dir) !== null
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
|
-
var
|
|
74
|
-
var
|
|
73
|
+
var skipEmptyBlockControlBefore = skipEmptyControls(-1);
|
|
74
|
+
var skipEmptyBlockControlAfter = skipEmptyControls(1);
|
|
75
75
|
export {
|
|
76
76
|
removeEmptyBlockControl,
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
skipEmptyBlockControlAfter,
|
|
78
|
+
skipEmptyBlockControlBefore
|
|
79
79
|
};
|
|
@@ -5,11 +5,16 @@ import {
|
|
|
5
5
|
import { namesNothing, newControlId } from "../../docx/sdt.js";
|
|
6
6
|
import { lockedControlPrefix, withContentLock } from "../../docx/sdtProps.js";
|
|
7
7
|
import { docxSchema } from "../../schema/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
controlAttrsOf,
|
|
10
|
+
isEmptyInlineControl
|
|
11
|
+
} from "../../schema/controlAttrs.js";
|
|
9
12
|
import { guardedCommand, openStretches } from "../../schema/guards.js";
|
|
10
13
|
import {
|
|
11
14
|
carriesLock,
|
|
12
15
|
controlSpans,
|
|
16
|
+
coversWhole,
|
|
17
|
+
emptyControlsIn,
|
|
13
18
|
selectionShut,
|
|
14
19
|
unlockAllowed
|
|
15
20
|
} from "../../schema/locks.js";
|
|
@@ -56,6 +61,11 @@ function stretchIn(block, reach) {
|
|
|
56
61
|
return from < to ? { from, to } : null;
|
|
57
62
|
}
|
|
58
63
|
function wrapperDepthOver(block, stretch, replaced = null) {
|
|
64
|
+
const shared = sharedWrappers(childrenUnder(block, stretch));
|
|
65
|
+
const at = replaced === null ? -1 : shared.findIndex((wrapper) => wrapper.eq(replaced));
|
|
66
|
+
return innermostDepth(at === -1 ? shared : shared.slice(0, at)) + 1;
|
|
67
|
+
}
|
|
68
|
+
function childrenUnder(block, stretch) {
|
|
59
69
|
const covered = [];
|
|
60
70
|
block.node.forEach((child, offset) => {
|
|
61
71
|
const from = block.start + offset;
|
|
@@ -63,9 +73,11 @@ function wrapperDepthOver(block, stretch, replaced = null) {
|
|
|
63
73
|
covered.push(child);
|
|
64
74
|
}
|
|
65
75
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
return covered;
|
|
77
|
+
}
|
|
78
|
+
function nothingToLock(block, stretch) {
|
|
79
|
+
const covered = childrenUnder(block, stretch);
|
|
80
|
+
return covered.length > 0 && covered.every(isEmptyInlineControl);
|
|
69
81
|
}
|
|
70
82
|
function gapsIn(stretch, spans) {
|
|
71
83
|
const gaps = [];
|
|
@@ -128,7 +140,9 @@ function blockLockEdits(state, block, spans, reach) {
|
|
|
128
140
|
return mark ? [{ from: span.from, to: span.to, mark, replaces: span.mark }] : [];
|
|
129
141
|
}
|
|
130
142
|
);
|
|
131
|
-
const fresh = open(
|
|
143
|
+
const fresh = open(
|
|
144
|
+
gapsIn(stretch, spans).filter((gap) => !nothingToLock(block, gap))
|
|
145
|
+
).map((gap) => ({
|
|
132
146
|
...gap,
|
|
133
147
|
mark: lockedControlMark(newControlId(), wrapperDepthOver(block, gap))
|
|
134
148
|
}));
|
|
@@ -152,6 +166,12 @@ function selectionLockDetail(state) {
|
|
|
152
166
|
if (opened) containers.set(pos, opened);
|
|
153
167
|
if (!node.isTextblock) return true;
|
|
154
168
|
const block = { node, start: pos + 1 };
|
|
169
|
+
for (const control of emptyControlsIn(block)) {
|
|
170
|
+
const lifted = unlockedContainerAttrs(control.node);
|
|
171
|
+
if (lifted && coversWhole(reach, control.span)) {
|
|
172
|
+
containers.set(control.span.from, lifted);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
155
175
|
const controls = controlSpans(block);
|
|
156
176
|
spans.push(
|
|
157
177
|
...liftable(
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the editor does beside a content control the file wrote inside a paragraph with nothing in
|
|
3
|
+
* it (`docx/wrappers`): Backspace and Delete take away what stands on the far side of it, as if the
|
|
4
|
+
* control were not there (`spec/notes/contentControls.md`).
|
|
5
|
+
*
|
|
6
|
+
* Such a control draws nothing and takes no width, so a key that took it away would take a phrase
|
|
7
|
+
* the file keeps with nothing on screen to show what went, and a key that merely passed the caret
|
|
8
|
+
* over it would be a keystroke the user sees nothing at all come of. So the two are one keystroke:
|
|
9
|
+
* the caret passes the whole run of them and the same key takes the character beyond. The control
|
|
10
|
+
* itself goes when a stretch covering it is taken away, which is the deletion clause's question
|
|
11
|
+
* (`schema/locks`).
|
|
12
|
+
*
|
|
13
|
+
* Between blocks the rule is `./blockControlEdits`'s, where passing the caret to another line is
|
|
14
|
+
* something the user can see and the key stops there.
|
|
15
|
+
*/
|
|
16
|
+
import { type Command } from "prosemirror-state";
|
|
17
|
+
/** Backspace beside the controls holding nothing that stand before the caret */
|
|
18
|
+
export declare const deleteBeyondEmptyControlsBefore: Command;
|
|
19
|
+
/** Delete beside the controls holding nothing that stand after the caret */
|
|
20
|
+
export declare const deleteBeyondEmptyControlsAfter: Command;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/editor/inlineControlEdits.ts
|
|
2
|
+
import {
|
|
3
|
+
chainCommands,
|
|
4
|
+
joinBackward,
|
|
5
|
+
joinForward,
|
|
6
|
+
selectNodeBackward,
|
|
7
|
+
selectNodeForward
|
|
8
|
+
} from "prosemirror-commands";
|
|
9
|
+
import {
|
|
10
|
+
TextSelection
|
|
11
|
+
} from "prosemirror-state";
|
|
12
|
+
import { isEmptyInlineControl } from "../schema/controlAttrs.js";
|
|
13
|
+
import { guardedCommand } from "../schema/guards.js";
|
|
14
|
+
function beyondEmptyControls(doc, pos, dir) {
|
|
15
|
+
let at = pos;
|
|
16
|
+
for (; ; ) {
|
|
17
|
+
const $at = doc.resolve(at);
|
|
18
|
+
const sibling = dir < 0 ? $at.nodeBefore : $at.nodeAfter;
|
|
19
|
+
if (!sibling || !isEmptyInlineControl(sibling)) break;
|
|
20
|
+
at += dir * sibling.nodeSize;
|
|
21
|
+
}
|
|
22
|
+
return at === pos ? null : at;
|
|
23
|
+
}
|
|
24
|
+
function beyondRun(state, dir) {
|
|
25
|
+
const $cursor = state.selection instanceof TextSelection ? state.selection.$cursor : null;
|
|
26
|
+
return $cursor === null ? null : beyondEmptyControls(state.doc, $cursor.pos, dir);
|
|
27
|
+
}
|
|
28
|
+
function charSize(text, dir) {
|
|
29
|
+
const point = text.codePointAt(dir < 0 ? Math.max(text.length - 2, 0) : 0);
|
|
30
|
+
return point !== void 0 && point > 65535 ? 2 : 1;
|
|
31
|
+
}
|
|
32
|
+
function reachBeyond(doc, beyond, dir) {
|
|
33
|
+
const $beyond = doc.resolve(beyond);
|
|
34
|
+
const sibling = dir < 0 ? $beyond.nodeBefore : $beyond.nodeAfter;
|
|
35
|
+
if (!sibling) return null;
|
|
36
|
+
const size = sibling.isText ? charSize(sibling.text ?? "", dir) : sibling.nodeSize;
|
|
37
|
+
return dir < 0 ? { from: beyond - size, to: beyond } : { from: beyond, to: beyond + size };
|
|
38
|
+
}
|
|
39
|
+
function fromBlockEdge(state, beyond, atEdge) {
|
|
40
|
+
const moved = state.apply(
|
|
41
|
+
state.tr.setSelection(TextSelection.create(state.doc, beyond))
|
|
42
|
+
);
|
|
43
|
+
let built = null;
|
|
44
|
+
atEdge(moved, (tr) => {
|
|
45
|
+
built = tr;
|
|
46
|
+
});
|
|
47
|
+
return built;
|
|
48
|
+
}
|
|
49
|
+
function deleteBeyondEmptyControls(dir) {
|
|
50
|
+
const atEdge = dir < 0 ? chainCommands(joinBackward, selectNodeBackward) : chainCommands(joinForward, selectNodeForward);
|
|
51
|
+
const edit = guardedCommand((state) => {
|
|
52
|
+
const beyond = beyondRun(state, dir);
|
|
53
|
+
if (beyond === null) return null;
|
|
54
|
+
const reach = reachBeyond(state.doc, beyond, dir);
|
|
55
|
+
if (reach === null) return fromBlockEdge(state, beyond, atEdge);
|
|
56
|
+
return state.tr.delete(reach.from, reach.to).scrollIntoView();
|
|
57
|
+
});
|
|
58
|
+
return (state, dispatch, view) => (
|
|
59
|
+
// With nothing beyond the run to take, the key still may not take the control away, so it is
|
|
60
|
+
// reported handled and the document is left as it stood.
|
|
61
|
+
edit(state, dispatch, view) || beyondRun(state, dir) !== null
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
var deleteBeyondEmptyControlsBefore = deleteBeyondEmptyControls(-1);
|
|
65
|
+
var deleteBeyondEmptyControlsAfter = deleteBeyondEmptyControls(1);
|
|
66
|
+
export {
|
|
67
|
+
deleteBeyondEmptyControlsAfter,
|
|
68
|
+
deleteBeyondEmptyControlsBefore
|
|
69
|
+
};
|
|
@@ -11,8 +11,8 @@ import { docxSchema } from "../../schema/index.js";
|
|
|
11
11
|
import { isBlockControl } from "../../schema/controlAttrs.js";
|
|
12
12
|
import {
|
|
13
13
|
removeEmptyBlockControl,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
skipEmptyBlockControlAfter,
|
|
15
|
+
skipEmptyBlockControlBefore
|
|
16
16
|
} from "../blockControlEdits.js";
|
|
17
17
|
import { insertLineBreak, insertPageBreak } from "../commands/breakCommands.js";
|
|
18
18
|
import {
|
|
@@ -30,6 +30,10 @@ import {
|
|
|
30
30
|
} from "../commands/listCommands.js";
|
|
31
31
|
import { insertEndnote, insertFootnote } from "../commands/noteCommands.js";
|
|
32
32
|
import { insertTab, moveAcrossTab } from "../commands/tabCommands.js";
|
|
33
|
+
import {
|
|
34
|
+
deleteBeyondEmptyControlsAfter,
|
|
35
|
+
deleteBeyondEmptyControlsBefore
|
|
36
|
+
} from "../inlineControlEdits.js";
|
|
33
37
|
import { openLinkPanel } from "./linkPanel.js";
|
|
34
38
|
var insertTabFromKeyboard = (state, dispatch, view) => {
|
|
35
39
|
if (!state.selection.empty && activeLinkSpan(state)) return false;
|
|
@@ -114,16 +118,23 @@ var docxKeymap = {
|
|
|
114
118
|
"Mod-Enter": insertPageBreak,
|
|
115
119
|
// `undoInputRule` comes first because it answers false unless the last transaction was an input
|
|
116
120
|
// rule, and the commands after it report the key handled wherever a control stands beside the
|
|
117
|
-
// caret. Then: a control holding nothing is
|
|
118
|
-
//
|
|
119
|
-
//
|
|
121
|
+
// caret. Then: a control holding nothing is never taken away by the key - between blocks the
|
|
122
|
+
// caret passes to the line beyond it, inside a paragraph the key passes over it and takes what
|
|
123
|
+
// stands beyond instead - a control holding one empty paragraph goes whole rather than being
|
|
124
|
+
// opened up, and the empty paragraph after a table keeps adjacent tables separate without
|
|
125
|
+
// changing imported documents.
|
|
120
126
|
Backspace: chainCommands(
|
|
121
127
|
undoInputRule,
|
|
122
|
-
|
|
128
|
+
skipEmptyBlockControlBefore,
|
|
129
|
+
deleteBeyondEmptyControlsBefore,
|
|
123
130
|
removeEmptyBlockControl,
|
|
124
131
|
preserveTableFollowingParagraph
|
|
125
132
|
),
|
|
126
|
-
Delete: chainCommands(
|
|
133
|
+
Delete: chainCommands(
|
|
134
|
+
skipEmptyBlockControlAfter,
|
|
135
|
+
deleteBeyondEmptyControlsAfter,
|
|
136
|
+
removeEmptyBlockControl
|
|
137
|
+
),
|
|
127
138
|
...historyKeymap,
|
|
128
139
|
"Mod-b": toggleBold,
|
|
129
140
|
"Mod-i": toggleItalic,
|
package/dist/ooxml/element.js
CHANGED
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
NAMESPACES,
|
|
4
4
|
qualify,
|
|
5
5
|
W_PREFIX,
|
|
6
|
-
wName
|
|
6
|
+
wName,
|
|
7
|
+
xmlnsName
|
|
7
8
|
} from "./names.js";
|
|
8
9
|
import { escapeXml, localPart } from "./xml.js";
|
|
9
10
|
function attrsText(attrs) {
|
|
@@ -16,7 +17,7 @@ function elementXml(name, attrs, children = []) {
|
|
|
16
17
|
return `${open}>${children.join("")}</${name}>`;
|
|
17
18
|
}
|
|
18
19
|
function xmlnsAttr(prefix) {
|
|
19
|
-
return [
|
|
20
|
+
return [xmlnsName(prefix), NAMESPACES[prefix]];
|
|
20
21
|
}
|
|
21
22
|
function localNameUnder(prefix, name) {
|
|
22
23
|
if (!name.includes(":")) return name;
|
package/dist/ooxml/errors.d.ts
CHANGED
|
@@ -94,6 +94,17 @@ export type ExportProblemReason =
|
|
|
94
94
|
readonly kind: "unwritable-part-root";
|
|
95
95
|
readonly part: ExportPartName;
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* A part a change is written into binds a prefix the writer spells to a namespace of its own, so
|
|
99
|
+
* the declaration the write adds would contradict the part (`unsupported-content`)
|
|
100
|
+
*/
|
|
101
|
+
| {
|
|
102
|
+
readonly kind: "conflicting-part-prefix";
|
|
103
|
+
/** Where the part sits in the package */
|
|
104
|
+
readonly path: string;
|
|
105
|
+
/** The prefix the part binds to something other than what the writer spells it for */
|
|
106
|
+
readonly prefix: string;
|
|
107
|
+
}
|
|
97
108
|
/** A cell's vertical merge covers rows its table does not have (`invalid-table`) */
|
|
98
109
|
| {
|
|
99
110
|
readonly kind: "vertical-merge-past-table";
|
package/dist/ooxml/fragment.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/ooxml/fragment.ts
|
|
2
|
+
import { XMLNS, xmlnsName } from "./names.js";
|
|
2
3
|
import {
|
|
3
4
|
elementChildren,
|
|
4
5
|
namespaceDecls,
|
|
@@ -29,7 +30,7 @@ function loneElement(xml) {
|
|
|
29
30
|
}
|
|
30
31
|
function isNamed(el, names) {
|
|
31
32
|
if (!names.includes(el.localName)) return false;
|
|
32
|
-
const declaration = el.prefix === null ?
|
|
33
|
+
const declaration = el.prefix === null ? XMLNS : xmlnsName(el.prefix);
|
|
33
34
|
for (let scope = el; scope.parentElement !== null; scope = scope.parentElement) {
|
|
34
35
|
if (scope.hasAttribute(declaration)) return el.namespaceURI === W_NS;
|
|
35
36
|
}
|
|
@@ -47,7 +48,7 @@ function holdsHeadAlone(el, shape) {
|
|
|
47
48
|
}
|
|
48
49
|
function rebindsReservedPrefix(el) {
|
|
49
50
|
return Array.from(el.attributes).some((attr) => {
|
|
50
|
-
if (attr.prefix !==
|
|
51
|
+
if (attr.prefix !== XMLNS) return false;
|
|
51
52
|
const reserved = RESERVED_PREFIXES.get(attr.localName);
|
|
52
53
|
return reserved !== void 0 && reserved !== attr.value;
|
|
53
54
|
}) || elementChildren(el).some(rebindsReservedPrefix);
|
package/dist/ooxml/names.d.ts
CHANGED
|
@@ -38,5 +38,9 @@ export declare function isKnownPrefix(prefix: string): prefix is KnownPrefix;
|
|
|
38
38
|
export declare function qualify(prefix: KnownPrefix, local: string): string;
|
|
39
39
|
/** `wName("val")` -> `w:val`. The one place the written WordprocessingML prefix is decided */
|
|
40
40
|
export declare function wName(local: string): string;
|
|
41
|
+
/** The attribute name a namespace declaration stands under, on its own for the default one */
|
|
42
|
+
export declare const XMLNS = "xmlns";
|
|
43
|
+
/** The name a declaration of one prefix is written under (`xmlnsName("w")` -> `xmlns:w`) */
|
|
44
|
+
export declare function xmlnsName(prefix: string): string;
|
|
41
45
|
/** The declaration a part root carries for one prefix, ready to write inside an opening tag */
|
|
42
46
|
export declare function xmlnsDecl(prefix: KnownPrefix): string;
|
package/dist/ooxml/names.js
CHANGED
|
@@ -22,8 +22,12 @@ function qualify(prefix, local) {
|
|
|
22
22
|
function wName(local) {
|
|
23
23
|
return qualify(W_PREFIX, local);
|
|
24
24
|
}
|
|
25
|
+
var XMLNS = "xmlns";
|
|
26
|
+
function xmlnsName(prefix) {
|
|
27
|
+
return `${XMLNS}:${prefix}`;
|
|
28
|
+
}
|
|
25
29
|
function xmlnsDecl(prefix) {
|
|
26
|
-
return
|
|
30
|
+
return `${xmlnsName(prefix)}="${NAMESPACES[prefix]}"`;
|
|
27
31
|
}
|
|
28
32
|
export {
|
|
29
33
|
M_NS,
|
|
@@ -31,8 +35,10 @@ export {
|
|
|
31
35
|
R_NS,
|
|
32
36
|
W_NS,
|
|
33
37
|
W_PREFIX,
|
|
38
|
+
XMLNS,
|
|
34
39
|
isKnownPrefix,
|
|
35
40
|
qualify,
|
|
36
41
|
wName,
|
|
37
|
-
xmlnsDecl
|
|
42
|
+
xmlnsDecl,
|
|
43
|
+
xmlnsName
|
|
38
44
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spelling the namespaces of an arrived part under the prefixes this package writes.
|
|
3
|
+
* `spec/notes/conformance.md` holds the decision and what it rests on.
|
|
4
|
+
*
|
|
5
|
+
* Names alone are rewritten: element names, attribute names, the namespace declarations
|
|
6
|
+
* themselves, and the prefix tokens of the markup-compatibility attributes that carry a prefix or
|
|
7
|
+
* QName list (§17.2.1-2, §17.2.4-5). No WordprocessingML attribute value holds a QName, so no
|
|
8
|
+
* other value is looked at, and text, CDATA, comments and processing instructions are copied byte
|
|
9
|
+
* for byte - a `w:p` a document wrote inside a `w:t` is its text, not its markup.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here turns a part down. One whose rewrite would not be unambiguous is handed back as it
|
|
12
|
+
* arrived, and what refuses it then is what refused it before this rewrite existed: the reader
|
|
13
|
+
* that needs the prefix (`docx/importDocx`) or the write about to spell it (`ooxml/partSplice`).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The part text with every namespace this package knows spelled the way it writes it.
|
|
17
|
+
*
|
|
18
|
+
* A part that comes back unrewritten comes back as the same string by identity, so a package no
|
|
19
|
+
* producer wrote foreign prefixes into is never re-encoded and still exports byte for byte.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withEditorPrefixes(xml: string): string;
|