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