@dxos/react-ui-form 0.8.1-staging.9eaf14f → 0.8.2-main.10c050d
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/lib/browser/index.mjs +1818 -1309
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1774 -1273
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1818 -1309
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/{ControlSection.d.ts → ControlSection/ControlSection.d.ts} +9 -6
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -0
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +8 -0
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -0
- package/dist/types/src/components/ControlSection/index.d.ts +2 -0
- package/dist/types/src/components/ControlSection/index.d.ts.map +1 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.test.d.ts +2 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +4 -4
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +6 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +38 -36
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +16 -12
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +2 -2
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +12 -0
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +5 -3
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +2 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +2 -2
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +23 -0
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +8 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +5 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +9 -0
- package/dist/types/src/util/refs.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +3 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/src/vitest-setup.d.ts +2 -0
- package/dist/types/src/vitest-setup.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -25
- package/src/components/ControlSection/ControlSection.stories.tsx +29 -0
- package/src/components/{ControlSection.tsx → ControlSection/ControlSection.tsx} +40 -16
- package/src/components/ControlSection/index.ts +5 -0
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.test.tsx +49 -0
- package/src/components/FieldEditor/FieldEditor.tsx +3 -2
- package/src/components/Form/ArrayField.tsx +63 -50
- package/src/components/Form/Defaults.tsx +77 -48
- package/src/components/Form/Form.stories.tsx +134 -109
- package/src/components/Form/Form.tsx +8 -5
- package/src/components/Form/FormActions.tsx +15 -18
- package/src/components/Form/FormContent.tsx +116 -46
- package/src/components/Form/FormContext.tsx +24 -10
- package/src/components/Form/Input.tsx +4 -10
- package/src/components/Form/RefField.tsx +217 -0
- package/src/components/Form/custom/GeoPointInput.tsx +2 -2
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +6 -5
- package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/Form/index.ts +0 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +19 -9
- package/src/components/ViewEditor/ViewEditor.tsx +65 -35
- package/src/components/deprecated/Form.stories.tsx +6 -6
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/components/deprecated/FormInput.tsx +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/testing.tsx +5 -9
- package/src/hooks/index.ts +3 -1
- package/src/hooks/useForm.ts +4 -3
- package/src/hooks/useQueryRefOptions.ts +53 -0
- package/src/hooks/useRefQueryLookupHandler.ts +39 -0
- package/src/translations.ts +9 -2
- package/src/util/formatting.ts +15 -3
- package/src/util/index.ts +3 -1
- package/src/util/refs.ts +38 -0
- package/src/util/schema.ts +14 -0
- package/src/vitest-setup.ts +11 -0
- package/dist/types/src/components/ControlSection.d.ts.map +0 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -32,8 +32,10 @@ __export(node_exports, {
|
|
|
32
32
|
ControlFrame: () => ControlFrame,
|
|
33
33
|
ControlFrameItem: () => ControlFrameItem,
|
|
34
34
|
ControlGroup: () => ControlGroup,
|
|
35
|
+
ControlGroupButton: () => ControlGroupButton,
|
|
35
36
|
ControlItem: () => ControlItem,
|
|
36
37
|
ControlItemInput: () => ControlItemInput,
|
|
38
|
+
ControlPage: () => ControlPage,
|
|
37
39
|
ControlSection: () => ControlSection,
|
|
38
40
|
ControlSectionHeading: () => ControlSectionHeading,
|
|
39
41
|
DeprecatedFormContainer: () => DeprecatedFormContainer,
|
|
@@ -52,51 +54,66 @@ __export(node_exports, {
|
|
|
52
54
|
ViewEditor: () => ViewEditor,
|
|
53
55
|
cellClassesForFieldType: () => cellClassesForFieldType,
|
|
54
56
|
controlItemClasses: () => controlItemClasses,
|
|
57
|
+
findArrayElementType: () => findArrayElementType,
|
|
55
58
|
formatForDisplay: () => formatForDisplay,
|
|
56
59
|
formatForEditing: () => formatForEditing,
|
|
60
|
+
getRefProps: () => getRefProps,
|
|
57
61
|
parseValue: () => parseValue,
|
|
58
62
|
pathNotUniqueError: () => pathNotUniqueError,
|
|
59
63
|
translations: () => translations_default,
|
|
60
64
|
useForm: () => useForm,
|
|
61
65
|
useFormContext: () => useFormContext,
|
|
62
66
|
useFormValues: () => useFormValues,
|
|
63
|
-
useInputProps: () => useInputProps
|
|
67
|
+
useInputProps: () => useInputProps,
|
|
68
|
+
useQueryRefOptions: () => useQueryRefOptions,
|
|
69
|
+
useRefQueryLookupHandler: () => useRefQueryLookupHandler
|
|
64
70
|
});
|
|
65
71
|
module.exports = __toCommonJS(node_exports);
|
|
72
|
+
var import_tracking = require("@preact-signals/safe-react/tracking");
|
|
66
73
|
var import_react = __toESM(require("react"));
|
|
67
74
|
var import_react_ui = require("@dxos/react-ui");
|
|
68
75
|
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
76
|
+
var import_tracking2 = require("@preact-signals/safe-react/tracking");
|
|
69
77
|
var import_react2 = __toESM(require("react"));
|
|
70
78
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
79
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
80
|
+
var import_tracking3 = require("@preact-signals/safe-react/tracking");
|
|
71
81
|
var import_react3 = __toESM(require("react"));
|
|
72
82
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
73
83
|
var import_log = require("@dxos/log");
|
|
74
84
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
75
85
|
var import_schema = require("@dxos/schema");
|
|
86
|
+
var import_tracking4 = require("@preact-signals/safe-react/tracking");
|
|
76
87
|
var import_react4 = __toESM(require("react"));
|
|
77
88
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
78
89
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
79
90
|
var import_util = require("@dxos/util");
|
|
91
|
+
var import_tracking5 = require("@preact-signals/safe-react/tracking");
|
|
80
92
|
var import_react5 = __toESM(require("react"));
|
|
81
93
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
82
|
-
var
|
|
94
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
95
|
+
var import_tracking6 = require("@preact-signals/safe-react/tracking");
|
|
83
96
|
var import_react6 = __toESM(require("react"));
|
|
84
97
|
var import_keys = require("@dxos/keys");
|
|
85
98
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
86
99
|
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
87
100
|
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
88
|
-
var
|
|
101
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
102
|
+
var import_tracking7 = require("@preact-signals/safe-react/tracking");
|
|
89
103
|
var import_react7 = __toESM(require("react"));
|
|
90
104
|
var import_react_ui7 = require("@dxos/react-ui");
|
|
91
|
-
var
|
|
105
|
+
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
92
106
|
var import_util2 = require("@dxos/util");
|
|
107
|
+
var import_tracking8 = require("@preact-signals/safe-react/tracking");
|
|
93
108
|
var import_react8 = __toESM(require("react"));
|
|
94
109
|
var import_react_ui8 = require("@dxos/react-ui");
|
|
110
|
+
var import_tracking9 = require("@preact-signals/safe-react/tracking");
|
|
95
111
|
var import_react9 = __toESM(require("react"));
|
|
96
|
-
var
|
|
112
|
+
var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
113
|
+
var import_tracking10 = require("@preact-signals/safe-react/tracking");
|
|
97
114
|
var import_react10 = __toESM(require("react"));
|
|
98
115
|
var import_react_ui9 = require("@dxos/react-ui");
|
|
99
|
-
var
|
|
116
|
+
var import_tracking11 = require("@preact-signals/safe-react/tracking");
|
|
100
117
|
var import_react11 = __toESM(require("react"));
|
|
101
118
|
var import_debug = require("@dxos/debug");
|
|
102
119
|
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
@@ -108,34 +125,55 @@ var import_effect3 = require("@dxos/effect");
|
|
|
108
125
|
var import_invariant = require("@dxos/invariant");
|
|
109
126
|
var import_log2 = require("@dxos/log");
|
|
110
127
|
var import_schema2 = require("@dxos/schema");
|
|
128
|
+
var import_react13 = require("react");
|
|
129
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
130
|
+
var import_echo = require("@dxos/react-client/echo");
|
|
131
|
+
var import_util3 = require("@dxos/util");
|
|
132
|
+
var import_react14 = require("react");
|
|
133
|
+
var import_log3 = require("@dxos/log");
|
|
134
|
+
var import_tracking12 = require("@preact-signals/safe-react/tracking");
|
|
111
135
|
var import_effect4 = require("effect");
|
|
112
136
|
var import_String = require("effect/String");
|
|
113
|
-
var
|
|
114
|
-
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
137
|
+
var import_react15 = __toESM(require("react"));
|
|
115
138
|
var import_effect5 = require("@dxos/effect");
|
|
116
139
|
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
117
140
|
var import_schema3 = require("@dxos/schema");
|
|
118
|
-
var
|
|
141
|
+
var import_util4 = require("@dxos/util");
|
|
142
|
+
var import_tracking13 = require("@preact-signals/safe-react/tracking");
|
|
119
143
|
var import_effect6 = require("effect");
|
|
120
144
|
var import_String2 = require("effect/String");
|
|
121
|
-
var
|
|
122
|
-
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
145
|
+
var import_react16 = __toESM(require("react"));
|
|
123
146
|
var import_effect7 = require("@dxos/effect");
|
|
124
147
|
var import_invariant2 = require("@dxos/invariant");
|
|
125
148
|
var import_react_ui10 = require("@dxos/react-ui");
|
|
126
|
-
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
127
149
|
var import_schema4 = require("@dxos/schema");
|
|
150
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
151
|
+
var import_format = require("date-fns/format");
|
|
128
152
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
129
|
-
var import_react15 = __toESM(require("react"));
|
|
130
153
|
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
131
|
-
var
|
|
154
|
+
var import_effect8 = require("@dxos/effect");
|
|
155
|
+
var import_effect9 = require("effect");
|
|
156
|
+
var import_effect10 = require("@dxos/effect");
|
|
157
|
+
var import_tracking14 = require("@preact-signals/safe-react/tracking");
|
|
158
|
+
var import_react17 = __toESM(require("react"));
|
|
159
|
+
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
160
|
+
var import_effect11 = require("@dxos/effect");
|
|
161
|
+
var import_keys2 = require("@dxos/keys");
|
|
162
|
+
var import_react18 = require("@dxos/lit-ui/react");
|
|
132
163
|
var import_react_ui11 = require("@dxos/react-ui");
|
|
164
|
+
var import_react_ui_tag_picker = require("@dxos/react-ui-tag-picker");
|
|
165
|
+
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
166
|
+
var import_util5 = require("@dxos/util");
|
|
167
|
+
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
168
|
+
var import_tracking15 = require("@preact-signals/safe-react/tracking");
|
|
169
|
+
var import_effect12 = require("effect");
|
|
170
|
+
var import_react19 = __toESM(require("react"));
|
|
171
|
+
var import_echo_schema11 = require("@dxos/echo-schema");
|
|
172
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
173
|
+
var import_react_ui12 = require("@dxos/react-ui");
|
|
133
174
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
134
175
|
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
135
176
|
var import_schema5 = require("@dxos/schema");
|
|
136
|
-
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
137
|
-
var import_format = require("date-fns/format");
|
|
138
|
-
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
139
177
|
var translationKey = "react-ui-form";
|
|
140
178
|
var translations_default = [
|
|
141
179
|
{
|
|
@@ -143,6 +181,7 @@ var translations_default = [
|
|
|
143
181
|
[translationKey]: {
|
|
144
182
|
"fields label": "Fields",
|
|
145
183
|
"hidden fields label": "Hidden Fields",
|
|
184
|
+
"empty readonly ref field label": "(none)",
|
|
146
185
|
// TODO(burdon): Standardize field/property.
|
|
147
186
|
"button add property": "Add property",
|
|
148
187
|
"field property label": "Property",
|
|
@@ -152,6 +191,8 @@ var translations_default = [
|
|
|
152
191
|
"add field": "Add field",
|
|
153
192
|
"delete field": "Delete field",
|
|
154
193
|
"field limit reached": "Maximum number of fields reached",
|
|
194
|
+
"boolean input true value": "Yes",
|
|
195
|
+
"boolean input false value": "No",
|
|
155
196
|
// TODO(burdon): Factor out?
|
|
156
197
|
"button cancel": "Cancel",
|
|
157
198
|
"button save": "Save",
|
|
@@ -181,373 +222,466 @@ var translations_default = [
|
|
|
181
222
|
"format number": "Number",
|
|
182
223
|
"format uri": "URI",
|
|
183
224
|
"format uuid": "UUID",
|
|
184
|
-
// Placeholders
|
|
225
|
+
// Placeholders.
|
|
185
226
|
"placeholder latitude": "Latitude",
|
|
186
227
|
"placeholder longitude": "Longitude",
|
|
187
|
-
// SelectOptionsInput
|
|
228
|
+
// SelectOptionsInput.
|
|
188
229
|
"select option label": "Label",
|
|
189
230
|
"select option label placeholder": "Option label",
|
|
190
231
|
"select option color": "Color",
|
|
191
232
|
"select option delete": "Delete",
|
|
192
|
-
"select option add": "Add option"
|
|
233
|
+
"select option add": "Add option",
|
|
234
|
+
// System schema message.
|
|
235
|
+
"system schema title": "System Schema",
|
|
236
|
+
"system schema description": "This schema is managed by the system and cannot be modified."
|
|
193
237
|
}
|
|
194
238
|
}
|
|
195
239
|
}
|
|
196
240
|
];
|
|
197
241
|
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
242
|
+
var _effect = (0, import_tracking.useSignals)();
|
|
243
|
+
try {
|
|
244
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
245
|
+
role: "none",
|
|
246
|
+
className: "container-max-width p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
247
|
+
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
248
|
+
role: "form",
|
|
249
|
+
className: (0, import_react_ui_theme.mx)("flex flex-col", import_react_ui_theme.textBlockWidth, classNames)
|
|
250
|
+
}, children));
|
|
251
|
+
} finally {
|
|
252
|
+
_effect.f();
|
|
253
|
+
}
|
|
205
254
|
};
|
|
206
255
|
var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
role: "none",
|
|
224
|
-
className: "flex min-bs-[--rail-action] items-center"
|
|
225
|
-
}, children))));
|
|
226
|
-
if (secondary) {
|
|
227
|
-
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
256
|
+
var _effect = (0, import_tracking.useSignals)();
|
|
257
|
+
try {
|
|
258
|
+
const primary = /* @__PURE__ */ import_react.default.createElement("div", {
|
|
259
|
+
role: "none",
|
|
260
|
+
className: "flex w-full gap-4 py-1"
|
|
261
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Root, null, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
262
|
+
role: "none",
|
|
263
|
+
className: "flex flex-col w-full"
|
|
264
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Label, {
|
|
265
|
+
classNames: "flex min-bs-[--rail-action] items-center",
|
|
266
|
+
style: {
|
|
267
|
+
fontSize: "unset"
|
|
268
|
+
}
|
|
269
|
+
}, label), description && /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.DescriptionAndValidation, {
|
|
270
|
+
classNames: "mbs-0.5"
|
|
271
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Description, null, description))), /* @__PURE__ */ import_react.default.createElement("div", {
|
|
228
272
|
role: "none"
|
|
229
|
-
},
|
|
273
|
+
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
274
|
+
role: "none",
|
|
275
|
+
className: "flex min-bs-[--rail-action] items-center"
|
|
276
|
+
}, children))));
|
|
277
|
+
if (secondary) {
|
|
278
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
279
|
+
role: "none"
|
|
280
|
+
}, primary, secondary);
|
|
281
|
+
}
|
|
282
|
+
return primary;
|
|
283
|
+
} finally {
|
|
284
|
+
_effect.f();
|
|
230
285
|
}
|
|
231
|
-
return primary;
|
|
232
286
|
};
|
|
233
|
-
var
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
287
|
+
var ControlPage = ({ children, classNames, ...props }) => {
|
|
288
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
289
|
+
try {
|
|
290
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
291
|
+
role: "none",
|
|
292
|
+
className: (0, import_react_ui_theme2.mx)("pli-2", classNames),
|
|
293
|
+
...props
|
|
294
|
+
}, children);
|
|
295
|
+
} finally {
|
|
296
|
+
_effect.f();
|
|
297
|
+
}
|
|
240
298
|
};
|
|
241
299
|
var ControlSection = ({ title, description, children }) => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
300
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
301
|
+
try {
|
|
302
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(ControlSectionHeading, {
|
|
303
|
+
title,
|
|
304
|
+
description
|
|
305
|
+
}), children);
|
|
306
|
+
} finally {
|
|
307
|
+
_effect.f();
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
var ControlSectionHeading = ({ title, description }) => {
|
|
311
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
312
|
+
try {
|
|
313
|
+
const { t } = (0, import_react_ui2.useTranslation)(translationKey);
|
|
314
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement("h2", {
|
|
315
|
+
className: "pli-4 container-max-width text-xl mbs-6 mbe-4"
|
|
316
|
+
}, (0, import_react_ui2.toLocalizedString)(title, t)), description && /* @__PURE__ */ import_react2.default.createElement("p", {
|
|
317
|
+
className: "pli-4 mlb-4 container-max-width text-description"
|
|
318
|
+
}, (0, import_react_ui2.toLocalizedString)(description, t)));
|
|
319
|
+
} finally {
|
|
320
|
+
_effect.f();
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
324
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
325
|
+
try {
|
|
326
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Button, {
|
|
327
|
+
...props,
|
|
328
|
+
classNames: [
|
|
329
|
+
"md:col-span-2",
|
|
330
|
+
classNames
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
} finally {
|
|
334
|
+
_effect.f();
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var ControlGroup = ({ children, classNames }) => {
|
|
338
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
339
|
+
try {
|
|
340
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
341
|
+
role: "none",
|
|
342
|
+
className: (0, import_react_ui_theme2.mx)("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4", classNames)
|
|
343
|
+
}, children);
|
|
344
|
+
} finally {
|
|
345
|
+
_effect.f();
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var ControlFrame = ({ children }) => {
|
|
349
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
350
|
+
try {
|
|
351
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
352
|
+
role: "none",
|
|
353
|
+
className: "p-4 border border-separator rounded-lg container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-2 md:gap-8"
|
|
354
|
+
}, children);
|
|
355
|
+
} finally {
|
|
356
|
+
_effect.f();
|
|
357
|
+
}
|
|
246
358
|
};
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
className: "group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4"
|
|
250
|
-
}, children);
|
|
251
|
-
var ControlFrame = ({ children }) => /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
252
|
-
role: "none",
|
|
253
|
-
className: "p-4 border border-separator rounded-lg container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-2 md:gap-8"
|
|
254
|
-
}, children);
|
|
255
|
-
var controlItemClasses = "p-4 border border-separator rounded-lg container-max-width grid md:col-span-2 grid-cols-subgrid items-center";
|
|
256
|
-
var controlItemTitleClasses = "text-lg font-normal mbe-2";
|
|
359
|
+
var controlItemClasses = "p-4 border border-separator rounded-lg container-max-width grid md:col-span-2 grid-cols-subgrid items-center gap-2";
|
|
360
|
+
var controlItemTitleClasses = "text-lg font-normal";
|
|
257
361
|
var controlItemDescriptionClasses = "text-base mlb-2 md:mbe-0 text-description";
|
|
258
362
|
var ControlItem = ({ title, description, children }) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
363
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
364
|
+
try {
|
|
365
|
+
const { t } = (0, import_react_ui2.useTranslation)(translationKey);
|
|
366
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
367
|
+
className: controlItemClasses
|
|
368
|
+
}, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
369
|
+
role: "none"
|
|
370
|
+
}, /* @__PURE__ */ import_react2.default.createElement("h3", {
|
|
371
|
+
className: controlItemTitleClasses
|
|
372
|
+
}, (0, import_react_ui2.toLocalizedString)(title, t)), description && /* @__PURE__ */ import_react2.default.createElement("p", {
|
|
373
|
+
className: controlItemDescriptionClasses
|
|
374
|
+
}, (0, import_react_ui2.toLocalizedString)(description, t))), children);
|
|
375
|
+
} finally {
|
|
376
|
+
_effect.f();
|
|
377
|
+
}
|
|
269
378
|
};
|
|
270
379
|
var ControlItemInput = ({ title, description, children }) => {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
380
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
381
|
+
try {
|
|
382
|
+
const { t } = (0, import_react_ui2.useTranslation)(translationKey);
|
|
383
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.Root, null, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
384
|
+
className: controlItemClasses
|
|
385
|
+
}, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
386
|
+
role: "none"
|
|
387
|
+
}, /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.Label, {
|
|
388
|
+
classNames: controlItemTitleClasses
|
|
389
|
+
}, (0, import_react_ui2.toLocalizedString)(title, t)), description && /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.DescriptionAndValidation, null, /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.Description, {
|
|
390
|
+
classNames: controlItemDescriptionClasses
|
|
391
|
+
}, (0, import_react_ui2.toLocalizedString)(description, t)))), children));
|
|
392
|
+
} finally {
|
|
393
|
+
_effect.f();
|
|
394
|
+
}
|
|
281
395
|
};
|
|
282
396
|
var ControlFrameItem = ({ title, description, children }) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
397
|
+
var _effect = (0, import_tracking2.useSignals)();
|
|
398
|
+
try {
|
|
399
|
+
const { t } = (0, import_react_ui2.useTranslation)(translationKey);
|
|
400
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
401
|
+
role: "group",
|
|
402
|
+
className: "min-is-0"
|
|
403
|
+
}, /* @__PURE__ */ import_react2.default.createElement("h3", {
|
|
404
|
+
className: "text-lg mbe-2"
|
|
405
|
+
}, (0, import_react_ui2.toLocalizedString)(title, t)), description && /* @__PURE__ */ import_react2.default.createElement("p", {
|
|
406
|
+
className: "mlb-2 md:mbe-0 text-description"
|
|
407
|
+
}, (0, import_react_ui2.toLocalizedString)(description, t)), children);
|
|
408
|
+
} finally {
|
|
409
|
+
_effect.f();
|
|
410
|
+
}
|
|
292
411
|
};
|
|
293
412
|
var InputHeader = ({ children, error }) => {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
413
|
+
var _effect = (0, import_tracking5.useSignals)();
|
|
414
|
+
try {
|
|
415
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
416
|
+
role: "none",
|
|
417
|
+
className: "flex justify-between items-center mbs-2 mbe-1 first:mbs-0"
|
|
418
|
+
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Trigger, {
|
|
419
|
+
asChild: true,
|
|
420
|
+
content: error,
|
|
421
|
+
side: "bottom"
|
|
422
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
423
|
+
icon: "ph--warning--regular",
|
|
424
|
+
size: 4,
|
|
425
|
+
classNames: import_react_ui_theme3.errorText
|
|
426
|
+
})));
|
|
427
|
+
} finally {
|
|
428
|
+
_effect.f();
|
|
429
|
+
}
|
|
306
430
|
};
|
|
307
431
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
0
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
setText(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
432
|
+
var _effect = (0, import_tracking4.useSignals)();
|
|
433
|
+
try {
|
|
434
|
+
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
435
|
+
const { status, error } = getStatus();
|
|
436
|
+
const geoPoint = (0, import_react4.useMemo)(() => getValue3() ?? [
|
|
437
|
+
0,
|
|
438
|
+
0
|
|
439
|
+
], [
|
|
440
|
+
getValue3
|
|
441
|
+
]);
|
|
442
|
+
const geoLocation = (0, import_react4.useMemo)(() => import_echo_schema2.GeoLocation.fromGeoPoint(geoPoint), [
|
|
443
|
+
geoPoint
|
|
444
|
+
]);
|
|
445
|
+
const [longitudeText, setLongitudeText] = (0, import_react4.useState)(geoLocation.longitude?.toString());
|
|
446
|
+
const [latitudeText, setLatitudeText] = (0, import_react4.useState)(geoLocation.latitude?.toString());
|
|
447
|
+
(0, import_react4.useEffect)(() => {
|
|
448
|
+
const location = import_echo_schema2.GeoLocation.fromGeoPoint(geoPoint);
|
|
449
|
+
setLongitudeText(location.longitude.toString());
|
|
450
|
+
setLatitudeText(location.latitude.toString());
|
|
451
|
+
}, [
|
|
452
|
+
geoPoint
|
|
453
|
+
]);
|
|
454
|
+
const handleCoordinateChange = (0, import_react4.useCallback)((coordinateType, setText) => (event) => {
|
|
455
|
+
const inputText = event.target.value;
|
|
456
|
+
setText(inputText);
|
|
457
|
+
if (inputText !== "" && inputText !== "-") {
|
|
458
|
+
const coord = (0, import_util.safeParseFloat)(inputText);
|
|
459
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
460
|
+
const currentLocation = import_echo_schema2.GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
461
|
+
0,
|
|
462
|
+
0
|
|
463
|
+
]);
|
|
464
|
+
const newLocation = {
|
|
465
|
+
...currentLocation,
|
|
466
|
+
[coordinateType]: coord
|
|
467
|
+
};
|
|
468
|
+
const newValue = import_echo_schema2.GeoLocation.toGeoPoint(newLocation);
|
|
469
|
+
onValueChange(type, newValue);
|
|
470
|
+
}
|
|
344
471
|
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
472
|
+
}, [
|
|
473
|
+
getValue3,
|
|
474
|
+
onValueChange,
|
|
475
|
+
type
|
|
476
|
+
]);
|
|
477
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
|
|
478
|
+
validationValence: status
|
|
479
|
+
}, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
|
|
480
|
+
error
|
|
481
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
482
|
+
role: "none",
|
|
483
|
+
className: "grid grid-cols-2 gap-2"
|
|
484
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
|
|
485
|
+
type: "text",
|
|
486
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
487
|
+
disabled,
|
|
488
|
+
placeholder: t("placeholder latitude"),
|
|
489
|
+
value: latitudeText,
|
|
490
|
+
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
491
|
+
onBlur
|
|
492
|
+
}), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
|
|
493
|
+
type: "text",
|
|
494
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
495
|
+
disabled,
|
|
496
|
+
placeholder: t("placeholder longitude"),
|
|
497
|
+
value: longitudeText,
|
|
498
|
+
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
499
|
+
onBlur
|
|
500
|
+
})));
|
|
501
|
+
} finally {
|
|
502
|
+
_effect.f();
|
|
503
|
+
}
|
|
375
504
|
};
|
|
376
505
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const newId = import_keys.PublicKey.random().truncate();
|
|
404
|
-
const newOption = {
|
|
405
|
-
id: newId,
|
|
406
|
-
title: "",
|
|
407
|
-
color: randomHue()
|
|
506
|
+
var _effect = (0, import_tracking6.useSignals)();
|
|
507
|
+
try {
|
|
508
|
+
const [selected, setSelectedId] = (0, import_react6.useState)(null);
|
|
509
|
+
const [isNewOption, setIsNewOption] = (0, import_react6.useState)(false);
|
|
510
|
+
const inputRef = (0, import_react6.useRef)(null);
|
|
511
|
+
const { t } = (0, import_react_ui6.useTranslation)(translationKey);
|
|
512
|
+
const { status, error } = getStatus();
|
|
513
|
+
const options = getValue3();
|
|
514
|
+
(0, import_react6.useEffect)(() => {
|
|
515
|
+
if (options === void 0) {
|
|
516
|
+
onValueChange(type, []);
|
|
517
|
+
}
|
|
518
|
+
}, [
|
|
519
|
+
options,
|
|
520
|
+
onValueChange,
|
|
521
|
+
type
|
|
522
|
+
]);
|
|
523
|
+
const randomHue = () => {
|
|
524
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
525
|
+
const unusedHues = import_react_ui_theme4.hues.filter((hue) => !usedHues.has(hue));
|
|
526
|
+
if (unusedHues.length > 0) {
|
|
527
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
528
|
+
}
|
|
529
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
530
|
+
const availableHues = import_react_ui_theme4.hues.filter((hue) => !lastThree.has(hue));
|
|
531
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? import_react_ui_theme4.hues[Math.floor(Math.random() * import_react_ui_theme4.hues.length)];
|
|
408
532
|
};
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
newOption
|
|
533
|
+
const handleAdd = (0, import_react6.useCallback)(() => {
|
|
534
|
+
const newId = import_keys.PublicKey.random().truncate();
|
|
535
|
+
const newOption = {
|
|
536
|
+
id: newId,
|
|
537
|
+
title: "",
|
|
538
|
+
color: randomHue()
|
|
539
|
+
};
|
|
540
|
+
onValueChange(type, [
|
|
541
|
+
...options ?? [],
|
|
542
|
+
newOption
|
|
543
|
+
]);
|
|
544
|
+
setSelectedId(newId);
|
|
545
|
+
setIsNewOption(true);
|
|
546
|
+
}, [
|
|
547
|
+
options,
|
|
548
|
+
type,
|
|
549
|
+
onValueChange
|
|
412
550
|
]);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
options,
|
|
417
|
-
type,
|
|
418
|
-
onValueChange
|
|
419
|
-
]);
|
|
420
|
-
const handleDelete = (0, import_react6.useCallback)((id) => {
|
|
421
|
-
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
422
|
-
onValueChange(type, newOptions);
|
|
423
|
-
setSelectedId(null);
|
|
424
|
-
}, [
|
|
425
|
-
options,
|
|
426
|
-
type,
|
|
427
|
-
onValueChange
|
|
428
|
-
]);
|
|
429
|
-
const handleMove = (0, import_react6.useCallback)((from, to) => {
|
|
430
|
-
if (!options) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
const newOptions = [
|
|
434
|
-
...options
|
|
435
|
-
];
|
|
436
|
-
const [removed] = newOptions.splice(from, 1);
|
|
437
|
-
newOptions.splice(to, 0, removed);
|
|
438
|
-
onValueChange(type, newOptions);
|
|
439
|
-
}, [
|
|
440
|
-
options,
|
|
441
|
-
type,
|
|
442
|
-
onValueChange
|
|
443
|
-
]);
|
|
444
|
-
const handleClick = (0, import_react6.useCallback)((id) => {
|
|
445
|
-
setSelectedId((current) => current === id ? null : id);
|
|
446
|
-
}, []);
|
|
447
|
-
const handleTitleChange = (0, import_react6.useCallback)((id) => (e) => {
|
|
448
|
-
const newOptions = options?.map((o) => o.id === id ? {
|
|
449
|
-
...o,
|
|
450
|
-
title: e.target.value
|
|
451
|
-
} : o);
|
|
452
|
-
onValueChange(type, newOptions ?? []);
|
|
453
|
-
}, [
|
|
454
|
-
options,
|
|
455
|
-
type,
|
|
456
|
-
onValueChange
|
|
457
|
-
]);
|
|
458
|
-
const handleKeyDown = (0, import_react6.useCallback)((e) => {
|
|
459
|
-
if (e.key === "Enter") {
|
|
551
|
+
const handleDelete = (0, import_react6.useCallback)((id) => {
|
|
552
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
553
|
+
onValueChange(type, newOptions);
|
|
460
554
|
setSelectedId(null);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
555
|
+
}, [
|
|
556
|
+
options,
|
|
557
|
+
type,
|
|
558
|
+
onValueChange
|
|
559
|
+
]);
|
|
560
|
+
const handleMove = (0, import_react6.useCallback)((from, to) => {
|
|
561
|
+
if (!options) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const newOptions = [
|
|
565
|
+
...options
|
|
566
|
+
];
|
|
567
|
+
const [removed] = newOptions.splice(from, 1);
|
|
568
|
+
newOptions.splice(to, 0, removed);
|
|
569
|
+
onValueChange(type, newOptions);
|
|
570
|
+
}, [
|
|
571
|
+
options,
|
|
572
|
+
type,
|
|
573
|
+
onValueChange
|
|
574
|
+
]);
|
|
575
|
+
const handleClick = (0, import_react6.useCallback)((id) => {
|
|
576
|
+
setSelectedId((current) => current === id ? null : id);
|
|
577
|
+
}, []);
|
|
578
|
+
const handleTitleChange = (0, import_react6.useCallback)((id) => (e) => {
|
|
579
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
580
|
+
...o,
|
|
581
|
+
title: e.target.value
|
|
582
|
+
} : o);
|
|
583
|
+
onValueChange(type, newOptions ?? []);
|
|
584
|
+
}, [
|
|
585
|
+
options,
|
|
586
|
+
type,
|
|
587
|
+
onValueChange
|
|
588
|
+
]);
|
|
589
|
+
const handleKeyDown = (0, import_react6.useCallback)((e) => {
|
|
590
|
+
if (e.key === "Enter") {
|
|
591
|
+
setSelectedId(null);
|
|
592
|
+
}
|
|
593
|
+
}, []);
|
|
594
|
+
const handleColorChange = (0, import_react6.useCallback)((id) => (hue) => {
|
|
595
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
596
|
+
...o,
|
|
597
|
+
color: hue
|
|
598
|
+
} : o);
|
|
599
|
+
onValueChange(type, newOptions ?? []);
|
|
600
|
+
}, [
|
|
601
|
+
options,
|
|
602
|
+
type,
|
|
603
|
+
onValueChange
|
|
604
|
+
]);
|
|
605
|
+
(0, import_react6.useEffect)(() => {
|
|
606
|
+
if (selected && isNewOption && inputRef.current) {
|
|
607
|
+
inputRef.current.focus();
|
|
608
|
+
setIsNewOption(false);
|
|
609
|
+
}
|
|
610
|
+
}, [
|
|
611
|
+
selected,
|
|
612
|
+
isNewOption
|
|
613
|
+
]);
|
|
614
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
615
|
+
validationValence: status
|
|
616
|
+
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
617
|
+
error
|
|
618
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
619
|
+
role: "none"
|
|
620
|
+
}, options && /* @__PURE__ */ import_react6.default.createElement(import_react_ui_list.List.Root, {
|
|
621
|
+
items: options,
|
|
622
|
+
isItem: (item) => true,
|
|
623
|
+
onMove: handleMove
|
|
624
|
+
}, ({ items }) => /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
625
|
+
role: "list",
|
|
626
|
+
className: "w-full overflow-auto"
|
|
627
|
+
}, items?.map((item) => /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
628
|
+
key: item.id
|
|
629
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui_list.List.Item, {
|
|
630
|
+
role: "button",
|
|
631
|
+
item,
|
|
632
|
+
classNames: (0, import_react_ui_theme4.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
633
|
+
"aria-expanded": selected === item.id
|
|
634
|
+
}, /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
635
|
+
className: "flex items-center"
|
|
636
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react6.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
637
|
+
onClick: () => handleClick(item.id),
|
|
638
|
+
classNames: "flex-1"
|
|
639
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Tag, {
|
|
640
|
+
palette: item.color
|
|
641
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Icon, {
|
|
642
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
643
|
+
onClick: () => handleClick(item.id)
|
|
644
|
+
})), selected === item.id && /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
645
|
+
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
646
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, {
|
|
647
|
+
classNames: "text-xs"
|
|
648
|
+
}, t("select option label")), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
649
|
+
className: "flex flex-row items-center gap-1"
|
|
650
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
651
|
+
placeholder: t("select option label placeholder"),
|
|
652
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
653
|
+
value: item.title,
|
|
654
|
+
onChange: handleTitleChange(item.id),
|
|
655
|
+
onKeyDown: handleKeyDown,
|
|
656
|
+
classNames: "flex-1",
|
|
657
|
+
"data-no-submit": true
|
|
658
|
+
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Toolbar.Root, {
|
|
659
|
+
classNames: "p-0 m-0 !is-auto"
|
|
660
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui_pickers.HuePicker, {
|
|
661
|
+
value: item.color,
|
|
662
|
+
onChange: handleColorChange(item.id),
|
|
663
|
+
rootVariant: "toolbar-button"
|
|
664
|
+
})), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.IconButton, {
|
|
665
|
+
icon: "ph--trash--fill",
|
|
666
|
+
iconOnly: true,
|
|
667
|
+
label: t("select option delete"),
|
|
668
|
+
onClick: () => handleDelete(item.id)
|
|
669
|
+
})))))), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
670
|
+
role: "listitem"
|
|
671
|
+
}, /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
672
|
+
role: "button",
|
|
673
|
+
className: (0, import_react_ui_theme4.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
674
|
+
onClick: handleAdd
|
|
675
|
+
}, /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
676
|
+
className: "flex items-center gap-1"
|
|
677
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Icon, {
|
|
678
|
+
icon: "ph--plus--regular"
|
|
679
|
+
}), /* @__PURE__ */ import_react6.default.createElement("span", {
|
|
680
|
+
className: "text-sm"
|
|
681
|
+
}, t("select option add")))))))));
|
|
682
|
+
} finally {
|
|
683
|
+
_effect.f();
|
|
684
|
+
}
|
|
551
685
|
};
|
|
552
686
|
var gridCols = [
|
|
553
687
|
"grid-cols-1",
|
|
@@ -556,126 +690,162 @@ var gridCols = [
|
|
|
556
690
|
"grid-cols-4"
|
|
557
691
|
];
|
|
558
692
|
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
693
|
+
var _effect = (0, import_tracking7.useSignals)();
|
|
694
|
+
try {
|
|
695
|
+
const { status, error } = getStatus();
|
|
696
|
+
const values = getValue3() ?? {};
|
|
697
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
698
|
+
validationValence: status
|
|
699
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
700
|
+
error
|
|
701
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
702
|
+
className: (0, import_react_ui_theme5.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
703
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
704
|
+
key: prop,
|
|
705
|
+
type: "number",
|
|
706
|
+
disabled,
|
|
707
|
+
value: values[prop],
|
|
708
|
+
onChange: (event) => onValueChange(type, {
|
|
709
|
+
...values,
|
|
710
|
+
[prop]: (0, import_util2.safeParseFloat)(event.target.value, 0)
|
|
711
|
+
}),
|
|
712
|
+
onBlur
|
|
713
|
+
}))));
|
|
714
|
+
} finally {
|
|
715
|
+
_effect.f();
|
|
716
|
+
}
|
|
578
717
|
};
|
|
579
718
|
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
719
|
+
var _effect = (0, import_tracking8.useSignals)();
|
|
720
|
+
try {
|
|
721
|
+
const { status, error } = getStatus();
|
|
722
|
+
return disabled && !getValue3() ? null : disabled && inputOnly ? /* @__PURE__ */ import_react8.default.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
723
|
+
validationValence: status
|
|
724
|
+
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
725
|
+
error
|
|
726
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), disabled ? /* @__PURE__ */ import_react8.default.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.TextInput, {
|
|
727
|
+
disabled,
|
|
728
|
+
placeholder,
|
|
729
|
+
value: getValue3() ?? "",
|
|
730
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
731
|
+
onBlur
|
|
732
|
+
}), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Validation, null, error));
|
|
733
|
+
} finally {
|
|
734
|
+
_effect.f();
|
|
735
|
+
}
|
|
592
736
|
};
|
|
593
737
|
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
disabled,
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
738
|
+
var _effect = (0, import_tracking8.useSignals)();
|
|
739
|
+
try {
|
|
740
|
+
const { status, error } = getStatus();
|
|
741
|
+
return disabled && !getValue3() ? null : disabled && inputOnly ? /* @__PURE__ */ import_react8.default.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
742
|
+
validationValence: status
|
|
743
|
+
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
744
|
+
error
|
|
745
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), disabled ? /* @__PURE__ */ import_react8.default.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.TextInput, {
|
|
746
|
+
type: "number",
|
|
747
|
+
disabled,
|
|
748
|
+
placeholder,
|
|
749
|
+
value: getValue3() ?? 0,
|
|
750
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
751
|
+
onBlur
|
|
752
|
+
}), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.DescriptionAndValidation, null, error));
|
|
753
|
+
} finally {
|
|
754
|
+
_effect.f();
|
|
755
|
+
}
|
|
607
756
|
};
|
|
608
|
-
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
757
|
+
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange, disabled }) => {
|
|
758
|
+
var _effect = (0, import_tracking8.useSignals)();
|
|
759
|
+
try {
|
|
760
|
+
const { status, error } = getStatus();
|
|
761
|
+
const checked = Boolean(getValue3());
|
|
762
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
763
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
764
|
+
validationValence: status
|
|
765
|
+
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
766
|
+
error
|
|
767
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), disabled ? /* @__PURE__ */ import_react8.default.createElement("p", null, t(checked ? "boolean input true value" : "boolean input false value")) : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Switch, {
|
|
768
|
+
checked,
|
|
769
|
+
onCheckedChange: (value) => onValueChange(type, value)
|
|
770
|
+
}), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.DescriptionAndValidation, null, error));
|
|
771
|
+
} finally {
|
|
772
|
+
_effect.f();
|
|
773
|
+
}
|
|
619
774
|
};
|
|
620
775
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
776
|
+
var _effect = (0, import_tracking8.useSignals)();
|
|
777
|
+
try {
|
|
778
|
+
const { status, error } = getStatus();
|
|
779
|
+
const value = getValue3();
|
|
780
|
+
const handleValueChange = (0, import_react8.useCallback)((value2) => onValueChange(type, value2), [
|
|
781
|
+
type,
|
|
782
|
+
onValueChange
|
|
783
|
+
]);
|
|
784
|
+
return disabled && !value ? null : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
785
|
+
validationValence: status
|
|
786
|
+
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
787
|
+
error
|
|
788
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), disabled ? /* @__PURE__ */ import_react8.default.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value)?.label ?? String(value)) : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Root, {
|
|
789
|
+
value,
|
|
790
|
+
onValueChange: handleValueChange
|
|
791
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.TriggerButton, {
|
|
792
|
+
classNames: "is-full",
|
|
793
|
+
disabled,
|
|
794
|
+
placeholder
|
|
795
|
+
}), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Portal, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Content, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
796
|
+
// NOTE: Numeric values are converted to and from strings.
|
|
797
|
+
/* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Option, {
|
|
798
|
+
key: String(value2),
|
|
799
|
+
value: String(value2)
|
|
800
|
+
}, label2 ?? String(value2))
|
|
801
|
+
)))))), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.DescriptionAndValidation, null, error));
|
|
802
|
+
} finally {
|
|
803
|
+
_effect.f();
|
|
804
|
+
}
|
|
640
805
|
};
|
|
641
806
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
textarea
|
|
648
|
-
textarea
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
disabled,
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
807
|
+
var _effect = (0, import_tracking8.useSignals)();
|
|
808
|
+
try {
|
|
809
|
+
const { status, error } = getStatus();
|
|
810
|
+
const textareaRef = (0, import_react8.useRef)(null);
|
|
811
|
+
const adjustHeight = (0, import_react8.useCallback)(() => {
|
|
812
|
+
const textarea = textareaRef.current;
|
|
813
|
+
if (textarea) {
|
|
814
|
+
textarea.style.blockSize = "auto";
|
|
815
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
816
|
+
}
|
|
817
|
+
}, []);
|
|
818
|
+
(0, import_react8.useEffect)(() => {
|
|
819
|
+
adjustHeight();
|
|
820
|
+
}, [
|
|
821
|
+
adjustHeight
|
|
822
|
+
]);
|
|
823
|
+
(0, import_react8.useEffect)(() => {
|
|
824
|
+
adjustHeight();
|
|
825
|
+
}, [
|
|
826
|
+
getValue3(),
|
|
827
|
+
adjustHeight
|
|
828
|
+
]);
|
|
829
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
830
|
+
validationValence: status
|
|
831
|
+
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
832
|
+
error
|
|
833
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), disabled ? /* @__PURE__ */ import_react8.default.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.TextArea, {
|
|
834
|
+
ref: textareaRef,
|
|
835
|
+
disabled,
|
|
836
|
+
placeholder,
|
|
837
|
+
value: getValue3() ?? "",
|
|
838
|
+
classNames: "min-bs-auto max-h-40 overflow-auto",
|
|
839
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
840
|
+
onBlur,
|
|
841
|
+
style: {
|
|
842
|
+
resize: "none"
|
|
843
|
+
},
|
|
844
|
+
spellCheck: false
|
|
845
|
+
}), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Validation, null, error));
|
|
846
|
+
} finally {
|
|
847
|
+
_effect.f();
|
|
848
|
+
}
|
|
679
849
|
};
|
|
680
850
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
681
851
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
@@ -684,7 +854,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
684
854
|
L: 93,
|
|
685
855
|
S: void 0,
|
|
686
856
|
A: [
|
|
687
|
-
"
|
|
857
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
688
858
|
""
|
|
689
859
|
]
|
|
690
860
|
});
|
|
@@ -785,7 +955,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
785
955
|
} catch (err) {
|
|
786
956
|
import_log2.log.catch(err, void 0, {
|
|
787
957
|
F: __dxlog_file,
|
|
788
|
-
L:
|
|
958
|
+
L: 213,
|
|
789
959
|
S: void 0,
|
|
790
960
|
C: (f, a) => f(...a)
|
|
791
961
|
});
|
|
@@ -856,7 +1026,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
856
1026
|
var createKeySet = (obj, value) => {
|
|
857
1027
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
858
1028
|
F: __dxlog_file,
|
|
859
|
-
L:
|
|
1029
|
+
L: 275,
|
|
860
1030
|
S: void 0,
|
|
861
1031
|
A: [
|
|
862
1032
|
"obj",
|
|
@@ -877,6 +1047,70 @@ var flatMap = (errors) => {
|
|
|
877
1047
|
return result;
|
|
878
1048
|
}, {});
|
|
879
1049
|
};
|
|
1050
|
+
var useRefQueryLookupHandler = ({ space }) => {
|
|
1051
|
+
return (0, import_react13.useCallback)(async (typeInfo) => {
|
|
1052
|
+
if (!space) {
|
|
1053
|
+
return [];
|
|
1054
|
+
}
|
|
1055
|
+
const query = space.db.query(import_echo.Filter.typename(typeInfo.typename));
|
|
1056
|
+
const { objects } = await query.run();
|
|
1057
|
+
return objects.map((object) => {
|
|
1058
|
+
const dxn = (0, import_echo_schema5.getDXN)(object);
|
|
1059
|
+
if (!dxn) {
|
|
1060
|
+
return void 0;
|
|
1061
|
+
}
|
|
1062
|
+
const item = {
|
|
1063
|
+
dxn,
|
|
1064
|
+
label: object?.name ?? object?.id ?? ""
|
|
1065
|
+
};
|
|
1066
|
+
return item;
|
|
1067
|
+
}).filter(import_util3.isNonNullable);
|
|
1068
|
+
}, [
|
|
1069
|
+
space
|
|
1070
|
+
]);
|
|
1071
|
+
};
|
|
1072
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
1073
|
+
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
1074
|
+
const [options, setOptions] = (0, import_react14.useState)([]);
|
|
1075
|
+
const [loading, setLoading] = (0, import_react14.useState)(false);
|
|
1076
|
+
(0, import_react14.useEffect)(() => {
|
|
1077
|
+
if (!refTypeInfo || !onQueryRefOptions) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const fetchOptions = async () => {
|
|
1081
|
+
setLoading(true);
|
|
1082
|
+
try {
|
|
1083
|
+
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
1084
|
+
setOptions(fetchedOptions.map((option) => {
|
|
1085
|
+
const dxn = option.dxn.toString();
|
|
1086
|
+
return {
|
|
1087
|
+
id: dxn,
|
|
1088
|
+
label: option.label ?? dxn,
|
|
1089
|
+
hue: "neutral"
|
|
1090
|
+
};
|
|
1091
|
+
}));
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
import_log3.log.error("Failed to fetch ref options:", error, {
|
|
1094
|
+
F: __dxlog_file2,
|
|
1095
|
+
L: 42,
|
|
1096
|
+
S: void 0,
|
|
1097
|
+
C: (f, a) => f(...a)
|
|
1098
|
+
});
|
|
1099
|
+
setOptions([]);
|
|
1100
|
+
} finally {
|
|
1101
|
+
setLoading(false);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
void fetchOptions();
|
|
1105
|
+
}, [
|
|
1106
|
+
refTypeInfo,
|
|
1107
|
+
onQueryRefOptions
|
|
1108
|
+
]);
|
|
1109
|
+
return {
|
|
1110
|
+
options,
|
|
1111
|
+
loading
|
|
1112
|
+
};
|
|
1113
|
+
};
|
|
880
1114
|
var FormContext = /* @__PURE__ */ (0, import_react11.createContext)(void 0);
|
|
881
1115
|
var useFormContext = () => {
|
|
882
1116
|
return (0, import_react11.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
@@ -905,16 +1139,14 @@ var useInputProps = (path = []) => {
|
|
|
905
1139
|
]);
|
|
906
1140
|
};
|
|
907
1141
|
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
const handleKeyDown = (event) => {
|
|
1142
|
+
var _effect = (0, import_tracking11.useSignals)();
|
|
1143
|
+
try {
|
|
1144
|
+
const form = useForm(formOptions);
|
|
1145
|
+
const handleKeyDown = (0, import_react11.useCallback)((event) => {
|
|
914
1146
|
const keyIsEnter = event.key === "Enter";
|
|
915
1147
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
916
1148
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
917
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
1149
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
918
1150
|
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
919
1151
|
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
920
1152
|
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
@@ -925,784 +1157,150 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
925
1157
|
event.target.blur();
|
|
926
1158
|
}
|
|
927
1159
|
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1160
|
+
}, [
|
|
1161
|
+
form,
|
|
1162
|
+
autoSave
|
|
1163
|
+
]);
|
|
1164
|
+
(0, import_react11.useEffect)(() => {
|
|
1165
|
+
if (!formRef?.current) {
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
const formElement = formRef.current;
|
|
1169
|
+
formElement.addEventListener("keydown", handleKeyDown);
|
|
1170
|
+
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
1171
|
+
}, [
|
|
1172
|
+
formRef,
|
|
1173
|
+
form.canSave,
|
|
1174
|
+
form.formIsValid,
|
|
1175
|
+
form.handleSave,
|
|
1176
|
+
autoSave
|
|
1177
|
+
]);
|
|
1178
|
+
return /* @__PURE__ */ import_react11.default.createElement(FormContext.Provider, {
|
|
1179
|
+
value: form
|
|
1180
|
+
}, children);
|
|
1181
|
+
} finally {
|
|
1182
|
+
_effect.f();
|
|
1183
|
+
}
|
|
942
1184
|
};
|
|
943
|
-
var FormActions = ({
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
1185
|
+
var FormActions = ({ readonly, onCancel }) => {
|
|
1186
|
+
var _effect = (0, import_tracking10.useSignals)();
|
|
1187
|
+
try {
|
|
1188
|
+
const { t } = (0, import_react_ui9.useTranslation)(translationKey);
|
|
1189
|
+
const { canSave, handleSave } = useFormContext();
|
|
1190
|
+
return /* @__PURE__ */ import_react10.default.createElement("div", {
|
|
1191
|
+
role: "none",
|
|
1192
|
+
className: "flex [&_button]:grow gap-1"
|
|
1193
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react10.default.createElement(import_react_ui9.IconButton, {
|
|
1194
|
+
"data-testid": "cancel-button",
|
|
1195
|
+
icon: "ph--x--regular",
|
|
1196
|
+
label: t("button cancel"),
|
|
1197
|
+
onClick: onCancel
|
|
1198
|
+
}), handleSave && /* @__PURE__ */ import_react10.default.createElement(import_react_ui9.IconButton, {
|
|
1199
|
+
type: "submit",
|
|
1200
|
+
"data-testid": "save-button",
|
|
1201
|
+
disabled: !canSave,
|
|
1202
|
+
icon: "ph--check--regular",
|
|
1203
|
+
label: t("button save"),
|
|
1204
|
+
onClick: handleSave
|
|
1205
|
+
}));
|
|
1206
|
+
} finally {
|
|
1207
|
+
_effect.f();
|
|
1208
|
+
}
|
|
965
1209
|
};
|
|
966
|
-
var
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1210
|
+
var parseValue = ({ type, format, value }) => {
|
|
1211
|
+
if (value === void 0 || value === null || value === "") {
|
|
1212
|
+
return void 0;
|
|
1213
|
+
}
|
|
1214
|
+
const parseScalar = (type2) => {
|
|
1215
|
+
switch (type2) {
|
|
1216
|
+
case import_echo_schema6.TypeEnum.Boolean: {
|
|
1217
|
+
if (typeof value === "string") {
|
|
1218
|
+
const lowercaseValue = value.toLowerCase();
|
|
1219
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1220
|
+
return false;
|
|
1221
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1222
|
+
return true;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return Boolean(value);
|
|
1226
|
+
}
|
|
1227
|
+
case import_echo_schema6.TypeEnum.Number: {
|
|
1228
|
+
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1229
|
+
const num = Number(cleaned);
|
|
1230
|
+
return Number.isNaN(num) ? null : num;
|
|
1231
|
+
}
|
|
1232
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1233
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1234
|
+
return String(value);
|
|
1235
|
+
default: {
|
|
1236
|
+
return value;
|
|
1237
|
+
}
|
|
989
1238
|
}
|
|
990
|
-
return Object.fromEntries((0, import_schema4.getSchemaProperties)(typeLiteral, {}).map((prop) => [
|
|
991
|
-
prop.name,
|
|
992
|
-
prop.defaultValue
|
|
993
|
-
]));
|
|
994
1239
|
};
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
return getDefaultObjectValue(elementType);
|
|
998
|
-
} else {
|
|
999
|
-
return import_effect7.SimpleType.getDefaultValue(type);
|
|
1000
|
-
}
|
|
1001
|
-
}, [
|
|
1002
|
-
type,
|
|
1003
|
-
elementType
|
|
1004
|
-
]);
|
|
1005
|
-
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
1006
|
-
inputProps.onValueChange(type, [
|
|
1007
|
-
...values,
|
|
1008
|
-
newValue
|
|
1009
|
-
]);
|
|
1010
|
-
}, [
|
|
1011
|
-
type,
|
|
1012
|
-
elementType,
|
|
1013
|
-
inputProps,
|
|
1014
|
-
newValue,
|
|
1015
|
-
values
|
|
1016
|
-
]);
|
|
1017
|
-
const handleRemove = (0, import_react14.useCallback)((index) => {
|
|
1018
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
1019
|
-
inputProps.onValueChange(type, newValues);
|
|
1020
|
-
}, [
|
|
1021
|
-
type,
|
|
1022
|
-
inputProps,
|
|
1023
|
-
values
|
|
1024
|
-
]);
|
|
1025
|
-
if (!elementType) {
|
|
1026
|
-
return null;
|
|
1240
|
+
if (!format) {
|
|
1241
|
+
return parseScalar(type);
|
|
1027
1242
|
}
|
|
1028
|
-
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1029
|
-
role: "none",
|
|
1030
|
-
className: (0, import_react_ui_theme8.mx)(padding)
|
|
1031
|
-
}, /* @__PURE__ */ import_react14.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1032
|
-
role: "none",
|
|
1033
|
-
className: "flex flex-col gap-1"
|
|
1034
|
-
}, values.map((_value, index) => /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1035
|
-
key: index,
|
|
1036
|
-
role: "none",
|
|
1037
|
-
className: "flex items-center gap-1"
|
|
1038
|
-
}, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1039
|
-
role: "none",
|
|
1040
|
-
className: "flex-1"
|
|
1041
|
-
}, /* @__PURE__ */ import_react14.default.createElement(FormField, {
|
|
1042
|
-
property: {
|
|
1043
|
-
...property,
|
|
1044
|
-
array: false,
|
|
1045
|
-
ast: elementType
|
|
1046
|
-
},
|
|
1047
|
-
path: [
|
|
1048
|
-
...path ?? [],
|
|
1049
|
-
index
|
|
1050
|
-
],
|
|
1051
|
-
readonly,
|
|
1052
|
-
inline: true,
|
|
1053
|
-
Custom,
|
|
1054
|
-
lookupComponent
|
|
1055
|
-
})), /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1056
|
-
icon: "ph--trash--regular",
|
|
1057
|
-
iconOnly: true,
|
|
1058
|
-
label: t("button remove"),
|
|
1059
|
-
onClick: () => handleRemove(index)
|
|
1060
|
-
})))), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1061
|
-
role: "none",
|
|
1062
|
-
className: "flex justify-between items-center plb-1"
|
|
1063
|
-
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1064
|
-
icon: "ph--plus--regular",
|
|
1065
|
-
iconOnly: true,
|
|
1066
|
-
label: t("button add"),
|
|
1067
|
-
onClick: handleAdd
|
|
1068
|
-
})));
|
|
1069
|
-
};
|
|
1070
|
-
var getInputComponent = (type, format) => {
|
|
1071
1243
|
switch (format) {
|
|
1072
|
-
case
|
|
1073
|
-
return
|
|
1074
|
-
case
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
case
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
case
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1114
|
-
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1115
|
-
const CustomComponent = Custom?.[jsonPath];
|
|
1116
|
-
if (CustomComponent) {
|
|
1117
|
-
return /* @__PURE__ */ import_react13.default.createElement(CustomComponent, {
|
|
1118
|
-
type,
|
|
1119
|
-
format,
|
|
1120
|
-
label,
|
|
1121
|
-
inputOnly: inline,
|
|
1122
|
-
placeholder,
|
|
1123
|
-
disabled: readonly,
|
|
1124
|
-
...inputProps
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
if (array) {
|
|
1128
|
-
return /* @__PURE__ */ import_react13.default.createElement(ArrayField, {
|
|
1129
|
-
property,
|
|
1130
|
-
path,
|
|
1131
|
-
inputProps,
|
|
1132
|
-
readonly,
|
|
1133
|
-
Custom
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1136
|
-
const InputComponent = getInputComponent(type, format);
|
|
1137
|
-
if (InputComponent) {
|
|
1138
|
-
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
1139
|
-
role: "none"
|
|
1140
|
-
}, /* @__PURE__ */ import_react13.default.createElement(InputComponent, {
|
|
1141
|
-
type,
|
|
1142
|
-
format,
|
|
1143
|
-
label,
|
|
1144
|
-
inputOnly: inline,
|
|
1145
|
-
placeholder,
|
|
1146
|
-
disabled: readonly,
|
|
1147
|
-
...inputProps
|
|
1148
|
-
}));
|
|
1149
|
-
}
|
|
1150
|
-
if (options) {
|
|
1151
|
-
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
1152
|
-
role: "none"
|
|
1153
|
-
}, /* @__PURE__ */ import_react13.default.createElement(SelectInput, {
|
|
1154
|
-
type,
|
|
1155
|
-
format,
|
|
1156
|
-
disabled: readonly,
|
|
1157
|
-
inputOnly: inline,
|
|
1158
|
-
label,
|
|
1159
|
-
options: options.map((option) => ({
|
|
1160
|
-
value: option,
|
|
1161
|
-
label: String(option)
|
|
1162
|
-
})),
|
|
1163
|
-
placeholder,
|
|
1164
|
-
...inputProps
|
|
1165
|
-
}));
|
|
1166
|
-
}
|
|
1167
|
-
if (type === "object") {
|
|
1168
|
-
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1169
|
-
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_echo_schema5.AST.isTypeLiteral);
|
|
1170
|
-
if (typeLiteral) {
|
|
1171
|
-
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
1172
|
-
role: "none"
|
|
1173
|
-
}, !inline && /* @__PURE__ */ import_react13.default.createElement("div", null, label), /* @__PURE__ */ import_react13.default.createElement(FormFields, {
|
|
1174
|
-
schema: import_echo_schema5.S.make(typeLiteral),
|
|
1175
|
-
path,
|
|
1176
|
-
readonly,
|
|
1177
|
-
Custom
|
|
1178
|
-
}));
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
return null;
|
|
1182
|
-
};
|
|
1183
|
-
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1184
|
-
const values = useFormValues(path);
|
|
1185
|
-
const properties = (0, import_react13.useMemo)(() => {
|
|
1186
|
-
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1187
|
-
const filtered = filter ? filter(props) : props;
|
|
1188
|
-
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
1189
|
-
}, [
|
|
1190
|
-
schema,
|
|
1191
|
-
values,
|
|
1192
|
-
filter,
|
|
1193
|
-
sort
|
|
1194
|
-
]);
|
|
1195
|
-
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
1196
|
-
role: "form",
|
|
1197
|
-
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2")
|
|
1198
|
-
}, properties.map((property) => {
|
|
1199
|
-
return /* @__PURE__ */ import_react13.default.createElement(FormField, {
|
|
1200
|
-
key: property.name,
|
|
1201
|
-
property,
|
|
1202
|
-
path: [
|
|
1203
|
-
...path ?? [],
|
|
1204
|
-
property.name
|
|
1205
|
-
],
|
|
1206
|
-
readonly,
|
|
1207
|
-
lookupComponent,
|
|
1208
|
-
Custom
|
|
1209
|
-
});
|
|
1210
|
-
}).filter(import_util3.isNotFalsy));
|
|
1211
|
-
};
|
|
1212
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1213
|
-
const formRef = (0, import_react9.useRef)(null);
|
|
1214
|
-
const onValid = (0, import_react9.useMemo)(() => autoSave ? onSave : void 0, [
|
|
1215
|
-
autoSave,
|
|
1216
|
-
onSave
|
|
1217
|
-
]);
|
|
1218
|
-
(0, import_react9.useEffect)(() => {
|
|
1219
|
-
if (autoFocus && formRef.current) {
|
|
1220
|
-
const input = formRef.current.querySelector("input");
|
|
1221
|
-
if (input) {
|
|
1222
|
-
input.focus();
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}, [
|
|
1226
|
-
autoFocus
|
|
1227
|
-
]);
|
|
1228
|
-
return /* @__PURE__ */ import_react9.default.createElement(FormProvider, {
|
|
1229
|
-
formRef,
|
|
1230
|
-
schema,
|
|
1231
|
-
autoSave,
|
|
1232
|
-
initialValues,
|
|
1233
|
-
onValuesChanged,
|
|
1234
|
-
onValidate,
|
|
1235
|
-
onValid,
|
|
1236
|
-
onSave
|
|
1237
|
-
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1238
|
-
ref: formRef,
|
|
1239
|
-
role: "none",
|
|
1240
|
-
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
1241
|
-
"data-testid": testId
|
|
1242
|
-
}, /* @__PURE__ */ import_react9.default.createElement(FormFields, {
|
|
1243
|
-
schema,
|
|
1244
|
-
path,
|
|
1245
|
-
readonly,
|
|
1246
|
-
filter,
|
|
1247
|
-
sort,
|
|
1248
|
-
lookupComponent,
|
|
1249
|
-
Custom
|
|
1250
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react9.default.createElement(FormActions, {
|
|
1251
|
-
onCancel,
|
|
1252
|
-
readonly
|
|
1253
|
-
})));
|
|
1254
|
-
};
|
|
1255
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1256
|
-
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1257
|
-
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
1258
|
-
const [props, setProps] = (0, import_react3.useState)(projection.getFieldProjection(field.id).props);
|
|
1259
|
-
(0, import_react3.useEffect)(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1260
|
-
field,
|
|
1261
|
-
projection
|
|
1262
|
-
]);
|
|
1263
|
-
const [schemas, setSchemas] = (0, import_react3.useState)([]);
|
|
1264
|
-
(0, import_react3.useEffect)(() => {
|
|
1265
|
-
if (!registry) {
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
1269
|
-
fire: true
|
|
1270
|
-
});
|
|
1271
|
-
const t2 = setTimeout(async () => {
|
|
1272
|
-
const schemas2 = await registry.query().run();
|
|
1273
|
-
setSchemas(schemas2);
|
|
1274
|
-
});
|
|
1275
|
-
return () => {
|
|
1276
|
-
clearTimeout(t2);
|
|
1277
|
-
subscription?.();
|
|
1278
|
-
};
|
|
1279
|
-
}, [
|
|
1280
|
-
registry
|
|
1281
|
-
]);
|
|
1282
|
-
const [referenceSchema, setReferenceSchema] = (0, import_react3.useState)();
|
|
1283
|
-
(0, import_react3.useEffect)(() => {
|
|
1284
|
-
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1285
|
-
}, [
|
|
1286
|
-
schemas,
|
|
1287
|
-
props?.referenceSchema
|
|
1288
|
-
]);
|
|
1289
|
-
const [{ fieldSchema }, setFieldSchema] = (0, import_react3.useState)({
|
|
1290
|
-
fieldSchema: (0, import_schema.getFormatSchema)(props?.format)
|
|
1291
|
-
});
|
|
1292
|
-
const handleValuesChanged = (0, import_react3.useCallback)((_props) => {
|
|
1293
|
-
setFieldSchema((prev) => {
|
|
1294
|
-
const fieldSchema2 = (0, import_schema.getFormatSchema)(_props.format);
|
|
1295
|
-
if (prev.fieldSchema === fieldSchema2) {
|
|
1296
|
-
return prev;
|
|
1297
|
-
}
|
|
1298
|
-
return {
|
|
1299
|
-
fieldSchema: fieldSchema2
|
|
1300
|
-
};
|
|
1301
|
-
});
|
|
1302
|
-
setReferenceSchema((prev) => {
|
|
1303
|
-
if (_props.referenceSchema !== prev?.typename) {
|
|
1304
|
-
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
1305
|
-
if (newSchema) {
|
|
1306
|
-
return newSchema;
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
return prev;
|
|
1310
|
-
});
|
|
1311
|
-
setProps((props2) => {
|
|
1312
|
-
const type = import_echo_schema.formatToType[_props.format];
|
|
1313
|
-
if (props2.type !== type) {
|
|
1314
|
-
return {
|
|
1315
|
-
...props2,
|
|
1316
|
-
..._props,
|
|
1317
|
-
type
|
|
1318
|
-
};
|
|
1319
|
-
}
|
|
1320
|
-
return _props;
|
|
1321
|
-
});
|
|
1322
|
-
}, [
|
|
1323
|
-
schemas,
|
|
1324
|
-
props.format,
|
|
1325
|
-
props.referenceSchema
|
|
1326
|
-
]);
|
|
1327
|
-
const handleValidate = (0, import_react3.useCallback)(({ property }) => {
|
|
1328
|
-
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
1329
|
-
return [
|
|
1330
|
-
{
|
|
1331
|
-
path: "property",
|
|
1332
|
-
message: `property is not unique: '${property}'`
|
|
1333
|
-
}
|
|
1334
|
-
];
|
|
1335
|
-
}
|
|
1336
|
-
}, [
|
|
1337
|
-
view.fields,
|
|
1338
|
-
field
|
|
1339
|
-
]);
|
|
1340
|
-
const handleSave = (0, import_react3.useCallback)((props2) => {
|
|
1341
|
-
projection.setFieldProjection({
|
|
1342
|
-
field,
|
|
1343
|
-
props: props2
|
|
1344
|
-
});
|
|
1345
|
-
onSave();
|
|
1346
|
-
}, [
|
|
1347
|
-
projection,
|
|
1348
|
-
field,
|
|
1349
|
-
onSave
|
|
1350
|
-
]);
|
|
1351
|
-
const handleCancel = (0, import_react3.useCallback)(() => {
|
|
1352
|
-
requestAnimationFrame(() => onCancel?.());
|
|
1353
|
-
onSave();
|
|
1354
|
-
}, [
|
|
1355
|
-
onSave
|
|
1356
|
-
]);
|
|
1357
|
-
const Custom = (0, import_react3.useMemo)(() => ({
|
|
1358
|
-
["format"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
1359
|
-
...props2,
|
|
1360
|
-
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
1361
|
-
value,
|
|
1362
|
-
label: t(`format ${value}`)
|
|
1363
|
-
}))
|
|
1364
|
-
}),
|
|
1365
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
1366
|
-
...props2,
|
|
1367
|
-
options: schemas.map((schema) => ({
|
|
1368
|
-
value: schema.typename
|
|
1369
|
-
}))
|
|
1370
|
-
}),
|
|
1371
|
-
["referencePath"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
1372
|
-
...props2,
|
|
1373
|
-
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
1374
|
-
value: p.name
|
|
1375
|
-
})) : []
|
|
1376
|
-
}),
|
|
1377
|
-
["options"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectOptionInput, props2)
|
|
1378
|
-
}), [
|
|
1379
|
-
t,
|
|
1380
|
-
schemas,
|
|
1381
|
-
referenceSchema
|
|
1382
|
-
]);
|
|
1383
|
-
const propIsNotType = (0, import_react3.useCallback)((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
1384
|
-
if (!fieldSchema) {
|
|
1385
|
-
import_log.log.warn("invalid format", {
|
|
1386
|
-
props
|
|
1387
|
-
}, {
|
|
1388
|
-
F: __dxlog_file3,
|
|
1389
|
-
L: 174,
|
|
1390
|
-
S: void 0,
|
|
1391
|
-
C: (f, a) => f(...a)
|
|
1392
|
-
});
|
|
1393
|
-
return null;
|
|
1394
|
-
}
|
|
1395
|
-
return /* @__PURE__ */ import_react3.default.createElement(Form, {
|
|
1396
|
-
key: field.id,
|
|
1397
|
-
autoFocus: true,
|
|
1398
|
-
values: props,
|
|
1399
|
-
schema: fieldSchema,
|
|
1400
|
-
filter: propIsNotType,
|
|
1401
|
-
sort: [
|
|
1402
|
-
"property",
|
|
1403
|
-
"format"
|
|
1404
|
-
],
|
|
1405
|
-
onValuesChanged: handleValuesChanged,
|
|
1406
|
-
onValidate: handleValidate,
|
|
1407
|
-
onSave: handleSave,
|
|
1408
|
-
onCancel: handleCancel,
|
|
1409
|
-
Custom
|
|
1410
|
-
});
|
|
1411
|
-
};
|
|
1412
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1413
|
-
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1414
|
-
var ViewMetaSchema = import_echo_schema8.S.Struct({
|
|
1415
|
-
name: import_echo_schema8.S.String.annotations({
|
|
1416
|
-
[import_echo_schema8.AST.TitleAnnotationId]: "View"
|
|
1417
|
-
}),
|
|
1418
|
-
typename: import_echo_schema8.Format.URL.annotations({
|
|
1419
|
-
[import_echo_schema8.AST.TitleAnnotationId]: "Typename"
|
|
1420
|
-
})
|
|
1421
|
-
}).pipe(import_echo_schema8.S.mutable);
|
|
1422
|
-
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1423
|
-
const { t } = (0, import_react_ui11.useTranslation)(translationKey);
|
|
1424
|
-
const projection = (0, import_react15.useMemo)(() => new import_schema5.ViewProjection(schema.jsonSchema, view), [
|
|
1425
|
-
schema,
|
|
1426
|
-
view
|
|
1427
|
-
]);
|
|
1428
|
-
const [field, setField] = (0, import_react15.useState)();
|
|
1429
|
-
const viewValues = (0, import_react15.useMemo)(() => {
|
|
1430
|
-
return {
|
|
1431
|
-
name: view.name,
|
|
1432
|
-
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
1433
|
-
// TODO(burdon): Settings should have domain name owned by user.
|
|
1434
|
-
typename: view.query.typename
|
|
1435
|
-
};
|
|
1436
|
-
}, [
|
|
1437
|
-
view
|
|
1438
|
-
]);
|
|
1439
|
-
const handleSelect = (0, import_react15.useCallback)((field2) => {
|
|
1440
|
-
setField((f) => f === field2 ? void 0 : field2);
|
|
1441
|
-
}, []);
|
|
1442
|
-
const handleAdd = (0, import_react15.useCallback)(() => {
|
|
1443
|
-
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1444
|
-
F: __dxlog_file4,
|
|
1445
|
-
L: 76,
|
|
1446
|
-
S: void 0,
|
|
1447
|
-
A: [
|
|
1448
|
-
"!schema.readonly",
|
|
1449
|
-
""
|
|
1450
|
-
]
|
|
1451
|
-
});
|
|
1452
|
-
const field2 = projection.createFieldProjection();
|
|
1453
|
-
setField(field2);
|
|
1454
|
-
}, [
|
|
1455
|
-
schema,
|
|
1456
|
-
view
|
|
1457
|
-
]);
|
|
1458
|
-
const handleUpdate = (0, import_react15.useCallback)(({ name, typename }) => {
|
|
1459
|
-
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1460
|
-
F: __dxlog_file4,
|
|
1461
|
-
L: 83,
|
|
1462
|
-
S: void 0,
|
|
1463
|
-
A: [
|
|
1464
|
-
"!schema.readonly",
|
|
1465
|
-
""
|
|
1466
|
-
]
|
|
1467
|
-
});
|
|
1468
|
-
requestAnimationFrame(() => {
|
|
1469
|
-
if (view.name !== name) {
|
|
1470
|
-
view.name = name;
|
|
1471
|
-
}
|
|
1472
|
-
if (view.query.typename !== typename) {
|
|
1473
|
-
onTypenameChanged?.(typename);
|
|
1474
|
-
}
|
|
1475
|
-
});
|
|
1476
|
-
}, [
|
|
1477
|
-
schema,
|
|
1478
|
-
view,
|
|
1479
|
-
onTypenameChanged
|
|
1480
|
-
]);
|
|
1481
|
-
const handleDelete = (0, import_react15.useCallback)((fieldId) => {
|
|
1482
|
-
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1483
|
-
F: __dxlog_file4,
|
|
1484
|
-
L: 99,
|
|
1485
|
-
S: void 0,
|
|
1486
|
-
A: [
|
|
1487
|
-
"!schema.readonly",
|
|
1488
|
-
""
|
|
1489
|
-
]
|
|
1490
|
-
});
|
|
1491
|
-
if (fieldId === field?.id) {
|
|
1492
|
-
setField(void 0);
|
|
1493
|
-
}
|
|
1494
|
-
onDelete?.(fieldId);
|
|
1495
|
-
}, [
|
|
1496
|
-
schema,
|
|
1497
|
-
field,
|
|
1498
|
-
onDelete
|
|
1499
|
-
]);
|
|
1500
|
-
const handleMove = (0, import_react15.useCallback)((fromIndex, toIndex) => {
|
|
1501
|
-
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1502
|
-
F: __dxlog_file4,
|
|
1503
|
-
L: 111,
|
|
1504
|
-
S: void 0,
|
|
1505
|
-
A: [
|
|
1506
|
-
"!schema.readonly",
|
|
1507
|
-
""
|
|
1508
|
-
]
|
|
1509
|
-
});
|
|
1510
|
-
const fields = [
|
|
1511
|
-
...view.fields
|
|
1512
|
-
];
|
|
1513
|
-
const [moved] = fields.splice(fromIndex, 1);
|
|
1514
|
-
fields.splice(toIndex, 0, moved);
|
|
1515
|
-
view.fields = fields;
|
|
1516
|
-
}, [
|
|
1517
|
-
schema,
|
|
1518
|
-
view.fields
|
|
1519
|
-
]);
|
|
1520
|
-
const handleClose = (0, import_react15.useCallback)(() => setField(void 0), []);
|
|
1521
|
-
const hiddenProperties = projection.getHiddenProperties();
|
|
1522
|
-
const handleHide = (0, import_react15.useCallback)((fieldId) => {
|
|
1523
|
-
setField(void 0);
|
|
1524
|
-
projection.hideFieldProjection(fieldId);
|
|
1525
|
-
}, [
|
|
1526
|
-
projection
|
|
1527
|
-
]);
|
|
1528
|
-
const handleShow = (0, import_react15.useCallback)((property) => {
|
|
1529
|
-
setField(void 0);
|
|
1530
|
-
projection.showFieldProjection(property);
|
|
1531
|
-
}, [
|
|
1532
|
-
projection
|
|
1533
|
-
]);
|
|
1534
|
-
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1535
|
-
role: "none",
|
|
1536
|
-
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1537
|
-
}, /* @__PURE__ */ import_react15.default.createElement(Form, {
|
|
1538
|
-
autoSave: true,
|
|
1539
|
-
schema: ViewMetaSchema,
|
|
1540
|
-
values: viewValues,
|
|
1541
|
-
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1542
|
-
}), /* @__PURE__ */ import_react15.default.createElement("div", null, /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1543
|
-
role: "none",
|
|
1544
|
-
className: "p-2"
|
|
1545
|
-
}, /* @__PURE__ */ import_react15.default.createElement("label", {
|
|
1546
|
-
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1547
|
-
}, t("fields label"))), /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.Root, {
|
|
1548
|
-
items: view.fields,
|
|
1549
|
-
isItem: import_echo_schema8.S.is(import_schema5.FieldSchema),
|
|
1550
|
-
getId: (field2) => field2.id,
|
|
1551
|
-
onMove: schema.readonly ? void 0 : handleMove
|
|
1552
|
-
}, ({ items: fields }) => /* @__PURE__ */ import_react15.default.createElement(import_react15.default.Fragment, null, showHeading && /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1553
|
-
role: "heading",
|
|
1554
|
-
className: grid
|
|
1555
|
-
}, /* @__PURE__ */ import_react15.default.createElement("div", null), /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1556
|
-
className: "flex items-center text-sm"
|
|
1557
|
-
}, t("field path label"))), /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1558
|
-
role: "list",
|
|
1559
|
-
className: "flex flex-col w-full"
|
|
1560
|
-
}, fields?.map((field2) => /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.Item, {
|
|
1561
|
-
key: field2.id,
|
|
1562
|
-
item: field2,
|
|
1563
|
-
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1564
|
-
}, /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1565
|
-
onClick: () => handleSelect(field2)
|
|
1566
|
-
}, field2.path), /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1567
|
-
className: "flex items-center gap-2 -ml-4"
|
|
1568
|
-
}, /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1569
|
-
icon: "ph--eye-slash--regular",
|
|
1570
|
-
disabled: view.fields.length <= 1,
|
|
1571
|
-
onClick: () => handleHide(field2.id)
|
|
1572
|
-
}), !schema.readonly && /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1573
|
-
icon: "ph--trash--regular",
|
|
1574
|
-
disabled: view.fields.length <= 1,
|
|
1575
|
-
onClick: () => handleDelete(field2.id)
|
|
1576
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react15.default.createElement("div", null, /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1577
|
-
role: "none",
|
|
1578
|
-
className: "p-2"
|
|
1579
|
-
}, /* @__PURE__ */ import_react15.default.createElement("label", {
|
|
1580
|
-
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1581
|
-
}, t("hidden fields label"))), /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.Root, {
|
|
1582
|
-
items: hiddenProperties,
|
|
1583
|
-
isItem: (item) => typeof item === "string",
|
|
1584
|
-
getId: (property) => property
|
|
1585
|
-
}, ({ items: properties }) => /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1586
|
-
role: "list",
|
|
1587
|
-
className: "flex flex-col w-full"
|
|
1588
|
-
}, properties?.map((property) => /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.Item, {
|
|
1589
|
-
key: property,
|
|
1590
|
-
item: property,
|
|
1591
|
-
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1592
|
-
}, /* @__PURE__ */ import_react15.default.createElement("div", null), /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.ItemTitle, null, property), /* @__PURE__ */ import_react15.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1593
|
-
icon: "ph--eye--regular",
|
|
1594
|
-
onClick: () => handleShow(property)
|
|
1595
|
-
}))))))), field && /* @__PURE__ */ import_react15.default.createElement(FieldEditor, {
|
|
1596
|
-
key: field.id,
|
|
1597
|
-
view,
|
|
1598
|
-
projection,
|
|
1599
|
-
field,
|
|
1600
|
-
registry,
|
|
1601
|
-
onSave: handleClose
|
|
1602
|
-
}), !readonly && !field && /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1603
|
-
className: "flex p-2 justify-center"
|
|
1604
|
-
}, /* @__PURE__ */ import_react15.default.createElement(import_react_ui11.IconButton, {
|
|
1605
|
-
icon: "ph--plus--regular",
|
|
1606
|
-
label: t("button add property"),
|
|
1607
|
-
onClick: schema.readonly ? void 0 : handleAdd,
|
|
1608
|
-
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
1609
|
-
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
1610
|
-
})));
|
|
1611
|
-
};
|
|
1612
|
-
var parseValue = ({ type, format, value }) => {
|
|
1613
|
-
if (value === void 0 || value === null || value === "") {
|
|
1614
|
-
return void 0;
|
|
1615
|
-
}
|
|
1616
|
-
const parseScalar = (type2) => {
|
|
1617
|
-
switch (type2) {
|
|
1618
|
-
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1619
|
-
if (typeof value === "string") {
|
|
1620
|
-
const lowercaseValue = value.toLowerCase();
|
|
1621
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1622
|
-
return false;
|
|
1623
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1624
|
-
return true;
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
return Boolean(value);
|
|
1628
|
-
}
|
|
1629
|
-
case import_echo_schema9.TypeEnum.Number: {
|
|
1630
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1631
|
-
const num = Number(cleaned);
|
|
1632
|
-
return Number.isNaN(num) ? null : num;
|
|
1633
|
-
}
|
|
1634
|
-
case import_echo_schema9.TypeEnum.String:
|
|
1635
|
-
case import_echo_schema9.TypeEnum.Ref:
|
|
1636
|
-
return String(value);
|
|
1637
|
-
default: {
|
|
1638
|
-
return value;
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
};
|
|
1642
|
-
if (!format) {
|
|
1643
|
-
return parseScalar(type);
|
|
1644
|
-
}
|
|
1645
|
-
switch (format) {
|
|
1646
|
-
case import_echo_schema9.FormatEnum.Boolean:
|
|
1647
|
-
return parseScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1648
|
-
case import_echo_schema9.FormatEnum.Number:
|
|
1649
|
-
case import_echo_schema9.FormatEnum.Percent:
|
|
1650
|
-
case import_echo_schema9.FormatEnum.Currency:
|
|
1651
|
-
return parseScalar(import_echo_schema9.TypeEnum.Number);
|
|
1652
|
-
case import_echo_schema9.FormatEnum.String:
|
|
1653
|
-
case import_echo_schema9.FormatEnum.Markdown: {
|
|
1654
|
-
return parseScalar(import_echo_schema9.TypeEnum.String);
|
|
1655
|
-
}
|
|
1656
|
-
case import_echo_schema9.FormatEnum.Ref:
|
|
1657
|
-
throw new Error(`unexpected format: ${import_echo_schema9.FormatEnum.Ref}`);
|
|
1658
|
-
case import_echo_schema9.FormatEnum.DateTime:
|
|
1659
|
-
case import_echo_schema9.FormatEnum.Date:
|
|
1660
|
-
case import_echo_schema9.FormatEnum.Time:
|
|
1661
|
-
case import_echo_schema9.FormatEnum.Timestamp: {
|
|
1662
|
-
const date = new Date(value);
|
|
1663
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1664
|
-
}
|
|
1665
|
-
case import_echo_schema9.FormatEnum.GeoPoint: {
|
|
1666
|
-
if (typeof value === "string") {
|
|
1667
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1668
|
-
const parts = cleaned.split(",");
|
|
1669
|
-
if (parts.length === 2) {
|
|
1670
|
-
const lat = parseFloat(parts[0]);
|
|
1671
|
-
const long = parseFloat(parts[1]);
|
|
1672
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1673
|
-
return import_echo_schema9.GeoLocation.toGeoPoint({
|
|
1674
|
-
latitude: lat,
|
|
1675
|
-
longitude: long
|
|
1676
|
-
});
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
return [
|
|
1681
|
-
0,
|
|
1682
|
-
0
|
|
1683
|
-
];
|
|
1684
|
-
}
|
|
1685
|
-
default: {
|
|
1686
|
-
return value;
|
|
1244
|
+
case import_echo_schema6.FormatEnum.Boolean:
|
|
1245
|
+
return parseScalar(import_echo_schema6.TypeEnum.Boolean);
|
|
1246
|
+
case import_echo_schema6.FormatEnum.Number:
|
|
1247
|
+
case import_echo_schema6.FormatEnum.Percent:
|
|
1248
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1249
|
+
return parseScalar(import_echo_schema6.TypeEnum.Number);
|
|
1250
|
+
case import_echo_schema6.FormatEnum.String:
|
|
1251
|
+
case import_echo_schema6.FormatEnum.Markdown: {
|
|
1252
|
+
return parseScalar(import_echo_schema6.TypeEnum.String);
|
|
1253
|
+
}
|
|
1254
|
+
case import_echo_schema6.FormatEnum.Ref:
|
|
1255
|
+
throw new Error(`unexpected format: ${import_echo_schema6.FormatEnum.Ref}`);
|
|
1256
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1257
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1258
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1259
|
+
case import_echo_schema6.FormatEnum.Timestamp: {
|
|
1260
|
+
const date = new Date(value);
|
|
1261
|
+
return isNaN(date.getTime()) ? null : date;
|
|
1262
|
+
}
|
|
1263
|
+
case import_echo_schema6.FormatEnum.GeoPoint: {
|
|
1264
|
+
if (typeof value === "string") {
|
|
1265
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1266
|
+
const parts = cleaned.split(",");
|
|
1267
|
+
if (parts.length === 2) {
|
|
1268
|
+
const lat = parseFloat(parts[0]);
|
|
1269
|
+
const long = parseFloat(parts[1]);
|
|
1270
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1271
|
+
return import_echo_schema6.GeoLocation.toGeoPoint({
|
|
1272
|
+
latitude: lat,
|
|
1273
|
+
longitude: long
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return [
|
|
1279
|
+
0,
|
|
1280
|
+
0
|
|
1281
|
+
];
|
|
1282
|
+
}
|
|
1283
|
+
default: {
|
|
1284
|
+
return value;
|
|
1687
1285
|
}
|
|
1688
1286
|
}
|
|
1689
1287
|
};
|
|
1690
1288
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1691
1289
|
if (!format) {
|
|
1692
1290
|
switch (type) {
|
|
1693
|
-
case
|
|
1291
|
+
case import_echo_schema6.TypeEnum.Number:
|
|
1694
1292
|
return [
|
|
1695
1293
|
"text-right",
|
|
1696
1294
|
"font-mono"
|
|
1697
1295
|
];
|
|
1698
|
-
case
|
|
1296
|
+
case import_echo_schema6.TypeEnum.Boolean:
|
|
1699
1297
|
return [
|
|
1700
1298
|
"text-right",
|
|
1701
1299
|
"font-mono"
|
|
1702
1300
|
];
|
|
1703
|
-
case
|
|
1301
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1704
1302
|
return void 0;
|
|
1705
|
-
case
|
|
1303
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1706
1304
|
return void 0;
|
|
1707
1305
|
default: {
|
|
1708
1306
|
return void 0;
|
|
@@ -1710,23 +1308,23 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1710
1308
|
}
|
|
1711
1309
|
}
|
|
1712
1310
|
switch (format) {
|
|
1713
|
-
case
|
|
1311
|
+
case import_echo_schema6.FormatEnum.Markdown:
|
|
1714
1312
|
return void 0;
|
|
1715
|
-
case
|
|
1716
|
-
case
|
|
1717
|
-
case
|
|
1718
|
-
case
|
|
1719
|
-
case
|
|
1313
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1314
|
+
case import_echo_schema6.FormatEnum.Timestamp:
|
|
1315
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1316
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1317
|
+
case import_echo_schema6.FormatEnum.Duration:
|
|
1720
1318
|
return [
|
|
1721
1319
|
"font-mono",
|
|
1722
1320
|
"text-right"
|
|
1723
1321
|
];
|
|
1724
|
-
case
|
|
1322
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1725
1323
|
return [
|
|
1726
1324
|
"text-right"
|
|
1727
1325
|
];
|
|
1728
|
-
case
|
|
1729
|
-
case
|
|
1326
|
+
case import_echo_schema6.FormatEnum.JSON:
|
|
1327
|
+
case import_echo_schema6.FormatEnum.DID:
|
|
1730
1328
|
return [
|
|
1731
1329
|
"font-mono"
|
|
1732
1330
|
];
|
|
@@ -1741,12 +1339,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1741
1339
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1742
1340
|
const formatScalar = (type2) => {
|
|
1743
1341
|
switch (type2) {
|
|
1744
|
-
case
|
|
1342
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1745
1343
|
return value.toLocaleString().toUpperCase();
|
|
1746
|
-
case
|
|
1344
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1747
1345
|
return value.toLocaleString(locale);
|
|
1748
|
-
case
|
|
1749
|
-
case
|
|
1346
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1347
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1750
1348
|
return String(value);
|
|
1751
1349
|
default: {
|
|
1752
1350
|
return String(value);
|
|
@@ -1757,20 +1355,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1757
1355
|
return formatScalar(type);
|
|
1758
1356
|
}
|
|
1759
1357
|
switch (format) {
|
|
1760
|
-
case
|
|
1761
|
-
return formatScalar(
|
|
1358
|
+
case import_echo_schema7.FormatEnum.Boolean: {
|
|
1359
|
+
return formatScalar(import_echo_schema7.TypeEnum.Boolean);
|
|
1762
1360
|
}
|
|
1763
|
-
case
|
|
1764
|
-
return formatScalar(
|
|
1361
|
+
case import_echo_schema7.FormatEnum.Number: {
|
|
1362
|
+
return formatScalar(import_echo_schema7.TypeEnum.Number);
|
|
1765
1363
|
}
|
|
1766
|
-
case
|
|
1767
|
-
case
|
|
1768
|
-
return formatScalar(
|
|
1364
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1365
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1366
|
+
return formatScalar(import_echo_schema7.TypeEnum.String);
|
|
1769
1367
|
}
|
|
1770
|
-
case
|
|
1368
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1771
1369
|
return `${value * 100}%`;
|
|
1772
1370
|
}
|
|
1773
|
-
case
|
|
1371
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1774
1372
|
return value.toLocaleString(locale, {
|
|
1775
1373
|
style: "currency",
|
|
1776
1374
|
currency: "USD",
|
|
@@ -1778,21 +1376,33 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1778
1376
|
maximumFractionDigits: 2
|
|
1779
1377
|
});
|
|
1780
1378
|
}
|
|
1781
|
-
case
|
|
1782
|
-
|
|
1379
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1380
|
+
try {
|
|
1381
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1382
|
+
} catch (error) {
|
|
1383
|
+
return "Invalid Date";
|
|
1384
|
+
}
|
|
1783
1385
|
}
|
|
1784
|
-
case
|
|
1785
|
-
|
|
1386
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1387
|
+
try {
|
|
1388
|
+
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
return "Invalid Time";
|
|
1391
|
+
}
|
|
1786
1392
|
}
|
|
1787
|
-
case
|
|
1788
|
-
|
|
1393
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1394
|
+
try {
|
|
1395
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1396
|
+
} catch (error) {
|
|
1397
|
+
return "Invalid DateTime";
|
|
1398
|
+
}
|
|
1789
1399
|
}
|
|
1790
|
-
case
|
|
1400
|
+
case import_echo_schema7.FormatEnum.GeoPoint: {
|
|
1791
1401
|
if (value === null || value === void 0) {
|
|
1792
1402
|
return "";
|
|
1793
1403
|
}
|
|
1794
1404
|
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1795
|
-
const { latitude, longitude } =
|
|
1405
|
+
const { latitude, longitude } = import_echo_schema7.GeoLocation.fromGeoPoint(value);
|
|
1796
1406
|
return `${latitude},${longitude}`;
|
|
1797
1407
|
}
|
|
1798
1408
|
return String(value);
|
|
@@ -1808,10 +1418,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1808
1418
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1809
1419
|
const formatScalar = (type2) => {
|
|
1810
1420
|
switch (type2) {
|
|
1811
|
-
case
|
|
1812
|
-
case
|
|
1813
|
-
case
|
|
1814
|
-
case
|
|
1421
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1422
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1423
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1424
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1815
1425
|
return String(value);
|
|
1816
1426
|
default:
|
|
1817
1427
|
return String(value);
|
|
@@ -1821,36 +1431,36 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1821
1431
|
return formatScalar(type);
|
|
1822
1432
|
}
|
|
1823
1433
|
switch (format) {
|
|
1824
|
-
case
|
|
1825
|
-
case
|
|
1826
|
-
case
|
|
1827
|
-
case
|
|
1434
|
+
case import_echo_schema7.FormatEnum.Boolean:
|
|
1435
|
+
case import_echo_schema7.FormatEnum.Number:
|
|
1436
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1437
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1828
1438
|
return formatScalar(type);
|
|
1829
1439
|
}
|
|
1830
|
-
case
|
|
1440
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1831
1441
|
return String(value * 100);
|
|
1832
1442
|
}
|
|
1833
|
-
case
|
|
1443
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1834
1444
|
return String(value);
|
|
1835
1445
|
}
|
|
1836
|
-
case
|
|
1446
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1837
1447
|
const date = new Date(value);
|
|
1838
1448
|
return date.toISOString();
|
|
1839
1449
|
}
|
|
1840
|
-
case
|
|
1450
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1841
1451
|
const date = new Date(value);
|
|
1842
1452
|
return date.toISOString().split("T")[0];
|
|
1843
1453
|
}
|
|
1844
|
-
case
|
|
1454
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1845
1455
|
const date = new Date(value);
|
|
1846
1456
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1847
1457
|
}
|
|
1848
|
-
case
|
|
1458
|
+
case import_echo_schema7.FormatEnum.GeoPoint: {
|
|
1849
1459
|
if (value === null || value === void 0) {
|
|
1850
1460
|
return "";
|
|
1851
1461
|
}
|
|
1852
1462
|
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1853
|
-
const { latitude, longitude } =
|
|
1463
|
+
const { latitude, longitude } = import_echo_schema7.GeoLocation.fromGeoPoint(value);
|
|
1854
1464
|
return `${latitude},${longitude}`;
|
|
1855
1465
|
}
|
|
1856
1466
|
return String(value);
|
|
@@ -1860,14 +1470,901 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1860
1470
|
}
|
|
1861
1471
|
}
|
|
1862
1472
|
};
|
|
1473
|
+
var findArrayElementType = (ast) => {
|
|
1474
|
+
const tupleType = (0, import_effect10.findNode)(ast, import_effect9.SchemaAST.isTupleType);
|
|
1475
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
1476
|
+
return elementType;
|
|
1477
|
+
};
|
|
1478
|
+
var getRefProps = (property) => {
|
|
1479
|
+
const { ast, format, array } = property;
|
|
1480
|
+
if (format === import_echo_schema8.FormatEnum.Ref) {
|
|
1481
|
+
return {
|
|
1482
|
+
ast,
|
|
1483
|
+
isArray: false
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
if (array) {
|
|
1487
|
+
const elementType = findArrayElementType(ast);
|
|
1488
|
+
if (elementType) {
|
|
1489
|
+
const annotation = (0, import_effect8.findAnnotation)(elementType, import_echo_schema8.ReferenceAnnotationId);
|
|
1490
|
+
if (annotation) {
|
|
1491
|
+
return {
|
|
1492
|
+
ast: elementType,
|
|
1493
|
+
isArray: true
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return void 0;
|
|
1499
|
+
};
|
|
1500
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
1501
|
+
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1502
|
+
var _effect = (0, import_tracking13.useSignals)();
|
|
1503
|
+
try {
|
|
1504
|
+
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1505
|
+
const { ast, name, type, title } = property;
|
|
1506
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
1507
|
+
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1508
|
+
F: __dxlog_file3,
|
|
1509
|
+
L: 36,
|
|
1510
|
+
S: void 0,
|
|
1511
|
+
A: [
|
|
1512
|
+
"Array.isArray(values)",
|
|
1513
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1514
|
+
]
|
|
1515
|
+
});
|
|
1516
|
+
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
1517
|
+
const elementType = findArrayElementType(ast);
|
|
1518
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1519
|
+
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
1520
|
+
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_effect6.SchemaAST.isTypeLiteral);
|
|
1521
|
+
if (!typeLiteral) {
|
|
1522
|
+
return {};
|
|
1523
|
+
}
|
|
1524
|
+
return Object.fromEntries((0, import_schema4.getSchemaProperties)(typeLiteral, {}).map((prop) => [
|
|
1525
|
+
prop.name,
|
|
1526
|
+
prop.defaultValue
|
|
1527
|
+
]));
|
|
1528
|
+
};
|
|
1529
|
+
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : import_effect7.SimpleType.getDefaultValue(type);
|
|
1530
|
+
const handleAdd = (0, import_react16.useCallback)(() => {
|
|
1531
|
+
inputProps.onValueChange(type, [
|
|
1532
|
+
...values,
|
|
1533
|
+
getDefaultValue()
|
|
1534
|
+
]);
|
|
1535
|
+
}, [
|
|
1536
|
+
type,
|
|
1537
|
+
elementType,
|
|
1538
|
+
inputProps,
|
|
1539
|
+
values
|
|
1540
|
+
]);
|
|
1541
|
+
const handleRemove = (0, import_react16.useCallback)((index) => {
|
|
1542
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
1543
|
+
inputProps.onValueChange(type, newValues);
|
|
1544
|
+
}, [
|
|
1545
|
+
type,
|
|
1546
|
+
inputProps,
|
|
1547
|
+
values
|
|
1548
|
+
]);
|
|
1549
|
+
if (!elementType) {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
return readonly && values.length < 1 ? null : /* @__PURE__ */ import_react16.default.createElement(import_react16.default.Fragment, null, /* @__PURE__ */ import_react16.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1553
|
+
role: "none",
|
|
1554
|
+
className: readonly ? "flex flex-wrap gap-1 mlb-1" : values.length > 0 ? "grid gap-1 grid-cols-[1fr_min-content] mlb-1" : "hidden"
|
|
1555
|
+
}, values.map((_value, index) => {
|
|
1556
|
+
const field = /* @__PURE__ */ import_react16.default.createElement(FormField, {
|
|
1557
|
+
property: {
|
|
1558
|
+
...property,
|
|
1559
|
+
array: false,
|
|
1560
|
+
ast: elementType
|
|
1561
|
+
},
|
|
1562
|
+
path: [
|
|
1563
|
+
...path ?? [],
|
|
1564
|
+
index
|
|
1565
|
+
],
|
|
1566
|
+
readonly,
|
|
1567
|
+
inline: true,
|
|
1568
|
+
Custom,
|
|
1569
|
+
lookupComponent
|
|
1570
|
+
});
|
|
1571
|
+
return readonly ? field : /* @__PURE__ */ import_react16.default.createElement(import_react16.Fragment, {
|
|
1572
|
+
key: index
|
|
1573
|
+
}, /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1574
|
+
role: "none"
|
|
1575
|
+
}, field), /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1576
|
+
icon: "ph--trash--regular",
|
|
1577
|
+
iconOnly: true,
|
|
1578
|
+
label: t("button remove"),
|
|
1579
|
+
onClick: () => handleRemove(index),
|
|
1580
|
+
classNames: "self-center"
|
|
1581
|
+
}));
|
|
1582
|
+
})), !readonly && /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1583
|
+
classNames: "is-full mlb-1 flex",
|
|
1584
|
+
icon: "ph--plus--regular",
|
|
1585
|
+
label: t("add field"),
|
|
1586
|
+
onClick: handleAdd
|
|
1587
|
+
}));
|
|
1588
|
+
} finally {
|
|
1589
|
+
_effect.f();
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1593
|
+
var _effect = (0, import_tracking14.useSignals)();
|
|
1594
|
+
try {
|
|
1595
|
+
const { t } = (0, import_react_ui11.useTranslation)(translationKey);
|
|
1596
|
+
const refTypeInfo = (0, import_react17.useMemo)(() => ast ? (0, import_effect11.findAnnotation)(ast, import_echo_schema9.ReferenceAnnotationId) : void 0, [
|
|
1597
|
+
ast
|
|
1598
|
+
]);
|
|
1599
|
+
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1600
|
+
refTypeInfo,
|
|
1601
|
+
onQueryRefOptions
|
|
1602
|
+
});
|
|
1603
|
+
if (refTypeInfo && refTypeInfo?.typename === (0, import_echo_schema9.getTypeAnnotation)(import_echo_schema9.Expando)?.typename || !onQueryRefOptions) {
|
|
1604
|
+
return /* @__PURE__ */ import_react17.default.createElement(RefFieldFallback, {
|
|
1605
|
+
type,
|
|
1606
|
+
label,
|
|
1607
|
+
placeholder,
|
|
1608
|
+
disabled,
|
|
1609
|
+
inputOnly,
|
|
1610
|
+
getValue: getValue3,
|
|
1611
|
+
onBlur,
|
|
1612
|
+
onValueChange,
|
|
1613
|
+
...restInputProps
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
const handleGetValue = (0, import_react17.useCallback)(() => {
|
|
1617
|
+
const formValue = getValue3();
|
|
1618
|
+
const unknownToRefOption = (val) => {
|
|
1619
|
+
if (import_echo_schema9.Ref.isRef(val)) {
|
|
1620
|
+
const dxnString = val.dxn.toString();
|
|
1621
|
+
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1622
|
+
if (matchingOption) {
|
|
1623
|
+
return matchingOption;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return void 0;
|
|
1627
|
+
};
|
|
1628
|
+
if (array && Array.isArray(formValue)) {
|
|
1629
|
+
return formValue.map(unknownToRefOption).filter(import_util5.isNonNullable) ?? [];
|
|
1630
|
+
}
|
|
1631
|
+
const option = unknownToRefOption(formValue);
|
|
1632
|
+
if (option) {
|
|
1633
|
+
return [
|
|
1634
|
+
option
|
|
1635
|
+
];
|
|
1636
|
+
}
|
|
1637
|
+
return [];
|
|
1638
|
+
}, [
|
|
1639
|
+
getValue3,
|
|
1640
|
+
availableOptions,
|
|
1641
|
+
array
|
|
1642
|
+
]);
|
|
1643
|
+
const handleSearch = (0, import_react17.useCallback)((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1644
|
+
id: option.id,
|
|
1645
|
+
label: option.label,
|
|
1646
|
+
hue: option.hue
|
|
1647
|
+
})), [
|
|
1648
|
+
availableOptions
|
|
1649
|
+
]);
|
|
1650
|
+
const handleUpdate = (0, import_react17.useCallback)((ids) => {
|
|
1651
|
+
if (ids.length === 0) {
|
|
1652
|
+
onValueChange("object", void 0);
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
const refs = ids.map((id) => {
|
|
1656
|
+
const item = availableOptions.find((option) => option.id === id);
|
|
1657
|
+
if (item) {
|
|
1658
|
+
const dxn = import_keys2.DXN.parse(item.id);
|
|
1659
|
+
return import_echo_schema9.Ref.fromDXN(dxn);
|
|
1660
|
+
}
|
|
1661
|
+
return null;
|
|
1662
|
+
}).filter(import_util5.isNonNullable);
|
|
1663
|
+
if (array) {
|
|
1664
|
+
onValueChange("object", refs);
|
|
1665
|
+
} else {
|
|
1666
|
+
onValueChange("object", refs[0]);
|
|
1667
|
+
}
|
|
1668
|
+
}, [
|
|
1669
|
+
availableOptions,
|
|
1670
|
+
array,
|
|
1671
|
+
onValueChange
|
|
1672
|
+
]);
|
|
1673
|
+
const tagPickerMode = (0, import_react17.useMemo)(() => array ? "multi-select" : "single-select", [
|
|
1674
|
+
array
|
|
1675
|
+
]);
|
|
1676
|
+
if (!refTypeInfo) {
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
const { status, error } = restInputProps.getStatus();
|
|
1680
|
+
const items = handleGetValue();
|
|
1681
|
+
return disabled && items.length < 1 ? null : /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Root, {
|
|
1682
|
+
validationValence: status
|
|
1683
|
+
}, !inputOnly && /* @__PURE__ */ import_react17.default.createElement(InputHeader, {
|
|
1684
|
+
error
|
|
1685
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Label, null, label)), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1686
|
+
"data-no-submit": true
|
|
1687
|
+
}, disabled ? items.length < 1 ? /* @__PURE__ */ import_react17.default.createElement("p", {
|
|
1688
|
+
className: (0, import_react_ui_theme8.mx)(import_react_ui_theme8.descriptionText, "mbe-2")
|
|
1689
|
+
}, t("empty readonly ref field label")) : items.map((item) => /* @__PURE__ */ import_react17.default.createElement(import_react18.DxRefTag, {
|
|
1690
|
+
key: item.id,
|
|
1691
|
+
refid: item.id,
|
|
1692
|
+
rootclassname: "mie-1",
|
|
1693
|
+
style: {
|
|
1694
|
+
marginInlineEnd: ".25rem"
|
|
1695
|
+
}
|
|
1696
|
+
}, item.label)) : /* @__PURE__ */ import_react17.default.createElement(import_react_ui_tag_picker.TagPicker, {
|
|
1697
|
+
readonly: disabled,
|
|
1698
|
+
items,
|
|
1699
|
+
mode: tagPickerMode,
|
|
1700
|
+
onBlur: (event) => onBlur(event),
|
|
1701
|
+
onUpdate: handleUpdate,
|
|
1702
|
+
onSearch: handleSearch,
|
|
1703
|
+
classNames: "rounded-sm bg-inputSurface p-1.5"
|
|
1704
|
+
})), inputOnly && /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.DescriptionAndValidation, null, error));
|
|
1705
|
+
} finally {
|
|
1706
|
+
_effect.f();
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1710
|
+
var _effect = (0, import_tracking14.useSignals)();
|
|
1711
|
+
try {
|
|
1712
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1713
|
+
const dxn = import_keys2.DXN.tryParse(dxnString);
|
|
1714
|
+
if (dxn) {
|
|
1715
|
+
onValueChange?.("object", import_echo_schema9.Ref.fromDXN(dxn));
|
|
1716
|
+
} else if (dxnString === "") {
|
|
1717
|
+
onValueChange?.("object", void 0);
|
|
1718
|
+
} else {
|
|
1719
|
+
onValueChange?.("string", dxnString);
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
const handleGetValue = () => {
|
|
1723
|
+
const formValue = getValue3();
|
|
1724
|
+
if (typeof formValue === "string") {
|
|
1725
|
+
return formValue;
|
|
1726
|
+
}
|
|
1727
|
+
if (import_echo_schema9.Ref.isRef(formValue)) {
|
|
1728
|
+
return formValue.dxn.toString();
|
|
1729
|
+
}
|
|
1730
|
+
return void 0;
|
|
1731
|
+
};
|
|
1732
|
+
return /* @__PURE__ */ import_react17.default.createElement(TextInput, {
|
|
1733
|
+
type,
|
|
1734
|
+
label,
|
|
1735
|
+
disabled,
|
|
1736
|
+
placeholder,
|
|
1737
|
+
inputOnly,
|
|
1738
|
+
getValue: handleGetValue,
|
|
1739
|
+
onValueChange: handleOnValueChange,
|
|
1740
|
+
...restInputProps
|
|
1741
|
+
});
|
|
1742
|
+
} finally {
|
|
1743
|
+
_effect.f();
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
var getInputComponent = (type, format) => {
|
|
1747
|
+
switch (format) {
|
|
1748
|
+
case import_echo_schema10.FormatEnum.GeoPoint:
|
|
1749
|
+
return GeoPointInput;
|
|
1750
|
+
case import_echo_schema10.FormatEnum.Markdown:
|
|
1751
|
+
return MarkdownInput;
|
|
1752
|
+
}
|
|
1753
|
+
switch (type) {
|
|
1754
|
+
case "string":
|
|
1755
|
+
return TextInput;
|
|
1756
|
+
case "number":
|
|
1757
|
+
return NumberInput;
|
|
1758
|
+
case "boolean":
|
|
1759
|
+
return BooleanInput;
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1763
|
+
var _effect = (0, import_tracking12.useSignals)();
|
|
1764
|
+
try {
|
|
1765
|
+
const inputProps = useInputProps(path);
|
|
1766
|
+
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1767
|
+
const label = (0, import_react15.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1768
|
+
title,
|
|
1769
|
+
name
|
|
1770
|
+
]);
|
|
1771
|
+
const placeholder = (0, import_react15.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1772
|
+
examples,
|
|
1773
|
+
description
|
|
1774
|
+
]);
|
|
1775
|
+
const FoundComponent = lookupComponent?.({
|
|
1776
|
+
prop: name,
|
|
1777
|
+
schema: import_effect4.Schema.make(ast),
|
|
1778
|
+
inputProps: {
|
|
1779
|
+
type,
|
|
1780
|
+
format,
|
|
1781
|
+
label,
|
|
1782
|
+
disabled: readonly,
|
|
1783
|
+
placeholder,
|
|
1784
|
+
...inputProps
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
if (FoundComponent) {
|
|
1788
|
+
return FoundComponent;
|
|
1789
|
+
}
|
|
1790
|
+
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1791
|
+
const CustomComponent = Custom?.[jsonPath];
|
|
1792
|
+
if (CustomComponent) {
|
|
1793
|
+
return /* @__PURE__ */ import_react15.default.createElement(CustomComponent, {
|
|
1794
|
+
type,
|
|
1795
|
+
format,
|
|
1796
|
+
label,
|
|
1797
|
+
inputOnly: inline,
|
|
1798
|
+
placeholder,
|
|
1799
|
+
disabled: readonly,
|
|
1800
|
+
...inputProps
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
const refProps = getRefProps(property);
|
|
1804
|
+
if (refProps) {
|
|
1805
|
+
return /* @__PURE__ */ import_react15.default.createElement(RefField, {
|
|
1806
|
+
ast: refProps.ast,
|
|
1807
|
+
array: refProps.isArray,
|
|
1808
|
+
type,
|
|
1809
|
+
format,
|
|
1810
|
+
label,
|
|
1811
|
+
placeholder,
|
|
1812
|
+
disabled: readonly,
|
|
1813
|
+
inputOnly: inline,
|
|
1814
|
+
onQueryRefOptions,
|
|
1815
|
+
...inputProps
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
if (array) {
|
|
1819
|
+
return /* @__PURE__ */ import_react15.default.createElement(ArrayField, {
|
|
1820
|
+
property,
|
|
1821
|
+
path,
|
|
1822
|
+
inputProps,
|
|
1823
|
+
readonly,
|
|
1824
|
+
Custom
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
const InputComponent = getInputComponent(type, format);
|
|
1828
|
+
if (InputComponent) {
|
|
1829
|
+
return /* @__PURE__ */ import_react15.default.createElement(InputComponent, {
|
|
1830
|
+
type,
|
|
1831
|
+
format,
|
|
1832
|
+
label,
|
|
1833
|
+
inputOnly: inline,
|
|
1834
|
+
placeholder,
|
|
1835
|
+
disabled: readonly,
|
|
1836
|
+
...inputProps
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
if (options) {
|
|
1840
|
+
return /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1841
|
+
type,
|
|
1842
|
+
format,
|
|
1843
|
+
disabled: readonly,
|
|
1844
|
+
inputOnly: inline,
|
|
1845
|
+
label,
|
|
1846
|
+
options: options.map((option) => ({
|
|
1847
|
+
value: option,
|
|
1848
|
+
label: String(option)
|
|
1849
|
+
})),
|
|
1850
|
+
placeholder,
|
|
1851
|
+
...inputProps
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
if (type === "object") {
|
|
1855
|
+
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1856
|
+
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_effect4.SchemaAST.isTypeLiteral);
|
|
1857
|
+
if (typeLiteral) {
|
|
1858
|
+
return /* @__PURE__ */ import_react15.default.createElement(import_react15.default.Fragment, null, !inline && /* @__PURE__ */ import_react15.default.createElement("h3", {
|
|
1859
|
+
className: "text-lg mbs-2 mbe-1 first:mbs-0"
|
|
1860
|
+
}, label), /* @__PURE__ */ import_react15.default.createElement(FormFields, {
|
|
1861
|
+
schema: import_effect4.Schema.make(typeLiteral),
|
|
1862
|
+
path,
|
|
1863
|
+
readonly,
|
|
1864
|
+
onQueryRefOptions,
|
|
1865
|
+
Custom,
|
|
1866
|
+
lookupComponent
|
|
1867
|
+
}));
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
return null;
|
|
1871
|
+
} finally {
|
|
1872
|
+
_effect.f();
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
var FormFields = ({ classNames, Custom, schema, path, filter, sort, readonly, lookupComponent, onQueryRefOptions }) => {
|
|
1876
|
+
var _effect = (0, import_tracking12.useSignals)();
|
|
1877
|
+
try {
|
|
1878
|
+
const values = useFormValues(path);
|
|
1879
|
+
const properties = (0, import_react15.useMemo)(() => {
|
|
1880
|
+
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1881
|
+
const filtered = filter ? filter(props) : props;
|
|
1882
|
+
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
1883
|
+
}, [
|
|
1884
|
+
schema,
|
|
1885
|
+
values,
|
|
1886
|
+
filter,
|
|
1887
|
+
sort
|
|
1888
|
+
]);
|
|
1889
|
+
return (
|
|
1890
|
+
// TODO(burdon): Consistent padding (with composite forms).
|
|
1891
|
+
/* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1892
|
+
role: "form",
|
|
1893
|
+
className: (0, import_react_ui_theme7.mx)("p-2 is-full", classNames)
|
|
1894
|
+
}, properties.map((property) => {
|
|
1895
|
+
return /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1896
|
+
key: property.name,
|
|
1897
|
+
property,
|
|
1898
|
+
path: [
|
|
1899
|
+
...path ?? [],
|
|
1900
|
+
property.name
|
|
1901
|
+
],
|
|
1902
|
+
readonly,
|
|
1903
|
+
onQueryRefOptions,
|
|
1904
|
+
lookupComponent,
|
|
1905
|
+
Custom
|
|
1906
|
+
});
|
|
1907
|
+
}).filter(import_util4.isNotFalsy))
|
|
1908
|
+
);
|
|
1909
|
+
} finally {
|
|
1910
|
+
_effect.f();
|
|
1911
|
+
}
|
|
1912
|
+
};
|
|
1913
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1914
|
+
var _effect = (0, import_tracking9.useSignals)();
|
|
1915
|
+
try {
|
|
1916
|
+
const formRef = (0, import_react9.useRef)(null);
|
|
1917
|
+
const onValid = (0, import_react9.useMemo)(() => autoSave ? onSave : void 0, [
|
|
1918
|
+
autoSave,
|
|
1919
|
+
onSave
|
|
1920
|
+
]);
|
|
1921
|
+
(0, import_react9.useEffect)(() => {
|
|
1922
|
+
if (autoFocus && formRef.current) {
|
|
1923
|
+
const input = formRef.current.querySelector("input");
|
|
1924
|
+
if (input) {
|
|
1925
|
+
input.focus();
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
}, [
|
|
1929
|
+
autoFocus
|
|
1930
|
+
]);
|
|
1931
|
+
return /* @__PURE__ */ import_react9.default.createElement(FormProvider, {
|
|
1932
|
+
formRef,
|
|
1933
|
+
schema,
|
|
1934
|
+
autoSave,
|
|
1935
|
+
initialValues,
|
|
1936
|
+
onValuesChanged,
|
|
1937
|
+
onValidate,
|
|
1938
|
+
onValid,
|
|
1939
|
+
onSave
|
|
1940
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1941
|
+
ref: formRef,
|
|
1942
|
+
role: "none",
|
|
1943
|
+
className: (0, import_react_ui_theme6.mx)("flex flex-col gap-4", classNames),
|
|
1944
|
+
"data-testid": testId
|
|
1945
|
+
}, /* @__PURE__ */ import_react9.default.createElement(FormFields, {
|
|
1946
|
+
schema,
|
|
1947
|
+
path,
|
|
1948
|
+
readonly,
|
|
1949
|
+
filter,
|
|
1950
|
+
sort,
|
|
1951
|
+
onQueryRefOptions,
|
|
1952
|
+
lookupComponent,
|
|
1953
|
+
Custom
|
|
1954
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react9.default.createElement(FormActions, {
|
|
1955
|
+
onCancel,
|
|
1956
|
+
readonly
|
|
1957
|
+
})));
|
|
1958
|
+
} finally {
|
|
1959
|
+
_effect.f();
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1963
|
+
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1964
|
+
var _effect = (0, import_tracking3.useSignals)();
|
|
1965
|
+
try {
|
|
1966
|
+
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
1967
|
+
const [props, setProps] = (0, import_react3.useState)(projection.getFieldProjection(field.id).props);
|
|
1968
|
+
(0, import_react3.useEffect)(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1969
|
+
field,
|
|
1970
|
+
projection
|
|
1971
|
+
]);
|
|
1972
|
+
const [schemas, setSchemas] = (0, import_react3.useState)([]);
|
|
1973
|
+
(0, import_react3.useEffect)(() => {
|
|
1974
|
+
if (!registry) {
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
1978
|
+
fire: true
|
|
1979
|
+
});
|
|
1980
|
+
const t2 = setTimeout(async () => {
|
|
1981
|
+
const schemas2 = await registry.query().run();
|
|
1982
|
+
setSchemas(schemas2);
|
|
1983
|
+
});
|
|
1984
|
+
return () => {
|
|
1985
|
+
clearTimeout(t2);
|
|
1986
|
+
subscription?.();
|
|
1987
|
+
};
|
|
1988
|
+
}, [
|
|
1989
|
+
registry
|
|
1990
|
+
]);
|
|
1991
|
+
const [referenceSchema, setReferenceSchema] = (0, import_react3.useState)();
|
|
1992
|
+
(0, import_react3.useEffect)(() => {
|
|
1993
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1994
|
+
}, [
|
|
1995
|
+
schemas,
|
|
1996
|
+
props?.referenceSchema
|
|
1997
|
+
]);
|
|
1998
|
+
const [{ fieldSchema }, setFieldSchema] = (0, import_react3.useState)({
|
|
1999
|
+
fieldSchema: (0, import_schema.getFormatSchema)(props?.format)
|
|
2000
|
+
});
|
|
2001
|
+
const handleValuesChanged = (0, import_react3.useCallback)((_props) => {
|
|
2002
|
+
setFieldSchema((prev) => {
|
|
2003
|
+
const fieldSchema2 = (0, import_schema.getFormatSchema)(_props.format);
|
|
2004
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
2005
|
+
return prev;
|
|
2006
|
+
}
|
|
2007
|
+
return {
|
|
2008
|
+
fieldSchema: fieldSchema2
|
|
2009
|
+
};
|
|
2010
|
+
});
|
|
2011
|
+
setReferenceSchema((prev) => {
|
|
2012
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
2013
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
2014
|
+
if (newSchema) {
|
|
2015
|
+
return newSchema;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
return prev;
|
|
2019
|
+
});
|
|
2020
|
+
setProps((props2) => {
|
|
2021
|
+
const type = import_echo_schema.formatToType[_props.format];
|
|
2022
|
+
if (props2.type !== type) {
|
|
2023
|
+
return {
|
|
2024
|
+
...props2,
|
|
2025
|
+
..._props,
|
|
2026
|
+
type
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
return _props;
|
|
2030
|
+
});
|
|
2031
|
+
}, [
|
|
2032
|
+
schemas,
|
|
2033
|
+
props.format,
|
|
2034
|
+
props.referenceSchema
|
|
2035
|
+
]);
|
|
2036
|
+
const handleValidate = (0, import_react3.useCallback)(({ property }) => {
|
|
2037
|
+
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
2038
|
+
return [
|
|
2039
|
+
{
|
|
2040
|
+
path: "property",
|
|
2041
|
+
message: `property is not unique: '${property}'`
|
|
2042
|
+
}
|
|
2043
|
+
];
|
|
2044
|
+
}
|
|
2045
|
+
}, [
|
|
2046
|
+
view.fields,
|
|
2047
|
+
field
|
|
2048
|
+
]);
|
|
2049
|
+
const handleSave = (0, import_react3.useCallback)((props2) => {
|
|
2050
|
+
projection.setFieldProjection({
|
|
2051
|
+
field,
|
|
2052
|
+
props: props2
|
|
2053
|
+
});
|
|
2054
|
+
onSave();
|
|
2055
|
+
}, [
|
|
2056
|
+
projection,
|
|
2057
|
+
field,
|
|
2058
|
+
onSave
|
|
2059
|
+
]);
|
|
2060
|
+
const handleCancel = (0, import_react3.useCallback)(() => {
|
|
2061
|
+
requestAnimationFrame(() => onCancel?.());
|
|
2062
|
+
onSave();
|
|
2063
|
+
}, [
|
|
2064
|
+
onSave
|
|
2065
|
+
]);
|
|
2066
|
+
const custom = (0, import_react3.useMemo)(() => ({
|
|
2067
|
+
["format"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
2068
|
+
...props2,
|
|
2069
|
+
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
2070
|
+
value,
|
|
2071
|
+
label: t(`format ${value}`)
|
|
2072
|
+
}))
|
|
2073
|
+
}),
|
|
2074
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
2075
|
+
...props2,
|
|
2076
|
+
options: schemas.map((schema) => ({
|
|
2077
|
+
value: schema.typename
|
|
2078
|
+
}))
|
|
2079
|
+
}),
|
|
2080
|
+
["referencePath"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
2081
|
+
...props2,
|
|
2082
|
+
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
2083
|
+
value: p.name
|
|
2084
|
+
})) : []
|
|
2085
|
+
}),
|
|
2086
|
+
["options"]: (props2) => /* @__PURE__ */ import_react3.default.createElement(SelectOptionInput, props2)
|
|
2087
|
+
}), [
|
|
2088
|
+
t,
|
|
2089
|
+
schemas,
|
|
2090
|
+
referenceSchema
|
|
2091
|
+
]);
|
|
2092
|
+
const propIsNotType = (0, import_react3.useCallback)((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
2093
|
+
if (!fieldSchema) {
|
|
2094
|
+
import_log.log.warn("invalid format", {
|
|
2095
|
+
props
|
|
2096
|
+
}, {
|
|
2097
|
+
F: __dxlog_file4,
|
|
2098
|
+
L: 175,
|
|
2099
|
+
S: void 0,
|
|
2100
|
+
C: (f, a) => f(...a)
|
|
2101
|
+
});
|
|
2102
|
+
return null;
|
|
2103
|
+
}
|
|
2104
|
+
return /* @__PURE__ */ import_react3.default.createElement(Form, {
|
|
2105
|
+
key: field.id,
|
|
2106
|
+
autoFocus: true,
|
|
2107
|
+
values: props,
|
|
2108
|
+
schema: fieldSchema,
|
|
2109
|
+
filter: propIsNotType,
|
|
2110
|
+
sort: [
|
|
2111
|
+
"property",
|
|
2112
|
+
"format"
|
|
2113
|
+
],
|
|
2114
|
+
onValuesChanged: handleValuesChanged,
|
|
2115
|
+
onValidate: handleValidate,
|
|
2116
|
+
onSave: handleSave,
|
|
2117
|
+
onCancel: handleCancel,
|
|
2118
|
+
Custom: custom
|
|
2119
|
+
});
|
|
2120
|
+
} finally {
|
|
2121
|
+
_effect.f();
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2125
|
+
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
2126
|
+
var ViewMetaSchema = import_effect12.Schema.Struct({
|
|
2127
|
+
name: import_effect12.Schema.String.annotations({
|
|
2128
|
+
title: "View"
|
|
2129
|
+
}),
|
|
2130
|
+
typename: import_echo_schema11.Format.URL.annotations({
|
|
2131
|
+
title: "Typename"
|
|
2132
|
+
})
|
|
2133
|
+
}).pipe(import_effect12.Schema.mutable);
|
|
2134
|
+
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
2135
|
+
var _effect = (0, import_tracking15.useSignals)();
|
|
2136
|
+
try {
|
|
2137
|
+
const { t } = (0, import_react_ui12.useTranslation)(translationKey);
|
|
2138
|
+
const projection = (0, import_react19.useMemo)(() => {
|
|
2139
|
+
const jsonSchema = schema instanceof import_echo_schema11.EchoSchema ? schema.jsonSchema : (0, import_echo_schema11.toJsonSchema)(schema);
|
|
2140
|
+
return new import_schema5.ViewProjection(jsonSchema, view);
|
|
2141
|
+
}, [
|
|
2142
|
+
schema,
|
|
2143
|
+
view
|
|
2144
|
+
]);
|
|
2145
|
+
const [field, setField] = (0, import_react19.useState)();
|
|
2146
|
+
const immutable = readonly || !(0, import_echo_schema11.isMutable)(schema);
|
|
2147
|
+
const viewValues = (0, import_react19.useMemo)(() => {
|
|
2148
|
+
return {
|
|
2149
|
+
name: view.name,
|
|
2150
|
+
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
2151
|
+
// TODO(burdon): Settings should have domain name owned by user.
|
|
2152
|
+
typename: view.query.typename
|
|
2153
|
+
};
|
|
2154
|
+
}, [
|
|
2155
|
+
view
|
|
2156
|
+
]);
|
|
2157
|
+
const handleSelect = (0, import_react19.useCallback)((field2) => {
|
|
2158
|
+
if (immutable) {
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
setField((f) => f === field2 ? void 0 : field2);
|
|
2162
|
+
}, [
|
|
2163
|
+
immutable
|
|
2164
|
+
]);
|
|
2165
|
+
const handleAdd = (0, import_react19.useCallback)(() => {
|
|
2166
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2167
|
+
F: __dxlog_file5,
|
|
2168
|
+
L: 88,
|
|
2169
|
+
S: void 0,
|
|
2170
|
+
A: [
|
|
2171
|
+
"!immutable",
|
|
2172
|
+
""
|
|
2173
|
+
]
|
|
2174
|
+
});
|
|
2175
|
+
const field2 = projection.createFieldProjection();
|
|
2176
|
+
setField(field2);
|
|
2177
|
+
}, [
|
|
2178
|
+
schema,
|
|
2179
|
+
view
|
|
2180
|
+
]);
|
|
2181
|
+
const handleUpdate = (0, import_react19.useCallback)(({ name, typename }) => {
|
|
2182
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2183
|
+
F: __dxlog_file5,
|
|
2184
|
+
L: 95,
|
|
2185
|
+
S: void 0,
|
|
2186
|
+
A: [
|
|
2187
|
+
"!immutable",
|
|
2188
|
+
""
|
|
2189
|
+
]
|
|
2190
|
+
});
|
|
2191
|
+
requestAnimationFrame(() => {
|
|
2192
|
+
if (view.name !== name) {
|
|
2193
|
+
view.name = name;
|
|
2194
|
+
}
|
|
2195
|
+
if (view.query.typename !== typename && !immutable) {
|
|
2196
|
+
onTypenameChanged?.(typename);
|
|
2197
|
+
}
|
|
2198
|
+
});
|
|
2199
|
+
}, [
|
|
2200
|
+
schema,
|
|
2201
|
+
view,
|
|
2202
|
+
onTypenameChanged,
|
|
2203
|
+
immutable
|
|
2204
|
+
]);
|
|
2205
|
+
const handleDelete = (0, import_react19.useCallback)((fieldId) => {
|
|
2206
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2207
|
+
F: __dxlog_file5,
|
|
2208
|
+
L: 111,
|
|
2209
|
+
S: void 0,
|
|
2210
|
+
A: [
|
|
2211
|
+
"!immutable",
|
|
2212
|
+
""
|
|
2213
|
+
]
|
|
2214
|
+
});
|
|
2215
|
+
if (fieldId === field?.id) {
|
|
2216
|
+
setField(void 0);
|
|
2217
|
+
}
|
|
2218
|
+
onDelete?.(fieldId);
|
|
2219
|
+
}, [
|
|
2220
|
+
schema,
|
|
2221
|
+
field,
|
|
2222
|
+
onDelete
|
|
2223
|
+
]);
|
|
2224
|
+
const handleMove = (0, import_react19.useCallback)((fromIndex, toIndex) => {
|
|
2225
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2226
|
+
F: __dxlog_file5,
|
|
2227
|
+
L: 123,
|
|
2228
|
+
S: void 0,
|
|
2229
|
+
A: [
|
|
2230
|
+
"!immutable",
|
|
2231
|
+
""
|
|
2232
|
+
]
|
|
2233
|
+
});
|
|
2234
|
+
const fields = [
|
|
2235
|
+
...view.fields
|
|
2236
|
+
];
|
|
2237
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
2238
|
+
fields.splice(toIndex, 0, moved);
|
|
2239
|
+
view.fields = fields;
|
|
2240
|
+
}, [
|
|
2241
|
+
schema,
|
|
2242
|
+
view.fields
|
|
2243
|
+
]);
|
|
2244
|
+
const handleClose = (0, import_react19.useCallback)(() => setField(void 0), []);
|
|
2245
|
+
const hiddenProperties = projection.getHiddenProperties();
|
|
2246
|
+
const handleHide = (0, import_react19.useCallback)((fieldId) => {
|
|
2247
|
+
setField(void 0);
|
|
2248
|
+
projection.hideFieldProjection(fieldId);
|
|
2249
|
+
}, [
|
|
2250
|
+
projection
|
|
2251
|
+
]);
|
|
2252
|
+
const handleShow = (0, import_react19.useCallback)((property) => {
|
|
2253
|
+
setField(void 0);
|
|
2254
|
+
projection.showFieldProjection(property);
|
|
2255
|
+
}, [
|
|
2256
|
+
projection
|
|
2257
|
+
]);
|
|
2258
|
+
return /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2259
|
+
role: "none",
|
|
2260
|
+
className: (0, import_react_ui_theme9.mx)("overflow-y-auto", classNames)
|
|
2261
|
+
}, /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2262
|
+
role: "none",
|
|
2263
|
+
className: "p-2"
|
|
2264
|
+
}, /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2265
|
+
role: "none",
|
|
2266
|
+
className: "mbe-2"
|
|
2267
|
+
}, immutable && /* @__PURE__ */ import_react19.default.createElement(import_react_ui12.Message.Root, {
|
|
2268
|
+
valence: "neutral",
|
|
2269
|
+
className: "rounded"
|
|
2270
|
+
}, /* @__PURE__ */ import_react19.default.createElement(import_react_ui12.Message.Title, null, /* @__PURE__ */ import_react19.default.createElement(import_react_ui12.Icon, {
|
|
2271
|
+
icon: "ph--info--regular",
|
|
2272
|
+
size: 5,
|
|
2273
|
+
classNames: "inline"
|
|
2274
|
+
}), " ", t("system schema title")), /* @__PURE__ */ import_react19.default.createElement(import_react_ui12.Message.Body, null, t("system schema description")))), /* @__PURE__ */ import_react19.default.createElement(Form, {
|
|
2275
|
+
autoSave: true,
|
|
2276
|
+
schema: ViewMetaSchema,
|
|
2277
|
+
values: viewValues,
|
|
2278
|
+
onSave: handleUpdate,
|
|
2279
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
2280
|
+
})), /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2281
|
+
role: "none",
|
|
2282
|
+
className: "min-bs-0 overflow-y-auto"
|
|
2283
|
+
}, /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2284
|
+
role: "none",
|
|
2285
|
+
className: "p-2"
|
|
2286
|
+
}, /* @__PURE__ */ import_react19.default.createElement("label", {
|
|
2287
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
2288
|
+
}, t("fields label"))), /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.Root, {
|
|
2289
|
+
items: view.fields,
|
|
2290
|
+
isItem: import_effect12.Schema.is(import_schema5.FieldSchema),
|
|
2291
|
+
getId: (field2) => field2.id,
|
|
2292
|
+
onMove: immutable ? void 0 : handleMove
|
|
2293
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react19.default.createElement(import_react19.default.Fragment, null, showHeading && /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2294
|
+
role: "heading",
|
|
2295
|
+
className: grid
|
|
2296
|
+
}, /* @__PURE__ */ import_react19.default.createElement("div", null), /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2297
|
+
className: "flex items-center text-sm"
|
|
2298
|
+
}, t("field path label"))), /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2299
|
+
role: "list",
|
|
2300
|
+
className: "flex flex-col w-full"
|
|
2301
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.Item, {
|
|
2302
|
+
key: field2.id,
|
|
2303
|
+
item: field2,
|
|
2304
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, !immutable && "cursor-pointer")
|
|
2305
|
+
}, /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
2306
|
+
onClick: () => handleSelect(field2)
|
|
2307
|
+
}, field2.path), /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2308
|
+
className: "flex items-center gap-2 -ml-4"
|
|
2309
|
+
}, /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
2310
|
+
icon: "ph--eye-slash--regular",
|
|
2311
|
+
disabled: view.fields.length <= 1,
|
|
2312
|
+
onClick: () => handleHide(field2.id)
|
|
2313
|
+
}), !immutable && /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
2314
|
+
icon: "ph--trash--regular",
|
|
2315
|
+
disabled: view.fields.length <= 1,
|
|
2316
|
+
onClick: () => handleDelete(field2.id)
|
|
2317
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react19.default.createElement("div", null, /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2318
|
+
role: "none",
|
|
2319
|
+
className: "p-2"
|
|
2320
|
+
}, /* @__PURE__ */ import_react19.default.createElement("label", {
|
|
2321
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
2322
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.Root, {
|
|
2323
|
+
items: hiddenProperties,
|
|
2324
|
+
isItem: (item) => typeof item === "string",
|
|
2325
|
+
getId: (property) => property
|
|
2326
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2327
|
+
role: "list",
|
|
2328
|
+
className: "flex flex-col w-full"
|
|
2329
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.Item, {
|
|
2330
|
+
key: property,
|
|
2331
|
+
item: property,
|
|
2332
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, !immutable && "cursor-pointer")
|
|
2333
|
+
}, /* @__PURE__ */ import_react19.default.createElement("div", null), /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.ItemTitle, null, property), /* @__PURE__ */ import_react19.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
2334
|
+
icon: "ph--eye--regular",
|
|
2335
|
+
onClick: () => handleShow(property)
|
|
2336
|
+
}))))))), field && /* @__PURE__ */ import_react19.default.createElement(FieldEditor, {
|
|
2337
|
+
key: field.id,
|
|
2338
|
+
view,
|
|
2339
|
+
projection,
|
|
2340
|
+
field,
|
|
2341
|
+
registry,
|
|
2342
|
+
onSave: handleClose
|
|
2343
|
+
}), !readonly && !field && /* @__PURE__ */ import_react19.default.createElement("div", {
|
|
2344
|
+
role: "none",
|
|
2345
|
+
className: "p-2"
|
|
2346
|
+
}, /* @__PURE__ */ import_react19.default.createElement(import_react_ui12.IconButton, {
|
|
2347
|
+
icon: "ph--plus--regular",
|
|
2348
|
+
label: t("button add property"),
|
|
2349
|
+
onClick: immutable ? void 0 : handleAdd,
|
|
2350
|
+
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
2351
|
+
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT,
|
|
2352
|
+
classNames: "flex is-full"
|
|
2353
|
+
})));
|
|
2354
|
+
} finally {
|
|
2355
|
+
_effect.f();
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
1863
2358
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1864
2359
|
0 && (module.exports = {
|
|
1865
2360
|
BooleanInput,
|
|
1866
2361
|
ControlFrame,
|
|
1867
2362
|
ControlFrameItem,
|
|
1868
2363
|
ControlGroup,
|
|
2364
|
+
ControlGroupButton,
|
|
1869
2365
|
ControlItem,
|
|
1870
2366
|
ControlItemInput,
|
|
2367
|
+
ControlPage,
|
|
1871
2368
|
ControlSection,
|
|
1872
2369
|
ControlSectionHeading,
|
|
1873
2370
|
DeprecatedFormContainer,
|
|
@@ -1886,14 +2383,18 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1886
2383
|
ViewEditor,
|
|
1887
2384
|
cellClassesForFieldType,
|
|
1888
2385
|
controlItemClasses,
|
|
2386
|
+
findArrayElementType,
|
|
1889
2387
|
formatForDisplay,
|
|
1890
2388
|
formatForEditing,
|
|
2389
|
+
getRefProps,
|
|
1891
2390
|
parseValue,
|
|
1892
2391
|
pathNotUniqueError,
|
|
1893
2392
|
translations,
|
|
1894
2393
|
useForm,
|
|
1895
2394
|
useFormContext,
|
|
1896
2395
|
useFormValues,
|
|
1897
|
-
useInputProps
|
|
2396
|
+
useInputProps,
|
|
2397
|
+
useQueryRefOptions,
|
|
2398
|
+
useRefQueryLookupHandler
|
|
1898
2399
|
});
|
|
1899
2400
|
//# sourceMappingURL=index.cjs.map
|