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