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