@webiny/app 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f
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 +29 -0
- package/App.js +105 -0
- package/App.js.map +1 -0
- package/apollo-client/InMemoryCache.d.ts +1 -1
- package/apollo-client/InMemoryCache.js +33 -36
- package/apollo-client/InMemoryCache.js.map +1 -0
- package/components/Image.js +18 -16
- package/components/Image.js.map +1 -0
- package/components/Routes.js +27 -17
- package/components/Routes.js.map +1 -0
- package/components/View.js +21 -14
- package/components/View.js.map +1 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +19 -1
- package/components/index.js.map +1 -0
- package/config.d.ts +8 -0
- package/config.js +30 -0
- package/config.js.map +1 -0
- package/contexts/Ui/index.d.ts +1 -4
- package/contexts/Ui/index.js +32 -42
- package/contexts/Ui/index.js.map +1 -0
- package/core/AddRoute.d.ts +3 -0
- package/core/AddRoute.js +19 -0
- package/core/AddRoute.js.map +1 -0
- package/core/DebounceRender.d.ts +11 -0
- package/core/DebounceRender.js +41 -0
- package/core/DebounceRender.js.map +1 -0
- package/core/Plugin.d.ts +8 -0
- package/core/Plugin.js +21 -0
- package/core/Plugin.js.map +1 -0
- package/core/Plugins.d.ts +12 -0
- package/core/Plugins.js +45 -0
- package/core/Plugins.js.map +1 -0
- package/core/Provider.d.ts +9 -0
- package/core/Provider.js +21 -0
- package/core/Provider.js.map +1 -0
- package/core/Routes.d.ts +6 -0
- package/core/Routes.js +42 -0
- package/core/Routes.js.map +1 -0
- package/core/createProvider.d.ts +6 -0
- package/core/createProvider.js +13 -0
- package/core/createProvider.js.map +1 -0
- package/core/createProviderPlugin.d.ts +8 -0
- package/core/createProviderPlugin.js +21 -0
- package/core/createProviderPlugin.js.map +1 -0
- package/hooks/useAutocomplete/index.js +12 -1
- package/hooks/useAutocomplete/index.js.map +1 -0
- package/hooks/useAutocomplete/useAutocomplete.d.ts +6 -1
- package/hooks/useAutocomplete/useAutocomplete.js +16 -14
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -0
- package/hooks/useDataList/functions/getData.d.ts +1 -1
- package/hooks/useDataList/functions/getData.js +12 -4
- package/hooks/useDataList/functions/getData.js.map +1 -0
- package/hooks/useDataList/functions/getError.d.ts +1 -1
- package/hooks/useDataList/functions/getError.js +12 -4
- package/hooks/useDataList/functions/getError.js.map +1 -0
- package/hooks/useDataList/functions/getMeta.d.ts +1 -1
- package/hooks/useDataList/functions/getMeta.js +12 -4
- package/hooks/useDataList/functions/getMeta.js.map +1 -0
- package/hooks/useDataList/functions/index.js +27 -3
- package/hooks/useDataList/functions/index.js.map +1 -0
- package/hooks/useDataList/functions/searchDataByKey.d.ts +1 -1
- package/hooks/useDataList/functions/searchDataByKey.js +8 -6
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -0
- package/hooks/useDataList/index.js +12 -1
- package/hooks/useDataList/index.js.map +1 -0
- package/hooks/useDataList/useDataList.d.ts +4 -4
- package/hooks/useDataList/useDataList.js +47 -58
- package/hooks/useDataList/useDataList.js.map +1 -0
- package/hooks/useDataList/utils/index.js +20 -2
- package/hooks/useDataList/utils/index.js.map +1 -0
- package/hooks/useDataList/utils/prepareLoadListParams.d.ts +10 -3
- package/hooks/useDataList/utils/prepareLoadListParams.js +19 -15
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -0
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +13 -4
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +11 -4
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +1 -0
- package/hooks/useDataList/utils/types.js +5 -1
- package/hooks/useDataList/utils/types.js.map +1 -0
- package/hooks/useHandler.d.ts +11 -1
- package/hooks/useHandler.js +11 -5
- package/hooks/useHandler.js.map +1 -0
- package/hooks/useHandlers.d.ts +1 -1
- package/hooks/useHandlers.js +14 -6
- package/hooks/useHandlers.js.map +1 -0
- package/hooks/useUi.js +12 -5
- package/hooks/useUi.js.map +1 -0
- package/i18n/i18n.js +14 -5
- package/i18n/i18n.js.map +1 -0
- package/i18n/index.js +13 -1
- package/i18n/index.js.map +1 -0
- package/index.d.ts +15 -0
- package/index.js +147 -0
- package/index.js.map +1 -0
- package/package.json +33 -25
- package/plugins/AddQuerySelectionPlugin.d.ts +9 -2
- package/plugins/AddQuerySelectionPlugin.js +73 -52
- package/plugins/AddQuerySelectionPlugin.js.map +1 -0
- package/plugins/ApolloCacheObjectIdPlugin.d.ts +8 -8
- package/plugins/ApolloCacheObjectIdPlugin.js +23 -25
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -0
- package/plugins/ApolloDynamicLink.d.ts +3 -2
- package/plugins/ApolloDynamicLink.js +30 -32
- package/plugins/ApolloDynamicLink.js.map +1 -0
- package/plugins/ApolloLinkPlugin.d.ts +5 -5
- package/plugins/ApolloLinkPlugin.js +32 -29
- package/plugins/ApolloLinkPlugin.js.map +1 -0
- package/plugins/ConsoleLinkPlugin.js +25 -24
- package/plugins/ConsoleLinkPlugin.js.map +1 -0
- package/plugins/LocaleHeaderLinkPlugin.d.ts +3 -7
- package/plugins/LocaleHeaderLinkPlugin.js +28 -36
- package/plugins/LocaleHeaderLinkPlugin.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +13 -5
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +46 -45
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +10 -2
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +13 -4
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +6 -4
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +21 -17
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin.js +31 -28
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -0
- package/plugins/OmitTypenameLinkPlugin.js +22 -22
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -0
- package/plugins/RoutePlugin.d.ts +2 -2
- package/plugins/RoutePlugin.js +26 -24
- package/plugins/RoutePlugin.js.map +1 -0
- package/plugins/TenantHeaderLinkPlugin.d.ts +3 -7
- package/plugins/TenantHeaderLinkPlugin.js +28 -39
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -0
- package/plugins/ViewPlugin.d.ts +4 -4
- package/plugins/ViewPlugin.js +26 -24
- package/plugins/ViewPlugin.js.map +1 -0
- package/plugins/image.js +41 -55
- package/plugins/image.js.map +1 -0
- package/plugins/index.js +49 -33
- package/plugins/index.js.map +1 -0
- package/types.d.ts +20 -16
- package/types.js +12 -2
- package/types.js.map +1 -0
- package/utils/getApiUrl.d.ts +1 -0
- package/utils/getApiUrl.js +11 -0
- package/utils/getApiUrl.js.map +1 -0
- package/utils/getGqlApiUrl.d.ts +1 -0
- package/utils/getGqlApiUrl.js +11 -0
- package/utils/getGqlApiUrl.js.map +1 -0
- package/utils/getHeadlessCmsGqlApiUrl.d.ts +5 -0
- package/utils/getHeadlessCmsGqlApiUrl.js +17 -0
- package/utils/getHeadlessCmsGqlApiUrl.js.map +1 -0
- package/utils/getLocaleCode.d.ts +6 -0
- package/utils/getLocaleCode.js +42 -0
- package/utils/getLocaleCode.js.map +1 -0
- package/utils/getPrerenderId.d.ts +6 -0
- package/utils/getPrerenderId.js +10 -0
- package/utils/getPrerenderId.js.map +1 -0
- package/utils/getTenantId.d.ts +6 -0
- package/utils/getTenantId.js +34 -0
- package/utils/getTenantId.js.map +1 -0
- package/utils/index.d.ts +8 -0
- package/utils/index.js +93 -0
- package/utils/index.js.map +1 -0
- package/utils/isLocalhost.d.ts +1 -0
- package/utils/isLocalhost.js +14 -0
- package/utils/isLocalhost.js.map +1 -0
- package/utils/isPrerendering.d.ts +1 -0
- package/utils/isPrerendering.js +10 -0
- package/utils/isPrerendering.js.map +1 -0
package/plugins/image.js
CHANGED
|
@@ -1,91 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
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");
|
|
3
12
|
var _excluded = ["transform", "srcSet"];
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { Image } from "@webiny/ui/Image";
|
|
6
13
|
var SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];
|
|
14
|
+
|
|
7
15
|
/**
|
|
8
16
|
* Width of the image should not be just any random number. For optimization reasons,
|
|
9
17
|
* we only allow the ones listed in SUPPORTED_IMAGE_RESIZE_WIDTHS list (Webiny Cloud supports only these).
|
|
10
18
|
*/
|
|
11
|
-
|
|
12
19
|
var getSupportedImageResizeWidth = function getSupportedImageResizeWidth(width) {
|
|
13
20
|
var output = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];
|
|
14
21
|
var i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;
|
|
15
|
-
|
|
16
22
|
while (i >= 0) {
|
|
17
23
|
if (width === SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
|
|
18
24
|
output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
|
|
19
25
|
break;
|
|
20
26
|
}
|
|
21
|
-
|
|
22
27
|
if (width > SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
|
|
23
28
|
// Use next larger width. If there isn't any, use current.
|
|
24
29
|
output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i + 1];
|
|
25
|
-
|
|
26
30
|
if (!output) {
|
|
27
31
|
output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
|
|
28
32
|
}
|
|
29
|
-
|
|
30
33
|
break;
|
|
31
34
|
}
|
|
32
|
-
|
|
33
35
|
i--;
|
|
34
36
|
}
|
|
35
|
-
|
|
36
37
|
return output;
|
|
37
38
|
};
|
|
38
39
|
/**
|
|
39
40
|
* Currently we only allow "width" as a transform option.
|
|
40
41
|
* @param args
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
43
|
var sanitizeTransformArgs = function sanitizeTransformArgs(args) {
|
|
45
44
|
var output = {};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
45
|
+
if (!args || args.width === undefined || args.width === null) {
|
|
46
|
+
return output;
|
|
47
|
+
}
|
|
48
|
+
var width = parseInt(args.width);
|
|
49
|
+
if (width > 0) {
|
|
50
|
+
output.width = getSupportedImageResizeWidth(width);
|
|
53
51
|
}
|
|
54
|
-
|
|
55
52
|
return output;
|
|
56
53
|
};
|
|
57
|
-
|
|
58
54
|
var getSizes = function getSizes(width) {
|
|
55
|
+
if (typeof width !== "string") {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
59
58
|
// Check if width was set as percentage, with "%" in the value.
|
|
60
|
-
if (
|
|
59
|
+
if (width.endsWith("%")) {
|
|
61
60
|
return "".concat(parseInt(width), "vw");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (typeof width === "string" && width.endsWith("vw")) {
|
|
61
|
+
}
|
|
62
|
+
// Check if width was set as viewport width, with "vw" in the value.
|
|
63
|
+
if (width.endsWith("vw")) {
|
|
66
64
|
return "".concat(parseInt(width), "vw");
|
|
67
|
-
}
|
|
68
|
-
|
|
65
|
+
}
|
|
69
66
|
|
|
70
|
-
if
|
|
67
|
+
// Check if width was set as relative, with "em" in the value.
|
|
68
|
+
if (width.endsWith("em")) {
|
|
71
69
|
return "".concat(parseInt(width), "em");
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
return null;
|
|
71
|
+
return undefined;
|
|
75
72
|
};
|
|
76
|
-
|
|
77
73
|
var isFixedImageWidth = function isFixedImageWidth(width) {
|
|
78
74
|
if (Number.isFinite(width)) {
|
|
79
75
|
return true;
|
|
80
76
|
}
|
|
81
|
-
|
|
82
77
|
if (typeof width === "string" && width.endsWith("px")) {
|
|
83
78
|
return true;
|
|
84
79
|
}
|
|
85
|
-
|
|
86
80
|
return false;
|
|
87
81
|
};
|
|
88
|
-
|
|
89
82
|
var getSrcSetAutoSizes = function getSrcSetAutoSizes(max) {
|
|
90
83
|
max = isFixedImageWidth(max) ? parseInt("" + max) : 2500;
|
|
91
84
|
var maxWidth = getSupportedImageResizeWidth(max);
|
|
@@ -93,14 +86,12 @@ var getSrcSetAutoSizes = function getSrcSetAutoSizes(max) {
|
|
|
93
86
|
return supportedWidth <= maxWidth;
|
|
94
87
|
});
|
|
95
88
|
};
|
|
96
|
-
|
|
97
89
|
var convertTransformToQueryParams = function convertTransformToQueryParams(transform) {
|
|
98
90
|
return Object.keys(transform).map(function (key) {
|
|
99
91
|
return "".concat(key, "=").concat(transform[key]);
|
|
100
92
|
}).join("&");
|
|
101
93
|
};
|
|
102
|
-
|
|
103
|
-
export default (function () {
|
|
94
|
+
var _default = function _default() {
|
|
104
95
|
var imagePlugin = {
|
|
105
96
|
name: "image-component",
|
|
106
97
|
type: "image-component",
|
|
@@ -113,48 +104,42 @@ export default (function () {
|
|
|
113
104
|
if (!props) {
|
|
114
105
|
return "";
|
|
115
106
|
}
|
|
116
|
-
|
|
117
107
|
var src = props.src,
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
transform = props.transform;
|
|
120
109
|
if (!transform) {
|
|
121
110
|
return src;
|
|
122
111
|
}
|
|
123
|
-
|
|
124
112
|
if (!src || src.startsWith("data:") || src.endsWith("svg")) {
|
|
125
113
|
return src;
|
|
126
114
|
}
|
|
127
|
-
|
|
128
|
-
var params =
|
|
129
|
-
params = convertTransformToQueryParams(params);
|
|
115
|
+
var sanitizedParams = sanitizeTransformArgs(transform);
|
|
116
|
+
var params = convertTransformToQueryParams(sanitizedParams);
|
|
130
117
|
return src + "?" + params;
|
|
131
118
|
},
|
|
132
119
|
render: function render(props) {
|
|
133
120
|
var transform = props.transform,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
121
|
+
srcSetInitial = props.srcSet,
|
|
122
|
+
imageProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
137
123
|
var srcSet = srcSetInitial;
|
|
138
124
|
var sizes;
|
|
139
125
|
var src = imageProps.src;
|
|
140
|
-
|
|
141
126
|
if (srcSet && srcSet === "auto") {
|
|
142
|
-
srcSet = {};
|
|
127
|
+
srcSet = {};
|
|
143
128
|
|
|
129
|
+
// Check if image width was forced, and additionally if width was set as pixels, with "px" in the value.
|
|
144
130
|
var forcedWidth = props.width || props.style && props.style.width;
|
|
145
131
|
var srcSetAutoWidths = getSrcSetAutoSizes(forcedWidth);
|
|
146
132
|
srcSetAutoWidths.forEach(function (width) {
|
|
147
133
|
srcSet[width + "w"] = imagePlugin.getImageSrc({
|
|
148
134
|
src: src,
|
|
149
|
-
transform:
|
|
135
|
+
transform: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, transform), {}, {
|
|
150
136
|
width: width
|
|
151
137
|
})
|
|
152
138
|
});
|
|
153
139
|
});
|
|
154
140
|
sizes = getSizes(forcedWidth);
|
|
155
141
|
}
|
|
156
|
-
|
|
157
|
-
return /*#__PURE__*/React.createElement(Image, Object.assign({}, imageProps, {
|
|
142
|
+
return /*#__PURE__*/_react.default.createElement(_Image.Image, Object.assign({}, imageProps, {
|
|
158
143
|
srcSet: srcSet,
|
|
159
144
|
src: src,
|
|
160
145
|
sizes: sizes
|
|
@@ -162,4 +147,5 @@ export default (function () {
|
|
|
162
147
|
}
|
|
163
148
|
};
|
|
164
149
|
return imagePlugin;
|
|
165
|
-
}
|
|
150
|
+
};
|
|
151
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["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","srcSetInitial","srcSet","imageProps","sizes","forcedWidth","style","srcSetAutoWidths","forEach"],"sources":["image.tsx"],"sourcesContent":["import React from \"react\";\nimport { Image } from \"@webiny/ui/Image\";\nimport { 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} src={src} sizes={sizes} />;\n }\n };\n\n return imagePlugin;\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AAAyC;AAGzC,IAAMA,6BAA6B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;;AAE5E;AACA;AACA;AACA;AACA,IAAMC,4BAA4B,GAAG,SAA/BA,4BAA4B,CAAIC,KAAa,EAAK;EACpD,IAAIC,MAAM,GAAGH,6BAA6B,CAAC,CAAC,CAAC;EAC7C,IAAII,CAAC,GAAGJ,6BAA6B,CAACK,MAAM;EAC5C,OAAOD,CAAC,IAAI,CAAC,EAAE;IACX,IAAIF,KAAK,KAAKF,6BAA6B,CAACI,CAAC,CAAC,EAAE;MAC5CD,MAAM,GAAGH,6BAA6B,CAACI,CAAC,CAAC;MACzC;IACJ;IAEA,IAAIF,KAAK,GAAGF,6BAA6B,CAACI,CAAC,CAAC,EAAE;MAC1C;MACAD,MAAM,GAAGH,6BAA6B,CAACI,CAAC,GAAG,CAAC,CAAC;MAC7C,IAAI,CAACD,MAAM,EAAE;QACTA,MAAM,GAAGH,6BAA6B,CAACI,CAAC,CAAC;MAC7C;MACA;IACJ;IAEAA,CAAC,EAAE;EACP;EAEA,OAA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|
|
4
|
-
import imagePlugin from "./image";
|
|
5
|
-
export { imagePlugin };
|
|
1
|
+
"use strict";
|
|
6
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
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"));
|
|
7
19
|
var PluginComponent = function PluginComponent(props) {
|
|
8
20
|
return props.children;
|
|
9
21
|
};
|
|
10
|
-
|
|
11
22
|
var PluginsComponent = function PluginsComponent(props) {
|
|
12
23
|
return props.children;
|
|
13
24
|
};
|
|
14
|
-
|
|
15
|
-
export var renderPlugin = function renderPlugin(name) {
|
|
25
|
+
var renderPlugin = function renderPlugin(name) {
|
|
16
26
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17
27
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
18
28
|
var _options$wrapper = options.wrapper,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var plugin = plugins.byName(name);
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
wrapper = _options$wrapper === void 0 ? true : _options$wrapper,
|
|
30
|
+
_options$fn = options.fn,
|
|
31
|
+
fn = _options$fn === void 0 ? "render" : _options$fn;
|
|
32
|
+
var plugin = _plugins.plugins.byName(name);
|
|
33
|
+
(0, _warning.default)(plugin, "No such plugin \"".concat(name, "\""));
|
|
25
34
|
if (!plugin) {
|
|
26
35
|
return null;
|
|
27
36
|
}
|
|
28
|
-
|
|
29
37
|
var content = plugin[fn](params);
|
|
30
|
-
|
|
31
38
|
if (content) {
|
|
32
|
-
return wrapper ? /*#__PURE__*/
|
|
39
|
+
return wrapper ? /*#__PURE__*/_react.default.createElement(PluginComponent, {
|
|
33
40
|
key: plugin.name,
|
|
34
41
|
name: name,
|
|
35
42
|
params: params,
|
|
36
43
|
fn: fn
|
|
37
|
-
}, content) : /*#__PURE__*/
|
|
44
|
+
}, content) : /*#__PURE__*/_react.default.cloneElement(content, {
|
|
38
45
|
key: plugin.name
|
|
39
46
|
});
|
|
40
47
|
}
|
|
41
|
-
|
|
42
48
|
return null;
|
|
43
49
|
};
|
|
44
|
-
|
|
50
|
+
exports.renderPlugin = renderPlugin;
|
|
51
|
+
var renderPlugins = function renderPlugins(type) {
|
|
45
52
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
46
53
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
47
54
|
var _options$wrapper2 = options.wrapper,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var content = plugins.byType(type).filter(
|
|
55
|
+
wrapper = _options$wrapper2 === void 0 ? true : _options$wrapper2,
|
|
56
|
+
_options$fn2 = options.fn,
|
|
57
|
+
fn = _options$fn2 === void 0 ? "render" : _options$fn2,
|
|
58
|
+
_options$filter = options.filter,
|
|
59
|
+
filter = _options$filter === void 0 ? function (v) {
|
|
60
|
+
return v;
|
|
61
|
+
} : _options$filter,
|
|
62
|
+
reverse = options.reverse;
|
|
63
|
+
var content = _plugins.plugins.byType(type).filter(function (pl) {
|
|
64
|
+
/**
|
|
65
|
+
* TODO @ts-refactor Problem with possibility of a different subtype.
|
|
66
|
+
*/
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
return filter(pl);
|
|
69
|
+
})
|
|
70
|
+
/**
|
|
71
|
+
* We cast as string because renderPlugin checks for the plugin.name
|
|
72
|
+
*/.map(function (plugin) {
|
|
57
73
|
return renderPlugin(plugin.name, params, {
|
|
58
74
|
wrapper: wrapper,
|
|
59
75
|
fn: fn
|
|
60
76
|
});
|
|
61
77
|
}).filter(Boolean);
|
|
62
|
-
|
|
63
78
|
if (reverse) {
|
|
64
79
|
content.reverse();
|
|
65
80
|
}
|
|
66
|
-
|
|
67
|
-
return wrapper ? /*#__PURE__*/React.createElement(PluginsComponent, {
|
|
81
|
+
return wrapper ? /*#__PURE__*/_react.default.createElement(PluginsComponent, {
|
|
68
82
|
type: type,
|
|
69
83
|
params: params,
|
|
70
84
|
fn: fn
|
|
71
85
|
}, content) : content;
|
|
72
86
|
};
|
|
73
|
-
|
|
87
|
+
exports.renderPlugins = renderPlugins;
|
|
88
|
+
var _default = [_image.default];
|
|
89
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PluginComponent","props","children","PluginsComponent","renderPlugin","name","params","options","wrapper","fn","plugin","plugins","byName","warning","content","React","cloneElement","key","renderPlugins","type","filter","v","reverse","byType","pl","map","Boolean","imagePlugin"],"sources":["index.tsx"],"sourcesContent":["import React, { ReactNode } from \"react\";\nimport warning from \"warning\";\nimport { plugins } from \"@webiny/plugins\";\nimport { 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}\nconst PluginComponent: React.FC<PluginComponentProps> = props => {\n return props.children as React.ReactElement;\n};\ninterface PluginsComponentProps {\n type: string;\n params: Record<string, any>;\n fn: string;\n}\nconst PluginsComponent: React.FC<PluginsComponentProps> = props => {\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-ignore\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":";;;;;;;;;;;;;;AAAA;AACA;AACA;AAEA;AA4BA,IAAMA,eAA+C,GAAG,SAAlDA,eAA+C,CAAGC,KAAK,EAAI;EAC7D,OAAOA,KAAK,CAACC,QAAQ;AACzB,CAAC;AAMD,IAAMC,gBAAiD,GAAG,SAApDA,gBAAiD,CAAGF,KAAK,EAAI;EAC/D,OAAOA,KAAK,CAACC,QAAQ;AACzB,CAAC;AAEM,IAAME,YAA0B,GAAG,SAA7BA,YAA0B,CAAIC,IAAI,EAAgC;EAAA,IAA9BC,M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AAM,CAAC,UAAAI,EAAE,EAAI;IACV;AACZ;AACA;IACY;IACA,OAAOJ,MAAM,CAACI,EAAE,CAAC;EACrB,CAAC;EACD;AACR;AACA,KAFQ,CAGCC,GAAG,CAAC,UAAAf,MAAM;IAAA,OAAIN,YAAY,CAACM,MAAM,CAACL,IAAI,EAAYC,MAAM,EAAE;MAAEE,OAAO,EAAPA,OAAO;MAAEC,EAAE,EAAFA;IAAG,CAAC,CAAC;EAAA,EAAC,CAC3EW,MAAM,CAACM,OAAO,CAAC;EAEpB,IAAIJ,OAAO,EAAE;IACTR,OAAO,CAACQ,OAAO,EAAE;EACrB;EAEA,OAAOd,OAAO,gBACV,6BAAC,gBAAgB;IAAC,IAAI,EAAEW,IAAK;IAAC,MAAM,EAAEb,MAAO;IAAC,EAAE,EAAEG;EAAG,GAChDK,OAAO,CACO,GAEnBA,OACH;AACL,CAAC;AAAC;AAAA,eAEa,CAACa,cAAW,CAAC;AAAA"}
|
package/types.d.ts
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
|
+
/// <reference types="web" />
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import { Plugin } from "@webiny/plugins/types";
|
|
3
4
|
import { ApolloClient } from "apollo-client";
|
|
4
5
|
import { CSSProperties } from "react";
|
|
5
|
-
export declare type WebinyInitPlugin = Plugin & {
|
|
6
|
-
type: "webiny-init";
|
|
7
|
-
init(): void;
|
|
8
|
-
};
|
|
9
6
|
export declare type UploadOptions = {
|
|
10
7
|
apolloClient: ApolloClient<object>;
|
|
8
|
+
onProgress?: (params: {
|
|
9
|
+
sent: number;
|
|
10
|
+
total: number;
|
|
11
|
+
percentage: number;
|
|
12
|
+
}) => void;
|
|
11
13
|
};
|
|
12
14
|
export declare type UiStatePlugin = Plugin & {
|
|
13
15
|
type: "ui-state";
|
|
14
16
|
render(): React.ReactElement;
|
|
15
17
|
};
|
|
18
|
+
export interface UploadedFile {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
size: number;
|
|
23
|
+
key: string;
|
|
24
|
+
}
|
|
16
25
|
export declare type FileUploaderPlugin = Plugin & {
|
|
17
26
|
type: "file-uploader";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare type AppFileManagerStoragePlugin = Plugin & {
|
|
21
|
-
type: "app-file-manager-storage";
|
|
22
|
-
upload(file: File, options: UploadOptions): Promise<any>;
|
|
27
|
+
name: "file-uploader";
|
|
28
|
+
upload(file: File, options: UploadOptions): Promise<UploadedFile>;
|
|
23
29
|
};
|
|
24
30
|
export { Plugin };
|
|
25
|
-
export
|
|
31
|
+
export interface ImageProps {
|
|
26
32
|
src: string;
|
|
27
33
|
preset?: string;
|
|
28
34
|
transform?: {
|
|
@@ -35,7 +41,9 @@ export declare type ImageProps = {
|
|
|
35
41
|
title?: string;
|
|
36
42
|
alt?: string;
|
|
37
43
|
style?: CSSProperties;
|
|
38
|
-
|
|
44
|
+
width?: string | number;
|
|
45
|
+
height?: string | number;
|
|
46
|
+
}
|
|
39
47
|
/**
|
|
40
48
|
* "getImageSrc" has to be defined as a separate property, so its functionality can be reused outside of
|
|
41
49
|
* the Image component. This is ideal in cases where manual creation of image src is needed.
|
|
@@ -43,7 +51,7 @@ export declare type ImageProps = {
|
|
|
43
51
|
export declare type ImageComponentPlugin = Plugin & {
|
|
44
52
|
type: "image-component";
|
|
45
53
|
render: (props: ImageProps) => React.ReactElement;
|
|
46
|
-
getImageSrc: (props?:
|
|
54
|
+
getImageSrc: (props?: Record<string, any>) => string;
|
|
47
55
|
presets: {
|
|
48
56
|
[key: string]: any;
|
|
49
57
|
};
|
|
@@ -56,7 +64,3 @@ export declare type RoutePlugin = Plugin & {
|
|
|
56
64
|
type: "route";
|
|
57
65
|
route: React.ReactElement;
|
|
58
66
|
};
|
|
59
|
-
export declare type CacheGetObjectIdPlugin = Plugin & {
|
|
60
|
-
type: "cache-get-object-id";
|
|
61
|
-
getObjectId(obj: Record<string, any>): string | undefined;
|
|
62
|
-
};
|
package/types.js
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Plugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _types.Plugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _types = require("@webiny/plugins/types");
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import * as React from \"react\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { ApolloClient } from \"apollo-client\";\nimport { CSSProperties } from \"react\";\n\nexport type UploadOptions = {\n apolloClient: ApolloClient<object>;\n onProgress?: (params: { sent: number; total: number; percentage: number }) => void;\n};\n\nexport type UiStatePlugin = Plugin & {\n type: \"ui-state\";\n render(): React.ReactElement;\n};\n\nexport interface UploadedFile {\n id: string;\n name: string;\n type: string;\n size: number;\n key: string;\n}\n\nexport type FileUploaderPlugin = Plugin & {\n type: \"file-uploader\";\n name: \"file-uploader\";\n upload(file: File, options: UploadOptions): Promise<UploadedFile>;\n};\n\nexport { Plugin };\n\nexport interface ImageProps {\n src: string;\n preset?: string;\n transform?: {\n [key: string]: any;\n };\n // \"auto\" is a special keyword - if present, plugins insert their own srcSet.\n srcSet?: { [key: string]: any } | \"auto\";\n className?: string;\n title?: string;\n alt?: string;\n style?: CSSProperties;\n width?: string | number;\n height?: string | number;\n}\n\n/**\n * \"getImageSrc\" has to be defined as a separate property, so its functionality can be reused outside of\n * the Image component. This is ideal in cases where manual creation of image src is needed.\n */\nexport type ImageComponentPlugin = Plugin & {\n type: \"image-component\";\n render: (props: ImageProps) => React.ReactElement;\n getImageSrc: (props?: Record<string, any>) => string;\n presets: { [key: string]: any };\n};\n\n/**\n * Enables registering new routes.\n * @see https://docs.webiny.com/docs/webiny-apps/admin/development/plugins-reference/app#route\n */\nexport type RoutePlugin = Plugin & {\n type: \"route\";\n route: React.ReactElement;\n};\n"],"mappings":";;;;;;;;;;;AACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getApiUrl: (path?: string) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getApiUrl = void 0;
|
|
7
|
+
var getApiUrl = function getApiUrl() {
|
|
8
|
+
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
9
|
+
return process.env.REACT_APP_API_URL + path;
|
|
10
|
+
};
|
|
11
|
+
exports.getApiUrl = getApiUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getApiUrl","path","process","env","REACT_APP_API_URL"],"sources":["getApiUrl.ts"],"sourcesContent":["export const getApiUrl = (path = \"\"): string => {\n return process.env.REACT_APP_API_URL + path;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,SAAS,GAAG,SAAZA,SAAS,GAA0B;EAAA,IAAtBC,IAAI,uEAAG,EAAE;EAC/B,OAAOC,OAAO,CAACC,GAAG,CAACC,iBAAiB,GAAGH,IAAI;AAC/C,CAAC;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getGqlApiUrl: () => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getGqlApiUrl = void 0;
|
|
7
|
+
var _getApiUrl = require("./getApiUrl");
|
|
8
|
+
var getGqlApiUrl = function getGqlApiUrl() {
|
|
9
|
+
return (0, _getApiUrl.getApiUrl)("/graphql");
|
|
10
|
+
};
|
|
11
|
+
exports.getGqlApiUrl = getGqlApiUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getGqlApiUrl","getApiUrl"],"sources":["getGqlApiUrl.ts"],"sourcesContent":["import { getApiUrl } from \"./getApiUrl\";\n\nexport const getGqlApiUrl = (): string => {\n return getApiUrl(\"/graphql\");\n};\n"],"mappings":";;;;;;AAAA;AAEO,IAAMA,YAAY,GAAG,SAAfA,YAAY,GAAiB;EACtC,OAAO,IAAAC,oBAAS,EAAC,UAAU,CAAC;AAChC,CAAC;AAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getHeadlessCmsGqlApiUrl = void 0;
|
|
7
|
+
var _getApiUrl = require("./getApiUrl");
|
|
8
|
+
var _getLocaleCode = require("./getLocaleCode");
|
|
9
|
+
var getHeadlessCmsGqlApiUrl = function getHeadlessCmsGqlApiUrl() {
|
|
10
|
+
var locale = (0, _getLocaleCode.getLocaleCode)();
|
|
11
|
+
return {
|
|
12
|
+
preview: (0, _getApiUrl.getApiUrl)("/cms/preview/".concat(locale)),
|
|
13
|
+
read: (0, _getApiUrl.getApiUrl)("/cms/read/".concat(locale)),
|
|
14
|
+
manage: (0, _getApiUrl.getApiUrl)("/cms/manage/".concat(locale))
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.getHeadlessCmsGqlApiUrl = getHeadlessCmsGqlApiUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getHeadlessCmsGqlApiUrl","locale","getLocaleCode","preview","getApiUrl","read","manage"],"sources":["getHeadlessCmsGqlApiUrl.ts"],"sourcesContent":["import { getApiUrl } from \"./getApiUrl\";\nimport { getLocaleCode } from \"./getLocaleCode\";\n\nexport const getHeadlessCmsGqlApiUrl = (): { preview: string; read: string; manage: string } => {\n const locale = getLocaleCode();\n return {\n preview: getApiUrl(`/cms/preview/${locale}`),\n read: getApiUrl(`/cms/read/${locale}`),\n manage: getApiUrl(`/cms/manage/${locale}`)\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AAEO,IAAMA,uBAAuB,GAAG,SAA1BA,uBAAuB,GAA4D;EAC5F,IAAMC,MAAM,GAAG,IAAAC,4BAAa,GAAE;EAC9B,OAAO;IACHC,OAAO,EAAE,IAAAC,oBAAS,yBAAiBH,MAAM,EAAG;IAC5CI,IAAI,EAAE,IAAAD,oBAAS,sBAAcH,MAAM,EAAG;IACtCK,MAAM,EAAE,IAAAF,oBAAS,wBAAgBH,MAAM;EAC3C,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getLocaleCode = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _isLocalhost = require("./isLocalhost");
|
|
10
|
+
var getLocaleCode = function getLocaleCode() {
|
|
11
|
+
// 1. Get locale via the `__locale` query param. Useful when doing page previews.
|
|
12
|
+
var locale = new URLSearchParams(location.search).get("__locale");
|
|
13
|
+
if (locale) {
|
|
14
|
+
return locale;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 2. Get locale via `window.__PS_RENDER_LOCALE__`. Used with prerendered pages.
|
|
18
|
+
locale = window.__PS_RENDER_LOCALE__;
|
|
19
|
+
if (locale) {
|
|
20
|
+
return locale;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 3. Get locale via `window.localStorage.webiny_i18n_locale`. Used within the Admin app.
|
|
24
|
+
var localesByContext = window.localStorage.webiny_i18n_locale;
|
|
25
|
+
if (localesByContext) {
|
|
26
|
+
// The `localesByContext` is a string that contains locales for all available
|
|
27
|
+
// "locale contexts", for example: `default:en-US;content:en-US;`. Here, we
|
|
28
|
+
// want to extract the locale for the "content" locale context.
|
|
29
|
+
var _localesByContext$mat = localesByContext.match(/content:(.*?);/),
|
|
30
|
+
_localesByContext$mat2 = (0, _slicedToArray2.default)(_localesByContext$mat, 2),
|
|
31
|
+
matchedLocale = _localesByContext$mat2[1];
|
|
32
|
+
return matchedLocale;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 4. Finally, for development purposes, we take the `WEBINY_WEBSITE_LOCALE_CODE`
|
|
36
|
+
// and `WEBINY_ADMIN_LOCALE_CODE` environment variables into consideration.
|
|
37
|
+
if ((0, _isLocalhost.isLocalhost)()) {
|
|
38
|
+
return process.env.WEBINY_WEBSITE_LOCALE_CODE || process.env.WEBINY_ADMIN_LOCALE_CODE || null;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
exports.getLocaleCode = getLocaleCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getLocaleCode","locale","URLSearchParams","location","search","get","window","__PS_RENDER_LOCALE__","localesByContext","localStorage","webiny_i18n_locale","match","matchedLocale","isLocalhost","process","env","WEBINY_WEBSITE_LOCALE_CODE","WEBINY_ADMIN_LOCALE_CODE"],"sources":["getLocaleCode.ts"],"sourcesContent":["import { isLocalhost } from \"./isLocalhost\";\n\ndeclare global {\n interface Window {\n __PS_RENDER_LOCALE__: string;\n }\n}\n\nexport const getLocaleCode = (): string | null => {\n // 1. Get locale via the `__locale` query param. Useful when doing page previews.\n let locale = new URLSearchParams(location.search).get(\"__locale\");\n if (locale) {\n return locale;\n }\n\n // 2. Get locale via `window.__PS_RENDER_LOCALE__`. Used with prerendered pages.\n locale = window.__PS_RENDER_LOCALE__;\n if (locale) {\n return locale;\n }\n\n // 3. Get locale via `window.localStorage.webiny_i18n_locale`. Used within the Admin app.\n const localesByContext = window.localStorage.webiny_i18n_locale;\n if (localesByContext) {\n // The `localesByContext` is a string that contains locales for all available\n // \"locale contexts\", for example: `default:en-US;content:en-US;`. Here, we\n // want to extract the locale for the \"content\" locale context.\n const [, matchedLocale] = localesByContext.match(/content:(.*?);/);\n return matchedLocale;\n }\n\n // 4. Finally, for development purposes, we take the `WEBINY_WEBSITE_LOCALE_CODE`\n // and `WEBINY_ADMIN_LOCALE_CODE` environment variables into consideration.\n if (isLocalhost()) {\n return (\n process.env.WEBINY_WEBSITE_LOCALE_CODE || process.env.WEBINY_ADMIN_LOCALE_CODE || null\n );\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;AAAA;AAQO,IAAMA,aAAa,GAAG,SAAhBA,aAAa,GAAwB;EAC9C;EACA,IAAIC,MAAM,GAAG,IAAIC,eAAe,CAACC,QAAQ,CAACC,MAAM,CAAC,CAACC,GAAG,CAAC,UAAU,CAAC;EACjE,IAAIJ,MAAM,EAAE;IACR,OAAOA,MAAM;EACjB;;EAEA;EACAA,MAAM,GAAGK,MAAM,CAACC,oBAAoB;EACpC,IAAIN,MAAM,EAAE;IACR,OAAOA,MAAM;EACjB;;EAEA;EACA,IAAMO,gBAAgB,GAAGF,MAAM,CAACG,YAAY,CAACC,kBAAkB;EAC/D,IAAIF,gBAAgB,EAAE;IAClB;IACA;IACA;IACA,4BAA0BA,gBAAgB,CAACG,KAAK,CAAC,gBAAgB,CAAC;MAAA;MAAzDC,aAAa;IACtB,OAAOA,aAAa;EACxB;;EAEA;EACA;EACA,IAAI,IAAAC,wBAAW,GAAE,EAAE;IACf,OACIC,OAAO,CAACC,GAAG,CAACC,0BAA0B,IAAIF,OAAO,CAACC,GAAG,CAACE,wBAAwB,IAAI,IAAI;EAE9F;EAEA,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPrerenderId = void 0;
|
|
7
|
+
var getPrerenderId = function getPrerenderId() {
|
|
8
|
+
return window["__PS_RENDER_ID__"] || null;
|
|
9
|
+
};
|
|
10
|
+
exports.getPrerenderId = getPrerenderId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getPrerenderId","window"],"sources":["getPrerenderId.ts"],"sourcesContent":["declare global {\n interface Window {\n __PS_RENDER_ID__: string;\n }\n}\n\nexport const getPrerenderId = (): string | null => {\n return window[\"__PS_RENDER_ID__\"] || null;\n};\n"],"mappings":";;;;;;AAMO,IAAMA,cAAc,GAAG,SAAjBA,cAAc,GAAwB;EAC/C,OAAOC,MAAM,CAAC,kBAAkB,CAAC,IAAI,IAAI;AAC7C,CAAC;AAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTenantId = void 0;
|
|
7
|
+
var _isLocalhost = require("./isLocalhost");
|
|
8
|
+
var getTenantId = function getTenantId() {
|
|
9
|
+
// 1. Get tenant via the `__tenant` query param. Useful when doing page previews.
|
|
10
|
+
var tenant = new URLSearchParams(location.search).get("__tenant");
|
|
11
|
+
if (tenant) {
|
|
12
|
+
return tenant;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 2. Get tenant via `window.__PS_RENDER_TENANT__`. Used with prerendered pages.
|
|
16
|
+
tenant = window.__PS_RENDER_TENANT__;
|
|
17
|
+
if (tenant) {
|
|
18
|
+
return tenant;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 3. Get tenant via `window.localStorage.webiny_tenant`. Used within the Admin app.
|
|
22
|
+
tenant = window.localStorage.webiny_tenant;
|
|
23
|
+
if (tenant) {
|
|
24
|
+
return tenant;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 4. Finally, for development purposes, we take the `WEBINY_WEBSITE_TENANT_ID`
|
|
28
|
+
// and `WEBINY_ADMIN_TENANT_ID` environment variables into consideration.
|
|
29
|
+
if ((0, _isLocalhost.isLocalhost)()) {
|
|
30
|
+
return process.env.WEBINY_WEBSITE_TENANT_ID || process.env.WEBINY_ADMIN_TENANT_ID || null;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
exports.getTenantId = getTenantId;
|