@dxos/react-ui-form 0.7.5-labs.a279d8c → 0.7.5-labs.c0e040f
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 +601 -283
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +595 -273
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +601 -283
- 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.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +1 -0
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +3 -2
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +4 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- 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/index.d.ts +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +2 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.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 +1 -0
- 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 -1
- package/package.json +25 -24
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.tsx +3 -2
- package/src/components/Form/ArrayField.tsx +1 -1
- package/src/components/Form/Defaults.tsx +61 -4
- package/src/components/Form/Form.tsx +20 -3
- package/src/components/Form/FormActions.tsx +1 -1
- package/src/components/Form/FormContent.tsx +24 -9
- package/src/components/Form/FormContext.tsx +48 -4
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +58 -0
- package/src/components/Form/custom/SelectOptionsInput.tsx +190 -0
- package/src/components/Form/custom/index.ts +1 -0
- package/src/components/Form/factory.tsx +3 -1
- package/src/components/Form/index.ts +3 -0
- package/src/components/ViewEditor/ViewEditor.tsx +7 -4
- package/src/components/deprecated/FormInput.tsx +20 -7
- package/src/hooks/useForm.ts +6 -1
- package/src/translations.ts +8 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,13 +29,16 @@ 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
|
GeoPointInput: () => GeoPointInput,
|
|
36
37
|
InputHeader: () => InputHeader,
|
|
38
|
+
MarkdownInput: () => MarkdownInput,
|
|
37
39
|
NumberInput: () => NumberInput,
|
|
38
40
|
SelectInput: () => SelectInput,
|
|
41
|
+
SelectOptionInput: () => SelectOptionInput,
|
|
39
42
|
TextInput: () => TextInput,
|
|
40
43
|
TupleInput: () => TupleInput,
|
|
41
44
|
ViewEditor: () => ViewEditor,
|
|
@@ -46,68 +49,75 @@ __export(node_exports, {
|
|
|
46
49
|
parseValue: () => parseValue,
|
|
47
50
|
pathNotUniqueError: () => pathNotUniqueError,
|
|
48
51
|
translations: () => translations_default,
|
|
49
|
-
useForm: () => useForm
|
|
52
|
+
useForm: () => useForm,
|
|
53
|
+
useFormValues: () => useFormValues
|
|
50
54
|
});
|
|
51
55
|
module.exports = __toCommonJS(node_exports);
|
|
52
56
|
var import_react = __toESM(require("react"));
|
|
53
57
|
var import_react_ui = require("@dxos/react-ui");
|
|
58
|
+
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
54
59
|
var import_react2 = __toESM(require("react"));
|
|
55
60
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
56
61
|
var import_log = require("@dxos/log");
|
|
57
62
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
58
63
|
var import_schema = require("@dxos/schema");
|
|
59
64
|
var import_react3 = __toESM(require("react"));
|
|
65
|
+
var import_debug = require("@dxos/debug");
|
|
66
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
67
|
+
var import_effect = require("@dxos/effect");
|
|
68
|
+
var import_react4 = require("react");
|
|
69
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
70
|
+
var import_effect2 = require("@dxos/effect");
|
|
71
|
+
var import_invariant = require("@dxos/invariant");
|
|
72
|
+
var import_log2 = require("@dxos/log");
|
|
73
|
+
var import_schema2 = require("@dxos/schema");
|
|
74
|
+
var import_react5 = __toESM(require("react"));
|
|
60
75
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
61
76
|
var import_util = require("@dxos/util");
|
|
62
|
-
var
|
|
77
|
+
var import_react6 = __toESM(require("react"));
|
|
63
78
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
64
|
-
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
65
|
-
var import_react5 = __toESM(require("react"));
|
|
66
|
-
var import_react_ui5 = require("@dxos/react-ui");
|
|
67
79
|
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
68
|
-
var import_util2 = require("@dxos/util");
|
|
69
|
-
var import_react6 = __toESM(require("react"));
|
|
70
|
-
var import_react_ui6 = require("@dxos/react-ui");
|
|
71
80
|
var import_react7 = __toESM(require("react"));
|
|
81
|
+
var import_keys = require("@dxos/keys");
|
|
82
|
+
var import_react_ui5 = require("@dxos/react-ui");
|
|
83
|
+
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
84
|
+
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
72
85
|
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
73
86
|
var import_react8 = __toESM(require("react"));
|
|
74
|
-
var
|
|
87
|
+
var import_react_ui6 = require("@dxos/react-ui");
|
|
75
88
|
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
89
|
+
var import_util2 = require("@dxos/util");
|
|
76
90
|
var import_react9 = __toESM(require("react"));
|
|
77
|
-
var
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
var import_invariant = require("@dxos/invariant");
|
|
84
|
-
var import_log2 = require("@dxos/log");
|
|
85
|
-
var import_schema2 = require("@dxos/schema");
|
|
91
|
+
var import_react_ui7 = require("@dxos/react-ui");
|
|
92
|
+
var import_react10 = __toESM(require("react"));
|
|
93
|
+
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
94
|
+
var import_react11 = __toESM(require("react"));
|
|
95
|
+
var import_react_ui8 = require("@dxos/react-ui");
|
|
96
|
+
var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
86
97
|
var import_effect3 = require("effect");
|
|
87
98
|
var import_String = require("effect/String");
|
|
88
|
-
var
|
|
99
|
+
var import_react12 = __toESM(require("react"));
|
|
89
100
|
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
90
101
|
var import_effect4 = require("@dxos/effect");
|
|
91
|
-
var
|
|
102
|
+
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
92
103
|
var import_schema3 = require("@dxos/schema");
|
|
93
104
|
var import_util3 = require("@dxos/util");
|
|
94
105
|
var import_effect5 = require("effect");
|
|
95
106
|
var import_String2 = require("effect/String");
|
|
96
|
-
var
|
|
107
|
+
var import_react13 = __toESM(require("react"));
|
|
97
108
|
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
98
109
|
var import_effect6 = require("@dxos/effect");
|
|
99
110
|
var import_invariant2 = require("@dxos/invariant");
|
|
100
|
-
var
|
|
101
|
-
var
|
|
111
|
+
var import_react_ui9 = require("@dxos/react-ui");
|
|
112
|
+
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
102
113
|
var import_schema4 = require("@dxos/schema");
|
|
103
114
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
104
|
-
var
|
|
115
|
+
var import_react14 = __toESM(require("react"));
|
|
105
116
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
106
|
-
var
|
|
107
|
-
var
|
|
108
|
-
var
|
|
117
|
+
var import_react_ui10 = require("@dxos/react-ui");
|
|
118
|
+
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
119
|
+
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
109
120
|
var import_schema5 = require("@dxos/schema");
|
|
110
|
-
var import_util4 = require("@dxos/util");
|
|
111
121
|
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
112
122
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
113
123
|
var translationKey = "react-ui-form";
|
|
@@ -146,6 +156,7 @@ var translations_default = [
|
|
|
146
156
|
"format ref": "Reference",
|
|
147
157
|
"format regex": "RegExp",
|
|
148
158
|
"format string": "String",
|
|
159
|
+
"format single-select": "Select",
|
|
149
160
|
"format text": "Long text",
|
|
150
161
|
"format time": "Time",
|
|
151
162
|
"format timestamp": "Timestamp",
|
|
@@ -155,11 +166,26 @@ var translations_default = [
|
|
|
155
166
|
"format uuid": "UUID",
|
|
156
167
|
// Placeholders
|
|
157
168
|
"placeholder latitude": "Latitude",
|
|
158
|
-
"placeholder longitude": "Longitude"
|
|
169
|
+
"placeholder longitude": "Longitude",
|
|
170
|
+
// SelectOptionsInput
|
|
171
|
+
"select option label": "Label",
|
|
172
|
+
"select option label placeholder": "Option label",
|
|
173
|
+
"select option color": "Color",
|
|
174
|
+
"select option delete": "Delete",
|
|
175
|
+
"select option add": "Add option"
|
|
159
176
|
}
|
|
160
177
|
}
|
|
161
178
|
}
|
|
162
179
|
];
|
|
180
|
+
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
181
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
182
|
+
role: "none",
|
|
183
|
+
className: "w-full p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
184
|
+
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
185
|
+
role: "form",
|
|
186
|
+
className: (0, import_react_ui_theme.mx)("flex flex-col", import_react_ui_theme.textBlockWidth, classNames)
|
|
187
|
+
}, children));
|
|
188
|
+
};
|
|
163
189
|
var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
164
190
|
const primary = /* @__PURE__ */ import_react.default.createElement("div", {
|
|
165
191
|
role: "none",
|
|
@@ -168,179 +194,47 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
168
194
|
role: "none",
|
|
169
195
|
className: "flex flex-col w-full"
|
|
170
196
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Label, {
|
|
171
|
-
classNames: "flex min-
|
|
197
|
+
classNames: "flex min-bs-[--rail-action] items-center",
|
|
198
|
+
style: {
|
|
199
|
+
fontSize: "unset"
|
|
200
|
+
}
|
|
172
201
|
}, label), description && /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.DescriptionAndValidation, {
|
|
173
202
|
classNames: "mbs-0.5"
|
|
174
203
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Description, null, description))), /* @__PURE__ */ import_react.default.createElement("div", {
|
|
175
204
|
role: "none"
|
|
176
205
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
177
206
|
role: "none",
|
|
178
|
-
className: "flex min-
|
|
207
|
+
className: "flex min-bs-[--rail-action] items-center"
|
|
179
208
|
}, children))));
|
|
180
209
|
if (secondary) {
|
|
181
210
|
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
182
|
-
role: "none"
|
|
183
|
-
className: "flex flex-col w-full"
|
|
211
|
+
role: "none"
|
|
184
212
|
}, primary, secondary);
|
|
185
213
|
}
|
|
186
214
|
return primary;
|
|
187
215
|
};
|
|
188
|
-
var InputHeader = ({ children, error }) => {
|
|
189
|
-
return /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
190
|
-
role: "none",
|
|
191
|
-
className: "flex justify-between items-center mb-1"
|
|
192
|
-
}, children, error && /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
193
|
-
asChild: true
|
|
194
|
-
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Icon, {
|
|
195
|
-
icon: "ph--warning--regular",
|
|
196
|
-
size: 4,
|
|
197
|
-
classNames: import_react_ui_theme.errorText
|
|
198
|
-
})), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
199
|
-
side: "bottom"
|
|
200
|
-
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
201
|
-
};
|
|
202
|
-
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
203
|
-
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
204
|
-
const { status, error } = getStatus();
|
|
205
|
-
const [lng = 0, lat = 0] = getValue3() ?? [];
|
|
206
|
-
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Root, {
|
|
207
|
-
validationValence: status
|
|
208
|
-
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, {
|
|
209
|
-
error
|
|
210
|
-
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
211
|
-
className: "grid grid-cols-2 gap-2"
|
|
212
|
-
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
213
|
-
type: "number",
|
|
214
|
-
disabled,
|
|
215
|
-
placeholder: t("placeholder longitude"),
|
|
216
|
-
value: lng,
|
|
217
|
-
onChange: (event) => onValueChange(type, [
|
|
218
|
-
lat,
|
|
219
|
-
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
220
|
-
]),
|
|
221
|
-
onBlur
|
|
222
|
-
}), /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
223
|
-
type: "number",
|
|
224
|
-
disabled,
|
|
225
|
-
placeholder: t("placeholder latitude"),
|
|
226
|
-
value: lat,
|
|
227
|
-
onChange: (event) => onValueChange(type, [
|
|
228
|
-
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
229
|
-
lng
|
|
230
|
-
]),
|
|
231
|
-
onBlur
|
|
232
|
-
})));
|
|
233
|
-
};
|
|
234
|
-
var gridCols = [
|
|
235
|
-
"grid-cols-1",
|
|
236
|
-
"grid-cols-2",
|
|
237
|
-
"grid-cols-3",
|
|
238
|
-
"grid-cols-4"
|
|
239
|
-
];
|
|
240
|
-
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
241
|
-
const { status, error } = getStatus();
|
|
242
|
-
const values = getValue3() ?? {};
|
|
243
|
-
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Root, {
|
|
244
|
-
validationValence: status
|
|
245
|
-
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
246
|
-
error
|
|
247
|
-
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
248
|
-
className: (0, import_react_ui_theme2.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
249
|
-
}, binding.map((prop) => /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.TextInput, {
|
|
250
|
-
key: prop,
|
|
251
|
-
type: "number",
|
|
252
|
-
disabled,
|
|
253
|
-
value: values[prop],
|
|
254
|
-
onChange: (event) => onValueChange(type, {
|
|
255
|
-
...values,
|
|
256
|
-
[prop]: (0, import_util2.safeParseFloat)(event.target.value, 0)
|
|
257
|
-
}),
|
|
258
|
-
onBlur
|
|
259
|
-
}))));
|
|
260
|
-
};
|
|
261
|
-
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
262
|
-
const { status, error } = getStatus();
|
|
263
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
264
|
-
validationValence: status
|
|
265
|
-
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
266
|
-
error
|
|
267
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
268
|
-
disabled,
|
|
269
|
-
placeholder,
|
|
270
|
-
value: getValue3() ?? "",
|
|
271
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
272
|
-
onBlur
|
|
273
|
-
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Validation, null, error));
|
|
274
|
-
};
|
|
275
|
-
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
276
|
-
const { status, error } = getStatus();
|
|
277
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
278
|
-
validationValence: status
|
|
279
|
-
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
280
|
-
error
|
|
281
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
282
|
-
type: "number",
|
|
283
|
-
disabled,
|
|
284
|
-
placeholder,
|
|
285
|
-
value: getValue3() ?? 0,
|
|
286
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
287
|
-
onBlur
|
|
288
|
-
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
289
|
-
};
|
|
290
|
-
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
291
|
-
const { status, error } = getStatus();
|
|
292
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
293
|
-
validationValence: status
|
|
294
|
-
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
295
|
-
error
|
|
296
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Switch, {
|
|
297
|
-
checked: getValue3(),
|
|
298
|
-
onCheckedChange: (value) => onValueChange(type, value)
|
|
299
|
-
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
300
|
-
};
|
|
301
|
-
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
302
|
-
const { status, error } = getStatus();
|
|
303
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
304
|
-
validationValence: status
|
|
305
|
-
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
306
|
-
error
|
|
307
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Root, {
|
|
308
|
-
value: getValue3(),
|
|
309
|
-
onValueChange: (value) => onValueChange(type, value)
|
|
310
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.TriggerButton, {
|
|
311
|
-
classNames: "is-full",
|
|
312
|
-
disabled,
|
|
313
|
-
placeholder
|
|
314
|
-
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Portal, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
315
|
-
// NOTE: Numeric values are converted to and from strings.
|
|
316
|
-
/* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Option, {
|
|
317
|
-
key: String(value),
|
|
318
|
-
value: String(value)
|
|
319
|
-
}, label2 ?? String(value))
|
|
320
|
-
)))))), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
321
|
-
};
|
|
322
216
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
323
217
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
324
218
|
(0, import_invariant.invariant)(import_effect2.AST.isTypeLiteral(schema.ast), void 0, {
|
|
325
219
|
F: __dxlog_file,
|
|
326
|
-
L:
|
|
220
|
+
L: 92,
|
|
327
221
|
S: void 0,
|
|
328
222
|
A: [
|
|
329
223
|
"AST.isTypeLiteral(schema.ast)",
|
|
330
224
|
""
|
|
331
225
|
]
|
|
332
226
|
});
|
|
333
|
-
const [values, setValues] = (0,
|
|
334
|
-
(0,
|
|
227
|
+
const [values, setValues] = (0, import_react4.useState)(initialValues);
|
|
228
|
+
(0, import_react4.useEffect)(() => {
|
|
335
229
|
setValues(initialValues);
|
|
336
230
|
}, [
|
|
337
231
|
initialValues
|
|
338
232
|
]);
|
|
339
|
-
const [touched, setTouched] = (0,
|
|
340
|
-
const [changed, setChanged] = (0,
|
|
341
|
-
const [errors, setErrors] = (0,
|
|
342
|
-
const [saving, setSaving] = (0,
|
|
343
|
-
const validate = (0,
|
|
233
|
+
const [touched, setTouched] = (0, import_react4.useState)(createKeySet(initialValues, false));
|
|
234
|
+
const [changed, setChanged] = (0, import_react4.useState)(createKeySet(initialValues, false));
|
|
235
|
+
const [errors, setErrors] = (0, import_react4.useState)({});
|
|
236
|
+
const [saving, setSaving] = (0, import_react4.useState)(false);
|
|
237
|
+
const validate = (0, import_react4.useCallback)((values2) => {
|
|
344
238
|
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
345
239
|
if (errors2.length === 0 && onValidate) {
|
|
346
240
|
const validatedValues = values2;
|
|
@@ -353,11 +247,11 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
353
247
|
schema,
|
|
354
248
|
onValidate
|
|
355
249
|
]);
|
|
356
|
-
const [schemaDirty, setSchemaDirty] = (0,
|
|
357
|
-
(0,
|
|
250
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react4.useState)(false);
|
|
251
|
+
(0, import_react4.useEffect)(() => setSchemaDirty(true), [
|
|
358
252
|
schema
|
|
359
253
|
]);
|
|
360
|
-
(0,
|
|
254
|
+
(0, import_react4.useEffect)(() => {
|
|
361
255
|
if (schemaDirty) {
|
|
362
256
|
validate(values);
|
|
363
257
|
setSchemaDirty(false);
|
|
@@ -366,13 +260,18 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
366
260
|
values,
|
|
367
261
|
schemaDirty
|
|
368
262
|
]);
|
|
369
|
-
const
|
|
263
|
+
const formIsValid = (0, import_react4.useMemo)(() => {
|
|
264
|
+
return Object.keys(errors).length === 0;
|
|
265
|
+
}, [
|
|
266
|
+
errors
|
|
267
|
+
]);
|
|
268
|
+
const canSave = (0, import_react4.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
370
269
|
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
371
270
|
touched,
|
|
372
271
|
errors,
|
|
373
272
|
saving
|
|
374
273
|
]);
|
|
375
|
-
const handleSave = (0,
|
|
274
|
+
const handleSave = (0, import_react4.useCallback)(async () => {
|
|
376
275
|
if (validate(values)) {
|
|
377
276
|
setSaving(true);
|
|
378
277
|
try {
|
|
@@ -389,7 +288,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
389
288
|
onSave,
|
|
390
289
|
changed
|
|
391
290
|
]);
|
|
392
|
-
const getStatus = (0,
|
|
291
|
+
const getStatus = (0, import_react4.useCallback)((path) => {
|
|
393
292
|
const jsonPath = Array.isArray(path) ? (0, import_effect2.createJsonPath)(path) : path;
|
|
394
293
|
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
395
294
|
return {
|
|
@@ -412,7 +311,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
412
311
|
} catch (err) {
|
|
413
312
|
import_log2.log.catch(err, void 0, {
|
|
414
313
|
F: __dxlog_file,
|
|
415
|
-
L:
|
|
314
|
+
L: 198,
|
|
416
315
|
S: void 0,
|
|
417
316
|
C: (f, a) => f(...a)
|
|
418
317
|
});
|
|
@@ -434,7 +333,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
434
333
|
});
|
|
435
334
|
}
|
|
436
335
|
};
|
|
437
|
-
const onTouched = (0,
|
|
336
|
+
const onTouched = (0, import_react4.useCallback)((path) => {
|
|
438
337
|
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
439
338
|
setTouched((touched2) => ({
|
|
440
339
|
...touched2,
|
|
@@ -453,6 +352,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
453
352
|
changed,
|
|
454
353
|
canSave,
|
|
455
354
|
handleSave,
|
|
355
|
+
formIsValid,
|
|
456
356
|
// Field utils.
|
|
457
357
|
getStatus,
|
|
458
358
|
getValue: getFormValue,
|
|
@@ -463,7 +363,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
463
363
|
var createKeySet = (obj, value) => {
|
|
464
364
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
465
365
|
F: __dxlog_file,
|
|
466
|
-
L:
|
|
366
|
+
L: 241,
|
|
467
367
|
S: void 0,
|
|
468
368
|
A: [
|
|
469
369
|
"obj",
|
|
@@ -484,9 +384,9 @@ var flatMap = (errors) => {
|
|
|
484
384
|
return result;
|
|
485
385
|
}, {});
|
|
486
386
|
};
|
|
487
|
-
var FormContext = /* @__PURE__ */ (0,
|
|
387
|
+
var FormContext = /* @__PURE__ */ (0, import_react3.createContext)(void 0);
|
|
488
388
|
var useFormContext = () => {
|
|
489
|
-
return (0,
|
|
389
|
+
return (0, import_react3.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
490
390
|
};
|
|
491
391
|
var useFormValues = (path = []) => {
|
|
492
392
|
const { values: formValues } = useFormContext();
|
|
@@ -502,27 +402,406 @@ var useInputProps = (path = []) => {
|
|
|
502
402
|
onBlur: () => onTouched(path)
|
|
503
403
|
};
|
|
504
404
|
};
|
|
505
|
-
var FormProvider = ({ children, ...formOptions }) => {
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
405
|
+
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
406
|
+
const form = useForm(formOptions);
|
|
407
|
+
(0, import_react3.useEffect)(() => {
|
|
408
|
+
if (!formRef?.current) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const handleKeyDown = (event) => {
|
|
412
|
+
const keyIsEnter = event.key === "Enter";
|
|
413
|
+
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
414
|
+
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
415
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
416
|
+
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
417
|
+
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
418
|
+
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
419
|
+
if (!autoSave && form.canSave) {
|
|
420
|
+
form.handleSave();
|
|
421
|
+
}
|
|
422
|
+
if (autoSave && form.formIsValid) {
|
|
423
|
+
event.target.blur();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
const formElement = formRef.current;
|
|
428
|
+
formElement.addEventListener("keydown", handleKeyDown);
|
|
429
|
+
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
430
|
+
}, [
|
|
431
|
+
formRef,
|
|
432
|
+
form.canSave,
|
|
433
|
+
form.formIsValid,
|
|
434
|
+
form.handleSave,
|
|
435
|
+
autoSave
|
|
436
|
+
]);
|
|
437
|
+
return /* @__PURE__ */ import_react3.default.createElement(FormContext.Provider, {
|
|
438
|
+
value: form
|
|
509
439
|
}, children);
|
|
510
440
|
};
|
|
441
|
+
var InputHeader = ({ children, error }) => {
|
|
442
|
+
return /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
443
|
+
role: "none",
|
|
444
|
+
className: "flex justify-between items-center mb-1"
|
|
445
|
+
}, children, error && /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
446
|
+
asChild: true
|
|
447
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Icon, {
|
|
448
|
+
icon: "ph--warning--regular",
|
|
449
|
+
size: 4,
|
|
450
|
+
classNames: import_react_ui_theme2.errorText
|
|
451
|
+
})), /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
452
|
+
side: "bottom"
|
|
453
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
454
|
+
};
|
|
455
|
+
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
456
|
+
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
457
|
+
const { status, error } = getStatus();
|
|
458
|
+
const [lng = 0, lat = 0] = getValue3() ?? [];
|
|
459
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Root, {
|
|
460
|
+
validationValence: status
|
|
461
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
462
|
+
error
|
|
463
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
464
|
+
className: "grid grid-cols-2 gap-2"
|
|
465
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
466
|
+
type: "number",
|
|
467
|
+
disabled,
|
|
468
|
+
placeholder: t("placeholder longitude"),
|
|
469
|
+
value: lng,
|
|
470
|
+
onChange: (event) => onValueChange(type, [
|
|
471
|
+
lat,
|
|
472
|
+
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
473
|
+
]),
|
|
474
|
+
onBlur
|
|
475
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
476
|
+
type: "number",
|
|
477
|
+
disabled,
|
|
478
|
+
placeholder: t("placeholder latitude"),
|
|
479
|
+
value: lat,
|
|
480
|
+
onChange: (event) => onValueChange(type, [
|
|
481
|
+
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
482
|
+
lng
|
|
483
|
+
]),
|
|
484
|
+
onBlur
|
|
485
|
+
})));
|
|
486
|
+
};
|
|
487
|
+
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
488
|
+
const [selected, setSelectedId] = (0, import_react7.useState)(null);
|
|
489
|
+
const [isNewOption, setIsNewOption] = (0, import_react7.useState)(false);
|
|
490
|
+
const inputRef = (0, import_react7.useRef)(null);
|
|
491
|
+
const { t } = (0, import_react_ui5.useTranslation)(translationKey);
|
|
492
|
+
const { status, error } = getStatus();
|
|
493
|
+
const options = getValue3();
|
|
494
|
+
(0, import_react7.useEffect)(() => {
|
|
495
|
+
if (options === void 0) {
|
|
496
|
+
onValueChange(type, []);
|
|
497
|
+
}
|
|
498
|
+
}, [
|
|
499
|
+
options,
|
|
500
|
+
onValueChange,
|
|
501
|
+
type
|
|
502
|
+
]);
|
|
503
|
+
const randomHue = () => {
|
|
504
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
505
|
+
const unusedHues = import_react_ui_theme3.hues.filter((hue) => !usedHues.has(hue));
|
|
506
|
+
if (unusedHues.length > 0) {
|
|
507
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
508
|
+
}
|
|
509
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
510
|
+
const availableHues = import_react_ui_theme3.hues.filter((hue) => !lastThree.has(hue));
|
|
511
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? import_react_ui_theme3.hues[Math.floor(Math.random() * import_react_ui_theme3.hues.length)];
|
|
512
|
+
};
|
|
513
|
+
const handleAdd = (0, import_react7.useCallback)(() => {
|
|
514
|
+
const newId = import_keys.PublicKey.random().truncate();
|
|
515
|
+
const newOption = {
|
|
516
|
+
id: newId,
|
|
517
|
+
title: "",
|
|
518
|
+
color: randomHue()
|
|
519
|
+
};
|
|
520
|
+
onValueChange(type, [
|
|
521
|
+
...options ?? [],
|
|
522
|
+
newOption
|
|
523
|
+
]);
|
|
524
|
+
setSelectedId(newId);
|
|
525
|
+
setIsNewOption(true);
|
|
526
|
+
}, [
|
|
527
|
+
options,
|
|
528
|
+
type,
|
|
529
|
+
onValueChange
|
|
530
|
+
]);
|
|
531
|
+
const handleDelete = (0, import_react7.useCallback)((id) => {
|
|
532
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
533
|
+
onValueChange(type, newOptions);
|
|
534
|
+
setSelectedId(null);
|
|
535
|
+
}, [
|
|
536
|
+
options,
|
|
537
|
+
type,
|
|
538
|
+
onValueChange
|
|
539
|
+
]);
|
|
540
|
+
const handleMove = (0, import_react7.useCallback)((from, to) => {
|
|
541
|
+
if (!options) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const newOptions = [
|
|
545
|
+
...options
|
|
546
|
+
];
|
|
547
|
+
const [removed] = newOptions.splice(from, 1);
|
|
548
|
+
newOptions.splice(to, 0, removed);
|
|
549
|
+
onValueChange(type, newOptions);
|
|
550
|
+
}, [
|
|
551
|
+
options,
|
|
552
|
+
type,
|
|
553
|
+
onValueChange
|
|
554
|
+
]);
|
|
555
|
+
const handleClick = (0, import_react7.useCallback)((id) => {
|
|
556
|
+
setSelectedId((current) => current === id ? null : id);
|
|
557
|
+
}, []);
|
|
558
|
+
const handleTitleChange = (0, import_react7.useCallback)((id) => (e) => {
|
|
559
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
560
|
+
...o,
|
|
561
|
+
title: e.target.value
|
|
562
|
+
} : o);
|
|
563
|
+
onValueChange(type, newOptions ?? []);
|
|
564
|
+
}, [
|
|
565
|
+
options,
|
|
566
|
+
type,
|
|
567
|
+
onValueChange
|
|
568
|
+
]);
|
|
569
|
+
const handleKeyDown = (0, import_react7.useCallback)((e) => {
|
|
570
|
+
if (e.key === "Enter") {
|
|
571
|
+
setSelectedId(null);
|
|
572
|
+
}
|
|
573
|
+
}, []);
|
|
574
|
+
const handleColorChange = (0, import_react7.useCallback)((id) => (hue) => {
|
|
575
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
576
|
+
...o,
|
|
577
|
+
color: hue
|
|
578
|
+
} : o);
|
|
579
|
+
onValueChange(type, newOptions ?? []);
|
|
580
|
+
}, [
|
|
581
|
+
options,
|
|
582
|
+
type,
|
|
583
|
+
onValueChange
|
|
584
|
+
]);
|
|
585
|
+
(0, import_react7.useEffect)(() => {
|
|
586
|
+
if (selected && isNewOption && inputRef.current) {
|
|
587
|
+
inputRef.current.focus();
|
|
588
|
+
setIsNewOption(false);
|
|
589
|
+
}
|
|
590
|
+
}, [
|
|
591
|
+
selected,
|
|
592
|
+
isNewOption
|
|
593
|
+
]);
|
|
594
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Root, {
|
|
595
|
+
validationValence: status
|
|
596
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
597
|
+
error
|
|
598
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
599
|
+
role: "none"
|
|
600
|
+
}, options && /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.Root, {
|
|
601
|
+
items: options,
|
|
602
|
+
isItem: (item) => true,
|
|
603
|
+
onMove: handleMove
|
|
604
|
+
}, ({ items }) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
605
|
+
role: "list",
|
|
606
|
+
className: "w-full overflow-auto"
|
|
607
|
+
}, items?.map((item) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
608
|
+
key: item.id
|
|
609
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.Item, {
|
|
610
|
+
role: "button",
|
|
611
|
+
item,
|
|
612
|
+
classNames: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
613
|
+
"aria-expanded": selected === item.id
|
|
614
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
615
|
+
className: "flex items-center"
|
|
616
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
617
|
+
onClick: () => handleClick(item.id),
|
|
618
|
+
classNames: "flex-1"
|
|
619
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tag, {
|
|
620
|
+
palette: item.color
|
|
621
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
622
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
623
|
+
onClick: () => handleClick(item.id)
|
|
624
|
+
})), selected === item.id && /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
625
|
+
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
626
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Label, {
|
|
627
|
+
classNames: "text-xs"
|
|
628
|
+
}, t("select option label")), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
629
|
+
className: "flex flex-row items-center gap-1"
|
|
630
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.TextInput, {
|
|
631
|
+
placeholder: t("select option label placeholder"),
|
|
632
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
633
|
+
value: item.title,
|
|
634
|
+
onChange: handleTitleChange(item.id),
|
|
635
|
+
onKeyDown: handleKeyDown,
|
|
636
|
+
classNames: "flex-1",
|
|
637
|
+
"data-no-submit": true
|
|
638
|
+
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
639
|
+
classNames: "p-0 m-0 !is-auto"
|
|
640
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_pickers.HuePickerToolbarButton, {
|
|
641
|
+
hue: item.color,
|
|
642
|
+
onChangeHue: handleColorChange(item.id)
|
|
643
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.IconButton, {
|
|
644
|
+
icon: "ph--trash--fill",
|
|
645
|
+
iconOnly: true,
|
|
646
|
+
label: t("select option delete"),
|
|
647
|
+
onClick: () => handleDelete(item.id)
|
|
648
|
+
})))))), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
649
|
+
role: "listitem"
|
|
650
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
651
|
+
role: "button",
|
|
652
|
+
className: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
653
|
+
onClick: handleAdd
|
|
654
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
655
|
+
className: "flex items-center gap-1"
|
|
656
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
657
|
+
icon: "ph--plus--regular"
|
|
658
|
+
}), /* @__PURE__ */ import_react7.default.createElement("span", {
|
|
659
|
+
className: "text-sm"
|
|
660
|
+
}, t("select option add")))))))));
|
|
661
|
+
};
|
|
662
|
+
var gridCols = [
|
|
663
|
+
"grid-cols-1",
|
|
664
|
+
"grid-cols-2",
|
|
665
|
+
"grid-cols-3",
|
|
666
|
+
"grid-cols-4"
|
|
667
|
+
];
|
|
668
|
+
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
669
|
+
const { status, error } = getStatus();
|
|
670
|
+
const values = getValue3() ?? {};
|
|
671
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.Root, {
|
|
672
|
+
validationValence: status
|
|
673
|
+
}, /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
674
|
+
error
|
|
675
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
676
|
+
className: (0, import_react_ui_theme4.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
677
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.TextInput, {
|
|
678
|
+
key: prop,
|
|
679
|
+
type: "number",
|
|
680
|
+
disabled,
|
|
681
|
+
value: values[prop],
|
|
682
|
+
onChange: (event) => onValueChange(type, {
|
|
683
|
+
...values,
|
|
684
|
+
[prop]: (0, import_util2.safeParseFloat)(event.target.value, 0)
|
|
685
|
+
}),
|
|
686
|
+
onBlur
|
|
687
|
+
}))));
|
|
688
|
+
};
|
|
689
|
+
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
690
|
+
const { status, error } = getStatus();
|
|
691
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
692
|
+
validationValence: status
|
|
693
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
694
|
+
error
|
|
695
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextInput, {
|
|
696
|
+
disabled,
|
|
697
|
+
placeholder,
|
|
698
|
+
value: getValue3() ?? "",
|
|
699
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
700
|
+
onBlur
|
|
701
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
702
|
+
};
|
|
703
|
+
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
704
|
+
const { status, error } = getStatus();
|
|
705
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
706
|
+
validationValence: status
|
|
707
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
708
|
+
error
|
|
709
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextInput, {
|
|
710
|
+
type: "number",
|
|
711
|
+
disabled,
|
|
712
|
+
placeholder,
|
|
713
|
+
value: getValue3() ?? 0,
|
|
714
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
715
|
+
onBlur
|
|
716
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
717
|
+
};
|
|
718
|
+
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
719
|
+
const { status, error } = getStatus();
|
|
720
|
+
const checked = Boolean(getValue3());
|
|
721
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
722
|
+
validationValence: status
|
|
723
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
724
|
+
error
|
|
725
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Switch, {
|
|
726
|
+
checked,
|
|
727
|
+
onCheckedChange: (value) => onValueChange(type, value)
|
|
728
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
729
|
+
};
|
|
730
|
+
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
731
|
+
const { status, error } = getStatus();
|
|
732
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
733
|
+
validationValence: status
|
|
734
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
735
|
+
error
|
|
736
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Root, {
|
|
737
|
+
value: getValue3(),
|
|
738
|
+
onValueChange: (value) => onValueChange(type, value)
|
|
739
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
740
|
+
classNames: "is-full",
|
|
741
|
+
disabled,
|
|
742
|
+
placeholder
|
|
743
|
+
}), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Portal, null, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Content, null, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
744
|
+
// NOTE: Numeric values are converted to and from strings.
|
|
745
|
+
/* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Option, {
|
|
746
|
+
key: String(value),
|
|
747
|
+
value: String(value)
|
|
748
|
+
}, label2 ?? String(value))
|
|
749
|
+
)))))), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
750
|
+
};
|
|
751
|
+
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
752
|
+
const { status, error } = getStatus();
|
|
753
|
+
const textareaRef = (0, import_react9.useRef)(null);
|
|
754
|
+
const adjustHeight = (0, import_react9.useCallback)(() => {
|
|
755
|
+
const textarea = textareaRef.current;
|
|
756
|
+
if (textarea) {
|
|
757
|
+
textarea.style.blockSize = "auto";
|
|
758
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
759
|
+
}
|
|
760
|
+
}, []);
|
|
761
|
+
(0, import_react9.useEffect)(() => {
|
|
762
|
+
adjustHeight();
|
|
763
|
+
}, [
|
|
764
|
+
adjustHeight
|
|
765
|
+
]);
|
|
766
|
+
(0, import_react9.useEffect)(() => {
|
|
767
|
+
adjustHeight();
|
|
768
|
+
}, [
|
|
769
|
+
getValue3(),
|
|
770
|
+
adjustHeight
|
|
771
|
+
]);
|
|
772
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
773
|
+
validationValence: status
|
|
774
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
775
|
+
error
|
|
776
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextArea, {
|
|
777
|
+
ref: textareaRef,
|
|
778
|
+
disabled,
|
|
779
|
+
placeholder,
|
|
780
|
+
value: getValue3() ?? "",
|
|
781
|
+
classNames: "min-bs-auto overflow-hidden",
|
|
782
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
783
|
+
onBlur,
|
|
784
|
+
style: {
|
|
785
|
+
resize: "none"
|
|
786
|
+
},
|
|
787
|
+
spellCheck: false
|
|
788
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
789
|
+
};
|
|
511
790
|
var FormActions = ({ onCancel, readonly }) => {
|
|
512
|
-
const { t } = (0,
|
|
791
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
513
792
|
const { canSave, handleSave } = useFormContext();
|
|
514
|
-
return /* @__PURE__ */
|
|
793
|
+
return /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
515
794
|
role: "none",
|
|
516
|
-
className: "flex justify-center"
|
|
517
|
-
}, /* @__PURE__ */
|
|
795
|
+
className: "mt-2 flex justify-center"
|
|
796
|
+
}, /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
518
797
|
role: "none",
|
|
519
|
-
className: (0,
|
|
520
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
798
|
+
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
799
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
521
800
|
"data-testid": "cancel-button",
|
|
522
801
|
icon: "ph--x--regular",
|
|
523
802
|
label: t("button cancel"),
|
|
524
803
|
onClick: onCancel
|
|
525
|
-
}), handleSave && /* @__PURE__ */
|
|
804
|
+
}), handleSave && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
526
805
|
type: "submit",
|
|
527
806
|
"data-testid": "save-button",
|
|
528
807
|
disabled: !canSave,
|
|
@@ -534,16 +813,16 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
534
813
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
535
814
|
var padding = "px-2";
|
|
536
815
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
537
|
-
const { t } = (0,
|
|
816
|
+
const { t } = (0, import_react_ui9.useTranslation)(translationKey);
|
|
538
817
|
const { ast, name, type, title } = property;
|
|
539
818
|
const values = useFormValues(path ?? []);
|
|
540
|
-
(0, import_invariant2.invariant)(Array.isArray(values),
|
|
819
|
+
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
541
820
|
F: __dxlog_file2,
|
|
542
821
|
L: 37,
|
|
543
822
|
S: void 0,
|
|
544
823
|
A: [
|
|
545
824
|
"Array.isArray(values)",
|
|
546
|
-
""
|
|
825
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
547
826
|
]
|
|
548
827
|
});
|
|
549
828
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
@@ -560,7 +839,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
560
839
|
prop.defaultValue
|
|
561
840
|
]));
|
|
562
841
|
};
|
|
563
|
-
const newValue = (0,
|
|
842
|
+
const newValue = (0, import_react13.useMemo)(() => {
|
|
564
843
|
if (type === "object" && elementType) {
|
|
565
844
|
return getDefaultObjectValue(elementType);
|
|
566
845
|
} else {
|
|
@@ -570,7 +849,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
570
849
|
type,
|
|
571
850
|
elementType
|
|
572
851
|
]);
|
|
573
|
-
const handleAdd = (0,
|
|
852
|
+
const handleAdd = (0, import_react13.useCallback)(() => {
|
|
574
853
|
inputProps.onValueChange(type, [
|
|
575
854
|
...values,
|
|
576
855
|
newValue
|
|
@@ -582,7 +861,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
582
861
|
newValue,
|
|
583
862
|
values
|
|
584
863
|
]);
|
|
585
|
-
const handleRemove = (0,
|
|
864
|
+
const handleRemove = (0, import_react13.useCallback)((index) => {
|
|
586
865
|
const newValues = values.filter((_, i) => i !== index);
|
|
587
866
|
inputProps.onValueChange(type, newValues);
|
|
588
867
|
}, [
|
|
@@ -593,20 +872,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
593
872
|
if (!elementType) {
|
|
594
873
|
return null;
|
|
595
874
|
}
|
|
596
|
-
return /* @__PURE__ */
|
|
875
|
+
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
597
876
|
role: "none",
|
|
598
|
-
className: (0,
|
|
599
|
-
}, /* @__PURE__ */
|
|
877
|
+
className: (0, import_react_ui_theme8.mx)(padding)
|
|
878
|
+
}, /* @__PURE__ */ import_react13.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
600
879
|
role: "none",
|
|
601
880
|
className: "flex flex-col gap-1"
|
|
602
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
881
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
603
882
|
key: index,
|
|
604
883
|
role: "none",
|
|
605
884
|
className: "flex items-center gap-1"
|
|
606
|
-
}, /* @__PURE__ */
|
|
885
|
+
}, /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
607
886
|
role: "none",
|
|
608
887
|
className: "flex-1"
|
|
609
|
-
}, /* @__PURE__ */
|
|
888
|
+
}, /* @__PURE__ */ import_react13.default.createElement(FormField, {
|
|
610
889
|
property: {
|
|
611
890
|
...property,
|
|
612
891
|
array: false,
|
|
@@ -620,15 +899,15 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
620
899
|
inline: true,
|
|
621
900
|
Custom,
|
|
622
901
|
lookupComponent
|
|
623
|
-
})), /* @__PURE__ */
|
|
902
|
+
})), /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
624
903
|
icon: "ph--trash--regular",
|
|
625
904
|
iconOnly: true,
|
|
626
905
|
label: t("button remove"),
|
|
627
906
|
onClick: () => handleRemove(index)
|
|
628
|
-
})))), /* @__PURE__ */
|
|
907
|
+
})))), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
629
908
|
role: "none",
|
|
630
909
|
className: "flex justify-between items-center plb-1"
|
|
631
|
-
}, /* @__PURE__ */
|
|
910
|
+
}, /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
632
911
|
icon: "ph--plus--regular",
|
|
633
912
|
iconOnly: true,
|
|
634
913
|
label: t("button add"),
|
|
@@ -639,6 +918,8 @@ var getInputComponent = (type, format) => {
|
|
|
639
918
|
switch (format) {
|
|
640
919
|
case import_echo_schema6.FormatEnum.LatLng:
|
|
641
920
|
return GeoPointInput;
|
|
921
|
+
case import_echo_schema6.FormatEnum.Markdown:
|
|
922
|
+
return MarkdownInput;
|
|
642
923
|
}
|
|
643
924
|
switch (type) {
|
|
644
925
|
case "string":
|
|
@@ -652,23 +933,14 @@ var getInputComponent = (type, format) => {
|
|
|
652
933
|
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
653
934
|
const inputProps = useInputProps(path);
|
|
654
935
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
655
|
-
const label = (0,
|
|
936
|
+
const label = (0, import_react12.useMemo)(() => title ?? (0, import_effect3.pipe)(name, import_String.capitalize), [
|
|
656
937
|
title,
|
|
657
938
|
name
|
|
658
939
|
]);
|
|
659
|
-
const placeholder = (0,
|
|
940
|
+
const placeholder = (0, import_react12.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
660
941
|
examples,
|
|
661
942
|
description
|
|
662
943
|
]);
|
|
663
|
-
if (array) {
|
|
664
|
-
return /* @__PURE__ */ import_react11.default.createElement(ArrayField, {
|
|
665
|
-
property,
|
|
666
|
-
path,
|
|
667
|
-
inputProps,
|
|
668
|
-
readonly,
|
|
669
|
-
Custom
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
944
|
const FoundComponent = lookupComponent?.({
|
|
673
945
|
prop: name,
|
|
674
946
|
schema: import_echo_schema4.S.make(ast),
|
|
@@ -682,12 +954,37 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
682
954
|
}
|
|
683
955
|
});
|
|
684
956
|
if (FoundComponent) {
|
|
685
|
-
return /* @__PURE__ */
|
|
957
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
958
|
+
role: "none"
|
|
959
|
+
}, FoundComponent);
|
|
686
960
|
}
|
|
687
961
|
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
688
|
-
const
|
|
962
|
+
const CustomComponent = Custom?.[jsonPath];
|
|
963
|
+
if (CustomComponent) {
|
|
964
|
+
return /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
965
|
+
type,
|
|
966
|
+
format,
|
|
967
|
+
label,
|
|
968
|
+
inputOnly: inline,
|
|
969
|
+
placeholder,
|
|
970
|
+
disabled: readonly,
|
|
971
|
+
...inputProps
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
if (array) {
|
|
975
|
+
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
976
|
+
property,
|
|
977
|
+
path,
|
|
978
|
+
inputProps,
|
|
979
|
+
readonly,
|
|
980
|
+
Custom
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
const InputComponent = getInputComponent(type, format);
|
|
689
984
|
if (InputComponent) {
|
|
690
|
-
return /* @__PURE__ */
|
|
985
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
986
|
+
role: "none"
|
|
987
|
+
}, /* @__PURE__ */ import_react12.default.createElement(InputComponent, {
|
|
691
988
|
type,
|
|
692
989
|
format,
|
|
693
990
|
label,
|
|
@@ -698,9 +995,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
698
995
|
}));
|
|
699
996
|
}
|
|
700
997
|
if (options) {
|
|
701
|
-
return /* @__PURE__ */
|
|
998
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
702
999
|
role: "none"
|
|
703
|
-
}, /* @__PURE__ */
|
|
1000
|
+
}, /* @__PURE__ */ import_react12.default.createElement(SelectInput, {
|
|
704
1001
|
type,
|
|
705
1002
|
format,
|
|
706
1003
|
disabled: readonly,
|
|
@@ -718,7 +1015,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
718
1015
|
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
719
1016
|
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema4.AST.isTypeLiteral);
|
|
720
1017
|
if (typeLiteral) {
|
|
721
|
-
return /* @__PURE__ */
|
|
1018
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
1019
|
+
role: "none"
|
|
1020
|
+
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
722
1021
|
schema: import_echo_schema4.S.make(typeLiteral),
|
|
723
1022
|
path,
|
|
724
1023
|
readonly,
|
|
@@ -730,7 +1029,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
730
1029
|
};
|
|
731
1030
|
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
732
1031
|
const values = useFormValues(path);
|
|
733
|
-
const properties = (0,
|
|
1032
|
+
const properties = (0, import_react12.useMemo)(() => {
|
|
734
1033
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
735
1034
|
const filtered = filter ? filter(props) : props;
|
|
736
1035
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -740,11 +1039,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
740
1039
|
filter,
|
|
741
1040
|
sort
|
|
742
1041
|
]);
|
|
743
|
-
return /* @__PURE__ */
|
|
1042
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
744
1043
|
role: "form",
|
|
745
|
-
className: (0,
|
|
1044
|
+
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2")
|
|
746
1045
|
}, properties.map((property) => {
|
|
747
|
-
return /* @__PURE__ */
|
|
1046
|
+
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
748
1047
|
key: property.name,
|
|
749
1048
|
property,
|
|
750
1049
|
path: [
|
|
@@ -757,23 +1056,37 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
757
1056
|
});
|
|
758
1057
|
}).filter(import_util3.isNotFalsy));
|
|
759
1058
|
};
|
|
760
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
761
|
-
const
|
|
1059
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1060
|
+
const formRef = (0, import_react10.useRef)(null);
|
|
1061
|
+
const onValid = (0, import_react10.useMemo)(() => autoSave ? onSave : void 0, [
|
|
762
1062
|
autoSave,
|
|
763
1063
|
onSave
|
|
764
1064
|
]);
|
|
765
|
-
|
|
1065
|
+
(0, import_react10.useEffect)(() => {
|
|
1066
|
+
if (autoFocus && formRef.current) {
|
|
1067
|
+
const input = formRef.current.querySelector("input");
|
|
1068
|
+
if (input) {
|
|
1069
|
+
input.focus();
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}, [
|
|
1073
|
+
autoFocus
|
|
1074
|
+
]);
|
|
1075
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormProvider, {
|
|
1076
|
+
formRef,
|
|
766
1077
|
schema,
|
|
1078
|
+
autoSave,
|
|
767
1079
|
initialValues,
|
|
768
1080
|
onValuesChanged,
|
|
769
1081
|
onValidate,
|
|
770
1082
|
onValid,
|
|
771
1083
|
onSave
|
|
772
|
-
}, /* @__PURE__ */
|
|
1084
|
+
}, /* @__PURE__ */ import_react10.default.createElement("div", {
|
|
1085
|
+
ref: formRef,
|
|
773
1086
|
role: "none",
|
|
774
|
-
className: (0,
|
|
1087
|
+
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
775
1088
|
"data-testid": testId
|
|
776
|
-
}, /* @__PURE__ */
|
|
1089
|
+
}, /* @__PURE__ */ import_react10.default.createElement(FormFields, {
|
|
777
1090
|
schema,
|
|
778
1091
|
path,
|
|
779
1092
|
readonly,
|
|
@@ -781,7 +1094,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
781
1094
|
sort,
|
|
782
1095
|
lookupComponent,
|
|
783
1096
|
Custom
|
|
784
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1097
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react10.default.createElement(FormActions, {
|
|
785
1098
|
onCancel,
|
|
786
1099
|
readonly
|
|
787
1100
|
})));
|
|
@@ -851,7 +1164,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
851
1164
|
type
|
|
852
1165
|
};
|
|
853
1166
|
}
|
|
854
|
-
return
|
|
1167
|
+
return _props;
|
|
855
1168
|
});
|
|
856
1169
|
}, [
|
|
857
1170
|
schemas,
|
|
@@ -907,7 +1220,8 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
907
1220
|
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
908
1221
|
value: p.name
|
|
909
1222
|
})) : []
|
|
910
|
-
})
|
|
1223
|
+
}),
|
|
1224
|
+
["options"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectOptionInput, props2)
|
|
911
1225
|
}), [
|
|
912
1226
|
t,
|
|
913
1227
|
schemas,
|
|
@@ -919,7 +1233,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
919
1233
|
props
|
|
920
1234
|
}, {
|
|
921
1235
|
F: __dxlog_file3,
|
|
922
|
-
L:
|
|
1236
|
+
L: 174,
|
|
923
1237
|
S: void 0,
|
|
924
1238
|
C: (f, a) => f(...a)
|
|
925
1239
|
});
|
|
@@ -947,18 +1261,18 @@ var ViewMetaSchema = import_echo_schema7.S.Struct({
|
|
|
947
1261
|
name: import_echo_schema7.S.String.annotations({
|
|
948
1262
|
[import_echo_schema7.AST.TitleAnnotationId]: "View"
|
|
949
1263
|
}),
|
|
950
|
-
typename: import_echo_schema7.Format.
|
|
1264
|
+
typename: import_echo_schema7.Format.URL.annotations({
|
|
951
1265
|
[import_echo_schema7.AST.TitleAnnotationId]: "Typename"
|
|
952
1266
|
})
|
|
953
1267
|
}).pipe(import_echo_schema7.S.mutable);
|
|
954
1268
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
955
|
-
const { t } = (0,
|
|
956
|
-
const projection = (0,
|
|
1269
|
+
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1270
|
+
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
957
1271
|
schema,
|
|
958
1272
|
view
|
|
959
1273
|
]);
|
|
960
|
-
const [field, setField] = (0,
|
|
961
|
-
const viewValues = (0,
|
|
1274
|
+
const [field, setField] = (0, import_react14.useState)();
|
|
1275
|
+
const viewValues = (0, import_react14.useMemo)(() => {
|
|
962
1276
|
return {
|
|
963
1277
|
name: view.name,
|
|
964
1278
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -968,7 +1282,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
968
1282
|
}, [
|
|
969
1283
|
view
|
|
970
1284
|
]);
|
|
971
|
-
const handleViewUpdate = (0,
|
|
1285
|
+
const handleViewUpdate = (0, import_react14.useCallback)(({ name, typename }) => {
|
|
972
1286
|
requestAnimationFrame(() => {
|
|
973
1287
|
if (view.name !== name) {
|
|
974
1288
|
view.name = name;
|
|
@@ -982,67 +1296,71 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
982
1296
|
schema,
|
|
983
1297
|
onTypenameChanged
|
|
984
1298
|
]);
|
|
985
|
-
const handleSelect = (0,
|
|
1299
|
+
const handleSelect = (0, import_react14.useCallback)((field2) => {
|
|
986
1300
|
setField((f) => f === field2 ? void 0 : field2);
|
|
987
1301
|
}, []);
|
|
988
|
-
const handleAdd = (0,
|
|
1302
|
+
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
989
1303
|
const field2 = projection.createFieldProjection();
|
|
990
1304
|
setField(field2);
|
|
991
1305
|
}, [
|
|
992
1306
|
view
|
|
993
1307
|
]);
|
|
994
|
-
const handleMove = (0,
|
|
995
|
-
|
|
1308
|
+
const handleMove = (0, import_react14.useCallback)((fromIndex, toIndex) => {
|
|
1309
|
+
const fields = [
|
|
1310
|
+
...view.fields
|
|
1311
|
+
];
|
|
1312
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
1313
|
+
fields.splice(toIndex, 0, moved);
|
|
1314
|
+
view.fields = fields;
|
|
996
1315
|
}, [
|
|
997
1316
|
view.fields
|
|
998
1317
|
]);
|
|
999
|
-
const handleClose = (0,
|
|
1000
|
-
return /* @__PURE__ */
|
|
1318
|
+
const handleClose = (0, import_react14.useCallback)(() => setField(void 0), []);
|
|
1319
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1001
1320
|
role: "none",
|
|
1002
|
-
className: (0,
|
|
1003
|
-
}, /* @__PURE__ */
|
|
1004
|
-
autoFocus: true,
|
|
1321
|
+
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1322
|
+
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
1005
1323
|
autoSave: true,
|
|
1006
1324
|
schema: ViewMetaSchema,
|
|
1007
1325
|
values: viewValues,
|
|
1008
1326
|
onSave: handleViewUpdate
|
|
1009
|
-
}), /* @__PURE__ */
|
|
1327
|
+
}), /* @__PURE__ */ import_react14.default.createElement("div", null, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1010
1328
|
role: "none",
|
|
1011
1329
|
className: "p-2"
|
|
1012
|
-
}, /* @__PURE__ */
|
|
1013
|
-
className: (0,
|
|
1014
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1330
|
+
}, /* @__PURE__ */ import_react14.default.createElement("label", {
|
|
1331
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1332
|
+
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1015
1333
|
items: view.fields,
|
|
1016
1334
|
isItem: import_echo_schema7.S.is(import_schema5.FieldSchema),
|
|
1017
1335
|
getId: (field2) => field2.id,
|
|
1018
1336
|
onMove: handleMove
|
|
1019
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1337
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1020
1338
|
role: "heading",
|
|
1021
1339
|
className: grid
|
|
1022
|
-
}, /* @__PURE__ */
|
|
1340
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", null), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1023
1341
|
className: "flex items-center text-sm"
|
|
1024
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1342
|
+
}, t("field path label"))), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1025
1343
|
role: "list",
|
|
1026
1344
|
className: "flex flex-col w-full"
|
|
1027
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1345
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Item, {
|
|
1028
1346
|
key: field2.id,
|
|
1029
1347
|
item: field2,
|
|
1030
|
-
classNames: (0,
|
|
1031
|
-
}, /* @__PURE__ */
|
|
1348
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1349
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1032
1350
|
onClick: () => handleSelect(field2)
|
|
1033
|
-
}, field2.path), /* @__PURE__ */
|
|
1351
|
+
}, field2.path), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1034
1352
|
disabled: view.fields.length <= 1,
|
|
1035
1353
|
onClick: () => onDelete(field2.id)
|
|
1036
|
-
}))))))), field && /* @__PURE__ */
|
|
1354
|
+
}))))))), field && /* @__PURE__ */ import_react14.default.createElement(FieldEditor, {
|
|
1037
1355
|
key: field.id,
|
|
1038
1356
|
view,
|
|
1039
1357
|
projection,
|
|
1040
1358
|
field,
|
|
1041
1359
|
registry,
|
|
1042
1360
|
onSave: handleClose
|
|
1043
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1361
|
+
}), !readonly && !field && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1044
1362
|
className: "flex p-2 justify-center"
|
|
1045
|
-
}, /* @__PURE__ */
|
|
1363
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1046
1364
|
icon: "ph--plus--regular",
|
|
1047
1365
|
label: t("button add property"),
|
|
1048
1366
|
onClick: handleAdd,
|
|
@@ -1267,13 +1585,16 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1267
1585
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1268
1586
|
0 && (module.exports = {
|
|
1269
1587
|
BooleanInput,
|
|
1588
|
+
DeprecatedFormContainer,
|
|
1270
1589
|
DeprecatedFormInput,
|
|
1271
1590
|
FieldEditor,
|
|
1272
1591
|
Form,
|
|
1273
1592
|
GeoPointInput,
|
|
1274
1593
|
InputHeader,
|
|
1594
|
+
MarkdownInput,
|
|
1275
1595
|
NumberInput,
|
|
1276
1596
|
SelectInput,
|
|
1597
|
+
SelectOptionInput,
|
|
1277
1598
|
TextInput,
|
|
1278
1599
|
TupleInput,
|
|
1279
1600
|
ViewEditor,
|
|
@@ -1284,6 +1605,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1284
1605
|
parseValue,
|
|
1285
1606
|
pathNotUniqueError,
|
|
1286
1607
|
translations,
|
|
1287
|
-
useForm
|
|
1608
|
+
useForm,
|
|
1609
|
+
useFormValues
|
|
1288
1610
|
});
|
|
1289
1611
|
//# sourceMappingURL=index.cjs.map
|