@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
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@use-kona/editor",
3
+ "version": "0.1.0-rc.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.ts"
7
+ },
8
+ "main": "./dist/editor.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
14
+ "scripts": {
15
+ "build": "rslib build",
16
+ "build:storybook": "storybook build",
17
+ "check": "biome check --write",
18
+ "dev": "rslib build --watch",
19
+ "format": "biome format --write",
20
+ "storybook": "storybook dev",
21
+ "test": "vitest run"
22
+ },
23
+ "devDependencies": {
24
+ "@biomejs/biome": "2.0.0",
25
+ "@rsbuild/core": "~1.4.0",
26
+ "@rsbuild/plugin-react": "^1.3.2",
27
+ "@rslib/core": "^0.10.4",
28
+ "@storybook/addon-docs": "^9.0.13",
29
+ "@storybook/addon-essentials": "^9.0.0-alpha.12",
30
+ "@storybook/addon-interactions": "^9.0.0-alpha.10",
31
+ "@storybook/addon-links": "^9.0.13",
32
+ "@storybook/addon-onboarding": "^9.0.13",
33
+ "@storybook/blocks": "^9.0.0-alpha.17",
34
+ "@storybook/react": "^9.0.13",
35
+ "@storybook/test": "^9.0.0-alpha.2",
36
+ "@testing-library/jest-dom": "^6.6.3",
37
+ "@testing-library/react": "^16.3.0",
38
+ "@types/is-url": "^1.2.32",
39
+ "@types/react": "^19.1.8",
40
+ "@types/react-dom": "18",
41
+ "clsx": "^2.1.1",
42
+ "is-url": "^1.2.4",
43
+ "jsdom": "^26.1.0",
44
+ "react": "^18.3.1",
45
+ "react-dnd": "^16.0.1",
46
+ "react-dnd-html5-backend": "^16.0.1",
47
+ "react-dom": "18",
48
+ "storybook": "^9.0.13",
49
+ "storybook-addon-rslib": "^2.0.2",
50
+ "storybook-react-rsbuild": "^2.0.2",
51
+ "typescript": "^5.8.3",
52
+ "vitest": "^3.2.4"
53
+ },
54
+ "peerDependencies": {
55
+ "react": ">=16.9.0",
56
+ "react-dnd": "^16.0.1",
57
+ "react-dnd-html5-backend": "^16.0.1",
58
+ "react-dom": "18"
59
+ },
60
+ "dependencies": {
61
+ "@nanostores/react": "^1.0.0",
62
+ "escape-html": "^1.0.3",
63
+ "is-hotkey": "^0.2.0",
64
+ "nanostores": "^1.0.1",
65
+ "prismjs": "^1.30.0",
66
+ "slate": "^0.117.2",
67
+ "slate-history": "^0.113.1",
68
+ "slate-hyperscript": "^0.100.0",
69
+ "slate-react": "^0.117.3"
70
+ }
71
+ }
@@ -0,0 +1 @@
1
+ export const ELEMENT_PARAGRAPH = 'paragraph';
@@ -0,0 +1,159 @@
1
+ import isHotkey from 'is-hotkey';
2
+ import React, {
3
+ isValidElement,
4
+ type JSX,
5
+ type KeyboardEvent,
6
+ type ReactElement,
7
+ type ReactNode,
8
+ useCallback,
9
+ } from 'react';
10
+ import type { DecoratedRange, Editor, NodeEntry } from 'slate';
11
+ import {
12
+ Editable,
13
+ type RenderElementProps,
14
+ type RenderLeafProps,
15
+ useReadOnly,
16
+ } from 'slate-react';
17
+ import { BaseElement } from '../elements/BaseElement';
18
+ import type { IPlugin } from '../types';
19
+ import styles from './styles.module.css';
20
+
21
+ const SUPPORTED_HANDLERS = ['onDrop', 'onKeyDown', 'onPaste'];
22
+
23
+ type Props = {
24
+ readOnly?: boolean;
25
+ };
26
+
27
+ export const createEditable =
28
+ (editor: Editor, plugins: IPlugin[]) =>
29
+ ({ readOnly }: Props) => {
30
+ const renderElement = (props: RenderElementProps): ReactElement => {
31
+ let result: ReactElement | null = null;
32
+
33
+ for (const plugin of plugins) {
34
+ for (const element of plugin.blocks || []) {
35
+ if (element.type !== props.element.type) continue;
36
+
37
+ const newElement = element.render(props, editor);
38
+ result = newElement || result;
39
+ }
40
+ }
41
+
42
+ for (const plugin of plugins) {
43
+ if (plugin.renderBlock) {
44
+ result = plugin.renderBlock({
45
+ ...props,
46
+ children: result || props.children,
47
+ });
48
+ }
49
+ }
50
+
51
+ return result || <BaseElement {...props} />;
52
+ };
53
+
54
+ const renderLeaf = (props: RenderLeafProps): JSX.Element => {
55
+ let result: ReactNode;
56
+ for (const plugin of plugins) {
57
+ plugin.leafs?.map((element) => {
58
+ const newElement = element.render(
59
+ {
60
+ ...props,
61
+ children: result || props.children,
62
+ },
63
+ editor,
64
+ );
65
+ if (newElement && isValidElement(newElement)) {
66
+ result = newElement;
67
+ }
68
+ });
69
+ }
70
+
71
+ return result as JSX.Element;
72
+ };
73
+
74
+ const handleHotkey = (event: KeyboardEvent) => {
75
+ for (const plugin of plugins) {
76
+ if (plugin.hotkeys) {
77
+ for (const hotkey of plugin.hotkeys) {
78
+ if (isHotkey(hotkey[0], event) && hotkey[1]) {
79
+ event.preventDefault();
80
+ hotkey[1](event, editor);
81
+ }
82
+ }
83
+ }
84
+ }
85
+ };
86
+
87
+ const decorate = (entry: NodeEntry) => {
88
+ const decorators: IPlugin[] = plugins.filter(
89
+ (plugin) => !!plugin.decorate,
90
+ );
91
+
92
+ return decorators.reduce<DecoratedRange[]>((decorations, plugin) => {
93
+ const pluginDecorators = plugin.decorate?.(entry) || [];
94
+ return decorations.concat(pluginDecorators);
95
+ }, []);
96
+ };
97
+
98
+ const handlers = plugins.reduce(
99
+ (handlers, plugin) => {
100
+ SUPPORTED_HANDLERS.forEach((handlerName) => {
101
+ if (plugin.handlers?.[handlerName]) {
102
+ const lastHandler = handlers[handlerName];
103
+ if (lastHandler) {
104
+ handlers[handlerName] = (event) => {
105
+ lastHandler(event, editor);
106
+ plugin.handlers?.[handlerName](event, editor);
107
+ };
108
+ } else {
109
+ handlers[handlerName] = (event) => {
110
+ plugin.handlers?.[handlerName](event, editor);
111
+ };
112
+ }
113
+ }
114
+ });
115
+
116
+ return handlers;
117
+ },
118
+ {
119
+ onKeyDown: handleHotkey,
120
+ },
121
+ );
122
+
123
+ const Ui = useCallback(
124
+ ({ children }: { children: ReactNode }) => {
125
+ const ui = plugins.filter((p) => Boolean(p.ui));
126
+ const readOnly = useReadOnly();
127
+
128
+ if (!ui.length) {
129
+ return <div className={styles.editor}>{children}</div>;
130
+ }
131
+
132
+ return (
133
+ <>
134
+ {ui.map((p, index) => (
135
+ <React.Fragment key={index}>
136
+ {p.ui!({ readOnly, children, editor })}
137
+ </React.Fragment>
138
+ ))}
139
+ <div className={styles.editor}>{children}</div>
140
+ </>
141
+ );
142
+ },
143
+ [editor, plugins.filter],
144
+ );
145
+
146
+ return (
147
+ <div className={styles.root}>
148
+ <Ui>
149
+ <Editable
150
+ decorate={decorate}
151
+ renderElement={renderElement}
152
+ renderLeaf={renderLeaf}
153
+ readOnly={readOnly}
154
+ {...handlers}
155
+ />
156
+ </Ui>
157
+ </div>
158
+ );
159
+ };
@@ -0,0 +1,244 @@
1
+ import {
2
+ createEditor as createBaseEditor,
3
+ Editor,
4
+ Path,
5
+ Range,
6
+ Transforms,
7
+ } from 'slate';
8
+ import { withHistory } from 'slate-history';
9
+ import { withReact } from 'slate-react';
10
+ import type { CustomElement } from '../../types';
11
+ import type { Block, IPlugin } from '../types';
12
+
13
+ export const createEditor = (plugins: IPlugin[]) => () => {
14
+ const baseEditor = withHistory(withReact(createBaseEditor()));
15
+
16
+ const editorWithPlugins = plugins.reduce<Editor>((editor, plugin) => {
17
+ if (plugin.init) {
18
+ return plugin.init(editor);
19
+ }
20
+
21
+ return editor;
22
+ }, baseEditor);
23
+
24
+ const {
25
+ isInline,
26
+ isVoid,
27
+ normalizeNode,
28
+ deleteFragment,
29
+ deleteBackward,
30
+ deleteForward,
31
+ } = editorWithPlugins;
32
+
33
+ editorWithPlugins.normalizeNode = (entry) => {
34
+ const [node, path] = entry;
35
+
36
+ const lastElement =
37
+ editorWithPlugins.children[editorWithPlugins.children.length - 1];
38
+ if (!lastElement || (lastElement as CustomElement).type !== 'paragraph') {
39
+ const paragraph = {
40
+ type: 'paragraph',
41
+ children: [{ text: '' }],
42
+ };
43
+ Transforms.insertNodes(editorWithPlugins, paragraph, {
44
+ at: [editorWithPlugins.children.length],
45
+ });
46
+ }
47
+
48
+ return normalizeNode([node, path]);
49
+ };
50
+
51
+ editorWithPlugins.isVoid = (element) => {
52
+ const result = plugins.reduce<boolean | undefined>((result, plugin) => {
53
+ const match = plugin.blocks?.find((el) => element?.type === el.type);
54
+ if (match && 'isVoid' in match) {
55
+ return match.isVoid;
56
+ }
57
+
58
+ return result;
59
+ }, undefined);
60
+
61
+ return result ?? isVoid(element);
62
+ };
63
+
64
+ editorWithPlugins.isInline = (element) => {
65
+ const result = plugins.reduce<boolean | undefined>((result, plugin) => {
66
+ const match = plugin.blocks?.find((el) => element?.type === el.type);
67
+ if (match && 'isInline' in match) {
68
+ return match.isInline;
69
+ }
70
+
71
+ return result;
72
+ }, undefined);
73
+
74
+ return result ?? isInline(element);
75
+ };
76
+
77
+ editorWithPlugins.deleteForward = async (unit) => {
78
+ const { selection } = editorWithPlugins;
79
+
80
+ if (!selection) {
81
+ return;
82
+ }
83
+
84
+ if (Range.isCollapsed(selection)) {
85
+ const firstEntry = Editor.above<CustomElement>(editorWithPlugins, {
86
+ at: selection.anchor,
87
+ match: (n) => Editor.isBlock(editorWithPlugins, n as CustomElement),
88
+ mode: 'lowest',
89
+ });
90
+
91
+ if (!firstEntry) {
92
+ return;
93
+ }
94
+
95
+ const [, currentPath] = firstEntry;
96
+
97
+ const secondEntry = Editor.above<CustomElement>(editorWithPlugins, {
98
+ at: Editor.after(editorWithPlugins, selection.anchor),
99
+ match: (n) => Editor.isBlock(editorWithPlugins, n as CustomElement),
100
+ mode: 'lowest',
101
+ });
102
+
103
+ if (!secondEntry) {
104
+ return;
105
+ }
106
+
107
+ const [node, path] = secondEntry;
108
+
109
+ if (
110
+ node &&
111
+ Editor.isStart(editorWithPlugins, selection.anchor, currentPath)
112
+ ) {
113
+ const matchedBlock = plugins.reduce<Block | null>((block, plugin) => {
114
+ const match = plugin.blocks?.find((b) => b.type === node.type);
115
+ return block || match || null;
116
+ }, null);
117
+
118
+ if (matchedBlock) {
119
+ const result = matchedBlock.onBeforeDelete
120
+ ? await matchedBlock?.onBeforeDelete?.([node])
121
+ : true;
122
+ if (result) {
123
+ Transforms.removeNodes(editorWithPlugins, { at: path });
124
+ matchedBlock.onDelete?.([node]);
125
+ }
126
+ return;
127
+ }
128
+ }
129
+ }
130
+
131
+ deleteForward(unit);
132
+ };
133
+
134
+ editorWithPlugins.deleteBackward = async (unit) => {
135
+ const { selection } = editorWithPlugins;
136
+
137
+ if (!selection) {
138
+ return;
139
+ }
140
+
141
+ if (Range.isCollapsed(selection)) {
142
+ const firstEntry = Editor.above<CustomElement>(editorWithPlugins, {
143
+ at: selection.anchor,
144
+ match: (n) => Editor.isBlock(editorWithPlugins, n as CustomElement),
145
+ mode: 'lowest',
146
+ });
147
+ const secondEntry = Editor.above<CustomElement>(editorWithPlugins, {
148
+ at: Editor.before(editorWithPlugins, selection.anchor),
149
+ match: (n) => Editor.isBlock(editorWithPlugins, n as CustomElement),
150
+ mode: 'lowest',
151
+ });
152
+
153
+ if (!firstEntry || !secondEntry) {
154
+ return;
155
+ }
156
+
157
+ const [_, currentPath] = firstEntry;
158
+ const [node, path] = secondEntry;
159
+
160
+ if (
161
+ node &&
162
+ Editor.isStart(editorWithPlugins, selection.anchor, currentPath)
163
+ ) {
164
+ const matchedBlock = plugins.reduce<Block | null>((block, plugin) => {
165
+ const match = plugin.blocks?.find((b) => b.type === node.type);
166
+ return block || match || null;
167
+ }, null);
168
+
169
+ if (matchedBlock) {
170
+ const result = matchedBlock.onBeforeDelete
171
+ ? await matchedBlock.onBeforeDelete([node])
172
+ : true;
173
+ if (result) {
174
+ Transforms.removeNodes(editorWithPlugins, { at: path });
175
+ matchedBlock.onDelete?.([node]);
176
+ }
177
+ return;
178
+ }
179
+ }
180
+ }
181
+
182
+ deleteBackward(unit);
183
+ };
184
+
185
+ editorWithPlugins.deleteFragment = async (options) => {
186
+ const { selection } = editorWithPlugins;
187
+
188
+ if (!selection) {
189
+ return;
190
+ }
191
+
192
+ const [start, end] = Range.edges(selection);
193
+ const isSingleText = Path.equals(start.path, end.path);
194
+
195
+ if (isSingleText) {
196
+ deleteFragment(options);
197
+ return;
198
+ }
199
+ const nodes = Array.from(
200
+ Editor.nodes<CustomElement>(editorWithPlugins, {
201
+ at: selection,
202
+ match: (n) =>
203
+ !Editor.isEditor(n) &&
204
+ Editor.isBlock(editorWithPlugins, n as CustomElement),
205
+ }),
206
+ ).reverse();
207
+
208
+ for (const entry of nodes) {
209
+ const [node, path] = entry;
210
+
211
+ const plugin = plugins.find((plugin) =>
212
+ plugin.blocks?.find((b) => b.type === node.type),
213
+ );
214
+ if (plugin) {
215
+ const match = plugin.blocks?.find((b) => b.type === node.type);
216
+ const result = match?.onBeforeDelete
217
+ ? await match.onBeforeDelete([node])
218
+ : true;
219
+ if (result) {
220
+ Transforms.removeNodes(editorWithPlugins, {
221
+ at: path,
222
+ match: (n) => (n as CustomElement).type === node.type,
223
+ });
224
+ match?.onDelete?.([node]);
225
+ } else {
226
+ return;
227
+ }
228
+ } else {
229
+ Transforms.removeNodes(editorWithPlugins, {
230
+ at: path,
231
+ match: (n) => (n as CustomElement).type === node.type,
232
+ });
233
+ }
234
+ }
235
+
236
+ if (nodes.length > 0) {
237
+ return;
238
+ }
239
+
240
+ deleteFragment(options);
241
+ };
242
+
243
+ return editorWithPlugins;
244
+ };
@@ -0,0 +1,57 @@
1
+ import { type Descendant, Element, type Node } from 'slate';
2
+ import { jsx } from 'slate-hyperscript';
3
+ import type { IPlugin } from '../types';
4
+
5
+ export const deserialize =
6
+ (plugins: IPlugin[]) =>
7
+ (
8
+ element: HTMLElement,
9
+ ): (Descendant | string)[] | string | Descendant | null => {
10
+ if (element.nodeType === 3) {
11
+ return element.textContent;
12
+ } else if (element.nodeType !== 1) {
13
+ return null;
14
+ } else if (element.nodeName === 'BR') {
15
+ return '\n';
16
+ }
17
+
18
+ let children = Array.from(element.childNodes).flatMap((node) =>
19
+ deserialize(plugins)(node as HTMLElement),
20
+ );
21
+
22
+ if (children.length === 0) {
23
+ children = [{ text: '' }];
24
+ }
25
+
26
+ if (element.nodeName === 'BODY') {
27
+ if (children.some((c) => Element.isElement(c))) {
28
+ return jsx('fragment', {}, children);
29
+ } else {
30
+ return jsx('element', { type: 'paragraph' }, children);
31
+ }
32
+ }
33
+
34
+ if (element.nodeName === 'P') {
35
+ return jsx('element', { type: 'paragraph' }, children);
36
+ }
37
+
38
+ let result: Node | null = null;
39
+ for (const plugin of plugins) {
40
+ if (plugin.blocks?.some((b) => b.deserialize)) {
41
+ plugin.blocks.forEach((e) => {
42
+ if (e.deserialize) {
43
+ // Cast children to match the expected type in Deserialize interface
44
+ const childrenAsDescendants = children as (string | Descendant)[];
45
+ const newResult = e.deserialize(element, childrenAsDescendants);
46
+ if (newResult) {
47
+ result = newResult;
48
+ }
49
+ }
50
+ });
51
+ }
52
+ if (result) {
53
+ return result;
54
+ }
55
+ }
56
+ return children.filter((child) => child !== null);
57
+ };
@@ -0,0 +1,10 @@
1
+ import { Editor, NodeEntry, Node, Path } from 'slate';
2
+
3
+ export const getPrev = (editor: Editor, node: NodeEntry) => {
4
+ try {
5
+ const [, path] = node;
6
+ return Node.get(editor, Path.previous(path));
7
+ } catch (e) {
8
+ return null;
9
+ }
10
+ };
@@ -0,0 +1,38 @@
1
+ import escapeHtml from 'escape-html';
2
+ import { Text } from 'slate';
3
+ import type { CustomElement, CustomText } from '../../types';
4
+ import type { IPlugin } from '../types';
5
+
6
+ export const serialize =
7
+ (plugins: IPlugin[]) =>
8
+ (
9
+ node: CustomElement | CustomElement[] | CustomText | CustomText[],
10
+ ): string => {
11
+ const serializers = plugins
12
+ .flatMap((plugin) => plugin.blocks?.map((element) => element.serialize))
13
+ .filter(Boolean);
14
+
15
+ if (Array.isArray(node)) {
16
+ return node.map(serialize(plugins)).join('');
17
+ }
18
+
19
+ if (Text.isText(node)) {
20
+ return serializers.reduce((prev, current) => {
21
+ return current?.(node) || prev;
22
+ }, escapeHtml(node.text));
23
+ } else {
24
+ const children: string = node.children
25
+ ?.map((n) => serialize(plugins)(n))
26
+ .join('');
27
+
28
+ if (node.type === 'paragraph') {
29
+ return `<p>${children}</p>`;
30
+ }
31
+
32
+ return (
33
+ serializers.reduce((prev, current) => {
34
+ return current?.(node, children) || prev;
35
+ }, '') || children
36
+ );
37
+ }
38
+ };
@@ -0,0 +1,28 @@
1
+ .root {
2
+ position: relative;
3
+ display: flex;
4
+ flex-direction: column;
5
+ height: 100%;
6
+ color: var(--kona-editor-text-color, #444);
7
+ background-color: var(--kona-editor-background-color, #fff);
8
+ }
9
+
10
+ .editor {
11
+ outline: none;
12
+ overflow: auto;
13
+
14
+ &::-webkit-scrollbar {
15
+ background: rgba(0, 0, 0, 0.025);
16
+ width: 4px;
17
+ border-radius: 8px;
18
+ }
19
+
20
+ &::-webkit-scrollbar-thumb {
21
+ background: rgba(0, 0, 0, 0.075);
22
+ border-radius: 8px;
23
+ }
24
+
25
+ & > [role="textbox"] {
26
+ outline: none;
27
+ }
28
+ }
@@ -0,0 +1,10 @@
1
+ import type { Descendant } from 'slate';
2
+
3
+ export const defaultValue: { children: Descendant[] } = {
4
+ children: [
5
+ {
6
+ type: 'paragraph',
7
+ children: [{ text: '' }],
8
+ },
9
+ ],
10
+ };
package/src/editor.tsx ADDED
@@ -0,0 +1,55 @@
1
+ import { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
2
+ import { type Descendant, type NodeMatch, Transforms } from 'slate';
3
+ import { ReactEditor, Slate } from 'slate-react';
4
+ import type { CustomElement } from '../types';
5
+ import { createEditable } from './core/createEditable';
6
+ import { createEditor } from './core/createEditor';
7
+ import { deserialize } from './core/deserialize';
8
+ import { serialize } from './core/serialize';
9
+ import type { EditorRef, IPlugin } from './types';
10
+ import { isEmpty } from './utils';
11
+
12
+ type KonaEditorProps = {
13
+ readOnly?: boolean;
14
+ plugins?: IPlugin[];
15
+ initialValue: Descendant[];
16
+ onChange: (value: Descendant[]) => void;
17
+ };
18
+
19
+ export const KonaEditor = forwardRef<EditorRef, KonaEditorProps>(
20
+ (props, ref) => {
21
+ const { initialValue, plugins = [], readOnly = false, onChange } = props;
22
+
23
+ const [editor] = useState(createEditor(plugins));
24
+
25
+ const SlateEditable = useCallback(createEditable(editor, plugins), []);
26
+
27
+ useImperativeHandle(ref, () => {
28
+ const deleteNode = (match: NodeMatch<CustomElement>) => {
29
+ Transforms.removeNodes(editor, { at: [], match });
30
+ };
31
+
32
+ return {
33
+ serialize: serialize(plugins),
34
+ deserialize: deserialize(plugins),
35
+ deleteNode,
36
+ isEmpty: () => {
37
+ return isEmpty(editor.children);
38
+ },
39
+ focus: () => {
40
+ ReactEditor.focus(editor);
41
+ },
42
+ };
43
+ }, [editor, plugins]);
44
+
45
+ return (
46
+ <Slate
47
+ editor={editor}
48
+ initialValue={initialValue}
49
+ onValueChange={onChange}
50
+ >
51
+ <SlateEditable readOnly={readOnly} />
52
+ </Slate>
53
+ );
54
+ },
55
+ );
@@ -0,0 +1,5 @@
1
+ import { RenderElementProps } from 'slate-react';
2
+
3
+ export const BaseElement = (props: RenderElementProps) => {
4
+ return <p {...props.attributes}>{props.children}</p>;
5
+ };
@@ -0,0 +1,8 @@
1
+ .root {
2
+ position: fixed;
3
+ top: 0;
4
+ left: 0;
5
+ right: 0;
6
+ bottom: 0;
7
+ z-index: 1;
8
+ }