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