@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.
- package/Fields/ErrorBoundary.d.ts +2 -1
- package/Fields/ErrorBoundary.js +32 -52
- package/Fields/ErrorBoundary.js.map +1 -1
- package/Fields/FieldElement.d.ts +1 -1
- package/Fields/FieldElement.js +43 -52
- package/Fields/FieldElement.js.map +1 -1
- package/Fields/FieldElementError.js +6 -13
- package/Fields/FieldElementError.js.map +1 -1
- package/Fields/Fields.js +29 -39
- package/Fields/Fields.js.map +1 -1
- package/Fields/Label.js +7 -31
- package/Fields/Label.js.map +1 -1
- package/Fields/index.js +3 -38
- package/Fields/index.js.map +1 -1
- package/Fields/useBind.d.ts +1 -1
- package/Fields/useBind.js +59 -64
- package/Fields/useBind.js.map +1 -1
- package/Fields/useRenderPlugins.js +4 -12
- package/Fields/useRenderPlugins.js.map +1 -1
- package/ModelFieldProvider/ModelFieldContext.d.ts +2 -2
- package/ModelFieldProvider/ModelFieldContext.js +16 -21
- package/ModelFieldProvider/ModelFieldContext.js.map +1 -1
- package/ModelFieldProvider/index.js +2 -27
- package/ModelFieldProvider/index.js.map +1 -1
- package/ModelFieldProvider/useModelField.d.ts +1 -1
- package/ModelFieldProvider/useModelField.js +15 -23
- package/ModelFieldProvider/useModelField.js.map +1 -1
- package/ModelProvider/ModelContext.d.ts +1 -1
- package/ModelProvider/ModelContext.js +7 -13
- package/ModelProvider/ModelContext.js.map +1 -1
- package/ModelProvider/index.js +2 -27
- package/ModelProvider/index.js.map +1 -1
- package/ModelProvider/useModel.d.ts +1 -1
- package/ModelProvider/useModel.js +6 -12
- package/ModelProvider/useModel.js.map +1 -1
- package/constants.js +1 -7
- package/constants.js.map +1 -1
- package/createFieldsList.d.ts +1 -1
- package/createFieldsList.js +23 -26
- package/createFieldsList.js.map +1 -1
- package/createValidationContainer.js +11 -16
- package/createValidationContainer.js.map +1 -1
- package/createValidators.d.ts +2 -2
- package/createValidators.js +18 -28
- package/createValidators.js.map +1 -1
- package/entries.graphql.d.ts +2 -2
- package/entries.graphql.js +292 -70
- package/entries.graphql.js.map +1 -1
- package/getModelTitleFieldId.d.ts +1 -1
- package/getModelTitleFieldId.js +1 -7
- package/getModelTitleFieldId.js.map +1 -1
- package/index.js +10 -115
- package/index.js.map +1 -1
- package/package.json +12 -13
- package/prepareFormData.d.ts +1 -1
- package/prepareFormData.js +22 -41
- package/prepareFormData.js.map +1 -1
- package/types/index.d.ts +16 -10
- package/types/index.js +54 -38
- package/types/index.js.map +1 -1
- package/types/model.d.ts +4 -4
- package/types/model.js +1 -5
- package/types/model.js.map +1 -1
- package/types/shared.js +1 -5
- package/types/validation.d.ts +3 -3
- package/types/validation.js +1 -5
- package/types/validation.js.map +1 -1
package/Fields/useBind.js
CHANGED
|
@@ -1,116 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
20
|
-
function useBind(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
37
|
+
const defaultValueFromSettings = !isMultipleValues ? field.settings?.defaultValue : null;
|
|
47
38
|
memoizedBindComponents.current[componentId] = function UseBind(params) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
defaultValue =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
53
|
+
field
|
|
61
54
|
}
|
|
62
|
-
},
|
|
55
|
+
}, bind => {
|
|
63
56
|
// Multiple-values functions below.
|
|
64
|
-
|
|
57
|
+
const props = {
|
|
58
|
+
...bind
|
|
59
|
+
};
|
|
65
60
|
if (field.multipleValues && index === -1) {
|
|
66
|
-
props.appendValue =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
bind.onChange([
|
|
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 =
|
|
72
|
-
bind.onChange([newValue
|
|
66
|
+
props.prependValue = newValue => {
|
|
67
|
+
bind.onChange([newValue, ...(bind.value || [])]);
|
|
73
68
|
};
|
|
74
|
-
props.appendValues =
|
|
75
|
-
bind.onChange([
|
|
69
|
+
props.appendValues = newValues => {
|
|
70
|
+
bind.onChange([...(bind.value || []), ...newValues]);
|
|
76
71
|
};
|
|
77
|
-
props.removeValue =
|
|
72
|
+
props.removeValue = index => {
|
|
78
73
|
if (index < 0) {
|
|
79
74
|
return;
|
|
80
75
|
}
|
|
81
|
-
|
|
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 =
|
|
82
|
+
props.moveValueUp = index => {
|
|
88
83
|
if (index <= 0) {
|
|
89
84
|
return;
|
|
90
85
|
}
|
|
91
|
-
|
|
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 =
|
|
91
|
+
props.moveValueDown = index => {
|
|
97
92
|
if (index >= bind.value.length) {
|
|
98
93
|
return;
|
|
99
94
|
}
|
|
100
|
-
|
|
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__*/
|
|
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 =
|
|
113
|
-
memoizedBindComponents.current[componentId].ValidationContainer =
|
|
107
|
+
memoizedBindComponents.current[componentId].displayName = `Bind<${name}>`;
|
|
108
|
+
memoizedBindComponents.current[componentId].ValidationContainer = createValidationContainer(name);
|
|
114
109
|
return memoizedBindComponents.current[componentId];
|
|
115
110
|
};
|
|
116
111
|
}
|
package/Fields/useBind.js.map
CHANGED
|
@@ -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,mBAAmB,CAACC,KAAK,CAAC;EAC3C,IAAMiB,IAAI,GAAG,IAAAC,aAAO,EAAC,CAAC;EAEtB,OAAO,YAAgB;IAAA,IAAfC,KAAK,GAAAC,SAAA,CAAAC,M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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,YAAY,QAAQ,OAAO;AAEnD,SAASC,OAAO,QAAQ,cAAc;AACtC,SAASC,gBAAgB;AAEzB,SAASC,aAAa;AACtB,SAASC,yBAAyB;AAalC,MAAMC,mBAAm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Aa,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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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":["
|
|
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("
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
19
|
-
Provider
|
|
20
|
-
useHook
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
const {
|
|
13
|
+
Provider,
|
|
14
|
+
useHook
|
|
15
|
+
} = createGenericContext("FieldIndex");
|
|
16
|
+
export const ParentValueIndexProvider = Provider;
|
|
17
|
+
export const useParentValueIndex = () => {
|
|
23
18
|
try {
|
|
24
|
-
|
|
19
|
+
const context = useHook();
|
|
25
20
|
return context.index;
|
|
26
|
-
} catch
|
|
21
|
+
} catch {
|
|
27
22
|
return -1;
|
|
28
23
|
}
|
|
29
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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
|
-
|
|
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":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelFieldContext\";\nexport * from \"./useModelField\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
|
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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(
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
export const useModelField = makeDecoratable(() => {
|
|
16
|
+
const field = useContext(ModelFieldContext);
|
|
17
|
+
const parentValueIndex = useParentValueIndex();
|
|
26
18
|
if (!field) {
|
|
27
|
-
throw Error(
|
|
19
|
+
throw Error(`Missing "ModelFieldProvider" in the component tree. Are you using the "useModelField()" hook in the right place?`);
|
|
28
20
|
}
|
|
29
|
-
|
|
21
|
+
const fieldPlugin = getFieldPlugin(field.type);
|
|
30
22
|
return {
|
|
31
|
-
field
|
|
32
|
-
fieldPlugin
|
|
33
|
-
parentValueIndex
|
|
23
|
+
field,
|
|
24
|
+
fieldPlugin,
|
|
25
|
+
parentValueIndex
|
|
34
26
|
};
|
|
35
27
|
});
|
|
36
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})
|
|
7
|
-
|
|
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":["
|
|
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":[]}
|
package/ModelProvider/index.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
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":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ModelContext\";\nexport * from \"./useModel\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
6
|
+
export function useModel() {
|
|
7
|
+
const model = useContext(ModelContext);
|
|
14
8
|
if (!model) {
|
|
15
|
-
throw Error(
|
|
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
|
|
12
|
+
model
|
|
19
13
|
};
|
|
20
14
|
}
|
|
21
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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
|
-
|
|
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"
|
|
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":[]}
|
package/createFieldsList.d.ts
CHANGED