@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,128 @@
|
|
|
1
|
+
.floating-text-format-popup {
|
|
2
|
+
vertical-align: middle;
|
|
3
|
+
background-color: #fff;
|
|
4
|
+
transition: opacity 0.5s;
|
|
5
|
+
height: 43px;
|
|
6
|
+
will-change: transform;
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
@apply absolute top-0 left-0 z-10 flex rounded-md bg-white p-1 opacity-0 shadow-md;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.floating-text-format-popup button.popup-item {
|
|
12
|
+
border: 0;
|
|
13
|
+
display: flex;
|
|
14
|
+
background: none;
|
|
15
|
+
border-radius: 10px;
|
|
16
|
+
padding: 8px;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
vertical-align: middle;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.floating-text-format-popup button.popup-item:disabled {
|
|
22
|
+
cursor: not-allowed;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.floating-text-format-popup button.popup-item.spaced {
|
|
26
|
+
margin-right: 2px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.floating-text-format-popup button.popup-item i.format {
|
|
30
|
+
background-size: contain;
|
|
31
|
+
display: inline-block;
|
|
32
|
+
height: 18px;
|
|
33
|
+
width: 18px;
|
|
34
|
+
margin-top: 2px;
|
|
35
|
+
vertical-align: -0.25em;
|
|
36
|
+
display: flex;
|
|
37
|
+
opacity: 0.6;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.floating-text-format-popup button.popup-item:disabled i.format {
|
|
41
|
+
opacity: 0.2;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.floating-text-format-popup button.popup-item.active {
|
|
45
|
+
background-color: rgba(223, 232, 250, 0.3);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.floating-text-format-popup button.popup-item.active i {
|
|
49
|
+
opacity: 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.floating-text-format-popup .popup-item:hover:not([disabled]) {
|
|
53
|
+
background-color: #eee;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.floating-text-format-popup select.popup-item {
|
|
57
|
+
border: 0;
|
|
58
|
+
display: flex;
|
|
59
|
+
background: none;
|
|
60
|
+
border-radius: 10px;
|
|
61
|
+
padding: 8px;
|
|
62
|
+
vertical-align: middle;
|
|
63
|
+
-webkit-appearance: none;
|
|
64
|
+
-moz-appearance: none;
|
|
65
|
+
width: 70px;
|
|
66
|
+
font-size: 14px;
|
|
67
|
+
color: #777;
|
|
68
|
+
text-overflow: ellipsis;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.floating-text-format-popup select.code-language {
|
|
72
|
+
text-transform: capitalize;
|
|
73
|
+
width: 130px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.floating-text-format-popup .popup-item .text {
|
|
77
|
+
display: flex;
|
|
78
|
+
line-height: 20px;
|
|
79
|
+
width: 200px;
|
|
80
|
+
vertical-align: middle;
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
color: #777;
|
|
83
|
+
text-overflow: ellipsis;
|
|
84
|
+
width: 70px;
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
height: 20px;
|
|
87
|
+
text-align: left;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.floating-text-format-popup .popup-item .icon {
|
|
91
|
+
display: flex;
|
|
92
|
+
width: 20px;
|
|
93
|
+
height: 20px;
|
|
94
|
+
user-select: none;
|
|
95
|
+
margin-right: 8px;
|
|
96
|
+
line-height: 16px;
|
|
97
|
+
background-size: contain;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.floating-text-format-popup i.chevron-down {
|
|
101
|
+
margin-top: 3px;
|
|
102
|
+
width: 16px;
|
|
103
|
+
height: 16px;
|
|
104
|
+
display: flex;
|
|
105
|
+
user-select: none;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.floating-text-format-popup i.chevron-down.inside {
|
|
109
|
+
width: 16px;
|
|
110
|
+
height: 16px;
|
|
111
|
+
display: flex;
|
|
112
|
+
margin-left: -25px;
|
|
113
|
+
margin-top: 11px;
|
|
114
|
+
margin-right: 10px;
|
|
115
|
+
pointer-events: none;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.floating-text-format-popup .divider {
|
|
119
|
+
width: 1px;
|
|
120
|
+
background-color: #eee;
|
|
121
|
+
margin: 0 4px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@media (max-width: 1024px) {
|
|
125
|
+
.floating-text-format-popup button.insert-comment {
|
|
126
|
+
display: none;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
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 './index.css';
|
|
10
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
import {
|
|
13
|
+
$getSelection,
|
|
14
|
+
$isRangeSelection,
|
|
15
|
+
$isTextNode,
|
|
16
|
+
COMMAND_PRIORITY_LOW,
|
|
17
|
+
FORMAT_TEXT_COMMAND,
|
|
18
|
+
LexicalEditor,
|
|
19
|
+
SELECTION_CHANGE_COMMAND,
|
|
20
|
+
} from 'lexical';
|
|
21
|
+
import { createPortal } from 'react-dom';
|
|
22
|
+
import { $isCodeHighlightNode } from '@lexical/code';
|
|
23
|
+
import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
|
|
24
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
25
|
+
import { mergeRegister } from '@lexical/utils';
|
|
26
|
+
|
|
27
|
+
import { IconButton } from '../../../icon-button';
|
|
28
|
+
import { getDOMRangeRect } from '../../utils/getDOMRangeRect';
|
|
29
|
+
import { getSelectedNode } from '../../utils/getSelectedNode';
|
|
30
|
+
import { setFloatingElemPosition } from '../../utils/setFloatingElemPosition';
|
|
31
|
+
|
|
32
|
+
function TextFormatFloatingToolbar({
|
|
33
|
+
editor,
|
|
34
|
+
anchorElem,
|
|
35
|
+
isLink,
|
|
36
|
+
isBold,
|
|
37
|
+
isItalic,
|
|
38
|
+
isUnderline,
|
|
39
|
+
isCode,
|
|
40
|
+
isStrikethrough,
|
|
41
|
+
isSubscript,
|
|
42
|
+
isSuperscript,
|
|
43
|
+
}: {
|
|
44
|
+
editor: LexicalEditor;
|
|
45
|
+
anchorElem: HTMLElement;
|
|
46
|
+
isBold: boolean;
|
|
47
|
+
isCode: boolean;
|
|
48
|
+
isItalic: boolean;
|
|
49
|
+
isLink: boolean;
|
|
50
|
+
isStrikethrough: boolean;
|
|
51
|
+
isSubscript: boolean;
|
|
52
|
+
isSuperscript: boolean;
|
|
53
|
+
isUnderline: boolean;
|
|
54
|
+
}): JSX.Element {
|
|
55
|
+
const popupCharStylesEditorRef = useRef<HTMLDivElement | null>(null);
|
|
56
|
+
|
|
57
|
+
const insertLink = useCallback(() => {
|
|
58
|
+
if (!isLink) {
|
|
59
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, 'https://');
|
|
60
|
+
} else {
|
|
61
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
62
|
+
}
|
|
63
|
+
}, [editor, isLink]);
|
|
64
|
+
|
|
65
|
+
const updateTextFormatFloatingToolbar = useCallback(() => {
|
|
66
|
+
const selection = $getSelection();
|
|
67
|
+
|
|
68
|
+
const popupCharStylesEditorElem = popupCharStylesEditorRef.current;
|
|
69
|
+
const nativeSelection = window.getSelection();
|
|
70
|
+
|
|
71
|
+
if (popupCharStylesEditorElem === null) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const rootElement = editor.getRootElement();
|
|
76
|
+
if (
|
|
77
|
+
selection !== null &&
|
|
78
|
+
nativeSelection !== null &&
|
|
79
|
+
!nativeSelection.isCollapsed &&
|
|
80
|
+
rootElement !== null &&
|
|
81
|
+
rootElement.contains(nativeSelection.anchorNode)
|
|
82
|
+
) {
|
|
83
|
+
const rangeRect = getDOMRangeRect(nativeSelection, rootElement);
|
|
84
|
+
|
|
85
|
+
setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);
|
|
86
|
+
}
|
|
87
|
+
}, [editor, anchorElem]);
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const scrollerElem = anchorElem.parentElement;
|
|
91
|
+
|
|
92
|
+
const update = () => {
|
|
93
|
+
editor.getEditorState().read(() => {
|
|
94
|
+
updateTextFormatFloatingToolbar();
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
window.addEventListener('resize', update);
|
|
99
|
+
if (scrollerElem) {
|
|
100
|
+
scrollerElem.addEventListener('scroll', update);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return () => {
|
|
104
|
+
window.removeEventListener('resize', update);
|
|
105
|
+
if (scrollerElem) {
|
|
106
|
+
scrollerElem.removeEventListener('scroll', update);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}, [editor, updateTextFormatFloatingToolbar, anchorElem]);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
editor.getEditorState().read(() => {
|
|
113
|
+
updateTextFormatFloatingToolbar();
|
|
114
|
+
});
|
|
115
|
+
return mergeRegister(
|
|
116
|
+
editor.registerUpdateListener(({ editorState }) => {
|
|
117
|
+
editorState.read(() => {
|
|
118
|
+
updateTextFormatFloatingToolbar();
|
|
119
|
+
});
|
|
120
|
+
}),
|
|
121
|
+
|
|
122
|
+
editor.registerCommand(
|
|
123
|
+
SELECTION_CHANGE_COMMAND,
|
|
124
|
+
() => {
|
|
125
|
+
updateTextFormatFloatingToolbar();
|
|
126
|
+
return false;
|
|
127
|
+
},
|
|
128
|
+
COMMAND_PRIORITY_LOW,
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
}, [editor, updateTextFormatFloatingToolbar]);
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div ref={popupCharStylesEditorRef} className="floating-text-format-popup gap-0.5">
|
|
135
|
+
{editor.isEditable() && (
|
|
136
|
+
<>
|
|
137
|
+
<IconButton
|
|
138
|
+
onClick={() => {
|
|
139
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold');
|
|
140
|
+
}}
|
|
141
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
142
|
+
aria-label="Format text as bold"
|
|
143
|
+
>
|
|
144
|
+
<i
|
|
145
|
+
className={`format bold w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
146
|
+
isBold ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
147
|
+
}`}
|
|
148
|
+
/>
|
|
149
|
+
</IconButton>
|
|
150
|
+
<IconButton
|
|
151
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
152
|
+
onClick={() => {
|
|
153
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic');
|
|
154
|
+
}}
|
|
155
|
+
aria-label="Format text as italics"
|
|
156
|
+
>
|
|
157
|
+
<i
|
|
158
|
+
className={`format italic w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
159
|
+
isItalic ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
160
|
+
}`}
|
|
161
|
+
/>
|
|
162
|
+
</IconButton>
|
|
163
|
+
<IconButton
|
|
164
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
165
|
+
onClick={() => {
|
|
166
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline');
|
|
167
|
+
}}
|
|
168
|
+
aria-label="Format text to underlined"
|
|
169
|
+
>
|
|
170
|
+
<i
|
|
171
|
+
className={`format underline w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
172
|
+
isUnderline ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
173
|
+
}`}
|
|
174
|
+
/>
|
|
175
|
+
</IconButton>
|
|
176
|
+
<IconButton
|
|
177
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
178
|
+
onClick={() => {
|
|
179
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough');
|
|
180
|
+
}}
|
|
181
|
+
aria-label="Format text with a strikethrough"
|
|
182
|
+
>
|
|
183
|
+
<i
|
|
184
|
+
className={`format strikethrough w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
185
|
+
isStrikethrough ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
186
|
+
}`}
|
|
187
|
+
/>
|
|
188
|
+
</IconButton>
|
|
189
|
+
<IconButton
|
|
190
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
191
|
+
onClick={() => {
|
|
192
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript');
|
|
193
|
+
}}
|
|
194
|
+
title="Subscript"
|
|
195
|
+
aria-label="Format Subscript"
|
|
196
|
+
>
|
|
197
|
+
<i
|
|
198
|
+
className={`format subscript w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
199
|
+
isSubscript ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
200
|
+
}`}
|
|
201
|
+
/>
|
|
202
|
+
</IconButton>
|
|
203
|
+
<IconButton
|
|
204
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
205
|
+
onClick={() => {
|
|
206
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript');
|
|
207
|
+
}}
|
|
208
|
+
title="Superscript"
|
|
209
|
+
aria-label="Format Superscript"
|
|
210
|
+
>
|
|
211
|
+
<i
|
|
212
|
+
className={`format superscript w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
213
|
+
isSuperscript ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
214
|
+
}`}
|
|
215
|
+
/>
|
|
216
|
+
</IconButton>
|
|
217
|
+
<IconButton
|
|
218
|
+
style={{ padding: 0, overflow: 'hidden' }}
|
|
219
|
+
onClick={() => {
|
|
220
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code');
|
|
221
|
+
}}
|
|
222
|
+
aria-label="Insert code block"
|
|
223
|
+
>
|
|
224
|
+
<i
|
|
225
|
+
className={`format code w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
226
|
+
isCode ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
227
|
+
}`}
|
|
228
|
+
/>
|
|
229
|
+
</IconButton>
|
|
230
|
+
<IconButton style={{ padding: 0, overflow: 'hidden' }} onClick={insertLink} aria-label="Insert link">
|
|
231
|
+
<i
|
|
232
|
+
className={`format link w-full h-full bg-[length:18px_18px] bg-no-repeat bg-center ${
|
|
233
|
+
isLink ? 'bg-purple-50-900 opacity-100' : 'opacity-60'
|
|
234
|
+
}`}
|
|
235
|
+
/>
|
|
236
|
+
</IconButton>
|
|
237
|
+
</>
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLElement): JSX.Element | null {
|
|
244
|
+
const [isText, setIsText] = useState(false);
|
|
245
|
+
const [isLink, setIsLink] = useState(false);
|
|
246
|
+
const [isBold, setIsBold] = useState(false);
|
|
247
|
+
const [isItalic, setIsItalic] = useState(false);
|
|
248
|
+
const [isUnderline, setIsUnderline] = useState(false);
|
|
249
|
+
const [isStrikethrough, setIsStrikethrough] = useState(false);
|
|
250
|
+
const [isSubscript, setIsSubscript] = useState(false);
|
|
251
|
+
const [isSuperscript, setIsSuperscript] = useState(false);
|
|
252
|
+
const [isCode, setIsCode] = useState(false);
|
|
253
|
+
|
|
254
|
+
const updatePopup = useCallback(() => {
|
|
255
|
+
editor.getEditorState().read(() => {
|
|
256
|
+
// Should not to pop up the floating toolbar when using IME input
|
|
257
|
+
if (editor.isComposing()) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const selection = $getSelection();
|
|
261
|
+
const nativeSelection = window.getSelection();
|
|
262
|
+
const rootElement = editor.getRootElement();
|
|
263
|
+
|
|
264
|
+
if (
|
|
265
|
+
nativeSelection !== null &&
|
|
266
|
+
(!$isRangeSelection(selection) || rootElement === null || !rootElement.contains(nativeSelection.anchorNode))
|
|
267
|
+
) {
|
|
268
|
+
setIsText(false);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (!$isRangeSelection(selection)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const node = getSelectedNode(selection);
|
|
277
|
+
|
|
278
|
+
// Update text format
|
|
279
|
+
setIsBold(selection.hasFormat('bold'));
|
|
280
|
+
setIsItalic(selection.hasFormat('italic'));
|
|
281
|
+
setIsUnderline(selection.hasFormat('underline'));
|
|
282
|
+
setIsStrikethrough(selection.hasFormat('strikethrough'));
|
|
283
|
+
setIsSubscript(selection.hasFormat('subscript'));
|
|
284
|
+
setIsSuperscript(selection.hasFormat('superscript'));
|
|
285
|
+
setIsCode(selection.hasFormat('code'));
|
|
286
|
+
|
|
287
|
+
// Update links
|
|
288
|
+
const parent = node.getParent();
|
|
289
|
+
if ($isLinkNode(parent) || $isLinkNode(node)) {
|
|
290
|
+
setIsLink(true);
|
|
291
|
+
} else {
|
|
292
|
+
setIsLink(false);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (!$isCodeHighlightNode(selection.anchor.getNode()) && selection.getTextContent() !== '') {
|
|
296
|
+
setIsText($isTextNode(node));
|
|
297
|
+
} else {
|
|
298
|
+
setIsText(false);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}, [editor]);
|
|
302
|
+
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
document.addEventListener('selectionchange', updatePopup);
|
|
305
|
+
return () => {
|
|
306
|
+
document.removeEventListener('selectionchange', updatePopup);
|
|
307
|
+
};
|
|
308
|
+
}, [updatePopup]);
|
|
309
|
+
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
return mergeRegister(
|
|
312
|
+
editor.registerUpdateListener(() => {
|
|
313
|
+
updatePopup();
|
|
314
|
+
}),
|
|
315
|
+
editor.registerRootListener(() => {
|
|
316
|
+
if (editor.getRootElement() === null) {
|
|
317
|
+
setIsText(false);
|
|
318
|
+
}
|
|
319
|
+
}),
|
|
320
|
+
);
|
|
321
|
+
}, [editor, updatePopup]);
|
|
322
|
+
|
|
323
|
+
if (!isText || isLink) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return createPortal(
|
|
328
|
+
<TextFormatFloatingToolbar
|
|
329
|
+
editor={editor}
|
|
330
|
+
anchorElem={anchorElem}
|
|
331
|
+
isLink={isLink}
|
|
332
|
+
isBold={isBold}
|
|
333
|
+
isItalic={isItalic}
|
|
334
|
+
isStrikethrough={isStrikethrough}
|
|
335
|
+
isSubscript={isSubscript}
|
|
336
|
+
isSuperscript={isSuperscript}
|
|
337
|
+
isUnderline={isUnderline}
|
|
338
|
+
isCode={isCode}
|
|
339
|
+
/>,
|
|
340
|
+
anchorElem,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export default function FloatingTextFormatToolbarPlugin({
|
|
345
|
+
anchorElem = document.body,
|
|
346
|
+
}: {
|
|
347
|
+
anchorElem?: HTMLElement;
|
|
348
|
+
}): JSX.Element | null {
|
|
349
|
+
const [editor] = useLexicalComposerContext();
|
|
350
|
+
return useFloatingTextFormatToolbar(editor, anchorElem);
|
|
351
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { LinkPlugin as LexicalLinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
|
|
12
|
+
import { validateUrl } from '../../utils/url';
|
|
13
|
+
|
|
14
|
+
export default function LinkPlugin(): JSX.Element {
|
|
15
|
+
return <LexicalLinkPlugin validateUrl={validateUrl} />;
|
|
16
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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 {RangeSelection} from 'lexical';
|
|
10
|
+
|
|
11
|
+
import {$getListDepth, $isListItemNode, $isListNode} from '@lexical/list';
|
|
12
|
+
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
13
|
+
import {
|
|
14
|
+
$getSelection,
|
|
15
|
+
$isElementNode,
|
|
16
|
+
$isRangeSelection,
|
|
17
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
18
|
+
ElementNode,
|
|
19
|
+
INDENT_CONTENT_COMMAND,
|
|
20
|
+
} from 'lexical';
|
|
21
|
+
import {useEffect} from 'react';
|
|
22
|
+
|
|
23
|
+
type Props = Readonly<{
|
|
24
|
+
maxDepth: number | null | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
function getElementNodesInSelection(
|
|
28
|
+
selection: RangeSelection,
|
|
29
|
+
): Set<ElementNode> {
|
|
30
|
+
const nodesInSelection = selection.getNodes();
|
|
31
|
+
|
|
32
|
+
if (nodesInSelection.length === 0) {
|
|
33
|
+
return new Set([
|
|
34
|
+
selection.anchor.getNode().getParentOrThrow(),
|
|
35
|
+
selection.focus.getNode().getParentOrThrow(),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return new Set(
|
|
40
|
+
nodesInSelection.map((n) => ($isElementNode(n) ? n : n.getParentOrThrow())),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isIndentPermitted(maxDepth: number): boolean {
|
|
45
|
+
const selection = $getSelection();
|
|
46
|
+
|
|
47
|
+
if (!$isRangeSelection(selection)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const elementNodesInSelection: Set<ElementNode> =
|
|
52
|
+
getElementNodesInSelection(selection);
|
|
53
|
+
|
|
54
|
+
let totalDepth = 0;
|
|
55
|
+
|
|
56
|
+
for (const elementNode of elementNodesInSelection) {
|
|
57
|
+
if ($isListNode(elementNode)) {
|
|
58
|
+
totalDepth = Math.max($getListDepth(elementNode) + 1, totalDepth);
|
|
59
|
+
} else if ($isListItemNode(elementNode)) {
|
|
60
|
+
const parent = elementNode.getParent();
|
|
61
|
+
|
|
62
|
+
if (!$isListNode(parent)) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'ListMaxIndentLevelPlugin: A ListItemNode must have a ListNode for a parent.',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
totalDepth = Math.max($getListDepth(parent) + 1, totalDepth);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return totalDepth <= maxDepth;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default function ListMaxIndentLevelPlugin({maxDepth}: Props): null {
|
|
76
|
+
const [editor] = useLexicalComposerContext();
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
return editor.registerCommand(
|
|
80
|
+
INDENT_CONTENT_COMMAND,
|
|
81
|
+
() => !isIndentPermitted(maxDepth ?? 7),
|
|
82
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
83
|
+
);
|
|
84
|
+
}, [editor, maxDepth]);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 * as React from 'react';
|
|
10
|
+
import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin';
|
|
11
|
+
|
|
12
|
+
import { PLAYGROUND_TRANSFORMERS } from '../MarkdownTransformers';
|
|
13
|
+
|
|
14
|
+
export default function MarkdownPlugin(): JSX.Element {
|
|
15
|
+
return <MarkdownShortcutPlugin transformers={PLAYGROUND_TRANSFORMERS} />;
|
|
16
|
+
}
|