@webiny/app-headless-cms-common 0.0.0-unstable.06b2ede40f

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 (81) hide show
  1. package/Fields/ErrorBoundary.d.ts +24 -0
  2. package/Fields/ErrorBoundary.js +40 -0
  3. package/Fields/ErrorBoundary.js.map +1 -0
  4. package/Fields/FieldElement.d.ts +64 -0
  5. package/Fields/FieldElement.js +71 -0
  6. package/Fields/FieldElement.js.map +1 -0
  7. package/Fields/FieldElementError.d.ts +7 -0
  8. package/Fields/FieldElementError.js +26 -0
  9. package/Fields/FieldElementError.js.map +1 -0
  10. package/Fields/Fields.d.ts +11 -0
  11. package/Fields/Fields.js +35 -0
  12. package/Fields/Fields.js.map +1 -0
  13. package/Fields/Label.d.ts +6 -0
  14. package/Fields/Label.js +10 -0
  15. package/Fields/Label.js.map +1 -0
  16. package/Fields/index.d.ts +3 -0
  17. package/Fields/index.js +5 -0
  18. package/Fields/index.js.map +1 -0
  19. package/Fields/useBind.d.ts +9 -0
  20. package/Fields/useBind.js +113 -0
  21. package/Fields/useBind.js.map +1 -0
  22. package/Fields/useRenderPlugins.d.ts +1 -0
  23. package/Fields/useRenderPlugins.js +7 -0
  24. package/Fields/useRenderPlugins.js.map +1 -0
  25. package/LICENSE +21 -0
  26. package/ModelFieldProvider/ModelFieldContext.d.ts +36 -0
  27. package/ModelFieldProvider/ModelFieldContext.js +26 -0
  28. package/ModelFieldProvider/ModelFieldContext.js.map +1 -0
  29. package/ModelFieldProvider/index.d.ts +2 -0
  30. package/ModelFieldProvider/index.js +4 -0
  31. package/ModelFieldProvider/index.js.map +1 -0
  32. package/ModelFieldProvider/useModelField.d.ts +16 -0
  33. package/ModelFieldProvider/useModelField.js +29 -0
  34. package/ModelFieldProvider/useModelField.js.map +1 -0
  35. package/ModelProvider/ModelContext.d.ts +9 -0
  36. package/ModelProvider/ModelContext.js +12 -0
  37. package/ModelProvider/ModelContext.js.map +1 -0
  38. package/ModelProvider/index.d.ts +2 -0
  39. package/ModelProvider/index.js +4 -0
  40. package/ModelProvider/index.js.map +1 -0
  41. package/ModelProvider/useModel.d.ts +9 -0
  42. package/ModelProvider/useModel.js +16 -0
  43. package/ModelProvider/useModel.js.map +1 -0
  44. package/README.md +18 -0
  45. package/constants.d.ts +1 -0
  46. package/constants.js +3 -0
  47. package/constants.js.map +1 -0
  48. package/createFieldsList.d.ts +8 -0
  49. package/createFieldsList.js +49 -0
  50. package/createFieldsList.js.map +1 -0
  51. package/createValidationContainer.d.ts +18 -0
  52. package/createValidationContainer.js +26 -0
  53. package/createValidationContainer.js.map +1 -0
  54. package/createValidators.d.ts +3 -0
  55. package/createValidators.js +52 -0
  56. package/createValidators.js.map +1 -0
  57. package/entries.graphql.d.ts +218 -0
  58. package/entries.graphql.js +402 -0
  59. package/entries.graphql.js.map +1 -0
  60. package/getModelTitleFieldId.d.ts +2 -0
  61. package/getModelTitleFieldId.js +8 -0
  62. package/getModelTitleFieldId.js.map +1 -0
  63. package/index.d.ts +10 -0
  64. package/index.js +12 -0
  65. package/index.js.map +1 -0
  66. package/package.json +52 -0
  67. package/prepareFormData.d.ts +2 -0
  68. package/prepareFormData.js +71 -0
  69. package/prepareFormData.js.map +1 -0
  70. package/types/index.d.ts +567 -0
  71. package/types/index.js +56 -0
  72. package/types/index.js.map +1 -0
  73. package/types/model.d.ts +100 -0
  74. package/types/model.js +3 -0
  75. package/types/model.js.map +1 -0
  76. package/types/shared.d.ts +5 -0
  77. package/types/shared.js +3 -0
  78. package/types/shared.js.map +1 -0
  79. package/types/validation.d.ts +79 -0
  80. package/types/validation.js +3 -0
  81. package/types/validation.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelFieldContext\";\nexport * from \"./useModelField\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import type { CmsModelField, CmsModelFieldTypePlugin } from "../types";
3
+ export interface UseModelField {
4
+ field: CmsModelField;
5
+ parentValueIndex: number;
6
+ fieldPlugin: CmsModelFieldTypePlugin;
7
+ }
8
+ /**
9
+ * Get model field from the current context.
10
+ */
11
+ export declare const useModelField: import("@webiny/react-composition").GenericHook<unknown, UseModelField> & {
12
+ original: import("@webiny/react-composition").GenericHook<unknown, UseModelField>;
13
+ originalName: string;
14
+ } & {
15
+ createDecorator: (decorator: import("@webiny/react-composition").Decorator<() => UseModelField>) => () => import("react").JSX.Element;
16
+ };
@@ -0,0 +1,29 @@
1
+ import { useContext } from "react";
2
+ import { plugins } from "@webiny/plugins";
3
+ import { makeDecoratable } from "@webiny/react-composition";
4
+ import { ModelFieldContext, useParentValueIndex } from "./ModelFieldContext";
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;
11
+ };
12
+ /**
13
+ * Get model field from the current context.
14
+ */
15
+ export const useModelField = makeDecoratable(() => {
16
+ const field = useContext(ModelFieldContext);
17
+ const parentValueIndex = useParentValueIndex();
18
+ if (!field) {
19
+ throw Error(`Missing "ModelFieldProvider" in the component tree. Are you using the "useModelField()" hook in the right place?`);
20
+ }
21
+ const fieldPlugin = getFieldPlugin(field.type);
22
+ return {
23
+ field,
24
+ fieldPlugin,
25
+ parentValueIndex
26
+ };
27
+ });
28
+
29
+ //# sourceMappingURL=useModelField.js.map
@@ -0,0 +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\";\nimport type { CmsModelField, CmsModelFieldTypePlugin } from \"~/types\";\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 const parentValueIndex = useParentValueIndex();\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 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;EAC3C,MAAMU,gBAAgB,GAAGT,mBAAmB,CAAC,CAAC;EAE9C,IAAI,CAACM,KAAK,EAAE;IACR,MAAMC,KAAK,CACP,kHACJ,CAAC;EACL;EAEA,MAAMG,WAAW,GAAGT,cAAc,CAACK,KAAK,CAACJ,IAAI,CAAC;EAE9C,OAAO;IAAEI,KAAK;IAAEI,WAAW;IAAED;EAAiB,CAAC;AACnD,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import type { CmsModel } from "../types";
3
+ export type ModelContext = CmsModel;
4
+ export declare const ModelContext: React.Context<CmsModel | undefined>;
5
+ export interface ModelProviderProps {
6
+ model: CmsModel;
7
+ children: React.ReactNode;
8
+ }
9
+ export declare const ModelProvider: ({ model, children }: ModelProviderProps) => React.JSX.Element;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ export const ModelContext = /*#__PURE__*/React.createContext(undefined);
3
+ export const ModelProvider = ({
4
+ model,
5
+ children
6
+ }) => {
7
+ return /*#__PURE__*/React.createElement(ModelContext.Provider, {
8
+ value: model
9
+ }, children);
10
+ };
11
+
12
+ //# sourceMappingURL=ModelContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","ModelContext","createContext","undefined","ModelProvider","model","children","createElement","Provider","value"],"sources":["ModelContext.tsx"],"sourcesContent":["import React from \"react\";\nimport type { CmsModel } from \"~/types\";\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 <ModelContext.Provider value={model}>{children}</ModelContext.Provider>;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAKzB,OAAO,MAAMC,YAAY,gBAAGD,KAAK,CAACE,aAAa,CAA2BC,SAAS,CAAC;AAOpF,OAAO,MAAMC,aAAa,GAAGA,CAAC;EAAEC,KAAK;EAAEC;AAA6B,CAAC,KAAK;EACtE,oBAAON,KAAA,CAAAO,aAAA,CAACN,YAAY,CAACO,QAAQ;IAACC,KAAK,EAAEJ;EAAM,GAAEC,QAAgC,CAAC;AAClF,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./ModelContext";
2
+ export * from "./useModel";
@@ -0,0 +1,4 @@
1
+ export * from "./ModelContext";
2
+ export * from "./useModel";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelContext\";\nexport * from \"./useModel\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { CmsModel } from "../types";
2
+ type UseModelReturnType = {
3
+ model: CmsModel;
4
+ };
5
+ /**
6
+ * Get model from the current context.
7
+ */
8
+ export declare function useModel(): UseModelReturnType;
9
+ export {};
@@ -0,0 +1,16 @@
1
+ import { useContext } from "react";
2
+ import { ModelContext } from "./ModelContext";
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
+ };
14
+ }
15
+
16
+ //# sourceMappingURL=useModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useContext","ModelContext","useModel","model","Error"],"sources":["useModel.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ModelContext } from \"./ModelContext\";\nimport type { CmsModel } from \"~/types\";\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":[]}
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @webiny/app-headless-cms-common
2
+
3
+ [![](https://img.shields.io/npm/dw/@webiny/app-headless-cms-common.svg)](https://www.npmjs.com/package/@webiny/app-headless-cms-common)
4
+ [![](https://img.shields.io/npm/v/@webiny/app-headless-cms-common.svg)](https://www.npmjs.com/package/@webiny/app-headless-cms-common)
5
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
+
8
+ ## Install
9
+
10
+ ```
11
+ npm install --save @webiny/app-headless-cms-common
12
+ ```
13
+
14
+ Or if you prefer yarn:
15
+
16
+ ```
17
+ yarn add @webiny/app-headless-cms-common
18
+ ```
package/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const CMS_MODEL_SINGLETON_TAG = "singleton";
package/constants.js ADDED
@@ -0,0 +1,3 @@
1
+ export const CMS_MODEL_SINGLETON_TAG = "singleton";
2
+
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CMS_MODEL_SINGLETON_TAG"],"sources":["constants.ts"],"sourcesContent":["export const CMS_MODEL_SINGLETON_TAG = \"singleton\";\n"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB,GAAG,WAAW","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import type { CmsModel, CmsModelField } from "./types";
2
+ interface CreateFieldsListParams {
3
+ model: CmsModel;
4
+ fields: CmsModelField[];
5
+ graphQLTypePrefix?: string;
6
+ }
7
+ export declare function createFieldsList({ model, fields: inputFields, graphQLTypePrefix }: CreateFieldsListParams): string;
8
+ export {};
@@ -0,0 +1,49 @@
1
+ import { plugins } from "@webiny/plugins";
2
+ export function createFieldsList({
3
+ model,
4
+ fields: inputFields,
5
+ graphQLTypePrefix
6
+ }) {
7
+ const fieldPlugins = plugins.byType("cms-editor-field-type").reduce((acc, item) => ({
8
+ ...acc,
9
+ [item.field.type]: item.field
10
+ }), {});
11
+ const typePrefix = graphQLTypePrefix ?? model.singularApiName;
12
+ const fields = inputFields.map(field => {
13
+ if (!fieldPlugins[field.type]) {
14
+ console.log(`Unknown field plugin for field type "${field.type}".`);
15
+ return null;
16
+ }
17
+ const {
18
+ graphql
19
+ } = fieldPlugins[field.type];
20
+ if (graphql && graphql.queryField) {
21
+ const {
22
+ queryField
23
+ } = graphql;
24
+ const selection = typeof queryField === "string" ? queryField : queryField({
25
+ model,
26
+ field,
27
+ graphQLTypePrefix: typePrefix
28
+ });
29
+
30
+ /**
31
+ * If field type plugin returns `null`, we don't include the field in the selection.
32
+ */
33
+ if (selection === null) {
34
+ return null;
35
+ }
36
+ return `${field.fieldId} ${selection}`;
37
+ }
38
+ return field.fieldId;
39
+ }).filter(Boolean);
40
+ /**
41
+ * If there are no fields, let's always load the `_empty` field.
42
+ */
43
+ if (fields.length === 0) {
44
+ fields.push("_empty");
45
+ }
46
+ return fields.join("\n");
47
+ }
48
+
49
+ //# sourceMappingURL=createFieldsList.js.map
@@ -0,0 +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\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface CreateFieldsListParams {\n model: CmsModel;\n fields: CmsModelField[];\n graphQLTypePrefix?: string;\n}\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,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":[]}
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicElements {
5
+ "hcms-field-validation": {
6
+ "data-path": string;
7
+ "data-field-type": string;
8
+ "data-field-multiple-values": string;
9
+ "data-field-renderer": string;
10
+ style: React.CSSProperties;
11
+ children: React.ReactNode;
12
+ };
13
+ }
14
+ }
15
+ }
16
+ export declare const createValidationContainer: (path: string) => ({ children }: {
17
+ children: React.ReactNode;
18
+ }) => React.JSX.Element;
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { useModelField } from "./ModelFieldProvider";
3
+ const ValidationContainerStyles = {
4
+ display: "inherit"
5
+ };
6
+ export const createValidationContainer = path => {
7
+ return function ValidationContainer({
8
+ children
9
+ }) {
10
+ const {
11
+ field
12
+ } = useModelField();
13
+ if (field.multipleValues === undefined) {
14
+ field.multipleValues = false;
15
+ }
16
+ return /*#__PURE__*/React.createElement("hcms-field-validation", {
17
+ style: ValidationContainerStyles,
18
+ "data-path": path,
19
+ "data-field-type": field.type,
20
+ "data-field-multiple-values": String(field.multipleValues),
21
+ "data-field-renderer": String(field.renderer.name)
22
+ }, children);
23
+ };
24
+ };
25
+
26
+ //# sourceMappingURL=createValidationContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useModelField","ValidationContainerStyles","display","createValidationContainer","path","ValidationContainer","children","field","multipleValues","undefined","createElement","style","type","String","renderer","name"],"sources":["createValidationContainer.tsx"],"sourcesContent":["import React from \"react\";\nimport { useModelField } from \"./ModelFieldProvider\";\n\ndeclare global {\n // eslint-disable-next-line\n namespace JSX {\n interface IntrinsicElements {\n \"hcms-field-validation\": {\n \"data-path\": string;\n \"data-field-type\": string;\n \"data-field-multiple-values\": string;\n \"data-field-renderer\": string;\n style: React.CSSProperties;\n children: React.ReactNode;\n };\n }\n }\n}\n\nconst ValidationContainerStyles = { display: \"inherit\" };\n\nexport const createValidationContainer = (path: string) => {\n return function ValidationContainer({ children }: { children: React.ReactNode }) {\n const { field } = useModelField();\n\n if (field.multipleValues === undefined) {\n field.multipleValues = false;\n }\n\n return (\n <hcms-field-validation\n style={ValidationContainerStyles}\n data-path={path}\n data-field-type={field.type}\n data-field-multiple-values={String(field.multipleValues)}\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;AAkBtB,MAAMC,yBAAyB,GAAG;EAAEC,OAAO,EAAE;AAAU,CAAC;AAExD,OAAO,MAAMC,yBAAyB,GAAIC,IAAY,IAAK;EACvD,OAAO,SAASC,mBAAmBA,CAAC;IAAEC;EAAwC,CAAC,EAAE;IAC7E,MAAM;MAAEC;IAAM,CAAC,GAAGP,aAAa,CAAC,CAAC;IAEjC,IAAIO,KAAK,CAACC,cAAc,KAAKC,SAAS,EAAE;MACpCF,KAAK,CAACC,cAAc,GAAG,KAAK;IAChC;IAEA,oBACIT,KAAA,CAAAW,aAAA;MACIC,KAAK,EAAEV,yBAA0B;MACjC,aAAWG,IAAK;MAChB,mBAAiBG,KAAK,CAACK,IAAK;MAC5B,8BAA4BC,MAAM,CAACN,KAAK,CAACC,cAAc,CAAE;MACzD,uBAAqBK,MAAM,CAACN,KAAK,CAACO,QAAQ,CAACC,IAAI;IAAE,GAEhDT,QACkB,CAAC;EAEhC,CAAC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import type { CmsModelField, CmsModelFieldValidator } from "./types";
2
+ import type { Validator } from "@webiny/validation/types";
3
+ export declare const createValidators: (field: CmsModelField, validation: (CmsModelFieldValidator | Validator)[]) => Validator[];
@@ -0,0 +1,52 @@
1
+ import { plugins } from "@webiny/plugins";
2
+ import camelCase from "lodash/camelCase";
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
+ }, []);
50
+ };
51
+
52
+ //# sourceMappingURL=createValidators.js.map
@@ -0,0 +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 { CmsModelField, CmsModelFieldValidator, CmsModelFieldValidatorPlugin } from \"~/types\";\nimport type { Validator } from \"@webiny/validation/types\";\nimport camelCase from \"lodash/camelCase\";\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;AAGzC,OAAOC,SAAS,MAAM,kBAAkB;AAExC,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,KAAKF,GAAG,IAAI,EAAE,GAAG,CAAC;YAC3CN,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":[]}
@@ -0,0 +1,218 @@
1
+ import type { CmsContentEntryRevision, CmsContentEntry, CmsEditorContentModel, CmsErrorResponse, CmsMetaResponse, CmsModelField } from "./types";
2
+ import type { FormValidationOptions } from "@webiny/form";
3
+ /**
4
+ * ############################################
5
+ * Get CMS Entry Query
6
+ */
7
+ export interface CmsEntryGetQueryResponse {
8
+ content: {
9
+ data: CmsContentEntry;
10
+ error: CmsErrorResponse | null;
11
+ };
12
+ }
13
+ export interface CmsEntryGetQueryVariables {
14
+ revision?: string;
15
+ entryId?: string;
16
+ }
17
+ export declare const createReadQuery: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
18
+ /**
19
+ * ############################################
20
+ * Get CMS Singleton Entry Query
21
+ */
22
+ export interface CmsEntryGetSingletonQueryResponse {
23
+ content: {
24
+ data: CmsContentEntry;
25
+ error: CmsErrorResponse | null;
26
+ };
27
+ }
28
+ export declare const createReadSingletonQuery: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
29
+ /**
30
+ * ############################################
31
+ * List CMS Entry Revisions Query
32
+ */
33
+ export interface CmsEntriesListRevisionsQueryResponse {
34
+ revisions: {
35
+ data: CmsContentEntryRevision[];
36
+ error: CmsErrorResponse | null;
37
+ meta: CmsMetaResponse;
38
+ };
39
+ }
40
+ export interface CmsEntriesListRevisionsQueryVariables {
41
+ id: string;
42
+ }
43
+ export declare const createRevisionsQuery: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
44
+ /**
45
+ * ############################################
46
+ * List CMS Entries Query
47
+ */
48
+ export interface CmsEntriesListQueryResponse {
49
+ content: {
50
+ data: CmsContentEntry[];
51
+ error: CmsErrorResponse | null;
52
+ meta: CmsMetaResponse;
53
+ };
54
+ }
55
+ export interface CmsEntriesListQueryVariables {
56
+ where?: {
57
+ [key: string]: any;
58
+ };
59
+ sort?: string[];
60
+ limit?: number;
61
+ after?: string;
62
+ }
63
+ export declare const createListQueryDataSelection: (model: CmsEditorContentModel, fields?: CmsModelField[]) => string;
64
+ export declare const createListQuery: (model: CmsEditorContentModel, fields?: CmsModelField[], deleted?: boolean) => import("graphql").DocumentNode;
65
+ /**
66
+ * ############################################
67
+ * Delete Mutation
68
+ */
69
+ export interface CmsEntryDeleteMutationResponse {
70
+ content: {
71
+ data: CmsContentEntry | null;
72
+ error: CmsErrorResponse | null;
73
+ };
74
+ }
75
+ export interface CmsEntryDeleteMutationVariables {
76
+ revision: string;
77
+ permanently?: boolean;
78
+ }
79
+ export declare const createDeleteMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
80
+ /**
81
+ * ############################################
82
+ * Restore from bin Mutation
83
+ */
84
+ export interface CmsEntryRestoreFromBinMutationResponse {
85
+ content: {
86
+ data: CmsContentEntry | null;
87
+ error: CmsErrorResponse | null;
88
+ };
89
+ }
90
+ export interface CmsEntryRestoreFromBinMutationVariables {
91
+ revision: string;
92
+ }
93
+ export declare const createRestoreFromBinMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
94
+ /**
95
+ * ############################################
96
+ * Create Mutation
97
+ */
98
+ export interface CmsEntryCreateMutationResponse {
99
+ content: {
100
+ data: CmsContentEntry | null;
101
+ error: CmsErrorResponse | null;
102
+ };
103
+ }
104
+ export interface CmsEntryCreateMutationVariables {
105
+ /**
106
+ * We have any here because we do not know which fields does entry have
107
+ */
108
+ data: Record<string, any>;
109
+ options?: FormValidationOptions;
110
+ }
111
+ export declare const createCreateMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
112
+ /**
113
+ * ############################################
114
+ * Create From Mutation
115
+ */
116
+ export interface CmsEntryCreateFromMutationResponse {
117
+ content: {
118
+ data?: CmsContentEntry;
119
+ error?: CmsErrorResponse;
120
+ };
121
+ }
122
+ export interface CmsEntryCreateFromMutationVariables {
123
+ revision: string;
124
+ /**
125
+ * We have any here because we do not know which fields does entry have
126
+ */
127
+ data?: Record<string, any>;
128
+ options?: FormValidationOptions;
129
+ }
130
+ export declare const createCreateFromMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
131
+ /**
132
+ * ############################################
133
+ * Update Mutation
134
+ */
135
+ export interface CmsEntryUpdateMutationResponse {
136
+ content: {
137
+ data?: CmsContentEntry;
138
+ error?: CmsErrorResponse;
139
+ };
140
+ }
141
+ export interface CmsEntryUpdateMutationVariables {
142
+ revision: string;
143
+ /**
144
+ * We have any here because we do not know which fields does entry have
145
+ */
146
+ data: Record<string, any>;
147
+ options?: FormValidationOptions;
148
+ }
149
+ export declare const createUpdateMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
150
+ /**
151
+ * ############################################
152
+ * Update Singleton Mutation
153
+ */
154
+ export interface CmsEntryUpdateSingletonMutationResponse {
155
+ content: {
156
+ data?: CmsContentEntry;
157
+ error?: CmsErrorResponse;
158
+ };
159
+ }
160
+ export interface CmsEntryUpdateSingletonMutationVariables {
161
+ /**
162
+ * We have any here because we do not know which fields does entry have
163
+ */
164
+ data: Record<string, any>;
165
+ options?: FormValidationOptions;
166
+ }
167
+ export declare const createUpdateSingletonMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
168
+ /**
169
+ * ############################################
170
+ * Publish Mutation
171
+ */
172
+ export interface CmsEntryPublishMutationResponse {
173
+ content: {
174
+ data?: CmsContentEntry;
175
+ error?: CmsErrorResponse;
176
+ };
177
+ }
178
+ export interface CmsEntryPublishMutationVariables {
179
+ revision: string;
180
+ }
181
+ export declare const createPublishMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
182
+ /**
183
+ * ############################################
184
+ * Unpublish Mutation
185
+ */
186
+ export interface CmsEntryUnpublishMutationResponse {
187
+ content: {
188
+ data?: CmsContentEntry;
189
+ error?: CmsErrorResponse;
190
+ };
191
+ }
192
+ export interface CmsEntryUnpublishMutationVariables {
193
+ revision: string;
194
+ }
195
+ export declare const createUnpublishMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
196
+ /**
197
+ * ############################################
198
+ * Bulk Action Mutation
199
+ */
200
+ export interface CmsEntryBulkActionMutationResponse {
201
+ content: {
202
+ data?: {
203
+ id: string;
204
+ };
205
+ error?: CmsErrorResponse;
206
+ };
207
+ }
208
+ export interface CmsEntryBulkActionMutationVariables {
209
+ action: string;
210
+ where?: {
211
+ [key: string]: any;
212
+ };
213
+ search?: string;
214
+ data?: {
215
+ [key: string]: any;
216
+ };
217
+ }
218
+ export declare const createBulkActionMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;