@portone/docx-editor 0.6.6 → 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 +21 -0
- package/dist/docx/fidelity.js +2 -4
- package/dist/docx/importParagraph.js +1 -6
- package/dist/docx/runProps.d.ts +3 -0
- package/dist/docx/runProps.js +9 -0
- package/dist/docx/serializeParagraph.js +29 -3
- package/dist/editor/blockControlEdits.js +4 -4
- package/dist/editor/commands/comments/editing.js +3 -2
- package/dist/editor/createEditor.js +6 -9
- 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/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/schema/attrRoles.js +1 -0
- package/dist/schema/clipboard.js +3 -0
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +42 -1
- 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/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/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @portone/docx-editor
|
|
2
2
|
|
|
3
|
+
## 0.6.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#209](https://github.com/portone-io/docx-editor/pull/209) [`55cf73e`](https://github.com/portone-io/docx-editor/commit/55cf73e3f66b3b461b2a42b5a29634e2265b3515) Thanks [@Deea222](https://github.com/Deea222)! - Show and fill a highlighted run that holds no text, the blank a form leaves to be filled in.
|
|
8
|
+
|
|
9
|
+
A run with formatting and no characters, such as a yellow-highlighted empty table cell, used to be kept as invisible XML: nothing showed where the blank was, and text typed there came out unformatted.
|
|
10
|
+
Where the run's own properties paint a highlight or a shading, the editor now draws it as a short box, whose width the `--docx-editor-empty-run-width` property sets.
|
|
11
|
+
Any other empty run still takes no room, including one whose highlight or shading comes only from a style.
|
|
12
|
+
|
|
13
|
+
Clicking the box and typing, composing, or pasting fills it: the text takes the run's formatting, whatever formatting pasted text carried, and the box goes in the same undo step.
|
|
14
|
+
Bookmarks and other markers that draw nothing beside the box do not stop it filling, and a blank of other formatting beside it stays.
|
|
15
|
+
In a content control holding only such a run, the text goes into the control and what is typed next stays in it.
|
|
16
|
+
A blank inside a hyperlink, or in a control whose lock keeps its contents from being edited, is not filled; the text goes beside it in the formatting of the text around it.
|
|
17
|
+
|
|
18
|
+
A blank nobody filled goes back out in the file byte for byte as it came, even when the paragraph around it was edited.
|
|
19
|
+
|
|
20
|
+
Typed text now takes the formatting of the nearest text in its paragraph, the text before the caret or else the text after it, passing over what draws nothing, as Word does.
|
|
21
|
+
Text typed beside a bookmark, a comment's range marker, or a formatted run with no text used to take that element's formatting, which usually meant none.
|
|
22
|
+
In a paragraph with no text, typed text takes the properties of a formatted run with no text in it, including properties nothing draws, such as `w:rtl w:val="0"` that Google Docs writes, and the run's revision ids; such text is no longer drawn with the paragraph style's character formatting alone.
|
|
23
|
+
|
|
3
24
|
## 0.6.6
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/docx/fidelity.js
CHANGED
|
@@ -33,7 +33,7 @@ function preservedBy(node, element) {
|
|
|
33
33
|
code: "preserved-run-content"
|
|
34
34
|
};
|
|
35
35
|
case "rawInline":
|
|
36
|
-
return preservedInline(node
|
|
36
|
+
return preservedInline(node);
|
|
37
37
|
default:
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
@@ -44,9 +44,7 @@ function preservedBlockNote(node, element) {
|
|
|
44
44
|
}
|
|
45
45
|
return node.attrs.guarded === true ? { severity: "hidden", code: "range-marker" } : { severity: "hidden", code: "preserved-block" };
|
|
46
46
|
}
|
|
47
|
-
function preservedInline(node
|
|
48
|
-
const name = stringAttr(node.attrs.element) ?? localNameOf(element);
|
|
49
|
-
if (name === "r") return null;
|
|
47
|
+
function preservedInline(node) {
|
|
50
48
|
const severity = severityOf(node.attrs.display);
|
|
51
49
|
return severity === "hidden" && node.attrs.guarded === true ? { severity, code: "range-marker" } : { severity, code: "preserved-inline" };
|
|
52
50
|
}
|
|
@@ -145,12 +145,7 @@ function buildRunNodes(run, images, themeFonts, comments, wrappers = []) {
|
|
|
145
145
|
}
|
|
146
146
|
if (nodes.length === 0) {
|
|
147
147
|
return [
|
|
148
|
-
docxSchema.nodes.
|
|
149
|
-
{ xml: serializeXml(run), element: run.localName },
|
|
150
|
-
null,
|
|
151
|
-
// The wrappers have to close again around this XML on export, so their marks ride along here too
|
|
152
|
-
wrappers
|
|
153
|
-
)
|
|
148
|
+
docxSchema.nodes.emptyRun.create({ xml: serializeXml(run) }, null, marks)
|
|
154
149
|
];
|
|
155
150
|
}
|
|
156
151
|
return nodes;
|
package/dist/docx/runProps.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* The display values produced here are used on screen only. What goes back into the document is
|
|
12
12
|
* always the rPr string.
|
|
13
13
|
*/
|
|
14
|
+
import type { Mark } from "prosemirror-model";
|
|
14
15
|
import { type RunFormat } from "../model/format";
|
|
15
16
|
import { type EditableRunKey, type RunEdit } from "./formatting";
|
|
16
17
|
export type { RunEdit } from "./formatting";
|
|
@@ -25,6 +26,8 @@ export interface RunProps {
|
|
|
25
26
|
}
|
|
26
27
|
/** Derives the display values again from the rPr we operated on. The same rPr always yields the same display values */
|
|
27
28
|
export declare function readRunProps(rPr: string | null): RunFormat | null;
|
|
29
|
+
/** The colour a run's own properties paint behind its characters, whatever it inherits. null for none */
|
|
30
|
+
export declare function ownBackground(run: Mark): string | null;
|
|
28
31
|
/**
|
|
29
32
|
* The rPr and display values after changing one piece of character formatting.
|
|
30
33
|
*
|
package/dist/docx/runProps.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
parsePropsXml,
|
|
6
6
|
renderProps
|
|
7
7
|
} from "../ooxml/props.js";
|
|
8
|
+
import { runBackground } from "../styles/inlineStyle.js";
|
|
8
9
|
import {
|
|
9
10
|
EMPTY_RUN_PROPS,
|
|
10
11
|
RUN_PROPERTIES,
|
|
@@ -19,6 +20,13 @@ function propsOf(rPr) {
|
|
|
19
20
|
function readRunProps(rPr) {
|
|
20
21
|
return rPr === null ? null : readRunFormat(parsePropsXml(rPr));
|
|
21
22
|
}
|
|
23
|
+
function ownBackground(run) {
|
|
24
|
+
const format = toRunFormat(run.attrs.format);
|
|
25
|
+
if (format === null || runBackground(format) === null) return null;
|
|
26
|
+
const rPr = run.attrs.rPr;
|
|
27
|
+
const own = readRunProps(typeof rPr === "string" ? rPr : null);
|
|
28
|
+
return own === null ? null : runBackground(own);
|
|
29
|
+
}
|
|
22
30
|
function inheritedFormat(current) {
|
|
23
31
|
const direct = new Set(Object.keys(readRunProps(current.rPr) ?? {}));
|
|
24
32
|
const inherited = {};
|
|
@@ -50,5 +58,6 @@ export {
|
|
|
50
58
|
editRunProps,
|
|
51
59
|
isRunToggleOn,
|
|
52
60
|
matchesRunEdit,
|
|
61
|
+
ownBackground,
|
|
53
62
|
readRunProps
|
|
54
63
|
};
|
|
@@ -12,7 +12,15 @@ import {
|
|
|
12
12
|
withExtent
|
|
13
13
|
} from "../ooxml/image.js";
|
|
14
14
|
import { wName } from "../ooxml/names.js";
|
|
15
|
-
import {
|
|
15
|
+
import { parsePropsXml } from "../ooxml/props.js";
|
|
16
|
+
import {
|
|
17
|
+
attrString,
|
|
18
|
+
childByLocalName,
|
|
19
|
+
elementChildren,
|
|
20
|
+
escapeXml,
|
|
21
|
+
serializeXml
|
|
22
|
+
} from "../ooxml/xml.js";
|
|
23
|
+
import { isEmptyRun } from "../schema/emptyRuns.js";
|
|
16
24
|
import { wrapperMarks } from "../schema/wrappers.js";
|
|
17
25
|
import { NO_EXPORT_REFS } from "./exportRefs.js";
|
|
18
26
|
import { emptyWrapperXml, wrapperKindOf } from "./wrappers.js";
|
|
@@ -113,11 +121,29 @@ function preservedXml(node) {
|
|
|
113
121
|
}
|
|
114
122
|
return xml;
|
|
115
123
|
}
|
|
124
|
+
function readWith(run, mark) {
|
|
125
|
+
const rPr = childByLocalName(run, "rPr");
|
|
126
|
+
return attrString(run) === rawAttrsOf(mark?.attrs.rAttrs) && (rPr ? serializeXml(rPr) : null) === rawAttrsOf(mark?.attrs.rPr);
|
|
127
|
+
}
|
|
128
|
+
function emptyRunPart(node) {
|
|
129
|
+
const xml = rawAttrsOf(node.attrs.xml);
|
|
130
|
+
const run = xml === null ? null : parsePropsXml(xml);
|
|
131
|
+
const mark = markOf(node, "run");
|
|
132
|
+
if (xml !== null && run !== null && readWith(run, mark)) {
|
|
133
|
+
return { kind: "raw", xml };
|
|
134
|
+
}
|
|
135
|
+
const pieces = (run ? elementChildren(run) : []).filter((child) => child.localName !== "rPr").map(serializeXml);
|
|
136
|
+
return { kind: "run", mark, pieces, sealed: true };
|
|
137
|
+
}
|
|
116
138
|
function addInline(parts, child, images) {
|
|
117
139
|
if (child.type.name === "rawInline") {
|
|
118
140
|
parts.push({ kind: "raw", xml: preservedXml(child) });
|
|
119
141
|
return;
|
|
120
142
|
}
|
|
143
|
+
if (isEmptyRun(child)) {
|
|
144
|
+
parts.push(emptyRunPart(child));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
121
147
|
const empty = emptyWrapperXml(child);
|
|
122
148
|
if (empty !== null) {
|
|
123
149
|
parts.push({ kind: "raw", xml: empty });
|
|
@@ -146,10 +172,10 @@ function addInline(parts, child, images) {
|
|
|
146
172
|
const piece = renderInline(child, images);
|
|
147
173
|
const mark = markOf(child, "run");
|
|
148
174
|
const last = parts.at(-1);
|
|
149
|
-
if (last?.kind === "run" && sameMark(last.mark, mark)) {
|
|
175
|
+
if (last?.kind === "run" && !last.sealed && sameMark(last.mark, mark)) {
|
|
150
176
|
last.pieces.push(piece);
|
|
151
177
|
} else {
|
|
152
|
-
parts.push({ kind: "run", mark, pieces: [piece] });
|
|
178
|
+
parts.push({ kind: "run", mark, pieces: [piece], sealed: false });
|
|
153
179
|
}
|
|
154
180
|
}
|
|
155
181
|
function renderParagraphPart(part) {
|
|
@@ -33,7 +33,7 @@ function caretAtEdge(selection, dir) {
|
|
|
33
33
|
const at = dir < 0 ? 0 : $cursor.parent.content.size;
|
|
34
34
|
return $cursor.parentOffset === at ? $cursor : null;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function emptyControlsBeside(selection, dir) {
|
|
37
37
|
const $cursor = caretAtEdge(selection, dir);
|
|
38
38
|
if (!$cursor) return null;
|
|
39
39
|
const depth = $cursor.depth;
|
|
@@ -52,7 +52,7 @@ function emptyRunBeside(selection, dir) {
|
|
|
52
52
|
}
|
|
53
53
|
function skipEmptyControls(dir) {
|
|
54
54
|
const move = guardedCommand((state) => {
|
|
55
|
-
const beyond =
|
|
55
|
+
const beyond = emptyControlsBeside(state.selection, dir)?.beyond;
|
|
56
56
|
if (beyond === null || beyond === void 0) return null;
|
|
57
57
|
const $cursor = state.selection instanceof TextSelection ? state.selection.$cursor : null;
|
|
58
58
|
if ($cursor && isEmptyParagraph($cursor.parent)) {
|
|
@@ -65,9 +65,9 @@ function skipEmptyControls(dir) {
|
|
|
65
65
|
return state.tr.setSelection(Selection.near(state.doc.resolve(beyond), dir)).scrollIntoView();
|
|
66
66
|
});
|
|
67
67
|
return (state, dispatch, view) => (
|
|
68
|
-
// With nothing beyond the
|
|
68
|
+
// With nothing beyond the row there is nowhere to pass to, and the key still may not take the
|
|
69
69
|
// control away, so it is reported handled and the document is left as it stood.
|
|
70
|
-
move(state, dispatch, view) ||
|
|
70
|
+
move(state, dispatch, view) || emptyControlsBeside(state.selection, dir) !== null
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
var skipEmptyBlockControlBefore = skipEmptyControls(-1);
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "../../../docx/story.js";
|
|
18
18
|
import { docxSchema } from "../../../schema/index.js";
|
|
19
19
|
import { guardedCommand } from "../../../schema/guards.js";
|
|
20
|
+
import { isCommentNode } from "../../../schema/protection.js";
|
|
20
21
|
import { isWrapperType } from "../../../schema/wrappers.js";
|
|
21
22
|
import {
|
|
22
23
|
reservedCommentDurableIds,
|
|
@@ -56,7 +57,7 @@ function nextCommentId(state) {
|
|
|
56
57
|
reserve(id);
|
|
57
58
|
}
|
|
58
59
|
state.doc.descendants((node) => {
|
|
59
|
-
if (node
|
|
60
|
+
if (isCommentNode(node)) {
|
|
60
61
|
const id = stringAttr(node.attrs.id);
|
|
61
62
|
if (id !== null) reserve(id);
|
|
62
63
|
}
|
|
@@ -356,7 +357,7 @@ function removeComment(id) {
|
|
|
356
357
|
const positions = [];
|
|
357
358
|
const bodies = /* @__PURE__ */ new Set([id]);
|
|
358
359
|
state.doc.descendants((node, pos) => {
|
|
359
|
-
if ((node
|
|
360
|
+
if (isCommentNode(node) && stringAttr(node.attrs.id) === id) {
|
|
360
361
|
positions.push({ pos, size: node.nodeSize });
|
|
361
362
|
}
|
|
362
363
|
if (node.type.name === "commentReference" && stringAttr(node.attrs.id) === id) {
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from "./editorDocument.js";
|
|
26
26
|
import { editRefusal } from "./editRefusal.js";
|
|
27
27
|
import { imageFiles } from "./imageFiles.js";
|
|
28
|
+
import { caretFormat } from "./plugins/caretFormat.js";
|
|
28
29
|
import { columnResize } from "./plugins/columnResize.js";
|
|
29
30
|
import { commentComposer } from "./plugins/commentComposer.js";
|
|
30
31
|
import { commentDecorations } from "./plugins/commentDecorations.js";
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
} from "./plugins/displayDerivation.js";
|
|
39
40
|
import { documentProtection } from "./plugins/documentProtection.js";
|
|
40
41
|
import { imagePaste } from "./plugins/imagePaste.js";
|
|
42
|
+
import { inlinePlugins } from "./plugins/inlinePlugins.js";
|
|
41
43
|
import { docxKeymap, historyKeys } from "./plugins/keymap.js";
|
|
42
44
|
import { linkPanel } from "./plugins/linkPanel.js";
|
|
43
45
|
import { listInputRules } from "./plugins/listInputRules.js";
|
|
@@ -47,11 +49,7 @@ import { noteNavigation } from "./plugins/noteNavigation.js";
|
|
|
47
49
|
import { noteNumbering } from "./plugins/noteNumbering.js";
|
|
48
50
|
import { numberingMarkers } from "./plugins/numberingDecorations.js";
|
|
49
51
|
import { rowResize } from "./plugins/rowResize.js";
|
|
50
|
-
import { tabCaret } from "./plugins/tabCaret.js";
|
|
51
|
-
import { tabDecorations } from "./plugins/tabDecorations.js";
|
|
52
|
-
import { tabLayout } from "./plugins/tabLayout.js";
|
|
53
52
|
import { tableContextMenu } from "./plugins/tableContextMenu.js";
|
|
54
|
-
import { tabPointer } from "./plugins/tabPointer.js";
|
|
55
53
|
import { textContextMenu } from "./plugins/textContextMenu.js";
|
|
56
54
|
import { ImageNodeView } from "./views/imageResize.js";
|
|
57
55
|
import { runMarkView } from "./views/runMarkView.js";
|
|
@@ -93,6 +91,9 @@ function createEditorState(doc, options = {}) {
|
|
|
93
91
|
// plugin appending to an edit, which then sees the control it kept, and behind the one above,
|
|
94
92
|
// whose deletion it keeps the control through before a composition opens
|
|
95
93
|
controlContents(),
|
|
94
|
+
// What the caret writes with, behind the one above so the marks it gives a caret it keeps
|
|
95
|
+
// inside a control win
|
|
96
|
+
caretFormat(),
|
|
96
97
|
history(),
|
|
97
98
|
keymap(docxKeymap),
|
|
98
99
|
historyKeys(),
|
|
@@ -130,11 +131,7 @@ function createEditorState(doc, options = {}) {
|
|
|
130
131
|
// What the notes under the page are, worked out from the document the same way
|
|
131
132
|
noteProjection.plugin,
|
|
132
133
|
noteNavigation(),
|
|
133
|
-
|
|
134
|
-
tabDecorations(),
|
|
135
|
-
tabPointer(),
|
|
136
|
-
tabLayout(),
|
|
137
|
-
tabCaret(),
|
|
134
|
+
...inlinePlugins(),
|
|
138
135
|
// Works the display values out again after every edit: the lines of a table's cells, and
|
|
139
136
|
// the style values of the paragraphs the edit built or rewrote
|
|
140
137
|
displayDerivation(),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Mark, type Node as PMNode } from "prosemirror-model";
|
|
2
|
+
import { type StepRange } from "../schema/locks";
|
|
3
|
+
export interface FormatSource {
|
|
4
|
+
/** The run mark what is written takes, null for none */
|
|
5
|
+
run: Mark | null;
|
|
6
|
+
/** The runs holding no characters what is written fills, where one of them gave the formatting */
|
|
7
|
+
fills: StepRange | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function sameRun(a: Mark | null, b: Mark | null): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Word's rule: the nearest character the paragraph shows, before the caret else after it, and a run
|
|
12
|
+
* holding no characters only where the paragraph shows none. null in a paragraph holding nothing.
|
|
13
|
+
*
|
|
14
|
+
* A run holding no characters gives the formatting only where what is written fills it, so a blank
|
|
15
|
+
* the text cannot take the place of is passed over and never stands painted twice.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatSourceAt(doc: PMNode, pos: number): FormatSource | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/editor/formatSource.ts
|
|
2
|
+
import { Mark } from "prosemirror-model";
|
|
3
|
+
import { ownBackground } from "../docx/runProps.js";
|
|
4
|
+
import { docxSchema } from "../schema/index.js";
|
|
5
|
+
import { isEmptyRun } from "../schema/emptyRuns.js";
|
|
6
|
+
import {
|
|
7
|
+
controlsWrittenInto,
|
|
8
|
+
drawsNothing
|
|
9
|
+
} from "../schema/locks.js";
|
|
10
|
+
import { wrapperMarks } from "../schema/wrappers.js";
|
|
11
|
+
function runOf(node) {
|
|
12
|
+
return docxSchema.marks.run.isInSet(node.marks) ?? null;
|
|
13
|
+
}
|
|
14
|
+
function sameRun(a, b) {
|
|
15
|
+
return a === null || b === null ? a === b : a.eq(b);
|
|
16
|
+
}
|
|
17
|
+
function fillable(doc, pos, node) {
|
|
18
|
+
if (!isEmptyRun(node)) return false;
|
|
19
|
+
const open = controlsWrittenInto(doc, pos, pos + node.nodeSize).map(
|
|
20
|
+
(span) => span.mark
|
|
21
|
+
);
|
|
22
|
+
return wrapperMarks(node).every(
|
|
23
|
+
(wrapper) => wrapper.type === docxSchema.marks.sdt && open.some((control) => control.eq(wrapper))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function shows(doc, node, pos) {
|
|
27
|
+
if (!drawsNothing(node)) return true;
|
|
28
|
+
const run = runOf(node);
|
|
29
|
+
return run !== null && ownBackground(run) !== null && fillable(doc, pos, node);
|
|
30
|
+
}
|
|
31
|
+
function nearest($pos, matches) {
|
|
32
|
+
const parent = $pos.parent;
|
|
33
|
+
const index = $pos.index();
|
|
34
|
+
const at = (child) => matches(parent.child(child), $pos.posAtIndex(child));
|
|
35
|
+
for (let child = index - 1; child >= 0; child -= 1) {
|
|
36
|
+
if (at(child)) return child;
|
|
37
|
+
}
|
|
38
|
+
for (let child = index; child < parent.childCount; child += 1) {
|
|
39
|
+
if (at(child)) return child;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function filledFrom($pos, index) {
|
|
44
|
+
const parent = $pos.parent;
|
|
45
|
+
const source = parent.child(index);
|
|
46
|
+
const joins = (at) => {
|
|
47
|
+
const node = parent.maybeChild(at);
|
|
48
|
+
return node !== null && isEmptyRun(node) && sameRun(runOf(node), runOf(source)) && Mark.sameSet(wrapperMarks(node), wrapperMarks(source));
|
|
49
|
+
};
|
|
50
|
+
let first = index;
|
|
51
|
+
while (joins(first - 1)) first -= 1;
|
|
52
|
+
let last = index;
|
|
53
|
+
while (joins(last + 1)) last += 1;
|
|
54
|
+
return { from: $pos.posAtIndex(first), to: $pos.posAtIndex(last + 1) };
|
|
55
|
+
}
|
|
56
|
+
function formatSourceAt(doc, pos) {
|
|
57
|
+
const $pos = doc.resolve(pos);
|
|
58
|
+
const parent = $pos.parent;
|
|
59
|
+
if (!parent.inlineContent) return null;
|
|
60
|
+
if ($pos.textOffset > 0) {
|
|
61
|
+
return { run: runOf(parent.child($pos.index())), fills: null };
|
|
62
|
+
}
|
|
63
|
+
const source = nearest($pos, (node2, at) => shows(doc, node2, at)) ?? nearest($pos, (node2, at) => fillable(doc, at, node2));
|
|
64
|
+
if (source === null) return null;
|
|
65
|
+
const node = parent.child(source);
|
|
66
|
+
return {
|
|
67
|
+
run: runOf(node),
|
|
68
|
+
fills: isEmptyRun(node) ? filledFrom($pos, source) : null
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
formatSourceAt,
|
|
73
|
+
sameRun
|
|
74
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from "prosemirror-state";
|
|
2
|
+
/**
|
|
3
|
+
* Gives a caret the formatting of the character the rule in `../formatSource` finds, where a mark
|
|
4
|
+
* the caret was given on purpose does not stand: a caret beside something that draws nothing
|
|
5
|
+
* carries on the text the rule finds, and one beside a blank takes the blank's formatting, which
|
|
6
|
+
* `controlContents` then fills.
|
|
7
|
+
*
|
|
8
|
+
* It stands behind `controlContents`, whose stored marks for a caret left inside a control win.
|
|
9
|
+
*/
|
|
10
|
+
export declare function caretFormat(): Plugin;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/editor/plugins/caretFormat.ts
|
|
2
|
+
import { Plugin, TextSelection } from "prosemirror-state";
|
|
3
|
+
import { docxSchema } from "../../schema/index.js";
|
|
4
|
+
import { formatSourceAt, sameRun } from "../formatSource.js";
|
|
5
|
+
function caretMarks(tr) {
|
|
6
|
+
const caret = tr.selection instanceof TextSelection ? tr.selection.$cursor : null;
|
|
7
|
+
const source = caret ? formatSourceAt(tr.doc, caret.pos) : null;
|
|
8
|
+
if (!caret || source === null) return null;
|
|
9
|
+
const own = caret.marks();
|
|
10
|
+
const runType = docxSchema.marks.run;
|
|
11
|
+
if (sameRun(runType.isInSet(own) ?? null, source.run)) return null;
|
|
12
|
+
const others = runType.removeFromSet(own);
|
|
13
|
+
return source.run === null ? others : source.run.addToSet(others);
|
|
14
|
+
}
|
|
15
|
+
function caretFormat() {
|
|
16
|
+
let live = null;
|
|
17
|
+
return new Plugin({
|
|
18
|
+
view(view) {
|
|
19
|
+
live = view;
|
|
20
|
+
return {
|
|
21
|
+
destroy() {
|
|
22
|
+
live = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
appendTransaction(transactions, _oldState, newState) {
|
|
27
|
+
const moved = transactions.some((tr2) => tr2.docChanged || tr2.selectionSet);
|
|
28
|
+
if (!moved || newState.storedMarks !== null || live?.composing === true) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const tr = newState.tr;
|
|
32
|
+
const marks = caretMarks(tr);
|
|
33
|
+
return marks === null ? null : tr.setStoredMarks(marks);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
caretFormat
|
|
39
|
+
};
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* left beside a control the edit emptied: what is typed, composed or pasted there next goes into
|
|
17
17
|
* the control rather than beside it, until the caret moves. A caret the user places against the
|
|
18
18
|
* edge of a control still stands outside it.
|
|
19
|
+
*
|
|
20
|
+
* What is written where a run holding no characters gave the formatting (`../formatSource`) takes
|
|
21
|
+
* that run's formatting and fills it, a paste included: the run goes, and where it stood inside
|
|
22
|
+
* open controls, the controls are laid over what was written, so a caret placed in a control's
|
|
23
|
+
* blank writes into the control.
|
|
19
24
|
*/
|
|
20
25
|
import { Plugin } from "prosemirror-state";
|
|
21
26
|
/** Where the caret keeps writing into the controls it wrote into, while it stays there */
|
|
@@ -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/schema/attrRoles.js
CHANGED
|
@@ -162,6 +162,7 @@ var NODE_ATTR_ROLES = {
|
|
|
162
162
|
// renumbered around an edit is the same reference it was
|
|
163
163
|
label: { role: "display", class: "derived" }
|
|
164
164
|
},
|
|
165
|
+
emptyRun: { xml: { role: "source", class: "preserved" } },
|
|
165
166
|
rawRunContent: {
|
|
166
167
|
xml: { role: "source", class: "preserved" },
|
|
167
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">;
|
|
@@ -1066,6 +1066,47 @@ var docxSchema = new Schema({
|
|
|
1066
1066
|
}
|
|
1067
1067
|
]
|
|
1068
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
|
+
},
|
|
1069
1110
|
/** The node that carries a non-run element inside a paragraph (a bookmark, for instance) exactly as it came */
|
|
1070
1111
|
rawInline: {
|
|
1071
1112
|
group: "inline",
|
|
@@ -1074,7 +1115,7 @@ var docxSchema = new Schema({
|
|
|
1074
1115
|
marks: "wrapper",
|
|
1075
1116
|
attrs: {
|
|
1076
1117
|
xml: { default: null },
|
|
1077
|
-
/** The local name of the element
|
|
1118
|
+
/** The local name of the element */
|
|
1078
1119
|
element: { default: null },
|
|
1079
1120
|
display: { default: "hidden" },
|
|
1080
1121
|
text: { default: null },
|
package/dist/schema/locks.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export declare const controlLifted: PluginKey<boolean>;
|
|
|
47
47
|
* the caret then writes into a control it emptied, the node it stood as goes, since the control
|
|
48
48
|
* stands as the new text instead. That removal is the one step here a lock against deletion would
|
|
49
49
|
* refuse, and it removes no control.
|
|
50
|
+
*
|
|
51
|
+
* The same transaction takes away a run holding no characters that text written beside it filled
|
|
52
|
+
* (`editor/formatSource`), giving that text the run's formatting and laying the controls the run
|
|
53
|
+
* stood in over it first, so a control a lock keeps never stands on nothing.
|
|
50
54
|
*/
|
|
51
55
|
export declare const controlKept: PluginKey<boolean>;
|
|
52
56
|
/** The stretch a judgement or an edit runs over */
|
|
@@ -103,6 +107,13 @@ export declare function controlSpans(block: Textblock): ControlSpan[];
|
|
|
103
107
|
* (`editor/commands/lockCommands`).
|
|
104
108
|
*/
|
|
105
109
|
export declare function coversWhole(range: StepRange, span: StepRange): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Whether this inline node puts nothing on the page: a control holding nothing, a comment's range
|
|
112
|
+
* marker, a run holding no characters, or a preserved element drawn as nothing, such as a bookmark.
|
|
113
|
+
*
|
|
114
|
+
* A run holding no characters counts even where its highlight is drawn, since it holds no text.
|
|
115
|
+
*/
|
|
116
|
+
export declare function drawsNothing(node: PMNode): boolean;
|
|
106
117
|
/**
|
|
107
118
|
* The inline controls replacing this stretch writes into rather than takes away, each as the
|
|
108
119
|
* whole stretch it covers, outermost first.
|
package/dist/schema/locks.js
CHANGED
|
@@ -131,6 +131,7 @@ function drawsNothing(node) {
|
|
|
131
131
|
switch (node.type.name) {
|
|
132
132
|
case "commentStart":
|
|
133
133
|
case "commentEnd":
|
|
134
|
+
case "emptyRun":
|
|
134
135
|
return true;
|
|
135
136
|
case "rawInline":
|
|
136
137
|
case "rawRunContent":
|
|
@@ -340,6 +341,7 @@ export {
|
|
|
340
341
|
controlSpans,
|
|
341
342
|
controlsWrittenInto,
|
|
342
343
|
coversWhole,
|
|
344
|
+
drawsNothing,
|
|
343
345
|
emptyControlsIn,
|
|
344
346
|
historyReplay,
|
|
345
347
|
isLockedContainer,
|
|
@@ -54,6 +54,8 @@ export declare const editorClassNames: {
|
|
|
54
54
|
readonly commentMarker: "docx-editor-comment-marker";
|
|
55
55
|
/** A superscript footnote or endnote reference */
|
|
56
56
|
readonly noteReference: "docx-editor-note-reference";
|
|
57
|
+
/** A run holding no characters, which takes width only where its own properties paint a background */
|
|
58
|
+
readonly emptyRun: "docx-editor-empty-run";
|
|
57
59
|
readonly rawInline: "docx-editor-raw-inline";
|
|
58
60
|
/** A preserved child of a run, drawn by the `display` its policy gave it */
|
|
59
61
|
readonly rawRunContent: "docx-editor-raw-run";
|
|
@@ -238,6 +240,8 @@ export declare const editorAttributes: {
|
|
|
238
240
|
readonly containerPageSpace: "data-container-page-space";
|
|
239
241
|
/** A display-only copy of a table header row on a continued page */
|
|
240
242
|
readonly tableRepeatedHeader: "data-table-repeated-header";
|
|
243
|
+
/** Put on a run whose own properties paint a background, so a run holding no characters inside it is drawn wide */
|
|
244
|
+
readonly paintsBackground: "data-paints";
|
|
241
245
|
/**
|
|
242
246
|
* The tooltip a control shows on hover, drawn by the CSS straight from this attribute.
|
|
243
247
|
* It is the one mark here whose selector is the attribute on its own rather than a
|
|
@@ -49,6 +49,8 @@ var editorClassNames = {
|
|
|
49
49
|
commentMarker: `${PREFIX}-comment-marker`,
|
|
50
50
|
/** A superscript footnote or endnote reference */
|
|
51
51
|
noteReference: `${PREFIX}-note-reference`,
|
|
52
|
+
/** A run holding no characters, which takes width only where its own properties paint a background */
|
|
53
|
+
emptyRun: `${PREFIX}-empty-run`,
|
|
52
54
|
rawInline: `${PREFIX}-raw-inline`,
|
|
53
55
|
/** A preserved child of a run, drawn by the `display` its policy gave it */
|
|
54
56
|
rawRunContent: `${PREFIX}-raw-run`,
|
|
@@ -227,6 +229,8 @@ var editorAttributes = {
|
|
|
227
229
|
containerPageSpace: "data-container-page-space",
|
|
228
230
|
/** A display-only copy of a table header row on a continued page */
|
|
229
231
|
tableRepeatedHeader: "data-table-repeated-header",
|
|
232
|
+
/** Put on a run whose own properties paint a background, so a run holding no characters inside it is drawn wide */
|
|
233
|
+
paintsBackground: "data-paints",
|
|
230
234
|
/**
|
|
231
235
|
* The tooltip a control shows on hover, drawn by the CSS straight from this attribute.
|
|
232
236
|
* It is the one mark here whose selector is the attribute on its own rather than a
|
|
@@ -32,6 +32,8 @@ export declare const SINGLE_LINE_RATIO = 1.3;
|
|
|
32
32
|
export declare const HIGHLIGHT_COLORS: Record<HighlightName, string>;
|
|
33
33
|
/** Turns line spacing into a single CSS line-height value. With none given, one line height is the default */
|
|
34
34
|
export declare function lineHeightValue(spacing: LineSpacing | null): string;
|
|
35
|
+
/** The colour painted behind the characters, the highlight over the fill as Word paints them. null for none */
|
|
36
|
+
export declare function runBackground(format: RunFormat): string | null;
|
|
35
37
|
export declare function runStyle(format: RunFormat | null, fontFallbacks?: FontFallbacks): string | undefined;
|
|
36
38
|
/**
|
|
37
39
|
* The CSS a paragraph is drawn with: its own formatting, and the character formatting the style it
|
|
@@ -92,12 +92,17 @@ function inheritedRunCss(format, fontFallbacks) {
|
|
|
92
92
|
if (format.color) css.push(`color:${format.color}`);
|
|
93
93
|
return css;
|
|
94
94
|
}
|
|
95
|
+
function runBackground(format) {
|
|
96
|
+
const highlight = format.highlight ? HIGHLIGHT_COLORS[format.highlight] : void 0;
|
|
97
|
+
if (highlight) return highlight;
|
|
98
|
+
return format.background && format.background !== NO_FILL ? format.background : null;
|
|
99
|
+
}
|
|
95
100
|
function ownRunCss(format) {
|
|
96
101
|
const css = [];
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
else if (format.background)
|
|
100
|
-
css.push(`background-color:${fillColor(
|
|
102
|
+
const background = runBackground(format);
|
|
103
|
+
if (background !== null) css.push(`background-color:${background}`);
|
|
104
|
+
else if (format.background === NO_FILL)
|
|
105
|
+
css.push(`background-color:${fillColor(NO_FILL)}`);
|
|
101
106
|
if (format.verticalAlign === "superscript") css.push("vertical-align:super");
|
|
102
107
|
if (format.verticalAlign === "subscript") css.push("vertical-align:sub");
|
|
103
108
|
return css;
|
|
@@ -222,6 +227,7 @@ export {
|
|
|
222
227
|
lineHeightValue,
|
|
223
228
|
paragraphStyle,
|
|
224
229
|
rowStyle,
|
|
230
|
+
runBackground,
|
|
225
231
|
runStyle,
|
|
226
232
|
tableStyle
|
|
227
233
|
};
|
package/dist/styles.css
CHANGED
|
@@ -1112,6 +1112,21 @@ button.docx-editor-comment-body {
|
|
|
1112
1112
|
outline: none;
|
|
1113
1113
|
}
|
|
1114
1114
|
|
|
1115
|
+
/*
|
|
1116
|
+
* A run holding no characters takes no width, unless its own properties paint a background: then
|
|
1117
|
+
* it is a short blank in that colour, the place a form leaves for text to be written in. The run
|
|
1118
|
+
* around it paints the colour, so the box only has to be wide.
|
|
1119
|
+
*/
|
|
1120
|
+
.docx-editor-empty-run {
|
|
1121
|
+
display: inline-block;
|
|
1122
|
+
width: 0;
|
|
1123
|
+
vertical-align: baseline;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
.docx-editor-run[data-paints] > .docx-editor-empty-run {
|
|
1127
|
+
width: var(--docx-editor-empty-run-width, 1em);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1115
1130
|
/*
|
|
1116
1131
|
* A preserved fragment inside a paragraph or inside a run. What it draws is the `display` the
|
|
1117
1132
|
* preservation rule gave it (`docx/importPolicy`), so the rule is read here as an attribute
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portone/docx-editor",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "A simple DOCX editor for React, built directly on OOXML.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@biomejs/biome": "2.5.14",
|
|
77
77
|
"@changesets/changelog-github": "^1.0.0",
|
|
78
78
|
"@changesets/cli": "^3.0.1",
|
|
79
|
-
"@microsoft/api-extractor": "7.59.
|
|
79
|
+
"@microsoft/api-extractor": "7.59.2",
|
|
80
80
|
"@playwright/test": "^1.62.1",
|
|
81
81
|
"@types/jsdom": "^30.0.0",
|
|
82
82
|
"@types/node": "^26.2.0",
|