@webiny/app-headless-cms-common 6.3.0 → 6.4.0-beta.1
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/Fields/ErrorBoundary.js +29 -34
- package/Fields/ErrorBoundary.js.map +1 -1
- package/Fields/FieldElement.js +38 -61
- package/Fields/FieldElement.js.map +1 -1
- package/Fields/FieldElementError.js +13 -22
- package/Fields/FieldElementError.js.map +1 -1
- package/Fields/FieldRulesProvider.js +11 -17
- package/Fields/FieldRulesProvider.js.map +1 -1
- package/Fields/Fields.js +76 -139
- package/Fields/Fields.js.map +1 -1
- package/Fields/Label.js +7 -7
- package/Fields/Label.js.map +1 -1
- package/Fields/LayoutDescriptorCell.js +33 -40
- package/Fields/LayoutDescriptorCell.js.map +1 -1
- package/Fields/evaluateExpression.js +54 -94
- package/Fields/evaluateExpression.js.map +1 -1
- package/Fields/fieldOptions.js +56 -104
- package/Fields/fieldOptions.js.map +1 -1
- package/Fields/index.js +0 -2
- package/Fields/layoutFieldRenderers/AlertFieldRenderer.js +7 -10
- package/Fields/layoutFieldRenderers/AlertFieldRenderer.js.map +1 -1
- package/Fields/layoutFieldRenderers/SeparatorFieldRenderer.js +12 -15
- package/Fields/layoutFieldRenderers/SeparatorFieldRenderer.js.map +1 -1
- package/Fields/layoutFieldRenderers/TabsFieldRenderer.js +52 -63
- package/Fields/layoutFieldRenderers/TabsFieldRenderer.js.map +1 -1
- package/Fields/operatorOptions.js +115 -87
- package/Fields/operatorOptions.js.map +1 -1
- package/Fields/useBind.js +101 -107
- package/Fields/useBind.js.map +1 -1
- package/Fields/useFieldRules.js +79 -133
- package/Fields/useFieldRules.js.map +1 -1
- package/Fields/useRenderPlugins.js +3 -2
- package/Fields/useRenderPlugins.js.map +1 -1
- package/ModelFieldProvider/CanEditField.js +6 -9
- package/ModelFieldProvider/CanEditField.js.map +1 -1
- package/ModelFieldProvider/ModelFieldContext.js +15 -22
- package/ModelFieldProvider/ModelFieldContext.js.map +1 -1
- package/ModelFieldProvider/index.js +0 -2
- package/ModelFieldProvider/useModelField.js +15 -21
- package/ModelFieldProvider/useModelField.js.map +1 -1
- package/ModelProvider/ModelContext.js +11 -15
- package/ModelProvider/ModelContext.js.map +1 -1
- package/ModelProvider/index.js +0 -2
- package/ModelProvider/useModel.js +7 -11
- package/ModelProvider/useModel.js.map +1 -1
- package/constants.js +2 -1
- package/constants.js.map +1 -1
- package/createFieldsList.js +27 -49
- package/createFieldsList.js.map +1 -1
- package/createValidationContainer.js +13 -20
- package/createValidationContainer.js.map +1 -1
- package/createValidators.js +42 -47
- package/createValidators.js.map +1 -1
- package/entries.graphql.d.ts +11 -0
- package/entries.graphql.js +74 -164
- package/entries.graphql.js.map +1 -1
- package/exports/admin/cms/model.js +0 -2
- package/exports/admin/cms.d.ts +1 -1
- package/exports/admin/cms.js +0 -3
- package/getModelTitleFieldId.js +4 -5
- package/getModelTitleFieldId.js.map +1 -1
- package/index.js +0 -2
- package/normalizeIcon.js +8 -7
- package/normalizeIcon.js.map +1 -1
- package/package.json +11 -13
- package/prepareFormData.js +39 -61
- package/prepareFormData.js.map +1 -1
- package/types/index.d.ts +2 -0
- package/types/index.js +1 -41
- package/types/model.js +4 -27
- package/types/model.js.map +1 -1
- package/types/shared.js +0 -3
- package/types/validation.js +0 -3
- package/Fields/index.js.map +0 -1
- package/ModelFieldProvider/index.js.map +0 -1
- package/ModelProvider/index.js.map +0 -1
- package/exports/admin/cms/model.js.map +0 -1
- package/exports/admin/cms.js.map +0 -1
- package/index.js.map +0 -1
- package/types/index.js.map +0 -1
- package/types/shared.js.map +0 -1
- package/types/validation.js.map +0 -1
package/Fields/Label.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { FormComponentLabel } from "@webiny/admin-ui";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
3
|
+
const Label = ({ children })=>/*#__PURE__*/ react.createElement(FormComponentLabel, {
|
|
4
|
+
text: children
|
|
5
|
+
});
|
|
6
|
+
const Fields_Label = Label;
|
|
7
|
+
export default Fields_Label;
|
|
8
|
+
export { Label };
|
|
9
9
|
|
|
10
10
|
//# sourceMappingURL=Label.js.map
|
package/Fields/Label.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Fields/Label.js","sources":["../../src/Fields/Label.tsx"],"sourcesContent":["import React from \"react\";\nimport { FormComponentLabel } from \"@webiny/admin-ui\";\n\ninterface LabelProps {\n children?: React.ReactNode;\n}\n\nexport const Label = ({ children }: LabelProps) => <FormComponentLabel text={children} />;\n\nexport default Label;\n"],"names":["Label","children","FormComponentLabel"],"mappings":";;AAOO,MAAMA,QAAQ,CAAC,EAAEC,QAAQ,EAAc,iBAAK,oBAACC,oBAAkBA;QAAC,MAAMD;;AAE7E,qBAAeD"}
|
|
@@ -1,47 +1,40 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { plugins } from "@webiny/plugins";
|
|
3
3
|
import { SeparatorFieldRenderer } from "./layoutFieldRenderers/SeparatorFieldRenderer.js";
|
|
4
4
|
import { AlertFieldRenderer } from "./layoutFieldRenderers/AlertFieldRenderer.js";
|
|
5
5
|
import { TabsFieldRenderer } from "./layoutFieldRenderers/TabsFieldRenderer.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
fields,
|
|
38
|
-
contentModel,
|
|
39
|
-
gridClassName
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
6
|
+
const LayoutDescriptorCell = ({ field, Bind, fields, contentModel, gridClassName })=>{
|
|
7
|
+
switch(field.type){
|
|
8
|
+
case "separator":
|
|
9
|
+
return /*#__PURE__*/ react.createElement(SeparatorFieldRenderer, {
|
|
10
|
+
field: field
|
|
11
|
+
});
|
|
12
|
+
case "alert":
|
|
13
|
+
return /*#__PURE__*/ react.createElement(AlertFieldRenderer, {
|
|
14
|
+
field: field
|
|
15
|
+
});
|
|
16
|
+
case "tabs":
|
|
17
|
+
return /*#__PURE__*/ react.createElement(TabsFieldRenderer, {
|
|
18
|
+
field: field,
|
|
19
|
+
Bind: Bind,
|
|
20
|
+
fields: fields,
|
|
21
|
+
contentModel: contentModel,
|
|
22
|
+
gridClassName: gridClassName
|
|
23
|
+
});
|
|
24
|
+
default:
|
|
25
|
+
{
|
|
26
|
+
const rendererPlugin = plugins.byType("cms-layout-field-renderer").find((p)=>p.fieldType === field.type);
|
|
27
|
+
if (rendererPlugin) return rendererPlugin.render({
|
|
28
|
+
field,
|
|
29
|
+
Bind,
|
|
30
|
+
fields,
|
|
31
|
+
contentModel,
|
|
32
|
+
gridClassName
|
|
33
|
+
});
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
45
37
|
};
|
|
38
|
+
export { LayoutDescriptorCell };
|
|
46
39
|
|
|
47
40
|
//# sourceMappingURL=LayoutDescriptorCell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Fields/LayoutDescriptorCell.js","sources":["../../src/Fields/LayoutDescriptorCell.tsx"],"sourcesContent":["import React from \"react\";\nimport type {\n CmsAlertLayoutField,\n CmsLayoutField,\n CmsSeparatorLayoutField,\n CmsTabLayoutField\n} from \"~/types/model.js\";\nimport type {\n BindComponent,\n CmsEditorContentModel,\n CmsModelLayoutFieldRendererPlugin,\n CmsModelField\n} from \"~/types/index.js\";\nimport { plugins } from \"@webiny/plugins\";\nimport { SeparatorFieldRenderer } from \"./layoutFieldRenderers/SeparatorFieldRenderer.js\";\nimport { AlertFieldRenderer } from \"./layoutFieldRenderers/AlertFieldRenderer.js\";\nimport { TabsFieldRenderer } from \"./layoutFieldRenderers/TabsFieldRenderer.js\";\n\ninterface LayoutDescriptorCellProps {\n field: CmsLayoutField;\n Bind: BindComponent;\n fields: CmsModelField[];\n contentModel: CmsEditorContentModel;\n gridClassName?: string;\n}\n\nexport const LayoutDescriptorCell = ({\n field,\n Bind,\n fields,\n contentModel,\n gridClassName\n}: LayoutDescriptorCellProps) => {\n switch (field.type) {\n case \"separator\":\n return <SeparatorFieldRenderer field={field as CmsSeparatorLayoutField} />;\n case \"alert\":\n return <AlertFieldRenderer field={field as CmsAlertLayoutField} />;\n case \"tabs\":\n return (\n <TabsFieldRenderer\n field={field as CmsTabLayoutField}\n Bind={Bind}\n fields={fields}\n contentModel={contentModel}\n gridClassName={gridClassName}\n />\n );\n default: {\n const rendererPlugin = plugins\n .byType<CmsModelLayoutFieldRendererPlugin>(\"cms-layout-field-renderer\")\n .find(p => p.fieldType === field.type);\n if (rendererPlugin) {\n return rendererPlugin.render({\n field,\n Bind,\n fields,\n contentModel,\n gridClassName\n });\n }\n return null;\n }\n }\n};\n"],"names":["LayoutDescriptorCell","field","Bind","fields","contentModel","gridClassName","SeparatorFieldRenderer","AlertFieldRenderer","TabsFieldRenderer","rendererPlugin","plugins","p"],"mappings":";;;;;AA0BO,MAAMA,uBAAuB,CAAC,EACjCC,KAAK,EACLC,IAAI,EACJC,MAAM,EACNC,YAAY,EACZC,aAAa,EACW;IACxB,OAAQJ,MAAM,IAAI;QACd,KAAK;YACD,OAAO,WAAP,GAAO,oBAACK,wBAAsBA;gBAAC,OAAOL;;QAC1C,KAAK;YACD,OAAO,WAAP,GAAO,oBAACM,oBAAkBA;gBAAC,OAAON;;QACtC,KAAK;YACD,OAAO,WAAP,GACI,oBAACO,mBAAiBA;gBACd,OAAOP;gBACP,MAAMC;gBACN,QAAQC;gBACR,cAAcC;gBACd,eAAeC;;QAG3B;YAAS;gBACL,MAAMI,iBAAiBC,QAAAA,MACZ,CAAoC,6BAC1C,IAAI,CAACC,CAAAA,IAAKA,EAAE,SAAS,KAAKV,MAAM,IAAI;gBACzC,IAAIQ,gBACA,OAAOA,eAAe,MAAM,CAAC;oBACzBR;oBACAC;oBACAC;oBACAC;oBACAC;gBACJ;gBAEJ,OAAO;YACX;IACJ;AACJ"}
|
|
@@ -1,102 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return fieldPath.replace(/\$/g, "0");
|
|
17
|
-
}
|
|
18
|
-
const pathParts = fieldPath.split(".");
|
|
19
|
-
const parentParts = bindParentName.split(".");
|
|
20
|
-
|
|
21
|
-
// Build a map of prefix -> index from the parent path.
|
|
22
|
-
// E.g., parentName "panorama.hotspots.2.items.1" gives us:
|
|
23
|
-
// "panorama.hotspots" -> "2"
|
|
24
|
-
// "panorama.hotspots.2.items" -> "1"
|
|
25
|
-
const indexMap = new Map();
|
|
26
|
-
const prefixParts = [];
|
|
27
|
-
for (const part of parentParts) {
|
|
28
|
-
if (/^\d+$/.test(part)) {
|
|
29
|
-
indexMap.set(prefixParts.join("."), part);
|
|
30
|
-
} else {
|
|
31
|
-
prefixParts.push(part);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Walk through pathParts and replace each `$` with the corresponding index
|
|
36
|
-
const resolved = [];
|
|
37
|
-
const currentPrefix = [];
|
|
38
|
-
for (const part of pathParts) {
|
|
39
|
-
if (part === "$") {
|
|
40
|
-
const key = currentPrefix.join(".");
|
|
41
|
-
const index = indexMap.get(key) ?? "0";
|
|
42
|
-
resolved.push(index);
|
|
1
|
+
function resolveFieldPath(fieldPath, bindParentName) {
|
|
2
|
+
if (!fieldPath.includes("$")) return fieldPath;
|
|
3
|
+
if (!bindParentName) return fieldPath.replace(/\$/g, "0");
|
|
4
|
+
const pathParts = fieldPath.split(".");
|
|
5
|
+
const parentParts = bindParentName.split(".");
|
|
6
|
+
const indexMap = new Map();
|
|
7
|
+
const prefixParts = [];
|
|
8
|
+
for (const part of parentParts)if (/^\d+$/.test(part)) indexMap.set(prefixParts.join("."), part);
|
|
9
|
+
else prefixParts.push(part);
|
|
10
|
+
const resolved = [];
|
|
11
|
+
const currentPrefix = [];
|
|
12
|
+
for (const part of pathParts)if ("$" === part) {
|
|
13
|
+
const key = currentPrefix.join(".");
|
|
14
|
+
const index = indexMap.get(key) ?? "0";
|
|
15
|
+
resolved.push(index);
|
|
43
16
|
} else {
|
|
44
|
-
|
|
45
|
-
|
|
17
|
+
currentPrefix.push(part);
|
|
18
|
+
resolved.push(part);
|
|
46
19
|
}
|
|
47
|
-
|
|
48
|
-
return resolved.join(".");
|
|
20
|
+
return resolved.join(".");
|
|
49
21
|
}
|
|
50
22
|
function compareValues(operator, val, rhs) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
23
|
+
switch(operator){
|
|
24
|
+
case "==":
|
|
25
|
+
return val == rhs;
|
|
26
|
+
case "!=":
|
|
27
|
+
return val != rhs;
|
|
28
|
+
case ">":
|
|
29
|
+
return Number(val) > Number(rhs);
|
|
30
|
+
case "<":
|
|
31
|
+
return Number(val) < Number(rhs);
|
|
32
|
+
case ">=":
|
|
33
|
+
return Number(val) >= Number(rhs);
|
|
34
|
+
case "<=":
|
|
35
|
+
return Number(val) <= Number(rhs);
|
|
36
|
+
case "contains":
|
|
37
|
+
return String(val ?? "").includes(String(rhs ?? ""));
|
|
38
|
+
case "startsWith":
|
|
39
|
+
return String(val ?? "").startsWith(String(rhs ?? ""));
|
|
40
|
+
case "endsWith":
|
|
41
|
+
return String(val ?? "").endsWith(String(rhs ?? ""));
|
|
42
|
+
case "isEmpty":
|
|
43
|
+
return null == val || "" === val || Array.isArray(val) && 0 === val.length;
|
|
44
|
+
case "isNotEmpty":
|
|
45
|
+
return null != val && "" !== val && !(Array.isArray(val) && 0 === val.length);
|
|
46
|
+
default:
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
77
49
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
target,
|
|
88
|
-
operator,
|
|
89
|
-
value: rhs
|
|
90
|
-
} = parsed;
|
|
91
|
-
let val;
|
|
92
|
-
if (target.endsWith(".length")) {
|
|
93
|
-
const arrayPath = target.slice(0, -".length".length);
|
|
94
|
-
const arr = getFormValue(arrayPath);
|
|
95
|
-
val = Array.isArray(arr) ? arr.length : 0;
|
|
96
|
-
} else {
|
|
97
|
-
val = getFormValue(target);
|
|
98
|
-
}
|
|
99
|
-
return compareValues(operator, val, rhs);
|
|
50
|
+
function evaluateExpression(parsed, getFormValue) {
|
|
51
|
+
const { target, operator, value: rhs } = parsed;
|
|
52
|
+
let val;
|
|
53
|
+
if (target.endsWith(".length")) {
|
|
54
|
+
const arrayPath = target.slice(0, -7);
|
|
55
|
+
const arr = getFormValue(arrayPath);
|
|
56
|
+
val = Array.isArray(arr) ? arr.length : 0;
|
|
57
|
+
} else val = getFormValue(target);
|
|
58
|
+
return compareValues(operator, val, rhs);
|
|
100
59
|
}
|
|
60
|
+
export { evaluateExpression, resolveFieldPath };
|
|
101
61
|
|
|
102
62
|
//# sourceMappingURL=evaluateExpression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Fields/evaluateExpression.js","sources":["../../src/Fields/evaluateExpression.ts"],"sourcesContent":["export type Operator =\n | \"==\"\n | \"!=\"\n | \">\"\n | \"<\"\n | \">=\"\n | \"<=\"\n | \"contains\"\n | \"startsWith\"\n | \"endsWith\"\n | \"isEmpty\"\n | \"isNotEmpty\";\n\nexport interface ParsedExpression {\n target: string;\n operator: Operator;\n value: string | number | boolean | null;\n}\n\n/**\n * Resolve a fieldPath that may contain `$` placeholders using the bindParentName.\n *\n * The bindParentName gives us the concrete indices for the current list context.\n * For example, if fieldPath is `panorama.hotspots.$.title` and bindParentName\n * is `panorama.hotspots.2`, the result is `panorama.hotspots.2.title`.\n *\n * Supports multiple nested `$` segments for deeply nested list objects.\n */\nexport function resolveFieldPath(fieldPath: string, bindParentName?: string): string {\n if (!fieldPath.includes(\"$\")) {\n return fieldPath;\n }\n\n if (!bindParentName) {\n // No parent context, replace $ with 0 as fallback\n return fieldPath.replace(/\\$/g, \"0\");\n }\n\n const pathParts = fieldPath.split(\".\");\n const parentParts = bindParentName.split(\".\");\n\n // Build a map of prefix -> index from the parent path.\n // E.g., parentName \"panorama.hotspots.2.items.1\" gives us:\n // \"panorama.hotspots\" -> \"2\"\n // \"panorama.hotspots.2.items\" -> \"1\"\n const indexMap = new Map<string, string>();\n const prefixParts: string[] = [];\n for (const part of parentParts) {\n if (/^\\d+$/.test(part)) {\n indexMap.set(prefixParts.join(\".\"), part);\n } else {\n prefixParts.push(part);\n }\n }\n\n // Walk through pathParts and replace each `$` with the corresponding index\n const resolved: string[] = [];\n const currentPrefix: string[] = [];\n for (const part of pathParts) {\n if (part === \"$\") {\n const key = currentPrefix.join(\".\");\n const index = indexMap.get(key) ?? \"0\";\n resolved.push(index);\n } else {\n currentPrefix.push(part);\n resolved.push(part);\n }\n }\n\n return resolved.join(\".\");\n}\n\nfunction compareValues(\n operator: string,\n val: unknown,\n rhs: string | number | boolean | null\n): boolean {\n switch (operator) {\n case \"==\":\n return val == rhs;\n case \"!=\":\n return val != rhs;\n case \">\":\n return Number(val) > Number(rhs);\n case \"<\":\n return Number(val) < Number(rhs);\n case \">=\":\n return Number(val) >= Number(rhs);\n case \"<=\":\n return Number(val) <= Number(rhs);\n case \"contains\":\n return String(val ?? \"\").includes(String(rhs ?? \"\"));\n case \"startsWith\":\n return String(val ?? \"\").startsWith(String(rhs ?? \"\"));\n case \"endsWith\":\n return String(val ?? \"\").endsWith(String(rhs ?? \"\"));\n case \"isEmpty\":\n return val == null || val === \"\" || (Array.isArray(val) && val.length === 0);\n case \"isNotEmpty\":\n return val != null && val !== \"\" && !(Array.isArray(val) && val.length === 0);\n default:\n return false;\n }\n}\n\n/**\n * Evaluate a parsed expression against form values.\n *\n * If the resolved fieldPath ends with `.length`, it reads the array at the parent\n * path and uses its length as the left-hand value.\n */\nexport function evaluateExpression(\n parsed: ParsedExpression,\n getFormValue: (path: string) => unknown\n): boolean {\n const { target, operator, value: rhs } = parsed;\n\n let val: unknown;\n if (target.endsWith(\".length\")) {\n const arrayPath = target.slice(0, -\".length\".length);\n const arr = getFormValue(arrayPath);\n val = Array.isArray(arr) ? arr.length : 0;\n } else {\n val = getFormValue(target);\n }\n\n return compareValues(operator, val, rhs);\n}\n"],"names":["resolveFieldPath","fieldPath","bindParentName","pathParts","parentParts","indexMap","Map","prefixParts","part","resolved","currentPrefix","key","index","compareValues","operator","val","rhs","Number","String","Array","evaluateExpression","parsed","getFormValue","target","arrayPath","arr"],"mappings":"AA4BO,SAASA,iBAAiBC,SAAiB,EAAEC,cAAuB;IACvE,IAAI,C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,QAAPA,OAAeA,AAAQ,OAARA,OAAeI,MAAM,OAAO,CAACJ,QAAQA,AAAe,MAAfA,IAAI,MAAM;QACzE,KAAK;YACD,OAAOA,AAAO,QAAPA,OAAeA,AAAQ,OAARA,OAAc,CAAEI,CAAAA,MAAM,OAAO,CAACJ,QAAQA,AAAe,MAAfA,IAAI,MAAM,AAAK;QAC/E;YACI,OAAO;IACf;AACJ;AAQO,SAASK,mBACZC,MAAwB,EACxBC,YAAuC;IAEvC,MAAM,EAAEC,MAAM,EAAET,QAAQ,EAAE,OAAOE,GAAG,EAAE,GAAGK;IAEzC,IAAIN;IACJ,IAAIQ,OAAO,QAAQ,CAAC,YAAY;QAC5B,MAAMC,YAAYD,OAAO,KAAK,CAAC,GAAG;QAClC,MAAME,MAAMH,aAAaE;QACzBT,MAAMI,MAAM,OAAO,CAACM,OAAOA,IAAI,MAAM,GAAG;IAC5C,OACIV,MAAMO,aAAaC;IAGvB,OAAOV,cAAcC,UAAUC,KAAKC;AACxC"}
|
package/Fields/fieldOptions.js
CHANGED
|
@@ -1,113 +1,65 @@
|
|
|
1
1
|
import { isLayoutField } from "../types/model.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const plugin = pluginByType.get(cell.type);
|
|
18
|
-
if (!plugin?.field.getFieldLabelPrefixes) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const prefixes = plugin.field.getFieldLabelPrefixes({
|
|
22
|
-
field: cell
|
|
23
|
-
});
|
|
24
|
-
for (const [fieldId, prefix] of Object.entries(prefixes)) {
|
|
25
|
-
map.set(fieldId, prefix);
|
|
26
|
-
}
|
|
2
|
+
function buildFieldLabelPrefixes(layout, plugins) {
|
|
3
|
+
const map = new Map();
|
|
4
|
+
const pluginByType = new Map(plugins.map((p)=>[
|
|
5
|
+
p.field.type,
|
|
6
|
+
p
|
|
7
|
+
]));
|
|
8
|
+
for (const row of layout)for (const cell of row){
|
|
9
|
+
if (!isLayoutField(cell)) continue;
|
|
10
|
+
const plugin = pluginByType.get(cell.type);
|
|
11
|
+
if (!plugin?.field.getFieldLabelPrefixes) continue;
|
|
12
|
+
const prefixes = plugin.field.getFieldLabelPrefixes({
|
|
13
|
+
field: cell
|
|
14
|
+
});
|
|
15
|
+
for (const [fieldId, prefix] of Object.entries(prefixes))map.set(fieldId, prefix);
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
return map;
|
|
17
|
+
return map;
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
const childFields = field.settings?.fields;
|
|
69
|
-
|
|
70
|
-
// Ref field: include for isEmpty checks, skip children
|
|
71
|
-
if (field.type === "ref") {
|
|
72
|
-
options.push({
|
|
73
|
-
label,
|
|
74
|
-
value: path,
|
|
75
|
-
fieldType: field.type
|
|
76
|
-
});
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Object with child fields
|
|
81
|
-
if (childFields && childFields.length > 0) {
|
|
82
|
-
// Build label prefixes from the object field's own layout (e.g., tabs inside an object).
|
|
83
|
-
let childPrefixes;
|
|
84
|
-
if (layoutPlugins && field.settings?.layout) {
|
|
85
|
-
childPrefixes = buildFieldLabelPrefixes(field.settings.layout, layoutPlugins);
|
|
86
|
-
}
|
|
87
|
-
if (field.list) {
|
|
88
|
-
// List object: emit .length pseudo-option
|
|
19
|
+
function buildFieldOptions(fields, prefix = "", labelPrefix = "", fieldLabelPrefixes, layoutPlugins) {
|
|
20
|
+
const options = [];
|
|
21
|
+
for (const field of fields){
|
|
22
|
+
const path = prefix + field.fieldId;
|
|
23
|
+
const layoutPrefix = fieldLabelPrefixes?.get(field.id);
|
|
24
|
+
const label = layoutPrefix ? `${labelPrefix}${layoutPrefix} › ${field.label}` : labelPrefix + field.label;
|
|
25
|
+
if ("dynamicZone" === field.type) {
|
|
26
|
+
options.push({
|
|
27
|
+
label: `${label} › Length`,
|
|
28
|
+
value: `${path}.length`,
|
|
29
|
+
fieldType: "number"
|
|
30
|
+
});
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const childFields = field.settings?.fields;
|
|
34
|
+
if ("ref" === field.type) {
|
|
35
|
+
options.push({
|
|
36
|
+
label,
|
|
37
|
+
value: path,
|
|
38
|
+
fieldType: field.type
|
|
39
|
+
});
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (childFields && childFields.length > 0) {
|
|
43
|
+
let childPrefixes;
|
|
44
|
+
if (layoutPlugins && field.settings?.layout) childPrefixes = buildFieldLabelPrefixes(field.settings.layout, layoutPlugins);
|
|
45
|
+
if (field.list) {
|
|
46
|
+
options.push({
|
|
47
|
+
label: `${label} › Length`,
|
|
48
|
+
value: `${path}.length`,
|
|
49
|
+
fieldType: "number"
|
|
50
|
+
});
|
|
51
|
+
options.push(...buildFieldOptions(childFields, `${path}.$.`, `${label} › `, childPrefixes, layoutPlugins));
|
|
52
|
+
} else options.push(...buildFieldOptions(childFields, `${path}.`, `${label} › `, childPrefixes, layoutPlugins));
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
89
55
|
options.push({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
56
|
+
label,
|
|
57
|
+
value: path,
|
|
58
|
+
fieldType: field.type
|
|
93
59
|
});
|
|
94
|
-
// Recurse children with $ segment
|
|
95
|
-
options.push(...buildFieldOptions(childFields, `${path}.$.`, `${label} › `, childPrefixes, layoutPlugins));
|
|
96
|
-
} else {
|
|
97
|
-
// Non-list object: recurse into children
|
|
98
|
-
options.push(...buildFieldOptions(childFields, `${path}.`, `${label} › `, childPrefixes, layoutPlugins));
|
|
99
|
-
}
|
|
100
|
-
continue;
|
|
101
60
|
}
|
|
102
|
-
|
|
103
|
-
// Leaf field
|
|
104
|
-
options.push({
|
|
105
|
-
label,
|
|
106
|
-
value: path,
|
|
107
|
-
fieldType: field.type
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return options;
|
|
61
|
+
return options;
|
|
111
62
|
}
|
|
63
|
+
export { buildFieldLabelPrefixes, buildFieldOptions };
|
|
112
64
|
|
|
113
65
|
//# sourceMappingURL=fieldOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Fields/fieldOptions.js","sources":["../../src/Fields/fieldOptions.ts"],"sourcesContent":["import type { CmsModelField, CmsEditorFieldsLayout } from \"~/types/model.js\";\nimport type { CmsModelLayoutFieldTypePlugin } from \"~/types/index.js\";\nimport { isLayoutField } from \"~/types/model.js\";\n\nexport interface FieldOption {\n label: string;\n value: string;\n fieldType: string;\n}\n\n/**\n * Walk a model layout and collect label prefixes for each field ID by delegating\n * to `getFieldLabelPrefixes` on the matching layout-field-type plugin.\n *\n * Returns a map from fieldId to its label prefix string\n * (e.g., `\"metaTitle\" → \"My Tabs › SEO\"`).\n */\nexport function buildFieldLabelPrefixes(\n layout: CmsEditorFieldsLayout,\n plugins: CmsModelLayoutFieldTypePlugin[]\n): Map<string, string> {\n const map = new Map<string, string>();\n const pluginByType = new Map(plugins.map(p => [p.field.type, p]));\n\n for (const row of layout) {\n for (const cell of row) {\n if (!isLayoutField(cell)) {\n continue;\n }\n\n const plugin = pluginByType.get(cell.type);\n if (!plugin?.field.getFieldLabelPrefixes) {\n continue;\n }\n\n const prefixes = plugin.field.getFieldLabelPrefixes({ field: cell });\n for (const [fieldId, prefix] of Object.entries(prefixes)) {\n map.set(fieldId, prefix);\n }\n }\n }\n\n return map;\n}\n\n/**\n * Build a flat list of field options from the model's field tree.\n * Paths are absolute using fieldId segments, with `$` for list-object children\n * (e.g., `panorama.hotspots.$.title`).\n *\n * When `fieldLabelPrefixes` is provided, fields whose IDs appear in the map will\n * have the layout hierarchy prepended to their labels\n * (e.g., `\"My Tabs › SEO › Meta Title\"`).\n *\n * When `layoutPlugins` is provided, nested layouts inside object fields\n * (e.g., tabs inside an object field) are also scanned for label prefixes.\n *\n * Recursion rules:\n * - Leaf field (no settings.fields): emit option\n * - Object field (settings.fields, not list): recurse with prefix\n * - List object field (settings.fields, list: true): emit `.length` pseudo-option,\n * then recurse children with `.$` segment\n * - dynamicZone: skip\n * - ref: emit for isEmpty checks, skip children\n */\nexport function buildFieldOptions(\n fields: CmsModelField[],\n prefix = \"\",\n labelPrefix = \"\",\n fieldLabelPrefixes?: Map<string, string>,\n layoutPlugins?: CmsModelLayoutFieldTypePlugin[]\n): FieldOption[] {\n const options: FieldOption[] = [];\n\n for (const field of fields) {\n const path = prefix + field.fieldId;\n const layoutPrefix = fieldLabelPrefixes?.get(field.id);\n const label = layoutPrefix\n ? `${labelPrefix}${layoutPrefix} › ${field.label}`\n : labelPrefix + field.label;\n\n // Dynamic zone: emit .length pseudo-option only, skip children\n if (field.type === \"dynamicZone\") {\n options.push({\n label: `${label} › Length`,\n value: `${path}.length`,\n fieldType: \"number\"\n });\n continue;\n }\n\n const childFields = field.settings?.fields;\n\n // Ref field: include for isEmpty checks, skip children\n if (field.type === \"ref\") {\n options.push({ label, value: path, fieldType: field.type });\n continue;\n }\n\n // Object with child fields\n if (childFields && childFields.length > 0) {\n // Build label prefixes from the object field's own layout (e.g., tabs inside an object).\n let childPrefixes: Map<string, string> | undefined;\n if (layoutPlugins && field.settings?.layout) {\n childPrefixes = buildFieldLabelPrefixes(field.settings.layout, layoutPlugins);\n }\n\n if (field.list) {\n // List object: emit .length pseudo-option\n options.push({\n label: `${label} › Length`,\n value: `${path}.length`,\n fieldType: \"number\"\n });\n // Recurse children with $ segment\n options.push(\n ...buildFieldOptions(\n childFields,\n `${path}.$.`,\n `${label} › `,\n childPrefixes,\n layoutPlugins\n )\n );\n } else {\n // Non-list object: recurse into children\n options.push(\n ...buildFieldOptions(\n childFields,\n `${path}.`,\n `${label} › `,\n childPrefixes,\n layoutPlugins\n )\n );\n }\n continue;\n }\n\n // Leaf field\n options.push({ label, value: path, fieldType: field.type });\n }\n\n return options;\n}\n"],"names":["buildFieldLabelPrefixes","layout","plugins","map","Map","pluginByType","p","row","cell","isLayoutField","plugin","prefixes","fieldId","prefix","Object","buildFieldOptions","fields","labelPrefix","fieldLabelPrefixes","layoutPlugins","options","field","path","layoutPrefix","label","childFields","childPrefixes"],"mappings":";AAiBO,SAASA,wBACZC,MAA6B,EAC7BC,OAAwC;IAExC,MAAMC,MAAM,IAAIC;IAChB,MAAMC,eAAe,IAAID,IAAIF,QAAQ,GAAG,CAACI,CAAAA,IAAK;YAACA,EAAE,KAAK,CAAC,IAAI;YAAEA;SAAE;IAE/D,KAAK,MAAMC,OAAON,OACd,KAAK,MAAMO,QAAQD,IAAK;QACpB,IAAI,CAACE,cAAcD,OACf;QAGJ,MAAME,SAASL,aAAa,GAAG,CAACG,KAAK,IAAI;QACzC,IAAI,CAACE,QAAQ,MAAM,uBACf;QAGJ,MAAMC,WAAWD,OAAO,KAAK,CAAC,qBAAqB,CAAC;YAAE,OAAOF;QAAK;QAClE,KAAK,MAAM,CAACI,SAASC,OAAO,IAAIC,OAAO,OAAO,CAACH,UAC3CR,IAAI,GAAG,CAACS,SAASC;IAEzB;IAGJ,OAAOV;AACX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CAAC,EACbE,eACAP;YAIZ;QACJ;QAGAC,QAAQ,IAAI,CAAC;YAAEI;YAAO,OAAOF;YAAM,WAAWD,MAAM,IAAI;QAAC;IAC7D;IAEA,OAAOD;AACX"}
|
package/Fields/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { Alert, Grid } from "@webiny/admin-ui";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type: field.alertType
|
|
10
|
-
}, field.label));
|
|
11
|
-
};
|
|
3
|
+
const AlertFieldRenderer = ({ field })=>/*#__PURE__*/ react.createElement(Grid.Column, {
|
|
4
|
+
span: 12
|
|
5
|
+
}, /*#__PURE__*/ react.createElement(Alert, {
|
|
6
|
+
type: field.alertType
|
|
7
|
+
}, field.label));
|
|
8
|
+
export { AlertFieldRenderer };
|
|
12
9
|
|
|
13
10
|
//# sourceMappingURL=AlertFieldRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Fields/layoutFieldRenderers/AlertFieldRenderer.js","sources":["../../../src/Fields/layoutFieldRenderers/AlertFieldRenderer.tsx"],"sourcesContent":["import React from \"react\";\nimport { Alert, Grid } from \"@webiny/admin-ui\";\nimport type { CmsAlertLayoutField } from \"~/types/model.js\";\n\ninterface AlertFieldRendererProps {\n field: CmsAlertLayoutField;\n}\n\nexport const AlertFieldRenderer = ({ field }: AlertFieldRendererProps) => {\n return (\n <Grid.Column span={12}>\n <Alert type={field.alertType}>{field.label}</Alert>\n </Grid.Column>\n );\n};\n"],"names":["AlertFieldRenderer","field","Grid","Alert"],"mappings":";;AAQO,MAAMA,qBAAqB,CAAC,EAAEC,KAAK,EAA2B,GAC1D,WAAP,GACI,oBAACC,KAAK,MAAM;QAAC,MAAM;qBACf,oBAACC,OAAKA;QAAC,MAAMF,MAAM,SAAS;OAAGA,MAAM,KAAK"}
|