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