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