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