@kopexa/tiptap 17.6.18 → 17.7.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 (428) hide show
  1. package/dist/index.d.mts +691 -24
  2. package/dist/index.d.ts +691 -24
  3. package/dist/index.js +1081 -668
  4. package/dist/index.mjs +7686 -112
  5. package/package.json +57 -52
  6. package/dist/chunk-2SI7MRAE.mjs +0 -64
  7. package/dist/chunk-2U5CQUZH.mjs +0 -91
  8. package/dist/chunk-2UDCL55K.mjs +0 -55
  9. package/dist/chunk-2V6VOAPI.mjs +0 -139
  10. package/dist/chunk-2Z2QVW67.mjs +0 -1
  11. package/dist/chunk-32SUXCAQ.mjs +0 -115
  12. package/dist/chunk-33QD5PYJ.mjs +0 -63
  13. package/dist/chunk-3VRQUYYW.mjs +0 -169
  14. package/dist/chunk-42HKGCOO.mjs +0 -129
  15. package/dist/chunk-4ALV4UA5.mjs +0 -1
  16. package/dist/chunk-4CDZ547I.mjs +0 -185
  17. package/dist/chunk-4HO7BWDC.mjs +0 -89
  18. package/dist/chunk-4JRYQZ4A.mjs +0 -174
  19. package/dist/chunk-552JLRNB.mjs +0 -35
  20. package/dist/chunk-5SMDMQDF.mjs +0 -34
  21. package/dist/chunk-6552DQWB.mjs +0 -416
  22. package/dist/chunk-7FDDRVUE.mjs +0 -143
  23. package/dist/chunk-7VGROP26.mjs +0 -262
  24. package/dist/chunk-7VW67NVL.mjs +0 -80
  25. package/dist/chunk-AAV7ZNBP.mjs +0 -83
  26. package/dist/chunk-ATRHILCH.mjs +0 -1
  27. package/dist/chunk-B7WJOQ3X.mjs +0 -103
  28. package/dist/chunk-BEV5U2DK.mjs +0 -131
  29. package/dist/chunk-BXHPO3T7.mjs +0 -152
  30. package/dist/chunk-BXJYNSWQ.mjs +0 -30
  31. package/dist/chunk-C5RQWJKE.mjs +0 -155
  32. package/dist/chunk-CNVACBGT.mjs +0 -51
  33. package/dist/chunk-DQK6PA4U.mjs +0 -276
  34. package/dist/chunk-DSBJFMHK.mjs +0 -38
  35. package/dist/chunk-DT7ML2P4.mjs +0 -42
  36. package/dist/chunk-DZLGLP7R.mjs +0 -99
  37. package/dist/chunk-EAAQE5ZV.mjs +0 -283
  38. package/dist/chunk-EHY2NAW7.mjs +0 -120
  39. package/dist/chunk-EIIWU5FR.mjs +0 -61
  40. package/dist/chunk-ERPGWXFK.mjs +0 -163
  41. package/dist/chunk-F73FCUD5.mjs +0 -1
  42. package/dist/chunk-FRJX2F4T.mjs +0 -55
  43. package/dist/chunk-GYIYX2JH.mjs +0 -73
  44. package/dist/chunk-H6LC4LDQ.mjs +0 -63
  45. package/dist/chunk-H7MS2UMO.mjs +0 -168
  46. package/dist/chunk-HLLA2HRV.mjs +0 -1
  47. package/dist/chunk-HTJ2RXOG.mjs +0 -32
  48. package/dist/chunk-IFXRPGIJ.mjs +0 -98
  49. package/dist/chunk-IOB3REX6.mjs +0 -173
  50. package/dist/chunk-IQERE7KP.mjs +0 -115
  51. package/dist/chunk-JCV5SEKN.mjs +0 -65
  52. package/dist/chunk-JVSH5T4B.mjs +0 -72
  53. package/dist/chunk-KK4K43WM.mjs +0 -59
  54. package/dist/chunk-KR42JAVB.mjs +0 -60
  55. package/dist/chunk-KYLBKQ2E.mjs +0 -203
  56. package/dist/chunk-L5RDMV3H.mjs +0 -216
  57. package/dist/chunk-LNVWG34E.mjs +0 -165
  58. package/dist/chunk-LVNUU67N.mjs +0 -1
  59. package/dist/chunk-MNTOOEHA.mjs +0 -1
  60. package/dist/chunk-N3JE67CS.mjs +0 -81
  61. package/dist/chunk-N4CT5RNC.mjs +0 -123
  62. package/dist/chunk-OEVR5N7X.mjs +0 -65
  63. package/dist/chunk-P55PLOHR.mjs +0 -34
  64. package/dist/chunk-Q5FK7SFY.mjs +0 -75
  65. package/dist/chunk-Q7DFJ5NI.mjs +0 -153
  66. package/dist/chunk-QIELBKP3.mjs +0 -104
  67. package/dist/chunk-R2GM4A3T.mjs +0 -71
  68. package/dist/chunk-REJEJXOZ.mjs +0 -10
  69. package/dist/chunk-RFWNKE7D.mjs +0 -238
  70. package/dist/chunk-TAM3VMJT.mjs +0 -80
  71. package/dist/chunk-TDFS3DCZ.mjs +0 -79
  72. package/dist/chunk-TLM5ALHZ.mjs +0 -1
  73. package/dist/chunk-TZQQ6C2Q.mjs +0 -101
  74. package/dist/chunk-U5XAL46P.mjs +0 -39
  75. package/dist/chunk-UJ4BNZ63.mjs +0 -178
  76. package/dist/chunk-UVHVCION.mjs +0 -168
  77. package/dist/chunk-V6TAZMQN.mjs +0 -105
  78. package/dist/chunk-VF3G2URZ.mjs +0 -83
  79. package/dist/chunk-VRQ6OSAZ.mjs +0 -76
  80. package/dist/chunk-VTKJPVNM.mjs +0 -148
  81. package/dist/chunk-VX3HSJ76.mjs +0 -73
  82. package/dist/chunk-W2FLOOJ6.mjs +0 -75
  83. package/dist/chunk-XGAABDMW.mjs +0 -159
  84. package/dist/chunk-Y2KSWMG5.mjs +0 -1
  85. package/dist/chunk-YJAHZXLG.mjs +0 -92
  86. package/dist/chunk-Z365KVQY.mjs +0 -34
  87. package/dist/chunk-ZVTJ6XD7.mjs +0 -88
  88. package/dist/chunk-ZZ4OU46C.mjs +0 -131
  89. package/dist/context/editor-context.d.mts +0 -10
  90. package/dist/context/editor-context.d.ts +0 -10
  91. package/dist/context/editor-context.js +0 -34
  92. package/dist/context/editor-context.mjs +0 -9
  93. package/dist/context/editor-file-context.d.mts +0 -70
  94. package/dist/context/editor-file-context.d.ts +0 -70
  95. package/dist/context/editor-file-context.js +0 -96
  96. package/dist/context/editor-file-context.mjs +0 -12
  97. package/dist/extensions/callout/callout-settings.d.mts +0 -13
  98. package/dist/extensions/callout/callout-settings.d.ts +0 -13
  99. package/dist/extensions/callout/callout-settings.js +0 -206
  100. package/dist/extensions/callout/callout-settings.mjs +0 -9
  101. package/dist/extensions/callout/callout-view.d.mts +0 -12
  102. package/dist/extensions/callout/callout-view.d.ts +0 -12
  103. package/dist/extensions/callout/callout-view.js +0 -273
  104. package/dist/extensions/callout/callout-view.mjs +0 -12
  105. package/dist/extensions/callout/index.d.mts +0 -44
  106. package/dist/extensions/callout/index.d.ts +0 -44
  107. package/dist/extensions/callout/index.js +0 -380
  108. package/dist/extensions/callout/index.mjs +0 -13
  109. package/dist/extensions/callout/messages.d.mts +0 -59
  110. package/dist/extensions/callout/messages.d.ts +0 -59
  111. package/dist/extensions/callout/messages.js +0 -88
  112. package/dist/extensions/callout/messages.mjs +0 -7
  113. package/dist/extensions/image/image-view.d.mts +0 -15
  114. package/dist/extensions/image/image-view.d.ts +0 -15
  115. package/dist/extensions/image/image-view.js +0 -255
  116. package/dist/extensions/image/image-view.mjs +0 -12
  117. package/dist/extensions/image/index.d.mts +0 -29
  118. package/dist/extensions/image/index.d.ts +0 -29
  119. package/dist/extensions/image/index.js +0 -282
  120. package/dist/extensions/image/index.mjs +0 -16
  121. package/dist/extensions/image/messages.d.mts +0 -28
  122. package/dist/extensions/image/messages.d.ts +0 -28
  123. package/dist/extensions/image/messages.js +0 -57
  124. package/dist/extensions/image/messages.mjs +0 -7
  125. package/dist/extensions/image-upload/image-upload-view.d.mts +0 -12
  126. package/dist/extensions/image-upload/image-upload-view.d.ts +0 -12
  127. package/dist/extensions/image-upload/image-upload-view.js +0 -338
  128. package/dist/extensions/image-upload/image-upload-view.mjs +0 -12
  129. package/dist/extensions/image-upload/index.d.mts +0 -46
  130. package/dist/extensions/image-upload/index.d.ts +0 -46
  131. package/dist/extensions/image-upload/index.js +0 -414
  132. package/dist/extensions/image-upload/index.mjs +0 -16
  133. package/dist/extensions/image-upload/messages.d.mts +0 -32
  134. package/dist/extensions/image-upload/messages.d.ts +0 -32
  135. package/dist/extensions/image-upload/messages.js +0 -61
  136. package/dist/extensions/image-upload/messages.mjs +0 -7
  137. package/dist/extensions/link/index.d.mts +0 -6
  138. package/dist/extensions/link/index.d.ts +0 -6
  139. package/dist/extensions/link/index.js +0 -94
  140. package/dist/extensions/link/index.mjs +0 -7
  141. package/dist/extensions/math/index.d.mts +0 -38
  142. package/dist/extensions/math/index.d.ts +0 -38
  143. package/dist/extensions/math/index.js +0 -544
  144. package/dist/extensions/math/index.mjs +0 -17
  145. package/dist/extensions/math/inline-math-view.d.mts +0 -12
  146. package/dist/extensions/math/inline-math-view.d.ts +0 -12
  147. package/dist/extensions/math/inline-math-view.js +0 -232
  148. package/dist/extensions/math/inline-math-view.mjs +0 -11
  149. package/dist/extensions/math/inline-math.d.mts +0 -32
  150. package/dist/extensions/math/inline-math.d.ts +0 -32
  151. package/dist/extensions/math/inline-math.js +0 -304
  152. package/dist/extensions/math/inline-math.mjs +0 -12
  153. package/dist/extensions/math/math-block-view.d.mts +0 -11
  154. package/dist/extensions/math/math-block-view.d.ts +0 -11
  155. package/dist/extensions/math/math-block-view.js +0 -248
  156. package/dist/extensions/math/math-block-view.mjs +0 -11
  157. package/dist/extensions/math/messages.d.mts +0 -49
  158. package/dist/extensions/math/messages.d.ts +0 -49
  159. package/dist/extensions/math/messages.js +0 -78
  160. package/dist/extensions/math/messages.mjs +0 -7
  161. package/dist/extensions/selection/index.d.mts +0 -5
  162. package/dist/extensions/selection/index.d.ts +0 -5
  163. package/dist/extensions/selection/index.js +0 -62
  164. package/dist/extensions/selection/index.mjs +0 -7
  165. package/dist/extensions/toc/index.d.mts +0 -53
  166. package/dist/extensions/toc/index.d.ts +0 -53
  167. package/dist/extensions/toc/index.js +0 -501
  168. package/dist/extensions/toc/index.mjs +0 -13
  169. package/dist/extensions/toc/messages.d.mts +0 -74
  170. package/dist/extensions/toc/messages.d.ts +0 -74
  171. package/dist/extensions/toc/messages.js +0 -103
  172. package/dist/extensions/toc/messages.mjs +0 -7
  173. package/dist/extensions/toc/toc-settings.d.mts +0 -13
  174. package/dist/extensions/toc/toc-settings.d.ts +0 -13
  175. package/dist/extensions/toc/toc-settings.js +0 -283
  176. package/dist/extensions/toc/toc-settings.mjs +0 -9
  177. package/dist/extensions/toc/toc-view.d.mts +0 -12
  178. package/dist/extensions/toc/toc-view.d.ts +0 -12
  179. package/dist/extensions/toc/toc-view.js +0 -411
  180. package/dist/extensions/toc/toc-view.mjs +0 -12
  181. package/dist/extensions/trailing-node/index.d.mts +0 -9
  182. package/dist/extensions/trailing-node/index.d.ts +0 -9
  183. package/dist/extensions/trailing-node/index.js +0 -86
  184. package/dist/extensions/trailing-node/index.mjs +0 -7
  185. package/dist/extensions/ui-state/index.d.mts +0 -34
  186. package/dist/extensions/ui-state/index.d.ts +0 -34
  187. package/dist/extensions/ui-state/index.js +0 -84
  188. package/dist/extensions/ui-state/index.mjs +0 -9
  189. package/dist/extensions/variable/extract-variables.d.mts +0 -16
  190. package/dist/extensions/variable/extract-variables.d.ts +0 -16
  191. package/dist/extensions/variable/extract-variables.js +0 -58
  192. package/dist/extensions/variable/extract-variables.mjs +0 -7
  193. package/dist/extensions/variable/index.d.mts +0 -38
  194. package/dist/extensions/variable/index.d.ts +0 -38
  195. package/dist/extensions/variable/index.js +0 -190
  196. package/dist/extensions/variable/index.mjs +0 -11
  197. package/dist/extensions/variable/messages.d.mts +0 -69
  198. package/dist/extensions/variable/messages.d.ts +0 -69
  199. package/dist/extensions/variable/messages.js +0 -98
  200. package/dist/extensions/variable/messages.mjs +0 -7
  201. package/dist/extensions/variable/variable-context.d.mts +0 -56
  202. package/dist/extensions/variable/variable-context.d.ts +0 -56
  203. package/dist/extensions/variable/variable-context.js +0 -70
  204. package/dist/extensions/variable/variable-context.mjs +0 -12
  205. package/dist/extensions/variable/variable-filler-dialog.d.mts +0 -43
  206. package/dist/extensions/variable/variable-filler-dialog.d.ts +0 -43
  207. package/dist/extensions/variable/variable-filler-dialog.js +0 -207
  208. package/dist/extensions/variable/variable-filler-dialog.mjs +0 -9
  209. package/dist/extensions/variable/variable-suggestion.d.mts +0 -31
  210. package/dist/extensions/variable/variable-suggestion.d.ts +0 -31
  211. package/dist/extensions/variable/variable-suggestion.js +0 -615
  212. package/dist/extensions/variable/variable-suggestion.mjs +0 -14
  213. package/dist/extensions/variable/variable-view.d.mts +0 -13
  214. package/dist/extensions/variable/variable-view.d.ts +0 -13
  215. package/dist/extensions/variable/variable-view.js +0 -110
  216. package/dist/extensions/variable/variable-view.mjs +0 -11
  217. package/dist/hooks/use-create-editor.d.mts +0 -46
  218. package/dist/hooks/use-create-editor.d.ts +0 -46
  219. package/dist/hooks/use-create-editor.js +0 -2726
  220. package/dist/hooks/use-create-editor.mjs +0 -37
  221. package/dist/hooks/use-cursor-visibility.d.mts +0 -37
  222. package/dist/hooks/use-cursor-visibility.d.ts +0 -37
  223. package/dist/hooks/use-cursor-visibility.js +0 -140
  224. package/dist/hooks/use-cursor-visibility.mjs +0 -8
  225. package/dist/hooks/use-floating-element.d.mts +0 -43
  226. package/dist/hooks/use-floating-element.d.ts +0 -43
  227. package/dist/hooks/use-floating-element.js +0 -88
  228. package/dist/hooks/use-floating-element.mjs +0 -8
  229. package/dist/hooks/use-floating-toolbar-visibility.d.mts +0 -32
  230. package/dist/hooks/use-floating-toolbar-visibility.d.ts +0 -32
  231. package/dist/hooks/use-floating-toolbar-visibility.js +0 -115
  232. package/dist/hooks/use-floating-toolbar-visibility.mjs +0 -13
  233. package/dist/hooks/use-menu-navigation.d.mts +0 -55
  234. package/dist/hooks/use-menu-navigation.d.ts +0 -55
  235. package/dist/hooks/use-menu-navigation.js +0 -163
  236. package/dist/hooks/use-menu-navigation.mjs +0 -8
  237. package/dist/hooks/use-tiptap-editor.d.mts +0 -20
  238. package/dist/hooks/use-tiptap-editor.d.ts +0 -20
  239. package/dist/hooks/use-tiptap-editor.js +0 -58
  240. package/dist/hooks/use-tiptap-editor.mjs +0 -8
  241. package/dist/hooks/use-ui-editor-state.d.mts +0 -7
  242. package/dist/hooks/use-ui-editor-state.d.ts +0 -7
  243. package/dist/hooks/use-ui-editor-state.js +0 -107
  244. package/dist/hooks/use-ui-editor-state.mjs +0 -11
  245. package/dist/hooks/use-window-size.d.mts +0 -12
  246. package/dist/hooks/use-window-size.d.ts +0 -12
  247. package/dist/hooks/use-window-size.js +0 -75
  248. package/dist/hooks/use-window-size.mjs +0 -7
  249. package/dist/presets/basic/editor-header.d.mts +0 -23
  250. package/dist/presets/basic/editor-header.d.ts +0 -23
  251. package/dist/presets/basic/editor-header.js +0 -2750
  252. package/dist/presets/basic/editor-header.mjs +0 -43
  253. package/dist/presets/basic/index.d.mts +0 -38
  254. package/dist/presets/basic/index.d.ts +0 -38
  255. package/dist/presets/basic/index.js +0 -6891
  256. package/dist/presets/basic/index.mjs +0 -85
  257. package/dist/ui/blockquote-button/blockquote-button.d.mts +0 -20
  258. package/dist/ui/blockquote-button/blockquote-button.d.ts +0 -20
  259. package/dist/ui/blockquote-button/blockquote-button.js +0 -247
  260. package/dist/ui/blockquote-button/blockquote-button.mjs +0 -9
  261. package/dist/ui/blockquote-button/index.d.mts +0 -6
  262. package/dist/ui/blockquote-button/index.d.ts +0 -6
  263. package/dist/ui/blockquote-button/index.js +0 -259
  264. package/dist/ui/blockquote-button/index.mjs +0 -21
  265. package/dist/ui/blockquote-button/use-blockquote.d.mts +0 -85
  266. package/dist/ui/blockquote-button/use-blockquote.d.ts +0 -85
  267. package/dist/ui/blockquote-button/use-blockquote.js +0 -192
  268. package/dist/ui/blockquote-button/use-blockquote.mjs +0 -17
  269. package/dist/ui/bubble-menu/index.d.mts +0 -13
  270. package/dist/ui/bubble-menu/index.d.ts +0 -13
  271. package/dist/ui/bubble-menu/index.js +0 -673
  272. package/dist/ui/bubble-menu/index.mjs +0 -16
  273. package/dist/ui/codeblock-button/code-block-button.d.mts +0 -20
  274. package/dist/ui/codeblock-button/code-block-button.d.ts +0 -20
  275. package/dist/ui/codeblock-button/code-block-button.js +0 -237
  276. package/dist/ui/codeblock-button/code-block-button.mjs +0 -9
  277. package/dist/ui/codeblock-button/index.d.mts +0 -6
  278. package/dist/ui/codeblock-button/index.d.ts +0 -6
  279. package/dist/ui/codeblock-button/index.js +0 -249
  280. package/dist/ui/codeblock-button/index.mjs +0 -21
  281. package/dist/ui/codeblock-button/use-code-block.d.mts +0 -92
  282. package/dist/ui/codeblock-button/use-code-block.d.ts +0 -92
  283. package/dist/ui/codeblock-button/use-code-block.js +0 -192
  284. package/dist/ui/codeblock-button/use-code-block.mjs +0 -17
  285. package/dist/ui/color-highlight-button/color-highlight-button.d.mts +0 -25
  286. package/dist/ui/color-highlight-button/color-highlight-button.d.ts +0 -25
  287. package/dist/ui/color-highlight-button/color-highlight-button.js +0 -266
  288. package/dist/ui/color-highlight-button/color-highlight-button.mjs +0 -9
  289. package/dist/ui/color-highlight-button/index.d.mts +0 -6
  290. package/dist/ui/color-highlight-button/index.d.ts +0 -6
  291. package/dist/ui/color-highlight-button/index.js +0 -342
  292. package/dist/ui/color-highlight-button/index.mjs +0 -27
  293. package/dist/ui/color-highlight-button/use-color-highlight.d.mts +0 -64
  294. package/dist/ui/color-highlight-button/use-color-highlight.d.ts +0 -64
  295. package/dist/ui/color-highlight-button/use-color-highlight.js +0 -247
  296. package/dist/ui/color-highlight-button/use-color-highlight.mjs +0 -23
  297. package/dist/ui/color-highlight-popover/color-highlight-popover.d.mts +0 -29
  298. package/dist/ui/color-highlight-popover/color-highlight-popover.d.ts +0 -29
  299. package/dist/ui/color-highlight-popover/color-highlight-popover.js +0 -590
  300. package/dist/ui/color-highlight-popover/color-highlight-popover.mjs +0 -17
  301. package/dist/ui/color-highlight-popover/index.d.mts +0 -6
  302. package/dist/ui/color-highlight-popover/index.d.ts +0 -6
  303. package/dist/ui/color-highlight-popover/index.js +0 -591
  304. package/dist/ui/color-highlight-popover/index.mjs +0 -17
  305. package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.d.mts +0 -30
  306. package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.d.ts +0 -30
  307. package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.js +0 -171
  308. package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.mjs +0 -10
  309. package/dist/ui/heading-button/index.d.mts +0 -45
  310. package/dist/ui/heading-button/index.d.ts +0 -45
  311. package/dist/ui/heading-button/index.js +0 -222
  312. package/dist/ui/heading-button/index.mjs +0 -16
  313. package/dist/ui/heading-button/utils.d.mts +0 -17
  314. package/dist/ui/heading-button/utils.d.ts +0 -17
  315. package/dist/ui/heading-button/utils.js +0 -92
  316. package/dist/ui/heading-button/utils.mjs +0 -19
  317. package/dist/ui/heading-dropdown-menu/index.d.mts +0 -14
  318. package/dist/ui/heading-dropdown-menu/index.d.ts +0 -14
  319. package/dist/ui/heading-dropdown-menu/index.js +0 -308
  320. package/dist/ui/heading-dropdown-menu/index.mjs +0 -10
  321. package/dist/ui/link-bubble/index.d.mts +0 -13
  322. package/dist/ui/link-bubble/index.d.ts +0 -13
  323. package/dist/ui/link-bubble/index.js +0 -183
  324. package/dist/ui/link-bubble/index.mjs +0 -10
  325. package/dist/ui/link-popover/index.d.mts +0 -7
  326. package/dist/ui/link-popover/index.d.ts +0 -7
  327. package/dist/ui/link-popover/index.js +0 -512
  328. package/dist/ui/link-popover/index.mjs +0 -30
  329. package/dist/ui/link-popover/link-popover.d.mts +0 -85
  330. package/dist/ui/link-popover/link-popover.d.ts +0 -85
  331. package/dist/ui/link-popover/link-popover.js +0 -498
  332. package/dist/ui/link-popover/link-popover.mjs +0 -16
  333. package/dist/ui/link-popover/use-link-popover.d.mts +0 -123
  334. package/dist/ui/link-popover/use-link-popover.d.ts +0 -123
  335. package/dist/ui/link-popover/use-link-popover.js +0 -259
  336. package/dist/ui/link-popover/use-link-popover.mjs +0 -20
  337. package/dist/ui/list-button/index.d.mts +0 -50
  338. package/dist/ui/list-button/index.d.ts +0 -50
  339. package/dist/ui/list-button/index.js +0 -232
  340. package/dist/ui/list-button/index.mjs +0 -24
  341. package/dist/ui/list-dropdown-menu/index.d.mts +0 -45
  342. package/dist/ui/list-dropdown-menu/index.d.ts +0 -45
  343. package/dist/ui/list-dropdown-menu/index.js +0 -361
  344. package/dist/ui/list-dropdown-menu/index.mjs +0 -21
  345. package/dist/ui/mark-button/index.d.mts +0 -59
  346. package/dist/ui/mark-button/index.d.ts +0 -59
  347. package/dist/ui/mark-button/index.js +0 -217
  348. package/dist/ui/mark-button/index.mjs +0 -26
  349. package/dist/ui/reset-all-formatting-button/index.d.mts +0 -7
  350. package/dist/ui/reset-all-formatting-button/index.d.ts +0 -7
  351. package/dist/ui/reset-all-formatting-button/index.js +0 -286
  352. package/dist/ui/reset-all-formatting-button/index.mjs +0 -26
  353. package/dist/ui/reset-all-formatting-button/reset-all-formatting-button.d.mts +0 -30
  354. package/dist/ui/reset-all-formatting-button/reset-all-formatting-button.d.ts +0 -30
  355. package/dist/ui/reset-all-formatting-button/reset-all-formatting-button.js +0 -271
  356. package/dist/ui/reset-all-formatting-button/reset-all-formatting-button.mjs +0 -12
  357. package/dist/ui/reset-all-formatting-button/use-reset-all-formatting.d.mts +0 -103
  358. package/dist/ui/reset-all-formatting-button/use-reset-all-formatting.d.ts +0 -103
  359. package/dist/ui/reset-all-formatting-button/use-reset-all-formatting.js +0 -211
  360. package/dist/ui/reset-all-formatting-button/use-reset-all-formatting.mjs +0 -21
  361. package/dist/ui/slash-dropdown-menu/index.d.mts +0 -10
  362. package/dist/ui/slash-dropdown-menu/index.d.ts +0 -10
  363. package/dist/ui/slash-dropdown-menu/index.js +0 -1056
  364. package/dist/ui/slash-dropdown-menu/index.mjs +0 -19
  365. package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.d.mts +0 -16
  366. package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.d.ts +0 -16
  367. package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.js +0 -1053
  368. package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.mjs +0 -16
  369. package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.d.mts +0 -162
  370. package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.d.ts +0 -162
  371. package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.js +0 -457
  372. package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.mjs +0 -10
  373. package/dist/ui/suggestion-menu/index.d.mts +0 -10
  374. package/dist/ui/suggestion-menu/index.d.ts +0 -10
  375. package/dist/ui/suggestion-menu/index.js +0 -489
  376. package/dist/ui/suggestion-menu/index.mjs +0 -17
  377. package/dist/ui/suggestion-menu/suggestion-menu-types.d.mts +0 -89
  378. package/dist/ui/suggestion-menu/suggestion-menu-types.d.ts +0 -89
  379. package/dist/ui/suggestion-menu/suggestion-menu-types.js +0 -19
  380. package/dist/ui/suggestion-menu/suggestion-menu-types.mjs +0 -1
  381. package/dist/ui/suggestion-menu/suggestion-menu-utils.d.mts +0 -27
  382. package/dist/ui/suggestion-menu/suggestion-menu-utils.d.ts +0 -27
  383. package/dist/ui/suggestion-menu/suggestion-menu-utils.js +0 -75
  384. package/dist/ui/suggestion-menu/suggestion-menu-utils.mjs +0 -9
  385. package/dist/ui/suggestion-menu/suggestion-menu.d.mts +0 -15
  386. package/dist/ui/suggestion-menu/suggestion-menu.d.ts +0 -15
  387. package/dist/ui/suggestion-menu/suggestion-menu.js +0 -453
  388. package/dist/ui/suggestion-menu/suggestion-menu.mjs +0 -12
  389. package/dist/ui/table-button/index.d.mts +0 -15
  390. package/dist/ui/table-button/index.d.ts +0 -15
  391. package/dist/ui/table-button/index.js +0 -202
  392. package/dist/ui/table-button/index.mjs +0 -9
  393. package/dist/ui/table-button/use-table.d.mts +0 -51
  394. package/dist/ui/table-button/use-table.d.ts +0 -51
  395. package/dist/ui/table-button/use-table.js +0 -146
  396. package/dist/ui/table-button/use-table.mjs +0 -14
  397. package/dist/ui/text-align-button/index.d.mts +0 -6
  398. package/dist/ui/text-align-button/index.d.ts +0 -6
  399. package/dist/ui/text-align-button/index.js +0 -235
  400. package/dist/ui/text-align-button/index.mjs +0 -29
  401. package/dist/ui/text-align-button/text-align-button.d.mts +0 -20
  402. package/dist/ui/text-align-button/text-align-button.d.ts +0 -20
  403. package/dist/ui/text-align-button/text-align-button.js +0 -215
  404. package/dist/ui/text-align-button/text-align-button.mjs +0 -9
  405. package/dist/ui/text-align-button/use-text-align.d.mts +0 -106
  406. package/dist/ui/text-align-button/use-text-align.d.ts +0 -106
  407. package/dist/ui/text-align-button/use-text-align.js +0 -169
  408. package/dist/ui/text-align-button/use-text-align.mjs +0 -24
  409. package/dist/ui/undo-redo-button/index.d.mts +0 -6
  410. package/dist/ui/undo-redo-button/index.d.ts +0 -6
  411. package/dist/ui/undo-redo-button/index.js +0 -202
  412. package/dist/ui/undo-redo-button/index.mjs +0 -25
  413. package/dist/ui/undo-redo-button/undo-redo-button.d.mts +0 -23
  414. package/dist/ui/undo-redo-button/undo-redo-button.d.ts +0 -23
  415. package/dist/ui/undo-redo-button/undo-redo-button.js +0 -187
  416. package/dist/ui/undo-redo-button/undo-redo-button.mjs +0 -10
  417. package/dist/ui/undo-redo-button/use-undo-redo.d.mts +0 -95
  418. package/dist/ui/undo-redo-button/use-undo-redo.d.ts +0 -95
  419. package/dist/ui/undo-redo-button/use-undo-redo.js +0 -146
  420. package/dist/ui/undo-redo-button/use-undo-redo.mjs +0 -21
  421. package/dist/utils/index.d.mts +0 -38
  422. package/dist/utils/index.d.ts +0 -38
  423. package/dist/utils/index.js +0 -128
  424. package/dist/utils/index.mjs +0 -15
  425. package/dist/utils/safe-parse.d.mts +0 -14
  426. package/dist/utils/safe-parse.d.ts +0 -14
  427. package/dist/utils/safe-parse.js +0 -203
  428. package/dist/utils/safe-parse.mjs +0 -8
@@ -1,2750 +0,0 @@
1
- "use client";
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/presets/basic/editor-header.tsx
32
- var editor_header_exports = {};
33
- __export(editor_header_exports, {
34
- EditorHeader: () => EditorHeader,
35
- MoreOptions: () => MoreOptions
36
- });
37
- module.exports = __toCommonJS(editor_header_exports);
38
- var import_icons16 = require("@kopexa/icons");
39
- var import_popover3 = require("@kopexa/popover");
40
- var import_toolbar9 = require("@kopexa/toolbar");
41
- var import_use_is_mobile2 = require("@kopexa/use-is-mobile");
42
- var import_react22 = require("react");
43
-
44
- // src/context/editor-context.ts
45
- var import_react_utils = require("@kopexa/react-utils");
46
- var [EditorUIProvider, useEditorUIContext] = (0, import_react_utils.createContext)();
47
-
48
- // src/hooks/use-cursor-visibility.ts
49
- var React2 = __toESM(require("react"));
50
-
51
- // src/hooks/use-window-size.ts
52
- var React = __toESM(require("react"));
53
- function useWindowSize() {
54
- const [windowSize, setWindowSize] = React.useState({
55
- width: 0,
56
- height: 0,
57
- offsetTop: 0
58
- });
59
- React.useEffect(() => {
60
- handleResize();
61
- function handleResize() {
62
- if (typeof window === "undefined") return;
63
- const vp = window.visualViewport;
64
- if (!vp) return;
65
- const { width = 0, height = 0, offsetTop = 0 } = vp;
66
- setWindowSize((state) => {
67
- if (width === state.width && height === state.height && offsetTop === state.offsetTop) {
68
- return state;
69
- }
70
- return { width, height, offsetTop };
71
- });
72
- }
73
- const visualViewport = window.visualViewport;
74
- if (visualViewport) {
75
- visualViewport.addEventListener("resize", handleResize);
76
- visualViewport.addEventListener("scroll", handleResize);
77
- }
78
- return () => {
79
- if (visualViewport) {
80
- visualViewport.removeEventListener("resize", handleResize);
81
- visualViewport.removeEventListener("scroll", handleResize);
82
- }
83
- };
84
- }, []);
85
- return windowSize;
86
- }
87
-
88
- // src/hooks/use-cursor-visibility.ts
89
- function useCursorVisibility({
90
- editor,
91
- overlayHeight = 0,
92
- elementRef = null
93
- }) {
94
- const { height: windowHeight } = useWindowSize();
95
- const [rect, setRect] = React2.useState({
96
- x: 0,
97
- y: 0,
98
- width: 0,
99
- height: 0
100
- });
101
- const updateRect = React2.useCallback(() => {
102
- var _a;
103
- const element = (_a = elementRef == null ? void 0 : elementRef.current) != null ? _a : document.body;
104
- const { x, y, width, height } = element.getBoundingClientRect();
105
- setRect({ x, y, width, height });
106
- }, [elementRef]);
107
- React2.useEffect(() => {
108
- var _a;
109
- const element = (_a = elementRef == null ? void 0 : elementRef.current) != null ? _a : document.body;
110
- updateRect();
111
- const resizeObserver = new ResizeObserver(() => {
112
- window.requestAnimationFrame(updateRect);
113
- });
114
- resizeObserver.observe(element);
115
- window.addEventListener("scroll", updateRect, { passive: true });
116
- return () => {
117
- resizeObserver.disconnect();
118
- window.removeEventListener("scroll", updateRect);
119
- };
120
- }, [elementRef, updateRect]);
121
- React2.useEffect(() => {
122
- const ensureCursorVisibility = () => {
123
- if (!editor) return;
124
- const { state, view } = editor;
125
- if (!view.hasFocus()) return;
126
- const { from } = state.selection;
127
- const cursorCoords = view.coordsAtPos(from);
128
- if (windowHeight < rect.height) {
129
- if (cursorCoords) {
130
- const availableSpace = windowHeight - cursorCoords.top - overlayHeight > 0;
131
- if (!availableSpace) {
132
- const targetScrollY = (
133
- // TODO: Needed?
134
- // window.scrollY + (cursorCoords.top - windowHeight / 2)
135
- cursorCoords.top - windowHeight / 2
136
- );
137
- window.scrollTo({
138
- top: targetScrollY,
139
- behavior: "smooth"
140
- });
141
- }
142
- }
143
- }
144
- };
145
- ensureCursorVisibility();
146
- }, [editor, overlayHeight, windowHeight, rect.height]);
147
- return rect;
148
- }
149
-
150
- // src/hooks/use-tiptap-editor.ts
151
- var import_react = require("@tiptap/react");
152
- var import_react2 = require("react");
153
- function useTiptapEditor(providedEditor) {
154
- const { editor: coreEditor } = (0, import_react.useCurrentEditor)();
155
- const mainEditor = (0, import_react2.useMemo)(
156
- () => providedEditor || coreEditor,
157
- [providedEditor, coreEditor]
158
- );
159
- const editorState = (0, import_react.useEditorState)({
160
- editor: mainEditor,
161
- selector(context) {
162
- if (!context.editor) {
163
- return {
164
- editor: null,
165
- editorState: void 0,
166
- canCommand: void 0
167
- };
168
- }
169
- return {
170
- editor: context.editor,
171
- editorState: context.editor.state,
172
- canCommand: context.editor.can
173
- };
174
- }
175
- });
176
- return editorState || { editor: null };
177
- }
178
-
179
- // src/ui/blockquote-button/blockquote-button.tsx
180
- var import_toolbar = require("@kopexa/toolbar");
181
- var React4 = __toESM(require("react"));
182
-
183
- // src/ui/blockquote-button/use-blockquote.ts
184
- var import_editor_utils = require("@kopexa/editor-utils");
185
- var import_icons = require("@kopexa/icons");
186
- var import_state = require("@tiptap/pm/state");
187
- var React3 = __toESM(require("react"));
188
- var BLOCKQUOTE_SHORTCUT_KEY = "mod+shift+b";
189
- function canToggleBlockquote(editor, turnInto = true) {
190
- var _a;
191
- if (!editor || !editor.isEditable) return false;
192
- if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor) || (0, import_editor_utils.isNodeTypeSelected)(editor, ["image"]))
193
- return false;
194
- if (!turnInto) {
195
- return editor.can().toggleWrap("blockquote");
196
- }
197
- try {
198
- const view = editor.view;
199
- const state = view.state;
200
- const selection = state.selection;
201
- if (selection.empty || selection instanceof import_state.TextSelection) {
202
- const pos = (_a = (0, import_editor_utils.findNodePosition)({
203
- editor,
204
- node: state.selection.$anchor.node(1)
205
- })) == null ? void 0 : _a.pos;
206
- if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
207
- }
208
- return true;
209
- } catch {
210
- return false;
211
- }
212
- }
213
- function toggleBlockquote(editor) {
214
- var _a, _b, _c;
215
- if (!editor || !editor.isEditable) return false;
216
- if (!canToggleBlockquote(editor)) return false;
217
- try {
218
- const view = editor.view;
219
- let state = view.state;
220
- let tr = state.tr;
221
- if (state.selection.empty || state.selection instanceof import_state.TextSelection) {
222
- const pos = (_a = (0, import_editor_utils.findNodePosition)({
223
- editor,
224
- node: state.selection.$anchor.node(1)
225
- })) == null ? void 0 : _a.pos;
226
- if (!(0, import_editor_utils.isValidPosition)(pos)) return false;
227
- tr = tr.setSelection(import_state.NodeSelection.create(state.doc, pos));
228
- view.dispatch(tr);
229
- state = view.state;
230
- }
231
- const selection = state.selection;
232
- let chain = editor.chain().focus();
233
- if (selection instanceof import_state.NodeSelection) {
234
- const firstChild = (_b = selection.node.firstChild) == null ? void 0 : _b.firstChild;
235
- const lastChild = (_c = selection.node.lastChild) == null ? void 0 : _c.lastChild;
236
- const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
237
- const to = lastChild ? selection.to - lastChild.nodeSize : selection.to - 1;
238
- chain = chain.setTextSelection({ from, to }).clearNodes();
239
- }
240
- const toggle = editor.isActive("blockquote") ? chain.lift("blockquote") : chain.wrapIn("blockquote");
241
- toggle.run();
242
- editor.chain().focus().selectTextblockEnd().run();
243
- return true;
244
- } catch {
245
- return false;
246
- }
247
- }
248
- function shouldShowButton(props) {
249
- const { editor, hideWhenUnavailable } = props;
250
- if (!editor || !editor.isEditable) return false;
251
- if (!(0, import_editor_utils.isNodeInSchema)("blockquote", editor)) return false;
252
- if (hideWhenUnavailable && !editor.isActive("code")) {
253
- return canToggleBlockquote(editor);
254
- }
255
- return true;
256
- }
257
- function useBlockquote(config) {
258
- const {
259
- editor: providedEditor,
260
- hideWhenUnavailable = false,
261
- onToggled
262
- } = config || {};
263
- const { editor } = useTiptapEditor(providedEditor);
264
- const [isVisible, setIsVisible] = React3.useState(true);
265
- const canToggle3 = canToggleBlockquote(editor);
266
- const isActive = (editor == null ? void 0 : editor.isActive("blockquote")) || false;
267
- React3.useEffect(() => {
268
- if (!editor) return;
269
- const handleSelectionUpdate = () => {
270
- setIsVisible(shouldShowButton({ editor, hideWhenUnavailable }));
271
- };
272
- handleSelectionUpdate();
273
- editor.on("selectionUpdate", handleSelectionUpdate);
274
- return () => {
275
- editor.off("selectionUpdate", handleSelectionUpdate);
276
- };
277
- }, [editor, hideWhenUnavailable]);
278
- const handleToggle = React3.useCallback(() => {
279
- if (!editor) return false;
280
- const success = toggleBlockquote(editor);
281
- if (success) {
282
- onToggled == null ? void 0 : onToggled();
283
- }
284
- return success;
285
- }, [editor, onToggled]);
286
- return {
287
- isVisible,
288
- isActive,
289
- handleToggle,
290
- canToggle: canToggle3,
291
- label: "Blockquote",
292
- shortcutKeys: BLOCKQUOTE_SHORTCUT_KEY,
293
- Icon: import_icons.BlockquoteIcon
294
- };
295
- }
296
-
297
- // src/ui/blockquote-button/blockquote-button.tsx
298
- var import_jsx_runtime = require("react/jsx-runtime");
299
- var BlockquoteButton = ({
300
- editor: providedEditor,
301
- text,
302
- hideWhenUnavailable = false,
303
- onToggled,
304
- showShortcut = false,
305
- onClick,
306
- children,
307
- ...buttonProps
308
- }) => {
309
- const { editor } = useTiptapEditor(providedEditor);
310
- const {
311
- isVisible,
312
- canToggle: canToggle3,
313
- isActive,
314
- handleToggle,
315
- label,
316
- shortcutKeys,
317
- Icon
318
- } = useBlockquote({
319
- editor,
320
- hideWhenUnavailable,
321
- onToggled
322
- });
323
- const handleClick = React4.useCallback(
324
- (event) => {
325
- onClick == null ? void 0 : onClick(event);
326
- if (event.defaultPrevented) return;
327
- handleToggle();
328
- },
329
- [handleToggle, onClick]
330
- );
331
- if (!isVisible) {
332
- return null;
333
- }
334
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
335
- import_toolbar.ToolbarButton,
336
- {
337
- type: "button",
338
- variant: "ghost",
339
- color: "default",
340
- disabled: !canToggle3,
341
- "data-disabled": !canToggle3,
342
- "data-active-state": isActive ? "on" : "off",
343
- tabIndex: -1,
344
- "aria-label": "blockquote",
345
- "aria-pressed": isActive,
346
- title: label,
347
- shortcutKeys,
348
- onClick: handleClick,
349
- isIconOnly: !text && !children,
350
- ...buttonProps,
351
- children: children != null ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
352
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {}),
353
- text && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: text })
354
- ] })
355
- }
356
- );
357
- };
358
-
359
- // src/ui/codeblock-button/code-block-button.tsx
360
- var import_icons3 = require("@kopexa/icons");
361
- var import_toolbar2 = require("@kopexa/toolbar");
362
- var import_react3 = require("react");
363
-
364
- // src/ui/codeblock-button/use-code-block.ts
365
- var import_editor_utils2 = require("@kopexa/editor-utils");
366
- var import_icons2 = require("@kopexa/icons");
367
- var import_state2 = require("@tiptap/pm/state");
368
- var React5 = __toESM(require("react"));
369
- var CODE_BLOCK_SHORTCUT_KEY = "mod+alt+c";
370
- function canToggle(editor, turnInto = true) {
371
- var _a;
372
- if (!editor || !editor.isEditable) return false;
373
- if (!(0, import_editor_utils2.isNodeInSchema)("codeBlock", editor) || (0, import_editor_utils2.isNodeTypeSelected)(editor, ["image"]))
374
- return false;
375
- if (!turnInto) {
376
- return editor.can().toggleNode("codeBlock", "paragraph");
377
- }
378
- try {
379
- const view = editor.view;
380
- const state = view.state;
381
- const selection = state.selection;
382
- if (selection.empty || selection instanceof import_state2.TextSelection) {
383
- const pos = (_a = (0, import_editor_utils2.findNodePosition)({
384
- editor,
385
- node: state.selection.$anchor.node(1)
386
- })) == null ? void 0 : _a.pos;
387
- if (!(0, import_editor_utils2.isValidPosition)(pos)) return false;
388
- }
389
- return true;
390
- } catch {
391
- return false;
392
- }
393
- }
394
- function toggleCodeBlock(editor) {
395
- var _a, _b, _c;
396
- if (!editor || !editor.isEditable) return false;
397
- if (!canToggle(editor)) return false;
398
- try {
399
- const view = editor.view;
400
- let state = view.state;
401
- let tr = state.tr;
402
- if (state.selection.empty || state.selection instanceof import_state2.TextSelection) {
403
- const pos = (_a = (0, import_editor_utils2.findNodePosition)({
404
- editor,
405
- node: state.selection.$anchor.node(1)
406
- })) == null ? void 0 : _a.pos;
407
- if (!(0, import_editor_utils2.isValidPosition)(pos)) return false;
408
- tr = tr.setSelection(import_state2.NodeSelection.create(state.doc, pos));
409
- view.dispatch(tr);
410
- state = view.state;
411
- }
412
- const selection = state.selection;
413
- let chain = editor.chain().focus();
414
- if (selection instanceof import_state2.NodeSelection) {
415
- const firstChild = (_b = selection.node.firstChild) == null ? void 0 : _b.firstChild;
416
- const lastChild = (_c = selection.node.lastChild) == null ? void 0 : _c.lastChild;
417
- const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
418
- const to = lastChild ? selection.to - lastChild.nodeSize : selection.to - 1;
419
- chain = chain.setTextSelection({ from, to }).clearNodes();
420
- }
421
- const toggle = editor.isActive("codeBlock") ? chain.setNode("paragraph") : chain.toggleNode("codeBlock", "paragraph");
422
- toggle.run();
423
- editor.chain().focus().selectTextblockEnd().run();
424
- return true;
425
- } catch {
426
- return false;
427
- }
428
- }
429
- function shouldShowButton2(props) {
430
- const { editor, hideWhenUnavailable } = props;
431
- if (!editor || !editor.isEditable) return false;
432
- if (!(0, import_editor_utils2.isNodeInSchema)("codeBlock", editor)) return false;
433
- if (hideWhenUnavailable && !editor.isActive("code")) {
434
- return canToggle(editor);
435
- }
436
- return true;
437
- }
438
- function useCodeBlock(config) {
439
- const {
440
- editor: providedEditor,
441
- hideWhenUnavailable = false,
442
- onToggled
443
- } = config || {};
444
- const { editor } = useTiptapEditor(providedEditor);
445
- const [isVisible, setIsVisible] = React5.useState(true);
446
- const canToggleState = canToggle(editor);
447
- const isActive = (editor == null ? void 0 : editor.isActive("codeBlock")) || false;
448
- React5.useEffect(() => {
449
- if (!editor) return;
450
- const handleSelectionUpdate = () => {
451
- setIsVisible(shouldShowButton2({ editor, hideWhenUnavailable }));
452
- };
453
- handleSelectionUpdate();
454
- editor.on("selectionUpdate", handleSelectionUpdate);
455
- return () => {
456
- editor.off("selectionUpdate", handleSelectionUpdate);
457
- };
458
- }, [editor, hideWhenUnavailable]);
459
- const handleToggle = React5.useCallback(() => {
460
- if (!editor) return false;
461
- const success = toggleCodeBlock(editor);
462
- if (success) {
463
- onToggled == null ? void 0 : onToggled();
464
- }
465
- return success;
466
- }, [editor, onToggled]);
467
- return {
468
- isVisible,
469
- isActive,
470
- handleToggle,
471
- canToggle: canToggleState,
472
- label: "Code Block",
473
- shortcutKeys: CODE_BLOCK_SHORTCUT_KEY,
474
- Icon: import_icons2.CodeblockIcon
475
- };
476
- }
477
-
478
- // src/ui/codeblock-button/code-block-button.tsx
479
- var import_jsx_runtime2 = require("react/jsx-runtime");
480
- var CodeBlockButton = ({
481
- editor: providedEditor,
482
- text,
483
- hideWhenUnavailable = false,
484
- onToggled,
485
- showShortcut = false,
486
- onClick,
487
- children,
488
- ...buttonProps
489
- }) => {
490
- const { editor } = useTiptapEditor(providedEditor);
491
- const { isVisible, canToggle: canToggle3, isActive, handleToggle, label, shortcutKeys } = useCodeBlock({
492
- editor,
493
- hideWhenUnavailable,
494
- onToggled
495
- });
496
- const handleClick = (0, import_react3.useCallback)(
497
- (event) => {
498
- onClick == null ? void 0 : onClick(event);
499
- if (event.defaultPrevented) return;
500
- handleToggle();
501
- },
502
- [handleToggle, onClick]
503
- );
504
- if (!isVisible) {
505
- return null;
506
- }
507
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
508
- import_toolbar2.ToolbarButton,
509
- {
510
- type: "button",
511
- variant: "ghost",
512
- color: "default",
513
- disabled: !canToggle3,
514
- "data-disabled": !canToggle3,
515
- "data-active-state": isActive ? "on" : "off",
516
- tabIndex: -1,
517
- "aria-label": "codeBlock",
518
- "aria-pressed": isActive,
519
- title: label,
520
- shortcutKeys,
521
- onClick: handleClick,
522
- isIconOnly: true,
523
- ...buttonProps,
524
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons3.CodeblockIcon, {})
525
- }
526
- );
527
- };
528
-
529
- // src/ui/color-highlight-popover/color-highlight-popover.tsx
530
- var import_button = require("@kopexa/button");
531
- var import_icons5 = require("@kopexa/icons");
532
- var import_popover = require("@kopexa/popover");
533
- var import_toolbar4 = require("@kopexa/toolbar");
534
- var import_react5 = require("react");
535
-
536
- // src/hooks/use-menu-navigation.ts
537
- var React6 = __toESM(require("react"));
538
- function useMenuNavigation({
539
- editor,
540
- containerRef,
541
- query,
542
- items,
543
- onSelect,
544
- onClose,
545
- orientation = "vertical",
546
- autoSelectFirstItem = true
547
- }) {
548
- const [selectedIndex, setSelectedIndex] = React6.useState(
549
- autoSelectFirstItem ? 0 : -1
550
- );
551
- React6.useEffect(() => {
552
- const handleKeyboardNavigation = (event) => {
553
- if (!items.length) return false;
554
- const moveNext = () => setSelectedIndex((currentIndex) => {
555
- if (currentIndex === -1) return 0;
556
- return (currentIndex + 1) % items.length;
557
- });
558
- const movePrev = () => setSelectedIndex((currentIndex) => {
559
- if (currentIndex === -1) return items.length - 1;
560
- return (currentIndex - 1 + items.length) % items.length;
561
- });
562
- switch (event.key) {
563
- case "ArrowUp": {
564
- if (orientation === "horizontal") return false;
565
- event.preventDefault();
566
- movePrev();
567
- return true;
568
- }
569
- case "ArrowDown": {
570
- if (orientation === "horizontal") return false;
571
- event.preventDefault();
572
- moveNext();
573
- return true;
574
- }
575
- case "ArrowLeft": {
576
- if (orientation === "vertical") return false;
577
- event.preventDefault();
578
- movePrev();
579
- return true;
580
- }
581
- case "ArrowRight": {
582
- if (orientation === "vertical") return false;
583
- event.preventDefault();
584
- moveNext();
585
- return true;
586
- }
587
- case "Tab": {
588
- event.preventDefault();
589
- if (event.shiftKey) {
590
- movePrev();
591
- } else {
592
- moveNext();
593
- }
594
- return true;
595
- }
596
- case "Home": {
597
- event.preventDefault();
598
- setSelectedIndex(0);
599
- return true;
600
- }
601
- case "End": {
602
- event.preventDefault();
603
- setSelectedIndex(items.length - 1);
604
- return true;
605
- }
606
- case "Enter": {
607
- if (event.isComposing) return false;
608
- event.preventDefault();
609
- if (selectedIndex !== -1 && items[selectedIndex]) {
610
- onSelect == null ? void 0 : onSelect(items[selectedIndex]);
611
- }
612
- return true;
613
- }
614
- case "Escape": {
615
- event.preventDefault();
616
- onClose == null ? void 0 : onClose();
617
- return true;
618
- }
619
- default:
620
- return false;
621
- }
622
- };
623
- let targetElement = null;
624
- if (editor) {
625
- targetElement = editor.view.dom;
626
- } else if (containerRef == null ? void 0 : containerRef.current) {
627
- targetElement = containerRef.current;
628
- }
629
- if (targetElement) {
630
- targetElement.addEventListener("keydown", handleKeyboardNavigation, true);
631
- return () => {
632
- targetElement == null ? void 0 : targetElement.removeEventListener(
633
- "keydown",
634
- handleKeyboardNavigation,
635
- true
636
- );
637
- };
638
- }
639
- return void 0;
640
- }, [
641
- editor,
642
- containerRef,
643
- items,
644
- selectedIndex,
645
- onSelect,
646
- onClose,
647
- orientation
648
- ]);
649
- React6.useEffect(() => {
650
- if (query) {
651
- setSelectedIndex(autoSelectFirstItem ? 0 : -1);
652
- }
653
- }, [query, autoSelectFirstItem]);
654
- return {
655
- selectedIndex: items.length ? selectedIndex : void 0,
656
- setSelectedIndex
657
- };
658
- }
659
-
660
- // src/ui/color-highlight-button/color-highlight-button.tsx
661
- var import_theme = require("@kopexa/theme");
662
- var import_toolbar3 = require("@kopexa/toolbar");
663
- var import_react4 = require("react");
664
-
665
- // src/ui/color-highlight-button/use-color-highlight.ts
666
- var import_editor_utils3 = require("@kopexa/editor-utils");
667
- var import_icons4 = require("@kopexa/icons");
668
- var import_use_is_mobile = require("@kopexa/use-is-mobile");
669
- var React7 = __toESM(require("react"));
670
- var import_react_hotkeys_hook = require("react-hotkeys-hook");
671
- var COLOR_HIGHLIGHT_SHORTCUT_KEY = "mod+shift+h";
672
- var HIGHLIGHT_COLORS = [
673
- {
674
- label: "Default background",
675
- value: "var(--tt-bg-color)",
676
- border: "var(--tt-bg-color-contrast)"
677
- },
678
- {
679
- label: "Gray background",
680
- value: "var(--tt-color-highlight-gray)",
681
- border: "var(--tt-color-highlight-gray-contrast)"
682
- },
683
- {
684
- label: "Brown background",
685
- value: "var(--tt-color-highlight-brown)",
686
- border: "var(--tt-color-highlight-brown-contrast)"
687
- },
688
- {
689
- label: "Orange background",
690
- value: "var(--tt-color-highlight-orange)",
691
- border: "var(--tt-color-highlight-orange-contrast)"
692
- },
693
- {
694
- label: "Yellow background",
695
- value: "var(--tt-color-highlight-yellow)",
696
- border: "var(--tt-color-highlight-yellow-contrast)"
697
- },
698
- {
699
- label: "Green background",
700
- value: "var(--tt-color-highlight-green)",
701
- border: "var(--tt-color-highlight-green-contrast)"
702
- },
703
- {
704
- label: "Blue background",
705
- value: "var(--tt-color-highlight-blue)",
706
- border: "var(--tt-color-highlight-blue-contrast)"
707
- },
708
- {
709
- label: "Purple background",
710
- value: "var(--tt-color-highlight-purple)",
711
- border: "var(--tt-color-highlight-purple-contrast)"
712
- },
713
- {
714
- label: "Pink background",
715
- value: "var(--tt-color-highlight-pink)",
716
- border: "var(--tt-color-highlight-pink-contrast)"
717
- },
718
- {
719
- label: "Red background",
720
- value: "var(--tt-color-highlight-red)",
721
- border: "var(--tt-color-highlight-red-contrast)"
722
- }
723
- ];
724
- function pickHighlightColorsByValue(values) {
725
- const colorMap = new Map(
726
- HIGHLIGHT_COLORS.map((color) => [color.value, color])
727
- );
728
- return values.map((value) => colorMap.get(value)).filter((color) => !!color);
729
- }
730
- function canColorHighlight(editor) {
731
- if (!editor || !editor.isEditable) return false;
732
- if (!(0, import_editor_utils3.isMarkInSchema)("highlight", editor) || (0, import_editor_utils3.isNodeTypeSelected)(editor, ["image"]))
733
- return false;
734
- return editor.can().setMark("highlight");
735
- }
736
- function isColorHighlightActive(editor, highlightColor) {
737
- if (!editor || !editor.isEditable) return false;
738
- return highlightColor ? editor.isActive("highlight", { color: highlightColor }) : editor.isActive("highlight");
739
- }
740
- function removeHighlight(editor) {
741
- if (!editor || !editor.isEditable) return false;
742
- if (!canColorHighlight(editor)) return false;
743
- return editor.chain().focus().unsetMark("highlight").run();
744
- }
745
- function shouldShowButton3(props) {
746
- const { editor, hideWhenUnavailable } = props;
747
- if (!editor || !editor.isEditable) return false;
748
- if (!(0, import_editor_utils3.isMarkInSchema)("highlight", editor)) return false;
749
- if (hideWhenUnavailable && !editor.isActive("code")) {
750
- return canColorHighlight(editor);
751
- }
752
- return true;
753
- }
754
- function useColorHighlight(config) {
755
- const {
756
- editor: providedEditor,
757
- label,
758
- highlightColor,
759
- hideWhenUnavailable = false,
760
- onApplied
761
- } = config;
762
- const { editor } = useTiptapEditor(providedEditor);
763
- const isMobile = (0, import_use_is_mobile.useIsMobile)();
764
- const [isVisible, setIsVisible] = React7.useState(true);
765
- const canColorHighlightState = canColorHighlight(editor);
766
- const isActive = isColorHighlightActive(editor, highlightColor);
767
- React7.useEffect(() => {
768
- if (!editor) return;
769
- const handleSelectionUpdate = () => {
770
- setIsVisible(shouldShowButton3({ editor, hideWhenUnavailable }));
771
- };
772
- handleSelectionUpdate();
773
- editor.on("selectionUpdate", handleSelectionUpdate);
774
- return () => {
775
- editor.off("selectionUpdate", handleSelectionUpdate);
776
- };
777
- }, [editor, hideWhenUnavailable]);
778
- const handleColorHighlight = React7.useCallback(() => {
779
- if (!editor || !canColorHighlightState || !highlightColor || !label)
780
- return false;
781
- if (editor.state.storedMarks) {
782
- const highlightMarkType = editor.schema.marks.highlight;
783
- if (highlightMarkType) {
784
- editor.view.dispatch(
785
- editor.state.tr.removeStoredMark(highlightMarkType)
786
- );
787
- }
788
- }
789
- setTimeout(() => {
790
- const success = editor.chain().focus().toggleMark("highlight", { color: highlightColor }).run();
791
- if (success) {
792
- onApplied == null ? void 0 : onApplied({ color: highlightColor, label });
793
- }
794
- return success;
795
- }, 0);
796
- }, [canColorHighlightState, highlightColor, editor, label, onApplied]);
797
- const handleRemoveHighlight = React7.useCallback(() => {
798
- const success = removeHighlight(editor);
799
- if (success) {
800
- onApplied == null ? void 0 : onApplied({ color: "", label: "Remove highlight" });
801
- }
802
- return success;
803
- }, [editor, onApplied]);
804
- (0, import_react_hotkeys_hook.useHotkeys)(
805
- COLOR_HIGHLIGHT_SHORTCUT_KEY,
806
- (event) => {
807
- event.preventDefault();
808
- handleColorHighlight();
809
- },
810
- {
811
- enabled: isVisible && canColorHighlightState,
812
- enableOnContentEditable: !isMobile,
813
- enableOnFormTags: true
814
- }
815
- );
816
- return {
817
- isVisible,
818
- isActive,
819
- handleColorHighlight,
820
- handleRemoveHighlight,
821
- canColorHighlight: canColorHighlightState,
822
- label: label || `Highlight`,
823
- shortcutKeys: COLOR_HIGHLIGHT_SHORTCUT_KEY,
824
- Icon: import_icons4.HighlighterIcon
825
- };
826
- }
827
-
828
- // src/ui/color-highlight-button/color-highlight-button.tsx
829
- var import_jsx_runtime3 = require("react/jsx-runtime");
830
- var ColorHighlightButton = ({
831
- editor: providedEditor,
832
- highlightColor,
833
- text,
834
- hideWhenUnavailable = false,
835
- onApplied,
836
- showShortcut = false,
837
- onClick,
838
- children,
839
- style,
840
- className,
841
- ...buttonProps
842
- }) => {
843
- const { editor } = useTiptapEditor(providedEditor);
844
- const {
845
- isVisible,
846
- canColorHighlight: canColorHighlight2,
847
- isActive,
848
- handleColorHighlight,
849
- label,
850
- shortcutKeys
851
- } = useColorHighlight({
852
- editor,
853
- highlightColor,
854
- label: text || `Toggle highlight (${highlightColor})`,
855
- hideWhenUnavailable,
856
- onApplied
857
- });
858
- const handleClick = (0, import_react4.useCallback)(
859
- (event) => {
860
- onClick == null ? void 0 : onClick(event);
861
- if (event.defaultPrevented) return;
862
- handleColorHighlight();
863
- },
864
- [handleColorHighlight, onClick]
865
- );
866
- const buttonStyle = (0, import_react4.useMemo)(
867
- () => ({
868
- ...style,
869
- "--highlight-color": highlightColor
870
- }),
871
- [highlightColor, style]
872
- );
873
- if (!isVisible) {
874
- return null;
875
- }
876
- const styles = (0, import_theme.colorHighlightButton)();
877
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
878
- import_toolbar3.ToolbarButton,
879
- {
880
- type: "button",
881
- disabled: !canColorHighlight2,
882
- "data-disabled": !canColorHighlight2,
883
- variant: "ghost",
884
- color: "default",
885
- "data-active-state": isActive ? "on" : "off",
886
- tabIndex: -1,
887
- "aria-label": label,
888
- shortcutKeys,
889
- "aria-pressed": isActive,
890
- onClick: handleClick,
891
- style: buttonStyle,
892
- className: styles.button({ className }),
893
- isIconOnly: true,
894
- ...buttonProps,
895
- children: [
896
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
897
- "span",
898
- {
899
- "data-active-state": isActive ? "on" : "off",
900
- className: styles.mark()
901
- }
902
- ),
903
- children || /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
904
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
905
- "span",
906
- {
907
- style: { "--highlight-color": highlightColor }
908
- }
909
- ),
910
- text
911
- ] })
912
- ]
913
- }
914
- );
915
- };
916
-
917
- // src/ui/color-highlight-popover/color-highlight-popover.tsx
918
- var import_jsx_runtime4 = require("react/jsx-runtime");
919
- var ColorHighlightPopoverButton = ({
920
- className,
921
- children,
922
- ...props
923
- }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
924
- import_button.IconButton,
925
- {
926
- type: "button",
927
- className,
928
- variant: "ghost",
929
- color: "default",
930
- tabIndex: -1,
931
- "aria-label": "Highlight text",
932
- tooltip: "Highlight",
933
- isIconOnly: !children,
934
- ...props,
935
- children: children != null ? children : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_icons5.HighlighterIcon, {})
936
- }
937
- );
938
- function ColorHighlightPopoverContent({
939
- editor,
940
- colors = pickHighlightColorsByValue([
941
- "var(--tt-color-highlight-green)",
942
- "var(--tt-color-highlight-blue)",
943
- "var(--tt-color-highlight-red)",
944
- "var(--tt-color-highlight-purple)",
945
- "var(--tt-color-highlight-yellow)"
946
- ])
947
- }) {
948
- const { handleRemoveHighlight } = useColorHighlight({ editor });
949
- const containerRef = (0, import_react5.useRef)(null);
950
- const menuItems = (0, import_react5.useMemo)(
951
- () => [...colors, { label: "Remove highlight", value: "none" }],
952
- [colors]
953
- );
954
- const { selectedIndex } = useMenuNavigation({
955
- containerRef,
956
- items: menuItems,
957
- orientation: "both",
958
- onSelect: (item) => {
959
- if (!containerRef.current) return false;
960
- const highlightedElement = containerRef.current.querySelector(
961
- '[data-highlighted="true"]'
962
- );
963
- if (highlightedElement) highlightedElement.click();
964
- if (item.value === "none") handleRemoveHighlight();
965
- },
966
- autoSelectFirstItem: false
967
- });
968
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: containerRef, className: "flex gap-1 items-center", children: [
969
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
970
- "div",
971
- {
972
- className: "flex items-center gap-1 outline-none",
973
- "data-orientation": "horizontal",
974
- children: colors.map((color, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
975
- ColorHighlightButton,
976
- {
977
- editor,
978
- highlightColor: color.value,
979
- "aria-label": `${color.label} highlight color`,
980
- tabIndex: index === selectedIndex ? 0 : -1,
981
- "data-highlighted": selectedIndex === index
982
- },
983
- color.value
984
- ))
985
- }
986
- ),
987
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_toolbar4.ToolbarSeparator, { orientation: "vertical" }),
988
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "tiptap-button-group", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
989
- import_button.IconButton,
990
- {
991
- onClick: handleRemoveHighlight,
992
- "aria-label": "Remove highlight",
993
- tabIndex: selectedIndex === colors.length ? 0 : -1,
994
- type: "button",
995
- role: "menuitem",
996
- variant: "ghost",
997
- color: "default",
998
- "data-highlighted": selectedIndex === colors.length,
999
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_icons5.BanIcon, {})
1000
- }
1001
- ) })
1002
- ] });
1003
- }
1004
- function ColorHighlightPopover({
1005
- editor: providedEditor,
1006
- colors = pickHighlightColorsByValue([
1007
- "var(--tt-color-highlight-green)",
1008
- "var(--tt-color-highlight-blue)",
1009
- "var(--tt-color-highlight-red)",
1010
- "var(--tt-color-highlight-purple)",
1011
- "var(--tt-color-highlight-yellow)"
1012
- ]),
1013
- hideWhenUnavailable = false,
1014
- onApplied,
1015
- ...props
1016
- }) {
1017
- const { editor } = useTiptapEditor(providedEditor);
1018
- const [isOpen, setIsOpen] = (0, import_react5.useState)(false);
1019
- const { isVisible, canColorHighlight: canColorHighlight2, isActive, label } = useColorHighlight({
1020
- editor,
1021
- hideWhenUnavailable,
1022
- onApplied
1023
- });
1024
- if (!isVisible) return null;
1025
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_popover.Popover.Root, { open: isOpen, onOpenChange: setIsOpen, spacing: "dense", children: [
1026
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1027
- import_popover.Popover.Trigger,
1028
- {
1029
- render: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1030
- ColorHighlightPopoverButton,
1031
- {
1032
- disabled: !canColorHighlight2,
1033
- "data-disabled": !canColorHighlight2,
1034
- "data-active-state": isActive ? "on" : "off",
1035
- "aria-pressed": isActive,
1036
- "aria-label": label,
1037
- title: label,
1038
- ...props
1039
- }
1040
- )
1041
- }
1042
- ),
1043
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_popover.Popover.Content, { "aria-label": "Highlight colors", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ColorHighlightPopoverContent, { editor, colors }) })
1044
- ] });
1045
- }
1046
-
1047
- // src/ui/heading-dropdown-menu/index.tsx
1048
- var import_button3 = require("@kopexa/button");
1049
- var import_dropdown_menu = require("@kopexa/dropdown-menu");
1050
- var import_editor_utils5 = require("@kopexa/editor-utils");
1051
- var import_icons7 = require("@kopexa/icons");
1052
- var import_react7 = require("@tiptap/react");
1053
- var React9 = __toESM(require("react"));
1054
-
1055
- // src/ui/heading-button/index.tsx
1056
- var import_button2 = require("@kopexa/button");
1057
- var import_editor_utils4 = require("@kopexa/editor-utils");
1058
- var import_icons6 = require("@kopexa/icons");
1059
- var React8 = __toESM(require("react"));
1060
-
1061
- // src/ui/heading-button/utils.ts
1062
- var import_react6 = require("@tiptap/react");
1063
- var headingShortcutKeys = {
1064
- 1: "Ctrl-Alt-1",
1065
- 2: "Ctrl-Alt-2",
1066
- 3: "Ctrl-Alt-3",
1067
- 4: "Ctrl-Alt-4",
1068
- 5: "Ctrl-Alt-5",
1069
- 6: "Ctrl-Alt-6"
1070
- };
1071
- function canToggleHeading(editor, level) {
1072
- if (!editor) return false;
1073
- try {
1074
- return editor.can().toggleNode("heading", "paragraph", { level });
1075
- } catch {
1076
- return false;
1077
- }
1078
- }
1079
- function isHeadingActive(editor, level) {
1080
- if (!editor) return false;
1081
- return editor.isActive("heading", { level });
1082
- }
1083
- function toggleHeading(editor, level) {
1084
- if (!editor) return;
1085
- if (editor.isActive("heading", { level })) {
1086
- editor.chain().focus().setNode("paragraph").run();
1087
- } else {
1088
- editor.chain().focus().toggleNode("heading", "paragraph", { level }).run();
1089
- }
1090
- }
1091
- function isHeadingButtonDisabled(editor, level, userDisabled = false) {
1092
- if (!editor) return true;
1093
- if (userDisabled) return true;
1094
- if (!canToggleHeading(editor, level)) return true;
1095
- return false;
1096
- }
1097
- function shouldShowHeadingButton(params) {
1098
- const { editor, hideWhenUnavailable, headingInSchema } = params;
1099
- if (!headingInSchema || !editor) {
1100
- return false;
1101
- }
1102
- if (hideWhenUnavailable) {
1103
- if ((0, import_react6.isNodeSelection)(editor.state.selection)) {
1104
- return false;
1105
- }
1106
- }
1107
- return true;
1108
- }
1109
- function getFormattedHeadingName(level) {
1110
- return `Heading ${level}`;
1111
- }
1112
-
1113
- // src/ui/heading-button/index.tsx
1114
- var import_jsx_runtime5 = require("react/jsx-runtime");
1115
- var headingIcons = {
1116
- 1: import_icons6.HeadingOneIcon,
1117
- 2: import_icons6.HeadingTwoIcon,
1118
- 3: import_icons6.HeadingThreeIcon,
1119
- 4: import_icons6.HeadingFourIcon,
1120
- 5: import_icons6.HeadingFiveIcon,
1121
- 6: import_icons6.HeadingSixIcon
1122
- };
1123
- function useHeadingState(editor, level, disabled = false) {
1124
- const headingInSchema = (0, import_editor_utils4.isNodeInSchema)("heading", editor);
1125
- const isDisabled = isHeadingButtonDisabled(editor, level, disabled);
1126
- const isActive = isHeadingActive(editor, level);
1127
- const Icon = headingIcons[level];
1128
- const shortcutKey = headingShortcutKeys[level];
1129
- const formattedName = getFormattedHeadingName(level);
1130
- return {
1131
- headingInSchema,
1132
- isDisabled,
1133
- isActive,
1134
- Icon,
1135
- shortcutKey,
1136
- formattedName
1137
- };
1138
- }
1139
- var HeadingButton = ({
1140
- editor: providedEditor,
1141
- level,
1142
- text,
1143
- hideWhenUnavailable = false,
1144
- className = "",
1145
- disabled,
1146
- onClick,
1147
- children,
1148
- ref,
1149
- ...buttonProps
1150
- }) => {
1151
- const { editor } = useTiptapEditor(providedEditor);
1152
- const {
1153
- headingInSchema,
1154
- isDisabled,
1155
- isActive,
1156
- Icon,
1157
- shortcutKey,
1158
- formattedName
1159
- } = useHeadingState(editor, level, disabled);
1160
- const handleClick = React8.useCallback(
1161
- (e) => {
1162
- onClick == null ? void 0 : onClick(e);
1163
- if (!e.defaultPrevented && !isDisabled && editor) {
1164
- toggleHeading(editor, level);
1165
- }
1166
- },
1167
- [onClick, isDisabled, editor, level]
1168
- );
1169
- const show = React8.useMemo(() => {
1170
- return shouldShowHeadingButton({
1171
- editor,
1172
- level,
1173
- hideWhenUnavailable,
1174
- headingInSchema
1175
- });
1176
- }, [editor, level, hideWhenUnavailable, headingInSchema]);
1177
- if (!show || !editor || !editor.isEditable) {
1178
- return null;
1179
- }
1180
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1181
- import_button2.Button,
1182
- {
1183
- type: "button",
1184
- className: className.trim(),
1185
- disabled: isDisabled,
1186
- variant: "ghost",
1187
- color: "default",
1188
- "data-active-state": isActive ? "on" : "off",
1189
- "data-disabled": isDisabled,
1190
- tabIndex: -1,
1191
- "aria-label": formattedName,
1192
- "aria-pressed": isActive,
1193
- tooltip: formattedName,
1194
- shortcutKeys: shortcutKey,
1195
- onClick: handleClick,
1196
- startContent: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, {}),
1197
- ...buttonProps,
1198
- ref,
1199
- children: children || text
1200
- }
1201
- );
1202
- };
1203
-
1204
- // src/ui/heading-dropdown-menu/index.tsx
1205
- var import_jsx_runtime6 = require("react/jsx-runtime");
1206
- function HeadingDropdownMenu({
1207
- editor: providedEditor,
1208
- levels = [1, 2, 3, 4, 5, 6],
1209
- hideWhenUnavailable = false,
1210
- onOpenChange,
1211
- ...props
1212
- }) {
1213
- var _a;
1214
- const [isOpen, setIsOpen] = React9.useState(false);
1215
- const { editor } = useTiptapEditor(providedEditor);
1216
- const headingInSchema = (0, import_editor_utils5.isNodeInSchema)("heading", editor);
1217
- const handleOnOpenChange = React9.useCallback(
1218
- (open) => {
1219
- setIsOpen(open);
1220
- onOpenChange == null ? void 0 : onOpenChange(open);
1221
- },
1222
- [onOpenChange]
1223
- );
1224
- const getActiveIcon = React9.useCallback(() => {
1225
- if (!editor) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons7.HeadingIcon, {});
1226
- const activeLevel = levels.find(
1227
- (level) => editor.isActive("heading", { level })
1228
- );
1229
- if (!activeLevel) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons7.HeadingIcon, {});
1230
- const ActiveIcon = headingIcons[activeLevel];
1231
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ActiveIcon, {});
1232
- }, [editor, levels]);
1233
- const canToggleAnyHeading = React9.useCallback(() => {
1234
- if (!editor) return false;
1235
- return levels.some(
1236
- (level) => editor.can().toggleNode("heading", "paragraph", { level })
1237
- );
1238
- }, [editor, levels]);
1239
- const isDisabled = !canToggleAnyHeading();
1240
- const isAnyHeadingActive = (_a = editor == null ? void 0 : editor.isActive("heading")) != null ? _a : false;
1241
- const show = React9.useMemo(() => {
1242
- if (!headingInSchema || !editor) {
1243
- return false;
1244
- }
1245
- if (hideWhenUnavailable) {
1246
- if ((0, import_react7.isNodeSelection)(editor.state.selection) || !canToggleAnyHeading()) {
1247
- return false;
1248
- }
1249
- }
1250
- return true;
1251
- }, [headingInSchema, editor, hideWhenUnavailable, canToggleAnyHeading]);
1252
- if (!show || !editor || !editor.isEditable) {
1253
- return null;
1254
- }
1255
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_dropdown_menu.DropdownMenu.Root, { open: isOpen, onOpenChange: handleOnOpenChange, children: [
1256
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_dropdown_menu.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1257
- import_button3.Button,
1258
- {
1259
- type: "button",
1260
- disabled: isDisabled,
1261
- variant: "ghost",
1262
- color: "default",
1263
- "data-active-state": isAnyHeadingActive ? "on" : "off",
1264
- "data-disabled": isDisabled,
1265
- tabIndex: -1,
1266
- "aria-label": "Format text as heading",
1267
- "aria-pressed": isAnyHeadingActive,
1268
- tooltip: "Heading",
1269
- endContent: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons7.ChevronDownIcon, {}),
1270
- ...props,
1271
- children: getActiveIcon()
1272
- }
1273
- ) }),
1274
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_dropdown_menu.DropdownMenu.Content, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_dropdown_menu.DropdownMenu.Group, { children: levels.map((level) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_dropdown_menu.DropdownMenu.Item, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1275
- HeadingButton,
1276
- {
1277
- editor,
1278
- level,
1279
- text: getFormattedHeadingName(level),
1280
- tooltip: "",
1281
- fullWidth: true,
1282
- spacing: "start"
1283
- }
1284
- ) }, `heading-${level}`)) }) })
1285
- ] });
1286
- }
1287
-
1288
- // src/ui/link-popover/link-popover.tsx
1289
- var import_button4 = require("@kopexa/button");
1290
- var import_icons9 = require("@kopexa/icons");
1291
- var import_input = require("@kopexa/input");
1292
- var import_popover2 = require("@kopexa/popover");
1293
- var import_toolbar5 = require("@kopexa/toolbar");
1294
- var import_react8 = require("react");
1295
-
1296
- // src/ui/link-popover/use-link-popover.ts
1297
- var import_editor_utils6 = require("@kopexa/editor-utils");
1298
- var import_icons8 = require("@kopexa/icons");
1299
- var React10 = __toESM(require("react"));
1300
-
1301
- // src/utils/index.ts
1302
- var MAX_FILE_SIZE = 5 * 1024 * 1024;
1303
- var ATTR_WHITESPACE = (
1304
- // eslint-disable-next-line no-control-regex
1305
- // biome-ignore lint/suspicious/noControlCharactersInRegex: we can do this yay
1306
- /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
1307
- );
1308
- function isAllowedUri(uri, protocols) {
1309
- const allowedProtocols = [
1310
- "http",
1311
- "https",
1312
- "ftp",
1313
- "ftps",
1314
- "mailto",
1315
- "tel",
1316
- "callto",
1317
- "sms",
1318
- "cid",
1319
- "xmpp"
1320
- ];
1321
- if (protocols) {
1322
- for (const protocol of protocols) {
1323
- const nextProtocol = typeof protocol === "string" ? protocol : protocol.scheme;
1324
- if (nextProtocol) {
1325
- allowedProtocols.push(nextProtocol);
1326
- }
1327
- }
1328
- }
1329
- return !uri || uri.replace(ATTR_WHITESPACE, "").match(
1330
- new RegExp(
1331
- // eslint-disable-next-line no-useless-escape
1332
- `^(?:(?:${allowedProtocols.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,
1333
- "i"
1334
- )
1335
- );
1336
- }
1337
- function sanitizeUrl(inputUrl, baseUrl, protocols) {
1338
- try {
1339
- const url = new URL(inputUrl, baseUrl);
1340
- if (isAllowedUri(url.href, protocols)) {
1341
- return url.href;
1342
- }
1343
- } catch {
1344
- }
1345
- return "#";
1346
- }
1347
-
1348
- // src/ui/link-popover/use-link-popover.ts
1349
- function canSetLink(editor) {
1350
- if (!editor || !editor.isEditable) return false;
1351
- return editor.can().setMark("link");
1352
- }
1353
- function isLinkActive(editor) {
1354
- if (!editor || !editor.isEditable) return false;
1355
- return editor.isActive("link");
1356
- }
1357
- function shouldShowLinkButton(props) {
1358
- const { editor, hideWhenUnavailable } = props;
1359
- const linkInSchema = (0, import_editor_utils6.isMarkInSchema)("link", editor);
1360
- if (!linkInSchema || !editor) {
1361
- return false;
1362
- }
1363
- if (hideWhenUnavailable && !editor.isActive("code")) {
1364
- return canSetLink(editor);
1365
- }
1366
- return true;
1367
- }
1368
- function useLinkHandler(props) {
1369
- const { editor, onSetLink } = props;
1370
- const [url, setUrl] = React10.useState(null);
1371
- React10.useEffect(() => {
1372
- if (!editor) return;
1373
- const { href } = editor.getAttributes("link");
1374
- if (isLinkActive(editor) && url === null) {
1375
- setUrl(href || "");
1376
- }
1377
- }, [editor, url]);
1378
- React10.useEffect(() => {
1379
- if (!editor) return;
1380
- const updateLinkState = () => {
1381
- const { href } = editor.getAttributes("link");
1382
- setUrl(href || "");
1383
- };
1384
- editor.on("selectionUpdate", updateLinkState);
1385
- return () => {
1386
- editor.off("selectionUpdate", updateLinkState);
1387
- };
1388
- }, [editor]);
1389
- const setLink = React10.useCallback(() => {
1390
- if (!url || !editor) return;
1391
- const { selection } = editor.state;
1392
- const isEmpty = selection.empty;
1393
- let chain = editor.chain().focus();
1394
- chain = chain.extendMarkRange("link").setLink({ href: url });
1395
- if (isEmpty) {
1396
- chain = chain.insertContent({ type: "text", text: url });
1397
- }
1398
- chain.run();
1399
- setUrl(null);
1400
- onSetLink == null ? void 0 : onSetLink();
1401
- }, [editor, onSetLink, url]);
1402
- const removeLink = React10.useCallback(() => {
1403
- if (!editor) return;
1404
- editor.chain().focus().extendMarkRange("link").unsetLink().setMeta("preventAutolink", true).run();
1405
- setUrl("");
1406
- }, [editor]);
1407
- const openLink = React10.useCallback(
1408
- (target = "_blank", features = "noopener,noreferrer") => {
1409
- if (!url) return;
1410
- const safeUrl = sanitizeUrl(url, window.location.href);
1411
- if (safeUrl !== "#") {
1412
- window.open(safeUrl, target, features);
1413
- }
1414
- },
1415
- [url]
1416
- );
1417
- return {
1418
- url: url || "",
1419
- setUrl,
1420
- setLink,
1421
- removeLink,
1422
- openLink
1423
- };
1424
- }
1425
- function useLinkState(props) {
1426
- const { editor, hideWhenUnavailable = false } = props;
1427
- const canSet = canSetLink(editor);
1428
- const isActive = isLinkActive(editor);
1429
- const [isVisible, setIsVisible] = React10.useState(false);
1430
- React10.useEffect(() => {
1431
- if (!editor) return;
1432
- const handleSelectionUpdate = () => {
1433
- setIsVisible(
1434
- shouldShowLinkButton({
1435
- editor,
1436
- hideWhenUnavailable
1437
- })
1438
- );
1439
- };
1440
- handleSelectionUpdate();
1441
- editor.on("selectionUpdate", handleSelectionUpdate);
1442
- return () => {
1443
- editor.off("selectionUpdate", handleSelectionUpdate);
1444
- };
1445
- }, [editor, hideWhenUnavailable]);
1446
- return {
1447
- isVisible,
1448
- canSet,
1449
- isActive
1450
- };
1451
- }
1452
- function useLinkPopover(config) {
1453
- const {
1454
- editor: providedEditor,
1455
- hideWhenUnavailable = false,
1456
- onSetLink
1457
- } = config || {};
1458
- const { editor } = useTiptapEditor(providedEditor);
1459
- const { isVisible, canSet, isActive } = useLinkState({
1460
- editor,
1461
- hideWhenUnavailable
1462
- });
1463
- const linkHandler = useLinkHandler({
1464
- editor,
1465
- onSetLink
1466
- });
1467
- return {
1468
- isVisible,
1469
- canSet,
1470
- isActive,
1471
- label: "Link",
1472
- Icon: import_icons8.LinkIcon,
1473
- ...linkHandler
1474
- };
1475
- }
1476
-
1477
- // src/ui/link-popover/link-popover.tsx
1478
- var import_jsx_runtime7 = require("react/jsx-runtime");
1479
- var LinkButton = ({ className, children, ...props }) => {
1480
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1481
- import_toolbar5.ToolbarButton,
1482
- {
1483
- type: "button",
1484
- className,
1485
- variant: "ghost",
1486
- color: "default",
1487
- tabIndex: -1,
1488
- "aria-label": "Link",
1489
- title: "Link",
1490
- isIconOnly: !children,
1491
- ...props,
1492
- children: children || /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons9.LinkIcon, {})
1493
- }
1494
- );
1495
- };
1496
- var LinkMain = ({
1497
- url,
1498
- setUrl,
1499
- setLink,
1500
- removeLink,
1501
- openLink,
1502
- isActive,
1503
- onSave
1504
- }) => {
1505
- const [isEditing, setIsEditing] = (0, import_react8.useState)(!isActive || !url);
1506
- (0, import_react8.useEffect)(() => {
1507
- setIsEditing(!isActive || !url);
1508
- }, [isActive, url]);
1509
- const handleKeyDown = (event) => {
1510
- if (event.key === "Enter") {
1511
- event.preventDefault();
1512
- setLink();
1513
- setIsEditing(false);
1514
- onSave == null ? void 0 : onSave();
1515
- } else if (event.key === "Escape") {
1516
- event.preventDefault();
1517
- setIsEditing(false);
1518
- }
1519
- };
1520
- const handleSave = () => {
1521
- setLink();
1522
- setIsEditing(false);
1523
- onSave == null ? void 0 : onSave();
1524
- };
1525
- const handleEdit = () => {
1526
- setIsEditing(true);
1527
- };
1528
- if (isEditing) {
1529
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center gap-1 min-w-[280px]", children: [
1530
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1531
- import_input.Input,
1532
- {
1533
- type: "url",
1534
- placeholder: "Enter URL...",
1535
- value: url,
1536
- onChange: (e) => setUrl(e.target.value),
1537
- onKeyDown: handleKeyDown,
1538
- autoComplete: "off",
1539
- autoCorrect: "off",
1540
- autoCapitalize: "off",
1541
- className: "flex-1 h-8 text-sm",
1542
- autoFocus: true
1543
- }
1544
- ),
1545
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1546
- import_button4.IconButton,
1547
- {
1548
- type: "button",
1549
- size: "sm",
1550
- variant: "ghost",
1551
- onClick: handleSave,
1552
- "aria-label": "Save link",
1553
- disabled: !url,
1554
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons9.CheckIcon, { className: "size-4" })
1555
- }
1556
- )
1557
- ] });
1558
- }
1559
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center gap-1 min-w-[280px]", children: [
1560
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1561
- "a",
1562
- {
1563
- href: url,
1564
- target: "_blank",
1565
- rel: "noopener noreferrer",
1566
- className: "flex-1 text-sm text-primary truncate max-w-[200px] hover:underline px-2",
1567
- onClick: (e) => {
1568
- e.preventDefault();
1569
- openLink();
1570
- },
1571
- children: url
1572
- }
1573
- ),
1574
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center gap-0.5 border-l pl-1 ml-1", children: [
1575
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1576
- import_button4.IconButton,
1577
- {
1578
- type: "button",
1579
- size: "sm",
1580
- variant: "ghost",
1581
- onClick: openLink,
1582
- "aria-label": "Open link in new tab",
1583
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons9.ExternalLinkIcon, { className: "size-4" })
1584
- }
1585
- ),
1586
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1587
- import_button4.IconButton,
1588
- {
1589
- type: "button",
1590
- size: "sm",
1591
- variant: "ghost",
1592
- onClick: handleEdit,
1593
- "aria-label": "Edit link",
1594
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons9.EditIcon, { className: "size-4" })
1595
- }
1596
- ),
1597
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1598
- import_button4.IconButton,
1599
- {
1600
- type: "button",
1601
- size: "sm",
1602
- variant: "ghost",
1603
- onClick: removeLink,
1604
- "aria-label": "Remove link",
1605
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons9.TrashIcon, { className: "size-4" })
1606
- }
1607
- )
1608
- ] })
1609
- ] });
1610
- };
1611
- function LinkPopover({
1612
- editor: providedEditor,
1613
- hideWhenUnavailable = false,
1614
- onSetLink,
1615
- onOpenChange,
1616
- autoOpenOnLinkActive = true,
1617
- onClick,
1618
- children,
1619
- ...buttonProps
1620
- }) {
1621
- const { editor } = useTiptapEditor(providedEditor);
1622
- const [isOpen, setIsOpen] = (0, import_react8.useState)(false);
1623
- const {
1624
- isVisible,
1625
- canSet,
1626
- isActive,
1627
- url,
1628
- setUrl,
1629
- setLink,
1630
- removeLink,
1631
- openLink,
1632
- label
1633
- } = useLinkPopover({
1634
- editor,
1635
- hideWhenUnavailable,
1636
- onSetLink
1637
- });
1638
- const handleOnOpenChange = (0, import_react8.useCallback)(
1639
- (nextIsOpen) => {
1640
- setIsOpen(nextIsOpen);
1641
- onOpenChange == null ? void 0 : onOpenChange(nextIsOpen);
1642
- },
1643
- [onOpenChange]
1644
- );
1645
- const handleSetLink = (0, import_react8.useCallback)(() => {
1646
- setLink();
1647
- setIsOpen(false);
1648
- }, [setLink]);
1649
- const handleClick = (0, import_react8.useCallback)(
1650
- (event) => {
1651
- onClick == null ? void 0 : onClick(event);
1652
- if (event.defaultPrevented) return;
1653
- setIsOpen(!isOpen);
1654
- },
1655
- [onClick, isOpen]
1656
- );
1657
- (0, import_react8.useEffect)(() => {
1658
- if (autoOpenOnLinkActive && isActive) {
1659
- setIsOpen(true);
1660
- }
1661
- }, [autoOpenOnLinkActive, isActive]);
1662
- if (!isVisible) {
1663
- return null;
1664
- }
1665
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1666
- import_popover2.Popover.Root,
1667
- {
1668
- open: isOpen,
1669
- onOpenChange: handleOnOpenChange,
1670
- spacing: "dense",
1671
- children: [
1672
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1673
- import_popover2.Popover.Trigger,
1674
- {
1675
- render: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1676
- LinkButton,
1677
- {
1678
- "data-disabled": !canSet,
1679
- disabled: !canSet,
1680
- "data-active-state": isActive ? "on" : "off",
1681
- "aria-label": label,
1682
- "aria-pressed": isActive,
1683
- onClick: handleClick,
1684
- ...buttonProps
1685
- }
1686
- )
1687
- }
1688
- ),
1689
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_popover2.Popover.Content, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1690
- LinkMain,
1691
- {
1692
- url,
1693
- setUrl,
1694
- setLink: handleSetLink,
1695
- removeLink,
1696
- openLink,
1697
- isActive,
1698
- onSave: () => setIsOpen(false)
1699
- }
1700
- ) })
1701
- ]
1702
- }
1703
- );
1704
- }
1705
- LinkButton.displayName = "LinkButton";
1706
-
1707
- // src/ui/list-dropdown-menu/index.tsx
1708
- var import_button6 = require("@kopexa/button");
1709
- var import_dropdown_menu2 = require("@kopexa/dropdown-menu");
1710
- var import_editor_utils8 = require("@kopexa/editor-utils");
1711
- var import_icons11 = require("@kopexa/icons");
1712
- var import_react11 = require("@tiptap/react");
1713
- var import_react12 = require("react");
1714
-
1715
- // src/ui/list-button/index.tsx
1716
- var import_button5 = require("@kopexa/button");
1717
- var import_editor_utils7 = require("@kopexa/editor-utils");
1718
- var import_icons10 = require("@kopexa/icons");
1719
- var import_react9 = require("@tiptap/react");
1720
- var import_react10 = require("react");
1721
- var import_jsx_runtime8 = require("react/jsx-runtime");
1722
- var listOptions = [
1723
- {
1724
- label: "Bullet List",
1725
- type: "bulletList",
1726
- icon: import_icons10.ListIcon
1727
- },
1728
- {
1729
- label: "Ordered List",
1730
- type: "orderedList",
1731
- icon: import_icons10.ListOrderedIcon
1732
- },
1733
- {
1734
- label: "Task List",
1735
- type: "taskList",
1736
- icon: import_icons10.ListTodoIcon
1737
- }
1738
- ];
1739
- var listShortcutKeys = {
1740
- bulletList: "Ctrl-Shift-8",
1741
- orderedList: "Ctrl-Shift-7",
1742
- taskList: "Ctrl-Shift-9"
1743
- };
1744
- function canToggleList(editor, type) {
1745
- if (!editor) {
1746
- return false;
1747
- }
1748
- switch (type) {
1749
- case "bulletList":
1750
- return editor.can().toggleBulletList();
1751
- case "orderedList":
1752
- return editor.can().toggleOrderedList();
1753
- case "taskList":
1754
- return editor.can().toggleList("taskList", "taskItem");
1755
- default:
1756
- return false;
1757
- }
1758
- }
1759
- function isListActive(editor, type) {
1760
- if (!editor) return false;
1761
- switch (type) {
1762
- case "bulletList":
1763
- return editor.isActive("bulletList");
1764
- case "orderedList":
1765
- return editor.isActive("orderedList");
1766
- case "taskList":
1767
- return editor.isActive("taskList");
1768
- default:
1769
- return false;
1770
- }
1771
- }
1772
- function toggleList(editor, type) {
1773
- if (!editor) return;
1774
- switch (type) {
1775
- case "bulletList":
1776
- editor.chain().focus().toggleBulletList().run();
1777
- break;
1778
- case "orderedList":
1779
- editor.chain().focus().toggleOrderedList().run();
1780
- break;
1781
- case "taskList":
1782
- editor.chain().focus().toggleList("taskList", "taskItem").run();
1783
- break;
1784
- }
1785
- }
1786
- function getListOption(type) {
1787
- return listOptions.find((option) => option.type === type);
1788
- }
1789
- function shouldShowListButton(params) {
1790
- const { editor, type, hideWhenUnavailable, listInSchema } = params;
1791
- if (!listInSchema || !editor) {
1792
- return false;
1793
- }
1794
- if (hideWhenUnavailable) {
1795
- if ((0, import_react9.isNodeSelection)(editor.state.selection) || !canToggleList(editor, type)) {
1796
- return false;
1797
- }
1798
- }
1799
- return true;
1800
- }
1801
- function useListState(editor, type) {
1802
- const listInSchema = (0, import_editor_utils7.isNodeInSchema)(type, editor);
1803
- const listOption = getListOption(type);
1804
- const isActive = isListActive(editor, type);
1805
- const shortcutKey = listShortcutKeys[type];
1806
- return {
1807
- listInSchema,
1808
- listOption,
1809
- isActive,
1810
- shortcutKey
1811
- };
1812
- }
1813
- var ListButton = ({
1814
- editor: providedEditor,
1815
- type,
1816
- hideWhenUnavailable = false,
1817
- className = "",
1818
- onClick,
1819
- text,
1820
- children,
1821
- ref,
1822
- ...buttonProps
1823
- }) => {
1824
- const { editor } = useTiptapEditor(providedEditor);
1825
- const { listInSchema, listOption, isActive, shortcutKey } = useListState(
1826
- editor,
1827
- type
1828
- );
1829
- const Icon = (listOption == null ? void 0 : listOption.icon) || import_icons10.ListIcon;
1830
- const handleClick = (0, import_react10.useCallback)(
1831
- (e) => {
1832
- onClick == null ? void 0 : onClick(e);
1833
- if (!e.defaultPrevented && editor) {
1834
- toggleList(editor, type);
1835
- }
1836
- },
1837
- [onClick, editor, type]
1838
- );
1839
- const show = (0, import_react10.useMemo)(() => {
1840
- return shouldShowListButton({
1841
- editor,
1842
- type,
1843
- hideWhenUnavailable,
1844
- listInSchema
1845
- });
1846
- }, [editor, type, hideWhenUnavailable, listInSchema]);
1847
- if (!show || !editor || !editor.isEditable) {
1848
- return null;
1849
- }
1850
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1851
- import_button5.Button,
1852
- {
1853
- type: "button",
1854
- className: className.trim(),
1855
- variant: "ghost",
1856
- color: "default",
1857
- "data-active-state": isActive ? "on" : "off",
1858
- tabIndex: -1,
1859
- "aria-label": (listOption == null ? void 0 : listOption.label) || type,
1860
- "aria-pressed": isActive,
1861
- tooltip: (listOption == null ? void 0 : listOption.label) || type,
1862
- shortcutKeys: shortcutKey,
1863
- onClick: handleClick,
1864
- startContent: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, {}),
1865
- ...buttonProps,
1866
- ref,
1867
- children: children || text
1868
- }
1869
- );
1870
- };
1871
-
1872
- // src/ui/list-dropdown-menu/index.tsx
1873
- var import_jsx_runtime9 = require("react/jsx-runtime");
1874
- function canToggleAnyList(editor, listTypes) {
1875
- if (!editor) return false;
1876
- return listTypes.some((type) => canToggleList(editor, type));
1877
- }
1878
- function isAnyListActive(editor, listTypes) {
1879
- if (!editor) return false;
1880
- return listTypes.some((type) => isListActive(editor, type));
1881
- }
1882
- function getFilteredListOptions(availableTypes) {
1883
- return listOptions.filter(
1884
- (option) => !option.type || availableTypes.includes(option.type)
1885
- );
1886
- }
1887
- function shouldShowListDropdown(params) {
1888
- const { editor, hideWhenUnavailable, listInSchema, canToggleAny } = params;
1889
- if (!listInSchema || !editor) {
1890
- return false;
1891
- }
1892
- if (hideWhenUnavailable) {
1893
- if ((0, import_react11.isNodeSelection)(editor.state.selection) || !canToggleAny) {
1894
- return false;
1895
- }
1896
- }
1897
- return true;
1898
- }
1899
- function useListDropdownState(editor, availableTypes) {
1900
- const [isOpen, setIsOpen] = (0, import_react12.useState)(false);
1901
- const listInSchema = availableTypes.some(
1902
- (type) => (0, import_editor_utils8.isNodeInSchema)(type, editor)
1903
- );
1904
- const filteredLists = (0, import_react12.useMemo)(
1905
- () => getFilteredListOptions(availableTypes),
1906
- [availableTypes]
1907
- );
1908
- const canToggleAny = canToggleAnyList(editor, availableTypes);
1909
- const isAnyActive = isAnyListActive(editor, availableTypes);
1910
- const handleOpenChange = (0, import_react12.useCallback)(
1911
- (open, callback) => {
1912
- setIsOpen(open);
1913
- callback == null ? void 0 : callback(open);
1914
- },
1915
- []
1916
- );
1917
- return {
1918
- isOpen,
1919
- setIsOpen,
1920
- listInSchema,
1921
- filteredLists,
1922
- canToggleAny,
1923
- isAnyActive,
1924
- handleOpenChange
1925
- };
1926
- }
1927
- function useActiveListIcon(editor, filteredLists) {
1928
- return (0, import_react12.useCallback)(() => {
1929
- const activeOption = filteredLists.find(
1930
- (option) => isListActive(editor, option.type)
1931
- );
1932
- return activeOption ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(activeOption.icon, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons11.ListIcon, {});
1933
- }, [editor, filteredLists]);
1934
- }
1935
- function ListDropdownMenu({
1936
- editor: providedEditor,
1937
- types = ["bulletList", "orderedList", "taskList"],
1938
- hideWhenUnavailable = false,
1939
- onOpenChange,
1940
- ...props
1941
- }) {
1942
- const { editor } = useTiptapEditor(providedEditor);
1943
- const {
1944
- isOpen,
1945
- listInSchema,
1946
- filteredLists,
1947
- canToggleAny,
1948
- isAnyActive,
1949
- handleOpenChange
1950
- } = useListDropdownState(editor, types);
1951
- const getActiveIcon = useActiveListIcon(editor, filteredLists);
1952
- const show = (0, import_react12.useMemo)(() => {
1953
- return shouldShowListDropdown({
1954
- editor,
1955
- listTypes: types,
1956
- hideWhenUnavailable,
1957
- listInSchema,
1958
- canToggleAny
1959
- });
1960
- }, [editor, types, hideWhenUnavailable, listInSchema, canToggleAny]);
1961
- const handleOnOpenChange = (0, import_react12.useCallback)(
1962
- (open) => handleOpenChange(open, onOpenChange),
1963
- [handleOpenChange, onOpenChange]
1964
- );
1965
- if (!show || !editor || !editor.isEditable) {
1966
- return null;
1967
- }
1968
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_dropdown_menu2.DropdownMenu.Root, { open: isOpen, onOpenChange: handleOnOpenChange, children: [
1969
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dropdown_menu2.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1970
- import_button6.Button,
1971
- {
1972
- type: "button",
1973
- variant: "ghost",
1974
- color: "default",
1975
- "data-active-state": isAnyActive ? "on" : "off",
1976
- tabIndex: -1,
1977
- "aria-label": "List options",
1978
- tooltip: "List",
1979
- endContent: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons11.ChevronDownIcon, {}),
1980
- ...props,
1981
- children: getActiveIcon()
1982
- }
1983
- ) }),
1984
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dropdown_menu2.DropdownMenu.Content, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dropdown_menu2.DropdownMenu.Group, { children: filteredLists.map((option) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dropdown_menu2.DropdownMenu.Item, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1985
- ListButton,
1986
- {
1987
- editor,
1988
- type: option.type,
1989
- text: option.label,
1990
- hideWhenUnavailable,
1991
- tooltip: "",
1992
- fullWidth: true,
1993
- spacing: "start"
1994
- }
1995
- ) }, option.type)) }) })
1996
- ] });
1997
- }
1998
-
1999
- // src/ui/mark-button/index.tsx
2000
- var import_editor_utils9 = require("@kopexa/editor-utils");
2001
- var import_icons12 = require("@kopexa/icons");
2002
- var import_toolbar6 = require("@kopexa/toolbar");
2003
- var import_react13 = require("@tiptap/react");
2004
- var import_react14 = require("react");
2005
- var import_jsx_runtime10 = require("react/jsx-runtime");
2006
- var markIcons = {
2007
- bold: import_icons12.BoldIcon,
2008
- italic: import_icons12.ItalicIcon,
2009
- underline: import_icons12.UnderlineIcon,
2010
- strike: import_icons12.StrikeIcon,
2011
- code: import_icons12.CodeIcon,
2012
- superscript: import_icons12.SuperscriptIcon,
2013
- subscript: import_icons12.SubscriptIcon
2014
- };
2015
- var markShortcutKeys = {
2016
- bold: "mod+b",
2017
- italic: "mod+i",
2018
- underline: "mod+u",
2019
- strike: "mod+shift+s",
2020
- code: "mod+e",
2021
- superscript: "mod+.",
2022
- subscript: "mod+,"
2023
- };
2024
- function canToggleMark(editor, type) {
2025
- if (!editor || !editor.isEditable) return false;
2026
- if (!(0, import_editor_utils9.isMarkInSchema)(type, editor) || (0, import_editor_utils9.isNodeTypeSelected)(editor, ["image"]))
2027
- return false;
2028
- return editor.can().toggleMark(type);
2029
- }
2030
- function isMarkActive(editor, type) {
2031
- if (!editor) return false;
2032
- return editor.isActive(type);
2033
- }
2034
- function toggleMark(editor, type) {
2035
- if (!editor) return;
2036
- editor.chain().focus().toggleMark(type).run();
2037
- }
2038
- function isMarkButtonDisabled(editor, type, userDisabled = false) {
2039
- if (!editor) return true;
2040
- if (userDisabled) return true;
2041
- if (editor.isActive("codeBlock")) return true;
2042
- if (!canToggleMark(editor, type)) return true;
2043
- return false;
2044
- }
2045
- function shouldShowMarkButton(params) {
2046
- const { editor, type, hideWhenUnavailable, markInSchema } = params;
2047
- if (!markInSchema || !editor) {
2048
- return false;
2049
- }
2050
- if (hideWhenUnavailable) {
2051
- if ((0, import_react13.isNodeSelection)(editor.state.selection) || !canToggleMark(editor, type)) {
2052
- return false;
2053
- }
2054
- }
2055
- return true;
2056
- }
2057
- function getFormattedMarkName(type) {
2058
- return type.charAt(0).toUpperCase() + type.slice(1);
2059
- }
2060
- function useMarkState(editor, type, disabled = false) {
2061
- const markInSchema = (0, import_editor_utils9.isMarkInSchema)(type, editor);
2062
- const isDisabled = isMarkButtonDisabled(editor, type, disabled);
2063
- const isActive = isMarkActive(editor, type);
2064
- const Icon = markIcons[type];
2065
- const shortcutKey = markShortcutKeys[type];
2066
- const formattedName = getFormattedMarkName(type);
2067
- return {
2068
- markInSchema,
2069
- isDisabled,
2070
- isActive,
2071
- Icon,
2072
- shortcutKey,
2073
- formattedName
2074
- };
2075
- }
2076
- var MarkButton = ({
2077
- editor: providedEditor,
2078
- type,
2079
- text,
2080
- hideWhenUnavailable = false,
2081
- className = "",
2082
- disabled,
2083
- onClick,
2084
- children,
2085
- ...buttonProps
2086
- }) => {
2087
- const { editor } = useTiptapEditor(providedEditor);
2088
- const {
2089
- markInSchema,
2090
- isDisabled,
2091
- isActive,
2092
- Icon,
2093
- shortcutKey,
2094
- formattedName
2095
- } = useMarkState(editor, type, disabled);
2096
- const handleClick = (0, import_react14.useCallback)(
2097
- (e) => {
2098
- onClick == null ? void 0 : onClick(e);
2099
- if (!e.defaultPrevented && !isDisabled && editor) {
2100
- toggleMark(editor, type);
2101
- }
2102
- },
2103
- [onClick, isDisabled, editor, type]
2104
- );
2105
- const show = (0, import_react14.useMemo)(() => {
2106
- return shouldShowMarkButton({
2107
- editor,
2108
- type,
2109
- hideWhenUnavailable,
2110
- markInSchema
2111
- });
2112
- }, [editor, type, hideWhenUnavailable, markInSchema]);
2113
- if (!show || !editor || !editor.isEditable) {
2114
- return null;
2115
- }
2116
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2117
- import_toolbar6.ToolbarButton,
2118
- {
2119
- type: "button",
2120
- className: className.trim(),
2121
- disabled: isDisabled,
2122
- variant: "ghost",
2123
- color: "default",
2124
- "data-active-state": isActive ? "on" : "off",
2125
- "data-disabled": isDisabled,
2126
- tabIndex: -1,
2127
- "aria-label": type,
2128
- "aria-pressed": isActive,
2129
- title: formattedName,
2130
- shortcutKeys: shortcutKey,
2131
- onClick: handleClick,
2132
- isIconOnly: true,
2133
- ...buttonProps,
2134
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, {})
2135
- }
2136
- );
2137
- };
2138
-
2139
- // src/ui/table-button/index.tsx
2140
- var import_toolbar7 = require("@kopexa/toolbar");
2141
- var import_react17 = require("react");
2142
-
2143
- // src/ui/table-button/use-table.ts
2144
- var import_editor_utils10 = require("@kopexa/editor-utils");
2145
- var import_icons13 = require("@kopexa/icons");
2146
- var import_react15 = require("@tiptap/react");
2147
- var import_react16 = require("react");
2148
- function canToggle2(editor) {
2149
- if (!editor || !editor.isEditable) return false;
2150
- if (!(0, import_editor_utils10.isNodeInSchema)("table", editor) || (0, import_editor_utils10.isNodeTypeSelected)(editor, ["image"])) {
2151
- return false;
2152
- }
2153
- try {
2154
- return editor.can().insertTable({ rows: 3, cols: 3, withHeaderRow: true });
2155
- } catch {
2156
- return false;
2157
- }
2158
- }
2159
- function toggleTable(editor, config) {
2160
- var _a;
2161
- if (!editor || !editor.isEditable) return false;
2162
- if (!canToggle2(editor)) return false;
2163
- try {
2164
- return editor.chain().focus().insertTable({
2165
- rows: (config == null ? void 0 : config.rows) || 3,
2166
- cols: (config == null ? void 0 : config.cols) || 3,
2167
- withHeaderRow: (_a = config == null ? void 0 : config.withHeaderRow) != null ? _a : true
2168
- }).run();
2169
- } catch {
2170
- return false;
2171
- }
2172
- }
2173
- function shouldShowButton4(props) {
2174
- const { editor, hideWhenUnavailable } = props;
2175
- if (!editor || !editor.isEditable) return false;
2176
- if (!(0, import_editor_utils10.isNodeInSchema)("table", editor)) return false;
2177
- if (hideWhenUnavailable) {
2178
- if ((0, import_react15.isNodeSelection)(editor.state.selection) || !canToggle2) {
2179
- return false;
2180
- }
2181
- }
2182
- return true;
2183
- }
2184
- function useTableBlock(config) {
2185
- const {
2186
- editor: providedEditor,
2187
- hideWhenUnavailable = false,
2188
- onToggled
2189
- } = config || {};
2190
- const { editor } = useTiptapEditor(providedEditor);
2191
- const [isVisible, setIsVisible] = (0, import_react16.useState)(true);
2192
- const canToggleState = canToggle2(editor);
2193
- const isActive = (editor == null ? void 0 : editor.isActive("table")) || false;
2194
- (0, import_react16.useEffect)(() => {
2195
- if (!editor) return;
2196
- const handleSelectionUpdate = () => {
2197
- setIsVisible(shouldShowButton4({ editor, hideWhenUnavailable }));
2198
- };
2199
- handleSelectionUpdate();
2200
- editor.on("selectionUpdate", handleSelectionUpdate);
2201
- return () => {
2202
- editor.off("selectionUpdate", handleSelectionUpdate);
2203
- };
2204
- }, [editor, hideWhenUnavailable]);
2205
- const handleToggle = (0, import_react16.useCallback)(() => {
2206
- if (!editor) return false;
2207
- const success = toggleTable(editor);
2208
- if (success) {
2209
- onToggled == null ? void 0 : onToggled();
2210
- }
2211
- return success;
2212
- }, [editor, onToggled]);
2213
- return {
2214
- isVisible,
2215
- isActive,
2216
- handleToggle,
2217
- canToggle: canToggleState,
2218
- label: "Table",
2219
- // shortcutKeys: CODE_BLOCK_SHORTCUT_KEY,
2220
- Icon: import_icons13.TableIcon
2221
- };
2222
- }
2223
-
2224
- // src/ui/table-button/index.tsx
2225
- var import_jsx_runtime11 = require("react/jsx-runtime");
2226
- var TableButton = ({
2227
- editor: providedEditor,
2228
- text,
2229
- hideWhenUnavailable = false,
2230
- onToggled,
2231
- onClick,
2232
- children,
2233
- ...buttonProps
2234
- }) => {
2235
- const { editor } = useTiptapEditor(providedEditor);
2236
- const {
2237
- isVisible,
2238
- canToggle: canToggle3,
2239
- isActive,
2240
- handleToggle,
2241
- label,
2242
- // shortcutKeys,
2243
- Icon
2244
- } = useTableBlock({
2245
- editor,
2246
- hideWhenUnavailable,
2247
- onToggled
2248
- });
2249
- const handleClick = (0, import_react17.useCallback)(
2250
- (event) => {
2251
- onClick == null ? void 0 : onClick(event);
2252
- if (event.defaultPrevented) return;
2253
- handleToggle();
2254
- },
2255
- [handleToggle, onClick]
2256
- );
2257
- if (!isVisible) {
2258
- return null;
2259
- }
2260
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2261
- import_toolbar7.ToolbarButton,
2262
- {
2263
- type: "button",
2264
- variant: "ghost",
2265
- color: "default",
2266
- "data-active-state": isActive ? "on" : "off",
2267
- disabled: !canToggle3,
2268
- "data-disabled": !canToggle3,
2269
- tabIndex: -1,
2270
- "aria-label": label,
2271
- "aria-pressed": isActive,
2272
- title: label,
2273
- onClick: handleClick,
2274
- isIconOnly: !text && !children,
2275
- ...buttonProps,
2276
- children: children || /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2277
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Icon, {}),
2278
- text && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { children: text })
2279
- ] })
2280
- }
2281
- );
2282
- };
2283
-
2284
- // src/ui/text-align-button/text-align-button.tsx
2285
- var import_button7 = require("@kopexa/button");
2286
- var import_react19 = require("react");
2287
-
2288
- // src/ui/text-align-button/use-text-align.ts
2289
- var import_editor_utils11 = require("@kopexa/editor-utils");
2290
- var import_icons14 = require("@kopexa/icons");
2291
- var import_react18 = require("react");
2292
- var TEXT_ALIGN_SHORTCUT_KEYS = {
2293
- left: "mod+shift+l",
2294
- center: "mod+shift+e",
2295
- right: "mod+shift+r",
2296
- justify: "mod+shift+j"
2297
- };
2298
- var textAlignIcons = {
2299
- left: import_icons14.AlignLeftIcon,
2300
- center: import_icons14.AlignCenterIcon,
2301
- right: import_icons14.AlignRightIcon,
2302
- justify: import_icons14.AlignJustifyIcon
2303
- };
2304
- var textAlignLabels = {
2305
- left: "Align left",
2306
- center: "Align center",
2307
- right: "Align right",
2308
- justify: "Align justify"
2309
- };
2310
- function canSetTextAlign(editor, align) {
2311
- if (!editor || !editor.isEditable) return false;
2312
- if (!(0, import_editor_utils11.isExtensionAvailable)(editor, "textAlign") || (0, import_editor_utils11.isNodeTypeSelected)(editor, ["image"]))
2313
- return false;
2314
- return editor.can().setTextAlign(align);
2315
- }
2316
- function hasSetTextAlign(commands) {
2317
- return "setTextAlign" in commands;
2318
- }
2319
- function isTextAlignActive(editor, align) {
2320
- if (!editor || !editor.isEditable) return false;
2321
- return editor.isActive({ textAlign: align });
2322
- }
2323
- function setTextAlign(editor, align) {
2324
- if (!editor || !editor.isEditable) return false;
2325
- if (!canSetTextAlign(editor, align)) return false;
2326
- const chain = editor.chain().focus();
2327
- if (hasSetTextAlign(chain)) {
2328
- return chain.setTextAlign(align).run();
2329
- }
2330
- return false;
2331
- }
2332
- function shouldShowButton5(props) {
2333
- const { editor, hideWhenUnavailable, align } = props;
2334
- if (!editor || !editor.isEditable) return false;
2335
- if (!(0, import_editor_utils11.isExtensionAvailable)(editor, "textAlign")) return false;
2336
- if (hideWhenUnavailable && !editor.isActive("code")) {
2337
- return canSetTextAlign(editor, align);
2338
- }
2339
- return true;
2340
- }
2341
- function useTextAlign(config) {
2342
- const {
2343
- editor: providedEditor,
2344
- align,
2345
- hideWhenUnavailable = false,
2346
- onAligned
2347
- } = config;
2348
- const { editor } = useTiptapEditor(providedEditor);
2349
- const [isVisible, setIsVisible] = (0, import_react18.useState)(true);
2350
- const canAlign = canSetTextAlign(editor, align);
2351
- const isActive = isTextAlignActive(editor, align);
2352
- (0, import_react18.useEffect)(() => {
2353
- if (!editor) return;
2354
- const handleSelectionUpdate = () => {
2355
- setIsVisible(shouldShowButton5({ editor, align, hideWhenUnavailable }));
2356
- };
2357
- handleSelectionUpdate();
2358
- editor.on("selectionUpdate", handleSelectionUpdate);
2359
- return () => {
2360
- editor.off("selectionUpdate", handleSelectionUpdate);
2361
- };
2362
- }, [editor, hideWhenUnavailable, align]);
2363
- const handleTextAlign = (0, import_react18.useCallback)(() => {
2364
- if (!editor) return false;
2365
- const success = setTextAlign(editor, align);
2366
- if (success) {
2367
- onAligned == null ? void 0 : onAligned();
2368
- }
2369
- return success;
2370
- }, [editor, align, onAligned]);
2371
- return {
2372
- isVisible,
2373
- isActive,
2374
- handleTextAlign,
2375
- canAlign,
2376
- label: textAlignLabels[align],
2377
- shortcutKeys: TEXT_ALIGN_SHORTCUT_KEYS[align],
2378
- Icon: textAlignIcons[align]
2379
- };
2380
- }
2381
-
2382
- // src/ui/text-align-button/text-align-button.tsx
2383
- var import_jsx_runtime12 = require("react/jsx-runtime");
2384
- var TextAlignButton = ({
2385
- editor: providedEditor,
2386
- align,
2387
- text,
2388
- hideWhenUnavailable = false,
2389
- onAligned,
2390
- showShortcut = false,
2391
- onClick,
2392
- children,
2393
- ...buttonProps
2394
- }) => {
2395
- const { editor } = useTiptapEditor(providedEditor);
2396
- const {
2397
- isVisible,
2398
- handleTextAlign,
2399
- label,
2400
- canAlign,
2401
- isActive,
2402
- Icon,
2403
- shortcutKeys
2404
- } = useTextAlign({
2405
- editor,
2406
- align,
2407
- hideWhenUnavailable,
2408
- onAligned
2409
- });
2410
- const handleClick = (0, import_react19.useCallback)(
2411
- (e) => {
2412
- onClick == null ? void 0 : onClick(e);
2413
- if (e.defaultPrevented) return;
2414
- handleTextAlign();
2415
- },
2416
- [handleTextAlign, onClick]
2417
- );
2418
- if (!isVisible) {
2419
- return null;
2420
- }
2421
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2422
- import_button7.IconButton,
2423
- {
2424
- type: "button",
2425
- disabled: canAlign,
2426
- variant: "ghost",
2427
- color: "default",
2428
- "data-active-state": isActive ? "on" : "off",
2429
- "data-disabled": canAlign,
2430
- tabIndex: -1,
2431
- "aria-label": label,
2432
- "aria-pressed": isActive,
2433
- tooltip: label,
2434
- shortcutKeys,
2435
- onClick: handleClick,
2436
- ...buttonProps,
2437
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Icon, {})
2438
- }
2439
- );
2440
- };
2441
-
2442
- // src/ui/undo-redo-button/undo-redo-button.tsx
2443
- var import_toolbar8 = require("@kopexa/toolbar");
2444
- var import_react21 = require("react");
2445
-
2446
- // src/ui/undo-redo-button/use-undo-redo.ts
2447
- var import_editor_utils12 = require("@kopexa/editor-utils");
2448
- var import_icons15 = require("@kopexa/icons");
2449
- var import_react20 = require("react");
2450
- var UNDO_REDO_SHORTCUT_KEYS = {
2451
- undo: "mod+z",
2452
- redo: "mod+shift+z"
2453
- };
2454
- var historyActionLabels = {
2455
- undo: "Undo",
2456
- redo: "Redo"
2457
- };
2458
- var historyIcons = {
2459
- undo: import_icons15.UndoIcon,
2460
- redo: import_icons15.RedoIcon
2461
- };
2462
- function canExecuteUndoRedoAction(editor, action) {
2463
- if (!editor || !editor.isEditable) return false;
2464
- if ((0, import_editor_utils12.isNodeTypeSelected)(editor, ["image"])) return false;
2465
- return action === "undo" ? editor.can().undo() : editor.can().redo();
2466
- }
2467
- function executeUndoRedoAction(editor, action) {
2468
- if (!editor || !editor.isEditable) return false;
2469
- if (!canExecuteUndoRedoAction(editor, action)) return false;
2470
- const chain = editor.chain().focus();
2471
- return action === "undo" ? chain.undo().run() : chain.redo().run();
2472
- }
2473
- function shouldShowButton6(props) {
2474
- const { editor, hideWhenUnavailable, action } = props;
2475
- if (!editor || !editor.isEditable) return false;
2476
- if (hideWhenUnavailable && !editor.isActive("code")) {
2477
- return canExecuteUndoRedoAction(editor, action);
2478
- }
2479
- return true;
2480
- }
2481
- function useUndoRedo(config) {
2482
- const {
2483
- editor: providedEditor,
2484
- action,
2485
- hideWhenUnavailable = false,
2486
- onExecuted
2487
- } = config;
2488
- const { editor } = useTiptapEditor(providedEditor);
2489
- const [isVisible, setIsVisible] = (0, import_react20.useState)(true);
2490
- const canExecute = canExecuteUndoRedoAction(editor, action);
2491
- (0, import_react20.useEffect)(() => {
2492
- if (!editor) return;
2493
- const handleUpdate = () => {
2494
- setIsVisible(shouldShowButton6({ editor, hideWhenUnavailable, action }));
2495
- };
2496
- handleUpdate();
2497
- editor.on("transaction", handleUpdate);
2498
- return () => {
2499
- editor.off("transaction", handleUpdate);
2500
- };
2501
- }, [editor, hideWhenUnavailable, action]);
2502
- const handleAction = (0, import_react20.useCallback)(() => {
2503
- if (!editor) return false;
2504
- const success = executeUndoRedoAction(editor, action);
2505
- if (success) {
2506
- onExecuted == null ? void 0 : onExecuted();
2507
- }
2508
- return success;
2509
- }, [editor, action, onExecuted]);
2510
- return {
2511
- isVisible,
2512
- handleAction,
2513
- canExecute,
2514
- label: historyActionLabels[action],
2515
- shortcutKeys: UNDO_REDO_SHORTCUT_KEYS[action],
2516
- Icon: historyIcons[action]
2517
- };
2518
- }
2519
-
2520
- // src/ui/undo-redo-button/undo-redo-button.tsx
2521
- var import_jsx_runtime13 = require("react/jsx-runtime");
2522
- var UndoRedoButton = ({
2523
- editor: providedEditor,
2524
- action,
2525
- text,
2526
- hideWhenUnavailable = false,
2527
- onExecuted,
2528
- showShortcut = false,
2529
- onClick,
2530
- children,
2531
- ...buttonProps
2532
- }) => {
2533
- const { editor } = useTiptapEditor(providedEditor);
2534
- const { isVisible, handleAction, label, canExecute, Icon, shortcutKeys } = useUndoRedo({
2535
- editor,
2536
- action,
2537
- hideWhenUnavailable,
2538
- onExecuted
2539
- });
2540
- const handleClick = (0, import_react21.useCallback)(
2541
- (event) => {
2542
- onClick == null ? void 0 : onClick(event);
2543
- if (event.defaultPrevented) return;
2544
- handleAction();
2545
- },
2546
- [handleAction, onClick]
2547
- );
2548
- if (!isVisible) {
2549
- return null;
2550
- }
2551
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2552
- import_toolbar8.ToolbarButton,
2553
- {
2554
- type: "button",
2555
- variant: "ghost",
2556
- color: "default",
2557
- disabled: !canExecute,
2558
- "data-disabled": !canExecute,
2559
- tabIndex: -1,
2560
- "aria-label": label,
2561
- title: label,
2562
- shortcutKeys,
2563
- onClick: handleClick,
2564
- isIconOnly: true,
2565
- ...buttonProps,
2566
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, {})
2567
- }
2568
- );
2569
- };
2570
-
2571
- // src/presets/basic/editor-header.tsx
2572
- var import_jsx_runtime14 = require("react/jsx-runtime");
2573
- var EditorHeader = ({
2574
- editor: providedEditor,
2575
- variant
2576
- }) => {
2577
- var _a, _b;
2578
- const { editor } = useTiptapEditor(providedEditor);
2579
- const isMobile = (0, import_use_is_mobile2.useIsMobile)();
2580
- const windowSize = useWindowSize();
2581
- const { styles } = useEditorUIContext();
2582
- const toolbarRef = (0, import_react22.useRef)(null);
2583
- const bodyRect = useCursorVisibility({
2584
- editor,
2585
- overlayHeight: (_b = (_a = toolbarRef.current) == null ? void 0 : _a.getBoundingClientRect().height) != null ? _b : 0
2586
- });
2587
- if (!(editor == null ? void 0 : editor.isEditable)) {
2588
- return null;
2589
- }
2590
- const ToolbarContent = variant === "comment" ? CommentToolbarContent : variant === "field" ? FieldToolbarContent : MainToolbarContent;
2591
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: styles.toolbarContainer(), "data-slot": "editor-toolbar", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2592
- import_toolbar9.Toolbar,
2593
- {
2594
- sticky: true,
2595
- radius: "none",
2596
- border: "none",
2597
- style: isMobile ? {
2598
- bottom: `calc(100% - ${windowSize.height - bodyRect.y}px)`
2599
- } : {},
2600
- className: styles.toolbar(),
2601
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ToolbarContent, {})
2602
- }
2603
- ) });
2604
- };
2605
- var MainToolbarContent = () => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2606
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2607
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(UndoRedoButton, { action: "undo" }),
2608
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(UndoRedoButton, { action: "redo" })
2609
- ] }),
2610
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarSeparator, {}),
2611
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2612
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(HeadingDropdownMenu, { levels: [1, 2, 3, 4] }),
2613
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ListDropdownMenu, { types: ["bulletList", "orderedList", "taskList"] }),
2614
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BlockquoteButton, {}),
2615
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CodeBlockButton, {})
2616
- ] }),
2617
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarSeparator, {}),
2618
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2619
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "bold" }),
2620
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "italic" }),
2621
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "strike" }),
2622
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "code" }),
2623
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "underline" }),
2624
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ColorHighlightPopover, {}),
2625
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(LinkPopover, {})
2626
- ] }),
2627
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarSeparator, {}),
2628
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TableButton, {}) }),
2629
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MoreOptions, { hideWhenUnavailable: true })
2630
- ] });
2631
- var CommentToolbarContent = () => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2632
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2633
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "bold" }),
2634
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "italic" }),
2635
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "strike" }),
2636
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "code" })
2637
- ] }),
2638
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarSeparator, {}),
2639
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2640
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(LinkPopover, {}),
2641
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ListDropdownMenu, { types: ["bulletList", "orderedList"] })
2642
- ] })
2643
- ] });
2644
- var FieldToolbarContent = () => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2645
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "bold" }),
2646
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "italic" }),
2647
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "strike" }),
2648
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(LinkPopover, {})
2649
- ] });
2650
- function MoreOptions({
2651
- editor: providedEditor,
2652
- hideWhenUnavailable = false,
2653
- ...props
2654
- }) {
2655
- const { editor } = useTiptapEditor(providedEditor);
2656
- const [show, setShow] = (0, import_react22.useState)(false);
2657
- (0, import_react22.useEffect)(() => {
2658
- if (!editor) return;
2659
- const handleSelectionUpdate = () => {
2660
- setShow(
2661
- shouldShowMoreOptions({
2662
- editor,
2663
- hideWhenUnavailable
2664
- })
2665
- );
2666
- };
2667
- handleSelectionUpdate();
2668
- editor.on("selectionUpdate", handleSelectionUpdate);
2669
- return () => {
2670
- editor.off("selectionUpdate", handleSelectionUpdate);
2671
- };
2672
- }, [editor, hideWhenUnavailable]);
2673
- if (!show || !editor || !editor.isEditable) {
2674
- return null;
2675
- }
2676
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2677
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarSeparator, {}),
2678
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_popover3.Popover.Root, { spacing: "dense", width: "auto", children: [
2679
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2680
- import_popover3.Popover.Trigger,
2681
- {
2682
- render: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2683
- import_toolbar9.ToolbarButton,
2684
- {
2685
- type: "button",
2686
- variant: "ghost",
2687
- color: "default",
2688
- tabIndex: -1,
2689
- size: "md",
2690
- "aria-label": "More options",
2691
- title: "More options",
2692
- isIconOnly: true,
2693
- ...props,
2694
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons16.MoreVerticalIcon, {})
2695
- }
2696
- )
2697
- }
2698
- ),
2699
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2700
- import_popover3.Popover.Content,
2701
- {
2702
- side: "top",
2703
- align: "end",
2704
- alignOffset: 4,
2705
- sideOffset: 4,
2706
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.Toolbar, { children: [
2707
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2708
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "superscript" }),
2709
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MarkButton, { type: "subscript" })
2710
- ] }),
2711
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_toolbar9.ToolbarSeparator, {}),
2712
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_toolbar9.ToolbarGroup, { children: [
2713
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TextAlignButton, { align: "left" }),
2714
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TextAlignButton, { align: "center" }),
2715
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TextAlignButton, { align: "right" }),
2716
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TextAlignButton, { align: "justify" })
2717
- ] })
2718
- ] })
2719
- }
2720
- )
2721
- ] }) })
2722
- ] });
2723
- }
2724
- function canMoreOptions(editor) {
2725
- if (!editor) {
2726
- return false;
2727
- }
2728
- const canTextAlignAny = ["left", "center", "right", "justify"].some(
2729
- (align) => canSetTextAlign(editor, align)
2730
- );
2731
- const canMarkAny = ["superscript", "subscript"].some(
2732
- (type) => canToggleMark(editor, type)
2733
- );
2734
- return canMarkAny || canTextAlignAny;
2735
- }
2736
- function shouldShowMoreOptions(params) {
2737
- const { editor, hideWhenUnavailable } = params;
2738
- if (!editor) {
2739
- return false;
2740
- }
2741
- if (hideWhenUnavailable && !editor.isActive("code")) {
2742
- return canMoreOptions(editor);
2743
- }
2744
- return Boolean(editor == null ? void 0 : editor.isEditable);
2745
- }
2746
- // Annotate the CommonJS export names for ESM import in node:
2747
- 0 && (module.exports = {
2748
- EditorHeader,
2749
- MoreOptions
2750
- });