@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.
Files changed (82) hide show
  1. package/Fields/ErrorBoundary.js +29 -34
  2. package/Fields/ErrorBoundary.js.map +1 -1
  3. package/Fields/FieldElement.js +38 -61
  4. package/Fields/FieldElement.js.map +1 -1
  5. package/Fields/FieldElementError.js +13 -22
  6. package/Fields/FieldElementError.js.map +1 -1
  7. package/Fields/FieldRulesProvider.js +11 -17
  8. package/Fields/FieldRulesProvider.js.map +1 -1
  9. package/Fields/Fields.js +76 -139
  10. package/Fields/Fields.js.map +1 -1
  11. package/Fields/Label.js +7 -7
  12. package/Fields/Label.js.map +1 -1
  13. package/Fields/LayoutDescriptorCell.js +33 -40
  14. package/Fields/LayoutDescriptorCell.js.map +1 -1
  15. package/Fields/evaluateExpression.js +54 -94
  16. package/Fields/evaluateExpression.js.map +1 -1
  17. package/Fields/fieldOptions.js +56 -104
  18. package/Fields/fieldOptions.js.map +1 -1
  19. package/Fields/index.js +0 -2
  20. package/Fields/layoutFieldRenderers/AlertFieldRenderer.js +7 -10
  21. package/Fields/layoutFieldRenderers/AlertFieldRenderer.js.map +1 -1
  22. package/Fields/layoutFieldRenderers/SeparatorFieldRenderer.js +12 -15
  23. package/Fields/layoutFieldRenderers/SeparatorFieldRenderer.js.map +1 -1
  24. package/Fields/layoutFieldRenderers/TabsFieldRenderer.js +52 -63
  25. package/Fields/layoutFieldRenderers/TabsFieldRenderer.js.map +1 -1
  26. package/Fields/operatorOptions.js +115 -87
  27. package/Fields/operatorOptions.js.map +1 -1
  28. package/Fields/useBind.js +101 -107
  29. package/Fields/useBind.js.map +1 -1
  30. package/Fields/useFieldRules.js +79 -133
  31. package/Fields/useFieldRules.js.map +1 -1
  32. package/Fields/useRenderPlugins.js +3 -2
  33. package/Fields/useRenderPlugins.js.map +1 -1
  34. package/ModelFieldProvider/CanEditField.js +6 -9
  35. package/ModelFieldProvider/CanEditField.js.map +1 -1
  36. package/ModelFieldProvider/ModelFieldContext.js +15 -22
  37. package/ModelFieldProvider/ModelFieldContext.js.map +1 -1
  38. package/ModelFieldProvider/index.js +0 -2
  39. package/ModelFieldProvider/useModelField.js +15 -21
  40. package/ModelFieldProvider/useModelField.js.map +1 -1
  41. package/ModelProvider/ModelContext.js +11 -15
  42. package/ModelProvider/ModelContext.js.map +1 -1
  43. package/ModelProvider/index.js +0 -2
  44. package/ModelProvider/useModel.js +7 -11
  45. package/ModelProvider/useModel.js.map +1 -1
  46. package/constants.js +2 -1
  47. package/constants.js.map +1 -1
  48. package/createFieldsList.js +27 -49
  49. package/createFieldsList.js.map +1 -1
  50. package/createValidationContainer.js +13 -20
  51. package/createValidationContainer.js.map +1 -1
  52. package/createValidators.js +42 -47
  53. package/createValidators.js.map +1 -1
  54. package/entries.graphql.d.ts +11 -0
  55. package/entries.graphql.js +74 -164
  56. package/entries.graphql.js.map +1 -1
  57. package/exports/admin/cms/model.js +0 -2
  58. package/exports/admin/cms.d.ts +1 -1
  59. package/exports/admin/cms.js +0 -3
  60. package/getModelTitleFieldId.js +4 -5
  61. package/getModelTitleFieldId.js.map +1 -1
  62. package/index.js +0 -2
  63. package/normalizeIcon.js +8 -7
  64. package/normalizeIcon.js.map +1 -1
  65. package/package.json +11 -13
  66. package/prepareFormData.js +39 -61
  67. package/prepareFormData.js.map +1 -1
  68. package/types/index.d.ts +2 -0
  69. package/types/index.js +1 -41
  70. package/types/model.js +4 -27
  71. package/types/model.js.map +1 -1
  72. package/types/shared.js +0 -3
  73. package/types/validation.js +0 -3
  74. package/Fields/index.js.map +0 -1
  75. package/ModelFieldProvider/index.js.map +0 -1
  76. package/ModelProvider/index.js.map +0 -1
  77. package/exports/admin/cms/model.js.map +0 -1
  78. package/exports/admin/cms.js.map +0 -1
  79. package/index.js.map +0 -1
  80. package/types/index.js.map +0 -1
  81. package/types/shared.js.map +0 -1
  82. package/types/validation.js.map +0 -1
@@ -1,26 +1,19 @@
1
- import React from "react";
1
+ import react from "react";
2
2
  import { createGenericContext } from "@webiny/app-admin";
3
- export const ModelFieldContext = /*#__PURE__*/React.createContext(undefined);
4
- export const ModelFieldProvider = ({
5
- field,
6
- children
7
- }) => {
8
- return /*#__PURE__*/React.createElement(ModelFieldContext.Provider, {
9
- value: field
10
- }, children);
11
- };
12
- const {
13
- Provider,
14
- useHook
15
- } = createGenericContext("FieldIndex");
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,"names":["React","createGenericContext","ModelFieldContext","createContext","undefined","ModelFieldProvider","field","children","createElement","Provider","value","useHook","ParentValueIndexProvider","useParentValueIndex","context","index"],"sources":["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"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,oBAAoB,QAAQ,mBAAmB;AAIxD,OAAO,MAAMC,iBAAiB,gBAAGF,KAAK,CAACG,aAAa,CAAgCC,SAAS,CAAC;AAO9F,OAAO,MAAMC,kBAAkB,GAAGA,CAAC;EAAEC,KAAK;EAAEC;AAAkC,CAAC,KAAK;EAChF,oBAAOP,KAAA,CAAAQ,aAAA,CAACN,iBAAiB,CAACO,QAAQ;IAACC,KAAK,EAAEJ;EAAM,GAAEC,QAAqC,CAAC;AAC5F,CAAC;AAED,MAAM;EAAEE,QAAQ;EAAEE;AAAQ,CAAC,GAAGV,oBAAoB,CAAoB,YAAY,CAAC;AAEnF,OAAO,MAAMW,wBAAwB,GAAGH,QAAQ;AAEhD,OAAO,MAAMI,mBAAmB,GAAGA,CAAA,KAAM;EACrC,IAAI;IACA,MAAMC,OAAO,GAAGH,OAAO,CAAC,CAAC;IACzB,OAAOG,OAAO,CAACC,KAAK;EACxB,CAAC,CAAC,MAAM;IACJ,OAAO,CAAC,CAAC;EACb;AACJ,CAAC","ignoreList":[]}
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"}
@@ -1,5 +1,3 @@
1
1
  export * from "./ModelFieldContext.js";
2
2
  export * from "./useModelField.js";
3
3
  export * from "./CanEditField.js";
4
-
5
- //# sourceMappingURL=index.js.map
@@ -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
- const plugin = plugins.byType("cms-editor-field-type").find(plugin => plugin.field.type === type);
7
- if (!plugin) {
8
- throw Error(`Missing plugin for field type "${type}"!`);
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
- * Get model field from the current context.
14
- */
15
- export const useModelField = makeDecoratable(() => {
16
- const field = useContext(ModelFieldContext);
17
- if (!field) {
18
- throw Error(`Missing "ModelFieldProvider" in the component tree. Are you using the "useModelField()" hook in the right place?`);
19
- }
20
- const parentValueIndex = useParentValueIndex();
21
- const fieldPlugin = getFieldPlugin(field.type);
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,"names":["useContext","plugins","makeDecoratable","ModelFieldContext","useParentValueIndex","getFieldPlugin","type","plugin","byType","find","field","Error","useModelField","parentValueIndex","fieldPlugin"],"sources":["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"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,OAAO,QAAQ,iBAAiB;AACzC,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,iBAAiB,EAAEC,mBAAmB;AAO/C,MAAMC,cAA8B,GAAGC,IAAI,IAAI;EAC3C,MAAMC,MAAM,GAAGN,OAAO,CACjBO,MAAM,CAA0B,uBAAuB,CAAC,CACxDC,IAAI,CAACF,MAAM,IAAIA,MAAM,CAACG,KAAK,CAACJ,IAAI,KAAKA,IAAI,CAAC;EAE/C,IAAI,CAACC,MAAM,EAAE;IACT,MAAMI,KAAK,CAAC,kCAAkCL,IAAI,IAAI,CAAC;EAC3D;EAEA,OAAOC,MAAM;AACjB,CAAC;AAQD;AACA;AACA;AACA,OAAO,MAAMK,aAAa,GAAGV,eAAe,CAAC,MAAqB;EAC9D,MAAMQ,KAAK,GAAGV,UAAU,CAACG,iBAAiB,CAAC;EAE3C,IAAI,CAACO,KAAK,EAAE;IACR,MAAMC,KAAK,CACP,kHACJ,CAAC;EACL;EAEA,MAAME,gBAAgB,GAAGT,mBAAmB,CAAC,CAAC;EAE9C,MAAMU,WAAW,GAAGT,cAAc,CAACK,KAAK,CAACJ,IAAI,CAAC;EAE9C,OAAO;IAAEI,KAAK;IAAEI,WAAW;IAAED;EAAiB,CAAC;AACnD,CAAC,CAAC","ignoreList":[]}
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 React from "react";
1
+ import react from "react";
2
2
  import { DevToolsSection } from "@webiny/app-admin";
3
- export const ModelContext = /*#__PURE__*/React.createContext(undefined);
4
- export const ModelProvider = ({
5
- model,
6
- children
7
- }) => {
8
- return /*#__PURE__*/React.createElement(ModelContext.Provider, {
9
- value: model
10
- }, /*#__PURE__*/React.createElement(DevToolsSection, {
11
- name: "Model",
12
- group: "CMS",
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,"names":["React","DevToolsSection","ModelContext","createContext","undefined","ModelProvider","model","children","createElement","Provider","value","name","group","data","views"],"sources":["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"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,eAAe,QAAQ,mBAAmB;AAKnD,OAAO,MAAMC,YAAY,gBAAGF,KAAK,CAACG,aAAa,CAA2BC,SAAS,CAAC;AAOpF,OAAO,MAAMC,aAAa,GAAGA,CAAC;EAAEC,KAAK;EAAEC;AAA6B,CAAC,KAAK;EACtE,oBACIP,KAAA,CAAAQ,aAAA,CAACN,YAAY,CAACO,QAAQ;IAACC,KAAK,EAAEJ;EAAM,gBAChCN,KAAA,CAAAQ,aAAA,CAACP,eAAe;IAACU,IAAI,EAAE,OAAQ;IAACC,KAAK,EAAC,KAAK;IAACC,IAAI,EAAEP,KAAM;IAACQ,KAAK,EAAE;EAAM,CAAE,CAAC,EACxEP,QACkB,CAAC;AAEhC,CAAC","ignoreList":[]}
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"}
@@ -1,4 +1,2 @@
1
1
  export * from "./ModelContext.js";
2
2
  export * from "./useModel.js";
3
-
4
- //# sourceMappingURL=index.js.map
@@ -1,16 +1,12 @@
1
1
  import { useContext } from "react";
2
2
  import { ModelContext } from "./ModelContext.js";
3
- /**
4
- * Get model from the current context.
5
- */
6
- export function useModel() {
7
- const model = useContext(ModelContext);
8
- if (!model) {
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,"names":["useContext","ModelContext","useModel","model","Error"],"sources":["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"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,YAAY;AAOrB;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAA,EAAuB;EAC3C,MAAMC,KAAK,GAAGH,UAAU,CAACC,YAAY,CAAC;EACtC,IAAI,CAACE,KAAK,EAAE;IACR,MAAMC,KAAK,CACP,uGACJ,CAAC;EACL;EAEA,OAAO;IAAED;EAAM,CAAC;AACpB","ignoreList":[]}
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
@@ -1,3 +1,4 @@
1
- export const CMS_MODEL_SINGLETON_TAG = "singleEntry";
1
+ const CMS_MODEL_SINGLETON_TAG = "singleEntry";
2
+ export { CMS_MODEL_SINGLETON_TAG };
2
3
 
3
4
  //# sourceMappingURL=constants.js.map
package/constants.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["CMS_MODEL_SINGLETON_TAG"],"sources":["constants.ts"],"sourcesContent":["export const CMS_MODEL_SINGLETON_TAG = \"singleEntry\";\n"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB,GAAG,aAAa","ignoreList":[]}
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"}
@@ -1,53 +1,31 @@
1
1
  import { plugins } from "@webiny/plugins";
2
- /**
3
- * When used in ACO, this method receives a filtered list of field types.
4
- * Find `createListRecords` in app-aco to find out more.
5
- */
6
- export function createFieldsList({
7
- model,
8
- fields: inputFields,
9
- graphQLTypePrefix
10
- }) {
11
- const fieldPlugins = plugins.byType("cms-editor-field-type").reduce((acc, item) => ({
12
- ...acc,
13
- [item.field.type]: item.field
14
- }), {});
15
- const typePrefix = graphQLTypePrefix ?? model.singularApiName;
16
- const fields = inputFields.map(field => {
17
- if (!fieldPlugins[field.type]) {
18
- console.log(`Unknown field plugin for field type "${field.type}".`);
19
- return null;
20
- }
21
- const {
22
- graphql
23
- } = fieldPlugins[field.type];
24
- if (graphql && graphql.queryField) {
25
- const {
26
- queryField
27
- } = graphql;
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
@@ -1 +1 @@
1
- {"version":3,"names":["plugins","createFieldsList","model","fields","inputFields","graphQLTypePrefix","fieldPlugins","byType","reduce","acc","item","field","type","typePrefix","singularApiName","map","console","log","graphql","queryField","selection","fieldId","filter","Boolean","length","push","join"],"sources":["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"],"mappings":"AACA,SAASA,OAAO,QAAQ,iBAAiB;AAQzC;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAC;EAC7BC,KAAK;EACLC,MAAM,EAAEC,WAAW;EACnBC;AACoB,CAAC,EAAU;EAC/B,MAAMC,YAA8D,GAAGN,OAAO,CACzEO,MAAM,CAA0B,uBAAuB,CAAC,CACxDC,MAAM,CAAC,CAACC,GAAG,EAAEC,IAAI,MAAM;IAAE,GAAGD,GAAG;IAAE,CAACC,IAAI,CAACC,KAAK,CAACC,IAAI,GAAGF,IAAI,CAACC;EAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAE3E,MAAME,UAAU,GAAGR,iBAAiB,IAAIH,KAAK,CAACY,eAAe;EAE7D,MAAMX,MAAM,GAAGC,WAAW,CACrBW,GAAG,CAACJ,KAAK,IAAI;IACV,IAAI,CAACL,YAAY,CAACK,KAAK,CAACC,IAAI,CAAC,EAAE;MAC3BI,OAAO,CAACC,GAAG,CAAC,wCAAwCN,KAAK,CAACC,IAAI,IAAI,CAAC;MACnE,OAAO,IAAI;IACf;IACA,MAAM;MAAEM;IAAQ,CAAC,GAAGZ,YAAY,CAACK,KAAK,CAACC,IAAI,CAAC;IAE5C,IAAIM,OAAO,IAAIA,OAAO,CAACC,UAAU,EAAE;MAC/B,MAAM;QAAEA;MAAW,CAAC,GAAGD,OAAO;MAC9B,MAAME,SAAS,GACX,OAAOD,UAAU,KAAK,QAAQ,GACxBA,UAAU,GACVA,UAAU,CAAC;QAAEjB,KAAK;QAAES,KAAK;QAAEN,iBAAiB,EAAEQ;MAAW,CAAC,CAAC;;MAErE;AAChB;AACA;MACgB,IAAIO,SAAS,KAAK,IAAI,EAAE;QACpB,OAAO,IAAI;MACf;MAEA,OAAO,GAAGT,KAAK,CAACU,OAAO,IAAID,SAAS,EAAE;IAC1C;IAEA,OAAOT,KAAK,CAACU,OAAO;EACxB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACpB;AACJ;AACA;EACI,IAAIpB,MAAM,CAACqB,MAAM,KAAK,CAAC,EAAE;IACrBrB,MAAM,CAACsB,IAAI,CAAC,QAAQ,CAAC;EACzB;EACA,OAAOtB,MAAM,CAACuB,IAAI,CAAC,IAAI,CAAC;AAC5B","ignoreList":[]}
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 React from "react";
1
+ import react from "react";
2
2
  import { useModelField } from "./ModelFieldProvider/index.js";
3
- export const createValidationContainer = path => {
4
- return function ValidationContainer({
5
- children
6
- }) {
7
- const {
8
- field
9
- } = useModelField();
10
- if (field.list === undefined) {
11
- field.list = false;
12
- }
13
- return /*#__PURE__*/React.createElement("hcms-field-validation", {
14
- class: "block",
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,"names":["React","useModelField","createValidationContainer","path","ValidationContainer","children","field","list","undefined","createElement","class","type","String","renderer","name"],"sources":["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"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,aAAa;AAiBtB,OAAO,MAAMC,yBAAyB,GAAIC,IAAY,IAAK;EACvD,OAAO,SAASC,mBAAmBA,CAAC;IAAEC;EAAwC,CAAC,EAAE;IAC7E,MAAM;MAAEC;IAAM,CAAC,GAAGL,aAAa,CAAC,CAAC;IAEjC,IAAIK,KAAK,CAACC,IAAI,KAAKC,SAAS,EAAE;MAC1BF,KAAK,CAACC,IAAI,GAAG,KAAK;IACtB;IAEA,oBACIP,KAAA,CAAAS,aAAA;MACIC,KAAK,EAAE,OAAQ;MACf,aAAWP,IAAK;MAChB,mBAAiBG,KAAK,CAACK,IAAK;MAC5B,8BAA4BC,MAAM,CAACN,KAAK,CAACC,IAAI,CAAE;MAC/C,uBAAqBK,MAAM,CAACN,KAAK,CAACO,QAAQ,CAACC,IAAI;IAAE,GAEhDT,QACkB,CAAC;EAEhC,CAAC;AACL,CAAC","ignoreList":[]}
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"}
@@ -1,52 +1,47 @@
1
1
  import { plugins } from "@webiny/plugins";
2
2
  import camelCase from "lodash/camelCase.js";
3
- export const createValidators = (field, validation) => {
4
- const validatorPlugins = plugins.byType("cms-model-field-validator");
5
- return validation.reduce((collection, item) => {
6
- if (typeof item === "function") {
7
- return [...collection, item];
8
- }
9
- const validatorPlugin = validatorPlugins.find(plugin => plugin.validator.name === item.name);
10
- if (!validatorPlugin || typeof validatorPlugin.validator.validate !== "function") {
11
- return collection;
12
- }
13
- const validator = async value => {
14
- let isInvalid;
15
- let message = item.message;
16
- try {
17
- const result = await validatorPlugin.validator.validate(value, {
18
- validator: item,
19
- field
20
- });
21
- isInvalid = result === false;
22
- } catch (e) {
23
- isInvalid = true;
24
- if (e.message && !item.message) {
25
- message = e.message;
26
- }
27
- }
28
- if (isInvalid) {
29
- let interpolated = message || "Invalid value.";
30
- const getVariableValues = validatorPlugin.validator.getVariableValues;
31
- if (typeof getVariableValues === "function") {
32
- const variables = getVariableValues({
33
- validator: item
34
- });
35
- Object.keys(variables).forEach(key => {
36
- const regex = new RegExp(`{${key}}`, "g");
37
- interpolated = interpolated.replace(regex, variables[key]);
38
- });
39
- }
40
- throw new Error(interpolated);
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
@@ -1 +1 @@
1
- {"version":3,"names":["plugins","camelCase","createValidators","field","validation","validatorPlugins","byType","reduce","collection","item","validatorPlugin","find","plugin","validator","name","validate","value","isInvalid","message","result","e","interpolated","getVariableValues","variables","Object","keys","forEach","key","regex","RegExp","replace","Error","validatorName","push"],"sources":["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"],"mappings":"AAAA,SAASA,OAAO,QAAQ,iBAAiB;AAOzC,OAAOC,SAAS,MAAM,qBAAqB;AAE3C,OAAO,MAAMC,gBAAgB,GAAGA,CAC5BC,KAAoB,EACpBC,UAAkD,KACpC;EACd,MAAMC,gBAAgB,GAAGL,OAAO,CAACM,MAAM,CACnC,2BACJ,CAAC;EAED,OAAOF,UAAU,CAACG,MAAM,CAAc,CAACC,UAAU,EAAEC,IAAI,KAAK;IACxD,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;MAC5B,OAAO,CAAC,GAAGD,UAAU,EAAEC,IAAI,CAAC;IAChC;IAEA,MAAMC,eAAe,GAAGL,gBAAgB,CAACM,IAAI,CACzCC,MAAM,IAAIA,MAAM,CAACC,SAAS,CAACC,IAAI,KAAKL,IAAI,CAACK,IAC7C,CAAC;IAED,IAAI,CAACJ,eAAe,IAAI,OAAOA,eAAe,CAACG,SAAS,CAACE,QAAQ,KAAK,UAAU,EAAE;MAC9E,OAAOP,UAAU;IACrB;IAEA,MAAMK,SAAS,GAAG,MAAOG,KAAkB,IAAK;MAC5C,IAAIC,SAAS;MACb,IAAIC,OAAO,GAAGT,IAAI,CAACS,OAAO;MAC1B,IAAI;QACA,MAAMC,MAAM,GAAG,MAAMT,eAAe,CAACG,SAAS,CAACE,QAAQ,CAACC,KAAK,EAAE;UAC3DH,SAAS,EAAEJ,IAAI;UACfN;QACJ,CAAC,CAAC;QAEFc,SAAS,GAAGE,MAAM,KAAK,KAAK;MAChC,CAAC,CAAC,OAAOC,CAAC,EAAE;QACRH,SAAS,GAAG,IAAI;QAChB,IAAIG,CAAC,CAACF,OAAO,IAAI,CAACT,IAAI,CAACS,OAAO,EAAE;UAC5BA,OAAO,GAAGE,CAAC,CAACF,OAAO;QACvB;MACJ;MAEA,IAAID,SAAS,EAAE;QACX,IAAII,YAAY,GAAGH,OAAO,IAAI,gBAAgB;QAE9C,MAAMI,iBAAiB,GAAGZ,eAAe,CAACG,SAAS,CAACS,iBAAiB;QACrE,IAAI,OAAOA,iBAAiB,KAAK,UAAU,EAAE;UACzC,MAAMC,SAAS,GAAGD,iBAAiB,CAAC;YAAET,SAAS,EAAEJ;UAAK,CAAC,CAAC;UAExDe,MAAM,CAACC,IAAI,CAACF,SAAS,CAAC,CAACG,OAAO,CAACC,GAAG,IAAI;YAClC,MAAMC,KAAK,GAAG,IAAIC,MAAM,CAAC,IAAIF,GAAG,GAAG,EAAE,GAAG,CAAC;YACzCN,YAAY,GAAGA,YAAY,CAACS,OAAO,CAACF,KAAK,EAAEL,SAAS,CAACI,GAAG,CAAC,CAAC;UAC9D,CAAC,CAAC;QACN;QAEA,MAAM,IAAII,KAAK,CAACV,YAAY,CAAC;MACjC;IACJ,CAAC;IACD;AACR;AACA;IACQR,SAAS,CAACmB,aAAa,GAAG/B,SAAS,CAACS,eAAe,CAACG,SAAS,CAACC,IAAI,CAAC;IAEnEN,UAAU,CAACyB,IAAI,CAACpB,SAAS,CAAC;IAC1B,OAAOL,UAAU;EACrB,CAAC,EAAE,EAAiB,CAAC;AACzB,CAAC","ignoreList":[]}
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"}
@@ -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