@portone/docx-editor 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/CONTRIBUTING.md +4 -4
- package/dist/core.d.ts +7 -0
- package/dist/core.js +2 -0
- package/dist/docx/commentOnlyChange.d.ts +4 -4
- package/dist/docx/comments/constants.d.ts +7 -0
- package/dist/docx/comments/constants.js +13 -1
- package/dist/docx/comments/dates.d.ts +22 -0
- package/dist/docx/comments/dates.js +102 -0
- package/dist/docx/comments/durable.d.ts +22 -0
- package/dist/docx/comments/durable.js +138 -0
- package/dist/docx/comments/grammar.d.ts +10 -1
- package/dist/docx/comments/grammar.js +49 -2
- package/dist/docx/comments/model.d.ts +10 -2
- package/dist/docx/comments/model.js +38 -8
- package/dist/docx/comments/parts.d.ts +53 -7
- package/dist/docx/comments/parts.js +163 -20
- package/dist/docx/comments/people.d.ts +1 -1
- package/dist/docx/comments/people.js +5 -15
- package/dist/docx/comments/reading.d.ts +26 -0
- package/dist/docx/comments/reading.js +109 -49
- package/dist/docx/comments/writing.d.ts +2 -7
- package/dist/docx/comments/writing.js +30 -43
- package/dist/docx/compareDocx.d.ts +154 -0
- package/dist/docx/compareDocx.js +218 -0
- package/dist/docx/fidelity.js +2 -4
- package/dist/docx/importParagraph.js +6 -9
- package/dist/docx/invariants.js +19 -6
- package/dist/docx/packageParts.d.ts +2 -0
- package/dist/docx/packageParts.js +5 -1
- package/dist/docx/partPlan.d.ts +12 -0
- package/dist/docx/partPlan.js +19 -1
- package/dist/docx/protectionPolicy.d.ts +33 -5
- package/dist/docx/protectionPolicy.js +93 -47
- package/dist/docx/runProps.d.ts +3 -0
- package/dist/docx/runProps.js +9 -0
- package/dist/docx/sequenceDiff.d.ts +56 -0
- package/dist/docx/sequenceDiff.js +252 -0
- package/dist/docx/serializeParagraph.js +29 -3
- package/dist/docx/storyProjection.d.ts +2 -0
- package/dist/docx/storyProjection.js +10 -9
- package/dist/docx/textDiff.d.ts +24 -0
- package/dist/docx/textDiff.js +38 -0
- package/dist/editor/blockControlEdits.js +4 -4
- package/dist/editor/commands/comments/editing.js +59 -22
- package/dist/editor/commands/comments/model.d.ts +3 -1
- package/dist/editor/createEditor.js +6 -9
- package/dist/editor/editorDocument.d.ts +4 -0
- package/dist/editor/editorDocument.js +10 -0
- package/dist/editor/formatSource.d.ts +17 -0
- package/dist/editor/formatSource.js +74 -0
- package/dist/editor/plugins/caretFormat.d.ts +10 -0
- package/dist/editor/plugins/caretFormat.js +39 -0
- package/dist/editor/plugins/commentDecorations.js +6 -2
- package/dist/editor/plugins/controlContents.d.ts +5 -0
- package/dist/editor/plugins/controlContents.js +120 -13
- package/dist/editor/plugins/emptyRunPointer.d.ts +9 -0
- package/dist/editor/plugins/emptyRunPointer.js +22 -0
- package/dist/editor/plugins/inlinePlugins.d.ts +6 -0
- package/dist/editor/plugins/inlinePlugins.js +19 -0
- package/dist/editor/stories/storyState.js +4 -8
- package/dist/editor/views/runMarkView.d.ts +5 -2
- package/dist/editor/views/runMarkView.js +12 -1
- package/dist/ooxml/errors.d.ts +1 -1
- package/dist/ooxml/names.d.ts +2 -0
- package/dist/ooxml/names.js +2 -0
- package/dist/ooxml/partSplice.d.ts +13 -3
- package/dist/ooxml/partSplice.js +45 -18
- package/dist/schema/attrRoles.js +4 -1
- package/dist/schema/clipboard.js +3 -0
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +52 -4
- package/dist/schema/emptyRuns.d.ts +3 -0
- package/dist/schema/emptyRuns.js +7 -0
- package/dist/schema/locks.d.ts +11 -0
- package/dist/schema/locks.js +2 -0
- package/dist/schema/protection.js +2 -1
- package/dist/styles/classNames.d.ts +4 -0
- package/dist/styles/classNames.js +4 -0
- package/dist/styles/inlineStyle.d.ts +2 -0
- package/dist/styles/inlineStyle.js +10 -4
- package/dist/styles.css +15 -0
- package/dist/ui/CommentsPanel.js +8 -13
- package/dist/ui/comments/commentDate.d.ts +7 -0
- package/dist/ui/comments/commentDate.js +17 -0
- package/package.json +7 -7
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,
|
|
@@ -39,6 +39,7 @@ function bodyOf(attrs, doc) {
|
|
|
39
39
|
author: stringOrNull(attrs.author),
|
|
40
40
|
initials: stringOrNull(attrs.initials),
|
|
41
41
|
date: stringOrNull(attrs.date),
|
|
42
|
+
dateUtc: stringOrNull(attrs.dateUtc),
|
|
42
43
|
body: id === null ? null : storyNodeOf(doc, storyKey("comment", id))
|
|
43
44
|
};
|
|
44
45
|
}
|
|
@@ -100,7 +101,7 @@ function sameIdentity(was, now) {
|
|
|
100
101
|
return was.authorId === now.authorId && was.author === now.author;
|
|
101
102
|
}
|
|
102
103
|
function sameWords(was, now) {
|
|
103
|
-
return sameStory(was.body, now.body) && was.initials === now.initials && was.date === now.date;
|
|
104
|
+
return sameStory(was.body, now.body) && was.initials === now.initials && was.date === now.date && was.dateUtc === now.dateUtc;
|
|
104
105
|
}
|
|
105
106
|
function commentIdentitiesKept(before, after) {
|
|
106
107
|
const now = threadsIn(after);
|
|
@@ -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/dist/ui/CommentsPanel.js
CHANGED
|
@@ -20,18 +20,13 @@ import { commentOwned } from "../schema/protection.js";
|
|
|
20
20
|
import { protectionOf } from "../schema/protectionState.js";
|
|
21
21
|
import { editorClassNames } from "../styles/classNames.js";
|
|
22
22
|
import { CommentComposer, FocusedTextarea } from "./comments/CommentComposer.js";
|
|
23
|
+
import { commentTime, shownCommentDate } from "./comments/commentDate.js";
|
|
23
24
|
import {
|
|
24
25
|
COMPOSER_POSITION,
|
|
25
26
|
useCommentRailLayout
|
|
26
27
|
} from "./comments/useCommentRailLayout.js";
|
|
27
28
|
import { tooltipAttribute } from "./Tooltip.js";
|
|
28
29
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
-
function shownDate(value) {
|
|
30
|
-
if (value === null) return null;
|
|
31
|
-
const date = new Date(value);
|
|
32
|
-
if (Number.isNaN(date.valueOf())) return value;
|
|
33
|
-
return `${date.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
34
|
-
}
|
|
35
30
|
function run(view, command) {
|
|
36
31
|
const applied = command(
|
|
37
32
|
view.state,
|
|
@@ -50,7 +45,7 @@ function shownBesideThePage(comment) {
|
|
|
50
45
|
function CommentIdentity({
|
|
51
46
|
comment
|
|
52
47
|
}) {
|
|
53
|
-
const date =
|
|
48
|
+
const date = shownCommentDate(comment.date);
|
|
54
49
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
55
50
|
/* @__PURE__ */ jsx("span", { className: editorClassNames.commentAuthor, children: comment.author ?? "Unknown author" }),
|
|
56
51
|
date && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: date })
|
|
@@ -79,13 +74,13 @@ function CommentsPanel({
|
|
|
79
74
|
const composerSelectionPos = composerRange?.from ?? -1;
|
|
80
75
|
const visible = useMemo(
|
|
81
76
|
() => allCommentsOpen ? [...comments].sort((left, right) => {
|
|
82
|
-
const leftTime =
|
|
83
|
-
const rightTime =
|
|
84
|
-
if (
|
|
77
|
+
const leftTime = commentTime(left.date);
|
|
78
|
+
const rightTime = commentTime(right.date);
|
|
79
|
+
if (leftTime === null && rightTime === null) {
|
|
85
80
|
return right.referencePos - left.referencePos;
|
|
86
81
|
}
|
|
87
|
-
if (
|
|
88
|
-
if (
|
|
82
|
+
if (leftTime === null) return 1;
|
|
83
|
+
if (rightTime === null) return -1;
|
|
89
84
|
return rightTime - leftTime;
|
|
90
85
|
}) : comments.filter(shownBesideThePage),
|
|
91
86
|
[allCommentsOpen, comments]
|
|
@@ -281,7 +276,7 @@ function CommentsPanel({
|
|
|
281
276
|
children: [
|
|
282
277
|
/* @__PURE__ */ jsxs("div", { className: editorClassNames.commentMeta, children: [
|
|
283
278
|
/* @__PURE__ */ jsx("span", { className: editorClassNames.commentAuthor, children: reply.author ?? "Unknown author" }),
|
|
284
|
-
|
|
279
|
+
shownCommentDate(reply.date) && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: shownCommentDate(reply.date) })
|
|
285
280
|
] }),
|
|
286
281
|
isEditing ? /* @__PURE__ */ jsx(
|
|
287
282
|
FocusedTextarea,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Null for a date that is not an instant as `toISOString` spells one: that is a date the document
|
|
3
|
+
* wrote as no time, which the browser would still read, `2026-02-30` as the second of March.
|
|
4
|
+
*/
|
|
5
|
+
export declare function commentTime(value: string | null): number | null;
|
|
6
|
+
/** In the reader's zone and browser language; a date naming no instant is shown as written */
|
|
7
|
+
export declare function shownCommentDate(value: string | null, locales?: Intl.LocalesArgument): string | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/ui/comments/commentDate.ts
|
|
2
|
+
function commentTime(value) {
|
|
3
|
+
if (value === null) return null;
|
|
4
|
+
const time = Date.parse(value);
|
|
5
|
+
return Number.isNaN(time) || new Date(time).toISOString() !== value ? null : time;
|
|
6
|
+
}
|
|
7
|
+
function shownCommentDate(value, locales) {
|
|
8
|
+
const time = commentTime(value);
|
|
9
|
+
return time === null ? value : new Intl.DateTimeFormat(locales, {
|
|
10
|
+
dateStyle: "medium",
|
|
11
|
+
timeStyle: "short"
|
|
12
|
+
}).format(time);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
commentTime,
|
|
16
|
+
shownCommentDate
|
|
17
|
+
};
|
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",
|
|
@@ -73,15 +73,15 @@
|
|
|
73
73
|
"react": ">=18"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@biomejs/biome": "2.5.
|
|
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",
|
|
83
|
-
"@types/react": "19.
|
|
84
|
-
"@types/react-dom": "19.
|
|
83
|
+
"@types/react": "19.3.0",
|
|
84
|
+
"@types/react-dom": "19.3.0",
|
|
85
85
|
"@vitejs/plugin-react": "^6.0.5",
|
|
86
86
|
"esbuild": "^0.28.1",
|
|
87
87
|
"jsdom": "^30.0.1",
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
"prosemirror-tables": "^1.8.5",
|
|
96
96
|
"prosemirror-transform": "^1.12.0",
|
|
97
97
|
"prosemirror-view": "^1.41.6",
|
|
98
|
-
"react": "^19.
|
|
99
|
-
"react-dom": "^19.
|
|
98
|
+
"react": "^19.3.0",
|
|
99
|
+
"react-dom": "^19.3.0",
|
|
100
100
|
"typescript": "^7.0.2",
|
|
101
101
|
"vite": "^8.0.12",
|
|
102
102
|
"vitest": "^5.0.0"
|