@uipath/apollo-wind 2.23.0 → 2.24.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/index.cjs +96 -86
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/prompt-editor/components/EditorToolbar.cjs +156 -0
- package/dist/components/ui/prompt-editor/components/EditorToolbar.d.ts +9 -0
- package/dist/components/ui/prompt-editor/components/EditorToolbar.js +122 -0
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.cjs +205 -0
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.d.ts +14 -0
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.js +161 -0
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.cjs +194 -0
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.d.ts +28 -0
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.js +160 -0
- package/dist/components/ui/prompt-editor/components/TokenPill.cjs +119 -0
- package/dist/components/ui/prompt-editor/components/TokenPill.d.ts +15 -0
- package/dist/components/ui/prompt-editor/components/TokenPill.js +85 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.cjs +138 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.d.ts +13 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.js +104 -0
- package/dist/components/ui/prompt-editor/components/token-icon-markup.cjs +138 -0
- package/dist/components/ui/prompt-editor/components/token-icon-markup.d.ts +16 -0
- package/dist/components/ui/prompt-editor/components/token-icon-markup.js +104 -0
- package/dist/components/ui/prompt-editor/index.cjs +40 -0
- package/dist/components/ui/prompt-editor/index.d.ts +4 -0
- package/dist/components/ui/prompt-editor/index.js +3 -0
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/index.cjs +72 -0
- package/dist/components/ui/prompt-editor/nodes/index.d.ts +8 -0
- package/dist/components/ui/prompt-editor/nodes/index.js +5 -0
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.cjs +242 -0
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.d.ts +15 -0
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.js +208 -0
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.cjs +164 -0
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.d.ts +1 -0
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.js +130 -0
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.cjs +50 -0
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.d.ts +4 -0
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.js +16 -0
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.cjs +108 -0
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.d.ts +3 -0
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.js +74 -0
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.cjs +313 -0
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.d.ts +7 -0
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.js +276 -0
- package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.cjs +186 -0
- package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.d.ts +7 -0
- package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.js +152 -0
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.cjs +132 -0
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.d.ts +7 -0
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.js +98 -0
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.cjs +85 -0
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.d.ts +4 -0
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.js +51 -0
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.cjs +98 -0
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.d.ts +8 -0
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.js +64 -0
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.cjs +137 -0
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.d.ts +19 -0
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.js +100 -0
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.cjs +49 -0
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.d.ts +8 -0
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.js +12 -0
- package/dist/components/ui/prompt-editor/prompt-editor.cjs +402 -0
- package/dist/components/ui/prompt-editor/prompt-editor.d.ts +35 -0
- package/dist/components/ui/prompt-editor/prompt-editor.js +368 -0
- package/dist/components/ui/prompt-editor/types.cjs +74 -0
- package/dist/components/ui/prompt-editor/types.d.ts +58 -0
- package/dist/components/ui/prompt-editor/types.js +31 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.cjs +60 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.d.ts +29 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.js +20 -0
- package/dist/components/ui/prompt-editor/utils/comparison.cjs +39 -0
- package/dist/components/ui/prompt-editor/utils/comparison.d.ts +3 -0
- package/dist/components/ui/prompt-editor/utils/comparison.js +5 -0
- package/dist/components/ui/prompt-editor/utils/index.cjs +68 -0
- package/dist/components/ui/prompt-editor/utils/index.d.ts +3 -0
- package/dist/components/ui/prompt-editor/utils/index.js +4 -0
- package/dist/components/ui/prompt-editor/utils/insert-token.cjs +103 -0
- package/dist/components/ui/prompt-editor/utils/insert-token.d.ts +12 -0
- package/dist/components/ui/prompt-editor/utils/insert-token.js +66 -0
- package/dist/components/ui/prompt-editor/utils/serialization.cjs +255 -0
- package/dist/components/ui/prompt-editor/utils/serialization.d.ts +16 -0
- package/dist/components/ui/prompt-editor/utils/serialization.js +200 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/styles.css +42 -0
- package/dist/tailwind.utilities.css +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { getAllPromptTokenNodes } from "./shared/token-nodes.js";
|
|
4
|
+
const NODE_TYPE_TO_TOKEN_TYPE = {
|
|
5
|
+
'input-token': 'input',
|
|
6
|
+
'output-token': 'output',
|
|
7
|
+
'state-token': 'state',
|
|
8
|
+
'resource-token': 'resource'
|
|
9
|
+
};
|
|
10
|
+
const ValidateTokensPlugin = ({ options })=>{
|
|
11
|
+
const [editor] = useLexicalComposerContext();
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
const validValues = new Map();
|
|
14
|
+
for (const opt of options){
|
|
15
|
+
if (!validValues.has(opt.type)) validValues.set(opt.type, new Set());
|
|
16
|
+
validValues.get(opt.type).add(opt.value);
|
|
17
|
+
}
|
|
18
|
+
const checkIsInvalid = (node)=>{
|
|
19
|
+
const tokenType = NODE_TYPE_TO_TOKEN_TYPE[node.getType()];
|
|
20
|
+
if (!tokenType) return false;
|
|
21
|
+
const validSet = validValues.get(tokenType);
|
|
22
|
+
return !validSet || !validSet.has(node.getValue());
|
|
23
|
+
};
|
|
24
|
+
const validateAllNodes = ()=>{
|
|
25
|
+
const tokenNodes = getAllPromptTokenNodes();
|
|
26
|
+
for (const node of tokenNodes){
|
|
27
|
+
const isInvalid = checkIsInvalid(node);
|
|
28
|
+
if (node.getIsInvalid() !== isInvalid) node.setIsInvalid(isInvalid);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
editor.update(validateAllNodes);
|
|
32
|
+
const unregister = editor.registerUpdateListener(({ editorState, prevEditorState })=>{
|
|
33
|
+
if (editorState === prevEditorState) return;
|
|
34
|
+
editorState.read(()=>{
|
|
35
|
+
const tokenNodes = getAllPromptTokenNodes();
|
|
36
|
+
let needsUpdate = false;
|
|
37
|
+
for (const node of tokenNodes)if (node.getIsInvalid() !== checkIsInvalid(node)) {
|
|
38
|
+
needsUpdate = true;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
if (needsUpdate) editor.update(validateAllNodes);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return unregister;
|
|
45
|
+
}, [
|
|
46
|
+
editor,
|
|
47
|
+
options
|
|
48
|
+
]);
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
export { ValidateTokensPlugin };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
ValueSyncPlugin: ()=>ValueSyncPlugin
|
|
28
|
+
});
|
|
29
|
+
const external_react_namespaceObject = require("react");
|
|
30
|
+
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
|
+
const external_lexical_namespaceObject = require("lexical");
|
|
32
|
+
const index_cjs_namespaceObject = require("../utils/index.cjs");
|
|
33
|
+
const getDeepActiveElement = (rootElement)=>{
|
|
34
|
+
const rootNode = rootElement.getRootNode();
|
|
35
|
+
let activeElement = null;
|
|
36
|
+
activeElement = rootNode instanceof ShadowRoot || rootNode instanceof Document ? rootNode.activeElement : document.activeElement;
|
|
37
|
+
while(activeElement instanceof HTMLElement && activeElement.shadowRoot?.activeElement)activeElement = activeElement.shadowRoot.activeElement;
|
|
38
|
+
return activeElement;
|
|
39
|
+
};
|
|
40
|
+
const isEditorFocused = (rootElement)=>{
|
|
41
|
+
if (!rootElement) return false;
|
|
42
|
+
const activeElement = getDeepActiveElement(rootElement);
|
|
43
|
+
return !!activeElement && (activeElement === rootElement || rootElement.contains(activeElement));
|
|
44
|
+
};
|
|
45
|
+
const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef })=>{
|
|
46
|
+
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
47
|
+
const lastValueRef = (0, external_react_namespaceObject.useRef)(value);
|
|
48
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
49
|
+
if (void 0 === value) return;
|
|
50
|
+
if (value === lastValueRef.current) return;
|
|
51
|
+
if (lastValueRef.current && (0, index_cjs_namespaceObject.areTokensEqual)(lastValueRef.current, value)) {
|
|
52
|
+
lastValueRef.current = value;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (lastEmittedValueRef?.current && (0, index_cjs_namespaceObject.areTokensEqual)(lastEmittedValueRef.current, value)) {
|
|
56
|
+
lastValueRef.current = value;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const currentTokens = editorRef.current?.getEditorState().read(index_cjs_namespaceObject.$getEditorTokensInternal);
|
|
60
|
+
if (currentTokens && (0, index_cjs_namespaceObject.areTokensEqual)(currentTokens, value)) {
|
|
61
|
+
lastValueRef.current = value;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const rootElement = editor.getRootElement();
|
|
65
|
+
const editorIsFocused = isEditorFocused(rootElement);
|
|
66
|
+
const shouldSkipDomSelection = !editorIsFocused;
|
|
67
|
+
try {
|
|
68
|
+
if (isSyncingRef) isSyncingRef.current = true;
|
|
69
|
+
editor.update(()=>{
|
|
70
|
+
if (shouldSkipDomSelection) (0, external_lexical_namespaceObject.$addUpdateTag)(external_lexical_namespaceObject.SKIP_DOM_SELECTION_TAG);
|
|
71
|
+
(0, index_cjs_namespaceObject.$setEditorTokensInternal)(value);
|
|
72
|
+
}, {
|
|
73
|
+
discrete: true,
|
|
74
|
+
onUpdate: ()=>{
|
|
75
|
+
if (isSyncingRef) isSyncingRef.current = false;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
lastValueRef.current = value;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (isSyncingRef) isSyncingRef.current = false;
|
|
81
|
+
console.error('ValueSyncPlugin: Error syncing value to editor', error);
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
editor,
|
|
85
|
+
value,
|
|
86
|
+
editorRef,
|
|
87
|
+
lastEmittedValueRef,
|
|
88
|
+
isSyncingRef
|
|
89
|
+
]);
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
exports.ValueSyncPlugin = __webpack_exports__.ValueSyncPlugin;
|
|
93
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
94
|
+
"ValueSyncPlugin"
|
|
95
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
96
|
+
Object.defineProperty(exports, '__esModule', {
|
|
97
|
+
value: true
|
|
98
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type LexicalEditor } from 'lexical';
|
|
2
|
+
import type { PromptEditorToken } from '../types';
|
|
3
|
+
export declare const ValueSyncPlugin: ({ value, editorRef, lastEmittedValueRef, isSyncingRef, }: {
|
|
4
|
+
value: PromptEditorToken[] | undefined;
|
|
5
|
+
editorRef: React.MutableRefObject<LexicalEditor | null>;
|
|
6
|
+
lastEmittedValueRef?: React.MutableRefObject<PromptEditorToken[] | null>;
|
|
7
|
+
isSyncingRef?: React.MutableRefObject<boolean>;
|
|
8
|
+
}) => null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
import { $addUpdateTag, SKIP_DOM_SELECTION_TAG } from "lexical";
|
|
4
|
+
import { $getEditorTokensInternal, $setEditorTokensInternal, areTokensEqual } from "../utils/index.js";
|
|
5
|
+
const getDeepActiveElement = (rootElement)=>{
|
|
6
|
+
const rootNode = rootElement.getRootNode();
|
|
7
|
+
let activeElement = null;
|
|
8
|
+
activeElement = rootNode instanceof ShadowRoot || rootNode instanceof Document ? rootNode.activeElement : document.activeElement;
|
|
9
|
+
while(activeElement instanceof HTMLElement && activeElement.shadowRoot?.activeElement)activeElement = activeElement.shadowRoot.activeElement;
|
|
10
|
+
return activeElement;
|
|
11
|
+
};
|
|
12
|
+
const isEditorFocused = (rootElement)=>{
|
|
13
|
+
if (!rootElement) return false;
|
|
14
|
+
const activeElement = getDeepActiveElement(rootElement);
|
|
15
|
+
return !!activeElement && (activeElement === rootElement || rootElement.contains(activeElement));
|
|
16
|
+
};
|
|
17
|
+
const ValueSyncPlugin = ({ value, editorRef, lastEmittedValueRef, isSyncingRef })=>{
|
|
18
|
+
const [editor] = useLexicalComposerContext();
|
|
19
|
+
const lastValueRef = useRef(value);
|
|
20
|
+
useEffect(()=>{
|
|
21
|
+
if (void 0 === value) return;
|
|
22
|
+
if (value === lastValueRef.current) return;
|
|
23
|
+
if (lastValueRef.current && areTokensEqual(lastValueRef.current, value)) {
|
|
24
|
+
lastValueRef.current = value;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (lastEmittedValueRef?.current && areTokensEqual(lastEmittedValueRef.current, value)) {
|
|
28
|
+
lastValueRef.current = value;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const currentTokens = editorRef.current?.getEditorState().read($getEditorTokensInternal);
|
|
32
|
+
if (currentTokens && areTokensEqual(currentTokens, value)) {
|
|
33
|
+
lastValueRef.current = value;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const rootElement = editor.getRootElement();
|
|
37
|
+
const editorIsFocused = isEditorFocused(rootElement);
|
|
38
|
+
const shouldSkipDomSelection = !editorIsFocused;
|
|
39
|
+
try {
|
|
40
|
+
if (isSyncingRef) isSyncingRef.current = true;
|
|
41
|
+
editor.update(()=>{
|
|
42
|
+
if (shouldSkipDomSelection) $addUpdateTag(SKIP_DOM_SELECTION_TAG);
|
|
43
|
+
$setEditorTokensInternal(value);
|
|
44
|
+
}, {
|
|
45
|
+
discrete: true,
|
|
46
|
+
onUpdate: ()=>{
|
|
47
|
+
if (isSyncingRef) isSyncingRef.current = false;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
lastValueRef.current = value;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (isSyncingRef) isSyncingRef.current = false;
|
|
53
|
+
console.error('ValueSyncPlugin: Error syncing value to editor', error);
|
|
54
|
+
}
|
|
55
|
+
}, [
|
|
56
|
+
editor,
|
|
57
|
+
value,
|
|
58
|
+
editorRef,
|
|
59
|
+
lastEmittedValueRef,
|
|
60
|
+
isSyncingRef
|
|
61
|
+
]);
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
export { ValueSyncPlugin };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
VARIABLE_DRAG_MIME: ()=>VARIABLE_DRAG_MIME,
|
|
28
|
+
VariableDropPlugin: ()=>VariableDropPlugin
|
|
29
|
+
});
|
|
30
|
+
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
|
+
const external_lexical_namespaceObject = require("lexical");
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
33
|
+
const index_cjs_namespaceObject = require("../utils/index.cjs");
|
|
34
|
+
const VARIABLE_DRAG_MIME = 'application/x-apollo-prompt-variable';
|
|
35
|
+
const getCaretFromPoint = (x, y)=>{
|
|
36
|
+
if (document.caretPositionFromPoint) {
|
|
37
|
+
const pos = document.caretPositionFromPoint(x, y);
|
|
38
|
+
return pos ? {
|
|
39
|
+
offsetNode: pos.offsetNode,
|
|
40
|
+
offset: pos.offset
|
|
41
|
+
} : null;
|
|
42
|
+
}
|
|
43
|
+
const range = document.caretRangeFromPoint?.(x, y);
|
|
44
|
+
return range ? {
|
|
45
|
+
offsetNode: range.startContainer,
|
|
46
|
+
offset: range.startOffset
|
|
47
|
+
} : null;
|
|
48
|
+
};
|
|
49
|
+
const $resolveDropPosition = (editor, offsetNode, domOffset, clientX)=>{
|
|
50
|
+
const node = (0, external_lexical_namespaceObject.$getNearestNodeFromDOMNode)(offsetNode);
|
|
51
|
+
if (!node) return null;
|
|
52
|
+
if ((0, external_lexical_namespaceObject.$isDecoratorNode)(node)) {
|
|
53
|
+
const el = editor.getElementByKey(node.getKey());
|
|
54
|
+
const rect = el?.getBoundingClientRect();
|
|
55
|
+
const isAfter = rect ? clientX > rect.left + rect.width / 2 : true;
|
|
56
|
+
const parent = node.getParent();
|
|
57
|
+
if (!parent) return null;
|
|
58
|
+
return {
|
|
59
|
+
key: parent.getKey(),
|
|
60
|
+
offset: node.getIndexWithinParent() + (isAfter ? 1 : 0),
|
|
61
|
+
type: 'element'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if ((0, external_lexical_namespaceObject.$isTextNode)(node)) return {
|
|
65
|
+
key: node.getKey(),
|
|
66
|
+
offset: domOffset,
|
|
67
|
+
type: 'text'
|
|
68
|
+
};
|
|
69
|
+
if ((0, external_lexical_namespaceObject.$isParagraphNode)(node)) return {
|
|
70
|
+
key: node.getKey(),
|
|
71
|
+
offset: domOffset,
|
|
72
|
+
type: 'element'
|
|
73
|
+
};
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
function VariableDropPlugin({ disabled, mapVarDropToToken }) {
|
|
77
|
+
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
78
|
+
const mapRef = (0, external_react_namespaceObject.useRef)(mapVarDropToToken);
|
|
79
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
80
|
+
mapRef.current = mapVarDropToToken;
|
|
81
|
+
});
|
|
82
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
83
|
+
if (disabled) return;
|
|
84
|
+
const hasVariablePayload = (dt)=>!!dt && dt.types.includes(VARIABLE_DRAG_MIME);
|
|
85
|
+
const onDragOver = (e)=>{
|
|
86
|
+
if (!hasVariablePayload(e.dataTransfer)) return;
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy';
|
|
89
|
+
};
|
|
90
|
+
const onDrop = (e)=>{
|
|
91
|
+
const path = e.dataTransfer?.getData(VARIABLE_DRAG_MIME);
|
|
92
|
+
if (!path) return;
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
const root = editor.getRootElement();
|
|
95
|
+
const caret = getCaretFromPoint(e.clientX, e.clientY);
|
|
96
|
+
editor.update(()=>{
|
|
97
|
+
let placed = false;
|
|
98
|
+
if (caret && root?.contains(caret.offsetNode)) {
|
|
99
|
+
const resolved = $resolveDropPosition(editor, caret.offsetNode, caret.offset, e.clientX);
|
|
100
|
+
if (resolved) {
|
|
101
|
+
const sel = (0, external_lexical_namespaceObject.$createRangeSelection)();
|
|
102
|
+
sel.anchor.set(resolved.key, resolved.offset, resolved.type);
|
|
103
|
+
sel.focus.set(resolved.key, resolved.offset, resolved.type);
|
|
104
|
+
(0, external_lexical_namespaceObject.$setSelection)(sel);
|
|
105
|
+
placed = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!placed) (0, external_lexical_namespaceObject.$getRoot)().selectEnd();
|
|
109
|
+
(0, index_cjs_namespaceObject.$insertTokenAtCursor)(mapRef.current(path));
|
|
110
|
+
});
|
|
111
|
+
editor.focus();
|
|
112
|
+
};
|
|
113
|
+
return editor.registerRootListener((rootElement, prevRootElement)=>{
|
|
114
|
+
if (prevRootElement) {
|
|
115
|
+
prevRootElement.removeEventListener('dragover', onDragOver);
|
|
116
|
+
prevRootElement.removeEventListener('drop', onDrop);
|
|
117
|
+
}
|
|
118
|
+
if (rootElement) {
|
|
119
|
+
rootElement.addEventListener('dragover', onDragOver);
|
|
120
|
+
rootElement.addEventListener('drop', onDrop);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}, [
|
|
124
|
+
editor,
|
|
125
|
+
disabled
|
|
126
|
+
]);
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
exports.VARIABLE_DRAG_MIME = __webpack_exports__.VARIABLE_DRAG_MIME;
|
|
130
|
+
exports.VariableDropPlugin = __webpack_exports__.VariableDropPlugin;
|
|
131
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
132
|
+
"VARIABLE_DRAG_MIME",
|
|
133
|
+
"VariableDropPlugin"
|
|
134
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
135
|
+
Object.defineProperty(exports, '__esModule', {
|
|
136
|
+
value: true
|
|
137
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PromptEditorAutoCompleteOption } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* dataTransfer MIME a drag source must set to the variable path string (e.g. `vars.firstName`) for
|
|
4
|
+
* the editor to treat a drop as a variable insertion. Only this MIME is handled — plain text drops
|
|
5
|
+
* (e.g. dragging selected text) fall through to the browser's native behaviour untouched.
|
|
6
|
+
*/
|
|
7
|
+
export declare const VARIABLE_DRAG_MIME = "application/x-apollo-prompt-variable";
|
|
8
|
+
export interface VariableDropPluginProps {
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Map a dropped variable path to the token option to insert at the drop point. */
|
|
11
|
+
mapVarDropToToken: (insertPath: string) => PromptEditorAutoCompleteOption;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Inserts a variable token when a drag source drops a variable path onto the editor. Native HTML5
|
|
15
|
+
* drag-drop (no dnd-kit dependency): a consumer's drag source sets the dropped path on
|
|
16
|
+
* `dataTransfer` (see {@link VARIABLE_DRAG_MIME}); on drop we resolve the caret at the drop point,
|
|
17
|
+
* map the path to a token via `mapVarDropToToken`, and insert it there.
|
|
18
|
+
*/
|
|
19
|
+
export declare function VariableDropPlugin({ disabled, mapVarDropToToken }: VariableDropPluginProps): null;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
+
import { $createRangeSelection, $getNearestNodeFromDOMNode, $getRoot, $isDecoratorNode, $isParagraphNode, $isTextNode, $setSelection } from "lexical";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { $insertTokenAtCursor } from "../utils/index.js";
|
|
5
|
+
const VARIABLE_DRAG_MIME = 'application/x-apollo-prompt-variable';
|
|
6
|
+
const getCaretFromPoint = (x, y)=>{
|
|
7
|
+
if (document.caretPositionFromPoint) {
|
|
8
|
+
const pos = document.caretPositionFromPoint(x, y);
|
|
9
|
+
return pos ? {
|
|
10
|
+
offsetNode: pos.offsetNode,
|
|
11
|
+
offset: pos.offset
|
|
12
|
+
} : null;
|
|
13
|
+
}
|
|
14
|
+
const range = document.caretRangeFromPoint?.(x, y);
|
|
15
|
+
return range ? {
|
|
16
|
+
offsetNode: range.startContainer,
|
|
17
|
+
offset: range.startOffset
|
|
18
|
+
} : null;
|
|
19
|
+
};
|
|
20
|
+
const $resolveDropPosition = (editor, offsetNode, domOffset, clientX)=>{
|
|
21
|
+
const node = $getNearestNodeFromDOMNode(offsetNode);
|
|
22
|
+
if (!node) return null;
|
|
23
|
+
if ($isDecoratorNode(node)) {
|
|
24
|
+
const el = editor.getElementByKey(node.getKey());
|
|
25
|
+
const rect = el?.getBoundingClientRect();
|
|
26
|
+
const isAfter = rect ? clientX > rect.left + rect.width / 2 : true;
|
|
27
|
+
const parent = node.getParent();
|
|
28
|
+
if (!parent) return null;
|
|
29
|
+
return {
|
|
30
|
+
key: parent.getKey(),
|
|
31
|
+
offset: node.getIndexWithinParent() + (isAfter ? 1 : 0),
|
|
32
|
+
type: 'element'
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if ($isTextNode(node)) return {
|
|
36
|
+
key: node.getKey(),
|
|
37
|
+
offset: domOffset,
|
|
38
|
+
type: 'text'
|
|
39
|
+
};
|
|
40
|
+
if ($isParagraphNode(node)) return {
|
|
41
|
+
key: node.getKey(),
|
|
42
|
+
offset: domOffset,
|
|
43
|
+
type: 'element'
|
|
44
|
+
};
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
function VariableDropPlugin({ disabled, mapVarDropToToken }) {
|
|
48
|
+
const [editor] = useLexicalComposerContext();
|
|
49
|
+
const mapRef = useRef(mapVarDropToToken);
|
|
50
|
+
useEffect(()=>{
|
|
51
|
+
mapRef.current = mapVarDropToToken;
|
|
52
|
+
});
|
|
53
|
+
useEffect(()=>{
|
|
54
|
+
if (disabled) return;
|
|
55
|
+
const hasVariablePayload = (dt)=>!!dt && dt.types.includes(VARIABLE_DRAG_MIME);
|
|
56
|
+
const onDragOver = (e)=>{
|
|
57
|
+
if (!hasVariablePayload(e.dataTransfer)) return;
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy';
|
|
60
|
+
};
|
|
61
|
+
const onDrop = (e)=>{
|
|
62
|
+
const path = e.dataTransfer?.getData(VARIABLE_DRAG_MIME);
|
|
63
|
+
if (!path) return;
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
const root = editor.getRootElement();
|
|
66
|
+
const caret = getCaretFromPoint(e.clientX, e.clientY);
|
|
67
|
+
editor.update(()=>{
|
|
68
|
+
let placed = false;
|
|
69
|
+
if (caret && root?.contains(caret.offsetNode)) {
|
|
70
|
+
const resolved = $resolveDropPosition(editor, caret.offsetNode, caret.offset, e.clientX);
|
|
71
|
+
if (resolved) {
|
|
72
|
+
const sel = $createRangeSelection();
|
|
73
|
+
sel.anchor.set(resolved.key, resolved.offset, resolved.type);
|
|
74
|
+
sel.focus.set(resolved.key, resolved.offset, resolved.type);
|
|
75
|
+
$setSelection(sel);
|
|
76
|
+
placed = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!placed) $getRoot().selectEnd();
|
|
80
|
+
$insertTokenAtCursor(mapRef.current(path));
|
|
81
|
+
});
|
|
82
|
+
editor.focus();
|
|
83
|
+
};
|
|
84
|
+
return editor.registerRootListener((rootElement, prevRootElement)=>{
|
|
85
|
+
if (prevRootElement) {
|
|
86
|
+
prevRootElement.removeEventListener('dragover', onDragOver);
|
|
87
|
+
prevRootElement.removeEventListener('drop', onDrop);
|
|
88
|
+
}
|
|
89
|
+
if (rootElement) {
|
|
90
|
+
rootElement.addEventListener('dragover', onDragOver);
|
|
91
|
+
rootElement.addEventListener('drop', onDrop);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}, [
|
|
95
|
+
editor,
|
|
96
|
+
disabled
|
|
97
|
+
]);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
export { VARIABLE_DRAG_MIME, VariableDropPlugin };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
isPromptTokenNode: ()=>isPromptTokenNode,
|
|
28
|
+
getAllPromptTokenNodes: ()=>getAllPromptTokenNodes
|
|
29
|
+
});
|
|
30
|
+
const utils_namespaceObject = require("@lexical/utils");
|
|
31
|
+
const InputTokenNode_cjs_namespaceObject = require("../../nodes/InputTokenNode.cjs");
|
|
32
|
+
const OutputTokenNode_cjs_namespaceObject = require("../../nodes/OutputTokenNode.cjs");
|
|
33
|
+
const StateTokenNode_cjs_namespaceObject = require("../../nodes/StateTokenNode.cjs");
|
|
34
|
+
const ResourceTokenNode_cjs_namespaceObject = require("../../nodes/ResourceTokenNode.cjs");
|
|
35
|
+
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
|
+
const getAllPromptTokenNodes = ()=>{
|
|
37
|
+
const nodes = [];
|
|
38
|
+
for (const { node } of (0, utils_namespaceObject.$dfs)())if (isPromptTokenNode(node)) nodes.push(node);
|
|
39
|
+
return nodes;
|
|
40
|
+
};
|
|
41
|
+
exports.getAllPromptTokenNodes = __webpack_exports__.getAllPromptTokenNodes;
|
|
42
|
+
exports.isPromptTokenNode = __webpack_exports__.isPromptTokenNode;
|
|
43
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
44
|
+
"getAllPromptTokenNodes",
|
|
45
|
+
"isPromptTokenNode"
|
|
46
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
47
|
+
Object.defineProperty(exports, '__esModule', {
|
|
48
|
+
value: true
|
|
49
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LexicalNode } from 'lexical';
|
|
2
|
+
import { type InputTokenNode } from '../../nodes/InputTokenNode';
|
|
3
|
+
import { type OutputTokenNode } from '../../nodes/OutputTokenNode';
|
|
4
|
+
import { type StateTokenNode } from '../../nodes/StateTokenNode';
|
|
5
|
+
import { type ResourceTokenNode } from '../../nodes/ResourceTokenNode';
|
|
6
|
+
export type PromptTokenNode = InputTokenNode | OutputTokenNode | StateTokenNode | ResourceTokenNode;
|
|
7
|
+
export declare const isPromptTokenNode: (node: LexicalNode | null | undefined) => node is PromptTokenNode;
|
|
8
|
+
export declare const getAllPromptTokenNodes: () => PromptTokenNode[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $dfs } from "@lexical/utils";
|
|
2
|
+
import { isInputTokenNode } from "../../nodes/InputTokenNode.js";
|
|
3
|
+
import { isOutputTokenNode } from "../../nodes/OutputTokenNode.js";
|
|
4
|
+
import { isStateTokenNode } from "../../nodes/StateTokenNode.js";
|
|
5
|
+
import { isResourceTokenNode } from "../../nodes/ResourceTokenNode.js";
|
|
6
|
+
const isPromptTokenNode = (node)=>isInputTokenNode(node) || isOutputTokenNode(node) || isStateTokenNode(node) || isResourceTokenNode(node);
|
|
7
|
+
const getAllPromptTokenNodes = ()=>{
|
|
8
|
+
const nodes = [];
|
|
9
|
+
for (const { node } of $dfs())if (isPromptTokenNode(node)) nodes.push(node);
|
|
10
|
+
return nodes;
|
|
11
|
+
};
|
|
12
|
+
export { getAllPromptTokenNodes, isPromptTokenNode };
|