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