@webiny/app-admin 6.5.0-beta.9 → 6.5.0
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/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.d.ts +2 -0
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.js +13 -5
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectRenderer.js +8 -26
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectRenderer.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.d.ts +8 -3
- package/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.js +25 -17
- package/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.test.d.ts +1 -0
- package/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.test.js +106 -0
- package/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.test.js.map +1 -0
- package/features/formModel/abstractions.d.ts +16 -0
- package/features/formModel/abstractions.js +2 -1
- package/features/formModel/abstractions.js.map +1 -1
- package/features/formModel/index.d.ts +2 -2
- package/features/formModel/index.js +1 -1
- package/package.json +24 -24
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { IObjectFieldItemVM, LayoutNodeVM } from "../../../../features/formModel/index.js";
|
|
3
|
+
import { FieldValueFormatter } from "../../../../features/formModel/index.js";
|
|
3
4
|
import type { ISortableItemProps } from "../../../../presentation/sortable/index.js";
|
|
4
5
|
export declare const NestedLayout: (({ layout }: {
|
|
5
6
|
layout: LayoutNodeVM[];
|
|
@@ -10,6 +11,7 @@ export declare const NestedLayout: (({ layout }: {
|
|
|
10
11
|
layout: LayoutNodeVM[];
|
|
11
12
|
}) => React.JSX.Element;
|
|
12
13
|
};
|
|
14
|
+
export declare function useFieldValueFormatters(): FieldValueFormatter.Interface[];
|
|
13
15
|
export interface ListItemRendererProps {
|
|
14
16
|
item: IObjectFieldItemVM;
|
|
15
17
|
index: number;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import react, { useEffect, useState } from "react";
|
|
1
|
+
import react, { useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { observer } from "mobx-react-lite";
|
|
3
3
|
import { Accordion, Button, IconButton } from "@webiny/admin-ui";
|
|
4
4
|
import { ReactComponent } from "@webiny/icons/add.svg";
|
|
5
5
|
import { ReactComponent as delete_outline_svg_ReactComponent } from "@webiny/icons/delete_outline.svg";
|
|
6
6
|
import { ReactComponent as arrow_upward_svg_ReactComponent } from "@webiny/icons/arrow_upward.svg";
|
|
7
7
|
import { ReactComponent as arrow_downward_svg_ReactComponent } from "@webiny/icons/arrow_downward.svg";
|
|
8
|
-
import {
|
|
8
|
+
import { useContainer } from "@webiny/app";
|
|
9
|
+
import { FieldValueFormatter, hasSubtreeFocusRequest } from "../../../../features/formModel/index.js";
|
|
9
10
|
import { LayoutNodeRenderer } from "../../../../features/formModel/FormView.js";
|
|
10
11
|
import { resolveItemDescription, resolveItemTitle } from "./resolveItemTitle.js";
|
|
11
12
|
const NestedLayout = observer(({ layout })=>/*#__PURE__*/ react.createElement("div", {
|
|
@@ -14,8 +15,15 @@ const NestedLayout = observer(({ layout })=>/*#__PURE__*/ react.createElement("d
|
|
|
14
15
|
key: index,
|
|
15
16
|
node: node
|
|
16
17
|
}))));
|
|
18
|
+
function useFieldValueFormatters() {
|
|
19
|
+
const container = useContainer();
|
|
20
|
+
return useMemo(()=>container.resolveAll(FieldValueFormatter), [
|
|
21
|
+
container
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
17
24
|
const ListItemRenderer = observer(({ item, index, total, label, itemTitle, itemDescription, disabled, sortable })=>{
|
|
18
25
|
const [open, setOpen] = useState(false);
|
|
26
|
+
const formatters = useFieldValueFormatters();
|
|
19
27
|
const hasFocusRequest = hasSubtreeFocusRequest(item.fields);
|
|
20
28
|
useEffect(()=>{
|
|
21
29
|
if (hasFocusRequest) setOpen(true);
|
|
@@ -51,8 +59,8 @@ const ListItemRenderer = observer(({ item, index, total, label, itemTitle, itemD
|
|
|
51
59
|
variant: "container",
|
|
52
60
|
openClosedIndicatorPosition: "left"
|
|
53
61
|
}, /*#__PURE__*/ react.createElement(Accordion.Item, {
|
|
54
|
-
title: resolveItemTitle(item, index, label,
|
|
55
|
-
description: resolveItemDescription(item, index, itemDescription),
|
|
62
|
+
title: resolveItemTitle(item.fields, index, `${label || "Item"} #${index + 1}`, itemTitle, formatters),
|
|
63
|
+
description: resolveItemDescription(item.fields, index, itemDescription, formatters),
|
|
56
64
|
actions: disabled ? null : actions,
|
|
57
65
|
open: open,
|
|
58
66
|
onOpenChange: setOpen,
|
|
@@ -98,6 +106,6 @@ const AddItemButton = ({ label, disabled, onAdd })=>/*#__PURE__*/ react.createEl
|
|
|
98
106
|
onClick: onAdd,
|
|
99
107
|
disabled: disabled
|
|
100
108
|
}));
|
|
101
|
-
export { AddItemButton, ListItemRenderer, NestedLayout };
|
|
109
|
+
export { AddItemButton, ListItemRenderer, NestedLayout, useFieldValueFormatters };
|
|
102
110
|
|
|
103
111
|
//# sourceMappingURL=ObjectFieldComponents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { Accordion, Button, IconButton } from \"@webiny/admin-ui\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport { ReactComponent as DeleteIcon } from \"@webiny/icons/delete_outline.svg\";\nimport { ReactComponent as ArrowUp } from \"@webiny/icons/arrow_upward.svg\";\nimport { ReactComponent as ArrowDown } from \"@webiny/icons/arrow_downward.svg\";\nimport type { IObjectFieldItemVM, LayoutNodeVM } from \"~/features/formModel/index.js\";\nimport { hasSubtreeFocusRequest } from \"~/features/formModel/index.js\";\nimport { LayoutNodeRenderer } from \"~/features/formModel/FormView.js\";\nimport { resolveItemTitle, resolveItemDescription } from \"./resolveItemTitle.js\";\nimport type { ISortableItemProps } from \"~/presentation/sortable/index.js\";\n\nexport const NestedLayout = observer(({ layout }: { layout: LayoutNodeVM[] }) => {\n return (\n <div className={\"flex flex-col gap-md\"}>\n {layout.map((node, index) => (\n <LayoutNodeRenderer key={index} node={node} />\n ))}\n </div>\n );\n});\n\nexport interface ListItemRendererProps {\n item: IObjectFieldItemVM;\n index: number;\n total: number;\n label?: string;\n itemTitle?: string | ((data: Record<string, unknown>, index: number) => string);\n itemDescription?: string | ((data: Record<string, unknown>, index: number) => string);\n disabled: boolean;\n sortable?: ISortableItemProps;\n}\n\nexport const ListItemRenderer = observer(\n ({\n item,\n index,\n total,\n label,\n itemTitle,\n itemDescription,\n disabled,\n sortable\n }: ListItemRendererProps) => {\n const [open, setOpen] = useState(false);\n const hasFocusRequest = hasSubtreeFocusRequest(item.fields);\n\n useEffect(() => {\n if (hasFocusRequest) {\n setOpen(true);\n }\n }, [hasFocusRequest]);\n\n const actions = (\n <>\n <IconButton\n icon={<ArrowDown />}\n onClick={e => {\n e.stopPropagation();\n item.moveDown();\n }}\n variant=\"ghost\"\n disabled={index === total - 1}\n />\n <IconButton\n icon={<ArrowUp />}\n onClick={e => {\n e.stopPropagation();\n item.moveUp();\n }}\n variant=\"ghost\"\n disabled={index === 0}\n />\n <Accordion.Item.Action.Separator />\n <IconButton\n icon={<DeleteIcon />}\n onClick={e => {\n e.stopPropagation();\n item.remove();\n }}\n variant=\"ghost\"\n />\n </>\n );\n\n const accordion = (\n <Accordion\n background={\"base\"}\n variant={\"container\"}\n openClosedIndicatorPosition={\"left\"}\n >\n <Accordion.Item\n title={resolveItemTitle(item
|
|
1
|
+
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { Accordion, Button, IconButton } from \"@webiny/admin-ui\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport { ReactComponent as DeleteIcon } from \"@webiny/icons/delete_outline.svg\";\nimport { ReactComponent as ArrowUp } from \"@webiny/icons/arrow_upward.svg\";\nimport { ReactComponent as ArrowDown } from \"@webiny/icons/arrow_downward.svg\";\nimport { useContainer } from \"@webiny/app\";\nimport type { IObjectFieldItemVM, LayoutNodeVM } from \"~/features/formModel/index.js\";\nimport { FieldValueFormatter, hasSubtreeFocusRequest } from \"~/features/formModel/index.js\";\nimport { LayoutNodeRenderer } from \"~/features/formModel/FormView.js\";\nimport { resolveItemTitle, resolveItemDescription } from \"./resolveItemTitle.js\";\nimport type { ISortableItemProps } from \"~/presentation/sortable/index.js\";\n\nexport const NestedLayout = observer(({ layout }: { layout: LayoutNodeVM[] }) => {\n return (\n <div className={\"flex flex-col gap-md\"}>\n {layout.map((node, index) => (\n <LayoutNodeRenderer key={index} node={node} />\n ))}\n </div>\n );\n});\n\nexport function useFieldValueFormatters(): FieldValueFormatter.Interface[] {\n const container = useContainer();\n return useMemo(() => container.resolveAll(FieldValueFormatter), [container]);\n}\n\nexport interface ListItemRendererProps {\n item: IObjectFieldItemVM;\n index: number;\n total: number;\n label?: string;\n itemTitle?: string | ((data: Record<string, unknown>, index: number) => string);\n itemDescription?: string | ((data: Record<string, unknown>, index: number) => string);\n disabled: boolean;\n sortable?: ISortableItemProps;\n}\n\nexport const ListItemRenderer = observer(\n ({\n item,\n index,\n total,\n label,\n itemTitle,\n itemDescription,\n disabled,\n sortable\n }: ListItemRendererProps) => {\n const [open, setOpen] = useState(false);\n const formatters = useFieldValueFormatters();\n const hasFocusRequest = hasSubtreeFocusRequest(item.fields);\n\n useEffect(() => {\n if (hasFocusRequest) {\n setOpen(true);\n }\n }, [hasFocusRequest]);\n\n const actions = (\n <>\n <IconButton\n icon={<ArrowDown />}\n onClick={e => {\n e.stopPropagation();\n item.moveDown();\n }}\n variant=\"ghost\"\n disabled={index === total - 1}\n />\n <IconButton\n icon={<ArrowUp />}\n onClick={e => {\n e.stopPropagation();\n item.moveUp();\n }}\n variant=\"ghost\"\n disabled={index === 0}\n />\n <Accordion.Item.Action.Separator />\n <IconButton\n icon={<DeleteIcon />}\n onClick={e => {\n e.stopPropagation();\n item.remove();\n }}\n variant=\"ghost\"\n />\n </>\n );\n\n const accordion = (\n <Accordion\n background={\"base\"}\n variant={\"container\"}\n openClosedIndicatorPosition={\"left\"}\n >\n <Accordion.Item\n title={resolveItemTitle(\n item.fields,\n index,\n `${label || \"Item\"} #${index + 1}`,\n itemTitle,\n formatters\n )}\n description={resolveItemDescription(\n item.fields,\n index,\n itemDescription,\n formatters\n )}\n actions={disabled ? null : actions}\n open={open}\n onOpenChange={setOpen}\n draggable={!disabled && sortable !== undefined}\n dragHandleRef={sortable?.handleRef}\n >\n <NestedLayout layout={item.layout} />\n </Accordion.Item>\n </Accordion>\n );\n\n if (!sortable) {\n return accordion;\n }\n\n return (\n <div\n ref={sortable.ref}\n data-sortable-item=\"\"\n className={\"relative\"}\n style={{ opacity: sortable.isDragging ? 0.4 : 1 }}\n >\n {sortable.closestEdge === \"top\" && (\n <DropIndicator position={\"top\"} isFirst={index === 0} />\n )}\n {accordion}\n {sortable.closestEdge === \"bottom\" && (\n <DropIndicator position={\"bottom\"} isLast={index === total - 1} />\n )}\n </div>\n );\n }\n);\n\nconst DropIndicator = ({\n position,\n isFirst = false,\n isLast = false\n}: {\n position: \"top\" | \"bottom\";\n isFirst?: boolean;\n isLast?: boolean;\n}) => {\n let offset = \"calc(var(--spacing-md) / -2)\";\n if (position === \"top\" && isFirst) {\n offset = \"0px\";\n }\n if (position === \"bottom\" && isLast) {\n offset = \"0px\";\n }\n\n return (\n <div\n className={\"absolute left-0 right-0 z-10\"}\n style={{\n [position]: offset,\n transform: position === \"top\" ? \"translateY(-50%)\" : \"translateY(50%)\"\n }}\n >\n <div className={\"w-full h-[2px] bg-primary rounded-full\"} />\n </div>\n );\n};\n\nexport interface AddItemButtonProps {\n label?: string;\n disabled: boolean;\n onAdd: () => void;\n}\n\nexport const AddItemButton = ({ label, disabled, onAdd }: AddItemButtonProps) => {\n return (\n <div>\n <Button\n icon={<AddIcon />}\n text={label || \"Add Item\"}\n variant={\"tertiary\"}\n onClick={onAdd}\n disabled={disabled}\n />\n </div>\n );\n};\n"],"names":["NestedLayout","observer","layout","node","index","LayoutNodeRenderer","useFieldValueFormatters","container","useContainer","useMemo","FieldValueFormatter","ListItemRenderer","item","total","label","itemTitle","itemDescription","disabled","sortable","open","setOpen","useState","formatters","hasFocusRequest","hasSubtreeFocusRequest","useEffect","actions","IconButton","ArrowDown","e","ArrowUp","Accordion","DeleteIcon","accordion","resolveItemTitle","resolveItemDescription","undefined","DropIndicator","position","isFirst","isLast","offset","AddItemButton","onAdd","Button","AddIcon"],"mappings":";;;;;;;;;;;AAcO,MAAMA,eAAeC,SAAS,CAAC,EAAEC,MAAM,EAA8B,GACjE,WAAP,GACI,oBAAC;QAAI,WAAW;OACXA,OAAO,GAAG,CAAC,CAACC,MAAMC,QAAAA,WAAAA,GACf,oBAACC,oBAAkBA;YAAC,KAAKD;YAAO,MAAMD;;AAM/C,SAASG;IACZ,MAAMC,YAAYC;IAClB,OAAOC,QAAQ,IAAMF,UAAU,UAAU,CAACG,sBAAsB;QAACH;KAAU;AAC/E;AAaO,MAAMI,mBAAmBV,SAC5B,CAAC,EACGW,IAAI,EACJR,KAAK,EACLS,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,QAAQ,EACY;IACpB,MAAM,CAACC,MAAMC,QAAQ,GAAGC,SAAS;IACjC,MAAMC,aAAahB;IACnB,MAAMiB,kBAAkBC,uBAAuBZ,KAAK,MAAM;IAE1Da,UAAU;QACN,IAAIF,iBACAH,QAAQ;IAEhB,GAAG;QAACG;KAAgB;IAEpB,MAAMG,UAAU,WAAVA,GACF,wDACI,oBAACC,YAAUA;QACP,oBAAM,oBAACC,mCAASA;QAChB,SAASC,CAAAA;YACLA,EAAE,eAAe;YACjBjB,KAAK,QAAQ;QACjB;QACA,SAAQ;QACR,UAAUR,UAAUS,QAAQ;sBAEhC,oBAACc,YAAUA;QACP,oBAAM,oBAACG,iCAAOA;QACd,SAASD,CAAAA;YACLA,EAAE,eAAe;YACjBjB,KAAK,MAAM;QACf;QACA,SAAQ;QACR,UAAUR,AAAU,MAAVA;sBAEd,oBAAC2B,UAAU,IAAI,CAAC,MAAM,CAAC,SAAS,uBAChC,oBAACJ,YAAUA;QACP,oBAAM,oBAACK,mCAAUA;QACjB,SAASH,CAAAA;YACLA,EAAE,eAAe;YACjBjB,KAAK,MAAM;QACf;QACA,SAAQ;;IAKpB,MAAMqB,YAAY,WAAZA,GACF,oBAACF,WAASA;QACN,YAAY;QACZ,SAAS;QACT,6BAA6B;qBAE7B,oBAACA,UAAU,IAAI;QACX,OAAOG,iBACHtB,KAAK,MAAM,EACXR,OACA,GAAGU,SAAS,OAAO,EAAE,EAAEV,QAAQ,GAAG,EAClCW,WACAO;QAEJ,aAAaa,uBACTvB,KAAK,MAAM,EACXR,OACAY,iBACAM;QAEJ,SAASL,WAAW,OAAOS;QAC3B,MAAMP;QACN,cAAcC;QACd,WAAW,CAACH,YAAYC,AAAakB,WAAblB;QACxB,eAAeA,UAAU;qBAEzB,oBAAClB,cAAYA;QAAC,QAAQY,KAAK,MAAM;;IAK7C,IAAI,CAACM,UACD,OAAOe;IAGX,OAAO,WAAP,GACI,oBAAC;QACG,KAAKf,SAAS,GAAG;QACjB,sBAAmB;QACnB,WAAW;QACX,OAAO;YAAE,SAASA,SAAS,UAAU,GAAG,MAAM;QAAE;OAE/CA,AAAyB,UAAzBA,SAAS,WAAW,IAAc,WAAT,GACtB,oBAACmB,eAAaA;QAAC,UAAU;QAAO,SAASjC,AAAU,MAAVA;QAE5C6B,WACAf,AAAyB,aAAzBA,SAAS,WAAW,IAAiB,WAAZ,GACtB,oBAACmB,eAAaA;QAAC,UAAU;QAAU,QAAQjC,UAAUS,QAAQ;;AAI7E;AAGJ,MAAMwB,gBAAgB,CAAC,EACnBC,QAAQ,EACRC,UAAU,KAAK,EACfC,SAAS,KAAK,EAKjB;IACG,IAAIC,SAAS;IACb,IAAIH,AAAa,UAAbA,YAAsBC,SACtBE,SAAS;IAEb,IAAIH,AAAa,aAAbA,YAAyBE,QACzBC,SAAS;IAGb,OAAO,WAAP,GACI,oBAAC;QACG,WAAW;QACX,OAAO;YACH,CAACH,SAAS,EAAEG;YACZ,WAAWH,AAAa,UAAbA,WAAqB,qBAAqB;QACzD;qBAEA,oBAAC;QAAI,WAAW;;AAG5B;AAQO,MAAMI,gBAAgB,CAAC,EAAE5B,KAAK,EAAEG,QAAQ,EAAE0B,KAAK,EAAsB,GACjE,WAAP,GACI,oBAAC,2BACG,oBAACC,QAAMA;QACH,oBAAM,oBAACC,gBAAOA;QACd,MAAM/B,SAAS;QACf,SAAS;QACT,SAAS6B;QACT,UAAU1B"}
|
|
@@ -1,33 +1,12 @@
|
|
|
1
1
|
import react, { useEffect, useState } from "react";
|
|
2
2
|
import { Accordion } from "@webiny/admin-ui";
|
|
3
3
|
import { createObjectFieldRenderer } from "../../../../features/formModel/createFieldRenderer.js";
|
|
4
|
-
import { NestedLayout } from "./ObjectFieldComponents.js";
|
|
4
|
+
import { NestedLayout, useFieldValueFormatters } from "./ObjectFieldComponents.js";
|
|
5
|
+
import { resolveItemDescription, resolveItemTitle } from "./resolveItemTitle.js";
|
|
5
6
|
import { hasSubtreeFocusRequest } from "../../../../features/formModel/index.js";
|
|
6
|
-
function resolveTitle(field, itemTitle) {
|
|
7
|
-
if (!itemTitle) return field.label;
|
|
8
|
-
if ("string" == typeof itemTitle) {
|
|
9
|
-
const child = field.fields.find((f)=>f.name === itemTitle);
|
|
10
|
-
return (child ? String(child.value ?? "") : "") || field.label;
|
|
11
|
-
}
|
|
12
|
-
const data = {};
|
|
13
|
-
for (const child of field.fields)data[child.name] = child.value;
|
|
14
|
-
return itemTitle(data) || field.label;
|
|
15
|
-
}
|
|
16
|
-
function resolveDescription(field, itemDescription) {
|
|
17
|
-
if (!itemDescription) return;
|
|
18
|
-
if ("string" == typeof itemDescription) {
|
|
19
|
-
const child = field.fields.find((f)=>f.name === itemDescription);
|
|
20
|
-
return (child ? String(child.value ?? "") : "") || void 0;
|
|
21
|
-
}
|
|
22
|
-
const data = {};
|
|
23
|
-
for (const child of field.fields)data[child.name] = child.value;
|
|
24
|
-
return itemDescription(data) || void 0;
|
|
25
|
-
}
|
|
26
7
|
const ObjectRenderer = createObjectFieldRenderer(({ field })=>{
|
|
27
8
|
const settings = field.rendererSettings;
|
|
28
|
-
|
|
29
|
-
layout: field.layout
|
|
30
|
-
});
|
|
9
|
+
const formatters = useFieldValueFormatters();
|
|
31
10
|
const focusInside = hasSubtreeFocusRequest(field.fields);
|
|
32
11
|
const [open, setOpen] = useState(settings?.open ?? true);
|
|
33
12
|
useEffect(()=>{
|
|
@@ -35,12 +14,15 @@ const ObjectRenderer = createObjectFieldRenderer(({ field })=>{
|
|
|
35
14
|
}, [
|
|
36
15
|
focusInside
|
|
37
16
|
]);
|
|
17
|
+
if (settings?.container === false) return /*#__PURE__*/ react.createElement(NestedLayout, {
|
|
18
|
+
layout: field.layout
|
|
19
|
+
});
|
|
38
20
|
return /*#__PURE__*/ react.createElement(Accordion, {
|
|
39
21
|
background: "base",
|
|
40
22
|
variant: "container"
|
|
41
23
|
}, /*#__PURE__*/ react.createElement(Accordion.Item, {
|
|
42
|
-
title:
|
|
43
|
-
description:
|
|
24
|
+
title: resolveItemTitle(field.fields, 0, field.label || "", settings?.itemTitle, formatters),
|
|
25
|
+
description: resolveItemDescription(field.fields, 0, settings?.itemDescription, formatters),
|
|
44
26
|
open: open,
|
|
45
27
|
onOpenChange: setOpen,
|
|
46
28
|
className: "pl-sm"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/ObjectRenderer.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/ObjectRenderer.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { Accordion } from \"@webiny/admin-ui\";\nimport { createObjectFieldRenderer } from \"~/features/formModel/createFieldRenderer.js\";\nimport { NestedLayout } from \"./ObjectFieldComponents.js\";\nimport
|
|
1
|
+
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/ObjectRenderer.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/ObjectRenderer.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { Accordion } from \"@webiny/admin-ui\";\nimport { createObjectFieldRenderer } from \"~/features/formModel/createFieldRenderer.js\";\nimport { NestedLayout, useFieldValueFormatters } from \"./ObjectFieldComponents.js\";\nimport { resolveItemDescription, resolveItemTitle } from \"./resolveItemTitle.js\";\nimport { hasSubtreeFocusRequest } from \"~/features/formModel/index.js\";\n\ndeclare module \"../../../../features/formModel/abstractions.js\" {\n interface IFieldRendererRegistry {\n objectAccordionSingle: {\n fieldType: \"object\";\n settings?: {\n open?: boolean;\n container?: boolean;\n itemTitle?: string | ((data: Record<string, unknown>) => string);\n itemDescription?: string | ((data: Record<string, unknown>) => string);\n };\n };\n }\n}\n\nexport const ObjectRenderer = createObjectFieldRenderer<\"objectAccordionSingle\">(({ field }) => {\n const settings = field.rendererSettings;\n const formatters = useFieldValueFormatters();\n\n // Force the object accordion open when a focus request lands anywhere in\n // its subtree, so \"jump to field\" can cascade through collapsed levels.\n const focusInside = hasSubtreeFocusRequest(field.fields);\n const [open, setOpen] = useState(settings?.open ?? true);\n useEffect(() => {\n if (focusInside) {\n setOpen(true);\n }\n }, [focusInside]);\n\n if (settings?.container === false) {\n return <NestedLayout layout={field.layout} />;\n }\n\n return (\n <Accordion background={\"base\"} variant={\"container\"}>\n <Accordion.Item\n title={resolveItemTitle(\n field.fields,\n 0,\n field.label || \"\",\n settings?.itemTitle,\n formatters\n )}\n description={resolveItemDescription(\n field.fields,\n 0,\n settings?.itemDescription,\n formatters\n )}\n open={open}\n onOpenChange={setOpen}\n className={\"pl-sm\"}\n >\n <NestedLayout layout={field.layout} />\n </Accordion.Item>\n </Accordion>\n );\n});\n"],"names":["ObjectRenderer","createObjectFieldRenderer","field","settings","formatters","useFieldValueFormatters","focusInside","hasSubtreeFocusRequest","open","setOpen","useState","useEffect","NestedLayout","Accordion","resolveItemTitle","resolveItemDescription"],"mappings":";;;;;;AAqBO,MAAMA,iBAAiBC,0BAAmD,CAAC,EAAEC,KAAK,EAAE;IACvF,MAAMC,WAAWD,MAAM,gBAAgB;IACvC,MAAME,aAAaC;IAInB,MAAMC,cAAcC,uBAAuBL,MAAM,MAAM;IACvD,MAAM,CAACM,MAAMC,QAAQ,GAAGC,SAASP,UAAU,QAAQ;IACnDQ,UAAU;QACN,IAAIL,aACAG,QAAQ;IAEhB,GAAG;QAACH;KAAY;IAEhB,IAAIH,UAAU,cAAc,OACxB,OAAO,WAAP,GAAO,oBAACS,cAAYA;QAAC,QAAQV,MAAM,MAAM;;IAG7C,OAAO,WAAP,GACI,oBAACW,WAASA;QAAC,YAAY;QAAQ,SAAS;qBACpC,oBAACA,UAAU,IAAI;QACX,OAAOC,iBACHZ,MAAM,MAAM,EACZ,GACAA,MAAM,KAAK,IAAI,IACfC,UAAU,WACVC;QAEJ,aAAaW,uBACTb,MAAM,MAAM,EACZ,GACAC,UAAU,iBACVC;QAEJ,MAAMI;QACN,cAAcC;QACd,WAAW;qBAEX,oBAACG,cAAYA;QAAC,QAAQV,MAAM,MAAM;;AAIlD"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IFieldValueFormatter, IFieldVM } from "../../../../features/formModel/index.js";
|
|
2
2
|
type ItemStringSetting = string | ((data: Record<string, unknown>, index: number) => string);
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The text a field's value reads as in a summary. A formatter registered for the field's type
|
|
5
|
+
* wins; otherwise each value is printed, swapped for its option label when the field has options.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatFieldValue(field: IFieldVM, formatters: IFieldValueFormatter[]): string;
|
|
8
|
+
export declare function resolveItemTitle(fields: IFieldVM[], index: number, fallback: string, itemTitle: ItemStringSetting | undefined, formatters: IFieldValueFormatter[]): string;
|
|
9
|
+
export declare function resolveItemDescription(fields: IFieldVM[], index: number, itemDescription: ItemStringSetting | undefined, formatters: IFieldValueFormatter[]): string | undefined;
|
|
5
10
|
export {};
|
|
@@ -3,26 +3,34 @@ function fieldsToData(fields) {
|
|
|
3
3
|
for (const field of fields)data[field.name] = field.value;
|
|
4
4
|
return data;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
function formatScalar(value, options) {
|
|
7
|
+
if (null == value || "object" == typeof value) return "";
|
|
8
|
+
const option = options?.find((o)=>String(o.value) === String(value));
|
|
9
|
+
return option ? option.label : String(value);
|
|
10
|
+
}
|
|
11
|
+
function formatFieldValue(field, formatters) {
|
|
12
|
+
const formatter = formatters.find((f)=>f.type === field.type);
|
|
13
|
+
if (formatter) return formatter.format(field) ?? "";
|
|
14
|
+
const values = Array.isArray(field.value) ? field.value : [
|
|
15
|
+
field.value
|
|
16
|
+
];
|
|
17
|
+
return values.map((value)=>formatScalar(value, field.options)).filter(Boolean).join(", ");
|
|
18
|
+
}
|
|
19
|
+
function resolveSetting(fields, index, setting, formatters) {
|
|
20
|
+
if ("string" == typeof setting) {
|
|
21
|
+
const field = fields.find((f)=>f.name === setting);
|
|
22
|
+
return field ? formatFieldValue(field, formatters) : "";
|
|
13
23
|
}
|
|
14
|
-
|
|
15
|
-
return itemTitle(data, index) || fallback;
|
|
24
|
+
return setting(fieldsToData(fields), index);
|
|
16
25
|
}
|
|
17
|
-
function
|
|
26
|
+
function resolveItemTitle(fields, index, fallback, itemTitle, formatters) {
|
|
27
|
+
if (!itemTitle) return fallback;
|
|
28
|
+
return resolveSetting(fields, index, itemTitle, formatters) || fallback;
|
|
29
|
+
}
|
|
30
|
+
function resolveItemDescription(fields, index, itemDescription, formatters) {
|
|
18
31
|
if (!itemDescription) return;
|
|
19
|
-
|
|
20
|
-
const field = item.fields.find((f)=>f.name === itemDescription);
|
|
21
|
-
return field ? String(field.value ?? "") || void 0 : void 0;
|
|
22
|
-
}
|
|
23
|
-
const data = fieldsToData(item.fields);
|
|
24
|
-
return itemDescription(data, index) || void 0;
|
|
32
|
+
return resolveSetting(fields, index, itemDescription, formatters) || void 0;
|
|
25
33
|
}
|
|
26
|
-
export { resolveItemDescription, resolveItemTitle };
|
|
34
|
+
export { formatFieldValue, resolveItemDescription, resolveItemTitle };
|
|
27
35
|
|
|
28
36
|
//# sourceMappingURL=resolveItemTitle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.ts"],"sourcesContent":["import type { IFieldVM,
|
|
1
|
+
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.ts"],"sourcesContent":["import type { IFieldValueFormatter, IFieldVM, IValueOption } from \"~/features/formModel/index.js\";\n\ntype ItemStringSetting = string | ((data: Record<string, unknown>, index: number) => string);\n\nfunction fieldsToData(fields: IFieldVM[]): Record<string, unknown> {\n const data: Record<string, unknown> = {};\n for (const field of fields) {\n data[field.name] = field.value;\n }\n return data;\n}\n\nfunction formatScalar(value: unknown, options: IValueOption[] | undefined): string {\n if (value === null || value === undefined || typeof value === \"object\") {\n return \"\";\n }\n // Predefined values store the option's value; the editor knows the option by its label.\n const option = options?.find(o => String(o.value) === String(value));\n return option ? option.label : String(value);\n}\n\n/**\n * The text a field's value reads as in a summary. A formatter registered for the field's type\n * wins; otherwise each value is printed, swapped for its option label when the field has options.\n */\nexport function formatFieldValue(field: IFieldVM, formatters: IFieldValueFormatter[]): string {\n const formatter = formatters.find(f => f.type === field.type);\n if (formatter) {\n return formatter.format(field) ?? \"\";\n }\n\n const values = Array.isArray(field.value) ? field.value : [field.value];\n return values\n .map(value => formatScalar(value, field.options))\n .filter(Boolean)\n .join(\", \");\n}\n\nfunction resolveSetting(\n fields: IFieldVM[],\n index: number,\n setting: ItemStringSetting,\n formatters: IFieldValueFormatter[]\n): string {\n if (typeof setting === \"string\") {\n const field = fields.find(f => f.name === setting);\n return field ? formatFieldValue(field, formatters) : \"\";\n }\n\n return setting(fieldsToData(fields), index);\n}\n\nexport function resolveItemTitle(\n fields: IFieldVM[],\n index: number,\n fallback: string,\n itemTitle: ItemStringSetting | undefined,\n formatters: IFieldValueFormatter[]\n): string {\n if (!itemTitle) {\n return fallback;\n }\n\n return resolveSetting(fields, index, itemTitle, formatters) || fallback;\n}\n\nexport function resolveItemDescription(\n fields: IFieldVM[],\n index: number,\n itemDescription: ItemStringSetting | undefined,\n formatters: IFieldValueFormatter[]\n): string | undefined {\n if (!itemDescription) {\n return undefined;\n }\n\n return resolveSetting(fields, index, itemDescription, formatters) || undefined;\n}\n"],"names":["fieldsToData","fields","data","field","formatScalar","value","options","option","o","String","formatFieldValue","formatters","formatter","f","values","Array","Boolean","resolveSetting","index","setting","resolveItemTitle","fallback","itemTitle","resolveItemDescription","itemDescription","undefined"],"mappings":"AAIA,SAASA,aAAaC,MAAkB;IACpC,MAAMC,OAAgC,CAAC;IACvC,KAAK,MAAMC,SAASF,OAChBC,IAAI,CAACC,MAAM,IAAI,CAAC,GAAGA,MAAM,KAAK;IAElC,OAAOD;AACX;AAEA,SAASE,aAAaC,KAAc,EAAEC,OAAmC;IACrE,IAAID,QAAAA,SAAyC,AAAiB,YAAjB,OAAOA,OAChD,OAAO;IAGX,MAAME,SAASD,SAAS,KAAKE,CAAAA,IAAKC,OAAOD,EAAE,KAAK,MAAMC,OAAOJ;IAC7D,OAAOE,SAASA,OAAO,KAAK,GAAGE,OAAOJ;AAC1C;AAMO,SAASK,iBAAiBP,KAAe,EAAEQ,UAAkC;IAChF,MAAMC,YAAYD,WAAW,IAAI,CAACE,CAAAA,IAAKA,EAAE,IAAI,KAAKV,MAAM,IAAI;IAC5D,IAAIS,WACA,OAAOA,UAAU,MAAM,CAACT,UAAU;IAGtC,MAAMW,SAASC,MAAM,OAAO,CAACZ,MAAM,KAAK,IAAIA,MAAM,KAAK,GAAG;QAACA,MAAM,KAAK;KAAC;IACvE,OAAOW,OACF,GAAG,CAACT,CAAAA,QAASD,aAAaC,OAAOF,MAAM,OAAO,GAC9C,MAAM,CAACa,SACP,IAAI,CAAC;AACd;AAEA,SAASC,eACLhB,MAAkB,EAClBiB,KAAa,EACbC,OAA0B,EAC1BR,UAAkC;IAElC,IAAI,AAAmB,YAAnB,OAAOQ,SAAsB;QAC7B,MAAMhB,QAAQF,OAAO,IAAI,CAACY,CAAAA,IAAKA,EAAE,IAAI,KAAKM;QAC1C,OAAOhB,QAAQO,iBAAiBP,OAAOQ,cAAc;IACzD;IAEA,OAAOQ,QAAQnB,aAAaC,SAASiB;AACzC;AAEO,SAASE,iBACZnB,MAAkB,EAClBiB,KAAa,EACbG,QAAgB,EAChBC,SAAwC,EACxCX,UAAkC;IAElC,IAAI,CAACW,WACD,OAAOD;IAGX,OAAOJ,eAAehB,QAAQiB,OAAOI,WAAWX,eAAeU;AACnE;AAEO,SAASE,uBACZtB,MAAkB,EAClBiB,KAAa,EACbM,eAA8C,EAC9Cb,UAAkC;IAElC,IAAI,CAACa,iBACD;IAGJ,OAAOP,eAAehB,QAAQiB,OAAOM,iBAAiBb,eAAec;AACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { resolveItemDescription, resolveItemTitle } from "./resolveItemTitle.js";
|
|
3
|
+
const field = (name, type, value, extra = {})=>({
|
|
4
|
+
name,
|
|
5
|
+
type,
|
|
6
|
+
value,
|
|
7
|
+
...extra
|
|
8
|
+
});
|
|
9
|
+
const classTypes = [
|
|
10
|
+
{
|
|
11
|
+
label: "Fitness",
|
|
12
|
+
value: "fitness"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: "Personal Training",
|
|
16
|
+
value: "personal-training"
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
describe("resolveItemTitle", ()=>{
|
|
20
|
+
it("shows the label of a predefined value instead of its value", ()=>{
|
|
21
|
+
const fields = [
|
|
22
|
+
field("classType", "text", "personal-training", {
|
|
23
|
+
options: classTypes
|
|
24
|
+
})
|
|
25
|
+
];
|
|
26
|
+
expect(resolveItemTitle(fields, 0, "Item #1", "classType", [])).toBe("Personal Training");
|
|
27
|
+
});
|
|
28
|
+
it("joins the labels of a list of predefined values", ()=>{
|
|
29
|
+
const fields = [
|
|
30
|
+
field("classTypes", "text", [
|
|
31
|
+
"fitness",
|
|
32
|
+
"personal-training"
|
|
33
|
+
], {
|
|
34
|
+
options: classTypes
|
|
35
|
+
})
|
|
36
|
+
];
|
|
37
|
+
expect(resolveItemTitle(fields, 0, "Item #1", "classTypes", [])).toBe("Fitness, Personal Training");
|
|
38
|
+
});
|
|
39
|
+
it("matches a numeric predefined value", ()=>{
|
|
40
|
+
const fields = [
|
|
41
|
+
field("size", "number", 2, {
|
|
42
|
+
options: [
|
|
43
|
+
{
|
|
44
|
+
label: "Small",
|
|
45
|
+
value: 1
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: "Large",
|
|
49
|
+
value: 2
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
];
|
|
54
|
+
expect(resolveItemTitle(fields, 0, "Item #1", "size", [])).toBe("Large");
|
|
55
|
+
});
|
|
56
|
+
it("hands the value to the formatter registered for the field's type", ()=>{
|
|
57
|
+
const formatter = {
|
|
58
|
+
type: "ref",
|
|
59
|
+
format: (f)=>null === f.value ? void 0 : "Baker"
|
|
60
|
+
};
|
|
61
|
+
const fields = [
|
|
62
|
+
field("location", "ref", {
|
|
63
|
+
id: "baker#0001",
|
|
64
|
+
modelId: "location"
|
|
65
|
+
})
|
|
66
|
+
];
|
|
67
|
+
expect(resolveItemTitle(fields, 0, "Item #1", "location", [
|
|
68
|
+
formatter
|
|
69
|
+
])).toBe("Baker");
|
|
70
|
+
expect(resolveItemDescription(fields, 0, "location", [
|
|
71
|
+
formatter
|
|
72
|
+
])).toBe("Baker");
|
|
73
|
+
});
|
|
74
|
+
it("falls back while a value has no readable text", ()=>{
|
|
75
|
+
const loading = {
|
|
76
|
+
type: "ref",
|
|
77
|
+
format: ()=>void 0
|
|
78
|
+
};
|
|
79
|
+
const fields = [
|
|
80
|
+
field("location", "ref", {
|
|
81
|
+
id: "baker#0001",
|
|
82
|
+
modelId: "location"
|
|
83
|
+
}),
|
|
84
|
+
field("details", "object", {
|
|
85
|
+
a: 1
|
|
86
|
+
})
|
|
87
|
+
];
|
|
88
|
+
expect(resolveItemTitle(fields, 2, "Facility #3", "location", [
|
|
89
|
+
loading
|
|
90
|
+
])).toBe("Facility #3");
|
|
91
|
+
expect(resolveItemTitle(fields, 2, "Facility #3", "details", [])).toBe("Facility #3");
|
|
92
|
+
expect(resolveItemDescription(fields, 2, "location", [
|
|
93
|
+
loading
|
|
94
|
+
])).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
it("passes raw values to a title function", ()=>{
|
|
97
|
+
const fields = [
|
|
98
|
+
field("classType", "text", "fitness", {
|
|
99
|
+
options: classTypes
|
|
100
|
+
})
|
|
101
|
+
];
|
|
102
|
+
expect(resolveItemTitle(fields, 1, "Item #2", (data, index)=>`${data.classType} ${index}`, [])).toBe("fitness 1");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=resolveItemTitle.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.test.js","sources":["../../../../../src/base/Base/FieldRenderers/ObjectRenderer/resolveItemTitle.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport type { IFieldValueFormatter, IFieldVM } from \"~/features/formModel/index.js\";\nimport { resolveItemDescription, resolveItemTitle } from \"./resolveItemTitle.js\";\n\nconst field = (name: string, type: string, value: unknown, extra: Partial<IFieldVM> = {}) =>\n ({ name, type, value, ...extra }) as IFieldVM;\n\nconst classTypes = [\n { label: \"Fitness\", value: \"fitness\" },\n { label: \"Personal Training\", value: \"personal-training\" }\n];\n\ndescribe(\"resolveItemTitle\", () => {\n it(\"shows the label of a predefined value instead of its value\", () => {\n const fields = [field(\"classType\", \"text\", \"personal-training\", { options: classTypes })];\n\n expect(resolveItemTitle(fields, 0, \"Item #1\", \"classType\", [])).toBe(\"Personal Training\");\n });\n\n it(\"joins the labels of a list of predefined values\", () => {\n const fields = [\n field(\"classTypes\", \"text\", [\"fitness\", \"personal-training\"], { options: classTypes })\n ];\n\n expect(resolveItemTitle(fields, 0, \"Item #1\", \"classTypes\", [])).toBe(\n \"Fitness, Personal Training\"\n );\n });\n\n it(\"matches a numeric predefined value\", () => {\n const fields = [\n field(\"size\", \"number\", 2, {\n options: [\n { label: \"Small\", value: 1 },\n { label: \"Large\", value: 2 }\n ]\n })\n ];\n\n expect(resolveItemTitle(fields, 0, \"Item #1\", \"size\", [])).toBe(\"Large\");\n });\n\n it(\"hands the value to the formatter registered for the field's type\", () => {\n const formatter: IFieldValueFormatter = {\n type: \"ref\",\n format: f => (f.value === null ? undefined : \"Baker\")\n };\n const fields = [field(\"location\", \"ref\", { id: \"baker#0001\", modelId: \"location\" })];\n\n expect(resolveItemTitle(fields, 0, \"Item #1\", \"location\", [formatter])).toBe(\"Baker\");\n expect(resolveItemDescription(fields, 0, \"location\", [formatter])).toBe(\"Baker\");\n });\n\n it(\"falls back while a value has no readable text\", () => {\n const loading: IFieldValueFormatter = { type: \"ref\", format: () => undefined };\n const fields = [\n field(\"location\", \"ref\", { id: \"baker#0001\", modelId: \"location\" }),\n field(\"details\", \"object\", { a: 1 })\n ];\n\n expect(resolveItemTitle(fields, 2, \"Facility #3\", \"location\", [loading])).toBe(\n \"Facility #3\"\n );\n expect(resolveItemTitle(fields, 2, \"Facility #3\", \"details\", [])).toBe(\"Facility #3\");\n expect(resolveItemDescription(fields, 2, \"location\", [loading])).toBeUndefined();\n });\n\n it(\"passes raw values to a title function\", () => {\n const fields = [field(\"classType\", \"text\", \"fitness\", { options: classTypes })];\n\n expect(\n resolveItemTitle(\n fields,\n 1,\n \"Item #2\",\n (data, index) => `${data.classType} ${index}`,\n []\n )\n ).toBe(\"fitness 1\");\n });\n});\n"],"names":["field","name","type","value","extra","classTypes","describe","it","fields","expect","resolveItemTitle","formatter","f","undefined","resolveItemDescription","loading","data","index"],"mappings":";;AAIA,MAAMA,QAAQ,CAACC,MAAcC,MAAcC,OAAgBC,QAA2B,CAAC,CAAC,GACnF;QAAEH;QAAMC;QAAMC;QAAO,GAAGC,KAAK;IAAC;AAEnC,MAAMC,aAAa;IACf;QAAE,OAAO;QAAW,OAAO;IAAU;IACrC;QAAE,OAAO;QAAqB,OAAO;IAAoB;CAC5D;AAEDC,SAAS,oBAAoB;IACzBC,GAAG,8DAA8D;QAC7D,MAAMC,SAAS;YAACR,MAAM,aAAa,QAAQ,qBAAqB;gBAAE,SAASK;YAAW;SAAG;QAEzFI,OAAOC,iBAAiBF,QAAQ,GAAG,WAAW,aAAa,EAAE,GAAG,IAAI,CAAC;IACzE;IAEAD,GAAG,mDAAmD;QAClD,MAAMC,SAAS;YACXR,MAAM,cAAc,QAAQ;gBAAC;gBAAW;aAAoB,EAAE;gBAAE,SAASK;YAAW;SACvF;QAEDI,OAAOC,iBAAiBF,QAAQ,GAAG,WAAW,cAAc,EAAE,GAAG,IAAI,CACjE;IAER;IAEAD,GAAG,sCAAsC;QACrC,MAAMC,SAAS;YACXR,MAAM,QAAQ,UAAU,GAAG;gBACvB,SAAS;oBACL;wBAAE,OAAO;wBAAS,OAAO;oBAAE;oBAC3B;wBAAE,OAAO;wBAAS,OAAO;oBAAE;iBAC9B;YACL;SACH;QAEDS,OAAOC,iBAAiBF,QAAQ,GAAG,WAAW,QAAQ,EAAE,GAAG,IAAI,CAAC;IACpE;IAEAD,GAAG,oEAAoE;QACnE,MAAMI,YAAkC;YACpC,MAAM;YACN,QAAQC,CAAAA,IAAMA,AAAY,SAAZA,EAAE,KAAK,GAAYC,SAAY;QACjD;QACA,MAAML,SAAS;YAACR,MAAM,YAAY,OAAO;gBAAE,IAAI;gBAAc,SAAS;YAAW;SAAG;QAEpFS,OAAOC,iBAAiBF,QAAQ,GAAG,WAAW,YAAY;YAACG;SAAU,GAAG,IAAI,CAAC;QAC7EF,OAAOK,uBAAuBN,QAAQ,GAAG,YAAY;YAACG;SAAU,GAAG,IAAI,CAAC;IAC5E;IAEAJ,GAAG,iDAAiD;QAChD,MAAMQ,UAAgC;YAAE,MAAM;YAAO,QAAQ,IAAMF;QAAU;QAC7E,MAAML,SAAS;YACXR,MAAM,YAAY,OAAO;gBAAE,IAAI;gBAAc,SAAS;YAAW;YACjEA,MAAM,WAAW,UAAU;gBAAE,GAAG;YAAE;SACrC;QAEDS,OAAOC,iBAAiBF,QAAQ,GAAG,eAAe,YAAY;YAACO;SAAQ,GAAG,IAAI,CAC1E;QAEJN,OAAOC,iBAAiBF,QAAQ,GAAG,eAAe,WAAW,EAAE,GAAG,IAAI,CAAC;QACvEC,OAAOK,uBAAuBN,QAAQ,GAAG,YAAY;YAACO;SAAQ,GAAG,aAAa;IAClF;IAEAR,GAAG,yCAAyC;QACxC,MAAMC,SAAS;YAACR,MAAM,aAAa,QAAQ,WAAW;gBAAE,SAASK;YAAW;SAAG;QAE/EI,OACIC,iBACIF,QACA,GACA,WACA,CAACQ,MAAMC,QAAU,GAAGD,KAAK,SAAS,CAAC,CAAC,EAAEC,OAAO,EAC7C,EAAE,GAER,IAAI,CAAC;IACX;AACJ"}
|
|
@@ -787,6 +787,22 @@ export declare namespace FieldType {
|
|
|
787
787
|
type FieldBuilder = IFieldBuilder;
|
|
788
788
|
type FieldBuilderRegistry = IFieldBuilderRegistry;
|
|
789
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* Turns a field's value into the text shown where the value is summarised rather than edited,
|
|
792
|
+
* such as an accordion item's title. Register one for a field type whose raw value is not
|
|
793
|
+
* readable, like a reference, which holds an entry ID rather than the entry's title.
|
|
794
|
+
*
|
|
795
|
+
* `format` is read inside an observer, so it may return `undefined` while it loads a value and
|
|
796
|
+
* an observable value once it has it.
|
|
797
|
+
*/
|
|
798
|
+
export interface IFieldValueFormatter {
|
|
799
|
+
readonly type: string;
|
|
800
|
+
format(field: IFieldVM): string | undefined;
|
|
801
|
+
}
|
|
802
|
+
export declare const FieldValueFormatter: import("@webiny/di").Abstraction<IFieldValueFormatter>;
|
|
803
|
+
export declare namespace FieldValueFormatter {
|
|
804
|
+
type Interface = IFieldValueFormatter;
|
|
805
|
+
}
|
|
790
806
|
export declare const FieldBuilderRegistry: import("@webiny/di").Abstraction<IFieldBuilderRegistry>;
|
|
791
807
|
export declare namespace FieldBuilderRegistry {
|
|
792
808
|
type Interface = IFieldBuilderRegistry;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/admin";
|
|
2
2
|
const FieldType = createAbstraction("FormModel/FieldType");
|
|
3
|
+
const FieldValueFormatter = createAbstraction("FormModel/FieldValueFormatter");
|
|
3
4
|
const FieldBuilderRegistry = createAbstraction("FormModel/FieldBuilderRegistry");
|
|
4
5
|
const FormModelFactory = createAbstraction("FormModelFactory");
|
|
5
6
|
const RuleEvaluator = createAbstraction("FormModelRuleEvaluator");
|
|
6
|
-
export { FieldBuilderRegistry, FieldType, FormModelFactory, RuleEvaluator };
|
|
7
|
+
export { FieldBuilderRegistry, FieldType, FieldValueFormatter, FormModelFactory, RuleEvaluator };
|
|
7
8
|
|
|
8
9
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/formModel/abstractions.js","sources":["../../../src/features/formModel/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { z } from \"zod\";\nimport type { Icon } from \"~/components/IconPicker/types.js\";\n\n// ---------------------------------------------------------------------------\n// Renderer registry — augmented by each renderer via declare module\n// ---------------------------------------------------------------------------\n\nexport interface IFieldRendererRegistry {}\n\nexport type FieldRendererName<\n TType extends string = string,\n TOptions extends boolean = boolean\n> = string extends TType\n ? keyof IFieldRendererRegistry & string\n : {\n [K in keyof IFieldRendererRegistry]: TType extends IFieldRendererRegistry[K][\"fieldType\"]\n ? boolean extends TOptions\n ? K\n : TOptions extends true\n ? IFieldRendererRegistry[K] extends { options: true }\n ? K\n : never\n : IFieldRendererRegistry[K] extends { options: true }\n ? never\n : K\n : never;\n }[keyof IFieldRendererRegistry] &\n string;\n\nexport type FieldRendererSettings<TName extends string> = TName extends keyof IFieldRendererRegistry\n ? IFieldRendererRegistry[TName][\"settings\"]\n : Record<string, unknown> | undefined;\n\n// ---------------------------------------------------------------------------\n// Field types\n// ---------------------------------------------------------------------------\n\nexport interface IFieldConfig {\n name: string;\n type: string;\n label?: string;\n help?: string;\n description?: string;\n note?: string;\n placeholder?: string;\n defaultValue?: unknown;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n isList?: boolean;\n hidden: boolean;\n required: boolean;\n requiredMessage?: string;\n disabled: boolean;\n schema?: z.ZodTypeAny;\n options?: IValueOption[] | ((params: IFieldCallbackParams) => IValueOption[]);\n normalizeValue?: (value: unknown) => unknown;\n beforeChangeCallbacks?: BeforeChangeCallback[];\n afterChangeCallbacks?: AfterChangeCallback[];\n afterSetValueCallbacks?: AfterSetValueCallback[];\n onBlurCallbacks?: OnBlurCallback[];\n requiredWhenCallbacks?: RequiredWhenCallback[];\n hiddenWhenCallbacks?: HiddenWhenCallback[];\n disabledWhenCallbacks?: DisabledWhenCallback[];\n computed?: ComputedFieldCallback;\n computedUntilDirty?: ComputedFieldCallback;\n tags?: string[];\n cloneValue?: CloneValueCallback;\n context?: FieldContextCallback;\n rules?: IRule[];\n}\n\nexport interface IFieldScope {\n field(name: string): IField;\n parent(): IFieldScope;\n}\n\nexport interface IFieldNavigator {\n parent(): IFieldScope;\n}\n\nexport interface IFieldCallbackParams {\n field: IFieldNavigator;\n form: IFormModel;\n}\n\nexport interface IRequiredWhenCallbackConfig {\n fn: (params: IFieldCallbackParams) => boolean;\n message?: string;\n}\n\nexport type RequiredWhenCallback = IRequiredWhenCallbackConfig;\n\nexport type HiddenWhenCallback = (params: IFieldCallbackParams) => boolean;\n\nexport type DisabledWhenCallback = (params: IFieldCallbackParams) => boolean;\n\nexport type ComputedFieldCallback = (params: IFieldCallbackParams) => unknown;\n\nexport type FieldContextCallback = (params: IFieldCallbackParams) => Record<string, unknown>;\n\n// ---------------------------------------------------------------------------\n// Rules system\n// ---------------------------------------------------------------------------\n\nexport type RuleAction = \"hide\" | \"disable\";\n\nexport type RuleOperator =\n | \"==\"\n | \"eq\"\n | \"!=\"\n | \"neq\"\n | \">\"\n | \"gt\"\n | \"<\"\n | \"lt\"\n | \">=\"\n | \"gte\"\n | \"<=\"\n | \"lte\"\n | \"isEmpty\"\n | \"isNotEmpty\"\n | \"isTruthy\"\n | \"isFalsy\"\n | \"matches\"\n | \"contains\"\n | \"notContains\"\n | \"startsWith\"\n | \"notStartsWith\"\n | \"endsWith\"\n | \"notEndsWith\";\n\nexport interface IRule {\n type: string;\n target: string;\n operator: RuleOperator | (string & {});\n value: string | number | boolean | null;\n action: RuleAction;\n}\n\nexport interface IRuleEvaluator {\n canEvaluate(rule: IRule): boolean;\n evaluate(rule: IRule, form: IFormModel): boolean;\n}\n\nexport interface IValueOption<V extends string | number = string | number> {\n label: string;\n value: V;\n disabled?: boolean;\n}\n\nexport type OptionValueType<TType extends string> = TType extends \"number\" ? number : string;\n\nexport interface IFieldValidation {\n isValid: boolean | null;\n message?: string;\n}\n\nexport interface IFieldVM {\n name: string;\n /** Full dotted path of the field within the form (e.g. \"author.address.street\"). */\n qualifiedName: string;\n type: string;\n label?: string;\n help?: string;\n description?: string;\n note?: string;\n placeholder?: string;\n value: unknown;\n validation: IFieldValidation;\n validating: boolean;\n required: boolean;\n visible: boolean;\n disabled: boolean;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n isList?: boolean;\n options?: IValueOption[];\n onChange: (value: unknown) => void;\n onBlur: () => void;\n addItem: (value?: unknown) => void;\n removeItem: (index: number) => void;\n focusRequested: boolean;\n clearFocusRequest: () => void;\n context: Record<string, unknown>;\n}\n\nexport interface IObjectFieldVM extends IFieldVM {\n type: \"object\";\n isList: boolean;\n /** Child field VMs for non-list object fields. */\n fields: IFieldVM[];\n /**\n * Resolved layout for non-list object fields. For templated objects, resolves\n * against the active template's per-template layout (if registered via\n * `layout.object()`), otherwise defaults to one row per visible child.\n * For list-mode fields, see `items[].layout`.\n */\n layout: LayoutNodeVM[];\n /** Items for list-mode object fields. */\n items: IObjectFieldItemVM[];\n /** Append a new item. Templated lists require a template id. */\n addItem: (value?: unknown) => void;\n moveItem: (fromIndex: number, toIndex: number) => void;\n /** Duplicate a list item (including its `_templateId` when templated) and insert it after the source. */\n duplicateItem: (index: number) => void;\n /** True when the object has templates defined. */\n isTemplated: boolean;\n /** Templates visible in the picker (filtered by each template's reactive `visible`). */\n availableTemplates: ITemplateVM[];\n /** Currently active template id (single-object mode), or null if no template picked. */\n activeTemplateId: string | null;\n /** Switch to a different template. Discards values not present in the new template. */\n setTemplate: (templateId: string) => void;\n /** Returns a cloned copy of the current single-value data with cloneValue transforms applied. */\n getClonedData: () => Record<string, unknown>;\n}\n\nexport interface IObjectFieldItemVM {\n key: string;\n fields: IFieldVM[];\n /**\n * Resolved layout for this item. For templated lists, resolves against the\n * item's template-specific layout (if registered via `layout.object()`),\n * otherwise defaults to one row per visible child.\n */\n layout: LayoutNodeVM[];\n remove: () => void;\n moveUp: () => void;\n moveDown: () => void;\n duplicate: () => void;\n getClonedData: () => Record<string, unknown>;\n /** The template id of this item, if the parent list is templated. */\n templateId?: string;\n}\n\n/**\n * VM exposed for each available template in the picker.\n */\nexport interface ITemplateIcon {\n type: string;\n name: string;\n}\n\nexport interface ITemplateVM {\n id: string;\n label: string;\n description?: string;\n icon?: ITemplateIcon;\n}\n\nexport interface IField {\n readonly name: string;\n readonly type: string;\n readonly visible: boolean;\n readonly disabled: boolean;\n readonly vm: IFieldVM;\n readonly config: IFieldConfig;\n getValue<T = unknown>(): T;\n setValue(value: unknown): void;\n setValueSilent(value: unknown): void;\n setDisabled(value: boolean): void;\n setVisible(value: boolean): void;\n /**\n * `parentPath` is the parent's qualified name. `scopePath` returns a path that\n * `form.field()` resolves to the parent itself; it differs from `parentPath` for\n * list item children, where it includes the item index (`blocks.2`). `$.` rule\n * targets and `field.parent()` resolve against it. Defaults to `parentPath`.\n */\n setForm(form: IFormModel, parentPath?: string, scopePath?: () => string): void;\n setAncestorRules(rules: IRule[]): void;\n setValidation(validation: IFieldValidation): void;\n resetValidation(): void;\n validate(options?: { force?: boolean }): Promise<boolean>;\n remove(): void;\n addBeforeChange(cb: BeforeChangeCallback): void;\n addAfterChange(cb: AfterChangeCallback): void;\n addAfterSetValue(cb: AfterSetValueCallback): void;\n addOnBlur(cb: OnBlurCallback): void;\n /**\n * Append a conditional required check. Multiple callbacks chain additively;\n * the first one returning `true` makes the field required for the current\n * form state. The built-in `.required()` flag (if set) always counts as a\n * truthy check and cannot be overridden.\n */\n addRequiredWhen(fn: (params: IFieldCallbackParams) => boolean, message?: string): void;\n /**\n * Mark this field as a derived value computed from `fn(form)`. The field\n * stays editable (no auto-disable) and is excluded from `isDirty` while\n * still tracking the computed value. Validation continues to apply.\n */\n setComputed(fn: ComputedFieldCallback): void;\n /**\n * Same as `setComputed`, but the field switches to manual mode the first\n * time the user edits its value. After that, the computed callback no\n * longer overrides user input.\n */\n setComputedUntilDirty(fn: ComputedFieldCallback): void;\n blur(): void;\n as<T extends keyof FieldTypeMap>(type: T): FieldTypeMap[T];\n readonly qualifiedName: string;\n focus(): void;\n requestFocus(): void;\n clearFocusRequest(): void;\n}\n\n/**\n * Maps field type strings to their typed field interfaces.\n * Extended via module augmentation when new field types are registered.\n */\nexport interface ITypedField<V> extends IField {\n getValue<T = V>(): T;\n}\n\ntype InferFieldTypeMap = {\n [K in keyof IFieldBuilderRegistry]: ReturnType<\n IFieldBuilderRegistry[K]\n > extends IObjectFieldBuilder\n ? IObjectField\n : ReturnType<IFieldBuilderRegistry[K]> extends { readonly __valueType?: infer V }\n ? ITypedField<V>\n : IField;\n};\n\nexport type FieldTypeMap = { [K in keyof InferFieldTypeMap]: InferFieldTypeMap[K] };\n\nexport type FileValue = {\n id: string;\n name: string;\n size: number;\n mimeType: string;\n src: string;\n width: number | undefined;\n height: number | undefined;\n};\n\n// ---------------------------------------------------------------------------\n// Object / List field types\n// ---------------------------------------------------------------------------\n\nexport interface IObjectFieldConfig extends IFieldConfig {\n childBuilders: Record<string, IFieldBuilder>;\n isList: boolean;\n listSchema?: z.ZodTypeAny;\n templates?: ITemplateConfig[];\n /**\n * Inner layout declared on the field itself via `.layout()`. A `layout.object()`\n * node in the parent layout takes precedence over it.\n */\n layout?: LayoutNode[];\n}\n\nexport interface ITemplateBuilder {\n label(text: string): this;\n description(text: string): this;\n icon(icon: ITemplateIcon): this;\n fields(factory: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder>): this;\n layout(factory: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]): this;\n visible(predicate: (form: IFormModel) => boolean): this;\n}\n\nexport interface ITemplateConfig {\n id: string;\n label: string;\n description?: string;\n icon?: ITemplateIcon;\n childBuilders: Record<string, IFieldBuilder>;\n layout?: LayoutNode[];\n visible?: (form: IFormModel) => boolean;\n}\n\nexport interface IObjectField extends ITypedField<Record<string, unknown> | null> {\n readonly isList: boolean;\n readonly children: Map<string, IField>;\n readonly items: IListItemField[];\n readonly isTemplated: boolean;\n readonly activeTemplateId: string | null;\n readonly availableTemplates: ITemplateVM[];\n /**\n * Add, replace, or remove children on this object field at runtime.\n * Mirrors `form.fields()` but scoped to this object's children. Existing\n * keys are replaced; new keys are appended; passing `undefined` removes.\n * Throws on templated objects — each template owns its own fields.\n */\n fields(\n factory: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder | undefined>\n ): void;\n /**\n * Register an inner layout used by the field's VM (`field.layout` for\n * single objects, `item.layout` for list items).\n *\n * Pass `LayoutNode[]` for non-templated objects (the layout applies to the\n * single object or every list item). Pass `Record<templateId, LayoutNode[]>`\n * for templated objects (each entry applies when that template is active\n * or for each list item with that template). Templates without an entry\n * fall back to default one-row-per-visible-child.\n */\n setInnerLayout(layout: LayoutNode[] | Record<string, LayoutNode[]>): void;\n /**\n * Append a new list item.\n * - Non-templated list: `addItem(data?)` — data hydrates the new item.\n * - Templated list: `addItem(templateId, data?)` — templateId picks the variant.\n */\n addItem(\n templateIdOrData?: string | Record<string, unknown>,\n data?: Record<string, unknown>\n ): void;\n removeItem(index: number): void;\n moveItem(fromIndex: number, toIndex: number): void;\n /** Duplicate a list item (including its `_templateId`) and insert after the source. */\n duplicateItem(index: number): void;\n setTemplate(templateId: string): void;\n /**\n * Runtime template management. Available on every object field but throws\n * when called on a non-templated field (`isTemplated === false`).\n */\n readonly templates: IObjectFieldTemplates;\n getInnerLayout(): LayoutNode[] | null;\n getData(): Record<string, unknown> | Record<string, unknown>[];\n}\n\nexport interface IObjectFieldTemplates {\n add(id: string, configure: (t: ITemplateBuilder) => void): void;\n remove(templateId: string): void;\n}\n\nexport interface IListItemField {\n readonly key: string;\n readonly children: Map<string, IField>;\n readonly templateId?: string;\n getData(): Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Callback types\n// ---------------------------------------------------------------------------\n\nexport type BeforeChangeCallback = (value: unknown, params: IFieldCallbackParams) => unknown;\nexport type AfterChangeCallback = (value: unknown, params: IFieldCallbackParams) => void;\nexport type AfterSetValueCallback = (value: unknown, params: IFieldCallbackParams) => void;\nexport type OnBlurCallback = (value: unknown, params: IFieldCallbackParams) => void;\nexport type CloneValueCallback = (value: unknown) => unknown;\n\n// ---------------------------------------------------------------------------\n// Layout types\n// ---------------------------------------------------------------------------\n\nexport type LayoutNode =\n | IRowNode\n | ISeparatorNode\n | IAlertNode\n | ITabsNode\n | IElementNode\n | IObjectNode;\n\nexport interface IRowNode {\n type: \"row\";\n fieldIds: string[];\n position?: LayoutPosition;\n}\n\n/** @deprecated Use IRowBuilder instead */\nexport type IRowNodeHandle = IRowBuilder;\n\nexport interface ISeparatorNode {\n type: \"separator\";\n title?: string;\n description?: string;\n rules?: IRule[];\n}\n\nexport interface ITabDefinition {\n id: string;\n label: string;\n description?: string;\n icon?: Icon;\n layout: LayoutNode[];\n rules?: IRule[];\n}\n\n/**\n * User-facing tab spec accepted by `layout.tabs(...)`. The layout is supplied\n * as a callback receiving the layout builder, mirroring `layout.object(...)`.\n * Resolved to `ITabDefinition` (with `layout: LayoutNode[]`) at build time.\n */\nexport interface ITabDefinitionInput {\n id: string;\n label: string;\n description?: string;\n icon?: Icon;\n layout: (layout: ILayoutBuilder) => ILayoutNodeBuilder[];\n rules?: IRule[];\n}\n\nexport interface ITabsNode {\n type: \"tabs\";\n id?: string;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n tabs: ITabDefinition[];\n rules?: IRule[];\n}\n\nexport interface IAlertNode {\n type: \"alert\";\n message?: string;\n alertType?: \"info\" | \"success\" | \"warning\" | \"danger\";\n rules?: IRule[];\n}\n\nexport interface IElementNode {\n type: \"element\";\n id?: string;\n renderer: string;\n props?: Record<string, unknown>;\n}\n\n/**\n * Layout node that references an object field and registers an inner layout\n * on it. Resolved as a single-field row in the outer layout — the inner\n * layout is exposed on the field's VM (`field.layout` for single objects,\n * `item.layout` for list items).\n *\n * - For non-templated objects, `inner` is `LayoutNode[]` (one layout, applied\n * to the single object or every list item).\n * - For templated objects, `inner` is `Record<templateId, LayoutNode[]>` —\n * each entry is the layout used when that template is active (or for each\n * list item with that template).\n */\nexport interface IObjectNode {\n type: \"object\";\n fieldName: string;\n inner: LayoutNode[] | Record<string, LayoutNode[]>;\n}\n\n// ---------------------------------------------------------------------------\n// Layout node builders\n// ---------------------------------------------------------------------------\n\nexport interface ILayoutNodeBuilder {\n build(): LayoutNode;\n}\n\nexport interface IRowBuilder extends ILayoutNodeBuilder {\n before(target: string): IRowBuilder;\n after(target: string): IRowBuilder;\n build(): IRowNode;\n}\n\nexport interface ISeparatorBuilder extends ILayoutNodeBuilder {\n title(text: string): this;\n description(text: string): this;\n rules(rules: IRule[]): this;\n build(): ISeparatorNode;\n}\n\nexport interface IAlertBuilder extends ILayoutNodeBuilder {\n message(text: string): this;\n alertType(type: \"info\" | \"success\" | \"warning\" | \"danger\"): this;\n rules(rules: IRule[]): this;\n build(): IAlertNode;\n}\n\nexport interface ITabBuilder {\n label(text: string): this;\n description(text: string): this;\n icon(icon: Icon): this;\n layout(factory: (l: ILayoutBuilder) => ILayoutNodeBuilder[]): this;\n rules(rules: IRule[]): this;\n}\n\nexport interface ITabsBuilder extends ILayoutNodeBuilder {\n renderer(name: string, settings?: Record<string, unknown>): this;\n tab(id: string, configure: (tab: ITabBuilder) => void): this;\n before(target: string): this;\n after(target: string): this;\n rules(rules: IRule[]): this;\n build(): ITabsNode;\n}\n\nexport interface IElementBuilder extends ILayoutNodeBuilder {\n build(): IElementNode;\n}\n\nexport interface IObjectBuilder extends ILayoutNodeBuilder {\n build(): IObjectNode;\n}\n\n// ---------------------------------------------------------------------------\n// Layout VM types\n// ---------------------------------------------------------------------------\n\nexport type LayoutNodeVM =\n | IRowNodeVM\n | ISeparatorNodeVM\n | IAlertNodeVM\n | ITabsNodeVM\n | IElementNodeVM;\n\nexport interface IRowNodeVM {\n type: \"row\";\n fields: IFieldVM[];\n}\n\nexport interface ISeparatorNodeVM {\n type: \"separator\";\n title?: string;\n description?: string;\n}\n\nexport interface IAlertNodeVM {\n type: \"alert\";\n message?: string;\n alertType: \"info\" | \"success\" | \"warning\" | \"danger\";\n}\n\nexport interface ITabDefinitionVM {\n id: string;\n label: string;\n description?: string;\n icon?: Icon;\n hasErrors: boolean;\n disabled: boolean;\n layout: LayoutNodeVM[];\n}\n\nexport interface ITabsNodeVM {\n type: \"tabs\";\n id?: string;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n tabs: ITabDefinitionVM[];\n disabled: boolean;\n activeTabId: string;\n setActiveTab: (id: string) => void;\n}\n\nexport interface IElementNodeVM {\n type: \"element\";\n renderer: string;\n props?: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Layout modifier types\n// ---------------------------------------------------------------------------\n\nexport type LayoutPosition =\n | { type: \"before\"; target: string }\n | { type: \"after\"; target: string }\n | { type: \"replace\"; target: string };\n\nexport interface IPositionedLayoutNode {\n node: LayoutNode;\n position?: LayoutPosition;\n}\n\n/**\n * Chainable handle returned by modifier layout.row().\n * Can be used as-is (appended) or positioned via .before()/.after()/.replace().\n */\nexport interface ILayoutNodeHandle extends IPositionedLayoutNode {\n before(target: string): IPositionedLayoutNode;\n after(target: string): IPositionedLayoutNode;\n replace(target: string): IPositionedLayoutNode;\n}\n\n// ---------------------------------------------------------------------------\n// Named layout node access types\n// ---------------------------------------------------------------------------\n\nexport interface LayoutNodeHandleMap {\n tabs: ITabsBuilder;\n element: IElementNode;\n object: IObjectNode;\n}\n\nexport interface ILayoutNodeAccessHandle {\n as<T extends keyof LayoutNodeHandleMap>(type: T): LayoutNodeHandleMap[T];\n}\n\n/** @deprecated Use ITabsBuilder instead */\nexport type ITabsHandle = ITabsBuilder;\n\n/** @deprecated Use ITabBuilder instead */\nexport type ITabHandle = ITabBuilder;\n\n// ---------------------------------------------------------------------------\n// Modifier types\n// ---------------------------------------------------------------------------\n\nexport interface IFormModifier {\n modify(form: IFormModel): void;\n}\n\nexport interface ILayoutModifier {\n row(...fieldIds: string[]): ILayoutNodeHandle;\n separator(): ILayoutNodeHandle;\n alert(): ILayoutNodeHandle;\n tabs(config: {\n id?: string;\n renderer?: string;\n tabs: ITabDefinitionInput[];\n rules?: IRule[];\n }): ILayoutNodeHandle;\n element(renderer: string, props?: Record<string, unknown>): ILayoutNodeHandle;\n object(\n fieldName: string,\n layout: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]\n ): ILayoutNodeHandle;\n object(\n fieldName: string,\n templateLayouts: Record<string, (layout: ILayoutBuilder) => ILayoutNodeBuilder[]>\n ): ILayoutNodeHandle;\n remove(target: string): void;\n}\n\n// ---------------------------------------------------------------------------\n// Form types\n// ---------------------------------------------------------------------------\n\nexport interface IFormError {\n path: string;\n label?: string;\n breadcrumb?: string[];\n message: string;\n}\n\nexport interface IFormVM {\n layout: LayoutNodeVM[];\n errors: IFormError[];\n hasErrors: boolean;\n isDirty: boolean;\n isValid: boolean | null;\n submitCount: number;\n focusField(path: string): void;\n getData(): Record<string, unknown>;\n setData(data: Record<string, unknown>, options?: { dirty?: boolean }): void;\n}\n\n/**\n * Imperative form-level rule. Receives the live form and may return a flat\n * list of errors (sync or async). Errors are merged into `form.errors` and\n * surfaced on per-field validation when their `path` matches a known field.\n */\nexport type FormRuleFn = (\n form: IFormModel\n) => IFormError[] | undefined | void | Promise<IFormError[] | undefined | void>;\n\n/**\n * A form-level rule. Either a Zod schema (validated against `form.getData()`)\n * or an imperative function returning an error list.\n */\nexport type FormRule = z.ZodTypeAny | FormRuleFn;\n\nexport interface IFormModel<T = Record<string, any>> {\n field(name: string): IField;\n fields(\n factory: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder | undefined>\n ): void;\n layout(factory: (layout: ILayoutModifier) => (LayoutNode | IPositionedLayoutNode)[]): void;\n layout(nodeId: string): ILayoutNodeAccessHandle;\n /**\n * Replace the entire layout. Re-registers per-field inner layouts and\n * propagates ancestor rules. Use `layout()` (modifier form) for additive\n * changes.\n */\n setLayout(factory: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]): void;\n /**\n * Append a form-level validation rule. Runs after per-field validation.\n * Accepts a Zod schema (validated against `getData()`) or an imperative\n * function returning a list of errors.\n */\n addRule(rule: FormRule): void;\n getData(): T;\n setData(data: T, options?: { dirty?: boolean }): void;\n reset(): void;\n validate(): Promise<boolean>;\n /**\n * Assign errors from outside the form, e.g. a rejected save. Errors whose `path`\n * resolves to a visible field become that field's validation error; the rest are\n * form-level. The form is marked as submitted so `FormErrors` renders them. They are\n * cleared by the next `validate()`, `setData()` or `reset()`.\n */\n setErrors(errors: IFormError[]): void;\n submit<T = Record<string, unknown>>(options?: { skipValidation?: boolean }): Promise<T | false>;\n evaluateRules(rules: IRule[] | undefined): { visible: boolean; disabled: boolean };\n focusField(name: string): void;\n readonly isDirty: boolean;\n readonly isValid: boolean | null;\n readonly submitted: boolean;\n readonly submitCount: number;\n readonly errors: IFormError[];\n readonly vm: IFormVM;\n getFieldBuilders(predicate?: (builder: IFieldBuilder) => boolean): IFieldBuilder[];\n traverse(callback: (builder: IFieldBuilder) => void): void;\n resolveChildLayout(layout: LayoutNode[], children: Map<string, IField>): LayoutNodeVM[];\n readonly registry: IFieldBuilderRegistry;\n}\n\n// ---------------------------------------------------------------------------\n// FormModel namespace — groups all public types under one import\n// ---------------------------------------------------------------------------\n\nexport namespace FormModel {\n export type FieldConfig = IFieldConfig;\n export type ValueOption = IValueOption;\n export type FieldValidation = IFieldValidation;\n export type FieldVM = IFieldVM;\n export type Field = IField;\n export type ObjectField = IObjectField;\n export type ObjectFieldConfig = IObjectFieldConfig;\n export type BeforeChange = BeforeChangeCallback;\n export type AfterChange = AfterChangeCallback;\n export type AfterSetValue = AfterSetValueCallback;\n export type OnBlur = OnBlurCallback;\n export type CloneValue = CloneValueCallback;\n export type LayoutNodeBuilder = ILayoutNodeBuilder;\n export type RowBuilder = IRowBuilder;\n export type SeparatorBuilder = ISeparatorBuilder;\n export type AlertBuilder = IAlertBuilder;\n export type AlertNode = IAlertNode;\n export type AlertNodeVM = IAlertNodeVM;\n export type TabBuilder = ITabBuilder;\n export type TabsBuilder = ITabsBuilder;\n export type ElementBuilder = IElementBuilder;\n export type ObjectBuilder = IObjectBuilder;\n export type RowNode = IRowNode;\n /** @deprecated Use RowBuilder instead */\n export type RowNodeHandle = IRowNodeHandle;\n export type RowNodeVM = IRowNodeVM;\n export type SeparatorNode = ISeparatorNode;\n export type SeparatorNodeVM = ISeparatorNodeVM;\n export type TabsNode = ITabsNode;\n export type TabDefinition = ITabDefinition;\n export type TabDefinitionInput = ITabDefinitionInput;\n export type TabsNodeVM = ITabsNodeVM;\n export type TabDefinitionVM = ITabDefinitionVM;\n export type TabIcon = Icon;\n export type ElementNode = IElementNode;\n export type ElementNodeVM = IElementNodeVM;\n export type ObjectNode = IObjectNode;\n export type ObjectFieldVM = IObjectFieldVM;\n export type ObjectFieldItemVM = IObjectFieldItemVM;\n export type TemplateBuilder = ITemplateBuilder;\n export type TemplateConfig = ITemplateConfig;\n export type TemplateIcon = ITemplateIcon;\n export type TemplateVM = ITemplateVM;\n export type ObjectFieldTemplatesAPI = IObjectFieldTemplates;\n export type FormError = IFormError;\n export type FormVM = IFormVM;\n export type Interface<T = Record<string, any>> = IFormModel<T>;\n export type Modifier = IFormModifier;\n export type LayoutModifier = ILayoutModifier;\n export type Rule = IRule;\n export type Action = RuleAction;\n export type RuleEvaluator = IRuleEvaluator;\n export type FormRuleFunction = FormRuleFn;\n export type FormRuleType = FormRule;\n export type CallbackParams = IFieldCallbackParams;\n export type RequiredWhen = (params: IFieldCallbackParams) => boolean;\n export type HiddenWhen = HiddenWhenCallback;\n export type DisabledWhen = DisabledWhenCallback;\n export type Computed = ComputedFieldCallback;\n}\n\n// ---------------------------------------------------------------------------\n// FormModelFactory abstraction\n// ---------------------------------------------------------------------------\n\nexport interface IFormModelFactory {\n create<T = Record<string, any>>(config: IFormModelConfig): IFormModel<T>;\n}\n\nexport interface IFormModelConfig {\n fields: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder>;\n layout?: (layout: ILayoutBuilder) => ILayoutNodeBuilder[];\n validateOnSubmit?: boolean;\n ruleEvaluators?: IRuleEvaluator[];\n}\n\nexport interface ILayoutBuilder {\n row(...fieldIds: string[]): IRowBuilder;\n separator(): ISeparatorBuilder;\n alert(): IAlertBuilder;\n tabs(id?: string): ITabsBuilder;\n element(renderer: string, props?: Record<string, unknown>): IElementBuilder;\n /**\n * Reference an object field and register its inner layout.\n *\n * Non-templated: pass a single layout factory; the layout applies to the\n * single object or to every list item. Templated: pass a map of factories\n * keyed by template id; each entry applies when that template is active\n * (or for each list item with that template). Templates without an entry\n * fall back to default one-row-per-visible-child.\n */\n object(\n fieldName: string,\n layout: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]\n ): IObjectBuilder;\n object(\n fieldName: string,\n templateLayouts: Record<string, (layout: ILayoutBuilder) => ILayoutNodeBuilder[]>\n ): IObjectBuilder;\n}\n\nexport interface IFieldBuilder<\n TType extends string = string,\n TOptions extends boolean = false,\n TValue = unknown\n> {\n readonly __valueType?: TValue;\n label(text: string): this;\n help(text: string): this;\n description(text: string): this;\n note(text: string): this;\n placeholder(text: string): this;\n schema(zodSchema: z.ZodTypeAny): this;\n defaultValue(value: unknown): this;\n renderer<TName extends FieldRendererName<TType, TOptions>>(\n name: TName,\n ...args: undefined extends FieldRendererSettings<TName>\n ? [settings?: FieldRendererSettings<TName>]\n : FieldRendererSettings<TName> extends undefined\n ? []\n : [settings: FieldRendererSettings<TName>]\n ): this;\n hidden(): this;\n hiddenWhen(fn: HiddenWhenCallback): this;\n disabledWhen(fn: DisabledWhenCallback): this;\n required(message?: string): this;\n /**\n * Conditional required check. Multiple `requiredWhen()` calls chain — the\n * first one to return `true` for the current form state makes the field\n * required. Built-in `.required()` (if set) is evaluated alongside.\n */\n requiredWhen(fn: (params: IFieldCallbackParams) => boolean, message?: string): this;\n list(): this;\n disabled(value?: boolean): this;\n rules(rules: IRule[]): this;\n beforeChange(fn: BeforeChangeCallback): this;\n afterChange(fn: AfterChangeCallback): this;\n afterSetValue(fn: AfterSetValueCallback): this;\n onBlur(fn: OnBlurCallback): this;\n cloneValue(fn: CloneValueCallback): this;\n getName(): string;\n getType(): string;\n getTags(): string[];\n tags(tags: string[]): this;\n /**\n * Mark this field as a derived value computed from `fn(form)`. The field\n * stays editable; user edits are accepted but the computed value continues\n * to flow whenever a dependency changes. To make the user \"win\", use\n * `computedUntilDirty()` instead.\n */\n computed(fn: ComputedFieldCallback): this;\n /**\n * Same as `computed`, but the field switches to manual mode the first time\n * its value is changed via the UI. After that, `fn(form)` no longer\n * overrides user input.\n */\n computedUntilDirty(fn: ComputedFieldCallback): this;\n build(name: string): IFieldConfig;\n}\n\nexport interface IOptionsFieldBuilder<TType extends string, TValue = unknown> extends IFieldBuilder<\n TType,\n false,\n TValue\n> {\n options(\n opts:\n | IValueOption<OptionValueType<TType>>[]\n | ((params: IFieldCallbackParams) => IValueOption<OptionValueType<TType>>[])\n ): IFieldBuilder<TType, true, TValue>;\n}\n\nexport interface IObjectFieldBuilder extends IFieldBuilder<\n \"object\",\n false,\n Record<string, unknown> | null\n> {\n fields(fn: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder>): this;\n list(): this;\n listSchema(schema: z.ZodTypeAny): this;\n template(id: string, configure: (t: ITemplateBuilder) => void): this;\n /**\n * Lay out the object's children: rows of child field names, plus separators, alerts\n * and tabs. Applies to the single object and to every list item. Templated objects\n * declare their layouts per template instead.\n */\n layout(factory: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]): this;\n}\n\nexport interface IFieldBuilderRegistry {}\n\n// ---------------------------------------------------------------------------\n// Field type plugin system\n// ---------------------------------------------------------------------------\n\nexport interface IFieldTypeFactory {\n readonly type: string;\n create(registry: IFieldBuilderRegistry): IFieldBuilder;\n}\n\nexport const FieldType = createAbstraction<IFieldTypeFactory>(\"FormModel/FieldType\");\n\nexport namespace FieldType {\n export type Interface = IFieldTypeFactory;\n export type FieldBuilder = IFieldBuilder;\n export type FieldBuilderRegistry = IFieldBuilderRegistry;\n}\n\nexport const FieldBuilderRegistry = createAbstraction<IFieldBuilderRegistry>(\n \"FormModel/FieldBuilderRegistry\"\n);\n\nexport namespace FieldBuilderRegistry {\n export type Interface = IFieldBuilderRegistry;\n}\n\nexport const FormModelFactory = createAbstraction<IFormModelFactory>(\"FormModelFactory\");\n\nexport namespace FormModelFactory {\n export type Interface = IFormModelFactory;\n export type Config = IFormModelConfig;\n export type LayoutBuilder = ILayoutBuilder;\n export type FieldBuilder = IFieldBuilder;\n export type OptionsFieldBuilder<TType extends string> = IOptionsFieldBuilder<TType>;\n export type ObjectFieldBuilder = IObjectFieldBuilder;\n export type FieldBuilderRegistry = IFieldBuilderRegistry;\n}\n\nexport const RuleEvaluator = createAbstraction<IRuleEvaluator>(\"FormModelRuleEvaluator\");\n\nexport namespace RuleEvaluator {\n export type Interface = IRuleEvaluator;\n export type Rule = IRule;\n export type Action = RuleAction;\n}\n"],"names":["FieldType","createAbstraction","FieldBuilderRegistry","FormModelFactory","RuleEvaluator"],"mappings":";AA6+BO,MAAMA,YAAYC,kBAAqC;AAQvD,MAAMC,uBAAuBD,kBAChC;AAOG,MAAME,mBAAmBF,kBAAqC;AAY9D,MAAMG,gBAAgBH,kBAAkC"}
|
|
1
|
+
{"version":3,"file":"features/formModel/abstractions.js","sources":["../../../src/features/formModel/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { z } from \"zod\";\nimport type { Icon } from \"~/components/IconPicker/types.js\";\n\n// ---------------------------------------------------------------------------\n// Renderer registry — augmented by each renderer via declare module\n// ---------------------------------------------------------------------------\n\nexport interface IFieldRendererRegistry {}\n\nexport type FieldRendererName<\n TType extends string = string,\n TOptions extends boolean = boolean\n> = string extends TType\n ? keyof IFieldRendererRegistry & string\n : {\n [K in keyof IFieldRendererRegistry]: TType extends IFieldRendererRegistry[K][\"fieldType\"]\n ? boolean extends TOptions\n ? K\n : TOptions extends true\n ? IFieldRendererRegistry[K] extends { options: true }\n ? K\n : never\n : IFieldRendererRegistry[K] extends { options: true }\n ? never\n : K\n : never;\n }[keyof IFieldRendererRegistry] &\n string;\n\nexport type FieldRendererSettings<TName extends string> = TName extends keyof IFieldRendererRegistry\n ? IFieldRendererRegistry[TName][\"settings\"]\n : Record<string, unknown> | undefined;\n\n// ---------------------------------------------------------------------------\n// Field types\n// ---------------------------------------------------------------------------\n\nexport interface IFieldConfig {\n name: string;\n type: string;\n label?: string;\n help?: string;\n description?: string;\n note?: string;\n placeholder?: string;\n defaultValue?: unknown;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n isList?: boolean;\n hidden: boolean;\n required: boolean;\n requiredMessage?: string;\n disabled: boolean;\n schema?: z.ZodTypeAny;\n options?: IValueOption[] | ((params: IFieldCallbackParams) => IValueOption[]);\n normalizeValue?: (value: unknown) => unknown;\n beforeChangeCallbacks?: BeforeChangeCallback[];\n afterChangeCallbacks?: AfterChangeCallback[];\n afterSetValueCallbacks?: AfterSetValueCallback[];\n onBlurCallbacks?: OnBlurCallback[];\n requiredWhenCallbacks?: RequiredWhenCallback[];\n hiddenWhenCallbacks?: HiddenWhenCallback[];\n disabledWhenCallbacks?: DisabledWhenCallback[];\n computed?: ComputedFieldCallback;\n computedUntilDirty?: ComputedFieldCallback;\n tags?: string[];\n cloneValue?: CloneValueCallback;\n context?: FieldContextCallback;\n rules?: IRule[];\n}\n\nexport interface IFieldScope {\n field(name: string): IField;\n parent(): IFieldScope;\n}\n\nexport interface IFieldNavigator {\n parent(): IFieldScope;\n}\n\nexport interface IFieldCallbackParams {\n field: IFieldNavigator;\n form: IFormModel;\n}\n\nexport interface IRequiredWhenCallbackConfig {\n fn: (params: IFieldCallbackParams) => boolean;\n message?: string;\n}\n\nexport type RequiredWhenCallback = IRequiredWhenCallbackConfig;\n\nexport type HiddenWhenCallback = (params: IFieldCallbackParams) => boolean;\n\nexport type DisabledWhenCallback = (params: IFieldCallbackParams) => boolean;\n\nexport type ComputedFieldCallback = (params: IFieldCallbackParams) => unknown;\n\nexport type FieldContextCallback = (params: IFieldCallbackParams) => Record<string, unknown>;\n\n// ---------------------------------------------------------------------------\n// Rules system\n// ---------------------------------------------------------------------------\n\nexport type RuleAction = \"hide\" | \"disable\";\n\nexport type RuleOperator =\n | \"==\"\n | \"eq\"\n | \"!=\"\n | \"neq\"\n | \">\"\n | \"gt\"\n | \"<\"\n | \"lt\"\n | \">=\"\n | \"gte\"\n | \"<=\"\n | \"lte\"\n | \"isEmpty\"\n | \"isNotEmpty\"\n | \"isTruthy\"\n | \"isFalsy\"\n | \"matches\"\n | \"contains\"\n | \"notContains\"\n | \"startsWith\"\n | \"notStartsWith\"\n | \"endsWith\"\n | \"notEndsWith\";\n\nexport interface IRule {\n type: string;\n target: string;\n operator: RuleOperator | (string & {});\n value: string | number | boolean | null;\n action: RuleAction;\n}\n\nexport interface IRuleEvaluator {\n canEvaluate(rule: IRule): boolean;\n evaluate(rule: IRule, form: IFormModel): boolean;\n}\n\nexport interface IValueOption<V extends string | number = string | number> {\n label: string;\n value: V;\n disabled?: boolean;\n}\n\nexport type OptionValueType<TType extends string> = TType extends \"number\" ? number : string;\n\nexport interface IFieldValidation {\n isValid: boolean | null;\n message?: string;\n}\n\nexport interface IFieldVM {\n name: string;\n /** Full dotted path of the field within the form (e.g. \"author.address.street\"). */\n qualifiedName: string;\n type: string;\n label?: string;\n help?: string;\n description?: string;\n note?: string;\n placeholder?: string;\n value: unknown;\n validation: IFieldValidation;\n validating: boolean;\n required: boolean;\n visible: boolean;\n disabled: boolean;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n isList?: boolean;\n options?: IValueOption[];\n onChange: (value: unknown) => void;\n onBlur: () => void;\n addItem: (value?: unknown) => void;\n removeItem: (index: number) => void;\n focusRequested: boolean;\n clearFocusRequest: () => void;\n context: Record<string, unknown>;\n}\n\nexport interface IObjectFieldVM extends IFieldVM {\n type: \"object\";\n isList: boolean;\n /** Child field VMs for non-list object fields. */\n fields: IFieldVM[];\n /**\n * Resolved layout for non-list object fields. For templated objects, resolves\n * against the active template's per-template layout (if registered via\n * `layout.object()`), otherwise defaults to one row per visible child.\n * For list-mode fields, see `items[].layout`.\n */\n layout: LayoutNodeVM[];\n /** Items for list-mode object fields. */\n items: IObjectFieldItemVM[];\n /** Append a new item. Templated lists require a template id. */\n addItem: (value?: unknown) => void;\n moveItem: (fromIndex: number, toIndex: number) => void;\n /** Duplicate a list item (including its `_templateId` when templated) and insert it after the source. */\n duplicateItem: (index: number) => void;\n /** True when the object has templates defined. */\n isTemplated: boolean;\n /** Templates visible in the picker (filtered by each template's reactive `visible`). */\n availableTemplates: ITemplateVM[];\n /** Currently active template id (single-object mode), or null if no template picked. */\n activeTemplateId: string | null;\n /** Switch to a different template. Discards values not present in the new template. */\n setTemplate: (templateId: string) => void;\n /** Returns a cloned copy of the current single-value data with cloneValue transforms applied. */\n getClonedData: () => Record<string, unknown>;\n}\n\nexport interface IObjectFieldItemVM {\n key: string;\n fields: IFieldVM[];\n /**\n * Resolved layout for this item. For templated lists, resolves against the\n * item's template-specific layout (if registered via `layout.object()`),\n * otherwise defaults to one row per visible child.\n */\n layout: LayoutNodeVM[];\n remove: () => void;\n moveUp: () => void;\n moveDown: () => void;\n duplicate: () => void;\n getClonedData: () => Record<string, unknown>;\n /** The template id of this item, if the parent list is templated. */\n templateId?: string;\n}\n\n/**\n * VM exposed for each available template in the picker.\n */\nexport interface ITemplateIcon {\n type: string;\n name: string;\n}\n\nexport interface ITemplateVM {\n id: string;\n label: string;\n description?: string;\n icon?: ITemplateIcon;\n}\n\nexport interface IField {\n readonly name: string;\n readonly type: string;\n readonly visible: boolean;\n readonly disabled: boolean;\n readonly vm: IFieldVM;\n readonly config: IFieldConfig;\n getValue<T = unknown>(): T;\n setValue(value: unknown): void;\n setValueSilent(value: unknown): void;\n setDisabled(value: boolean): void;\n setVisible(value: boolean): void;\n /**\n * `parentPath` is the parent's qualified name. `scopePath` returns a path that\n * `form.field()` resolves to the parent itself; it differs from `parentPath` for\n * list item children, where it includes the item index (`blocks.2`). `$.` rule\n * targets and `field.parent()` resolve against it. Defaults to `parentPath`.\n */\n setForm(form: IFormModel, parentPath?: string, scopePath?: () => string): void;\n setAncestorRules(rules: IRule[]): void;\n setValidation(validation: IFieldValidation): void;\n resetValidation(): void;\n validate(options?: { force?: boolean }): Promise<boolean>;\n remove(): void;\n addBeforeChange(cb: BeforeChangeCallback): void;\n addAfterChange(cb: AfterChangeCallback): void;\n addAfterSetValue(cb: AfterSetValueCallback): void;\n addOnBlur(cb: OnBlurCallback): void;\n /**\n * Append a conditional required check. Multiple callbacks chain additively;\n * the first one returning `true` makes the field required for the current\n * form state. The built-in `.required()` flag (if set) always counts as a\n * truthy check and cannot be overridden.\n */\n addRequiredWhen(fn: (params: IFieldCallbackParams) => boolean, message?: string): void;\n /**\n * Mark this field as a derived value computed from `fn(form)`. The field\n * stays editable (no auto-disable) and is excluded from `isDirty` while\n * still tracking the computed value. Validation continues to apply.\n */\n setComputed(fn: ComputedFieldCallback): void;\n /**\n * Same as `setComputed`, but the field switches to manual mode the first\n * time the user edits its value. After that, the computed callback no\n * longer overrides user input.\n */\n setComputedUntilDirty(fn: ComputedFieldCallback): void;\n blur(): void;\n as<T extends keyof FieldTypeMap>(type: T): FieldTypeMap[T];\n readonly qualifiedName: string;\n focus(): void;\n requestFocus(): void;\n clearFocusRequest(): void;\n}\n\n/**\n * Maps field type strings to their typed field interfaces.\n * Extended via module augmentation when new field types are registered.\n */\nexport interface ITypedField<V> extends IField {\n getValue<T = V>(): T;\n}\n\ntype InferFieldTypeMap = {\n [K in keyof IFieldBuilderRegistry]: ReturnType<\n IFieldBuilderRegistry[K]\n > extends IObjectFieldBuilder\n ? IObjectField\n : ReturnType<IFieldBuilderRegistry[K]> extends { readonly __valueType?: infer V }\n ? ITypedField<V>\n : IField;\n};\n\nexport type FieldTypeMap = { [K in keyof InferFieldTypeMap]: InferFieldTypeMap[K] };\n\nexport type FileValue = {\n id: string;\n name: string;\n size: number;\n mimeType: string;\n src: string;\n width: number | undefined;\n height: number | undefined;\n};\n\n// ---------------------------------------------------------------------------\n// Object / List field types\n// ---------------------------------------------------------------------------\n\nexport interface IObjectFieldConfig extends IFieldConfig {\n childBuilders: Record<string, IFieldBuilder>;\n isList: boolean;\n listSchema?: z.ZodTypeAny;\n templates?: ITemplateConfig[];\n /**\n * Inner layout declared on the field itself via `.layout()`. A `layout.object()`\n * node in the parent layout takes precedence over it.\n */\n layout?: LayoutNode[];\n}\n\nexport interface ITemplateBuilder {\n label(text: string): this;\n description(text: string): this;\n icon(icon: ITemplateIcon): this;\n fields(factory: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder>): this;\n layout(factory: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]): this;\n visible(predicate: (form: IFormModel) => boolean): this;\n}\n\nexport interface ITemplateConfig {\n id: string;\n label: string;\n description?: string;\n icon?: ITemplateIcon;\n childBuilders: Record<string, IFieldBuilder>;\n layout?: LayoutNode[];\n visible?: (form: IFormModel) => boolean;\n}\n\nexport interface IObjectField extends ITypedField<Record<string, unknown> | null> {\n readonly isList: boolean;\n readonly children: Map<string, IField>;\n readonly items: IListItemField[];\n readonly isTemplated: boolean;\n readonly activeTemplateId: string | null;\n readonly availableTemplates: ITemplateVM[];\n /**\n * Add, replace, or remove children on this object field at runtime.\n * Mirrors `form.fields()` but scoped to this object's children. Existing\n * keys are replaced; new keys are appended; passing `undefined` removes.\n * Throws on templated objects — each template owns its own fields.\n */\n fields(\n factory: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder | undefined>\n ): void;\n /**\n * Register an inner layout used by the field's VM (`field.layout` for\n * single objects, `item.layout` for list items).\n *\n * Pass `LayoutNode[]` for non-templated objects (the layout applies to the\n * single object or every list item). Pass `Record<templateId, LayoutNode[]>`\n * for templated objects (each entry applies when that template is active\n * or for each list item with that template). Templates without an entry\n * fall back to default one-row-per-visible-child.\n */\n setInnerLayout(layout: LayoutNode[] | Record<string, LayoutNode[]>): void;\n /**\n * Append a new list item.\n * - Non-templated list: `addItem(data?)` — data hydrates the new item.\n * - Templated list: `addItem(templateId, data?)` — templateId picks the variant.\n */\n addItem(\n templateIdOrData?: string | Record<string, unknown>,\n data?: Record<string, unknown>\n ): void;\n removeItem(index: number): void;\n moveItem(fromIndex: number, toIndex: number): void;\n /** Duplicate a list item (including its `_templateId`) and insert after the source. */\n duplicateItem(index: number): void;\n setTemplate(templateId: string): void;\n /**\n * Runtime template management. Available on every object field but throws\n * when called on a non-templated field (`isTemplated === false`).\n */\n readonly templates: IObjectFieldTemplates;\n getInnerLayout(): LayoutNode[] | null;\n getData(): Record<string, unknown> | Record<string, unknown>[];\n}\n\nexport interface IObjectFieldTemplates {\n add(id: string, configure: (t: ITemplateBuilder) => void): void;\n remove(templateId: string): void;\n}\n\nexport interface IListItemField {\n readonly key: string;\n readonly children: Map<string, IField>;\n readonly templateId?: string;\n getData(): Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Callback types\n// ---------------------------------------------------------------------------\n\nexport type BeforeChangeCallback = (value: unknown, params: IFieldCallbackParams) => unknown;\nexport type AfterChangeCallback = (value: unknown, params: IFieldCallbackParams) => void;\nexport type AfterSetValueCallback = (value: unknown, params: IFieldCallbackParams) => void;\nexport type OnBlurCallback = (value: unknown, params: IFieldCallbackParams) => void;\nexport type CloneValueCallback = (value: unknown) => unknown;\n\n// ---------------------------------------------------------------------------\n// Layout types\n// ---------------------------------------------------------------------------\n\nexport type LayoutNode =\n | IRowNode\n | ISeparatorNode\n | IAlertNode\n | ITabsNode\n | IElementNode\n | IObjectNode;\n\nexport interface IRowNode {\n type: \"row\";\n fieldIds: string[];\n position?: LayoutPosition;\n}\n\n/** @deprecated Use IRowBuilder instead */\nexport type IRowNodeHandle = IRowBuilder;\n\nexport interface ISeparatorNode {\n type: \"separator\";\n title?: string;\n description?: string;\n rules?: IRule[];\n}\n\nexport interface ITabDefinition {\n id: string;\n label: string;\n description?: string;\n icon?: Icon;\n layout: LayoutNode[];\n rules?: IRule[];\n}\n\n/**\n * User-facing tab spec accepted by `layout.tabs(...)`. The layout is supplied\n * as a callback receiving the layout builder, mirroring `layout.object(...)`.\n * Resolved to `ITabDefinition` (with `layout: LayoutNode[]`) at build time.\n */\nexport interface ITabDefinitionInput {\n id: string;\n label: string;\n description?: string;\n icon?: Icon;\n layout: (layout: ILayoutBuilder) => ILayoutNodeBuilder[];\n rules?: IRule[];\n}\n\nexport interface ITabsNode {\n type: \"tabs\";\n id?: string;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n tabs: ITabDefinition[];\n rules?: IRule[];\n}\n\nexport interface IAlertNode {\n type: \"alert\";\n message?: string;\n alertType?: \"info\" | \"success\" | \"warning\" | \"danger\";\n rules?: IRule[];\n}\n\nexport interface IElementNode {\n type: \"element\";\n id?: string;\n renderer: string;\n props?: Record<string, unknown>;\n}\n\n/**\n * Layout node that references an object field and registers an inner layout\n * on it. Resolved as a single-field row in the outer layout — the inner\n * layout is exposed on the field's VM (`field.layout` for single objects,\n * `item.layout` for list items).\n *\n * - For non-templated objects, `inner` is `LayoutNode[]` (one layout, applied\n * to the single object or every list item).\n * - For templated objects, `inner` is `Record<templateId, LayoutNode[]>` —\n * each entry is the layout used when that template is active (or for each\n * list item with that template).\n */\nexport interface IObjectNode {\n type: \"object\";\n fieldName: string;\n inner: LayoutNode[] | Record<string, LayoutNode[]>;\n}\n\n// ---------------------------------------------------------------------------\n// Layout node builders\n// ---------------------------------------------------------------------------\n\nexport interface ILayoutNodeBuilder {\n build(): LayoutNode;\n}\n\nexport interface IRowBuilder extends ILayoutNodeBuilder {\n before(target: string): IRowBuilder;\n after(target: string): IRowBuilder;\n build(): IRowNode;\n}\n\nexport interface ISeparatorBuilder extends ILayoutNodeBuilder {\n title(text: string): this;\n description(text: string): this;\n rules(rules: IRule[]): this;\n build(): ISeparatorNode;\n}\n\nexport interface IAlertBuilder extends ILayoutNodeBuilder {\n message(text: string): this;\n alertType(type: \"info\" | \"success\" | \"warning\" | \"danger\"): this;\n rules(rules: IRule[]): this;\n build(): IAlertNode;\n}\n\nexport interface ITabBuilder {\n label(text: string): this;\n description(text: string): this;\n icon(icon: Icon): this;\n layout(factory: (l: ILayoutBuilder) => ILayoutNodeBuilder[]): this;\n rules(rules: IRule[]): this;\n}\n\nexport interface ITabsBuilder extends ILayoutNodeBuilder {\n renderer(name: string, settings?: Record<string, unknown>): this;\n tab(id: string, configure: (tab: ITabBuilder) => void): this;\n before(target: string): this;\n after(target: string): this;\n rules(rules: IRule[]): this;\n build(): ITabsNode;\n}\n\nexport interface IElementBuilder extends ILayoutNodeBuilder {\n build(): IElementNode;\n}\n\nexport interface IObjectBuilder extends ILayoutNodeBuilder {\n build(): IObjectNode;\n}\n\n// ---------------------------------------------------------------------------\n// Layout VM types\n// ---------------------------------------------------------------------------\n\nexport type LayoutNodeVM =\n | IRowNodeVM\n | ISeparatorNodeVM\n | IAlertNodeVM\n | ITabsNodeVM\n | IElementNodeVM;\n\nexport interface IRowNodeVM {\n type: \"row\";\n fields: IFieldVM[];\n}\n\nexport interface ISeparatorNodeVM {\n type: \"separator\";\n title?: string;\n description?: string;\n}\n\nexport interface IAlertNodeVM {\n type: \"alert\";\n message?: string;\n alertType: \"info\" | \"success\" | \"warning\" | \"danger\";\n}\n\nexport interface ITabDefinitionVM {\n id: string;\n label: string;\n description?: string;\n icon?: Icon;\n hasErrors: boolean;\n disabled: boolean;\n layout: LayoutNodeVM[];\n}\n\nexport interface ITabsNodeVM {\n type: \"tabs\";\n id?: string;\n renderer?: string;\n rendererSettings?: Record<string, unknown>;\n tabs: ITabDefinitionVM[];\n disabled: boolean;\n activeTabId: string;\n setActiveTab: (id: string) => void;\n}\n\nexport interface IElementNodeVM {\n type: \"element\";\n renderer: string;\n props?: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Layout modifier types\n// ---------------------------------------------------------------------------\n\nexport type LayoutPosition =\n | { type: \"before\"; target: string }\n | { type: \"after\"; target: string }\n | { type: \"replace\"; target: string };\n\nexport interface IPositionedLayoutNode {\n node: LayoutNode;\n position?: LayoutPosition;\n}\n\n/**\n * Chainable handle returned by modifier layout.row().\n * Can be used as-is (appended) or positioned via .before()/.after()/.replace().\n */\nexport interface ILayoutNodeHandle extends IPositionedLayoutNode {\n before(target: string): IPositionedLayoutNode;\n after(target: string): IPositionedLayoutNode;\n replace(target: string): IPositionedLayoutNode;\n}\n\n// ---------------------------------------------------------------------------\n// Named layout node access types\n// ---------------------------------------------------------------------------\n\nexport interface LayoutNodeHandleMap {\n tabs: ITabsBuilder;\n element: IElementNode;\n object: IObjectNode;\n}\n\nexport interface ILayoutNodeAccessHandle {\n as<T extends keyof LayoutNodeHandleMap>(type: T): LayoutNodeHandleMap[T];\n}\n\n/** @deprecated Use ITabsBuilder instead */\nexport type ITabsHandle = ITabsBuilder;\n\n/** @deprecated Use ITabBuilder instead */\nexport type ITabHandle = ITabBuilder;\n\n// ---------------------------------------------------------------------------\n// Modifier types\n// ---------------------------------------------------------------------------\n\nexport interface IFormModifier {\n modify(form: IFormModel): void;\n}\n\nexport interface ILayoutModifier {\n row(...fieldIds: string[]): ILayoutNodeHandle;\n separator(): ILayoutNodeHandle;\n alert(): ILayoutNodeHandle;\n tabs(config: {\n id?: string;\n renderer?: string;\n tabs: ITabDefinitionInput[];\n rules?: IRule[];\n }): ILayoutNodeHandle;\n element(renderer: string, props?: Record<string, unknown>): ILayoutNodeHandle;\n object(\n fieldName: string,\n layout: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]\n ): ILayoutNodeHandle;\n object(\n fieldName: string,\n templateLayouts: Record<string, (layout: ILayoutBuilder) => ILayoutNodeBuilder[]>\n ): ILayoutNodeHandle;\n remove(target: string): void;\n}\n\n// ---------------------------------------------------------------------------\n// Form types\n// ---------------------------------------------------------------------------\n\nexport interface IFormError {\n path: string;\n label?: string;\n breadcrumb?: string[];\n message: string;\n}\n\nexport interface IFormVM {\n layout: LayoutNodeVM[];\n errors: IFormError[];\n hasErrors: boolean;\n isDirty: boolean;\n isValid: boolean | null;\n submitCount: number;\n focusField(path: string): void;\n getData(): Record<string, unknown>;\n setData(data: Record<string, unknown>, options?: { dirty?: boolean }): void;\n}\n\n/**\n * Imperative form-level rule. Receives the live form and may return a flat\n * list of errors (sync or async). Errors are merged into `form.errors` and\n * surfaced on per-field validation when their `path` matches a known field.\n */\nexport type FormRuleFn = (\n form: IFormModel\n) => IFormError[] | undefined | void | Promise<IFormError[] | undefined | void>;\n\n/**\n * A form-level rule. Either a Zod schema (validated against `form.getData()`)\n * or an imperative function returning an error list.\n */\nexport type FormRule = z.ZodTypeAny | FormRuleFn;\n\nexport interface IFormModel<T = Record<string, any>> {\n field(name: string): IField;\n fields(\n factory: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder | undefined>\n ): void;\n layout(factory: (layout: ILayoutModifier) => (LayoutNode | IPositionedLayoutNode)[]): void;\n layout(nodeId: string): ILayoutNodeAccessHandle;\n /**\n * Replace the entire layout. Re-registers per-field inner layouts and\n * propagates ancestor rules. Use `layout()` (modifier form) for additive\n * changes.\n */\n setLayout(factory: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]): void;\n /**\n * Append a form-level validation rule. Runs after per-field validation.\n * Accepts a Zod schema (validated against `getData()`) or an imperative\n * function returning a list of errors.\n */\n addRule(rule: FormRule): void;\n getData(): T;\n setData(data: T, options?: { dirty?: boolean }): void;\n reset(): void;\n validate(): Promise<boolean>;\n /**\n * Assign errors from outside the form, e.g. a rejected save. Errors whose `path`\n * resolves to a visible field become that field's validation error; the rest are\n * form-level. The form is marked as submitted so `FormErrors` renders them. They are\n * cleared by the next `validate()`, `setData()` or `reset()`.\n */\n setErrors(errors: IFormError[]): void;\n submit<T = Record<string, unknown>>(options?: { skipValidation?: boolean }): Promise<T | false>;\n evaluateRules(rules: IRule[] | undefined): { visible: boolean; disabled: boolean };\n focusField(name: string): void;\n readonly isDirty: boolean;\n readonly isValid: boolean | null;\n readonly submitted: boolean;\n readonly submitCount: number;\n readonly errors: IFormError[];\n readonly vm: IFormVM;\n getFieldBuilders(predicate?: (builder: IFieldBuilder) => boolean): IFieldBuilder[];\n traverse(callback: (builder: IFieldBuilder) => void): void;\n resolveChildLayout(layout: LayoutNode[], children: Map<string, IField>): LayoutNodeVM[];\n readonly registry: IFieldBuilderRegistry;\n}\n\n// ---------------------------------------------------------------------------\n// FormModel namespace — groups all public types under one import\n// ---------------------------------------------------------------------------\n\nexport namespace FormModel {\n export type FieldConfig = IFieldConfig;\n export type ValueOption = IValueOption;\n export type FieldValidation = IFieldValidation;\n export type FieldVM = IFieldVM;\n export type Field = IField;\n export type ObjectField = IObjectField;\n export type ObjectFieldConfig = IObjectFieldConfig;\n export type BeforeChange = BeforeChangeCallback;\n export type AfterChange = AfterChangeCallback;\n export type AfterSetValue = AfterSetValueCallback;\n export type OnBlur = OnBlurCallback;\n export type CloneValue = CloneValueCallback;\n export type LayoutNodeBuilder = ILayoutNodeBuilder;\n export type RowBuilder = IRowBuilder;\n export type SeparatorBuilder = ISeparatorBuilder;\n export type AlertBuilder = IAlertBuilder;\n export type AlertNode = IAlertNode;\n export type AlertNodeVM = IAlertNodeVM;\n export type TabBuilder = ITabBuilder;\n export type TabsBuilder = ITabsBuilder;\n export type ElementBuilder = IElementBuilder;\n export type ObjectBuilder = IObjectBuilder;\n export type RowNode = IRowNode;\n /** @deprecated Use RowBuilder instead */\n export type RowNodeHandle = IRowNodeHandle;\n export type RowNodeVM = IRowNodeVM;\n export type SeparatorNode = ISeparatorNode;\n export type SeparatorNodeVM = ISeparatorNodeVM;\n export type TabsNode = ITabsNode;\n export type TabDefinition = ITabDefinition;\n export type TabDefinitionInput = ITabDefinitionInput;\n export type TabsNodeVM = ITabsNodeVM;\n export type TabDefinitionVM = ITabDefinitionVM;\n export type TabIcon = Icon;\n export type ElementNode = IElementNode;\n export type ElementNodeVM = IElementNodeVM;\n export type ObjectNode = IObjectNode;\n export type ObjectFieldVM = IObjectFieldVM;\n export type ObjectFieldItemVM = IObjectFieldItemVM;\n export type TemplateBuilder = ITemplateBuilder;\n export type TemplateConfig = ITemplateConfig;\n export type TemplateIcon = ITemplateIcon;\n export type TemplateVM = ITemplateVM;\n export type ObjectFieldTemplatesAPI = IObjectFieldTemplates;\n export type FormError = IFormError;\n export type FormVM = IFormVM;\n export type Interface<T = Record<string, any>> = IFormModel<T>;\n export type Modifier = IFormModifier;\n export type LayoutModifier = ILayoutModifier;\n export type Rule = IRule;\n export type Action = RuleAction;\n export type RuleEvaluator = IRuleEvaluator;\n export type FormRuleFunction = FormRuleFn;\n export type FormRuleType = FormRule;\n export type CallbackParams = IFieldCallbackParams;\n export type RequiredWhen = (params: IFieldCallbackParams) => boolean;\n export type HiddenWhen = HiddenWhenCallback;\n export type DisabledWhen = DisabledWhenCallback;\n export type Computed = ComputedFieldCallback;\n}\n\n// ---------------------------------------------------------------------------\n// FormModelFactory abstraction\n// ---------------------------------------------------------------------------\n\nexport interface IFormModelFactory {\n create<T = Record<string, any>>(config: IFormModelConfig): IFormModel<T>;\n}\n\nexport interface IFormModelConfig {\n fields: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder>;\n layout?: (layout: ILayoutBuilder) => ILayoutNodeBuilder[];\n validateOnSubmit?: boolean;\n ruleEvaluators?: IRuleEvaluator[];\n}\n\nexport interface ILayoutBuilder {\n row(...fieldIds: string[]): IRowBuilder;\n separator(): ISeparatorBuilder;\n alert(): IAlertBuilder;\n tabs(id?: string): ITabsBuilder;\n element(renderer: string, props?: Record<string, unknown>): IElementBuilder;\n /**\n * Reference an object field and register its inner layout.\n *\n * Non-templated: pass a single layout factory; the layout applies to the\n * single object or to every list item. Templated: pass a map of factories\n * keyed by template id; each entry applies when that template is active\n * (or for each list item with that template). Templates without an entry\n * fall back to default one-row-per-visible-child.\n */\n object(\n fieldName: string,\n layout: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]\n ): IObjectBuilder;\n object(\n fieldName: string,\n templateLayouts: Record<string, (layout: ILayoutBuilder) => ILayoutNodeBuilder[]>\n ): IObjectBuilder;\n}\n\nexport interface IFieldBuilder<\n TType extends string = string,\n TOptions extends boolean = false,\n TValue = unknown\n> {\n readonly __valueType?: TValue;\n label(text: string): this;\n help(text: string): this;\n description(text: string): this;\n note(text: string): this;\n placeholder(text: string): this;\n schema(zodSchema: z.ZodTypeAny): this;\n defaultValue(value: unknown): this;\n renderer<TName extends FieldRendererName<TType, TOptions>>(\n name: TName,\n ...args: undefined extends FieldRendererSettings<TName>\n ? [settings?: FieldRendererSettings<TName>]\n : FieldRendererSettings<TName> extends undefined\n ? []\n : [settings: FieldRendererSettings<TName>]\n ): this;\n hidden(): this;\n hiddenWhen(fn: HiddenWhenCallback): this;\n disabledWhen(fn: DisabledWhenCallback): this;\n required(message?: string): this;\n /**\n * Conditional required check. Multiple `requiredWhen()` calls chain — the\n * first one to return `true` for the current form state makes the field\n * required. Built-in `.required()` (if set) is evaluated alongside.\n */\n requiredWhen(fn: (params: IFieldCallbackParams) => boolean, message?: string): this;\n list(): this;\n disabled(value?: boolean): this;\n rules(rules: IRule[]): this;\n beforeChange(fn: BeforeChangeCallback): this;\n afterChange(fn: AfterChangeCallback): this;\n afterSetValue(fn: AfterSetValueCallback): this;\n onBlur(fn: OnBlurCallback): this;\n cloneValue(fn: CloneValueCallback): this;\n getName(): string;\n getType(): string;\n getTags(): string[];\n tags(tags: string[]): this;\n /**\n * Mark this field as a derived value computed from `fn(form)`. The field\n * stays editable; user edits are accepted but the computed value continues\n * to flow whenever a dependency changes. To make the user \"win\", use\n * `computedUntilDirty()` instead.\n */\n computed(fn: ComputedFieldCallback): this;\n /**\n * Same as `computed`, but the field switches to manual mode the first time\n * its value is changed via the UI. After that, `fn(form)` no longer\n * overrides user input.\n */\n computedUntilDirty(fn: ComputedFieldCallback): this;\n build(name: string): IFieldConfig;\n}\n\nexport interface IOptionsFieldBuilder<TType extends string, TValue = unknown> extends IFieldBuilder<\n TType,\n false,\n TValue\n> {\n options(\n opts:\n | IValueOption<OptionValueType<TType>>[]\n | ((params: IFieldCallbackParams) => IValueOption<OptionValueType<TType>>[])\n ): IFieldBuilder<TType, true, TValue>;\n}\n\nexport interface IObjectFieldBuilder extends IFieldBuilder<\n \"object\",\n false,\n Record<string, unknown> | null\n> {\n fields(fn: (registry: IFieldBuilderRegistry) => Record<string, IFieldBuilder>): this;\n list(): this;\n listSchema(schema: z.ZodTypeAny): this;\n template(id: string, configure: (t: ITemplateBuilder) => void): this;\n /**\n * Lay out the object's children: rows of child field names, plus separators, alerts\n * and tabs. Applies to the single object and to every list item. Templated objects\n * declare their layouts per template instead.\n */\n layout(factory: (layout: ILayoutBuilder) => ILayoutNodeBuilder[]): this;\n}\n\nexport interface IFieldBuilderRegistry {}\n\n// ---------------------------------------------------------------------------\n// Field type plugin system\n// ---------------------------------------------------------------------------\n\nexport interface IFieldTypeFactory {\n readonly type: string;\n create(registry: IFieldBuilderRegistry): IFieldBuilder;\n}\n\nexport const FieldType = createAbstraction<IFieldTypeFactory>(\"FormModel/FieldType\");\n\nexport namespace FieldType {\n export type Interface = IFieldTypeFactory;\n export type FieldBuilder = IFieldBuilder;\n export type FieldBuilderRegistry = IFieldBuilderRegistry;\n}\n\n// ---------------------------------------------------------------------------\n// Field value formatting\n// ---------------------------------------------------------------------------\n\n/**\n * Turns a field's value into the text shown where the value is summarised rather than edited,\n * such as an accordion item's title. Register one for a field type whose raw value is not\n * readable, like a reference, which holds an entry ID rather than the entry's title.\n *\n * `format` is read inside an observer, so it may return `undefined` while it loads a value and\n * an observable value once it has it.\n */\nexport interface IFieldValueFormatter {\n readonly type: string;\n format(field: IFieldVM): string | undefined;\n}\n\nexport const FieldValueFormatter = createAbstraction<IFieldValueFormatter>(\n \"FormModel/FieldValueFormatter\"\n);\n\nexport namespace FieldValueFormatter {\n export type Interface = IFieldValueFormatter;\n}\n\nexport const FieldBuilderRegistry = createAbstraction<IFieldBuilderRegistry>(\n \"FormModel/FieldBuilderRegistry\"\n);\n\nexport namespace FieldBuilderRegistry {\n export type Interface = IFieldBuilderRegistry;\n}\n\nexport const FormModelFactory = createAbstraction<IFormModelFactory>(\"FormModelFactory\");\n\nexport namespace FormModelFactory {\n export type Interface = IFormModelFactory;\n export type Config = IFormModelConfig;\n export type LayoutBuilder = ILayoutBuilder;\n export type FieldBuilder = IFieldBuilder;\n export type OptionsFieldBuilder<TType extends string> = IOptionsFieldBuilder<TType>;\n export type ObjectFieldBuilder = IObjectFieldBuilder;\n export type FieldBuilderRegistry = IFieldBuilderRegistry;\n}\n\nexport const RuleEvaluator = createAbstraction<IRuleEvaluator>(\"FormModelRuleEvaluator\");\n\nexport namespace RuleEvaluator {\n export type Interface = IRuleEvaluator;\n export type Rule = IRule;\n export type Action = RuleAction;\n}\n"],"names":["FieldType","createAbstraction","FieldValueFormatter","FieldBuilderRegistry","FormModelFactory","RuleEvaluator"],"mappings":";AA6+BO,MAAMA,YAAYC,kBAAqC;AAyBvD,MAAMC,sBAAsBD,kBAC/B;AAOG,MAAME,uBAAuBF,kBAChC;AAOG,MAAMG,mBAAmBH,kBAAqC;AAY9D,MAAMI,gBAAgBJ,kBAAkC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { FormModelFeature } from "./feature.js";
|
|
2
2
|
import "./renderers.js";
|
|
3
|
-
export { FormModelFactory, RuleEvaluator, FieldType, FieldBuilderRegistry } from "./abstractions.js";
|
|
4
|
-
export type { FormModel, IFieldRendererRegistry, FieldRendererName, FieldRendererSettings, IFormModelFactory, IFormModelConfig, ILayoutBuilder, ILayoutNodeBuilder, IRowBuilder, ISeparatorBuilder, ITabBuilder, ITabsBuilder, IElementBuilder, IObjectBuilder, IFieldBuilder, IOptionsFieldBuilder, IObjectFieldBuilder, IFieldBuilderRegistry, IFormModel, IField, IObjectField, IObjectFieldConfig, IListItemField, IObjectFieldVM, IObjectFieldItemVM, ITemplateBuilder, ITemplateIcon, ITemplateConfig, ITemplateVM, IObjectFieldTemplates, FieldTypeMap, ITypedField, IFieldConfig, IFieldVM, IFieldValidation, IFormVM, IFormError, IValueOption, IRowNode, IRowNodeHandle, IRowNodeVM, ISeparatorNode, ISeparatorNodeVM, IAlertNode, IAlertNodeVM, ITabsNode, ITabDefinition, ITabsNodeVM, ITabDefinitionVM, IElementNode, IElementNodeVM, IObjectNode, ILayoutNodeAccessHandle, LayoutNodeHandleMap, ITabsHandle, ITabHandle, LayoutNode, LayoutNodeVM, LayoutPosition, IPositionedLayoutNode, ILayoutNodeHandle, ILayoutModifier, IFormModifier, IRule, IRuleEvaluator, RuleAction, BeforeChangeCallback, AfterChangeCallback, AfterSetValueCallback, OnBlurCallback, CloneValueCallback, IFieldTypeFactory, FileValue } from "./abstractions.js";
|
|
3
|
+
export { FormModelFactory, RuleEvaluator, FieldType, FieldValueFormatter, FieldBuilderRegistry } from "./abstractions.js";
|
|
4
|
+
export type { FormModel, IFieldRendererRegistry, FieldRendererName, FieldRendererSettings, IFormModelFactory, IFormModelConfig, ILayoutBuilder, ILayoutNodeBuilder, IRowBuilder, ISeparatorBuilder, ITabBuilder, ITabsBuilder, IElementBuilder, IObjectBuilder, IFieldBuilder, IOptionsFieldBuilder, IObjectFieldBuilder, IFieldBuilderRegistry, IFormModel, IField, IObjectField, IObjectFieldConfig, IListItemField, IObjectFieldVM, IObjectFieldItemVM, ITemplateBuilder, ITemplateIcon, ITemplateConfig, ITemplateVM, IObjectFieldTemplates, FieldTypeMap, ITypedField, IFieldConfig, IFieldVM, IFieldValueFormatter, IFieldValidation, IFormVM, IFormError, IValueOption, IRowNode, IRowNodeHandle, IRowNodeVM, ISeparatorNode, ISeparatorNodeVM, IAlertNode, IAlertNodeVM, ITabsNode, ITabDefinition, ITabsNodeVM, ITabDefinitionVM, IElementNode, IElementNodeVM, IObjectNode, ILayoutNodeAccessHandle, LayoutNodeHandleMap, ITabsHandle, ITabHandle, LayoutNode, LayoutNodeVM, LayoutPosition, IPositionedLayoutNode, ILayoutNodeHandle, ILayoutModifier, IFormModifier, IRule, IRuleEvaluator, RuleAction, BeforeChangeCallback, AfterChangeCallback, AfterSetValueCallback, OnBlurCallback, CloneValueCallback, IFieldTypeFactory, FileValue } from "./abstractions.js";
|
|
5
5
|
export { Field } from "./Field.js";
|
|
6
6
|
export { FieldBuilder, createFieldBuilderRegistry } from "./FieldBuilder.js";
|
|
7
7
|
import "./fieldTypes/TextFieldType.js";
|
|
@@ -7,7 +7,7 @@ import "./fieldTypes/TextFieldType.js";
|
|
|
7
7
|
import "./fieldTypes/NumberFieldType.js";
|
|
8
8
|
import "./fieldTypes/BooleanFieldType.js";
|
|
9
9
|
export { FormModelFeature } from "./feature.js";
|
|
10
|
-
export { FieldBuilderRegistry, FieldType, FormModelFactory, RuleEvaluator } from "./abstractions.js";
|
|
10
|
+
export { FieldBuilderRegistry, FieldType, FieldValueFormatter, FormModelFactory, RuleEvaluator } from "./abstractions.js";
|
|
11
11
|
export { Field } from "./Field.js";
|
|
12
12
|
export { FieldBuilder, createFieldBuilderRegistry } from "./FieldBuilder.js";
|
|
13
13
|
export { BooleanFieldBuilder, BooleanFieldType, DateTimeFieldBuilder, DateTimeFieldType, FileFieldBuilder, FileFieldType, FileUrlFieldBuilder, FileUrlFieldType, NumberFieldBuilder, NumberFieldType, ObjectFieldBuilder, ObjectFieldType, TextFieldBuilder, TextFieldType } from "./fieldTypes/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app-admin",
|
|
3
|
-
"version": "6.5.0
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -23,27 +23,27 @@
|
|
|
23
23
|
"@emotion/styled": "11.14.1",
|
|
24
24
|
"@fortawesome/fontawesome-svg-core": "7.3.1",
|
|
25
25
|
"@fortawesome/react-fontawesome": "3.5.0",
|
|
26
|
-
"@iconify/json": "2.2.
|
|
26
|
+
"@iconify/json": "2.2.544",
|
|
27
27
|
"@lexical/utils": "0.52.0",
|
|
28
28
|
"@types/react": "18.3.31",
|
|
29
|
-
"@webiny/admin-ui": "6.5.0
|
|
30
|
-
"@webiny/app": "6.5.0
|
|
29
|
+
"@webiny/admin-ui": "6.5.0",
|
|
30
|
+
"@webiny/app": "6.5.0",
|
|
31
31
|
"@webiny/di": "1.1.0",
|
|
32
|
-
"@webiny/feature": "6.5.0
|
|
33
|
-
"@webiny/form": "6.5.0
|
|
34
|
-
"@webiny/icons": "6.5.0
|
|
35
|
-
"@webiny/lexical-converter": "6.5.0
|
|
36
|
-
"@webiny/lexical-editor": "6.5.0
|
|
37
|
-
"@webiny/lexical-nodes": "6.5.0
|
|
38
|
-
"@webiny/lexical-theme": "6.5.0
|
|
39
|
-
"@webiny/plugins": "6.5.0
|
|
40
|
-
"@webiny/react-composition": "6.5.0
|
|
41
|
-
"@webiny/react-properties": "6.5.0
|
|
42
|
-
"@webiny/sdk": "6.5.0
|
|
43
|
-
"@webiny/telemetry": "6.5.0
|
|
44
|
-
"@webiny/utils": "6.5.0
|
|
45
|
-
"@webiny/validation": "6.5.0
|
|
46
|
-
"@webiny/wcp": "6.5.0
|
|
32
|
+
"@webiny/feature": "6.5.0",
|
|
33
|
+
"@webiny/form": "6.5.0",
|
|
34
|
+
"@webiny/icons": "6.5.0",
|
|
35
|
+
"@webiny/lexical-converter": "6.5.0",
|
|
36
|
+
"@webiny/lexical-editor": "6.5.0",
|
|
37
|
+
"@webiny/lexical-nodes": "6.5.0",
|
|
38
|
+
"@webiny/lexical-theme": "6.5.0",
|
|
39
|
+
"@webiny/plugins": "6.5.0",
|
|
40
|
+
"@webiny/react-composition": "6.5.0",
|
|
41
|
+
"@webiny/react-properties": "6.5.0",
|
|
42
|
+
"@webiny/sdk": "6.5.0",
|
|
43
|
+
"@webiny/telemetry": "6.5.0",
|
|
44
|
+
"@webiny/utils": "6.5.0",
|
|
45
|
+
"@webiny/validation": "6.5.0",
|
|
46
|
+
"@webiny/wcp": "6.5.0",
|
|
47
47
|
"apollo-cache": "1.3.5",
|
|
48
48
|
"apollo-client": "2.6.10",
|
|
49
49
|
"apollo-link": "1.2.14",
|
|
@@ -58,21 +58,21 @@
|
|
|
58
58
|
"lexical": "0.52.0",
|
|
59
59
|
"lodash": "4.18.1",
|
|
60
60
|
"markdown-to-jsx": "9.10.3",
|
|
61
|
-
"mime": "4.1.
|
|
61
|
+
"mime": "4.1.1",
|
|
62
62
|
"minimatch": "10.2.6",
|
|
63
63
|
"mobx": "7.0.6",
|
|
64
64
|
"mobx-react-lite": "5.1.0",
|
|
65
65
|
"monaco-editor": "0.53.0",
|
|
66
66
|
"react": "18.3.1",
|
|
67
67
|
"react-dom": "18.3.1",
|
|
68
|
-
"react-resizable-panels": "4.14.
|
|
68
|
+
"react-resizable-panels": "4.14.5",
|
|
69
69
|
"react-transition-group": "4.4.5",
|
|
70
70
|
"react-virtualized": "9.22.6",
|
|
71
71
|
"reset-css": "5.0.2",
|
|
72
72
|
"slugify": "1.6.9",
|
|
73
73
|
"tinycolor2": "1.6.0",
|
|
74
74
|
"unicode-emoji-json": "0.9.0",
|
|
75
|
-
"zod": "4.6.
|
|
75
|
+
"zod": "4.6.7"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@testing-library/react": "16.3.3",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"@types/react-transition-group": "4.4.12",
|
|
84
84
|
"@types/store": "2.0.5",
|
|
85
85
|
"@types/tinycolor2": "1.4.6",
|
|
86
|
-
"@webiny/build-tools": "6.5.0
|
|
86
|
+
"@webiny/build-tools": "6.5.0",
|
|
87
87
|
"rimraf": "6.1.3",
|
|
88
88
|
"typescript": "7.0.2",
|
|
89
|
-
"vitest": "5.0.
|
|
89
|
+
"vitest": "5.0.5"
|
|
90
90
|
},
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|