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.
- package/package.json +5 -1
- package/src/client/assets/css/components/table.less +3 -0
- package/src/client/components/Form.ts +2 -6
- package/src/client/components/Table/index.tsx +24 -79
- package/src/client/components/button.tsx +2 -1
- package/src/client/components/containers/Popover/index.tsx +2 -2
- package/src/client/components/dropdown/index.tsx +16 -6
- package/src/client/components/input/Slider/index.tsx +0 -2
- package/src/client/components/inputv3/Rte/Editor.tsx +271 -0
- package/src/client/components/inputv3/Rte/ToolbarPlugin/BlockFormat.tsx +220 -0
- package/src/client/components/inputv3/Rte/ToolbarPlugin/ElementFormat.tsx +107 -0
- package/src/client/components/inputv3/Rte/ToolbarPlugin/index.tsx +768 -0
- package/src/client/components/inputv3/Rte/appSettings.ts +36 -0
- package/src/client/components/inputv3/Rte/context/FlashMessageContext.tsx +68 -0
- package/src/client/components/inputv3/Rte/context/SettingsContext.tsx +71 -0
- package/src/client/components/inputv3/Rte/context/SharedAutocompleteContext.tsx +71 -0
- package/src/client/components/inputv3/Rte/context/SharedHistoryContext.tsx +35 -0
- package/src/client/components/inputv3/Rte/currentEditor.ts +42 -0
- package/src/client/components/inputv3/Rte/hooks/useFlashMessage.tsx +16 -0
- package/src/client/components/inputv3/Rte/hooks/useReport.ts +67 -0
- package/src/client/components/inputv3/Rte/images/emoji/1F600.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/1F641.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/1F642.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/2764.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/LICENSE.md +5 -0
- package/src/client/components/inputv3/Rte/images/icons/draggable-block-menu.svg +1 -0
- package/src/client/components/inputv3/Rte/images/icons/prettier-error.svg +1 -0
- package/src/client/components/inputv3/Rte/images/icons/prettier.svg +1 -0
- package/src/client/components/inputv3/Rte/images/image/LICENSE.md +5 -0
- package/src/client/components/inputv3/Rte/images/image-broken.svg +4 -0
- package/src/client/components/inputv3/Rte/images/logo.svg +1 -0
- package/src/client/components/inputv3/Rte/index.tsx +63 -79
- package/src/client/components/inputv3/Rte/nodes/AutocompleteNode.tsx +119 -0
- package/src/client/components/inputv3/Rte/nodes/EmojiNode.tsx +102 -0
- package/src/client/components/inputv3/Rte/nodes/EquationComponent.tsx +141 -0
- package/src/client/components/inputv3/Rte/nodes/EquationNode.tsx +174 -0
- package/src/client/components/inputv3/Rte/nodes/FigmaNode.tsx +135 -0
- package/src/client/components/inputv3/Rte/nodes/ImageComponent.tsx +468 -0
- package/src/client/components/inputv3/Rte/nodes/ImageNode.css +43 -0
- package/src/client/components/inputv3/Rte/nodes/ImageNode.tsx +266 -0
- package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageComponent.tsx +402 -0
- package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.css +94 -0
- package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.tsx +294 -0
- package/src/client/components/inputv3/Rte/nodes/KeywordNode.ts +67 -0
- package/src/client/components/inputv3/Rte/nodes/LayoutContainerNode.ts +137 -0
- package/src/client/components/inputv3/Rte/nodes/LayoutItemNode.ts +71 -0
- package/src/client/components/inputv3/Rte/nodes/MentionNode.ts +130 -0
- package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.css +62 -0
- package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.tsx +170 -0
- package/src/client/components/inputv3/Rte/nodes/PlaygroundNodes.ts +76 -0
- package/src/client/components/inputv3/Rte/nodes/PollComponent.tsx +249 -0
- package/src/client/components/inputv3/Rte/nodes/PollNode.css +187 -0
- package/src/client/components/inputv3/Rte/nodes/PollNode.tsx +209 -0
- package/src/client/components/inputv3/Rte/nodes/StickyComponent.tsx +261 -0
- package/src/client/components/inputv3/Rte/nodes/StickyNode.css +37 -0
- package/src/client/components/inputv3/Rte/nodes/StickyNode.tsx +150 -0
- package/src/client/components/inputv3/Rte/nodes/TweetNode.tsx +223 -0
- package/src/client/components/inputv3/Rte/nodes/YouTubeNode.tsx +184 -0
- package/src/client/components/inputv3/Rte/plugins/ActionsPlugin/index.tsx +334 -0
- package/src/client/components/inputv3/Rte/plugins/AutoEmbedPlugin/index.tsx +352 -0
- package/src/client/components/inputv3/Rte/plugins/AutoLinkPlugin/index.tsx +32 -0
- package/src/client/components/inputv3/Rte/plugins/AutocompletePlugin/index.tsx +2529 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +70 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +14 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +156 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.css +54 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.tsx +190 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/utils.ts +33 -0
- package/src/client/components/inputv3/Rte/plugins/CodeHighlightPlugin/index.ts +21 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/Collapsible.css +57 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts +168 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContentNode.ts +127 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts +152 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleUtils.ts +17 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/index.ts +284 -0
- package/src/client/components/inputv3/Rte/plugins/ComponentPickerPlugin/index.tsx +370 -0
- package/src/client/components/inputv3/Rte/plugins/ContextMenuPlugin/index.tsx +270 -0
- package/src/client/components/inputv3/Rte/plugins/DocsPlugin/index.tsx +20 -0
- package/src/client/components/inputv3/Rte/plugins/DragDropPastePlugin/index.ts +51 -0
- package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.css +36 -0
- package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.tsx +43 -0
- package/src/client/components/inputv3/Rte/plugins/EmojiPickerPlugin/index.tsx +198 -0
- package/src/client/components/inputv3/Rte/plugins/EmojisPlugin/index.ts +75 -0
- package/src/client/components/inputv3/Rte/plugins/EquationsPlugin/index.tsx +82 -0
- package/src/client/components/inputv3/Rte/plugins/FigmaPlugin/index.tsx +40 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.css +41 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.tsx +393 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.css +141 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.tsx +388 -0
- package/src/client/components/inputv3/Rte/plugins/ImagesPlugin/index.tsx +350 -0
- package/src/client/components/inputv3/Rte/plugins/InlineImagePlugin/index.tsx +336 -0
- package/src/client/components/inputv3/Rte/plugins/KeywordsPlugin/index.ts +56 -0
- package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/InsertLayoutDialog.tsx +58 -0
- package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/LayoutPlugin.tsx +219 -0
- package/src/client/components/inputv3/Rte/plugins/LinkPlugin/index.tsx +34 -0
- package/src/client/components/inputv3/Rte/plugins/ListMaxIndentLevelPlugin/index.ts +85 -0
- package/src/client/components/inputv3/Rte/plugins/MarkdownShortcutPlugin/index.tsx +16 -0
- package/src/client/components/inputv3/Rte/plugins/MarkdownTransformers/index.ts +324 -0
- package/src/client/components/inputv3/Rte/plugins/MaxLengthPlugin/index.tsx +53 -0
- package/src/client/components/inputv3/Rte/plugins/MentionsPlugin/index.tsx +696 -0
- package/src/client/components/inputv3/Rte/plugins/PageBreakPlugin/index.tsx +57 -0
- package/src/client/components/inputv3/Rte/plugins/PasteLogPlugin/index.tsx +54 -0
- package/src/client/components/inputv3/Rte/plugins/PollPlugin/index.tsx +86 -0
- package/src/client/components/inputv3/Rte/plugins/SpeechToTextPlugin/index.ts +125 -0
- package/src/client/components/inputv3/Rte/plugins/StickyPlugin/index.ts +22 -0
- package/src/client/components/inputv3/Rte/plugins/TabFocusPlugin/index.tsx +65 -0
- package/src/client/components/inputv3/Rte/plugins/TableActionMenuPlugin/index.tsx +773 -0
- package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.css +12 -0
- package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.tsx +436 -0
- package/src/client/components/inputv3/Rte/plugins/TableHoverActionsPlugin/index.tsx +287 -0
- package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.css +95 -0
- package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.tsx +197 -0
- package/src/client/components/inputv3/Rte/plugins/TablePlugin.tsx +178 -0
- package/src/client/components/inputv3/Rte/plugins/TestRecorderPlugin/index.tsx +468 -0
- package/src/client/components/inputv3/Rte/plugins/TreeViewPlugin/index.tsx +26 -0
- package/src/client/components/inputv3/Rte/plugins/TwitterPlugin/index.ts +41 -0
- package/src/client/components/inputv3/Rte/plugins/TypingPerfPlugin/index.ts +117 -0
- package/src/client/components/inputv3/Rte/plugins/YouTubePlugin/index.ts +41 -0
- package/src/client/components/inputv3/Rte/shared/canUseDOM.ts +4 -0
- package/src/client/components/inputv3/Rte/shared/caretFromPoint.ts +40 -0
- package/src/client/components/inputv3/Rte/shared/environment.ts +56 -0
- package/src/client/components/inputv3/Rte/shared/invariant.ts +26 -0
- package/src/client/components/inputv3/Rte/shared/normalizeClassNames.ts +21 -0
- package/src/client/components/inputv3/Rte/shared/react-test-utils.ts +18 -0
- package/src/client/components/inputv3/Rte/shared/reactPatches.ts +22 -0
- package/src/client/components/inputv3/Rte/shared/simpleDiffWithCursor.ts +49 -0
- package/src/client/components/inputv3/Rte/shared/useLayoutEffect.ts +19 -0
- package/src/client/components/inputv3/Rte/shared/warnOnlyOnce.ts +20 -0
- package/src/client/components/inputv3/Rte/style.less +30 -60
- package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.css +13 -0
- package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.ts +20 -0
- package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.css +447 -0
- package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.ts +120 -0
- package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.css +13 -0
- package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.ts +20 -0
- package/src/client/components/inputv3/Rte/ui/ColorPicker.css +88 -0
- package/src/client/components/inputv3/Rte/ui/ColorPicker.tsx +365 -0
- package/src/client/components/inputv3/Rte/ui/ContentEditable.css +44 -0
- package/src/client/components/inputv3/Rte/ui/ContentEditable.tsx +36 -0
- package/src/client/components/inputv3/Rte/ui/DropDown.tsx +259 -0
- package/src/client/components/inputv3/Rte/ui/DropdownColorPicker.tsx +41 -0
- package/src/client/components/inputv3/Rte/ui/EquationEditor.css +38 -0
- package/src/client/components/inputv3/Rte/ui/EquationEditor.tsx +56 -0
- package/src/client/components/inputv3/Rte/ui/FileInput.tsx +38 -0
- package/src/client/components/inputv3/Rte/ui/FlashMessage.css +28 -0
- package/src/client/components/inputv3/Rte/ui/FlashMessage.tsx +29 -0
- package/src/client/components/inputv3/Rte/ui/ImageResizer.tsx +316 -0
- package/src/client/components/inputv3/Rte/ui/Input.css +32 -0
- package/src/client/components/inputv3/Rte/ui/KatexRenderer.tsx +54 -0
- package/src/client/components/inputv3/Rte/ui/Switch.tsx +36 -0
- package/src/client/components/inputv3/Rte/utils/docSerialization.ts +77 -0
- package/src/client/components/inputv3/Rte/utils/emoji-list.ts +16615 -0
- package/src/client/components/inputv3/Rte/utils/getDOMRangeRect.ts +27 -0
- package/src/client/components/inputv3/Rte/utils/getSelectedNode.ts +27 -0
- package/src/client/components/inputv3/Rte/utils/guard.ts +10 -0
- package/src/client/components/inputv3/Rte/utils/isMobileWidth.ts +7 -0
- package/src/client/components/inputv3/Rte/utils/joinClasses.ts +13 -0
- package/src/client/components/inputv3/Rte/utils/setFloatingElemPosition.ts +51 -0
- package/src/client/components/inputv3/Rte/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
- package/src/client/components/inputv3/Rte/utils/swipe.ts +127 -0
- package/src/client/components/inputv3/Rte/utils/url.ts +38 -0
- package/src/client/components/inputv3/base.tsx +10 -7
- package/src/client/components/inputv3/file/index.tsx +11 -5
- package/src/client/components/inputv3/index.tsx +2 -2
- package/src/common/data/rte/nodes.ts +60 -9
- package/src/common/validation/index.ts +21 -2
- package/src/common/validation/schema.ts +34 -11
- package/src/common/validation/validator.ts +12 -4
- package/src/common/validation/validators.ts +112 -63
- package/src/server/services/router/http/multipart.ts +0 -1
- package/src/server/services/router/request/index.ts +1 -1
- package/src/server/services/schema/index.ts +26 -4
- package/src/server/services/schema/request.ts +3 -2
- package/src/server/services/schema/rte.ts +110 -0
- package/src/{common/data/rte/index.ts → server/utils/rte.ts} +27 -16
- package/src/client/components/inputv3/Rte/ExampleTheme.tsx +0 -42
- package/src/client/components/inputv3/Rte/ToolbarPlugin.tsx +0 -167
- package/src/client/components/inputv3/Rte/icons/LICENSE.md +0 -5
- package/src/client/components/inputv3/Rte/icons/arrow-clockwise.svg +0 -4
- package/src/client/components/inputv3/Rte/icons/arrow-counterclockwise.svg +0 -4
- package/src/client/components/inputv3/Rte/icons/journal-text.svg +0 -5
- package/src/client/components/inputv3/Rte/icons/justify.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-center.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-left.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-paragraph.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-right.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-bold.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-italic.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-strikethrough.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-underline.svg +0 -3
|
@@ -0,0 +1,117 @@
|
|
|
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 {useEffect} from 'react';
|
|
10
|
+
|
|
11
|
+
import useReport from '../../hooks/useReport';
|
|
12
|
+
|
|
13
|
+
const validInputTypes = new Set([
|
|
14
|
+
'insertText',
|
|
15
|
+
'insertCompositionText',
|
|
16
|
+
'insertFromComposition',
|
|
17
|
+
'insertLineBreak',
|
|
18
|
+
'insertParagraph',
|
|
19
|
+
'deleteCompositionText',
|
|
20
|
+
'deleteContentBackward',
|
|
21
|
+
'deleteByComposition',
|
|
22
|
+
'deleteContent',
|
|
23
|
+
'deleteContentForward',
|
|
24
|
+
'deleteWordBackward',
|
|
25
|
+
'deleteWordForward',
|
|
26
|
+
'deleteHardLineBackward',
|
|
27
|
+
'deleteSoftLineBackward',
|
|
28
|
+
'deleteHardLineForward',
|
|
29
|
+
'deleteSoftLineForward',
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export default function TypingPerfPlugin(): JSX.Element | null {
|
|
33
|
+
const report = useReport();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
let start = 0;
|
|
36
|
+
let timerId: ReturnType<typeof setTimeout> | null;
|
|
37
|
+
let keyPressTimerId: ReturnType<typeof setTimeout> | null;
|
|
38
|
+
let log: Array<DOMHighResTimeStamp> = [];
|
|
39
|
+
let invalidatingEvent = false;
|
|
40
|
+
|
|
41
|
+
const measureEventEnd = function logKeyPress() {
|
|
42
|
+
if (keyPressTimerId != null) {
|
|
43
|
+
if (invalidatingEvent) {
|
|
44
|
+
invalidatingEvent = false;
|
|
45
|
+
} else {
|
|
46
|
+
log.push(performance.now() - start);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
clearTimeout(keyPressTimerId);
|
|
50
|
+
keyPressTimerId = null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const measureEventStart = function measureEvent() {
|
|
55
|
+
if (timerId != null) {
|
|
56
|
+
clearTimeout(timerId);
|
|
57
|
+
timerId = null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// We use a setTimeout(0) instead of requestAnimationFrame, due to
|
|
61
|
+
// inconsistencies between the sequencing of rAF in different browsers.
|
|
62
|
+
keyPressTimerId = setTimeout(measureEventEnd, 0);
|
|
63
|
+
// Schedule a timer to report the results.
|
|
64
|
+
timerId = setTimeout(() => {
|
|
65
|
+
const total = log.reduce((a, b) => a + b, 0);
|
|
66
|
+
const reportedText =
|
|
67
|
+
'Typing Perf: ' + Math.round((total / log.length) * 100) / 100 + 'ms';
|
|
68
|
+
report(reportedText);
|
|
69
|
+
log = [];
|
|
70
|
+
}, 2000);
|
|
71
|
+
// Make the time after we do the previous logic, so we don't measure the overhead
|
|
72
|
+
// for it all.
|
|
73
|
+
start = performance.now();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const beforeInputHandler = function beforeInputHandler(event: InputEvent) {
|
|
77
|
+
if (!validInputTypes.has(event.inputType) || invalidatingEvent) {
|
|
78
|
+
invalidatingEvent = false;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
measureEventStart();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const keyDownHandler = function keyDownHandler(event: KeyboardEvent) {
|
|
86
|
+
const key = event.key;
|
|
87
|
+
|
|
88
|
+
if (key === 'Backspace' || key === 'Enter') {
|
|
89
|
+
measureEventStart();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const pasteHandler = function pasteHandler() {
|
|
94
|
+
invalidatingEvent = true;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const cutHandler = function cutHandler() {
|
|
98
|
+
invalidatingEvent = true;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
window.addEventListener('keydown', keyDownHandler, true);
|
|
102
|
+
window.addEventListener('selectionchange', measureEventEnd, true);
|
|
103
|
+
window.addEventListener('beforeinput', beforeInputHandler, true);
|
|
104
|
+
window.addEventListener('paste', pasteHandler, true);
|
|
105
|
+
window.addEventListener('cut', cutHandler, true);
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
window.removeEventListener('keydown', keyDownHandler, true);
|
|
109
|
+
window.removeEventListener('selectionchange', measureEventEnd, true);
|
|
110
|
+
window.removeEventListener('beforeinput', beforeInputHandler, true);
|
|
111
|
+
window.removeEventListener('paste', pasteHandler, true);
|
|
112
|
+
window.removeEventListener('cut', cutHandler, true);
|
|
113
|
+
};
|
|
114
|
+
}, [report]);
|
|
115
|
+
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
10
|
+
import {$insertNodeToNearestRoot} from '@lexical/utils';
|
|
11
|
+
import {COMMAND_PRIORITY_EDITOR, createCommand, LexicalCommand} from 'lexical';
|
|
12
|
+
import {useEffect} from 'react';
|
|
13
|
+
|
|
14
|
+
import {$createYouTubeNode, YouTubeNode} from '../../nodes/YouTubeNode';
|
|
15
|
+
|
|
16
|
+
export const INSERT_YOUTUBE_COMMAND: LexicalCommand<string> = createCommand(
|
|
17
|
+
'INSERT_YOUTUBE_COMMAND',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export default function YouTubePlugin(): JSX.Element | null {
|
|
21
|
+
const [editor] = useLexicalComposerContext();
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!editor.hasNodes([YouTubeNode])) {
|
|
25
|
+
throw new Error('YouTubePlugin: YouTubeNode not registered on editor');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return editor.registerCommand<string>(
|
|
29
|
+
INSERT_YOUTUBE_COMMAND,
|
|
30
|
+
(payload) => {
|
|
31
|
+
const youTubeNode = $createYouTubeNode(payload);
|
|
32
|
+
$insertNodeToNearestRoot(youTubeNode);
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
COMMAND_PRIORITY_EDITOR,
|
|
37
|
+
);
|
|
38
|
+
}, [editor]);
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
export default function caretFromPoint(
|
|
10
|
+
x: number,
|
|
11
|
+
y: number,
|
|
12
|
+
): null | {
|
|
13
|
+
offset: number;
|
|
14
|
+
node: Node;
|
|
15
|
+
} {
|
|
16
|
+
if (typeof document.caretRangeFromPoint !== 'undefined') {
|
|
17
|
+
const range = document.caretRangeFromPoint(x, y);
|
|
18
|
+
if (range === null) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
node: range.startContainer,
|
|
23
|
+
offset: range.startOffset,
|
|
24
|
+
};
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
} else if (document.caretPositionFromPoint !== 'undefined') {
|
|
27
|
+
// @ts-ignore FF - no types
|
|
28
|
+
const range = document.caretPositionFromPoint(x, y);
|
|
29
|
+
if (range === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
node: range.offsetNode,
|
|
34
|
+
offset: range.offset,
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
// Gracefully handle IE
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { CAN_USE_DOM } from './canUseDOM';
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
interface Document {
|
|
13
|
+
documentMode?: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Window {
|
|
17
|
+
MSStream?: unknown;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const documentMode =
|
|
22
|
+
CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
23
|
+
|
|
24
|
+
export const IS_APPLE: boolean =
|
|
25
|
+
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
26
|
+
|
|
27
|
+
export const IS_FIREFOX: boolean =
|
|
28
|
+
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
29
|
+
|
|
30
|
+
export const CAN_USE_BEFORE_INPUT: boolean =
|
|
31
|
+
CAN_USE_DOM && 'InputEvent' in window && !documentMode
|
|
32
|
+
? 'getTargetRanges' in new window.InputEvent('input')
|
|
33
|
+
: false;
|
|
34
|
+
|
|
35
|
+
export const IS_SAFARI: boolean =
|
|
36
|
+
CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
37
|
+
|
|
38
|
+
export const IS_IOS: boolean =
|
|
39
|
+
CAN_USE_DOM &&
|
|
40
|
+
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
41
|
+
!window.MSStream;
|
|
42
|
+
|
|
43
|
+
export const IS_ANDROID: boolean =
|
|
44
|
+
CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
45
|
+
|
|
46
|
+
// Keep these in case we need to use them in the future.
|
|
47
|
+
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
48
|
+
export const IS_CHROME: boolean =
|
|
49
|
+
CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
50
|
+
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
51
|
+
|
|
52
|
+
export const IS_ANDROID_CHROME: boolean =
|
|
53
|
+
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
54
|
+
|
|
55
|
+
export const IS_APPLE_WEBKIT =
|
|
56
|
+
CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
// invariant(condition, message) will refine types based on "condition", and
|
|
10
|
+
// if "condition" is false will throw an error. This function is special-cased
|
|
11
|
+
// in flow itself, so we can't name it anything else.
|
|
12
|
+
export default function invariant(
|
|
13
|
+
cond?: boolean,
|
|
14
|
+
message?: string,
|
|
15
|
+
...args: string[]
|
|
16
|
+
): asserts cond {
|
|
17
|
+
if (cond) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
throw new Error(
|
|
22
|
+
'Internal Lexical error: invariant() is meant to be replaced at compile ' +
|
|
23
|
+
'time. There is no runtime version. Error: ' +
|
|
24
|
+
message,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export default function normalizeClassNames(
|
|
10
|
+
...classNames: Array<typeof undefined | boolean | null | string>
|
|
11
|
+
): Array<string> {
|
|
12
|
+
const rval = [];
|
|
13
|
+
for (const className of classNames) {
|
|
14
|
+
if (className && typeof className === 'string') {
|
|
15
|
+
for (const [s] of className.matchAll(/\S+/g)) {
|
|
16
|
+
rval.push(s);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return rval;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 * as React from 'react';
|
|
9
|
+
import * as ReactTestUtils from 'react-dom/test-utils';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React 19 moved act from react-dom/test-utils to react
|
|
13
|
+
* https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-react-dom-test-utils
|
|
14
|
+
*/
|
|
15
|
+
export const act =
|
|
16
|
+
'act' in React
|
|
17
|
+
? (React.act as typeof ReactTestUtils.act)
|
|
18
|
+
: ReactTestUtils.act;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 React from 'react';
|
|
10
|
+
|
|
11
|
+
// Webpack + React 17 fails to compile on the usage of `React.startTransition` or
|
|
12
|
+
// `React["startTransition"]` even if it's behind a feature detection of
|
|
13
|
+
// `"startTransition" in React`. Moving this to a constant avoids the issue :/
|
|
14
|
+
const START_TRANSITION = 'startTransition';
|
|
15
|
+
|
|
16
|
+
export function startTransition(callback: () => void) {
|
|
17
|
+
if (START_TRANSITION in React) {
|
|
18
|
+
React[START_TRANSITION](callback);
|
|
19
|
+
} else {
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
export default function simpleDiffWithCursor(
|
|
10
|
+
a: string,
|
|
11
|
+
b: string,
|
|
12
|
+
cursor: number,
|
|
13
|
+
): {index: number; insert: string; remove: number} {
|
|
14
|
+
const aLength = a.length;
|
|
15
|
+
const bLength = b.length;
|
|
16
|
+
let left = 0; // number of same characters counting from left
|
|
17
|
+
let right = 0; // number of same characters counting from right
|
|
18
|
+
// Iterate left to the right until we find a changed character
|
|
19
|
+
// First iteration considers the current cursor position
|
|
20
|
+
while (
|
|
21
|
+
left < aLength &&
|
|
22
|
+
left < bLength &&
|
|
23
|
+
a[left] === b[left] &&
|
|
24
|
+
left < cursor
|
|
25
|
+
) {
|
|
26
|
+
left++;
|
|
27
|
+
}
|
|
28
|
+
// Iterate right to the left until we find a changed character
|
|
29
|
+
while (
|
|
30
|
+
right + left < aLength &&
|
|
31
|
+
right + left < bLength &&
|
|
32
|
+
a[aLength - right - 1] === b[bLength - right - 1]
|
|
33
|
+
) {
|
|
34
|
+
right++;
|
|
35
|
+
}
|
|
36
|
+
// Try to iterate left further to the right without caring about the current cursor position
|
|
37
|
+
while (
|
|
38
|
+
right + left < aLength &&
|
|
39
|
+
right + left < bLength &&
|
|
40
|
+
a[left] === b[left]
|
|
41
|
+
) {
|
|
42
|
+
left++;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
index: left,
|
|
46
|
+
insert: b.slice(left, bLength - right),
|
|
47
|
+
remove: aLength - left - right,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 {useEffect, useLayoutEffect} from 'react';
|
|
10
|
+
import {CAN_USE_DOM} from '../shared/canUseDOM';
|
|
11
|
+
|
|
12
|
+
// This workaround is no longer necessary in React 19,
|
|
13
|
+
// but we currently support React >=17.x
|
|
14
|
+
// https://github.com/facebook/react/pull/26395
|
|
15
|
+
const useLayoutEffectImpl: typeof useLayoutEffect = CAN_USE_DOM
|
|
16
|
+
? useLayoutEffect
|
|
17
|
+
: useEffect;
|
|
18
|
+
|
|
19
|
+
export default useLayoutEffectImpl;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export default function warnOnlyOnce(message: string) {
|
|
10
|
+
if (!__DEV__) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let run = false;
|
|
14
|
+
return () => {
|
|
15
|
+
if (!run) {
|
|
16
|
+
console.warn(message);
|
|
17
|
+
}
|
|
18
|
+
run = true;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
.input.rte {
|
|
2
|
+
|
|
3
|
+
.preview {
|
|
4
|
+
position: relative;
|
|
5
|
+
|
|
6
|
+
&:before {
|
|
7
|
+
|
|
8
|
+
content: 'Click here to edit';
|
|
9
|
+
|
|
10
|
+
display: flex;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
align-items: center;
|
|
13
|
+
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 0;
|
|
16
|
+
left: 0;
|
|
17
|
+
right: 0;
|
|
18
|
+
bottom: 0;
|
|
19
|
+
|
|
20
|
+
background: fade(#FFF, 50%);
|
|
21
|
+
pointer-events: none;
|
|
22
|
+
z-index: 1;
|
|
23
|
+
opacity: 0;
|
|
24
|
+
transition: all 0.3s linear;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&:hover:before {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
2
32
|
.other h2 {
|
|
3
33
|
font-size: 18px;
|
|
4
34
|
color: #444;
|
|
@@ -236,26 +266,6 @@
|
|
|
236
266
|
padding-left: 16px;
|
|
237
267
|
}
|
|
238
268
|
|
|
239
|
-
.editor-list-ol {
|
|
240
|
-
padding: 0;
|
|
241
|
-
margin: 0;
|
|
242
|
-
margin-left: 16px;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
.editor-list-ul {
|
|
246
|
-
padding: 0;
|
|
247
|
-
margin: 0;
|
|
248
|
-
margin-left: 16px;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
.editor-listitem {
|
|
252
|
-
margin: 8px 32px 8px 32px;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
.editor-nested-listitem {
|
|
256
|
-
list-style-type: none;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
269
|
pre::-webkit-scrollbar {
|
|
260
270
|
background: transparent;
|
|
261
271
|
width: 10px;
|
|
@@ -385,44 +395,4 @@
|
|
|
385
395
|
line-height: 16px;
|
|
386
396
|
background-size: contain;
|
|
387
397
|
}
|
|
388
|
-
|
|
389
|
-
i.undo {
|
|
390
|
-
background-image: url(icons/arrow-counterclockwise.svg);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
i.redo {
|
|
394
|
-
background-image: url(icons/arrow-clockwise.svg);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
i.bold {
|
|
398
|
-
background-image: url(icons/type-bold.svg);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
i.italic {
|
|
402
|
-
background-image: url(icons/type-italic.svg);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
i.underline {
|
|
406
|
-
background-image: url(icons/type-underline.svg);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
i.strikethrough {
|
|
410
|
-
background-image: url(icons/type-strikethrough.svg);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
i.left-align {
|
|
414
|
-
background-image: url(icons/text-left.svg);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
i.center-align {
|
|
418
|
-
background-image: url(icons/text-center.svg);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
i.right-align {
|
|
422
|
-
background-image: url(icons/text-right.svg);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
i.justify-align {
|
|
426
|
-
background-image: url(icons/justify.svg);
|
|
427
|
-
}
|
|
428
398
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
.CommentEditorTheme__paragraph {
|
|
11
|
+
margin: 0;
|
|
12
|
+
position: 'relative';
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 {EditorThemeClasses} from 'lexical';
|
|
10
|
+
|
|
11
|
+
import './CommentEditorTheme.css';
|
|
12
|
+
|
|
13
|
+
import baseTheme from './PlaygroundEditorTheme';
|
|
14
|
+
|
|
15
|
+
const theme: EditorThemeClasses = {
|
|
16
|
+
...baseTheme,
|
|
17
|
+
paragraph: 'CommentEditorTheme__paragraph',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default theme;
|