@portone/docx-editor 0.1.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 (347) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/CONTRIBUTING.md +63 -0
  3. package/LICENSE +203 -0
  4. package/README.md +48 -0
  5. package/assets/editor.png +0 -0
  6. package/dist/DocxEditor.d.ts +123 -0
  7. package/dist/DocxEditor.js +348 -0
  8. package/dist/core.d.ts +36 -0
  9. package/dist/core.js +38 -0
  10. package/dist/docx/comments/constants.d.ts +8 -0
  11. package/dist/docx/comments/constants.js +20 -0
  12. package/dist/docx/comments/model.d.ts +37 -0
  13. package/dist/docx/comments/model.js +104 -0
  14. package/dist/docx/comments/reading.d.ts +36 -0
  15. package/dist/docx/comments/reading.js +149 -0
  16. package/dist/docx/comments/writing.d.ts +11 -0
  17. package/dist/docx/comments/writing.js +327 -0
  18. package/dist/docx/comments.d.ts +3 -0
  19. package/dist/docx/comments.js +4 -0
  20. package/dist/docx/container.d.ts +12 -0
  21. package/dist/docx/container.js +130 -0
  22. package/dist/docx/documentSettings.d.ts +4 -0
  23. package/dist/docx/documentSettings.js +14 -0
  24. package/dist/docx/exportDocx.d.ts +15 -0
  25. package/dist/docx/exportDocx.js +163 -0
  26. package/dist/docx/exportRefs.d.ts +16 -0
  27. package/dist/docx/exportRefs.js +10 -0
  28. package/dist/docx/formatting/direct.d.ts +30 -0
  29. package/dist/docx/formatting/direct.js +201 -0
  30. package/dist/docx/formatting/effectiveParagraph.d.ts +15 -0
  31. package/dist/docx/formatting/effectiveParagraph.js +81 -0
  32. package/dist/docx/formatting/styles.d.ts +67 -0
  33. package/dist/docx/formatting/styles.js +165 -0
  34. package/dist/docx/formatting/tabStops.d.ts +8 -0
  35. package/dist/docx/formatting/tabStops.js +65 -0
  36. package/dist/docx/formatting.d.ts +4 -0
  37. package/dist/docx/formatting.js +4 -0
  38. package/dist/docx/headersFooters.d.ts +36 -0
  39. package/dist/docx/headersFooters.js +218 -0
  40. package/dist/docx/hyperlink.d.ts +75 -0
  41. package/dist/docx/hyperlink.js +71 -0
  42. package/dist/docx/importDocx.d.ts +21 -0
  43. package/dist/docx/importDocx.js +263 -0
  44. package/dist/docx/importParagraph.d.ts +32 -0
  45. package/dist/docx/importParagraph.js +308 -0
  46. package/dist/docx/importTable.d.ts +9 -0
  47. package/dist/docx/importTable.js +275 -0
  48. package/dist/docx/media.d.ts +60 -0
  49. package/dist/docx/media.js +213 -0
  50. package/dist/docx/notes.d.ts +22 -0
  51. package/dist/docx/notes.js +71 -0
  52. package/dist/docx/pageGeometry.d.ts +75 -0
  53. package/dist/docx/pageGeometry.js +88 -0
  54. package/dist/docx/paraProps.d.ts +74 -0
  55. package/dist/docx/paraProps.js +167 -0
  56. package/dist/docx/propsXml.d.ts +49 -0
  57. package/dist/docx/propsXml.js +302 -0
  58. package/dist/docx/relationships.d.ts +42 -0
  59. package/dist/docx/relationships.js +94 -0
  60. package/dist/docx/runProps.d.ts +51 -0
  61. package/dist/docx/runProps.js +207 -0
  62. package/dist/docx/scan.d.ts +20 -0
  63. package/dist/docx/scan.js +110 -0
  64. package/dist/docx/sdt.d.ts +56 -0
  65. package/dist/docx/sdt.js +104 -0
  66. package/dist/docx/sdtProps.d.ts +18 -0
  67. package/dist/docx/sdtProps.js +11 -0
  68. package/dist/docx/serializeBlock.d.ts +4 -0
  69. package/dist/docx/serializeBlock.js +30 -0
  70. package/dist/docx/serializeParagraph.d.ts +15 -0
  71. package/dist/docx/serializeParagraph.js +208 -0
  72. package/dist/docx/serializeTable.d.ts +12 -0
  73. package/dist/docx/serializeTable.js +134 -0
  74. package/dist/docx/session.d.ts +81 -0
  75. package/dist/docx/session.js +79 -0
  76. package/dist/docx/tableFormatting/editing.d.ts +64 -0
  77. package/dist/docx/tableFormatting/editing.js +318 -0
  78. package/dist/docx/tableFormatting/reading.d.ts +96 -0
  79. package/dist/docx/tableFormatting/reading.js +221 -0
  80. package/dist/docx/tableFormatting.d.ts +2 -0
  81. package/dist/docx/tableFormatting.js +3 -0
  82. package/dist/docx/tableTemplate.d.ts +22 -0
  83. package/dist/docx/tableTemplate.js +111 -0
  84. package/dist/docx/theme.d.ts +40 -0
  85. package/dist/docx/theme.js +61 -0
  86. package/dist/docx/uniqueControls.d.ts +14 -0
  87. package/dist/docx/uniqueControls.js +62 -0
  88. package/dist/download.d.ts +57 -0
  89. package/dist/download.js +44 -0
  90. package/dist/editor/clipboard/images.d.ts +14 -0
  91. package/dist/editor/clipboard/images.js +158 -0
  92. package/dist/editor/clipboard/inlineFormatting.d.ts +21 -0
  93. package/dist/editor/clipboard/inlineFormatting.js +232 -0
  94. package/dist/editor/commands/breakCommands.d.ts +8 -0
  95. package/dist/editor/commands/breakCommands.js +19 -0
  96. package/dist/editor/commands/canRunCommand.d.ts +6 -0
  97. package/dist/editor/commands/canRunCommand.js +10 -0
  98. package/dist/editor/commands/commentCommands.d.ts +3 -0
  99. package/dist/editor/commands/commentCommands.js +4 -0
  100. package/dist/editor/commands/comments/editing.d.ts +21 -0
  101. package/dist/editor/commands/comments/editing.js +305 -0
  102. package/dist/editor/commands/comments/model.d.ts +31 -0
  103. package/dist/editor/commands/comments/model.js +0 -0
  104. package/dist/editor/commands/comments/reading.d.ts +8 -0
  105. package/dist/editor/commands/comments/reading.js +58 -0
  106. package/dist/editor/commands/formatting/editing.d.ts +32 -0
  107. package/dist/editor/commands/formatting/editing.js +138 -0
  108. package/dist/editor/commands/formatting/reading.d.ts +57 -0
  109. package/dist/editor/commands/formatting/reading.js +82 -0
  110. package/dist/editor/commands/formatting/shared.d.ts +32 -0
  111. package/dist/editor/commands/formatting/shared.js +53 -0
  112. package/dist/editor/commands/formattingCommands.d.ts +2 -0
  113. package/dist/editor/commands/formattingCommands.js +3 -0
  114. package/dist/editor/commands/historyCommands.d.ts +11 -0
  115. package/dist/editor/commands/historyCommands.js +16 -0
  116. package/dist/editor/commands/indentCommands.d.ts +15 -0
  117. package/dist/editor/commands/indentCommands.js +44 -0
  118. package/dist/editor/commands/index.d.ts +82 -0
  119. package/dist/editor/commands/index.js +171 -0
  120. package/dist/editor/commands/linkCommands.d.ts +56 -0
  121. package/dist/editor/commands/linkCommands.js +146 -0
  122. package/dist/editor/commands/listCommands.d.ts +58 -0
  123. package/dist/editor/commands/listCommands.js +140 -0
  124. package/dist/editor/commands/lockCommands.d.ts +47 -0
  125. package/dist/editor/commands/lockCommands.js +198 -0
  126. package/dist/editor/commands/noteQueries.d.ts +12 -0
  127. package/dist/editor/commands/noteQueries.js +29 -0
  128. package/dist/editor/commands/paragraphCommands.d.ts +59 -0
  129. package/dist/editor/commands/paragraphCommands.js +113 -0
  130. package/dist/editor/commands/spacingCommands.d.ts +23 -0
  131. package/dist/editor/commands/spacingCommands.js +48 -0
  132. package/dist/editor/commands/tabCommands.d.ts +5 -0
  133. package/dist/editor/commands/tabCommands.js +65 -0
  134. package/dist/editor/createEditor.d.ts +59 -0
  135. package/dist/editor/createEditor.js +160 -0
  136. package/dist/editor/documentStyles.d.ts +60 -0
  137. package/dist/editor/documentStyles.js +80 -0
  138. package/dist/editor/externalClipboard.d.ts +11 -0
  139. package/dist/editor/externalClipboard.js +323 -0
  140. package/dist/editor/imageFiles.d.ts +74 -0
  141. package/dist/editor/imageFiles.js +173 -0
  142. package/dist/editor/insertImage.d.ts +31 -0
  143. package/dist/editor/insertImage.js +35 -0
  144. package/dist/editor/insertTable.d.ts +18 -0
  145. package/dist/editor/insertTable.js +44 -0
  146. package/dist/editor/paragraphEdits.d.ts +42 -0
  147. package/dist/editor/paragraphEdits.js +59 -0
  148. package/dist/editor/plainText.d.ts +3 -0
  149. package/dist/editor/plainText.js +50 -0
  150. package/dist/editor/plugins/bookmarkProtection.d.ts +3 -0
  151. package/dist/editor/plugins/bookmarkProtection.js +28 -0
  152. package/dist/editor/plugins/columnResize.d.ts +27 -0
  153. package/dist/editor/plugins/columnResize.js +192 -0
  154. package/dist/editor/plugins/commentDecorations.d.ts +3 -0
  155. package/dist/editor/plugins/commentDecorations.js +23 -0
  156. package/dist/editor/plugins/commentReservations.d.ts +5 -0
  157. package/dist/editor/plugins/commentReservations.js +26 -0
  158. package/dist/editor/plugins/dropCaret.d.ts +10 -0
  159. package/dist/editor/plugins/dropCaret.js +11 -0
  160. package/dist/editor/plugins/imagePaste.d.ts +8 -0
  161. package/dist/editor/plugins/imagePaste.js +265 -0
  162. package/dist/editor/plugins/keymap.d.ts +5 -0
  163. package/dist/editor/plugins/keymap.js +94 -0
  164. package/dist/editor/plugins/linkPanel.d.ts +23 -0
  165. package/dist/editor/plugins/linkPanel.js +39 -0
  166. package/dist/editor/plugins/listInputRules.d.ts +14 -0
  167. package/dist/editor/plugins/listInputRules.js +36 -0
  168. package/dist/editor/plugins/lockedContent.d.ts +6 -0
  169. package/dist/editor/plugins/lockedContent.js +41 -0
  170. package/dist/editor/plugins/noteProtection.d.ts +3 -0
  171. package/dist/editor/plugins/noteProtection.js +25 -0
  172. package/dist/editor/plugins/numberingDecorations.d.ts +42 -0
  173. package/dist/editor/plugins/numberingDecorations.js +110 -0
  174. package/dist/editor/plugins/rowResize.d.ts +15 -0
  175. package/dist/editor/plugins/rowResize.js +196 -0
  176. package/dist/editor/plugins/styledParagraphs.d.ts +15 -0
  177. package/dist/editor/plugins/styledParagraphs.js +65 -0
  178. package/dist/editor/plugins/tabCaret.d.ts +3 -0
  179. package/dist/editor/plugins/tabCaret.js +126 -0
  180. package/dist/editor/plugins/tabDecorations.d.ts +11 -0
  181. package/dist/editor/plugins/tabDecorations.js +87 -0
  182. package/dist/editor/plugins/tabLayout.d.ts +16 -0
  183. package/dist/editor/plugins/tabLayout.js +328 -0
  184. package/dist/editor/plugins/tabPointer.d.ts +7 -0
  185. package/dist/editor/plugins/tabPointer.js +95 -0
  186. package/dist/editor/plugins/tableContextMenu.d.ts +21 -0
  187. package/dist/editor/plugins/tableContextMenu.js +88 -0
  188. package/dist/editor/plugins/textContextMenu.d.ts +15 -0
  189. package/dist/editor/plugins/textContextMenu.js +90 -0
  190. package/dist/editor/views/imageResize.d.ts +53 -0
  191. package/dist/editor/views/imageResize.js +167 -0
  192. package/dist/editor/views/runMarkView.d.ts +15 -0
  193. package/dist/editor/views/runMarkView.js +9 -0
  194. package/dist/editor/views/tableView.d.ts +24 -0
  195. package/dist/editor/views/tableView.js +32 -0
  196. package/dist/index.d.ts +44 -0
  197. package/dist/index.js +38 -0
  198. package/dist/model/format.d.ts +240 -0
  199. package/dist/model/format.js +305 -0
  200. package/dist/model/tabStops.d.ts +17 -0
  201. package/dist/model/tabStops.js +22 -0
  202. package/dist/numbering/listTemplate.d.ts +29 -0
  203. package/dist/numbering/listTemplate.js +83 -0
  204. package/dist/numbering/markers.d.ts +24 -0
  205. package/dist/numbering/markers.js +93 -0
  206. package/dist/numbering/parseNumbering.d.ts +65 -0
  207. package/dist/numbering/parseNumbering.js +116 -0
  208. package/dist/numbering/writeNumbering.d.ts +13 -0
  209. package/dist/numbering/writeNumbering.js +49 -0
  210. package/dist/ooxml/errors.d.ts +39 -0
  211. package/dist/ooxml/errors.js +21 -0
  212. package/dist/ooxml/image.d.ts +88 -0
  213. package/dist/ooxml/image.js +106 -0
  214. package/dist/ooxml/tabStops.d.ts +3 -0
  215. package/dist/ooxml/tabStops.js +51 -0
  216. package/dist/ooxml/units.d.ts +37 -0
  217. package/dist/ooxml/units.js +116 -0
  218. package/dist/ooxml/xml.d.ts +36 -0
  219. package/dist/ooxml/xml.js +89 -0
  220. package/dist/page/PageGuides.d.ts +16 -0
  221. package/dist/page/PageGuides.js +114 -0
  222. package/dist/page/measureBlocks.d.ts +25 -0
  223. package/dist/page/measureBlocks.js +80 -0
  224. package/dist/page/pageDecorations.d.ts +36 -0
  225. package/dist/page/pageDecorations.js +211 -0
  226. package/dist/page/pageLayout.d.ts +176 -0
  227. package/dist/page/pageLayout.js +157 -0
  228. package/dist/page/tableMeasurements.d.ts +10 -0
  229. package/dist/page/tableMeasurements.js +115 -0
  230. package/dist/page/usePageLayout.d.ts +57 -0
  231. package/dist/page/usePageLayout.js +141 -0
  232. package/dist/schema/docxSchema.d.ts +9 -0
  233. package/dist/schema/docxSchema.js +863 -0
  234. package/dist/schema/index.d.ts +2 -0
  235. package/dist/schema/index.js +9 -0
  236. package/dist/schema/locks.d.ts +112 -0
  237. package/dist/schema/locks.js +211 -0
  238. package/dist/schema/rendering.d.ts +6 -0
  239. package/dist/schema/rendering.js +46 -0
  240. package/dist/styles/classNames.d.ts +214 -0
  241. package/dist/styles/classNames.js +208 -0
  242. package/dist/styles/colors.d.ts +11 -0
  243. package/dist/styles/colors.js +14 -0
  244. package/dist/styles/fontSizes.d.ts +6 -0
  245. package/dist/styles/fontSizes.js +20 -0
  246. package/dist/styles/fontStack.d.ts +55 -0
  247. package/dist/styles/fontStack.js +262 -0
  248. package/dist/styles/fonts.d.ts +6 -0
  249. package/dist/styles/fonts.js +11 -0
  250. package/dist/styles/inlineStyle.d.ts +67 -0
  251. package/dist/styles/inlineStyle.js +212 -0
  252. package/dist/styles/lineSpacings.d.ts +11 -0
  253. package/dist/styles/lineSpacings.js +10 -0
  254. package/dist/styles.css +1650 -0
  255. package/dist/table/cellBorders.d.ts +12 -0
  256. package/dist/table/cellBorders.js +9 -0
  257. package/dist/table/cellFormatting.d.ts +57 -0
  258. package/dist/table/cellFormatting.js +173 -0
  259. package/dist/table/columns.d.ts +25 -0
  260. package/dist/table/columns.js +155 -0
  261. package/dist/table/commands.d.ts +19 -0
  262. package/dist/table/commands.js +63 -0
  263. package/dist/table/format.d.ts +35 -0
  264. package/dist/table/format.js +26 -0
  265. package/dist/table/gridBorders.d.ts +42 -0
  266. package/dist/table/gridBorders.js +192 -0
  267. package/dist/table/index.d.ts +16 -0
  268. package/dist/table/index.js +52 -0
  269. package/dist/table/merge.d.ts +36 -0
  270. package/dist/table/merge.js +125 -0
  271. package/dist/table/resize.d.ts +55 -0
  272. package/dist/table/resize.js +66 -0
  273. package/dist/table/rowResize.d.ts +14 -0
  274. package/dist/table/rowResize.js +44 -0
  275. package/dist/table/rows.d.ts +32 -0
  276. package/dist/table/rows.js +89 -0
  277. package/dist/table/widths.d.ts +69 -0
  278. package/dist/table/widths.js +97 -0
  279. package/dist/ui/AlignMenu.d.ts +15 -0
  280. package/dist/ui/AlignMenu.js +64 -0
  281. package/dist/ui/CellStyleGroup.d.ts +15 -0
  282. package/dist/ui/CellStyleGroup.js +232 -0
  283. package/dist/ui/ColorPicker.d.ts +13 -0
  284. package/dist/ui/ColorPicker.js +165 -0
  285. package/dist/ui/CommentsPanel.d.ts +15 -0
  286. package/dist/ui/CommentsPanel.js +348 -0
  287. package/dist/ui/FontFamilySelect.d.ts +14 -0
  288. package/dist/ui/FontFamilySelect.js +59 -0
  289. package/dist/ui/FontSizeSelect.d.ts +11 -0
  290. package/dist/ui/FontSizeSelect.js +49 -0
  291. package/dist/ui/InsertImageButton.d.ts +9 -0
  292. package/dist/ui/InsertImageButton.js +47 -0
  293. package/dist/ui/LinkCard.d.ts +12 -0
  294. package/dist/ui/LinkCard.js +127 -0
  295. package/dist/ui/LinkPanel.d.ts +9 -0
  296. package/dist/ui/LinkPanel.js +121 -0
  297. package/dist/ui/MenuChoice.d.ts +11 -0
  298. package/dist/ui/MenuChoice.js +32 -0
  299. package/dist/ui/NotesPanel.d.ts +6 -0
  300. package/dist/ui/NotesPanel.js +33 -0
  301. package/dist/ui/ParagraphStyleSelect.d.ts +11 -0
  302. package/dist/ui/ParagraphStyleSelect.js +62 -0
  303. package/dist/ui/Popover.d.ts +22 -0
  304. package/dist/ui/Popover.js +74 -0
  305. package/dist/ui/SpacingMenu.d.ts +12 -0
  306. package/dist/ui/SpacingMenu.js +54 -0
  307. package/dist/ui/TableMenu.d.ts +12 -0
  308. package/dist/ui/TableMenu.js +112 -0
  309. package/dist/ui/TableSizePicker.d.ts +9 -0
  310. package/dist/ui/TableSizePicker.js +53 -0
  311. package/dist/ui/TextMenu.d.ts +15 -0
  312. package/dist/ui/TextMenu.js +194 -0
  313. package/dist/ui/Toolbar.d.ts +19 -0
  314. package/dist/ui/Toolbar.js +448 -0
  315. package/dist/ui/ToolbarButton.d.ts +23 -0
  316. package/dist/ui/ToolbarButton.js +56 -0
  317. package/dist/ui/Tooltip.d.ts +19 -0
  318. package/dist/ui/Tooltip.js +47 -0
  319. package/dist/ui/ZoomSelect.d.ts +7 -0
  320. package/dist/ui/ZoomSelect.js +44 -0
  321. package/dist/ui/comments/CommentComposer.d.ts +17 -0
  322. package/dist/ui/comments/CommentComposer.js +59 -0
  323. package/dist/ui/comments/useCommentRailLayout.d.ts +18 -0
  324. package/dist/ui/comments/useCommentRailLayout.js +183 -0
  325. package/dist/ui/keyboardWalk.d.ts +22 -0
  326. package/dist/ui/keyboardWalk.js +70 -0
  327. package/dist/ui/openAddress.d.ts +11 -0
  328. package/dist/ui/openAddress.js +16 -0
  329. package/dist/ui/panelPlacement.d.ts +51 -0
  330. package/dist/ui/panelPlacement.js +71 -0
  331. package/dist/ui/presets.d.ts +11 -0
  332. package/dist/ui/presets.js +0 -0
  333. package/dist/ui/rovingFocus.d.ts +20 -0
  334. package/dist/ui/rovingFocus.js +61 -0
  335. package/dist/ui/runCommand.d.ts +5 -0
  336. package/dist/ui/runCommand.js +13 -0
  337. package/dist/ui/useDismiss.d.ts +6 -0
  338. package/dist/ui/useDismiss.js +31 -0
  339. package/dist/ui/useFitWidthZoom.d.ts +2 -0
  340. package/dist/ui/useFitWidthZoom.js +26 -0
  341. package/dist/ui/useGridKeyboard.d.ts +12 -0
  342. package/dist/ui/useGridKeyboard.js +90 -0
  343. package/dist/ui/useMenuKeyboard.d.ts +12 -0
  344. package/dist/ui/useMenuKeyboard.js +56 -0
  345. package/dist/ui/zoom.d.ts +4 -0
  346. package/dist/ui/zoom.js +21 -0
  347. package/package.json +120 -0
@@ -0,0 +1,82 @@
1
+ // src/editor/commands/formatting/reading.ts
2
+ import { fontNamesOf } from "../../../docx/formatting.js";
3
+ import {
4
+ NO_FILL,
5
+ toRunFormat
6
+ } from "../../../model/format.js";
7
+ import {
8
+ DEFAULT_FONT_FALLBACKS
9
+ } from "../../../styles/fontStack.js";
10
+ import {
11
+ FALLBACK_FONT_SIZE_PT,
12
+ HIGHLIGHT_COLORS
13
+ } from "../../../styles/inlineStyle.js";
14
+ import { documentDefaults } from "../../documentStyles.js";
15
+ import { activePieces, runMarkOf } from "./shared.js";
16
+ function sharedValue(values) {
17
+ if (values.length === 0) return null;
18
+ const [first, ...rest] = values;
19
+ return rest.every((value) => value === first) ? first : null;
20
+ }
21
+ function defaultFontSizePt(state) {
22
+ return documentDefaults(state).fontSizePt ?? FALLBACK_FONT_SIZE_PT;
23
+ }
24
+ function activeFontSize(state) {
25
+ const sizes = activePieces(state).map(
26
+ (target) => target.format?.fontSizePt ?? null
27
+ );
28
+ const first = sizes[0] ?? null;
29
+ if (sizes.some((pt) => pt !== first)) return { kind: "mixed" };
30
+ if (first !== null) return { kind: "size", pt: first };
31
+ return { kind: "default", pt: defaultFontSizePt(state) };
32
+ }
33
+ function fontNameOf(format) {
34
+ return fontNamesOf(format?.fontFamily)[0] ?? null;
35
+ }
36
+ function defaultFontName(state, fontFallbacks) {
37
+ const defaults = documentDefaults(state);
38
+ return fontNamesOf(defaults.fontFamily)[0] ?? fontFallbacks.defaultFontName;
39
+ }
40
+ function activeFontFamily(state, fontFallbacks = DEFAULT_FONT_FALLBACKS) {
41
+ const names = activePieces(state).map((target) => fontNameOf(target.format));
42
+ const first = names[0] ?? null;
43
+ if (names.some((name) => name !== first)) return { kind: "mixed" };
44
+ if (first !== null) return { kind: "font", name: first };
45
+ return { kind: "default", name: defaultFontName(state, fontFallbacks) };
46
+ }
47
+ function documentFontNames(doc, defaults) {
48
+ const names = new Set(fontNamesOf(defaults.fontFamily));
49
+ doc.descendants((node) => {
50
+ const mark = runMarkOf(node.marks);
51
+ for (const name of fontNamesOf(
52
+ toRunFormat(mark?.attrs.format)?.fontFamily
53
+ )) {
54
+ names.add(name);
55
+ }
56
+ return true;
57
+ });
58
+ return Array.from(names).sort((a, b) => a.localeCompare(b));
59
+ }
60
+ function activeTextColor(state) {
61
+ return sharedValue(
62
+ activePieces(state).map((target) => target.format?.color ?? null)
63
+ );
64
+ }
65
+ function backgroundOf(format) {
66
+ const highlight = format?.highlight;
67
+ if (highlight !== void 0) return HIGHLIGHT_COLORS[highlight] ?? null;
68
+ const background = format?.background ?? null;
69
+ return background === NO_FILL ? null : background;
70
+ }
71
+ function activeTextBackground(state) {
72
+ return sharedValue(
73
+ activePieces(state).map((target) => backgroundOf(target.format ?? null))
74
+ );
75
+ }
76
+ export {
77
+ activeFontFamily,
78
+ activeFontSize,
79
+ activeTextBackground,
80
+ activeTextColor,
81
+ documentFontNames
82
+ };
@@ -0,0 +1,32 @@
1
+ /** Shared text-piece discovery for formatting reads and edits. */
2
+ import type { Mark } from "prosemirror-model";
3
+ import type { EditorState } from "prosemirror-state";
4
+ import { type RunFormat } from "../../../model/format";
5
+ /** One piece of text whose formatting is to be edited */
6
+ export interface TextPiece {
7
+ from: number;
8
+ to: number;
9
+ /** The run mark this text carries. Null for text with no formatting */
10
+ mark: Mark | null;
11
+ /** The formatting XML of the paragraph the text sits in. Used to check for style inheritance */
12
+ pPr: string | null;
13
+ /** The effective formatting visible on screen */
14
+ format: RunFormat | null;
15
+ }
16
+ export declare function text(value: unknown): string | null;
17
+ export declare function runMarkOf(marks: readonly Mark[]): Mark | null;
18
+ /**
19
+ * The text pieces inside the selection.
20
+ * Non-text content is skipped. A tab is text in the model and shares its OOXML run properties,
21
+ * so character formatting reaches it along with the visible characters around it.
22
+ * Selections with several ranges, such as a table cell selection, go down the same path.
23
+ */
24
+ export declare function textPieces(state: EditorState): TextPiece[];
25
+ /** When the selection is collapsed, the formatting that text typed next will follow */
26
+ export declare function caretPiece(state: EditorState): TextPiece;
27
+ /**
28
+ * The places formatting currently applies to: a single caret, or the text pieces of the selection
29
+ * a lock leaves open. It has to leave out what `applyToSelection` leaves out, or a toggle reads off
30
+ * for text that is already on and can never turn it off.
31
+ */
32
+ export declare function activePieces(state: EditorState): TextPiece[];
@@ -0,0 +1,53 @@
1
+ // src/editor/commands/formatting/shared.ts
2
+ import { toRunFormat } from "../../../model/format.js";
3
+ import { docxSchema } from "../../../schema/index.js";
4
+ import { rangeTouchesLocked } from "../../../schema/locks.js";
5
+ function text(value) {
6
+ return typeof value === "string" ? value : null;
7
+ }
8
+ function runMarkOf(marks) {
9
+ return marks.find((mark) => mark.type === docxSchema.marks.run) ?? null;
10
+ }
11
+ function piece(from, to, marks, parent) {
12
+ const mark = runMarkOf(marks);
13
+ return {
14
+ from,
15
+ to,
16
+ mark,
17
+ pPr: text(parent?.attrs.pPr),
18
+ format: toRunFormat(mark?.attrs.format)
19
+ };
20
+ }
21
+ function textPieces(state) {
22
+ const pieces = [];
23
+ for (const range of state.selection.ranges) {
24
+ const from = range.$from.pos;
25
+ const to = range.$to.pos;
26
+ state.doc.nodesBetween(from, to, (node, pos, parent) => {
27
+ if (!node.isText) return true;
28
+ const start = Math.max(pos, from);
29
+ const end = Math.min(pos + node.nodeSize, to);
30
+ if (start < end) pieces.push(piece(start, end, node.marks, parent));
31
+ return false;
32
+ });
33
+ }
34
+ return pieces;
35
+ }
36
+ function caretPiece(state) {
37
+ const $from = state.selection.$from;
38
+ const marks = state.storedMarks ?? $from.marks();
39
+ return piece($from.pos, $from.pos, marks, $from.parent);
40
+ }
41
+ function activePieces(state) {
42
+ if (state.selection.empty) return [caretPiece(state)];
43
+ return textPieces(state).filter(
44
+ (target) => !rangeTouchesLocked(state.doc, target.from, target.to)
45
+ );
46
+ }
47
+ export {
48
+ activePieces,
49
+ caretPiece,
50
+ runMarkOf,
51
+ text,
52
+ textPieces
53
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./formatting/editing";
2
+ export * from "./formatting/reading";
@@ -0,0 +1,3 @@
1
+ // src/editor/commands/formattingCommands.ts
2
+ export * from "./formatting/editing.js";
3
+ export * from "./formatting/reading.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Undo and redo, each carrying the pass that takes a replayed lock through the lock guard
3
+ * (`historyReplay` in `schema/locks`).
4
+ *
5
+ * These are the two the keymap, the toolbar and `./commands` use. A raw prosemirror-history command
6
+ * is refused the moment the history reaches a lock, and that refusal leaves everything behind it in
7
+ * the history out of reach.
8
+ */
9
+ import type { Command } from "prosemirror-state";
10
+ export declare const undo: Command;
11
+ export declare const redo: Command;
@@ -0,0 +1,16 @@
1
+ // src/editor/commands/historyCommands.ts
2
+ import { redo as historyRedo, undo as historyUndo } from "prosemirror-history";
3
+ import { historyReplay } from "../../schema/locks.js";
4
+ function replaying(command) {
5
+ return (state, dispatch, view) => command(
6
+ state,
7
+ dispatch && ((tr) => dispatch(tr.setMeta(historyReplay, true))),
8
+ view
9
+ );
10
+ }
11
+ var undo = replaying(historyUndo);
12
+ var redo = replaying(historyRedo);
13
+ export {
14
+ redo,
15
+ undo
16
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The indent commands, which work on any paragraph.
3
+ *
4
+ * In any paragraph but a list they move that paragraph's own left indent one step, the same as
5
+ * Word, which is what sets them apart from `increaseListLevel` and `decreaseListLevel`.
6
+ * In a list paragraph they move the item one level instead, exactly what Tab and Shift+Tab do.
7
+ * A selection holding both kinds gets each paragraph treated by its own rule.
8
+ */
9
+ import type { Command, EditorState } from "prosemirror-state";
10
+ export declare const increaseIndent: Command;
11
+ export declare const decreaseIndent: Command;
12
+ /** Whether anything in the selection can still move right. The toolbar disables the button when nothing can */
13
+ export declare function canIncreaseIndent(state: EditorState): boolean;
14
+ /** Whether anything in the selection can still move left. A paragraph with no indent left to give up cannot */
15
+ export declare function canDecreaseIndent(state: EditorState): boolean;
@@ -0,0 +1,44 @@
1
+ // src/editor/commands/indentCommands.ts
2
+ import { withLeftIndent, withListNumbering } from "../../docx/paraProps.js";
3
+ import { toParagraphFormat } from "../../model/format.js";
4
+ import { editParagraphs, paragraphPPr } from "../paragraphEdits.js";
5
+ import { documentNumbering } from "../plugins/numberingDecorations.js";
6
+ import { listLevelChange, listRefOf } from "./listCommands.js";
7
+ var STEP_TWIPS = 720;
8
+ function leftIndentTwips(node) {
9
+ const format = toParagraphFormat(node.attrs.format);
10
+ const pt = format?.indentStartPt ?? format?.indentLeftPt ?? 0;
11
+ return Math.round(pt * 20);
12
+ }
13
+ function steppedLeftTwips(node, delta) {
14
+ const left = leftIndentTwips(node);
15
+ if (delta === -1 && left <= 0) return null;
16
+ return Math.max(0, left + delta * STEP_TWIPS);
17
+ }
18
+ function indentStep(delta) {
19
+ return (state, dispatch) => {
20
+ const numbering = documentNumbering(state);
21
+ return editParagraphs(state, dispatch, (node, styles, defaultStyleId) => {
22
+ if (listRefOf(node)) {
23
+ const change = listLevelChange(numbering, node, delta);
24
+ return change && withListNumbering(paragraphPPr(node), change, styles, defaultStyleId);
25
+ }
26
+ const left = steppedLeftTwips(node, delta);
27
+ return left === null ? null : withLeftIndent(paragraphPPr(node), left, styles, defaultStyleId);
28
+ });
29
+ };
30
+ }
31
+ var increaseIndent = indentStep(1);
32
+ var decreaseIndent = indentStep(-1);
33
+ function canIncreaseIndent(state) {
34
+ return increaseIndent(state);
35
+ }
36
+ function canDecreaseIndent(state) {
37
+ return decreaseIndent(state);
38
+ }
39
+ export {
40
+ canDecreaseIndent,
41
+ canIncreaseIndent,
42
+ decreaseIndent,
43
+ increaseIndent
44
+ };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The public surface for character formatting and list editing.
3
+ *
4
+ * Everything the built-in toolbar and the right click menu run is exported, so a consumer can
5
+ * build controls of its own design or drive the same editing from a plugin. Following the
6
+ * ProseMirror convention, calling a command without `dispatch` only reports whether it is
7
+ * applicable right now, and `is*Active`, `can*` and `active*` are used to render button state.
8
+ */
9
+ import type { Command } from "prosemirror-state";
10
+ export type EditorCommand = Command;
11
+ /** The paragraph styles the document defines, which the style picker offers */
12
+ export type { ParagraphStyleOption } from "../../docx/formatting";
13
+ export type { RunToggle } from "../../docx/runProps";
14
+ export type { LineSpacing, ParagraphAlign } from "../../model/format";
15
+ export type { ListKind } from "../../numbering/listTemplate";
16
+ /** The size an image is shown at, which the insert command asks for */
17
+ export type { ImageExtent } from "../../ooxml/image";
18
+ /** The fonts to draw with where a document names one the machine does not have, which the font queries read */
19
+ export type { FontFallbacks } from "../../styles/fontStack";
20
+ /**
21
+ * The document's own default formatting, which `documentFontNames` needs, and the width of one
22
+ * line of body text on the paper the document names, which is what an image wider than the page
23
+ * is shrunk to
24
+ */
25
+ export { documentBodyWidthPx, documentDefaults, documentParagraphStyles, } from "../documentStyles";
26
+ /**
27
+ * The way an image file goes from outside into the document, which is what an image button of
28
+ * your own stands on. `insertImageFiles` is all of it in one call, and is what the built-in
29
+ * button runs; `readImageFile` and `fittedExtent` are for a caller that puts the image in itself,
30
+ * the second being the rule by which an image wider than the body is shrunk to the body width.
31
+ * Both take that width, which `documentBodyWidthPx` reads off the open document; left out, it is
32
+ * A4's.
33
+ */
34
+ export { fittedExtent, IMAGE_FILE_ACCEPT, imageFilesIn, insertImageFiles, readImageFile, } from "../imageFiles";
35
+ export type { ImageToInsert } from "../insertImage";
36
+ export { canInsertImage, insertImage } from "../insertImage";
37
+ export type { TableSize } from "../insertTable";
38
+ export { canInsertTable, insertTable } from "../insertTable";
39
+ /**
40
+ * The two breaks, which are what the keymap binds to Shift+Enter and Mod+Enter
41
+ * (`editor/plugins/keymap`), so a control of your own can put in either.
42
+ */
43
+ export { insertLineBreak, insertPageBreak } from "./breakCommands";
44
+ /**
45
+ * Whether a command this package does not own would go through right now, the lock guard included.
46
+ * The commands here need no such wrapper: each of them asks the guard before it answers. What does
47
+ * is a command of a consumer's own, or one out of `prosemirror-commands`, since the predicates the
48
+ * question takes are not exported anywhere.
49
+ */
50
+ export { canRunCommand } from "./canRunCommand";
51
+ export type { CommentAuthor, DocumentComment, DocumentCommentReply, NewComment, } from "./commentCommands";
52
+ export { addComment, addCommentReply, canAddComment, documentComments, removeComment, removeCommentReply, selectComment, setCommentResolved, updateComment, updateCommentReply, } from "./commentCommands";
53
+ export type { ActiveFontFamily, ActiveFontSize, } from "./formattingCommands";
54
+ export { activeFontFamily, activeFontSize, activeTextBackground, activeTextColor, canFormatText, documentFontNames, isBoldActive, isItalicActive, isStrikeActive, isUnderlineActive, setFontFamily, setFontSize, setTextBackground, setTextColor, toggleBold, toggleItalic, toggleStrike, toggleUnderline, } from "./formattingCommands";
55
+ /**
56
+ * Undo and redo are the editor's own rather than prosemirror-history's, because a replayed lock
57
+ * only passes the lock guard with the pass these two carry (`./historyCommands`). They also find
58
+ * the history this editor keeps, which an import of the consumer's own copy of prosemirror-history
59
+ * would not.
60
+ */
61
+ export { redo, undo } from "./historyCommands";
62
+ export { canDecreaseIndent, canIncreaseIndent, decreaseIndent, increaseIndent, } from "./indentCommands";
63
+ export type { ActiveLinkSpan } from "./linkCommands";
64
+ /**
65
+ * The link commands, which the Cmd+K panel and the toolbar button are drawn from
66
+ * (`ui/LinkPanel`). `activeLink` is the address to show, `canSetLink` whether a link may go on at
67
+ * all - it is asked before an address has been typed - and `removeLink` reporting false is how a
68
+ * control knows there is no link to take away.
69
+ * `activeLinkSpan` is the one link the selection sits inside, stretch and address, which is what a
70
+ * card standing by a link is placed and drawn from (`ui/LinkCard`).
71
+ */
72
+ export { activeLink, activeLinkSpan, canSetLink, removeLink, setLink, } from "./linkCommands";
73
+ export { activeListKind, decreaseListLevel, increaseListLevel, isInList, toggleBulletList, toggleNumberedList, } from "./listCommands";
74
+ export type { SelectionLock } from "./lockCommands";
75
+ export { documentHasLocked, lockSelection, selectionLock, selectionTouchesLocked, unlockSelection, } from "./lockCommands";
76
+ export type { DocumentNote } from "./noteQueries";
77
+ export { documentNotes } from "./noteQueries";
78
+ export type { ActiveParagraphAlign, ActiveParagraphStyle, } from "./paragraphCommands";
79
+ export { activeParagraphAlign, activeParagraphStyle, canSetParagraphAlign, setParagraphAlign, setParagraphStyle, } from "./paragraphCommands";
80
+ export { activeLineSpacing, canSetLineSpacing, SINGLE_LINE_SPACING, setLineSpacing, } from "./spacingCommands";
81
+ /** Inserts the same editable DOCX tab as the built-in Tab binding. */
82
+ export { insertTab } from "./tabCommands";
@@ -0,0 +1,171 @@
1
+ // src/editor/commands/index.ts
2
+ import {
3
+ documentBodyWidthPx,
4
+ documentDefaults,
5
+ documentParagraphStyles
6
+ } from "../documentStyles.js";
7
+ import {
8
+ fittedExtent,
9
+ IMAGE_FILE_ACCEPT,
10
+ imageFilesIn,
11
+ insertImageFiles,
12
+ readImageFile
13
+ } from "../imageFiles.js";
14
+ import { canInsertImage, insertImage } from "../insertImage.js";
15
+ import { canInsertTable, insertTable } from "../insertTable.js";
16
+ import { insertLineBreak, insertPageBreak } from "./breakCommands.js";
17
+ import { canRunCommand } from "./canRunCommand.js";
18
+ import {
19
+ addComment,
20
+ addCommentReply,
21
+ canAddComment,
22
+ documentComments,
23
+ removeComment,
24
+ removeCommentReply,
25
+ selectComment,
26
+ setCommentResolved,
27
+ updateComment,
28
+ updateCommentReply
29
+ } from "./commentCommands.js";
30
+ import {
31
+ activeFontFamily,
32
+ activeFontSize,
33
+ activeTextBackground,
34
+ activeTextColor,
35
+ canFormatText,
36
+ documentFontNames,
37
+ isBoldActive,
38
+ isItalicActive,
39
+ isStrikeActive,
40
+ isUnderlineActive,
41
+ setFontFamily,
42
+ setFontSize,
43
+ setTextBackground,
44
+ setTextColor,
45
+ toggleBold,
46
+ toggleItalic,
47
+ toggleStrike,
48
+ toggleUnderline
49
+ } from "./formattingCommands.js";
50
+ import { redo, undo } from "./historyCommands.js";
51
+ import {
52
+ canDecreaseIndent,
53
+ canIncreaseIndent,
54
+ decreaseIndent,
55
+ increaseIndent
56
+ } from "./indentCommands.js";
57
+ import {
58
+ activeLink,
59
+ activeLinkSpan,
60
+ canSetLink,
61
+ removeLink,
62
+ setLink
63
+ } from "./linkCommands.js";
64
+ import {
65
+ activeListKind,
66
+ decreaseListLevel,
67
+ increaseListLevel,
68
+ isInList,
69
+ toggleBulletList,
70
+ toggleNumberedList
71
+ } from "./listCommands.js";
72
+ import {
73
+ documentHasLocked,
74
+ lockSelection,
75
+ selectionLock,
76
+ selectionTouchesLocked,
77
+ unlockSelection
78
+ } from "./lockCommands.js";
79
+ import { documentNotes } from "./noteQueries.js";
80
+ import {
81
+ activeParagraphAlign,
82
+ activeParagraphStyle,
83
+ canSetParagraphAlign,
84
+ setParagraphAlign,
85
+ setParagraphStyle
86
+ } from "./paragraphCommands.js";
87
+ import {
88
+ activeLineSpacing,
89
+ canSetLineSpacing,
90
+ SINGLE_LINE_SPACING,
91
+ setLineSpacing
92
+ } from "./spacingCommands.js";
93
+ import { insertTab } from "./tabCommands.js";
94
+ export {
95
+ IMAGE_FILE_ACCEPT,
96
+ SINGLE_LINE_SPACING,
97
+ activeFontFamily,
98
+ activeFontSize,
99
+ activeLineSpacing,
100
+ activeLink,
101
+ activeLinkSpan,
102
+ activeListKind,
103
+ activeParagraphAlign,
104
+ activeParagraphStyle,
105
+ activeTextBackground,
106
+ activeTextColor,
107
+ addComment,
108
+ addCommentReply,
109
+ canAddComment,
110
+ canDecreaseIndent,
111
+ canFormatText,
112
+ canIncreaseIndent,
113
+ canInsertImage,
114
+ canInsertTable,
115
+ canRunCommand,
116
+ canSetLineSpacing,
117
+ canSetLink,
118
+ canSetParagraphAlign,
119
+ decreaseIndent,
120
+ decreaseListLevel,
121
+ documentBodyWidthPx,
122
+ documentComments,
123
+ documentDefaults,
124
+ documentFontNames,
125
+ documentHasLocked,
126
+ documentNotes,
127
+ documentParagraphStyles,
128
+ fittedExtent,
129
+ imageFilesIn,
130
+ increaseIndent,
131
+ increaseListLevel,
132
+ insertImage,
133
+ insertImageFiles,
134
+ insertLineBreak,
135
+ insertPageBreak,
136
+ insertTab,
137
+ insertTable,
138
+ isBoldActive,
139
+ isInList,
140
+ isItalicActive,
141
+ isStrikeActive,
142
+ isUnderlineActive,
143
+ lockSelection,
144
+ readImageFile,
145
+ redo,
146
+ removeComment,
147
+ removeCommentReply,
148
+ removeLink,
149
+ selectComment,
150
+ selectionLock,
151
+ selectionTouchesLocked,
152
+ setCommentResolved,
153
+ setFontFamily,
154
+ setFontSize,
155
+ setLineSpacing,
156
+ setLink,
157
+ setParagraphAlign,
158
+ setParagraphStyle,
159
+ setTextBackground,
160
+ setTextColor,
161
+ toggleBold,
162
+ toggleBulletList,
163
+ toggleItalic,
164
+ toggleNumberedList,
165
+ toggleStrike,
166
+ toggleUnderline,
167
+ undo,
168
+ unlockSelection,
169
+ updateComment,
170
+ updateCommentReply
171
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Creates, removes, and inspects link spans. Existing links are edited as whole objects, while
3
+ * unlocked plain-text pieces can be linked independently; non-inclusive edges remain outside.
4
+ */
5
+ import type { Command, EditorState } from "prosemirror-state";
6
+ /**
7
+ * Puts a link at this address on the text the selection covers, and changes where every link it
8
+ * touches points, each of them whole.
9
+ *
10
+ * A piece already pointing there is left untouched, so the wrapper it came in with is not rewritten
11
+ * for nothing. A host typed with no scheme is written with one (`settled`).
12
+ */
13
+ export declare function setLink(url: string): Command;
14
+ /**
15
+ * Takes off every link the selection touches, each of them whole, however little of it the
16
+ * selection covers.
17
+ * The text and its formatting stay where they are; only the wrapper goes.
18
+ */
19
+ export declare const removeLink: Command;
20
+ /**
21
+ * Whether a link can go on where the selection stands, which is what a control offering one is
22
+ * drawn from.
23
+ *
24
+ * It is asked before an address has been typed, which is why it is a query of its own rather than
25
+ * `setLink(url)` with no dispatch.
26
+ */
27
+ export declare function canSetLink(state: EditorState): boolean;
28
+ /**
29
+ * The address at the selection. null where the selection is in no link, where the link it is in
30
+ * names a bookmark rather than an address, and where several addresses are mixed.
31
+ *
32
+ * The three answer as one, unlike `activeFontSize`, because the one thing drawn from this is the
33
+ * address field of the link panel and all three leave it empty. It reads the same pieces the
34
+ * commands edit, so the address shown is the address `setLink` would change.
35
+ */
36
+ export declare function activeLink(state: EditorState): string | null;
37
+ /** The stretch one link covers, and where it points */
38
+ export interface ActiveLinkSpan {
39
+ from: number;
40
+ to: number;
41
+ /** The address. null for a link that names a bookmark rather than an address */
42
+ href: string | null;
43
+ }
44
+ /**
45
+ * The one link the selection sits inside, as the stretch it covers and the address it points at.
46
+ * null where the selection is in no link, where it runs past the edge of one, and where it covers
47
+ * several.
48
+ *
49
+ * This is what the card that says where a link points is drawn from (`ui/LinkCard`), so it answers
50
+ * about the link rather than about the address: a link naming a bookmark is here with a null `href`,
51
+ * where `activeLink` and it are one answer.
52
+ *
53
+ * The locks are the one thing it does not read. A link inside a settled part of the document still
54
+ * has an address worth reading, and what may be done to it is `canSetLink` and `removeLink`.
55
+ */
56
+ export declare function activeLinkSpan(state: EditorState): ActiveLinkSpan | null;