@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.
Files changed (99) hide show
  1. package/dist/components/ui/index.cjs +96 -86
  2. package/dist/components/ui/index.d.ts +1 -0
  3. package/dist/components/ui/index.js +1 -0
  4. package/dist/components/ui/prompt-editor/components/EditorToolbar.cjs +156 -0
  5. package/dist/components/ui/prompt-editor/components/EditorToolbar.d.ts +9 -0
  6. package/dist/components/ui/prompt-editor/components/EditorToolbar.js +122 -0
  7. package/dist/components/ui/prompt-editor/components/MarkdownPreview.cjs +205 -0
  8. package/dist/components/ui/prompt-editor/components/MarkdownPreview.d.ts +14 -0
  9. package/dist/components/ui/prompt-editor/components/MarkdownPreview.js +161 -0
  10. package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.cjs +194 -0
  11. package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.d.ts +28 -0
  12. package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.js +160 -0
  13. package/dist/components/ui/prompt-editor/components/TokenPill.cjs +119 -0
  14. package/dist/components/ui/prompt-editor/components/TokenPill.d.ts +15 -0
  15. package/dist/components/ui/prompt-editor/components/TokenPill.js +85 -0
  16. package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.cjs +138 -0
  17. package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.d.ts +13 -0
  18. package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.js +104 -0
  19. package/dist/components/ui/prompt-editor/components/token-icon-markup.cjs +138 -0
  20. package/dist/components/ui/prompt-editor/components/token-icon-markup.d.ts +16 -0
  21. package/dist/components/ui/prompt-editor/components/token-icon-markup.js +104 -0
  22. package/dist/components/ui/prompt-editor/index.cjs +40 -0
  23. package/dist/components/ui/prompt-editor/index.d.ts +4 -0
  24. package/dist/components/ui/prompt-editor/index.js +3 -0
  25. package/dist/components/ui/prompt-editor/nodes/InputTokenNode.cjs +145 -0
  26. package/dist/components/ui/prompt-editor/nodes/InputTokenNode.d.ts +30 -0
  27. package/dist/components/ui/prompt-editor/nodes/InputTokenNode.js +105 -0
  28. package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.cjs +145 -0
  29. package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.d.ts +30 -0
  30. package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.js +105 -0
  31. package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.cjs +145 -0
  32. package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.d.ts +30 -0
  33. package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.js +105 -0
  34. package/dist/components/ui/prompt-editor/nodes/StateTokenNode.cjs +145 -0
  35. package/dist/components/ui/prompt-editor/nodes/StateTokenNode.d.ts +30 -0
  36. package/dist/components/ui/prompt-editor/nodes/StateTokenNode.js +105 -0
  37. package/dist/components/ui/prompt-editor/nodes/index.cjs +72 -0
  38. package/dist/components/ui/prompt-editor/nodes/index.d.ts +8 -0
  39. package/dist/components/ui/prompt-editor/nodes/index.js +5 -0
  40. package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.cjs +242 -0
  41. package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.d.ts +15 -0
  42. package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.js +208 -0
  43. package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.cjs +164 -0
  44. package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.d.ts +1 -0
  45. package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.js +130 -0
  46. package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.cjs +50 -0
  47. package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.d.ts +4 -0
  48. package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.js +16 -0
  49. package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.cjs +108 -0
  50. package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.d.ts +3 -0
  51. package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.js +74 -0
  52. package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.cjs +313 -0
  53. package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.d.ts +7 -0
  54. package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.js +276 -0
  55. package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.cjs +186 -0
  56. package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.d.ts +7 -0
  57. package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.js +152 -0
  58. package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.cjs +132 -0
  59. package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.d.ts +7 -0
  60. package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.js +98 -0
  61. package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.cjs +85 -0
  62. package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.d.ts +4 -0
  63. package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.js +51 -0
  64. package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.cjs +98 -0
  65. package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.d.ts +8 -0
  66. package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.js +64 -0
  67. package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.cjs +137 -0
  68. package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.d.ts +19 -0
  69. package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.js +100 -0
  70. package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.cjs +49 -0
  71. package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.d.ts +8 -0
  72. package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.js +12 -0
  73. package/dist/components/ui/prompt-editor/prompt-editor.cjs +402 -0
  74. package/dist/components/ui/prompt-editor/prompt-editor.d.ts +35 -0
  75. package/dist/components/ui/prompt-editor/prompt-editor.js +368 -0
  76. package/dist/components/ui/prompt-editor/types.cjs +74 -0
  77. package/dist/components/ui/prompt-editor/types.d.ts +58 -0
  78. package/dist/components/ui/prompt-editor/types.js +31 -0
  79. package/dist/components/ui/prompt-editor/utils/autocomplete-segments.cjs +60 -0
  80. package/dist/components/ui/prompt-editor/utils/autocomplete-segments.d.ts +29 -0
  81. package/dist/components/ui/prompt-editor/utils/autocomplete-segments.js +20 -0
  82. package/dist/components/ui/prompt-editor/utils/comparison.cjs +39 -0
  83. package/dist/components/ui/prompt-editor/utils/comparison.d.ts +3 -0
  84. package/dist/components/ui/prompt-editor/utils/comparison.js +5 -0
  85. package/dist/components/ui/prompt-editor/utils/index.cjs +68 -0
  86. package/dist/components/ui/prompt-editor/utils/index.d.ts +3 -0
  87. package/dist/components/ui/prompt-editor/utils/index.js +4 -0
  88. package/dist/components/ui/prompt-editor/utils/insert-token.cjs +103 -0
  89. package/dist/components/ui/prompt-editor/utils/insert-token.d.ts +12 -0
  90. package/dist/components/ui/prompt-editor/utils/insert-token.js +66 -0
  91. package/dist/components/ui/prompt-editor/utils/serialization.cjs +255 -0
  92. package/dist/components/ui/prompt-editor/utils/serialization.d.ts +16 -0
  93. package/dist/components/ui/prompt-editor/utils/serialization.js +200 -0
  94. package/dist/index.cjs +7 -0
  95. package/dist/index.d.ts +2 -0
  96. package/dist/index.js +2 -1
  97. package/dist/styles.css +42 -0
  98. package/dist/tailwind.utilities.css +1 -1
  99. package/package.json +7 -1
@@ -0,0 +1,186 @@
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
+ RenameTokensPlugin: ()=>RenameTokensPlugin
28
+ });
29
+ const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
30
+ const external_react_namespaceObject = require("react");
31
+ const index_cjs_namespaceObject = require("../nodes/index.cjs");
32
+ const external_utils_index_cjs_namespaceObject = require("../utils/index.cjs");
33
+ const token_nodes_cjs_namespaceObject = require("./shared/token-nodes.cjs");
34
+ const TOKEN_TYPES = [
35
+ 'input',
36
+ 'state',
37
+ 'output',
38
+ 'resource'
39
+ ];
40
+ const createTreeNode = ()=>({
41
+ children: new Map()
42
+ });
43
+ const buildPathTree = (paths)=>{
44
+ const root = createTreeNode();
45
+ for (const path of paths){
46
+ if (!path) continue;
47
+ const segments = path.split('.').filter(Boolean);
48
+ if (0 === segments.length) continue;
49
+ let current = root;
50
+ for (const segment of segments){
51
+ const next = current.children.get(segment) ?? createTreeNode();
52
+ if (!current.children.has(segment)) current.children.set(segment, next);
53
+ current = next;
54
+ }
55
+ }
56
+ return root;
57
+ };
58
+ const joinPath = (prefix, key)=>prefix ? `${prefix}.${key}` : key;
59
+ const detectPathRenames = (prevNode, nextNode, prevPrefix, nextPrefix, renames)=>{
60
+ const prevKeys = [
61
+ ...prevNode.children.keys()
62
+ ];
63
+ const nextKeys = [
64
+ ...nextNode.children.keys()
65
+ ];
66
+ const removedKeys = prevKeys.filter((k)=>!nextNode.children.has(k));
67
+ const addedKeys = nextKeys.filter((k)=>!prevNode.children.has(k));
68
+ const commonKeys = prevKeys.filter((k)=>nextNode.children.has(k));
69
+ if (1 === removedKeys.length && 1 === addedKeys.length) {
70
+ const oldPath = joinPath(prevPrefix, removedKeys[0]);
71
+ const newPath = joinPath(nextPrefix, addedKeys[0]);
72
+ renames.push({
73
+ oldPath,
74
+ newPath
75
+ });
76
+ const prevChild = prevNode.children.get(removedKeys[0]);
77
+ const nextChild = nextNode.children.get(addedKeys[0]);
78
+ if (prevChild && nextChild) detectPathRenames(prevChild, nextChild, oldPath, newPath, renames);
79
+ }
80
+ for (const key of commonKeys){
81
+ const prevChild = prevNode.children.get(key);
82
+ const nextChild = nextNode.children.get(key);
83
+ if (prevChild && nextChild) detectPathRenames(prevChild, nextChild, joinPath(prevPrefix, key), joinPath(nextPrefix, key), renames);
84
+ }
85
+ };
86
+ const groupOptionsByType = (options)=>{
87
+ const grouped = {
88
+ input: new Set(),
89
+ state: new Set(),
90
+ output: new Set(),
91
+ resource: new Set()
92
+ };
93
+ for (const opt of options)grouped[opt.type].add(opt.value);
94
+ return grouped;
95
+ };
96
+ const detectRenamesByType = (prevOptions, currOptions)=>{
97
+ const prevGrouped = groupOptionsByType(prevOptions);
98
+ const currGrouped = groupOptionsByType(currOptions);
99
+ const renames = [];
100
+ for (const type of TOKEN_TYPES){
101
+ const typeRenames = [];
102
+ detectPathRenames(buildPathTree(prevGrouped[type]), buildPathTree(currGrouped[type]), '', '', typeRenames);
103
+ for (const rename of typeRenames)renames.push({
104
+ ...rename,
105
+ type
106
+ });
107
+ }
108
+ return renames;
109
+ };
110
+ const applyPathRename = (value, oldPath, newPath)=>{
111
+ if (value === oldPath) return newPath;
112
+ if (value.startsWith(`${oldPath}.`)) return `${newPath}${value.slice(oldPath.length)}`;
113
+ return value;
114
+ };
115
+ const RenameTokensPlugin = ({ options, onChange })=>{
116
+ const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
117
+ const prevOptionsRef = (0, external_react_namespaceObject.useRef)(options);
118
+ const renameSequenceRef = (0, external_react_namespaceObject.useRef)(0);
119
+ const onChangeRef = (0, external_react_namespaceObject.useRef)(onChange);
120
+ (0, external_react_namespaceObject.useEffect)(()=>{
121
+ onChangeRef.current = onChange;
122
+ }, [
123
+ onChange
124
+ ]);
125
+ (0, external_react_namespaceObject.useEffect)(()=>{
126
+ const prevOptions = prevOptionsRef.current;
127
+ prevOptionsRef.current = options;
128
+ const renames = detectRenamesByType(prevOptions, options);
129
+ if (0 === renames.length) return;
130
+ const sortedRenames = [
131
+ ...renames
132
+ ].sort((a, b)=>b.oldPath.length - a.oldPath.length);
133
+ const renameSequence = ++renameSequenceRef.current;
134
+ let cancelled = false;
135
+ queueMicrotask(()=>{
136
+ if (cancelled || renameSequenceRef.current !== renameSequence) return;
137
+ let updatedTokens = null;
138
+ editor.update(()=>{
139
+ let tokensChanged = false;
140
+ const tokenNodes = (0, token_nodes_cjs_namespaceObject.getAllPromptTokenNodes)();
141
+ const renamesByType = new Map();
142
+ for (const rename of sortedRenames){
143
+ const list = renamesByType.get(rename.type);
144
+ if (list) list.push(rename);
145
+ else renamesByType.set(rename.type, [
146
+ rename
147
+ ]);
148
+ }
149
+ for (const node of tokenNodes){
150
+ const nodeType = (0, index_cjs_namespaceObject.isInputTokenNode)(node) ? 'input' : (0, index_cjs_namespaceObject.isOutputTokenNode)(node) ? 'output' : (0, index_cjs_namespaceObject.isStateTokenNode)(node) ? 'state' : (0, index_cjs_namespaceObject.isResourceTokenNode)(node) ? 'resource' : null;
151
+ if (!nodeType) continue;
152
+ const matchingRenames = renamesByType.get(nodeType);
153
+ if (!matchingRenames) continue;
154
+ const currentValue = node.getValue();
155
+ let nextValue = currentValue;
156
+ for (const rename of matchingRenames)nextValue = applyPathRename(nextValue, rename.oldPath, rename.newPath);
157
+ if (nextValue !== currentValue) {
158
+ node.setValue(nextValue);
159
+ tokensChanged = true;
160
+ }
161
+ }
162
+ if (tokensChanged) updatedTokens = (0, external_utils_index_cjs_namespaceObject.$getEditorTokensInternal)();
163
+ }, {
164
+ discrete: true,
165
+ onUpdate: ()=>{
166
+ if (cancelled || renameSequenceRef.current !== renameSequence) return;
167
+ if (updatedTokens) onChangeRef.current?.(updatedTokens);
168
+ }
169
+ });
170
+ });
171
+ return ()=>{
172
+ cancelled = true;
173
+ };
174
+ }, [
175
+ editor,
176
+ options
177
+ ]);
178
+ return null;
179
+ };
180
+ exports.RenameTokensPlugin = __webpack_exports__.RenameTokensPlugin;
181
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
182
+ "RenameTokensPlugin"
183
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
184
+ Object.defineProperty(exports, '__esModule', {
185
+ value: true
186
+ });
@@ -0,0 +1,7 @@
1
+ import type { PromptEditorAutoCompleteOption, PromptEditorToken } from '../types';
2
+ interface RenameTokensPluginProps {
3
+ options: PromptEditorAutoCompleteOption[];
4
+ onChange?: (tokens: PromptEditorToken[]) => void;
5
+ }
6
+ export declare const RenameTokensPlugin: ({ options, onChange }: RenameTokensPluginProps) => null;
7
+ export {};
@@ -0,0 +1,152 @@
1
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
+ import { useEffect, useRef } from "react";
3
+ import { isInputTokenNode, isOutputTokenNode, isResourceTokenNode, isStateTokenNode } from "../nodes/index.js";
4
+ import { $getEditorTokensInternal } from "../utils/index.js";
5
+ import { getAllPromptTokenNodes } from "./shared/token-nodes.js";
6
+ const TOKEN_TYPES = [
7
+ 'input',
8
+ 'state',
9
+ 'output',
10
+ 'resource'
11
+ ];
12
+ const createTreeNode = ()=>({
13
+ children: new Map()
14
+ });
15
+ const buildPathTree = (paths)=>{
16
+ const root = createTreeNode();
17
+ for (const path of paths){
18
+ if (!path) continue;
19
+ const segments = path.split('.').filter(Boolean);
20
+ if (0 === segments.length) continue;
21
+ let current = root;
22
+ for (const segment of segments){
23
+ const next = current.children.get(segment) ?? createTreeNode();
24
+ if (!current.children.has(segment)) current.children.set(segment, next);
25
+ current = next;
26
+ }
27
+ }
28
+ return root;
29
+ };
30
+ const joinPath = (prefix, key)=>prefix ? `${prefix}.${key}` : key;
31
+ const detectPathRenames = (prevNode, nextNode, prevPrefix, nextPrefix, renames)=>{
32
+ const prevKeys = [
33
+ ...prevNode.children.keys()
34
+ ];
35
+ const nextKeys = [
36
+ ...nextNode.children.keys()
37
+ ];
38
+ const removedKeys = prevKeys.filter((k)=>!nextNode.children.has(k));
39
+ const addedKeys = nextKeys.filter((k)=>!prevNode.children.has(k));
40
+ const commonKeys = prevKeys.filter((k)=>nextNode.children.has(k));
41
+ if (1 === removedKeys.length && 1 === addedKeys.length) {
42
+ const oldPath = joinPath(prevPrefix, removedKeys[0]);
43
+ const newPath = joinPath(nextPrefix, addedKeys[0]);
44
+ renames.push({
45
+ oldPath,
46
+ newPath
47
+ });
48
+ const prevChild = prevNode.children.get(removedKeys[0]);
49
+ const nextChild = nextNode.children.get(addedKeys[0]);
50
+ if (prevChild && nextChild) detectPathRenames(prevChild, nextChild, oldPath, newPath, renames);
51
+ }
52
+ for (const key of commonKeys){
53
+ const prevChild = prevNode.children.get(key);
54
+ const nextChild = nextNode.children.get(key);
55
+ if (prevChild && nextChild) detectPathRenames(prevChild, nextChild, joinPath(prevPrefix, key), joinPath(nextPrefix, key), renames);
56
+ }
57
+ };
58
+ const groupOptionsByType = (options)=>{
59
+ const grouped = {
60
+ input: new Set(),
61
+ state: new Set(),
62
+ output: new Set(),
63
+ resource: new Set()
64
+ };
65
+ for (const opt of options)grouped[opt.type].add(opt.value);
66
+ return grouped;
67
+ };
68
+ const detectRenamesByType = (prevOptions, currOptions)=>{
69
+ const prevGrouped = groupOptionsByType(prevOptions);
70
+ const currGrouped = groupOptionsByType(currOptions);
71
+ const renames = [];
72
+ for (const type of TOKEN_TYPES){
73
+ const typeRenames = [];
74
+ detectPathRenames(buildPathTree(prevGrouped[type]), buildPathTree(currGrouped[type]), '', '', typeRenames);
75
+ for (const rename of typeRenames)renames.push({
76
+ ...rename,
77
+ type
78
+ });
79
+ }
80
+ return renames;
81
+ };
82
+ const applyPathRename = (value, oldPath, newPath)=>{
83
+ if (value === oldPath) return newPath;
84
+ if (value.startsWith(`${oldPath}.`)) return `${newPath}${value.slice(oldPath.length)}`;
85
+ return value;
86
+ };
87
+ const RenameTokensPlugin = ({ options, onChange })=>{
88
+ const [editor] = useLexicalComposerContext();
89
+ const prevOptionsRef = useRef(options);
90
+ const renameSequenceRef = useRef(0);
91
+ const onChangeRef = useRef(onChange);
92
+ useEffect(()=>{
93
+ onChangeRef.current = onChange;
94
+ }, [
95
+ onChange
96
+ ]);
97
+ useEffect(()=>{
98
+ const prevOptions = prevOptionsRef.current;
99
+ prevOptionsRef.current = options;
100
+ const renames = detectRenamesByType(prevOptions, options);
101
+ if (0 === renames.length) return;
102
+ const sortedRenames = [
103
+ ...renames
104
+ ].sort((a, b)=>b.oldPath.length - a.oldPath.length);
105
+ const renameSequence = ++renameSequenceRef.current;
106
+ let cancelled = false;
107
+ queueMicrotask(()=>{
108
+ if (cancelled || renameSequenceRef.current !== renameSequence) return;
109
+ let updatedTokens = null;
110
+ editor.update(()=>{
111
+ let tokensChanged = false;
112
+ const tokenNodes = getAllPromptTokenNodes();
113
+ const renamesByType = new Map();
114
+ for (const rename of sortedRenames){
115
+ const list = renamesByType.get(rename.type);
116
+ if (list) list.push(rename);
117
+ else renamesByType.set(rename.type, [
118
+ rename
119
+ ]);
120
+ }
121
+ for (const node of tokenNodes){
122
+ const nodeType = isInputTokenNode(node) ? 'input' : isOutputTokenNode(node) ? 'output' : isStateTokenNode(node) ? 'state' : isResourceTokenNode(node) ? 'resource' : null;
123
+ if (!nodeType) continue;
124
+ const matchingRenames = renamesByType.get(nodeType);
125
+ if (!matchingRenames) continue;
126
+ const currentValue = node.getValue();
127
+ let nextValue = currentValue;
128
+ for (const rename of matchingRenames)nextValue = applyPathRename(nextValue, rename.oldPath, rename.newPath);
129
+ if (nextValue !== currentValue) {
130
+ node.setValue(nextValue);
131
+ tokensChanged = true;
132
+ }
133
+ }
134
+ if (tokensChanged) updatedTokens = $getEditorTokensInternal();
135
+ }, {
136
+ discrete: true,
137
+ onUpdate: ()=>{
138
+ if (cancelled || renameSequenceRef.current !== renameSequence) return;
139
+ if (updatedTokens) onChangeRef.current?.(updatedTokens);
140
+ }
141
+ });
142
+ });
143
+ return ()=>{
144
+ cancelled = true;
145
+ };
146
+ }, [
147
+ editor,
148
+ options
149
+ ]);
150
+ return null;
151
+ };
152
+ export { RenameTokensPlugin };
@@ -0,0 +1,132 @@
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
+ ToolbarActionsPlugin: ()=>ToolbarActionsPlugin
28
+ });
29
+ const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
30
+ const external_lexical_namespaceObject = require("lexical");
31
+ const external_react_namespaceObject = require("react");
32
+ const wrapSelectionWithMarkers = (startMarker, endMarker)=>{
33
+ const selection = (0, external_lexical_namespaceObject.$getSelection)();
34
+ if (!(0, external_lexical_namespaceObject.$isRangeSelection)(selection)) return;
35
+ if (selection.isCollapsed()) {
36
+ const markerNode = (0, external_lexical_namespaceObject.$createTextNode)(`${startMarker}${endMarker}`);
37
+ selection.insertNodes([
38
+ markerNode
39
+ ]);
40
+ const offset = startMarker.length;
41
+ selection.setTextNodeRange(markerNode, offset, markerNode, offset);
42
+ return;
43
+ }
44
+ const isBackward = selection.isBackward();
45
+ const startPoint = isBackward ? selection.focus : selection.anchor;
46
+ const endPoint = isBackward ? selection.anchor : selection.focus;
47
+ const startNode = startPoint.getNode();
48
+ const startOffset = startPoint.offset;
49
+ const endNode = endPoint.getNode();
50
+ const endOffset = endPoint.offset;
51
+ if ((0, external_lexical_namespaceObject.$isTextNode)(endNode)) {
52
+ const text = endNode.getTextContent();
53
+ endNode.setTextContent(text.slice(0, endOffset) + endMarker + text.slice(endOffset));
54
+ } else {
55
+ const endText = (0, external_lexical_namespaceObject.$createTextNode)(endMarker);
56
+ endNode.insertAfter(endText);
57
+ }
58
+ if ((0, external_lexical_namespaceObject.$isTextNode)(startNode)) {
59
+ const text = startNode.getTextContent();
60
+ startNode.setTextContent(text.slice(0, startOffset) + startMarker + text.slice(startOffset));
61
+ } else {
62
+ const startText = (0, external_lexical_namespaceObject.$createTextNode)(startMarker);
63
+ startNode.insertBefore(startText);
64
+ }
65
+ };
66
+ const insertLinePrefixForSelection = (getPrefix)=>{
67
+ const selection = (0, external_lexical_namespaceObject.$getSelection)();
68
+ if (!(0, external_lexical_namespaceObject.$isRangeSelection)(selection)) return;
69
+ const anchorNode = selection.anchor.getNode();
70
+ const focusNode = selection.focus.getNode();
71
+ const anchorParent = (0, external_lexical_namespaceObject.$isTextNode)(anchorNode) || !(0, external_lexical_namespaceObject.$isParagraphNode)(anchorNode) ? anchorNode.getParent() : anchorNode;
72
+ const focusParent = (0, external_lexical_namespaceObject.$isTextNode)(focusNode) || !(0, external_lexical_namespaceObject.$isParagraphNode)(focusNode) ? focusNode.getParent() : focusNode;
73
+ if (!anchorParent || !focusParent) return;
74
+ const root = (0, external_lexical_namespaceObject.$getRoot)();
75
+ const allParagraphs = root.getChildren().filter(external_lexical_namespaceObject.$isParagraphNode);
76
+ const anchorIndex = allParagraphs.findIndex((p)=>p.is(anchorParent));
77
+ const focusIndex = allParagraphs.findIndex((p)=>p.is(focusParent));
78
+ if (-1 === anchorIndex || -1 === focusIndex) return;
79
+ const startIndex = Math.min(anchorIndex, focusIndex);
80
+ const endIndex = Math.max(anchorIndex, focusIndex);
81
+ let lineCounter = 0;
82
+ for(let i = startIndex; i <= endIndex; i++){
83
+ const paragraph = allParagraphs[i];
84
+ const firstChild = paragraph.getFirstChild();
85
+ const prefix = getPrefix(lineCounter);
86
+ lineCounter++;
87
+ if ((0, external_lexical_namespaceObject.$isTextNode)(firstChild)) {
88
+ const text = firstChild.getTextContent();
89
+ if (text.startsWith(prefix)) firstChild.setTextContent(text.slice(prefix.length));
90
+ else firstChild.setTextContent(prefix + text);
91
+ } else if (firstChild) {
92
+ const prefixNode = (0, external_lexical_namespaceObject.$createTextNode)(prefix);
93
+ firstChild.insertBefore(prefixNode);
94
+ } else paragraph.append((0, external_lexical_namespaceObject.$createTextNode)(prefix));
95
+ }
96
+ };
97
+ const ToolbarActionsPlugin = ({ actionsRef })=>{
98
+ const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
99
+ (0, external_react_namespaceObject.useEffect)(()=>{
100
+ actionsRef.current = {
101
+ formatBold: ()=>{
102
+ editor.update(()=>wrapSelectionWithMarkers('**', '**'));
103
+ },
104
+ formatItalic: ()=>{
105
+ editor.update(()=>wrapSelectionWithMarkers('*', '*'));
106
+ },
107
+ formatStrikethrough: ()=>{
108
+ editor.update(()=>wrapSelectionWithMarkers('~~', '~~'));
109
+ },
110
+ formatNumberedList: ()=>{
111
+ editor.update(()=>insertLinePrefixForSelection((i)=>`${i + 1}. `));
112
+ },
113
+ formatBulletedList: ()=>{
114
+ editor.update(()=>insertLinePrefixForSelection(()=>'- '));
115
+ }
116
+ };
117
+ return ()=>{
118
+ actionsRef.current = null;
119
+ };
120
+ }, [
121
+ editor,
122
+ actionsRef
123
+ ]);
124
+ return null;
125
+ };
126
+ exports.ToolbarActionsPlugin = __webpack_exports__.ToolbarActionsPlugin;
127
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
128
+ "ToolbarActionsPlugin"
129
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
130
+ Object.defineProperty(exports, '__esModule', {
131
+ value: true
132
+ });
@@ -0,0 +1,7 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import type { PromptEditorToolbarActionsRef } from '../types';
3
+ interface ToolbarActionsPluginProps {
4
+ actionsRef: MutableRefObject<PromptEditorToolbarActionsRef | null>;
5
+ }
6
+ export declare const ToolbarActionsPlugin: ({ actionsRef }: ToolbarActionsPluginProps) => null;
7
+ export {};
@@ -0,0 +1,98 @@
1
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
+ import { $createTextNode, $getRoot, $getSelection, $isParagraphNode, $isRangeSelection, $isTextNode } from "lexical";
3
+ import { useEffect } from "react";
4
+ const wrapSelectionWithMarkers = (startMarker, endMarker)=>{
5
+ const selection = $getSelection();
6
+ if (!$isRangeSelection(selection)) return;
7
+ if (selection.isCollapsed()) {
8
+ const markerNode = $createTextNode(`${startMarker}${endMarker}`);
9
+ selection.insertNodes([
10
+ markerNode
11
+ ]);
12
+ const offset = startMarker.length;
13
+ selection.setTextNodeRange(markerNode, offset, markerNode, offset);
14
+ return;
15
+ }
16
+ const isBackward = selection.isBackward();
17
+ const startPoint = isBackward ? selection.focus : selection.anchor;
18
+ const endPoint = isBackward ? selection.anchor : selection.focus;
19
+ const startNode = startPoint.getNode();
20
+ const startOffset = startPoint.offset;
21
+ const endNode = endPoint.getNode();
22
+ const endOffset = endPoint.offset;
23
+ if ($isTextNode(endNode)) {
24
+ const text = endNode.getTextContent();
25
+ endNode.setTextContent(text.slice(0, endOffset) + endMarker + text.slice(endOffset));
26
+ } else {
27
+ const endText = $createTextNode(endMarker);
28
+ endNode.insertAfter(endText);
29
+ }
30
+ if ($isTextNode(startNode)) {
31
+ const text = startNode.getTextContent();
32
+ startNode.setTextContent(text.slice(0, startOffset) + startMarker + text.slice(startOffset));
33
+ } else {
34
+ const startText = $createTextNode(startMarker);
35
+ startNode.insertBefore(startText);
36
+ }
37
+ };
38
+ const insertLinePrefixForSelection = (getPrefix)=>{
39
+ const selection = $getSelection();
40
+ if (!$isRangeSelection(selection)) return;
41
+ const anchorNode = selection.anchor.getNode();
42
+ const focusNode = selection.focus.getNode();
43
+ const anchorParent = $isTextNode(anchorNode) || !$isParagraphNode(anchorNode) ? anchorNode.getParent() : anchorNode;
44
+ const focusParent = $isTextNode(focusNode) || !$isParagraphNode(focusNode) ? focusNode.getParent() : focusNode;
45
+ if (!anchorParent || !focusParent) return;
46
+ const root = $getRoot();
47
+ const allParagraphs = root.getChildren().filter($isParagraphNode);
48
+ const anchorIndex = allParagraphs.findIndex((p)=>p.is(anchorParent));
49
+ const focusIndex = allParagraphs.findIndex((p)=>p.is(focusParent));
50
+ if (-1 === anchorIndex || -1 === focusIndex) return;
51
+ const startIndex = Math.min(anchorIndex, focusIndex);
52
+ const endIndex = Math.max(anchorIndex, focusIndex);
53
+ let lineCounter = 0;
54
+ for(let i = startIndex; i <= endIndex; i++){
55
+ const paragraph = allParagraphs[i];
56
+ const firstChild = paragraph.getFirstChild();
57
+ const prefix = getPrefix(lineCounter);
58
+ lineCounter++;
59
+ if ($isTextNode(firstChild)) {
60
+ const text = firstChild.getTextContent();
61
+ if (text.startsWith(prefix)) firstChild.setTextContent(text.slice(prefix.length));
62
+ else firstChild.setTextContent(prefix + text);
63
+ } else if (firstChild) {
64
+ const prefixNode = $createTextNode(prefix);
65
+ firstChild.insertBefore(prefixNode);
66
+ } else paragraph.append($createTextNode(prefix));
67
+ }
68
+ };
69
+ const ToolbarActionsPlugin = ({ actionsRef })=>{
70
+ const [editor] = useLexicalComposerContext();
71
+ useEffect(()=>{
72
+ actionsRef.current = {
73
+ formatBold: ()=>{
74
+ editor.update(()=>wrapSelectionWithMarkers('**', '**'));
75
+ },
76
+ formatItalic: ()=>{
77
+ editor.update(()=>wrapSelectionWithMarkers('*', '*'));
78
+ },
79
+ formatStrikethrough: ()=>{
80
+ editor.update(()=>wrapSelectionWithMarkers('~~', '~~'));
81
+ },
82
+ formatNumberedList: ()=>{
83
+ editor.update(()=>insertLinePrefixForSelection((i)=>`${i + 1}. `));
84
+ },
85
+ formatBulletedList: ()=>{
86
+ editor.update(()=>insertLinePrefixForSelection(()=>'- '));
87
+ }
88
+ };
89
+ return ()=>{
90
+ actionsRef.current = null;
91
+ };
92
+ }, [
93
+ editor,
94
+ actionsRef
95
+ ]);
96
+ return null;
97
+ };
98
+ export { ToolbarActionsPlugin };
@@ -0,0 +1,85 @@
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
+ ValidateTokensPlugin: ()=>ValidateTokensPlugin
28
+ });
29
+ const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
30
+ const external_react_namespaceObject = require("react");
31
+ 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
+ const ValidateTokensPlugin = ({ options })=>{
39
+ const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
40
+ (0, external_react_namespaceObject.useEffect)(()=>{
41
+ const validValues = new Map();
42
+ for (const opt of options){
43
+ if (!validValues.has(opt.type)) validValues.set(opt.type, new Set());
44
+ validValues.get(opt.type).add(opt.value);
45
+ }
46
+ const checkIsInvalid = (node)=>{
47
+ const tokenType = NODE_TYPE_TO_TOKEN_TYPE[node.getType()];
48
+ if (!tokenType) return false;
49
+ const validSet = validValues.get(tokenType);
50
+ return !validSet || !validSet.has(node.getValue());
51
+ };
52
+ const validateAllNodes = ()=>{
53
+ const tokenNodes = (0, token_nodes_cjs_namespaceObject.getAllPromptTokenNodes)();
54
+ for (const node of tokenNodes){
55
+ const isInvalid = checkIsInvalid(node);
56
+ if (node.getIsInvalid() !== isInvalid) node.setIsInvalid(isInvalid);
57
+ }
58
+ };
59
+ editor.update(validateAllNodes);
60
+ const unregister = editor.registerUpdateListener(({ editorState, prevEditorState })=>{
61
+ if (editorState === prevEditorState) return;
62
+ editorState.read(()=>{
63
+ const tokenNodes = (0, token_nodes_cjs_namespaceObject.getAllPromptTokenNodes)();
64
+ let needsUpdate = false;
65
+ for (const node of tokenNodes)if (node.getIsInvalid() !== checkIsInvalid(node)) {
66
+ needsUpdate = true;
67
+ break;
68
+ }
69
+ if (needsUpdate) editor.update(validateAllNodes);
70
+ });
71
+ });
72
+ return unregister;
73
+ }, [
74
+ editor,
75
+ options
76
+ ]);
77
+ return null;
78
+ };
79
+ exports.ValidateTokensPlugin = __webpack_exports__.ValidateTokensPlugin;
80
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
81
+ "ValidateTokensPlugin"
82
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
83
+ Object.defineProperty(exports, '__esModule', {
84
+ value: true
85
+ });
@@ -0,0 +1,4 @@
1
+ import type { PromptEditorAutoCompleteOption } from '../types';
2
+ export declare const ValidateTokensPlugin: ({ options, }: {
3
+ options: PromptEditorAutoCompleteOption[];
4
+ }) => null;