@portone/docx-editor 0.6.0 → 0.6.2

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.
Files changed (146) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/DocxEditor.js +84 -26
  3. package/dist/core.d.ts +4 -3
  4. package/dist/docx/exportDocx.d.ts +3 -2
  5. package/dist/docx/exportDocx.js +6 -10
  6. package/dist/docx/headersFooters.js +35 -23
  7. package/dist/docx/identities.d.ts +30 -0
  8. package/dist/docx/identities.js +43 -10
  9. package/dist/docx/importDocx.js +25 -26
  10. package/dist/docx/importParagraph.d.ts +1 -4
  11. package/dist/docx/importParagraph.js +4 -18
  12. package/dist/docx/invariants.d.ts +13 -10
  13. package/dist/docx/invariants.js +300 -116
  14. package/dist/docx/newLists.js +12 -3
  15. package/dist/docx/notes/newNote.d.ts +39 -0
  16. package/dist/docx/notes/newNote.js +122 -0
  17. package/dist/docx/notes/numbering.d.ts +27 -0
  18. package/dist/docx/notes/numbering.js +113 -0
  19. package/dist/docx/notes/reading.d.ts +58 -0
  20. package/dist/docx/notes/reading.js +98 -0
  21. package/dist/docx/notes/references.d.ts +33 -0
  22. package/dist/docx/notes/references.js +37 -0
  23. package/dist/docx/notes/writing.d.ts +19 -0
  24. package/dist/docx/notes/writing.js +95 -0
  25. package/dist/docx/partPlan.d.ts +3 -0
  26. package/dist/docx/partPlanners.d.ts +13 -0
  27. package/dist/docx/partPlanners.js +48 -0
  28. package/dist/docx/sections.d.ts +5 -0
  29. package/dist/docx/sections.js +7 -2
  30. package/dist/docx/serializeParagraph.js +7 -2
  31. package/dist/docx/serializePreserved.d.ts +5 -1
  32. package/dist/docx/serializePreserved.js +24 -7
  33. package/dist/docx/session.d.ts +5 -0
  34. package/dist/docx/session.js +6 -0
  35. package/dist/docx/storyParts.d.ts +133 -0
  36. package/dist/docx/storyParts.js +314 -0
  37. package/dist/editor/clipboard/htmlReader.d.ts +24 -4
  38. package/dist/editor/clipboard/htmlReader.js +39 -4
  39. package/dist/editor/clipboard/internalChannel.d.ts +30 -3
  40. package/dist/editor/clipboard/internalChannel.js +43 -3
  41. package/dist/editor/clipboard/normalizers.d.ts +35 -8
  42. package/dist/editor/clipboard/normalizers.js +60 -11
  43. package/dist/editor/clipboard/plugin.js +42 -22
  44. package/dist/editor/commands/exportQueries.d.ts +4 -3
  45. package/dist/editor/commands/index.d.ts +2 -1
  46. package/dist/editor/commands/index.js +18 -0
  47. package/dist/editor/commands/noteCommands.d.ts +47 -0
  48. package/dist/editor/commands/noteCommands.js +95 -0
  49. package/dist/editor/commands/noteQueries.d.ts +22 -3
  50. package/dist/editor/commands/noteQueries.js +21 -13
  51. package/dist/editor/createEditor.js +21 -3
  52. package/dist/editor/documentStyles.d.ts +3 -0
  53. package/dist/editor/documentStyles.js +2 -1
  54. package/dist/editor/editorDocument.d.ts +24 -0
  55. package/dist/editor/editorDocument.js +34 -4
  56. package/dist/editor/notes/noteSurface.d.ts +53 -0
  57. package/dist/editor/notes/noteSurface.js +246 -0
  58. package/dist/editor/plugins/compositionSelection.d.ts +20 -0
  59. package/dist/editor/plugins/compositionSelection.js +19 -0
  60. package/dist/editor/plugins/keymap.d.ts +14 -0
  61. package/dist/editor/plugins/keymap.js +13 -1
  62. package/dist/editor/plugins/noteLifecycle.d.ts +18 -0
  63. package/dist/editor/plugins/noteLifecycle.js +117 -0
  64. package/dist/editor/plugins/noteNavigation.d.ts +45 -0
  65. package/dist/editor/plugins/noteNavigation.js +86 -0
  66. package/dist/editor/plugins/noteNumbering.d.ts +13 -0
  67. package/dist/editor/plugins/noteNumbering.js +58 -0
  68. package/dist/editor/plugins/rowResize.js +2 -7
  69. package/dist/editor/plugins/tabLayout.js +2 -7
  70. package/dist/editor/stories/storyMarkup.d.ts +24 -0
  71. package/dist/editor/stories/storyMarkup.js +35 -0
  72. package/dist/editor/stories/storyState.d.ts +34 -0
  73. package/dist/editor/stories/storyState.js +74 -0
  74. package/dist/editor/stories/storyView.d.ts +115 -0
  75. package/dist/editor/stories/storyView.js +144 -0
  76. package/dist/index.d.ts +2 -2
  77. package/dist/numbering/spellers.d.ts +1 -1
  78. package/dist/numbering/spellers.js +6 -1
  79. package/dist/ooxml/errors.d.ts +135 -2
  80. package/dist/ooxml/errors.js +6 -0
  81. package/dist/page/blockKinds.d.ts +23 -4
  82. package/dist/page/demands/footnoteDemands.d.ts +18 -0
  83. package/dist/page/demands/footnoteDemands.js +51 -0
  84. package/dist/page/demands/index.d.ts +43 -0
  85. package/dist/page/demands/index.js +8 -0
  86. package/dist/page/kinds/paragraphKind.js +7 -1
  87. package/dist/page/kinds/tableKind.js +9 -1
  88. package/dist/page/measureBlocks.d.ts +2 -0
  89. package/dist/page/measureBlocks.js +31 -10
  90. package/dist/page/pageDecorations.d.ts +9 -2
  91. package/dist/page/pageDecorations.js +18 -5
  92. package/dist/page/pageLayout.d.ts +77 -1
  93. package/dist/page/pageLayout.js +186 -9
  94. package/dist/page/usePageLayout.d.ts +57 -2
  95. package/dist/page/usePageLayout.js +50 -5
  96. package/dist/schema/attrRoles.js +3 -2
  97. package/dist/schema/docxSchema.js +5 -2
  98. package/dist/schema/editGuard.d.ts +1 -1
  99. package/dist/schema/guards.js +1 -2
  100. package/dist/schema/preservedGuards.d.ts +4 -6
  101. package/dist/schema/preservedGuards.js +0 -9
  102. package/dist/schema/stories.d.ts +42 -2
  103. package/dist/schema/stories.js +28 -5
  104. package/dist/styles/classNames.d.ts +21 -6
  105. package/dist/styles/classNames.js +21 -6
  106. package/dist/styles/inlineStyle.d.ts +7 -0
  107. package/dist/styles/inlineStyle.js +11 -5
  108. package/dist/styles/visualScale.d.ts +19 -0
  109. package/dist/styles/visualScale.js +26 -0
  110. package/dist/styles.css +89 -32
  111. package/dist/ui/InsertImageButton.d.ts +3 -1
  112. package/dist/ui/InsertImageButton.js +3 -2
  113. package/dist/ui/TableMenu.d.ts +5 -2
  114. package/dist/ui/TableMenu.js +18 -1
  115. package/dist/ui/TextMenu.d.ts +5 -2
  116. package/dist/ui/TextMenu.js +21 -6
  117. package/dist/ui/Toolbar.d.ts +17 -2
  118. package/dist/ui/Toolbar.js +23 -10
  119. package/dist/ui/comments/useCommentRailLayout.js +2 -4
  120. package/dist/ui/noteItems.d.ts +21 -0
  121. package/dist/ui/noteItems.js +30 -0
  122. package/dist/ui/notes/NoteAreas.d.ts +73 -0
  123. package/dist/ui/notes/NoteAreas.js +131 -0
  124. package/dist/ui/notes/NoteList.d.ts +25 -0
  125. package/dist/ui/notes/NoteList.js +58 -0
  126. package/dist/ui/notes/StoryRow.d.ts +75 -0
  127. package/dist/ui/notes/StoryRow.js +122 -0
  128. package/dist/ui/notes/noteBands.d.ts +100 -0
  129. package/dist/ui/notes/noteBands.js +142 -0
  130. package/dist/ui/notes/noteHeights.d.ts +10 -0
  131. package/dist/ui/notes/noteHeights.js +24 -0
  132. package/dist/ui/notes/noteSeparator.d.ts +12 -0
  133. package/dist/ui/notes/noteSeparator.js +9 -0
  134. package/dist/ui/notes/useStorySurface.d.ts +68 -0
  135. package/dist/ui/notes/useStorySurface.js +95 -0
  136. package/dist/ui/runCommand.d.ts +8 -1
  137. package/dist/ui/runCommand.js +2 -2
  138. package/dist/ui/shortcutLabels.d.ts +16 -0
  139. package/dist/ui/shortcutLabels.js +9 -0
  140. package/dist/ui/usePageRoom.d.ts +13 -0
  141. package/dist/ui/usePageRoom.js +31 -0
  142. package/package.json +1 -1
  143. package/dist/docx/notes.d.ts +0 -27
  144. package/dist/docx/notes.js +0 -55
  145. package/dist/ui/NotesPanel.d.ts +0 -6
  146. package/dist/ui/NotesPanel.js +0 -33
@@ -37,7 +37,12 @@ import { readLinkTargets } from "./hyperlink.js";
37
37
  import { NO_IMPORT_SOURCES } from "./importParagraph.js";
38
38
  import { readImageSources } from "./media.js";
39
39
  import { NUMBERING_REL_TYPE } from "./newLists.js";
40
- import { readNotes } from "./notes.js";
40
+ import { withNoteLabels } from "./notes/numbering.js";
41
+ import {
42
+ readNoteNumbering,
43
+ readNotes,
44
+ specialNotesOf
45
+ } from "./notes/reading.js";
41
46
  import { readPart, relatedPartPath } from "./packageParts.js";
42
47
  import { A4_PORTRAIT } from "./pageGeometry.js";
43
48
  import { readRelationships } from "./relationships.js";
@@ -215,25 +220,13 @@ function readDocx(input) {
215
220
  );
216
221
  const comments = readComments(parts, mainPartPath);
217
222
  const notes = readNotes(parts, mainPartPath);
218
- const noteLabels = {
219
- footnote: /* @__PURE__ */ new Map(),
220
- endnote: /* @__PURE__ */ new Map()
221
- };
222
- const noteLabel = (kind, id) => {
223
- const labels = noteLabels[kind];
224
- const existing = labels.get(id);
225
- if (existing) return existing;
226
- const label = `${labels.size + 1}`;
227
- labels.set(id, label);
228
- return label;
229
- };
223
+ const noteNumbering = readNoteNumbering(settingsDom);
224
+ const specialNotes = specialNotesOf(notes);
230
225
  const sources = {
231
226
  images: readImageSources(parts, mainPartPath),
232
227
  themeFonts,
233
228
  links: readLinkTargets(parts, mainPartPath),
234
- comments,
235
- notes,
236
- noteLabel
229
+ comments
237
230
  };
238
231
  const sessionId = newSessionId();
239
232
  const headerFooters = readHeaderFooterStories(
@@ -275,14 +268,18 @@ function readDocx(input) {
275
268
  )
276
269
  );
277
270
  }
278
- const doc = docxSchema.nodes.doc.create(
279
- {
280
- sectPr: scan.sectPr,
281
- stories: Object.fromEntries(
282
- Array.from(stories, ([key, story]) => [key, story.doc.toJSON()])
283
- )
284
- },
285
- blockNodes
271
+ const doc = withNoteLabels(
272
+ docxSchema.nodes.doc.create(
273
+ {
274
+ sectPr: scan.sectPr,
275
+ stories: Object.fromEntries(
276
+ Array.from(stories, ([key, story]) => [key, story.doc.toJSON()])
277
+ )
278
+ },
279
+ blockNodes
280
+ ),
281
+ noteNumbering,
282
+ specialNotes
286
283
  );
287
284
  return {
288
285
  doc,
@@ -294,7 +291,7 @@ function readDocx(input) {
294
291
  documentPrefix: scan.prefix,
295
292
  documentSuffix: scan.suffix,
296
293
  documentHadBom: hadBom,
297
- blocks: blockNodes.map((node, i) => ({
294
+ blocks: doc.children.map((node, i) => ({
298
295
  xml: scan.blocks[i]?.xml ?? "",
299
296
  node
300
297
  })),
@@ -308,7 +305,9 @@ function readDocx(input) {
308
305
  comments,
309
306
  commentReferenceIds: new Set(commentReferencesIn(doc).keys()),
310
307
  headerFooterStories: headerFooters.refs,
311
- stories
308
+ stories,
309
+ noteNumbering,
310
+ specialNotes
312
311
  })
313
312
  };
314
313
  }
@@ -19,11 +19,10 @@ import type { Node as PMNode } from "prosemirror-model";
19
19
  import { type ImportedComments } from "./comments/reading";
20
20
  import { type LinkTargets } from "./hyperlink";
21
21
  import type { ImageSources } from "./media";
22
- import { type ImportedNotes, type NoteKind } from "./notes";
23
22
  import { type ThemeFonts } from "./theme";
24
23
  /**
25
24
  * What the body is read with: the images its drawings can point at, the fonts a theme reference
26
- * resolves to, the addresses its links can point at, and the bodies of its comments and notes.
25
+ * resolves to, the addresses its links can point at, and the comments its references name.
27
26
  * They travel together from `docx/importDocx` down through the tables to here.
28
27
  */
29
28
  export interface ImportSources {
@@ -31,8 +30,6 @@ export interface ImportSources {
31
30
  themeFonts: ThemeFonts;
32
31
  links: LinkTargets;
33
32
  comments: ImportedComments;
34
- notes: ImportedNotes;
35
- noteLabel: (kind: NoteKind, id: string) => string;
36
33
  }
37
34
  export declare const NO_IMPORT_SOURCES: ImportSources;
38
35
  /**
@@ -20,7 +20,6 @@ import {
20
20
  preservationOf
21
21
  } from "./importPreserved.js";
22
22
  import { NO_IMAGES } from "./media.js";
23
- import { NO_NOTES, noteById } from "./notes.js";
24
23
  import { NO_THEME_FONTS } from "./theme.js";
25
24
  import { wrapperFits, wrapperKindFor } from "./wrappers.js";
26
25
  function runMark(run, themeFonts) {
@@ -47,7 +46,7 @@ function buildImage(el, marks, images) {
47
46
  marks
48
47
  );
49
48
  }
50
- function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
49
+ function buildModelledRunChild(el, marks, images, comments) {
51
50
  switch (el.localName) {
52
51
  case "t": {
53
52
  const text = el.textContent ?? "";
@@ -102,7 +101,6 @@ function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
102
101
  const id = annotationId(el);
103
102
  if (id === null) return null;
104
103
  const kind = el.localName === "footnoteReference" ? "footnote" : "endnote";
105
- const note = noteById(notes, kind, id);
106
104
  const written = attributeByLocalName(el, "customMarkFollows");
107
105
  const customMarkFollows = written !== null && (ST_OnOff.parse(written) ?? true);
108
106
  return [
@@ -110,7 +108,6 @@ function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
110
108
  {
111
109
  kind,
112
110
  id,
113
- label: note ? noteLabel(kind, id) : "?",
114
111
  customMarkFollows,
115
112
  referenceXml: serializeXml(el)
116
113
  },
@@ -123,7 +120,7 @@ function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
123
120
  return null;
124
121
  }
125
122
  }
126
- function buildRunNodes(run, images, themeFonts, comments, notes, noteLabel, wrappers = []) {
123
+ function buildRunNodes(run, images, themeFonts, comments, wrappers = []) {
127
124
  const mark = runMark(run, themeFonts);
128
125
  const marks = wrappers.reduce(
129
126
  (set, wrapper) => wrapper.addToSet(set),
@@ -134,14 +131,7 @@ function buildRunNodes(run, images, themeFonts, comments, notes, noteLabel, wrap
134
131
  const policy = policyFor(child, "r");
135
132
  if (policy.tier === "model") {
136
133
  if (child.localName === "rPr") continue;
137
- const built = buildModelledRunChild(
138
- child,
139
- marks,
140
- images,
141
- comments,
142
- notes,
143
- noteLabel
144
- );
134
+ const built = buildModelledRunChild(child, marks, images, comments);
145
135
  if (built !== null) {
146
136
  nodes.push(...built);
147
137
  continue;
@@ -176,9 +166,7 @@ var NO_IMPORT_SOURCES = {
176
166
  images: NO_IMAGES,
177
167
  themeFonts: NO_THEME_FONTS,
178
168
  links: NO_LINK_TARGETS,
179
- comments: NO_COMMENTS,
180
- notes: NO_NOTES,
181
- noteLabel: () => "?"
169
+ comments: NO_COMMENTS
182
170
  };
183
171
  function buildModelledInline(child, sources, depth, wrappers) {
184
172
  if (child.localName === "r") {
@@ -187,8 +175,6 @@ function buildModelledInline(child, sources, depth, wrappers) {
187
175
  sources.images,
188
176
  sources.themeFonts,
189
177
  sources.comments,
190
- sources.notes,
191
- sources.noteLabel,
192
178
  wrappers
193
179
  );
194
180
  }
@@ -5,27 +5,30 @@
5
5
  * would throw, so a screen can ask at edit time what `exportDocx` would say. The list is walked in
6
6
  * order and `exportDocx` throws its first entry, which is what keeps the two from disagreeing.
7
7
  *
8
+ * A code covers several situations, so each entry also carries the `ExportProblemReason`
9
+ * (`ooxml/errors`) naming the one that was met and the content it is about. Every place a problem
10
+ * is built names its own, rather than a reader telling them apart by the message.
11
+ *
12
+ * What the writer puts out block by block is the body and every side story a part writer rewrites
13
+ * (`exportScopes`), so the invariants over content are asked of each of those in turn: markup
14
+ * refused in the body is refused just the same out of a footnote or a header.
15
+ *
8
16
  * The checks inspect model attrs and preserved XML without running the writers. Bookmark
9
17
  * fragments and list definitions use the export parser. `assertBookmarkPairs` in `./exportDocx`
10
18
  * and `assertPartsParse` in `./partPlan` remain the final checks over the parts as actually written.
11
19
  */
12
20
  import type { Node as PMNode } from "prosemirror-model";
13
- import type { DocxExportErrorCode } from "../ooxml/errors";
21
+ import type { ExportProblem } from "../ooxml/errors";
14
22
  import type { ExportOptions } from "./exportDocx";
15
23
  import { type DocxSession, type SessionStore } from "./session";
16
- /** One reason the document cannot be written back, with the code `exportDocx` would throw it under */
17
- export interface ExportProblem {
18
- readonly code: DocxExportErrorCode;
19
- readonly message: string;
20
- /** Where the problem stands in the document. Absent for a problem of the package or of the session */
21
- readonly pos?: number;
22
- }
24
+ export type { ExportPartName, ExportProblem, ExportProblemReason, ExportProblemStory, ExportStoryKind, } from "../ooxml/errors";
23
25
  /** The problems as the writer sees them, for a caller already inside the writer's parser scope */
24
26
  export declare function problemsOf(doc: PMNode, session: SessionStore): readonly ExportProblem[];
25
27
  /**
26
28
  * Known reasons writing this document back would be refused, in the order `exportDocx` would
27
- * raise them. An empty list does not rule out failures while writing. Each entry carries the code and message the
28
- * `DocxExportError` would carry, and the position in the document where there is one.
29
+ * raise them. An empty list does not rule out failures while writing. Each entry carries the code
30
+ * and message the `DocxExportError` would carry, the `reason` naming what the refusal is about,
31
+ * and the position in the document where there is one.
29
32
  *
30
33
  * The list definitions are read to tell a new list from one the document already had, so this
31
34
  * needs an XML parser the way `exportDocx` does and takes the same option.