@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,205 @@
1
+ import { useStore } from '@nanostores/react';
2
+ import cn from 'clsx';
3
+ import type { MapStore } from 'nanostores';
4
+ import React, {
5
+ type CSSProperties,
6
+ type ReactNode,
7
+ useEffect,
8
+ useLayoutEffect,
9
+ useMemo,
10
+ useRef,
11
+ useState,
12
+ } from 'react';
13
+ import { createPortal } from 'react-dom';
14
+ import { Editor } from 'slate';
15
+ import { useFocused, useSlate, useSlateSelection } from 'slate-react';
16
+ import type { CustomElement } from '../../../types';
17
+ import { insert, insertText, removeCommand, set, wrap } from './actions';
18
+ import styles from './styles.module.css';
19
+ import type { Command, CommandsStore } from './types';
20
+
21
+ type Props = {
22
+ $store: MapStore<CommandsStore>;
23
+ commands: Command[];
24
+ ignoreNodes?: string[];
25
+ renderMenu: (children: ReactNode) => ReactNode;
26
+ };
27
+
28
+ export const Menu = (props: Props) => {
29
+ const { commands, $store, renderMenu, ignoreNodes = [] } = props;
30
+ const store = useStore($store);
31
+ const [style, setStyle] = useState<CSSProperties | undefined>({});
32
+ const [active, setActive] = useState(0);
33
+ const refs = useRef<Record<string, HTMLButtonElement>>({});
34
+
35
+ const selection = useSlateSelection();
36
+ const editor = useSlate() as Editor;
37
+ const isFocused = useFocused();
38
+
39
+ const entry = Editor.above<CustomElement>(editor, {
40
+ match: (n) => Editor.isBlock(editor, n as CustomElement),
41
+ });
42
+
43
+ // biome-ignore lint/correctness/useExhaustiveDependencies: we care only about those deps
44
+ const actions = useMemo(() => {
45
+ return {
46
+ removeCommand: removeCommand(editor, selection, store.filter),
47
+ set: set(editor, selection, store.filter),
48
+ insert: insert(editor, selection, store.filter),
49
+ wrap: wrap(editor, selection, store.filter),
50
+ insertText: insertText(editor),
51
+ };
52
+ }, [commands, store.filter]);
53
+
54
+ // biome-ignore lint/correctness/useExhaustiveDependencies: we care only about those deps
55
+ useLayoutEffect(() => {
56
+ const { selection } = editor;
57
+
58
+ if (!selection || !isFocused) {
59
+ setStyle(undefined);
60
+ return;
61
+ }
62
+
63
+ setTimeout(() => {
64
+ const domSelection = window.getSelection();
65
+ const domRange = domSelection?.getRangeAt(0);
66
+ const rect = domRange?.getBoundingClientRect();
67
+
68
+ if (store.isOpen) {
69
+ setStyle({
70
+ opacity: 1,
71
+ transform: 'scale(1)',
72
+ top: `${(rect?.top || 0) + window.scrollY + (rect?.height || 0) + 2}px`,
73
+ left: `${(rect?.left || 0) + window.scrollX + (rect?.width || 0) / 2}px`,
74
+ });
75
+ } else {
76
+ setStyle({
77
+ opacity: 0,
78
+ transform: 'scale(0.9)',
79
+ });
80
+ }
81
+ }, 0);
82
+
83
+ const handleKeyDown = (event: KeyboardEvent) => {
84
+ switch (event.key) {
85
+ case 'ArrowDown': {
86
+ event.preventDefault();
87
+ setActive((active) => {
88
+ const newActive = active >= commands.length - 1 ? 0 : active + 1;
89
+ refs.current[newActive]?.scrollIntoView({ block: 'nearest' });
90
+
91
+ return newActive;
92
+ });
93
+ break;
94
+ }
95
+ case 'ArrowUp': {
96
+ event.preventDefault();
97
+ setActive((active) => {
98
+ const newActive = active <= 0 ? commands.length - 1 : active - 1;
99
+ refs.current[newActive]?.scrollIntoView({ block: 'nearest' });
100
+
101
+ return newActive;
102
+ });
103
+ break;
104
+ }
105
+ case 'Enter': {
106
+ event.preventDefault();
107
+ commands[active]?.action(actions, editor);
108
+ $store.setKey('isOpen', false);
109
+ break;
110
+ }
111
+ case 'Escape': {
112
+ event.stopPropagation();
113
+ $store.setKey('isOpen', false);
114
+ close();
115
+ break;
116
+ }
117
+ }
118
+ };
119
+
120
+ if (store.isOpen && commands.length > 0) {
121
+ document.addEventListener('keydown', handleKeyDown);
122
+ }
123
+
124
+ return () => {
125
+ document.removeEventListener('keydown', handleKeyDown);
126
+ };
127
+ }, [selection, active, actions, store.isOpen]);
128
+
129
+ // biome-ignore lint/correctness/useExhaustiveDependencies: we care only about filter
130
+ useEffect(() => {
131
+ if (active < 0) {
132
+ setActive(0);
133
+ return;
134
+ }
135
+
136
+ if (active > commands.length - 1) {
137
+ setActive(commands.length - 1);
138
+ }
139
+ }, [store.filter]);
140
+
141
+ const handleMenuLayout = (element: HTMLDivElement) => {
142
+ if (element) {
143
+ const { height, top } = element.getBoundingClientRect();
144
+
145
+ const domSelection = window.getSelection();
146
+ const domRange = domSelection?.getRangeAt(0);
147
+ const rect = domRange?.getBoundingClientRect();
148
+
149
+ if (top + height >= window.innerHeight) {
150
+ setStyle((style) => ({
151
+ ...style,
152
+ top: `${top - height - (rect?.height ?? 22)}px`,
153
+ }));
154
+ }
155
+ }
156
+ };
157
+
158
+ if (!commands.length) {
159
+ return null;
160
+ }
161
+
162
+ if (entry && ignoreNodes.includes(entry[0].type)) {
163
+ return null;
164
+ }
165
+
166
+ return createPortal(
167
+ renderMenu(
168
+ <>
169
+ {store.isOpen && <div className={styles.backdrop} onClick={close} />}
170
+ <div
171
+ ref={handleMenuLayout}
172
+ style={style}
173
+ className={styles.menu}
174
+ onMouseDown={(event) => {
175
+ event.preventDefault();
176
+ }}
177
+ >
178
+ {commands.map((command, index) => (
179
+ <button
180
+ type="button"
181
+ ref={(element) => {
182
+ if (element) {
183
+ refs.current[index] = element;
184
+ }
185
+ }}
186
+ key={index}
187
+ className={cn(styles.button, {
188
+ [styles.active]: index === active,
189
+ })}
190
+ onMouseDown={(event) => {
191
+ event.preventDefault();
192
+ command.action(actions, editor);
193
+ $store.setKey('isOpen', false);
194
+ }}
195
+ >
196
+ <span className={styles.icon}>{command.icon}</span>
197
+ <span>{command.title}</span>
198
+ </button>
199
+ ))}
200
+ </div>
201
+ </>,
202
+ ),
203
+ document.body,
204
+ );
205
+ };
@@ -0,0 +1,41 @@
1
+ import { type Editor, type Selection, Transforms } from 'slate';
2
+ import type { CustomElement } from '../../../types';
3
+
4
+ export const removeCommand =
5
+ (editor: Editor, selection: Selection, filter?: string | boolean) => () => {
6
+ Transforms.delete(editor, {
7
+ at: selection?.focus,
8
+ distance: typeof filter === 'string' ? filter.length + 1 : 1,
9
+ reverse: true,
10
+ unit: 'character',
11
+ });
12
+ };
13
+
14
+ export const set =
15
+ (editor: Editor, selection: Selection, filter?: string | boolean) =>
16
+ (params: Partial<CustomElement>, options = {}) => {
17
+ removeCommand(editor, selection, filter)();
18
+ Transforms.setNodes(editor, params, {
19
+ ...options,
20
+ });
21
+ };
22
+
23
+ export const insert =
24
+ (editor: Editor, selection: Selection, filter?: string | boolean) =>
25
+ (params: CustomElement | CustomElement[]) => {
26
+ removeCommand(editor, selection, filter)();
27
+ Transforms.insertNodes(editor, params);
28
+ };
29
+
30
+ export const wrap =
31
+ (editor: Editor, selection: Selection, filter?: string | boolean) =>
32
+ (params: CustomElement, options = {}) => {
33
+ removeCommand(editor, selection, filter)();
34
+ Transforms.wrapNodes(editor, params, {
35
+ ...options,
36
+ });
37
+ };
38
+
39
+ export const insertText = (editor: Editor) => (text: string) => {
40
+ Transforms.insertText(editor, text);
41
+ };
@@ -0,0 +1,2 @@
1
+ export { CommandsPlugin } from './CommandsPlugin';
2
+ export type { Command } from './types';
@@ -0,0 +1,69 @@
1
+ :root {
2
+ --menu-background-color: #fff;
3
+ --menu-background-color-hover: #f9f9f9;
4
+ --menu-text-color: #444;
5
+ --menu-border-color: #ddd;
6
+ }
7
+
8
+ .menu {
9
+ position: absolute;
10
+ color: var(--menu-text-color, #444);
11
+ z-index: 31;
12
+ top: -100000px;
13
+ left: -100000px;
14
+ opacity: 0;
15
+ transform: scale(0.9);
16
+ margin-top: -6px;
17
+ background-color: var(--menu-background-color, #fff);
18
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.025);
19
+ border: 1px solid var(--menu-border-color, #ddd);
20
+ border-radius: 4px;
21
+ transition: transform 0.25s;
22
+ display: flex;
23
+ flex-direction: column;
24
+ max-height: 200px;
25
+ overflow-y: auto;
26
+ font-size: 12px;
27
+ }
28
+
29
+ .button {
30
+ border: none;
31
+ background: transparent;
32
+ display: inline-flex;
33
+ column-gap: 8px;
34
+ align-items: center;
35
+ padding: 8px 8px;
36
+ height: 40px;
37
+ box-sizing: border-box;
38
+ cursor: pointer;
39
+ color: var(--menu-text-color, #444);
40
+ }
41
+
42
+ .button:hover {
43
+ background-color: var(--menu-background-color-hover, #f9f9f9);
44
+ }
45
+
46
+ .active {
47
+ background-color: var(--menu-background-color-hover, #f9f9f9);
48
+ }
49
+
50
+ .icon {
51
+ width: 24px;
52
+ height: 24px;
53
+ opacity: 0.5;
54
+ padding: 2px;
55
+ font-size: 12px;
56
+ background: var(--menu-background-color-hover, #f9f9f9);
57
+ color: var(--menu-text-color, #444);
58
+ border-radius: 4px;
59
+ display: inline-flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ }
63
+
64
+ .backdrop {
65
+ position: fixed;
66
+ inset: 0;
67
+ z-index: 30;
68
+ background-color: transparent;
69
+ }
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import type { Editor, Node } from 'slate';
4
+ import type { CustomElement } from '../../../types';
5
+
6
+ export type Options = {
7
+ commands: Command[];
8
+ renderMenu: (children: ReactNode) => ReactNode;
9
+ ignoreNodes?: string[];
10
+ };
11
+
12
+ export type CommandsStore = {
13
+ isOpen: boolean;
14
+ filter: boolean | string;
15
+ commands: Command[];
16
+ };
17
+
18
+ export type Command = {
19
+ name: string;
20
+ title: string;
21
+ commandName: string;
22
+ icon: ReactNode;
23
+ action: (actions: Actions, editor: Editor) => void;
24
+ };
25
+
26
+ export type Actions = {
27
+ removeCommand: () => void;
28
+ set: (params: Partial<CustomElement>, options?: any) => void;
29
+ insert: (params: CustomElement) => void;
30
+ wrap: (params: CustomElement, options?: any) => void;
31
+ insertText: (text: string) => void;
32
+ };
@@ -0,0 +1,200 @@
1
+ import type React from 'react';
2
+ import { useEffect, useState } from 'react';
3
+ import {
4
+ type ConnectDragPreview,
5
+ type ConnectDragSource,
6
+ type ConnectDropTarget,
7
+ useDrag,
8
+ useDrop,
9
+ } from 'react-dnd';
10
+ import { NativeTypes } from 'react-dnd-html5-backend';
11
+ import { Editor, Path, Transforms } from 'slate';
12
+ import {
13
+ ReactEditor,
14
+ type RenderElementProps,
15
+ useReadOnly,
16
+ useSlate,
17
+ } from 'slate-react';
18
+ import type { CustomElement } from '../../../types';
19
+ import type { IPlugin } from '../../types';
20
+
21
+ type Options = {
22
+ onDropFiles: (editor: Editor, files: File[], path: Path) => void;
23
+ renderBlock?: (params: {
24
+ props: RenderElementProps;
25
+ dragRef: ConnectDragSource;
26
+ dropRef: ConnectDropTarget;
27
+ previewRef: ConnectDragPreview;
28
+ position: 'top' | 'bottom' | null;
29
+ }) => React.ReactNode;
30
+ ignoreNodes?: string[];
31
+ customTypes?: {
32
+ [type: string]: {
33
+ type: string | symbol;
34
+ getData?: (element: CustomElement) => Record<string, unknown>;
35
+ };
36
+ };
37
+ };
38
+
39
+ export class DnDPlugin implements IPlugin {
40
+ constructor(private options: Options) {}
41
+
42
+ static DND_BLOCK_ELEMENT = 'block';
43
+
44
+ handlers = {
45
+ onDrop: (event: DragEvent) => {
46
+ event.preventDefault();
47
+ },
48
+ };
49
+
50
+ renderBlock = (props: RenderElementProps) => {
51
+ const editor = useSlate();
52
+
53
+ const options = this.options;
54
+ const isReadOnly = useReadOnly();
55
+
56
+ const [dropPosition, setDropPosition] = useState<'top' | 'bottom' | null>(
57
+ null,
58
+ );
59
+
60
+ const customType = options.customTypes?.[props.element.type];
61
+
62
+ const [, drag, preview] = useDrag({
63
+ type: customType?.type || DnDPlugin.DND_BLOCK_ELEMENT,
64
+ item: {
65
+ ...(customType?.getData?.(props.element) || {}),
66
+ element: props.element,
67
+ },
68
+ canDrag: !isReadOnly,
69
+ });
70
+
71
+ const allCustomTypes = Object.values(options.customTypes || {}).map(
72
+ (customType) => customType.type,
73
+ );
74
+
75
+ const [{ isOver }, drop] = useDrop({
76
+ accept: [
77
+ DnDPlugin.DND_BLOCK_ELEMENT,
78
+ NativeTypes.FILE,
79
+ ...allCustomTypes,
80
+ ],
81
+ collect(monitor) {
82
+ return {
83
+ item: monitor.getItem(),
84
+ isOver: monitor.isOver(),
85
+ position: monitor.isOver() ? monitor.getClientOffset() : null,
86
+ };
87
+ },
88
+ hover(_, monitor) {
89
+ const element = ReactEditor.toDOMNode(
90
+ editor,
91
+ props.element,
92
+ ) as HTMLElement;
93
+ if (!element) return;
94
+
95
+ const hoverBoundingRect = element.getBoundingClientRect();
96
+ const hoverMiddleY =
97
+ (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
98
+ const clientOffset = monitor.getClientOffset();
99
+ if (!clientOffset) return;
100
+
101
+ const hoverClientY = clientOffset.y - hoverBoundingRect.top;
102
+
103
+ if (hoverClientY < hoverMiddleY) {
104
+ setDropPosition('top');
105
+ } else {
106
+ setDropPosition('bottom');
107
+ }
108
+ },
109
+ drop(item, monitor) {
110
+ const itemType = monitor.getItemType();
111
+
112
+ const sourceTo = ReactEditor.findPath(editor, props.element);
113
+
114
+ if (!sourceTo) return;
115
+
116
+ const dropPath = getDropPath(editor, sourceTo, dropPosition);
117
+
118
+ if (!dropPath) return;
119
+
120
+ switch (itemType) {
121
+ case NativeTypes.FILE:
122
+ options.onDropFiles(
123
+ editor,
124
+ (item as { files: File[] }).files,
125
+ dropPath,
126
+ );
127
+ break;
128
+ default: {
129
+ const targetTo = ReactEditor.findPath(
130
+ editor,
131
+ (item as { element: CustomElement }).element,
132
+ );
133
+
134
+ if (!dropPosition) {
135
+ return;
136
+ }
137
+
138
+ moveNode(editor, sourceTo, targetTo, dropPosition);
139
+ break;
140
+ }
141
+ }
142
+
143
+ setDropPosition(null);
144
+ },
145
+ });
146
+
147
+ // biome-ignore lint/correctness/useExhaustiveDependencies: we care only about this dep
148
+ useEffect(() => {
149
+ setDropPosition(null);
150
+ }, [isOver]);
151
+
152
+ if (this.options.ignoreNodes?.includes(props.element.type)) {
153
+ return props.children;
154
+ }
155
+
156
+ if (editor.isInline(props.element)) {
157
+ return props.children;
158
+ }
159
+
160
+ return options.renderBlock?.({
161
+ props,
162
+ dragRef: drag,
163
+ dropRef: drop,
164
+ previewRef: preview,
165
+ position: dropPosition,
166
+ });
167
+ };
168
+ }
169
+
170
+ const getDropPath = (
171
+ editor: Editor,
172
+ targetNodePath: Path,
173
+ position: 'top' | 'bottom' | null,
174
+ ) => {
175
+ const target = Editor.node(editor, targetNodePath);
176
+
177
+ switch (position) {
178
+ case 'top':
179
+ return target[1];
180
+ case 'bottom':
181
+ return Path.next(target[1]);
182
+ }
183
+ };
184
+
185
+ const moveNode = (
186
+ editor: Editor,
187
+ targetNodePath: Path,
188
+ sourceNodePath: Path,
189
+ position: 'top' | 'bottom',
190
+ ) => {
191
+ const dropPath = getDropPath(editor, targetNodePath, position);
192
+
193
+ if (!dropPath) return;
194
+
195
+ Transforms.moveNodes(editor, {
196
+ at: sourceNodePath,
197
+ to: dropPath,
198
+ mode: 'highest',
199
+ });
200
+ };
@@ -0,0 +1 @@
1
+ export { DnDPlugin } from './DnDPlugin';
@@ -0,0 +1,42 @@
1
+ .root {
2
+ position: relative;
3
+ border-top: 2px solid transparent;
4
+ border-bottom: 2px solid transparent;
5
+ }
6
+
7
+ .block {
8
+ position: relative;
9
+ border-radius: 4px;
10
+ display: grid;
11
+ grid-template-columns: 16px 1fr;
12
+ column-gap: 8px;
13
+ align-items: start;
14
+ padding: 4px 8px 4px 8px;
15
+ transition: background-color 0.25s;
16
+ }
17
+
18
+ .block:hover {
19
+ background-color: rgba(0, 0, 0, 0.025);
20
+ }
21
+
22
+ .block:hover .drag {
23
+ opacity: 1;
24
+ }
25
+
26
+ .drag {
27
+ display: inline-block;
28
+ vertical-align: baseline;
29
+ width: 16px;
30
+ cursor: move;
31
+ line-height: 1.2;
32
+ opacity: 0;
33
+ transition: opacity 0.25s;
34
+ }
35
+
36
+ .top {
37
+ border-top: 2px solid #3498db;
38
+ }
39
+
40
+ .bottom {
41
+ border-bottom: 2px solid #3498db;
42
+ }