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