@crystallize/design-system 1.3.2 → 1.4.1
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/CHANGELOG.md +12 -0
- package/dist/TableComponent-I2YOOYOU.css +281 -0
- package/dist/TableComponent-QINOO453.mjs +1377 -0
- package/dist/arrow-clockwise-Z2G6UEGP.svg +1 -0
- package/dist/arrow-counterclockwise-2O5EYVJT.svg +1 -0
- package/dist/bg-color-HB2WDYGO.svg +1 -0
- package/dist/camera-CR7D2PNH.svg +1 -0
- package/dist/caret-right-fill-FFBNEXVX.svg +1 -0
- package/dist/chat-square-quote-CI6PUJHH.svg +1 -0
- package/dist/chevron-down-3FRWSIKS.svg +1 -0
- package/dist/chunk-VUXQZRSP.mjs +737 -0
- package/dist/clipboard-OSEFDF25.svg +1 -0
- package/dist/close-FH57ZMJF.svg +1 -0
- package/dist/code-SEVR6TIQ.svg +1 -0
- package/dist/copy-DMGDODUL.svg +1 -0
- package/dist/diagram-2-CEJUD2B4.svg +1 -0
- package/dist/download-JXUGIUCX.svg +1 -0
- package/dist/draggable-block-menu-KKHDNKJA.svg +1 -0
- package/dist/dropdown-more-BHZ5COKX.svg +1 -0
- package/dist/file-image-TIQPFJX4.svg +1 -0
- package/dist/filetype-gif-OG2BEYYK.svg +1 -0
- package/dist/font-color-J4GA3ZJO.svg +1 -0
- package/dist/font-family-ZU5N6TTE.svg +1 -0
- package/dist/gear-ICMT4NTP.svg +1 -0
- package/dist/horizontal-rule-N6RD2V7H.svg +1 -0
- package/dist/indent-MJ6JIMCK.svg +1 -0
- package/dist/index.css +2711 -315
- package/dist/index.d.ts +145 -40
- package/dist/index.js +10376 -1481
- package/dist/index.mjs +7609 -746
- package/dist/journal-code-XUT44HDV.svg +1 -0
- package/dist/justify-J7X5JEEX.svg +1 -0
- package/dist/link-W52N4JKZ.svg +1 -0
- package/dist/list-ol-2ZEUN4Z7.svg +1 -0
- package/dist/list-ul-DVKNUP47.svg +1 -0
- package/dist/lock-WCYOZOHW.svg +1 -0
- package/dist/lock-fill-JZSKOSHK.svg +1 -0
- package/dist/markdown-4BGQNLLT.svg +1 -0
- package/dist/mic-H5FNOMM7.svg +1 -0
- package/dist/outdent-2LUMUMIP.svg +1 -0
- package/dist/paint-bucket-VCISMZTH.svg +1 -0
- package/dist/palette-SWGFPRWZ.svg +1 -0
- package/dist/pencil-fill-STFSC26F.svg +1 -0
- package/dist/plug-HGGGEVS3.svg +1 -0
- package/dist/plug-fill-OTG3U4TN.svg +1 -0
- package/dist/plus-CQISIKEC.svg +1 -0
- package/dist/plus-slash-minus-N22JU4TI.svg +1 -0
- package/dist/prettier-WUJ7B5NV.svg +1 -0
- package/dist/prettier-error-DYJSLYDP.svg +1 -0
- package/dist/square-check-UTG6FU6D.svg +1 -0
- package/dist/success-YVXUMPEZ.svg +1 -0
- package/dist/table-BR6DI4ZQ.svg +1 -0
- package/dist/text-center-UQI6PAEF.svg +1 -0
- package/dist/text-left-KT2B6TR3.svg +1 -0
- package/dist/text-paragraph-MFTUIIQG.svg +1 -0
- package/dist/text-right-SKELPISG.svg +1 -0
- package/dist/trash-UOM6D7TD.svg +1 -0
- package/dist/type-bold-PY7COC3N.svg +1 -0
- package/dist/type-h1-6KJP7YOM.svg +1 -0
- package/dist/type-h2-VHI2USC3.svg +1 -0
- package/dist/type-h3-JIU77CHO.svg +1 -0
- package/dist/type-h4-P5EHKDAL.svg +1 -0
- package/dist/type-h5-CS2KYVRG.svg +1 -0
- package/dist/type-h6-J2O74LJZ.svg +1 -0
- package/dist/type-italic-3DSFOSG2.svg +1 -0
- package/dist/type-strikethrough-E2KKQFSX.svg +1 -0
- package/dist/type-subscript-BMPTRIBU.svg +1 -0
- package/dist/type-superscript-EDF6EPAA.svg +1 -0
- package/dist/type-underline-CBFA5VLF.svg +1 -0
- package/dist/upload-Q6KICGZW.svg +1 -0
- package/dist/user-EOI2NEFZ.svg +1 -0
- package/package.json +30 -6
- package/src/dialog/dialog.tsx +1 -0
- package/src/icon-button/icon-button.css +16 -14
- package/src/index.ts +4 -4
- package/src/input/input.css +1 -1
- package/src/input-with-label/input-with-label.css +1 -1
- package/src/rich-text-editor/appSettings.ts +28 -0
- package/src/rich-text-editor/context/SettingsContext.tsx +71 -0
- package/src/rich-text-editor/context/SharedAutocompleteContext.tsx +60 -0
- package/src/rich-text-editor/context/SharedHistoryContext.tsx +25 -0
- package/src/rich-text-editor/hooks/useReport.ts +64 -0
- package/src/rich-text-editor/images/cat-typing.gif +0 -0
- package/src/rich-text-editor/images/emoji/1F600.png +0 -0
- package/src/rich-text-editor/images/emoji/1F641.png +0 -0
- package/src/rich-text-editor/images/emoji/1F642.png +0 -0
- package/src/rich-text-editor/images/emoji/2764.png +0 -0
- package/src/rich-text-editor/images/emoji/LICENSE.md +5 -0
- package/src/rich-text-editor/images/icons/LICENSE.md +5 -0
- package/src/rich-text-editor/images/icons/arrow-clockwise.svg +1 -0
- package/src/rich-text-editor/images/icons/arrow-counterclockwise.svg +1 -0
- package/src/rich-text-editor/images/icons/bg-color.svg +1 -0
- package/src/rich-text-editor/images/icons/camera.svg +1 -0
- package/src/rich-text-editor/images/icons/card-checklist.svg +1 -0
- package/src/rich-text-editor/images/icons/caret-right-fill.svg +1 -0
- package/src/rich-text-editor/images/icons/chat-left-text.svg +1 -0
- package/src/rich-text-editor/images/icons/chat-right-dots.svg +1 -0
- package/src/rich-text-editor/images/icons/chat-right-text.svg +1 -0
- package/src/rich-text-editor/images/icons/chat-right.svg +1 -0
- package/src/rich-text-editor/images/icons/chat-square-quote.svg +1 -0
- package/src/rich-text-editor/images/icons/chevron-down.svg +1 -0
- package/src/rich-text-editor/images/icons/clipboard.svg +1 -0
- package/src/rich-text-editor/images/icons/close.svg +1 -0
- package/src/rich-text-editor/images/icons/code.svg +1 -0
- package/src/rich-text-editor/images/icons/comments.svg +1 -0
- package/src/rich-text-editor/images/icons/copy.svg +1 -0
- package/src/rich-text-editor/images/icons/diagram-2.svg +1 -0
- package/src/rich-text-editor/images/icons/download.svg +1 -0
- package/src/rich-text-editor/images/icons/draggable-block-menu.svg +1 -0
- package/src/rich-text-editor/images/icons/dropdown-more.svg +1 -0
- package/src/rich-text-editor/images/icons/figma.svg +1 -0
- package/src/rich-text-editor/images/icons/file-image.svg +1 -0
- package/src/rich-text-editor/images/icons/filetype-gif.svg +1 -0
- package/src/rich-text-editor/images/icons/font-color.svg +1 -0
- package/src/rich-text-editor/images/icons/font-family.svg +1 -0
- package/src/rich-text-editor/images/icons/gear.svg +1 -0
- package/src/rich-text-editor/images/icons/horizontal-rule.svg +1 -0
- package/src/rich-text-editor/images/icons/indent.svg +1 -0
- package/src/rich-text-editor/images/icons/journal-code.svg +1 -0
- package/src/rich-text-editor/images/icons/journal-text.svg +1 -0
- package/src/rich-text-editor/images/icons/justify.svg +1 -0
- package/src/rich-text-editor/images/icons/link.svg +1 -0
- package/src/rich-text-editor/images/icons/list-ol.svg +1 -0
- package/src/rich-text-editor/images/icons/list-ul.svg +1 -0
- package/src/rich-text-editor/images/icons/lock-fill.svg +1 -0
- package/src/rich-text-editor/images/icons/lock.svg +1 -0
- package/src/rich-text-editor/images/icons/markdown.svg +1 -0
- package/src/rich-text-editor/images/icons/mic.svg +1 -0
- package/src/rich-text-editor/images/icons/outdent.svg +1 -0
- package/src/rich-text-editor/images/icons/paint-bucket.svg +1 -0
- package/src/rich-text-editor/images/icons/palette.svg +1 -0
- package/src/rich-text-editor/images/icons/pencil-fill.svg +1 -0
- package/src/rich-text-editor/images/icons/plug-fill.svg +1 -0
- package/src/rich-text-editor/images/icons/plug.svg +1 -0
- package/src/rich-text-editor/images/icons/plus-slash-minus.svg +1 -0
- package/src/rich-text-editor/images/icons/plus.svg +1 -0
- package/src/rich-text-editor/images/icons/prettier-error.svg +1 -0
- package/src/rich-text-editor/images/icons/prettier.svg +1 -0
- package/src/rich-text-editor/images/icons/send.svg +1 -0
- package/src/rich-text-editor/images/icons/square-check.svg +1 -0
- package/src/rich-text-editor/images/icons/sticky.svg +1 -0
- package/src/rich-text-editor/images/icons/success.svg +1 -0
- package/src/rich-text-editor/images/icons/table.svg +1 -0
- package/src/rich-text-editor/images/icons/text-center.svg +1 -0
- package/src/rich-text-editor/images/icons/text-left.svg +1 -0
- package/src/rich-text-editor/images/icons/text-paragraph.svg +1 -0
- package/src/rich-text-editor/images/icons/text-right.svg +1 -0
- package/src/rich-text-editor/images/icons/trash.svg +1 -0
- package/src/rich-text-editor/images/icons/trash3.svg +1 -0
- package/src/rich-text-editor/images/icons/tweet.svg +1 -0
- package/src/rich-text-editor/images/icons/type-bold.svg +1 -0
- package/src/rich-text-editor/images/icons/type-h1.svg +1 -0
- package/src/rich-text-editor/images/icons/type-h2.svg +1 -0
- package/src/rich-text-editor/images/icons/type-h3.svg +1 -0
- package/src/rich-text-editor/images/icons/type-h4.svg +1 -0
- package/src/rich-text-editor/images/icons/type-h5.svg +1 -0
- package/src/rich-text-editor/images/icons/type-h6.svg +1 -0
- package/src/rich-text-editor/images/icons/type-italic.svg +1 -0
- package/src/rich-text-editor/images/icons/type-strikethrough.svg +1 -0
- package/src/rich-text-editor/images/icons/type-subscript.svg +1 -0
- package/src/rich-text-editor/images/icons/type-superscript.svg +1 -0
- package/src/rich-text-editor/images/icons/type-underline.svg +1 -0
- package/src/rich-text-editor/images/icons/upload.svg +1 -0
- package/src/rich-text-editor/images/icons/user.svg +1 -0
- package/src/rich-text-editor/images/icons/youtube.svg +1 -0
- package/src/rich-text-editor/images/image/LICENSE.md +5 -0
- package/src/rich-text-editor/images/landscape.jpg +0 -0
- package/src/rich-text-editor/images/logo.svg +1 -0
- package/src/rich-text-editor/images/yellow-flower-small.jpg +0 -0
- package/src/rich-text-editor/images/yellow-flower.jpg +0 -0
- package/src/rich-text-editor/index.ts +1 -0
- package/src/rich-text-editor/model/crystallize-rich-text-types/code.ts +39 -0
- package/src/rich-text-editor/model/crystallize-rich-text-types/headings.ts +12 -0
- package/src/rich-text-editor/model/crystallize-rich-text-types/index.ts +69 -0
- package/src/rich-text-editor/model/crystallize-rich-text-types/link.ts +9 -0
- package/src/rich-text-editor/model/crystallize-rich-text-types/table.ts +16 -0
- package/src/rich-text-editor/model/crystallize-to-lexical.ts +186 -0
- package/src/rich-text-editor/model/lexical-to-crystallize.ts +232 -0
- package/src/rich-text-editor/nodes/AutocompleteNode.tsx +96 -0
- package/src/rich-text-editor/nodes/BaseNodes.ts +45 -0
- package/src/rich-text-editor/nodes/KeywordNode.ts +73 -0
- package/src/rich-text-editor/nodes/TableCellNodes.ts +31 -0
- package/src/rich-text-editor/nodes/TableComponent.tsx +1547 -0
- package/src/rich-text-editor/nodes/TableNode.tsx +398 -0
- package/src/rich-text-editor/plugins/ActionsPlugin/index.tsx +83 -0
- package/src/rich-text-editor/plugins/AutoLinkPlugin/index.tsx +47 -0
- package/src/rich-text-editor/plugins/AutocompletePlugin/index.tsx +2536 -0
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +60 -0
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +14 -0
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +140 -0
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/index.css +46 -0
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/index.tsx +155 -0
- package/src/rich-text-editor/plugins/CodeHighlightPlugin/index.ts +21 -0
- package/src/rich-text-editor/plugins/ComponentPickerPlugin/index.tsx +320 -0
- package/src/rich-text-editor/plugins/DragDropPastePlugin/index.ts +40 -0
- package/src/rich-text-editor/plugins/DraggableBlockPlugin/index.css +36 -0
- package/src/rich-text-editor/plugins/DraggableBlockPlugin/index.tsx +368 -0
- package/src/rich-text-editor/plugins/FloatingLinkEditorPlugin/index.css +40 -0
- package/src/rich-text-editor/plugins/FloatingLinkEditorPlugin/index.tsx +305 -0
- package/src/rich-text-editor/plugins/FloatingTextFormatToolbarPlugin/index.css +128 -0
- package/src/rich-text-editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +351 -0
- package/src/rich-text-editor/plugins/LinkPlugin/index.tsx +16 -0
- package/src/rich-text-editor/plugins/ListMaxIndentLevelPlugin/index.ts +86 -0
- package/src/rich-text-editor/plugins/MarkdownShortcutPlugin/index.tsx +16 -0
- package/src/rich-text-editor/plugins/MarkdownTransformers/index.ts +195 -0
- package/src/rich-text-editor/plugins/MaxLengthPlugin/index.tsx +49 -0
- package/src/rich-text-editor/plugins/SpeechToTextPlugin/index.ts +113 -0
- package/src/rich-text-editor/plugins/TabFocusPlugin/index.tsx +65 -0
- package/src/rich-text-editor/plugins/TableActionMenuPlugin/index.tsx +481 -0
- package/src/rich-text-editor/plugins/TableCellResizer/index.css +12 -0
- package/src/rich-text-editor/plugins/TableCellResizer/index.tsx +386 -0
- package/src/rich-text-editor/plugins/TablePlugin.tsx +190 -0
- package/src/rich-text-editor/plugins/ToolbarPlugin/index.tsx +726 -0
- package/src/rich-text-editor/plugins/TreeViewPlugin/index.tsx +25 -0
- package/src/rich-text-editor/plugins/TypingPerfPlugin/index.ts +117 -0
- package/src/rich-text-editor/rich-text-editor.css +1396 -0
- package/src/rich-text-editor/rich-text-editor.stories.tsx +385 -0
- package/src/rich-text-editor/rich-text-editor.tsx +228 -0
- package/src/rich-text-editor/tests/rich-text-editor-basic-rendering.test.tsx +47 -0
- package/src/rich-text-editor/tests/rich-text-editor-code.test.tsx +39 -0
- package/src/rich-text-editor/tests/rich-text-editor-model-basics.test.tsx +56 -0
- package/src/rich-text-editor/tests/rich-text-editor-model-conversions.test.tsx +195 -0
- package/src/rich-text-editor/tests/rich-text-editor-onchange.test.tsx +37 -0
- package/src/rich-text-editor/tests/rich-text-editor-quote.test.tsx +36 -0
- package/src/rich-text-editor/tests/rich-text-editor-text-formats.test.tsx +135 -0
- package/src/rich-text-editor/tests/rich-text-editor-typing.test.tsx +73 -0
- package/src/rich-text-editor/tests/utils.ts +23 -0
- package/src/rich-text-editor/themes/PlaygroundEditorTheme.css +433 -0
- package/src/rich-text-editor/themes/PlaygroundEditorTheme.ts +113 -0
- package/src/rich-text-editor/types.ts +5 -0
- package/src/rich-text-editor/ui/ContentEditable.css +13 -0
- package/src/rich-text-editor/ui/ContentEditable.tsx +15 -0
- package/src/rich-text-editor/ui/LinkPreview.css +57 -0
- package/src/rich-text-editor/ui/LinkPreview.tsx +169 -0
- package/src/rich-text-editor/utils/environment.ts +1 -0
- package/src/rich-text-editor/utils/getDOMRangeRect.ts +42 -0
- package/src/rich-text-editor/utils/getSelectedNode.ts +27 -0
- package/src/rich-text-editor/utils/guard.ts +10 -0
- package/src/rich-text-editor/utils/isMobileWidth.ts +7 -0
- package/src/rich-text-editor/utils/joinClasses.ts +13 -0
- package/src/rich-text-editor/utils/point.ts +55 -0
- package/src/rich-text-editor/utils/rect.ts +158 -0
- package/src/rich-text-editor/utils/setFloatingElemPosition.ts +46 -0
- package/src/rich-text-editor/utils/swipe.ts +127 -0
- package/src/rich-text-editor/utils/url.ts +33 -0
- package/src/Tokens.stories.tsx +0 -18
|
@@ -0,0 +1,320 @@
|
|
|
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 { useCallback, useMemo, useState } from 'react';
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import { $createParagraphNode, $getSelection, $isRangeSelection, FORMAT_ELEMENT_COMMAND, TextNode } from 'lexical';
|
|
12
|
+
import * as ReactDOM from 'react-dom';
|
|
13
|
+
import { $createCodeNode } from '@lexical/code';
|
|
14
|
+
import { INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
|
|
15
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
16
|
+
import { INSERT_HORIZONTAL_RULE_COMMAND } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
17
|
+
import {
|
|
18
|
+
LexicalTypeaheadMenuPlugin,
|
|
19
|
+
TypeaheadOption,
|
|
20
|
+
useBasicTypeaheadTriggerMatch,
|
|
21
|
+
} from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
22
|
+
import { $createHeadingNode, $createQuoteNode } from '@lexical/rich-text';
|
|
23
|
+
import { $setBlocksType_experimental } from '@lexical/selection';
|
|
24
|
+
import { INSERT_TABLE_COMMAND } from '@lexical/table';
|
|
25
|
+
|
|
26
|
+
// import { InsertNewTableDialog } from '../TablePlugin';
|
|
27
|
+
|
|
28
|
+
class ComponentPickerOption extends TypeaheadOption {
|
|
29
|
+
// What shows up in the editor
|
|
30
|
+
title: string;
|
|
31
|
+
// Icon for display
|
|
32
|
+
icon?: JSX.Element;
|
|
33
|
+
// For extra searching.
|
|
34
|
+
keywords: Array<string>;
|
|
35
|
+
// TBD
|
|
36
|
+
keyboardShortcut?: string;
|
|
37
|
+
// What happens when you select this option?
|
|
38
|
+
onSelect: (queryString: string) => void;
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
title: string,
|
|
42
|
+
options: {
|
|
43
|
+
icon?: JSX.Element;
|
|
44
|
+
keywords?: Array<string>;
|
|
45
|
+
keyboardShortcut?: string;
|
|
46
|
+
onSelect: (queryString: string) => void;
|
|
47
|
+
},
|
|
48
|
+
) {
|
|
49
|
+
super(title);
|
|
50
|
+
this.title = title;
|
|
51
|
+
this.keywords = options.keywords || [];
|
|
52
|
+
this.icon = options.icon;
|
|
53
|
+
this.keyboardShortcut = options.keyboardShortcut;
|
|
54
|
+
this.onSelect = options.onSelect.bind(this);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ComponentPickerMenuItem({
|
|
59
|
+
index,
|
|
60
|
+
isSelected,
|
|
61
|
+
onClick,
|
|
62
|
+
onMouseEnter,
|
|
63
|
+
option,
|
|
64
|
+
}: {
|
|
65
|
+
index: number;
|
|
66
|
+
isSelected: boolean;
|
|
67
|
+
onClick: () => void;
|
|
68
|
+
onMouseEnter: () => void;
|
|
69
|
+
option: ComponentPickerOption;
|
|
70
|
+
}) {
|
|
71
|
+
let className = 'item';
|
|
72
|
+
if (isSelected) {
|
|
73
|
+
className += ' selected';
|
|
74
|
+
}
|
|
75
|
+
return (
|
|
76
|
+
<li
|
|
77
|
+
key={option.key}
|
|
78
|
+
tabIndex={-1}
|
|
79
|
+
className={className}
|
|
80
|
+
ref={option.setRefElement}
|
|
81
|
+
role="option"
|
|
82
|
+
aria-selected={isSelected}
|
|
83
|
+
id={'typeahead-item-' + index}
|
|
84
|
+
onMouseEnter={onMouseEnter}
|
|
85
|
+
onClick={onClick}
|
|
86
|
+
>
|
|
87
|
+
{option.icon}
|
|
88
|
+
<span className="text">{option.title}</span>
|
|
89
|
+
</li>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default function ComponentPickerMenuPlugin(): JSX.Element {
|
|
94
|
+
const [editor] = useLexicalComposerContext();
|
|
95
|
+
const [queryString, setQueryString] = useState<string | null>(null);
|
|
96
|
+
|
|
97
|
+
const checkForTriggerMatch = useBasicTypeaheadTriggerMatch('/', {
|
|
98
|
+
minLength: 0,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const getDynamicOptions = useCallback(() => {
|
|
102
|
+
const options: Array<ComponentPickerOption> = [];
|
|
103
|
+
|
|
104
|
+
if (queryString == null) {
|
|
105
|
+
return options;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const fullTableRegex = new RegExp(/^([1-9]|10)x([1-9]|10)$/);
|
|
109
|
+
const partialTableRegex = new RegExp(/^([1-9]|10)x?$/);
|
|
110
|
+
|
|
111
|
+
const fullTableMatch = fullTableRegex.exec(queryString);
|
|
112
|
+
const partialTableMatch = partialTableRegex.exec(queryString);
|
|
113
|
+
|
|
114
|
+
if (fullTableMatch) {
|
|
115
|
+
const [rows, columns] = fullTableMatch[0].split('x').map((n: string) => parseInt(n, 10));
|
|
116
|
+
|
|
117
|
+
options.push(
|
|
118
|
+
new ComponentPickerOption(`${rows}x${columns} Table`, {
|
|
119
|
+
icon: <i className="icon table" />,
|
|
120
|
+
keywords: ['table'],
|
|
121
|
+
onSelect: () =>
|
|
122
|
+
// @ts-ignore Correct types, but since they're dynamic TS doesn't like it.
|
|
123
|
+
editor.dispatchCommand(INSERT_TABLE_COMMAND, { columns, rows }),
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
} else if (partialTableMatch) {
|
|
127
|
+
const rows = parseInt(partialTableMatch[0], 10);
|
|
128
|
+
|
|
129
|
+
options.push(
|
|
130
|
+
...Array.from({ length: 5 }, (_, i) => i + 1).map(
|
|
131
|
+
columns =>
|
|
132
|
+
new ComponentPickerOption(`${rows}x${columns} Table`, {
|
|
133
|
+
icon: <i className="icon table" />,
|
|
134
|
+
keywords: ['table'],
|
|
135
|
+
onSelect: () =>
|
|
136
|
+
// @ts-ignore Correct types, but since they're dynamic TS doesn't like it.
|
|
137
|
+
editor.dispatchCommand(INSERT_TABLE_COMMAND, { columns, rows }),
|
|
138
|
+
}),
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return options;
|
|
144
|
+
}, [editor, queryString]);
|
|
145
|
+
|
|
146
|
+
const options = useMemo(() => {
|
|
147
|
+
const baseOptions = [
|
|
148
|
+
new ComponentPickerOption('Paragraph', {
|
|
149
|
+
icon: <i className="icon paragraph" />,
|
|
150
|
+
keywords: ['normal', 'paragraph', 'p', 'text'],
|
|
151
|
+
onSelect: () =>
|
|
152
|
+
editor.update(() => {
|
|
153
|
+
const selection = $getSelection();
|
|
154
|
+
if ($isRangeSelection(selection)) {
|
|
155
|
+
$setBlocksType_experimental(selection, () => $createParagraphNode());
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
}),
|
|
159
|
+
...Array.from({ length: 3 }, (_, i) => i + 1).map(
|
|
160
|
+
n =>
|
|
161
|
+
new ComponentPickerOption(`Heading ${n}`, {
|
|
162
|
+
icon: <i className={`icon h${n}`} />,
|
|
163
|
+
keywords: ['heading', 'header', `h${n}`],
|
|
164
|
+
onSelect: () =>
|
|
165
|
+
editor.update(() => {
|
|
166
|
+
const selection = $getSelection();
|
|
167
|
+
if ($isRangeSelection(selection)) {
|
|
168
|
+
$setBlocksType_experimental(selection, () =>
|
|
169
|
+
// @ts-ignore Correct types, but since they're dynamic TS doesn't like it.
|
|
170
|
+
$createHeadingNode(`h${n}`),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
}),
|
|
175
|
+
),
|
|
176
|
+
// new ComponentPickerOption('Table', {
|
|
177
|
+
// icon: <i className="icon table" />,
|
|
178
|
+
// keywords: ['table', 'grid', 'spreadsheet', 'rows', 'columns'],
|
|
179
|
+
// onSelect: () =>
|
|
180
|
+
// showModal('Insert Table', onClose => <InsertTableDialog activeEditor={editor} onClose={onClose} />),
|
|
181
|
+
// }),
|
|
182
|
+
// new ComponentPickerOption('Table (Experimental)', {
|
|
183
|
+
// icon: <i className="icon table" />,
|
|
184
|
+
// keywords: ['table', 'grid', 'spreadsheet', 'rows', 'columns'],
|
|
185
|
+
// onSelect: () =>
|
|
186
|
+
// showModal('Insert Table', onClose => <InsertNewTableDialog activeEditor={editor} onClose={onClose} />),
|
|
187
|
+
// }),
|
|
188
|
+
new ComponentPickerOption('Numbered List', {
|
|
189
|
+
icon: <i className="icon number" />,
|
|
190
|
+
keywords: ['numbered list', 'ordered list', 'ol'],
|
|
191
|
+
onSelect: () => editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined),
|
|
192
|
+
}),
|
|
193
|
+
new ComponentPickerOption('Bulleted List', {
|
|
194
|
+
icon: <i className="icon bullet" />,
|
|
195
|
+
keywords: ['bulleted list', 'unordered list', 'ul'],
|
|
196
|
+
onSelect: () => editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined),
|
|
197
|
+
}),
|
|
198
|
+
new ComponentPickerOption('Check List', {
|
|
199
|
+
icon: <i className="icon check" />,
|
|
200
|
+
keywords: ['check list', 'todo list'],
|
|
201
|
+
onSelect: () => editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined),
|
|
202
|
+
}),
|
|
203
|
+
new ComponentPickerOption('Quote', {
|
|
204
|
+
icon: <i className="icon quote" />,
|
|
205
|
+
keywords: ['block quote'],
|
|
206
|
+
onSelect: () =>
|
|
207
|
+
editor.update(() => {
|
|
208
|
+
const selection = $getSelection();
|
|
209
|
+
if ($isRangeSelection(selection)) {
|
|
210
|
+
$setBlocksType_experimental(selection, () => $createQuoteNode());
|
|
211
|
+
}
|
|
212
|
+
}),
|
|
213
|
+
}),
|
|
214
|
+
new ComponentPickerOption('Code', {
|
|
215
|
+
icon: <i className="icon code" />,
|
|
216
|
+
keywords: ['javascript', 'python', 'js', 'codeblock'],
|
|
217
|
+
onSelect: () =>
|
|
218
|
+
editor.update(() => {
|
|
219
|
+
const selection = $getSelection();
|
|
220
|
+
|
|
221
|
+
if ($isRangeSelection(selection)) {
|
|
222
|
+
if (selection.isCollapsed()) {
|
|
223
|
+
$setBlocksType_experimental(selection, () => $createCodeNode());
|
|
224
|
+
} else {
|
|
225
|
+
// Will this ever happen?
|
|
226
|
+
const textContent = selection.getTextContent();
|
|
227
|
+
const codeNode = $createCodeNode();
|
|
228
|
+
selection.insertNodes([codeNode]);
|
|
229
|
+
selection.insertRawText(textContent);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}),
|
|
233
|
+
}),
|
|
234
|
+
new ComponentPickerOption('Divider', {
|
|
235
|
+
icon: <i className="icon horizontal-rule" />,
|
|
236
|
+
keywords: ['horizontal rule', 'divider', 'hr'],
|
|
237
|
+
onSelect: () => editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined),
|
|
238
|
+
}),
|
|
239
|
+
|
|
240
|
+
...['left', 'center', 'right', 'justify'].map(
|
|
241
|
+
alignment =>
|
|
242
|
+
new ComponentPickerOption(`Align ${alignment}`, {
|
|
243
|
+
icon: <i className={`icon ${alignment}-align`} />,
|
|
244
|
+
keywords: ['align', 'justify', alignment],
|
|
245
|
+
onSelect: () =>
|
|
246
|
+
// @ts-ignore Correct types, but since they're dynamic TS doesn't like it.
|
|
247
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, alignment),
|
|
248
|
+
}),
|
|
249
|
+
),
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
const dynamicOptions = getDynamicOptions();
|
|
253
|
+
|
|
254
|
+
return queryString
|
|
255
|
+
? [
|
|
256
|
+
...dynamicOptions,
|
|
257
|
+
...baseOptions.filter(option => {
|
|
258
|
+
return new RegExp(queryString, 'gi').exec(option.title) || option.keywords != null
|
|
259
|
+
? option.keywords.some(keyword => new RegExp(queryString, 'gi').exec(keyword))
|
|
260
|
+
: false;
|
|
261
|
+
}),
|
|
262
|
+
]
|
|
263
|
+
: baseOptions;
|
|
264
|
+
}, [editor, getDynamicOptions, queryString]);
|
|
265
|
+
|
|
266
|
+
const onSelectOption = useCallback(
|
|
267
|
+
(
|
|
268
|
+
selectedOption: ComponentPickerOption,
|
|
269
|
+
nodeToRemove: TextNode | null,
|
|
270
|
+
closeMenu: () => void,
|
|
271
|
+
matchingString: string,
|
|
272
|
+
) => {
|
|
273
|
+
editor.update(() => {
|
|
274
|
+
if (nodeToRemove) {
|
|
275
|
+
nodeToRemove.remove();
|
|
276
|
+
}
|
|
277
|
+
selectedOption.onSelect(matchingString);
|
|
278
|
+
closeMenu();
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
[editor],
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
return (
|
|
285
|
+
<>
|
|
286
|
+
<LexicalTypeaheadMenuPlugin<ComponentPickerOption>
|
|
287
|
+
onQueryChange={setQueryString}
|
|
288
|
+
onSelectOption={onSelectOption}
|
|
289
|
+
triggerFn={checkForTriggerMatch}
|
|
290
|
+
options={options}
|
|
291
|
+
menuRenderFn={(anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) =>
|
|
292
|
+
anchorElementRef.current && options.length
|
|
293
|
+
? ReactDOM.createPortal(
|
|
294
|
+
<div className="typeahead-popover component-picker-menu">
|
|
295
|
+
<ul>
|
|
296
|
+
{options.map((option, i: number) => (
|
|
297
|
+
<ComponentPickerMenuItem
|
|
298
|
+
index={i}
|
|
299
|
+
isSelected={selectedIndex === i}
|
|
300
|
+
onClick={() => {
|
|
301
|
+
setHighlightedIndex(i);
|
|
302
|
+
selectOptionAndCleanUp(option);
|
|
303
|
+
}}
|
|
304
|
+
onMouseEnter={() => {
|
|
305
|
+
setHighlightedIndex(i);
|
|
306
|
+
}}
|
|
307
|
+
key={option.key}
|
|
308
|
+
option={option}
|
|
309
|
+
/>
|
|
310
|
+
))}
|
|
311
|
+
</ul>
|
|
312
|
+
</div>,
|
|
313
|
+
anchorElementRef.current,
|
|
314
|
+
)
|
|
315
|
+
: null
|
|
316
|
+
}
|
|
317
|
+
/>
|
|
318
|
+
</>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
@@ -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
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
10
|
+
import { DRAG_DROP_PASTE } from '@lexical/rich-text';
|
|
11
|
+
import { isMimeType, mediaFileReader } from '@lexical/utils';
|
|
12
|
+
import { COMMAND_PRIORITY_LOW } from 'lexical';
|
|
13
|
+
import { useEffect } from 'react';
|
|
14
|
+
|
|
15
|
+
const ACCEPTABLE_IMAGE_TYPES = ['image/', 'image/heic', 'image/heif', 'image/gif', 'image/webp'];
|
|
16
|
+
|
|
17
|
+
export default function DragDropPaste(): null {
|
|
18
|
+
const [editor] = useLexicalComposerContext();
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
return editor.registerCommand(
|
|
21
|
+
DRAG_DROP_PASTE,
|
|
22
|
+
files => {
|
|
23
|
+
(async () => {
|
|
24
|
+
const filesResult = await mediaFileReader(
|
|
25
|
+
files,
|
|
26
|
+
[ACCEPTABLE_IMAGE_TYPES].flatMap(x => x),
|
|
27
|
+
);
|
|
28
|
+
for (const { file, result } of filesResult) {
|
|
29
|
+
if (isMimeType(file, ACCEPTABLE_IMAGE_TYPES)) {
|
|
30
|
+
console.log({ file, name: file.name });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})();
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
COMMAND_PRIORITY_LOW,
|
|
37
|
+
);
|
|
38
|
+
}, [editor]);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.draggable-block-menu {
|
|
2
|
+
border-radius: 4px;
|
|
3
|
+
padding: 2px 1px;
|
|
4
|
+
cursor: grab;
|
|
5
|
+
opacity: 0;
|
|
6
|
+
position: absolute;
|
|
7
|
+
left: 0;
|
|
8
|
+
top: 0;
|
|
9
|
+
will-change: transform;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.draggable-block-menu .icon {
|
|
13
|
+
width: 16px;
|
|
14
|
+
height: 16px;
|
|
15
|
+
opacity: 0.3;
|
|
16
|
+
background-image: url(../../images/icons/draggable-block-menu.svg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.draggable-block-menu:active {
|
|
20
|
+
cursor: grabbing;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.draggable-block-menu:hover {
|
|
24
|
+
background-color: #efefef;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.draggable-block-target-line {
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
background: deepskyblue;
|
|
30
|
+
height: 4px;
|
|
31
|
+
position: absolute;
|
|
32
|
+
left: 0;
|
|
33
|
+
top: 0;
|
|
34
|
+
opacity: 0;
|
|
35
|
+
will-change: transform;
|
|
36
|
+
}
|