@webiny/app 5.34.0-beta.2 → 5.34.1-beta.0

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 ADDED
@@ -0,0 +1,24 @@
1
+ import React, { ReactElement } from "react";
2
+ import { RouteProps } from "@webiny/react-router";
3
+ import { HigherOrderComponent } from "@webiny/react-composition";
4
+ interface State {
5
+ routes: Record<string, ReactElement<RouteProps>>;
6
+ plugins: JSX.Element[];
7
+ providers: HigherOrderComponent[];
8
+ }
9
+ interface AppContext extends State {
10
+ addRoute(route: JSX.Element): void;
11
+ addProvider(hoc: HigherOrderComponent): void;
12
+ addPlugin(plugin: React.ReactNode): void;
13
+ }
14
+ declare const AppContext: React.Context<AppContext | undefined>;
15
+ export declare const useApp: () => AppContext;
16
+ export interface AppProps {
17
+ debounceRender?: number;
18
+ children?: React.ReactNode | React.ReactNode[];
19
+ }
20
+ export declare const App: {
21
+ ({ debounceRender, children }: AppProps): JSX.Element;
22
+ displayName: string;
23
+ };
24
+ export {};
package/App.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.useApp = exports.App = void 0;
11
+
12
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
+
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+
16
+ var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
+
18
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
19
+
20
+ var _react = _interopRequireWildcard(require("react"));
21
+
22
+ var _reactRouter = require("@webiny/react-router");
23
+
24
+ var _reactComposition = require("@webiny/react-composition");
25
+
26
+ var _Routes = require("./core/Routes");
27
+
28
+ var _DebounceRender = require("./core/DebounceRender");
29
+
30
+ var _Plugins = require("./core/Plugins");
31
+
32
+ var AppContext = /*#__PURE__*/(0, _react.createContext)(undefined);
33
+ AppContext.displayName = "AppContext";
34
+
35
+ var useApp = function useApp() {
36
+ var appContext = (0, _react.useContext)(AppContext);
37
+
38
+ if (!appContext) {
39
+ throw Error("AppContext provider was not found. Are you using the \"useApp()\" hook in the right place?");
40
+ }
41
+
42
+ return appContext;
43
+ };
44
+
45
+ exports.useApp = useApp;
46
+
47
+ var App = function App(_ref) {
48
+ var _ref$debounceRender = _ref.debounceRender,
49
+ debounceRender = _ref$debounceRender === void 0 ? 50 : _ref$debounceRender,
50
+ children = _ref.children;
51
+
52
+ var _useState = (0, _react.useState)({
53
+ routes: {},
54
+ plugins: [],
55
+ providers: []
56
+ }),
57
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
58
+ state = _useState2[0],
59
+ setState = _useState2[1];
60
+
61
+ var addRoute = (0, _react.useCallback)(function (route) {
62
+ setState(function (state) {
63
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, state), {}, {
64
+ routes: (0, _objectSpread3.default)((0, _objectSpread3.default)({}, state.routes), {}, (0, _defineProperty2.default)({}, route.props.path, route))
65
+ });
66
+ });
67
+ }, []);
68
+ var addProvider = (0, _react.useCallback)(function (component) {
69
+ setState(function (state) {
70
+ if (state.providers.findIndex(function (m) {
71
+ return m === component;
72
+ }) > -1) {
73
+ return state;
74
+ }
75
+
76
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, state), {}, {
77
+ providers: [].concat((0, _toConsumableArray2.default)(state.providers), [component])
78
+ });
79
+ });
80
+ }, []);
81
+ var addPlugin = (0, _react.useCallback)(function (element) {
82
+ setState(function (state) {
83
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, state), {}, {
84
+ plugins: [].concat((0, _toConsumableArray2.default)(state.plugins), [element])
85
+ });
86
+ });
87
+ }, []);
88
+ var appContext = (0, _react.useMemo)(function () {
89
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, state), {}, {
90
+ addRoute: addRoute,
91
+ addProvider: addProvider,
92
+ addPlugin: addPlugin
93
+ });
94
+ }, [state]);
95
+ var AppRouter = (0, _react.useMemo)(function () {
96
+ return function AppRouter() {
97
+ var routes = Object.values(state.routes);
98
+ return /*#__PURE__*/_react.default.createElement(_Routes.Routes, {
99
+ key: routes.length,
100
+ routes: routes
101
+ });
102
+ };
103
+ }, [state.routes]);
104
+ var Providers = (0, _react.useMemo)(function () {
105
+ return _reactComposition.compose.apply(void 0, (0, _toConsumableArray2.default)(state.providers || []))(_DebounceRender.DebounceRender);
106
+ }, [state.providers]);
107
+ Providers.displayName = "Providers";
108
+ return /*#__PURE__*/_react.default.createElement(AppContext.Provider, {
109
+ value: appContext
110
+ }, /*#__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, {
111
+ wait: debounceRender
112
+ }, /*#__PURE__*/_react.default.createElement(AppRouter, null))))));
113
+ };
114
+
115
+ exports.App = App;
116
+ 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","children","useState","routes","plugins","providers","state","setState","addRoute","useCallback","route","props","path","addProvider","component","findIndex","m","addPlugin","element","useMemo","AppRouter","Object","values","length","Providers","compose","DebounceRender"],"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 } 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\ninterface State {\n routes: Record<string, ReactElement<RouteProps>>;\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 children?: React.ReactNode | React.ReactNode[];\n}\n\nexport const App = ({ debounceRender = 50, children }: AppProps) => {\n const [state, setState] = useState<State>({\n routes: {},\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 () =>\n function AppRouter() {\n const routes = Object.values(state.routes);\n return <SortRoutes key={routes.length} routes={routes} />;\n },\n [state.routes]\n );\n\n const Providers = useMemo(\n () => compose(...(state.providers || []))(DebounceRender),\n [state.providers]\n );\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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"}
@@ -15,6 +15,8 @@ var _plugins = require("@webiny/plugins");
15
15
 
16
16
  var _reactRouter = require("@webiny/react-router");
17
17
 
18
+ // This file is necessary only for backwards compatibility.
19
+ // We'll remove this once the legacy rendering engine is removed.
18
20
  var Routes = function Routes() {
19
21
  // We cannot call `sort` on the array returned by the `plugins.byType` call - it is read-only.
20
22
  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,MAAS,GAAM;EACxB;EACA,IAAMC,MAAM,GAAG,iCAAIC,gBAAA,CAAQC,MAAR,CAA4B,OAA5B,CAAJ,EAA0CC,IAA1C,CAA+C,UAACC,CAAD,EAAIC,CAAJ,EAAU;IACpE,IAAMC,KAAK,GAAGF,CAAC,CAACG,KAAF,CAAQC,KAAR,CAAcC,IAAd,IAAsB,GAApC;IACA,IAAMC,KAAK,GAAGL,CAAC,CAACE,KAAF,CAAQC,KAAR,CAAcC,IAAd,IAAsB,GAApC,CAFoE,CAIpE;;IACA,IAAIH,KAAK,KAAK,GAAV,IAAiBI,KAAK,KAAK,GAA/B,EAAoC;MAChC,OAAO,CAAC,CAAR;IACH,CAPmE,CASpE;;;IACA,IAAIJ,KAAK,KAAK,GAAV,IAAiBA,KAAK,KAAK,GAA/B,EAAoC;MAChC,OAAO,CAAP;IACH,CAZmE,CAcpE;;;IACA,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWK,QAAX,CAAoBD,KAApB,CAAJ,EAAgC;MAC5B,OAAO,CAAC,CAAR;IACH;;IAED,OAAO,CAAP;EACH,CApBc,CAAf;EAsBA,oBACI,6BAAC,mBAAD,QACKV,MAAM,CAACY,GAAP,CAAW;IAAA,IAAGL,KAAH,QAAGA,KAAH;IAAA,IAAUM,IAAV,QAAUA,IAAV;IAAA,oBAAqBC,cAAA,CAAMC,YAAN,CAAmBR,KAAnB,EAA0B;MAAES,GAAG,EAAEH;IAAP,CAA1B,CAArB;EAAA,CAAX,CADL,CADJ;AAKH,CA7BM"}
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,MAAS,GAAM;EACxB;EACA,IAAMC,MAAM,GAAG,iCAAIC,gBAAA,CAAQC,MAAR,CAA4B,OAA5B,CAAJ,EAA0CC,IAA1C,CAA+C,UAACC,CAAD,EAAIC,CAAJ,EAAU;IACpE,IAAMC,KAAK,GAAGF,CAAC,CAACG,KAAF,CAAQC,KAAR,CAAcC,IAAd,IAAsB,GAApC;IACA,IAAMC,KAAK,GAAGL,CAAC,CAACE,KAAF,CAAQC,KAAR,CAAcC,IAAd,IAAsB,GAApC,CAFoE,CAIpE;;IACA,IAAIH,KAAK,KAAK,GAAV,IAAiBI,KAAK,KAAK,GAA/B,EAAoC;MAChC,OAAO,CAAC,CAAR;IACH,CAPmE,CASpE;;;IACA,IAAIJ,KAAK,KAAK,GAAV,IAAiBA,KAAK,KAAK,GAA/B,EAAoC;MAChC,OAAO,CAAP;IACH,CAZmE,CAcpE;;;IACA,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWK,QAAX,CAAoBD,KAApB,CAAJ,EAAgC;MAC5B,OAAO,CAAC,CAAR;IACH;;IAED,OAAO,CAAP;EACH,CApBc,CAAf;EAsBA,oBACI,6BAAC,mBAAD,QACKV,MAAM,CAACY,GAAP,CAAW;IAAA,IAAGL,KAAH,QAAGA,KAAH;IAAA,IAAUM,IAAV,QAAUA,IAAV;IAAA,oBAAqBC,cAAA,CAAMC,YAAN,CAAmBR,KAAnB,EAA0B;MAAES,GAAG,EAAEH;IAAP,CAA1B,CAArB;EAAA,CAAX,CADL,CADJ;AAKH,CA7BM"}
@@ -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 {};
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.UiProvider = exports.UiContext = exports.UiConsumer = void 0;
8
+ exports.UiProvider = exports.UiContext = void 0;
9
9
 
10
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
@@ -78,15 +78,4 @@ var UiProvider = /*#__PURE__*/function (_React$Component) {
78
78
  return UiProvider;
79
79
  }(_react.default.Component);
80
80
 
81
- exports.UiProvider = UiProvider;
82
-
83
- var UiConsumer = function UiConsumer(_ref) {
84
- var children = _ref.children;
85
- return /*#__PURE__*/_react.default.createElement(UiContext.Consumer, null, function (ui) {
86
- return /*#__PURE__*/_react.default.cloneElement(children, {
87
- ui: ui
88
- });
89
- });
90
- };
91
-
92
- exports.UiConsumer = UiConsumer;
81
+ 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,cAAA,CAAMC,aAAN,CAAoB,EAApB,CAAlB;;;;IAqBMC,U;;;;;;;;;;;;;;;wFACsB;MAC3BC,EAAE,EAAE;IADuB,C;0FAIJ,UAACC,MAAD,EAA4B;MACnD,OAAO,MAAKC,QAAL,CAAc,UAACC,KAAD,EAAkB;QACnC,OAAO;UAAEH,EAAE,8DAAOG,KAAK,CAACH,EAAb,GAAoBC,MAAM,CAACE,KAAK,CAACH,EAAP,CAA1B;QAAJ,CAAP;MACH,CAFM,CAAP;IAGH,C;;;;;;WAED,kBAAyB;MACrB,IAAMI,KAAqB,+DAAQ,KAAKD,KAAL,CAAWH,EAAnB;QAAuBE,QAAQ,EAAE,KAAKG;MAAtC,EAA3B;;MACA,IAAMC,cAAc,GAAGC,gBAAA,CAAQC,MAAR,CAA8B,UAA9B,CAAvB;;MACA,oBACI,6BAAC,SAAD,CAAW,QAAX;QAAoB,KAAK,EAAEJ;MAA3B,GACKE,cAAc,CAACG,GAAf,CAAmB,UAAAC,EAAE;QAAA,oBAAIb,cAAA,CAAMc,YAAN,CAAmBD,EAAE,CAACE,MAAH,EAAnB,EAAgC;UAAEC,GAAG,EAAEH,EAAE,CAACI;QAAV,CAAhC,CAAJ;MAAA,CAArB,CADL,EAEK,KAAKC,KAAL,CAAWC,QAFhB,CADJ;IAMH;;;EApB2BnB,cAAA,CAAMoB,S;;;;AA0B/B,IAAMC,UAAqC,GAAG,SAAxCA,UAAwC,OAAkB;EAAA,IAAfF,QAAe,QAAfA,QAAe;EACnE,oBAAO,6BAAC,SAAD,CAAW,QAAX,QAAqB,UAAAhB,EAAE;IAAA,oBAAIH,cAAA,CAAMc,YAAN,CAAmBK,QAAnB,EAA6B;MAAEhB,EAAE,EAAFA;IAAF,CAA7B,CAAJ;EAAA,CAAvB,CAAP;AACH,CAFM"}
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,cAAA,CAAMC,aAAN,CAAoB,EAApB,CAAlB;;;;IAqBMC,U;;;;;;;;;;;;;;;wFACsB;MAC3BC,EAAE,EAAE;IADuB,C;0FAIJ,UAACC,MAAD,EAA4B;MACnD,OAAO,MAAKC,QAAL,CAAc,UAACC,KAAD,EAAkB;QACnC,OAAO;UAAEH,EAAE,8DAAOG,KAAK,CAACH,EAAb,GAAoBC,MAAM,CAACE,KAAK,CAACH,EAAP,CAA1B;QAAJ,CAAP;MACH,CAFM,CAAP;IAGH,C;;;;;;WAED,kBAAyB;MACrB,IAAMI,KAAqB,+DAAQ,KAAKD,KAAL,CAAWH,EAAnB;QAAuBE,QAAQ,EAAE,KAAKG;MAAtC,EAA3B;;MACA,IAAMC,cAAc,GAAGC,gBAAA,CAAQC,MAAR,CAA8B,UAA9B,CAAvB;;MACA,oBACI,6BAAC,SAAD,CAAW,QAAX;QAAoB,KAAK,EAAEJ;MAA3B,GACKE,cAAc,CAACG,GAAf,CAAmB,UAAAC,EAAE;QAAA,oBAAIb,cAAA,CAAMc,YAAN,CAAmBD,EAAE,CAACE,MAAH,EAAnB,EAAgC;UAAEC,GAAG,EAAEH,EAAE,CAACI;QAAV,CAAhC,CAAJ;MAAA,CAArB,CADL,EAEK,KAAKC,KAAL,CAAWC,QAFhB,CADJ;IAMH;;;EApB2BnB,cAAA,CAAMoB,S"}
@@ -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,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.AddRoute = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _App = require("../App");
13
+
14
+ var _reactRouter = require("@webiny/react-router");
15
+
16
+ var AddRoute = function AddRoute(props) {
17
+ var _useApp = (0, _App.useApp)(),
18
+ addRoute = _useApp.addRoute;
19
+
20
+ (0, _react.useEffect)(function () {
21
+ addRoute( /*#__PURE__*/_react.default.createElement(_reactRouter.Route, props));
22
+ }, []);
23
+ return null;
24
+ };
25
+
26
+ 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,QAAiC,CAAAC,KAAK,EAAI;EACnD,cAAqB,IAAAC,WAAA,GAArB;EAAA,IAAQC,QAAR,WAAQA,QAAR;;EAEA,IAAAC,gBAAA,EAAU,YAAM;IACZD,QAAQ,eAAC,6BAAC,kBAAD,EAAWF,KAAX,CAAD,CAAR;EACH,CAFD,EAEG,EAFH;EAIA,OAAO,IAAP;AACH,CARM"}
@@ -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,51 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.DebounceRender = void 0;
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ var _lodash = _interopRequireDefault(require("lodash.debounce"));
17
+
18
+ /**
19
+ * We need to debounce the rendering of children during app bootstrap, since many plugins
20
+ * can add more and more Providers which will recompose the entire hierarchy of React Context providers.
21
+ * During this stage, we don't want to render anything.
22
+ */
23
+ var DebounceRender = function DebounceRender(_ref) {
24
+ var _ref$wait = _ref.wait,
25
+ wait = _ref$wait === void 0 ? 50 : _ref$wait,
26
+ children = _ref.children;
27
+
28
+ var _useState = (0, _react.useState)(wait === 0),
29
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
30
+ render = _useState2[0],
31
+ setRender = _useState2[1];
32
+
33
+ var debouncedRender = (0, _react.useMemo)(function () {
34
+ return (0, _lodash.default)(function () {
35
+ setRender(true);
36
+ }, wait);
37
+ }, [setRender]);
38
+ (0, _react.useEffect)(function () {
39
+ if (render) {
40
+ return;
41
+ }
42
+
43
+ debouncedRender();
44
+ return function () {
45
+ debouncedRender.cancel();
46
+ };
47
+ }, []);
48
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, render ? children : null);
49
+ };
50
+
51
+ 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,cAAkC,OAA6B;EAAA,qBAA1BC,IAA0B;EAAA,IAA1BA,IAA0B,0BAAnB,EAAmB;EAAA,IAAfC,QAAe,QAAfA,QAAe;;EACxE,gBAA4B,IAAAC,eAAA,EAASF,IAAI,KAAK,CAAlB,CAA5B;EAAA;EAAA,IAAOG,MAAP;EAAA,IAAeC,SAAf;;EAEA,IAAMC,eAAe,GAAG,IAAAC,cAAA,EAAQ,YAAM;IAClC,OAAO,IAAAC,eAAA,EAAS,YAAM;MAClBH,SAAS,CAAC,IAAD,CAAT;IACH,CAFM,EAEJJ,IAFI,CAAP;EAGH,CAJuB,EAIrB,CAACI,SAAD,CAJqB,CAAxB;EAMA,IAAAI,gBAAA,EAAU,YAAM;IACZ,IAAIL,MAAJ,EAAY;MACR;IACH;;IAEDE,eAAe;IAEf,OAAO,YAAM;MACTA,eAAe,CAACI,MAAhB;IACH,CAFD;EAGH,CAVD,EAUG,EAVH;EAYA,oBAAO,4DAAGN,MAAM,GAAGF,QAAH,GAAc,IAAvB,CAAP;AACH,CAtBM"}
@@ -0,0 +1,8 @@
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
+ export declare const Plugins: React.FC;
8
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.PluginsProvider = exports.PluginsContext = exports.Plugins = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _App = require("../App");
13
+
14
+ var PluginsContext = /*#__PURE__*/(0, _react.createContext)(false);
15
+ exports.PluginsContext = PluginsContext;
16
+ PluginsContext.displayName = "PluginsContext";
17
+
18
+ var PluginsProviderComponent = function PluginsProviderComponent(_ref) {
19
+ var children = _ref.children;
20
+
21
+ /**
22
+ * This context only serves as a safeguard. We need to warn users when they mount a plugin without using
23
+ * the <Plugins> component. In that case, the context will not be available, and we can log warnings.
24
+ */
25
+ return /*#__PURE__*/_react.default.createElement(PluginsContext.Provider, {
26
+ value: true
27
+ }, children);
28
+ };
29
+
30
+ var PluginsProvider = /*#__PURE__*/(0, _react.memo)(PluginsProviderComponent);
31
+ exports.PluginsProvider = PluginsProvider;
32
+
33
+ var Plugins = function Plugins(_ref2) {
34
+ var children = _ref2.children;
35
+
36
+ var _useApp = (0, _App.useApp)(),
37
+ addPlugin = _useApp.addPlugin;
38
+
39
+ var hasParentPlugin = (0, _react.useContext)(PluginsContext);
40
+ (0, _react.useEffect)(function () {
41
+ if (hasParentPlugin) {
42
+ return;
43
+ }
44
+
45
+ _react.Children.forEach(children, function (child) {
46
+ return addPlugin(child);
47
+ });
48
+ }, []);
49
+ return hasParentPlugin ? /*#__PURE__*/_react.default.createElement(_react.Fragment, null, children) : null;
50
+ };
51
+
52
+ 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\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,EAAuB,KAAvB,CAAvB;;AACPD,cAAc,CAACE,WAAf,GAA6B,gBAA7B;;AAKA,IAAMC,wBAAiE,GAAG,SAApEA,wBAAoE,OAAkB;EAAA,IAAfC,QAAe,QAAfA,QAAe;;EACxF;AACJ;AACA;AACA;EACI,oBAAO,6BAAC,cAAD,CAAgB,QAAhB;IAAyB,KAAK,EAAE;EAAhC,GAAuCA,QAAvC,CAAP;AACH,CAND;;AAQO,IAAMC,eAAe,gBAAG,IAAAC,WAAA,EAAKH,wBAAL,CAAxB;;;AAEA,IAAMI,OAAiB,GAAG,SAApBA,OAAoB,QAAkB;EAAA,IAAfH,QAAe,SAAfA,QAAe;;EAC/C,cAAsB,IAAAI,WAAA,GAAtB;EAAA,IAAQC,SAAR,WAAQA,SAAR;;EACA,IAAMC,eAAe,GAAG,IAAAC,iBAAA,EAAWX,cAAX,CAAxB;EAEA,IAAAY,gBAAA,EAAU,YAAM;IACZ,IAAIF,eAAJ,EAAqB;MACjB;IACH;;IAEDG,eAAA,CAASC,OAAT,CAAiBV,QAAjB,EAA2B,UAAAW,KAAK;MAAA,OAAIN,SAAS,CAACM,KAAD,CAAb;IAAA,CAAhC;EACH,CAND,EAMG,EANH;EAQA,OAAOL,eAAe,gBAAG,6BAAC,eAAD,QAAWN,QAAX,CAAH,GAAqC,IAA3D;AACH,CAbM"}
@@ -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,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Provider = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _ = require("./..");
11
+
12
+ /**
13
+ * Register a new React context provider.
14
+ */
15
+ var Provider = function Provider(_ref) {
16
+ var hoc = _ref.hoc;
17
+
18
+ var _useApp = (0, _.useApp)(),
19
+ addProvider = _useApp.addProvider;
20
+
21
+ (0, _react.useEffect)(function () {
22
+ return addProvider(hoc);
23
+ }, []);
24
+ return null;
25
+ };
26
+
27
+ 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,QAAoC,OAAa;EAAA,IAAVC,GAAU,QAAVA,GAAU;;EAC1D,cAAwB,IAAAC,QAAA,GAAxB;EAAA,IAAQC,WAAR,WAAQA,WAAR;;EAEA,IAAAC,gBAAA,EAAU,YAAM;IACZ,OAAOD,WAAW,CAACF,GAAD,CAAlB;EACH,CAFD,EAEG,EAFH;EAIA,OAAO,IAAP;AACH,CARM"}
@@ -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,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Routes = void 0;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ var _plugins = require("@webiny/plugins");
15
+
16
+ var _reactRouter = require("@webiny/react-router");
17
+
18
+ var Routes = function Routes(props) {
19
+ var routes = [].concat((0, _toConsumableArray2.default)(props.routes), (0, _toConsumableArray2.default)(_plugins.plugins.byType("route").map(function (_ref) {
20
+ var route = _ref.route;
21
+ return route;
22
+ }))).sort(function (a, b) {
23
+ var pathA = a.props.path || "*";
24
+ var pathB = b.props.path || "*"; // This will sort paths at the very bottom of the list
25
+
26
+ if (pathA === "/" && pathB === "*") {
27
+ return -1;
28
+ } // This will push * and / to the bottom of the list
29
+
30
+
31
+ if (pathA === "*" || pathA === "/") {
32
+ return 1;
33
+ } // This will push * and / to the bottom of the list
34
+
35
+
36
+ if (["*", "/"].includes(pathB)) {
37
+ return -1;
38
+ }
39
+
40
+ return 0;
41
+ });
42
+ return /*#__PURE__*/_react.default.createElement(_reactRouter.Routes, null, routes.map(function (route, index) {
43
+ return /*#__PURE__*/_react.default.cloneElement(route, {
44
+ key: "".concat(route.props.path, ":").concat(index)
45
+ });
46
+ }));
47
+ };
48
+
49
+ 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,MAAgC,CAAAC,KAAK,EAAI;EAClD,IAAMC,MAAM,GAAG,2CACRD,KAAK,CAACC,MADE,oCAGRC,gBAAA,CAAQC,MAAR,CAA4B,OAA5B,EAAqCC,GAArC,CAAyC;IAAA,IAAGC,KAAH,QAAGA,KAAH;IAAA,OAAeA,KAAf;EAAA,CAAzC,CAHQ,GAIbC,IAJa,CAIR,UAACC,CAAD,EAAIC,CAAJ,EAAU;IACb,IAAMC,KAAK,GAAGF,CAAC,CAACP,KAAF,CAAQU,IAAR,IAAgB,GAA9B;IACA,IAAMC,KAAK,GAAGH,CAAC,CAACR,KAAF,CAAQU,IAAR,IAAgB,GAA9B,CAFa,CAIb;;IACA,IAAID,KAAK,KAAK,GAAV,IAAiBE,KAAK,KAAK,GAA/B,EAAoC;MAChC,OAAO,CAAC,CAAR;IACH,CAPY,CASb;;;IACA,IAAIF,KAAK,KAAK,GAAV,IAAiBA,KAAK,KAAK,GAA/B,EAAoC;MAChC,OAAO,CAAP;IACH,CAZY,CAcb;;;IACA,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWG,QAAX,CAAoBD,KAApB,CAAJ,EAAgC;MAC5B,OAAO,CAAC,CAAR;IACH;;IAED,OAAO,CAAP;EACH,CAxBc,CAAf;EA0BA,oBACI,6BAAC,mBAAD,QACKV,MAAM,CAACG,GAAP,CAAW,UAACC,KAAD,EAAQQ,KAAR;IAAA,oBACRC,cAAA,CAAMC,YAAN,CAAmBV,KAAnB,EAA0B;MAAEW,GAAG,YAAKX,KAAK,CAACL,KAAN,CAAYU,IAAjB,cAAyBG,KAAzB;IAAL,CAA1B,CADQ;EAAA,CAAX,CADL,CADJ;AAOH,CAlCM"}
@@ -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,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createProviderPlugin = createProviderPlugin;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _Provider = require("./Provider");
13
+
14
+ /**
15
+ * Creates a component, which, when mounted, will register an app provider.
16
+ * This is particularly useful for wrapping the entire app with custom React Context providers.
17
+ * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
18
+ */
19
+ function createProviderPlugin(hoc) {
20
+ return function ProviderPlugin() {
21
+ return /*#__PURE__*/_react.default.createElement(_Provider.Provider, {
22
+ hoc: hoc
23
+ });
24
+ };
25
+ }
@@ -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,oBAAT,CAA8BC,GAA9B,EAAmE;EACtE,OAAO,SAASC,cAAT,GAA0B;IAC7B,oBAAO,6BAAC,kBAAD;MAAU,GAAG,EAAED;IAAf,EAAP;EACH,CAFD;AAGH"}
package/index.d.ts CHANGED
@@ -2,3 +2,12 @@ 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/Provider";
11
+ export * from "./core/AddRoute";
12
+ export * from "./core/DebounceRender";
13
+ export * from "./core/createProviderPlugin";
package/index.js CHANGED
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ AddQuerySelectionPlugin: true,
8
+ ApolloLinkPlugin: true,
9
+ RoutePlugin: true,
10
+ ApolloCacheObjectIdPlugin: true
11
+ };
6
12
  Object.defineProperty(exports, "AddQuerySelectionPlugin", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -34,4 +40,102 @@ var _ApolloLinkPlugin = require("./plugins/ApolloLinkPlugin");
34
40
 
35
41
  var _RoutePlugin = require("./plugins/RoutePlugin");
36
42
 
37
- var _ApolloCacheObjectIdPlugin = require("./plugins/ApolloCacheObjectIdPlugin");
43
+ var _ApolloCacheObjectIdPlugin = require("./plugins/ApolloCacheObjectIdPlugin");
44
+
45
+ var _reactComposition = require("@webiny/react-composition");
46
+
47
+ Object.keys(_reactComposition).forEach(function (key) {
48
+ if (key === "default" || key === "__esModule") return;
49
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
+ if (key in exports && exports[key] === _reactComposition[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function get() {
54
+ return _reactComposition[key];
55
+ }
56
+ });
57
+ });
58
+
59
+ var _App = require("./App");
60
+
61
+ Object.keys(_App).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
64
+ if (key in exports && exports[key] === _App[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function get() {
68
+ return _App[key];
69
+ }
70
+ });
71
+ });
72
+
73
+ var _Plugins = require("./core/Plugins");
74
+
75
+ Object.keys(_Plugins).forEach(function (key) {
76
+ if (key === "default" || key === "__esModule") return;
77
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
78
+ if (key in exports && exports[key] === _Plugins[key]) return;
79
+ Object.defineProperty(exports, key, {
80
+ enumerable: true,
81
+ get: function get() {
82
+ return _Plugins[key];
83
+ }
84
+ });
85
+ });
86
+
87
+ var _Provider = require("./core/Provider");
88
+
89
+ Object.keys(_Provider).forEach(function (key) {
90
+ if (key === "default" || key === "__esModule") return;
91
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
92
+ if (key in exports && exports[key] === _Provider[key]) return;
93
+ Object.defineProperty(exports, key, {
94
+ enumerable: true,
95
+ get: function get() {
96
+ return _Provider[key];
97
+ }
98
+ });
99
+ });
100
+
101
+ var _AddRoute = require("./core/AddRoute");
102
+
103
+ Object.keys(_AddRoute).forEach(function (key) {
104
+ if (key === "default" || key === "__esModule") return;
105
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
106
+ if (key in exports && exports[key] === _AddRoute[key]) return;
107
+ Object.defineProperty(exports, key, {
108
+ enumerable: true,
109
+ get: function get() {
110
+ return _AddRoute[key];
111
+ }
112
+ });
113
+ });
114
+
115
+ var _DebounceRender = require("./core/DebounceRender");
116
+
117
+ Object.keys(_DebounceRender).forEach(function (key) {
118
+ if (key === "default" || key === "__esModule") return;
119
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
120
+ if (key in exports && exports[key] === _DebounceRender[key]) return;
121
+ Object.defineProperty(exports, key, {
122
+ enumerable: true,
123
+ get: function get() {
124
+ return _DebounceRender[key];
125
+ }
126
+ });
127
+ });
128
+
129
+ var _createProviderPlugin = require("./core/createProviderPlugin");
130
+
131
+ Object.keys(_createProviderPlugin).forEach(function (key) {
132
+ if (key === "default" || key === "__esModule") return;
133
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
134
+ if (key in exports && exports[key] === _createProviderPlugin[key]) return;
135
+ Object.defineProperty(exports, key, {
136
+ enumerable: true,
137
+ get: function get() {
138
+ return _createProviderPlugin[key];
139
+ }
140
+ });
141
+ });
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { AddQuerySelectionPlugin } from \"./plugins/AddQuerySelectionPlugin\";\nexport { ApolloLinkPlugin } from \"./plugins/ApolloLinkPlugin\";\nexport { RoutePlugin } from \"./plugins/RoutePlugin\";\nexport { ApolloCacheObjectIdPlugin } from \"./plugins/ApolloCacheObjectIdPlugin\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { AddQuerySelectionPlugin } from \"./plugins/AddQuerySelectionPlugin\";\nexport { ApolloLinkPlugin } from \"./plugins/ApolloLinkPlugin\";\nexport { RoutePlugin } from \"./plugins/RoutePlugin\";\nexport { ApolloCacheObjectIdPlugin } from \"./plugins/ApolloCacheObjectIdPlugin\";\n\n// Composition - we re-export this for ease of use\nexport * from \"@webiny/react-composition\";\nexport type { HigherOrderComponent, ComposeProps, ComposableFC } from \"@webiny/react-composition\";\n\n// App framework\nexport * from \"./App\";\nexport type { AppProps } from \"./App\";\nexport * from \"./core/Plugins\";\nexport * from \"./core/Provider\";\nexport * from \"./core/AddRoute\";\nexport * from \"./core/DebounceRender\";\nexport * from \"./core/createProviderPlugin\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAIA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/app",
3
- "version": "5.34.0-beta.2",
3
+ "version": "5.34.1-beta.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,11 +19,12 @@
19
19
  "@emotion/styled": "10.3.0",
20
20
  "@types/react": "17.0.39",
21
21
  "@types/web": "0.0.61",
22
- "@webiny/i18n": "5.34.0-beta.2",
23
- "@webiny/i18n-react": "5.34.0-beta.2",
24
- "@webiny/plugins": "5.34.0-beta.2",
25
- "@webiny/react-router": "5.34.0-beta.2",
26
- "@webiny/ui": "5.34.0-beta.2",
22
+ "@webiny/i18n": "5.34.1-beta.0",
23
+ "@webiny/i18n-react": "5.34.1-beta.0",
24
+ "@webiny/plugins": "5.34.1-beta.0",
25
+ "@webiny/react-composition": "5.34.1-beta.0",
26
+ "@webiny/react-router": "5.34.1-beta.0",
27
+ "@webiny/ui": "5.34.1-beta.0",
27
28
  "apollo-cache": "1.3.5",
28
29
  "apollo-cache-inmemory": "1.6.6",
29
30
  "apollo-client": "2.6.10",
@@ -36,6 +37,7 @@
36
37
  "graphql": "15.8.0",
37
38
  "invariant": "2.2.4",
38
39
  "lodash": "4.17.21",
40
+ "lodash.debounce": "4.0.8",
39
41
  "nanoid": "3.3.4",
40
42
  "react": "17.0.2",
41
43
  "react-dom": "17.0.2",
@@ -48,9 +50,10 @@
48
50
  "@babel/preset-env": "^7.19.4",
49
51
  "@babel/preset-react": "^7.18.6",
50
52
  "@babel/preset-typescript": "^7.18.6",
53
+ "@types/lodash.debounce": "^4.0.7",
51
54
  "@types/warning": "^3.0.0",
52
- "@webiny/cli": "^5.34.0-beta.2",
53
- "@webiny/project-utils": "^5.34.0-beta.2",
55
+ "@webiny/cli": "^5.34.1-beta.0",
56
+ "@webiny/project-utils": "^5.34.1-beta.0",
54
57
  "babel-plugin-lodash": "^3.3.4",
55
58
  "rimraf": "^3.0.2",
56
59
  "typescript": "4.7.4"
@@ -71,5 +74,5 @@
71
74
  ]
72
75
  }
73
76
  },
74
- "gitHead": "16af8737377a9ae1dd6ac4ecffec5625726c814e"
77
+ "gitHead": "c893b6c771e45d4b2ea13da4f17455abdaef8239"
75
78
  }