@webiny/app-headless-cms-common 5.43.3 → 6.0.0-alpha.1

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 (67) hide show
  1. package/Fields/ErrorBoundary.d.ts +2 -1
  2. package/Fields/ErrorBoundary.js +32 -52
  3. package/Fields/ErrorBoundary.js.map +1 -1
  4. package/Fields/FieldElement.d.ts +1 -1
  5. package/Fields/FieldElement.js +43 -52
  6. package/Fields/FieldElement.js.map +1 -1
  7. package/Fields/FieldElementError.js +6 -13
  8. package/Fields/FieldElementError.js.map +1 -1
  9. package/Fields/Fields.js +29 -39
  10. package/Fields/Fields.js.map +1 -1
  11. package/Fields/Label.js +7 -31
  12. package/Fields/Label.js.map +1 -1
  13. package/Fields/index.js +3 -38
  14. package/Fields/index.js.map +1 -1
  15. package/Fields/useBind.d.ts +1 -1
  16. package/Fields/useBind.js +59 -64
  17. package/Fields/useBind.js.map +1 -1
  18. package/Fields/useRenderPlugins.js +4 -12
  19. package/Fields/useRenderPlugins.js.map +1 -1
  20. package/ModelFieldProvider/ModelFieldContext.d.ts +2 -2
  21. package/ModelFieldProvider/ModelFieldContext.js +16 -21
  22. package/ModelFieldProvider/ModelFieldContext.js.map +1 -1
  23. package/ModelFieldProvider/index.js +2 -27
  24. package/ModelFieldProvider/index.js.map +1 -1
  25. package/ModelFieldProvider/useModelField.d.ts +1 -1
  26. package/ModelFieldProvider/useModelField.js +15 -23
  27. package/ModelFieldProvider/useModelField.js.map +1 -1
  28. package/ModelProvider/ModelContext.d.ts +1 -1
  29. package/ModelProvider/ModelContext.js +7 -13
  30. package/ModelProvider/ModelContext.js.map +1 -1
  31. package/ModelProvider/index.js +2 -27
  32. package/ModelProvider/index.js.map +1 -1
  33. package/ModelProvider/useModel.d.ts +1 -1
  34. package/ModelProvider/useModel.js +6 -12
  35. package/ModelProvider/useModel.js.map +1 -1
  36. package/constants.js +1 -7
  37. package/constants.js.map +1 -1
  38. package/createFieldsList.d.ts +1 -1
  39. package/createFieldsList.js +23 -26
  40. package/createFieldsList.js.map +1 -1
  41. package/createValidationContainer.js +11 -16
  42. package/createValidationContainer.js.map +1 -1
  43. package/createValidators.d.ts +2 -2
  44. package/createValidators.js +18 -28
  45. package/createValidators.js.map +1 -1
  46. package/entries.graphql.d.ts +2 -2
  47. package/entries.graphql.js +292 -70
  48. package/entries.graphql.js.map +1 -1
  49. package/getModelTitleFieldId.d.ts +1 -1
  50. package/getModelTitleFieldId.js +1 -7
  51. package/getModelTitleFieldId.js.map +1 -1
  52. package/index.js +10 -115
  53. package/index.js.map +1 -1
  54. package/package.json +12 -13
  55. package/prepareFormData.d.ts +1 -1
  56. package/prepareFormData.js +22 -41
  57. package/prepareFormData.js.map +1 -1
  58. package/types/index.d.ts +16 -10
  59. package/types/index.js +54 -38
  60. package/types/index.js.map +1 -1
  61. package/types/model.d.ts +4 -4
  62. package/types/model.js +1 -5
  63. package/types/model.js.map +1 -1
  64. package/types/shared.js +1 -5
  65. package/types/validation.d.ts +3 -3
  66. package/types/validation.js +1 -5
  67. package/types/validation.js.map +1 -1
package/Fields/useBind.js CHANGED
@@ -1,116 +1,111 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.useBind = useBind;
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
- var _react = _interopRequireWildcard(require("react"));
12
- var _form = require("@webiny/form");
13
- var _createValidators = require("../createValidators");
14
- var _ModelFieldProvider = require("../ModelFieldProvider");
15
- var _createValidationContainer = require("../createValidationContainer");
16
- var createFieldCacheKey = function createFieldCacheKey(field) {
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 => {
17
7
  return [field.id, field.fieldId, JSON.stringify(field.validation), JSON.stringify(field.listValidation)].join(";");
18
8
  };
19
- var emptyValidators = [];
20
- function useBind(_ref) {
21
- var Bind = _ref.Bind;
22
- var _useModelField = (0, _ModelFieldProvider.useModelField)(),
23
- field = _useModelField.field;
24
- var memoizedBindComponents = (0, _react.useRef)({});
25
- var cacheKey = createFieldCacheKey(field);
26
- var form = (0, _form.useForm)();
27
- return function () {
28
- var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
29
- var parentName = Bind.parentName;
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;
30
23
 
31
24
  // If there's a parent name assigned to the given Bind component, we need to include it in the new field "name".
32
25
  // This allows us to have nested fields (like "object" field with nested properties)
33
- var name = [parentName, field.fieldId, index >= 0 ? index : undefined].filter(function (v) {
34
- return v !== undefined;
35
- }).join(".");
36
- var componentId = "".concat(name, ";").concat(cacheKey);
26
+ const name = [parentName, field.fieldId, index >= 0 ? index : undefined].filter(v => v !== undefined).join(".");
27
+ const componentId = `${name};${cacheKey}`;
37
28
  if (memoizedBindComponents.current[componentId]) {
38
29
  return memoizedBindComponents.current[componentId];
39
30
  }
40
- var validators = (0, _createValidators.createValidators)(field, field.validation || emptyValidators);
41
- var listValidators = (0, _createValidators.createValidators)(field, field.listValidation || emptyValidators);
42
- var isMultipleValues = index === -1 && field.multipleValues;
43
- var inputValidators = isMultipleValues ? listValidators : validators;
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;
44
35
 
45
36
  // We only use default values for single-value fields.
46
- var defaultValueFromSettings = !isMultipleValues ? field.settings?.defaultValue : null;
37
+ const defaultValueFromSettings = !isMultipleValues ? field.settings?.defaultValue : null;
47
38
  memoizedBindComponents.current[componentId] = function UseBind(params) {
48
- var childName = params.name,
49
- childValidators = params.validators,
50
- children = params.children,
51
- _params$defaultValue = params.defaultValue,
52
- defaultValue = _params$defaultValue === void 0 ? defaultValueFromSettings : _params$defaultValue;
53
- var _useModelField2 = (0, _ModelFieldProvider.useModelField)(),
54
- field = _useModelField2.field;
55
- return /*#__PURE__*/_react.default.createElement(Bind, {
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, {
56
49
  name: childName || name,
57
50
  validators: childValidators || inputValidators,
58
51
  defaultValue: defaultValue ?? null,
59
52
  context: {
60
- field: field
53
+ field
61
54
  }
62
- }, function (bind) {
55
+ }, bind => {
63
56
  // Multiple-values functions below.
64
- var props = (0, _objectSpread2.default)({}, bind);
57
+ const props = {
58
+ ...bind
59
+ };
65
60
  if (field.multipleValues && index === -1) {
66
- props.appendValue = function (newValue, index) {
67
- var currentValue = bind.value || [];
68
- var newIndex = index ?? currentValue.length;
69
- bind.onChange([].concat((0, _toConsumableArray2.default)(currentValue.slice(0, newIndex)), [newValue], (0, _toConsumableArray2.default)(currentValue.slice(newIndex))));
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)]);
70
65
  };
71
- props.prependValue = function (newValue) {
72
- bind.onChange([newValue].concat((0, _toConsumableArray2.default)(bind.value || [])));
66
+ props.prependValue = newValue => {
67
+ bind.onChange([newValue, ...(bind.value || [])]);
73
68
  };
74
- props.appendValues = function (newValues) {
75
- bind.onChange([].concat((0, _toConsumableArray2.default)(bind.value || []), (0, _toConsumableArray2.default)(newValues)));
69
+ props.appendValues = newValues => {
70
+ bind.onChange([...(bind.value || []), ...newValues]);
76
71
  };
77
- props.removeValue = function (index) {
72
+ props.removeValue = index => {
78
73
  if (index < 0) {
79
74
  return;
80
75
  }
81
- var value = [].concat((0, _toConsumableArray2.default)(bind.value.slice(0, index)), (0, _toConsumableArray2.default)(bind.value.slice(index + 1)));
76
+ const value = [...bind.value.slice(0, index), ...bind.value.slice(index + 1)];
82
77
  bind.onChange(value.length === 0 ? null : value);
83
78
 
84
79
  // To make sure the field is still valid, we must trigger validation.
85
80
  form.validateInput(field.fieldId);
86
81
  };
87
- props.moveValueUp = function (index) {
82
+ props.moveValueUp = index => {
88
83
  if (index <= 0) {
89
84
  return;
90
85
  }
91
- var value = (0, _toConsumableArray2.default)(bind.value);
86
+ const value = [...bind.value];
92
87
  value.splice(index, 1);
93
88
  value.splice(index - 1, 0, bind.value[index]);
94
89
  bind.onChange(value);
95
90
  };
96
- props.moveValueDown = function (index) {
91
+ props.moveValueDown = index => {
97
92
  if (index >= bind.value.length) {
98
93
  return;
99
94
  }
100
- var value = (0, _toConsumableArray2.default)(bind.value);
95
+ const value = [...bind.value];
101
96
  value.splice(index, 1);
102
97
  value.splice(index + 1, 0, bind.value[index]);
103
98
  bind.onChange(value);
104
99
  };
105
100
  }
106
- return typeof children === "function" ? children(props) : /*#__PURE__*/(0, _react.cloneElement)(children, props);
101
+ return typeof children === "function" ? children(props) : /*#__PURE__*/cloneElement(children, props);
107
102
  });
108
103
  };
109
104
 
110
105
  // We need to keep track of current field name, to support nested fields.
111
106
  memoizedBindComponents.current[componentId].parentName = name;
112
- memoizedBindComponents.current[componentId].displayName = "Bind<".concat(name, ">");
113
- memoizedBindComponents.current[componentId].ValidationContainer = (0, _createValidationContainer.createValidationContainer)(name);
107
+ memoizedBindComponents.current[componentId].displayName = `Bind<${name}>`;
108
+ memoizedBindComponents.current[componentId].ValidationContainer = createValidationContainer(name);
114
109
  return memoizedBindComponents.current[componentId];
115
110
  };
116
111
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_form","_createValidators","_ModelFieldProvider","_createValidationContainer","createFieldCacheKey","field","id","fieldId","JSON","stringify","validation","listValidation","join","emptyValidators","useBind","_ref","Bind","_useModelField","useModelField","memoizedBindComponents","useRef","cacheKey","form","useForm","index","arguments","length","undefined","parentName","name","filter","v","componentId","concat","current","validators","createValidators","listValidators","isMultipleValues","multipleValues","inputValidators","defaultValueFromSettings","settings","defaultValue","UseBind","params","childName","childValidators","children","_params$defaultValue","_useModelField2","default","createElement","context","bind","props","_objectSpread2","appendValue","newValue","currentValue","value","newIndex","onChange","_toConsumableArray2","slice","prependValue","appendValues","newValues","removeValue","validateInput","moveValueUp","splice","moveValueDown","cloneElement","displayName","ValidationContainer","createValidationContainer"],"sources":["useBind.tsx"],"sourcesContent":["import React, { useRef, cloneElement } from \"react\";\nimport { Validator } from \"@webiny/validation/types\";\nimport { useForm } from \"@webiny/form\";\nimport { createValidators } from \"~/createValidators\";\nimport { 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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,0BAAA,GAAAJ,OAAA;AAaA,IAAMK,mBAAmB,GAAG,SAAtBA,mBAAmBA,CAAIC,KAAoB,EAAK;EAClD,OAAO,CACHA,KAAK,CAACC,EAAE,EACRD,KAAK,CAACE,OAAO,EACbC,IAAI,CAACC,SAAS,CAACJ,KAAK,CAACK,UAAU,CAAC,EAChCF,IAAI,CAACC,SAAS,CAACJ,KAAK,CAACM,cAAc,CAAC,CACvC,CAACC,IAAI,CAAC,GAAG,CAAC;AACf,CAAC;AAMD,IAAMC,eAA4B,GAAG,EAAE;AAEhC,SAASC,OAAOA,CAAAC,IAAA,EAAyB;EAAA,IAAtBC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAC1B,IAAAC,cAAA,GAAkB,IAAAC,iCAAa,EAAC,CAAC;IAAzBb,KAAK,GAAAY,cAAA,CAALZ,KAAK;EACb,IAAMc,sBAAsB,GAAG,IAAAC,aAAM,EAAgC,CAAC,CAAC,CAAC;EACxE,IAAMC,QAAQ,GAAGjB,mBAA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,QAAQ,CAACF,KAAK,CAAC;UACxB,CAAC;UAEDL,KAAK,CAACiB,aAAa,GAAG,UAAChD,KAAa,EAAK;YACrC,IAAIA,KAAK,IAAI8B,IAAI,CAACM,KAAK,CAAClC,MAAM,EAAE;cAC5B;YACJ;YAEA,IAAMkC,KAAK,OAAAG,mBAAA,CAAAZ,OAAA,EAAOG,IAAI,CAACM,KAAK,CAAC;YAC7BA,KAAK,CAACW,MAAM,CAAC/C,KAAK,EAAE,CAAC,CAAC;YACtBoC,KAAK,CAACW,MAAM,CAAC/C,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE8B,IAAI,CAACM,KAAK,CAACpC,KAAK,CAAC,CAAC;YAE7C8B,IAAI,CAACQ,QAAQ,CAACF,KAAK,CAAC;UACxB,CAAC;QACL;QAEA,OAAO,OAAOZ,QAAQ,KAAK,UAAU,GAC/BA,QAAQ,CAACO,KAAK,CAAC,gBACf,IAAAkB,mBAAY,EAACzB,QAAQ,EAAEO,KAAK,CAAC;MACvC,CACE,CAAC;IAEf,CAAkB;;IAElB;IACApC,sBAAsB,CAACe,OAAO,CAACF,WAAW,CAAC,CAACJ,UAAU,GAAGC,IAAI;IAC7DV,sBAAsB,CAACe,OAAO,CAACF,WAAW,CAAC,CAAC0C,WAAW,WAAAzC,MAAA,CAAWJ,IAAI,MAAG;IACzEV,sBAAsB,CAACe,OAAO,CAACF,WAAW,CAAC,CAAC2C,mBAAmB,GAC3D,IAAAC,oDAAyB,EAAC/C,IAAI,CAAC;IAEnC,OAAOV,sBAAsB,CAACe,OAAO,CAACF,WAAW,CAAC;EACtD,CAAC;AACL","ignoreList":[]}
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,YA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AK,CAAC5B,KAAK,CAAC,CAAC;YAE7CuB,IAAI,CAACQ,QAAQ,CAACH,KAAK,CAAC;UACxB,CAAC;UAEDJ,KAAK,CAACgB,aAAa,GAAIxC,KAAa,IAAK;YACrC,IAAIA,KAAK,IAAIuB,IAAI,CAACK,KAAK,CAACE,MAAM,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":[]}
@@ -1,15 +1,7 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useRenderPlugins = useRenderPlugins;
7
- var _plugins = require("@webiny/plugins");
8
- var _react = require("react");
9
- function useRenderPlugins() {
10
- return (0, _react.useMemo)(function () {
11
- return _plugins.plugins.byType("cms-editor-field-renderer");
12
- }, []);
1
+ import { plugins } from "@webiny/plugins";
2
+ import { useMemo } from "react";
3
+ export function useRenderPlugins() {
4
+ return useMemo(() => plugins.byType("cms-editor-field-renderer"), []);
13
5
  }
14
6
 
15
7
  //# sourceMappingURL=useRenderPlugins.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_plugins","require","_react","useRenderPlugins","useMemo","plugins","byType"],"sources":["useRenderPlugins.ts"],"sourcesContent":["import { plugins } from \"@webiny/plugins\";\nimport { useMemo } from \"react\";\nimport { CmsEditorFieldRendererPlugin } from \"~/types\";\n\nexport function useRenderPlugins() {\n return useMemo(\n () => plugins.byType<CmsEditorFieldRendererPlugin>(\"cms-editor-field-renderer\"),\n []\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGO,SAASE,gBAAgBA,CAAA,EAAG;EAC/B,OAAO,IAAAC,cAAO,EACV;IAAA,OAAMC,gBAAO,CAACC,MAAM,CAA+B,2BAA2B,CAAC;EAAA,GAC/E,EACJ,CAAC;AACL","ignoreList":[]}
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":[]}
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CmsModelField } from "../types";
2
+ import type { CmsModelField } from "../types";
3
3
  export type ModelFieldContext = CmsModelField;
4
4
  export declare const ModelFieldContext: React.Context<{
5
5
  id: string;
@@ -9,7 +9,7 @@ export declare const ModelFieldContext: React.Context<{
9
9
  label: string;
10
10
  helpText?: string | undefined;
11
11
  placeholderText?: string | undefined;
12
- validation?: (import("../types").CmsModelFieldValidator | import("@webiny/validation/types").Validator)[] | undefined;
12
+ validation?: (import("@webiny/validation/types").Validator | import("../types").CmsModelFieldValidator)[] | undefined;
13
13
  listValidation?: import("../types").CmsModelFieldValidator[] | undefined;
14
14
  multipleValues?: boolean | undefined;
15
15
  predefinedValues?: import("../types").CmsEditorFieldPredefinedValues | undefined;
@@ -1,29 +1,24 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.useParentValueIndex = exports.ParentValueIndexProvider = exports.ModelFieldProvider = exports.ModelFieldContext = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _appAdmin = require("@webiny/app-admin");
10
- var ModelFieldContext = exports.ModelFieldContext = /*#__PURE__*/_react.default.createContext(undefined);
11
- var ModelFieldProvider = exports.ModelFieldProvider = function ModelFieldProvider(_ref) {
12
- var field = _ref.field,
13
- children = _ref.children;
14
- return /*#__PURE__*/_react.default.createElement(ModelFieldContext.Provider, {
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, {
15
9
  value: field
16
10
  }, children);
17
11
  };
18
- var _createGenericContext = (0, _appAdmin.createGenericContext)("FieldIndex"),
19
- Provider = _createGenericContext.Provider,
20
- useHook = _createGenericContext.useHook;
21
- var ParentValueIndexProvider = exports.ParentValueIndexProvider = Provider;
22
- var useParentValueIndex = exports.useParentValueIndex = function useParentValueIndex() {
12
+ const {
13
+ Provider,
14
+ useHook
15
+ } = createGenericContext("FieldIndex");
16
+ export const ParentValueIndexProvider = Provider;
17
+ export const useParentValueIndex = () => {
23
18
  try {
24
- var context = useHook();
19
+ const context = useHook();
25
20
  return context.index;
26
- } catch (_unused) {
21
+ } catch {
27
22
  return -1;
28
23
  }
29
24
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_appAdmin","ModelFieldContext","exports","React","createContext","undefined","ModelFieldProvider","_ref","field","children","default","createElement","Provider","value","_createGenericContext","createGenericContext","useHook","ParentValueIndexProvider","useParentValueIndex","context","index","_unused"],"sources":["ModelFieldContext.tsx"],"sourcesContent":["import React from \"react\";\nimport { 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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAIO,IAAME,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,gBAAGE,cAAK,CAACC,aAAa,CAAgCC,SAAS,CAAC;AAOvF,IAAMC,kBAAkB,GAAAJ,OAAA,CAAAI,kBAAA,GAAG,SAArBA,kBAAkBA,CAAAC,IAAA,EAAqD;EAAA,IAA/CC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAChD,oBAAOZ,MAAA,CAAAa,OAAA,CAAAC,aAAA,CAACV,iBAAiB,CAACW,QAAQ;IAACC,KAAK,EAAEL;EAAM,GAAEC,QAAqC,CAAC;AAC5F,CAAC;AAED,IAAAK,qBAAA,GAA8B,IAAAC,8BAAoB,EAAoB,YAAY,CAAC;EAA3EH,QAAQ,GAAAE,qBAAA,CAARF,QAAQ;EAAEI,OAAO,GAAAF,qBAAA,CAAPE,OAAO;AAElB,IAAMC,wBAAwB,GAAAf,OAAA,CAAAe,wBAAA,GAAGL,QAAQ;AAEzC,IAAMM,mBAAmB,GAAAhB,OAAA,CAAAgB,mBAAA,GAAG,SAAtBA,mBAAmBA,CAAA,EAAS;EACrC,IAAI;IACA,IAAMC,OAAO,GAAGH,OAAO,CAAC,CAAC;IACzB,OAAOG,OAAO,CAACC,KAAK;EACxB,CAAC,CAAC,OAAAC,OAAA,EAAM;IACJ,OAAO,CAAC,CAAC;EACb;AACJ,CAAC","ignoreList":[]}
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":[]}
@@ -1,29 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _ModelFieldContext = require("./ModelFieldContext");
7
- Object.keys(_ModelFieldContext).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _ModelFieldContext[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _ModelFieldContext[key];
14
- }
15
- });
16
- });
17
- var _useModelField = require("./useModelField");
18
- Object.keys(_useModelField).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _useModelField[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _useModelField[key];
25
- }
26
- });
27
- });
1
+ export * from "./ModelFieldContext";
2
+ export * from "./useModelField";
28
3
 
29
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_ModelFieldContext","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_useModelField"],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelFieldContext\";\nexport * from \"./useModelField\";\n"],"mappings":";;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,kBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,kBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,kBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,cAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,cAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,cAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,cAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelFieldContext\";\nexport * from \"./useModelField\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { CmsModelField, CmsModelFieldTypePlugin } from "../types";
2
+ import type { CmsModelField, CmsModelFieldTypePlugin } from "../types";
3
3
  export interface UseModelField {
4
4
  field: CmsModelField;
5
5
  parentValueIndex: number;
@@ -1,36 +1,28 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useModelField = void 0;
7
- var _react = require("react");
8
- var _plugins = require("@webiny/plugins");
9
- var _reactComposition = require("@webiny/react-composition");
10
- var _ModelFieldContext = require("./ModelFieldContext");
11
- var getFieldPlugin = function getFieldPlugin(type) {
12
- var plugin = _plugins.plugins.byType("cms-editor-field-type").find(function (plugin) {
13
- return plugin.field.type === type;
14
- });
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);
15
7
  if (!plugin) {
16
- throw Error("Missing plugin for field type \"".concat(type, "\"!"));
8
+ throw Error(`Missing plugin for field type "${type}"!`);
17
9
  }
18
10
  return plugin;
19
11
  };
20
12
  /**
21
13
  * Get model field from the current context.
22
14
  */
23
- var useModelField = exports.useModelField = (0, _reactComposition.makeDecoratable)(function () {
24
- var field = (0, _react.useContext)(_ModelFieldContext.ModelFieldContext);
25
- var parentValueIndex = (0, _ModelFieldContext.useParentValueIndex)();
15
+ export const useModelField = makeDecoratable(() => {
16
+ const field = useContext(ModelFieldContext);
17
+ const parentValueIndex = useParentValueIndex();
26
18
  if (!field) {
27
- throw Error("Missing \"ModelFieldProvider\" in the component tree. Are you using the \"useModelField()\" hook in the right place?");
19
+ throw Error(`Missing "ModelFieldProvider" in the component tree. Are you using the "useModelField()" hook in the right place?`);
28
20
  }
29
- var fieldPlugin = getFieldPlugin(field.type);
21
+ const fieldPlugin = getFieldPlugin(field.type);
30
22
  return {
31
- field: field,
32
- fieldPlugin: fieldPlugin,
33
- parentValueIndex: parentValueIndex
23
+ field,
24
+ fieldPlugin,
25
+ parentValueIndex
34
26
  };
35
27
  });
36
28
 
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_plugins","_reactComposition","_ModelFieldContext","getFieldPlugin","type","plugin","plugins","byType","find","field","Error","concat","useModelField","exports","makeDecoratable","useContext","ModelFieldContext","parentValueIndex","useParentValueIndex","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 { 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,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AAOA,IAAMI,cAA8B,GAAG,SAAjCA,cAA8BA,CAAGC,IAAI,EAAI;EAC3C,IAAMC,MAAM,GAAGC,gBAAO,CACjBC,MAAM,CAA0B,uBAAuB,CAAC,CACxDC,IAAI,CAAC,UAAAH,MAAM;IAAA,OAAIA,MAAM,CAACI,KAAK,CAACL,IAAI,KAAKA,IAAI;EAAA,EAAC;EAE/C,IAAI,CAACC,MAAM,EAAE;IACT,MAAMK,KAAK,oCAAAC,MAAA,CAAmCP,IAAI,QAAI,CAAC;EAC3D;EAEA,OAAOC,MAAM;AACjB,CAAC;AAQD;AACA;AACA;AACO,IAAMO,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,IAAAE,iCAAe,EAAC,YAAqB;EAC9D,IAAML,KAAK,GAAG,IAAAM,iBAAU,EAACC,oCAAiB,CAAC;EAC3C,IAAMC,gBAAgB,GAAG,IAAAC,sCAAmB,EAAC,CAAC;EAE9C,IAAI,CAACT,KAAK,EAAE;IACR,MAAMC,KAAK,uHAEX,CAAC;EACL;EAEA,IAAMS,WAAW,GAAGhB,cAAc,CAACM,KAAK,CAACL,IAAI,CAAC;EAE9C,OAAO;IAAEK,KAAK,EAALA,KAAK;IAAEU,WAAW,EAAXA,WAAW;IAAEF,gBAAgB,EAAhBA;EAAiB,CAAC;AACnD,CAAC,CAAC","ignoreList":[]}
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":[]}
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CmsModel } from "../types";
2
+ import type { CmsModel } from "../types";
3
3
  export type ModelContext = CmsModel;
4
4
  export declare const ModelContext: React.Context<CmsModel | undefined>;
5
5
  export interface ModelProviderProps {
@@ -1,16 +1,10 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.ModelProvider = exports.ModelContext = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var ModelContext = exports.ModelContext = /*#__PURE__*/_react.default.createContext(undefined);
10
- var ModelProvider = exports.ModelProvider = function ModelProvider(_ref) {
11
- var model = _ref.model,
12
- children = _ref.children;
13
- return /*#__PURE__*/_react.default.createElement(ModelContext.Provider, {
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, {
14
8
  value: model
15
9
  }, children);
16
10
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","ModelContext","exports","React","createContext","undefined","ModelProvider","_ref","model","children","default","createElement","Provider","value"],"sources":["ModelContext.tsx"],"sourcesContent":["import React from \"react\";\nimport { 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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKO,IAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,gBAAGE,cAAK,CAACC,aAAa,CAA2BC,SAAS,CAAC;AAO7E,IAAMC,aAAa,GAAAJ,OAAA,CAAAI,aAAA,GAAG,SAAhBA,aAAaA,CAAAC,IAAA,EAAgD;EAAA,IAA1CC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAC3C,oBAAOX,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACV,YAAY,CAACW,QAAQ;IAACC,KAAK,EAAEL;EAAM,GAAEC,QAAgC,CAAC;AAClF,CAAC","ignoreList":[]}
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":[]}
@@ -1,29 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _ModelContext = require("./ModelContext");
7
- Object.keys(_ModelContext).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _ModelContext[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _ModelContext[key];
14
- }
15
- });
16
- });
17
- var _useModel = require("./useModel");
18
- Object.keys(_useModel).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _useModel[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _useModel[key];
25
- }
26
- });
27
- });
1
+ export * from "./ModelContext";
2
+ export * from "./useModel";
28
3
 
29
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_ModelContext","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_useModel"],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelContext\";\nexport * from \"./useModel\";\n"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,SAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,SAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,SAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,SAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelContext\";\nexport * from \"./useModel\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { CmsModel } from "../types";
1
+ import type { CmsModel } from "../types";
2
2
  type UseModelReturnType = {
3
3
  model: CmsModel;
4
4
  };
@@ -1,21 +1,15 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useModel = useModel;
7
- var _react = require("react");
8
- var _ModelContext = require("./ModelContext");
1
+ import { useContext } from "react";
2
+ import { ModelContext } from "./ModelContext";
9
3
  /**
10
4
  * Get model from the current context.
11
5
  */
12
- function useModel() {
13
- var model = (0, _react.useContext)(_ModelContext.ModelContext);
6
+ export function useModel() {
7
+ const model = useContext(ModelContext);
14
8
  if (!model) {
15
- throw Error("Missing \"ModelContext\" in the component tree. Are you using the \"useModel()\" hook in the right place?");
9
+ throw Error(`Missing "ModelContext" in the component tree. Are you using the "useModel()" hook in the right place?`);
16
10
  }
17
11
  return {
18
- model: model
12
+ model
19
13
  };
20
14
  }
21
15
 
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_ModelContext","useModel","model","useContext","ModelContext","Error"],"sources":["useModel.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ModelContext } from \"./ModelContext\";\nimport { 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,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAOA;AACA;AACA;AACO,SAASE,QAAQA,CAAA,EAAuB;EAC3C,IAAMC,KAAK,GAAG,IAAAC,iBAAU,EAACC,0BAAY,CAAC;EACtC,IAAI,CAACF,KAAK,EAAE;IACR,MAAMG,KAAK,4GAEX,CAAC;EACL;EAEA,OAAO;IAAEH,KAAK,EAALA;EAAM,CAAC;AACpB","ignoreList":[]}
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/constants.js CHANGED
@@ -1,9 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CMS_MODEL_SINGLETON_TAG = void 0;
7
- var CMS_MODEL_SINGLETON_TAG = exports.CMS_MODEL_SINGLETON_TAG = "singleton";
1
+ export const CMS_MODEL_SINGLETON_TAG = "singleton";
8
2
 
9
3
  //# sourceMappingURL=constants.js.map
package/constants.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["CMS_MODEL_SINGLETON_TAG","exports"],"sources":["constants.ts"],"sourcesContent":["export const CMS_MODEL_SINGLETON_TAG = \"singleton\";\n"],"mappings":";;;;;;AAAO,IAAMA,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,WAAW","ignoreList":[]}
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":[]}
@@ -1,4 +1,4 @@
1
- import { CmsModel, CmsModelField } from "./types";
1
+ import type { CmsModel, CmsModelField } from "./types";
2
2
  interface CreateFieldsListParams {
3
3
  model: CmsModel;
4
4
  fields: CmsModelField[];