@webiny/app 6.0.0-rc.0 → 6.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.d.ts +1 -2
- package/App.js +2 -8
- package/App.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/package.json +9 -9
- package/core/DebounceRender.d.ts +0 -12
- package/core/DebounceRender.js +0 -31
- package/core/DebounceRender.js.map +0 -1
package/App.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ interface AppContext extends State {
|
|
|
11
11
|
declare const AppContext: React.Context<AppContext | undefined>;
|
|
12
12
|
export declare const useApp: () => AppContext;
|
|
13
13
|
export interface AppProps {
|
|
14
|
-
debounceRender?: number;
|
|
15
14
|
routes?: Array<any>;
|
|
16
15
|
providers?: Array<Decorator<GenericComponent<ProviderProps>>>;
|
|
17
16
|
decorators?: DecoratorsCollection;
|
|
@@ -20,6 +19,6 @@ export interface AppProps {
|
|
|
20
19
|
interface ProviderProps {
|
|
21
20
|
children: React.ReactNode;
|
|
22
21
|
}
|
|
23
|
-
export declare const AppBase: React.MemoExoticComponent<({
|
|
22
|
+
export declare const AppBase: React.MemoExoticComponent<({ routes, providers, children }: AppProps) => React.JSX.Element>;
|
|
24
23
|
export declare const App: ({ decorators, ...props }: AppProps) => React.JSX.Element;
|
|
25
24
|
export {};
|
package/App.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { compose, CompositionProvider } from "@webiny/react-composition";
|
|
3
|
-
import { DebounceRender } from "./core/DebounceRender.js";
|
|
4
3
|
import { PluginsProvider } from "./core/Plugins.js";
|
|
5
4
|
import { RouterWithConfig, useRouterConfig } from "./config/RouterConfig.js";
|
|
6
5
|
import { AppContainer } from "./AppContainer.js";
|
|
@@ -16,7 +15,6 @@ export const useApp = () => {
|
|
|
16
15
|
return appContext;
|
|
17
16
|
};
|
|
18
17
|
export const AppBase = /*#__PURE__*/React.memo(({
|
|
19
|
-
debounceRender = 50,
|
|
20
18
|
routes = [],
|
|
21
19
|
providers = [],
|
|
22
20
|
children
|
|
@@ -65,17 +63,13 @@ export const AppBase = /*#__PURE__*/React.memo(({
|
|
|
65
63
|
return /*#__PURE__*/React.memo(compose(...(state.providers || []))(({
|
|
66
64
|
children
|
|
67
65
|
}) => {
|
|
68
|
-
return /*#__PURE__*/React.createElement(
|
|
69
|
-
wait: debounceRender
|
|
70
|
-
}, children);
|
|
66
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
71
67
|
}));
|
|
72
68
|
}, [state.providers.length]);
|
|
73
69
|
Providers.displayName = "Providers";
|
|
74
70
|
return /*#__PURE__*/React.createElement(AppContext.Provider, {
|
|
75
71
|
value: appContext
|
|
76
|
-
}, children, /*#__PURE__*/React.createElement(AppContainer, null, /*#__PURE__*/React.createElement(Providers, null, /*#__PURE__*/React.createElement(PluginsProvider, null, state.plugins), /*#__PURE__*/React.createElement(
|
|
77
|
-
wait: debounceRender
|
|
78
|
-
}, /*#__PURE__*/React.createElement(RouterWithConfig, null, /*#__PURE__*/React.createElement(AppRouter, null), /*#__PURE__*/React.createElement(RouteContent, null))))));
|
|
72
|
+
}, children, /*#__PURE__*/React.createElement(AppContainer, null, /*#__PURE__*/React.createElement(Providers, null, /*#__PURE__*/React.createElement(PluginsProvider, null, state.plugins), /*#__PURE__*/React.createElement(RouterWithConfig, null, /*#__PURE__*/React.createElement(AppRouter, null), /*#__PURE__*/React.createElement(RouteContent, null)))));
|
|
79
73
|
});
|
|
80
74
|
AppBase.displayName = "AppBase";
|
|
81
75
|
export const App = ({
|
package/App.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","compose","CompositionProvider","
|
|
1
|
+
{"version":3,"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","compose","CompositionProvider","PluginsProvider","RouterWithConfig","useRouterConfig","AppContainer","RouteContent","useRouter","AppContext","undefined","displayName","useApp","appContext","Error","AppBase","memo","routes","providers","children","state","setState","plugins","addProvider","component","findIndex","m","addPlugin","element","AppRouter","router","routerConfig","routesFromConfig","combinedRoutes","setRoutes","length","Providers","createElement","Fragment","Provider","value","App","decorators","props","Object","assign"],"sources":["App.tsx"],"sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from \"react\";\nimport {\n compose,\n CompositionProvider,\n Decorator,\n DecoratorsCollection,\n GenericComponent\n} from \"@webiny/react-composition\";\nimport { PluginsProvider } from \"./core/Plugins.js\";\nimport { RouterWithConfig, useRouterConfig } from \"./config/RouterConfig.js\";\nimport { AppContainer } from \"./AppContainer.js\";\nimport { RouteContent } from \"~/presentation/router/components/RouteContent.js\";\nimport { useRouter } from \"~/router.js\";\n\ninterface State {\n plugins: JSX.Element[];\n providers: Decorator<GenericComponent<ProviderProps>>[];\n}\n\ninterface AppContext extends State {\n addProvider(hoc: Decorator<GenericComponent<ProviderProps>>): void;\n\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 routes?: Array<any>;\n providers?: Array<Decorator<GenericComponent<ProviderProps>>>;\n decorators?: DecoratorsCollection;\n children?: React.ReactNode | React.ReactNode[];\n}\n\ninterface ProviderProps {\n children: React.ReactNode;\n}\n\ntype ComponentWithChildren = React.ComponentType<{ children?: React.ReactNode }>;\n\nexport const AppBase = React.memo(({ routes = [], providers = [], children }: AppProps) => {\n const [state, setState] = useState<State>({\n plugins: [],\n providers\n });\n\n const addProvider = useCallback((component: Decorator<any>) => {\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: JSX.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 addProvider,\n addPlugin\n }),\n [state]\n );\n\n const AppRouter = useMemo(() => {\n return function AppRouter() {\n const router = useRouter();\n const routerConfig = useRouterConfig();\n const routesFromConfig = routerConfig.routes;\n const combinedRoutes = [...routes, ...routesFromConfig];\n\n useEffect(() => {\n router.setRoutes(combinedRoutes);\n }, [combinedRoutes.length]);\n\n return null;\n };\n }, []);\n\n const Providers = useMemo(() => {\n return React.memo(\n compose(...(state.providers || []))(({ children }: ProviderProps) => {\n return <>{children}</>;\n })\n );\n }, [state.providers.length]) as ComponentWithChildren;\n\n Providers.displayName = \"Providers\";\n\n return (\n <AppContext.Provider value={appContext}>\n {children}\n <AppContainer>\n <Providers>\n <PluginsProvider>{state.plugins}</PluginsProvider>\n <RouterWithConfig>\n <AppRouter />\n <RouteContent />\n </RouterWithConfig>\n </Providers>\n </AppContainer>\n </AppContext.Provider>\n );\n});\n\nAppBase.displayName = \"AppBase\";\n\nexport const App = ({ decorators, ...props }: AppProps) => {\n return (\n <CompositionProvider decorators={decorators}>\n <AppBase decorators={decorators} {...props} />\n </CompositionProvider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACnG,SACIC,OAAO,EACPC,mBAAmB,QAIhB,2BAA2B;AAClC,SAASC,eAAe;AACxB,SAASC,gBAAgB,EAAEC,eAAe;AAC1C,SAASC,YAAY;AACrB,SAASC,YAAY;AACrB,SAASC,SAAS;AAalB,MAAMC,UAAU,gBAAGd,aAAa,CAAyBe,SAAS,CAAC;AAEnED,UAAU,CAACE,WAAW,GAAG,YAAY;AA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AA2C,aAAA,CAAC9B,YAAY,MAAE,CACD,CACX,CACD,CACG,CAAC;AAE9B,CAAC,CAAC;AAEFQ,OAAO,CAACJ,WAAW,GAAG,SAAS;AAE/B,OAAO,MAAM8B,GAAG,GAAGA,CAAC;EAAEC,UAAU;EAAE,GAAGC;AAAgB,CAAC,KAAK;EACvD,oBACIjD,KAAA,CAAA2C,aAAA,CAACnC,mBAAmB;IAACwC,UAAU,EAAEA;EAAW,gBACxChD,KAAA,CAAA2C,aAAA,CAACtB,OAAO,EAAA6B,MAAA,CAAAC,MAAA;IAACH,UAAU,EAAEA;EAAW,GAAKC,KAAK,CAAG,CAC5B,CAAC;AAE9B,CAAC","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export type { AppProps } from "./App.js";
|
|
|
9
9
|
export * from "./core/Plugins.js";
|
|
10
10
|
export * from "./core/Plugin.js";
|
|
11
11
|
export * from "./core/Provider.js";
|
|
12
|
-
export * from "./core/DebounceRender.js";
|
|
13
12
|
export * from "./core/createProvider.js";
|
|
14
13
|
export * from "./core/createProviderPlugin.js";
|
|
15
14
|
export * from "./renderApp.js";
|
package/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export * from "./AppContainer.js";
|
|
|
10
10
|
export * from "./core/Plugins.js";
|
|
11
11
|
export * from "./core/Plugin.js";
|
|
12
12
|
export * from "./core/Provider.js";
|
|
13
|
-
export * from "./core/DebounceRender.js";
|
|
14
13
|
export * from "./core/createProvider.js";
|
|
15
14
|
export * from "./core/createProviderPlugin.js";
|
|
16
15
|
export * from "./renderApp.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AddQuerySelectionPlugin","ApolloLinkPlugin","ApolloCacheObjectIdPlugin","useContainer","DiContainerProvider","useFeature","createFeature","Route","RouteLink","SimpleLink","useRouter","useRoute","useLocalStorage","useLocalStorageValue","useLocalStorageValues"],"sources":["index.ts"],"sourcesContent":["export { AddQuerySelectionPlugin } from \"./plugins/AddQuerySelectionPlugin.js\";\nexport { ApolloLinkPlugin } from \"./plugins/ApolloLinkPlugin.js\";\nexport {\n ApolloCacheObjectIdPlugin,\n type ApolloCacheObject\n} from \"./plugins/ApolloCacheObjectIdPlugin.js\";\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.js\";\nexport * from \"./AppContainer.js\";\nexport type { AppProps } from \"./App.js\";\nexport * from \"./core/Plugins.js\";\nexport * from \"./core/Plugin.js\";\nexport * from \"./core/Provider.js\";\nexport * from \"./core/
|
|
1
|
+
{"version":3,"names":["AddQuerySelectionPlugin","ApolloLinkPlugin","ApolloCacheObjectIdPlugin","useContainer","DiContainerProvider","useFeature","createFeature","Route","RouteLink","SimpleLink","useRouter","useRoute","useLocalStorage","useLocalStorageValue","useLocalStorageValues"],"sources":["index.ts"],"sourcesContent":["export { AddQuerySelectionPlugin } from \"./plugins/AddQuerySelectionPlugin.js\";\nexport { ApolloLinkPlugin } from \"./plugins/ApolloLinkPlugin.js\";\nexport {\n ApolloCacheObjectIdPlugin,\n type ApolloCacheObject\n} from \"./plugins/ApolloCacheObjectIdPlugin.js\";\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.js\";\nexport * from \"./AppContainer.js\";\nexport type { AppProps } from \"./App.js\";\nexport * from \"./core/Plugins.js\";\nexport * from \"./core/Plugin.js\";\nexport * from \"./core/Provider.js\";\nexport * from \"./core/createProvider.js\";\nexport * from \"./core/createProviderPlugin.js\";\nexport * from \"./renderApp.js\";\nexport * from \"./utils/createGenericContext.js\";\nexport { useContainer, DiContainerProvider } from \"./shared/di/DiContainerProvider.js\";\nexport { useFeature } from \"./shared/di/useFeature.js\";\nexport { createFeature } from \"./shared/di/createFeature.js\";\n\nexport { Route } from \"./features/router/Route.js\";\nexport { RouteLink, type RouteLinkProps } from \"./presentation/router/components/RouteLink.js\";\nexport { SimpleLink, type SimpleLinkProps } from \"./presentation/router/components/SimpleLink.js\";\n\nexport { useRouter, useRoute } from \"./presentation/router/index.js\";\nexport {\n useLocalStorage,\n useLocalStorageValue,\n useLocalStorageValues\n} from \"./presentation/localStorage/index.js\";\n\nexport * from \"./helpers/InterfaceGenerator/index.js\";\n"],"mappings":"AAAA,SAASA,uBAAuB;AAChC,SAASC,gBAAgB;AACzB,SACIC,yBAAyB;;AAI7B;AACA,cAAc,2BAA2B;AAGzC;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAY,EAAEC,mBAAmB;AAC1C,SAASC,UAAU;AACnB,SAASC,aAAa;AAEtB,SAASC,KAAK;AACd,SAASC,SAAS;AAClB,SAASC,UAAU;AAEnB,SAASC,SAAS,EAAEC,QAAQ;AAC5B,SACIC,eAAe,EACfC,oBAAoB,EACpBC,qBAAqB;AAGzB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app",
|
|
3
|
-
"version": "6.0.0-rc.
|
|
3
|
+
"version": "6.0.0-rc.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"@emotion/styled": "11.10.6",
|
|
20
20
|
"@types/react": "18.2.79",
|
|
21
21
|
"@webiny/di": "0.2.3",
|
|
22
|
-
"@webiny/feature": "6.0.0-rc.
|
|
23
|
-
"@webiny/i18n": "6.0.0-rc.
|
|
24
|
-
"@webiny/i18n-react": "6.0.0-rc.
|
|
25
|
-
"@webiny/plugins": "6.0.0-rc.
|
|
26
|
-
"@webiny/react-composition": "6.0.0-rc.
|
|
27
|
-
"@webiny/react-properties": "6.0.0-rc.
|
|
22
|
+
"@webiny/feature": "6.0.0-rc.1",
|
|
23
|
+
"@webiny/i18n": "6.0.0-rc.1",
|
|
24
|
+
"@webiny/i18n-react": "6.0.0-rc.1",
|
|
25
|
+
"@webiny/plugins": "6.0.0-rc.1",
|
|
26
|
+
"@webiny/react-composition": "6.0.0-rc.1",
|
|
27
|
+
"@webiny/react-properties": "6.0.0-rc.1",
|
|
28
28
|
"apollo-cache": "1.3.5",
|
|
29
29
|
"apollo-cache-inmemory": "1.6.6",
|
|
30
30
|
"apollo-client": "2.6.10",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/lodash": "4.17.23",
|
|
53
53
|
"@types/warning": "3.0.3",
|
|
54
|
-
"@webiny/build-tools": "6.0.0-rc.
|
|
54
|
+
"@webiny/build-tools": "6.0.0-rc.1",
|
|
55
55
|
"rimraf": "6.1.3",
|
|
56
56
|
"type-fest": "5.4.4",
|
|
57
57
|
"typescript": "5.9.3",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
]
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "36d702721ff9ed39fb21d6f5fe7922a2a8716e63"
|
|
72
72
|
}
|
package/core/DebounceRender.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
interface Props {
|
|
3
|
-
wait?: number;
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* We need to debounce the rendering of children during app bootstrap, since many plugins
|
|
8
|
-
* can add more and more Providers which will recompose the entire hierarchy of React Context providers.
|
|
9
|
-
* During this stage, we don't want to render anything.
|
|
10
|
-
*/
|
|
11
|
-
export declare const DebounceRender: ({ wait, children }: Props) => React.JSX.Element;
|
|
12
|
-
export {};
|
package/core/DebounceRender.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useEffect, useMemo, useState } from "react";
|
|
3
|
-
import debounce from "lodash/debounce.js";
|
|
4
|
-
/**
|
|
5
|
-
* We need to debounce the rendering of children during app bootstrap, since many plugins
|
|
6
|
-
* can add more and more Providers which will recompose the entire hierarchy of React Context providers.
|
|
7
|
-
* During this stage, we don't want to render anything.
|
|
8
|
-
*/
|
|
9
|
-
export const DebounceRender = ({
|
|
10
|
-
wait = 50,
|
|
11
|
-
children
|
|
12
|
-
}) => {
|
|
13
|
-
const [render, setRender] = useState(wait === 0);
|
|
14
|
-
const debouncedRender = useMemo(() => {
|
|
15
|
-
return debounce(() => {
|
|
16
|
-
setRender(true);
|
|
17
|
-
}, wait);
|
|
18
|
-
}, [setRender]);
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (render) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
debouncedRender();
|
|
24
|
-
return () => {
|
|
25
|
-
debouncedRender.cancel();
|
|
26
|
-
};
|
|
27
|
-
}, []);
|
|
28
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, render ? children : null);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=DebounceRender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEffect","useMemo","useState","debounce","DebounceRender","wait","children","render","setRender","debouncedRender","cancel","createElement","Fragment"],"sources":["DebounceRender.tsx"],"sourcesContent":["import React from \"react\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport debounce from \"lodash/debounce.js\";\n\ninterface Props {\n wait?: number;\n children?: React.ReactNode;\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 = ({ wait = 50, children }: Props) => {\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,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACpD,OAAOC,QAAQ,MAAM,oBAAoB;AAMzC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAGA,CAAC;EAAEC,IAAI,GAAG,EAAE;EAAEC;AAAgB,CAAC,KAAK;EAC9D,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGN,QAAQ,CAACG,IAAI,KAAK,CAAC,CAAC;EAEhD,MAAMI,eAAe,GAAGR,OAAO,CAAC,MAAM;IAClC,OAAOE,QAAQ,CAAC,MAAM;MAClBK,SAAS,CAAC,IAAI,CAAC;IACnB,CAAC,EAAEH,IAAI,CAAC;EACZ,CAAC,EAAE,CAACG,SAAS,CAAC,CAAC;EAEfR,SAAS,CAAC,MAAM;IACZ,IAAIO,MAAM,EAAE;MACR;IACJ;IAEAE,eAAe,CAAC,CAAC;IAEjB,OAAO,MAAM;MACTA,eAAe,CAACC,MAAM,CAAC,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,oBAAOX,KAAA,CAAAY,aAAA,CAAAZ,KAAA,CAAAa,QAAA,QAAGL,MAAM,GAAGD,QAAQ,GAAG,IAAO,CAAC;AAC1C,CAAC","ignoreList":[]}
|