@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,51 @@
1
+ .root {
2
+ display: flex;
3
+ justify-content: space-between;
4
+ column-gap: 8px;
5
+ padding: 4px;
6
+ border-bottom: 1px solid var(--kona-editor-border-color);
7
+ }
8
+
9
+ .button {
10
+ width: 20px;
11
+ height: 20px;
12
+ border-radius: 4px;
13
+ display: inline-flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ cursor: pointer;
17
+ padding: 0;
18
+ margin: 0;
19
+ outline: none;
20
+ background-color: transparent;
21
+
22
+ &:active {
23
+ transform: scale(0.9);
24
+ }
25
+ }
26
+
27
+ .customMenu {
28
+ max-height: 250px;
29
+ width: 200px;
30
+ overflow-y: auto;
31
+ position: absolute;
32
+ background-color: var(--kona-editor-background-color);
33
+ border: 1px solid var(--kona-editor-border-color);
34
+ z-index: 21;
35
+ border-radius: 8px;
36
+ font-size: 12px;
37
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.025);
38
+
39
+ &::-webkit-scrollbar {
40
+ width: 6px;
41
+ }
42
+
43
+ &::-webkit-scrollbar-track {
44
+ background: transparent;
45
+ }
46
+
47
+ &::-webkit-scrollbar-thumb {
48
+ background-color: rgba(0, 0, 0, 0.25);
49
+ border-radius: 10px;
50
+ }
51
+ }
@@ -0,0 +1,99 @@
1
+ import { forwardRef, useMemo } from 'react';
2
+ import { Node } from 'slate';
3
+ import type { CustomElement } from '../../types';
4
+ import { CheckIcon } from './icons/check';
5
+ import { CopyIcon } from './icons/copy';
6
+ import styles from './LanguageSelector.module.css';
7
+ import { Button } from './ui/Button';
8
+ import { Dropdown } from './ui/Dropdown';
9
+ import { Menu as MenuBase, type MenuConfig } from './ui/Menu';
10
+
11
+ type Props = {
12
+ value: string;
13
+ onChange: (value: string) => void;
14
+ params: {
15
+ element: CustomElement;
16
+ };
17
+ };
18
+
19
+ const languages = [
20
+ { value: 'javascript', label: 'JavaScript' },
21
+ { value: 'typescript', label: 'TypeScript' },
22
+ { value: 'jsx', label: 'JSX' },
23
+ { value: 'tsx', label: 'TSX' },
24
+ { value: 'html', label: 'HTML' },
25
+ { value: 'css', label: 'CSS' },
26
+ { value: 'json', label: 'JSON' },
27
+ { value: 'python', label: 'Python' },
28
+ { value: 'java', label: 'Java' },
29
+ { value: 'c', label: 'C' },
30
+ { value: 'cpp', label: 'C++' },
31
+ { value: 'csharp', label: 'C#' },
32
+ { value: 'go', label: 'Go' },
33
+ { value: 'rust', label: 'Rust' },
34
+ { value: 'ruby', label: 'Ruby' },
35
+ { value: 'php', label: 'PHP' },
36
+ { value: 'bash', label: 'Bash' },
37
+ { value: 'sql', label: 'SQL' },
38
+ { value: 'markdown', label: 'Markdown' },
39
+ { value: 'yaml', label: 'YAML' },
40
+ { value: 'plaintext', label: 'Plain Text' },
41
+ ];
42
+
43
+ export const LanguageSelector = (props: Props) => {
44
+ const { value: language, onChange, params } = props;
45
+
46
+ const handleCopyClick = () => {
47
+ const text = Array.from(Node.texts(params.element))
48
+ .map((nodeEntry) => nodeEntry[0].text)
49
+ .join('\n');
50
+
51
+ navigator.clipboard.writeText(text);
52
+ };
53
+
54
+ // biome-ignore lint/correctness/useExhaustiveDependencies: we don't care about other deps
55
+ const menuConfig: MenuConfig = useMemo(
56
+ () => ({
57
+ items: languages.map(({ label, value }) => ({
58
+ render: () => (
59
+ <>
60
+ <MenuBase.Icon>
61
+ {value === language && <CheckIcon size={16} />}
62
+ </MenuBase.Icon>
63
+ <MenuBase.Title>{label}</MenuBase.Title>
64
+ </>
65
+ ),
66
+ onSelect: () => {
67
+ onChange(value);
68
+ },
69
+ })),
70
+ }),
71
+ [language],
72
+ );
73
+ return (
74
+ <div className={styles.root}>
75
+ <Dropdown
76
+ config={menuConfig}
77
+ Menu={forwardRef<HTMLDivElement, { className: string }>(
78
+ (props, ref) => (
79
+ <div
80
+ {...props}
81
+ ref={ref}
82
+ className={[styles.customMenu, props.className].join(' ')}
83
+ />
84
+ ),
85
+ )}
86
+ >
87
+ {({ ref, onClick }) => (
88
+ <Button ref={ref} size="sm" onClick={onClick}>
89
+ {languages.find((l) => l.value === language)?.label ||
90
+ 'Select language'}
91
+ </Button>
92
+ )}
93
+ </Dropdown>
94
+ <Button size="sm" type="button" onClick={handleCopyClick}>
95
+ <CopyIcon size={16} />
96
+ </Button>
97
+ </div>
98
+ );
99
+ };
@@ -0,0 +1,27 @@
1
+ .root {
2
+ display: flex;
3
+ border-radius: 4px;
4
+ background-color: var(--kona-editor-background-color, #fff);
5
+ border: 1px solid var(--kona-editor-border-color, #ddd);
6
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.025);
7
+ }
8
+
9
+ .button {
10
+ width: 20px;
11
+ height: 20px;
12
+ border-radius: 4px;
13
+ display: inline-flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ cursor: pointer;
17
+ padding: 0;
18
+ margin: 0;
19
+ outline: none;
20
+ background-color: transparent;
21
+ border: none;
22
+ opacity: 0.65;
23
+
24
+ &:hover {
25
+ opacity: 1;
26
+ }
27
+ }
@@ -0,0 +1,58 @@
1
+ import { Editor, Transforms } from 'slate';
2
+ import { ReactEditor } from 'slate-react';
3
+ import type { FloatingMenuPlugin, OptionsMethods } from '../plugins';
4
+ import { EditIcon } from './icons/edit';
5
+ import { ExternalIcon } from './icons/external';
6
+ import styles from './LinksHint.module.css';
7
+ import { $store } from './store';
8
+
9
+ type Props = {
10
+ methods: OptionsMethods;
11
+ floatingMenuPlugin: FloatingMenuPlugin;
12
+ };
13
+
14
+ export const LinksHint = (props: Props) => {
15
+ const { methods, floatingMenuPlugin } = props;
16
+
17
+ return (
18
+ <div className={styles.root}>
19
+ <button
20
+ type="button"
21
+ className={styles.button}
22
+ onMouseDown={(event) => {
23
+ event.preventDefault();
24
+ const element = methods.getLinkElement();
25
+ const editor = methods.getEditor();
26
+ const url = methods.getUrl();
27
+
28
+ if (!element) {
29
+ return;
30
+ }
31
+
32
+ const domElement = ReactEditor.toDOMNode(editor, element);
33
+ const path = ReactEditor.findPath(editor, element);
34
+ const range = Editor.range(editor, path);
35
+ Transforms.select(editor, range);
36
+
37
+ floatingMenuPlugin.openOnElement(domElement);
38
+ $store.setKey('floatingMenuMode', 'link');
39
+ $store.setKey('isFloatingMenuOpen', true);
40
+ $store.setKey('url', url);
41
+ }}
42
+ >
43
+ <EditIcon size={16} />
44
+ </button>
45
+ <button
46
+ type="button"
47
+ className={styles.button}
48
+ onMouseDown={(event) => {
49
+ event.preventDefault();
50
+ const url = methods.getUrl();
51
+ window.open(url, '_blank');
52
+ }}
53
+ >
54
+ <ExternalIcon size={16} />
55
+ </button>
56
+ </div>
57
+ );
58
+ };
@@ -0,0 +1,37 @@
1
+ .root {
2
+ padding: 8px;
3
+ display: flex;
4
+ column-gap: 4px;
5
+ background-color: var(--kona-editor-background-color);
6
+ border-bottom: 1px dotted var(--kona-editor-border-color);
7
+ color: var(--kona-editor-text-color);
8
+ width: 100%;
9
+ }
10
+
11
+ .button {
12
+ width: 20px;
13
+ height: 20px;
14
+ border-radius: 4px;
15
+ display: inline-flex;
16
+ align-items: center;
17
+ justify-content: center;
18
+ cursor: pointer;
19
+ padding: 0;
20
+ margin: 0;
21
+ outline: none;
22
+ background-color: transparent;
23
+ border: none;
24
+ color: inherit;
25
+ opacity: 0.65;
26
+ }
27
+
28
+ .active {
29
+ opacity: 1;
30
+ }
31
+
32
+ .divider {
33
+ display: inline-block;
34
+ border-left: 1px solid var(--kona-editor-border-color);
35
+ width: 1px;
36
+ height: 20px;
37
+ }
@@ -0,0 +1,80 @@
1
+ import type { Editor } from 'slate';
2
+ import { HeadingsPlugin, ListsPlugin } from '../plugins';
3
+ import { Heading1Icon } from './icons/heading1';
4
+ import { Heading2Icon } from './icons/heading2';
5
+ import { Heading3Icon } from './icons/heading3';
6
+ import { OlIcon } from './icons/ol';
7
+ import { UlIcon } from './icons/ul';
8
+ import styles from './Menu.module.css';
9
+
10
+ type Props = {
11
+ editor: Editor;
12
+ };
13
+
14
+ export const Menu = (props: Props) => {
15
+ const { editor } = props;
16
+
17
+ return (
18
+ <div className={styles.root}>
19
+ <button
20
+ type="button"
21
+ className={getButtonClassName(HeadingsPlugin.isHeading1Active(editor))}
22
+ onMouseDown={(event) => {
23
+ event.preventDefault();
24
+ HeadingsPlugin.toggleHeading1(editor);
25
+ }}
26
+ >
27
+ <Heading1Icon size={16} />
28
+ </button>
29
+ <button
30
+ type="button"
31
+ className={getButtonClassName(HeadingsPlugin.isHeading2Active(editor))}
32
+ onMouseDown={(event) => {
33
+ event.preventDefault();
34
+ HeadingsPlugin.toggleHeading2(editor);
35
+ }}
36
+ >
37
+ <Heading2Icon size={16} />
38
+ </button>
39
+ <button
40
+ type="button"
41
+ className={getButtonClassName(HeadingsPlugin.isHeading3Active(editor))}
42
+ onMouseDown={(event) => {
43
+ event.preventDefault();
44
+ HeadingsPlugin.toggleHeading3(editor);
45
+ }}
46
+ >
47
+ <Heading3Icon size={16} />
48
+ </button>
49
+ <span className={styles.divider} />
50
+ <button
51
+ type="button"
52
+ className={getButtonClassName(
53
+ ListsPlugin.isListActive(editor, ListsPlugin.BULLETED_LIST_ELEMENT),
54
+ )}
55
+ onMouseDown={(event) => {
56
+ event.preventDefault();
57
+ ListsPlugin.toggleList(editor, ListsPlugin.BULLETED_LIST_ELEMENT);
58
+ }}
59
+ >
60
+ <UlIcon size={16} />
61
+ </button>
62
+ <button
63
+ type="button"
64
+ className={getButtonClassName(
65
+ ListsPlugin.isListActive(editor, ListsPlugin.NUMBERED_LIST_ELEMENT),
66
+ )}
67
+ onMouseDown={(event) => {
68
+ event.preventDefault();
69
+ ListsPlugin.toggleList(editor, ListsPlugin.NUMBERED_LIST_ELEMENT);
70
+ }}
71
+ >
72
+ <OlIcon size={16} />
73
+ </button>
74
+ </div>
75
+ );
76
+ };
77
+
78
+ const getButtonClassName = (isActive: boolean) => {
79
+ return isActive ? [styles.button, styles.active].join(' ') : styles.button;
80
+ };
@@ -0,0 +1,11 @@
1
+ export enum Color {
2
+ Red = 'red',
3
+ Blue = 'blue',
4
+ Yellow = 'yellow',
5
+ }
6
+
7
+ export const colors = {
8
+ [Color.Red]: '#ff000055',
9
+ [Color.Blue]: '#0000ff55',
10
+ [Color.Yellow]: '#ffff0055',
11
+ };
@@ -0,0 +1,76 @@
1
+ import { type Command, HeadingsPlugin, ListsPlugin } from '../plugins';
2
+ import { Heading1Icon } from './icons/heading1';
3
+ import { Heading2Icon } from './icons/heading2';
4
+ import { Heading3Icon } from './icons/heading3';
5
+ import { OlIcon } from './icons/ol';
6
+ import { TextIcon } from './icons/text';
7
+ import { UlIcon } from './icons/ul';
8
+
9
+ export const getCommands = (): Command[] => {
10
+ return [
11
+ {
12
+ name: 'paragraph',
13
+ title: 'Paragraph',
14
+ icon: <TextIcon size={16} />,
15
+ commandName: 'paragraph',
16
+ action: (actions) => {
17
+ actions.set({ type: 'paragraph' });
18
+ },
19
+ },
20
+ {
21
+ name: 'heading-1',
22
+ title: 'Heading 1',
23
+ commandName: 'heading1',
24
+ icon: <Heading1Icon size={16} />,
25
+ action: (actions) => {
26
+ actions.set({ type: HeadingsPlugin.HeadingLevel1 });
27
+ },
28
+ },
29
+ {
30
+ name: 'heading-2',
31
+ title: 'Heading 2',
32
+ commandName: 'heading2',
33
+ icon: <Heading2Icon size={16} />,
34
+ action: (actions) => {
35
+ actions.set({ type: HeadingsPlugin.HeadingLevel2 });
36
+ },
37
+ },
38
+ {
39
+ name: 'heading-3',
40
+ title: 'Heading 3',
41
+ commandName: 'heading3',
42
+ icon: <Heading3Icon size={16} />,
43
+ action: (actions) => {
44
+ actions.set({ type: HeadingsPlugin.HeadingLevel3 });
45
+ },
46
+ },
47
+ {
48
+ name: 'ul',
49
+ title: 'Bulleted list',
50
+ commandName: 'bulleted list',
51
+ icon: <UlIcon size={16} />,
52
+ action: (actions, editor) => {
53
+ actions.removeCommand();
54
+ ListsPlugin.toggleList(
55
+ editor,
56
+ ListsPlugin.BULLETED_LIST_ELEMENT,
57
+ ListsPlugin.LIST_ITEM_ELEMENT,
58
+ );
59
+ },
60
+ },
61
+ {
62
+ name: 'ol',
63
+ title: 'Numbered list',
64
+ commandName: 'numbered list',
65
+ icon: <OlIcon size={16} />,
66
+ action: (actions, editor) => {
67
+ actions.removeCommand();
68
+ ListsPlugin.toggleList(
69
+ editor,
70
+ ListsPlugin.NUMBERED_LIST_ELEMENT,
71
+ ListsPlugin.LIST_ITEM_ELEMENT,
72
+ );
73
+ },
74
+ },
75
+ ];
76
+ };
@@ -0,0 +1,143 @@
1
+ import type { Editor } from 'slate';
2
+ import {
3
+ BasicFormattingPlugin,
4
+ BreaksPlugin,
5
+ CodeBlockPlugin,
6
+ type Commands,
7
+ CommandsPlugin,
8
+ DnDPlugin,
9
+ FloatingMenuPlugin,
10
+ HeadingsPlugin,
11
+ HighlightsPlugin,
12
+ LinksPlugin,
13
+ ListsPlugin,
14
+ MenuPlugin,
15
+ NodeIdPlugin,
16
+ PlaceholderPlugin,
17
+ ShortcutsPlugin,
18
+ TableOfContentsPlugin,
19
+ } from '../plugins';
20
+ import type { CodeElement } from '../plugins/CodeBlockPlugin/types';
21
+ import { Backdrop } from './Backdrop';
22
+ import { colors } from './colors';
23
+ import { DragBlock } from './DragBlock';
24
+ import { FloatingMenu } from './FloatingMenu';
25
+ import { getCommands } from './getCommands';
26
+ import { getShortcuts } from './getShortcuts';
27
+ import { LanguageSelector } from './LanguageSelector';
28
+ import { LinksHint } from './LinksHint';
29
+ import { Menu } from './Menu';
30
+ import { $store } from './store';
31
+
32
+ export const getPlugins = () => {
33
+ const floatingMenuPlugin = new FloatingMenuPlugin({
34
+ ignoreNodes: [CodeBlockPlugin.CODE_ELEMENT],
35
+ renderMenu: (editor: Editor, commands: Commands) => {
36
+ return (
37
+ <FloatingMenu $store={$store} editor={editor} commands={commands} />
38
+ );
39
+ },
40
+ renderBackdrop: (commands) => {
41
+ const handleClose = () => {
42
+ commands.onClose();
43
+ $store.setKey('isFloatingMenuOpen', false);
44
+ };
45
+
46
+ return <Backdrop onClose={handleClose} />;
47
+ },
48
+ onShow: () => {
49
+ $store.setKey('isFloatingMenuOpen', true);
50
+ return true;
51
+ },
52
+ onHide: () => {
53
+ if ($store.get().floatingMenuMode === 'main') {
54
+ $store.setKey('isFloatingMenuOpen', false);
55
+ $store.setKey('url', undefined);
56
+ return false;
57
+ }
58
+
59
+ return true;
60
+ },
61
+ });
62
+
63
+ return [
64
+ new BasicFormattingPlugin(),
65
+ new PlaceholderPlugin({
66
+ focused: 'Write / to open command menu',
67
+ unfocused: 'Write / to open command menu',
68
+ ignoreNodes: [CodeBlockPlugin.CODE_LINE_ELEMENT],
69
+ }),
70
+ new NodeIdPlugin({
71
+ generateId: () => Math.random().toString(36).substring(2, 15),
72
+ }),
73
+ new HeadingsPlugin(),
74
+ new MenuPlugin({
75
+ renderMenu: ({ editor }) => {
76
+ return <Menu editor={editor} />;
77
+ },
78
+ }),
79
+ new DnDPlugin({
80
+ renderBlock: (params) => {
81
+ return <DragBlock {...params} />;
82
+ },
83
+ onDropFiles: () => {},
84
+ ignoreNodes: [
85
+ CodeBlockPlugin.CODE_LINE_ELEMENT,
86
+ ListsPlugin.BULLETED_LIST_ELEMENT,
87
+ ListsPlugin.NUMBERED_LIST_ELEMENT,
88
+ ],
89
+ }),
90
+ new ShortcutsPlugin({
91
+ shortcuts: getShortcuts(),
92
+ ignoreNodes: [
93
+ CodeBlockPlugin.CODE_ELEMENT,
94
+ CodeBlockPlugin.CODE_LINE_ELEMENT,
95
+ ],
96
+ }),
97
+ new LinksPlugin({
98
+ renderHint: (methods) => (
99
+ <LinksHint floatingMenuPlugin={floatingMenuPlugin} methods={methods} />
100
+ ),
101
+ }),
102
+ new CommandsPlugin({
103
+ commands: getCommands(),
104
+ renderMenu: (children) => {
105
+ return <div>{children}</div>;
106
+ },
107
+ ignoreNodes: [CodeBlockPlugin.CODE_LINE_ELEMENT],
108
+ }),
109
+ new TableOfContentsPlugin({
110
+ levels: {
111
+ [HeadingsPlugin.HeadingLevel1]: 1,
112
+ [HeadingsPlugin.HeadingLevel2]: 2,
113
+ [HeadingsPlugin.HeadingLevel3]: 3,
114
+ },
115
+ }),
116
+ floatingMenuPlugin,
117
+ new HighlightsPlugin({
118
+ colors,
119
+ }),
120
+ new BreaksPlugin({
121
+ breakNodes: [
122
+ HeadingsPlugin.HeadingLevel1,
123
+ HeadingsPlugin.HeadingLevel2,
124
+ HeadingsPlugin.HeadingLevel3,
125
+ ],
126
+ }),
127
+ new ListsPlugin({}),
128
+ new CodeBlockPlugin({
129
+ renderLanguageSelector: (value, onChange, params) => {
130
+ return (
131
+ <LanguageSelector
132
+ value={value}
133
+ onChange={onChange}
134
+ params={{
135
+ ...params,
136
+ element: params.element as CodeElement,
137
+ }}
138
+ />
139
+ );
140
+ },
141
+ }),
142
+ ];
143
+ };
@@ -0,0 +1,107 @@
1
+ import { Editor, Transforms } from 'slate';
2
+ import { type ChangeMatch, HeadingsPlugin, type Shortcut } from '../plugins';
3
+
4
+ export const getShortcuts = (): Shortcut[] => {
5
+ return [
6
+ {
7
+ trigger: ' ',
8
+ before: /\*\*/g,
9
+ after: /\*\*/g,
10
+ change(editor: Editor, match) {
11
+ replaceWithMarkedText(editor, match, 'bold');
12
+ },
13
+ },
14
+ {
15
+ trigger: ' ',
16
+ before: /\*/g,
17
+ after: /\*/g,
18
+ change(editor: Editor, match) {
19
+ replaceWithMarkedText(editor, match, 'italic');
20
+ },
21
+ },
22
+ {
23
+ trigger: ' ',
24
+ before: /~~/g,
25
+ after: /~~/g,
26
+ change(editor: Editor, match) {
27
+ replaceWithMarkedText(editor, match, 'strikethrough');
28
+ },
29
+ },
30
+ {
31
+ trigger: ' ',
32
+ before: /^###/g,
33
+ change(editor, match) {
34
+ replaceWithHeading(editor, match, HeadingsPlugin.HeadingLevel3);
35
+ },
36
+ },
37
+ {
38
+ trigger: ' ',
39
+ before: /^##/g,
40
+ change(editor, match) {
41
+ replaceWithHeading(editor, match, HeadingsPlugin.HeadingLevel2);
42
+ },
43
+ },
44
+ {
45
+ trigger: ' ',
46
+ before: /^#/g,
47
+ change(editor, match) {
48
+ replaceWithHeading(editor, match, HeadingsPlugin.HeadingLevel1);
49
+ },
50
+ },
51
+ ];
52
+ };
53
+
54
+ const replaceWithHeading = (
55
+ editor: Editor,
56
+ match: ChangeMatch,
57
+ type: string,
58
+ ) => {
59
+ Editor.withoutNormalizing(editor, () => {
60
+ const { selection } = editor;
61
+
62
+ if (selection) {
63
+ Transforms.delete(editor, {
64
+ at: selection.focus,
65
+ distance: match.before?.[0].length,
66
+ reverse: true,
67
+ unit: 'character',
68
+ });
69
+
70
+ Transforms.setNodes(editor, {
71
+ type,
72
+ });
73
+ }
74
+ });
75
+ };
76
+
77
+ const replaceWithMarkedText = (
78
+ editor: Editor,
79
+ match: ChangeMatch,
80
+ mark: string,
81
+ ) => {
82
+ Editor.withoutNormalizing(editor, () => {
83
+ if (!editor.selection) {
84
+ return;
85
+ }
86
+
87
+ Transforms.delete(editor, {
88
+ at: editor.selection?.focus,
89
+ distance: match.text?.length || 0,
90
+ reverse: true,
91
+ unit: 'character',
92
+ });
93
+ Transforms.insertText(editor, match.cleanText || '');
94
+ Transforms.setSelection(editor, {
95
+ anchor: editor.selection?.focus,
96
+ focus: {
97
+ path: editor.selection?.focus.path,
98
+ offset: editor.selection?.focus.offset - (match.cleanText?.length || 0),
99
+ },
100
+ });
101
+ Editor.addMark(editor, mark, true);
102
+ Transforms.setSelection(editor, {
103
+ anchor: editor.selection.anchor,
104
+ focus: editor.selection.anchor,
105
+ });
106
+ });
107
+ };