@dxos/react-ui-form 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203
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 +1610 -1825
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1610 -1825
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +3 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form-old.stories.d.ts +1 -42
- package/dist/types/src/components/Form/Form-old.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +9 -6
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +32 -32
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +2 -2
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +3 -3
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +8 -12
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +14 -9
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.d.ts +56 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/{ControlSection/ControlSection.stories.d.ts → Settings/Settings.stories.d.ts} +3 -9
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +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/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/echo.d.ts +6 -0
- package/dist/types/src/util/echo.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -45
- package/src/components/FieldEditor/FieldEditor.stories.tsx +39 -18
- package/src/components/FieldEditor/FieldEditor.tsx +13 -6
- package/src/components/Form/Form-old.stories.tsx +42 -42
- package/src/components/Form/Form.stories.tsx +12 -17
- package/src/components/Form/Form.tsx +52 -27
- package/src/components/Form/FormField.tsx +23 -17
- package/src/components/Form/FormFieldComponent.stories.tsx +1 -1
- package/src/components/Form/FormFieldComponent.tsx +17 -16
- package/src/components/Form/FormFieldSet.tsx +8 -5
- package/src/components/Form/fields/ArrayField.tsx +11 -11
- package/src/components/Form/fields/RefField.tsx +82 -99
- package/src/components/Form/fields/SelectOptionField.stories.tsx +1 -1
- package/src/components/Form/fields/SelectOptionField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +12 -5
- package/src/components/ObjectPicker/ObjectPicker.tsx +66 -57
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +234 -0
- package/src/components/{ControlSection → Settings}/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +18 -12
- package/src/components/ViewEditor/ViewEditor.test.tsx +1 -5
- package/src/components/ViewEditor/ViewEditor.tsx +77 -44
- package/src/components/index.ts +1 -1
- package/src/components/testing.tsx +3 -5
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useFormHandler.ts +20 -6
- package/src/translations.ts +1 -1
- package/src/util/echo.ts +25 -0
- package/src/util/index.ts +1 -0
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- 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/hooks/useQueryRefOptions.d.ts +0 -30
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryOptions.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryOptions.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
- package/src/components/ControlSection/ControlSection.tsx +0 -153
- package/src/hooks/useQueryRefOptions.ts +0 -70
- package/src/hooks/useRefQueryOptions.ts +0 -37
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/translations.ts
|
|
2
|
-
var translationKey = "react-ui-form";
|
|
2
|
+
var translationKey = "@dxos/react-ui-form";
|
|
3
3
|
var translations = [
|
|
4
4
|
{
|
|
5
5
|
"en-US": {
|
|
@@ -75,154 +75,27 @@ var translations = [
|
|
|
75
75
|
}
|
|
76
76
|
];
|
|
77
77
|
|
|
78
|
-
// src/components/ControlSection/ControlSection.tsx
|
|
79
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
80
|
-
import React from "react";
|
|
81
|
-
import { Button, Input, toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
82
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
83
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
84
|
-
var ControlPage = ({ children, classNames, ...props }) => {
|
|
85
|
-
var _effect = _useSignals();
|
|
86
|
-
try {
|
|
87
|
-
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
88
|
-
scrollable: true,
|
|
89
|
-
classNames: "[--control-spacing:var(--dx-trimMd)]"
|
|
90
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
91
|
-
role: "none",
|
|
92
|
-
className: mx("pli-cardSpacingInline pbe-trimLg", classNames),
|
|
93
|
-
...props
|
|
94
|
-
}, children));
|
|
95
|
-
} finally {
|
|
96
|
-
_effect.f();
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var ControlSection = ({ title, description, children }) => {
|
|
100
|
-
var _effect = _useSignals();
|
|
101
|
-
try {
|
|
102
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ControlSectionHeading, {
|
|
103
|
-
title,
|
|
104
|
-
description
|
|
105
|
-
}), children);
|
|
106
|
-
} finally {
|
|
107
|
-
_effect.f();
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
var ControlSectionHeading = ({ title, description }) => {
|
|
111
|
-
var _effect = _useSignals();
|
|
112
|
-
try {
|
|
113
|
-
const { t } = useTranslation(translationKey);
|
|
114
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h2", {
|
|
115
|
-
className: "pli-trimMd container-max-width text-xl mbs-trimLg mbe-trimMd"
|
|
116
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
|
|
117
|
-
className: "pli-trimMd mlb-trimMd container-max-width text-description"
|
|
118
|
-
}, toLocalizedString(description, t)));
|
|
119
|
-
} finally {
|
|
120
|
-
_effect.f();
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
124
|
-
var _effect = _useSignals();
|
|
125
|
-
try {
|
|
126
|
-
return /* @__PURE__ */ React.createElement(Button, {
|
|
127
|
-
...props,
|
|
128
|
-
classNames: [
|
|
129
|
-
"md:col-span-2",
|
|
130
|
-
classNames
|
|
131
|
-
]
|
|
132
|
-
});
|
|
133
|
-
} finally {
|
|
134
|
-
_effect.f();
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var ControlGroup = ({ children, classNames }) => {
|
|
138
|
-
var _effect = _useSignals();
|
|
139
|
-
try {
|
|
140
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
141
|
-
role: "none",
|
|
142
|
-
className: mx("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd", "[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end", classNames)
|
|
143
|
-
}, children);
|
|
144
|
-
} finally {
|
|
145
|
-
_effect.f();
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
var ControlFrame = ({ children }) => {
|
|
149
|
-
var _effect = _useSignals();
|
|
150
|
-
try {
|
|
151
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
152
|
-
role: "none",
|
|
153
|
-
className: mx("container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd", "border border-separator rounded-md")
|
|
154
|
-
}, children);
|
|
155
|
-
} finally {
|
|
156
|
-
_effect.f();
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
var controlItemClasses = mx([
|
|
160
|
-
"container-max-width grid md:col-span-2 grid-cols-subgrid gap-trimSm items-center",
|
|
161
|
-
// TODO(burdon): Use grid gap consistently or apply margins consistently?
|
|
162
|
-
"mlb-[--control-spacing] *:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd",
|
|
163
|
-
"border border-separator rounded-md"
|
|
164
|
-
]);
|
|
165
|
-
var controlItemTitleClasses = "mbe-0 text-lg text-baseText font-normal";
|
|
166
|
-
var controlItemDescriptionClasses = "mlb-trimSm md:mbe-0 text-base text-description";
|
|
167
|
-
var ControlItem = ({ title, description, children }) => {
|
|
168
|
-
var _effect = _useSignals();
|
|
169
|
-
try {
|
|
170
|
-
const { t } = useTranslation(translationKey);
|
|
171
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
172
|
-
className: controlItemClasses
|
|
173
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
174
|
-
role: "none"
|
|
175
|
-
}, /* @__PURE__ */ React.createElement("h3", {
|
|
176
|
-
className: controlItemTitleClasses
|
|
177
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
|
|
178
|
-
className: controlItemDescriptionClasses
|
|
179
|
-
}, toLocalizedString(description, t))), children);
|
|
180
|
-
} finally {
|
|
181
|
-
_effect.f();
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var ControlItemInput = ({ title, description, children }) => {
|
|
185
|
-
var _effect = _useSignals();
|
|
186
|
-
try {
|
|
187
|
-
const { t } = useTranslation(translationKey);
|
|
188
|
-
return /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement("div", {
|
|
189
|
-
className: controlItemClasses
|
|
190
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
191
|
-
role: "none"
|
|
192
|
-
}, /* @__PURE__ */ React.createElement(Input.Label, {
|
|
193
|
-
classNames: controlItemTitleClasses
|
|
194
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Description, {
|
|
195
|
-
classNames: controlItemDescriptionClasses
|
|
196
|
-
}, toLocalizedString(description, t)))), children));
|
|
197
|
-
} finally {
|
|
198
|
-
_effect.f();
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var ControlFrameItem = ({ title, description, children }) => {
|
|
202
|
-
var _effect = _useSignals();
|
|
203
|
-
try {
|
|
204
|
-
const { t } = useTranslation(translationKey);
|
|
205
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
206
|
-
role: "group",
|
|
207
|
-
className: "min-is-0"
|
|
208
|
-
}, /* @__PURE__ */ React.createElement("h3", {
|
|
209
|
-
className: "text-lg mbe-2"
|
|
210
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
|
|
211
|
-
className: "mlb-trimSm md:mbe-0 text-description"
|
|
212
|
-
}, toLocalizedString(description, t)), children);
|
|
213
|
-
} finally {
|
|
214
|
-
_effect.f();
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
78
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
219
|
-
import {
|
|
220
|
-
import
|
|
79
|
+
import React17, { useCallback as useCallback14, useEffect as useEffect7, useMemo as useMemo7, useState as useState5 } from "react";
|
|
80
|
+
import { Obj as Obj3 } from "@dxos/echo";
|
|
221
81
|
import { Format as Format4, FormatEnums, formatToType } from "@dxos/echo/internal";
|
|
222
|
-
import { log as
|
|
223
|
-
import { useAsyncEffect
|
|
82
|
+
import { log as log2 } from "@dxos/log";
|
|
83
|
+
import { useAsyncEffect, useTranslation as useTranslation8 } from "@dxos/react-ui";
|
|
224
84
|
import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
|
|
225
85
|
|
|
86
|
+
// src/util/echo.ts
|
|
87
|
+
import { Obj } from "@dxos/echo";
|
|
88
|
+
import { setValue as setValuePlain, splitJsonPath } from "@dxos/effect";
|
|
89
|
+
var setValueEchoAware = (obj, path, value3) => {
|
|
90
|
+
if (Obj.isObject(obj)) {
|
|
91
|
+
Obj.change(obj, (mutableObj) => {
|
|
92
|
+
Obj.setValue(mutableObj, splitJsonPath(path), value3);
|
|
93
|
+
});
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
return setValuePlain(obj, path, value3);
|
|
97
|
+
};
|
|
98
|
+
|
|
226
99
|
// src/util/field.ts
|
|
227
100
|
import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
|
|
228
101
|
var parseValue = ({ type, format, value: value3 }) => {
|
|
@@ -515,28 +388,25 @@ var getRefProps = (ast) => {
|
|
|
515
388
|
};
|
|
516
389
|
|
|
517
390
|
// src/components/Form/fields/ArrayField.tsx
|
|
518
|
-
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
519
391
|
import * as Option3 from "effect/Option";
|
|
520
392
|
import * as SchemaAST2 from "effect/SchemaAST";
|
|
521
|
-
import
|
|
393
|
+
import React5, { useCallback as useCallback3 } from "react";
|
|
522
394
|
import { findNode as findNode2, getArrayElementType as getArrayElementType2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2, isNestedType as isNestedType2 } from "@dxos/effect";
|
|
523
|
-
import {
|
|
524
|
-
import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
395
|
+
import { IconButton as IconButton2, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
525
396
|
|
|
526
397
|
// src/components/Form/Form.tsx
|
|
527
|
-
import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
|
|
528
398
|
import { createContext } from "@radix-ui/react-context";
|
|
529
399
|
import * as Schema2 from "effect/Schema";
|
|
530
|
-
import
|
|
400
|
+
import React4, { useEffect as useEffect3, useMemo as useMemo4, useRef } from "react";
|
|
531
401
|
import { createJsonPath as createJsonPath3, getValue as getValue$2 } from "@dxos/effect";
|
|
532
|
-
import { IconButton, ScrollArea, useTranslation as
|
|
533
|
-
import { mx as
|
|
402
|
+
import { IconButton, ScrollArea, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
403
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
534
404
|
|
|
535
405
|
// src/hooks/useFormHandler.ts
|
|
536
406
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
537
407
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
538
|
-
import {
|
|
539
|
-
import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
|
|
408
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
409
|
+
import { createJsonPath, fromEffectValidationPath, getValue as getValue$, setValue as setValue$ } from "@dxos/effect";
|
|
540
410
|
import { log } from "@dxos/log";
|
|
541
411
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
542
412
|
import { validateSchema } from "@dxos/schema";
|
|
@@ -547,7 +417,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
547
417
|
const [errors, setErrors] = useState({});
|
|
548
418
|
const [saving, setSaving] = useState(false);
|
|
549
419
|
const defaultValues = useDefaultValue(defaultValuesProp, () => ({}));
|
|
550
|
-
const [values
|
|
420
|
+
const [values$, setValues] = useControllableState({
|
|
551
421
|
prop: valuesProp,
|
|
552
422
|
defaultProp: defaultValues,
|
|
553
423
|
onChange: () => {
|
|
@@ -558,6 +428,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
558
428
|
setSaving(false);
|
|
559
429
|
}
|
|
560
430
|
});
|
|
431
|
+
const values = values$;
|
|
561
432
|
const validate = useCallback((values2) => {
|
|
562
433
|
if (!schema) {
|
|
563
434
|
return false;
|
|
@@ -568,7 +439,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
568
439
|
errors: errors2
|
|
569
440
|
}, {
|
|
570
441
|
F: __dxlog_file,
|
|
571
|
-
L:
|
|
442
|
+
L: 160,
|
|
572
443
|
S: void 0,
|
|
573
444
|
C: (f, a) => f(...a)
|
|
574
445
|
});
|
|
@@ -661,7 +532,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
661
532
|
value: value3
|
|
662
533
|
}, {
|
|
663
534
|
F: __dxlog_file,
|
|
664
|
-
L:
|
|
535
|
+
L: 259,
|
|
665
536
|
S: void 0,
|
|
666
537
|
C: (f, a) => f(...a)
|
|
667
538
|
});
|
|
@@ -674,23 +545,22 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
674
545
|
} catch (err) {
|
|
675
546
|
log.catch(err, void 0, {
|
|
676
547
|
F: __dxlog_file,
|
|
677
|
-
L:
|
|
548
|
+
L: 268,
|
|
678
549
|
S: void 0,
|
|
679
550
|
C: (f, a) => f(...a)
|
|
680
551
|
});
|
|
681
552
|
parsedValue = void 0;
|
|
682
553
|
}
|
|
683
|
-
const newValues = {
|
|
554
|
+
const newValues = Obj2.isObject(values) ? (setValueEchoAware(values, jsonPath, parsedValue), values) : {
|
|
684
555
|
...setValue$(values, jsonPath, parsedValue)
|
|
685
556
|
};
|
|
686
557
|
setValues(newValues);
|
|
687
558
|
const newChanged = {
|
|
688
|
-
...changed,
|
|
689
559
|
[jsonPath]: true
|
|
690
560
|
};
|
|
691
561
|
setChanged({
|
|
692
562
|
...changed,
|
|
693
|
-
|
|
563
|
+
...newChanged
|
|
694
564
|
});
|
|
695
565
|
const isValid2 = validate(newValues);
|
|
696
566
|
onValuesChanged?.(newValues, {
|
|
@@ -798,145 +668,43 @@ var useKeyHandler = (formElement, form) => {
|
|
|
798
668
|
]);
|
|
799
669
|
};
|
|
800
670
|
|
|
801
|
-
// src/hooks/useQueryRefOptions.ts
|
|
802
|
-
import { useCallback as useCallback3, useState as useState2 } from "react";
|
|
803
|
-
import { log as log2 } from "@dxos/log";
|
|
804
|
-
import { useAsyncEffect } from "@dxos/react-ui";
|
|
805
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
806
|
-
var useQueryRefOptions = ({ typename, onQueryRefOptions }) => {
|
|
807
|
-
const [options, setOptions] = useState2([]);
|
|
808
|
-
const [loading, setLoading] = useState2(false);
|
|
809
|
-
const [state, setState] = useState2({});
|
|
810
|
-
const update = useCallback3(() => setState({}), []);
|
|
811
|
-
useAsyncEffect(async () => {
|
|
812
|
-
if (!typename || !onQueryRefOptions) {
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
setLoading(true);
|
|
816
|
-
try {
|
|
817
|
-
const options2 = await onQueryRefOptions({
|
|
818
|
-
typename
|
|
819
|
-
});
|
|
820
|
-
log2("options", {
|
|
821
|
-
options: options2.length
|
|
822
|
-
}, {
|
|
823
|
-
F: __dxlog_file2,
|
|
824
|
-
L: 50,
|
|
825
|
-
S: void 0,
|
|
826
|
-
C: (f, a) => f(...a)
|
|
827
|
-
});
|
|
828
|
-
setOptions(options2.map((option) => {
|
|
829
|
-
const dxn = option.dxn.toString();
|
|
830
|
-
return {
|
|
831
|
-
id: dxn,
|
|
832
|
-
label: option.label ?? dxn,
|
|
833
|
-
hue: "neutral"
|
|
834
|
-
};
|
|
835
|
-
}));
|
|
836
|
-
} catch (error) {
|
|
837
|
-
log2.error("Failed to fetch ref options:", error, {
|
|
838
|
-
F: __dxlog_file2,
|
|
839
|
-
L: 62,
|
|
840
|
-
S: void 0,
|
|
841
|
-
C: (f, a) => f(...a)
|
|
842
|
-
});
|
|
843
|
-
setOptions([]);
|
|
844
|
-
} finally {
|
|
845
|
-
setLoading(false);
|
|
846
|
-
}
|
|
847
|
-
}, [
|
|
848
|
-
typename,
|
|
849
|
-
onQueryRefOptions,
|
|
850
|
-
state
|
|
851
|
-
]);
|
|
852
|
-
return {
|
|
853
|
-
options,
|
|
854
|
-
update,
|
|
855
|
-
loading
|
|
856
|
-
};
|
|
857
|
-
};
|
|
858
|
-
|
|
859
|
-
// src/hooks/useRefQueryOptions.ts
|
|
860
|
-
import { useCallback as useCallback4 } from "react";
|
|
861
|
-
import { Obj } from "@dxos/echo";
|
|
862
|
-
import { Filter } from "@dxos/react-client/echo";
|
|
863
|
-
import { isNonNullable } from "@dxos/util";
|
|
864
|
-
var useRefQueryOptions = ({ space }) => {
|
|
865
|
-
return useCallback4(async ({ typename }) => {
|
|
866
|
-
if (!space) {
|
|
867
|
-
return [];
|
|
868
|
-
}
|
|
869
|
-
const query = space.db.query(Filter.typename(typename));
|
|
870
|
-
const objects = await query.run();
|
|
871
|
-
return objects.map((object) => {
|
|
872
|
-
const dxn = Obj.getDXN(object);
|
|
873
|
-
if (!dxn) {
|
|
874
|
-
return void 0;
|
|
875
|
-
}
|
|
876
|
-
return {
|
|
877
|
-
dxn,
|
|
878
|
-
label: Obj.getLabel(object) ?? object?.id ?? ""
|
|
879
|
-
};
|
|
880
|
-
}).filter(isNonNullable);
|
|
881
|
-
}, [
|
|
882
|
-
space
|
|
883
|
-
]);
|
|
884
|
-
};
|
|
885
|
-
|
|
886
671
|
// src/components/Form/FormFieldComponent.tsx
|
|
887
|
-
import {
|
|
888
|
-
import
|
|
889
|
-
import {
|
|
890
|
-
import { labelSpacing } from "@dxos/react-ui-stack";
|
|
891
|
-
import { errorText, mx as mx2 } from "@dxos/react-ui-theme";
|
|
672
|
+
import React, { Component } from "react";
|
|
673
|
+
import { Icon, Input, Tooltip } from "@dxos/react-ui";
|
|
674
|
+
import { errorText } from "@dxos/ui-theme";
|
|
892
675
|
var FormFieldLabel = ({ label, error, readonly, asChild }) => {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
className: mx2("flex justify-between items-center", labelSpacing)
|
|
904
|
-
}, /* @__PURE__ */ React2.createElement(Label, labelProps, label), error && /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
|
|
905
|
-
asChild: true,
|
|
906
|
-
content: error,
|
|
907
|
-
side: "bottom"
|
|
908
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
909
|
-
icon: "ph--warning--regular",
|
|
910
|
-
size: 4,
|
|
911
|
-
classNames: errorText
|
|
912
|
-
})));
|
|
913
|
-
} finally {
|
|
914
|
-
_effect.f();
|
|
915
|
-
}
|
|
676
|
+
const Label = readonly || asChild ? "span" : Input.Label;
|
|
677
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Label, null, label), error && /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
678
|
+
asChild: true,
|
|
679
|
+
content: error,
|
|
680
|
+
side: "bottom"
|
|
681
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
682
|
+
icon: "ph--warning--regular",
|
|
683
|
+
size: 4,
|
|
684
|
+
classNames: errorText
|
|
685
|
+
})));
|
|
916
686
|
};
|
|
917
687
|
FormFieldLabel.displayName = "Form.FieldLabel";
|
|
918
688
|
var FormFieldWrapper = (props) => {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
if (layout === "static" && value3 == null) {
|
|
925
|
-
return null;
|
|
926
|
-
}
|
|
927
|
-
const str = String(value3 ?? "");
|
|
928
|
-
return /* @__PURE__ */ React2.createElement(Input2.Root, {
|
|
929
|
-
validationValence: status
|
|
930
|
-
}, layout !== "inline" && /* @__PURE__ */ React2.createElement(FormFieldLabel, {
|
|
931
|
-
error,
|
|
932
|
-
readonly,
|
|
933
|
-
label
|
|
934
|
-
}), layout === "static" ? /* @__PURE__ */ React2.createElement("p", null, str) : children ? children({
|
|
935
|
-
value: value3
|
|
936
|
-
}) : null, layout === "full" && /* @__PURE__ */ React2.createElement(Input2.DescriptionAndValidation, null, /* @__PURE__ */ React2.createElement(Input2.Validation, null, error)));
|
|
937
|
-
} finally {
|
|
938
|
-
_effect.f();
|
|
689
|
+
const { children, readonly, layout, label, getStatus, getValue } = props;
|
|
690
|
+
const { status, error } = getStatus();
|
|
691
|
+
const value3 = getValue();
|
|
692
|
+
if (layout === "static" && value3 == null) {
|
|
693
|
+
return null;
|
|
939
694
|
}
|
|
695
|
+
const str = String(value3 ?? "");
|
|
696
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
697
|
+
role: "none",
|
|
698
|
+
className: "contents"
|
|
699
|
+
}, /* @__PURE__ */ React.createElement(Input.Root, {
|
|
700
|
+
validationValence: status
|
|
701
|
+
}, layout !== "inline" && /* @__PURE__ */ React.createElement(FormFieldLabel, {
|
|
702
|
+
error,
|
|
703
|
+
readonly,
|
|
704
|
+
label
|
|
705
|
+
}), layout === "static" ? /* @__PURE__ */ React.createElement("p", null, str) : children ? children({
|
|
706
|
+
value: value3
|
|
707
|
+
}) : null, layout === "full" && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Validation, null, error))));
|
|
940
708
|
};
|
|
941
709
|
var FormFieldErrorBoundary = class extends Component {
|
|
942
710
|
static getDerivedStateFromError(error) {
|
|
@@ -954,9 +722,9 @@ var FormFieldErrorBoundary = class extends Component {
|
|
|
954
722
|
}
|
|
955
723
|
render() {
|
|
956
724
|
if (this.state.error) {
|
|
957
|
-
return /* @__PURE__ */
|
|
725
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
958
726
|
className: "flex gap-2 border border-roseFill font-mono text-sm"
|
|
959
|
-
}, /* @__PURE__ */
|
|
727
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
960
728
|
className: "bg-roseFill text-surfaceText pli-1 font-thin"
|
|
961
729
|
}, "ERROR"), String(this.props.path?.join(".")));
|
|
962
730
|
}
|
|
@@ -970,121 +738,135 @@ var FormFieldErrorBoundary = class extends Component {
|
|
|
970
738
|
};
|
|
971
739
|
|
|
972
740
|
// src/components/Form/FormFieldSet.tsx
|
|
973
|
-
import {
|
|
974
|
-
import
|
|
975
|
-
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
741
|
+
import React3, { forwardRef, useMemo as useMemo3 } from "react";
|
|
742
|
+
import { mx } from "@dxos/ui-theme";
|
|
976
743
|
import { isTruthy } from "@dxos/util";
|
|
977
744
|
|
|
978
745
|
// src/components/Form/FormField.tsx
|
|
979
|
-
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
980
746
|
import * as Match from "effect/Match";
|
|
981
747
|
import * as Option2 from "effect/Option";
|
|
982
748
|
import * as Schema from "effect/Schema";
|
|
983
749
|
import * as SchemaAST from "effect/SchemaAST";
|
|
984
750
|
import * as String2 from "effect/String";
|
|
985
|
-
import
|
|
751
|
+
import React2, { useMemo as useMemo2 } from "react";
|
|
986
752
|
import { Format as Format3 } from "@dxos/echo";
|
|
987
753
|
import { createJsonPath as createJsonPath2, findNode, getAnnotation, getDiscriminatedType, isArrayType as isArrayType2, isDiscriminatedUnion, isLiteralUnion, isNestedType } from "@dxos/effect";
|
|
988
|
-
import { useTranslation
|
|
754
|
+
import { useTranslation } from "@dxos/react-ui";
|
|
989
755
|
var FormField = (props) => {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
756
|
+
const {
|
|
757
|
+
type,
|
|
758
|
+
name,
|
|
759
|
+
path,
|
|
760
|
+
projection,
|
|
761
|
+
fieldMap,
|
|
762
|
+
fieldProvider,
|
|
763
|
+
readonly,
|
|
764
|
+
layout,
|
|
765
|
+
// RefFieldProps
|
|
766
|
+
createOptionLabel,
|
|
767
|
+
createOptionIcon,
|
|
768
|
+
createInitialValuePath,
|
|
769
|
+
db,
|
|
770
|
+
schemaHook,
|
|
771
|
+
getOptions: getRefOptions,
|
|
772
|
+
onCreate
|
|
773
|
+
} = props;
|
|
774
|
+
const { t } = useTranslation(translationKey);
|
|
775
|
+
const title = getAnnotation(SchemaAST.TitleAnnotationId)(type);
|
|
776
|
+
const description = getAnnotation(SchemaAST.DescriptionAnnotationId)(type);
|
|
777
|
+
const examples = getAnnotation(SchemaAST.ExamplesAnnotationId)(type);
|
|
778
|
+
const label = useMemo2(() => title ?? String2.capitalize(name), [
|
|
779
|
+
title,
|
|
780
|
+
name
|
|
781
|
+
]);
|
|
782
|
+
const placeholder = useMemo2(() => examples?.length ? `${t("example placeholder")}: ${examples[0]}` : description ?? label, [
|
|
783
|
+
examples,
|
|
784
|
+
description,
|
|
785
|
+
label
|
|
786
|
+
]);
|
|
787
|
+
const fieldState = useFormFieldState(FormField.displayName, path);
|
|
788
|
+
const fieldProps = {
|
|
789
|
+
type,
|
|
790
|
+
format: Format3.FormatAnnotation.getFromAst(type).pipe((annotation) => Option2.getOrUndefined(annotation)),
|
|
791
|
+
readonly,
|
|
792
|
+
label,
|
|
793
|
+
placeholder,
|
|
794
|
+
layout,
|
|
795
|
+
...fieldState
|
|
796
|
+
};
|
|
797
|
+
const jsonPath = createJsonPath2(path ?? []);
|
|
798
|
+
const CustomField = fieldMap?.[jsonPath];
|
|
799
|
+
if (CustomField) {
|
|
800
|
+
return /* @__PURE__ */ React2.createElement(CustomField, fieldProps);
|
|
801
|
+
}
|
|
802
|
+
const component = fieldProvider?.({
|
|
803
|
+
schema: Schema.make(type),
|
|
804
|
+
prop: name,
|
|
805
|
+
fieldProps
|
|
806
|
+
});
|
|
807
|
+
if (component) {
|
|
808
|
+
return component;
|
|
809
|
+
}
|
|
810
|
+
if (isArrayType2(type)) {
|
|
811
|
+
return /* @__PURE__ */ React2.createElement(ArrayField, {
|
|
812
|
+
fieldProps: fieldState,
|
|
1011
813
|
label,
|
|
1012
|
-
|
|
1013
|
-
layout,
|
|
1014
|
-
...fieldState
|
|
1015
|
-
};
|
|
1016
|
-
const jsonPath = createJsonPath2(path ?? []);
|
|
1017
|
-
const CustomField = fieldMap?.[jsonPath];
|
|
1018
|
-
if (CustomField) {
|
|
1019
|
-
return /* @__PURE__ */ React3.createElement(CustomField, fieldProps);
|
|
1020
|
-
}
|
|
1021
|
-
const component = fieldProvider?.({
|
|
1022
|
-
schema: Schema.make(type),
|
|
1023
|
-
prop: name,
|
|
1024
|
-
fieldProps
|
|
814
|
+
...props
|
|
1025
815
|
});
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
816
|
+
}
|
|
817
|
+
const Field = getFormField(fieldProps);
|
|
818
|
+
if (Field) {
|
|
819
|
+
return /* @__PURE__ */ React2.createElement(Field, fieldProps);
|
|
820
|
+
}
|
|
821
|
+
const options = getOptions(type);
|
|
822
|
+
if (options) {
|
|
823
|
+
return /* @__PURE__ */ React2.createElement(SelectField, {
|
|
824
|
+
...fieldProps,
|
|
825
|
+
options: options.map((option) => ({
|
|
826
|
+
value: option,
|
|
827
|
+
label: option.toString()
|
|
828
|
+
}))
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
const refProps = getRefProps(type);
|
|
832
|
+
if (refProps) {
|
|
833
|
+
return /* @__PURE__ */ React2.createElement(RefField, {
|
|
834
|
+
...fieldProps,
|
|
835
|
+
...refProps,
|
|
836
|
+
createOptionLabel,
|
|
837
|
+
createOptionIcon,
|
|
838
|
+
createInitialValuePath,
|
|
839
|
+
db,
|
|
840
|
+
schemaHook,
|
|
841
|
+
getOptions: getRefOptions,
|
|
842
|
+
onCreate
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
if (isNestedType(type)) {
|
|
846
|
+
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
847
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST.isTypeLiteral);
|
|
848
|
+
if (typeLiteral) {
|
|
849
|
+
const schema = Schema.make(typeLiteral);
|
|
850
|
+
return /* @__PURE__ */ React2.createElement(FormFieldSet, {
|
|
851
|
+
schema,
|
|
852
|
+
path,
|
|
853
|
+
readonly,
|
|
854
|
+
layout,
|
|
1032
855
|
label,
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
const Field = getFormField(fieldProps);
|
|
1037
|
-
if (Field) {
|
|
1038
|
-
return /* @__PURE__ */ React3.createElement(Field, fieldProps);
|
|
1039
|
-
}
|
|
1040
|
-
const options = getOptions(type);
|
|
1041
|
-
if (options) {
|
|
1042
|
-
return /* @__PURE__ */ React3.createElement(SelectField, {
|
|
1043
|
-
...fieldProps,
|
|
1044
|
-
options: options.map((option) => ({
|
|
1045
|
-
value: option,
|
|
1046
|
-
label: option.toString()
|
|
1047
|
-
}))
|
|
1048
|
-
});
|
|
1049
|
-
}
|
|
1050
|
-
const refProps = getRefProps(type);
|
|
1051
|
-
if (refProps) {
|
|
1052
|
-
return /* @__PURE__ */ React3.createElement(RefField, {
|
|
1053
|
-
...fieldProps,
|
|
1054
|
-
...refProps,
|
|
1055
|
-
createSchema,
|
|
856
|
+
projection,
|
|
857
|
+
fieldMap,
|
|
858
|
+
fieldProvider,
|
|
1056
859
|
createOptionLabel,
|
|
1057
860
|
createOptionIcon,
|
|
1058
861
|
createInitialValuePath,
|
|
1059
|
-
|
|
1060
|
-
|
|
862
|
+
db,
|
|
863
|
+
schemaHook,
|
|
864
|
+
getOptions: getRefOptions,
|
|
865
|
+
onCreate
|
|
1061
866
|
});
|
|
1062
867
|
}
|
|
1063
|
-
if (isNestedType(type)) {
|
|
1064
|
-
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
1065
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST.isTypeLiteral);
|
|
1066
|
-
if (typeLiteral) {
|
|
1067
|
-
const schema = Schema.make(typeLiteral);
|
|
1068
|
-
return /* @__PURE__ */ React3.createElement(FormFieldSet, {
|
|
1069
|
-
schema,
|
|
1070
|
-
path,
|
|
1071
|
-
readonly,
|
|
1072
|
-
layout,
|
|
1073
|
-
label,
|
|
1074
|
-
projection,
|
|
1075
|
-
fieldMap,
|
|
1076
|
-
fieldProvider,
|
|
1077
|
-
createOptionLabel,
|
|
1078
|
-
createOptionIcon,
|
|
1079
|
-
onCreate,
|
|
1080
|
-
onQueryRefOptions
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
return null;
|
|
1085
|
-
} finally {
|
|
1086
|
-
_effect.f();
|
|
1087
868
|
}
|
|
869
|
+
return null;
|
|
1088
870
|
};
|
|
1089
871
|
FormField.displayName = "Form.FormField";
|
|
1090
872
|
var getFormField = ({ type, format }) => {
|
|
@@ -1111,85 +893,90 @@ var getOptions = (ast) => {
|
|
|
1111
893
|
};
|
|
1112
894
|
|
|
1113
895
|
// src/components/Form/FormFieldSet.tsx
|
|
896
|
+
var FORM_FIELDSET_NAME = "Form.FieldSet";
|
|
1114
897
|
var FormFieldSet = /* @__PURE__ */ forwardRef(({ classNames, label, schema, readonly, path, exclude, sort, projection, layout, ...props }, forwardRef4) => {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (prop) {
|
|
1132
|
-
orderedProps.push(prop);
|
|
1133
|
-
}
|
|
898
|
+
const values = useFormValues(FORM_FIELDSET_NAME, path);
|
|
899
|
+
const properties = useMemo3(() => {
|
|
900
|
+
if (!schema) {
|
|
901
|
+
return [];
|
|
902
|
+
}
|
|
903
|
+
const props2 = getFormProperties(schema.ast);
|
|
904
|
+
if (projection) {
|
|
905
|
+
const fieldProjections = projection.getFieldProjections();
|
|
906
|
+
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
907
|
+
const visibleProps = props2.filter((prop) => !hiddenProperties.has(prop.name.toString()));
|
|
908
|
+
const orderedProps = [];
|
|
909
|
+
for (const fieldProjection of fieldProjections) {
|
|
910
|
+
const fieldPath = String(fieldProjection.field.path);
|
|
911
|
+
const prop = visibleProps.find((p) => p.name === fieldPath);
|
|
912
|
+
if (prop) {
|
|
913
|
+
orderedProps.push(prop);
|
|
1134
914
|
}
|
|
1135
|
-
const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
|
|
1136
|
-
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
1137
|
-
orderedProps.push(...remainingProps);
|
|
1138
|
-
return orderedProps;
|
|
1139
915
|
}
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}, layout !== "inline" && label && /* @__PURE__ */ React4.createElement(FormFieldLabel, {
|
|
1157
|
-
label,
|
|
1158
|
-
asChild: true
|
|
1159
|
-
}), properties.map((property) => {
|
|
1160
|
-
const name = property.name.toString();
|
|
1161
|
-
return /* @__PURE__ */ React4.createElement(FormFieldErrorBoundary, {
|
|
1162
|
-
key: name,
|
|
1163
|
-
path: [
|
|
1164
|
-
...path ?? [],
|
|
1165
|
-
name
|
|
1166
|
-
]
|
|
1167
|
-
}, /* @__PURE__ */ React4.createElement(FormField, {
|
|
1168
|
-
type: property.type,
|
|
1169
|
-
name,
|
|
1170
|
-
path: [
|
|
1171
|
-
...path ?? [],
|
|
1172
|
-
name
|
|
1173
|
-
],
|
|
1174
|
-
readonly,
|
|
1175
|
-
layout,
|
|
1176
|
-
projection,
|
|
1177
|
-
...props
|
|
1178
|
-
}));
|
|
1179
|
-
}).filter(isTruthy));
|
|
1180
|
-
} finally {
|
|
1181
|
-
_effect.f();
|
|
916
|
+
const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
|
|
917
|
+
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
918
|
+
orderedProps.push(...remainingProps);
|
|
919
|
+
return orderedProps;
|
|
920
|
+
}
|
|
921
|
+
const filtered = exclude ? exclude(props2) : props2;
|
|
922
|
+
return sort ? filtered.sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString())) : filtered;
|
|
923
|
+
}, [
|
|
924
|
+
schema,
|
|
925
|
+
values,
|
|
926
|
+
exclude,
|
|
927
|
+
sort,
|
|
928
|
+
projection?.fields
|
|
929
|
+
]);
|
|
930
|
+
if ((readonly || layout === "static") && values == null) {
|
|
931
|
+
return null;
|
|
1182
932
|
}
|
|
933
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
934
|
+
role: "form",
|
|
935
|
+
className: mx("is-full", layout === "inline" && "flex flex-col gap-2", classNames),
|
|
936
|
+
ref: forwardRef4
|
|
937
|
+
}, layout !== "inline" && label && /* @__PURE__ */ React3.createElement(FormFieldLabel, {
|
|
938
|
+
label,
|
|
939
|
+
asChild: true
|
|
940
|
+
}), properties.map((property) => {
|
|
941
|
+
const name = property.name.toString();
|
|
942
|
+
return /* @__PURE__ */ React3.createElement(FormFieldErrorBoundary, {
|
|
943
|
+
key: name,
|
|
944
|
+
path: [
|
|
945
|
+
...path ?? [],
|
|
946
|
+
name
|
|
947
|
+
]
|
|
948
|
+
}, /* @__PURE__ */ React3.createElement(FormField, {
|
|
949
|
+
type: property.type,
|
|
950
|
+
name,
|
|
951
|
+
path: [
|
|
952
|
+
...path ?? [],
|
|
953
|
+
name
|
|
954
|
+
],
|
|
955
|
+
readonly,
|
|
956
|
+
layout,
|
|
957
|
+
projection,
|
|
958
|
+
...props
|
|
959
|
+
}));
|
|
960
|
+
}).filter(isTruthy));
|
|
1183
961
|
});
|
|
1184
|
-
FormFieldSet.displayName =
|
|
962
|
+
FormFieldSet.displayName = FORM_FIELDSET_NAME;
|
|
1185
963
|
|
|
1186
964
|
// src/components/Form/Form.tsx
|
|
1187
965
|
var omitId = (schema) => schema.pipe(Schema2.omit("id"));
|
|
1188
966
|
var [FormContextProvider, useFormContext] = createContext("Form");
|
|
1189
|
-
var useFormValues = (componentName, path = []) => {
|
|
967
|
+
var useFormValues = (componentName, path = [], defaultValue) => {
|
|
1190
968
|
const jsonPath = createJsonPath3(path);
|
|
1191
969
|
const { form: { values } } = useFormContext(componentName);
|
|
1192
|
-
|
|
970
|
+
const value3 = getValue$2(values, jsonPath);
|
|
971
|
+
useEffect3(() => {
|
|
972
|
+
if (!value3 && defaultValue) {
|
|
973
|
+
setValueEchoAware(values, jsonPath, defaultValue());
|
|
974
|
+
}
|
|
975
|
+
}, [
|
|
976
|
+
value3,
|
|
977
|
+
defaultValue
|
|
978
|
+
]);
|
|
979
|
+
return value3;
|
|
1193
980
|
};
|
|
1194
981
|
var useFormFieldState = (componentName, path = []) => {
|
|
1195
982
|
const stablePath = useMemo4(() => path, [
|
|
@@ -1210,129 +997,99 @@ var useFormFieldState = (componentName, path = []) => {
|
|
|
1210
997
|
]);
|
|
1211
998
|
};
|
|
1212
999
|
var FormRoot = ({ children, schema, values, onSave, onCancel, ...props }) => {
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
...props
|
|
1225
|
-
}, children);
|
|
1226
|
-
} finally {
|
|
1227
|
-
_effect.f();
|
|
1228
|
-
}
|
|
1000
|
+
const form = useFormHandler({
|
|
1001
|
+
schema,
|
|
1002
|
+
values,
|
|
1003
|
+
onSave,
|
|
1004
|
+
onCancel,
|
|
1005
|
+
...props
|
|
1006
|
+
});
|
|
1007
|
+
return /* @__PURE__ */ React4.createElement(FormContextProvider, {
|
|
1008
|
+
form,
|
|
1009
|
+
...props
|
|
1010
|
+
}, children);
|
|
1229
1011
|
};
|
|
1230
1012
|
FormRoot.displayName = "Form.Root";
|
|
1231
|
-
var
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
"plb-cardSpacingBlock",
|
|
1237
|
-
classNames
|
|
1238
|
-
]
|
|
1239
|
-
}, children), /* @__PURE__ */ React5.createElement(ScrollArea.Scrollbar, {
|
|
1240
|
-
orientation: "vertical"
|
|
1241
|
-
}, /* @__PURE__ */ React5.createElement(ScrollArea.Thumb, null)));
|
|
1242
|
-
} finally {
|
|
1243
|
-
_effect.f();
|
|
1244
|
-
}
|
|
1013
|
+
var FORM_VIEWPORT_NAME = "Form.Viewport";
|
|
1014
|
+
var FormViewport = ({ children }) => {
|
|
1015
|
+
return /* @__PURE__ */ React4.createElement(ScrollArea.Root, {
|
|
1016
|
+
orientation: "vertical"
|
|
1017
|
+
}, /* @__PURE__ */ React4.createElement(ScrollArea.Viewport, null, children));
|
|
1245
1018
|
};
|
|
1246
|
-
FormViewport.displayName =
|
|
1019
|
+
FormViewport.displayName = FORM_VIEWPORT_NAME;
|
|
1020
|
+
var FORM_CONTENT_NAME = "Form.Content";
|
|
1247
1021
|
var FormContent = ({ classNames, children }) => {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
"data-testid": testId
|
|
1258
|
-
}, children);
|
|
1259
|
-
} finally {
|
|
1260
|
-
_effect.f();
|
|
1261
|
-
}
|
|
1022
|
+
const { form, testId } = useFormContext(FORM_CONTENT_NAME);
|
|
1023
|
+
const ref = useRef(null);
|
|
1024
|
+
useKeyHandler(ref.current, form);
|
|
1025
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1026
|
+
ref,
|
|
1027
|
+
role: "form",
|
|
1028
|
+
className: mx2("flex flex-col is-full pli-cardSpacingInline density-fine", classNames),
|
|
1029
|
+
"data-testid": testId
|
|
1030
|
+
}, children);
|
|
1262
1031
|
};
|
|
1263
|
-
FormContent.displayName =
|
|
1032
|
+
FormContent.displayName = FORM_CONTENT_NAME;
|
|
1033
|
+
var FORM_FIELDSET_NAME2 = "Form.FieldSet";
|
|
1264
1034
|
var FormFieldSet2 = ({ classNames }) => {
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
...props
|
|
1272
|
-
});
|
|
1273
|
-
} finally {
|
|
1274
|
-
_effect.f();
|
|
1275
|
-
}
|
|
1035
|
+
const { form, ...props } = useFormContext(FORM_FIELDSET_NAME2);
|
|
1036
|
+
return /* @__PURE__ */ React4.createElement(FormFieldSet, {
|
|
1037
|
+
classNames,
|
|
1038
|
+
schema: form.schema,
|
|
1039
|
+
...props
|
|
1040
|
+
});
|
|
1276
1041
|
};
|
|
1277
|
-
FormFieldSet2.displayName =
|
|
1042
|
+
FormFieldSet2.displayName = FORM_FIELDSET_NAME2;
|
|
1043
|
+
var FORM_ACTIONS_NAME = "Form.Actions";
|
|
1278
1044
|
var FormActions = ({ classNames }) => {
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
if (readonly || layout === "static") {
|
|
1284
|
-
return null;
|
|
1285
|
-
}
|
|
1286
|
-
return /* @__PURE__ */ React5.createElement("div", {
|
|
1287
|
-
role: "none",
|
|
1288
|
-
className: mx4("grid grid-flow-col auto-cols-fr gap-2 pbs-cardSpacingBlock", classNames)
|
|
1289
|
-
}, onCancel && /* @__PURE__ */ React5.createElement(IconButton, {
|
|
1290
|
-
icon: "ph--x--regular",
|
|
1291
|
-
iconEnd: true,
|
|
1292
|
-
label: t("cancel button label"),
|
|
1293
|
-
onClick: onCancel,
|
|
1294
|
-
"data-testid": "cancel-button"
|
|
1295
|
-
}), onSave && /* @__PURE__ */ React5.createElement(IconButton, {
|
|
1296
|
-
type: "submit",
|
|
1297
|
-
variant: "primary",
|
|
1298
|
-
disabled: !isValid,
|
|
1299
|
-
icon: "ph--check--regular",
|
|
1300
|
-
iconEnd: true,
|
|
1301
|
-
label: t("save button label"),
|
|
1302
|
-
onClick: onSave,
|
|
1303
|
-
"data-testid": "save-button"
|
|
1304
|
-
}));
|
|
1305
|
-
} finally {
|
|
1306
|
-
_effect.f();
|
|
1045
|
+
const { t } = useTranslation2(translationKey);
|
|
1046
|
+
const { form: { canSave, onSave, onCancel }, readonly, layout } = useFormContext(FORM_ACTIONS_NAME);
|
|
1047
|
+
if (readonly || layout === "static") {
|
|
1048
|
+
return null;
|
|
1307
1049
|
}
|
|
1050
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1051
|
+
role: "none",
|
|
1052
|
+
className: mx2("grid grid-flow-col auto-cols-fr gap-2 pbs-cardSpacingBlock", classNames)
|
|
1053
|
+
}, onCancel && /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1054
|
+
icon: "ph--x--regular",
|
|
1055
|
+
iconEnd: true,
|
|
1056
|
+
label: t("cancel button label"),
|
|
1057
|
+
onClick: onCancel,
|
|
1058
|
+
"data-testid": "cancel-button"
|
|
1059
|
+
}), onSave && /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1060
|
+
type: "submit",
|
|
1061
|
+
variant: "primary",
|
|
1062
|
+
disabled: !canSave,
|
|
1063
|
+
icon: "ph--check--regular",
|
|
1064
|
+
iconEnd: true,
|
|
1065
|
+
label: t("save button label"),
|
|
1066
|
+
onClick: onSave,
|
|
1067
|
+
"data-testid": "save-button"
|
|
1068
|
+
}));
|
|
1308
1069
|
};
|
|
1309
|
-
FormActions.displayName =
|
|
1310
|
-
var
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
return null;
|
|
1317
|
-
}
|
|
1318
|
-
return /* @__PURE__ */ React5.createElement("div", {
|
|
1319
|
-
role: "none",
|
|
1320
|
-
className: mx4("flex is-full pbs-cardSpacingBlock", classNames)
|
|
1321
|
-
}, /* @__PURE__ */ React5.createElement(IconButton, {
|
|
1322
|
-
classNames: "is-full",
|
|
1323
|
-
type: "submit",
|
|
1324
|
-
variant: "primary",
|
|
1325
|
-
disabled: !isValid,
|
|
1326
|
-
icon: icon ?? "ph--check--regular",
|
|
1327
|
-
label: label ?? t("save button label"),
|
|
1328
|
-
onClick: onSave,
|
|
1329
|
-
"data-testid": "save-button"
|
|
1330
|
-
}));
|
|
1331
|
-
} finally {
|
|
1332
|
-
_effect.f();
|
|
1070
|
+
FormActions.displayName = FORM_ACTIONS_NAME;
|
|
1071
|
+
var FORM_SUBMIT_NAME = "Form.Submit";
|
|
1072
|
+
var FormSubmit = ({ classNames, label, icon, disabled }) => {
|
|
1073
|
+
const { t } = useTranslation2(translationKey);
|
|
1074
|
+
const { form: { canSave, onSave }, readonly, layout } = useFormContext(FORM_SUBMIT_NAME);
|
|
1075
|
+
if (readonly || layout === "static") {
|
|
1076
|
+
return null;
|
|
1333
1077
|
}
|
|
1078
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1079
|
+
role: "none",
|
|
1080
|
+
className: mx2("flex is-full pbs-cardSpacingBlock", classNames)
|
|
1081
|
+
}, /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1082
|
+
classNames: "is-full",
|
|
1083
|
+
type: "submit",
|
|
1084
|
+
variant: "primary",
|
|
1085
|
+
disabled: disabled ?? !canSave,
|
|
1086
|
+
icon: icon ?? "ph--check--regular",
|
|
1087
|
+
label: label ?? t("save button label"),
|
|
1088
|
+
onClick: onSave,
|
|
1089
|
+
"data-testid": "save-button"
|
|
1090
|
+
}));
|
|
1334
1091
|
};
|
|
1335
|
-
FormSubmit.displayName =
|
|
1092
|
+
FormSubmit.displayName = FORM_SUBMIT_NAME;
|
|
1336
1093
|
var Form = {
|
|
1337
1094
|
Root: FormRoot,
|
|
1338
1095
|
Viewport: FormViewport,
|
|
@@ -1344,103 +1101,88 @@ var Form = {
|
|
|
1344
1101
|
};
|
|
1345
1102
|
|
|
1346
1103
|
// src/components/Form/fields/ArrayField.tsx
|
|
1347
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/Form/fields/ArrayField.tsx";
|
|
1348
1104
|
var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps, ...props }) => {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
const
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
});
|
|
1364
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
1365
|
-
const baseNode = findNode2(typeNode, isDiscriminatedUnion2);
|
|
1366
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode, SchemaAST2.isTypeLiteral);
|
|
1367
|
-
if (!typeLiteral) {
|
|
1368
|
-
return {};
|
|
1369
|
-
}
|
|
1370
|
-
return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
|
|
1371
|
-
const defaultValue = SchemaAST2.getDefaultAnnotation(prop.type).pipe((annotation) => Option3.getOrUndefined(annotation));
|
|
1372
|
-
return [
|
|
1373
|
-
prop.name,
|
|
1374
|
-
defaultValue
|
|
1375
|
-
];
|
|
1376
|
-
}));
|
|
1377
|
-
};
|
|
1378
|
-
const handleAdd = useCallback5(() => {
|
|
1379
|
-
const defaultValue = isNestedType2(type) && elementType ? getDefaultObjectValue(elementType) : getDefaultValue(elementType);
|
|
1380
|
-
onValueChange(type, [
|
|
1381
|
-
...values,
|
|
1105
|
+
const { t } = useTranslation3(translationKey);
|
|
1106
|
+
const elementType = getArrayElementType2(type);
|
|
1107
|
+
const { onValueChange } = inputProps;
|
|
1108
|
+
const values = useFormValues(ArrayField.displayName, path, () => []);
|
|
1109
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1110
|
+
const baseNode = findNode2(typeNode, isDiscriminatedUnion2);
|
|
1111
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode, SchemaAST2.isTypeLiteral);
|
|
1112
|
+
if (!typeLiteral) {
|
|
1113
|
+
return {};
|
|
1114
|
+
}
|
|
1115
|
+
return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
|
|
1116
|
+
const defaultValue = SchemaAST2.getDefaultAnnotation(prop.type).pipe((annotation) => Option3.getOrUndefined(annotation));
|
|
1117
|
+
return [
|
|
1118
|
+
prop.name,
|
|
1382
1119
|
defaultValue
|
|
1383
|
-
]
|
|
1384
|
-
}, [
|
|
1385
|
-
onValueChange,
|
|
1386
|
-
type,
|
|
1387
|
-
elementType,
|
|
1388
|
-
values
|
|
1389
|
-
]);
|
|
1390
|
-
const handleDelete = useCallback5((idx) => {
|
|
1391
|
-
onValueChange(type, values.filter((_, i) => i !== idx));
|
|
1392
|
-
}, [
|
|
1393
|
-
onValueChange,
|
|
1394
|
-
type,
|
|
1395
|
-
values
|
|
1396
|
-
]);
|
|
1397
|
-
if (!elementType || (readonly || layout === "static") && values.length < 1) {
|
|
1398
|
-
return null;
|
|
1399
|
-
}
|
|
1400
|
-
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, (layout !== "static" || values.length > 0) && /* @__PURE__ */ React6.createElement(FormFieldLabel, {
|
|
1401
|
-
readonly,
|
|
1402
|
-
label,
|
|
1403
|
-
asChild: true
|
|
1404
|
-
}), /* @__PURE__ */ React6.createElement("div", {
|
|
1405
|
-
role: "none",
|
|
1406
|
-
className: "flex flex-col gap-2"
|
|
1407
|
-
}, values.map((_, index) => {
|
|
1408
|
-
return /* @__PURE__ */ React6.createElement("div", {
|
|
1409
|
-
role: "none",
|
|
1410
|
-
key: index,
|
|
1411
|
-
className: "grid grid-cols-[1fr_min-content] gap-2 last:mb-3"
|
|
1412
|
-
}, /* @__PURE__ */ React6.createElement(FormField, {
|
|
1413
|
-
autoFocus: index === values.length - 1,
|
|
1414
|
-
type: elementType,
|
|
1415
|
-
path: [
|
|
1416
|
-
...path ?? [],
|
|
1417
|
-
index
|
|
1418
|
-
],
|
|
1419
|
-
readonly: readonly || layout === "static",
|
|
1420
|
-
layout: "inline",
|
|
1421
|
-
...props
|
|
1422
|
-
}), !readonly && layout !== "static" && /* @__PURE__ */ React6.createElement("div", {
|
|
1423
|
-
role: "none",
|
|
1424
|
-
className: "flex flex-col bs-full justify-end"
|
|
1425
|
-
}, /* @__PURE__ */ React6.createElement("div", {
|
|
1426
|
-
role: "none",
|
|
1427
|
-
className: "flex items-center bs-[var(--line-height)]"
|
|
1428
|
-
}, /* @__PURE__ */ React6.createElement(IconButton2, {
|
|
1429
|
-
icon: "ph--x--regular",
|
|
1430
|
-
iconOnly: true,
|
|
1431
|
-
label: t("button remove"),
|
|
1432
|
-
onClick: () => handleDelete(index),
|
|
1433
|
-
classNames: "self-center"
|
|
1434
|
-
}))));
|
|
1435
|
-
})), !readonly && layout !== "static" && /* @__PURE__ */ React6.createElement(IconButton2, {
|
|
1436
|
-
classNames: "flex is-full _mlb-cardSpacingBlock",
|
|
1437
|
-
icon: "ph--plus--regular",
|
|
1438
|
-
label: t("add field"),
|
|
1439
|
-
onClick: handleAdd
|
|
1120
|
+
];
|
|
1440
1121
|
}));
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1122
|
+
};
|
|
1123
|
+
const handleAdd = useCallback3(() => {
|
|
1124
|
+
const defaultValue = isNestedType2(type) && elementType ? getDefaultObjectValue(elementType) : getDefaultValue(elementType);
|
|
1125
|
+
values && onValueChange(type, [
|
|
1126
|
+
...values,
|
|
1127
|
+
defaultValue
|
|
1128
|
+
]);
|
|
1129
|
+
}, [
|
|
1130
|
+
onValueChange,
|
|
1131
|
+
type,
|
|
1132
|
+
elementType,
|
|
1133
|
+
values
|
|
1134
|
+
]);
|
|
1135
|
+
const handleDelete = useCallback3((idx) => {
|
|
1136
|
+
onValueChange(type, values?.filter((_, i) => i !== idx));
|
|
1137
|
+
}, [
|
|
1138
|
+
onValueChange,
|
|
1139
|
+
type,
|
|
1140
|
+
values
|
|
1141
|
+
]);
|
|
1142
|
+
if (!elementType || (readonly || layout === "static") && values && values.length < 1) {
|
|
1143
|
+
return null;
|
|
1443
1144
|
}
|
|
1145
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, (layout !== "static" || values && values.length > 0) && /* @__PURE__ */ React5.createElement(FormFieldLabel, {
|
|
1146
|
+
readonly,
|
|
1147
|
+
label,
|
|
1148
|
+
asChild: true
|
|
1149
|
+
}), /* @__PURE__ */ React5.createElement("div", {
|
|
1150
|
+
role: "none",
|
|
1151
|
+
className: "flex flex-col gap-2"
|
|
1152
|
+
}, values?.map((_, index) => {
|
|
1153
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1154
|
+
role: "none",
|
|
1155
|
+
key: index,
|
|
1156
|
+
className: "grid grid-cols-[1fr_min-content] gap-2 last:mb-3"
|
|
1157
|
+
}, /* @__PURE__ */ React5.createElement(FormField, {
|
|
1158
|
+
autoFocus: index === values.length - 1,
|
|
1159
|
+
type: elementType,
|
|
1160
|
+
path: [
|
|
1161
|
+
...path ?? [],
|
|
1162
|
+
index
|
|
1163
|
+
],
|
|
1164
|
+
readonly: readonly || layout === "static",
|
|
1165
|
+
layout: "inline",
|
|
1166
|
+
...props
|
|
1167
|
+
}), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement("div", {
|
|
1168
|
+
role: "none",
|
|
1169
|
+
className: "flex flex-col bs-full justify-end"
|
|
1170
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
1171
|
+
role: "none",
|
|
1172
|
+
className: "flex items-center bs-[var(--line-height)]"
|
|
1173
|
+
}, /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1174
|
+
icon: "ph--x--regular",
|
|
1175
|
+
iconOnly: true,
|
|
1176
|
+
label: t("button remove"),
|
|
1177
|
+
onClick: () => handleDelete(index),
|
|
1178
|
+
classNames: "self-center"
|
|
1179
|
+
}))));
|
|
1180
|
+
})), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1181
|
+
classNames: "flex is-full _mlb-cardSpacingBlock",
|
|
1182
|
+
icon: "ph--plus--regular",
|
|
1183
|
+
label: t("add field"),
|
|
1184
|
+
onClick: handleAdd
|
|
1185
|
+
}));
|
|
1444
1186
|
};
|
|
1445
1187
|
ArrayField.displayName = "Form.ArrayField";
|
|
1446
1188
|
var getDefaultValue = (ast) => {
|
|
@@ -1454,6 +1196,9 @@ var getDefaultValue = (ast) => {
|
|
|
1454
1196
|
case "BooleanKeyword": {
|
|
1455
1197
|
return false;
|
|
1456
1198
|
}
|
|
1199
|
+
case "Suspend": {
|
|
1200
|
+
return getDefaultValue(ast.f());
|
|
1201
|
+
}
|
|
1457
1202
|
default: {
|
|
1458
1203
|
if (ast && isNestedType2(ast)) {
|
|
1459
1204
|
return {};
|
|
@@ -1465,783 +1210,696 @@ var getDefaultValue = (ast) => {
|
|
|
1465
1210
|
};
|
|
1466
1211
|
|
|
1467
1212
|
// src/components/Form/fields/BooleanField.tsx
|
|
1468
|
-
import {
|
|
1469
|
-
import
|
|
1470
|
-
import { Input as Input3 } from "@dxos/react-ui";
|
|
1213
|
+
import React6, { useCallback as useCallback4 } from "react";
|
|
1214
|
+
import { Input as Input2 } from "@dxos/react-ui";
|
|
1471
1215
|
var BooleanField = ({ type, readonly, onValueChange, ...props }) => {
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
onCheckedChange: handleChange
|
|
1485
|
-
}));
|
|
1486
|
-
} finally {
|
|
1487
|
-
_effect.f();
|
|
1488
|
-
}
|
|
1216
|
+
const handleChange = useCallback4((value3) => onValueChange?.(type, value3), [
|
|
1217
|
+
type,
|
|
1218
|
+
onValueChange
|
|
1219
|
+
]);
|
|
1220
|
+
return /* @__PURE__ */ React6.createElement(FormFieldWrapper, {
|
|
1221
|
+
readonly,
|
|
1222
|
+
...props
|
|
1223
|
+
}, ({ value: value3 }) => /* @__PURE__ */ React6.createElement(Input2.Switch, {
|
|
1224
|
+
disabled: !!readonly,
|
|
1225
|
+
checked: value3,
|
|
1226
|
+
onCheckedChange: handleChange
|
|
1227
|
+
}));
|
|
1489
1228
|
};
|
|
1490
1229
|
|
|
1491
1230
|
// src/components/Form/fields/GeoPointField.tsx
|
|
1492
|
-
import {
|
|
1493
|
-
import React8, { useCallback as useCallback7, useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
1231
|
+
import React7, { useCallback as useCallback5, useEffect as useEffect4, useMemo as useMemo5, useState as useState2 } from "react";
|
|
1494
1232
|
import { GeoLocation as GeoLocation3 } from "@dxos/echo/internal";
|
|
1495
|
-
import { Input as
|
|
1233
|
+
import { Input as Input3, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
1496
1234
|
import { safeParseFloat } from "@dxos/util";
|
|
1497
1235
|
var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
const
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
if (
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
const newValue = GeoLocation3.toGeoPoint(newLocation);
|
|
1535
|
-
onValueChange(type, newValue);
|
|
1536
|
-
}
|
|
1236
|
+
const { t } = useTranslation4(translationKey);
|
|
1237
|
+
const { status, error } = getStatus();
|
|
1238
|
+
const geoPoint = useMemo5(() => getValue() ?? [
|
|
1239
|
+
0,
|
|
1240
|
+
0
|
|
1241
|
+
], [
|
|
1242
|
+
getValue
|
|
1243
|
+
]);
|
|
1244
|
+
const value3 = useMemo5(() => GeoLocation3.fromGeoPoint(geoPoint), [
|
|
1245
|
+
geoPoint
|
|
1246
|
+
]);
|
|
1247
|
+
const [longitudeText, setLongitudeText] = useState2(value3.longitude?.toString());
|
|
1248
|
+
const [latitudeText, setLatitudeText] = useState2(value3.latitude?.toString());
|
|
1249
|
+
useEffect4(() => {
|
|
1250
|
+
const location = GeoLocation3.fromGeoPoint(geoPoint);
|
|
1251
|
+
setLongitudeText(location.longitude?.toString());
|
|
1252
|
+
setLatitudeText(location.latitude?.toString());
|
|
1253
|
+
}, [
|
|
1254
|
+
geoPoint
|
|
1255
|
+
]);
|
|
1256
|
+
const handleChange = useCallback5((coordinateType, setText) => (event) => {
|
|
1257
|
+
const inputText = event.target.value;
|
|
1258
|
+
setText(inputText);
|
|
1259
|
+
if (inputText !== "" && inputText !== "-") {
|
|
1260
|
+
const coord = safeParseFloat(inputText);
|
|
1261
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
1262
|
+
const currentLocation = GeoLocation3.fromGeoPoint(getValue() ?? [
|
|
1263
|
+
0,
|
|
1264
|
+
0
|
|
1265
|
+
]);
|
|
1266
|
+
const newLocation = {
|
|
1267
|
+
...currentLocation,
|
|
1268
|
+
[coordinateType]: coord
|
|
1269
|
+
};
|
|
1270
|
+
const newValue = GeoLocation3.toGeoPoint(newLocation);
|
|
1271
|
+
onValueChange(type, newValue);
|
|
1537
1272
|
}
|
|
1538
|
-
}, [
|
|
1539
|
-
type,
|
|
1540
|
-
getValue,
|
|
1541
|
-
onValueChange
|
|
1542
|
-
]);
|
|
1543
|
-
if ((readonly || layout === "static") && !value3?.latitude && !value3?.longitude) {
|
|
1544
|
-
return null;
|
|
1545
1273
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
}), layout === "static" ? /* @__PURE__ */ React8.createElement(LatLng, value3) : /* @__PURE__ */ React8.createElement("div", {
|
|
1554
|
-
role: "none",
|
|
1555
|
-
className: "grid grid-cols-2 gap-2"
|
|
1556
|
-
}, /* @__PURE__ */ React8.createElement("div", null, /* @__PURE__ */ React8.createElement(Input4.Root, null, layout !== "inline" && /* @__PURE__ */ React8.createElement(Input4.Label, null, t("latitude label")), /* @__PURE__ */ React8.createElement(Input4.TextInput, {
|
|
1557
|
-
type: "number",
|
|
1558
|
-
step: "0.00001",
|
|
1559
|
-
min: "-90",
|
|
1560
|
-
max: "90",
|
|
1561
|
-
disabled: !!readonly,
|
|
1562
|
-
placeholder: t("latitude placeholder"),
|
|
1563
|
-
value: latitudeText ?? "",
|
|
1564
|
-
onChange: handleChange("latitude", setLatitudeText),
|
|
1565
|
-
onBlur
|
|
1566
|
-
}))), /* @__PURE__ */ React8.createElement("div", null, /* @__PURE__ */ React8.createElement(Input4.Root, null, layout !== "inline" && /* @__PURE__ */ React8.createElement(Input4.Label, null, t("longitude label")), /* @__PURE__ */ React8.createElement(Input4.TextInput, {
|
|
1567
|
-
type: "number",
|
|
1568
|
-
step: "0.00001",
|
|
1569
|
-
min: "-180",
|
|
1570
|
-
max: "180",
|
|
1571
|
-
disabled: !!readonly,
|
|
1572
|
-
placeholder: t("longitude placeholder"),
|
|
1573
|
-
value: longitudeText ?? "",
|
|
1574
|
-
onChange: handleChange("longitude", setLongitudeText),
|
|
1575
|
-
onBlur
|
|
1576
|
-
})))));
|
|
1577
|
-
} finally {
|
|
1578
|
-
_effect.f();
|
|
1274
|
+
}, [
|
|
1275
|
+
type,
|
|
1276
|
+
getValue,
|
|
1277
|
+
onValueChange
|
|
1278
|
+
]);
|
|
1279
|
+
if ((readonly || layout === "static") && !value3?.latitude && !value3?.longitude) {
|
|
1280
|
+
return null;
|
|
1579
1281
|
}
|
|
1282
|
+
return /* @__PURE__ */ React7.createElement(Input3.Root, {
|
|
1283
|
+
validationValence: status
|
|
1284
|
+
}, layout !== "inline" && /* @__PURE__ */ React7.createElement(FormFieldLabel, {
|
|
1285
|
+
error,
|
|
1286
|
+
readonly,
|
|
1287
|
+
label,
|
|
1288
|
+
asChild: true
|
|
1289
|
+
}), layout === "static" ? /* @__PURE__ */ React7.createElement(LatLng, value3) : /* @__PURE__ */ React7.createElement("div", {
|
|
1290
|
+
role: "none",
|
|
1291
|
+
className: "grid grid-cols-2 gap-2"
|
|
1292
|
+
}, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("latitude label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1293
|
+
type: "number",
|
|
1294
|
+
step: "0.00001",
|
|
1295
|
+
min: "-90",
|
|
1296
|
+
max: "90",
|
|
1297
|
+
disabled: !!readonly,
|
|
1298
|
+
placeholder: t("latitude placeholder"),
|
|
1299
|
+
value: latitudeText ?? "",
|
|
1300
|
+
onChange: handleChange("latitude", setLatitudeText),
|
|
1301
|
+
onBlur
|
|
1302
|
+
}))), /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("longitude label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1303
|
+
type: "number",
|
|
1304
|
+
step: "0.00001",
|
|
1305
|
+
min: "-180",
|
|
1306
|
+
max: "180",
|
|
1307
|
+
disabled: !!readonly,
|
|
1308
|
+
placeholder: t("longitude placeholder"),
|
|
1309
|
+
value: longitudeText ?? "",
|
|
1310
|
+
onChange: handleChange("longitude", setLongitudeText),
|
|
1311
|
+
onBlur
|
|
1312
|
+
})))));
|
|
1580
1313
|
};
|
|
1581
1314
|
var LatLng = ({ latitude = 0, longitude = 0 }) => {
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
className: "text-subdued"
|
|
1592
|
-
}, "\xB0", lngHem)));
|
|
1593
|
-
} finally {
|
|
1594
|
-
_effect.f();
|
|
1595
|
-
}
|
|
1315
|
+
const latHem = latitude >= 0 ? "N" : "S";
|
|
1316
|
+
const lngHem = longitude >= 0 ? "E" : "W";
|
|
1317
|
+
return /* @__PURE__ */ React7.createElement("span", {
|
|
1318
|
+
className: "inline-flex items-center gap-1"
|
|
1319
|
+
}, /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(latitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
|
|
1320
|
+
className: "text-subdued"
|
|
1321
|
+
}, "\xB0", latHem)), /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(longitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
|
|
1322
|
+
className: "text-subdued"
|
|
1323
|
+
}, "\xB0", lngHem)));
|
|
1596
1324
|
};
|
|
1597
1325
|
|
|
1598
1326
|
// src/components/Form/fields/MarkdownField.tsx
|
|
1599
|
-
import {
|
|
1600
|
-
import
|
|
1601
|
-
import { Input as Input5 } from "@dxos/react-ui";
|
|
1327
|
+
import React8, { useCallback as useCallback6, useEffect as useEffect5, useRef as useRef2 } from "react";
|
|
1328
|
+
import { Input as Input4 } from "@dxos/react-ui";
|
|
1602
1329
|
var MarkdownField = ({ type, readonly, label, placeholder, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
if ((readonly || layout === "static") && !value3) {
|
|
1631
|
-
return null;
|
|
1632
|
-
}
|
|
1633
|
-
return /* @__PURE__ */ React9.createElement(Input5.Root, {
|
|
1634
|
-
validationValence: status
|
|
1635
|
-
}, layout !== "inline" && /* @__PURE__ */ React9.createElement(FormFieldLabel, {
|
|
1636
|
-
error,
|
|
1637
|
-
readonly,
|
|
1638
|
-
label
|
|
1639
|
-
}), layout === "static" ? /* @__PURE__ */ React9.createElement("p", null, value3) : /* @__PURE__ */ React9.createElement(Input5.TextArea, {
|
|
1640
|
-
ref: textareaRef,
|
|
1641
|
-
disabled: !!readonly,
|
|
1642
|
-
placeholder,
|
|
1643
|
-
value: value3 ?? "",
|
|
1644
|
-
classNames: "min-bs-auto max-bs-40 overflow-auto",
|
|
1645
|
-
onChange: handleChange,
|
|
1646
|
-
onBlur,
|
|
1647
|
-
style: {
|
|
1648
|
-
resize: "none"
|
|
1649
|
-
},
|
|
1650
|
-
spellCheck: false
|
|
1651
|
-
}), layout === "full" && /* @__PURE__ */ React9.createElement(Input5.Validation, null, error));
|
|
1652
|
-
} finally {
|
|
1653
|
-
_effect.f();
|
|
1330
|
+
const { status, error } = getStatus();
|
|
1331
|
+
const textareaRef = useRef2(null);
|
|
1332
|
+
const adjustHeight = useCallback6(() => {
|
|
1333
|
+
const textarea = textareaRef.current;
|
|
1334
|
+
if (textarea) {
|
|
1335
|
+
textarea.style.blockSize = "auto";
|
|
1336
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
1337
|
+
}
|
|
1338
|
+
}, []);
|
|
1339
|
+
useEffect5(() => {
|
|
1340
|
+
adjustHeight();
|
|
1341
|
+
}, [
|
|
1342
|
+
adjustHeight
|
|
1343
|
+
]);
|
|
1344
|
+
useEffect5(() => {
|
|
1345
|
+
adjustHeight();
|
|
1346
|
+
}, [
|
|
1347
|
+
getValue(),
|
|
1348
|
+
adjustHeight
|
|
1349
|
+
]);
|
|
1350
|
+
const handleChange = useCallback6((event) => onValueChange(type, event.target.value), [
|
|
1351
|
+
type,
|
|
1352
|
+
onValueChange
|
|
1353
|
+
]);
|
|
1354
|
+
const value3 = getValue();
|
|
1355
|
+
if ((readonly || layout === "static") && !value3) {
|
|
1356
|
+
return null;
|
|
1654
1357
|
}
|
|
1358
|
+
return /* @__PURE__ */ React8.createElement(Input4.Root, {
|
|
1359
|
+
validationValence: status
|
|
1360
|
+
}, layout !== "inline" && /* @__PURE__ */ React8.createElement(FormFieldLabel, {
|
|
1361
|
+
error,
|
|
1362
|
+
readonly,
|
|
1363
|
+
label
|
|
1364
|
+
}), layout === "static" ? /* @__PURE__ */ React8.createElement("p", null, value3) : /* @__PURE__ */ React8.createElement(Input4.TextArea, {
|
|
1365
|
+
ref: textareaRef,
|
|
1366
|
+
disabled: !!readonly,
|
|
1367
|
+
placeholder,
|
|
1368
|
+
value: value3 ?? "",
|
|
1369
|
+
classNames: "min-bs-auto max-bs-40 overflow-auto",
|
|
1370
|
+
onChange: handleChange,
|
|
1371
|
+
onBlur,
|
|
1372
|
+
style: {
|
|
1373
|
+
resize: "none"
|
|
1374
|
+
},
|
|
1375
|
+
spellCheck: false
|
|
1376
|
+
}), layout === "full" && /* @__PURE__ */ React8.createElement(Input4.Validation, null, error));
|
|
1655
1377
|
};
|
|
1656
1378
|
|
|
1657
1379
|
// src/components/Form/fields/NumberField.tsx
|
|
1658
|
-
import {
|
|
1659
|
-
import
|
|
1660
|
-
import { Input as Input6 } from "@dxos/react-ui";
|
|
1380
|
+
import React9, { useCallback as useCallback7 } from "react";
|
|
1381
|
+
import { Input as Input5 } from "@dxos/react-ui";
|
|
1661
1382
|
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
1662
1383
|
var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
onBlur
|
|
1679
|
-
}));
|
|
1680
|
-
} finally {
|
|
1681
|
-
_effect.f();
|
|
1682
|
-
}
|
|
1384
|
+
const handleChange = useCallback7((event) => onValueChange(type, safeParseFloat2(event.target.value) || 0), [
|
|
1385
|
+
type,
|
|
1386
|
+
onValueChange
|
|
1387
|
+
]);
|
|
1388
|
+
return /* @__PURE__ */ React9.createElement(FormFieldWrapper, {
|
|
1389
|
+
readonly,
|
|
1390
|
+
...props
|
|
1391
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React9.createElement(Input5.TextInput, {
|
|
1392
|
+
type: "number",
|
|
1393
|
+
disabled: !!readonly,
|
|
1394
|
+
placeholder,
|
|
1395
|
+
value: value3,
|
|
1396
|
+
onChange: handleChange,
|
|
1397
|
+
onBlur
|
|
1398
|
+
}));
|
|
1683
1399
|
};
|
|
1684
1400
|
|
|
1685
1401
|
// src/components/Form/fields/RefField.tsx
|
|
1686
|
-
import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
|
|
1687
1402
|
import "@dxos/lit-ui/dx-tag-picker.pcss";
|
|
1688
|
-
import
|
|
1689
|
-
import { Ref as Ref2 } from "@dxos/echo";
|
|
1403
|
+
import React11, { useCallback as useCallback9, useMemo as useMemo6 } from "react";
|
|
1404
|
+
import { Entity, Filter, Ref as Ref2, Type } from "@dxos/echo";
|
|
1690
1405
|
import { ReferenceAnnotationId } from "@dxos/echo/internal";
|
|
1406
|
+
import { useQuery, useSchema as useSchema$ } from "@dxos/echo-react";
|
|
1691
1407
|
import { findAnnotation } from "@dxos/effect";
|
|
1692
1408
|
import { DXN } from "@dxos/keys";
|
|
1693
1409
|
import { DxAnchor } from "@dxos/lit-ui/react";
|
|
1694
|
-
import { Button
|
|
1695
|
-
import { descriptionText, mx as
|
|
1696
|
-
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1410
|
+
import { Button, Icon as Icon2, Input as Input6, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1411
|
+
import { descriptionText, mx as mx3 } from "@dxos/ui-theme";
|
|
1697
1412
|
|
|
1698
1413
|
// src/components/ObjectPicker/ObjectPicker.tsx
|
|
1699
|
-
import {
|
|
1700
|
-
import
|
|
1701
|
-
import {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
const [searchString, setSearchString] = useState4("");
|
|
1709
|
-
const handleFormSave = useCallback10((values) => {
|
|
1710
|
-
onCreate?.(values);
|
|
1711
|
-
setShowForm(false);
|
|
1712
|
-
setSearchString("");
|
|
1713
|
-
}, [
|
|
1714
|
-
onCreate
|
|
1715
|
-
]);
|
|
1716
|
-
const handleFormCancel = useCallback10(() => {
|
|
1717
|
-
setShowForm(false);
|
|
1718
|
-
setSearchString("");
|
|
1719
|
-
}, []);
|
|
1720
|
-
const handleClick = useCallback10((event) => {
|
|
1721
|
-
if (createSchema && event.target.closest('[data-value="__create__"]')) {
|
|
1722
|
-
event.stopPropagation();
|
|
1723
|
-
event.preventDefault();
|
|
1724
|
-
setShowForm(true);
|
|
1725
|
-
}
|
|
1726
|
-
}, [
|
|
1727
|
-
createSchema
|
|
1728
|
-
]);
|
|
1729
|
-
const handleKeyDown = useCallback10((event) => {
|
|
1730
|
-
if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
|
|
1731
|
-
event.stopPropagation();
|
|
1732
|
-
event.preventDefault();
|
|
1733
|
-
setShowForm(true);
|
|
1734
|
-
}
|
|
1735
|
-
}, [
|
|
1736
|
-
createSchema
|
|
1737
|
-
]);
|
|
1738
|
-
const labelById = useMemo6(() => options.reduce((acc, option) => {
|
|
1739
|
-
acc[option.id.toLowerCase()] = option.label.toLowerCase();
|
|
1740
|
-
return acc;
|
|
1741
|
-
}, {}), [
|
|
1742
|
-
options
|
|
1743
|
-
]);
|
|
1744
|
-
return /* @__PURE__ */ React11.createElement(Combobox.Content, {
|
|
1745
|
-
...props,
|
|
1746
|
-
ref,
|
|
1747
|
-
filter: (value3, search) => value3 === "__create__" || labelById[value3]?.includes(search.toLowerCase()) ? 1 : 0,
|
|
1748
|
-
onClickCapture: handleClick,
|
|
1749
|
-
onKeyDownCapture: handleKeyDown
|
|
1750
|
-
}, showForm && createSchema ? /* @__PURE__ */ React11.createElement(Popover.Viewport, null, /* @__PURE__ */ React11.createElement(Form.Root, {
|
|
1751
|
-
testId: "create-referenced-object-form",
|
|
1752
|
-
schema: createSchema,
|
|
1753
|
-
values: createInitialValuePath ? {
|
|
1754
|
-
[createInitialValuePath]: searchString
|
|
1755
|
-
} : {},
|
|
1756
|
-
onSave: handleFormSave,
|
|
1757
|
-
onCancel: handleFormCancel
|
|
1758
|
-
}, /* @__PURE__ */ React11.createElement(Form.Viewport, null, /* @__PURE__ */ React11.createElement(Form.Content, null, /* @__PURE__ */ React11.createElement(Form.FieldSet, null), /* @__PURE__ */ React11.createElement(Form.Actions, null))))) : /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(Combobox.Input, {
|
|
1759
|
-
placeholder: t("ref field combobox input placeholder"),
|
|
1760
|
-
value: searchString,
|
|
1761
|
-
onValueChange: setSearchString,
|
|
1762
|
-
autoFocus: true
|
|
1763
|
-
}), /* @__PURE__ */ React11.createElement(Combobox.List, null, options.map((option) => /* @__PURE__ */ React11.createElement(Combobox.Item, {
|
|
1764
|
-
key: option.id,
|
|
1765
|
-
value: option.id,
|
|
1766
|
-
onSelect: () => onSelect(option.id),
|
|
1767
|
-
classNames: "flex items-center gap-2"
|
|
1768
|
-
}, /* @__PURE__ */ React11.createElement("span", {
|
|
1769
|
-
className: "grow"
|
|
1770
|
-
}, option.label), selectedIds?.includes(option.id) && /* @__PURE__ */ React11.createElement(Icon2, {
|
|
1771
|
-
icon: "ph--check--regular"
|
|
1772
|
-
}))), searchString.length > 0 && createOptionLabel && createOptionIcon && createSchema && onCreate && /* @__PURE__ */ React11.createElement(Combobox.Item, {
|
|
1773
|
-
value: "__create__",
|
|
1774
|
-
classNames: "flex items-center gap-2"
|
|
1775
|
-
}, /* @__PURE__ */ React11.createElement(Icon2, {
|
|
1776
|
-
icon: createOptionIcon
|
|
1777
|
-
}), t(createOptionLabel[0], {
|
|
1414
|
+
import React10, { forwardRef as forwardRef2, useCallback as useCallback8, useState as useState3 } from "react";
|
|
1415
|
+
import { Popover, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1416
|
+
import { Combobox, useSearchListInput, useSearchListResults } from "@dxos/react-ui-searchlist";
|
|
1417
|
+
var CreateItem = ({ createOptionLabel, createOptionIcon, onCreateItemSelect }) => {
|
|
1418
|
+
const { t } = useTranslation5(translationKey);
|
|
1419
|
+
const { query } = useSearchListInput();
|
|
1420
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1421
|
+
value: "__create__",
|
|
1422
|
+
label: t(createOptionLabel[0], {
|
|
1778
1423
|
ns: createOptionLabel[1].ns,
|
|
1779
|
-
text:
|
|
1780
|
-
})
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1424
|
+
text: query
|
|
1425
|
+
}),
|
|
1426
|
+
icon: createOptionIcon,
|
|
1427
|
+
classNames: "flex items-center gap-2",
|
|
1428
|
+
closeOnSelect: false,
|
|
1429
|
+
onSelect: () => {
|
|
1430
|
+
onCreateItemSelect(query);
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
var ObjectPickerContent = /* @__PURE__ */ forwardRef2(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, onSelect, onCreate, ...props }, ref) => {
|
|
1435
|
+
const { t } = useTranslation5(translationKey);
|
|
1436
|
+
const [showForm, setShowForm] = useState3(false);
|
|
1437
|
+
const [formInitialValue, setFormInitialValue] = useState3("");
|
|
1438
|
+
const { results, handleSearch } = useSearchListResults({
|
|
1439
|
+
items: options
|
|
1440
|
+
});
|
|
1441
|
+
const handleFormSave = useCallback8((values) => {
|
|
1442
|
+
onCreate?.(values);
|
|
1443
|
+
setShowForm(false);
|
|
1444
|
+
setFormInitialValue("");
|
|
1445
|
+
}, [
|
|
1446
|
+
onCreate
|
|
1447
|
+
]);
|
|
1448
|
+
const handleFormCancel = useCallback8(() => {
|
|
1449
|
+
setShowForm(false);
|
|
1450
|
+
setFormInitialValue("");
|
|
1451
|
+
}, []);
|
|
1452
|
+
const handleKeyDown = useCallback8((event) => {
|
|
1453
|
+
if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
|
|
1454
|
+
event.stopPropagation();
|
|
1455
|
+
event.preventDefault();
|
|
1456
|
+
const input = event.currentTarget.querySelector('input[type="text"]');
|
|
1457
|
+
const currentQuery = input?.value || "";
|
|
1458
|
+
setFormInitialValue(currentQuery);
|
|
1459
|
+
setShowForm(true);
|
|
1460
|
+
}
|
|
1461
|
+
}, [
|
|
1462
|
+
createSchema
|
|
1463
|
+
]);
|
|
1464
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Content, {
|
|
1465
|
+
...props,
|
|
1466
|
+
ref,
|
|
1467
|
+
onSearch: handleSearch,
|
|
1468
|
+
onKeyDownCapture: handleKeyDown
|
|
1469
|
+
}, showForm && createSchema ? /* @__PURE__ */ React10.createElement(Popover.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Root, {
|
|
1470
|
+
testId: "create-referenced-object-form",
|
|
1471
|
+
schema: createSchema,
|
|
1472
|
+
values: createInitialValuePath ? {
|
|
1473
|
+
[createInitialValuePath]: formInitialValue
|
|
1474
|
+
} : {},
|
|
1475
|
+
onSave: handleFormSave,
|
|
1476
|
+
onCancel: handleFormCancel
|
|
1477
|
+
}, /* @__PURE__ */ React10.createElement(Form.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Content, null, /* @__PURE__ */ React10.createElement(Form.FieldSet, null), /* @__PURE__ */ React10.createElement(Form.Actions, null))))) : /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(Combobox.Input, {
|
|
1478
|
+
placeholder: t("ref field combobox input placeholder"),
|
|
1479
|
+
autoFocus: true
|
|
1480
|
+
}), /* @__PURE__ */ React10.createElement(Combobox.List, null, results.map((option) => /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1481
|
+
key: option.id,
|
|
1482
|
+
value: option.id,
|
|
1483
|
+
label: option.label,
|
|
1484
|
+
checked: selectedIds?.includes(option.id),
|
|
1485
|
+
onSelect: () => onSelect(option.id),
|
|
1486
|
+
classNames: "flex items-center gap-2"
|
|
1487
|
+
})), createOptionLabel && createOptionIcon && createSchema && onCreate && /* @__PURE__ */ React10.createElement(CreateItem, {
|
|
1488
|
+
createOptionLabel,
|
|
1489
|
+
createOptionIcon,
|
|
1490
|
+
onCreateItemSelect: (query) => {
|
|
1491
|
+
setFormInitialValue(query);
|
|
1492
|
+
setShowForm(true);
|
|
1493
|
+
}
|
|
1494
|
+
}))), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
|
|
1784
1495
|
});
|
|
1785
1496
|
ObjectPickerContent.displayName = "ObjectPickerContent";
|
|
1786
1497
|
var ObjectPicker = {
|
|
1787
1498
|
Root: Combobox.Root,
|
|
1499
|
+
Portal: Combobox.Portal,
|
|
1788
1500
|
Trigger: Combobox.Trigger,
|
|
1789
1501
|
VirtualTrigger: Combobox.VirtualTrigger,
|
|
1790
1502
|
Content: ObjectPickerContent
|
|
1791
1503
|
};
|
|
1792
1504
|
|
|
1793
1505
|
// src/components/Form/fields/RefField.tsx
|
|
1794
|
-
var
|
|
1506
|
+
var isRefSnapshot = (val) => {
|
|
1795
1507
|
return typeof val === "object" && typeof val?.["/"] === "string";
|
|
1796
1508
|
};
|
|
1509
|
+
var defaultGetOptions = (results) => results.map((result) => {
|
|
1510
|
+
const id = Entity.getDXN(result).toString();
|
|
1511
|
+
const label = Entity.getLabel(result);
|
|
1512
|
+
return {
|
|
1513
|
+
id,
|
|
1514
|
+
label: label ?? id
|
|
1515
|
+
};
|
|
1516
|
+
});
|
|
1517
|
+
var defaultResultsHook = (db, typename) => useQuery(db, typename ? typename === Type.getTypename(Type.Obj) ? Filter.everything() : Filter.typename(typename) : Filter.nothing());
|
|
1797
1518
|
var RefField = (props) => {
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1812
|
-
const
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
return matchingOption;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
return void 0;
|
|
1822
|
-
};
|
|
1823
|
-
if (array && Array.isArray(formValue)) {
|
|
1824
|
-
return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
|
|
1825
|
-
}
|
|
1826
|
-
const option = unknownToRefOption(formValue);
|
|
1827
|
-
if (option) {
|
|
1828
|
-
return [
|
|
1829
|
-
option
|
|
1830
|
-
];
|
|
1831
|
-
}
|
|
1832
|
-
return [];
|
|
1833
|
-
}, [
|
|
1834
|
-
options,
|
|
1835
|
-
array,
|
|
1836
|
-
getValue
|
|
1837
|
-
]);
|
|
1838
|
-
const handleUpdate = useCallback11((ids) => {
|
|
1839
|
-
if (ids.length === 0) {
|
|
1840
|
-
onValueChange(type, void 0);
|
|
1841
|
-
return;
|
|
1842
|
-
}
|
|
1843
|
-
const refs = ids.map((id) => {
|
|
1844
|
-
const item = options.find((option) => option.id === id);
|
|
1845
|
-
if (item) {
|
|
1846
|
-
const dxn = DXN.parse(item.id);
|
|
1847
|
-
return Ref2.fromDXN(dxn);
|
|
1848
|
-
}
|
|
1849
|
-
return null;
|
|
1850
|
-
}).filter(isNonNullable2);
|
|
1851
|
-
if (array) {
|
|
1852
|
-
onValueChange(type, refs);
|
|
1853
|
-
} else {
|
|
1854
|
-
onValueChange(type, refs[0]);
|
|
1855
|
-
}
|
|
1856
|
-
}, [
|
|
1857
|
-
options,
|
|
1858
|
-
type,
|
|
1859
|
-
array,
|
|
1860
|
-
onValueChange
|
|
1861
|
-
]);
|
|
1862
|
-
const handleCreate = useCallback11((values) => {
|
|
1863
|
-
onCreate?.(values);
|
|
1864
|
-
updateOptions();
|
|
1865
|
-
}, [
|
|
1866
|
-
onCreate,
|
|
1867
|
-
updateOptions
|
|
1868
|
-
]);
|
|
1869
|
-
const items = handleGetValue();
|
|
1870
|
-
const selectedIds = useMemo7(() => items.map((i) => i.id), [
|
|
1871
|
-
items
|
|
1872
|
-
]);
|
|
1873
|
-
const toggleSelect = useCallback11((id) => {
|
|
1874
|
-
if (array) {
|
|
1875
|
-
const nextIds = selectedIds.includes(id) ? selectedIds.filter((x) => x !== id) : [
|
|
1876
|
-
...selectedIds,
|
|
1877
|
-
id
|
|
1878
|
-
];
|
|
1879
|
-
handleUpdate(nextIds);
|
|
1880
|
-
} else {
|
|
1881
|
-
if (selectedIds[0] === id) {
|
|
1882
|
-
handleUpdate([]);
|
|
1883
|
-
} else {
|
|
1884
|
-
handleUpdate([
|
|
1885
|
-
id
|
|
1886
|
-
]);
|
|
1519
|
+
const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, db, resultsHook: useResults = defaultResultsHook, schemaHook: useSchema = useSchema$, getOptions: getOptions2 = defaultGetOptions, onCreate, onValueChange } = props;
|
|
1520
|
+
const { t } = useTranslation6(translationKey);
|
|
1521
|
+
const { status, error } = getStatus();
|
|
1522
|
+
const typename = useMemo6(() => type ? findAnnotation(type, ReferenceAnnotationId)?.typename : void 0, [
|
|
1523
|
+
type
|
|
1524
|
+
]);
|
|
1525
|
+
const results = useResults(db, typename);
|
|
1526
|
+
const options = useMemo6(() => getOptions2(results), [
|
|
1527
|
+
results,
|
|
1528
|
+
getOptions2
|
|
1529
|
+
]);
|
|
1530
|
+
const handleGetValue = useCallback9(() => {
|
|
1531
|
+
const formValue = getValue();
|
|
1532
|
+
const unknownToRefOption = (value3) => {
|
|
1533
|
+
const isRef = Ref2.isRef(value3);
|
|
1534
|
+
if (isRef || isRefSnapshot(value3)) {
|
|
1535
|
+
const dxnString = isRef ? value3.dxn.toString() : value3["/"];
|
|
1536
|
+
const matchingOption = options.find((option) => option.id === dxnString);
|
|
1537
|
+
if (matchingOption) {
|
|
1538
|
+
return matchingOption;
|
|
1887
1539
|
}
|
|
1888
1540
|
}
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1541
|
+
return void 0;
|
|
1542
|
+
};
|
|
1543
|
+
return unknownToRefOption(formValue);
|
|
1544
|
+
}, [
|
|
1545
|
+
options,
|
|
1546
|
+
getValue
|
|
1547
|
+
]);
|
|
1548
|
+
const handleUpdate = useCallback9((id) => {
|
|
1549
|
+
const item2 = options.find((option) => option.id === id);
|
|
1550
|
+
const ref = item2 ? Ref2.fromDXN(DXN.parse(item2.id)) : void 0;
|
|
1551
|
+
onValueChange(type, ref);
|
|
1552
|
+
}, [
|
|
1553
|
+
options,
|
|
1554
|
+
type,
|
|
1555
|
+
onValueChange
|
|
1556
|
+
]);
|
|
1557
|
+
const item = handleGetValue();
|
|
1558
|
+
const selectedIds = useMemo6(() => item ? [
|
|
1559
|
+
item.id
|
|
1560
|
+
] : [], [
|
|
1561
|
+
item
|
|
1562
|
+
]);
|
|
1563
|
+
const createSchema = useSchema(db, typename);
|
|
1564
|
+
const handleCreate = useCallback9((values) => {
|
|
1565
|
+
if (createSchema && onCreate) {
|
|
1566
|
+
onCreate(createSchema, values);
|
|
1896
1567
|
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
className: "flex gap-2 is-full"
|
|
1914
|
-
}, items?.map((item) => /* @__PURE__ */ React12.createElement(Input7.Root, {
|
|
1915
|
-
key: item.id
|
|
1916
|
-
}, /* @__PURE__ */ React12.createElement(Input7.TextInput, {
|
|
1917
|
-
value: item.label,
|
|
1918
|
-
readOnly: true,
|
|
1919
|
-
classNames: "is-full"
|
|
1920
|
-
})))) : /* @__PURE__ */ React12.createElement(Button2, {
|
|
1921
|
-
classNames: "is-full text-start gap-2"
|
|
1922
|
-
}, /* @__PURE__ */ React12.createElement("div", {
|
|
1923
|
-
role: "none",
|
|
1924
|
-
className: "grow overflow-hidden"
|
|
1925
|
-
}, /* @__PURE__ */ React12.createElement("span", {
|
|
1926
|
-
className: "flex truncate text-description"
|
|
1927
|
-
}, placeholder ?? t("ref field placeholder", {
|
|
1928
|
-
count: array ? 99 : 1
|
|
1929
|
-
}))), /* @__PURE__ */ React12.createElement(Icon3, {
|
|
1930
|
-
size: 3,
|
|
1931
|
-
icon: "ph--caret-down--bold"
|
|
1932
|
-
}))), /* @__PURE__ */ React12.createElement(ObjectPicker.Content, {
|
|
1933
|
-
classNames: "popover-card-width",
|
|
1934
|
-
options,
|
|
1935
|
-
selectedIds,
|
|
1936
|
-
createSchema,
|
|
1937
|
-
createOptionLabel,
|
|
1938
|
-
createOptionIcon,
|
|
1939
|
-
createInitialValuePath,
|
|
1940
|
-
onCreate: handleCreate,
|
|
1941
|
-
onSelect: toggleSelect
|
|
1942
|
-
}))), layout === "full" && /* @__PURE__ */ React12.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1943
|
-
} finally {
|
|
1944
|
-
_effect.f();
|
|
1568
|
+
}, [
|
|
1569
|
+
createSchema,
|
|
1570
|
+
onCreate
|
|
1571
|
+
]);
|
|
1572
|
+
const handleSelect = useCallback9((id) => {
|
|
1573
|
+
if (item?.id === id) {
|
|
1574
|
+
handleUpdate(void 0);
|
|
1575
|
+
} else {
|
|
1576
|
+
handleUpdate(id);
|
|
1577
|
+
}
|
|
1578
|
+
}, [
|
|
1579
|
+
item,
|
|
1580
|
+
handleUpdate
|
|
1581
|
+
]);
|
|
1582
|
+
if (!typename || (readonly || layout === "static") && !item) {
|
|
1583
|
+
return null;
|
|
1945
1584
|
}
|
|
1585
|
+
return /* @__PURE__ */ React11.createElement(Input6.Root, {
|
|
1586
|
+
validationValence: status
|
|
1587
|
+
}, layout !== "inline" && /* @__PURE__ */ React11.createElement(FormFieldLabel, {
|
|
1588
|
+
error,
|
|
1589
|
+
readonly,
|
|
1590
|
+
label
|
|
1591
|
+
}), /* @__PURE__ */ React11.createElement("div", null, readonly ? !item ? /* @__PURE__ */ React11.createElement("p", {
|
|
1592
|
+
className: mx3(descriptionText, "mbe-2")
|
|
1593
|
+
}, t("empty readonly ref field label")) : /* @__PURE__ */ React11.createElement(DxAnchor, {
|
|
1594
|
+
key: item.id,
|
|
1595
|
+
dxn: item.id,
|
|
1596
|
+
rootclassname: "mie-1"
|
|
1597
|
+
}, item.label) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Trigger, {
|
|
1598
|
+
asChild: true,
|
|
1599
|
+
classNames: "p-0"
|
|
1600
|
+
}, item ? /* @__PURE__ */ React11.createElement("div", {
|
|
1601
|
+
className: "flex gap-2 is-full"
|
|
1602
|
+
}, /* @__PURE__ */ React11.createElement(Input6.Root, {
|
|
1603
|
+
key: item.id
|
|
1604
|
+
}, /* @__PURE__ */ React11.createElement(Input6.TextInput, {
|
|
1605
|
+
value: item.label,
|
|
1606
|
+
readOnly: true,
|
|
1607
|
+
classNames: "is-full"
|
|
1608
|
+
}))) : /* @__PURE__ */ React11.createElement(Button, {
|
|
1609
|
+
classNames: "is-full text-start gap-2"
|
|
1610
|
+
}, /* @__PURE__ */ React11.createElement("div", {
|
|
1611
|
+
role: "none",
|
|
1612
|
+
className: "grow overflow-hidden"
|
|
1613
|
+
}, /* @__PURE__ */ React11.createElement("span", {
|
|
1614
|
+
className: "flex truncate text-description"
|
|
1615
|
+
}, placeholder ?? t("ref field placeholder"))), /* @__PURE__ */ React11.createElement(Icon2, {
|
|
1616
|
+
size: 3,
|
|
1617
|
+
icon: "ph--caret-down--bold"
|
|
1618
|
+
}))), /* @__PURE__ */ React11.createElement(ObjectPicker.Portal, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Content, {
|
|
1619
|
+
classNames: "popover-card-width",
|
|
1620
|
+
options,
|
|
1621
|
+
selectedIds,
|
|
1622
|
+
createSchema: createSchema && omitId(createSchema),
|
|
1623
|
+
createOptionLabel,
|
|
1624
|
+
createOptionIcon,
|
|
1625
|
+
createInitialValuePath,
|
|
1626
|
+
onCreate: handleCreate,
|
|
1627
|
+
onSelect: handleSelect
|
|
1628
|
+
})))), layout === "full" && /* @__PURE__ */ React11.createElement(Input6.DescriptionAndValidation, null, error));
|
|
1946
1629
|
};
|
|
1947
1630
|
|
|
1948
1631
|
// src/components/Form/fields/SelectField.tsx
|
|
1949
|
-
import {
|
|
1950
|
-
import
|
|
1951
|
-
import { Input as Input8, Select } from "@dxos/react-ui";
|
|
1632
|
+
import React12, { useCallback as useCallback10 } from "react";
|
|
1633
|
+
import { Input as Input7, Select } from "@dxos/react-ui";
|
|
1952
1634
|
var SelectField = ({ type, readonly, label, layout, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
if ((readonly || layout === "static") && value3 == null) {
|
|
1962
|
-
return null;
|
|
1963
|
-
}
|
|
1964
|
-
return /* @__PURE__ */ React13.createElement(Input8.Root, {
|
|
1965
|
-
validationValence: status
|
|
1966
|
-
}, layout !== "inline" && /* @__PURE__ */ React13.createElement(FormFieldLabel, {
|
|
1967
|
-
error,
|
|
1968
|
-
readonly,
|
|
1969
|
-
label
|
|
1970
|
-
}), layout === "static" ? /* @__PURE__ */ React13.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value3)?.label ?? String(value3)) : /* @__PURE__ */ React13.createElement(Select.Root, {
|
|
1971
|
-
value: value3,
|
|
1972
|
-
onValueChange: handleValueChange
|
|
1973
|
-
}, /* @__PURE__ */ React13.createElement(Select.TriggerButton, {
|
|
1974
|
-
classNames: "is-full",
|
|
1975
|
-
disabled: !!readonly,
|
|
1976
|
-
placeholder
|
|
1977
|
-
}), /* @__PURE__ */ React13.createElement(Select.Portal, null, /* @__PURE__ */ React13.createElement(Select.Content, null, /* @__PURE__ */ React13.createElement(Select.Viewport, null, options?.map(({ value: value4, label: label2 }) => (
|
|
1978
|
-
// NOTE: Numeric values are converted to and from strings.
|
|
1979
|
-
/* @__PURE__ */ React13.createElement(Select.Option, {
|
|
1980
|
-
key: String(value4),
|
|
1981
|
-
value: String(value4)
|
|
1982
|
-
}, label2 ?? String(value4))
|
|
1983
|
-
))), /* @__PURE__ */ React13.createElement(Select.Arrow, null)))), layout === "full" && /* @__PURE__ */ React13.createElement(Input8.DescriptionAndValidation, null, error));
|
|
1984
|
-
} finally {
|
|
1985
|
-
_effect.f();
|
|
1635
|
+
const { status, error } = getStatus();
|
|
1636
|
+
const value3 = getValue();
|
|
1637
|
+
const handleValueChange = useCallback10((value4) => onValueChange(type, value4), [
|
|
1638
|
+
type,
|
|
1639
|
+
onValueChange
|
|
1640
|
+
]);
|
|
1641
|
+
if ((readonly || layout === "static") && value3 == null) {
|
|
1642
|
+
return null;
|
|
1986
1643
|
}
|
|
1644
|
+
return /* @__PURE__ */ React12.createElement(Input7.Root, {
|
|
1645
|
+
validationValence: status
|
|
1646
|
+
}, layout !== "inline" && /* @__PURE__ */ React12.createElement(FormFieldLabel, {
|
|
1647
|
+
error,
|
|
1648
|
+
readonly,
|
|
1649
|
+
label
|
|
1650
|
+
}), layout === "static" ? /* @__PURE__ */ React12.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value3)?.label ?? String(value3)) : /* @__PURE__ */ React12.createElement(Select.Root, {
|
|
1651
|
+
value: value3,
|
|
1652
|
+
onValueChange: handleValueChange
|
|
1653
|
+
}, /* @__PURE__ */ React12.createElement(Select.TriggerButton, {
|
|
1654
|
+
classNames: "is-full",
|
|
1655
|
+
disabled: !!readonly,
|
|
1656
|
+
placeholder
|
|
1657
|
+
}), /* @__PURE__ */ React12.createElement(Select.Portal, null, /* @__PURE__ */ React12.createElement(Select.Content, null, /* @__PURE__ */ React12.createElement(Select.Viewport, null, options?.map(({ value: value4, label: label2 }) => (
|
|
1658
|
+
// NOTE: Numeric values are converted to and from strings.
|
|
1659
|
+
/* @__PURE__ */ React12.createElement(Select.Option, {
|
|
1660
|
+
key: String(value4),
|
|
1661
|
+
value: String(value4)
|
|
1662
|
+
}, label2 ?? String(value4))
|
|
1663
|
+
))), /* @__PURE__ */ React12.createElement(Select.Arrow, null)))), layout === "full" && /* @__PURE__ */ React12.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1987
1664
|
};
|
|
1988
1665
|
|
|
1989
1666
|
// src/components/Form/fields/SelectOptionField.tsx
|
|
1990
|
-
import {
|
|
1991
|
-
import React14, { useCallback as useCallback13, useEffect as useEffect5, useRef as useRef3, useState as useState5 } from "react";
|
|
1667
|
+
import React13, { useCallback as useCallback11, useEffect as useEffect6, useRef as useRef3, useState as useState4 } from "react";
|
|
1992
1668
|
import { PublicKey } from "@dxos/keys";
|
|
1993
|
-
import { IconButton as IconButton3, Input as
|
|
1669
|
+
import { IconButton as IconButton3, Input as Input8, Tag, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1994
1670
|
import { List } from "@dxos/react-ui-list";
|
|
1995
1671
|
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
1996
|
-
import { hues, subtleHover } from "@dxos/
|
|
1672
|
+
import { hues, osTranslations, subtleHover } from "@dxos/ui-theme";
|
|
1997
1673
|
var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueChange }) => {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
]);
|
|
2015
|
-
const
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
1674
|
+
const { t } = useTranslation7(translationKey);
|
|
1675
|
+
const { status, error } = getStatus();
|
|
1676
|
+
const [selected, setSelectedId] = useState4(null);
|
|
1677
|
+
const [isNewOption, setIsNewOption] = useState4(false);
|
|
1678
|
+
const inputRef = useRef3(null);
|
|
1679
|
+
const options = getValue();
|
|
1680
|
+
useEffect6(() => {
|
|
1681
|
+
if (options === void 0) {
|
|
1682
|
+
onValueChange(type, []);
|
|
1683
|
+
}
|
|
1684
|
+
}, [
|
|
1685
|
+
options,
|
|
1686
|
+
type,
|
|
1687
|
+
onValueChange
|
|
1688
|
+
]);
|
|
1689
|
+
const randomHue = () => {
|
|
1690
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
1691
|
+
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
1692
|
+
if (unusedHues.length > 0) {
|
|
1693
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
1694
|
+
}
|
|
1695
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
1696
|
+
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
1697
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
|
|
1698
|
+
};
|
|
1699
|
+
const handleAdd = useCallback11(() => {
|
|
1700
|
+
const newId = PublicKey.random().truncate();
|
|
1701
|
+
const newOption = {
|
|
1702
|
+
id: newId,
|
|
1703
|
+
title: "",
|
|
1704
|
+
color: randomHue()
|
|
2024
1705
|
};
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
id: newId,
|
|
2029
|
-
title: "",
|
|
2030
|
-
color: randomHue()
|
|
2031
|
-
};
|
|
2032
|
-
onValueChange(type, [
|
|
2033
|
-
...options ?? [],
|
|
2034
|
-
newOption
|
|
2035
|
-
]);
|
|
2036
|
-
setSelectedId(newId);
|
|
2037
|
-
setIsNewOption(true);
|
|
2038
|
-
}, [
|
|
2039
|
-
options,
|
|
2040
|
-
type,
|
|
2041
|
-
onValueChange
|
|
1706
|
+
onValueChange(type, [
|
|
1707
|
+
...options ?? [],
|
|
1708
|
+
newOption
|
|
2042
1709
|
]);
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
1710
|
+
setSelectedId(newId);
|
|
1711
|
+
setIsNewOption(true);
|
|
1712
|
+
}, [
|
|
1713
|
+
options,
|
|
1714
|
+
type,
|
|
1715
|
+
onValueChange
|
|
1716
|
+
]);
|
|
1717
|
+
const handleDelete = useCallback11((id) => {
|
|
1718
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
1719
|
+
onValueChange(type, newOptions);
|
|
1720
|
+
setSelectedId(null);
|
|
1721
|
+
}, [
|
|
1722
|
+
options,
|
|
1723
|
+
type,
|
|
1724
|
+
onValueChange
|
|
1725
|
+
]);
|
|
1726
|
+
const handleMove = useCallback11((from, to) => {
|
|
1727
|
+
if (!options) {
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
const newOptions = [
|
|
1731
|
+
...options
|
|
1732
|
+
];
|
|
1733
|
+
const [removed] = newOptions.splice(from, 1);
|
|
1734
|
+
newOptions.splice(to, 0, removed);
|
|
1735
|
+
onValueChange(type, newOptions);
|
|
1736
|
+
}, [
|
|
1737
|
+
options,
|
|
1738
|
+
type,
|
|
1739
|
+
onValueChange
|
|
1740
|
+
]);
|
|
1741
|
+
const handleClick = useCallback11((id) => {
|
|
1742
|
+
setSelectedId((current) => current === id ? null : id);
|
|
1743
|
+
}, []);
|
|
1744
|
+
const handleTitleChange = useCallback11((id) => (e) => {
|
|
1745
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
1746
|
+
...o,
|
|
1747
|
+
title: e.target.value
|
|
1748
|
+
} : o);
|
|
1749
|
+
onValueChange(type, newOptions ?? []);
|
|
1750
|
+
}, [
|
|
1751
|
+
options,
|
|
1752
|
+
type,
|
|
1753
|
+
onValueChange
|
|
1754
|
+
]);
|
|
1755
|
+
const handleKeyDown = useCallback11((ev) => {
|
|
1756
|
+
if (ev.key === "Enter") {
|
|
2046
1757
|
setSelectedId(null);
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
label: t(selected === item.id ? "collapse label" : "expand label", {
|
|
2145
|
-
ns: "os"
|
|
2146
|
-
}),
|
|
2147
|
-
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2148
|
-
onClick: () => handleClick(item.id)
|
|
2149
|
-
})), selected === item.id && /* @__PURE__ */ React14.createElement("div", {
|
|
2150
|
-
className: "pli-cardSpacingInline plb-cardSpacingBlock flex flex-col gap-1 density-fine"
|
|
2151
|
-
}, /* @__PURE__ */ React14.createElement(Input9.Label, {
|
|
2152
|
-
classNames: "text-xs"
|
|
2153
|
-
}, t("select option label")), /* @__PURE__ */ React14.createElement("div", {
|
|
2154
|
-
className: "grid grid-cols-[1fr_min-content_min-content] gap-1"
|
|
2155
|
-
}, /* @__PURE__ */ React14.createElement(Input9.TextInput, {
|
|
2156
|
-
disabled: !!readonly,
|
|
2157
|
-
placeholder: t("select option label placeholder"),
|
|
2158
|
-
ref: selected === item.id ? inputRef : void 0,
|
|
2159
|
-
value: item.title,
|
|
2160
|
-
onChange: handleTitleChange(item.id),
|
|
2161
|
-
onKeyDown: handleKeyDown,
|
|
2162
|
-
classNames: "flex-1"
|
|
2163
|
-
}), /* @__PURE__ */ React14.createElement(HuePicker, {
|
|
2164
|
-
disabled: !!readonly,
|
|
2165
|
-
value: item.color,
|
|
2166
|
-
onChange: handleColorChange(item.id)
|
|
2167
|
-
}), /* @__PURE__ */ React14.createElement(IconButton3, {
|
|
2168
|
-
disabled: !!readonly,
|
|
2169
|
-
icon: "ph--trash--fill",
|
|
2170
|
-
iconOnly: true,
|
|
2171
|
-
label: t("select option delete"),
|
|
2172
|
-
onClick: () => handleDelete(item.id)
|
|
2173
|
-
})))))), /* @__PURE__ */ React14.createElement(IconButton3, {
|
|
2174
|
-
variant: "ghost",
|
|
2175
|
-
icon: "ph--plus--regular",
|
|
2176
|
-
label: t("select option add"),
|
|
2177
|
-
onClick: handleAdd,
|
|
2178
|
-
disabled: !!readonly,
|
|
2179
|
-
classNames: "is-full"
|
|
2180
|
-
})))));
|
|
2181
|
-
} finally {
|
|
2182
|
-
_effect.f();
|
|
2183
|
-
}
|
|
1758
|
+
}
|
|
1759
|
+
}, []);
|
|
1760
|
+
const handleColorChange = useCallback11((id) => (hue) => {
|
|
1761
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
1762
|
+
...o,
|
|
1763
|
+
color: hue
|
|
1764
|
+
} : o);
|
|
1765
|
+
onValueChange(type, newOptions ?? []);
|
|
1766
|
+
}, [
|
|
1767
|
+
options,
|
|
1768
|
+
type,
|
|
1769
|
+
onValueChange
|
|
1770
|
+
]);
|
|
1771
|
+
useEffect6(() => {
|
|
1772
|
+
if (selected && isNewOption && inputRef.current) {
|
|
1773
|
+
inputRef.current.focus();
|
|
1774
|
+
setIsNewOption(false);
|
|
1775
|
+
}
|
|
1776
|
+
}, [
|
|
1777
|
+
selected,
|
|
1778
|
+
isNewOption
|
|
1779
|
+
]);
|
|
1780
|
+
return /* @__PURE__ */ React13.createElement(Input8.Root, {
|
|
1781
|
+
validationValence: status
|
|
1782
|
+
}, /* @__PURE__ */ React13.createElement(FormFieldLabel, {
|
|
1783
|
+
error,
|
|
1784
|
+
readonly,
|
|
1785
|
+
label
|
|
1786
|
+
}), /* @__PURE__ */ React13.createElement("div", {
|
|
1787
|
+
role: "none"
|
|
1788
|
+
}, options && /* @__PURE__ */ React13.createElement(List.Root, {
|
|
1789
|
+
items: options,
|
|
1790
|
+
isItem: (_item) => true,
|
|
1791
|
+
onMove: readonly ? void 0 : handleMove,
|
|
1792
|
+
readonly: !!readonly
|
|
1793
|
+
}, ({ items }) => /* @__PURE__ */ React13.createElement("div", {
|
|
1794
|
+
role: "list",
|
|
1795
|
+
className: "is-full overflow-auto"
|
|
1796
|
+
}, items?.map((item) => /* @__PURE__ */ React13.createElement("div", {
|
|
1797
|
+
key: item.id
|
|
1798
|
+
}, /* @__PURE__ */ React13.createElement(List.Item, {
|
|
1799
|
+
role: "button",
|
|
1800
|
+
item,
|
|
1801
|
+
classNames: [
|
|
1802
|
+
subtleHover,
|
|
1803
|
+
"flex flex-col cursor-pointer rounded-sm"
|
|
1804
|
+
],
|
|
1805
|
+
"aria-expanded": selected === item.id
|
|
1806
|
+
}, /* @__PURE__ */ React13.createElement("div", {
|
|
1807
|
+
className: "flex items-center"
|
|
1808
|
+
}, /* @__PURE__ */ React13.createElement(List.ItemDragHandle, {
|
|
1809
|
+
disabled: !!readonly
|
|
1810
|
+
}), /* @__PURE__ */ React13.createElement(List.ItemTitle, {
|
|
1811
|
+
onClick: () => handleClick(item.id),
|
|
1812
|
+
classNames: "flex-1"
|
|
1813
|
+
}, /* @__PURE__ */ React13.createElement(Tag, {
|
|
1814
|
+
palette: item.color
|
|
1815
|
+
}, item.title || "\u200B")), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1816
|
+
iconOnly: true,
|
|
1817
|
+
variant: "ghost",
|
|
1818
|
+
label: t(selected === item.id ? "collapse label" : "expand label", {
|
|
1819
|
+
ns: osTranslations
|
|
1820
|
+
}),
|
|
1821
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
1822
|
+
onClick: () => handleClick(item.id)
|
|
1823
|
+
})), selected === item.id && /* @__PURE__ */ React13.createElement("div", {
|
|
1824
|
+
className: "pli-cardSpacingInline plb-cardSpacingBlock flex flex-col gap-1 density-fine"
|
|
1825
|
+
}, /* @__PURE__ */ React13.createElement(Input8.Label, {
|
|
1826
|
+
classNames: "text-xs"
|
|
1827
|
+
}, t("select option label")), /* @__PURE__ */ React13.createElement("div", {
|
|
1828
|
+
className: "grid grid-cols-[1fr_min-content_min-content] gap-1"
|
|
1829
|
+
}, /* @__PURE__ */ React13.createElement(Input8.TextInput, {
|
|
1830
|
+
disabled: !!readonly,
|
|
1831
|
+
placeholder: t("select option label placeholder"),
|
|
1832
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
1833
|
+
value: item.title,
|
|
1834
|
+
onChange: handleTitleChange(item.id),
|
|
1835
|
+
onKeyDown: handleKeyDown,
|
|
1836
|
+
classNames: "flex-1"
|
|
1837
|
+
}), /* @__PURE__ */ React13.createElement(HuePicker, {
|
|
1838
|
+
disabled: !!readonly,
|
|
1839
|
+
value: item.color,
|
|
1840
|
+
onChange: handleColorChange(item.id)
|
|
1841
|
+
}), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1842
|
+
disabled: !!readonly,
|
|
1843
|
+
icon: "ph--trash--fill",
|
|
1844
|
+
iconOnly: true,
|
|
1845
|
+
label: t("select option delete"),
|
|
1846
|
+
onClick: () => handleDelete(item.id)
|
|
1847
|
+
})))))), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1848
|
+
variant: "ghost",
|
|
1849
|
+
icon: "ph--plus--regular",
|
|
1850
|
+
label: t("select option add"),
|
|
1851
|
+
onClick: handleAdd,
|
|
1852
|
+
disabled: !!readonly,
|
|
1853
|
+
classNames: "is-full"
|
|
1854
|
+
})))));
|
|
2184
1855
|
};
|
|
2185
1856
|
|
|
2186
1857
|
// src/components/Form/fields/TextField.tsx
|
|
2187
|
-
import {
|
|
2188
|
-
import
|
|
2189
|
-
import { Input as Input10 } from "@dxos/react-ui";
|
|
1858
|
+
import React14, { useCallback as useCallback12 } from "react";
|
|
1859
|
+
import { Input as Input9 } from "@dxos/react-ui";
|
|
2190
1860
|
var TextField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
onBlur
|
|
2207
|
-
}));
|
|
2208
|
-
} finally {
|
|
2209
|
-
_effect.f();
|
|
2210
|
-
}
|
|
1861
|
+
const handleChange = useCallback12((event) => onValueChange(type, event.target.value), [
|
|
1862
|
+
type,
|
|
1863
|
+
onValueChange
|
|
1864
|
+
]);
|
|
1865
|
+
return /* @__PURE__ */ React14.createElement(FormFieldWrapper, {
|
|
1866
|
+
readonly,
|
|
1867
|
+
...props
|
|
1868
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React14.createElement(Input9.TextInput, {
|
|
1869
|
+
noAutoFill: true,
|
|
1870
|
+
disabled: !!readonly,
|
|
1871
|
+
placeholder,
|
|
1872
|
+
value: value3,
|
|
1873
|
+
onChange: handleChange,
|
|
1874
|
+
onBlur
|
|
1875
|
+
}));
|
|
2211
1876
|
};
|
|
2212
1877
|
|
|
2213
1878
|
// src/components/Form/fields/TextAreaField.tsx
|
|
2214
|
-
import {
|
|
2215
|
-
import
|
|
2216
|
-
import { Input as Input11 } from "@dxos/react-ui";
|
|
1879
|
+
import React15, { useCallback as useCallback13 } from "react";
|
|
1880
|
+
import { Input as Input10 } from "@dxos/react-ui";
|
|
2217
1881
|
var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
onBlur
|
|
2234
|
-
}));
|
|
2235
|
-
} finally {
|
|
2236
|
-
_effect.f();
|
|
2237
|
-
}
|
|
1882
|
+
const handleChange = useCallback13((event) => onValueChange(type, event.target.value), [
|
|
1883
|
+
type,
|
|
1884
|
+
onValueChange
|
|
1885
|
+
]);
|
|
1886
|
+
return /* @__PURE__ */ React15.createElement(FormFieldWrapper, {
|
|
1887
|
+
readonly,
|
|
1888
|
+
...props
|
|
1889
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React15.createElement(Input10.TextArea, {
|
|
1890
|
+
rows: 3,
|
|
1891
|
+
disabled: !!readonly,
|
|
1892
|
+
placeholder,
|
|
1893
|
+
value: value3,
|
|
1894
|
+
onChange: handleChange,
|
|
1895
|
+
onBlur
|
|
1896
|
+
}));
|
|
2238
1897
|
};
|
|
2239
1898
|
|
|
2240
1899
|
// src/components/Form/fields/TupleField.tsx
|
|
2241
|
-
import
|
|
2242
|
-
import
|
|
2243
|
-
import {
|
|
2244
|
-
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
1900
|
+
import React16 from "react";
|
|
1901
|
+
import { Input as Input11 } from "@dxos/react-ui";
|
|
1902
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
2245
1903
|
import { safeParseFloat as safeParseFloat3 } from "@dxos/util";
|
|
2246
1904
|
var gridCols = [
|
|
2247
1905
|
"grid-cols-1",
|
|
@@ -2250,494 +1908,631 @@ var gridCols = [
|
|
|
2250
1908
|
"grid-cols-4"
|
|
2251
1909
|
];
|
|
2252
1910
|
var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValueChange, onBlur }) => {
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
onBlur
|
|
2277
|
-
}))));
|
|
2278
|
-
} finally {
|
|
2279
|
-
_effect.f();
|
|
2280
|
-
}
|
|
1911
|
+
const { status, error } = getStatus();
|
|
1912
|
+
const values = getValue() ?? {};
|
|
1913
|
+
return /* @__PURE__ */ React16.createElement(Input11.Root, {
|
|
1914
|
+
validationValence: status
|
|
1915
|
+
}, /* @__PURE__ */ React16.createElement(FormFieldLabel, {
|
|
1916
|
+
error,
|
|
1917
|
+
readonly,
|
|
1918
|
+
label
|
|
1919
|
+
}), /* @__PURE__ */ React16.createElement("div", {
|
|
1920
|
+
className: mx4("grid gap-2", gridCols[binding.length - 1])
|
|
1921
|
+
}, binding.map((prop) => /* @__PURE__ */ React16.createElement(Input11.TextInput, {
|
|
1922
|
+
key: prop,
|
|
1923
|
+
type: "number",
|
|
1924
|
+
disabled: !!readonly,
|
|
1925
|
+
value: values[prop],
|
|
1926
|
+
onChange: (event) => {
|
|
1927
|
+
onValueChange(type, {
|
|
1928
|
+
...values,
|
|
1929
|
+
[prop]: safeParseFloat3(event.target.value, 0)
|
|
1930
|
+
});
|
|
1931
|
+
},
|
|
1932
|
+
onBlur
|
|
1933
|
+
}))));
|
|
2281
1934
|
};
|
|
2282
1935
|
|
|
2283
1936
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
2284
|
-
var
|
|
2285
|
-
var FieldEditor = ({ readonly, projection, field, registry, onSave, onCancel }) => {
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
1937
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1938
|
+
var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }) => {
|
|
1939
|
+
const { t } = useTranslation8(translationKey);
|
|
1940
|
+
const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
|
|
1941
|
+
useEffect7(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1942
|
+
field,
|
|
1943
|
+
projection
|
|
1944
|
+
]);
|
|
1945
|
+
const [schemas, setSchemas] = useState5([]);
|
|
1946
|
+
useAsyncEffect(async () => {
|
|
1947
|
+
if (!registry) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
1951
|
+
fire: true
|
|
1952
|
+
});
|
|
1953
|
+
const schemas2 = await registry.query().run();
|
|
1954
|
+
setSchemas(schemas2);
|
|
1955
|
+
return () => subscription?.();
|
|
1956
|
+
}, [
|
|
1957
|
+
registry
|
|
1958
|
+
]);
|
|
1959
|
+
const [referenceSchema, setReferenceSchema] = useState5();
|
|
1960
|
+
useEffect7(() => {
|
|
1961
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
1962
|
+
}, [
|
|
1963
|
+
schemas,
|
|
1964
|
+
props?.referenceSchema
|
|
1965
|
+
]);
|
|
1966
|
+
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
1967
|
+
fieldSchema: getFormatSchema(props?.format)
|
|
1968
|
+
});
|
|
1969
|
+
const fieldMap = useMemo7(() => ({
|
|
1970
|
+
["format"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
1971
|
+
...props2,
|
|
1972
|
+
options: FormatEnums.filter((value3) => value3 !== Format4.TypeFormat.None).map((value3) => ({
|
|
1973
|
+
value: value3,
|
|
1974
|
+
label: t(`format ${value3}`)
|
|
1975
|
+
}))
|
|
1976
|
+
}),
|
|
1977
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
1978
|
+
...props2,
|
|
1979
|
+
options: schemas.map((schema) => ({
|
|
1980
|
+
value: schema.typename
|
|
1981
|
+
}))
|
|
1982
|
+
}),
|
|
1983
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
1984
|
+
...props2,
|
|
1985
|
+
options: referenceSchema ? getFormProperties(referenceSchema.ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
|
|
1986
|
+
value: p.name.toString()
|
|
1987
|
+
})) : []
|
|
1988
|
+
}),
|
|
1989
|
+
["options"]: (props2) => /* @__PURE__ */ React17.createElement(SelectOptionField, props2)
|
|
1990
|
+
}), [
|
|
1991
|
+
t,
|
|
1992
|
+
schemas,
|
|
1993
|
+
referenceSchema
|
|
1994
|
+
]);
|
|
1995
|
+
const propIsNotType = useCallback14((props2) => props2.filter((prop) => prop.name !== "type"), []);
|
|
1996
|
+
const handleValuesChanged = useCallback14((_props) => {
|
|
1997
|
+
setFieldSchema((prev) => {
|
|
1998
|
+
const fieldSchema2 = getFormatSchema(_props.format);
|
|
1999
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
2000
|
+
return prev;
|
|
2298
2001
|
}
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
}
|
|
2302
|
-
const schemas2 = await registry.query().run();
|
|
2303
|
-
setSchemas(schemas2);
|
|
2304
|
-
return () => subscription?.();
|
|
2305
|
-
}, [
|
|
2306
|
-
registry
|
|
2307
|
-
]);
|
|
2308
|
-
const [referenceSchema, setReferenceSchema] = useState6();
|
|
2309
|
-
useEffect6(() => {
|
|
2310
|
-
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
2311
|
-
}, [
|
|
2312
|
-
schemas,
|
|
2313
|
-
props?.referenceSchema
|
|
2314
|
-
]);
|
|
2315
|
-
const [{ fieldSchema }, setFieldSchema] = useState6({
|
|
2316
|
-
fieldSchema: getFormatSchema(props?.format)
|
|
2002
|
+
return {
|
|
2003
|
+
fieldSchema: fieldSchema2
|
|
2004
|
+
};
|
|
2317
2005
|
});
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
label: t(`format ${value3}`)
|
|
2324
|
-
}))
|
|
2325
|
-
}),
|
|
2326
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ React18.createElement(SelectField, {
|
|
2327
|
-
...props2,
|
|
2328
|
-
options: schemas.map((schema) => ({
|
|
2329
|
-
value: schema.typename
|
|
2330
|
-
}))
|
|
2331
|
-
}),
|
|
2332
|
-
["referencePath"]: (props2) => /* @__PURE__ */ React18.createElement(SelectField, {
|
|
2333
|
-
...props2,
|
|
2334
|
-
options: referenceSchema ? getFormProperties(referenceSchema.ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
|
|
2335
|
-
value: p.name.toString()
|
|
2336
|
-
})) : []
|
|
2337
|
-
}),
|
|
2338
|
-
["options"]: (props2) => /* @__PURE__ */ React18.createElement(SelectOptionField, props2)
|
|
2339
|
-
}), [
|
|
2340
|
-
t,
|
|
2341
|
-
schemas,
|
|
2342
|
-
referenceSchema
|
|
2343
|
-
]);
|
|
2344
|
-
const propIsNotType = useCallback16((props2) => props2.filter((prop) => prop.name !== "type"), []);
|
|
2345
|
-
const handleValuesChanged = useCallback16((_props) => {
|
|
2346
|
-
setFieldSchema((prev) => {
|
|
2347
|
-
const fieldSchema2 = getFormatSchema(_props.format);
|
|
2348
|
-
if (prev.fieldSchema === fieldSchema2) {
|
|
2349
|
-
return prev;
|
|
2006
|
+
setReferenceSchema((prev) => {
|
|
2007
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
2008
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
2009
|
+
if (newSchema) {
|
|
2010
|
+
return newSchema;
|
|
2350
2011
|
}
|
|
2012
|
+
}
|
|
2013
|
+
return prev;
|
|
2014
|
+
});
|
|
2015
|
+
setProps((props2) => {
|
|
2016
|
+
const type = formatToType[_props.format];
|
|
2017
|
+
const additionalProps = formatToAdditionalPropertyAttributes[_props.format];
|
|
2018
|
+
if (props2.type !== type) {
|
|
2351
2019
|
return {
|
|
2352
|
-
|
|
2020
|
+
...props2,
|
|
2021
|
+
..._props,
|
|
2022
|
+
...additionalProps,
|
|
2023
|
+
type
|
|
2353
2024
|
};
|
|
2354
|
-
}
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
return {
|
|
2369
|
-
...props2,
|
|
2370
|
-
..._props,
|
|
2371
|
-
...additionalProps,
|
|
2372
|
-
type
|
|
2373
|
-
};
|
|
2025
|
+
}
|
|
2026
|
+
return _props;
|
|
2027
|
+
});
|
|
2028
|
+
}, [
|
|
2029
|
+
schemas,
|
|
2030
|
+
props.format,
|
|
2031
|
+
props.referenceSchema
|
|
2032
|
+
]);
|
|
2033
|
+
const handleValidate = useCallback14(({ property }) => {
|
|
2034
|
+
if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
|
|
2035
|
+
return [
|
|
2036
|
+
{
|
|
2037
|
+
path: "property",
|
|
2038
|
+
message: `property is not unique: '${property}'`
|
|
2374
2039
|
}
|
|
2375
|
-
|
|
2040
|
+
];
|
|
2041
|
+
}
|
|
2042
|
+
}, [
|
|
2043
|
+
projection.getFields(),
|
|
2044
|
+
field
|
|
2045
|
+
]);
|
|
2046
|
+
const handleSave = useCallback14((props2) => {
|
|
2047
|
+
if (view) {
|
|
2048
|
+
Obj3.change(view, () => {
|
|
2049
|
+
projection.setFieldProjection({
|
|
2050
|
+
field,
|
|
2051
|
+
props: props2
|
|
2052
|
+
});
|
|
2376
2053
|
});
|
|
2377
|
-
}
|
|
2378
|
-
schemas,
|
|
2379
|
-
props.format,
|
|
2380
|
-
props.referenceSchema
|
|
2381
|
-
]);
|
|
2382
|
-
const handleValidate = useCallback16(({ property }) => {
|
|
2383
|
-
if (property && projection.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
2384
|
-
return [
|
|
2385
|
-
{
|
|
2386
|
-
path: "property",
|
|
2387
|
-
message: `property is not unique: '${property}'`
|
|
2388
|
-
}
|
|
2389
|
-
];
|
|
2390
|
-
}
|
|
2391
|
-
}, [
|
|
2392
|
-
projection.fields,
|
|
2393
|
-
field
|
|
2394
|
-
]);
|
|
2395
|
-
const handleSave = useCallback16((props2) => {
|
|
2054
|
+
} else {
|
|
2396
2055
|
projection.setFieldProjection({
|
|
2397
2056
|
field,
|
|
2398
2057
|
props: props2
|
|
2399
2058
|
});
|
|
2400
|
-
onSave();
|
|
2401
|
-
}, [
|
|
2402
|
-
projection,
|
|
2403
|
-
field,
|
|
2404
|
-
onSave
|
|
2405
|
-
]);
|
|
2406
|
-
const handleCancel = useCallback16(() => {
|
|
2407
|
-
onSave();
|
|
2408
|
-
requestAnimationFrame(() => onCancel?.());
|
|
2409
|
-
}, [
|
|
2410
|
-
onSave
|
|
2411
|
-
]);
|
|
2412
|
-
if (!fieldSchema) {
|
|
2413
|
-
log3.warn("invalid format", {
|
|
2414
|
-
props
|
|
2415
|
-
}, {
|
|
2416
|
-
F: __dxlog_file4,
|
|
2417
|
-
L: 166,
|
|
2418
|
-
S: void 0,
|
|
2419
|
-
C: (f, a) => f(...a)
|
|
2420
|
-
});
|
|
2421
|
-
return null;
|
|
2422
2059
|
}
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
},
|
|
2440
|
-
|
|
2441
|
-
|
|
2060
|
+
onSave();
|
|
2061
|
+
}, [
|
|
2062
|
+
projection,
|
|
2063
|
+
field,
|
|
2064
|
+
view,
|
|
2065
|
+
onSave
|
|
2066
|
+
]);
|
|
2067
|
+
const handleCancel = useCallback14(() => {
|
|
2068
|
+
onSave();
|
|
2069
|
+
requestAnimationFrame(() => onCancel?.());
|
|
2070
|
+
}, [
|
|
2071
|
+
onSave
|
|
2072
|
+
]);
|
|
2073
|
+
if (!fieldSchema) {
|
|
2074
|
+
log2.warn("invalid format", {
|
|
2075
|
+
props
|
|
2076
|
+
}, {
|
|
2077
|
+
F: __dxlog_file2,
|
|
2078
|
+
L: 173,
|
|
2079
|
+
S: void 0,
|
|
2080
|
+
C: (f, a) => f(...a)
|
|
2081
|
+
});
|
|
2082
|
+
return null;
|
|
2442
2083
|
}
|
|
2084
|
+
return /* @__PURE__ */ React17.createElement(Form.Root, {
|
|
2085
|
+
key: field.id,
|
|
2086
|
+
fieldMap,
|
|
2087
|
+
autoFocus: true,
|
|
2088
|
+
readonly,
|
|
2089
|
+
schema: fieldSchema,
|
|
2090
|
+
values: props,
|
|
2091
|
+
exclude: propIsNotType,
|
|
2092
|
+
sort: [
|
|
2093
|
+
"property",
|
|
2094
|
+
"format"
|
|
2095
|
+
],
|
|
2096
|
+
onValuesChanged: handleValuesChanged,
|
|
2097
|
+
onValidate: handleValidate,
|
|
2098
|
+
onSave: handleSave,
|
|
2099
|
+
onCancel: handleCancel
|
|
2100
|
+
}, /* @__PURE__ */ React17.createElement(Form.Content, null, /* @__PURE__ */ React17.createElement(Form.FieldSet, null), /* @__PURE__ */ React17.createElement(Form.Actions, null)));
|
|
2101
|
+
};
|
|
2102
|
+
|
|
2103
|
+
// src/components/Settings/Settings.tsx
|
|
2104
|
+
import React18 from "react";
|
|
2105
|
+
import { Button as Button2, Input as Input12, ScrollArea as ScrollArea2, toLocalizedString, useTranslation as useTranslation9 } from "@dxos/react-ui";
|
|
2106
|
+
import { mx as mx5 } from "@dxos/ui-theme";
|
|
2107
|
+
var SETTINGS_ROOT_NAME = "Settings.Root";
|
|
2108
|
+
var SETTINGS_SECTION_NAME = "Settings.Section";
|
|
2109
|
+
var SETTINGS_SECTION_HEADING_NAME = "Settings.SectionHeading";
|
|
2110
|
+
var SETTINGS_GROUP_NAME = "Settings.Group";
|
|
2111
|
+
var SETTINGS_GROUP_BUTTON_NAME = "Settings.GroupButton";
|
|
2112
|
+
var SETTINGS_CONTAINER_NAME = "Settings.Container";
|
|
2113
|
+
var SETTINGS_FRAME_NAME = "Settings.Frame";
|
|
2114
|
+
var SETTINGS_FRAME_ITEM_NAME = "Settings.FrameItem";
|
|
2115
|
+
var SETTINGS_ITEM_NAME = "Settings.Item";
|
|
2116
|
+
var SETTINGS_ITEM_INPUT_NAME = "Settings.ItemInput";
|
|
2117
|
+
var styles = {
|
|
2118
|
+
title: "pbe-trimMd text-baseText text-lg",
|
|
2119
|
+
description: "text-base text-description",
|
|
2120
|
+
grid: "grid grid-cols-1 md:grid-cols-[3fr_2fr] gap-x-trimLg"
|
|
2121
|
+
};
|
|
2122
|
+
var SettingsRoot = ({ children }) => {
|
|
2123
|
+
return /* @__PURE__ */ React18.createElement(ScrollArea2.Root, {
|
|
2124
|
+
orientation: "vertical"
|
|
2125
|
+
}, /* @__PURE__ */ React18.createElement(ScrollArea2.Viewport, {
|
|
2126
|
+
classNames: "p-trimMd"
|
|
2127
|
+
}, children));
|
|
2128
|
+
};
|
|
2129
|
+
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
2130
|
+
var SettingsSection = ({ title, description, children }) => {
|
|
2131
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement(SettingsSectionHeading, {
|
|
2132
|
+
title,
|
|
2133
|
+
description
|
|
2134
|
+
}), /* @__PURE__ */ React18.createElement("div", {
|
|
2135
|
+
className: "is-full pbs-trimMd space-y-trimMd"
|
|
2136
|
+
}, children));
|
|
2137
|
+
};
|
|
2138
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
2139
|
+
var SettingsSectionHeading = ({ title, description }) => {
|
|
2140
|
+
const { t } = useTranslation9(translationKey);
|
|
2141
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("h2", {
|
|
2142
|
+
className: "pli-trimMd container-max-width text-xl mbs-trimMd mbe-trimMd"
|
|
2143
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React18.createElement("p", {
|
|
2144
|
+
className: "pli-trimMd mlb-trimMd container-max-width text-description"
|
|
2145
|
+
}, toLocalizedString(description, t)));
|
|
2146
|
+
};
|
|
2147
|
+
SettingsSectionHeading.displayName = SETTINGS_SECTION_HEADING_NAME;
|
|
2148
|
+
var SettingsGroupButton = ({ classNames, ...props }) => {
|
|
2149
|
+
return /* @__PURE__ */ React18.createElement(Button2, {
|
|
2150
|
+
...props,
|
|
2151
|
+
classNames: [
|
|
2152
|
+
"md:col-span-2",
|
|
2153
|
+
classNames
|
|
2154
|
+
]
|
|
2155
|
+
});
|
|
2156
|
+
};
|
|
2157
|
+
SettingsGroupButton.displayName = SETTINGS_GROUP_BUTTON_NAME;
|
|
2158
|
+
var SettingsGroup = ({ children, classNames }) => /* @__PURE__ */ React18.createElement("div", {
|
|
2159
|
+
role: "none",
|
|
2160
|
+
className: mx5("group container-max-width space-y-trimMd", classNames)
|
|
2161
|
+
}, children);
|
|
2162
|
+
SettingsGroup.displayName = SETTINGS_GROUP_NAME;
|
|
2163
|
+
var SettingsFrame = ({ children }) => /* @__PURE__ */ React18.createElement("div", {
|
|
2164
|
+
role: "none",
|
|
2165
|
+
className: mx5("container-max-width p-trimMd", "border border-separator rounded-md")
|
|
2166
|
+
}, children);
|
|
2167
|
+
SettingsFrame.displayName = SETTINGS_FRAME_NAME;
|
|
2168
|
+
var SettingsFrameItem = ({ title, description, children }) => {
|
|
2169
|
+
const { t } = useTranslation9(translationKey);
|
|
2170
|
+
return /* @__PURE__ */ React18.createElement("div", {
|
|
2171
|
+
role: "group",
|
|
2172
|
+
className: "min-is-0"
|
|
2173
|
+
}, /* @__PURE__ */ React18.createElement("h3", {
|
|
2174
|
+
className: "text-lg mbe-2"
|
|
2175
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React18.createElement("p", {
|
|
2176
|
+
className: "mlb-trimSm md:mbe-0 text-description"
|
|
2177
|
+
}, toLocalizedString(description, t)), children);
|
|
2178
|
+
};
|
|
2179
|
+
SettingsFrameItem.displayName = SETTINGS_FRAME_ITEM_NAME;
|
|
2180
|
+
var SettingsContainer = ({ classNames, children }) => {
|
|
2181
|
+
return /* @__PURE__ */ React18.createElement("div", {
|
|
2182
|
+
role: "none",
|
|
2183
|
+
className: mx5([
|
|
2184
|
+
"container-max-width",
|
|
2185
|
+
"*:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd",
|
|
2186
|
+
"border border-separator rounded-md",
|
|
2187
|
+
classNames
|
|
2188
|
+
])
|
|
2189
|
+
}, children);
|
|
2190
|
+
};
|
|
2191
|
+
SettingsContainer.displayName = SETTINGS_CONTAINER_NAME;
|
|
2192
|
+
var SettingsItem = ({ title, description = "", children }) => {
|
|
2193
|
+
const { t } = useTranslation9(translationKey);
|
|
2194
|
+
return /* @__PURE__ */ React18.createElement(SettingsContainer, {
|
|
2195
|
+
classNames: styles.grid
|
|
2196
|
+
}, /* @__PURE__ */ React18.createElement("h3", {
|
|
2197
|
+
className: mx5(styles.title, "md:col-span-2")
|
|
2198
|
+
}, toLocalizedString(title, t)), /* @__PURE__ */ React18.createElement("p", {
|
|
2199
|
+
className: styles.description
|
|
2200
|
+
}, toLocalizedString(description, t)), /* @__PURE__ */ React18.createElement("div", {
|
|
2201
|
+
role: "none",
|
|
2202
|
+
className: "text-end plb-1"
|
|
2203
|
+
}, children));
|
|
2204
|
+
};
|
|
2205
|
+
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
2206
|
+
var SettingsItemInput = ({ title, description = "", children }) => {
|
|
2207
|
+
const { t } = useTranslation9(translationKey);
|
|
2208
|
+
return /* @__PURE__ */ React18.createElement(Input12.Root, null, /* @__PURE__ */ React18.createElement(SettingsContainer, {
|
|
2209
|
+
classNames: styles.grid
|
|
2210
|
+
}, /* @__PURE__ */ React18.createElement(Input12.Label, {
|
|
2211
|
+
classNames: mx5(styles.title, "md:col-span-2")
|
|
2212
|
+
}, toLocalizedString(title, t)), /* @__PURE__ */ React18.createElement(Input12.DescriptionAndValidation, null, /* @__PURE__ */ React18.createElement(Input12.Description, {
|
|
2213
|
+
classNames: styles.description
|
|
2214
|
+
}, toLocalizedString(description, t))), /* @__PURE__ */ React18.createElement("div", {
|
|
2215
|
+
role: "none",
|
|
2216
|
+
className: "text-end plb-1"
|
|
2217
|
+
}, children)));
|
|
2218
|
+
};
|
|
2219
|
+
SettingsItemInput.displayName = SETTINGS_ITEM_INPUT_NAME;
|
|
2220
|
+
var Settings = {
|
|
2221
|
+
Root: SettingsRoot,
|
|
2222
|
+
Section: SettingsSection,
|
|
2223
|
+
SectionHeading: SettingsSectionHeading,
|
|
2224
|
+
Group: SettingsGroup,
|
|
2225
|
+
GroupButton: SettingsGroupButton,
|
|
2226
|
+
Container: SettingsContainer,
|
|
2227
|
+
Frame: SettingsFrame,
|
|
2228
|
+
FrameItem: SettingsFrameItem,
|
|
2229
|
+
Item: SettingsItem,
|
|
2230
|
+
ItemInput: SettingsItemInput
|
|
2443
2231
|
};
|
|
2444
2232
|
|
|
2445
2233
|
// src/components/ViewEditor/ViewEditor.tsx
|
|
2446
|
-
import {
|
|
2234
|
+
import { RegistryContext } from "@effect-atom/atom-react";
|
|
2447
2235
|
import * as Array2 from "effect/Array";
|
|
2448
2236
|
import * as Match2 from "effect/Match";
|
|
2449
2237
|
import * as Option4 from "effect/Option";
|
|
2450
2238
|
import * as Schema3 from "effect/Schema";
|
|
2451
|
-
import React19, { forwardRef as forwardRef3, useCallback as
|
|
2452
|
-
import { Filter as Filter2, Format as Format5, Query, QueryAST } from "@dxos/echo";
|
|
2239
|
+
import React19, { forwardRef as forwardRef3, useCallback as useCallback15, useContext, useImperativeHandle, useMemo as useMemo8, useState as useState6 } from "react";
|
|
2240
|
+
import { Filter as Filter2, Format as Format5, Obj as Obj4, Query, QueryAST } from "@dxos/echo";
|
|
2453
2241
|
import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
|
|
2454
|
-
import "@dxos/
|
|
2455
|
-
import {
|
|
2242
|
+
import { invariant } from "@dxos/invariant";
|
|
2243
|
+
import { useObject } from "@dxos/react-client/echo";
|
|
2456
2244
|
import { Callout, IconButton as IconButton4, Input as Input13, useTranslation as useTranslation10 } from "@dxos/react-ui";
|
|
2457
2245
|
import { QueryForm } from "@dxos/react-ui-components";
|
|
2458
2246
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
2459
|
-
import {
|
|
2460
|
-
import {
|
|
2461
|
-
var
|
|
2247
|
+
import { FieldSchema, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
|
|
2248
|
+
import { mx as mx6, osTranslations as osTranslations2, subtleHover as subtleHover2 } from "@dxos/ui-theme";
|
|
2249
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2462
2250
|
var listGrid = "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]";
|
|
2463
2251
|
var listItemGrid = "grid grid-cols-subgrid col-span-5";
|
|
2464
2252
|
var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode = "schema", registry, readonly, showHeading = false, types, tags, onQueryChanged, onDelete }, forwardedRef) => {
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
const
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
schema,
|
|
2474
|
-
JSON.stringify(view.projection)
|
|
2475
|
-
]);
|
|
2476
|
-
useImperativeHandle(forwardedRef, () => projectionModel, [
|
|
2477
|
-
projectionModel
|
|
2478
|
-
]);
|
|
2479
|
-
const [expandedField, setExpandedField] = useState7();
|
|
2480
|
-
const queueTarget = Match2.value(view.query.ast).pipe(Match2.when({
|
|
2481
|
-
type: "options"
|
|
2482
|
-
}, ({ options }) => {
|
|
2483
|
-
return Option4.fromNullable(options.queues).pipe(Option4.flatMap((queues) => Array2.head(queues)), Option4.getOrUndefined);
|
|
2484
|
-
}), Match2.orElse(() => void 0));
|
|
2485
|
-
const viewSchema = useMemo9(() => {
|
|
2486
|
-
const base = Schema3.Struct({
|
|
2487
|
-
query: mode === "schema" ? Format5.URL.annotations({
|
|
2488
|
-
title: "Record type"
|
|
2489
|
-
}) : QueryAST.Query.annotations({
|
|
2490
|
-
title: "Query"
|
|
2491
|
-
})
|
|
2492
|
-
});
|
|
2493
|
-
if (mode === "tag") {
|
|
2494
|
-
return Schema3.Struct({
|
|
2495
|
-
...base.fields,
|
|
2496
|
-
target: Schema3.optional(Schema3.String.annotations({
|
|
2497
|
-
title: "Target Queue"
|
|
2498
|
-
}))
|
|
2499
|
-
}).pipe(Schema3.mutable);
|
|
2500
|
-
}
|
|
2501
|
-
return base.pipe(Schema3.mutable);
|
|
2502
|
-
}, [
|
|
2503
|
-
mode
|
|
2504
|
-
]);
|
|
2505
|
-
const viewValues = useMemo9(() => ({
|
|
2506
|
-
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2507
|
-
target: queueTarget
|
|
2508
|
-
}), [
|
|
2509
|
-
mode,
|
|
2510
|
-
view.query.ast,
|
|
2511
|
-
queueTarget
|
|
2512
|
-
]);
|
|
2513
|
-
const fieldMap = useMemo9(() => mode === "tag" ? customFields({
|
|
2514
|
-
types,
|
|
2515
|
-
tags
|
|
2516
|
-
}) : void 0, [
|
|
2517
|
-
mode,
|
|
2518
|
-
types,
|
|
2519
|
-
tags
|
|
2520
|
-
]);
|
|
2521
|
-
const handleAdd = useCallback17(() => {
|
|
2522
|
-
invariant2(!readonly, void 0, {
|
|
2523
|
-
F: __dxlog_file5,
|
|
2524
|
-
L: 129,
|
|
2525
|
-
S: void 0,
|
|
2526
|
-
A: [
|
|
2527
|
-
"!readonly",
|
|
2528
|
-
""
|
|
2529
|
-
]
|
|
2530
|
-
});
|
|
2531
|
-
const field = projectionModel.createFieldProjection();
|
|
2532
|
-
setExpandedField(field.id);
|
|
2533
|
-
}, [
|
|
2534
|
-
schema,
|
|
2535
|
-
projectionModel,
|
|
2536
|
-
readonly
|
|
2537
|
-
]);
|
|
2538
|
-
const handleUpdate = useCallback17((values) => {
|
|
2539
|
-
requestAnimationFrame(() => {
|
|
2540
|
-
const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : values.query;
|
|
2541
|
-
onQueryChanged?.(query, values.target);
|
|
2542
|
-
});
|
|
2543
|
-
}, [
|
|
2544
|
-
onQueryChanged,
|
|
2253
|
+
const atomRegistry = useContext(RegistryContext);
|
|
2254
|
+
const schemaReadonly = !isMutable(schema);
|
|
2255
|
+
const { t } = useTranslation10(translationKey);
|
|
2256
|
+
const projectionModel = useMemo8(() => {
|
|
2257
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2258
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2259
|
+
const model = new ProjectionModel({
|
|
2260
|
+
registry: atomRegistry,
|
|
2545
2261
|
view,
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2262
|
+
baseSchema: jsonSchema,
|
|
2263
|
+
change
|
|
2264
|
+
});
|
|
2265
|
+
return model;
|
|
2266
|
+
}, [
|
|
2267
|
+
atomRegistry,
|
|
2268
|
+
schema,
|
|
2269
|
+
view
|
|
2270
|
+
]);
|
|
2271
|
+
useImperativeHandle(forwardedRef, () => projectionModel, [
|
|
2272
|
+
projectionModel
|
|
2273
|
+
]);
|
|
2274
|
+
const queueTarget = Match2.value(view.query.ast).pipe(Match2.when({
|
|
2275
|
+
type: "options"
|
|
2276
|
+
}, ({ options }) => {
|
|
2277
|
+
return Option4.fromNullable(options.queues).pipe(Option4.flatMap((queues) => Array2.head(queues)), Option4.getOrUndefined);
|
|
2278
|
+
}), Match2.orElse(() => void 0));
|
|
2279
|
+
const viewSchema = useMemo8(() => {
|
|
2280
|
+
const base = Schema3.Struct({
|
|
2281
|
+
query: mode === "schema" ? Format5.URL.annotations({
|
|
2282
|
+
title: "Record type"
|
|
2283
|
+
}) : QueryAST.Query.annotations({
|
|
2284
|
+
title: "Query"
|
|
2285
|
+
})
|
|
2286
|
+
});
|
|
2287
|
+
if (mode === "tag") {
|
|
2288
|
+
return Schema3.Struct({
|
|
2289
|
+
...base.fields,
|
|
2290
|
+
target: Schema3.optional(Schema3.String.annotations({
|
|
2291
|
+
title: "Target Queue"
|
|
2292
|
+
}))
|
|
2293
|
+
}).pipe(Schema3.mutable);
|
|
2294
|
+
}
|
|
2295
|
+
return base.pipe(Schema3.mutable);
|
|
2296
|
+
}, [
|
|
2297
|
+
mode
|
|
2298
|
+
]);
|
|
2299
|
+
const viewValues = useMemo8(() => ({
|
|
2300
|
+
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2301
|
+
target: queueTarget
|
|
2302
|
+
}), [
|
|
2303
|
+
mode,
|
|
2304
|
+
view.query.ast,
|
|
2305
|
+
queueTarget
|
|
2306
|
+
]);
|
|
2307
|
+
const fieldMap = useMemo8(() => mode === "tag" ? customFields({
|
|
2308
|
+
types,
|
|
2309
|
+
tags
|
|
2310
|
+
}) : void 0, [
|
|
2311
|
+
mode,
|
|
2312
|
+
types,
|
|
2313
|
+
tags
|
|
2314
|
+
]);
|
|
2315
|
+
const handleUpdate = useCallback15((values) => {
|
|
2316
|
+
requestAnimationFrame(() => {
|
|
2317
|
+
const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : values.query;
|
|
2318
|
+
onQueryChanged?.(query, values.target);
|
|
2319
|
+
});
|
|
2320
|
+
}, [
|
|
2321
|
+
onQueryChanged,
|
|
2322
|
+
view,
|
|
2323
|
+
queueTarget,
|
|
2324
|
+
mode
|
|
2325
|
+
]);
|
|
2326
|
+
const handleDelete = useCallback15((fieldId) => {
|
|
2327
|
+
invariant(!readonly, void 0, {
|
|
2328
|
+
F: __dxlog_file3,
|
|
2329
|
+
L: 155,
|
|
2330
|
+
S: void 0,
|
|
2331
|
+
A: [
|
|
2332
|
+
"!readonly",
|
|
2333
|
+
""
|
|
2334
|
+
]
|
|
2335
|
+
});
|
|
2336
|
+
onDelete?.(fieldId);
|
|
2337
|
+
}, [
|
|
2338
|
+
onDelete,
|
|
2339
|
+
readonly
|
|
2340
|
+
]);
|
|
2341
|
+
return /* @__PURE__ */ React19.createElement("div", {
|
|
2342
|
+
role: "none",
|
|
2343
|
+
className: mx6(classNames)
|
|
2344
|
+
}, schemaReadonly && !readonly && /* @__PURE__ */ React19.createElement(Callout.Root, {
|
|
2345
|
+
valence: "info",
|
|
2346
|
+
classNames: "mlb-cardSpacingBlock"
|
|
2347
|
+
}, /* @__PURE__ */ React19.createElement(Callout.Title, null, t("system schema description"))), /* @__PURE__ */ React19.createElement(Form.Root, {
|
|
2348
|
+
schema: viewSchema,
|
|
2349
|
+
values: viewValues,
|
|
2350
|
+
fieldMap,
|
|
2351
|
+
autoSave: true,
|
|
2352
|
+
onSave: handleUpdate
|
|
2353
|
+
}, /* @__PURE__ */ React19.createElement(Form.FieldSet, null), /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
2354
|
+
label: t("fields label"),
|
|
2355
|
+
asChild: true
|
|
2356
|
+
}), /* @__PURE__ */ React19.createElement(FieldList, {
|
|
2357
|
+
schema,
|
|
2358
|
+
view,
|
|
2359
|
+
registry,
|
|
2360
|
+
readonly,
|
|
2361
|
+
showHeading,
|
|
2362
|
+
onDelete: handleDelete
|
|
2363
|
+
})));
|
|
2604
2364
|
});
|
|
2605
2365
|
var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2366
|
+
const atomRegistry = useContext(RegistryContext);
|
|
2367
|
+
const schemaReadonly = !isMutable(schema);
|
|
2368
|
+
const { t } = useTranslation10(translationKey);
|
|
2369
|
+
const [viewSnapshot] = useObject(view);
|
|
2370
|
+
const projectionModel = useMemo8(() => {
|
|
2371
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2372
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2373
|
+
const model = new ProjectionModel({
|
|
2374
|
+
registry: atomRegistry,
|
|
2375
|
+
view,
|
|
2376
|
+
baseSchema: jsonSchema,
|
|
2377
|
+
change
|
|
2378
|
+
});
|
|
2379
|
+
return model;
|
|
2380
|
+
}, [
|
|
2381
|
+
atomRegistry,
|
|
2382
|
+
schema,
|
|
2383
|
+
view
|
|
2384
|
+
]);
|
|
2385
|
+
const [expandedField, setExpandedField] = useState6();
|
|
2386
|
+
const handleAdd = useCallback15(() => {
|
|
2387
|
+
invariant(!readonly, void 0, {
|
|
2388
|
+
F: __dxlog_file3,
|
|
2389
|
+
L: 220,
|
|
2390
|
+
S: void 0,
|
|
2391
|
+
A: [
|
|
2392
|
+
"!readonly",
|
|
2393
|
+
""
|
|
2394
|
+
]
|
|
2395
|
+
});
|
|
2396
|
+
const field = projectionModel.createFieldProjection();
|
|
2397
|
+
setExpandedField(field.id);
|
|
2398
|
+
}, [
|
|
2399
|
+
projectionModel,
|
|
2400
|
+
readonly
|
|
2401
|
+
]);
|
|
2402
|
+
const handleToggleField = useCallback15((field) => {
|
|
2403
|
+
setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
|
|
2404
|
+
}, [
|
|
2405
|
+
readonly
|
|
2406
|
+
]);
|
|
2407
|
+
const handleDelete = useCallback15((fieldId) => {
|
|
2408
|
+
invariant(!readonly, void 0, {
|
|
2409
|
+
F: __dxlog_file3,
|
|
2410
|
+
L: 234,
|
|
2411
|
+
S: void 0,
|
|
2412
|
+
A: [
|
|
2413
|
+
"!readonly",
|
|
2414
|
+
""
|
|
2415
|
+
]
|
|
2416
|
+
});
|
|
2417
|
+
if (fieldId === expandedField) {
|
|
2418
|
+
setExpandedField(void 0);
|
|
2419
|
+
}
|
|
2420
|
+
onDelete?.(fieldId);
|
|
2421
|
+
}, [
|
|
2422
|
+
expandedField,
|
|
2423
|
+
onDelete,
|
|
2424
|
+
readonly
|
|
2425
|
+
]);
|
|
2426
|
+
const handleMove = useCallback15((fromIndex, toIndex) => {
|
|
2427
|
+
invariant(!readonly, void 0, {
|
|
2428
|
+
F: __dxlog_file3,
|
|
2429
|
+
L: 246,
|
|
2430
|
+
S: void 0,
|
|
2431
|
+
A: [
|
|
2432
|
+
"!readonly",
|
|
2433
|
+
""
|
|
2434
|
+
]
|
|
2435
|
+
});
|
|
2436
|
+
Obj4.change(view, (v) => {
|
|
2652
2437
|
const fields = [
|
|
2653
|
-
...
|
|
2438
|
+
...v.projection.fields
|
|
2654
2439
|
];
|
|
2655
2440
|
const [moved] = fields.splice(fromIndex, 1);
|
|
2656
2441
|
fields.splice(toIndex, 0, moved);
|
|
2657
|
-
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
getId: (field) => field.id,
|
|
2679
|
-
onMove: readonly ? void 0 : handleMove,
|
|
2680
|
-
readonly
|
|
2681
|
-
}, ({ items: fields }) => /* @__PURE__ */ React19.createElement(React19.Fragment, null, showHeading && /* @__PURE__ */ React19.createElement("h3", {
|
|
2682
|
-
className: "text-sm"
|
|
2683
|
-
}, t("field path label")), /* @__PURE__ */ React19.createElement("div", {
|
|
2684
|
-
role: "list",
|
|
2685
|
-
className: listGrid
|
|
2686
|
-
}, fields?.map((field) => {
|
|
2687
|
-
const hidden = field.visible === false;
|
|
2688
|
-
return /* @__PURE__ */ React19.createElement(List2.Item, {
|
|
2689
|
-
key: field.id,
|
|
2690
|
-
item: field,
|
|
2691
|
-
classNames: listItemGrid,
|
|
2692
|
-
"aria-expanded": expandedField === field.id
|
|
2693
|
-
}, /* @__PURE__ */ React19.createElement("div", {
|
|
2694
|
-
role: "none",
|
|
2695
|
-
className: mx7(subtleHover2, listItemGrid, "rounded-sm cursor-pointer min-bs-10")
|
|
2696
|
-
}, /* @__PURE__ */ React19.createElement(List2.ItemDragHandle, {
|
|
2697
|
-
disabled: readonly || schemaReadonly
|
|
2698
|
-
}), /* @__PURE__ */ React19.createElement(List2.ItemTitle, {
|
|
2699
|
-
classNames: hidden && "text-subdued",
|
|
2700
|
-
onClick: () => handleToggleField(field)
|
|
2701
|
-
}, field.path), /* @__PURE__ */ React19.createElement(List2.ItemButton, {
|
|
2702
|
-
label: t(hidden ? "show field label" : "hide field label"),
|
|
2703
|
-
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2704
|
-
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2705
|
-
autoHide: false,
|
|
2706
|
-
disabled: readonly || !hidden && projectionModel.fields.length <= 1,
|
|
2707
|
-
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2708
|
-
}), !readonly && /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(List2.ItemDeleteButton, {
|
|
2709
|
-
label: t("delete field label"),
|
|
2710
|
-
autoHide: false,
|
|
2711
|
-
disabled: readonly || schemaReadonly || view.projection.fields.length <= 1,
|
|
2712
|
-
onClick: () => handleDelete(field.id),
|
|
2713
|
-
"data-testid": "field.delete"
|
|
2714
|
-
}), /* @__PURE__ */ React19.createElement(IconButton4, {
|
|
2715
|
-
iconOnly: true,
|
|
2716
|
-
variant: "ghost",
|
|
2717
|
-
label: t("toggle expand label", {
|
|
2718
|
-
ns: "os"
|
|
2719
|
-
}),
|
|
2720
|
-
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2721
|
-
onClick: () => handleToggleField(field),
|
|
2722
|
-
"data-testid": "field.toggle"
|
|
2723
|
-
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React19.createElement("div", {
|
|
2724
|
-
role: "none",
|
|
2725
|
-
className: "col-span-5 mbs-1 mbe-1 border border-separator rounded-md"
|
|
2726
|
-
}, /* @__PURE__ */ React19.createElement(FieldEditor, {
|
|
2727
|
-
readonly: readonly || schemaReadonly,
|
|
2728
|
-
registry,
|
|
2729
|
-
projection: projectionModel,
|
|
2730
|
-
field,
|
|
2731
|
-
onSave: handleClose
|
|
2732
|
-
})));
|
|
2733
|
-
}))));
|
|
2734
|
-
} finally {
|
|
2735
|
-
_effect.f();
|
|
2442
|
+
v.projection.fields = fields;
|
|
2443
|
+
});
|
|
2444
|
+
}, [
|
|
2445
|
+
view,
|
|
2446
|
+
readonly
|
|
2447
|
+
]);
|
|
2448
|
+
const handleClose = useCallback15(() => setExpandedField(void 0), []);
|
|
2449
|
+
const handleHide = useCallback15((fieldId) => {
|
|
2450
|
+
setExpandedField(void 0);
|
|
2451
|
+
projectionModel.hideFieldProjection(fieldId);
|
|
2452
|
+
}, [
|
|
2453
|
+
projectionModel
|
|
2454
|
+
]);
|
|
2455
|
+
const handleShow = useCallback15((property) => {
|
|
2456
|
+
setExpandedField(void 0);
|
|
2457
|
+
projectionModel.showFieldProjection(property);
|
|
2458
|
+
}, [
|
|
2459
|
+
projectionModel
|
|
2460
|
+
]);
|
|
2461
|
+
if (!viewSnapshot) {
|
|
2462
|
+
return null;
|
|
2736
2463
|
}
|
|
2464
|
+
return /* @__PURE__ */ React19.createElement(List2.Root, {
|
|
2465
|
+
items: viewSnapshot.projection.fields,
|
|
2466
|
+
isItem: Schema3.is(FieldSchema),
|
|
2467
|
+
getId: (field) => field.id,
|
|
2468
|
+
onMove: readonly ? void 0 : handleMove,
|
|
2469
|
+
readonly
|
|
2470
|
+
}, ({ items: fields }) => /* @__PURE__ */ React19.createElement(React19.Fragment, null, showHeading && /* @__PURE__ */ React19.createElement("h3", {
|
|
2471
|
+
className: "text-sm"
|
|
2472
|
+
}, t("field path label")), /* @__PURE__ */ React19.createElement("div", {
|
|
2473
|
+
role: "list",
|
|
2474
|
+
className: listGrid
|
|
2475
|
+
}, fields?.map((field) => {
|
|
2476
|
+
const hidden = field.visible === false;
|
|
2477
|
+
return /* @__PURE__ */ React19.createElement(List2.Item, {
|
|
2478
|
+
key: field.id,
|
|
2479
|
+
item: field,
|
|
2480
|
+
classNames: listItemGrid,
|
|
2481
|
+
"aria-expanded": expandedField === field.id
|
|
2482
|
+
}, /* @__PURE__ */ React19.createElement("div", {
|
|
2483
|
+
role: "none",
|
|
2484
|
+
className: mx6(subtleHover2, listItemGrid, "rounded-sm cursor-pointer min-bs-10")
|
|
2485
|
+
}, /* @__PURE__ */ React19.createElement(List2.ItemDragHandle, {
|
|
2486
|
+
disabled: readonly || schemaReadonly
|
|
2487
|
+
}), /* @__PURE__ */ React19.createElement(List2.ItemTitle, {
|
|
2488
|
+
classNames: hidden && "text-subdued",
|
|
2489
|
+
onClick: () => handleToggleField(field)
|
|
2490
|
+
}, field.path), /* @__PURE__ */ React19.createElement(List2.ItemButton, {
|
|
2491
|
+
label: t(hidden ? "show field label" : "hide field label"),
|
|
2492
|
+
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2493
|
+
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2494
|
+
autoHide: false,
|
|
2495
|
+
disabled: readonly || !hidden && projectionModel.getFields().length <= 1,
|
|
2496
|
+
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2497
|
+
}), !readonly && /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(List2.ItemDeleteButton, {
|
|
2498
|
+
label: t("delete field label"),
|
|
2499
|
+
autoHide: false,
|
|
2500
|
+
disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
|
|
2501
|
+
onClick: () => handleDelete(field.id),
|
|
2502
|
+
"data-testid": "field.delete"
|
|
2503
|
+
}), /* @__PURE__ */ React19.createElement(IconButton4, {
|
|
2504
|
+
iconOnly: true,
|
|
2505
|
+
variant: "ghost",
|
|
2506
|
+
label: t("toggle expand label", {
|
|
2507
|
+
ns: osTranslations2
|
|
2508
|
+
}),
|
|
2509
|
+
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2510
|
+
onClick: () => handleToggleField(field),
|
|
2511
|
+
"data-testid": "field.toggle"
|
|
2512
|
+
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React19.createElement("div", {
|
|
2513
|
+
role: "none",
|
|
2514
|
+
className: "col-span-5 mbs-1 mbe-1 border border-separator rounded-md"
|
|
2515
|
+
}, /* @__PURE__ */ React19.createElement(FieldEditor, {
|
|
2516
|
+
readonly: readonly || schemaReadonly,
|
|
2517
|
+
registry,
|
|
2518
|
+
projection: projectionModel,
|
|
2519
|
+
field,
|
|
2520
|
+
onSave: handleClose
|
|
2521
|
+
})));
|
|
2522
|
+
})), !readonly && !expandedField && /* @__PURE__ */ React19.createElement("div", {
|
|
2523
|
+
role: "none",
|
|
2524
|
+
className: "mlb-cardSpacingBlock"
|
|
2525
|
+
}, /* @__PURE__ */ React19.createElement(IconButton4, {
|
|
2526
|
+
icon: "ph--plus--regular",
|
|
2527
|
+
label: t("add property button label"),
|
|
2528
|
+
onClick: handleAdd,
|
|
2529
|
+
disabled: viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT,
|
|
2530
|
+
classNames: "is-full"
|
|
2531
|
+
}))));
|
|
2737
2532
|
};
|
|
2738
2533
|
var customFields = ({ types, tags }) => ({
|
|
2739
2534
|
query: ({ type, readonly, label, getValue, onValueChange }) => {
|
|
2740
|
-
const handleChange =
|
|
2535
|
+
const handleChange = useCallback15((query) => onValueChange(type, query.ast), [
|
|
2741
2536
|
onValueChange
|
|
2742
2537
|
]);
|
|
2743
2538
|
return /* @__PURE__ */ React19.createElement(Input13.Root, null, /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
@@ -2754,15 +2549,6 @@ var customFields = ({ types, tags }) => ({
|
|
|
2754
2549
|
export {
|
|
2755
2550
|
ArrayField,
|
|
2756
2551
|
BooleanField,
|
|
2757
|
-
ControlFrame,
|
|
2758
|
-
ControlFrameItem,
|
|
2759
|
-
ControlGroup,
|
|
2760
|
-
ControlGroupButton,
|
|
2761
|
-
ControlItem,
|
|
2762
|
-
ControlItemInput,
|
|
2763
|
-
ControlPage,
|
|
2764
|
-
ControlSection,
|
|
2765
|
-
ControlSectionHeading,
|
|
2766
2552
|
FieldEditor,
|
|
2767
2553
|
Form,
|
|
2768
2554
|
FormFieldErrorBoundary,
|
|
@@ -2775,12 +2561,12 @@ export {
|
|
|
2775
2561
|
RefField,
|
|
2776
2562
|
SelectField,
|
|
2777
2563
|
SelectOptionField,
|
|
2564
|
+
Settings,
|
|
2778
2565
|
TextAreaField,
|
|
2779
2566
|
TextField,
|
|
2780
2567
|
TupleField,
|
|
2781
2568
|
ViewEditor,
|
|
2782
2569
|
cellClassesForFieldType,
|
|
2783
|
-
controlItemClasses,
|
|
2784
2570
|
formatForDisplay,
|
|
2785
2571
|
formatForEditing,
|
|
2786
2572
|
getDefaultValue,
|
|
@@ -2789,13 +2575,12 @@ export {
|
|
|
2789
2575
|
omitId,
|
|
2790
2576
|
parseValue,
|
|
2791
2577
|
pathNotUniqueError,
|
|
2578
|
+
setValueEchoAware,
|
|
2792
2579
|
translations,
|
|
2793
2580
|
useFormContext,
|
|
2794
2581
|
useFormFieldState,
|
|
2795
2582
|
useFormHandler,
|
|
2796
2583
|
useFormValues,
|
|
2797
|
-
useKeyHandler
|
|
2798
|
-
useQueryRefOptions,
|
|
2799
|
-
useRefQueryOptions
|
|
2584
|
+
useKeyHandler
|
|
2800
2585
|
};
|
|
2801
2586
|
//# sourceMappingURL=index.mjs.map
|