@dxos/react-ui-form 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
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 +1440 -1244
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1426 -1230
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1440 -1244
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.test.d.ts +2 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +4 -4
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +1 -2
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +5 -3
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +5 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/vitest-setup.d.ts +2 -0
- package/dist/types/src/vitest-setup.d.ts.map +1 -0
- package/package.json +27 -25
- package/src/components/ControlSection/ControlSection.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.test.tsx +49 -0
- package/src/components/FieldEditor/FieldEditor.tsx +3 -2
- package/src/components/Form/ArrayField.tsx +51 -34
- package/src/components/Form/Defaults.tsx +74 -48
- package/src/components/Form/Form.stories.tsx +77 -101
- package/src/components/Form/Form.tsx +1 -2
- package/src/components/Form/FormActions.tsx +15 -18
- package/src/components/Form/FormContent.tsx +24 -29
- package/src/components/Form/FormContext.tsx +11 -7
- package/src/components/Form/Input.tsx +1 -1
- package/src/components/Form/RefField.tsx +30 -10
- package/src/components/ViewEditor/ViewEditor.stories.tsx +14 -5
- package/src/components/ViewEditor/ViewEditor.tsx +51 -24
- package/src/components/testing.tsx +5 -9
- package/src/hooks/useRefQueryLookupHandler.ts +1 -3
- package/src/translations.ts +9 -2
- package/src/vitest-setup.ts +11 -0
|
@@ -6,6 +6,7 @@ var translations_default = [
|
|
|
6
6
|
[translationKey]: {
|
|
7
7
|
"fields label": "Fields",
|
|
8
8
|
"hidden fields label": "Hidden Fields",
|
|
9
|
+
"empty readonly ref field label": "(none)",
|
|
9
10
|
// TODO(burdon): Standardize field/property.
|
|
10
11
|
"button add property": "Add property",
|
|
11
12
|
"field property label": "Property",
|
|
@@ -15,6 +16,8 @@ var translations_default = [
|
|
|
15
16
|
"add field": "Add field",
|
|
16
17
|
"delete field": "Delete field",
|
|
17
18
|
"field limit reached": "Maximum number of fields reached",
|
|
19
|
+
"boolean input true value": "Yes",
|
|
20
|
+
"boolean input false value": "No",
|
|
18
21
|
// TODO(burdon): Factor out?
|
|
19
22
|
"button cancel": "Cancel",
|
|
20
23
|
"button save": "Save",
|
|
@@ -44,246 +47,324 @@ var translations_default = [
|
|
|
44
47
|
"format number": "Number",
|
|
45
48
|
"format uri": "URI",
|
|
46
49
|
"format uuid": "UUID",
|
|
47
|
-
// Placeholders
|
|
50
|
+
// Placeholders.
|
|
48
51
|
"placeholder latitude": "Latitude",
|
|
49
52
|
"placeholder longitude": "Longitude",
|
|
50
|
-
// SelectOptionsInput
|
|
53
|
+
// SelectOptionsInput.
|
|
51
54
|
"select option label": "Label",
|
|
52
55
|
"select option label placeholder": "Option label",
|
|
53
56
|
"select option color": "Color",
|
|
54
57
|
"select option delete": "Delete",
|
|
55
|
-
"select option add": "Add option"
|
|
58
|
+
"select option add": "Add option",
|
|
59
|
+
// System schema message.
|
|
60
|
+
"system schema title": "System Schema",
|
|
61
|
+
"system schema description": "This schema is managed by the system and cannot be modified."
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
];
|
|
60
66
|
|
|
61
67
|
// packages/ui/react-ui-form/src/components/deprecated/FormInput.tsx
|
|
68
|
+
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
62
69
|
import React from "react";
|
|
63
70
|
import { Input } from "@dxos/react-ui";
|
|
64
71
|
import { mx, textBlockWidth } from "@dxos/react-ui-theme";
|
|
65
72
|
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
var _effect = _useSignals();
|
|
74
|
+
try {
|
|
75
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
76
|
+
role: "none",
|
|
77
|
+
className: "container-max-width p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
78
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
79
|
+
role: "form",
|
|
80
|
+
className: mx("flex flex-col", textBlockWidth, classNames)
|
|
81
|
+
}, children));
|
|
82
|
+
} finally {
|
|
83
|
+
_effect.f();
|
|
84
|
+
}
|
|
73
85
|
};
|
|
74
86
|
var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
role: "none",
|
|
92
|
-
className: "flex min-bs-[--rail-action] items-center"
|
|
93
|
-
}, children))));
|
|
94
|
-
if (secondary) {
|
|
95
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
87
|
+
var _effect = _useSignals();
|
|
88
|
+
try {
|
|
89
|
+
const primary = /* @__PURE__ */ React.createElement("div", {
|
|
90
|
+
role: "none",
|
|
91
|
+
className: "flex w-full gap-4 py-1"
|
|
92
|
+
}, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement("div", {
|
|
93
|
+
role: "none",
|
|
94
|
+
className: "flex flex-col w-full"
|
|
95
|
+
}, /* @__PURE__ */ React.createElement(Input.Label, {
|
|
96
|
+
classNames: "flex min-bs-[--rail-action] items-center",
|
|
97
|
+
style: {
|
|
98
|
+
fontSize: "unset"
|
|
99
|
+
}
|
|
100
|
+
}, label), description && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, {
|
|
101
|
+
classNames: "mbs-0.5"
|
|
102
|
+
}, /* @__PURE__ */ React.createElement(Input.Description, null, description))), /* @__PURE__ */ React.createElement("div", {
|
|
96
103
|
role: "none"
|
|
97
|
-
},
|
|
104
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
105
|
+
role: "none",
|
|
106
|
+
className: "flex min-bs-[--rail-action] items-center"
|
|
107
|
+
}, children))));
|
|
108
|
+
if (secondary) {
|
|
109
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
110
|
+
role: "none"
|
|
111
|
+
}, primary, secondary);
|
|
112
|
+
}
|
|
113
|
+
return primary;
|
|
114
|
+
} finally {
|
|
115
|
+
_effect.f();
|
|
98
116
|
}
|
|
99
|
-
return primary;
|
|
100
117
|
};
|
|
101
118
|
|
|
102
119
|
// packages/ui/react-ui-form/src/components/ControlSection/ControlSection.tsx
|
|
120
|
+
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
103
121
|
import React2 from "react";
|
|
104
122
|
import { Button, Input as Input2, toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
105
123
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
106
124
|
var ControlPage = ({ children, classNames, ...props }) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
var _effect = _useSignals2();
|
|
126
|
+
try {
|
|
127
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
128
|
+
role: "none",
|
|
129
|
+
className: mx2("pli-2", classNames),
|
|
130
|
+
...props
|
|
131
|
+
}, children);
|
|
132
|
+
} finally {
|
|
133
|
+
_effect.f();
|
|
134
|
+
}
|
|
112
135
|
};
|
|
113
136
|
var ControlSection = ({ title, description, children }) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
137
|
+
var _effect = _useSignals2();
|
|
138
|
+
try {
|
|
139
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ControlSectionHeading, {
|
|
140
|
+
title,
|
|
141
|
+
description
|
|
142
|
+
}), children);
|
|
143
|
+
} finally {
|
|
144
|
+
_effect.f();
|
|
145
|
+
}
|
|
118
146
|
};
|
|
119
147
|
var ControlSectionHeading = ({ title, description }) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
var _effect = _useSignals2();
|
|
149
|
+
try {
|
|
150
|
+
const { t } = useTranslation(translationKey);
|
|
151
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", {
|
|
152
|
+
className: "pli-4 container-max-width text-xl mbs-6 mbe-4"
|
|
153
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement("p", {
|
|
154
|
+
className: "pli-4 mlb-4 container-max-width text-description"
|
|
155
|
+
}, toLocalizedString(description, t)));
|
|
156
|
+
} finally {
|
|
157
|
+
_effect.f();
|
|
158
|
+
}
|
|
126
159
|
};
|
|
127
160
|
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
classNames
|
|
133
|
-
|
|
134
|
-
|
|
161
|
+
var _effect = _useSignals2();
|
|
162
|
+
try {
|
|
163
|
+
return /* @__PURE__ */ React2.createElement(Button, {
|
|
164
|
+
...props,
|
|
165
|
+
classNames: [
|
|
166
|
+
"md:col-span-2",
|
|
167
|
+
classNames
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
} finally {
|
|
171
|
+
_effect.f();
|
|
172
|
+
}
|
|
135
173
|
};
|
|
136
|
-
var ControlGroup = ({ children, classNames }) =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
174
|
+
var ControlGroup = ({ children, classNames }) => {
|
|
175
|
+
var _effect = _useSignals2();
|
|
176
|
+
try {
|
|
177
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
178
|
+
role: "none",
|
|
179
|
+
className: mx2("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4", classNames)
|
|
180
|
+
}, children);
|
|
181
|
+
} finally {
|
|
182
|
+
_effect.f();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var ControlFrame = ({ children }) => {
|
|
186
|
+
var _effect = _useSignals2();
|
|
187
|
+
try {
|
|
188
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
189
|
+
role: "none",
|
|
190
|
+
className: "p-4 border border-separator rounded-lg container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-2 md:gap-8"
|
|
191
|
+
}, children);
|
|
192
|
+
} finally {
|
|
193
|
+
_effect.f();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var controlItemClasses = "p-4 border border-separator rounded-lg container-max-width grid md:col-span-2 grid-cols-subgrid items-center gap-2";
|
|
197
|
+
var controlItemTitleClasses = "text-lg font-normal";
|
|
146
198
|
var controlItemDescriptionClasses = "text-base mlb-2 md:mbe-0 text-description";
|
|
147
199
|
var ControlItem = ({ title, description, children }) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
200
|
+
var _effect = _useSignals2();
|
|
201
|
+
try {
|
|
202
|
+
const { t } = useTranslation(translationKey);
|
|
203
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
204
|
+
className: controlItemClasses
|
|
205
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
206
|
+
role: "none"
|
|
207
|
+
}, /* @__PURE__ */ React2.createElement("h3", {
|
|
208
|
+
className: controlItemTitleClasses
|
|
209
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement("p", {
|
|
210
|
+
className: controlItemDescriptionClasses
|
|
211
|
+
}, toLocalizedString(description, t))), children);
|
|
212
|
+
} finally {
|
|
213
|
+
_effect.f();
|
|
214
|
+
}
|
|
158
215
|
};
|
|
159
216
|
var ControlItemInput = ({ title, description, children }) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
217
|
+
var _effect = _useSignals2();
|
|
218
|
+
try {
|
|
219
|
+
const { t } = useTranslation(translationKey);
|
|
220
|
+
return /* @__PURE__ */ React2.createElement(Input2.Root, null, /* @__PURE__ */ React2.createElement("div", {
|
|
221
|
+
className: controlItemClasses
|
|
222
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
223
|
+
role: "none"
|
|
224
|
+
}, /* @__PURE__ */ React2.createElement(Input2.Label, {
|
|
225
|
+
classNames: controlItemTitleClasses
|
|
226
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement(Input2.DescriptionAndValidation, null, /* @__PURE__ */ React2.createElement(Input2.Description, {
|
|
227
|
+
classNames: controlItemDescriptionClasses
|
|
228
|
+
}, toLocalizedString(description, t)))), children));
|
|
229
|
+
} finally {
|
|
230
|
+
_effect.f();
|
|
231
|
+
}
|
|
170
232
|
};
|
|
171
233
|
var ControlFrameItem = ({ title, description, children }) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
234
|
+
var _effect = _useSignals2();
|
|
235
|
+
try {
|
|
236
|
+
const { t } = useTranslation(translationKey);
|
|
237
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
238
|
+
role: "group",
|
|
239
|
+
className: "min-is-0"
|
|
240
|
+
}, /* @__PURE__ */ React2.createElement("h3", {
|
|
241
|
+
className: "text-lg mbe-2"
|
|
242
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React2.createElement("p", {
|
|
243
|
+
className: "mlb-2 md:mbe-0 text-description"
|
|
244
|
+
}, toLocalizedString(description, t)), children);
|
|
245
|
+
} finally {
|
|
246
|
+
_effect.f();
|
|
247
|
+
}
|
|
181
248
|
};
|
|
182
249
|
|
|
183
250
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
184
|
-
import
|
|
251
|
+
import { useSignals as _useSignals14 } from "@preact-signals/safe-react/tracking";
|
|
252
|
+
import React14, { useCallback as useCallback9, useEffect as useEffect8, useMemo as useMemo7, useState as useState5 } from "react";
|
|
185
253
|
import { FormatEnum as FormatEnum5, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
186
254
|
import { log as log3 } from "@dxos/log";
|
|
187
|
-
import { useTranslation as
|
|
255
|
+
import { useTranslation as useTranslation8 } from "@dxos/react-ui";
|
|
188
256
|
import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
|
|
189
257
|
|
|
190
258
|
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
259
|
+
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
|
191
260
|
import React4, { useCallback, useState, useEffect, useMemo } from "react";
|
|
192
261
|
import { GeoLocation } from "@dxos/echo-schema";
|
|
193
262
|
import { Input as Input3, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
194
263
|
import { safeParseFloat } from "@dxos/util";
|
|
195
264
|
|
|
196
265
|
// packages/ui/react-ui-form/src/components/Form/Input.tsx
|
|
266
|
+
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
197
267
|
import React3 from "react";
|
|
198
268
|
import { Icon, Tooltip } from "@dxos/react-ui";
|
|
199
269
|
import { errorText } from "@dxos/react-ui-theme";
|
|
200
270
|
var InputHeader = ({ children, error }) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
271
|
+
var _effect = _useSignals3();
|
|
272
|
+
try {
|
|
273
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
274
|
+
role: "none",
|
|
275
|
+
className: "flex justify-between items-center mbs-2 mbe-1 first:mbs-0"
|
|
276
|
+
}, children, error && /* @__PURE__ */ React3.createElement(Tooltip.Trigger, {
|
|
277
|
+
asChild: true,
|
|
278
|
+
content: error,
|
|
279
|
+
side: "bottom"
|
|
280
|
+
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
281
|
+
icon: "ph--warning--regular",
|
|
282
|
+
size: 4,
|
|
283
|
+
classNames: errorText
|
|
284
|
+
})));
|
|
285
|
+
} finally {
|
|
286
|
+
_effect.f();
|
|
287
|
+
}
|
|
213
288
|
};
|
|
214
289
|
|
|
215
290
|
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
216
291
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
setText(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
292
|
+
var _effect = _useSignals4();
|
|
293
|
+
try {
|
|
294
|
+
const { t } = useTranslation2(translationKey);
|
|
295
|
+
const { status, error } = getStatus();
|
|
296
|
+
const geoPoint = useMemo(() => getValue3() ?? [
|
|
297
|
+
0,
|
|
298
|
+
0
|
|
299
|
+
], [
|
|
300
|
+
getValue3
|
|
301
|
+
]);
|
|
302
|
+
const geoLocation = useMemo(() => GeoLocation.fromGeoPoint(geoPoint), [
|
|
303
|
+
geoPoint
|
|
304
|
+
]);
|
|
305
|
+
const [longitudeText, setLongitudeText] = useState(geoLocation.longitude?.toString());
|
|
306
|
+
const [latitudeText, setLatitudeText] = useState(geoLocation.latitude?.toString());
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
const location = GeoLocation.fromGeoPoint(geoPoint);
|
|
309
|
+
setLongitudeText(location.longitude.toString());
|
|
310
|
+
setLatitudeText(location.latitude.toString());
|
|
311
|
+
}, [
|
|
312
|
+
geoPoint
|
|
313
|
+
]);
|
|
314
|
+
const handleCoordinateChange = useCallback((coordinateType, setText) => (event) => {
|
|
315
|
+
const inputText = event.target.value;
|
|
316
|
+
setText(inputText);
|
|
317
|
+
if (inputText !== "" && inputText !== "-") {
|
|
318
|
+
const coord = safeParseFloat(inputText);
|
|
319
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
320
|
+
const currentLocation = GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
321
|
+
0,
|
|
322
|
+
0
|
|
323
|
+
]);
|
|
324
|
+
const newLocation = {
|
|
325
|
+
...currentLocation,
|
|
326
|
+
[coordinateType]: coord
|
|
327
|
+
};
|
|
328
|
+
const newValue = GeoLocation.toGeoPoint(newLocation);
|
|
329
|
+
onValueChange(type, newValue);
|
|
330
|
+
}
|
|
253
331
|
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
332
|
+
}, [
|
|
333
|
+
getValue3,
|
|
334
|
+
onValueChange,
|
|
335
|
+
type
|
|
336
|
+
]);
|
|
337
|
+
return /* @__PURE__ */ React4.createElement(Input3.Root, {
|
|
338
|
+
validationValence: status
|
|
339
|
+
}, /* @__PURE__ */ React4.createElement(InputHeader, {
|
|
340
|
+
error
|
|
341
|
+
}, /* @__PURE__ */ React4.createElement(Input3.Label, null, label)), /* @__PURE__ */ React4.createElement("div", {
|
|
342
|
+
role: "none",
|
|
343
|
+
className: "grid grid-cols-2 gap-2"
|
|
344
|
+
}, /* @__PURE__ */ React4.createElement(Input3.TextInput, {
|
|
345
|
+
type: "text",
|
|
346
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
347
|
+
disabled,
|
|
348
|
+
placeholder: t("placeholder latitude"),
|
|
349
|
+
value: latitudeText,
|
|
350
|
+
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
351
|
+
onBlur
|
|
352
|
+
}), /* @__PURE__ */ React4.createElement(Input3.TextInput, {
|
|
353
|
+
type: "text",
|
|
354
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
355
|
+
disabled,
|
|
356
|
+
placeholder: t("placeholder longitude"),
|
|
357
|
+
value: longitudeText,
|
|
358
|
+
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
359
|
+
onBlur
|
|
360
|
+
})));
|
|
361
|
+
} finally {
|
|
362
|
+
_effect.f();
|
|
363
|
+
}
|
|
284
364
|
};
|
|
285
365
|
|
|
286
366
|
// packages/ui/react-ui-form/src/components/Form/custom/SelectOptionsInput.tsx
|
|
367
|
+
import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
|
|
287
368
|
import React5, { useCallback as useCallback2, useEffect as useEffect2, useState as useState2, useRef } from "react";
|
|
288
369
|
import { PublicKey } from "@dxos/keys";
|
|
289
370
|
import { Icon as Icon2, IconButton, Input as Input4, Tag, Toolbar, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
@@ -291,183 +372,189 @@ import { List } from "@dxos/react-ui-list";
|
|
|
291
372
|
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
292
373
|
import { hues, mx as mx3 } from "@dxos/react-ui-theme";
|
|
293
374
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const newId = PublicKey.random().truncate();
|
|
321
|
-
const newOption = {
|
|
322
|
-
id: newId,
|
|
323
|
-
title: "",
|
|
324
|
-
color: randomHue()
|
|
375
|
+
var _effect = _useSignals5();
|
|
376
|
+
try {
|
|
377
|
+
const [selected, setSelectedId] = useState2(null);
|
|
378
|
+
const [isNewOption, setIsNewOption] = useState2(false);
|
|
379
|
+
const inputRef = useRef(null);
|
|
380
|
+
const { t } = useTranslation3(translationKey);
|
|
381
|
+
const { status, error } = getStatus();
|
|
382
|
+
const options = getValue3();
|
|
383
|
+
useEffect2(() => {
|
|
384
|
+
if (options === void 0) {
|
|
385
|
+
onValueChange(type, []);
|
|
386
|
+
}
|
|
387
|
+
}, [
|
|
388
|
+
options,
|
|
389
|
+
onValueChange,
|
|
390
|
+
type
|
|
391
|
+
]);
|
|
392
|
+
const randomHue = () => {
|
|
393
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
394
|
+
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
395
|
+
if (unusedHues.length > 0) {
|
|
396
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
397
|
+
}
|
|
398
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
399
|
+
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
400
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
|
|
325
401
|
};
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
newOption
|
|
402
|
+
const handleAdd = useCallback2(() => {
|
|
403
|
+
const newId = PublicKey.random().truncate();
|
|
404
|
+
const newOption = {
|
|
405
|
+
id: newId,
|
|
406
|
+
title: "",
|
|
407
|
+
color: randomHue()
|
|
408
|
+
};
|
|
409
|
+
onValueChange(type, [
|
|
410
|
+
...options ?? [],
|
|
411
|
+
newOption
|
|
412
|
+
]);
|
|
413
|
+
setSelectedId(newId);
|
|
414
|
+
setIsNewOption(true);
|
|
415
|
+
}, [
|
|
416
|
+
options,
|
|
417
|
+
type,
|
|
418
|
+
onValueChange
|
|
329
419
|
]);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
options,
|
|
334
|
-
type,
|
|
335
|
-
onValueChange
|
|
336
|
-
]);
|
|
337
|
-
const handleDelete = useCallback2((id) => {
|
|
338
|
-
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
339
|
-
onValueChange(type, newOptions);
|
|
340
|
-
setSelectedId(null);
|
|
341
|
-
}, [
|
|
342
|
-
options,
|
|
343
|
-
type,
|
|
344
|
-
onValueChange
|
|
345
|
-
]);
|
|
346
|
-
const handleMove = useCallback2((from, to) => {
|
|
347
|
-
if (!options) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
const newOptions = [
|
|
351
|
-
...options
|
|
352
|
-
];
|
|
353
|
-
const [removed] = newOptions.splice(from, 1);
|
|
354
|
-
newOptions.splice(to, 0, removed);
|
|
355
|
-
onValueChange(type, newOptions);
|
|
356
|
-
}, [
|
|
357
|
-
options,
|
|
358
|
-
type,
|
|
359
|
-
onValueChange
|
|
360
|
-
]);
|
|
361
|
-
const handleClick = useCallback2((id) => {
|
|
362
|
-
setSelectedId((current) => current === id ? null : id);
|
|
363
|
-
}, []);
|
|
364
|
-
const handleTitleChange = useCallback2((id) => (e) => {
|
|
365
|
-
const newOptions = options?.map((o) => o.id === id ? {
|
|
366
|
-
...o,
|
|
367
|
-
title: e.target.value
|
|
368
|
-
} : o);
|
|
369
|
-
onValueChange(type, newOptions ?? []);
|
|
370
|
-
}, [
|
|
371
|
-
options,
|
|
372
|
-
type,
|
|
373
|
-
onValueChange
|
|
374
|
-
]);
|
|
375
|
-
const handleKeyDown = useCallback2((e) => {
|
|
376
|
-
if (e.key === "Enter") {
|
|
420
|
+
const handleDelete = useCallback2((id) => {
|
|
421
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
422
|
+
onValueChange(type, newOptions);
|
|
377
423
|
setSelectedId(null);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
424
|
+
}, [
|
|
425
|
+
options,
|
|
426
|
+
type,
|
|
427
|
+
onValueChange
|
|
428
|
+
]);
|
|
429
|
+
const handleMove = useCallback2((from, to) => {
|
|
430
|
+
if (!options) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const newOptions = [
|
|
434
|
+
...options
|
|
435
|
+
];
|
|
436
|
+
const [removed] = newOptions.splice(from, 1);
|
|
437
|
+
newOptions.splice(to, 0, removed);
|
|
438
|
+
onValueChange(type, newOptions);
|
|
439
|
+
}, [
|
|
440
|
+
options,
|
|
441
|
+
type,
|
|
442
|
+
onValueChange
|
|
443
|
+
]);
|
|
444
|
+
const handleClick = useCallback2((id) => {
|
|
445
|
+
setSelectedId((current) => current === id ? null : id);
|
|
446
|
+
}, []);
|
|
447
|
+
const handleTitleChange = useCallback2((id) => (e) => {
|
|
448
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
449
|
+
...o,
|
|
450
|
+
title: e.target.value
|
|
451
|
+
} : o);
|
|
452
|
+
onValueChange(type, newOptions ?? []);
|
|
453
|
+
}, [
|
|
454
|
+
options,
|
|
455
|
+
type,
|
|
456
|
+
onValueChange
|
|
457
|
+
]);
|
|
458
|
+
const handleKeyDown = useCallback2((e) => {
|
|
459
|
+
if (e.key === "Enter") {
|
|
460
|
+
setSelectedId(null);
|
|
461
|
+
}
|
|
462
|
+
}, []);
|
|
463
|
+
const handleColorChange = useCallback2((id) => (hue) => {
|
|
464
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
465
|
+
...o,
|
|
466
|
+
color: hue
|
|
467
|
+
} : o);
|
|
468
|
+
onValueChange(type, newOptions ?? []);
|
|
469
|
+
}, [
|
|
470
|
+
options,
|
|
471
|
+
type,
|
|
472
|
+
onValueChange
|
|
473
|
+
]);
|
|
474
|
+
useEffect2(() => {
|
|
475
|
+
if (selected && isNewOption && inputRef.current) {
|
|
476
|
+
inputRef.current.focus();
|
|
477
|
+
setIsNewOption(false);
|
|
478
|
+
}
|
|
479
|
+
}, [
|
|
480
|
+
selected,
|
|
481
|
+
isNewOption
|
|
482
|
+
]);
|
|
483
|
+
return /* @__PURE__ */ React5.createElement(Input4.Root, {
|
|
484
|
+
validationValence: status
|
|
485
|
+
}, /* @__PURE__ */ React5.createElement(InputHeader, {
|
|
486
|
+
error
|
|
487
|
+
}, /* @__PURE__ */ React5.createElement(Input4.Label, null, label)), /* @__PURE__ */ React5.createElement("div", {
|
|
488
|
+
role: "none"
|
|
489
|
+
}, options && /* @__PURE__ */ React5.createElement(List.Root, {
|
|
490
|
+
items: options,
|
|
491
|
+
isItem: (item) => true,
|
|
492
|
+
onMove: handleMove
|
|
493
|
+
}, ({ items }) => /* @__PURE__ */ React5.createElement("div", {
|
|
494
|
+
role: "list",
|
|
495
|
+
className: "w-full overflow-auto"
|
|
496
|
+
}, items?.map((item) => /* @__PURE__ */ React5.createElement("div", {
|
|
497
|
+
key: item.id
|
|
498
|
+
}, /* @__PURE__ */ React5.createElement(List.Item, {
|
|
499
|
+
role: "button",
|
|
500
|
+
item,
|
|
501
|
+
classNames: mx3("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
502
|
+
"aria-expanded": selected === item.id
|
|
503
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
504
|
+
className: "flex items-center"
|
|
505
|
+
}, /* @__PURE__ */ React5.createElement(List.ItemDragHandle, null), /* @__PURE__ */ React5.createElement(List.ItemTitle, {
|
|
506
|
+
onClick: () => handleClick(item.id),
|
|
507
|
+
classNames: "flex-1"
|
|
508
|
+
}, /* @__PURE__ */ React5.createElement(Tag, {
|
|
509
|
+
palette: item.color
|
|
510
|
+
}, item.title || "\u200B")), /* @__PURE__ */ React5.createElement(Icon2, {
|
|
511
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
512
|
+
onClick: () => handleClick(item.id)
|
|
513
|
+
})), selected === item.id && /* @__PURE__ */ React5.createElement("div", {
|
|
514
|
+
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
515
|
+
}, /* @__PURE__ */ React5.createElement(Input4.Label, {
|
|
516
|
+
classNames: "text-xs"
|
|
517
|
+
}, t("select option label")), /* @__PURE__ */ React5.createElement("div", {
|
|
518
|
+
className: "flex flex-row items-center gap-1"
|
|
519
|
+
}, /* @__PURE__ */ React5.createElement(Input4.TextInput, {
|
|
520
|
+
placeholder: t("select option label placeholder"),
|
|
521
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
522
|
+
value: item.title,
|
|
523
|
+
onChange: handleTitleChange(item.id),
|
|
524
|
+
onKeyDown: handleKeyDown,
|
|
525
|
+
classNames: "flex-1",
|
|
526
|
+
"data-no-submit": true
|
|
527
|
+
}), /* @__PURE__ */ React5.createElement(Toolbar.Root, {
|
|
528
|
+
classNames: "p-0 m-0 !is-auto"
|
|
529
|
+
}, /* @__PURE__ */ React5.createElement(HuePicker, {
|
|
530
|
+
value: item.color,
|
|
531
|
+
onChange: handleColorChange(item.id),
|
|
532
|
+
rootVariant: "toolbar-button"
|
|
533
|
+
})), /* @__PURE__ */ React5.createElement(IconButton, {
|
|
534
|
+
icon: "ph--trash--fill",
|
|
535
|
+
iconOnly: true,
|
|
536
|
+
label: t("select option delete"),
|
|
537
|
+
onClick: () => handleDelete(item.id)
|
|
538
|
+
})))))), /* @__PURE__ */ React5.createElement("div", {
|
|
539
|
+
role: "listitem"
|
|
540
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
541
|
+
role: "button",
|
|
542
|
+
className: mx3("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
543
|
+
onClick: handleAdd
|
|
544
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
545
|
+
className: "flex items-center gap-1"
|
|
546
|
+
}, /* @__PURE__ */ React5.createElement(Icon2, {
|
|
547
|
+
icon: "ph--plus--regular"
|
|
548
|
+
}), /* @__PURE__ */ React5.createElement("span", {
|
|
549
|
+
className: "text-sm"
|
|
550
|
+
}, t("select option add")))))))));
|
|
551
|
+
} finally {
|
|
552
|
+
_effect.f();
|
|
553
|
+
}
|
|
468
554
|
};
|
|
469
555
|
|
|
470
556
|
// packages/ui/react-ui-form/src/components/Form/custom/TupleInput.tsx
|
|
557
|
+
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
471
558
|
import React6 from "react";
|
|
472
559
|
import { Input as Input5 } from "@dxos/react-ui";
|
|
473
560
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
@@ -479,148 +566,182 @@ var gridCols = [
|
|
|
479
566
|
"grid-cols-4"
|
|
480
567
|
];
|
|
481
568
|
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
569
|
+
var _effect = _useSignals6();
|
|
570
|
+
try {
|
|
571
|
+
const { status, error } = getStatus();
|
|
572
|
+
const values = getValue3() ?? {};
|
|
573
|
+
return /* @__PURE__ */ React6.createElement(Input5.Root, {
|
|
574
|
+
validationValence: status
|
|
575
|
+
}, /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
576
|
+
error
|
|
577
|
+
}, /* @__PURE__ */ React6.createElement(Input5.Label, null, label)), /* @__PURE__ */ React6.createElement("div", {
|
|
578
|
+
className: mx4("grid gap-2", gridCols[binding.length - 1])
|
|
579
|
+
}, binding.map((prop) => /* @__PURE__ */ React6.createElement(Input5.TextInput, {
|
|
580
|
+
key: prop,
|
|
581
|
+
type: "number",
|
|
582
|
+
disabled,
|
|
583
|
+
value: values[prop],
|
|
584
|
+
onChange: (event) => onValueChange(type, {
|
|
585
|
+
...values,
|
|
586
|
+
[prop]: safeParseFloat2(event.target.value, 0)
|
|
587
|
+
}),
|
|
588
|
+
onBlur
|
|
589
|
+
}))));
|
|
590
|
+
} finally {
|
|
591
|
+
_effect.f();
|
|
592
|
+
}
|
|
501
593
|
};
|
|
502
594
|
|
|
503
595
|
// packages/ui/react-ui-form/src/components/Form/Defaults.tsx
|
|
596
|
+
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
504
597
|
import React7, { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
505
|
-
import { Input as Input6, Select } from "@dxos/react-ui";
|
|
598
|
+
import { Input as Input6, Select, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
506
599
|
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
600
|
+
var _effect = _useSignals7();
|
|
601
|
+
try {
|
|
602
|
+
const { status, error } = getStatus();
|
|
603
|
+
return disabled && !getValue3() ? null : disabled && inputOnly ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
604
|
+
validationValence: status
|
|
605
|
+
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
606
|
+
error
|
|
607
|
+
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), disabled ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input6.TextInput, {
|
|
608
|
+
disabled,
|
|
609
|
+
placeholder,
|
|
610
|
+
value: getValue3() ?? "",
|
|
611
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
612
|
+
onBlur
|
|
613
|
+
}), inputOnly && /* @__PURE__ */ React7.createElement(Input6.Validation, null, error));
|
|
614
|
+
} finally {
|
|
615
|
+
_effect.f();
|
|
616
|
+
}
|
|
519
617
|
};
|
|
520
618
|
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
disabled,
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
619
|
+
var _effect = _useSignals7();
|
|
620
|
+
try {
|
|
621
|
+
const { status, error } = getStatus();
|
|
622
|
+
return disabled && !getValue3() ? null : disabled && inputOnly ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
623
|
+
validationValence: status
|
|
624
|
+
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
625
|
+
error
|
|
626
|
+
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), disabled ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input6.TextInput, {
|
|
627
|
+
type: "number",
|
|
628
|
+
disabled,
|
|
629
|
+
placeholder,
|
|
630
|
+
value: getValue3() ?? 0,
|
|
631
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
632
|
+
onBlur
|
|
633
|
+
}), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
|
|
634
|
+
} finally {
|
|
635
|
+
_effect.f();
|
|
636
|
+
}
|
|
534
637
|
};
|
|
535
|
-
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
638
|
+
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange, disabled }) => {
|
|
639
|
+
var _effect = _useSignals7();
|
|
640
|
+
try {
|
|
641
|
+
const { status, error } = getStatus();
|
|
642
|
+
const checked = Boolean(getValue3());
|
|
643
|
+
const { t } = useTranslation4(translationKey);
|
|
644
|
+
return /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
645
|
+
validationValence: status
|
|
646
|
+
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
647
|
+
error
|
|
648
|
+
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), disabled ? /* @__PURE__ */ React7.createElement("p", null, t(checked ? "boolean input true value" : "boolean input false value")) : /* @__PURE__ */ React7.createElement(Input6.Switch, {
|
|
649
|
+
checked,
|
|
650
|
+
onCheckedChange: (value) => onValueChange(type, value)
|
|
651
|
+
}), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
|
|
652
|
+
} finally {
|
|
653
|
+
_effect.f();
|
|
654
|
+
}
|
|
546
655
|
};
|
|
547
656
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
onValueChange
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
/* @__PURE__ */ React7.createElement(Select.
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
657
|
+
var _effect = _useSignals7();
|
|
658
|
+
try {
|
|
659
|
+
const { status, error } = getStatus();
|
|
660
|
+
const value = getValue3();
|
|
661
|
+
const handleValueChange = useCallback3((value2) => onValueChange(type, value2), [
|
|
662
|
+
type,
|
|
663
|
+
onValueChange
|
|
664
|
+
]);
|
|
665
|
+
return disabled && !value ? null : /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
666
|
+
validationValence: status
|
|
667
|
+
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
668
|
+
error
|
|
669
|
+
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), disabled ? /* @__PURE__ */ React7.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value)?.label ?? String(value)) : /* @__PURE__ */ React7.createElement(Select.Root, {
|
|
670
|
+
value,
|
|
671
|
+
onValueChange: handleValueChange
|
|
672
|
+
}, /* @__PURE__ */ React7.createElement(Select.TriggerButton, {
|
|
673
|
+
classNames: "is-full",
|
|
674
|
+
disabled,
|
|
675
|
+
placeholder
|
|
676
|
+
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
677
|
+
// NOTE: Numeric values are converted to and from strings.
|
|
678
|
+
/* @__PURE__ */ React7.createElement(Select.Option, {
|
|
679
|
+
key: String(value2),
|
|
680
|
+
value: String(value2)
|
|
681
|
+
}, label2 ?? String(value2))
|
|
682
|
+
)))))), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
|
|
683
|
+
} finally {
|
|
684
|
+
_effect.f();
|
|
685
|
+
}
|
|
572
686
|
};
|
|
573
687
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
textarea
|
|
580
|
-
textarea
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
disabled,
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
688
|
+
var _effect = _useSignals7();
|
|
689
|
+
try {
|
|
690
|
+
const { status, error } = getStatus();
|
|
691
|
+
const textareaRef = useRef2(null);
|
|
692
|
+
const adjustHeight = useCallback3(() => {
|
|
693
|
+
const textarea = textareaRef.current;
|
|
694
|
+
if (textarea) {
|
|
695
|
+
textarea.style.blockSize = "auto";
|
|
696
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
697
|
+
}
|
|
698
|
+
}, []);
|
|
699
|
+
useEffect3(() => {
|
|
700
|
+
adjustHeight();
|
|
701
|
+
}, [
|
|
702
|
+
adjustHeight
|
|
703
|
+
]);
|
|
704
|
+
useEffect3(() => {
|
|
705
|
+
adjustHeight();
|
|
706
|
+
}, [
|
|
707
|
+
getValue3(),
|
|
708
|
+
adjustHeight
|
|
709
|
+
]);
|
|
710
|
+
return /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
711
|
+
validationValence: status
|
|
712
|
+
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
713
|
+
error
|
|
714
|
+
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), disabled ? /* @__PURE__ */ React7.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React7.createElement(Input6.TextArea, {
|
|
715
|
+
ref: textareaRef,
|
|
716
|
+
disabled,
|
|
717
|
+
placeholder,
|
|
718
|
+
value: getValue3() ?? "",
|
|
719
|
+
classNames: "min-bs-auto max-h-40 overflow-auto",
|
|
720
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
721
|
+
onBlur,
|
|
722
|
+
style: {
|
|
723
|
+
resize: "none"
|
|
724
|
+
},
|
|
725
|
+
spellCheck: false
|
|
726
|
+
}), inputOnly && /* @__PURE__ */ React7.createElement(Input6.Validation, null, error));
|
|
727
|
+
} finally {
|
|
728
|
+
_effect.f();
|
|
729
|
+
}
|
|
611
730
|
};
|
|
612
731
|
|
|
613
732
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
733
|
+
import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
|
|
614
734
|
import React13, { useEffect as useEffect7, useMemo as useMemo6, useRef as useRef3 } from "react";
|
|
615
|
-
import { mx as
|
|
735
|
+
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
616
736
|
|
|
617
737
|
// packages/ui/react-ui-form/src/components/Form/FormActions.tsx
|
|
738
|
+
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
618
739
|
import React9 from "react";
|
|
619
|
-
import { IconButton as IconButton2, useTranslation as
|
|
620
|
-
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
740
|
+
import { IconButton as IconButton2, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
621
741
|
|
|
622
742
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
623
|
-
import
|
|
743
|
+
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
744
|
+
import React8, { createContext, useContext, useEffect as useEffect6, useMemo as useMemo3, useCallback as useCallback6 } from "react";
|
|
624
745
|
import { raise } from "@dxos/debug";
|
|
625
746
|
import { getValue as getValue2 } from "@dxos/echo-schema";
|
|
626
747
|
import { createJsonPath as createJsonPath2 } from "@dxos/effect";
|
|
@@ -840,7 +961,7 @@ import { getDXN } from "@dxos/echo-schema";
|
|
|
840
961
|
import { Filter } from "@dxos/react-client/echo";
|
|
841
962
|
import { isNonNullable } from "@dxos/util";
|
|
842
963
|
var useRefQueryLookupHandler = ({ space }) => {
|
|
843
|
-
|
|
964
|
+
return useCallback5(async (typeInfo) => {
|
|
844
965
|
if (!space) {
|
|
845
966
|
return [];
|
|
846
967
|
}
|
|
@@ -860,7 +981,6 @@ var useRefQueryLookupHandler = ({ space }) => {
|
|
|
860
981
|
}, [
|
|
861
982
|
space
|
|
862
983
|
]);
|
|
863
|
-
return handleRefQueryLookup;
|
|
864
984
|
};
|
|
865
985
|
|
|
866
986
|
// packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts
|
|
@@ -938,12 +1058,10 @@ var useInputProps = (path = []) => {
|
|
|
938
1058
|
]);
|
|
939
1059
|
};
|
|
940
1060
|
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
const handleKeyDown = (event) => {
|
|
1061
|
+
var _effect = _useSignals8();
|
|
1062
|
+
try {
|
|
1063
|
+
const form = useForm(formOptions);
|
|
1064
|
+
const handleKeyDown = useCallback6((event) => {
|
|
947
1065
|
const keyIsEnter = event.key === "Enter";
|
|
948
1066
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
949
1067
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
@@ -958,64 +1076,76 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
958
1076
|
event.target.blur();
|
|
959
1077
|
}
|
|
960
1078
|
}
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1079
|
+
}, [
|
|
1080
|
+
form,
|
|
1081
|
+
autoSave
|
|
1082
|
+
]);
|
|
1083
|
+
useEffect6(() => {
|
|
1084
|
+
if (!formRef?.current) {
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
const formElement = formRef.current;
|
|
1088
|
+
formElement.addEventListener("keydown", handleKeyDown);
|
|
1089
|
+
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
1090
|
+
}, [
|
|
1091
|
+
formRef,
|
|
1092
|
+
form.canSave,
|
|
1093
|
+
form.formIsValid,
|
|
1094
|
+
form.handleSave,
|
|
1095
|
+
autoSave
|
|
1096
|
+
]);
|
|
1097
|
+
return /* @__PURE__ */ React8.createElement(FormContext.Provider, {
|
|
1098
|
+
value: form
|
|
1099
|
+
}, children);
|
|
1100
|
+
} finally {
|
|
1101
|
+
_effect.f();
|
|
1102
|
+
}
|
|
975
1103
|
};
|
|
976
1104
|
|
|
977
1105
|
// packages/ui/react-ui-form/src/components/Form/FormActions.tsx
|
|
978
|
-
var FormActions = ({
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
}
|
|
1106
|
+
var FormActions = ({ readonly, onCancel }) => {
|
|
1107
|
+
var _effect = _useSignals9();
|
|
1108
|
+
try {
|
|
1109
|
+
const { t } = useTranslation5(translationKey);
|
|
1110
|
+
const { canSave, handleSave } = useFormContext();
|
|
1111
|
+
return /* @__PURE__ */ React9.createElement("div", {
|
|
1112
|
+
role: "none",
|
|
1113
|
+
className: "flex [&_button]:grow gap-1"
|
|
1114
|
+
}, onCancel && !readonly && /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
1115
|
+
"data-testid": "cancel-button",
|
|
1116
|
+
icon: "ph--x--regular",
|
|
1117
|
+
label: t("button cancel"),
|
|
1118
|
+
onClick: onCancel
|
|
1119
|
+
}), handleSave && /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
1120
|
+
type: "submit",
|
|
1121
|
+
"data-testid": "save-button",
|
|
1122
|
+
disabled: !canSave,
|
|
1123
|
+
icon: "ph--check--regular",
|
|
1124
|
+
label: t("button save"),
|
|
1125
|
+
onClick: handleSave
|
|
1126
|
+
}));
|
|
1127
|
+
} finally {
|
|
1128
|
+
_effect.f();
|
|
1129
|
+
}
|
|
1000
1130
|
};
|
|
1001
1131
|
|
|
1002
1132
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
1133
|
+
import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
|
|
1003
1134
|
import { Schema, SchemaAST as SchemaAST4, pipe as pipe2 } from "effect";
|
|
1004
1135
|
import { capitalize as capitalize2 } from "effect/String";
|
|
1005
1136
|
import React12, { useMemo as useMemo5 } from "react";
|
|
1006
1137
|
import { createJsonPath as createJsonPath3, findNode as findNode3, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
1007
|
-
import { mx as mx7 } from "@dxos/react-ui-theme";
|
|
1008
1138
|
import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
|
|
1009
1139
|
import { isNotFalsy } from "@dxos/util";
|
|
1010
1140
|
|
|
1011
1141
|
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
1142
|
+
import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
|
|
1012
1143
|
import { SchemaAST as SchemaAST3, pipe } from "effect";
|
|
1013
1144
|
import { capitalize } from "effect/String";
|
|
1014
|
-
import React10, { useCallback as
|
|
1145
|
+
import React10, { Fragment, useCallback as useCallback7 } from "react";
|
|
1015
1146
|
import { findNode as findNode2, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
1016
1147
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1017
|
-
import { IconButton as IconButton3, useTranslation as
|
|
1018
|
-
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
1148
|
+
import { IconButton as IconButton3, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1019
1149
|
import { getSchemaProperties } from "@dxos/schema";
|
|
1020
1150
|
|
|
1021
1151
|
// packages/ui/react-ui-form/src/util/field.ts
|
|
@@ -1327,238 +1457,262 @@ var getRefProps = (property) => {
|
|
|
1327
1457
|
|
|
1328
1458
|
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
1329
1459
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
1330
|
-
var padding = "px-2";
|
|
1331
1460
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
const
|
|
1348
|
-
const
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
prop
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1461
|
+
var _effect = _useSignals10();
|
|
1462
|
+
try {
|
|
1463
|
+
const { t } = useTranslation6(translationKey);
|
|
1464
|
+
const { ast, name, type, title } = property;
|
|
1465
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
1466
|
+
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1467
|
+
F: __dxlog_file3,
|
|
1468
|
+
L: 36,
|
|
1469
|
+
S: void 0,
|
|
1470
|
+
A: [
|
|
1471
|
+
"Array.isArray(values)",
|
|
1472
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1473
|
+
]
|
|
1474
|
+
});
|
|
1475
|
+
const label = title ?? pipe(name, capitalize);
|
|
1476
|
+
const elementType = findArrayElementType(ast);
|
|
1477
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1478
|
+
const baseNode = findNode2(typeNode, isDiscriminatedUnion);
|
|
1479
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
|
|
1480
|
+
if (!typeLiteral) {
|
|
1481
|
+
return {};
|
|
1482
|
+
}
|
|
1483
|
+
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
|
|
1484
|
+
prop.name,
|
|
1485
|
+
prop.defaultValue
|
|
1486
|
+
]));
|
|
1487
|
+
};
|
|
1488
|
+
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
1489
|
+
const handleAdd = useCallback7(() => {
|
|
1490
|
+
inputProps.onValueChange(type, [
|
|
1491
|
+
...values,
|
|
1492
|
+
getDefaultValue()
|
|
1493
|
+
]);
|
|
1494
|
+
}, [
|
|
1495
|
+
type,
|
|
1496
|
+
elementType,
|
|
1497
|
+
inputProps,
|
|
1498
|
+
values
|
|
1362
1499
|
]);
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1500
|
+
const handleRemove = useCallback7((index) => {
|
|
1501
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
1502
|
+
inputProps.onValueChange(type, newValues);
|
|
1503
|
+
}, [
|
|
1504
|
+
type,
|
|
1505
|
+
inputProps,
|
|
1506
|
+
values
|
|
1507
|
+
]);
|
|
1508
|
+
if (!elementType) {
|
|
1509
|
+
return null;
|
|
1510
|
+
}
|
|
1511
|
+
return readonly && values.length < 1 ? null : /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
1512
|
+
role: "none",
|
|
1513
|
+
className: readonly ? "flex flex-wrap gap-1 mlb-1" : values.length > 0 ? "grid gap-1 grid-cols-[1fr_min-content] mlb-1" : "hidden"
|
|
1514
|
+
}, values.map((_value, index) => {
|
|
1515
|
+
const field = /* @__PURE__ */ React10.createElement(FormField, {
|
|
1516
|
+
property: {
|
|
1517
|
+
...property,
|
|
1518
|
+
array: false,
|
|
1519
|
+
ast: elementType
|
|
1520
|
+
},
|
|
1521
|
+
path: [
|
|
1522
|
+
...path ?? [],
|
|
1523
|
+
index
|
|
1524
|
+
],
|
|
1525
|
+
readonly,
|
|
1526
|
+
inline: true,
|
|
1527
|
+
Custom,
|
|
1528
|
+
lookupComponent
|
|
1529
|
+
});
|
|
1530
|
+
return readonly ? field : /* @__PURE__ */ React10.createElement(Fragment, {
|
|
1531
|
+
key: index
|
|
1532
|
+
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1533
|
+
role: "none"
|
|
1534
|
+
}, field), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1535
|
+
icon: "ph--trash--regular",
|
|
1536
|
+
iconOnly: true,
|
|
1537
|
+
label: t("button remove"),
|
|
1538
|
+
onClick: () => handleRemove(index),
|
|
1539
|
+
classNames: "self-center"
|
|
1540
|
+
}));
|
|
1541
|
+
})), !readonly && /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1542
|
+
classNames: "is-full mlb-1 flex",
|
|
1543
|
+
icon: "ph--plus--regular",
|
|
1544
|
+
label: t("add field"),
|
|
1545
|
+
onClick: handleAdd
|
|
1546
|
+
}));
|
|
1547
|
+
} finally {
|
|
1548
|
+
_effect.f();
|
|
1379
1549
|
}
|
|
1380
|
-
return /* @__PURE__ */ React10.createElement("div", {
|
|
1381
|
-
role: "none",
|
|
1382
|
-
className: mx6(padding)
|
|
1383
|
-
}, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
1384
|
-
role: "none",
|
|
1385
|
-
className: "flex flex-col gap-1"
|
|
1386
|
-
}, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
|
|
1387
|
-
key: index,
|
|
1388
|
-
role: "none",
|
|
1389
|
-
className: "flex items-center gap-1"
|
|
1390
|
-
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1391
|
-
role: "none",
|
|
1392
|
-
className: "flex-1"
|
|
1393
|
-
}, /* @__PURE__ */ React10.createElement(FormField, {
|
|
1394
|
-
property: {
|
|
1395
|
-
...property,
|
|
1396
|
-
array: false,
|
|
1397
|
-
ast: elementType
|
|
1398
|
-
},
|
|
1399
|
-
path: [
|
|
1400
|
-
...path ?? [],
|
|
1401
|
-
index
|
|
1402
|
-
],
|
|
1403
|
-
readonly,
|
|
1404
|
-
inline: true,
|
|
1405
|
-
Custom,
|
|
1406
|
-
lookupComponent
|
|
1407
|
-
})), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1408
|
-
icon: "ph--trash--regular",
|
|
1409
|
-
iconOnly: true,
|
|
1410
|
-
label: t("button remove"),
|
|
1411
|
-
onClick: () => handleRemove(index)
|
|
1412
|
-
})))), /* @__PURE__ */ React10.createElement("div", {
|
|
1413
|
-
role: "none",
|
|
1414
|
-
className: "flex justify-between items-center plb-1"
|
|
1415
|
-
}, /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1416
|
-
icon: "ph--plus--regular",
|
|
1417
|
-
iconOnly: true,
|
|
1418
|
-
label: t("button add"),
|
|
1419
|
-
onClick: handleAdd
|
|
1420
|
-
})));
|
|
1421
1550
|
};
|
|
1422
1551
|
|
|
1423
1552
|
// packages/ui/react-ui-form/src/components/Form/RefField.tsx
|
|
1424
|
-
import
|
|
1553
|
+
import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
|
|
1554
|
+
import React11, { useCallback as useCallback8, useMemo as useMemo4 } from "react";
|
|
1425
1555
|
import { Expando, getTypeAnnotation, Ref, ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo-schema";
|
|
1426
1556
|
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
1427
1557
|
import { DXN } from "@dxos/keys";
|
|
1428
|
-
import {
|
|
1558
|
+
import { DxRefTag } from "@dxos/lit-ui/react";
|
|
1559
|
+
import { Input as Input7, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1429
1560
|
import { TagPicker } from "@dxos/react-ui-tag-picker";
|
|
1561
|
+
import { descriptionText, mx as mx5 } from "@dxos/react-ui-theme";
|
|
1430
1562
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1431
1563
|
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
type,
|
|
1442
|
-
label,
|
|
1443
|
-
placeholder,
|
|
1444
|
-
disabled,
|
|
1445
|
-
inputOnly,
|
|
1446
|
-
getValue: getValue3,
|
|
1447
|
-
onBlur,
|
|
1448
|
-
onValueChange,
|
|
1449
|
-
...restInputProps
|
|
1564
|
+
var _effect = _useSignals11();
|
|
1565
|
+
try {
|
|
1566
|
+
const { t } = useTranslation7(translationKey);
|
|
1567
|
+
const refTypeInfo = useMemo4(() => ast ? findAnnotation2(ast, ReferenceAnnotationId2) : void 0, [
|
|
1568
|
+
ast
|
|
1569
|
+
]);
|
|
1570
|
+
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1571
|
+
refTypeInfo,
|
|
1572
|
+
onQueryRefOptions
|
|
1450
1573
|
});
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1574
|
+
if (refTypeInfo && refTypeInfo?.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
|
|
1575
|
+
return /* @__PURE__ */ React11.createElement(RefFieldFallback, {
|
|
1576
|
+
type,
|
|
1577
|
+
label,
|
|
1578
|
+
placeholder,
|
|
1579
|
+
disabled,
|
|
1580
|
+
inputOnly,
|
|
1581
|
+
getValue: getValue3,
|
|
1582
|
+
onBlur,
|
|
1583
|
+
onValueChange,
|
|
1584
|
+
...restInputProps
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
const handleGetValue = useCallback8(() => {
|
|
1588
|
+
const formValue = getValue3();
|
|
1589
|
+
const unknownToRefOption = (val) => {
|
|
1590
|
+
if (Ref.isRef(val)) {
|
|
1591
|
+
const dxnString = val.dxn.toString();
|
|
1592
|
+
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1593
|
+
if (matchingOption) {
|
|
1594
|
+
return matchingOption;
|
|
1595
|
+
}
|
|
1460
1596
|
}
|
|
1597
|
+
return void 0;
|
|
1598
|
+
};
|
|
1599
|
+
if (array && Array.isArray(formValue)) {
|
|
1600
|
+
return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
|
|
1461
1601
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
const option = unknownToRefOption(formValue);
|
|
1468
|
-
if (option) {
|
|
1469
|
-
return [
|
|
1470
|
-
option
|
|
1471
|
-
];
|
|
1472
|
-
}
|
|
1473
|
-
return [];
|
|
1474
|
-
}, [
|
|
1475
|
-
getValue3,
|
|
1476
|
-
availableOptions,
|
|
1477
|
-
array
|
|
1478
|
-
]);
|
|
1479
|
-
const handleSearch = useCallback7((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1480
|
-
id: option.id,
|
|
1481
|
-
label: option.label,
|
|
1482
|
-
hue: option.hue
|
|
1483
|
-
})), [
|
|
1484
|
-
availableOptions
|
|
1485
|
-
]);
|
|
1486
|
-
const handleUpdate = useCallback7((ids) => {
|
|
1487
|
-
if (ids.length === 0) {
|
|
1488
|
-
onValueChange("object", void 0);
|
|
1489
|
-
return;
|
|
1490
|
-
}
|
|
1491
|
-
const refs = ids.map((id) => {
|
|
1492
|
-
const item = availableOptions.find((option) => option.id === id);
|
|
1493
|
-
if (item) {
|
|
1494
|
-
const dxn = DXN.parse(item.id);
|
|
1495
|
-
return Ref.fromDXN(dxn);
|
|
1602
|
+
const option = unknownToRefOption(formValue);
|
|
1603
|
+
if (option) {
|
|
1604
|
+
return [
|
|
1605
|
+
option
|
|
1606
|
+
];
|
|
1496
1607
|
}
|
|
1608
|
+
return [];
|
|
1609
|
+
}, [
|
|
1610
|
+
getValue3,
|
|
1611
|
+
availableOptions,
|
|
1612
|
+
array
|
|
1613
|
+
]);
|
|
1614
|
+
const handleSearch = useCallback8((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1615
|
+
id: option.id,
|
|
1616
|
+
label: option.label,
|
|
1617
|
+
hue: option.hue
|
|
1618
|
+
})), [
|
|
1619
|
+
availableOptions
|
|
1620
|
+
]);
|
|
1621
|
+
const handleUpdate = useCallback8((ids) => {
|
|
1622
|
+
if (ids.length === 0) {
|
|
1623
|
+
onValueChange("object", void 0);
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
const refs = ids.map((id) => {
|
|
1627
|
+
const item = availableOptions.find((option) => option.id === id);
|
|
1628
|
+
if (item) {
|
|
1629
|
+
const dxn = DXN.parse(item.id);
|
|
1630
|
+
return Ref.fromDXN(dxn);
|
|
1631
|
+
}
|
|
1632
|
+
return null;
|
|
1633
|
+
}).filter(isNonNullable2);
|
|
1634
|
+
if (array) {
|
|
1635
|
+
onValueChange("object", refs);
|
|
1636
|
+
} else {
|
|
1637
|
+
onValueChange("object", refs[0]);
|
|
1638
|
+
}
|
|
1639
|
+
}, [
|
|
1640
|
+
availableOptions,
|
|
1641
|
+
array,
|
|
1642
|
+
onValueChange
|
|
1643
|
+
]);
|
|
1644
|
+
const tagPickerMode = useMemo4(() => array ? "multi-select" : "single-select", [
|
|
1645
|
+
array
|
|
1646
|
+
]);
|
|
1647
|
+
if (!refTypeInfo) {
|
|
1497
1648
|
return null;
|
|
1498
|
-
}).filter(isNonNullable2);
|
|
1499
|
-
if (array) {
|
|
1500
|
-
onValueChange("object", refs);
|
|
1501
|
-
} else {
|
|
1502
|
-
onValueChange("object", refs[0]);
|
|
1503
1649
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1650
|
+
const { status, error } = restInputProps.getStatus();
|
|
1651
|
+
const items = handleGetValue();
|
|
1652
|
+
return disabled && items.length < 1 ? null : /* @__PURE__ */ React11.createElement(Input7.Root, {
|
|
1653
|
+
validationValence: status
|
|
1654
|
+
}, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
|
|
1655
|
+
error
|
|
1656
|
+
}, /* @__PURE__ */ React11.createElement(Input7.Label, null, label)), /* @__PURE__ */ React11.createElement("div", {
|
|
1657
|
+
"data-no-submit": true
|
|
1658
|
+
}, disabled ? items.length < 1 ? /* @__PURE__ */ React11.createElement("p", {
|
|
1659
|
+
className: mx5(descriptionText, "mbe-2")
|
|
1660
|
+
}, t("empty readonly ref field label")) : items.map((item) => /* @__PURE__ */ React11.createElement(DxRefTag, {
|
|
1661
|
+
key: item.id,
|
|
1662
|
+
refid: item.id,
|
|
1663
|
+
rootclassname: "mie-1",
|
|
1664
|
+
style: {
|
|
1665
|
+
marginInlineEnd: ".25rem"
|
|
1666
|
+
}
|
|
1667
|
+
}, item.label)) : /* @__PURE__ */ React11.createElement(TagPicker, {
|
|
1668
|
+
readonly: disabled,
|
|
1669
|
+
items,
|
|
1670
|
+
mode: tagPickerMode,
|
|
1671
|
+
onBlur: (event) => onBlur(event),
|
|
1672
|
+
onUpdate: handleUpdate,
|
|
1673
|
+
onSearch: handleSearch,
|
|
1674
|
+
classNames: "rounded-sm bg-inputSurface p-1.5"
|
|
1675
|
+
})), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1676
|
+
} finally {
|
|
1677
|
+
_effect.f();
|
|
1514
1678
|
}
|
|
1515
|
-
const { status, error } = restInputProps.getStatus();
|
|
1516
|
-
return /* @__PURE__ */ React11.createElement(Input7.Root, {
|
|
1517
|
-
validationValence: status
|
|
1518
|
-
}, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
|
|
1519
|
-
error
|
|
1520
|
-
}, /* @__PURE__ */ React11.createElement(Input7.Label, null, label)), /* @__PURE__ */ React11.createElement("div", {
|
|
1521
|
-
"data-no-submit": true
|
|
1522
|
-
}, /* @__PURE__ */ React11.createElement(TagPicker, {
|
|
1523
|
-
items: handleGetValue(),
|
|
1524
|
-
mode: tagPickerMode,
|
|
1525
|
-
onBlur: (event) => onBlur(event),
|
|
1526
|
-
onUpdate: handleUpdate,
|
|
1527
|
-
onSearch: handleSearch,
|
|
1528
|
-
classNames: "rounded-sm bg-input p-1.5"
|
|
1529
|
-
})), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1530
1679
|
};
|
|
1531
1680
|
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1681
|
+
var _effect = _useSignals11();
|
|
1682
|
+
try {
|
|
1683
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1684
|
+
const dxn = DXN.tryParse(dxnString);
|
|
1685
|
+
if (dxn) {
|
|
1686
|
+
onValueChange?.("object", Ref.fromDXN(dxn));
|
|
1687
|
+
} else if (dxnString === "") {
|
|
1688
|
+
onValueChange?.("object", void 0);
|
|
1689
|
+
} else {
|
|
1690
|
+
onValueChange?.("string", dxnString);
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
const handleGetValue = () => {
|
|
1694
|
+
const formValue = getValue3();
|
|
1695
|
+
if (typeof formValue === "string") {
|
|
1696
|
+
return formValue;
|
|
1697
|
+
}
|
|
1698
|
+
if (Ref.isRef(formValue)) {
|
|
1699
|
+
return formValue.dxn.toString();
|
|
1700
|
+
}
|
|
1701
|
+
return void 0;
|
|
1702
|
+
};
|
|
1703
|
+
return /* @__PURE__ */ React11.createElement(TextInput, {
|
|
1704
|
+
type,
|
|
1705
|
+
label,
|
|
1706
|
+
disabled,
|
|
1707
|
+
placeholder,
|
|
1708
|
+
inputOnly,
|
|
1709
|
+
getValue: handleGetValue,
|
|
1710
|
+
onValueChange: handleOnValueChange,
|
|
1711
|
+
...restInputProps
|
|
1712
|
+
});
|
|
1713
|
+
} finally {
|
|
1714
|
+
_effect.f();
|
|
1715
|
+
}
|
|
1562
1716
|
};
|
|
1563
1717
|
|
|
1564
1718
|
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
@@ -1582,570 +1736,612 @@ var getInputComponent = (type, format) => {
|
|
|
1582
1736
|
|
|
1583
1737
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
1584
1738
|
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
title,
|
|
1589
|
-
name
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
description
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
return /* @__PURE__ */ React12.createElement("div", {
|
|
1609
|
-
role: "none"
|
|
1610
|
-
}, FoundComponent);
|
|
1611
|
-
}
|
|
1612
|
-
const jsonPath = createJsonPath3(path ?? []);
|
|
1613
|
-
const CustomComponent = Custom?.[jsonPath];
|
|
1614
|
-
if (CustomComponent) {
|
|
1615
|
-
return /* @__PURE__ */ React12.createElement(CustomComponent, {
|
|
1616
|
-
type,
|
|
1617
|
-
format,
|
|
1618
|
-
label,
|
|
1619
|
-
inputOnly: inline,
|
|
1620
|
-
placeholder,
|
|
1621
|
-
disabled: readonly,
|
|
1622
|
-
...inputProps
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
const refProps = getRefProps(property);
|
|
1626
|
-
if (refProps) {
|
|
1627
|
-
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1628
|
-
ast: refProps.ast,
|
|
1629
|
-
array: refProps.isArray,
|
|
1630
|
-
type,
|
|
1631
|
-
format,
|
|
1632
|
-
label,
|
|
1633
|
-
placeholder,
|
|
1634
|
-
disabled: readonly,
|
|
1635
|
-
inputOnly: inline,
|
|
1636
|
-
onQueryRefOptions,
|
|
1637
|
-
...inputProps
|
|
1638
|
-
});
|
|
1639
|
-
}
|
|
1640
|
-
if (array) {
|
|
1641
|
-
return /* @__PURE__ */ React12.createElement(ArrayField, {
|
|
1642
|
-
property,
|
|
1643
|
-
path,
|
|
1644
|
-
inputProps,
|
|
1645
|
-
readonly,
|
|
1646
|
-
Custom
|
|
1739
|
+
var _effect = _useSignals12();
|
|
1740
|
+
try {
|
|
1741
|
+
const inputProps = useInputProps(path);
|
|
1742
|
+
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1743
|
+
const label = useMemo5(() => title ?? pipe2(name, capitalize2), [
|
|
1744
|
+
title,
|
|
1745
|
+
name
|
|
1746
|
+
]);
|
|
1747
|
+
const placeholder = useMemo5(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1748
|
+
examples,
|
|
1749
|
+
description
|
|
1750
|
+
]);
|
|
1751
|
+
const FoundComponent = lookupComponent?.({
|
|
1752
|
+
prop: name,
|
|
1753
|
+
schema: Schema.make(ast),
|
|
1754
|
+
inputProps: {
|
|
1755
|
+
type,
|
|
1756
|
+
format,
|
|
1757
|
+
label,
|
|
1758
|
+
disabled: readonly,
|
|
1759
|
+
placeholder,
|
|
1760
|
+
...inputProps
|
|
1761
|
+
}
|
|
1647
1762
|
});
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode3(ast, SchemaAST4.isTypeLiteral);
|
|
1683
|
-
if (typeLiteral) {
|
|
1684
|
-
return /* @__PURE__ */ React12.createElement("div", {
|
|
1685
|
-
role: "none"
|
|
1686
|
-
}, !inline && /* @__PURE__ */ React12.createElement("h3", {
|
|
1687
|
-
className: "text-lg mbs-2 mbe-1"
|
|
1688
|
-
}, label), /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1689
|
-
schema: Schema.make(typeLiteral),
|
|
1763
|
+
if (FoundComponent) {
|
|
1764
|
+
return FoundComponent;
|
|
1765
|
+
}
|
|
1766
|
+
const jsonPath = createJsonPath3(path ?? []);
|
|
1767
|
+
const CustomComponent = Custom?.[jsonPath];
|
|
1768
|
+
if (CustomComponent) {
|
|
1769
|
+
return /* @__PURE__ */ React12.createElement(CustomComponent, {
|
|
1770
|
+
type,
|
|
1771
|
+
format,
|
|
1772
|
+
label,
|
|
1773
|
+
inputOnly: inline,
|
|
1774
|
+
placeholder,
|
|
1775
|
+
disabled: readonly,
|
|
1776
|
+
...inputProps
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
const refProps = getRefProps(property);
|
|
1780
|
+
if (refProps) {
|
|
1781
|
+
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1782
|
+
ast: refProps.ast,
|
|
1783
|
+
array: refProps.isArray,
|
|
1784
|
+
type,
|
|
1785
|
+
format,
|
|
1786
|
+
label,
|
|
1787
|
+
placeholder,
|
|
1788
|
+
disabled: readonly,
|
|
1789
|
+
inputOnly: inline,
|
|
1790
|
+
onQueryRefOptions,
|
|
1791
|
+
...inputProps
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
if (array) {
|
|
1795
|
+
return /* @__PURE__ */ React12.createElement(ArrayField, {
|
|
1796
|
+
property,
|
|
1690
1797
|
path,
|
|
1798
|
+
inputProps,
|
|
1691
1799
|
readonly,
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1800
|
+
Custom
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
const InputComponent = getInputComponent(type, format);
|
|
1804
|
+
if (InputComponent) {
|
|
1805
|
+
return /* @__PURE__ */ React12.createElement(InputComponent, {
|
|
1806
|
+
type,
|
|
1807
|
+
format,
|
|
1808
|
+
label,
|
|
1809
|
+
inputOnly: inline,
|
|
1810
|
+
placeholder,
|
|
1811
|
+
disabled: readonly,
|
|
1812
|
+
...inputProps
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
if (options) {
|
|
1816
|
+
return /* @__PURE__ */ React12.createElement(SelectInput, {
|
|
1817
|
+
type,
|
|
1818
|
+
format,
|
|
1819
|
+
disabled: readonly,
|
|
1820
|
+
inputOnly: inline,
|
|
1821
|
+
label,
|
|
1822
|
+
options: options.map((option) => ({
|
|
1823
|
+
value: option,
|
|
1824
|
+
label: String(option)
|
|
1825
|
+
})),
|
|
1826
|
+
placeholder,
|
|
1827
|
+
...inputProps
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
if (type === "object") {
|
|
1831
|
+
const baseNode = findNode3(ast, isDiscriminatedUnion2);
|
|
1832
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode3(ast, SchemaAST4.isTypeLiteral);
|
|
1833
|
+
if (typeLiteral) {
|
|
1834
|
+
return /* @__PURE__ */ React12.createElement(React12.Fragment, null, !inline && /* @__PURE__ */ React12.createElement("h3", {
|
|
1835
|
+
className: "text-lg mbs-2 mbe-1 first:mbs-0"
|
|
1836
|
+
}, label), /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1837
|
+
schema: Schema.make(typeLiteral),
|
|
1838
|
+
path,
|
|
1839
|
+
readonly,
|
|
1840
|
+
onQueryRefOptions,
|
|
1841
|
+
Custom,
|
|
1842
|
+
lookupComponent
|
|
1843
|
+
}));
|
|
1844
|
+
}
|
|
1696
1845
|
}
|
|
1846
|
+
return null;
|
|
1847
|
+
} finally {
|
|
1848
|
+
_effect.f();
|
|
1697
1849
|
}
|
|
1698
|
-
return null;
|
|
1699
1850
|
};
|
|
1700
1851
|
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
const
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1852
|
+
var _effect = _useSignals12();
|
|
1853
|
+
try {
|
|
1854
|
+
const values = useFormValues(path);
|
|
1855
|
+
const properties = useMemo5(() => {
|
|
1856
|
+
const props = getSchemaProperties2(schema.ast, values);
|
|
1857
|
+
const filtered = filter ? filter(props) : props;
|
|
1858
|
+
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
1859
|
+
}, [
|
|
1860
|
+
schema,
|
|
1861
|
+
values,
|
|
1862
|
+
filter,
|
|
1863
|
+
sort
|
|
1864
|
+
]);
|
|
1865
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1866
|
+
role: "form",
|
|
1867
|
+
className: "is-full"
|
|
1868
|
+
}, properties.map((property) => {
|
|
1869
|
+
return /* @__PURE__ */ React12.createElement(FormField, {
|
|
1870
|
+
key: property.name,
|
|
1871
|
+
property,
|
|
1872
|
+
path: [
|
|
1873
|
+
...path ?? [],
|
|
1874
|
+
property.name
|
|
1875
|
+
],
|
|
1876
|
+
readonly,
|
|
1877
|
+
onQueryRefOptions,
|
|
1878
|
+
lookupComponent,
|
|
1879
|
+
Custom
|
|
1880
|
+
});
|
|
1881
|
+
}).filter(isNotFalsy));
|
|
1882
|
+
} finally {
|
|
1883
|
+
_effect.f();
|
|
1884
|
+
}
|
|
1729
1885
|
};
|
|
1730
1886
|
|
|
1731
1887
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
1732
1888
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
onSave
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
if (
|
|
1742
|
-
input.
|
|
1889
|
+
var _effect = _useSignals13();
|
|
1890
|
+
try {
|
|
1891
|
+
const formRef = useRef3(null);
|
|
1892
|
+
const onValid = useMemo6(() => autoSave ? onSave : void 0, [
|
|
1893
|
+
autoSave,
|
|
1894
|
+
onSave
|
|
1895
|
+
]);
|
|
1896
|
+
useEffect7(() => {
|
|
1897
|
+
if (autoFocus && formRef.current) {
|
|
1898
|
+
const input = formRef.current.querySelector("input");
|
|
1899
|
+
if (input) {
|
|
1900
|
+
input.focus();
|
|
1901
|
+
}
|
|
1743
1902
|
}
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
}
|
|
1903
|
+
}, [
|
|
1904
|
+
autoFocus
|
|
1905
|
+
]);
|
|
1906
|
+
return /* @__PURE__ */ React13.createElement(FormProvider, {
|
|
1907
|
+
formRef,
|
|
1908
|
+
schema,
|
|
1909
|
+
autoSave,
|
|
1910
|
+
initialValues,
|
|
1911
|
+
onValuesChanged,
|
|
1912
|
+
onValidate,
|
|
1913
|
+
onValid,
|
|
1914
|
+
onSave
|
|
1915
|
+
}, /* @__PURE__ */ React13.createElement("div", {
|
|
1916
|
+
ref: formRef,
|
|
1917
|
+
role: "none",
|
|
1918
|
+
className: mx6("flex flex-col gap-4", classNames),
|
|
1919
|
+
"data-testid": testId
|
|
1920
|
+
}, /* @__PURE__ */ React13.createElement(FormFields, {
|
|
1921
|
+
schema,
|
|
1922
|
+
path,
|
|
1923
|
+
readonly,
|
|
1924
|
+
filter,
|
|
1925
|
+
sort,
|
|
1926
|
+
onQueryRefOptions,
|
|
1927
|
+
lookupComponent,
|
|
1928
|
+
Custom
|
|
1929
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React13.createElement(FormActions, {
|
|
1930
|
+
onCancel,
|
|
1931
|
+
readonly
|
|
1932
|
+
})));
|
|
1933
|
+
} finally {
|
|
1934
|
+
_effect.f();
|
|
1935
|
+
}
|
|
1775
1936
|
};
|
|
1776
1937
|
|
|
1777
1938
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
1778
1939
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1779
1940
|
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
field
|
|
1784
|
-
projection
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
fire: true
|
|
1793
|
-
});
|
|
1794
|
-
const t2 = setTimeout(async () => {
|
|
1795
|
-
const schemas2 = await registry.query().run();
|
|
1796
|
-
setSchemas(schemas2);
|
|
1797
|
-
});
|
|
1798
|
-
return () => {
|
|
1799
|
-
clearTimeout(t2);
|
|
1800
|
-
subscription?.();
|
|
1801
|
-
};
|
|
1802
|
-
}, [
|
|
1803
|
-
registry
|
|
1804
|
-
]);
|
|
1805
|
-
const [referenceSchema, setReferenceSchema] = useState5();
|
|
1806
|
-
useEffect8(() => {
|
|
1807
|
-
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1808
|
-
}, [
|
|
1809
|
-
schemas,
|
|
1810
|
-
props?.referenceSchema
|
|
1811
|
-
]);
|
|
1812
|
-
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
1813
|
-
fieldSchema: getFormatSchema(props?.format)
|
|
1814
|
-
});
|
|
1815
|
-
const handleValuesChanged = useCallback8((_props) => {
|
|
1816
|
-
setFieldSchema((prev) => {
|
|
1817
|
-
const fieldSchema2 = getFormatSchema(_props.format);
|
|
1818
|
-
if (prev.fieldSchema === fieldSchema2) {
|
|
1819
|
-
return prev;
|
|
1941
|
+
var _effect = _useSignals14();
|
|
1942
|
+
try {
|
|
1943
|
+
const { t } = useTranslation8(translationKey);
|
|
1944
|
+
const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
|
|
1945
|
+
useEffect8(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1946
|
+
field,
|
|
1947
|
+
projection
|
|
1948
|
+
]);
|
|
1949
|
+
const [schemas, setSchemas] = useState5([]);
|
|
1950
|
+
useEffect8(() => {
|
|
1951
|
+
if (!registry) {
|
|
1952
|
+
return;
|
|
1820
1953
|
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1954
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
1955
|
+
fire: true
|
|
1956
|
+
});
|
|
1957
|
+
const t2 = setTimeout(async () => {
|
|
1958
|
+
const schemas2 = await registry.query().run();
|
|
1959
|
+
setSchemas(schemas2);
|
|
1960
|
+
});
|
|
1961
|
+
return () => {
|
|
1962
|
+
clearTimeout(t2);
|
|
1963
|
+
subscription?.();
|
|
1823
1964
|
};
|
|
1965
|
+
}, [
|
|
1966
|
+
registry
|
|
1967
|
+
]);
|
|
1968
|
+
const [referenceSchema, setReferenceSchema] = useState5();
|
|
1969
|
+
useEffect8(() => {
|
|
1970
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1971
|
+
}, [
|
|
1972
|
+
schemas,
|
|
1973
|
+
props?.referenceSchema
|
|
1974
|
+
]);
|
|
1975
|
+
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
1976
|
+
fieldSchema: getFormatSchema(props?.format)
|
|
1824
1977
|
});
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
const
|
|
1828
|
-
if (
|
|
1829
|
-
return
|
|
1978
|
+
const handleValuesChanged = useCallback9((_props) => {
|
|
1979
|
+
setFieldSchema((prev) => {
|
|
1980
|
+
const fieldSchema2 = getFormatSchema(_props.format);
|
|
1981
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
1982
|
+
return prev;
|
|
1830
1983
|
}
|
|
1831
|
-
}
|
|
1832
|
-
return prev;
|
|
1833
|
-
});
|
|
1834
|
-
setProps((props2) => {
|
|
1835
|
-
const type = formatToType[_props.format];
|
|
1836
|
-
if (props2.type !== type) {
|
|
1837
1984
|
return {
|
|
1838
|
-
|
|
1839
|
-
..._props,
|
|
1840
|
-
type
|
|
1985
|
+
fieldSchema: fieldSchema2
|
|
1841
1986
|
};
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
]);
|
|
1850
|
-
const handleValidate = useCallback8(({ property }) => {
|
|
1851
|
-
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
1852
|
-
return [
|
|
1853
|
-
{
|
|
1854
|
-
path: "property",
|
|
1855
|
-
message: `property is not unique: '${property}'`
|
|
1987
|
+
});
|
|
1988
|
+
setReferenceSchema((prev) => {
|
|
1989
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
1990
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
1991
|
+
if (newSchema) {
|
|
1992
|
+
return newSchema;
|
|
1993
|
+
}
|
|
1856
1994
|
}
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1995
|
+
return prev;
|
|
1996
|
+
});
|
|
1997
|
+
setProps((props2) => {
|
|
1998
|
+
const type = formatToType[_props.format];
|
|
1999
|
+
if (props2.type !== type) {
|
|
2000
|
+
return {
|
|
2001
|
+
...props2,
|
|
2002
|
+
..._props,
|
|
2003
|
+
type
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
return _props;
|
|
2007
|
+
});
|
|
2008
|
+
}, [
|
|
2009
|
+
schemas,
|
|
2010
|
+
props.format,
|
|
2011
|
+
props.referenceSchema
|
|
2012
|
+
]);
|
|
2013
|
+
const handleValidate = useCallback9(({ property }) => {
|
|
2014
|
+
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
2015
|
+
return [
|
|
2016
|
+
{
|
|
2017
|
+
path: "property",
|
|
2018
|
+
message: `property is not unique: '${property}'`
|
|
2019
|
+
}
|
|
2020
|
+
];
|
|
2021
|
+
}
|
|
2022
|
+
}, [
|
|
2023
|
+
view.fields,
|
|
2024
|
+
field
|
|
2025
|
+
]);
|
|
2026
|
+
const handleSave = useCallback9((props2) => {
|
|
2027
|
+
projection.setFieldProjection({
|
|
2028
|
+
field,
|
|
2029
|
+
props: props2
|
|
2030
|
+
});
|
|
2031
|
+
onSave();
|
|
2032
|
+
}, [
|
|
2033
|
+
projection,
|
|
1865
2034
|
field,
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
2035
|
+
onSave
|
|
2036
|
+
]);
|
|
2037
|
+
const handleCancel = useCallback9(() => {
|
|
2038
|
+
requestAnimationFrame(() => onCancel?.());
|
|
2039
|
+
onSave();
|
|
2040
|
+
}, [
|
|
2041
|
+
onSave
|
|
2042
|
+
]);
|
|
2043
|
+
const custom = useMemo7(() => ({
|
|
2044
|
+
["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2045
|
+
...props2,
|
|
2046
|
+
options: FormatEnums.filter((value) => value !== FormatEnum5.None).map((value) => ({
|
|
2047
|
+
value,
|
|
2048
|
+
label: t(`format ${value}`)
|
|
2049
|
+
}))
|
|
2050
|
+
}),
|
|
2051
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2052
|
+
...props2,
|
|
2053
|
+
options: schemas.map((schema) => ({
|
|
2054
|
+
value: schema.typename
|
|
2055
|
+
}))
|
|
2056
|
+
}),
|
|
2057
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2058
|
+
...props2,
|
|
2059
|
+
options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
|
|
2060
|
+
value: p.name
|
|
2061
|
+
})) : []
|
|
2062
|
+
}),
|
|
2063
|
+
["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
|
|
2064
|
+
}), [
|
|
2065
|
+
t,
|
|
2066
|
+
schemas,
|
|
2067
|
+
referenceSchema
|
|
2068
|
+
]);
|
|
2069
|
+
const propIsNotType = useCallback9((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
2070
|
+
if (!fieldSchema) {
|
|
2071
|
+
log3.warn("invalid format", {
|
|
2072
|
+
props
|
|
2073
|
+
}, {
|
|
2074
|
+
F: __dxlog_file4,
|
|
2075
|
+
L: 175,
|
|
2076
|
+
S: void 0,
|
|
2077
|
+
C: (f, a) => f(...a)
|
|
2078
|
+
});
|
|
2079
|
+
return null;
|
|
2080
|
+
}
|
|
2081
|
+
return /* @__PURE__ */ React14.createElement(Form, {
|
|
2082
|
+
key: field.id,
|
|
2083
|
+
autoFocus: true,
|
|
2084
|
+
values: props,
|
|
2085
|
+
schema: fieldSchema,
|
|
2086
|
+
filter: propIsNotType,
|
|
2087
|
+
sort: [
|
|
2088
|
+
"property",
|
|
2089
|
+
"format"
|
|
2090
|
+
],
|
|
2091
|
+
onValuesChanged: handleValuesChanged,
|
|
2092
|
+
onValidate: handleValidate,
|
|
2093
|
+
onSave: handleSave,
|
|
2094
|
+
onCancel: handleCancel,
|
|
2095
|
+
Custom: custom
|
|
1915
2096
|
});
|
|
1916
|
-
|
|
2097
|
+
} finally {
|
|
2098
|
+
_effect.f();
|
|
1917
2099
|
}
|
|
1918
|
-
return /* @__PURE__ */ React14.createElement(Form, {
|
|
1919
|
-
key: field.id,
|
|
1920
|
-
autoFocus: true,
|
|
1921
|
-
values: props,
|
|
1922
|
-
schema: fieldSchema,
|
|
1923
|
-
filter: propIsNotType,
|
|
1924
|
-
sort: [
|
|
1925
|
-
"property",
|
|
1926
|
-
"format"
|
|
1927
|
-
],
|
|
1928
|
-
onValuesChanged: handleValuesChanged,
|
|
1929
|
-
onValidate: handleValidate,
|
|
1930
|
-
onSave: handleSave,
|
|
1931
|
-
onCancel: handleCancel,
|
|
1932
|
-
Custom
|
|
1933
|
-
});
|
|
1934
2100
|
};
|
|
1935
2101
|
|
|
1936
2102
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
1937
|
-
import {
|
|
1938
|
-
import
|
|
1939
|
-
import {
|
|
2103
|
+
import { useSignals as _useSignals15 } from "@preact-signals/safe-react/tracking";
|
|
2104
|
+
import { Schema as Schema2 } from "effect";
|
|
2105
|
+
import React15, { useCallback as useCallback10, useMemo as useMemo8, useState as useState6 } from "react";
|
|
2106
|
+
import { EchoSchema, Format, isMutable, toJsonSchema } from "@dxos/echo-schema";
|
|
1940
2107
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1941
|
-
import { IconButton as IconButton4, useTranslation as
|
|
2108
|
+
import { Icon as Icon3, IconButton as IconButton4, Message, useTranslation as useTranslation9 } from "@dxos/react-ui";
|
|
1942
2109
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
1943
|
-
import { ghostHover, inputTextLabel, mx as
|
|
2110
|
+
import { ghostHover, inputTextLabel, mx as mx7 } from "@dxos/react-ui-theme";
|
|
1944
2111
|
import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1945
2112
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1946
2113
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1947
2114
|
var ViewMetaSchema = Schema2.Struct({
|
|
1948
2115
|
name: Schema2.String.annotations({
|
|
1949
|
-
|
|
2116
|
+
title: "View"
|
|
1950
2117
|
}),
|
|
1951
2118
|
typename: Format.URL.annotations({
|
|
1952
|
-
|
|
2119
|
+
title: "Typename"
|
|
1953
2120
|
})
|
|
1954
2121
|
}).pipe(Schema2.mutable);
|
|
1955
2122
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
A: [
|
|
1982
|
-
"!immutable",
|
|
1983
|
-
""
|
|
1984
|
-
]
|
|
1985
|
-
});
|
|
1986
|
-
const field2 = projection.createFieldProjection();
|
|
1987
|
-
setField(field2);
|
|
1988
|
-
}, [
|
|
1989
|
-
schema,
|
|
1990
|
-
view
|
|
1991
|
-
]);
|
|
1992
|
-
const handleUpdate = useCallback9(({ name, typename }) => {
|
|
1993
|
-
invariant3(!immutable, void 0, {
|
|
1994
|
-
F: __dxlog_file5,
|
|
1995
|
-
L: 85,
|
|
1996
|
-
S: void 0,
|
|
1997
|
-
A: [
|
|
1998
|
-
"!immutable",
|
|
1999
|
-
""
|
|
2000
|
-
]
|
|
2001
|
-
});
|
|
2002
|
-
requestAnimationFrame(() => {
|
|
2003
|
-
if (view.name !== name) {
|
|
2004
|
-
view.name = name;
|
|
2123
|
+
var _effect = _useSignals15();
|
|
2124
|
+
try {
|
|
2125
|
+
const { t } = useTranslation9(translationKey);
|
|
2126
|
+
const projection = useMemo8(() => {
|
|
2127
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2128
|
+
return new ViewProjection(jsonSchema, view);
|
|
2129
|
+
}, [
|
|
2130
|
+
schema,
|
|
2131
|
+
view
|
|
2132
|
+
]);
|
|
2133
|
+
const [field, setField] = useState6();
|
|
2134
|
+
const immutable = readonly || !isMutable(schema);
|
|
2135
|
+
const viewValues = useMemo8(() => {
|
|
2136
|
+
return {
|
|
2137
|
+
name: view.name,
|
|
2138
|
+
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
2139
|
+
// TODO(burdon): Settings should have domain name owned by user.
|
|
2140
|
+
typename: view.query.typename
|
|
2141
|
+
};
|
|
2142
|
+
}, [
|
|
2143
|
+
view
|
|
2144
|
+
]);
|
|
2145
|
+
const handleSelect = useCallback10((field2) => {
|
|
2146
|
+
if (immutable) {
|
|
2147
|
+
return;
|
|
2005
2148
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2149
|
+
setField((f) => f === field2 ? void 0 : field2);
|
|
2150
|
+
}, [
|
|
2151
|
+
immutable
|
|
2152
|
+
]);
|
|
2153
|
+
const handleAdd = useCallback10(() => {
|
|
2154
|
+
invariant3(!immutable, void 0, {
|
|
2155
|
+
F: __dxlog_file5,
|
|
2156
|
+
L: 88,
|
|
2157
|
+
S: void 0,
|
|
2158
|
+
A: [
|
|
2159
|
+
"!immutable",
|
|
2160
|
+
""
|
|
2161
|
+
]
|
|
2162
|
+
});
|
|
2163
|
+
const field2 = projection.createFieldProjection();
|
|
2164
|
+
setField(field2);
|
|
2165
|
+
}, [
|
|
2166
|
+
schema,
|
|
2167
|
+
view
|
|
2168
|
+
]);
|
|
2169
|
+
const handleUpdate = useCallback10(({ name, typename }) => {
|
|
2170
|
+
invariant3(!immutable, void 0, {
|
|
2171
|
+
F: __dxlog_file5,
|
|
2172
|
+
L: 95,
|
|
2173
|
+
S: void 0,
|
|
2174
|
+
A: [
|
|
2175
|
+
"!immutable",
|
|
2176
|
+
""
|
|
2177
|
+
]
|
|
2178
|
+
});
|
|
2179
|
+
requestAnimationFrame(() => {
|
|
2180
|
+
if (view.name !== name) {
|
|
2181
|
+
view.name = name;
|
|
2182
|
+
}
|
|
2183
|
+
if (view.query.typename !== typename && !immutable) {
|
|
2184
|
+
onTypenameChanged?.(typename);
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
}, [
|
|
2188
|
+
schema,
|
|
2189
|
+
view,
|
|
2190
|
+
onTypenameChanged,
|
|
2191
|
+
immutable
|
|
2192
|
+
]);
|
|
2193
|
+
const handleDelete = useCallback10((fieldId) => {
|
|
2194
|
+
invariant3(!immutable, void 0, {
|
|
2195
|
+
F: __dxlog_file5,
|
|
2196
|
+
L: 111,
|
|
2197
|
+
S: void 0,
|
|
2198
|
+
A: [
|
|
2199
|
+
"!immutable",
|
|
2200
|
+
""
|
|
2201
|
+
]
|
|
2202
|
+
});
|
|
2203
|
+
if (fieldId === field?.id) {
|
|
2204
|
+
setField(void 0);
|
|
2008
2205
|
}
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2206
|
+
onDelete?.(fieldId);
|
|
2207
|
+
}, [
|
|
2208
|
+
schema,
|
|
2209
|
+
field,
|
|
2210
|
+
onDelete
|
|
2211
|
+
]);
|
|
2212
|
+
const handleMove = useCallback10((fromIndex, toIndex) => {
|
|
2213
|
+
invariant3(!immutable, void 0, {
|
|
2214
|
+
F: __dxlog_file5,
|
|
2215
|
+
L: 123,
|
|
2216
|
+
S: void 0,
|
|
2217
|
+
A: [
|
|
2218
|
+
"!immutable",
|
|
2219
|
+
""
|
|
2220
|
+
]
|
|
2221
|
+
});
|
|
2222
|
+
const fields = [
|
|
2223
|
+
...view.fields
|
|
2224
|
+
];
|
|
2225
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
2226
|
+
fields.splice(toIndex, 0, moved);
|
|
2227
|
+
view.fields = fields;
|
|
2228
|
+
}, [
|
|
2229
|
+
schema,
|
|
2230
|
+
view.fields
|
|
2231
|
+
]);
|
|
2232
|
+
const handleClose = useCallback10(() => setField(void 0), []);
|
|
2233
|
+
const hiddenProperties = projection.getHiddenProperties();
|
|
2234
|
+
const handleHide = useCallback10((fieldId) => {
|
|
2026
2235
|
setField(void 0);
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
projection,
|
|
2137
|
-
field,
|
|
2138
|
-
registry,
|
|
2139
|
-
onSave: handleClose
|
|
2140
|
-
}), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
|
|
2141
|
-
className: "flex p-2 justify-center"
|
|
2142
|
-
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
2143
|
-
icon: "ph--plus--regular",
|
|
2144
|
-
label: t("button add property"),
|
|
2145
|
-
onClick: immutable ? void 0 : handleAdd,
|
|
2146
|
-
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
2147
|
-
disabled: view.fields.length >= VIEW_FIELD_LIMIT
|
|
2148
|
-
})));
|
|
2236
|
+
projection.hideFieldProjection(fieldId);
|
|
2237
|
+
}, [
|
|
2238
|
+
projection
|
|
2239
|
+
]);
|
|
2240
|
+
const handleShow = useCallback10((property) => {
|
|
2241
|
+
setField(void 0);
|
|
2242
|
+
projection.showFieldProjection(property);
|
|
2243
|
+
}, [
|
|
2244
|
+
projection
|
|
2245
|
+
]);
|
|
2246
|
+
return /* @__PURE__ */ React15.createElement("div", {
|
|
2247
|
+
role: "none",
|
|
2248
|
+
className: mx7("overflow-y-auto", classNames)
|
|
2249
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
2250
|
+
role: "none",
|
|
2251
|
+
className: "p-2"
|
|
2252
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
2253
|
+
role: "none",
|
|
2254
|
+
className: "mbe-2"
|
|
2255
|
+
}, immutable && /* @__PURE__ */ React15.createElement(Message.Root, {
|
|
2256
|
+
valence: "neutral",
|
|
2257
|
+
className: "rounded"
|
|
2258
|
+
}, /* @__PURE__ */ React15.createElement(Message.Title, null, /* @__PURE__ */ React15.createElement(Icon3, {
|
|
2259
|
+
icon: "ph--info--regular",
|
|
2260
|
+
size: 5,
|
|
2261
|
+
classNames: "inline"
|
|
2262
|
+
}), " ", t("system schema title")), /* @__PURE__ */ React15.createElement(Message.Body, null, t("system schema description")))), /* @__PURE__ */ React15.createElement(Form, {
|
|
2263
|
+
autoSave: true,
|
|
2264
|
+
schema: ViewMetaSchema,
|
|
2265
|
+
values: viewValues,
|
|
2266
|
+
onSave: handleUpdate,
|
|
2267
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
2268
|
+
})), /* @__PURE__ */ React15.createElement("div", {
|
|
2269
|
+
role: "none",
|
|
2270
|
+
className: "min-bs-0 overflow-y-auto"
|
|
2271
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
2272
|
+
role: "none",
|
|
2273
|
+
className: "p-2"
|
|
2274
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
2275
|
+
className: mx7(inputTextLabel)
|
|
2276
|
+
}, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
2277
|
+
items: view.fields,
|
|
2278
|
+
isItem: Schema2.is(FieldSchema),
|
|
2279
|
+
getId: (field2) => field2.id,
|
|
2280
|
+
onMove: immutable ? void 0 : handleMove
|
|
2281
|
+
}, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
|
|
2282
|
+
role: "heading",
|
|
2283
|
+
className: grid
|
|
2284
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
|
|
2285
|
+
className: "flex items-center text-sm"
|
|
2286
|
+
}, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
|
|
2287
|
+
role: "list",
|
|
2288
|
+
className: "flex flex-col w-full"
|
|
2289
|
+
}, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
2290
|
+
key: field2.id,
|
|
2291
|
+
item: field2,
|
|
2292
|
+
classNames: mx7(grid, ghostHover, !immutable && "cursor-pointer")
|
|
2293
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
|
|
2294
|
+
onClick: () => handleSelect(field2)
|
|
2295
|
+
}, field2.path), /* @__PURE__ */ React15.createElement("div", {
|
|
2296
|
+
className: "flex items-center gap-2 -ml-4"
|
|
2297
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
2298
|
+
icon: "ph--eye-slash--regular",
|
|
2299
|
+
disabled: view.fields.length <= 1,
|
|
2300
|
+
onClick: () => handleHide(field2.id)
|
|
2301
|
+
}), !immutable && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
2302
|
+
icon: "ph--trash--regular",
|
|
2303
|
+
disabled: view.fields.length <= 1,
|
|
2304
|
+
onClick: () => handleDelete(field2.id)
|
|
2305
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
|
|
2306
|
+
role: "none",
|
|
2307
|
+
className: "p-2"
|
|
2308
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
2309
|
+
className: mx7(inputTextLabel)
|
|
2310
|
+
}, t("hidden fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
2311
|
+
items: hiddenProperties,
|
|
2312
|
+
isItem: (item) => typeof item === "string",
|
|
2313
|
+
getId: (property) => property
|
|
2314
|
+
}, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
|
|
2315
|
+
role: "list",
|
|
2316
|
+
className: "flex flex-col w-full"
|
|
2317
|
+
}, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
2318
|
+
key: property,
|
|
2319
|
+
item: property,
|
|
2320
|
+
classNames: mx7(grid, ghostHover, !immutable && "cursor-pointer")
|
|
2321
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
2322
|
+
icon: "ph--eye--regular",
|
|
2323
|
+
onClick: () => handleShow(property)
|
|
2324
|
+
}))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
|
|
2325
|
+
key: field.id,
|
|
2326
|
+
view,
|
|
2327
|
+
projection,
|
|
2328
|
+
field,
|
|
2329
|
+
registry,
|
|
2330
|
+
onSave: handleClose
|
|
2331
|
+
}), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
|
|
2332
|
+
role: "none",
|
|
2333
|
+
className: "p-2"
|
|
2334
|
+
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
2335
|
+
icon: "ph--plus--regular",
|
|
2336
|
+
label: t("button add property"),
|
|
2337
|
+
onClick: immutable ? void 0 : handleAdd,
|
|
2338
|
+
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
2339
|
+
disabled: view.fields.length >= VIEW_FIELD_LIMIT,
|
|
2340
|
+
classNames: "flex is-full"
|
|
2341
|
+
})));
|
|
2342
|
+
} finally {
|
|
2343
|
+
_effect.f();
|
|
2344
|
+
}
|
|
2149
2345
|
};
|
|
2150
2346
|
export {
|
|
2151
2347
|
BooleanInput,
|