@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,448 @@
1
+ // src/ui/Toolbar.tsx
2
+ import {
3
+ Baseline,
4
+ Bold,
5
+ Highlighter,
6
+ IndentDecrease,
7
+ IndentIncrease,
8
+ Italic,
9
+ Link,
10
+ List,
11
+ ListChevronsUpDown,
12
+ ListOrdered,
13
+ MessagesSquare,
14
+ Redo2,
15
+ Strikethrough,
16
+ Table,
17
+ Underline,
18
+ Undo2
19
+ } from "lucide-react";
20
+ import { useMemo, useRef } from "react";
21
+ import {
22
+ activeFontFamily,
23
+ activeFontSize,
24
+ activeTextBackground,
25
+ activeTextColor,
26
+ canFormatText,
27
+ documentFontNames,
28
+ isBoldActive,
29
+ isItalicActive,
30
+ isStrikeActive,
31
+ isUnderlineActive,
32
+ setTextBackground,
33
+ setTextColor,
34
+ toggleBold,
35
+ toggleItalic,
36
+ toggleStrike,
37
+ toggleUnderline
38
+ } from "../editor/commands/formattingCommands.js";
39
+ import { redo, undo } from "../editor/commands/historyCommands.js";
40
+ import {
41
+ canDecreaseIndent,
42
+ canIncreaseIndent,
43
+ decreaseIndent,
44
+ increaseIndent
45
+ } from "../editor/commands/indentCommands.js";
46
+ import {
47
+ activeListKind,
48
+ toggleBulletList,
49
+ toggleNumberedList
50
+ } from "../editor/commands/listCommands.js";
51
+ import {
52
+ activeParagraphAlign,
53
+ activeParagraphStyle,
54
+ canSetParagraphAlign
55
+ } from "../editor/commands/paragraphCommands.js";
56
+ import { canSetLineSpacing } from "../editor/commands/spacingCommands.js";
57
+ import {
58
+ documentDefaults,
59
+ documentParagraphStyles
60
+ } from "../editor/documentStyles.js";
61
+ import { canInsertTable } from "../editor/insertTable.js";
62
+ import { openLinkPanel } from "../editor/plugins/linkPanel.js";
63
+ import { editorClassNames } from "../styles/classNames.js";
64
+ import { AlignMenu, alignIcon } from "./AlignMenu.js";
65
+ import { CellStyleGroup } from "./CellStyleGroup.js";
66
+ import { ColorPicker } from "./ColorPicker.js";
67
+ import { FontFamilySelect } from "./FontFamilySelect.js";
68
+ import { FontSizeSelect } from "./FontSizeSelect.js";
69
+ import { InsertImageButton } from "./InsertImageButton.js";
70
+ import { useLinearWalk } from "./keyboardWalk.js";
71
+ import { ParagraphStyleSelect } from "./ParagraphStyleSelect.js";
72
+ import { Popover } from "./Popover.js";
73
+ import { commandRunner } from "./runCommand.js";
74
+ import { SpacingMenu } from "./SpacingMenu.js";
75
+ import { TableSizePicker } from "./TableSizePicker.js";
76
+ import { ToolbarButton } from "./ToolbarButton.js";
77
+ import { hushedAttribute, useTooltipsHushed } from "./Tooltip.js";
78
+ import { ZoomSelect } from "./ZoomSelect.js";
79
+ import { jsx, jsxs } from "react/jsx-runtime";
80
+ var TEXT_TOGGLES = [
81
+ { label: "Bold", icon: Bold, command: toggleBold, active: isBoldActive },
82
+ {
83
+ label: "Italic",
84
+ icon: Italic,
85
+ command: toggleItalic,
86
+ active: isItalicActive
87
+ },
88
+ {
89
+ label: "Underline",
90
+ icon: Underline,
91
+ command: toggleUnderline,
92
+ active: isUnderlineActive
93
+ },
94
+ {
95
+ label: "Strikethrough",
96
+ icon: Strikethrough,
97
+ command: toggleStrike,
98
+ active: isStrikeActive
99
+ }
100
+ ];
101
+ var LIST_TOGGLES = [
102
+ {
103
+ label: "Numbered list",
104
+ icon: ListOrdered,
105
+ kind: "numbered",
106
+ command: toggleNumberedList
107
+ },
108
+ {
109
+ label: "Bulleted list",
110
+ icon: List,
111
+ kind: "bullet",
112
+ command: toggleBulletList
113
+ }
114
+ ];
115
+ var INDENTS = [
116
+ {
117
+ label: "Decrease indent",
118
+ icon: IndentDecrease,
119
+ command: decreaseIndent,
120
+ enabled: canDecreaseIndent
121
+ },
122
+ {
123
+ label: "Increase indent",
124
+ icon: IndentIncrease,
125
+ command: increaseIndent,
126
+ enabled: canIncreaseIndent
127
+ }
128
+ ];
129
+ function Separator() {
130
+ return /* @__PURE__ */ jsx("span", { className: editorClassNames.toolbarSeparator });
131
+ }
132
+ var TOOLBAR_CONTROLS = `.${editorClassNames.toolbarButton},.${editorClassNames.toolbarSelect}`;
133
+ function isLive(control) {
134
+ return !control.matches(":disabled");
135
+ }
136
+ function HistoryGroup({ state, run }) {
137
+ return /* @__PURE__ */ jsxs("div", { className: editorClassNames.toolbarGroup, children: [
138
+ /* @__PURE__ */ jsx(
139
+ ToolbarButton,
140
+ {
141
+ label: "Undo",
142
+ icon: Undo2,
143
+ disabled: !undo(state),
144
+ onRun: () => run(undo)
145
+ }
146
+ ),
147
+ /* @__PURE__ */ jsx(
148
+ ToolbarButton,
149
+ {
150
+ label: "Redo",
151
+ icon: Redo2,
152
+ disabled: !redo(state),
153
+ onRun: () => run(redo)
154
+ }
155
+ )
156
+ ] });
157
+ }
158
+ function TextToggleGroup({
159
+ state,
160
+ run,
161
+ disabled
162
+ }) {
163
+ return /* @__PURE__ */ jsx("div", { className: editorClassNames.toolbarGroup, children: TEXT_TOGGLES.map((toggle) => /* @__PURE__ */ jsx(
164
+ ToolbarButton,
165
+ {
166
+ label: toggle.label,
167
+ icon: toggle.icon,
168
+ pressed: toggle.active(state),
169
+ disabled,
170
+ onRun: () => run(toggle.command)
171
+ },
172
+ toggle.label
173
+ )) });
174
+ }
175
+ function ColorGroup({
176
+ state,
177
+ colors,
178
+ run,
179
+ disabled
180
+ }) {
181
+ return /* @__PURE__ */ jsxs("div", { className: editorClassNames.toolbarGroup, children: [
182
+ /* @__PURE__ */ jsx(
183
+ Popover,
184
+ {
185
+ label: "Text color",
186
+ icon: Baseline,
187
+ indicatorColor: activeTextColor(state) ?? "#000000",
188
+ panel: "dialog",
189
+ disabled,
190
+ children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
191
+ ColorPicker,
192
+ {
193
+ current: activeTextColor(state),
194
+ colors,
195
+ close,
196
+ takeFocus,
197
+ onPick: (hex) => {
198
+ run(setTextColor(hex));
199
+ close();
200
+ }
201
+ }
202
+ )
203
+ }
204
+ ),
205
+ /* @__PURE__ */ jsx(
206
+ Popover,
207
+ {
208
+ label: "Highlight",
209
+ icon: Highlighter,
210
+ indicatorColor: activeTextBackground(state) ?? "transparent",
211
+ panel: "dialog",
212
+ disabled,
213
+ children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
214
+ ColorPicker,
215
+ {
216
+ current: activeTextBackground(state),
217
+ colors,
218
+ close,
219
+ takeFocus,
220
+ onPick: (hex) => {
221
+ run(setTextBackground(hex));
222
+ close();
223
+ }
224
+ }
225
+ )
226
+ }
227
+ )
228
+ ] });
229
+ }
230
+ function ParagraphLayoutGroup({
231
+ state,
232
+ lineSpacings,
233
+ run
234
+ }) {
235
+ return /* @__PURE__ */ jsxs("div", { className: editorClassNames.toolbarGroup, children: [
236
+ /* @__PURE__ */ jsx(
237
+ Popover,
238
+ {
239
+ label: "Alignment",
240
+ icon: alignIcon(activeParagraphAlign(state)),
241
+ panel: "menu",
242
+ disabled: !canSetParagraphAlign(state),
243
+ children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
244
+ AlignMenu,
245
+ {
246
+ state,
247
+ run,
248
+ close,
249
+ takeFocus
250
+ }
251
+ )
252
+ }
253
+ ),
254
+ /* @__PURE__ */ jsx(
255
+ Popover,
256
+ {
257
+ label: "Line and paragraph spacing",
258
+ icon: ListChevronsUpDown,
259
+ panel: "menu",
260
+ disabled: !canSetLineSpacing(state),
261
+ children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
262
+ SpacingMenu,
263
+ {
264
+ state,
265
+ lineSpacings,
266
+ run,
267
+ close,
268
+ takeFocus
269
+ }
270
+ )
271
+ }
272
+ )
273
+ ] });
274
+ }
275
+ function ListGroup({ state, run }) {
276
+ const kind = activeListKind(state);
277
+ return /* @__PURE__ */ jsx("div", { className: editorClassNames.toolbarGroup, children: LIST_TOGGLES.map((toggle) => /* @__PURE__ */ jsx(
278
+ ToolbarButton,
279
+ {
280
+ label: toggle.label,
281
+ icon: toggle.icon,
282
+ pressed: kind === toggle.kind,
283
+ disabled: !toggle.command(state),
284
+ onRun: () => run(toggle.command)
285
+ },
286
+ toggle.kind
287
+ )) });
288
+ }
289
+ function IndentGroup({ state, run }) {
290
+ return /* @__PURE__ */ jsx("div", { className: editorClassNames.toolbarGroup, children: INDENTS.map((indent) => /* @__PURE__ */ jsx(
291
+ ToolbarButton,
292
+ {
293
+ label: indent.label,
294
+ icon: indent.icon,
295
+ disabled: !indent.enabled(state),
296
+ onRun: () => run(indent.command)
297
+ },
298
+ indent.label
299
+ )) });
300
+ }
301
+ function Toolbar({
302
+ view,
303
+ state,
304
+ fontFallbacks,
305
+ presets,
306
+ onToggleComments,
307
+ commentsOpen = false,
308
+ zoom,
309
+ onZoomChange
310
+ }) {
311
+ const run = commandRunner(view);
312
+ const bar = useRef(null);
313
+ const keys = useLinearWalk({
314
+ container: bar,
315
+ selector: TOOLBAR_CONTROLS,
316
+ orientation: "horizontal",
317
+ navigable: isLive
318
+ });
319
+ const hushed = useTooltipsHushed();
320
+ const doc = state.doc;
321
+ const defaults = documentDefaults(state);
322
+ const formattable = canFormatText(state);
323
+ const documentFonts = useMemo(
324
+ () => documentFontNames(doc, defaults),
325
+ [doc, defaults]
326
+ );
327
+ const onKeyDown = (event) => {
328
+ const { target } = event;
329
+ if (target instanceof HTMLElement && target.matches(TOOLBAR_CONTROLS)) {
330
+ keys.walk(event);
331
+ }
332
+ };
333
+ return /* @__PURE__ */ jsxs(
334
+ "div",
335
+ {
336
+ ref: bar,
337
+ className: editorClassNames.toolbar,
338
+ role: "toolbar",
339
+ "aria-label": "Editor toolbar",
340
+ onKeyDown,
341
+ ...hushedAttribute(hushed),
342
+ children: [
343
+ /* @__PURE__ */ jsx(HistoryGroup, { state, run }),
344
+ /* @__PURE__ */ jsx(ZoomSelect, { zoom, onZoomChange }),
345
+ /* @__PURE__ */ jsx(Separator, {}),
346
+ /* @__PURE__ */ jsxs("div", { className: editorClassNames.toolbarGroup, children: [
347
+ /* @__PURE__ */ jsx(
348
+ ParagraphStyleSelect,
349
+ {
350
+ current: activeParagraphStyle(state),
351
+ styles: documentParagraphStyles(state),
352
+ run
353
+ }
354
+ ),
355
+ /* @__PURE__ */ jsx(
356
+ FontFamilySelect,
357
+ {
358
+ current: activeFontFamily(state, fontFallbacks),
359
+ documentFonts,
360
+ fonts: presets?.fonts,
361
+ fontFallbacks,
362
+ disabled: !formattable,
363
+ run
364
+ }
365
+ ),
366
+ /* @__PURE__ */ jsx(
367
+ FontSizeSelect,
368
+ {
369
+ current: activeFontSize(state),
370
+ fontSizes: presets?.fontSizes,
371
+ disabled: !formattable,
372
+ run
373
+ }
374
+ )
375
+ ] }),
376
+ /* @__PURE__ */ jsx(Separator, {}),
377
+ /* @__PURE__ */ jsx(TextToggleGroup, { state, run, disabled: !formattable }),
378
+ /* @__PURE__ */ jsx(
379
+ ColorGroup,
380
+ {
381
+ state,
382
+ colors: presets?.colors,
383
+ run,
384
+ disabled: !formattable
385
+ }
386
+ ),
387
+ /* @__PURE__ */ jsx(Separator, {}),
388
+ /* @__PURE__ */ jsx(
389
+ ParagraphLayoutGroup,
390
+ {
391
+ state,
392
+ lineSpacings: presets?.lineSpacings,
393
+ run
394
+ }
395
+ ),
396
+ /* @__PURE__ */ jsx(Separator, {}),
397
+ /* @__PURE__ */ jsx(ListGroup, { state, run }),
398
+ /* @__PURE__ */ jsx(IndentGroup, { state, run }),
399
+ /* @__PURE__ */ jsx(Separator, {}),
400
+ /* @__PURE__ */ jsx(
401
+ CellStyleGroup,
402
+ {
403
+ state,
404
+ cellBorders: presets?.cellBorders,
405
+ colors: presets?.colors,
406
+ run
407
+ }
408
+ ),
409
+ /* @__PURE__ */ jsx(Separator, {}),
410
+ /* @__PURE__ */ jsxs("div", { className: editorClassNames.toolbarGroup, children: [
411
+ /* @__PURE__ */ jsx(
412
+ Popover,
413
+ {
414
+ label: "Insert table",
415
+ icon: Table,
416
+ panel: "dialog",
417
+ disabled: !canInsertTable(state),
418
+ children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(TableSizePicker, { run, close, takeFocus })
419
+ }
420
+ ),
421
+ /* @__PURE__ */ jsx(InsertImageButton, { view, state }),
422
+ /* @__PURE__ */ jsx(
423
+ ToolbarButton,
424
+ {
425
+ label: "Link",
426
+ icon: Link,
427
+ disabled: !openLinkPanel(state),
428
+ onRun: () => run(openLinkPanel)
429
+ }
430
+ ),
431
+ /* @__PURE__ */ jsx(
432
+ ToolbarButton,
433
+ {
434
+ label: commentsOpen ? "Hide comments" : "Show comments",
435
+ icon: MessagesSquare,
436
+ pressed: commentsOpen,
437
+ disabled: !onToggleComments,
438
+ onRun: () => onToggleComments?.()
439
+ }
440
+ )
441
+ ] })
442
+ ]
443
+ }
444
+ );
445
+ }
446
+ export {
447
+ Toolbar
448
+ };
@@ -0,0 +1,23 @@
1
+ /** A toolbar button whose pointer activation preserves the editor selection and IME state. */
2
+ import type { LucideIcon } from "lucide-react";
3
+ export declare const ICON_SIZE = 16;
4
+ /** Keyboard-generated clicks have `detail === 0`; panels use the source to decide focus. */
5
+ export type RunSource = "pointer" | "keyboard";
6
+ export interface ToolbarButtonProps {
7
+ /** Shared accessible name and tooltip text. */
8
+ label: string;
9
+ icon: LucideIcon;
10
+ pressed?: boolean;
11
+ /** Open state for disclosure buttons. */
12
+ expanded?: boolean;
13
+ popup?: "menu" | "dialog";
14
+ /** Optional color bar drawn under the icon. */
15
+ indicatorColor?: string;
16
+ disabled?: boolean;
17
+ onRun: (source: RunSource) => void;
18
+ }
19
+ /**
20
+ * `forwardRef` rather than a `ref` prop: React 18 hands a function component no `ref`
21
+ * in its props, so the button would never reach the popovers that focus it.
22
+ */
23
+ export declare const ToolbarButton: import("react").ForwardRefExoticComponent<ToolbarButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,56 @@
1
+ // src/ui/ToolbarButton.tsx
2
+ import { forwardRef } from "react";
3
+ import { editorClassNames } from "../styles/classNames.js";
4
+ import { tooltipAttribute } from "./Tooltip.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var ICON_SIZE = 16;
7
+ var ToolbarButton = forwardRef(
8
+ function ToolbarButton2({
9
+ label,
10
+ icon: Icon,
11
+ pressed,
12
+ expanded,
13
+ popup,
14
+ indicatorColor,
15
+ disabled,
16
+ onRun
17
+ }, ref) {
18
+ return /* @__PURE__ */ jsx(
19
+ "button",
20
+ {
21
+ ref,
22
+ type: "button",
23
+ className: editorClassNames.toolbarButton,
24
+ "aria-label": label,
25
+ ...tooltipAttribute(label),
26
+ "aria-pressed": pressed,
27
+ "aria-expanded": expanded,
28
+ "aria-haspopup": popup,
29
+ disabled,
30
+ onMouseDown: (event) => event.preventDefault(),
31
+ onClick: (event) => onRun(event.detail > 0 ? "pointer" : "keyboard"),
32
+ children: indicatorColor ? /* @__PURE__ */ jsxs(
33
+ "span",
34
+ {
35
+ className: editorClassNames.toolbarColorIcon,
36
+ "aria-hidden": "true",
37
+ children: [
38
+ /* @__PURE__ */ jsx(Icon, { size: ICON_SIZE }),
39
+ /* @__PURE__ */ jsx(
40
+ "span",
41
+ {
42
+ className: editorClassNames.toolbarColorIndicator,
43
+ style: { backgroundColor: indicatorColor }
44
+ }
45
+ )
46
+ ]
47
+ }
48
+ ) : /* @__PURE__ */ jsx(Icon, { size: ICON_SIZE, "aria-hidden": "true" })
49
+ }
50
+ );
51
+ }
52
+ );
53
+ export {
54
+ ICON_SIZE,
55
+ ToolbarButton
56
+ };
@@ -0,0 +1,19 @@
1
+ /** CSS-rendered tooltip shown on hover or keyboard focus. */
2
+ import { type ReactElement, type ReactNode } from "react";
3
+ /** Adds tooltip text to an element that can render its own pseudo-element. */
4
+ export declare function tooltipAttribute(label: string): {
5
+ "data-docx-editor-tooltip": string;
6
+ };
7
+ /** Hides tooltips after Escape until pointer or focus movement, as required by WCAG 1.4.13. */
8
+ export declare function useTooltipsHushed(): boolean;
9
+ export declare function hushedAttribute(hushed: boolean): {
10
+ "data-docx-editor-tooltips-off": string;
11
+ } | {
12
+ "data-docx-editor-tooltips-off"?: undefined;
13
+ };
14
+ export interface TooltipProps {
15
+ /** Text shown by the tooltip. */
16
+ label: string;
17
+ children: ReactNode;
18
+ }
19
+ export declare function Tooltip({ label, children }: TooltipProps): ReactElement;
@@ -0,0 +1,47 @@
1
+ // src/ui/Tooltip.tsx
2
+ import { useEffect, useState } from "react";
3
+ import { editorAttributes, editorClassNames } from "../styles/classNames.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function tooltipAttribute(label) {
6
+ return { [editorAttributes.tooltip]: label };
7
+ }
8
+ function useTooltipsHushed() {
9
+ const [hushed, setHushed] = useState(false);
10
+ useEffect(() => {
11
+ const onKeyDown = (event) => {
12
+ if (event.key === "Escape") setHushed(true);
13
+ };
14
+ document.addEventListener("keydown", onKeyDown, true);
15
+ return () => document.removeEventListener("keydown", onKeyDown, true);
16
+ }, []);
17
+ useEffect(() => {
18
+ if (!hushed) return;
19
+ const wake = () => setHushed(false);
20
+ document.addEventListener("pointermove", wake, true);
21
+ document.addEventListener("focusin", wake, true);
22
+ return () => {
23
+ document.removeEventListener("pointermove", wake, true);
24
+ document.removeEventListener("focusin", wake, true);
25
+ };
26
+ }, [hushed]);
27
+ return hushed;
28
+ }
29
+ function hushedAttribute(hushed) {
30
+ return hushed ? { [editorAttributes.tooltipsHushed]: "" } : {};
31
+ }
32
+ function Tooltip({ label, children }) {
33
+ return /* @__PURE__ */ jsx(
34
+ "span",
35
+ {
36
+ className: editorClassNames.tooltipWrapper,
37
+ ...tooltipAttribute(label),
38
+ children
39
+ }
40
+ );
41
+ }
42
+ export {
43
+ Tooltip,
44
+ hushedAttribute,
45
+ tooltipAttribute,
46
+ useTooltipsHushed
47
+ };
@@ -0,0 +1,7 @@
1
+ import type { ReactElement } from "react";
2
+ import { type DocxEditorZoom } from "./zoom";
3
+ export interface ZoomSelectProps {
4
+ zoom: DocxEditorZoom;
5
+ onZoomChange: (zoom: DocxEditorZoom) => void;
6
+ }
7
+ export declare function ZoomSelect({ zoom, onZoomChange, }: ZoomSelectProps): ReactElement;
@@ -0,0 +1,44 @@
1
+ // src/ui/ZoomSelect.tsx
2
+ import { editorClassNames } from "../styles/classNames.js";
3
+ import { Tooltip } from "./Tooltip.js";
4
+ import {
5
+ DEFAULT_ZOOM_LEVELS,
6
+ normalizeZoom
7
+ } from "./zoom.js";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ function optionValue(zoom) {
10
+ return zoom === "fit-width" ? zoom : String(zoom);
11
+ }
12
+ function percentage(zoom) {
13
+ return `${Math.round(zoom * 100)}%`;
14
+ }
15
+ function ZoomSelect({
16
+ zoom,
17
+ onZoomChange
18
+ }) {
19
+ const normalized = normalizeZoom(zoom);
20
+ const levels = typeof normalized === "number" && !DEFAULT_ZOOM_LEVELS.includes(
21
+ normalized
22
+ ) ? [...DEFAULT_ZOOM_LEVELS, normalized].sort((left, right) => left - right) : DEFAULT_ZOOM_LEVELS;
23
+ return /* @__PURE__ */ jsx(Tooltip, { label: "Zoom", children: /* @__PURE__ */ jsxs(
24
+ "select",
25
+ {
26
+ className: `${editorClassNames.toolbarSelect} ${editorClassNames.zoomSelect}`,
27
+ "aria-label": "Zoom",
28
+ value: optionValue(normalized),
29
+ onChange: (event) => {
30
+ const value = event.currentTarget.value;
31
+ onZoomChange(
32
+ value === "fit-width" ? value : normalizeZoom(Number(value))
33
+ );
34
+ },
35
+ children: [
36
+ /* @__PURE__ */ jsx("option", { value: "fit-width", children: "Fit" }),
37
+ levels.map((level) => /* @__PURE__ */ jsx("option", { value: level, children: percentage(level) }, level))
38
+ ]
39
+ }
40
+ ) });
41
+ }
42
+ export {
43
+ ZoomSelect
44
+ };
@@ -0,0 +1,17 @@
1
+ import { type ReactElement } from "react";
2
+ import type { CommentAuthor } from "../../editor/commands/commentCommands";
3
+ interface FocusedTextareaProps {
4
+ label: string;
5
+ value: string;
6
+ onChange: (value: string) => void;
7
+ }
8
+ export declare function FocusedTextarea({ label, value, onChange, }: FocusedTextareaProps): ReactElement;
9
+ export interface CommentComposerProps {
10
+ author: CommentAuthor;
11
+ label: string;
12
+ submitLabel: string;
13
+ onSubmit: (text: string) => boolean;
14
+ onClose: () => void;
15
+ }
16
+ export declare function CommentComposer({ author, label, submitLabel, onSubmit, onClose, }: CommentComposerProps): ReactElement;
17
+ export {};