@uipath/apollo-wind 2.60.1 → 2.61.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/forms/field-actions.cjs +181 -0
- package/dist/components/forms/field-actions.d.ts +131 -0
- package/dist/components/forms/field-actions.js +129 -0
- package/dist/components/forms/field-control.cjs +415 -0
- package/dist/components/forms/field-control.d.ts +52 -0
- package/dist/components/forms/field-control.js +372 -0
- package/dist/components/forms/field-renderer.cjs +77 -420
- package/dist/components/forms/field-renderer.d.ts +2 -3
- package/dist/components/forms/field-renderer.js +78 -421
- package/dist/components/forms/form-designer.cjs +7 -1
- package/dist/components/forms/form-designer.js +7 -1
- package/dist/components/forms/form-schema.d.ts +121 -2
- package/dist/components/forms/form-strings.cjs +67 -0
- package/dist/components/forms/form-strings.d.ts +30 -0
- package/dist/components/forms/form-strings.js +30 -0
- package/dist/components/forms/index.cjs +53 -9
- package/dist/components/forms/index.d.ts +6 -1
- package/dist/components/forms/index.js +6 -1
- package/dist/components/forms/literal-value-context.cjs +37 -0
- package/dist/components/forms/literal-value-context.d.ts +5 -0
- package/dist/components/forms/literal-value-context.js +3 -0
- package/dist/components/forms/metadata-form.cjs +100 -21
- package/dist/components/forms/metadata-form.d.ts +5 -0
- package/dist/components/forms/metadata-form.js +101 -22
- package/dist/components/forms/mode-aware-field.cjs +589 -0
- package/dist/components/forms/mode-aware-field.d.ts +15 -0
- package/dist/components/forms/mode-aware-field.js +555 -0
- package/dist/components/forms/opaque-value.cjs +44 -0
- package/dist/components/forms/opaque-value.d.ts +7 -0
- package/dist/components/forms/opaque-value.js +7 -0
- package/dist/components/forms/rules-engine.cjs +13 -0
- package/dist/components/forms/rules-engine.js +13 -0
- package/dist/components/forms/schema-serializer.cjs +8 -0
- package/dist/components/forms/schema-serializer.js +8 -0
- package/dist/components/forms/string-list-field.cjs +36 -18
- package/dist/components/forms/string-list-field.d.ts +6 -0
- package/dist/components/forms/string-list-field.js +35 -20
- package/dist/components/forms/validation-converter.cjs +32 -2
- package/dist/components/forms/validation-converter.d.ts +17 -1
- package/dist/components/forms/validation-converter.js +30 -3
- package/dist/components/forms/value-modes.cjs +253 -0
- package/dist/components/forms/value-modes.d.ts +236 -0
- package/dist/components/forms/value-modes.js +180 -0
- package/dist/components/ui/avatar.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/boolean-radio-group.cjs +114 -0
- package/dist/components/ui/boolean-radio-group.d.ts +24 -0
- package/dist/components/ui/boolean-radio-group.js +77 -0
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/command.d.ts +7 -7
- package/dist/components/ui/field-addons/field-menu.cjs +1 -0
- package/dist/components/ui/field-addons/field-menu.d.ts +2 -0
- package/dist/components/ui/field-addons/field-menu.js +1 -0
- package/dist/components/ui/field-addons/index.cjs +4 -0
- package/dist/components/ui/field-addons/index.d.ts +1 -0
- package/dist/components/ui/field-addons/index.js +2 -1
- package/dist/components/ui/field-addons/value-mode-strings.cjs +7 -1
- package/dist/components/ui/field-addons/value-mode-strings.d.ts +9 -0
- package/dist/components/ui/field-addons/value-mode-strings.js +7 -1
- package/dist/components/ui/field-addons/value-mode-switch-dialog.cjs +73 -0
- package/dist/components/ui/field-addons/value-mode-switch-dialog.d.ts +16 -0
- package/dist/components/ui/field-addons/value-mode-switch-dialog.js +39 -0
- package/dist/components/ui/form-field.cjs +2 -1
- package/dist/components/ui/form-field.d.ts +2 -0
- package/dist/components/ui/form-field.js +2 -1
- package/dist/components/ui/index.cjs +230 -186
- package/dist/components/ui/index.d.ts +4 -0
- package/dist/components/ui/index.js +4 -0
- package/dist/components/ui/input-group.cjs +6 -3
- package/dist/components/ui/input-group.d.ts +6 -5
- package/dist/components/ui/input-group.js +6 -3
- package/dist/components/ui/json-tree-view/DecorationChip.cjs +81 -0
- package/dist/components/ui/json-tree-view/DecorationChip.d.ts +4 -0
- package/dist/components/ui/json-tree-view/DecorationChip.js +47 -0
- package/dist/components/ui/json-tree-view/EditorChrome.cjs +88 -0
- package/dist/components/ui/json-tree-view/EditorChrome.d.ts +21 -0
- package/dist/components/ui/json-tree-view/EditorChrome.js +51 -0
- package/dist/components/ui/json-tree-view/JsonContainerEditor.cjs +95 -0
- package/dist/components/ui/json-tree-view/JsonContainerEditor.d.ts +18 -0
- package/dist/components/ui/json-tree-view/JsonContainerEditor.js +61 -0
- package/dist/components/ui/json-tree-view/JsonLeafValueEditor.cjs +86 -0
- package/dist/components/ui/json-tree-view/JsonLeafValueEditor.d.ts +12 -0
- package/dist/components/ui/json-tree-view/JsonLeafValueEditor.js +52 -0
- package/dist/components/ui/json-tree-view/JsonMultilineLeafEditor.cjs +74 -0
- package/dist/components/ui/json-tree-view/JsonMultilineLeafEditor.d.ts +13 -0
- package/dist/components/ui/json-tree-view/JsonMultilineLeafEditor.js +40 -0
- package/dist/components/ui/json-tree-view/JsonTree.cjs +253 -0
- package/dist/components/ui/json-tree-view/JsonTree.d.ts +81 -0
- package/dist/components/ui/json-tree-view/JsonTree.js +219 -0
- package/dist/components/ui/json-tree-view/JsonTree.types.cjs +18 -0
- package/dist/components/ui/json-tree-view/JsonTree.types.d.ts +253 -0
- package/dist/components/ui/json-tree-view/JsonTree.types.js +0 -0
- package/dist/components/ui/json-tree-view/JsonTreeRow.cjs +284 -0
- package/dist/components/ui/json-tree-view/JsonTreeRow.d.ts +50 -0
- package/dist/components/ui/json-tree-view/JsonTreeRow.js +244 -0
- package/dist/components/ui/json-tree-view/JsonTreeToolbar.cjs +209 -0
- package/dist/components/ui/json-tree-view/JsonTreeToolbar.d.ts +35 -0
- package/dist/components/ui/json-tree-view/JsonTreeToolbar.js +175 -0
- package/dist/components/ui/json-tree-view/JsonTreeTooltip.cjs +84 -0
- package/dist/components/ui/json-tree-view/JsonTreeTooltip.d.ts +21 -0
- package/dist/components/ui/json-tree-view/JsonTreeTooltip.js +47 -0
- package/dist/components/ui/json-tree-view/JsonTypeBadge.cjs +70 -0
- package/dist/components/ui/json-tree-view/JsonTypeBadge.d.ts +17 -0
- package/dist/components/ui/json-tree-view/JsonTypeBadge.js +36 -0
- package/dist/components/ui/json-tree-view/NodeKey.cjs +77 -0
- package/dist/components/ui/json-tree-view/NodeKey.d.ts +16 -0
- package/dist/components/ui/json-tree-view/NodeKey.js +43 -0
- package/dist/components/ui/json-tree-view/RowActions.cjs +120 -0
- package/dist/components/ui/json-tree-view/RowActions.d.ts +15 -0
- package/dist/components/ui/json-tree-view/RowActions.js +86 -0
- package/dist/components/ui/json-tree-view/ScalarValueCell.cjs +112 -0
- package/dist/components/ui/json-tree-view/ScalarValueCell.d.ts +18 -0
- package/dist/components/ui/json-tree-view/ScalarValueCell.js +75 -0
- package/dist/components/ui/json-tree-view/buildJsonTree.cjs +324 -0
- package/dist/components/ui/json-tree-view/buildJsonTree.d.ts +75 -0
- package/dist/components/ui/json-tree-view/buildJsonTree.js +257 -0
- package/dist/components/ui/json-tree-view/clipboard.cjs +63 -0
- package/dist/components/ui/json-tree-view/clipboard.d.ts +6 -0
- package/dist/components/ui/json-tree-view/clipboard.js +29 -0
- package/dist/components/ui/json-tree-view/index.cjs +175 -0
- package/dist/components/ui/json-tree-view/index.d.ts +10 -0
- package/dist/components/ui/json-tree-view/index.js +11 -0
- package/dist/components/ui/json-tree-view/leafEditTypes.cjs +74 -0
- package/dist/components/ui/json-tree-view/leafEditTypes.d.ts +12 -0
- package/dist/components/ui/json-tree-view/leafEditTypes.js +34 -0
- package/dist/components/ui/json-tree-view/strings.cjs +122 -0
- package/dist/components/ui/json-tree-view/strings.d.ts +65 -0
- package/dist/components/ui/json-tree-view/strings.js +79 -0
- package/dist/components/ui/prompt-value-control.cjs +70 -0
- package/dist/components/ui/prompt-value-control.d.ts +28 -0
- package/dist/components/ui/prompt-value-control.js +36 -0
- package/dist/components/ui/sheet.d.ts +1 -1
- package/dist/components/ui/spinner.d.ts +1 -1
- package/dist/components/ui/switch.d.ts +2 -2
- package/dist/components/ui/textarea.cjs +1 -1
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/toggle-group.d.ts +2 -2
- package/dist/components/ui/toggle.d.ts +2 -2
- package/dist/components/ui/variable-value-control.cjs +98 -0
- package/dist/components/ui/variable-value-control.d.ts +35 -0
- package/dist/components/ui/variable-value-control.js +64 -0
- package/dist/index.cjs +145 -16
- package/dist/index.d.ts +21 -3
- package/dist/index.js +11 -2
- package/dist/lib/index.cjs +4 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/utils.cjs +21 -1
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.js +18 -1
- package/dist/styles.css +225 -0
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
createClearAction: ()=>createClearAction,
|
|
28
|
+
resolveVariables: ()=>resolveVariables,
|
|
29
|
+
createInsertVariableAction: ()=>createInsertVariableAction,
|
|
30
|
+
resolveFieldActions: ()=>resolveFieldActions,
|
|
31
|
+
DEFAULT_FIELD_ACTION_REGISTRY: ()=>DEFAULT_FIELD_ACTION_REGISTRY,
|
|
32
|
+
buildFieldActionRegistry: ()=>buildFieldActionRegistry,
|
|
33
|
+
createAiAssistAction: ()=>createAiAssistAction
|
|
34
|
+
});
|
|
35
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
36
|
+
const external_lucide_react_namespaceObject = require("lucide-react");
|
|
37
|
+
const ai_assist_action_cjs_namespaceObject = require("../ui/field-actions/ai-assist-action.cjs");
|
|
38
|
+
const insert_variable_action_cjs_namespaceObject = require("../ui/field-actions/insert-variable-action.cjs");
|
|
39
|
+
function resolveVariables(source, field) {
|
|
40
|
+
if (!source) return [];
|
|
41
|
+
return 'function' == typeof source ? source({
|
|
42
|
+
field
|
|
43
|
+
}) : source;
|
|
44
|
+
}
|
|
45
|
+
function offers(ctx, mode) {
|
|
46
|
+
return !!ctx.setModeValue && !!ctx.field.valueModes?.modes.includes(mode);
|
|
47
|
+
}
|
|
48
|
+
const REPLACED_WITHOUT_ASKING = new Set([
|
|
49
|
+
'number',
|
|
50
|
+
'boolean',
|
|
51
|
+
'switch',
|
|
52
|
+
'checkbox'
|
|
53
|
+
]);
|
|
54
|
+
function insertTarget(ctx, formatReference, text) {
|
|
55
|
+
if (ctx.disabled) return;
|
|
56
|
+
if (ctx.insertable) {
|
|
57
|
+
const insertText = ctx.control?.insertText;
|
|
58
|
+
if (!insertText) return;
|
|
59
|
+
const mode = ctx.mode?.mode ?? 'literal';
|
|
60
|
+
return (reference)=>insertText(formatReference?.(reference, {
|
|
61
|
+
field: ctx.field,
|
|
62
|
+
mode
|
|
63
|
+
}) ?? reference);
|
|
64
|
+
}
|
|
65
|
+
const confirm = ctx.mode?.mode === 'literal' && REPLACED_WITHOUT_ASKING.has(ctx.field.type) ? void 0 : {
|
|
66
|
+
title: text.replaceTitle,
|
|
67
|
+
description: text.replaceDescription,
|
|
68
|
+
confirmLabel: text.replaceConfirm
|
|
69
|
+
};
|
|
70
|
+
for (const mode of [
|
|
71
|
+
'expression',
|
|
72
|
+
'variable'
|
|
73
|
+
])if (offers(ctx, mode)) return (reference)=>ctx.setModeValue?.(mode, reference, {
|
|
74
|
+
confirm
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function createInsertVariableAction({ variables, formatReference, strings, id = 'insert-variable' }) {
|
|
78
|
+
return {
|
|
79
|
+
id,
|
|
80
|
+
render: (ctx)=>{
|
|
81
|
+
if (ctx.mode?.mode === 'variable') return null;
|
|
82
|
+
const text = {
|
|
83
|
+
...ctx.strings.insertVariable,
|
|
84
|
+
...strings
|
|
85
|
+
};
|
|
86
|
+
const insert = insertTarget(ctx, formatReference, text);
|
|
87
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(insert_variable_action_cjs_namespaceObject.InsertVariableAction, {
|
|
88
|
+
variables: Array.isArray(variables) ? variables : ()=>variables ? resolveVariables(variables, ctx.field) : ctx.variables(),
|
|
89
|
+
onInsert: insert && ((reference)=>insertTarget(ctx, formatReference, text)?.(reference)),
|
|
90
|
+
disabled: ctx.disabled,
|
|
91
|
+
strings: text
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function createAiAssistAction({ generate, hint, placeholder, strings, id = 'ai-assist' }) {
|
|
97
|
+
return {
|
|
98
|
+
id,
|
|
99
|
+
render: (ctx)=>{
|
|
100
|
+
const promptPlaceholder = 'function' == typeof placeholder ? placeholder(ctx) : placeholder;
|
|
101
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ai_assist_action_cjs_namespaceObject.AiAssistAction, {
|
|
102
|
+
onGenerate: async (prompt)=>{
|
|
103
|
+
const result = await generate({
|
|
104
|
+
prompt
|
|
105
|
+
}, ctx);
|
|
106
|
+
if (!result || ctx.disabled) return;
|
|
107
|
+
const mode = result.mode ?? ctx.mode?.mode;
|
|
108
|
+
if (ctx.setModeValue && mode) ctx.setModeValue(mode, result.value);
|
|
109
|
+
else ctx.setValue(result.value);
|
|
110
|
+
},
|
|
111
|
+
hint: 'function' == typeof hint ? hint(ctx) : hint,
|
|
112
|
+
disabled: ctx.disabled,
|
|
113
|
+
strings: {
|
|
114
|
+
...ctx.strings.aiAssist,
|
|
115
|
+
...void 0 !== promptPlaceholder && {
|
|
116
|
+
promptPlaceholder
|
|
117
|
+
},
|
|
118
|
+
...strings
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function createClearAction({ strings, id = 'clear' } = {}) {
|
|
125
|
+
return {
|
|
126
|
+
id,
|
|
127
|
+
label: (ctx)=>strings?.label ?? ctx.strings.clear.label,
|
|
128
|
+
icon: external_lucide_react_namespaceObject.Eraser,
|
|
129
|
+
destructive: true,
|
|
130
|
+
disabled: (ctx)=>ctx.disabled || ctx.empty,
|
|
131
|
+
onSelect: (ctx)=>ctx.clear()
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function buildFieldActionRegistry(plugins) {
|
|
135
|
+
const registry = {
|
|
136
|
+
header: {},
|
|
137
|
+
menu: {
|
|
138
|
+
clear: createClearAction()
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
for (const { fieldActions } of plugins){
|
|
142
|
+
Object.assign(registry.header, fieldActions?.header);
|
|
143
|
+
Object.assign(registry.menu, fieldActions?.menu);
|
|
144
|
+
}
|
|
145
|
+
return registry;
|
|
146
|
+
}
|
|
147
|
+
const DEFAULT_FIELD_ACTION_REGISTRY = (()=>{
|
|
148
|
+
const { header, menu } = buildFieldActionRegistry([]);
|
|
149
|
+
return Object.freeze({
|
|
150
|
+
header: Object.freeze(header),
|
|
151
|
+
menu: Object.freeze(menu)
|
|
152
|
+
});
|
|
153
|
+
})();
|
|
154
|
+
function resolveFieldActions(field, registry) {
|
|
155
|
+
const pick = (ids, actions)=>(ids ?? []).flatMap((id)=>actions[id] ? [
|
|
156
|
+
actions[id]
|
|
157
|
+
] : []);
|
|
158
|
+
return {
|
|
159
|
+
header: pick(field.headerActions, registry.header),
|
|
160
|
+
menu: pick(field.menuActions, registry.menu)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
exports.DEFAULT_FIELD_ACTION_REGISTRY = __webpack_exports__.DEFAULT_FIELD_ACTION_REGISTRY;
|
|
164
|
+
exports.buildFieldActionRegistry = __webpack_exports__.buildFieldActionRegistry;
|
|
165
|
+
exports.createAiAssistAction = __webpack_exports__.createAiAssistAction;
|
|
166
|
+
exports.createClearAction = __webpack_exports__.createClearAction;
|
|
167
|
+
exports.createInsertVariableAction = __webpack_exports__.createInsertVariableAction;
|
|
168
|
+
exports.resolveFieldActions = __webpack_exports__.resolveFieldActions;
|
|
169
|
+
exports.resolveVariables = __webpack_exports__.resolveVariables;
|
|
170
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
171
|
+
"DEFAULT_FIELD_ACTION_REGISTRY",
|
|
172
|
+
"buildFieldActionRegistry",
|
|
173
|
+
"createAiAssistAction",
|
|
174
|
+
"createClearAction",
|
|
175
|
+
"createInsertVariableAction",
|
|
176
|
+
"resolveFieldActions",
|
|
177
|
+
"resolveVariables"
|
|
178
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
179
|
+
Object.defineProperty(exports, '__esModule', {
|
|
180
|
+
value: true
|
|
181
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { type LucideIcon } from 'lucide-react';
|
|
2
|
+
import type * as React from 'react';
|
|
3
|
+
import type { FieldValues, UseFormReturn } from 'react-hook-form';
|
|
4
|
+
import { type AiAssistActionStrings } from '../ui/field-actions/ai-assist-action';
|
|
5
|
+
import { type InsertVariableActionStrings } from '../ui/field-actions/insert-variable-action';
|
|
6
|
+
import type { VariablePickerItem } from '../ui/variable-picker';
|
|
7
|
+
import type { FieldMetadata, FormPlugin, FormVariables, ValueModeId } from './form-schema';
|
|
8
|
+
import type { ClearActionStrings, MetadataFormStrings } from './form-strings';
|
|
9
|
+
import type { DecodedValue, ValueModeControlHandle } from './value-modes';
|
|
10
|
+
/** What an action sees of its field. Read when the action runs, so it is always current. */
|
|
11
|
+
export interface FieldActionContext {
|
|
12
|
+
field: FieldMetadata;
|
|
13
|
+
name: string;
|
|
14
|
+
/** The stored value. */
|
|
15
|
+
value: unknown;
|
|
16
|
+
/** Writes the stored value. Never `undefined`, which the form reads as unset: clear with `null`. */
|
|
17
|
+
setValue(value: unknown): void;
|
|
18
|
+
/** Empties the value, keeping its mode; a field without value modes is set to `null`. */
|
|
19
|
+
clear(): void;
|
|
20
|
+
/** Whether the value is empty, decoded first on a field with `valueModes`. */
|
|
21
|
+
empty: boolean;
|
|
22
|
+
disabled: boolean;
|
|
23
|
+
/** The active value control, for focus and caret insertion. */
|
|
24
|
+
control: ValueModeControlHandle | null;
|
|
25
|
+
/** Whether the active control takes text at its caret. */
|
|
26
|
+
insertable: boolean;
|
|
27
|
+
/** The form's variables for this field, resolved when called; never call it during render. */
|
|
28
|
+
variables(): ValueModeVariable[];
|
|
29
|
+
form: UseFormReturn<FieldValues>;
|
|
30
|
+
/** The form's strings, every plugin's over the English defaults. */
|
|
31
|
+
strings: MetadataFormStrings;
|
|
32
|
+
/** The decoded value. Only on a field with `valueModes`. */
|
|
33
|
+
mode?: DecodedValue;
|
|
34
|
+
/**
|
|
35
|
+
* Writes `inner` in `mode`. With `confirm`, a non-empty value is replaced only once the user
|
|
36
|
+
* confirms, in the lossy-switch dialog worded as `confirm` gives. Only on a field with
|
|
37
|
+
* `valueModes`.
|
|
38
|
+
*/
|
|
39
|
+
setModeValue?(mode: ValueModeId, inner: unknown, options?: {
|
|
40
|
+
confirm?: FieldActionConfirm;
|
|
41
|
+
}): void;
|
|
42
|
+
}
|
|
43
|
+
/** The wording of a confirmation; each part defaults to the lossy-switch dialog's. */
|
|
44
|
+
export interface FieldActionConfirm {
|
|
45
|
+
title?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
confirmLabel?: string;
|
|
48
|
+
}
|
|
49
|
+
/** An action behind the field's label. */
|
|
50
|
+
export interface FieldHeaderAction {
|
|
51
|
+
id: string;
|
|
52
|
+
render(ctx: FieldActionContext): React.ReactNode;
|
|
53
|
+
}
|
|
54
|
+
/** A row of the field's trailing menu, below its modes. */
|
|
55
|
+
export interface FieldMenuAction {
|
|
56
|
+
id: string;
|
|
57
|
+
label: string | ((ctx: FieldActionContext) => string);
|
|
58
|
+
icon?: LucideIcon;
|
|
59
|
+
destructive?: boolean;
|
|
60
|
+
disabled?(ctx: FieldActionContext): boolean;
|
|
61
|
+
onSelect(ctx: FieldActionContext): void;
|
|
62
|
+
}
|
|
63
|
+
/** A variable Insert variable offers, rendered as supplied. */
|
|
64
|
+
export type ValueModeVariable = VariablePickerItem;
|
|
65
|
+
/** `source` for `field`: a function is called now, so only call this when a picker opens. */
|
|
66
|
+
export declare function resolveVariables(source: FormVariables | undefined, field: FieldMetadata): ValueModeVariable[];
|
|
67
|
+
/**
|
|
68
|
+
* Generates a value from a prompt. Resolving with a value writes it, in `mode` or else the mode
|
|
69
|
+
* the field is in when it resolves; resolving with nothing writes nothing.
|
|
70
|
+
*/
|
|
71
|
+
export type FieldActionGenerate = (request: {
|
|
72
|
+
prompt: string;
|
|
73
|
+
}, ctx: FieldActionContext) => Promise<{
|
|
74
|
+
mode?: ValueModeId;
|
|
75
|
+
value: unknown;
|
|
76
|
+
} | undefined | void>;
|
|
77
|
+
export interface FieldActionsPluginConfig {
|
|
78
|
+
/** Header actions by id, in the order fields list them. */
|
|
79
|
+
header?: Record<string, FieldHeaderAction>;
|
|
80
|
+
/** Menu actions by id. `clear` is registered unless a plugin replaces it. */
|
|
81
|
+
menu?: Record<string, FieldMenuAction>;
|
|
82
|
+
}
|
|
83
|
+
/** Every plugin's `fieldActions` over the default `clear`, later plugins winning by id. */
|
|
84
|
+
export interface FieldActionRegistry {
|
|
85
|
+
header: Record<string, FieldHeaderAction>;
|
|
86
|
+
menu: Record<string, FieldMenuAction>;
|
|
87
|
+
}
|
|
88
|
+
export interface InsertVariableActionOptions {
|
|
89
|
+
/** Defaults to the form's `FormPlugin.variables`. */
|
|
90
|
+
variables?: FormVariables;
|
|
91
|
+
/**
|
|
92
|
+
* How a picked reference is written at the caret, such as `{{ ref }}` inside fixed-value text.
|
|
93
|
+
* A field that switches to `expression` or `variable` to take the reference gets it as picked.
|
|
94
|
+
*/
|
|
95
|
+
formatReference?: (reference: string, ctx: {
|
|
96
|
+
field: FieldMetadata;
|
|
97
|
+
mode: ValueModeId;
|
|
98
|
+
}) => string;
|
|
99
|
+
strings?: Partial<InsertVariableActionStrings>;
|
|
100
|
+
/** Defaults to `insert-variable`. */
|
|
101
|
+
id?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Insert variable: a variable picker behind the label that writes the picked reference. */
|
|
104
|
+
export declare function createInsertVariableAction({ variables, formatReference, strings, id, }: InsertVariableActionOptions): FieldHeaderAction;
|
|
105
|
+
export interface AiAssistActionOptions {
|
|
106
|
+
generate: FieldActionGenerate;
|
|
107
|
+
/** Guidance under the prompt, such as the value type expected. */
|
|
108
|
+
hint?: React.ReactNode | ((ctx: FieldActionContext) => React.ReactNode);
|
|
109
|
+
/** The prompt's placeholder, such as an example request for this field. */
|
|
110
|
+
placeholder?: string | ((ctx: FieldActionContext) => string);
|
|
111
|
+
strings?: Partial<AiAssistActionStrings>;
|
|
112
|
+
/** Defaults to `ai-assist`. */
|
|
113
|
+
id?: string;
|
|
114
|
+
}
|
|
115
|
+
/** AI assist: a prompt behind the label whose generated value is written to the field. */
|
|
116
|
+
export declare function createAiAssistAction({ generate, hint, placeholder, strings, id, }: AiAssistActionOptions): FieldHeaderAction;
|
|
117
|
+
export interface ClearActionOptions {
|
|
118
|
+
strings?: Partial<ClearActionStrings>;
|
|
119
|
+
/** Defaults to `clear`. */
|
|
120
|
+
id?: string;
|
|
121
|
+
}
|
|
122
|
+
/** Clear value: a menu row that empties the value, keeping its mode. */
|
|
123
|
+
export declare function createClearAction({ strings, id, }?: ClearActionOptions): FieldMenuAction;
|
|
124
|
+
export declare function buildFieldActionRegistry(plugins: readonly FormPlugin[]): FieldActionRegistry;
|
|
125
|
+
/** The registry of a form whose plugins add no actions: just Clear. Frozen, as it is shared. */
|
|
126
|
+
export declare const DEFAULT_FIELD_ACTION_REGISTRY: Readonly<FieldActionRegistry>;
|
|
127
|
+
/** A field's actions in its order. Unregistered ids are left out. */
|
|
128
|
+
export declare function resolveFieldActions(field: FieldMetadata, registry: FieldActionRegistry): {
|
|
129
|
+
header: FieldHeaderAction[];
|
|
130
|
+
menu: FieldMenuAction[];
|
|
131
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Eraser } from "lucide-react";
|
|
3
|
+
import { AiAssistAction } from "../ui/field-actions/ai-assist-action.js";
|
|
4
|
+
import { InsertVariableAction } from "../ui/field-actions/insert-variable-action.js";
|
|
5
|
+
function resolveVariables(source, field) {
|
|
6
|
+
if (!source) return [];
|
|
7
|
+
return 'function' == typeof source ? source({
|
|
8
|
+
field
|
|
9
|
+
}) : source;
|
|
10
|
+
}
|
|
11
|
+
function offers(ctx, mode) {
|
|
12
|
+
return !!ctx.setModeValue && !!ctx.field.valueModes?.modes.includes(mode);
|
|
13
|
+
}
|
|
14
|
+
const REPLACED_WITHOUT_ASKING = new Set([
|
|
15
|
+
'number',
|
|
16
|
+
'boolean',
|
|
17
|
+
'switch',
|
|
18
|
+
'checkbox'
|
|
19
|
+
]);
|
|
20
|
+
function insertTarget(ctx, formatReference, text) {
|
|
21
|
+
if (ctx.disabled) return;
|
|
22
|
+
if (ctx.insertable) {
|
|
23
|
+
const insertText = ctx.control?.insertText;
|
|
24
|
+
if (!insertText) return;
|
|
25
|
+
const mode = ctx.mode?.mode ?? 'literal';
|
|
26
|
+
return (reference)=>insertText(formatReference?.(reference, {
|
|
27
|
+
field: ctx.field,
|
|
28
|
+
mode
|
|
29
|
+
}) ?? reference);
|
|
30
|
+
}
|
|
31
|
+
const confirm = ctx.mode?.mode === 'literal' && REPLACED_WITHOUT_ASKING.has(ctx.field.type) ? void 0 : {
|
|
32
|
+
title: text.replaceTitle,
|
|
33
|
+
description: text.replaceDescription,
|
|
34
|
+
confirmLabel: text.replaceConfirm
|
|
35
|
+
};
|
|
36
|
+
for (const mode of [
|
|
37
|
+
'expression',
|
|
38
|
+
'variable'
|
|
39
|
+
])if (offers(ctx, mode)) return (reference)=>ctx.setModeValue?.(mode, reference, {
|
|
40
|
+
confirm
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function createInsertVariableAction({ variables, formatReference, strings, id = 'insert-variable' }) {
|
|
44
|
+
return {
|
|
45
|
+
id,
|
|
46
|
+
render: (ctx)=>{
|
|
47
|
+
if (ctx.mode?.mode === 'variable') return null;
|
|
48
|
+
const text = {
|
|
49
|
+
...ctx.strings.insertVariable,
|
|
50
|
+
...strings
|
|
51
|
+
};
|
|
52
|
+
const insert = insertTarget(ctx, formatReference, text);
|
|
53
|
+
return /*#__PURE__*/ jsx(InsertVariableAction, {
|
|
54
|
+
variables: Array.isArray(variables) ? variables : ()=>variables ? resolveVariables(variables, ctx.field) : ctx.variables(),
|
|
55
|
+
onInsert: insert && ((reference)=>insertTarget(ctx, formatReference, text)?.(reference)),
|
|
56
|
+
disabled: ctx.disabled,
|
|
57
|
+
strings: text
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function createAiAssistAction({ generate, hint, placeholder, strings, id = 'ai-assist' }) {
|
|
63
|
+
return {
|
|
64
|
+
id,
|
|
65
|
+
render: (ctx)=>{
|
|
66
|
+
const promptPlaceholder = 'function' == typeof placeholder ? placeholder(ctx) : placeholder;
|
|
67
|
+
return /*#__PURE__*/ jsx(AiAssistAction, {
|
|
68
|
+
onGenerate: async (prompt)=>{
|
|
69
|
+
const result = await generate({
|
|
70
|
+
prompt
|
|
71
|
+
}, ctx);
|
|
72
|
+
if (!result || ctx.disabled) return;
|
|
73
|
+
const mode = result.mode ?? ctx.mode?.mode;
|
|
74
|
+
if (ctx.setModeValue && mode) ctx.setModeValue(mode, result.value);
|
|
75
|
+
else ctx.setValue(result.value);
|
|
76
|
+
},
|
|
77
|
+
hint: 'function' == typeof hint ? hint(ctx) : hint,
|
|
78
|
+
disabled: ctx.disabled,
|
|
79
|
+
strings: {
|
|
80
|
+
...ctx.strings.aiAssist,
|
|
81
|
+
...void 0 !== promptPlaceholder && {
|
|
82
|
+
promptPlaceholder
|
|
83
|
+
},
|
|
84
|
+
...strings
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function createClearAction({ strings, id = 'clear' } = {}) {
|
|
91
|
+
return {
|
|
92
|
+
id,
|
|
93
|
+
label: (ctx)=>strings?.label ?? ctx.strings.clear.label,
|
|
94
|
+
icon: Eraser,
|
|
95
|
+
destructive: true,
|
|
96
|
+
disabled: (ctx)=>ctx.disabled || ctx.empty,
|
|
97
|
+
onSelect: (ctx)=>ctx.clear()
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function buildFieldActionRegistry(plugins) {
|
|
101
|
+
const registry = {
|
|
102
|
+
header: {},
|
|
103
|
+
menu: {
|
|
104
|
+
clear: createClearAction()
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
for (const { fieldActions } of plugins){
|
|
108
|
+
Object.assign(registry.header, fieldActions?.header);
|
|
109
|
+
Object.assign(registry.menu, fieldActions?.menu);
|
|
110
|
+
}
|
|
111
|
+
return registry;
|
|
112
|
+
}
|
|
113
|
+
const DEFAULT_FIELD_ACTION_REGISTRY = (()=>{
|
|
114
|
+
const { header, menu } = buildFieldActionRegistry([]);
|
|
115
|
+
return Object.freeze({
|
|
116
|
+
header: Object.freeze(header),
|
|
117
|
+
menu: Object.freeze(menu)
|
|
118
|
+
});
|
|
119
|
+
})();
|
|
120
|
+
function resolveFieldActions(field, registry) {
|
|
121
|
+
const pick = (ids, actions)=>(ids ?? []).flatMap((id)=>actions[id] ? [
|
|
122
|
+
actions[id]
|
|
123
|
+
] : []);
|
|
124
|
+
return {
|
|
125
|
+
header: pick(field.headerActions, registry.header),
|
|
126
|
+
menu: pick(field.menuActions, registry.menu)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export { DEFAULT_FIELD_ACTION_REGISTRY, buildFieldActionRegistry, createAiAssistAction, createClearAction, createInsertVariableAction, resolveFieldActions, resolveVariables };
|