@webiny/app-headless-cms-common 6.3.0-beta.4 → 6.4.0-beta.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/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
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { createGenericContext } from "@webiny/app-admin";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export const ParentValueIndexProvider = Provider;
|
|
17
|
-
export const useParentValueIndex = () => {
|
|
18
|
-
try {
|
|
19
|
-
const context = useHook();
|
|
20
|
-
return context.index;
|
|
21
|
-
} catch {
|
|
22
|
-
return -1;
|
|
23
|
-
}
|
|
3
|
+
const ModelFieldContext = /*#__PURE__*/ react.createContext(void 0);
|
|
4
|
+
const ModelFieldProvider = ({ field, children })=>/*#__PURE__*/ react.createElement(ModelFieldContext.Provider, {
|
|
5
|
+
value: field
|
|
6
|
+
}, children);
|
|
7
|
+
const { Provider: Provider, useHook: useHook } = createGenericContext("FieldIndex");
|
|
8
|
+
const ParentValueIndexProvider = Provider;
|
|
9
|
+
const useParentValueIndex = ()=>{
|
|
10
|
+
try {
|
|
11
|
+
const context = useHook();
|
|
12
|
+
return context.index;
|
|
13
|
+
} catch {
|
|
14
|
+
return -1;
|
|
15
|
+
}
|
|
24
16
|
};
|
|
17
|
+
export { ModelFieldContext, ModelFieldProvider, ParentValueIndexProvider, useParentValueIndex };
|
|
25
18
|
|
|
26
19
|
//# sourceMappingURL=ModelFieldContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ModelFieldProvider/ModelFieldContext.js","sources":["../../src/ModelFieldProvider/ModelFieldContext.tsx"],"sourcesContent":["import React from \"react\";\nimport type { CmsModelField } from \"~/types/index.js\";\nimport { createGenericContext } from \"@webiny/app-admin\";\n\nexport type ModelFieldContext = CmsModelField;\n\nexport const ModelFieldContext = React.createContext<ModelFieldContext | undefined>(undefined);\n\nexport interface ModelFieldProviderProps {\n field: CmsModelField;\n children: React.ReactNode;\n}\n\nexport const ModelFieldProvider = ({ field, children }: ModelFieldProviderProps) => {\n return <ModelFieldContext.Provider value={field}>{children}</ModelFieldContext.Provider>;\n};\n\nconst { Provider, useHook } = createGenericContext<{ index: number }>(\"FieldIndex\");\n\nexport const ParentValueIndexProvider = Provider;\n\nexport const useParentValueIndex = () => {\n try {\n const context = useHook();\n return context.index;\n } catch {\n return -1;\n }\n};\n"],"names":["ModelFieldContext","React","undefined","ModelFieldProvider","field","children","Provider","useHook","createGenericContext","ParentValueIndexProvider","useParentValueIndex","context"],"mappings":";;AAMO,MAAMA,oBAAoB,WAAHA,GAAGC,MAAAA,aAAmB,CAAgCC;AAO7E,MAAMC,qBAAqB,CAAC,EAAEC,KAAK,EAAEC,QAAQ,EAA2B,GACpE,WAAP,GAAO,oBAACL,kBAAkB,QAAQ;QAAC,OAAOI;OAAQC;AAGtD,MAAM,EAAEC,UAAAA,QAAQ,EAAEC,SAAAA,OAAO,EAAE,GAAGC,qBAAwC;AAE/D,MAAMC,2BAA2BH;AAEjC,MAAMI,sBAAsB;IAC/B,IAAI;QACA,MAAMC,UAAUJ;QAChB,OAAOI,QAAQ,KAAK;IACxB,EAAE,OAAM;QACJ,OAAO;IACX;AACJ"}
|
|
@@ -2,28 +2,22 @@ import { useContext } from "react";
|
|
|
2
2
|
import { plugins } from "@webiny/plugins";
|
|
3
3
|
import { makeDecoratable } from "@webiny/react-composition";
|
|
4
4
|
import { ModelFieldContext, useParentValueIndex } from "./ModelFieldContext.js";
|
|
5
|
-
const getFieldPlugin = type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return plugin;
|
|
5
|
+
const getFieldPlugin = (type)=>{
|
|
6
|
+
const plugin = plugins.byType("cms-editor-field-type").find((plugin)=>plugin.field.type === type);
|
|
7
|
+
if (!plugin) throw Error(`Missing plugin for field type "${type}"!`);
|
|
8
|
+
return plugin;
|
|
11
9
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
field,
|
|
24
|
-
fieldPlugin,
|
|
25
|
-
parentValueIndex
|
|
26
|
-
};
|
|
10
|
+
const useModelField = makeDecoratable(()=>{
|
|
11
|
+
const field = useContext(ModelFieldContext);
|
|
12
|
+
if (!field) throw Error('Missing "ModelFieldProvider" in the component tree. Are you using the "useModelField()" hook in the right place?');
|
|
13
|
+
const parentValueIndex = useParentValueIndex();
|
|
14
|
+
const fieldPlugin = getFieldPlugin(field.type);
|
|
15
|
+
return {
|
|
16
|
+
field,
|
|
17
|
+
fieldPlugin,
|
|
18
|
+
parentValueIndex
|
|
19
|
+
};
|
|
27
20
|
});
|
|
21
|
+
export { useModelField };
|
|
28
22
|
|
|
29
23
|
//# sourceMappingURL=useModelField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ModelFieldProvider/useModelField.js","sources":["../../src/ModelFieldProvider/useModelField.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { plugins } from \"@webiny/plugins\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport { ModelFieldContext, useParentValueIndex } from \"./ModelFieldContext.js\";\nimport type { CmsModelField, CmsModelFieldTypePlugin } from \"~/types/index.js\";\n\ninterface GetFieldPlugin {\n (type: string): CmsModelFieldTypePlugin;\n}\n\nconst getFieldPlugin: GetFieldPlugin = type => {\n const plugin = plugins\n .byType<CmsModelFieldTypePlugin>(\"cms-editor-field-type\")\n .find(plugin => plugin.field.type === type);\n\n if (!plugin) {\n throw Error(`Missing plugin for field type \"${type}\"!`);\n }\n\n return plugin;\n};\n\nexport interface UseModelField {\n field: CmsModelField;\n parentValueIndex: number;\n fieldPlugin: CmsModelFieldTypePlugin;\n}\n\n/**\n * Get model field from the current context.\n */\nexport const useModelField = makeDecoratable((): UseModelField => {\n const field = useContext(ModelFieldContext);\n\n if (!field) {\n throw Error(\n `Missing \"ModelFieldProvider\" in the component tree. Are you using the \"useModelField()\" hook in the right place?`\n );\n }\n\n const parentValueIndex = useParentValueIndex();\n\n const fieldPlugin = getFieldPlugin(field.type);\n\n return { field, fieldPlugin, parentValueIndex };\n});\n"],"names":["getFieldPlugin","type","plugin","plugins","Error","useModelField","makeDecoratable","field","useContext","ModelFieldContext","parentValueIndex","useParentValueIndex","fieldPlugin"],"mappings":";;;;AAUA,MAAMA,iBAAiCC,CAAAA;IACnC,MAAMC,SAASC,QAAAA,MACJ,CAA0B,yBAChC,IAAI,CAACD,CAAAA,SAAUA,OAAO,KAAK,CAAC,IAAI,KAAKD;IAE1C,IAAI,CAACC,QACD,MAAME,MAAM,CAAC,+BAA+B,EAAEH,KAAK,EAAE,CAAC;IAG1D,OAAOC;AACX;AAWO,MAAMG,gBAAgBC,gBAAgB;IACzC,MAAMC,QAAQC,WAAWC;IAEzB,IAAI,CAACF,OACD,MAAMH,MACF;IAIR,MAAMM,mBAAmBC;IAEzB,MAAMC,cAAcZ,eAAeO,MAAM,IAAI;IAE7C,OAAO;QAAEA;QAAOK;QAAaF;IAAiB;AAClD"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { DevToolsSection } from "@webiny/app-admin";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
data: model,
|
|
14
|
-
views: "raw"
|
|
15
|
-
}), children);
|
|
16
|
-
};
|
|
3
|
+
const ModelContext = /*#__PURE__*/ react.createContext(void 0);
|
|
4
|
+
const ModelProvider = ({ model, children })=>/*#__PURE__*/ react.createElement(ModelContext.Provider, {
|
|
5
|
+
value: model
|
|
6
|
+
}, /*#__PURE__*/ react.createElement(DevToolsSection, {
|
|
7
|
+
name: "Model",
|
|
8
|
+
group: "CMS",
|
|
9
|
+
data: model,
|
|
10
|
+
views: "raw"
|
|
11
|
+
}), children);
|
|
12
|
+
export { ModelContext, ModelProvider };
|
|
17
13
|
|
|
18
14
|
//# sourceMappingURL=ModelContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ModelProvider/ModelContext.js","sources":["../../src/ModelProvider/ModelContext.tsx"],"sourcesContent":["import React from \"react\";\nimport { DevToolsSection } from \"@webiny/app-admin\";\nimport type { CmsModel } from \"~/types/index.js\";\n\nexport type ModelContext = CmsModel;\n\nexport const ModelContext = React.createContext<ModelContext | undefined>(undefined);\n\nexport interface ModelProviderProps {\n model: CmsModel;\n children: React.ReactNode;\n}\n\nexport const ModelProvider = ({ model, children }: ModelProviderProps) => {\n return (\n <ModelContext.Provider value={model}>\n <DevToolsSection name={\"Model\"} group=\"CMS\" data={model} views={\"raw\"} />\n {children}\n </ModelContext.Provider>\n );\n};\n"],"names":["ModelContext","React","undefined","ModelProvider","model","children","DevToolsSection"],"mappings":";;AAMO,MAAMA,eAAe,WAAHA,GAAGC,MAAAA,aAAmB,CAA2BC;AAOnE,MAAMC,gBAAgB,CAAC,EAAEC,KAAK,EAAEC,QAAQ,EAAsB,GAC1D,WAAP,GACI,oBAACL,aAAa,QAAQ;QAAC,OAAOI;qBAC1B,oBAACE,iBAAeA;QAAC,MAAM;QAAS,OAAM;QAAM,MAAMF;QAAO,OAAO;QAC/DC"}
|
package/ModelProvider/index.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { ModelContext } from "./ModelContext.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
throw Error(`Missing "ModelContext" in the component tree. Are you using the "useModel()" hook in the right place?`);
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
model
|
|
13
|
-
};
|
|
3
|
+
function useModel() {
|
|
4
|
+
const model = useContext(ModelContext);
|
|
5
|
+
if (!model) throw Error('Missing "ModelContext" in the component tree. Are you using the "useModel()" hook in the right place?');
|
|
6
|
+
return {
|
|
7
|
+
model
|
|
8
|
+
};
|
|
14
9
|
}
|
|
10
|
+
export { useModel };
|
|
15
11
|
|
|
16
12
|
//# sourceMappingURL=useModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ModelProvider/useModel.js","sources":["../../src/ModelProvider/useModel.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ModelContext } from \"./ModelContext.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ntype UseModelReturnType = {\n model: CmsModel;\n};\n\n/**\n * Get model from the current context.\n */\nexport function useModel(): UseModelReturnType {\n const model = useContext(ModelContext);\n if (!model) {\n throw Error(\n `Missing \"ModelContext\" in the component tree. Are you using the \"useModel()\" hook in the right place?`\n );\n }\n\n return { model };\n}\n"],"names":["useModel","model","useContext","ModelContext","Error"],"mappings":";;AAWO,SAASA;IACZ,MAAMC,QAAQC,WAAWC;IACzB,IAAI,CAACF,OACD,MAAMG,MACF;IAIR,OAAO;QAAEH;IAAM;AACnB"}
|
package/constants.js
CHANGED
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const CMS_MODEL_SINGLETON_TAG = \"singleEntry\";\n"],"names":["CMS_MODEL_SINGLETON_TAG"],"mappings":"AAAO,MAAMA,0BAA0B"}
|
package/createFieldsList.js
CHANGED
|
@@ -1,53 +1,31 @@
|
|
|
1
1
|
import { plugins } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const selection = typeof queryField === "string" ? queryField : queryField({
|
|
29
|
-
model,
|
|
30
|
-
field,
|
|
31
|
-
graphQLTypePrefix: typePrefix
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* If field type plugin returns `null`, we don't include the field in the selection.
|
|
36
|
-
*/
|
|
37
|
-
if (selection === null) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
return `${field.fieldId} ${selection}`;
|
|
41
|
-
}
|
|
42
|
-
return field.fieldId;
|
|
43
|
-
}).filter(Boolean);
|
|
44
|
-
/**
|
|
45
|
-
* If there are no fields, let's always load the `_empty` field.
|
|
46
|
-
*/
|
|
47
|
-
if (fields.length === 0) {
|
|
48
|
-
fields.push("_empty");
|
|
49
|
-
}
|
|
50
|
-
return fields.join("\n");
|
|
2
|
+
function createFieldsList({ model, fields: inputFields, graphQLTypePrefix }) {
|
|
3
|
+
const fieldPlugins = plugins.byType("cms-editor-field-type").reduce((acc, item)=>({
|
|
4
|
+
...acc,
|
|
5
|
+
[item.field.type]: item.field
|
|
6
|
+
}), {});
|
|
7
|
+
const typePrefix = graphQLTypePrefix ?? model.singularApiName;
|
|
8
|
+
const fields = inputFields.map((field)=>{
|
|
9
|
+
if (!fieldPlugins[field.type]) {
|
|
10
|
+
console.log(`Unknown field plugin for field type "${field.type}".`);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const { graphql } = fieldPlugins[field.type];
|
|
14
|
+
if (graphql && graphql.queryField) {
|
|
15
|
+
const { queryField } = graphql;
|
|
16
|
+
const selection = "string" == typeof queryField ? queryField : queryField({
|
|
17
|
+
model,
|
|
18
|
+
field,
|
|
19
|
+
graphQLTypePrefix: typePrefix
|
|
20
|
+
});
|
|
21
|
+
if (null === selection) return null;
|
|
22
|
+
return `${field.fieldId} ${selection}`;
|
|
23
|
+
}
|
|
24
|
+
return field.fieldId;
|
|
25
|
+
}).filter(Boolean);
|
|
26
|
+
if (0 === fields.length) fields.push("_empty");
|
|
27
|
+
return fields.join("\n");
|
|
51
28
|
}
|
|
29
|
+
export { createFieldsList };
|
|
52
30
|
|
|
53
31
|
//# sourceMappingURL=createFieldsList.js.map
|
package/createFieldsList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createFieldsList.js","sources":["../src/createFieldsList.ts"],"sourcesContent":["import type { CmsModel, CmsModelField, CmsModelFieldTypePlugin } from \"~/types/index.js\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface CreateFieldsListParams {\n model: CmsModel;\n fields: CmsModelField[];\n graphQLTypePrefix?: string;\n}\n\n/**\n * When used in ACO, this method receives a filtered list of field types.\n * Find `createListRecords` in app-aco to find out more.\n */\nexport function createFieldsList({\n model,\n fields: inputFields,\n graphQLTypePrefix\n}: CreateFieldsListParams): string {\n const fieldPlugins: Record<string, CmsModelFieldTypePlugin[\"field\"]> = plugins\n .byType<CmsModelFieldTypePlugin>(\"cms-editor-field-type\")\n .reduce((acc, item) => ({ ...acc, [item.field.type]: item.field }), {});\n\n const typePrefix = graphQLTypePrefix ?? model.singularApiName;\n\n const fields = inputFields\n .map(field => {\n if (!fieldPlugins[field.type]) {\n console.log(`Unknown field plugin for field type \"${field.type}\".`);\n return null;\n }\n const { graphql } = fieldPlugins[field.type];\n\n if (graphql && graphql.queryField) {\n const { queryField } = graphql;\n const selection =\n typeof queryField === \"string\"\n ? queryField\n : queryField({ model, field, graphQLTypePrefix: typePrefix });\n\n /**\n * If field type plugin returns `null`, we don't include the field in the selection.\n */\n if (selection === null) {\n return null;\n }\n\n return `${field.fieldId} ${selection}`;\n }\n\n return field.fieldId;\n })\n .filter(Boolean);\n /**\n * If there are no fields, let's always load the `_empty` field.\n */\n if (fields.length === 0) {\n fields.push(\"_empty\");\n }\n return fields.join(\"\\n\");\n}\n"],"names":["createFieldsList","model","inputFields","graphQLTypePrefix","fieldPlugins","plugins","acc","item","typePrefix","fields","field","console","graphql","queryField","selection","Boolean"],"mappings":";AAaO,SAASA,iBAAiB,EAC7BC,KAAK,EACL,QAAQC,WAAW,EACnBC,iBAAiB,EACI;IACrB,MAAMC,eAAiEC,QAAAA,MAC5D,CAA0B,yBAChC,MAAM,CAAC,CAACC,KAAKC,OAAU;YAAE,GAAGD,GAAG;YAAE,CAACC,KAAK,KAAK,CAAC,IAAI,CAAC,EAAEA,KAAK,KAAK;QAAC,IAAI,CAAC;IAEzE,MAAMC,aAAaL,qBAAqBF,MAAM,eAAe;IAE7D,MAAMQ,SAASP,YACV,GAAG,CAACQ,CAAAA;QACD,IAAI,CAACN,YAAY,CAACM,MAAM,IAAI,CAAC,EAAE;YAC3BC,QAAQ,GAAG,CAAC,CAAC,qCAAqC,EAAED,MAAM,IAAI,CAAC,EAAE,CAAC;YAClE,OAAO;QACX;QACA,MAAM,EAAEE,OAAO,EAAE,GAAGR,YAAY,CAACM,MAAM,IAAI,CAAC;QAE5C,IAAIE,WAAWA,QAAQ,UAAU,EAAE;YAC/B,MAAM,EAAEC,UAAU,EAAE,GAAGD;YACvB,MAAME,YACF,AAAsB,YAAtB,OAAOD,aACDA,aACAA,WAAW;gBAAEZ;gBAAOS;gBAAO,mBAAmBF;YAAW;YAKnE,IAAIM,AAAc,SAAdA,WACA,OAAO;YAGX,OAAO,GAAGJ,MAAM,OAAO,CAAC,CAAC,EAAEI,WAAW;QAC1C;QAEA,OAAOJ,MAAM,OAAO;IACxB,GACC,MAAM,CAACK;IAIZ,IAAIN,AAAkB,MAAlBA,OAAO,MAAM,EACbA,OAAO,IAAI,CAAC;IAEhB,OAAOA,OAAO,IAAI,CAAC;AACvB"}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { useModelField } from "./ModelFieldProvider/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"data-path": path,
|
|
16
|
-
"data-field-type": field.type,
|
|
17
|
-
"data-field-multiple-values": String(field.list),
|
|
18
|
-
"data-field-renderer": String(field.renderer.name)
|
|
19
|
-
}, children);
|
|
20
|
-
};
|
|
21
|
-
};
|
|
3
|
+
const createValidationContainer = (path)=>function({ children }) {
|
|
4
|
+
const { field } = useModelField();
|
|
5
|
+
if (void 0 === field.list) field.list = false;
|
|
6
|
+
return /*#__PURE__*/ react.createElement("hcms-field-validation", {
|
|
7
|
+
class: "block",
|
|
8
|
+
"data-path": path,
|
|
9
|
+
"data-field-type": field.type,
|
|
10
|
+
"data-field-multiple-values": String(field.list),
|
|
11
|
+
"data-field-renderer": String(field.renderer.name)
|
|
12
|
+
}, children);
|
|
13
|
+
};
|
|
14
|
+
export { createValidationContainer };
|
|
22
15
|
|
|
23
16
|
//# sourceMappingURL=createValidationContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createValidationContainer.js","sources":["../src/createValidationContainer.tsx"],"sourcesContent":["import React from \"react\";\nimport { useModelField } from \"./ModelFieldProvider/index.js\";\n\ndeclare module \"react\" {\n namespace JSX {\n interface IntrinsicElements {\n \"hcms-field-validation\": {\n class: string;\n \"data-path\": string;\n \"data-field-type\": string;\n \"data-field-multiple-values\": string;\n \"data-field-renderer\": string;\n children: React.ReactNode;\n };\n }\n }\n}\n\nexport const createValidationContainer = (path: string) => {\n return function ValidationContainer({ children }: { children: React.ReactNode }) {\n const { field } = useModelField();\n\n if (field.list === undefined) {\n field.list = false;\n }\n\n return (\n <hcms-field-validation\n class={\"block\"}\n data-path={path}\n data-field-type={field.type}\n data-field-multiple-values={String(field.list)}\n data-field-renderer={String(field.renderer.name)}\n >\n {children}\n </hcms-field-validation>\n );\n };\n};\n"],"names":["createValidationContainer","path","children","field","useModelField","undefined","String"],"mappings":";;AAkBO,MAAMA,4BAA4B,CAACC,OAC/B,SAA6B,EAAEC,QAAQ,EAAiC;QAC3E,MAAM,EAAEC,KAAK,EAAE,GAAGC;QAElB,IAAID,AAAeE,WAAfF,MAAM,IAAI,EACVA,MAAM,IAAI,GAAG;QAGjB,OAAO,WAAP,GACI,oBAAC;YACG,OAAO;YACP,aAAWF;YACX,mBAAiBE,MAAM,IAAI;YAC3B,8BAA4BG,OAAOH,MAAM,IAAI;YAC7C,uBAAqBG,OAAOH,MAAM,QAAQ,CAAC,IAAI;WAE9CD;IAGb"}
|
package/createValidators.js
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
import { plugins } from "@webiny/plugins";
|
|
2
2
|
import camelCase from "lodash/camelCase.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* We need to set the validator name because it will be used as the reference to skip, if necessary.
|
|
45
|
-
*/
|
|
46
|
-
validator.validatorName = camelCase(validatorPlugin.validator.name);
|
|
47
|
-
collection.push(validator);
|
|
48
|
-
return collection;
|
|
49
|
-
}, []);
|
|
3
|
+
const createValidators = (field, validation)=>{
|
|
4
|
+
const validatorPlugins = plugins.byType("cms-model-field-validator");
|
|
5
|
+
return validation.reduce((collection, item)=>{
|
|
6
|
+
if ("function" == typeof item) return [
|
|
7
|
+
...collection,
|
|
8
|
+
item
|
|
9
|
+
];
|
|
10
|
+
const validatorPlugin = validatorPlugins.find((plugin)=>plugin.validator.name === item.name);
|
|
11
|
+
if (!validatorPlugin || "function" != typeof validatorPlugin.validator.validate) return collection;
|
|
12
|
+
const validator = async (value)=>{
|
|
13
|
+
let isInvalid;
|
|
14
|
+
let message = item.message;
|
|
15
|
+
try {
|
|
16
|
+
const result = await validatorPlugin.validator.validate(value, {
|
|
17
|
+
validator: item,
|
|
18
|
+
field
|
|
19
|
+
});
|
|
20
|
+
isInvalid = false === result;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
isInvalid = true;
|
|
23
|
+
if (e.message && !item.message) message = e.message;
|
|
24
|
+
}
|
|
25
|
+
if (isInvalid) {
|
|
26
|
+
let interpolated = message || "Invalid value.";
|
|
27
|
+
const getVariableValues = validatorPlugin.validator.getVariableValues;
|
|
28
|
+
if ("function" == typeof getVariableValues) {
|
|
29
|
+
const variables = getVariableValues({
|
|
30
|
+
validator: item
|
|
31
|
+
});
|
|
32
|
+
Object.keys(variables).forEach((key)=>{
|
|
33
|
+
const regex = new RegExp(`{${key}}`, "g");
|
|
34
|
+
interpolated = interpolated.replace(regex, variables[key]);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
throw new Error(interpolated);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
validator.validatorName = camelCase(validatorPlugin.validator.name);
|
|
41
|
+
collection.push(validator);
|
|
42
|
+
return collection;
|
|
43
|
+
}, []);
|
|
50
44
|
};
|
|
45
|
+
export { createValidators };
|
|
51
46
|
|
|
52
47
|
//# sourceMappingURL=createValidators.js.map
|
package/createValidators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createValidators.js","sources":["../src/createValidators.ts"],"sourcesContent":["import { plugins } from \"@webiny/plugins\";\nimport type {\n CmsModelField,\n CmsModelFieldValidator,\n CmsModelFieldValidatorPlugin\n} from \"~/types/index.js\";\nimport type { Validator } from \"@webiny/validation/types.js\";\nimport camelCase from \"lodash/camelCase.js\";\n\nexport const createValidators = (\n field: CmsModelField,\n validation: (CmsModelFieldValidator | Validator)[]\n): Validator[] => {\n const validatorPlugins = plugins.byType<CmsModelFieldValidatorPlugin>(\n \"cms-model-field-validator\"\n );\n\n return validation.reduce<Validator[]>((collection, item) => {\n if (typeof item === \"function\") {\n return [...collection, item];\n }\n\n const validatorPlugin = validatorPlugins.find(\n plugin => plugin.validator.name === item.name\n );\n\n if (!validatorPlugin || typeof validatorPlugin.validator.validate !== \"function\") {\n return collection;\n }\n\n const validator = async (value: any | any[]) => {\n let isInvalid;\n let message = item.message;\n try {\n const result = await validatorPlugin.validator.validate(value, {\n validator: item,\n field\n });\n\n isInvalid = result === false;\n } catch (e) {\n isInvalid = true;\n if (e.message && !item.message) {\n message = e.message;\n }\n }\n\n if (isInvalid) {\n let interpolated = message || \"Invalid value.\";\n\n const getVariableValues = validatorPlugin.validator.getVariableValues;\n if (typeof getVariableValues === \"function\") {\n const variables = getVariableValues({ validator: item });\n\n Object.keys(variables).forEach(key => {\n const regex = new RegExp(`{${key}}`, \"g\");\n interpolated = interpolated.replace(regex, variables[key]);\n });\n }\n\n throw new Error(interpolated);\n }\n };\n /**\n * We need to set the validator name because it will be used as the reference to skip, if necessary.\n */\n validator.validatorName = camelCase(validatorPlugin.validator.name);\n\n collection.push(validator);\n return collection;\n }, [] as Validator[]);\n};\n"],"names":["createValidators","field","validation","validatorPlugins","plugins","collection","item","validatorPlugin","plugin","validator","value","isInvalid","message","result","e","interpolated","getVariableValues","variables","Object","key","regex","RegExp","Error","camelCase"],"mappings":";;AASO,MAAMA,mBAAmB,CAC5BC,OACAC;IAEA,MAAMC,mBAAmBC,QAAQ,MAAM,CACnC;IAGJ,OAAOF,WAAW,MAAM,CAAc,CAACG,YAAYC;QAC/C,IAAI,AAAgB,cAAhB,OAAOA,MACP,OAAO;eAAID;YAAYC;SAAK;QAGhC,MAAMC,kBAAkBJ,iBAAiB,IAAI,CACzCK,CAAAA,SAAUA,OAAO,SAAS,CAAC,IAAI,KAAKF,KAAK,IAAI;QAGjD,IAAI,CAACC,mBAAmB,AAA8C,cAA9C,OAAOA,gBAAgB,SAAS,CAAC,QAAQ,EAC7D,OAAOF;QAGX,MAAMI,YAAY,OAAOC;YACrB,IAAIC;YACJ,IAAIC,UAAUN,KAAK,OAAO;YAC1B,IAAI;gBACA,MAAMO,SAAS,MAAMN,gBAAgB,SAAS,CAAC,QAAQ,CAACG,OAAO;oBAC3D,WAAWJ;oBACXL;gBACJ;gBAEAU,YAAYE,AAAW,UAAXA;YAChB,EAAE,OAAOC,GAAG;gBACRH,YAAY;gBACZ,IAAIG,EAAE,OAAO,IAAI,CAACR,KAAK,OAAO,EAC1BM,UAAUE,EAAE,OAAO;YAE3B;YAEA,IAAIH,WAAW;gBACX,IAAII,eAAeH,WAAW;gBAE9B,MAAMI,oBAAoBT,gBAAgB,SAAS,CAAC,iBAAiB;gBACrE,IAAI,AAA6B,cAA7B,OAAOS,mBAAkC;oBACzC,MAAMC,YAAYD,kBAAkB;wBAAE,WAAWV;oBAAK;oBAEtDY,OAAO,IAAI,CAACD,WAAW,OAAO,CAACE,CAAAA;wBAC3B,MAAMC,QAAQ,IAAIC,OAAO,CAAC,CAAC,EAAEF,IAAI,CAAC,CAAC,EAAE;wBACrCJ,eAAeA,aAAa,OAAO,CAACK,OAAOH,SAAS,CAACE,IAAI;oBAC7D;gBACJ;gBAEA,MAAM,IAAIG,MAAMP;YACpB;QACJ;QAIAN,UAAU,aAAa,GAAGc,UAAUhB,gBAAgB,SAAS,CAAC,IAAI;QAElEF,WAAW,IAAI,CAACI;QAChB,OAAOJ;IACX,GAAG,EAAE;AACT"}
|
package/entries.graphql.d.ts
CHANGED
|
@@ -165,6 +165,17 @@ export interface CmsEntryUpdateSingletonMutationVariables {
|
|
|
165
165
|
options?: FormValidationOptions;
|
|
166
166
|
}
|
|
167
167
|
export declare const createUpdateSingletonMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
168
|
+
export interface CmsEntryUpdateRevisionDescriptionMutationResponse {
|
|
169
|
+
content: {
|
|
170
|
+
data?: CmsContentEntry;
|
|
171
|
+
error?: CmsErrorResponse;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export interface CmsEntryUpdateRevisionDescriptionMutationVariables {
|
|
175
|
+
revision: string;
|
|
176
|
+
revisionDescription: string;
|
|
177
|
+
}
|
|
178
|
+
export declare const createUpdateRevisionDescriptionMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
|
|
168
179
|
/**
|
|
169
180
|
* ############################################
|
|
170
181
|
* Publish Mutation
|