@scottjgilbert/lexical-blog-editor 0.1.4 → 1.0.0-beta.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 (313) hide show
  1. package/README.md +73 -67
  2. package/build/Editor.d.ts +8 -3
  3. package/build/Editor.d.ts.map +1 -1
  4. package/build/Editor.js +13 -8
  5. package/build/EditorExport.d.ts +4 -0
  6. package/build/EditorExport.d.ts.map +1 -0
  7. package/build/EditorExport.js +13 -0
  8. package/build/appSettings.d.ts +1 -1
  9. package/build/appSettings.js +1 -1
  10. package/build/buildHTMLConfig.d.ts +1 -1
  11. package/build/buildHTMLConfig.d.ts.map +1 -1
  12. package/build/buildHTMLConfig.js +35 -11
  13. package/build/context/FlashMessageContext.d.ts +2 -2
  14. package/build/context/FlashMessageContext.d.ts.map +1 -1
  15. package/build/context/FlashMessageContext.js +4 -3
  16. package/build/context/SharedHistoryContext.d.ts +3 -3
  17. package/build/context/SharedHistoryContext.d.ts.map +1 -1
  18. package/build/context/SharedHistoryContext.js +3 -2
  19. package/build/context/ToolbarContext.d.ts +1 -0
  20. package/build/context/ToolbarContext.d.ts.map +1 -1
  21. package/build/context/ToolbarContext.js +2 -0
  22. package/build/hooks/useModal.d.ts.map +1 -1
  23. package/build/hooks/useModal.js +1 -0
  24. package/build/hooks/useReport.d.ts +0 -7
  25. package/build/hooks/useReport.d.ts.map +1 -1
  26. package/build/hooks/useReport.js +1 -0
  27. package/build/index.css +283 -246
  28. package/build/index.d.ts +3 -3
  29. package/build/index.d.ts.map +1 -1
  30. package/build/index.js +2 -2
  31. package/build/nodes/CodeNode/CodeHighlightNode.d.ts +35 -0
  32. package/build/nodes/CodeNode/CodeHighlightNode.d.ts.map +1 -0
  33. package/build/nodes/CodeNode/CodeHighlightNode.js +88 -0
  34. package/build/nodes/CodeNode/CodeHighlighterShiki.d.ts +22 -0
  35. package/build/nodes/CodeNode/CodeHighlighterShiki.d.ts.map +1 -0
  36. package/build/nodes/CodeNode/CodeHighlighterShiki.js +644 -0
  37. package/build/nodes/CodeNode/CodeNode.d.ts +48 -0
  38. package/build/nodes/CodeNode/CodeNode.d.ts.map +1 -0
  39. package/build/nodes/CodeNode/CodeNode.js +367 -0
  40. package/build/nodes/CodeNode/FacadeShiki.d.ts +18 -0
  41. package/build/nodes/CodeNode/FacadeShiki.d.ts.map +1 -0
  42. package/build/nodes/CodeNode/FacadeShiki.js +159 -0
  43. package/build/nodes/CodeNode/FlatStructureUtils.d.ts +21 -0
  44. package/build/nodes/CodeNode/FlatStructureUtils.d.ts.map +1 -0
  45. package/build/nodes/CodeNode/FlatStructureUtils.js +85 -0
  46. package/build/nodes/CodeNode/invariant.d.ts +2 -0
  47. package/build/nodes/CodeNode/invariant.d.ts.map +1 -0
  48. package/build/nodes/CodeNode/invariant.js +6 -0
  49. package/build/nodes/DateTimeNode/DateTimeComponent.d.ts.map +1 -1
  50. package/build/nodes/DateTimeNode/DateTimeComponent.js +1 -0
  51. package/build/nodes/DateTimeNode/DateTimeNode.css +21 -0
  52. package/build/nodes/FigmaNode/FigmaNode.d.ts.map +1 -0
  53. package/build/nodes/FigmaNode/ServerFigmaNode.d.ts +21 -0
  54. package/build/nodes/FigmaNode/ServerFigmaNode.d.ts.map +1 -0
  55. package/build/nodes/FigmaNode/ServerFigmaNode.js +48 -0
  56. package/build/nodes/ImageComponent.d.ts.map +1 -1
  57. package/build/nodes/ImageComponent.js +1 -2
  58. package/build/nodes/ImageNode.d.ts +7 -7
  59. package/build/nodes/ImageNode.d.ts.map +1 -1
  60. package/build/nodes/ImageNode.js +30 -30
  61. package/build/nodes/LayoutContainerNode.d.ts +2 -2
  62. package/build/nodes/LayoutContainerNode.d.ts.map +1 -1
  63. package/build/nodes/LayoutContainerNode.js +10 -10
  64. package/build/nodes/PlaygroundNodes/PlaygroundNodes.d.ts.map +1 -0
  65. package/build/nodes/{PlaygroundNodes.js → PlaygroundNodes/PlaygroundNodes.js} +19 -21
  66. package/build/nodes/PlaygroundNodes/ServerPlaygroundNodes.d.ts +11 -0
  67. package/build/nodes/PlaygroundNodes/ServerPlaygroundNodes.d.ts.map +1 -0
  68. package/build/nodes/PlaygroundNodes/ServerPlaygroundNodes.js +65 -0
  69. package/build/nodes/TweetNode/ServerTweetNode.d.ts +20 -0
  70. package/build/nodes/TweetNode/ServerTweetNode.d.ts.map +1 -0
  71. package/build/nodes/TweetNode/ServerTweetNode.js +59 -0
  72. package/build/nodes/TweetNode/TweetNode.d.ts.map +1 -0
  73. package/build/nodes/YouTubeNode/ServerYouTubeNode.d.ts +21 -0
  74. package/build/nodes/YouTubeNode/ServerYouTubeNode.d.ts.map +1 -0
  75. package/build/nodes/YouTubeNode/ServerYouTubeNode.js +67 -0
  76. package/build/nodes/YouTubeNode/YouTubeNode.d.ts.map +1 -0
  77. package/build/plugins/ActionsPlugin/index.d.ts +0 -7
  78. package/build/plugins/ActionsPlugin/index.d.ts.map +1 -1
  79. package/build/plugins/ActionsPlugin/index.js +2 -1
  80. package/build/plugins/AutoEmbedPlugin/index.d.ts +2 -9
  81. package/build/plugins/AutoEmbedPlugin/index.d.ts.map +1 -1
  82. package/build/plugins/AutoEmbedPlugin/index.js +30 -29
  83. package/build/plugins/AutoLinkPlugin/index.d.ts +1 -1
  84. package/build/plugins/AutoLinkPlugin/index.d.ts.map +1 -1
  85. package/build/plugins/AutoLinkPlugin/index.js +3 -2
  86. package/build/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +1 -1
  87. package/build/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts.map +1 -1
  88. package/build/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +7 -6
  89. package/build/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +2 -2
  90. package/build/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts.map +1 -1
  91. package/build/plugins/CodeActionMenuPlugin/components/PrettierButton/index.js +25 -24
  92. package/build/plugins/CodeActionMenuPlugin/index.d.ts +2 -9
  93. package/build/plugins/CodeActionMenuPlugin/index.d.ts.map +1 -1
  94. package/build/plugins/CodeActionMenuPlugin/index.js +22 -20
  95. package/build/plugins/CodeActionMenuPlugin/utils.d.ts.map +1 -1
  96. package/build/plugins/CodeActionMenuPlugin/utils.js +3 -2
  97. package/build/plugins/CodeHighlightPrismPlugin/index.d.ts +1 -1
  98. package/build/plugins/CodeHighlightPrismPlugin/index.d.ts.map +1 -1
  99. package/build/plugins/CodeHighlightPrismPlugin/index.js +4 -10
  100. package/build/plugins/CodeHighlightShikiPlugin/index.d.ts +1 -1
  101. package/build/plugins/CodeHighlightShikiPlugin/index.d.ts.map +1 -1
  102. package/build/plugins/CodeHighlightShikiPlugin/index.js +3 -3
  103. package/build/plugins/CollapsiblePlugin/Collapsible.css +17 -1
  104. package/build/plugins/CollapsiblePlugin/index.d.ts +1 -1
  105. package/build/plugins/CollapsiblePlugin/index.d.ts.map +1 -1
  106. package/build/plugins/CollapsiblePlugin/index.js +11 -10
  107. package/build/plugins/ComponentPickerPlugin/index.d.ts.map +1 -1
  108. package/build/plugins/ComponentPickerPlugin/index.js +3 -8
  109. package/build/plugins/ContextMenuPlugin/index.d.ts +1 -1
  110. package/build/plugins/ContextMenuPlugin/index.d.ts.map +1 -1
  111. package/build/plugins/ContextMenuPlugin/index.js +15 -14
  112. package/build/plugins/DateTimePlugin/index.d.ts +2 -2
  113. package/build/plugins/DateTimePlugin/index.d.ts.map +1 -1
  114. package/build/plugins/DateTimePlugin/index.js +8 -14
  115. package/build/plugins/DragDropPastePlugin/index.d.ts +0 -7
  116. package/build/plugins/DragDropPastePlugin/index.d.ts.map +1 -1
  117. package/build/plugins/DragDropPastePlugin/index.js +12 -11
  118. package/build/plugins/DraggableBlockPlugin/index.css +6 -0
  119. package/build/plugins/DraggableBlockPlugin/index.d.ts +2 -2
  120. package/build/plugins/DraggableBlockPlugin/index.d.ts.map +1 -1
  121. package/build/plugins/DraggableBlockPlugin/index.js +23 -22
  122. package/build/plugins/EmojiPickerPlugin/index.d.ts +0 -7
  123. package/build/plugins/EmojiPickerPlugin/index.d.ts.map +1 -1
  124. package/build/plugins/EmojiPickerPlugin/index.js +1 -0
  125. package/build/plugins/EmojisPlugin/index.d.ts +1 -8
  126. package/build/plugins/EmojisPlugin/index.d.ts.map +1 -1
  127. package/build/plugins/EmojisPlugin/index.js +10 -16
  128. package/build/plugins/EquationsPlugin/index.d.ts +3 -3
  129. package/build/plugins/EquationsPlugin/index.d.ts.map +1 -1
  130. package/build/plugins/EquationsPlugin/index.js +14 -10
  131. package/build/plugins/FigmaPlugin/index.d.ts +2 -2
  132. package/build/plugins/FigmaPlugin/index.d.ts.map +1 -1
  133. package/build/plugins/FigmaPlugin/index.js +8 -14
  134. package/build/plugins/FloatingLinkEditorPlugin/index.css +11 -0
  135. package/build/plugins/FloatingLinkEditorPlugin/index.d.ts +3 -3
  136. package/build/plugins/FloatingLinkEditorPlugin/index.d.ts.map +1 -1
  137. package/build/plugins/FloatingLinkEditorPlugin/index.js +28 -27
  138. package/build/plugins/FloatingTextFormatToolbarPlugin/index.css +15 -0
  139. package/build/plugins/FloatingTextFormatToolbarPlugin/index.d.ts.map +1 -1
  140. package/build/plugins/FloatingTextFormatToolbarPlugin/index.js +2 -1
  141. package/build/plugins/ImagesPlugin/index.d.ts +3 -3
  142. package/build/plugins/ImagesPlugin/index.d.ts.map +1 -1
  143. package/build/plugins/ImagesPlugin/index.js +38 -37
  144. package/build/plugins/KeywordsPlugin/index.d.ts +1 -8
  145. package/build/plugins/KeywordsPlugin/index.d.ts.map +1 -1
  146. package/build/plugins/KeywordsPlugin/index.js +6 -12
  147. package/build/plugins/LayoutPlugin/InsertLayoutDialog.d.ts +2 -2
  148. package/build/plugins/LayoutPlugin/InsertLayoutDialog.d.ts.map +1 -1
  149. package/build/plugins/LayoutPlugin/InsertLayoutDialog.js +10 -9
  150. package/build/plugins/LayoutPlugin/LayoutPlugin.d.ts +1 -1
  151. package/build/plugins/LayoutPlugin/LayoutPlugin.d.ts.map +1 -1
  152. package/build/plugins/LayoutPlugin/LayoutPlugin.js +8 -14
  153. package/build/plugins/LinkPlugin/index.d.ts.map +1 -1
  154. package/build/plugins/LinkPlugin/index.js +1 -0
  155. package/build/plugins/MarkdownShortcutPlugin/index.d.ts.map +1 -1
  156. package/build/plugins/MarkdownShortcutPlugin/index.js +1 -0
  157. package/build/plugins/MarkdownTransformers/index.d.ts +1 -1
  158. package/build/plugins/MarkdownTransformers/index.d.ts.map +1 -1
  159. package/build/plugins/MarkdownTransformers/index.js +25 -25
  160. package/build/plugins/PasteLogPlugin/index.d.ts.map +1 -1
  161. package/build/plugins/PasteLogPlugin/index.js +1 -0
  162. package/build/plugins/ShortcutsPlugin/index.d.ts +0 -7
  163. package/build/plugins/ShortcutsPlugin/index.d.ts.map +1 -1
  164. package/build/plugins/ShortcutsPlugin/index.js +1 -0
  165. package/build/plugins/SpeechToTextPlugin/index.d.ts +2 -2
  166. package/build/plugins/SpeechToTextPlugin/index.d.ts.map +1 -1
  167. package/build/plugins/SpeechToTextPlugin/index.js +7 -11
  168. package/build/plugins/TabFocusPlugin/index.d.ts +0 -7
  169. package/build/plugins/TabFocusPlugin/index.d.ts.map +1 -1
  170. package/build/plugins/TabFocusPlugin/index.js +6 -5
  171. package/build/plugins/TableActionMenuPlugin/index.d.ts +1 -8
  172. package/build/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
  173. package/build/plugins/TableActionMenuPlugin/index.js +41 -40
  174. package/build/plugins/TableCellResizer/index.d.ts +2 -2
  175. package/build/plugins/TableCellResizer/index.d.ts.map +1 -1
  176. package/build/plugins/TableCellResizer/index.js +43 -42
  177. package/build/plugins/TableHoverActionsPlugin/index.d.ts +1 -8
  178. package/build/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
  179. package/build/plugins/TableHoverActionsPlugin/index.js +19 -18
  180. package/build/plugins/TableHoverActionsV2Plugin/index.d.ts.map +1 -1
  181. package/build/plugins/TableHoverActionsV2Plugin/index.js +1 -0
  182. package/build/plugins/TablePlugin.d.ts +2 -2
  183. package/build/plugins/TablePlugin.d.ts.map +1 -1
  184. package/build/plugins/TablePlugin.js +11 -10
  185. package/build/plugins/TableScrollShadowPlugin/index.d.ts +0 -7
  186. package/build/plugins/TableScrollShadowPlugin/index.d.ts.map +1 -1
  187. package/build/plugins/TableScrollShadowPlugin/index.js +9 -8
  188. package/build/plugins/TestRecorderPlugin/index.d.ts +1 -8
  189. package/build/plugins/TestRecorderPlugin/index.d.ts.map +1 -1
  190. package/build/plugins/TestRecorderPlugin/index.js +45 -44
  191. package/build/plugins/ToolbarPlugin/fontSize.d.ts +2 -2
  192. package/build/plugins/ToolbarPlugin/fontSize.d.ts.map +1 -1
  193. package/build/plugins/ToolbarPlugin/fontSize.js +19 -18
  194. package/build/plugins/ToolbarPlugin/index.d.ts.map +1 -1
  195. package/build/plugins/ToolbarPlugin/index.js +68 -60
  196. package/build/plugins/ToolbarPlugin/languages.d.ts +14 -0
  197. package/build/plugins/ToolbarPlugin/languages.d.ts.map +1 -0
  198. package/build/plugins/ToolbarPlugin/languages.js +185 -0
  199. package/build/plugins/ToolbarPlugin/utils.d.ts +2 -2
  200. package/build/plugins/ToolbarPlugin/utils.js +21 -21
  201. package/build/plugins/TwitterPlugin/index.d.ts +2 -2
  202. package/build/plugins/TwitterPlugin/index.d.ts.map +1 -1
  203. package/build/plugins/TwitterPlugin/index.js +8 -14
  204. package/build/plugins/YouTubePlugin/index.d.ts +2 -2
  205. package/build/plugins/YouTubePlugin/index.d.ts.map +1 -1
  206. package/build/plugins/YouTubePlugin/index.js +8 -14
  207. package/build/themes/PlaygroundEditorTheme.css +301 -33
  208. package/build/themes/ViewerTheme.css +899 -0
  209. package/build/{plugins/MentionsPlugin/index.d.ts → themes/ViewerTheme.d.ts} +5 -3
  210. package/build/themes/ViewerTheme.d.ts.map +1 -0
  211. package/build/themes/ViewerTheme.js +124 -0
  212. package/build/themes/ViewerThemeComplete.css +1043 -0
  213. package/build/ui/ColorPicker.d.ts +2 -2
  214. package/build/ui/ColorPicker.d.ts.map +1 -1
  215. package/build/ui/ColorPicker.js +47 -46
  216. package/build/ui/DropDown.d.ts.map +1 -1
  217. package/build/ui/DropDown.js +1 -0
  218. package/build/ui/FlashMessage.d.ts +3 -3
  219. package/build/ui/FlashMessage.d.ts.map +1 -1
  220. package/build/ui/FlashMessage.js +3 -2
  221. package/build/ui/ImageResizer.d.ts +3 -3
  222. package/build/ui/ImageResizer.d.ts.map +1 -1
  223. package/build/ui/ImageResizer.js +20 -19
  224. package/build/ui/KatexEquationAlterer.css +3 -1
  225. package/build/ui/KatexEquationAlterer.d.ts.map +1 -1
  226. package/build/ui/KatexEquationAlterer.js +1 -0
  227. package/build/ui/KatexRenderer.d.ts.map +1 -1
  228. package/build/ui/KatexRenderer.js +1 -0
  229. package/build/ui/Modal.d.ts.map +1 -1
  230. package/build/ui/Modal.js +1 -0
  231. package/build/ui/Switch.d.ts +2 -2
  232. package/build/ui/Switch.d.ts.map +1 -1
  233. package/build/ui/Switch.js +3 -2
  234. package/build/ui/TextInput.d.ts.map +1 -1
  235. package/build/ui/TextInput.js +1 -0
  236. package/build/utils/ServerBlockWithAlignableContents.d.ts +22 -0
  237. package/build/utils/ServerBlockWithAlignableContents.d.ts.map +1 -0
  238. package/build/utils/ServerBlockWithAlignableContents.js +6 -0
  239. package/build/utils/focusUtils.d.ts.map +1 -1
  240. package/build/utils/focusUtils.js +4 -3
  241. package/build/utils/getDOMRangeRect.d.ts.map +1 -1
  242. package/build/utils/getDOMRangeRect.js +1 -0
  243. package/build/utils/setFloatingElemPosition.d.ts.map +1 -1
  244. package/build/utils/setFloatingElemPosition.js +5 -4
  245. package/build/utils/swipe.d.ts +0 -7
  246. package/build/utils/swipe.d.ts.map +1 -1
  247. package/build/utils/swipe.js +5 -11
  248. package/build/viewer/Viewer.d.ts +18 -0
  249. package/build/viewer/Viewer.d.ts.map +1 -0
  250. package/build/viewer/Viewer.js +105 -0
  251. package/build/viewer/client.d.ts +18 -0
  252. package/build/viewer/client.d.ts.map +1 -0
  253. package/build/viewer/client.js +97 -0
  254. package/build/viewer/index.d.ts +4 -0
  255. package/build/viewer/index.d.ts.map +1 -0
  256. package/build/viewer/index.js +2 -0
  257. package/package.json +58 -36
  258. package/build/collaboration.d.ts +0 -12
  259. package/build/collaboration.d.ts.map +0 -1
  260. package/build/collaboration.js +0 -32
  261. package/build/nodes/FigmaNode.d.ts.map +0 -1
  262. package/build/nodes/PageBreakNode/index.css +0 -64
  263. package/build/nodes/PageBreakNode/index.d.ts +0 -25
  264. package/build/nodes/PageBreakNode/index.d.ts.map +0 -1
  265. package/build/nodes/PageBreakNode/index.js +0 -83
  266. package/build/nodes/PlaygroundNodes.d.ts.map +0 -1
  267. package/build/nodes/PollComponent.d.ts +0 -17
  268. package/build/nodes/PollComponent.d.ts.map +0 -1
  269. package/build/nodes/PollComponent.js +0 -85
  270. package/build/nodes/PollNode.css +0 -165
  271. package/build/nodes/PollNode.d.ts +0 -51
  272. package/build/nodes/PollNode.d.ts.map +0 -1
  273. package/build/nodes/PollNode.js +0 -153
  274. package/build/nodes/StickyComponent.d.ts +0 -18
  275. package/build/nodes/StickyComponent.d.ts.map +0 -1
  276. package/build/nodes/StickyComponent.js +0 -155
  277. package/build/nodes/StickyNode.css +0 -37
  278. package/build/nodes/StickyNode.d.ts +0 -39
  279. package/build/nodes/StickyNode.d.ts.map +0 -1
  280. package/build/nodes/StickyNode.js +0 -66
  281. package/build/nodes/TweetNode.d.ts.map +0 -1
  282. package/build/nodes/YouTubeNode.d.ts.map +0 -1
  283. package/build/plugins/DocsPlugin/index.d.ts +0 -10
  284. package/build/plugins/DocsPlugin/index.d.ts.map +0 -1
  285. package/build/plugins/DocsPlugin/index.js +0 -4
  286. package/build/plugins/MaxLengthPlugin/index.d.ts +0 -11
  287. package/build/plugins/MaxLengthPlugin/index.d.ts.map +0 -1
  288. package/build/plugins/MaxLengthPlugin/index.js +0 -44
  289. package/build/plugins/MentionsPlugin/index.d.ts.map +0 -1
  290. package/build/plugins/MentionsPlugin/index.js +0 -562
  291. package/build/plugins/PageBreakPlugin/index.d.ts +0 -12
  292. package/build/plugins/PageBreakPlugin/index.d.ts.map +0 -1
  293. package/build/plugins/PageBreakPlugin/index.js +0 -34
  294. package/build/plugins/StickyPlugin/index.d.ts +0 -10
  295. package/build/plugins/StickyPlugin/index.d.ts.map +0 -1
  296. package/build/plugins/StickyPlugin/index.js +0 -19
  297. package/build/plugins/TreeViewPlugin/index.d.ts +0 -10
  298. package/build/plugins/TreeViewPlugin/index.d.ts.map +0 -1
  299. package/build/plugins/TreeViewPlugin/index.js +0 -7
  300. package/build/plugins/TypingPerfPlugin/index.d.ts +0 -10
  301. package/build/plugins/TypingPerfPlugin/index.d.ts.map +0 -1
  302. package/build/plugins/TypingPerfPlugin/index.js +0 -100
  303. package/build/plugins/VersionsPlugin/index.css +0 -57
  304. package/build/plugins/VersionsPlugin/index.d.ts +0 -14
  305. package/build/plugins/VersionsPlugin/index.d.ts.map +0 -1
  306. package/build/plugins/VersionsPlugin/index.js +0 -147
  307. /package/build/nodes/{FigmaNode.d.ts → FigmaNode/FigmaNode.d.ts} +0 -0
  308. /package/build/nodes/{FigmaNode.js → FigmaNode/FigmaNode.js} +0 -0
  309. /package/build/nodes/{PlaygroundNodes.d.ts → PlaygroundNodes/PlaygroundNodes.d.ts} +0 -0
  310. /package/build/nodes/{TweetNode.d.ts → TweetNode/TweetNode.d.ts} +0 -0
  311. /package/build/nodes/{TweetNode.js → TweetNode/TweetNode.js} +0 -0
  312. /package/build/nodes/{YouTubeNode.d.ts → YouTubeNode/YouTubeNode.d.ts} +0 -0
  313. /package/build/nodes/{YouTubeNode.js → YouTubeNode/YouTubeNode.js} +0 -0
@@ -1,17 +0,0 @@
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 type { Options } from './PollNode';
9
- import type { JSX } from 'react';
10
- import './PollNode.css';
11
- import { NodeKey } from 'lexical';
12
- export default function PollComponent({ question, options, nodeKey, }: {
13
- nodeKey: NodeKey;
14
- options: Options;
15
- question: string;
16
- }): JSX.Element;
17
- //# sourceMappingURL=PollComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PollComponent.d.ts","sourceRoot":"","sources":["../../src/nodes/PollComponent.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAS,OAAO,EAAW,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE/B,OAAO,gBAAgB,CAAC;AAMxB,OAAO,EAOL,OAAO,EACR,MAAM,SAAS,CAAC;AAuGjB,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,QAAQ,EACR,OAAO,EACP,OAAO,GACR,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,GAAG,CAAC,OAAO,CAmFd"}
@@ -1,85 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import './PollNode.css';
3
- import { useCollaborationContext } from '@lexical/react/LexicalCollaborationContext';
4
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
5
- import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
6
- import { mergeRegister } from '@lexical/utils';
7
- import { $getNodeByKey, $getSelection, $isNodeSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, } from 'lexical';
8
- import { useEffect, useMemo, useRef, useState } from 'react';
9
- import Button from '../ui/Button';
10
- import joinClasses from '../utils/joinClasses';
11
- import { $isPollNode, createPollOption } from './PollNode';
12
- function getTotalVotes(options) {
13
- return options.reduce((totalVotes, next) => {
14
- return totalVotes + next.votes.length;
15
- }, 0);
16
- }
17
- function PollOptionComponent({ option, index, options, totalVotes, withPollNode, }) {
18
- const { name: username } = useCollaborationContext();
19
- const checkboxRef = useRef(null);
20
- const votesArray = option.votes;
21
- const checkedIndex = votesArray.indexOf(username);
22
- const checked = checkedIndex !== -1;
23
- const votes = votesArray.length;
24
- const text = option.text;
25
- return (_jsxs("div", { className: "PollNode__optionContainer", children: [_jsx("div", { className: joinClasses('PollNode__optionCheckboxWrapper', checked && 'PollNode__optionCheckboxChecked'), children: _jsx("input", { ref: checkboxRef, className: "PollNode__optionCheckbox", type: "checkbox", onChange: (e) => {
26
- withPollNode((node) => {
27
- node.toggleVote(option, username);
28
- });
29
- }, checked: checked }) }), _jsxs("div", { className: "PollNode__optionInputWrapper", children: [_jsx("div", { className: "PollNode__optionInputVotes", style: { width: `${votes === 0 ? 0 : (votes / totalVotes) * 100}%` } }), _jsx("span", { className: "PollNode__optionInputVotesCount", children: votes > 0 && (votes === 1 ? '1 vote' : `${votes} votes`) }), _jsx("input", { className: "PollNode__optionInput", type: "text", value: text, onChange: (e) => {
30
- const target = e.target;
31
- const value = target.value;
32
- const selectionStart = target.selectionStart;
33
- const selectionEnd = target.selectionEnd;
34
- withPollNode((node) => {
35
- node.setOptionText(option, value);
36
- }, () => {
37
- target.selectionStart = selectionStart;
38
- target.selectionEnd = selectionEnd;
39
- });
40
- }, placeholder: `Option ${index + 1}` })] }), _jsx("button", { disabled: options.length < 3, className: joinClasses('PollNode__optionDelete', options.length < 3 && 'PollNode__optionDeleteDisabled'), "aria-label": "Remove", onClick: () => {
41
- withPollNode((node) => {
42
- node.deleteOption(option);
43
- });
44
- } })] }));
45
- }
46
- export default function PollComponent({ question, options, nodeKey, }) {
47
- const [editor] = useLexicalComposerContext();
48
- const totalVotes = useMemo(() => getTotalVotes(options), [options]);
49
- const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
50
- const [selection, setSelection] = useState(null);
51
- const ref = useRef(null);
52
- useEffect(() => {
53
- return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
54
- setSelection(editorState.read(() => $getSelection()));
55
- }), editor.registerCommand(CLICK_COMMAND, (payload) => {
56
- const event = payload;
57
- if (event.target === ref.current) {
58
- if (!event.shiftKey) {
59
- clearSelection();
60
- }
61
- setSelected(!isSelected);
62
- return true;
63
- }
64
- return false;
65
- }, COMMAND_PRIORITY_LOW));
66
- }, [clearSelection, editor, isSelected, nodeKey, setSelected]);
67
- const withPollNode = (cb, onUpdate) => {
68
- editor.update(() => {
69
- const node = $getNodeByKey(nodeKey);
70
- if ($isPollNode(node)) {
71
- cb(node);
72
- }
73
- }, { onUpdate });
74
- };
75
- const addOption = () => {
76
- withPollNode((node) => {
77
- node.addOption(createPollOption());
78
- });
79
- };
80
- const isFocused = $isNodeSelection(selection) && isSelected;
81
- return (_jsx("div", { className: `PollNode__container ${isFocused ? 'focused' : ''}`, ref: ref, children: _jsxs("div", { className: "PollNode__inner", children: [_jsx("h2", { className: "PollNode__heading", children: question }), options.map((option, index) => {
82
- const key = option.uid;
83
- return (_jsx(PollOptionComponent, { withPollNode: withPollNode, option: option, index: index, options: options, totalVotes: totalVotes }, key));
84
- }), _jsx("div", { className: "PollNode__footer", children: _jsx(Button, { onClick: addOption, small: true, children: "Add Option" }) })] }) }));
85
- }
@@ -1,165 +0,0 @@
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
- */
9
-
10
- .PollNode__container {
11
- border: 1px solid #eee;
12
- background-color: #fcfcfc;
13
- border-radius: 10px;
14
- max-width: 600px;
15
- min-width: 400px;
16
- cursor: pointer;
17
- user-select: none;
18
- }
19
- .PollNode__container.focused {
20
- outline: 2px solid rgb(60, 132, 244);
21
- }
22
- .PollNode__inner {
23
- margin: 15px;
24
- cursor: default;
25
- }
26
- .PollNode__heading {
27
- margin-left: 0px;
28
- margin-top: 0px;
29
- margin-right: 0px;
30
- margin-bottom: 15px;
31
- color: #444;
32
- text-align: center;
33
- font-size: 18px;
34
- }
35
- .PollNode__optionContainer {
36
- display: flex;
37
- flex-direction: row;
38
- margin-bottom: 10px;
39
- align-items: center;
40
- }
41
- .PollNode__optionInputWrapper {
42
- display: flex;
43
- flex: 10px;
44
- border: 1px solid rgb(61, 135, 245);
45
- border-radius: 5px;
46
- position: relative;
47
- overflow: hidden;
48
- cursor: pointer;
49
- }
50
- .PollNode__optionInput {
51
- display: flex;
52
- flex: 1px;
53
- border: 0px;
54
- padding: 7px;
55
- color: rgb(61, 135, 245);
56
- background-color: transparent;
57
- font-weight: bold;
58
- outline: 0px;
59
- z-index: 0;
60
- }
61
- .PollNode__optionInput::placeholder {
62
- font-weight: normal;
63
- color: #999;
64
- }
65
- .PollNode__optionInputVotes {
66
- background-color: rgb(236, 243, 254);
67
- height: 100%;
68
- position: absolute;
69
- top: 0px;
70
- left: 0px;
71
- transition: width 1s ease;
72
- z-index: 0;
73
- }
74
- .PollNode__optionInputVotesCount {
75
- color: rgb(61, 135, 245);
76
- position: absolute;
77
- right: 15px;
78
- font-size: 12px;
79
- top: 5px;
80
- }
81
- .PollNode__optionCheckboxWrapper {
82
- position: relative;
83
- display: flex;
84
- width: 22px;
85
- height: 22px;
86
- border: 1px solid #999;
87
- margin-right: 10px;
88
- border-radius: 5px;
89
- }
90
- .PollNode__optionCheckboxChecked {
91
- border: 1px solid rgb(61, 135, 245);
92
- background-color: rgb(61, 135, 245);
93
- }
94
- .PollNode__optionCheckboxChecked:after {
95
- content: '';
96
- cursor: pointer;
97
- border-color: #fff;
98
- border-style: solid;
99
- position: absolute;
100
- display: block;
101
- top: 4px;
102
- width: 5px;
103
- left: 8px;
104
- height: 9px;
105
- margin: 0;
106
- transform: rotate(45deg);
107
- border-width: 0 2px 2px 0;
108
- pointer-events: none;
109
- }
110
- .PollNode__optionCheckbox {
111
- border: 0px;
112
- position: absolute;
113
- display: block;
114
- width: 100%;
115
- height: 100%;
116
- opacity: 0;
117
- cursor: pointer;
118
- }
119
- .PollNode__optionDelete {
120
- position: relative;
121
- display: flex;
122
- width: 28px;
123
- height: 28px;
124
- margin-left: 6px;
125
- border: 0px;
126
- background-color: transparent;
127
- background-position: 6px 6px;
128
- background-repeat: no-repeat;
129
- z-index: 0;
130
- cursor: pointer;
131
- border-radius: 5px;
132
- opacity: 0.3;
133
- }
134
- .PollNode__optionDelete:before,
135
- .PollNode__optionDelete:after {
136
- position: absolute;
137
- display: block;
138
- content: '';
139
- background-color: #999;
140
- width: 2px;
141
- height: 15px;
142
- top: 6px;
143
- left: 13px;
144
- }
145
- .PollNode__optionDelete:before {
146
- transform: rotate(-45deg);
147
- }
148
- .PollNode__optionDelete:after {
149
- transform: rotate(45deg);
150
- }
151
- .PollNode__optionDelete:hover {
152
- opacity: 1;
153
- background-color: #eee;
154
- }
155
- .PollNode__optionDeleteDisabled {
156
- cursor: not-allowed;
157
- }
158
- .PollNode__optionDeleteDisabled:hover {
159
- opacity: 0.3;
160
- background-color: transparent;
161
- }
162
- .PollNode__footer {
163
- display: flex;
164
- justify-content: center;
165
- }
@@ -1,51 +0,0 @@
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 type { JSX } from 'react';
9
- import { DecoratorNode, DOMExportOutput, LexicalNode, SerializedLexicalNode, Spread, StateConfigValue, type StateValueOrUpdater } from 'lexical';
10
- export type Options = ReadonlyArray<Option>;
11
- export type Option = Readonly<{
12
- text: string;
13
- uid: string;
14
- votes: Array<string>;
15
- }>;
16
- export declare function createPollOption(text?: string): Option;
17
- export type SerializedPollNode = Spread<{
18
- question: string;
19
- options: Options;
20
- }, SerializedLexicalNode>;
21
- declare const questionState: import("lexical").StateConfig<"question", string>;
22
- declare const optionsState: import("lexical").StateConfig<"options", Options>;
23
- export declare class PollNode extends DecoratorNode<JSX.Element> {
24
- $config(): import("lexical").StaticNodeConfigRecord<"poll", {
25
- extends: typeof DecoratorNode;
26
- importDOM: import("lexical").DOMConversionMap<HTMLElement>;
27
- stateConfigs: ({
28
- flat: true;
29
- stateConfig: import("lexical").StateConfig<"question", string>;
30
- } | {
31
- flat: true;
32
- stateConfig: import("lexical").StateConfig<"options", Options>;
33
- })[];
34
- }>;
35
- getQuestion(): StateConfigValue<typeof questionState>;
36
- setQuestion(valueOrUpdater: StateValueOrUpdater<typeof questionState>): this;
37
- getOptions(): StateConfigValue<typeof optionsState>;
38
- setOptions(valueOrUpdater: StateValueOrUpdater<typeof optionsState>): this;
39
- addOption(option: Option): this;
40
- deleteOption(option: Option): this;
41
- setOptionText(option: Option, text: string): this;
42
- toggleVote(option: Option, username: string): this;
43
- exportDOM(): DOMExportOutput;
44
- createDOM(): HTMLElement;
45
- updateDOM(): false;
46
- decorate(): JSX.Element;
47
- }
48
- export declare function $createPollNode(question: string, options: Options): PollNode;
49
- export declare function $isPollNode(node: LexicalNode | null | undefined): node is PollNode;
50
- export {};
51
- //# sourceMappingURL=PollNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PollNode.d.ts","sourceRoot":"","sources":["../../src/nodes/PollNode.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE/B,OAAO,EAKL,aAAa,EAEb,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,MAAM,EACN,gBAAgB,EAChB,KAAK,mBAAmB,EACzB,MAAM,SAAS,CAAC;AAGjB,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;AAE5C,MAAM,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC,CAAC;AAWH,wBAAgB,gBAAgB,CAAC,IAAI,SAAK,GAAG,MAAM,CAMlD;AAcD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACrC;IACE,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB,EACD,qBAAqB,CACtB,CAAC;AAgCF,QAAA,MAAM,aAAa,mDAEjB,CAAC;AACH,QAAA,MAAM,YAAY,mDAIhB,CAAC;AAEH,qBAAa,QAAS,SAAQ,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC;IACtD,OAAO;;;;;;;;;;;IAmBP,WAAW,IAAI,gBAAgB,CAAC,OAAO,aAAa,CAAC;IAGrD,WAAW,CAAC,cAAc,EAAE,mBAAmB,CAAC,OAAO,aAAa,CAAC,GAAG,IAAI;IAG5E,UAAU,IAAI,gBAAgB,CAAC,OAAO,YAAY,CAAC;IAGnD,UAAU,CAAC,cAAc,EAAE,mBAAmB,CAAC,OAAO,YAAY,CAAC,GAAG,IAAI;IAI1E,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAYlC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAUjD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAqBlD,SAAS,IAAI,eAAe;IAU5B,SAAS,IAAI,WAAW;IAMxB,SAAS,IAAI,KAAK;IAIlB,QAAQ,IAAI,GAAG,CAAC,OAAO;CASxB;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,QAAQ,CAE5E;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,QAAQ,CAElB"}
@@ -1,153 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { $getState, $setState, buildImportMap, createState, DecoratorNode, } from 'lexical';
3
- import * as React from 'react';
4
- const PollComponent = React.lazy(() => import('./PollComponent'));
5
- function createUID() {
6
- return Math.random()
7
- .toString(36)
8
- .replace(/[^a-z]+/g, '')
9
- .substring(0, 5);
10
- }
11
- export function createPollOption(text = '') {
12
- return {
13
- text,
14
- uid: createUID(),
15
- votes: [],
16
- };
17
- }
18
- function cloneOption(option, text, votes) {
19
- return {
20
- text,
21
- uid: option.uid,
22
- votes: votes || Array.from(option.votes),
23
- };
24
- }
25
- function $convertPollElement(domNode) {
26
- const question = domNode.getAttribute('data-lexical-poll-question');
27
- const options = domNode.getAttribute('data-lexical-poll-options');
28
- if (question !== null && options !== null) {
29
- const node = $createPollNode(question, JSON.parse(options));
30
- return { node };
31
- }
32
- return null;
33
- }
34
- function parseOptions(json) {
35
- const options = [];
36
- if (Array.isArray(json)) {
37
- for (const row of json) {
38
- if (row &&
39
- typeof row.text === 'string' &&
40
- typeof row.uid === 'string' &&
41
- Array.isArray(row.votes) &&
42
- row.votes.every((v) => typeof v === 'string')) {
43
- options.push(row);
44
- }
45
- }
46
- }
47
- return options;
48
- }
49
- const questionState = createState('question', {
50
- parse: (v) => (typeof v === 'string' ? v : ''),
51
- });
52
- const optionsState = createState('options', {
53
- isEqual: (a, b) => a.length === b.length && JSON.stringify(a) === JSON.stringify(b),
54
- parse: parseOptions,
55
- });
56
- export class PollNode extends DecoratorNode {
57
- $config() {
58
- return this.config('poll', {
59
- extends: DecoratorNode,
60
- importDOM: buildImportMap({
61
- span: (domNode) => domNode.getAttribute('data-lexical-poll-question') !== null
62
- ? {
63
- conversion: $convertPollElement,
64
- priority: 2,
65
- }
66
- : null,
67
- }),
68
- stateConfigs: [
69
- { flat: true, stateConfig: questionState },
70
- { flat: true, stateConfig: optionsState },
71
- ],
72
- });
73
- }
74
- getQuestion() {
75
- return $getState(this, questionState);
76
- }
77
- setQuestion(valueOrUpdater) {
78
- return $setState(this, questionState, valueOrUpdater);
79
- }
80
- getOptions() {
81
- return $getState(this, optionsState);
82
- }
83
- setOptions(valueOrUpdater) {
84
- return $setState(this, optionsState, valueOrUpdater);
85
- }
86
- addOption(option) {
87
- return this.setOptions((options) => [...options, option]);
88
- }
89
- deleteOption(option) {
90
- return this.setOptions((prevOptions) => {
91
- const index = prevOptions.indexOf(option);
92
- if (index === -1) {
93
- return prevOptions;
94
- }
95
- const options = Array.from(prevOptions);
96
- options.splice(index, 1);
97
- return options;
98
- });
99
- }
100
- setOptionText(option, text) {
101
- return this.setOptions((prevOptions) => {
102
- const clonedOption = cloneOption(option, text);
103
- const options = Array.from(prevOptions);
104
- const index = options.indexOf(option);
105
- options[index] = clonedOption;
106
- return options;
107
- });
108
- }
109
- toggleVote(option, username) {
110
- return this.setOptions((prevOptions) => {
111
- const index = prevOptions.indexOf(option);
112
- if (index === -1) {
113
- return prevOptions;
114
- }
115
- const votes = option.votes;
116
- const votesClone = Array.from(votes);
117
- const voteIndex = votes.indexOf(username);
118
- if (voteIndex === -1) {
119
- votesClone.push(username);
120
- }
121
- else {
122
- votesClone.splice(voteIndex, 1);
123
- }
124
- const clonedOption = cloneOption(option, option.text, votesClone);
125
- const options = Array.from(prevOptions);
126
- options[index] = clonedOption;
127
- return options;
128
- });
129
- }
130
- exportDOM() {
131
- const element = document.createElement('span');
132
- element.setAttribute('data-lexical-poll-question', this.getQuestion());
133
- element.setAttribute('data-lexical-poll-options', JSON.stringify(this.getOptions()));
134
- return { element };
135
- }
136
- createDOM() {
137
- const elem = document.createElement('span');
138
- elem.style.display = 'inline-block';
139
- return elem;
140
- }
141
- updateDOM() {
142
- return false;
143
- }
144
- decorate() {
145
- return (_jsx(PollComponent, { question: this.getQuestion(), options: this.getOptions(), nodeKey: this.__key }));
146
- }
147
- }
148
- export function $createPollNode(question, options) {
149
- return new PollNode().setQuestion(question).setOptions(options);
150
- }
151
- export function $isPollNode(node) {
152
- return node instanceof PollNode;
153
- }
@@ -1,18 +0,0 @@
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 type { LexicalEditor, NodeKey } from "lexical";
9
- import type { JSX } from "react";
10
- import "./StickyNode.css";
11
- export default function StickyComponent({ x, y, nodeKey, color, caption, }: {
12
- caption: LexicalEditor;
13
- color: "pink" | "yellow";
14
- nodeKey: NodeKey;
15
- x: number;
16
- y: number;
17
- }): JSX.Element;
18
- //# sourceMappingURL=StickyComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StickyComponent.d.ts","sourceRoot":"","sources":["../../src/nodes/StickyComponent.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,kBAAkB,CAAC;AAmC1B,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,CAAC,EACD,CAAC,EACD,OAAO,EACP,KAAK,EACL,OAAO,GACR,EAAE;IACD,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,GAAG,GAAG,CAAC,OAAO,CAmMd"}
@@ -1,155 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import "./StickyNode.css";
3
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
4
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
5
- import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
6
- import { PlainTextPlugin } from "@lexical/react/LexicalPlainTextPlugin";
7
- import { calculateZoomLevel } from "@lexical/utils";
8
- import { $getNodeByKey } from "lexical";
9
- import { useEffect, useLayoutEffect, useRef } from "react";
10
- import StickyEditorTheme from "../themes/StickyEditorTheme";
11
- import ContentEditable from "../ui/ContentEditable";
12
- import { $isStickyNode } from "./StickyNode";
13
- function positionSticky(stickyElem, positioning) {
14
- const style = stickyElem.style;
15
- const rootElementRect = positioning.rootElementRect;
16
- const rectLeft = rootElementRect !== null ? rootElementRect.left : 0;
17
- const rectTop = rootElementRect !== null ? rootElementRect.top : 0;
18
- style.top = rectTop + positioning.y + "px";
19
- style.left = rectLeft + positioning.x + "px";
20
- }
21
- export default function StickyComponent({ x, y, nodeKey, color, caption, }) {
22
- const [editor] = useLexicalComposerContext();
23
- const stickyContainerRef = useRef(null);
24
- const positioningRef = useRef({
25
- isDragging: false,
26
- offsetX: 0,
27
- offsetY: 0,
28
- rootElementRect: null,
29
- x: 0,
30
- y: 0,
31
- });
32
- useEffect(() => {
33
- const position = positioningRef.current;
34
- position.x = x;
35
- position.y = y;
36
- const stickyContainer = stickyContainerRef.current;
37
- if (stickyContainer !== null) {
38
- positionSticky(stickyContainer, position);
39
- }
40
- }, [x, y]);
41
- useLayoutEffect(() => {
42
- const position = positioningRef.current;
43
- const resizeObserver = new ResizeObserver((entries) => {
44
- for (let i = 0; i < entries.length; i++) {
45
- const entry = entries[i];
46
- const { target } = entry;
47
- position.rootElementRect = target.getBoundingClientRect();
48
- const stickyContainer = stickyContainerRef.current;
49
- if (stickyContainer !== null) {
50
- positionSticky(stickyContainer, position);
51
- }
52
- }
53
- });
54
- const removeRootListener = editor.registerRootListener((nextRootElem, prevRootElem) => {
55
- if (prevRootElem !== null) {
56
- resizeObserver.unobserve(prevRootElem);
57
- }
58
- if (nextRootElem !== null) {
59
- resizeObserver.observe(nextRootElem);
60
- }
61
- });
62
- const handleWindowResize = () => {
63
- const rootElement = editor.getRootElement();
64
- const stickyContainer = stickyContainerRef.current;
65
- if (rootElement !== null && stickyContainer !== null) {
66
- position.rootElementRect = rootElement.getBoundingClientRect();
67
- positionSticky(stickyContainer, position);
68
- }
69
- };
70
- window.addEventListener("resize", handleWindowResize);
71
- return () => {
72
- window.removeEventListener("resize", handleWindowResize);
73
- removeRootListener();
74
- };
75
- }, [editor]);
76
- useEffect(() => {
77
- const stickyContainer = stickyContainerRef.current;
78
- if (stickyContainer !== null) {
79
- // Delay adding transition so we don't trigger the
80
- // transition on load of the sticky.
81
- setTimeout(() => {
82
- stickyContainer.style.setProperty("transition", "top 0.3s ease 0s, left 0.3s ease 0s");
83
- }, 500);
84
- }
85
- }, []);
86
- const handlePointerMove = (event) => {
87
- const stickyContainer = stickyContainerRef.current;
88
- const positioning = positioningRef.current;
89
- const rootElementRect = positioning.rootElementRect;
90
- const zoom = calculateZoomLevel(stickyContainer);
91
- if (stickyContainer !== null &&
92
- positioning.isDragging &&
93
- rootElementRect !== null) {
94
- positioning.x =
95
- event.pageX / zoom - positioning.offsetX - rootElementRect.left;
96
- positioning.y =
97
- event.pageY / zoom - positioning.offsetY - rootElementRect.top;
98
- positionSticky(stickyContainer, positioning);
99
- }
100
- };
101
- const handlePointerUp = (event) => {
102
- const stickyContainer = stickyContainerRef.current;
103
- const positioning = positioningRef.current;
104
- if (stickyContainer !== null) {
105
- positioning.isDragging = false;
106
- stickyContainer.classList.remove("dragging");
107
- editor.update(() => {
108
- const node = $getNodeByKey(nodeKey);
109
- if ($isStickyNode(node)) {
110
- node.setPosition(positioning.x, positioning.y);
111
- }
112
- });
113
- }
114
- document.removeEventListener("pointermove", handlePointerMove);
115
- document.removeEventListener("pointerup", handlePointerUp);
116
- };
117
- const handleDelete = () => {
118
- editor.update(() => {
119
- const node = $getNodeByKey(nodeKey);
120
- if ($isStickyNode(node)) {
121
- node.remove();
122
- }
123
- });
124
- };
125
- const handleColorChange = () => {
126
- editor.update(() => {
127
- const node = $getNodeByKey(nodeKey);
128
- if ($isStickyNode(node)) {
129
- node.toggleColor();
130
- }
131
- });
132
- };
133
- return (_jsx("div", { ref: stickyContainerRef, className: "sticky-note-container", children: _jsxs("div", { className: `sticky-note ${color}`, onPointerDown: (event) => {
134
- const stickyContainer = stickyContainerRef.current;
135
- if (stickyContainer == null ||
136
- event.button === 2 ||
137
- event.target !== stickyContainer.firstChild) {
138
- // Right click or click on editor should not work
139
- return;
140
- }
141
- const stickContainer = stickyContainer;
142
- const positioning = positioningRef.current;
143
- if (stickContainer !== null) {
144
- const { top, left } = stickContainer.getBoundingClientRect();
145
- const zoom = calculateZoomLevel(stickContainer);
146
- positioning.offsetX = event.clientX / zoom - left;
147
- positioning.offsetY = event.clientY / zoom - top;
148
- positioning.isDragging = true;
149
- stickContainer.classList.add("dragging");
150
- document.addEventListener("pointermove", handlePointerMove);
151
- document.addEventListener("pointerup", handlePointerUp);
152
- event.preventDefault();
153
- }
154
- }, children: [_jsx("button", { onClick: handleDelete, className: "delete", "aria-label": "Delete sticky note", title: "Delete", children: "X" }), _jsx("button", { onClick: handleColorChange, className: "color", "aria-label": "Change sticky note color", title: "Color", children: _jsx("i", { className: "bucket" }) }), _jsx(LexicalNestedComposer, { initialEditor: caption, initialTheme: StickyEditorTheme, children: _jsx(PlainTextPlugin, { contentEditable: _jsx(ContentEditable, { placeholder: "What's up?", placeholderClassName: "StickyNode__placeholder", className: "StickyNode__contentEditable" }), ErrorBoundary: LexicalErrorBoundary }) })] }) }));
155
- }