@dxos/react-ui-form 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446
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 +537 -846
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +506 -807
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +537 -846
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/{ControlSection/ControlSection.d.ts → ControlSection.d.ts} +5 -8
- package/dist/types/src/components/ControlSection.d.ts.map +1 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- 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 +4 -6
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +34 -37
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +11 -14
- 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/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
- 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/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -2
- 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/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -2
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -26
- package/src/components/{ControlSection/ControlSection.tsx → ControlSection.tsx} +14 -38
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +17 -13
- package/src/components/Form/Defaults.tsx +1 -4
- package/src/components/Form/Form.stories.tsx +43 -92
- package/src/components/Form/Form.tsx +3 -7
- package/src/components/Form/FormContent.tsx +19 -90
- package/src/components/Form/FormContext.tsx +3 -13
- package/src/components/Form/Input.tsx +9 -3
- package/src/components/Form/custom/GeoPointInput.tsx +2 -2
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +5 -6
- package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/Form/index.ts +1 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +4 -5
- package/src/components/ViewEditor/ViewEditor.tsx +20 -23
- 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 +0 -1
- package/src/hooks/index.ts +1 -3
- package/src/hooks/useForm.ts +3 -4
- package/src/util/formatting.ts +3 -15
- package/src/util/index.ts +1 -3
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -8
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/index.d.ts +0 -2
- package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -12
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/dist/types/src/util/refs.d.ts +0 -9
- package/dist/types/src/util/refs.d.ts.map +0 -1
- package/dist/types/src/util/schema.d.ts +0 -3
- package/dist/types/src/util/schema.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -29
- package/src/components/ControlSection/index.ts +0 -5
- package/src/components/Form/RefField.tsx +0 -197
- package/src/hooks/useQueryRefOptions.ts +0 -53
- package/src/hooks/useRefQueryLookupHandler.ts +0 -41
- package/src/util/refs.ts +0 -38
- package/src/util/schema.ts +0 -14
|
@@ -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: "w-full 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,23 +101,9 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
101
101
|
return primary;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
// packages/ui/react-ui-form/src/components/ControlSection
|
|
104
|
+
// packages/ui/react-ui-form/src/components/ControlSection.tsx
|
|
105
105
|
import React2 from "react";
|
|
106
|
-
import {
|
|
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
|
-
};
|
|
106
|
+
import { toLocalizedString, useTranslation, Input as Input2 } from "@dxos/react-ui";
|
|
121
107
|
var ControlSectionHeading = ({ title, description }) => {
|
|
122
108
|
const { t } = useTranslation(translationKey);
|
|
123
109
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", {
|
|
@@ -126,18 +112,15 @@ var ControlSectionHeading = ({ title, description }) => {
|
|
|
126
112
|
className: "pli-4 mlb-4 container-max-width text-description"
|
|
127
113
|
}, toLocalizedString(description, t)));
|
|
128
114
|
};
|
|
129
|
-
var
|
|
130
|
-
return /* @__PURE__ */ React2.createElement(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
classNames
|
|
135
|
-
]
|
|
136
|
-
});
|
|
115
|
+
var ControlSection = ({ title, description, children }) => {
|
|
116
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ControlSectionHeading, {
|
|
117
|
+
title,
|
|
118
|
+
description
|
|
119
|
+
}), children);
|
|
137
120
|
};
|
|
138
|
-
var ControlGroup = ({ children
|
|
121
|
+
var ControlGroup = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
|
|
139
122
|
role: "none",
|
|
140
|
-
className:
|
|
123
|
+
className: "group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4"
|
|
141
124
|
}, children);
|
|
142
125
|
var ControlFrame = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
|
|
143
126
|
role: "none",
|
|
@@ -183,9 +166,9 @@ var ControlFrameItem = ({ title, description, children }) => {
|
|
|
183
166
|
};
|
|
184
167
|
|
|
185
168
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
186
|
-
import
|
|
187
|
-
import { FormatEnum as
|
|
188
|
-
import { log as
|
|
169
|
+
import React13, { useCallback as useCallback6, useEffect as useEffect7, useMemo as useMemo7, useState as useState4 } from "react";
|
|
170
|
+
import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
171
|
+
import { log as log2 } from "@dxos/log";
|
|
189
172
|
import { useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
190
173
|
import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
|
|
191
174
|
|
|
@@ -203,15 +186,15 @@ var InputHeader = ({ children, error }) => {
|
|
|
203
186
|
return /* @__PURE__ */ React3.createElement("div", {
|
|
204
187
|
role: "none",
|
|
205
188
|
className: "flex justify-between items-center mb-1"
|
|
206
|
-
}, children, error && /* @__PURE__ */ React3.createElement(Tooltip.Trigger, {
|
|
207
|
-
asChild: true
|
|
208
|
-
content: error,
|
|
209
|
-
side: "bottom"
|
|
189
|
+
}, children, error && /* @__PURE__ */ React3.createElement(Tooltip.Root, null, /* @__PURE__ */ React3.createElement(Tooltip.Trigger, {
|
|
190
|
+
asChild: true
|
|
210
191
|
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
211
192
|
icon: "ph--warning--regular",
|
|
212
193
|
size: 4,
|
|
213
194
|
classNames: errorText
|
|
214
|
-
}))
|
|
195
|
+
})), /* @__PURE__ */ React3.createElement(Tooltip.Content, {
|
|
196
|
+
side: "bottom"
|
|
197
|
+
}, /* @__PURE__ */ React3.createElement(Tooltip.Arrow, null), error)));
|
|
215
198
|
};
|
|
216
199
|
|
|
217
200
|
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
@@ -291,7 +274,7 @@ import { PublicKey } from "@dxos/keys";
|
|
|
291
274
|
import { Icon as Icon2, IconButton, Input as Input4, Tag, Toolbar, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
292
275
|
import { List } from "@dxos/react-ui-list";
|
|
293
276
|
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
294
|
-
import { hues, mx as
|
|
277
|
+
import { hues, mx as mx2 } from "@dxos/react-ui-theme";
|
|
295
278
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
296
279
|
const [selected, setSelectedId] = useState2(null);
|
|
297
280
|
const [isNewOption, setIsNewOption] = useState2(false);
|
|
@@ -417,7 +400,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
417
400
|
}, /* @__PURE__ */ React5.createElement(List.Item, {
|
|
418
401
|
role: "button",
|
|
419
402
|
item,
|
|
420
|
-
classNames:
|
|
403
|
+
classNames: mx2("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
421
404
|
"aria-expanded": selected === item.id
|
|
422
405
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
423
406
|
className: "flex items-center"
|
|
@@ -458,7 +441,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
458
441
|
role: "listitem"
|
|
459
442
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
460
443
|
role: "button",
|
|
461
|
-
className:
|
|
444
|
+
className: mx2("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
462
445
|
onClick: handleAdd
|
|
463
446
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
464
447
|
className: "flex items-center gap-1"
|
|
@@ -472,7 +455,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
472
455
|
// packages/ui/react-ui-form/src/components/Form/custom/TupleInput.tsx
|
|
473
456
|
import React6 from "react";
|
|
474
457
|
import { Input as Input5 } from "@dxos/react-ui";
|
|
475
|
-
import { mx as
|
|
458
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
476
459
|
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
477
460
|
var gridCols = [
|
|
478
461
|
"grid-cols-1",
|
|
@@ -488,7 +471,7 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
488
471
|
}, /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
489
472
|
error
|
|
490
473
|
}, /* @__PURE__ */ React6.createElement(Input5.Label, null, label)), /* @__PURE__ */ React6.createElement("div", {
|
|
491
|
-
className:
|
|
474
|
+
className: mx3("grid gap-2", gridCols[binding.length - 1])
|
|
492
475
|
}, binding.map((prop) => /* @__PURE__ */ React6.createElement(Input5.TextInput, {
|
|
493
476
|
key: prop,
|
|
494
477
|
type: "number",
|
|
@@ -548,28 +531,23 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
|
|
|
548
531
|
};
|
|
549
532
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
550
533
|
const { status, error } = getStatus();
|
|
551
|
-
const value = getValue3();
|
|
552
|
-
const handleValueChange = useCallback3((value2) => onValueChange(type, value2), [
|
|
553
|
-
type,
|
|
554
|
-
onValueChange
|
|
555
|
-
]);
|
|
556
534
|
return /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
557
535
|
validationValence: status
|
|
558
536
|
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
559
537
|
error
|
|
560
538
|
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), /* @__PURE__ */ React7.createElement(Select.Root, {
|
|
561
|
-
value,
|
|
562
|
-
onValueChange:
|
|
539
|
+
value: getValue3(),
|
|
540
|
+
onValueChange: (value) => onValueChange(type, value)
|
|
563
541
|
}, /* @__PURE__ */ React7.createElement(Select.TriggerButton, {
|
|
564
542
|
classNames: "is-full",
|
|
565
543
|
disabled,
|
|
566
544
|
placeholder
|
|
567
|
-
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value
|
|
545
|
+
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
568
546
|
// NOTE: Numeric values are converted to and from strings.
|
|
569
547
|
/* @__PURE__ */ React7.createElement(Select.Option, {
|
|
570
|
-
key: String(
|
|
571
|
-
value: String(
|
|
572
|
-
}, label2 ?? String(
|
|
548
|
+
key: String(value),
|
|
549
|
+
value: String(value)
|
|
550
|
+
}, label2 ?? String(value))
|
|
573
551
|
)))))), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
|
|
574
552
|
};
|
|
575
553
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
@@ -613,22 +591,22 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
|
|
|
613
591
|
};
|
|
614
592
|
|
|
615
593
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
616
|
-
import
|
|
617
|
-
import { mx as
|
|
594
|
+
import React12, { useEffect as useEffect6, useMemo as useMemo6, useRef as useRef3 } from "react";
|
|
595
|
+
import { mx as mx7 } from "@dxos/react-ui-theme";
|
|
618
596
|
|
|
619
597
|
// packages/ui/react-ui-form/src/components/Form/FormActions.tsx
|
|
620
598
|
import React9 from "react";
|
|
621
599
|
import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
622
|
-
import { mx as
|
|
600
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
623
601
|
|
|
624
602
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
625
|
-
import React8, { createContext, useContext, useEffect as
|
|
603
|
+
import React8, { createContext, useContext, useEffect as useEffect5, useMemo as useMemo3 } from "react";
|
|
626
604
|
import { raise } from "@dxos/debug";
|
|
627
605
|
import { getValue as getValue2 } from "@dxos/echo-schema";
|
|
628
606
|
import { createJsonPath as createJsonPath2 } from "@dxos/effect";
|
|
629
607
|
|
|
630
608
|
// packages/ui/react-ui-form/src/hooks/useForm.ts
|
|
631
|
-
import { SchemaAST } from "effect";
|
|
609
|
+
import { SchemaAST as AST } from "effect";
|
|
632
610
|
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
|
|
633
611
|
import { getValue, setValue } from "@dxos/echo-schema";
|
|
634
612
|
import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
|
|
@@ -637,12 +615,12 @@ import { log } from "@dxos/log";
|
|
|
637
615
|
import { validateSchema } from "@dxos/schema";
|
|
638
616
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
639
617
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
640
|
-
invariant(
|
|
618
|
+
invariant(AST.isTypeLiteral(schema.ast), void 0, {
|
|
641
619
|
F: __dxlog_file,
|
|
642
620
|
L: 93,
|
|
643
621
|
S: void 0,
|
|
644
622
|
A: [
|
|
645
|
-
"
|
|
623
|
+
"AST.isTypeLiteral(schema.ast)",
|
|
646
624
|
""
|
|
647
625
|
]
|
|
648
626
|
});
|
|
@@ -743,7 +721,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
743
721
|
} catch (err) {
|
|
744
722
|
log.catch(err, void 0, {
|
|
745
723
|
F: __dxlog_file,
|
|
746
|
-
L:
|
|
724
|
+
L: 212,
|
|
747
725
|
S: void 0,
|
|
748
726
|
C: (f, a) => f(...a)
|
|
749
727
|
});
|
|
@@ -814,7 +792,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
814
792
|
var createKeySet = (obj, value) => {
|
|
815
793
|
invariant(obj, void 0, {
|
|
816
794
|
F: __dxlog_file,
|
|
817
|
-
L:
|
|
795
|
+
L: 274,
|
|
818
796
|
S: void 0,
|
|
819
797
|
A: [
|
|
820
798
|
"obj",
|
|
@@ -836,81 +814,6 @@ var flatMap = (errors) => {
|
|
|
836
814
|
}, {});
|
|
837
815
|
};
|
|
838
816
|
|
|
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
|
-
|
|
868
|
-
// packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts
|
|
869
|
-
import { useEffect as useEffect5, useState as useState4 } from "react";
|
|
870
|
-
import { log as log2 } from "@dxos/log";
|
|
871
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
872
|
-
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
873
|
-
const [options, setOptions] = useState4([]);
|
|
874
|
-
const [loading, setLoading] = useState4(false);
|
|
875
|
-
useEffect5(() => {
|
|
876
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
const fetchOptions = async () => {
|
|
880
|
-
setLoading(true);
|
|
881
|
-
try {
|
|
882
|
-
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
883
|
-
setOptions(fetchedOptions.map((option) => {
|
|
884
|
-
const dxn = option.dxn.toString();
|
|
885
|
-
return {
|
|
886
|
-
id: dxn,
|
|
887
|
-
label: option.label ?? dxn,
|
|
888
|
-
hue: "neutral"
|
|
889
|
-
};
|
|
890
|
-
}));
|
|
891
|
-
} catch (error) {
|
|
892
|
-
log2.error("Failed to fetch ref options:", error, {
|
|
893
|
-
F: __dxlog_file2,
|
|
894
|
-
L: 42,
|
|
895
|
-
S: void 0,
|
|
896
|
-
C: (f, a) => f(...a)
|
|
897
|
-
});
|
|
898
|
-
setOptions([]);
|
|
899
|
-
} finally {
|
|
900
|
-
setLoading(false);
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
void fetchOptions();
|
|
904
|
-
}, [
|
|
905
|
-
refTypeInfo,
|
|
906
|
-
onQueryRefOptions
|
|
907
|
-
]);
|
|
908
|
-
return {
|
|
909
|
-
options,
|
|
910
|
-
loading
|
|
911
|
-
};
|
|
912
|
-
};
|
|
913
|
-
|
|
914
817
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
915
818
|
var FormContext = /* @__PURE__ */ createContext(void 0);
|
|
916
819
|
var useFormContext = () => {
|
|
@@ -941,7 +844,7 @@ var useInputProps = (path = []) => {
|
|
|
941
844
|
};
|
|
942
845
|
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
943
846
|
const form = useForm(formOptions);
|
|
944
|
-
|
|
847
|
+
useEffect5(() => {
|
|
945
848
|
if (!formRef?.current) {
|
|
946
849
|
return;
|
|
947
850
|
}
|
|
@@ -949,7 +852,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
949
852
|
const keyIsEnter = event.key === "Enter";
|
|
950
853
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
951
854
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
952
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit")
|
|
855
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
953
856
|
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
954
857
|
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
955
858
|
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
@@ -985,7 +888,7 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
985
888
|
className: "mt-2 flex justify-center"
|
|
986
889
|
}, /* @__PURE__ */ React9.createElement("div", {
|
|
987
890
|
role: "none",
|
|
988
|
-
className:
|
|
891
|
+
className: mx4(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
989
892
|
}, onCancel && !readonly && /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
990
893
|
"data-testid": "cancel-button",
|
|
991
894
|
icon: "ph--x--regular",
|
|
@@ -1002,588 +905,151 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
1002
905
|
};
|
|
1003
906
|
|
|
1004
907
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
1005
|
-
import {
|
|
908
|
+
import { pipe as pipe2 } from "effect";
|
|
1006
909
|
import { capitalize as capitalize2 } from "effect/String";
|
|
1007
|
-
import
|
|
1008
|
-
import {
|
|
1009
|
-
import {
|
|
910
|
+
import React11, { useMemo as useMemo5 } from "react";
|
|
911
|
+
import { AST as AST3, S } from "@dxos/echo-schema";
|
|
912
|
+
import { createJsonPath as createJsonPath3, findNode as findNode2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
913
|
+
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
1010
914
|
import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
|
|
1011
915
|
import { isNotFalsy } from "@dxos/util";
|
|
1012
916
|
|
|
1013
917
|
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
1014
|
-
import {
|
|
918
|
+
import { pipe } from "effect";
|
|
1015
919
|
import { capitalize } from "effect/String";
|
|
1016
|
-
import React10, { useCallback as
|
|
1017
|
-
import {
|
|
920
|
+
import React10, { useCallback as useCallback5, useMemo as useMemo4 } from "react";
|
|
921
|
+
import { AST as AST2 } from "@dxos/echo-schema";
|
|
922
|
+
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
1018
923
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1019
924
|
import { IconButton as IconButton3, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1020
|
-
import { mx as
|
|
925
|
+
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
1021
926
|
import { getSchemaProperties } from "@dxos/schema";
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
return Number.isNaN(num) ? null : num;
|
|
1046
|
-
}
|
|
1047
|
-
case TypeEnum.String:
|
|
1048
|
-
case TypeEnum.Ref:
|
|
1049
|
-
return String(value);
|
|
1050
|
-
default: {
|
|
1051
|
-
return value;
|
|
1052
|
-
}
|
|
927
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
928
|
+
var padding = "px-2";
|
|
929
|
+
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
930
|
+
const { t } = useTranslation5(translationKey);
|
|
931
|
+
const { ast, name, type, title } = property;
|
|
932
|
+
const values = useFormValues(path ?? []);
|
|
933
|
+
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
934
|
+
F: __dxlog_file2,
|
|
935
|
+
L: 37,
|
|
936
|
+
S: void 0,
|
|
937
|
+
A: [
|
|
938
|
+
"Array.isArray(values)",
|
|
939
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
940
|
+
]
|
|
941
|
+
});
|
|
942
|
+
const label = title ?? pipe(name, capitalize);
|
|
943
|
+
const tupleType = findNode(ast, AST2.isTupleType);
|
|
944
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
945
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
946
|
+
const baseNode = findNode(typeNode, isDiscriminatedUnion);
|
|
947
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, AST2.isTypeLiteral);
|
|
948
|
+
if (!typeLiteral) {
|
|
949
|
+
return {};
|
|
1053
950
|
}
|
|
951
|
+
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
|
|
952
|
+
prop.name,
|
|
953
|
+
prop.defaultValue
|
|
954
|
+
]));
|
|
1054
955
|
};
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
return parseScalar(TypeEnum.Boolean);
|
|
1061
|
-
case FormatEnum.Number:
|
|
1062
|
-
case FormatEnum.Percent:
|
|
1063
|
-
case FormatEnum.Currency:
|
|
1064
|
-
return parseScalar(TypeEnum.Number);
|
|
1065
|
-
case FormatEnum.String:
|
|
1066
|
-
case FormatEnum.Markdown: {
|
|
1067
|
-
return parseScalar(TypeEnum.String);
|
|
1068
|
-
}
|
|
1069
|
-
case FormatEnum.Ref:
|
|
1070
|
-
throw new Error(`unexpected format: ${FormatEnum.Ref}`);
|
|
1071
|
-
case FormatEnum.DateTime:
|
|
1072
|
-
case FormatEnum.Date:
|
|
1073
|
-
case FormatEnum.Time:
|
|
1074
|
-
case FormatEnum.Timestamp: {
|
|
1075
|
-
const date = new Date(value);
|
|
1076
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1077
|
-
}
|
|
1078
|
-
case FormatEnum.GeoPoint: {
|
|
1079
|
-
if (typeof value === "string") {
|
|
1080
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1081
|
-
const parts = cleaned.split(",");
|
|
1082
|
-
if (parts.length === 2) {
|
|
1083
|
-
const lat = parseFloat(parts[0]);
|
|
1084
|
-
const long = parseFloat(parts[1]);
|
|
1085
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1086
|
-
return GeoLocation2.toGeoPoint({
|
|
1087
|
-
latitude: lat,
|
|
1088
|
-
longitude: long
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
return [
|
|
1094
|
-
0,
|
|
1095
|
-
0
|
|
1096
|
-
];
|
|
1097
|
-
}
|
|
1098
|
-
default: {
|
|
1099
|
-
return value;
|
|
956
|
+
const newValue = useMemo4(() => {
|
|
957
|
+
if (type === "object" && elementType) {
|
|
958
|
+
return getDefaultObjectValue(elementType);
|
|
959
|
+
} else {
|
|
960
|
+
return SimpleType.getDefaultValue(type);
|
|
1100
961
|
}
|
|
962
|
+
}, [
|
|
963
|
+
type,
|
|
964
|
+
elementType
|
|
965
|
+
]);
|
|
966
|
+
const handleAdd = useCallback5(() => {
|
|
967
|
+
inputProps.onValueChange(type, [
|
|
968
|
+
...values,
|
|
969
|
+
newValue
|
|
970
|
+
]);
|
|
971
|
+
}, [
|
|
972
|
+
type,
|
|
973
|
+
elementType,
|
|
974
|
+
inputProps,
|
|
975
|
+
newValue,
|
|
976
|
+
values
|
|
977
|
+
]);
|
|
978
|
+
const handleRemove = useCallback5((index) => {
|
|
979
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
980
|
+
inputProps.onValueChange(type, newValues);
|
|
981
|
+
}, [
|
|
982
|
+
type,
|
|
983
|
+
inputProps,
|
|
984
|
+
values
|
|
985
|
+
]);
|
|
986
|
+
if (!elementType) {
|
|
987
|
+
return null;
|
|
1101
988
|
}
|
|
989
|
+
return /* @__PURE__ */ React10.createElement("div", {
|
|
990
|
+
role: "none",
|
|
991
|
+
className: mx5(padding)
|
|
992
|
+
}, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
993
|
+
role: "none",
|
|
994
|
+
className: "flex flex-col gap-1"
|
|
995
|
+
}, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
|
|
996
|
+
key: index,
|
|
997
|
+
role: "none",
|
|
998
|
+
className: "flex items-center gap-1"
|
|
999
|
+
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1000
|
+
role: "none",
|
|
1001
|
+
className: "flex-1"
|
|
1002
|
+
}, /* @__PURE__ */ React10.createElement(FormField, {
|
|
1003
|
+
property: {
|
|
1004
|
+
...property,
|
|
1005
|
+
array: false,
|
|
1006
|
+
ast: elementType
|
|
1007
|
+
},
|
|
1008
|
+
path: [
|
|
1009
|
+
...path ?? [],
|
|
1010
|
+
index
|
|
1011
|
+
],
|
|
1012
|
+
readonly,
|
|
1013
|
+
inline: true,
|
|
1014
|
+
Custom,
|
|
1015
|
+
lookupComponent
|
|
1016
|
+
})), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1017
|
+
icon: "ph--trash--regular",
|
|
1018
|
+
iconOnly: true,
|
|
1019
|
+
label: t("button remove"),
|
|
1020
|
+
onClick: () => handleRemove(index)
|
|
1021
|
+
})))), /* @__PURE__ */ React10.createElement("div", {
|
|
1022
|
+
role: "none",
|
|
1023
|
+
className: "flex justify-between items-center plb-1"
|
|
1024
|
+
}, /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1025
|
+
icon: "ph--plus--regular",
|
|
1026
|
+
iconOnly: true,
|
|
1027
|
+
label: t("button add"),
|
|
1028
|
+
onClick: handleAdd
|
|
1029
|
+
})));
|
|
1102
1030
|
};
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
return [
|
|
1108
|
-
"text-right",
|
|
1109
|
-
"font-mono"
|
|
1110
|
-
];
|
|
1111
|
-
case TypeEnum.Boolean:
|
|
1112
|
-
return [
|
|
1113
|
-
"text-right",
|
|
1114
|
-
"font-mono"
|
|
1115
|
-
];
|
|
1116
|
-
case TypeEnum.String:
|
|
1117
|
-
return void 0;
|
|
1118
|
-
case TypeEnum.Ref:
|
|
1119
|
-
return void 0;
|
|
1120
|
-
default: {
|
|
1121
|
-
return void 0;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1031
|
+
|
|
1032
|
+
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
1033
|
+
import { FormatEnum } from "@dxos/echo-schema";
|
|
1034
|
+
var getInputComponent = (type, format) => {
|
|
1125
1035
|
switch (format) {
|
|
1036
|
+
case FormatEnum.GeoPoint:
|
|
1037
|
+
return GeoPointInput;
|
|
1126
1038
|
case FormatEnum.Markdown:
|
|
1127
|
-
return
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
case
|
|
1131
|
-
|
|
1132
|
-
case
|
|
1133
|
-
return
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
];
|
|
1137
|
-
case FormatEnum.Currency:
|
|
1138
|
-
return [
|
|
1139
|
-
"text-right"
|
|
1140
|
-
];
|
|
1141
|
-
case FormatEnum.JSON:
|
|
1142
|
-
case FormatEnum.DID:
|
|
1143
|
-
return [
|
|
1144
|
-
"font-mono"
|
|
1145
|
-
];
|
|
1146
|
-
default:
|
|
1147
|
-
return void 0;
|
|
1148
|
-
}
|
|
1149
|
-
};
|
|
1150
|
-
var pathNotUniqueError = (path) => ({
|
|
1151
|
-
path: "path",
|
|
1152
|
-
message: `'${path}' is already present`
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
// packages/ui/react-ui-form/src/util/formatting.ts
|
|
1156
|
-
import { format as formatDate } from "date-fns/format";
|
|
1157
|
-
import { FormatEnum as FormatEnum2, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
|
|
1158
|
-
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1159
|
-
const formatScalar = (type2) => {
|
|
1160
|
-
switch (type2) {
|
|
1161
|
-
case TypeEnum2.Boolean:
|
|
1162
|
-
return value.toLocaleString().toUpperCase();
|
|
1163
|
-
case TypeEnum2.Number:
|
|
1164
|
-
return value.toLocaleString(locale);
|
|
1165
|
-
case TypeEnum2.String:
|
|
1166
|
-
case TypeEnum2.Ref:
|
|
1167
|
-
return String(value);
|
|
1168
|
-
default: {
|
|
1169
|
-
return String(value);
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
if (!format) {
|
|
1174
|
-
return formatScalar(type);
|
|
1175
|
-
}
|
|
1176
|
-
switch (format) {
|
|
1177
|
-
case FormatEnum2.Boolean: {
|
|
1178
|
-
return formatScalar(TypeEnum2.Boolean);
|
|
1179
|
-
}
|
|
1180
|
-
case FormatEnum2.Number: {
|
|
1181
|
-
return formatScalar(TypeEnum2.Number);
|
|
1182
|
-
}
|
|
1183
|
-
case FormatEnum2.String:
|
|
1184
|
-
case FormatEnum2.Ref: {
|
|
1185
|
-
return formatScalar(TypeEnum2.String);
|
|
1186
|
-
}
|
|
1187
|
-
case FormatEnum2.Percent: {
|
|
1188
|
-
return `${value * 100}%`;
|
|
1189
|
-
}
|
|
1190
|
-
case FormatEnum2.Currency: {
|
|
1191
|
-
return value.toLocaleString(locale, {
|
|
1192
|
-
style: "currency",
|
|
1193
|
-
currency: "USD",
|
|
1194
|
-
minimumFractionDigits: 2,
|
|
1195
|
-
maximumFractionDigits: 2
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
case FormatEnum2.Date: {
|
|
1199
|
-
try {
|
|
1200
|
-
return formatDate(new Date(value), "yyyy-MM-dd");
|
|
1201
|
-
} catch (error) {
|
|
1202
|
-
return "Invalid Date";
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
case FormatEnum2.Time: {
|
|
1206
|
-
try {
|
|
1207
|
-
return formatDate(new Date(value), "HH:mm:ss");
|
|
1208
|
-
} catch (error) {
|
|
1209
|
-
return "Invalid Time";
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
case FormatEnum2.DateTime: {
|
|
1213
|
-
try {
|
|
1214
|
-
return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1215
|
-
} catch (error) {
|
|
1216
|
-
return "Invalid DateTime";
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
case FormatEnum2.GeoPoint: {
|
|
1220
|
-
if (value === null || value === void 0) {
|
|
1221
|
-
return "";
|
|
1222
|
-
}
|
|
1223
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1224
|
-
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1225
|
-
return `${latitude},${longitude}`;
|
|
1226
|
-
}
|
|
1227
|
-
return String(value);
|
|
1228
|
-
}
|
|
1229
|
-
default: {
|
|
1230
|
-
if (value === null || value === "undefined") {
|
|
1231
|
-
return "";
|
|
1232
|
-
}
|
|
1233
|
-
return String(value);
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1238
|
-
const formatScalar = (type2) => {
|
|
1239
|
-
switch (type2) {
|
|
1240
|
-
case TypeEnum2.Boolean:
|
|
1241
|
-
case TypeEnum2.Number:
|
|
1242
|
-
case TypeEnum2.String:
|
|
1243
|
-
case TypeEnum2.Ref:
|
|
1244
|
-
return String(value);
|
|
1245
|
-
default:
|
|
1246
|
-
return String(value);
|
|
1247
|
-
}
|
|
1248
|
-
};
|
|
1249
|
-
if (!format) {
|
|
1250
|
-
return formatScalar(type);
|
|
1251
|
-
}
|
|
1252
|
-
switch (format) {
|
|
1253
|
-
case FormatEnum2.Boolean:
|
|
1254
|
-
case FormatEnum2.Number:
|
|
1255
|
-
case FormatEnum2.String:
|
|
1256
|
-
case FormatEnum2.Ref: {
|
|
1257
|
-
return formatScalar(type);
|
|
1258
|
-
}
|
|
1259
|
-
case FormatEnum2.Percent: {
|
|
1260
|
-
return String(value * 100);
|
|
1261
|
-
}
|
|
1262
|
-
case FormatEnum2.Currency: {
|
|
1263
|
-
return String(value);
|
|
1264
|
-
}
|
|
1265
|
-
case FormatEnum2.DateTime: {
|
|
1266
|
-
const date = new Date(value);
|
|
1267
|
-
return date.toISOString();
|
|
1268
|
-
}
|
|
1269
|
-
case FormatEnum2.Date: {
|
|
1270
|
-
const date = new Date(value);
|
|
1271
|
-
return date.toISOString().split("T")[0];
|
|
1272
|
-
}
|
|
1273
|
-
case FormatEnum2.Time: {
|
|
1274
|
-
const date = new Date(value);
|
|
1275
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
1276
|
-
}
|
|
1277
|
-
case FormatEnum2.GeoPoint: {
|
|
1278
|
-
if (value === null || value === void 0) {
|
|
1279
|
-
return "";
|
|
1280
|
-
}
|
|
1281
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1282
|
-
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1283
|
-
return `${latitude},${longitude}`;
|
|
1284
|
-
}
|
|
1285
|
-
return String(value);
|
|
1286
|
-
}
|
|
1287
|
-
default: {
|
|
1288
|
-
return String(value);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
};
|
|
1292
|
-
|
|
1293
|
-
// packages/ui/react-ui-form/src/util/refs.ts
|
|
1294
|
-
import { FormatEnum as FormatEnum3, ReferenceAnnotationId } from "@dxos/echo-schema";
|
|
1295
|
-
import { findAnnotation } from "@dxos/effect";
|
|
1296
|
-
|
|
1297
|
-
// packages/ui/react-ui-form/src/util/schema.ts
|
|
1298
|
-
import { SchemaAST as SchemaAST2 } from "effect";
|
|
1299
|
-
import { findNode } from "@dxos/effect";
|
|
1300
|
-
var findArrayElementType = (ast) => {
|
|
1301
|
-
const tupleType = findNode(ast, SchemaAST2.isTupleType);
|
|
1302
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
1303
|
-
return elementType;
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
|
-
// packages/ui/react-ui-form/src/util/refs.ts
|
|
1307
|
-
var getRefProps = (property) => {
|
|
1308
|
-
const { ast, format, array } = property;
|
|
1309
|
-
if (format === FormatEnum3.Ref) {
|
|
1310
|
-
return {
|
|
1311
|
-
ast,
|
|
1312
|
-
isArray: false
|
|
1313
|
-
};
|
|
1314
|
-
}
|
|
1315
|
-
if (array) {
|
|
1316
|
-
const elementType = findArrayElementType(ast);
|
|
1317
|
-
if (elementType) {
|
|
1318
|
-
const annotation = findAnnotation(elementType, ReferenceAnnotationId);
|
|
1319
|
-
if (annotation) {
|
|
1320
|
-
return {
|
|
1321
|
-
ast: elementType,
|
|
1322
|
-
isArray: true
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
return void 0;
|
|
1328
|
-
};
|
|
1329
|
-
|
|
1330
|
-
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
1331
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
1332
|
-
var padding = "px-2";
|
|
1333
|
-
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1334
|
-
const { t } = useTranslation5(translationKey);
|
|
1335
|
-
const { ast, name, type, title } = property;
|
|
1336
|
-
const values = useFormValues(path ?? []) ?? [];
|
|
1337
|
-
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1338
|
-
F: __dxlog_file3,
|
|
1339
|
-
L: 39,
|
|
1340
|
-
S: void 0,
|
|
1341
|
-
A: [
|
|
1342
|
-
"Array.isArray(values)",
|
|
1343
|
-
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1344
|
-
]
|
|
1345
|
-
});
|
|
1346
|
-
const label = title ?? pipe(name, capitalize);
|
|
1347
|
-
const elementType = findArrayElementType(ast);
|
|
1348
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
1349
|
-
const baseNode = findNode2(typeNode, isDiscriminatedUnion);
|
|
1350
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
|
|
1351
|
-
if (!typeLiteral) {
|
|
1352
|
-
return {};
|
|
1353
|
-
}
|
|
1354
|
-
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
|
|
1355
|
-
prop.name,
|
|
1356
|
-
prop.defaultValue
|
|
1357
|
-
]));
|
|
1358
|
-
};
|
|
1359
|
-
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
1360
|
-
const handleAdd = useCallback6(() => {
|
|
1361
|
-
inputProps.onValueChange(type, [
|
|
1362
|
-
...values,
|
|
1363
|
-
getDefaultValue()
|
|
1364
|
-
]);
|
|
1365
|
-
}, [
|
|
1366
|
-
type,
|
|
1367
|
-
elementType,
|
|
1368
|
-
inputProps,
|
|
1369
|
-
values
|
|
1370
|
-
]);
|
|
1371
|
-
const handleRemove = useCallback6((index) => {
|
|
1372
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
1373
|
-
inputProps.onValueChange(type, newValues);
|
|
1374
|
-
}, [
|
|
1375
|
-
type,
|
|
1376
|
-
inputProps,
|
|
1377
|
-
values
|
|
1378
|
-
]);
|
|
1379
|
-
if (!elementType) {
|
|
1380
|
-
return null;
|
|
1381
|
-
}
|
|
1382
|
-
return /* @__PURE__ */ React10.createElement("div", {
|
|
1383
|
-
role: "none",
|
|
1384
|
-
className: mx6(padding)
|
|
1385
|
-
}, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
1386
|
-
role: "none",
|
|
1387
|
-
className: "flex flex-col gap-1"
|
|
1388
|
-
}, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
|
|
1389
|
-
key: index,
|
|
1390
|
-
role: "none",
|
|
1391
|
-
className: "flex items-center gap-1"
|
|
1392
|
-
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1393
|
-
role: "none",
|
|
1394
|
-
className: "flex-1"
|
|
1395
|
-
}, /* @__PURE__ */ React10.createElement(FormField, {
|
|
1396
|
-
property: {
|
|
1397
|
-
...property,
|
|
1398
|
-
array: false,
|
|
1399
|
-
ast: elementType
|
|
1400
|
-
},
|
|
1401
|
-
path: [
|
|
1402
|
-
...path ?? [],
|
|
1403
|
-
index
|
|
1404
|
-
],
|
|
1405
|
-
readonly,
|
|
1406
|
-
inline: true,
|
|
1407
|
-
Custom,
|
|
1408
|
-
lookupComponent
|
|
1409
|
-
})), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1410
|
-
icon: "ph--trash--regular",
|
|
1411
|
-
iconOnly: true,
|
|
1412
|
-
label: t("button remove"),
|
|
1413
|
-
onClick: () => handleRemove(index)
|
|
1414
|
-
})))), /* @__PURE__ */ React10.createElement("div", {
|
|
1415
|
-
role: "none",
|
|
1416
|
-
className: "flex justify-between items-center plb-1"
|
|
1417
|
-
}, /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1418
|
-
icon: "ph--plus--regular",
|
|
1419
|
-
iconOnly: true,
|
|
1420
|
-
label: t("button add"),
|
|
1421
|
-
onClick: handleAdd
|
|
1422
|
-
})));
|
|
1423
|
-
};
|
|
1424
|
-
|
|
1425
|
-
// packages/ui/react-ui-form/src/components/Form/RefField.tsx
|
|
1426
|
-
import React11, { useCallback as useCallback7, useMemo as useMemo4 } from "react";
|
|
1427
|
-
import { Expando, getTypeAnnotation, Ref, ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo-schema";
|
|
1428
|
-
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
1429
|
-
import { DXN } from "@dxos/keys";
|
|
1430
|
-
import { Input as Input7 } from "@dxos/react-ui";
|
|
1431
|
-
import { TagPicker } from "@dxos/react-ui-tag-picker";
|
|
1432
|
-
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1433
|
-
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1434
|
-
const refTypeInfo = useMemo4(() => ast ? findAnnotation2(ast, ReferenceAnnotationId2) : void 0, [
|
|
1435
|
-
ast
|
|
1436
|
-
]);
|
|
1437
|
-
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1438
|
-
refTypeInfo,
|
|
1439
|
-
onQueryRefOptions
|
|
1440
|
-
});
|
|
1441
|
-
if (refTypeInfo && refTypeInfo?.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
|
|
1442
|
-
return /* @__PURE__ */ React11.createElement(RefFieldFallback, {
|
|
1443
|
-
type,
|
|
1444
|
-
label,
|
|
1445
|
-
placeholder,
|
|
1446
|
-
disabled,
|
|
1447
|
-
inputOnly,
|
|
1448
|
-
getValue: getValue3,
|
|
1449
|
-
onBlur,
|
|
1450
|
-
onValueChange,
|
|
1451
|
-
...restInputProps
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
const handleGetValue = useCallback7(() => {
|
|
1455
|
-
const formValue = getValue3();
|
|
1456
|
-
const unknownToRefOption = (val) => {
|
|
1457
|
-
if (Ref.isRef(val)) {
|
|
1458
|
-
const dxnString = val.dxn.toString();
|
|
1459
|
-
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1460
|
-
if (matchingOption) {
|
|
1461
|
-
return matchingOption;
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
return void 0;
|
|
1465
|
-
};
|
|
1466
|
-
if (array && Array.isArray(formValue)) {
|
|
1467
|
-
return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
|
|
1468
|
-
}
|
|
1469
|
-
const option = unknownToRefOption(formValue);
|
|
1470
|
-
if (option) {
|
|
1471
|
-
return [
|
|
1472
|
-
option
|
|
1473
|
-
];
|
|
1474
|
-
}
|
|
1475
|
-
return [];
|
|
1476
|
-
}, [
|
|
1477
|
-
getValue3,
|
|
1478
|
-
availableOptions,
|
|
1479
|
-
array
|
|
1480
|
-
]);
|
|
1481
|
-
const handleSearch = useCallback7((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1482
|
-
id: option.id,
|
|
1483
|
-
label: option.label,
|
|
1484
|
-
hue: option.hue
|
|
1485
|
-
})), [
|
|
1486
|
-
availableOptions
|
|
1487
|
-
]);
|
|
1488
|
-
const handleUpdate = useCallback7((ids) => {
|
|
1489
|
-
if (ids.length === 0) {
|
|
1490
|
-
onValueChange("object", void 0);
|
|
1491
|
-
return;
|
|
1492
|
-
}
|
|
1493
|
-
const refs = ids.map((id) => {
|
|
1494
|
-
const item = availableOptions.find((option) => option.id === id);
|
|
1495
|
-
if (item) {
|
|
1496
|
-
const dxn = DXN.parse(item.id);
|
|
1497
|
-
return Ref.fromDXN(dxn);
|
|
1498
|
-
}
|
|
1499
|
-
return null;
|
|
1500
|
-
}).filter(isNonNullable2);
|
|
1501
|
-
if (array) {
|
|
1502
|
-
onValueChange("object", refs);
|
|
1503
|
-
} else {
|
|
1504
|
-
onValueChange("object", refs[0]);
|
|
1505
|
-
}
|
|
1506
|
-
}, [
|
|
1507
|
-
availableOptions,
|
|
1508
|
-
array,
|
|
1509
|
-
onValueChange
|
|
1510
|
-
]);
|
|
1511
|
-
const tagPickerMode = useMemo4(() => array ? "multi-select" : "single-select", [
|
|
1512
|
-
array
|
|
1513
|
-
]);
|
|
1514
|
-
if (!refTypeInfo) {
|
|
1515
|
-
return null;
|
|
1516
|
-
}
|
|
1517
|
-
const { status, error } = restInputProps.getStatus();
|
|
1518
|
-
return /* @__PURE__ */ React11.createElement(Input7.Root, {
|
|
1519
|
-
validationValence: status
|
|
1520
|
-
}, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
|
|
1521
|
-
error
|
|
1522
|
-
}, /* @__PURE__ */ React11.createElement(Input7.Label, null, label)), /* @__PURE__ */ React11.createElement("div", {
|
|
1523
|
-
"data-no-submit": true
|
|
1524
|
-
}, /* @__PURE__ */ React11.createElement(TagPicker, {
|
|
1525
|
-
items: handleGetValue(),
|
|
1526
|
-
mode: tagPickerMode,
|
|
1527
|
-
onBlur: (event) => onBlur(event),
|
|
1528
|
-
onUpdate: handleUpdate,
|
|
1529
|
-
onSearch: handleSearch,
|
|
1530
|
-
classNames: "rounded-sm bg-input p-1.5"
|
|
1531
|
-
})), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1532
|
-
};
|
|
1533
|
-
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1534
|
-
const handleOnValueChange = (_type, dxnString) => {
|
|
1535
|
-
const dxn = DXN.tryParse(dxnString);
|
|
1536
|
-
if (dxn) {
|
|
1537
|
-
onValueChange?.("object", Ref.fromDXN(dxn));
|
|
1538
|
-
} else if (dxnString === "") {
|
|
1539
|
-
onValueChange?.("object", void 0);
|
|
1540
|
-
} else {
|
|
1541
|
-
onValueChange?.("string", dxnString);
|
|
1542
|
-
}
|
|
1543
|
-
};
|
|
1544
|
-
const handleGetValue = () => {
|
|
1545
|
-
const formValue = getValue3();
|
|
1546
|
-
if (typeof formValue === "string") {
|
|
1547
|
-
return formValue;
|
|
1548
|
-
}
|
|
1549
|
-
if (Ref.isRef(formValue)) {
|
|
1550
|
-
return formValue.dxn.toString();
|
|
1551
|
-
}
|
|
1552
|
-
return void 0;
|
|
1553
|
-
};
|
|
1554
|
-
return /* @__PURE__ */ React11.createElement(TextInput, {
|
|
1555
|
-
type,
|
|
1556
|
-
label,
|
|
1557
|
-
disabled,
|
|
1558
|
-
placeholder,
|
|
1559
|
-
inputOnly,
|
|
1560
|
-
getValue: handleGetValue,
|
|
1561
|
-
onValueChange: handleOnValueChange,
|
|
1562
|
-
...restInputProps
|
|
1563
|
-
});
|
|
1564
|
-
};
|
|
1565
|
-
|
|
1566
|
-
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
1567
|
-
import { FormatEnum as FormatEnum4 } from "@dxos/echo-schema";
|
|
1568
|
-
var getInputComponent = (type, format) => {
|
|
1569
|
-
switch (format) {
|
|
1570
|
-
case FormatEnum4.GeoPoint:
|
|
1571
|
-
return GeoPointInput;
|
|
1572
|
-
case FormatEnum4.Markdown:
|
|
1573
|
-
return MarkdownInput;
|
|
1574
|
-
}
|
|
1575
|
-
switch (type) {
|
|
1576
|
-
case "string":
|
|
1577
|
-
return TextInput;
|
|
1578
|
-
case "number":
|
|
1579
|
-
return NumberInput;
|
|
1580
|
-
case "boolean":
|
|
1581
|
-
return BooleanInput;
|
|
1039
|
+
return MarkdownInput;
|
|
1040
|
+
}
|
|
1041
|
+
switch (type) {
|
|
1042
|
+
case "string":
|
|
1043
|
+
return TextInput;
|
|
1044
|
+
case "number":
|
|
1045
|
+
return NumberInput;
|
|
1046
|
+
case "boolean":
|
|
1047
|
+
return BooleanInput;
|
|
1582
1048
|
}
|
|
1583
1049
|
};
|
|
1584
1050
|
|
|
1585
1051
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
1586
|
-
var FormField = ({ property, path, readonly, inline,
|
|
1052
|
+
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
1587
1053
|
const inputProps = useInputProps(path);
|
|
1588
1054
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1589
1055
|
const label = useMemo5(() => title ?? pipe2(name, capitalize2), [
|
|
@@ -1596,7 +1062,7 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1596
1062
|
]);
|
|
1597
1063
|
const FoundComponent = lookupComponent?.({
|
|
1598
1064
|
prop: name,
|
|
1599
|
-
schema:
|
|
1065
|
+
schema: S.make(ast),
|
|
1600
1066
|
inputProps: {
|
|
1601
1067
|
type,
|
|
1602
1068
|
format,
|
|
@@ -1607,14 +1073,14 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1607
1073
|
}
|
|
1608
1074
|
});
|
|
1609
1075
|
if (FoundComponent) {
|
|
1610
|
-
return /* @__PURE__ */
|
|
1076
|
+
return /* @__PURE__ */ React11.createElement("div", {
|
|
1611
1077
|
role: "none"
|
|
1612
1078
|
}, FoundComponent);
|
|
1613
1079
|
}
|
|
1614
1080
|
const jsonPath = createJsonPath3(path ?? []);
|
|
1615
1081
|
const CustomComponent = Custom?.[jsonPath];
|
|
1616
1082
|
if (CustomComponent) {
|
|
1617
|
-
return /* @__PURE__ */
|
|
1083
|
+
return /* @__PURE__ */ React11.createElement(CustomComponent, {
|
|
1618
1084
|
type,
|
|
1619
1085
|
format,
|
|
1620
1086
|
label,
|
|
@@ -1624,23 +1090,8 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1624
1090
|
...inputProps
|
|
1625
1091
|
});
|
|
1626
1092
|
}
|
|
1627
|
-
const refProps = getRefProps(property);
|
|
1628
|
-
if (refProps) {
|
|
1629
|
-
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1630
|
-
ast: refProps.ast,
|
|
1631
|
-
array: refProps.isArray,
|
|
1632
|
-
type,
|
|
1633
|
-
format,
|
|
1634
|
-
label,
|
|
1635
|
-
placeholder,
|
|
1636
|
-
disabled: readonly,
|
|
1637
|
-
inputOnly: inline,
|
|
1638
|
-
onQueryRefOptions,
|
|
1639
|
-
...inputProps
|
|
1640
|
-
});
|
|
1641
|
-
}
|
|
1642
1093
|
if (array) {
|
|
1643
|
-
return /* @__PURE__ */
|
|
1094
|
+
return /* @__PURE__ */ React11.createElement(ArrayField, {
|
|
1644
1095
|
property,
|
|
1645
1096
|
path,
|
|
1646
1097
|
inputProps,
|
|
@@ -1650,9 +1101,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1650
1101
|
}
|
|
1651
1102
|
const InputComponent = getInputComponent(type, format);
|
|
1652
1103
|
if (InputComponent) {
|
|
1653
|
-
return /* @__PURE__ */
|
|
1104
|
+
return /* @__PURE__ */ React11.createElement("div", {
|
|
1654
1105
|
role: "none"
|
|
1655
|
-
}, /* @__PURE__ */
|
|
1106
|
+
}, /* @__PURE__ */ React11.createElement(InputComponent, {
|
|
1656
1107
|
type,
|
|
1657
1108
|
format,
|
|
1658
1109
|
label,
|
|
@@ -1663,9 +1114,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1663
1114
|
}));
|
|
1664
1115
|
}
|
|
1665
1116
|
if (options) {
|
|
1666
|
-
return /* @__PURE__ */
|
|
1117
|
+
return /* @__PURE__ */ React11.createElement("div", {
|
|
1667
1118
|
role: "none"
|
|
1668
|
-
}, /* @__PURE__ */
|
|
1119
|
+
}, /* @__PURE__ */ React11.createElement(SelectInput, {
|
|
1669
1120
|
type,
|
|
1670
1121
|
format,
|
|
1671
1122
|
disabled: readonly,
|
|
@@ -1680,26 +1131,22 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1680
1131
|
}));
|
|
1681
1132
|
}
|
|
1682
1133
|
if (type === "object") {
|
|
1683
|
-
const baseNode =
|
|
1684
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) :
|
|
1134
|
+
const baseNode = findNode2(ast, isDiscriminatedUnion2);
|
|
1135
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode2(ast, AST3.isTypeLiteral);
|
|
1685
1136
|
if (typeLiteral) {
|
|
1686
|
-
return /* @__PURE__ */
|
|
1137
|
+
return /* @__PURE__ */ React11.createElement("div", {
|
|
1687
1138
|
role: "none"
|
|
1688
|
-
}, !inline && /* @__PURE__ */
|
|
1689
|
-
|
|
1690
|
-
}, label), /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1691
|
-
schema: Schema.make(typeLiteral),
|
|
1139
|
+
}, !inline && /* @__PURE__ */ React11.createElement("div", null, label), /* @__PURE__ */ React11.createElement(FormFields, {
|
|
1140
|
+
schema: S.make(typeLiteral),
|
|
1692
1141
|
path,
|
|
1693
1142
|
readonly,
|
|
1694
|
-
|
|
1695
|
-
Custom,
|
|
1696
|
-
lookupComponent
|
|
1143
|
+
Custom
|
|
1697
1144
|
}));
|
|
1698
1145
|
}
|
|
1699
1146
|
}
|
|
1700
1147
|
return null;
|
|
1701
1148
|
};
|
|
1702
|
-
var FormFields = ({ schema, path, filter, sort, readonly,
|
|
1149
|
+
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1703
1150
|
const values = useFormValues(path);
|
|
1704
1151
|
const properties = useMemo5(() => {
|
|
1705
1152
|
const props = getSchemaProperties2(schema.ast, values);
|
|
@@ -1711,11 +1158,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1711
1158
|
filter,
|
|
1712
1159
|
sort
|
|
1713
1160
|
]);
|
|
1714
|
-
return /* @__PURE__ */
|
|
1161
|
+
return /* @__PURE__ */ React11.createElement("div", {
|
|
1715
1162
|
role: "form",
|
|
1716
|
-
className:
|
|
1163
|
+
className: mx6("flex flex-col w-full gap-2")
|
|
1717
1164
|
}, properties.map((property) => {
|
|
1718
|
-
return /* @__PURE__ */
|
|
1165
|
+
return /* @__PURE__ */ React11.createElement(FormField, {
|
|
1719
1166
|
key: property.name,
|
|
1720
1167
|
property,
|
|
1721
1168
|
path: [
|
|
@@ -1723,7 +1170,6 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1723
1170
|
property.name
|
|
1724
1171
|
],
|
|
1725
1172
|
readonly,
|
|
1726
|
-
onQueryRefOptions,
|
|
1727
1173
|
lookupComponent,
|
|
1728
1174
|
Custom
|
|
1729
1175
|
});
|
|
@@ -1731,13 +1177,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1731
1177
|
};
|
|
1732
1178
|
|
|
1733
1179
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
1734
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel,
|
|
1180
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1735
1181
|
const formRef = useRef3(null);
|
|
1736
1182
|
const onValid = useMemo6(() => autoSave ? onSave : void 0, [
|
|
1737
1183
|
autoSave,
|
|
1738
1184
|
onSave
|
|
1739
1185
|
]);
|
|
1740
|
-
|
|
1186
|
+
useEffect6(() => {
|
|
1741
1187
|
if (autoFocus && formRef.current) {
|
|
1742
1188
|
const input = formRef.current.querySelector("input");
|
|
1743
1189
|
if (input) {
|
|
@@ -1747,7 +1193,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1747
1193
|
}, [
|
|
1748
1194
|
autoFocus
|
|
1749
1195
|
]);
|
|
1750
|
-
return /* @__PURE__ */
|
|
1196
|
+
return /* @__PURE__ */ React12.createElement(FormProvider, {
|
|
1751
1197
|
formRef,
|
|
1752
1198
|
schema,
|
|
1753
1199
|
autoSave,
|
|
@@ -1756,37 +1202,36 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1756
1202
|
onValidate,
|
|
1757
1203
|
onValid,
|
|
1758
1204
|
onSave
|
|
1759
|
-
}, /* @__PURE__ */
|
|
1205
|
+
}, /* @__PURE__ */ React12.createElement("div", {
|
|
1760
1206
|
ref: formRef,
|
|
1761
1207
|
role: "none",
|
|
1762
|
-
className:
|
|
1208
|
+
className: mx7("p-2", classNames),
|
|
1763
1209
|
"data-testid": testId
|
|
1764
|
-
}, /* @__PURE__ */
|
|
1210
|
+
}, /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1765
1211
|
schema,
|
|
1766
1212
|
path,
|
|
1767
1213
|
readonly,
|
|
1768
1214
|
filter,
|
|
1769
1215
|
sort,
|
|
1770
|
-
onQueryRefOptions,
|
|
1771
1216
|
lookupComponent,
|
|
1772
1217
|
Custom
|
|
1773
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1218
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React12.createElement(FormActions, {
|
|
1774
1219
|
onCancel,
|
|
1775
1220
|
readonly
|
|
1776
1221
|
})));
|
|
1777
1222
|
};
|
|
1778
1223
|
|
|
1779
1224
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
1780
|
-
var
|
|
1225
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1781
1226
|
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1782
1227
|
const { t } = useTranslation6(translationKey);
|
|
1783
|
-
const [props, setProps] =
|
|
1784
|
-
|
|
1228
|
+
const [props, setProps] = useState4(projection.getFieldProjection(field.id).props);
|
|
1229
|
+
useEffect7(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1785
1230
|
field,
|
|
1786
1231
|
projection
|
|
1787
1232
|
]);
|
|
1788
|
-
const [schemas, setSchemas] =
|
|
1789
|
-
|
|
1233
|
+
const [schemas, setSchemas] = useState4([]);
|
|
1234
|
+
useEffect7(() => {
|
|
1790
1235
|
if (!registry) {
|
|
1791
1236
|
return;
|
|
1792
1237
|
}
|
|
@@ -1804,17 +1249,17 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1804
1249
|
}, [
|
|
1805
1250
|
registry
|
|
1806
1251
|
]);
|
|
1807
|
-
const [referenceSchema, setReferenceSchema] =
|
|
1808
|
-
|
|
1252
|
+
const [referenceSchema, setReferenceSchema] = useState4();
|
|
1253
|
+
useEffect7(() => {
|
|
1809
1254
|
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1810
1255
|
}, [
|
|
1811
1256
|
schemas,
|
|
1812
1257
|
props?.referenceSchema
|
|
1813
1258
|
]);
|
|
1814
|
-
const [{ fieldSchema }, setFieldSchema] =
|
|
1259
|
+
const [{ fieldSchema }, setFieldSchema] = useState4({
|
|
1815
1260
|
fieldSchema: getFormatSchema(props?.format)
|
|
1816
1261
|
});
|
|
1817
|
-
const handleValuesChanged =
|
|
1262
|
+
const handleValuesChanged = useCallback6((_props) => {
|
|
1818
1263
|
setFieldSchema((prev) => {
|
|
1819
1264
|
const fieldSchema2 = getFormatSchema(_props.format);
|
|
1820
1265
|
if (prev.fieldSchema === fieldSchema2) {
|
|
@@ -1849,7 +1294,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1849
1294
|
props.format,
|
|
1850
1295
|
props.referenceSchema
|
|
1851
1296
|
]);
|
|
1852
|
-
const handleValidate =
|
|
1297
|
+
const handleValidate = useCallback6(({ property }) => {
|
|
1853
1298
|
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
1854
1299
|
return [
|
|
1855
1300
|
{
|
|
@@ -1862,7 +1307,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1862
1307
|
view.fields,
|
|
1863
1308
|
field
|
|
1864
1309
|
]);
|
|
1865
|
-
const handleSave =
|
|
1310
|
+
const handleSave = useCallback6((props2) => {
|
|
1866
1311
|
projection.setFieldProjection({
|
|
1867
1312
|
field,
|
|
1868
1313
|
props: props2
|
|
@@ -1873,51 +1318,51 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1873
1318
|
field,
|
|
1874
1319
|
onSave
|
|
1875
1320
|
]);
|
|
1876
|
-
const handleCancel =
|
|
1321
|
+
const handleCancel = useCallback6(() => {
|
|
1877
1322
|
requestAnimationFrame(() => onCancel?.());
|
|
1878
1323
|
onSave();
|
|
1879
1324
|
}, [
|
|
1880
1325
|
onSave
|
|
1881
1326
|
]);
|
|
1882
1327
|
const Custom = useMemo7(() => ({
|
|
1883
|
-
["format"]: (props2) => /* @__PURE__ */
|
|
1328
|
+
["format"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
|
|
1884
1329
|
...props2,
|
|
1885
|
-
options: FormatEnums.filter((value) => value !==
|
|
1330
|
+
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
1886
1331
|
value,
|
|
1887
1332
|
label: t(`format ${value}`)
|
|
1888
1333
|
}))
|
|
1889
1334
|
}),
|
|
1890
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */
|
|
1335
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
|
|
1891
1336
|
...props2,
|
|
1892
1337
|
options: schemas.map((schema) => ({
|
|
1893
1338
|
value: schema.typename
|
|
1894
1339
|
}))
|
|
1895
1340
|
}),
|
|
1896
|
-
["referencePath"]: (props2) => /* @__PURE__ */
|
|
1341
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
|
|
1897
1342
|
...props2,
|
|
1898
1343
|
options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
|
|
1899
1344
|
value: p.name
|
|
1900
1345
|
})) : []
|
|
1901
1346
|
}),
|
|
1902
|
-
["options"]: (props2) => /* @__PURE__ */
|
|
1347
|
+
["options"]: (props2) => /* @__PURE__ */ React13.createElement(SelectOptionInput, props2)
|
|
1903
1348
|
}), [
|
|
1904
1349
|
t,
|
|
1905
1350
|
schemas,
|
|
1906
1351
|
referenceSchema
|
|
1907
1352
|
]);
|
|
1908
|
-
const propIsNotType =
|
|
1353
|
+
const propIsNotType = useCallback6((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
1909
1354
|
if (!fieldSchema) {
|
|
1910
|
-
|
|
1355
|
+
log2.warn("invalid format", {
|
|
1911
1356
|
props
|
|
1912
1357
|
}, {
|
|
1913
|
-
F:
|
|
1358
|
+
F: __dxlog_file3,
|
|
1914
1359
|
L: 174,
|
|
1915
1360
|
S: void 0,
|
|
1916
1361
|
C: (f, a) => f(...a)
|
|
1917
1362
|
});
|
|
1918
1363
|
return null;
|
|
1919
1364
|
}
|
|
1920
|
-
return /* @__PURE__ */
|
|
1365
|
+
return /* @__PURE__ */ React13.createElement(Form, {
|
|
1921
1366
|
key: field.id,
|
|
1922
1367
|
autoFocus: true,
|
|
1923
1368
|
values: props,
|
|
@@ -1936,32 +1381,30 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1936
1381
|
};
|
|
1937
1382
|
|
|
1938
1383
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
1939
|
-
import {
|
|
1940
|
-
import
|
|
1941
|
-
import { Format, isMutable, toJsonSchema } from "@dxos/echo-schema";
|
|
1384
|
+
import React14, { useCallback as useCallback7, useMemo as useMemo8, useState as useState5 } from "react";
|
|
1385
|
+
import { AST as AST4, Format, S as S2 } from "@dxos/echo-schema";
|
|
1942
1386
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1943
1387
|
import { IconButton as IconButton4, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1944
1388
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
1945
|
-
import { ghostHover, inputTextLabel, mx as
|
|
1389
|
+
import { ghostHover, inputTextLabel, mx as mx8 } from "@dxos/react-ui-theme";
|
|
1946
1390
|
import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1947
|
-
var
|
|
1391
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1948
1392
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1949
|
-
var ViewMetaSchema =
|
|
1950
|
-
name:
|
|
1951
|
-
[
|
|
1393
|
+
var ViewMetaSchema = S2.Struct({
|
|
1394
|
+
name: S2.String.annotations({
|
|
1395
|
+
[AST4.TitleAnnotationId]: "View"
|
|
1952
1396
|
}),
|
|
1953
1397
|
typename: Format.URL.annotations({
|
|
1954
|
-
[
|
|
1398
|
+
[AST4.TitleAnnotationId]: "Typename"
|
|
1955
1399
|
})
|
|
1956
|
-
}).pipe(
|
|
1400
|
+
}).pipe(S2.mutable);
|
|
1957
1401
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1958
1402
|
const { t } = useTranslation7(translationKey);
|
|
1959
|
-
const projection = useMemo8(() => new ViewProjection(
|
|
1403
|
+
const projection = useMemo8(() => new ViewProjection(schema.jsonSchema, view), [
|
|
1960
1404
|
schema,
|
|
1961
1405
|
view
|
|
1962
1406
|
]);
|
|
1963
|
-
const [field, setField] =
|
|
1964
|
-
const immutable = readonly || !isMutable(schema);
|
|
1407
|
+
const [field, setField] = useState5();
|
|
1965
1408
|
const viewValues = useMemo8(() => {
|
|
1966
1409
|
return {
|
|
1967
1410
|
name: view.name,
|
|
@@ -1972,16 +1415,16 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1972
1415
|
}, [
|
|
1973
1416
|
view
|
|
1974
1417
|
]);
|
|
1975
|
-
const handleSelect =
|
|
1418
|
+
const handleSelect = useCallback7((field2) => {
|
|
1976
1419
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1977
1420
|
}, []);
|
|
1978
|
-
const handleAdd =
|
|
1979
|
-
invariant3(!
|
|
1980
|
-
F:
|
|
1981
|
-
L:
|
|
1421
|
+
const handleAdd = useCallback7(() => {
|
|
1422
|
+
invariant3(!schema.readonly, void 0, {
|
|
1423
|
+
F: __dxlog_file4,
|
|
1424
|
+
L: 76,
|
|
1982
1425
|
S: void 0,
|
|
1983
1426
|
A: [
|
|
1984
|
-
"!
|
|
1427
|
+
"!schema.readonly",
|
|
1985
1428
|
""
|
|
1986
1429
|
]
|
|
1987
1430
|
});
|
|
@@ -1991,13 +1434,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1991
1434
|
schema,
|
|
1992
1435
|
view
|
|
1993
1436
|
]);
|
|
1994
|
-
const handleUpdate =
|
|
1995
|
-
invariant3(!
|
|
1996
|
-
F:
|
|
1997
|
-
L:
|
|
1437
|
+
const handleUpdate = useCallback7(({ name, typename }) => {
|
|
1438
|
+
invariant3(!schema.readonly, void 0, {
|
|
1439
|
+
F: __dxlog_file4,
|
|
1440
|
+
L: 83,
|
|
1998
1441
|
S: void 0,
|
|
1999
1442
|
A: [
|
|
2000
|
-
"!
|
|
1443
|
+
"!schema.readonly",
|
|
2001
1444
|
""
|
|
2002
1445
|
]
|
|
2003
1446
|
});
|
|
@@ -2014,13 +1457,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
2014
1457
|
view,
|
|
2015
1458
|
onTypenameChanged
|
|
2016
1459
|
]);
|
|
2017
|
-
const handleDelete =
|
|
2018
|
-
invariant3(!
|
|
2019
|
-
F:
|
|
2020
|
-
L:
|
|
1460
|
+
const handleDelete = useCallback7((fieldId) => {
|
|
1461
|
+
invariant3(!schema.readonly, void 0, {
|
|
1462
|
+
F: __dxlog_file4,
|
|
1463
|
+
L: 99,
|
|
2021
1464
|
S: void 0,
|
|
2022
1465
|
A: [
|
|
2023
|
-
"!
|
|
1466
|
+
"!schema.readonly",
|
|
2024
1467
|
""
|
|
2025
1468
|
]
|
|
2026
1469
|
});
|
|
@@ -2033,13 +1476,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
2033
1476
|
field,
|
|
2034
1477
|
onDelete
|
|
2035
1478
|
]);
|
|
2036
|
-
const handleMove =
|
|
2037
|
-
invariant3(!
|
|
2038
|
-
F:
|
|
2039
|
-
L:
|
|
1479
|
+
const handleMove = useCallback7((fromIndex, toIndex) => {
|
|
1480
|
+
invariant3(!schema.readonly, void 0, {
|
|
1481
|
+
F: __dxlog_file4,
|
|
1482
|
+
L: 111,
|
|
2040
1483
|
S: void 0,
|
|
2041
1484
|
A: [
|
|
2042
|
-
"!
|
|
1485
|
+
"!schema.readonly",
|
|
2043
1486
|
""
|
|
2044
1487
|
]
|
|
2045
1488
|
});
|
|
@@ -2053,111 +1496,363 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
2053
1496
|
schema,
|
|
2054
1497
|
view.fields
|
|
2055
1498
|
]);
|
|
2056
|
-
const handleClose =
|
|
1499
|
+
const handleClose = useCallback7(() => setField(void 0), []);
|
|
2057
1500
|
const hiddenProperties = projection.getHiddenProperties();
|
|
2058
|
-
const handleHide =
|
|
1501
|
+
const handleHide = useCallback7((fieldId) => {
|
|
2059
1502
|
setField(void 0);
|
|
2060
1503
|
projection.hideFieldProjection(fieldId);
|
|
2061
1504
|
}, [
|
|
2062
1505
|
projection
|
|
2063
1506
|
]);
|
|
2064
|
-
const handleShow =
|
|
1507
|
+
const handleShow = useCallback7((property) => {
|
|
2065
1508
|
setField(void 0);
|
|
2066
1509
|
projection.showFieldProjection(property);
|
|
2067
1510
|
}, [
|
|
2068
1511
|
projection
|
|
2069
1512
|
]);
|
|
2070
|
-
return /* @__PURE__ */
|
|
1513
|
+
return /* @__PURE__ */ React14.createElement("div", {
|
|
2071
1514
|
role: "none",
|
|
2072
|
-
className:
|
|
2073
|
-
}, /* @__PURE__ */
|
|
1515
|
+
className: mx8("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1516
|
+
}, /* @__PURE__ */ React14.createElement(Form, {
|
|
2074
1517
|
autoSave: true,
|
|
2075
1518
|
schema: ViewMetaSchema,
|
|
2076
1519
|
values: viewValues,
|
|
2077
|
-
onSave:
|
|
2078
|
-
|
|
2079
|
-
}), /* @__PURE__ */ React15.createElement("div", {
|
|
2080
|
-
role: "none",
|
|
2081
|
-
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
2082
|
-
}, /* @__PURE__ */ React15.createElement("div", {
|
|
1520
|
+
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1521
|
+
}), /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("div", {
|
|
2083
1522
|
role: "none",
|
|
2084
1523
|
className: "p-2"
|
|
2085
|
-
}, /* @__PURE__ */
|
|
2086
|
-
className:
|
|
2087
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1524
|
+
}, /* @__PURE__ */ React14.createElement("label", {
|
|
1525
|
+
className: mx8(inputTextLabel)
|
|
1526
|
+
}, t("fields label"))), /* @__PURE__ */ React14.createElement(List2.Root, {
|
|
2088
1527
|
items: view.fields,
|
|
2089
|
-
isItem:
|
|
1528
|
+
isItem: S2.is(FieldSchema),
|
|
2090
1529
|
getId: (field2) => field2.id,
|
|
2091
|
-
onMove:
|
|
2092
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1530
|
+
onMove: schema.readonly ? void 0 : handleMove
|
|
1531
|
+
}, ({ items: fields }) => /* @__PURE__ */ React14.createElement(React14.Fragment, null, showHeading && /* @__PURE__ */ React14.createElement("div", {
|
|
2093
1532
|
role: "heading",
|
|
2094
1533
|
className: grid
|
|
2095
|
-
}, /* @__PURE__ */
|
|
1534
|
+
}, /* @__PURE__ */ React14.createElement("div", null), /* @__PURE__ */ React14.createElement("div", {
|
|
2096
1535
|
className: "flex items-center text-sm"
|
|
2097
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1536
|
+
}, t("field path label"))), /* @__PURE__ */ React14.createElement("div", {
|
|
2098
1537
|
role: "list",
|
|
2099
1538
|
className: "flex flex-col w-full"
|
|
2100
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1539
|
+
}, fields?.map((field2) => /* @__PURE__ */ React14.createElement(List2.Item, {
|
|
2101
1540
|
key: field2.id,
|
|
2102
1541
|
item: field2,
|
|
2103
|
-
classNames:
|
|
2104
|
-
}, /* @__PURE__ */
|
|
1542
|
+
classNames: mx8(grid, ghostHover, "cursor-pointer")
|
|
1543
|
+
}, /* @__PURE__ */ React14.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React14.createElement(List2.ItemTitle, {
|
|
2105
1544
|
onClick: () => handleSelect(field2)
|
|
2106
|
-
}, field2.path), /* @__PURE__ */
|
|
1545
|
+
}, field2.path), /* @__PURE__ */ React14.createElement("div", {
|
|
2107
1546
|
className: "flex items-center gap-2 -ml-4"
|
|
2108
|
-
}, /* @__PURE__ */
|
|
1547
|
+
}, /* @__PURE__ */ React14.createElement(List2.ItemButton, {
|
|
2109
1548
|
icon: "ph--eye-slash--regular",
|
|
2110
1549
|
disabled: view.fields.length <= 1,
|
|
2111
1550
|
onClick: () => handleHide(field2.id)
|
|
2112
|
-
}), !
|
|
1551
|
+
}), !schema.readonly && /* @__PURE__ */ React14.createElement(List2.ItemDeleteButton, {
|
|
2113
1552
|
icon: "ph--trash--regular",
|
|
2114
1553
|
disabled: view.fields.length <= 1,
|
|
2115
1554
|
onClick: () => handleDelete(field2.id)
|
|
2116
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
1555
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("div", {
|
|
2117
1556
|
role: "none",
|
|
2118
1557
|
className: "p-2"
|
|
2119
|
-
}, /* @__PURE__ */
|
|
2120
|
-
className:
|
|
2121
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
1558
|
+
}, /* @__PURE__ */ React14.createElement("label", {
|
|
1559
|
+
className: mx8(inputTextLabel)
|
|
1560
|
+
}, t("hidden fields label"))), /* @__PURE__ */ React14.createElement(List2.Root, {
|
|
2122
1561
|
items: hiddenProperties,
|
|
2123
1562
|
isItem: (item) => typeof item === "string",
|
|
2124
1563
|
getId: (property) => property
|
|
2125
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
1564
|
+
}, ({ items: properties }) => /* @__PURE__ */ React14.createElement("div", {
|
|
2126
1565
|
role: "list",
|
|
2127
1566
|
className: "flex flex-col w-full"
|
|
2128
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
1567
|
+
}, properties?.map((property) => /* @__PURE__ */ React14.createElement(List2.Item, {
|
|
2129
1568
|
key: property,
|
|
2130
1569
|
item: property,
|
|
2131
|
-
classNames:
|
|
2132
|
-
}, /* @__PURE__ */
|
|
1570
|
+
classNames: mx8(grid, ghostHover, "cursor-pointer")
|
|
1571
|
+
}, /* @__PURE__ */ React14.createElement("div", null), /* @__PURE__ */ React14.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React14.createElement(List2.ItemButton, {
|
|
2133
1572
|
icon: "ph--eye--regular",
|
|
2134
1573
|
onClick: () => handleShow(property)
|
|
2135
|
-
}))))))), field && /* @__PURE__ */
|
|
1574
|
+
}))))))), field && /* @__PURE__ */ React14.createElement(FieldEditor, {
|
|
2136
1575
|
key: field.id,
|
|
2137
1576
|
view,
|
|
2138
1577
|
projection,
|
|
2139
1578
|
field,
|
|
2140
1579
|
registry,
|
|
2141
1580
|
onSave: handleClose
|
|
2142
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1581
|
+
}), !readonly && !field && /* @__PURE__ */ React14.createElement("div", {
|
|
2143
1582
|
className: "flex p-2 justify-center"
|
|
2144
|
-
}, /* @__PURE__ */
|
|
1583
|
+
}, /* @__PURE__ */ React14.createElement(IconButton4, {
|
|
2145
1584
|
icon: "ph--plus--regular",
|
|
2146
1585
|
label: t("button add property"),
|
|
2147
|
-
onClick:
|
|
1586
|
+
onClick: schema.readonly ? void 0 : handleAdd,
|
|
2148
1587
|
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
2149
1588
|
disabled: view.fields.length >= VIEW_FIELD_LIMIT
|
|
2150
1589
|
})));
|
|
2151
1590
|
};
|
|
1591
|
+
|
|
1592
|
+
// packages/ui/react-ui-form/src/util/field.ts
|
|
1593
|
+
import { FormatEnum as FormatEnum3, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo-schema";
|
|
1594
|
+
var parseValue = ({ type, format, value }) => {
|
|
1595
|
+
if (value === void 0 || value === null || value === "") {
|
|
1596
|
+
return void 0;
|
|
1597
|
+
}
|
|
1598
|
+
const parseScalar = (type2) => {
|
|
1599
|
+
switch (type2) {
|
|
1600
|
+
case TypeEnum.Boolean: {
|
|
1601
|
+
if (typeof value === "string") {
|
|
1602
|
+
const lowercaseValue = value.toLowerCase();
|
|
1603
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1604
|
+
return false;
|
|
1605
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1606
|
+
return true;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
return Boolean(value);
|
|
1610
|
+
}
|
|
1611
|
+
case TypeEnum.Number: {
|
|
1612
|
+
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1613
|
+
const num = Number(cleaned);
|
|
1614
|
+
return Number.isNaN(num) ? null : num;
|
|
1615
|
+
}
|
|
1616
|
+
case TypeEnum.String:
|
|
1617
|
+
case TypeEnum.Ref:
|
|
1618
|
+
return String(value);
|
|
1619
|
+
default: {
|
|
1620
|
+
return value;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
if (!format) {
|
|
1625
|
+
return parseScalar(type);
|
|
1626
|
+
}
|
|
1627
|
+
switch (format) {
|
|
1628
|
+
case FormatEnum3.Boolean:
|
|
1629
|
+
return parseScalar(TypeEnum.Boolean);
|
|
1630
|
+
case FormatEnum3.Number:
|
|
1631
|
+
case FormatEnum3.Percent:
|
|
1632
|
+
case FormatEnum3.Currency:
|
|
1633
|
+
return parseScalar(TypeEnum.Number);
|
|
1634
|
+
case FormatEnum3.String:
|
|
1635
|
+
case FormatEnum3.Markdown: {
|
|
1636
|
+
return parseScalar(TypeEnum.String);
|
|
1637
|
+
}
|
|
1638
|
+
case FormatEnum3.Ref:
|
|
1639
|
+
throw new Error(`unexpected format: ${FormatEnum3.Ref}`);
|
|
1640
|
+
case FormatEnum3.DateTime:
|
|
1641
|
+
case FormatEnum3.Date:
|
|
1642
|
+
case FormatEnum3.Time:
|
|
1643
|
+
case FormatEnum3.Timestamp: {
|
|
1644
|
+
const date = new Date(value);
|
|
1645
|
+
return isNaN(date.getTime()) ? null : date;
|
|
1646
|
+
}
|
|
1647
|
+
case FormatEnum3.GeoPoint: {
|
|
1648
|
+
if (typeof value === "string") {
|
|
1649
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1650
|
+
const parts = cleaned.split(",");
|
|
1651
|
+
if (parts.length === 2) {
|
|
1652
|
+
const lat = parseFloat(parts[0]);
|
|
1653
|
+
const long = parseFloat(parts[1]);
|
|
1654
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1655
|
+
return GeoLocation2.toGeoPoint({
|
|
1656
|
+
latitude: lat,
|
|
1657
|
+
longitude: long
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
return [
|
|
1663
|
+
0,
|
|
1664
|
+
0
|
|
1665
|
+
];
|
|
1666
|
+
}
|
|
1667
|
+
default: {
|
|
1668
|
+
return value;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
var cellClassesForFieldType = ({ type, format }) => {
|
|
1673
|
+
if (!format) {
|
|
1674
|
+
switch (type) {
|
|
1675
|
+
case TypeEnum.Number:
|
|
1676
|
+
return [
|
|
1677
|
+
"text-right",
|
|
1678
|
+
"font-mono"
|
|
1679
|
+
];
|
|
1680
|
+
case TypeEnum.Boolean:
|
|
1681
|
+
return [
|
|
1682
|
+
"text-right",
|
|
1683
|
+
"font-mono"
|
|
1684
|
+
];
|
|
1685
|
+
case TypeEnum.String:
|
|
1686
|
+
return void 0;
|
|
1687
|
+
case TypeEnum.Ref:
|
|
1688
|
+
return void 0;
|
|
1689
|
+
default: {
|
|
1690
|
+
return void 0;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
switch (format) {
|
|
1695
|
+
case FormatEnum3.Markdown:
|
|
1696
|
+
return void 0;
|
|
1697
|
+
case FormatEnum3.Time:
|
|
1698
|
+
case FormatEnum3.Timestamp:
|
|
1699
|
+
case FormatEnum3.DateTime:
|
|
1700
|
+
case FormatEnum3.Date:
|
|
1701
|
+
case FormatEnum3.Duration:
|
|
1702
|
+
return [
|
|
1703
|
+
"font-mono",
|
|
1704
|
+
"text-right"
|
|
1705
|
+
];
|
|
1706
|
+
case FormatEnum3.Currency:
|
|
1707
|
+
return [
|
|
1708
|
+
"text-right"
|
|
1709
|
+
];
|
|
1710
|
+
case FormatEnum3.JSON:
|
|
1711
|
+
case FormatEnum3.DID:
|
|
1712
|
+
return [
|
|
1713
|
+
"font-mono"
|
|
1714
|
+
];
|
|
1715
|
+
default:
|
|
1716
|
+
return void 0;
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
var pathNotUniqueError = (path) => ({
|
|
1720
|
+
path: "path",
|
|
1721
|
+
message: `'${path}' is already present`
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
// packages/ui/react-ui-form/src/util/formatting.ts
|
|
1725
|
+
import { format as formatDate } from "date-fns/format";
|
|
1726
|
+
import { FormatEnum as FormatEnum4, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
|
|
1727
|
+
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1728
|
+
const formatScalar = (type2) => {
|
|
1729
|
+
switch (type2) {
|
|
1730
|
+
case TypeEnum2.Boolean:
|
|
1731
|
+
return value.toLocaleString().toUpperCase();
|
|
1732
|
+
case TypeEnum2.Number:
|
|
1733
|
+
return value.toLocaleString(locale);
|
|
1734
|
+
case TypeEnum2.String:
|
|
1735
|
+
case TypeEnum2.Ref:
|
|
1736
|
+
return String(value);
|
|
1737
|
+
default: {
|
|
1738
|
+
return String(value);
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
if (!format) {
|
|
1743
|
+
return formatScalar(type);
|
|
1744
|
+
}
|
|
1745
|
+
switch (format) {
|
|
1746
|
+
case FormatEnum4.Boolean: {
|
|
1747
|
+
return formatScalar(TypeEnum2.Boolean);
|
|
1748
|
+
}
|
|
1749
|
+
case FormatEnum4.Number: {
|
|
1750
|
+
return formatScalar(TypeEnum2.Number);
|
|
1751
|
+
}
|
|
1752
|
+
case FormatEnum4.String:
|
|
1753
|
+
case FormatEnum4.Ref: {
|
|
1754
|
+
return formatScalar(TypeEnum2.String);
|
|
1755
|
+
}
|
|
1756
|
+
case FormatEnum4.Percent: {
|
|
1757
|
+
return `${value * 100}%`;
|
|
1758
|
+
}
|
|
1759
|
+
case FormatEnum4.Currency: {
|
|
1760
|
+
return value.toLocaleString(locale, {
|
|
1761
|
+
style: "currency",
|
|
1762
|
+
currency: "USD",
|
|
1763
|
+
minimumFractionDigits: 2,
|
|
1764
|
+
maximumFractionDigits: 2
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
case FormatEnum4.Date: {
|
|
1768
|
+
return formatDate(new Date(value), "yyyy-MM-dd");
|
|
1769
|
+
}
|
|
1770
|
+
case FormatEnum4.Time: {
|
|
1771
|
+
return formatDate(new Date(value), "HH:mm:ss");
|
|
1772
|
+
}
|
|
1773
|
+
case FormatEnum4.DateTime: {
|
|
1774
|
+
return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1775
|
+
}
|
|
1776
|
+
case FormatEnum4.GeoPoint: {
|
|
1777
|
+
if (value === null || value === void 0) {
|
|
1778
|
+
return "";
|
|
1779
|
+
}
|
|
1780
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1781
|
+
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1782
|
+
return `${latitude},${longitude}`;
|
|
1783
|
+
}
|
|
1784
|
+
return String(value);
|
|
1785
|
+
}
|
|
1786
|
+
default: {
|
|
1787
|
+
if (value === null || value === "undefined") {
|
|
1788
|
+
return "";
|
|
1789
|
+
}
|
|
1790
|
+
return String(value);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
};
|
|
1794
|
+
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1795
|
+
const formatScalar = (type2) => {
|
|
1796
|
+
switch (type2) {
|
|
1797
|
+
case TypeEnum2.Boolean:
|
|
1798
|
+
case TypeEnum2.Number:
|
|
1799
|
+
case TypeEnum2.String:
|
|
1800
|
+
case TypeEnum2.Ref:
|
|
1801
|
+
return String(value);
|
|
1802
|
+
default:
|
|
1803
|
+
return String(value);
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
if (!format) {
|
|
1807
|
+
return formatScalar(type);
|
|
1808
|
+
}
|
|
1809
|
+
switch (format) {
|
|
1810
|
+
case FormatEnum4.Boolean:
|
|
1811
|
+
case FormatEnum4.Number:
|
|
1812
|
+
case FormatEnum4.String:
|
|
1813
|
+
case FormatEnum4.Ref: {
|
|
1814
|
+
return formatScalar(type);
|
|
1815
|
+
}
|
|
1816
|
+
case FormatEnum4.Percent: {
|
|
1817
|
+
return String(value * 100);
|
|
1818
|
+
}
|
|
1819
|
+
case FormatEnum4.Currency: {
|
|
1820
|
+
return String(value);
|
|
1821
|
+
}
|
|
1822
|
+
case FormatEnum4.DateTime: {
|
|
1823
|
+
const date = new Date(value);
|
|
1824
|
+
return date.toISOString();
|
|
1825
|
+
}
|
|
1826
|
+
case FormatEnum4.Date: {
|
|
1827
|
+
const date = new Date(value);
|
|
1828
|
+
return date.toISOString().split("T")[0];
|
|
1829
|
+
}
|
|
1830
|
+
case FormatEnum4.Time: {
|
|
1831
|
+
const date = new Date(value);
|
|
1832
|
+
return date.toISOString().split("T")[1].split(".")[0];
|
|
1833
|
+
}
|
|
1834
|
+
case FormatEnum4.GeoPoint: {
|
|
1835
|
+
if (value === null || value === void 0) {
|
|
1836
|
+
return "";
|
|
1837
|
+
}
|
|
1838
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1839
|
+
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1840
|
+
return `${latitude},${longitude}`;
|
|
1841
|
+
}
|
|
1842
|
+
return String(value);
|
|
1843
|
+
}
|
|
1844
|
+
default: {
|
|
1845
|
+
return String(value);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
2152
1849
|
export {
|
|
2153
1850
|
BooleanInput,
|
|
2154
1851
|
ControlFrame,
|
|
2155
1852
|
ControlFrameItem,
|
|
2156
1853
|
ControlGroup,
|
|
2157
|
-
ControlGroupButton,
|
|
2158
1854
|
ControlItem,
|
|
2159
1855
|
ControlItemInput,
|
|
2160
|
-
ControlPage,
|
|
2161
1856
|
ControlSection,
|
|
2162
1857
|
ControlSectionHeading,
|
|
2163
1858
|
DeprecatedFormContainer,
|
|
@@ -2176,18 +1871,14 @@ export {
|
|
|
2176
1871
|
ViewEditor,
|
|
2177
1872
|
cellClassesForFieldType,
|
|
2178
1873
|
controlItemClasses,
|
|
2179
|
-
findArrayElementType,
|
|
2180
1874
|
formatForDisplay,
|
|
2181
1875
|
formatForEditing,
|
|
2182
|
-
getRefProps,
|
|
2183
1876
|
parseValue,
|
|
2184
1877
|
pathNotUniqueError,
|
|
2185
1878
|
translations_default as translations,
|
|
2186
1879
|
useForm,
|
|
2187
1880
|
useFormContext,
|
|
2188
1881
|
useFormValues,
|
|
2189
|
-
useInputProps
|
|
2190
|
-
useQueryRefOptions,
|
|
2191
|
-
useRefQueryLookupHandler
|
|
1882
|
+
useInputProps
|
|
2192
1883
|
};
|
|
2193
1884
|
//# sourceMappingURL=index.mjs.map
|