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