@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,194 @@
|
|
|
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
|
+
PromptEditorAutocompleteMenu: ()=>PromptEditorAutocompleteMenu
|
|
28
|
+
});
|
|
29
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
|
+
const external_lucide_react_namespaceObject = require("lucide-react");
|
|
31
|
+
const external_react_namespaceObject = require("react");
|
|
32
|
+
const external_react_dom_namespaceObject = require("react-dom");
|
|
33
|
+
const external_command_cjs_namespaceObject = require("../../command.cjs");
|
|
34
|
+
const external_types_cjs_namespaceObject = require("../types.cjs");
|
|
35
|
+
const autocomplete_segments_cjs_namespaceObject = require("../utils/autocomplete-segments.cjs");
|
|
36
|
+
const MENU_WIDTH = 320;
|
|
37
|
+
const VIEWPORT_MARGIN = 8;
|
|
38
|
+
const OPTION_ICON = {
|
|
39
|
+
input: external_lucide_react_namespaceObject.Variable,
|
|
40
|
+
output: external_lucide_react_namespaceObject.SquareFunction,
|
|
41
|
+
state: external_lucide_react_namespaceObject.Database,
|
|
42
|
+
resource: external_lucide_react_namespaceObject.Paperclip
|
|
43
|
+
};
|
|
44
|
+
function resolvePortalTarget(contextElement) {
|
|
45
|
+
const dialogContent = contextElement?.closest?.('[role="dialog"]');
|
|
46
|
+
if (dialogContent instanceof HTMLElement) return dialogContent;
|
|
47
|
+
return document.body;
|
|
48
|
+
}
|
|
49
|
+
const PromptEditorAutocompleteMenu = ({ open, anchorEl, initialSearch, options, onSelect, onCommitFreeForm, onClose })=>{
|
|
50
|
+
const containerRef = (0, external_react_namespaceObject.useRef)(null);
|
|
51
|
+
const [search, setSearch] = (0, external_react_namespaceObject.useState)(initialSearch);
|
|
52
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
53
|
+
if (open) setSearch(initialSearch);
|
|
54
|
+
}, [
|
|
55
|
+
open,
|
|
56
|
+
initialSearch
|
|
57
|
+
]);
|
|
58
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
59
|
+
if (!open) return;
|
|
60
|
+
const handlePointerDown = (e)=>{
|
|
61
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) onClose();
|
|
62
|
+
};
|
|
63
|
+
document.addEventListener('pointerdown', handlePointerDown, true);
|
|
64
|
+
return ()=>document.removeEventListener('pointerdown', handlePointerDown, true);
|
|
65
|
+
}, [
|
|
66
|
+
open,
|
|
67
|
+
onClose
|
|
68
|
+
]);
|
|
69
|
+
const [, forceUpdate] = (0, external_react_namespaceObject.useReducer)((tick)=>tick + 1, 0);
|
|
70
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
71
|
+
if (!open || !anchorEl) return;
|
|
72
|
+
let rafId = null;
|
|
73
|
+
const onScrollOrResize = (event)=>{
|
|
74
|
+
if ('scroll' === event.type && containerRef.current?.contains(event.target)) return;
|
|
75
|
+
if (null !== rafId) return;
|
|
76
|
+
rafId = requestAnimationFrame(()=>{
|
|
77
|
+
rafId = null;
|
|
78
|
+
forceUpdate();
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
document.addEventListener('scroll', onScrollOrResize, true);
|
|
82
|
+
window.addEventListener('resize', onScrollOrResize);
|
|
83
|
+
return ()=>{
|
|
84
|
+
document.removeEventListener('scroll', onScrollOrResize, true);
|
|
85
|
+
window.removeEventListener('resize', onScrollOrResize);
|
|
86
|
+
if (null !== rafId) cancelAnimationFrame(rafId);
|
|
87
|
+
};
|
|
88
|
+
}, [
|
|
89
|
+
open,
|
|
90
|
+
anchorEl
|
|
91
|
+
]);
|
|
92
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
93
|
+
if (!open) return;
|
|
94
|
+
const node = containerRef.current;
|
|
95
|
+
if (!node) return;
|
|
96
|
+
const handlePointerDown = (e)=>{
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
};
|
|
100
|
+
node.addEventListener('pointerdown', handlePointerDown);
|
|
101
|
+
return ()=>node.removeEventListener('pointerdown', handlePointerDown);
|
|
102
|
+
}, [
|
|
103
|
+
open
|
|
104
|
+
]);
|
|
105
|
+
if (!open || !anchorEl) return null;
|
|
106
|
+
const rect = anchorEl.getBoundingClientRect();
|
|
107
|
+
const left = Math.max(VIEWPORT_MARGIN, Math.min(rect.left, window.innerWidth - MENU_WIDTH - VIEWPORT_MARGIN));
|
|
108
|
+
const portalTarget = resolvePortalTarget(anchorEl.contextElement);
|
|
109
|
+
const trimmedSearch = search.trim();
|
|
110
|
+
const freeFormPath = onCommitFreeForm && autocomplete_segments_cjs_namespaceObject.VARIABLE_PATH_REGEX.test(trimmedSearch) && !options.some((o)=>o.value === trimmedSearch) ? trimmedSearch : null;
|
|
111
|
+
return /*#__PURE__*/ (0, external_react_dom_namespaceObject.createPortal)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
112
|
+
ref: containerRef,
|
|
113
|
+
"data-variable-picker-popover": "",
|
|
114
|
+
className: "rounded-md border bg-popover shadow-lg",
|
|
115
|
+
style: {
|
|
116
|
+
position: 'fixed',
|
|
117
|
+
top: rect.bottom + 4,
|
|
118
|
+
left,
|
|
119
|
+
width: MENU_WIDTH,
|
|
120
|
+
zIndex: 1400
|
|
121
|
+
},
|
|
122
|
+
onKeyDown: (e)=>{
|
|
123
|
+
if ('Escape' === e.key) {
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
onClose();
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_command_cjs_namespaceObject.Command, {
|
|
129
|
+
shouldFilter: true,
|
|
130
|
+
loop: true,
|
|
131
|
+
children: [
|
|
132
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_command_cjs_namespaceObject.CommandInput, {
|
|
133
|
+
value: search,
|
|
134
|
+
onValueChange: setSearch,
|
|
135
|
+
placeholder: "Search variables…",
|
|
136
|
+
autoFocus: true
|
|
137
|
+
}),
|
|
138
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_command_cjs_namespaceObject.CommandList, {
|
|
139
|
+
children: [
|
|
140
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_command_cjs_namespaceObject.CommandEmpty, {
|
|
141
|
+
children: "No variables found."
|
|
142
|
+
}),
|
|
143
|
+
options.map((option)=>{
|
|
144
|
+
const Icon = OPTION_ICON[option.type];
|
|
145
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_command_cjs_namespaceObject.CommandItem, {
|
|
146
|
+
value: option.value,
|
|
147
|
+
onSelect: ()=>onSelect(option.value),
|
|
148
|
+
children: [
|
|
149
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Icon, {
|
|
150
|
+
className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
|
|
151
|
+
}),
|
|
152
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
153
|
+
className: "truncate",
|
|
154
|
+
children: option.value
|
|
155
|
+
}),
|
|
156
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
157
|
+
className: "ml-auto pl-2 text-xs text-muted-foreground",
|
|
158
|
+
children: (0, external_types_cjs_namespaceObject.getPromptEditorTokenTypeLabel)(option.type)
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
}, `${option.type}:${option.value}`);
|
|
162
|
+
}),
|
|
163
|
+
freeFormPath && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_command_cjs_namespaceObject.CommandItem, {
|
|
164
|
+
value: freeFormPath,
|
|
165
|
+
onSelect: ()=>onCommitFreeForm?.(freeFormPath),
|
|
166
|
+
children: [
|
|
167
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_lucide_react_namespaceObject.Variable, {
|
|
168
|
+
className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
|
|
169
|
+
}),
|
|
170
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("span", {
|
|
171
|
+
className: "truncate",
|
|
172
|
+
children: [
|
|
173
|
+
"Insert ",
|
|
174
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
175
|
+
className: "font-medium",
|
|
176
|
+
children: freeFormPath
|
|
177
|
+
})
|
|
178
|
+
]
|
|
179
|
+
})
|
|
180
|
+
]
|
|
181
|
+
})
|
|
182
|
+
]
|
|
183
|
+
})
|
|
184
|
+
]
|
|
185
|
+
})
|
|
186
|
+
}), portalTarget);
|
|
187
|
+
};
|
|
188
|
+
exports.PromptEditorAutocompleteMenu = __webpack_exports__.PromptEditorAutocompleteMenu;
|
|
189
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
190
|
+
"PromptEditorAutocompleteMenu"
|
|
191
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
192
|
+
Object.defineProperty(exports, '__esModule', {
|
|
193
|
+
value: true
|
|
194
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PromptEditorAutoCompleteOption } from '../types';
|
|
2
|
+
export interface PromptEditorAutocompleteMenuProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
anchorEl: {
|
|
5
|
+
getBoundingClientRect: () => DOMRect;
|
|
6
|
+
contextElement?: Element;
|
|
7
|
+
} | null;
|
|
8
|
+
/** Pre-fill the search input with the user's typed prefix (everything after `$`). */
|
|
9
|
+
initialSearch: string;
|
|
10
|
+
/** Variable options to offer. */
|
|
11
|
+
options: PromptEditorAutoCompleteOption[];
|
|
12
|
+
/** Called with the selected option's value (path). */
|
|
13
|
+
onSelect: (path: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Commit the typed query verbatim as a free-form chip. When set, a typed path that matches no
|
|
16
|
+
* option but is a valid variable path is offered as an "Insert" item so Enter commits it (the
|
|
17
|
+
* menu owns Enter while focused, so free-form commit has to happen here, not in the editor).
|
|
18
|
+
*/
|
|
19
|
+
onCommitFreeForm?: (path: string) => void;
|
|
20
|
+
/** Called when the menu should close (Escape, click-outside, selection committed). */
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Caret-anchored variable picker for the prompt editor's `$` trigger. Built on apollo-wind's
|
|
25
|
+
* `Command` (cmdk) for search + keyboard nav, anchored to the Lexical caret rect via a
|
|
26
|
+
* `position: fixed` container that tracks the caret across scroll/resize.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PromptEditorAutocompleteMenu: ({ open, anchorEl, initialSearch, options, onSelect, onCommitFreeForm, onClose, }: PromptEditorAutocompleteMenuProps) => import("react").ReactPortal | null;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Database, Paperclip, SquareFunction, Variable } from "lucide-react";
|
|
3
|
+
import { useEffect, useReducer, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { Command, CommandEmpty, CommandInput, CommandItem, CommandList } from "../../command.js";
|
|
6
|
+
import { getPromptEditorTokenTypeLabel } from "../types.js";
|
|
7
|
+
import { VARIABLE_PATH_REGEX } from "../utils/autocomplete-segments.js";
|
|
8
|
+
const MENU_WIDTH = 320;
|
|
9
|
+
const VIEWPORT_MARGIN = 8;
|
|
10
|
+
const OPTION_ICON = {
|
|
11
|
+
input: Variable,
|
|
12
|
+
output: SquareFunction,
|
|
13
|
+
state: Database,
|
|
14
|
+
resource: Paperclip
|
|
15
|
+
};
|
|
16
|
+
function resolvePortalTarget(contextElement) {
|
|
17
|
+
const dialogContent = contextElement?.closest?.('[role="dialog"]');
|
|
18
|
+
if (dialogContent instanceof HTMLElement) return dialogContent;
|
|
19
|
+
return document.body;
|
|
20
|
+
}
|
|
21
|
+
const PromptEditorAutocompleteMenu = ({ open, anchorEl, initialSearch, options, onSelect, onCommitFreeForm, onClose })=>{
|
|
22
|
+
const containerRef = useRef(null);
|
|
23
|
+
const [search, setSearch] = useState(initialSearch);
|
|
24
|
+
useEffect(()=>{
|
|
25
|
+
if (open) setSearch(initialSearch);
|
|
26
|
+
}, [
|
|
27
|
+
open,
|
|
28
|
+
initialSearch
|
|
29
|
+
]);
|
|
30
|
+
useEffect(()=>{
|
|
31
|
+
if (!open) return;
|
|
32
|
+
const handlePointerDown = (e)=>{
|
|
33
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) onClose();
|
|
34
|
+
};
|
|
35
|
+
document.addEventListener('pointerdown', handlePointerDown, true);
|
|
36
|
+
return ()=>document.removeEventListener('pointerdown', handlePointerDown, true);
|
|
37
|
+
}, [
|
|
38
|
+
open,
|
|
39
|
+
onClose
|
|
40
|
+
]);
|
|
41
|
+
const [, forceUpdate] = useReducer((tick)=>tick + 1, 0);
|
|
42
|
+
useEffect(()=>{
|
|
43
|
+
if (!open || !anchorEl) return;
|
|
44
|
+
let rafId = null;
|
|
45
|
+
const onScrollOrResize = (event)=>{
|
|
46
|
+
if ('scroll' === event.type && containerRef.current?.contains(event.target)) return;
|
|
47
|
+
if (null !== rafId) return;
|
|
48
|
+
rafId = requestAnimationFrame(()=>{
|
|
49
|
+
rafId = null;
|
|
50
|
+
forceUpdate();
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
document.addEventListener('scroll', onScrollOrResize, true);
|
|
54
|
+
window.addEventListener('resize', onScrollOrResize);
|
|
55
|
+
return ()=>{
|
|
56
|
+
document.removeEventListener('scroll', onScrollOrResize, true);
|
|
57
|
+
window.removeEventListener('resize', onScrollOrResize);
|
|
58
|
+
if (null !== rafId) cancelAnimationFrame(rafId);
|
|
59
|
+
};
|
|
60
|
+
}, [
|
|
61
|
+
open,
|
|
62
|
+
anchorEl
|
|
63
|
+
]);
|
|
64
|
+
useEffect(()=>{
|
|
65
|
+
if (!open) return;
|
|
66
|
+
const node = containerRef.current;
|
|
67
|
+
if (!node) return;
|
|
68
|
+
const handlePointerDown = (e)=>{
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
};
|
|
72
|
+
node.addEventListener('pointerdown', handlePointerDown);
|
|
73
|
+
return ()=>node.removeEventListener('pointerdown', handlePointerDown);
|
|
74
|
+
}, [
|
|
75
|
+
open
|
|
76
|
+
]);
|
|
77
|
+
if (!open || !anchorEl) return null;
|
|
78
|
+
const rect = anchorEl.getBoundingClientRect();
|
|
79
|
+
const left = Math.max(VIEWPORT_MARGIN, Math.min(rect.left, window.innerWidth - MENU_WIDTH - VIEWPORT_MARGIN));
|
|
80
|
+
const portalTarget = resolvePortalTarget(anchorEl.contextElement);
|
|
81
|
+
const trimmedSearch = search.trim();
|
|
82
|
+
const freeFormPath = onCommitFreeForm && VARIABLE_PATH_REGEX.test(trimmedSearch) && !options.some((o)=>o.value === trimmedSearch) ? trimmedSearch : null;
|
|
83
|
+
return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
|
|
84
|
+
ref: containerRef,
|
|
85
|
+
"data-variable-picker-popover": "",
|
|
86
|
+
className: "rounded-md border bg-popover shadow-lg",
|
|
87
|
+
style: {
|
|
88
|
+
position: 'fixed',
|
|
89
|
+
top: rect.bottom + 4,
|
|
90
|
+
left,
|
|
91
|
+
width: MENU_WIDTH,
|
|
92
|
+
zIndex: 1400
|
|
93
|
+
},
|
|
94
|
+
onKeyDown: (e)=>{
|
|
95
|
+
if ('Escape' === e.key) {
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
onClose();
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
children: /*#__PURE__*/ jsxs(Command, {
|
|
101
|
+
shouldFilter: true,
|
|
102
|
+
loop: true,
|
|
103
|
+
children: [
|
|
104
|
+
/*#__PURE__*/ jsx(CommandInput, {
|
|
105
|
+
value: search,
|
|
106
|
+
onValueChange: setSearch,
|
|
107
|
+
placeholder: "Search variables…",
|
|
108
|
+
autoFocus: true
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ jsxs(CommandList, {
|
|
111
|
+
children: [
|
|
112
|
+
/*#__PURE__*/ jsx(CommandEmpty, {
|
|
113
|
+
children: "No variables found."
|
|
114
|
+
}),
|
|
115
|
+
options.map((option)=>{
|
|
116
|
+
const Icon = OPTION_ICON[option.type];
|
|
117
|
+
return /*#__PURE__*/ jsxs(CommandItem, {
|
|
118
|
+
value: option.value,
|
|
119
|
+
onSelect: ()=>onSelect(option.value),
|
|
120
|
+
children: [
|
|
121
|
+
/*#__PURE__*/ jsx(Icon, {
|
|
122
|
+
className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ jsx("span", {
|
|
125
|
+
className: "truncate",
|
|
126
|
+
children: option.value
|
|
127
|
+
}),
|
|
128
|
+
/*#__PURE__*/ jsx("span", {
|
|
129
|
+
className: "ml-auto pl-2 text-xs text-muted-foreground",
|
|
130
|
+
children: getPromptEditorTokenTypeLabel(option.type)
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
}, `${option.type}:${option.value}`);
|
|
134
|
+
}),
|
|
135
|
+
freeFormPath && /*#__PURE__*/ jsxs(CommandItem, {
|
|
136
|
+
value: freeFormPath,
|
|
137
|
+
onSelect: ()=>onCommitFreeForm?.(freeFormPath),
|
|
138
|
+
children: [
|
|
139
|
+
/*#__PURE__*/ jsx(Variable, {
|
|
140
|
+
className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
|
|
141
|
+
}),
|
|
142
|
+
/*#__PURE__*/ jsxs("span", {
|
|
143
|
+
className: "truncate",
|
|
144
|
+
children: [
|
|
145
|
+
"Insert ",
|
|
146
|
+
/*#__PURE__*/ jsx("span", {
|
|
147
|
+
className: "font-medium",
|
|
148
|
+
children: freeFormPath
|
|
149
|
+
})
|
|
150
|
+
]
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
})
|
|
154
|
+
]
|
|
155
|
+
})
|
|
156
|
+
]
|
|
157
|
+
})
|
|
158
|
+
}), portalTarget);
|
|
159
|
+
};
|
|
160
|
+
export { PromptEditorAutocompleteMenu };
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
TokenPill: ()=>TokenPill
|
|
28
|
+
});
|
|
29
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
|
+
const external_react_namespaceObject = require("react");
|
|
31
|
+
const external_lucide_react_namespaceObject = require("lucide-react");
|
|
32
|
+
const external_types_cjs_namespaceObject = require("../types.cjs");
|
|
33
|
+
const TOKEN_TYPE_ICON = {
|
|
34
|
+
input: external_lucide_react_namespaceObject.Variable,
|
|
35
|
+
output: external_lucide_react_namespaceObject.SquareFunction,
|
|
36
|
+
state: external_lucide_react_namespaceObject.Database,
|
|
37
|
+
resource: external_lucide_react_namespaceObject.Paperclip,
|
|
38
|
+
text: external_lucide_react_namespaceObject.Variable
|
|
39
|
+
};
|
|
40
|
+
const TokenPillBase = ({ value, tokenType, onRemove, diffType, readonly, isInvalid, isSelected, onMouseDown })=>{
|
|
41
|
+
const PROMPT_EDITOR_TOKEN_COLORS = (0, external_types_cjs_namespaceObject.getPromptEditorTokenColors)();
|
|
42
|
+
const colors = isInvalid && !diffType ? PROMPT_EDITOR_TOKEN_COLORS.invalid : PROMPT_EDITOR_TOKEN_COLORS.valid;
|
|
43
|
+
const Icon = TOKEN_TYPE_ICON[tokenType];
|
|
44
|
+
const handleRemoveMouseDown = (e)=>{
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
};
|
|
48
|
+
const handleRemoveClick = (e)=>{
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
onRemove?.();
|
|
52
|
+
};
|
|
53
|
+
const bgColor = diffType ? 'added' === diffType ? 'rgba(76, 175, 80, 0.15)' : 'rgba(244, 67, 54, 0.15)' : colors.background;
|
|
54
|
+
const outerClassName = [
|
|
55
|
+
'relative inline-flex items-center align-middle gap-[3px] h-5 rounded px-1 text-[13px] leading-5 outline-offset-1',
|
|
56
|
+
readonly ? 'cursor-default' : 'cursor-pointer',
|
|
57
|
+
'removed' === diffType ? 'line-through opacity-60' : '',
|
|
58
|
+
isSelected ? 'z-10' : ''
|
|
59
|
+
].filter(Boolean).join(' ');
|
|
60
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("span", {
|
|
61
|
+
onMouseDown: onMouseDown,
|
|
62
|
+
className: outerClassName,
|
|
63
|
+
style: {
|
|
64
|
+
backgroundColor: bgColor,
|
|
65
|
+
outline: isSelected ? `2px solid ${colors.border}` : 'none'
|
|
66
|
+
},
|
|
67
|
+
children: [
|
|
68
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
69
|
+
className: "inline-flex shrink-0",
|
|
70
|
+
style: {
|
|
71
|
+
color: colors.icon
|
|
72
|
+
},
|
|
73
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Icon, {
|
|
74
|
+
className: "h-3.5 w-3.5"
|
|
75
|
+
})
|
|
76
|
+
}),
|
|
77
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
78
|
+
className: "font-normal whitespace-nowrap",
|
|
79
|
+
style: {
|
|
80
|
+
color: colors.text,
|
|
81
|
+
fontFamily: "'Noto Sans', sans-serif"
|
|
82
|
+
},
|
|
83
|
+
children: value
|
|
84
|
+
}),
|
|
85
|
+
!readonly && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
|
|
86
|
+
type: "button",
|
|
87
|
+
"aria-label": "Remove token",
|
|
88
|
+
className: "inline-flex items-center justify-center p-px border-0 bg-transparent cursor-pointer rounded-[2px] w-4 h-4",
|
|
89
|
+
style: {
|
|
90
|
+
color: colors.text
|
|
91
|
+
},
|
|
92
|
+
onMouseDown: handleRemoveMouseDown,
|
|
93
|
+
onClick: handleRemoveClick,
|
|
94
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg", {
|
|
95
|
+
width: "12",
|
|
96
|
+
height: "12",
|
|
97
|
+
viewBox: "0 0 24 24",
|
|
98
|
+
fill: "none",
|
|
99
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
100
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("path", {
|
|
101
|
+
d: "M18 6L6 18M6 6L18 18",
|
|
102
|
+
stroke: "currentColor",
|
|
103
|
+
strokeWidth: "2",
|
|
104
|
+
strokeLinecap: "round",
|
|
105
|
+
strokeLinejoin: "round"
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const TokenPill = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(TokenPillBase);
|
|
113
|
+
exports.TokenPill = __webpack_exports__.TokenPill;
|
|
114
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
115
|
+
"TokenPill"
|
|
116
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
117
|
+
Object.defineProperty(exports, '__esModule', {
|
|
118
|
+
value: true
|
|
119
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PromptEditorDiffType, PromptEditorTokenType } from '../types';
|
|
2
|
+
export interface TokenPillProps {
|
|
3
|
+
value: string;
|
|
4
|
+
/** Token type — selects the leading icon and (via the wrapper) the tooltip label. */
|
|
5
|
+
tokenType: PromptEditorTokenType;
|
|
6
|
+
onRemove?: () => void;
|
|
7
|
+
diffType?: PromptEditorDiffType;
|
|
8
|
+
readonly?: boolean;
|
|
9
|
+
isInvalid?: boolean;
|
|
10
|
+
/** True when the underlying Lexical decorator is in `NodeSelection` — drives the focus outline. */
|
|
11
|
+
isSelected?: boolean;
|
|
12
|
+
/** Mouse-down on the pill body (not the X). The wrapper uses it to set NodeSelection on the decorator. */
|
|
13
|
+
onMouseDown?: (e: React.MouseEvent) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const TokenPill: import("react").MemoExoticComponent<({ value, tokenType, onRemove, diffType, readonly, isInvalid, isSelected, onMouseDown, }: TokenPillProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { Database, Paperclip, SquareFunction, Variable } from "lucide-react";
|
|
4
|
+
import { getPromptEditorTokenColors } from "../types.js";
|
|
5
|
+
const TOKEN_TYPE_ICON = {
|
|
6
|
+
input: Variable,
|
|
7
|
+
output: SquareFunction,
|
|
8
|
+
state: Database,
|
|
9
|
+
resource: Paperclip,
|
|
10
|
+
text: Variable
|
|
11
|
+
};
|
|
12
|
+
const TokenPillBase = ({ value, tokenType, onRemove, diffType, readonly, isInvalid, isSelected, onMouseDown })=>{
|
|
13
|
+
const PROMPT_EDITOR_TOKEN_COLORS = getPromptEditorTokenColors();
|
|
14
|
+
const colors = isInvalid && !diffType ? PROMPT_EDITOR_TOKEN_COLORS.invalid : PROMPT_EDITOR_TOKEN_COLORS.valid;
|
|
15
|
+
const Icon = TOKEN_TYPE_ICON[tokenType];
|
|
16
|
+
const handleRemoveMouseDown = (e)=>{
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
e.stopPropagation();
|
|
19
|
+
};
|
|
20
|
+
const handleRemoveClick = (e)=>{
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
onRemove?.();
|
|
24
|
+
};
|
|
25
|
+
const bgColor = diffType ? 'added' === diffType ? 'rgba(76, 175, 80, 0.15)' : 'rgba(244, 67, 54, 0.15)' : colors.background;
|
|
26
|
+
const outerClassName = [
|
|
27
|
+
'relative inline-flex items-center align-middle gap-[3px] h-5 rounded px-1 text-[13px] leading-5 outline-offset-1',
|
|
28
|
+
readonly ? 'cursor-default' : 'cursor-pointer',
|
|
29
|
+
'removed' === diffType ? 'line-through opacity-60' : '',
|
|
30
|
+
isSelected ? 'z-10' : ''
|
|
31
|
+
].filter(Boolean).join(' ');
|
|
32
|
+
return /*#__PURE__*/ jsxs("span", {
|
|
33
|
+
onMouseDown: onMouseDown,
|
|
34
|
+
className: outerClassName,
|
|
35
|
+
style: {
|
|
36
|
+
backgroundColor: bgColor,
|
|
37
|
+
outline: isSelected ? `2px solid ${colors.border}` : 'none'
|
|
38
|
+
},
|
|
39
|
+
children: [
|
|
40
|
+
/*#__PURE__*/ jsx("span", {
|
|
41
|
+
className: "inline-flex shrink-0",
|
|
42
|
+
style: {
|
|
43
|
+
color: colors.icon
|
|
44
|
+
},
|
|
45
|
+
children: /*#__PURE__*/ jsx(Icon, {
|
|
46
|
+
className: "h-3.5 w-3.5"
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
/*#__PURE__*/ jsx("span", {
|
|
50
|
+
className: "font-normal whitespace-nowrap",
|
|
51
|
+
style: {
|
|
52
|
+
color: colors.text,
|
|
53
|
+
fontFamily: "'Noto Sans', sans-serif"
|
|
54
|
+
},
|
|
55
|
+
children: value
|
|
56
|
+
}),
|
|
57
|
+
!readonly && /*#__PURE__*/ jsx("button", {
|
|
58
|
+
type: "button",
|
|
59
|
+
"aria-label": "Remove token",
|
|
60
|
+
className: "inline-flex items-center justify-center p-px border-0 bg-transparent cursor-pointer rounded-[2px] w-4 h-4",
|
|
61
|
+
style: {
|
|
62
|
+
color: colors.text
|
|
63
|
+
},
|
|
64
|
+
onMouseDown: handleRemoveMouseDown,
|
|
65
|
+
onClick: handleRemoveClick,
|
|
66
|
+
children: /*#__PURE__*/ jsx("svg", {
|
|
67
|
+
width: "12",
|
|
68
|
+
height: "12",
|
|
69
|
+
viewBox: "0 0 24 24",
|
|
70
|
+
fill: "none",
|
|
71
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
72
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
73
|
+
d: "M18 6L6 18M6 6L18 18",
|
|
74
|
+
stroke: "currentColor",
|
|
75
|
+
strokeWidth: "2",
|
|
76
|
+
strokeLinecap: "round",
|
|
77
|
+
strokeLinejoin: "round"
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const TokenPill = /*#__PURE__*/ memo(TokenPillBase);
|
|
85
|
+
export { TokenPill };
|