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