@webiny/app 0.0.0-mt-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/apollo-client/InMemoryCache.d.ts +7 -0
  4. package/apollo-client/InMemoryCache.js +59 -0
  5. package/components/Image.d.ts +3 -0
  6. package/components/Image.js +28 -0
  7. package/components/Routes.d.ts +2 -0
  8. package/components/Routes.js +35 -0
  9. package/components/View.d.ts +8 -0
  10. package/components/View.js +23 -0
  11. package/components/index.d.ts +1 -0
  12. package/components/index.js +1 -0
  13. package/contexts/Ui/index.d.ts +27 -0
  14. package/contexts/Ui/index.js +69 -0
  15. package/hooks/useAutocomplete/index.d.ts +1 -0
  16. package/hooks/useAutocomplete/index.js +1 -0
  17. package/hooks/useAutocomplete/useAutocomplete.d.ts +6 -0
  18. package/hooks/useAutocomplete/useAutocomplete.js +27 -0
  19. package/hooks/useDataList/functions/getData.d.ts +2 -0
  20. package/hooks/useDataList/functions/getData.js +4 -0
  21. package/hooks/useDataList/functions/getError.d.ts +2 -0
  22. package/hooks/useDataList/functions/getError.js +4 -0
  23. package/hooks/useDataList/functions/getMeta.d.ts +2 -0
  24. package/hooks/useDataList/functions/getMeta.js +4 -0
  25. package/hooks/useDataList/functions/index.d.ts +3 -0
  26. package/hooks/useDataList/functions/index.js +3 -0
  27. package/hooks/useDataList/functions/searchDataByKey.d.ts +2 -0
  28. package/hooks/useDataList/functions/searchDataByKey.js +21 -0
  29. package/hooks/useDataList/index.d.ts +1 -0
  30. package/hooks/useDataList/index.js +1 -0
  31. package/hooks/useDataList/useDataList.d.ts +36 -0
  32. package/hooks/useDataList/useDataList.js +193 -0
  33. package/hooks/useDataList/utils/index.d.ts +2 -0
  34. package/hooks/useDataList/utils/index.js +2 -0
  35. package/hooks/useDataList/utils/prepareLoadListParams.d.ts +4 -0
  36. package/hooks/useDataList/utils/prepareLoadListParams.js +34 -0
  37. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +5 -0
  38. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +22 -0
  39. package/hooks/useDataList/utils/types.d.ts +34 -0
  40. package/hooks/useDataList/utils/types.js +1 -0
  41. package/hooks/useHandler.d.ts +1 -0
  42. package/hooks/useHandler.js +12 -0
  43. package/hooks/useHandlers.d.ts +11 -0
  44. package/hooks/useHandlers.js +19 -0
  45. package/hooks/useUi.d.ts +2 -0
  46. package/hooks/useUi.js +5 -0
  47. package/i18n/i18n.d.ts +2 -0
  48. package/i18n/i18n.js +5 -0
  49. package/i18n/index.d.ts +1 -0
  50. package/i18n/index.js +1 -0
  51. package/package.json +70 -0
  52. package/plugins/AddQuerySelectionPlugin.d.ts +15 -0
  53. package/plugins/AddQuerySelectionPlugin.js +101 -0
  54. package/plugins/ApolloCacheObjectIdPlugin.d.ts +15 -0
  55. package/plugins/ApolloCacheObjectIdPlugin.js +40 -0
  56. package/plugins/ApolloDynamicLink.d.ts +5 -0
  57. package/plugins/ApolloDynamicLink.js +62 -0
  58. package/plugins/ApolloLinkPlugin.d.ts +13 -0
  59. package/plugins/ApolloLinkPlugin.js +43 -0
  60. package/plugins/ConsoleLinkPlugin.d.ts +8 -0
  61. package/plugins/ConsoleLinkPlugin.js +47 -0
  62. package/plugins/LocaleHeaderLinkPlugin.d.ts +14 -0
  63. package/plugins/LocaleHeaderLinkPlugin.js +61 -0
  64. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +6 -0
  65. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +76 -0
  66. package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +3 -0
  67. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +9 -0
  68. package/plugins/NetworkErrorLinkPlugin/assets/close_24px.svg +1 -0
  69. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +5 -0
  70. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +27 -0
  71. package/plugins/NetworkErrorLinkPlugin.d.ts +7 -0
  72. package/plugins/NetworkErrorLinkPlugin.js +45 -0
  73. package/plugins/OmitTypenameLinkPlugin.d.ts +8 -0
  74. package/plugins/OmitTypenameLinkPlugin.js +41 -0
  75. package/plugins/RoutePlugin.d.ts +12 -0
  76. package/plugins/RoutePlugin.js +36 -0
  77. package/plugins/TenantHeaderLinkPlugin.d.ts +14 -0
  78. package/plugins/TenantHeaderLinkPlugin.js +71 -0
  79. package/plugins/ViewPlugin.d.ts +14 -0
  80. package/plugins/ViewPlugin.js +41 -0
  81. package/plugins/image.d.ts +3 -0
  82. package/plugins/image.js +165 -0
  83. package/plugins/index.d.ts +20 -0
  84. package/plugins/index.js +73 -0
  85. package/types.d.ts +62 -0
  86. package/types.js +2 -0
@@ -0,0 +1,165 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["transform", "srcSet"];
4
+ import React from "react";
5
+ import { Image } from "@webiny/ui/Image";
6
+ var SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];
7
+ /**
8
+ * Width of the image should not be just any random number. For optimization reasons,
9
+ * we only allow the ones listed in SUPPORTED_IMAGE_RESIZE_WIDTHS list (Webiny Cloud supports only these).
10
+ */
11
+
12
+ var getSupportedImageResizeWidth = function getSupportedImageResizeWidth(width) {
13
+ var output = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];
14
+ var i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;
15
+
16
+ while (i >= 0) {
17
+ if (width === SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
18
+ output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
19
+ break;
20
+ }
21
+
22
+ if (width > SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
23
+ // Use next larger width. If there isn't any, use current.
24
+ output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i + 1];
25
+
26
+ if (!output) {
27
+ output = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
28
+ }
29
+
30
+ break;
31
+ }
32
+
33
+ i--;
34
+ }
35
+
36
+ return output;
37
+ };
38
+ /**
39
+ * Currently we only allow "width" as a transform option.
40
+ * @param args
41
+ */
42
+
43
+
44
+ var sanitizeTransformArgs = function sanitizeTransformArgs(args) {
45
+ var output = {};
46
+
47
+ if (args) {
48
+ var width = parseInt(args.width);
49
+
50
+ if (width > 0) {
51
+ output.width = getSupportedImageResizeWidth(width);
52
+ }
53
+ }
54
+
55
+ return output;
56
+ };
57
+
58
+ var getSizes = function getSizes(width) {
59
+ // Check if width was set as percentage, with "%" in the value.
60
+ if (typeof width === "string" && width.endsWith("%")) {
61
+ return "".concat(parseInt(width), "vw");
62
+ } // Check if width was set as viewport width, with "vw" in the value.
63
+
64
+
65
+ if (typeof width === "string" && width.endsWith("vw")) {
66
+ return "".concat(parseInt(width), "vw");
67
+ } // Check if width was set as relative, with "em" in the value.
68
+
69
+
70
+ if (typeof width === "string" && width.endsWith("em")) {
71
+ return "".concat(parseInt(width), "em");
72
+ }
73
+
74
+ return null;
75
+ };
76
+
77
+ var isFixedImageWidth = function isFixedImageWidth(width) {
78
+ if (Number.isFinite(width)) {
79
+ return true;
80
+ }
81
+
82
+ if (typeof width === "string" && width.endsWith("px")) {
83
+ return true;
84
+ }
85
+
86
+ return false;
87
+ };
88
+
89
+ var getSrcSetAutoSizes = function getSrcSetAutoSizes(max) {
90
+ max = isFixedImageWidth(max) ? parseInt("" + max) : 2500;
91
+ var maxWidth = getSupportedImageResizeWidth(max);
92
+ return SUPPORTED_IMAGE_RESIZE_WIDTHS.filter(function (supportedWidth) {
93
+ return supportedWidth <= maxWidth;
94
+ });
95
+ };
96
+
97
+ var convertTransformToQueryParams = function convertTransformToQueryParams(transform) {
98
+ return Object.keys(transform).map(function (key) {
99
+ return "".concat(key, "=").concat(transform[key]);
100
+ }).join("&");
101
+ };
102
+
103
+ export default (function () {
104
+ var imagePlugin = {
105
+ name: "image-component",
106
+ type: "image-component",
107
+ presets: {
108
+ avatar: {
109
+ width: 300
110
+ }
111
+ },
112
+ getImageSrc: function getImageSrc(props) {
113
+ if (!props) {
114
+ return "";
115
+ }
116
+
117
+ var src = props.src,
118
+ transform = props.transform;
119
+
120
+ if (!transform) {
121
+ return src;
122
+ }
123
+
124
+ if (!src || src.startsWith("data:") || src.endsWith("svg")) {
125
+ return src;
126
+ }
127
+
128
+ var params = sanitizeTransformArgs(transform);
129
+ params = convertTransformToQueryParams(params);
130
+ return src + "?" + params;
131
+ },
132
+ render: function render(props) {
133
+ var transform = props.transform,
134
+ srcSetInitial = props.srcSet,
135
+ imageProps = _objectWithoutProperties(props, _excluded);
136
+
137
+ var srcSet = srcSetInitial;
138
+ var sizes;
139
+ var src = imageProps.src;
140
+
141
+ if (srcSet && srcSet === "auto") {
142
+ srcSet = {}; // Check if image width was forced, and additionally if width was set as pixels, with "px" in the value.
143
+
144
+ var forcedWidth = props.width || props.style && props.style.width;
145
+ var srcSetAutoWidths = getSrcSetAutoSizes(forcedWidth);
146
+ srcSetAutoWidths.forEach(function (width) {
147
+ srcSet[width + "w"] = imagePlugin.getImageSrc({
148
+ src: src,
149
+ transform: _objectSpread(_objectSpread({}, transform), {}, {
150
+ width: width
151
+ })
152
+ });
153
+ });
154
+ sizes = getSizes(forcedWidth);
155
+ }
156
+
157
+ return /*#__PURE__*/React.createElement(Image, Object.assign({}, imageProps, {
158
+ srcSet: srcSet,
159
+ src: src,
160
+ sizes: sizes
161
+ }));
162
+ }
163
+ };
164
+ return imagePlugin;
165
+ });
@@ -0,0 +1,20 @@
1
+ import { ReactNode } from "react";
2
+ import { Plugin } from "@webiny/plugins/types";
3
+ import imagePlugin from "./image";
4
+ export { imagePlugin };
5
+ declare type RenderPluginOptions<T> = {
6
+ wrapper?: boolean;
7
+ fn?: string;
8
+ filter?: (value: T, index: number, array: T[]) => boolean;
9
+ reverse?: boolean;
10
+ };
11
+ interface RenderPlugin {
12
+ <T extends Plugin = Plugin>(name: string, params?: any, options?: RenderPluginOptions<T>): ReactNode | ReactNode[];
13
+ }
14
+ interface RenderPlugins {
15
+ <T extends Plugin = Plugin>(type: string, params?: any, options?: RenderPluginOptions<T>): ReactNode | ReactNode[];
16
+ }
17
+ export declare const renderPlugin: RenderPlugin;
18
+ export declare const renderPlugins: RenderPlugins;
19
+ declare const _default: (() => import("../types").ImageComponentPlugin)[];
20
+ export default _default;
@@ -0,0 +1,73 @@
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
+
7
+ var PluginComponent = function PluginComponent(props) {
8
+ return props.children;
9
+ };
10
+
11
+ var PluginsComponent = function PluginsComponent(props) {
12
+ return props.children;
13
+ };
14
+
15
+ export var renderPlugin = function renderPlugin(name) {
16
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
18
+ var _options$wrapper = options.wrapper,
19
+ wrapper = _options$wrapper === void 0 ? true : _options$wrapper,
20
+ _options$fn = options.fn,
21
+ fn = _options$fn === void 0 ? "render" : _options$fn;
22
+ var plugin = plugins.byName(name);
23
+ warning(plugin, "No such plugin \"".concat(name, "\""));
24
+
25
+ if (!plugin) {
26
+ return null;
27
+ }
28
+
29
+ var content = plugin[fn](params);
30
+
31
+ if (content) {
32
+ return wrapper ? /*#__PURE__*/React.createElement(PluginComponent, {
33
+ key: plugin.name,
34
+ name: name,
35
+ params: params,
36
+ fn: fn
37
+ }, content) : /*#__PURE__*/React.cloneElement(content, {
38
+ key: plugin.name
39
+ });
40
+ }
41
+
42
+ return null;
43
+ };
44
+ export var renderPlugins = function renderPlugins(type) {
45
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
47
+ var _options$wrapper2 = options.wrapper,
48
+ wrapper = _options$wrapper2 === void 0 ? true : _options$wrapper2,
49
+ _options$fn2 = options.fn,
50
+ fn = _options$fn2 === void 0 ? "render" : _options$fn2,
51
+ _options$filter = options.filter,
52
+ filter = _options$filter === void 0 ? function (v) {
53
+ return v;
54
+ } : _options$filter,
55
+ reverse = options.reverse;
56
+ var content = plugins.byType(type).filter(filter).map(function (plugin) {
57
+ return renderPlugin(plugin.name, params, {
58
+ wrapper: wrapper,
59
+ fn: fn
60
+ });
61
+ }).filter(Boolean);
62
+
63
+ if (reverse) {
64
+ content.reverse();
65
+ }
66
+
67
+ return wrapper ? /*#__PURE__*/React.createElement(PluginsComponent, {
68
+ type: type,
69
+ params: params,
70
+ fn: fn
71
+ }, content) : content;
72
+ };
73
+ export default [imagePlugin];
package/types.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ import * as React from "react";
2
+ import { Plugin } from "@webiny/plugins/types";
3
+ import { ApolloClient } from "apollo-client";
4
+ import { CSSProperties } from "react";
5
+ export declare type WebinyInitPlugin = Plugin & {
6
+ type: "webiny-init";
7
+ init(): void;
8
+ };
9
+ export declare type UploadOptions = {
10
+ apolloClient: ApolloClient<object>;
11
+ };
12
+ export declare type UiStatePlugin = Plugin & {
13
+ type: "ui-state";
14
+ render(): React.ReactElement;
15
+ };
16
+ export declare type FileUploaderPlugin = Plugin & {
17
+ type: "file-uploader";
18
+ upload(file: File, options: UploadOptions): Promise<any>;
19
+ };
20
+ export declare type AppFileManagerStoragePlugin = Plugin & {
21
+ type: "app-file-manager-storage";
22
+ upload(file: File, options: UploadOptions): Promise<any>;
23
+ };
24
+ export { Plugin };
25
+ export declare type ImageProps = {
26
+ src: string;
27
+ preset?: string;
28
+ transform?: {
29
+ [key: string]: any;
30
+ };
31
+ srcSet?: {
32
+ [key: string]: any;
33
+ } | "auto";
34
+ className?: string;
35
+ title?: string;
36
+ alt?: string;
37
+ style?: CSSProperties;
38
+ };
39
+ /**
40
+ * "getImageSrc" has to be defined as a separate property, so its functionality can be reused outside of
41
+ * the Image component. This is ideal in cases where manual creation of image src is needed.
42
+ */
43
+ export declare type ImageComponentPlugin = Plugin & {
44
+ type: "image-component";
45
+ render: (props: ImageProps) => React.ReactElement;
46
+ getImageSrc: (props?: Object) => string;
47
+ presets: {
48
+ [key: string]: any;
49
+ };
50
+ };
51
+ /**
52
+ * Enables registering new routes.
53
+ * @see https://docs.webiny.com/docs/webiny-apps/admin/development/plugins-reference/app#route
54
+ */
55
+ export declare type RoutePlugin = Plugin & {
56
+ type: "route";
57
+ route: React.ReactElement;
58
+ };
59
+ export declare type CacheGetObjectIdPlugin = Plugin & {
60
+ type: "cache-get-object-id";
61
+ getObjectId(obj: Record<string, any>): string | undefined;
62
+ };
package/types.js ADDED
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "@webiny/plugins/types";
2
+ export { Plugin };