@use-kona/editor 0.1.0-rc.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 (401) hide show
  1. package/README.md +23 -0
  2. package/dist/constants.d.ts +1 -0
  3. package/dist/constants.js +2 -0
  4. package/dist/core/createEditable.d.ts +7 -0
  5. package/dist/core/createEditable.js +110 -0
  6. package/dist/core/createEditor.d.ts +2 -0
  7. package/dist/core/createEditor.js +167 -0
  8. package/dist/core/deserialize.d.ts +3 -0
  9. package/dist/core/deserialize.js +33 -0
  10. package/dist/core/queries.d.ts +2 -0
  11. package/dist/core/queries.js +10 -0
  12. package/dist/core/serialize.d.ts +3 -0
  13. package/dist/core/serialize.js +13 -0
  14. package/dist/core/styles.module.js +6 -0
  15. package/dist/core/styles_module.css +29 -0
  16. package/dist/defaultValue.d.ts +4 -0
  17. package/dist/defaultValue.js +13 -0
  18. package/dist/editor.d.ts +10 -0
  19. package/dist/editor.js +43 -0
  20. package/dist/elements/BaseElement.d.ts +2 -0
  21. package/dist/elements/BaseElement.js +6 -0
  22. package/dist/examples/Backdrop.d.ts +5 -0
  23. package/dist/examples/Backdrop.js +13 -0
  24. package/dist/examples/Backdrop.module.js +5 -0
  25. package/dist/examples/Backdrop_module.css +6 -0
  26. package/dist/examples/DragBlock.d.ts +11 -0
  27. package/dist/examples/DragBlock.js +38 -0
  28. package/dist/examples/DragBlock.module.js +9 -0
  29. package/dist/examples/DragBlock_module.css +43 -0
  30. package/dist/examples/DragHandler.d.ts +2 -0
  31. package/dist/examples/DragHandler.js +44 -0
  32. package/dist/examples/DragHandler.module.js +8 -0
  33. package/dist/examples/DragHandler_module.css +18 -0
  34. package/dist/examples/Editor.d.ts +2 -0
  35. package/dist/examples/Editor.js +23 -0
  36. package/dist/examples/Editor.module.js +12 -0
  37. package/dist/examples/Editor_module.css +128 -0
  38. package/dist/examples/FloatingMenu.d.ts +17 -0
  39. package/dist/examples/FloatingMenu.js +244 -0
  40. package/dist/examples/FloatingMenu.module.js +9 -0
  41. package/dist/examples/FloatingMenu_module.css +75 -0
  42. package/dist/examples/LanguageSelector.d.ts +10 -0
  43. package/dist/examples/LanguageSelector.js +154 -0
  44. package/dist/examples/LanguageSelector.module.js +7 -0
  45. package/dist/examples/LanguageSelector_module.css +52 -0
  46. package/dist/examples/LinksHint.d.ts +7 -0
  47. package/dist/examples/LinksHint.js +50 -0
  48. package/dist/examples/LinksHint.module.js +6 -0
  49. package/dist/examples/LinksHint_module.css +28 -0
  50. package/dist/examples/Menu.d.ts +6 -0
  51. package/dist/examples/Menu.js +79 -0
  52. package/dist/examples/Menu.module.js +8 -0
  53. package/dist/examples/Menu_module.css +38 -0
  54. package/dist/examples/colors.d.ts +10 -0
  55. package/dist/examples/colors.js +12 -0
  56. package/dist/examples/getCommands.d.ts +2 -0
  57. package/dist/examples/getCommands.js +87 -0
  58. package/dist/examples/getPlugins.d.ts +2 -0
  59. package/dist/examples/getPlugins.js +127 -0
  60. package/dist/examples/getShortcuts.d.ts +2 -0
  61. package/dist/examples/getShortcuts.js +90 -0
  62. package/dist/examples/icons/bold.d.ts +2 -0
  63. package/dist/examples/icons/bold.js +27 -0
  64. package/dist/examples/icons/check.d.ts +2 -0
  65. package/dist/examples/icons/check.js +24 -0
  66. package/dist/examples/icons/chevronRight.d.ts +2 -0
  67. package/dist/examples/icons/chevronRight.js +24 -0
  68. package/dist/examples/icons/color.d.ts +2 -0
  69. package/dist/examples/icons/color.js +30 -0
  70. package/dist/examples/icons/copy.d.ts +2 -0
  71. package/dist/examples/icons/copy.js +27 -0
  72. package/dist/examples/icons/cross.d.ts +2 -0
  73. package/dist/examples/icons/cross.js +27 -0
  74. package/dist/examples/icons/drag.d.ts +2 -0
  75. package/dist/examples/icons/drag.js +39 -0
  76. package/dist/examples/icons/edit.d.ts +2 -0
  77. package/dist/examples/icons/edit.js +30 -0
  78. package/dist/examples/icons/external.d.ts +2 -0
  79. package/dist/examples/icons/external.js +30 -0
  80. package/dist/examples/icons/heading1.d.ts +2 -0
  81. package/dist/examples/icons/heading1.js +45 -0
  82. package/dist/examples/icons/heading2.d.ts +2 -0
  83. package/dist/examples/icons/heading2.js +45 -0
  84. package/dist/examples/icons/heading3.d.ts +2 -0
  85. package/dist/examples/icons/heading3.js +48 -0
  86. package/dist/examples/icons/italic.d.ts +2 -0
  87. package/dist/examples/icons/italic.js +30 -0
  88. package/dist/examples/icons/link.d.ts +2 -0
  89. package/dist/examples/icons/link.js +30 -0
  90. package/dist/examples/icons/ol.d.ts +2 -0
  91. package/dist/examples/icons/ol.js +36 -0
  92. package/dist/examples/icons/strikethrough.d.ts +2 -0
  93. package/dist/examples/icons/strikethrough.js +27 -0
  94. package/dist/examples/icons/text.d.ts +2 -0
  95. package/dist/examples/icons/text.js +22 -0
  96. package/dist/examples/icons/types.d.ts +3 -0
  97. package/dist/examples/icons/types.js +0 -0
  98. package/dist/examples/icons/ul.d.ts +2 -0
  99. package/dist/examples/icons/ul.js +39 -0
  100. package/dist/examples/icons/underline.d.ts +2 -0
  101. package/dist/examples/icons/underline.js +27 -0
  102. package/dist/examples/store.d.ts +8 -0
  103. package/dist/examples/store.js +6 -0
  104. package/dist/examples/styles.module.js +11 -0
  105. package/dist/examples/styles_module.css +78 -0
  106. package/dist/examples/text.d.ts +3 -0
  107. package/dist/examples/text.js +60 -0
  108. package/dist/examples/ui/Button/Button.d.ts +8 -0
  109. package/dist/examples/ui/Button/Button.js +15 -0
  110. package/dist/examples/ui/Button/ButtonWrapper.d.ts +4 -0
  111. package/dist/examples/ui/Button/ButtonWrapper.js +14 -0
  112. package/dist/examples/ui/Button/index.d.ts +2 -0
  113. package/dist/examples/ui/Button/index.js +3 -0
  114. package/dist/examples/ui/Button/styles.module.js +10 -0
  115. package/dist/examples/ui/Button/styles_module.css +72 -0
  116. package/dist/examples/ui/Button/types.d.ts +1 -0
  117. package/dist/examples/ui/Button/types.js +0 -0
  118. package/dist/examples/ui/Dropdown/Dropdown.d.ts +16 -0
  119. package/dist/examples/ui/Dropdown/Dropdown.js +75 -0
  120. package/dist/examples/ui/Dropdown/index.d.ts +1 -0
  121. package/dist/examples/ui/Dropdown/index.js +2 -0
  122. package/dist/examples/ui/Menu/Menu.d.ts +41 -0
  123. package/dist/examples/ui/Menu/Menu.js +404 -0
  124. package/dist/examples/ui/Menu/MenuDelimiter.d.ts +1 -0
  125. package/dist/examples/ui/Menu/MenuDelimiter.js +6 -0
  126. package/dist/examples/ui/Menu/MenuHotkey.d.ts +6 -0
  127. package/dist/examples/ui/Menu/MenuHotkey.js +12 -0
  128. package/dist/examples/ui/Menu/MenuIcon.d.ts +6 -0
  129. package/dist/examples/ui/Menu/MenuIcon.js +12 -0
  130. package/dist/examples/ui/Menu/MenuItem.d.ts +6 -0
  131. package/dist/examples/ui/Menu/MenuItem.js +17 -0
  132. package/dist/examples/ui/Menu/MenuTitle.d.ts +6 -0
  133. package/dist/examples/ui/Menu/MenuTitle.js +12 -0
  134. package/dist/examples/ui/Menu/SafeSpace.d.ts +6 -0
  135. package/dist/examples/ui/Menu/SafeSpace.js +65 -0
  136. package/dist/examples/ui/Menu/index.d.ts +2 -0
  137. package/dist/examples/ui/Menu/index.js +2 -0
  138. package/dist/examples/ui/Menu/styles.module.js +21 -0
  139. package/dist/examples/ui/Menu/styles_module.css +140 -0
  140. package/dist/examples/ui/Menu/types.d.ts +16 -0
  141. package/dist/examples/ui/Menu/types.js +0 -0
  142. package/dist/examples/ui/useMenuPosition.d.ts +18 -0
  143. package/dist/examples/ui/useMenuPosition.js +51 -0
  144. package/dist/examples/ui/useMergeRefs.d.ts +23 -0
  145. package/dist/examples/ui/useMergeRefs.js +11 -0
  146. package/dist/index.d.ts +2 -0
  147. package/dist/index.js +3 -0
  148. package/dist/plugins/AttachmentsPlugin/AttachmentsPlugin.d.ts +17 -0
  149. package/dist/plugins/AttachmentsPlugin/AttachmentsPlugin.js +37 -0
  150. package/dist/plugins/AttachmentsPlugin/index.d.ts +1 -0
  151. package/dist/plugins/AttachmentsPlugin/index.js +2 -0
  152. package/dist/plugins/AttachmentsPlugin/types.d.ts +11 -0
  153. package/dist/plugins/AttachmentsPlugin/types.js +0 -0
  154. package/dist/plugins/BasicFormattingPlugin/BasicFormattingPlugin.d.ts +20 -0
  155. package/dist/plugins/BasicFormattingPlugin/BasicFormattingPlugin.js +76 -0
  156. package/dist/plugins/BasicFormattingPlugin/index.d.ts +1 -0
  157. package/dist/plugins/BasicFormattingPlugin/index.js +2 -0
  158. package/dist/plugins/BreaksPlugin/BreaksPlugin.d.ts +15 -0
  159. package/dist/plugins/BreaksPlugin/BreaksPlugin.js +50 -0
  160. package/dist/plugins/BreaksPlugin/index.d.ts +1 -0
  161. package/dist/plugins/BreaksPlugin/index.js +2 -0
  162. package/dist/plugins/CodeBlockPlugin/CodeBlock.d.ts +9 -0
  163. package/dist/plugins/CodeBlockPlugin/CodeBlock.js +18 -0
  164. package/dist/plugins/CodeBlockPlugin/CodeBlockLine.d.ts +2 -0
  165. package/dist/plugins/CodeBlockPlugin/CodeBlockLine.js +9 -0
  166. package/dist/plugins/CodeBlockPlugin/CodeBlockPlugin.d.ts +55 -0
  167. package/dist/plugins/CodeBlockPlugin/CodeBlockPlugin.js +224 -0
  168. package/dist/plugins/CodeBlockPlugin/index.d.ts +1 -0
  169. package/dist/plugins/CodeBlockPlugin/index.js +2 -0
  170. package/dist/plugins/CodeBlockPlugin/styles.module.js +6 -0
  171. package/dist/plugins/CodeBlockPlugin/styles_module.css +12 -0
  172. package/dist/plugins/CodeBlockPlugin/types.d.ts +8 -0
  173. package/dist/plugins/CodeBlockPlugin/types.js +0 -0
  174. package/dist/plugins/CodeBlockPlugin/utils.d.ts +13 -0
  175. package/dist/plugins/CodeBlockPlugin/utils.js +87 -0
  176. package/dist/plugins/CommandsPlugin/CommandsPlugin.d.ts +11 -0
  177. package/dist/plugins/CommandsPlugin/CommandsPlugin.js +65 -0
  178. package/dist/plugins/CommandsPlugin/Menu.d.ts +11 -0
  179. package/dist/plugins/CommandsPlugin/Menu.js +153 -0
  180. package/dist/plugins/CommandsPlugin/actions.d.ts +7 -0
  181. package/dist/plugins/CommandsPlugin/actions.js +29 -0
  182. package/dist/plugins/CommandsPlugin/index.d.ts +2 -0
  183. package/dist/plugins/CommandsPlugin/index.js +2 -0
  184. package/dist/plugins/CommandsPlugin/styles.module.js +9 -0
  185. package/dist/plugins/CommandsPlugin/styles_module.css +66 -0
  186. package/dist/plugins/CommandsPlugin/types.d.ts +27 -0
  187. package/dist/plugins/CommandsPlugin/types.js +0 -0
  188. package/dist/plugins/DnDPlugin/DnDPlugin.d.ts +33 -0
  189. package/dist/plugins/DnDPlugin/DnDPlugin.js +110 -0
  190. package/dist/plugins/DnDPlugin/index.d.ts +1 -0
  191. package/dist/plugins/DnDPlugin/index.js +2 -0
  192. package/dist/plugins/DnDPlugin/styles.module.js +9 -0
  193. package/dist/plugins/DnDPlugin/styles_module.css +43 -0
  194. package/dist/plugins/FloatingMenuPlugin/FloatingMenu.d.ts +9 -0
  195. package/dist/plugins/FloatingMenuPlugin/FloatingMenu.js +89 -0
  196. package/dist/plugins/FloatingMenuPlugin/FloatingMenuPlugin.d.ts +15 -0
  197. package/dist/plugins/FloatingMenuPlugin/FloatingMenuPlugin.js +36 -0
  198. package/dist/plugins/FloatingMenuPlugin/index.d.ts +2 -0
  199. package/dist/plugins/FloatingMenuPlugin/index.js +2 -0
  200. package/dist/plugins/FloatingMenuPlugin/styles.module.js +7 -0
  201. package/dist/plugins/FloatingMenuPlugin/styles_module.css +23 -0
  202. package/dist/plugins/FloatingMenuPlugin/types.d.ts +16 -0
  203. package/dist/plugins/FloatingMenuPlugin/types.js +0 -0
  204. package/dist/plugins/HeadingsPlugin/HeadingsPlugin.d.ts +19 -0
  205. package/dist/plugins/HeadingsPlugin/HeadingsPlugin.js +64 -0
  206. package/dist/plugins/HeadingsPlugin/index.d.ts +1 -0
  207. package/dist/plugins/HeadingsPlugin/index.js +2 -0
  208. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.d.ts +16 -0
  209. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.js +36 -0
  210. package/dist/plugins/HighlightsPlugin/index.d.ts +1 -0
  211. package/dist/plugins/HighlightsPlugin/index.js +2 -0
  212. package/dist/plugins/LinksPlugin/Link.d.ts +11 -0
  213. package/dist/plugins/LinksPlugin/Link.js +89 -0
  214. package/dist/plugins/LinksPlugin/LinksPlugin.d.ts +17 -0
  215. package/dist/plugins/LinksPlugin/LinksPlugin.js +102 -0
  216. package/dist/plugins/LinksPlugin/constants.d.ts +1 -0
  217. package/dist/plugins/LinksPlugin/constants.js +2 -0
  218. package/dist/plugins/LinksPlugin/index.d.ts +2 -0
  219. package/dist/plugins/LinksPlugin/index.js +2 -0
  220. package/dist/plugins/LinksPlugin/styles.module.js +11 -0
  221. package/dist/plugins/LinksPlugin/styles_module.css +71 -0
  222. package/dist/plugins/LinksPlugin/types.d.ts +18 -0
  223. package/dist/plugins/LinksPlugin/types.js +0 -0
  224. package/dist/plugins/ListsPlugin/ListsPlugin.d.ts +32 -0
  225. package/dist/plugins/ListsPlugin/ListsPlugin.js +218 -0
  226. package/dist/plugins/ListsPlugin/index.d.ts +1 -0
  227. package/dist/plugins/ListsPlugin/index.js +2 -0
  228. package/dist/plugins/ListsPlugin/styles.module.js +6 -0
  229. package/dist/plugins/ListsPlugin/styles_module.css +8 -0
  230. package/dist/plugins/MenuPlugin/Menu.d.ts +2 -0
  231. package/dist/plugins/MenuPlugin/Menu.js +14 -0
  232. package/dist/plugins/MenuPlugin/MenuPlugin.d.ts +7 -0
  233. package/dist/plugins/MenuPlugin/MenuPlugin.js +19 -0
  234. package/dist/plugins/MenuPlugin/index.d.ts +1 -0
  235. package/dist/plugins/MenuPlugin/index.js +2 -0
  236. package/dist/plugins/MenuPlugin/styles.module.js +6 -0
  237. package/dist/plugins/MenuPlugin/styles_module.css +33 -0
  238. package/dist/plugins/MenuPlugin/types.d.ts +4 -0
  239. package/dist/plugins/MenuPlugin/types.js +0 -0
  240. package/dist/plugins/NodeIdPlugin/NodeIdPlugin.d.ts +15 -0
  241. package/dist/plugins/NodeIdPlugin/NodeIdPlugin.js +36 -0
  242. package/dist/plugins/NodeIdPlugin/index.d.ts +1 -0
  243. package/dist/plugins/NodeIdPlugin/index.js +2 -0
  244. package/dist/plugins/PlaceholderPlugin/PlaceholderPlugin.d.ts +16 -0
  245. package/dist/plugins/PlaceholderPlugin/PlaceholderPlugin.js +44 -0
  246. package/dist/plugins/PlaceholderPlugin/index.d.ts +1 -0
  247. package/dist/plugins/PlaceholderPlugin/index.js +2 -0
  248. package/dist/plugins/PlaceholderPlugin/styles.module.js +5 -0
  249. package/dist/plugins/PlaceholderPlugin/styles_module.css +14 -0
  250. package/dist/plugins/ShortcutsPlugin/ShortcutsPlugin.d.ts +24 -0
  251. package/dist/plugins/ShortcutsPlugin/ShortcutsPlugin.js +55 -0
  252. package/dist/plugins/ShortcutsPlugin/index.d.ts +2 -0
  253. package/dist/plugins/ShortcutsPlugin/index.js +2 -0
  254. package/dist/plugins/TableOfContentsPlugin/TableOfContentsPlugin.d.ts +18 -0
  255. package/dist/plugins/TableOfContentsPlugin/TableOfContentsPlugin.js +76 -0
  256. package/dist/plugins/TableOfContentsPlugin/index.d.ts +1 -0
  257. package/dist/plugins/TableOfContentsPlugin/index.js +2 -0
  258. package/dist/plugins/TableOfContentsPlugin/styles.module.js +10 -0
  259. package/dist/plugins/TableOfContentsPlugin/styles_module.css +114 -0
  260. package/dist/plugins/index.d.ts +16 -0
  261. package/dist/plugins/index.js +17 -0
  262. package/dist/queries/getMatchedGroups.d.ts +0 -0
  263. package/dist/queries/getMatchedGroups.js +0 -0
  264. package/dist/types.d.ts +50 -0
  265. package/dist/types.js +0 -0
  266. package/dist/utils.d.ts +2 -0
  267. package/dist/utils.js +8 -0
  268. package/package.json +71 -0
  269. package/src/constants.ts +1 -0
  270. package/src/core/createEditable.tsx +159 -0
  271. package/src/core/createEditor.ts +244 -0
  272. package/src/core/deserialize.ts +57 -0
  273. package/src/core/queries.ts +10 -0
  274. package/src/core/serialize.ts +38 -0
  275. package/src/core/styles.module.css +28 -0
  276. package/src/defaultValue.ts +10 -0
  277. package/src/editor.tsx +55 -0
  278. package/src/elements/BaseElement.tsx +5 -0
  279. package/src/examples/Backdrop.module.css +8 -0
  280. package/src/examples/Backdrop.tsx +16 -0
  281. package/src/examples/DragBlock.module.css +42 -0
  282. package/src/examples/DragBlock.tsx +57 -0
  283. package/src/examples/DragHandler.module.css +17 -0
  284. package/src/examples/DragHandler.tsx +39 -0
  285. package/src/examples/Editor.module.css +130 -0
  286. package/src/examples/Editor.tsx +26 -0
  287. package/src/examples/FloatingMenu.module.css +74 -0
  288. package/src/examples/FloatingMenu.tsx +274 -0
  289. package/src/examples/LanguageSelector.module.css +51 -0
  290. package/src/examples/LanguageSelector.tsx +99 -0
  291. package/src/examples/LinksHint.module.css +27 -0
  292. package/src/examples/LinksHint.tsx +58 -0
  293. package/src/examples/Menu.module.css +37 -0
  294. package/src/examples/Menu.tsx +80 -0
  295. package/src/examples/colors.ts +11 -0
  296. package/src/examples/getCommands.tsx +76 -0
  297. package/src/examples/getPlugins.tsx +143 -0
  298. package/src/examples/getShortcuts.ts +107 -0
  299. package/src/examples/icons/bold.tsx +20 -0
  300. package/src/examples/icons/check.tsx +19 -0
  301. package/src/examples/icons/chevronRight.tsx +19 -0
  302. package/src/examples/icons/color.tsx +23 -0
  303. package/src/examples/icons/copy.tsx +20 -0
  304. package/src/examples/icons/cross.tsx +20 -0
  305. package/src/examples/icons/drag.tsx +24 -0
  306. package/src/examples/icons/edit.tsx +21 -0
  307. package/src/examples/icons/external.tsx +21 -0
  308. package/src/examples/icons/heading1.tsx +26 -0
  309. package/src/examples/icons/heading2.tsx +26 -0
  310. package/src/examples/icons/heading3.tsx +27 -0
  311. package/src/examples/icons/italic.tsx +21 -0
  312. package/src/examples/icons/link.tsx +21 -0
  313. package/src/examples/icons/ol.tsx +23 -0
  314. package/src/examples/icons/strikethrough.tsx +20 -0
  315. package/src/examples/icons/text.tsx +18 -0
  316. package/src/examples/icons/types.ts +3 -0
  317. package/src/examples/icons/ul.tsx +24 -0
  318. package/src/examples/icons/underline.tsx +20 -0
  319. package/src/examples/store.ts +14 -0
  320. package/src/examples/styles.module.css +77 -0
  321. package/src/examples/text.tsx +133 -0
  322. package/src/examples/ui/Button/Button.tsx +34 -0
  323. package/src/examples/ui/Button/ButtonWrapper.tsx +22 -0
  324. package/src/examples/ui/Button/index.ts +2 -0
  325. package/src/examples/ui/Button/styles.module.css +75 -0
  326. package/src/examples/ui/Button/types.ts +1 -0
  327. package/src/examples/ui/Dropdown/Dropdown.tsx +101 -0
  328. package/src/examples/ui/Dropdown/index.ts +1 -0
  329. package/src/examples/ui/Menu/Menu.tsx +576 -0
  330. package/src/examples/ui/Menu/MenuDelimiter.tsx +3 -0
  331. package/src/examples/ui/Menu/MenuHotkey.tsx +17 -0
  332. package/src/examples/ui/Menu/MenuIcon.tsx +17 -0
  333. package/src/examples/ui/Menu/MenuItem.tsx +45 -0
  334. package/src/examples/ui/Menu/MenuTitle.tsx +17 -0
  335. package/src/examples/ui/Menu/SafeSpace.tsx +84 -0
  336. package/src/examples/ui/Menu/index.ts +2 -0
  337. package/src/examples/ui/Menu/styles.module.css +143 -0
  338. package/src/examples/ui/Menu/types.ts +18 -0
  339. package/src/examples/ui/useMenuPosition.ts +72 -0
  340. package/src/examples/ui/useMergeRefs.ts +39 -0
  341. package/src/index.ts +2 -0
  342. package/src/plugins/AttachmentsPlugin/AttachmentsPlugin.tsx +41 -0
  343. package/src/plugins/AttachmentsPlugin/index.ts +1 -0
  344. package/src/plugins/AttachmentsPlugin/types.ts +12 -0
  345. package/src/plugins/BasicFormattingPlugin/BasicFormattingPlugin.tsx +100 -0
  346. package/src/plugins/BasicFormattingPlugin/index.ts +1 -0
  347. package/src/plugins/BreaksPlugin/BreaksPlugin.tsx +70 -0
  348. package/src/plugins/BreaksPlugin/index.ts +1 -0
  349. package/src/plugins/CodeBlockPlugin/CodeBlock.tsx +20 -0
  350. package/src/plugins/CodeBlockPlugin/CodeBlockLine.tsx +7 -0
  351. package/src/plugins/CodeBlockPlugin/CodeBlockPlugin.tsx +304 -0
  352. package/src/plugins/CodeBlockPlugin/index.ts +1 -0
  353. package/src/plugins/CodeBlockPlugin/styles.module.css +11 -0
  354. package/src/plugins/CodeBlockPlugin/types.ts +10 -0
  355. package/src/plugins/CodeBlockPlugin/utils.ts +117 -0
  356. package/src/plugins/CommandsPlugin/CommandsPlugin.tsx +99 -0
  357. package/src/plugins/CommandsPlugin/Menu.tsx +205 -0
  358. package/src/plugins/CommandsPlugin/actions.ts +41 -0
  359. package/src/plugins/CommandsPlugin/index.ts +2 -0
  360. package/src/plugins/CommandsPlugin/styles.module.css +69 -0
  361. package/src/plugins/CommandsPlugin/types.ts +32 -0
  362. package/src/plugins/DnDPlugin/DnDPlugin.tsx +200 -0
  363. package/src/plugins/DnDPlugin/index.ts +1 -0
  364. package/src/plugins/DnDPlugin/styles.module.css +42 -0
  365. package/src/plugins/FloatingMenuPlugin/FloatingMenu.tsx +144 -0
  366. package/src/plugins/FloatingMenuPlugin/FloatingMenuPlugin.tsx +44 -0
  367. package/src/plugins/FloatingMenuPlugin/index.ts +2 -0
  368. package/src/plugins/FloatingMenuPlugin/styles.module.css +22 -0
  369. package/src/plugins/FloatingMenuPlugin/types.ts +18 -0
  370. package/src/plugins/HeadingsPlugin/HeadingsPlugin.tsx +75 -0
  371. package/src/plugins/HeadingsPlugin/index.ts +1 -0
  372. package/src/plugins/HighlightsPlugin/HighlightsPlugin.tsx +56 -0
  373. package/src/plugins/HighlightsPlugin/index.ts +1 -0
  374. package/src/plugins/LinksPlugin/Link.tsx +90 -0
  375. package/src/plugins/LinksPlugin/LinksPlugin.tsx +128 -0
  376. package/src/plugins/LinksPlugin/constants.ts +1 -0
  377. package/src/plugins/LinksPlugin/index.ts +2 -0
  378. package/src/plugins/LinksPlugin/styles.module.css +73 -0
  379. package/src/plugins/LinksPlugin/types.ts +19 -0
  380. package/src/plugins/ListsPlugin/ListsPlugin.tsx +355 -0
  381. package/src/plugins/ListsPlugin/index.ts +1 -0
  382. package/src/plugins/ListsPlugin/styles.module.css +7 -0
  383. package/src/plugins/MenuPlugin/Menu.tsx +9 -0
  384. package/src/plugins/MenuPlugin/MenuPlugin.tsx +20 -0
  385. package/src/plugins/MenuPlugin/index.ts +1 -0
  386. package/src/plugins/MenuPlugin/styles.module.css +33 -0
  387. package/src/plugins/MenuPlugin/types.ts +5 -0
  388. package/src/plugins/NodeIdPlugin/NodeIdPlugin.ts +62 -0
  389. package/src/plugins/NodeIdPlugin/index.ts +1 -0
  390. package/src/plugins/PlaceholderPlugin/PlaceholderPlugin.tsx +66 -0
  391. package/src/plugins/PlaceholderPlugin/index.ts +1 -0
  392. package/src/plugins/PlaceholderPlugin/styles.module.css +17 -0
  393. package/src/plugins/ShortcutsPlugin/ShortcutsPlugin.tsx +133 -0
  394. package/src/plugins/ShortcutsPlugin/index.ts +2 -0
  395. package/src/plugins/TableOfContentsPlugin/TableOfContentsPlugin.tsx +102 -0
  396. package/src/plugins/TableOfContentsPlugin/index.ts +1 -0
  397. package/src/plugins/TableOfContentsPlugin/styles.module.css +113 -0
  398. package/src/plugins/index.ts +20 -0
  399. package/src/queries/getMatchedGroups.ts +0 -0
  400. package/src/types.ts +87 -0
  401. package/src/utils.ts +15 -0
@@ -0,0 +1,55 @@
1
+ import type { KeyboardEvent } from 'react';
2
+ import { Editor, type NodeEntry } from 'slate';
3
+ import { type RenderElementProps, type RenderLeafProps } from 'slate-react';
4
+ import type { IPlugin } from '../../types';
5
+ import type { CodeElement } from './types';
6
+ import 'prismjs/themes/prism.css';
7
+ import 'prismjs/components/prism-javascript';
8
+ import 'prismjs/components/prism-typescript';
9
+ import 'prismjs/components/prism-json';
10
+ import 'prismjs/components/prism-markup';
11
+ import 'prismjs/components/prism-css';
12
+ import 'prismjs/components/prism-jsx';
13
+ import 'prismjs/components/prism-tsx';
14
+ import 'prismjs/components/prism-python';
15
+ import 'prismjs/components/prism-java';
16
+ import 'prismjs/components/prism-c';
17
+ import 'prismjs/components/prism-cpp';
18
+ import 'prismjs/components/prism-csharp';
19
+ import 'prismjs/components/prism-go';
20
+ import 'prismjs/components/prism-rust';
21
+ import 'prismjs/components/prism-ruby';
22
+ import 'prismjs/components/prism-php';
23
+ import 'prismjs/components/prism-bash';
24
+ import 'prismjs/components/prism-sql';
25
+ import 'prismjs/components/prism-yaml';
26
+ import 'prismjs/components/prism-markdown';
27
+ type Options = {
28
+ renderLanguageSelector: (value: string, onChange: (value: string) => void, params: {
29
+ element: CodeElement;
30
+ }) => React.ReactNode;
31
+ };
32
+ export declare class CodeBlockPlugin implements IPlugin {
33
+ private options;
34
+ constructor(options: Options);
35
+ static CODE_ELEMENT: string;
36
+ static CODE_LINE_ELEMENT: string;
37
+ handlers: {
38
+ onKeyDown: (event: KeyboardEvent, editor: Editor) => void;
39
+ };
40
+ decorate(entry: NodeEntry): (import("slate").BaseRange & {
41
+ merge?: (leaf: import("slate").Text, decoration: object) => void;
42
+ } & {
43
+ token: boolean;
44
+ })[];
45
+ blocks: {
46
+ type: string;
47
+ render: (props: RenderElementProps, editor: Editor) => import("react/jsx-runtime").JSX.Element;
48
+ }[];
49
+ leafs: {
50
+ render: (props: RenderLeafProps) => import("react/jsx-runtime").JSX.Element;
51
+ }[];
52
+ static isCodeBlockActive(editor: Editor): boolean;
53
+ static toggleCodeBlock: (editor: Editor) => void;
54
+ }
55
+ export {};
@@ -0,0 +1,224 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import prismjs from "prismjs";
3
+ import { Editor, Element, Node, Transforms } from "slate";
4
+ import { ReactEditor } from "slate-react";
5
+ import { CodeBlock } from "./CodeBlock.js";
6
+ import { normalizeTokens } from "./utils.js";
7
+ import "prismjs/themes/prism.css";
8
+ import { CodeBlockLine } from "./CodeBlockLine.js";
9
+ import "prismjs/components/prism-javascript";
10
+ import "prismjs/components/prism-typescript";
11
+ import "prismjs/components/prism-json";
12
+ import "prismjs/components/prism-markup";
13
+ import "prismjs/components/prism-css";
14
+ import "prismjs/components/prism-jsx";
15
+ import "prismjs/components/prism-tsx";
16
+ import "prismjs/components/prism-python";
17
+ import "prismjs/components/prism-java";
18
+ import "prismjs/components/prism-c";
19
+ import "prismjs/components/prism-cpp";
20
+ import "prismjs/components/prism-csharp";
21
+ import "prismjs/components/prism-go";
22
+ import "prismjs/components/prism-rust";
23
+ import "prismjs/components/prism-ruby";
24
+ import "prismjs/components/prism-php";
25
+ import "prismjs/components/prism-bash";
26
+ import "prismjs/components/prism-sql";
27
+ import "prismjs/components/prism-yaml";
28
+ import "prismjs/components/prism-markdown";
29
+ class CodeBlockPlugin {
30
+ options;
31
+ constructor(options){
32
+ this.options = options;
33
+ }
34
+ static CODE_ELEMENT = 'code';
35
+ static CODE_LINE_ELEMENT = 'code-line';
36
+ handlers = {
37
+ onKeyDown: (event, editor)=>{
38
+ const entry = Editor.above(editor, {
39
+ match: (n)=>!Editor.isEditor(n) && Editor.isBlock(editor, n),
40
+ mode: 'highest'
41
+ });
42
+ if (!entry) return;
43
+ const [node] = entry;
44
+ if ('Tab' === event.key && node.type === CodeBlockPlugin.CODE_ELEMENT) {
45
+ event.preventDefault();
46
+ if (event.shiftKey) {
47
+ const { selection } = editor;
48
+ if (selection && selection.anchor.offset === selection.focus.offset) {
49
+ const [line] = Editor.node(editor, selection.anchor.path);
50
+ const text = Node.string(line);
51
+ const cursorPos = selection.anchor.offset;
52
+ if (cursorPos >= 4 && ' ' === text.substring(cursorPos - 4, cursorPos)) editor.delete({
53
+ unit: 'character',
54
+ distance: 4,
55
+ reverse: true
56
+ });
57
+ else if (text.startsWith(' ')) {
58
+ const path = selection.anchor.path;
59
+ const start = {
60
+ path,
61
+ offset: 0
62
+ };
63
+ const end = {
64
+ path,
65
+ offset: 4
66
+ };
67
+ editor.delete({
68
+ at: {
69
+ anchor: start,
70
+ focus: end
71
+ }
72
+ });
73
+ }
74
+ }
75
+ } else editor.insertText(' ');
76
+ }
77
+ if ('a' === event.key && (event.ctrlKey || event.metaKey) && node && node.type === CodeBlockPlugin.CODE_ELEMENT) {
78
+ event.preventDefault();
79
+ const entry = Editor.above(editor, {
80
+ match: (n)=>!Editor.isEditor(n) && Element.isElement(n) && n.type === CodeBlockPlugin.CODE_ELEMENT
81
+ });
82
+ if (entry) {
83
+ const [, codeBlockPath] = entry;
84
+ const start = Editor.start(editor, codeBlockPath);
85
+ const end = Editor.end(editor, codeBlockPath);
86
+ Transforms.select(editor, {
87
+ anchor: start,
88
+ focus: end
89
+ });
90
+ }
91
+ }
92
+ }
93
+ };
94
+ decorate(entry) {
95
+ const [block, blockPath] = entry;
96
+ if (!Element.isElement(block) || block.type !== CodeBlockPlugin.CODE_ELEMENT) return [];
97
+ const language = block.language || 'plaintext';
98
+ const text = block.children.map((line)=>Node.string(line)).join('\n');
99
+ const prismLanguage = prismjs.languages[language] || prismjs.languages.javascript || {};
100
+ const tokens = prismjs.tokenize(text, prismLanguage);
101
+ const normalizedTokens = normalizeTokens(tokens);
102
+ const decorations = [];
103
+ for(let index = 0; index < normalizedTokens.length; index++){
104
+ const tokens = normalizedTokens[index];
105
+ let start = 0;
106
+ for (const token of tokens){
107
+ const length = token.content.length;
108
+ if (!length) continue;
109
+ const end = start + length;
110
+ const path = [
111
+ ...blockPath,
112
+ index,
113
+ 0
114
+ ];
115
+ decorations.push({
116
+ anchor: {
117
+ path,
118
+ offset: start
119
+ },
120
+ focus: {
121
+ path,
122
+ offset: end
123
+ },
124
+ token: true,
125
+ ...Object.fromEntries(token.types.map((type)=>[
126
+ type,
127
+ true
128
+ ]))
129
+ });
130
+ start = end;
131
+ }
132
+ }
133
+ return decorations;
134
+ }
135
+ blocks = [
136
+ {
137
+ type: CodeBlockPlugin.CODE_ELEMENT,
138
+ render: (props, editor)=>{
139
+ const onChange = (language)=>{
140
+ const path = ReactEditor.findPath(editor, props.element);
141
+ Transforms.setNodes(editor, {
142
+ language
143
+ }, {
144
+ at: path
145
+ });
146
+ };
147
+ return /*#__PURE__*/ jsx(CodeBlock, {
148
+ ...props,
149
+ element: props.element,
150
+ renderLanguageSelector: (element)=>this.options.renderLanguageSelector(props.element.language, onChange, {
151
+ element: element
152
+ })
153
+ });
154
+ }
155
+ },
156
+ {
157
+ type: CodeBlockPlugin.CODE_LINE_ELEMENT,
158
+ render: (props)=>/*#__PURE__*/ jsx(CodeBlockLine, {
159
+ ...props
160
+ })
161
+ }
162
+ ];
163
+ leafs = [
164
+ {
165
+ render: (props)=>{
166
+ const { leaf, attributes, children } = props;
167
+ const { text, ...rest } = leaf;
168
+ return /*#__PURE__*/ jsx("span", {
169
+ ...attributes,
170
+ className: Object.keys(rest).join(' '),
171
+ children: children
172
+ });
173
+ }
174
+ }
175
+ ];
176
+ static isCodeBlockActive(editor) {
177
+ const [match] = Array.from(Editor.nodes(editor, {
178
+ match: (n)=>!Editor.isEditor(n) && n.type === CodeBlockPlugin.CODE_ELEMENT,
179
+ mode: 'highest'
180
+ }));
181
+ return !!match;
182
+ }
183
+ static toggleCodeBlock = (editor)=>{
184
+ Editor.withoutNormalizing(editor, ()=>{
185
+ const node = Editor.above(editor, {
186
+ match: (n)=>!Editor.isEditor(n) && n.type === CodeBlockPlugin.CODE_ELEMENT,
187
+ mode: 'highest'
188
+ });
189
+ if (node) {
190
+ Transforms.setNodes(editor, {
191
+ type: 'paragraph'
192
+ }, {
193
+ at: node[1],
194
+ match: (n)=>n.type === CodeBlockPlugin.CODE_LINE_ELEMENT,
195
+ mode: 'lowest'
196
+ });
197
+ Transforms.unwrapNodes(editor, {
198
+ at: node[1],
199
+ match: (n)=>n.type === CodeBlockPlugin.CODE_ELEMENT,
200
+ split: true
201
+ });
202
+ } else {
203
+ Transforms.setNodes(editor, {
204
+ type: CodeBlockPlugin.CODE_LINE_ELEMENT,
205
+ children: [
206
+ {
207
+ text: ''
208
+ }
209
+ ]
210
+ }, {
211
+ match: (n)=>Editor.isBlock(editor, n) && 'paragraph' === n.type
212
+ });
213
+ Transforms.wrapNodes(editor, {
214
+ type: CodeBlockPlugin.CODE_ELEMENT,
215
+ language: "javascript",
216
+ children: []
217
+ }, {
218
+ match: (n)=>n.type === CodeBlockPlugin.CODE_LINE_ELEMENT
219
+ });
220
+ }
221
+ });
222
+ };
223
+ }
224
+ export { CodeBlockPlugin };
@@ -0,0 +1 @@
1
+ export { CodeBlockPlugin } from './CodeBlockPlugin';
@@ -0,0 +1,2 @@
1
+ import { CodeBlockPlugin } from "./CodeBlockPlugin.js";
2
+ export { CodeBlockPlugin };
@@ -0,0 +1,6 @@
1
+ import "./styles_module.css";
2
+ const styles_module = {
3
+ code: "code-j4FgXP",
4
+ content: "content-HIkMJO"
5
+ };
6
+ export { styles_module as default };
@@ -0,0 +1,12 @@
1
+ .code-j4FgXP {
2
+ border: 1px solid var(--kona-editor-border-color, #eee);
3
+ border-radius: 4px;
4
+ font-family: monospace;
5
+ overflow: hidden;
6
+ }
7
+
8
+ .content-HIkMJO {
9
+ background-color: var(--kona-editor-background-color, #fff);
10
+ padding: 8px;
11
+ }
12
+
@@ -0,0 +1,8 @@
1
+ import type { CustomElement, CustomText } from '../../../types';
2
+ export type CodeElement = {
3
+ language: string;
4
+ children: CodeLineElement[];
5
+ } & CustomElement;
6
+ export type CodeLineElement = {
7
+ children: CustomText[];
8
+ };
File without changes
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copied from prism-react-renderer repo
3
+ * https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/utils/normalizeTokens.js
4
+ * */
5
+ import Prism from 'prismjs';
6
+ type PrismToken = Prism.Token;
7
+ type Token = {
8
+ types: string[];
9
+ content: string;
10
+ empty?: boolean;
11
+ };
12
+ export declare const normalizeTokens: (tokens: Array<PrismToken | string>) => Token[][];
13
+ export {};
@@ -0,0 +1,87 @@
1
+ const newlineRe = /\r\n|\r|\n/;
2
+ const normalizeEmptyLines = (line)=>{
3
+ if (0 === line.length) line.push({
4
+ types: [
5
+ 'plain'
6
+ ],
7
+ content: '\n',
8
+ empty: true
9
+ });
10
+ else if (1 === line.length && '' === line[0].content) {
11
+ line[0].content = '\n';
12
+ line[0].empty = true;
13
+ }
14
+ };
15
+ const appendTypes = (types, add)=>{
16
+ const typesSize = types.length;
17
+ if (typesSize > 0 && types[typesSize - 1] === add) return types;
18
+ return types.concat(add);
19
+ };
20
+ const normalizeTokens = (tokens)=>{
21
+ const typeArrStack = [
22
+ []
23
+ ];
24
+ const tokenArrStack = [
25
+ tokens
26
+ ];
27
+ const tokenArrIndexStack = [
28
+ 0
29
+ ];
30
+ const tokenArrSizeStack = [
31
+ tokens.length
32
+ ];
33
+ let i = 0;
34
+ let stackIndex = 0;
35
+ let currentLine = [];
36
+ const acc = [
37
+ currentLine
38
+ ];
39
+ while(stackIndex > -1){
40
+ while((i = tokenArrIndexStack[stackIndex]++) < tokenArrSizeStack[stackIndex]){
41
+ let content;
42
+ let types = typeArrStack[stackIndex];
43
+ const tokenArr = tokenArrStack[stackIndex];
44
+ const token = tokenArr[i];
45
+ if ('string' == typeof token) {
46
+ types = stackIndex > 0 ? types : [
47
+ 'plain'
48
+ ];
49
+ content = token;
50
+ } else {
51
+ types = appendTypes(types, token.type);
52
+ if (token.alias) types = appendTypes(types, token.alias);
53
+ content = token.content;
54
+ }
55
+ if ('string' != typeof content) {
56
+ stackIndex++;
57
+ typeArrStack.push(types);
58
+ tokenArrStack.push(content);
59
+ tokenArrIndexStack.push(0);
60
+ tokenArrSizeStack.push(content.length);
61
+ continue;
62
+ }
63
+ const splitByNewlines = content.split(newlineRe);
64
+ const newlineCount = splitByNewlines.length;
65
+ currentLine.push({
66
+ types,
67
+ content: splitByNewlines[0]
68
+ });
69
+ for(let i = 1; i < newlineCount; i++){
70
+ normalizeEmptyLines(currentLine);
71
+ acc.push(currentLine = []);
72
+ currentLine.push({
73
+ types,
74
+ content: splitByNewlines[i]
75
+ });
76
+ }
77
+ }
78
+ stackIndex--;
79
+ typeArrStack.pop();
80
+ tokenArrStack.pop();
81
+ tokenArrIndexStack.pop();
82
+ tokenArrSizeStack.pop();
83
+ }
84
+ normalizeEmptyLines(currentLine);
85
+ return acc;
86
+ };
87
+ export { normalizeTokens };
@@ -0,0 +1,11 @@
1
+ import { type MapStore, type ReadableAtom } from 'nanostores';
2
+ import type { IPlugin, UiParams } from '../../types';
3
+ import type { CommandsStore, Options } from './types';
4
+ export declare class CommandsPlugin implements IPlugin {
5
+ options: Options;
6
+ $store: MapStore<CommandsStore>;
7
+ $commands: ReadableAtom<CommandsStore['commands']>;
8
+ constructor(options: Options);
9
+ init(editor: any): any;
10
+ ui(params: UiParams): import("react/jsx-runtime").JSX.Element | null;
11
+ }
@@ -0,0 +1,65 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useStore } from "@nanostores/react";
3
+ import { computed, map } from "nanostores";
4
+ import { Editor, Node } from "slate";
5
+ import { Menu } from "./Menu.js";
6
+ class CommandsPlugin {
7
+ options;
8
+ $store;
9
+ $commands;
10
+ constructor(options){
11
+ this.options = options;
12
+ this.$store = map({
13
+ isOpen: false,
14
+ filter: false,
15
+ commands: []
16
+ });
17
+ this.$commands = computed(this.$store, (store)=>{
18
+ if (false === store.filter) return [];
19
+ return store.commands.filter((command)=>{
20
+ const isCommandMatches = command.commandName.toLocaleLowerCase().includes(store.filter.toLocaleLowerCase());
21
+ const isTitleMatches = command.title.toLocaleLowerCase().includes(store.filter.toLocaleLowerCase());
22
+ return isCommandMatches || isTitleMatches;
23
+ });
24
+ });
25
+ }
26
+ init(editor) {
27
+ const { onChange, insertText } = editor;
28
+ editor.insertText = (text)=>{
29
+ if ('/' === text) {
30
+ this.$store.setKey('isOpen', true);
31
+ this.$store.setKey('commands', this.options.commands);
32
+ this.$store.setKey('filter', '');
33
+ }
34
+ insertText(text);
35
+ };
36
+ editor.onChange = (...args)=>{
37
+ if (this.$store.get().isOpen) {
38
+ const filter = /\/([^/]*)$/g.exec(getCurrentText(editor));
39
+ if (filter?.[0]) this.$store.setKey('filter', filter[1]);
40
+ else this.$store.setKey('filter', false);
41
+ }
42
+ return onChange(...args);
43
+ };
44
+ return editor;
45
+ }
46
+ ui(params) {
47
+ const commands = useStore(this.$commands);
48
+ const { isOpen } = useStore(this.$store);
49
+ if (!isOpen) return null;
50
+ return /*#__PURE__*/ jsx(Menu, {
51
+ renderMenu: this.options.renderMenu,
52
+ $store: this.$store,
53
+ commands: commands,
54
+ ignoreNodes: this.options.ignoreNodes
55
+ });
56
+ }
57
+ }
58
+ const getCurrentText = (editor)=>{
59
+ const entry = Editor.above(editor, {
60
+ match: (n)=>Editor.isBlock(editor, n)
61
+ });
62
+ if (entry) return Node.string(entry[0]);
63
+ return '';
64
+ };
65
+ export { CommandsPlugin };
@@ -0,0 +1,11 @@
1
+ import type { MapStore } from 'nanostores';
2
+ import React, { type ReactNode } from 'react';
3
+ import type { Command, CommandsStore } from './types';
4
+ type Props = {
5
+ $store: MapStore<CommandsStore>;
6
+ commands: Command[];
7
+ ignoreNodes?: string[];
8
+ renderMenu: (children: ReactNode) => ReactNode;
9
+ };
10
+ export declare const Menu: (props: Props) => React.ReactPortal | null;
11
+ export {};
@@ -0,0 +1,153 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useStore } from "@nanostores/react";
3
+ import clsx from "clsx";
4
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
5
+ import { createPortal } from "react-dom";
6
+ import { Editor } from "slate";
7
+ import { useFocused, useSlate, useSlateSelection } from "slate-react";
8
+ import { insert, insertText, removeCommand, set, wrap } from "./actions.js";
9
+ import styles_module from "./styles.module.js";
10
+ const Menu = (props)=>{
11
+ const { commands, $store, renderMenu, ignoreNodes = [] } = props;
12
+ const store = useStore($store);
13
+ const [style, setStyle] = useState({});
14
+ const [active, setActive] = useState(0);
15
+ const refs = useRef({});
16
+ const selection = useSlateSelection();
17
+ const editor = useSlate();
18
+ const isFocused = useFocused();
19
+ const entry = Editor.above(editor, {
20
+ match: (n)=>Editor.isBlock(editor, n)
21
+ });
22
+ const actions = useMemo(()=>({
23
+ removeCommand: removeCommand(editor, selection, store.filter),
24
+ set: set(editor, selection, store.filter),
25
+ insert: insert(editor, selection, store.filter),
26
+ wrap: wrap(editor, selection, store.filter),
27
+ insertText: insertText(editor)
28
+ }), [
29
+ commands,
30
+ store.filter
31
+ ]);
32
+ useLayoutEffect(()=>{
33
+ const { selection } = editor;
34
+ if (!selection || !isFocused) return void setStyle(void 0);
35
+ setTimeout(()=>{
36
+ const domSelection = window.getSelection();
37
+ const domRange = domSelection?.getRangeAt(0);
38
+ const rect = domRange?.getBoundingClientRect();
39
+ store.isOpen ? setStyle({
40
+ opacity: 1,
41
+ transform: 'scale(1)',
42
+ top: `${(rect?.top || 0) + window.scrollY + (rect?.height || 0) + 2}px`,
43
+ left: `${(rect?.left || 0) + window.scrollX + (rect?.width || 0) / 2}px`
44
+ }) : setStyle({
45
+ opacity: 0,
46
+ transform: 'scale(0.9)'
47
+ });
48
+ }, 0);
49
+ const handleKeyDown = (event)=>{
50
+ switch(event.key){
51
+ case 'ArrowDown':
52
+ event.preventDefault();
53
+ setActive((active)=>{
54
+ const newActive = active >= commands.length - 1 ? 0 : active + 1;
55
+ refs.current[newActive]?.scrollIntoView({
56
+ block: 'nearest'
57
+ });
58
+ return newActive;
59
+ });
60
+ break;
61
+ case 'ArrowUp':
62
+ event.preventDefault();
63
+ setActive((active)=>{
64
+ const newActive = active <= 0 ? commands.length - 1 : active - 1;
65
+ refs.current[newActive]?.scrollIntoView({
66
+ block: 'nearest'
67
+ });
68
+ return newActive;
69
+ });
70
+ break;
71
+ case 'Enter':
72
+ event.preventDefault();
73
+ commands[active]?.action(actions, editor);
74
+ $store.setKey('isOpen', false);
75
+ break;
76
+ case 'Escape':
77
+ event.stopPropagation();
78
+ $store.setKey('isOpen', false);
79
+ close();
80
+ break;
81
+ }
82
+ };
83
+ if (store.isOpen && commands.length > 0) document.addEventListener('keydown', handleKeyDown);
84
+ return ()=>{
85
+ document.removeEventListener('keydown', handleKeyDown);
86
+ };
87
+ }, [
88
+ selection,
89
+ active,
90
+ actions,
91
+ store.isOpen
92
+ ]);
93
+ useEffect(()=>{
94
+ if (active < 0) return void setActive(0);
95
+ if (active > commands.length - 1) setActive(commands.length - 1);
96
+ }, [
97
+ store.filter
98
+ ]);
99
+ const handleMenuLayout = (element)=>{
100
+ if (element) {
101
+ const { height, top } = element.getBoundingClientRect();
102
+ const domSelection = window.getSelection();
103
+ const domRange = domSelection?.getRangeAt(0);
104
+ const rect = domRange?.getBoundingClientRect();
105
+ if (top + height >= window.innerHeight) setStyle((style)=>({
106
+ ...style,
107
+ top: `${top - height - (rect?.height ?? 22)}px`
108
+ }));
109
+ }
110
+ };
111
+ if (!commands.length) return null;
112
+ if (entry && ignoreNodes.includes(entry[0].type)) return null;
113
+ return /*#__PURE__*/ createPortal(renderMenu(/*#__PURE__*/ jsxs(Fragment, {
114
+ children: [
115
+ store.isOpen && /*#__PURE__*/ jsx("div", {
116
+ className: styles_module.backdrop,
117
+ onClick: close
118
+ }),
119
+ /*#__PURE__*/ jsx("div", {
120
+ ref: handleMenuLayout,
121
+ style: style,
122
+ className: styles_module.menu,
123
+ onMouseDown: (event)=>{
124
+ event.preventDefault();
125
+ },
126
+ children: commands.map((command, index)=>/*#__PURE__*/ jsxs("button", {
127
+ type: "button",
128
+ ref: (element)=>{
129
+ if (element) refs.current[index] = element;
130
+ },
131
+ className: clsx(styles_module.button, {
132
+ [styles_module.active]: index === active
133
+ }),
134
+ onMouseDown: (event)=>{
135
+ event.preventDefault();
136
+ command.action(actions, editor);
137
+ $store.setKey('isOpen', false);
138
+ },
139
+ children: [
140
+ /*#__PURE__*/ jsx("span", {
141
+ className: styles_module.icon,
142
+ children: command.icon
143
+ }),
144
+ /*#__PURE__*/ jsx("span", {
145
+ children: command.title
146
+ })
147
+ ]
148
+ }, index))
149
+ })
150
+ ]
151
+ })), document.body);
152
+ };
153
+ export { Menu };
@@ -0,0 +1,7 @@
1
+ import { type Editor, type Selection } from 'slate';
2
+ import type { CustomElement } from '../../../types';
3
+ export declare const removeCommand: (editor: Editor, selection: Selection, filter?: string | boolean) => () => void;
4
+ export declare const set: (editor: Editor, selection: Selection, filter?: string | boolean) => (params: Partial<CustomElement>, options?: {}) => void;
5
+ export declare const insert: (editor: Editor, selection: Selection, filter?: string | boolean) => (params: CustomElement | CustomElement[]) => void;
6
+ export declare const wrap: (editor: Editor, selection: Selection, filter?: string | boolean) => (params: CustomElement, options?: {}) => void;
7
+ export declare const insertText: (editor: Editor) => (text: string) => void;