@uipath/apollo-wind 2.46.0 → 2.47.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/dist/components/ui/avatar.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/command.d.ts +13 -13
- package/dist/components/ui/index.cjs +30 -30
- package/dist/components/ui/prompt-editor/components/EditorToolbar.cjs +101 -68
- package/dist/components/ui/prompt-editor/components/EditorToolbar.d.ts +16 -2
- package/dist/components/ui/prompt-editor/components/EditorToolbar.js +101 -68
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.cjs +13 -8
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.d.ts +13 -1
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.js +13 -8
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.cjs +22 -11
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.js +23 -12
- package/dist/components/ui/prompt-editor/components/TokenPill.cjs +4 -2
- package/dist/components/ui/prompt-editor/components/TokenPill.js +4 -2
- package/dist/components/ui/prompt-editor/components/TokenPillSlot.cjs +58 -0
- package/dist/components/ui/prompt-editor/components/TokenPillSlot.d.ts +7 -0
- package/dist/components/ui/prompt-editor/components/TokenPillSlot.js +24 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.cjs +8 -9
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.js +8 -9
- package/dist/components/ui/prompt-editor/index.cjs +152 -9
- package/dist/components/ui/prompt-editor/index.d.ts +13 -1
- package/dist/components/ui/prompt-editor/index.js +11 -1
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.cjs +2 -2
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.d.ts +1 -1
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.js +2 -2
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.cjs +2 -2
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.d.ts +1 -1
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.js +2 -2
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.cjs +2 -2
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.d.ts +1 -1
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.js +2 -2
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.cjs +2 -2
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.d.ts +1 -1
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.js +2 -2
- package/dist/components/ui/prompt-editor/nodes/index.cjs +1 -1
- package/dist/components/ui/prompt-editor/nodes/index.d.ts +5 -5
- package/dist/components/ui/prompt-editor/nodes/index.js +1 -1
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.cjs +11 -5
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.d.ts +8 -1
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.js +12 -6
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.cjs +1 -1
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.js +1 -1
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.cjs +1 -1
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.js +1 -1
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.cjs +1 -1
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.js +1 -1
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.cjs +12 -6
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.js +13 -7
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.cjs +64 -3
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.d.ts +6 -2
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.js +65 -4
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.cjs +4 -9
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.js +4 -9
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.cjs +10 -5
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.d.ts +3 -1
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.js +10 -5
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.cjs +1 -1
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.js +2 -2
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.cjs +10 -1
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.d.ts +4 -1
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.js +8 -2
- package/dist/components/ui/prompt-editor/prompt-editor-config.cjs +69 -0
- package/dist/components/ui/prompt-editor/prompt-editor-config.d.ts +70 -0
- package/dist/components/ui/prompt-editor/prompt-editor-config.js +29 -0
- package/dist/components/ui/prompt-editor/prompt-editor.cjs +198 -88
- package/dist/components/ui/prompt-editor/prompt-editor.d.ts +46 -1
- package/dist/components/ui/prompt-editor/prompt-editor.js +199 -89
- package/dist/components/ui/prompt-editor/types.cjs +5 -5
- package/dist/components/ui/prompt-editor/types.d.ts +18 -2
- package/dist/components/ui/prompt-editor/types.js +5 -5
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.cjs +10 -5
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.d.ts +13 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.js +8 -6
- package/dist/components/ui/prompt-editor/utils/index.cjs +1 -1
- package/dist/components/ui/prompt-editor/utils/index.d.ts +1 -1
- package/dist/components/ui/prompt-editor/utils/index.js +1 -1
- package/dist/components/ui/prompt-editor/utils/insert-token.d.ts +1 -1
- package/dist/components/ui/prompt-editor/utils/rich-serialization.cjs +186 -0
- package/dist/components/ui/prompt-editor/utils/rich-serialization.d.ts +38 -0
- package/dist/components/ui/prompt-editor/utils/rich-serialization.js +140 -0
- package/dist/components/ui/prompt-editor/utils/serialization.cjs +13 -5
- package/dist/components/ui/prompt-editor/utils/serialization.js +14 -6
- package/dist/components/ui/sheet.d.ts +1 -1
- package/dist/components/ui/spinner.d.ts +1 -1
- package/dist/components/ui/switch.d.ts +2 -2
- package/dist/components/ui/toggle-group.d.ts +2 -2
- package/dist/components/ui/toggle.d.ts +2 -2
- package/dist/index.cjs +136 -61
- package/dist/index.d.ts +89 -89
- package/dist/index.js +61 -61
- package/dist/styles.css +15 -0
- package/package.json +3 -1
|
@@ -26,8 +26,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
EditorRefPlugin: ()=>EditorRefPlugin
|
|
28
28
|
});
|
|
29
|
-
const external_react_namespaceObject = require("react");
|
|
30
29
|
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
30
|
+
const external_react_namespaceObject = require("react");
|
|
31
31
|
const EditorRefPlugin = ({ onRef })=>{
|
|
32
32
|
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
33
33
|
const onRefRef = (0, external_react_namespaceObject.useRef)(onRef);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
3
|
const EditorRefPlugin = ({ onRef })=>{
|
|
4
4
|
const [editor] = useLexicalComposerContext();
|
|
5
5
|
const onRefRef = useRef(onRef);
|
|
@@ -26,10 +26,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
MultilinePlugin: ()=>MultilinePlugin
|
|
28
28
|
});
|
|
29
|
-
const external_react_namespaceObject = require("react");
|
|
30
29
|
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
30
|
const utils_namespaceObject = require("@lexical/utils");
|
|
32
31
|
const external_lexical_namespaceObject = require("lexical");
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
33
33
|
const collapseParagraphs = ()=>{
|
|
34
34
|
const root = (0, external_lexical_namespaceObject.$getRoot)();
|
|
35
35
|
const paragraphs = root.getChildren().filter(external_lexical_namespaceObject.$isParagraphNode);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
2
|
import { mergeRegister } from "@lexical/utils";
|
|
4
3
|
import { $createParagraphNode, $createTextNode, $getRoot, $isLineBreakNode, $isParagraphNode, COMMAND_PRIORITY_NORMAL, KEY_ENTER_COMMAND, TextNode } from "lexical";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
5
|
const collapseParagraphs = ()=>{
|
|
6
6
|
const root = $getRoot();
|
|
7
7
|
const paragraphs = root.getChildren().filter($isParagraphNode);
|
|
@@ -27,11 +27,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
registerNodeSelectionFixCommands: ()=>registerNodeSelectionFixCommands,
|
|
28
28
|
NodeSelectionFixPlugin: ()=>NodeSelectionFixPlugin
|
|
29
29
|
});
|
|
30
|
-
const external_react_namespaceObject = require("react");
|
|
31
30
|
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
32
31
|
const external_lexical_namespaceObject = require("lexical");
|
|
33
|
-
const
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
34
33
|
const index_cjs_namespaceObject = require("../utils/index.cjs");
|
|
34
|
+
const token_nodes_cjs_namespaceObject = require("./shared/token-nodes.cjs");
|
|
35
|
+
const $isBlockElement = (node)=>(0, external_lexical_namespaceObject.$isElementNode)(node) && !node.isInline() && !(0, external_lexical_namespaceObject.$isRootNode)(node);
|
|
35
36
|
const $setCollapsedSelection = (key, offset, type)=>{
|
|
36
37
|
const sel = (0, external_lexical_namespaceObject.$createRangeSelection)();
|
|
37
38
|
sel.anchor.set(key, offset, type);
|
|
@@ -59,7 +60,7 @@ const getPromptTokenBeforeCursor = ()=>{
|
|
|
59
60
|
const prev = anchorNode.getPreviousSibling();
|
|
60
61
|
return (0, token_nodes_cjs_namespaceObject.isPromptTokenNode)(prev) ? prev : null;
|
|
61
62
|
}
|
|
62
|
-
if ((
|
|
63
|
+
if ($isBlockElement(anchorNode)) {
|
|
63
64
|
const offset = selection.anchor.offset;
|
|
64
65
|
if (0 === offset) return null;
|
|
65
66
|
const prev = anchorNode.getChildAtIndex(offset - 1);
|
|
@@ -75,7 +76,7 @@ const getPromptTokenAfterCursor = ()=>{
|
|
|
75
76
|
const next = anchorNode.getNextSibling();
|
|
76
77
|
return (0, token_nodes_cjs_namespaceObject.isPromptTokenNode)(next) ? next : null;
|
|
77
78
|
}
|
|
78
|
-
if ((
|
|
79
|
+
if ($isBlockElement(anchorNode)) {
|
|
79
80
|
const next = anchorNode.getChildAtIndex(selection.anchor.offset);
|
|
80
81
|
return (0, token_nodes_cjs_namespaceObject.isPromptTokenNode)(next) ? next : null;
|
|
81
82
|
}
|
|
@@ -167,13 +168,13 @@ const registerNodeSelectionFixCommands = (editor)=>{
|
|
|
167
168
|
const anchorNode = selection.anchor.getNode();
|
|
168
169
|
let paragraph = null;
|
|
169
170
|
let offset = 0;
|
|
170
|
-
if ('element' === selection.anchor.type && (
|
|
171
|
+
if ('element' === selection.anchor.type && $isBlockElement(anchorNode)) {
|
|
171
172
|
paragraph = anchorNode;
|
|
172
173
|
offset = selection.anchor.offset;
|
|
173
174
|
} else {
|
|
174
175
|
if (!('text' === selection.anchor.type && (0, external_lexical_namespaceObject.$isTextNode)(anchorNode)) || 0 !== selection.anchor.offset) return false;
|
|
175
176
|
const parent = anchorNode.getParent();
|
|
176
|
-
if (
|
|
177
|
+
if (!$isBlockElement(parent)) return false;
|
|
177
178
|
paragraph = parent;
|
|
178
179
|
offset = anchorNode.getIndexWithinParent();
|
|
179
180
|
}
|
|
@@ -285,7 +286,12 @@ const registerNodeSelectionFixCommands = (editor)=>{
|
|
|
285
286
|
const unregisterArrowUp = editor.registerCommand(external_lexical_namespaceObject.KEY_ARROW_UP_COMMAND, handleArrowUp, external_lexical_namespaceObject.COMMAND_PRIORITY_HIGH);
|
|
286
287
|
const unregisterArrowDown = editor.registerCommand(external_lexical_namespaceObject.KEY_ARROW_DOWN_COMMAND, handleArrowDown, external_lexical_namespaceObject.COMMAND_PRIORITY_HIGH);
|
|
287
288
|
const unregisterEscape = editor.registerCommand(external_lexical_namespaceObject.KEY_ESCAPE_COMMAND, handleEscape, external_lexical_namespaceObject.COMMAND_PRIORITY_HIGH);
|
|
289
|
+
const unregisterClick = editor.registerCommand(external_lexical_namespaceObject.CLICK_COMMAND, (event)=>{
|
|
290
|
+
const target = event.target;
|
|
291
|
+
return target instanceof Element && null != target.closest('[data-lexical-decorator]');
|
|
292
|
+
}, external_lexical_namespaceObject.COMMAND_PRIORITY_HIGH);
|
|
288
293
|
return ()=>{
|
|
294
|
+
unregisterClick();
|
|
289
295
|
unregisterBackspace();
|
|
290
296
|
unregisterDelete();
|
|
291
297
|
unregisterArrowLeft();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
-
import { $createNodeSelection, $createRangeSelection, $createTextNode, $getSelection, $isLineBreakNode, $isNodeSelection, $
|
|
4
|
-
import {
|
|
2
|
+
import { $createNodeSelection, $createRangeSelection, $createTextNode, $getSelection, $isElementNode, $isLineBreakNode, $isNodeSelection, $isRangeSelection, $isRootNode, $isTextNode, $setSelection, CLICK_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ESCAPE_COMMAND } from "lexical";
|
|
3
|
+
import { useEffect } from "react";
|
|
5
4
|
import { WORD_JOINER } from "../utils/index.js";
|
|
5
|
+
import { isPromptTokenNode } from "./shared/token-nodes.js";
|
|
6
|
+
const $isBlockElement = (node)=>$isElementNode(node) && !node.isInline() && !$isRootNode(node);
|
|
6
7
|
const $setCollapsedSelection = (key, offset, type)=>{
|
|
7
8
|
const sel = $createRangeSelection();
|
|
8
9
|
sel.anchor.set(key, offset, type);
|
|
@@ -30,7 +31,7 @@ const getPromptTokenBeforeCursor = ()=>{
|
|
|
30
31
|
const prev = anchorNode.getPreviousSibling();
|
|
31
32
|
return isPromptTokenNode(prev) ? prev : null;
|
|
32
33
|
}
|
|
33
|
-
if ($
|
|
34
|
+
if ($isBlockElement(anchorNode)) {
|
|
34
35
|
const offset = selection.anchor.offset;
|
|
35
36
|
if (0 === offset) return null;
|
|
36
37
|
const prev = anchorNode.getChildAtIndex(offset - 1);
|
|
@@ -46,7 +47,7 @@ const getPromptTokenAfterCursor = ()=>{
|
|
|
46
47
|
const next = anchorNode.getNextSibling();
|
|
47
48
|
return isPromptTokenNode(next) ? next : null;
|
|
48
49
|
}
|
|
49
|
-
if ($
|
|
50
|
+
if ($isBlockElement(anchorNode)) {
|
|
50
51
|
const next = anchorNode.getChildAtIndex(selection.anchor.offset);
|
|
51
52
|
return isPromptTokenNode(next) ? next : null;
|
|
52
53
|
}
|
|
@@ -138,13 +139,13 @@ const registerNodeSelectionFixCommands = (editor)=>{
|
|
|
138
139
|
const anchorNode = selection.anchor.getNode();
|
|
139
140
|
let paragraph = null;
|
|
140
141
|
let offset = 0;
|
|
141
|
-
if ('element' === selection.anchor.type && $
|
|
142
|
+
if ('element' === selection.anchor.type && $isBlockElement(anchorNode)) {
|
|
142
143
|
paragraph = anchorNode;
|
|
143
144
|
offset = selection.anchor.offset;
|
|
144
145
|
} else {
|
|
145
146
|
if (!('text' === selection.anchor.type && $isTextNode(anchorNode)) || 0 !== selection.anchor.offset) return false;
|
|
146
147
|
const parent = anchorNode.getParent();
|
|
147
|
-
if (!$
|
|
148
|
+
if (!$isBlockElement(parent)) return false;
|
|
148
149
|
paragraph = parent;
|
|
149
150
|
offset = anchorNode.getIndexWithinParent();
|
|
150
151
|
}
|
|
@@ -256,7 +257,12 @@ const registerNodeSelectionFixCommands = (editor)=>{
|
|
|
256
257
|
const unregisterArrowUp = editor.registerCommand(KEY_ARROW_UP_COMMAND, handleArrowUp, COMMAND_PRIORITY_HIGH);
|
|
257
258
|
const unregisterArrowDown = editor.registerCommand(KEY_ARROW_DOWN_COMMAND, handleArrowDown, COMMAND_PRIORITY_HIGH);
|
|
258
259
|
const unregisterEscape = editor.registerCommand(KEY_ESCAPE_COMMAND, handleEscape, COMMAND_PRIORITY_HIGH);
|
|
260
|
+
const unregisterClick = editor.registerCommand(CLICK_COMMAND, (event)=>{
|
|
261
|
+
const target = event.target;
|
|
262
|
+
return target instanceof Element && null != target.closest('[data-lexical-decorator]');
|
|
263
|
+
}, COMMAND_PRIORITY_HIGH);
|
|
259
264
|
return ()=>{
|
|
265
|
+
unregisterClick();
|
|
260
266
|
unregisterBackspace();
|
|
261
267
|
unregisterDelete();
|
|
262
268
|
unregisterArrowLeft();
|
|
@@ -26,9 +26,32 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
ToolbarActionsPlugin: ()=>ToolbarActionsPlugin
|
|
28
28
|
});
|
|
29
|
+
const list_namespaceObject = require("@lexical/list");
|
|
29
30
|
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
|
+
const utils_namespaceObject = require("@lexical/utils");
|
|
30
32
|
const external_lexical_namespaceObject = require("lexical");
|
|
31
33
|
const external_react_namespaceObject = require("react");
|
|
34
|
+
const EMPTY_ACTIVE_FORMATS = {
|
|
35
|
+
bold: false,
|
|
36
|
+
italic: false,
|
|
37
|
+
strikethrough: false,
|
|
38
|
+
orderedList: false,
|
|
39
|
+
bulletedList: false
|
|
40
|
+
};
|
|
41
|
+
const $readActiveFormats = ()=>{
|
|
42
|
+
const selection = (0, external_lexical_namespaceObject.$getSelection)();
|
|
43
|
+
if (!(0, external_lexical_namespaceObject.$isRangeSelection)(selection)) return EMPTY_ACTIVE_FORMATS;
|
|
44
|
+
const anchorNode = selection.anchor.getNode();
|
|
45
|
+
const listType = (0, utils_namespaceObject.$getNearestNodeOfType)(anchorNode, list_namespaceObject.ListNode)?.getListType();
|
|
46
|
+
return {
|
|
47
|
+
bold: selection.hasFormat('bold'),
|
|
48
|
+
italic: selection.hasFormat('italic'),
|
|
49
|
+
strikethrough: selection.hasFormat('strikethrough'),
|
|
50
|
+
orderedList: 'number' === listType,
|
|
51
|
+
bulletedList: 'bullet' === listType
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const activeFormatsEqual = (a, b)=>a.bold === b.bold && a.italic === b.italic && a.strikethrough === b.strikethrough && a.orderedList === b.orderedList && a.bulletedList === b.bulletedList;
|
|
32
55
|
const wrapSelectionWithMarkers = (startMarker, endMarker)=>{
|
|
33
56
|
const selection = (0, external_lexical_namespaceObject.$getSelection)();
|
|
34
57
|
if (!(0, external_lexical_namespaceObject.$isRangeSelection)(selection)) return;
|
|
@@ -94,10 +117,27 @@ const insertLinePrefixForSelection = (getPrefix)=>{
|
|
|
94
117
|
} else paragraph.append((0, external_lexical_namespaceObject.$createTextNode)(prefix));
|
|
95
118
|
}
|
|
96
119
|
};
|
|
97
|
-
const ToolbarActionsPlugin = ({ actionsRef })=>{
|
|
120
|
+
const ToolbarActionsPlugin = ({ actionsRef, richText, onActiveFormatsChange })=>{
|
|
98
121
|
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
99
122
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
100
|
-
|
|
123
|
+
if (richText) {
|
|
124
|
+
const toggleList = (target)=>{
|
|
125
|
+
const listType = editor.getEditorState().read(()=>{
|
|
126
|
+
const selection = (0, external_lexical_namespaceObject.$getSelection)();
|
|
127
|
+
if (!(0, external_lexical_namespaceObject.$isRangeSelection)(selection)) return;
|
|
128
|
+
return (0, utils_namespaceObject.$getNearestNodeOfType)(selection.anchor.getNode(), list_namespaceObject.ListNode)?.getListType();
|
|
129
|
+
});
|
|
130
|
+
if (listType === target) editor.dispatchCommand(list_namespaceObject.REMOVE_LIST_COMMAND, void 0);
|
|
131
|
+
else editor.dispatchCommand('number' === target ? list_namespaceObject.INSERT_ORDERED_LIST_COMMAND : list_namespaceObject.INSERT_UNORDERED_LIST_COMMAND, void 0);
|
|
132
|
+
};
|
|
133
|
+
actionsRef.current = {
|
|
134
|
+
formatBold: ()=>editor.dispatchCommand(external_lexical_namespaceObject.FORMAT_TEXT_COMMAND, 'bold'),
|
|
135
|
+
formatItalic: ()=>editor.dispatchCommand(external_lexical_namespaceObject.FORMAT_TEXT_COMMAND, 'italic'),
|
|
136
|
+
formatStrikethrough: ()=>editor.dispatchCommand(external_lexical_namespaceObject.FORMAT_TEXT_COMMAND, 'strikethrough'),
|
|
137
|
+
formatNumberedList: ()=>toggleList('number'),
|
|
138
|
+
formatBulletedList: ()=>toggleList('bullet')
|
|
139
|
+
};
|
|
140
|
+
} else actionsRef.current = {
|
|
101
141
|
formatBold: ()=>{
|
|
102
142
|
editor.update(()=>wrapSelectionWithMarkers('**', '**'));
|
|
103
143
|
},
|
|
@@ -119,7 +159,28 @@ const ToolbarActionsPlugin = ({ actionsRef })=>{
|
|
|
119
159
|
};
|
|
120
160
|
}, [
|
|
121
161
|
editor,
|
|
122
|
-
actionsRef
|
|
162
|
+
actionsRef,
|
|
163
|
+
richText
|
|
164
|
+
]);
|
|
165
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
166
|
+
if (!richText || !onActiveFormatsChange) return;
|
|
167
|
+
let last = null;
|
|
168
|
+
const report = ()=>{
|
|
169
|
+
const next = editor.getEditorState().read($readActiveFormats);
|
|
170
|
+
if (!last || !activeFormatsEqual(last, next)) {
|
|
171
|
+
last = next;
|
|
172
|
+
onActiveFormatsChange(next);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
report();
|
|
176
|
+
return (0, utils_namespaceObject.mergeRegister)(editor.registerUpdateListener(report), editor.registerCommand(external_lexical_namespaceObject.SELECTION_CHANGE_COMMAND, ()=>{
|
|
177
|
+
report();
|
|
178
|
+
return false;
|
|
179
|
+
}, external_lexical_namespaceObject.COMMAND_PRIORITY_LOW));
|
|
180
|
+
}, [
|
|
181
|
+
editor,
|
|
182
|
+
richText,
|
|
183
|
+
onActiveFormatsChange
|
|
123
184
|
]);
|
|
124
185
|
return null;
|
|
125
186
|
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type MutableRefObject } from 'react';
|
|
2
|
-
import type { PromptEditorToolbarActionsRef } from '../types';
|
|
2
|
+
import type { PromptEditorToolbarActionsRef, PromptEditorToolbarActiveFormats } from '../types';
|
|
3
3
|
interface ToolbarActionsPluginProps {
|
|
4
4
|
actionsRef: MutableRefObject<PromptEditorToolbarActionsRef | null>;
|
|
5
|
+
/** WYSIWYG mode: dispatch real Lexical format/list commands instead of inserting markdown markers. */
|
|
6
|
+
richText?: boolean;
|
|
7
|
+
/** Rich mode only: reports which formats are active at the selection, for toolbar pressed states. */
|
|
8
|
+
onActiveFormatsChange?: (formats: PromptEditorToolbarActiveFormats) => void;
|
|
5
9
|
}
|
|
6
|
-
export declare const ToolbarActionsPlugin: ({ actionsRef }: ToolbarActionsPluginProps) => null;
|
|
10
|
+
export declare const ToolbarActionsPlugin: ({ actionsRef, richText, onActiveFormatsChange, }: ToolbarActionsPluginProps) => null;
|
|
7
11
|
export {};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
|
+
import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, ListNode, REMOVE_LIST_COMMAND } from "@lexical/list";
|
|
1
2
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
-
import { $
|
|
3
|
+
import { $getNearestNodeOfType, mergeRegister } from "@lexical/utils";
|
|
4
|
+
import { $createTextNode, $getRoot, $getSelection, $isParagraphNode, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, SELECTION_CHANGE_COMMAND } from "lexical";
|
|
3
5
|
import { useEffect } from "react";
|
|
6
|
+
const EMPTY_ACTIVE_FORMATS = {
|
|
7
|
+
bold: false,
|
|
8
|
+
italic: false,
|
|
9
|
+
strikethrough: false,
|
|
10
|
+
orderedList: false,
|
|
11
|
+
bulletedList: false
|
|
12
|
+
};
|
|
13
|
+
const $readActiveFormats = ()=>{
|
|
14
|
+
const selection = $getSelection();
|
|
15
|
+
if (!$isRangeSelection(selection)) return EMPTY_ACTIVE_FORMATS;
|
|
16
|
+
const anchorNode = selection.anchor.getNode();
|
|
17
|
+
const listType = $getNearestNodeOfType(anchorNode, ListNode)?.getListType();
|
|
18
|
+
return {
|
|
19
|
+
bold: selection.hasFormat('bold'),
|
|
20
|
+
italic: selection.hasFormat('italic'),
|
|
21
|
+
strikethrough: selection.hasFormat('strikethrough'),
|
|
22
|
+
orderedList: 'number' === listType,
|
|
23
|
+
bulletedList: 'bullet' === listType
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const activeFormatsEqual = (a, b)=>a.bold === b.bold && a.italic === b.italic && a.strikethrough === b.strikethrough && a.orderedList === b.orderedList && a.bulletedList === b.bulletedList;
|
|
4
27
|
const wrapSelectionWithMarkers = (startMarker, endMarker)=>{
|
|
5
28
|
const selection = $getSelection();
|
|
6
29
|
if (!$isRangeSelection(selection)) return;
|
|
@@ -66,10 +89,27 @@ const insertLinePrefixForSelection = (getPrefix)=>{
|
|
|
66
89
|
} else paragraph.append($createTextNode(prefix));
|
|
67
90
|
}
|
|
68
91
|
};
|
|
69
|
-
const ToolbarActionsPlugin = ({ actionsRef })=>{
|
|
92
|
+
const ToolbarActionsPlugin = ({ actionsRef, richText, onActiveFormatsChange })=>{
|
|
70
93
|
const [editor] = useLexicalComposerContext();
|
|
71
94
|
useEffect(()=>{
|
|
72
|
-
|
|
95
|
+
if (richText) {
|
|
96
|
+
const toggleList = (target)=>{
|
|
97
|
+
const listType = editor.getEditorState().read(()=>{
|
|
98
|
+
const selection = $getSelection();
|
|
99
|
+
if (!$isRangeSelection(selection)) return;
|
|
100
|
+
return $getNearestNodeOfType(selection.anchor.getNode(), ListNode)?.getListType();
|
|
101
|
+
});
|
|
102
|
+
if (listType === target) editor.dispatchCommand(REMOVE_LIST_COMMAND, void 0);
|
|
103
|
+
else editor.dispatchCommand('number' === target ? INSERT_ORDERED_LIST_COMMAND : INSERT_UNORDERED_LIST_COMMAND, void 0);
|
|
104
|
+
};
|
|
105
|
+
actionsRef.current = {
|
|
106
|
+
formatBold: ()=>editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold'),
|
|
107
|
+
formatItalic: ()=>editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic'),
|
|
108
|
+
formatStrikethrough: ()=>editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough'),
|
|
109
|
+
formatNumberedList: ()=>toggleList('number'),
|
|
110
|
+
formatBulletedList: ()=>toggleList('bullet')
|
|
111
|
+
};
|
|
112
|
+
} else actionsRef.current = {
|
|
73
113
|
formatBold: ()=>{
|
|
74
114
|
editor.update(()=>wrapSelectionWithMarkers('**', '**'));
|
|
75
115
|
},
|
|
@@ -91,7 +131,28 @@ const ToolbarActionsPlugin = ({ actionsRef })=>{
|
|
|
91
131
|
};
|
|
92
132
|
}, [
|
|
93
133
|
editor,
|
|
94
|
-
actionsRef
|
|
134
|
+
actionsRef,
|
|
135
|
+
richText
|
|
136
|
+
]);
|
|
137
|
+
useEffect(()=>{
|
|
138
|
+
if (!richText || !onActiveFormatsChange) return;
|
|
139
|
+
let last = null;
|
|
140
|
+
const report = ()=>{
|
|
141
|
+
const next = editor.getEditorState().read($readActiveFormats);
|
|
142
|
+
if (!last || !activeFormatsEqual(last, next)) {
|
|
143
|
+
last = next;
|
|
144
|
+
onActiveFormatsChange(next);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
report();
|
|
148
|
+
return mergeRegister(editor.registerUpdateListener(report), editor.registerCommand(SELECTION_CHANGE_COMMAND, ()=>{
|
|
149
|
+
report();
|
|
150
|
+
return false;
|
|
151
|
+
}, COMMAND_PRIORITY_LOW));
|
|
152
|
+
}, [
|
|
153
|
+
editor,
|
|
154
|
+
richText,
|
|
155
|
+
onActiveFormatsChange
|
|
95
156
|
]);
|
|
96
157
|
return null;
|
|
97
158
|
};
|
|
@@ -28,26 +28,21 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
30
30
|
const external_react_namespaceObject = require("react");
|
|
31
|
+
const autocomplete_segments_cjs_namespaceObject = require("../utils/autocomplete-segments.cjs");
|
|
31
32
|
const token_nodes_cjs_namespaceObject = require("./shared/token-nodes.cjs");
|
|
32
|
-
const NODE_TYPE_TO_TOKEN_TYPE = {
|
|
33
|
-
'input-token': 'input',
|
|
34
|
-
'output-token': 'output',
|
|
35
|
-
'state-token': 'state',
|
|
36
|
-
'resource-token': 'resource'
|
|
37
|
-
};
|
|
38
33
|
const ValidateTokensPlugin = ({ options })=>{
|
|
39
34
|
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
40
35
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
41
36
|
const validValues = new Map();
|
|
42
37
|
for (const opt of options){
|
|
43
38
|
if (!validValues.has(opt.type)) validValues.set(opt.type, new Set());
|
|
44
|
-
validValues.get(opt.type).add(opt.value);
|
|
39
|
+
validValues.get(opt.type).add((0, autocomplete_segments_cjs_namespaceObject.normalizeVariablePath)(opt.value));
|
|
45
40
|
}
|
|
46
41
|
const checkIsInvalid = (node)=>{
|
|
47
|
-
const tokenType = NODE_TYPE_TO_TOKEN_TYPE[node.getType()];
|
|
42
|
+
const tokenType = token_nodes_cjs_namespaceObject.NODE_TYPE_TO_TOKEN_TYPE[node.getType()];
|
|
48
43
|
if (!tokenType) return false;
|
|
49
44
|
const validSet = validValues.get(tokenType);
|
|
50
|
-
return !validSet || !validSet.has(node.getValue());
|
|
45
|
+
return !validSet || !validSet.has((0, autocomplete_segments_cjs_namespaceObject.normalizeVariablePath)(node.getValue()));
|
|
51
46
|
};
|
|
52
47
|
const validateAllNodes = ()=>{
|
|
53
48
|
const tokenNodes = (0, token_nodes_cjs_namespaceObject.getAllPromptTokenNodes)();
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
'input-token': 'input',
|
|
6
|
-
'output-token': 'output',
|
|
7
|
-
'state-token': 'state',
|
|
8
|
-
'resource-token': 'resource'
|
|
9
|
-
};
|
|
3
|
+
import { normalizeVariablePath } from "../utils/autocomplete-segments.js";
|
|
4
|
+
import { NODE_TYPE_TO_TOKEN_TYPE, getAllPromptTokenNodes } from "./shared/token-nodes.js";
|
|
10
5
|
const ValidateTokensPlugin = ({ options })=>{
|
|
11
6
|
const [editor] = useLexicalComposerContext();
|
|
12
7
|
useEffect(()=>{
|
|
13
8
|
const validValues = new Map();
|
|
14
9
|
for (const opt of options){
|
|
15
10
|
if (!validValues.has(opt.type)) validValues.set(opt.type, new Set());
|
|
16
|
-
validValues.get(opt.type).add(opt.value);
|
|
11
|
+
validValues.get(opt.type).add(normalizeVariablePath(opt.value));
|
|
17
12
|
}
|
|
18
13
|
const checkIsInvalid = (node)=>{
|
|
19
14
|
const tokenType = NODE_TYPE_TO_TOKEN_TYPE[node.getType()];
|
|
20
15
|
if (!tokenType) return false;
|
|
21
16
|
const validSet = validValues.get(tokenType);
|
|
22
|
-
return !validSet || !validSet.has(node.getValue());
|
|
17
|
+
return !validSet || !validSet.has(normalizeVariablePath(node.getValue()));
|
|
23
18
|
};
|
|
24
19
|
const validateAllNodes = ()=>{
|
|
25
20
|
const tokenNodes = getAllPromptTokenNodes();
|
|
@@ -26,10 +26,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
ValueSyncPlugin: ()=>ValueSyncPlugin
|
|
28
28
|
});
|
|
29
|
-
const external_react_namespaceObject = require("react");
|
|
30
29
|
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
30
|
const external_lexical_namespaceObject = require("lexical");
|
|
31
|
+
const external_react_namespaceObject = require("react");
|
|
32
32
|
const index_cjs_namespaceObject = require("../utils/index.cjs");
|
|
33
|
+
const rich_serialization_cjs_namespaceObject = require("../utils/rich-serialization.cjs");
|
|
33
34
|
const getDeepActiveElement = (rootElement)=>{
|
|
34
35
|
const rootNode = rootElement.getRootNode();
|
|
35
36
|
let activeElement = null;
|
|
@@ -42,9 +43,11 @@ const isEditorFocused = (rootElement)=>{
|
|
|
42
43
|
const activeElement = getDeepActiveElement(rootElement);
|
|
43
44
|
return !!activeElement && (activeElement === rootElement || rootElement.contains(activeElement));
|
|
44
45
|
};
|
|
45
|
-
const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef })=>{
|
|
46
|
+
const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef, richText })=>{
|
|
46
47
|
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
47
48
|
const lastValueRef = (0, external_react_namespaceObject.useRef)(value);
|
|
49
|
+
const $getTokens = richText ? rich_serialization_cjs_namespaceObject.$getRichEditorTokensInternal : index_cjs_namespaceObject.$getEditorTokensInternal;
|
|
50
|
+
const $setTokens = richText ? rich_serialization_cjs_namespaceObject.$setRichEditorTokensInternal : index_cjs_namespaceObject.$setEditorTokensInternal;
|
|
48
51
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
49
52
|
if (void 0 === value) return;
|
|
50
53
|
if (value === lastValueRef.current) return;
|
|
@@ -56,7 +59,7 @@ const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef }
|
|
|
56
59
|
lastValueRef.current = value;
|
|
57
60
|
return;
|
|
58
61
|
}
|
|
59
|
-
const currentTokens = editorRef.current?.getEditorState().read(
|
|
62
|
+
const currentTokens = editorRef.current?.getEditorState().read($getTokens);
|
|
60
63
|
if (currentTokens && (0, index_cjs_namespaceObject.areTokensEqual)(currentTokens, value)) {
|
|
61
64
|
lastValueRef.current = value;
|
|
62
65
|
return;
|
|
@@ -68,7 +71,7 @@ const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef }
|
|
|
68
71
|
if (isSyncingRef) isSyncingRef.current = true;
|
|
69
72
|
editor.update(()=>{
|
|
70
73
|
if (shouldSkipDomSelection) (0, external_lexical_namespaceObject.$addUpdateTag)(external_lexical_namespaceObject.SKIP_DOM_SELECTION_TAG);
|
|
71
|
-
(
|
|
74
|
+
$setTokens(value);
|
|
72
75
|
}, {
|
|
73
76
|
discrete: true,
|
|
74
77
|
onUpdate: ()=>{
|
|
@@ -85,7 +88,9 @@ const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef }
|
|
|
85
88
|
value,
|
|
86
89
|
editorRef,
|
|
87
90
|
lastEmittedValueRef,
|
|
88
|
-
isSyncingRef
|
|
91
|
+
isSyncingRef,
|
|
92
|
+
$getTokens,
|
|
93
|
+
$setTokens
|
|
89
94
|
]);
|
|
90
95
|
return null;
|
|
91
96
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type LexicalEditor } from 'lexical';
|
|
2
2
|
import type { PromptEditorToken } from '../types';
|
|
3
|
-
export declare const ValueSyncPlugin: ({ value, editorRef, lastEmittedValueRef, isSyncingRef, }: {
|
|
3
|
+
export declare const ValueSyncPlugin: ({ value, editorRef, lastEmittedValueRef, isSyncingRef, richText, }: {
|
|
4
4
|
value: PromptEditorToken[] | undefined;
|
|
5
5
|
editorRef: React.MutableRefObject<LexicalEditor | null>;
|
|
6
6
|
lastEmittedValueRef?: React.MutableRefObject<PromptEditorToken[] | null>;
|
|
7
7
|
isSyncingRef?: React.MutableRefObject<boolean>;
|
|
8
|
+
/** WYSIWYG mode: read/write through the markdown-aware serializers so a sync can't flatten rich state. */
|
|
9
|
+
richText?: boolean;
|
|
8
10
|
}) => null;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
2
|
import { $addUpdateTag, SKIP_DOM_SELECTION_TAG } from "lexical";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
4
|
import { $getEditorTokensInternal, $setEditorTokensInternal, areTokensEqual } from "../utils/index.js";
|
|
5
|
+
import { $getRichEditorTokensInternal, $setRichEditorTokensInternal } from "../utils/rich-serialization.js";
|
|
5
6
|
const getDeepActiveElement = (rootElement)=>{
|
|
6
7
|
const rootNode = rootElement.getRootNode();
|
|
7
8
|
let activeElement = null;
|
|
@@ -14,9 +15,11 @@ const isEditorFocused = (rootElement)=>{
|
|
|
14
15
|
const activeElement = getDeepActiveElement(rootElement);
|
|
15
16
|
return !!activeElement && (activeElement === rootElement || rootElement.contains(activeElement));
|
|
16
17
|
};
|
|
17
|
-
const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef })=>{
|
|
18
|
+
const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef, richText })=>{
|
|
18
19
|
const [editor] = useLexicalComposerContext();
|
|
19
20
|
const lastValueRef = useRef(value);
|
|
21
|
+
const $getTokens = richText ? $getRichEditorTokensInternal : $getEditorTokensInternal;
|
|
22
|
+
const $setTokens = richText ? $setRichEditorTokensInternal : $setEditorTokensInternal;
|
|
20
23
|
useEffect(()=>{
|
|
21
24
|
if (void 0 === value) return;
|
|
22
25
|
if (value === lastValueRef.current) return;
|
|
@@ -28,7 +31,7 @@ const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef }
|
|
|
28
31
|
lastValueRef.current = value;
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
|
-
const currentTokens = editorRef.current?.getEditorState().read($
|
|
34
|
+
const currentTokens = editorRef.current?.getEditorState().read($getTokens);
|
|
32
35
|
if (currentTokens && areTokensEqual(currentTokens, value)) {
|
|
33
36
|
lastValueRef.current = value;
|
|
34
37
|
return;
|
|
@@ -40,7 +43,7 @@ const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef }
|
|
|
40
43
|
if (isSyncingRef) isSyncingRef.current = true;
|
|
41
44
|
editor.update(()=>{
|
|
42
45
|
if (shouldSkipDomSelection) $addUpdateTag(SKIP_DOM_SELECTION_TAG);
|
|
43
|
-
$
|
|
46
|
+
$setTokens(value);
|
|
44
47
|
}, {
|
|
45
48
|
discrete: true,
|
|
46
49
|
onUpdate: ()=>{
|
|
@@ -57,7 +60,9 @@ const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef }
|
|
|
57
60
|
value,
|
|
58
61
|
editorRef,
|
|
59
62
|
lastEmittedValueRef,
|
|
60
|
-
isSyncingRef
|
|
63
|
+
isSyncingRef,
|
|
64
|
+
$getTokens,
|
|
65
|
+
$setTokens
|
|
61
66
|
]);
|
|
62
67
|
return null;
|
|
63
68
|
};
|
|
@@ -66,7 +66,7 @@ const $resolveDropPosition = (editor, offsetNode, domOffset, clientX)=>{
|
|
|
66
66
|
offset: domOffset,
|
|
67
67
|
type: 'text'
|
|
68
68
|
};
|
|
69
|
-
if ((0, external_lexical_namespaceObject.$
|
|
69
|
+
if ((0, external_lexical_namespaceObject.$isElementNode)(node) && !node.isInline()) return {
|
|
70
70
|
key: node.getKey(),
|
|
71
71
|
offset: domOffset,
|
|
72
72
|
type: 'element'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
-
import { $createRangeSelection, $getNearestNodeFromDOMNode, $getRoot, $isDecoratorNode, $
|
|
2
|
+
import { $createRangeSelection, $getNearestNodeFromDOMNode, $getRoot, $isDecoratorNode, $isElementNode, $isTextNode, $setSelection } from "lexical";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { $insertTokenAtCursor } from "../utils/index.js";
|
|
5
5
|
const VARIABLE_DRAG_MIME = 'application/x-apollo-prompt-variable';
|
|
@@ -37,7 +37,7 @@ const $resolveDropPosition = (editor, offsetNode, domOffset, clientX)=>{
|
|
|
37
37
|
offset: domOffset,
|
|
38
38
|
type: 'text'
|
|
39
39
|
};
|
|
40
|
-
if ($
|
|
40
|
+
if ($isElementNode(node) && !node.isInline()) return {
|
|
41
41
|
key: node.getKey(),
|
|
42
42
|
offset: domOffset,
|
|
43
43
|
type: 'element'
|
|
@@ -25,22 +25,31 @@ var __webpack_exports__ = {};
|
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
isPromptTokenNode: ()=>isPromptTokenNode,
|
|
28
|
+
NODE_TYPE_TO_TOKEN_TYPE: ()=>NODE_TYPE_TO_TOKEN_TYPE,
|
|
28
29
|
getAllPromptTokenNodes: ()=>getAllPromptTokenNodes
|
|
29
30
|
});
|
|
30
31
|
const utils_namespaceObject = require("@lexical/utils");
|
|
31
32
|
const InputTokenNode_cjs_namespaceObject = require("../../nodes/InputTokenNode.cjs");
|
|
32
33
|
const OutputTokenNode_cjs_namespaceObject = require("../../nodes/OutputTokenNode.cjs");
|
|
33
|
-
const StateTokenNode_cjs_namespaceObject = require("../../nodes/StateTokenNode.cjs");
|
|
34
34
|
const ResourceTokenNode_cjs_namespaceObject = require("../../nodes/ResourceTokenNode.cjs");
|
|
35
|
+
const StateTokenNode_cjs_namespaceObject = require("../../nodes/StateTokenNode.cjs");
|
|
36
|
+
const NODE_TYPE_TO_TOKEN_TYPE = {
|
|
37
|
+
'input-token': 'input',
|
|
38
|
+
'output-token': 'output',
|
|
39
|
+
'state-token': 'state',
|
|
40
|
+
'resource-token': 'resource'
|
|
41
|
+
};
|
|
35
42
|
const isPromptTokenNode = (node)=>(0, InputTokenNode_cjs_namespaceObject.isInputTokenNode)(node) || (0, OutputTokenNode_cjs_namespaceObject.isOutputTokenNode)(node) || (0, StateTokenNode_cjs_namespaceObject.isStateTokenNode)(node) || (0, ResourceTokenNode_cjs_namespaceObject.isResourceTokenNode)(node);
|
|
36
43
|
const getAllPromptTokenNodes = ()=>{
|
|
37
44
|
const nodes = [];
|
|
38
45
|
for (const { node } of (0, utils_namespaceObject.$dfs)())if (isPromptTokenNode(node)) nodes.push(node);
|
|
39
46
|
return nodes;
|
|
40
47
|
};
|
|
48
|
+
exports.NODE_TYPE_TO_TOKEN_TYPE = __webpack_exports__.NODE_TYPE_TO_TOKEN_TYPE;
|
|
41
49
|
exports.getAllPromptTokenNodes = __webpack_exports__.getAllPromptTokenNodes;
|
|
42
50
|
exports.isPromptTokenNode = __webpack_exports__.isPromptTokenNode;
|
|
43
51
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
52
|
+
"NODE_TYPE_TO_TOKEN_TYPE",
|
|
44
53
|
"getAllPromptTokenNodes",
|
|
45
54
|
"isPromptTokenNode"
|
|
46
55
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { LexicalNode } from 'lexical';
|
|
2
2
|
import { type InputTokenNode } from '../../nodes/InputTokenNode';
|
|
3
3
|
import { type OutputTokenNode } from '../../nodes/OutputTokenNode';
|
|
4
|
-
import { type StateTokenNode } from '../../nodes/StateTokenNode';
|
|
5
4
|
import { type ResourceTokenNode } from '../../nodes/ResourceTokenNode';
|
|
5
|
+
import { type StateTokenNode } from '../../nodes/StateTokenNode';
|
|
6
|
+
import type { PromptEditorTokenType } from '../../types';
|
|
6
7
|
export type PromptTokenNode = InputTokenNode | OutputTokenNode | StateTokenNode | ResourceTokenNode;
|
|
8
|
+
/** Lexical node type → token type, typed so lookups need no cast. */
|
|
9
|
+
export declare const NODE_TYPE_TO_TOKEN_TYPE: Record<string, Exclude<PromptEditorTokenType, 'text'>>;
|
|
7
10
|
export declare const isPromptTokenNode: (node: LexicalNode | null | undefined) => node is PromptTokenNode;
|
|
8
11
|
export declare const getAllPromptTokenNodes: () => PromptTokenNode[];
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { $dfs } from "@lexical/utils";
|
|
2
2
|
import { isInputTokenNode } from "../../nodes/InputTokenNode.js";
|
|
3
3
|
import { isOutputTokenNode } from "../../nodes/OutputTokenNode.js";
|
|
4
|
-
import { isStateTokenNode } from "../../nodes/StateTokenNode.js";
|
|
5
4
|
import { isResourceTokenNode } from "../../nodes/ResourceTokenNode.js";
|
|
5
|
+
import { isStateTokenNode } from "../../nodes/StateTokenNode.js";
|
|
6
|
+
const NODE_TYPE_TO_TOKEN_TYPE = {
|
|
7
|
+
'input-token': 'input',
|
|
8
|
+
'output-token': 'output',
|
|
9
|
+
'state-token': 'state',
|
|
10
|
+
'resource-token': 'resource'
|
|
11
|
+
};
|
|
6
12
|
const isPromptTokenNode = (node)=>isInputTokenNode(node) || isOutputTokenNode(node) || isStateTokenNode(node) || isResourceTokenNode(node);
|
|
7
13
|
const getAllPromptTokenNodes = ()=>{
|
|
8
14
|
const nodes = [];
|
|
9
15
|
for (const { node } of $dfs())if (isPromptTokenNode(node)) nodes.push(node);
|
|
10
16
|
return nodes;
|
|
11
17
|
};
|
|
12
|
-
export { getAllPromptTokenNodes, isPromptTokenNode };
|
|
18
|
+
export { NODE_TYPE_TO_TOKEN_TYPE, getAllPromptTokenNodes, isPromptTokenNode };
|