@liveblocks/react-tiptap 2.18.3 → 2.18.4-uns1
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/dist/{LiveblocksExtension.mjs → LiveblocksExtension.cjs} +41 -38
- package/dist/{LiveblocksExtension.mjs.map → LiveblocksExtension.cjs.map} +1 -1
- package/dist/LiveblocksExtension.js +37 -40
- package/dist/LiveblocksExtension.js.map +1 -1
- package/dist/ai/{AiExtension.mjs → AiExtension.cjs} +36 -32
- package/dist/ai/AiExtension.cjs.map +1 -0
- package/dist/ai/AiExtension.js +31 -35
- package/dist/ai/AiExtension.js.map +1 -1
- package/dist/ai/{AiToolbar.mjs → AiToolbar.cjs} +145 -142
- package/dist/ai/{AiToolbar.mjs.map → AiToolbar.cjs.map} +1 -1
- package/dist/ai/AiToolbar.js +141 -144
- package/dist/ai/AiToolbar.js.map +1 -1
- package/dist/{classnames.mjs → classnames.cjs} +4 -2
- package/dist/{classnames.mjs.map → classnames.cjs.map} +1 -1
- package/dist/classnames.js +1 -3
- package/dist/classnames.js.map +1 -1
- package/dist/comments/{AnchoredThreads.mjs → AnchoredThreads.cjs} +38 -36
- package/dist/comments/{AnchoredThreads.mjs.map → AnchoredThreads.cjs.map} +1 -1
- package/dist/comments/AnchoredThreads.js +35 -37
- package/dist/comments/AnchoredThreads.js.map +1 -1
- package/dist/comments/{CommentsExtension.mjs → CommentsExtension.cjs} +34 -32
- package/dist/comments/{CommentsExtension.mjs.map → CommentsExtension.cjs.map} +1 -1
- package/dist/comments/CommentsExtension.js +31 -33
- package/dist/comments/CommentsExtension.js.map +1 -1
- package/dist/comments/{FloatingComposer.mjs → FloatingComposer.cjs} +34 -31
- package/dist/comments/{FloatingComposer.mjs.map → FloatingComposer.cjs.map} +1 -1
- package/dist/comments/FloatingComposer.js +30 -33
- package/dist/comments/FloatingComposer.js.map +1 -1
- package/dist/comments/{FloatingThreads.mjs → FloatingThreads.cjs} +39 -36
- package/dist/comments/{FloatingThreads.mjs.map → FloatingThreads.cjs.map} +1 -1
- package/dist/comments/FloatingThreads.js +35 -38
- package/dist/comments/FloatingThreads.js.map +1 -1
- package/dist/context.cjs +24 -0
- package/dist/{context.mjs.map → context.cjs.map} +1 -1
- package/dist/context.js +8 -11
- package/dist/context.js.map +1 -1
- package/dist/index.cjs +29 -0
- package/dist/{index.mjs.map → index.cjs.map} +1 -1
- package/dist/index.js +13 -27
- package/dist/index.js.map +1 -1
- package/dist/mentions/{Avatar.mjs → Avatar.cjs} +16 -14
- package/dist/mentions/Avatar.cjs.map +1 -0
- package/dist/mentions/Avatar.js +13 -15
- package/dist/mentions/Avatar.js.map +1 -1
- package/dist/mentions/Mention.cjs +31 -0
- package/dist/mentions/Mention.cjs.map +1 -0
- package/dist/mentions/Mention.js +25 -25
- package/dist/mentions/Mention.js.map +1 -1
- package/dist/mentions/{MentionExtension.mjs → MentionExtension.cjs} +35 -33
- package/dist/mentions/{MentionExtension.mjs.map → MentionExtension.cjs.map} +1 -1
- package/dist/mentions/MentionExtension.js +32 -34
- package/dist/mentions/MentionExtension.js.map +1 -1
- package/dist/mentions/{MentionNode.mjs → MentionNode.cjs} +12 -10
- package/dist/mentions/{MentionNode.mjs.map → MentionNode.cjs.map} +1 -1
- package/dist/mentions/MentionNode.js +9 -11
- package/dist/mentions/MentionNode.js.map +1 -1
- package/dist/mentions/{MentionsList.mjs → MentionsList.cjs} +39 -35
- package/dist/mentions/{MentionsList.mjs.map → MentionsList.cjs.map} +1 -1
- package/dist/mentions/MentionsList.js +34 -38
- package/dist/mentions/MentionsList.js.map +1 -1
- package/dist/toolbar/{FloatingToolbar.mjs → FloatingToolbar.cjs} +67 -64
- package/dist/toolbar/{FloatingToolbar.mjs.map → FloatingToolbar.cjs.map} +1 -1
- package/dist/toolbar/FloatingToolbar.js +63 -66
- package/dist/toolbar/FloatingToolbar.js.map +1 -1
- package/dist/toolbar/{Toolbar.mjs → Toolbar.cjs} +116 -91
- package/dist/toolbar/{Toolbar.mjs.map → Toolbar.cjs.map} +1 -1
- package/dist/toolbar/Toolbar.js +90 -115
- package/dist/toolbar/Toolbar.js.map +1 -1
- package/dist/toolbar/shared.cjs +36 -0
- package/dist/toolbar/{shared.mjs.map → shared.cjs.map} +1 -1
- package/dist/toolbar/shared.js +12 -15
- package/dist/toolbar/shared.js.map +1 -1
- package/dist/types.cjs +39 -0
- package/dist/{types.mjs.map → types.cjs.map} +1 -1
- package/dist/types.js +8 -19
- package/dist/types.js.map +1 -1
- package/dist/{utils.mjs → utils.cjs} +23 -14
- package/dist/{utils.mjs.map → utils.cjs.map} +1 -1
- package/dist/utils.js +13 -22
- package/dist/utils.js.map +1 -1
- package/dist/version-history/{HistoryVersionPreview.mjs → HistoryVersionPreview.cjs} +36 -34
- package/dist/version-history/{HistoryVersionPreview.mjs.map → HistoryVersionPreview.cjs.map} +1 -1
- package/dist/version-history/HistoryVersionPreview.js +33 -35
- package/dist/version-history/HistoryVersionPreview.js.map +1 -1
- package/dist/version.cjs +10 -0
- package/dist/{version.mjs.map → version.cjs.map} +1 -1
- package/dist/version.js +3 -7
- package/dist/version.js.map +1 -1
- package/package.json +18 -17
- package/styles.css.d.cts +1 -0
- package/dist/ai/AiExtension.mjs.map +0 -1
- package/dist/context.mjs +0 -21
- package/dist/index.mjs +0 -15
- package/dist/mentions/Avatar.mjs.map +0 -1
- package/dist/mentions/Mention.mjs +0 -27
- package/dist/mentions/Mention.mjs.map +0 -1
- package/dist/toolbar/shared.mjs +0 -33
- package/dist/types.mjs +0 -28
- package/dist/version.mjs +0 -6
- /package/dist/{index.d.mts → index.d.cts} +0 -0
package/dist/ai/AiToolbar.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var utils = require('../utils.js');
|
|
14
|
-
var AiExtension = require('./AiExtension.js');
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { hide, offset, shift, limitShift, autoUpdate, useFloating } from '@floating-ui/react-dom';
|
|
3
|
+
import { useLayoutEffect } from '@liveblocks/react/_private';
|
|
4
|
+
import { CheckIcon, UndoIcon, CrossIcon, ArrowCornerDownRightIcon, SparklesIcon, ShortcutTooltip, Button, SendIcon, WarningIcon, EditIcon, ShortenIcon, LengthenIcon, SparklesTextIcon, QuestionMarkIcon, useRefs, TooltipProvider } from '@liveblocks/react-ui/_private';
|
|
5
|
+
import { useEditorState } from '@tiptap/react';
|
|
6
|
+
import { Command, useCommandState } from 'cmdk';
|
|
7
|
+
import { createContext, useContext, forwardRef, useCallback, useRef, useMemo, useEffect, useState } from 'react';
|
|
8
|
+
import { createPortal } from 'react-dom';
|
|
9
|
+
import { classNames } from '../classnames.js';
|
|
10
|
+
import { useCurrentEditor, EditorProvider } from '../context.js';
|
|
11
|
+
import { getDomRangeFromSelection } from '../utils.js';
|
|
12
|
+
import { isContextualPromptDiffResponse, DEFAULT_STATE } from './AiExtension.js';
|
|
15
13
|
|
|
16
14
|
const AI_TOOLBAR_COLLISION_PADDING = 10;
|
|
17
|
-
const AiToolbarContext =
|
|
15
|
+
const AiToolbarContext = createContext(null);
|
|
18
16
|
function useAiToolbarContext() {
|
|
19
|
-
const context =
|
|
17
|
+
const context = useContext(AiToolbarContext);
|
|
20
18
|
if (!context) {
|
|
21
19
|
throw new Error("useAiToolbarContext must be used within an AiToolbar");
|
|
22
20
|
}
|
|
@@ -59,48 +57,48 @@ function flipToolbar() {
|
|
|
59
57
|
}
|
|
60
58
|
};
|
|
61
59
|
}
|
|
62
|
-
const AiToolbarDropdownSeparator =
|
|
63
|
-
return /* @__PURE__ */
|
|
64
|
-
className:
|
|
60
|
+
const AiToolbarDropdownSeparator = forwardRef(({ className, ...props }, forwardedRef) => {
|
|
61
|
+
return /* @__PURE__ */ jsx(Command.Separator, {
|
|
62
|
+
className: classNames("lb-dropdown-separator", className),
|
|
65
63
|
...props,
|
|
66
64
|
ref: forwardedRef
|
|
67
65
|
});
|
|
68
66
|
});
|
|
69
|
-
const AiToolbarSuggestionsSeparator =
|
|
70
|
-
return /* @__PURE__ */
|
|
67
|
+
const AiToolbarSuggestionsSeparator = forwardRef((props, forwardedRef) => {
|
|
68
|
+
return /* @__PURE__ */ jsx(AiToolbarDropdownSeparator, {
|
|
71
69
|
ref: forwardedRef,
|
|
72
70
|
...props
|
|
73
71
|
});
|
|
74
72
|
});
|
|
75
|
-
const AiToolbarDropdownItem =
|
|
76
|
-
return /* @__PURE__ */
|
|
77
|
-
className:
|
|
73
|
+
const AiToolbarDropdownItem = forwardRef(({ children, onSelect, icon, className, ...props }, forwardedRef) => {
|
|
74
|
+
return /* @__PURE__ */ jsxs(Command.Item, {
|
|
75
|
+
className: classNames("lb-dropdown-item", className),
|
|
78
76
|
onSelect,
|
|
79
77
|
...props,
|
|
80
78
|
ref: forwardedRef,
|
|
81
79
|
children: [
|
|
82
|
-
icon ? /* @__PURE__ */
|
|
80
|
+
icon ? /* @__PURE__ */ jsx("span", {
|
|
83
81
|
className: "lb-icon-container",
|
|
84
82
|
children: icon
|
|
85
83
|
}) : null,
|
|
86
|
-
children ? /* @__PURE__ */
|
|
84
|
+
children ? /* @__PURE__ */ jsx("span", {
|
|
87
85
|
className: "lb-dropdown-item-label",
|
|
88
86
|
children
|
|
89
87
|
}) : null
|
|
90
88
|
]
|
|
91
89
|
});
|
|
92
90
|
});
|
|
93
|
-
const AiToolbarSuggestionsLabel =
|
|
94
|
-
return /* @__PURE__ */
|
|
91
|
+
const AiToolbarSuggestionsLabel = forwardRef(({ children, className, ...props }, forwardedRef) => {
|
|
92
|
+
return /* @__PURE__ */ jsx("span", {
|
|
95
93
|
ref: forwardedRef,
|
|
96
|
-
className:
|
|
94
|
+
className: classNames("lb-dropdown-label", className),
|
|
97
95
|
...props,
|
|
98
96
|
children
|
|
99
97
|
});
|
|
100
98
|
});
|
|
101
|
-
const AiToolbarSuggestion =
|
|
102
|
-
const editor =
|
|
103
|
-
const handleSelect =
|
|
99
|
+
const AiToolbarSuggestion = forwardRef(({ prompt: manualPrompt, ...props }, forwardedRef) => {
|
|
100
|
+
const editor = useCurrentEditor("Suggestion", "AiToolbar");
|
|
101
|
+
const handleSelect = useCallback(
|
|
104
102
|
(prompt) => {
|
|
105
103
|
editor.commands.$startAiToolbarThinking(
|
|
106
104
|
manualPrompt ?? prompt
|
|
@@ -108,51 +106,51 @@ const AiToolbarSuggestion = react.forwardRef(({ prompt: manualPrompt, ...props }
|
|
|
108
106
|
},
|
|
109
107
|
[editor, manualPrompt]
|
|
110
108
|
);
|
|
111
|
-
return /* @__PURE__ */
|
|
109
|
+
return /* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
112
110
|
...props,
|
|
113
111
|
onSelect: handleSelect,
|
|
114
112
|
ref: forwardedRef
|
|
115
113
|
});
|
|
116
114
|
});
|
|
117
115
|
function AiToolbarReviewingSuggestions() {
|
|
118
|
-
const editor =
|
|
116
|
+
const editor = useCurrentEditor("ReviewingSuggestions", "AiToolbar");
|
|
119
117
|
const { state } = useAiToolbarContext();
|
|
120
118
|
const { response } = state;
|
|
121
|
-
if (
|
|
122
|
-
return /* @__PURE__ */
|
|
119
|
+
if (isContextualPromptDiffResponse(response)) {
|
|
120
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
123
121
|
children: [
|
|
124
|
-
/* @__PURE__ */
|
|
125
|
-
icon: /* @__PURE__ */
|
|
122
|
+
/* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
123
|
+
icon: /* @__PURE__ */ jsx(CheckIcon, {}),
|
|
126
124
|
onSelect: editor.commands.$acceptAiToolbarResponse,
|
|
127
125
|
children: "Accept"
|
|
128
126
|
}),
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
icon: /* @__PURE__ */
|
|
127
|
+
/* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
128
|
+
icon: /* @__PURE__ */ jsx(UndoIcon, {}),
|
|
131
129
|
onSelect: editor.commands.$startAiToolbarThinking,
|
|
132
130
|
children: "Try again"
|
|
133
131
|
}),
|
|
134
|
-
/* @__PURE__ */
|
|
135
|
-
icon: /* @__PURE__ */
|
|
132
|
+
/* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
133
|
+
icon: /* @__PURE__ */ jsx(CrossIcon, {}),
|
|
136
134
|
onSelect: editor.commands.$closeAiToolbar,
|
|
137
135
|
children: "Discard"
|
|
138
136
|
})
|
|
139
137
|
]
|
|
140
138
|
});
|
|
141
139
|
} else {
|
|
142
|
-
return /* @__PURE__ */
|
|
140
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
143
141
|
children: [
|
|
144
|
-
/* @__PURE__ */
|
|
145
|
-
icon: /* @__PURE__ */
|
|
142
|
+
/* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
143
|
+
icon: /* @__PURE__ */ jsx(ArrowCornerDownRightIcon, {}),
|
|
146
144
|
onSelect: editor.commands.$acceptAiToolbarResponse,
|
|
147
145
|
children: "Insert below"
|
|
148
146
|
}),
|
|
149
|
-
/* @__PURE__ */
|
|
150
|
-
icon: /* @__PURE__ */
|
|
147
|
+
/* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
148
|
+
icon: /* @__PURE__ */ jsx(UndoIcon, {}),
|
|
151
149
|
onSelect: editor.commands.$startAiToolbarThinking,
|
|
152
150
|
children: "Try again"
|
|
153
151
|
}),
|
|
154
|
-
/* @__PURE__ */
|
|
155
|
-
icon: /* @__PURE__ */
|
|
152
|
+
/* @__PURE__ */ jsx(AiToolbarDropdownItem, {
|
|
153
|
+
icon: /* @__PURE__ */ jsx(CrossIcon, {}),
|
|
156
154
|
onSelect: editor.commands.$closeAiToolbar,
|
|
157
155
|
children: "Discard"
|
|
158
156
|
})
|
|
@@ -161,16 +159,16 @@ function AiToolbarReviewingSuggestions() {
|
|
|
161
159
|
}
|
|
162
160
|
}
|
|
163
161
|
function AiToolbarCustomPromptContent() {
|
|
164
|
-
const editor =
|
|
162
|
+
const editor = useCurrentEditor("CustomPromptContent", "AiToolbar");
|
|
165
163
|
const aiName = editor.storage.liveblocksAi.name;
|
|
166
|
-
const textAreaRef =
|
|
164
|
+
const textAreaRef = useRef(null);
|
|
167
165
|
const { state, dropdownRef, isDropdownHidden } = useAiToolbarContext();
|
|
168
166
|
const { customPrompt } = state;
|
|
169
|
-
const isCustomPromptEmpty =
|
|
167
|
+
const isCustomPromptEmpty = useMemo(
|
|
170
168
|
() => customPrompt.trim() === "",
|
|
171
169
|
[customPrompt]
|
|
172
170
|
);
|
|
173
|
-
|
|
171
|
+
useLayoutEffect(
|
|
174
172
|
() => {
|
|
175
173
|
setTimeout(() => {
|
|
176
174
|
const textArea = textAreaRef.current;
|
|
@@ -209,7 +207,7 @@ function AiToolbarCustomPromptContent() {
|
|
|
209
207
|
}
|
|
210
208
|
}
|
|
211
209
|
};
|
|
212
|
-
const handleCustomPromptChange =
|
|
210
|
+
const handleCustomPromptChange = useCallback(
|
|
213
211
|
(customPrompt2) => {
|
|
214
212
|
editor.commands._updateAiToolbarCustomPrompt(
|
|
215
213
|
customPrompt2
|
|
@@ -217,7 +215,7 @@ function AiToolbarCustomPromptContent() {
|
|
|
217
215
|
},
|
|
218
216
|
[editor]
|
|
219
217
|
);
|
|
220
|
-
const handleSendClick =
|
|
218
|
+
const handleSendClick = useCallback(() => {
|
|
221
219
|
if (isCustomPromptEmpty) {
|
|
222
220
|
return;
|
|
223
221
|
}
|
|
@@ -226,21 +224,21 @@ function AiToolbarCustomPromptContent() {
|
|
|
226
224
|
state.phase === "reviewing"
|
|
227
225
|
);
|
|
228
226
|
}, [editor, customPrompt, isCustomPromptEmpty, state.phase]);
|
|
229
|
-
return /* @__PURE__ */
|
|
227
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
230
228
|
className: "lb-tiptap-ai-toolbar-content",
|
|
231
229
|
children: [
|
|
232
|
-
/* @__PURE__ */
|
|
230
|
+
/* @__PURE__ */ jsx("span", {
|
|
233
231
|
className: "lb-icon-container lb-tiptap-ai-toolbar-icon-container",
|
|
234
|
-
children: /* @__PURE__ */
|
|
232
|
+
children: /* @__PURE__ */ jsx(SparklesIcon, {})
|
|
235
233
|
}),
|
|
236
|
-
/* @__PURE__ */
|
|
234
|
+
/* @__PURE__ */ jsx("div", {
|
|
237
235
|
className: "lb-tiptap-ai-toolbar-custom-prompt-container",
|
|
238
236
|
"data-value": customPrompt,
|
|
239
|
-
children: /* @__PURE__ */
|
|
237
|
+
children: /* @__PURE__ */ jsx(Command.Input, {
|
|
240
238
|
value: customPrompt,
|
|
241
239
|
onValueChange: handleCustomPromptChange,
|
|
242
240
|
asChild: true,
|
|
243
|
-
children: /* @__PURE__ */
|
|
241
|
+
children: /* @__PURE__ */ jsx("textarea", {
|
|
244
242
|
ref: textAreaRef,
|
|
245
243
|
className: "lb-tiptap-ai-toolbar-custom-prompt",
|
|
246
244
|
placeholder: `Ask ${aiName} anything\u2026`,
|
|
@@ -250,16 +248,16 @@ function AiToolbarCustomPromptContent() {
|
|
|
250
248
|
})
|
|
251
249
|
})
|
|
252
250
|
}),
|
|
253
|
-
/* @__PURE__ */
|
|
251
|
+
/* @__PURE__ */ jsx("div", {
|
|
254
252
|
className: "lb-tiptap-ai-toolbar-actions",
|
|
255
|
-
children: /* @__PURE__ */
|
|
253
|
+
children: /* @__PURE__ */ jsx(ShortcutTooltip, {
|
|
256
254
|
content: `Ask ${aiName}`,
|
|
257
255
|
shortcut: "Enter",
|
|
258
|
-
children: /* @__PURE__ */
|
|
256
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
259
257
|
className: "lb-tiptap-ai-toolbar-action",
|
|
260
258
|
variant: "primary",
|
|
261
259
|
"aria-label": `Ask ${aiName}`,
|
|
262
|
-
icon: /* @__PURE__ */
|
|
260
|
+
icon: /* @__PURE__ */ jsx(SendIcon, {}),
|
|
263
261
|
disabled: isCustomPromptEmpty,
|
|
264
262
|
onClick: handleSendClick
|
|
265
263
|
})
|
|
@@ -271,15 +269,15 @@ function AiToolbarCustomPromptContent() {
|
|
|
271
269
|
function AiToolbarAsking() {
|
|
272
270
|
const { state } = useAiToolbarContext();
|
|
273
271
|
const { error } = state;
|
|
274
|
-
return /* @__PURE__ */
|
|
272
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
275
273
|
children: [
|
|
276
|
-
/* @__PURE__ */
|
|
277
|
-
error ? /* @__PURE__ */
|
|
274
|
+
/* @__PURE__ */ jsx(AiToolbarCustomPromptContent, {}),
|
|
275
|
+
error ? /* @__PURE__ */ jsxs("div", {
|
|
278
276
|
className: "lb-tiptap-ai-toolbar-error",
|
|
279
277
|
children: [
|
|
280
|
-
/* @__PURE__ */
|
|
278
|
+
/* @__PURE__ */ jsx("span", {
|
|
281
279
|
className: "lb-icon-container",
|
|
282
|
-
children: /* @__PURE__ */
|
|
280
|
+
children: /* @__PURE__ */ jsx(WarningIcon, {})
|
|
283
281
|
}),
|
|
284
282
|
"There was a problem with your request."
|
|
285
283
|
]
|
|
@@ -288,43 +286,43 @@ function AiToolbarAsking() {
|
|
|
288
286
|
});
|
|
289
287
|
}
|
|
290
288
|
function AiToolbarThinking() {
|
|
291
|
-
const editor =
|
|
292
|
-
const contentRef =
|
|
289
|
+
const editor = useCurrentEditor("AiToolbarThinking", "AiToolbar");
|
|
290
|
+
const contentRef = useRef(null);
|
|
293
291
|
const aiName = editor.storage.liveblocksAi.name;
|
|
294
|
-
const handleCancel =
|
|
292
|
+
const handleCancel = useCallback(() => {
|
|
295
293
|
editor.commands.$cancelAiToolbarThinking();
|
|
296
294
|
}, [editor]);
|
|
297
|
-
|
|
295
|
+
useLayoutEffect(() => {
|
|
298
296
|
contentRef.current?.focus();
|
|
299
297
|
window.getSelection()?.removeAllRanges();
|
|
300
298
|
}, []);
|
|
301
|
-
return /* @__PURE__ */
|
|
302
|
-
children: /* @__PURE__ */
|
|
299
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
300
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
303
301
|
className: "lb-tiptap-ai-toolbar-content",
|
|
304
302
|
tabIndex: 0,
|
|
305
303
|
ref: contentRef,
|
|
306
304
|
children: [
|
|
307
|
-
/* @__PURE__ */
|
|
305
|
+
/* @__PURE__ */ jsx("span", {
|
|
308
306
|
className: "lb-icon-container lb-tiptap-ai-toolbar-icon-container",
|
|
309
|
-
children: /* @__PURE__ */
|
|
307
|
+
children: /* @__PURE__ */ jsx(SparklesIcon, {})
|
|
310
308
|
}),
|
|
311
|
-
/* @__PURE__ */
|
|
309
|
+
/* @__PURE__ */ jsxs("div", {
|
|
312
310
|
className: "lb-tiptap-ai-toolbar-thinking",
|
|
313
311
|
children: [
|
|
314
312
|
aiName,
|
|
315
313
|
" is thinking\u2026"
|
|
316
314
|
]
|
|
317
315
|
}),
|
|
318
|
-
/* @__PURE__ */
|
|
316
|
+
/* @__PURE__ */ jsx("div", {
|
|
319
317
|
className: "lb-tiptap-ai-toolbar-actions",
|
|
320
|
-
children: /* @__PURE__ */
|
|
318
|
+
children: /* @__PURE__ */ jsx(ShortcutTooltip, {
|
|
321
319
|
content: "Cancel",
|
|
322
320
|
shortcut: "Escape",
|
|
323
|
-
children: /* @__PURE__ */
|
|
321
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
324
322
|
className: "lb-tiptap-ai-toolbar-action",
|
|
325
323
|
variant: "secondary",
|
|
326
324
|
"aria-label": "Cancel",
|
|
327
|
-
icon: /* @__PURE__ */
|
|
325
|
+
icon: /* @__PURE__ */ jsx(UndoIcon, {}),
|
|
328
326
|
onClick: handleCancel
|
|
329
327
|
})
|
|
330
328
|
})
|
|
@@ -336,16 +334,16 @@ function AiToolbarThinking() {
|
|
|
336
334
|
function AiToolbarReviewing() {
|
|
337
335
|
const { state } = useAiToolbarContext();
|
|
338
336
|
const { response } = state;
|
|
339
|
-
return /* @__PURE__ */
|
|
337
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
340
338
|
children: [
|
|
341
|
-
response.type === "other" ? /* @__PURE__ */
|
|
339
|
+
response.type === "other" ? /* @__PURE__ */ jsx("div", {
|
|
342
340
|
className: "lb-tiptap-ai-toolbar-response-container",
|
|
343
|
-
children: /* @__PURE__ */
|
|
341
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
344
342
|
className: "lb-tiptap-ai-toolbar-response",
|
|
345
343
|
children: response.text
|
|
346
344
|
})
|
|
347
345
|
}) : null,
|
|
348
|
-
/* @__PURE__ */
|
|
346
|
+
/* @__PURE__ */ jsx(AiToolbarCustomPromptContent, {})
|
|
349
347
|
]
|
|
350
348
|
});
|
|
351
349
|
}
|
|
@@ -355,17 +353,17 @@ function AiToolbarContainer({
|
|
|
355
353
|
dropdownRef,
|
|
356
354
|
children
|
|
357
355
|
}) {
|
|
358
|
-
const editor =
|
|
356
|
+
const editor = useCurrentEditor("AiToolbarContainer", "AiToolbar");
|
|
359
357
|
const customPrompt = state.customPrompt;
|
|
360
|
-
const isCustomPromptMultiline =
|
|
358
|
+
const isCustomPromptMultiline = useMemo(
|
|
361
359
|
() => customPrompt?.includes("\n"),
|
|
362
360
|
[customPrompt]
|
|
363
361
|
);
|
|
364
|
-
const hasDropdownItems =
|
|
362
|
+
const hasDropdownItems = useCommandState(
|
|
365
363
|
(state2) => state2.filtered.count > 0
|
|
366
364
|
);
|
|
367
365
|
const isDropdownHidden = isCustomPromptMultiline || !hasDropdownItems;
|
|
368
|
-
|
|
366
|
+
useEffect(() => {
|
|
369
367
|
if (!editor) {
|
|
370
368
|
return;
|
|
371
369
|
}
|
|
@@ -385,7 +383,7 @@ function AiToolbarContainer({
|
|
|
385
383
|
document.removeEventListener("keydown", handleKeyDown);
|
|
386
384
|
};
|
|
387
385
|
}, [editor, state.phase]);
|
|
388
|
-
return /* @__PURE__ */
|
|
386
|
+
return /* @__PURE__ */ jsxs(AiToolbarContext.Provider, {
|
|
389
387
|
value: {
|
|
390
388
|
state,
|
|
391
389
|
toolbarRef,
|
|
@@ -393,74 +391,74 @@ function AiToolbarContainer({
|
|
|
393
391
|
isDropdownHidden
|
|
394
392
|
},
|
|
395
393
|
children: [
|
|
396
|
-
/* @__PURE__ */
|
|
394
|
+
/* @__PURE__ */ jsxs("div", {
|
|
397
395
|
className: "lb-tiptap-ai-toolbar-container",
|
|
398
396
|
children: [
|
|
399
|
-
/* @__PURE__ */
|
|
397
|
+
/* @__PURE__ */ jsx("div", {
|
|
400
398
|
className: "lb-elevation lb-tiptap-ai-toolbar",
|
|
401
|
-
children: state.phase === "asking" ? /* @__PURE__ */
|
|
399
|
+
children: state.phase === "asking" ? /* @__PURE__ */ jsx(AiToolbarAsking, {}) : state.phase === "thinking" ? /* @__PURE__ */ jsx(AiToolbarThinking, {}) : state.phase === "reviewing" ? /* @__PURE__ */ jsx(AiToolbarReviewing, {}) : null
|
|
402
400
|
}),
|
|
403
|
-
/* @__PURE__ */
|
|
401
|
+
/* @__PURE__ */ jsxs("div", {
|
|
404
402
|
className: "lb-tiptap-ai-toolbar-halo",
|
|
405
403
|
"data-active": state.phase === "thinking" ? "" : void 0,
|
|
406
404
|
"aria-hidden": true,
|
|
407
405
|
children: [
|
|
408
|
-
/* @__PURE__ */
|
|
406
|
+
/* @__PURE__ */ jsx("div", {
|
|
409
407
|
className: "lb-tiptap-ai-toolbar-halo-horizontal"
|
|
410
408
|
}),
|
|
411
|
-
/* @__PURE__ */
|
|
409
|
+
/* @__PURE__ */ jsx("div", {
|
|
412
410
|
className: "lb-tiptap-ai-toolbar-halo-vertical"
|
|
413
411
|
})
|
|
414
412
|
]
|
|
415
413
|
})
|
|
416
414
|
]
|
|
417
415
|
}),
|
|
418
|
-
state.phase === "asking" || state.phase === "reviewing" ? /* @__PURE__ */
|
|
416
|
+
state.phase === "asking" || state.phase === "reviewing" ? /* @__PURE__ */ jsx(Command.List, {
|
|
419
417
|
className: "lb-elevation lb-dropdown lb-tiptap-ai-toolbar-dropdown",
|
|
420
418
|
"data-hidden": isDropdownHidden ? "" : void 0,
|
|
421
419
|
ref: dropdownRef,
|
|
422
|
-
children: state.phase === "reviewing" ? /* @__PURE__ */
|
|
420
|
+
children: state.phase === "reviewing" ? /* @__PURE__ */ jsx(AiToolbarReviewingSuggestions, {}) : children
|
|
423
421
|
}) : null
|
|
424
422
|
]
|
|
425
423
|
});
|
|
426
424
|
}
|
|
427
|
-
const defaultSuggestions = /* @__PURE__ */
|
|
425
|
+
const defaultSuggestions = /* @__PURE__ */ jsxs(Fragment, {
|
|
428
426
|
children: [
|
|
429
|
-
/* @__PURE__ */
|
|
430
|
-
icon: /* @__PURE__ */
|
|
427
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestion, {
|
|
428
|
+
icon: /* @__PURE__ */ jsx(EditIcon, {}),
|
|
431
429
|
prompt: "Improve the quality of the text",
|
|
432
430
|
children: "Improve writing"
|
|
433
431
|
}),
|
|
434
|
-
/* @__PURE__ */
|
|
435
|
-
icon: /* @__PURE__ */
|
|
432
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestion, {
|
|
433
|
+
icon: /* @__PURE__ */ jsx(CheckIcon, {}),
|
|
436
434
|
prompt: "Fix spelling & grammar errors in the text",
|
|
437
435
|
children: "Fix mistakes"
|
|
438
436
|
}),
|
|
439
|
-
/* @__PURE__ */
|
|
440
|
-
icon: /* @__PURE__ */
|
|
437
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestion, {
|
|
438
|
+
icon: /* @__PURE__ */ jsx(ShortenIcon, {}),
|
|
441
439
|
prompt: "Shorten the text, simplifying it",
|
|
442
440
|
children: "Simplify"
|
|
443
441
|
}),
|
|
444
|
-
/* @__PURE__ */
|
|
445
|
-
icon: /* @__PURE__ */
|
|
442
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestion, {
|
|
443
|
+
icon: /* @__PURE__ */ jsx(LengthenIcon, {}),
|
|
446
444
|
prompt: "Lengthen the text, going into more detail",
|
|
447
445
|
children: "Add more detail"
|
|
448
446
|
}),
|
|
449
|
-
/* @__PURE__ */
|
|
450
|
-
/* @__PURE__ */
|
|
451
|
-
icon: /* @__PURE__ */
|
|
447
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestionsSeparator, {}),
|
|
448
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestion, {
|
|
449
|
+
icon: /* @__PURE__ */ jsx(SparklesTextIcon, {}),
|
|
452
450
|
prompt: "Continue writing from the text's end",
|
|
453
451
|
children: "Continue writing"
|
|
454
452
|
}),
|
|
455
|
-
/* @__PURE__ */
|
|
456
|
-
icon: /* @__PURE__ */
|
|
453
|
+
/* @__PURE__ */ jsx(AiToolbarSuggestion, {
|
|
454
|
+
icon: /* @__PURE__ */ jsx(QuestionMarkIcon, {}),
|
|
457
455
|
prompt: "Explain what the text is about",
|
|
458
456
|
children: "Explain"
|
|
459
457
|
})
|
|
460
458
|
]
|
|
461
459
|
});
|
|
462
460
|
const AiToolbar = Object.assign(
|
|
463
|
-
|
|
461
|
+
forwardRef(
|
|
464
462
|
({
|
|
465
463
|
offset: sideOffset = 6,
|
|
466
464
|
editor,
|
|
@@ -468,14 +466,14 @@ const AiToolbar = Object.assign(
|
|
|
468
466
|
suggestions: Suggestions = defaultSuggestions,
|
|
469
467
|
...props
|
|
470
468
|
}, forwardedRef) => {
|
|
471
|
-
const state =
|
|
469
|
+
const state = useEditorState({
|
|
472
470
|
editor,
|
|
473
471
|
selector: (ctx) => {
|
|
474
472
|
return ctx.editor?.storage.liveblocksAi?.state;
|
|
475
473
|
}
|
|
476
|
-
}) ??
|
|
474
|
+
}) ?? DEFAULT_STATE;
|
|
477
475
|
const selection = editor?.state.selection;
|
|
478
|
-
const floatingOptions =
|
|
476
|
+
const floatingOptions = useMemo(() => {
|
|
479
477
|
const detectOverflowOptions = {
|
|
480
478
|
padding: AI_TOOLBAR_COLLISION_PADDING
|
|
481
479
|
};
|
|
@@ -484,18 +482,18 @@ const AiToolbar = Object.assign(
|
|
|
484
482
|
placement: "bottom",
|
|
485
483
|
middleware: [
|
|
486
484
|
tiptapFloating(editor),
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
485
|
+
hide(detectOverflowOptions),
|
|
486
|
+
offset(sideOffset),
|
|
487
|
+
shift({
|
|
490
488
|
...detectOverflowOptions,
|
|
491
489
|
mainAxis: false,
|
|
492
490
|
crossAxis: true,
|
|
493
|
-
limiter:
|
|
491
|
+
limiter: limitShift()
|
|
494
492
|
}),
|
|
495
493
|
flipToolbar()
|
|
496
494
|
],
|
|
497
495
|
whileElementsMounted: (...args) => {
|
|
498
|
-
return
|
|
496
|
+
return autoUpdate(...args, {
|
|
499
497
|
animationFrame: true
|
|
500
498
|
});
|
|
501
499
|
}
|
|
@@ -508,20 +506,20 @@ const AiToolbar = Object.assign(
|
|
|
508
506
|
x,
|
|
509
507
|
y,
|
|
510
508
|
isPositioned
|
|
511
|
-
} =
|
|
509
|
+
} = useFloating({
|
|
512
510
|
...floatingOptions,
|
|
513
511
|
open: isOpen
|
|
514
512
|
});
|
|
515
|
-
const toolbarRef =
|
|
516
|
-
const mergedRefs =
|
|
517
|
-
const dropdownRef =
|
|
518
|
-
const [selectedDropdownValue, setSelectedDropdownValue] =
|
|
519
|
-
|
|
513
|
+
const toolbarRef = useRef(null);
|
|
514
|
+
const mergedRefs = useRefs(forwardedRef, toolbarRef, setFloating);
|
|
515
|
+
const dropdownRef = useRef(null);
|
|
516
|
+
const [selectedDropdownValue, setSelectedDropdownValue] = useState("");
|
|
517
|
+
useEffect(() => {
|
|
520
518
|
if (state.phase === "closed") {
|
|
521
519
|
setSelectedDropdownValue("");
|
|
522
520
|
}
|
|
523
521
|
}, [state.phase]);
|
|
524
|
-
|
|
522
|
+
useEffect(() => {
|
|
525
523
|
if (state.phase === "closed") {
|
|
526
524
|
setSelectedDropdownValue("");
|
|
527
525
|
return;
|
|
@@ -537,7 +535,7 @@ const AiToolbar = Object.assign(
|
|
|
537
535
|
firstDropdownItem?.dataset.value ?? ""
|
|
538
536
|
);
|
|
539
537
|
}, [state.phase, dropdownRef, setSelectedDropdownValue]);
|
|
540
|
-
|
|
538
|
+
useEffect(() => {
|
|
541
539
|
if (!editor) {
|
|
542
540
|
return;
|
|
543
541
|
}
|
|
@@ -545,13 +543,13 @@ const AiToolbar = Object.assign(
|
|
|
545
543
|
editor.commands.$closeAiToolbar();
|
|
546
544
|
}
|
|
547
545
|
}, [state.phase, editor, selection]);
|
|
548
|
-
|
|
546
|
+
useLayoutEffect(() => {
|
|
549
547
|
if (!editor || !isOpen) {
|
|
550
548
|
return;
|
|
551
549
|
}
|
|
552
550
|
setReference(null);
|
|
553
551
|
setTimeout(() => {
|
|
554
|
-
if (state.phase === "reviewing" &&
|
|
552
|
+
if (state.phase === "reviewing" && isContextualPromptDiffResponse(state.response)) {
|
|
555
553
|
const changes = editor.view.dom.querySelectorAll(
|
|
556
554
|
"ychange[data-liveblocks]"
|
|
557
555
|
);
|
|
@@ -578,7 +576,7 @@ const AiToolbar = Object.assign(
|
|
|
578
576
|
}
|
|
579
577
|
});
|
|
580
578
|
} else if (selection) {
|
|
581
|
-
const domRange =
|
|
579
|
+
const domRange = getDomRangeFromSelection(editor, selection);
|
|
582
580
|
setReference(domRange);
|
|
583
581
|
} else {
|
|
584
582
|
setReference(null);
|
|
@@ -592,7 +590,7 @@ const AiToolbar = Object.assign(
|
|
|
592
590
|
state.phase,
|
|
593
591
|
state.response
|
|
594
592
|
]);
|
|
595
|
-
|
|
593
|
+
useEffect(() => {
|
|
596
594
|
if (!editor || !isOpen) {
|
|
597
595
|
return;
|
|
598
596
|
}
|
|
@@ -614,15 +612,15 @@ const AiToolbar = Object.assign(
|
|
|
614
612
|
if (!editor || !isOpen) {
|
|
615
613
|
return null;
|
|
616
614
|
}
|
|
617
|
-
return
|
|
618
|
-
/* @__PURE__ */
|
|
619
|
-
children: /* @__PURE__ */
|
|
615
|
+
return createPortal(
|
|
616
|
+
/* @__PURE__ */ jsx(TooltipProvider, {
|
|
617
|
+
children: /* @__PURE__ */ jsx(EditorProvider, {
|
|
620
618
|
editor,
|
|
621
|
-
children: /* @__PURE__ */
|
|
619
|
+
children: /* @__PURE__ */ jsx(Command, {
|
|
622
620
|
role: "toolbar",
|
|
623
621
|
label: "AI toolbar",
|
|
624
622
|
"aria-orientation": "horizontal",
|
|
625
|
-
className:
|
|
623
|
+
className: classNames(
|
|
626
624
|
"lb-root lb-portal lb-tiptap-ai-toolbar-portal",
|
|
627
625
|
className
|
|
628
626
|
),
|
|
@@ -636,11 +634,11 @@ const AiToolbar = Object.assign(
|
|
|
636
634
|
value: selectedDropdownValue,
|
|
637
635
|
onValueChange: setSelectedDropdownValue,
|
|
638
636
|
...props,
|
|
639
|
-
children: /* @__PURE__ */
|
|
637
|
+
children: /* @__PURE__ */ jsx(AiToolbarContainer, {
|
|
640
638
|
state,
|
|
641
639
|
dropdownRef,
|
|
642
640
|
toolbarRef,
|
|
643
|
-
children: typeof Suggestions === "function" ? /* @__PURE__ */
|
|
641
|
+
children: typeof Suggestions === "function" ? /* @__PURE__ */ jsx(Suggestions, {
|
|
644
642
|
children: defaultSuggestions
|
|
645
643
|
}) : Suggestions
|
|
646
644
|
})
|
|
@@ -658,6 +656,5 @@ const AiToolbar = Object.assign(
|
|
|
658
656
|
}
|
|
659
657
|
);
|
|
660
658
|
|
|
661
|
-
|
|
662
|
-
exports.AiToolbar = AiToolbar;
|
|
659
|
+
export { AI_TOOLBAR_COLLISION_PADDING, AiToolbar };
|
|
663
660
|
//# sourceMappingURL=AiToolbar.js.map
|