@webiny/app-headless-cms-common 0.0.0-unstable.c7dec08bb0 → 0.0.0-unstable.df7a8bb475

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.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 +77 -0
  6. package/Fields/FieldElement.js.map +1 -0
  7. package/Fields/FieldElementError.d.ts +7 -0
  8. package/Fields/FieldElementError.js +25 -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/ModelFieldProvider/ModelFieldContext.d.ts +38 -0
  26. package/ModelFieldProvider/ModelFieldContext.js +26 -0
  27. package/ModelFieldProvider/ModelFieldContext.js.map +1 -0
  28. package/ModelFieldProvider/index.d.ts +2 -0
  29. package/ModelFieldProvider/index.js +4 -0
  30. package/ModelFieldProvider/index.js.map +1 -0
  31. package/ModelFieldProvider/useModelField.d.ts +15 -0
  32. package/ModelFieldProvider/useModelField.js +29 -0
  33. package/ModelFieldProvider/useModelField.js.map +1 -0
  34. package/ModelProvider/ModelContext.d.ts +9 -0
  35. package/ModelProvider/ModelContext.js +12 -0
  36. package/ModelProvider/ModelContext.js.map +1 -0
  37. package/ModelProvider/index.d.ts +2 -0
  38. package/ModelProvider/index.js +4 -0
  39. package/ModelProvider/index.js.map +1 -0
  40. package/ModelProvider/useModel.d.ts +9 -0
  41. package/ModelProvider/useModel.js +16 -0
  42. package/ModelProvider/useModel.js.map +1 -0
  43. package/README.md +6 -13
  44. package/constants.d.ts +1 -0
  45. package/constants.js +3 -0
  46. package/constants.js.map +1 -0
  47. package/createFieldsList.d.ts +3 -2
  48. package/createFieldsList.js +42 -28
  49. package/createFieldsList.js.map +1 -1
  50. package/createValidationContainer.d.ts +18 -0
  51. package/createValidationContainer.js +23 -0
  52. package/createValidationContainer.js.map +1 -0
  53. package/createValidators.d.ts +3 -0
  54. package/createValidators.js +52 -0
  55. package/createValidators.js.map +1 -0
  56. package/entries.graphql.d.ts +74 -2
  57. package/entries.graphql.js +360 -53
  58. package/entries.graphql.js.map +1 -1
  59. package/exports/admin/cms.d.ts +1 -0
  60. package/exports/admin/cms.js +3 -0
  61. package/exports/admin/cms.js.map +1 -0
  62. package/getModelTitleFieldId.d.ts +1 -1
  63. package/getModelTitleFieldId.js +3 -8
  64. package/getModelTitleFieldId.js.map +1 -1
  65. package/index.d.ts +10 -3
  66. package/index.js +11 -37
  67. package/index.js.map +1 -1
  68. package/package.json +22 -27
  69. package/prepareFormData.d.ts +2 -0
  70. package/prepareFormData.js +71 -0
  71. package/prepareFormData.js.map +1 -0
  72. package/types/index.d.ts +113 -48
  73. package/types/index.js +2 -37
  74. package/types/index.js.map +1 -1
  75. package/types/model.d.ts +27 -19
  76. package/types/model.js +2 -4
  77. package/types/model.js.map +1 -1
  78. package/types/shared.js +2 -4
  79. package/types/shared.js.map +1 -1
  80. package/types/validation.d.ts +3 -3
  81. package/types/validation.js +2 -4
  82. package/types/validation.js.map +1 -1
@@ -0,0 +1,15 @@
1
+ import type { CmsModelField, CmsModelFieldTypePlugin } from "../types/index.js";
2
+ export interface UseModelField {
3
+ field: CmsModelField;
4
+ parentValueIndex: number;
5
+ fieldPlugin: CmsModelFieldTypePlugin;
6
+ }
7
+ /**
8
+ * Get model field from the current context.
9
+ */
10
+ export declare const useModelField: import("@webiny/react-composition").GenericHook<unknown, UseModelField> & {
11
+ original: import("@webiny/react-composition").GenericHook<unknown, UseModelField>;
12
+ originalName: string;
13
+ } & {
14
+ createDecorator: (decorator: import("@webiny/react-composition").Decorator<() => UseModelField>) => () => React.JSX.Element;
15
+ };
@@ -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.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;
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.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 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/index.js";
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/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 <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.js";
2
+ export * from "./useModel.js";
@@ -0,0 +1,4 @@
1
+ export * from "./ModelContext.js";
2
+ export * from "./useModel.js";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelContext.js\";\nexport * from \"./useModel.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { CmsModel } from "../types/index.js";
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.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
+ };
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.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":[]}
package/README.md CHANGED
@@ -1,18 +1,11 @@
1
1
  # @webiny/app-headless-cms-common
2
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)
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
7
6
 
8
- ## Install
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
9
8
 
10
- ```
11
- npm install --save @webiny/app-headless-cms-common
12
- ```
9
+ ---
13
10
 
14
- Or if you prefer yarn:
15
-
16
- ```
17
- yarn add @webiny/app-headless-cms-common
18
- ```
11
+ _This README file is automatically generated during the publish process._
package/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const CMS_MODEL_SINGLETON_TAG = "singleEntry";
package/constants.js ADDED
@@ -0,0 +1,3 @@
1
+ export const CMS_MODEL_SINGLETON_TAG = "singleEntry";
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 = \"singleEntry\";\n"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB,GAAG,aAAa","ignoreList":[]}
@@ -1,7 +1,8 @@
1
- import { CmsModelField, CmsModel } from "./types";
1
+ import type { CmsModel, CmsModelField } from "./types/index.js";
2
2
  interface CreateFieldsListParams {
3
3
  model: CmsModel;
4
4
  fields: CmsModelField[];
5
+ graphQLTypePrefix?: string;
5
6
  }
6
- export declare function createFieldsList({ model, fields }: CreateFieldsListParams): string;
7
+ export declare function createFieldsList({ model, fields: inputFields, graphQLTypePrefix }: CreateFieldsListParams): string;
7
8
  export {};
@@ -1,35 +1,49 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createFieldsList = createFieldsList;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _plugins = require("@webiny/plugins");
11
- function createFieldsList(_ref) {
12
- var model = _ref.model,
13
- fields = _ref.fields;
14
- var fieldPlugins = _plugins.plugins.byType("cms-editor-field-type").reduce(function (acc, item) {
15
- return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, acc), {}, (0, _defineProperty2.default)({}, item.field.type, item.field));
16
- }, {});
17
-
18
- // console.log(fields, model);
19
- return fields.map(function (field) {
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 => {
20
13
  if (!fieldPlugins[field.type]) {
21
- console.log("Unknown field plugin for field type \"".concat(field.type, "\"."));
14
+ console.log(`Unknown field plugin for field type "${field.type}".`);
22
15
  return null;
23
16
  }
24
- var graphql = fieldPlugins[field.type].graphql;
17
+ const {
18
+ graphql
19
+ } = fieldPlugins[field.type];
25
20
  if (graphql && graphql.queryField) {
26
- var queryField = graphql.queryField;
27
- var selection = typeof queryField === "string" ? queryField : queryField({
28
- model: model,
29
- field: field
21
+ const {
22
+ queryField
23
+ } = graphql;
24
+ const selection = typeof queryField === "string" ? queryField : queryField({
25
+ model,
26
+ field,
27
+ graphQLTypePrefix: typePrefix
30
28
  });
31
- return "".concat(field.fieldId, " ").concat(selection);
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}`;
32
37
  }
33
38
  return field.fieldId;
34
- }).filter(Boolean).join("\n");
35
- }
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
@@ -1 +1 @@
1
- {"version":3,"names":["createFieldsList","model","fields","fieldPlugins","plugins","byType","reduce","acc","item","field","type","map","console","log","graphql","queryField","selection","fieldId","filter","Boolean","join"],"sources":["createFieldsList.ts"],"sourcesContent":["import { CmsModelField, CmsEditorFieldTypePlugin, CmsModel } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface CreateFieldsListParams {\n model: CmsModel;\n fields: CmsModelField[];\n}\n\nexport function createFieldsList({ model, fields }: CreateFieldsListParams): string {\n const fieldPlugins: Record<string, CmsEditorFieldTypePlugin[\"field\"]> = plugins\n .byType<CmsEditorFieldTypePlugin>(\"cms-editor-field-type\")\n .reduce((acc, item) => ({ ...acc, [item.field.type]: item.field }), {});\n\n // console.log(fields, model);\n return fields\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\" ? queryField : queryField({ model, field });\n\n return `${field.fieldId} ${selection}`;\n }\n\n return field.fieldId;\n })\n .filter(Boolean)\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;AACA;AAOO,SAASA,gBAAgB,OAAoD;EAAA,IAAjDC,KAAK,QAALA,KAAK;IAAEC,MAAM,QAANA,MAAM;EAC5C,IAAMC,YAA+D,GAAGC,gBAAO,CAC1EC,MAAM,CAA2B,uBAAuB,CAAC,CACzDC,MAAM,CAAC,UAACC,GAAG,EAAEC,IAAI;IAAA,mEAAWD,GAAG,yCAAGC,IAAI,CAACC,KAAK,CAACC,IAAI,EAAGF,IAAI,CAACC,KAAK;EAAA,CAAG,EAAE,CAAC,CAAC,CAAC;;EAE3E;EACA,OAAOP,MAAM,CACRS,GAAG,CAAC,UAAAF,KAAK,EAAI;IACV,IAAI,CAACN,YAAY,CAACM,KAAK,CAACC,IAAI,CAAC,EAAE;MAC3BE,OAAO,CAACC,GAAG,iDAAyCJ,KAAK,CAACC,IAAI,SAAK;MACnE,OAAO,IAAI;IACf;IACA,IAAQI,OAAO,GAAKX,YAAY,CAACM,KAAK,CAACC,IAAI,CAAC,CAApCI,OAAO;IAEf,IAAIA,OAAO,IAAIA,OAAO,CAACC,UAAU,EAAE;MAC/B,IAAQA,UAAU,GAAKD,OAAO,CAAtBC,UAAU;MAClB,IAAMC,SAAS,GACX,OAAOD,UAAU,KAAK,QAAQ,GAAGA,UAAU,GAAGA,UAAU,CAAC;QAAEd,KAAK,EAALA,KAAK;QAAEQ,KAAK,EAALA;MAAM,CAAC,CAAC;MAE9E,iBAAUA,KAAK,CAACQ,OAAO,cAAID,SAAS;IACxC;IAEA,OAAOP,KAAK,CAACQ,OAAO;EACxB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,IAAI,CAAC;AACnB"}
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\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 module "react" {
3
+ namespace JSX {
4
+ interface IntrinsicElements {
5
+ "hcms-field-validation": {
6
+ class: string;
7
+ "data-path": string;
8
+ "data-field-type": string;
9
+ "data-field-multiple-values": string;
10
+ "data-field-renderer": string;
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,23 @@
1
+ import React from "react";
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
+ };
22
+
23
+ //# sourceMappingURL=createValidationContainer.js.map
@@ -0,0 +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":[]}
@@ -0,0 +1,3 @@
1
+ import type { CmsModelField, CmsModelFieldValidator } from "./types/index.js";
2
+ import type { Validator } from "@webiny/validation/types.js";
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.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
+ }, []);
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 {\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,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":[]}
@@ -1,4 +1,5 @@
1
- import { CmsContentEntryRevision, CmsContentEntry, CmsEditorContentModel, CmsErrorResponse, CmsMetaResponse, CmsModelField } from "./types";
1
+ import type { CmsContentEntry, CmsContentEntryRevision, CmsEditorContentModel, CmsErrorResponse, CmsMetaResponse, CmsModelField } from "./types/index.js";
2
+ import type { FormValidationOptions } from "@webiny/form";
2
3
  /**
3
4
  * ############################################
4
5
  * Get CMS Entry Query
@@ -14,6 +15,17 @@ export interface CmsEntryGetQueryVariables {
14
15
  entryId?: string;
15
16
  }
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;
17
29
  /**
18
30
  * ############################################
19
31
  * List CMS Entry Revisions Query
@@ -48,7 +60,8 @@ export interface CmsEntriesListQueryVariables {
48
60
  limit?: number;
49
61
  after?: string;
50
62
  }
51
- export declare const createListQuery: (model: CmsEditorContentModel, fields?: CmsModelField[]) => import("graphql").DocumentNode;
63
+ export declare const createListQueryDataSelection: (model: CmsEditorContentModel, fields?: CmsModelField[]) => string;
64
+ export declare const createListQuery: (model: CmsEditorContentModel, fields?: CmsModelField[], deleted?: boolean) => import("graphql").DocumentNode;
52
65
  /**
53
66
  * ############################################
54
67
  * Delete Mutation
@@ -61,8 +74,23 @@ export interface CmsEntryDeleteMutationResponse {
61
74
  }
62
75
  export interface CmsEntryDeleteMutationVariables {
63
76
  revision: string;
77
+ permanently?: boolean;
64
78
  }
65
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;
66
94
  /**
67
95
  * ############################################
68
96
  * Create Mutation
@@ -78,6 +106,7 @@ export interface CmsEntryCreateMutationVariables {
78
106
  * We have any here because we do not know which fields does entry have
79
107
  */
80
108
  data: Record<string, any>;
109
+ options?: FormValidationOptions;
81
110
  }
82
111
  export declare const createCreateMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
83
112
  /**
@@ -96,6 +125,7 @@ export interface CmsEntryCreateFromMutationVariables {
96
125
  * We have any here because we do not know which fields does entry have
97
126
  */
98
127
  data?: Record<string, any>;
128
+ options?: FormValidationOptions;
99
129
  }
100
130
  export declare const createCreateFromMutation: (model: CmsEditorContentModel) => import("graphql").DocumentNode;
101
131
  /**
@@ -114,8 +144,27 @@ export interface CmsEntryUpdateMutationVariables {
114
144
  * We have any here because we do not know which fields does entry have
115
145
  */
116
146
  data: Record<string, any>;
147
+ options?: FormValidationOptions;
117
148
  }
118
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;
119
168
  /**
120
169
  * ############################################
121
170
  * Publish Mutation
@@ -144,3 +193,26 @@ export interface CmsEntryUnpublishMutationVariables {
144
193
  revision: string;
145
194
  }
146
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;