@dxos/react-ui-form 0.8.1 → 0.8.2-main.2f9c567
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 +338 -149
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +326 -138
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +338 -149
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/{ControlSection.d.ts → ControlSection/ControlSection.d.ts} +8 -5
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -0
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +8 -0
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -0
- package/dist/types/src/components/ControlSection/index.d.ts +2 -0
- package/dist/types/src/components/ControlSection/index.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.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +6 -3
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +37 -34
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +14 -11
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +2 -2
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +24 -0
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +1 -0
- package/dist/types/src/components/Form/index.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.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +2 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +2 -2
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +8 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -0
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/components/ControlSection/ControlSection.stories.tsx +29 -0
- package/src/components/{ControlSection.tsx → ControlSection/ControlSection.tsx} +38 -14
- package/src/components/ControlSection/index.ts +5 -0
- package/src/components/Form/ArrayField.tsx +8 -7
- package/src/components/Form/Defaults.tsx +4 -1
- package/src/components/Form/Form.stories.tsx +90 -42
- package/src/components/Form/Form.tsx +7 -2
- package/src/components/Form/FormContent.tsx +62 -19
- package/src/components/Form/FormContext.tsx +10 -2
- package/src/components/Form/RefField.tsx +152 -0
- package/src/components/Form/custom/GeoPointInput.tsx +2 -2
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +5 -4
- package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
- package/src/components/Form/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +3 -2
- package/src/components/ViewEditor/ViewEditor.tsx +12 -10
- package/src/components/deprecated/Form.stories.tsx +6 -6
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/components/deprecated/FormInput.tsx +1 -1
- package/src/components/index.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useForm.ts +3 -3
- package/src/hooks/useRefQueryLookupHandler.ts +43 -0
- package/src/util/formatting.ts +15 -3
- package/dist/types/src/components/ControlSection.d.ts.map +0 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -32,8 +32,10 @@ __export(node_exports, {
|
|
|
32
32
|
ControlFrame: () => ControlFrame,
|
|
33
33
|
ControlFrameItem: () => ControlFrameItem,
|
|
34
34
|
ControlGroup: () => ControlGroup,
|
|
35
|
+
ControlGroupButton: () => ControlGroupButton,
|
|
35
36
|
ControlItem: () => ControlItem,
|
|
36
37
|
ControlItemInput: () => ControlItemInput,
|
|
38
|
+
ControlPage: () => ControlPage,
|
|
37
39
|
ControlSection: () => ControlSection,
|
|
38
40
|
ControlSectionHeading: () => ControlSectionHeading,
|
|
39
41
|
DeprecatedFormContainer: () => DeprecatedFormContainer,
|
|
@@ -60,7 +62,8 @@ __export(node_exports, {
|
|
|
60
62
|
useForm: () => useForm,
|
|
61
63
|
useFormContext: () => useFormContext,
|
|
62
64
|
useFormValues: () => useFormValues,
|
|
63
|
-
useInputProps: () => useInputProps
|
|
65
|
+
useInputProps: () => useInputProps,
|
|
66
|
+
useRefQueryLookupHandler: () => useRefQueryLookupHandler
|
|
64
67
|
});
|
|
65
68
|
module.exports = __toCommonJS(node_exports);
|
|
66
69
|
var import_react = __toESM(require("react"));
|
|
@@ -68,6 +71,7 @@ var import_react_ui = require("@dxos/react-ui");
|
|
|
68
71
|
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
69
72
|
var import_react2 = __toESM(require("react"));
|
|
70
73
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
74
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
71
75
|
var import_react3 = __toESM(require("react"));
|
|
72
76
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
73
77
|
var import_log = require("@dxos/log");
|
|
@@ -79,24 +83,24 @@ var import_react_ui4 = require("@dxos/react-ui");
|
|
|
79
83
|
var import_util = require("@dxos/util");
|
|
80
84
|
var import_react5 = __toESM(require("react"));
|
|
81
85
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
82
|
-
var
|
|
86
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
83
87
|
var import_react6 = __toESM(require("react"));
|
|
84
88
|
var import_keys = require("@dxos/keys");
|
|
85
89
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
86
90
|
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
87
91
|
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
88
|
-
var
|
|
92
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
89
93
|
var import_react7 = __toESM(require("react"));
|
|
90
94
|
var import_react_ui7 = require("@dxos/react-ui");
|
|
91
|
-
var
|
|
95
|
+
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
92
96
|
var import_util2 = require("@dxos/util");
|
|
93
97
|
var import_react8 = __toESM(require("react"));
|
|
94
98
|
var import_react_ui8 = require("@dxos/react-ui");
|
|
95
99
|
var import_react9 = __toESM(require("react"));
|
|
96
|
-
var
|
|
100
|
+
var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
97
101
|
var import_react10 = __toESM(require("react"));
|
|
98
102
|
var import_react_ui9 = require("@dxos/react-ui");
|
|
99
|
-
var
|
|
103
|
+
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
100
104
|
var import_react11 = __toESM(require("react"));
|
|
101
105
|
var import_debug = require("@dxos/debug");
|
|
102
106
|
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
@@ -108,30 +112,39 @@ var import_effect3 = require("@dxos/effect");
|
|
|
108
112
|
var import_invariant = require("@dxos/invariant");
|
|
109
113
|
var import_log2 = require("@dxos/log");
|
|
110
114
|
var import_schema2 = require("@dxos/schema");
|
|
115
|
+
var import_react13 = require("react");
|
|
116
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
117
|
+
var import_echo = require("@dxos/react-client/echo");
|
|
118
|
+
var import_util3 = require("@dxos/util");
|
|
111
119
|
var import_effect4 = require("effect");
|
|
112
120
|
var import_String = require("effect/String");
|
|
113
|
-
var
|
|
114
|
-
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
121
|
+
var import_react14 = __toESM(require("react"));
|
|
115
122
|
var import_effect5 = require("@dxos/effect");
|
|
116
|
-
var
|
|
123
|
+
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
117
124
|
var import_schema3 = require("@dxos/schema");
|
|
118
|
-
var
|
|
125
|
+
var import_util4 = require("@dxos/util");
|
|
119
126
|
var import_effect6 = require("effect");
|
|
120
127
|
var import_String2 = require("effect/String");
|
|
121
|
-
var
|
|
122
|
-
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
128
|
+
var import_react15 = __toESM(require("react"));
|
|
123
129
|
var import_effect7 = require("@dxos/effect");
|
|
124
130
|
var import_invariant2 = require("@dxos/invariant");
|
|
125
131
|
var import_react_ui10 = require("@dxos/react-ui");
|
|
126
|
-
var
|
|
132
|
+
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
127
133
|
var import_schema4 = require("@dxos/schema");
|
|
134
|
+
var import_react16 = __toESM(require("react"));
|
|
135
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
136
|
+
var import_effect8 = require("@dxos/effect");
|
|
137
|
+
var import_keys2 = require("@dxos/keys");
|
|
138
|
+
var import_live_object = require("@dxos/live-object");
|
|
139
|
+
var import_log3 = require("@dxos/log");
|
|
128
140
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
129
|
-
var
|
|
141
|
+
var import_effect9 = require("effect");
|
|
142
|
+
var import_react17 = __toESM(require("react"));
|
|
130
143
|
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
131
144
|
var import_invariant3 = require("@dxos/invariant");
|
|
132
145
|
var import_react_ui11 = require("@dxos/react-ui");
|
|
133
146
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
134
|
-
var
|
|
147
|
+
var import_react_ui_theme10 = require("@dxos/react-ui-theme");
|
|
135
148
|
var import_schema5 = require("@dxos/schema");
|
|
136
149
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
137
150
|
var import_format = require("date-fns/format");
|
|
@@ -197,7 +210,7 @@ var translations_default = [
|
|
|
197
210
|
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
198
211
|
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
199
212
|
role: "none",
|
|
200
|
-
className: "
|
|
213
|
+
className: "container-max-width p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
201
214
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
202
215
|
role: "form",
|
|
203
216
|
className: (0, import_react_ui_theme.mx)("flex flex-col", import_react_ui_theme.textBlockWidth, classNames)
|
|
@@ -230,6 +243,19 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
230
243
|
}
|
|
231
244
|
return primary;
|
|
232
245
|
};
|
|
246
|
+
var ControlPage = ({ children, classNames, ...props }) => {
|
|
247
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
248
|
+
role: "none",
|
|
249
|
+
className: (0, import_react_ui_theme2.mx)("pli-2", classNames),
|
|
250
|
+
...props
|
|
251
|
+
}, children);
|
|
252
|
+
};
|
|
253
|
+
var ControlSection = ({ title, description, children }) => {
|
|
254
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(ControlSectionHeading, {
|
|
255
|
+
title,
|
|
256
|
+
description
|
|
257
|
+
}), children);
|
|
258
|
+
};
|
|
233
259
|
var ControlSectionHeading = ({ title, description }) => {
|
|
234
260
|
const { t } = (0, import_react_ui2.useTranslation)(translationKey);
|
|
235
261
|
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement("h2", {
|
|
@@ -238,15 +264,18 @@ var ControlSectionHeading = ({ title, description }) => {
|
|
|
238
264
|
className: "pli-4 mlb-4 container-max-width text-description"
|
|
239
265
|
}, (0, import_react_ui2.toLocalizedString)(description, t)));
|
|
240
266
|
};
|
|
241
|
-
var
|
|
242
|
-
return /* @__PURE__ */ import_react2.default.createElement(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
267
|
+
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
268
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Button, {
|
|
269
|
+
...props,
|
|
270
|
+
classNames: [
|
|
271
|
+
"md:col-span-2",
|
|
272
|
+
classNames
|
|
273
|
+
]
|
|
274
|
+
});
|
|
246
275
|
};
|
|
247
|
-
var ControlGroup = ({ children }) => /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
276
|
+
var ControlGroup = ({ children, classNames }) => /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
248
277
|
role: "none",
|
|
249
|
-
className: "group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4"
|
|
278
|
+
className: (0, import_react_ui_theme2.mx)("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4", classNames)
|
|
250
279
|
}, children);
|
|
251
280
|
var ControlFrame = ({ children }) => /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
252
281
|
role: "none",
|
|
@@ -299,7 +328,7 @@ var InputHeader = ({ children, error }) => {
|
|
|
299
328
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
300
329
|
icon: "ph--warning--regular",
|
|
301
330
|
size: 4,
|
|
302
|
-
classNames:
|
|
331
|
+
classNames: import_react_ui_theme3.errorText
|
|
303
332
|
})), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Content, {
|
|
304
333
|
side: "bottom"
|
|
305
334
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Arrow, null), error)));
|
|
@@ -391,13 +420,13 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
391
420
|
]);
|
|
392
421
|
const randomHue = () => {
|
|
393
422
|
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
394
|
-
const unusedHues =
|
|
423
|
+
const unusedHues = import_react_ui_theme4.hues.filter((hue) => !usedHues.has(hue));
|
|
395
424
|
if (unusedHues.length > 0) {
|
|
396
425
|
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
397
426
|
}
|
|
398
427
|
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
399
|
-
const availableHues =
|
|
400
|
-
return availableHues[Math.floor(Math.random() * availableHues.length)] ??
|
|
428
|
+
const availableHues = import_react_ui_theme4.hues.filter((hue) => !lastThree.has(hue));
|
|
429
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? import_react_ui_theme4.hues[Math.floor(Math.random() * import_react_ui_theme4.hues.length)];
|
|
401
430
|
};
|
|
402
431
|
const handleAdd = (0, import_react6.useCallback)(() => {
|
|
403
432
|
const newId = import_keys.PublicKey.random().truncate();
|
|
@@ -498,7 +527,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
498
527
|
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui_list.List.Item, {
|
|
499
528
|
role: "button",
|
|
500
529
|
item,
|
|
501
|
-
classNames: (0,
|
|
530
|
+
classNames: (0, import_react_ui_theme4.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
502
531
|
"aria-expanded": selected === item.id
|
|
503
532
|
}, /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
504
533
|
className: "flex items-center"
|
|
@@ -539,7 +568,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
539
568
|
role: "listitem"
|
|
540
569
|
}, /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
541
570
|
role: "button",
|
|
542
|
-
className: (0,
|
|
571
|
+
className: (0, import_react_ui_theme4.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
543
572
|
onClick: handleAdd
|
|
544
573
|
}, /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
545
574
|
className: "flex items-center gap-1"
|
|
@@ -563,7 +592,7 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
563
592
|
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
564
593
|
error
|
|
565
594
|
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
566
|
-
className: (0,
|
|
595
|
+
className: (0, import_react_ui_theme5.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
567
596
|
}, binding.map((prop) => /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
568
597
|
key: prop,
|
|
569
598
|
type: "number",
|
|
@@ -619,23 +648,28 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
|
|
|
619
648
|
};
|
|
620
649
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
621
650
|
const { status, error } = getStatus();
|
|
651
|
+
const value = getValue3();
|
|
652
|
+
const handleValueChange = (0, import_react8.useCallback)((value2) => onValueChange(type, value2), [
|
|
653
|
+
type,
|
|
654
|
+
onValueChange
|
|
655
|
+
]);
|
|
622
656
|
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
623
657
|
validationValence: status
|
|
624
658
|
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
625
659
|
error
|
|
626
660
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Root, {
|
|
627
|
-
value
|
|
628
|
-
onValueChange:
|
|
661
|
+
value,
|
|
662
|
+
onValueChange: handleValueChange
|
|
629
663
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.TriggerButton, {
|
|
630
664
|
classNames: "is-full",
|
|
631
665
|
disabled,
|
|
632
666
|
placeholder
|
|
633
|
-
}), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Portal, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Content, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
667
|
+
}), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Portal, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Content, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
634
668
|
// NOTE: Numeric values are converted to and from strings.
|
|
635
669
|
/* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Option, {
|
|
636
|
-
key: String(
|
|
637
|
-
value: String(
|
|
638
|
-
}, label2 ?? String(
|
|
670
|
+
key: String(value2),
|
|
671
|
+
value: String(value2)
|
|
672
|
+
}, label2 ?? String(value2))
|
|
639
673
|
)))))), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.DescriptionAndValidation, null, error));
|
|
640
674
|
};
|
|
641
675
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
@@ -684,7 +718,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
684
718
|
L: 93,
|
|
685
719
|
S: void 0,
|
|
686
720
|
A: [
|
|
687
|
-
"
|
|
721
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
688
722
|
""
|
|
689
723
|
]
|
|
690
724
|
});
|
|
@@ -877,6 +911,29 @@ var flatMap = (errors) => {
|
|
|
877
911
|
return result;
|
|
878
912
|
}, {});
|
|
879
913
|
};
|
|
914
|
+
var useRefQueryLookupHandler = ({ space }) => {
|
|
915
|
+
const handleRefQueryLookup = (0, import_react13.useCallback)(async (typeInfo) => {
|
|
916
|
+
if (!space) {
|
|
917
|
+
return [];
|
|
918
|
+
}
|
|
919
|
+
const query = space.db.query(import_echo.Filter.typename(typeInfo.typename));
|
|
920
|
+
const { objects } = await query.run();
|
|
921
|
+
return objects.map((object) => {
|
|
922
|
+
const dxn = (0, import_echo_schema5.getDXN)(object);
|
|
923
|
+
if (!dxn) {
|
|
924
|
+
return void 0;
|
|
925
|
+
}
|
|
926
|
+
const item = {
|
|
927
|
+
dxn,
|
|
928
|
+
label: object?.name ?? object?.id ?? ""
|
|
929
|
+
};
|
|
930
|
+
return item;
|
|
931
|
+
}).filter(import_util3.isNonNullable);
|
|
932
|
+
}, [
|
|
933
|
+
space
|
|
934
|
+
]);
|
|
935
|
+
return handleRefQueryLookup;
|
|
936
|
+
};
|
|
880
937
|
var FormContext = /* @__PURE__ */ (0, import_react11.createContext)(void 0);
|
|
881
938
|
var useFormContext = () => {
|
|
882
939
|
return (0, import_react11.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
@@ -948,7 +1005,7 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
948
1005
|
className: "mt-2 flex justify-center"
|
|
949
1006
|
}, /* @__PURE__ */ import_react10.default.createElement("div", {
|
|
950
1007
|
role: "none",
|
|
951
|
-
className: (0,
|
|
1008
|
+
className: (0, import_react_ui_theme7.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
952
1009
|
}, onCancel && !readonly && /* @__PURE__ */ import_react10.default.createElement(import_react_ui9.IconButton, {
|
|
953
1010
|
"data-testid": "cancel-button",
|
|
954
1011
|
icon: "ph--x--regular",
|
|
@@ -968,10 +1025,10 @@ var padding = "px-2";
|
|
|
968
1025
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
969
1026
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
970
1027
|
const { ast, name, type, title } = property;
|
|
971
|
-
const values = useFormValues(path ?? []);
|
|
1028
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
972
1029
|
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
973
1030
|
F: __dxlog_file2,
|
|
974
|
-
L:
|
|
1031
|
+
L: 38,
|
|
975
1032
|
S: void 0,
|
|
976
1033
|
A: [
|
|
977
1034
|
"Array.isArray(values)",
|
|
@@ -979,11 +1036,11 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
979
1036
|
]
|
|
980
1037
|
});
|
|
981
1038
|
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
982
|
-
const tupleType = (0, import_effect7.findNode)(ast,
|
|
1039
|
+
const tupleType = (0, import_effect7.findNode)(ast, import_effect6.SchemaAST.isTupleType);
|
|
983
1040
|
const elementType = tupleType?.rest[0]?.type;
|
|
984
1041
|
const getDefaultObjectValue = (typeNode) => {
|
|
985
1042
|
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
986
|
-
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode,
|
|
1043
|
+
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_effect6.SchemaAST.isTypeLiteral);
|
|
987
1044
|
if (!typeLiteral) {
|
|
988
1045
|
return {};
|
|
989
1046
|
}
|
|
@@ -992,7 +1049,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
992
1049
|
prop.defaultValue
|
|
993
1050
|
]));
|
|
994
1051
|
};
|
|
995
|
-
const newValue = (0,
|
|
1052
|
+
const newValue = (0, import_react15.useMemo)(() => {
|
|
996
1053
|
if (type === "object" && elementType) {
|
|
997
1054
|
return getDefaultObjectValue(elementType);
|
|
998
1055
|
} else {
|
|
@@ -1002,7 +1059,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1002
1059
|
type,
|
|
1003
1060
|
elementType
|
|
1004
1061
|
]);
|
|
1005
|
-
const handleAdd = (0,
|
|
1062
|
+
const handleAdd = (0, import_react15.useCallback)(() => {
|
|
1006
1063
|
inputProps.onValueChange(type, [
|
|
1007
1064
|
...values,
|
|
1008
1065
|
newValue
|
|
@@ -1014,7 +1071,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1014
1071
|
newValue,
|
|
1015
1072
|
values
|
|
1016
1073
|
]);
|
|
1017
|
-
const handleRemove = (0,
|
|
1074
|
+
const handleRemove = (0, import_react15.useCallback)((index) => {
|
|
1018
1075
|
const newValues = values.filter((_, i) => i !== index);
|
|
1019
1076
|
inputProps.onValueChange(type, newValues);
|
|
1020
1077
|
}, [
|
|
@@ -1025,20 +1082,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1025
1082
|
if (!elementType) {
|
|
1026
1083
|
return null;
|
|
1027
1084
|
}
|
|
1028
|
-
return /* @__PURE__ */
|
|
1085
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1029
1086
|
role: "none",
|
|
1030
|
-
className: (0,
|
|
1031
|
-
}, /* @__PURE__ */
|
|
1087
|
+
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1088
|
+
}, /* @__PURE__ */ import_react15.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1032
1089
|
role: "none",
|
|
1033
1090
|
className: "flex flex-col gap-1"
|
|
1034
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
1091
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1035
1092
|
key: index,
|
|
1036
1093
|
role: "none",
|
|
1037
1094
|
className: "flex items-center gap-1"
|
|
1038
|
-
}, /* @__PURE__ */
|
|
1095
|
+
}, /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1039
1096
|
role: "none",
|
|
1040
1097
|
className: "flex-1"
|
|
1041
|
-
}, /* @__PURE__ */
|
|
1098
|
+
}, /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1042
1099
|
property: {
|
|
1043
1100
|
...property,
|
|
1044
1101
|
array: false,
|
|
@@ -1052,21 +1109,115 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1052
1109
|
inline: true,
|
|
1053
1110
|
Custom,
|
|
1054
1111
|
lookupComponent
|
|
1055
|
-
})), /* @__PURE__ */
|
|
1112
|
+
})), /* @__PURE__ */ import_react15.default.createElement(import_react_ui10.IconButton, {
|
|
1056
1113
|
icon: "ph--trash--regular",
|
|
1057
1114
|
iconOnly: true,
|
|
1058
1115
|
label: t("button remove"),
|
|
1059
1116
|
onClick: () => handleRemove(index)
|
|
1060
|
-
})))), /* @__PURE__ */
|
|
1117
|
+
})))), /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1061
1118
|
role: "none",
|
|
1062
1119
|
className: "flex justify-between items-center plb-1"
|
|
1063
|
-
}, /* @__PURE__ */
|
|
1120
|
+
}, /* @__PURE__ */ import_react15.default.createElement(import_react_ui10.IconButton, {
|
|
1064
1121
|
icon: "ph--plus--regular",
|
|
1065
1122
|
iconOnly: true,
|
|
1066
1123
|
label: t("button add"),
|
|
1067
1124
|
onClick: handleAdd
|
|
1068
1125
|
})));
|
|
1069
1126
|
};
|
|
1127
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/RefField.tsx";
|
|
1128
|
+
var RefField = ({ ast, type, label, readonly, placeholder, inline, onQueryRefOptions, inputProps }) => {
|
|
1129
|
+
const { getValue: getValue3, onValueChange, ...restInputProps } = inputProps;
|
|
1130
|
+
const refTypeInfo = (0, import_effect8.findAnnotation)(ast, import_echo_schema6.ReferenceAnnotationId);
|
|
1131
|
+
const [refOptions, setRefOptions] = (0, import_react16.useState)([]);
|
|
1132
|
+
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
1133
|
+
(0, import_react16.useEffect)(() => {
|
|
1134
|
+
if (!refTypeInfo || !onQueryRefOptions) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
const fetchOptions = async () => {
|
|
1138
|
+
setLoading(true);
|
|
1139
|
+
try {
|
|
1140
|
+
const options = await onQueryRefOptions(refTypeInfo);
|
|
1141
|
+
setRefOptions(options.map((option) => ({
|
|
1142
|
+
label: option.label,
|
|
1143
|
+
value: option.dxn.toString()
|
|
1144
|
+
})));
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
import_log3.log.error("Failed to fetch ref options:", error, {
|
|
1147
|
+
F: __dxlog_file3,
|
|
1148
|
+
L: 69,
|
|
1149
|
+
S: void 0,
|
|
1150
|
+
C: (f, a) => f(...a)
|
|
1151
|
+
});
|
|
1152
|
+
setRefOptions([]);
|
|
1153
|
+
} finally {
|
|
1154
|
+
setLoading(false);
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
void fetchOptions();
|
|
1158
|
+
}, [
|
|
1159
|
+
refTypeInfo,
|
|
1160
|
+
onQueryRefOptions
|
|
1161
|
+
]);
|
|
1162
|
+
if (!refTypeInfo) {
|
|
1163
|
+
return null;
|
|
1164
|
+
}
|
|
1165
|
+
if (refTypeInfo.typename === (0, import_echo_schema6.getTypeAnnotation)(import_echo_schema6.Expando)?.typename || !onQueryRefOptions) {
|
|
1166
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1167
|
+
const dxn = import_keys2.DXN.tryParse(dxnString);
|
|
1168
|
+
if (dxn) {
|
|
1169
|
+
onValueChange?.("object", (0, import_live_object.refFromDXN)(dxn));
|
|
1170
|
+
} else if (dxnString === "") {
|
|
1171
|
+
onValueChange?.("object", void 0);
|
|
1172
|
+
} else {
|
|
1173
|
+
onValueChange?.("string", dxnString);
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
const handleGetValue2 = () => {
|
|
1177
|
+
const formValue = getValue3();
|
|
1178
|
+
if (typeof formValue === "string") {
|
|
1179
|
+
return formValue;
|
|
1180
|
+
}
|
|
1181
|
+
if (import_echo_schema6.Ref.isRef(formValue)) {
|
|
1182
|
+
return formValue.dxn.toString();
|
|
1183
|
+
}
|
|
1184
|
+
return void 0;
|
|
1185
|
+
};
|
|
1186
|
+
return /* @__PURE__ */ import_react16.default.createElement(TextInput, {
|
|
1187
|
+
type,
|
|
1188
|
+
label,
|
|
1189
|
+
disabled: readonly,
|
|
1190
|
+
placeholder,
|
|
1191
|
+
inputOnly: inline,
|
|
1192
|
+
getValue: handleGetValue2,
|
|
1193
|
+
onValueChange: handleOnValueChange,
|
|
1194
|
+
...restInputProps
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
const handleGetValue = () => {
|
|
1198
|
+
const formValue = getValue3();
|
|
1199
|
+
if (import_echo_schema6.Ref.isRef(formValue)) {
|
|
1200
|
+
return formValue.dxn.toString();
|
|
1201
|
+
}
|
|
1202
|
+
return void 0;
|
|
1203
|
+
};
|
|
1204
|
+
const handleValueChanged = (_type, dxnString) => {
|
|
1205
|
+
const dxn = import_keys2.DXN.parse(dxnString);
|
|
1206
|
+
const ref = (0, import_live_object.refFromDXN)(dxn);
|
|
1207
|
+
onValueChange("object", ref);
|
|
1208
|
+
};
|
|
1209
|
+
return /* @__PURE__ */ import_react16.default.createElement(SelectInput, {
|
|
1210
|
+
type,
|
|
1211
|
+
label,
|
|
1212
|
+
disabled: readonly || loading,
|
|
1213
|
+
placeholder: loading ? "Loading options..." : placeholder,
|
|
1214
|
+
inputOnly: inline,
|
|
1215
|
+
getValue: handleGetValue,
|
|
1216
|
+
onValueChange: handleValueChanged,
|
|
1217
|
+
options: refOptions,
|
|
1218
|
+
...restInputProps
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1070
1221
|
var getInputComponent = (type, format) => {
|
|
1071
1222
|
switch (format) {
|
|
1072
1223
|
case import_echo_schema7.FormatEnum.GeoPoint:
|
|
@@ -1083,20 +1234,20 @@ var getInputComponent = (type, format) => {
|
|
|
1083
1234
|
return BooleanInput;
|
|
1084
1235
|
}
|
|
1085
1236
|
};
|
|
1086
|
-
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
1237
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1087
1238
|
const inputProps = useInputProps(path);
|
|
1088
1239
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1089
|
-
const label = (0,
|
|
1240
|
+
const label = (0, import_react14.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1090
1241
|
title,
|
|
1091
1242
|
name
|
|
1092
1243
|
]);
|
|
1093
|
-
const placeholder = (0,
|
|
1244
|
+
const placeholder = (0, import_react14.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1094
1245
|
examples,
|
|
1095
1246
|
description
|
|
1096
1247
|
]);
|
|
1097
1248
|
const FoundComponent = lookupComponent?.({
|
|
1098
1249
|
prop: name,
|
|
1099
|
-
schema:
|
|
1250
|
+
schema: import_effect4.Schema.make(ast),
|
|
1100
1251
|
inputProps: {
|
|
1101
1252
|
type,
|
|
1102
1253
|
format,
|
|
@@ -1107,14 +1258,14 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1107
1258
|
}
|
|
1108
1259
|
});
|
|
1109
1260
|
if (FoundComponent) {
|
|
1110
|
-
return /* @__PURE__ */
|
|
1261
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1111
1262
|
role: "none"
|
|
1112
1263
|
}, FoundComponent);
|
|
1113
1264
|
}
|
|
1114
1265
|
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1115
1266
|
const CustomComponent = Custom?.[jsonPath];
|
|
1116
1267
|
if (CustomComponent) {
|
|
1117
|
-
return /* @__PURE__ */
|
|
1268
|
+
return /* @__PURE__ */ import_react14.default.createElement(CustomComponent, {
|
|
1118
1269
|
type,
|
|
1119
1270
|
format,
|
|
1120
1271
|
label,
|
|
@@ -1125,7 +1276,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1125
1276
|
});
|
|
1126
1277
|
}
|
|
1127
1278
|
if (array) {
|
|
1128
|
-
return /* @__PURE__ */
|
|
1279
|
+
return /* @__PURE__ */ import_react14.default.createElement(ArrayField, {
|
|
1129
1280
|
property,
|
|
1130
1281
|
path,
|
|
1131
1282
|
inputProps,
|
|
@@ -1135,9 +1286,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1135
1286
|
}
|
|
1136
1287
|
const InputComponent = getInputComponent(type, format);
|
|
1137
1288
|
if (InputComponent) {
|
|
1138
|
-
return /* @__PURE__ */
|
|
1289
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1139
1290
|
role: "none"
|
|
1140
|
-
}, /* @__PURE__ */
|
|
1291
|
+
}, /* @__PURE__ */ import_react14.default.createElement(InputComponent, {
|
|
1141
1292
|
type,
|
|
1142
1293
|
format,
|
|
1143
1294
|
label,
|
|
@@ -1148,9 +1299,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1148
1299
|
}));
|
|
1149
1300
|
}
|
|
1150
1301
|
if (options) {
|
|
1151
|
-
return /* @__PURE__ */
|
|
1302
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1152
1303
|
role: "none"
|
|
1153
|
-
}, /* @__PURE__ */
|
|
1304
|
+
}, /* @__PURE__ */ import_react14.default.createElement(SelectInput, {
|
|
1154
1305
|
type,
|
|
1155
1306
|
format,
|
|
1156
1307
|
disabled: readonly,
|
|
@@ -1164,25 +1315,41 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1164
1315
|
...inputProps
|
|
1165
1316
|
}));
|
|
1166
1317
|
}
|
|
1318
|
+
if (format === "ref") {
|
|
1319
|
+
return /* @__PURE__ */ import_react14.default.createElement(RefField, {
|
|
1320
|
+
ast,
|
|
1321
|
+
type,
|
|
1322
|
+
label,
|
|
1323
|
+
readonly,
|
|
1324
|
+
placeholder,
|
|
1325
|
+
inline,
|
|
1326
|
+
onQueryRefOptions,
|
|
1327
|
+
inputProps
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1167
1330
|
if (type === "object") {
|
|
1168
1331
|
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1169
|
-
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast,
|
|
1332
|
+
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_effect4.SchemaAST.isTypeLiteral);
|
|
1170
1333
|
if (typeLiteral) {
|
|
1171
|
-
return /* @__PURE__ */
|
|
1334
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1172
1335
|
role: "none"
|
|
1173
|
-
}, !inline && /* @__PURE__ */
|
|
1174
|
-
|
|
1336
|
+
}, !inline && /* @__PURE__ */ import_react14.default.createElement("h3", {
|
|
1337
|
+
className: "text-lg mbs-2 mbe-1"
|
|
1338
|
+
}, label), /* @__PURE__ */ import_react14.default.createElement(FormFields, {
|
|
1339
|
+
schema: import_effect4.Schema.make(typeLiteral),
|
|
1175
1340
|
path,
|
|
1176
1341
|
readonly,
|
|
1177
|
-
|
|
1342
|
+
onQueryRefOptions,
|
|
1343
|
+
Custom,
|
|
1344
|
+
lookupComponent
|
|
1178
1345
|
}));
|
|
1179
1346
|
}
|
|
1180
1347
|
}
|
|
1181
1348
|
return null;
|
|
1182
1349
|
};
|
|
1183
|
-
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1350
|
+
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1184
1351
|
const values = useFormValues(path);
|
|
1185
|
-
const properties = (0,
|
|
1352
|
+
const properties = (0, import_react14.useMemo)(() => {
|
|
1186
1353
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1187
1354
|
const filtered = filter ? filter(props) : props;
|
|
1188
1355
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1192,11 +1359,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1192
1359
|
filter,
|
|
1193
1360
|
sort
|
|
1194
1361
|
]);
|
|
1195
|
-
return /* @__PURE__ */
|
|
1362
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1196
1363
|
role: "form",
|
|
1197
|
-
className: (0,
|
|
1364
|
+
className: (0, import_react_ui_theme8.mx)("flex flex-col w-full gap-2")
|
|
1198
1365
|
}, properties.map((property) => {
|
|
1199
|
-
return /* @__PURE__ */
|
|
1366
|
+
return /* @__PURE__ */ import_react14.default.createElement(FormField, {
|
|
1200
1367
|
key: property.name,
|
|
1201
1368
|
property,
|
|
1202
1369
|
path: [
|
|
@@ -1204,12 +1371,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1204
1371
|
property.name
|
|
1205
1372
|
],
|
|
1206
1373
|
readonly,
|
|
1374
|
+
onQueryRefOptions,
|
|
1207
1375
|
lookupComponent,
|
|
1208
1376
|
Custom
|
|
1209
1377
|
});
|
|
1210
|
-
}).filter(
|
|
1378
|
+
}).filter(import_util4.isNotFalsy));
|
|
1211
1379
|
};
|
|
1212
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1380
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1213
1381
|
const formRef = (0, import_react9.useRef)(null);
|
|
1214
1382
|
const onValid = (0, import_react9.useMemo)(() => autoSave ? onSave : void 0, [
|
|
1215
1383
|
autoSave,
|
|
@@ -1237,7 +1405,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1237
1405
|
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1238
1406
|
ref: formRef,
|
|
1239
1407
|
role: "none",
|
|
1240
|
-
className: (0,
|
|
1408
|
+
className: (0, import_react_ui_theme6.mx)("p-2", classNames),
|
|
1241
1409
|
"data-testid": testId
|
|
1242
1410
|
}, /* @__PURE__ */ import_react9.default.createElement(FormFields, {
|
|
1243
1411
|
schema,
|
|
@@ -1245,6 +1413,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1245
1413
|
readonly,
|
|
1246
1414
|
filter,
|
|
1247
1415
|
sort,
|
|
1416
|
+
onQueryRefOptions,
|
|
1248
1417
|
lookupComponent,
|
|
1249
1418
|
Custom
|
|
1250
1419
|
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react9.default.createElement(FormActions, {
|
|
@@ -1252,7 +1421,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1252
1421
|
readonly
|
|
1253
1422
|
})));
|
|
1254
1423
|
};
|
|
1255
|
-
var
|
|
1424
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1256
1425
|
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1257
1426
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
1258
1427
|
const [props, setProps] = (0, import_react3.useState)(projection.getFieldProjection(field.id).props);
|
|
@@ -1385,7 +1554,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1385
1554
|
import_log.log.warn("invalid format", {
|
|
1386
1555
|
props
|
|
1387
1556
|
}, {
|
|
1388
|
-
F:
|
|
1557
|
+
F: __dxlog_file4,
|
|
1389
1558
|
L: 174,
|
|
1390
1559
|
S: void 0,
|
|
1391
1560
|
C: (f, a) => f(...a)
|
|
@@ -1409,24 +1578,24 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1409
1578
|
Custom
|
|
1410
1579
|
});
|
|
1411
1580
|
};
|
|
1412
|
-
var
|
|
1581
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1413
1582
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1414
|
-
var ViewMetaSchema =
|
|
1415
|
-
name:
|
|
1416
|
-
[
|
|
1583
|
+
var ViewMetaSchema = import_effect9.Schema.Struct({
|
|
1584
|
+
name: import_effect9.Schema.String.annotations({
|
|
1585
|
+
[import_effect9.SchemaAST.TitleAnnotationId]: "View"
|
|
1417
1586
|
}),
|
|
1418
1587
|
typename: import_echo_schema8.Format.URL.annotations({
|
|
1419
|
-
[
|
|
1588
|
+
[import_effect9.SchemaAST.TitleAnnotationId]: "Typename"
|
|
1420
1589
|
})
|
|
1421
|
-
}).pipe(
|
|
1590
|
+
}).pipe(import_effect9.Schema.mutable);
|
|
1422
1591
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1423
1592
|
const { t } = (0, import_react_ui11.useTranslation)(translationKey);
|
|
1424
|
-
const projection = (0,
|
|
1593
|
+
const projection = (0, import_react17.useMemo)(() => new import_schema5.ViewProjection(schema.jsonSchema, view), [
|
|
1425
1594
|
schema,
|
|
1426
1595
|
view
|
|
1427
1596
|
]);
|
|
1428
|
-
const [field, setField] = (0,
|
|
1429
|
-
const viewValues = (0,
|
|
1597
|
+
const [field, setField] = (0, import_react17.useState)();
|
|
1598
|
+
const viewValues = (0, import_react17.useMemo)(() => {
|
|
1430
1599
|
return {
|
|
1431
1600
|
name: view.name,
|
|
1432
1601
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1436,13 +1605,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1436
1605
|
}, [
|
|
1437
1606
|
view
|
|
1438
1607
|
]);
|
|
1439
|
-
const handleSelect = (0,
|
|
1608
|
+
const handleSelect = (0, import_react17.useCallback)((field2) => {
|
|
1440
1609
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1441
1610
|
}, []);
|
|
1442
|
-
const handleAdd = (0,
|
|
1611
|
+
const handleAdd = (0, import_react17.useCallback)(() => {
|
|
1443
1612
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1444
|
-
F:
|
|
1445
|
-
L:
|
|
1613
|
+
F: __dxlog_file5,
|
|
1614
|
+
L: 77,
|
|
1446
1615
|
S: void 0,
|
|
1447
1616
|
A: [
|
|
1448
1617
|
"!schema.readonly",
|
|
@@ -1455,10 +1624,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1455
1624
|
schema,
|
|
1456
1625
|
view
|
|
1457
1626
|
]);
|
|
1458
|
-
const handleUpdate = (0,
|
|
1627
|
+
const handleUpdate = (0, import_react17.useCallback)(({ name, typename }) => {
|
|
1459
1628
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1460
|
-
F:
|
|
1461
|
-
L:
|
|
1629
|
+
F: __dxlog_file5,
|
|
1630
|
+
L: 84,
|
|
1462
1631
|
S: void 0,
|
|
1463
1632
|
A: [
|
|
1464
1633
|
"!schema.readonly",
|
|
@@ -1478,10 +1647,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1478
1647
|
view,
|
|
1479
1648
|
onTypenameChanged
|
|
1480
1649
|
]);
|
|
1481
|
-
const handleDelete = (0,
|
|
1650
|
+
const handleDelete = (0, import_react17.useCallback)((fieldId) => {
|
|
1482
1651
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1483
|
-
F:
|
|
1484
|
-
L:
|
|
1652
|
+
F: __dxlog_file5,
|
|
1653
|
+
L: 100,
|
|
1485
1654
|
S: void 0,
|
|
1486
1655
|
A: [
|
|
1487
1656
|
"!schema.readonly",
|
|
@@ -1497,10 +1666,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1497
1666
|
field,
|
|
1498
1667
|
onDelete
|
|
1499
1668
|
]);
|
|
1500
|
-
const handleMove = (0,
|
|
1669
|
+
const handleMove = (0, import_react17.useCallback)((fromIndex, toIndex) => {
|
|
1501
1670
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1502
|
-
F:
|
|
1503
|
-
L:
|
|
1671
|
+
F: __dxlog_file5,
|
|
1672
|
+
L: 112,
|
|
1504
1673
|
S: void 0,
|
|
1505
1674
|
A: [
|
|
1506
1675
|
"!schema.readonly",
|
|
@@ -1517,91 +1686,95 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1517
1686
|
schema,
|
|
1518
1687
|
view.fields
|
|
1519
1688
|
]);
|
|
1520
|
-
const handleClose = (0,
|
|
1689
|
+
const handleClose = (0, import_react17.useCallback)(() => setField(void 0), []);
|
|
1521
1690
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1522
|
-
const handleHide = (0,
|
|
1691
|
+
const handleHide = (0, import_react17.useCallback)((fieldId) => {
|
|
1523
1692
|
setField(void 0);
|
|
1524
1693
|
projection.hideFieldProjection(fieldId);
|
|
1525
1694
|
}, [
|
|
1526
1695
|
projection
|
|
1527
1696
|
]);
|
|
1528
|
-
const handleShow = (0,
|
|
1697
|
+
const handleShow = (0, import_react17.useCallback)((property) => {
|
|
1529
1698
|
setField(void 0);
|
|
1530
1699
|
projection.showFieldProjection(property);
|
|
1531
1700
|
}, [
|
|
1532
1701
|
projection
|
|
1533
1702
|
]);
|
|
1534
|
-
return /* @__PURE__ */
|
|
1703
|
+
return /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1535
1704
|
role: "none",
|
|
1536
|
-
className: (0,
|
|
1537
|
-
}, /* @__PURE__ */
|
|
1705
|
+
className: (0, import_react_ui_theme10.mx)("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1706
|
+
}, /* @__PURE__ */ import_react17.default.createElement(Form, {
|
|
1538
1707
|
autoSave: true,
|
|
1539
1708
|
schema: ViewMetaSchema,
|
|
1540
1709
|
values: viewValues,
|
|
1541
|
-
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1542
|
-
|
|
1710
|
+
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
1711
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
1712
|
+
}), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1713
|
+
role: "none",
|
|
1714
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
1715
|
+
}, /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1543
1716
|
role: "none",
|
|
1544
1717
|
className: "p-2"
|
|
1545
|
-
}, /* @__PURE__ */
|
|
1546
|
-
className: (0,
|
|
1547
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1718
|
+
}, /* @__PURE__ */ import_react17.default.createElement("label", {
|
|
1719
|
+
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1720
|
+
}, t("fields label"))), /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.Root, {
|
|
1548
1721
|
items: view.fields,
|
|
1549
|
-
isItem:
|
|
1722
|
+
isItem: import_effect9.Schema.is(import_schema5.FieldSchema),
|
|
1550
1723
|
getId: (field2) => field2.id,
|
|
1551
1724
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1552
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1725
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, showHeading && /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1553
1726
|
role: "heading",
|
|
1554
1727
|
className: grid
|
|
1555
|
-
}, /* @__PURE__ */
|
|
1728
|
+
}, /* @__PURE__ */ import_react17.default.createElement("div", null), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1556
1729
|
className: "flex items-center text-sm"
|
|
1557
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1730
|
+
}, t("field path label"))), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1558
1731
|
role: "list",
|
|
1559
1732
|
className: "flex flex-col w-full"
|
|
1560
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1733
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.Item, {
|
|
1561
1734
|
key: field2.id,
|
|
1562
1735
|
item: field2,
|
|
1563
|
-
classNames: (0,
|
|
1564
|
-
}, /* @__PURE__ */
|
|
1736
|
+
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1737
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1565
1738
|
onClick: () => handleSelect(field2)
|
|
1566
|
-
}, field2.path), /* @__PURE__ */
|
|
1739
|
+
}, field2.path), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1567
1740
|
className: "flex items-center gap-2 -ml-4"
|
|
1568
|
-
}, /* @__PURE__ */
|
|
1741
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1569
1742
|
icon: "ph--eye-slash--regular",
|
|
1570
1743
|
disabled: view.fields.length <= 1,
|
|
1571
1744
|
onClick: () => handleHide(field2.id)
|
|
1572
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
1745
|
+
}), !schema.readonly && /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1573
1746
|
icon: "ph--trash--regular",
|
|
1574
1747
|
disabled: view.fields.length <= 1,
|
|
1575
1748
|
onClick: () => handleDelete(field2.id)
|
|
1576
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
1749
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react17.default.createElement("div", null, /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1577
1750
|
role: "none",
|
|
1578
1751
|
className: "p-2"
|
|
1579
|
-
}, /* @__PURE__ */
|
|
1580
|
-
className: (0,
|
|
1581
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
1752
|
+
}, /* @__PURE__ */ import_react17.default.createElement("label", {
|
|
1753
|
+
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1754
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.Root, {
|
|
1582
1755
|
items: hiddenProperties,
|
|
1583
1756
|
isItem: (item) => typeof item === "string",
|
|
1584
1757
|
getId: (property) => property
|
|
1585
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
1758
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1586
1759
|
role: "list",
|
|
1587
1760
|
className: "flex flex-col w-full"
|
|
1588
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
1761
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.Item, {
|
|
1589
1762
|
key: property,
|
|
1590
1763
|
item: property,
|
|
1591
|
-
classNames: (0,
|
|
1592
|
-
}, /* @__PURE__ */
|
|
1764
|
+
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1765
|
+
}, /* @__PURE__ */ import_react17.default.createElement("div", null), /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.ItemTitle, null, property), /* @__PURE__ */ import_react17.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1593
1766
|
icon: "ph--eye--regular",
|
|
1594
1767
|
onClick: () => handleShow(property)
|
|
1595
|
-
}))))))), field && /* @__PURE__ */
|
|
1768
|
+
}))))))), field && /* @__PURE__ */ import_react17.default.createElement(FieldEditor, {
|
|
1596
1769
|
key: field.id,
|
|
1597
1770
|
view,
|
|
1598
1771
|
projection,
|
|
1599
1772
|
field,
|
|
1600
1773
|
registry,
|
|
1601
1774
|
onSave: handleClose
|
|
1602
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1775
|
+
}), !readonly && !field && /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1603
1776
|
className: "flex p-2 justify-center"
|
|
1604
|
-
}, /* @__PURE__ */
|
|
1777
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.IconButton, {
|
|
1605
1778
|
icon: "ph--plus--regular",
|
|
1606
1779
|
label: t("button add property"),
|
|
1607
1780
|
onClick: schema.readonly ? void 0 : handleAdd,
|
|
@@ -1779,13 +1952,25 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1779
1952
|
});
|
|
1780
1953
|
}
|
|
1781
1954
|
case import_echo_schema10.FormatEnum.Date: {
|
|
1782
|
-
|
|
1955
|
+
try {
|
|
1956
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
return "Invalid Date";
|
|
1959
|
+
}
|
|
1783
1960
|
}
|
|
1784
1961
|
case import_echo_schema10.FormatEnum.Time: {
|
|
1785
|
-
|
|
1962
|
+
try {
|
|
1963
|
+
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1964
|
+
} catch (error) {
|
|
1965
|
+
return "Invalid Time";
|
|
1966
|
+
}
|
|
1786
1967
|
}
|
|
1787
1968
|
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1788
|
-
|
|
1969
|
+
try {
|
|
1970
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1971
|
+
} catch (error) {
|
|
1972
|
+
return "Invalid DateTime";
|
|
1973
|
+
}
|
|
1789
1974
|
}
|
|
1790
1975
|
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1791
1976
|
if (value === null || value === void 0) {
|
|
@@ -1866,8 +2051,10 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1866
2051
|
ControlFrame,
|
|
1867
2052
|
ControlFrameItem,
|
|
1868
2053
|
ControlGroup,
|
|
2054
|
+
ControlGroupButton,
|
|
1869
2055
|
ControlItem,
|
|
1870
2056
|
ControlItemInput,
|
|
2057
|
+
ControlPage,
|
|
1871
2058
|
ControlSection,
|
|
1872
2059
|
ControlSectionHeading,
|
|
1873
2060
|
DeprecatedFormContainer,
|
|
@@ -1894,6 +2081,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1894
2081
|
useForm,
|
|
1895
2082
|
useFormContext,
|
|
1896
2083
|
useFormValues,
|
|
1897
|
-
useInputProps
|
|
2084
|
+
useInputProps,
|
|
2085
|
+
useRefQueryLookupHandler
|
|
1898
2086
|
});
|
|
1899
2087
|
//# sourceMappingURL=index.cjs.map
|