@crystallize/design-system 1.4.0 → 1.4.2

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 (380) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/TableComponent-I2YOOYOU.css +281 -0
  3. package/dist/TableComponent-QINOO453.mjs +1377 -0
  4. package/dist/arrow-clockwise-Z2G6UEGP.svg +1 -0
  5. package/dist/arrow-counterclockwise-2O5EYVJT.svg +1 -0
  6. package/dist/bg-color-HB2WDYGO.svg +1 -0
  7. package/dist/camera-CR7D2PNH.svg +1 -0
  8. package/dist/caret-right-fill-FFBNEXVX.svg +1 -0
  9. package/dist/chat-square-quote-CI6PUJHH.svg +1 -0
  10. package/dist/chevron-down-3FRWSIKS.svg +1 -0
  11. package/dist/chunk-VUXQZRSP.mjs +737 -0
  12. package/dist/clipboard-OSEFDF25.svg +1 -0
  13. package/dist/close-FH57ZMJF.svg +1 -0
  14. package/dist/code-SEVR6TIQ.svg +1 -0
  15. package/dist/copy-DMGDODUL.svg +1 -0
  16. package/dist/diagram-2-CEJUD2B4.svg +1 -0
  17. package/dist/download-JXUGIUCX.svg +1 -0
  18. package/dist/draggable-block-menu-KKHDNKJA.svg +1 -0
  19. package/dist/dropdown-more-BHZ5COKX.svg +1 -0
  20. package/dist/file-image-TIQPFJX4.svg +1 -0
  21. package/dist/filetype-gif-OG2BEYYK.svg +1 -0
  22. package/dist/font-color-J4GA3ZJO.svg +1 -0
  23. package/dist/font-family-ZU5N6TTE.svg +1 -0
  24. package/dist/gear-ICMT4NTP.svg +1 -0
  25. package/dist/horizontal-rule-N6RD2V7H.svg +1 -0
  26. package/dist/indent-MJ6JIMCK.svg +1 -0
  27. package/dist/index.css +4209 -0
  28. package/dist/index.d.ts +450 -3
  29. package/dist/index.js +11526 -5
  30. package/dist/index.mjs +9437 -0
  31. package/dist/journal-code-XUT44HDV.svg +1 -0
  32. package/dist/justify-J7X5JEEX.svg +1 -0
  33. package/dist/link-W52N4JKZ.svg +1 -0
  34. package/dist/list-ol-2ZEUN4Z7.svg +1 -0
  35. package/dist/list-ul-DVKNUP47.svg +1 -0
  36. package/dist/lock-WCYOZOHW.svg +1 -0
  37. package/dist/lock-fill-JZSKOSHK.svg +1 -0
  38. package/dist/markdown-4BGQNLLT.svg +1 -0
  39. package/dist/mic-H5FNOMM7.svg +1 -0
  40. package/dist/outdent-2LUMUMIP.svg +1 -0
  41. package/dist/paint-bucket-VCISMZTH.svg +1 -0
  42. package/dist/palette-SWGFPRWZ.svg +1 -0
  43. package/dist/pencil-fill-STFSC26F.svg +1 -0
  44. package/dist/plug-HGGGEVS3.svg +1 -0
  45. package/dist/plug-fill-OTG3U4TN.svg +1 -0
  46. package/dist/plus-CQISIKEC.svg +1 -0
  47. package/dist/plus-slash-minus-N22JU4TI.svg +1 -0
  48. package/dist/prettier-WUJ7B5NV.svg +1 -0
  49. package/dist/prettier-error-DYJSLYDP.svg +1 -0
  50. package/dist/square-check-UTG6FU6D.svg +1 -0
  51. package/dist/success-YVXUMPEZ.svg +1 -0
  52. package/dist/table-BR6DI4ZQ.svg +1 -0
  53. package/dist/text-center-UQI6PAEF.svg +1 -0
  54. package/dist/text-left-KT2B6TR3.svg +1 -0
  55. package/dist/text-paragraph-MFTUIIQG.svg +1 -0
  56. package/dist/text-right-SKELPISG.svg +1 -0
  57. package/dist/trash-UOM6D7TD.svg +1 -0
  58. package/dist/type-bold-PY7COC3N.svg +1 -0
  59. package/dist/type-h1-6KJP7YOM.svg +1 -0
  60. package/dist/type-h2-VHI2USC3.svg +1 -0
  61. package/dist/type-h3-JIU77CHO.svg +1 -0
  62. package/dist/type-h4-P5EHKDAL.svg +1 -0
  63. package/dist/type-h5-CS2KYVRG.svg +1 -0
  64. package/dist/type-h6-J2O74LJZ.svg +1 -0
  65. package/dist/type-italic-3DSFOSG2.svg +1 -0
  66. package/dist/type-strikethrough-E2KKQFSX.svg +1 -0
  67. package/dist/type-subscript-BMPTRIBU.svg +1 -0
  68. package/dist/type-superscript-EDF6EPAA.svg +1 -0
  69. package/dist/type-underline-CBFA5VLF.svg +1 -0
  70. package/dist/upload-Q6KICGZW.svg +1 -0
  71. package/dist/user-EOI2NEFZ.svg +1 -0
  72. package/package.json +114 -79
  73. package/readme.md +9 -0
  74. package/src/action-menu/ActionMenu.stories.tsx +25 -0
  75. package/src/action-menu/action-item.tsx +16 -0
  76. package/src/action-menu/action-menu.css +38 -0
  77. package/src/action-menu/action-menu.tsx +25 -0
  78. package/src/action-menu/index.tsx +3 -0
  79. package/src/avatar/Avatar.stories.tsx +20 -0
  80. package/src/avatar/avatar.css +23 -0
  81. package/src/avatar/avatar.tsx +34 -0
  82. package/src/avatar/get-initials.ts +5 -0
  83. package/src/avatar/index.ts +1 -0
  84. package/src/button/Button.stories.tsx +105 -0
  85. package/src/button/button.css +116 -0
  86. package/src/button/button.tsx +136 -0
  87. package/src/button/index.ts +3 -0
  88. package/src/card/card.css +7 -0
  89. package/src/card/card.stories.tsx +24 -0
  90. package/src/card/card.tsx +27 -0
  91. package/src/card/index.ts +3 -0
  92. package/src/checkbox/checkbox.css +30 -0
  93. package/src/checkbox/checkbox.stories.tsx +62 -0
  94. package/src/checkbox/checkbox.test.tsx +16 -0
  95. package/src/checkbox/checkbox.tsx +28 -0
  96. package/src/checkbox/index.ts +1 -0
  97. package/src/colors/Colors.stories.tsx +127 -0
  98. package/src/colors/color-defaults.json +15 -0
  99. package/src/colors/color-pairing.json +12 -0
  100. package/src/colors/colors.json +158 -0
  101. package/src/colors/index.ts +1 -0
  102. package/src/colors/old-to-new.txt +19 -0
  103. package/src/colors/types.ts +29 -0
  104. package/src/dialog/Dialog.stories.tsx +168 -0
  105. package/src/dialog/Dialog.test.tsx +25 -0
  106. package/src/dialog/config.tsx +139 -0
  107. package/src/dialog/confirm-dialog.tsx +70 -0
  108. package/src/dialog/destroyFns.ts +1 -0
  109. package/src/dialog/dialog.css +27 -0
  110. package/src/dialog/dialog.tsx +95 -0
  111. package/src/dialog/index.tsx +40 -0
  112. package/src/dialog/types.ts +70 -0
  113. package/src/dropdown-menu/DropdownMenu.stories.tsx +38 -0
  114. package/src/dropdown-menu/dropdown-menu-item.tsx +15 -0
  115. package/src/dropdown-menu/dropdown-menu-label.tsx +10 -0
  116. package/src/dropdown-menu/dropdown-menu-root.tsx +33 -0
  117. package/src/dropdown-menu/dropdown-menu.css +20 -0
  118. package/src/dropdown-menu/index.ts +11 -0
  119. package/src/icon-button/IconButton.stories.tsx +45 -0
  120. package/src/icon-button/icon-button.css +50 -0
  121. package/src/icon-button/icon-button.tsx +39 -0
  122. package/src/icon-button/index.ts +3 -0
  123. package/src/iconography/Icon.stories.tsx +47 -0
  124. package/src/iconography/add.tsx +30 -0
  125. package/src/iconography/arrow.tsx +15 -0
  126. package/src/iconography/atom.tsx +59 -0
  127. package/src/iconography/cancel.tsx +26 -0
  128. package/src/iconography/catalogue.tsx +26 -0
  129. package/src/iconography/copy.tsx +24 -0
  130. package/src/iconography/crystal.tsx +93 -0
  131. package/src/iconography/customers.tsx +38 -0
  132. package/src/iconography/edit.tsx +30 -0
  133. package/src/iconography/error.tsx +40 -0
  134. package/src/iconography/fulfilment.tsx +58 -0
  135. package/src/iconography/glasses.tsx +62 -0
  136. package/src/iconography/graphQL.tsx +90 -0
  137. package/src/iconography/grid.tsx +84 -0
  138. package/src/iconography/hooks.tsx +26 -0
  139. package/src/iconography/image.tsx +47 -0
  140. package/src/iconography/index.ts +63 -0
  141. package/src/iconography/info.tsx +41 -0
  142. package/src/iconography/key.tsx +19 -0
  143. package/src/iconography/language.tsx +38 -0
  144. package/src/iconography/nail-polish.tsx +84 -0
  145. package/src/iconography/order.tsx +38 -0
  146. package/src/iconography/particle.tsx +88 -0
  147. package/src/iconography/percentage.tsx +44 -0
  148. package/src/iconography/price-tag.tsx +40 -0
  149. package/src/iconography/shapes.tsx +48 -0
  150. package/src/iconography/subscription.tsx +34 -0
  151. package/src/iconography/topics.tsx +58 -0
  152. package/src/iconography/triangle.tsx +27 -0
  153. package/src/iconography/usage.tsx +34 -0
  154. package/src/iconography/users.tsx +44 -0
  155. package/src/iconography/warning.tsx +51 -0
  156. package/src/index.css +14 -0
  157. package/src/index.ts +33 -0
  158. package/src/inline-radio/index.ts +1 -0
  159. package/src/inline-radio/inline-radio.css +36 -0
  160. package/src/inline-radio/inline-radio.stories.tsx +81 -0
  161. package/src/inline-radio/inline-radio.tsx +41 -0
  162. package/src/input/Input.stories.tsx +26 -0
  163. package/src/input/index.ts +1 -0
  164. package/src/input/input.css +7 -0
  165. package/src/input/input.tsx +20 -0
  166. package/src/input-with-label/InputWithLabel.stories.tsx +98 -0
  167. package/src/input-with-label/index.ts +3 -0
  168. package/src/input-with-label/input-with-label.css +35 -0
  169. package/src/input-with-label/input-with-label.tsx +59 -0
  170. package/src/label/index.ts +1 -0
  171. package/src/label/label.css +3 -0
  172. package/src/label/label.stories.tsx +19 -0
  173. package/src/label/label.tsx +13 -0
  174. package/src/progress/Progress.stories.tsx +26 -0
  175. package/src/progress/index.ts +1 -0
  176. package/src/progress/progress.css +7 -0
  177. package/src/progress/progress.tsx +17 -0
  178. package/src/radio/index.ts +1 -0
  179. package/src/radio/radio.css +20 -0
  180. package/src/radio/radio.stories.tsx +142 -0
  181. package/src/radio/radio.tsx +19 -0
  182. package/src/rich-text-editor/appSettings.ts +28 -0
  183. package/src/rich-text-editor/context/SettingsContext.tsx +71 -0
  184. package/src/rich-text-editor/context/SharedAutocompleteContext.tsx +60 -0
  185. package/src/rich-text-editor/context/SharedHistoryContext.tsx +25 -0
  186. package/src/rich-text-editor/hooks/useReport.ts +64 -0
  187. package/src/rich-text-editor/images/cat-typing.gif +0 -0
  188. package/src/rich-text-editor/images/emoji/1F600.png +0 -0
  189. package/src/rich-text-editor/images/emoji/1F641.png +0 -0
  190. package/src/rich-text-editor/images/emoji/1F642.png +0 -0
  191. package/src/rich-text-editor/images/emoji/2764.png +0 -0
  192. package/src/rich-text-editor/images/emoji/LICENSE.md +5 -0
  193. package/src/rich-text-editor/images/icons/LICENSE.md +5 -0
  194. package/src/rich-text-editor/images/icons/arrow-clockwise.svg +1 -0
  195. package/src/rich-text-editor/images/icons/arrow-counterclockwise.svg +1 -0
  196. package/src/rich-text-editor/images/icons/bg-color.svg +1 -0
  197. package/src/rich-text-editor/images/icons/camera.svg +1 -0
  198. package/src/rich-text-editor/images/icons/card-checklist.svg +1 -0
  199. package/src/rich-text-editor/images/icons/caret-right-fill.svg +1 -0
  200. package/src/rich-text-editor/images/icons/chat-left-text.svg +1 -0
  201. package/src/rich-text-editor/images/icons/chat-right-dots.svg +1 -0
  202. package/src/rich-text-editor/images/icons/chat-right-text.svg +1 -0
  203. package/src/rich-text-editor/images/icons/chat-right.svg +1 -0
  204. package/src/rich-text-editor/images/icons/chat-square-quote.svg +1 -0
  205. package/src/rich-text-editor/images/icons/chevron-down.svg +1 -0
  206. package/src/rich-text-editor/images/icons/clipboard.svg +1 -0
  207. package/src/rich-text-editor/images/icons/close.svg +1 -0
  208. package/src/rich-text-editor/images/icons/code.svg +1 -0
  209. package/src/rich-text-editor/images/icons/comments.svg +1 -0
  210. package/src/rich-text-editor/images/icons/copy.svg +1 -0
  211. package/src/rich-text-editor/images/icons/diagram-2.svg +1 -0
  212. package/src/rich-text-editor/images/icons/download.svg +1 -0
  213. package/src/rich-text-editor/images/icons/draggable-block-menu.svg +1 -0
  214. package/src/rich-text-editor/images/icons/dropdown-more.svg +1 -0
  215. package/src/rich-text-editor/images/icons/figma.svg +1 -0
  216. package/src/rich-text-editor/images/icons/file-image.svg +1 -0
  217. package/src/rich-text-editor/images/icons/filetype-gif.svg +1 -0
  218. package/src/rich-text-editor/images/icons/font-color.svg +1 -0
  219. package/src/rich-text-editor/images/icons/font-family.svg +1 -0
  220. package/src/rich-text-editor/images/icons/gear.svg +1 -0
  221. package/src/rich-text-editor/images/icons/horizontal-rule.svg +1 -0
  222. package/src/rich-text-editor/images/icons/indent.svg +1 -0
  223. package/src/rich-text-editor/images/icons/journal-code.svg +1 -0
  224. package/src/rich-text-editor/images/icons/journal-text.svg +1 -0
  225. package/src/rich-text-editor/images/icons/justify.svg +1 -0
  226. package/src/rich-text-editor/images/icons/link.svg +1 -0
  227. package/src/rich-text-editor/images/icons/list-ol.svg +1 -0
  228. package/src/rich-text-editor/images/icons/list-ul.svg +1 -0
  229. package/src/rich-text-editor/images/icons/lock-fill.svg +1 -0
  230. package/src/rich-text-editor/images/icons/lock.svg +1 -0
  231. package/src/rich-text-editor/images/icons/markdown.svg +1 -0
  232. package/src/rich-text-editor/images/icons/mic.svg +1 -0
  233. package/src/rich-text-editor/images/icons/outdent.svg +1 -0
  234. package/src/rich-text-editor/images/icons/paint-bucket.svg +1 -0
  235. package/src/rich-text-editor/images/icons/palette.svg +1 -0
  236. package/src/rich-text-editor/images/icons/pencil-fill.svg +1 -0
  237. package/src/rich-text-editor/images/icons/plug-fill.svg +1 -0
  238. package/src/rich-text-editor/images/icons/plug.svg +1 -0
  239. package/src/rich-text-editor/images/icons/plus-slash-minus.svg +1 -0
  240. package/src/rich-text-editor/images/icons/plus.svg +1 -0
  241. package/src/rich-text-editor/images/icons/prettier-error.svg +1 -0
  242. package/src/rich-text-editor/images/icons/prettier.svg +1 -0
  243. package/src/rich-text-editor/images/icons/send.svg +1 -0
  244. package/src/rich-text-editor/images/icons/square-check.svg +1 -0
  245. package/src/rich-text-editor/images/icons/sticky.svg +1 -0
  246. package/src/rich-text-editor/images/icons/success.svg +1 -0
  247. package/src/rich-text-editor/images/icons/table.svg +1 -0
  248. package/src/rich-text-editor/images/icons/text-center.svg +1 -0
  249. package/src/rich-text-editor/images/icons/text-left.svg +1 -0
  250. package/src/rich-text-editor/images/icons/text-paragraph.svg +1 -0
  251. package/src/rich-text-editor/images/icons/text-right.svg +1 -0
  252. package/src/rich-text-editor/images/icons/trash.svg +1 -0
  253. package/src/rich-text-editor/images/icons/trash3.svg +1 -0
  254. package/src/rich-text-editor/images/icons/tweet.svg +1 -0
  255. package/src/rich-text-editor/images/icons/type-bold.svg +1 -0
  256. package/src/rich-text-editor/images/icons/type-h1.svg +1 -0
  257. package/src/rich-text-editor/images/icons/type-h2.svg +1 -0
  258. package/src/rich-text-editor/images/icons/type-h3.svg +1 -0
  259. package/src/rich-text-editor/images/icons/type-h4.svg +1 -0
  260. package/src/rich-text-editor/images/icons/type-h5.svg +1 -0
  261. package/src/rich-text-editor/images/icons/type-h6.svg +1 -0
  262. package/src/rich-text-editor/images/icons/type-italic.svg +1 -0
  263. package/src/rich-text-editor/images/icons/type-strikethrough.svg +1 -0
  264. package/src/rich-text-editor/images/icons/type-subscript.svg +1 -0
  265. package/src/rich-text-editor/images/icons/type-superscript.svg +1 -0
  266. package/src/rich-text-editor/images/icons/type-underline.svg +1 -0
  267. package/src/rich-text-editor/images/icons/upload.svg +1 -0
  268. package/src/rich-text-editor/images/icons/user.svg +1 -0
  269. package/src/rich-text-editor/images/icons/youtube.svg +1 -0
  270. package/src/rich-text-editor/images/image/LICENSE.md +5 -0
  271. package/src/rich-text-editor/images/landscape.jpg +0 -0
  272. package/src/rich-text-editor/images/logo.svg +1 -0
  273. package/src/rich-text-editor/images/yellow-flower-small.jpg +0 -0
  274. package/src/rich-text-editor/images/yellow-flower.jpg +0 -0
  275. package/src/rich-text-editor/index.ts +1 -0
  276. package/src/rich-text-editor/model/crystallize-rich-text-types/code.ts +39 -0
  277. package/src/rich-text-editor/model/crystallize-rich-text-types/headings.ts +12 -0
  278. package/src/rich-text-editor/model/crystallize-rich-text-types/index.ts +69 -0
  279. package/src/rich-text-editor/model/crystallize-rich-text-types/link.ts +9 -0
  280. package/src/rich-text-editor/model/crystallize-rich-text-types/table.ts +16 -0
  281. package/src/rich-text-editor/model/crystallize-to-lexical.ts +186 -0
  282. package/src/rich-text-editor/model/lexical-to-crystallize.ts +232 -0
  283. package/src/rich-text-editor/nodes/AutocompleteNode.tsx +96 -0
  284. package/src/rich-text-editor/nodes/BaseNodes.ts +45 -0
  285. package/src/rich-text-editor/nodes/KeywordNode.ts +73 -0
  286. package/src/rich-text-editor/nodes/TableCellNodes.ts +31 -0
  287. package/src/rich-text-editor/nodes/TableComponent.tsx +1547 -0
  288. package/src/rich-text-editor/nodes/TableNode.tsx +398 -0
  289. package/src/rich-text-editor/plugins/ActionsPlugin/index.tsx +83 -0
  290. package/src/rich-text-editor/plugins/AutoLinkPlugin/index.tsx +47 -0
  291. package/src/rich-text-editor/plugins/AutocompletePlugin/index.tsx +2536 -0
  292. package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +60 -0
  293. package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +14 -0
  294. package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +140 -0
  295. package/src/rich-text-editor/plugins/CodeActionMenuPlugin/index.css +46 -0
  296. package/src/rich-text-editor/plugins/CodeActionMenuPlugin/index.tsx +155 -0
  297. package/src/rich-text-editor/plugins/CodeHighlightPlugin/index.ts +21 -0
  298. package/src/rich-text-editor/plugins/ComponentPickerPlugin/index.tsx +320 -0
  299. package/src/rich-text-editor/plugins/DragDropPastePlugin/index.ts +40 -0
  300. package/src/rich-text-editor/plugins/DraggableBlockPlugin/index.css +36 -0
  301. package/src/rich-text-editor/plugins/DraggableBlockPlugin/index.tsx +368 -0
  302. package/src/rich-text-editor/plugins/FloatingLinkEditorPlugin/index.css +40 -0
  303. package/src/rich-text-editor/plugins/FloatingLinkEditorPlugin/index.tsx +305 -0
  304. package/src/rich-text-editor/plugins/FloatingTextFormatToolbarPlugin/index.css +128 -0
  305. package/src/rich-text-editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +351 -0
  306. package/src/rich-text-editor/plugins/LinkPlugin/index.tsx +16 -0
  307. package/src/rich-text-editor/plugins/ListMaxIndentLevelPlugin/index.ts +86 -0
  308. package/src/rich-text-editor/plugins/MarkdownShortcutPlugin/index.tsx +16 -0
  309. package/src/rich-text-editor/plugins/MarkdownTransformers/index.ts +195 -0
  310. package/src/rich-text-editor/plugins/MaxLengthPlugin/index.tsx +49 -0
  311. package/src/rich-text-editor/plugins/SpeechToTextPlugin/index.ts +113 -0
  312. package/src/rich-text-editor/plugins/TabFocusPlugin/index.tsx +65 -0
  313. package/src/rich-text-editor/plugins/TableActionMenuPlugin/index.tsx +481 -0
  314. package/src/rich-text-editor/plugins/TableCellResizer/index.css +12 -0
  315. package/src/rich-text-editor/plugins/TableCellResizer/index.tsx +386 -0
  316. package/src/rich-text-editor/plugins/TablePlugin.tsx +190 -0
  317. package/src/rich-text-editor/plugins/ToolbarPlugin/index.tsx +726 -0
  318. package/src/rich-text-editor/plugins/TreeViewPlugin/index.tsx +25 -0
  319. package/src/rich-text-editor/plugins/TypingPerfPlugin/index.ts +117 -0
  320. package/src/rich-text-editor/rich-text-editor.css +1361 -0
  321. package/src/rich-text-editor/rich-text-editor.stories.tsx +385 -0
  322. package/src/rich-text-editor/rich-text-editor.tsx +228 -0
  323. package/src/rich-text-editor/tests/rich-text-editor-basic-rendering.test.tsx +47 -0
  324. package/src/rich-text-editor/tests/rich-text-editor-code.test.tsx +39 -0
  325. package/src/rich-text-editor/tests/rich-text-editor-model-basics.test.tsx +56 -0
  326. package/src/rich-text-editor/tests/rich-text-editor-model-conversions.test.tsx +195 -0
  327. package/src/rich-text-editor/tests/rich-text-editor-onchange.test.tsx +37 -0
  328. package/src/rich-text-editor/tests/rich-text-editor-quote.test.tsx +36 -0
  329. package/src/rich-text-editor/tests/rich-text-editor-text-formats.test.tsx +135 -0
  330. package/src/rich-text-editor/tests/rich-text-editor-typing.test.tsx +73 -0
  331. package/src/rich-text-editor/tests/utils.ts +23 -0
  332. package/src/rich-text-editor/themes/PlaygroundEditorTheme.css +433 -0
  333. package/src/rich-text-editor/themes/PlaygroundEditorTheme.ts +113 -0
  334. package/src/rich-text-editor/types.ts +5 -0
  335. package/src/rich-text-editor/ui/ContentEditable.css +13 -0
  336. package/src/rich-text-editor/ui/ContentEditable.tsx +15 -0
  337. package/src/rich-text-editor/ui/LinkPreview.css +57 -0
  338. package/src/rich-text-editor/ui/LinkPreview.tsx +169 -0
  339. package/src/rich-text-editor/utils/environment.ts +1 -0
  340. package/src/rich-text-editor/utils/getDOMRangeRect.ts +42 -0
  341. package/src/rich-text-editor/utils/getSelectedNode.ts +27 -0
  342. package/src/rich-text-editor/utils/guard.ts +10 -0
  343. package/src/rich-text-editor/utils/isMobileWidth.ts +7 -0
  344. package/src/rich-text-editor/utils/joinClasses.ts +13 -0
  345. package/src/rich-text-editor/utils/point.ts +55 -0
  346. package/src/rich-text-editor/utils/rect.ts +158 -0
  347. package/src/rich-text-editor/utils/setFloatingElemPosition.ts +46 -0
  348. package/src/rich-text-editor/utils/swipe.ts +127 -0
  349. package/src/rich-text-editor/utils/url.ts +33 -0
  350. package/src/select/index.ts +1 -0
  351. package/src/select/select-item.tsx +18 -0
  352. package/src/select/select-root.tsx +50 -0
  353. package/src/select/select.css +44 -0
  354. package/src/select/select.stories.tsx +74 -0
  355. package/src/select/select.ts +9 -0
  356. package/src/slider/Slider.stories.tsx +54 -0
  357. package/src/slider/index.ts +1 -0
  358. package/src/slider/slider.css +27 -0
  359. package/src/slider/slider.tsx +20 -0
  360. package/src/spinner/Spinner.stories.tsx +19 -0
  361. package/src/spinner/index.tsx +48 -0
  362. package/src/spinner/spinner.css +11 -0
  363. package/src/tag/Tag.stories.tsx +32 -0
  364. package/src/tag/index.ts +1 -0
  365. package/src/tag/tag.css +7 -0
  366. package/src/tag/tag.tsx +27 -0
  367. package/src/vite-env.d.ts +1 -0
  368. package/tailwind.config.cjs +51 -0
  369. package/LICENSE +0 -21
  370. package/README.md +0 -87
  371. package/dist/components/Button.d.ts +0 -11
  372. package/dist/components/Checkbox.d.ts +0 -29
  373. package/dist/components/Typography.d.ts +0 -14
  374. package/dist/design-system.cjs.development.js +0 -251
  375. package/dist/design-system.cjs.development.js.map +0 -1
  376. package/dist/design-system.cjs.production.min.js +0 -2
  377. package/dist/design-system.cjs.production.min.js.map +0 -1
  378. package/dist/design-system.esm.js +0 -245
  379. package/dist/design-system.esm.js.map +0 -1
  380. package/dist/styles/theme.d.ts +0 -2
@@ -0,0 +1,368 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import './index.css';
9
+
10
+ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
11
+ import {eventFiles} from '@lexical/rich-text';
12
+ import {mergeRegister} from '@lexical/utils';
13
+ import {
14
+ $getNearestNodeFromDOMNode,
15
+ $getNodeByKey,
16
+ $getRoot,
17
+ COMMAND_PRIORITY_HIGH,
18
+ COMMAND_PRIORITY_LOW,
19
+ DRAGOVER_COMMAND,
20
+ DROP_COMMAND,
21
+ LexicalEditor,
22
+ } from 'lexical';
23
+ import * as React from 'react';
24
+ import {DragEvent as ReactDragEvent, useEffect, useRef, useState} from 'react';
25
+ import {createPortal} from 'react-dom';
26
+
27
+ import {isHTMLElement} from '../../utils/guard';
28
+ import {Point} from '../../utils/point';
29
+ import {Rect} from '../../utils/rect';
30
+
31
+ const SPACE = 4;
32
+ const TARGET_LINE_HALF_HEIGHT = 2;
33
+ const DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu';
34
+ const DRAG_DATA_FORMAT = 'application/x-lexical-drag-block';
35
+ const TEXT_BOX_HORIZONTAL_PADDING = 28;
36
+
37
+ const Downward = 1;
38
+ const Upward = -1;
39
+ const Indeterminate = 0;
40
+
41
+ let prevIndex = Infinity;
42
+
43
+ function getCurrentIndex(keysLength: number): number {
44
+ if (keysLength === 0) {
45
+ return Infinity;
46
+ }
47
+ if (prevIndex >= 0 && prevIndex < keysLength) {
48
+ return prevIndex;
49
+ }
50
+
51
+ return Math.floor(keysLength / 2);
52
+ }
53
+
54
+ function getTopLevelNodeKeys(editor: LexicalEditor): string[] {
55
+ return editor.getEditorState().read(() => $getRoot().getChildrenKeys());
56
+ }
57
+
58
+ function getBlockElement(
59
+ anchorElem: HTMLElement,
60
+ editor: LexicalEditor,
61
+ event: MouseEvent,
62
+ ): HTMLElement | null {
63
+ const anchorElementRect = anchorElem.getBoundingClientRect();
64
+ const topLevelNodeKeys = getTopLevelNodeKeys(editor);
65
+
66
+ let blockElem: HTMLElement | null = null;
67
+
68
+ editor.getEditorState().read(() => {
69
+ let index = getCurrentIndex(topLevelNodeKeys.length);
70
+ let direction = Indeterminate;
71
+
72
+ while (index >= 0 && index < topLevelNodeKeys.length) {
73
+ const key = topLevelNodeKeys[index];
74
+ const elem = editor.getElementByKey(key);
75
+ if (elem === null) {
76
+ break;
77
+ }
78
+ const point = new Point(event.x, event.y);
79
+ const domRect = Rect.fromDOM(elem);
80
+ const {marginTop, marginBottom} = window.getComputedStyle(elem);
81
+
82
+ const rect = domRect.generateNewRect({
83
+ bottom: domRect.bottom + parseFloat(marginBottom),
84
+ left: anchorElementRect.left,
85
+ right: anchorElementRect.right,
86
+ top: domRect.top - parseFloat(marginTop),
87
+ });
88
+
89
+ const {
90
+ result,
91
+ reason: {isOnTopSide, isOnBottomSide},
92
+ } = rect.contains(point);
93
+
94
+ if (result) {
95
+ blockElem = elem;
96
+ prevIndex = index;
97
+ break;
98
+ }
99
+
100
+ if (direction === Indeterminate) {
101
+ if (isOnTopSide) {
102
+ direction = Upward;
103
+ } else if (isOnBottomSide) {
104
+ direction = Downward;
105
+ } else {
106
+ // stop search block element
107
+ direction = Infinity;
108
+ }
109
+ }
110
+
111
+ index += direction;
112
+ }
113
+ });
114
+
115
+ return blockElem;
116
+ }
117
+
118
+ function isOnMenu(element: HTMLElement): boolean {
119
+ return !!element.closest(`.${DRAGGABLE_BLOCK_MENU_CLASSNAME}`);
120
+ }
121
+
122
+ function setMenuPosition(
123
+ targetElem: HTMLElement | null,
124
+ floatingElem: HTMLElement,
125
+ anchorElem: HTMLElement,
126
+ ) {
127
+ if (!targetElem) {
128
+ floatingElem.style.opacity = '0';
129
+ floatingElem.style.transform = 'translate(-10000px, -10000px)';
130
+ return;
131
+ }
132
+
133
+ const targetRect = targetElem.getBoundingClientRect();
134
+ const targetStyle = window.getComputedStyle(targetElem);
135
+ const floatingElemRect = floatingElem.getBoundingClientRect();
136
+ const anchorElementRect = anchorElem.getBoundingClientRect();
137
+
138
+ const top =
139
+ targetRect.top +
140
+ (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 -
141
+ anchorElementRect.top;
142
+
143
+ const left = SPACE;
144
+
145
+ floatingElem.style.opacity = '1';
146
+ floatingElem.style.transform = `translate(${left}px, ${top}px)`;
147
+ }
148
+
149
+ function setDragImage(
150
+ dataTransfer: DataTransfer,
151
+ draggableBlockElem: HTMLElement,
152
+ ) {
153
+ const {transform} = draggableBlockElem.style;
154
+
155
+ // Remove dragImage borders
156
+ draggableBlockElem.style.transform = 'translateZ(0)';
157
+ dataTransfer.setDragImage(draggableBlockElem, 0, 0);
158
+
159
+ setTimeout(() => {
160
+ draggableBlockElem.style.transform = transform;
161
+ });
162
+ }
163
+
164
+ function setTargetLine(
165
+ targetLineElem: HTMLElement,
166
+ targetBlockElem: HTMLElement,
167
+ mouseY: number,
168
+ anchorElem: HTMLElement,
169
+ ) {
170
+ const targetStyle = window.getComputedStyle(targetBlockElem);
171
+ const {top: targetBlockElemTop, height: targetBlockElemHeight} =
172
+ targetBlockElem.getBoundingClientRect();
173
+ const {top: anchorTop, width: anchorWidth} =
174
+ anchorElem.getBoundingClientRect();
175
+
176
+ let lineTop = targetBlockElemTop;
177
+ // At the bottom of the target
178
+ if (mouseY - targetBlockElemTop > targetBlockElemHeight / 2) {
179
+ lineTop += targetBlockElemHeight + parseFloat(targetStyle.marginBottom);
180
+ } else {
181
+ lineTop -= parseFloat(targetStyle.marginTop);
182
+ }
183
+
184
+ const top = lineTop - anchorTop - TARGET_LINE_HALF_HEIGHT;
185
+ const left = TEXT_BOX_HORIZONTAL_PADDING - SPACE;
186
+
187
+ targetLineElem.style.transform = `translate(${left}px, ${top}px)`;
188
+ targetLineElem.style.width = `${
189
+ anchorWidth - (TEXT_BOX_HORIZONTAL_PADDING - SPACE) * 2
190
+ }px`;
191
+ targetLineElem.style.opacity = '.4';
192
+ }
193
+
194
+ function hideTargetLine(targetLineElem: HTMLElement | null) {
195
+ if (targetLineElem) {
196
+ targetLineElem.style.opacity = '0';
197
+ targetLineElem.style.transform = 'translate(-10000px, -10000px)';
198
+ }
199
+ }
200
+
201
+ function useDraggableBlockMenu(
202
+ editor: LexicalEditor,
203
+ anchorElem: HTMLElement,
204
+ isEditable: boolean,
205
+ ): JSX.Element {
206
+ const scrollerElem = anchorElem.parentElement;
207
+
208
+ const menuRef = useRef<HTMLDivElement>(null);
209
+ const targetLineRef = useRef<HTMLDivElement>(null);
210
+ const [draggableBlockElem, setDraggableBlockElem] =
211
+ useState<HTMLElement | null>(null);
212
+
213
+ useEffect(() => {
214
+ function onMouseMove(event: MouseEvent) {
215
+ const target = event.target;
216
+ if (!isHTMLElement(target)) {
217
+ setDraggableBlockElem(null);
218
+ return;
219
+ }
220
+
221
+ if (isOnMenu(target)) {
222
+ return;
223
+ }
224
+
225
+ const _draggableBlockElem = getBlockElement(anchorElem, editor, event);
226
+
227
+ setDraggableBlockElem(_draggableBlockElem);
228
+ }
229
+
230
+ function onMouseLeave() {
231
+ setDraggableBlockElem(null);
232
+ }
233
+
234
+ scrollerElem?.addEventListener('mousemove', onMouseMove);
235
+ scrollerElem?.addEventListener('mouseleave', onMouseLeave);
236
+
237
+ return () => {
238
+ scrollerElem?.removeEventListener('mousemove', onMouseMove);
239
+ scrollerElem?.removeEventListener('mouseleave', onMouseLeave);
240
+ };
241
+ }, [scrollerElem, anchorElem, editor]);
242
+
243
+ useEffect(() => {
244
+ if (menuRef.current) {
245
+ setMenuPosition(draggableBlockElem, menuRef.current, anchorElem);
246
+ }
247
+ }, [anchorElem, draggableBlockElem]);
248
+
249
+ useEffect(() => {
250
+ function onDragover(event: DragEvent): boolean {
251
+ const [isFileTransfer] = eventFiles(event);
252
+ if (isFileTransfer) {
253
+ return false;
254
+ }
255
+ const {pageY, target} = event;
256
+ if (!isHTMLElement(target)) {
257
+ return false;
258
+ }
259
+ const targetBlockElem = getBlockElement(anchorElem, editor, event);
260
+ const targetLineElem = targetLineRef.current;
261
+ if (targetBlockElem === null || targetLineElem === null) {
262
+ return false;
263
+ }
264
+ setTargetLine(targetLineElem, targetBlockElem, pageY, anchorElem);
265
+ // Prevent default event to be able to trigger onDrop events
266
+ event.preventDefault();
267
+ return true;
268
+ }
269
+
270
+ function onDrop(event: DragEvent): boolean {
271
+ const [isFileTransfer] = eventFiles(event);
272
+ if (isFileTransfer) {
273
+ return false;
274
+ }
275
+ const {target, dataTransfer, pageY} = event;
276
+ const dragData = dataTransfer?.getData(DRAG_DATA_FORMAT) || '';
277
+ const draggedNode = $getNodeByKey(dragData);
278
+ if (!draggedNode) {
279
+ return false;
280
+ }
281
+ if (!isHTMLElement(target)) {
282
+ return false;
283
+ }
284
+ const targetBlockElem = getBlockElement(anchorElem, editor, event);
285
+ if (!targetBlockElem) {
286
+ return false;
287
+ }
288
+ const targetNode = $getNearestNodeFromDOMNode(targetBlockElem);
289
+ if (!targetNode) {
290
+ return false;
291
+ }
292
+ if (targetNode === draggedNode) {
293
+ return true;
294
+ }
295
+ const {top, height} = targetBlockElem.getBoundingClientRect();
296
+ const shouldInsertAfter = pageY - top > height / 2;
297
+ if (shouldInsertAfter) {
298
+ targetNode.insertAfter(draggedNode);
299
+ } else {
300
+ targetNode.insertBefore(draggedNode);
301
+ }
302
+ setDraggableBlockElem(null);
303
+
304
+ return true;
305
+ }
306
+
307
+ return mergeRegister(
308
+ editor.registerCommand(
309
+ DRAGOVER_COMMAND,
310
+ (event) => {
311
+ return onDragover(event);
312
+ },
313
+ COMMAND_PRIORITY_LOW,
314
+ ),
315
+ editor.registerCommand(
316
+ DROP_COMMAND,
317
+ (event) => {
318
+ return onDrop(event);
319
+ },
320
+ COMMAND_PRIORITY_HIGH,
321
+ ),
322
+ );
323
+ }, [anchorElem, editor]);
324
+
325
+ function onDragStart(event: ReactDragEvent<HTMLDivElement>): void {
326
+ const dataTransfer = event.dataTransfer;
327
+ if (!dataTransfer || !draggableBlockElem) {
328
+ return;
329
+ }
330
+ setDragImage(dataTransfer, draggableBlockElem);
331
+ let nodeKey = '';
332
+ editor.update(() => {
333
+ const node = $getNearestNodeFromDOMNode(draggableBlockElem);
334
+ if (node) {
335
+ nodeKey = node.getKey();
336
+ }
337
+ });
338
+ dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey);
339
+ }
340
+
341
+ function onDragEnd(): void {
342
+ hideTargetLine(targetLineRef.current);
343
+ }
344
+
345
+ return createPortal(
346
+ <>
347
+ <div
348
+ className="icon draggable-block-menu"
349
+ ref={menuRef}
350
+ draggable={true}
351
+ onDragStart={onDragStart}
352
+ onDragEnd={onDragEnd}>
353
+ <div className={isEditable ? 'icon' : ''} />
354
+ </div>
355
+ <div className="draggable-block-target-line" ref={targetLineRef} />
356
+ </>,
357
+ anchorElem,
358
+ );
359
+ }
360
+
361
+ export default function DraggableBlockPlugin({
362
+ anchorElem = document.body,
363
+ }: {
364
+ anchorElem?: HTMLElement;
365
+ }): JSX.Element {
366
+ const [editor] = useLexicalComposerContext();
367
+ return useDraggableBlockMenu(editor, anchorElem, editor._editable);
368
+ }
@@ -0,0 +1,40 @@
1
+ .link-editor {
2
+ position: absolute;
3
+ top: 0;
4
+ left: 0;
5
+ z-index: 10;
6
+ max-width: 400px;
7
+ width: 100%;
8
+ opacity: 0;
9
+ background-color: #fff;
10
+ box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
11
+ border-radius: 8px;
12
+ transition: opacity 0.5s;
13
+ will-change: transform;
14
+ }
15
+
16
+ .link-editor .button {
17
+ width: 20px;
18
+ height: 20px;
19
+ display: inline-block;
20
+ padding: 6px;
21
+ border-radius: 8px;
22
+ cursor: pointer;
23
+ margin: 0 2px;
24
+ }
25
+
26
+ .link-editor .button.hovered {
27
+ width: 20px;
28
+ height: 20px;
29
+ display: inline-block;
30
+ background-color: #eee;
31
+ }
32
+
33
+ .link-editor .button i,
34
+ .actions i {
35
+ background-size: contain;
36
+ display: inline-block;
37
+ height: 20px;
38
+ width: 20px;
39
+ vertical-align: -0.25em;
40
+ }
@@ -0,0 +1,305 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import './index.css';
9
+ import { Dispatch, useCallback, useEffect, useRef, useState } from 'react';
10
+ import * as React from 'react';
11
+ import {
12
+ $getSelection,
13
+ $isRangeSelection,
14
+ COMMAND_PRIORITY_CRITICAL,
15
+ COMMAND_PRIORITY_HIGH,
16
+ COMMAND_PRIORITY_LOW,
17
+ GridSelection,
18
+ KEY_ESCAPE_COMMAND,
19
+ LexicalEditor,
20
+ NodeSelection,
21
+ RangeSelection,
22
+ SELECTION_CHANGE_COMMAND,
23
+ } from 'lexical';
24
+ import { createPortal } from 'react-dom';
25
+ import { $isAutoLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
26
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
27
+ import { $findMatchingParent, mergeRegister } from '@lexical/utils';
28
+
29
+ import { Button } from '../../../button';
30
+ import { IconButton } from '../../../icon-button';
31
+ import { Icon } from '../../../iconography';
32
+ import { InputWithLabel } from '../../../input-with-label';
33
+ import LinkPreview from '../../ui/LinkPreview';
34
+ import { getSelectedNode } from '../../utils/getSelectedNode';
35
+ import { setFloatingElemPosition } from '../../utils/setFloatingElemPosition';
36
+ import { sanitizeUrl } from '../../utils/url';
37
+
38
+ function FloatingLinkEditor({
39
+ editor,
40
+ isLink,
41
+ setIsLink,
42
+ anchorElem,
43
+ }: {
44
+ editor: LexicalEditor;
45
+ isLink: boolean;
46
+ setIsLink: Dispatch<boolean>;
47
+ anchorElem: HTMLElement;
48
+ }): JSX.Element {
49
+ const editorRef = useRef<HTMLDivElement | null>(null);
50
+ const inputRef = useRef<HTMLInputElement>(null);
51
+ const [linkUrl, setLinkUrl] = useState('');
52
+ const [rel, setRel] = useState<string | null>(null);
53
+ const [target, setTarget] = useState<string | null>(null);
54
+ const [isEditMode, setEditMode] = useState(false);
55
+ const [lastSelection, setLastSelection] = useState<RangeSelection | GridSelection | NodeSelection | null>(null);
56
+
57
+ const updateLinkEditor = useCallback(() => {
58
+ const selection = $getSelection();
59
+ if ($isRangeSelection(selection)) {
60
+ const node = getSelectedNode(selection);
61
+ const parent = node.getParent();
62
+ if ($isLinkNode(parent)) {
63
+ setLinkUrl(parent.getURL());
64
+ setRel(parent.getRel());
65
+ setTarget(parent.getTarget());
66
+ } else if ($isLinkNode(node)) {
67
+ setLinkUrl(node.getURL());
68
+ setRel(node.getRel());
69
+ setRel(node.getTarget());
70
+ } else {
71
+ setLinkUrl('');
72
+ setRel(null);
73
+ setTarget(null);
74
+ }
75
+ }
76
+ const editorElem = editorRef.current;
77
+ const nativeSelection = window.getSelection();
78
+ const activeElement = document.activeElement;
79
+
80
+ if (editorElem === null) {
81
+ return;
82
+ }
83
+
84
+ const rootElement = editor.getRootElement();
85
+
86
+ if (
87
+ selection !== null &&
88
+ nativeSelection !== null &&
89
+ rootElement !== null &&
90
+ rootElement.contains(nativeSelection.anchorNode) &&
91
+ editor.isEditable()
92
+ ) {
93
+ const domRange = nativeSelection.getRangeAt(0);
94
+ let rect;
95
+ if (nativeSelection.anchorNode === rootElement) {
96
+ let inner = rootElement;
97
+ while (inner.firstElementChild != null) {
98
+ inner = inner.firstElementChild as HTMLElement;
99
+ }
100
+ rect = inner.getBoundingClientRect();
101
+ } else {
102
+ rect = domRange.getBoundingClientRect();
103
+ }
104
+
105
+ setFloatingElemPosition(rect, editorElem, anchorElem);
106
+ setLastSelection(selection);
107
+ } else if (!activeElement || activeElement.className !== 'link-input') {
108
+ if (rootElement !== null) {
109
+ setFloatingElemPosition(null, editorElem, anchorElem);
110
+ }
111
+ setLastSelection(null);
112
+ setEditMode(false);
113
+ setLinkUrl('');
114
+ }
115
+
116
+ return true;
117
+ }, [anchorElem, editor]);
118
+
119
+ useEffect(() => {
120
+ const scrollerElem = anchorElem.parentElement;
121
+
122
+ const update = () => {
123
+ editor.getEditorState().read(() => {
124
+ updateLinkEditor();
125
+ });
126
+ };
127
+
128
+ window.addEventListener('resize', update);
129
+
130
+ if (scrollerElem) {
131
+ scrollerElem.addEventListener('scroll', update);
132
+ }
133
+
134
+ return () => {
135
+ window.removeEventListener('resize', update);
136
+
137
+ if (scrollerElem) {
138
+ scrollerElem.removeEventListener('scroll', update);
139
+ }
140
+ };
141
+ }, [anchorElem.parentElement, editor, updateLinkEditor]);
142
+
143
+ useEffect(() => {
144
+ return mergeRegister(
145
+ editor.registerUpdateListener(({ editorState }) => {
146
+ editorState.read(() => {
147
+ updateLinkEditor();
148
+ });
149
+ }),
150
+
151
+ editor.registerCommand(
152
+ SELECTION_CHANGE_COMMAND,
153
+ () => {
154
+ updateLinkEditor();
155
+ return true;
156
+ },
157
+ COMMAND_PRIORITY_LOW,
158
+ ),
159
+ editor.registerCommand(
160
+ KEY_ESCAPE_COMMAND,
161
+ () => {
162
+ if (isLink) {
163
+ setIsLink(false);
164
+ return true;
165
+ }
166
+ return false;
167
+ },
168
+ COMMAND_PRIORITY_HIGH,
169
+ ),
170
+ );
171
+ }, [editor, updateLinkEditor, setIsLink, isLink]);
172
+
173
+ useEffect(() => {
174
+ editor.getEditorState().read(() => {
175
+ updateLinkEditor();
176
+ });
177
+ }, [editor, updateLinkEditor]);
178
+
179
+ useEffect(() => {
180
+ if (isEditMode && inputRef.current) {
181
+ inputRef.current.focus();
182
+ }
183
+ }, [isEditMode]);
184
+
185
+ return (
186
+ <div ref={editorRef} className="link-editor">
187
+ {isEditMode ? (
188
+ <div>
189
+ <div className="border-0 border-b border-gray-100-800 border-solid px-3">
190
+ <InputWithLabel label="Link" type="text" value={linkUrl} onChange={e => setLinkUrl(e.target.value)} />
191
+ </div>
192
+
193
+ <div className="border-0 border-b border-gray-100-800 border-solid px-3">
194
+ <InputWithLabel label="Rel" type="text" value={rel ?? ''} onChange={e => setRel(e.target.value)} />
195
+ </div>
196
+ <div className="border-0 border-b border-gray-100-800 border-solid px-3">
197
+ <InputWithLabel label="Target" type="text" value={target ?? ''} onChange={e => setTarget(e.target.value)} />
198
+ </div>
199
+ <div className="flex px-6 py-2 justify-end">
200
+ <Button
201
+ onClick={() => {
202
+ if (lastSelection !== null) {
203
+ if (linkUrl !== '') {
204
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
205
+ url: sanitizeUrl(linkUrl),
206
+ rel,
207
+ target,
208
+ });
209
+ }
210
+ setEditMode(false);
211
+ }
212
+ }}
213
+ >
214
+ Done
215
+ </Button>
216
+ </div>
217
+ </div>
218
+ ) : (
219
+ <>
220
+ <div className="link-input !flex flex-nowrap justify-between items-center max-w-full ">
221
+ <div className=" grid">
222
+ <a href={linkUrl} target="_blank" rel="noopener noreferrer">
223
+ {linkUrl}
224
+ </a>
225
+ {rel || target ? (
226
+ <div className="flex mt-1 gap-1">
227
+ {rel && (
228
+ <div className="text-[10px] text-gray-600-300 px-1 bg-purple-50-900 rounded-md py-0.5">{rel}</div>
229
+ )}
230
+ {target && (
231
+ <div className="text-[10px] text-gray-600-300 px-1 bg-purple-50-900 rounded-md py-0.5">
232
+ {target}
233
+ </div>
234
+ )}
235
+ </div>
236
+ ) : null}
237
+ </div>
238
+ <div>
239
+ <IconButton
240
+ size="sm"
241
+ tabIndex={0}
242
+ onMouseDown={event => event.preventDefault()}
243
+ onClick={() => setEditMode(true)}
244
+ >
245
+ <Icon.Edit />
246
+ </IconButton>
247
+ </div>
248
+ </div>
249
+ <div>
250
+ <LinkPreview url={linkUrl} />
251
+ </div>
252
+ </>
253
+ )}
254
+ </div>
255
+ );
256
+ }
257
+
258
+ function useFloatingLinkEditorToolbar(editor: LexicalEditor, anchorElem: HTMLElement): JSX.Element | null {
259
+ const [activeEditor, setActiveEditor] = useState(editor);
260
+ const [isLink, setIsLink] = useState(false);
261
+
262
+ const updateToolbar = useCallback(() => {
263
+ const selection = $getSelection();
264
+ if ($isRangeSelection(selection)) {
265
+ const node = getSelectedNode(selection);
266
+ const linkParent = $findMatchingParent(node, $isLinkNode);
267
+ const autoLinkParent = $findMatchingParent(node, $isAutoLinkNode);
268
+
269
+ // We don't want this menu to open for auto links.
270
+ if (linkParent != null && autoLinkParent == null) {
271
+ setIsLink(true);
272
+ } else {
273
+ setIsLink(false);
274
+ }
275
+ }
276
+ }, []);
277
+
278
+ useEffect(() => {
279
+ return editor.registerCommand(
280
+ SELECTION_CHANGE_COMMAND,
281
+ (_payload, newEditor) => {
282
+ updateToolbar();
283
+ setActiveEditor(newEditor);
284
+ return false;
285
+ },
286
+ COMMAND_PRIORITY_CRITICAL,
287
+ );
288
+ }, [editor, updateToolbar]);
289
+
290
+ return isLink
291
+ ? createPortal(
292
+ <FloatingLinkEditor editor={activeEditor} isLink={isLink} anchorElem={anchorElem} setIsLink={setIsLink} />,
293
+ anchorElem,
294
+ )
295
+ : null;
296
+ }
297
+
298
+ export default function FloatingLinkEditorPlugin({
299
+ anchorElem = document.body,
300
+ }: {
301
+ anchorElem?: HTMLElement;
302
+ }): JSX.Element | null {
303
+ const [editor] = useLexicalComposerContext();
304
+ return useFloatingLinkEditorToolbar(editor, anchorElem);
305
+ }