@dxos/react-ui-form 0.7.4 → 0.7.5-labs.071a3e2
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 +841 -521
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +877 -571
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +841 -521
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +16 -0
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/Defaults.d.ts +5 -6
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +14 -17
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +7 -1
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts +7 -0
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormContent.d.ts +26 -0
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormContext.d.ts +20 -0
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -0
- package/dist/types/src/components/Form/Input.d.ts +5 -6
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +4 -0
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +4 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +7 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +6 -0
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts +4 -0
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/factory.d.ts +2 -2
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +2 -2
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +6 -5
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +5 -0
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +13 -15
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +28 -27
- package/src/components/FieldEditor/FieldEditor.stories.tsx +3 -3
- package/src/components/FieldEditor/FieldEditor.tsx +77 -51
- package/src/components/Form/ArrayField.tsx +111 -0
- package/src/components/Form/Defaults.tsx +20 -33
- package/src/components/Form/Form.stories.tsx +48 -6
- package/src/components/Form/Form.tsx +49 -329
- package/src/components/Form/FormActions.tsx +41 -0
- package/src/components/Form/FormContent.tsx +173 -0
- package/src/components/Form/FormContext.tsx +48 -0
- package/src/components/Form/Input.tsx +5 -6
- package/src/components/Form/custom/GeoPointInput.tsx +44 -0
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +58 -0
- package/src/components/Form/custom/SelectOptionsInput.tsx +192 -0
- package/src/components/Form/custom/TupleInput.tsx +49 -0
- package/src/components/Form/custom/index.ts +7 -0
- package/src/components/Form/factory.tsx +4 -7
- package/src/components/Form/index.ts +3 -2
- package/src/components/ViewEditor/ViewEditor.stories.tsx +30 -8
- package/src/components/ViewEditor/ViewEditor.tsx +18 -10
- package/src/components/deprecated/FormInput.tsx +20 -7
- package/src/hooks/useForm.ts +67 -79
- package/src/translations.ts +8 -0
- package/dist/types/src/components/Form/Custom.d.ts +0 -5
- package/dist/types/src/components/Form/Custom.d.ts.map +0 -1
- package/src/components/Form/Custom.tsx +0 -65
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,15 +29,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
BooleanInput: () => BooleanInput,
|
|
32
|
+
DeprecatedFormContainer: () => DeprecatedFormContainer,
|
|
32
33
|
DeprecatedFormInput: () => DeprecatedFormInput,
|
|
33
34
|
FieldEditor: () => FieldEditor,
|
|
34
35
|
Form: () => Form,
|
|
35
|
-
|
|
36
|
-
GeiPointInput: () => GeiPointInput,
|
|
36
|
+
GeoPointInput: () => GeoPointInput,
|
|
37
37
|
InputHeader: () => InputHeader,
|
|
38
38
|
NumberInput: () => NumberInput,
|
|
39
39
|
SelectInput: () => SelectInput,
|
|
40
|
+
SelectOptionInput: () => SelectOptionInput,
|
|
40
41
|
TextInput: () => TextInput,
|
|
42
|
+
TupleInput: () => TupleInput,
|
|
41
43
|
ViewEditor: () => ViewEditor,
|
|
42
44
|
cellClassesForFieldType: () => cellClassesForFieldType,
|
|
43
45
|
cellClassesForRowSelection: () => cellClassesForRowSelection,
|
|
@@ -51,42 +53,71 @@ __export(node_exports, {
|
|
|
51
53
|
module.exports = __toCommonJS(node_exports);
|
|
52
54
|
var import_react = __toESM(require("react"));
|
|
53
55
|
var import_react_ui = require("@dxos/react-ui");
|
|
56
|
+
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
54
57
|
var import_react2 = __toESM(require("react"));
|
|
55
58
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
56
59
|
var import_log = require("@dxos/log");
|
|
57
60
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
58
61
|
var import_schema = require("@dxos/schema");
|
|
59
|
-
var import_effect = require("effect");
|
|
60
|
-
var import_String = require("effect/String");
|
|
61
62
|
var import_react3 = __toESM(require("react"));
|
|
62
|
-
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
63
|
-
var import_effect2 = require("@dxos/effect");
|
|
64
|
-
var import_log2 = require("@dxos/log");
|
|
65
63
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
66
|
-
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
67
|
-
var import_schema2 = require("@dxos/schema");
|
|
68
64
|
var import_util = require("@dxos/util");
|
|
69
65
|
var import_react4 = __toESM(require("react"));
|
|
70
66
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
67
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
71
68
|
var import_react5 = __toESM(require("react"));
|
|
69
|
+
var import_keys = require("@dxos/keys");
|
|
72
70
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
73
|
-
var
|
|
74
|
-
var
|
|
71
|
+
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
72
|
+
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
73
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
75
74
|
var import_react6 = __toESM(require("react"));
|
|
76
75
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
77
|
-
var
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
var
|
|
76
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
77
|
+
var import_util2 = require("@dxos/util");
|
|
78
|
+
var import_react7 = __toESM(require("react"));
|
|
79
|
+
var import_react_ui7 = require("@dxos/react-ui");
|
|
81
80
|
var import_react8 = __toESM(require("react"));
|
|
81
|
+
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
82
|
+
var import_react9 = __toESM(require("react"));
|
|
83
|
+
var import_react_ui8 = require("@dxos/react-ui");
|
|
84
|
+
var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
85
|
+
var import_react10 = __toESM(require("react"));
|
|
86
|
+
var import_debug = require("@dxos/debug");
|
|
87
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
88
|
+
var import_effect = require("@dxos/effect");
|
|
89
|
+
var import_react11 = require("react");
|
|
90
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
91
|
+
var import_effect2 = require("@dxos/effect");
|
|
92
|
+
var import_invariant = require("@dxos/invariant");
|
|
93
|
+
var import_log2 = require("@dxos/log");
|
|
94
|
+
var import_schema2 = require("@dxos/schema");
|
|
95
|
+
var import_effect3 = require("effect");
|
|
96
|
+
var import_String = require("effect/String");
|
|
97
|
+
var import_react12 = __toESM(require("react"));
|
|
82
98
|
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
83
|
-
var
|
|
84
|
-
var
|
|
85
|
-
var
|
|
86
|
-
var
|
|
87
|
-
var
|
|
99
|
+
var import_effect4 = require("@dxos/effect");
|
|
100
|
+
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
101
|
+
var import_schema3 = require("@dxos/schema");
|
|
102
|
+
var import_util3 = require("@dxos/util");
|
|
103
|
+
var import_effect5 = require("effect");
|
|
104
|
+
var import_String2 = require("effect/String");
|
|
105
|
+
var import_react13 = __toESM(require("react"));
|
|
88
106
|
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
107
|
+
var import_effect6 = require("@dxos/effect");
|
|
108
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
109
|
+
var import_react_ui9 = require("@dxos/react-ui");
|
|
110
|
+
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
111
|
+
var import_schema4 = require("@dxos/schema");
|
|
89
112
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
113
|
+
var import_react14 = __toESM(require("react"));
|
|
114
|
+
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
115
|
+
var import_react_ui10 = require("@dxos/react-ui");
|
|
116
|
+
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
117
|
+
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
118
|
+
var import_schema5 = require("@dxos/schema");
|
|
119
|
+
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
120
|
+
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
90
121
|
var translationKey = "react-ui-form";
|
|
91
122
|
var translations_default = [
|
|
92
123
|
{
|
|
@@ -123,6 +154,7 @@ var translations_default = [
|
|
|
123
154
|
"format ref": "Reference",
|
|
124
155
|
"format regex": "RegExp",
|
|
125
156
|
"format string": "String",
|
|
157
|
+
"format single-select": "Select",
|
|
126
158
|
"format text": "Long text",
|
|
127
159
|
"format time": "Time",
|
|
128
160
|
"format timestamp": "Timestamp",
|
|
@@ -132,11 +164,26 @@ var translations_default = [
|
|
|
132
164
|
"format uuid": "UUID",
|
|
133
165
|
// Placeholders
|
|
134
166
|
"placeholder latitude": "Latitude",
|
|
135
|
-
"placeholder longitude": "Longitude"
|
|
167
|
+
"placeholder longitude": "Longitude",
|
|
168
|
+
// SelectOptionsInput
|
|
169
|
+
"select option label": "Label",
|
|
170
|
+
"select option label placeholder": "Option label",
|
|
171
|
+
"select option color": "Color",
|
|
172
|
+
"select option delete": "Delete",
|
|
173
|
+
"select option add": "Add option"
|
|
136
174
|
}
|
|
137
175
|
}
|
|
138
176
|
}
|
|
139
177
|
];
|
|
178
|
+
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
179
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
180
|
+
role: "none",
|
|
181
|
+
className: "w-full p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
182
|
+
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
183
|
+
role: "form",
|
|
184
|
+
className: (0, import_react_ui_theme.mx)("flex flex-col", import_react_ui_theme.textBlockWidth, classNames)
|
|
185
|
+
}, children));
|
|
186
|
+
};
|
|
140
187
|
var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
141
188
|
const primary = /* @__PURE__ */ import_react.default.createElement("div", {
|
|
142
189
|
role: "none",
|
|
@@ -145,179 +192,373 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
145
192
|
role: "none",
|
|
146
193
|
className: "flex flex-col w-full"
|
|
147
194
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Label, {
|
|
148
|
-
classNames: "flex min-
|
|
195
|
+
classNames: "flex min-bs-[--rail-action] items-center",
|
|
196
|
+
style: {
|
|
197
|
+
fontSize: "unset"
|
|
198
|
+
}
|
|
149
199
|
}, label), description && /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.DescriptionAndValidation, {
|
|
150
200
|
classNames: "mbs-0.5"
|
|
151
201
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Description, null, description))), /* @__PURE__ */ import_react.default.createElement("div", {
|
|
152
202
|
role: "none"
|
|
153
203
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
154
204
|
role: "none",
|
|
155
|
-
className: "flex min-
|
|
205
|
+
className: "flex min-bs-[--rail-action] items-center"
|
|
156
206
|
}, children))));
|
|
157
207
|
if (secondary) {
|
|
158
208
|
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
159
|
-
role: "none"
|
|
160
|
-
className: "flex flex-col w-full"
|
|
209
|
+
role: "none"
|
|
161
210
|
}, primary, secondary);
|
|
162
211
|
}
|
|
163
212
|
return primary;
|
|
164
213
|
};
|
|
165
214
|
var InputHeader = ({ children, error }) => {
|
|
166
|
-
return /* @__PURE__ */
|
|
215
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
167
216
|
role: "none",
|
|
168
217
|
className: "flex justify-between items-center mb-1"
|
|
169
|
-
}, children, error && /* @__PURE__ */
|
|
218
|
+
}, children, error && /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
170
219
|
asChild: true
|
|
171
|
-
}, /* @__PURE__ */
|
|
220
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Icon, {
|
|
172
221
|
icon: "ph--warning--regular",
|
|
173
222
|
size: 4,
|
|
174
223
|
classNames: import_react_ui_theme2.errorText
|
|
175
|
-
})), /* @__PURE__ */
|
|
224
|
+
})), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
176
225
|
side: "bottom"
|
|
177
|
-
}, /* @__PURE__ */
|
|
226
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
227
|
+
};
|
|
228
|
+
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
229
|
+
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
230
|
+
const { status, error } = getStatus();
|
|
231
|
+
const [lng = 0, lat = 0] = getValue3() ?? [];
|
|
232
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Root, {
|
|
233
|
+
validationValence: status
|
|
234
|
+
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, {
|
|
235
|
+
error
|
|
236
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
237
|
+
className: "grid grid-cols-2 gap-2"
|
|
238
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
239
|
+
type: "number",
|
|
240
|
+
disabled,
|
|
241
|
+
placeholder: t("placeholder longitude"),
|
|
242
|
+
value: lng,
|
|
243
|
+
onChange: (event) => onValueChange(type, [
|
|
244
|
+
lat,
|
|
245
|
+
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
246
|
+
]),
|
|
247
|
+
onBlur
|
|
248
|
+
}), /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
249
|
+
type: "number",
|
|
250
|
+
disabled,
|
|
251
|
+
placeholder: t("placeholder latitude"),
|
|
252
|
+
value: lat,
|
|
253
|
+
onChange: (event) => onValueChange(type, [
|
|
254
|
+
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
255
|
+
lng
|
|
256
|
+
]),
|
|
257
|
+
onBlur
|
|
258
|
+
})));
|
|
259
|
+
};
|
|
260
|
+
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
261
|
+
const [selected, setSelectedId] = (0, import_react5.useState)(null);
|
|
262
|
+
const [isNewOption, setIsNewOption] = (0, import_react5.useState)(false);
|
|
263
|
+
const inputRef = (0, import_react5.useRef)(null);
|
|
264
|
+
const { t } = (0, import_react_ui5.useTranslation)(translationKey);
|
|
265
|
+
const { status, error } = getStatus();
|
|
266
|
+
const options = getValue3();
|
|
267
|
+
(0, import_react5.useEffect)(() => {
|
|
268
|
+
if (options === void 0) {
|
|
269
|
+
onValueChange(type, []);
|
|
270
|
+
}
|
|
271
|
+
}, [
|
|
272
|
+
options,
|
|
273
|
+
onValueChange,
|
|
274
|
+
type
|
|
275
|
+
]);
|
|
276
|
+
const randomHue = () => {
|
|
277
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
278
|
+
const hueKeys = Object.keys(import_react_ui_theme3.hueTokenThemes);
|
|
279
|
+
const unusedHues = hueKeys.filter((hue) => !usedHues.has(hue));
|
|
280
|
+
if (unusedHues.length > 0) {
|
|
281
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
282
|
+
}
|
|
283
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
284
|
+
const availableHues = hueKeys.filter((hue) => !lastThree.has(hue));
|
|
285
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hueKeys[Math.floor(Math.random() * hueKeys.length)];
|
|
286
|
+
};
|
|
287
|
+
const handleAdd = (0, import_react5.useCallback)(() => {
|
|
288
|
+
const newId = import_keys.PublicKey.random().truncate();
|
|
289
|
+
const newOption = {
|
|
290
|
+
id: newId,
|
|
291
|
+
title: "",
|
|
292
|
+
color: randomHue()
|
|
293
|
+
};
|
|
294
|
+
onValueChange(type, [
|
|
295
|
+
...options ?? [],
|
|
296
|
+
newOption
|
|
297
|
+
]);
|
|
298
|
+
setSelectedId(newId);
|
|
299
|
+
setIsNewOption(true);
|
|
300
|
+
}, [
|
|
301
|
+
options,
|
|
302
|
+
type,
|
|
303
|
+
onValueChange
|
|
304
|
+
]);
|
|
305
|
+
const handleDelete = (0, import_react5.useCallback)((id) => {
|
|
306
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
307
|
+
onValueChange(type, newOptions);
|
|
308
|
+
setSelectedId(null);
|
|
309
|
+
}, [
|
|
310
|
+
options,
|
|
311
|
+
type,
|
|
312
|
+
onValueChange
|
|
313
|
+
]);
|
|
314
|
+
const handleMove = (0, import_react5.useCallback)((from, to) => {
|
|
315
|
+
if (!options) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const newOptions = [
|
|
319
|
+
...options
|
|
320
|
+
];
|
|
321
|
+
const [removed] = newOptions.splice(from, 1);
|
|
322
|
+
newOptions.splice(to, 0, removed);
|
|
323
|
+
onValueChange(type, newOptions);
|
|
324
|
+
}, [
|
|
325
|
+
options,
|
|
326
|
+
type,
|
|
327
|
+
onValueChange
|
|
328
|
+
]);
|
|
329
|
+
const handleClick = (0, import_react5.useCallback)((id) => {
|
|
330
|
+
setSelectedId((current) => current === id ? null : id);
|
|
331
|
+
}, []);
|
|
332
|
+
const handleTitleChange = (0, import_react5.useCallback)((id) => (e) => {
|
|
333
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
334
|
+
...o,
|
|
335
|
+
title: e.target.value
|
|
336
|
+
} : o);
|
|
337
|
+
onValueChange(type, newOptions ?? []);
|
|
338
|
+
}, [
|
|
339
|
+
options,
|
|
340
|
+
type,
|
|
341
|
+
onValueChange
|
|
342
|
+
]);
|
|
343
|
+
const handleKeyDown = (0, import_react5.useCallback)((e) => {
|
|
344
|
+
if (e.key === "Enter") {
|
|
345
|
+
setSelectedId(null);
|
|
346
|
+
}
|
|
347
|
+
}, []);
|
|
348
|
+
const handleColorChange = (0, import_react5.useCallback)((id) => (hue) => {
|
|
349
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
350
|
+
...o,
|
|
351
|
+
color: hue
|
|
352
|
+
} : o);
|
|
353
|
+
onValueChange(type, newOptions ?? []);
|
|
354
|
+
}, [
|
|
355
|
+
options,
|
|
356
|
+
type,
|
|
357
|
+
onValueChange
|
|
358
|
+
]);
|
|
359
|
+
(0, import_react5.useEffect)(() => {
|
|
360
|
+
if (selected && isNewOption && inputRef.current) {
|
|
361
|
+
inputRef.current.focus();
|
|
362
|
+
setIsNewOption(false);
|
|
363
|
+
}
|
|
364
|
+
}, [
|
|
365
|
+
selected,
|
|
366
|
+
isNewOption
|
|
367
|
+
]);
|
|
368
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Root, {
|
|
369
|
+
validationValence: status
|
|
370
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
371
|
+
error
|
|
372
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
373
|
+
role: "none"
|
|
374
|
+
}, options && /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.Root, {
|
|
375
|
+
items: options,
|
|
376
|
+
isItem: (item) => true,
|
|
377
|
+
onMove: handleMove
|
|
378
|
+
}, ({ items }) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
379
|
+
role: "list",
|
|
380
|
+
className: "w-full overflow-auto"
|
|
381
|
+
}, items?.map((item) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
382
|
+
key: item.id
|
|
383
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.Item, {
|
|
384
|
+
role: "button",
|
|
385
|
+
item,
|
|
386
|
+
classNames: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
387
|
+
"aria-expanded": selected === item.id
|
|
388
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
389
|
+
className: "flex items-center"
|
|
390
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
391
|
+
onClick: () => handleClick(item.id),
|
|
392
|
+
classNames: "flex-1"
|
|
393
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tag, {
|
|
394
|
+
palette: item.color
|
|
395
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
396
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
397
|
+
onClick: () => handleClick(item.id)
|
|
398
|
+
})), selected === item.id && /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
399
|
+
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
400
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, {
|
|
401
|
+
classNames: "text-xs"
|
|
402
|
+
}, t("select option label")), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
403
|
+
className: "flex flex-row items-center gap-1"
|
|
404
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.TextInput, {
|
|
405
|
+
placeholder: t("select option label placeholder"),
|
|
406
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
407
|
+
value: item.title,
|
|
408
|
+
onChange: handleTitleChange(item.id),
|
|
409
|
+
onKeyDown: handleKeyDown,
|
|
410
|
+
classNames: "flex-1"
|
|
411
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
412
|
+
classNames: "p-0 m-0 !is-auto"
|
|
413
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_pickers.HuePickerToolbarButton, {
|
|
414
|
+
hue: item.color,
|
|
415
|
+
onChangeHue: handleColorChange(item.id)
|
|
416
|
+
})), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.IconButton, {
|
|
417
|
+
icon: "ph--trash--fill",
|
|
418
|
+
iconOnly: true,
|
|
419
|
+
label: t("select option delete"),
|
|
420
|
+
onClick: () => handleDelete(item.id)
|
|
421
|
+
})))))), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
422
|
+
role: "listitem"
|
|
423
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
424
|
+
role: "button",
|
|
425
|
+
className: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
426
|
+
onClick: handleAdd
|
|
427
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
428
|
+
className: "flex items-center gap-1"
|
|
429
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
430
|
+
icon: "ph--plus--regular"
|
|
431
|
+
}), /* @__PURE__ */ import_react5.default.createElement("span", {
|
|
432
|
+
className: "text-sm"
|
|
433
|
+
}, t("select option add")))))))));
|
|
434
|
+
};
|
|
435
|
+
var gridCols = [
|
|
436
|
+
"grid-cols-1",
|
|
437
|
+
"grid-cols-2",
|
|
438
|
+
"grid-cols-3",
|
|
439
|
+
"grid-cols-4"
|
|
440
|
+
];
|
|
441
|
+
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
442
|
+
const { status, error } = getStatus();
|
|
443
|
+
const values = getValue3() ?? {};
|
|
444
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
445
|
+
validationValence: status
|
|
446
|
+
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
447
|
+
error
|
|
448
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
449
|
+
className: (0, import_react_ui_theme4.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
450
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
451
|
+
key: prop,
|
|
452
|
+
type: "number",
|
|
453
|
+
disabled,
|
|
454
|
+
value: values[prop],
|
|
455
|
+
onChange: (event) => onValueChange(type, {
|
|
456
|
+
...values,
|
|
457
|
+
[prop]: (0, import_util2.safeParseFloat)(event.target.value, 0)
|
|
458
|
+
}),
|
|
459
|
+
onBlur
|
|
460
|
+
}))));
|
|
178
461
|
};
|
|
179
|
-
var TextInput = ({
|
|
180
|
-
const { status, error } = getStatus
|
|
181
|
-
return /* @__PURE__ */
|
|
462
|
+
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
463
|
+
const { status, error } = getStatus();
|
|
464
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
182
465
|
validationValence: status
|
|
183
|
-
}, !inputOnly && /* @__PURE__ */
|
|
466
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
184
467
|
error
|
|
185
|
-
}, /* @__PURE__ */
|
|
468
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
186
469
|
disabled,
|
|
187
470
|
placeholder,
|
|
188
|
-
value:
|
|
189
|
-
onChange: (event) => onValueChange(
|
|
471
|
+
value: getValue3() ?? "",
|
|
472
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
190
473
|
onBlur
|
|
191
|
-
}), inputOnly && /* @__PURE__ */
|
|
474
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
192
475
|
};
|
|
193
|
-
var NumberInput = ({
|
|
194
|
-
const { status, error } = getStatus
|
|
195
|
-
return /* @__PURE__ */
|
|
476
|
+
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
477
|
+
const { status, error } = getStatus();
|
|
478
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
196
479
|
validationValence: status
|
|
197
|
-
}, !inputOnly && /* @__PURE__ */
|
|
480
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
198
481
|
error
|
|
199
|
-
}, /* @__PURE__ */
|
|
482
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
200
483
|
type: "number",
|
|
201
484
|
disabled,
|
|
202
485
|
placeholder,
|
|
203
|
-
value:
|
|
204
|
-
onChange: (event) => onValueChange(
|
|
486
|
+
value: getValue3() ?? 0,
|
|
487
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
205
488
|
onBlur
|
|
206
|
-
}), inputOnly && /* @__PURE__ */
|
|
489
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
207
490
|
};
|
|
208
|
-
var BooleanInput = ({
|
|
209
|
-
const { status, error } = getStatus
|
|
210
|
-
return /* @__PURE__ */
|
|
491
|
+
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
492
|
+
const { status, error } = getStatus();
|
|
493
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
211
494
|
validationValence: status
|
|
212
|
-
}, !inputOnly && /* @__PURE__ */
|
|
495
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
213
496
|
error
|
|
214
|
-
}, /* @__PURE__ */
|
|
215
|
-
checked:
|
|
216
|
-
onCheckedChange: (value) => onValueChange(
|
|
217
|
-
}), inputOnly && /* @__PURE__ */
|
|
497
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Switch, {
|
|
498
|
+
checked: getValue3(),
|
|
499
|
+
onCheckedChange: (value) => onValueChange(type, value)
|
|
500
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
218
501
|
};
|
|
219
|
-
var SelectInput = ({
|
|
220
|
-
const { status, error } = getStatus
|
|
221
|
-
return /* @__PURE__ */
|
|
502
|
+
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
503
|
+
const { status, error } = getStatus();
|
|
504
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
222
505
|
validationValence: status
|
|
223
|
-
}, !inputOnly && /* @__PURE__ */
|
|
506
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
224
507
|
error
|
|
225
|
-
}, /* @__PURE__ */
|
|
226
|
-
value:
|
|
227
|
-
onValueChange: (value) => onValueChange(
|
|
228
|
-
}, /* @__PURE__ */
|
|
508
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Root, {
|
|
509
|
+
value: getValue3(),
|
|
510
|
+
onValueChange: (value) => onValueChange(type, value)
|
|
511
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
229
512
|
classNames: "is-full",
|
|
230
513
|
disabled,
|
|
231
514
|
placeholder
|
|
232
|
-
}), /* @__PURE__ */
|
|
515
|
+
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Portal, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Content, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
233
516
|
// NOTE: Numeric values are converted to and from strings.
|
|
234
|
-
/* @__PURE__ */
|
|
517
|
+
/* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Option, {
|
|
235
518
|
key: String(value),
|
|
236
519
|
value: String(value)
|
|
237
520
|
}, label2 ?? String(value))
|
|
238
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
239
|
-
};
|
|
240
|
-
var GeiPointInput = ({ property, type, label, disabled, getStatus, getValue, onValueChange, onBlur }) => {
|
|
241
|
-
const { t } = (0, import_react_ui6.useTranslation)(translationKey);
|
|
242
|
-
const { status, error } = getStatus?.(property);
|
|
243
|
-
const [lng = 0, lat = 0] = getValue(property) ?? [];
|
|
244
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
245
|
-
validationValence: status
|
|
246
|
-
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
247
|
-
error
|
|
248
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
249
|
-
className: "grid grid-cols-2 gap-2"
|
|
250
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
251
|
-
type: "number",
|
|
252
|
-
disabled,
|
|
253
|
-
placeholder: t("placeholder longitude"),
|
|
254
|
-
value: lng,
|
|
255
|
-
onChange: (event) => onValueChange(property, type, [
|
|
256
|
-
lat,
|
|
257
|
-
safeParseFloat(event.target.value, 0)
|
|
258
|
-
]),
|
|
259
|
-
onBlur
|
|
260
|
-
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
261
|
-
type: "number",
|
|
262
|
-
disabled,
|
|
263
|
-
placeholder: t("placeholder latitude"),
|
|
264
|
-
value: lat,
|
|
265
|
-
onChange: (event) => onValueChange(property, type, [
|
|
266
|
-
safeParseFloat(event.target.value, 0),
|
|
267
|
-
lng
|
|
268
|
-
]),
|
|
269
|
-
onBlur
|
|
270
|
-
})));
|
|
271
|
-
};
|
|
272
|
-
var safeParseFloat = (str, defaultValue) => {
|
|
273
|
-
try {
|
|
274
|
-
return parseFloat(str);
|
|
275
|
-
} catch {
|
|
276
|
-
return defaultValue ?? 0;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
var getInputComponent = (type, format) => {
|
|
280
|
-
switch (format) {
|
|
281
|
-
case import_echo_schema3.FormatEnum.LatLng:
|
|
282
|
-
return GeiPointInput;
|
|
283
|
-
}
|
|
284
|
-
switch (type) {
|
|
285
|
-
case "string":
|
|
286
|
-
return TextInput;
|
|
287
|
-
case "number":
|
|
288
|
-
return NumberInput;
|
|
289
|
-
case "boolean":
|
|
290
|
-
return BooleanInput;
|
|
291
|
-
}
|
|
521
|
+
)))))), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
292
522
|
};
|
|
293
523
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
294
524
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
295
|
-
|
|
296
|
-
|
|
525
|
+
(0, import_invariant.invariant)(import_effect2.AST.isTypeLiteral(schema.ast), void 0, {
|
|
526
|
+
F: __dxlog_file,
|
|
527
|
+
L: 91,
|
|
528
|
+
S: void 0,
|
|
529
|
+
A: [
|
|
530
|
+
"AST.isTypeLiteral(schema.ast)",
|
|
531
|
+
""
|
|
532
|
+
]
|
|
533
|
+
});
|
|
534
|
+
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
535
|
+
(0, import_react11.useEffect)(() => {
|
|
297
536
|
setValues(initialValues);
|
|
298
537
|
}, [
|
|
299
538
|
initialValues
|
|
300
539
|
]);
|
|
301
|
-
const [touched, setTouched] = (0,
|
|
302
|
-
const [changed, setChanged] = (0,
|
|
303
|
-
const [errors, setErrors] = (0,
|
|
304
|
-
const [saving, setSaving] = (0,
|
|
305
|
-
const validate = (0,
|
|
306
|
-
let errors2 = (0,
|
|
540
|
+
const [touched, setTouched] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
541
|
+
const [changed, setChanged] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
542
|
+
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
543
|
+
const [saving, setSaving] = (0, import_react11.useState)(false);
|
|
544
|
+
const validate = (0, import_react11.useCallback)((values2) => {
|
|
545
|
+
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
307
546
|
if (errors2.length === 0 && onValidate) {
|
|
308
|
-
|
|
547
|
+
const validatedValues = values2;
|
|
548
|
+
errors2 = onValidate(validatedValues) ?? [];
|
|
309
549
|
}
|
|
310
550
|
setErrors(flatMap(errors2));
|
|
311
|
-
|
|
551
|
+
const valid = errors2.length === 0;
|
|
552
|
+
return valid;
|
|
312
553
|
}, [
|
|
313
554
|
schema,
|
|
314
555
|
onValidate
|
|
315
556
|
]);
|
|
316
|
-
const [schemaDirty, setSchemaDirty] = (0,
|
|
317
|
-
(0,
|
|
557
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
558
|
+
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
318
559
|
schema
|
|
319
560
|
]);
|
|
320
|
-
(0,
|
|
561
|
+
(0, import_react11.useEffect)(() => {
|
|
321
562
|
if (schemaDirty) {
|
|
322
563
|
validate(values);
|
|
323
564
|
setSchemaDirty(false);
|
|
@@ -326,13 +567,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
326
567
|
values,
|
|
327
568
|
schemaDirty
|
|
328
569
|
]);
|
|
329
|
-
const canSave = (0,
|
|
330
|
-
|
|
570
|
+
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
571
|
+
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
331
572
|
touched,
|
|
332
573
|
errors,
|
|
333
574
|
saving
|
|
334
575
|
]);
|
|
335
|
-
const handleSave = (0,
|
|
576
|
+
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
336
577
|
if (validate(values)) {
|
|
337
578
|
setSaving(true);
|
|
338
579
|
try {
|
|
@@ -346,38 +587,45 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
346
587
|
}, [
|
|
347
588
|
values,
|
|
348
589
|
validate,
|
|
349
|
-
onSave
|
|
590
|
+
onSave,
|
|
591
|
+
changed
|
|
350
592
|
]);
|
|
351
|
-
const getStatus = (0,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
593
|
+
const getStatus = (0, import_react11.useCallback)((path) => {
|
|
594
|
+
const jsonPath = Array.isArray(path) ? (0, import_effect2.createJsonPath)(path) : path;
|
|
595
|
+
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
596
|
+
return {
|
|
597
|
+
status: matchingError ? "error" : void 0,
|
|
598
|
+
error: matchingError ? matchingError[1] : void 0
|
|
599
|
+
};
|
|
600
|
+
}, [
|
|
356
601
|
errors
|
|
357
602
|
]);
|
|
358
|
-
const
|
|
359
|
-
return
|
|
603
|
+
const getFormValue = (path) => {
|
|
604
|
+
return (0, import_echo_schema3.getValue)(values, (0, import_effect2.createJsonPath)(path));
|
|
360
605
|
};
|
|
361
|
-
const onValueChange = (
|
|
606
|
+
const onValueChange = (path, type, value) => {
|
|
607
|
+
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
362
608
|
let parsedValue = value;
|
|
363
609
|
try {
|
|
364
610
|
if (type === "number") {
|
|
365
611
|
parsedValue = parseFloat(value) || 0;
|
|
366
612
|
}
|
|
367
613
|
} catch (err) {
|
|
368
|
-
|
|
614
|
+
import_log2.log.catch(err, void 0, {
|
|
369
615
|
F: __dxlog_file,
|
|
370
|
-
L:
|
|
616
|
+
L: 193,
|
|
371
617
|
S: void 0,
|
|
372
618
|
C: (f, a) => f(...a)
|
|
373
619
|
});
|
|
374
620
|
parsedValue = void 0;
|
|
375
621
|
}
|
|
376
|
-
const newValues =
|
|
622
|
+
const newValues = {
|
|
623
|
+
...(0, import_echo_schema3.setValue)(values, jsonPath, parsedValue)
|
|
624
|
+
};
|
|
377
625
|
setValues(newValues);
|
|
378
626
|
setChanged((prev) => ({
|
|
379
627
|
...prev,
|
|
380
|
-
[
|
|
628
|
+
[jsonPath]: true
|
|
381
629
|
}));
|
|
382
630
|
onValuesChanged?.(newValues);
|
|
383
631
|
const isValid = validate(newValues);
|
|
@@ -387,15 +635,12 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
387
635
|
});
|
|
388
636
|
}
|
|
389
637
|
};
|
|
390
|
-
const
|
|
391
|
-
const
|
|
638
|
+
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
639
|
+
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
392
640
|
setTouched((touched2) => ({
|
|
393
641
|
...touched2,
|
|
394
|
-
[
|
|
642
|
+
[jsonPath]: true
|
|
395
643
|
}));
|
|
396
|
-
if (event.relatedTarget?.getAttribute("type") === "submit") {
|
|
397
|
-
setTouched(createKeySet(values, true));
|
|
398
|
-
}
|
|
399
644
|
validate(values);
|
|
400
645
|
}, [
|
|
401
646
|
validate,
|
|
@@ -411,15 +656,15 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
411
656
|
handleSave,
|
|
412
657
|
// Field utils.
|
|
413
658
|
getStatus,
|
|
414
|
-
getValue,
|
|
659
|
+
getValue: getFormValue,
|
|
415
660
|
onValueChange,
|
|
416
|
-
|
|
661
|
+
onTouched
|
|
417
662
|
};
|
|
418
663
|
};
|
|
419
664
|
var createKeySet = (obj, value) => {
|
|
420
665
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
421
666
|
F: __dxlog_file,
|
|
422
|
-
L:
|
|
667
|
+
L: 235,
|
|
423
668
|
S: void 0,
|
|
424
669
|
A: [
|
|
425
670
|
"obj",
|
|
@@ -433,316 +678,346 @@ var createKeySet = (obj, value) => {
|
|
|
433
678
|
};
|
|
434
679
|
var flatMap = (errors) => {
|
|
435
680
|
return errors.reduce((result, { path, message }) => {
|
|
436
|
-
|
|
437
|
-
|
|
681
|
+
const jsonPath = (0, import_effect2.fromEffectValidationPath)(path);
|
|
682
|
+
if (!(jsonPath in result)) {
|
|
683
|
+
result[jsonPath] = message;
|
|
438
684
|
}
|
|
439
685
|
return result;
|
|
440
686
|
}, {});
|
|
441
687
|
};
|
|
442
|
-
var
|
|
443
|
-
|
|
444
|
-
return
|
|
688
|
+
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
689
|
+
var useFormContext = () => {
|
|
690
|
+
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
691
|
+
};
|
|
692
|
+
var useFormValues = (path = []) => {
|
|
693
|
+
const { values: formValues } = useFormContext();
|
|
694
|
+
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
695
|
+
return (0, import_echo_schema2.getValue)(formValues, jsonPath);
|
|
445
696
|
};
|
|
446
|
-
var
|
|
447
|
-
const
|
|
448
|
-
const newValue = index === void 0 ? value : [
|
|
449
|
-
...obj[key]
|
|
450
|
-
].map((v, i) => i === parseInt(index) ? value : v);
|
|
697
|
+
var useInputProps = (path = []) => {
|
|
698
|
+
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
451
699
|
return {
|
|
452
|
-
|
|
453
|
-
|
|
700
|
+
getStatus: () => getStatus(path),
|
|
701
|
+
getValue: () => getFormValue(path),
|
|
702
|
+
onValueChange: (type, value) => onValueChange(path, type, value),
|
|
703
|
+
onBlur: () => onTouched(path)
|
|
454
704
|
};
|
|
455
705
|
};
|
|
456
|
-
var
|
|
706
|
+
var FormProvider = ({ children, ...formOptions }) => {
|
|
707
|
+
const formHandler = useForm(formOptions);
|
|
708
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
709
|
+
value: formHandler
|
|
710
|
+
}, children);
|
|
711
|
+
};
|
|
712
|
+
var FormActions = ({ onCancel, readonly }) => {
|
|
713
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
714
|
+
const { canSave, handleSave } = useFormContext();
|
|
715
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
716
|
+
role: "none",
|
|
717
|
+
className: "flex justify-center"
|
|
718
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
719
|
+
role: "none",
|
|
720
|
+
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
721
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
722
|
+
"data-testid": "cancel-button",
|
|
723
|
+
icon: "ph--x--regular",
|
|
724
|
+
label: t("button cancel"),
|
|
725
|
+
onClick: onCancel
|
|
726
|
+
}), handleSave && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
727
|
+
type: "submit",
|
|
728
|
+
"data-testid": "save-button",
|
|
729
|
+
disabled: !canSave,
|
|
730
|
+
icon: "ph--check--regular",
|
|
731
|
+
label: t("button save"),
|
|
732
|
+
onClick: handleSave
|
|
733
|
+
})));
|
|
734
|
+
};
|
|
735
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
457
736
|
var padding = "px-2";
|
|
458
|
-
var
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
737
|
+
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
738
|
+
const { t } = (0, import_react_ui9.useTranslation)(translationKey);
|
|
739
|
+
const { ast, name, type, title } = property;
|
|
740
|
+
const values = useFormValues(path ?? []);
|
|
741
|
+
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
742
|
+
F: __dxlog_file2,
|
|
743
|
+
L: 37,
|
|
744
|
+
S: void 0,
|
|
745
|
+
A: [
|
|
746
|
+
"Array.isArray(values)",
|
|
747
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
748
|
+
]
|
|
470
749
|
});
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
750
|
+
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
751
|
+
const tupleType = (0, import_effect6.findNode)(ast, import_echo_schema5.AST.isTupleType);
|
|
752
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
753
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
754
|
+
const baseNode = (0, import_effect6.findNode)(typeNode, import_effect6.isDiscriminatedUnion);
|
|
755
|
+
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode, import_echo_schema5.AST.isTypeLiteral);
|
|
756
|
+
if (!typeLiteral) {
|
|
757
|
+
return {};
|
|
758
|
+
}
|
|
759
|
+
return Object.fromEntries((0, import_schema4.getSchemaProperties)(typeLiteral, {}).map((prop) => [
|
|
760
|
+
prop.name,
|
|
761
|
+
prop.defaultValue
|
|
762
|
+
]));
|
|
763
|
+
};
|
|
764
|
+
const newValue = (0, import_react13.useMemo)(() => {
|
|
765
|
+
if (type === "object" && elementType) {
|
|
766
|
+
return getDefaultObjectValue(elementType);
|
|
767
|
+
} else {
|
|
768
|
+
return import_effect6.SimpleType.getDefaultValue(type);
|
|
769
|
+
}
|
|
479
770
|
}, [
|
|
480
|
-
|
|
481
|
-
|
|
771
|
+
type,
|
|
772
|
+
elementType
|
|
773
|
+
]);
|
|
774
|
+
const handleAdd = (0, import_react13.useCallback)(() => {
|
|
775
|
+
inputProps.onValueChange(type, [
|
|
776
|
+
...values,
|
|
777
|
+
newValue
|
|
778
|
+
]);
|
|
779
|
+
}, [
|
|
780
|
+
type,
|
|
781
|
+
elementType,
|
|
782
|
+
inputProps,
|
|
783
|
+
newValue,
|
|
482
784
|
values
|
|
483
785
|
]);
|
|
484
|
-
(0,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
errors
|
|
488
|
-
}, {
|
|
489
|
-
F: __dxlog_file2,
|
|
490
|
-
L: 100,
|
|
491
|
-
S: void 0,
|
|
492
|
-
C: (f, a) => f(...a)
|
|
493
|
-
});
|
|
494
|
-
}
|
|
786
|
+
const handleRemove = (0, import_react13.useCallback)((index) => {
|
|
787
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
788
|
+
inputProps.onValueChange(type, newValues);
|
|
495
789
|
}, [
|
|
496
|
-
|
|
790
|
+
type,
|
|
791
|
+
inputProps,
|
|
792
|
+
values
|
|
497
793
|
]);
|
|
498
|
-
|
|
499
|
-
role: "form",
|
|
500
|
-
className: (0, import_react_ui_theme.mx)("flex flex-col w-full gap-2 py-2", classNames),
|
|
501
|
-
"data-testid": testId
|
|
502
|
-
}, properties.map((property) => {
|
|
503
|
-
const { ast, name, type, format, title, description, examples, options, array } = property;
|
|
504
|
-
const key = [
|
|
505
|
-
...path,
|
|
506
|
-
name
|
|
507
|
-
];
|
|
508
|
-
const label = title ?? (0, import_effect.pipe)(name, import_String.capitalize);
|
|
509
|
-
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
510
|
-
let InputComponent = Custom?.[key.join(".")];
|
|
511
|
-
if (!InputComponent) {
|
|
512
|
-
if (options) {
|
|
513
|
-
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
514
|
-
key: name,
|
|
515
|
-
role: "none",
|
|
516
|
-
className: padding
|
|
517
|
-
}, /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
518
|
-
type,
|
|
519
|
-
format,
|
|
520
|
-
property: name,
|
|
521
|
-
disabled: readonly,
|
|
522
|
-
label,
|
|
523
|
-
options: options.map((option) => ({
|
|
524
|
-
value: option,
|
|
525
|
-
label: String(option)
|
|
526
|
-
})),
|
|
527
|
-
placeholder,
|
|
528
|
-
...inputProps
|
|
529
|
-
}));
|
|
530
|
-
}
|
|
531
|
-
InputComponent = getInputComponent(type, format);
|
|
532
|
-
if (array) {
|
|
533
|
-
return /* @__PURE__ */ import_react3.default.createElement(ArrayField, {
|
|
534
|
-
key: name,
|
|
535
|
-
name,
|
|
536
|
-
type,
|
|
537
|
-
array: true,
|
|
538
|
-
label,
|
|
539
|
-
ast,
|
|
540
|
-
values,
|
|
541
|
-
format,
|
|
542
|
-
readonly,
|
|
543
|
-
placeholder,
|
|
544
|
-
inputProps,
|
|
545
|
-
Custom
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
if (!InputComponent) {
|
|
550
|
-
if (type === "object") {
|
|
551
|
-
const baseNode = (0, import_effect2.findNode)(ast, import_effect2.isDiscriminatedUnion);
|
|
552
|
-
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(ast, import_echo_schema2.AST.isTypeLiteral);
|
|
553
|
-
if (typeLiteral) {
|
|
554
|
-
const schema2 = import_echo_schema2.S.make(typeLiteral);
|
|
555
|
-
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
556
|
-
key: name,
|
|
557
|
-
role: "none"
|
|
558
|
-
}, /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
559
|
-
className: padding
|
|
560
|
-
}, label), /* @__PURE__ */ import_react3.default.createElement(Form, {
|
|
561
|
-
schema: schema2,
|
|
562
|
-
path: key,
|
|
563
|
-
values: values[name] ?? {},
|
|
564
|
-
onValuesChanged: (childValues) => {
|
|
565
|
-
inputProps.onValueChange(name, "object", childValues);
|
|
566
|
-
},
|
|
567
|
-
Custom
|
|
568
|
-
}));
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
(0, import_log2.log)("no renderer for property", {
|
|
572
|
-
name,
|
|
573
|
-
type
|
|
574
|
-
}, {
|
|
575
|
-
F: __dxlog_file2,
|
|
576
|
-
L: 185,
|
|
577
|
-
S: void 0,
|
|
578
|
-
C: (f, a) => f(...a)
|
|
579
|
-
});
|
|
580
|
-
return null;
|
|
581
|
-
}
|
|
582
|
-
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
583
|
-
key: name,
|
|
584
|
-
role: "none",
|
|
585
|
-
className: padding
|
|
586
|
-
}, /* @__PURE__ */ import_react3.default.createElement(InputComponent, {
|
|
587
|
-
type,
|
|
588
|
-
format,
|
|
589
|
-
property: name,
|
|
590
|
-
disabled: readonly,
|
|
591
|
-
label,
|
|
592
|
-
placeholder,
|
|
593
|
-
...inputProps
|
|
594
|
-
}));
|
|
595
|
-
}).filter(import_util.isNotFalsy), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react3.default.createElement(FormActions, {
|
|
596
|
-
onCancel,
|
|
597
|
-
onSubmit: handleSave,
|
|
598
|
-
canSubmit: canSave,
|
|
599
|
-
readonly
|
|
600
|
-
}));
|
|
601
|
-
};
|
|
602
|
-
var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholder, inputProps, Custom }) => {
|
|
603
|
-
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
604
|
-
const arrayValues = values[name] ?? [];
|
|
605
|
-
const key = [
|
|
606
|
-
name
|
|
607
|
-
];
|
|
608
|
-
const tupleType = (0, import_effect2.findNode)(ast, import_echo_schema2.AST.isTupleType);
|
|
609
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
610
|
-
if (type === "object" && elementType) {
|
|
611
|
-
const baseNode = (0, import_effect2.findNode)(elementType, import_effect2.isDiscriminatedUnion);
|
|
612
|
-
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(elementType, import_echo_schema2.AST.isTypeLiteral);
|
|
613
|
-
if (typeLiteral) {
|
|
614
|
-
const schema = import_echo_schema2.S.make(typeLiteral);
|
|
615
|
-
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
616
|
-
key: name,
|
|
617
|
-
role: "none",
|
|
618
|
-
className: (0, import_react_ui_theme.mx)(padding)
|
|
619
|
-
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
620
|
-
role: "none",
|
|
621
|
-
className: "flex flex-col gap-1"
|
|
622
|
-
}, arrayValues.map((value, index) => {
|
|
623
|
-
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
624
|
-
key: index,
|
|
625
|
-
role: "none",
|
|
626
|
-
className: "flex items-center gap-1"
|
|
627
|
-
}, /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
628
|
-
role: "none",
|
|
629
|
-
className: "flex-1"
|
|
630
|
-
}, /* @__PURE__ */ import_react3.default.createElement(Form, {
|
|
631
|
-
schema,
|
|
632
|
-
path: [
|
|
633
|
-
...key,
|
|
634
|
-
index.toString()
|
|
635
|
-
],
|
|
636
|
-
values: value,
|
|
637
|
-
onValuesChanged: (childValues) => {
|
|
638
|
-
const newValues = [
|
|
639
|
-
...arrayValues
|
|
640
|
-
];
|
|
641
|
-
newValues[index] = childValues;
|
|
642
|
-
inputProps.onValueChange(name, "object", newValues);
|
|
643
|
-
},
|
|
644
|
-
Custom
|
|
645
|
-
})), /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.IconButton, {
|
|
646
|
-
icon: "ph--trash--regular",
|
|
647
|
-
iconOnly: true,
|
|
648
|
-
label: t("button remove"),
|
|
649
|
-
onClick: () => {
|
|
650
|
-
const newValues = arrayValues.filter((_, i) => i !== index);
|
|
651
|
-
inputProps.onValueChange(name, type, newValues);
|
|
652
|
-
}
|
|
653
|
-
}));
|
|
654
|
-
})), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
655
|
-
role: "none",
|
|
656
|
-
className: "flex justify-between items-center plb-1"
|
|
657
|
-
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.IconButton, {
|
|
658
|
-
icon: "ph--plus--regular",
|
|
659
|
-
iconOnly: true,
|
|
660
|
-
label: t("button add"),
|
|
661
|
-
onClick: () => {
|
|
662
|
-
const newValues = [
|
|
663
|
-
...arrayValues,
|
|
664
|
-
{}
|
|
665
|
-
];
|
|
666
|
-
inputProps.onValueChange(name, type, newValues);
|
|
667
|
-
}
|
|
668
|
-
})));
|
|
669
|
-
}
|
|
670
|
-
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
671
|
-
key: name,
|
|
672
|
-
role: "none"
|
|
673
|
-
}, "Nested form not supported in arrays, yet.");
|
|
674
|
-
}
|
|
675
|
-
const InputComponent = getInputComponent(type, format);
|
|
676
|
-
if (!InputComponent) {
|
|
794
|
+
if (!elementType) {
|
|
677
795
|
return null;
|
|
678
796
|
}
|
|
679
|
-
return /* @__PURE__ */
|
|
797
|
+
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
680
798
|
role: "none",
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
799
|
+
className: (0, import_react_ui_theme8.mx)(padding)
|
|
800
|
+
}, /* @__PURE__ */ import_react13.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
684
801
|
role: "none",
|
|
685
802
|
className: "flex flex-col gap-1"
|
|
686
|
-
},
|
|
803
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
687
804
|
key: index,
|
|
688
805
|
role: "none",
|
|
689
|
-
className: "flex items-
|
|
690
|
-
}, /* @__PURE__ */
|
|
806
|
+
className: "flex items-center gap-1"
|
|
807
|
+
}, /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
691
808
|
role: "none",
|
|
692
809
|
className: "flex-1"
|
|
693
|
-
}, /* @__PURE__ */
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
810
|
+
}, /* @__PURE__ */ import_react13.default.createElement(FormField, {
|
|
811
|
+
property: {
|
|
812
|
+
...property,
|
|
813
|
+
array: false,
|
|
814
|
+
ast: elementType
|
|
815
|
+
},
|
|
816
|
+
path: [
|
|
817
|
+
...path ?? [],
|
|
818
|
+
index
|
|
819
|
+
],
|
|
820
|
+
readonly,
|
|
821
|
+
inline: true,
|
|
822
|
+
Custom,
|
|
823
|
+
lookupComponent
|
|
824
|
+
})), /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
703
825
|
icon: "ph--trash--regular",
|
|
704
826
|
iconOnly: true,
|
|
705
827
|
label: t("button remove"),
|
|
706
|
-
onClick: () =>
|
|
707
|
-
|
|
708
|
-
inputProps.onValueChange(name, type, newValues);
|
|
709
|
-
}
|
|
710
|
-
})))), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
828
|
+
onClick: () => handleRemove(index)
|
|
829
|
+
})))), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
711
830
|
role: "none",
|
|
712
831
|
className: "flex justify-between items-center plb-1"
|
|
713
|
-
}, /* @__PURE__ */
|
|
832
|
+
}, /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
714
833
|
icon: "ph--plus--regular",
|
|
715
834
|
iconOnly: true,
|
|
716
835
|
label: t("button add"),
|
|
717
|
-
onClick:
|
|
718
|
-
const newValues = [
|
|
719
|
-
...arrayValues,
|
|
720
|
-
import_effect2.SimpleType.getDefaultValue(type)
|
|
721
|
-
];
|
|
722
|
-
inputProps.onValueChange(name, type, newValues);
|
|
723
|
-
}
|
|
836
|
+
onClick: handleAdd
|
|
724
837
|
})));
|
|
725
838
|
};
|
|
726
|
-
var
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
839
|
+
var getInputComponent = (type, format) => {
|
|
840
|
+
switch (format) {
|
|
841
|
+
case import_echo_schema6.FormatEnum.LatLng:
|
|
842
|
+
return GeoPointInput;
|
|
843
|
+
}
|
|
844
|
+
switch (type) {
|
|
845
|
+
case "string":
|
|
846
|
+
return TextInput;
|
|
847
|
+
case "number":
|
|
848
|
+
return NumberInput;
|
|
849
|
+
case "boolean":
|
|
850
|
+
return BooleanInput;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
854
|
+
const inputProps = useInputProps(path);
|
|
855
|
+
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
856
|
+
const label = (0, import_react12.useMemo)(() => title ?? (0, import_effect3.pipe)(name, import_String.capitalize), [
|
|
857
|
+
title,
|
|
858
|
+
name
|
|
859
|
+
]);
|
|
860
|
+
const placeholder = (0, import_react12.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
861
|
+
examples,
|
|
862
|
+
description
|
|
863
|
+
]);
|
|
864
|
+
const FoundComponent = lookupComponent?.({
|
|
865
|
+
prop: name,
|
|
866
|
+
schema: import_echo_schema4.S.make(ast),
|
|
867
|
+
inputProps: {
|
|
868
|
+
type,
|
|
869
|
+
format,
|
|
870
|
+
label,
|
|
871
|
+
disabled: readonly,
|
|
872
|
+
placeholder,
|
|
873
|
+
...inputProps
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
if (FoundComponent) {
|
|
877
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
878
|
+
role: "none"
|
|
879
|
+
}, FoundComponent);
|
|
880
|
+
}
|
|
881
|
+
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
882
|
+
const CustomComponent = Custom?.[jsonPath];
|
|
883
|
+
if (CustomComponent) {
|
|
884
|
+
return (
|
|
885
|
+
// TODO(ZaymonFC): We should try to remove this div wrapper.
|
|
886
|
+
/* @__PURE__ */ import_react12.default.createElement("div", {
|
|
887
|
+
role: "none"
|
|
888
|
+
}, /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
889
|
+
type,
|
|
890
|
+
format,
|
|
891
|
+
label,
|
|
892
|
+
inputOnly: inline,
|
|
893
|
+
placeholder,
|
|
894
|
+
disabled: readonly,
|
|
895
|
+
...inputProps
|
|
896
|
+
}))
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
if (array) {
|
|
900
|
+
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
901
|
+
property,
|
|
902
|
+
path,
|
|
903
|
+
inputProps,
|
|
904
|
+
readonly,
|
|
905
|
+
Custom
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
const InputComponent = getInputComponent(type, format);
|
|
909
|
+
if (InputComponent) {
|
|
910
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
911
|
+
role: "none"
|
|
912
|
+
}, /* @__PURE__ */ import_react12.default.createElement(InputComponent, {
|
|
913
|
+
type,
|
|
914
|
+
format,
|
|
915
|
+
label,
|
|
916
|
+
inputOnly: inline,
|
|
917
|
+
placeholder,
|
|
918
|
+
disabled: readonly,
|
|
919
|
+
...inputProps
|
|
920
|
+
}));
|
|
921
|
+
}
|
|
922
|
+
if (options) {
|
|
923
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
924
|
+
role: "none"
|
|
925
|
+
}, /* @__PURE__ */ import_react12.default.createElement(SelectInput, {
|
|
926
|
+
type,
|
|
927
|
+
format,
|
|
928
|
+
disabled: readonly,
|
|
929
|
+
inputOnly: inline,
|
|
930
|
+
label,
|
|
931
|
+
options: options.map((option) => ({
|
|
932
|
+
value: option,
|
|
933
|
+
label: String(option)
|
|
934
|
+
})),
|
|
935
|
+
placeholder,
|
|
936
|
+
...inputProps
|
|
937
|
+
}));
|
|
938
|
+
}
|
|
939
|
+
if (type === "object") {
|
|
940
|
+
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
941
|
+
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema4.AST.isTypeLiteral);
|
|
942
|
+
if (typeLiteral) {
|
|
943
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
944
|
+
role: "none"
|
|
945
|
+
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
946
|
+
schema: import_echo_schema4.S.make(typeLiteral),
|
|
947
|
+
path,
|
|
948
|
+
readonly,
|
|
949
|
+
Custom
|
|
950
|
+
}));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return null;
|
|
954
|
+
};
|
|
955
|
+
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
956
|
+
const values = useFormValues(path);
|
|
957
|
+
const properties = (0, import_react12.useMemo)(() => {
|
|
958
|
+
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
959
|
+
const filtered = filter ? filter(props) : props;
|
|
960
|
+
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
961
|
+
}, [
|
|
962
|
+
schema,
|
|
963
|
+
values,
|
|
964
|
+
filter,
|
|
965
|
+
sort
|
|
966
|
+
]);
|
|
967
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
968
|
+
role: "form",
|
|
969
|
+
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2 py-2")
|
|
970
|
+
}, properties.map((property) => {
|
|
971
|
+
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
972
|
+
key: property.name,
|
|
973
|
+
property,
|
|
974
|
+
path: [
|
|
975
|
+
...path ?? [],
|
|
976
|
+
property.name
|
|
977
|
+
],
|
|
978
|
+
readonly,
|
|
979
|
+
lookupComponent,
|
|
980
|
+
Custom
|
|
981
|
+
});
|
|
982
|
+
}).filter(import_util3.isNotFalsy));
|
|
983
|
+
};
|
|
984
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
985
|
+
const onValid = (0, import_react8.useMemo)(() => autoSave ? onSave : void 0, [
|
|
986
|
+
autoSave,
|
|
987
|
+
onSave
|
|
988
|
+
]);
|
|
989
|
+
(0, import_react8.useEffect)(() => {
|
|
990
|
+
if (autoFocus) {
|
|
991
|
+
const input = document.querySelector("input");
|
|
992
|
+
if (input) {
|
|
993
|
+
input.focus();
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}, [
|
|
997
|
+
autoFocus
|
|
998
|
+
]);
|
|
999
|
+
return /* @__PURE__ */ import_react8.default.createElement(FormProvider, {
|
|
1000
|
+
schema,
|
|
1001
|
+
initialValues,
|
|
1002
|
+
onValuesChanged,
|
|
1003
|
+
onValidate,
|
|
1004
|
+
onValid,
|
|
1005
|
+
onSave
|
|
1006
|
+
}, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
732
1007
|
role: "none",
|
|
733
|
-
className: (0,
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
1008
|
+
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
1009
|
+
"data-testid": testId
|
|
1010
|
+
}, /* @__PURE__ */ import_react8.default.createElement(FormFields, {
|
|
1011
|
+
schema,
|
|
1012
|
+
path,
|
|
1013
|
+
readonly,
|
|
1014
|
+
filter,
|
|
1015
|
+
sort,
|
|
1016
|
+
lookupComponent,
|
|
1017
|
+
Custom
|
|
1018
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react8.default.createElement(FormActions, {
|
|
1019
|
+
onCancel,
|
|
1020
|
+
readonly
|
|
746
1021
|
})));
|
|
747
1022
|
};
|
|
748
1023
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
@@ -758,9 +1033,11 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
758
1033
|
if (!registry) {
|
|
759
1034
|
return;
|
|
760
1035
|
}
|
|
761
|
-
const subscription = registry.subscribe(setSchemas)
|
|
1036
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
1037
|
+
fire: true
|
|
1038
|
+
});
|
|
762
1039
|
const t2 = setTimeout(async () => {
|
|
763
|
-
const schemas2 = await registry.query();
|
|
1040
|
+
const schemas2 = await registry.query().run();
|
|
764
1041
|
setSchemas(schemas2);
|
|
765
1042
|
});
|
|
766
1043
|
return () => {
|
|
@@ -770,9 +1047,9 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
770
1047
|
}, [
|
|
771
1048
|
registry
|
|
772
1049
|
]);
|
|
773
|
-
const [
|
|
1050
|
+
const [referenceSchema, setReferenceSchema] = (0, import_react2.useState)();
|
|
774
1051
|
(0, import_react2.useEffect)(() => {
|
|
775
|
-
|
|
1052
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
776
1053
|
}, [
|
|
777
1054
|
schemas,
|
|
778
1055
|
props?.referenceSchema
|
|
@@ -781,14 +1058,24 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
781
1058
|
fieldSchema: (0, import_schema.getFormatSchema)(props?.format)
|
|
782
1059
|
});
|
|
783
1060
|
const handleValuesChanged = (0, import_react2.useCallback)((_props) => {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
1061
|
+
setFieldSchema((prev) => {
|
|
1062
|
+
const fieldSchema2 = (0, import_schema.getFormatSchema)(_props.format);
|
|
1063
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
1064
|
+
return prev;
|
|
1065
|
+
}
|
|
1066
|
+
return {
|
|
1067
|
+
fieldSchema: fieldSchema2
|
|
1068
|
+
};
|
|
1069
|
+
});
|
|
1070
|
+
setReferenceSchema((prev) => {
|
|
1071
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
1072
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
1073
|
+
if (newSchema) {
|
|
1074
|
+
return newSchema;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
return prev;
|
|
1078
|
+
});
|
|
792
1079
|
setProps((props2) => {
|
|
793
1080
|
const type = import_echo_schema.formatToType[_props.format];
|
|
794
1081
|
if (props2.type !== type) {
|
|
@@ -798,11 +1085,12 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
798
1085
|
type
|
|
799
1086
|
};
|
|
800
1087
|
}
|
|
801
|
-
return
|
|
1088
|
+
return _props;
|
|
802
1089
|
});
|
|
803
1090
|
}, [
|
|
804
1091
|
schemas,
|
|
805
|
-
props
|
|
1092
|
+
props.format,
|
|
1093
|
+
props.referenceSchema
|
|
806
1094
|
]);
|
|
807
1095
|
const handleValidate = (0, import_react2.useCallback)(({ property }) => {
|
|
808
1096
|
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
@@ -834,12 +1122,39 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
834
1122
|
}, [
|
|
835
1123
|
onSave
|
|
836
1124
|
]);
|
|
1125
|
+
const Custom = (0, import_react2.useMemo)(() => ({
|
|
1126
|
+
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
1127
|
+
...props2,
|
|
1128
|
+
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
1129
|
+
value,
|
|
1130
|
+
label: t(`format ${value}`)
|
|
1131
|
+
}))
|
|
1132
|
+
}),
|
|
1133
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
1134
|
+
...props2,
|
|
1135
|
+
options: schemas.map((schema) => ({
|
|
1136
|
+
value: schema.typename
|
|
1137
|
+
}))
|
|
1138
|
+
}),
|
|
1139
|
+
["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
1140
|
+
...props2,
|
|
1141
|
+
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
1142
|
+
value: p.name
|
|
1143
|
+
})) : []
|
|
1144
|
+
}),
|
|
1145
|
+
["options"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectOptionInput, props2)
|
|
1146
|
+
}), [
|
|
1147
|
+
t,
|
|
1148
|
+
schemas,
|
|
1149
|
+
referenceSchema
|
|
1150
|
+
]);
|
|
1151
|
+
const propIsNotType = (0, import_react2.useCallback)((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
837
1152
|
if (!fieldSchema) {
|
|
838
1153
|
import_log.log.warn("invalid format", {
|
|
839
1154
|
props
|
|
840
1155
|
}, {
|
|
841
1156
|
F: __dxlog_file3,
|
|
842
|
-
L:
|
|
1157
|
+
L: 174,
|
|
843
1158
|
S: void 0,
|
|
844
1159
|
C: (f, a) => f(...a)
|
|
845
1160
|
});
|
|
@@ -850,7 +1165,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
850
1165
|
autoFocus: true,
|
|
851
1166
|
values: props,
|
|
852
1167
|
schema: fieldSchema,
|
|
853
|
-
filter:
|
|
1168
|
+
filter: propIsNotType,
|
|
854
1169
|
sort: [
|
|
855
1170
|
"property",
|
|
856
1171
|
"format"
|
|
@@ -859,46 +1174,26 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
859
1174
|
onValidate: handleValidate,
|
|
860
1175
|
onSave: handleSave,
|
|
861
1176
|
onCancel: handleCancel,
|
|
862
|
-
Custom
|
|
863
|
-
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
864
|
-
...props2,
|
|
865
|
-
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
866
|
-
value,
|
|
867
|
-
label: t(`format ${value}`)
|
|
868
|
-
}))
|
|
869
|
-
}),
|
|
870
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
871
|
-
...props2,
|
|
872
|
-
options: schemas.map((schema2) => ({
|
|
873
|
-
value: schema2.typename
|
|
874
|
-
}))
|
|
875
|
-
}),
|
|
876
|
-
["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
877
|
-
...props2,
|
|
878
|
-
options: schema ? (0, import_schema.getSchemaProperties)(schema.schema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
879
|
-
value: p.name
|
|
880
|
-
})) : []
|
|
881
|
-
})
|
|
882
|
-
}
|
|
1177
|
+
Custom
|
|
883
1178
|
});
|
|
884
1179
|
};
|
|
885
1180
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
886
|
-
var ViewMetaSchema =
|
|
887
|
-
name:
|
|
888
|
-
[
|
|
1181
|
+
var ViewMetaSchema = import_echo_schema7.S.Struct({
|
|
1182
|
+
name: import_echo_schema7.S.String.annotations({
|
|
1183
|
+
[import_echo_schema7.AST.TitleAnnotationId]: "View"
|
|
889
1184
|
}),
|
|
890
|
-
typename:
|
|
891
|
-
[
|
|
1185
|
+
typename: import_echo_schema7.Format.DXN.annotations({
|
|
1186
|
+
[import_echo_schema7.AST.TitleAnnotationId]: "Typename"
|
|
892
1187
|
})
|
|
893
|
-
}).pipe(
|
|
894
|
-
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
895
|
-
const { t } = (0,
|
|
896
|
-
const projection = (0,
|
|
1188
|
+
}).pipe(import_echo_schema7.S.mutable);
|
|
1189
|
+
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1190
|
+
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1191
|
+
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
897
1192
|
schema,
|
|
898
1193
|
view
|
|
899
1194
|
]);
|
|
900
|
-
const [field, setField] = (0,
|
|
901
|
-
const viewValues = (0,
|
|
1195
|
+
const [field, setField] = (0, import_react14.useState)();
|
|
1196
|
+
const viewValues = (0, import_react14.useMemo)(() => {
|
|
902
1197
|
return {
|
|
903
1198
|
name: view.name,
|
|
904
1199
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -908,82 +1203,91 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
908
1203
|
}, [
|
|
909
1204
|
view
|
|
910
1205
|
]);
|
|
911
|
-
const handleViewUpdate = (0,
|
|
1206
|
+
const handleViewUpdate = (0, import_react14.useCallback)(({ name, typename }) => {
|
|
912
1207
|
requestAnimationFrame(() => {
|
|
913
|
-
view.name
|
|
914
|
-
|
|
915
|
-
|
|
1208
|
+
if (view.name !== name) {
|
|
1209
|
+
view.name = name;
|
|
1210
|
+
}
|
|
1211
|
+
if (view.query.type !== typename) {
|
|
1212
|
+
onTypenameChanged(typename);
|
|
1213
|
+
}
|
|
916
1214
|
});
|
|
917
1215
|
}, [
|
|
918
1216
|
view,
|
|
919
|
-
schema
|
|
1217
|
+
schema,
|
|
1218
|
+
onTypenameChanged
|
|
920
1219
|
]);
|
|
921
|
-
const handleSelect = (0,
|
|
1220
|
+
const handleSelect = (0, import_react14.useCallback)((field2) => {
|
|
922
1221
|
setField((f) => f === field2 ? void 0 : field2);
|
|
923
1222
|
}, []);
|
|
924
|
-
const handleAdd = (0,
|
|
1223
|
+
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
925
1224
|
const field2 = projection.createFieldProjection();
|
|
926
1225
|
setField(field2);
|
|
927
1226
|
}, [
|
|
928
1227
|
view
|
|
929
1228
|
]);
|
|
930
|
-
const handleMove = (0,
|
|
931
|
-
|
|
1229
|
+
const handleMove = (0, import_react14.useCallback)((fromIndex, toIndex) => {
|
|
1230
|
+
const fields = [
|
|
1231
|
+
...view.fields
|
|
1232
|
+
];
|
|
1233
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
1234
|
+
fields.splice(toIndex, 0, moved);
|
|
1235
|
+
view.fields = fields;
|
|
932
1236
|
}, [
|
|
933
1237
|
view.fields
|
|
934
1238
|
]);
|
|
935
|
-
const handleClose = (0,
|
|
936
|
-
return /* @__PURE__ */
|
|
1239
|
+
const handleClose = (0, import_react14.useCallback)(() => setField(void 0), []);
|
|
1240
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
937
1241
|
role: "none",
|
|
938
|
-
className: (0,
|
|
939
|
-
}, /* @__PURE__ */
|
|
1242
|
+
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1243
|
+
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
940
1244
|
autoFocus: true,
|
|
941
1245
|
autoSave: true,
|
|
942
1246
|
schema: ViewMetaSchema,
|
|
943
1247
|
values: viewValues,
|
|
944
1248
|
onSave: handleViewUpdate
|
|
945
|
-
}), /* @__PURE__ */
|
|
1249
|
+
}), /* @__PURE__ */ import_react14.default.createElement("div", null, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
946
1250
|
role: "none",
|
|
947
1251
|
className: "p-2"
|
|
948
|
-
}, /* @__PURE__ */
|
|
949
|
-
className: (0,
|
|
950
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1252
|
+
}, /* @__PURE__ */ import_react14.default.createElement("label", {
|
|
1253
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1254
|
+
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
951
1255
|
items: view.fields,
|
|
952
|
-
isItem:
|
|
1256
|
+
isItem: import_echo_schema7.S.is(import_schema5.FieldSchema),
|
|
953
1257
|
getId: (field2) => field2.id,
|
|
954
1258
|
onMove: handleMove
|
|
955
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1259
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
956
1260
|
role: "heading",
|
|
957
1261
|
className: grid
|
|
958
|
-
}, /* @__PURE__ */
|
|
1262
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", null), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
959
1263
|
className: "flex items-center text-sm"
|
|
960
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1264
|
+
}, t("field path label"))), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
961
1265
|
role: "list",
|
|
962
1266
|
className: "flex flex-col w-full"
|
|
963
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1267
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Item, {
|
|
964
1268
|
key: field2.id,
|
|
965
1269
|
item: field2,
|
|
966
|
-
classNames: (0,
|
|
967
|
-
}, /* @__PURE__ */
|
|
1270
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1271
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
968
1272
|
onClick: () => handleSelect(field2)
|
|
969
|
-
}, field2.path), /* @__PURE__ */
|
|
1273
|
+
}, field2.path), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
970
1274
|
disabled: view.fields.length <= 1,
|
|
971
1275
|
onClick: () => onDelete(field2.id)
|
|
972
|
-
}))))))), field && /* @__PURE__ */
|
|
1276
|
+
}))))))), field && /* @__PURE__ */ import_react14.default.createElement(FieldEditor, {
|
|
973
1277
|
key: field.id,
|
|
974
1278
|
view,
|
|
975
1279
|
projection,
|
|
976
1280
|
field,
|
|
977
1281
|
registry,
|
|
978
1282
|
onSave: handleClose
|
|
979
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1283
|
+
}), !readonly && !field && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
980
1284
|
className: "flex p-2 justify-center"
|
|
981
|
-
}, /* @__PURE__ */
|
|
1285
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
982
1286
|
icon: "ph--plus--regular",
|
|
983
1287
|
label: t("button add property"),
|
|
984
1288
|
onClick: handleAdd,
|
|
985
1289
|
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
986
|
-
disabled: view.fields.length >=
|
|
1290
|
+
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
987
1291
|
})));
|
|
988
1292
|
};
|
|
989
1293
|
var parseValue = ({ type, format, value }) => {
|
|
@@ -992,7 +1296,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
992
1296
|
}
|
|
993
1297
|
const parseScalar = (type2) => {
|
|
994
1298
|
switch (type2) {
|
|
995
|
-
case
|
|
1299
|
+
case import_echo_schema8.TypeEnum.Boolean: {
|
|
996
1300
|
if (typeof value === "string") {
|
|
997
1301
|
const lowercaseValue = value.toLowerCase();
|
|
998
1302
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1003,13 +1307,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1003
1307
|
}
|
|
1004
1308
|
return Boolean(value);
|
|
1005
1309
|
}
|
|
1006
|
-
case
|
|
1310
|
+
case import_echo_schema8.TypeEnum.Number: {
|
|
1007
1311
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1008
1312
|
const num = Number(cleaned);
|
|
1009
1313
|
return Number.isNaN(num) ? null : num;
|
|
1010
1314
|
}
|
|
1011
|
-
case
|
|
1012
|
-
case
|
|
1315
|
+
case import_echo_schema8.TypeEnum.String:
|
|
1316
|
+
case import_echo_schema8.TypeEnum.Ref:
|
|
1013
1317
|
return String(value);
|
|
1014
1318
|
default: {
|
|
1015
1319
|
return value;
|
|
@@ -1020,22 +1324,22 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1020
1324
|
return parseScalar(type);
|
|
1021
1325
|
}
|
|
1022
1326
|
switch (format) {
|
|
1023
|
-
case
|
|
1024
|
-
return parseScalar(
|
|
1025
|
-
case
|
|
1026
|
-
case
|
|
1027
|
-
case
|
|
1028
|
-
return parseScalar(
|
|
1029
|
-
case
|
|
1030
|
-
case
|
|
1031
|
-
return parseScalar(
|
|
1327
|
+
case import_echo_schema8.FormatEnum.Boolean:
|
|
1328
|
+
return parseScalar(import_echo_schema8.TypeEnum.Boolean);
|
|
1329
|
+
case import_echo_schema8.FormatEnum.Number:
|
|
1330
|
+
case import_echo_schema8.FormatEnum.Percent:
|
|
1331
|
+
case import_echo_schema8.FormatEnum.Currency:
|
|
1332
|
+
return parseScalar(import_echo_schema8.TypeEnum.Number);
|
|
1333
|
+
case import_echo_schema8.FormatEnum.String:
|
|
1334
|
+
case import_echo_schema8.FormatEnum.Markdown: {
|
|
1335
|
+
return parseScalar(import_echo_schema8.TypeEnum.String);
|
|
1032
1336
|
}
|
|
1033
|
-
case
|
|
1034
|
-
throw new Error(`unexpected format: ${
|
|
1035
|
-
case
|
|
1036
|
-
case
|
|
1037
|
-
case
|
|
1038
|
-
case
|
|
1337
|
+
case import_echo_schema8.FormatEnum.Ref:
|
|
1338
|
+
throw new Error(`unexpected format: ${import_echo_schema8.FormatEnum.Ref}`);
|
|
1339
|
+
case import_echo_schema8.FormatEnum.DateTime:
|
|
1340
|
+
case import_echo_schema8.FormatEnum.Date:
|
|
1341
|
+
case import_echo_schema8.FormatEnum.Time:
|
|
1342
|
+
case import_echo_schema8.FormatEnum.Timestamp: {
|
|
1039
1343
|
const date = new Date(value);
|
|
1040
1344
|
return isNaN(date.getTime()) ? null : date;
|
|
1041
1345
|
}
|
|
@@ -1047,19 +1351,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1047
1351
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1048
1352
|
if (!format) {
|
|
1049
1353
|
switch (type) {
|
|
1050
|
-
case
|
|
1354
|
+
case import_echo_schema8.TypeEnum.Number:
|
|
1051
1355
|
return [
|
|
1052
1356
|
"text-right",
|
|
1053
1357
|
"font-mono"
|
|
1054
1358
|
];
|
|
1055
|
-
case
|
|
1359
|
+
case import_echo_schema8.TypeEnum.Boolean:
|
|
1056
1360
|
return [
|
|
1057
1361
|
"text-right",
|
|
1058
1362
|
"font-mono"
|
|
1059
1363
|
];
|
|
1060
|
-
case
|
|
1364
|
+
case import_echo_schema8.TypeEnum.String:
|
|
1061
1365
|
return void 0;
|
|
1062
|
-
case
|
|
1366
|
+
case import_echo_schema8.TypeEnum.Ref:
|
|
1063
1367
|
return void 0;
|
|
1064
1368
|
default: {
|
|
1065
1369
|
return void 0;
|
|
@@ -1067,20 +1371,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1067
1371
|
}
|
|
1068
1372
|
}
|
|
1069
1373
|
switch (format) {
|
|
1070
|
-
case
|
|
1374
|
+
case import_echo_schema8.FormatEnum.Markdown:
|
|
1071
1375
|
return void 0;
|
|
1072
|
-
case
|
|
1073
|
-
case
|
|
1074
|
-
case
|
|
1075
|
-
case
|
|
1376
|
+
case import_echo_schema8.FormatEnum.Timestamp:
|
|
1377
|
+
case import_echo_schema8.FormatEnum.DateTime:
|
|
1378
|
+
case import_echo_schema8.FormatEnum.Date:
|
|
1379
|
+
case import_echo_schema8.FormatEnum.Time:
|
|
1076
1380
|
return [
|
|
1077
1381
|
"font-mono"
|
|
1078
1382
|
];
|
|
1079
|
-
case
|
|
1383
|
+
case import_echo_schema8.FormatEnum.Currency:
|
|
1080
1384
|
return [
|
|
1081
1385
|
"text-right"
|
|
1082
1386
|
];
|
|
1083
|
-
case
|
|
1387
|
+
case import_echo_schema8.FormatEnum.JSON:
|
|
1084
1388
|
return [
|
|
1085
1389
|
"font-mono"
|
|
1086
1390
|
];
|
|
@@ -1098,12 +1402,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1098
1402
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1099
1403
|
const formatScalar = (type2) => {
|
|
1100
1404
|
switch (type2) {
|
|
1101
|
-
case
|
|
1405
|
+
case import_echo_schema9.TypeEnum.Boolean:
|
|
1102
1406
|
return value.toLocaleString().toUpperCase();
|
|
1103
|
-
case
|
|
1407
|
+
case import_echo_schema9.TypeEnum.Number:
|
|
1104
1408
|
return value.toLocaleString(locale);
|
|
1105
|
-
case
|
|
1106
|
-
case
|
|
1409
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1410
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1107
1411
|
return String(value);
|
|
1108
1412
|
default: {
|
|
1109
1413
|
return String(value);
|
|
@@ -1114,20 +1418,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1114
1418
|
return formatScalar(type);
|
|
1115
1419
|
}
|
|
1116
1420
|
switch (format) {
|
|
1117
|
-
case
|
|
1118
|
-
return formatScalar(
|
|
1421
|
+
case import_echo_schema9.FormatEnum.Boolean: {
|
|
1422
|
+
return formatScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1119
1423
|
}
|
|
1120
|
-
case
|
|
1121
|
-
return formatScalar(
|
|
1424
|
+
case import_echo_schema9.FormatEnum.Number: {
|
|
1425
|
+
return formatScalar(import_echo_schema9.TypeEnum.Number);
|
|
1122
1426
|
}
|
|
1123
|
-
case
|
|
1124
|
-
case
|
|
1125
|
-
return formatScalar(
|
|
1427
|
+
case import_echo_schema9.FormatEnum.String:
|
|
1428
|
+
case import_echo_schema9.FormatEnum.Ref: {
|
|
1429
|
+
return formatScalar(import_echo_schema9.TypeEnum.String);
|
|
1126
1430
|
}
|
|
1127
|
-
case
|
|
1431
|
+
case import_echo_schema9.FormatEnum.Percent: {
|
|
1128
1432
|
return `${value * 100}%`;
|
|
1129
1433
|
}
|
|
1130
|
-
case
|
|
1434
|
+
case import_echo_schema9.FormatEnum.Currency: {
|
|
1131
1435
|
return value.toLocaleString(locale, {
|
|
1132
1436
|
style: "currency",
|
|
1133
1437
|
currency: "USD",
|
|
@@ -1135,13 +1439,13 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1135
1439
|
maximumFractionDigits: 2
|
|
1136
1440
|
});
|
|
1137
1441
|
}
|
|
1138
|
-
case
|
|
1139
|
-
case
|
|
1140
|
-
case
|
|
1442
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1443
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1444
|
+
case import_echo_schema9.FormatEnum.Time: {
|
|
1141
1445
|
const date = new Date(value);
|
|
1142
|
-
if (format ===
|
|
1446
|
+
if (format === import_echo_schema9.FormatEnum.DateTime) {
|
|
1143
1447
|
return date.toLocaleString(locale);
|
|
1144
|
-
} else if (format ===
|
|
1448
|
+
} else if (format === import_echo_schema9.FormatEnum.Date) {
|
|
1145
1449
|
return date.toLocaleDateString(locale);
|
|
1146
1450
|
} else {
|
|
1147
1451
|
return date.toLocaleTimeString(locale);
|
|
@@ -1158,10 +1462,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1158
1462
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1159
1463
|
const formatScalar = (type2) => {
|
|
1160
1464
|
switch (type2) {
|
|
1161
|
-
case
|
|
1162
|
-
case
|
|
1163
|
-
case
|
|
1164
|
-
case
|
|
1465
|
+
case import_echo_schema9.TypeEnum.Boolean:
|
|
1466
|
+
case import_echo_schema9.TypeEnum.Number:
|
|
1467
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1468
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1165
1469
|
return String(value);
|
|
1166
1470
|
default:
|
|
1167
1471
|
return String(value);
|
|
@@ -1171,27 +1475,27 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1171
1475
|
return formatScalar(type);
|
|
1172
1476
|
}
|
|
1173
1477
|
switch (format) {
|
|
1174
|
-
case
|
|
1175
|
-
case
|
|
1176
|
-
case
|
|
1177
|
-
case
|
|
1478
|
+
case import_echo_schema9.FormatEnum.Boolean:
|
|
1479
|
+
case import_echo_schema9.FormatEnum.Number:
|
|
1480
|
+
case import_echo_schema9.FormatEnum.String:
|
|
1481
|
+
case import_echo_schema9.FormatEnum.Ref: {
|
|
1178
1482
|
return formatScalar(type);
|
|
1179
1483
|
}
|
|
1180
|
-
case
|
|
1484
|
+
case import_echo_schema9.FormatEnum.Percent: {
|
|
1181
1485
|
return String(value * 100);
|
|
1182
1486
|
}
|
|
1183
|
-
case
|
|
1487
|
+
case import_echo_schema9.FormatEnum.Currency: {
|
|
1184
1488
|
return String(value);
|
|
1185
1489
|
}
|
|
1186
|
-
case
|
|
1490
|
+
case import_echo_schema9.FormatEnum.DateTime: {
|
|
1187
1491
|
const date = new Date(value);
|
|
1188
1492
|
return date.toISOString();
|
|
1189
1493
|
}
|
|
1190
|
-
case
|
|
1494
|
+
case import_echo_schema9.FormatEnum.Date: {
|
|
1191
1495
|
const date = new Date(value);
|
|
1192
1496
|
return date.toISOString().split("T")[0];
|
|
1193
1497
|
}
|
|
1194
|
-
case
|
|
1498
|
+
case import_echo_schema9.FormatEnum.Time: {
|
|
1195
1499
|
const date = new Date(value);
|
|
1196
1500
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1197
1501
|
}
|
|
@@ -1203,15 +1507,17 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1203
1507
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1204
1508
|
0 && (module.exports = {
|
|
1205
1509
|
BooleanInput,
|
|
1510
|
+
DeprecatedFormContainer,
|
|
1206
1511
|
DeprecatedFormInput,
|
|
1207
1512
|
FieldEditor,
|
|
1208
1513
|
Form,
|
|
1209
|
-
|
|
1210
|
-
GeiPointInput,
|
|
1514
|
+
GeoPointInput,
|
|
1211
1515
|
InputHeader,
|
|
1212
1516
|
NumberInput,
|
|
1213
1517
|
SelectInput,
|
|
1518
|
+
SelectOptionInput,
|
|
1214
1519
|
TextInput,
|
|
1520
|
+
TupleInput,
|
|
1215
1521
|
ViewEditor,
|
|
1216
1522
|
cellClassesForFieldType,
|
|
1217
1523
|
cellClassesForRowSelection,
|