@webiny/app 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97

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 (76) hide show
  1. package/App.d.ts +29 -0
  2. package/App.js +105 -0
  3. package/App.js.map +1 -0
  4. package/components/Routes.js +3 -0
  5. package/components/Routes.js.map +1 -1
  6. package/contexts/Ui/index.d.ts +0 -4
  7. package/contexts/Ui/index.js +2 -11
  8. package/contexts/Ui/index.js.map +1 -1
  9. package/core/AddRoute.d.ts +3 -0
  10. package/core/AddRoute.js +19 -0
  11. package/core/AddRoute.js.map +1 -0
  12. package/core/DebounceRender.d.ts +11 -0
  13. package/core/DebounceRender.js +41 -0
  14. package/core/DebounceRender.js.map +1 -0
  15. package/core/Plugin.d.ts +8 -0
  16. package/core/Plugin.js +21 -0
  17. package/core/Plugin.js.map +1 -0
  18. package/core/Plugins.d.ts +12 -0
  19. package/core/Plugins.js +45 -0
  20. package/core/Plugins.js.map +1 -0
  21. package/core/Provider.d.ts +9 -0
  22. package/core/Provider.js +21 -0
  23. package/core/Provider.js.map +1 -0
  24. package/core/Routes.d.ts +6 -0
  25. package/core/Routes.js +42 -0
  26. package/core/Routes.js.map +1 -0
  27. package/core/createProvider.d.ts +6 -0
  28. package/core/createProvider.js +13 -0
  29. package/core/createProvider.js.map +1 -0
  30. package/core/createProviderPlugin.d.ts +8 -0
  31. package/core/createProviderPlugin.js +21 -0
  32. package/core/createProviderPlugin.js.map +1 -0
  33. package/index.d.ts +11 -0
  34. package/index.js +115 -1
  35. package/index.js.map +1 -1
  36. package/package.json +23 -20
  37. package/plugins/AddQuerySelectionPlugin.d.ts +8 -1
  38. package/plugins/AddQuerySelectionPlugin.js +26 -5
  39. package/plugins/AddQuerySelectionPlugin.js.map +1 -1
  40. package/plugins/LocaleHeaderLinkPlugin.d.ts +0 -5
  41. package/plugins/LocaleHeaderLinkPlugin.js +2 -5
  42. package/plugins/LocaleHeaderLinkPlugin.js.map +1 -1
  43. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
  44. package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +9 -3
  45. package/plugins/TenantHeaderLinkPlugin.d.ts +0 -5
  46. package/plugins/TenantHeaderLinkPlugin.js +2 -5
  47. package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
  48. package/types.d.ts +17 -5
  49. package/types.js.map +1 -1
  50. package/utils/getApiUrl.d.ts +1 -0
  51. package/utils/getApiUrl.js +11 -0
  52. package/utils/getApiUrl.js.map +1 -0
  53. package/utils/getGqlApiUrl.d.ts +1 -0
  54. package/utils/getGqlApiUrl.js +11 -0
  55. package/utils/getGqlApiUrl.js.map +1 -0
  56. package/utils/getHeadlessCmsGqlApiUrl.d.ts +5 -0
  57. package/utils/getHeadlessCmsGqlApiUrl.js +17 -0
  58. package/utils/getHeadlessCmsGqlApiUrl.js.map +1 -0
  59. package/utils/getLocaleCode.d.ts +6 -0
  60. package/utils/getLocaleCode.js +42 -0
  61. package/utils/getLocaleCode.js.map +1 -0
  62. package/utils/getPrerenderId.d.ts +6 -0
  63. package/utils/getPrerenderId.js +10 -0
  64. package/utils/getPrerenderId.js.map +1 -0
  65. package/utils/getTenantId.d.ts +6 -0
  66. package/utils/getTenantId.js +34 -0
  67. package/utils/getTenantId.js.map +1 -0
  68. package/utils/index.d.ts +8 -0
  69. package/utils/index.js +93 -0
  70. package/utils/index.js.map +1 -0
  71. package/utils/isLocalhost.d.ts +1 -0
  72. package/utils/isLocalhost.js +14 -0
  73. package/utils/isLocalhost.js.map +1 -0
  74. package/utils/isPrerendering.d.ts +1 -0
  75. package/utils/isPrerendering.js +10 -0
  76. package/utils/isPrerendering.js.map +1 -0
package/App.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import React, { ReactElement } from "react";
2
+ import { RouteProps } from "@webiny/react-router";
3
+ import { HigherOrderComponent } from "@webiny/react-composition";
4
+ declare type RoutesByPath = {
5
+ [key: string]: ReactElement<RouteProps>;
6
+ };
7
+ interface State {
8
+ routes: RoutesByPath;
9
+ plugins: JSX.Element[];
10
+ providers: HigherOrderComponent[];
11
+ }
12
+ interface AppContext extends State {
13
+ addRoute(route: JSX.Element): void;
14
+ addProvider(hoc: HigherOrderComponent): void;
15
+ addPlugin(plugin: React.ReactNode): void;
16
+ }
17
+ declare const AppContext: React.Context<AppContext | undefined>;
18
+ export declare const useApp: () => AppContext;
19
+ export interface AppProps {
20
+ debounceRender?: number;
21
+ routes?: Array<RouteProps>;
22
+ providers?: Array<HigherOrderComponent>;
23
+ children?: React.ReactNode | React.ReactNode[];
24
+ }
25
+ export declare const App: {
26
+ ({ debounceRender, routes, providers, children }: AppProps): JSX.Element;
27
+ displayName: string;
28
+ };
29
+ export {};
package/App.js ADDED
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useApp = exports.App = void 0;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+ var _react = _interopRequireWildcard(require("react"));
14
+ var _reactRouter = require("@webiny/react-router");
15
+ var _reactComposition = require("@webiny/react-composition");
16
+ var _Routes = require("./core/Routes");
17
+ var _DebounceRender = require("./core/DebounceRender");
18
+ var _Plugins = require("./core/Plugins");
19
+ var AppContext = /*#__PURE__*/(0, _react.createContext)(undefined);
20
+ AppContext.displayName = "AppContext";
21
+ var useApp = function useApp() {
22
+ var appContext = (0, _react.useContext)(AppContext);
23
+ if (!appContext) {
24
+ throw Error("AppContext provider was not found. Are you using the \"useApp()\" hook in the right place?");
25
+ }
26
+ return appContext;
27
+ };
28
+ exports.useApp = useApp;
29
+ var App = function App(_ref) {
30
+ var _ref$debounceRender = _ref.debounceRender,
31
+ debounceRender = _ref$debounceRender === void 0 ? 50 : _ref$debounceRender,
32
+ _ref$routes = _ref.routes,
33
+ routes = _ref$routes === void 0 ? [] : _ref$routes,
34
+ _ref$providers = _ref.providers,
35
+ providers = _ref$providers === void 0 ? [] : _ref$providers,
36
+ children = _ref.children;
37
+ var _useState = (0, _react.useState)({
38
+ routes: routes.reduce(function (acc, item) {
39
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, acc), {}, (0, _defineProperty2.default)({}, item.path, /*#__PURE__*/_react.default.createElement(_reactRouter.Route, item)));
40
+ }, {}),
41
+ plugins: [],
42
+ providers: providers
43
+ }),
44
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
45
+ state = _useState2[0],
46
+ setState = _useState2[1];
47
+ var addRoute = (0, _react.useCallback)(function (route) {
48
+ setState(function (state) {
49
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state), {}, {
50
+ routes: (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state.routes), {}, (0, _defineProperty2.default)({}, route.props.path, route))
51
+ });
52
+ });
53
+ }, []);
54
+ var addProvider = (0, _react.useCallback)(function (component) {
55
+ setState(function (state) {
56
+ if (state.providers.findIndex(function (m) {
57
+ return m === component;
58
+ }) > -1) {
59
+ return state;
60
+ }
61
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state), {}, {
62
+ providers: [].concat((0, _toConsumableArray2.default)(state.providers), [component])
63
+ });
64
+ });
65
+ }, []);
66
+ var addPlugin = (0, _react.useCallback)(function (element) {
67
+ setState(function (state) {
68
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state), {}, {
69
+ plugins: [].concat((0, _toConsumableArray2.default)(state.plugins), [element])
70
+ });
71
+ });
72
+ }, []);
73
+ var appContext = (0, _react.useMemo)(function () {
74
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state), {}, {
75
+ addRoute: addRoute,
76
+ addProvider: addProvider,
77
+ addPlugin: addPlugin
78
+ });
79
+ }, [state]);
80
+ var AppRouter = (0, _react.useMemo)(function () {
81
+ return function AppRouter() {
82
+ var routes = Object.values(state.routes);
83
+ return /*#__PURE__*/_react.default.createElement(_Routes.Routes, {
84
+ key: routes.length,
85
+ routes: routes
86
+ });
87
+ };
88
+ }, [state.routes]);
89
+ var Providers = (0, _react.useMemo)(function () {
90
+ return _reactComposition.compose.apply(void 0, (0, _toConsumableArray2.default)(state.providers || []))(function (_ref2) {
91
+ var children = _ref2.children;
92
+ return /*#__PURE__*/_react.default.createElement(_DebounceRender.DebounceRender, {
93
+ wait: debounceRender
94
+ }, children);
95
+ });
96
+ }, [state.providers.length]);
97
+ Providers.displayName = "Providers";
98
+ return /*#__PURE__*/_react.default.createElement(AppContext.Provider, {
99
+ value: appContext
100
+ }, /*#__PURE__*/_react.default.createElement(_reactComposition.CompositionProvider, null, children, /*#__PURE__*/_react.default.createElement(_reactRouter.BrowserRouter, null, /*#__PURE__*/_react.default.createElement(Providers, null, /*#__PURE__*/_react.default.createElement(_Plugins.PluginsProvider, null, state.plugins), /*#__PURE__*/_react.default.createElement(_DebounceRender.DebounceRender, {
101
+ wait: debounceRender
102
+ }, /*#__PURE__*/_react.default.createElement(AppRouter, null))))));
103
+ };
104
+ exports.App = App;
105
+ App.displayName = "App";
package/App.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AppContext","createContext","undefined","displayName","useApp","appContext","useContext","Error","App","debounceRender","routes","providers","children","useState","reduce","acc","item","path","plugins","state","setState","addRoute","useCallback","route","props","addProvider","component","findIndex","m","addPlugin","element","useMemo","AppRouter","Object","values","length","Providers","compose"],"sources":["App.tsx"],"sourcesContent":["import React, {\n createContext,\n useContext,\n useMemo,\n useState,\n useCallback,\n FunctionComponentElement,\n ReactElement\n} from \"react\";\nimport { BrowserRouter, RouteProps, Route } from \"@webiny/react-router\";\nimport { compose, HigherOrderComponent, CompositionProvider } from \"@webiny/react-composition\";\nimport { Routes as SortRoutes } from \"./core/Routes\";\nimport { DebounceRender } from \"./core/DebounceRender\";\nimport { PluginsProvider } from \"./core/Plugins\";\n\ntype RoutesByPath = {\n [key: string]: ReactElement<RouteProps>;\n};\n\ninterface State {\n routes: RoutesByPath;\n plugins: JSX.Element[];\n providers: HigherOrderComponent[];\n}\n\ninterface AppContext extends State {\n addRoute(route: JSX.Element): void;\n addProvider(hoc: HigherOrderComponent): void;\n addPlugin(plugin: React.ReactNode): void;\n}\n\nconst AppContext = createContext<AppContext | undefined>(undefined);\n\nAppContext.displayName = \"AppContext\";\n\nexport const useApp = () => {\n const appContext = useContext(AppContext);\n if (!appContext) {\n throw Error(\n `AppContext provider was not found. Are you using the \"useApp()\" hook in the right place?`\n );\n }\n return appContext;\n};\n\nexport interface AppProps {\n debounceRender?: number;\n routes?: Array<RouteProps>;\n providers?: Array<HigherOrderComponent>;\n children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const App = ({ debounceRender = 50, routes = [], providers = [], children }: AppProps) => {\n const [state, setState] = useState<State>({\n routes: routes.reduce<RoutesByPath>((acc, item) => {\n return { ...acc, [item.path as string]: <Route {...item} /> };\n }, {}),\n plugins: [],\n providers\n });\n\n const addRoute = useCallback((route: FunctionComponentElement<RouteProps>) => {\n setState(state => {\n return {\n ...state,\n routes: { ...state.routes, [route.props.path as string]: route }\n };\n });\n }, []);\n\n const addProvider = useCallback(component => {\n setState(state => {\n if (state.providers.findIndex(m => m === component) > -1) {\n return state;\n }\n\n return {\n ...state,\n providers: [...state.providers, component]\n };\n });\n }, []);\n\n const addPlugin = useCallback(element => {\n setState(state => {\n return {\n ...state,\n plugins: [...state.plugins, element]\n };\n });\n }, []);\n\n const appContext = useMemo(\n () => ({\n ...state,\n addRoute,\n addProvider,\n addPlugin\n }),\n [state]\n );\n\n const AppRouter = useMemo(() => {\n return function AppRouter() {\n const routes = Object.values(state.routes);\n return <SortRoutes key={routes.length} routes={routes} />;\n };\n }, [state.routes]);\n\n const Providers = useMemo(() => {\n return compose(...(state.providers || []))(({ children }: any) => (\n <DebounceRender wait={debounceRender}>{children}</DebounceRender>\n ));\n }, [state.providers.length]);\n\n Providers.displayName = \"Providers\";\n\n return (\n <AppContext.Provider value={appContext}>\n <CompositionProvider>\n {children}\n <BrowserRouter>\n <Providers>\n <PluginsProvider>{state.plugins}</PluginsProvider>\n <DebounceRender wait={debounceRender}>\n <AppRouter />\n </DebounceRender>\n </Providers>\n </BrowserRouter>\n </CompositionProvider>\n </AppContext.Provider>\n );\n};\n\nApp.displayName = \"App\";\n"],"mappings":"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"}
@@ -9,6 +9,9 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _plugins = require("@webiny/plugins");
11
11
  var _reactRouter = require("@webiny/react-router");
12
+ // This file is necessary only for backwards compatibility.
13
+ // We'll remove this once the legacy rendering engine is removed.
14
+
12
15
  var Routes = function Routes() {
13
16
  // We cannot call `sort` on the array returned by the `plugins.byType` call - it is read-only.
14
17
  var routes = (0, _toConsumableArray2.default)(_plugins.plugins.byType("route")).sort(function (a, b) {
@@ -1 +1 @@
1
- {"version":3,"names":["Routes","routes","plugins","byType","sort","a","b","pathA","route","props","path","pathB","includes","map","name","React","cloneElement","key"],"sources":["Routes.tsx"],"sourcesContent":["import React from \"react\";\nimport { plugins } from \"@webiny/plugins\";\nimport { Routes as ReactRouterRoutes } from \"@webiny/react-router\";\nimport { RoutePlugin } from \"../types\";\n\nexport const Routes = () => {\n // We cannot call `sort` on the array returned by the `plugins.byType` call - it is read-only.\n const routes = [...plugins.byType<RoutePlugin>(\"route\")].sort((a, b) => {\n const pathA = a.route.props.path || \"*\";\n const pathB = b.route.props.path || \"*\";\n\n // This will sort paths at the very bottom of the list\n if (pathA === \"/\" && pathB === \"*\") {\n return -1;\n }\n\n // This will push * and / to the bottom of the list\n if (pathA === \"*\" || pathA === \"/\") {\n return 1;\n }\n\n // This will push * and / to the bottom of the list\n if ([\"*\", \"/\"].includes(pathB)) {\n return -1;\n }\n\n return 0;\n });\n\n return (\n <ReactRouterRoutes>\n {routes.map(({ route, name }) => React.cloneElement(route, { key: name }))}\n </ReactRouterRoutes>\n );\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AAGO,IAAMA,MAAM,GAAG,SAATA,MAAM,GAAS;EACxB;EACA,IAAMC,MAAM,GAAG,iCAAIC,gBAAO,CAACC,MAAM,CAAc,OAAO,CAAC,EAAEC,IAAI,CAAC,UAACC,CAAC,EAAEC,CAAC,EAAK;IACpE,IAAMC,KAAK,GAAGF,CAAC,CAACG,KAAK,CAACC,KAAK,CAACC,IAAI,IAAI,GAAG;IACvC,IAAMC,KAAK,GAAGL,CAAC,CAACE,KAAK,CAACC,KAAK,CAACC,IAAI,IAAI,GAAG;;IAEvC;IACA,IAAIH,KAAK,KAAK,GAAG,IAAII,KAAK,KAAK,GAAG,EAAE;MAChC,OAAO,CAAC,CAAC;IACb;;IAEA;IACA,IAAIJ,KAAK,KAAK,GAAG,IAAIA,KAAK,KAAK,GAAG,EAAE;MAChC,OAAO,CAAC;IACZ;;IAEA;IACA,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACK,QAAQ,CAACD,KAAK,CAAC,EAAE;MAC5B,OAAO,CAAC,CAAC;IACb;IAEA,OAAO,CAAC;EACZ,CAAC,CAAC;EAEF,oBACI,6BAAC,mBAAiB,QACbV,MAAM,CAACY,GAAG,CAAC;IAAA,IAAGL,KAAK,QAALA,KAAK;MAAEM,IAAI,QAAJA,IAAI;IAAA,oBAAOC,cAAK,CAACC,YAAY,CAACR,KAAK,EAAE;MAAES,GAAG,EAAEH;IAAK,CAAC,CAAC;EAAA,EAAC,CAC1D;AAE5B,CAAC;AAAC"}
1
+ {"version":3,"names":["Routes","routes","plugins","byType","sort","a","b","pathA","route","props","path","pathB","includes","map","name","React","cloneElement","key"],"sources":["Routes.tsx"],"sourcesContent":["// This file is necessary only for backwards compatibility.\n// We'll remove this once the legacy rendering engine is removed.\nimport React from \"react\";\nimport { plugins } from \"@webiny/plugins\";\nimport { Routes as ReactRouterRoutes } from \"@webiny/react-router\";\nimport { RoutePlugin } from \"../types\";\n\nexport const Routes = () => {\n // We cannot call `sort` on the array returned by the `plugins.byType` call - it is read-only.\n const routes = [...plugins.byType<RoutePlugin>(\"route\")].sort((a, b) => {\n const pathA = a.route.props.path || \"*\";\n const pathB = b.route.props.path || \"*\";\n\n // This will sort paths at the very bottom of the list\n if (pathA === \"/\" && pathB === \"*\") {\n return -1;\n }\n\n // This will push * and / to the bottom of the list\n if (pathA === \"*\" || pathA === \"/\") {\n return 1;\n }\n\n // This will push * and / to the bottom of the list\n if ([\"*\", \"/\"].includes(pathB)) {\n return -1;\n }\n\n return 0;\n });\n\n return (\n <ReactRouterRoutes>\n {routes.map(({ route, name }) => React.cloneElement(route, { key: name }))}\n </ReactRouterRoutes>\n );\n};\n"],"mappings":";;;;;;;;AAEA;AACA;AACA;AAJA;AACA;;AAMO,IAAMA,MAAM,GAAG,SAATA,MAAM,GAAS;EACxB;EACA,IAAMC,MAAM,GAAG,iCAAIC,gBAAO,CAACC,MAAM,CAAc,OAAO,CAAC,EAAEC,IAAI,CAAC,UAACC,CAAC,EAAEC,CAAC,EAAK;IACpE,IAAMC,KAAK,GAAGF,CAAC,CAACG,KAAK,CAACC,KAAK,CAACC,IAAI,IAAI,GAAG;IACvC,IAAMC,KAAK,GAAGL,CAAC,CAACE,KAAK,CAACC,KAAK,CAACC,IAAI,IAAI,GAAG;;IAEvC;IACA,IAAIH,KAAK,KAAK,GAAG,IAAII,KAAK,KAAK,GAAG,EAAE;MAChC,OAAO,CAAC,CAAC;IACb;;IAEA;IACA,IAAIJ,KAAK,KAAK,GAAG,IAAIA,KAAK,KAAK,GAAG,EAAE;MAChC,OAAO,CAAC;IACZ;;IAEA;IACA,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACK,QAAQ,CAACD,KAAK,CAAC,EAAE;MAC5B,OAAO,CAAC,CAAC;IACb;IAEA,OAAO,CAAC;EACZ,CAAC,CAAC;EAEF,oBACI,6BAAC,mBAAiB,QACbV,MAAM,CAACY,GAAG,CAAC;IAAA,IAAGL,KAAK,QAALA,KAAK;MAAEM,IAAI,QAAJA,IAAI;IAAA,oBAAOC,cAAK,CAACC,YAAY,CAACR,KAAK,EAAE;MAAES,GAAG,EAAEH;IAAK,CAAC,CAAC;EAAA,EAAC,CAC1D;AAE5B,CAAC;AAAC"}
@@ -21,8 +21,4 @@ export declare class UiProvider extends React.Component<Props, State> {
21
21
  private readonly setData;
22
22
  render(): JSX.Element;
23
23
  }
24
- export interface UiConsumerProps {
25
- children: React.ReactElement;
26
- }
27
- export declare const UiConsumer: React.FC<UiConsumerProps>;
28
24
  export {};
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.UiProvider = exports.UiContext = exports.UiConsumer = void 0;
7
+ exports.UiProvider = exports.UiContext = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -56,13 +56,4 @@ var UiProvider = /*#__PURE__*/function (_React$Component) {
56
56
  }]);
57
57
  return UiProvider;
58
58
  }(_react.default.Component);
59
- exports.UiProvider = UiProvider;
60
- var UiConsumer = function UiConsumer(_ref) {
61
- var children = _ref.children;
62
- return /*#__PURE__*/_react.default.createElement(UiContext.Consumer, null, function (ui) {
63
- return /*#__PURE__*/_react.default.cloneElement(children, {
64
- ui: ui
65
- });
66
- });
67
- };
68
- exports.UiConsumer = UiConsumer;
59
+ exports.UiProvider = UiProvider;
@@ -1 +1 @@
1
- {"version":3,"names":["UiContext","React","createContext","UiProvider","ui","setter","setState","state","value","setData","uiStatePlugins","plugins","byType","map","pl","cloneElement","render","key","name","props","children","Component","UiConsumer"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport { UiStatePlugin } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\nexport const UiContext = React.createContext({});\n\ntype Props = {};\n\ntype State = {\n ui: { [key: string]: any };\n};\n\ninterface UiData {\n [key: string]: any;\n}\n\ninterface UiDataSetter {\n (ui: UiData): UiData;\n}\n\nexport interface UiContextValue {\n setState: (setter: UiDataSetter) => void;\n [key: string]: any;\n}\n\nexport class UiProvider extends React.Component<Props, State> {\n public override state: State = {\n ui: {}\n };\n\n private readonly setData = (setter: Function): void => {\n return this.setState((state: State) => {\n return { ui: { ...state.ui, ...setter(state.ui) } };\n });\n };\n\n public override render() {\n const value: UiContextValue = { ...this.state.ui, setState: this.setData };\n const uiStatePlugins = plugins.byType<UiStatePlugin>(\"ui-state\");\n return (\n <UiContext.Provider value={value}>\n {uiStatePlugins.map(pl => React.cloneElement(pl.render(), { key: pl.name }))}\n {this.props.children}\n </UiContext.Provider>\n );\n }\n}\n\nexport interface UiConsumerProps {\n children: React.ReactElement;\n}\nexport const UiConsumer: React.FC<UiConsumerProps> = ({ children }) => {\n return <UiContext.Consumer>{ui => React.cloneElement(children, { ui })}</UiContext.Consumer>;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAEA;AAEO,IAAMA,SAAS,gBAAGC,cAAK,CAACC,aAAa,CAAC,CAAC,CAAC,CAAC;AAAC;AAAA,IAqBpCC,UAAU;EAAA;EAAA;EAAA;IAAA;IAAA;IAAA;MAAA;IAAA;IAAA;IAAA,oFACY;MAC3BC,EAAE,EAAE,CAAC;IACT,CAAC;IAAA,sFAE0B,UAACC,MAAgB,EAAW;MACnD,OAAO,MAAKC,QAAQ,CAAC,UAACC,KAAY,EAAK;QACnC,OAAO;UAAEH,EAAE,8DAAOG,KAAK,CAACH,EAAE,GAAKC,MAAM,CAACE,KAAK,CAACH,EAAE,CAAC;QAAG,CAAC;MACvD,CAAC,CAAC;IACN,CAAC;IAAA;EAAA;EAAA;IAAA;IAAA,OAED,kBAAyB;MACrB,IAAMI,KAAqB,+DAAQ,IAAI,CAACD,KAAK,CAACH,EAAE;QAAEE,QAAQ,EAAE,IAAI,CAACG;MAAO,EAAE;MAC1E,IAAMC,cAAc,GAAGC,gBAAO,CAACC,MAAM,CAAgB,UAAU,CAAC;MAChE,oBACI,6BAAC,SAAS,CAAC,QAAQ;QAAC,KAAK,EAAEJ;MAAM,GAC5BE,cAAc,CAACG,GAAG,CAAC,UAAAC,EAAE;QAAA,oBAAIb,cAAK,CAACc,YAAY,CAACD,EAAE,CAACE,MAAM,EAAE,EAAE;UAAEC,GAAG,EAAEH,EAAE,CAACI;QAAK,CAAC,CAAC;MAAA,EAAC,EAC3E,IAAI,CAACC,KAAK,CAACC,QAAQ,CACH;IAE7B;EAAC;EAAA;AAAA,EApB2BnB,cAAK,CAACoB,SAAS;AAAA;AA0BxC,IAAMC,UAAqC,GAAG,SAAxCA,UAAqC,OAAqB;EAAA,IAAfF,QAAQ,QAARA,QAAQ;EAC5D,oBAAO,6BAAC,SAAS,CAAC,QAAQ,QAAE,UAAAhB,EAAE;IAAA,oBAAIH,cAAK,CAACc,YAAY,CAACK,QAAQ,EAAE;MAAEhB,EAAE,EAAFA;IAAG,CAAC,CAAC;EAAA,EAAsB;AAChG,CAAC;AAAC"}
1
+ {"version":3,"names":["UiContext","React","createContext","UiProvider","ui","setter","setState","state","value","setData","uiStatePlugins","plugins","byType","map","pl","cloneElement","render","key","name","props","children","Component"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport { UiStatePlugin } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\nexport const UiContext = React.createContext({});\n\ntype Props = {};\n\ntype State = {\n ui: { [key: string]: any };\n};\n\ninterface UiData {\n [key: string]: any;\n}\n\ninterface UiDataSetter {\n (ui: UiData): UiData;\n}\n\nexport interface UiContextValue {\n setState: (setter: UiDataSetter) => void;\n [key: string]: any;\n}\n\nexport class UiProvider extends React.Component<Props, State> {\n public override state: State = {\n ui: {}\n };\n\n private readonly setData = (setter: Function): void => {\n return this.setState((state: State) => {\n return { ui: { ...state.ui, ...setter(state.ui) } };\n });\n };\n\n public override render() {\n const value: UiContextValue = { ...this.state.ui, setState: this.setData };\n const uiStatePlugins = plugins.byType<UiStatePlugin>(\"ui-state\");\n return (\n <UiContext.Provider value={value}>\n {uiStatePlugins.map(pl => React.cloneElement(pl.render(), { key: pl.name }))}\n {this.props.children}\n </UiContext.Provider>\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAEA;AAEO,IAAMA,SAAS,gBAAGC,cAAK,CAACC,aAAa,CAAC,CAAC,CAAC,CAAC;AAAC;AAAA,IAqBpCC,UAAU;EAAA;EAAA;EAAA;IAAA;IAAA;IAAA;MAAA;IAAA;IAAA;IAAA,oFACY;MAC3BC,EAAE,EAAE,CAAC;IACT,CAAC;IAAA,sFAE0B,UAACC,MAAgB,EAAW;MACnD,OAAO,MAAKC,QAAQ,CAAC,UAACC,KAAY,EAAK;QACnC,OAAO;UAAEH,EAAE,8DAAOG,KAAK,CAACH,EAAE,GAAKC,MAAM,CAACE,KAAK,CAACH,EAAE,CAAC;QAAG,CAAC;MACvD,CAAC,CAAC;IACN,CAAC;IAAA;EAAA;EAAA;IAAA;IAAA,OAED,kBAAyB;MACrB,IAAMI,KAAqB,+DAAQ,IAAI,CAACD,KAAK,CAACH,EAAE;QAAEE,QAAQ,EAAE,IAAI,CAACG;MAAO,EAAE;MAC1E,IAAMC,cAAc,GAAGC,gBAAO,CAACC,MAAM,CAAgB,UAAU,CAAC;MAChE,oBACI,6BAAC,SAAS,CAAC,QAAQ;QAAC,KAAK,EAAEJ;MAAM,GAC5BE,cAAc,CAACG,GAAG,CAAC,UAAAC,EAAE;QAAA,oBAAIb,cAAK,CAACc,YAAY,CAACD,EAAE,CAACE,MAAM,EAAE,EAAE;UAAEC,GAAG,EAAEH,EAAE,CAACI;QAAK,CAAC,CAAC;MAAA,EAAC,EAC3E,IAAI,CAACC,KAAK,CAACC,QAAQ,CACH;IAE7B;EAAC;EAAA;AAAA,EApB2BnB,cAAK,CAACoB,SAAS;AAAA"}
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { RouteProps } from "@webiny/react-router";
3
+ export declare const AddRoute: React.FC<RouteProps>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AddRoute = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _App = require("../App");
10
+ var _reactRouter = require("@webiny/react-router");
11
+ var AddRoute = function AddRoute(props) {
12
+ var _useApp = (0, _App.useApp)(),
13
+ addRoute = _useApp.addRoute;
14
+ (0, _react.useEffect)(function () {
15
+ addRoute( /*#__PURE__*/_react.default.createElement(_reactRouter.Route, props));
16
+ }, []);
17
+ return null;
18
+ };
19
+ exports.AddRoute = AddRoute;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AddRoute","props","useApp","addRoute","useEffect"],"sources":["AddRoute.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { useApp } from \"~/App\";\nimport { Route, RouteProps } from \"@webiny/react-router\";\n\nexport const AddRoute: React.FC<RouteProps> = props => {\n const { addRoute } = useApp();\n\n useEffect(() => {\n addRoute(<Route {...props} />);\n }, []);\n\n return null;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEO,IAAMA,QAA8B,GAAG,SAAjCA,QAA8B,CAAGC,KAAK,EAAI;EACnD,cAAqB,IAAAC,WAAM,GAAE;IAArBC,QAAQ,WAARA,QAAQ;EAEhB,IAAAC,gBAAS,EAAC,YAAM;IACZD,QAAQ,eAAC,6BAAC,kBAAK,EAAKF,KAAK,CAAI,CAAC;EAClC,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,IAAI;AACf,CAAC;AAAC"}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ interface Props {
3
+ wait?: number;
4
+ }
5
+ /**
6
+ * We need to debounce the rendering of children during app bootstrap, since many plugins
7
+ * can add more and more Providers which will recompose the entire hierarchy of React Context providers.
8
+ * During this stage, we don't want to render anything.
9
+ */
10
+ export declare const DebounceRender: React.FC<Props>;
11
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.DebounceRender = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _lodash = _interopRequireDefault(require("lodash.debounce"));
12
+ /**
13
+ * We need to debounce the rendering of children during app bootstrap, since many plugins
14
+ * can add more and more Providers which will recompose the entire hierarchy of React Context providers.
15
+ * During this stage, we don't want to render anything.
16
+ */
17
+ var DebounceRender = function DebounceRender(_ref) {
18
+ var _ref$wait = _ref.wait,
19
+ wait = _ref$wait === void 0 ? 50 : _ref$wait,
20
+ children = _ref.children;
21
+ var _useState = (0, _react.useState)(wait === 0),
22
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
23
+ render = _useState2[0],
24
+ setRender = _useState2[1];
25
+ var debouncedRender = (0, _react.useMemo)(function () {
26
+ return (0, _lodash.default)(function () {
27
+ setRender(true);
28
+ }, wait);
29
+ }, [setRender]);
30
+ (0, _react.useEffect)(function () {
31
+ if (render) {
32
+ return;
33
+ }
34
+ debouncedRender();
35
+ return function () {
36
+ debouncedRender.cancel();
37
+ };
38
+ }, []);
39
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, render ? children : null);
40
+ };
41
+ exports.DebounceRender = DebounceRender;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DebounceRender","wait","children","useState","render","setRender","debouncedRender","useMemo","debounce","useEffect","cancel"],"sources":["DebounceRender.tsx"],"sourcesContent":["import React from \"react\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport debounce from \"lodash.debounce\";\n\ninterface Props {\n wait?: number;\n}\n/**\n * We need to debounce the rendering of children during app bootstrap, since many plugins\n * can add more and more Providers which will recompose the entire hierarchy of React Context providers.\n * During this stage, we don't want to render anything.\n */\nexport const DebounceRender: React.FC<Props> = ({ wait = 50, children }) => {\n const [render, setRender] = useState(wait === 0);\n\n const debouncedRender = useMemo(() => {\n return debounce(() => {\n setRender(true);\n }, wait);\n }, [setRender]);\n\n useEffect(() => {\n if (render) {\n return;\n }\n\n debouncedRender();\n\n return () => {\n debouncedRender.cancel();\n };\n }, []);\n\n return <>{render ? children : null}</>;\n};\n"],"mappings":";;;;;;;;;AAAA;AAEA;AAKA;AACA;AACA;AACA;AACA;AACO,IAAMA,cAA+B,GAAG,SAAlCA,cAA+B,OAAgC;EAAA,qBAA1BC,IAAI;IAAJA,IAAI,0BAAG,EAAE;IAAEC,QAAQ,QAARA,QAAQ;EACjE,gBAA4B,IAAAC,eAAQ,EAACF,IAAI,KAAK,CAAC,CAAC;IAAA;IAAzCG,MAAM;IAAEC,SAAS;EAExB,IAAMC,eAAe,GAAG,IAAAC,cAAO,EAAC,YAAM;IAClC,OAAO,IAAAC,eAAQ,EAAC,YAAM;MAClBH,SAAS,CAAC,IAAI,CAAC;IACnB,CAAC,EAAEJ,IAAI,CAAC;EACZ,CAAC,EAAE,CAACI,SAAS,CAAC,CAAC;EAEf,IAAAI,gBAAS,EAAC,YAAM;IACZ,IAAIL,MAAM,EAAE;MACR;IACJ;IAEAE,eAAe,EAAE;IAEjB,OAAO,YAAM;MACTA,eAAe,CAACI,MAAM,EAAE;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,oBAAO,4DAAGN,MAAM,GAAGF,QAAQ,GAAG,IAAI,CAAI;AAC1C,CAAC;AAAC"}
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { HigherOrderComponent } from "@webiny/react-composition";
3
+ interface PluginProps {
4
+ providers?: HigherOrderComponent[];
5
+ children?: React.ReactNode;
6
+ }
7
+ export declare const Plugin: React.NamedExoticComponent<PluginProps>;
8
+ export {};
package/core/Plugin.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Plugin = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _Provider = require("./Provider");
10
+ var _Plugins = require("./Plugins");
11
+ var Plugin = /*#__PURE__*/_react.default.memo(function Plugin(_ref) {
12
+ var providers = _ref.providers,
13
+ children = _ref.children;
14
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (providers || []).map(function (provider, index) {
15
+ return /*#__PURE__*/_react.default.createElement(_Provider.Provider, {
16
+ key: index,
17
+ hoc: provider
18
+ });
19
+ }), children ? /*#__PURE__*/_react.default.createElement(_Plugins.Plugins, null, children) : null);
20
+ });
21
+ exports.Plugin = Plugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Plugin","React","memo","providers","children","map","provider","index"],"sources":["Plugin.tsx"],"sourcesContent":["import React from \"react\";\nimport { Provider } from \"./Provider\";\nimport { Plugins } from \"./Plugins\";\nimport { HigherOrderComponent } from \"@webiny/react-composition\";\n\ninterface PluginProps {\n providers?: HigherOrderComponent[];\n children?: React.ReactNode;\n}\n\nexport const Plugin = React.memo(function Plugin({ providers, children }: PluginProps) {\n return (\n <>\n {(providers || []).map((provider, index) => (\n <Provider key={index} hoc={provider} />\n ))}\n {children ? <Plugins>{children}</Plugins> : null}\n </>\n );\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAQO,IAAMA,MAAM,gBAAGC,cAAK,CAACC,IAAI,CAAC,SAASF,MAAM,OAAuC;EAAA,IAApCG,SAAS,QAATA,SAAS;IAAEC,QAAQ,QAARA,QAAQ;EAClE,oBACI,4DACK,CAACD,SAAS,IAAI,EAAE,EAAEE,GAAG,CAAC,UAACC,QAAQ,EAAEC,KAAK;IAAA,oBACnC,6BAAC,kBAAQ;MAAC,GAAG,EAAEA,KAAM;MAAC,GAAG,EAAED;IAAS,EAAG;EAAA,CAC1C,CAAC,EACDF,QAAQ,gBAAG,6BAAC,gBAAO,QAAEA,QAAQ,CAAW,GAAG,IAAI,CACjD;AAEX,CAAC,CAAC;AAAC"}
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ export declare const PluginsContext: React.Context<boolean>;
3
+ interface PluginsProviderComponentProps {
4
+ children: JSX.Element[];
5
+ }
6
+ export declare const PluginsProvider: React.NamedExoticComponent<PluginsProviderComponentProps>;
7
+ /**
8
+ * @param children
9
+ * @deprecated This component should not be used directly. Use the <Plugin> component to create plugins.
10
+ */
11
+ export declare const Plugins: React.FC;
12
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PluginsProvider = exports.PluginsContext = exports.Plugins = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _App = require("../App");
10
+ var PluginsContext = /*#__PURE__*/(0, _react.createContext)(false);
11
+ exports.PluginsContext = PluginsContext;
12
+ PluginsContext.displayName = "PluginsContext";
13
+ var PluginsProviderComponent = function PluginsProviderComponent(_ref) {
14
+ var children = _ref.children;
15
+ /**
16
+ * This context only serves as a safeguard. We need to warn users when they mount a plugin without using
17
+ * the <Plugins> component. In that case, the context will not be available, and we can log warnings.
18
+ */
19
+ return /*#__PURE__*/_react.default.createElement(PluginsContext.Provider, {
20
+ value: true
21
+ }, children);
22
+ };
23
+ var PluginsProvider = /*#__PURE__*/(0, _react.memo)(PluginsProviderComponent);
24
+
25
+ /**
26
+ * @param children
27
+ * @deprecated This component should not be used directly. Use the <Plugin> component to create plugins.
28
+ */
29
+ exports.PluginsProvider = PluginsProvider;
30
+ var Plugins = function Plugins(_ref2) {
31
+ var children = _ref2.children;
32
+ var _useApp = (0, _App.useApp)(),
33
+ addPlugin = _useApp.addPlugin;
34
+ var hasParentPlugin = (0, _react.useContext)(PluginsContext);
35
+ (0, _react.useEffect)(function () {
36
+ if (hasParentPlugin) {
37
+ return;
38
+ }
39
+ _react.Children.forEach(children, function (child) {
40
+ return addPlugin(child);
41
+ });
42
+ }, []);
43
+ return hasParentPlugin ? /*#__PURE__*/_react.default.createElement(_react.Fragment, null, children) : null;
44
+ };
45
+ exports.Plugins = Plugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PluginsContext","createContext","displayName","PluginsProviderComponent","children","PluginsProvider","memo","Plugins","useApp","addPlugin","hasParentPlugin","useContext","useEffect","Children","forEach","child"],"sources":["Plugins.tsx"],"sourcesContent":["import React, { Fragment, Children, createContext, useContext, useEffect, memo } from \"react\";\nimport { useApp } from \"~/App\";\n\nexport const PluginsContext = createContext<boolean>(false);\nPluginsContext.displayName = \"PluginsContext\";\n\ninterface PluginsProviderComponentProps {\n children: JSX.Element[];\n}\nconst PluginsProviderComponent: React.FC<PluginsProviderComponentProps> = ({ children }) => {\n /**\n * This context only serves as a safeguard. We need to warn users when they mount a plugin without using\n * the <Plugins> component. In that case, the context will not be available, and we can log warnings.\n */\n return <PluginsContext.Provider value={true}>{children}</PluginsContext.Provider>;\n};\n\nexport const PluginsProvider = memo(PluginsProviderComponent);\n\n/**\n * @param children\n * @deprecated This component should not be used directly. Use the <Plugin> component to create plugins.\n */\nexport const Plugins: React.FC = ({ children }) => {\n const { addPlugin } = useApp();\n const hasParentPlugin = useContext(PluginsContext);\n\n useEffect(() => {\n if (hasParentPlugin) {\n return;\n }\n\n Children.forEach(children, child => addPlugin(child));\n }, []);\n\n return hasParentPlugin ? <Fragment>{children}</Fragment> : null;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,IAAMA,cAAc,gBAAG,IAAAC,oBAAa,EAAU,KAAK,CAAC;AAAC;AAC5DD,cAAc,CAACE,WAAW,GAAG,gBAAgB;AAK7C,IAAMC,wBAAiE,GAAG,SAApEA,wBAAiE,OAAqB;EAAA,IAAfC,QAAQ,QAARA,QAAQ;EACjF;AACJ;AACA;AACA;EACI,oBAAO,6BAAC,cAAc,CAAC,QAAQ;IAAC,KAAK,EAAE;EAAK,GAAEA,QAAQ,CAA2B;AACrF,CAAC;AAEM,IAAMC,eAAe,gBAAG,IAAAC,WAAI,EAACH,wBAAwB,CAAC;;AAE7D;AACA;AACA;AACA;AAHA;AAIO,IAAMI,OAAiB,GAAG,SAApBA,OAAiB,QAAqB;EAAA,IAAfH,QAAQ,SAARA,QAAQ;EACxC,cAAsB,IAAAI,WAAM,GAAE;IAAtBC,SAAS,WAATA,SAAS;EACjB,IAAMC,eAAe,GAAG,IAAAC,iBAAU,EAACX,cAAc,CAAC;EAElD,IAAAY,gBAAS,EAAC,YAAM;IACZ,IAAIF,eAAe,EAAE;MACjB;IACJ;IAEAG,eAAQ,CAACC,OAAO,CAACV,QAAQ,EAAE,UAAAW,KAAK;MAAA,OAAIN,SAAS,CAACM,KAAK,CAAC;IAAA,EAAC;EACzD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOL,eAAe,gBAAG,6BAAC,eAAQ,QAAEN,QAAQ,CAAY,GAAG,IAAI;AACnE,CAAC;AAAC"}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { HigherOrderComponent } from "../index";
3
+ export interface ProviderProps {
4
+ hoc: HigherOrderComponent;
5
+ }
6
+ /**
7
+ * Register a new React context provider.
8
+ */
9
+ export declare const Provider: React.FC<ProviderProps>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Provider = void 0;
7
+ var _react = require("react");
8
+ var _ = require("./..");
9
+ /**
10
+ * Register a new React context provider.
11
+ */
12
+ var Provider = function Provider(_ref) {
13
+ var hoc = _ref.hoc;
14
+ var _useApp = (0, _.useApp)(),
15
+ addProvider = _useApp.addProvider;
16
+ (0, _react.useEffect)(function () {
17
+ return addProvider(hoc);
18
+ }, []);
19
+ return null;
20
+ };
21
+ exports.Provider = Provider;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Provider","hoc","useApp","addProvider","useEffect"],"sources":["Provider.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { HigherOrderComponent, useApp } from \"~/index\";\n\nexport interface ProviderProps {\n hoc: HigherOrderComponent;\n}\n\n/**\n * Register a new React context provider.\n */\nexport const Provider: React.FC<ProviderProps> = ({ hoc }) => {\n const { addProvider } = useApp();\n\n useEffect(() => {\n return addProvider(hoc);\n }, []);\n\n return null;\n};\n"],"mappings":";;;;;;AAAA;AACA;AAMA;AACA;AACA;AACO,IAAMA,QAAiC,GAAG,SAApCA,QAAiC,OAAgB;EAAA,IAAVC,GAAG,QAAHA,GAAG;EACnD,cAAwB,IAAAC,QAAM,GAAE;IAAxBC,WAAW,WAAXA,WAAW;EAEnB,IAAAC,gBAAS,EAAC,YAAM;IACZ,OAAOD,WAAW,CAACF,GAAG,CAAC;EAC3B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,IAAI;AACf,CAAC;AAAC"}
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ interface RoutesProps {
3
+ routes: JSX.Element[];
4
+ }
5
+ export declare const Routes: React.FC<RoutesProps>;
6
+ export {};
package/core/Routes.js ADDED
@@ -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.Routes = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _plugins = require("@webiny/plugins");
11
+ var _reactRouter = require("@webiny/react-router");
12
+ var Routes = function Routes(props) {
13
+ var routes = [].concat((0, _toConsumableArray2.default)(props.routes), (0, _toConsumableArray2.default)(_plugins.plugins.byType("route").map(function (_ref) {
14
+ var route = _ref.route;
15
+ return route;
16
+ }))).sort(function (a, b) {
17
+ var pathA = a.props.path || "*";
18
+ var pathB = b.props.path || "*";
19
+
20
+ // This will sort paths at the very bottom of the list
21
+ if (pathA === "/" && pathB === "*") {
22
+ return -1;
23
+ }
24
+
25
+ // This will push * and / to the bottom of the list
26
+ if (pathA === "*" || pathA === "/") {
27
+ return 1;
28
+ }
29
+
30
+ // This will push * and / to the bottom of the list
31
+ if (["*", "/"].includes(pathB)) {
32
+ return -1;
33
+ }
34
+ return 0;
35
+ });
36
+ return /*#__PURE__*/_react.default.createElement(_reactRouter.Routes, null, routes.map(function (route, index) {
37
+ return /*#__PURE__*/_react.default.cloneElement(route, {
38
+ key: "".concat(route.props.path, ":").concat(index)
39
+ });
40
+ }));
41
+ };
42
+ exports.Routes = Routes;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Routes","props","routes","plugins","byType","map","route","sort","a","b","pathA","path","pathB","includes","index","React","cloneElement","key"],"sources":["Routes.tsx"],"sourcesContent":["import React from \"react\";\nimport { plugins } from \"@webiny/plugins\";\nimport { Routes as ReactRouterRoutes } from \"@webiny/react-router\";\nimport { RoutePlugin } from \"~/types\";\n\ninterface RoutesProps {\n routes: JSX.Element[];\n}\n\nexport const Routes: React.FC<RoutesProps> = props => {\n const routes = [\n ...props.routes,\n // For backwards compatibility, we need to support the RoutePlugin routes as well.\n ...plugins.byType<RoutePlugin>(\"route\").map(({ route }) => route)\n ].sort((a, b) => {\n const pathA = a.props.path || \"*\";\n const pathB = b.props.path || \"*\";\n\n // This will sort paths at the very bottom of the list\n if (pathA === \"/\" && pathB === \"*\") {\n return -1;\n }\n\n // This will push * and / to the bottom of the list\n if (pathA === \"*\" || pathA === \"/\") {\n return 1;\n }\n\n // This will push * and / to the bottom of the list\n if ([\"*\", \"/\"].includes(pathB)) {\n return -1;\n }\n\n return 0;\n });\n\n return (\n <ReactRouterRoutes>\n {routes.map((route, index) =>\n React.cloneElement(route, { key: `${route.props.path}:${index}` })\n )}\n </ReactRouterRoutes>\n );\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AAOO,IAAMA,MAA6B,GAAG,SAAhCA,MAA6B,CAAGC,KAAK,EAAI;EAClD,IAAMC,MAAM,GAAG,2CACRD,KAAK,CAACC,MAAM,oCAEZC,gBAAO,CAACC,MAAM,CAAc,OAAO,CAAC,CAACC,GAAG,CAAC;IAAA,IAAGC,KAAK,QAALA,KAAK;IAAA,OAAOA,KAAK;EAAA,EAAC,GACnEC,IAAI,CAAC,UAACC,CAAC,EAAEC,CAAC,EAAK;IACb,IAAMC,KAAK,GAAGF,CAAC,CAACP,KAAK,CAACU,IAAI,IAAI,GAAG;IACjC,IAAMC,KAAK,GAAGH,CAAC,CAACR,KAAK,CAACU,IAAI,IAAI,GAAG;;IAEjC;IACA,IAAID,KAAK,KAAK,GAAG,IAAIE,KAAK,KAAK,GAAG,EAAE;MAChC,OAAO,CAAC,CAAC;IACb;;IAEA;IACA,IAAIF,KAAK,KAAK,GAAG,IAAIA,KAAK,KAAK,GAAG,EAAE;MAChC,OAAO,CAAC;IACZ;;IAEA;IACA,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACG,QAAQ,CAACD,KAAK,CAAC,EAAE;MAC5B,OAAO,CAAC,CAAC;IACb;IAEA,OAAO,CAAC;EACZ,CAAC,CAAC;EAEF,oBACI,6BAAC,mBAAiB,QACbV,MAAM,CAACG,GAAG,CAAC,UAACC,KAAK,EAAEQ,KAAK;IAAA,oBACrBC,cAAK,CAACC,YAAY,CAACV,KAAK,EAAE;MAAEW,GAAG,YAAKX,KAAK,CAACL,KAAK,CAACU,IAAI,cAAIG,KAAK;IAAG,CAAC,CAAC;EAAA,EACrE,CACe;AAE5B,CAAC;AAAC"}
@@ -0,0 +1,6 @@
1
+ import { HigherOrderComponent } from "@webiny/react-composition";
2
+ /**
3
+ * Creates a Higher Order Component which is meant to wrap the entire app content.
4
+ * This is mostly useful for adding React Context providers.
5
+ */
6
+ export declare function createProvider(hoc: HigherOrderComponent): HigherOrderComponent;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createProvider = createProvider;
7
+ /**
8
+ * Creates a Higher Order Component which is meant to wrap the entire app content.
9
+ * This is mostly useful for adding React Context providers.
10
+ */
11
+ function createProvider(hoc) {
12
+ return hoc;
13
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createProvider","hoc"],"sources":["createProvider.tsx"],"sourcesContent":["import { HigherOrderComponent } from \"@webiny/react-composition\";\n\n/**\n * Creates a Higher Order Component which is meant to wrap the entire app content.\n * This is mostly useful for adding React Context providers.\n */\nexport function createProvider(hoc: HigherOrderComponent): HigherOrderComponent {\n return hoc;\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACO,SAASA,cAAc,CAACC,GAAyB,EAAwB;EAC5E,OAAOA,GAAG;AACd"}
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { HigherOrderComponent } from "@webiny/react-composition";
3
+ /**
4
+ * Creates a component, which, when mounted, will register an app provider.
5
+ * This is particularly useful for wrapping the entire app with custom React Context providers.
6
+ * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
7
+ */
8
+ export declare function createProviderPlugin(hoc: HigherOrderComponent): React.FC;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createProviderPlugin = createProviderPlugin;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _Provider = require("./Provider");
10
+ /**
11
+ * Creates a component, which, when mounted, will register an app provider.
12
+ * This is particularly useful for wrapping the entire app with custom React Context providers.
13
+ * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
14
+ */
15
+ function createProviderPlugin(hoc) {
16
+ return function ProviderPlugin() {
17
+ return /*#__PURE__*/_react.default.createElement(_Provider.Provider, {
18
+ hoc: hoc
19
+ });
20
+ };
21
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createProviderPlugin","hoc","ProviderPlugin"],"sources":["createProviderPlugin.tsx"],"sourcesContent":["import React from \"react\";\nimport { HigherOrderComponent } from \"@webiny/react-composition\";\nimport { Provider } from \"./Provider\";\n\n/**\n * Creates a component, which, when mounted, will register an app provider.\n * This is particularly useful for wrapping the entire app with custom React Context providers.\n * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.\n */\nexport function createProviderPlugin(hoc: HigherOrderComponent): React.FC {\n return function ProviderPlugin() {\n return <Provider hoc={hoc} />;\n };\n}\n"],"mappings":";;;;;;;AAAA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoB,CAACC,GAAyB,EAAY;EACtE,OAAO,SAASC,cAAc,GAAG;IAC7B,oBAAO,6BAAC,kBAAQ;MAAC,GAAG,EAAED;IAAI,EAAG;EACjC,CAAC;AACL"}
package/index.d.ts CHANGED
@@ -2,3 +2,14 @@ export { AddQuerySelectionPlugin } from "./plugins/AddQuerySelectionPlugin";
2
2
  export { ApolloLinkPlugin } from "./plugins/ApolloLinkPlugin";
3
3
  export { RoutePlugin } from "./plugins/RoutePlugin";
4
4
  export { ApolloCacheObjectIdPlugin } from "./plugins/ApolloCacheObjectIdPlugin";
5
+ export * from "@webiny/react-composition";
6
+ export type { HigherOrderComponent, ComposeProps, ComposableFC } from "@webiny/react-composition";
7
+ export * from "./App";
8
+ export type { AppProps } from "./App";
9
+ export * from "./core/Plugins";
10
+ export * from "./core/Plugin";
11
+ export * from "./core/Provider";
12
+ export * from "./core/AddRoute";
13
+ export * from "./core/DebounceRender";
14
+ export * from "./core/createProvider";
15
+ export * from "./core/createProviderPlugin";