@webiny/app 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/App.d.ts +5 -12
- package/App.js +70 -84
- package/App.js.map +1 -1
- package/AppContainer.d.ts +23 -0
- package/AppContainer.js +9 -0
- package/AppContainer.js.map +1 -0
- package/apollo-client/InMemoryCache.d.ts +3 -2
- package/apollo-client/InMemoryCache.js +16 -47
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/apollo-client/IntrospectionFragmentMatcher.d.ts +2 -2
- package/apollo-client/IntrospectionFragmentMatcher.js +33 -50
- package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
- package/components/Image.d.ts +1 -1
- package/components/Image.js +11 -19
- package/components/Image.js.map +1 -1
- package/components/Routes.js +13 -23
- package/components/Routes.js.map +1 -1
- package/components/View.js +14 -26
- package/components/View.js.map +1 -1
- package/components/index.js +2 -19
- package/components/index.js.map +1 -1
- package/config/RouterConfig/Route.d.ts +30 -0
- package/config/RouterConfig/Route.js +42 -0
- package/config/RouterConfig/Route.js.map +1 -0
- package/config/RouterConfig.d.ts +32 -0
- package/config/RouterConfig.js +18 -0
- package/config/RouterConfig.js.map +1 -0
- package/config.js +9 -15
- package/config.js.map +1 -1
- package/contexts/Ui/index.js +28 -52
- package/contexts/Ui/index.js.map +1 -1
- package/core/DebounceRender.js +13 -24
- package/core/DebounceRender.js.map +1 -1
- package/core/Plugin.d.ts +1 -1
- package/core/Plugin.js +11 -19
- package/core/Plugin.js.map +1 -1
- package/core/Plugins.js +18 -24
- package/core/Plugins.js.map +1 -1
- package/core/Provider.d.ts +1 -1
- package/core/Provider.js +9 -13
- package/core/Provider.js.map +1 -1
- package/core/Routes.js +14 -23
- package/core/Routes.js.map +1 -1
- package/core/createProvider.d.ts +2 -2
- package/core/createProvider.js +1 -7
- package/core/createProvider.js.map +1 -1
- package/core/createProviderPlugin.d.ts +1 -1
- package/core/createProviderPlugin.js +4 -10
- package/core/createProviderPlugin.js.map +1 -1
- package/hooks/useAutocomplete/index.js +1 -12
- package/hooks/useAutocomplete/index.js.map +1 -1
- package/hooks/useAutocomplete/useAutocomplete.d.ts +1 -1
- package/hooks/useAutocomplete/useAutocomplete.js +9 -16
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +2 -11
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +2 -11
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +2 -11
- package/hooks/useDataList/functions/getMeta.js.map +1 -1
- package/hooks/useDataList/functions/index.js +3 -27
- package/hooks/useDataList/functions/index.js.map +1 -1
- package/hooks/useDataList/functions/searchDataByKey.js +4 -10
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
- package/hooks/useDataList/index.js +1 -12
- package/hooks/useDataList/index.js.map +1 -1
- package/hooks/useDataList/useDataList.d.ts +2 -2
- package/hooks/useDataList/useDataList.js +78 -78
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.js +2 -20
- package/hooks/useDataList/utils/index.js.map +1 -1
- package/hooks/useDataList/utils/prepareLoadListParams.js +9 -15
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +10 -14
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +1 -1
- package/hooks/useDataList/utils/types.js +1 -5
- package/hooks/useHandler.js +7 -12
- package/hooks/useHandler.js.map +1 -1
- package/hooks/useHandlers.js +11 -17
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.js +5 -11
- package/hooks/useRegisterLegacyPlugin.js.map +1 -1
- package/hooks/useUi.d.ts +1 -1
- package/hooks/useUi.js +4 -10
- package/hooks/useUi.js.map +1 -1
- package/i18n/i18n.js +5 -13
- package/i18n/i18n.js.map +1 -1
- package/i18n/index.js +1 -13
- package/i18n/index.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +17 -177
- package/index.js.map +1 -1
- package/package.json +10 -9
- package/plugins/AddQuerySelectionPlugin.d.ts +1 -1
- package/plugins/AddQuerySelectionPlugin.js +61 -107
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloCacheObjectIdPlugin.js +12 -31
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.d.ts +3 -2
- package/plugins/ApolloDynamicLink.js +19 -46
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ApolloLinkPlugin.d.ts +1 -1
- package/plugins/ApolloLinkPlugin.js +18 -37
- package/plugins/ApolloLinkPlugin.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.js +20 -41
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/LocaleHeaderLinkPlugin.d.ts +1 -1
- package/plugins/LocaleHeaderLinkPlugin.js +23 -40
- package/plugins/LocaleHeaderLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +39 -51
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +68 -12
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +1 -1
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +12 -18
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.js +23 -40
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +11 -30
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/RoutePlugin.d.ts +1 -1
- package/plugins/RoutePlugin.js +12 -31
- package/plugins/RoutePlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.d.ts +1 -1
- package/plugins/TenantHeaderLinkPlugin.js +30 -47
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
- package/plugins/ViewPlugin.d.ts +1 -1
- package/plugins/ViewPlugin.js +15 -36
- package/plugins/ViewPlugin.js.map +1 -1
- package/plugins/image.d.ts +1 -1
- package/plugins/image.js +46 -53
- package/plugins/image.js.map +1 -1
- package/plugins/index.d.ts +2 -2
- package/plugins/index.js +31 -53
- package/plugins/index.js.map +1 -1
- package/react-butterfiles/Files.js +208 -235
- package/react-butterfiles/Files.js.map +1 -1
- package/react-butterfiles/index.js +2 -8
- package/react-butterfiles/index.js.map +1 -1
- package/react-butterfiles/utils/generateId.js +1 -7
- package/react-butterfiles/utils/generateId.js.map +1 -1
- package/react-butterfiles/utils/readFileContent.js +4 -10
- package/react-butterfiles/utils/readFileContent.js.map +1 -1
- package/renderApp.d.ts +1 -1
- package/renderApp.js +4 -11
- package/renderApp.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +11 -11
- package/types.js.map +1 -1
- package/utils/createGenericContext.js +13 -22
- package/utils/createGenericContext.js.map +1 -1
- package/utils/createHashing.js +9 -15
- package/utils/createHashing.js.map +1 -1
- package/utils/getApiUrl.js +1 -8
- package/utils/getApiUrl.js.map +1 -1
- package/utils/getGqlApiUrl.js +3 -9
- package/utils/getGqlApiUrl.js.map +1 -1
- package/utils/getHeadlessCmsGqlApiUrl.js +7 -13
- package/utils/getHeadlessCmsGqlApiUrl.js.map +1 -1
- package/utils/getLocaleCode.js +6 -16
- package/utils/getLocaleCode.js.map +1 -1
- package/utils/getPrerenderId.js +1 -7
- package/utils/getPrerenderId.js.map +1 -1
- package/utils/getTenantId.js +7 -13
- package/utils/getTenantId.js.map +1 -1
- package/utils/index.js +10 -115
- package/utils/index.js.map +1 -1
- package/utils/isLocalhost.js +4 -12
- package/utils/isLocalhost.js.map +1 -1
- package/utils/isPrerendering.js +1 -7
- package/utils/isPrerendering.js.map +1 -1
- package/utils/legacyPluginToReactComponent.d.ts +1 -1
- package/utils/legacyPluginToReactComponent.js +5 -11
- package/utils/legacyPluginToReactComponent.js.map +1 -1
- package/core/AddRoute.d.ts +0 -21
- package/core/AddRoute.js +0 -21
- package/core/AddRoute.js.map +0 -1
package/plugins/image.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
-
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
var _Image = require("@webiny/ui/Image");
|
|
12
|
-
var _excluded = ["transform", "srcSet"];
|
|
13
|
-
var SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Image } from "@webiny/ui/Image";
|
|
3
|
+
const SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];
|
|
14
4
|
|
|
15
5
|
/**
|
|
16
6
|
* Width of the image should not be just any random number. For optimization reasons,
|
|
17
7
|
* we only allow the ones listed in SUPPORTED_IMAGE_RESIZE_WIDTHS list (Webiny Cloud supports only these).
|
|
18
8
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const getSupportedImageResizeWidth = width => {
|
|
10
|
+
let output = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];
|
|
11
|
+
let i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;
|
|
22
12
|
while (i >= 0) {
|
|
23
13
|
if (width === SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
|
|
24
14
|
output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
|
|
@@ -40,37 +30,37 @@ var getSupportedImageResizeWidth = function getSupportedImageResizeWidth(width)
|
|
|
40
30
|
* Currently we only allow "width" as a transform option.
|
|
41
31
|
* @param args
|
|
42
32
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
const sanitizeTransformArgs = args => {
|
|
34
|
+
const output = {};
|
|
45
35
|
if (!args || args.width === undefined || args.width === null) {
|
|
46
36
|
return output;
|
|
47
37
|
}
|
|
48
|
-
|
|
38
|
+
const width = parseInt(args.width);
|
|
49
39
|
if (width > 0) {
|
|
50
40
|
output.width = getSupportedImageResizeWidth(width);
|
|
51
41
|
}
|
|
52
42
|
return output;
|
|
53
43
|
};
|
|
54
|
-
|
|
44
|
+
const getSizes = width => {
|
|
55
45
|
if (typeof width !== "string") {
|
|
56
46
|
return undefined;
|
|
57
47
|
}
|
|
58
48
|
// Check if width was set as percentage, with "%" in the value.
|
|
59
49
|
if (width.endsWith("%")) {
|
|
60
|
-
return
|
|
50
|
+
return `${parseInt(width)}vw`;
|
|
61
51
|
}
|
|
62
52
|
// Check if width was set as viewport width, with "vw" in the value.
|
|
63
53
|
if (width.endsWith("vw")) {
|
|
64
|
-
return
|
|
54
|
+
return `${parseInt(width)}vw`;
|
|
65
55
|
}
|
|
66
56
|
|
|
67
57
|
// Check if width was set as relative, with "em" in the value.
|
|
68
58
|
if (width.endsWith("em")) {
|
|
69
|
-
return
|
|
59
|
+
return `${parseInt(width)}em`;
|
|
70
60
|
}
|
|
71
61
|
return undefined;
|
|
72
62
|
};
|
|
73
|
-
|
|
63
|
+
const isFixedImageWidth = width => {
|
|
74
64
|
if (Number.isFinite(width)) {
|
|
75
65
|
return true;
|
|
76
66
|
}
|
|
@@ -79,20 +69,18 @@ var isFixedImageWidth = function isFixedImageWidth(width) {
|
|
|
79
69
|
}
|
|
80
70
|
return false;
|
|
81
71
|
};
|
|
82
|
-
|
|
72
|
+
const getSrcSetAutoSizes = max => {
|
|
83
73
|
max = isFixedImageWidth(max) ? parseInt("" + max) : 2500;
|
|
84
|
-
|
|
85
|
-
return SUPPORTED_IMAGE_RESIZE_WIDTHS.filter(
|
|
74
|
+
const maxWidth = getSupportedImageResizeWidth(max);
|
|
75
|
+
return SUPPORTED_IMAGE_RESIZE_WIDTHS.filter(supportedWidth => {
|
|
86
76
|
return supportedWidth <= maxWidth;
|
|
87
77
|
});
|
|
88
78
|
};
|
|
89
|
-
|
|
90
|
-
return Object.keys(transform).map(
|
|
91
|
-
return "".concat(key, "=").concat(transform[key]);
|
|
92
|
-
}).join("&");
|
|
79
|
+
const convertTransformToQueryParams = transform => {
|
|
80
|
+
return Object.keys(transform).map(key => `${key}=${transform[key]}`).join("&");
|
|
93
81
|
};
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
export default () => {
|
|
83
|
+
const imagePlugin = {
|
|
96
84
|
name: "image-component",
|
|
97
85
|
type: "image-component",
|
|
98
86
|
presets: {
|
|
@@ -100,46 +88,51 @@ var _default = exports.default = function _default() {
|
|
|
100
88
|
width: 300
|
|
101
89
|
}
|
|
102
90
|
},
|
|
103
|
-
getImageSrc:
|
|
91
|
+
getImageSrc: props => {
|
|
104
92
|
if (!props) {
|
|
105
93
|
return "";
|
|
106
94
|
}
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
const {
|
|
96
|
+
src,
|
|
97
|
+
transform
|
|
98
|
+
} = props;
|
|
109
99
|
if (!transform) {
|
|
110
100
|
return src;
|
|
111
101
|
}
|
|
112
102
|
if (!src || src.startsWith("data:") || src.endsWith("svg")) {
|
|
113
103
|
return src;
|
|
114
104
|
}
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
const sanitizedParams = sanitizeTransformArgs(transform);
|
|
106
|
+
const params = convertTransformToQueryParams(sanitizedParams);
|
|
117
107
|
return src + "?" + params;
|
|
118
108
|
},
|
|
119
|
-
render
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
109
|
+
render(props) {
|
|
110
|
+
const {
|
|
111
|
+
transform,
|
|
112
|
+
srcSet: srcSetInitial,
|
|
113
|
+
...imageProps
|
|
114
|
+
} = props;
|
|
115
|
+
let srcSet = srcSetInitial;
|
|
116
|
+
let sizes;
|
|
117
|
+
const src = imageProps.src;
|
|
126
118
|
if (srcSet && srcSet === "auto") {
|
|
127
119
|
srcSet = {};
|
|
128
120
|
|
|
129
121
|
// Check if image width was forced, and additionally if width was set as pixels, with "px" in the value.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
srcSetAutoWidths.forEach(
|
|
122
|
+
const forcedWidth = props.width || props.style && props.style.width;
|
|
123
|
+
const srcSetAutoWidths = getSrcSetAutoSizes(forcedWidth);
|
|
124
|
+
srcSetAutoWidths.forEach(width => {
|
|
133
125
|
srcSet[width + "w"] = imagePlugin.getImageSrc({
|
|
134
|
-
src
|
|
135
|
-
transform:
|
|
136
|
-
|
|
137
|
-
|
|
126
|
+
src,
|
|
127
|
+
transform: {
|
|
128
|
+
...transform,
|
|
129
|
+
width
|
|
130
|
+
}
|
|
138
131
|
});
|
|
139
132
|
});
|
|
140
133
|
sizes = getSizes(forcedWidth);
|
|
141
134
|
}
|
|
142
|
-
return /*#__PURE__*/
|
|
135
|
+
return /*#__PURE__*/React.createElement(Image, Object.assign({}, imageProps, {
|
|
143
136
|
srcSet: srcSet,
|
|
144
137
|
src: src,
|
|
145
138
|
sizes: sizes
|
package/plugins/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","Image","SUPPORTED_IMAGE_RESIZE_WIDTHS","getSupportedImageResizeWidth","width","output","i","length","sanitizeTransformArgs","args","undefined","parseInt","getSizes","endsWith","isFixedImageWidth","Number","isFinite","getSrcSetAutoSizes","max","maxWidth","filter","supportedWidth","convertTransformToQueryParams","transform","Object","keys","map","key","join","imagePlugin","name","type","presets","avatar","getImageSrc","props","src","startsWith","sanitizedParams","params","render","srcSet","srcSetInitial","imageProps","sizes","forcedWidth","style","srcSetAutoWidths","forEach","createElement","assign"],"sources":["image.tsx"],"sourcesContent":["import React from \"react\";\nimport { Image } from \"@webiny/ui/Image\";\nimport type { ImageComponentPlugin } from \"~/types\";\n\nconst SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];\n\n/**\n * Width of the image should not be just any random number. For optimization reasons,\n * we only allow the ones listed in SUPPORTED_IMAGE_RESIZE_WIDTHS list (Webiny Cloud supports only these).\n */\nconst getSupportedImageResizeWidth = (width: number) => {\n let output = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];\n let i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;\n while (i >= 0) {\n if (width === SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {\n output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];\n break;\n }\n\n if (width > SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {\n // Use next larger width. If there isn't any, use current.\n output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i + 1];\n if (!output) {\n output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];\n }\n break;\n }\n\n i--;\n }\n\n return output;\n};\n\ninterface SanitizeTransformArgsParams {\n width?: string;\n}\ninterface SanitizeTransformArgsResult {\n width?: number;\n}\n/**\n * Currently we only allow \"width\" as a transform option.\n * @param args\n */\nconst sanitizeTransformArgs = (args?: SanitizeTransformArgsParams): SanitizeTransformArgsResult => {\n const output: SanitizeTransformArgsResult = {};\n if (!args || args.width === undefined || args.width === null) {\n return output;\n }\n const width = parseInt(args.width);\n if (width > 0) {\n output.width = getSupportedImageResizeWidth(width);\n }\n\n return output;\n};\n\nconst getSizes = (width?: string | number): string | undefined => {\n if (typeof width !== \"string\") {\n return undefined;\n }\n // Check if width was set as percentage, with \"%\" in the value.\n if (width.endsWith(\"%\")) {\n return `${parseInt(width)}vw`;\n }\n // Check if width was set as viewport width, with \"vw\" in the value.\n if (width.endsWith(\"vw\")) {\n return `${parseInt(width)}vw`;\n }\n\n // Check if width was set as relative, with \"em\" in the value.\n if (width.endsWith(\"em\")) {\n return `${parseInt(width)}em`;\n }\n\n return undefined;\n};\n\nconst isFixedImageWidth = (width?: number | string) => {\n if (Number.isFinite(width)) {\n return true;\n }\n\n if (typeof width === \"string\" && width.endsWith(\"px\")) {\n return true;\n }\n return false;\n};\n\nconst getSrcSetAutoSizes = (max?: string | number) => {\n max = isFixedImageWidth(max) ? parseInt(\"\" + max) : 2500;\n const maxWidth = getSupportedImageResizeWidth(max);\n return SUPPORTED_IMAGE_RESIZE_WIDTHS.filter((supportedWidth: number) => {\n return supportedWidth <= maxWidth;\n });\n};\n\nconst convertTransformToQueryParams = (transform: Record<string, any>): string => {\n return Object.keys(transform)\n .map(key => `${key}=${transform[key]}`)\n .join(\"&\");\n};\n\nexport default () => {\n const imagePlugin: ImageComponentPlugin = {\n name: \"image-component\",\n type: \"image-component\",\n presets: {\n avatar: { width: 300 }\n },\n getImageSrc: (props?: Record<string, any>) => {\n if (!props) {\n return \"\";\n }\n\n const { src, transform } = props;\n if (!transform) {\n return src;\n }\n\n if (!src || src.startsWith(\"data:\") || src.endsWith(\"svg\")) {\n return src;\n }\n\n const sanitizedParams = sanitizeTransformArgs(transform);\n const params = convertTransformToQueryParams(sanitizedParams);\n return src + \"?\" + params;\n },\n render(props) {\n const { transform, srcSet: srcSetInitial, ...imageProps } = props;\n let srcSet: any = srcSetInitial;\n let sizes: string | undefined;\n const src = imageProps.src;\n if (srcSet && srcSet === \"auto\") {\n srcSet = {};\n\n // Check if image width was forced, and additionally if width was set as pixels, with \"px\" in the value.\n const forcedWidth = props.width || (props.style && props.style.width);\n const srcSetAutoWidths = getSrcSetAutoSizes(forcedWidth);\n srcSetAutoWidths.forEach(width => {\n srcSet[width + \"w\"] = imagePlugin.getImageSrc({\n src,\n transform: { ...transform, width }\n });\n });\n sizes = getSizes(forcedWidth);\n }\n\n return <Image {...imageProps} srcSet={srcSet}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AAgB,GAAG9B,kBAAkB,CAAC4B,WAAW,CAAC;QACxDE,gBAAgB,CAACC,OAAO,CAAC5C,KAAK,IAAI;UAC9BqC,MAAM,CAACrC,KAAK,GAAG,GAAG,CAAC,GAAGyB,WAAW,CAACK,WAAW,CAAC;YAC1CE,GAAG;YACHb,SAAS,EAAE;cAAE,GAAGA,SAAS;cAAEnB;YAAM;UACrC,CAAC,CAAC;QACN,CAAC,CAAC;QACFwC,KAAK,GAAGhC,QAAQ,CAACiC,WAAW,CAAC;MACjC;MAEA,oBAAO7C,KAAA,CAAAiD,aAAA,CAAChD,KAAK,EAAAuB,MAAA,CAAA0B,MAAA,KAAKP,UAAU;QAAEF,MAAM,EAAEA,MAAO;QAACL,GAAG,EAAEA,GAAI;QAACQ,KAAK,EAAEA;MAAM,EAAE,CAAC;IAC5E;EACJ,CAAC;EAED,OAAOf,WAAW;AACtB,CAAC","ignoreList":[]}
|
package/plugins/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { Plugin } from "@webiny/plugins/types";
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { Plugin } from "@webiny/plugins/types";
|
|
3
3
|
import imagePlugin from "./image";
|
|
4
4
|
export { imagePlugin };
|
|
5
5
|
type RenderPluginOptions<T> = {
|
package/plugins/index.js
CHANGED
|
@@ -1,65 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
Object.defineProperty(exports, "imagePlugin", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _image.default;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.renderPlugins = exports.renderPlugin = void 0;
|
|
15
|
-
var _react = _interopRequireDefault(require("react"));
|
|
16
|
-
var _warning = _interopRequireDefault(require("warning"));
|
|
17
|
-
var _plugins = require("@webiny/plugins");
|
|
18
|
-
var _image = _interopRequireDefault(require("./image"));
|
|
19
|
-
var PluginComponent = function PluginComponent(props) {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import warning from "warning";
|
|
3
|
+
import { plugins } from "@webiny/plugins";
|
|
4
|
+
import imagePlugin from "./image";
|
|
5
|
+
export { imagePlugin };
|
|
6
|
+
const PluginComponent = props => {
|
|
20
7
|
return props.children;
|
|
21
8
|
};
|
|
22
|
-
|
|
9
|
+
const PluginsComponent = props => {
|
|
23
10
|
return props.children;
|
|
24
11
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var plugin = _plugins.plugins.byName(name);
|
|
33
|
-
(0, _warning.default)(plugin, "No such plugin \"".concat(name, "\""));
|
|
12
|
+
export const renderPlugin = (name, params = {}, options = {}) => {
|
|
13
|
+
const {
|
|
14
|
+
wrapper = true,
|
|
15
|
+
fn = "render"
|
|
16
|
+
} = options;
|
|
17
|
+
const plugin = plugins.byName(name);
|
|
18
|
+
warning(plugin, `No such plugin "${name}"`);
|
|
34
19
|
if (!plugin) {
|
|
35
20
|
return null;
|
|
36
21
|
}
|
|
37
|
-
|
|
22
|
+
const content = plugin[fn](params);
|
|
38
23
|
if (content) {
|
|
39
|
-
return wrapper ? /*#__PURE__*/
|
|
24
|
+
return wrapper ? /*#__PURE__*/React.createElement(PluginComponent, {
|
|
40
25
|
key: plugin.name,
|
|
41
26
|
name: name,
|
|
42
27
|
params: params,
|
|
43
28
|
fn: fn
|
|
44
|
-
}, content) : (/*#__PURE__*/
|
|
29
|
+
}, content) : (/*#__PURE__*/React.cloneElement(content, {
|
|
45
30
|
key: plugin.name
|
|
46
31
|
}));
|
|
47
32
|
}
|
|
48
33
|
return null;
|
|
49
34
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
filter = _options$filter === void 0 ? function (v) {
|
|
59
|
-
return v;
|
|
60
|
-
} : _options$filter,
|
|
61
|
-
reverse = options.reverse;
|
|
62
|
-
var content = _plugins.plugins.byType(type).filter(function (pl) {
|
|
35
|
+
export const renderPlugins = (type, params = {}, options = {}) => {
|
|
36
|
+
const {
|
|
37
|
+
wrapper = true,
|
|
38
|
+
fn = "render",
|
|
39
|
+
filter = v => v,
|
|
40
|
+
reverse
|
|
41
|
+
} = options;
|
|
42
|
+
const content = plugins.byType(type).filter(pl => {
|
|
63
43
|
/**
|
|
64
44
|
* TODO @ts-refactor Problem with possibility of a different subtype.
|
|
65
45
|
*/
|
|
@@ -68,21 +48,19 @@ var renderPlugins = exports.renderPlugins = function renderPlugins(type) {
|
|
|
68
48
|
})
|
|
69
49
|
/**
|
|
70
50
|
* We cast as string because renderPlugin checks for the plugin.name
|
|
71
|
-
*/.map(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
}).filter(Boolean);
|
|
51
|
+
*/.map(plugin => renderPlugin(plugin.name, params, {
|
|
52
|
+
wrapper,
|
|
53
|
+
fn
|
|
54
|
+
})).filter(Boolean);
|
|
77
55
|
if (reverse) {
|
|
78
56
|
content.reverse();
|
|
79
57
|
}
|
|
80
|
-
return wrapper ? /*#__PURE__*/
|
|
58
|
+
return wrapper ? /*#__PURE__*/React.createElement(PluginsComponent, {
|
|
81
59
|
type: type,
|
|
82
60
|
params: params,
|
|
83
61
|
fn: fn
|
|
84
62
|
}, content) : content;
|
|
85
63
|
};
|
|
86
|
-
|
|
64
|
+
export default [imagePlugin];
|
|
87
65
|
|
|
88
66
|
//# sourceMappingURL=index.js.map
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","warning","plugins","imagePlugin","PluginComponent","props","children","PluginsComponent","renderPlugin","name","params","options","wrapper","fn","plugin","byName","content","createElement","key","cloneElement","renderPlugins","type","filter","v","reverse","byType","pl","map","Boolean"],"sources":["index.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport React from \"react\";\nimport warning from \"warning\";\nimport { plugins } from \"@webiny/plugins\";\nimport type { Plugin } from \"@webiny/plugins/types\";\nimport imagePlugin from \"./image\";\n\nexport { imagePlugin };\n\ntype RenderPluginOptions<T> = {\n wrapper?: boolean;\n fn?: string;\n filter?: (value: T, index: number, array: T[]) => boolean;\n reverse?: boolean;\n};\n\ninterface RenderPlugin {\n <T extends Plugin = Plugin>(name: string, params?: any, options?: RenderPluginOptions<T>):\n | ReactNode\n | ReactNode[];\n}\n\ninterface RenderPlugins {\n <T extends Plugin = Plugin>(type: string, params?: any, options?: RenderPluginOptions<T>):\n | ReactNode\n | ReactNode[];\n}\n\ninterface PluginComponentProps {\n name: string;\n params: Record<string, any>;\n fn: string;\n children: React.ReactNode;\n}\nconst PluginComponent = (props: PluginComponentProps) => {\n return props.children as React.ReactElement;\n};\ninterface PluginsComponentProps {\n type: string;\n params: Record<string, any>;\n fn: string;\n children: React.ReactNode;\n}\nconst PluginsComponent = (props: PluginsComponentProps) => {\n return props.children as React.ReactElement;\n};\n\nexport const renderPlugin: RenderPlugin = (name, params = {}, options = {}) => {\n const { wrapper = true, fn = \"render\" } = options;\n\n const plugin = plugins.byName(name);\n warning(plugin, `No such plugin \"${name}\"`);\n\n if (!plugin) {\n return null;\n }\n\n const content = plugin[fn](params);\n if (content) {\n return wrapper ? (\n <PluginComponent key={plugin.name} name={name} params={params} fn={fn}>\n {content}\n </PluginComponent>\n ) : (\n React.cloneElement(content, { key: plugin.name })\n );\n }\n return null;\n};\n\nexport const renderPlugins: RenderPlugins = (type, params = {}, options = {}) => {\n const { wrapper = true, fn = \"render\", filter = v => v, reverse } = options;\n\n const content = plugins\n .byType(type)\n .filter(pl => {\n /**\n * TODO @ts-refactor Problem with possibility of a different subtype.\n */\n // @ts-expect-error\n return filter(pl);\n })\n /**\n * We cast as string because renderPlugin checks for the plugin.name\n */\n .map(plugin => renderPlugin(plugin.name as string, params, { wrapper, fn }))\n .filter(Boolean);\n\n if (reverse) {\n content.reverse();\n }\n\n return wrapper ? (\n <PluginsComponent type={type} params={params} fn={fn}>\n {content}\n </PluginsComponent>\n ) : (\n content\n );\n};\n\nexport default [imagePlugin];\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,OAAO,MAAM,SAAS;AAC7B,SAASC,OAAO,QAAQ,iBAAiB;AAEzC,OAAOC,WAAW;AAElB,SAASA,WAAW;AA2BpB,MAAMC,eAAe,GAAIC,KAA2B,IAAK;EACrD,OAAOA,KAAK,CAACC,QAAQ;AACzB,CAAC;AAOD,MAAMC,gBAAgB,GAAIF,KAA4B,IAAK;EACvD,OAAOA,KAAK,CAACC,QAAQ;AACzB,CAAC;AAED,OAAO,MAAME,YAA0B,GAAGA,CAACC,IAAI,EAAEC,MAAM,GAAG,CAAC,CAAC,EAAEC,OAAO,GAAG,CAAC,CAAC,KAAK;EAC3E,MAAM;IAAEC,OAAO,GAAG,IAAI;IAAEC,EAAE,GAAG;EAAS,CAAC,GAAGF,OAAO;EAEjD,MAAMG,MAAM,GAAGZ,OAAO,CAACa,MAAM,CAACN,IAAI,CAAC;EACnCR,OAAO,CAACa,MAAM,EAAE,mBAAmBL,IAAI,GAAG,CAAC;EAE3C,IAAI,CAACK,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,MAAME,OAAO,GAAGF,MAAM,CAACD,EAAE,CAAC,CAACH,MAAM,CAAC;EAClC,IAAIM,OAAO,EAAE;IACT,OAAOJ,OAAO,gBACVZ,KAAA,CAAAiB,aAAA,CAACb,eAAe;MAACc,GAAG,EAAEJ,MAAM,CAACL,IAAK;MAACA,IAAI,EAAEA,IAAK;MAACC,MAAM,EAAEA,MAAO;MAACG,EAAE,EAAEA;IAAG,GACjEG,OACY,CAAC,iBAElBhB,KAAK,CAACmB,YAAY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