@scottjgilbert/lexical-blog-editor 0.1.4 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -67
- package/build/Editor.d.ts +8 -3
- package/build/Editor.d.ts.map +1 -1
- package/build/Editor.js +13 -8
- package/build/EditorExport.d.ts +4 -0
- package/build/EditorExport.d.ts.map +1 -0
- package/build/EditorExport.js +13 -0
- package/build/appSettings.d.ts +1 -1
- package/build/appSettings.js +1 -1
- package/build/buildHTMLConfig.d.ts +1 -1
- package/build/buildHTMLConfig.d.ts.map +1 -1
- package/build/buildHTMLConfig.js +35 -11
- package/build/context/FlashMessageContext.d.ts +2 -2
- package/build/context/FlashMessageContext.d.ts.map +1 -1
- package/build/context/FlashMessageContext.js +4 -3
- package/build/context/SharedHistoryContext.d.ts +3 -3
- package/build/context/SharedHistoryContext.d.ts.map +1 -1
- package/build/context/SharedHistoryContext.js +3 -2
- package/build/context/ToolbarContext.d.ts +1 -0
- package/build/context/ToolbarContext.d.ts.map +1 -1
- package/build/context/ToolbarContext.js +2 -0
- package/build/hooks/useModal.d.ts.map +1 -1
- package/build/hooks/useModal.js +1 -0
- package/build/hooks/useReport.d.ts +0 -7
- package/build/hooks/useReport.d.ts.map +1 -1
- package/build/hooks/useReport.js +1 -0
- package/build/index.css +283 -246
- package/build/index.d.ts +3 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/nodes/CodeNode/CodeHighlightNode.d.ts +35 -0
- package/build/nodes/CodeNode/CodeHighlightNode.d.ts.map +1 -0
- package/build/nodes/CodeNode/CodeHighlightNode.js +88 -0
- package/build/nodes/CodeNode/CodeHighlighterShiki.d.ts +22 -0
- package/build/nodes/CodeNode/CodeHighlighterShiki.d.ts.map +1 -0
- package/build/nodes/CodeNode/CodeHighlighterShiki.js +644 -0
- package/build/nodes/CodeNode/CodeNode.d.ts +48 -0
- package/build/nodes/CodeNode/CodeNode.d.ts.map +1 -0
- package/build/nodes/CodeNode/CodeNode.js +367 -0
- package/build/nodes/CodeNode/FacadeShiki.d.ts +18 -0
- package/build/nodes/CodeNode/FacadeShiki.d.ts.map +1 -0
- package/build/nodes/CodeNode/FacadeShiki.js +159 -0
- package/build/nodes/CodeNode/FlatStructureUtils.d.ts +21 -0
- package/build/nodes/CodeNode/FlatStructureUtils.d.ts.map +1 -0
- package/build/nodes/CodeNode/FlatStructureUtils.js +85 -0
- package/build/nodes/CodeNode/invariant.d.ts +2 -0
- package/build/nodes/CodeNode/invariant.d.ts.map +1 -0
- package/build/nodes/CodeNode/invariant.js +6 -0
- package/build/nodes/DateTimeNode/DateTimeComponent.d.ts.map +1 -1
- package/build/nodes/DateTimeNode/DateTimeComponent.js +1 -0
- package/build/nodes/DateTimeNode/DateTimeNode.css +21 -0
- package/build/nodes/FigmaNode/FigmaNode.d.ts.map +1 -0
- package/build/nodes/FigmaNode/ServerFigmaNode.d.ts +21 -0
- package/build/nodes/FigmaNode/ServerFigmaNode.d.ts.map +1 -0
- package/build/nodes/FigmaNode/ServerFigmaNode.js +48 -0
- package/build/nodes/ImageComponent.d.ts.map +1 -1
- package/build/nodes/ImageComponent.js +1 -2
- package/build/nodes/ImageNode.d.ts +7 -7
- package/build/nodes/ImageNode.d.ts.map +1 -1
- package/build/nodes/ImageNode.js +30 -30
- package/build/nodes/LayoutContainerNode.d.ts +2 -2
- package/build/nodes/LayoutContainerNode.d.ts.map +1 -1
- package/build/nodes/LayoutContainerNode.js +10 -10
- package/build/nodes/PlaygroundNodes/PlaygroundNodes.d.ts.map +1 -0
- package/build/nodes/{PlaygroundNodes.js → PlaygroundNodes/PlaygroundNodes.js} +19 -21
- package/build/nodes/PlaygroundNodes/ServerPlaygroundNodes.d.ts +11 -0
- package/build/nodes/PlaygroundNodes/ServerPlaygroundNodes.d.ts.map +1 -0
- package/build/nodes/PlaygroundNodes/ServerPlaygroundNodes.js +65 -0
- package/build/nodes/TweetNode/ServerTweetNode.d.ts +20 -0
- package/build/nodes/TweetNode/ServerTweetNode.d.ts.map +1 -0
- package/build/nodes/TweetNode/ServerTweetNode.js +59 -0
- package/build/nodes/TweetNode/TweetNode.d.ts.map +1 -0
- package/build/nodes/YouTubeNode/ServerYouTubeNode.d.ts +21 -0
- package/build/nodes/YouTubeNode/ServerYouTubeNode.d.ts.map +1 -0
- package/build/nodes/YouTubeNode/ServerYouTubeNode.js +67 -0
- package/build/nodes/YouTubeNode/YouTubeNode.d.ts.map +1 -0
- package/build/plugins/ActionsPlugin/index.d.ts +0 -7
- package/build/plugins/ActionsPlugin/index.d.ts.map +1 -1
- package/build/plugins/ActionsPlugin/index.js +2 -1
- package/build/plugins/AutoEmbedPlugin/index.d.ts +2 -9
- package/build/plugins/AutoEmbedPlugin/index.d.ts.map +1 -1
- package/build/plugins/AutoEmbedPlugin/index.js +30 -29
- package/build/plugins/AutoLinkPlugin/index.d.ts +1 -1
- package/build/plugins/AutoLinkPlugin/index.d.ts.map +1 -1
- package/build/plugins/AutoLinkPlugin/index.js +3 -2
- package/build/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +1 -1
- package/build/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts.map +1 -1
- package/build/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +7 -6
- package/build/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +2 -2
- package/build/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts.map +1 -1
- package/build/plugins/CodeActionMenuPlugin/components/PrettierButton/index.js +25 -24
- package/build/plugins/CodeActionMenuPlugin/index.d.ts +2 -9
- package/build/plugins/CodeActionMenuPlugin/index.d.ts.map +1 -1
- package/build/plugins/CodeActionMenuPlugin/index.js +22 -20
- package/build/plugins/CodeActionMenuPlugin/utils.d.ts.map +1 -1
- package/build/plugins/CodeActionMenuPlugin/utils.js +3 -2
- package/build/plugins/CodeHighlightPrismPlugin/index.d.ts +1 -1
- package/build/plugins/CodeHighlightPrismPlugin/index.d.ts.map +1 -1
- package/build/plugins/CodeHighlightPrismPlugin/index.js +4 -10
- package/build/plugins/CodeHighlightShikiPlugin/index.d.ts +1 -1
- package/build/plugins/CodeHighlightShikiPlugin/index.d.ts.map +1 -1
- package/build/plugins/CodeHighlightShikiPlugin/index.js +3 -3
- package/build/plugins/CollapsiblePlugin/Collapsible.css +17 -1
- package/build/plugins/CollapsiblePlugin/index.d.ts +1 -1
- package/build/plugins/CollapsiblePlugin/index.d.ts.map +1 -1
- package/build/plugins/CollapsiblePlugin/index.js +11 -10
- package/build/plugins/ComponentPickerPlugin/index.d.ts.map +1 -1
- package/build/plugins/ComponentPickerPlugin/index.js +3 -8
- package/build/plugins/ContextMenuPlugin/index.d.ts +1 -1
- package/build/plugins/ContextMenuPlugin/index.d.ts.map +1 -1
- package/build/plugins/ContextMenuPlugin/index.js +15 -14
- package/build/plugins/DateTimePlugin/index.d.ts +2 -2
- package/build/plugins/DateTimePlugin/index.d.ts.map +1 -1
- package/build/plugins/DateTimePlugin/index.js +8 -14
- package/build/plugins/DragDropPastePlugin/index.d.ts +0 -7
- package/build/plugins/DragDropPastePlugin/index.d.ts.map +1 -1
- package/build/plugins/DragDropPastePlugin/index.js +12 -11
- package/build/plugins/DraggableBlockPlugin/index.css +6 -0
- package/build/plugins/DraggableBlockPlugin/index.d.ts +2 -2
- package/build/plugins/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/build/plugins/DraggableBlockPlugin/index.js +23 -22
- package/build/plugins/EmojiPickerPlugin/index.d.ts +0 -7
- package/build/plugins/EmojiPickerPlugin/index.d.ts.map +1 -1
- package/build/plugins/EmojiPickerPlugin/index.js +1 -0
- package/build/plugins/EmojisPlugin/index.d.ts +1 -8
- package/build/plugins/EmojisPlugin/index.d.ts.map +1 -1
- package/build/plugins/EmojisPlugin/index.js +10 -16
- package/build/plugins/EquationsPlugin/index.d.ts +3 -3
- package/build/plugins/EquationsPlugin/index.d.ts.map +1 -1
- package/build/plugins/EquationsPlugin/index.js +14 -10
- package/build/plugins/FigmaPlugin/index.d.ts +2 -2
- package/build/plugins/FigmaPlugin/index.d.ts.map +1 -1
- package/build/plugins/FigmaPlugin/index.js +8 -14
- package/build/plugins/FloatingLinkEditorPlugin/index.css +11 -0
- package/build/plugins/FloatingLinkEditorPlugin/index.d.ts +3 -3
- package/build/plugins/FloatingLinkEditorPlugin/index.d.ts.map +1 -1
- package/build/plugins/FloatingLinkEditorPlugin/index.js +28 -27
- package/build/plugins/FloatingTextFormatToolbarPlugin/index.css +15 -0
- package/build/plugins/FloatingTextFormatToolbarPlugin/index.d.ts.map +1 -1
- package/build/plugins/FloatingTextFormatToolbarPlugin/index.js +2 -1
- package/build/plugins/ImagesPlugin/index.d.ts +3 -3
- package/build/plugins/ImagesPlugin/index.d.ts.map +1 -1
- package/build/plugins/ImagesPlugin/index.js +38 -37
- package/build/plugins/KeywordsPlugin/index.d.ts +1 -8
- package/build/plugins/KeywordsPlugin/index.d.ts.map +1 -1
- package/build/plugins/KeywordsPlugin/index.js +6 -12
- package/build/plugins/LayoutPlugin/InsertLayoutDialog.d.ts +2 -2
- package/build/plugins/LayoutPlugin/InsertLayoutDialog.d.ts.map +1 -1
- package/build/plugins/LayoutPlugin/InsertLayoutDialog.js +10 -9
- package/build/plugins/LayoutPlugin/LayoutPlugin.d.ts +1 -1
- package/build/plugins/LayoutPlugin/LayoutPlugin.d.ts.map +1 -1
- package/build/plugins/LayoutPlugin/LayoutPlugin.js +8 -14
- package/build/plugins/LinkPlugin/index.d.ts.map +1 -1
- package/build/plugins/LinkPlugin/index.js +1 -0
- package/build/plugins/MarkdownShortcutPlugin/index.d.ts.map +1 -1
- package/build/plugins/MarkdownShortcutPlugin/index.js +1 -0
- package/build/plugins/MarkdownTransformers/index.d.ts +1 -1
- package/build/plugins/MarkdownTransformers/index.d.ts.map +1 -1
- package/build/plugins/MarkdownTransformers/index.js +25 -25
- package/build/plugins/PasteLogPlugin/index.d.ts.map +1 -1
- package/build/plugins/PasteLogPlugin/index.js +1 -0
- package/build/plugins/ShortcutsPlugin/index.d.ts +0 -7
- package/build/plugins/ShortcutsPlugin/index.d.ts.map +1 -1
- package/build/plugins/ShortcutsPlugin/index.js +1 -0
- package/build/plugins/SpeechToTextPlugin/index.d.ts +2 -2
- package/build/plugins/SpeechToTextPlugin/index.d.ts.map +1 -1
- package/build/plugins/SpeechToTextPlugin/index.js +7 -11
- package/build/plugins/TabFocusPlugin/index.d.ts +0 -7
- package/build/plugins/TabFocusPlugin/index.d.ts.map +1 -1
- package/build/plugins/TabFocusPlugin/index.js +6 -5
- package/build/plugins/TableActionMenuPlugin/index.d.ts +1 -8
- package/build/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
- package/build/plugins/TableActionMenuPlugin/index.js +41 -40
- package/build/plugins/TableCellResizer/index.d.ts +2 -2
- package/build/plugins/TableCellResizer/index.d.ts.map +1 -1
- package/build/plugins/TableCellResizer/index.js +43 -42
- package/build/plugins/TableHoverActionsPlugin/index.d.ts +1 -8
- package/build/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
- package/build/plugins/TableHoverActionsPlugin/index.js +19 -18
- package/build/plugins/TableHoverActionsV2Plugin/index.d.ts.map +1 -1
- package/build/plugins/TableHoverActionsV2Plugin/index.js +1 -0
- package/build/plugins/TablePlugin.d.ts +2 -2
- package/build/plugins/TablePlugin.d.ts.map +1 -1
- package/build/plugins/TablePlugin.js +11 -10
- package/build/plugins/TableScrollShadowPlugin/index.d.ts +0 -7
- package/build/plugins/TableScrollShadowPlugin/index.d.ts.map +1 -1
- package/build/plugins/TableScrollShadowPlugin/index.js +9 -8
- package/build/plugins/TestRecorderPlugin/index.d.ts +1 -8
- package/build/plugins/TestRecorderPlugin/index.d.ts.map +1 -1
- package/build/plugins/TestRecorderPlugin/index.js +45 -44
- package/build/plugins/ToolbarPlugin/fontSize.d.ts +2 -2
- package/build/plugins/ToolbarPlugin/fontSize.d.ts.map +1 -1
- package/build/plugins/ToolbarPlugin/fontSize.js +19 -18
- package/build/plugins/ToolbarPlugin/index.d.ts.map +1 -1
- package/build/plugins/ToolbarPlugin/index.js +68 -60
- package/build/plugins/ToolbarPlugin/languages.d.ts +14 -0
- package/build/plugins/ToolbarPlugin/languages.d.ts.map +1 -0
- package/build/plugins/ToolbarPlugin/languages.js +185 -0
- package/build/plugins/ToolbarPlugin/utils.d.ts +2 -2
- package/build/plugins/ToolbarPlugin/utils.js +21 -21
- package/build/plugins/TwitterPlugin/index.d.ts +2 -2
- package/build/plugins/TwitterPlugin/index.d.ts.map +1 -1
- package/build/plugins/TwitterPlugin/index.js +8 -14
- package/build/plugins/YouTubePlugin/index.d.ts +2 -2
- package/build/plugins/YouTubePlugin/index.d.ts.map +1 -1
- package/build/plugins/YouTubePlugin/index.js +8 -14
- package/build/themes/PlaygroundEditorTheme.css +301 -33
- package/build/themes/ViewerTheme.css +899 -0
- package/build/{plugins/MentionsPlugin/index.d.ts → themes/ViewerTheme.d.ts} +5 -3
- package/build/themes/ViewerTheme.d.ts.map +1 -0
- package/build/themes/ViewerTheme.js +124 -0
- package/build/themes/ViewerThemeComplete.css +1043 -0
- package/build/ui/ColorPicker.d.ts +2 -2
- package/build/ui/ColorPicker.d.ts.map +1 -1
- package/build/ui/ColorPicker.js +47 -46
- package/build/ui/DropDown.d.ts.map +1 -1
- package/build/ui/DropDown.js +1 -0
- package/build/ui/FlashMessage.d.ts +3 -3
- package/build/ui/FlashMessage.d.ts.map +1 -1
- package/build/ui/FlashMessage.js +3 -2
- package/build/ui/ImageResizer.d.ts +3 -3
- package/build/ui/ImageResizer.d.ts.map +1 -1
- package/build/ui/ImageResizer.js +20 -19
- package/build/ui/KatexEquationAlterer.css +3 -1
- package/build/ui/KatexEquationAlterer.d.ts.map +1 -1
- package/build/ui/KatexEquationAlterer.js +1 -0
- package/build/ui/KatexRenderer.d.ts.map +1 -1
- package/build/ui/KatexRenderer.js +1 -0
- package/build/ui/Modal.d.ts.map +1 -1
- package/build/ui/Modal.js +1 -0
- package/build/ui/Switch.d.ts +2 -2
- package/build/ui/Switch.d.ts.map +1 -1
- package/build/ui/Switch.js +3 -2
- package/build/ui/TextInput.d.ts.map +1 -1
- package/build/ui/TextInput.js +1 -0
- package/build/utils/ServerBlockWithAlignableContents.d.ts +22 -0
- package/build/utils/ServerBlockWithAlignableContents.d.ts.map +1 -0
- package/build/utils/ServerBlockWithAlignableContents.js +6 -0
- package/build/utils/focusUtils.d.ts.map +1 -1
- package/build/utils/focusUtils.js +4 -3
- package/build/utils/getDOMRangeRect.d.ts.map +1 -1
- package/build/utils/getDOMRangeRect.js +1 -0
- package/build/utils/setFloatingElemPosition.d.ts.map +1 -1
- package/build/utils/setFloatingElemPosition.js +5 -4
- package/build/utils/swipe.d.ts +0 -7
- package/build/utils/swipe.d.ts.map +1 -1
- package/build/utils/swipe.js +5 -11
- package/build/viewer/Viewer.d.ts +18 -0
- package/build/viewer/Viewer.d.ts.map +1 -0
- package/build/viewer/Viewer.js +105 -0
- package/build/viewer/client.d.ts +18 -0
- package/build/viewer/client.d.ts.map +1 -0
- package/build/viewer/client.js +97 -0
- package/build/viewer/index.d.ts +4 -0
- package/build/viewer/index.d.ts.map +1 -0
- package/build/viewer/index.js +2 -0
- package/package.json +58 -36
- package/build/collaboration.d.ts +0 -12
- package/build/collaboration.d.ts.map +0 -1
- package/build/collaboration.js +0 -32
- package/build/nodes/FigmaNode.d.ts.map +0 -1
- package/build/nodes/PageBreakNode/index.css +0 -64
- package/build/nodes/PageBreakNode/index.d.ts +0 -25
- package/build/nodes/PageBreakNode/index.d.ts.map +0 -1
- package/build/nodes/PageBreakNode/index.js +0 -83
- package/build/nodes/PlaygroundNodes.d.ts.map +0 -1
- package/build/nodes/PollComponent.d.ts +0 -17
- package/build/nodes/PollComponent.d.ts.map +0 -1
- package/build/nodes/PollComponent.js +0 -85
- package/build/nodes/PollNode.css +0 -165
- package/build/nodes/PollNode.d.ts +0 -51
- package/build/nodes/PollNode.d.ts.map +0 -1
- package/build/nodes/PollNode.js +0 -153
- package/build/nodes/StickyComponent.d.ts +0 -18
- package/build/nodes/StickyComponent.d.ts.map +0 -1
- package/build/nodes/StickyComponent.js +0 -155
- package/build/nodes/StickyNode.css +0 -37
- package/build/nodes/StickyNode.d.ts +0 -39
- package/build/nodes/StickyNode.d.ts.map +0 -1
- package/build/nodes/StickyNode.js +0 -66
- package/build/nodes/TweetNode.d.ts.map +0 -1
- package/build/nodes/YouTubeNode.d.ts.map +0 -1
- package/build/plugins/DocsPlugin/index.d.ts +0 -10
- package/build/plugins/DocsPlugin/index.d.ts.map +0 -1
- package/build/plugins/DocsPlugin/index.js +0 -4
- package/build/plugins/MaxLengthPlugin/index.d.ts +0 -11
- package/build/plugins/MaxLengthPlugin/index.d.ts.map +0 -1
- package/build/plugins/MaxLengthPlugin/index.js +0 -44
- package/build/plugins/MentionsPlugin/index.d.ts.map +0 -1
- package/build/plugins/MentionsPlugin/index.js +0 -562
- package/build/plugins/PageBreakPlugin/index.d.ts +0 -12
- package/build/plugins/PageBreakPlugin/index.d.ts.map +0 -1
- package/build/plugins/PageBreakPlugin/index.js +0 -34
- package/build/plugins/StickyPlugin/index.d.ts +0 -10
- package/build/plugins/StickyPlugin/index.d.ts.map +0 -1
- package/build/plugins/StickyPlugin/index.js +0 -19
- package/build/plugins/TreeViewPlugin/index.d.ts +0 -10
- package/build/plugins/TreeViewPlugin/index.d.ts.map +0 -1
- package/build/plugins/TreeViewPlugin/index.js +0 -7
- package/build/plugins/TypingPerfPlugin/index.d.ts +0 -10
- package/build/plugins/TypingPerfPlugin/index.d.ts.map +0 -1
- package/build/plugins/TypingPerfPlugin/index.js +0 -100
- package/build/plugins/VersionsPlugin/index.css +0 -57
- package/build/plugins/VersionsPlugin/index.d.ts +0 -14
- package/build/plugins/VersionsPlugin/index.d.ts.map +0 -1
- package/build/plugins/VersionsPlugin/index.js +0 -147
- /package/build/nodes/{FigmaNode.d.ts → FigmaNode/FigmaNode.d.ts} +0 -0
- /package/build/nodes/{FigmaNode.js → FigmaNode/FigmaNode.js} +0 -0
- /package/build/nodes/{PlaygroundNodes.d.ts → PlaygroundNodes/PlaygroundNodes.d.ts} +0 -0
- /package/build/nodes/{TweetNode.d.ts → TweetNode/TweetNode.d.ts} +0 -0
- /package/build/nodes/{TweetNode.js → TweetNode/TweetNode.js} +0 -0
- /package/build/nodes/{YouTubeNode.d.ts → YouTubeNode/YouTubeNode.d.ts} +0 -0
- /package/build/nodes/{YouTubeNode.js → YouTubeNode/YouTubeNode.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeNode.d.ts","sourceRoot":"","sources":["../../../src/nodes/CodeNode/CodeNode.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EACV,gBAAgB,EAEhB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,OAAO,EACR,MAAM,SAAS,CAAC;AAGjB,OAAO,EAOL,WAAW,EACZ,MAAM,SAAS,CAAC;AAQjB,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACrC;IACE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,EACD,qBAAqB,CACtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAClD,eAAO,MAAM,sBAAsB,QAAO,MAA+B,CAAC;AAgB1E,oBAAoB;AACpB,qBAAa,QAAS,SAAQ,WAAW;IACvC,gBAAgB;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACtC,gBAAgB;IAChB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,gBAAgB;IAChB,4BAA4B,EAAE,OAAO,CAAC;IAEtC,MAAM,CAAC,OAAO,IAAI,MAAM;IAIxB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ;gBAI1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,OAAO;IAO/D,cAAc,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI;IAQpC,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW;IAuB5C,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO;IAoD1E,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe;IAyBjD,MAAM,CAAC,SAAS,IAAI,gBAAgB,GAAG,IAAI;IAmE3C,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,kBAAkB,GAAG,QAAQ;IAI/D,cAAc,CAAC,cAAc,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,GAAG,IAAI;IAO3E,UAAU,IAAI,kBAAkB;IAShC,cAAc,CACZ,SAAS,EAAE,cAAc,EACzB,gBAAgB,UAAO,GACtB,IAAI,GAAG,aAAa,GAAG,iBAAiB,GAAG,OAAO;IA4ErD,SAAS,IAAI,KAAK;IAIlB,eAAe,IAAI,OAAO;IAQ1B,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAMtD,WAAW,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS;IAIxC,6BAA6B,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI;IAMzD,6BAA6B,IAAI,OAAO;IAIxC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAMhD,QAAQ,IAAI,MAAM,GAAG,SAAS;CAG/B;AAED,wBAAgB,eAAe,CAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAChC,QAAQ,CAEV;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,QAAQ,CAElB"}
|
|
@@ -0,0 +1,367 @@
|
|
|
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 { addClassNamesToElement, isHTMLElement } from "@lexical/utils";
|
|
9
|
+
import { $create, $createLineBreakNode, $createParagraphNode, $createTabNode, $isTabNode, $isTextNode, ElementNode, } from "lexical";
|
|
10
|
+
import { $createCodeHighlightNode, $isCodeHighlightNode, } from "./CodeHighlightNode";
|
|
11
|
+
import { $getFirstCodeNodeOfLine } from "./FlatStructureUtils";
|
|
12
|
+
export const DEFAULT_CODE_LANGUAGE = "javascript";
|
|
13
|
+
export const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
14
|
+
function hasChildDOMNodeTag(node, tagName) {
|
|
15
|
+
for (const child of node.childNodes) {
|
|
16
|
+
if (isHTMLElement(child) && child.tagName === tagName) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
hasChildDOMNodeTag(child, tagName);
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const LANGUAGE_DATA_ATTRIBUTE = "data-language";
|
|
24
|
+
const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = "data-highlight-language";
|
|
25
|
+
const THEME_DATA_ATTRIBUTE = "data-theme";
|
|
26
|
+
/** @noInheritDoc */
|
|
27
|
+
export class CodeNode extends ElementNode {
|
|
28
|
+
static getType() {
|
|
29
|
+
return "code";
|
|
30
|
+
}
|
|
31
|
+
static clone(node) {
|
|
32
|
+
return new CodeNode(node.__language, node.__key);
|
|
33
|
+
}
|
|
34
|
+
constructor(language, key) {
|
|
35
|
+
super(key);
|
|
36
|
+
this.__language = language || undefined;
|
|
37
|
+
this.__isSyntaxHighlightSupported = false;
|
|
38
|
+
this.__theme = undefined;
|
|
39
|
+
}
|
|
40
|
+
afterCloneFrom(prevNode) {
|
|
41
|
+
super.afterCloneFrom(prevNode);
|
|
42
|
+
this.__language = prevNode.__language;
|
|
43
|
+
this.__theme = prevNode.__theme;
|
|
44
|
+
this.__isSyntaxHighlightSupported = prevNode.__isSyntaxHighlightSupported;
|
|
45
|
+
}
|
|
46
|
+
// View
|
|
47
|
+
createDOM(config) {
|
|
48
|
+
const element = document.createElement("code");
|
|
49
|
+
addClassNamesToElement(element, config.theme.code);
|
|
50
|
+
element.setAttribute("spellcheck", "false");
|
|
51
|
+
const language = this.getLanguage();
|
|
52
|
+
if (language) {
|
|
53
|
+
element.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
|
|
54
|
+
if (this.getIsSyntaxHighlightSupported()) {
|
|
55
|
+
element.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const theme = this.getTheme();
|
|
59
|
+
if (theme) {
|
|
60
|
+
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
61
|
+
}
|
|
62
|
+
const style = this.getStyle();
|
|
63
|
+
if (style) {
|
|
64
|
+
element.setAttribute("style", style);
|
|
65
|
+
}
|
|
66
|
+
return element;
|
|
67
|
+
}
|
|
68
|
+
updateDOM(prevNode, dom, config) {
|
|
69
|
+
const language = this.__language;
|
|
70
|
+
const prevLanguage = prevNode.__language;
|
|
71
|
+
if (language) {
|
|
72
|
+
if (language !== prevLanguage) {
|
|
73
|
+
dom.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (prevLanguage) {
|
|
77
|
+
dom.removeAttribute(LANGUAGE_DATA_ATTRIBUTE);
|
|
78
|
+
}
|
|
79
|
+
const isSyntaxHighlightSupported = this.__isSyntaxHighlightSupported;
|
|
80
|
+
const prevIsSyntaxHighlightSupported = prevNode.__isSyntaxHighlightSupported;
|
|
81
|
+
if (prevIsSyntaxHighlightSupported && prevLanguage) {
|
|
82
|
+
if (isSyntaxHighlightSupported && language) {
|
|
83
|
+
if (language !== prevLanguage) {
|
|
84
|
+
dom.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
dom.removeAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (isSyntaxHighlightSupported && language) {
|
|
92
|
+
dom.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
93
|
+
}
|
|
94
|
+
const theme = this.__theme;
|
|
95
|
+
const prevTheme = prevNode.__theme;
|
|
96
|
+
if (theme) {
|
|
97
|
+
if (theme !== prevTheme) {
|
|
98
|
+
dom.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (prevTheme) {
|
|
102
|
+
dom.removeAttribute(THEME_DATA_ATTRIBUTE);
|
|
103
|
+
}
|
|
104
|
+
const style = this.__style;
|
|
105
|
+
const prevStyle = prevNode.__style;
|
|
106
|
+
if (style) {
|
|
107
|
+
if (style !== prevStyle) {
|
|
108
|
+
dom.setAttribute("style", style);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (prevStyle) {
|
|
112
|
+
dom.removeAttribute("style");
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
exportDOM(editor) {
|
|
117
|
+
const element = document.createElement("pre");
|
|
118
|
+
addClassNamesToElement(element, editor._config.theme.code);
|
|
119
|
+
element.setAttribute("spellcheck", "false");
|
|
120
|
+
const language = this.getLanguage();
|
|
121
|
+
if (language) {
|
|
122
|
+
element.setAttribute(LANGUAGE_DATA_ATTRIBUTE, language);
|
|
123
|
+
if (this.getIsSyntaxHighlightSupported()) {
|
|
124
|
+
element.setAttribute(HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE, language);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const theme = this.getTheme();
|
|
128
|
+
if (theme) {
|
|
129
|
+
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
130
|
+
}
|
|
131
|
+
const style = this.getStyle();
|
|
132
|
+
if (style) {
|
|
133
|
+
element.setAttribute("style", style);
|
|
134
|
+
}
|
|
135
|
+
return { element };
|
|
136
|
+
}
|
|
137
|
+
static importDOM() {
|
|
138
|
+
return {
|
|
139
|
+
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
140
|
+
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
141
|
+
// inline format handled by TextNode otherwise.
|
|
142
|
+
code: (node) => {
|
|
143
|
+
const isMultiLine = node.textContent != null &&
|
|
144
|
+
(/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, "BR"));
|
|
145
|
+
return isMultiLine
|
|
146
|
+
? {
|
|
147
|
+
conversion: $convertPreElement,
|
|
148
|
+
priority: 1,
|
|
149
|
+
}
|
|
150
|
+
: null;
|
|
151
|
+
},
|
|
152
|
+
div: () => ({
|
|
153
|
+
conversion: $convertDivElement,
|
|
154
|
+
priority: 1,
|
|
155
|
+
}),
|
|
156
|
+
pre: () => ({
|
|
157
|
+
conversion: $convertPreElement,
|
|
158
|
+
priority: 0,
|
|
159
|
+
}),
|
|
160
|
+
table: (node) => {
|
|
161
|
+
const table = node;
|
|
162
|
+
// domNode is a <table> since we matched it by nodeName
|
|
163
|
+
if (isGitHubCodeTable(table)) {
|
|
164
|
+
return {
|
|
165
|
+
conversion: $convertTableElement,
|
|
166
|
+
priority: 3,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
},
|
|
171
|
+
td: (node) => {
|
|
172
|
+
// element is a <td> since we matched it by nodeName
|
|
173
|
+
const td = node;
|
|
174
|
+
const table = td.closest("table");
|
|
175
|
+
if (isGitHubCodeCell(td) || (table && isGitHubCodeTable(table))) {
|
|
176
|
+
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
177
|
+
// Otherwise it'll fall back to the T
|
|
178
|
+
return {
|
|
179
|
+
conversion: convertCodeNoop,
|
|
180
|
+
priority: 3,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
},
|
|
185
|
+
tr: (node) => {
|
|
186
|
+
// element is a <tr> since we matched it by nodeName
|
|
187
|
+
const tr = node;
|
|
188
|
+
const table = tr.closest("table");
|
|
189
|
+
if (table && isGitHubCodeTable(table)) {
|
|
190
|
+
return {
|
|
191
|
+
conversion: convertCodeNoop,
|
|
192
|
+
priority: 3,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
static importJSON(serializedNode) {
|
|
200
|
+
return $createCodeNode().updateFromJSON(serializedNode);
|
|
201
|
+
}
|
|
202
|
+
updateFromJSON(serializedNode) {
|
|
203
|
+
return super
|
|
204
|
+
.updateFromJSON(serializedNode)
|
|
205
|
+
.setLanguage(serializedNode.language)
|
|
206
|
+
.setTheme(serializedNode.theme);
|
|
207
|
+
}
|
|
208
|
+
exportJSON() {
|
|
209
|
+
return Object.assign(Object.assign({}, super.exportJSON()), { language: this.getLanguage(), theme: this.getTheme() });
|
|
210
|
+
}
|
|
211
|
+
// Mutation
|
|
212
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
213
|
+
const children = this.getChildren();
|
|
214
|
+
const childrenLength = children.length;
|
|
215
|
+
if (childrenLength >= 2 &&
|
|
216
|
+
children[childrenLength - 1].getTextContent() === "\n" &&
|
|
217
|
+
children[childrenLength - 2].getTextContent() === "\n" &&
|
|
218
|
+
selection.isCollapsed() &&
|
|
219
|
+
selection.anchor.key === this.__key &&
|
|
220
|
+
selection.anchor.offset === childrenLength) {
|
|
221
|
+
children[childrenLength - 1].remove();
|
|
222
|
+
children[childrenLength - 2].remove();
|
|
223
|
+
const newElement = $createParagraphNode();
|
|
224
|
+
this.insertAfter(newElement, restoreSelection);
|
|
225
|
+
return newElement;
|
|
226
|
+
}
|
|
227
|
+
// If the selection is within the codeblock, find all leading tabs and
|
|
228
|
+
// spaces of the current line. Create a new line that has all those
|
|
229
|
+
// tabs and spaces, such that leading indentation is preserved.
|
|
230
|
+
const { anchor, focus } = selection;
|
|
231
|
+
const firstPoint = anchor.isBefore(focus) ? anchor : focus;
|
|
232
|
+
const firstSelectionNode = firstPoint.getNode();
|
|
233
|
+
if ($isTextNode(firstSelectionNode)) {
|
|
234
|
+
let node = $getFirstCodeNodeOfLine(firstSelectionNode);
|
|
235
|
+
const insertNodes = [];
|
|
236
|
+
// eslint-disable-next-line no-constant-condition
|
|
237
|
+
while (true) {
|
|
238
|
+
if ($isTabNode(node)) {
|
|
239
|
+
insertNodes.push($createTabNode());
|
|
240
|
+
node = node.getNextSibling();
|
|
241
|
+
}
|
|
242
|
+
else if ($isCodeHighlightNode(node)) {
|
|
243
|
+
let spaces = 0;
|
|
244
|
+
const text = node.getTextContent();
|
|
245
|
+
const textSize = node.getTextContentSize();
|
|
246
|
+
while (spaces < textSize && text[spaces] === " ") {
|
|
247
|
+
spaces++;
|
|
248
|
+
}
|
|
249
|
+
if (spaces !== 0) {
|
|
250
|
+
insertNodes.push($createCodeHighlightNode(" ".repeat(spaces)));
|
|
251
|
+
}
|
|
252
|
+
if (spaces !== textSize) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
node = node.getNextSibling();
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const split = firstSelectionNode.splitText(anchor.offset)[0];
|
|
262
|
+
const x = anchor.offset === 0 ? 0 : 1;
|
|
263
|
+
const index = split.getIndexWithinParent() + x;
|
|
264
|
+
const codeNode = firstSelectionNode.getParentOrThrow();
|
|
265
|
+
const nodesToInsert = [$createLineBreakNode(), ...insertNodes];
|
|
266
|
+
codeNode.splice(index, 0, nodesToInsert);
|
|
267
|
+
const last = insertNodes[insertNodes.length - 1];
|
|
268
|
+
if (last) {
|
|
269
|
+
last.select();
|
|
270
|
+
}
|
|
271
|
+
else if (anchor.offset === 0) {
|
|
272
|
+
split.selectPrevious();
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
split.getNextSibling().selectNext(0, 0);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if ($isCodeNode(firstSelectionNode)) {
|
|
279
|
+
const { offset } = selection.anchor;
|
|
280
|
+
firstSelectionNode.splice(offset, 0, [$createLineBreakNode()]);
|
|
281
|
+
firstSelectionNode.select(offset + 1, offset + 1);
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
canIndent() {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
collapseAtStart() {
|
|
289
|
+
const paragraph = $createParagraphNode();
|
|
290
|
+
const children = this.getChildren();
|
|
291
|
+
children.forEach((child) => paragraph.append(child));
|
|
292
|
+
this.replace(paragraph);
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
setLanguage(language) {
|
|
296
|
+
const writable = this.getWritable();
|
|
297
|
+
writable.__language = language || undefined;
|
|
298
|
+
return writable;
|
|
299
|
+
}
|
|
300
|
+
getLanguage() {
|
|
301
|
+
return this.getLatest().__language;
|
|
302
|
+
}
|
|
303
|
+
setIsSyntaxHighlightSupported(isSupported) {
|
|
304
|
+
const writable = this.getWritable();
|
|
305
|
+
writable.__isSyntaxHighlightSupported = isSupported;
|
|
306
|
+
return writable;
|
|
307
|
+
}
|
|
308
|
+
getIsSyntaxHighlightSupported() {
|
|
309
|
+
return this.getLatest().__isSyntaxHighlightSupported;
|
|
310
|
+
}
|
|
311
|
+
setTheme(theme) {
|
|
312
|
+
const writable = this.getWritable();
|
|
313
|
+
writable.__theme = theme || undefined;
|
|
314
|
+
return writable;
|
|
315
|
+
}
|
|
316
|
+
getTheme() {
|
|
317
|
+
return this.getLatest().__theme;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
export function $createCodeNode(language, theme) {
|
|
321
|
+
return $create(CodeNode).setLanguage(language).setTheme(theme);
|
|
322
|
+
}
|
|
323
|
+
export function $isCodeNode(node) {
|
|
324
|
+
return (node === null || node === void 0 ? void 0 : node.__type) == "code";
|
|
325
|
+
}
|
|
326
|
+
function $convertPreElement(domNode) {
|
|
327
|
+
const language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE);
|
|
328
|
+
return { node: $createCodeNode(language) };
|
|
329
|
+
}
|
|
330
|
+
function $convertDivElement(domNode) {
|
|
331
|
+
// domNode is a <div> since we matched it by nodeName
|
|
332
|
+
const div = domNode;
|
|
333
|
+
const isCode = isCodeElement(div);
|
|
334
|
+
if (!isCode && !isCodeChildElement(div)) {
|
|
335
|
+
return {
|
|
336
|
+
node: null,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
node: isCode ? $createCodeNode() : null,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function $convertTableElement() {
|
|
344
|
+
return { node: $createCodeNode() };
|
|
345
|
+
}
|
|
346
|
+
function convertCodeNoop() {
|
|
347
|
+
return { node: null };
|
|
348
|
+
}
|
|
349
|
+
function isCodeElement(div) {
|
|
350
|
+
return div.style.fontFamily.match("monospace") !== null;
|
|
351
|
+
}
|
|
352
|
+
function isCodeChildElement(node) {
|
|
353
|
+
let parent = node.parentElement;
|
|
354
|
+
while (parent !== null) {
|
|
355
|
+
if (isCodeElement(parent)) {
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
parent = parent.parentElement;
|
|
359
|
+
}
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
function isGitHubCodeCell(cell) {
|
|
363
|
+
return cell.classList.contains("js-file-line");
|
|
364
|
+
}
|
|
365
|
+
function isGitHubCodeTable(table) {
|
|
366
|
+
return table.classList.contains("js-file-line-container");
|
|
367
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { CodeNode } from "./CodeNode";
|
|
9
|
+
import type { LexicalEditor, LexicalNode, NodeKey } from "lexical";
|
|
10
|
+
export declare function isCodeLanguageLoaded(language: string): boolean;
|
|
11
|
+
export declare function loadCodeLanguage(language: string, editor?: LexicalEditor, codeNodeKey?: NodeKey): Promise<void> | undefined;
|
|
12
|
+
export declare function isCodeThemeLoaded(theme: string): boolean;
|
|
13
|
+
export declare function loadCodeTheme(theme: string, editor?: LexicalEditor, codeNodeKey?: NodeKey): Promise<void> | undefined;
|
|
14
|
+
export declare function getCodeLanguageOptions(): [string, string][];
|
|
15
|
+
export declare function getCodeThemeOptions(): [string, string][];
|
|
16
|
+
export declare function normalizeCodeLanguage(language: string): string;
|
|
17
|
+
export declare function $getHighlightNodes(codeNode: CodeNode, language: string): LexicalNode[];
|
|
18
|
+
//# sourceMappingURL=FacadeShiki.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FacadeShiki.d.ts","sourceRoot":"","sources":["../../../src/nodes/CodeNode/FacadeShiki.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA4BnE,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,WAWpD;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,aAAa,EACtB,WAAW,CAAC,EAAE,OAAO,6BA8BtB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,WAS9C;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,aAAa,EACtB,WAAW,CAAC,EAAE,OAAO,6BAiBtB;AAED,wBAAgB,sBAAsB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAE3D;AACD,wBAAgB,mBAAmB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAExD;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAU9D;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,GACf,WAAW,EAAE,CAoBf"}
|
|
@@ -0,0 +1,159 @@
|
|
|
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 { $isCodeNode } from "./CodeNode";
|
|
9
|
+
import { $createCodeHighlightNode } from "./CodeHighlightNode";
|
|
10
|
+
import { createHighlighterCoreSync, getTokenStyleObject, isSpecialLang, isSpecialTheme, stringifyTokenStyle, } from "@shikijs/core";
|
|
11
|
+
import { createJavaScriptRegexEngine } from "@shikijs/engine-javascript";
|
|
12
|
+
import { $createLineBreakNode, $createTabNode, $getNodeByKey } from "lexical";
|
|
13
|
+
import { bundledLanguagesInfo } from "shiki/langs";
|
|
14
|
+
import { bundledThemesInfo } from "shiki/themes";
|
|
15
|
+
const shiki = createHighlighterCoreSync({
|
|
16
|
+
engine: createJavaScriptRegexEngine(),
|
|
17
|
+
langs: [],
|
|
18
|
+
themes: [],
|
|
19
|
+
});
|
|
20
|
+
function getDiffedLanguage(language) {
|
|
21
|
+
const DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
|
|
22
|
+
const diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
|
|
23
|
+
return diffLanguageMatch ? diffLanguageMatch[1] : null;
|
|
24
|
+
}
|
|
25
|
+
export function isCodeLanguageLoaded(language) {
|
|
26
|
+
const diffedLanguage = getDiffedLanguage(language);
|
|
27
|
+
const langId = diffedLanguage || language;
|
|
28
|
+
// handle shiki Hard-coded languages ['ansi', '', 'plaintext', 'txt', 'text', 'plain']
|
|
29
|
+
if (isSpecialLang(langId)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
// note: getLoadedLanguages() also returns aliases
|
|
33
|
+
return shiki.getLoadedLanguages().includes(langId);
|
|
34
|
+
}
|
|
35
|
+
export function loadCodeLanguage(language, editor, codeNodeKey) {
|
|
36
|
+
const diffedLanguage = getDiffedLanguage(language);
|
|
37
|
+
const langId = diffedLanguage ? diffedLanguage : language;
|
|
38
|
+
if (!isCodeLanguageLoaded(langId)) {
|
|
39
|
+
const languageInfo = bundledLanguagesInfo.find((desc) => desc.id === langId || (desc.aliases && desc.aliases.includes(langId)));
|
|
40
|
+
if (languageInfo) {
|
|
41
|
+
// in case we arrive here concurrently (not yet loaded language is loaded twice)
|
|
42
|
+
// shiki's synchronous checks make sure to load it only once
|
|
43
|
+
return shiki.loadLanguage(languageInfo.import()).then(() => {
|
|
44
|
+
// here we know that the language is loaded
|
|
45
|
+
// make sure the code is highlighed with the correct language
|
|
46
|
+
if (editor && codeNodeKey) {
|
|
47
|
+
editor.update(() => {
|
|
48
|
+
const codeNode = $getNodeByKey(codeNodeKey);
|
|
49
|
+
if ($isCodeNode(codeNode) &&
|
|
50
|
+
codeNode.getLanguage() === language &&
|
|
51
|
+
!codeNode.getIsSyntaxHighlightSupported()) {
|
|
52
|
+
codeNode.setIsSyntaxHighlightSupported(true);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function isCodeThemeLoaded(theme) {
|
|
61
|
+
const themeId = theme;
|
|
62
|
+
// handle shiki special theme ['none']
|
|
63
|
+
if (isSpecialTheme(themeId)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return shiki.getLoadedThemes().includes(themeId);
|
|
67
|
+
}
|
|
68
|
+
export function loadCodeTheme(theme, editor, codeNodeKey) {
|
|
69
|
+
if (!isCodeThemeLoaded(theme)) {
|
|
70
|
+
const themeInfo = bundledThemesInfo.find((info) => info.id === theme);
|
|
71
|
+
if (themeInfo) {
|
|
72
|
+
return shiki.loadTheme(themeInfo.import()).then(() => {
|
|
73
|
+
if (editor && codeNodeKey) {
|
|
74
|
+
editor.update(() => {
|
|
75
|
+
const codeNode = $getNodeByKey(codeNodeKey);
|
|
76
|
+
if ($isCodeNode(codeNode)) {
|
|
77
|
+
codeNode.markDirty();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function getCodeLanguageOptions() {
|
|
86
|
+
return bundledLanguagesInfo.map((i) => [i.id, i.name]);
|
|
87
|
+
}
|
|
88
|
+
export function getCodeThemeOptions() {
|
|
89
|
+
return bundledThemesInfo.map((i) => [i.id, i.displayName]);
|
|
90
|
+
}
|
|
91
|
+
export function normalizeCodeLanguage(language) {
|
|
92
|
+
const langId = language;
|
|
93
|
+
const languageInfo = bundledLanguagesInfo.find((desc) => desc.id === langId || (desc.aliases && desc.aliases.includes(langId)));
|
|
94
|
+
if (languageInfo) {
|
|
95
|
+
return languageInfo.id;
|
|
96
|
+
}
|
|
97
|
+
return language;
|
|
98
|
+
}
|
|
99
|
+
export function $getHighlightNodes(codeNode, language) {
|
|
100
|
+
const DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
|
|
101
|
+
const diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
|
|
102
|
+
const code = codeNode.getTextContent();
|
|
103
|
+
const tokensResult = shiki.codeToTokens(code, {
|
|
104
|
+
lang: diffLanguageMatch ? diffLanguageMatch[1] : language,
|
|
105
|
+
theme: codeNode.getTheme() || "poimandres",
|
|
106
|
+
});
|
|
107
|
+
const { tokens, bg, fg } = tokensResult;
|
|
108
|
+
let style = "";
|
|
109
|
+
if (bg) {
|
|
110
|
+
style += `background-color: ${bg};`;
|
|
111
|
+
}
|
|
112
|
+
if (fg) {
|
|
113
|
+
style += `color: ${fg};`;
|
|
114
|
+
}
|
|
115
|
+
if (codeNode.getStyle() !== style) {
|
|
116
|
+
codeNode.setStyle(style);
|
|
117
|
+
}
|
|
118
|
+
return mapTokensToLexicalStructure(tokens, !!diffLanguageMatch);
|
|
119
|
+
}
|
|
120
|
+
function mapTokensToLexicalStructure(tokens, diff) {
|
|
121
|
+
const nodes = [];
|
|
122
|
+
tokens.forEach((line, idx) => {
|
|
123
|
+
if (idx) {
|
|
124
|
+
nodes.push($createLineBreakNode());
|
|
125
|
+
}
|
|
126
|
+
line.forEach((token, tidx) => {
|
|
127
|
+
let text = token.content;
|
|
128
|
+
// implement diff-xxxx languages
|
|
129
|
+
if (diff && tidx === 0 && text.length > 0) {
|
|
130
|
+
const prefixes = ["+", "-", ">", "<", " "];
|
|
131
|
+
const prefixTypes = [
|
|
132
|
+
"inserted",
|
|
133
|
+
"deleted",
|
|
134
|
+
"inserted",
|
|
135
|
+
"deleted",
|
|
136
|
+
"unchanged",
|
|
137
|
+
];
|
|
138
|
+
const prefixIndex = prefixes.indexOf(text[0]);
|
|
139
|
+
if (prefixIndex !== -1) {
|
|
140
|
+
nodes.push($createCodeHighlightNode(prefixes[prefixIndex], prefixTypes[prefixIndex]));
|
|
141
|
+
text = text.slice(1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const parts = text.split("\t");
|
|
145
|
+
parts.forEach((part, pidx) => {
|
|
146
|
+
if (pidx) {
|
|
147
|
+
nodes.push($createTabNode());
|
|
148
|
+
}
|
|
149
|
+
if (part !== "") {
|
|
150
|
+
const node = $createCodeHighlightNode(part);
|
|
151
|
+
const style = stringifyTokenStyle(token.htmlStyle || getTokenStyleObject(token));
|
|
152
|
+
node.setStyle(style);
|
|
153
|
+
nodes.push(node);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
return nodes;
|
|
159
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { CodeHighlightNode } from "./CodeHighlightNode";
|
|
9
|
+
import type { LineBreakNode, TabNode } from "lexical";
|
|
10
|
+
export declare function $getFirstCodeNodeOfLine(anchor: CodeHighlightNode | TabNode | LineBreakNode): CodeHighlightNode | TabNode | LineBreakNode;
|
|
11
|
+
export declare function $getLastCodeNodeOfLine(anchor: CodeHighlightNode | TabNode | LineBreakNode): CodeHighlightNode | TabNode | LineBreakNode;
|
|
12
|
+
/**
|
|
13
|
+
* Determines the visual writing direction of a code line.
|
|
14
|
+
*
|
|
15
|
+
* Scans the line segments (CodeHighlightNode/TabNode) from start to end
|
|
16
|
+
* and returns the first strong direction found ("ltr" or "rtl").
|
|
17
|
+
* If no strong character is found, falls back to the parent element's
|
|
18
|
+
* direction. Returns null if indeterminate.
|
|
19
|
+
*/
|
|
20
|
+
export declare function $getCodeLineDirection(anchor: CodeHighlightNode | TabNode | LineBreakNode): "ltr" | "rtl" | null;
|
|
21
|
+
//# sourceMappingURL=FlatStructureUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatStructureUtils.d.ts","sourceRoot":"","sources":["../../../src/nodes/CodeNode/FlatStructureUtils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAGV,aAAa,EAEb,OAAO,EACR,MAAM,SAAS,CAAC;AA+BjB,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,iBAAiB,GAAG,OAAO,GAAG,aAAa,GAClD,iBAAiB,GAAG,OAAO,GAAG,aAAa,CAE7C;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,iBAAiB,GAAG,OAAO,GAAG,aAAa,GAClD,iBAAiB,GAAG,OAAO,GAAG,aAAa,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,GAAG,OAAO,GAAG,aAAa,GAClD,KAAK,GAAG,KAAK,GAAG,IAAI,CA6BtB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 { $getAdjacentCaret } from "@lexical/utils";
|
|
9
|
+
import { $getSiblingCaret, $isElementNode, $isLineBreakNode, $isTabNode, getTextDirection, } from "lexical";
|
|
10
|
+
import { $isCodeHighlightNode } from "./CodeHighlightNode";
|
|
11
|
+
function $getLastMatchingCodeNode(anchor, direction) {
|
|
12
|
+
let matchingNode = anchor;
|
|
13
|
+
for (let caret = $getSiblingCaret(anchor, direction); caret && ($isCodeHighlightNode(caret.origin) || $isTabNode(caret.origin)); caret = $getAdjacentCaret(caret)) {
|
|
14
|
+
matchingNode = caret.origin;
|
|
15
|
+
}
|
|
16
|
+
return matchingNode;
|
|
17
|
+
}
|
|
18
|
+
export function $getFirstCodeNodeOfLine(anchor) {
|
|
19
|
+
return $getLastMatchingCodeNode(anchor, "previous");
|
|
20
|
+
}
|
|
21
|
+
export function $getLastCodeNodeOfLine(anchor) {
|
|
22
|
+
return $getLastMatchingCodeNode(anchor, "next");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Determines the visual writing direction of a code line.
|
|
26
|
+
*
|
|
27
|
+
* Scans the line segments (CodeHighlightNode/TabNode) from start to end
|
|
28
|
+
* and returns the first strong direction found ("ltr" or "rtl").
|
|
29
|
+
* If no strong character is found, falls back to the parent element's
|
|
30
|
+
* direction. Returns null if indeterminate.
|
|
31
|
+
*/
|
|
32
|
+
export function $getCodeLineDirection(anchor) {
|
|
33
|
+
const start = $getFirstCodeNodeOfLine(anchor);
|
|
34
|
+
const end = $getLastCodeNodeOfLine(anchor);
|
|
35
|
+
let node = start;
|
|
36
|
+
while (node !== null) {
|
|
37
|
+
if ($isCodeHighlightNode(node)) {
|
|
38
|
+
const direction = getTextDirection(node.getTextContent());
|
|
39
|
+
if (direction !== null) {
|
|
40
|
+
return direction;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (node === end) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
node = node.getNextSibling();
|
|
47
|
+
}
|
|
48
|
+
const parent = start.getParent();
|
|
49
|
+
if ($isElementNode(parent)) {
|
|
50
|
+
const parentDirection = parent.getDirection();
|
|
51
|
+
if (parentDirection === "ltr" || parentDirection === "rtl") {
|
|
52
|
+
return parentDirection;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function findNextNonBlankInLine(anchor, offset) {
|
|
58
|
+
let node = anchor;
|
|
59
|
+
let nodeOffset = offset;
|
|
60
|
+
let nodeTextContent = anchor.getTextContent();
|
|
61
|
+
let nodeTextContentSize = anchor.getTextContentSize();
|
|
62
|
+
// eslint-disable-next-line no-constant-condition
|
|
63
|
+
while (true) {
|
|
64
|
+
if (!$isCodeHighlightNode(node) || nodeOffset === nodeTextContentSize) {
|
|
65
|
+
node = node.getNextSibling();
|
|
66
|
+
if (node === null || $isLineBreakNode(node)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if ($isCodeHighlightNode(node)) {
|
|
70
|
+
nodeOffset = 0;
|
|
71
|
+
nodeTextContent = node.getTextContent();
|
|
72
|
+
nodeTextContentSize = node.getTextContentSize();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if ($isCodeHighlightNode(node)) {
|
|
76
|
+
if (nodeTextContent[nodeOffset] !== " ") {
|
|
77
|
+
return {
|
|
78
|
+
node,
|
|
79
|
+
offset: nodeOffset,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
nodeOffset++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../../src/nodes/CodeNode/invariant.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,EAChB,GAAG,IAAI,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAQd"}
|