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