@dxos/react-ui-form 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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/README.md +0 -1
- package/dist/lib/browser/index.mjs +2315 -2116
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +2315 -2116
- 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 +8 -7
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +82 -5
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +84 -25
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +127 -55
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +43 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +77 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts +18 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts +16 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +82 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/index.d.ts +12 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +2 -4
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +54 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +85 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +39 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts +81 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +22 -10
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +84 -8
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +4 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -3
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts +6 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +63 -54
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts +3 -3
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts +2 -2
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +7 -0
- package/dist/types/src/util/properties.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +3 -3
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +52 -43
- package/src/components/FieldEditor/FieldEditor.stories.tsx +51 -32
- package/src/components/FieldEditor/FieldEditor.test.tsx +3 -2
- package/src/components/FieldEditor/FieldEditor.tsx +87 -83
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +154 -219
- package/src/components/Form/Form.tsx +314 -97
- package/src/components/Form/FormField.tsx +305 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +171 -0
- package/src/components/Form/FormFieldSet.tsx +129 -0
- package/src/components/Form/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +154 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/GeoPointField.tsx +120 -0
- package/src/components/Form/fields/MarkdownField.tsx +78 -0
- package/src/components/Form/fields/NumberField.tsx +39 -0
- package/src/components/Form/fields/RefField.tsx +199 -0
- package/src/components/Form/fields/SelectField.tsx +65 -0
- package/src/components/Form/fields/SelectOptionField.stories.tsx +64 -0
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +49 -45
- package/src/components/Form/fields/TextAreaField.tsx +38 -0
- package/src/components/Form/fields/TextField.tsx +38 -0
- package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +17 -10
- package/src/components/Form/fields/index.ts +15 -0
- package/src/components/Form/index.ts +3 -4
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +210 -0
- package/src/components/ObjectPicker/ObjectPicker.tsx +186 -0
- package/src/components/{ControlSection → ObjectPicker}/index.ts +1 -1
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +129 -0
- package/src/components/Settings/index.ts +5 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +141 -63
- package/src/components/ViewEditor/ViewEditor.test.tsx +17 -18
- package/src/components/ViewEditor/ViewEditor.tsx +353 -203
- package/src/components/index.ts +2 -3
- package/src/components/testing.tsx +33 -13
- package/src/hooks/index.ts +2 -3
- package/src/hooks/useFormHandler.ts +380 -0
- package/src/hooks/useKeyHandler.tsx +37 -0
- package/src/translations.ts +66 -58
- package/src/util/field.ts +33 -43
- package/src/util/formatting.ts +22 -22
- package/src/util/index.ts +1 -1
- package/src/util/properties.ts +18 -0
- package/src/util/refs.ts +17 -19
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -8
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/index.d.ts +0 -2
- package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
- package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
- package/dist/types/src/components/Form/Defaults.d.ts +0 -14
- package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormActions.d.ts +0 -9
- package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContent.d.ts +0 -57
- package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContext.d.ts +0 -23
- package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
- package/dist/types/src/components/Form/Input.d.ts +0 -26
- package/dist/types/src/components/Form/Input.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -12
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -7
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/index.d.ts +0 -4
- package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/factory.d.ts +0 -8
- package/dist/types/src/components/Form/factory.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.d.ts +0 -15
- package/dist/types/src/components/deprecated/Form.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +0 -13
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +0 -16
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/index.d.ts +0 -2
- package/dist/types/src/components/deprecated/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useForm.d.ts +0 -67
- package/dist/types/src/hooks/useForm.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/dist/types/src/util/schema.d.ts +0 -3
- package/dist/types/src/util/schema.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -41
- package/src/components/ControlSection/ControlSection.tsx +0 -139
- package/src/components/Form/ArrayField.tsx +0 -124
- package/src/components/Form/Defaults.tsx +0 -203
- package/src/components/Form/FormActions.tsx +0 -53
- package/src/components/Form/FormContent.tsx +0 -240
- package/src/components/Form/FormContext.tsx +0 -110
- package/src/components/Form/Input.tsx +0 -51
- package/src/components/Form/RefField.tsx +0 -213
- package/src/components/Form/custom/GeoPointInput.tsx +0 -72
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +0 -61
- package/src/components/Form/custom/index.ts +0 -7
- package/src/components/Form/factory.tsx +0 -31
- package/src/components/deprecated/Form.stories.tsx +0 -62
- package/src/components/deprecated/Form.tsx +0 -119
- package/src/components/deprecated/FormInput.tsx +0 -71
- package/src/components/deprecated/index.ts +0 -5
- package/src/hooks/useForm.ts +0 -291
- package/src/hooks/useQueryRefOptions.ts +0 -53
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -14
|
@@ -1,805 +1,441 @@
|
|
|
1
1
|
// src/translations.ts
|
|
2
|
-
var translationKey = "react-ui-form";
|
|
2
|
+
var translationKey = "@dxos/react-ui-form";
|
|
3
3
|
var translations = [
|
|
4
4
|
{
|
|
5
5
|
"en-US": {
|
|
6
6
|
[translationKey]: {
|
|
7
|
-
"fields
|
|
8
|
-
"hidden
|
|
9
|
-
"empty
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"field
|
|
13
|
-
"field
|
|
14
|
-
"field
|
|
15
|
-
"field
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"field
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"format
|
|
33
|
-
"format
|
|
34
|
-
"format
|
|
35
|
-
"format
|
|
36
|
-
"format
|
|
37
|
-
"format
|
|
38
|
-
"format
|
|
39
|
-
"format
|
|
40
|
-
"format
|
|
41
|
-
"format
|
|
42
|
-
"format
|
|
43
|
-
"format
|
|
44
|
-
"format
|
|
45
|
-
"format
|
|
46
|
-
"format
|
|
47
|
-
"format
|
|
48
|
-
"format
|
|
49
|
-
"format
|
|
50
|
-
"format
|
|
51
|
-
"format
|
|
52
|
-
"format
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
"
|
|
7
|
+
"fields.label": "Fields",
|
|
8
|
+
"hidden-fields.label": "Hidden Fields",
|
|
9
|
+
"empty-readonly-ref-field.label": "(none)",
|
|
10
|
+
"add-property-button.label": "Add property",
|
|
11
|
+
"field-property.label": "Property",
|
|
12
|
+
"field-property.placeholder": "Property name",
|
|
13
|
+
"field-format.label": "Type",
|
|
14
|
+
"field-path.label": "Field path",
|
|
15
|
+
"add-field.button": "Add field",
|
|
16
|
+
"boolean-input-true.value": "Yes",
|
|
17
|
+
"boolean-input-false.value": "No",
|
|
18
|
+
"show-field.label": "Show field",
|
|
19
|
+
"hide-field.label": "Hide field",
|
|
20
|
+
"delete-field.label": "Delete field",
|
|
21
|
+
"ref-field-combobox-input.placeholder": "Search\u2026",
|
|
22
|
+
"ref-field.placeholder": "Select\u2026",
|
|
23
|
+
"ref-field.placeholder_one": "Select\u2026",
|
|
24
|
+
"ref-field.placeholder_other": "Select items\u2026",
|
|
25
|
+
"create-option.label": "Create",
|
|
26
|
+
"example.placeholder": "Example",
|
|
27
|
+
"latitude.placeholder": "Latitude (e.g., 40.7128)",
|
|
28
|
+
"longitude.placeholder": "Longitude (e.g., -74.0060)",
|
|
29
|
+
"cancel-button.label": "Cancel",
|
|
30
|
+
"save-button.label": "Save",
|
|
31
|
+
// TypeFormat
|
|
32
|
+
"format.boolean.label": "Boolean",
|
|
33
|
+
"format.currency.label": "Currency",
|
|
34
|
+
"format.date.label": "Date",
|
|
35
|
+
"format.date-time.label": "DateTime",
|
|
36
|
+
"format.did.label": "DID",
|
|
37
|
+
"format.duration.label": "Duration",
|
|
38
|
+
"format.dxn.label": "DXN",
|
|
39
|
+
"format.email.label": "Email",
|
|
40
|
+
"format.formula.label": "Formula",
|
|
41
|
+
"format.hostname.label": "Hostname",
|
|
42
|
+
"format.integer.label": "Integer",
|
|
43
|
+
"format.json.label": "JSON",
|
|
44
|
+
"format.lnglat.label": "Geopoint",
|
|
45
|
+
"format.markdown.label": "Markdown",
|
|
46
|
+
"format.percent.label": "Percent",
|
|
47
|
+
"format.ref.label": "Reference",
|
|
48
|
+
"format.regex.label": "RegExp",
|
|
49
|
+
"format.string.label": "String",
|
|
50
|
+
"format.single-select.label": "Select",
|
|
51
|
+
"format.multi-select.label": "Multi-select",
|
|
52
|
+
"format.text.label": "Long text",
|
|
53
|
+
"format.time.label": "Time",
|
|
54
|
+
"format.timestamp.label": "Timestamp",
|
|
55
|
+
"format.user.label": "User",
|
|
56
|
+
"format.number.label": "Number",
|
|
57
|
+
"format.uri.label": "URI",
|
|
58
|
+
"format.url.label": "URL",
|
|
59
|
+
"format.uuid.label": "UUID",
|
|
60
|
+
// GeoPointField.
|
|
61
|
+
"latitude.label": "Latitude",
|
|
62
|
+
"longitude.label": "Longitude",
|
|
63
|
+
// SelectOptionsField.
|
|
64
|
+
"select-option.label": "Label",
|
|
65
|
+
"select-option-label.placeholder": "Option label",
|
|
66
|
+
"select-option-delete.button": "Delete",
|
|
67
|
+
"select-option-add.button": "Add option",
|
|
62
68
|
// System schema message.
|
|
63
|
-
"system
|
|
64
|
-
"system
|
|
69
|
+
"system-schema.title": "System type",
|
|
70
|
+
"system-schema.description": "System type: cannot add or remove fields.",
|
|
71
|
+
"remove.button": "Remove"
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
];
|
|
69
76
|
|
|
70
|
-
// src/components/
|
|
71
|
-
import {
|
|
72
|
-
import
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
className: mx("flex flex-col", textBlockWidth, classNames)
|
|
84
|
-
}, children));
|
|
85
|
-
} finally {
|
|
86
|
-
_effect.f();
|
|
77
|
+
// src/components/FieldEditor/FieldEditor.tsx
|
|
78
|
+
import React17, { useCallback as useCallback14, useEffect as useEffect7, useMemo as useMemo7, useState as useState5 } from "react";
|
|
79
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
80
|
+
import { Format as Format4, FormatEnums, formatToType } from "@dxos/echo/internal";
|
|
81
|
+
import { log as log2 } from "@dxos/log";
|
|
82
|
+
import { useAsyncEffect, useTranslation as useTranslation8 } from "@dxos/react-ui";
|
|
83
|
+
import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
|
|
84
|
+
|
|
85
|
+
// src/util/field.ts
|
|
86
|
+
import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
|
|
87
|
+
var parseValue = ({ type, format, value: value3 }) => {
|
|
88
|
+
if (value3 === void 0 || value3 === null || value3 === "") {
|
|
89
|
+
return void 0;
|
|
87
90
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
const parseScalar = (type2) => {
|
|
92
|
+
switch (type2) {
|
|
93
|
+
case TypeEnum.Boolean: {
|
|
94
|
+
if (typeof value3 === "string") {
|
|
95
|
+
const lowercaseValue = value3.toLowerCase();
|
|
96
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
97
|
+
return false;
|
|
98
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return Boolean(value3);
|
|
103
|
+
}
|
|
104
|
+
case TypeEnum.Number: {
|
|
105
|
+
const cleaned = typeof value3 === "string" ? value3.replace(/[^0-9.-]+/g, "") : value3;
|
|
106
|
+
const num = Number(cleaned);
|
|
107
|
+
return Number.isNaN(num) ? null : num;
|
|
108
|
+
}
|
|
109
|
+
case TypeEnum.String:
|
|
110
|
+
case TypeEnum.Ref:
|
|
111
|
+
return String(value3);
|
|
112
|
+
default: {
|
|
113
|
+
return value3;
|
|
102
114
|
}
|
|
103
|
-
}, label), description && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, {
|
|
104
|
-
classNames: "mbs-0.5"
|
|
105
|
-
}, /* @__PURE__ */ React.createElement(Input.Description, null, description))), /* @__PURE__ */ React.createElement("div", {
|
|
106
|
-
role: "none"
|
|
107
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
108
|
-
role: "none",
|
|
109
|
-
className: "flex min-bs-[--rail-action] items-center"
|
|
110
|
-
}, children))));
|
|
111
|
-
if (secondary) {
|
|
112
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
113
|
-
role: "none"
|
|
114
|
-
}, primary, secondary);
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// src/components/ControlSection/ControlSection.tsx
|
|
123
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
124
|
-
import React2 from "react";
|
|
125
|
-
import { Button, Input as Input2, toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
126
|
-
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
127
|
-
var ControlPage = ({ children, classNames, ...props }) => {
|
|
128
|
-
var _effect = _useSignals2();
|
|
129
|
-
try {
|
|
130
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
131
|
-
role: "none",
|
|
132
|
-
className: mx2("pli-cardSpacingInline", classNames),
|
|
133
|
-
...props
|
|
134
|
-
}, children);
|
|
135
|
-
} finally {
|
|
136
|
-
_effect.f();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
var ControlSection = ({ title, description, children }) => {
|
|
140
|
-
var _effect = _useSignals2();
|
|
141
|
-
try {
|
|
142
|
-
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ControlSectionHeading, {
|
|
143
|
-
title,
|
|
144
|
-
description
|
|
145
|
-
}), children);
|
|
146
|
-
} finally {
|
|
147
|
-
_effect.f();
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
var ControlSectionHeading = ({ title, description }) => {
|
|
151
|
-
var _effect = _useSignals2();
|
|
152
|
-
try {
|
|
153
|
-
const { t } = useTranslation(translationKey);
|
|
154
|
-
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", {
|
|
155
|
-
className: "pli-trimMd container-max-width text-xl mbs-trimLg mbe-trimMd"
|
|
156
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement("p", {
|
|
157
|
-
className: "pli-trimMd mlb-trimMd container-max-width text-description"
|
|
158
|
-
}, toLocalizedString(description, t)));
|
|
159
|
-
} finally {
|
|
160
|
-
_effect.f();
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
164
|
-
var _effect = _useSignals2();
|
|
165
|
-
try {
|
|
166
|
-
return /* @__PURE__ */ React2.createElement(Button, {
|
|
167
|
-
...props,
|
|
168
|
-
classNames: [
|
|
169
|
-
"md:col-span-2",
|
|
170
|
-
classNames
|
|
171
|
-
]
|
|
172
|
-
});
|
|
173
|
-
} finally {
|
|
174
|
-
_effect.f();
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var ControlGroup = ({ children, classNames }) => {
|
|
178
|
-
var _effect = _useSignals2();
|
|
179
|
-
try {
|
|
180
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
181
|
-
role: "none",
|
|
182
|
-
className: mx2("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd", classNames)
|
|
183
|
-
}, children);
|
|
184
|
-
} finally {
|
|
185
|
-
_effect.f();
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
var ControlFrame = ({ children }) => {
|
|
189
|
-
var _effect = _useSignals2();
|
|
190
|
-
try {
|
|
191
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
192
|
-
role: "none",
|
|
193
|
-
className: "p-trimMd container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd border border-separator rounded-md"
|
|
194
|
-
}, children);
|
|
195
|
-
} finally {
|
|
196
|
-
_effect.f();
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
var controlItemClasses = "pli-trimMd plb-trimMd container-max-width grid md:col-span-2 grid-cols-subgrid items-center gap-trimSm border border-separator rounded-md *:first:!mbs-0 *:last:!mbe-0";
|
|
200
|
-
var controlItemTitleClasses = "text-lg font-normal";
|
|
201
|
-
var controlItemDescriptionClasses = "text-base mlb-trimSm md:mbe-0 text-description";
|
|
202
|
-
var ControlItem = ({ title, description, children }) => {
|
|
203
|
-
var _effect = _useSignals2();
|
|
204
|
-
try {
|
|
205
|
-
const { t } = useTranslation(translationKey);
|
|
206
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
207
|
-
className: controlItemClasses
|
|
208
|
-
}, /* @__PURE__ */ React2.createElement("div", {
|
|
209
|
-
role: "none"
|
|
210
|
-
}, /* @__PURE__ */ React2.createElement("h3", {
|
|
211
|
-
className: controlItemTitleClasses
|
|
212
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement("p", {
|
|
213
|
-
className: controlItemDescriptionClasses
|
|
214
|
-
}, toLocalizedString(description, t))), children);
|
|
215
|
-
} finally {
|
|
216
|
-
_effect.f();
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
var ControlItemInput = ({ title, description, children }) => {
|
|
220
|
-
var _effect = _useSignals2();
|
|
221
|
-
try {
|
|
222
|
-
const { t } = useTranslation(translationKey);
|
|
223
|
-
return /* @__PURE__ */ React2.createElement(Input2.Root, null, /* @__PURE__ */ React2.createElement("div", {
|
|
224
|
-
className: controlItemClasses
|
|
225
|
-
}, /* @__PURE__ */ React2.createElement("div", {
|
|
226
|
-
role: "none"
|
|
227
|
-
}, /* @__PURE__ */ React2.createElement(Input2.Label, {
|
|
228
|
-
classNames: controlItemTitleClasses
|
|
229
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement(Input2.DescriptionAndValidation, null, /* @__PURE__ */ React2.createElement(Input2.Description, {
|
|
230
|
-
classNames: controlItemDescriptionClasses
|
|
231
|
-
}, toLocalizedString(description, t)))), children));
|
|
232
|
-
} finally {
|
|
233
|
-
_effect.f();
|
|
116
|
+
};
|
|
117
|
+
if (!format) {
|
|
118
|
+
return parseScalar(type);
|
|
234
119
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
120
|
+
switch (format) {
|
|
121
|
+
case Format.TypeFormat.Boolean:
|
|
122
|
+
return parseScalar(TypeEnum.Boolean);
|
|
123
|
+
case Format.TypeFormat.Number:
|
|
124
|
+
case Format.TypeFormat.Percent:
|
|
125
|
+
case Format.TypeFormat.Currency:
|
|
126
|
+
return parseScalar(TypeEnum.Number);
|
|
127
|
+
case Format.TypeFormat.String:
|
|
128
|
+
case Format.TypeFormat.Markdown: {
|
|
129
|
+
return parseScalar(TypeEnum.String);
|
|
130
|
+
}
|
|
131
|
+
case Format.TypeFormat.Ref:
|
|
132
|
+
throw new Error(`unexpected format: ${Format.TypeFormat.Ref}`);
|
|
133
|
+
case Format.TypeFormat.DateTime:
|
|
134
|
+
case Format.TypeFormat.Date:
|
|
135
|
+
case Format.TypeFormat.Time:
|
|
136
|
+
case Format.TypeFormat.Timestamp: {
|
|
137
|
+
const date = new Date(value3);
|
|
138
|
+
return isNaN(date.getTime()) ? null : date;
|
|
139
|
+
}
|
|
140
|
+
case Format.TypeFormat.GeoPoint: {
|
|
141
|
+
if (typeof value3 === "string") {
|
|
142
|
+
const cleaned = value3.replace(/[^0-9.,-]+/g, "");
|
|
143
|
+
const parts = cleaned.split(",");
|
|
144
|
+
if (parts.length === 2) {
|
|
145
|
+
const lat = parseFloat(parts[0]);
|
|
146
|
+
const long = parseFloat(parts[1]);
|
|
147
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
148
|
+
return GeoLocation.toGeoPoint({
|
|
149
|
+
latitude: lat,
|
|
150
|
+
longitude: long
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return [
|
|
156
|
+
0,
|
|
157
|
+
0
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
default: {
|
|
161
|
+
return value3;
|
|
162
|
+
}
|
|
250
163
|
}
|
|
251
164
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
content: error,
|
|
287
|
-
side: "bottom"
|
|
288
|
-
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
289
|
-
icon: "ph--warning--regular",
|
|
290
|
-
size: 4,
|
|
291
|
-
classNames: errorText
|
|
292
|
-
})));
|
|
293
|
-
} finally {
|
|
294
|
-
_effect.f();
|
|
165
|
+
var cellClassesForFieldType = ({ type, format }) => {
|
|
166
|
+
switch (format || type) {
|
|
167
|
+
case Format.TypeFormat.Markdown:
|
|
168
|
+
return void 0;
|
|
169
|
+
case Format.TypeFormat.Time:
|
|
170
|
+
case Format.TypeFormat.Timestamp:
|
|
171
|
+
case Format.TypeFormat.DateTime:
|
|
172
|
+
case Format.TypeFormat.Date:
|
|
173
|
+
case Format.TypeFormat.Duration:
|
|
174
|
+
return [
|
|
175
|
+
"font-mono",
|
|
176
|
+
"text-right"
|
|
177
|
+
];
|
|
178
|
+
case Format.TypeFormat.Currency:
|
|
179
|
+
return [
|
|
180
|
+
"text-right"
|
|
181
|
+
];
|
|
182
|
+
case Format.TypeFormat.JSON:
|
|
183
|
+
case Format.TypeFormat.DID:
|
|
184
|
+
return [
|
|
185
|
+
"font-mono"
|
|
186
|
+
];
|
|
187
|
+
case TypeEnum.Number:
|
|
188
|
+
case TypeEnum.Boolean:
|
|
189
|
+
return [
|
|
190
|
+
"text-right",
|
|
191
|
+
"font-mono"
|
|
192
|
+
];
|
|
193
|
+
case TypeEnum.String:
|
|
194
|
+
return void 0;
|
|
195
|
+
case TypeEnum.Ref:
|
|
196
|
+
return void 0;
|
|
197
|
+
default:
|
|
198
|
+
return void 0;
|
|
295
199
|
}
|
|
296
200
|
};
|
|
201
|
+
var pathNotUniqueError = (path) => ({
|
|
202
|
+
path: "path",
|
|
203
|
+
message: `'${path}' is already present`
|
|
204
|
+
});
|
|
297
205
|
|
|
298
|
-
// src/
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const [longitudeText, setLongitudeText] = useState(geoLocation.longitude?.toString());
|
|
314
|
-
const [latitudeText, setLatitudeText] = useState(geoLocation.latitude?.toString());
|
|
315
|
-
useEffect(() => {
|
|
316
|
-
const location = GeoLocation.fromGeoPoint(geoPoint);
|
|
317
|
-
setLongitudeText(location.longitude.toString());
|
|
318
|
-
setLatitudeText(location.latitude.toString());
|
|
319
|
-
}, [
|
|
320
|
-
geoPoint
|
|
321
|
-
]);
|
|
322
|
-
const handleCoordinateChange = useCallback((coordinateType, setText) => (event) => {
|
|
323
|
-
const inputText = event.target.value;
|
|
324
|
-
setText(inputText);
|
|
325
|
-
if (inputText !== "" && inputText !== "-") {
|
|
326
|
-
const coord = safeParseFloat(inputText);
|
|
327
|
-
if (coord !== void 0 && !isNaN(coord)) {
|
|
328
|
-
const currentLocation = GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
329
|
-
0,
|
|
330
|
-
0
|
|
331
|
-
]);
|
|
332
|
-
const newLocation = {
|
|
333
|
-
...currentLocation,
|
|
334
|
-
[coordinateType]: coord
|
|
335
|
-
};
|
|
336
|
-
const newValue = GeoLocation.toGeoPoint(newLocation);
|
|
337
|
-
onValueChange(type, newValue);
|
|
338
|
-
}
|
|
206
|
+
// src/util/formatting.ts
|
|
207
|
+
import { format as formatDate } from "date-fns/format";
|
|
208
|
+
import { Format as Format2, GeoLocation as GeoLocation2, TypeEnum as TypeEnum2 } from "@dxos/echo/internal";
|
|
209
|
+
var formatForDisplay = ({ type, format, value: value3, locale = void 0 }) => {
|
|
210
|
+
const formatScalar = (type2) => {
|
|
211
|
+
switch (type2) {
|
|
212
|
+
case TypeEnum2.Boolean:
|
|
213
|
+
return value3.toLocaleString().toUpperCase();
|
|
214
|
+
case TypeEnum2.Number:
|
|
215
|
+
return value3.toLocaleString(locale);
|
|
216
|
+
case TypeEnum2.String:
|
|
217
|
+
case TypeEnum2.Ref:
|
|
218
|
+
return String(value3);
|
|
219
|
+
default: {
|
|
220
|
+
return String(value3);
|
|
339
221
|
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
]);
|
|
345
|
-
return /* @__PURE__ */ React4.createElement(Input4.Root, {
|
|
346
|
-
validationValence: status
|
|
347
|
-
}, /* @__PURE__ */ React4.createElement(InputHeader, {
|
|
348
|
-
error,
|
|
349
|
-
label
|
|
350
|
-
}), /* @__PURE__ */ React4.createElement("div", {
|
|
351
|
-
role: "none",
|
|
352
|
-
className: "grid grid-cols-2 gap-2"
|
|
353
|
-
}, /* @__PURE__ */ React4.createElement(Input4.TextInput, {
|
|
354
|
-
type: "text",
|
|
355
|
-
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
356
|
-
disabled,
|
|
357
|
-
placeholder: t("placeholder latitude"),
|
|
358
|
-
value: latitudeText,
|
|
359
|
-
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
360
|
-
onBlur
|
|
361
|
-
}), /* @__PURE__ */ React4.createElement(Input4.TextInput, {
|
|
362
|
-
type: "text",
|
|
363
|
-
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
364
|
-
disabled,
|
|
365
|
-
placeholder: t("placeholder longitude"),
|
|
366
|
-
value: longitudeText,
|
|
367
|
-
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
368
|
-
onBlur
|
|
369
|
-
})));
|
|
370
|
-
} finally {
|
|
371
|
-
_effect.f();
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
if (!format) {
|
|
225
|
+
return formatScalar(type);
|
|
372
226
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
227
|
+
switch (format) {
|
|
228
|
+
case Format2.TypeFormat.Boolean: {
|
|
229
|
+
return formatScalar(TypeEnum2.Boolean);
|
|
230
|
+
}
|
|
231
|
+
case Format2.TypeFormat.Number: {
|
|
232
|
+
return formatScalar(TypeEnum2.Number);
|
|
233
|
+
}
|
|
234
|
+
case Format2.TypeFormat.String:
|
|
235
|
+
case Format2.TypeFormat.Ref: {
|
|
236
|
+
return formatScalar(TypeEnum2.String);
|
|
237
|
+
}
|
|
238
|
+
case Format2.TypeFormat.Percent: {
|
|
239
|
+
return `${value3 * 100}%`;
|
|
240
|
+
}
|
|
241
|
+
case Format2.TypeFormat.Currency: {
|
|
242
|
+
return value3.toLocaleString(locale, {
|
|
243
|
+
style: "currency",
|
|
244
|
+
currency: "USD",
|
|
245
|
+
minimumFractionDigits: 2,
|
|
246
|
+
maximumFractionDigits: 2
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
case Format2.TypeFormat.Date: {
|
|
250
|
+
try {
|
|
251
|
+
return formatDate(new Date(value3), "yyyy-MM-dd");
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return "Invalid Date";
|
|
395
254
|
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
403
|
-
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
404
|
-
if (unusedHues.length > 0) {
|
|
405
|
-
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
255
|
+
}
|
|
256
|
+
case Format2.TypeFormat.Time: {
|
|
257
|
+
try {
|
|
258
|
+
return formatDate(new Date(value3), "HH:mm:ss");
|
|
259
|
+
} catch (error) {
|
|
260
|
+
return "Invalid Time";
|
|
406
261
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const newOption = {
|
|
414
|
-
id: newId,
|
|
415
|
-
title: "",
|
|
416
|
-
color: randomHue()
|
|
417
|
-
};
|
|
418
|
-
onValueChange(type, [
|
|
419
|
-
...options ?? [],
|
|
420
|
-
newOption
|
|
421
|
-
]);
|
|
422
|
-
setSelectedId(newId);
|
|
423
|
-
setIsNewOption(true);
|
|
424
|
-
}, [
|
|
425
|
-
options,
|
|
426
|
-
type,
|
|
427
|
-
onValueChange
|
|
428
|
-
]);
|
|
429
|
-
const handleDelete = useCallback2((id) => {
|
|
430
|
-
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
431
|
-
onValueChange(type, newOptions);
|
|
432
|
-
setSelectedId(null);
|
|
433
|
-
}, [
|
|
434
|
-
options,
|
|
435
|
-
type,
|
|
436
|
-
onValueChange
|
|
437
|
-
]);
|
|
438
|
-
const handleMove = useCallback2((from, to) => {
|
|
439
|
-
if (!options) {
|
|
440
|
-
return;
|
|
262
|
+
}
|
|
263
|
+
case Format2.TypeFormat.DateTime: {
|
|
264
|
+
try {
|
|
265
|
+
return formatDate(new Date(value3), "yyyy-MM-dd HH:mm:ss");
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return "Invalid DateTime";
|
|
441
268
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
newOptions.splice(to, 0, removed);
|
|
447
|
-
onValueChange(type, newOptions);
|
|
448
|
-
}, [
|
|
449
|
-
options,
|
|
450
|
-
type,
|
|
451
|
-
onValueChange
|
|
452
|
-
]);
|
|
453
|
-
const handleClick = useCallback2((id) => {
|
|
454
|
-
setSelectedId((current) => current === id ? null : id);
|
|
455
|
-
}, []);
|
|
456
|
-
const handleTitleChange = useCallback2((id) => (e) => {
|
|
457
|
-
const newOptions = options?.map((o) => o.id === id ? {
|
|
458
|
-
...o,
|
|
459
|
-
title: e.target.value
|
|
460
|
-
} : o);
|
|
461
|
-
onValueChange(type, newOptions ?? []);
|
|
462
|
-
}, [
|
|
463
|
-
options,
|
|
464
|
-
type,
|
|
465
|
-
onValueChange
|
|
466
|
-
]);
|
|
467
|
-
const handleKeyDown = useCallback2((e) => {
|
|
468
|
-
if (e.key === "Enter") {
|
|
469
|
-
setSelectedId(null);
|
|
269
|
+
}
|
|
270
|
+
case Format2.TypeFormat.GeoPoint: {
|
|
271
|
+
if (value3 === null || value3 === void 0) {
|
|
272
|
+
return "";
|
|
470
273
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
...o,
|
|
475
|
-
color: hue
|
|
476
|
-
} : o);
|
|
477
|
-
onValueChange(type, newOptions ?? []);
|
|
478
|
-
}, [
|
|
479
|
-
options,
|
|
480
|
-
type,
|
|
481
|
-
onValueChange
|
|
482
|
-
]);
|
|
483
|
-
useEffect2(() => {
|
|
484
|
-
if (selected && isNewOption && inputRef.current) {
|
|
485
|
-
inputRef.current.focus();
|
|
486
|
-
setIsNewOption(false);
|
|
274
|
+
if (Array.isArray(value3) && value3.length >= 2 && value3.every(Number.isFinite)) {
|
|
275
|
+
const { latitude, longitude } = GeoLocation2.fromGeoPoint(value3);
|
|
276
|
+
return `${latitude},${longitude}`;
|
|
487
277
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
label
|
|
497
|
-
}), /* @__PURE__ */ React5.createElement("div", {
|
|
498
|
-
role: "none"
|
|
499
|
-
}, options && /* @__PURE__ */ React5.createElement(List.Root, {
|
|
500
|
-
items: options,
|
|
501
|
-
isItem: (item) => true,
|
|
502
|
-
onMove: handleMove
|
|
503
|
-
}, ({ items }) => /* @__PURE__ */ React5.createElement("div", {
|
|
504
|
-
role: "list",
|
|
505
|
-
className: "w-full overflow-auto"
|
|
506
|
-
}, items?.map((item) => /* @__PURE__ */ React5.createElement("div", {
|
|
507
|
-
key: item.id
|
|
508
|
-
}, /* @__PURE__ */ React5.createElement(List.Item, {
|
|
509
|
-
role: "button",
|
|
510
|
-
item,
|
|
511
|
-
classNames: [
|
|
512
|
-
"p-1 plb-2",
|
|
513
|
-
"flex flex-col",
|
|
514
|
-
"cursor-pointer",
|
|
515
|
-
"hover:bg-hoverOverlay"
|
|
516
|
-
],
|
|
517
|
-
"aria-expanded": selected === item.id
|
|
518
|
-
}, /* @__PURE__ */ React5.createElement("div", {
|
|
519
|
-
className: "flex items-center"
|
|
520
|
-
}, /* @__PURE__ */ React5.createElement(List.ItemDragHandle, null), /* @__PURE__ */ React5.createElement(List.ItemTitle, {
|
|
521
|
-
onClick: () => handleClick(item.id),
|
|
522
|
-
classNames: "flex-1"
|
|
523
|
-
}, /* @__PURE__ */ React5.createElement(Tag, {
|
|
524
|
-
palette: item.color
|
|
525
|
-
}, item.title || "\u200B")), /* @__PURE__ */ React5.createElement(Icon2, {
|
|
526
|
-
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
527
|
-
onClick: () => handleClick(item.id)
|
|
528
|
-
})), selected === item.id && /* @__PURE__ */ React5.createElement("div", {
|
|
529
|
-
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
530
|
-
}, /* @__PURE__ */ React5.createElement(Input5.Label, {
|
|
531
|
-
classNames: "text-xs"
|
|
532
|
-
}, t("select option label")), /* @__PURE__ */ React5.createElement("div", {
|
|
533
|
-
className: "flex flex-row items-center gap-1"
|
|
534
|
-
}, /* @__PURE__ */ React5.createElement(Input5.TextInput, {
|
|
535
|
-
placeholder: t("select option label placeholder"),
|
|
536
|
-
ref: selected === item.id ? inputRef : void 0,
|
|
537
|
-
value: item.title,
|
|
538
|
-
onChange: handleTitleChange(item.id),
|
|
539
|
-
onKeyDown: handleKeyDown,
|
|
540
|
-
classNames: "flex-1",
|
|
541
|
-
"data-no-submit": true
|
|
542
|
-
}), /* @__PURE__ */ React5.createElement(Toolbar.Root, {
|
|
543
|
-
classNames: "p-0 m-0 !is-auto"
|
|
544
|
-
}, /* @__PURE__ */ React5.createElement(HuePicker, {
|
|
545
|
-
value: item.color,
|
|
546
|
-
onChange: handleColorChange(item.id),
|
|
547
|
-
rootVariant: "toolbar-button"
|
|
548
|
-
})), /* @__PURE__ */ React5.createElement(IconButton, {
|
|
549
|
-
icon: "ph--trash--fill",
|
|
550
|
-
iconOnly: true,
|
|
551
|
-
label: t("select option delete"),
|
|
552
|
-
onClick: () => handleDelete(item.id)
|
|
553
|
-
})))))), /* @__PURE__ */ React5.createElement("div", {
|
|
554
|
-
role: "listitem"
|
|
555
|
-
}, /* @__PURE__ */ React5.createElement("div", {
|
|
556
|
-
role: "button",
|
|
557
|
-
className: mx4("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
558
|
-
onClick: handleAdd
|
|
559
|
-
}, /* @__PURE__ */ React5.createElement("div", {
|
|
560
|
-
className: "flex items-center gap-1"
|
|
561
|
-
}, /* @__PURE__ */ React5.createElement(Icon2, {
|
|
562
|
-
icon: "ph--plus--regular"
|
|
563
|
-
}), /* @__PURE__ */ React5.createElement("span", {
|
|
564
|
-
className: "text-sm"
|
|
565
|
-
}, t("select option add")))))))));
|
|
566
|
-
} finally {
|
|
567
|
-
_effect.f();
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
// src/components/Form/custom/TupleInput.tsx
|
|
572
|
-
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
573
|
-
import React6 from "react";
|
|
574
|
-
import { Input as Input6 } from "@dxos/react-ui";
|
|
575
|
-
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
576
|
-
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
577
|
-
var gridCols = [
|
|
578
|
-
"grid-cols-1",
|
|
579
|
-
"grid-cols-2",
|
|
580
|
-
"grid-cols-3",
|
|
581
|
-
"grid-cols-4"
|
|
582
|
-
];
|
|
583
|
-
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
584
|
-
var _effect = _useSignals6();
|
|
585
|
-
try {
|
|
586
|
-
const { status, error } = getStatus();
|
|
587
|
-
const values = getValue3() ?? {};
|
|
588
|
-
return /* @__PURE__ */ React6.createElement(Input6.Root, {
|
|
589
|
-
validationValence: status
|
|
590
|
-
}, /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
591
|
-
error,
|
|
592
|
-
label
|
|
593
|
-
}), /* @__PURE__ */ React6.createElement("div", {
|
|
594
|
-
className: mx5("grid gap-2", gridCols[binding.length - 1])
|
|
595
|
-
}, binding.map((prop) => /* @__PURE__ */ React6.createElement(Input6.TextInput, {
|
|
596
|
-
key: prop,
|
|
597
|
-
type: "number",
|
|
598
|
-
disabled,
|
|
599
|
-
value: values[prop],
|
|
600
|
-
onChange: (event) => onValueChange(type, {
|
|
601
|
-
...values,
|
|
602
|
-
[prop]: safeParseFloat2(event.target.value, 0)
|
|
603
|
-
}),
|
|
604
|
-
onBlur
|
|
605
|
-
}))));
|
|
606
|
-
} finally {
|
|
607
|
-
_effect.f();
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
// src/components/Form/Defaults.tsx
|
|
612
|
-
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
613
|
-
import React7, { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
614
|
-
import { Input as Input7, Select, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
615
|
-
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
616
|
-
var _effect = _useSignals7();
|
|
617
|
-
try {
|
|
618
|
-
const { status, error } = getStatus();
|
|
619
|
-
return disabled && !getValue3() ? null : disabled && inputOnly ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input7.Root, {
|
|
620
|
-
validationValence: status
|
|
621
|
-
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
622
|
-
error,
|
|
623
|
-
label
|
|
624
|
-
}), disabled ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input7.TextInput, {
|
|
625
|
-
disabled,
|
|
626
|
-
placeholder,
|
|
627
|
-
value: getValue3() ?? "",
|
|
628
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
629
|
-
onBlur
|
|
630
|
-
}), inputOnly && /* @__PURE__ */ React7.createElement(Input7.Validation, null, error));
|
|
631
|
-
} finally {
|
|
632
|
-
_effect.f();
|
|
278
|
+
return String(value3);
|
|
279
|
+
}
|
|
280
|
+
default: {
|
|
281
|
+
if (value3 === null || value3 === "undefined") {
|
|
282
|
+
return "";
|
|
283
|
+
}
|
|
284
|
+
return String(value3);
|
|
285
|
+
}
|
|
633
286
|
}
|
|
634
287
|
};
|
|
635
|
-
var
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
650
|
-
onBlur
|
|
651
|
-
}), inputOnly && /* @__PURE__ */ React7.createElement(Input7.DescriptionAndValidation, null, error));
|
|
652
|
-
} finally {
|
|
653
|
-
_effect.f();
|
|
288
|
+
var formatForEditing = ({ type, format, value: value3, locale = void 0 }) => {
|
|
289
|
+
const formatScalar = (type2) => {
|
|
290
|
+
switch (type2) {
|
|
291
|
+
case TypeEnum2.Boolean:
|
|
292
|
+
case TypeEnum2.Number:
|
|
293
|
+
case TypeEnum2.String:
|
|
294
|
+
case TypeEnum2.Ref:
|
|
295
|
+
return String(value3);
|
|
296
|
+
default:
|
|
297
|
+
return String(value3);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
if (!format) {
|
|
301
|
+
return formatScalar(type);
|
|
654
302
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
303
|
+
switch (format) {
|
|
304
|
+
case Format2.TypeFormat.Boolean:
|
|
305
|
+
case Format2.TypeFormat.Number:
|
|
306
|
+
case Format2.TypeFormat.String:
|
|
307
|
+
case Format2.TypeFormat.Ref: {
|
|
308
|
+
return formatScalar(type);
|
|
309
|
+
}
|
|
310
|
+
case Format2.TypeFormat.Percent: {
|
|
311
|
+
return String(value3 * 100);
|
|
312
|
+
}
|
|
313
|
+
case Format2.TypeFormat.Currency: {
|
|
314
|
+
return String(value3);
|
|
315
|
+
}
|
|
316
|
+
case Format2.TypeFormat.DateTime: {
|
|
317
|
+
const date = new Date(value3);
|
|
318
|
+
return date.toISOString();
|
|
319
|
+
}
|
|
320
|
+
case Format2.TypeFormat.Date: {
|
|
321
|
+
const date = new Date(value3);
|
|
322
|
+
return date.toISOString().split("T")[0];
|
|
323
|
+
}
|
|
324
|
+
case Format2.TypeFormat.Time: {
|
|
325
|
+
const date = new Date(value3);
|
|
326
|
+
return date.toISOString().split("T")[1].split(".")[0];
|
|
327
|
+
}
|
|
328
|
+
case Format2.TypeFormat.GeoPoint: {
|
|
329
|
+
if (value3 === null || value3 === void 0) {
|
|
330
|
+
return "";
|
|
331
|
+
}
|
|
332
|
+
if (Array.isArray(value3) && value3.length >= 2 && value3.every(Number.isFinite)) {
|
|
333
|
+
const { latitude, longitude } = GeoLocation2.fromGeoPoint(value3);
|
|
334
|
+
return `${latitude},${longitude}`;
|
|
335
|
+
}
|
|
336
|
+
return String(value3);
|
|
337
|
+
}
|
|
338
|
+
default: {
|
|
339
|
+
return String(value3);
|
|
340
|
+
}
|
|
673
341
|
}
|
|
674
342
|
};
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
onValueChange
|
|
683
|
-
]);
|
|
684
|
-
return disabled && !value ? null : /* @__PURE__ */ React7.createElement(Input7.Root, {
|
|
685
|
-
validationValence: status
|
|
686
|
-
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
687
|
-
error,
|
|
688
|
-
label
|
|
689
|
-
}), disabled ? /* @__PURE__ */ React7.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value)?.label ?? String(value)) : /* @__PURE__ */ React7.createElement(Select.Root, {
|
|
690
|
-
value,
|
|
691
|
-
onValueChange: handleValueChange
|
|
692
|
-
}, /* @__PURE__ */ React7.createElement(Select.TriggerButton, {
|
|
693
|
-
classNames: "is-full",
|
|
694
|
-
disabled,
|
|
695
|
-
placeholder
|
|
696
|
-
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
697
|
-
// NOTE: Numeric values are converted to and from strings.
|
|
698
|
-
/* @__PURE__ */ React7.createElement(Select.Option, {
|
|
699
|
-
key: String(value2),
|
|
700
|
-
value: String(value2)
|
|
701
|
-
}, label2 ?? String(value2))
|
|
702
|
-
)))))), inputOnly && /* @__PURE__ */ React7.createElement(Input7.DescriptionAndValidation, null, error));
|
|
703
|
-
} finally {
|
|
704
|
-
_effect.f();
|
|
705
|
-
}
|
|
343
|
+
|
|
344
|
+
// src/util/properties.ts
|
|
345
|
+
import * as Option from "effect/Option";
|
|
346
|
+
import { Annotation } from "@dxos/echo";
|
|
347
|
+
import { getProperties } from "@dxos/effect";
|
|
348
|
+
var getFormProperties = (ast) => {
|
|
349
|
+
return getProperties(ast).filter((prop) => Annotation.FormInputAnnotation.getFromAst(prop.type).pipe(Option.getOrElse(() => true)));
|
|
706
350
|
};
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
351
|
+
|
|
352
|
+
// src/util/refs.ts
|
|
353
|
+
import { Ref } from "@dxos/echo";
|
|
354
|
+
import { ReferenceAnnotationId } from "@dxos/echo/internal";
|
|
355
|
+
import { findAnnotation, getArrayElementType, isArrayType } from "@dxos/effect";
|
|
356
|
+
var getRefProps = (ast) => {
|
|
357
|
+
if (isArrayType(ast)) {
|
|
358
|
+
const elementType = getArrayElementType(ast);
|
|
359
|
+
if (elementType) {
|
|
360
|
+
if (Ref.isRefType(elementType)) {
|
|
361
|
+
const typename = findAnnotation(elementType, ReferenceAnnotationId)?.typename;
|
|
362
|
+
return {
|
|
363
|
+
ast: elementType,
|
|
364
|
+
isArray: true,
|
|
365
|
+
typename
|
|
366
|
+
};
|
|
717
367
|
}
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
getValue3(),
|
|
728
|
-
adjustHeight
|
|
729
|
-
]);
|
|
730
|
-
return /* @__PURE__ */ React7.createElement(Input7.Root, {
|
|
731
|
-
validationValence: status
|
|
732
|
-
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
733
|
-
error,
|
|
734
|
-
label
|
|
735
|
-
}), disabled ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input7.TextArea, {
|
|
736
|
-
ref: textareaRef,
|
|
737
|
-
disabled,
|
|
738
|
-
placeholder,
|
|
739
|
-
value: getValue3() ?? "",
|
|
740
|
-
classNames: "min-bs-auto max-h-40 overflow-auto",
|
|
741
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
742
|
-
onBlur,
|
|
743
|
-
style: {
|
|
744
|
-
resize: "none"
|
|
745
|
-
},
|
|
746
|
-
spellCheck: false
|
|
747
|
-
}), inputOnly && /* @__PURE__ */ React7.createElement(Input7.Validation, null, error));
|
|
748
|
-
} finally {
|
|
749
|
-
_effect.f();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (Ref.isRefType(ast)) {
|
|
371
|
+
const typename = findAnnotation(ast, ReferenceAnnotationId)?.typename;
|
|
372
|
+
return {
|
|
373
|
+
ast,
|
|
374
|
+
isArray: false,
|
|
375
|
+
typename
|
|
376
|
+
};
|
|
750
377
|
}
|
|
378
|
+
return void 0;
|
|
751
379
|
};
|
|
752
380
|
|
|
753
|
-
// src/components/Form/
|
|
754
|
-
import
|
|
755
|
-
import
|
|
756
|
-
import {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
760
|
-
import React9 from "react";
|
|
761
|
-
import { IconButton as IconButton2, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
762
|
-
import { cardSpacing } from "@dxos/react-ui-stack";
|
|
763
|
-
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
381
|
+
// src/components/Form/fields/ArrayField.tsx
|
|
382
|
+
import * as Option3 from "effect/Option";
|
|
383
|
+
import * as SchemaAST3 from "effect/SchemaAST";
|
|
384
|
+
import React5, { useCallback as useCallback3 } from "react";
|
|
385
|
+
import { findNode as findNode2, getArrayElementType as getArrayElementType2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2, isNestedType as isNestedType2 } from "@dxos/effect";
|
|
386
|
+
import { IconButton as IconButton2, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
764
387
|
|
|
765
|
-
// src/components/Form/
|
|
766
|
-
import {
|
|
767
|
-
import
|
|
768
|
-
import
|
|
769
|
-
import {
|
|
770
|
-
import { createJsonPath as
|
|
388
|
+
// src/components/Form/Form.tsx
|
|
389
|
+
import { createContext } from "@radix-ui/react-context";
|
|
390
|
+
import * as Schema2 from "effect/Schema";
|
|
391
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
392
|
+
import React4, { useEffect as useEffect3, useMemo as useMemo4, useRef } from "react";
|
|
393
|
+
import { createJsonPath as createJsonPath3, getValue as getValue$2 } from "@dxos/effect";
|
|
394
|
+
import { IconButton, ScrollArea, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
395
|
+
import { composable, composableProps, mx } from "@dxos/ui-theme";
|
|
771
396
|
|
|
772
|
-
// src/hooks/
|
|
773
|
-
import {
|
|
774
|
-
import { useCallback
|
|
775
|
-
import {
|
|
776
|
-
import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
|
|
777
|
-
import { invariant } from "@dxos/invariant";
|
|
397
|
+
// src/hooks/useFormHandler.ts
|
|
398
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
399
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
400
|
+
import { createJsonPath, fromEffectValidationPath, getValue as getValue$ } from "@dxos/effect";
|
|
778
401
|
import { log } from "@dxos/log";
|
|
402
|
+
import { useDefaultValue } from "@dxos/react-ui";
|
|
779
403
|
import { validateSchema } from "@dxos/schema";
|
|
780
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/
|
|
781
|
-
var
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
404
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useFormHandler.ts";
|
|
405
|
+
var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: defaultValuesProp, onValuesChanged, onValidate, onSave, onCancel, ...props }) => {
|
|
406
|
+
const [changed, setChanged] = useState({});
|
|
407
|
+
const [touched, setTouched] = useState({});
|
|
408
|
+
const [errors, setErrors] = useState({});
|
|
409
|
+
const [saving, setSaving] = useState(false);
|
|
410
|
+
const defaultValues = useDefaultValue(defaultValuesProp, () => ({}));
|
|
411
|
+
const [values$, setValues] = useControllableState({
|
|
412
|
+
prop: valuesProp,
|
|
413
|
+
defaultProp: defaultValues,
|
|
414
|
+
onChange: () => {
|
|
415
|
+
if (valuesProp !== void 0) {
|
|
416
|
+
setValues(valuesProp ?? defaultValues);
|
|
417
|
+
setChanged({});
|
|
418
|
+
setTouched({});
|
|
419
|
+
setErrors({});
|
|
420
|
+
setSaving(false);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
790
423
|
});
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
]);
|
|
797
|
-
const [touched, setTouched] = useState3(createKeySet(initialValues, false));
|
|
798
|
-
const [changed, setChanged] = useState3(createKeySet(initialValues, false));
|
|
799
|
-
const [errors, setErrors] = useState3({});
|
|
800
|
-
const [saving, setSaving] = useState3(false);
|
|
801
|
-
const validate = useCallback4((values2) => {
|
|
424
|
+
const values = values$;
|
|
425
|
+
const validate = useCallback((values2) => {
|
|
426
|
+
if (!schema) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
802
429
|
let errors2 = validateSchema(schema, values2) ?? [];
|
|
430
|
+
log("validate", {
|
|
431
|
+
values: values2,
|
|
432
|
+
errors: errors2
|
|
433
|
+
}, {
|
|
434
|
+
F: __dxlog_file,
|
|
435
|
+
L: 155,
|
|
436
|
+
S: void 0,
|
|
437
|
+
C: (f, a) => f(...a)
|
|
438
|
+
});
|
|
803
439
|
if (errors2.length === 0 && onValidate) {
|
|
804
440
|
const validatedValues = values2;
|
|
805
441
|
errors2 = onValidate(validatedValues) ?? [];
|
|
@@ -811,36 +447,38 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
811
447
|
schema,
|
|
812
448
|
onValidate
|
|
813
449
|
]);
|
|
814
|
-
const [
|
|
815
|
-
|
|
450
|
+
const [schemaChanged, setSchemaChanged] = useState(false);
|
|
451
|
+
useEffect(() => setSchemaChanged(true), [
|
|
816
452
|
schema
|
|
817
453
|
]);
|
|
818
|
-
|
|
819
|
-
if (
|
|
454
|
+
useEffect(() => {
|
|
455
|
+
if (schemaChanged) {
|
|
820
456
|
validate(values);
|
|
821
|
-
|
|
457
|
+
setSchemaChanged(false);
|
|
822
458
|
}
|
|
823
459
|
}, [
|
|
460
|
+
validate,
|
|
824
461
|
values,
|
|
825
|
-
|
|
462
|
+
schemaChanged
|
|
826
463
|
]);
|
|
827
|
-
const
|
|
464
|
+
const isValid = useMemo(() => {
|
|
828
465
|
return Object.keys(errors).length === 0;
|
|
829
466
|
}, [
|
|
830
467
|
errors
|
|
831
468
|
]);
|
|
832
|
-
const canSave =
|
|
469
|
+
const canSave = useMemo(() => !saving && // Check if any error paths that are touched have errors.
|
|
833
470
|
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
834
471
|
touched,
|
|
835
472
|
errors,
|
|
836
473
|
saving
|
|
837
474
|
]);
|
|
838
|
-
const handleSave =
|
|
475
|
+
const handleSave = useCallback(async () => {
|
|
839
476
|
if (validate(values)) {
|
|
840
477
|
setSaving(true);
|
|
841
478
|
try {
|
|
842
479
|
await onSave?.(values, {
|
|
843
|
-
changed
|
|
480
|
+
changed,
|
|
481
|
+
isValid
|
|
844
482
|
});
|
|
845
483
|
} finally {
|
|
846
484
|
setSaving(false);
|
|
@@ -850,11 +488,17 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
850
488
|
values,
|
|
851
489
|
validate,
|
|
852
490
|
onSave,
|
|
853
|
-
changed
|
|
491
|
+
changed,
|
|
492
|
+
isValid
|
|
854
493
|
]);
|
|
855
|
-
const
|
|
494
|
+
const handleCancel = useCallback(() => {
|
|
495
|
+
onCancel?.();
|
|
496
|
+
}, [
|
|
497
|
+
onCancel
|
|
498
|
+
]);
|
|
499
|
+
const getStatus = useCallback((path) => {
|
|
856
500
|
const jsonPath = Array.isArray(path) ? createJsonPath(path) : path;
|
|
857
|
-
const
|
|
501
|
+
const [_, error] = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`)) ?? [];
|
|
858
502
|
const isTouched = touched[jsonPath];
|
|
859
503
|
if (!isTouched) {
|
|
860
504
|
return {
|
|
@@ -863,110 +507,138 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
863
507
|
};
|
|
864
508
|
}
|
|
865
509
|
return {
|
|
866
|
-
status:
|
|
867
|
-
error:
|
|
510
|
+
status: error ? "error" : void 0,
|
|
511
|
+
error: error ? error ?? void 0 : void 0
|
|
868
512
|
};
|
|
869
513
|
}, [
|
|
870
514
|
errors,
|
|
871
515
|
touched
|
|
872
516
|
]);
|
|
873
|
-
const
|
|
874
|
-
return getValue(values, createJsonPath(path));
|
|
517
|
+
const getValue = useCallback((path) => {
|
|
518
|
+
return getValue$(values, createJsonPath(path));
|
|
875
519
|
}, [
|
|
876
520
|
values
|
|
877
521
|
]);
|
|
878
|
-
const onValueChange =
|
|
522
|
+
const onValueChange = useCallback((path, type, value3) => {
|
|
523
|
+
log("onValueChange", {
|
|
524
|
+
path,
|
|
525
|
+
value: value3
|
|
526
|
+
}, {
|
|
527
|
+
F: __dxlog_file,
|
|
528
|
+
L: 254,
|
|
529
|
+
S: void 0,
|
|
530
|
+
C: (f, a) => f(...a)
|
|
531
|
+
});
|
|
879
532
|
const jsonPath = createJsonPath(path);
|
|
880
|
-
|
|
533
|
+
const pathArray = path;
|
|
534
|
+
let parsedValue = value3;
|
|
881
535
|
try {
|
|
882
|
-
if (type === "
|
|
883
|
-
parsedValue = parseFloat(
|
|
536
|
+
if (type._tag === "NumberKeyword") {
|
|
537
|
+
parsedValue = parseFloat(value3) || 0;
|
|
884
538
|
}
|
|
885
539
|
} catch (err) {
|
|
886
540
|
log.catch(err, void 0, {
|
|
887
541
|
F: __dxlog_file,
|
|
888
|
-
L:
|
|
542
|
+
L: 264,
|
|
889
543
|
S: void 0,
|
|
890
544
|
C: (f, a) => f(...a)
|
|
891
545
|
});
|
|
892
546
|
parsedValue = void 0;
|
|
893
547
|
}
|
|
894
|
-
const newValues =
|
|
895
|
-
|
|
548
|
+
const newValues = mergeAtPath(values, pathArray, parsedValue);
|
|
549
|
+
const newChanged = {
|
|
550
|
+
[jsonPath]: true
|
|
896
551
|
};
|
|
897
|
-
setValues(newValues);
|
|
898
552
|
setChanged((prev) => ({
|
|
899
553
|
...prev,
|
|
900
|
-
|
|
554
|
+
...newChanged
|
|
901
555
|
}));
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
556
|
+
const isValid2 = validate(newValues);
|
|
557
|
+
onValuesChanged?.(newValues, {
|
|
558
|
+
isValid: isValid2,
|
|
559
|
+
changed: newChanged
|
|
560
|
+
});
|
|
561
|
+
if (valuesProp === void 0) {
|
|
562
|
+
setValues(newValues);
|
|
908
563
|
}
|
|
909
564
|
}, [
|
|
910
565
|
values,
|
|
911
|
-
onValuesChanged,
|
|
912
566
|
validate,
|
|
913
|
-
|
|
914
|
-
|
|
567
|
+
onValuesChanged,
|
|
568
|
+
valuesProp
|
|
915
569
|
]);
|
|
916
|
-
const
|
|
570
|
+
const onBlur = useCallback(async (path) => {
|
|
917
571
|
const jsonPath = createJsonPath(path);
|
|
918
572
|
setTouched((touched2) => ({
|
|
919
573
|
...touched2,
|
|
920
574
|
[jsonPath]: true
|
|
921
575
|
}));
|
|
922
|
-
validate(values);
|
|
576
|
+
const isValid2 = validate(values);
|
|
577
|
+
if (Object.keys(changed).length > 0 && isValid2 && autoSave) {
|
|
578
|
+
await onSave?.(values, {
|
|
579
|
+
changed,
|
|
580
|
+
isValid: isValid2
|
|
581
|
+
});
|
|
582
|
+
}
|
|
923
583
|
}, [
|
|
924
584
|
validate,
|
|
925
|
-
values
|
|
585
|
+
values,
|
|
586
|
+
changed,
|
|
587
|
+
autoSave,
|
|
588
|
+
onSave
|
|
926
589
|
]);
|
|
927
|
-
return
|
|
590
|
+
return useMemo(() => ({
|
|
928
591
|
// State.
|
|
592
|
+
schema,
|
|
929
593
|
values,
|
|
930
594
|
errors,
|
|
931
595
|
touched,
|
|
932
596
|
changed,
|
|
597
|
+
isValid,
|
|
933
598
|
canSave,
|
|
934
|
-
|
|
599
|
+
autoSave,
|
|
935
600
|
// Actions.
|
|
936
|
-
handleSave,
|
|
601
|
+
onSave: handleSave,
|
|
602
|
+
onCancel: handleCancel,
|
|
937
603
|
// Field utils.
|
|
938
604
|
getStatus,
|
|
939
|
-
getValue
|
|
605
|
+
getValue,
|
|
606
|
+
onBlur,
|
|
940
607
|
onValueChange,
|
|
941
|
-
|
|
608
|
+
...props
|
|
942
609
|
}), [
|
|
610
|
+
schema,
|
|
943
611
|
values,
|
|
944
612
|
errors,
|
|
945
613
|
touched,
|
|
946
614
|
changed,
|
|
947
615
|
canSave,
|
|
948
|
-
|
|
949
|
-
handleSave,
|
|
616
|
+
isValid,
|
|
950
617
|
getStatus,
|
|
951
|
-
|
|
618
|
+
getValue,
|
|
619
|
+
onBlur,
|
|
952
620
|
onValueChange,
|
|
953
|
-
|
|
621
|
+
onSave,
|
|
622
|
+
onCancel
|
|
954
623
|
]);
|
|
955
624
|
};
|
|
956
|
-
var
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
625
|
+
var mergeAtPath = (obj, path, value3) => {
|
|
626
|
+
if (path.length === 0) {
|
|
627
|
+
return value3;
|
|
628
|
+
}
|
|
629
|
+
const [head2, ...rest] = path;
|
|
630
|
+
const child = rest.length === 0 ? value3 : mergeAtPath(obj?.[head2], rest, value3);
|
|
631
|
+
if (Array.isArray(obj)) {
|
|
632
|
+
const copy = [
|
|
633
|
+
...obj
|
|
634
|
+
];
|
|
635
|
+
copy[head2] = child;
|
|
636
|
+
return copy;
|
|
637
|
+
}
|
|
638
|
+
return {
|
|
639
|
+
...obj,
|
|
640
|
+
[head2]: child
|
|
641
|
+
};
|
|
970
642
|
};
|
|
971
643
|
var flatMap = (errors) => {
|
|
972
644
|
return errors.reduce((result, { path, message }) => {
|
|
@@ -978,1424 +650,1951 @@ var flatMap = (errors) => {
|
|
|
978
650
|
}, {});
|
|
979
651
|
};
|
|
980
652
|
|
|
981
|
-
// src/hooks/
|
|
982
|
-
import { useCallback as
|
|
983
|
-
import {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
const { objects } = await query.run();
|
|
993
|
-
return objects.map((object) => {
|
|
994
|
-
const dxn = getObjectDXN(object);
|
|
995
|
-
if (!dxn) {
|
|
996
|
-
return void 0;
|
|
653
|
+
// src/hooks/useKeyHandler.tsx
|
|
654
|
+
import { useCallback as useCallback2, useEffect as useEffect2 } from "react";
|
|
655
|
+
import { addEventListener } from "@dxos/async";
|
|
656
|
+
var useKeyHandler = (formElement, form) => {
|
|
657
|
+
const handleKeyDown = useCallback2((event) => {
|
|
658
|
+
switch (event.key) {
|
|
659
|
+
case "Enter": {
|
|
660
|
+
if (event.metaKey && form.canSave) {
|
|
661
|
+
form.onSave();
|
|
662
|
+
}
|
|
663
|
+
break;
|
|
997
664
|
}
|
|
998
|
-
|
|
999
|
-
dxn,
|
|
1000
|
-
label: object?.name ?? object?.id ?? ""
|
|
1001
|
-
};
|
|
1002
|
-
return item;
|
|
1003
|
-
}).filter(isNonNullable);
|
|
665
|
+
}
|
|
1004
666
|
}, [
|
|
1005
|
-
|
|
667
|
+
form.isValid,
|
|
668
|
+
form.canSave,
|
|
669
|
+
form.onSave,
|
|
670
|
+
form.autoSave
|
|
1006
671
|
]);
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
// src/hooks/useQueryRefOptions.ts
|
|
1010
|
-
import { useEffect as useEffect5, useState as useState4 } from "react";
|
|
1011
|
-
import { log as log2 } from "@dxos/log";
|
|
1012
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
1013
|
-
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
1014
|
-
const [options, setOptions] = useState4([]);
|
|
1015
|
-
const [loading, setLoading] = useState4(false);
|
|
1016
|
-
useEffect5(() => {
|
|
1017
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
672
|
+
useEffect2(() => {
|
|
673
|
+
if (!formElement) {
|
|
1018
674
|
return;
|
|
1019
675
|
}
|
|
1020
|
-
|
|
1021
|
-
setLoading(true);
|
|
1022
|
-
try {
|
|
1023
|
-
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
1024
|
-
setOptions(fetchedOptions.map((option) => {
|
|
1025
|
-
const dxn = option.dxn.toString();
|
|
1026
|
-
return {
|
|
1027
|
-
id: dxn,
|
|
1028
|
-
label: option.label ?? dxn,
|
|
1029
|
-
hue: "neutral"
|
|
1030
|
-
};
|
|
1031
|
-
}));
|
|
1032
|
-
} catch (error) {
|
|
1033
|
-
log2.error("Failed to fetch ref options:", error, {
|
|
1034
|
-
F: __dxlog_file2,
|
|
1035
|
-
L: 42,
|
|
1036
|
-
S: void 0,
|
|
1037
|
-
C: (f, a) => f(...a)
|
|
1038
|
-
});
|
|
1039
|
-
setOptions([]);
|
|
1040
|
-
} finally {
|
|
1041
|
-
setLoading(false);
|
|
1042
|
-
}
|
|
1043
|
-
};
|
|
1044
|
-
void fetchOptions();
|
|
676
|
+
return addEventListener(formElement, "keydown", handleKeyDown);
|
|
1045
677
|
}, [
|
|
1046
|
-
|
|
1047
|
-
|
|
678
|
+
formElement,
|
|
679
|
+
handleKeyDown
|
|
1048
680
|
]);
|
|
1049
|
-
return {
|
|
1050
|
-
options,
|
|
1051
|
-
loading
|
|
1052
|
-
};
|
|
1053
681
|
};
|
|
1054
682
|
|
|
1055
|
-
// src/components/Form/
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
}), [
|
|
1076
|
-
getStatus,
|
|
1077
|
-
getFormValue,
|
|
1078
|
-
onValueChange,
|
|
1079
|
-
onTouched,
|
|
1080
|
-
stablePath
|
|
1081
|
-
]);
|
|
1082
|
-
};
|
|
1083
|
-
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
1084
|
-
var _effect = _useSignals8();
|
|
1085
|
-
try {
|
|
1086
|
-
const form = useForm(formOptions);
|
|
1087
|
-
const handleKeyDown = useCallback6((event) => {
|
|
1088
|
-
const keyIsEnter = event.key === "Enter";
|
|
1089
|
-
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
1090
|
-
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
1091
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
1092
|
-
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
1093
|
-
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
1094
|
-
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
1095
|
-
if (!autoSave && form.canSave) {
|
|
1096
|
-
form.handleSave();
|
|
1097
|
-
}
|
|
1098
|
-
if (autoSave && form.formIsValid) {
|
|
1099
|
-
event.target.blur();
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
}, [
|
|
1103
|
-
form,
|
|
1104
|
-
autoSave
|
|
1105
|
-
]);
|
|
1106
|
-
useEffect6(() => {
|
|
1107
|
-
if (!formRef?.current) {
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
const formElement = formRef.current;
|
|
1111
|
-
formElement.addEventListener("keydown", handleKeyDown);
|
|
1112
|
-
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
1113
|
-
}, [
|
|
1114
|
-
formRef,
|
|
1115
|
-
form.canSave,
|
|
1116
|
-
form.formIsValid,
|
|
1117
|
-
form.handleSave,
|
|
1118
|
-
autoSave
|
|
1119
|
-
]);
|
|
1120
|
-
return /* @__PURE__ */ React8.createElement(FormContext.Provider, {
|
|
1121
|
-
value: form
|
|
1122
|
-
}, children);
|
|
1123
|
-
} finally {
|
|
1124
|
-
_effect.f();
|
|
1125
|
-
}
|
|
683
|
+
// src/components/Form/FormFieldComponent.tsx
|
|
684
|
+
import React, { Component } from "react";
|
|
685
|
+
import { Icon, Input, Tooltip } from "@dxos/react-ui";
|
|
686
|
+
import { inputTextLabel } from "@dxos/ui-theme";
|
|
687
|
+
var FormFieldLabel = ({ label, error, readonly, asChild }) => {
|
|
688
|
+
const Label = readonly || asChild ? "span" : Input.Label;
|
|
689
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
690
|
+
role: "none",
|
|
691
|
+
className: "flex items-center justify-between"
|
|
692
|
+
}, /* @__PURE__ */ React.createElement(Label, {
|
|
693
|
+
className: inputTextLabel
|
|
694
|
+
}, label), error && /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
695
|
+
asChild: true,
|
|
696
|
+
content: error,
|
|
697
|
+
side: "bottom"
|
|
698
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
699
|
+
icon: "ph--warning--regular",
|
|
700
|
+
size: 4,
|
|
701
|
+
classNames: "text-error-text"
|
|
702
|
+
})));
|
|
1126
703
|
};
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
return /* @__PURE__ */ React9.createElement("div", {
|
|
1135
|
-
role: "none",
|
|
1136
|
-
className: mx6(outerSpacing === "scroll-fields" ? "pli-cardSpacingInline mbe-cardSpacingBlock" : outerSpacing ? cardSpacing : "mbs-cardSpacingBlock", "flex [&_button]:grow gap-1 first:mbs-0")
|
|
1137
|
-
}, onCancel && !readonly && /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
1138
|
-
"data-testid": "cancel-button",
|
|
1139
|
-
icon: "ph--x--regular",
|
|
1140
|
-
label: t("button cancel"),
|
|
1141
|
-
onClick: onCancel
|
|
1142
|
-
}), handleSave && /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
1143
|
-
type: "submit",
|
|
1144
|
-
"data-testid": "save-button",
|
|
1145
|
-
disabled: !canSave,
|
|
1146
|
-
icon: "ph--check--regular",
|
|
1147
|
-
label: t("button save"),
|
|
1148
|
-
onClick: handleSave
|
|
1149
|
-
}));
|
|
1150
|
-
} finally {
|
|
1151
|
-
_effect.f();
|
|
704
|
+
FormFieldLabel.displayName = "Form.FieldLabel";
|
|
705
|
+
var FormFieldWrapper = (props) => {
|
|
706
|
+
const { children, readonly, layout, label, getStatus, getValue } = props;
|
|
707
|
+
const { status, error } = getStatus();
|
|
708
|
+
const value3 = getValue();
|
|
709
|
+
if (layout === "static" && value3 == null) {
|
|
710
|
+
return null;
|
|
1152
711
|
}
|
|
712
|
+
const str = String(value3 ?? "");
|
|
713
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
714
|
+
role: "none",
|
|
715
|
+
className: "contents"
|
|
716
|
+
}, /* @__PURE__ */ React.createElement(Input.Root, {
|
|
717
|
+
validationValence: status
|
|
718
|
+
}, layout !== "inline" && /* @__PURE__ */ React.createElement(FormFieldLabel, {
|
|
719
|
+
error,
|
|
720
|
+
readonly,
|
|
721
|
+
label
|
|
722
|
+
}), layout === "static" ? /* @__PURE__ */ React.createElement("p", null, str) : children ? children({
|
|
723
|
+
value: value3
|
|
724
|
+
}) : null, layout === "full" && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Validation, null, error))));
|
|
1153
725
|
};
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
import React12, { forwardRef, useMemo as useMemo5 } from "react";
|
|
1160
|
-
import { createJsonPath as createJsonPath3, findNode as findNode3, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
1161
|
-
import { mx as mx8 } from "@dxos/react-ui-theme";
|
|
1162
|
-
import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
|
|
1163
|
-
import { isNotFalsy } from "@dxos/util";
|
|
1164
|
-
|
|
1165
|
-
// src/components/Form/ArrayField.tsx
|
|
1166
|
-
import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
|
|
1167
|
-
import { SchemaAST as SchemaAST3, pipe } from "effect";
|
|
1168
|
-
import { capitalize } from "effect/String";
|
|
1169
|
-
import React10, { Fragment, useCallback as useCallback7 } from "react";
|
|
1170
|
-
import { findNode as findNode2, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
1171
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1172
|
-
import { IconButton as IconButton3, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1173
|
-
import { getSchemaProperties } from "@dxos/schema";
|
|
1174
|
-
|
|
1175
|
-
// src/util/field.ts
|
|
1176
|
-
import { FormatEnum, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo-schema";
|
|
1177
|
-
var parseValue = ({ type, format, value }) => {
|
|
1178
|
-
if (value === void 0 || value === null || value === "") {
|
|
1179
|
-
return void 0;
|
|
726
|
+
var FormFieldErrorBoundary = class extends Component {
|
|
727
|
+
static getDerivedStateFromError(error) {
|
|
728
|
+
return {
|
|
729
|
+
error
|
|
730
|
+
};
|
|
1180
731
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
case TypeEnum.Boolean: {
|
|
1184
|
-
if (typeof value === "string") {
|
|
1185
|
-
const lowercaseValue = value.toLowerCase();
|
|
1186
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1187
|
-
return false;
|
|
1188
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1189
|
-
return true;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
return Boolean(value);
|
|
1193
|
-
}
|
|
1194
|
-
case TypeEnum.Number: {
|
|
1195
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1196
|
-
const num = Number(cleaned);
|
|
1197
|
-
return Number.isNaN(num) ? null : num;
|
|
1198
|
-
}
|
|
1199
|
-
case TypeEnum.String:
|
|
1200
|
-
case TypeEnum.Ref:
|
|
1201
|
-
return String(value);
|
|
1202
|
-
default: {
|
|
1203
|
-
return value;
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
732
|
+
state = {
|
|
733
|
+
error: void 0
|
|
1206
734
|
};
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
switch (format) {
|
|
1211
|
-
case FormatEnum.Boolean:
|
|
1212
|
-
return parseScalar(TypeEnum.Boolean);
|
|
1213
|
-
case FormatEnum.Number:
|
|
1214
|
-
case FormatEnum.Percent:
|
|
1215
|
-
case FormatEnum.Currency:
|
|
1216
|
-
return parseScalar(TypeEnum.Number);
|
|
1217
|
-
case FormatEnum.String:
|
|
1218
|
-
case FormatEnum.Markdown: {
|
|
1219
|
-
return parseScalar(TypeEnum.String);
|
|
1220
|
-
}
|
|
1221
|
-
case FormatEnum.Ref:
|
|
1222
|
-
throw new Error(`unexpected format: ${FormatEnum.Ref}`);
|
|
1223
|
-
case FormatEnum.DateTime:
|
|
1224
|
-
case FormatEnum.Date:
|
|
1225
|
-
case FormatEnum.Time:
|
|
1226
|
-
case FormatEnum.Timestamp: {
|
|
1227
|
-
const date = new Date(value);
|
|
1228
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1229
|
-
}
|
|
1230
|
-
case FormatEnum.GeoPoint: {
|
|
1231
|
-
if (typeof value === "string") {
|
|
1232
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1233
|
-
const parts = cleaned.split(",");
|
|
1234
|
-
if (parts.length === 2) {
|
|
1235
|
-
const lat = parseFloat(parts[0]);
|
|
1236
|
-
const long = parseFloat(parts[1]);
|
|
1237
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1238
|
-
return GeoLocation2.toGeoPoint({
|
|
1239
|
-
latitude: lat,
|
|
1240
|
-
longitude: long
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
return [
|
|
1246
|
-
0,
|
|
1247
|
-
0
|
|
1248
|
-
];
|
|
1249
|
-
}
|
|
1250
|
-
default: {
|
|
1251
|
-
return value;
|
|
735
|
+
componentDidUpdate(prevProps) {
|
|
736
|
+
if (prevProps.path !== this.props.path) {
|
|
737
|
+
this.resetError();
|
|
1252
738
|
}
|
|
1253
739
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
"font-mono"
|
|
1262
|
-
];
|
|
1263
|
-
case TypeEnum.Boolean:
|
|
1264
|
-
return [
|
|
1265
|
-
"text-right",
|
|
1266
|
-
"font-mono"
|
|
1267
|
-
];
|
|
1268
|
-
case TypeEnum.String:
|
|
1269
|
-
return void 0;
|
|
1270
|
-
case TypeEnum.Ref:
|
|
1271
|
-
return void 0;
|
|
1272
|
-
default: {
|
|
1273
|
-
return void 0;
|
|
1274
|
-
}
|
|
740
|
+
render() {
|
|
741
|
+
if (this.state.error) {
|
|
742
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
743
|
+
className: "flex gap-2 border border-rose-fill font-mono text-sm"
|
|
744
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
745
|
+
className: "bg-rose-fill text-surface-text px-1 font-thin"
|
|
746
|
+
}, "ERROR"), String(this.props.path?.join(".")));
|
|
1275
747
|
}
|
|
748
|
+
return this.props.children;
|
|
1276
749
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
case FormatEnum.Timestamp:
|
|
1282
|
-
case FormatEnum.DateTime:
|
|
1283
|
-
case FormatEnum.Date:
|
|
1284
|
-
case FormatEnum.Duration:
|
|
1285
|
-
return [
|
|
1286
|
-
"font-mono",
|
|
1287
|
-
"text-right"
|
|
1288
|
-
];
|
|
1289
|
-
case FormatEnum.Currency:
|
|
1290
|
-
return [
|
|
1291
|
-
"text-right"
|
|
1292
|
-
];
|
|
1293
|
-
case FormatEnum.JSON:
|
|
1294
|
-
case FormatEnum.DID:
|
|
1295
|
-
return [
|
|
1296
|
-
"font-mono"
|
|
1297
|
-
];
|
|
1298
|
-
default:
|
|
1299
|
-
return void 0;
|
|
750
|
+
resetError() {
|
|
751
|
+
this.setState({
|
|
752
|
+
error: void 0
|
|
753
|
+
});
|
|
1300
754
|
}
|
|
1301
755
|
};
|
|
1302
|
-
var pathNotUniqueError = (path) => ({
|
|
1303
|
-
path: "path",
|
|
1304
|
-
message: `'${path}' is already present`
|
|
1305
|
-
});
|
|
1306
756
|
|
|
1307
|
-
// src/
|
|
1308
|
-
import {
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
757
|
+
// src/components/Form/FormFieldSet.tsx
|
|
758
|
+
import React3, { useMemo as useMemo3 } from "react";
|
|
759
|
+
|
|
760
|
+
// src/components/Form/FormField.tsx
|
|
761
|
+
import * as Match from "effect/Match";
|
|
762
|
+
import * as Option2 from "effect/Option";
|
|
763
|
+
import * as Schema from "effect/Schema";
|
|
764
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
765
|
+
import * as String2 from "effect/String";
|
|
766
|
+
import React2, { useMemo as useMemo2 } from "react";
|
|
767
|
+
import { Format as Format3 } from "@dxos/echo";
|
|
768
|
+
import { createJsonPath as createJsonPath2, findNode, getAnnotation, getDiscriminatedType, isArrayType as isArrayType2, isDiscriminatedUnion, isLiteralUnion, isNestedType } from "@dxos/effect";
|
|
769
|
+
import { useTranslation } from "@dxos/react-ui";
|
|
770
|
+
var FormField = (props) => {
|
|
771
|
+
const {
|
|
772
|
+
type,
|
|
773
|
+
name,
|
|
774
|
+
path,
|
|
775
|
+
projection,
|
|
776
|
+
fieldMap,
|
|
777
|
+
fieldProvider,
|
|
778
|
+
readonly,
|
|
779
|
+
layout,
|
|
780
|
+
// RefFieldProps
|
|
781
|
+
createTypename,
|
|
782
|
+
createOptionLabel,
|
|
783
|
+
createOptionIcon,
|
|
784
|
+
createInitialValuePath,
|
|
785
|
+
createFieldMap,
|
|
786
|
+
db,
|
|
787
|
+
schemaHook,
|
|
788
|
+
getOptions: getRefOptions,
|
|
789
|
+
onCreate
|
|
790
|
+
} = props;
|
|
791
|
+
const { t } = useTranslation(translationKey);
|
|
792
|
+
const title = getAnnotation(SchemaAST.TitleAnnotationId)(type);
|
|
793
|
+
const description = getAnnotation(SchemaAST.DescriptionAnnotationId)(type);
|
|
794
|
+
const examples = getAnnotation(SchemaAST.ExamplesAnnotationId)(type);
|
|
795
|
+
const label = useMemo2(() => title ?? String2.capitalize(name), [
|
|
796
|
+
title,
|
|
797
|
+
name
|
|
798
|
+
]);
|
|
799
|
+
const placeholder = useMemo2(() => examples?.length ? `${t("example.placeholder")}: ${examples[0]}` : description ?? label, [
|
|
800
|
+
examples,
|
|
801
|
+
description,
|
|
802
|
+
label
|
|
803
|
+
]);
|
|
804
|
+
const fieldState = useFormFieldState(FormField.displayName, path);
|
|
805
|
+
const fieldProps = {
|
|
806
|
+
type,
|
|
807
|
+
format: Format3.FormatAnnotation.getFromAst(type).pipe((annotation) => Option2.getOrUndefined(annotation)),
|
|
808
|
+
readonly,
|
|
809
|
+
label,
|
|
810
|
+
placeholder,
|
|
811
|
+
layout,
|
|
812
|
+
...fieldState
|
|
1324
813
|
};
|
|
1325
|
-
|
|
1326
|
-
|
|
814
|
+
const jsonPath = createJsonPath2(path ?? []);
|
|
815
|
+
const CustomField = fieldMap?.[jsonPath];
|
|
816
|
+
if (CustomField) {
|
|
817
|
+
return /* @__PURE__ */ React2.createElement(CustomField, fieldProps);
|
|
818
|
+
}
|
|
819
|
+
const component = fieldProvider?.({
|
|
820
|
+
schema: Schema.make(type),
|
|
821
|
+
prop: name,
|
|
822
|
+
fieldProps
|
|
823
|
+
});
|
|
824
|
+
if (component) {
|
|
825
|
+
return component;
|
|
826
|
+
}
|
|
827
|
+
if (isArrayType2(type)) {
|
|
828
|
+
return /* @__PURE__ */ React2.createElement(ArrayField, {
|
|
829
|
+
fieldProps: fieldState,
|
|
830
|
+
label,
|
|
831
|
+
...props
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
const Field = getFormField(fieldProps);
|
|
835
|
+
if (Field) {
|
|
836
|
+
return /* @__PURE__ */ React2.createElement(Field, fieldProps);
|
|
837
|
+
}
|
|
838
|
+
const options = getOptions(type);
|
|
839
|
+
if (options) {
|
|
840
|
+
const fieldProjections = projection?.getFieldProjections();
|
|
841
|
+
const fieldProjection = fieldProjections?.find((fp) => fp.field.path === name);
|
|
842
|
+
const selectOptions = fieldProjection?.props.options;
|
|
843
|
+
return /* @__PURE__ */ React2.createElement(SelectField, {
|
|
844
|
+
...fieldProps,
|
|
845
|
+
options: options.map((option) => {
|
|
846
|
+
const selectOption = selectOptions?.find((so) => so.id === globalThis.String(option));
|
|
847
|
+
return {
|
|
848
|
+
value: option,
|
|
849
|
+
label: selectOption?.title ?? option.toString()
|
|
850
|
+
};
|
|
851
|
+
})
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
const refProps = getRefProps(type);
|
|
855
|
+
if (refProps) {
|
|
856
|
+
const isCreateTarget = !createTypename || refProps.typename === createTypename;
|
|
857
|
+
return /* @__PURE__ */ React2.createElement(RefField, {
|
|
858
|
+
...fieldProps,
|
|
859
|
+
...refProps,
|
|
860
|
+
createOptionLabel: isCreateTarget ? createOptionLabel : void 0,
|
|
861
|
+
createOptionIcon: isCreateTarget ? createOptionIcon : void 0,
|
|
862
|
+
createInitialValuePath: isCreateTarget ? createInitialValuePath : void 0,
|
|
863
|
+
createFieldMap: isCreateTarget ? createFieldMap : void 0,
|
|
864
|
+
db,
|
|
865
|
+
schemaHook,
|
|
866
|
+
getOptions: getRefOptions,
|
|
867
|
+
onCreate
|
|
868
|
+
});
|
|
1327
869
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
return
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
870
|
+
if (isNestedType(type)) {
|
|
871
|
+
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
872
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST.isTypeLiteral);
|
|
873
|
+
if (typeLiteral) {
|
|
874
|
+
const schema = Schema.make(typeLiteral);
|
|
875
|
+
return /* @__PURE__ */ React2.createElement(FormFieldSet, {
|
|
876
|
+
schema,
|
|
877
|
+
path,
|
|
878
|
+
readonly,
|
|
879
|
+
layout,
|
|
880
|
+
label,
|
|
881
|
+
projection,
|
|
882
|
+
fieldMap,
|
|
883
|
+
fieldProvider,
|
|
884
|
+
createOptionLabel,
|
|
885
|
+
createOptionIcon,
|
|
886
|
+
createInitialValuePath,
|
|
887
|
+
db,
|
|
888
|
+
schemaHook,
|
|
889
|
+
getOptions: getRefOptions,
|
|
890
|
+
onCreate
|
|
1348
891
|
});
|
|
1349
892
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
case
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
893
|
+
}
|
|
894
|
+
return null;
|
|
895
|
+
};
|
|
896
|
+
FormField.displayName = "Form.FormField";
|
|
897
|
+
var getFormField = ({ type, format }) => {
|
|
898
|
+
const formatField = Match.value(format).pipe(Match.withReturnType(), Match.when(Format3.TypeFormat.GeoPoint, () => GeoPointField), Match.when(Format3.TypeFormat.Markdown, () => MarkdownField), Match.when(Format3.TypeFormat.Text, () => TextAreaField), Match.orElse(() => void 0));
|
|
899
|
+
if (formatField) {
|
|
900
|
+
return formatField;
|
|
901
|
+
}
|
|
902
|
+
switch (type._tag) {
|
|
903
|
+
// TODO(wittjosiah): Schema.Any is currently used to represent template inputs.
|
|
904
|
+
case "AnyKeyword":
|
|
905
|
+
case "StringKeyword":
|
|
906
|
+
return TextField;
|
|
907
|
+
case "NumberKeyword":
|
|
908
|
+
return NumberField;
|
|
909
|
+
case "BooleanKeyword":
|
|
910
|
+
return BooleanField;
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
var getOptions = (ast) => {
|
|
914
|
+
if (isLiteralUnion(ast)) {
|
|
915
|
+
return ast.types.map((type) => type.literal).filter((v) => v !== null);
|
|
916
|
+
}
|
|
917
|
+
return Format3.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option2.getOrUndefined(annotation));
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
// src/components/Form/FormFieldSet.tsx
|
|
921
|
+
var FORM_FIELDSET_NAME = "Form.FieldSet";
|
|
922
|
+
var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection, layout, ...props }) => {
|
|
923
|
+
const values = useFormValues(FORM_FIELDSET_NAME, path);
|
|
924
|
+
const properties = useMemo3(() => {
|
|
925
|
+
if (!schema) {
|
|
926
|
+
return [];
|
|
1370
927
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
928
|
+
const schemaProps = getFormProperties(schema.ast);
|
|
929
|
+
const filteredProps = exclude ? exclude(schemaProps) : schemaProps;
|
|
930
|
+
if (projection) {
|
|
931
|
+
const fieldProjections = projection.getFieldProjections();
|
|
932
|
+
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
933
|
+
const visibleProps = filteredProps.filter((prop) => !hiddenProperties.has(prop.name.toString()));
|
|
934
|
+
const orderedProps = [];
|
|
935
|
+
for (const fieldProjection of fieldProjections) {
|
|
936
|
+
const fieldPath = String(fieldProjection.field.path);
|
|
937
|
+
const prop = visibleProps.find((p) => p.name === fieldPath);
|
|
938
|
+
if (prop) {
|
|
939
|
+
orderedProps.push(prop);
|
|
940
|
+
}
|
|
1378
941
|
}
|
|
1379
|
-
|
|
942
|
+
const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
|
|
943
|
+
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
944
|
+
orderedProps.push(...remainingProps);
|
|
945
|
+
return orderedProps;
|
|
1380
946
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
947
|
+
return sort ? [
|
|
948
|
+
...filteredProps
|
|
949
|
+
].sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString())) : filteredProps;
|
|
950
|
+
}, [
|
|
951
|
+
schema,
|
|
952
|
+
values,
|
|
953
|
+
exclude,
|
|
954
|
+
sort,
|
|
955
|
+
projection
|
|
956
|
+
]);
|
|
957
|
+
if ((readonly || layout === "static") && values == null) {
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, layout !== "inline" && label && /* @__PURE__ */ React3.createElement(FormFieldLabel, {
|
|
961
|
+
label,
|
|
962
|
+
asChild: true
|
|
963
|
+
}), properties.map((property) => {
|
|
964
|
+
const name = property.name.toString();
|
|
965
|
+
return /* @__PURE__ */ React3.createElement(FormFieldErrorBoundary, {
|
|
966
|
+
key: name,
|
|
967
|
+
path: [
|
|
968
|
+
...path ?? [],
|
|
969
|
+
name
|
|
970
|
+
]
|
|
971
|
+
}, /* @__PURE__ */ React3.createElement(FormField, {
|
|
972
|
+
type: property.type,
|
|
973
|
+
name,
|
|
974
|
+
path: [
|
|
975
|
+
...path ?? [],
|
|
976
|
+
name
|
|
977
|
+
],
|
|
978
|
+
readonly,
|
|
979
|
+
layout,
|
|
980
|
+
projection,
|
|
981
|
+
...props
|
|
982
|
+
}));
|
|
983
|
+
}));
|
|
984
|
+
};
|
|
985
|
+
FormFieldSet.displayName = FORM_FIELDSET_NAME;
|
|
986
|
+
|
|
987
|
+
// src/components/Form/Form.tsx
|
|
988
|
+
var omitId = (schema) => schema.pipe(Schema2.omit("id"));
|
|
989
|
+
var [FormContextProvider, useFormContext] = createContext("Form");
|
|
990
|
+
var useFormValues = (componentName, path, defaultValue) => {
|
|
991
|
+
const stablePath = useMemo4(() => path ?? [], [
|
|
992
|
+
path ? path.join(".") : void 0
|
|
993
|
+
]);
|
|
994
|
+
const jsonPath = createJsonPath3(stablePath);
|
|
995
|
+
const { form: { values, onValueChange } } = useFormContext(componentName);
|
|
996
|
+
const value3 = getValue$2(values, jsonPath);
|
|
997
|
+
const lastAppliedPathRef = useRef(null);
|
|
998
|
+
useEffect3(() => {
|
|
999
|
+
if (value3 == null && defaultValue && lastAppliedPathRef.current !== jsonPath) {
|
|
1000
|
+
lastAppliedPathRef.current = jsonPath;
|
|
1001
|
+
onValueChange(stablePath, SchemaAST2.stringKeyword, defaultValue());
|
|
1386
1002
|
}
|
|
1003
|
+
}, [
|
|
1004
|
+
value3,
|
|
1005
|
+
defaultValue,
|
|
1006
|
+
onValueChange,
|
|
1007
|
+
stablePath,
|
|
1008
|
+
jsonPath
|
|
1009
|
+
]);
|
|
1010
|
+
return value3;
|
|
1011
|
+
};
|
|
1012
|
+
var useFormFieldState = (componentName, path = []) => {
|
|
1013
|
+
const stablePath = useMemo4(() => path, [
|
|
1014
|
+
Array.isArray(path) ? path.join(".") : path
|
|
1015
|
+
]);
|
|
1016
|
+
const { form: { getStatus, getValue, onBlur, onValueChange } } = useFormContext(componentName);
|
|
1017
|
+
return useMemo4(() => ({
|
|
1018
|
+
getStatus: () => getStatus(stablePath),
|
|
1019
|
+
getValue: () => getValue(stablePath),
|
|
1020
|
+
onBlur: () => onBlur(stablePath),
|
|
1021
|
+
onValueChange: (ast, value3) => onValueChange(stablePath, ast, value3)
|
|
1022
|
+
}), [
|
|
1023
|
+
getStatus,
|
|
1024
|
+
getValue,
|
|
1025
|
+
onBlur,
|
|
1026
|
+
onValueChange,
|
|
1027
|
+
stablePath
|
|
1028
|
+
]);
|
|
1029
|
+
};
|
|
1030
|
+
var FormRoot = ({ children, schema, values, onSave, onCancel, ...props }) => {
|
|
1031
|
+
const form = useFormHandler({
|
|
1032
|
+
schema,
|
|
1033
|
+
values,
|
|
1034
|
+
onSave,
|
|
1035
|
+
onCancel,
|
|
1036
|
+
...props
|
|
1037
|
+
});
|
|
1038
|
+
return /* @__PURE__ */ React4.createElement(FormContextProvider, {
|
|
1039
|
+
form,
|
|
1040
|
+
...props
|
|
1041
|
+
}, children);
|
|
1042
|
+
};
|
|
1043
|
+
FormRoot.displayName = "Form.Root";
|
|
1044
|
+
var FORM_VIEWPORT_NAME = "Form.Viewport";
|
|
1045
|
+
var FormViewport = composable(({ children, ...props }, forwardedRef) => {
|
|
1046
|
+
return /* @__PURE__ */ React4.createElement(ScrollArea.Root, {
|
|
1047
|
+
...composableProps(props),
|
|
1048
|
+
orientation: "vertical",
|
|
1049
|
+
centered: true,
|
|
1050
|
+
padding: true,
|
|
1051
|
+
thin: true,
|
|
1052
|
+
ref: forwardedRef
|
|
1053
|
+
}, /* @__PURE__ */ React4.createElement(ScrollArea.Viewport, null, children));
|
|
1054
|
+
});
|
|
1055
|
+
FormViewport.displayName = FORM_VIEWPORT_NAME;
|
|
1056
|
+
var FORM_CONTENT_NAME = "Form.Content";
|
|
1057
|
+
var FormContent = ({ classNames, children }) => {
|
|
1058
|
+
const { form, testId } = useFormContext(FORM_CONTENT_NAME);
|
|
1059
|
+
const ref = useRef(null);
|
|
1060
|
+
useKeyHandler(ref.current, form);
|
|
1061
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1062
|
+
ref,
|
|
1063
|
+
role: "form",
|
|
1064
|
+
className: mx("flex flex-col w-full", classNames),
|
|
1065
|
+
"data-testid": testId
|
|
1066
|
+
}, children);
|
|
1067
|
+
};
|
|
1068
|
+
FormContent.displayName = FORM_CONTENT_NAME;
|
|
1069
|
+
var FORM_FIELDSET_NAME2 = "Form.FieldSet";
|
|
1070
|
+
var FormFieldSet2 = (props) => {
|
|
1071
|
+
const { form, ...contextProps } = useFormContext(FORM_FIELDSET_NAME2);
|
|
1072
|
+
return /* @__PURE__ */ React4.createElement(FormFieldSet, {
|
|
1073
|
+
schema: form.schema,
|
|
1074
|
+
...contextProps,
|
|
1075
|
+
...props
|
|
1076
|
+
});
|
|
1077
|
+
};
|
|
1078
|
+
FormFieldSet2.displayName = FORM_FIELDSET_NAME2;
|
|
1079
|
+
var FORM_ACTIONS_NAME = "Form.Actions";
|
|
1080
|
+
var FormActions = ({ classNames }) => {
|
|
1081
|
+
const { t } = useTranslation2(translationKey);
|
|
1082
|
+
const { form: { canSave, onSave, onCancel }, readonly, layout } = useFormContext(FORM_ACTIONS_NAME);
|
|
1083
|
+
if (readonly || layout === "static") {
|
|
1084
|
+
return null;
|
|
1387
1085
|
}
|
|
1086
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1087
|
+
role: "none",
|
|
1088
|
+
className: mx("grid grid-flow-col gap-form-gap auto-cols-fr py-form-padding", classNames)
|
|
1089
|
+
}, onCancel && /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1090
|
+
icon: "ph--x--regular",
|
|
1091
|
+
iconEnd: true,
|
|
1092
|
+
label: t("cancel-button.label"),
|
|
1093
|
+
onClick: onCancel,
|
|
1094
|
+
"data-testid": "cancel-button"
|
|
1095
|
+
}), onSave && /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1096
|
+
type: "submit",
|
|
1097
|
+
variant: "primary",
|
|
1098
|
+
disabled: !canSave,
|
|
1099
|
+
icon: "ph--check--regular",
|
|
1100
|
+
iconEnd: true,
|
|
1101
|
+
label: t("save-button.label"),
|
|
1102
|
+
onClick: onSave,
|
|
1103
|
+
"data-testid": "save-button"
|
|
1104
|
+
}));
|
|
1388
1105
|
};
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1106
|
+
FormActions.displayName = FORM_ACTIONS_NAME;
|
|
1107
|
+
var FORM_SUBMIT_NAME = "Form.Submit";
|
|
1108
|
+
var FormSubmit = ({ classNames, label, icon, disabled }) => {
|
|
1109
|
+
const { t } = useTranslation2(translationKey);
|
|
1110
|
+
const { form: { canSave, onSave }, readonly, layout } = useFormContext(FORM_SUBMIT_NAME);
|
|
1111
|
+
if (readonly || layout === "static") {
|
|
1112
|
+
return null;
|
|
1113
|
+
}
|
|
1114
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1115
|
+
role: "none",
|
|
1116
|
+
className: mx("flex w-full pt-form-padding", classNames)
|
|
1117
|
+
}, /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1118
|
+
classNames: "w-full",
|
|
1119
|
+
type: "submit",
|
|
1120
|
+
variant: "primary",
|
|
1121
|
+
disabled: disabled ?? !canSave,
|
|
1122
|
+
icon: icon ?? "ph--check--regular",
|
|
1123
|
+
label: label ?? t("save-button.label"),
|
|
1124
|
+
onClick: onSave,
|
|
1125
|
+
"data-testid": "save-button"
|
|
1126
|
+
}));
|
|
1127
|
+
};
|
|
1128
|
+
FormSubmit.displayName = FORM_SUBMIT_NAME;
|
|
1129
|
+
var Form = {
|
|
1130
|
+
Root: FormRoot,
|
|
1131
|
+
Viewport: FormViewport,
|
|
1132
|
+
Content: FormContent,
|
|
1133
|
+
FieldSet: FormFieldSet2,
|
|
1134
|
+
Label: FormFieldLabel,
|
|
1135
|
+
Actions: FormActions,
|
|
1136
|
+
Submit: FormSubmit
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
// src/components/Form/fields/ArrayField.tsx
|
|
1140
|
+
var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps, ...props }) => {
|
|
1141
|
+
const { t } = useTranslation3(translationKey);
|
|
1142
|
+
const elementType = getArrayElementType2(type);
|
|
1143
|
+
const { onValueChange } = inputProps;
|
|
1144
|
+
const values = useFormValues(ArrayField.displayName, path, () => []);
|
|
1145
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1146
|
+
const baseNode = findNode2(typeNode, isDiscriminatedUnion2);
|
|
1147
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
|
|
1148
|
+
if (!typeLiteral) {
|
|
1149
|
+
return {};
|
|
1399
1150
|
}
|
|
1151
|
+
return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
|
|
1152
|
+
const defaultValue = SchemaAST3.getDefaultAnnotation(prop.type).pipe((annotation) => Option3.getOrUndefined(annotation));
|
|
1153
|
+
return [
|
|
1154
|
+
prop.name,
|
|
1155
|
+
defaultValue
|
|
1156
|
+
];
|
|
1157
|
+
}));
|
|
1400
1158
|
};
|
|
1401
|
-
|
|
1402
|
-
|
|
1159
|
+
const handleAdd = useCallback3(() => {
|
|
1160
|
+
const defaultValue = isNestedType2(type) && elementType ? getDefaultObjectValue(elementType) : getDefaultValue(elementType);
|
|
1161
|
+
values && onValueChange(type, [
|
|
1162
|
+
...values,
|
|
1163
|
+
defaultValue
|
|
1164
|
+
]);
|
|
1165
|
+
}, [
|
|
1166
|
+
onValueChange,
|
|
1167
|
+
type,
|
|
1168
|
+
elementType,
|
|
1169
|
+
values
|
|
1170
|
+
]);
|
|
1171
|
+
const handleDelete = useCallback3((idx) => {
|
|
1172
|
+
onValueChange(type, values?.filter((_, i) => i !== idx));
|
|
1173
|
+
}, [
|
|
1174
|
+
onValueChange,
|
|
1175
|
+
type,
|
|
1176
|
+
values
|
|
1177
|
+
]);
|
|
1178
|
+
if (!elementType || (readonly || layout === "static") && values && values.length < 1) {
|
|
1179
|
+
return null;
|
|
1403
1180
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1181
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, (layout !== "static" || values && values.length > 0) && /* @__PURE__ */ React5.createElement(FormFieldLabel, {
|
|
1182
|
+
readonly,
|
|
1183
|
+
label,
|
|
1184
|
+
asChild: true
|
|
1185
|
+
}), /* @__PURE__ */ React5.createElement("div", {
|
|
1186
|
+
role: "none",
|
|
1187
|
+
className: "flex flex-col gap-form-gap"
|
|
1188
|
+
}, values?.map((_, index) => {
|
|
1189
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1190
|
+
role: "none",
|
|
1191
|
+
key: index,
|
|
1192
|
+
className: "flex gap-form-gap last:mb-form-gap"
|
|
1193
|
+
}, /* @__PURE__ */ React5.createElement(FormField, {
|
|
1194
|
+
autoFocus: index === values.length - 1,
|
|
1195
|
+
type: elementType,
|
|
1196
|
+
path: [
|
|
1197
|
+
...path ?? [],
|
|
1198
|
+
index
|
|
1199
|
+
],
|
|
1200
|
+
readonly: readonly || layout === "static",
|
|
1201
|
+
layout: "inline",
|
|
1202
|
+
...props
|
|
1203
|
+
}), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement("div", {
|
|
1204
|
+
role: "none",
|
|
1205
|
+
className: "flex flex-col h-full justify-end"
|
|
1206
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
1207
|
+
role: "none",
|
|
1208
|
+
className: "flex items-center h-[2rem]"
|
|
1209
|
+
}, /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1210
|
+
icon: "ph--x--regular",
|
|
1211
|
+
iconOnly: true,
|
|
1212
|
+
label: t("remove.button"),
|
|
1213
|
+
onClick: () => handleDelete(index),
|
|
1214
|
+
classNames: "self-center"
|
|
1215
|
+
}))));
|
|
1216
|
+
})), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1217
|
+
classNames: "flex w-full",
|
|
1218
|
+
icon: "ph--plus--regular",
|
|
1219
|
+
label: t("add-field.button"),
|
|
1220
|
+
onClick: handleAdd
|
|
1221
|
+
}));
|
|
1222
|
+
};
|
|
1223
|
+
ArrayField.displayName = "Form.ArrayField";
|
|
1224
|
+
var getDefaultValue = (ast) => {
|
|
1225
|
+
switch (ast?._tag) {
|
|
1226
|
+
case "StringKeyword": {
|
|
1227
|
+
return "";
|
|
1420
1228
|
}
|
|
1421
|
-
case
|
|
1422
|
-
|
|
1423
|
-
return date.toISOString().split("T")[0];
|
|
1229
|
+
case "NumberKeyword": {
|
|
1230
|
+
return 0;
|
|
1424
1231
|
}
|
|
1425
|
-
case
|
|
1426
|
-
|
|
1427
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
1232
|
+
case "BooleanKeyword": {
|
|
1233
|
+
return false;
|
|
1428
1234
|
}
|
|
1429
|
-
case
|
|
1430
|
-
|
|
1431
|
-
return "";
|
|
1432
|
-
}
|
|
1433
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1434
|
-
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1435
|
-
return `${latitude},${longitude}`;
|
|
1436
|
-
}
|
|
1437
|
-
return String(value);
|
|
1235
|
+
case "Suspend": {
|
|
1236
|
+
return getDefaultValue(ast.f());
|
|
1438
1237
|
}
|
|
1439
1238
|
default: {
|
|
1440
|
-
|
|
1239
|
+
if (ast && isNestedType2(ast)) {
|
|
1240
|
+
return {};
|
|
1241
|
+
} else {
|
|
1242
|
+
throw new Error(`Unsupported type: ${ast?._tag}`);
|
|
1243
|
+
}
|
|
1441
1244
|
}
|
|
1442
1245
|
}
|
|
1443
1246
|
};
|
|
1444
1247
|
|
|
1445
|
-
// src/
|
|
1446
|
-
import {
|
|
1447
|
-
import {
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1248
|
+
// src/components/Form/fields/BooleanField.tsx
|
|
1249
|
+
import React6, { useCallback as useCallback4 } from "react";
|
|
1250
|
+
import { Input as Input2 } from "@dxos/react-ui";
|
|
1251
|
+
var BooleanField = ({ type, readonly, onValueChange, ...props }) => {
|
|
1252
|
+
const handleChange = useCallback4((value3) => onValueChange?.(type, value3), [
|
|
1253
|
+
type,
|
|
1254
|
+
onValueChange
|
|
1255
|
+
]);
|
|
1256
|
+
return /* @__PURE__ */ React6.createElement(FormFieldWrapper, {
|
|
1257
|
+
readonly,
|
|
1258
|
+
...props
|
|
1259
|
+
}, ({ value: value3 }) => /* @__PURE__ */ React6.createElement(Input2.Switch, {
|
|
1260
|
+
disabled: !!readonly,
|
|
1261
|
+
checked: value3,
|
|
1262
|
+
onCheckedChange: handleChange
|
|
1263
|
+
}));
|
|
1456
1264
|
};
|
|
1457
1265
|
|
|
1458
|
-
// src/
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1266
|
+
// src/components/Form/fields/GeoPointField.tsx
|
|
1267
|
+
import React7, { useCallback as useCallback5, useEffect as useEffect4, useMemo as useMemo5, useState as useState2 } from "react";
|
|
1268
|
+
import { GeoLocation as GeoLocation3 } from "@dxos/echo/internal";
|
|
1269
|
+
import { Input as Input3, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
1270
|
+
import { safeParseFloat } from "@dxos/util";
|
|
1271
|
+
var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1272
|
+
const { t } = useTranslation4(translationKey);
|
|
1273
|
+
const { status, error } = getStatus();
|
|
1274
|
+
const geoPoint = useMemo5(() => getValue() ?? [
|
|
1275
|
+
0,
|
|
1276
|
+
0
|
|
1277
|
+
], [
|
|
1278
|
+
getValue
|
|
1279
|
+
]);
|
|
1280
|
+
const value3 = useMemo5(() => GeoLocation3.fromGeoPoint(geoPoint), [
|
|
1281
|
+
geoPoint
|
|
1282
|
+
]);
|
|
1283
|
+
const [longitudeText, setLongitudeText] = useState2(value3.longitude?.toString());
|
|
1284
|
+
const [latitudeText, setLatitudeText] = useState2(value3.latitude?.toString());
|
|
1285
|
+
useEffect4(() => {
|
|
1286
|
+
const location = GeoLocation3.fromGeoPoint(geoPoint);
|
|
1287
|
+
setLongitudeText(location.longitude?.toString());
|
|
1288
|
+
setLatitudeText(location.latitude?.toString());
|
|
1289
|
+
}, [
|
|
1290
|
+
geoPoint
|
|
1291
|
+
]);
|
|
1292
|
+
const handleChange = useCallback5((coordinateType, setText) => (event) => {
|
|
1293
|
+
const inputText = event.target.value;
|
|
1294
|
+
setText(inputText);
|
|
1295
|
+
if (inputText !== "" && inputText !== "-") {
|
|
1296
|
+
const coord = safeParseFloat(inputText);
|
|
1297
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
1298
|
+
const currentLocation = GeoLocation3.fromGeoPoint(getValue() ?? [
|
|
1299
|
+
0,
|
|
1300
|
+
0
|
|
1301
|
+
]);
|
|
1302
|
+
const newLocation = {
|
|
1303
|
+
...currentLocation,
|
|
1304
|
+
[coordinateType]: coord
|
|
1475
1305
|
};
|
|
1306
|
+
const newValue = GeoLocation3.toGeoPoint(newLocation);
|
|
1307
|
+
onValueChange(type, newValue);
|
|
1476
1308
|
}
|
|
1477
1309
|
}
|
|
1310
|
+
}, [
|
|
1311
|
+
type,
|
|
1312
|
+
getValue,
|
|
1313
|
+
onValueChange
|
|
1314
|
+
]);
|
|
1315
|
+
if ((readonly || layout === "static") && !value3?.latitude && !value3?.longitude) {
|
|
1316
|
+
return null;
|
|
1478
1317
|
}
|
|
1479
|
-
return
|
|
1318
|
+
return /* @__PURE__ */ React7.createElement(Input3.Root, {
|
|
1319
|
+
validationValence: status
|
|
1320
|
+
}, layout !== "inline" && /* @__PURE__ */ React7.createElement(FormFieldLabel, {
|
|
1321
|
+
error,
|
|
1322
|
+
readonly,
|
|
1323
|
+
label,
|
|
1324
|
+
asChild: true
|
|
1325
|
+
}), layout === "static" ? /* @__PURE__ */ React7.createElement(LatLng, value3) : /* @__PURE__ */ React7.createElement("div", {
|
|
1326
|
+
role: "none",
|
|
1327
|
+
className: "grid grid-cols-2 gap-form-gap"
|
|
1328
|
+
}, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("latitude.label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1329
|
+
type: "number",
|
|
1330
|
+
step: "0.00001",
|
|
1331
|
+
min: "-90",
|
|
1332
|
+
max: "90",
|
|
1333
|
+
disabled: !!readonly,
|
|
1334
|
+
placeholder: t("latitude.placeholder"),
|
|
1335
|
+
value: latitudeText ?? "",
|
|
1336
|
+
onChange: handleChange("latitude", setLatitudeText),
|
|
1337
|
+
onBlur
|
|
1338
|
+
}))), /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("longitude.label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1339
|
+
type: "number",
|
|
1340
|
+
step: "0.00001",
|
|
1341
|
+
min: "-180",
|
|
1342
|
+
max: "180",
|
|
1343
|
+
disabled: !!readonly,
|
|
1344
|
+
placeholder: t("longitude.placeholder"),
|
|
1345
|
+
value: longitudeText ?? "",
|
|
1346
|
+
onChange: handleChange("longitude", setLongitudeText),
|
|
1347
|
+
onBlur
|
|
1348
|
+
})))));
|
|
1349
|
+
};
|
|
1350
|
+
var LatLng = ({ latitude = 0, longitude = 0 }) => {
|
|
1351
|
+
const latHem = latitude >= 0 ? "N" : "S";
|
|
1352
|
+
const lngHem = longitude >= 0 ? "E" : "W";
|
|
1353
|
+
return /* @__PURE__ */ React7.createElement("span", {
|
|
1354
|
+
className: "inline-flex items-center gap-form-gap"
|
|
1355
|
+
}, /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(latitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
|
|
1356
|
+
className: "text-subdued"
|
|
1357
|
+
}, "\xB0", latHem)), /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(longitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
|
|
1358
|
+
className: "text-subdued"
|
|
1359
|
+
}, "\xB0", lngHem)));
|
|
1480
1360
|
};
|
|
1481
1361
|
|
|
1482
|
-
// src/components/Form/
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
const
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
S: void 0,
|
|
1494
|
-
A: [
|
|
1495
|
-
"Array.isArray(values)",
|
|
1496
|
-
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1497
|
-
]
|
|
1498
|
-
});
|
|
1499
|
-
const label = title ?? pipe(name, capitalize);
|
|
1500
|
-
const elementType = findArrayElementType(ast);
|
|
1501
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
1502
|
-
const baseNode = findNode2(typeNode, isDiscriminatedUnion);
|
|
1503
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
|
|
1504
|
-
if (!typeLiteral) {
|
|
1505
|
-
return {};
|
|
1506
|
-
}
|
|
1507
|
-
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
|
|
1508
|
-
prop.name,
|
|
1509
|
-
prop.defaultValue
|
|
1510
|
-
]));
|
|
1511
|
-
};
|
|
1512
|
-
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
1513
|
-
const handleAdd = useCallback7(() => {
|
|
1514
|
-
inputProps.onValueChange(type, [
|
|
1515
|
-
...values,
|
|
1516
|
-
getDefaultValue()
|
|
1517
|
-
]);
|
|
1518
|
-
}, [
|
|
1519
|
-
type,
|
|
1520
|
-
elementType,
|
|
1521
|
-
inputProps,
|
|
1522
|
-
values
|
|
1523
|
-
]);
|
|
1524
|
-
const handleRemove = useCallback7((index) => {
|
|
1525
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
1526
|
-
inputProps.onValueChange(type, newValues);
|
|
1527
|
-
}, [
|
|
1528
|
-
type,
|
|
1529
|
-
inputProps,
|
|
1530
|
-
values
|
|
1531
|
-
]);
|
|
1532
|
-
if (!elementType) {
|
|
1533
|
-
return null;
|
|
1362
|
+
// src/components/Form/fields/MarkdownField.tsx
|
|
1363
|
+
import React8, { useCallback as useCallback6, useEffect as useEffect5, useRef as useRef2 } from "react";
|
|
1364
|
+
import { Input as Input4 } from "@dxos/react-ui";
|
|
1365
|
+
var MarkdownField = ({ type, readonly, label, placeholder, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1366
|
+
const { status, error } = getStatus();
|
|
1367
|
+
const textareaRef = useRef2(null);
|
|
1368
|
+
const adjustHeight = useCallback6(() => {
|
|
1369
|
+
const textarea = textareaRef.current;
|
|
1370
|
+
if (textarea) {
|
|
1371
|
+
textarea.style.blockSize = "auto";
|
|
1372
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
1534
1373
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
Custom,
|
|
1555
|
-
lookupComponent
|
|
1556
|
-
});
|
|
1557
|
-
return readonly ? field : /* @__PURE__ */ React10.createElement(Fragment, {
|
|
1558
|
-
key: index
|
|
1559
|
-
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1560
|
-
role: "none"
|
|
1561
|
-
}, field), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1562
|
-
icon: "ph--trash--regular",
|
|
1563
|
-
iconOnly: true,
|
|
1564
|
-
label: t("button remove"),
|
|
1565
|
-
onClick: () => handleRemove(index),
|
|
1566
|
-
classNames: "self-center"
|
|
1567
|
-
}));
|
|
1568
|
-
})), !readonly && /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1569
|
-
classNames: "is-full mlb-cardSpacingBlock flex",
|
|
1570
|
-
icon: "ph--plus--regular",
|
|
1571
|
-
label: t("add field"),
|
|
1572
|
-
onClick: handleAdd
|
|
1573
|
-
}));
|
|
1574
|
-
} finally {
|
|
1575
|
-
_effect.f();
|
|
1374
|
+
}, []);
|
|
1375
|
+
useEffect5(() => {
|
|
1376
|
+
adjustHeight();
|
|
1377
|
+
}, [
|
|
1378
|
+
adjustHeight
|
|
1379
|
+
]);
|
|
1380
|
+
useEffect5(() => {
|
|
1381
|
+
adjustHeight();
|
|
1382
|
+
}, [
|
|
1383
|
+
getValue(),
|
|
1384
|
+
adjustHeight
|
|
1385
|
+
]);
|
|
1386
|
+
const handleChange = useCallback6((event) => onValueChange(type, event.target.value), [
|
|
1387
|
+
type,
|
|
1388
|
+
onValueChange
|
|
1389
|
+
]);
|
|
1390
|
+
const value3 = getValue();
|
|
1391
|
+
if ((readonly || layout === "static") && !value3) {
|
|
1392
|
+
return null;
|
|
1576
1393
|
}
|
|
1394
|
+
return /* @__PURE__ */ React8.createElement(Input4.Root, {
|
|
1395
|
+
validationValence: status
|
|
1396
|
+
}, layout !== "inline" && /* @__PURE__ */ React8.createElement(FormFieldLabel, {
|
|
1397
|
+
error,
|
|
1398
|
+
readonly,
|
|
1399
|
+
label
|
|
1400
|
+
}), layout === "static" ? /* @__PURE__ */ React8.createElement("p", null, value3) : /* @__PURE__ */ React8.createElement(Input4.TextArea, {
|
|
1401
|
+
ref: textareaRef,
|
|
1402
|
+
disabled: !!readonly,
|
|
1403
|
+
placeholder,
|
|
1404
|
+
value: value3 ?? "",
|
|
1405
|
+
classNames: "min-h-auto max-h-40 overflow-auto",
|
|
1406
|
+
onChange: handleChange,
|
|
1407
|
+
onBlur,
|
|
1408
|
+
style: {
|
|
1409
|
+
resize: "none"
|
|
1410
|
+
},
|
|
1411
|
+
spellCheck: false
|
|
1412
|
+
}), layout === "full" && /* @__PURE__ */ React8.createElement(Input4.Validation, null, error));
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
// src/components/Form/fields/NumberField.tsx
|
|
1416
|
+
import React9, { useCallback as useCallback7 } from "react";
|
|
1417
|
+
import { Input as Input5 } from "@dxos/react-ui";
|
|
1418
|
+
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
1419
|
+
var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1420
|
+
const handleChange = useCallback7((event) => onValueChange(type, safeParseFloat2(event.target.value) || 0), [
|
|
1421
|
+
type,
|
|
1422
|
+
onValueChange
|
|
1423
|
+
]);
|
|
1424
|
+
return /* @__PURE__ */ React9.createElement(FormFieldWrapper, {
|
|
1425
|
+
readonly,
|
|
1426
|
+
...props
|
|
1427
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React9.createElement(Input5.TextInput, {
|
|
1428
|
+
type: "number",
|
|
1429
|
+
disabled: !!readonly,
|
|
1430
|
+
placeholder,
|
|
1431
|
+
value: value3,
|
|
1432
|
+
onChange: handleChange,
|
|
1433
|
+
onBlur
|
|
1434
|
+
}));
|
|
1577
1435
|
};
|
|
1578
1436
|
|
|
1579
|
-
// src/components/Form/RefField.tsx
|
|
1580
|
-
import
|
|
1581
|
-
import React11, { useCallback as
|
|
1582
|
-
import {
|
|
1437
|
+
// src/components/Form/fields/RefField.tsx
|
|
1438
|
+
import "@dxos/lit-ui/dx-tag-picker.pcss";
|
|
1439
|
+
import React11, { useCallback as useCallback9, useMemo as useMemo6 } from "react";
|
|
1440
|
+
import { Entity, Filter, Obj, Ref as Ref2, Type } from "@dxos/echo";
|
|
1441
|
+
import { ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo/internal";
|
|
1442
|
+
import { useQuery, useSchema as useSchema$ } from "@dxos/echo-react";
|
|
1583
1443
|
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
1584
1444
|
import { DXN } from "@dxos/keys";
|
|
1585
|
-
import {
|
|
1586
|
-
import { Input as
|
|
1587
|
-
import {
|
|
1588
|
-
import {
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1445
|
+
import { DxAnchor } from "@dxos/lit-ui/react";
|
|
1446
|
+
import { Button, Icon as Icon2, Input as Input6, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1447
|
+
import { ParentLabelAnnotationId } from "@dxos/schema";
|
|
1448
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1449
|
+
|
|
1450
|
+
// src/components/ObjectPicker/ObjectPicker.tsx
|
|
1451
|
+
import React10, { forwardRef, useCallback as useCallback8, useState as useState3 } from "react";
|
|
1452
|
+
import { Popover, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1453
|
+
import { Combobox, useSearchListInput, useSearchListResults } from "@dxos/react-ui-search";
|
|
1454
|
+
var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap, onSelect, onCreate, ...props }, forwardedRef) => {
|
|
1455
|
+
const { t } = useTranslation5(translationKey);
|
|
1456
|
+
const [showForm, setShowForm] = useState3(false);
|
|
1457
|
+
const [formInitialValue, setFormInitialValue] = useState3("");
|
|
1458
|
+
const { results, handleSearch } = useSearchListResults({
|
|
1459
|
+
items: options
|
|
1460
|
+
});
|
|
1461
|
+
const handleFormSave = useCallback8((values) => {
|
|
1462
|
+
onCreate?.(values);
|
|
1463
|
+
setShowForm(false);
|
|
1464
|
+
setFormInitialValue("");
|
|
1465
|
+
}, [
|
|
1466
|
+
onCreate
|
|
1467
|
+
]);
|
|
1468
|
+
const handleFormCancel = useCallback8(() => {
|
|
1469
|
+
setShowForm(false);
|
|
1470
|
+
setFormInitialValue("");
|
|
1471
|
+
}, []);
|
|
1472
|
+
const handleKeyDown = useCallback8((event) => {
|
|
1473
|
+
if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
|
|
1474
|
+
event.stopPropagation();
|
|
1475
|
+
event.preventDefault();
|
|
1476
|
+
const input = event.currentTarget.querySelector('input[type="text"]');
|
|
1477
|
+
const currentQuery = input?.value || "";
|
|
1478
|
+
setFormInitialValue(currentQuery);
|
|
1479
|
+
setShowForm(true);
|
|
1613
1480
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
if (matchingOption) {
|
|
1621
|
-
return matchingOption;
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
return void 0;
|
|
1625
|
-
};
|
|
1626
|
-
if (array && Array.isArray(formValue)) {
|
|
1627
|
-
return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
|
|
1628
|
-
}
|
|
1629
|
-
const option = unknownToRefOption(formValue);
|
|
1630
|
-
if (option) {
|
|
1631
|
-
return [
|
|
1632
|
-
option
|
|
1633
|
-
];
|
|
1634
|
-
}
|
|
1635
|
-
return [];
|
|
1636
|
-
}, [
|
|
1637
|
-
getValue3,
|
|
1638
|
-
availableOptions,
|
|
1639
|
-
array
|
|
1640
|
-
]);
|
|
1641
|
-
const handleSearch = useCallback8((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1642
|
-
id: option.id,
|
|
1643
|
-
label: option.label,
|
|
1644
|
-
hue: option.hue
|
|
1645
|
-
})), [
|
|
1646
|
-
availableOptions
|
|
1647
|
-
]);
|
|
1648
|
-
const handleUpdate = useCallback8((ids) => {
|
|
1649
|
-
if (ids.length === 0) {
|
|
1650
|
-
onValueChange("object", void 0);
|
|
1651
|
-
return;
|
|
1652
|
-
}
|
|
1653
|
-
const refs = ids.map((id) => {
|
|
1654
|
-
const item = availableOptions.find((option) => option.id === id);
|
|
1655
|
-
if (item) {
|
|
1656
|
-
const dxn = DXN.parse(item.id);
|
|
1657
|
-
return Ref.fromDXN(dxn);
|
|
1658
|
-
}
|
|
1659
|
-
return null;
|
|
1660
|
-
}).filter(isNonNullable2);
|
|
1661
|
-
if (array) {
|
|
1662
|
-
onValueChange("object", refs);
|
|
1663
|
-
} else {
|
|
1664
|
-
onValueChange("object", refs[0]);
|
|
1665
|
-
}
|
|
1666
|
-
}, [
|
|
1667
|
-
availableOptions,
|
|
1668
|
-
array,
|
|
1669
|
-
onValueChange
|
|
1670
|
-
]);
|
|
1671
|
-
const tagPickerMode = useMemo4(() => array ? "multi-select" : "single-select", [
|
|
1672
|
-
array
|
|
1673
|
-
]);
|
|
1674
|
-
if (!refTypeInfo) {
|
|
1675
|
-
return null;
|
|
1676
|
-
}
|
|
1677
|
-
const { status, error } = restInputProps.getStatus();
|
|
1678
|
-
const items = handleGetValue();
|
|
1679
|
-
return disabled && items.length < 1 ? null : /* @__PURE__ */ React11.createElement(Input8.Root, {
|
|
1680
|
-
validationValence: status
|
|
1681
|
-
}, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
|
|
1682
|
-
error,
|
|
1683
|
-
label
|
|
1684
|
-
}), /* @__PURE__ */ React11.createElement("div", {
|
|
1685
|
-
"data-no-submit": true
|
|
1686
|
-
}, disabled ? items.length < 1 ? /* @__PURE__ */ React11.createElement("p", {
|
|
1687
|
-
className: mx7(descriptionText, "mbe-2")
|
|
1688
|
-
}, t("empty readonly ref field label")) : items.map((item) => /* @__PURE__ */ React11.createElement(DxRefTag, {
|
|
1689
|
-
key: item.id,
|
|
1690
|
-
refid: item.id,
|
|
1691
|
-
rootclassname: "mie-1",
|
|
1692
|
-
style: {
|
|
1693
|
-
marginInlineEnd: ".25rem"
|
|
1694
|
-
}
|
|
1695
|
-
}, item.label)) : /* @__PURE__ */ React11.createElement(TagPicker, {
|
|
1696
|
-
readonly: disabled,
|
|
1697
|
-
items,
|
|
1698
|
-
mode: tagPickerMode,
|
|
1699
|
-
onBlur: (event) => onBlur(event),
|
|
1700
|
-
onUpdate: handleUpdate,
|
|
1481
|
+
}, [
|
|
1482
|
+
createSchema
|
|
1483
|
+
]);
|
|
1484
|
+
if (showForm && createSchema) {
|
|
1485
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Content, {
|
|
1486
|
+
...props,
|
|
1701
1487
|
onSearch: handleSearch,
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1488
|
+
onKeyDownCapture: handleKeyDown,
|
|
1489
|
+
ref: forwardedRef
|
|
1490
|
+
}, /* @__PURE__ */ React10.createElement(Popover.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Root, {
|
|
1491
|
+
testId: "create-referenced-object-form",
|
|
1492
|
+
schema: createSchema,
|
|
1493
|
+
defaultValues: createInitialValuePath ? {
|
|
1494
|
+
[createInitialValuePath]: formInitialValue
|
|
1495
|
+
} : {},
|
|
1496
|
+
fieldMap: createFieldMap,
|
|
1497
|
+
onSave: handleFormSave,
|
|
1498
|
+
onCancel: handleFormCancel
|
|
1499
|
+
}, /* @__PURE__ */ React10.createElement(Form.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Content, null, /* @__PURE__ */ React10.createElement(Form.FieldSet, null), /* @__PURE__ */ React10.createElement(Form.Actions, null))))), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
|
|
1706
1500
|
}
|
|
1501
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Content, {
|
|
1502
|
+
...props,
|
|
1503
|
+
onSearch: handleSearch,
|
|
1504
|
+
onKeyDownCapture: handleKeyDown,
|
|
1505
|
+
ref: forwardedRef
|
|
1506
|
+
}, /* @__PURE__ */ React10.createElement(Combobox.Input, {
|
|
1507
|
+
placeholder: t("ref-field-combobox-input.placeholder"),
|
|
1508
|
+
autoFocus: true
|
|
1509
|
+
}), /* @__PURE__ */ React10.createElement(Combobox.List, null, results.map((option) => /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1510
|
+
key: option.id,
|
|
1511
|
+
value: option.id,
|
|
1512
|
+
label: option.label,
|
|
1513
|
+
checked: selectedIds?.includes(option.id),
|
|
1514
|
+
onSelect: () => onSelect(option.id),
|
|
1515
|
+
classNames: "flex items-center gap-2"
|
|
1516
|
+
})), createSchema && onCreate && /* @__PURE__ */ React10.createElement(CreateItem, {
|
|
1517
|
+
createOptionLabel,
|
|
1518
|
+
createOptionIcon: createOptionIcon ?? "ph--plus--regular",
|
|
1519
|
+
onCreateItemSelect: (query) => {
|
|
1520
|
+
setFormInitialValue(query);
|
|
1521
|
+
setShowForm(true);
|
|
1522
|
+
}
|
|
1523
|
+
})), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
|
|
1524
|
+
});
|
|
1525
|
+
var CreateItem = ({ createOptionLabel, createOptionIcon, onCreateItemSelect }) => {
|
|
1526
|
+
const { t } = useTranslation5(translationKey);
|
|
1527
|
+
const { query } = useSearchListInput();
|
|
1528
|
+
const label = createOptionLabel ? t(createOptionLabel[0], {
|
|
1529
|
+
ns: createOptionLabel[1].ns,
|
|
1530
|
+
text: query
|
|
1531
|
+
}) : t("create-option.label");
|
|
1532
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1533
|
+
value: "__create__",
|
|
1534
|
+
label,
|
|
1535
|
+
icon: createOptionIcon,
|
|
1536
|
+
classNames: "flex items-center gap-2",
|
|
1537
|
+
closeOnSelect: false,
|
|
1538
|
+
onSelect: () => {
|
|
1539
|
+
onCreateItemSelect(query);
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1707
1542
|
};
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1543
|
+
ObjectPickerContent.displayName = "ObjectPicker.Content";
|
|
1544
|
+
var ObjectPicker = {
|
|
1545
|
+
Root: Combobox.Root,
|
|
1546
|
+
Portal: Combobox.Portal,
|
|
1547
|
+
Trigger: Combobox.Trigger,
|
|
1548
|
+
VirtualTrigger: Combobox.VirtualTrigger,
|
|
1549
|
+
Content: ObjectPickerContent
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
// src/components/Form/fields/RefField.tsx
|
|
1553
|
+
var isRefSnapshot = (val) => {
|
|
1554
|
+
return typeof val === "object" && typeof val?.["/"] === "string";
|
|
1555
|
+
};
|
|
1556
|
+
var defaultGetOptions = (results, { parentLabel } = {}) => results.map((result) => {
|
|
1557
|
+
const id = Entity.getDXN(result).toString();
|
|
1558
|
+
const parent = parentLabel ? Obj.getParent(result) : void 0;
|
|
1559
|
+
const label = parent ? Entity.getLabel(parent) : Entity.getLabel(result);
|
|
1560
|
+
return {
|
|
1561
|
+
id,
|
|
1562
|
+
label: label ?? id
|
|
1563
|
+
};
|
|
1564
|
+
});
|
|
1565
|
+
var defaultResultsHook = (db, typename) => useQuery(db, typename ? typename === Type.getTypename(Obj.Unknown) ? Filter.everything() : Filter.typename(typename) : Filter.nothing());
|
|
1566
|
+
var RefField = (props) => {
|
|
1567
|
+
const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap, db, resultsHook: useResults = defaultResultsHook, schemaHook: useSchema = useSchema$, getOptions: getOptions2 = defaultGetOptions, onCreate, onValueChange } = props;
|
|
1568
|
+
const { t } = useTranslation6(translationKey);
|
|
1569
|
+
const { status, error } = getStatus();
|
|
1570
|
+
const typename = useMemo6(() => type ? findAnnotation2(type, ReferenceAnnotationId2)?.typename : void 0, [
|
|
1571
|
+
type
|
|
1572
|
+
]);
|
|
1573
|
+
const results = useResults(db, typename);
|
|
1574
|
+
const options = useMemo6(() => {
|
|
1575
|
+
const parentLabel = type ? findAnnotation2(type, ParentLabelAnnotationId) === true : false;
|
|
1576
|
+
return getOptions2(results, {
|
|
1577
|
+
parentLabel
|
|
1578
|
+
});
|
|
1579
|
+
}, [
|
|
1580
|
+
results,
|
|
1581
|
+
getOptions2,
|
|
1582
|
+
type
|
|
1583
|
+
]);
|
|
1584
|
+
const handleGetValue = useCallback9(() => {
|
|
1585
|
+
const formValue = getValue();
|
|
1586
|
+
const unknownToRefOption = (value3) => {
|
|
1587
|
+
const isRef = Ref2.isRef(value3);
|
|
1588
|
+
if (isRef || isRefSnapshot(value3)) {
|
|
1589
|
+
const dxnString = isRef ? value3.dxn.toString() : value3["/"];
|
|
1590
|
+
const matchingOption = options.find((option) => option.id === dxnString);
|
|
1591
|
+
if (matchingOption) {
|
|
1592
|
+
return matchingOption;
|
|
1593
|
+
}
|
|
1728
1594
|
}
|
|
1729
1595
|
return void 0;
|
|
1730
1596
|
};
|
|
1731
|
-
return
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1597
|
+
return unknownToRefOption(formValue);
|
|
1598
|
+
}, [
|
|
1599
|
+
options,
|
|
1600
|
+
getValue
|
|
1601
|
+
]);
|
|
1602
|
+
const handleUpdate = useCallback9((id) => {
|
|
1603
|
+
const item2 = options.find((option) => option.id === id);
|
|
1604
|
+
const ref = item2 ? Ref2.fromDXN(DXN.parse(item2.id)) : void 0;
|
|
1605
|
+
onValueChange(type, ref);
|
|
1606
|
+
}, [
|
|
1607
|
+
options,
|
|
1608
|
+
type,
|
|
1609
|
+
onValueChange
|
|
1610
|
+
]);
|
|
1611
|
+
const item = handleGetValue();
|
|
1612
|
+
const selectedIds = useMemo6(() => item ? [
|
|
1613
|
+
item.id
|
|
1614
|
+
] : [], [
|
|
1615
|
+
item
|
|
1616
|
+
]);
|
|
1617
|
+
const createSchema = useSchema(db, typename);
|
|
1618
|
+
const handleCreate = useCallback9((values) => {
|
|
1619
|
+
if (createSchema && onCreate) {
|
|
1620
|
+
onCreate(createSchema, values);
|
|
1621
|
+
}
|
|
1622
|
+
}, [
|
|
1623
|
+
createSchema,
|
|
1624
|
+
onCreate
|
|
1625
|
+
]);
|
|
1626
|
+
const handleSelect = useCallback9((id) => {
|
|
1627
|
+
if (item?.id === id) {
|
|
1628
|
+
handleUpdate(void 0);
|
|
1629
|
+
} else {
|
|
1630
|
+
handleUpdate(id);
|
|
1631
|
+
}
|
|
1632
|
+
}, [
|
|
1633
|
+
item,
|
|
1634
|
+
handleUpdate
|
|
1635
|
+
]);
|
|
1636
|
+
if (!typename || (readonly || layout === "static") && !item) {
|
|
1637
|
+
return null;
|
|
1743
1638
|
}
|
|
1639
|
+
return /* @__PURE__ */ React11.createElement(Input6.Root, {
|
|
1640
|
+
validationValence: status
|
|
1641
|
+
}, layout !== "inline" && /* @__PURE__ */ React11.createElement(FormFieldLabel, {
|
|
1642
|
+
error,
|
|
1643
|
+
readonly,
|
|
1644
|
+
label
|
|
1645
|
+
}), /* @__PURE__ */ React11.createElement("div", null, readonly ? !item ? /* @__PURE__ */ React11.createElement("p", {
|
|
1646
|
+
className: mx2("text-description", "mb-2")
|
|
1647
|
+
}, t("empty-readonly-ref-field.label")) : /* @__PURE__ */ React11.createElement(DxAnchor, {
|
|
1648
|
+
key: item.id,
|
|
1649
|
+
dxn: item.id,
|
|
1650
|
+
rootclassname: "me-1"
|
|
1651
|
+
}, item.label) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Trigger, {
|
|
1652
|
+
asChild: true,
|
|
1653
|
+
classNames: "p-0"
|
|
1654
|
+
}, item ? /* @__PURE__ */ React11.createElement("div", {
|
|
1655
|
+
className: "flex gap-form-gap w-full"
|
|
1656
|
+
}, /* @__PURE__ */ React11.createElement(Input6.Root, {
|
|
1657
|
+
key: item.id
|
|
1658
|
+
}, /* @__PURE__ */ React11.createElement(Input6.TextInput, {
|
|
1659
|
+
value: item.label,
|
|
1660
|
+
readOnly: true,
|
|
1661
|
+
classNames: "w-full"
|
|
1662
|
+
}))) : /* @__PURE__ */ React11.createElement(Button, {
|
|
1663
|
+
classNames: "w-full text-start gap-form-gap"
|
|
1664
|
+
}, /* @__PURE__ */ React11.createElement("div", {
|
|
1665
|
+
role: "none",
|
|
1666
|
+
className: "grow overflow-hidden"
|
|
1667
|
+
}, /* @__PURE__ */ React11.createElement("span", {
|
|
1668
|
+
className: "flex truncate text-description"
|
|
1669
|
+
}, placeholder ?? t("ref-field.placeholder"))), /* @__PURE__ */ React11.createElement(Icon2, {
|
|
1670
|
+
size: 3,
|
|
1671
|
+
icon: "ph--caret-down--bold"
|
|
1672
|
+
}))), /* @__PURE__ */ React11.createElement(ObjectPicker.Portal, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Content, {
|
|
1673
|
+
classNames: "dx-card-popover-width",
|
|
1674
|
+
options,
|
|
1675
|
+
selectedIds,
|
|
1676
|
+
createSchema: createSchema && omitId(createSchema),
|
|
1677
|
+
createOptionLabel,
|
|
1678
|
+
createOptionIcon,
|
|
1679
|
+
createInitialValuePath,
|
|
1680
|
+
createFieldMap,
|
|
1681
|
+
onCreate: handleCreate,
|
|
1682
|
+
onSelect: handleSelect
|
|
1683
|
+
})))), layout === "full" && /* @__PURE__ */ React11.createElement(Input6.DescriptionAndValidation, null, error));
|
|
1744
1684
|
};
|
|
1745
1685
|
|
|
1746
|
-
// src/components/Form/
|
|
1747
|
-
import {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
case "number":
|
|
1759
|
-
return NumberInput;
|
|
1760
|
-
case "boolean":
|
|
1761
|
-
return BooleanInput;
|
|
1686
|
+
// src/components/Form/fields/SelectField.tsx
|
|
1687
|
+
import React12, { useCallback as useCallback10 } from "react";
|
|
1688
|
+
import { Input as Input7, Select } from "@dxos/react-ui";
|
|
1689
|
+
var SelectField = ({ type, readonly, label, layout, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
1690
|
+
const { status, error } = getStatus();
|
|
1691
|
+
const value3 = getValue();
|
|
1692
|
+
const handleValueChange = useCallback10((value4) => onValueChange(type, value4), [
|
|
1693
|
+
type,
|
|
1694
|
+
onValueChange
|
|
1695
|
+
]);
|
|
1696
|
+
if ((readonly || layout === "static") && value3 == null) {
|
|
1697
|
+
return null;
|
|
1762
1698
|
}
|
|
1699
|
+
return /* @__PURE__ */ React12.createElement(Input7.Root, {
|
|
1700
|
+
validationValence: status
|
|
1701
|
+
}, layout !== "inline" && /* @__PURE__ */ React12.createElement(FormFieldLabel, {
|
|
1702
|
+
error,
|
|
1703
|
+
readonly,
|
|
1704
|
+
label
|
|
1705
|
+
}), layout === "static" ? /* @__PURE__ */ React12.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value3)?.label ?? String(value3)) : /* @__PURE__ */ React12.createElement(Select.Root, {
|
|
1706
|
+
value: value3,
|
|
1707
|
+
onValueChange: handleValueChange
|
|
1708
|
+
}, /* @__PURE__ */ React12.createElement(Select.TriggerButton, {
|
|
1709
|
+
classNames: "w-full",
|
|
1710
|
+
disabled: !!readonly,
|
|
1711
|
+
placeholder
|
|
1712
|
+
}), /* @__PURE__ */ React12.createElement(Select.Portal, null, /* @__PURE__ */ React12.createElement(Select.Content, null, /* @__PURE__ */ React12.createElement(Select.Viewport, null, options?.map(({ value: value4, label: label2 }) => (
|
|
1713
|
+
// NOTE: Numeric values are converted to and from strings.
|
|
1714
|
+
/* @__PURE__ */ React12.createElement(Select.Option, {
|
|
1715
|
+
key: String(value4),
|
|
1716
|
+
value: String(value4)
|
|
1717
|
+
}, label2 ?? String(value4))
|
|
1718
|
+
))), /* @__PURE__ */ React12.createElement(Select.Arrow, null)))), layout === "full" && /* @__PURE__ */ React12.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1763
1719
|
};
|
|
1764
1720
|
|
|
1765
|
-
// src/components/Form/
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
inputProps: {
|
|
1783
|
-
type,
|
|
1784
|
-
format,
|
|
1785
|
-
label,
|
|
1786
|
-
disabled: readonly,
|
|
1787
|
-
placeholder,
|
|
1788
|
-
...inputProps
|
|
1789
|
-
}
|
|
1790
|
-
});
|
|
1791
|
-
if (FoundComponent) {
|
|
1792
|
-
return FoundComponent;
|
|
1793
|
-
}
|
|
1794
|
-
const jsonPath = createJsonPath3(path ?? []);
|
|
1795
|
-
const CustomComponent = Custom?.[jsonPath];
|
|
1796
|
-
if (CustomComponent) {
|
|
1797
|
-
return /* @__PURE__ */ React12.createElement(CustomComponent, {
|
|
1798
|
-
type,
|
|
1799
|
-
format,
|
|
1800
|
-
label,
|
|
1801
|
-
inputOnly: inline,
|
|
1802
|
-
placeholder,
|
|
1803
|
-
disabled: readonly,
|
|
1804
|
-
...inputProps
|
|
1805
|
-
});
|
|
1806
|
-
}
|
|
1807
|
-
const refProps = getRefProps(property);
|
|
1808
|
-
if (refProps) {
|
|
1809
|
-
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1810
|
-
ast: refProps.ast,
|
|
1811
|
-
array: refProps.isArray,
|
|
1812
|
-
type,
|
|
1813
|
-
format,
|
|
1814
|
-
label,
|
|
1815
|
-
placeholder,
|
|
1816
|
-
disabled: readonly,
|
|
1817
|
-
inputOnly: inline,
|
|
1818
|
-
onQueryRefOptions,
|
|
1819
|
-
...inputProps
|
|
1820
|
-
});
|
|
1721
|
+
// src/components/Form/fields/SelectOptionField.tsx
|
|
1722
|
+
import React13, { useCallback as useCallback11, useEffect as useEffect6, useRef as useRef3, useState as useState4 } from "react";
|
|
1723
|
+
import { PublicKey } from "@dxos/keys";
|
|
1724
|
+
import { IconButton as IconButton3, Input as Input8, Tag, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1725
|
+
import { List } from "@dxos/react-ui-list";
|
|
1726
|
+
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
1727
|
+
import { hues, osTranslations, subtleHover } from "@dxos/ui-theme";
|
|
1728
|
+
var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueChange }) => {
|
|
1729
|
+
const { t } = useTranslation7(translationKey);
|
|
1730
|
+
const { status, error } = getStatus();
|
|
1731
|
+
const [selected, setSelectedId] = useState4(null);
|
|
1732
|
+
const [isNewOption, setIsNewOption] = useState4(false);
|
|
1733
|
+
const inputRef = useRef3(null);
|
|
1734
|
+
const options = getValue();
|
|
1735
|
+
useEffect6(() => {
|
|
1736
|
+
if (options === void 0) {
|
|
1737
|
+
onValueChange(type, []);
|
|
1821
1738
|
}
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1739
|
+
}, [
|
|
1740
|
+
options,
|
|
1741
|
+
type,
|
|
1742
|
+
onValueChange
|
|
1743
|
+
]);
|
|
1744
|
+
const randomHue = () => {
|
|
1745
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
1746
|
+
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
1747
|
+
if (unusedHues.length > 0) {
|
|
1748
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
1830
1749
|
}
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1750
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
1751
|
+
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
1752
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
|
|
1753
|
+
};
|
|
1754
|
+
const handleAdd = useCallback11(() => {
|
|
1755
|
+
const newId = PublicKey.random().truncate();
|
|
1756
|
+
const newOption = {
|
|
1757
|
+
id: newId,
|
|
1758
|
+
title: "",
|
|
1759
|
+
color: randomHue()
|
|
1760
|
+
};
|
|
1761
|
+
onValueChange(type, [
|
|
1762
|
+
...options ?? [],
|
|
1763
|
+
newOption
|
|
1764
|
+
]);
|
|
1765
|
+
setSelectedId(newId);
|
|
1766
|
+
setIsNewOption(true);
|
|
1767
|
+
}, [
|
|
1768
|
+
options,
|
|
1769
|
+
type,
|
|
1770
|
+
onValueChange
|
|
1771
|
+
]);
|
|
1772
|
+
const handleDelete = useCallback11((id) => {
|
|
1773
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
1774
|
+
onValueChange(type, newOptions);
|
|
1775
|
+
setSelectedId(null);
|
|
1776
|
+
}, [
|
|
1777
|
+
options,
|
|
1778
|
+
type,
|
|
1779
|
+
onValueChange
|
|
1780
|
+
]);
|
|
1781
|
+
const handleMove = useCallback11((from, to) => {
|
|
1782
|
+
if (!options) {
|
|
1783
|
+
return;
|
|
1842
1784
|
}
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1785
|
+
const newOptions = [
|
|
1786
|
+
...options
|
|
1787
|
+
];
|
|
1788
|
+
const [removed] = newOptions.splice(from, 1);
|
|
1789
|
+
newOptions.splice(to, 0, removed);
|
|
1790
|
+
onValueChange(type, newOptions);
|
|
1791
|
+
}, [
|
|
1792
|
+
options,
|
|
1793
|
+
type,
|
|
1794
|
+
onValueChange
|
|
1795
|
+
]);
|
|
1796
|
+
const handleClick = useCallback11((id) => {
|
|
1797
|
+
setSelectedId((current) => current === id ? null : id);
|
|
1798
|
+
}, []);
|
|
1799
|
+
const handleTitleChange = useCallback11((id) => (e) => {
|
|
1800
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
1801
|
+
...o,
|
|
1802
|
+
title: e.target.value
|
|
1803
|
+
} : o);
|
|
1804
|
+
onValueChange(type, newOptions ?? []);
|
|
1805
|
+
}, [
|
|
1806
|
+
options,
|
|
1807
|
+
type,
|
|
1808
|
+
onValueChange
|
|
1809
|
+
]);
|
|
1810
|
+
const handleKeyDown = useCallback11((ev) => {
|
|
1811
|
+
if (ev.key === "Enter") {
|
|
1812
|
+
setSelectedId(null);
|
|
1857
1813
|
}
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1814
|
+
}, []);
|
|
1815
|
+
const handleColorChange = useCallback11((id) => (hue) => {
|
|
1816
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
1817
|
+
...o,
|
|
1818
|
+
color: hue
|
|
1819
|
+
} : o);
|
|
1820
|
+
onValueChange(type, newOptions ?? []);
|
|
1821
|
+
}, [
|
|
1822
|
+
options,
|
|
1823
|
+
type,
|
|
1824
|
+
onValueChange
|
|
1825
|
+
]);
|
|
1826
|
+
useEffect6(() => {
|
|
1827
|
+
if (selected && isNewOption && inputRef.current) {
|
|
1828
|
+
inputRef.current.focus();
|
|
1829
|
+
setIsNewOption(false);
|
|
1873
1830
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1831
|
+
}, [
|
|
1832
|
+
selected,
|
|
1833
|
+
isNewOption
|
|
1834
|
+
]);
|
|
1835
|
+
return /* @__PURE__ */ React13.createElement(Input8.Root, {
|
|
1836
|
+
validationValence: status
|
|
1837
|
+
}, /* @__PURE__ */ React13.createElement(FormFieldLabel, {
|
|
1838
|
+
error,
|
|
1839
|
+
readonly,
|
|
1840
|
+
label
|
|
1841
|
+
}), /* @__PURE__ */ React13.createElement("div", {
|
|
1842
|
+
role: "none"
|
|
1843
|
+
}, options && /* @__PURE__ */ React13.createElement(List.Root, {
|
|
1844
|
+
items: options,
|
|
1845
|
+
isItem: (_item) => true,
|
|
1846
|
+
onMove: readonly ? void 0 : handleMove,
|
|
1847
|
+
readonly: !!readonly
|
|
1848
|
+
}, ({ items }) => /* @__PURE__ */ React13.createElement("div", {
|
|
1849
|
+
role: "list",
|
|
1850
|
+
className: "w-full overflow-auto"
|
|
1851
|
+
}, items?.map((item) => /* @__PURE__ */ React13.createElement("div", {
|
|
1852
|
+
key: item.id
|
|
1853
|
+
}, /* @__PURE__ */ React13.createElement(List.Item, {
|
|
1854
|
+
role: "button",
|
|
1855
|
+
item,
|
|
1856
|
+
classNames: [
|
|
1857
|
+
subtleHover,
|
|
1858
|
+
"flex flex-col cursor-pointer rounded-xs"
|
|
1859
|
+
],
|
|
1860
|
+
"aria-expanded": selected === item.id
|
|
1861
|
+
}, /* @__PURE__ */ React13.createElement("div", {
|
|
1862
|
+
className: "flex items-center"
|
|
1863
|
+
}, /* @__PURE__ */ React13.createElement(List.ItemDragHandle, {
|
|
1864
|
+
disabled: !!readonly
|
|
1865
|
+
}), /* @__PURE__ */ React13.createElement(List.ItemTitle, {
|
|
1866
|
+
onClick: () => handleClick(item.id),
|
|
1867
|
+
classNames: "flex-1"
|
|
1868
|
+
}, /* @__PURE__ */ React13.createElement(Tag, {
|
|
1869
|
+
palette: item.color
|
|
1870
|
+
}, item.title || "\u200B")), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1871
|
+
iconOnly: true,
|
|
1872
|
+
variant: "ghost",
|
|
1873
|
+
label: t(selected === item.id ? "collapse label" : "expand label", {
|
|
1874
|
+
ns: osTranslations
|
|
1875
|
+
}),
|
|
1876
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
1877
|
+
onClick: () => handleClick(item.id)
|
|
1878
|
+
})), selected === item.id && /* @__PURE__ */ React13.createElement("div", {
|
|
1879
|
+
className: "flex flex-col p-form-padding gap-form-gap dx-density-fine"
|
|
1880
|
+
}, /* @__PURE__ */ React13.createElement(Input8.Label, {
|
|
1881
|
+
classNames: "text-xs"
|
|
1882
|
+
}, t("select-option.label")), /* @__PURE__ */ React13.createElement("div", {
|
|
1883
|
+
className: "grid grid-cols-[1fr_min-content_min-content] gap-form-gap"
|
|
1884
|
+
}, /* @__PURE__ */ React13.createElement(Input8.TextInput, {
|
|
1885
|
+
disabled: !!readonly,
|
|
1886
|
+
placeholder: t("select-option-label.placeholder"),
|
|
1887
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
1888
|
+
value: item.title,
|
|
1889
|
+
onChange: handleTitleChange(item.id),
|
|
1890
|
+
onKeyDown: handleKeyDown,
|
|
1891
|
+
classNames: "flex-1"
|
|
1892
|
+
}), /* @__PURE__ */ React13.createElement(HuePicker, {
|
|
1893
|
+
disabled: !!readonly,
|
|
1894
|
+
value: item.color,
|
|
1895
|
+
onChange: handleColorChange(item.id)
|
|
1896
|
+
}), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1897
|
+
disabled: !!readonly,
|
|
1898
|
+
icon: "ph--trash--fill",
|
|
1899
|
+
iconOnly: true,
|
|
1900
|
+
label: t("select-option-delete.button"),
|
|
1901
|
+
onClick: () => handleDelete(item.id)
|
|
1902
|
+
})))))), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1903
|
+
variant: "ghost",
|
|
1904
|
+
icon: "ph--plus--regular",
|
|
1905
|
+
label: t("select-option-add.button"),
|
|
1906
|
+
onClick: handleAdd,
|
|
1907
|
+
disabled: !!readonly,
|
|
1908
|
+
classNames: "w-full"
|
|
1909
|
+
})))));
|
|
1878
1910
|
};
|
|
1879
|
-
var FormFields = /* @__PURE__ */ forwardRef(({ classNames, testId, schema, path, filter, sort, readonly, lookupComponent, Custom, onQueryRefOptions }, forwardRef2) => {
|
|
1880
|
-
var _effect = _useSignals12();
|
|
1881
|
-
try {
|
|
1882
|
-
const values = useFormValues(path);
|
|
1883
|
-
const properties = useMemo5(() => {
|
|
1884
|
-
const props = getSchemaProperties2(schema.ast, values);
|
|
1885
|
-
const filtered = filter ? filter(props) : props;
|
|
1886
|
-
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
1887
|
-
}, [
|
|
1888
|
-
schema,
|
|
1889
|
-
values,
|
|
1890
|
-
filter,
|
|
1891
|
-
sort
|
|
1892
|
-
]);
|
|
1893
|
-
return /* @__PURE__ */ React12.createElement("div", {
|
|
1894
|
-
role: "form",
|
|
1895
|
-
className: mx8("is-full", classNames),
|
|
1896
|
-
ref: forwardRef2
|
|
1897
|
-
}, properties.map((property) => {
|
|
1898
|
-
return /* @__PURE__ */ React12.createElement(FormField, {
|
|
1899
|
-
key: property.name,
|
|
1900
|
-
property,
|
|
1901
|
-
path: [
|
|
1902
|
-
...path ?? [],
|
|
1903
|
-
property.name
|
|
1904
|
-
],
|
|
1905
|
-
readonly,
|
|
1906
|
-
onQueryRefOptions,
|
|
1907
|
-
lookupComponent,
|
|
1908
|
-
Custom
|
|
1909
|
-
});
|
|
1910
|
-
}).filter(isNotFalsy));
|
|
1911
|
-
} finally {
|
|
1912
|
-
_effect.f();
|
|
1913
|
-
}
|
|
1914
|
-
});
|
|
1915
1911
|
|
|
1916
|
-
// src/components/Form/
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1912
|
+
// src/components/Form/fields/TextField.tsx
|
|
1913
|
+
import React14, { useCallback as useCallback12 } from "react";
|
|
1914
|
+
import { Input as Input9 } from "@dxos/react-ui";
|
|
1915
|
+
var TextField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1916
|
+
const handleChange = useCallback12((event) => onValueChange(type, event.target.value), [
|
|
1917
|
+
type,
|
|
1918
|
+
onValueChange
|
|
1919
|
+
]);
|
|
1920
|
+
return /* @__PURE__ */ React14.createElement(FormFieldWrapper, {
|
|
1921
|
+
readonly,
|
|
1922
|
+
...props
|
|
1923
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React14.createElement(Input9.TextInput, {
|
|
1924
|
+
noAutoFill: true,
|
|
1925
|
+
disabled: !!readonly,
|
|
1926
|
+
placeholder,
|
|
1927
|
+
value: value3,
|
|
1928
|
+
onChange: handleChange,
|
|
1929
|
+
onBlur
|
|
1930
|
+
}));
|
|
1931
|
+
};
|
|
1932
|
+
|
|
1933
|
+
// src/components/Form/fields/TextAreaField.tsx
|
|
1934
|
+
import React15, { useCallback as useCallback13 } from "react";
|
|
1935
|
+
import { Input as Input10 } from "@dxos/react-ui";
|
|
1936
|
+
var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1937
|
+
const handleChange = useCallback13((event) => onValueChange(type, event.target.value), [
|
|
1938
|
+
type,
|
|
1939
|
+
onValueChange
|
|
1940
|
+
]);
|
|
1941
|
+
return /* @__PURE__ */ React15.createElement(FormFieldWrapper, {
|
|
1942
|
+
readonly,
|
|
1943
|
+
...props
|
|
1944
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React15.createElement(Input10.TextArea, {
|
|
1945
|
+
rows: 3,
|
|
1946
|
+
disabled: !!readonly,
|
|
1947
|
+
placeholder,
|
|
1948
|
+
value: value3,
|
|
1949
|
+
onChange: handleChange,
|
|
1950
|
+
onBlur
|
|
1951
|
+
}));
|
|
1952
|
+
};
|
|
1953
|
+
|
|
1954
|
+
// src/components/Form/fields/TupleField.tsx
|
|
1955
|
+
import React16 from "react";
|
|
1956
|
+
import { Input as Input11 } from "@dxos/react-ui";
|
|
1957
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
1958
|
+
import { safeParseFloat as safeParseFloat3 } from "@dxos/util";
|
|
1959
|
+
var gridCols = [
|
|
1960
|
+
"grid-cols-1",
|
|
1961
|
+
"grid-cols-2",
|
|
1962
|
+
"grid-cols-3",
|
|
1963
|
+
"grid-cols-4"
|
|
1964
|
+
];
|
|
1965
|
+
var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1966
|
+
const { status, error } = getStatus();
|
|
1967
|
+
const values = getValue() ?? {};
|
|
1968
|
+
return /* @__PURE__ */ React16.createElement(Input11.Root, {
|
|
1969
|
+
validationValence: status
|
|
1970
|
+
}, /* @__PURE__ */ React16.createElement(FormFieldLabel, {
|
|
1971
|
+
error,
|
|
1972
|
+
readonly,
|
|
1973
|
+
label
|
|
1974
|
+
}), /* @__PURE__ */ React16.createElement("div", {
|
|
1975
|
+
className: mx3("grid gap-form-gap", gridCols[binding.length - 1])
|
|
1976
|
+
}, binding.map((prop) => /* @__PURE__ */ React16.createElement(Input11.TextInput, {
|
|
1977
|
+
key: prop,
|
|
1978
|
+
type: "number",
|
|
1979
|
+
disabled: !!readonly,
|
|
1980
|
+
value: values[prop],
|
|
1981
|
+
onChange: (event) => {
|
|
1982
|
+
onValueChange(type, {
|
|
1983
|
+
...values,
|
|
1984
|
+
[prop]: safeParseFloat3(event.target.value, 0)
|
|
1985
|
+
});
|
|
1986
|
+
},
|
|
1987
|
+
onBlur
|
|
1988
|
+
}))));
|
|
1966
1989
|
};
|
|
1967
1990
|
|
|
1968
1991
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
1969
|
-
var
|
|
1970
|
-
var FieldEditor = ({ projection, field, registry, onSave, onCancel
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1992
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1993
|
+
var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }) => {
|
|
1994
|
+
const { t } = useTranslation8(translationKey);
|
|
1995
|
+
const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
|
|
1996
|
+
useEffect7(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1997
|
+
field,
|
|
1998
|
+
projection
|
|
1999
|
+
]);
|
|
2000
|
+
const [schemas, setSchemas] = useState5([]);
|
|
2001
|
+
useAsyncEffect(async () => {
|
|
2002
|
+
if (!registry) {
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
2006
|
+
fire: true
|
|
2007
|
+
});
|
|
2008
|
+
const schemas2 = await registry.query().run();
|
|
2009
|
+
setSchemas(schemas2);
|
|
2010
|
+
return () => subscription?.();
|
|
2011
|
+
}, [
|
|
2012
|
+
registry
|
|
2013
|
+
]);
|
|
2014
|
+
const [referenceSchema, setReferenceSchema] = useState5();
|
|
2015
|
+
useEffect7(() => {
|
|
2016
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
2017
|
+
}, [
|
|
2018
|
+
schemas,
|
|
2019
|
+
props?.referenceSchema
|
|
2020
|
+
]);
|
|
2021
|
+
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
2022
|
+
fieldSchema: getFormatSchema(props?.format)
|
|
2023
|
+
});
|
|
2024
|
+
const fieldMap = useMemo7(() => ({
|
|
2025
|
+
["format"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
2026
|
+
...props2,
|
|
2027
|
+
options: FormatEnums.filter((value3) => value3 !== Format4.TypeFormat.None).map((value3) => ({
|
|
2028
|
+
value: value3,
|
|
2029
|
+
label: t(`format.${value3}.label`)
|
|
2030
|
+
}))
|
|
2031
|
+
}),
|
|
2032
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
2033
|
+
...props2,
|
|
2034
|
+
options: schemas.map((schema) => ({
|
|
2035
|
+
value: schema.typename
|
|
2036
|
+
}))
|
|
2037
|
+
}),
|
|
2038
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
2039
|
+
...props2,
|
|
2040
|
+
options: referenceSchema ? getFormProperties(referenceSchema.ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
|
|
2041
|
+
value: p.name.toString()
|
|
2042
|
+
})) : []
|
|
2043
|
+
}),
|
|
2044
|
+
["options"]: (props2) => /* @__PURE__ */ React17.createElement(SelectOptionField, props2)
|
|
2045
|
+
}), [
|
|
2046
|
+
t,
|
|
2047
|
+
schemas,
|
|
2048
|
+
referenceSchema
|
|
2049
|
+
]);
|
|
2050
|
+
const propIsNotType = useCallback14((props2) => props2.filter((prop) => prop.name !== "type"), []);
|
|
2051
|
+
const handleValuesChanged = useCallback14((_props) => {
|
|
2052
|
+
setFieldSchema((prev) => {
|
|
2053
|
+
const fieldSchema2 = getFormatSchema(_props.format);
|
|
2054
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
2055
|
+
return prev;
|
|
1983
2056
|
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
});
|
|
1987
|
-
const t2 = setTimeout(async () => {
|
|
1988
|
-
const schemas2 = await registry.query().run();
|
|
1989
|
-
setSchemas(schemas2);
|
|
1990
|
-
});
|
|
1991
|
-
return () => {
|
|
1992
|
-
clearTimeout(t2);
|
|
1993
|
-
subscription?.();
|
|
2057
|
+
return {
|
|
2058
|
+
fieldSchema: fieldSchema2
|
|
1994
2059
|
};
|
|
1995
|
-
}, [
|
|
1996
|
-
registry
|
|
1997
|
-
]);
|
|
1998
|
-
const [referenceSchema, setReferenceSchema] = useState5();
|
|
1999
|
-
useEffect8(() => {
|
|
2000
|
-
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
2001
|
-
}, [
|
|
2002
|
-
schemas,
|
|
2003
|
-
props?.referenceSchema
|
|
2004
|
-
]);
|
|
2005
|
-
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
2006
|
-
fieldSchema: getFormatSchema(props?.format)
|
|
2007
2060
|
});
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
const
|
|
2011
|
-
if (
|
|
2012
|
-
return
|
|
2061
|
+
setReferenceSchema((prev) => {
|
|
2062
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
2063
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
2064
|
+
if (newSchema) {
|
|
2065
|
+
return newSchema;
|
|
2013
2066
|
}
|
|
2067
|
+
}
|
|
2068
|
+
return prev;
|
|
2069
|
+
});
|
|
2070
|
+
setProps((props2) => {
|
|
2071
|
+
const type = formatToType[_props.format];
|
|
2072
|
+
const additionalProps = formatToAdditionalPropertyAttributes[_props.format];
|
|
2073
|
+
if (props2.type !== type) {
|
|
2014
2074
|
return {
|
|
2015
|
-
|
|
2075
|
+
...props2,
|
|
2076
|
+
..._props,
|
|
2077
|
+
...additionalProps,
|
|
2078
|
+
type
|
|
2016
2079
|
};
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
...props2,
|
|
2032
|
-
..._props,
|
|
2033
|
-
type
|
|
2034
|
-
};
|
|
2080
|
+
}
|
|
2081
|
+
return _props;
|
|
2082
|
+
});
|
|
2083
|
+
}, [
|
|
2084
|
+
schemas,
|
|
2085
|
+
props.format,
|
|
2086
|
+
props.referenceSchema
|
|
2087
|
+
]);
|
|
2088
|
+
const handleValidate = useCallback14(({ property }) => {
|
|
2089
|
+
if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
|
|
2090
|
+
return [
|
|
2091
|
+
{
|
|
2092
|
+
path: "property",
|
|
2093
|
+
message: `property is not unique: '${property}'`
|
|
2035
2094
|
}
|
|
2036
|
-
|
|
2095
|
+
];
|
|
2096
|
+
}
|
|
2097
|
+
}, [
|
|
2098
|
+
projection.getFields(),
|
|
2099
|
+
field
|
|
2100
|
+
]);
|
|
2101
|
+
const handleSave = useCallback14((props2) => {
|
|
2102
|
+
if (view) {
|
|
2103
|
+
Obj2.change(view, () => {
|
|
2104
|
+
projection.setFieldProjection({
|
|
2105
|
+
field,
|
|
2106
|
+
props: props2
|
|
2107
|
+
});
|
|
2037
2108
|
});
|
|
2038
|
-
}
|
|
2039
|
-
schemas,
|
|
2040
|
-
props.format,
|
|
2041
|
-
props.referenceSchema
|
|
2042
|
-
]);
|
|
2043
|
-
const handleValidate = useCallback9(({ property }) => {
|
|
2044
|
-
if (property && projection.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
2045
|
-
return [
|
|
2046
|
-
{
|
|
2047
|
-
path: "property",
|
|
2048
|
-
message: `property is not unique: '${property}'`
|
|
2049
|
-
}
|
|
2050
|
-
];
|
|
2051
|
-
}
|
|
2052
|
-
}, [
|
|
2053
|
-
projection.fields,
|
|
2054
|
-
field
|
|
2055
|
-
]);
|
|
2056
|
-
const handleSave = useCallback9((props2) => {
|
|
2109
|
+
} else {
|
|
2057
2110
|
projection.setFieldProjection({
|
|
2058
2111
|
field,
|
|
2059
2112
|
props: props2
|
|
2060
2113
|
});
|
|
2061
|
-
onSave();
|
|
2062
|
-
}, [
|
|
2063
|
-
projection,
|
|
2064
|
-
field,
|
|
2065
|
-
onSave
|
|
2066
|
-
]);
|
|
2067
|
-
const handleCancel = useCallback9(() => {
|
|
2068
|
-
requestAnimationFrame(() => onCancel?.());
|
|
2069
|
-
onSave();
|
|
2070
|
-
}, [
|
|
2071
|
-
onSave
|
|
2072
|
-
]);
|
|
2073
|
-
const custom = useMemo7(() => ({
|
|
2074
|
-
["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2075
|
-
...props2,
|
|
2076
|
-
options: FormatEnums.filter((value) => value !== FormatEnum5.None).map((value) => ({
|
|
2077
|
-
value,
|
|
2078
|
-
label: t(`format ${value}`)
|
|
2079
|
-
}))
|
|
2080
|
-
}),
|
|
2081
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2082
|
-
...props2,
|
|
2083
|
-
options: schemas.map((schema) => ({
|
|
2084
|
-
value: schema.typename
|
|
2085
|
-
}))
|
|
2086
|
-
}),
|
|
2087
|
-
["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2088
|
-
...props2,
|
|
2089
|
-
options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
|
|
2090
|
-
value: p.name
|
|
2091
|
-
})) : []
|
|
2092
|
-
}),
|
|
2093
|
-
["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
|
|
2094
|
-
}), [
|
|
2095
|
-
t,
|
|
2096
|
-
schemas,
|
|
2097
|
-
referenceSchema
|
|
2098
|
-
]);
|
|
2099
|
-
const propIsNotType = useCallback9((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
2100
|
-
if (!fieldSchema) {
|
|
2101
|
-
log3.warn("invalid format", {
|
|
2102
|
-
props
|
|
2103
|
-
}, {
|
|
2104
|
-
F: __dxlog_file4,
|
|
2105
|
-
L: 173,
|
|
2106
|
-
S: void 0,
|
|
2107
|
-
C: (f, a) => f(...a)
|
|
2108
|
-
});
|
|
2109
|
-
return null;
|
|
2110
2114
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2115
|
+
onSave();
|
|
2116
|
+
}, [
|
|
2117
|
+
projection,
|
|
2118
|
+
field,
|
|
2119
|
+
view,
|
|
2120
|
+
onSave
|
|
2121
|
+
]);
|
|
2122
|
+
const handleCancel = useCallback14(() => {
|
|
2123
|
+
onSave();
|
|
2124
|
+
requestAnimationFrame(() => onCancel?.());
|
|
2125
|
+
}, [
|
|
2126
|
+
onSave
|
|
2127
|
+
]);
|
|
2128
|
+
if (!fieldSchema) {
|
|
2129
|
+
log2.warn("invalid format", {
|
|
2130
|
+
props
|
|
2131
|
+
}, {
|
|
2132
|
+
F: __dxlog_file2,
|
|
2133
|
+
L: 172,
|
|
2134
|
+
S: void 0,
|
|
2135
|
+
C: (f, a) => f(...a)
|
|
2127
2136
|
});
|
|
2128
|
-
|
|
2129
|
-
_effect.f();
|
|
2137
|
+
return null;
|
|
2130
2138
|
}
|
|
2139
|
+
return /* @__PURE__ */ React17.createElement(Form.Root, {
|
|
2140
|
+
key: field.id,
|
|
2141
|
+
fieldMap,
|
|
2142
|
+
autoFocus: true,
|
|
2143
|
+
readonly,
|
|
2144
|
+
schema: fieldSchema,
|
|
2145
|
+
values: props,
|
|
2146
|
+
exclude: propIsNotType,
|
|
2147
|
+
sort: [
|
|
2148
|
+
"property",
|
|
2149
|
+
"format"
|
|
2150
|
+
],
|
|
2151
|
+
onValuesChanged: handleValuesChanged,
|
|
2152
|
+
onValidate: handleValidate,
|
|
2153
|
+
onSave: handleSave,
|
|
2154
|
+
onCancel: handleCancel
|
|
2155
|
+
}, /* @__PURE__ */ React17.createElement(Form.Content, null, /* @__PURE__ */ React17.createElement(Form.FieldSet, null), /* @__PURE__ */ React17.createElement(Form.Actions, null)));
|
|
2156
|
+
};
|
|
2157
|
+
|
|
2158
|
+
// src/components/Settings/Settings.tsx
|
|
2159
|
+
import React18 from "react";
|
|
2160
|
+
import { Input as Input12, ScrollArea as ScrollArea2, toLocalizedString, useTranslation as useTranslation9 } from "@dxos/react-ui";
|
|
2161
|
+
import { composable as composable2, composableProps as composableProps2, mx as mx4 } from "@dxos/ui-theme";
|
|
2162
|
+
var SETTINGS_ROOT_NAME = "Settings.Root";
|
|
2163
|
+
var SETTINGS_VIEWPORT_NAME = "Settings.Viewport";
|
|
2164
|
+
var SETTINGS_SECTION_NAME = "Settings.Section";
|
|
2165
|
+
var SETTINGS_PANEL_NAME = "Settings.Panel";
|
|
2166
|
+
var SETTINGS_ITEM_NAME = "Settings.Item";
|
|
2167
|
+
var SettingsRoot = ({ children, classNames }) => {
|
|
2168
|
+
return /* @__PURE__ */ React18.createElement("div", {
|
|
2169
|
+
className: mx4("flex flex-col gap-2", classNames)
|
|
2170
|
+
}, children);
|
|
2171
|
+
};
|
|
2172
|
+
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
2173
|
+
var SettingsViewport = composable2(({ children, ...props }, forwardedRef) => {
|
|
2174
|
+
return /* @__PURE__ */ React18.createElement(ScrollArea2.Root, {
|
|
2175
|
+
...composableProps2(props),
|
|
2176
|
+
orientation: "vertical",
|
|
2177
|
+
centered: true,
|
|
2178
|
+
thin: true,
|
|
2179
|
+
ref: forwardedRef
|
|
2180
|
+
}, /* @__PURE__ */ React18.createElement(ScrollArea2.Viewport, {
|
|
2181
|
+
classNames: "px-4 pointer-coarse:px-2"
|
|
2182
|
+
}, /* @__PURE__ */ React18.createElement("div", {
|
|
2183
|
+
role: "none",
|
|
2184
|
+
className: "dx-document flex flex-col gap-2 py-4"
|
|
2185
|
+
}, children)));
|
|
2186
|
+
});
|
|
2187
|
+
SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
|
|
2188
|
+
var SettingsSection = ({ title, description, children }) => {
|
|
2189
|
+
const { t } = useTranslation9(translationKey);
|
|
2190
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("h2", {
|
|
2191
|
+
className: "px-trim-md mt-trim-md text-xl"
|
|
2192
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React18.createElement("p", {
|
|
2193
|
+
className: "px-trim-md text-description"
|
|
2194
|
+
}, toLocalizedString(description, t)), /* @__PURE__ */ React18.createElement("div", {
|
|
2195
|
+
className: "w-full pt-trim-md space-y-trim-md"
|
|
2196
|
+
}, children));
|
|
2197
|
+
};
|
|
2198
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
2199
|
+
var SettingsPanel = ({ classNames, children }) => {
|
|
2200
|
+
return /* @__PURE__ */ React18.createElement("div", {
|
|
2201
|
+
role: "none",
|
|
2202
|
+
className: mx4("flex flex-col gap-3 p-trim-md border border-separator rounded-sm", classNames)
|
|
2203
|
+
}, children);
|
|
2204
|
+
};
|
|
2205
|
+
SettingsPanel.displayName = SETTINGS_PANEL_NAME;
|
|
2206
|
+
var SettingsItem = ({ title, description = "", children }) => {
|
|
2207
|
+
const { t } = useTranslation9(translationKey);
|
|
2208
|
+
return /* @__PURE__ */ React18.createElement(Input12.Root, null, /* @__PURE__ */ React18.createElement(SettingsPanel, {
|
|
2209
|
+
classNames: "grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0"
|
|
2210
|
+
}, /* @__PURE__ */ React18.createElement(Input12.Label, {
|
|
2211
|
+
classNames: "pb-trim-md text-base-surface-text text-lg md:col-span-2"
|
|
2212
|
+
}, toLocalizedString(title, t)), /* @__PURE__ */ React18.createElement(Input12.DescriptionAndValidation, null, /* @__PURE__ */ React18.createElement(Input12.Description, {
|
|
2213
|
+
classNames: "text-base text-description"
|
|
2214
|
+
}, toLocalizedString(description, t))), /* @__PURE__ */ React18.createElement("div", {
|
|
2215
|
+
role: "none",
|
|
2216
|
+
className: "text-end py-1"
|
|
2217
|
+
}, children)));
|
|
2218
|
+
};
|
|
2219
|
+
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
2220
|
+
var Settings = {
|
|
2221
|
+
Root: SettingsRoot,
|
|
2222
|
+
Viewport: SettingsViewport,
|
|
2223
|
+
Section: SettingsSection,
|
|
2224
|
+
Panel: SettingsPanel,
|
|
2225
|
+
Item: SettingsItem
|
|
2131
2226
|
};
|
|
2132
2227
|
|
|
2133
2228
|
// src/components/ViewEditor/ViewEditor.tsx
|
|
2134
|
-
import {
|
|
2135
|
-
import
|
|
2136
|
-
import
|
|
2137
|
-
import
|
|
2138
|
-
import
|
|
2139
|
-
import {
|
|
2229
|
+
import { RegistryContext } from "@effect-atom/atom-react";
|
|
2230
|
+
import * as Array2 from "effect/Array";
|
|
2231
|
+
import * as Match2 from "effect/Match";
|
|
2232
|
+
import * as Option4 from "effect/Option";
|
|
2233
|
+
import * as Schema3 from "effect/Schema";
|
|
2234
|
+
import React19, { forwardRef as forwardRef2, useCallback as useCallback15, useContext, useImperativeHandle, useMemo as useMemo8, useState as useState6 } from "react";
|
|
2235
|
+
import { Entity as Entity2, Feed, Filter as Filter2, Format as Format5, Obj as Obj3, Query, QueryAST, Ref as Ref3 } from "@dxos/echo";
|
|
2236
|
+
import { View } from "@dxos/echo";
|
|
2237
|
+
import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
|
|
2238
|
+
import { invariant } from "@dxos/invariant";
|
|
2239
|
+
import { useObject, useQuery as useQuery2 } from "@dxos/react-client/echo";
|
|
2240
|
+
import { IconButton as IconButton4, Input as Input13, Message, useTranslation as useTranslation10 } from "@dxos/react-ui";
|
|
2241
|
+
import { QueryForm } from "@dxos/react-ui-components";
|
|
2140
2242
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
2141
|
-
import {
|
|
2142
|
-
import {
|
|
2143
|
-
|
|
2144
|
-
var
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
if (
|
|
2229
|
-
|
|
2243
|
+
import { ParentLabelAnnotation, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
|
|
2244
|
+
import { mx as mx5, osTranslations as osTranslations2, subtleHover as subtleHover2 } from "@dxos/ui-theme";
|
|
2245
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2246
|
+
var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode = "schema", registry, db, readonly, showHeading = false, types, tags, onQueryChanged, onDelete }, forwardedRef) => {
|
|
2247
|
+
const atomRegistry = useContext(RegistryContext);
|
|
2248
|
+
const schemaReadonly = !isMutable(schema);
|
|
2249
|
+
const { t } = useTranslation10(translationKey);
|
|
2250
|
+
const projectionModel = useMemo8(() => {
|
|
2251
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2252
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2253
|
+
const model = new ProjectionModel({
|
|
2254
|
+
registry: atomRegistry,
|
|
2255
|
+
view,
|
|
2256
|
+
baseSchema: jsonSchema,
|
|
2257
|
+
change
|
|
2258
|
+
});
|
|
2259
|
+
return model;
|
|
2260
|
+
}, [
|
|
2261
|
+
atomRegistry,
|
|
2262
|
+
schema,
|
|
2263
|
+
view
|
|
2264
|
+
]);
|
|
2265
|
+
useImperativeHandle(forwardedRef, () => projectionModel, [
|
|
2266
|
+
projectionModel
|
|
2267
|
+
]);
|
|
2268
|
+
const queueTarget = Match2.value(view.query.ast).pipe(Match2.when({
|
|
2269
|
+
type: "from"
|
|
2270
|
+
}, ({ from }) => {
|
|
2271
|
+
if (from._tag !== "scope") {
|
|
2272
|
+
return void 0;
|
|
2273
|
+
}
|
|
2274
|
+
return Option4.fromNullable(from.scope.queues).pipe(Option4.flatMap((queues) => Array2.head(queues)), Option4.map(String), Option4.getOrUndefined);
|
|
2275
|
+
}), Match2.orElse(() => void 0));
|
|
2276
|
+
const feeds = useQuery2(db, Filter2.type(Feed.Feed));
|
|
2277
|
+
const targetRef = useMemo8(() => {
|
|
2278
|
+
if (!queueTarget) {
|
|
2279
|
+
return void 0;
|
|
2280
|
+
}
|
|
2281
|
+
const feed = feeds.find((feed2) => Feed.getQueueDxn(feed2)?.toString() === queueTarget);
|
|
2282
|
+
return feed ? Ref3.fromDXN(Entity2.getDXN(feed)) : void 0;
|
|
2283
|
+
}, [
|
|
2284
|
+
queueTarget,
|
|
2285
|
+
feeds
|
|
2286
|
+
]);
|
|
2287
|
+
const viewSchema = useMemo8(() => {
|
|
2288
|
+
const base = Schema3.Struct({
|
|
2289
|
+
query: mode === "schema" ? Format5.URL.annotations({
|
|
2290
|
+
title: "Record type"
|
|
2291
|
+
}) : QueryAST.Query.annotations({
|
|
2292
|
+
title: "Query"
|
|
2293
|
+
})
|
|
2294
|
+
});
|
|
2295
|
+
if (mode === "tag") {
|
|
2296
|
+
return Schema3.Struct({
|
|
2297
|
+
...base.fields,
|
|
2298
|
+
// TODO(wittjosiah): Replace Type.Feed with Dataset.Dataset when Ref.Ref supports unions.
|
|
2299
|
+
target: Ref3.Ref(Feed.Feed).pipe(Schema3.annotations({
|
|
2300
|
+
title: "Target Feed"
|
|
2301
|
+
}), ParentLabelAnnotation.set(true), Schema3.optional)
|
|
2302
|
+
}).pipe(Schema3.mutable);
|
|
2303
|
+
}
|
|
2304
|
+
return base.pipe(Schema3.mutable);
|
|
2305
|
+
}, [
|
|
2306
|
+
mode
|
|
2307
|
+
]);
|
|
2308
|
+
const viewValues = useMemo8(() => ({
|
|
2309
|
+
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2310
|
+
target: targetRef
|
|
2311
|
+
}), [
|
|
2312
|
+
mode,
|
|
2313
|
+
view.query.ast,
|
|
2314
|
+
targetRef
|
|
2315
|
+
]);
|
|
2316
|
+
const fieldMap = useMemo8(() => mode === "tag" ? customFields({
|
|
2317
|
+
types,
|
|
2318
|
+
tags
|
|
2319
|
+
}) : void 0, [
|
|
2320
|
+
mode,
|
|
2321
|
+
types,
|
|
2322
|
+
tags
|
|
2323
|
+
]);
|
|
2324
|
+
const handleUpdate = useCallback15((values) => {
|
|
2325
|
+
const targetValue = values.target;
|
|
2326
|
+
let queueDxn;
|
|
2327
|
+
if (Ref3.isRef(targetValue)) {
|
|
2328
|
+
const feedDxn = targetValue.dxn.toString();
|
|
2329
|
+
const feed = feeds.find((feed2) => Obj3.getDXN(feed2).toString() === feedDxn);
|
|
2330
|
+
if (feed) {
|
|
2331
|
+
queueDxn = Feed.getQueueDxn(feed)?.toString();
|
|
2230
2332
|
}
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2333
|
+
}
|
|
2334
|
+
const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : JSON.parse(JSON.stringify(values.query));
|
|
2335
|
+
onQueryChanged?.(query, queueDxn);
|
|
2336
|
+
}, [
|
|
2337
|
+
onQueryChanged,
|
|
2338
|
+
mode,
|
|
2339
|
+
feeds
|
|
2340
|
+
]);
|
|
2341
|
+
const handleDelete = useCallback15((fieldId) => {
|
|
2342
|
+
invariant(!readonly, void 0, {
|
|
2343
|
+
F: __dxlog_file3,
|
|
2344
|
+
L: 185,
|
|
2345
|
+
S: void 0,
|
|
2346
|
+
A: [
|
|
2347
|
+
"!readonly",
|
|
2348
|
+
""
|
|
2349
|
+
]
|
|
2350
|
+
});
|
|
2351
|
+
onDelete?.(fieldId);
|
|
2352
|
+
}, [
|
|
2353
|
+
onDelete,
|
|
2354
|
+
readonly
|
|
2355
|
+
]);
|
|
2356
|
+
return /* @__PURE__ */ React19.createElement("div", {
|
|
2357
|
+
role: "none",
|
|
2358
|
+
className: mx5(classNames)
|
|
2359
|
+
}, schemaReadonly && !readonly && /* @__PURE__ */ React19.createElement(Message.Root, {
|
|
2360
|
+
valence: "info",
|
|
2361
|
+
classNames: "my-form-padding"
|
|
2362
|
+
}, /* @__PURE__ */ React19.createElement(Message.Title, null, t("system-schema.description"))), /* @__PURE__ */ React19.createElement(Form.Root, {
|
|
2363
|
+
schema: viewSchema,
|
|
2364
|
+
values: viewValues,
|
|
2365
|
+
fieldMap,
|
|
2366
|
+
db,
|
|
2367
|
+
onValuesChanged: handleUpdate
|
|
2368
|
+
}, /* @__PURE__ */ React19.createElement(Form.FieldSet, null), /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
2369
|
+
label: t("fields.label"),
|
|
2370
|
+
asChild: true
|
|
2371
|
+
}), /* @__PURE__ */ React19.createElement(FieldList, {
|
|
2372
|
+
schema,
|
|
2373
|
+
view,
|
|
2374
|
+
registry,
|
|
2375
|
+
readonly,
|
|
2376
|
+
showHeading,
|
|
2377
|
+
onDelete: handleDelete
|
|
2378
|
+
})));
|
|
2379
|
+
});
|
|
2380
|
+
var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
2381
|
+
const atomRegistry = useContext(RegistryContext);
|
|
2382
|
+
const schemaReadonly = !isMutable(schema);
|
|
2383
|
+
const { t } = useTranslation10(translationKey);
|
|
2384
|
+
const [viewSnapshot] = useObject(view);
|
|
2385
|
+
const projectionModel = useMemo8(() => {
|
|
2386
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2387
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2388
|
+
const model = new ProjectionModel({
|
|
2389
|
+
registry: atomRegistry,
|
|
2390
|
+
view,
|
|
2391
|
+
baseSchema: jsonSchema,
|
|
2392
|
+
change
|
|
2393
|
+
});
|
|
2394
|
+
return model;
|
|
2395
|
+
}, [
|
|
2396
|
+
atomRegistry,
|
|
2397
|
+
schema,
|
|
2398
|
+
view
|
|
2399
|
+
]);
|
|
2400
|
+
const [expandedField, setExpandedField] = useState6();
|
|
2401
|
+
const handleAdd = useCallback15(() => {
|
|
2402
|
+
invariant(!readonly, void 0, {
|
|
2403
|
+
F: __dxlog_file3,
|
|
2404
|
+
L: 250,
|
|
2405
|
+
S: void 0,
|
|
2406
|
+
A: [
|
|
2407
|
+
"!readonly",
|
|
2408
|
+
""
|
|
2409
|
+
]
|
|
2410
|
+
});
|
|
2411
|
+
const field = projectionModel.createFieldProjection();
|
|
2412
|
+
setExpandedField(field.id);
|
|
2413
|
+
}, [
|
|
2414
|
+
projectionModel,
|
|
2415
|
+
readonly
|
|
2416
|
+
]);
|
|
2417
|
+
const handleToggleField = useCallback15((field) => {
|
|
2418
|
+
setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
|
|
2419
|
+
}, [
|
|
2420
|
+
readonly
|
|
2421
|
+
]);
|
|
2422
|
+
const handleDelete = useCallback15((fieldId) => {
|
|
2423
|
+
invariant(!readonly, void 0, {
|
|
2424
|
+
F: __dxlog_file3,
|
|
2425
|
+
L: 264,
|
|
2426
|
+
S: void 0,
|
|
2427
|
+
A: [
|
|
2428
|
+
"!readonly",
|
|
2429
|
+
""
|
|
2430
|
+
]
|
|
2431
|
+
});
|
|
2432
|
+
if (fieldId === expandedField) {
|
|
2433
|
+
setExpandedField(void 0);
|
|
2434
|
+
}
|
|
2435
|
+
onDelete?.(fieldId);
|
|
2436
|
+
}, [
|
|
2437
|
+
expandedField,
|
|
2438
|
+
onDelete,
|
|
2439
|
+
readonly
|
|
2440
|
+
]);
|
|
2441
|
+
const handleMove = useCallback15((fromIndex, toIndex) => {
|
|
2442
|
+
invariant(!readonly, void 0, {
|
|
2443
|
+
F: __dxlog_file3,
|
|
2444
|
+
L: 276,
|
|
2445
|
+
S: void 0,
|
|
2446
|
+
A: [
|
|
2447
|
+
"!readonly",
|
|
2448
|
+
""
|
|
2449
|
+
]
|
|
2450
|
+
});
|
|
2451
|
+
Obj3.change(view, (obj) => {
|
|
2247
2452
|
const fields = [
|
|
2248
|
-
...
|
|
2453
|
+
...obj.projection.fields
|
|
2249
2454
|
];
|
|
2250
2455
|
const [moved] = fields.splice(fromIndex, 1);
|
|
2251
2456
|
fields.splice(toIndex, 0, moved);
|
|
2252
|
-
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2457
|
+
obj.projection.fields = fields;
|
|
2458
|
+
});
|
|
2459
|
+
}, [
|
|
2460
|
+
view,
|
|
2461
|
+
readonly
|
|
2462
|
+
]);
|
|
2463
|
+
const handleClose = useCallback15(() => setExpandedField(void 0), []);
|
|
2464
|
+
const handleHide = useCallback15((fieldId) => {
|
|
2465
|
+
setExpandedField(void 0);
|
|
2466
|
+
projectionModel.hideFieldProjection(fieldId);
|
|
2467
|
+
}, [
|
|
2468
|
+
projectionModel
|
|
2469
|
+
]);
|
|
2470
|
+
const handleShow = useCallback15((property) => {
|
|
2471
|
+
setExpandedField(void 0);
|
|
2472
|
+
projectionModel.showFieldProjection(property);
|
|
2473
|
+
}, [
|
|
2474
|
+
projectionModel
|
|
2475
|
+
]);
|
|
2476
|
+
if (!viewSnapshot) {
|
|
2477
|
+
return null;
|
|
2478
|
+
}
|
|
2479
|
+
return /* @__PURE__ */ React19.createElement(List2.Root, {
|
|
2480
|
+
items: viewSnapshot.projection.fields,
|
|
2481
|
+
isItem: Schema3.is(View.FieldSchema),
|
|
2482
|
+
getId: (field) => field.id,
|
|
2483
|
+
onMove: readonly ? void 0 : handleMove,
|
|
2484
|
+
readonly
|
|
2485
|
+
}, ({ items: fields }) => /* @__PURE__ */ React19.createElement(React19.Fragment, null, showHeading && /* @__PURE__ */ React19.createElement("h3", {
|
|
2486
|
+
className: "text-sm"
|
|
2487
|
+
}, t("field-path.label")), /* @__PURE__ */ React19.createElement("div", {
|
|
2488
|
+
role: "list",
|
|
2489
|
+
className: "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]"
|
|
2490
|
+
}, fields?.map((field) => {
|
|
2491
|
+
const hidden = field.visible === false;
|
|
2492
|
+
return /* @__PURE__ */ React19.createElement(List2.Item, {
|
|
2493
|
+
key: field.id,
|
|
2494
|
+
item: field,
|
|
2495
|
+
classNames: "grid grid-cols-subgrid col-span-5",
|
|
2496
|
+
"aria-expanded": expandedField === field.id
|
|
2497
|
+
}, /* @__PURE__ */ React19.createElement("div", {
|
|
2275
2498
|
role: "none",
|
|
2276
|
-
className:
|
|
2277
|
-
}, /* @__PURE__ */
|
|
2278
|
-
|
|
2279
|
-
}, /* @__PURE__ */
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2499
|
+
className: mx5(subtleHover2, "grid grid-cols-subgrid col-span-5", "rounded-xs cursor-pointer min-h-10")
|
|
2500
|
+
}, /* @__PURE__ */ React19.createElement(List2.ItemDragHandle, {
|
|
2501
|
+
disabled: readonly || schemaReadonly
|
|
2502
|
+
}), /* @__PURE__ */ React19.createElement(List2.ItemTitle, {
|
|
2503
|
+
classNames: hidden && "text-subdued",
|
|
2504
|
+
onClick: () => handleToggleField(field)
|
|
2505
|
+
}, field.path), /* @__PURE__ */ React19.createElement(List2.ItemIconButton, {
|
|
2506
|
+
label: t(hidden ? "show field label" : "hide field label"),
|
|
2507
|
+
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2508
|
+
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2509
|
+
autoHide: false,
|
|
2510
|
+
disabled: readonly || !hidden && projectionModel.getFields().length <= 1,
|
|
2511
|
+
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2512
|
+
}), !readonly && /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(List2.ItemDeleteButton, {
|
|
2513
|
+
label: t("delete-field.label"),
|
|
2514
|
+
autoHide: false,
|
|
2515
|
+
disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
|
|
2516
|
+
onClick: () => handleDelete(field.id),
|
|
2517
|
+
"data-testid": "field.delete"
|
|
2518
|
+
}), /* @__PURE__ */ React19.createElement(List2.ItemIconButton, {
|
|
2519
|
+
iconOnly: true,
|
|
2520
|
+
variant: "ghost",
|
|
2521
|
+
label: t("toggle-expand.label", {
|
|
2522
|
+
ns: osTranslations2
|
|
2523
|
+
}),
|
|
2524
|
+
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2525
|
+
onClick: () => handleToggleField(field),
|
|
2526
|
+
"data-testid": "field.toggle"
|
|
2527
|
+
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React19.createElement("div", {
|
|
2287
2528
|
role: "none",
|
|
2288
|
-
className:
|
|
2289
|
-
}, /* @__PURE__ */
|
|
2290
|
-
|
|
2291
|
-
}, t("fields label")), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
2292
|
-
items: view.projection.fields,
|
|
2293
|
-
isItem: Schema2.is(FieldSchema),
|
|
2294
|
-
getId: (field2) => field2.id,
|
|
2295
|
-
readonly,
|
|
2296
|
-
onMove: readonly ? void 0 : handleMove
|
|
2297
|
-
}, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
|
|
2298
|
-
role: "heading",
|
|
2299
|
-
className: grid
|
|
2300
|
-
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
|
|
2301
|
-
className: "flex items-center text-sm"
|
|
2302
|
-
}, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
|
|
2303
|
-
role: "list",
|
|
2304
|
-
className: "flex flex-col is-full"
|
|
2305
|
-
}, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
2306
|
-
key: field2.id,
|
|
2307
|
-
item: field2,
|
|
2308
|
-
classNames: mx9(grid, ghostHover, "overflow-hidden", !readonly && "cursor-pointer")
|
|
2309
|
-
}, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
|
|
2310
|
-
onClick: () => handleSelect(field2)
|
|
2311
|
-
}, field2.path), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
2312
|
-
"data-testid": "hide-field-button",
|
|
2313
|
-
icon: "ph--eye-slash--regular",
|
|
2314
|
-
// TDOO(burdon): Is this the correct test?
|
|
2315
|
-
disabled: view.projection.fields.length <= 1,
|
|
2316
|
-
onClick: () => handleHide(field2.id)
|
|
2317
|
-
}), !readonly && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
2318
|
-
disabled: view.projection.fields.length <= 1,
|
|
2319
|
-
onClick: () => handleDelete(field2.id)
|
|
2320
|
-
})))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement(React15.Fragment, null, /* @__PURE__ */ React15.createElement("label", {
|
|
2321
|
-
className: mx9(inputTextLabel)
|
|
2322
|
-
}, t("hidden fields label")), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
2323
|
-
items: hiddenProperties,
|
|
2324
|
-
isItem: (item) => typeof item === "string",
|
|
2325
|
-
getId: (property) => property
|
|
2326
|
-
}, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
|
|
2327
|
-
role: "list",
|
|
2328
|
-
className: "flex flex-col is-full"
|
|
2329
|
-
}, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
2330
|
-
key: property,
|
|
2331
|
-
item: property,
|
|
2332
|
-
classNames: mx9(grid, ghostHover, !readonly && "cursor-pointer")
|
|
2333
|
-
}, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, {
|
|
2334
|
-
disabled: true
|
|
2335
|
-
}), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
2336
|
-
icon: "ph--eye--regular",
|
|
2337
|
-
onClick: () => handleShow(property),
|
|
2338
|
-
"data-testid": "show-field-button"
|
|
2339
|
-
}))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
|
|
2340
|
-
key: field.id,
|
|
2341
|
-
projection,
|
|
2342
|
-
field,
|
|
2529
|
+
className: "col-span-5 mt-1 mb-1 border border-separator rounded-md"
|
|
2530
|
+
}, /* @__PURE__ */ React19.createElement(FieldEditor, {
|
|
2531
|
+
readonly: readonly || schemaReadonly,
|
|
2343
2532
|
registry,
|
|
2533
|
+
projection: projectionModel,
|
|
2534
|
+
field,
|
|
2344
2535
|
onSave: handleClose
|
|
2345
|
-
}), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
|
|
2346
|
-
role: "none",
|
|
2347
|
-
className: outerSpacing ? cardSpacing3 : "mlb-cardSpacingBlock"
|
|
2348
|
-
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
2349
|
-
icon: "ph--plus--regular",
|
|
2350
|
-
label: t("button add property"),
|
|
2351
|
-
onClick: readonly ? void 0 : handleAdd,
|
|
2352
|
-
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
2353
|
-
disabled: view.projection.fields.length >= VIEW_FIELD_LIMIT,
|
|
2354
|
-
classNames: "flex is-full"
|
|
2355
2536
|
})));
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
|
|
2537
|
+
})), !readonly && !expandedField && /* @__PURE__ */ React19.createElement("div", {
|
|
2538
|
+
role: "none",
|
|
2539
|
+
className: "my-form-padding"
|
|
2540
|
+
}, /* @__PURE__ */ React19.createElement(IconButton4, {
|
|
2541
|
+
icon: "ph--plus--regular",
|
|
2542
|
+
label: t("add-property-button.label"),
|
|
2543
|
+
onClick: handleAdd,
|
|
2544
|
+
disabled: viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT,
|
|
2545
|
+
classNames: "w-full"
|
|
2546
|
+
}))));
|
|
2359
2547
|
};
|
|
2548
|
+
var customFields = ({ types, tags }) => ({
|
|
2549
|
+
query: ({ type, readonly, label, getValue, onValueChange }) => {
|
|
2550
|
+
const handleChange = useCallback15((query) => onValueChange(type, query.ast), [
|
|
2551
|
+
onValueChange
|
|
2552
|
+
]);
|
|
2553
|
+
return /* @__PURE__ */ React19.createElement(Input13.Root, null, /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
2554
|
+
readonly,
|
|
2555
|
+
label
|
|
2556
|
+
}), /* @__PURE__ */ React19.createElement(QueryForm, {
|
|
2557
|
+
initialQuery: getValue(),
|
|
2558
|
+
types,
|
|
2559
|
+
tags,
|
|
2560
|
+
onChange: handleChange
|
|
2561
|
+
}));
|
|
2562
|
+
}
|
|
2563
|
+
});
|
|
2360
2564
|
export {
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
ControlFrameItem,
|
|
2364
|
-
ControlGroup,
|
|
2365
|
-
ControlGroupButton,
|
|
2366
|
-
ControlItem,
|
|
2367
|
-
ControlItemInput,
|
|
2368
|
-
ControlPage,
|
|
2369
|
-
ControlSection,
|
|
2370
|
-
ControlSectionHeading,
|
|
2371
|
-
DeprecatedFormContainer,
|
|
2372
|
-
DeprecatedFormInput,
|
|
2565
|
+
ArrayField,
|
|
2566
|
+
BooleanField,
|
|
2373
2567
|
FieldEditor,
|
|
2374
2568
|
Form,
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2569
|
+
FormFieldErrorBoundary,
|
|
2570
|
+
FormFieldLabel,
|
|
2571
|
+
FormFieldWrapper,
|
|
2572
|
+
GeoPointField,
|
|
2573
|
+
MarkdownField,
|
|
2574
|
+
NumberField,
|
|
2575
|
+
ObjectPicker,
|
|
2576
|
+
RefField,
|
|
2577
|
+
SelectField,
|
|
2578
|
+
SelectOptionField,
|
|
2579
|
+
Settings,
|
|
2580
|
+
TextAreaField,
|
|
2581
|
+
TextField,
|
|
2582
|
+
TupleField,
|
|
2384
2583
|
ViewEditor,
|
|
2385
2584
|
cellClassesForFieldType,
|
|
2386
|
-
controlItemClasses,
|
|
2387
|
-
findArrayElementType,
|
|
2388
2585
|
formatForDisplay,
|
|
2389
2586
|
formatForEditing,
|
|
2587
|
+
getDefaultValue,
|
|
2588
|
+
getFormProperties,
|
|
2390
2589
|
getRefProps,
|
|
2590
|
+
omitId,
|
|
2391
2591
|
parseValue,
|
|
2392
2592
|
pathNotUniqueError,
|
|
2393
2593
|
translations,
|
|
2394
|
-
useForm,
|
|
2395
2594
|
useFormContext,
|
|
2595
|
+
useFormFieldState,
|
|
2596
|
+
useFormHandler,
|
|
2396
2597
|
useFormValues,
|
|
2397
|
-
|
|
2398
|
-
useQueryRefOptions,
|
|
2399
|
-
useRefQueryLookupHandler
|
|
2598
|
+
useKeyHandler
|
|
2400
2599
|
};
|
|
2401
2600
|
//# sourceMappingURL=index.mjs.map
|