5htp-core 0.4.8 → 0.4.9-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 (190) hide show
  1. package/package.json +5 -1
  2. package/src/client/assets/css/components/table.less +3 -0
  3. package/src/client/components/Form.ts +2 -6
  4. package/src/client/components/Table/index.tsx +24 -79
  5. package/src/client/components/button.tsx +2 -1
  6. package/src/client/components/containers/Popover/index.tsx +2 -2
  7. package/src/client/components/dropdown/index.tsx +16 -6
  8. package/src/client/components/input/Slider/index.tsx +0 -2
  9. package/src/client/components/inputv3/Rte/Editor.tsx +271 -0
  10. package/src/client/components/inputv3/Rte/ToolbarPlugin/BlockFormat.tsx +220 -0
  11. package/src/client/components/inputv3/Rte/ToolbarPlugin/ElementFormat.tsx +107 -0
  12. package/src/client/components/inputv3/Rte/ToolbarPlugin/index.tsx +768 -0
  13. package/src/client/components/inputv3/Rte/appSettings.ts +36 -0
  14. package/src/client/components/inputv3/Rte/context/FlashMessageContext.tsx +68 -0
  15. package/src/client/components/inputv3/Rte/context/SettingsContext.tsx +71 -0
  16. package/src/client/components/inputv3/Rte/context/SharedAutocompleteContext.tsx +71 -0
  17. package/src/client/components/inputv3/Rte/context/SharedHistoryContext.tsx +35 -0
  18. package/src/client/components/inputv3/Rte/currentEditor.ts +42 -0
  19. package/src/client/components/inputv3/Rte/hooks/useFlashMessage.tsx +16 -0
  20. package/src/client/components/inputv3/Rte/hooks/useReport.ts +67 -0
  21. package/src/client/components/inputv3/Rte/images/emoji/1F600.png +0 -0
  22. package/src/client/components/inputv3/Rte/images/emoji/1F641.png +0 -0
  23. package/src/client/components/inputv3/Rte/images/emoji/1F642.png +0 -0
  24. package/src/client/components/inputv3/Rte/images/emoji/2764.png +0 -0
  25. package/src/client/components/inputv3/Rte/images/emoji/LICENSE.md +5 -0
  26. package/src/client/components/inputv3/Rte/images/icons/draggable-block-menu.svg +1 -0
  27. package/src/client/components/inputv3/Rte/images/icons/prettier-error.svg +1 -0
  28. package/src/client/components/inputv3/Rte/images/icons/prettier.svg +1 -0
  29. package/src/client/components/inputv3/Rte/images/image/LICENSE.md +5 -0
  30. package/src/client/components/inputv3/Rte/images/image-broken.svg +4 -0
  31. package/src/client/components/inputv3/Rte/images/logo.svg +1 -0
  32. package/src/client/components/inputv3/Rte/index.tsx +63 -79
  33. package/src/client/components/inputv3/Rte/nodes/AutocompleteNode.tsx +119 -0
  34. package/src/client/components/inputv3/Rte/nodes/EmojiNode.tsx +102 -0
  35. package/src/client/components/inputv3/Rte/nodes/EquationComponent.tsx +141 -0
  36. package/src/client/components/inputv3/Rte/nodes/EquationNode.tsx +174 -0
  37. package/src/client/components/inputv3/Rte/nodes/FigmaNode.tsx +135 -0
  38. package/src/client/components/inputv3/Rte/nodes/ImageComponent.tsx +468 -0
  39. package/src/client/components/inputv3/Rte/nodes/ImageNode.css +43 -0
  40. package/src/client/components/inputv3/Rte/nodes/ImageNode.tsx +266 -0
  41. package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageComponent.tsx +402 -0
  42. package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.css +94 -0
  43. package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.tsx +294 -0
  44. package/src/client/components/inputv3/Rte/nodes/KeywordNode.ts +67 -0
  45. package/src/client/components/inputv3/Rte/nodes/LayoutContainerNode.ts +137 -0
  46. package/src/client/components/inputv3/Rte/nodes/LayoutItemNode.ts +71 -0
  47. package/src/client/components/inputv3/Rte/nodes/MentionNode.ts +130 -0
  48. package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.css +62 -0
  49. package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.tsx +170 -0
  50. package/src/client/components/inputv3/Rte/nodes/PlaygroundNodes.ts +76 -0
  51. package/src/client/components/inputv3/Rte/nodes/PollComponent.tsx +249 -0
  52. package/src/client/components/inputv3/Rte/nodes/PollNode.css +187 -0
  53. package/src/client/components/inputv3/Rte/nodes/PollNode.tsx +209 -0
  54. package/src/client/components/inputv3/Rte/nodes/StickyComponent.tsx +261 -0
  55. package/src/client/components/inputv3/Rte/nodes/StickyNode.css +37 -0
  56. package/src/client/components/inputv3/Rte/nodes/StickyNode.tsx +150 -0
  57. package/src/client/components/inputv3/Rte/nodes/TweetNode.tsx +223 -0
  58. package/src/client/components/inputv3/Rte/nodes/YouTubeNode.tsx +184 -0
  59. package/src/client/components/inputv3/Rte/plugins/ActionsPlugin/index.tsx +334 -0
  60. package/src/client/components/inputv3/Rte/plugins/AutoEmbedPlugin/index.tsx +352 -0
  61. package/src/client/components/inputv3/Rte/plugins/AutoLinkPlugin/index.tsx +32 -0
  62. package/src/client/components/inputv3/Rte/plugins/AutocompletePlugin/index.tsx +2529 -0
  63. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +70 -0
  64. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +14 -0
  65. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +156 -0
  66. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.css +54 -0
  67. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.tsx +190 -0
  68. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/utils.ts +33 -0
  69. package/src/client/components/inputv3/Rte/plugins/CodeHighlightPlugin/index.ts +21 -0
  70. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/Collapsible.css +57 -0
  71. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts +168 -0
  72. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContentNode.ts +127 -0
  73. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts +152 -0
  74. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleUtils.ts +17 -0
  75. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/index.ts +284 -0
  76. package/src/client/components/inputv3/Rte/plugins/ComponentPickerPlugin/index.tsx +370 -0
  77. package/src/client/components/inputv3/Rte/plugins/ContextMenuPlugin/index.tsx +270 -0
  78. package/src/client/components/inputv3/Rte/plugins/DocsPlugin/index.tsx +20 -0
  79. package/src/client/components/inputv3/Rte/plugins/DragDropPastePlugin/index.ts +51 -0
  80. package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.css +36 -0
  81. package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.tsx +43 -0
  82. package/src/client/components/inputv3/Rte/plugins/EmojiPickerPlugin/index.tsx +198 -0
  83. package/src/client/components/inputv3/Rte/plugins/EmojisPlugin/index.ts +75 -0
  84. package/src/client/components/inputv3/Rte/plugins/EquationsPlugin/index.tsx +82 -0
  85. package/src/client/components/inputv3/Rte/plugins/FigmaPlugin/index.tsx +40 -0
  86. package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.css +41 -0
  87. package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.tsx +393 -0
  88. package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.css +141 -0
  89. package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.tsx +388 -0
  90. package/src/client/components/inputv3/Rte/plugins/ImagesPlugin/index.tsx +350 -0
  91. package/src/client/components/inputv3/Rte/plugins/InlineImagePlugin/index.tsx +336 -0
  92. package/src/client/components/inputv3/Rte/plugins/KeywordsPlugin/index.ts +56 -0
  93. package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/InsertLayoutDialog.tsx +58 -0
  94. package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/LayoutPlugin.tsx +219 -0
  95. package/src/client/components/inputv3/Rte/plugins/LinkPlugin/index.tsx +34 -0
  96. package/src/client/components/inputv3/Rte/plugins/ListMaxIndentLevelPlugin/index.ts +85 -0
  97. package/src/client/components/inputv3/Rte/plugins/MarkdownShortcutPlugin/index.tsx +16 -0
  98. package/src/client/components/inputv3/Rte/plugins/MarkdownTransformers/index.ts +324 -0
  99. package/src/client/components/inputv3/Rte/plugins/MaxLengthPlugin/index.tsx +53 -0
  100. package/src/client/components/inputv3/Rte/plugins/MentionsPlugin/index.tsx +696 -0
  101. package/src/client/components/inputv3/Rte/plugins/PageBreakPlugin/index.tsx +57 -0
  102. package/src/client/components/inputv3/Rte/plugins/PasteLogPlugin/index.tsx +54 -0
  103. package/src/client/components/inputv3/Rte/plugins/PollPlugin/index.tsx +86 -0
  104. package/src/client/components/inputv3/Rte/plugins/SpeechToTextPlugin/index.ts +125 -0
  105. package/src/client/components/inputv3/Rte/plugins/StickyPlugin/index.ts +22 -0
  106. package/src/client/components/inputv3/Rte/plugins/TabFocusPlugin/index.tsx +65 -0
  107. package/src/client/components/inputv3/Rte/plugins/TableActionMenuPlugin/index.tsx +773 -0
  108. package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.css +12 -0
  109. package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.tsx +436 -0
  110. package/src/client/components/inputv3/Rte/plugins/TableHoverActionsPlugin/index.tsx +287 -0
  111. package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.css +95 -0
  112. package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.tsx +197 -0
  113. package/src/client/components/inputv3/Rte/plugins/TablePlugin.tsx +178 -0
  114. package/src/client/components/inputv3/Rte/plugins/TestRecorderPlugin/index.tsx +468 -0
  115. package/src/client/components/inputv3/Rte/plugins/TreeViewPlugin/index.tsx +26 -0
  116. package/src/client/components/inputv3/Rte/plugins/TwitterPlugin/index.ts +41 -0
  117. package/src/client/components/inputv3/Rte/plugins/TypingPerfPlugin/index.ts +117 -0
  118. package/src/client/components/inputv3/Rte/plugins/YouTubePlugin/index.ts +41 -0
  119. package/src/client/components/inputv3/Rte/shared/canUseDOM.ts +4 -0
  120. package/src/client/components/inputv3/Rte/shared/caretFromPoint.ts +40 -0
  121. package/src/client/components/inputv3/Rte/shared/environment.ts +56 -0
  122. package/src/client/components/inputv3/Rte/shared/invariant.ts +26 -0
  123. package/src/client/components/inputv3/Rte/shared/normalizeClassNames.ts +21 -0
  124. package/src/client/components/inputv3/Rte/shared/react-test-utils.ts +18 -0
  125. package/src/client/components/inputv3/Rte/shared/reactPatches.ts +22 -0
  126. package/src/client/components/inputv3/Rte/shared/simpleDiffWithCursor.ts +49 -0
  127. package/src/client/components/inputv3/Rte/shared/useLayoutEffect.ts +19 -0
  128. package/src/client/components/inputv3/Rte/shared/warnOnlyOnce.ts +20 -0
  129. package/src/client/components/inputv3/Rte/style.less +30 -60
  130. package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.css +13 -0
  131. package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.ts +20 -0
  132. package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.css +447 -0
  133. package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.ts +120 -0
  134. package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.css +13 -0
  135. package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.ts +20 -0
  136. package/src/client/components/inputv3/Rte/ui/ColorPicker.css +88 -0
  137. package/src/client/components/inputv3/Rte/ui/ColorPicker.tsx +365 -0
  138. package/src/client/components/inputv3/Rte/ui/ContentEditable.css +44 -0
  139. package/src/client/components/inputv3/Rte/ui/ContentEditable.tsx +36 -0
  140. package/src/client/components/inputv3/Rte/ui/DropDown.tsx +259 -0
  141. package/src/client/components/inputv3/Rte/ui/DropdownColorPicker.tsx +41 -0
  142. package/src/client/components/inputv3/Rte/ui/EquationEditor.css +38 -0
  143. package/src/client/components/inputv3/Rte/ui/EquationEditor.tsx +56 -0
  144. package/src/client/components/inputv3/Rte/ui/FileInput.tsx +38 -0
  145. package/src/client/components/inputv3/Rte/ui/FlashMessage.css +28 -0
  146. package/src/client/components/inputv3/Rte/ui/FlashMessage.tsx +29 -0
  147. package/src/client/components/inputv3/Rte/ui/ImageResizer.tsx +316 -0
  148. package/src/client/components/inputv3/Rte/ui/Input.css +32 -0
  149. package/src/client/components/inputv3/Rte/ui/KatexRenderer.tsx +54 -0
  150. package/src/client/components/inputv3/Rte/ui/Switch.tsx +36 -0
  151. package/src/client/components/inputv3/Rte/utils/docSerialization.ts +77 -0
  152. package/src/client/components/inputv3/Rte/utils/emoji-list.ts +16615 -0
  153. package/src/client/components/inputv3/Rte/utils/getDOMRangeRect.ts +27 -0
  154. package/src/client/components/inputv3/Rte/utils/getSelectedNode.ts +27 -0
  155. package/src/client/components/inputv3/Rte/utils/guard.ts +10 -0
  156. package/src/client/components/inputv3/Rte/utils/isMobileWidth.ts +7 -0
  157. package/src/client/components/inputv3/Rte/utils/joinClasses.ts +13 -0
  158. package/src/client/components/inputv3/Rte/utils/setFloatingElemPosition.ts +51 -0
  159. package/src/client/components/inputv3/Rte/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
  160. package/src/client/components/inputv3/Rte/utils/swipe.ts +127 -0
  161. package/src/client/components/inputv3/Rte/utils/url.ts +38 -0
  162. package/src/client/components/inputv3/base.tsx +10 -7
  163. package/src/client/components/inputv3/file/index.tsx +11 -5
  164. package/src/client/components/inputv3/index.tsx +2 -2
  165. package/src/common/data/rte/nodes.ts +60 -9
  166. package/src/common/validation/index.ts +21 -2
  167. package/src/common/validation/schema.ts +34 -11
  168. package/src/common/validation/validator.ts +12 -4
  169. package/src/common/validation/validators.ts +112 -63
  170. package/src/server/services/router/http/multipart.ts +0 -1
  171. package/src/server/services/router/request/index.ts +1 -1
  172. package/src/server/services/schema/index.ts +26 -4
  173. package/src/server/services/schema/request.ts +3 -2
  174. package/src/server/services/schema/rte.ts +110 -0
  175. package/src/{common/data/rte/index.ts → server/utils/rte.ts} +27 -16
  176. package/src/client/components/inputv3/Rte/ExampleTheme.tsx +0 -42
  177. package/src/client/components/inputv3/Rte/ToolbarPlugin.tsx +0 -167
  178. package/src/client/components/inputv3/Rte/icons/LICENSE.md +0 -5
  179. package/src/client/components/inputv3/Rte/icons/arrow-clockwise.svg +0 -4
  180. package/src/client/components/inputv3/Rte/icons/arrow-counterclockwise.svg +0 -4
  181. package/src/client/components/inputv3/Rte/icons/journal-text.svg +0 -5
  182. package/src/client/components/inputv3/Rte/icons/justify.svg +0 -3
  183. package/src/client/components/inputv3/Rte/icons/text-center.svg +0 -3
  184. package/src/client/components/inputv3/Rte/icons/text-left.svg +0 -3
  185. package/src/client/components/inputv3/Rte/icons/text-paragraph.svg +0 -3
  186. package/src/client/components/inputv3/Rte/icons/text-right.svg +0 -3
  187. package/src/client/components/inputv3/Rte/icons/type-bold.svg +0 -3
  188. package/src/client/components/inputv3/Rte/icons/type-italic.svg +0 -3
  189. package/src/client/components/inputv3/Rte/icons/type-strikethrough.svg +0 -3
  190. package/src/client/components/inputv3/Rte/icons/type-underline.svg +0 -3
@@ -0,0 +1,187 @@
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
+ font-size: 1rem;
20
+ }
21
+
22
+ .PollNode__container.focused {
23
+ outline: 2px solid rgb(60, 132, 244);
24
+ }
25
+
26
+ .PollNode__inner {
27
+ margin: 15px;
28
+ cursor: default;
29
+ }
30
+
31
+ .PollNode__heading {
32
+ margin-left: 0px;
33
+ margin-top: 0px;
34
+ margin-right: 0px;
35
+ margin-bottom: 15px;
36
+ color: #444;
37
+ text-align: center;
38
+ font-size: 18px;
39
+ }
40
+
41
+ .PollNode__optionContainer {
42
+ display: flex;
43
+ flex-direction: row;
44
+ margin-bottom: 10px;
45
+ align-items: center;
46
+ }
47
+
48
+ .PollNode__optionInputWrapper {
49
+ display: flex;
50
+ flex: 10px;
51
+ border: 1px solid rgb(61, 135, 245);
52
+ border-radius: 5px;
53
+ position: relative;
54
+ overflow: hidden;
55
+ cursor: pointer;
56
+ }
57
+
58
+ .PollNode__optionInput {
59
+ display: flex;
60
+ flex: 1px;
61
+ border: 0px;
62
+ padding: 7px;
63
+ color: rgb(61, 135, 245);
64
+ background-color: transparent;
65
+ font-weight: bold;
66
+ outline: 0px;
67
+ z-index: 0;
68
+ }
69
+
70
+ .PollNode__optionInput::placeholder {
71
+ font-weight: normal;
72
+ color: #999;
73
+ }
74
+
75
+ .PollNode__optionInputVotes {
76
+ background-color: rgb(236, 243, 254);
77
+ height: 100%;
78
+ position: absolute;
79
+ top: 0px;
80
+ left: 0px;
81
+ transition: width 1s ease;
82
+ z-index: 0;
83
+ }
84
+
85
+ .PollNode__optionInputVotesCount {
86
+ color: rgb(61, 135, 245);
87
+ position: absolute;
88
+ right: 15px;
89
+ font-size: 12px;
90
+ top: 5px;
91
+ }
92
+
93
+ .PollNode__optionCheckboxWrapper {
94
+ position: relative;
95
+ display: flex;
96
+ width: 22px;
97
+ height: 22px;
98
+ border: 1px solid #999;
99
+ border-radius: 5px;
100
+ }
101
+
102
+ .PollNode__optionCheckboxChecked {
103
+ border: 1px solid rgb(61, 135, 245);
104
+ background-color: rgb(61, 135, 245);
105
+ }
106
+
107
+ .PollNode__optionCheckboxChecked:after {
108
+ content: '';
109
+ cursor: pointer;
110
+ border-color: #fff;
111
+ border-style: solid;
112
+ position: absolute;
113
+ display: block;
114
+ top: 4px;
115
+ width: 5px;
116
+ left: 8px;
117
+ height: 9px;
118
+ margin: 0;
119
+ transform: rotate(45deg);
120
+ border-width: 0 2px 2px 0;
121
+ pointer-events: none;
122
+ }
123
+
124
+ .PollNode__optionCheckbox {
125
+ border: 0px;
126
+ position: absolute;
127
+ display: block;
128
+ width: 100%;
129
+ height: 100%;
130
+ opacity: 0;
131
+ cursor: pointer;
132
+ }
133
+
134
+ .PollNode__optionDelete {
135
+ position: relative;
136
+ display: flex;
137
+ width: 28px;
138
+ height: 28px;
139
+ margin-left: 6px;
140
+ border: 0px;
141
+ background-color: transparent;
142
+ background-position: 6px 6px;
143
+ background-repeat: no-repeat;
144
+ z-index: 0;
145
+ cursor: pointer;
146
+ border-radius: 5px;
147
+ opacity: 0.3;
148
+ }
149
+
150
+ .PollNode__optionDelete:before,
151
+ .PollNode__optionDelete:after {
152
+ position: absolute;
153
+ display: block;
154
+ content: '';
155
+ background-color: #999;
156
+ width: 2px;
157
+ height: 15px;
158
+ top: 6px;
159
+ left: 13px;
160
+ }
161
+
162
+ .PollNode__optionDelete:before {
163
+ transform: rotate(-45deg);
164
+ }
165
+
166
+ .PollNode__optionDelete:after {
167
+ transform: rotate(45deg);
168
+ }
169
+
170
+ .PollNode__optionDelete:hover {
171
+ opacity: 1;
172
+ background-color: #eee;
173
+ }
174
+
175
+ .PollNode__optionDeleteDisabled {
176
+ cursor: not-allowed;
177
+ }
178
+
179
+ .PollNode__optionDeleteDisabled:hover {
180
+ opacity: 0.3;
181
+ background-color: transparent;
182
+ }
183
+
184
+ .PollNode__footer {
185
+ display: flex;
186
+ justify-content: center;
187
+ }
@@ -0,0 +1,209 @@
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
+ import {
10
+ DecoratorNode,
11
+ DOMConversionMap,
12
+ DOMConversionOutput,
13
+ DOMExportOutput,
14
+ LexicalNode,
15
+ NodeKey,
16
+ SerializedLexicalNode,
17
+ Spread,
18
+ } from 'lexical';
19
+ import * as React from 'react';
20
+ import { Suspense } from 'react';
21
+
22
+ export type Options = ReadonlyArray<Option>;
23
+
24
+ export type Option = Readonly<{
25
+ text: string;
26
+ uid: string;
27
+ votes: Array<number>;
28
+ }>;
29
+
30
+ const PollComponent = React.lazy(() => import('./PollComponent'));
31
+
32
+ function createUID(): string {
33
+ return Math.random()
34
+ .toString(36)
35
+ .replace(/[^a-z]+/g, '')
36
+ .substr(0, 5);
37
+ }
38
+
39
+ export function createPollOption(text = ''): Option {
40
+ return {
41
+ text,
42
+ uid: createUID(),
43
+ votes: [],
44
+ };
45
+ }
46
+
47
+ function cloneOption(
48
+ option: Option,
49
+ text: string,
50
+ votes?: Array<number>,
51
+ ): Option {
52
+ return {
53
+ text,
54
+ uid: option.uid,
55
+ votes: votes || Array.from(option.votes),
56
+ };
57
+ }
58
+
59
+ export type SerializedPollNode = Spread<
60
+ {
61
+ question: string;
62
+ options: Options;
63
+ },
64
+ SerializedLexicalNode
65
+ >;
66
+
67
+ function $convertPollElement(domNode: HTMLElement): DOMConversionOutput | null {
68
+ const question = domNode.getAttribute('data-lexical-poll-question');
69
+ const options = domNode.getAttribute('data-lexical-poll-options');
70
+ if (question !== null && options !== null) {
71
+ const node = $createPollNode(question, JSON.parse(options));
72
+ return { node };
73
+ }
74
+ return null;
75
+ }
76
+
77
+ export class PollNode extends DecoratorNode<JSX.Element> {
78
+ __question: string;
79
+ __options: Options;
80
+
81
+ static getType(): string {
82
+ return 'poll';
83
+ }
84
+
85
+ static clone(node: PollNode): PollNode {
86
+ return new PollNode(node.__question, node.__options, node.__key);
87
+ }
88
+
89
+ static importJSON(serializedNode: SerializedPollNode): PollNode {
90
+ const node = $createPollNode(
91
+ serializedNode.question,
92
+ serializedNode.options,
93
+ );
94
+ serializedNode.options.forEach(node.addOption);
95
+ return node;
96
+ }
97
+
98
+ constructor(question: string, options: Options, key?: NodeKey) {
99
+ super(key);
100
+ this.__question = question;
101
+ this.__options = options;
102
+ }
103
+
104
+ exportJSON(): SerializedPollNode {
105
+ return {
106
+ options: this.__options,
107
+ question: this.__question,
108
+ type: 'poll',
109
+ version: 1,
110
+ };
111
+ }
112
+
113
+ addOption(option: Option): void {
114
+ const self = this.getWritable();
115
+ const options = Array.from(self.__options);
116
+ options.push(option);
117
+ self.__options = options;
118
+ }
119
+
120
+ deleteOption(option: Option): void {
121
+ const self = this.getWritable();
122
+ const options = Array.from(self.__options);
123
+ const index = options.indexOf(option);
124
+ options.splice(index, 1);
125
+ self.__options = options;
126
+ }
127
+
128
+ setOptionText(option: Option, text: string): void {
129
+ const self = this.getWritable();
130
+ const clonedOption = cloneOption(option, text);
131
+ const options = Array.from(self.__options);
132
+ const index = options.indexOf(option);
133
+ options[index] = clonedOption;
134
+ self.__options = options;
135
+ }
136
+
137
+ toggleVote(option: Option, clientID: number): void {
138
+ const self = this.getWritable();
139
+ const votes = option.votes;
140
+ const votesClone = Array.from(votes);
141
+ const voteIndex = votes.indexOf(clientID);
142
+ if (voteIndex === -1) {
143
+ votesClone.push(clientID);
144
+ } else {
145
+ votesClone.splice(voteIndex, 1);
146
+ }
147
+ const clonedOption = cloneOption(option, option.text, votesClone);
148
+ const options = Array.from(self.__options);
149
+ const index = options.indexOf(option);
150
+ options[index] = clonedOption;
151
+ self.__options = options;
152
+ }
153
+
154
+ static importDOM(): DOMConversionMap | null {
155
+ return {
156
+ span: (domNode: HTMLElement) => {
157
+ if (!domNode.hasAttribute('data-lexical-poll-question')) {
158
+ return null;
159
+ }
160
+ return {
161
+ conversion: $convertPollElement,
162
+ priority: 2,
163
+ };
164
+ },
165
+ };
166
+ }
167
+
168
+ exportDOM(): DOMExportOutput {
169
+ const element = document.createElement('span');
170
+ element.setAttribute('data-lexical-poll-question', this.__question);
171
+ element.setAttribute(
172
+ 'data-lexical-poll-options',
173
+ JSON.stringify(this.__options),
174
+ );
175
+ return { element };
176
+ }
177
+
178
+ createDOM(): HTMLElement {
179
+ const elem = document.createElement('span');
180
+ elem.style.display = 'inline-block';
181
+ return elem;
182
+ }
183
+
184
+ updateDOM(): false {
185
+ return false;
186
+ }
187
+
188
+ decorate(): JSX.Element {
189
+ return (
190
+ <Suspense fallback={null}>
191
+ <PollComponent
192
+ question={this.__question}
193
+ options={this.__options}
194
+ nodeKey={this.__key}
195
+ />
196
+ </Suspense>
197
+ );
198
+ }
199
+ }
200
+
201
+ export function $createPollNode(question: string, options: Options): PollNode {
202
+ return new PollNode(question, options);
203
+ }
204
+
205
+ export function $isPollNode(
206
+ node: LexicalNode | null | undefined,
207
+ ): node is PollNode {
208
+ return node instanceof PollNode;
209
+ }
@@ -0,0 +1,261 @@
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
+ import type {LexicalEditor, NodeKey} from 'lexical';
10
+
11
+ import './StickyNode.css';
12
+
13
+ import {useCollaborationContext} from '@lexical/react/LexicalCollaborationContext';
14
+ import {CollaborationPlugin} from '@lexical/react/LexicalCollaborationPlugin';
15
+ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
16
+ import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
17
+ import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
18
+ import {LexicalNestedComposer} from '@lexical/react/LexicalNestedComposer';
19
+ import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
20
+ import {calculateZoomLevel} from '@lexical/utils';
21
+ import {$getNodeByKey} from 'lexical';
22
+ import * as React from 'react';
23
+ import {useEffect, useRef} from 'react';
24
+ import useLayoutEffect from '../shared/useLayoutEffect';
25
+
26
+ import {useSharedHistoryContext} from '../context/SharedHistoryContext';
27
+ import StickyEditorTheme from '../themes/StickyEditorTheme';
28
+ import ContentEditable from '../ui/ContentEditable';
29
+ import {$isStickyNode} from './StickyNode';
30
+
31
+ type Positioning = {
32
+ isDragging: boolean;
33
+ offsetX: number;
34
+ offsetY: number;
35
+ rootElementRect: null | ClientRect;
36
+ x: number;
37
+ y: number;
38
+ };
39
+
40
+ function positionSticky(
41
+ stickyElem: HTMLElement,
42
+ positioning: Positioning,
43
+ ): void {
44
+ const style = stickyElem.style;
45
+ const rootElementRect = positioning.rootElementRect;
46
+ const rectLeft = rootElementRect !== null ? rootElementRect.left : 0;
47
+ const rectTop = rootElementRect !== null ? rootElementRect.top : 0;
48
+ style.top = rectTop + positioning.y + 'px';
49
+ style.left = rectLeft + positioning.x + 'px';
50
+ }
51
+
52
+ export default function StickyComponent({
53
+ x,
54
+ y,
55
+ nodeKey,
56
+ color,
57
+ caption,
58
+ }: {
59
+ caption: LexicalEditor;
60
+ color: 'pink' | 'yellow';
61
+ nodeKey: NodeKey;
62
+ x: number;
63
+ y: number;
64
+ }): JSX.Element {
65
+ const [editor] = useLexicalComposerContext();
66
+ const stickyContainerRef = useRef<null | HTMLDivElement>(null);
67
+ const positioningRef = useRef<Positioning>({
68
+ isDragging: false,
69
+ offsetX: 0,
70
+ offsetY: 0,
71
+ rootElementRect: null,
72
+ x: 0,
73
+ y: 0,
74
+ });
75
+ const {isCollabActive} = useCollaborationContext();
76
+
77
+ useEffect(() => {
78
+ const position = positioningRef.current;
79
+ position.x = x;
80
+ position.y = y;
81
+
82
+ const stickyContainer = stickyContainerRef.current;
83
+ if (stickyContainer !== null) {
84
+ positionSticky(stickyContainer, position);
85
+ }
86
+ }, [x, y]);
87
+
88
+ useLayoutEffect(() => {
89
+ const position = positioningRef.current;
90
+ const resizeObserver = new ResizeObserver((entries) => {
91
+ for (let i = 0; i < entries.length; i++) {
92
+ const entry = entries[i];
93
+ const {target} = entry;
94
+ position.rootElementRect = target.getBoundingClientRect();
95
+ const stickyContainer = stickyContainerRef.current;
96
+ if (stickyContainer !== null) {
97
+ positionSticky(stickyContainer, position);
98
+ }
99
+ }
100
+ });
101
+
102
+ const removeRootListener = editor.registerRootListener(
103
+ (nextRootElem, prevRootElem) => {
104
+ if (prevRootElem !== null) {
105
+ resizeObserver.unobserve(prevRootElem);
106
+ }
107
+ if (nextRootElem !== null) {
108
+ resizeObserver.observe(nextRootElem);
109
+ }
110
+ },
111
+ );
112
+
113
+ const handleWindowResize = () => {
114
+ const rootElement = editor.getRootElement();
115
+ const stickyContainer = stickyContainerRef.current;
116
+ if (rootElement !== null && stickyContainer !== null) {
117
+ position.rootElementRect = rootElement.getBoundingClientRect();
118
+ positionSticky(stickyContainer, position);
119
+ }
120
+ };
121
+
122
+ window.addEventListener('resize', handleWindowResize);
123
+
124
+ return () => {
125
+ window.removeEventListener('resize', handleWindowResize);
126
+ removeRootListener();
127
+ };
128
+ }, [editor]);
129
+
130
+ useEffect(() => {
131
+ const stickyContainer = stickyContainerRef.current;
132
+ if (stickyContainer !== null) {
133
+ // Delay adding transition so we don't trigger the
134
+ // transition on load of the sticky.
135
+ setTimeout(() => {
136
+ stickyContainer.style.setProperty(
137
+ 'transition',
138
+ 'top 0.3s ease 0s, left 0.3s ease 0s',
139
+ );
140
+ }, 500);
141
+ }
142
+ }, []);
143
+
144
+ const handlePointerMove = (event: PointerEvent) => {
145
+ const stickyContainer = stickyContainerRef.current;
146
+ const positioning = positioningRef.current;
147
+ const rootElementRect = positioning.rootElementRect;
148
+ const zoom = calculateZoomLevel(stickyContainer);
149
+ if (
150
+ stickyContainer !== null &&
151
+ positioning.isDragging &&
152
+ rootElementRect !== null
153
+ ) {
154
+ positioning.x =
155
+ event.pageX / zoom - positioning.offsetX - rootElementRect.left;
156
+ positioning.y =
157
+ event.pageY / zoom - positioning.offsetY - rootElementRect.top;
158
+ positionSticky(stickyContainer, positioning);
159
+ }
160
+ };
161
+
162
+ const handlePointerUp = (event: PointerEvent) => {
163
+ const stickyContainer = stickyContainerRef.current;
164
+ const positioning = positioningRef.current;
165
+ if (stickyContainer !== null) {
166
+ positioning.isDragging = false;
167
+ stickyContainer.classList.remove('dragging');
168
+ editor.update(() => {
169
+ const node = $getNodeByKey(nodeKey);
170
+ if ($isStickyNode(node)) {
171
+ node.setPosition(positioning.x, positioning.y);
172
+ }
173
+ });
174
+ }
175
+ document.removeEventListener('pointermove', handlePointerMove);
176
+ document.removeEventListener('pointerup', handlePointerUp);
177
+ };
178
+
179
+ const handleDelete = () => {
180
+ editor.update(() => {
181
+ const node = $getNodeByKey(nodeKey);
182
+ if ($isStickyNode(node)) {
183
+ node.remove();
184
+ }
185
+ });
186
+ };
187
+
188
+ const handleColorChange = () => {
189
+ editor.update(() => {
190
+ const node = $getNodeByKey(nodeKey);
191
+ if ($isStickyNode(node)) {
192
+ node.toggleColor();
193
+ }
194
+ });
195
+ };
196
+
197
+ const {historyState} = useSharedHistoryContext();
198
+
199
+ return (
200
+ <div ref={stickyContainerRef} className="sticky-note-container">
201
+ <div
202
+ className={`sticky-note ${color}`}
203
+ onPointerDown={(event) => {
204
+ const stickyContainer = stickyContainerRef.current;
205
+ if (
206
+ stickyContainer == null ||
207
+ event.button === 2 ||
208
+ event.target !== stickyContainer.firstChild
209
+ ) {
210
+ // Right click or click on editor should not work
211
+ return;
212
+ }
213
+ const stickContainer = stickyContainer;
214
+ const positioning = positioningRef.current;
215
+ if (stickContainer !== null) {
216
+ const {top, left} = stickContainer.getBoundingClientRect();
217
+ const zoom = calculateZoomLevel(stickContainer);
218
+ positioning.offsetX = event.clientX / zoom - left;
219
+ positioning.offsetY = event.clientY / zoom - top;
220
+ positioning.isDragging = true;
221
+ stickContainer.classList.add('dragging');
222
+ document.addEventListener('pointermove', handlePointerMove);
223
+ document.addEventListener('pointerup', handlePointerUp);
224
+ event.preventDefault();
225
+ }
226
+ }}>
227
+ <button
228
+ onClick={handleDelete}
229
+ className="delete"
230
+ aria-label="Delete sticky note"
231
+ title="Delete">
232
+ X
233
+ </button>
234
+ <button
235
+ onClick={handleColorChange}
236
+ className="color"
237
+ aria-label="Change sticky note color"
238
+ title="Color">
239
+ <i className="bucket" />
240
+ </button>
241
+ <LexicalNestedComposer
242
+ initialEditor={caption}
243
+ initialTheme={StickyEditorTheme}>
244
+
245
+ <HistoryPlugin externalHistoryState={historyState} />
246
+
247
+ <PlainTextPlugin
248
+ contentEditable={
249
+ <ContentEditable
250
+ placeholder="What's up?"
251
+ placeholderClassName="StickyNode__placeholder"
252
+ className="StickyNode__contentEditable"
253
+ />
254
+ }
255
+ ErrorBoundary={LexicalErrorBoundary}
256
+ />
257
+ </LexicalNestedComposer>
258
+ </div>
259
+ </div>
260
+ );
261
+ }
@@ -0,0 +1,37 @@
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
+ .StickyNode__contentEditable {
10
+ min-height: 20px;
11
+ border: 0;
12
+ resize: none;
13
+ cursor: text;
14
+ font-size: 24px;
15
+ caret-color: rgb(5, 5, 5);
16
+ display: block;
17
+ position: relative;
18
+ outline: 0;
19
+ padding: 10px;
20
+ user-select: text;
21
+ white-space: pre-wrap;
22
+ word-wrap: break-word;
23
+ }
24
+ .StickyNode__placeholder {
25
+ font-size: 24px;
26
+ color: #999;
27
+ overflow: hidden;
28
+ position: absolute;
29
+ text-overflow: ellipsis;
30
+ top: 30px;
31
+ left: 20px;
32
+ width: 120px;
33
+ user-select: none;
34
+ white-space: nowrap;
35
+ display: inline-block;
36
+ pointer-events: none;
37
+ }