@portone/docx-editor 0.2.0 → 0.3.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 (256) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/CONTRIBUTING.md +9 -1
  3. package/dist/DocxEditor.d.ts +6 -0
  4. package/dist/DocxEditor.js +12 -29
  5. package/dist/core.d.ts +23 -8
  6. package/dist/core.js +9 -4
  7. package/dist/docx/cloning.d.ts +38 -0
  8. package/dist/docx/cloning.js +74 -0
  9. package/dist/docx/commentOnlyChange.d.ts +14 -7
  10. package/dist/docx/commentOnlyChange.js +9 -139
  11. package/dist/docx/comments/constants.d.ts +3 -4
  12. package/dist/docx/comments/constants.js +4 -5
  13. package/dist/docx/comments/grammar.d.ts +86 -0
  14. package/dist/docx/comments/grammar.js +223 -0
  15. package/dist/docx/comments/parts.d.ts +52 -0
  16. package/dist/docx/comments/parts.js +279 -0
  17. package/dist/docx/comments/people.d.ts +11 -2
  18. package/dist/docx/comments/people.js +28 -106
  19. package/dist/docx/comments/policy.d.ts +7 -0
  20. package/dist/docx/comments/policy.js +43 -0
  21. package/dist/docx/comments/reading.d.ts +5 -3
  22. package/dist/docx/comments/reading.js +30 -29
  23. package/dist/docx/comments/writing.d.ts +19 -7
  24. package/dist/docx/comments/writing.js +105 -137
  25. package/dist/docx/documentSettings.d.ts +7 -0
  26. package/dist/docx/documentSettings.js +10 -2
  27. package/dist/docx/exportDocx.d.ts +40 -5
  28. package/dist/docx/exportDocx.js +71 -72
  29. package/dist/docx/exportRefs.d.ts +5 -2
  30. package/dist/docx/exportRefs.js +3 -1
  31. package/dist/docx/fidelity.d.ts +43 -0
  32. package/dist/docx/fidelity.js +64 -0
  33. package/dist/docx/formatting/attrs.d.ts +27 -0
  34. package/dist/docx/formatting/attrs.js +31 -0
  35. package/dist/docx/formatting/context.d.ts +31 -0
  36. package/dist/docx/formatting/context.js +42 -0
  37. package/dist/docx/formatting/direct.d.ts +6 -5
  38. package/dist/docx/formatting/direct.js +52 -81
  39. package/dist/docx/formatting/resolve.d.ts +45 -0
  40. package/dist/docx/formatting/resolve.js +140 -0
  41. package/dist/docx/formatting/runProperties.d.ts +93 -0
  42. package/dist/docx/formatting/runProperties.js +316 -0
  43. package/dist/docx/formatting/styles.js +3 -3
  44. package/dist/docx/formatting/tabStops.js +7 -22
  45. package/dist/docx/formatting.d.ts +4 -1
  46. package/dist/docx/formatting.js +4 -1
  47. package/dist/docx/headersFooters.js +13 -22
  48. package/dist/docx/identities.d.ts +67 -0
  49. package/dist/docx/identities.js +174 -0
  50. package/dist/docx/importDocx.d.ts +12 -1
  51. package/dist/docx/importDocx.js +72 -79
  52. package/dist/docx/importParagraph.d.ts +1 -1
  53. package/dist/docx/importParagraph.js +4 -3
  54. package/dist/docx/importTable.d.ts +1 -1
  55. package/dist/docx/importTable.js +17 -1
  56. package/dist/docx/invariants.d.ts +33 -0
  57. package/dist/docx/invariants.js +256 -0
  58. package/dist/docx/media.d.ts +6 -4
  59. package/dist/docx/media.js +6 -37
  60. package/dist/docx/newLists.d.ts +20 -0
  61. package/dist/docx/newLists.js +36 -0
  62. package/dist/docx/notes.js +6 -12
  63. package/dist/docx/numberingPlanner.d.ts +8 -0
  64. package/dist/docx/numberingPlanner.js +19 -0
  65. package/dist/docx/packageParts.d.ts +42 -0
  66. package/dist/docx/packageParts.js +135 -0
  67. package/dist/docx/pageGeometry.d.ts +2 -0
  68. package/dist/docx/pageGeometry.js +18 -9
  69. package/dist/docx/paraProps.d.ts +10 -22
  70. package/dist/docx/paraProps.js +75 -99
  71. package/dist/docx/partPlan.d.ts +36 -0
  72. package/dist/docx/partPlan.js +59 -0
  73. package/dist/docx/protectionPolicy.d.ts +127 -0
  74. package/dist/docx/protectionPolicy.js +169 -0
  75. package/dist/docx/relationships.d.ts +1 -1
  76. package/dist/docx/relationships.js +15 -15
  77. package/dist/docx/runProps.d.ts +9 -22
  78. package/dist/docx/runProps.js +15 -168
  79. package/dist/docx/scan.js +20 -52
  80. package/dist/docx/sdt.js +14 -37
  81. package/dist/docx/sdtProps.d.ts +8 -1
  82. package/dist/docx/sdtProps.js +10 -0
  83. package/dist/docx/serializeBlock.d.ts +2 -0
  84. package/dist/docx/serializeBlock.js +9 -7
  85. package/dist/docx/serializeParagraph.d.ts +2 -1
  86. package/dist/docx/serializeParagraph.js +25 -14
  87. package/dist/docx/serializeTable.js +63 -32
  88. package/dist/docx/session.d.ts +42 -14
  89. package/dist/docx/session.js +43 -17
  90. package/dist/docx/storyProjection.d.ts +36 -0
  91. package/dist/docx/storyProjection.js +23 -0
  92. package/dist/docx/tableFormatting/editing.js +130 -185
  93. package/dist/docx/tableFormatting/reading.d.ts +16 -6
  94. package/dist/docx/tableFormatting/reading.js +40 -20
  95. package/dist/docx/tableTemplate.js +37 -5
  96. package/dist/docx/theme.d.ts +0 -6
  97. package/dist/docx/theme.js +0 -8
  98. package/dist/download.d.ts +8 -5
  99. package/dist/download.js +2 -0
  100. package/dist/editor/clipboard/images.js +17 -3
  101. package/dist/editor/clipboard/inlineFormatting.d.ts +7 -0
  102. package/dist/editor/clipboard/inlineFormatting.js +20 -30
  103. package/dist/editor/commands/breakCommands.js +4 -3
  104. package/dist/editor/commands/canRunCommand.d.ts +2 -2
  105. package/dist/editor/commands/canRunCommand.js +1 -1
  106. package/dist/editor/commands/comments/editing.d.ts +6 -2
  107. package/dist/editor/commands/comments/editing.js +21 -36
  108. package/dist/editor/commands/exportQueries.d.ts +15 -0
  109. package/dist/editor/commands/exportQueries.js +14 -0
  110. package/dist/editor/commands/fidelityQueries.d.ts +12 -0
  111. package/dist/editor/commands/fidelityQueries.js +8 -0
  112. package/dist/editor/commands/formatting/editing.d.ts +2 -2
  113. package/dist/editor/commands/formatting/editing.js +26 -108
  114. package/dist/editor/commands/formatting/propertyCommands.d.ts +21 -0
  115. package/dist/editor/commands/formatting/propertyCommands.js +103 -0
  116. package/dist/editor/commands/formatting/shared.d.ts +3 -3
  117. package/dist/editor/commands/formatting/shared.js +5 -2
  118. package/dist/editor/commands/historyCommands.js +2 -1
  119. package/dist/editor/commands/indentCommands.js +5 -4
  120. package/dist/editor/commands/index.d.ts +11 -0
  121. package/dist/editor/commands/index.js +5 -0
  122. package/dist/editor/commands/linkCommands.js +5 -6
  123. package/dist/editor/commands/listCommands.js +8 -10
  124. package/dist/editor/commands/lockCommands.d.ts +7 -1
  125. package/dist/editor/commands/lockCommands.js +35 -37
  126. package/dist/editor/commands/paragraphCommands.js +28 -31
  127. package/dist/editor/commands/spacingCommands.js +1 -1
  128. package/dist/editor/commands/tabCommands.js +4 -3
  129. package/dist/editor/createEditor.d.ts +17 -29
  130. package/dist/editor/createEditor.js +61 -67
  131. package/dist/editor/documentStyles.d.ts +11 -35
  132. package/dist/editor/documentStyles.js +9 -52
  133. package/dist/editor/editorDocument.d.ts +56 -0
  134. package/dist/editor/editorDocument.js +74 -0
  135. package/dist/editor/externalClipboard.js +166 -33
  136. package/dist/editor/insertImage.js +4 -3
  137. package/dist/editor/insertTable.js +4 -3
  138. package/dist/editor/paragraphEdits.d.ts +11 -18
  139. package/dist/editor/paragraphEdits.js +7 -16
  140. package/dist/editor/plugins/displayDerivation.d.ts +47 -0
  141. package/dist/editor/plugins/displayDerivation.js +78 -0
  142. package/dist/editor/plugins/documentProtection.d.ts +3 -3
  143. package/dist/editor/plugins/imagePaste.js +4 -3
  144. package/dist/editor/plugins/keymap.js +18 -3
  145. package/dist/editor/plugins/lockedContent.d.ts +4 -4
  146. package/dist/editor/plugins/lockedContent.js +1 -1
  147. package/dist/editor/plugins/numberingDecorations.d.ts +5 -11
  148. package/dist/editor/plugins/numberingDecorations.js +7 -17
  149. package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
  150. package/dist/editor/plugins/paragraphDisplay.js +51 -0
  151. package/dist/editor/plugins/tabLayout.js +1 -1
  152. package/dist/editor/plugins/tableDisplay.d.ts +6 -0
  153. package/dist/editor/plugins/tableDisplay.js +16 -0
  154. package/dist/index.d.ts +2 -0
  155. package/dist/model/format.d.ts +30 -8
  156. package/dist/model/format.js +35 -22
  157. package/dist/model/tabStops.d.ts +9 -0
  158. package/dist/model/tabStops.js +18 -0
  159. package/dist/numbering/listTemplate.js +49 -10
  160. package/dist/numbering/parseNumbering.d.ts +14 -1
  161. package/dist/numbering/parseNumbering.js +35 -22
  162. package/dist/numbering/writeNumbering.d.ts +3 -4
  163. package/dist/numbering/writeNumbering.js +14 -25
  164. package/dist/ooxml/childOrder.d.ts +34 -0
  165. package/dist/ooxml/childOrder.js +496 -0
  166. package/dist/ooxml/element.d.ts +65 -0
  167. package/dist/ooxml/element.js +68 -0
  168. package/dist/ooxml/errors.d.ts +3 -2
  169. package/dist/ooxml/fragment.d.ts +53 -0
  170. package/dist/ooxml/fragment.js +76 -0
  171. package/dist/ooxml/image.d.ts +4 -0
  172. package/dist/ooxml/image.js +3 -5
  173. package/dist/ooxml/names.d.ts +27 -0
  174. package/dist/ooxml/names.js +29 -0
  175. package/dist/ooxml/partSplice.d.ts +67 -0
  176. package/dist/ooxml/partSplice.js +169 -0
  177. package/dist/ooxml/precedence.d.ts +31 -0
  178. package/dist/ooxml/precedence.js +51 -0
  179. package/dist/ooxml/props.d.ts +112 -0
  180. package/dist/ooxml/props.js +214 -0
  181. package/dist/ooxml/simpleTypes.d.ts +103 -0
  182. package/dist/ooxml/simpleTypes.js +182 -0
  183. package/dist/ooxml/tabStops.js +8 -27
  184. package/dist/ooxml/tagScan.d.ts +34 -0
  185. package/dist/ooxml/tagScan.js +108 -0
  186. package/dist/ooxml/units.d.ts +25 -13
  187. package/dist/ooxml/units.js +65 -31
  188. package/dist/ooxml/xml.d.ts +52 -0
  189. package/dist/ooxml/xml.js +64 -5
  190. package/dist/page/blockKinds.d.ts +103 -0
  191. package/dist/page/blockKinds.js +11 -0
  192. package/dist/page/kinds/index.d.ts +6 -0
  193. package/dist/page/kinds/index.js +10 -0
  194. package/dist/page/kinds/paragraphKind.d.ts +10 -0
  195. package/dist/page/kinds/paragraphKind.js +71 -0
  196. package/dist/page/kinds/tableKind.d.ts +10 -0
  197. package/dist/page/kinds/tableKind.js +178 -0
  198. package/dist/page/measureBlocks.d.ts +3 -1
  199. package/dist/page/measureBlocks.js +24 -25
  200. package/dist/page/pageDecorations.d.ts +27 -28
  201. package/dist/page/pageDecorations.js +70 -151
  202. package/dist/page/pageLayout.d.ts +10 -62
  203. package/dist/page/pageLayout.js +60 -53
  204. package/dist/page/usePageLayout.d.ts +2 -2
  205. package/dist/page/usePageLayout.js +3 -11
  206. package/dist/schema/attrRoles.d.ts +42 -0
  207. package/dist/schema/attrRoles.js +141 -0
  208. package/dist/schema/displayDerivation.d.ts +82 -0
  209. package/dist/schema/displayDerivation.js +130 -0
  210. package/dist/schema/docxSchema.d.ts +9 -0
  211. package/dist/schema/docxSchema.js +237 -114
  212. package/dist/schema/editGuard.d.ts +99 -0
  213. package/dist/schema/editGuard.js +43 -0
  214. package/dist/schema/guards.d.ts +91 -0
  215. package/dist/schema/guards.js +108 -0
  216. package/dist/schema/index.d.ts +2 -0
  217. package/dist/schema/index.js +2 -0
  218. package/dist/schema/locks.d.ts +17 -77
  219. package/dist/schema/locks.js +26 -70
  220. package/dist/schema/preservedGuards.d.ts +50 -0
  221. package/dist/schema/preservedGuards.js +80 -0
  222. package/dist/schema/protection.d.ts +17 -4
  223. package/dist/schema/protection.js +4 -2
  224. package/dist/schema/sourceEquality.d.ts +19 -0
  225. package/dist/schema/sourceEquality.js +39 -0
  226. package/dist/styles/inlineStyle.js +15 -6
  227. package/dist/table/cellFormatting.d.ts +8 -1
  228. package/dist/table/cellFormatting.js +10 -17
  229. package/dist/table/commands.d.ts +2 -2
  230. package/dist/table/commands.js +20 -18
  231. package/dist/table/format.d.ts +3 -0
  232. package/dist/table/format.js +3 -9
  233. package/dist/table/gridBorders.d.ts +14 -16
  234. package/dist/table/gridBorders.js +3 -41
  235. package/dist/table/index.d.ts +2 -2
  236. package/dist/table/merge.d.ts +4 -8
  237. package/dist/table/merge.js +5 -5
  238. package/package.json +10 -3
  239. package/dist/docx/comments/contentTypes.d.ts +0 -7
  240. package/dist/docx/comments/contentTypes.js +0 -38
  241. package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
  242. package/dist/docx/formatting/effectiveParagraph.js +0 -81
  243. package/dist/docx/propsXml.d.ts +0 -49
  244. package/dist/docx/propsXml.js +0 -302
  245. package/dist/docx/uniqueControls.d.ts +0 -14
  246. package/dist/docx/uniqueControls.js +0 -62
  247. package/dist/editor/plugins/bookmarkProtection.d.ts +0 -3
  248. package/dist/editor/plugins/bookmarkProtection.js +0 -28
  249. package/dist/editor/plugins/commentReservations.d.ts +0 -5
  250. package/dist/editor/plugins/commentReservations.js +0 -26
  251. package/dist/editor/plugins/noteProtection.d.ts +0 -3
  252. package/dist/editor/plugins/noteProtection.js +0 -25
  253. package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
  254. package/dist/editor/plugins/styledParagraphs.js +0 -65
  255. package/dist/page/tableMeasurements.d.ts +0 -10
  256. package/dist/page/tableMeasurements.js +0 -115
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Rejects transactions disallowed by the guard in `schema/locks`, which answers for the locks the
3
- * document carries and for the protection the editor runs under (`schema/protection`) alike. A
4
- * rejected IME edit also ends the browser composition on the next frame so ProseMirror cannot
5
- * remain stuck in composing state.
2
+ * Rejects transactions no guard `schema/guards` registers would let through, the locks the document
3
+ * carries and the protection the editor runs under (`schema/protection`) among them. A rejected IME
4
+ * edit also ends the browser composition on the next frame so ProseMirror cannot remain stuck in
5
+ * composing state.
6
6
  */
7
7
  import { Plugin } from "prosemirror-state";
8
8
  export declare function lockedContent(): Plugin;
@@ -1,6 +1,6 @@
1
1
  // src/editor/plugins/lockedContent.ts
2
2
  import { Plugin } from "prosemirror-state";
3
- import { transactionAllowed } from "../../schema/locks.js";
3
+ import { transactionAllowed } from "../../schema/guards.js";
4
4
  function endComposition(view) {
5
5
  if (!view.composing) return;
6
6
  const marks = view.state.storedMarks ?? view.state.selection.$from.marks();
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Draws list markers and inherited indentation as decorations so display-only values never create
3
- * new OOXML on export. The plugin also exposes numbering definitions to list commands.
3
+ * new OOXML on export. The definitions the markers are drawn from belong to the document
4
+ * snapshot, and the readers list commands ask stand here beside the drawing.
4
5
  */
5
6
  import type { Node as PMNode } from "prosemirror-model";
6
7
  import { type EditorState, Plugin } from "prosemirror-state";
7
8
  import { DecorationSet } from "prosemirror-view";
8
- import { type Numbering } from "../../numbering/parseNumbering";
9
+ import type { Numbering } from "../../numbering/parseNumbering";
9
10
  /** A number to draw on screen and the paragraph position it attaches to */
10
11
  export interface PlacedMarker {
11
12
  from: number;
@@ -22,13 +23,6 @@ export interface PlacedMarker {
22
23
  /** Walks a document to find the paragraphs that get numbers and what those numbers are */
23
24
  export declare function paragraphMarkers(doc: PMNode, numbering: Numbering): PlacedMarker[];
24
25
  export declare function markerDecorations(doc: PMNode, numbering: Numbering): DecorationSet;
25
- /** What the plugin holds: the document's list definitions and the numbers to draw right now */
26
- interface NumberingState {
27
- numbering: Numbering;
28
- /** Whether the document has a place (numbering.xml) to write the definition of a new list */
29
- canStartNewList: boolean;
30
- decorations: DecorationSet;
31
- }
32
26
  /** This document's list definitions. Empty when the editor does not know them */
33
27
  export declare function documentNumbering(state: EditorState): Numbering;
34
28
  /**
@@ -38,5 +32,5 @@ export declare function documentNumbering(state: EditorState): Numbering;
38
32
  * in the first place.
39
33
  */
40
34
  export declare function canStartNewList(state: EditorState): boolean;
41
- export declare function numberingMarkers(numbering?: Numbering, canStartNewList?: boolean): Plugin<NumberingState>;
42
- export {};
35
+ /** Draws the numbers this document's lists put in front of their paragraphs */
36
+ export declare function numberingMarkers(): Plugin<DecorationSet>;
@@ -3,10 +3,8 @@ import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { Decoration, DecorationSet } from "prosemirror-view";
4
4
  import { toParagraphFormat } from "../../model/format.js";
5
5
  import { computeMarkers } from "../../numbering/markers.js";
6
- import {
7
- EMPTY_NUMBERING
8
- } from "../../numbering/parseNumbering.js";
9
6
  import { editorAttributes, editorCssVariables } from "../../styles/classNames.js";
7
+ import { documentOf } from "../editorDocument.js";
10
8
  var FALLBACK_MARKER_WIDTH_PT = 18;
11
9
  function paragraphSpots(doc) {
12
10
  const spots = [];
@@ -76,28 +74,20 @@ function markerDecorations(doc, numbering) {
76
74
  }
77
75
  var numberingKey = new PluginKey("docxEditorNumbering");
78
76
  function documentNumbering(state) {
79
- return numberingKey.getState(state)?.numbering ?? EMPTY_NUMBERING;
77
+ return documentOf(state).formatting.numbering;
80
78
  }
81
79
  function canStartNewList(state) {
82
- return numberingKey.getState(state)?.canStartNewList ?? true;
80
+ return documentOf(state).canStartNewList;
83
81
  }
84
- function numberingMarkers(numbering = EMPTY_NUMBERING, canStartNewList2 = true) {
82
+ function numberingMarkers() {
85
83
  return new Plugin({
86
84
  key: numberingKey,
87
85
  state: {
88
- init: (_config, state) => ({
89
- numbering,
90
- canStartNewList: canStartNewList2,
91
- decorations: markerDecorations(state.doc, numbering)
92
- }),
93
- apply: (tr, current) => tr.docChanged ? {
94
- numbering,
95
- canStartNewList: canStartNewList2,
96
- decorations: markerDecorations(tr.doc, numbering)
97
- } : current
86
+ init: (_config, state) => markerDecorations(state.doc, documentOf(state).formatting.numbering),
87
+ apply: (tr, current, _old, state) => tr.docChanged ? markerDecorations(tr.doc, documentOf(state).formatting.numbering) : current
98
88
  },
99
89
  props: {
100
- decorations: (state) => numberingKey.getState(state)?.decorations
90
+ decorations: (state) => numberingKey.getState(state)
101
91
  }
102
92
  });
103
93
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The values a paragraph draws with, read out of the document's styles along the same path the
3
+ * import takes (`docx/formatting`), so that a paragraph an edit built, one it re-aligned and one
4
+ * the file arrived with all carry the same values for the same properties.
5
+ */
6
+ import type { DocumentDeriver } from "./displayDerivation";
7
+ export declare const paragraphDisplay: DocumentDeriver;
@@ -0,0 +1,51 @@
1
+ // src/editor/plugins/paragraphDisplay.ts
2
+ import {
3
+ paragraphAttrsOf,
4
+ resolveParagraph,
5
+ resolveRun
6
+ } from "../../docx/formatting.js";
7
+ import { docxSchema } from "../../schema/index.js";
8
+ import { paragraphPPr } from "../paragraphEdits.js";
9
+ function carriesNothing(node) {
10
+ return node.attrs.format === null && node.attrs.styleRun === null;
11
+ }
12
+ function stands(node, previous) {
13
+ return previous !== null && previous.attrs.pPr === node.attrs.pPr && !carriesNothing(node);
14
+ }
15
+ function holdsComposition(node, pos, composing) {
16
+ return composing !== null && composing >= pos && composing <= pos + node.nodeSize;
17
+ }
18
+ var paragraphDisplay = {
19
+ name: "paragraph",
20
+ nodeTypes: ["paragraph"],
21
+ derive(node, pos, _doc, context, previous) {
22
+ if (stands(node, previous) || holdsComposition(node, pos, context.composingAt)) {
23
+ return [];
24
+ }
25
+ const formatting = context.document.formatting;
26
+ const paragraph = resolveParagraph(paragraphPPr(node), formatting);
27
+ const derived = [
28
+ { pos, attrs: paragraphAttrsOf(paragraph) }
29
+ ];
30
+ node.forEach((child, offset) => {
31
+ const mark = docxSchema.marks.run.isInSet(child.marks);
32
+ if (!mark) return;
33
+ const rPr = mark.attrs.rPr;
34
+ derived.push({
35
+ pos: pos + 1 + offset,
36
+ mark: { type: mark.type, to: pos + 1 + offset + child.nodeSize },
37
+ attrs: {
38
+ format: resolveRun(
39
+ typeof rPr === "string" ? rPr : null,
40
+ paragraph,
41
+ formatting
42
+ )
43
+ }
44
+ });
45
+ });
46
+ return derived;
47
+ }
48
+ };
49
+ export {
50
+ paragraphDisplay
51
+ };
@@ -1,12 +1,12 @@
1
1
  // src/editor/plugins/tabLayout.ts
2
2
  import { Plugin } from "prosemirror-state";
3
3
  import { DEFAULT_TAB_STOP_PT } from "../../docx/documentSettings.js";
4
+ import { PX_PER_PT } from "../../docx/pageGeometry.js";
4
5
  import { toParagraphFormat } from "../../model/format.js";
5
6
  import { docxSchema } from "../../schema/index.js";
6
7
  import { editorClassNames, editorCssVariables } from "../../styles/classNames.js";
7
8
  import { documentDefaultTabStopPt } from "../documentStyles.js";
8
9
  import { setTabWidths, tabWidths } from "./tabDecorations.js";
9
- var PX_PER_PT = 96 / 72;
10
10
  var POSITION_EPSILON_PT = 0.01;
11
11
  var WIDTH_EPSILON_PX = 0.1;
12
12
  var NATURAL_WIDTH_PX = 1e5;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The lines a table's cells draw because of where they sit in the grid (`table/gridBorders`),
3
+ * derived again once the grid or the border inputs of the table moved.
4
+ */
5
+ import type { DocumentDeriver } from "./displayDerivation";
6
+ export declare const tableDisplay: DocumentDeriver;
@@ -0,0 +1,16 @@
1
+ // src/editor/plugins/tableDisplay.ts
2
+ import { cellFixes, sameFormattingInputs } from "../../table/gridBorders.js";
3
+ var tableDisplay = {
4
+ name: "table",
5
+ nodeTypes: ["table"],
6
+ derive(table, pos, _doc, _context, previous) {
7
+ if (previous !== null && sameFormattingInputs(previous, table)) return [];
8
+ return cellFixes(table).map((fix) => ({
9
+ pos: pos + 1 + fix.pos,
10
+ attrs: fix.attrs
11
+ }));
12
+ }
13
+ };
14
+ export {
15
+ tableDisplay
16
+ };
package/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@ export { EditorView } from "prosemirror-view";
15
15
  export type { DocxEditorHandle, DocxEditorMode, DocxEditorProps, } from "./DocxEditor";
16
16
  export { DocxEditor } from "./DocxEditor";
17
17
  export type { DocxBytes, DocxSource } from "./docx/importDocx";
18
+ /** What the handle and a `blocked` download report: each reason the document cannot be written, under the code `DocxExportError` would throw it with */
19
+ export type { ExportProblem } from "./docx/invariants";
18
20
  export type { DownloadDocxOptions, DownloadDocxResult, } from "./download";
19
21
  export { downloadDocx } from "./download";
20
22
  export type { CommentAuthor } from "./editor/commands/commentCommands";
@@ -11,7 +11,7 @@
11
11
  * declaration, the checks that let through only the shapes the read functions produce
12
12
  * live here alongside them.
13
13
  */
14
- import type { TabStop } from "./tabStops";
14
+ import { type TabStop } from "./tabStops";
15
15
  declare const ALIGNS: readonly ["left", "center", "right", "justify"];
16
16
  export type ParagraphAlign = (typeof ALIGNS)[number];
17
17
  declare const VERTICAL_ALIGNS: readonly ["superscript", "subscript"];
@@ -103,6 +103,11 @@ export interface ParagraphFormat {
103
103
  * page boundary guides
104
104
  */
105
105
  pageBreakBefore?: true;
106
+ /**
107
+ * Set when the document asks for this paragraph to stand on the same page as the start of the
108
+ * block after it (`w:keepNext`). Read by the page boundary guides
109
+ */
110
+ keepNext?: boolean;
106
111
  /** A CSS border in the form `1pt solid #000000` */
107
112
  borderTop?: string;
108
113
  borderBottom?: string;
@@ -110,15 +115,26 @@ export interface ParagraphFormat {
110
115
  borderRight?: string;
111
116
  background?: string;
112
117
  }
113
- /** The character formatting to render on screen */
118
+ /**
119
+ * The character formatting to render on screen.
120
+ *
121
+ * A toggle the run switches off outright (`w:val="0"`) is false rather than absent: absent means
122
+ * the run says nothing and what the style laid down stands, false is the run beating that style.
123
+ */
114
124
  export interface RunFormat {
115
- bold?: true;
116
- italic?: true;
117
- /** The underline kind. Absent entirely when there is no underline */
118
- underline?: UnderlineKind;
119
- strike?: true;
120
- smallCaps?: true;
125
+ bold?: boolean;
126
+ italic?: boolean;
127
+ /** The underline kind, or `none` for an underline switched off outright. Absent when the run says nothing */
128
+ underline?: UnderlineKind | "none";
129
+ strike?: boolean;
130
+ /** Two lines through the text (`w:dstrike`). Read from the document and not drawn or edited yet */
131
+ doubleStrike?: boolean;
132
+ smallCaps?: boolean;
133
+ /** Every letter drawn as a capital (`w:caps`). Read from the document and not drawn or edited yet */
134
+ caps?: boolean;
121
135
  fontSizePt?: number;
136
+ /** The room added between characters (`w:spacing`), below zero where they are drawn closer. Read from the document and not drawn or edited yet */
137
+ characterSpacingPt?: number;
122
138
  /** A CSS font name list in the form `"맑은 고딕","Malgun Gothic"` */
123
139
  fontFamily?: string;
124
140
  color?: string;
@@ -133,6 +149,12 @@ export interface RunFormat {
133
149
  */
134
150
  lang?: string;
135
151
  }
152
+ /**
153
+ * Every key of `RunFormat`, in the order a run's properties are read. The run property table
154
+ * (`docx/formatting/runProperties`) walks this list, which lives here because `model` imports
155
+ * nothing above it.
156
+ */
157
+ export declare const RUN_FORMAT_KEYS: readonly ["bold", "italic", "strike", "doubleStrike", "smallCaps", "caps", "underline", "fontSizePt", "characterSpacingPt", "fontFamily", "color", "highlight", "background", "verticalAlign", "lang"];
136
158
  /**
137
159
  * The table formatting to render on screen. The inner lines between cells are folded
138
160
  * into the cell formatting
@@ -1,4 +1,5 @@
1
1
  // src/model/format.ts
2
+ import { TAB_LEADERS, TAB_STOP_ALIGNMENTS } from "./tabStops.js";
2
3
  var ALIGNS = ["left", "center", "right", "justify"];
3
4
  var VERTICAL_ALIGNS = ["superscript", "subscript"];
4
5
  var CELL_VERTICAL_ALIGNS = ["top", "center", "bottom"];
@@ -56,6 +57,23 @@ function withWidthNumber(width, value) {
56
57
  if (width.type === "pct") return { type: "pct", fiftieths: value };
57
58
  return width;
58
59
  }
60
+ var RUN_FORMAT_KEYS = [
61
+ "bold",
62
+ "italic",
63
+ "strike",
64
+ "doubleStrike",
65
+ "smallCaps",
66
+ "caps",
67
+ "underline",
68
+ "fontSizePt",
69
+ "characterSpacingPt",
70
+ "fontFamily",
71
+ "color",
72
+ "highlight",
73
+ "background",
74
+ "verticalAlign",
75
+ "lang"
76
+ ];
59
77
  function isRecord(value) {
60
78
  return typeof value === "object" && value !== null && !Array.isArray(value);
61
79
  }
@@ -89,22 +107,6 @@ function toNumberingRef(value) {
89
107
  if (typeof numId !== "number" || typeof ilvl !== "number") return null;
90
108
  return { numId, ilvl };
91
109
  }
92
- var TAB_ALIGNMENTS = [
93
- "start",
94
- "center",
95
- "end",
96
- "decimal",
97
- "num",
98
- "bar"
99
- ];
100
- var TAB_LEADERS = [
101
- "none",
102
- "dot",
103
- "hyphen",
104
- "underscore",
105
- "heavy",
106
- "middleDot"
107
- ];
108
110
  function toTabStops(value) {
109
111
  if (!Array.isArray(value)) return null;
110
112
  const stops = [];
@@ -112,7 +114,9 @@ function toTabStops(value) {
112
114
  if (!isRecord(entry) || typeof entry.positionPt !== "number" || !Number.isFinite(entry.positionPt)) {
113
115
  continue;
114
116
  }
115
- const align = TAB_ALIGNMENTS.find((candidate) => candidate === entry.align);
117
+ const align = TAB_STOP_ALIGNMENTS.find(
118
+ (candidate) => candidate === entry.align
119
+ );
116
120
  if (!align) continue;
117
121
  const leader = TAB_LEADERS.find((candidate) => candidate === entry.leader);
118
122
  stops.push({
@@ -150,6 +154,7 @@ function toParagraphFormat(value) {
150
154
  const tabStops = toTabStops(value.tabStops);
151
155
  if (tabStops) format.tabStops = tabStops;
152
156
  if (value.pageBreakBefore === true) format.pageBreakBefore = true;
157
+ if (typeof value.keepNext === "boolean") format.keepNext = value.keepNext;
153
158
  copyBorders(value, format);
154
159
  const background = matching(FILL, value.background);
155
160
  if (background) format.background = background;
@@ -158,13 +163,20 @@ function toParagraphFormat(value) {
158
163
  function toRunFormat(value) {
159
164
  if (!isRecord(value)) return null;
160
165
  const format = {};
161
- if (value.bold === true) format.bold = true;
162
- if (value.italic === true) format.italic = true;
163
- if (value.strike === true) format.strike = true;
164
- if (value.smallCaps === true) format.smallCaps = true;
165
- if (isUnderlineKind(value.underline)) format.underline = value.underline;
166
+ if (typeof value.bold === "boolean") format.bold = value.bold;
167
+ if (typeof value.italic === "boolean") format.italic = value.italic;
168
+ if (typeof value.strike === "boolean") format.strike = value.strike;
169
+ if (typeof value.doubleStrike === "boolean")
170
+ format.doubleStrike = value.doubleStrike;
171
+ if (typeof value.smallCaps === "boolean") format.smallCaps = value.smallCaps;
172
+ if (typeof value.caps === "boolean") format.caps = value.caps;
173
+ if (isUnderlineKind(value.underline) || value.underline === "none") {
174
+ format.underline = value.underline;
175
+ }
166
176
  if (typeof value.fontSizePt === "number")
167
177
  format.fontSizePt = value.fontSizePt;
178
+ if (typeof value.characterSpacingPt === "number")
179
+ format.characterSpacingPt = value.characterSpacingPt;
168
180
  const fontFamily = matching(FONT_FAMILY, value.fontFamily);
169
181
  if (fontFamily) format.fontFamily = fontFamily;
170
182
  const color = matching(HEX_COLOR, value.color);
@@ -287,6 +299,7 @@ function spanCount(value) {
287
299
  }
288
300
  export {
289
301
  NO_FILL,
302
+ RUN_FORMAT_KEYS,
290
303
  isHighlightName,
291
304
  isUnderlineKind,
292
305
  spanCount,
@@ -6,6 +6,15 @@ export interface TabStop {
6
6
  align: TabAlignment | "bar";
7
7
  leader?: TabLeader;
8
8
  }
9
+ /**
10
+ * What a stop may be aligned to, and what it may draw the space it covers with.
11
+ *
12
+ * These are the members of the two unions above, listed so that a reader checking a value against
13
+ * them cannot fall out of step with the types. `ooxml/simpleTypes` builds `ST_TabJc` and
14
+ * `ST_TabTlc` on them, adding the spellings the document writes that the model does not keep.
15
+ */
16
+ export declare const TAB_STOP_ALIGNMENTS: readonly TabStop["align"][];
17
+ export declare const TAB_LEADERS: readonly TabLeader[];
9
18
  /** A tab entry before the paragraph-property hierarchy has been resolved. */
10
19
  export type TabStopDirective = TabStop | {
11
20
  positionPt: number;
@@ -1,4 +1,20 @@
1
1
  // src/model/tabStops.ts
2
+ var TAB_STOP_ALIGNMENTS = [
3
+ "start",
4
+ "center",
5
+ "end",
6
+ "decimal",
7
+ "num",
8
+ "bar"
9
+ ];
10
+ var TAB_LEADERS = [
11
+ "none",
12
+ "dot",
13
+ "hyphen",
14
+ "underscore",
15
+ "heavy",
16
+ "middleDot"
17
+ ];
2
18
  function layerTabStopDirectives(base, over) {
3
19
  const stops = /* @__PURE__ */ new Map();
4
20
  for (const stop of base) {
@@ -17,6 +33,8 @@ function mergeTabStops(base, over) {
17
33
  );
18
34
  }
19
35
  export {
36
+ TAB_LEADERS,
37
+ TAB_STOP_ALIGNMENTS,
20
38
  layerTabStopDirectives,
21
39
  mergeTabStops
22
40
  };
@@ -1,4 +1,7 @@
1
1
  // src/numbering/listTemplate.ts
2
+ import { elementXml } from "../ooxml/element.js";
3
+ import { wName } from "../ooxml/names.js";
4
+ import { orderedElement } from "../ooxml/props.js";
2
5
  var LEVEL_COUNT = 9;
3
6
  var MAX_ILVL = LEVEL_COUNT - 1;
4
7
  var NUMBER_CYCLE = [
@@ -51,25 +54,61 @@ function nextNumId(used, kind) {
51
54
  return listKindOf(from) === kind ? from : from + 1;
52
55
  }
53
56
  function indXml(indent) {
54
- const attrs = [
55
- ["w:left", indent?.startTwips],
56
- ["w:right", indent?.endTwips],
57
- ["w:hanging", indent?.hangingTwips],
58
- ["w:firstLine", indent?.firstLineTwips]
59
- ].filter((entry) => typeof entry[1] === "number").map(([name, value]) => `${name}="${value}"`).join(" ");
60
- return attrs === "" ? "" : `<w:pPr><w:ind ${attrs}/></w:pPr>`;
57
+ const slots = [
58
+ ["left", indent?.startTwips ?? null],
59
+ ["right", indent?.endTwips ?? null],
60
+ ["hanging", indent?.hangingTwips ?? null],
61
+ ["firstLine", indent?.firstLineTwips ?? null]
62
+ ];
63
+ const attrs = slots.filter((slot) => slot[1] !== null).map(([name, twips]) => [wName(name), `${twips}`]);
64
+ if (attrs.length === 0) return "";
65
+ return orderedElement(
66
+ wName("pPr"),
67
+ [],
68
+ [{ name: "ind", xml: elementXml(wName("ind"), attrs) }]
69
+ );
61
70
  }
62
71
  function levelXml(ilvl, level) {
63
72
  const ind = indXml(level.indent);
64
- return `<w:lvl w:ilvl="${ilvl}"><w:start w:val="${level.start}"/><w:numFmt w:val="${level.format}"/><w:lvlText w:val="${level.text}"/><w:lvlJc w:val="left"/>${ind}</w:lvl>`;
73
+ return orderedElement(
74
+ wName("lvl"),
75
+ [[wName("ilvl"), `${ilvl}`]],
76
+ [
77
+ {
78
+ name: "start",
79
+ xml: elementXml(wName("start"), [[wName("val"), `${level.start}`]])
80
+ },
81
+ {
82
+ name: "numFmt",
83
+ xml: elementXml(wName("numFmt"), [[wName("val"), level.format]])
84
+ },
85
+ {
86
+ name: "lvlText",
87
+ xml: elementXml(wName("lvlText"), [[wName("val"), level.text]])
88
+ },
89
+ {
90
+ name: "lvlJc",
91
+ xml: elementXml(wName("lvlJc"), [[wName("val"), "left"]])
92
+ },
93
+ ...ind === "" ? [] : [{ name: "pPr", xml: ind }]
94
+ ]
95
+ );
65
96
  }
66
97
  function abstractNumXml(abstractNumId, kind) {
67
98
  const levels = TEMPLATES[kind].levels;
68
99
  const body = Array.from(levels.entries()).map(([ilvl, level]) => levelXml(ilvl, level)).join("");
69
- return `<w:abstractNum w:abstractNumId="${abstractNumId}">${body}</w:abstractNum>`;
100
+ return elementXml(
101
+ wName("abstractNum"),
102
+ [[wName("abstractNumId"), `${abstractNumId}`]],
103
+ [body]
104
+ );
70
105
  }
71
106
  function numXml(numId, abstractNumId) {
72
- return `<w:num w:numId="${numId}"><w:abstractNumId w:val="${abstractNumId}"/></w:num>`;
107
+ return elementXml(
108
+ wName("num"),
109
+ [[wName("numId"), `${numId}`]],
110
+ [elementXml(wName("abstractNumId"), [[wName("val"), `${abstractNumId}`]])]
111
+ );
73
112
  }
74
113
  export {
75
114
  LEVEL_COUNT,
@@ -6,6 +6,7 @@
6
6
  * disturbs the file.
7
7
  */
8
8
  import type { TabStopDirective } from "../model/tabStops";
9
+ import { type XmlParser } from "../ooxml/xml";
9
10
  /** The number formats actually used across every fixture */
10
11
  declare const NUMBER_FORMATS: readonly ["decimal", "bullet", "lowerLetter", "upperLetter", "lowerRoman"];
11
12
  export type NumberFormat = (typeof NUMBER_FORMATS)[number];
@@ -61,5 +62,17 @@ export declare const NO_LEVEL_INDENT: LevelIndentPt;
61
62
  * OOXML rule).
62
63
  */
63
64
  export declare function levelIndentPt(indent: LevelIndent | null): LevelIndentPt;
64
- export declare function parseNumbering(xml: string | null): Numbering;
65
+ /** What a caller may say about reading numbering beyond handing over the XML */
66
+ export interface NumberingOptions {
67
+ /**
68
+ * The parser the numbering XML is read through. Left out, the `DOMParser` global is used, and a
69
+ * runtime carrying none refuses the read with `no-xml-parser`.
70
+ */
71
+ xmlParser?: XmlParser;
72
+ }
73
+ /**
74
+ * The lists this numbering XML defines. `null` is the document that has no numbering part, which
75
+ * defines none and asks nothing of a parser.
76
+ */
77
+ export declare function parseNumbering(xml: string | null, options?: NumberingOptions): Numbering;
65
78
  export {};