@collabchron/notiq 0.2.0 → 1.0.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 +21 -0
- package/README.md +230 -39
- package/dist/CodeActionMenuPlugin-EINOY4U4.mjs +15 -0
- package/dist/DynamicBlockComponent-NRQJ4WW4.mjs +161 -0
- package/dist/EquationComponent-CB6DFIHV.mjs +154 -0
- package/dist/ExcalidrawComponent-XW6646OH.mjs +528 -0
- package/dist/ExcalidrawPlugin-ZFHT62IF.mjs +14 -0
- package/dist/ExportPlugin-V2RLM63S.mjs +11 -0
- package/dist/FloatingLinkEditorPlugin-TRTCMSP4.mjs +12 -0
- package/dist/FloatingTextFormatToolbarPlugin-F2GY6LMI.mjs +30 -0
- package/dist/HintComponet-BRL6EAMS.mjs +217 -0
- package/dist/InlineImageComponent-UWIUWBHI.mjs +453 -0
- package/dist/MobileToolbar-BOOZAMQE.mjs +268 -0
- package/dist/SlashCommand-GMT5JI33.mjs +28 -0
- package/dist/StoryBuilderComponent-JGDBM5JU.mjs +562 -0
- package/{src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx → dist/TableCellActionMenuPlugin-PGK2K3VG.mjs} +667 -759
- package/{src/components/editor/plugins/TableHoverActionsPlugin/index.tsx → dist/TableHoverActionsPlugin-GJVE6VRW.mjs} +258 -314
- package/dist/TemplatePlugin-ZD3QEVTI.mjs +9 -0
- package/dist/ToolbarPlugin-7TOZRD2R.mjs +1547 -0
- package/dist/babel-JZ2EV6AX.mjs +7233 -0
- package/dist/background-color-XZTYLGO2.mjs +362 -0
- package/dist/block-format-YJCV2DIY.mjs +15 -0
- package/dist/chunk-2FNEAMSP.mjs +127 -0
- package/dist/chunk-3CPBODXA.mjs +84 -0
- package/dist/chunk-3G37YKTV.mjs +83 -0
- package/dist/chunk-3JVFG7ER.mjs +184 -0
- package/dist/chunk-456TN7IM.mjs +110 -0
- package/dist/chunk-4EXYCTGJ.mjs +27 -0
- package/{src/utils/getSelectedNode.ts → dist/chunk-4HBCVSE6.mjs} +26 -27
- package/dist/chunk-4MEDW3T6.mjs +125 -0
- package/dist/chunk-4VWFVWYP.mjs +36 -0
- package/dist/chunk-5BAKY5KN.mjs +84 -0
- package/dist/chunk-5QSNIVIG.mjs +333 -0
- package/dist/chunk-64Z3FI7T.mjs +37 -0
- package/{src/components/editor/nodes/Stepper/index.tsx → dist/chunk-6RNZQOH2.mjs} +214 -260
- package/dist/chunk-77KXU36M.mjs +64 -0
- package/dist/chunk-77UA6HYR.mjs +165 -0
- package/dist/chunk-7NZAPJ4G.mjs +102 -0
- package/dist/chunk-7VUMHWWL.mjs +152 -0
- package/dist/chunk-AMMKBSST.mjs +1256 -0
- package/dist/chunk-BIU7WTLX.mjs +95 -0
- package/dist/chunk-EGMI62PP.mjs +83 -0
- package/dist/chunk-EHNQD5KO.mjs +88 -0
- package/dist/chunk-FSM26655.mjs +37 -0
- package/{src/components/editor/nodes/Hint/index.tsx → dist/chunk-G53GLEAY.mjs} +158 -190
- package/dist/chunk-GK35L7UY.mjs +28 -0
- package/dist/chunk-GXYD4VZM.mjs +193 -0
- package/dist/chunk-GYIOYVCN.mjs +538 -0
- package/dist/chunk-GZPNVR7L.mjs +157 -0
- package/dist/chunk-JXDPPUJI.mjs +52 -0
- package/dist/chunk-K36V4SIW.mjs +141 -0
- package/dist/chunk-KJ6AJ44Q.mjs +128 -0
- package/dist/chunk-KJV3FAZ7.mjs +142 -0
- package/{src/components/editor/plugins/ImagesPlugin/index.tsx → dist/chunk-LGG4IUIA.mjs} +189 -222
- package/dist/chunk-LQN3CMKV.mjs +1906 -0
- package/dist/chunk-N3WN46VL.mjs +236 -0
- package/dist/chunk-PBD6LMLC.mjs +366 -0
- package/dist/chunk-POGRR73N.mjs +33 -0
- package/{src/components/editor/utils/editorFormatting.ts → dist/chunk-PZSUSXQG.mjs} +238 -282
- package/dist/chunk-QEIFVK5M.mjs +29 -0
- package/dist/chunk-QHIQKMVN.mjs +427 -0
- package/dist/chunk-TCYK7DM7.mjs +36 -0
- package/dist/chunk-TTHQCW5F.mjs +47 -0
- package/dist/chunk-U47ABU5Z.mjs +53 -0
- package/dist/chunk-WDG7J2DY.mjs +116 -0
- package/dist/chunk-WJRHXI2C.mjs +733 -0
- package/dist/chunk-XLER2DHM.mjs +357 -0
- package/dist/chunk-XWC4TK2N.mjs +315 -0
- package/dist/chunk-YHPNOWFH.mjs +15 -0
- package/dist/chunk-YKC3SO4Z.mjs +32 -0
- package/dist/chunk-YMBXLRW5.mjs +374 -0
- package/dist/chunk-YPHOEJ46.mjs +64 -0
- package/dist/chunk-YUDCJRJM.mjs +25 -0
- package/dist/chunk-Z4EWP7BI.mjs +65 -0
- package/dist/chunk-ZB5LZQKC.mjs +191 -0
- package/dist/chunk-ZJRKATOJ.mjs +65 -0
- package/dist/color-BPKOPQKN.mjs +12 -0
- package/dist/estree-XC56IUFX.mjs +4414 -0
- package/dist/font-FEZ3GKSF.mjs +13 -0
- package/dist/font-size-EK775WRH.mjs +15 -0
- package/dist/html-S3ACX7NI.mjs +2738 -0
- package/dist/image-2PJIAYAT.mjs +993 -0
- package/dist/index.d.mts +145 -0
- package/dist/index.d.ts +145 -0
- package/dist/index.js +57855 -0
- package/dist/index.mjs +1790 -0
- package/dist/insert-gif-SAIDYURE.mjs +100 -0
- package/dist/insert-image-U3RJN3OW.mjs +259 -0
- package/dist/insert-node-5P2CRJ7S.mjs +201 -0
- package/dist/insert-poll-HCPM7MO6.mjs +33 -0
- package/dist/insert-table-24XYUS2W.mjs +66 -0
- package/dist/markdown-SNVBOSRA.mjs +3487 -0
- package/dist/poll-component-2R4MDLHS.mjs +303 -0
- package/dist/postcss-ONF3VDIM.mjs +5051 -0
- package/dist/standalone-EOIALU3M.mjs +2373 -0
- package/dist/stepper-FSARL6X6.mjs +304 -0
- package/dist/styles/notiq.css +1149 -0
- package/dist/text-align-VLECWO4H.mjs +118 -0
- package/dist/text-format-BG5WOOPZ.mjs +16 -0
- package/dist/typescript-AMPI6OVS.mjs +13135 -0
- package/package.json +94 -10
- package/src/styles/notiq.css +1149 -0
- package/src/styles/tailwind-plugin.ts +134 -0
- package/components.json +0 -21
- package/eslint.config.mjs +0 -16
- package/next.config.ts +0 -12
- package/postcss.config.mjs +0 -5
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/images/icons/plus.svg +0 -10
- package/public/next.svg +0 -1
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/src/app/actions.ts +0 -2
- package/src/app/api/ai/route.ts +0 -175
- package/src/app/api/edgestore/[...edgestore]/route.ts +0 -28
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +0 -205
- package/src/app/layout.tsx +0 -38
- package/src/app/page.tsx +0 -12
- package/src/components/editor/Core.tsx +0 -220
- package/src/components/editor/hooks/instructions-messages.ts +0 -300
- package/src/components/editor/hooks/use-mobile.ts +0 -19
- package/src/components/editor/hooks/useReport.ts +0 -67
- package/src/components/editor/hooks/useResizeObservert.ts +0 -22
- package/src/components/editor/index.tsx +0 -39
- package/src/components/editor/lexical-on-change.tsx +0 -28
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +0 -92
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +0 -65
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +0 -105
- package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +0 -143
- package/src/components/editor/nodes/EquationNode/EquationNode.tsx +0 -170
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +0 -228
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +0 -137
- package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +0 -317
- package/src/components/editor/nodes/ExcalidrawNode/index.tsx +0 -204
- package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +0 -134
- package/src/components/editor/nodes/Hint/HintComponet.tsx +0 -221
- package/src/components/editor/nodes/ImageNode/index.tsx +0 -328
- package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +0 -383
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +0 -94
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +0 -309
- package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +0 -146
- package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +0 -79
- package/src/components/editor/nodes/PollNode/index.tsx +0 -204
- package/src/components/editor/nodes/TweetNode/index.tsx +0 -214
- package/src/components/editor/nodes/index.ts +0 -81
- package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +0 -350
- package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +0 -56
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +0 -70
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +0 -192
- package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +0 -217
- package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +0 -26
- package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +0 -21
- package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +0 -76
- package/src/components/editor/plugins/CollapsiblePlugin/index.ts +0 -228
- package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +0 -44
- package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +0 -52
- package/src/components/editor/plugins/EquationsPlugin/index.tsx +0 -85
- package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +0 -98
- package/src/components/editor/plugins/FigmaPlugin/index.tsx +0 -42
- package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +0 -445
- package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +0 -275
- package/src/components/editor/plugins/InlineImagePlugin/index.tsx +0 -351
- package/src/components/editor/plugins/LayoutPlugin/index.tsx +0 -238
- package/src/components/editor/plugins/LinkPlugin/index.tsx +0 -36
- package/src/components/editor/plugins/LinkWithMetaData/index.tsx +0 -271
- package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +0 -11
- package/src/components/editor/plugins/MarkdownTransformers/index.tsx +0 -304
- package/src/components/editor/plugins/PollPlugin/index.tsx +0 -49
- package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +0 -180
- package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +0 -253
- package/src/components/editor/plugins/SlashCommand/index.tsx +0 -621
- package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +0 -127
- package/src/components/editor/plugins/TabFocusPlugin/index.ts +0 -58
- package/src/components/editor/plugins/TableCellResizer/index.tsx +0 -438
- package/src/components/editor/plugins/TablePlugin/index.tsx +0 -99
- package/src/components/editor/plugins/ToolbarPlugin/index.tsx +0 -522
- package/src/components/editor/plugins/TwitterPlugin/index.ts +0 -35
- package/src/components/editor/plugins/YouTubeNode/index.tsx +0 -179
- package/src/components/editor/plugins/YouTubePlugin/index.ts +0 -41
- package/src/components/editor/themes/editor-theme.ts +0 -113
- package/src/components/editor/themes/theme.css +0 -377
- package/src/components/editor/utils/ai.ts +0 -291
- package/src/components/editor/utils/canUseDOM.ts +0 -12
- package/src/components/editor/utils/environment.ts +0 -50
- package/src/components/editor/utils/extract-data.ts +0 -166
- package/src/components/editor/utils/getAllLexicalChildren.ts +0 -13
- package/src/components/editor/utils/getDOMRangeRect.ts +0 -27
- package/src/components/editor/utils/getSelectedNode.ts +0 -27
- package/src/components/editor/utils/gif.ts +0 -29
- package/src/components/editor/utils/invariant.ts +0 -15
- package/src/components/editor/utils/setFloatingElemPosition.ts +0 -51
- package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +0 -40
- package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +0 -51
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +0 -15
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +0 -114
- package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +0 -6
- package/src/components/editor/utils/url.ts +0 -109
- package/src/components/editor/utils/useLayoutEffect.ts +0 -13
- package/src/components/providers/QueryProvider.tsx +0 -15
- package/src/components/providers/SharedHistoryContext.tsx +0 -28
- package/src/components/providers/ToolbarContext.tsx +0 -123
- package/src/components/providers/theme-provider.tsx +0 -11
- package/src/components/theme/ModeToggle.tsx +0 -40
- package/src/components/ui/FileInput.tsx +0 -40
- package/src/components/ui/Input.css +0 -32
- package/src/components/ui/Select.css +0 -42
- package/src/components/ui/Select.tsx +0 -36
- package/src/components/ui/TextInput.tsx +0 -48
- package/src/components/ui/ai/ai-button.tsx +0 -574
- package/src/components/ui/ai/border.tsx +0 -99
- package/src/components/ui/ai/placeholder-input-vanish.tsx +0 -282
- package/src/components/ui/button.tsx +0 -89
- package/src/components/ui/card.tsx +0 -76
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/command.tsx +0 -153
- package/src/components/ui/dialog/Dialog.css +0 -25
- package/src/components/ui/dialog/Dialog.tsx +0 -34
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/drop-downs/background-color.tsx +0 -183
- package/src/components/ui/drop-downs/block-format.tsx +0 -159
- package/src/components/ui/drop-downs/code.tsx +0 -42
- package/src/components/ui/drop-downs/color.tsx +0 -177
- package/src/components/ui/drop-downs/font-size.tsx +0 -138
- package/src/components/ui/drop-downs/font.tsx +0 -155
- package/src/components/ui/drop-downs/index.tsx +0 -122
- package/src/components/ui/drop-downs/insert-node.tsx +0 -213
- package/src/components/ui/drop-downs/text-align.tsx +0 -123
- package/src/components/ui/drop-downs/text-format.tsx +0 -104
- package/src/components/ui/dropdown-menu.tsx +0 -201
- package/src/components/ui/equation/EquationEditor.css +0 -38
- package/src/components/ui/equation/EquationEditor.tsx +0 -56
- package/src/components/ui/equation/KatexEquationAlterer.css +0 -41
- package/src/components/ui/equation/KatexEquationAlterer.tsx +0 -83
- package/src/components/ui/equation/KatexRenderer.tsx +0 -66
- package/src/components/ui/excalidraw/ExcalidrawModal.css +0 -64
- package/src/components/ui/excalidraw/ExcalidrawModal.tsx +0 -234
- package/src/components/ui/excalidraw/Modal.css +0 -62
- package/src/components/ui/excalidraw/Modal.tsx +0 -110
- package/src/components/ui/hover-card.tsx +0 -29
- package/src/components/ui/image/error-image.tsx +0 -17
- package/src/components/ui/image/file-upload.tsx +0 -240
- package/src/components/ui/image/image-resizer.tsx +0 -297
- package/src/components/ui/image/image-toolbar.tsx +0 -264
- package/src/components/ui/image/index.tsx +0 -408
- package/src/components/ui/image/lazy-image.tsx +0 -68
- package/src/components/ui/image/lazy-video.tsx +0 -71
- package/src/components/ui/input.tsx +0 -22
- package/src/components/ui/models/custom-dialog.tsx +0 -320
- package/src/components/ui/models/insert-gif.tsx +0 -90
- package/src/components/ui/models/insert-image.tsx +0 -52
- package/src/components/ui/models/insert-poll.tsx +0 -29
- package/src/components/ui/models/insert-table.tsx +0 -62
- package/src/components/ui/models/use-model.tsx +0 -91
- package/src/components/ui/poll/poll-component.tsx +0 -304
- package/src/components/ui/popover.tsx +0 -33
- package/src/components/ui/progress.tsx +0 -28
- package/src/components/ui/scroll-area.tsx +0 -48
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/skeleton.tsx +0 -15
- package/src/components/ui/sonner.tsx +0 -31
- package/src/components/ui/stepper/step.tsx +0 -179
- package/src/components/ui/stepper/stepper.tsx +0 -89
- package/src/components/ui/textarea.tsx +0 -22
- package/src/components/ui/toggle.tsx +0 -71
- package/src/components/ui/tooltip.tsx +0 -32
- package/src/components/ui/write/text-format-floting-toolbar.tsx +0 -346
- package/src/lib/edgestore.ts +0 -9
- package/src/lib/pinecone-client.ts +0 -0
- package/src/lib/utils.ts +0 -6
- package/src/utils/docSerialization.ts +0 -77
- package/src/utils/emoji-list.ts +0 -16615
- package/src/utils/getDOMRangeRect.ts +0 -27
- package/src/utils/getThemeSelector.ts +0 -25
- package/src/utils/isMobileWidth.ts +0 -7
- package/src/utils/joinClasses.ts +0 -13
- package/src/utils/setFloatingElemPosition.ts +0 -74
- package/src/utils/setFloatingElemPositionForLinkEditor.ts +0 -46
- package/src/utils/swipe.ts +0 -127
- package/src/utils/url.ts +0 -38
- package/tsconfig.json +0 -27
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { $isCodeHighlightNode } from "@lexical/code";
|
|
2
|
-
import { $isLinkNode } from "@lexical/link";
|
|
3
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
$findMatchingParent,
|
|
7
|
-
$getNearestNodeOfType,
|
|
8
|
-
mergeRegister,
|
|
9
|
-
} from "@lexical/utils";
|
|
10
|
-
import {
|
|
11
|
-
$getSelection,
|
|
12
|
-
$isParagraphNode,
|
|
13
|
-
$isRangeSelection,
|
|
14
|
-
$isRootOrShadowRoot,
|
|
15
|
-
$isTextNode,
|
|
16
|
-
getDOMSelection,
|
|
17
|
-
LexicalEditor,
|
|
18
|
-
} from "lexical";
|
|
19
|
-
import { Dispatch, useCallback, useEffect, useState } from "react";
|
|
20
|
-
import * as React from "react";
|
|
21
|
-
import { createPortal } from "react-dom";
|
|
22
|
-
|
|
23
|
-
import { getSelectedNode } from "../../utils/getSelectedNode";
|
|
24
|
-
|
|
25
|
-
import { blockTypeToBlockName } from "@/components/providers/ToolbarContext";
|
|
26
|
-
// import TextFormatFloatingToolbar from "@/components/ui/floting-text/write/text-format-floting-toolbar";
|
|
27
|
-
import {
|
|
28
|
-
$getSelectionStyleValueForProperty,
|
|
29
|
-
} from "@lexical/selection";
|
|
30
|
-
|
|
31
|
-
import { useRef } from "react";
|
|
32
|
-
import { $isTableNode } from "@lexical/table";
|
|
33
|
-
import { $isListNode, ListNode } from "@lexical/list";
|
|
34
|
-
import { $isHeadingNode } from "@lexical/rich-text";
|
|
35
|
-
import TextFormatFloatingToolbar from "@/components/ui/write/text-format-floting-toolbar";
|
|
36
|
-
|
|
37
|
-
function useFloatingTextFormatToolbar(
|
|
38
|
-
editor: LexicalEditor,
|
|
39
|
-
anchorElem: HTMLElement,
|
|
40
|
-
setIsLinkEditMode: Dispatch<boolean>
|
|
41
|
-
): React.JSX.Element | null {
|
|
42
|
-
const [isText, setIsText] = useState(false);
|
|
43
|
-
const [isLink, setIsLink] = useState(false);
|
|
44
|
-
const [isBold, setIsBold] = useState(false);
|
|
45
|
-
const [isItalic, setIsItalic] = useState(false);
|
|
46
|
-
const [isUnderline, setIsUnderline] = useState(false);
|
|
47
|
-
const [isStrikethrough, setIsStrikethrough] = useState(false);
|
|
48
|
-
const [isCode, setIsCode] = useState(false);
|
|
49
|
-
const [fontColor, setFontColor] = useState<string>("#000000");
|
|
50
|
-
const [bgColor, setBgColor] = useState<string>("#ffffff");
|
|
51
|
-
const [fontFamily, setFontFamily] = useState<string>("Arial");
|
|
52
|
-
const [blockType, setBlockType] =useState<keyof typeof blockTypeToBlockName>("paragraph");
|
|
53
|
-
const [isUppercase, setIsUppercase] = useState(false);
|
|
54
|
-
const [isLowercase, setIsLowercase] = useState(false);
|
|
55
|
-
const [isCapitalize, setIsCapitalize] = useState(false);
|
|
56
|
-
const [isSubscript, setIsSubscript] = useState(false);
|
|
57
|
-
const [isSuperscript, setIsSuperscript] = useState(false);
|
|
58
|
-
const [rootType, setRootType] = useState<"root" | "table">("root");
|
|
59
|
-
const [textAlign, setTextAlign] = useState<
|
|
60
|
-
"left" | "center" | "right" | "justify" | null
|
|
61
|
-
>(null);
|
|
62
|
-
const [fontSize, setFontSize] = useState<string>("16px");
|
|
63
|
-
|
|
64
|
-
const toolbarRef = useRef<HTMLDivElement>(null);
|
|
65
|
-
|
|
66
|
-
const updatePopup = useCallback(() => {
|
|
67
|
-
editor.getEditorState().read(() => {
|
|
68
|
-
if (editor.isComposing()) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const selection = $getSelection();
|
|
72
|
-
const nativeSelection = getDOMSelection(editor._window);
|
|
73
|
-
const rootElement = editor.getRootElement();
|
|
74
|
-
const aiElement = document.querySelector(".AI-format");
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
nativeSelection &&
|
|
83
|
-
nativeSelection.anchorNode instanceof HTMLElement &&
|
|
84
|
-
nativeSelection.anchorNode.closest(".dropdown-portal")
|
|
85
|
-
) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
nativeSelection !== null &&
|
|
91
|
-
(!$isRangeSelection(selection) ||
|
|
92
|
-
rootElement === null ||
|
|
93
|
-
!rootElement.contains(nativeSelection.anchorNode)) &&
|
|
94
|
-
!toolbarRef?.current?.contains(nativeSelection.anchorNode) && !(aiElement && aiElement.contains(nativeSelection.anchorNode))
|
|
95
|
-
|
|
96
|
-
) {
|
|
97
|
-
setIsText(false);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!$isRangeSelection(selection)) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const node = getSelectedNode(selection);
|
|
106
|
-
|
|
107
|
-
// Update text format
|
|
108
|
-
setIsBold(selection.hasFormat('bold'));
|
|
109
|
-
setIsItalic(selection.hasFormat('italic'));
|
|
110
|
-
setIsUnderline(selection.hasFormat('underline'));
|
|
111
|
-
setIsStrikethrough(selection.hasFormat('strikethrough'));
|
|
112
|
-
setIsSubscript(selection.hasFormat('subscript'));
|
|
113
|
-
setIsLowercase(selection.hasFormat('lowercase'));
|
|
114
|
-
setIsUppercase(selection.hasFormat('uppercase'));
|
|
115
|
-
setIsCapitalize(selection.hasFormat('capitalize'));
|
|
116
|
-
setIsSubscript(selection.hasFormat('subscript'));
|
|
117
|
-
setIsSuperscript(selection.hasFormat('superscript'));
|
|
118
|
-
|
|
119
|
-
setIsCode(selection.hasFormat('code'));
|
|
120
|
-
const size = $getSelectionStyleValueForProperty(
|
|
121
|
-
selection,
|
|
122
|
-
"font-size",
|
|
123
|
-
"16px"
|
|
124
|
-
);
|
|
125
|
-
setFontSize(size);
|
|
126
|
-
const alignment = $getSelectionStyleValueForProperty(
|
|
127
|
-
selection,
|
|
128
|
-
"text-align",
|
|
129
|
-
"left"
|
|
130
|
-
);
|
|
131
|
-
setTextAlign(alignment as "left" | "center" | "right" | "justify" | null);
|
|
132
|
-
|
|
133
|
-
// Update links
|
|
134
|
-
const parent = node.getParent();
|
|
135
|
-
if ($isLinkNode(parent) || $isLinkNode(node)) {
|
|
136
|
-
setIsLink(true);
|
|
137
|
-
} else {
|
|
138
|
-
setIsLink(false);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
!$isCodeHighlightNode(selection.anchor.getNode()) &&
|
|
143
|
-
selection.getTextContent() !== ''
|
|
144
|
-
) {
|
|
145
|
-
setIsText($isTextNode(node) || $isParagraphNode(node));
|
|
146
|
-
} else {
|
|
147
|
-
setIsText(false);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const rawTextContent = selection.getTextContent().replace(/\n/g, '');
|
|
151
|
-
if (!selection.isCollapsed() && rawTextContent === '') {
|
|
152
|
-
setIsText(false);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
setFontFamily(
|
|
156
|
-
$getSelectionStyleValueForProperty(selection, "font-family", "Arial")
|
|
157
|
-
);
|
|
158
|
-
setFontColor($getSelectionStyleValueForProperty(selection, "color"));
|
|
159
|
-
setBgColor(
|
|
160
|
-
$getSelectionStyleValueForProperty(selection, "background-color")
|
|
161
|
-
);
|
|
162
|
-
const tableNode = $findMatchingParent(node, $isTableNode);
|
|
163
|
-
if ($isTableNode(tableNode)) {
|
|
164
|
-
setRootType("table");
|
|
165
|
-
} else {
|
|
166
|
-
setRootType("root");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const anchorNode = selection.anchor.getNode();
|
|
170
|
-
let element =
|
|
171
|
-
anchorNode.getKey() === "root"
|
|
172
|
-
? anchorNode
|
|
173
|
-
: $findMatchingParent(anchorNode, (e) => {
|
|
174
|
-
const parent = e.getParent();
|
|
175
|
-
return parent !== null && $isRootOrShadowRoot(parent);
|
|
176
|
-
});
|
|
177
|
-
if ($isListNode(element)) {
|
|
178
|
-
const parentList = $getNearestNodeOfType<ListNode>(
|
|
179
|
-
anchorNode,
|
|
180
|
-
ListNode
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
const type = parentList
|
|
184
|
-
? parentList.getListType()
|
|
185
|
-
: element.getListType();
|
|
186
|
-
setBlockType(type);
|
|
187
|
-
} else {
|
|
188
|
-
const type = $isHeadingNode(element)
|
|
189
|
-
? element.getTag()
|
|
190
|
-
: // @ts-ignore
|
|
191
|
-
element.getType();
|
|
192
|
-
setBlockType(type as keyof typeof blockTypeToBlockName);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}, [editor]);
|
|
196
|
-
|
|
197
|
-
useEffect(() => {
|
|
198
|
-
const handleSelectionChange = () => {
|
|
199
|
-
if (toolbarRef.current && toolbarRef.current.contains(document.activeElement)) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
updatePopup();
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
document.addEventListener('selectionchange', handleSelectionChange);
|
|
206
|
-
return () => {
|
|
207
|
-
document.removeEventListener('selectionchange', handleSelectionChange);
|
|
208
|
-
};
|
|
209
|
-
}, [updatePopup]);
|
|
210
|
-
|
|
211
|
-
useEffect(() => {
|
|
212
|
-
return mergeRegister(
|
|
213
|
-
editor.registerUpdateListener(() => {
|
|
214
|
-
updatePopup();
|
|
215
|
-
}),
|
|
216
|
-
editor.registerRootListener(() => {
|
|
217
|
-
if (editor.getRootElement() === null) {
|
|
218
|
-
setIsText(false);
|
|
219
|
-
}
|
|
220
|
-
})
|
|
221
|
-
);
|
|
222
|
-
}, [editor, updatePopup]);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (!isText) {
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return createPortal(
|
|
231
|
-
<div ref={toolbarRef}>
|
|
232
|
-
<TextFormatFloatingToolbar
|
|
233
|
-
editor={editor}
|
|
234
|
-
anchorElem={anchorElem}
|
|
235
|
-
isLink={isLink}
|
|
236
|
-
isBold={isBold}
|
|
237
|
-
isItalic={isItalic}
|
|
238
|
-
isStrikethrough={isStrikethrough}
|
|
239
|
-
isUnderline={isUnderline}
|
|
240
|
-
isCode={isCode}
|
|
241
|
-
fontColor={fontColor}
|
|
242
|
-
bgColor={bgColor}
|
|
243
|
-
blockType={blockType}
|
|
244
|
-
fontFamily={fontFamily}
|
|
245
|
-
setIsLinkEditMode={setIsLinkEditMode}
|
|
246
|
-
isUppercase={isUppercase}
|
|
247
|
-
rootType={rootType}
|
|
248
|
-
textAlign={textAlign}
|
|
249
|
-
isLowercase={isLowercase}
|
|
250
|
-
isCapitalize={isCapitalize}
|
|
251
|
-
isSubscript={isSubscript}
|
|
252
|
-
fontSize={fontSize}
|
|
253
|
-
isSuperscript={isSuperscript}
|
|
254
|
-
/>
|
|
255
|
-
</div>,
|
|
256
|
-
anchorElem
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
export default function FloatingTextFormatToolbarPlugin({
|
|
262
|
-
anchorElem = document.body,
|
|
263
|
-
setIsLinkEditMode,
|
|
264
|
-
}: {
|
|
265
|
-
anchorElem?: HTMLElement;
|
|
266
|
-
setIsLinkEditMode: Dispatch<boolean>;
|
|
267
|
-
}): React.JSX.Element | null {
|
|
268
|
-
const [editor] = useLexicalComposerContext();
|
|
269
|
-
|
|
270
|
-
return useFloatingTextFormatToolbar(editor, anchorElem, setIsLinkEditMode);
|
|
271
|
-
|
|
272
|
-
// if (editor.isEditable())
|
|
273
|
-
// return useFloatingTextFormatToolbar(editor, anchorElem, setIsLinkEditMode);
|
|
274
|
-
// else return useFloatingTextReadMode(editor, anchorElem);
|
|
275
|
-
}
|
|
@@ -1,351 +0,0 @@
|
|
|
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 {Position} from '../../nodes/InlineImageNode/InlineImageNode';
|
|
9
|
-
import type {JSX} from 'react';
|
|
10
|
-
|
|
11
|
-
import '../../nodes/InlineImageNode/InlineImageNode.css';
|
|
12
|
-
|
|
13
|
-
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
14
|
-
import {$wrapNodeInElement, mergeRegister} from '@lexical/utils';
|
|
15
|
-
import {
|
|
16
|
-
$createParagraphNode,
|
|
17
|
-
$createRangeSelection,
|
|
18
|
-
$getSelection,
|
|
19
|
-
$insertNodes,
|
|
20
|
-
$isNodeSelection,
|
|
21
|
-
$isRootOrShadowRoot,
|
|
22
|
-
$setSelection,
|
|
23
|
-
COMMAND_PRIORITY_EDITOR,
|
|
24
|
-
COMMAND_PRIORITY_HIGH,
|
|
25
|
-
COMMAND_PRIORITY_LOW,
|
|
26
|
-
createCommand,
|
|
27
|
-
DRAGOVER_COMMAND,
|
|
28
|
-
DRAGSTART_COMMAND,
|
|
29
|
-
DROP_COMMAND,
|
|
30
|
-
getDOMSelectionFromTarget,
|
|
31
|
-
isHTMLElement,
|
|
32
|
-
LexicalCommand,
|
|
33
|
-
LexicalEditor,
|
|
34
|
-
} from 'lexical';
|
|
35
|
-
import * as React from 'react';
|
|
36
|
-
import {useEffect, useRef, useState} from 'react';
|
|
37
|
-
|
|
38
|
-
import {
|
|
39
|
-
$createInlineImageNode,
|
|
40
|
-
$isInlineImageNode,
|
|
41
|
-
InlineImageNode,
|
|
42
|
-
InlineImagePayload,
|
|
43
|
-
} from '../../nodes/InlineImageNode/InlineImageNode';
|
|
44
|
-
import { Button } from '@/components/ui/button';
|
|
45
|
-
import TextInput from '@/components/ui/TextInput';
|
|
46
|
-
import FileInput from '@/components/ui/FileInput';
|
|
47
|
-
import Select from '@/components/ui/Select';
|
|
48
|
-
import { DialogActions } from '@/components/ui/dialog/Dialog';
|
|
49
|
-
|
|
50
|
-
export type InsertInlineImagePayload = Readonly<InlineImagePayload>;
|
|
51
|
-
|
|
52
|
-
export const INSERT_INLINE_IMAGE_COMMAND: LexicalCommand<InlineImagePayload> =
|
|
53
|
-
createCommand('INSERT_INLINE_IMAGE_COMMAND');
|
|
54
|
-
|
|
55
|
-
export function InsertInlineImageDialog({
|
|
56
|
-
activeEditor,
|
|
57
|
-
onClose,
|
|
58
|
-
}: {
|
|
59
|
-
activeEditor: LexicalEditor;
|
|
60
|
-
onClose: () => void;
|
|
61
|
-
}): JSX.Element {
|
|
62
|
-
const hasModifier = useRef(false);
|
|
63
|
-
|
|
64
|
-
const [src, setSrc] = useState('');
|
|
65
|
-
const [altText, setAltText] = useState('');
|
|
66
|
-
const [showCaption, setShowCaption] = useState(false);
|
|
67
|
-
const [position, setPosition] = useState<Position>('left');
|
|
68
|
-
|
|
69
|
-
const isDisabled = src === '';
|
|
70
|
-
|
|
71
|
-
const handleShowCaptionChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
72
|
-
setShowCaption(e.target.checked);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const handlePositionChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
76
|
-
setPosition(e.target.value as Position);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const loadImage = (files: FileList | null) => {
|
|
80
|
-
const reader = new FileReader();
|
|
81
|
-
reader.onload = function () {
|
|
82
|
-
if (typeof reader.result === 'string') {
|
|
83
|
-
setSrc(reader.result);
|
|
84
|
-
}
|
|
85
|
-
return '';
|
|
86
|
-
};
|
|
87
|
-
if (files !== null) {
|
|
88
|
-
reader.readAsDataURL(files[0]);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
hasModifier.current = false;
|
|
94
|
-
const handler = (e: KeyboardEvent) => {
|
|
95
|
-
hasModifier.current = e.altKey;
|
|
96
|
-
};
|
|
97
|
-
document.addEventListener('keydown', handler);
|
|
98
|
-
return () => {
|
|
99
|
-
document.removeEventListener('keydown', handler);
|
|
100
|
-
};
|
|
101
|
-
}, [activeEditor]);
|
|
102
|
-
|
|
103
|
-
const handleOnClick = () => {
|
|
104
|
-
const payload = {altText, position, showCaption, src};
|
|
105
|
-
activeEditor.dispatchCommand(INSERT_INLINE_IMAGE_COMMAND, payload);
|
|
106
|
-
onClose();
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<>
|
|
111
|
-
<div style={{marginBottom: '1em'}}>
|
|
112
|
-
<FileInput
|
|
113
|
-
label="Image Upload"
|
|
114
|
-
onChange={loadImage}
|
|
115
|
-
accept="image/*"
|
|
116
|
-
data-test-id="image-modal-file-upload"
|
|
117
|
-
/>
|
|
118
|
-
</div>
|
|
119
|
-
<div style={{marginBottom: '1em'}}>
|
|
120
|
-
<TextInput
|
|
121
|
-
label="Alt Text"
|
|
122
|
-
placeholder="Descriptive alternative text"
|
|
123
|
-
onChange={setAltText}
|
|
124
|
-
value={altText}
|
|
125
|
-
data-test-id="image-modal-alt-text-input"
|
|
126
|
-
/>
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<Select
|
|
130
|
-
style={{marginBottom: '1em', width: '290px'}}
|
|
131
|
-
label="Position"
|
|
132
|
-
name="position"
|
|
133
|
-
id="position-select"
|
|
134
|
-
onChange={handlePositionChange}>
|
|
135
|
-
<option value="left">Left</option>
|
|
136
|
-
<option value="right">Right</option>
|
|
137
|
-
<option value="full">Full Width</option>
|
|
138
|
-
</Select>
|
|
139
|
-
|
|
140
|
-
<div className="Input__wrapper">
|
|
141
|
-
<input
|
|
142
|
-
id="caption"
|
|
143
|
-
className="InlineImageNode_Checkbox"
|
|
144
|
-
type="checkbox"
|
|
145
|
-
checked={showCaption}
|
|
146
|
-
onChange={handleShowCaptionChange}
|
|
147
|
-
/>
|
|
148
|
-
<label htmlFor="caption">Show Caption</label>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
|
-
<DialogActions>
|
|
152
|
-
<Button
|
|
153
|
-
data-test-id="image-modal-file-upload-btn"
|
|
154
|
-
disabled={isDisabled}
|
|
155
|
-
onClick={() => handleOnClick()}>
|
|
156
|
-
Confirm
|
|
157
|
-
</Button>
|
|
158
|
-
</DialogActions>
|
|
159
|
-
</>
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default function InlineImagePlugin(): JSX.Element | null {
|
|
164
|
-
const [editor] = useLexicalComposerContext();
|
|
165
|
-
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
if (!editor.hasNodes([InlineImageNode])) {
|
|
168
|
-
throw new Error('ImagesPlugin: ImageNode not registered on editor');
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return mergeRegister(
|
|
172
|
-
editor.registerCommand<InsertInlineImagePayload>(
|
|
173
|
-
INSERT_INLINE_IMAGE_COMMAND,
|
|
174
|
-
(payload) => {
|
|
175
|
-
const imageNode = $createInlineImageNode(payload);
|
|
176
|
-
$insertNodes([imageNode]);
|
|
177
|
-
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
178
|
-
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return true;
|
|
182
|
-
},
|
|
183
|
-
COMMAND_PRIORITY_EDITOR,
|
|
184
|
-
),
|
|
185
|
-
editor.registerCommand<DragEvent>(
|
|
186
|
-
DRAGSTART_COMMAND,
|
|
187
|
-
(event) => {
|
|
188
|
-
return $onDragStart(event);
|
|
189
|
-
},
|
|
190
|
-
COMMAND_PRIORITY_HIGH,
|
|
191
|
-
),
|
|
192
|
-
editor.registerCommand<DragEvent>(
|
|
193
|
-
DRAGOVER_COMMAND,
|
|
194
|
-
(event) => {
|
|
195
|
-
return $onDragover(event);
|
|
196
|
-
},
|
|
197
|
-
COMMAND_PRIORITY_LOW,
|
|
198
|
-
),
|
|
199
|
-
editor.registerCommand<DragEvent>(
|
|
200
|
-
DROP_COMMAND,
|
|
201
|
-
(event) => {
|
|
202
|
-
return $onDrop(event, editor);
|
|
203
|
-
},
|
|
204
|
-
COMMAND_PRIORITY_HIGH,
|
|
205
|
-
),
|
|
206
|
-
);
|
|
207
|
-
}, [editor]);
|
|
208
|
-
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const TRANSPARENT_IMAGE =
|
|
213
|
-
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
|
214
|
-
|
|
215
|
-
// Create the transparent image lazily when needed
|
|
216
|
-
function getTransparentImage(): HTMLImageElement {
|
|
217
|
-
if (typeof document === 'undefined') {
|
|
218
|
-
// Return a mock object for SSR
|
|
219
|
-
return {} as HTMLImageElement;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const img = document.createElement('img');
|
|
223
|
-
img.src = TRANSPARENT_IMAGE;
|
|
224
|
-
return img;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function $onDragStart(event: DragEvent): boolean {
|
|
228
|
-
const node = $getImageNodeInSelection();
|
|
229
|
-
if (!node) {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
const dataTransfer = event.dataTransfer;
|
|
233
|
-
if (!dataTransfer) {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
dataTransfer.setData('text/plain', '_');
|
|
238
|
-
|
|
239
|
-
// Only create the image if document is available
|
|
240
|
-
if (typeof document !== 'undefined') {
|
|
241
|
-
const img = getTransparentImage();
|
|
242
|
-
dataTransfer.setDragImage(img, 0, 0);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
dataTransfer.setData(
|
|
246
|
-
'application/x-lexical-drag',
|
|
247
|
-
JSON.stringify({
|
|
248
|
-
data: {
|
|
249
|
-
altText: node.__altText,
|
|
250
|
-
caption: node.__caption,
|
|
251
|
-
height: node.__height,
|
|
252
|
-
key: node.getKey(),
|
|
253
|
-
showCaption: node.__showCaption,
|
|
254
|
-
src: node.__src,
|
|
255
|
-
width: node.__width,
|
|
256
|
-
},
|
|
257
|
-
type: 'image',
|
|
258
|
-
}),
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function $onDragover(event: DragEvent): boolean {
|
|
265
|
-
const node = $getImageNodeInSelection();
|
|
266
|
-
if (!node) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
if (!canDropImage(event)) {
|
|
270
|
-
event.preventDefault();
|
|
271
|
-
}
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function $onDrop(event: DragEvent, editor: LexicalEditor): boolean {
|
|
276
|
-
const node = $getImageNodeInSelection();
|
|
277
|
-
if (!node) {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
const data = getDragImageData(event);
|
|
281
|
-
if (!data) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
event.preventDefault();
|
|
285
|
-
if (canDropImage(event)) {
|
|
286
|
-
const range = getDragSelection(event);
|
|
287
|
-
node.remove();
|
|
288
|
-
const rangeSelection = $createRangeSelection();
|
|
289
|
-
if (range !== null && range !== undefined) {
|
|
290
|
-
rangeSelection.applyDOMRange(range);
|
|
291
|
-
}
|
|
292
|
-
$setSelection(rangeSelection);
|
|
293
|
-
editor.dispatchCommand(INSERT_INLINE_IMAGE_COMMAND, data);
|
|
294
|
-
}
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function $getImageNodeInSelection(): InlineImageNode | null {
|
|
299
|
-
const selection = $getSelection();
|
|
300
|
-
if (!$isNodeSelection(selection)) {
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
const nodes = selection.getNodes();
|
|
304
|
-
const node = nodes[0];
|
|
305
|
-
return $isInlineImageNode(node) ? node : null;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function getDragImageData(event: DragEvent): null | InsertInlineImagePayload {
|
|
309
|
-
const dragData = event.dataTransfer?.getData('application/x-lexical-drag');
|
|
310
|
-
if (!dragData) {
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
const {type, data} = JSON.parse(dragData);
|
|
314
|
-
if (type !== 'image') {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return data;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
declare global {
|
|
322
|
-
interface DragEvent {
|
|
323
|
-
rangeOffset?: number;
|
|
324
|
-
rangeParent?: Node;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function canDropImage(event: DragEvent): boolean {
|
|
329
|
-
const target = event.target;
|
|
330
|
-
return !!(
|
|
331
|
-
isHTMLElement(target) &&
|
|
332
|
-
!target.closest('code, span.editor-image') &&
|
|
333
|
-
isHTMLElement(target.parentElement) &&
|
|
334
|
-
target.parentElement.closest('div.ContentEditable__root')
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function getDragSelection(event: DragEvent): Range | null | undefined {
|
|
339
|
-
let range;
|
|
340
|
-
const domSelection = getDOMSelectionFromTarget(event.target);
|
|
341
|
-
if (document.caretRangeFromPoint) {
|
|
342
|
-
range = document.caretRangeFromPoint(event.clientX, event.clientY);
|
|
343
|
-
} else if (event.rangeParent && domSelection !== null) {
|
|
344
|
-
domSelection.collapse(event.rangeParent, event.rangeOffset || 0);
|
|
345
|
-
range = domSelection.getRangeAt(0);
|
|
346
|
-
} else {
|
|
347
|
-
throw Error('Cannot get the selection when dragging');
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return range;
|
|
351
|
-
}
|