@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
|
@@ -67,7 +67,7 @@ import { mx, textBlockWidth } from "@dxos/react-ui-theme";
|
|
|
67
67
|
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
68
68
|
return /* @__PURE__ */ React.createElement("div", {
|
|
69
69
|
role: "none",
|
|
70
|
-
className: "
|
|
70
|
+
className: "container-max-width p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
71
71
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
72
72
|
role: "form",
|
|
73
73
|
className: mx("flex flex-col", textBlockWidth, classNames)
|
|
@@ -101,9 +101,23 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
101
101
|
return primary;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
// packages/ui/react-ui-form/src/components/ControlSection.tsx
|
|
104
|
+
// packages/ui/react-ui-form/src/components/ControlSection/ControlSection.tsx
|
|
105
105
|
import React2 from "react";
|
|
106
|
-
import {
|
|
106
|
+
import { Button, Input as Input2, toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
107
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
108
|
+
var ControlPage = ({ children, classNames, ...props }) => {
|
|
109
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
110
|
+
role: "none",
|
|
111
|
+
className: mx2("pli-2", classNames),
|
|
112
|
+
...props
|
|
113
|
+
}, children);
|
|
114
|
+
};
|
|
115
|
+
var ControlSection = ({ title, description, children }) => {
|
|
116
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ControlSectionHeading, {
|
|
117
|
+
title,
|
|
118
|
+
description
|
|
119
|
+
}), children);
|
|
120
|
+
};
|
|
107
121
|
var ControlSectionHeading = ({ title, description }) => {
|
|
108
122
|
const { t } = useTranslation(translationKey);
|
|
109
123
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", {
|
|
@@ -112,15 +126,18 @@ var ControlSectionHeading = ({ title, description }) => {
|
|
|
112
126
|
className: "pli-4 mlb-4 container-max-width text-description"
|
|
113
127
|
}, toLocalizedString(description, t)));
|
|
114
128
|
};
|
|
115
|
-
var
|
|
116
|
-
return /* @__PURE__ */ React2.createElement(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
130
|
+
return /* @__PURE__ */ React2.createElement(Button, {
|
|
131
|
+
...props,
|
|
132
|
+
classNames: [
|
|
133
|
+
"md:col-span-2",
|
|
134
|
+
classNames
|
|
135
|
+
]
|
|
136
|
+
});
|
|
120
137
|
};
|
|
121
|
-
var ControlGroup = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
|
|
138
|
+
var ControlGroup = ({ children, classNames }) => /* @__PURE__ */ React2.createElement("div", {
|
|
122
139
|
role: "none",
|
|
123
|
-
className: "group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4"
|
|
140
|
+
className: mx2("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4", classNames)
|
|
124
141
|
}, children);
|
|
125
142
|
var ControlFrame = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
|
|
126
143
|
role: "none",
|
|
@@ -166,9 +183,9 @@ var ControlFrameItem = ({ title, description, children }) => {
|
|
|
166
183
|
};
|
|
167
184
|
|
|
168
185
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
169
|
-
import
|
|
186
|
+
import React14, { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo7, useState as useState5 } from "react";
|
|
170
187
|
import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
171
|
-
import { log as
|
|
188
|
+
import { log as log3 } from "@dxos/log";
|
|
172
189
|
import { useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
173
190
|
import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
|
|
174
191
|
|
|
@@ -274,7 +291,7 @@ import { PublicKey } from "@dxos/keys";
|
|
|
274
291
|
import { Icon as Icon2, IconButton, Input as Input4, Tag, Toolbar, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
275
292
|
import { List } from "@dxos/react-ui-list";
|
|
276
293
|
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
277
|
-
import { hues, mx as
|
|
294
|
+
import { hues, mx as mx3 } from "@dxos/react-ui-theme";
|
|
278
295
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
279
296
|
const [selected, setSelectedId] = useState2(null);
|
|
280
297
|
const [isNewOption, setIsNewOption] = useState2(false);
|
|
@@ -400,7 +417,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
400
417
|
}, /* @__PURE__ */ React5.createElement(List.Item, {
|
|
401
418
|
role: "button",
|
|
402
419
|
item,
|
|
403
|
-
classNames:
|
|
420
|
+
classNames: mx3("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
404
421
|
"aria-expanded": selected === item.id
|
|
405
422
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
406
423
|
className: "flex items-center"
|
|
@@ -441,7 +458,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
441
458
|
role: "listitem"
|
|
442
459
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
443
460
|
role: "button",
|
|
444
|
-
className:
|
|
461
|
+
className: mx3("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
445
462
|
onClick: handleAdd
|
|
446
463
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
447
464
|
className: "flex items-center gap-1"
|
|
@@ -455,7 +472,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
455
472
|
// packages/ui/react-ui-form/src/components/Form/custom/TupleInput.tsx
|
|
456
473
|
import React6 from "react";
|
|
457
474
|
import { Input as Input5 } from "@dxos/react-ui";
|
|
458
|
-
import { mx as
|
|
475
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
459
476
|
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
460
477
|
var gridCols = [
|
|
461
478
|
"grid-cols-1",
|
|
@@ -471,7 +488,7 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
471
488
|
}, /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
472
489
|
error
|
|
473
490
|
}, /* @__PURE__ */ React6.createElement(Input5.Label, null, label)), /* @__PURE__ */ React6.createElement("div", {
|
|
474
|
-
className:
|
|
491
|
+
className: mx4("grid gap-2", gridCols[binding.length - 1])
|
|
475
492
|
}, binding.map((prop) => /* @__PURE__ */ React6.createElement(Input5.TextInput, {
|
|
476
493
|
key: prop,
|
|
477
494
|
type: "number",
|
|
@@ -531,23 +548,28 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
|
|
|
531
548
|
};
|
|
532
549
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
533
550
|
const { status, error } = getStatus();
|
|
551
|
+
const value = getValue3();
|
|
552
|
+
const handleValueChange = useCallback3((value2) => onValueChange(type, value2), [
|
|
553
|
+
type,
|
|
554
|
+
onValueChange
|
|
555
|
+
]);
|
|
534
556
|
return /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
535
557
|
validationValence: status
|
|
536
558
|
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
537
559
|
error
|
|
538
560
|
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), /* @__PURE__ */ React7.createElement(Select.Root, {
|
|
539
|
-
value
|
|
540
|
-
onValueChange:
|
|
561
|
+
value,
|
|
562
|
+
onValueChange: handleValueChange
|
|
541
563
|
}, /* @__PURE__ */ React7.createElement(Select.TriggerButton, {
|
|
542
564
|
classNames: "is-full",
|
|
543
565
|
disabled,
|
|
544
566
|
placeholder
|
|
545
|
-
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
567
|
+
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
546
568
|
// NOTE: Numeric values are converted to and from strings.
|
|
547
569
|
/* @__PURE__ */ React7.createElement(Select.Option, {
|
|
548
|
-
key: String(
|
|
549
|
-
value: String(
|
|
550
|
-
}, label2 ?? String(
|
|
570
|
+
key: String(value2),
|
|
571
|
+
value: String(value2)
|
|
572
|
+
}, label2 ?? String(value2))
|
|
551
573
|
)))))), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
|
|
552
574
|
};
|
|
553
575
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
@@ -591,13 +613,13 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
|
|
|
591
613
|
};
|
|
592
614
|
|
|
593
615
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
594
|
-
import
|
|
595
|
-
import { mx as
|
|
616
|
+
import React13, { useEffect as useEffect7, useMemo as useMemo6, useRef as useRef3 } from "react";
|
|
617
|
+
import { mx as mx8 } from "@dxos/react-ui-theme";
|
|
596
618
|
|
|
597
619
|
// packages/ui/react-ui-form/src/components/Form/FormActions.tsx
|
|
598
620
|
import React9 from "react";
|
|
599
621
|
import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
600
|
-
import { mx as
|
|
622
|
+
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
601
623
|
|
|
602
624
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
603
625
|
import React8, { createContext, useContext, useEffect as useEffect5, useMemo as useMemo3 } from "react";
|
|
@@ -606,7 +628,7 @@ import { getValue as getValue2 } from "@dxos/echo-schema";
|
|
|
606
628
|
import { createJsonPath as createJsonPath2 } from "@dxos/effect";
|
|
607
629
|
|
|
608
630
|
// packages/ui/react-ui-form/src/hooks/useForm.ts
|
|
609
|
-
import { SchemaAST
|
|
631
|
+
import { SchemaAST } from "effect";
|
|
610
632
|
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
|
|
611
633
|
import { getValue, setValue } from "@dxos/echo-schema";
|
|
612
634
|
import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
|
|
@@ -615,12 +637,12 @@ import { log } from "@dxos/log";
|
|
|
615
637
|
import { validateSchema } from "@dxos/schema";
|
|
616
638
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
617
639
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
618
|
-
invariant(
|
|
640
|
+
invariant(SchemaAST.isTypeLiteral(schema.ast), void 0, {
|
|
619
641
|
F: __dxlog_file,
|
|
620
642
|
L: 93,
|
|
621
643
|
S: void 0,
|
|
622
644
|
A: [
|
|
623
|
-
"
|
|
645
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
624
646
|
""
|
|
625
647
|
]
|
|
626
648
|
});
|
|
@@ -814,6 +836,35 @@ var flatMap = (errors) => {
|
|
|
814
836
|
}, {});
|
|
815
837
|
};
|
|
816
838
|
|
|
839
|
+
// packages/ui/react-ui-form/src/hooks/useRefQueryLookupHandler.ts
|
|
840
|
+
import { useCallback as useCallback5 } from "react";
|
|
841
|
+
import { getDXN } from "@dxos/echo-schema";
|
|
842
|
+
import { Filter } from "@dxos/react-client/echo";
|
|
843
|
+
import { isNonNullable } from "@dxos/util";
|
|
844
|
+
var useRefQueryLookupHandler = ({ space }) => {
|
|
845
|
+
const handleRefQueryLookup = useCallback5(async (typeInfo) => {
|
|
846
|
+
if (!space) {
|
|
847
|
+
return [];
|
|
848
|
+
}
|
|
849
|
+
const query = space.db.query(Filter.typename(typeInfo.typename));
|
|
850
|
+
const { objects } = await query.run();
|
|
851
|
+
return objects.map((object) => {
|
|
852
|
+
const dxn = getDXN(object);
|
|
853
|
+
if (!dxn) {
|
|
854
|
+
return void 0;
|
|
855
|
+
}
|
|
856
|
+
const item = {
|
|
857
|
+
dxn,
|
|
858
|
+
label: object?.name ?? object?.id ?? ""
|
|
859
|
+
};
|
|
860
|
+
return item;
|
|
861
|
+
}).filter(isNonNullable);
|
|
862
|
+
}, [
|
|
863
|
+
space
|
|
864
|
+
]);
|
|
865
|
+
return handleRefQueryLookup;
|
|
866
|
+
};
|
|
867
|
+
|
|
817
868
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
818
869
|
var FormContext = /* @__PURE__ */ createContext(void 0);
|
|
819
870
|
var useFormContext = () => {
|
|
@@ -888,7 +939,7 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
888
939
|
className: "mt-2 flex justify-center"
|
|
889
940
|
}, /* @__PURE__ */ React9.createElement("div", {
|
|
890
941
|
role: "none",
|
|
891
|
-
className:
|
|
942
|
+
className: mx5(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
892
943
|
}, onCancel && !readonly && /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
893
944
|
"data-testid": "cancel-button",
|
|
894
945
|
icon: "ph--x--regular",
|
|
@@ -905,34 +956,32 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
905
956
|
};
|
|
906
957
|
|
|
907
958
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
908
|
-
import { pipe as pipe2 } from "effect";
|
|
959
|
+
import { Schema, SchemaAST as SchemaAST3, pipe as pipe2 } from "effect";
|
|
909
960
|
import { capitalize as capitalize2 } from "effect/String";
|
|
910
|
-
import
|
|
911
|
-
import { AST as AST3, S } from "@dxos/echo-schema";
|
|
961
|
+
import React12, { useMemo as useMemo5 } from "react";
|
|
912
962
|
import { createJsonPath as createJsonPath3, findNode as findNode2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
913
|
-
import { mx as
|
|
963
|
+
import { mx as mx7 } from "@dxos/react-ui-theme";
|
|
914
964
|
import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
|
|
915
965
|
import { isNotFalsy } from "@dxos/util";
|
|
916
966
|
|
|
917
967
|
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
918
|
-
import { pipe } from "effect";
|
|
968
|
+
import { SchemaAST as SchemaAST2, pipe } from "effect";
|
|
919
969
|
import { capitalize } from "effect/String";
|
|
920
|
-
import React10, { useCallback as
|
|
921
|
-
import { AST as AST2 } from "@dxos/echo-schema";
|
|
970
|
+
import React10, { useCallback as useCallback6, useMemo as useMemo4 } from "react";
|
|
922
971
|
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
923
972
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
924
973
|
import { IconButton as IconButton3, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
925
|
-
import { mx as
|
|
974
|
+
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
926
975
|
import { getSchemaProperties } from "@dxos/schema";
|
|
927
976
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
928
977
|
var padding = "px-2";
|
|
929
978
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
930
979
|
const { t } = useTranslation5(translationKey);
|
|
931
980
|
const { ast, name, type, title } = property;
|
|
932
|
-
const values = useFormValues(path ?? []);
|
|
981
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
933
982
|
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
934
983
|
F: __dxlog_file2,
|
|
935
|
-
L:
|
|
984
|
+
L: 38,
|
|
936
985
|
S: void 0,
|
|
937
986
|
A: [
|
|
938
987
|
"Array.isArray(values)",
|
|
@@ -940,11 +989,11 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
940
989
|
]
|
|
941
990
|
});
|
|
942
991
|
const label = title ?? pipe(name, capitalize);
|
|
943
|
-
const tupleType = findNode(ast,
|
|
992
|
+
const tupleType = findNode(ast, SchemaAST2.isTupleType);
|
|
944
993
|
const elementType = tupleType?.rest[0]?.type;
|
|
945
994
|
const getDefaultObjectValue = (typeNode) => {
|
|
946
995
|
const baseNode = findNode(typeNode, isDiscriminatedUnion);
|
|
947
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode,
|
|
996
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, SchemaAST2.isTypeLiteral);
|
|
948
997
|
if (!typeLiteral) {
|
|
949
998
|
return {};
|
|
950
999
|
}
|
|
@@ -963,7 +1012,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
963
1012
|
type,
|
|
964
1013
|
elementType
|
|
965
1014
|
]);
|
|
966
|
-
const handleAdd =
|
|
1015
|
+
const handleAdd = useCallback6(() => {
|
|
967
1016
|
inputProps.onValueChange(type, [
|
|
968
1017
|
...values,
|
|
969
1018
|
newValue
|
|
@@ -975,7 +1024,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
975
1024
|
newValue,
|
|
976
1025
|
values
|
|
977
1026
|
]);
|
|
978
|
-
const handleRemove =
|
|
1027
|
+
const handleRemove = useCallback6((index) => {
|
|
979
1028
|
const newValues = values.filter((_, i) => i !== index);
|
|
980
1029
|
inputProps.onValueChange(type, newValues);
|
|
981
1030
|
}, [
|
|
@@ -988,7 +1037,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
988
1037
|
}
|
|
989
1038
|
return /* @__PURE__ */ React10.createElement("div", {
|
|
990
1039
|
role: "none",
|
|
991
|
-
className:
|
|
1040
|
+
className: mx6(padding)
|
|
992
1041
|
}, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
993
1042
|
role: "none",
|
|
994
1043
|
className: "flex flex-col gap-1"
|
|
@@ -1029,6 +1078,108 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1029
1078
|
})));
|
|
1030
1079
|
};
|
|
1031
1080
|
|
|
1081
|
+
// packages/ui/react-ui-form/src/components/Form/RefField.tsx
|
|
1082
|
+
import React11, { useEffect as useEffect6, useState as useState4 } from "react";
|
|
1083
|
+
import { Expando, getTypeAnnotation, Ref, ReferenceAnnotationId } from "@dxos/echo-schema";
|
|
1084
|
+
import { findAnnotation } from "@dxos/effect";
|
|
1085
|
+
import { DXN } from "@dxos/keys";
|
|
1086
|
+
import { refFromDXN } from "@dxos/live-object";
|
|
1087
|
+
import { log as log2 } from "@dxos/log";
|
|
1088
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/RefField.tsx";
|
|
1089
|
+
var RefField = ({ ast, type, label, readonly, placeholder, inline, onQueryRefOptions, inputProps }) => {
|
|
1090
|
+
const { getValue: getValue3, onValueChange, ...restInputProps } = inputProps;
|
|
1091
|
+
const refTypeInfo = findAnnotation(ast, ReferenceAnnotationId);
|
|
1092
|
+
const [refOptions, setRefOptions] = useState4([]);
|
|
1093
|
+
const [loading, setLoading] = useState4(false);
|
|
1094
|
+
useEffect6(() => {
|
|
1095
|
+
if (!refTypeInfo || !onQueryRefOptions) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
const fetchOptions = async () => {
|
|
1099
|
+
setLoading(true);
|
|
1100
|
+
try {
|
|
1101
|
+
const options = await onQueryRefOptions(refTypeInfo);
|
|
1102
|
+
setRefOptions(options.map((option) => ({
|
|
1103
|
+
label: option.label,
|
|
1104
|
+
value: option.dxn.toString()
|
|
1105
|
+
})));
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
log2.error("Failed to fetch ref options:", error, {
|
|
1108
|
+
F: __dxlog_file3,
|
|
1109
|
+
L: 69,
|
|
1110
|
+
S: void 0,
|
|
1111
|
+
C: (f, a) => f(...a)
|
|
1112
|
+
});
|
|
1113
|
+
setRefOptions([]);
|
|
1114
|
+
} finally {
|
|
1115
|
+
setLoading(false);
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
void fetchOptions();
|
|
1119
|
+
}, [
|
|
1120
|
+
refTypeInfo,
|
|
1121
|
+
onQueryRefOptions
|
|
1122
|
+
]);
|
|
1123
|
+
if (!refTypeInfo) {
|
|
1124
|
+
return null;
|
|
1125
|
+
}
|
|
1126
|
+
if (refTypeInfo.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
|
|
1127
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1128
|
+
const dxn = DXN.tryParse(dxnString);
|
|
1129
|
+
if (dxn) {
|
|
1130
|
+
onValueChange?.("object", refFromDXN(dxn));
|
|
1131
|
+
} else if (dxnString === "") {
|
|
1132
|
+
onValueChange?.("object", void 0);
|
|
1133
|
+
} else {
|
|
1134
|
+
onValueChange?.("string", dxnString);
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
const handleGetValue2 = () => {
|
|
1138
|
+
const formValue = getValue3();
|
|
1139
|
+
if (typeof formValue === "string") {
|
|
1140
|
+
return formValue;
|
|
1141
|
+
}
|
|
1142
|
+
if (Ref.isRef(formValue)) {
|
|
1143
|
+
return formValue.dxn.toString();
|
|
1144
|
+
}
|
|
1145
|
+
return void 0;
|
|
1146
|
+
};
|
|
1147
|
+
return /* @__PURE__ */ React11.createElement(TextInput, {
|
|
1148
|
+
type,
|
|
1149
|
+
label,
|
|
1150
|
+
disabled: readonly,
|
|
1151
|
+
placeholder,
|
|
1152
|
+
inputOnly: inline,
|
|
1153
|
+
getValue: handleGetValue2,
|
|
1154
|
+
onValueChange: handleOnValueChange,
|
|
1155
|
+
...restInputProps
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
const handleGetValue = () => {
|
|
1159
|
+
const formValue = getValue3();
|
|
1160
|
+
if (Ref.isRef(formValue)) {
|
|
1161
|
+
return formValue.dxn.toString();
|
|
1162
|
+
}
|
|
1163
|
+
return void 0;
|
|
1164
|
+
};
|
|
1165
|
+
const handleValueChanged = (_type, dxnString) => {
|
|
1166
|
+
const dxn = DXN.parse(dxnString);
|
|
1167
|
+
const ref = refFromDXN(dxn);
|
|
1168
|
+
onValueChange("object", ref);
|
|
1169
|
+
};
|
|
1170
|
+
return /* @__PURE__ */ React11.createElement(SelectInput, {
|
|
1171
|
+
type,
|
|
1172
|
+
label,
|
|
1173
|
+
disabled: readonly || loading,
|
|
1174
|
+
placeholder: loading ? "Loading options..." : placeholder,
|
|
1175
|
+
inputOnly: inline,
|
|
1176
|
+
getValue: handleGetValue,
|
|
1177
|
+
onValueChange: handleValueChanged,
|
|
1178
|
+
options: refOptions,
|
|
1179
|
+
...restInputProps
|
|
1180
|
+
});
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1032
1183
|
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
1033
1184
|
import { FormatEnum } from "@dxos/echo-schema";
|
|
1034
1185
|
var getInputComponent = (type, format) => {
|
|
@@ -1049,7 +1200,7 @@ var getInputComponent = (type, format) => {
|
|
|
1049
1200
|
};
|
|
1050
1201
|
|
|
1051
1202
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
1052
|
-
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
1203
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1053
1204
|
const inputProps = useInputProps(path);
|
|
1054
1205
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1055
1206
|
const label = useMemo5(() => title ?? pipe2(name, capitalize2), [
|
|
@@ -1062,7 +1213,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1062
1213
|
]);
|
|
1063
1214
|
const FoundComponent = lookupComponent?.({
|
|
1064
1215
|
prop: name,
|
|
1065
|
-
schema:
|
|
1216
|
+
schema: Schema.make(ast),
|
|
1066
1217
|
inputProps: {
|
|
1067
1218
|
type,
|
|
1068
1219
|
format,
|
|
@@ -1073,14 +1224,14 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1073
1224
|
}
|
|
1074
1225
|
});
|
|
1075
1226
|
if (FoundComponent) {
|
|
1076
|
-
return /* @__PURE__ */
|
|
1227
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1077
1228
|
role: "none"
|
|
1078
1229
|
}, FoundComponent);
|
|
1079
1230
|
}
|
|
1080
1231
|
const jsonPath = createJsonPath3(path ?? []);
|
|
1081
1232
|
const CustomComponent = Custom?.[jsonPath];
|
|
1082
1233
|
if (CustomComponent) {
|
|
1083
|
-
return /* @__PURE__ */
|
|
1234
|
+
return /* @__PURE__ */ React12.createElement(CustomComponent, {
|
|
1084
1235
|
type,
|
|
1085
1236
|
format,
|
|
1086
1237
|
label,
|
|
@@ -1091,7 +1242,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1091
1242
|
});
|
|
1092
1243
|
}
|
|
1093
1244
|
if (array) {
|
|
1094
|
-
return /* @__PURE__ */
|
|
1245
|
+
return /* @__PURE__ */ React12.createElement(ArrayField, {
|
|
1095
1246
|
property,
|
|
1096
1247
|
path,
|
|
1097
1248
|
inputProps,
|
|
@@ -1101,9 +1252,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1101
1252
|
}
|
|
1102
1253
|
const InputComponent = getInputComponent(type, format);
|
|
1103
1254
|
if (InputComponent) {
|
|
1104
|
-
return /* @__PURE__ */
|
|
1255
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1105
1256
|
role: "none"
|
|
1106
|
-
}, /* @__PURE__ */
|
|
1257
|
+
}, /* @__PURE__ */ React12.createElement(InputComponent, {
|
|
1107
1258
|
type,
|
|
1108
1259
|
format,
|
|
1109
1260
|
label,
|
|
@@ -1114,9 +1265,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1114
1265
|
}));
|
|
1115
1266
|
}
|
|
1116
1267
|
if (options) {
|
|
1117
|
-
return /* @__PURE__ */
|
|
1268
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1118
1269
|
role: "none"
|
|
1119
|
-
}, /* @__PURE__ */
|
|
1270
|
+
}, /* @__PURE__ */ React12.createElement(SelectInput, {
|
|
1120
1271
|
type,
|
|
1121
1272
|
format,
|
|
1122
1273
|
disabled: readonly,
|
|
@@ -1130,23 +1281,39 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1130
1281
|
...inputProps
|
|
1131
1282
|
}));
|
|
1132
1283
|
}
|
|
1284
|
+
if (format === "ref") {
|
|
1285
|
+
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1286
|
+
ast,
|
|
1287
|
+
type,
|
|
1288
|
+
label,
|
|
1289
|
+
readonly,
|
|
1290
|
+
placeholder,
|
|
1291
|
+
inline,
|
|
1292
|
+
onQueryRefOptions,
|
|
1293
|
+
inputProps
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1133
1296
|
if (type === "object") {
|
|
1134
1297
|
const baseNode = findNode2(ast, isDiscriminatedUnion2);
|
|
1135
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode2(ast,
|
|
1298
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode2(ast, SchemaAST3.isTypeLiteral);
|
|
1136
1299
|
if (typeLiteral) {
|
|
1137
|
-
return /* @__PURE__ */
|
|
1300
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1138
1301
|
role: "none"
|
|
1139
|
-
}, !inline && /* @__PURE__ */
|
|
1140
|
-
|
|
1302
|
+
}, !inline && /* @__PURE__ */ React12.createElement("h3", {
|
|
1303
|
+
className: "text-lg mbs-2 mbe-1"
|
|
1304
|
+
}, label), /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1305
|
+
schema: Schema.make(typeLiteral),
|
|
1141
1306
|
path,
|
|
1142
1307
|
readonly,
|
|
1143
|
-
|
|
1308
|
+
onQueryRefOptions,
|
|
1309
|
+
Custom,
|
|
1310
|
+
lookupComponent
|
|
1144
1311
|
}));
|
|
1145
1312
|
}
|
|
1146
1313
|
}
|
|
1147
1314
|
return null;
|
|
1148
1315
|
};
|
|
1149
|
-
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1316
|
+
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1150
1317
|
const values = useFormValues(path);
|
|
1151
1318
|
const properties = useMemo5(() => {
|
|
1152
1319
|
const props = getSchemaProperties2(schema.ast, values);
|
|
@@ -1158,11 +1325,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1158
1325
|
filter,
|
|
1159
1326
|
sort
|
|
1160
1327
|
]);
|
|
1161
|
-
return /* @__PURE__ */
|
|
1328
|
+
return /* @__PURE__ */ React12.createElement("div", {
|
|
1162
1329
|
role: "form",
|
|
1163
|
-
className:
|
|
1330
|
+
className: mx7("flex flex-col w-full gap-2")
|
|
1164
1331
|
}, properties.map((property) => {
|
|
1165
|
-
return /* @__PURE__ */
|
|
1332
|
+
return /* @__PURE__ */ React12.createElement(FormField, {
|
|
1166
1333
|
key: property.name,
|
|
1167
1334
|
property,
|
|
1168
1335
|
path: [
|
|
@@ -1170,6 +1337,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1170
1337
|
property.name
|
|
1171
1338
|
],
|
|
1172
1339
|
readonly,
|
|
1340
|
+
onQueryRefOptions,
|
|
1173
1341
|
lookupComponent,
|
|
1174
1342
|
Custom
|
|
1175
1343
|
});
|
|
@@ -1177,13 +1345,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1177
1345
|
};
|
|
1178
1346
|
|
|
1179
1347
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
1180
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1348
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1181
1349
|
const formRef = useRef3(null);
|
|
1182
1350
|
const onValid = useMemo6(() => autoSave ? onSave : void 0, [
|
|
1183
1351
|
autoSave,
|
|
1184
1352
|
onSave
|
|
1185
1353
|
]);
|
|
1186
|
-
|
|
1354
|
+
useEffect7(() => {
|
|
1187
1355
|
if (autoFocus && formRef.current) {
|
|
1188
1356
|
const input = formRef.current.querySelector("input");
|
|
1189
1357
|
if (input) {
|
|
@@ -1193,7 +1361,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1193
1361
|
}, [
|
|
1194
1362
|
autoFocus
|
|
1195
1363
|
]);
|
|
1196
|
-
return /* @__PURE__ */
|
|
1364
|
+
return /* @__PURE__ */ React13.createElement(FormProvider, {
|
|
1197
1365
|
formRef,
|
|
1198
1366
|
schema,
|
|
1199
1367
|
autoSave,
|
|
@@ -1202,36 +1370,37 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1202
1370
|
onValidate,
|
|
1203
1371
|
onValid,
|
|
1204
1372
|
onSave
|
|
1205
|
-
}, /* @__PURE__ */
|
|
1373
|
+
}, /* @__PURE__ */ React13.createElement("div", {
|
|
1206
1374
|
ref: formRef,
|
|
1207
1375
|
role: "none",
|
|
1208
|
-
className:
|
|
1376
|
+
className: mx8("p-2", classNames),
|
|
1209
1377
|
"data-testid": testId
|
|
1210
|
-
}, /* @__PURE__ */
|
|
1378
|
+
}, /* @__PURE__ */ React13.createElement(FormFields, {
|
|
1211
1379
|
schema,
|
|
1212
1380
|
path,
|
|
1213
1381
|
readonly,
|
|
1214
1382
|
filter,
|
|
1215
1383
|
sort,
|
|
1384
|
+
onQueryRefOptions,
|
|
1216
1385
|
lookupComponent,
|
|
1217
1386
|
Custom
|
|
1218
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1387
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React13.createElement(FormActions, {
|
|
1219
1388
|
onCancel,
|
|
1220
1389
|
readonly
|
|
1221
1390
|
})));
|
|
1222
1391
|
};
|
|
1223
1392
|
|
|
1224
1393
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
1225
|
-
var
|
|
1394
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1226
1395
|
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1227
1396
|
const { t } = useTranslation6(translationKey);
|
|
1228
|
-
const [props, setProps] =
|
|
1229
|
-
|
|
1397
|
+
const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
|
|
1398
|
+
useEffect8(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1230
1399
|
field,
|
|
1231
1400
|
projection
|
|
1232
1401
|
]);
|
|
1233
|
-
const [schemas, setSchemas] =
|
|
1234
|
-
|
|
1402
|
+
const [schemas, setSchemas] = useState5([]);
|
|
1403
|
+
useEffect8(() => {
|
|
1235
1404
|
if (!registry) {
|
|
1236
1405
|
return;
|
|
1237
1406
|
}
|
|
@@ -1249,17 +1418,17 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1249
1418
|
}, [
|
|
1250
1419
|
registry
|
|
1251
1420
|
]);
|
|
1252
|
-
const [referenceSchema, setReferenceSchema] =
|
|
1253
|
-
|
|
1421
|
+
const [referenceSchema, setReferenceSchema] = useState5();
|
|
1422
|
+
useEffect8(() => {
|
|
1254
1423
|
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1255
1424
|
}, [
|
|
1256
1425
|
schemas,
|
|
1257
1426
|
props?.referenceSchema
|
|
1258
1427
|
]);
|
|
1259
|
-
const [{ fieldSchema }, setFieldSchema] =
|
|
1428
|
+
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
1260
1429
|
fieldSchema: getFormatSchema(props?.format)
|
|
1261
1430
|
});
|
|
1262
|
-
const handleValuesChanged =
|
|
1431
|
+
const handleValuesChanged = useCallback7((_props) => {
|
|
1263
1432
|
setFieldSchema((prev) => {
|
|
1264
1433
|
const fieldSchema2 = getFormatSchema(_props.format);
|
|
1265
1434
|
if (prev.fieldSchema === fieldSchema2) {
|
|
@@ -1294,7 +1463,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1294
1463
|
props.format,
|
|
1295
1464
|
props.referenceSchema
|
|
1296
1465
|
]);
|
|
1297
|
-
const handleValidate =
|
|
1466
|
+
const handleValidate = useCallback7(({ property }) => {
|
|
1298
1467
|
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
1299
1468
|
return [
|
|
1300
1469
|
{
|
|
@@ -1307,7 +1476,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1307
1476
|
view.fields,
|
|
1308
1477
|
field
|
|
1309
1478
|
]);
|
|
1310
|
-
const handleSave =
|
|
1479
|
+
const handleSave = useCallback7((props2) => {
|
|
1311
1480
|
projection.setFieldProjection({
|
|
1312
1481
|
field,
|
|
1313
1482
|
props: props2
|
|
@@ -1318,51 +1487,51 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1318
1487
|
field,
|
|
1319
1488
|
onSave
|
|
1320
1489
|
]);
|
|
1321
|
-
const handleCancel =
|
|
1490
|
+
const handleCancel = useCallback7(() => {
|
|
1322
1491
|
requestAnimationFrame(() => onCancel?.());
|
|
1323
1492
|
onSave();
|
|
1324
1493
|
}, [
|
|
1325
1494
|
onSave
|
|
1326
1495
|
]);
|
|
1327
1496
|
const Custom = useMemo7(() => ({
|
|
1328
|
-
["format"]: (props2) => /* @__PURE__ */
|
|
1497
|
+
["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
1329
1498
|
...props2,
|
|
1330
1499
|
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
1331
1500
|
value,
|
|
1332
1501
|
label: t(`format ${value}`)
|
|
1333
1502
|
}))
|
|
1334
1503
|
}),
|
|
1335
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */
|
|
1504
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
1336
1505
|
...props2,
|
|
1337
1506
|
options: schemas.map((schema) => ({
|
|
1338
1507
|
value: schema.typename
|
|
1339
1508
|
}))
|
|
1340
1509
|
}),
|
|
1341
|
-
["referencePath"]: (props2) => /* @__PURE__ */
|
|
1510
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
1342
1511
|
...props2,
|
|
1343
1512
|
options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
|
|
1344
1513
|
value: p.name
|
|
1345
1514
|
})) : []
|
|
1346
1515
|
}),
|
|
1347
|
-
["options"]: (props2) => /* @__PURE__ */
|
|
1516
|
+
["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
|
|
1348
1517
|
}), [
|
|
1349
1518
|
t,
|
|
1350
1519
|
schemas,
|
|
1351
1520
|
referenceSchema
|
|
1352
1521
|
]);
|
|
1353
|
-
const propIsNotType =
|
|
1522
|
+
const propIsNotType = useCallback7((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
1354
1523
|
if (!fieldSchema) {
|
|
1355
|
-
|
|
1524
|
+
log3.warn("invalid format", {
|
|
1356
1525
|
props
|
|
1357
1526
|
}, {
|
|
1358
|
-
F:
|
|
1527
|
+
F: __dxlog_file4,
|
|
1359
1528
|
L: 174,
|
|
1360
1529
|
S: void 0,
|
|
1361
1530
|
C: (f, a) => f(...a)
|
|
1362
1531
|
});
|
|
1363
1532
|
return null;
|
|
1364
1533
|
}
|
|
1365
|
-
return /* @__PURE__ */
|
|
1534
|
+
return /* @__PURE__ */ React14.createElement(Form, {
|
|
1366
1535
|
key: field.id,
|
|
1367
1536
|
autoFocus: true,
|
|
1368
1537
|
values: props,
|
|
@@ -1381,30 +1550,31 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1381
1550
|
};
|
|
1382
1551
|
|
|
1383
1552
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
1384
|
-
import
|
|
1385
|
-
import {
|
|
1553
|
+
import { Schema as Schema2, SchemaAST as SchemaAST4 } from "effect";
|
|
1554
|
+
import React15, { useCallback as useCallback8, useMemo as useMemo8, useState as useState6 } from "react";
|
|
1555
|
+
import { Format } from "@dxos/echo-schema";
|
|
1386
1556
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1387
1557
|
import { IconButton as IconButton4, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1388
1558
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
1389
|
-
import { ghostHover, inputTextLabel, mx as
|
|
1559
|
+
import { ghostHover, inputTextLabel, mx as mx9 } from "@dxos/react-ui-theme";
|
|
1390
1560
|
import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1391
|
-
var
|
|
1561
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1392
1562
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1393
|
-
var ViewMetaSchema =
|
|
1394
|
-
name:
|
|
1395
|
-
[
|
|
1563
|
+
var ViewMetaSchema = Schema2.Struct({
|
|
1564
|
+
name: Schema2.String.annotations({
|
|
1565
|
+
[SchemaAST4.TitleAnnotationId]: "View"
|
|
1396
1566
|
}),
|
|
1397
1567
|
typename: Format.URL.annotations({
|
|
1398
|
-
[
|
|
1568
|
+
[SchemaAST4.TitleAnnotationId]: "Typename"
|
|
1399
1569
|
})
|
|
1400
|
-
}).pipe(
|
|
1570
|
+
}).pipe(Schema2.mutable);
|
|
1401
1571
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1402
1572
|
const { t } = useTranslation7(translationKey);
|
|
1403
1573
|
const projection = useMemo8(() => new ViewProjection(schema.jsonSchema, view), [
|
|
1404
1574
|
schema,
|
|
1405
1575
|
view
|
|
1406
1576
|
]);
|
|
1407
|
-
const [field, setField] =
|
|
1577
|
+
const [field, setField] = useState6();
|
|
1408
1578
|
const viewValues = useMemo8(() => {
|
|
1409
1579
|
return {
|
|
1410
1580
|
name: view.name,
|
|
@@ -1415,13 +1585,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1415
1585
|
}, [
|
|
1416
1586
|
view
|
|
1417
1587
|
]);
|
|
1418
|
-
const handleSelect =
|
|
1588
|
+
const handleSelect = useCallback8((field2) => {
|
|
1419
1589
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1420
1590
|
}, []);
|
|
1421
|
-
const handleAdd =
|
|
1591
|
+
const handleAdd = useCallback8(() => {
|
|
1422
1592
|
invariant3(!schema.readonly, void 0, {
|
|
1423
|
-
F:
|
|
1424
|
-
L:
|
|
1593
|
+
F: __dxlog_file5,
|
|
1594
|
+
L: 77,
|
|
1425
1595
|
S: void 0,
|
|
1426
1596
|
A: [
|
|
1427
1597
|
"!schema.readonly",
|
|
@@ -1434,10 +1604,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1434
1604
|
schema,
|
|
1435
1605
|
view
|
|
1436
1606
|
]);
|
|
1437
|
-
const handleUpdate =
|
|
1607
|
+
const handleUpdate = useCallback8(({ name, typename }) => {
|
|
1438
1608
|
invariant3(!schema.readonly, void 0, {
|
|
1439
|
-
F:
|
|
1440
|
-
L:
|
|
1609
|
+
F: __dxlog_file5,
|
|
1610
|
+
L: 84,
|
|
1441
1611
|
S: void 0,
|
|
1442
1612
|
A: [
|
|
1443
1613
|
"!schema.readonly",
|
|
@@ -1457,10 +1627,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1457
1627
|
view,
|
|
1458
1628
|
onTypenameChanged
|
|
1459
1629
|
]);
|
|
1460
|
-
const handleDelete =
|
|
1630
|
+
const handleDelete = useCallback8((fieldId) => {
|
|
1461
1631
|
invariant3(!schema.readonly, void 0, {
|
|
1462
|
-
F:
|
|
1463
|
-
L:
|
|
1632
|
+
F: __dxlog_file5,
|
|
1633
|
+
L: 100,
|
|
1464
1634
|
S: void 0,
|
|
1465
1635
|
A: [
|
|
1466
1636
|
"!schema.readonly",
|
|
@@ -1476,10 +1646,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1476
1646
|
field,
|
|
1477
1647
|
onDelete
|
|
1478
1648
|
]);
|
|
1479
|
-
const handleMove =
|
|
1649
|
+
const handleMove = useCallback8((fromIndex, toIndex) => {
|
|
1480
1650
|
invariant3(!schema.readonly, void 0, {
|
|
1481
|
-
F:
|
|
1482
|
-
L:
|
|
1651
|
+
F: __dxlog_file5,
|
|
1652
|
+
L: 112,
|
|
1483
1653
|
S: void 0,
|
|
1484
1654
|
A: [
|
|
1485
1655
|
"!schema.readonly",
|
|
@@ -1496,91 +1666,95 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1496
1666
|
schema,
|
|
1497
1667
|
view.fields
|
|
1498
1668
|
]);
|
|
1499
|
-
const handleClose =
|
|
1669
|
+
const handleClose = useCallback8(() => setField(void 0), []);
|
|
1500
1670
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1501
|
-
const handleHide =
|
|
1671
|
+
const handleHide = useCallback8((fieldId) => {
|
|
1502
1672
|
setField(void 0);
|
|
1503
1673
|
projection.hideFieldProjection(fieldId);
|
|
1504
1674
|
}, [
|
|
1505
1675
|
projection
|
|
1506
1676
|
]);
|
|
1507
|
-
const handleShow =
|
|
1677
|
+
const handleShow = useCallback8((property) => {
|
|
1508
1678
|
setField(void 0);
|
|
1509
1679
|
projection.showFieldProjection(property);
|
|
1510
1680
|
}, [
|
|
1511
1681
|
projection
|
|
1512
1682
|
]);
|
|
1513
|
-
return /* @__PURE__ */
|
|
1683
|
+
return /* @__PURE__ */ React15.createElement("div", {
|
|
1514
1684
|
role: "none",
|
|
1515
|
-
className:
|
|
1516
|
-
}, /* @__PURE__ */
|
|
1685
|
+
className: mx9("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1686
|
+
}, /* @__PURE__ */ React15.createElement(Form, {
|
|
1517
1687
|
autoSave: true,
|
|
1518
1688
|
schema: ViewMetaSchema,
|
|
1519
1689
|
values: viewValues,
|
|
1520
|
-
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1521
|
-
|
|
1690
|
+
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
1691
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
1692
|
+
}), /* @__PURE__ */ React15.createElement("div", {
|
|
1693
|
+
role: "none",
|
|
1694
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
1695
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
1522
1696
|
role: "none",
|
|
1523
1697
|
className: "p-2"
|
|
1524
|
-
}, /* @__PURE__ */
|
|
1525
|
-
className:
|
|
1526
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1698
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1699
|
+
className: mx9(inputTextLabel)
|
|
1700
|
+
}, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1527
1701
|
items: view.fields,
|
|
1528
|
-
isItem:
|
|
1702
|
+
isItem: Schema2.is(FieldSchema),
|
|
1529
1703
|
getId: (field2) => field2.id,
|
|
1530
1704
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1531
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1705
|
+
}, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
|
|
1532
1706
|
role: "heading",
|
|
1533
1707
|
className: grid
|
|
1534
|
-
}, /* @__PURE__ */
|
|
1708
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
|
|
1535
1709
|
className: "flex items-center text-sm"
|
|
1536
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1710
|
+
}, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
|
|
1537
1711
|
role: "list",
|
|
1538
1712
|
className: "flex flex-col w-full"
|
|
1539
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1713
|
+
}, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
1540
1714
|
key: field2.id,
|
|
1541
1715
|
item: field2,
|
|
1542
|
-
classNames:
|
|
1543
|
-
}, /* @__PURE__ */
|
|
1716
|
+
classNames: mx9(grid, ghostHover, "cursor-pointer")
|
|
1717
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
|
|
1544
1718
|
onClick: () => handleSelect(field2)
|
|
1545
|
-
}, field2.path), /* @__PURE__ */
|
|
1719
|
+
}, field2.path), /* @__PURE__ */ React15.createElement("div", {
|
|
1546
1720
|
className: "flex items-center gap-2 -ml-4"
|
|
1547
|
-
}, /* @__PURE__ */
|
|
1721
|
+
}, /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
1548
1722
|
icon: "ph--eye-slash--regular",
|
|
1549
1723
|
disabled: view.fields.length <= 1,
|
|
1550
1724
|
onClick: () => handleHide(field2.id)
|
|
1551
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
1725
|
+
}), !schema.readonly && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
1552
1726
|
icon: "ph--trash--regular",
|
|
1553
1727
|
disabled: view.fields.length <= 1,
|
|
1554
1728
|
onClick: () => handleDelete(field2.id)
|
|
1555
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
1729
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
|
|
1556
1730
|
role: "none",
|
|
1557
1731
|
className: "p-2"
|
|
1558
|
-
}, /* @__PURE__ */
|
|
1559
|
-
className:
|
|
1560
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
1732
|
+
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1733
|
+
className: mx9(inputTextLabel)
|
|
1734
|
+
}, t("hidden fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1561
1735
|
items: hiddenProperties,
|
|
1562
1736
|
isItem: (item) => typeof item === "string",
|
|
1563
1737
|
getId: (property) => property
|
|
1564
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
1738
|
+
}, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
|
|
1565
1739
|
role: "list",
|
|
1566
1740
|
className: "flex flex-col w-full"
|
|
1567
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
1741
|
+
}, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
|
|
1568
1742
|
key: property,
|
|
1569
1743
|
item: property,
|
|
1570
|
-
classNames:
|
|
1571
|
-
}, /* @__PURE__ */
|
|
1744
|
+
classNames: mx9(grid, ghostHover, "cursor-pointer")
|
|
1745
|
+
}, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
1572
1746
|
icon: "ph--eye--regular",
|
|
1573
1747
|
onClick: () => handleShow(property)
|
|
1574
|
-
}))))))), field && /* @__PURE__ */
|
|
1748
|
+
}))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
|
|
1575
1749
|
key: field.id,
|
|
1576
1750
|
view,
|
|
1577
1751
|
projection,
|
|
1578
1752
|
field,
|
|
1579
1753
|
registry,
|
|
1580
1754
|
onSave: handleClose
|
|
1581
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1755
|
+
}), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
|
|
1582
1756
|
className: "flex p-2 justify-center"
|
|
1583
|
-
}, /* @__PURE__ */
|
|
1757
|
+
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
1584
1758
|
icon: "ph--plus--regular",
|
|
1585
1759
|
label: t("button add property"),
|
|
1586
1760
|
onClick: schema.readonly ? void 0 : handleAdd,
|
|
@@ -1765,13 +1939,25 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1765
1939
|
});
|
|
1766
1940
|
}
|
|
1767
1941
|
case FormatEnum4.Date: {
|
|
1768
|
-
|
|
1942
|
+
try {
|
|
1943
|
+
return formatDate(new Date(value), "yyyy-MM-dd");
|
|
1944
|
+
} catch (error) {
|
|
1945
|
+
return "Invalid Date";
|
|
1946
|
+
}
|
|
1769
1947
|
}
|
|
1770
1948
|
case FormatEnum4.Time: {
|
|
1771
|
-
|
|
1949
|
+
try {
|
|
1950
|
+
return formatDate(new Date(value), "HH:mm:ss");
|
|
1951
|
+
} catch (error) {
|
|
1952
|
+
return "Invalid Time";
|
|
1953
|
+
}
|
|
1772
1954
|
}
|
|
1773
1955
|
case FormatEnum4.DateTime: {
|
|
1774
|
-
|
|
1956
|
+
try {
|
|
1957
|
+
return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1958
|
+
} catch (error) {
|
|
1959
|
+
return "Invalid DateTime";
|
|
1960
|
+
}
|
|
1775
1961
|
}
|
|
1776
1962
|
case FormatEnum4.GeoPoint: {
|
|
1777
1963
|
if (value === null || value === void 0) {
|
|
@@ -1851,8 +2037,10 @@ export {
|
|
|
1851
2037
|
ControlFrame,
|
|
1852
2038
|
ControlFrameItem,
|
|
1853
2039
|
ControlGroup,
|
|
2040
|
+
ControlGroupButton,
|
|
1854
2041
|
ControlItem,
|
|
1855
2042
|
ControlItemInput,
|
|
2043
|
+
ControlPage,
|
|
1856
2044
|
ControlSection,
|
|
1857
2045
|
ControlSectionHeading,
|
|
1858
2046
|
DeprecatedFormContainer,
|
|
@@ -1879,6 +2067,7 @@ export {
|
|
|
1879
2067
|
useForm,
|
|
1880
2068
|
useFormContext,
|
|
1881
2069
|
useFormValues,
|
|
1882
|
-
useInputProps
|
|
2070
|
+
useInputProps,
|
|
2071
|
+
useRefQueryLookupHandler
|
|
1883
2072
|
};
|
|
1884
2073
|
//# sourceMappingURL=index.mjs.map
|