@dxos/react-ui-form 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731
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 +1335 -561
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +2 -1
- package/dist/lib/browser/translations.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +1335 -561
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +2 -1
- package/dist/lib/node-esm/translations.mjs.map +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +2 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +35 -9
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +76 -16
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +14 -4
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +22 -10
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +8 -2
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts +19 -0
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts +50 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts +119 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts +30 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/index.d.ts +4 -0
- package/dist/types/src/components/Form/Layout/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts +31 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/DateField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/DateField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts +13 -0
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +2 -1
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts +4 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +2 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/index.d.ts +2 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +3 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/meta-tags.d.ts +30 -0
- package/dist/types/src/components/Form/meta-tags.d.ts.map +1 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts +2 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +3 -4
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +2 -2
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +2 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +2 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts +9 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts +87 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/index.d.ts +2 -0
- package/dist/types/src/components/ObjectTree/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.stories.d.ts +2 -1
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +7 -8
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +4 -4
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +9 -0
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +11 -0
- package/dist/types/src/util/properties.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -32
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.test.tsx +4 -1
- package/src/components/FieldEditor/FieldEditor.tsx +19 -14
- package/src/components/Form/Form.stories.tsx +21 -27
- package/src/components/Form/Form.tsx +106 -19
- package/src/components/Form/FormField.tsx +85 -28
- package/src/components/Form/FormFieldComponent.tsx +75 -20
- package/src/components/Form/FormFieldSet.tsx +32 -3
- package/src/components/Form/FormTooltipsContext.ts +25 -0
- package/src/components/Form/Layout/FormLayout.stories.test.tsx +51 -0
- package/src/components/Form/Layout/FormLayout.stories.tsx +422 -0
- package/src/components/Form/Layout/FormLayout.test.ts +59 -0
- package/src/components/Form/Layout/FormLayout.tsx +251 -0
- package/src/components/Form/Layout/annotation.ts +38 -0
- package/src/components/Form/Layout/index.ts +7 -0
- package/src/components/Form/Layout/parser.test.ts +120 -0
- package/src/components/Form/Layout/parser.ts +167 -0
- package/src/components/Form/fields/ArrayField.tsx +61 -38
- package/src/components/Form/fields/DateField.tsx +101 -0
- package/src/components/Form/fields/GeoPointField.tsx +4 -1
- package/src/components/Form/fields/InlineRefField.tsx +146 -0
- package/src/components/Form/fields/MarkdownField.tsx +3 -3
- package/src/components/Form/fields/RefField.tsx +29 -23
- package/src/components/Form/fields/SelectField.tsx +17 -5
- package/src/components/Form/fields/SelectOptionField.tsx +4 -3
- package/src/components/Form/fields/TextAreaField.tsx +1 -1
- package/src/components/Form/fields/TupleField.tsx +2 -1
- package/src/components/Form/fields/index.ts +2 -0
- package/src/components/Form/index.ts +3 -0
- package/src/components/Form/meta-tags.test.ts +47 -0
- package/src/components/Form/meta-tags.ts +33 -0
- package/src/components/ObjectForm/ObjectForm.tsx +21 -26
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +2 -2
- package/src/components/ObjectPicker/ObjectPicker.tsx +2 -2
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +14 -26
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +20 -10
- package/src/components/ObjectProperties/ObjectProperties.tsx +26 -30
- package/src/components/ObjectTree/ObjectTree.stories.tsx +134 -0
- package/src/components/ObjectTree/ObjectTree.tsx +190 -0
- package/src/components/ObjectTree/index.ts +5 -0
- package/src/components/Settings/Settings.tsx +2 -1
- package/src/components/Settings/SettingsItem.tsx +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +35 -40
- package/src/components/ViewEditor/ViewEditor.test.tsx +11 -8
- package/src/components/ViewEditor/ViewEditor.tsx +29 -32
- package/src/components/index.ts +1 -0
- package/src/components/testing.tsx +4 -4
- package/src/translations.ts +2 -1
- package/src/util/properties.test.ts +67 -9
- package/src/util/properties.ts +36 -4
- package/src/vite-env.d.ts +10 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
2
|
-
import
|
|
3
|
-
import { Obj as
|
|
4
|
-
import { Format as
|
|
2
|
+
import React20, { useCallback as useCallback16, useEffect as useEffect5, useMemo as useMemo10, useState as useState6 } from "react";
|
|
3
|
+
import { Filter as Filter2, Obj as Obj4, Type as Type4 } from "@dxos/echo";
|
|
4
|
+
import { Format as Format6, FormatEnums, formatToType } from "@dxos/echo/internal";
|
|
5
5
|
import { log as log2 } from "@dxos/log";
|
|
6
|
-
import { useAsyncEffect, useTranslation as
|
|
6
|
+
import { useAsyncEffect, useTranslation as useTranslation10 } from "@dxos/react-ui";
|
|
7
7
|
import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
|
|
8
|
-
import { translationKey as
|
|
8
|
+
import { translationKey as translationKey10 } from "#translations";
|
|
9
9
|
|
|
10
10
|
// src/util/field.ts
|
|
11
11
|
import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
|
|
@@ -310,18 +310,39 @@ var formatForEditing = ({ type, format, value: value3, locale = void 0 }) => {
|
|
|
310
310
|
import * as Option from "effect/Option";
|
|
311
311
|
import * as SchemaAST2 from "effect/SchemaAST";
|
|
312
312
|
import { Annotation } from "@dxos/echo";
|
|
313
|
-
import { getProperties } from "@dxos/effect";
|
|
313
|
+
import { getProperties, isArrayType, isNestedType } from "@dxos/effect";
|
|
314
|
+
var unwrapOptional = (prop) => {
|
|
315
|
+
if (!prop.isOptional || !SchemaAST2.isUnion(prop.type)) {
|
|
316
|
+
return prop.type;
|
|
317
|
+
}
|
|
318
|
+
const defined = prop.type.types.filter((type) => type._tag !== "UndefinedKeyword");
|
|
319
|
+
if (defined.length === 0) {
|
|
320
|
+
return prop.type;
|
|
321
|
+
}
|
|
322
|
+
return defined.length === 1 ? defined[0] : SchemaAST2.Union.make(defined, prop.type.annotations);
|
|
323
|
+
};
|
|
314
324
|
var getFormProperties = (ast) => {
|
|
315
|
-
const
|
|
316
|
-
|
|
325
|
+
const signatures = SchemaAST2.getPropertySignatures(ast);
|
|
326
|
+
const rawByName = new Map(signatures.map((prop) => [
|
|
327
|
+
prop.name,
|
|
328
|
+
unwrapOptional(prop)
|
|
329
|
+
]));
|
|
330
|
+
const hidden = new Set(signatures.filter((prop) => Annotation.FormInputAnnotation.getFromAst(unwrapOptional(prop)).pipe(Option.getOrElse(() => true)) === false).map((prop) => prop.name));
|
|
331
|
+
return getProperties(ast).filter((prop) => !hidden.has(prop.name)).map((prop) => {
|
|
332
|
+
const raw = rawByName.get(prop.name);
|
|
333
|
+
return raw && (isNestedType(raw) || isArrayType(raw)) ? {
|
|
334
|
+
...prop,
|
|
335
|
+
type: raw
|
|
336
|
+
} : prop;
|
|
337
|
+
});
|
|
317
338
|
};
|
|
318
339
|
|
|
319
340
|
// src/util/refs.ts
|
|
320
341
|
import { Ref } from "@dxos/echo";
|
|
321
342
|
import { ReferenceAnnotationId } from "@dxos/echo/internal";
|
|
322
|
-
import { findAnnotation, getArrayElementType, isArrayType } from "@dxos/effect";
|
|
343
|
+
import { findAnnotation, getArrayElementType, isArrayType as isArrayType2 } from "@dxos/effect";
|
|
323
344
|
var getRefProps = (ast) => {
|
|
324
|
-
if (
|
|
345
|
+
if (isArrayType2(ast)) {
|
|
325
346
|
const elementType = getArrayElementType(ast);
|
|
326
347
|
if (elementType) {
|
|
327
348
|
if (Ref.isRefType(elementType)) {
|
|
@@ -346,23 +367,25 @@ var getRefProps = (ast) => {
|
|
|
346
367
|
};
|
|
347
368
|
|
|
348
369
|
// src/components/Form/fields/ArrayField.tsx
|
|
349
|
-
import * as
|
|
350
|
-
import * as
|
|
351
|
-
import
|
|
352
|
-
import {
|
|
353
|
-
import {
|
|
370
|
+
import * as Option6 from "effect/Option";
|
|
371
|
+
import * as SchemaAST6 from "effect/SchemaAST";
|
|
372
|
+
import React6, { useCallback as useCallback3 } from "react";
|
|
373
|
+
import { Ref as Ref2 } from "@dxos/echo";
|
|
374
|
+
import { createJsonPath as createJsonPath6, findNode as findNode3, getArrayElementType as getArrayElementType2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2, isNestedType as isNestedType3 } from "@dxos/effect";
|
|
375
|
+
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
354
376
|
import { translationKey as translationKey3 } from "#translations";
|
|
355
377
|
|
|
356
378
|
// src/components/Form/Form.tsx
|
|
357
|
-
import { createContext } from "@radix-ui/react-context";
|
|
358
|
-
import * as
|
|
359
|
-
import * as
|
|
360
|
-
import * as
|
|
361
|
-
import
|
|
362
|
-
import { Annotation as EchoAnnotation } from "@dxos/echo";
|
|
363
|
-
import { createJsonPath as
|
|
364
|
-
import { IconButton, ScrollArea, useMergeRefs, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
365
|
-
import { composable, composableProps,
|
|
379
|
+
import { createContext as createContext2 } from "@radix-ui/react-context";
|
|
380
|
+
import * as Option5 from "effect/Option";
|
|
381
|
+
import * as Schema3 from "effect/Schema";
|
|
382
|
+
import * as SchemaAST5 from "effect/SchemaAST";
|
|
383
|
+
import React5, { useEffect as useEffect2, useMemo as useMemo5, useRef } from "react";
|
|
384
|
+
import { Annotation as EchoAnnotation, Type } from "@dxos/echo";
|
|
385
|
+
import { createJsonPath as createJsonPath5, getValue as getValue$2 } from "@dxos/effect";
|
|
386
|
+
import { Column, IconButton as IconButton2, Input as Input3, ScrollArea, useMergeRefs, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
387
|
+
import { composable, composableProps, withColumn } from "@dxos/react-ui";
|
|
388
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
366
389
|
import { translationKey as translationKey2 } from "#translations";
|
|
367
390
|
|
|
368
391
|
// src/hooks/useFormHandler.ts
|
|
@@ -582,18 +605,18 @@ var mergeAtPath = (obj, path, value3) => {
|
|
|
582
605
|
if (path.length === 0) {
|
|
583
606
|
return value3;
|
|
584
607
|
}
|
|
585
|
-
const [
|
|
586
|
-
const child = rest.length === 0 ? value3 : mergeAtPath(obj?.[
|
|
608
|
+
const [head, ...rest] = path;
|
|
609
|
+
const child = rest.length === 0 ? value3 : mergeAtPath(obj?.[head], rest, value3);
|
|
587
610
|
if (Array.isArray(obj)) {
|
|
588
611
|
const copy = [
|
|
589
612
|
...obj
|
|
590
613
|
];
|
|
591
|
-
copy[
|
|
614
|
+
copy[head] = child;
|
|
592
615
|
return copy;
|
|
593
616
|
}
|
|
594
617
|
return {
|
|
595
618
|
...obj,
|
|
596
|
-
[
|
|
619
|
+
[head]: child
|
|
597
620
|
};
|
|
598
621
|
};
|
|
599
622
|
var flatMap = (errors) => {
|
|
@@ -638,16 +661,32 @@ var useKeyHandler = (elRef, form) => {
|
|
|
638
661
|
};
|
|
639
662
|
|
|
640
663
|
// src/components/Form/FormFieldComponent.tsx
|
|
664
|
+
import { format as formatDate2 } from "date-fns";
|
|
641
665
|
import React, { Component } from "react";
|
|
666
|
+
import { Format as Format3 } from "@dxos/echo";
|
|
642
667
|
import { Icon, Input, Tooltip } from "@dxos/react-ui";
|
|
643
|
-
import { inputTextLabel } from "@dxos/ui
|
|
644
|
-
|
|
668
|
+
import { inputTextLabel } from "@dxos/react-ui";
|
|
669
|
+
import { mx } from "@dxos/ui-theme";
|
|
670
|
+
|
|
671
|
+
// src/components/Form/FormTooltipsContext.ts
|
|
672
|
+
import { createContext, useContext } from "react";
|
|
673
|
+
var FormTooltipsContext = createContext(true);
|
|
674
|
+
var useFormTooltips = () => useContext(FormTooltipsContext);
|
|
675
|
+
|
|
676
|
+
// src/components/Form/FormFieldComponent.tsx
|
|
677
|
+
var FormFieldLabel = ({ label, error, readonly, asChild, path }) => {
|
|
678
|
+
const tooltips = useFormTooltips();
|
|
645
679
|
const Label = readonly || asChild ? "span" : Input.Label;
|
|
680
|
+
const labelNode = /* @__PURE__ */ React.createElement(Label, {
|
|
681
|
+
className: mx(inputTextLabel, "text-sm")
|
|
682
|
+
}, label);
|
|
646
683
|
return /* @__PURE__ */ React.createElement("div", {
|
|
647
684
|
className: "flex items-center justify-between"
|
|
648
|
-
}, /* @__PURE__ */ React.createElement(
|
|
649
|
-
|
|
650
|
-
|
|
685
|
+
}, tooltips && path ? /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
686
|
+
asChild: true,
|
|
687
|
+
content: path,
|
|
688
|
+
side: "bottom"
|
|
689
|
+
}, labelNode) : labelNode, error && /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
651
690
|
asChild: true,
|
|
652
691
|
content: error,
|
|
653
692
|
side: "bottom"
|
|
@@ -658,14 +697,33 @@ var FormFieldLabel = ({ label, error, readonly, asChild }) => {
|
|
|
658
697
|
})));
|
|
659
698
|
};
|
|
660
699
|
FormFieldLabel.displayName = "Form.FieldLabel";
|
|
700
|
+
var formatStaticValue = (value3, format) => {
|
|
701
|
+
if (value3 == null) {
|
|
702
|
+
return "";
|
|
703
|
+
}
|
|
704
|
+
switch (format) {
|
|
705
|
+
case Format3.TypeFormat.DateTime:
|
|
706
|
+
case Format3.TypeFormat.Date:
|
|
707
|
+
case Format3.TypeFormat.Time: {
|
|
708
|
+
const date = new Date(value3);
|
|
709
|
+
if (Number.isNaN(date.getTime())) {
|
|
710
|
+
return String(value3);
|
|
711
|
+
}
|
|
712
|
+
const pattern = format === Format3.TypeFormat.DateTime ? "PPp" : format === Format3.TypeFormat.Date ? "PP" : "p";
|
|
713
|
+
return formatDate2(date, pattern);
|
|
714
|
+
}
|
|
715
|
+
default:
|
|
716
|
+
return String(value3);
|
|
717
|
+
}
|
|
718
|
+
};
|
|
661
719
|
var FormFieldWrapper = (props) => {
|
|
662
|
-
const { children, readonly, layout, label, getStatus, getValue } = props;
|
|
720
|
+
const { children, readonly, layout, label, jsonPath, format, getStatus, getValue } = props;
|
|
663
721
|
const { status, error } = getStatus();
|
|
664
722
|
const value3 = getValue();
|
|
665
723
|
if (layout === "static" && value3 == null) {
|
|
666
724
|
return null;
|
|
667
725
|
}
|
|
668
|
-
const str =
|
|
726
|
+
const str = formatStaticValue(value3, format);
|
|
669
727
|
return /* @__PURE__ */ React.createElement("div", {
|
|
670
728
|
className: "contents"
|
|
671
729
|
}, /* @__PURE__ */ React.createElement(Input.Root, {
|
|
@@ -673,10 +731,14 @@ var FormFieldWrapper = (props) => {
|
|
|
673
731
|
}, layout !== "inline" && /* @__PURE__ */ React.createElement(FormFieldLabel, {
|
|
674
732
|
error,
|
|
675
733
|
readonly,
|
|
676
|
-
label
|
|
677
|
-
|
|
734
|
+
label,
|
|
735
|
+
path: jsonPath
|
|
736
|
+
}), layout === "static" ? /* @__PURE__ */ React.createElement("p", {
|
|
737
|
+
className: "truncate min-w-0",
|
|
738
|
+
title: str
|
|
739
|
+
}, str) : children ? children({
|
|
678
740
|
value: value3
|
|
679
|
-
}) : null, layout === "full" && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Validation, null, error))));
|
|
741
|
+
}) : null, layout === "full" && error && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Validation, null, error))));
|
|
680
742
|
};
|
|
681
743
|
var FormFieldErrorBoundary = class extends Component {
|
|
682
744
|
static getDerivedStateFromError(error) {
|
|
@@ -695,9 +757,9 @@ var FormFieldErrorBoundary = class extends Component {
|
|
|
695
757
|
render() {
|
|
696
758
|
if (this.state.error) {
|
|
697
759
|
return /* @__PURE__ */ React.createElement("div", {
|
|
698
|
-
className: "flex gap-2 border border-rose-
|
|
760
|
+
className: "flex gap-2 border border-rose-bg font-mono text-sm"
|
|
699
761
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
700
|
-
className: "bg-rose-
|
|
762
|
+
className: "bg-rose-bg text-base-fg px-1 font-thin"
|
|
701
763
|
}, "ERROR"), String(this.props.path?.join(".")));
|
|
702
764
|
}
|
|
703
765
|
return this.props.children;
|
|
@@ -710,7 +772,9 @@ var FormFieldErrorBoundary = class extends Component {
|
|
|
710
772
|
};
|
|
711
773
|
|
|
712
774
|
// src/components/Form/FormFieldSet.tsx
|
|
713
|
-
import
|
|
775
|
+
import * as Option4 from "effect/Option";
|
|
776
|
+
import React4, { useMemo as useMemo4 } from "react";
|
|
777
|
+
import { createJsonPath as createJsonPath4 } from "@dxos/effect";
|
|
714
778
|
|
|
715
779
|
// src/components/Form/FormField.tsx
|
|
716
780
|
import * as Match from "effect/Match";
|
|
@@ -719,9 +783,10 @@ import * as Schema from "effect/Schema";
|
|
|
719
783
|
import * as SchemaAST3 from "effect/SchemaAST";
|
|
720
784
|
import * as String2 from "effect/String";
|
|
721
785
|
import React2, { useMemo as useMemo2 } from "react";
|
|
722
|
-
import { Format as
|
|
723
|
-
import { createJsonPath as createJsonPath2, findNode, getAnnotation as getAnnotation2, getDiscriminatedType, isArrayType as
|
|
724
|
-
import { useTranslation } from "@dxos/react-ui";
|
|
786
|
+
import { Annotation as Annotation2, Format as Format4 } from "@dxos/echo";
|
|
787
|
+
import { createJsonPath as createJsonPath2, findNode, getAnnotation as getAnnotation2, getDiscriminatedType, isArrayType as isArrayType3, isDiscriminatedUnion, isLiteralUnion as isLiteralUnion2, isNestedType as isNestedType2 } from "@dxos/effect";
|
|
788
|
+
import { IconButton, useTranslation } from "@dxos/react-ui";
|
|
789
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
725
790
|
import { translationKey } from "#translations";
|
|
726
791
|
var FormField = (props) => {
|
|
727
792
|
const {
|
|
@@ -740,7 +805,7 @@ var FormField = (props) => {
|
|
|
740
805
|
createInitialValuePath,
|
|
741
806
|
createFieldMap: createFieldMap3,
|
|
742
807
|
db,
|
|
743
|
-
|
|
808
|
+
useType: schemaHook,
|
|
744
809
|
getOptions,
|
|
745
810
|
onCreate
|
|
746
811
|
} = props;
|
|
@@ -748,7 +813,7 @@ var FormField = (props) => {
|
|
|
748
813
|
const title = getAnnotation2(SchemaAST3.TitleAnnotationId)(type);
|
|
749
814
|
const description = getAnnotation2(SchemaAST3.DescriptionAnnotationId)(type);
|
|
750
815
|
const examples = getAnnotation2(SchemaAST3.ExamplesAnnotationId)(type);
|
|
751
|
-
const label = useMemo2(() => title ?? String2.capitalize(name), [
|
|
816
|
+
const label = useMemo2(() => title ?? (name == null ? "" : String2.capitalize(name)), [
|
|
752
817
|
title,
|
|
753
818
|
name
|
|
754
819
|
]);
|
|
@@ -758,30 +823,34 @@ var FormField = (props) => {
|
|
|
758
823
|
label
|
|
759
824
|
]);
|
|
760
825
|
const fieldState = useFormFieldState(FormField.displayName, path);
|
|
826
|
+
const jsonPath = createJsonPath2(path ?? []);
|
|
761
827
|
const fieldProps = {
|
|
762
828
|
type,
|
|
763
|
-
format:
|
|
829
|
+
format: Format4.FormatAnnotation.getFromAst(type).pipe((annotation) => Option2.getOrUndefined(annotation)),
|
|
764
830
|
readonly,
|
|
765
831
|
label,
|
|
832
|
+
jsonPath,
|
|
766
833
|
placeholder,
|
|
767
834
|
layout,
|
|
768
835
|
db,
|
|
769
836
|
...fieldState
|
|
770
837
|
};
|
|
771
|
-
|
|
838
|
+
if (readonly && fieldState.getValue() == null) {
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
772
841
|
const CustomField = fieldMap?.[jsonPath];
|
|
773
842
|
if (CustomField) {
|
|
774
843
|
return /* @__PURE__ */ React2.createElement(CustomField, fieldProps);
|
|
775
844
|
}
|
|
776
845
|
const component = fieldProvider?.({
|
|
777
846
|
schema: Schema.make(type),
|
|
778
|
-
prop: name,
|
|
847
|
+
prop: name ?? "",
|
|
779
848
|
fieldProps
|
|
780
849
|
});
|
|
781
850
|
if (component) {
|
|
782
851
|
return component;
|
|
783
852
|
}
|
|
784
|
-
if (
|
|
853
|
+
if (isArrayType3(type)) {
|
|
785
854
|
return /* @__PURE__ */ React2.createElement(ArrayField, {
|
|
786
855
|
fieldProps: fieldState,
|
|
787
856
|
label,
|
|
@@ -810,6 +879,16 @@ var FormField = (props) => {
|
|
|
810
879
|
}
|
|
811
880
|
const refProps = getRefProps(type);
|
|
812
881
|
if (refProps) {
|
|
882
|
+
const inline = Annotation2.FormInlineAnnotation.getFromAst(refProps.ast).pipe(Option2.getOrElse(() => false));
|
|
883
|
+
if (inline && !refProps.isArray) {
|
|
884
|
+
return /* @__PURE__ */ React2.createElement(InlineRefField, {
|
|
885
|
+
...fieldProps,
|
|
886
|
+
...refProps,
|
|
887
|
+
db,
|
|
888
|
+
useType: schemaHook,
|
|
889
|
+
onCreate
|
|
890
|
+
});
|
|
891
|
+
}
|
|
813
892
|
const isCreateTarget = !createTypename || refProps.typename === createTypename;
|
|
814
893
|
return /* @__PURE__ */ React2.createElement(RefField, {
|
|
815
894
|
...fieldProps,
|
|
@@ -819,17 +898,17 @@ var FormField = (props) => {
|
|
|
819
898
|
createInitialValuePath: isCreateTarget ? createInitialValuePath : void 0,
|
|
820
899
|
createFieldMap: isCreateTarget ? createFieldMap3 : void 0,
|
|
821
900
|
db,
|
|
822
|
-
|
|
901
|
+
useType: schemaHook,
|
|
823
902
|
getOptions,
|
|
824
903
|
onCreate
|
|
825
904
|
});
|
|
826
905
|
}
|
|
827
|
-
if (
|
|
906
|
+
if (isNestedType2(type)) {
|
|
828
907
|
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
829
908
|
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST3.isTypeLiteral);
|
|
830
909
|
if (typeLiteral) {
|
|
831
910
|
const schema = Schema.make(typeLiteral);
|
|
832
|
-
return /* @__PURE__ */ React2.createElement(FormFieldSet, {
|
|
911
|
+
return /* @__PURE__ */ React2.createElement(Nesting, null, /* @__PURE__ */ React2.createElement(FormFieldSet, {
|
|
833
912
|
schema,
|
|
834
913
|
path,
|
|
835
914
|
readonly,
|
|
@@ -842,17 +921,33 @@ var FormField = (props) => {
|
|
|
842
921
|
createOptionIcon,
|
|
843
922
|
createInitialValuePath,
|
|
844
923
|
db,
|
|
845
|
-
|
|
924
|
+
useType: schemaHook,
|
|
846
925
|
getOptions,
|
|
847
926
|
onCreate
|
|
848
|
-
});
|
|
927
|
+
}));
|
|
849
928
|
}
|
|
850
929
|
}
|
|
851
930
|
return null;
|
|
852
931
|
};
|
|
853
932
|
FormField.displayName = "Form.FormField";
|
|
933
|
+
var Nesting = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
|
|
934
|
+
className: "px-2 border border-subdued-separator rounded-sm mt-2"
|
|
935
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
936
|
+
className: "pb-2"
|
|
937
|
+
}, children));
|
|
938
|
+
var IconBlock = ({ inline, ...props }) => {
|
|
939
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
940
|
+
className: mx2("h-full flex px-1", inline ? "items-center" : "flex-col pt-2.5")
|
|
941
|
+
}, /* @__PURE__ */ React2.createElement(IconButton, {
|
|
942
|
+
variant: "ghost",
|
|
943
|
+
density: "xs",
|
|
944
|
+
square: true,
|
|
945
|
+
iconOnly: true,
|
|
946
|
+
...props
|
|
947
|
+
}));
|
|
948
|
+
};
|
|
854
949
|
var getFormField = ({ type, format }) => {
|
|
855
|
-
const formatField = Match.value(format).pipe(Match.withReturnType(), Match.when(
|
|
950
|
+
const formatField = Match.value(format).pipe(Match.withReturnType(), Match.when(Format4.TypeFormat.Date, () => DateField), Match.when(Format4.TypeFormat.DateTime, () => DateField), Match.when(Format4.TypeFormat.GeoPoint, () => GeoPointField), Match.when(Format4.TypeFormat.Markdown, () => MarkdownField), Match.when(Format4.TypeFormat.Text, () => TextAreaField), Match.when(Format4.TypeFormat.Time, () => DateField), Match.orElse(() => void 0));
|
|
856
951
|
if (formatField) {
|
|
857
952
|
return formatField;
|
|
858
953
|
}
|
|
@@ -871,12 +966,283 @@ var getSelectOptions = (ast) => {
|
|
|
871
966
|
if (isLiteralUnion2(ast)) {
|
|
872
967
|
return ast.types.map((type) => type.literal).filter((v) => v !== null);
|
|
873
968
|
}
|
|
874
|
-
return
|
|
969
|
+
return Format4.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option2.getOrUndefined(annotation));
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
// src/components/Form/Layout/annotation.ts
|
|
973
|
+
import { createAnnotationHelper } from "@dxos/echo/internal";
|
|
974
|
+
var FormLayoutAnnotationId = /* @__PURE__ */ Symbol.for("@dxos/react-ui-form/annotation/Layout");
|
|
975
|
+
var FormLayoutAnnotation = createAnnotationHelper(FormLayoutAnnotationId);
|
|
976
|
+
var DEFAULT_LAYOUT_NAME = "default";
|
|
977
|
+
|
|
978
|
+
// src/components/Form/Layout/FormLayout.tsx
|
|
979
|
+
import * as Option3 from "effect/Option";
|
|
980
|
+
import * as Schema2 from "effect/Schema";
|
|
981
|
+
import * as SchemaAST4 from "effect/SchemaAST";
|
|
982
|
+
import * as String3 from "effect/String";
|
|
983
|
+
import React3, { Fragment, useMemo as useMemo3 } from "react";
|
|
984
|
+
import { Annotation as Annotation3 } from "@dxos/echo";
|
|
985
|
+
import { createJsonPath as createJsonPath3, findNode as findNode2, getAnnotation as getAnnotation3, getBaseType } from "@dxos/effect";
|
|
986
|
+
import { Input as Input2 } from "@dxos/react-ui";
|
|
987
|
+
|
|
988
|
+
// src/components/Form/Layout/parser.ts
|
|
989
|
+
var LayoutParseError = class extends Error {
|
|
990
|
+
position;
|
|
991
|
+
_tag = "LayoutParseError";
|
|
992
|
+
constructor(message, position) {
|
|
993
|
+
super(position !== void 0 ? `${message} (at position ${position})` : message), this.position = position;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
var TAG_RE = /<\s*(\/?)\s*(\w+)([^>]*?)(\/?)\s*>/g;
|
|
997
|
+
var ATTR_RE = /([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\d+))/g;
|
|
998
|
+
var parseAttrs = (raw) => {
|
|
999
|
+
const attrs = {};
|
|
1000
|
+
ATTR_RE.lastIndex = 0;
|
|
1001
|
+
let match;
|
|
1002
|
+
while ((match = ATTR_RE.exec(raw)) !== null) {
|
|
1003
|
+
const [, key, doubleQuoted, singleQuoted, bare] = match;
|
|
1004
|
+
attrs[key] = doubleQuoted ?? singleQuoted ?? bare;
|
|
1005
|
+
}
|
|
1006
|
+
return attrs;
|
|
1007
|
+
};
|
|
1008
|
+
var tokenize = (input) => {
|
|
1009
|
+
const tokens = [];
|
|
1010
|
+
TAG_RE.lastIndex = 0;
|
|
1011
|
+
let match;
|
|
1012
|
+
let cursor = 0;
|
|
1013
|
+
while ((match = TAG_RE.exec(input)) !== null) {
|
|
1014
|
+
const between = input.slice(cursor, match.index);
|
|
1015
|
+
if (between.trim().length > 0) {
|
|
1016
|
+
throw new LayoutParseError(`unexpected text content: ${JSON.stringify(between.trim())}`, cursor);
|
|
1017
|
+
}
|
|
1018
|
+
const [, slash, name, attrsRaw, selfSlash] = match;
|
|
1019
|
+
if (slash) {
|
|
1020
|
+
tokens.push({
|
|
1021
|
+
type: "close",
|
|
1022
|
+
name,
|
|
1023
|
+
position: match.index
|
|
1024
|
+
});
|
|
1025
|
+
} else {
|
|
1026
|
+
tokens.push({
|
|
1027
|
+
type: "open",
|
|
1028
|
+
name,
|
|
1029
|
+
attrs: parseAttrs(attrsRaw),
|
|
1030
|
+
selfClosing: selfSlash === "/",
|
|
1031
|
+
position: match.index
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
cursor = match.index + match[0].length;
|
|
1035
|
+
}
|
|
1036
|
+
const trailing = input.slice(cursor);
|
|
1037
|
+
if (trailing.trim().length > 0) {
|
|
1038
|
+
throw new LayoutParseError(`unexpected text content: ${JSON.stringify(trailing.trim())}`, cursor);
|
|
1039
|
+
}
|
|
1040
|
+
return tokens;
|
|
1041
|
+
};
|
|
1042
|
+
var requireAttr = (attrs, key, tag, position) => {
|
|
1043
|
+
const value3 = attrs[key];
|
|
1044
|
+
if (value3 === void 0) {
|
|
1045
|
+
throw new LayoutParseError(`<${tag}> missing required attribute "${key}"`, position);
|
|
1046
|
+
}
|
|
1047
|
+
return value3;
|
|
1048
|
+
};
|
|
1049
|
+
var parseInteger = (value3, attr, tag, position) => {
|
|
1050
|
+
if (!/^\d+$/.test(value3)) {
|
|
1051
|
+
throw new LayoutParseError(`<${tag}> attribute "${attr}" expects an integer, got ${JSON.stringify(value3)}`, position);
|
|
1052
|
+
}
|
|
1053
|
+
return Number.parseInt(value3, 10);
|
|
1054
|
+
};
|
|
1055
|
+
var parseLayout = (template) => {
|
|
1056
|
+
const tokens = tokenize(template);
|
|
1057
|
+
if (tokens.length === 0) {
|
|
1058
|
+
throw new LayoutParseError("empty template");
|
|
1059
|
+
}
|
|
1060
|
+
let index = 0;
|
|
1061
|
+
const parseNode = () => {
|
|
1062
|
+
const token = tokens[index];
|
|
1063
|
+
if (!token || token.type !== "open") {
|
|
1064
|
+
throw new LayoutParseError(`expected an opening tag, got ${JSON.stringify(token)}`, token?.position);
|
|
1065
|
+
}
|
|
1066
|
+
if (token.name === "field") {
|
|
1067
|
+
if (!token.selfClosing) {
|
|
1068
|
+
throw new LayoutParseError('<field> must be self-closing (e.g. <field name="x"/>)', token.position);
|
|
1069
|
+
}
|
|
1070
|
+
const name = requireAttr(token.attrs, "name", "field", token.position);
|
|
1071
|
+
const spanRaw = token.attrs.span;
|
|
1072
|
+
const span = spanRaw !== void 0 ? parseInteger(spanRaw, "span", "field", token.position) : void 0;
|
|
1073
|
+
index += 1;
|
|
1074
|
+
return {
|
|
1075
|
+
kind: "field",
|
|
1076
|
+
name,
|
|
1077
|
+
span
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
if (token.name === "grid") {
|
|
1081
|
+
if (token.selfClosing) {
|
|
1082
|
+
throw new LayoutParseError("<grid> must wrap children (cannot self-close)", token.position);
|
|
1083
|
+
}
|
|
1084
|
+
const cols = parseInteger(requireAttr(token.attrs, "cols", "grid", token.position), "cols", "grid", token.position);
|
|
1085
|
+
index += 1;
|
|
1086
|
+
const children = [];
|
|
1087
|
+
while (index < tokens.length && !(tokens[index].type === "close" && tokens[index].name === "grid")) {
|
|
1088
|
+
children.push(parseNode());
|
|
1089
|
+
}
|
|
1090
|
+
const closing = tokens[index];
|
|
1091
|
+
if (!closing || closing.type !== "close" || closing.name !== "grid") {
|
|
1092
|
+
throw new LayoutParseError("<grid> not closed", token.position);
|
|
1093
|
+
}
|
|
1094
|
+
index += 1;
|
|
1095
|
+
return {
|
|
1096
|
+
kind: "grid",
|
|
1097
|
+
cols,
|
|
1098
|
+
children
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
throw new LayoutParseError(`unknown element <${token.name}>`, token.position);
|
|
1102
|
+
};
|
|
1103
|
+
const root = parseNode();
|
|
1104
|
+
if (index !== tokens.length) {
|
|
1105
|
+
const trailing = tokens[index];
|
|
1106
|
+
throw new LayoutParseError(`unexpected trailing tag <${trailing.type === "open" ? "" : "/"}${trailing.name}>`, trailing.position);
|
|
1107
|
+
}
|
|
1108
|
+
if (root.kind !== "grid") {
|
|
1109
|
+
throw new LayoutParseError("root element must be <grid>");
|
|
1110
|
+
}
|
|
1111
|
+
return root;
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
// src/components/Form/Layout/FormLayout.tsx
|
|
1115
|
+
var FORM_LAYOUT_NAME = "Form.Layout";
|
|
1116
|
+
var FormLayout = ({ schema, template, name = DEFAULT_LAYOUT_NAME, path, readonly, layout, projection, ...props }) => {
|
|
1117
|
+
const annotated = Option3.getOrUndefined(FormLayoutAnnotation.get(schema));
|
|
1118
|
+
const source = template ?? annotated?.[name];
|
|
1119
|
+
if (source === void 0) {
|
|
1120
|
+
throw new LayoutParseError(annotated ? `no layout named "${name}" on schema (available: ${Object.keys(annotated).join(", ") || "\u2205"})` : `no template provided and schema has no FormLayoutAnnotation`);
|
|
1121
|
+
}
|
|
1122
|
+
const tree = useMemo3(() => parseLayout(source), [
|
|
1123
|
+
source
|
|
1124
|
+
]);
|
|
1125
|
+
return /* @__PURE__ */ React3.createElement(RenderNode, {
|
|
1126
|
+
node: tree,
|
|
1127
|
+
schema,
|
|
1128
|
+
basePath: path ?? [],
|
|
1129
|
+
readonly,
|
|
1130
|
+
layout,
|
|
1131
|
+
projection,
|
|
1132
|
+
...props
|
|
1133
|
+
});
|
|
1134
|
+
};
|
|
1135
|
+
FormLayout.displayName = FORM_LAYOUT_NAME;
|
|
1136
|
+
var RenderNode = ({ node, schema, basePath, ...props }) => {
|
|
1137
|
+
if (node.kind === "grid") {
|
|
1138
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
1139
|
+
className: "grid gap-x-form-gap",
|
|
1140
|
+
style: {
|
|
1141
|
+
gridTemplateColumns: `repeat(${node.cols}, minmax(0, 1fr))`
|
|
1142
|
+
}
|
|
1143
|
+
}, node.children.map((child, index) => /* @__PURE__ */ React3.createElement(Fragment, {
|
|
1144
|
+
key: index
|
|
1145
|
+
}, /* @__PURE__ */ React3.createElement(RenderNode, {
|
|
1146
|
+
node: child,
|
|
1147
|
+
schema,
|
|
1148
|
+
basePath,
|
|
1149
|
+
...props
|
|
1150
|
+
}))));
|
|
1151
|
+
}
|
|
1152
|
+
const resolved = resolveLayoutField(schema, node.name);
|
|
1153
|
+
if (!resolved) {
|
|
1154
|
+
throw new LayoutParseError(`field "${node.name}" not found on schema`);
|
|
1155
|
+
}
|
|
1156
|
+
const { type, segments, leafName, title, labelType } = resolved;
|
|
1157
|
+
const path = [
|
|
1158
|
+
...basePath,
|
|
1159
|
+
...segments
|
|
1160
|
+
];
|
|
1161
|
+
const span = node.span ? {
|
|
1162
|
+
gridColumn: `span ${node.span} / span ${node.span}`
|
|
1163
|
+
} : void 0;
|
|
1164
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
1165
|
+
className: "min-w-0",
|
|
1166
|
+
style: span
|
|
1167
|
+
}, /* @__PURE__ */ React3.createElement(FormFieldErrorBoundary, {
|
|
1168
|
+
path
|
|
1169
|
+
}, labelType ? /* @__PURE__ */ React3.createElement(LabelField, {
|
|
1170
|
+
schema: Schema2.make(labelType),
|
|
1171
|
+
label: title ?? String3.capitalize(leafName),
|
|
1172
|
+
path,
|
|
1173
|
+
layout: props.layout
|
|
1174
|
+
}) : /* @__PURE__ */ React3.createElement(FormField, {
|
|
1175
|
+
type,
|
|
1176
|
+
name: leafName,
|
|
1177
|
+
path,
|
|
1178
|
+
...props
|
|
1179
|
+
})));
|
|
1180
|
+
};
|
|
1181
|
+
var resolvePropertySignature = (ast, segments) => {
|
|
1182
|
+
let node = ast;
|
|
1183
|
+
for (let index = 0; index < segments.length; index++) {
|
|
1184
|
+
const typeLiteral = findNode2(node, SchemaAST4.isTypeLiteral);
|
|
1185
|
+
if (!typeLiteral) {
|
|
1186
|
+
return void 0;
|
|
1187
|
+
}
|
|
1188
|
+
const prop = SchemaAST4.getPropertySignatures(typeLiteral).find((p) => globalThis.String(p.name) === segments[index]);
|
|
1189
|
+
if (!prop) {
|
|
1190
|
+
return void 0;
|
|
1191
|
+
}
|
|
1192
|
+
if (index === segments.length - 1) {
|
|
1193
|
+
return prop;
|
|
1194
|
+
}
|
|
1195
|
+
node = prop.type;
|
|
1196
|
+
}
|
|
1197
|
+
return void 0;
|
|
1198
|
+
};
|
|
1199
|
+
var resolveLayoutField = (schema, name) => {
|
|
1200
|
+
const segments = name.split(".");
|
|
1201
|
+
const prop = resolvePropertySignature(schema.ast, segments);
|
|
1202
|
+
if (!prop) {
|
|
1203
|
+
return void 0;
|
|
1204
|
+
}
|
|
1205
|
+
const { type: baseType } = getBaseType(prop);
|
|
1206
|
+
const type = prop.annotations && Reflect.ownKeys(prop.annotations).length > 0 ? {
|
|
1207
|
+
...baseType,
|
|
1208
|
+
annotations: {
|
|
1209
|
+
...baseType.annotations,
|
|
1210
|
+
...prop.annotations
|
|
1211
|
+
}
|
|
1212
|
+
} : baseType;
|
|
1213
|
+
const title = getAnnotation3(SchemaAST4.TitleAnnotationId)(type);
|
|
1214
|
+
const labelType = findNode2(prop.type, SchemaAST4.isTypeLiteral);
|
|
1215
|
+
const labelled = labelType != null && Option3.isSome(Annotation3.LabelAnnotation.getFromAst(labelType));
|
|
1216
|
+
return {
|
|
1217
|
+
type,
|
|
1218
|
+
segments,
|
|
1219
|
+
leafName: segments[segments.length - 1],
|
|
1220
|
+
title,
|
|
1221
|
+
labelType: labelled ? labelType : void 0
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1224
|
+
var LabelField = ({ schema, label, path, layout }) => {
|
|
1225
|
+
const { getValue } = useFormFieldState(FORM_LAYOUT_NAME, path);
|
|
1226
|
+
const value3 = getValue();
|
|
1227
|
+
const text = value3 == null ? void 0 : Annotation3.getLabelWithSchema(schema, value3);
|
|
1228
|
+
if (text == null || text.trim().length === 0) {
|
|
1229
|
+
return null;
|
|
1230
|
+
}
|
|
1231
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
1232
|
+
className: "contents"
|
|
1233
|
+
}, /* @__PURE__ */ React3.createElement(Input2.Root, null, layout !== "inline" && /* @__PURE__ */ React3.createElement(FormFieldLabel, {
|
|
1234
|
+
readonly: true,
|
|
1235
|
+
label,
|
|
1236
|
+
path: createJsonPath3(path)
|
|
1237
|
+
}), /* @__PURE__ */ React3.createElement("p", {
|
|
1238
|
+
className: "truncate min-w-0",
|
|
1239
|
+
title: text
|
|
1240
|
+
}, text)));
|
|
875
1241
|
};
|
|
876
1242
|
|
|
877
1243
|
// src/components/Form/FormFieldSet.tsx
|
|
878
1244
|
var FORM_FIELDSET_NAME = "Form.FieldSet";
|
|
879
|
-
var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection, layout, ...props }) => {
|
|
1245
|
+
var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection, layout, layoutName = DEFAULT_LAYOUT_NAME, ...props }) => {
|
|
880
1246
|
const values = useFormValues(FORM_FIELDSET_NAME, path);
|
|
881
1247
|
const properties = useFormFieldSetProperties({
|
|
882
1248
|
schema,
|
|
@@ -888,18 +1254,35 @@ var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection,
|
|
|
888
1254
|
if ((readonly || layout === "static") && values == null) {
|
|
889
1255
|
return null;
|
|
890
1256
|
}
|
|
891
|
-
|
|
1257
|
+
const layouts = schema ? Option4.getOrUndefined(FormLayoutAnnotation.get(schema)) : void 0;
|
|
1258
|
+
if (layouts?.[layoutName] !== void 0 && schema) {
|
|
1259
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, layout !== "inline" && label && /* @__PURE__ */ React4.createElement(FormFieldLabel, {
|
|
1260
|
+
label,
|
|
1261
|
+
path: createJsonPath4(path ?? []),
|
|
1262
|
+
asChild: true
|
|
1263
|
+
}), /* @__PURE__ */ React4.createElement(FormLayout, {
|
|
1264
|
+
schema,
|
|
1265
|
+
name: layoutName,
|
|
1266
|
+
path,
|
|
1267
|
+
readonly,
|
|
1268
|
+
layout,
|
|
1269
|
+
projection,
|
|
1270
|
+
...props
|
|
1271
|
+
}));
|
|
1272
|
+
}
|
|
1273
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, layout !== "inline" && label && /* @__PURE__ */ React4.createElement(FormFieldLabel, {
|
|
892
1274
|
label,
|
|
1275
|
+
path: createJsonPath4(path ?? []),
|
|
893
1276
|
asChild: true
|
|
894
1277
|
}), properties.map((property) => {
|
|
895
1278
|
const name = property.name.toString();
|
|
896
|
-
return /* @__PURE__ */
|
|
1279
|
+
return /* @__PURE__ */ React4.createElement(FormFieldErrorBoundary, {
|
|
897
1280
|
key: name,
|
|
898
1281
|
path: [
|
|
899
1282
|
...path ?? [],
|
|
900
1283
|
name
|
|
901
1284
|
]
|
|
902
|
-
}, /* @__PURE__ */
|
|
1285
|
+
}, /* @__PURE__ */ React4.createElement(FormField, {
|
|
903
1286
|
type: property.type,
|
|
904
1287
|
name,
|
|
905
1288
|
path: [
|
|
@@ -915,7 +1298,7 @@ var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection,
|
|
|
915
1298
|
};
|
|
916
1299
|
FormFieldSet.displayName = FORM_FIELDSET_NAME;
|
|
917
1300
|
var useFormFieldSetProperties = ({ schema, exclude, projection, values, sort }) => {
|
|
918
|
-
return
|
|
1301
|
+
return useMemo4(() => {
|
|
919
1302
|
if (!schema) {
|
|
920
1303
|
return [];
|
|
921
1304
|
}
|
|
@@ -951,25 +1334,28 @@ var useFormFieldSetProperties = ({ schema, exclude, projection, values, sort })
|
|
|
951
1334
|
};
|
|
952
1335
|
|
|
953
1336
|
// src/components/Form/Form.tsx
|
|
954
|
-
var omitId = (
|
|
1337
|
+
var omitId = (schemaOrType) => {
|
|
1338
|
+
const schema = Type.isType(schemaOrType) ? Type.getSchema(schemaOrType) : schemaOrType;
|
|
1339
|
+
return schema.pipe(Schema3.omit("id"));
|
|
1340
|
+
};
|
|
955
1341
|
var omitHiddenFormFields = (schema) => {
|
|
956
|
-
const properties =
|
|
957
|
-
const hidden = properties.filter((prop) =>
|
|
958
|
-
return hidden.length === 0 ? schema : schema.pipe(
|
|
1342
|
+
const properties = SchemaAST5.getPropertySignatures(schema.ast);
|
|
1343
|
+
const hidden = properties.filter((prop) => Option5.getOrElse(EchoAnnotation.FormInputAnnotation.getFromAst(prop.type), () => true) === false).map((prop) => prop.name);
|
|
1344
|
+
return hidden.length === 0 ? schema : schema.pipe(Schema3.omit(...hidden));
|
|
959
1345
|
};
|
|
960
|
-
var [FormContextProvider, useFormContext] =
|
|
1346
|
+
var [FormContextProvider, useFormContext] = createContext2("Form");
|
|
961
1347
|
var useFormValues = (componentName, path, defaultValue) => {
|
|
962
|
-
const stablePath =
|
|
1348
|
+
const stablePath = useMemo5(() => path ?? [], [
|
|
963
1349
|
path ? path.join(".") : void 0
|
|
964
1350
|
]);
|
|
965
|
-
const jsonPath =
|
|
1351
|
+
const jsonPath = createJsonPath5(stablePath);
|
|
966
1352
|
const { form: { values, onValueChange } } = useFormContext(componentName);
|
|
967
1353
|
const value3 = getValue$2(values, jsonPath);
|
|
968
1354
|
const lastAppliedPathRef = useRef(null);
|
|
969
1355
|
useEffect2(() => {
|
|
970
1356
|
if (value3 == null && defaultValue && lastAppliedPathRef.current !== jsonPath) {
|
|
971
1357
|
lastAppliedPathRef.current = jsonPath;
|
|
972
|
-
onValueChange(stablePath,
|
|
1358
|
+
onValueChange(stablePath, SchemaAST5.stringKeyword, defaultValue());
|
|
973
1359
|
}
|
|
974
1360
|
}, [
|
|
975
1361
|
value3,
|
|
@@ -981,11 +1367,11 @@ var useFormValues = (componentName, path, defaultValue) => {
|
|
|
981
1367
|
return value3;
|
|
982
1368
|
};
|
|
983
1369
|
var useFormFieldState = (componentName, path = []) => {
|
|
984
|
-
const stablePath =
|
|
1370
|
+
const stablePath = useMemo5(() => path, [
|
|
985
1371
|
Array.isArray(path) ? path.join(".") : path
|
|
986
1372
|
]);
|
|
987
1373
|
const { form: { getStatus, getValue, onBlur, onValueChange } } = useFormContext(componentName);
|
|
988
|
-
return
|
|
1374
|
+
return useMemo5(() => ({
|
|
989
1375
|
getStatus: () => getStatus(stablePath),
|
|
990
1376
|
getValue: () => getValue(stablePath),
|
|
991
1377
|
onBlur: () => onBlur(stablePath),
|
|
@@ -1006,22 +1392,42 @@ var FormRoot = ({ children, schema, values, onSave, onCancel, ...props }) => {
|
|
|
1006
1392
|
onCancel,
|
|
1007
1393
|
...props
|
|
1008
1394
|
});
|
|
1009
|
-
return /* @__PURE__ */
|
|
1395
|
+
return /* @__PURE__ */ React5.createElement(FormTooltipsContext.Provider, {
|
|
1396
|
+
value: props.tooltips ?? true
|
|
1397
|
+
}, /* @__PURE__ */ React5.createElement(FormContextProvider, {
|
|
1010
1398
|
form,
|
|
1011
1399
|
...props
|
|
1012
|
-
}, children);
|
|
1400
|
+
}, children));
|
|
1013
1401
|
};
|
|
1014
1402
|
FormRoot.displayName = "Form.Root";
|
|
1015
1403
|
var FORM_VIEWPORT_NAME = "Form.Viewport";
|
|
1016
|
-
var FormViewport = composable(({ children, ...props }, forwardedRef) => {
|
|
1017
|
-
|
|
1404
|
+
var FormViewport = composable(({ children, scroll, gutter = "sm", ...props }, forwardedRef) => {
|
|
1405
|
+
const span = "[.dx-column-root_&]:col-span-full";
|
|
1406
|
+
if (scroll) {
|
|
1407
|
+
return /* @__PURE__ */ React5.createElement(Column.Root, {
|
|
1408
|
+
gutter,
|
|
1409
|
+
classNames: [
|
|
1410
|
+
"dx-expander",
|
|
1411
|
+
span
|
|
1412
|
+
]
|
|
1413
|
+
}, /* @__PURE__ */ React5.createElement(ScrollArea.Root, {
|
|
1414
|
+
...composableProps(props),
|
|
1415
|
+
orientation: "vertical",
|
|
1416
|
+
centered: true,
|
|
1417
|
+
padding: true,
|
|
1418
|
+
thin: true,
|
|
1419
|
+
ref: forwardedRef
|
|
1420
|
+
}, /* @__PURE__ */ React5.createElement(ScrollArea.Viewport, null, children)));
|
|
1421
|
+
}
|
|
1422
|
+
return /* @__PURE__ */ React5.createElement(Column.Root, {
|
|
1018
1423
|
...composableProps(props),
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1424
|
+
gutter,
|
|
1425
|
+
classNames: [
|
|
1426
|
+
"w-full min-w-0",
|
|
1427
|
+
span
|
|
1428
|
+
],
|
|
1023
1429
|
ref: forwardedRef
|
|
1024
|
-
},
|
|
1430
|
+
}, children);
|
|
1025
1431
|
});
|
|
1026
1432
|
FormViewport.displayName = FORM_VIEWPORT_NAME;
|
|
1027
1433
|
var FORM_CONTENT_NAME = "Form.Content";
|
|
@@ -1033,10 +1439,10 @@ var FormContent = composable(({ children, ...props }, forwardedRef) => {
|
|
|
1033
1439
|
localRef
|
|
1034
1440
|
]);
|
|
1035
1441
|
useKeyHandler(localRef, form);
|
|
1036
|
-
return /* @__PURE__ */
|
|
1442
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1037
1443
|
...composableProps(props, {
|
|
1038
1444
|
role: "form",
|
|
1039
|
-
classNames:
|
|
1445
|
+
classNames: mx3(withColumn.center(), "flex flex-col w-full")
|
|
1040
1446
|
}),
|
|
1041
1447
|
"data-testid": testId,
|
|
1042
1448
|
ref: mergedRef
|
|
@@ -1046,13 +1452,27 @@ FormContent.displayName = FORM_CONTENT_NAME;
|
|
|
1046
1452
|
var FORM_FIELDSET_NAME2 = "Form.FieldSet";
|
|
1047
1453
|
var FormFieldSet2 = (props) => {
|
|
1048
1454
|
const { form, ...contextProps } = useFormContext(FORM_FIELDSET_NAME2);
|
|
1049
|
-
return /* @__PURE__ */
|
|
1455
|
+
return /* @__PURE__ */ React5.createElement(FormFieldSet, {
|
|
1050
1456
|
schema: form.schema,
|
|
1051
1457
|
...contextProps,
|
|
1052
1458
|
...props
|
|
1053
1459
|
});
|
|
1054
1460
|
};
|
|
1055
1461
|
FormFieldSet2.displayName = FORM_FIELDSET_NAME2;
|
|
1462
|
+
var FORM_LAYOUT_NAME2 = "Form.Layout";
|
|
1463
|
+
var FormLayout2 = ({ schema, ...props }) => {
|
|
1464
|
+
const { form, ...contextProps } = useFormContext(FORM_LAYOUT_NAME2);
|
|
1465
|
+
const resolvedSchema = schema ?? form.schema;
|
|
1466
|
+
if (!resolvedSchema) {
|
|
1467
|
+
return null;
|
|
1468
|
+
}
|
|
1469
|
+
return /* @__PURE__ */ React5.createElement(FormLayout, {
|
|
1470
|
+
schema: resolvedSchema,
|
|
1471
|
+
...contextProps,
|
|
1472
|
+
...props
|
|
1473
|
+
});
|
|
1474
|
+
};
|
|
1475
|
+
FormLayout2.displayName = FORM_LAYOUT_NAME2;
|
|
1056
1476
|
var FORM_ACTIONS_NAME = "Form.Actions";
|
|
1057
1477
|
var FormActions = ({ classNames }) => {
|
|
1058
1478
|
const { t } = useTranslation2(translationKey2);
|
|
@@ -1060,15 +1480,15 @@ var FormActions = ({ classNames }) => {
|
|
|
1060
1480
|
if (readonly || layout === "static") {
|
|
1061
1481
|
return null;
|
|
1062
1482
|
}
|
|
1063
|
-
return /* @__PURE__ */
|
|
1064
|
-
className:
|
|
1065
|
-
}, onCancel && /* @__PURE__ */
|
|
1483
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1484
|
+
className: mx3(withColumn.center(), "grid grid-flow-col gap-form-gap auto-cols-fr py-form-padding", classNames)
|
|
1485
|
+
}, onCancel && /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1066
1486
|
icon: "ph--x--regular",
|
|
1067
1487
|
iconEnd: true,
|
|
1068
1488
|
label: t("cancel-button.label"),
|
|
1069
1489
|
onClick: onCancel,
|
|
1070
1490
|
"data-testid": "cancel-button"
|
|
1071
|
-
}), onSave && /* @__PURE__ */
|
|
1491
|
+
}), onSave && /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1072
1492
|
type: "submit",
|
|
1073
1493
|
variant: "primary",
|
|
1074
1494
|
disabled: !canSave,
|
|
@@ -1082,14 +1502,14 @@ var FormActions = ({ classNames }) => {
|
|
|
1082
1502
|
FormActions.displayName = FORM_ACTIONS_NAME;
|
|
1083
1503
|
var FORM_SECTION_NAME = "Form.Section";
|
|
1084
1504
|
var FormSection = composable(({ children, label, description, ...props }, forwardedRef) => {
|
|
1085
|
-
return /* @__PURE__ */
|
|
1505
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1086
1506
|
...composableProps(props, {
|
|
1087
1507
|
classNames: "flex flex-col pt-form-section-gap first:pt-0"
|
|
1088
1508
|
}),
|
|
1089
1509
|
ref: forwardedRef
|
|
1090
|
-
}, label && /* @__PURE__ */
|
|
1510
|
+
}, label && /* @__PURE__ */ React5.createElement("h2", {
|
|
1091
1511
|
className: "text-lg"
|
|
1092
|
-
}, label), description && /* @__PURE__ */
|
|
1512
|
+
}, label), description && /* @__PURE__ */ React5.createElement("p", {
|
|
1093
1513
|
className: "text-description"
|
|
1094
1514
|
}, description), children);
|
|
1095
1515
|
});
|
|
@@ -1101,9 +1521,9 @@ var FormSubmit = ({ classNames, label, icon, disabled }) => {
|
|
|
1101
1521
|
if (readonly || layout === "static") {
|
|
1102
1522
|
return null;
|
|
1103
1523
|
}
|
|
1104
|
-
return /* @__PURE__ */
|
|
1105
|
-
className:
|
|
1106
|
-
}, /* @__PURE__ */
|
|
1524
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1525
|
+
className: mx3("flex w-full pt-form-padding", classNames)
|
|
1526
|
+
}, /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1107
1527
|
classNames: "w-full",
|
|
1108
1528
|
type: "submit",
|
|
1109
1529
|
variant: "primary",
|
|
@@ -1115,15 +1535,29 @@ var FormSubmit = ({ classNames, label, icon, disabled }) => {
|
|
|
1115
1535
|
}));
|
|
1116
1536
|
};
|
|
1117
1537
|
FormSubmit.displayName = FORM_SUBMIT_NAME;
|
|
1538
|
+
var FORM_ERROR_NAME = "Form.Error";
|
|
1539
|
+
var FormError = ({ children, classNames }) => {
|
|
1540
|
+
if (!children) {
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
return /* @__PURE__ */ React5.createElement(Input3.Root, {
|
|
1544
|
+
validationValence: "error"
|
|
1545
|
+
}, /* @__PURE__ */ React5.createElement(Input3.Validation, {
|
|
1546
|
+
classNames
|
|
1547
|
+
}, children));
|
|
1548
|
+
};
|
|
1549
|
+
FormError.displayName = FORM_ERROR_NAME;
|
|
1118
1550
|
var Form = {
|
|
1119
1551
|
Root: FormRoot,
|
|
1120
1552
|
Viewport: FormViewport,
|
|
1121
1553
|
Content: FormContent,
|
|
1122
1554
|
Section: FormSection,
|
|
1123
1555
|
FieldSet: FormFieldSet2,
|
|
1556
|
+
Layout: FormLayout2,
|
|
1124
1557
|
Label: FormFieldLabel,
|
|
1125
1558
|
Actions: FormActions,
|
|
1126
|
-
Submit: FormSubmit
|
|
1559
|
+
Submit: FormSubmit,
|
|
1560
|
+
Error: FormError
|
|
1127
1561
|
};
|
|
1128
1562
|
|
|
1129
1563
|
// src/components/Form/fields/ArrayField.tsx
|
|
@@ -1133,13 +1567,13 @@ var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps,
|
|
|
1133
1567
|
const { onValueChange } = inputProps;
|
|
1134
1568
|
const values = useFormValues(ArrayField.displayName, path, () => []);
|
|
1135
1569
|
const getDefaultObjectValue = (typeNode) => {
|
|
1136
|
-
const baseNode =
|
|
1137
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) :
|
|
1570
|
+
const baseNode = findNode3(typeNode, isDiscriminatedUnion2);
|
|
1571
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode3(typeNode, SchemaAST6.isTypeLiteral);
|
|
1138
1572
|
if (!typeLiteral) {
|
|
1139
1573
|
return {};
|
|
1140
1574
|
}
|
|
1141
1575
|
return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
|
|
1142
|
-
const defaultValue =
|
|
1576
|
+
const defaultValue = SchemaAST6.getDefaultAnnotation(prop.type).pipe((annotation) => Option6.getOrUndefined(annotation));
|
|
1143
1577
|
return [
|
|
1144
1578
|
prop.name,
|
|
1145
1579
|
defaultValue
|
|
@@ -1147,9 +1581,9 @@ var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps,
|
|
|
1147
1581
|
}));
|
|
1148
1582
|
};
|
|
1149
1583
|
const handleAdd = useCallback3(() => {
|
|
1150
|
-
const defaultValue =
|
|
1151
|
-
|
|
1152
|
-
...values,
|
|
1584
|
+
const defaultValue = isNestedType3(type) && elementType ? getDefaultObjectValue(elementType) : getDefaultValue(elementType);
|
|
1585
|
+
onValueChange(type, [
|
|
1586
|
+
...values ?? [],
|
|
1153
1587
|
defaultValue
|
|
1154
1588
|
]);
|
|
1155
1589
|
}, [
|
|
@@ -1168,43 +1602,49 @@ var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps,
|
|
|
1168
1602
|
if (!elementType || (readonly || layout === "static") && values && values.length < 1) {
|
|
1169
1603
|
return null;
|
|
1170
1604
|
}
|
|
1171
|
-
|
|
1605
|
+
const renderItemAsObject = elementType && isNestedType3(elementType) && !Ref2.isRefType(elementType);
|
|
1606
|
+
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, (layout !== "static" || values && values.length > 0) && /* @__PURE__ */ React6.createElement("div", {
|
|
1607
|
+
className: "flex items-center gap-2"
|
|
1608
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
1609
|
+
className: "flex-1 min-w-0"
|
|
1610
|
+
}, /* @__PURE__ */ React6.createElement(FormFieldLabel, {
|
|
1172
1611
|
readonly,
|
|
1173
1612
|
label,
|
|
1613
|
+
path: createJsonPath6(path ?? []),
|
|
1174
1614
|
asChild: true
|
|
1175
|
-
}), /* @__PURE__ */
|
|
1176
|
-
|
|
1615
|
+
})), !readonly && layout !== "static" && /* @__PURE__ */ React6.createElement(IconBlock, {
|
|
1616
|
+
inline: true,
|
|
1617
|
+
icon: "ph--plus--regular",
|
|
1618
|
+
label: t("add-item.button"),
|
|
1619
|
+
onClick: handleAdd
|
|
1620
|
+
})), /* @__PURE__ */ React6.createElement("div", {
|
|
1621
|
+
className: "flex flex-col"
|
|
1177
1622
|
}, values?.map((_, index) => {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
autoFocus: index === values.length - 1,
|
|
1623
|
+
const isLast = index === values.length - 1;
|
|
1624
|
+
const fieldField = /* @__PURE__ */ React6.createElement(FormField, {
|
|
1625
|
+
...props,
|
|
1626
|
+
autoFocus: isLast,
|
|
1183
1627
|
type: elementType,
|
|
1628
|
+
...renderItemAsObject && {
|
|
1629
|
+
name: null
|
|
1630
|
+
},
|
|
1184
1631
|
path: [
|
|
1185
1632
|
...path ?? [],
|
|
1186
1633
|
index
|
|
1187
1634
|
],
|
|
1188
1635
|
readonly: readonly || layout === "static",
|
|
1189
|
-
layout: "inline"
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1636
|
+
layout: renderItemAsObject ? layout === "static" ? "static" : void 0 : "inline"
|
|
1637
|
+
});
|
|
1638
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
1639
|
+
key: index,
|
|
1640
|
+
className: "grid grid-cols-[1fr_min-content] items-center mb-1 last:mb-form-gap"
|
|
1641
|
+
}, fieldField, !readonly && layout !== "static" && /* @__PURE__ */ React6.createElement(IconBlock, {
|
|
1642
|
+
inline: !renderItemAsObject,
|
|
1196
1643
|
icon: "ph--x--regular",
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
}))));
|
|
1202
|
-
})), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1203
|
-
classNames: "flex w-full",
|
|
1204
|
-
icon: "ph--plus--regular",
|
|
1205
|
-
label: t("add-item.button"),
|
|
1206
|
-
onClick: handleAdd
|
|
1207
|
-
}));
|
|
1644
|
+
label: t("remove-item.button"),
|
|
1645
|
+
onClick: () => handleDelete(index)
|
|
1646
|
+
}));
|
|
1647
|
+
})));
|
|
1208
1648
|
};
|
|
1209
1649
|
ArrayField.displayName = "Form.ArrayField";
|
|
1210
1650
|
var getDefaultValue = (ast) => {
|
|
@@ -1222,7 +1662,7 @@ var getDefaultValue = (ast) => {
|
|
|
1222
1662
|
return getDefaultValue(ast.f());
|
|
1223
1663
|
}
|
|
1224
1664
|
default: {
|
|
1225
|
-
if (ast &&
|
|
1665
|
+
if (ast && isNestedType3(ast)) {
|
|
1226
1666
|
return {};
|
|
1227
1667
|
} else {
|
|
1228
1668
|
throw new Error(`Unsupported type: ${ast?._tag}`);
|
|
@@ -1232,39 +1672,112 @@ var getDefaultValue = (ast) => {
|
|
|
1232
1672
|
};
|
|
1233
1673
|
|
|
1234
1674
|
// src/components/Form/fields/BooleanField.tsx
|
|
1235
|
-
import
|
|
1236
|
-
import { Input as
|
|
1675
|
+
import React7, { useCallback as useCallback4 } from "react";
|
|
1676
|
+
import { Input as Input4 } from "@dxos/react-ui";
|
|
1237
1677
|
var BooleanField = ({ type, readonly, onValueChange, ...props }) => {
|
|
1238
1678
|
const handleChange = useCallback4((value3) => onValueChange?.(type, value3), [
|
|
1239
1679
|
type,
|
|
1240
1680
|
onValueChange
|
|
1241
1681
|
]);
|
|
1242
|
-
return /* @__PURE__ */
|
|
1682
|
+
return /* @__PURE__ */ React7.createElement(FormFieldWrapper, {
|
|
1243
1683
|
readonly,
|
|
1244
1684
|
...props
|
|
1245
|
-
}, ({ value: value3 }) => /* @__PURE__ */
|
|
1685
|
+
}, ({ value: value3 }) => /* @__PURE__ */ React7.createElement(Input4.Switch, {
|
|
1246
1686
|
disabled: !!readonly,
|
|
1247
1687
|
checked: value3,
|
|
1248
1688
|
onCheckedChange: handleChange
|
|
1249
1689
|
}));
|
|
1250
1690
|
};
|
|
1251
1691
|
|
|
1692
|
+
// src/components/Form/fields/DateField.tsx
|
|
1693
|
+
import { format as formatDate3 } from "date-fns";
|
|
1694
|
+
import React8, { useCallback as useCallback5 } from "react";
|
|
1695
|
+
import { Format as Format5 } from "@dxos/echo";
|
|
1696
|
+
import { Input as Input5 } from "@dxos/react-ui";
|
|
1697
|
+
var isoToLocalDateTime = (value3) => {
|
|
1698
|
+
if (!value3) {
|
|
1699
|
+
return "";
|
|
1700
|
+
}
|
|
1701
|
+
const date = new Date(value3);
|
|
1702
|
+
if (Number.isNaN(date.getTime())) {
|
|
1703
|
+
return "";
|
|
1704
|
+
}
|
|
1705
|
+
return formatDate3(date, "yyyy-MM-dd'T'HH:mm");
|
|
1706
|
+
};
|
|
1707
|
+
var localDateTimeToIso = (value3) => {
|
|
1708
|
+
if (!value3) {
|
|
1709
|
+
return void 0;
|
|
1710
|
+
}
|
|
1711
|
+
const date = new Date(value3);
|
|
1712
|
+
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
1713
|
+
};
|
|
1714
|
+
var DateField = ({ type, format, readonly, placeholder: _placeholder, onValueChange, onBlur: _onBlur, ...props }) => {
|
|
1715
|
+
const handleSimpleChange = useCallback5((next) => onValueChange(type, next), [
|
|
1716
|
+
type,
|
|
1717
|
+
onValueChange
|
|
1718
|
+
]);
|
|
1719
|
+
const handleDateTimeChange = useCallback5((next) => {
|
|
1720
|
+
const iso = localDateTimeToIso(next);
|
|
1721
|
+
onValueChange(type, iso);
|
|
1722
|
+
}, [
|
|
1723
|
+
type,
|
|
1724
|
+
onValueChange
|
|
1725
|
+
]);
|
|
1726
|
+
return /* @__PURE__ */ React8.createElement(FormFieldWrapper, {
|
|
1727
|
+
readonly,
|
|
1728
|
+
format,
|
|
1729
|
+
...props
|
|
1730
|
+
}, ({ value: value3 }) => {
|
|
1731
|
+
switch (format) {
|
|
1732
|
+
case Format5.TypeFormat.Date:
|
|
1733
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
1734
|
+
className: "grid grid-cols-[minmax(0,1fr)_min-content] items-stretch gap-1"
|
|
1735
|
+
}, /* @__PURE__ */ React8.createElement(Input5.Date, {
|
|
1736
|
+
classNames: "min-w-0 overflow-hidden",
|
|
1737
|
+
disabled: !!readonly,
|
|
1738
|
+
value: value3 ?? "",
|
|
1739
|
+
onValueChange: handleSimpleChange
|
|
1740
|
+
}), /* @__PURE__ */ React8.createElement(Input5.TriggerIcon, {
|
|
1741
|
+
classNames: "h-full"
|
|
1742
|
+
}));
|
|
1743
|
+
case Format5.TypeFormat.Time:
|
|
1744
|
+
return /* @__PURE__ */ React8.createElement(Input5.Time, {
|
|
1745
|
+
disabled: !!readonly,
|
|
1746
|
+
value: value3 ?? "",
|
|
1747
|
+
onValueChange: handleSimpleChange
|
|
1748
|
+
});
|
|
1749
|
+
case Format5.TypeFormat.DateTime:
|
|
1750
|
+
default:
|
|
1751
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
1752
|
+
className: "grid grid-cols-[minmax(0,1fr)_min-content] items-stretch gap-1"
|
|
1753
|
+
}, /* @__PURE__ */ React8.createElement(Input5.DateTime, {
|
|
1754
|
+
classNames: "min-w-0 overflow-hidden",
|
|
1755
|
+
disabled: !!readonly,
|
|
1756
|
+
value: isoToLocalDateTime(value3),
|
|
1757
|
+
onValueChange: handleDateTimeChange
|
|
1758
|
+
}), /* @__PURE__ */ React8.createElement(Input5.TriggerIcon, {
|
|
1759
|
+
classNames: "h-full"
|
|
1760
|
+
}));
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1252
1765
|
// src/components/Form/fields/GeoPointField.tsx
|
|
1253
|
-
import
|
|
1766
|
+
import React9, { useCallback as useCallback6, useEffect as useEffect3, useMemo as useMemo6, useState as useState2 } from "react";
|
|
1254
1767
|
import { GeoLocation as GeoLocation3 } from "@dxos/echo/internal";
|
|
1255
|
-
import { Input as
|
|
1768
|
+
import { Input as Input6, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
1256
1769
|
import { safeParseFloat } from "@dxos/util";
|
|
1257
1770
|
import { translationKey as translationKey4 } from "#translations";
|
|
1258
|
-
var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1771
|
+
var GeoPointField = ({ type, label, jsonPath, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1259
1772
|
const { t } = useTranslation4(translationKey4);
|
|
1260
1773
|
const { status, error } = getStatus();
|
|
1261
|
-
const geoPoint =
|
|
1774
|
+
const geoPoint = useMemo6(() => getValue() ?? [
|
|
1262
1775
|
0,
|
|
1263
1776
|
0
|
|
1264
1777
|
], [
|
|
1265
1778
|
getValue
|
|
1266
1779
|
]);
|
|
1267
|
-
const value3 =
|
|
1780
|
+
const value3 = useMemo6(() => GeoLocation3.fromGeoPoint(geoPoint), [
|
|
1268
1781
|
geoPoint
|
|
1269
1782
|
]);
|
|
1270
1783
|
const [longitudeText, setLongitudeText] = useState2(value3.longitude?.toString());
|
|
@@ -1276,7 +1789,7 @@ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onVal
|
|
|
1276
1789
|
}, [
|
|
1277
1790
|
geoPoint
|
|
1278
1791
|
]);
|
|
1279
|
-
const handleChange =
|
|
1792
|
+
const handleChange = useCallback6((coordinateType, setText) => (event) => {
|
|
1280
1793
|
const inputText = event.target.value;
|
|
1281
1794
|
setText(inputText);
|
|
1282
1795
|
if (inputText !== "" && inputText !== "-") {
|
|
@@ -1302,16 +1815,17 @@ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onVal
|
|
|
1302
1815
|
if ((readonly || layout === "static") && !value3?.latitude && !value3?.longitude) {
|
|
1303
1816
|
return null;
|
|
1304
1817
|
}
|
|
1305
|
-
return /* @__PURE__ */
|
|
1818
|
+
return /* @__PURE__ */ React9.createElement(Input6.Root, {
|
|
1306
1819
|
validationValence: status
|
|
1307
|
-
}, layout !== "inline" && /* @__PURE__ */
|
|
1820
|
+
}, layout !== "inline" && /* @__PURE__ */ React9.createElement(FormFieldLabel, {
|
|
1308
1821
|
error,
|
|
1309
1822
|
readonly,
|
|
1310
1823
|
label,
|
|
1824
|
+
path: jsonPath,
|
|
1311
1825
|
asChild: true
|
|
1312
|
-
}), layout === "static" ? /* @__PURE__ */
|
|
1826
|
+
}), layout === "static" ? /* @__PURE__ */ React9.createElement(LatLng, value3) : /* @__PURE__ */ React9.createElement("div", {
|
|
1313
1827
|
className: "grid grid-cols-2 gap-form-gap"
|
|
1314
|
-
}, /* @__PURE__ */
|
|
1828
|
+
}, /* @__PURE__ */ React9.createElement("div", null, /* @__PURE__ */ React9.createElement(Input6.Root, null, layout !== "inline" && /* @__PURE__ */ React9.createElement(Input6.Label, null, t("latitude.label")), /* @__PURE__ */ React9.createElement(Input6.TextInput, {
|
|
1315
1829
|
type: "number",
|
|
1316
1830
|
step: "0.00001",
|
|
1317
1831
|
min: "-90",
|
|
@@ -1321,7 +1835,7 @@ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onVal
|
|
|
1321
1835
|
value: latitudeText ?? "",
|
|
1322
1836
|
onChange: handleChange("latitude", setLatitudeText),
|
|
1323
1837
|
onBlur
|
|
1324
|
-
}))), /* @__PURE__ */
|
|
1838
|
+
}))), /* @__PURE__ */ React9.createElement("div", null, /* @__PURE__ */ React9.createElement(Input6.Root, null, layout !== "inline" && /* @__PURE__ */ React9.createElement(Input6.Label, null, t("longitude.label")), /* @__PURE__ */ React9.createElement(Input6.TextInput, {
|
|
1325
1839
|
type: "number",
|
|
1326
1840
|
step: "0.00001",
|
|
1327
1841
|
min: "-180",
|
|
@@ -1336,30 +1850,128 @@ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onVal
|
|
|
1336
1850
|
var LatLng = ({ latitude = 0, longitude = 0 }) => {
|
|
1337
1851
|
const latHem = latitude >= 0 ? "N" : "S";
|
|
1338
1852
|
const lngHem = longitude >= 0 ? "E" : "W";
|
|
1339
|
-
return /* @__PURE__ */
|
|
1853
|
+
return /* @__PURE__ */ React9.createElement("span", {
|
|
1340
1854
|
className: "inline-flex items-center gap-form-gap"
|
|
1341
|
-
}, /* @__PURE__ */
|
|
1855
|
+
}, /* @__PURE__ */ React9.createElement("span", null, /* @__PURE__ */ React9.createElement("span", null, Math.abs(latitude).toFixed(5)), /* @__PURE__ */ React9.createElement("span", {
|
|
1342
1856
|
className: "text-subdued"
|
|
1343
|
-
}, "\xB0", latHem)), /* @__PURE__ */
|
|
1857
|
+
}, "\xB0", latHem)), /* @__PURE__ */ React9.createElement("span", null, /* @__PURE__ */ React9.createElement("span", null, Math.abs(longitude).toFixed(5)), /* @__PURE__ */ React9.createElement("span", {
|
|
1344
1858
|
className: "text-subdued"
|
|
1345
1859
|
}, "\xB0", lngHem)));
|
|
1346
1860
|
};
|
|
1347
1861
|
|
|
1348
|
-
// src/components/Form/fields/
|
|
1862
|
+
// src/components/Form/fields/InlineRefField.tsx
|
|
1349
1863
|
import { useAtomValue } from "@effect-atom/atom-react";
|
|
1350
|
-
import
|
|
1351
|
-
import { Obj, Ref as
|
|
1864
|
+
import React10, { useCallback as useCallback7, useMemo as useMemo7 } from "react";
|
|
1865
|
+
import { Obj, Ref as Ref3, Type as Type2 } from "@dxos/echo";
|
|
1352
1866
|
import { AtomRef } from "@dxos/echo-atom";
|
|
1867
|
+
import { useType as defaultUseType } from "@dxos/echo-react";
|
|
1868
|
+
import { ReferenceAnnotationId as ReferenceAnnotationId2, splitJsonPath } from "@dxos/echo/internal";
|
|
1869
|
+
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
1870
|
+
import { Button, Icon as Icon2, Input as Input7, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1871
|
+
import { translationKey as translationKey5 } from "#translations";
|
|
1872
|
+
var InlineRefField = (props) => {
|
|
1873
|
+
const { type, readonly, label, jsonPath, layout, db, getValue, onValueChange, onCreate, useType: useType2 = defaultUseType } = props;
|
|
1874
|
+
const { t } = useTranslation5(translationKey5);
|
|
1875
|
+
const reference = getValue();
|
|
1876
|
+
const typename = useMemo7(() => type ? findAnnotation2(type, ReferenceAnnotationId2)?.typename : void 0, [
|
|
1877
|
+
type
|
|
1878
|
+
]);
|
|
1879
|
+
const createType = useType2(db, typename);
|
|
1880
|
+
const handleCreate = useCallback7(async () => {
|
|
1881
|
+
if (!createType || !onCreate) {
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
const newObject = await onCreate(createType, {});
|
|
1885
|
+
if (newObject) {
|
|
1886
|
+
onValueChange(type, Ref3.make(newObject));
|
|
1887
|
+
}
|
|
1888
|
+
}, [
|
|
1889
|
+
createType,
|
|
1890
|
+
onCreate,
|
|
1891
|
+
type,
|
|
1892
|
+
onValueChange
|
|
1893
|
+
]);
|
|
1894
|
+
if (readonly && !reference) {
|
|
1895
|
+
return null;
|
|
1896
|
+
}
|
|
1897
|
+
return /* @__PURE__ */ React10.createElement(Input7.Root, null, layout !== "inline" && /* @__PURE__ */ React10.createElement(FormFieldLabel, {
|
|
1898
|
+
readonly,
|
|
1899
|
+
label,
|
|
1900
|
+
path: jsonPath
|
|
1901
|
+
}), reference ? /* @__PURE__ */ React10.createElement(InlineForm, {
|
|
1902
|
+
reference,
|
|
1903
|
+
db,
|
|
1904
|
+
readonly,
|
|
1905
|
+
useType: useType2
|
|
1906
|
+
}) : !readonly && onCreate && /* @__PURE__ */ React10.createElement(Button, {
|
|
1907
|
+
classNames: "w-full gap-form-gap",
|
|
1908
|
+
disabled: !createType || !db,
|
|
1909
|
+
onClick: () => void handleCreate()
|
|
1910
|
+
}, /* @__PURE__ */ React10.createElement(Icon2, {
|
|
1911
|
+
icon: "ph--plus--regular",
|
|
1912
|
+
size: 4
|
|
1913
|
+
}), /* @__PURE__ */ React10.createElement("span", null, label || t("ref-field.placeholder"))));
|
|
1914
|
+
};
|
|
1915
|
+
var InlineForm = ({ reference, db, readonly, useType: useType2 = defaultUseType }) => {
|
|
1916
|
+
const target = useAtomValue(useMemo7(() => AtomRef.make(reference), [
|
|
1917
|
+
reference
|
|
1918
|
+
]));
|
|
1919
|
+
const typename = target ? Obj.getTypename(target) ?? void 0 : void 0;
|
|
1920
|
+
const typeFromRegistry = useType2(db, typename);
|
|
1921
|
+
const targetType = target && Obj.getType(target) || typeFromRegistry;
|
|
1922
|
+
const formSchema = useMemo7(() => targetType ? omitId(Type2.getSchema(targetType)) : void 0, [
|
|
1923
|
+
targetType
|
|
1924
|
+
]);
|
|
1925
|
+
const defaultValues = useMemo7(() => target ? {
|
|
1926
|
+
...target
|
|
1927
|
+
} : {}, [
|
|
1928
|
+
target
|
|
1929
|
+
]);
|
|
1930
|
+
const handleChange = useCallback7((values, { isValid, changed }) => {
|
|
1931
|
+
if (!isValid || !target) {
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1934
|
+
const changedPaths = Object.keys(changed).filter((path) => changed[path]);
|
|
1935
|
+
if (changedPaths.length === 0) {
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
Obj.update(target, () => {
|
|
1939
|
+
for (const path of changedPaths) {
|
|
1940
|
+
const parts = splitJsonPath(path);
|
|
1941
|
+
Obj.setValue(target, parts, Obj.getValue(values, parts));
|
|
1942
|
+
}
|
|
1943
|
+
});
|
|
1944
|
+
}, [
|
|
1945
|
+
target
|
|
1946
|
+
]);
|
|
1947
|
+
if (!target || !formSchema) {
|
|
1948
|
+
return null;
|
|
1949
|
+
}
|
|
1950
|
+
return /* @__PURE__ */ React10.createElement(Nesting, null, /* @__PURE__ */ React10.createElement(Form.Root, {
|
|
1951
|
+
schema: formSchema,
|
|
1952
|
+
defaultValues,
|
|
1953
|
+
db,
|
|
1954
|
+
onValuesChanged: handleChange
|
|
1955
|
+
}, /* @__PURE__ */ React10.createElement(Form.Content, null, /* @__PURE__ */ React10.createElement(Form.FieldSet, {
|
|
1956
|
+
readonly
|
|
1957
|
+
}))));
|
|
1958
|
+
};
|
|
1959
|
+
|
|
1960
|
+
// src/components/Form/fields/MarkdownField.tsx
|
|
1961
|
+
import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
|
|
1962
|
+
import React11, { useCallback as useCallback8, useMemo as useMemo8 } from "react";
|
|
1963
|
+
import { Obj as Obj2, Ref as Ref4 } from "@dxos/echo";
|
|
1964
|
+
import { AtomRef as AtomRef2 } from "@dxos/echo-atom";
|
|
1353
1965
|
import { createDocAccessor } from "@dxos/echo-db";
|
|
1354
|
-
import { Button, Icon as
|
|
1966
|
+
import { Button as Button2, Icon as Icon3, Input as Input8, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1355
1967
|
import { Editor, useBasicMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
1356
1968
|
import { Text } from "@dxos/schema";
|
|
1357
1969
|
import { createDataExtensions } from "@dxos/ui-editor";
|
|
1358
|
-
import { translationKey as
|
|
1970
|
+
import { translationKey as translationKey6 } from "#translations";
|
|
1359
1971
|
var editorClassNames = "transition-colors bg-input-surface focus-within:bg-focus-surface border border-separator rounded-xs p-1 px-2";
|
|
1360
|
-
var MarkdownField = ({ type, readonly, label, placeholder, layout, db, getStatus, getValue, onValueChange }) => {
|
|
1972
|
+
var MarkdownField = ({ type, readonly, label, jsonPath, placeholder, layout, db, getStatus, getValue, onValueChange }) => {
|
|
1361
1973
|
const { status, error } = getStatus();
|
|
1362
|
-
const isRef =
|
|
1974
|
+
const isRef = Ref4.isRefType(type);
|
|
1363
1975
|
const value3 = getValue();
|
|
1364
1976
|
if ((readonly || layout === "static") && value3 == null) {
|
|
1365
1977
|
return null;
|
|
@@ -1368,7 +1980,7 @@ var MarkdownField = ({ type, readonly, label, placeholder, layout, db, getStatus
|
|
|
1368
1980
|
if (isRef) {
|
|
1369
1981
|
const reference = value3;
|
|
1370
1982
|
if (reference) {
|
|
1371
|
-
return /* @__PURE__ */
|
|
1983
|
+
return /* @__PURE__ */ React11.createElement(RefMarkdownEditor, {
|
|
1372
1984
|
reference,
|
|
1373
1985
|
placeholder
|
|
1374
1986
|
});
|
|
@@ -1376,13 +1988,13 @@ var MarkdownField = ({ type, readonly, label, placeholder, layout, db, getStatus
|
|
|
1376
1988
|
if (readonly) {
|
|
1377
1989
|
return null;
|
|
1378
1990
|
}
|
|
1379
|
-
return /* @__PURE__ */
|
|
1991
|
+
return /* @__PURE__ */ React11.createElement(CreateTextButton, {
|
|
1380
1992
|
db,
|
|
1381
1993
|
disabled: !db,
|
|
1382
1994
|
onCreate: (ref) => onValueChange(type, ref)
|
|
1383
1995
|
});
|
|
1384
1996
|
}
|
|
1385
|
-
return /* @__PURE__ */
|
|
1997
|
+
return /* @__PURE__ */ React11.createElement(StringMarkdownEditor, {
|
|
1386
1998
|
value: value3 ?? "",
|
|
1387
1999
|
placeholder,
|
|
1388
2000
|
readonly: !!readonly,
|
|
@@ -1392,40 +2004,41 @@ var MarkdownField = ({ type, readonly, label, placeholder, layout, db, getStatus
|
|
|
1392
2004
|
const renderStatic = () => {
|
|
1393
2005
|
if (isRef) {
|
|
1394
2006
|
const reference = value3;
|
|
1395
|
-
return reference ? /* @__PURE__ */
|
|
2007
|
+
return reference ? /* @__PURE__ */ React11.createElement(RefStaticText, {
|
|
1396
2008
|
reference
|
|
1397
2009
|
}) : null;
|
|
1398
2010
|
}
|
|
1399
|
-
return /* @__PURE__ */
|
|
2011
|
+
return /* @__PURE__ */ React11.createElement("p", {
|
|
1400
2012
|
className: "whitespace-pre-wrap"
|
|
1401
2013
|
}, value3 ?? "");
|
|
1402
2014
|
};
|
|
1403
|
-
return /* @__PURE__ */
|
|
2015
|
+
return /* @__PURE__ */ React11.createElement(Input8.Root, {
|
|
1404
2016
|
validationValence: status
|
|
1405
|
-
}, layout !== "inline" && /* @__PURE__ */
|
|
2017
|
+
}, layout !== "inline" && /* @__PURE__ */ React11.createElement(FormFieldLabel, {
|
|
1406
2018
|
error,
|
|
1407
2019
|
readonly,
|
|
1408
|
-
label
|
|
1409
|
-
|
|
2020
|
+
label,
|
|
2021
|
+
path: jsonPath
|
|
2022
|
+
}), layout === "static" ? renderStatic() : renderEditor(), layout === "full" && /* @__PURE__ */ React11.createElement(Input8.Validation, null, error));
|
|
1410
2023
|
};
|
|
1411
2024
|
var RefStaticText = ({ reference }) => {
|
|
1412
|
-
const text =
|
|
2025
|
+
const text = useAtomValue2(useMemo8(() => AtomRef2.make(reference), [
|
|
1413
2026
|
reference
|
|
1414
2027
|
]));
|
|
1415
2028
|
if (!text?.content) {
|
|
1416
2029
|
return null;
|
|
1417
2030
|
}
|
|
1418
|
-
return /* @__PURE__ */
|
|
2031
|
+
return /* @__PURE__ */ React11.createElement("p", {
|
|
1419
2032
|
className: "whitespace-pre-wrap"
|
|
1420
2033
|
}, text.content);
|
|
1421
2034
|
};
|
|
1422
2035
|
var RefMarkdownEditor = ({ reference, placeholder }) => {
|
|
1423
|
-
const text =
|
|
2036
|
+
const text = useAtomValue2(useMemo8(() => AtomRef2.make(reference), [
|
|
1424
2037
|
reference
|
|
1425
2038
|
]));
|
|
1426
|
-
const dataExtensions =
|
|
2039
|
+
const dataExtensions = useMemo8(() => text ? [
|
|
1427
2040
|
createDataExtensions({
|
|
1428
|
-
id: reference.
|
|
2041
|
+
id: reference.uri,
|
|
1429
2042
|
text: createDocAccessor(text, [
|
|
1430
2043
|
"content"
|
|
1431
2044
|
])
|
|
@@ -1441,7 +2054,7 @@ var RefMarkdownEditor = ({ reference, placeholder }) => {
|
|
|
1441
2054
|
if (!text) {
|
|
1442
2055
|
return null;
|
|
1443
2056
|
}
|
|
1444
|
-
return /* @__PURE__ */
|
|
2057
|
+
return /* @__PURE__ */ React11.createElement(Editor.Root, null, /* @__PURE__ */ React11.createElement(Editor.View, {
|
|
1445
2058
|
classNames: editorClassNames,
|
|
1446
2059
|
extensions
|
|
1447
2060
|
}));
|
|
@@ -1450,10 +2063,10 @@ var StringMarkdownEditor = ({ value: value3, placeholder, readonly, onChange })
|
|
|
1450
2063
|
const extensions = useBasicMarkdownExtensions({
|
|
1451
2064
|
placeholder
|
|
1452
2065
|
});
|
|
1453
|
-
const handleChange =
|
|
2066
|
+
const handleChange = useCallback8((next) => onChange(next), [
|
|
1454
2067
|
onChange
|
|
1455
2068
|
]);
|
|
1456
|
-
return /* @__PURE__ */
|
|
2069
|
+
return /* @__PURE__ */ React11.createElement(Editor.Root, null, /* @__PURE__ */ React11.createElement(Editor.View, {
|
|
1457
2070
|
classNames: editorClassNames,
|
|
1458
2071
|
extensions,
|
|
1459
2072
|
value: value3,
|
|
@@ -1461,41 +2074,41 @@ var StringMarkdownEditor = ({ value: value3, placeholder, readonly, onChange })
|
|
|
1461
2074
|
}));
|
|
1462
2075
|
};
|
|
1463
2076
|
var CreateTextButton = ({ db, disabled, onCreate }) => {
|
|
1464
|
-
const { t } =
|
|
1465
|
-
const handleClick =
|
|
2077
|
+
const { t } = useTranslation6(translationKey6);
|
|
2078
|
+
const handleClick = useCallback8(() => {
|
|
1466
2079
|
if (!db) {
|
|
1467
2080
|
return;
|
|
1468
2081
|
}
|
|
1469
|
-
const text = db.add(
|
|
2082
|
+
const text = db.add(Obj2.make(Text.Text, {
|
|
1470
2083
|
content: ""
|
|
1471
2084
|
}));
|
|
1472
|
-
onCreate(
|
|
2085
|
+
onCreate(Ref4.make(text));
|
|
1473
2086
|
}, [
|
|
1474
2087
|
db,
|
|
1475
2088
|
onCreate
|
|
1476
2089
|
]);
|
|
1477
|
-
return /* @__PURE__ */
|
|
2090
|
+
return /* @__PURE__ */ React11.createElement(Button2, {
|
|
1478
2091
|
onClick: handleClick,
|
|
1479
2092
|
disabled
|
|
1480
|
-
}, /* @__PURE__ */
|
|
2093
|
+
}, /* @__PURE__ */ React11.createElement(Icon3, {
|
|
1481
2094
|
icon: "ph--plus--regular",
|
|
1482
2095
|
size: 4
|
|
1483
|
-
}), /* @__PURE__ */
|
|
2096
|
+
}), /* @__PURE__ */ React11.createElement("span", null, t("create-text.label")));
|
|
1484
2097
|
};
|
|
1485
2098
|
|
|
1486
2099
|
// src/components/Form/fields/NumberField.tsx
|
|
1487
|
-
import
|
|
1488
|
-
import { Input as
|
|
2100
|
+
import React12, { useCallback as useCallback9 } from "react";
|
|
2101
|
+
import { Input as Input9 } from "@dxos/react-ui";
|
|
1489
2102
|
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
1490
2103
|
var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1491
|
-
const handleChange =
|
|
2104
|
+
const handleChange = useCallback9((event) => onValueChange(type, safeParseFloat2(event.target.value) || 0), [
|
|
1492
2105
|
type,
|
|
1493
2106
|
onValueChange
|
|
1494
2107
|
]);
|
|
1495
|
-
return /* @__PURE__ */
|
|
2108
|
+
return /* @__PURE__ */ React12.createElement(FormFieldWrapper, {
|
|
1496
2109
|
readonly,
|
|
1497
2110
|
...props
|
|
1498
|
-
}, ({ value: value3 = "" }) => /* @__PURE__ */
|
|
2111
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React12.createElement(Input9.TextInput, {
|
|
1499
2112
|
type: "number",
|
|
1500
2113
|
disabled: !!readonly,
|
|
1501
2114
|
placeholder,
|
|
@@ -1506,43 +2119,43 @@ var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...prop
|
|
|
1506
2119
|
};
|
|
1507
2120
|
|
|
1508
2121
|
// src/components/Form/fields/RefField.tsx
|
|
1509
|
-
import
|
|
2122
|
+
import React14, { useCallback as useCallback11, useMemo as useMemo9, useState as useState4 } from "react";
|
|
1510
2123
|
import "@dxos/lit-ui/dx-tag-picker.pcss";
|
|
1511
|
-
import { Entity, Filter, Obj as
|
|
1512
|
-
import { useQuery,
|
|
1513
|
-
import { ReferenceAnnotationId as
|
|
1514
|
-
import { findAnnotation as
|
|
1515
|
-
import {
|
|
2124
|
+
import { Entity, Filter, Obj as Obj3, Ref as Ref5, Type as Type3 } from "@dxos/echo";
|
|
2125
|
+
import { useQuery, useType as defaultUseType2 } from "@dxos/echo-react";
|
|
2126
|
+
import { ANY_OBJECT_TYPENAME, ReferenceAnnotationId as ReferenceAnnotationId3 } from "@dxos/echo/internal";
|
|
2127
|
+
import { findAnnotation as findAnnotation3 } from "@dxos/effect";
|
|
2128
|
+
import { URI } from "@dxos/keys";
|
|
1516
2129
|
import { DxAnchor } from "@dxos/lit-ui/react";
|
|
1517
|
-
import { Button as
|
|
2130
|
+
import { Button as Button3, Icon as Icon4, Input as Input10, useTranslation as useTranslation8 } from "@dxos/react-ui";
|
|
1518
2131
|
import { ParentLabelAnnotationId } from "@dxos/schema";
|
|
1519
|
-
import { translationKey as
|
|
2132
|
+
import { translationKey as translationKey8 } from "#translations";
|
|
1520
2133
|
|
|
1521
2134
|
// src/components/ObjectPicker/ObjectPicker.tsx
|
|
1522
|
-
import
|
|
1523
|
-
import { Popover, useTranslation as
|
|
2135
|
+
import React13, { forwardRef, useCallback as useCallback10, useState as useState3 } from "react";
|
|
2136
|
+
import { Popover, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1524
2137
|
import { Combobox } from "@dxos/react-ui-list";
|
|
1525
2138
|
import { useSearchListResults } from "@dxos/react-ui-search";
|
|
1526
|
-
import { translationKey as
|
|
2139
|
+
import { translationKey as translationKey7 } from "#translations";
|
|
1527
2140
|
var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap: createFieldMap3, onSelect, onCreate, ...props }, forwardedRef) => {
|
|
1528
|
-
const { t } =
|
|
2141
|
+
const { t } = useTranslation7(translationKey7);
|
|
1529
2142
|
const [showForm, setShowForm] = useState3(false);
|
|
1530
2143
|
const [formInitialValue, setFormInitialValue] = useState3("");
|
|
1531
2144
|
const { results, query, handleSearch } = useSearchListResults({
|
|
1532
2145
|
items: options
|
|
1533
2146
|
});
|
|
1534
|
-
const handleFormSave =
|
|
2147
|
+
const handleFormSave = useCallback10(async (values) => {
|
|
1535
2148
|
await onCreate?.(values);
|
|
1536
2149
|
setShowForm(false);
|
|
1537
2150
|
setFormInitialValue("");
|
|
1538
2151
|
}, [
|
|
1539
2152
|
onCreate
|
|
1540
2153
|
]);
|
|
1541
|
-
const handleFormCancel =
|
|
2154
|
+
const handleFormCancel = useCallback10(() => {
|
|
1542
2155
|
setShowForm(false);
|
|
1543
2156
|
setFormInitialValue("");
|
|
1544
2157
|
}, []);
|
|
1545
|
-
const handleKeyDown =
|
|
2158
|
+
const handleKeyDown = useCallback10((event) => {
|
|
1546
2159
|
if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
|
|
1547
2160
|
event.stopPropagation();
|
|
1548
2161
|
event.preventDefault();
|
|
@@ -1555,11 +2168,11 @@ var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, cr
|
|
|
1555
2168
|
createSchema
|
|
1556
2169
|
]);
|
|
1557
2170
|
if (showForm && createSchema) {
|
|
1558
|
-
return /* @__PURE__ */
|
|
2171
|
+
return /* @__PURE__ */ React13.createElement(Combobox.Content, {
|
|
1559
2172
|
...props,
|
|
1560
2173
|
onKeyDownCapture: handleKeyDown,
|
|
1561
2174
|
ref: forwardedRef
|
|
1562
|
-
}, /* @__PURE__ */
|
|
2175
|
+
}, /* @__PURE__ */ React13.createElement(Popover.Viewport, null, /* @__PURE__ */ React13.createElement(Form.Root, {
|
|
1563
2176
|
testId: "create-referenced-object-form",
|
|
1564
2177
|
schema: createSchema,
|
|
1565
2178
|
defaultValues: createInitialValuePath ? {
|
|
@@ -1568,25 +2181,25 @@ var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, cr
|
|
|
1568
2181
|
fieldMap: createFieldMap3,
|
|
1569
2182
|
onSave: handleFormSave,
|
|
1570
2183
|
onCancel: handleFormCancel
|
|
1571
|
-
}, /* @__PURE__ */
|
|
2184
|
+
}, /* @__PURE__ */ React13.createElement(Form.Viewport, null, /* @__PURE__ */ React13.createElement(Form.Content, null, /* @__PURE__ */ React13.createElement(Form.FieldSet, null), /* @__PURE__ */ React13.createElement(Form.Actions, null))))), /* @__PURE__ */ React13.createElement(Combobox.Arrow, null));
|
|
1572
2185
|
}
|
|
1573
|
-
return /* @__PURE__ */
|
|
2186
|
+
return /* @__PURE__ */ React13.createElement(Combobox.Content, {
|
|
1574
2187
|
...props,
|
|
1575
2188
|
onKeyDownCapture: handleKeyDown,
|
|
1576
2189
|
ref: forwardedRef
|
|
1577
|
-
}, /* @__PURE__ */
|
|
2190
|
+
}, /* @__PURE__ */ React13.createElement(Combobox.Input, {
|
|
1578
2191
|
placeholder: t("ref-field-combobox-input.placeholder"),
|
|
1579
2192
|
autoFocus: true,
|
|
1580
2193
|
value: query,
|
|
1581
2194
|
onValueChange: handleSearch
|
|
1582
|
-
}), /* @__PURE__ */
|
|
2195
|
+
}), /* @__PURE__ */ React13.createElement(Combobox.List, null, results.map((option) => /* @__PURE__ */ React13.createElement(Combobox.Item, {
|
|
1583
2196
|
key: option.id,
|
|
1584
2197
|
value: option.id,
|
|
1585
2198
|
label: option.label,
|
|
1586
2199
|
checked: selectedIds?.includes(option.id),
|
|
1587
2200
|
onSelect: () => onSelect(option.id),
|
|
1588
2201
|
classNames: "flex items-center gap-2"
|
|
1589
|
-
})), createSchema && onCreate && /* @__PURE__ */
|
|
2202
|
+
})), createSchema && onCreate && /* @__PURE__ */ React13.createElement(CreateItem, {
|
|
1590
2203
|
query,
|
|
1591
2204
|
createOptionLabel,
|
|
1592
2205
|
createOptionIcon: createOptionIcon ?? "ph--plus--regular",
|
|
@@ -1594,15 +2207,15 @@ var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, cr
|
|
|
1594
2207
|
setFormInitialValue(currentQuery);
|
|
1595
2208
|
setShowForm(true);
|
|
1596
2209
|
}
|
|
1597
|
-
})), /* @__PURE__ */
|
|
2210
|
+
})), /* @__PURE__ */ React13.createElement(Combobox.Arrow, null));
|
|
1598
2211
|
});
|
|
1599
2212
|
var CreateItem = ({ query, createOptionLabel, createOptionIcon, onCreateItemSelect }) => {
|
|
1600
|
-
const { t } =
|
|
2213
|
+
const { t } = useTranslation7(translationKey7);
|
|
1601
2214
|
const label = createOptionLabel ? t(createOptionLabel[0], {
|
|
1602
2215
|
ns: createOptionLabel[1].ns,
|
|
1603
2216
|
text: query
|
|
1604
2217
|
}) : t("create-option.label");
|
|
1605
|
-
return /* @__PURE__ */
|
|
2218
|
+
return /* @__PURE__ */ React13.createElement(Combobox.Item, {
|
|
1606
2219
|
value: "__create__",
|
|
1607
2220
|
label,
|
|
1608
2221
|
icon: createOptionIcon,
|
|
@@ -1627,25 +2240,25 @@ var isRefSnapshot = (val) => {
|
|
|
1627
2240
|
return typeof val === "object" && typeof val?.["/"] === "string";
|
|
1628
2241
|
};
|
|
1629
2242
|
var defaultGetOptions = (results, { parentLabel } = {}) => results.map((result) => {
|
|
1630
|
-
const id = Entity.
|
|
1631
|
-
const parent = parentLabel ?
|
|
2243
|
+
const id = Entity.getURI(result);
|
|
2244
|
+
const parent = parentLabel ? Obj3.getParent(result) : void 0;
|
|
1632
2245
|
const label = parent ? Entity.getLabel(parent) : Entity.getLabel(result);
|
|
1633
2246
|
return {
|
|
1634
2247
|
id,
|
|
1635
2248
|
label: label ?? id
|
|
1636
2249
|
};
|
|
1637
2250
|
});
|
|
1638
|
-
var defaultUseResults = (db, typename) => useQuery(db, typename ? typename ===
|
|
2251
|
+
var defaultUseResults = (db, typename) => useQuery(db, typename ? typename === ANY_OBJECT_TYPENAME ? Filter.everything() : Filter.typename(typename) : Filter.nothing());
|
|
1639
2252
|
var RefField = (props) => {
|
|
1640
|
-
const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap: createFieldMap3, db,
|
|
1641
|
-
const { t } =
|
|
2253
|
+
const { type, readonly, label, jsonPath, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap: createFieldMap3, db, useType: useType2 = defaultUseType2, useResults = defaultUseResults, getOptions = defaultGetOptions, onCreate, onValueChange } = props;
|
|
2254
|
+
const { t } = useTranslation8(translationKey8);
|
|
1642
2255
|
const { status, error } = getStatus();
|
|
1643
|
-
const typename =
|
|
2256
|
+
const typename = useMemo9(() => type ? findAnnotation3(type, ReferenceAnnotationId3)?.typename : void 0, [
|
|
1644
2257
|
type
|
|
1645
2258
|
]);
|
|
1646
2259
|
const results = useResults(db, typename);
|
|
1647
|
-
const options =
|
|
1648
|
-
const parentLabel = type ?
|
|
2260
|
+
const options = useMemo9(() => {
|
|
2261
|
+
const parentLabel = type ? findAnnotation3(type, ParentLabelAnnotationId) === true : false;
|
|
1649
2262
|
return getOptions(results, {
|
|
1650
2263
|
parentLabel
|
|
1651
2264
|
});
|
|
@@ -1654,15 +2267,15 @@ var RefField = (props) => {
|
|
|
1654
2267
|
getOptions,
|
|
1655
2268
|
type
|
|
1656
2269
|
]);
|
|
1657
|
-
const handleGetValue =
|
|
2270
|
+
const handleGetValue = useCallback11(() => {
|
|
1658
2271
|
const formValue = getValue();
|
|
1659
|
-
const
|
|
2272
|
+
const dxnToEntityId = (dxn) => dxn.split(/[:/]/).filter(Boolean).pop() ?? dxn;
|
|
1660
2273
|
const unknownToRefOption = (value3) => {
|
|
1661
|
-
const isRef =
|
|
2274
|
+
const isRef = Ref5.isRef(value3);
|
|
1662
2275
|
if (isRef || isRefSnapshot(value3)) {
|
|
1663
|
-
const dxnString = isRef ? value3.
|
|
1664
|
-
const objectId =
|
|
1665
|
-
const matchingOption = options.find((option) =>
|
|
2276
|
+
const dxnString = isRef ? value3.uri : value3["/"];
|
|
2277
|
+
const objectId = dxnToEntityId(dxnString);
|
|
2278
|
+
const matchingOption = options.find((option) => dxnToEntityId(option.id) === objectId);
|
|
1666
2279
|
if (matchingOption) {
|
|
1667
2280
|
return matchingOption;
|
|
1668
2281
|
}
|
|
@@ -1675,20 +2288,20 @@ var RefField = (props) => {
|
|
|
1675
2288
|
getValue
|
|
1676
2289
|
]);
|
|
1677
2290
|
const item = handleGetValue();
|
|
1678
|
-
const selectedIds =
|
|
2291
|
+
const selectedIds = useMemo9(() => item ? [
|
|
1679
2292
|
item.id
|
|
1680
2293
|
] : [], [
|
|
1681
2294
|
item
|
|
1682
2295
|
]);
|
|
1683
|
-
const createSchema =
|
|
2296
|
+
const createSchema = useType2(db, typename);
|
|
1684
2297
|
const [open, setOpen] = useState4(false);
|
|
1685
|
-
const handleCreate =
|
|
2298
|
+
const handleCreate = useCallback11(async (values) => {
|
|
1686
2299
|
if (!createSchema || !onCreate) {
|
|
1687
2300
|
return;
|
|
1688
2301
|
}
|
|
1689
2302
|
const newObject = await onCreate(createSchema, values);
|
|
1690
2303
|
if (newObject) {
|
|
1691
|
-
onValueChange(type,
|
|
2304
|
+
onValueChange(type, Ref5.make(newObject));
|
|
1692
2305
|
}
|
|
1693
2306
|
setOpen(false);
|
|
1694
2307
|
}, [
|
|
@@ -1697,16 +2310,16 @@ var RefField = (props) => {
|
|
|
1697
2310
|
type,
|
|
1698
2311
|
onValueChange
|
|
1699
2312
|
]);
|
|
1700
|
-
const handleUpdate =
|
|
2313
|
+
const handleUpdate = useCallback11((id) => {
|
|
1701
2314
|
const item2 = options.find((option) => option.id === id);
|
|
1702
|
-
const ref = item2 ?
|
|
2315
|
+
const ref = item2 ? Ref5.fromURI(URI.make(item2.id)) : void 0;
|
|
1703
2316
|
onValueChange(type, ref);
|
|
1704
2317
|
}, [
|
|
1705
2318
|
options,
|
|
1706
2319
|
type,
|
|
1707
2320
|
onValueChange
|
|
1708
2321
|
]);
|
|
1709
|
-
const handleSelect =
|
|
2322
|
+
const handleSelect = useCallback11((id) => {
|
|
1710
2323
|
if (item?.id === id) {
|
|
1711
2324
|
handleUpdate(void 0);
|
|
1712
2325
|
} else {
|
|
@@ -1719,103 +2332,117 @@ var RefField = (props) => {
|
|
|
1719
2332
|
if (!typename || (readonly || layout === "static") && !item) {
|
|
1720
2333
|
return null;
|
|
1721
2334
|
}
|
|
1722
|
-
return /* @__PURE__ */
|
|
2335
|
+
return /* @__PURE__ */ React14.createElement(Input10.Root, {
|
|
1723
2336
|
validationValence: status
|
|
1724
|
-
}, layout !== "inline" && /* @__PURE__ */
|
|
2337
|
+
}, layout !== "inline" && /* @__PURE__ */ React14.createElement(FormFieldLabel, {
|
|
1725
2338
|
error,
|
|
1726
2339
|
readonly,
|
|
1727
|
-
label
|
|
1728
|
-
|
|
2340
|
+
label,
|
|
2341
|
+
path: jsonPath
|
|
2342
|
+
}), /* @__PURE__ */ React14.createElement("div", null, readonly ? !item ? /* @__PURE__ */ React14.createElement("p", {
|
|
1729
2343
|
className: "text-description mb-2"
|
|
1730
|
-
}, t("empty-readonly-ref-field.label")) : /* @__PURE__ */
|
|
2344
|
+
}, t("empty-readonly-ref-field.label")) : /* @__PURE__ */ React14.createElement(DxAnchor, {
|
|
1731
2345
|
key: item.id,
|
|
1732
2346
|
dxn: item.id,
|
|
1733
2347
|
rootclassname: "me-1"
|
|
1734
|
-
}, item.label) : /* @__PURE__ */
|
|
2348
|
+
}, item.label) : /* @__PURE__ */ React14.createElement(ObjectPicker.Root, {
|
|
1735
2349
|
open,
|
|
1736
2350
|
onOpenChange: setOpen
|
|
1737
|
-
}, /* @__PURE__ */
|
|
2351
|
+
}, /* @__PURE__ */ React14.createElement(ObjectPicker.Trigger, {
|
|
1738
2352
|
asChild: true,
|
|
1739
2353
|
classNames: "p-0"
|
|
1740
|
-
}, item ? /* @__PURE__ */
|
|
2354
|
+
}, item ? /* @__PURE__ */ React14.createElement("div", {
|
|
1741
2355
|
className: "flex gap-form-gap w-full"
|
|
1742
|
-
}, /* @__PURE__ */
|
|
2356
|
+
}, /* @__PURE__ */ React14.createElement(Input10.Root, {
|
|
1743
2357
|
key: item.id
|
|
1744
|
-
}, /* @__PURE__ */
|
|
2358
|
+
}, /* @__PURE__ */ React14.createElement(Input10.TextInput, {
|
|
1745
2359
|
value: item.label,
|
|
1746
2360
|
readOnly: true,
|
|
1747
2361
|
classNames: "w-full"
|
|
1748
|
-
}))) : /* @__PURE__ */
|
|
2362
|
+
}))) : /* @__PURE__ */ React14.createElement(Button3, {
|
|
1749
2363
|
classNames: "w-full text-start gap-form-gap"
|
|
1750
|
-
}, /* @__PURE__ */
|
|
2364
|
+
}, /* @__PURE__ */ React14.createElement("div", {
|
|
1751
2365
|
className: "grow overflow-hidden"
|
|
1752
|
-
}, /* @__PURE__ */
|
|
2366
|
+
}, /* @__PURE__ */ React14.createElement("span", {
|
|
1753
2367
|
className: "truncate text-description"
|
|
1754
|
-
}, placeholder
|
|
2368
|
+
}, placeholder || label || t("ref-field.placeholder"))), /* @__PURE__ */ React14.createElement(Icon4, {
|
|
1755
2369
|
size: 3,
|
|
1756
2370
|
icon: "ph--caret-down--bold"
|
|
1757
|
-
}))), /* @__PURE__ */
|
|
2371
|
+
}))), /* @__PURE__ */ React14.createElement(ObjectPicker.Portal, null, /* @__PURE__ */ React14.createElement(ObjectPicker.Content, {
|
|
1758
2372
|
classNames: "dx-card-popover-width",
|
|
1759
2373
|
options,
|
|
1760
2374
|
selectedIds,
|
|
1761
2375
|
// Strip hidden (`FormInputAnnotation.set(false)`) fields so the
|
|
1762
2376
|
// form's validator doesn't reject required-but-hidden fields
|
|
1763
2377
|
// such as backing-object refs supplied by a `FactoryAnnotation`.
|
|
1764
|
-
createSchema: createSchema && omitHiddenFormFields(omitId(createSchema)),
|
|
2378
|
+
createSchema: createSchema && omitHiddenFormFields(omitId(Type3.getSchema(createSchema))),
|
|
1765
2379
|
createOptionLabel,
|
|
1766
2380
|
createOptionIcon,
|
|
1767
2381
|
createInitialValuePath,
|
|
1768
2382
|
createFieldMap: createFieldMap3,
|
|
1769
2383
|
onCreate: handleCreate,
|
|
1770
2384
|
onSelect: handleSelect
|
|
1771
|
-
})))), layout === "full" && /* @__PURE__ */
|
|
2385
|
+
})))), layout === "full" && /* @__PURE__ */ React14.createElement(Input10.DescriptionAndValidation, null, error));
|
|
1772
2386
|
};
|
|
1773
2387
|
|
|
1774
2388
|
// src/components/Form/fields/SelectField.tsx
|
|
1775
|
-
import
|
|
1776
|
-
import { Input as
|
|
1777
|
-
|
|
2389
|
+
import React15, { useCallback as useCallback12 } from "react";
|
|
2390
|
+
import { Icon as Icon5, Input as Input11, Select } from "@dxos/react-ui";
|
|
2391
|
+
import { getStyles } from "@dxos/ui-theme";
|
|
2392
|
+
var SelectField = ({ type, readonly, label, jsonPath, layout, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
1778
2393
|
const { status, error } = getStatus();
|
|
1779
2394
|
const value3 = getValue();
|
|
1780
|
-
const handleValueChange =
|
|
2395
|
+
const handleValueChange = useCallback12((value4) => onValueChange(type, value4), [
|
|
1781
2396
|
type,
|
|
1782
2397
|
onValueChange
|
|
1783
2398
|
]);
|
|
1784
2399
|
if ((readonly || layout === "static") && value3 == null) {
|
|
1785
2400
|
return null;
|
|
1786
2401
|
}
|
|
1787
|
-
return /* @__PURE__ */
|
|
2402
|
+
return /* @__PURE__ */ React15.createElement(Input11.Root, {
|
|
1788
2403
|
validationValence: status
|
|
1789
|
-
}, layout !== "inline" && /* @__PURE__ */
|
|
2404
|
+
}, layout !== "inline" && /* @__PURE__ */ React15.createElement(FormFieldLabel, {
|
|
1790
2405
|
error,
|
|
1791
2406
|
readonly,
|
|
1792
|
-
label
|
|
1793
|
-
|
|
2407
|
+
label,
|
|
2408
|
+
path: jsonPath
|
|
2409
|
+
}), layout === "static" ? /* @__PURE__ */ React15.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value3)?.label ?? String(value3)) : /* @__PURE__ */ React15.createElement(Select.Root, {
|
|
1794
2410
|
value: value3,
|
|
1795
2411
|
onValueChange: handleValueChange
|
|
1796
|
-
}, /* @__PURE__ */
|
|
2412
|
+
}, /* @__PURE__ */ React15.createElement(Select.TriggerButton, {
|
|
1797
2413
|
classNames: "w-full",
|
|
1798
2414
|
disabled: !!readonly,
|
|
1799
2415
|
placeholder
|
|
1800
|
-
}), /* @__PURE__ */
|
|
2416
|
+
}), /* @__PURE__ */ React15.createElement(Select.Portal, null, /* @__PURE__ */ React15.createElement(Select.Content, null, /* @__PURE__ */ React15.createElement(Select.Viewport, null, options?.map(({ value: value4, label: label2, secondaryLabel, icon, iconHue }) => (
|
|
1801
2417
|
// NOTE: Numeric values are converted to and from strings.
|
|
1802
|
-
/* @__PURE__ */
|
|
2418
|
+
/* @__PURE__ */ React15.createElement(Select.Option, {
|
|
1803
2419
|
key: String(value4),
|
|
1804
2420
|
value: String(value4)
|
|
1805
|
-
},
|
|
1806
|
-
|
|
2421
|
+
}, /* @__PURE__ */ React15.createElement("span", {
|
|
2422
|
+
className: "flex items-center flex-row gap-2"
|
|
2423
|
+
}, icon && /* @__PURE__ */ React15.createElement(Icon5, {
|
|
2424
|
+
icon,
|
|
2425
|
+
classNames: getIconHueStyles(iconHue)
|
|
2426
|
+
}), label2 ?? String(value4), secondaryLabel && /* @__PURE__ */ React15.createElement("span", {
|
|
2427
|
+
className: "text-subdued text-xs"
|
|
2428
|
+
}, secondaryLabel)))
|
|
2429
|
+
))), /* @__PURE__ */ React15.createElement(Select.Arrow, null)))), layout === "full" && /* @__PURE__ */ React15.createElement(Input11.DescriptionAndValidation, null, error));
|
|
2430
|
+
};
|
|
2431
|
+
var getIconHueStyles = (iconHue) => {
|
|
2432
|
+
const styles = iconHue ? getStyles(iconHue) : void 0;
|
|
2433
|
+
return styles?.fg;
|
|
1807
2434
|
};
|
|
1808
2435
|
|
|
1809
2436
|
// src/components/Form/fields/SelectOptionField.tsx
|
|
1810
|
-
import
|
|
2437
|
+
import React16, { useCallback as useCallback13, useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
|
|
1811
2438
|
import { PublicKey } from "@dxos/keys";
|
|
1812
|
-
import { IconButton as IconButton3, Input as
|
|
2439
|
+
import { IconButton as IconButton3, Input as Input12, Tag, useTranslation as useTranslation9 } from "@dxos/react-ui";
|
|
1813
2440
|
import { List } from "@dxos/react-ui-list";
|
|
1814
2441
|
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
1815
2442
|
import { hues, osTranslations } from "@dxos/ui-theme";
|
|
1816
|
-
import { translationKey as
|
|
1817
|
-
var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueChange }) => {
|
|
1818
|
-
const { t } =
|
|
2443
|
+
import { translationKey as translationKey9 } from "#translations";
|
|
2444
|
+
var SelectOptionField = ({ type, readonly, label, jsonPath, getStatus, getValue, onValueChange }) => {
|
|
2445
|
+
const { t } = useTranslation9(translationKey9);
|
|
1819
2446
|
const { status, error } = getStatus();
|
|
1820
2447
|
const [selected, setSelectedId] = useState5(null);
|
|
1821
2448
|
const [isNewOption, setIsNewOption] = useState5(false);
|
|
@@ -1840,7 +2467,7 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1840
2467
|
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
1841
2468
|
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
|
|
1842
2469
|
};
|
|
1843
|
-
const handleAdd =
|
|
2470
|
+
const handleAdd = useCallback13(() => {
|
|
1844
2471
|
const newId = PublicKey.random().truncate();
|
|
1845
2472
|
const newOption = {
|
|
1846
2473
|
id: newId,
|
|
@@ -1858,7 +2485,7 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1858
2485
|
type,
|
|
1859
2486
|
onValueChange
|
|
1860
2487
|
]);
|
|
1861
|
-
const handleDelete =
|
|
2488
|
+
const handleDelete = useCallback13((id) => {
|
|
1862
2489
|
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
1863
2490
|
onValueChange(type, newOptions);
|
|
1864
2491
|
setSelectedId(null);
|
|
@@ -1867,7 +2494,7 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1867
2494
|
type,
|
|
1868
2495
|
onValueChange
|
|
1869
2496
|
]);
|
|
1870
|
-
const handleMove =
|
|
2497
|
+
const handleMove = useCallback13((from, to) => {
|
|
1871
2498
|
if (!options) {
|
|
1872
2499
|
return;
|
|
1873
2500
|
}
|
|
@@ -1882,10 +2509,10 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1882
2509
|
type,
|
|
1883
2510
|
onValueChange
|
|
1884
2511
|
]);
|
|
1885
|
-
const handleClick =
|
|
2512
|
+
const handleClick = useCallback13((id) => {
|
|
1886
2513
|
setSelectedId((current) => current === id ? null : id);
|
|
1887
2514
|
}, []);
|
|
1888
|
-
const handleTitleChange =
|
|
2515
|
+
const handleTitleChange = useCallback13((id) => (e) => {
|
|
1889
2516
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
1890
2517
|
...o,
|
|
1891
2518
|
title: e.target.value
|
|
@@ -1896,12 +2523,12 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1896
2523
|
type,
|
|
1897
2524
|
onValueChange
|
|
1898
2525
|
]);
|
|
1899
|
-
const handleKeyDown =
|
|
2526
|
+
const handleKeyDown = useCallback13((ev) => {
|
|
1900
2527
|
if (ev.key === "Enter") {
|
|
1901
2528
|
setSelectedId(null);
|
|
1902
2529
|
}
|
|
1903
2530
|
}, []);
|
|
1904
|
-
const handleColorChange =
|
|
2531
|
+
const handleColorChange = useCallback13((id) => (hue) => {
|
|
1905
2532
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
1906
2533
|
...o,
|
|
1907
2534
|
color: hue
|
|
@@ -1921,37 +2548,38 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1921
2548
|
selected,
|
|
1922
2549
|
isNewOption
|
|
1923
2550
|
]);
|
|
1924
|
-
return /* @__PURE__ */
|
|
2551
|
+
return /* @__PURE__ */ React16.createElement(Input12.Root, {
|
|
1925
2552
|
validationValence: status
|
|
1926
|
-
}, /* @__PURE__ */
|
|
2553
|
+
}, /* @__PURE__ */ React16.createElement(FormFieldLabel, {
|
|
1927
2554
|
error,
|
|
1928
2555
|
readonly,
|
|
1929
|
-
label
|
|
1930
|
-
|
|
2556
|
+
label,
|
|
2557
|
+
path: jsonPath
|
|
2558
|
+
}), /* @__PURE__ */ React16.createElement("div", null, options && /* @__PURE__ */ React16.createElement(List.Root, {
|
|
1931
2559
|
items: options,
|
|
1932
2560
|
isItem: (_item) => true,
|
|
1933
2561
|
onMove: readonly ? void 0 : handleMove,
|
|
1934
2562
|
readonly: !!readonly
|
|
1935
|
-
}, ({ items }) => /* @__PURE__ */
|
|
2563
|
+
}, ({ items }) => /* @__PURE__ */ React16.createElement("div", {
|
|
1936
2564
|
role: "list",
|
|
1937
2565
|
className: "w-full overflow-auto"
|
|
1938
|
-
}, items?.map((item) => /* @__PURE__ */
|
|
2566
|
+
}, items?.map((item) => /* @__PURE__ */ React16.createElement("div", {
|
|
1939
2567
|
key: item.id
|
|
1940
|
-
}, /* @__PURE__ */
|
|
2568
|
+
}, /* @__PURE__ */ React16.createElement(List.Item, {
|
|
1941
2569
|
role: "button",
|
|
1942
2570
|
item,
|
|
1943
2571
|
classNames: "flex flex-col cursor-pointer rounded-xs dx-hover",
|
|
1944
2572
|
"aria-expanded": selected === item.id
|
|
1945
|
-
}, /* @__PURE__ */
|
|
2573
|
+
}, /* @__PURE__ */ React16.createElement("div", {
|
|
1946
2574
|
className: "flex items-center"
|
|
1947
|
-
}, /* @__PURE__ */
|
|
2575
|
+
}, /* @__PURE__ */ React16.createElement(List.ItemDragHandle, {
|
|
1948
2576
|
disabled: !!readonly
|
|
1949
|
-
}), /* @__PURE__ */
|
|
2577
|
+
}), /* @__PURE__ */ React16.createElement(List.ItemTitle, {
|
|
1950
2578
|
onClick: () => handleClick(item.id),
|
|
1951
2579
|
classNames: "flex-1"
|
|
1952
|
-
}, /* @__PURE__ */
|
|
2580
|
+
}, /* @__PURE__ */ React16.createElement(Tag, {
|
|
1953
2581
|
palette: item.color
|
|
1954
|
-
}, item.title || "\u200B")), /* @__PURE__ */
|
|
2582
|
+
}, item.title || "\u200B")), /* @__PURE__ */ React16.createElement(IconButton3, {
|
|
1955
2583
|
iconOnly: true,
|
|
1956
2584
|
variant: "ghost",
|
|
1957
2585
|
label: t(selected === item.id ? "collapse.label" : "expand.label", {
|
|
@@ -1959,13 +2587,13 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1959
2587
|
}),
|
|
1960
2588
|
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
1961
2589
|
onClick: () => handleClick(item.id)
|
|
1962
|
-
})), selected === item.id && /* @__PURE__ */
|
|
1963
|
-
className: "flex flex-col p-form-padding gap-form-gap dx-density-
|
|
1964
|
-
}, /* @__PURE__ */
|
|
1965
|
-
classNames: "text-
|
|
1966
|
-
}, t("select-option.label")), /* @__PURE__ */
|
|
2590
|
+
})), selected === item.id && /* @__PURE__ */ React16.createElement("div", {
|
|
2591
|
+
className: "flex flex-col p-form-padding gap-form-gap dx-density-md"
|
|
2592
|
+
}, /* @__PURE__ */ React16.createElement(Input12.Label, {
|
|
2593
|
+
classNames: "text-sm"
|
|
2594
|
+
}, t("select-option.label")), /* @__PURE__ */ React16.createElement("div", {
|
|
1967
2595
|
className: "grid grid-cols-[1fr_min-content_min-content] gap-form-gap"
|
|
1968
|
-
}, /* @__PURE__ */
|
|
2596
|
+
}, /* @__PURE__ */ React16.createElement(Input12.TextInput, {
|
|
1969
2597
|
disabled: !!readonly,
|
|
1970
2598
|
placeholder: t("select-option-label.placeholder"),
|
|
1971
2599
|
ref: selected === item.id ? inputRef : void 0,
|
|
@@ -1973,17 +2601,17 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1973
2601
|
onChange: handleTitleChange(item.id),
|
|
1974
2602
|
onKeyDown: handleKeyDown,
|
|
1975
2603
|
classNames: "flex-1"
|
|
1976
|
-
}), /* @__PURE__ */
|
|
2604
|
+
}), /* @__PURE__ */ React16.createElement(HuePicker, {
|
|
1977
2605
|
disabled: !!readonly,
|
|
1978
2606
|
value: item.color,
|
|
1979
2607
|
onChange: handleColorChange(item.id)
|
|
1980
|
-
}), /* @__PURE__ */
|
|
2608
|
+
}), /* @__PURE__ */ React16.createElement(IconButton3, {
|
|
1981
2609
|
disabled: !!readonly,
|
|
1982
2610
|
icon: "ph--trash--fill",
|
|
1983
2611
|
iconOnly: true,
|
|
1984
2612
|
label: t("select-option-delete.button"),
|
|
1985
2613
|
onClick: () => handleDelete(item.id)
|
|
1986
|
-
})))))), /* @__PURE__ */
|
|
2614
|
+
})))))), /* @__PURE__ */ React16.createElement(IconButton3, {
|
|
1987
2615
|
variant: "ghost",
|
|
1988
2616
|
icon: "ph--plus--regular",
|
|
1989
2617
|
label: t("select-option-add.button"),
|
|
@@ -1994,17 +2622,17 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1994
2622
|
};
|
|
1995
2623
|
|
|
1996
2624
|
// src/components/Form/fields/TextField.tsx
|
|
1997
|
-
import
|
|
1998
|
-
import { Input as
|
|
2625
|
+
import React17, { useCallback as useCallback14 } from "react";
|
|
2626
|
+
import { Input as Input13 } from "@dxos/react-ui";
|
|
1999
2627
|
var TextField = ({ type, readonly, placeholder, onBlur, onValueChange, ...props }) => {
|
|
2000
|
-
const handleChange =
|
|
2628
|
+
const handleChange = useCallback14((event) => onValueChange(type, event.target.value), [
|
|
2001
2629
|
type,
|
|
2002
2630
|
onValueChange
|
|
2003
2631
|
]);
|
|
2004
|
-
return /* @__PURE__ */
|
|
2632
|
+
return /* @__PURE__ */ React17.createElement(FormFieldWrapper, {
|
|
2005
2633
|
readonly,
|
|
2006
2634
|
...props
|
|
2007
|
-
}, ({ value: value3 = "" }) => /* @__PURE__ */
|
|
2635
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React17.createElement(Input13.TextInput, {
|
|
2008
2636
|
noAutoFill: true,
|
|
2009
2637
|
disabled: !!readonly,
|
|
2010
2638
|
placeholder,
|
|
@@ -2015,18 +2643,18 @@ var TextField = ({ type, readonly, placeholder, onBlur, onValueChange, ...props
|
|
|
2015
2643
|
};
|
|
2016
2644
|
|
|
2017
2645
|
// src/components/Form/fields/TextAreaField.tsx
|
|
2018
|
-
import
|
|
2019
|
-
import { Input as
|
|
2646
|
+
import React18, { useCallback as useCallback15 } from "react";
|
|
2647
|
+
import { Input as Input14 } from "@dxos/react-ui";
|
|
2020
2648
|
var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
2021
|
-
const handleChange =
|
|
2649
|
+
const handleChange = useCallback15((event) => onValueChange(type, event.target.value), [
|
|
2022
2650
|
type,
|
|
2023
2651
|
onValueChange
|
|
2024
2652
|
]);
|
|
2025
|
-
return /* @__PURE__ */
|
|
2653
|
+
return /* @__PURE__ */ React18.createElement(FormFieldWrapper, {
|
|
2026
2654
|
readonly,
|
|
2027
2655
|
...props
|
|
2028
|
-
}, ({ value: value3 = "" }) => /* @__PURE__ */
|
|
2029
|
-
rows:
|
|
2656
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React18.createElement(Input14.TextArea, {
|
|
2657
|
+
rows: 5,
|
|
2030
2658
|
disabled: !!readonly,
|
|
2031
2659
|
placeholder,
|
|
2032
2660
|
value: value3,
|
|
@@ -2036,9 +2664,9 @@ var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...pr
|
|
|
2036
2664
|
};
|
|
2037
2665
|
|
|
2038
2666
|
// src/components/Form/fields/TupleField.tsx
|
|
2039
|
-
import
|
|
2040
|
-
import { Input as
|
|
2041
|
-
import { mx as
|
|
2667
|
+
import React19 from "react";
|
|
2668
|
+
import { Input as Input15 } from "@dxos/react-ui";
|
|
2669
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
2042
2670
|
import { safeParseFloat as safeParseFloat3 } from "@dxos/util";
|
|
2043
2671
|
var gridCols = [
|
|
2044
2672
|
"grid-cols-1",
|
|
@@ -2046,18 +2674,19 @@ var gridCols = [
|
|
|
2046
2674
|
"grid-cols-3",
|
|
2047
2675
|
"grid-cols-4"
|
|
2048
2676
|
];
|
|
2049
|
-
var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValueChange, onBlur }) => {
|
|
2677
|
+
var TupleField = ({ binding, type, readonly, label, jsonPath, getStatus, getValue, onValueChange, onBlur }) => {
|
|
2050
2678
|
const { status, error } = getStatus();
|
|
2051
2679
|
const values = getValue() ?? {};
|
|
2052
|
-
return /* @__PURE__ */
|
|
2680
|
+
return /* @__PURE__ */ React19.createElement(Input15.Root, {
|
|
2053
2681
|
validationValence: status
|
|
2054
|
-
}, /* @__PURE__ */
|
|
2682
|
+
}, /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
2055
2683
|
error,
|
|
2056
2684
|
readonly,
|
|
2057
|
-
label
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2685
|
+
label,
|
|
2686
|
+
path: jsonPath
|
|
2687
|
+
}), /* @__PURE__ */ React19.createElement("div", {
|
|
2688
|
+
className: mx4("grid gap-form-gap", gridCols[binding.length - 1])
|
|
2689
|
+
}, binding.map((prop) => /* @__PURE__ */ React19.createElement(Input15.TextInput, {
|
|
2061
2690
|
key: prop,
|
|
2062
2691
|
type: "number",
|
|
2063
2692
|
disabled: !!readonly,
|
|
@@ -2072,10 +2701,20 @@ var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValue
|
|
|
2072
2701
|
}))));
|
|
2073
2702
|
};
|
|
2074
2703
|
|
|
2704
|
+
// src/components/Form/meta-tags.ts
|
|
2705
|
+
import * as Schema4 from "effect/Schema";
|
|
2706
|
+
import { Ref as Ref6, Tag as Tag2 } from "@dxos/echo";
|
|
2707
|
+
var META_TAGS_KEY = "_tags";
|
|
2708
|
+
var withMetaTags = (schema) => omitId(Schema4.Struct({
|
|
2709
|
+
[META_TAGS_KEY]: Schema4.Array(Ref6.Ref(Tag2.Tag)).pipe(Schema4.annotations({
|
|
2710
|
+
title: "Tags"
|
|
2711
|
+
}), Schema4.optional)
|
|
2712
|
+
}).pipe(Schema4.extend(schema)));
|
|
2713
|
+
|
|
2075
2714
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
2076
2715
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
2077
2716
|
var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }) => {
|
|
2078
|
-
const { t } =
|
|
2717
|
+
const { t } = useTranslation10(translationKey10);
|
|
2079
2718
|
const [props, setProps] = useState6(projection.getFieldProjection(field.id).props);
|
|
2080
2719
|
useEffect5(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
2081
2720
|
field,
|
|
@@ -2086,10 +2725,10 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2086
2725
|
if (!registry) {
|
|
2087
2726
|
return;
|
|
2088
2727
|
}
|
|
2089
|
-
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
2728
|
+
const subscription = registry.query(Filter2.type(Type4.Type)).subscribe((query) => setSchemas(query.results), {
|
|
2090
2729
|
fire: true
|
|
2091
2730
|
});
|
|
2092
|
-
const schemas2 = await registry.query().run();
|
|
2731
|
+
const schemas2 = await registry.query(Filter2.type(Type4.Type)).run();
|
|
2093
2732
|
setSchemas(schemas2);
|
|
2094
2733
|
return () => subscription?.();
|
|
2095
2734
|
}, [
|
|
@@ -2097,7 +2736,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2097
2736
|
]);
|
|
2098
2737
|
const [referenceSchema, setReferenceSchema] = useState6();
|
|
2099
2738
|
useEffect5(() => {
|
|
2100
|
-
setReferenceSchema(schemas.find((schema) => schema
|
|
2739
|
+
setReferenceSchema(schemas.find((schema) => Type4.getTypename(schema) === props?.referenceSchema));
|
|
2101
2740
|
}, [
|
|
2102
2741
|
schemas,
|
|
2103
2742
|
props?.referenceSchema
|
|
@@ -2105,34 +2744,34 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2105
2744
|
const [{ fieldSchema }, setFieldSchema] = useState6({
|
|
2106
2745
|
fieldSchema: getFormatSchema(props?.format)
|
|
2107
2746
|
});
|
|
2108
|
-
const fieldMap =
|
|
2109
|
-
["format"]: (props2) => /* @__PURE__ */
|
|
2747
|
+
const fieldMap = useMemo10(() => ({
|
|
2748
|
+
["format"]: (props2) => /* @__PURE__ */ React20.createElement(SelectField, {
|
|
2110
2749
|
...props2,
|
|
2111
|
-
options: FormatEnums.filter((value3) => value3 !==
|
|
2750
|
+
options: FormatEnums.filter((value3) => value3 !== Format6.TypeFormat.None).map((value3) => ({
|
|
2112
2751
|
value: value3,
|
|
2113
2752
|
label: t(`format.${value3}.label`)
|
|
2114
2753
|
}))
|
|
2115
2754
|
}),
|
|
2116
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */
|
|
2755
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React20.createElement(SelectField, {
|
|
2117
2756
|
...props2,
|
|
2118
|
-
options: schemas.map((schema) => ({
|
|
2119
|
-
value:
|
|
2757
|
+
options: schemas.map((schema) => Type4.getTypename(schema)).filter((typename) => typename != null).map((typename) => ({
|
|
2758
|
+
value: typename
|
|
2120
2759
|
}))
|
|
2121
2760
|
}),
|
|
2122
|
-
["referencePath"]: (props2) => /* @__PURE__ */
|
|
2761
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React20.createElement(SelectField, {
|
|
2123
2762
|
...props2,
|
|
2124
|
-
options: referenceSchema ? getFormProperties(referenceSchema.ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
|
|
2763
|
+
options: referenceSchema ? getFormProperties(Type4.getSchema(referenceSchema).ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
|
|
2125
2764
|
value: p.name.toString()
|
|
2126
2765
|
})) : []
|
|
2127
2766
|
}),
|
|
2128
|
-
["options"]: (props2) => /* @__PURE__ */
|
|
2767
|
+
["options"]: (props2) => /* @__PURE__ */ React20.createElement(SelectOptionField, props2)
|
|
2129
2768
|
}), [
|
|
2130
2769
|
t,
|
|
2131
2770
|
schemas,
|
|
2132
2771
|
referenceSchema
|
|
2133
2772
|
]);
|
|
2134
|
-
const propIsNotType =
|
|
2135
|
-
const handleValuesChanged =
|
|
2773
|
+
const propIsNotType = useCallback16((props2) => props2.filter((prop) => prop.name !== "type"), []);
|
|
2774
|
+
const handleValuesChanged = useCallback16((_props) => {
|
|
2136
2775
|
setFieldSchema((prev) => {
|
|
2137
2776
|
const fieldSchema2 = getFormatSchema(_props.format);
|
|
2138
2777
|
if (prev.fieldSchema === fieldSchema2) {
|
|
@@ -2143,8 +2782,8 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2143
2782
|
};
|
|
2144
2783
|
});
|
|
2145
2784
|
setReferenceSchema((prev) => {
|
|
2146
|
-
if (_props.referenceSchema !== prev
|
|
2147
|
-
const newSchema = schemas.find((schema) => schema
|
|
2785
|
+
if (_props.referenceSchema !== (prev ? Type4.getTypename(prev) : void 0)) {
|
|
2786
|
+
const newSchema = schemas.find((schema) => Type4.getTypename(schema) === _props.referenceSchema);
|
|
2148
2787
|
if (newSchema) {
|
|
2149
2788
|
return newSchema;
|
|
2150
2789
|
}
|
|
@@ -2169,7 +2808,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2169
2808
|
props.format,
|
|
2170
2809
|
props.referenceSchema
|
|
2171
2810
|
]);
|
|
2172
|
-
const handleValidate =
|
|
2811
|
+
const handleValidate = useCallback16(({ property }) => {
|
|
2173
2812
|
if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
|
|
2174
2813
|
return [
|
|
2175
2814
|
{
|
|
@@ -2182,9 +2821,9 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2182
2821
|
projection.getFields(),
|
|
2183
2822
|
field
|
|
2184
2823
|
]);
|
|
2185
|
-
const handleSave =
|
|
2824
|
+
const handleSave = useCallback16((props2) => {
|
|
2186
2825
|
if (view) {
|
|
2187
|
-
|
|
2826
|
+
Obj4.update(view, () => {
|
|
2188
2827
|
projection.setFieldProjection({
|
|
2189
2828
|
field,
|
|
2190
2829
|
props: props2
|
|
@@ -2203,7 +2842,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2203
2842
|
view,
|
|
2204
2843
|
onSave
|
|
2205
2844
|
]);
|
|
2206
|
-
const handleCancel =
|
|
2845
|
+
const handleCancel = useCallback16(() => {
|
|
2207
2846
|
onSave();
|
|
2208
2847
|
requestAnimationFrame(() => onCancel?.());
|
|
2209
2848
|
}, [
|
|
@@ -2215,7 +2854,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2215
2854
|
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 156, S: void 0 });
|
|
2216
2855
|
return null;
|
|
2217
2856
|
}
|
|
2218
|
-
return /* @__PURE__ */
|
|
2857
|
+
return /* @__PURE__ */ React20.createElement(Form.Root, {
|
|
2219
2858
|
key: field.id,
|
|
2220
2859
|
fieldMap,
|
|
2221
2860
|
autoFocus: true,
|
|
@@ -2231,100 +2870,100 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2231
2870
|
onValidate: handleValidate,
|
|
2232
2871
|
onSave: handleSave,
|
|
2233
2872
|
onCancel: handleCancel
|
|
2234
|
-
}, /* @__PURE__ */
|
|
2873
|
+
}, /* @__PURE__ */ React20.createElement(Form.Content, null, /* @__PURE__ */ React20.createElement(Form.FieldSet, null), /* @__PURE__ */ React20.createElement(Form.Actions, null)));
|
|
2235
2874
|
};
|
|
2236
2875
|
|
|
2237
2876
|
// src/components/ObjectForm/ObjectForm.tsx
|
|
2238
|
-
import
|
|
2239
|
-
import
|
|
2240
|
-
import {
|
|
2241
|
-
import { splitJsonPath } from "@dxos/echo/internal";
|
|
2877
|
+
import React21, { useCallback as useCallback17, useMemo as useMemo11 } from "react";
|
|
2878
|
+
import { Obj as Obj5, Ref as Ref7, Tag as Tag3, Type as Type5 } from "@dxos/echo";
|
|
2879
|
+
import { splitJsonPath as splitJsonPath2 } from "@dxos/echo/internal";
|
|
2242
2880
|
import { invariant } from "@dxos/invariant";
|
|
2243
2881
|
import { HuePicker as HuePicker2 } from "@dxos/react-ui-pickers";
|
|
2244
|
-
import {
|
|
2245
|
-
import { translationKey as translationKey10 } from "#translations";
|
|
2882
|
+
import { translationKey as translationKey11 } from "#translations";
|
|
2246
2883
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ObjectForm/ObjectForm.tsx";
|
|
2247
2884
|
var createFieldMap = {
|
|
2248
2885
|
hue: ({ type, label, layout, getValue, onValueChange }) => {
|
|
2249
|
-
const handleChange =
|
|
2886
|
+
const handleChange = useCallback17((nextHue) => onValueChange(type, nextHue), [
|
|
2250
2887
|
onValueChange,
|
|
2251
2888
|
type
|
|
2252
2889
|
]);
|
|
2253
|
-
const handleReset =
|
|
2890
|
+
const handleReset = useCallback17(() => onValueChange(type, void 0), [
|
|
2254
2891
|
onValueChange,
|
|
2255
2892
|
type
|
|
2256
2893
|
]);
|
|
2257
|
-
return /* @__PURE__ */
|
|
2894
|
+
return /* @__PURE__ */ React21.createElement(React21.Fragment, null, layout !== "inline" && /* @__PURE__ */ React21.createElement(Form.Label, {
|
|
2258
2895
|
label
|
|
2259
|
-
}), /* @__PURE__ */
|
|
2896
|
+
}), /* @__PURE__ */ React21.createElement(HuePicker2, {
|
|
2260
2897
|
value: getValue(),
|
|
2261
2898
|
onChange: handleChange,
|
|
2262
2899
|
onReset: handleReset
|
|
2263
2900
|
}));
|
|
2264
2901
|
}
|
|
2265
2902
|
};
|
|
2266
|
-
var ObjectForm = ({ object,
|
|
2267
|
-
const db =
|
|
2268
|
-
const meta =
|
|
2269
|
-
const tags =
|
|
2270
|
-
|
|
2271
|
-
|
|
2903
|
+
var ObjectForm = ({ object, type }) => {
|
|
2904
|
+
const db = Obj5.getDatabase(object);
|
|
2905
|
+
const meta = Obj5.getMeta(object);
|
|
2906
|
+
const tags = [
|
|
2907
|
+
...meta.tags
|
|
2908
|
+
];
|
|
2909
|
+
const values = useMemo11(() => ({
|
|
2910
|
+
[META_TAGS_KEY]: tags,
|
|
2272
2911
|
...object
|
|
2273
2912
|
}), [
|
|
2274
2913
|
object,
|
|
2275
2914
|
tags
|
|
2276
2915
|
]);
|
|
2277
|
-
const formSchema =
|
|
2278
|
-
|
|
2279
|
-
}).pipe(Schema3.extend(schema))), [
|
|
2280
|
-
schema
|
|
2916
|
+
const formSchema = useMemo11(() => withMetaTags(Type5.getSchema(type)), [
|
|
2917
|
+
type
|
|
2281
2918
|
]);
|
|
2282
|
-
const handleCreate =
|
|
2283
|
-
invariant(db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L:
|
|
2284
|
-
invariant(
|
|
2285
|
-
const newObject = db.add(
|
|
2286
|
-
if (
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
...
|
|
2290
|
-
|
|
2919
|
+
const handleCreate = useCallback17((type2, values2) => {
|
|
2920
|
+
invariant(db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 48, S: void 0, A: ["db", ""] });
|
|
2921
|
+
invariant(Type5.isObject(type2), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 49, S: void 0, A: ["Type.isObject(type)", ""] });
|
|
2922
|
+
const newObject = db.add(Obj5.make(type2, values2));
|
|
2923
|
+
if (Obj5.instanceOf(Tag3.Tag, newObject)) {
|
|
2924
|
+
Obj5.update(object, (object2) => {
|
|
2925
|
+
Obj5.getMeta(object2).tags = [
|
|
2926
|
+
...Obj5.getMeta(object2).tags,
|
|
2927
|
+
Ref7.make(newObject)
|
|
2291
2928
|
];
|
|
2292
2929
|
});
|
|
2293
2930
|
}
|
|
2294
2931
|
}, []);
|
|
2295
|
-
const handleChange =
|
|
2932
|
+
const handleChange = useCallback17(({ [META_TAGS_KEY]: metaTags, ...values2 }, { isValid, changed }) => {
|
|
2296
2933
|
if (!isValid) {
|
|
2297
2934
|
return;
|
|
2298
2935
|
}
|
|
2299
2936
|
const changedPaths = Object.keys(changed).filter((path) => changed[path]);
|
|
2300
|
-
const hasTagsChange = changedPaths.some((path) =>
|
|
2937
|
+
const hasTagsChange = changedPaths.some((path) => splitJsonPath2(path)[0] === META_TAGS_KEY);
|
|
2301
2938
|
if (hasTagsChange) {
|
|
2302
|
-
|
|
2303
|
-
|
|
2939
|
+
Obj5.update(object, (object2) => {
|
|
2940
|
+
Obj5.getMeta(object2).tags = Array.isArray(metaTags) ? [
|
|
2941
|
+
...metaTags
|
|
2942
|
+
] : [];
|
|
2304
2943
|
});
|
|
2305
2944
|
}
|
|
2306
|
-
const nonTagPaths = changedPaths.filter((path) =>
|
|
2945
|
+
const nonTagPaths = changedPaths.filter((path) => splitJsonPath2(path)[0] !== META_TAGS_KEY);
|
|
2307
2946
|
if (nonTagPaths.length > 0) {
|
|
2308
|
-
|
|
2947
|
+
Obj5.update(object, () => {
|
|
2309
2948
|
for (const path of nonTagPaths) {
|
|
2310
|
-
const parts =
|
|
2311
|
-
const value3 =
|
|
2312
|
-
|
|
2949
|
+
const parts = splitJsonPath2(path);
|
|
2950
|
+
const value3 = Obj5.getValue(values2, parts);
|
|
2951
|
+
Obj5.setValue(object, parts, value3);
|
|
2313
2952
|
}
|
|
2314
2953
|
});
|
|
2315
2954
|
}
|
|
2316
2955
|
}, [
|
|
2317
2956
|
object
|
|
2318
2957
|
]);
|
|
2319
|
-
return /* @__PURE__ */
|
|
2958
|
+
return /* @__PURE__ */ React21.createElement(Form.Root, {
|
|
2320
2959
|
schema: formSchema,
|
|
2321
2960
|
defaultValues: values,
|
|
2322
|
-
createTypename:
|
|
2961
|
+
createTypename: Type5.getTypename(Tag3.Tag),
|
|
2323
2962
|
createOptionIcon: "ph--plus--regular",
|
|
2324
2963
|
createOptionLabel: [
|
|
2325
2964
|
"add-tag.label",
|
|
2326
2965
|
{
|
|
2327
|
-
ns:
|
|
2966
|
+
ns: translationKey11
|
|
2328
2967
|
}
|
|
2329
2968
|
],
|
|
2330
2969
|
createInitialValuePath: "label",
|
|
@@ -2332,70 +2971,72 @@ var ObjectForm = ({ object, schema }) => {
|
|
|
2332
2971
|
db,
|
|
2333
2972
|
onValuesChanged: handleChange,
|
|
2334
2973
|
onCreate: handleCreate
|
|
2335
|
-
}, /* @__PURE__ */
|
|
2974
|
+
}, /* @__PURE__ */ React21.createElement(Form.Viewport, null, /* @__PURE__ */ React21.createElement(Form.Content, null, /* @__PURE__ */ React21.createElement(Form.FieldSet, null))));
|
|
2336
2975
|
};
|
|
2337
2976
|
|
|
2338
2977
|
// src/components/ObjectProperties/ObjectProperties.tsx
|
|
2339
2978
|
import * as Function from "effect/Function";
|
|
2340
|
-
import * as
|
|
2341
|
-
import
|
|
2342
|
-
import
|
|
2343
|
-
import {
|
|
2344
|
-
import {
|
|
2345
|
-
import { splitJsonPath as splitJsonPath2 } from "@dxos/echo/internal";
|
|
2979
|
+
import * as Option7 from "effect/Option";
|
|
2980
|
+
import React22, { useCallback as useCallback18, useMemo as useMemo12 } from "react";
|
|
2981
|
+
import { Obj as Obj6, Tag as Tag4, Type as Type6 } from "@dxos/echo";
|
|
2982
|
+
import { useType } from "@dxos/echo-react";
|
|
2983
|
+
import { splitJsonPath as splitJsonPath3 } from "@dxos/echo/internal";
|
|
2346
2984
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2985
|
+
import { composable as composable2, composableProps as composableProps2 } from "@dxos/react-ui";
|
|
2347
2986
|
import { HuePicker as HuePicker3 } from "@dxos/react-ui-pickers";
|
|
2348
2987
|
import { FactoryAnnotation } from "@dxos/schema";
|
|
2349
|
-
import {
|
|
2350
|
-
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2351
|
-
import { translationKey as translationKey11 } from "#translations";
|
|
2988
|
+
import { translationKey as translationKey12 } from "#translations";
|
|
2352
2989
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ObjectProperties/ObjectProperties.tsx";
|
|
2353
2990
|
var ObjectProperties = composable2(({ children, object, ...props }, forwardedRef) => {
|
|
2354
|
-
const db =
|
|
2355
|
-
const meta =
|
|
2356
|
-
const tags =
|
|
2357
|
-
|
|
2358
|
-
|
|
2991
|
+
const db = Obj6.getDatabase(object);
|
|
2992
|
+
const meta = Obj6.getMeta(object);
|
|
2993
|
+
const tags = [
|
|
2994
|
+
...meta.tags
|
|
2995
|
+
];
|
|
2996
|
+
const values = useMemo12(() => ({
|
|
2997
|
+
[META_TAGS_KEY]: tags,
|
|
2359
2998
|
...object
|
|
2360
2999
|
}), [
|
|
2361
3000
|
object,
|
|
2362
3001
|
tags
|
|
2363
3002
|
]);
|
|
2364
|
-
const typename =
|
|
2365
|
-
const
|
|
2366
|
-
const
|
|
2367
|
-
const formSchema =
|
|
2368
|
-
return Function.pipe(
|
|
3003
|
+
const typename = Obj6.getTypename(object) ?? void 0;
|
|
3004
|
+
const typeFromRegistry = useType(db, typename);
|
|
3005
|
+
const type = Obj6.getType(object) ?? typeFromRegistry;
|
|
3006
|
+
const formSchema = useMemo12(() => {
|
|
3007
|
+
return Function.pipe(type, Option7.fromNullable, Option7.map((type2) => Type6.getSchema(type2)), Option7.map((schema) => withMetaTags(schema)), Option7.getOrUndefined);
|
|
2369
3008
|
}, [
|
|
2370
|
-
|
|
3009
|
+
type
|
|
2371
3010
|
]);
|
|
2372
|
-
const handleCreate =
|
|
2373
|
-
invariant2(db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
2374
|
-
invariant2(
|
|
2375
|
-
const factory =
|
|
2376
|
-
const newObject = factory ? factory(values2) :
|
|
3011
|
+
const handleCreate = useCallback18((type2, values2) => {
|
|
3012
|
+
invariant2(db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 52, S: void 0, A: ["db", ""] });
|
|
3013
|
+
invariant2(Type6.isObject(type2), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 53, S: void 0, A: ["Type.isObject(type)", ""] });
|
|
3014
|
+
const factory = Option7.getOrUndefined(FactoryAnnotation.get(Type6.getSchema(type2)));
|
|
3015
|
+
const newObject = factory ? factory(values2) : Obj6.make(type2, values2);
|
|
2377
3016
|
return db.add(newObject);
|
|
2378
3017
|
}, [
|
|
2379
3018
|
db
|
|
2380
3019
|
]);
|
|
2381
|
-
const handleChange =
|
|
3020
|
+
const handleChange = useCallback18(({ [META_TAGS_KEY]: metaTags, ...values2 }, { isValid, changed }) => {
|
|
2382
3021
|
if (!isValid) {
|
|
2383
3022
|
return;
|
|
2384
3023
|
}
|
|
2385
3024
|
const changedPaths = Object.keys(changed).filter((path) => changed[path]);
|
|
2386
|
-
const hasTagsChange = changedPaths.some((path) =>
|
|
3025
|
+
const hasTagsChange = changedPaths.some((path) => splitJsonPath3(path)[0] === META_TAGS_KEY);
|
|
2387
3026
|
if (hasTagsChange) {
|
|
2388
|
-
|
|
2389
|
-
|
|
3027
|
+
Obj6.update(object, (object2) => {
|
|
3028
|
+
Obj6.getMeta(object2).tags = Array.isArray(metaTags) ? [
|
|
3029
|
+
...metaTags
|
|
3030
|
+
] : [];
|
|
2390
3031
|
});
|
|
2391
3032
|
}
|
|
2392
|
-
const nonTagPaths = changedPaths.filter((path) =>
|
|
3033
|
+
const nonTagPaths = changedPaths.filter((path) => splitJsonPath3(path)[0] !== META_TAGS_KEY);
|
|
2393
3034
|
if (nonTagPaths.length > 0) {
|
|
2394
|
-
|
|
3035
|
+
Obj6.update(object, () => {
|
|
2395
3036
|
for (const path of nonTagPaths) {
|
|
2396
|
-
const parts =
|
|
2397
|
-
const value3 =
|
|
2398
|
-
|
|
3037
|
+
const parts = splitJsonPath3(path);
|
|
3038
|
+
const value3 = Obj6.getValue(values2, parts);
|
|
3039
|
+
Obj6.setValue(object, parts, value3);
|
|
2399
3040
|
}
|
|
2400
3041
|
});
|
|
2401
3042
|
}
|
|
@@ -2405,15 +3046,15 @@ var ObjectProperties = composable2(({ children, object, ...props }, forwardedRef
|
|
|
2405
3046
|
if (!formSchema) {
|
|
2406
3047
|
return null;
|
|
2407
3048
|
}
|
|
2408
|
-
return /* @__PURE__ */
|
|
3049
|
+
return /* @__PURE__ */ React22.createElement(Form.Root, {
|
|
2409
3050
|
schema: formSchema,
|
|
2410
3051
|
defaultValues: values,
|
|
2411
|
-
createTypename:
|
|
3052
|
+
createTypename: Type6.getTypename(Tag4.Tag),
|
|
2412
3053
|
createOptionIcon: "ph--plus--regular",
|
|
2413
3054
|
createOptionLabel: [
|
|
2414
3055
|
"add-tag.label",
|
|
2415
3056
|
{
|
|
2416
|
-
ns:
|
|
3057
|
+
ns: translationKey12
|
|
2417
3058
|
}
|
|
2418
3059
|
],
|
|
2419
3060
|
createInitialValuePath: "label",
|
|
@@ -2421,69 +3062,190 @@ var ObjectProperties = composable2(({ children, object, ...props }, forwardedRef
|
|
|
2421
3062
|
db,
|
|
2422
3063
|
onValuesChanged: handleChange,
|
|
2423
3064
|
onCreate: handleCreate
|
|
2424
|
-
}, /* @__PURE__ */
|
|
3065
|
+
}, /* @__PURE__ */ React22.createElement(Form.Viewport, {
|
|
2425
3066
|
...composableProps2(props),
|
|
2426
3067
|
ref: forwardedRef
|
|
2427
|
-
}, /* @__PURE__ */
|
|
3068
|
+
}, /* @__PURE__ */ React22.createElement(Form.Content, null, /* @__PURE__ */ React22.createElement(Form.FieldSet, null), children)));
|
|
2428
3069
|
});
|
|
2429
3070
|
var createFieldMap2 = {
|
|
2430
3071
|
hue: ({ type, label, layout, getValue, onValueChange }) => {
|
|
2431
|
-
const handleChange =
|
|
3072
|
+
const handleChange = useCallback18((nextHue) => onValueChange(type, nextHue), [
|
|
2432
3073
|
onValueChange,
|
|
2433
3074
|
type
|
|
2434
3075
|
]);
|
|
2435
|
-
const handleReset =
|
|
3076
|
+
const handleReset = useCallback18(() => onValueChange(type, void 0), [
|
|
2436
3077
|
onValueChange,
|
|
2437
3078
|
type
|
|
2438
3079
|
]);
|
|
2439
|
-
return /* @__PURE__ */
|
|
3080
|
+
return /* @__PURE__ */ React22.createElement(React22.Fragment, null, layout !== "inline" && /* @__PURE__ */ React22.createElement(Form.Label, {
|
|
2440
3081
|
label
|
|
2441
|
-
}), /* @__PURE__ */
|
|
3082
|
+
}), /* @__PURE__ */ React22.createElement(HuePicker3, {
|
|
2442
3083
|
value: getValue(),
|
|
2443
3084
|
onChange: handleChange,
|
|
2444
3085
|
onReset: handleReset
|
|
2445
3086
|
}));
|
|
2446
3087
|
}
|
|
2447
3088
|
};
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
3089
|
+
|
|
3090
|
+
// src/components/ObjectTree/ObjectTree.tsx
|
|
3091
|
+
import * as SchemaAST7 from "effect/SchemaAST";
|
|
3092
|
+
import React23 from "react";
|
|
3093
|
+
import { composable as composable3, composableProps as composableProps3 } from "@dxos/react-ui";
|
|
3094
|
+
import { mx as mx5 } from "@dxos/ui-theme";
|
|
3095
|
+
var ObjectTreeImpl = composable3(({ schema, value: value3, ...props }, forwardedRef) => /* @__PURE__ */ React23.createElement("div", {
|
|
3096
|
+
...composableProps3(props, {
|
|
3097
|
+
role: "table",
|
|
3098
|
+
classNames: "font-mono text-sm w-full"
|
|
3099
|
+
}),
|
|
3100
|
+
ref: forwardedRef
|
|
3101
|
+
}, /* @__PURE__ */ React23.createElement(Node, {
|
|
3102
|
+
ast: schema.ast,
|
|
3103
|
+
value: value3,
|
|
3104
|
+
label: null,
|
|
3105
|
+
depth: 0
|
|
3106
|
+
})));
|
|
3107
|
+
ObjectTreeImpl.displayName = "ObjectTree";
|
|
3108
|
+
var ObjectTree = ObjectTreeImpl;
|
|
3109
|
+
var unwrap = (ast) => {
|
|
3110
|
+
if (SchemaAST7.isRefinement(ast)) {
|
|
3111
|
+
return unwrap(ast.from);
|
|
3112
|
+
}
|
|
3113
|
+
if (SchemaAST7.isSuspend(ast)) {
|
|
3114
|
+
return unwrap(ast.f());
|
|
3115
|
+
}
|
|
3116
|
+
if (SchemaAST7.isTransformation(ast)) {
|
|
3117
|
+
return unwrap(ast.from);
|
|
3118
|
+
}
|
|
3119
|
+
return ast;
|
|
3120
|
+
};
|
|
3121
|
+
var stripOptional = (ast) => {
|
|
3122
|
+
if (!SchemaAST7.isUnion(ast)) {
|
|
3123
|
+
return ast;
|
|
3124
|
+
}
|
|
3125
|
+
const nonUndef = ast.types.filter((t) => !SchemaAST7.isUndefinedKeyword(t));
|
|
3126
|
+
return nonUndef.length === 1 ? nonUndef[0] : ast;
|
|
3127
|
+
};
|
|
3128
|
+
var Node = ({ ast, value: value3, label, depth }) => {
|
|
3129
|
+
const inner = unwrap(stripOptional(ast));
|
|
3130
|
+
if (SchemaAST7.isTypeLiteral(inner) && isPlainObject(value3)) {
|
|
3131
|
+
const childDepth = label === null ? depth : depth + 1;
|
|
3132
|
+
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, label !== null && /* @__PURE__ */ React23.createElement(Row, {
|
|
3133
|
+
label,
|
|
3134
|
+
value: null,
|
|
3135
|
+
depth,
|
|
3136
|
+
kind: "group"
|
|
3137
|
+
}), inner.propertySignatures.map((prop) => /* @__PURE__ */ React23.createElement(Node, {
|
|
3138
|
+
key: String(prop.name),
|
|
3139
|
+
ast: prop.type,
|
|
3140
|
+
value: value3[String(prop.name)],
|
|
3141
|
+
label: String(prop.name),
|
|
3142
|
+
depth: childDepth
|
|
3143
|
+
})));
|
|
3144
|
+
}
|
|
3145
|
+
if (SchemaAST7.isTupleType(inner) && Array.isArray(value3)) {
|
|
3146
|
+
const elemType = inner.rest[0]?.type;
|
|
3147
|
+
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, label !== null && /* @__PURE__ */ React23.createElement(Row, {
|
|
3148
|
+
label,
|
|
3149
|
+
value: `Array(${value3.length})`,
|
|
3150
|
+
depth,
|
|
3151
|
+
kind: "group"
|
|
3152
|
+
}), value3.map((item, index) => /* @__PURE__ */ React23.createElement(Node, {
|
|
3153
|
+
key: index,
|
|
3154
|
+
ast: elemType ?? SchemaAST7.unknownKeyword,
|
|
3155
|
+
value: item,
|
|
3156
|
+
label: `[${index}]`,
|
|
3157
|
+
depth: depth + 1
|
|
3158
|
+
})));
|
|
3159
|
+
}
|
|
3160
|
+
return /* @__PURE__ */ React23.createElement(Row, {
|
|
3161
|
+
label: label ?? "",
|
|
3162
|
+
value: formatLeaf(value3),
|
|
3163
|
+
depth,
|
|
3164
|
+
kind: "leaf"
|
|
3165
|
+
});
|
|
3166
|
+
};
|
|
3167
|
+
var Row = ({ label, value: value3, depth }) => /* @__PURE__ */ React23.createElement("div", {
|
|
3168
|
+
role: "row",
|
|
3169
|
+
className: mx5("flex items-baseline gap-3 py-1"),
|
|
3170
|
+
style: {
|
|
3171
|
+
paddingInlineStart: 8 + depth * 16
|
|
3172
|
+
}
|
|
3173
|
+
}, /* @__PURE__ */ React23.createElement("div", {
|
|
3174
|
+
role: "cell",
|
|
3175
|
+
className: "text-subdued"
|
|
3176
|
+
}, label), /* @__PURE__ */ React23.createElement("div", {
|
|
3177
|
+
role: "cell",
|
|
3178
|
+
className: mx5("break-all text-base-fg")
|
|
3179
|
+
}, value3));
|
|
3180
|
+
var isPlainObject = (value3) => typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
3181
|
+
var formatLeaf = (value3) => {
|
|
3182
|
+
if (value3 === void 0) {
|
|
3183
|
+
return null;
|
|
3184
|
+
}
|
|
3185
|
+
if (value3 === null) {
|
|
3186
|
+
return /* @__PURE__ */ React23.createElement("span", {
|
|
3187
|
+
className: "text-description"
|
|
3188
|
+
}, "null");
|
|
3189
|
+
}
|
|
3190
|
+
switch (typeof value3) {
|
|
3191
|
+
case "string":
|
|
3192
|
+
return /* @__PURE__ */ React23.createElement("span", {
|
|
3193
|
+
className: "text-blue-text"
|
|
3194
|
+
}, JSON.stringify(value3));
|
|
3195
|
+
case "number":
|
|
3196
|
+
case "bigint":
|
|
3197
|
+
return /* @__PURE__ */ React23.createElement("span", {
|
|
3198
|
+
className: "text-green-text"
|
|
3199
|
+
}, String(value3));
|
|
3200
|
+
case "boolean":
|
|
3201
|
+
return /* @__PURE__ */ React23.createElement("span", {
|
|
3202
|
+
className: "text-purple-text"
|
|
3203
|
+
}, String(value3));
|
|
3204
|
+
default:
|
|
3205
|
+
try {
|
|
3206
|
+
return JSON.stringify(value3);
|
|
3207
|
+
} catch {
|
|
3208
|
+
return String(value3);
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
};
|
|
2451
3212
|
|
|
2452
3213
|
// src/components/Settings/Settings.tsx
|
|
2453
|
-
import
|
|
2454
|
-
import { ScrollArea as ScrollArea2, toLocalizedString as toLocalizedString2, useTranslation as
|
|
2455
|
-
import { composable as
|
|
2456
|
-
import {
|
|
3214
|
+
import React26 from "react";
|
|
3215
|
+
import { ScrollArea as ScrollArea2, toLocalizedString as toLocalizedString2, useTranslation as useTranslation12 } from "@dxos/react-ui";
|
|
3216
|
+
import { composable as composable4, composableProps as composableProps4 } from "@dxos/react-ui";
|
|
3217
|
+
import { mx as mx7 } from "@dxos/ui-theme";
|
|
3218
|
+
import { translationKey as translationKey14 } from "#translations";
|
|
2457
3219
|
|
|
2458
3220
|
// src/components/Settings/SettingsFieldSet.tsx
|
|
2459
|
-
import * as
|
|
2460
|
-
import * as
|
|
2461
|
-
import
|
|
2462
|
-
import { getAnnotation as
|
|
2463
|
-
import { Input as
|
|
3221
|
+
import * as SchemaAST8 from "effect/SchemaAST";
|
|
3222
|
+
import * as String4 from "effect/String";
|
|
3223
|
+
import React25, { useCallback as useCallback19, useMemo as useMemo13 } from "react";
|
|
3224
|
+
import { getAnnotation as getAnnotation4 } from "@dxos/effect";
|
|
3225
|
+
import { Input as Input17, Select as Select2 } from "@dxos/react-ui";
|
|
2464
3226
|
|
|
2465
3227
|
// src/components/Settings/SettingsItem.tsx
|
|
2466
|
-
import
|
|
2467
|
-
import { Input as
|
|
2468
|
-
import { mx as
|
|
2469
|
-
import { translationKey as
|
|
3228
|
+
import React24 from "react";
|
|
3229
|
+
import { Input as Input16, toLocalizedString, useTranslation as useTranslation11 } from "@dxos/react-ui";
|
|
3230
|
+
import { mx as mx6 } from "@dxos/ui-theme";
|
|
3231
|
+
import { translationKey as translationKey13 } from "#translations";
|
|
2470
3232
|
var SETTINGS_PANEL_NAME = "Settings.Panel";
|
|
2471
3233
|
var SETTINGS_ITEM_NAME = "Settings.Item";
|
|
2472
3234
|
var SettingsPanel = ({ classNames, children }) => {
|
|
2473
|
-
return /* @__PURE__ */
|
|
2474
|
-
className:
|
|
3235
|
+
return /* @__PURE__ */ React24.createElement("div", {
|
|
3236
|
+
className: mx6("flex flex-col gap-3 p-trim-md border border-separator rounded-sm", classNames)
|
|
2475
3237
|
}, children);
|
|
2476
3238
|
};
|
|
2477
3239
|
SettingsPanel.displayName = SETTINGS_PANEL_NAME;
|
|
2478
3240
|
var SettingsItem = ({ title, description = "", children }) => {
|
|
2479
|
-
const { t } =
|
|
2480
|
-
return /* @__PURE__ */
|
|
3241
|
+
const { t } = useTranslation11(translationKey13);
|
|
3242
|
+
return /* @__PURE__ */ React24.createElement(Input16.Root, null, /* @__PURE__ */ React24.createElement(SettingsPanel, {
|
|
2481
3243
|
classNames: "grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0"
|
|
2482
|
-
}, /* @__PURE__ */
|
|
2483
|
-
classNames: "pb-trim-md text-base-
|
|
2484
|
-
}, toLocalizedString(title, t)), /* @__PURE__ */
|
|
3244
|
+
}, /* @__PURE__ */ React24.createElement(Input16.Label, {
|
|
3245
|
+
classNames: "pb-trim-md text-base-fg text-lg md:col-span-2"
|
|
3246
|
+
}, toLocalizedString(title, t)), /* @__PURE__ */ React24.createElement(Input16.DescriptionAndValidation, null, /* @__PURE__ */ React24.createElement(Input16.Description, {
|
|
2485
3247
|
classNames: "text-base text-description"
|
|
2486
|
-
}, toLocalizedString(description, t))), /* @__PURE__ */
|
|
3248
|
+
}, toLocalizedString(description, t))), /* @__PURE__ */ React24.createElement("div", {
|
|
2487
3249
|
className: "text-end py-1"
|
|
2488
3250
|
}, children)));
|
|
2489
3251
|
};
|
|
@@ -2491,7 +3253,7 @@ SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
|
2491
3253
|
|
|
2492
3254
|
// src/components/Settings/SettingsFieldSet.tsx
|
|
2493
3255
|
var SettingsFieldSet = ({ schema, values, onValuesChanged, readonly, fieldMap, visible, sort, pathPrefix = "" }) => {
|
|
2494
|
-
const properties =
|
|
3256
|
+
const properties = useMemo13(() => {
|
|
2495
3257
|
const props = getFormProperties(schema.ast);
|
|
2496
3258
|
if (!sort) {
|
|
2497
3259
|
return props;
|
|
@@ -2507,7 +3269,7 @@ var SettingsFieldSet = ({ schema, values, onValuesChanged, readonly, fieldMap, v
|
|
|
2507
3269
|
schema,
|
|
2508
3270
|
sort
|
|
2509
3271
|
]);
|
|
2510
|
-
const handleChange =
|
|
3272
|
+
const handleChange = useCallback19((name, value3) => {
|
|
2511
3273
|
onValuesChanged?.({
|
|
2512
3274
|
...values,
|
|
2513
3275
|
[name]: value3
|
|
@@ -2516,14 +3278,14 @@ var SettingsFieldSet = ({ schema, values, onValuesChanged, readonly, fieldMap, v
|
|
|
2516
3278
|
values,
|
|
2517
3279
|
onValuesChanged
|
|
2518
3280
|
]);
|
|
2519
|
-
return /* @__PURE__ */
|
|
3281
|
+
return /* @__PURE__ */ React25.createElement(React25.Fragment, null, properties.map((property) => {
|
|
2520
3282
|
const name = property.name.toString();
|
|
2521
3283
|
const path = pathPrefix ? `${pathPrefix}.${name}` : name;
|
|
2522
3284
|
if (visible && !visible(path, values)) {
|
|
2523
3285
|
return null;
|
|
2524
3286
|
}
|
|
2525
3287
|
const entry = fieldMap?.[name];
|
|
2526
|
-
return /* @__PURE__ */
|
|
3288
|
+
return /* @__PURE__ */ React25.createElement(SettingsFieldItem, {
|
|
2527
3289
|
key: name,
|
|
2528
3290
|
path,
|
|
2529
3291
|
property,
|
|
@@ -2541,14 +3303,14 @@ SettingsFieldSet.displayName = "Settings.FieldSet";
|
|
|
2541
3303
|
var SettingsFieldItem = ({ property, path, value: value3, onChange, readonly, customField, nestedFieldMap, visible, sort }) => {
|
|
2542
3304
|
const { type } = property;
|
|
2543
3305
|
const name = property.name.toString();
|
|
2544
|
-
const title =
|
|
2545
|
-
const description =
|
|
3306
|
+
const title = getAnnotation4(SchemaAST8.TitleAnnotationId)(type) ?? String4.capitalize(name);
|
|
3307
|
+
const description = getAnnotation4(SchemaAST8.DescriptionAnnotationId)(type);
|
|
2546
3308
|
if (customField) {
|
|
2547
3309
|
const CustomField = customField;
|
|
2548
|
-
return /* @__PURE__ */
|
|
3310
|
+
return /* @__PURE__ */ React25.createElement(SettingsItem, {
|
|
2549
3311
|
title,
|
|
2550
3312
|
description
|
|
2551
|
-
}, /* @__PURE__ */
|
|
3313
|
+
}, /* @__PURE__ */ React25.createElement(CustomField, {
|
|
2552
3314
|
value: value3,
|
|
2553
3315
|
onChange,
|
|
2554
3316
|
readonly
|
|
@@ -2557,7 +3319,7 @@ var SettingsFieldItem = ({ property, path, value: value3, onChange, readonly, cu
|
|
|
2557
3319
|
const fieldType = detectFieldType(type);
|
|
2558
3320
|
switch (fieldType) {
|
|
2559
3321
|
case "struct":
|
|
2560
|
-
return /* @__PURE__ */
|
|
3322
|
+
return /* @__PURE__ */ React25.createElement(SettingsFieldSet, {
|
|
2561
3323
|
schema: {
|
|
2562
3324
|
ast: type
|
|
2563
3325
|
},
|
|
@@ -2570,47 +3332,47 @@ var SettingsFieldItem = ({ property, path, value: value3, onChange, readonly, cu
|
|
|
2570
3332
|
pathPrefix: path
|
|
2571
3333
|
});
|
|
2572
3334
|
case "boolean":
|
|
2573
|
-
return /* @__PURE__ */
|
|
3335
|
+
return /* @__PURE__ */ React25.createElement(SettingsItem, {
|
|
2574
3336
|
title,
|
|
2575
3337
|
description
|
|
2576
|
-
}, /* @__PURE__ */
|
|
3338
|
+
}, /* @__PURE__ */ React25.createElement(Input17.Switch, {
|
|
2577
3339
|
disabled: readonly,
|
|
2578
3340
|
checked: !!value3,
|
|
2579
3341
|
onCheckedChange: (checked) => onChange(!!checked)
|
|
2580
3342
|
}));
|
|
2581
3343
|
case "select": {
|
|
2582
3344
|
const options = getSelectOptionsFromAst(type) ?? [];
|
|
2583
|
-
return /* @__PURE__ */
|
|
3345
|
+
return /* @__PURE__ */ React25.createElement(SettingsItem, {
|
|
2584
3346
|
title,
|
|
2585
3347
|
description
|
|
2586
|
-
}, /* @__PURE__ */
|
|
3348
|
+
}, /* @__PURE__ */ React25.createElement(Select2.Root, {
|
|
2587
3349
|
disabled: readonly,
|
|
2588
3350
|
value: value3 == null ? "" : globalThis.String(value3),
|
|
2589
3351
|
onValueChange: (selected) => {
|
|
2590
3352
|
const matched = options.find((option) => globalThis.String(option.value) === selected);
|
|
2591
3353
|
onChange(matched?.value ?? selected);
|
|
2592
3354
|
}
|
|
2593
|
-
}, /* @__PURE__ */
|
|
3355
|
+
}, /* @__PURE__ */ React25.createElement(Select2.TriggerButton, {
|
|
2594
3356
|
disabled: readonly
|
|
2595
|
-
}), /* @__PURE__ */
|
|
3357
|
+
}), /* @__PURE__ */ React25.createElement(Select2.Portal, null, /* @__PURE__ */ React25.createElement(Select2.Content, null, /* @__PURE__ */ React25.createElement(Select2.Viewport, null, options.map((option) => /* @__PURE__ */ React25.createElement(Select2.Option, {
|
|
2596
3358
|
key: globalThis.String(option.value),
|
|
2597
3359
|
value: globalThis.String(option.value)
|
|
2598
|
-
}, option.label ?? globalThis.String(option.value)))), /* @__PURE__ */
|
|
3360
|
+
}, option.label ?? globalThis.String(option.value)))), /* @__PURE__ */ React25.createElement(Select2.Arrow, null)))));
|
|
2599
3361
|
}
|
|
2600
3362
|
case "string":
|
|
2601
|
-
return /* @__PURE__ */
|
|
3363
|
+
return /* @__PURE__ */ React25.createElement(SettingsItem, {
|
|
2602
3364
|
title,
|
|
2603
3365
|
description
|
|
2604
|
-
}, /* @__PURE__ */
|
|
3366
|
+
}, /* @__PURE__ */ React25.createElement(Input17.TextInput, {
|
|
2605
3367
|
disabled: readonly,
|
|
2606
3368
|
value: value3 ?? "",
|
|
2607
3369
|
onChange: (event) => onChange(event.target.value)
|
|
2608
3370
|
}));
|
|
2609
3371
|
case "number":
|
|
2610
|
-
return /* @__PURE__ */
|
|
3372
|
+
return /* @__PURE__ */ React25.createElement(SettingsItem, {
|
|
2611
3373
|
title,
|
|
2612
3374
|
description
|
|
2613
|
-
}, /* @__PURE__ */
|
|
3375
|
+
}, /* @__PURE__ */ React25.createElement(Input17.TextInput, {
|
|
2614
3376
|
disabled: readonly,
|
|
2615
3377
|
type: "number",
|
|
2616
3378
|
value: value3 ?? "",
|
|
@@ -2633,32 +3395,32 @@ var SETTINGS_ROOT_NAME = "Settings.Root";
|
|
|
2633
3395
|
var SETTINGS_VIEWPORT_NAME = "Settings.Viewport";
|
|
2634
3396
|
var SETTINGS_SECTION_NAME = "Settings.Section";
|
|
2635
3397
|
var SettingsRoot = ({ children, classNames }) => {
|
|
2636
|
-
return /* @__PURE__ */
|
|
2637
|
-
className:
|
|
3398
|
+
return /* @__PURE__ */ React26.createElement("div", {
|
|
3399
|
+
className: mx7("flex flex-col gap-2", classNames)
|
|
2638
3400
|
}, children);
|
|
2639
3401
|
};
|
|
2640
3402
|
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
2641
|
-
var SettingsViewport =
|
|
2642
|
-
return /* @__PURE__ */
|
|
2643
|
-
...
|
|
3403
|
+
var SettingsViewport = composable4(({ children, ...props }, forwardedRef) => {
|
|
3404
|
+
return /* @__PURE__ */ React26.createElement(ScrollArea2.Root, {
|
|
3405
|
+
...composableProps4(props),
|
|
2644
3406
|
orientation: "vertical",
|
|
2645
3407
|
centered: true,
|
|
2646
3408
|
thin: true,
|
|
2647
3409
|
ref: forwardedRef
|
|
2648
|
-
}, /* @__PURE__ */
|
|
3410
|
+
}, /* @__PURE__ */ React26.createElement(ScrollArea2.Viewport, {
|
|
2649
3411
|
classNames: "px-4 pointer-coarse:px-2"
|
|
2650
|
-
}, /* @__PURE__ */
|
|
3412
|
+
}, /* @__PURE__ */ React26.createElement("div", {
|
|
2651
3413
|
className: "dx-document flex flex-col gap-2 py-4"
|
|
2652
3414
|
}, children)));
|
|
2653
3415
|
});
|
|
2654
3416
|
SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
|
|
2655
3417
|
var SettingsSection = ({ title, description, children }) => {
|
|
2656
|
-
const { t } =
|
|
2657
|
-
return /* @__PURE__ */
|
|
3418
|
+
const { t } = useTranslation12(translationKey14);
|
|
3419
|
+
return /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement("h2", {
|
|
2658
3420
|
className: "px-trim-md mt-trim-md text-xl"
|
|
2659
|
-
}, toLocalizedString2(title, t)), description && /* @__PURE__ */
|
|
3421
|
+
}, toLocalizedString2(title, t)), description && /* @__PURE__ */ React26.createElement("p", {
|
|
2660
3422
|
className: "px-trim-md text-description"
|
|
2661
|
-
}, toLocalizedString2(description, t)), /* @__PURE__ */
|
|
3423
|
+
}, toLocalizedString2(description, t)), /* @__PURE__ */ React26.createElement("div", {
|
|
2662
3424
|
className: "w-full pt-trim-md space-y-trim-md"
|
|
2663
3425
|
}, children));
|
|
2664
3426
|
};
|
|
@@ -2673,7 +3435,7 @@ var Settings = {
|
|
|
2673
3435
|
};
|
|
2674
3436
|
|
|
2675
3437
|
// src/components/Settings/SettingsSelectField.tsx
|
|
2676
|
-
import
|
|
3438
|
+
import React27 from "react";
|
|
2677
3439
|
import { Select as Select3 } from "@dxos/react-ui";
|
|
2678
3440
|
var createSelectField = ({ options, defaultLabel = "Default" }) => {
|
|
2679
3441
|
const normalized = options.map((option) => typeof option === "string" ? {
|
|
@@ -2682,45 +3444,43 @@ var createSelectField = ({ options, defaultLabel = "Default" }) => {
|
|
|
2682
3444
|
} : option);
|
|
2683
3445
|
const hasDefault = defaultLabel !== null;
|
|
2684
3446
|
const sentinel = hasDefault ? `__default__${Math.random().toString(36).slice(2)}` : "";
|
|
2685
|
-
return ({ value: value3, onChange, readonly }) => /* @__PURE__ */
|
|
3447
|
+
return ({ value: value3, onChange, readonly }) => /* @__PURE__ */ React27.createElement(Select3.Root, {
|
|
2686
3448
|
disabled: readonly,
|
|
2687
3449
|
value: value3 ?? sentinel,
|
|
2688
3450
|
onValueChange: (next) => onChange(hasDefault && next === sentinel ? void 0 : next)
|
|
2689
|
-
}, /* @__PURE__ */
|
|
3451
|
+
}, /* @__PURE__ */ React27.createElement(Select3.TriggerButton, {
|
|
2690
3452
|
disabled: readonly
|
|
2691
|
-
}), /* @__PURE__ */
|
|
3453
|
+
}), /* @__PURE__ */ React27.createElement(Select3.Portal, null, /* @__PURE__ */ React27.createElement(Select3.Content, null, /* @__PURE__ */ React27.createElement(Select3.Viewport, null, hasDefault && /* @__PURE__ */ React27.createElement(Select3.Option, {
|
|
2692
3454
|
value: sentinel
|
|
2693
|
-
}, defaultLabel), normalized.map((option) => /* @__PURE__ */
|
|
3455
|
+
}, defaultLabel), normalized.map((option) => /* @__PURE__ */ React27.createElement(Select3.Option, {
|
|
2694
3456
|
key: option.value,
|
|
2695
3457
|
value: option.value
|
|
2696
|
-
}, option.label ?? option.value))), /* @__PURE__ */
|
|
3458
|
+
}, option.label ?? option.value))), /* @__PURE__ */ React27.createElement(Select3.Arrow, null))));
|
|
2697
3459
|
};
|
|
2698
3460
|
|
|
2699
3461
|
// src/components/ViewEditor/ViewEditor.tsx
|
|
2700
3462
|
import { RegistryContext } from "@effect-atom/atom-react";
|
|
2701
|
-
import * as Array4 from "effect/Array";
|
|
2702
3463
|
import * as Match2 from "effect/Match";
|
|
2703
|
-
import * as
|
|
3464
|
+
import * as Option8 from "effect/Option";
|
|
2704
3465
|
import * as Schema5 from "effect/Schema";
|
|
2705
|
-
import
|
|
2706
|
-
import { Entity as Entity2, Feed, Filter as
|
|
2707
|
-
import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
|
|
3466
|
+
import React28, { forwardRef as forwardRef2, useCallback as useCallback20, useContext as useContext2, useImperativeHandle, useMemo as useMemo14, useState as useState7 } from "react";
|
|
3467
|
+
import { Entity as Entity2, Feed, Filter as Filter3, Format as Format7, Obj as Obj7, Query, QueryAST, Ref as Ref8, Type as Type7, View } from "@dxos/echo";
|
|
2708
3468
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2709
3469
|
import { useObject, useQuery as useQuery2 } from "@dxos/react-client/echo";
|
|
2710
|
-
import { IconButton as IconButton4, Input as
|
|
3470
|
+
import { IconButton as IconButton4, Input as Input18, Message, useTranslation as useTranslation13 } from "@dxos/react-ui";
|
|
2711
3471
|
import { QueryForm } from "@dxos/react-ui-components";
|
|
2712
3472
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
2713
3473
|
import { ParentLabelAnnotation, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
|
|
2714
|
-
import { mx as
|
|
2715
|
-
import { translationKey as
|
|
3474
|
+
import { mx as mx8, osTranslations as osTranslations2 } from "@dxos/ui-theme";
|
|
3475
|
+
import { translationKey as translationKey15 } from "#translations";
|
|
2716
3476
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2717
|
-
var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames,
|
|
2718
|
-
const atomRegistry =
|
|
2719
|
-
const schemaReadonly =
|
|
2720
|
-
const { t } =
|
|
2721
|
-
const projectionModel =
|
|
2722
|
-
const jsonSchema =
|
|
2723
|
-
const change = createEchoChangeCallback(view,
|
|
3477
|
+
var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, type, view, mode = "schema", registry, db, readonly, showHeading = false, types, tags, onQueryChanged, onDelete }, forwardedRef) => {
|
|
3478
|
+
const atomRegistry = useContext2(RegistryContext);
|
|
3479
|
+
const schemaReadonly = Type7.getDatabase(type) == null;
|
|
3480
|
+
const { t } = useTranslation13(translationKey15);
|
|
3481
|
+
const projectionModel = useMemo14(() => {
|
|
3482
|
+
const jsonSchema = type.jsonSchema;
|
|
3483
|
+
const change = createEchoChangeCallback(view, Type7.getDatabase(type) != null ? type : void 0);
|
|
2724
3484
|
const model = new ProjectionModel({
|
|
2725
3485
|
registry: atomRegistry,
|
|
2726
3486
|
view,
|
|
@@ -2730,7 +3490,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2730
3490
|
return model;
|
|
2731
3491
|
}, [
|
|
2732
3492
|
atomRegistry,
|
|
2733
|
-
|
|
3493
|
+
type,
|
|
2734
3494
|
view
|
|
2735
3495
|
]);
|
|
2736
3496
|
useImperativeHandle(forwardedRef, () => projectionModel, [
|
|
@@ -2742,22 +3502,23 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2742
3502
|
if (from._tag !== "scope") {
|
|
2743
3503
|
return void 0;
|
|
2744
3504
|
}
|
|
2745
|
-
|
|
3505
|
+
const feedScope = from.scopes.find((s) => s._tag === "feed");
|
|
3506
|
+
return Option8.fromNullable(feedScope).pipe(Option8.map((s) => s.feedUri), Option8.getOrUndefined);
|
|
2746
3507
|
}), Match2.orElse(() => void 0));
|
|
2747
|
-
const feeds = useQuery2(db,
|
|
2748
|
-
const targetRef =
|
|
3508
|
+
const feeds = useQuery2(db, Filter3.type(Feed.Feed));
|
|
3509
|
+
const targetRef = useMemo14(() => {
|
|
2749
3510
|
if (!queueTarget) {
|
|
2750
3511
|
return void 0;
|
|
2751
3512
|
}
|
|
2752
|
-
const feed = feeds.find((feed2) => Feed.
|
|
2753
|
-
return feed ?
|
|
3513
|
+
const feed = feeds.find((feed2) => Feed.getQueueUri(feed2)?.toString() === queueTarget);
|
|
3514
|
+
return feed ? Ref8.fromURI(Entity2.getURI(feed)) : void 0;
|
|
2754
3515
|
}, [
|
|
2755
3516
|
queueTarget,
|
|
2756
3517
|
feeds
|
|
2757
3518
|
]);
|
|
2758
|
-
const viewSchema =
|
|
3519
|
+
const viewSchema = useMemo14(() => {
|
|
2759
3520
|
const base = Schema5.Struct({
|
|
2760
|
-
query: mode === "schema" ?
|
|
3521
|
+
query: mode === "schema" ? Format7.URL.annotations({
|
|
2761
3522
|
title: "Record type"
|
|
2762
3523
|
}) : QueryAST.Query.annotations({
|
|
2763
3524
|
title: "Query"
|
|
@@ -2767,7 +3528,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2767
3528
|
return Schema5.Struct({
|
|
2768
3529
|
...base.fields,
|
|
2769
3530
|
// TODO(wittjosiah): Replace Type.Feed with Dataset.Dataset when Ref.Ref supports unions.
|
|
2770
|
-
target:
|
|
3531
|
+
target: Ref8.Ref(Feed.Feed).pipe(Schema5.annotations({
|
|
2771
3532
|
title: "Target Feed"
|
|
2772
3533
|
}), ParentLabelAnnotation.set(true), Schema5.optional)
|
|
2773
3534
|
}).pipe(Schema5.mutable);
|
|
@@ -2776,7 +3537,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2776
3537
|
}, [
|
|
2777
3538
|
mode
|
|
2778
3539
|
]);
|
|
2779
|
-
const viewValues =
|
|
3540
|
+
const viewValues = useMemo14(() => ({
|
|
2780
3541
|
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2781
3542
|
target: targetRef
|
|
2782
3543
|
}), [
|
|
@@ -2784,7 +3545,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2784
3545
|
view.query.ast,
|
|
2785
3546
|
targetRef
|
|
2786
3547
|
]);
|
|
2787
|
-
const fieldMap =
|
|
3548
|
+
const fieldMap = useMemo14(() => mode === "tag" ? customFields({
|
|
2788
3549
|
types,
|
|
2789
3550
|
tags
|
|
2790
3551
|
}) : void 0, [
|
|
@@ -2792,46 +3553,46 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2792
3553
|
types,
|
|
2793
3554
|
tags
|
|
2794
3555
|
]);
|
|
2795
|
-
const handleUpdate =
|
|
3556
|
+
const handleUpdate = useCallback20((values) => {
|
|
2796
3557
|
const targetValue = values.target;
|
|
2797
|
-
let
|
|
2798
|
-
if (
|
|
2799
|
-
const
|
|
2800
|
-
const feed = feeds.find((feed2) =>
|
|
3558
|
+
let queueDxn;
|
|
3559
|
+
if (Ref8.isRef(targetValue)) {
|
|
3560
|
+
const feedUri = targetValue.uri;
|
|
3561
|
+
const feed = feeds.find((feed2) => Obj7.getURI(feed2) === feedUri);
|
|
2801
3562
|
if (feed) {
|
|
2802
|
-
|
|
3563
|
+
queueDxn = Feed.getQueueUri(feed);
|
|
2803
3564
|
}
|
|
2804
3565
|
}
|
|
2805
|
-
const query = mode === "schema" ? Query.select(
|
|
2806
|
-
onQueryChanged?.(query,
|
|
3566
|
+
const query = mode === "schema" ? Query.select(Filter3.typename(values.query)).ast : JSON.parse(JSON.stringify(values.query));
|
|
3567
|
+
onQueryChanged?.(query, queueDxn);
|
|
2807
3568
|
}, [
|
|
2808
3569
|
onQueryChanged,
|
|
2809
3570
|
mode,
|
|
2810
3571
|
feeds
|
|
2811
3572
|
]);
|
|
2812
|
-
const handleDelete =
|
|
2813
|
-
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
3573
|
+
const handleDelete = useCallback20((fieldId) => {
|
|
3574
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 124, S: void 0, A: ["!readonly", ""] });
|
|
2814
3575
|
onDelete?.(fieldId);
|
|
2815
3576
|
}, [
|
|
2816
3577
|
onDelete,
|
|
2817
3578
|
readonly
|
|
2818
3579
|
]);
|
|
2819
|
-
return /* @__PURE__ */
|
|
2820
|
-
className:
|
|
2821
|
-
}, schemaReadonly && !readonly && /* @__PURE__ */
|
|
3580
|
+
return /* @__PURE__ */ React28.createElement("div", {
|
|
3581
|
+
className: mx8(classNames)
|
|
3582
|
+
}, schemaReadonly && !readonly && /* @__PURE__ */ React28.createElement(Message.Root, {
|
|
2822
3583
|
valence: "info",
|
|
2823
3584
|
classNames: "my-form-padding"
|
|
2824
|
-
}, /* @__PURE__ */
|
|
3585
|
+
}, /* @__PURE__ */ React28.createElement(Message.Title, null, t("system-schema.description"))), /* @__PURE__ */ React28.createElement(Form.Root, {
|
|
2825
3586
|
schema: viewSchema,
|
|
2826
3587
|
values: viewValues,
|
|
2827
3588
|
fieldMap,
|
|
2828
3589
|
db,
|
|
2829
3590
|
onValuesChanged: handleUpdate
|
|
2830
|
-
}, /* @__PURE__ */
|
|
3591
|
+
}, /* @__PURE__ */ React28.createElement(Form.FieldSet, null), /* @__PURE__ */ React28.createElement(FormFieldLabel, {
|
|
2831
3592
|
label: t("fields.label"),
|
|
2832
3593
|
asChild: true
|
|
2833
|
-
}), /* @__PURE__ */
|
|
2834
|
-
|
|
3594
|
+
}), /* @__PURE__ */ React28.createElement(FieldList, {
|
|
3595
|
+
type,
|
|
2835
3596
|
view,
|
|
2836
3597
|
registry,
|
|
2837
3598
|
readonly,
|
|
@@ -2839,14 +3600,14 @@ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode =
|
|
|
2839
3600
|
onDelete: handleDelete
|
|
2840
3601
|
})));
|
|
2841
3602
|
});
|
|
2842
|
-
var FieldList = ({
|
|
2843
|
-
const atomRegistry =
|
|
2844
|
-
const schemaReadonly =
|
|
2845
|
-
const { t } =
|
|
3603
|
+
var FieldList = ({ type, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
3604
|
+
const atomRegistry = useContext2(RegistryContext);
|
|
3605
|
+
const schemaReadonly = Type7.getDatabase(type) == null;
|
|
3606
|
+
const { t } = useTranslation13(translationKey15);
|
|
2846
3607
|
const [viewSnapshot] = useObject(view);
|
|
2847
|
-
const projectionModel =
|
|
2848
|
-
const jsonSchema =
|
|
2849
|
-
const change = createEchoChangeCallback(view,
|
|
3608
|
+
const projectionModel = useMemo14(() => {
|
|
3609
|
+
const jsonSchema = type.jsonSchema;
|
|
3610
|
+
const change = createEchoChangeCallback(view, Type7.getDatabase(type) != null ? type : void 0);
|
|
2850
3611
|
const model = new ProjectionModel({
|
|
2851
3612
|
registry: atomRegistry,
|
|
2852
3613
|
view,
|
|
@@ -2856,25 +3617,25 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2856
3617
|
return model;
|
|
2857
3618
|
}, [
|
|
2858
3619
|
atomRegistry,
|
|
2859
|
-
|
|
3620
|
+
type,
|
|
2860
3621
|
view
|
|
2861
3622
|
]);
|
|
2862
3623
|
const [expandedField, setExpandedField] = useState7();
|
|
2863
|
-
const handleAdd =
|
|
2864
|
-
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
3624
|
+
const handleAdd = useCallback20(() => {
|
|
3625
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 178, S: void 0, A: ["!readonly", ""] });
|
|
2865
3626
|
const field = projectionModel.createFieldProjection();
|
|
2866
3627
|
setExpandedField(field.id);
|
|
2867
3628
|
}, [
|
|
2868
3629
|
projectionModel,
|
|
2869
3630
|
readonly
|
|
2870
3631
|
]);
|
|
2871
|
-
const handleToggleField =
|
|
3632
|
+
const handleToggleField = useCallback20((field) => {
|
|
2872
3633
|
setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
|
|
2873
3634
|
}, [
|
|
2874
3635
|
readonly
|
|
2875
3636
|
]);
|
|
2876
|
-
const handleDelete =
|
|
2877
|
-
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
3637
|
+
const handleDelete = useCallback20((fieldId) => {
|
|
3638
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 191, S: void 0, A: ["!readonly", ""] });
|
|
2878
3639
|
if (fieldId === expandedField) {
|
|
2879
3640
|
setExpandedField(void 0);
|
|
2880
3641
|
}
|
|
@@ -2884,9 +3645,9 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2884
3645
|
onDelete,
|
|
2885
3646
|
readonly
|
|
2886
3647
|
]);
|
|
2887
|
-
const handleMove =
|
|
2888
|
-
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
2889
|
-
|
|
3648
|
+
const handleMove = useCallback20((fromIndex, toIndex) => {
|
|
3649
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 202, S: void 0, A: ["!readonly", ""] });
|
|
3650
|
+
Obj7.update(view, (view2) => {
|
|
2890
3651
|
const fields = [
|
|
2891
3652
|
...view2.projection.fields
|
|
2892
3653
|
];
|
|
@@ -2898,14 +3659,14 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2898
3659
|
view,
|
|
2899
3660
|
readonly
|
|
2900
3661
|
]);
|
|
2901
|
-
const handleClose =
|
|
2902
|
-
const handleHide =
|
|
3662
|
+
const handleClose = useCallback20(() => setExpandedField(void 0), []);
|
|
3663
|
+
const handleHide = useCallback20((fieldId) => {
|
|
2903
3664
|
setExpandedField(void 0);
|
|
2904
3665
|
projectionModel.hideFieldProjection(fieldId);
|
|
2905
3666
|
}, [
|
|
2906
3667
|
projectionModel
|
|
2907
3668
|
]);
|
|
2908
|
-
const handleShow =
|
|
3669
|
+
const handleShow = useCallback20((property) => {
|
|
2909
3670
|
setExpandedField(void 0);
|
|
2910
3671
|
projectionModel.showFieldProjection(property);
|
|
2911
3672
|
}, [
|
|
@@ -2914,45 +3675,45 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2914
3675
|
if (!viewSnapshot) {
|
|
2915
3676
|
return null;
|
|
2916
3677
|
}
|
|
2917
|
-
return /* @__PURE__ */
|
|
3678
|
+
return /* @__PURE__ */ React28.createElement(List2.Root, {
|
|
2918
3679
|
items: viewSnapshot.projection.fields,
|
|
2919
3680
|
isItem: Schema5.is(View.FieldSchema),
|
|
2920
3681
|
getId: (field) => field.id,
|
|
2921
3682
|
onMove: readonly ? void 0 : handleMove,
|
|
2922
3683
|
readonly
|
|
2923
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
3684
|
+
}, ({ items: fields }) => /* @__PURE__ */ React28.createElement(React28.Fragment, null, showHeading && /* @__PURE__ */ React28.createElement("h3", {
|
|
2924
3685
|
className: "text-sm"
|
|
2925
|
-
}, t("field-path.label")), /* @__PURE__ */
|
|
3686
|
+
}, t("field-path.label")), /* @__PURE__ */ React28.createElement("div", {
|
|
2926
3687
|
role: "list",
|
|
2927
3688
|
className: "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]"
|
|
2928
3689
|
}, fields?.map((field) => {
|
|
2929
3690
|
const hidden = field.visible === false;
|
|
2930
|
-
return /* @__PURE__ */
|
|
3691
|
+
return /* @__PURE__ */ React28.createElement(List2.Item, {
|
|
2931
3692
|
key: field.id,
|
|
2932
3693
|
item: field,
|
|
2933
3694
|
classNames: "grid grid-cols-subgrid col-span-5",
|
|
2934
3695
|
"aria-expanded": expandedField === field.id
|
|
2935
|
-
}, /* @__PURE__ */
|
|
3696
|
+
}, /* @__PURE__ */ React28.createElement("div", {
|
|
2936
3697
|
className: "grid grid-cols-subgrid col-span-5 rounded-xs cursor-pointer min-h-10 dx-hover"
|
|
2937
|
-
}, /* @__PURE__ */
|
|
3698
|
+
}, /* @__PURE__ */ React28.createElement(List2.ItemDragHandle, {
|
|
2938
3699
|
disabled: readonly || schemaReadonly
|
|
2939
|
-
}), /* @__PURE__ */
|
|
3700
|
+
}), /* @__PURE__ */ React28.createElement(List2.ItemTitle, {
|
|
2940
3701
|
classNames: hidden && "text-subdued",
|
|
2941
3702
|
onClick: () => handleToggleField(field)
|
|
2942
|
-
}, field.path), /* @__PURE__ */
|
|
3703
|
+
}, field.path), /* @__PURE__ */ React28.createElement(List2.ItemIconButton, {
|
|
2943
3704
|
label: t(hidden ? "show-field.label" : "hide-field.label"),
|
|
2944
3705
|
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2945
3706
|
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2946
3707
|
autoHide: false,
|
|
2947
3708
|
disabled: readonly || !hidden && projectionModel.getFields().length <= 1,
|
|
2948
3709
|
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2949
|
-
}), !readonly && /* @__PURE__ */
|
|
3710
|
+
}), !readonly && /* @__PURE__ */ React28.createElement(React28.Fragment, null, /* @__PURE__ */ React28.createElement(List2.ItemDeleteButton, {
|
|
2950
3711
|
label: t("delete-field.label"),
|
|
2951
3712
|
autoHide: false,
|
|
2952
3713
|
disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
|
|
2953
3714
|
onClick: () => handleDelete(field.id),
|
|
2954
3715
|
"data-testid": "field.delete"
|
|
2955
|
-
}), /* @__PURE__ */
|
|
3716
|
+
}), /* @__PURE__ */ React28.createElement(List2.ItemIconButton, {
|
|
2956
3717
|
iconOnly: true,
|
|
2957
3718
|
variant: "ghost",
|
|
2958
3719
|
label: t("toggle-expand.label", {
|
|
@@ -2961,18 +3722,18 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2961
3722
|
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2962
3723
|
onClick: () => handleToggleField(field),
|
|
2963
3724
|
"data-testid": "field.toggle"
|
|
2964
|
-
}))), expandedField === field.id && !readonly && /* @__PURE__ */
|
|
3725
|
+
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React28.createElement("div", {
|
|
2965
3726
|
className: "col-span-full mt-1 mb-1 border border-separator rounded-md"
|
|
2966
|
-
}, /* @__PURE__ */
|
|
3727
|
+
}, /* @__PURE__ */ React28.createElement(FieldEditor, {
|
|
2967
3728
|
readonly: readonly || schemaReadonly,
|
|
2968
3729
|
registry,
|
|
2969
3730
|
projection: projectionModel,
|
|
2970
3731
|
field,
|
|
2971
3732
|
onSave: handleClose
|
|
2972
3733
|
})));
|
|
2973
|
-
})), !readonly && !expandedField && /* @__PURE__ */
|
|
3734
|
+
})), !readonly && !expandedField && /* @__PURE__ */ React28.createElement("div", {
|
|
2974
3735
|
className: "my-form-padding"
|
|
2975
|
-
}, /* @__PURE__ */
|
|
3736
|
+
}, /* @__PURE__ */ React28.createElement(IconButton4, {
|
|
2976
3737
|
icon: "ph--plus--regular",
|
|
2977
3738
|
label: t("add-property-button.label"),
|
|
2978
3739
|
onClick: handleAdd,
|
|
@@ -2982,13 +3743,13 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2982
3743
|
};
|
|
2983
3744
|
var customFields = ({ types, tags }) => ({
|
|
2984
3745
|
query: ({ type, readonly, label, getValue, onValueChange }) => {
|
|
2985
|
-
const handleChange =
|
|
3746
|
+
const handleChange = useCallback20((query) => onValueChange(type, query.ast), [
|
|
2986
3747
|
onValueChange
|
|
2987
3748
|
]);
|
|
2988
|
-
return /* @__PURE__ */
|
|
3749
|
+
return /* @__PURE__ */ React28.createElement(Input18.Root, null, /* @__PURE__ */ React28.createElement(FormFieldLabel, {
|
|
2989
3750
|
readonly,
|
|
2990
3751
|
label
|
|
2991
|
-
}), /* @__PURE__ */
|
|
3752
|
+
}), /* @__PURE__ */ React28.createElement(QueryForm, {
|
|
2992
3753
|
initialQuery: getValue(),
|
|
2993
3754
|
types,
|
|
2994
3755
|
tags,
|
|
@@ -2999,17 +3760,27 @@ var customFields = ({ types, tags }) => ({
|
|
|
2999
3760
|
export {
|
|
3000
3761
|
ArrayField,
|
|
3001
3762
|
BooleanField,
|
|
3763
|
+
DEFAULT_LAYOUT_NAME,
|
|
3764
|
+
DateField,
|
|
3002
3765
|
FieldEditor,
|
|
3003
3766
|
Form,
|
|
3004
3767
|
FormFieldErrorBoundary,
|
|
3005
3768
|
FormFieldLabel,
|
|
3006
3769
|
FormFieldWrapper,
|
|
3770
|
+
FormLayout,
|
|
3771
|
+
FormLayoutAnnotation,
|
|
3772
|
+
FormLayoutAnnotationId,
|
|
3773
|
+
FormTooltipsContext,
|
|
3007
3774
|
GeoPointField,
|
|
3775
|
+
InlineRefField,
|
|
3776
|
+
LayoutParseError,
|
|
3777
|
+
META_TAGS_KEY,
|
|
3008
3778
|
MarkdownField,
|
|
3009
3779
|
NumberField,
|
|
3010
3780
|
ObjectForm,
|
|
3011
3781
|
ObjectPicker,
|
|
3012
3782
|
ObjectProperties,
|
|
3783
|
+
ObjectTree,
|
|
3013
3784
|
RefField,
|
|
3014
3785
|
SelectField,
|
|
3015
3786
|
SelectOptionField,
|
|
@@ -3029,12 +3800,15 @@ export {
|
|
|
3029
3800
|
getSelectOptionsFromAst,
|
|
3030
3801
|
omitHiddenFormFields,
|
|
3031
3802
|
omitId,
|
|
3803
|
+
parseLayout,
|
|
3032
3804
|
parseValue,
|
|
3033
3805
|
pathNotUniqueError,
|
|
3034
3806
|
useFormContext,
|
|
3035
3807
|
useFormFieldState,
|
|
3036
3808
|
useFormHandler,
|
|
3809
|
+
useFormTooltips,
|
|
3037
3810
|
useFormValues,
|
|
3038
|
-
useKeyHandler
|
|
3811
|
+
useKeyHandler,
|
|
3812
|
+
withMetaTags
|
|
3039
3813
|
};
|
|
3040
3814
|
//# sourceMappingURL=index.mjs.map
|