@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.
Files changed (155) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/assets/editor.png +0 -0
  3. package/dist/DocxEditor.d.ts +1 -1
  4. package/dist/DocxEditor.js +44 -25
  5. package/dist/docx/cloning.js +4 -9
  6. package/dist/docx/commentOnlyChange.d.ts +5 -3
  7. package/dist/docx/comments/grammar.d.ts +27 -10
  8. package/dist/docx/comments/grammar.js +18 -67
  9. package/dist/docx/comments/model.d.ts +5 -6
  10. package/dist/docx/comments/model.js +0 -9
  11. package/dist/docx/comments/parts.d.ts +16 -10
  12. package/dist/docx/comments/parts.js +65 -13
  13. package/dist/docx/comments/people.d.ts +11 -3
  14. package/dist/docx/comments/people.js +20 -6
  15. package/dist/docx/comments/policy.js +7 -1
  16. package/dist/docx/comments/reading.d.ts +4 -2
  17. package/dist/docx/comments/reading.js +1 -14
  18. package/dist/docx/comments/writing.js +65 -28
  19. package/dist/docx/exportDocx.js +10 -14
  20. package/dist/docx/exportRefs.d.ts +8 -3
  21. package/dist/docx/exportRefs.js +2 -1
  22. package/dist/docx/fidelity.js +24 -10
  23. package/dist/docx/fields.d.ts +42 -0
  24. package/dist/docx/fields.js +76 -0
  25. package/dist/docx/headersFooters.d.ts +89 -20
  26. package/dist/docx/headersFooters.js +163 -172
  27. package/dist/docx/importDocx.d.ts +1 -1
  28. package/dist/docx/importDocx.js +100 -48
  29. package/dist/docx/importParagraph.d.ts +16 -4
  30. package/dist/docx/importParagraph.js +87 -93
  31. package/dist/docx/importPolicy.d.ts +70 -0
  32. package/dist/docx/importPolicy.js +190 -0
  33. package/dist/docx/importPreserved.d.ts +30 -0
  34. package/dist/docx/importPreserved.js +54 -0
  35. package/dist/docx/importTable.js +56 -12
  36. package/dist/docx/invariants.js +16 -18
  37. package/dist/docx/notes.d.ts +6 -1
  38. package/dist/docx/notes.js +6 -16
  39. package/dist/docx/pageGeometry.d.ts +5 -14
  40. package/dist/docx/pageGeometry.js +0 -12
  41. package/dist/docx/protectionPolicy.d.ts +13 -5
  42. package/dist/docx/protectionPolicy.js +32 -22
  43. package/dist/docx/scan.d.ts +18 -8
  44. package/dist/docx/scan.js +17 -11
  45. package/dist/docx/sections.d.ts +126 -0
  46. package/dist/docx/sections.js +207 -0
  47. package/dist/docx/serializeBlock.d.ts +13 -4
  48. package/dist/docx/serializeBlock.js +16 -18
  49. package/dist/docx/serializeParagraph.d.ts +4 -0
  50. package/dist/docx/serializeParagraph.js +1 -0
  51. package/dist/docx/serializePreserved.d.ts +14 -0
  52. package/dist/docx/serializePreserved.js +24 -0
  53. package/dist/docx/serializeStory.d.ts +17 -0
  54. package/dist/docx/serializeStory.js +17 -0
  55. package/dist/docx/serializeTable.js +10 -13
  56. package/dist/docx/session.d.ts +23 -6
  57. package/dist/docx/session.js +26 -5
  58. package/dist/docx/story.d.ts +140 -0
  59. package/dist/docx/story.js +237 -0
  60. package/dist/docx/storyProjection.js +6 -1
  61. package/dist/editor/clipboard/htmlReader.d.ts +30 -0
  62. package/dist/editor/{externalClipboard.js → clipboard/htmlReader.js} +39 -223
  63. package/dist/editor/clipboard/internalChannel.d.ts +57 -0
  64. package/dist/editor/clipboard/internalChannel.js +58 -0
  65. package/dist/editor/clipboard/normalizers.d.ts +99 -0
  66. package/dist/editor/clipboard/normalizers.js +199 -0
  67. package/dist/editor/clipboard/parser.d.ts +34 -0
  68. package/dist/editor/clipboard/parser.js +58 -0
  69. package/dist/editor/clipboard/plugin.d.ts +21 -0
  70. package/dist/editor/clipboard/plugin.js +320 -0
  71. package/dist/editor/clipboard/readContext.d.ts +24 -0
  72. package/dist/editor/clipboard/readContext.js +19 -0
  73. package/dist/editor/clipboard/readers.d.ts +33 -0
  74. package/dist/editor/clipboard/readers.js +37 -0
  75. package/dist/editor/commands/comments/editing.d.ts +26 -6
  76. package/dist/editor/commands/comments/editing.js +175 -105
  77. package/dist/editor/commands/comments/model.d.ts +34 -17
  78. package/dist/editor/commands/comments/model.js +11 -0
  79. package/dist/editor/commands/comments/reading.d.ts +5 -3
  80. package/dist/editor/commands/comments/reading.js +8 -58
  81. package/dist/editor/commands/index.d.ts +2 -2
  82. package/dist/editor/commands/index.js +2 -0
  83. package/dist/editor/commands/listCommands.d.ts +6 -0
  84. package/dist/editor/commands/listCommands.js +3 -2
  85. package/dist/editor/commands/noteQueries.d.ts +22 -5
  86. package/dist/editor/commands/noteQueries.js +34 -6
  87. package/dist/editor/createEditor.js +13 -3
  88. package/dist/editor/documentStyles.d.ts +26 -4
  89. package/dist/editor/documentStyles.js +9 -4
  90. package/dist/editor/imageFiles.d.ts +2 -2
  91. package/dist/editor/imageFiles.js +2 -0
  92. package/dist/editor/insertTable.d.ts +1 -1
  93. package/dist/editor/insertTable.js +2 -2
  94. package/dist/editor/plainText.d.ts +12 -0
  95. package/dist/editor/plainText.js +2 -1
  96. package/dist/editor/plugins/columnResize.js +6 -3
  97. package/dist/editor/plugins/commentComposer.d.ts +28 -0
  98. package/dist/editor/plugins/commentComposer.js +46 -0
  99. package/dist/editor/plugins/commentDecorations.d.ts +29 -2
  100. package/dist/editor/plugins/commentDecorations.js +89 -15
  101. package/dist/editor/plugins/documentProjection.d.ts +31 -0
  102. package/dist/editor/plugins/documentProjection.js +22 -0
  103. package/dist/editor/plugins/imagePaste.js +15 -8
  104. package/dist/editor/plugins/linkPanel.d.ts +7 -3
  105. package/dist/editor/plugins/linkPanel.js +13 -27
  106. package/dist/editor/plugins/panelState.d.ts +67 -0
  107. package/dist/editor/plugins/panelState.js +54 -0
  108. package/dist/editor/plugins/tableContextMenu.d.ts +1 -1
  109. package/dist/editor/plugins/tableContextMenu.js +30 -47
  110. package/dist/editor/plugins/textContextMenu.d.ts +1 -1
  111. package/dist/editor/plugins/textContextMenu.js +30 -47
  112. package/dist/ooxml/fragment.d.ts +11 -0
  113. package/dist/ooxml/fragment.js +14 -4
  114. package/dist/ooxml/image.d.ts +3 -4
  115. package/dist/ooxml/image.js +50 -5
  116. package/dist/ooxml/names.d.ts +6 -0
  117. package/dist/ooxml/names.js +2 -0
  118. package/dist/ooxml/props.d.ts +8 -0
  119. package/dist/ooxml/props.js +14 -4
  120. package/dist/ooxml/rangeMarkers.d.ts +5 -0
  121. package/dist/ooxml/rangeMarkers.js +24 -0
  122. package/dist/page/PageGuides.d.ts +7 -3
  123. package/dist/page/PageGuides.js +13 -24
  124. package/dist/page/pageLayout.d.ts +64 -5
  125. package/dist/page/pageLayout.js +90 -29
  126. package/dist/page/usePageLayout.d.ts +14 -4
  127. package/dist/page/usePageLayout.js +19 -20
  128. package/dist/schema/attrRoles.js +38 -20
  129. package/dist/schema/docxSchema.d.ts +9 -1
  130. package/dist/schema/docxSchema.js +191 -139
  131. package/dist/schema/editGuard.d.ts +1 -1
  132. package/dist/schema/guards.js +2 -2
  133. package/dist/schema/index.d.ts +1 -0
  134. package/dist/schema/preservedFragments.d.ts +12 -0
  135. package/dist/schema/preservedFragments.js +38 -0
  136. package/dist/schema/preservedGuards.d.ts +9 -7
  137. package/dist/schema/preservedGuards.js +112 -11
  138. package/dist/schema/protection.d.ts +34 -5
  139. package/dist/schema/protection.js +42 -14
  140. package/dist/schema/rendering.js +3 -1
  141. package/dist/schema/stories.d.ts +49 -0
  142. package/dist/schema/stories.js +78 -0
  143. package/dist/styles/classNames.d.ts +3 -5
  144. package/dist/styles/classNames.js +3 -5
  145. package/dist/styles.css +74 -12
  146. package/dist/table/resize.d.ts +5 -3
  147. package/dist/ui/CommentsPanel.d.ts +1 -3
  148. package/dist/ui/CommentsPanel.js +24 -15
  149. package/dist/ui/NotesPanel.js +2 -2
  150. package/dist/ui/TextMenu.d.ts +1 -3
  151. package/dist/ui/TextMenu.js +10 -6
  152. package/dist/ui/comments/CommentComposer.d.ts +6 -1
  153. package/dist/ui/comments/CommentComposer.js +26 -3
  154. package/package.json +1 -1
  155. package/dist/editor/externalClipboard.d.ts +0 -22
@@ -2,7 +2,6 @@
2
2
  import {
3
3
  useCallback,
4
4
  useEffect,
5
- useMemo,
6
5
  useRef,
7
6
  useState
8
7
  } from "react";
@@ -10,10 +9,10 @@ import { editorCssVariables } from "../styles/classNames.js";
10
9
  import { measureSheet } from "./measureBlocks.js";
11
10
  import { setPageMarks } from "./pageDecorations.js";
12
11
  import {
13
- A4_PAGE_PIXELS,
12
+ A4_SECTION_PIXELS,
14
13
  PAGE_SPLIT_PX,
15
14
  pageLayout,
16
- pagePixels
15
+ sectionPaperAt
17
16
  } from "./pageLayout.js";
18
17
  function useFrameThrottle(run, hold) {
19
18
  const latest = useRef({ run, hold });
@@ -52,46 +51,46 @@ function usePageLayout({
52
51
  layer,
53
52
  enabled,
54
53
  revision,
55
- geometry
54
+ sections
56
55
  }) {
57
56
  const [overlay, setOverlay] = useState(null);
58
- const page = useMemo(
59
- () => geometry ? pagePixels(geometry) : A4_PAGE_PIXELS,
60
- [geometry]
61
- );
57
+ const papers = sections === void 0 || sections.length === 0 ? A4_SECTION_PIXELS : sections;
62
58
  const remeasure = useFrameThrottle(
63
59
  () => {
64
60
  const box = layer.current;
65
61
  if (!view || !box || !enabled) return;
66
62
  const measured = measureSheet(view, box);
67
- const layout = pageLayout({
68
- blocks: measured.blocks,
69
- pageBodyHeight: page.bodyHeight,
70
- pageStep: page.pageStep
71
- });
63
+ const layout = pageLayout({ blocks: measured.blocks, sections: papers });
64
+ const paperOf = (pos) => sectionPaperAt(papers, pos);
65
+ const sheet = paperOf(0);
72
66
  setPageMarks(view, { pushes: layout.pushes, cuts: layout.cuts });
73
- const sheetHeight = measured.contentTop + layout.bodyHeight + measured.contentBottom;
67
+ const sheetHeight = measured.contentTop + layout.bodyHeight + Math.max(measured.contentBottom, layout.marginBottom);
74
68
  box.style.setProperty(editorCssVariables.sheetHeight, `${sheetHeight}px`);
75
69
  const next = {
76
70
  left: measured.left,
77
71
  top: measured.top,
78
72
  width: measured.width,
79
73
  sheetHeight,
74
+ // A gap opens below the page that ends at this place, so it is that page's own margin
75
+ // the band is drawn under
80
76
  marks: layout.splits.map((split) => ({
81
77
  page: split.page,
82
- top: measured.contentTop + split.y + (split.crossed ? 0 : page.marginBottom),
78
+ top: measured.contentTop + split.y + (split.crossed ? 0 : paperOf(layout.pages[split.page - 2]?.pos ?? 0).marginBottom),
83
79
  height: split.crossed ? 0 : PAGE_SPLIT_PX,
84
80
  crossed: split.crossed
85
81
  })),
86
82
  // A page crossed into has no margin, so the place it was split at is its top corner
87
83
  pages: layout.pages.map((start) => {
88
- const paperTop = measured.contentTop + start.bodyStart - (start.crossed ? 0 : page.marginTop);
84
+ const paper = paperOf(start.pos);
85
+ const paperTop = measured.contentTop + start.bodyStart - (start.crossed ? 0 : paper.marginTop);
89
86
  return {
90
87
  page: start.page,
91
- headerTop: paperTop + page.marginTop / 2,
92
- footerTop: paperTop + page.pageHeight - page.marginBottom / 2,
93
- left: page.marginLeft,
94
- width: page.bodyWidth,
88
+ pos: start.pos,
89
+ pageInSection: start.pageInSection,
90
+ headerTop: paperTop + paper.marginTop / 2,
91
+ footerTop: paperTop + paper.pageHeight - paper.marginBottom / 2,
92
+ left: sheet.marginLeft,
93
+ width: sheet.bodyWidth,
95
94
  crossed: start.crossed
96
95
  };
97
96
  })
@@ -4,7 +4,13 @@ var NODE_ATTR_ROLES = {
4
4
  doc: {
5
5
  // The definitions of the lists started while editing. The export writes numbering.xml from
6
6
  // them and nothing derives them again, so they are a source value the document node holds
7
- newLists: { role: "source", class: "model" }
7
+ newLists: { role: "source", class: "model" },
8
+ // The section that closes the body, as the document wrote it. The export writes it back out
9
+ // between the blocks and the tail, so a change to it is a change to the document
10
+ sectPr: { role: "source", class: "preserved" },
11
+ // What each side story currently says. The comment writer puts a comment's back into the
12
+ // Comments part, so a change to one is a change to the document
13
+ stories: { role: "source", class: "model" }
8
14
  },
9
15
  paragraph: {
10
16
  srcId: { role: "session", class: "identity" },
@@ -25,13 +31,18 @@ var NODE_ATTR_ROLES = {
25
31
  styleInside: { role: "display", class: "derived" },
26
32
  styleCellMargins: { role: "display", class: "derived" },
27
33
  styleConditions: { role: "display", class: "derived" },
28
- styleBands: { role: "display", class: "derived" }
34
+ styleBands: { role: "display", class: "derived" },
35
+ // The markers a table and a row carry are content the writer puts back exactly where it
36
+ // stood, so a change to one is a change to the table rather than a display refresh
37
+ leadingXml: { role: "source", class: "preserved" }
29
38
  },
30
39
  tableRow: {
31
40
  trAttrs: { role: "source", class: "preserved" },
32
41
  tblPrEx: { role: "source", class: "preserved" },
33
42
  trPr: { role: "source", class: "preserved" },
34
- format: { role: "display", class: "derived" }
43
+ format: { role: "display", class: "derived" },
44
+ leadingXml: { role: "source", class: "preserved" },
45
+ trailingXml: { role: "source", class: "preserved" }
35
46
  },
36
47
  tableCell: {
37
48
  colspan: { role: "source", class: "model" },
@@ -47,19 +58,15 @@ var NODE_ATTR_ROLES = {
47
58
  // it out of the comparison would let a step that unlocks a cell pass as a re-derivation
48
59
  sdtPrefix: { role: "source", class: "preserved" },
49
60
  sdtContentsLocked: { role: "source", class: "derived" },
50
- sdtDeletionLocked: { role: "source", class: "derived" }
61
+ sdtDeletionLocked: { role: "source", class: "derived" },
62
+ trailingXml: { role: "source", class: "preserved" }
51
63
  },
52
64
  rawBlock: {
53
65
  xml: { role: "source", class: "preserved" },
54
- name: { role: "source", class: "identity" }
55
- },
56
- docxRaw: {
57
66
  srcId: { role: "session", class: "identity" },
58
- name: { role: "session", class: "identity" }
59
- },
60
- bookmarkBlock: {
61
- srcId: { role: "session", class: "identity" },
62
- name: { role: "session", class: "identity" }
67
+ name: { role: "session", class: "identity" },
68
+ display: { role: "session", class: "derived" },
69
+ guarded: { role: "session", class: "derived" }
63
70
  },
64
71
  hardBreak: { brAttrs: { role: "source", class: "preserved" } },
65
72
  image: {
@@ -84,14 +91,11 @@ var NODE_ATTR_ROLES = {
84
91
  authorId: { role: "source", class: "model" },
85
92
  initials: { role: "source", class: "model" },
86
93
  date: { role: "source", class: "model" },
87
- text: { role: "source", class: "model" },
88
- commentXml: { role: "source", class: "preserved" },
89
94
  paraId: { role: "source", class: "identity" },
90
95
  resolved: { role: "source", class: "model" },
91
96
  extensionXml: { role: "source", class: "preserved" },
92
97
  replies: { role: "source", class: "model" },
93
- // Read to decide whether the comment parts are rewritten at all; neither is written
94
- imported: { role: "session", class: "derived" },
98
+ // Read to decide whether the extended comment part is rewritten at all; it is never written
95
99
  threadImported: { role: "session", class: "derived" }
96
100
  },
97
101
  noteReference: {
@@ -99,12 +103,26 @@ var NODE_ATTR_ROLES = {
99
103
  id: { role: "source", class: "identity" },
100
104
  customMarkFollows: { role: "source", class: "model" },
101
105
  referenceXml: { role: "source", class: "preserved" },
102
- // Both come from the notes part as the document was opened, and the writer puts back the
106
+ // Worked out from the notes part as the document was opened, and the writer puts back the
103
107
  // reference alone: a note renumbered around an edit is the same reference it was
104
- label: { role: "display", class: "derived" },
105
- text: { role: "display", class: "derived" }
108
+ label: { role: "display", class: "derived" }
106
109
  },
107
- rawInline: { xml: { role: "source", class: "preserved" } }
110
+ rawRunContent: {
111
+ xml: { role: "source", class: "preserved" },
112
+ // What the fragment is and how it is drawn are read off the preservation table when the
113
+ // document is opened and never worked out again, so they travel with the fragment itself
114
+ element: { role: "session", class: "identity" },
115
+ display: { role: "session", class: "derived" },
116
+ text: { role: "session", class: "derived" },
117
+ guarded: { role: "session", class: "derived" }
118
+ },
119
+ rawInline: {
120
+ xml: { role: "source", class: "preserved" },
121
+ element: { role: "session", class: "identity" },
122
+ display: { role: "session", class: "derived" },
123
+ text: { role: "session", class: "derived" },
124
+ guarded: { role: "session", class: "derived" }
125
+ }
108
126
  };
109
127
  var MARK_ATTR_ROLES = {
110
128
  run: {
@@ -15,4 +15,12 @@ import { Schema } from "prosemirror-model";
15
15
  export { imageNodeSpec, runMarkSpec } from "./rendering";
16
16
  /** Whether this is a page-splitting break (`<w:br w:type="page"/>`). Read straight from the original attribute text */
17
17
  export declare function isPageBreak(brAttrs: unknown): boolean;
18
- export declare const docxSchema: Schema<"bookmarkBlock" | "commentEnd" | "commentReference" | "commentStart" | "doc" | "docxRaw" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
18
+ /**
19
+ * How a preserved fragment is drawn, baked into the node's attrs when the document is opened
20
+ * (`docx/importPolicy`) so that this layer reads a value rather than a vocabulary.
21
+ *
22
+ * `hidden` puts nothing on screen, `text` draws the character the fragment stands for, `break`
23
+ * ends the line where it stood, and `chip` draws a small box naming the element.
24
+ */
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" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;