@dxos/react-ui-form 0.7.4 → 0.7.5-feature-compute.4d9d99a
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 +292 -221
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +380 -308
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +292 -221
- 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/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +10 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +5 -0
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +3 -3
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/{Custom.d.ts → custom/GeoPointInput.d.ts} +3 -3
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +7 -0
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts +3 -0
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -0
- 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/hooks/useForm.d.ts +10 -11
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +26 -26
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.tsx +75 -50
- package/src/components/Form/Defaults.tsx +2 -0
- package/src/components/Form/Form.stories.tsx +33 -1
- package/src/components/Form/Form.tsx +33 -5
- package/src/components/Form/Input.tsx +3 -3
- package/src/components/Form/{Custom.tsx → custom/GeoPointInput.tsx} +4 -16
- package/src/components/Form/custom/TupleInput.tsx +53 -0
- package/src/components/Form/custom/index.ts +6 -0
- package/src/components/Form/factory.tsx +2 -2
- package/src/components/Form/index.ts +3 -2
- package/src/components/ViewEditor/ViewEditor.stories.tsx +30 -8
- package/src/components/ViewEditor/ViewEditor.tsx +13 -8
- package/src/hooks/useForm.ts +35 -54
- package/dist/types/src/components/Form/Custom.d.ts.map +0 -1
|
@@ -82,27 +82,16 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
85
|
-
import
|
|
85
|
+
import React7, { useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo3, useState as useState2 } from "react";
|
|
86
86
|
import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
87
87
|
import { log as log3 } from "@dxos/log";
|
|
88
88
|
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
89
89
|
import { getFormatSchema, getSchemaProperties as getSchemaProperties2, sortProperties } from "@dxos/schema";
|
|
90
90
|
|
|
91
|
-
// packages/ui/react-ui-form/src/components/Form/
|
|
92
|
-
import { pipe } from "effect";
|
|
93
|
-
import { capitalize } from "effect/String";
|
|
94
|
-
import React5, { useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
95
|
-
import { AST, S } from "@dxos/echo-schema";
|
|
96
|
-
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
97
|
-
import { log as log2 } from "@dxos/log";
|
|
98
|
-
import { IconButton, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
99
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
100
|
-
import { getSchemaProperties } from "@dxos/schema";
|
|
101
|
-
import { isNotFalsy } from "@dxos/util";
|
|
102
|
-
|
|
103
|
-
// packages/ui/react-ui-form/src/components/Form/Defaults.tsx
|
|
91
|
+
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
104
92
|
import React3 from "react";
|
|
105
|
-
import { Input as Input2,
|
|
93
|
+
import { Input as Input2, useTranslation } from "@dxos/react-ui";
|
|
94
|
+
import { safeParseFloat } from "@dxos/util";
|
|
106
95
|
|
|
107
96
|
// packages/ui/react-ui-form/src/components/Form/Input.tsx
|
|
108
97
|
import React2 from "react";
|
|
@@ -123,120 +112,156 @@ var InputHeader = ({ children, error }) => {
|
|
|
123
112
|
}, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), error)));
|
|
124
113
|
};
|
|
125
114
|
|
|
126
|
-
// packages/ui/react-ui-form/src/components/Form/
|
|
127
|
-
var
|
|
115
|
+
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
116
|
+
var GeoPointInput = ({ property, type, label, disabled, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
117
|
+
const { t } = useTranslation(translationKey);
|
|
128
118
|
const { status, error } = getStatus?.(property);
|
|
119
|
+
const [lng = 0, lat = 0] = getValue2(property) ?? [];
|
|
129
120
|
return /* @__PURE__ */ React3.createElement(Input2.Root, {
|
|
130
121
|
validationValence: status
|
|
131
|
-
},
|
|
122
|
+
}, /* @__PURE__ */ React3.createElement(InputHeader, {
|
|
132
123
|
error
|
|
133
|
-
}, /* @__PURE__ */ React3.createElement(Input2.Label, null, label)), /* @__PURE__ */ React3.createElement(
|
|
124
|
+
}, /* @__PURE__ */ React3.createElement(Input2.Label, null, label)), /* @__PURE__ */ React3.createElement("div", {
|
|
125
|
+
className: "grid grid-cols-2 gap-2"
|
|
126
|
+
}, /* @__PURE__ */ React3.createElement(Input2.TextInput, {
|
|
127
|
+
type: "number",
|
|
128
|
+
disabled,
|
|
129
|
+
placeholder: t("placeholder longitude"),
|
|
130
|
+
value: lng,
|
|
131
|
+
onChange: (event) => onValueChange(property, type, [
|
|
132
|
+
lat,
|
|
133
|
+
safeParseFloat(event.target.value, 0)
|
|
134
|
+
]),
|
|
135
|
+
onBlur
|
|
136
|
+
}), /* @__PURE__ */ React3.createElement(Input2.TextInput, {
|
|
137
|
+
type: "number",
|
|
138
|
+
disabled,
|
|
139
|
+
placeholder: t("placeholder latitude"),
|
|
140
|
+
value: lat,
|
|
141
|
+
onChange: (event) => onValueChange(property, type, [
|
|
142
|
+
safeParseFloat(event.target.value, 0),
|
|
143
|
+
lng
|
|
144
|
+
]),
|
|
145
|
+
onBlur
|
|
146
|
+
})));
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// packages/ui/react-ui-form/src/components/Form/custom/TupleInput.tsx
|
|
150
|
+
import React4 from "react";
|
|
151
|
+
import { Input as Input3 } from "@dxos/react-ui";
|
|
152
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
153
|
+
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
154
|
+
var gridCols = [
|
|
155
|
+
"grid-cols-1",
|
|
156
|
+
"grid-cols-2",
|
|
157
|
+
"grid-cols-3",
|
|
158
|
+
"grid-cols-4"
|
|
159
|
+
];
|
|
160
|
+
var TupleInput = ({ binding, property, type, label, disabled, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
161
|
+
const { status, error } = getStatus?.(property);
|
|
162
|
+
const values = getValue2(property) ?? {};
|
|
163
|
+
return /* @__PURE__ */ React4.createElement(Input3.Root, {
|
|
164
|
+
validationValence: status
|
|
165
|
+
}, /* @__PURE__ */ React4.createElement(InputHeader, {
|
|
166
|
+
error
|
|
167
|
+
}, /* @__PURE__ */ React4.createElement(Input3.Label, null, label)), /* @__PURE__ */ React4.createElement("div", {
|
|
168
|
+
className: mx("grid gap-2", gridCols[binding.length - 1])
|
|
169
|
+
}, binding.map((prop) => /* @__PURE__ */ React4.createElement(Input3.TextInput, {
|
|
170
|
+
key: prop,
|
|
171
|
+
type: "number",
|
|
172
|
+
disabled,
|
|
173
|
+
value: values[prop],
|
|
174
|
+
onChange: (event) => onValueChange(property, type, {
|
|
175
|
+
...values,
|
|
176
|
+
[prop]: safeParseFloat2(event.target.value, 0)
|
|
177
|
+
}),
|
|
178
|
+
onBlur
|
|
179
|
+
}))));
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// packages/ui/react-ui-form/src/components/Form/Defaults.tsx
|
|
183
|
+
import React5 from "react";
|
|
184
|
+
import { Input as Input4, Select } from "@dxos/react-ui";
|
|
185
|
+
var TextInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
186
|
+
const { status, error } = getStatus?.(property);
|
|
187
|
+
return /* @__PURE__ */ React5.createElement(Input4.Root, {
|
|
188
|
+
validationValence: status
|
|
189
|
+
}, !inputOnly && /* @__PURE__ */ React5.createElement(InputHeader, {
|
|
190
|
+
error
|
|
191
|
+
}, /* @__PURE__ */ React5.createElement(Input4.Label, null, label)), /* @__PURE__ */ React5.createElement(Input4.TextInput, {
|
|
134
192
|
disabled,
|
|
135
193
|
placeholder,
|
|
136
|
-
value:
|
|
194
|
+
value: getValue2(property) ?? "",
|
|
137
195
|
onChange: (event) => onValueChange(property, type, event.target.value),
|
|
138
196
|
onBlur
|
|
139
|
-
}), inputOnly && /* @__PURE__ */
|
|
197
|
+
}), inputOnly && /* @__PURE__ */ React5.createElement(Input4.Validation, null, error));
|
|
140
198
|
};
|
|
141
|
-
var NumberInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
|
|
199
|
+
var NumberInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
142
200
|
const { status, error } = getStatus?.(property);
|
|
143
|
-
return /* @__PURE__ */
|
|
201
|
+
return /* @__PURE__ */ React5.createElement(Input4.Root, {
|
|
144
202
|
validationValence: status
|
|
145
|
-
}, !inputOnly && /* @__PURE__ */
|
|
203
|
+
}, !inputOnly && /* @__PURE__ */ React5.createElement(InputHeader, {
|
|
146
204
|
error
|
|
147
|
-
}, /* @__PURE__ */
|
|
205
|
+
}, /* @__PURE__ */ React5.createElement(Input4.Label, null, label)), /* @__PURE__ */ React5.createElement(Input4.TextInput, {
|
|
148
206
|
type: "number",
|
|
149
207
|
disabled,
|
|
150
208
|
placeholder,
|
|
151
|
-
value:
|
|
209
|
+
value: getValue2(property) ?? 0,
|
|
152
210
|
onChange: (event) => onValueChange(property, type, event.target.value),
|
|
153
211
|
onBlur
|
|
154
|
-
}), inputOnly && /* @__PURE__ */
|
|
212
|
+
}), inputOnly && /* @__PURE__ */ React5.createElement(Input4.DescriptionAndValidation, null, error));
|
|
155
213
|
};
|
|
156
|
-
var BooleanInput = ({ property, type, label, inputOnly, getStatus, getValue, onValueChange }) => {
|
|
214
|
+
var BooleanInput = ({ property, type, label, inputOnly, getStatus, getValue: getValue2, onValueChange }) => {
|
|
157
215
|
const { status, error } = getStatus?.(property);
|
|
158
|
-
return /* @__PURE__ */
|
|
216
|
+
return /* @__PURE__ */ React5.createElement(Input4.Root, {
|
|
159
217
|
validationValence: status
|
|
160
|
-
}, !inputOnly && /* @__PURE__ */
|
|
218
|
+
}, !inputOnly && /* @__PURE__ */ React5.createElement(InputHeader, {
|
|
161
219
|
error
|
|
162
|
-
}, /* @__PURE__ */
|
|
163
|
-
checked:
|
|
220
|
+
}, /* @__PURE__ */ React5.createElement(Input4.Label, null, label)), /* @__PURE__ */ React5.createElement(Input4.Switch, {
|
|
221
|
+
checked: getValue2(property),
|
|
164
222
|
onCheckedChange: (value) => onValueChange(property, type, value)
|
|
165
|
-
}), inputOnly && /* @__PURE__ */
|
|
223
|
+
}), inputOnly && /* @__PURE__ */ React5.createElement(Input4.DescriptionAndValidation, null, error));
|
|
166
224
|
};
|
|
167
|
-
var SelectInput = ({ property, type, label, inputOnly, disabled, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
225
|
+
var SelectInput = ({ property, type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue2, onValueChange }) => {
|
|
168
226
|
const { status, error } = getStatus?.(property);
|
|
169
|
-
return /* @__PURE__ */
|
|
227
|
+
return /* @__PURE__ */ React5.createElement(Input4.Root, {
|
|
170
228
|
validationValence: status
|
|
171
|
-
}, !inputOnly && /* @__PURE__ */
|
|
229
|
+
}, !inputOnly && /* @__PURE__ */ React5.createElement(InputHeader, {
|
|
172
230
|
error
|
|
173
|
-
}, /* @__PURE__ */
|
|
174
|
-
value:
|
|
231
|
+
}, /* @__PURE__ */ React5.createElement(Input4.Label, null, label)), /* @__PURE__ */ React5.createElement(Select.Root, {
|
|
232
|
+
value: getValue2(property),
|
|
175
233
|
onValueChange: (value) => onValueChange(property, type, value)
|
|
176
|
-
}, /* @__PURE__ */
|
|
234
|
+
}, /* @__PURE__ */ React5.createElement(Select.TriggerButton, {
|
|
177
235
|
classNames: "is-full",
|
|
178
236
|
disabled,
|
|
179
237
|
placeholder
|
|
180
|
-
}), /* @__PURE__ */
|
|
238
|
+
}), /* @__PURE__ */ React5.createElement(Select.Portal, null, /* @__PURE__ */ React5.createElement(Select.Content, null, /* @__PURE__ */ React5.createElement(Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
181
239
|
// NOTE: Numeric values are converted to and from strings.
|
|
182
|
-
/* @__PURE__ */
|
|
240
|
+
/* @__PURE__ */ React5.createElement(Select.Option, {
|
|
183
241
|
key: String(value),
|
|
184
242
|
value: String(value)
|
|
185
243
|
}, label2 ?? String(value))
|
|
186
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
244
|
+
)))))), inputOnly && /* @__PURE__ */ React5.createElement(Input4.DescriptionAndValidation, null, error));
|
|
187
245
|
};
|
|
188
246
|
|
|
189
|
-
// packages/ui/react-ui-form/src/components/Form/
|
|
190
|
-
import {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
import
|
|
194
|
-
import {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
validationValence: status
|
|
201
|
-
}, /* @__PURE__ */ React4.createElement(InputHeader, {
|
|
202
|
-
error
|
|
203
|
-
}, /* @__PURE__ */ React4.createElement(Input3.Label, null, label)), /* @__PURE__ */ React4.createElement("div", {
|
|
204
|
-
className: "grid grid-cols-2 gap-2"
|
|
205
|
-
}, /* @__PURE__ */ React4.createElement(Input3.TextInput, {
|
|
206
|
-
type: "number",
|
|
207
|
-
disabled,
|
|
208
|
-
placeholder: t("placeholder longitude"),
|
|
209
|
-
value: lng,
|
|
210
|
-
onChange: (event) => onValueChange(property, type, [
|
|
211
|
-
lat,
|
|
212
|
-
safeParseFloat(event.target.value, 0)
|
|
213
|
-
]),
|
|
214
|
-
onBlur
|
|
215
|
-
}), /* @__PURE__ */ React4.createElement(Input3.TextInput, {
|
|
216
|
-
type: "number",
|
|
217
|
-
disabled,
|
|
218
|
-
placeholder: t("placeholder latitude"),
|
|
219
|
-
value: lat,
|
|
220
|
-
onChange: (event) => onValueChange(property, type, [
|
|
221
|
-
safeParseFloat(event.target.value, 0),
|
|
222
|
-
lng
|
|
223
|
-
]),
|
|
224
|
-
onBlur
|
|
225
|
-
})));
|
|
226
|
-
};
|
|
227
|
-
var safeParseFloat = (str, defaultValue) => {
|
|
228
|
-
try {
|
|
229
|
-
return parseFloat(str);
|
|
230
|
-
} catch {
|
|
231
|
-
return defaultValue ?? 0;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
247
|
+
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
248
|
+
import { pipe } from "effect";
|
|
249
|
+
import { capitalize } from "effect/String";
|
|
250
|
+
import React6, { useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
251
|
+
import { AST as AST2, S } from "@dxos/echo-schema";
|
|
252
|
+
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
253
|
+
import { log as log2 } from "@dxos/log";
|
|
254
|
+
import { IconButton, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
255
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
256
|
+
import { getSchemaProperties } from "@dxos/schema";
|
|
257
|
+
import { isNotFalsy } from "@dxos/util";
|
|
234
258
|
|
|
235
259
|
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
260
|
+
import { FormatEnum } from "@dxos/echo-schema";
|
|
236
261
|
var getInputComponent = (type, format) => {
|
|
237
262
|
switch (format) {
|
|
238
263
|
case FormatEnum.LatLng:
|
|
239
|
-
return
|
|
264
|
+
return GeoPointInput;
|
|
240
265
|
}
|
|
241
266
|
switch (type) {
|
|
242
267
|
case "string":
|
|
@@ -250,11 +275,22 @@ var getInputComponent = (type, format) => {
|
|
|
250
275
|
|
|
251
276
|
// packages/ui/react-ui-form/src/hooks/useForm.ts
|
|
252
277
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
278
|
+
import { getValue, setValue } from "@dxos/echo-schema";
|
|
279
|
+
import { AST } from "@dxos/effect";
|
|
253
280
|
import { invariant } from "@dxos/invariant";
|
|
254
281
|
import { log } from "@dxos/log";
|
|
255
282
|
import { validateSchema } from "@dxos/schema";
|
|
256
283
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
257
284
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
285
|
+
invariant(AST.isTypeLiteral(schema.ast), void 0, {
|
|
286
|
+
F: __dxlog_file,
|
|
287
|
+
L: 91,
|
|
288
|
+
S: void 0,
|
|
289
|
+
A: [
|
|
290
|
+
"AST.isTypeLiteral(schema.ast)",
|
|
291
|
+
""
|
|
292
|
+
]
|
|
293
|
+
});
|
|
258
294
|
const [values, setValues] = useState(initialValues);
|
|
259
295
|
useEffect(() => {
|
|
260
296
|
setValues(initialValues);
|
|
@@ -268,10 +304,12 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
268
304
|
const validate = useCallback((values2) => {
|
|
269
305
|
let errors2 = validateSchema(schema, values2) ?? [];
|
|
270
306
|
if (errors2.length === 0 && onValidate) {
|
|
271
|
-
|
|
307
|
+
const validatedValues = values2;
|
|
308
|
+
errors2 = onValidate(validatedValues) ?? [];
|
|
272
309
|
}
|
|
273
310
|
setErrors(flatMap(errors2));
|
|
274
|
-
|
|
311
|
+
const valid = errors2.length === 0;
|
|
312
|
+
return valid;
|
|
275
313
|
}, [
|
|
276
314
|
schema,
|
|
277
315
|
onValidate
|
|
@@ -309,7 +347,8 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
309
347
|
}, [
|
|
310
348
|
values,
|
|
311
349
|
validate,
|
|
312
|
-
onSave
|
|
350
|
+
onSave,
|
|
351
|
+
changed
|
|
313
352
|
]);
|
|
314
353
|
const getStatus = useCallback((property) => ({
|
|
315
354
|
status: errors[property] ? "error" : void 0,
|
|
@@ -318,8 +357,8 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
318
357
|
touched,
|
|
319
358
|
errors
|
|
320
359
|
]);
|
|
321
|
-
const
|
|
322
|
-
return
|
|
360
|
+
const getFormValue = (property) => {
|
|
361
|
+
return getValue(values, property);
|
|
323
362
|
};
|
|
324
363
|
const onValueChange = (property, type, value) => {
|
|
325
364
|
let parsedValue = value;
|
|
@@ -330,13 +369,15 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
330
369
|
} catch (err) {
|
|
331
370
|
log.catch(err, void 0, {
|
|
332
371
|
F: __dxlog_file,
|
|
333
|
-
L:
|
|
372
|
+
L: 179,
|
|
334
373
|
S: void 0,
|
|
335
374
|
C: (f, a) => f(...a)
|
|
336
375
|
});
|
|
337
376
|
parsedValue = void 0;
|
|
338
377
|
}
|
|
339
|
-
const newValues =
|
|
378
|
+
const newValues = {
|
|
379
|
+
...setValue(values, property, parsedValue)
|
|
380
|
+
};
|
|
340
381
|
setValues(newValues);
|
|
341
382
|
setChanged((prev) => ({
|
|
342
383
|
...prev,
|
|
@@ -374,7 +415,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
374
415
|
handleSave,
|
|
375
416
|
// Field utils.
|
|
376
417
|
getStatus,
|
|
377
|
-
getValue,
|
|
418
|
+
getValue: getFormValue,
|
|
378
419
|
onValueChange,
|
|
379
420
|
onBlur
|
|
380
421
|
};
|
|
@@ -382,7 +423,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
382
423
|
var createKeySet = (obj, value) => {
|
|
383
424
|
invariant(obj, void 0, {
|
|
384
425
|
F: __dxlog_file,
|
|
385
|
-
L:
|
|
426
|
+
L: 230,
|
|
386
427
|
S: void 0,
|
|
387
428
|
A: [
|
|
388
429
|
"obj",
|
|
@@ -402,25 +443,11 @@ var flatMap = (errors) => {
|
|
|
402
443
|
return result;
|
|
403
444
|
}, {});
|
|
404
445
|
};
|
|
405
|
-
var getByPath = (obj, path) => {
|
|
406
|
-
const [key, index] = path.split(".");
|
|
407
|
-
return index === void 0 ? obj[key] : obj[key][parseInt(index)];
|
|
408
|
-
};
|
|
409
|
-
var setByPath = (obj, path, value) => {
|
|
410
|
-
const [key, index] = path.split(".");
|
|
411
|
-
const newValue = index === void 0 ? value : [
|
|
412
|
-
...obj[key]
|
|
413
|
-
].map((v, i) => i === parseInt(index) ? value : v);
|
|
414
|
-
return {
|
|
415
|
-
...obj,
|
|
416
|
-
[key]: newValue
|
|
417
|
-
};
|
|
418
|
-
};
|
|
419
446
|
|
|
420
447
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
421
448
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
|
|
422
449
|
var padding = "px-2";
|
|
423
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, Custom }) => {
|
|
450
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
424
451
|
const onValid = useMemo2(() => autoSave ? onSave : void 0, [
|
|
425
452
|
autoSave,
|
|
426
453
|
onSave
|
|
@@ -452,7 +479,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
452
479
|
errors
|
|
453
480
|
}, {
|
|
454
481
|
F: __dxlog_file2,
|
|
455
|
-
L:
|
|
482
|
+
L: 106,
|
|
456
483
|
S: void 0,
|
|
457
484
|
C: (f, a) => f(...a)
|
|
458
485
|
});
|
|
@@ -460,9 +487,9 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
460
487
|
}, [
|
|
461
488
|
errors
|
|
462
489
|
]);
|
|
463
|
-
return /* @__PURE__ */
|
|
490
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
464
491
|
role: "form",
|
|
465
|
-
className:
|
|
492
|
+
className: mx2("flex flex-col w-full gap-2 py-2", classNames),
|
|
466
493
|
"data-testid": testId
|
|
467
494
|
}, properties.map((property) => {
|
|
468
495
|
const { ast, name, type, format, title, description, examples, options, array } = property;
|
|
@@ -472,14 +499,34 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
472
499
|
];
|
|
473
500
|
const label = title ?? pipe(name, capitalize);
|
|
474
501
|
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
502
|
+
const FoundComponent = lookupComponent?.({
|
|
503
|
+
prop: name,
|
|
504
|
+
schema: S.make(ast),
|
|
505
|
+
inputProps: {
|
|
506
|
+
property: name,
|
|
507
|
+
type,
|
|
508
|
+
format,
|
|
509
|
+
label,
|
|
510
|
+
disabled: readonly,
|
|
511
|
+
placeholder,
|
|
512
|
+
...inputProps
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
if (FoundComponent) {
|
|
516
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
517
|
+
key: name,
|
|
518
|
+
role: "none",
|
|
519
|
+
className: padding
|
|
520
|
+
}, FoundComponent);
|
|
521
|
+
}
|
|
475
522
|
let InputComponent = Custom?.[key.join(".")];
|
|
476
523
|
if (!InputComponent) {
|
|
477
524
|
if (options) {
|
|
478
|
-
return /* @__PURE__ */
|
|
525
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
479
526
|
key: name,
|
|
480
527
|
role: "none",
|
|
481
528
|
className: padding
|
|
482
|
-
}, /* @__PURE__ */
|
|
529
|
+
}, /* @__PURE__ */ React6.createElement(SelectInput, {
|
|
483
530
|
type,
|
|
484
531
|
format,
|
|
485
532
|
property: name,
|
|
@@ -495,7 +542,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
495
542
|
}
|
|
496
543
|
InputComponent = getInputComponent(type, format);
|
|
497
544
|
if (array) {
|
|
498
|
-
return /* @__PURE__ */
|
|
545
|
+
return /* @__PURE__ */ React6.createElement(ArrayField, {
|
|
499
546
|
key: name,
|
|
500
547
|
name,
|
|
501
548
|
type,
|
|
@@ -514,15 +561,15 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
514
561
|
if (!InputComponent) {
|
|
515
562
|
if (type === "object") {
|
|
516
563
|
const baseNode = findNode(ast, isDiscriminatedUnion);
|
|
517
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, values[name]) : findNode(ast,
|
|
564
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, values[name]) : findNode(ast, AST2.isTypeLiteral);
|
|
518
565
|
if (typeLiteral) {
|
|
519
566
|
const schema2 = S.make(typeLiteral);
|
|
520
|
-
return /* @__PURE__ */
|
|
567
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
521
568
|
key: name,
|
|
522
569
|
role: "none"
|
|
523
|
-
}, /* @__PURE__ */
|
|
570
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
524
571
|
className: padding
|
|
525
|
-
}, label), /* @__PURE__ */
|
|
572
|
+
}, label), /* @__PURE__ */ React6.createElement(Form, {
|
|
526
573
|
schema: schema2,
|
|
527
574
|
path: key,
|
|
528
575
|
values: values[name] ?? {},
|
|
@@ -538,17 +585,17 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
538
585
|
type
|
|
539
586
|
}, {
|
|
540
587
|
F: __dxlog_file2,
|
|
541
|
-
L:
|
|
588
|
+
L: 213,
|
|
542
589
|
S: void 0,
|
|
543
590
|
C: (f, a) => f(...a)
|
|
544
591
|
});
|
|
545
592
|
return null;
|
|
546
593
|
}
|
|
547
|
-
return /* @__PURE__ */
|
|
594
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
548
595
|
key: name,
|
|
549
596
|
role: "none",
|
|
550
597
|
className: padding
|
|
551
|
-
}, /* @__PURE__ */
|
|
598
|
+
}, /* @__PURE__ */ React6.createElement(InputComponent, {
|
|
552
599
|
type,
|
|
553
600
|
format,
|
|
554
601
|
property: name,
|
|
@@ -557,7 +604,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
557
604
|
placeholder,
|
|
558
605
|
...inputProps
|
|
559
606
|
}));
|
|
560
|
-
}).filter(isNotFalsy), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
607
|
+
}).filter(isNotFalsy), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React6.createElement(FormActions, {
|
|
561
608
|
onCancel,
|
|
562
609
|
onSubmit: handleSave,
|
|
563
610
|
canSubmit: canSave,
|
|
@@ -570,33 +617,33 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
570
617
|
const key = [
|
|
571
618
|
name
|
|
572
619
|
];
|
|
573
|
-
const tupleType = findNode(ast,
|
|
620
|
+
const tupleType = findNode(ast, AST2.isTupleType);
|
|
574
621
|
const elementType = tupleType?.rest[0]?.type;
|
|
575
622
|
if (type === "object" && elementType) {
|
|
576
623
|
const baseNode = findNode(elementType, isDiscriminatedUnion);
|
|
577
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, values[name]) : findNode(elementType,
|
|
624
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, values[name]) : findNode(elementType, AST2.isTypeLiteral);
|
|
578
625
|
if (typeLiteral) {
|
|
579
626
|
const schema = S.make(typeLiteral);
|
|
580
|
-
return /* @__PURE__ */
|
|
627
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
581
628
|
key: name,
|
|
582
629
|
role: "none",
|
|
583
|
-
className:
|
|
584
|
-
}, /* @__PURE__ */
|
|
630
|
+
className: mx2(padding)
|
|
631
|
+
}, /* @__PURE__ */ React6.createElement(InputHeader, null, label), /* @__PURE__ */ React6.createElement("div", {
|
|
585
632
|
role: "none",
|
|
586
633
|
className: "flex flex-col gap-1"
|
|
587
634
|
}, arrayValues.map((value, index) => {
|
|
588
|
-
return /* @__PURE__ */
|
|
635
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
589
636
|
key: index,
|
|
590
637
|
role: "none",
|
|
591
638
|
className: "flex items-center gap-1"
|
|
592
|
-
}, /* @__PURE__ */
|
|
639
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
593
640
|
role: "none",
|
|
594
641
|
className: "flex-1"
|
|
595
|
-
}, /* @__PURE__ */
|
|
642
|
+
}, /* @__PURE__ */ React6.createElement(Form, {
|
|
596
643
|
schema,
|
|
597
644
|
path: [
|
|
598
645
|
...key,
|
|
599
|
-
index
|
|
646
|
+
`[${index}]`
|
|
600
647
|
],
|
|
601
648
|
values: value,
|
|
602
649
|
onValuesChanged: (childValues) => {
|
|
@@ -607,7 +654,7 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
607
654
|
inputProps.onValueChange(name, "object", newValues);
|
|
608
655
|
},
|
|
609
656
|
Custom
|
|
610
|
-
})), /* @__PURE__ */
|
|
657
|
+
})), /* @__PURE__ */ React6.createElement(IconButton, {
|
|
611
658
|
icon: "ph--trash--regular",
|
|
612
659
|
iconOnly: true,
|
|
613
660
|
label: t("button remove"),
|
|
@@ -616,10 +663,10 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
616
663
|
inputProps.onValueChange(name, type, newValues);
|
|
617
664
|
}
|
|
618
665
|
}));
|
|
619
|
-
})), /* @__PURE__ */
|
|
666
|
+
})), /* @__PURE__ */ React6.createElement("div", {
|
|
620
667
|
role: "none",
|
|
621
668
|
className: "flex justify-between items-center plb-1"
|
|
622
|
-
}, /* @__PURE__ */
|
|
669
|
+
}, /* @__PURE__ */ React6.createElement(IconButton, {
|
|
623
670
|
icon: "ph--plus--regular",
|
|
624
671
|
iconOnly: true,
|
|
625
672
|
label: t("button add"),
|
|
@@ -632,7 +679,7 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
632
679
|
}
|
|
633
680
|
})));
|
|
634
681
|
}
|
|
635
|
-
return /* @__PURE__ */
|
|
682
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
636
683
|
key: name,
|
|
637
684
|
role: "none"
|
|
638
685
|
}, "Nested form not supported in arrays, yet.");
|
|
@@ -641,30 +688,30 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
641
688
|
if (!InputComponent) {
|
|
642
689
|
return null;
|
|
643
690
|
}
|
|
644
|
-
return /* @__PURE__ */
|
|
691
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
645
692
|
role: "none",
|
|
646
693
|
key: "meta-input",
|
|
647
|
-
className:
|
|
648
|
-
}, /* @__PURE__ */
|
|
694
|
+
className: mx2(padding)
|
|
695
|
+
}, /* @__PURE__ */ React6.createElement(InputHeader, null, label), /* @__PURE__ */ React6.createElement("div", {
|
|
649
696
|
role: "none",
|
|
650
697
|
className: "flex flex-col gap-1"
|
|
651
|
-
}, arrayValues.map((_, index) => /* @__PURE__ */
|
|
698
|
+
}, arrayValues.map((_, index) => /* @__PURE__ */ React6.createElement("div", {
|
|
652
699
|
key: index,
|
|
653
700
|
role: "none",
|
|
654
701
|
className: "flex items-start gap-1"
|
|
655
|
-
}, /* @__PURE__ */
|
|
702
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
656
703
|
role: "none",
|
|
657
704
|
className: "flex-1"
|
|
658
|
-
}, /* @__PURE__ */
|
|
705
|
+
}, /* @__PURE__ */ React6.createElement(InputComponent, {
|
|
659
706
|
type,
|
|
660
707
|
format,
|
|
661
708
|
label,
|
|
662
709
|
inputOnly: true,
|
|
663
|
-
property: `${name}
|
|
710
|
+
property: `${name}[${index}]`,
|
|
664
711
|
disabled: readonly,
|
|
665
712
|
placeholder,
|
|
666
713
|
...inputProps
|
|
667
|
-
})), /* @__PURE__ */
|
|
714
|
+
})), /* @__PURE__ */ React6.createElement(IconButton, {
|
|
668
715
|
icon: "ph--trash--regular",
|
|
669
716
|
iconOnly: true,
|
|
670
717
|
label: t("button remove"),
|
|
@@ -672,10 +719,10 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
672
719
|
const newValues = arrayValues.filter((_2, i) => i !== index);
|
|
673
720
|
inputProps.onValueChange(name, type, newValues);
|
|
674
721
|
}
|
|
675
|
-
})))), /* @__PURE__ */
|
|
722
|
+
})))), /* @__PURE__ */ React6.createElement("div", {
|
|
676
723
|
role: "none",
|
|
677
724
|
className: "flex justify-between items-center plb-1"
|
|
678
|
-
}, /* @__PURE__ */
|
|
725
|
+
}, /* @__PURE__ */ React6.createElement(IconButton, {
|
|
679
726
|
icon: "ph--plus--regular",
|
|
680
727
|
iconOnly: true,
|
|
681
728
|
label: t("button add"),
|
|
@@ -690,18 +737,18 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
690
737
|
};
|
|
691
738
|
var FormActions = ({ onCancel, onSubmit, canSubmit, readonly }) => {
|
|
692
739
|
const { t } = useTranslation2(translationKey);
|
|
693
|
-
return /* @__PURE__ */
|
|
740
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
694
741
|
role: "none",
|
|
695
742
|
className: "flex justify-center"
|
|
696
|
-
}, /* @__PURE__ */
|
|
743
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
697
744
|
role: "none",
|
|
698
|
-
className:
|
|
699
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
745
|
+
className: mx2(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
746
|
+
}, onCancel && !readonly && /* @__PURE__ */ React6.createElement(IconButton, {
|
|
700
747
|
"data-testid": "cancel-button",
|
|
701
748
|
icon: "ph--x--regular",
|
|
702
749
|
label: t("button cancel"),
|
|
703
750
|
onClick: onCancel
|
|
704
|
-
}), onSubmit && /* @__PURE__ */
|
|
751
|
+
}), onSubmit && /* @__PURE__ */ React6.createElement(IconButton, {
|
|
705
752
|
type: "submit",
|
|
706
753
|
"data-testid": "save-button",
|
|
707
754
|
disabled: !canSubmit,
|
|
@@ -725,9 +772,11 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
725
772
|
if (!registry) {
|
|
726
773
|
return;
|
|
727
774
|
}
|
|
728
|
-
const subscription = registry.subscribe(setSchemas)
|
|
775
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
776
|
+
fire: true
|
|
777
|
+
});
|
|
729
778
|
const t2 = setTimeout(async () => {
|
|
730
|
-
const schemas2 = await registry.query();
|
|
779
|
+
const schemas2 = await registry.query().run();
|
|
731
780
|
setSchemas(schemas2);
|
|
732
781
|
});
|
|
733
782
|
return () => {
|
|
@@ -737,9 +786,9 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
737
786
|
}, [
|
|
738
787
|
registry
|
|
739
788
|
]);
|
|
740
|
-
const [
|
|
789
|
+
const [referenceSchema, setReferenceSchema] = useState2();
|
|
741
790
|
useEffect3(() => {
|
|
742
|
-
|
|
791
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
743
792
|
}, [
|
|
744
793
|
schemas,
|
|
745
794
|
props?.referenceSchema
|
|
@@ -748,14 +797,24 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
748
797
|
fieldSchema: getFormatSchema(props?.format)
|
|
749
798
|
});
|
|
750
799
|
const handleValuesChanged = useCallback2((_props) => {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
800
|
+
setFieldSchema((prev) => {
|
|
801
|
+
const fieldSchema2 = getFormatSchema(_props.format);
|
|
802
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
803
|
+
return prev;
|
|
804
|
+
}
|
|
805
|
+
return {
|
|
806
|
+
fieldSchema: fieldSchema2
|
|
807
|
+
};
|
|
808
|
+
});
|
|
809
|
+
setReferenceSchema((prev) => {
|
|
810
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
811
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
812
|
+
if (newSchema) {
|
|
813
|
+
return newSchema;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return prev;
|
|
817
|
+
});
|
|
759
818
|
setProps((props2) => {
|
|
760
819
|
const type = formatToType[_props.format];
|
|
761
820
|
if (props2.type !== type) {
|
|
@@ -769,7 +828,8 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
769
828
|
});
|
|
770
829
|
}, [
|
|
771
830
|
schemas,
|
|
772
|
-
props
|
|
831
|
+
props.format,
|
|
832
|
+
props.referenceSchema
|
|
773
833
|
]);
|
|
774
834
|
const handleValidate = useCallback2(({ property }) => {
|
|
775
835
|
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
@@ -801,23 +861,49 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
801
861
|
}, [
|
|
802
862
|
onSave
|
|
803
863
|
]);
|
|
864
|
+
const Custom = useMemo3(() => ({
|
|
865
|
+
["format"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
866
|
+
...props2,
|
|
867
|
+
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
868
|
+
value,
|
|
869
|
+
label: t(`format ${value}`)
|
|
870
|
+
}))
|
|
871
|
+
}),
|
|
872
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
873
|
+
...props2,
|
|
874
|
+
options: schemas.map((schema) => ({
|
|
875
|
+
value: schema.typename
|
|
876
|
+
}))
|
|
877
|
+
}),
|
|
878
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
879
|
+
...props2,
|
|
880
|
+
options: referenceSchema ? getSchemaProperties2(referenceSchema.ast).sort(sortProperties).map((p) => ({
|
|
881
|
+
value: p.name
|
|
882
|
+
})) : []
|
|
883
|
+
})
|
|
884
|
+
}), [
|
|
885
|
+
t,
|
|
886
|
+
schemas,
|
|
887
|
+
referenceSchema
|
|
888
|
+
]);
|
|
889
|
+
const propIsNotType = useCallback2((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
804
890
|
if (!fieldSchema) {
|
|
805
891
|
log3.warn("invalid format", {
|
|
806
892
|
props
|
|
807
893
|
}, {
|
|
808
894
|
F: __dxlog_file3,
|
|
809
|
-
L:
|
|
895
|
+
L: 173,
|
|
810
896
|
S: void 0,
|
|
811
897
|
C: (f, a) => f(...a)
|
|
812
898
|
});
|
|
813
899
|
return null;
|
|
814
900
|
}
|
|
815
|
-
return /* @__PURE__ */
|
|
901
|
+
return /* @__PURE__ */ React7.createElement(Form, {
|
|
816
902
|
key: field.id,
|
|
817
903
|
autoFocus: true,
|
|
818
904
|
values: props,
|
|
819
905
|
schema: fieldSchema,
|
|
820
|
-
filter:
|
|
906
|
+
filter: propIsNotType,
|
|
821
907
|
sort: [
|
|
822
908
|
"property",
|
|
823
909
|
"format"
|
|
@@ -826,55 +912,35 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
826
912
|
onValidate: handleValidate,
|
|
827
913
|
onSave: handleSave,
|
|
828
914
|
onCancel: handleCancel,
|
|
829
|
-
Custom
|
|
830
|
-
["format"]: (props2) => /* @__PURE__ */ React6.createElement(SelectInput, {
|
|
831
|
-
...props2,
|
|
832
|
-
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
833
|
-
value,
|
|
834
|
-
label: t(`format ${value}`)
|
|
835
|
-
}))
|
|
836
|
-
}),
|
|
837
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ React6.createElement(SelectInput, {
|
|
838
|
-
...props2,
|
|
839
|
-
options: schemas.map((schema2) => ({
|
|
840
|
-
value: schema2.typename
|
|
841
|
-
}))
|
|
842
|
-
}),
|
|
843
|
-
["referencePath"]: (props2) => /* @__PURE__ */ React6.createElement(SelectInput, {
|
|
844
|
-
...props2,
|
|
845
|
-
options: schema ? getSchemaProperties2(schema.schema.ast).sort(sortProperties).map((p) => ({
|
|
846
|
-
value: p.name
|
|
847
|
-
})) : []
|
|
848
|
-
})
|
|
849
|
-
}
|
|
915
|
+
Custom
|
|
850
916
|
});
|
|
851
917
|
};
|
|
852
918
|
|
|
853
919
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
854
|
-
import
|
|
855
|
-
import { AST as
|
|
920
|
+
import React8, { useCallback as useCallback3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
921
|
+
import { AST as AST3, Format, S as S2 } from "@dxos/echo-schema";
|
|
856
922
|
import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
857
923
|
import { List } from "@dxos/react-ui-list";
|
|
858
|
-
import { ghostHover, inputTextLabel, mx as
|
|
924
|
+
import { ghostHover, inputTextLabel, mx as mx3 } from "@dxos/react-ui-theme";
|
|
859
925
|
import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
860
926
|
import { arrayMove } from "@dxos/util";
|
|
861
927
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
862
928
|
var ViewMetaSchema = S2.Struct({
|
|
863
929
|
name: S2.String.annotations({
|
|
864
|
-
[
|
|
930
|
+
[AST3.TitleAnnotationId]: "View"
|
|
865
931
|
}),
|
|
866
932
|
typename: Format.DXN.annotations({
|
|
867
|
-
[
|
|
933
|
+
[AST3.TitleAnnotationId]: "Typename"
|
|
868
934
|
})
|
|
869
935
|
}).pipe(S2.mutable);
|
|
870
|
-
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
936
|
+
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
871
937
|
const { t } = useTranslation4(translationKey);
|
|
872
|
-
const projection =
|
|
938
|
+
const projection = useMemo4(() => new ViewProjection(schema, view), [
|
|
873
939
|
schema,
|
|
874
940
|
view
|
|
875
941
|
]);
|
|
876
942
|
const [field, setField] = useState3();
|
|
877
|
-
const viewValues =
|
|
943
|
+
const viewValues = useMemo4(() => {
|
|
878
944
|
return {
|
|
879
945
|
name: view.name,
|
|
880
946
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -886,13 +952,17 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
886
952
|
]);
|
|
887
953
|
const handleViewUpdate = useCallback3(({ name, typename }) => {
|
|
888
954
|
requestAnimationFrame(() => {
|
|
889
|
-
view.name
|
|
890
|
-
|
|
891
|
-
|
|
955
|
+
if (view.name !== name) {
|
|
956
|
+
view.name = name;
|
|
957
|
+
}
|
|
958
|
+
if (view.query.type !== typename) {
|
|
959
|
+
onTypenameChanged(typename);
|
|
960
|
+
}
|
|
892
961
|
});
|
|
893
962
|
}, [
|
|
894
963
|
view,
|
|
895
|
-
schema
|
|
964
|
+
schema,
|
|
965
|
+
onTypenameChanged
|
|
896
966
|
]);
|
|
897
967
|
const handleSelect = useCallback3((field2) => {
|
|
898
968
|
setField((f) => f === field2 ? void 0 : field2);
|
|
@@ -909,52 +979,52 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
909
979
|
view.fields
|
|
910
980
|
]);
|
|
911
981
|
const handleClose = useCallback3(() => setField(void 0), []);
|
|
912
|
-
return /* @__PURE__ */
|
|
982
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
913
983
|
role: "none",
|
|
914
|
-
className:
|
|
915
|
-
}, /* @__PURE__ */
|
|
984
|
+
className: mx3("flex flex-col w-full divide-y divide-separator", classNames)
|
|
985
|
+
}, /* @__PURE__ */ React8.createElement(Form, {
|
|
916
986
|
autoFocus: true,
|
|
917
987
|
autoSave: true,
|
|
918
988
|
schema: ViewMetaSchema,
|
|
919
989
|
values: viewValues,
|
|
920
990
|
onSave: handleViewUpdate
|
|
921
|
-
}), /* @__PURE__ */
|
|
991
|
+
}), /* @__PURE__ */ React8.createElement("div", null, /* @__PURE__ */ React8.createElement("div", {
|
|
922
992
|
role: "none",
|
|
923
993
|
className: "p-2"
|
|
924
|
-
}, /* @__PURE__ */
|
|
925
|
-
className:
|
|
926
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
994
|
+
}, /* @__PURE__ */ React8.createElement("label", {
|
|
995
|
+
className: mx3(inputTextLabel)
|
|
996
|
+
}, t("fields label"))), /* @__PURE__ */ React8.createElement(List.Root, {
|
|
927
997
|
items: view.fields,
|
|
928
998
|
isItem: S2.is(FieldSchema),
|
|
929
999
|
getId: (field2) => field2.id,
|
|
930
1000
|
onMove: handleMove
|
|
931
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1001
|
+
}, ({ items: fields }) => /* @__PURE__ */ React8.createElement(React8.Fragment, null, showHeading && /* @__PURE__ */ React8.createElement("div", {
|
|
932
1002
|
role: "heading",
|
|
933
1003
|
className: grid
|
|
934
|
-
}, /* @__PURE__ */
|
|
1004
|
+
}, /* @__PURE__ */ React8.createElement("div", null), /* @__PURE__ */ React8.createElement("div", {
|
|
935
1005
|
className: "flex items-center text-sm"
|
|
936
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1006
|
+
}, t("field path label"))), /* @__PURE__ */ React8.createElement("div", {
|
|
937
1007
|
role: "list",
|
|
938
1008
|
className: "flex flex-col w-full"
|
|
939
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1009
|
+
}, fields?.map((field2) => /* @__PURE__ */ React8.createElement(List.Item, {
|
|
940
1010
|
key: field2.id,
|
|
941
1011
|
item: field2,
|
|
942
|
-
classNames:
|
|
943
|
-
}, /* @__PURE__ */
|
|
1012
|
+
classNames: mx3(grid, ghostHover, "cursor-pointer")
|
|
1013
|
+
}, /* @__PURE__ */ React8.createElement(List.ItemDragHandle, null), /* @__PURE__ */ React8.createElement(List.ItemTitle, {
|
|
944
1014
|
onClick: () => handleSelect(field2)
|
|
945
|
-
}, field2.path), /* @__PURE__ */
|
|
1015
|
+
}, field2.path), /* @__PURE__ */ React8.createElement(List.ItemDeleteButton, {
|
|
946
1016
|
disabled: view.fields.length <= 1,
|
|
947
1017
|
onClick: () => onDelete(field2.id)
|
|
948
|
-
}))))))), field && /* @__PURE__ */
|
|
1018
|
+
}))))))), field && /* @__PURE__ */ React8.createElement(FieldEditor, {
|
|
949
1019
|
key: field.id,
|
|
950
1020
|
view,
|
|
951
1021
|
projection,
|
|
952
1022
|
field,
|
|
953
1023
|
registry,
|
|
954
1024
|
onSave: handleClose
|
|
955
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1025
|
+
}), !readonly && !field && /* @__PURE__ */ React8.createElement("div", {
|
|
956
1026
|
className: "flex p-2 justify-center"
|
|
957
|
-
}, /* @__PURE__ */
|
|
1027
|
+
}, /* @__PURE__ */ React8.createElement(IconButton2, {
|
|
958
1028
|
icon: "ph--plus--regular",
|
|
959
1029
|
label: t("button add property"),
|
|
960
1030
|
onClick: handleAdd,
|
|
@@ -1188,11 +1258,12 @@ export {
|
|
|
1188
1258
|
FieldEditor,
|
|
1189
1259
|
Form,
|
|
1190
1260
|
FormActions,
|
|
1191
|
-
|
|
1261
|
+
GeoPointInput,
|
|
1192
1262
|
InputHeader,
|
|
1193
1263
|
NumberInput,
|
|
1194
1264
|
SelectInput,
|
|
1195
1265
|
TextInput,
|
|
1266
|
+
TupleInput,
|
|
1196
1267
|
ViewEditor,
|
|
1197
1268
|
cellClassesForFieldType,
|
|
1198
1269
|
cellClassesForRowSelection,
|