@portone/docx-editor 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +159 -0
- package/assets/editor.png +0 -0
- package/dist/DocxEditor.d.ts +1 -1
- package/dist/DocxEditor.js +44 -25
- package/dist/docx/cloning.js +4 -9
- package/dist/docx/commentOnlyChange.d.ts +5 -3
- package/dist/docx/comments/grammar.d.ts +27 -10
- package/dist/docx/comments/grammar.js +18 -67
- package/dist/docx/comments/model.d.ts +5 -6
- package/dist/docx/comments/model.js +0 -9
- package/dist/docx/comments/parts.d.ts +16 -10
- package/dist/docx/comments/parts.js +65 -13
- package/dist/docx/comments/people.d.ts +11 -3
- package/dist/docx/comments/people.js +20 -6
- package/dist/docx/comments/policy.js +7 -1
- package/dist/docx/comments/reading.d.ts +4 -2
- package/dist/docx/comments/reading.js +1 -14
- package/dist/docx/comments/writing.js +65 -28
- package/dist/docx/exportDocx.js +10 -14
- package/dist/docx/exportRefs.d.ts +8 -3
- package/dist/docx/exportRefs.js +2 -1
- package/dist/docx/fidelity.js +24 -10
- package/dist/docx/fields.d.ts +42 -0
- package/dist/docx/fields.js +76 -0
- package/dist/docx/headersFooters.d.ts +89 -20
- package/dist/docx/headersFooters.js +163 -172
- package/dist/docx/importDocx.d.ts +1 -1
- package/dist/docx/importDocx.js +100 -48
- package/dist/docx/importParagraph.d.ts +16 -4
- package/dist/docx/importParagraph.js +87 -93
- package/dist/docx/importPolicy.d.ts +70 -0
- package/dist/docx/importPolicy.js +190 -0
- package/dist/docx/importPreserved.d.ts +30 -0
- package/dist/docx/importPreserved.js +54 -0
- package/dist/docx/importTable.js +56 -12
- package/dist/docx/invariants.js +16 -18
- package/dist/docx/notes.d.ts +6 -1
- package/dist/docx/notes.js +6 -16
- package/dist/docx/pageGeometry.d.ts +5 -14
- package/dist/docx/pageGeometry.js +0 -12
- package/dist/docx/protectionPolicy.d.ts +13 -5
- package/dist/docx/protectionPolicy.js +32 -22
- package/dist/docx/scan.d.ts +18 -8
- package/dist/docx/scan.js +17 -11
- package/dist/docx/sections.d.ts +126 -0
- package/dist/docx/sections.js +207 -0
- package/dist/docx/serializeBlock.d.ts +13 -4
- package/dist/docx/serializeBlock.js +16 -18
- package/dist/docx/serializeParagraph.d.ts +4 -0
- package/dist/docx/serializeParagraph.js +1 -0
- package/dist/docx/serializePreserved.d.ts +14 -0
- package/dist/docx/serializePreserved.js +24 -0
- package/dist/docx/serializeStory.d.ts +17 -0
- package/dist/docx/serializeStory.js +17 -0
- package/dist/docx/serializeTable.js +10 -13
- package/dist/docx/session.d.ts +23 -6
- package/dist/docx/session.js +26 -5
- package/dist/docx/story.d.ts +140 -0
- package/dist/docx/story.js +237 -0
- package/dist/docx/storyProjection.js +6 -1
- package/dist/editor/clipboard/htmlReader.d.ts +30 -0
- package/dist/editor/{externalClipboard.js → clipboard/htmlReader.js} +39 -223
- package/dist/editor/clipboard/internalChannel.d.ts +57 -0
- package/dist/editor/clipboard/internalChannel.js +58 -0
- package/dist/editor/clipboard/normalizers.d.ts +99 -0
- package/dist/editor/clipboard/normalizers.js +199 -0
- package/dist/editor/clipboard/parser.d.ts +34 -0
- package/dist/editor/clipboard/parser.js +58 -0
- package/dist/editor/clipboard/plugin.d.ts +21 -0
- package/dist/editor/clipboard/plugin.js +320 -0
- package/dist/editor/clipboard/readContext.d.ts +24 -0
- package/dist/editor/clipboard/readContext.js +19 -0
- package/dist/editor/clipboard/readers.d.ts +33 -0
- package/dist/editor/clipboard/readers.js +37 -0
- package/dist/editor/commands/comments/editing.d.ts +26 -6
- package/dist/editor/commands/comments/editing.js +175 -105
- package/dist/editor/commands/comments/model.d.ts +34 -17
- package/dist/editor/commands/comments/model.js +11 -0
- package/dist/editor/commands/comments/reading.d.ts +5 -3
- package/dist/editor/commands/comments/reading.js +8 -58
- package/dist/editor/commands/index.d.ts +2 -2
- package/dist/editor/commands/index.js +2 -0
- package/dist/editor/commands/listCommands.d.ts +6 -0
- package/dist/editor/commands/listCommands.js +3 -2
- package/dist/editor/commands/noteQueries.d.ts +22 -5
- package/dist/editor/commands/noteQueries.js +34 -6
- package/dist/editor/createEditor.js +13 -3
- package/dist/editor/documentStyles.d.ts +26 -4
- package/dist/editor/documentStyles.js +9 -4
- package/dist/editor/imageFiles.d.ts +2 -2
- package/dist/editor/imageFiles.js +2 -0
- package/dist/editor/insertTable.d.ts +1 -1
- package/dist/editor/insertTable.js +2 -2
- package/dist/editor/plainText.d.ts +12 -0
- package/dist/editor/plainText.js +2 -1
- package/dist/editor/plugins/columnResize.js +6 -3
- package/dist/editor/plugins/commentComposer.d.ts +28 -0
- package/dist/editor/plugins/commentComposer.js +46 -0
- package/dist/editor/plugins/commentDecorations.d.ts +29 -2
- package/dist/editor/plugins/commentDecorations.js +89 -15
- package/dist/editor/plugins/documentProjection.d.ts +31 -0
- package/dist/editor/plugins/documentProjection.js +22 -0
- package/dist/editor/plugins/imagePaste.js +15 -8
- package/dist/editor/plugins/linkPanel.d.ts +7 -3
- package/dist/editor/plugins/linkPanel.js +13 -27
- package/dist/editor/plugins/panelState.d.ts +67 -0
- package/dist/editor/plugins/panelState.js +54 -0
- package/dist/editor/plugins/tableContextMenu.d.ts +1 -1
- package/dist/editor/plugins/tableContextMenu.js +30 -47
- package/dist/editor/plugins/textContextMenu.d.ts +1 -1
- package/dist/editor/plugins/textContextMenu.js +30 -47
- package/dist/ooxml/fragment.d.ts +11 -0
- package/dist/ooxml/fragment.js +14 -4
- package/dist/ooxml/image.d.ts +3 -4
- package/dist/ooxml/image.js +50 -5
- package/dist/ooxml/names.d.ts +6 -0
- package/dist/ooxml/names.js +2 -0
- package/dist/ooxml/props.d.ts +8 -0
- package/dist/ooxml/props.js +14 -4
- package/dist/ooxml/rangeMarkers.d.ts +5 -0
- package/dist/ooxml/rangeMarkers.js +24 -0
- package/dist/page/PageGuides.d.ts +7 -3
- package/dist/page/PageGuides.js +13 -24
- package/dist/page/pageLayout.d.ts +64 -5
- package/dist/page/pageLayout.js +90 -29
- package/dist/page/usePageLayout.d.ts +14 -4
- package/dist/page/usePageLayout.js +19 -20
- package/dist/schema/attrRoles.js +38 -20
- package/dist/schema/docxSchema.d.ts +9 -1
- package/dist/schema/docxSchema.js +191 -139
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +2 -2
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/preservedFragments.d.ts +12 -0
- package/dist/schema/preservedFragments.js +38 -0
- package/dist/schema/preservedGuards.d.ts +9 -7
- package/dist/schema/preservedGuards.js +112 -11
- package/dist/schema/protection.d.ts +34 -5
- package/dist/schema/protection.js +42 -14
- package/dist/schema/rendering.js +3 -1
- package/dist/schema/stories.d.ts +49 -0
- package/dist/schema/stories.js +78 -0
- package/dist/styles/classNames.d.ts +3 -5
- package/dist/styles/classNames.js +3 -5
- package/dist/styles.css +74 -12
- package/dist/table/resize.d.ts +5 -3
- package/dist/ui/CommentsPanel.d.ts +1 -3
- package/dist/ui/CommentsPanel.js +24 -15
- package/dist/ui/NotesPanel.js +2 -2
- package/dist/ui/TextMenu.d.ts +1 -3
- package/dist/ui/TextMenu.js +10 -6
- package/dist/ui/comments/CommentComposer.d.ts +6 -1
- package/dist/ui/comments/CommentComposer.js +26 -3
- package/package.json +1 -1
- package/dist/editor/externalClipboard.d.ts +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,164 @@
|
|
|
1
1
|
# @portone/docx-editor
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#105](https://github.com/portone-io/docx-editor/pull/105) [`efe7dbf`](https://github.com/portone-io/docx-editor/commit/efe7dbf6f2cb260ee912dbaed4c518c11b3527b7) Thanks [@Deea222](https://github.com/Deea222)! - Keep markup the editor cannot model where it stood, instead of standing the paragraph around it down.
|
|
8
|
+
|
|
9
|
+
Opening a document used to walk a handful of element names and give up on the rest, and giving up
|
|
10
|
+
travelled outward until a whole paragraph became an "Unsupported content" placeholder. A word
|
|
11
|
+
processor writes a `w:lastRenderedPageBreak` on every page it lays out, so a real document opened
|
|
12
|
+
with one locked paragraph per page.
|
|
13
|
+
|
|
14
|
+
Every level of the document now has a preservation rule of its own. A run child stays inside its
|
|
15
|
+
run, a paragraph child beside the runs, a block stays a block, and only a marker or a wrapper
|
|
16
|
+
standing between the rows or the cells of a table - where there is no node to keep it in - still
|
|
17
|
+
stands the table down. What is left shows as a small box naming the element it stands for, or as
|
|
18
|
+
nothing where the file drew nothing, and the paragraph around it stays editable.
|
|
19
|
+
|
|
20
|
+
- A field code and its drawn result, a tracked insertion or deletion, a symbol, a positional tab
|
|
21
|
+
and a content control the editor could not take apart are visible where they stand.
|
|
22
|
+
- Bookmarks, permission ranges, the markers of a moved passage and the pieces of a field cannot be
|
|
23
|
+
removed by an edit; a tracked-change container, a simple field and a symbol can be selected and
|
|
24
|
+
deleted whole.
|
|
25
|
+
- `documentFidelity` and the `notes` of `importDocx` now report `preserved-run-content`, and no
|
|
26
|
+
longer report `paragraph-demoted` for a document being opened.
|
|
27
|
+
- New node `rawRunContent`, and `rawInline` gains the attrs `element`, `display`, `text` and
|
|
28
|
+
`guarded`. A plugin reading the document model sees both.
|
|
29
|
+
- A footnote body, a comment body and a header now read a `w:cr` and a `w:noBreakHyphen` the way
|
|
30
|
+
the document body does.
|
|
31
|
+
|
|
32
|
+
- [#106](https://github.com/portone-io/docx-editor/pull/106) [`f2871cd`](https://github.com/portone-io/docx-editor/commit/f2871cd5535780c10574906c9dceb2b3ecc4715c) Thanks [@Deea222](https://github.com/Deea222)! - The comment composer keeps the text it was opened over while the document is edited elsewhere, and closes when that text is deleted or the mode turns read-only. The comment is written on that text rather than on whatever is selected when the writer submits.
|
|
33
|
+
|
|
34
|
+
Opening the composer no longer scrolls the document back to its first page.
|
|
35
|
+
|
|
36
|
+
`addComment` and `canAddComment` take an optional `{ from, to }` range as their last argument, which a composer of your own can hold across edits the same way; the current selection is still used when none is given.
|
|
37
|
+
|
|
38
|
+
- [#116](https://github.com/portone-io/docx-editor/pull/116) [`4d9964d`](https://github.com/portone-io/docx-editor/commit/4d9964d59ce66ce52dac06b86968b8ee20dc4f2d) Thanks [@Deea222](https://github.com/Deea222)! - Comment bodies keep their formatting when edited, and `setCommentBody` accepts a formatted body.
|
|
39
|
+
|
|
40
|
+
**Breaking:** the `commentReference` node loses its `text`, `commentXml` and `imported` attrs and
|
|
41
|
+
the `noteReference` node loses its `text` attr, together with the `data-comment-text`,
|
|
42
|
+
`data-comment-xml`, `data-comment-imported` and `data-note-text` attributes that carried them into
|
|
43
|
+
the DOM. A plugin that matched any of those reads what a comment or a note says through
|
|
44
|
+
`documentComments` and `documentNotes` instead, which answer as they always did.
|
|
45
|
+
|
|
46
|
+
**Breaking:** `DocumentComment`, `DocumentCommentReply` and `DocumentNote` declare every field
|
|
47
|
+
`readonly`. They are the editor's own records, worked out once per edit and handed out rather than
|
|
48
|
+
copied, so a caller that was writing into one copies it first.
|
|
49
|
+
|
|
50
|
+
A side story - a comment's body, a footnote's - is now read the way the document body is: the same
|
|
51
|
+
block readers, the same verbatim slices, one document of the editor's own schema per story. It
|
|
52
|
+
stands on the document node under `doc.attrs.stories`, so an edit to it rides a transaction and
|
|
53
|
+
lands in the history, and everything the edit did not touch is written back as the bytes it arrived
|
|
54
|
+
as. Editing a comment used to flatten its body to plain text and rewrite it as one run, which lost
|
|
55
|
+
its bold, its paragraph style and its second paragraph.
|
|
56
|
+
|
|
57
|
+
`setCommentBody(id, body)` is a new command on `./commands`. It takes a `doc` node of `docxSchema`,
|
|
58
|
+
which is what a composer of your own builds a formatted body as; `updateComment(id, text)` stays
|
|
59
|
+
what it was for a body that is only text.
|
|
60
|
+
|
|
61
|
+
Dropping those attrs is what the story replaces them with: what a comment or a note says is no
|
|
62
|
+
longer written on the node marking where it stands, so nothing has to keep the two in step, a copy
|
|
63
|
+
of the node no longer carries the body along with it, and neither reaches the clipboard.
|
|
64
|
+
|
|
65
|
+
- [#108](https://github.com/portone-io/docx-editor/pull/108) [`d783e24`](https://github.com/portone-io/docx-editor/commit/d783e2485eaf6bbbacc3498202019ab053f4e7da) Thanks [@Deea222](https://github.com/Deea222)! - Keep a table whose markers stand between its rows or its cells, and stand every block the editor
|
|
66
|
+
cannot model as one kind of placeholder.
|
|
67
|
+
|
|
68
|
+
**Breaking:** the `docxRaw` and `bookmarkBlock` node types no longer exist. Both were placeholders
|
|
69
|
+
for a block nobody could read, differing only in where the block stood and whether anything of it
|
|
70
|
+
was drawn, and `rawBlock` is now the one node for all of them. A plugin that matched either name
|
|
71
|
+
matches `rawBlock` instead and reads `display` (`"chip"` for a placeholder box, `"hidden"` for a
|
|
72
|
+
marker that draws nothing) and `guarded` to tell them apart. The class names
|
|
73
|
+
`docx-editor-bookmark-block`, `docx-editor-raw-xml` and `docx-editor-table` are gone with them;
|
|
74
|
+
every placeholder now draws as `docx-editor-raw-block`.
|
|
75
|
+
|
|
76
|
+
- A bookmark spanning a table column stands under the row rather than inside a cell, and used to
|
|
77
|
+
cost the whole table its structure. Such a table now opens as a table, and the marker goes back
|
|
78
|
+
exactly where it stood. A marker following a cell that only continues a vertical merge is the
|
|
79
|
+
remaining exception, since that cell is created fresh on export.
|
|
80
|
+
- `documentFidelity` and the `notes` of `importDocx` no longer report `table-demoted` for a table
|
|
81
|
+
whose only unread markup is a marker.
|
|
82
|
+
- A placeholder can now be moved between the body and a table cell and still export.
|
|
83
|
+
- `table` and `tableRow` gain a `leadingXml` attr, `tableRow` and `tableCell` a `trailingXml` attr:
|
|
84
|
+
the markers each carries between its children.
|
|
85
|
+
|
|
86
|
+
Table markers remain protected against deletion, duplication and reordering, including markers
|
|
87
|
+
whose ranges cross into a cell paragraph. Export checks read those fragments in document order.
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#109](https://github.com/portone-io/docx-editor/pull/109) [`05e9431`](https://github.com/portone-io/docx-editor/commit/05e9431c5ba773fa9f751860cbf34760b191d91a) Thanks [@Deea222](https://github.com/Deea222)! - Cache comment and note lists between document edits. Public readers continue to return independent comment, reply, and note records, so changes to their results cannot alter the editor's cached data.
|
|
92
|
+
|
|
93
|
+
- [#118](https://github.com/portone-io/docx-editor/pull/118) [`7de8870`](https://github.com/portone-io/docx-editor/commit/7de8870596bf4b311ab4b9fe4f19fb1291d37dbb) Thanks [@Deea222](https://github.com/Deea222)! - Every section now previews the headers and footers it names. A document whose second section
|
|
94
|
+
selects a header of its own used to draw the first section's on every page, because only the first
|
|
95
|
+
section's references were ever resolved.
|
|
96
|
+
|
|
97
|
+
A header and a footer body is read the way the document body is: the same block readers, the same
|
|
98
|
+
verbatim slices, one story per part on the document node beside the comment and footnote stories.
|
|
99
|
+
The plain-text walker each of them used to have is gone, so a `w:cr`, a no-break hyphen and a field
|
|
100
|
+
read the same in a header as they do anywhere else, and a `PAGE` or `NUMPAGES` field is now found by
|
|
101
|
+
pairing the field characters it is written between rather than by scanning the text they surround.
|
|
102
|
+
|
|
103
|
+
A header story the editor rewrote is written back into its own part, around the two ends that part
|
|
104
|
+
arrived with, and every part nobody rewrote is repacked as the bytes it came as. Editing a header is
|
|
105
|
+
not offered in the editor yet; this is the model and the export path underneath it.
|
|
106
|
+
|
|
107
|
+
- [#115](https://github.com/portone-io/docx-editor/pull/115) [`9c5331d`](https://github.com/portone-io/docx-editor/commit/9c5331d543b3238f9859c60f5821e7b94fe52bba) Thanks [@Deea222](https://github.com/Deea222)! - Copying and pasting inside the same document now keeps what it was copied as: paragraph and character formatting, tabs, breaks, images, links, and whole tables, instead of the part an HTML reader could make out. Copying a grid of cells and pasting it over selected cells fills them in place. Comment markers, bookmarks, and note references are not copied, so cutting and pasting them back drops them. A pasted list whose numbering the document no longer defines is given a number that it does, keeping the bullets or numbers it was copied with; a list arriving from another document or application is renumbered by the reader that reads it. Content copied from another document, including a second editor on the same page, still comes in through that reader.
|
|
108
|
+
|
|
109
|
+
- [#119](https://github.com/portone-io/docx-editor/pull/119) [`9b4b3fc`](https://github.com/portone-io/docx-editor/commit/9b4b3fc72ca51b89adf81063ca7fb2fb2c126e3f) Thanks [@Deea222](https://github.com/Deea222)! - Page boundaries and table widths now follow the paper of the section a block sits in. A document
|
|
110
|
+
whose second section is landscape used to be paginated as though the whole of it were the first
|
|
111
|
+
section's portrait paper, and a table put in that section was divided into the upright body width
|
|
112
|
+
and could not be widened past it.
|
|
113
|
+
|
|
114
|
+
Each page is now as tall as the body its own section leaves, a section break starts a new page
|
|
115
|
+
unless it is marked continuous, and a table is fitted to the body width of the section it is
|
|
116
|
+
inserted or dragged in. An image pasted into a section is fitted to the height that section's paper
|
|
117
|
+
leaves. A page number still carries on across a section boundary rather than restarting where the
|
|
118
|
+
section asks.
|
|
119
|
+
|
|
120
|
+
One sheet is still drawn at one width, the first section's, because nothing draws two paper widths
|
|
121
|
+
on one sheet. A landscape section is therefore paginated on landscape pages but drawn on the
|
|
122
|
+
sheet's width, and a table wider than the sheet's body is drawn shrunk to fit it while the document
|
|
123
|
+
keeps the width it was given. An even-page or odd-page start is preserved and exported untouched
|
|
124
|
+
but drawn as an ordinary new page.
|
|
125
|
+
|
|
126
|
+
- [#110](https://github.com/portone-io/docx-editor/pull/110) [`272cd5c`](https://github.com/portone-io/docx-editor/commit/272cd5c55098ef4c62e352fc9837b3db807c1439) Thanks [@Deea222](https://github.com/Deea222)! - Keep a picture's extension lists intact when the image is resized.
|
|
127
|
+
|
|
128
|
+
A picture written by Word often carries extension lists - the small records a word processor
|
|
129
|
+
attaches to a picture to remember things the format has no field for, such as which application
|
|
130
|
+
created it or what resolution to keep it at. Resizing such an image used to overwrite the name of
|
|
131
|
+
any empty record with the image's new size, which left the document with content Word reads as
|
|
132
|
+
invalid. Only the two sizes an image is drawn from are rewritten now, and every extension record
|
|
133
|
+
goes back out exactly as it came in.
|
|
134
|
+
|
|
135
|
+
Size updates follow the picture’s own XML paths, so an extension’s nested transforms and size
|
|
136
|
+
records stay unchanged too. Size attributes retain their quoting and surrounding markup.
|
|
137
|
+
|
|
138
|
+
- [#112](https://github.com/portone-io/docx-editor/pull/112) [`0327d4d`](https://github.com/portone-io/docx-editor/commit/0327d4dabe1de5814d440bf21f89cf5e5d1308b9) Thanks [@Deea222](https://github.com/Deea222)! - Give a document's sections a model of their own. Every `w:sectPr` is now read once - its paper and
|
|
139
|
+
margins, the header and footer stories it selects, whether the first page differs, and the page
|
|
140
|
+
number it starts at - instead of being read twice by two readers that looked for it differently.
|
|
141
|
+
|
|
142
|
+
The section that closes the body rides on the document node as `sectPr` rather than in the
|
|
143
|
+
preserved tail. It is written straight back out, so an untouched document still exports byte for
|
|
144
|
+
byte, and a submission that rewrites the paper it is written on is refused by
|
|
145
|
+
`onlyCommentsChangedBy` as it was before.
|
|
146
|
+
|
|
147
|
+
Pressing Enter in the last paragraph of a section continues to leave the break on the later half,
|
|
148
|
+
now on the same reading of `w:pPr` the rest of the package uses.
|
|
149
|
+
|
|
150
|
+
- [#111](https://github.com/portone-io/docx-editor/pull/111) [`4357635`](https://github.com/portone-io/docx-editor/commit/435763591d456ec26f6466b5e69ecc226a20f743) Thanks [@Deea222](https://github.com/Deea222)! - Take a comment added to a document whose author shares your display name, instead of refusing the whole save.
|
|
151
|
+
A document an older Word wrote has no people part, so its comments name an author and nobody in particular.
|
|
152
|
+
Adding a comment under one of those names no longer records a person for it, which had handed the comments already there to whoever commented next, and `onlyCommentsChangedBy` now takes such a comment back rather than reading it as a forged author.
|
|
153
|
+
Every comment carrying a shared name, the new one included, stays everyone's to edit.
|
|
154
|
+
This also protects comments preserved outside the editable story: their authors are not assigned to a new commenter, and the verifier rejects a people record that would claim them.
|
|
155
|
+
|
|
156
|
+
- [#113](https://github.com/portone-io/docx-editor/pull/113) [`e61185e`](https://github.com/portone-io/docx-editor/commit/e61185e645b06ce5091e59b08c5926fcaf71da16) Thanks [@Deea222](https://github.com/Deea222)! - Pasting text over selected table cells now fills every selected cell instead of only the first. Pasting the clipboard's plain text (Ctrl/Cmd+Shift+V) ignores accompanying HTML and images. Right-click Paste passes the clipboard's HTML and text through the same handlers as Ctrl/Cmd+V, including image loading and text fallback. Unreadable clipboard content leaves the selection intact when there is no usable text fallback.
|
|
157
|
+
|
|
158
|
+
- [#117](https://github.com/portone-io/docx-editor/pull/117) [`faf4081`](https://github.com/portone-io/docx-editor/commit/faf4081b43cbfd111985b1aa124e0e90b4136fc9) Thanks [@Deea222](https://github.com/Deea222)! - A hyperlink whose text is already underlined, which is how a word processor writes one, is drawn with one line under it rather than two. The editor's own link line is still drawn under a link the document leaves unstyled.
|
|
159
|
+
|
|
160
|
+
- [#106](https://github.com/portone-io/docx-editor/pull/106) [`f2871cd`](https://github.com/portone-io/docx-editor/commit/f2871cd5535780c10574906c9dceb2b3ecc4715c) Thanks [@Deea222](https://github.com/Deea222)! - Reject invalid comment range positions without throwing or adding a comment at a rounded position.
|
|
161
|
+
|
|
3
162
|
## 0.4.0
|
|
4
163
|
|
|
5
164
|
### Minor Changes
|
package/assets/editor.png
CHANGED
|
Binary file
|
package/dist/DocxEditor.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { EditorView } from "prosemirror-view";
|
|
|
12
12
|
import { type CSSProperties, type ReactNode } from "react";
|
|
13
13
|
import { type DocxSource } from "./docx/importDocx";
|
|
14
14
|
import { type ExportProblem } from "./docx/invariants";
|
|
15
|
-
import {
|
|
15
|
+
import type { CommentAuthor } from "./editor/commands/commentCommands";
|
|
16
16
|
import { DocxImportError } from "./ooxml/errors";
|
|
17
17
|
import type { EditableComments } from "./schema/protection";
|
|
18
18
|
import type { FontFallbacks } from "./styles/fontStack";
|
package/dist/DocxEditor.js
CHANGED
|
@@ -9,22 +9,27 @@ import {
|
|
|
9
9
|
useState
|
|
10
10
|
} from "react";
|
|
11
11
|
import { exportDocx } from "./docx/exportDocx.js";
|
|
12
|
+
import { variantsFor } from "./docx/headersFooters.js";
|
|
12
13
|
import { importDocx } from "./docx/importDocx.js";
|
|
13
14
|
import { exportProblems } from "./docx/invariants.js";
|
|
14
|
-
import {
|
|
15
|
-
documentComments
|
|
16
|
-
} from "./editor/commands/commentCommands.js";
|
|
15
|
+
import { sectionIn, sectionsOf } from "./docx/sections.js";
|
|
17
16
|
import { activeLinkSpan } from "./editor/commands/linkCommands.js";
|
|
18
17
|
import { createEditorView, editorStateForSession } from "./editor/createEditor.js";
|
|
18
|
+
import {
|
|
19
|
+
closeCommentComposer,
|
|
20
|
+
isCommentComposerOpen
|
|
21
|
+
} from "./editor/plugins/commentComposer.js";
|
|
22
|
+
import { commentProjection } from "./editor/plugins/commentDecorations.js";
|
|
19
23
|
import { setProtection } from "./editor/plugins/documentProtection.js";
|
|
20
24
|
import { isLinkPanelOpen } from "./editor/plugins/linkPanel.js";
|
|
21
25
|
import { tableMenuAnchor } from "./editor/plugins/tableContextMenu.js";
|
|
22
26
|
import { textMenuAnchor } from "./editor/plugins/textContextMenu.js";
|
|
23
27
|
import { DocxImportError } from "./ooxml/errors.js";
|
|
24
28
|
import { PageGuides } from "./page/PageGuides.js";
|
|
25
|
-
import { A4_PAGE_PIXELS, pagePixels } from "./page/pageLayout.js";
|
|
29
|
+
import { A4_PAGE_PIXELS, pagePixels, sectionPixels } from "./page/pageLayout.js";
|
|
26
30
|
import { usePageLayout } from "./page/usePageLayout.js";
|
|
27
31
|
import { editingProtection, protectionOf } from "./schema/protectionState.js";
|
|
32
|
+
import { storyNodeOf } from "./schema/stories.js";
|
|
28
33
|
import { editorClassNames } from "./styles/classNames.js";
|
|
29
34
|
import { CommentsPanel } from "./ui/CommentsPanel.js";
|
|
30
35
|
import { LinkCard } from "./ui/LinkCard.js";
|
|
@@ -36,6 +41,9 @@ import { Toolbar } from "./ui/Toolbar.js";
|
|
|
36
41
|
import { useFitWidthZoom } from "./ui/useFitWidthZoom.js";
|
|
37
42
|
import { normalizeZoom } from "./ui/zoom.js";
|
|
38
43
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
44
|
+
function runOn(view, command) {
|
|
45
|
+
command(view.state, (transaction) => view.dispatch(transaction));
|
|
46
|
+
}
|
|
39
47
|
function affordancesOf(mode) {
|
|
40
48
|
switch (mode.kind) {
|
|
41
49
|
case "readOnly":
|
|
@@ -161,7 +169,6 @@ function DocxEditorSurface({
|
|
|
161
169
|
);
|
|
162
170
|
const viewRef = useRef(null);
|
|
163
171
|
const [live, setLive] = useState(null);
|
|
164
|
-
const [commentComposerOpen, setCommentComposerOpen] = useState(false);
|
|
165
172
|
const [commentsOpen, setCommentsOpen] = useState(false);
|
|
166
173
|
const [uncontrolledZoom, setUncontrolledZoom] = useState(
|
|
167
174
|
() => normalizeZoom(defaultZoom)
|
|
@@ -217,7 +224,6 @@ function DocxEditorSurface({
|
|
|
217
224
|
const authorId = author?.id ?? null;
|
|
218
225
|
const mounted = live !== null;
|
|
219
226
|
useLayoutEffect(() => {
|
|
220
|
-
if (protection === "readOnly") setCommentComposerOpen(false);
|
|
221
227
|
const view = viewRef.current;
|
|
222
228
|
if (!view || !mounted) return;
|
|
223
229
|
const held = protectionOf(view.state);
|
|
@@ -231,40 +237,58 @@ function DocxEditorSurface({
|
|
|
231
237
|
useImperativeHandle(ref, () => {
|
|
232
238
|
const view = viewRef.current;
|
|
233
239
|
if (!view || opened?.status !== "opened") return null;
|
|
234
|
-
const
|
|
240
|
+
const session2 = opened.session;
|
|
235
241
|
return {
|
|
236
242
|
view,
|
|
237
|
-
exportBytes: () => exportDocx(view.state.doc,
|
|
238
|
-
exportProblems: () => exportProblems(view.state.doc,
|
|
243
|
+
exportBytes: () => exportDocx(view.state.doc, session2),
|
|
244
|
+
exportProblems: () => exportProblems(view.state.doc, session2)
|
|
239
245
|
};
|
|
240
246
|
}, [opened]);
|
|
247
|
+
const doc = live?.state.doc ?? null;
|
|
248
|
+
const session = opened?.status === "opened" ? opened.session : null;
|
|
249
|
+
const sections = useMemo(
|
|
250
|
+
() => doc === null ? null : sectionsOf(doc),
|
|
251
|
+
[doc]
|
|
252
|
+
);
|
|
253
|
+
const sectionPapers = useMemo(
|
|
254
|
+
() => sections === null ? void 0 : sectionPixels(sections),
|
|
255
|
+
[sections]
|
|
256
|
+
);
|
|
241
257
|
const overlay = usePageLayout({
|
|
242
258
|
view: live?.view ?? null,
|
|
243
259
|
layer: layerRef,
|
|
244
260
|
enabled: showPageGuides,
|
|
245
261
|
revision: live?.state.doc,
|
|
246
|
-
|
|
262
|
+
sections: sectionPapers
|
|
247
263
|
});
|
|
264
|
+
const headersFootersFor = useMemo(() => {
|
|
265
|
+
if (doc === null || session === null || sections === null) return void 0;
|
|
266
|
+
const shown = sections.map(
|
|
267
|
+
(section) => variantsFor(
|
|
268
|
+
section,
|
|
269
|
+
session.headerFooterStories,
|
|
270
|
+
(key) => storyNodeOf(doc, key)
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
return (face) => shown[sectionIn(sections, doc, face.pos).index] ?? null;
|
|
274
|
+
}, [doc, session, sections]);
|
|
248
275
|
if (opened?.status === "rejected") {
|
|
249
276
|
return renderImportError ? renderImportError(opened.error) : /* @__PURE__ */ jsx(ImportRejection, { error: opened.error });
|
|
250
277
|
}
|
|
251
278
|
const bodyOpen = live !== null && editingProtection(live.state) === "none";
|
|
252
|
-
const commentsOpenToWrite = live !== null && editingProtection(live.state) !== "readOnly";
|
|
253
279
|
const textAnchor = live ? textMenuAnchor(live.state) : null;
|
|
254
280
|
const tableAnchor = live && !textAnchor ? tableMenuAnchor(live.state) : null;
|
|
255
281
|
const linkAtCursor = live && !live.view.composing && !isLinkPanelOpen(live.state) ? activeLinkSpan(live.state) : null;
|
|
256
|
-
const comments = live?.state === void 0 ? [] :
|
|
282
|
+
const comments = live?.state === void 0 ? [] : commentProjection.read(live.state).comments;
|
|
257
283
|
const hasUnresolvedComments = comments.some((comment) => !comment.resolved);
|
|
258
|
-
const
|
|
259
|
-
const showComments = live !== null && (commentsOpen ||
|
|
284
|
+
const composerOpen = live !== null && isCommentComposerOpen(live.state);
|
|
285
|
+
const showComments = live !== null && (commentsOpen || composerOpen || hasUnresolvedComments);
|
|
260
286
|
const commentsPanel = live && showComments && /* @__PURE__ */ jsx(
|
|
261
287
|
CommentsPanel,
|
|
262
288
|
{
|
|
263
289
|
view: live.view,
|
|
264
290
|
state: live.state,
|
|
265
|
-
composerOpen: effectiveComposerOpen,
|
|
266
291
|
author,
|
|
267
|
-
closeComposer: () => setCommentComposerOpen(false),
|
|
268
292
|
scrollContainer: rootRef.current,
|
|
269
293
|
allCommentsOpen: commentsOpen
|
|
270
294
|
}
|
|
@@ -284,10 +308,8 @@ function DocxEditorSurface({
|
|
|
284
308
|
presets,
|
|
285
309
|
commentsOpen,
|
|
286
310
|
onToggleComments: () => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return !open;
|
|
290
|
-
});
|
|
311
|
+
if (commentsOpen) runOn(live.view, closeCommentComposer);
|
|
312
|
+
setCommentsOpen(!commentsOpen);
|
|
291
313
|
},
|
|
292
314
|
zoom: selectedZoom,
|
|
293
315
|
onZoomChange: changeZoom
|
|
@@ -323,7 +345,7 @@ function DocxEditorSurface({
|
|
|
323
345
|
PageGuides,
|
|
324
346
|
{
|
|
325
347
|
overlay,
|
|
326
|
-
|
|
348
|
+
headersFootersFor
|
|
327
349
|
}
|
|
328
350
|
),
|
|
329
351
|
live && opened?.status === "opened" && /* @__PURE__ */ jsx(NotesPanel, { state: live.state, pageWidth: page.pageWidth })
|
|
@@ -352,10 +374,7 @@ function DocxEditorSurface({
|
|
|
352
374
|
view: live.view,
|
|
353
375
|
state: live.state,
|
|
354
376
|
anchor: textAnchor,
|
|
355
|
-
allowLocking: locking
|
|
356
|
-
onAddComment: () => {
|
|
357
|
-
setCommentComposerOpen(true);
|
|
358
|
-
}
|
|
377
|
+
allowLocking: locking
|
|
359
378
|
}
|
|
360
379
|
),
|
|
361
380
|
live && tableAnchor && /* @__PURE__ */ jsx(
|
package/dist/docx/cloning.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/docx/cloning.ts
|
|
2
2
|
import { attrsText, withoutAttrs } from "../ooxml/element.js";
|
|
3
|
-
import { parseProps, renderProps, setChild } from "../ooxml/props.js";
|
|
4
3
|
import { parseAttrs } from "../ooxml/tagScan.js";
|
|
4
|
+
import { withoutSectionBreak } from "./sections.js";
|
|
5
5
|
var carried = (value) => value;
|
|
6
6
|
var defaulted = () => void 0;
|
|
7
7
|
var PARAGRAPH_ID_ATTRS = ["paraId", "textId"];
|
|
@@ -13,13 +13,8 @@ function withoutParagraphIds(value) {
|
|
|
13
13
|
if (kept.length === attrs.length) return value;
|
|
14
14
|
return kept.length === 0 ? null : attrsText(kept);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
const props = parseProps(value);
|
|
19
|
-
if (props === null) return value;
|
|
20
|
-
const without = setChild(props, "sectPr", null);
|
|
21
|
-
if (without.children.length === props.children.length) return value;
|
|
22
|
-
return renderProps(without) || null;
|
|
16
|
+
function droppingSectionBreak(value) {
|
|
17
|
+
return typeof value === "string" ? withoutSectionBreak(value) : value;
|
|
23
18
|
}
|
|
24
19
|
var INHERITED_CELL_ATTRS = ["tcAttrs", "tcPr", "tcW", "format"];
|
|
25
20
|
var INHERITED_ROW_ATTRS = ["trAttrs", "trPr", "format"];
|
|
@@ -48,7 +43,7 @@ var CLONE_POLICIES = {
|
|
|
48
43
|
// A paragraph-level `w:sectPr` ends the section it stands in, so it belongs to whichever
|
|
49
44
|
// paragraph ends up last in that section: the second half of a split, and no half of a copy,
|
|
50
45
|
// which is lifted out of the section it was taken from.
|
|
51
|
-
pPr: (value, side) => side === "after" ? value :
|
|
46
|
+
pPr: (value, side) => side === "after" ? value : droppingSectionBreak(value),
|
|
52
47
|
// What names the block this paragraph was opened from. Only the half still standing where
|
|
53
48
|
// that block stood may go on claiming it; `docx/exportDocx` writes the original bytes back
|
|
54
49
|
// for whatever claims one.
|
|
@@ -34,9 +34,11 @@ export type CommentOnlyVerdict = {
|
|
|
34
34
|
* has to read as it did, comments aside. Those three parts are read entry by entry instead
|
|
35
35
|
* (`./comments/policy`), since a comment edit is free to rewrite them and something has to say
|
|
36
36
|
* what it may have written there. A comment carrying no recorded identity is everyone's to
|
|
37
|
-
* edit here as it is in the editor (`schema/protection`)
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* edit here as it is in the editor (`schema/protection`). A comment that appeared carries this
|
|
38
|
+
* identity, or none under a name an original comment already carried unattributed, including a
|
|
39
|
+
* preserved comment outside the editable story. A file can claim any author, so an addition under
|
|
40
|
+
* any other name must carry the requester's identity. An identity already recorded is nobody's
|
|
41
|
+
* to rewrite, and a new identity cannot claim an original unattributed comment.
|
|
40
42
|
*
|
|
41
43
|
* `editableComments: "all"` judges the file of an editor opened for a moderator, where every
|
|
42
44
|
* comment was theirs to edit; an identity is nobody's to rewrite under either setting.
|
|
@@ -22,13 +22,38 @@ export declare const COMMENT_EX_ATTRIBUTES: ReadonlySet<string>;
|
|
|
22
22
|
* everything it writes.
|
|
23
23
|
*/
|
|
24
24
|
export declare function declarationWritten(attr: Attr): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether this element and everything inside it declares only namespaces this package writes.
|
|
27
|
+
*
|
|
28
|
+
* A declaration decides what every name under it means, so a block rebinding a prefix says one
|
|
29
|
+
* thing to this reader and another to Word, and is a place to put bytes nothing looks at.
|
|
30
|
+
*/
|
|
31
|
+
export declare function declarationsWritten(el: Element): boolean;
|
|
25
32
|
/**
|
|
26
33
|
* Whether the element carries no attribute outside this set, and declares no namespace outside
|
|
27
34
|
* what the writer declares.
|
|
28
35
|
*/
|
|
29
36
|
export declare function attributesWithin(el: Element, allowed: ReadonlySet<string>): boolean;
|
|
30
|
-
/**
|
|
31
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Whether the element holds elements and nothing else.
|
|
39
|
+
*
|
|
40
|
+
* The writer puts no whitespace, comment or stray text between the pieces of a body, so an entry
|
|
41
|
+
* carrying any is one it did not write, and a reading that passed over them would leave a place to
|
|
42
|
+
* put bytes nothing looks at.
|
|
43
|
+
*/
|
|
44
|
+
export declare function holdsElementsOnly(el: Element): boolean;
|
|
45
|
+
/** XML layout whitespace, which is the one text carrying no payload wherever it stands */
|
|
46
|
+
export declare function isLayoutText(node: Node): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the element holds elements and the whitespace a producer laid them out over.
|
|
49
|
+
*
|
|
50
|
+
* A block is sliced with the whitespace standing ahead of it (`docx/scan`), so the writer hands a
|
|
51
|
+
* block it left untouched back with the layout it arrived in, and an entry from a part written
|
|
52
|
+
* over several lines carries that layout between its blocks. Whitespace is the only text this
|
|
53
|
+
* passes over: a comment, a processing instruction or a stretch of real text is a place to put
|
|
54
|
+
* bytes nothing looks at, and none of them is anything the writer puts out.
|
|
55
|
+
*/
|
|
56
|
+
export declare function holdsElementsAndLayout(el: Element): boolean;
|
|
32
57
|
/**
|
|
33
58
|
* The paragraph a thread key belongs on, which is the last one of the body.
|
|
34
59
|
*
|
|
@@ -61,20 +86,12 @@ export declare function arrivedEntries(partXml: string | null): ReadonlyMap<stri
|
|
|
61
86
|
* declares it on its root along with the compatibility markup that goes with it (`./writing`).
|
|
62
87
|
*/
|
|
63
88
|
export declare function withThreadKey(commentXml: string, paraId: string, arrived: Element | null): string;
|
|
64
|
-
/**
|
|
65
|
-
* The text of a comment written in that shape, and null for an entry holding anything else: a
|
|
66
|
-
* field, a second run, markup a producer wrapped it in, an attribute this editor does not write.
|
|
67
|
-
*
|
|
68
|
-
* An entry that arrived and was not edited is compared as it stands rather than read here, so
|
|
69
|
-
* saying no to a shape this editor would not have written turns down only a rewrite.
|
|
70
|
-
*/
|
|
71
89
|
/** Whether this editor's writer could have put out this thread state */
|
|
72
90
|
export declare function wellFormedCommentExtension(entry: Element): boolean;
|
|
73
91
|
/** Whether this editor's writer could have put out this recorded identity */
|
|
74
92
|
export declare function wellFormedPerson(entry: Element): boolean;
|
|
75
93
|
/** The identity a recorded person stands for, and null for an entry recording none */
|
|
76
94
|
export declare function recordedIdentity(person: Element): string | null;
|
|
77
|
-
export declare function readStrictCommentBody(comment: Element): string | null;
|
|
78
95
|
/** The thread state of one comment, as this editor writes it into the extended part */
|
|
79
96
|
export declare function renderCommentExtension(comment: CommentReferenceData | CommentReplyData): string;
|
|
80
97
|
/**
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
// src/docx/comments/grammar.ts
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
elementXml,
|
|
5
|
-
xmlnsAttr
|
|
6
|
-
} from "../../ooxml/element.js";
|
|
7
|
-
import { NAMESPACES, qualify, wName } from "../../ooxml/names.js";
|
|
2
|
+
import { attrsText, elementXml } from "../../ooxml/element.js";
|
|
3
|
+
import { NAMESPACES, qualify } from "../../ooxml/names.js";
|
|
8
4
|
import {
|
|
9
5
|
attributeByLocalName,
|
|
10
6
|
elementChildren,
|
|
11
|
-
escapeXml,
|
|
12
7
|
parseXml,
|
|
13
8
|
W_NS
|
|
14
9
|
} from "../../ooxml/xml.js";
|
|
@@ -16,7 +11,6 @@ import { COMMENT_AUTHOR_PROVIDER, W14_NS, W15_NS } from "./constants.js";
|
|
|
16
11
|
var ELEMENT_NODE = 1;
|
|
17
12
|
var TEXT_NODE = 3;
|
|
18
13
|
var XMLNS_NS = "http://www.w3.org/2000/xmlns/";
|
|
19
|
-
var XML_NS = "http://www.w3.org/XML/1998/namespace";
|
|
20
14
|
var nameKey = (namespace, localName) => `${namespace ?? ""} ${localName}`;
|
|
21
15
|
var COMMENT_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
22
16
|
nameKey(W_NS, "id"),
|
|
@@ -29,12 +23,6 @@ var COMMENT_EX_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
29
23
|
nameKey(W15_NS, "paraIdParent"),
|
|
30
24
|
nameKey(W15_NS, "done")
|
|
31
25
|
]);
|
|
32
|
-
var PARAGRAPH_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
33
|
-
nameKey(W14_NS, "paraId")
|
|
34
|
-
]);
|
|
35
|
-
var TEXT_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
36
|
-
nameKey(XML_NS, "space")
|
|
37
|
-
]);
|
|
38
26
|
var PERSON_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
39
27
|
nameKey(W15_NS, "author")
|
|
40
28
|
]);
|
|
@@ -42,7 +30,6 @@ var PRESENCE_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
42
30
|
nameKey(W15_NS, "providerId"),
|
|
43
31
|
nameKey(W15_NS, "userId")
|
|
44
32
|
]);
|
|
45
|
-
var NO_ATTRIBUTES = /* @__PURE__ */ new Set();
|
|
46
33
|
var THREAD_KEY = /^[0-9A-Fa-f]{8}$/;
|
|
47
34
|
function threadKeyOrNone(el, localName) {
|
|
48
35
|
const value = attributeByLocalName(el, localName);
|
|
@@ -57,6 +44,11 @@ function declarationWritten(attr) {
|
|
|
57
44
|
if (!attr.name.startsWith("xmlns:")) return false;
|
|
58
45
|
return WRITTEN_NAMESPACES.get(attr.name.slice("xmlns:".length)) === attr.value;
|
|
59
46
|
}
|
|
47
|
+
function declarationsWritten(el) {
|
|
48
|
+
return Array.from(el.attributes).every(
|
|
49
|
+
(attr) => !attr.name.startsWith("xmlns") || declarationWritten(attr)
|
|
50
|
+
) && Array.from(el.children).every(declarationsWritten);
|
|
51
|
+
}
|
|
60
52
|
function attributesWithin(el, allowed) {
|
|
61
53
|
return Array.from(el.attributes).every(
|
|
62
54
|
(attr) => attr.namespaceURI === XMLNS_NS ? declarationWritten(attr) : allowed.has(nameKey(attr.namespaceURI, attr.localName))
|
|
@@ -70,22 +62,13 @@ function holdsElementsOnly(el) {
|
|
|
70
62
|
(node) => node.nodeType === ELEMENT_NODE
|
|
71
63
|
);
|
|
72
64
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (index > 0) pieces.push(elementXml(wName("br"), []));
|
|
81
|
-
if (line.length > 0 || lines.length === 1) {
|
|
82
|
-
pieces.push(
|
|
83
|
-
elementXml(wName("t"), [["xml:space", "preserve"]], [escapeXml(line)])
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
const key = paraId === null ? [] : [xmlnsAttr("w14"), [qualify("w14", "paraId"), paraId]];
|
|
88
|
-
return elementXml(wName("p"), key, [elementXml(wName("r"), [], pieces)]);
|
|
65
|
+
function isLayoutText(node) {
|
|
66
|
+
return node.nodeType === TEXT_NODE && /^[ \t\r\n]*$/.test(node.nodeValue ?? "");
|
|
67
|
+
}
|
|
68
|
+
function holdsElementsAndLayout(el) {
|
|
69
|
+
return Array.from(el.childNodes).every(
|
|
70
|
+
(node) => node.nodeType === ELEMENT_NODE || isLayoutText(node)
|
|
71
|
+
);
|
|
89
72
|
}
|
|
90
73
|
var PARAGRAPH_OR_SKIPPED = /<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<([^\s<>/:="']+:)?p(?=[\s/>])[^>]*>/g;
|
|
91
74
|
function lastBodyParagraph(comment) {
|
|
@@ -132,25 +115,6 @@ function withThreadKey(commentXml, paraId, arrived) {
|
|
|
132
115
|
const keyed = opening[0].slice(0, selfClosing ? -2 : -1) + ` ${attrsText([[qualify("w14", "paraId"), paraId]])}` + (selfClosing ? "/>" : ">");
|
|
133
116
|
return commentXml.slice(0, opening.index) + keyed + commentXml.slice(opening.index + opening[0].length);
|
|
134
117
|
}
|
|
135
|
-
function readRunText(run) {
|
|
136
|
-
if (!holdsElementsOnly(run)) return null;
|
|
137
|
-
const pieces = [];
|
|
138
|
-
for (const child of Array.from(run.children)) {
|
|
139
|
-
if (isNamed(child, W_NS, "br")) {
|
|
140
|
-
if (!attributesWithin(child, NO_ATTRIBUTES) || child.childNodes.length > 0) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
pieces.push("\n");
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
if (!isNamed(child, W_NS, "t")) return null;
|
|
147
|
-
if (!attributesWithin(child, TEXT_ATTRIBUTES) || child.getAttributeNS(XML_NS, "space") !== "preserve" || !holdsTextOnly(child)) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
pieces.push(child.textContent ?? "");
|
|
151
|
-
}
|
|
152
|
-
return pieces.join("");
|
|
153
|
-
}
|
|
154
118
|
function wellFormedCommentExtension(entry) {
|
|
155
119
|
return attributesWithin(entry, COMMENT_EX_ATTRIBUTES) && entry.childNodes.length === 0 && threadKeyOrNone(entry, "paraId") && threadKeyOrNone(entry, "paraIdParent") && // The writer says a thread is settled or open, and nothing else `ST_OnOff` would take
|
|
156
120
|
["0", "1", null].includes(attributeByLocalName(entry, "done"));
|
|
@@ -167,21 +131,6 @@ function recordedIdentity(person) {
|
|
|
167
131
|
const [presence] = Array.from(person.children);
|
|
168
132
|
return presence === void 0 ? null : attributeByLocalName(presence, "userId");
|
|
169
133
|
}
|
|
170
|
-
function readStrictCommentBody(comment) {
|
|
171
|
-
if (!holdsElementsOnly(comment)) return null;
|
|
172
|
-
const paragraphs = Array.from(comment.children);
|
|
173
|
-
if (paragraphs.length !== 1) return null;
|
|
174
|
-
const [paragraph] = paragraphs;
|
|
175
|
-
if (!isNamed(paragraph, W_NS, "p")) return null;
|
|
176
|
-
if (!attributesWithin(paragraph, PARAGRAPH_ATTRIBUTES)) return null;
|
|
177
|
-
if (!holdsElementsOnly(paragraph)) return null;
|
|
178
|
-
const runs = Array.from(paragraph.children);
|
|
179
|
-
if (runs.length !== 1) return null;
|
|
180
|
-
const [run] = runs;
|
|
181
|
-
if (!isNamed(run, W_NS, "r")) return null;
|
|
182
|
-
if (!attributesWithin(run, NO_ATTRIBUTES)) return null;
|
|
183
|
-
return readRunText(run);
|
|
184
|
-
}
|
|
185
134
|
function renderCommentExtension(comment) {
|
|
186
135
|
if (comment.extensionXml !== null) return comment.extensionXml;
|
|
187
136
|
const parent = "parentParaId" in comment ? [[qualify("w15", "paraIdParent"), comment.parentParaId]] : [];
|
|
@@ -211,10 +160,12 @@ export {
|
|
|
211
160
|
arrivedEntries,
|
|
212
161
|
attributesWithin,
|
|
213
162
|
declarationWritten,
|
|
163
|
+
declarationsWritten,
|
|
164
|
+
holdsElementsAndLayout,
|
|
165
|
+
holdsElementsOnly,
|
|
166
|
+
isLayoutText,
|
|
214
167
|
lastBodyParagraph,
|
|
215
|
-
readStrictCommentBody,
|
|
216
168
|
recordedIdentity,
|
|
217
|
-
renderCommentBody,
|
|
218
169
|
renderCommentExtension,
|
|
219
170
|
renderPerson,
|
|
220
171
|
wellFormedCommentExtension,
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { Node as PMNode } from "prosemirror-model";
|
|
5
5
|
import type { ImportedComments } from "./reading";
|
|
6
|
+
/**
|
|
7
|
+
* A comment as the reference node in the story carries it: who wrote it, where its thread state
|
|
8
|
+
* hangs, and the replies under it. What it says is not here - a body is a story of its own, held
|
|
9
|
+
* on the document node under `comment:<id>` (`docx/story`).
|
|
10
|
+
*/
|
|
6
11
|
export interface CommentReferenceData {
|
|
7
12
|
id: string;
|
|
8
13
|
author: string | null;
|
|
9
14
|
authorId: string | null;
|
|
10
15
|
initials: string | null;
|
|
11
16
|
date: string | null;
|
|
12
|
-
text: string;
|
|
13
|
-
commentXml: string | null;
|
|
14
|
-
imported: boolean;
|
|
15
17
|
paraId: string;
|
|
16
18
|
resolved: boolean;
|
|
17
19
|
extensionXml: string | null;
|
|
@@ -24,9 +26,6 @@ export interface CommentReplyData {
|
|
|
24
26
|
authorId: string | null;
|
|
25
27
|
initials: string | null;
|
|
26
28
|
date: string | null;
|
|
27
|
-
text: string;
|
|
28
|
-
commentXml: string | null;
|
|
29
|
-
imported: boolean;
|
|
30
29
|
paraId: string;
|
|
31
30
|
parentParaId: string;
|
|
32
31
|
extensionXml: string | null;
|