@blocklet/editor-lite 2.6.0
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/LICENSE +13 -0
- package/README.md +33 -0
- package/lib/blocklet-editor-viewer.d.ts +4 -0
- package/lib/blocklet-editor-viewer.js +12 -0
- package/lib/blocklet-editor.d.ts +2 -0
- package/lib/blocklet-editor.js +12 -0
- package/lib/components/Loading.d.ts +4 -0
- package/lib/components/Loading.js +13 -0
- package/lib/components/SelectionPopper.d.ts +14 -0
- package/lib/components/SelectionPopper.js +73 -0
- package/lib/components/animateText.d.ts +3 -0
- package/lib/components/animateText.js +29 -0
- package/lib/components/createPortal.d.ts +2 -0
- package/lib/components/createPortal.js +16 -0
- package/lib/config.d.ts +37 -0
- package/lib/config.js +12 -0
- package/lib/ext/AIPlugin/AIIcon.d.ts +5 -0
- package/lib/ext/AIPlugin/AIIcon.js +7 -0
- package/lib/ext/AIPlugin/Arrow.d.ts +1 -0
- package/lib/ext/AIPlugin/Arrow.js +5 -0
- package/lib/ext/AIPlugin/TextGeneration.d.ts +6 -0
- package/lib/ext/AIPlugin/TextGeneration.js +131 -0
- package/lib/ext/AIPlugin/Writing.d.ts +1 -0
- package/lib/ext/AIPlugin/Writing.js +7 -0
- package/lib/ext/AIPlugin/index.d.ts +9 -0
- package/lib/ext/AIPlugin/index.js +180 -0
- package/lib/ext/AIPlugin/utils.d.ts +6 -0
- package/lib/ext/AIPlugin/utils.js +44 -0
- package/lib/ext/AITranslationPlugin/index.d.ts +9 -0
- package/lib/ext/AITranslationPlugin/index.js +124 -0
- package/lib/ext/AITranslationPlugin/selection.d.ts +3 -0
- package/lib/ext/AITranslationPlugin/selection.js +45 -0
- package/lib/ext/AITranslationPlugin/translation.d.ts +3 -0
- package/lib/ext/AITranslationPlugin/translation.js +67 -0
- package/lib/ext/AITranslationPlugin/types.d.ts +49 -0
- package/lib/ext/AITranslationPlugin/types.js +1 -0
- package/lib/ext/AITranslationPlugin/utils.d.ts +46 -0
- package/lib/ext/AITranslationPlugin/utils.js +343 -0
- package/lib/ext/Aide/Aide.d.ts +4 -0
- package/lib/ext/Aide/Aide.js +30 -0
- package/lib/ext/Aide/Delayed.d.ts +7 -0
- package/lib/ext/Aide/Delayed.js +12 -0
- package/lib/ext/Aide/Input.d.ts +6 -0
- package/lib/ext/Aide/Input.js +49 -0
- package/lib/ext/Aide/Menu.d.ts +4 -0
- package/lib/ext/Aide/Menu.js +29 -0
- package/lib/ext/Aide/Output.d.ts +4 -0
- package/lib/ext/Aide/Output.js +14 -0
- package/lib/ext/Aide/Templates.d.ts +4 -0
- package/lib/ext/Aide/Templates.js +34 -0
- package/lib/ext/Aide/builtin-templates.d.ts +3 -0
- package/lib/ext/Aide/builtin-templates.js +48 -0
- package/lib/ext/Aide/context.d.ts +47 -0
- package/lib/ext/Aide/context.js +114 -0
- package/lib/ext/Aide/external-templates/Breadcrumb.d.ts +10 -0
- package/lib/ext/Aide/external-templates/Breadcrumb.js +11 -0
- package/lib/ext/Aide/external-templates/Output.d.ts +8 -0
- package/lib/ext/Aide/external-templates/Output.js +22 -0
- package/lib/ext/Aide/external-templates/Search.d.ts +6 -0
- package/lib/ext/Aide/external-templates/Search.js +14 -0
- package/lib/ext/Aide/external-templates/Tags.d.ts +4 -0
- package/lib/ext/Aide/external-templates/Tags.js +44 -0
- package/lib/ext/Aide/external-templates/Template.d.ts +7 -0
- package/lib/ext/Aide/external-templates/Template.js +110 -0
- package/lib/ext/Aide/external-templates/Templates.d.ts +6 -0
- package/lib/ext/Aide/external-templates/Templates.js +61 -0
- package/lib/ext/Aide/external-templates/index.d.ts +4 -0
- package/lib/ext/Aide/external-templates/index.js +83 -0
- package/lib/ext/Aide/external-templates/parameter-field.d.ts +6 -0
- package/lib/ext/Aide/external-templates/parameter-field.js +92 -0
- package/lib/ext/Aide/hooks.d.ts +7 -0
- package/lib/ext/Aide/hooks.js +14 -0
- package/lib/ext/Aide/index.d.ts +2 -0
- package/lib/ext/Aide/index.js +2 -0
- package/lib/ext/Aide/types.d.ts +84 -0
- package/lib/ext/Aide/types.js +25 -0
- package/lib/ext/Aide/withAiAvailable.d.ts +5 -0
- package/lib/ext/Aide/withAiAvailable.js +11 -0
- package/lib/ext/Alert/AlertComponent.d.ts +10 -0
- package/lib/ext/Alert/AlertComponent.js +38 -0
- package/lib/ext/Alert/AlertNode.d.ts +28 -0
- package/lib/ext/Alert/AlertNode.js +105 -0
- package/lib/ext/Alert/AlertPlugin.d.ts +11 -0
- package/lib/ext/Alert/AlertPlugin.js +41 -0
- package/lib/ext/BilibiliPlugin/BilibiliNode.d.ts +31 -0
- package/lib/ext/BilibiliPlugin/BilibiliNode.js +95 -0
- package/lib/ext/BilibiliPlugin/BilibiliVideo.d.ts +6 -0
- package/lib/ext/BilibiliPlugin/BilibiliVideo.js +24 -0
- package/lib/ext/BilibiliPlugin/config.d.ts +2 -0
- package/lib/ext/BilibiliPlugin/config.js +40 -0
- package/lib/ext/BilibiliPlugin/index.d.ts +5 -0
- package/lib/ext/BilibiliPlugin/index.js +20 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbed.d.ts +7 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbed.js +51 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbedNode.d.ts +30 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbedNode.js +96 -0
- package/lib/ext/BlockletEmbedPlugin/index.d.ts +12 -0
- package/lib/ext/BlockletEmbedPlugin/index.js +76 -0
- package/lib/ext/BlurTextPlugin.d.ts +1 -0
- package/lib/ext/BlurTextPlugin.js +40 -0
- package/lib/ext/BookmarkPlugin/Bookmark.d.ts +7 -0
- package/lib/ext/BookmarkPlugin/Bookmark.js +175 -0
- package/lib/ext/BookmarkPlugin/BookmarkNode.d.ts +35 -0
- package/lib/ext/BookmarkPlugin/BookmarkNode.js +110 -0
- package/lib/ext/BookmarkPlugin/index.d.ts +11 -0
- package/lib/ext/BookmarkPlugin/index.js +45 -0
- package/lib/ext/BusyPlugin.d.ts +9 -0
- package/lib/ext/BusyPlugin.js +17 -0
- package/lib/ext/CharacterCountPlugin/index.d.ts +10 -0
- package/lib/ext/CharacterCountPlugin/index.js +39 -0
- package/lib/ext/CharacterCountPlugin/useCharacterCount.d.ts +11 -0
- package/lib/ext/CharacterCountPlugin/useCharacterCount.js +49 -0
- package/lib/ext/CharacterLimitPlugin/index.d.ts +9 -0
- package/lib/ext/CharacterLimitPlugin/index.js +49 -0
- package/lib/ext/CheckboxPlugin.d.ts +3 -0
- package/lib/ext/CheckboxPlugin.js +75 -0
- package/lib/ext/CodeCopyPlugin/CodeCopyPlugin.d.ts +2 -0
- package/lib/ext/CodeCopyPlugin/CodeCopyPlugin.js +90 -0
- package/lib/ext/CodeCopyPlugin/copy.svg +1 -0
- package/lib/ext/CodeCopyPlugin/index.d.ts +1 -0
- package/lib/ext/CodeCopyPlugin/index.js +1 -0
- package/lib/ext/CodeCopyPlugin/style.css +12 -0
- package/lib/ext/ContentLocale.d.ts +7 -0
- package/lib/ext/ContentLocale.js +15 -0
- package/lib/ext/CustomOnChangePlugin/index.d.ts +5 -0
- package/lib/ext/CustomOnChangePlugin/index.js +17 -0
- package/lib/ext/CustomOnChangePlugin/styles.css +14 -0
- package/lib/ext/CustomOnChangePlugin/utils.d.ts +30 -0
- package/lib/ext/CustomOnChangePlugin/utils.js +148 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderContext.d.ts +13 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderContext.js +15 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderPlugin.d.ts +1 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderPlugin.js +11 -0
- package/lib/ext/EditorHolderPlugin/index.d.ts +2 -0
- package/lib/ext/EditorHolderPlugin/index.js +2 -0
- package/lib/ext/EditorReadyPlugin.d.ts +3 -0
- package/lib/ext/EditorReadyPlugin.js +15 -0
- package/lib/ext/FilePlugin/FileNode.d.ts +44 -0
- package/lib/ext/FilePlugin/FileNode.js +195 -0
- package/lib/ext/FilePlugin/FilePlugin.d.ts +7 -0
- package/lib/ext/FilePlugin/FilePlugin.js +27 -0
- package/lib/ext/FilePlugin/index.d.ts +2 -0
- package/lib/ext/FilePlugin/index.js +2 -0
- package/lib/ext/HeadingsIdPlugin.d.ts +1 -0
- package/lib/ext/HeadingsIdPlugin.js +67 -0
- package/lib/ext/ImagePathFixerPlugin.d.ts +1 -0
- package/lib/ext/ImagePathFixerPlugin.js +31 -0
- package/lib/ext/InlineTranslationPlugin/EditorTranslator.d.ts +42 -0
- package/lib/ext/InlineTranslationPlugin/EditorTranslator.js +199 -0
- package/lib/ext/InlineTranslationPlugin/InlineTranslationPlugin.d.ts +12 -0
- package/lib/ext/InlineTranslationPlugin/InlineTranslationPlugin.js +232 -0
- package/lib/ext/InlineTranslationPlugin/TranslationNode.d.ts +23 -0
- package/lib/ext/InlineTranslationPlugin/TranslationNode.js +49 -0
- package/lib/ext/InlineTranslationPlugin/index.d.ts +4 -0
- package/lib/ext/InlineTranslationPlugin/index.js +4 -0
- package/lib/ext/InlineTranslationPlugin/store.d.ts +50 -0
- package/lib/ext/InlineTranslationPlugin/store.js +94 -0
- package/lib/ext/InlineTranslationPlugin/types.d.ts +1 -0
- package/lib/ext/InlineTranslationPlugin/types.js +1 -0
- package/lib/ext/LexicalEditorRefPlugin.d.ts +14 -0
- package/lib/ext/LexicalEditorRefPlugin.js +26 -0
- package/lib/ext/OnContentChangePlugin.d.ts +14 -0
- package/lib/ext/OnContentChangePlugin.js +35 -0
- package/lib/ext/PasteSlackImagePlugin/index.d.ts +2 -0
- package/lib/ext/PasteSlackImagePlugin/index.js +22 -0
- package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.d.ts +32 -0
- package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.js +140 -0
- package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.d.ts +1 -0
- package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.js +15 -0
- package/lib/ext/PostLinkEmbedPlugin/index.d.ts +21 -0
- package/lib/ext/PostLinkEmbedPlugin/index.js +148 -0
- package/lib/ext/RemoveListPlugin.d.ts +1 -0
- package/lib/ext/RemoveListPlugin.js +63 -0
- package/lib/ext/SafeAreaPlugin.d.ts +12 -0
- package/lib/ext/SafeAreaPlugin.js +56 -0
- package/lib/ext/SelectBlockPlugin.d.ts +1 -0
- package/lib/ext/SelectBlockPlugin.js +95 -0
- package/lib/ext/ShortcutPlugin/CtrlsShortcutPlugin.d.ts +6 -0
- package/lib/ext/ShortcutPlugin/CtrlsShortcutPlugin.js +17 -0
- package/lib/ext/ShortcutPlugin/index.d.ts +1 -0
- package/lib/ext/ShortcutPlugin/index.js +1 -0
- package/lib/ext/TemplatePlugin.d.ts +8 -0
- package/lib/ext/TemplatePlugin.js +170 -0
- package/lib/ext/VideoPathFixerPlugin.d.ts +1 -0
- package/lib/ext/VideoPathFixerPlugin.js +31 -0
- package/lib/ext/VideoPlugin/VideoComponent.d.ts +5 -0
- package/lib/ext/VideoPlugin/VideoComponent.js +5 -0
- package/lib/ext/VideoPlugin/VideoNode.d.ts +37 -0
- package/lib/ext/VideoPlugin/VideoNode.js +97 -0
- package/lib/ext/VideoPlugin/VideoPlugin.d.ts +7 -0
- package/lib/ext/VideoPlugin/VideoPlugin.js +26 -0
- package/lib/ext/VideoPlugin/index.d.ts +2 -0
- package/lib/ext/VideoPlugin/index.js +2 -0
- package/lib/ext/common.d.ts +15 -0
- package/lib/ext/common.js +62 -0
- package/lib/ext/nodes/GithubComp.d.ts +3 -0
- package/lib/ext/nodes/GithubComp.js +20 -0
- package/lib/ext/nodes/GithubNode.d.ts +28 -0
- package/lib/ext/nodes/GithubNode.js +94 -0
- package/lib/ext/nodes/util.d.ts +5 -0
- package/lib/ext/nodes/util.js +1 -0
- package/lib/ext/translation/translation-utils.d.ts +16 -0
- package/lib/ext/translation/translation-utils.js +63 -0
- package/lib/ext/utils.d.ts +21 -0
- package/lib/ext/utils.js +88 -0
- package/lib/global.d.ts +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/lexical-utils/index.d.ts +46 -0
- package/lib/lexical-utils/index.js +243 -0
- package/lib/libs/sort-array-by-key.d.ts +4 -0
- package/lib/libs/sort-array-by-key.js +68 -0
- package/lib/libs/utm.d.ts +9 -0
- package/lib/libs/utm.js +43 -0
- package/lib/main/appSettings.d.ts +11 -0
- package/lib/main/appSettings.js +20 -0
- package/lib/main/context/SharedAutocompleteContext.d.ts +16 -0
- package/lib/main/context/SharedAutocompleteContext.js +35 -0
- package/lib/main/context/SharedHistoryContext.d.ts +17 -0
- package/lib/main/context/SharedHistoryContext.js +11 -0
- package/lib/main/editor-root.d.ts +2 -0
- package/lib/main/editor-root.js +46 -0
- package/lib/main/editor.d.ts +21 -0
- package/lib/main/editor.js +99 -0
- package/lib/main/hooks/hooks.d.ts +15 -0
- package/lib/main/hooks/hooks.js +49 -0
- package/lib/main/hooks/medium-zoom.d.ts +9 -0
- package/lib/main/hooks/medium-zoom.js +34 -0
- package/lib/main/hooks/use-mobile.d.ts +4 -0
- package/lib/main/hooks/use-mobile.js +6 -0
- package/lib/main/hooks/useBeforeUnload.d.ts +1 -0
- package/lib/main/hooks/useBeforeUnload.js +15 -0
- package/lib/main/hooks/useHasNodes.d.ts +1 -0
- package/lib/main/hooks/useHasNodes.js +8 -0
- package/lib/main/hooks/useIsFocused.d.ts +1 -0
- package/lib/main/hooks/useIsFocused.js +20 -0
- package/lib/main/hooks/useModal.d.ts +12 -0
- package/lib/main/hooks/useModal.js +33 -0
- package/lib/main/hooks/useReport.d.ts +8 -0
- package/lib/main/hooks/useReport.js +48 -0
- package/lib/main/hooks/useResponsiveTable.d.ts +5 -0
- package/lib/main/hooks/useResponsiveTable.js +31 -0
- package/lib/main/hooks/useTranslationListener.d.ts +4 -0
- package/lib/main/hooks/useTranslationListener.js +94 -0
- package/lib/main/icons.d.ts +3 -0
- package/lib/main/icons.js +25 -0
- package/lib/main/images/emoji/1F600.png +0 -0
- package/lib/main/images/emoji/1F641.png +0 -0
- package/lib/main/images/emoji/1F642.png +0 -0
- package/lib/main/images/emoji/2764.png +0 -0
- package/lib/main/images/excalidraw.svg +3 -0
- package/lib/main/images/icons/arrow-clockwise.svg +1 -0
- package/lib/main/images/icons/arrow-counterclockwise.svg +1 -0
- package/lib/main/images/icons/bg-color.svg +1 -0
- package/lib/main/images/icons/camera.svg +1 -0
- package/lib/main/images/icons/caret-right-fill.svg +1 -0
- package/lib/main/images/icons/chat-left-text.svg +1 -0
- package/lib/main/images/icons/chat-right-dots.svg +1 -0
- package/lib/main/images/icons/chat-right-text.svg +1 -0
- package/lib/main/images/icons/chat-right.svg +1 -0
- package/lib/main/images/icons/chat-square-quote.svg +1 -0
- package/lib/main/images/icons/chevron-down.svg +1 -0
- package/lib/main/images/icons/clipboard.svg +1 -0
- package/lib/main/images/icons/close.svg +1 -0
- package/lib/main/images/icons/code.svg +1 -0
- package/lib/main/images/icons/comments.svg +1 -0
- package/lib/main/images/icons/copy.svg +1 -0
- package/lib/main/images/icons/diagram-2.svg +1 -0
- package/lib/main/images/icons/download.svg +1 -0
- package/lib/main/images/icons/draggable-block-menu.svg +1 -0
- package/lib/main/images/icons/dropdown-more.svg +1 -0
- package/lib/main/images/icons/figma.svg +1 -0
- package/lib/main/images/icons/file-image.svg +1 -0
- package/lib/main/images/icons/filetype-gif.svg +1 -0
- package/lib/main/images/icons/font-color.svg +1 -0
- package/lib/main/images/icons/font-family.svg +1 -0
- package/lib/main/images/icons/gear.svg +1 -0
- package/lib/main/images/icons/horizontal-rule.svg +1 -0
- package/lib/main/images/icons/indent.svg +1 -0
- package/lib/main/images/icons/journal-code.svg +1 -0
- package/lib/main/images/icons/journal-text.svg +1 -0
- package/lib/main/images/icons/justify.svg +1 -0
- package/lib/main/images/icons/link.svg +1 -0
- package/lib/main/images/icons/list-ol.svg +1 -0
- package/lib/main/images/icons/list-ul.svg +1 -0
- package/lib/main/images/icons/lock-fill.svg +1 -0
- package/lib/main/images/icons/lock.svg +1 -0
- package/lib/main/images/icons/markdown.svg +1 -0
- package/lib/main/images/icons/mic.svg +1 -0
- package/lib/main/images/icons/outdent.svg +1 -0
- package/lib/main/images/icons/paint-bucket.svg +1 -0
- package/lib/main/images/icons/palette.svg +1 -0
- package/lib/main/images/icons/pencil-fill.svg +1 -0
- package/lib/main/images/icons/plug-fill.svg +1 -0
- package/lib/main/images/icons/plug.svg +1 -0
- package/lib/main/images/icons/plus-slash-minus.svg +1 -0
- package/lib/main/images/icons/plus.svg +1 -0
- package/lib/main/images/icons/prettier-error.svg +1 -0
- package/lib/main/images/icons/prettier.svg +1 -0
- package/lib/main/images/icons/send.svg +1 -0
- package/lib/main/images/icons/square-check.svg +1 -0
- package/lib/main/images/icons/sticky.svg +1 -0
- package/lib/main/images/icons/success.svg +1 -0
- package/lib/main/images/icons/table.svg +1 -0
- package/lib/main/images/icons/text-center.svg +1 -0
- package/lib/main/images/icons/text-left.svg +1 -0
- package/lib/main/images/icons/text-paragraph.svg +1 -0
- package/lib/main/images/icons/text-right.svg +1 -0
- package/lib/main/images/icons/trash.svg +1 -0
- package/lib/main/images/icons/trash3.svg +1 -0
- package/lib/main/images/icons/tweet.svg +1 -0
- package/lib/main/images/icons/type-bold.svg +1 -0
- package/lib/main/images/icons/type-h1.svg +1 -0
- package/lib/main/images/icons/type-h2.svg +1 -0
- package/lib/main/images/icons/type-h3.svg +1 -0
- package/lib/main/images/icons/type-h4.svg +1 -0
- package/lib/main/images/icons/type-h5.svg +1 -0
- package/lib/main/images/icons/type-h6.svg +1 -0
- package/lib/main/images/icons/type-italic.svg +1 -0
- package/lib/main/images/icons/type-strikethrough.svg +1 -0
- package/lib/main/images/icons/type-subscript.svg +1 -0
- package/lib/main/images/icons/type-superscript.svg +1 -0
- package/lib/main/images/icons/type-underline.svg +1 -0
- package/lib/main/images/icons/upload.svg +1 -0
- package/lib/main/images/icons/user.svg +1 -0
- package/lib/main/images/icons/youtube.svg +1 -0
- package/lib/main/images/landscape.jpg +0 -0
- package/lib/main/index.css +257 -0
- package/lib/main/index.d.ts +28 -0
- package/lib/main/index.js +52 -0
- package/lib/main/nodes/EmojiNode.d.ts +25 -0
- package/lib/main/nodes/EmojiNode.js +57 -0
- package/lib/main/nodes/EquationNode.d.ts +31 -0
- package/lib/main/nodes/EquationNode.js +65 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawComponent.d.ts +13 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawComponent.js +155 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawImage.d.ts +58 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawImage.js +60 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.css +75 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.d.ts +49 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.js +197 -0
- package/lib/main/nodes/ExcalidrawNode/index.d.ts +30 -0
- package/lib/main/nodes/ExcalidrawNode/index.js +95 -0
- package/lib/main/nodes/ExcalidrawNode/utils.d.ts +5 -0
- package/lib/main/nodes/ExcalidrawNode/utils.js +71 -0
- package/lib/main/nodes/FigmaNode.d.ts +30 -0
- package/lib/main/nodes/FigmaNode.js +59 -0
- package/lib/main/nodes/ImageComponent.d.ts +27 -0
- package/lib/main/nodes/ImageComponent.js +432 -0
- package/lib/main/nodes/ImageNode.css +51 -0
- package/lib/main/nodes/ImageNode.d.ts +74 -0
- package/lib/main/nodes/ImageNode.js +151 -0
- package/lib/main/nodes/KeywordNode.d.ts +25 -0
- package/lib/main/nodes/KeywordNode.js +52 -0
- package/lib/main/nodes/MentionNode.d.ts +27 -0
- package/lib/main/nodes/MentionNode.js +88 -0
- package/lib/main/nodes/PlaygroundNodes.d.ts +10 -0
- package/lib/main/nodes/PlaygroundNodes.js +70 -0
- package/lib/main/nodes/TweetNode.d.ts +31 -0
- package/lib/main/nodes/TweetNode.js +126 -0
- package/lib/main/nodes/YouTubeNode.d.ts +32 -0
- package/lib/main/nodes/YouTubeNode.js +94 -0
- package/lib/main/plugins/AutoEmbedPlugin/index.d.ts +27 -0
- package/lib/main/plugins/AutoEmbedPlugin/index.js +353 -0
- package/lib/main/plugins/AutoEmbedPlugin/urlParseCache.d.ts +2 -0
- package/lib/main/plugins/AutoEmbedPlugin/urlParseCache.js +14 -0
- package/lib/main/plugins/AutoLinkPlugin/index.d.ts +9 -0
- package/lib/main/plugins/AutoLinkPlugin/index.js +39 -0
- package/lib/main/plugins/ClickableLinkPlugin/index.d.ts +8 -0
- package/lib/main/plugins/ClickableLinkPlugin/index.js +141 -0
- package/lib/main/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -0
- package/lib/main/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +44 -0
- package/lib/main/plugins/CodeActionMenuPlugin/index.css +46 -0
- package/lib/main/plugins/CodeActionMenuPlugin/index.d.ts +12 -0
- package/lib/main/plugins/CodeActionMenuPlugin/index.js +100 -0
- package/lib/main/plugins/CodeActionMenuPlugin/utils.d.ts +2 -0
- package/lib/main/plugins/CodeActionMenuPlugin/utils.js +18 -0
- package/lib/main/plugins/CodeHighlightPlugin/index.d.ts +9 -0
- package/lib/main/plugins/CodeHighlightPlugin/index.js +17 -0
- package/lib/main/plugins/CollapsiblePlugin/Collapsible.css +61 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContainerNode.d.ts +30 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContainerNode.js +120 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContentNode.d.ts +24 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContentNode.js +90 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleTitleNode.d.ts +24 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleTitleNode.js +95 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleUtils.d.ts +9 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleUtils.js +15 -0
- package/lib/main/plugins/CollapsiblePlugin/index.d.ts +11 -0
- package/lib/main/plugins/CollapsiblePlugin/index.js +147 -0
- package/lib/main/plugins/ComponentPickerPlugin/index.d.ts +12 -0
- package/lib/main/plugins/ComponentPickerPlugin/index.js +438 -0
- package/lib/main/plugins/DragDropPastePlugin/index.d.ts +8 -0
- package/lib/main/plugins/DragDropPastePlugin/index.js +32 -0
- package/lib/main/plugins/DraggableBlockPlugin/index.css +36 -0
- package/lib/main/plugins/DraggableBlockPlugin/index.d.ts +12 -0
- package/lib/main/plugins/DraggableBlockPlugin/index.js +288 -0
- package/lib/main/plugins/EmojisPlugin/index.d.ts +9 -0
- package/lib/main/plugins/EmojisPlugin/index.js +63 -0
- package/lib/main/plugins/ExcalidrawPlugin/index.d.ts +3 -0
- package/lib/main/plugins/ExcalidrawPlugin/index.js +30 -0
- package/lib/main/plugins/FigmaPlugin/index.d.ts +11 -0
- package/lib/main/plugins/FigmaPlugin/index.js +27 -0
- package/lib/main/plugins/FloatingLinkEditorPlugin/index.css +39 -0
- package/lib/main/plugins/FloatingLinkEditorPlugin/index.d.ts +12 -0
- package/lib/main/plugins/FloatingLinkEditorPlugin/index.js +181 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/ColorPickerButton.d.ts +5 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/ColorPickerButton.js +24 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.css +128 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +12 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.js +216 -0
- package/lib/main/plugins/HorizontalRulePlugin/index.d.ts +8 -0
- package/lib/main/plugins/HorizontalRulePlugin/index.js +30 -0
- package/lib/main/plugins/ImagesPlugin/index.d.ts +15 -0
- package/lib/main/plugins/ImagesPlugin/index.js +36 -0
- package/lib/main/plugins/LexicalTypeaheadMenuPlugin/index.d.ts +64 -0
- package/lib/main/plugins/LexicalTypeaheadMenuPlugin/index.js +493 -0
- package/lib/main/plugins/MarkdownShortcutPlugin/index.d.ts +9 -0
- package/lib/main/plugins/MarkdownShortcutPlugin/index.js +22 -0
- package/lib/main/plugins/MarkdownTransformers/index.d.ts +12 -0
- package/lib/main/plugins/MarkdownTransformers/index.js +185 -0
- package/lib/main/plugins/MaxLengthPlugin/index.d.ts +10 -0
- package/lib/main/plugins/MaxLengthPlugin/index.js +43 -0
- package/lib/main/plugins/MentionsPlugin/HighlightStyle.d.ts +2 -0
- package/lib/main/plugins/MentionsPlugin/HighlightStyle.js +13 -0
- package/lib/main/plugins/MentionsPlugin/index.d.ts +9 -0
- package/lib/main/plugins/MentionsPlugin/index.js +175 -0
- package/lib/main/plugins/TabFocusPlugin/index.d.ts +8 -0
- package/lib/main/plugins/TabFocusPlugin/index.js +41 -0
- package/lib/main/plugins/TableActionMenuPlugin/index.d.ts +12 -0
- package/lib/main/plugins/TableActionMenuPlugin/index.js +486 -0
- package/lib/main/plugins/TableCellResizer/index.css +20 -0
- package/lib/main/plugins/TableCellResizer/index.d.ts +3 -0
- package/lib/main/plugins/TableCellResizer/index.js +295 -0
- package/lib/main/plugins/TableOfContentsPlugin/index.css +87 -0
- package/lib/main/plugins/TableOfContentsPlugin/index.d.ts +2 -0
- package/lib/main/plugins/TableOfContentsPlugin/index.js +106 -0
- package/lib/main/plugins/TablePlugin.d.ts +38 -0
- package/lib/main/plugins/TablePlugin.js +63 -0
- package/lib/main/plugins/ToolbarPlugin/index.d.ts +8 -0
- package/lib/main/plugins/ToolbarPlugin/index.js +467 -0
- package/lib/main/plugins/TreeViewPlugin/index.d.ts +9 -0
- package/lib/main/plugins/TreeViewPlugin/index.js +14 -0
- package/lib/main/plugins/TwitterPlugin/index.d.ts +11 -0
- package/lib/main/plugins/TwitterPlugin/index.js +27 -0
- package/lib/main/plugins/TypingPerfPlugin/index.d.ts +9 -0
- package/lib/main/plugins/TypingPerfPlugin/index.js +100 -0
- package/lib/main/plugins/YouTubePlugin/index.d.ts +11 -0
- package/lib/main/plugins/YouTubePlugin/index.js +27 -0
- package/lib/main/server/validation.d.ts +8 -0
- package/lib/main/server/validation.js +119 -0
- package/lib/main/setupEnv.d.ts +8 -0
- package/lib/main/setupEnv.js +25 -0
- package/lib/main/style/editable.css +476 -0
- package/lib/main/styled-editor-content.d.ts +5 -0
- package/lib/main/styled-editor-content.js +206 -0
- package/lib/main/themes/code-highlight/index.d.ts +32 -0
- package/lib/main/themes/code-highlight/index.js +58 -0
- package/lib/main/themes/customTheme.d.ts +2 -0
- package/lib/main/themes/customTheme.js +324 -0
- package/lib/main/themes/defaultTheme.d.ts +10 -0
- package/lib/main/themes/defaultTheme.js +554 -0
- package/lib/main/themes/table/index.d.ts +3 -0
- package/lib/main/themes/table/index.js +20 -0
- package/lib/main/themes/table/table.css +214 -0
- package/lib/main/ui/Button.css +36 -0
- package/lib/main/ui/Button.d.ts +18 -0
- package/lib/main/ui/Button.js +13 -0
- package/lib/main/ui/ColorPicker.css +89 -0
- package/lib/main/ui/ColorPicker.d.ts +28 -0
- package/lib/main/ui/ColorPicker.js +206 -0
- package/lib/main/ui/ContentEditable.d.ts +2 -0
- package/lib/main/ui/ContentEditable.js +15 -0
- package/lib/main/ui/Dialog.css +17 -0
- package/lib/main/ui/Dialog.d.ts +16 -0
- package/lib/main/ui/Dialog.js +15 -0
- package/lib/main/ui/DropDown.d.ts +25 -0
- package/lib/main/ui/DropDown.js +146 -0
- package/lib/main/ui/FileInput.d.ts +17 -0
- package/lib/main/ui/FileInput.js +5 -0
- package/lib/main/ui/FrameMockup/browser.css +52 -0
- package/lib/main/ui/FrameMockup/browser.d.ts +13 -0
- package/lib/main/ui/FrameMockup/browser.js +22 -0
- package/lib/main/ui/FrameMockup/index.d.ts +113 -0
- package/lib/main/ui/FrameMockup/index.js +61 -0
- package/lib/main/ui/ImageEnhancer.d.ts +29 -0
- package/lib/main/ui/ImageEnhancer.js +113 -0
- package/lib/main/ui/ImageResizer.d.ts +24 -0
- package/lib/main/ui/ImageResizer.js +154 -0
- package/lib/main/ui/Input.css +30 -0
- package/lib/main/ui/Modal.css +62 -0
- package/lib/main/ui/Modal.d.ts +15 -0
- package/lib/main/ui/Modal.js +50 -0
- package/lib/main/ui/Placeholder.d.ts +6 -0
- package/lib/main/ui/Placeholder.js +20 -0
- package/lib/main/ui/TextInput.d.ts +20 -0
- package/lib/main/ui/TextInput.js +14 -0
- package/lib/main/utils/getDOMRangeRect.d.ts +8 -0
- package/lib/main/utils/getDOMRangeRect.js +22 -0
- package/lib/main/utils/getSelectedNode.d.ts +2 -0
- package/lib/main/utils/getSelectedNode.js +22 -0
- package/lib/main/utils/guard.d.ts +14 -0
- package/lib/main/utils/guard.js +36 -0
- package/lib/main/utils/images.d.ts +10 -0
- package/lib/main/utils/images.js +16 -0
- package/lib/main/utils/join-classes.d.ts +8 -0
- package/lib/main/utils/join-classes.js +10 -0
- package/lib/main/utils/point.d.ts +21 -0
- package/lib/main/utils/point.js +42 -0
- package/lib/main/utils/prevent-duplicate-upload.d.ts +2 -0
- package/lib/main/utils/prevent-duplicate-upload.js +25 -0
- package/lib/main/utils/rect.d.ts +45 -0
- package/lib/main/utils/rect.js +98 -0
- package/lib/main/utils/sanitizeUrl.d.ts +8 -0
- package/lib/main/utils/sanitizeUrl.js +17 -0
- package/lib/main/utils/setFloatingElemPosition.d.ts +1 -0
- package/lib/main/utils/setFloatingElemPosition.js +32 -0
- package/lib/main/utils/swipe.d.ts +11 -0
- package/lib/main/utils/swipe.js +98 -0
- package/lib/main/viewer/index.d.ts +5 -0
- package/lib/main/viewer/index.js +25 -0
- package/lib/main/viewer/types.d.ts +14 -0
- package/lib/main/viewer/types.js +1 -0
- package/lib/main/viewer/viewer.d.ts +3 -0
- package/lib/main/viewer/viewer.js +31 -0
- package/lib/shared/canUseDOM.d.ts +8 -0
- package/lib/shared/canUseDOM.js +10 -0
- package/lib/shared/environment.d.ts +24 -0
- package/lib/shared/environment.js +21 -0
- package/lib/shared/getDOMSelection.d.ts +9 -0
- package/lib/shared/getDOMSelection.js +10 -0
- package/lib/shared/invariant.d.ts +8 -0
- package/lib/shared/invariant.js +16 -0
- package/lib/shared/useLayoutEffect.d.ts +10 -0
- package/lib/shared/useLayoutEffect.js +11 -0
- package/lib/types.d.ts +19 -0
- package/lib/types.js +1 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/LexicalCharacterLimitPlugin.d.ts +15 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/LexicalCharacterLimitPlugin.js +45 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/index.d.ts +1 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/index.js +1 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/useCharacterLimit.d.ts +16 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/useCharacterLimit.js +208 -0
- package/lib/vendor/history/LexicalHistoryPlugin.d.ts +14 -0
- package/lib/vendor/history/LexicalHistoryPlugin.js +15 -0
- package/lib/vendor/history/history/index.d.ts +63 -0
- package/lib/vendor/history/history/index.js +351 -0
- package/lib/vendor/history/useHistory.d.ts +10 -0
- package/lib/vendor/history/useHistory.js +15 -0
- package/package.json +109 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { ExcalidrawElement, NonDeleted } from '@excalidraw/excalidraw/dist/types/excalidraw/element/types';
|
|
9
|
+
import type { AppState, BinaryFiles } from '@excalidraw/excalidraw/dist/types/excalidraw/types';
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import { type JSX } from 'react';
|
|
12
|
+
type ImageType = 'svg' | 'canvas';
|
|
13
|
+
type Props = {
|
|
14
|
+
/**
|
|
15
|
+
* Configures the export setting for SVG/Canvas
|
|
16
|
+
*/
|
|
17
|
+
appState: AppState;
|
|
18
|
+
/**
|
|
19
|
+
* The css class applied to image to be rendered
|
|
20
|
+
*/
|
|
21
|
+
className?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The Excalidraw elements to be rendered as an image
|
|
24
|
+
*/
|
|
25
|
+
elements: NonDeleted<ExcalidrawElement>[];
|
|
26
|
+
/**
|
|
27
|
+
* The Excalidraw elements to be rendered as an image
|
|
28
|
+
*/
|
|
29
|
+
files: BinaryFiles;
|
|
30
|
+
/**
|
|
31
|
+
* The height of the image to be rendered
|
|
32
|
+
*/
|
|
33
|
+
height?: number | null;
|
|
34
|
+
/**
|
|
35
|
+
* The ref object to be used to render the image
|
|
36
|
+
*/
|
|
37
|
+
imageContainerRef: {
|
|
38
|
+
current: null | HTMLDivElement;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The type of image to be rendered
|
|
42
|
+
*/
|
|
43
|
+
imageType?: ImageType;
|
|
44
|
+
/**
|
|
45
|
+
* The css class applied to the root element of this component
|
|
46
|
+
*/
|
|
47
|
+
rootClassName?: string | null;
|
|
48
|
+
/**
|
|
49
|
+
* The width of the image to be rendered
|
|
50
|
+
*/
|
|
51
|
+
width?: number | null;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @explorer-desc
|
|
55
|
+
* A component for rendering Excalidraw elements as a static image
|
|
56
|
+
*/
|
|
57
|
+
export default function ExcalidrawImage({ elements, files, imageContainerRef, appState, rootClassName, ...rest }: Props & React.HTMLProps<HTMLDivElement>): JSX.Element;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import { exportToSvg } from '@excalidraw/excalidraw';
|
|
10
|
+
import { useTheme } from '@mui/material';
|
|
11
|
+
import { useEffect, useState } from 'react';
|
|
12
|
+
// exportToSvg has fonts from excalidraw.com
|
|
13
|
+
// We don't want them to be used in open source
|
|
14
|
+
const removeStyleFromSvg_HACK = (svg) => {
|
|
15
|
+
const styleTag = svg?.firstElementChild?.firstElementChild;
|
|
16
|
+
// Generated SVG is getting double-sized by height and width attributes
|
|
17
|
+
// We want to match the real size of the SVG element
|
|
18
|
+
const viewBox = svg.getAttribute('viewBox');
|
|
19
|
+
if (viewBox != null) {
|
|
20
|
+
const viewBoxDimensions = viewBox.split(' ');
|
|
21
|
+
svg.setAttribute('width', viewBoxDimensions[2]);
|
|
22
|
+
svg.setAttribute('height', viewBoxDimensions[3]);
|
|
23
|
+
}
|
|
24
|
+
if (styleTag && styleTag.tagName === 'style') {
|
|
25
|
+
styleTag.remove();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @explorer-desc
|
|
30
|
+
* A component for rendering Excalidraw elements as a static image
|
|
31
|
+
*/
|
|
32
|
+
export default function ExcalidrawImage({ elements, files, imageContainerRef, appState, rootClassName = null, ...rest }) {
|
|
33
|
+
const [Svg, setSvg] = useState(null);
|
|
34
|
+
const theme = useTheme();
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const setContent = async () => {
|
|
37
|
+
const svg = await exportToSvg({
|
|
38
|
+
appState: {
|
|
39
|
+
...appState,
|
|
40
|
+
...(theme.palette.mode === 'dark' && {
|
|
41
|
+
theme: 'dark',
|
|
42
|
+
viewBackgroundColor: theme.palette.background.default,
|
|
43
|
+
// exportWithDarkMode: true,
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
elements,
|
|
47
|
+
files,
|
|
48
|
+
});
|
|
49
|
+
removeStyleFromSvg_HACK(svg);
|
|
50
|
+
svg.setAttribute('width', '100%');
|
|
51
|
+
svg.setAttribute('height', '100%');
|
|
52
|
+
svg.setAttribute('display', 'block');
|
|
53
|
+
setSvg(svg);
|
|
54
|
+
};
|
|
55
|
+
setContent();
|
|
56
|
+
}, [elements, files, appState]);
|
|
57
|
+
return (_jsx("div", { ref: imageContainerRef, className: rootClassName ?? '',
|
|
58
|
+
// eslint-disable-next-line react/no-danger
|
|
59
|
+
dangerouslySetInnerHTML: { __html: Svg?.outerHTML ?? '' }, ...rest }));
|
|
60
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
.ExcalidrawModal__overlay {
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
position: fixed;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
top: 0px;
|
|
16
|
+
bottom: 0px;
|
|
17
|
+
left: 0px;
|
|
18
|
+
right: 0px;
|
|
19
|
+
flex-grow: 0px;
|
|
20
|
+
flex-shrink: 1px;
|
|
21
|
+
z-index: 10001;
|
|
22
|
+
background-color: rgba(40, 40, 40, 0.6);
|
|
23
|
+
}
|
|
24
|
+
.ExcalidrawModal__actions {
|
|
25
|
+
display: flex;
|
|
26
|
+
text-align: end;
|
|
27
|
+
position: absolute;
|
|
28
|
+
right: 5px;
|
|
29
|
+
top: 5px;
|
|
30
|
+
z-index: 1;
|
|
31
|
+
}
|
|
32
|
+
.ExcalidrawModal__actions button {
|
|
33
|
+
background-color: #fff;
|
|
34
|
+
border-radius: 5px;
|
|
35
|
+
}
|
|
36
|
+
.ExcalidrawModal__row {
|
|
37
|
+
position: relative;
|
|
38
|
+
padding: 42px 5px 5px;
|
|
39
|
+
width: 90vw;
|
|
40
|
+
height: 90vh;
|
|
41
|
+
border-radius: 8px;
|
|
42
|
+
box-shadow: 0 12px 28px 0 rgba(0, 0, 0, 0.2), 0 2px 4px 0 rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(255, 255, 255, 0.5);
|
|
43
|
+
}
|
|
44
|
+
.ExcalidrawModal__row > div {
|
|
45
|
+
border-radius: 5px;
|
|
46
|
+
}
|
|
47
|
+
.ExcalidrawModal__modal {
|
|
48
|
+
position: relative;
|
|
49
|
+
z-index: 99999;
|
|
50
|
+
top: 50px;
|
|
51
|
+
width: auto;
|
|
52
|
+
left: 0;
|
|
53
|
+
display: flex;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
align-items: center;
|
|
56
|
+
border-radius: 8px;
|
|
57
|
+
background-color: #eee;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.ExcalidrawModal__discardModal {
|
|
61
|
+
margin-top: 60px;
|
|
62
|
+
text-align: center;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.ExcalidrawModal__fullscreen .ExcalidrawModal__modal {
|
|
66
|
+
top: 0;
|
|
67
|
+
}
|
|
68
|
+
.ExcalidrawModal__fullscreen .ExcalidrawModal__row {
|
|
69
|
+
width: 100vw;
|
|
70
|
+
height: 100vh;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
body .excalidraw-modal-container {
|
|
74
|
+
z-index: 99999 !important;
|
|
75
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ReactPortal } from 'react';
|
|
2
|
+
import type { AppState, BinaryFiles, LibraryItems } from '@excalidraw/excalidraw/dist/types/excalidraw/types';
|
|
3
|
+
import '@excalidraw/excalidraw/index.css';
|
|
4
|
+
export type ExcalidrawElementFragment = {
|
|
5
|
+
isDeleted?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type Props = {
|
|
8
|
+
closeOnClickOutside?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The initial set of elements to draw into the scene
|
|
11
|
+
*/
|
|
12
|
+
initialElements: ReadonlyArray<ExcalidrawElementFragment>;
|
|
13
|
+
/**
|
|
14
|
+
* The initial set of elements to draw into the scene
|
|
15
|
+
*/
|
|
16
|
+
initialAppState: AppState;
|
|
17
|
+
/**
|
|
18
|
+
* The initial set of files to draw into the scene
|
|
19
|
+
*/
|
|
20
|
+
initialFiles: BinaryFiles;
|
|
21
|
+
/**
|
|
22
|
+
* The initial set of library items to draw into the scene
|
|
23
|
+
*/
|
|
24
|
+
initialLibraryItems?: LibraryItems;
|
|
25
|
+
/**
|
|
26
|
+
* Controls the visibility of the modal
|
|
27
|
+
*/
|
|
28
|
+
isShown?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Callback when closing and discarding the new changes
|
|
31
|
+
*/
|
|
32
|
+
onClose: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Completely remove Excalidraw component
|
|
35
|
+
*/
|
|
36
|
+
onDelete: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Callback when the save button is clicked
|
|
39
|
+
*/
|
|
40
|
+
onSave: (elements: ReadonlyArray<ExcalidrawElementFragment>, appState: Partial<AppState>, files: BinaryFiles) => void;
|
|
41
|
+
readonly?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* @explorer-desc
|
|
45
|
+
* A component which renders a modal with Excalidraw (a painting app)
|
|
46
|
+
* which can be used to export an editable image
|
|
47
|
+
*/
|
|
48
|
+
export default function ExcalidrawModal({ closeOnClickOutside, onSave, initialElements, initialAppState, initialFiles, initialLibraryItems, isShown, onDelete, onClose, readonly, }: Props): ReactPortal | null;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import { Excalidraw, useHandleLibrary, serializeLibraryAsJSON } from '@excalidraw/excalidraw';
|
|
10
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
11
|
+
import { createPortal } from 'react-dom';
|
|
12
|
+
import LoadingButton from '@mui/lab/LoadingButton';
|
|
13
|
+
import '@excalidraw/excalidraw/index.css';
|
|
14
|
+
import { useTheme } from '@mui/material';
|
|
15
|
+
import Button from '../../ui/Button';
|
|
16
|
+
import Modal from '../../ui/Modal';
|
|
17
|
+
import { uploadImageToMediaKit } from './utils';
|
|
18
|
+
const safeParseJSON = (json) => {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(json);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const LIBRARY_KEY = 'excalidraw-library';
|
|
27
|
+
/**
|
|
28
|
+
* @explorer-desc
|
|
29
|
+
* A component which renders a modal with Excalidraw (a painting app)
|
|
30
|
+
* which can be used to export an editable image
|
|
31
|
+
*/
|
|
32
|
+
export default function ExcalidrawModal({ closeOnClickOutside = false, onSave, initialElements, initialAppState, initialFiles, initialLibraryItems = safeParseJSON(localStorage.getItem(LIBRARY_KEY))?.libraryItems, isShown = false, onDelete, onClose, readonly, }) {
|
|
33
|
+
const excaliDrawModelRef = useRef(null);
|
|
34
|
+
const excaliDrawSceneRef = useRef(null);
|
|
35
|
+
const [discardModalOpen, setDiscardModalOpen] = useState(false);
|
|
36
|
+
const [elements, setElements] = useState(initialElements);
|
|
37
|
+
const [files, setFiles] = useState(initialFiles);
|
|
38
|
+
const [loading, setLoading] = useState(false);
|
|
39
|
+
const [saveText, setSaveText] = useState('Save');
|
|
40
|
+
const [fullScreen, setFullScreen] = useState(false);
|
|
41
|
+
const theme = useTheme();
|
|
42
|
+
const markBlockletDirtyState = () => {
|
|
43
|
+
if (!readonly) {
|
|
44
|
+
window.dispatchEvent(new CustomEvent('blocklet:markDirty', { detail: { key: 'excalidraw' } }));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const resetBlockletDirtyState = () => {
|
|
48
|
+
window.dispatchEvent(new CustomEvent('blocklet:resetDirty', { detail: { key: 'excalidraw' } }));
|
|
49
|
+
};
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
// @ts-ignore set window.name to add library target
|
|
52
|
+
window.name = window.location.href;
|
|
53
|
+
if (excaliDrawModelRef.current !== null) {
|
|
54
|
+
excaliDrawModelRef.current.focus();
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
useHandleLibrary({
|
|
58
|
+
excalidrawAPI: excaliDrawSceneRef.current,
|
|
59
|
+
getInitialLibraryItems: () => {
|
|
60
|
+
return initialLibraryItems;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
let modalOverlayElement = null;
|
|
65
|
+
const clickOutsideHandler = (event) => {
|
|
66
|
+
const { target } = event;
|
|
67
|
+
if (excaliDrawModelRef.current !== null &&
|
|
68
|
+
!excaliDrawModelRef.current.contains(target) &&
|
|
69
|
+
closeOnClickOutside) {
|
|
70
|
+
onDelete();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (excaliDrawModelRef.current !== null) {
|
|
74
|
+
modalOverlayElement = excaliDrawModelRef.current?.parentElement;
|
|
75
|
+
if (modalOverlayElement !== null) {
|
|
76
|
+
modalOverlayElement?.addEventListener('click', clickOutsideHandler);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return () => {
|
|
80
|
+
if (modalOverlayElement !== null) {
|
|
81
|
+
modalOverlayElement?.removeEventListener('click', clickOutsideHandler);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}, [closeOnClickOutside, onDelete]);
|
|
85
|
+
useLayoutEffect(() => {
|
|
86
|
+
const currentModalRef = excaliDrawModelRef.current;
|
|
87
|
+
const onKeyDown = (event) => {
|
|
88
|
+
if (event.key === 'Escape') {
|
|
89
|
+
setDiscardModalOpen(true);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
if (currentModalRef !== null) {
|
|
93
|
+
currentModalRef.addEventListener('keydown', onKeyDown);
|
|
94
|
+
}
|
|
95
|
+
return () => {
|
|
96
|
+
if (currentModalRef !== null) {
|
|
97
|
+
currentModalRef.removeEventListener('keydown', onKeyDown);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, [elements, files, onDelete]);
|
|
101
|
+
const save = async () => {
|
|
102
|
+
setLoading(true);
|
|
103
|
+
setSaveText('Saving...');
|
|
104
|
+
try {
|
|
105
|
+
if (elements.filter((el) => !el.isDeleted).length > 0) {
|
|
106
|
+
const appState = excaliDrawSceneRef?.current?.getAppState();
|
|
107
|
+
// We only need a subset of the state
|
|
108
|
+
const partialState = appState
|
|
109
|
+
? {
|
|
110
|
+
exportBackground: appState.exportBackground,
|
|
111
|
+
exportScale: appState.exportScale,
|
|
112
|
+
exportWithDarkMode: appState.theme === 'dark',
|
|
113
|
+
isBindingEnabled: appState.isBindingEnabled,
|
|
114
|
+
isLoading: appState.isLoading,
|
|
115
|
+
name: appState.name,
|
|
116
|
+
theme: appState.theme,
|
|
117
|
+
viewBackgroundColor: appState.viewBackgroundColor,
|
|
118
|
+
zenModeEnabled: appState.zenModeEnabled,
|
|
119
|
+
zoom: appState.zoom,
|
|
120
|
+
}
|
|
121
|
+
: {};
|
|
122
|
+
setSaveText('Uploading...');
|
|
123
|
+
await uploadImageToMediaKit(elements, files);
|
|
124
|
+
setSaveText('Saving...');
|
|
125
|
+
await onSave(elements, partialState, files);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// delete node if the scene is clear
|
|
129
|
+
await onDelete();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Error saving Excalidraw', error);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
setLoading(false);
|
|
137
|
+
setSaveText('Save');
|
|
138
|
+
resetBlockletDirtyState();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const discard = () => {
|
|
142
|
+
if (elements.filter((el) => !el.isDeleted).length === 0) {
|
|
143
|
+
// delete node if the scene is clear
|
|
144
|
+
onDelete();
|
|
145
|
+
resetBlockletDirtyState();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Otherwise, show confirmation dialog before closing
|
|
149
|
+
setDiscardModalOpen(true);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
153
|
+
function ShowDiscardDialog() {
|
|
154
|
+
return (_jsxs(Modal, { title: "Discard", onClose: () => {
|
|
155
|
+
setDiscardModalOpen(false);
|
|
156
|
+
}, closeOnClickOutside: false, children: ["Are you sure you want to discard the changes?", _jsxs("div", { className: "ExcalidrawModal__discardModal", children: [_jsx(Button, { onClick: () => {
|
|
157
|
+
resetBlockletDirtyState();
|
|
158
|
+
setDiscardModalOpen(false);
|
|
159
|
+
if (!initialElements?.length) {
|
|
160
|
+
onDelete();
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
onClose();
|
|
164
|
+
}
|
|
165
|
+
}, children: "Discard" }), ' ', _jsx(Button, { onClick: () => {
|
|
166
|
+
setDiscardModalOpen(false);
|
|
167
|
+
}, children: "Cancel" })] })] }));
|
|
168
|
+
}
|
|
169
|
+
if (isShown === false) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const onChange = (els, _, fls) => {
|
|
173
|
+
markBlockletDirtyState();
|
|
174
|
+
setElements(els);
|
|
175
|
+
setFiles(fls);
|
|
176
|
+
};
|
|
177
|
+
const onLibraryChange = (items) => {
|
|
178
|
+
const serializeJSON = serializeLibraryAsJSON(items);
|
|
179
|
+
localStorage.setItem(LIBRARY_KEY, serializeJSON);
|
|
180
|
+
};
|
|
181
|
+
// This is a hacky work-around for Excalidraw + Vite.
|
|
182
|
+
// In DEV, Vite pulls this in fine, in prod it doesn't. It seems
|
|
183
|
+
// like a module resolution issue with ESM vs CJS?
|
|
184
|
+
// @ts-ignore
|
|
185
|
+
const _Excalidraw = Excalidraw.$$typeof != null ? Excalidraw : Excalidraw.default;
|
|
186
|
+
const appState = {
|
|
187
|
+
...initialAppState,
|
|
188
|
+
...(theme.palette.mode === 'dark' && {
|
|
189
|
+
theme: 'dark',
|
|
190
|
+
}),
|
|
191
|
+
};
|
|
192
|
+
return createPortal(_jsx("div", { className: `ExcalidrawModal__overlay ${fullScreen ? 'ExcalidrawModal__fullscreen' : ''}`, role: "dialog", children: _jsx("div", { className: "ExcalidrawModal__modal", ref: excaliDrawModelRef, tabIndex: -1, style: { backgroundColor: theme.palette.grey[100] }, children: _jsxs("div", { className: "ExcalidrawModal__row", children: [discardModalOpen && _jsx(ShowDiscardDialog, {}), _jsx(_Excalidraw, { onChange: onChange, onLibraryChange: onLibraryChange, ref: excaliDrawSceneRef, initialData: {
|
|
193
|
+
appState: appState || { isLoading: false },
|
|
194
|
+
elements: initialElements,
|
|
195
|
+
files: initialFiles,
|
|
196
|
+
} }), _jsxs("div", { className: "ExcalidrawModal__actions", children: [!fullScreen && (_jsx(LoadingButton, { className: "action-button", style: { width: 32, padding: 0, display: 'flex', alignItems: 'center' }, onClick: () => setFullScreen(true), children: _jsx("i", { className: "iconify", "data-icon": "material-symbols:fullscreen", "data-height": "18" }) })), fullScreen && (_jsx(LoadingButton, { className: "action-button", style: { width: 32, padding: 0, display: 'flex', alignItems: 'center' }, onClick: () => setFullScreen(false), children: _jsx("i", { className: "iconify", "data-icon": "material-symbols:fullscreen-exit", "data-height": "18" }) })), !readonly && (_jsxs(_Fragment, { children: [_jsx(LoadingButton, { loadingPosition: "start", disabled: loading, className: "action-button", onClick: discard, children: "Discard" }), _jsx(LoadingButton, { loadingPosition: "start", loading: loading, className: "action-button", onClick: save, children: saveText })] })), readonly && (_jsx(LoadingButton, { className: "action-button", onClick: () => onClose(), children: "Close" }))] })] }) }) }), document.body);
|
|
197
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 './ExcalidrawModal.css';
|
|
9
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
10
|
+
import { DecoratorNode } from 'lexical';
|
|
11
|
+
import { type JSX } from 'react';
|
|
12
|
+
export type SerializedExcalidrawNode = Spread<{
|
|
13
|
+
data: string;
|
|
14
|
+
}, SerializedLexicalNode>;
|
|
15
|
+
export declare class ExcalidrawNode extends DecoratorNode<JSX.Element> {
|
|
16
|
+
__data: string;
|
|
17
|
+
static getType(): string;
|
|
18
|
+
static clone(node: ExcalidrawNode): ExcalidrawNode;
|
|
19
|
+
static importJSON(serializedNode: SerializedExcalidrawNode): ExcalidrawNode;
|
|
20
|
+
exportJSON(): SerializedExcalidrawNode;
|
|
21
|
+
constructor(data?: string, key?: NodeKey);
|
|
22
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
23
|
+
updateDOM(): false;
|
|
24
|
+
static importDOM(): DOMConversionMap<HTMLSpanElement> | null;
|
|
25
|
+
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
26
|
+
setData(data: string): void;
|
|
27
|
+
decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element;
|
|
28
|
+
}
|
|
29
|
+
export declare function $createExcalidrawNode(): ExcalidrawNode;
|
|
30
|
+
export declare function $isExcalidrawNode(node: LexicalNode | null): node is ExcalidrawNode;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import './ExcalidrawModal.css';
|
|
10
|
+
import { DecoratorNode } from 'lexical';
|
|
11
|
+
import { lazyRetry as lazy } from '@arcblock/ux/lib/Util';
|
|
12
|
+
import { Suspense } from 'react';
|
|
13
|
+
const ExcalidrawComponent = lazy(() => import('./ExcalidrawComponent'));
|
|
14
|
+
function convertExcalidrawElement(domNode) {
|
|
15
|
+
const excalidrawData = domNode.getAttribute('data-lexical-excalidraw-json');
|
|
16
|
+
if (excalidrawData) {
|
|
17
|
+
const node = $createExcalidrawNode();
|
|
18
|
+
node.__data = excalidrawData;
|
|
19
|
+
return {
|
|
20
|
+
node,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export class ExcalidrawNode extends DecoratorNode {
|
|
26
|
+
__data;
|
|
27
|
+
static getType() {
|
|
28
|
+
return 'excalidraw';
|
|
29
|
+
}
|
|
30
|
+
static clone(node) {
|
|
31
|
+
return new ExcalidrawNode(node.__data, node.__key);
|
|
32
|
+
}
|
|
33
|
+
static importJSON(serializedNode) {
|
|
34
|
+
return new ExcalidrawNode(serializedNode.data);
|
|
35
|
+
}
|
|
36
|
+
exportJSON() {
|
|
37
|
+
return {
|
|
38
|
+
data: this.__data,
|
|
39
|
+
type: 'excalidraw',
|
|
40
|
+
version: 1,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
constructor(data = '[]', key) {
|
|
44
|
+
super(key);
|
|
45
|
+
this.__data = data;
|
|
46
|
+
}
|
|
47
|
+
// View
|
|
48
|
+
createDOM(config) {
|
|
49
|
+
const span = document.createElement('span');
|
|
50
|
+
const { theme } = config;
|
|
51
|
+
span.className = `${theme.image ?? ''} ${theme.responsiveContainer ?? ''}`;
|
|
52
|
+
return span;
|
|
53
|
+
}
|
|
54
|
+
updateDOM() {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
static importDOM() {
|
|
58
|
+
return {
|
|
59
|
+
span: (domNode) => {
|
|
60
|
+
if (!domNode.hasAttribute('data-lexical-excalidraw-json')) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
conversion: convertExcalidrawElement,
|
|
65
|
+
priority: 1,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exportDOM(editor) {
|
|
71
|
+
const element = document.createElement('span');
|
|
72
|
+
const content = editor.getElementByKey(this.getKey());
|
|
73
|
+
if (content !== null) {
|
|
74
|
+
const svg = content.querySelector('svg');
|
|
75
|
+
if (svg !== null) {
|
|
76
|
+
element.innerHTML = svg.outerHTML;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
element.setAttribute('data-lexical-excalidraw-json', this.__data);
|
|
80
|
+
return { element };
|
|
81
|
+
}
|
|
82
|
+
setData(data) {
|
|
83
|
+
const self = this.getWritable();
|
|
84
|
+
self.__data = data;
|
|
85
|
+
}
|
|
86
|
+
decorate(editor, config) {
|
|
87
|
+
return (_jsx(Suspense, { fallback: null, children: _jsx(ExcalidrawComponent, { nodeKey: this.getKey(), data: this.__data }) }));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function $createExcalidrawNode() {
|
|
91
|
+
return new ExcalidrawNode();
|
|
92
|
+
}
|
|
93
|
+
export function $isExcalidrawNode(node) {
|
|
94
|
+
return node instanceof ExcalidrawNode;
|
|
95
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const getBlockletMountPointInfo: (name: string) => any;
|
|
2
|
+
export declare function isLocalImage(src: string): boolean;
|
|
3
|
+
export declare function joinImageUrl(src: string): string;
|
|
4
|
+
export declare function uploadImageToMediaKit(elements: any, files: any): Promise<void>;
|
|
5
|
+
export declare function covertImageWithMediaKitPath(elements: any, files: any): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { joinURL } from 'ufo';
|
|
2
|
+
// chain promise
|
|
3
|
+
const runPromiseInSequence = (list, fn) => {
|
|
4
|
+
return list.reduce((p, item) => {
|
|
5
|
+
return p.then(() => fn(item));
|
|
6
|
+
}, Promise.resolve()); // initial
|
|
7
|
+
};
|
|
8
|
+
export const getBlockletMountPointInfo = (name) => {
|
|
9
|
+
return window.blocklet?.componentMountPoints?.find((x) => x.name === name || x.did === name);
|
|
10
|
+
};
|
|
11
|
+
export function isLocalImage(src) {
|
|
12
|
+
return src.startsWith('data:image') || src.startsWith('blob:');
|
|
13
|
+
}
|
|
14
|
+
export function joinImageUrl(src) {
|
|
15
|
+
if (src?.startsWith('http')) {
|
|
16
|
+
return src;
|
|
17
|
+
}
|
|
18
|
+
// media kit
|
|
19
|
+
// const mountPoint = getBlockletMountPointInfo('z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9');
|
|
20
|
+
// discuss kit
|
|
21
|
+
const mountPoint = getBlockletMountPointInfo('did-comments')?.mountPoint;
|
|
22
|
+
if (mountPoint) {
|
|
23
|
+
const prefix = joinURL(window.location.origin, mountPoint, 'uploads');
|
|
24
|
+
// not add prefix
|
|
25
|
+
if (!src.startsWith(prefix)) {
|
|
26
|
+
return joinURL(prefix, src);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return src;
|
|
30
|
+
}
|
|
31
|
+
export async function uploadImageToMediaKit(elements, files) {
|
|
32
|
+
const filteredImages = elements?.filter((el) => el.type === 'image');
|
|
33
|
+
if (filteredImages.length > 0) {
|
|
34
|
+
// upload image to Media Kit
|
|
35
|
+
await runPromiseInSequence(filteredImages, async (el) => {
|
|
36
|
+
const fileItem = files[el.fileId];
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const uploader = window?.uploaderRef?.current?.getUploader?.();
|
|
39
|
+
const prefix = joinImageUrl('/');
|
|
40
|
+
// if not uploaded yet and is has uploader
|
|
41
|
+
if (isLocalImage(fileItem.dataURL) && !!uploader) {
|
|
42
|
+
// try to upload the image
|
|
43
|
+
const blobFile = await fetch(fileItem.dataURL).then((res) => res.blob());
|
|
44
|
+
const { data } = await uploader.uploadFile(blobFile).then((result) => {
|
|
45
|
+
// https://uppy.io/docs/uppy/#options
|
|
46
|
+
return result?.response;
|
|
47
|
+
});
|
|
48
|
+
// only save filename
|
|
49
|
+
files[el.fileId].dataURL = data.filename;
|
|
50
|
+
}
|
|
51
|
+
else if (fileItem.dataURL?.startsWith(prefix)) {
|
|
52
|
+
// remove the prefix
|
|
53
|
+
files[el.fileId].dataURL = fileItem.dataURL.replace(prefix, '');
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// promise all to chain the upload
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function covertImageWithMediaKitPath(elements, files) {
|
|
60
|
+
const filteredImages = elements?.filter((el) => el.type === 'image') || [];
|
|
61
|
+
if (filteredImages?.length > 0) {
|
|
62
|
+
// upload image to Media Kit
|
|
63
|
+
filteredImages.forEach((el) => {
|
|
64
|
+
const fileItem = files[el.fileId];
|
|
65
|
+
if (!isLocalImage(fileItem.dataURL)) {
|
|
66
|
+
// replace dataURL with Media Kit URL
|
|
67
|
+
files[el.fileId].dataURL = joinImageUrl(fileItem.dataURL);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { EditorConfig, ElementFormatType, LexicalEditor, LexicalNode, NodeKey, Spread } from 'lexical';
|
|
9
|
+
import { DecoratorBlockNode, SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
10
|
+
import type { JSX } from 'react';
|
|
11
|
+
export type SerializedFigmaNode = Spread<{
|
|
12
|
+
documentID: string;
|
|
13
|
+
type: 'figma';
|
|
14
|
+
version: 1;
|
|
15
|
+
}, SerializedDecoratorBlockNode>;
|
|
16
|
+
export declare class FigmaNode extends DecoratorBlockNode {
|
|
17
|
+
__id: string;
|
|
18
|
+
static getType(): string;
|
|
19
|
+
static clone(node: FigmaNode): FigmaNode;
|
|
20
|
+
static importJSON(serializedNode: SerializedFigmaNode): FigmaNode;
|
|
21
|
+
exportJSON(): SerializedFigmaNode;
|
|
22
|
+
constructor(id: string, format?: ElementFormatType, key?: NodeKey);
|
|
23
|
+
updateDOM(): false;
|
|
24
|
+
getId(): string;
|
|
25
|
+
getTextContent(_includeInert?: boolean | undefined, _includeDirectionless?: false | undefined): string;
|
|
26
|
+
decorate(_editor: LexicalEditor, config: EditorConfig): JSX.Element;
|
|
27
|
+
isInline(): false;
|
|
28
|
+
}
|
|
29
|
+
export declare function $createFigmaNode(documentID: string): FigmaNode;
|
|
30
|
+
export declare function $isFigmaNode(node: FigmaNode | LexicalNode | null | undefined): node is FigmaNode;
|