@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,24 @@
1
+ import type { ErrorInfo } from "react";
2
+ import React from "react";
3
+ import type { CmsModelField } from "../types";
4
+ type State = {
5
+ hasError: true;
6
+ error: Error;
7
+ } | {
8
+ hasError: false;
9
+ error: undefined;
10
+ };
11
+ interface Props {
12
+ field: CmsModelField;
13
+ [key: string]: any;
14
+ }
15
+ export declare class ErrorBoundary extends React.Component<Props, State> {
16
+ constructor(props: Props);
17
+ static getDerivedStateFromError(error: Error): {
18
+ hasError: boolean;
19
+ error: Error;
20
+ };
21
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
22
+ render(): any;
23
+ }
24
+ export {};
@@ -0,0 +1,40 @@
1
+ import React from "react";
2
+ import { FieldElementError } from "./FieldElementError";
3
+ export class ErrorBoundary extends React.Component {
4
+ constructor(props) {
5
+ super(props);
6
+ this.state = {
7
+ hasError: false,
8
+ error: undefined
9
+ };
10
+ }
11
+ static getDerivedStateFromError(error) {
12
+ return {
13
+ hasError: true,
14
+ error
15
+ };
16
+ }
17
+ componentDidCatch(error, errorInfo) {
18
+ const {
19
+ field
20
+ } = this.props;
21
+ if (!field) {
22
+ return;
23
+ }
24
+ console.groupCollapsed(`%cFIELD ERROR%c: An error occurred while rendering model field "${field.fieldId}" (${field.id}) of type "${field.type}".`, "color:red", "color:default");
25
+ console.log("Field definition", field);
26
+ console.error(error, errorInfo);
27
+ console.groupEnd();
28
+ }
29
+ render() {
30
+ if (this.state.hasError) {
31
+ return /*#__PURE__*/React.createElement(FieldElementError, {
32
+ title: `Error: ${this.state.error.message}`,
33
+ description: "See developer console for more details."
34
+ });
35
+ }
36
+ return this.props.children;
37
+ }
38
+ }
39
+
40
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","FieldElementError","ErrorBoundary","Component","constructor","props","state","hasError","error","undefined","getDerivedStateFromError","componentDidCatch","errorInfo","field","console","groupCollapsed","fieldId","id","type","log","groupEnd","render","createElement","title","message","description","children"],"sources":["ErrorBoundary.tsx"],"sourcesContent":["import type { ErrorInfo } from \"react\";\nimport React from \"react\";\nimport type { CmsModelField } from \"~/types\";\nimport { FieldElementError } from \"./FieldElementError\";\n\ntype State =\n | {\n hasError: true;\n error: Error;\n }\n | { hasError: false; error: undefined };\n\ninterface Props {\n field: CmsModelField;\n [key: string]: any;\n}\n\nexport class ErrorBoundary extends React.Component<Props, State> {\n constructor(props: Props) {\n super(props);\n this.state = {\n hasError: false,\n error: undefined\n };\n }\n\n static getDerivedStateFromError(error: Error) {\n return {\n hasError: true,\n error\n };\n }\n\n public override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { field } = this.props;\n if (!field) {\n return;\n }\n console.groupCollapsed(\n `%cFIELD ERROR%c: An error occurred while rendering model field \"${field.fieldId}\" (${field.id}) of type \"${field.type}\".`,\n \"color:red\",\n \"color:default\"\n );\n console.log(\"Field definition\", field);\n console.error(error, errorInfo);\n console.groupEnd();\n }\n\n public override render() {\n if (this.state.hasError) {\n return (\n <FieldElementError\n title={`Error: ${this.state.error.message}`}\n description={\"See developer console for more details.\"}\n />\n );\n }\n\n return this.props.children;\n }\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,iBAAiB;AAc1B,OAAO,MAAMC,aAAa,SAASF,KAAK,CAACG,SAAS,CAAe;EAC7DC,WAAWA,CAACC,KAAY,EAAE;IACtB,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;MACTC,QAAQ,EAAE,KAAK;MACfC,KAAK,EAAEC;IACX,CAAC;EACL;EAEA,OAAOC,wBAAwBA,CAACF,KAAY,EAAE;IAC1C,OAAO;MACHD,QAAQ,EAAE,IAAI;MACdC;IACJ,CAAC;EACL;EAEgBG,iBAAiBA,CAACH,KAAY,EAAEI,SAAoB,EAAE;IAClE,MAAM;MAAEC;IAAM,CAAC,GAAG,IAAI,CAACR,KAAK;IAC5B,IAAI,CAACQ,KAAK,EAAE;MACR;IACJ;IACAC,OAAO,CAACC,cAAc,CAClB,mEAAmEF,KAAK,CAACG,OAAO,MAAMH,KAAK,CAACI,EAAE,cAAcJ,KAAK,CAACK,IAAI,IAAI,EAC1H,WAAW,EACX,eACJ,CAAC;IACDJ,OAAO,CAACK,GAAG,CAAC,kBAAkB,EAAEN,KAAK,CAAC;IACtCC,OAAO,CAACN,KAAK,CAACA,KAAK,EAAEI,SAAS,CAAC;IAC/BE,OAAO,CAACM,QAAQ,CAAC,CAAC;EACtB;EAEgBC,MAAMA,CAAA,EAAG;IACrB,IAAI,IAAI,CAACf,KAAK,CAACC,QAAQ,EAAE;MACrB,oBACIP,KAAA,CAAAsB,aAAA,CAACrB,iBAAiB;QACdsB,KAAK,EAAE,UAAU,IAAI,CAACjB,KAAK,CAACE,KAAK,CAACgB,OAAO,EAAG;QAC5CC,WAAW,EAAE;MAA0C,CAC1D,CAAC;IAEV;IAEA,OAAO,IAAI,CAACpB,KAAK,CAACqB,QAAQ;EAC9B;AACJ","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ import React from "react";
2
+ import type { CmsModelField, CmsEditorContentModel, BindComponent } from "../types";
3
+ declare global {
4
+ namespace JSX {
5
+ interface IntrinsicElements {
6
+ "hcms-model-field": {
7
+ "data-id": string;
8
+ "data-type": string;
9
+ "data-field-id": string;
10
+ children: React.ReactNode;
11
+ };
12
+ }
13
+ }
14
+ }
15
+ export interface FieldElementProps {
16
+ field: CmsModelField;
17
+ Bind: BindComponent;
18
+ contentModel: CmsEditorContentModel;
19
+ }
20
+ export declare const FieldElement: (({ field, ...props }: FieldElementProps) => React.JSX.Element | null) & {
21
+ original: ({ field, ...props }: FieldElementProps) => React.JSX.Element | null;
22
+ originalName: string;
23
+ displayName: string;
24
+ } & {
25
+ original: (({ field, ...props }: FieldElementProps) => React.JSX.Element | null) & {
26
+ original: ({ field, ...props }: FieldElementProps) => React.JSX.Element | null;
27
+ originalName: string;
28
+ displayName: string;
29
+ };
30
+ originalName: string;
31
+ displayName: string;
32
+ } & {
33
+ createDecorator: (decorator: import("@webiny/app-admin").ComponentDecorator<(({ field, ...props }: FieldElementProps) => React.JSX.Element | null) & {
34
+ original: ({ field, ...props }: FieldElementProps) => React.JSX.Element | null;
35
+ originalName: string;
36
+ displayName: string;
37
+ }>) => (props: unknown) => React.JSX.Element;
38
+ };
39
+ /**
40
+ * @deprecated Use `FieldElement` instead.
41
+ */
42
+ export declare const RenderFieldElement: (({ field, ...props }: FieldElementProps) => React.JSX.Element | null) & {
43
+ original: ({ field, ...props }: FieldElementProps) => React.JSX.Element | null;
44
+ originalName: string;
45
+ displayName: string;
46
+ } & {
47
+ original: (({ field, ...props }: FieldElementProps) => React.JSX.Element | null) & {
48
+ original: ({ field, ...props }: FieldElementProps) => React.JSX.Element | null;
49
+ originalName: string;
50
+ displayName: string;
51
+ };
52
+ originalName: string;
53
+ displayName: string;
54
+ } & {
55
+ createDecorator: (decorator: import("@webiny/app-admin").ComponentDecorator<(({ field, ...props }: FieldElementProps) => React.JSX.Element | null) & {
56
+ original: ({ field, ...props }: FieldElementProps) => React.JSX.Element | null;
57
+ originalName: string;
58
+ displayName: string;
59
+ }>) => (props: unknown) => React.JSX.Element;
60
+ };
61
+ /**
62
+ * @deprecated Use `FieldElementProps` instead.
63
+ */
64
+ export type RenderFieldElementProps = FieldElementProps;
@@ -0,0 +1,71 @@
1
+ import React from "react";
2
+ import get from "lodash/get";
3
+ import { makeDecoratable } from "@webiny/app-admin";
4
+ import { i18n } from "@webiny/app/i18n";
5
+ import Label from "./Label";
6
+ import { useBind } from "./useBind";
7
+ import { useRenderPlugins } from "./useRenderPlugins";
8
+ import { ModelFieldProvider, useModelField } from "../ModelFieldProvider";
9
+ import { ErrorBoundary } from "./ErrorBoundary";
10
+ const t = i18n.ns("app-headless-cms/admin/components/content-form");
11
+ const RenderField = props => {
12
+ const renderPlugins = useRenderPlugins();
13
+ const {
14
+ Bind,
15
+ contentModel
16
+ } = props;
17
+ const {
18
+ field
19
+ } = useModelField();
20
+ const getBind = useBind({
21
+ Bind
22
+ });
23
+ if (typeof field.renderer === "function") {
24
+ return /*#__PURE__*/React.createElement(React.Fragment, null, field.renderer({
25
+ field,
26
+ getBind,
27
+ Label,
28
+ contentModel
29
+ }));
30
+ }
31
+ const renderPlugin = renderPlugins.find(plugin => plugin.renderer.rendererName === get(field, "renderer.name"));
32
+ if (!renderPlugin) {
33
+ return t`Cannot render "{fieldName}" field - field renderer missing.`({
34
+ fieldName: /*#__PURE__*/React.createElement("strong", null, field.fieldId)
35
+ });
36
+ }
37
+ return /*#__PURE__*/React.createElement(React.Fragment, null, renderPlugin.renderer.render({
38
+ field,
39
+ getBind,
40
+ Label,
41
+ contentModel
42
+ }));
43
+ };
44
+ export const FieldElement = makeDecoratable("FieldElement", ({
45
+ field,
46
+ ...props
47
+ }) => {
48
+ if (!field) {
49
+ return null;
50
+ }
51
+ return /*#__PURE__*/React.createElement("hcms-model-field", {
52
+ "data-id": field.id,
53
+ "data-field-id": field.fieldId,
54
+ "data-type": field.type
55
+ }, /*#__PURE__*/React.createElement(ErrorBoundary, {
56
+ field: field
57
+ }, /*#__PURE__*/React.createElement(ModelFieldProvider, {
58
+ field: field
59
+ }, /*#__PURE__*/React.createElement(RenderField, props))));
60
+ });
61
+
62
+ /**
63
+ * @deprecated Use `FieldElement` instead.
64
+ */
65
+ export const RenderFieldElement = FieldElement;
66
+
67
+ /**
68
+ * @deprecated Use `FieldElementProps` instead.
69
+ */
70
+
71
+ //# sourceMappingURL=FieldElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","get","makeDecoratable","i18n","Label","useBind","useRenderPlugins","ModelFieldProvider","useModelField","ErrorBoundary","t","ns","RenderField","props","renderPlugins","Bind","contentModel","field","getBind","renderer","createElement","Fragment","renderPlugin","find","plugin","rendererName","fieldName","fieldId","render","FieldElement","id","type","RenderFieldElement"],"sources":["FieldElement.tsx"],"sourcesContent":["import React from \"react\";\nimport get from \"lodash/get\";\nimport { makeDecoratable } from \"@webiny/app-admin\";\nimport { i18n } from \"@webiny/app/i18n\";\nimport Label from \"./Label\";\nimport { useBind } from \"./useBind\";\nimport { useRenderPlugins } from \"./useRenderPlugins\";\nimport { ModelFieldProvider, useModelField } from \"../ModelFieldProvider\";\nimport type { CmsModelField, CmsEditorContentModel, BindComponent } from \"~/types\";\nimport { ErrorBoundary } from \"./ErrorBoundary\";\n\nconst t = i18n.ns(\"app-headless-cms/admin/components/content-form\");\n\ndeclare global {\n // eslint-disable-next-line\n namespace JSX {\n interface IntrinsicElements {\n \"hcms-model-field\": {\n \"data-id\": string;\n \"data-type\": string;\n \"data-field-id\": string;\n children: React.ReactNode;\n };\n }\n }\n}\n\ntype RenderFieldProps = Omit<FieldElementProps, \"field\">;\n\nconst RenderField = (props: RenderFieldProps) => {\n const renderPlugins = useRenderPlugins();\n const { Bind, contentModel } = props;\n const { field } = useModelField();\n const getBind = useBind({ Bind });\n\n if (typeof field.renderer === \"function\") {\n return <>{field.renderer({ field, getBind, Label, contentModel })}</>;\n }\n\n const renderPlugin = renderPlugins.find(\n plugin => plugin.renderer.rendererName === get(field, \"renderer.name\")\n );\n\n if (!renderPlugin) {\n return t`Cannot render \"{fieldName}\" field - field renderer missing.`({\n fieldName: <strong>{field.fieldId}</strong>\n });\n }\n\n return <>{renderPlugin.renderer.render({ field, getBind, Label, contentModel })}</>;\n};\n\nexport interface FieldElementProps {\n field: CmsModelField;\n Bind: BindComponent;\n contentModel: CmsEditorContentModel;\n}\n\nexport const FieldElement = makeDecoratable(\n \"FieldElement\",\n ({ field, ...props }: FieldElementProps) => {\n if (!field) {\n return null;\n }\n\n return (\n <hcms-model-field\n data-id={field.id}\n data-field-id={field.fieldId}\n data-type={field.type}\n >\n <ErrorBoundary field={field}>\n <ModelFieldProvider field={field}>\n <RenderField {...props} />\n </ModelFieldProvider>\n </ErrorBoundary>\n </hcms-model-field>\n );\n }\n);\n\n/**\n * @deprecated Use `FieldElement` instead.\n */\nexport const RenderFieldElement = FieldElement;\n\n/**\n * @deprecated Use `FieldElementProps` instead.\n */\nexport type RenderFieldElementProps = FieldElementProps;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,GAAG,MAAM,YAAY;AAC5B,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,IAA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ACvC,cAAc,EACd,CAAC;EAAEe,KAAK;EAAE,GAAGJ;AAAyB,CAAC,KAAK;EACxC,IAAI,CAACI,KAAK,EAAE;IACR,OAAO,IAAI;EACf;EAEA,oBACIjB,KAAA,CAAAoB,aAAA;IACI,WAASH,KAAK,CAACa,EAAG;IAClB,iBAAeb,KAAK,CAACU,OAAQ;IAC7B,aAAWV,KAAK,CAACc;EAAK,gBAEtB/B,KAAA,CAAAoB,aAAA,CAACX,aAAa;IAACQ,KAAK,EAAEA;EAAM,gBACxBjB,KAAA,CAAAoB,aAAA,CAACb,kBAAkB;IAACU,KAAK,EAAEA;EAAM,gBAC7BjB,KAAA,CAAAoB,aAAA,CAACR,WAAW,EAAKC,KAAQ,CACT,CACT,CACD,CAAC;AAE3B,CACJ,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMmB,kBAAkB,GAAGH,YAAY;;AAE9C;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ interface FieldElementErrorProps {
3
+ title: string;
4
+ description: string;
5
+ }
6
+ export declare const FieldElementError: (props: FieldElementErrorProps) => React.JSX.Element | null;
7
+ export {};
@@ -0,0 +1,26 @@
1
+ import _styled from "@emotion/styled/base";
2
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
3
+ import React from "react";
4
+ const StyledError = /*#__PURE__*/_styled("div", process.env.NODE_ENV === "production" ? {
5
+ target: "e11oiyxk0"
6
+ } : {
7
+ target: "e11oiyxk0",
8
+ label: "StyledError"
9
+ })(process.env.NODE_ENV === "production" ? {
10
+ name: "1ybf6v5",
11
+ styles: "border:2px solid red;background-color:#f87e7e;border-radius:5px;padding:5px 10px"
12
+ } : {
13
+ name: "1ybf6v5",
14
+ styles: "border:2px solid red;background-color:#f87e7e;border-radius:5px;padding:5px 10px",
15
+ map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkZpZWxkRWxlbWVudEVycm9yLnRzeCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHOEIiLCJmaWxlIjoiRmllbGRFbGVtZW50RXJyb3IudHN4Iiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFJlYWN0IGZyb20gXCJyZWFjdFwiO1xuaW1wb3J0IHN0eWxlZCBmcm9tIFwiQGVtb3Rpb24vc3R5bGVkXCI7XG5cbmNvbnN0IFN0eWxlZEVycm9yID0gc3R5bGVkLmRpdmBcbiAgICBib3JkZXI6IDJweCBzb2xpZCByZWQ7XG4gICAgYmFja2dyb3VuZC1jb2xvcjogI2Y4N2U3ZTtcbiAgICBib3JkZXItcmFkaXVzOiA1cHg7XG4gICAgcGFkZGluZzogNXB4IDEwcHg7XG5gO1xuXG5pbnRlcmZhY2UgRmllbGRFbGVtZW50RXJyb3JQcm9wcyB7XG4gICAgdGl0bGU6IHN0cmluZztcbiAgICBkZXNjcmlwdGlvbjogc3RyaW5nO1xufVxuXG5jb25zdCBzaG93RXJyb3IgPSBwcm9jZXNzLmVudi5OT0RFX0VOViA9PT0gXCJkZXZlbG9wbWVudFwiO1xuXG5leHBvcnQgY29uc3QgRmllbGRFbGVtZW50RXJyb3IgPSAocHJvcHM6IEZpZWxkRWxlbWVudEVycm9yUHJvcHMpID0+IHtcbiAgICBpZiAoIXNob3dFcnJvcikge1xuICAgICAgICByZXR1cm4gbnVsbDtcbiAgICB9XG5cbiAgICByZXR1cm4gKFxuICAgICAgICA8U3R5bGVkRXJyb3I+XG4gICAgICAgICAgICA8aDU+e3Byb3BzLnRpdGxlfTwvaDU+XG4gICAgICAgICAgICA8cD57cHJvcHMuZGVzY3JpcHRpb259PC9wPlxuICAgICAgICA8L1N0eWxlZEVycm9yPlxuICAgICk7XG59O1xuIl19 */",
16
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
17
+ });
18
+ const showError = process.env.NODE_ENV === "development";
19
+ export const FieldElementError = props => {
20
+ if (!showError) {
21
+ return null;
22
+ }
23
+ return /*#__PURE__*/React.createElement(StyledError, null, /*#__PURE__*/React.createElement("h5", null, props.title), /*#__PURE__*/React.createElement("p", null, props.description));
24
+ };
25
+
26
+ //# sourceMappingURL=FieldElementError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","StyledError","_styled","process","env","NODE_ENV","target","label","name","styles","map","toString","_EMOTION_STRINGIFIED_CSS_ERROR__","showError","FieldElementError","props","createElement","title","description"],"sources":["FieldElementError.tsx"],"sourcesContent":["import React from \"react\";\nimport styled from \"@emotion/styled\";\n\nconst StyledError = styled.div`\n border: 2px solid red;\n background-color: #f87e7e;\n border-radius: 5px;\n padding: 5px 10px;\n`;\n\ninterface FieldElementErrorProps {\n title: string;\n description: string;\n}\n\nconst showError = process.env.NODE_ENV === \"development\";\n\nexport const FieldElementError = (props: FieldElementErrorProps) => {\n if (!showError) {\n return null;\n }\n\n return (\n <StyledError>\n <h5>{props.title}</h5>\n <p>{props.description}</p>\n </StyledError>\n );\n};\n"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,MAAMC,WAAW,gBAAAC,OAAA,QAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA;EAAAC,MAAA;AAAA;EAAAA,MAAA;EAAAC,KAAA;AAAA,GAAAJ,OAAA,CAAAC,GAAA,CAAAC,QAAA;EAAAG,IAAA;EAAAC,MAAA;AAAA;EAAAD,IAAA;EAAAC,MAAA;EAAAC,GAAA;EAAAC,QAAA,EAAAC;AAAA,EAKhB;AAOD,MAAMC,SAAS,GAAGV,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa;AAExD,OAAO,MAAMS,iBAAiB,GAAIC,KAA6B,IAAK;EAChE,IAAI,CAACF,SAAS,EAAE;IACZ,OAAO,IAAI;EACf;EAEA,oBACIb,KAAA,CAAAgB,aAAA,CAACf,WAAW,qBACRD,KAAA,CAAAgB,aAAA,aAAKD,KAAK,CAACE,KAAU,CAAC,eACtBjB,KAAA,CAAAgB,aAAA,YAAID,KAAK,CAACG,WAAe,CAChB,CAAC;AAEtB,CAAC","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import type { CmsEditorContentModel, CmsModelField, CmsEditorFieldsLayout, BindComponent } from "../types";
3
+ interface FieldsProps {
4
+ Bind: BindComponent;
5
+ contentModel: CmsEditorContentModel;
6
+ fields: CmsModelField[];
7
+ layout: CmsEditorFieldsLayout;
8
+ gridClassName?: string;
9
+ }
10
+ export declare const Fields: ({ Bind, fields, layout, contentModel, gridClassName }: FieldsProps) => React.JSX.Element;
11
+ export {};
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ import { Grid } from "@webiny/admin-ui";
3
+ import { FieldElement } from "./FieldElement";
4
+ import { FieldElementError } from "./FieldElementError";
5
+ const getFieldById = (fields, id) => {
6
+ return fields.find(field => field.id === id) || null;
7
+ };
8
+ export const Fields = ({
9
+ Bind,
10
+ fields,
11
+ layout,
12
+ contentModel,
13
+ gridClassName
14
+ }) => {
15
+ return /*#__PURE__*/React.createElement(Grid, {
16
+ className: gridClassName
17
+ }, layout.map((row, rowIndex) => /*#__PURE__*/React.createElement(React.Fragment, {
18
+ key: rowIndex
19
+ }, row.map(id => {
20
+ const field = getFieldById(fields, id);
21
+ return /*#__PURE__*/React.createElement(Grid.Column, {
22
+ span: Math.floor(12 / row.length),
23
+ key: id
24
+ }, field ? /*#__PURE__*/React.createElement(FieldElement, {
25
+ field: field,
26
+ Bind: Bind,
27
+ contentModel: contentModel
28
+ }) : /*#__PURE__*/React.createElement(FieldElementError, {
29
+ title: `Missing field with id "${id}"!`,
30
+ description: "Make sure field layout contains the correct field ids (hint: check for typos)."
31
+ }));
32
+ }))));
33
+ };
34
+
35
+ //# sourceMappingURL=Fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","Grid","FieldElement","FieldElementError","getFieldById","fields","id","find","field","Fields","Bind","layout","contentModel","gridClassName","createElement","className","map","row","rowIndex","Fragment","key","Column","span","Math","floor","length","title","description"],"sources":["Fields.tsx"],"sourcesContent":["import React from \"react\";\nimport { Grid, type ColumnProps } from \"@webiny/admin-ui\";\nimport { FieldElement } from \"./FieldElement\";\nimport { FieldElementError } from \"./FieldElementError\";\nimport type {\n CmsEditorContentModel,\n CmsModelField,\n CmsEditorFieldsLayout,\n BindComponent\n} from \"~/types\";\n\ninterface FieldsProps {\n Bind: BindComponent;\n contentModel: CmsEditorContentModel;\n fields: CmsModelField[];\n layout: CmsEditorFieldsLayout;\n gridClassName?: string;\n}\n\nconst getFieldById = (fields: CmsModelField[], id: string): CmsModelField | null => {\n return fields.find(field => field.id === id) || null;\n};\n\nexport const Fields = ({ Bind, fields, layout, contentModel, gridClassName }: FieldsProps) => {\n return (\n <Grid className={gridClassName}>\n {layout.map((row, rowIndex) => (\n <React.Fragment key={rowIndex}>\n {row.map(id => {\n const field = getFieldById(fields, id) as CmsModelField;\n\n return (\n <Grid.Column\n span={Math.floor(12 / row.length) as ColumnProps[\"span\"]}\n key={id}\n >\n {field ? (\n <FieldElement\n field={field}\n Bind={Bind}\n contentModel={contentModel}\n />\n ) : (\n <FieldElementError\n title={`Missing field with id \"${id}\"!`}\n description={\n \"Make sure field layout contains the correct field ids (hint: check for typos).\"\n }\n />\n )}\n </Grid.Column>\n );\n })}\n </React.Fragment>\n ))}\n </Grid>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,IAAI,QAA0B,kBAAkB;AACzD,SAASC,YAAY;AACrB,SAASC,iBAAiB;AAgB1B,MAAMC,YAAY,GAAGA,CAACC,MAAuB,EAAEC,EAAU,KAA2B;EAChF,OAAOD,MAAM,CAACE,IAAI,CAACC,KAAK,IAAIA,KAAK,CAACF,EAAE,KAAKA,EAAE,CAAC,IAAI,IAAI;AACxD,CAAC;AAED,OAAO,MAAMG,MAAM,GAAGA,CAAC;EAAEC,IAAI;EAAEL,MAAM;EAAEM,MAAM;EAAEC,YAAY;EAAEC;AAA2B,CAAC,KAAK;EAC1F,oBACIb,KAAA,CAAAc,aAAA,CAACb,IAAI;IAACc,SAAS,EAAEF;EAAc,GAC1BF,MAAM,CAACK,GAAG,CAAC,CAACC,GAAG,EAAEC,QAAQ,kBACtBlB,KAAA,CAAAc,aAAA,CAACd,KAAK,CAACmB,QAAQ;IAACC,GAAG,EAAEF;EAAS,GACzBD,GAAG,CAACD,GAAG,CAACV,EAAE,IAAI;IACX,MAAME,KAAK,GAAGJ,YAAY,CAACC,MAAM,EAAEC,EAAE,CAAkB;IAEvD,oBACIN,KAAA,CAAAc,aAAA,CAACb,IAAI,CAACoB,MAAM;MACRC,IAAI,EAAEC,IAAI,CAACC,KAAK,CAAC,EAAE,GAAGP,GAAG,CAACQ,MAAM,CAAyB;MACzDL,GAAG,EAAEd;IAAG,GAEPE,KAAK,gBACFR,KAAA,CAAAc,aAAA,CAACZ,YAAY;MACTM,KAAK,EAAEA,KAAM;MACbE,IAAI,EAAEA,IAAK;MACXE,YAAY,EAAEA;IAAa,CAC9B,CAAC,gBAEFZ,KAAA,CAAAc,aAAA,CAACX,iBAAiB;MACduB,KAAK,EAAE,0BAA0BpB,EAAE,IAAK;MACxCqB,WAAW,EACP;IACH,CACJ,CAEI,CAAC;EAEtB,CAAC,CACW,CACnB,CACC,CAAC;AAEf,CAAC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ interface LabelProps {
3
+ children?: React.ReactNode;
4
+ }
5
+ export declare const Label: ({ children }: LabelProps) => React.JSX.Element;
6
+ export default Label;
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { FormComponentLabel } from "@webiny/admin-ui";
3
+ export const Label = ({
4
+ children
5
+ }) => /*#__PURE__*/React.createElement(FormComponentLabel, {
6
+ text: children
7
+ });
8
+ export default Label;
9
+
10
+ //# sourceMappingURL=Label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","FormComponentLabel","Label","children","createElement","text"],"sources":["Label.tsx"],"sourcesContent":["import React from \"react\";\nimport { FormComponentLabel } from \"@webiny/admin-ui\";\n\ninterface LabelProps {\n children?: React.ReactNode;\n}\n\nexport const Label = ({ children }: LabelProps) => <FormComponentLabel text={children} />;\n\nexport default Label;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,kBAAkB,QAAQ,kBAAkB;AAMrD,OAAO,MAAMC,KAAK,GAAGA,CAAC;EAAEC;AAAqB,CAAC,kBAAKH,KAAA,CAAAI,aAAA,CAACH,kBAAkB;EAACI,IAAI,EAAEF;AAAS,CAAE,CAAC;AAEzF,eAAeD,KAAK","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./FieldElement";
2
+ export * from "./Fields";
3
+ export * from "./useBind";
@@ -0,0 +1,5 @@
1
+ export * from "./FieldElement";
2
+ export * from "./Fields";
3
+ export * from "./useBind";
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./FieldElement\";\nexport * from \"./Fields\";\nexport * from \"./useBind\";\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { BindComponent } from "../types";
2
+ interface UseBindProps {
3
+ Bind: BindComponent;
4
+ }
5
+ export interface GetBindCallable {
6
+ (index?: number): BindComponent;
7
+ }
8
+ export declare function useBind({ Bind }: UseBindProps): (index?: number) => BindComponent;
9
+ export {};
@@ -0,0 +1,113 @@
1
+ import React, { useRef, cloneElement } from "react";
2
+ import { useForm } from "@webiny/form";
3
+ import { createValidators } from "../createValidators";
4
+ import { useModelField } from "../ModelFieldProvider";
5
+ import { createValidationContainer } from "../createValidationContainer";
6
+ const createFieldCacheKey = field => {
7
+ return [field.id, field.fieldId, JSON.stringify(field.validation), JSON.stringify(field.listValidation)].join(";");
8
+ };
9
+ const emptyValidators = [];
10
+ export function useBind({
11
+ Bind
12
+ }) {
13
+ const {
14
+ field
15
+ } = useModelField();
16
+ const memoizedBindComponents = useRef({});
17
+ const cacheKey = createFieldCacheKey(field);
18
+ const form = useForm();
19
+ return (index = -1) => {
20
+ const {
21
+ parentName
22
+ } = Bind;
23
+
24
+ // If there's a parent name assigned to the given Bind component, we need to include it in the new field "name".
25
+ // This allows us to have nested fields (like "object" field with nested properties)
26
+ const name = [parentName, field.fieldId, index >= 0 ? index : undefined].filter(v => v !== undefined).join(".");
27
+ const componentId = `${name};${cacheKey}`;
28
+ if (memoizedBindComponents.current[componentId]) {
29
+ return memoizedBindComponents.current[componentId];
30
+ }
31
+ const validators = createValidators(field, field.validation || emptyValidators);
32
+ const listValidators = createValidators(field, field.listValidation || emptyValidators);
33
+ const isMultipleValues = index === -1 && field.multipleValues;
34
+ const inputValidators = isMultipleValues ? listValidators : validators;
35
+
36
+ // We only use default values for single-value fields.
37
+ const defaultValueFromSettings = !isMultipleValues ? field.settings?.defaultValue : null;
38
+ memoizedBindComponents.current[componentId] = function UseBind(params) {
39
+ const {
40
+ name: childName,
41
+ validators: childValidators,
42
+ children,
43
+ defaultValue = defaultValueFromSettings
44
+ } = params;
45
+ const {
46
+ field
47
+ } = useModelField();
48
+ return /*#__PURE__*/React.createElement(Bind, {
49
+ name: childName || name,
50
+ validators: childValidators || inputValidators,
51
+ defaultValue: defaultValue ?? null,
52
+ context: {
53
+ field
54
+ }
55
+ }, bind => {
56
+ // Multiple-values functions below.
57
+ const props = {
58
+ ...bind
59
+ };
60
+ if (field.multipleValues && index === -1) {
61
+ props.appendValue = (newValue, index) => {
62
+ const currentValue = bind.value || [];
63
+ const newIndex = index ?? currentValue.length;
64
+ bind.onChange([...currentValue.slice(0, newIndex), newValue, ...currentValue.slice(newIndex)]);
65
+ };
66
+ props.prependValue = newValue => {
67
+ bind.onChange([newValue, ...(bind.value || [])]);
68
+ };
69
+ props.appendValues = newValues => {
70
+ bind.onChange([...(bind.value || []), ...newValues]);
71
+ };
72
+ props.removeValue = index => {
73
+ if (index < 0) {
74
+ return;
75
+ }
76
+ const value = [...bind.value.slice(0, index), ...bind.value.slice(index + 1)];
77
+ bind.onChange(value.length === 0 ? null : value);
78
+
79
+ // To make sure the field is still valid, we must trigger validation.
80
+ form.validateInput(field.fieldId);
81
+ };
82
+ props.moveValueUp = index => {
83
+ if (index <= 0) {
84
+ return;
85
+ }
86
+ const value = [...bind.value];
87
+ value.splice(index, 1);
88
+ value.splice(index - 1, 0, bind.value[index]);
89
+ bind.onChange(value);
90
+ };
91
+ props.moveValueDown = index => {
92
+ if (index >= bind.value.length) {
93
+ return;
94
+ }
95
+ const value = [...bind.value];
96
+ value.splice(index, 1);
97
+ value.splice(index + 1, 0, bind.value[index]);
98
+ bind.onChange(value);
99
+ };
100
+ }
101
+ return typeof children === "function" ? children(props) : /*#__PURE__*/cloneElement(children, props);
102
+ });
103
+ };
104
+
105
+ // We need to keep track of current field name, to support nested fields.
106
+ memoizedBindComponents.current[componentId].parentName = name;
107
+ memoizedBindComponents.current[componentId].displayName = `Bind<${name}>`;
108
+ memoizedBindComponents.current[componentId].ValidationContainer = createValidationContainer(name);
109
+ return memoizedBindComponents.current[componentId];
110
+ };
111
+ }
112
+
113
+ //# sourceMappingURL=useBind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useRef","cloneElement","useForm","createValidators","useModelField","createValidationContainer","createFieldCacheKey","field","id","fieldId","JSON","stringify","validation","listValidation","join","emptyValidators","useBind","Bind","memoizedBindComponents","cacheKey","form","index","parentName","name","undefined","filter","v","componentId","current","validators","listValidators","isMultipleValues","multipleValues","inputValidators","defaultValueFromSettings","settings","defaultValue","UseBind","params","childName","childValidators","children","createElement","context","bind","props","appendValue","newValue","currentValue","value","newIndex","length","onChange","slice","prependValue","appendValues","newValues","removeValue","validateInput","moveValueUp","splice","moveValueDown","displayName","ValidationContainer"],"sources":["useBind.tsx"],"sourcesContent":["import React, { useRef, cloneElement } from \"react\";\nimport type { Validator } from \"@webiny/validation/types\";\nimport { useForm } from \"@webiny/form\";\nimport { createValidators } from \"~/createValidators\";\nimport type { BindComponent, CmsModelField } from \"~/types\";\nimport { useModelField } from \"~/ModelFieldProvider\";\nimport { createValidationContainer } from \"~/createValidationContainer\";\n\ninterface UseBindProps {\n Bind: BindComponent;\n}\n\ninterface UseBindParams {\n name?: string;\n validators?: Validator | Validator[];\n children?: any;\n defaultValue?: any;\n}\n\nconst createFieldCacheKey = (field: CmsModelField) => {\n return [\n field.id,\n field.fieldId,\n JSON.stringify(field.validation),\n JSON.stringify(field.listValidation)\n ].join(\";\");\n};\n\nexport interface GetBindCallable {\n (index?: number): BindComponent;\n}\n\nconst emptyValidators: Validator[] = [];\n\nexport function useBind({ Bind }: UseBindProps) {\n const { field } = useModelField();\n const memoizedBindComponents = useRef<Record<string, BindComponent>>({});\n const cacheKey = createFieldCacheKey(field);\n const form = useForm();\n\n return (index = -1) => {\n const { parentName } = Bind;\n\n // If there's a parent name assigned to the given Bind component, we need to include it in the new field \"name\".\n // This allows us to have nested fields (like \"object\" field with nested properties)\n const name = [parentName, field.fieldId, index >= 0 ? index : undefined]\n .filter(v => v !== undefined)\n .join(\".\");\n\n const componentId = `${name};${cacheKey}`;\n\n if (memoizedBindComponents.current[componentId]) {\n return memoizedBindComponents.current[componentId];\n }\n\n const validators = createValidators(field, field.validation || emptyValidators);\n const listValidators = createValidators(field, field.listValidation || emptyValidators);\n const isMultipleValues = index === -1 && field.multipleValues;\n const inputValidators = isMultipleValues ? listValidators : validators;\n\n // We only use default values for single-value fields.\n const defaultValueFromSettings = !isMultipleValues ? field.settings?.defaultValue : null;\n\n memoizedBindComponents.current[componentId] = function UseBind(params: UseBindParams) {\n const {\n name: childName,\n validators: childValidators,\n children,\n defaultValue = defaultValueFromSettings\n } = params;\n\n const { field } = useModelField();\n\n return (\n <Bind\n name={childName || name}\n validators={childValidators || inputValidators}\n defaultValue={defaultValue ?? null}\n context={{ field }}\n >\n {bind => {\n // Multiple-values functions below.\n const props = { ...bind };\n if (field.multipleValues && index === -1) {\n props.appendValue = (newValue: any, index?: number) => {\n const currentValue = bind.value || [];\n const newIndex = index ?? currentValue.length;\n\n bind.onChange([\n ...currentValue.slice(0, newIndex),\n newValue,\n ...currentValue.slice(newIndex)\n ]);\n };\n props.prependValue = (newValue: any) => {\n bind.onChange([newValue, ...(bind.value || [])]);\n };\n props.appendValues = (newValues: any[]) => {\n bind.onChange([...(bind.value || []), ...newValues]);\n };\n\n props.removeValue = (index: number) => {\n if (index < 0) {\n return;\n }\n\n const value = [\n ...bind.value.slice(0, index),\n ...bind.value.slice(index + 1)\n ];\n\n bind.onChange(value.length === 0 ? null : value);\n\n // To make sure the field is still valid, we must trigger validation.\n form.validateInput(field.fieldId);\n };\n\n props.moveValueUp = (index: number) => {\n if (index <= 0) {\n return;\n }\n\n const value = [...bind.value];\n value.splice(index, 1);\n value.splice(index - 1, 0, bind.value[index]);\n\n bind.onChange(value);\n };\n\n props.moveValueDown = (index: number) => {\n if (index >= bind.value.length) {\n return;\n }\n\n const value = [...bind.value];\n value.splice(index, 1);\n value.splice(index + 1, 0, bind.value[index]);\n\n bind.onChange(value);\n };\n }\n\n return typeof children === \"function\"\n ? children(props)\n : cloneElement(children, props);\n }}\n </Bind>\n );\n } as BindComponent;\n\n // We need to keep track of current field name, to support nested fields.\n memoizedBindComponents.current[componentId].parentName = name;\n memoizedBindComponents.current[componentId].displayName = `Bind<${name}>`;\n memoizedBindComponents.current[componentId].ValidationContainer =\n createValidationContainer(name);\n\n return memoizedBindComponents.current[componentId];\n };\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,MAAM,EAAEC,YAAY,QAAQ,OAAO;AAEnD,SAASC,OAAO,QAAQ,cAAc;AACtC,SAASC,gBAAgB;AAEzB,SAASC,aAAa;AACtB,SAASC,yBAAyB;AAalC,MAAMC,mBAAmB,GAAIC,KAAoB,IAAK;EAClD,OAAO,CACHA,KAAK,CAACC,EAAE,EACRD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AM,EAAE;cAC5B;YACJ;YAEA,MAAMF,KAAK,GAAG,CAAC,GAAGL,IAAI,CAACK,KAAK,CAAC;YAC7BA,KAAK,CAACW,MAAM,CAACvC,KAAK,EAAE,CAAC,CAAC;YACtB4B,KAAK,CAACW,MAAM,CAACvC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAEuB,IAAI,CAACK,KAAK,CAAC5B,KAAK,CAAC,CAAC;YAE7CuB,IAAI,CAACQ,QAAQ,CAACH,KAAK,CAAC;UACxB,CAAC;QACL;QAEA,OAAO,OAAOR,QAAQ,KAAK,UAAU,GAC/BA,QAAQ,CAACI,KAAK,CAAC,gBACf5C,YAAY,CAACwC,QAAQ,EAAEI,KAAK,CAAC;MACvC,CACE,CAAC;IAEf,CAAkB;;IAElB;IACA3B,sBAAsB,CAACU,OAAO,CAACD,WAAW,CAAC,CAACL,UAAU,GAAGC,IAAI;IAC7DL,sBAAsB,CAACU,OAAO,CAACD,WAAW,CAAC,CAACmC,WAAW,GAAG,QAAQvC,IAAI,GAAG;IACzEL,sBAAsB,CAACU,OAAO,CAACD,WAAW,CAAC,CAACoC,mBAAmB,GAC3D1D,yBAAyB,CAACkB,IAAI,CAAC;IAEnC,OAAOL,sBAAsB,CAACU,OAAO,CAACD,WAAW,CAAC;EACtD,CAAC;AACL","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare function useRenderPlugins(): import("@webiny/plugins/PluginsContainer").WithName<import("../types").CmsModelFieldRendererPlugin>[];
@@ -0,0 +1,7 @@
1
+ import { plugins } from "@webiny/plugins";
2
+ import { useMemo } from "react";
3
+ export function useRenderPlugins() {
4
+ return useMemo(() => plugins.byType("cms-editor-field-renderer"), []);
5
+ }
6
+
7
+ //# sourceMappingURL=useRenderPlugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["plugins","useMemo","useRenderPlugins","byType"],"sources":["useRenderPlugins.ts"],"sourcesContent":["import { plugins } from \"@webiny/plugins\";\nimport { useMemo } from \"react\";\nimport type { CmsEditorFieldRendererPlugin } from \"~/types\";\n\nexport function useRenderPlugins() {\n return useMemo(\n () => plugins.byType<CmsEditorFieldRendererPlugin>(\"cms-editor-field-renderer\"),\n []\n );\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,iBAAiB;AACzC,SAASC,OAAO,QAAQ,OAAO;AAG/B,OAAO,SAASC,gBAAgBA,CAAA,EAAG;EAC/B,OAAOD,OAAO,CACV,MAAMD,OAAO,CAACG,MAAM,CAA+B,2BAA2B,CAAC,EAC/E,EACJ,CAAC;AACL","ignoreList":[]}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import type { CmsModelField } from "../types";
3
+ export type ModelFieldContext = CmsModelField;
4
+ export declare const ModelFieldContext: React.Context<{
5
+ id: string;
6
+ type: string;
7
+ fieldId: string;
8
+ storageId?: string | undefined;
9
+ label: string;
10
+ helpText?: string | undefined;
11
+ placeholderText?: string | undefined;
12
+ validation?: (import("@webiny/validation/types").Validator | import("../types").CmsModelFieldValidator)[] | undefined;
13
+ listValidation?: import("../types").CmsModelFieldValidator[] | undefined;
14
+ multipleValues?: boolean | undefined;
15
+ predefinedValues?: import("../types").CmsEditorFieldPredefinedValues | undefined;
16
+ settings?: import("../types").CmsModelFieldSettings<unknown> | undefined;
17
+ renderer: {
18
+ name: string;
19
+ settings?: Record<string, any> | undefined;
20
+ } | ((props: import("../types").CmsModelFieldRendererProps) => React.ReactNode);
21
+ tags?: string[] | undefined;
22
+ } | undefined>;
23
+ export interface ModelFieldProviderProps {
24
+ field: CmsModelField;
25
+ children: React.ReactNode;
26
+ }
27
+ export declare const ModelFieldProvider: ({ field, children }: ModelFieldProviderProps) => React.JSX.Element;
28
+ export declare const ParentValueIndexProvider: {
29
+ ({ children, ...props }: {
30
+ index: number;
31
+ } & {
32
+ children: React.ReactNode;
33
+ }): React.JSX.Element;
34
+ displayName: string;
35
+ };
36
+ export declare const useParentValueIndex: () => number;
@@ -0,0 +1,26 @@
1
+ import React from "react";
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
+ }
24
+ };
25
+
26
+ //# sourceMappingURL=ModelFieldContext.js.map
@@ -0,0 +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\";\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":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./ModelFieldContext";
2
+ export * from "./useModelField";
@@ -0,0 +1,4 @@
1
+ export * from "./ModelFieldContext";
2
+ export * from "./useModelField";
3
+
4
+ //# sourceMappingURL=index.js.map