@collabchron/notiq 1.1.11 → 1.2.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.
Files changed (152) hide show
  1. package/dist/AICommandBarPlugin-ZEC755KY.mjs +27 -0
  2. package/dist/{AIDialog-2WZUFWSC.mjs → AIDialog-HJW6PQPR.mjs} +12 -13
  3. package/dist/{AudioComponent-CKLMLB5T.mjs → AudioComponent-W5XMZPQB.mjs} +10 -6
  4. package/dist/{DynamicBlockComponent-2LOADZUX.mjs → DynamicBlockComponent-CHRL2GAQ.mjs} +7 -6
  5. package/dist/{EquationComponent-4NFG55NQ.mjs → EquationComponent-GNQHG53L.mjs} +26 -7
  6. package/dist/{ExcalidrawComponent-SIMURTCA.mjs → ExcalidrawComponent-POMYXDSG.mjs} +34 -7
  7. package/dist/{FileComponent-Y56MX5QD.mjs → FileComponent-EOVCH4V5.mjs} +9 -5
  8. package/dist/{HintComponet-ET7M2Q7S.mjs → HintComponet-QXL5ESND.mjs} +32 -8
  9. package/dist/{InlineImageComponent-FVTA4LXZ.mjs → InlineImageComponent-KDN3VGZC.mjs} +8 -3
  10. package/dist/{StoryBuilderComponent-WQSNFPMM.mjs → StoryBuilderComponent-CBRFPFTR.mjs} +9 -10
  11. package/dist/{chunk-6UVNHT3T.mjs → chunk-4SYRK2NH.mjs} +23 -1
  12. package/dist/chunk-5CJZC5IB.mjs +9086 -0
  13. package/dist/{chunk-MW6MAUY3.mjs → chunk-6NK5DONB.mjs} +1 -1
  14. package/dist/{chunk-N6ILV6NF.mjs → chunk-ACW4DLVO.mjs} +21 -7
  15. package/dist/chunk-BCGD2YXP.mjs +574 -0
  16. package/dist/{chunk-TC3IISJZ.mjs → chunk-BTR3TPIN.mjs} +18 -5
  17. package/dist/{chunk-XAVQAXOJ.mjs → chunk-CQCS5YPS.mjs} +3 -5
  18. package/dist/{chunk-YTLUQJE2.mjs → chunk-D4UBNSUW.mjs} +1 -1
  19. package/dist/{chunk-KNW2CGIP.mjs → chunk-DBRZIA43.mjs} +4 -1
  20. package/dist/{chunk-CDAMHK63.mjs → chunk-GJK2L7ZM.mjs} +23 -2
  21. package/dist/{chunk-GYYLZ3MQ.mjs → chunk-IKYVBTCJ.mjs} +43 -20
  22. package/dist/chunk-IXRA5D53.mjs +10447 -0
  23. package/dist/{chunk-W6VQSFE5.mjs → chunk-J2CEQXG4.mjs} +1 -1
  24. package/dist/{chunk-43Z4Z2KD.mjs → chunk-JTNLN4JI.mjs} +1 -1
  25. package/dist/{chunk-OE5JRLCN.mjs → chunk-ONOHG5NB.mjs} +6 -4
  26. package/dist/{chunk-XZXGYNTY.mjs → chunk-OO42URWA.mjs} +27 -6
  27. package/dist/chunk-PBVRSNGU.mjs +129 -0
  28. package/dist/chunk-QCS57TIF.mjs +1794 -0
  29. package/dist/chunk-RNEIJRUS.mjs +60 -0
  30. package/dist/chunk-TJPTGECP.mjs +1556 -0
  31. package/dist/{chunk-XYMXGU4T.mjs → chunk-TMYRA2W4.mjs} +1 -1
  32. package/dist/{chunk-ZFV2HGD3.mjs → chunk-UNEFOZTS.mjs} +1 -1
  33. package/dist/chunk-X4NI7EQS.mjs +282 -0
  34. package/dist/chunk-XAJ4GACN.mjs +746 -0
  35. package/dist/{chunk-7QRJVZQY.mjs → chunk-YVUQRJVV.mjs} +63 -18
  36. package/dist/components/editor/Core.d.ts +15 -2
  37. package/dist/components/editor/index.d.ts +16 -5
  38. package/dist/components/editor/nodes/EquationNode/EquationNode.d.ts +1 -0
  39. package/dist/components/editor/nodes/Hint/index.d.ts +2 -1
  40. package/dist/components/editor/plugins/AICommandBarPlugin/index.d.ts +73 -1
  41. package/dist/components/editor/plugins/DraggableBlockPlugin/index.d.ts +25 -3
  42. package/dist/components/editor/plugins/InlineCopilotPlugin/index.d.ts +16 -3
  43. package/dist/components/editor/plugins/LinkWithMetaData/index.d.ts +20 -25
  44. package/dist/components/editor/plugins/MarkdownPastePlugin/index.d.ts +5 -0
  45. package/dist/components/editor/plugins/MarkdownTransformers/index.d.ts +2 -0
  46. package/dist/components/editor/plugins/SlashCommand/index.d.ts +18 -1
  47. package/dist/components/editor/plugins/SmartTypographyPlugin/index.d.ts +26 -0
  48. package/dist/components/editor/utils/aiStream.d.ts +27 -0
  49. package/dist/components/editor/utils/excalidrawDiagramBuilder.d.ts +29 -0
  50. package/dist/components/editor/utils/markdownTransformers.d.ts +4 -1
  51. package/dist/components/editor/utils/url.d.ts +16 -4
  52. package/dist/components/providers/AIContext.d.ts +8 -0
  53. package/dist/components/ui/equation/equationTypography.d.ts +23 -0
  54. package/dist/core/extension.d.ts +3 -1
  55. package/dist/core/extensions/blocks-kit.d.ts +22 -1
  56. package/dist/core/extensions/copilot-and-collab.d.ts +15 -1
  57. package/dist/core/index.d.ts +2 -1
  58. package/dist/core/react/NotiqContent.d.ts +4 -1
  59. package/dist/core/react/NotiqEditor.d.ts +8 -8
  60. package/dist/core/react/index.d.ts +1 -0
  61. package/dist/core/react/node-renderers.d.ts +73 -0
  62. package/dist/core/types.d.ts +1 -0
  63. package/dist/core.js +18136 -9084
  64. package/dist/core.mjs +58 -44
  65. package/dist/hooks/instructions-messages.d.ts +13 -4
  66. package/dist/{image-TPW7PZZK.mjs → image-AL6PHM2A.mjs} +18 -13
  67. package/dist/index.js +15180 -12858
  68. package/dist/index.mjs +121 -1641
  69. package/dist/{insert-audio-C66RZRKY.mjs → insert-audio-CRWR7EO5.mjs} +6 -8
  70. package/dist/{insert-file-3DTGRO7W.mjs → insert-file-I73AZW3L.mjs} +6 -8
  71. package/dist/{insert-gif-FIMCCBAI.mjs → insert-gif-KWRC3ACT.mjs} +4 -4
  72. package/dist/{insert-image-CZV6HWQZ.mjs → insert-image-XIY6BGW5.mjs} +6 -5
  73. package/dist/{insert-poll-6BCIFY5G.mjs → insert-poll-J5YVZNZ4.mjs} +4 -3
  74. package/dist/{insert-table-ZRJP6X52.mjs → insert-table-OIMJRFFK.mjs} +1 -1
  75. package/dist/{poll-component-VHMM5KKZ.mjs → poll-component-TVHXIKGQ.mjs} +3 -2
  76. package/dist/react.js +17933 -9531
  77. package/dist/react.mjs +41 -34
  78. package/dist/{stepper-4AO5XMO7.mjs → stepper-ILF7YXTO.mjs} +64 -74
  79. package/dist/styles/notiq.css +1 -1
  80. package/package.json +2 -2
  81. package/src/styles/notiq.css +20 -0
  82. package/dist/AICommandBarPlugin-TADJ3X2Y.mjs +0 -12
  83. package/dist/CodeActionMenuPlugin-MRKY67ED.mjs +0 -14
  84. package/dist/CollaborationPlugin-TIZOQBUT.mjs +0 -405
  85. package/dist/CollaboratorsBar-TMKBOBJI.mjs +0 -20
  86. package/dist/CommentsPlugin-5M4RD6YO.mjs +0 -19
  87. package/dist/ExcalidrawPlugin-2SGPIQ6U.mjs +0 -14
  88. package/dist/ExportPlugin-OKZOLBGS.mjs +0 -42
  89. package/dist/FloatingLinkEditorPlugin-MABB34L7.mjs +0 -12
  90. package/dist/FloatingTextFormatToolbarPlugin-SO5VON7Q.mjs +0 -45
  91. package/dist/InlineCopilotPlugin-PNS5Y6OO.mjs +0 -360
  92. package/dist/MobileToolbar-JKP2MLQJ.mjs +0 -984
  93. package/dist/SlashCommand-2TNOOUBM.mjs +0 -39
  94. package/dist/TableCellActionMenuPlugin-YWBA64J7.mjs +0 -838
  95. package/dist/TableHoverActionsPlugin-2EIXHEXN.mjs +0 -265
  96. package/dist/TemplatePlugin-HNTPEXBB.mjs +0 -9
  97. package/dist/ToolbarPlugin-IIAOU4P5.mjs +0 -35
  98. package/dist/VersionHistoryPlugin-23MAZB4G.mjs +0 -371
  99. package/dist/background-color-OZJCBYCT.mjs +0 -425
  100. package/dist/block-format-MTSIXWID.mjs +0 -14
  101. package/dist/chunk-2KESP7OU.mjs +0 -809
  102. package/dist/chunk-3AHNLIME.mjs +0 -1701
  103. package/dist/chunk-3IILA3IP.mjs +0 -28
  104. package/dist/chunk-4DVIYZVB.mjs +0 -193
  105. package/dist/chunk-4FFTOZGJ.mjs +0 -103
  106. package/dist/chunk-4UMUPCDK.mjs +0 -68
  107. package/dist/chunk-6D6QLRYR.mjs +0 -238
  108. package/dist/chunk-6SRMKQSD.mjs +0 -682
  109. package/dist/chunk-ACV47ZKE.mjs +0 -201
  110. package/dist/chunk-AYNKORDO.mjs +0 -6
  111. package/dist/chunk-BGV62GC2.mjs +0 -26
  112. package/dist/chunk-D3IOUQFR.mjs +0 -441
  113. package/dist/chunk-EEBA6OAH.mjs +0 -59
  114. package/dist/chunk-EIZMKFHF.mjs +0 -32
  115. package/dist/chunk-EVPWKNE4.mjs +0 -27
  116. package/dist/chunk-FMJ7DGWP.mjs +0 -144
  117. package/dist/chunk-FYLRS4BG.mjs +0 -88
  118. package/dist/chunk-HOZ4QRFV.mjs +0 -536
  119. package/dist/chunk-IAFCQV3Z.mjs +0 -349
  120. package/dist/chunk-IU2N42JJ.mjs +0 -1763
  121. package/dist/chunk-J6ZUY5BY.mjs +0 -202
  122. package/dist/chunk-K5OAFEVY.mjs +0 -191
  123. package/dist/chunk-KDA7ZYMJ.mjs +0 -431
  124. package/dist/chunk-KXRLARGI.mjs +0 -26
  125. package/dist/chunk-LAUAYRPC.mjs +0 -944
  126. package/dist/chunk-LLCP7NVE.mjs +0 -449
  127. package/dist/chunk-LU2XWLOE.mjs +0 -219
  128. package/dist/chunk-MPTE332I.mjs +0 -787
  129. package/dist/chunk-MTQZWJHR.mjs +0 -111
  130. package/dist/chunk-OXWTZV3U.mjs +0 -174
  131. package/dist/chunk-PD5K4AGP.mjs +0 -64
  132. package/dist/chunk-PFH63ZU4.mjs +0 -33
  133. package/dist/chunk-PHRVYPVM.mjs +0 -808
  134. package/dist/chunk-R7WFRENU.mjs +0 -262
  135. package/dist/chunk-RAVYEEIC.mjs +0 -36
  136. package/dist/chunk-RJQTA6HG.mjs +0 -358
  137. package/dist/chunk-SAOJHVPE.mjs +0 -153
  138. package/dist/chunk-VGAX6YEY.mjs +0 -399
  139. package/dist/chunk-W6GAJXUS.mjs +0 -334
  140. package/dist/chunk-XYDBUQ6Z.mjs +0 -1978
  141. package/dist/chunk-XYT6XM5S.mjs +0 -496
  142. package/dist/chunk-YDDBQZ77.mjs +0 -409
  143. package/dist/chunk-YE7M2VKR.mjs +0 -132
  144. package/dist/chunk-Z6JAFF55.mjs +0 -555
  145. package/dist/chunk-ZKZ7MLSS.mjs +0 -165
  146. package/dist/color-23323E3B.mjs +0 -13
  147. package/dist/font-IJKFR4BM.mjs +0 -12
  148. package/dist/font-size-GTL6UVQL.mjs +0 -15
  149. package/dist/insert-node-MA3FXEYN.mjs +0 -245
  150. package/dist/table-dropdown-4VCRSQB6.mjs +0 -391
  151. package/dist/text-align-CSDLJUDA.mjs +0 -121
  152. package/dist/text-format-6L5N3CHZ.mjs +0 -15
@@ -1,201 +0,0 @@
1
- import {
2
- $createCollapsibleContainerNode,
3
- $createCollapsibleContentNode,
4
- $createCollapsibleTitleNode,
5
- $isCollapsibleContainerNode,
6
- $isCollapsibleContentNode,
7
- $isCollapsibleTitleNode,
8
- CollapsibleContainerNode,
9
- CollapsibleContentNode,
10
- CollapsibleTitleNode
11
- } from "./chunk-4DVIYZVB.mjs";
12
- import {
13
- init_react_shim
14
- } from "./chunk-WYCFGRFJ.mjs";
15
-
16
- // src/components/editor/plugins/CollapsiblePlugin/index.ts
17
- init_react_shim();
18
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
19
- import { $findMatchingParent, mergeRegister } from "@lexical/utils";
20
- import {
21
- $createParagraphNode,
22
- $getNodeByKey,
23
- $getPreviousSelection,
24
- $getSelection,
25
- $isElementNode,
26
- $isRangeSelection,
27
- $setSelection,
28
- COMMAND_PRIORITY_EDITOR,
29
- COMMAND_PRIORITY_LOW,
30
- createCommand,
31
- DELETE_CHARACTER_COMMAND,
32
- INSERT_PARAGRAPH_COMMAND,
33
- KEY_ARROW_DOWN_COMMAND
34
- } from "lexical";
35
- import { useEffect } from "react";
36
- var INSERT_COLLAPSIBLE_COMMAND = createCommand();
37
- var TOGGLE_COLLAPSIBLE_COMMAND = createCommand();
38
- function CollapsiblePlugin() {
39
- const [editor] = useLexicalComposerContext();
40
- useEffect(() => {
41
- if (!editor.hasNodes([
42
- CollapsibleContainerNode,
43
- CollapsibleTitleNode,
44
- CollapsibleContentNode
45
- ])) {
46
- throw new Error(
47
- "CollapsiblePlugin: CollapsibleContainerNode, CollapsibleTitleNode, or CollapsibleContentNode not registered on editor"
48
- );
49
- }
50
- return mergeRegister(
51
- // Structure enforcing transformers for each node type. In case nesting structure is not
52
- // "Container > Title + Content" it'll unwrap nodes and convert it back
53
- // to regular content.
54
- editor.registerNodeTransform(CollapsibleContentNode, (node) => {
55
- const parent = node.getParent();
56
- if (!$isCollapsibleContainerNode(parent)) {
57
- const children = node.getChildren();
58
- for (const child of children) {
59
- node.insertAfter(child);
60
- }
61
- node.remove();
62
- }
63
- }),
64
- editor.registerNodeTransform(CollapsibleTitleNode, (node) => {
65
- const parent = node.getParent();
66
- if (!$isCollapsibleContainerNode(parent)) {
67
- node.replace($createParagraphNode().append(...node.getChildren()));
68
- }
69
- }),
70
- editor.registerNodeTransform(CollapsibleContainerNode, (node) => {
71
- const children = node.getChildren();
72
- if (children.length !== 2 || !$isCollapsibleTitleNode(children[0]) || !$isCollapsibleContentNode(children[1])) {
73
- for (const child of children) {
74
- node.insertAfter(child);
75
- }
76
- node.remove();
77
- }
78
- }),
79
- // This handles the case when container is collapsed and we delete its previous sibling
80
- // into it, it would cause collapsed content deleted (since it's display: none, and selection
81
- // swallows it when deletes single char). Instead we expand container, which is although
82
- // not perfect, but avoids bigger problem
83
- editor.registerCommand(
84
- DELETE_CHARACTER_COMMAND,
85
- () => {
86
- const selection = $getSelection();
87
- if (!$isRangeSelection(selection) || !selection.isCollapsed() || selection.anchor.offset !== 0) {
88
- return false;
89
- }
90
- const anchorNode = selection.anchor.getNode();
91
- const topLevelElement = anchorNode.getTopLevelElement();
92
- if (topLevelElement === null) {
93
- return false;
94
- }
95
- const container = topLevelElement.getPreviousSibling();
96
- if (!$isCollapsibleContainerNode(container) || container.getOpen()) {
97
- return false;
98
- }
99
- container.setOpen(true);
100
- return true;
101
- },
102
- COMMAND_PRIORITY_LOW
103
- ),
104
- // When collapsible is the last child pressing down arrow will insert paragraph
105
- // below it to allow adding more content. It's similar what $insertBlockNode
106
- // (mainly for decorators), except it'll always be possible to continue adding
107
- // new content even if trailing paragraph is accidentally deleted
108
- editor.registerCommand(
109
- KEY_ARROW_DOWN_COMMAND,
110
- () => {
111
- const selection = $getSelection();
112
- if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
113
- return false;
114
- }
115
- const container = $findMatchingParent(
116
- selection.anchor.getNode(),
117
- $isCollapsibleContainerNode
118
- );
119
- if (container === null) {
120
- return false;
121
- }
122
- const parent = container.getParent();
123
- if (parent !== null && parent.getLastChild() === container) {
124
- parent.append($createParagraphNode());
125
- }
126
- return false;
127
- },
128
- COMMAND_PRIORITY_LOW
129
- ),
130
- // Handling CMD+Enter to toggle collapsible element collapsed state
131
- editor.registerCommand(
132
- INSERT_PARAGRAPH_COMMAND,
133
- () => {
134
- var _a;
135
- const windowEvent = (_a = editor._window) == null ? void 0 : _a.event;
136
- if (windowEvent && (windowEvent.ctrlKey || windowEvent.metaKey) && windowEvent.key === "Enter") {
137
- const selection = $getPreviousSelection();
138
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
139
- const parent = $findMatchingParent(
140
- selection.anchor.getNode(),
141
- (node) => $isElementNode(node) && !node.isInline()
142
- );
143
- if ($isCollapsibleTitleNode(parent)) {
144
- const container = parent.getParent();
145
- if ($isCollapsibleContainerNode(container)) {
146
- container.toggleOpen();
147
- $setSelection(selection.clone());
148
- return true;
149
- }
150
- }
151
- }
152
- }
153
- return false;
154
- },
155
- COMMAND_PRIORITY_LOW
156
- ),
157
- editor.registerCommand(
158
- INSERT_COLLAPSIBLE_COMMAND,
159
- () => {
160
- editor.update(() => {
161
- const selection = $getSelection();
162
- if (!$isRangeSelection(selection)) {
163
- return;
164
- }
165
- const title = $createCollapsibleTitleNode();
166
- const content = $createCollapsibleContentNode().append(
167
- $createParagraphNode()
168
- );
169
- const container = $createCollapsibleContainerNode().append(
170
- title,
171
- content
172
- );
173
- selection.insertNodes([container]);
174
- title.selectStart();
175
- });
176
- return true;
177
- },
178
- COMMAND_PRIORITY_EDITOR
179
- ),
180
- editor.registerCommand(
181
- TOGGLE_COLLAPSIBLE_COMMAND,
182
- (key) => {
183
- editor.update(() => {
184
- const containerNode = $getNodeByKey(key);
185
- if ($isCollapsibleContainerNode(containerNode)) {
186
- containerNode.toggleOpen();
187
- }
188
- });
189
- return true;
190
- },
191
- COMMAND_PRIORITY_EDITOR
192
- )
193
- );
194
- }, [editor]);
195
- return null;
196
- }
197
-
198
- export {
199
- INSERT_COLLAPSIBLE_COMMAND,
200
- CollapsiblePlugin
201
- };
@@ -1,6 +0,0 @@
1
- import {
2
- init_react_shim
3
- } from "./chunk-WYCFGRFJ.mjs";
4
-
5
- // src/core/index.ts
6
- init_react_shim();
@@ -1,26 +0,0 @@
1
- import {
2
- init_react_shim
3
- } from "./chunk-WYCFGRFJ.mjs";
4
-
5
- // src/components/providers/AIContext.tsx
6
- init_react_shim();
7
- import React, { createContext, useContext } from "react";
8
- import { jsx } from "react/jsx-runtime";
9
- var AIContext = createContext({
10
- apiEndpoint: "/api/ai"
11
- });
12
- var useAI = () => useContext(AIContext);
13
- var AIProvider = ({
14
- config,
15
- children
16
- }) => {
17
- const value = React.useMemo(() => ({
18
- apiEndpoint: (config == null ? void 0 : config.apiEndpoint) || "/api/ai"
19
- }), [config]);
20
- return /* @__PURE__ */ jsx(AIContext.Provider, { value, children });
21
- };
22
-
23
- export {
24
- useAI,
25
- AIProvider
26
- };
@@ -1,441 +0,0 @@
1
- import {
2
- getSelectedNode
3
- } from "./chunk-KXRLARGI.mjs";
4
- import {
5
- Input
6
- } from "./chunk-5NRAXWYA.mjs";
7
- import {
8
- sanitizeUrl
9
- } from "./chunk-RAVYEEIC.mjs";
10
- import {
11
- Button
12
- } from "./chunk-OE5JRLCN.mjs";
13
- import {
14
- cn
15
- } from "./chunk-JHXDLYEV.mjs";
16
- import {
17
- init_react_shim
18
- } from "./chunk-WYCFGRFJ.mjs";
19
-
20
- // src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx
21
- init_react_shim();
22
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
23
- import { useCallback, useEffect, useRef, useState } from "react";
24
- import { createPortal } from "react-dom";
25
- import {
26
- $createLinkNode,
27
- $isAutoLinkNode,
28
- $isLinkNode,
29
- TOGGLE_LINK_COMMAND
30
- } from "@lexical/link";
31
- import { $findMatchingParent, mergeRegister } from "@lexical/utils";
32
- import {
33
- $getSelection,
34
- $isLineBreakNode,
35
- $isRangeSelection,
36
- CLICK_COMMAND,
37
- COMMAND_PRIORITY_CRITICAL,
38
- COMMAND_PRIORITY_HIGH,
39
- COMMAND_PRIORITY_LOW,
40
- getDOMSelection,
41
- KEY_ESCAPE_COMMAND,
42
- SELECTION_CHANGE_COMMAND
43
- } from "lexical";
44
-
45
- // src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts
46
- init_react_shim();
47
- var VERTICAL_GAP = 10;
48
- var HORIZONTAL_OFFSET = 5;
49
- function setFloatingElemPositionForLinkEditor(targetRect, floatingElem, anchorElem, verticalGap = VERTICAL_GAP, horizontalOffset = HORIZONTAL_OFFSET) {
50
- const scrollerElem = anchorElem.parentElement;
51
- if (targetRect === null || !scrollerElem) {
52
- floatingElem.style.opacity = "0";
53
- floatingElem.style.transform = "translate(-10000px, -10000px)";
54
- return;
55
- }
56
- const floatingElemRect = floatingElem.getBoundingClientRect();
57
- const anchorElementRect = anchorElem.getBoundingClientRect();
58
- const editorScrollerRect = scrollerElem.getBoundingClientRect();
59
- let top = targetRect.top - verticalGap;
60
- let left = targetRect.left - horizontalOffset;
61
- if (top < editorScrollerRect.top) {
62
- top += floatingElemRect.height + targetRect.height + verticalGap * 2;
63
- }
64
- if (left + floatingElemRect.width > editorScrollerRect.right) {
65
- left = editorScrollerRect.right - floatingElemRect.width - horizontalOffset;
66
- }
67
- top -= anchorElementRect.top;
68
- left -= anchorElementRect.left;
69
- floatingElem.style.opacity = "1";
70
- floatingElem.style.transform = `translate(${left}px, ${top}px)`;
71
- }
72
-
73
- // src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx
74
- import { Check, Edit2Icon, Link, X } from "lucide-react";
75
- import { jsx, jsxs } from "react/jsx-runtime";
76
- function preventDefault(event) {
77
- event.preventDefault();
78
- }
79
- function FloatingLinkEditor({
80
- editor,
81
- isLink,
82
- setIsLink,
83
- anchorElem,
84
- isLinkEditMode,
85
- setIsLinkEditMode
86
- }) {
87
- const editorRef = useRef(null);
88
- const inputRef = useRef(null);
89
- const [linkUrl, setLinkUrl] = useState("");
90
- const [editedLinkUrl, setEditedLinkUrl] = useState("https://");
91
- const [lastSelection, setLastSelection] = useState(
92
- null
93
- );
94
- const [urlLogo, setUrlLogo] = useState(null);
95
- const $updateLinkEditor = useCallback(() => {
96
- var _a, _b;
97
- const selection = $getSelection();
98
- if ($isRangeSelection(selection)) {
99
- const node = getSelectedNode(selection);
100
- const linkParent = $findMatchingParent(node, $isLinkNode);
101
- if (linkParent) {
102
- setLinkUrl(linkParent.getURL());
103
- } else if ($isLinkNode(node)) {
104
- setLinkUrl(node.getURL());
105
- } else {
106
- setLinkUrl("");
107
- }
108
- if (isLinkEditMode) {
109
- setEditedLinkUrl(linkUrl);
110
- }
111
- }
112
- const editorElem = editorRef.current;
113
- const nativeSelection = getDOMSelection(editor._window);
114
- const activeElement = document.activeElement;
115
- if (editorElem === null) {
116
- return;
117
- }
118
- const rootElement = editor.getRootElement();
119
- if (selection !== null && nativeSelection !== null && rootElement !== null && rootElement.contains(nativeSelection.anchorNode) && editor.isEditable()) {
120
- const domRect = (_b = (_a = nativeSelection.focusNode) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.getBoundingClientRect();
121
- if (domRect) {
122
- domRect.y += 40;
123
- setFloatingElemPositionForLinkEditor(domRect, editorElem, anchorElem);
124
- }
125
- setLastSelection(selection);
126
- } else if (!activeElement || activeElement.className !== "link-input") {
127
- if (rootElement !== null) {
128
- setFloatingElemPositionForLinkEditor(null, editorElem, anchorElem);
129
- }
130
- setLastSelection(null);
131
- setIsLinkEditMode(false);
132
- setLinkUrl("");
133
- }
134
- return true;
135
- }, [anchorElem, editor, setIsLinkEditMode, isLinkEditMode, linkUrl]);
136
- useEffect(() => {
137
- const scrollerElem = anchorElem.parentElement;
138
- const update = () => {
139
- editor.getEditorState().read(() => {
140
- $updateLinkEditor();
141
- });
142
- };
143
- window.addEventListener("resize", update);
144
- if (scrollerElem) {
145
- scrollerElem.addEventListener("scroll", update);
146
- }
147
- return () => {
148
- window.removeEventListener("resize", update);
149
- if (scrollerElem) {
150
- scrollerElem.removeEventListener("scroll", update);
151
- }
152
- };
153
- }, [anchorElem.parentElement, editor, $updateLinkEditor]);
154
- useEffect(() => {
155
- return mergeRegister(
156
- editor.registerUpdateListener(({ editorState }) => {
157
- editorState.read(() => {
158
- $updateLinkEditor();
159
- });
160
- }),
161
- editor.registerCommand(
162
- SELECTION_CHANGE_COMMAND,
163
- () => {
164
- $updateLinkEditor();
165
- return true;
166
- },
167
- COMMAND_PRIORITY_LOW
168
- ),
169
- editor.registerCommand(
170
- KEY_ESCAPE_COMMAND,
171
- () => {
172
- if (isLink) {
173
- setIsLink(false);
174
- return true;
175
- }
176
- return false;
177
- },
178
- COMMAND_PRIORITY_HIGH
179
- )
180
- );
181
- }, [editor, $updateLinkEditor, setIsLink, isLink]);
182
- useEffect(() => {
183
- editor.getEditorState().read(() => {
184
- $updateLinkEditor();
185
- });
186
- }, [editor, $updateLinkEditor]);
187
- useEffect(() => {
188
- if (isLinkEditMode && inputRef.current) {
189
- inputRef.current.focus();
190
- }
191
- }, [isLinkEditMode, isLink]);
192
- const monitorInputInteraction = (event) => {
193
- if (event.key === "Enter") {
194
- handleLinkSubmission(event);
195
- } else if (event.key === "Escape") {
196
- event.preventDefault();
197
- setIsLinkEditMode(false);
198
- }
199
- };
200
- const handleLinkSubmission = (event) => {
201
- event.preventDefault();
202
- if (lastSelection !== null) {
203
- if (linkUrl !== "") {
204
- editor.update(() => {
205
- editor.dispatchCommand(
206
- TOGGLE_LINK_COMMAND,
207
- sanitizeUrl(editedLinkUrl)
208
- );
209
- const selection = $getSelection();
210
- if ($isRangeSelection(selection)) {
211
- const parent = getSelectedNode(selection).getParent();
212
- if ($isAutoLinkNode(parent)) {
213
- const linkNode = $createLinkNode(parent.getURL(), {
214
- rel: parent.__rel,
215
- target: parent.__target,
216
- title: parent.__title
217
- });
218
- parent.replace(linkNode, true);
219
- }
220
- }
221
- });
222
- }
223
- setEditedLinkUrl("https://");
224
- setIsLinkEditMode(false);
225
- }
226
- };
227
- return /* @__PURE__ */ jsx(
228
- "div",
229
- {
230
- ref: editorRef,
231
- className: " absolute max-w-96 bg-background max-sm:mx-1 w-full border-0 top-0 left-0",
232
- children: isLinkEditMode ? /* @__PURE__ */ jsxs("div", { className: " relative w-full", children: [
233
- /* @__PURE__ */ jsx(
234
- Link,
235
- {
236
- className: cn(
237
- "size-[14px] text-muted-foreground absolute transition-colors duration-500 transform -translate-x-1/2 -translate-y-1/2 left-4 top-1/2",
238
- !!editedLinkUrl && "text-black dark:text-white"
239
- )
240
- }
241
- ),
242
- /* @__PURE__ */ jsx(
243
- Input,
244
- {
245
- placeholder: "https://",
246
- value: editedLinkUrl,
247
- onChange: (event) => {
248
- setEditedLinkUrl(event.target.value);
249
- },
250
- onKeyDown: (event) => {
251
- monitorInputInteraction(event);
252
- },
253
- ref: inputRef,
254
- className: "text-gray-900 pl-7 dark:text-gray-100 rounded-xl placeholder-gray-400 dark:placeholder-gray-500"
255
- }
256
- ),
257
- /* @__PURE__ */ jsxs("div", { className: " absolute bg-background rounded-xl flex flex-row gap-x-1 items-center transition-colors duration-500 transform -translate-y-1/2 right-2 top-1/2", children: [
258
- /* @__PURE__ */ jsx(
259
- Button,
260
- {
261
- className: " rounded-xl h-6 w-6 flex items-center",
262
- role: "button",
263
- variant: "destructive",
264
- size: "Toolbar",
265
- tip: "delete link",
266
- tabIndex: 0,
267
- onMouseDown: preventDefault,
268
- onClick: () => {
269
- setIsLinkEditMode(false);
270
- },
271
- children: /* @__PURE__ */ jsx(X, {})
272
- }
273
- ),
274
- /* @__PURE__ */ jsx(
275
- Button,
276
- {
277
- className: " rounded-xl h-6 w-6 flex items-center",
278
- role: "button",
279
- tabIndex: 0,
280
- tip: "confirm link",
281
- onMouseDown: preventDefault,
282
- onClick: handleLinkSubmission,
283
- size: "Toolbar",
284
- children: /* @__PURE__ */ jsx(Check, {})
285
- }
286
- )
287
- ] })
288
- ] }) : /* @__PURE__ */ jsxs("div", { className: "w-full border-input border rounded-xl h-9 flex items-center justify-between px-3 py-1 text-base shadow-sm ", children: [
289
- /* @__PURE__ */ jsx(
290
- Link,
291
- {
292
- className: cn(
293
- "size-[14px] text-muted-foreground absolute transition-colors duration-500 transform -translate-x-1/2 -translate-y-1/2 left-4 top-1/2",
294
- !!editedLinkUrl && "text-black dark:text-white"
295
- )
296
- }
297
- ),
298
- /* @__PURE__ */ jsx(
299
- "a",
300
- {
301
- href: sanitizeUrl(linkUrl),
302
- target: "_blank",
303
- rel: "noopener noreferrer",
304
- className: "pl-4 mb-[1px]",
305
- children: linkUrl
306
- }
307
- ),
308
- /* @__PURE__ */ jsxs("div", { className: " absolute bg-background rounded-xl flex flex-row gap-x-1 items-center transition-colors duration-500 transform -translate-y-1/2 right-2 top-1/2", children: [
309
- /* @__PURE__ */ jsx(
310
- Button,
311
- {
312
- className: " rounded-xl z-50 h-6 w-6 flex items-center",
313
- role: "button",
314
- size: "Toolbar",
315
- tip: "edit link",
316
- tabIndex: 0,
317
- onMouseDown: preventDefault,
318
- onClick: (event) => {
319
- event.preventDefault();
320
- setEditedLinkUrl(linkUrl);
321
- setIsLinkEditMode(true);
322
- },
323
- children: /* @__PURE__ */ jsx(Edit2Icon, { className: "size-4" })
324
- }
325
- ),
326
- /* @__PURE__ */ jsx(
327
- Button,
328
- {
329
- className: " rounded-xl h-6 w-6 flex items-center",
330
- role: "button",
331
- tabIndex: 0,
332
- variant: "secondary",
333
- tip: "delet link",
334
- size: "Toolbar",
335
- onMouseDown: preventDefault,
336
- onClick: () => {
337
- editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
338
- },
339
- children: /* @__PURE__ */ jsx(X, {})
340
- }
341
- )
342
- ] })
343
- ] })
344
- }
345
- );
346
- }
347
- function useFloatingLinkEditorToolbar(editor, anchorElem, isLinkEditMode, setIsLinkEditMode) {
348
- const [activeEditor, setActiveEditor] = useState(editor);
349
- const [isLink, setIsLink] = useState(false);
350
- useEffect(() => {
351
- function $updateToolbar() {
352
- const selection = $getSelection();
353
- if ($isRangeSelection(selection)) {
354
- const focusNode = getSelectedNode(selection);
355
- const focusLinkNode = $findMatchingParent(focusNode, $isLinkNode);
356
- const focusAutoLinkNode = $findMatchingParent(
357
- focusNode,
358
- $isAutoLinkNode
359
- );
360
- if (!(focusLinkNode || focusAutoLinkNode)) {
361
- setIsLink(false);
362
- return;
363
- }
364
- const badNode = selection.getNodes().filter((node) => !$isLineBreakNode(node)).find((node) => {
365
- const linkNode = $findMatchingParent(node, $isLinkNode);
366
- const autoLinkNode = $findMatchingParent(node, $isAutoLinkNode);
367
- return focusLinkNode && !focusLinkNode.is(linkNode) || linkNode && !linkNode.is(focusLinkNode) || focusAutoLinkNode && !focusAutoLinkNode.is(autoLinkNode) || autoLinkNode && (!autoLinkNode.is(focusAutoLinkNode) || autoLinkNode.getIsUnlinked());
368
- });
369
- if (!badNode) {
370
- setIsLink(true);
371
- } else {
372
- setIsLink(false);
373
- }
374
- }
375
- }
376
- return mergeRegister(
377
- editor.registerUpdateListener(({ editorState }) => {
378
- editorState.read(() => {
379
- $updateToolbar();
380
- });
381
- }),
382
- editor.registerCommand(
383
- SELECTION_CHANGE_COMMAND,
384
- (_payload, newEditor) => {
385
- $updateToolbar();
386
- setActiveEditor(newEditor);
387
- return false;
388
- },
389
- COMMAND_PRIORITY_CRITICAL
390
- ),
391
- editor.registerCommand(
392
- CLICK_COMMAND,
393
- (payload) => {
394
- const selection = $getSelection();
395
- if ($isRangeSelection(selection)) {
396
- const node = getSelectedNode(selection);
397
- const linkNode = $findMatchingParent(node, $isLinkNode);
398
- if ($isLinkNode(linkNode) && (payload.metaKey || payload.ctrlKey)) {
399
- window.open(linkNode.getURL(), "_blank");
400
- return true;
401
- }
402
- }
403
- return false;
404
- },
405
- COMMAND_PRIORITY_LOW
406
- )
407
- );
408
- }, [editor]);
409
- if (!isLink) return null;
410
- return createPortal(
411
- /* @__PURE__ */ jsx(
412
- FloatingLinkEditor,
413
- {
414
- editor: activeEditor,
415
- isLink,
416
- anchorElem,
417
- setIsLink,
418
- isLinkEditMode,
419
- setIsLinkEditMode
420
- }
421
- ),
422
- anchorElem
423
- );
424
- }
425
- function FloatingLinkEditorPlugin({
426
- anchorElem = document.body,
427
- isLinkEditMode,
428
- setIsLinkEditMode
429
- }) {
430
- const [editor] = useLexicalComposerContext();
431
- return useFloatingLinkEditorToolbar(
432
- editor,
433
- anchorElem,
434
- isLinkEditMode,
435
- setIsLinkEditMode
436
- );
437
- }
438
-
439
- export {
440
- FloatingLinkEditorPlugin
441
- };