@shuvi/platform-web 0.0.1-rc.34 → 1.0.0-rc.2

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 (238) hide show
  1. package/esm/shared/appTypes.d.ts +15 -0
  2. package/esm/shared/appTypes.js +1 -0
  3. package/esm/shared/configTypes.d.ts +14 -0
  4. package/esm/shared/configTypes.js +1 -0
  5. package/esm/shared/index.d.ts +5 -0
  6. package/esm/shared/index.js +5 -0
  7. package/esm/shared/renderTypes.d.ts +44 -0
  8. package/esm/shared/renderTypes.js +1 -0
  9. package/esm/shared/routeTypes.d.ts +47 -0
  10. package/esm/shared/routeTypes.js +1 -0
  11. package/esm/shared/serverTypes.d.ts +6 -0
  12. package/esm/shared/serverTypes.js +1 -0
  13. package/esm/shuvi-app/app/client.d.ts +2 -0
  14. package/esm/shuvi-app/app/client.js +125 -0
  15. package/esm/shuvi-app/app/server.d.ts +2 -0
  16. package/esm/shuvi-app/app/server.js +67 -0
  17. package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.d.ts +0 -0
  18. package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.js +2 -1
  19. package/esm/shuvi-app/entry/client/app.d.ts +2 -0
  20. package/esm/shuvi-app/entry/client/app.js +57 -0
  21. package/esm/shuvi-app/entry/client/index.d.ts +2 -0
  22. package/esm/shuvi-app/entry/client/index.js +12 -0
  23. package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.d.ts +0 -0
  24. package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.js +2 -2
  25. package/{shuvi-app → esm/shuvi-app}/entry/client/run.prod.d.ts +0 -0
  26. package/esm/shuvi-app/entry/client/run.prod.js +3 -0
  27. package/{shuvi-app → esm/shuvi-app}/entry/client/setup-env.d.ts +1 -1
  28. package/esm/shuvi-app/entry/client/setup-env.js +17 -0
  29. package/esm/shuvi-app/entry/server/index.d.ts +6 -0
  30. package/esm/shuvi-app/entry/server/index.js +7 -0
  31. package/esm/shuvi-app/react/AppComponent.d.ts +4 -0
  32. package/esm/shuvi-app/react/AppComponent.jsx +6 -0
  33. package/esm/shuvi-app/react/AppContainer.d.ts +6 -0
  34. package/esm/shuvi-app/react/AppContainer.jsx +23 -0
  35. package/esm/shuvi-app/react/Error.d.ts +5 -0
  36. package/esm/shuvi-app/react/Error.jsx +38 -0
  37. package/esm/shuvi-app/react/ErrorBoundary.d.ts +16 -0
  38. package/esm/shuvi-app/react/ErrorBoundary.jsx +25 -0
  39. package/esm/shuvi-app/react/ErrorPage.d.ts +5 -0
  40. package/esm/shuvi-app/react/ErrorPage.jsx +7 -0
  41. package/esm/shuvi-app/react/Link.d.ts +7 -0
  42. package/esm/shuvi-app/react/Link.jsx +115 -0
  43. package/esm/shuvi-app/react/applicationContext.d.ts +7 -0
  44. package/esm/shuvi-app/react/applicationContext.jsx +10 -0
  45. package/esm/shuvi-app/react/dynamic.d.ts +31 -0
  46. package/esm/shuvi-app/react/dynamic.jsx +62 -0
  47. package/esm/shuvi-app/react/getRoutes.d.ts +2 -0
  48. package/esm/shuvi-app/react/getRoutes.js +31 -0
  49. package/esm/shuvi-app/react/head/head-manager-context.d.ts +2 -0
  50. package/esm/shuvi-app/react/head/head-manager-context.js +2 -0
  51. package/esm/shuvi-app/react/head/head-manager.d.ts +10 -0
  52. package/esm/shuvi-app/react/head/head-manager.js +93 -0
  53. package/esm/shuvi-app/react/head/head.d.ts +33 -0
  54. package/esm/shuvi-app/react/head/head.jsx +178 -0
  55. package/esm/shuvi-app/react/head/index.d.ts +4 -0
  56. package/esm/shuvi-app/react/head/index.js +4 -0
  57. package/esm/shuvi-app/react/head/side-effect.d.ts +30 -0
  58. package/esm/shuvi-app/react/head/side-effect.jsx +44 -0
  59. package/esm/shuvi-app/react/head/types.d.ts +15 -0
  60. package/esm/shuvi-app/react/head/types.js +1 -0
  61. package/esm/shuvi-app/react/index.d.ts +4 -0
  62. package/esm/shuvi-app/react/index.js +4 -0
  63. package/esm/shuvi-app/react/loadRouteComponent.d.ts +4 -0
  64. package/esm/shuvi-app/react/loadRouteComponent.jsx +9 -0
  65. package/esm/shuvi-app/react/loadable/index.d.ts +2 -0
  66. package/esm/shuvi-app/react/loadable/index.js +2 -0
  67. package/esm/shuvi-app/react/loadable/loadable-context.d.ts +4 -0
  68. package/esm/shuvi-app/react/loadable/loadable-context.js +3 -0
  69. package/esm/shuvi-app/react/loadable/loadable.d.ts +30 -0
  70. package/esm/shuvi-app/react/loadable/loadable.js +277 -0
  71. package/esm/shuvi-app/react/redox-react/RedoxWrapper.d.ts +8 -0
  72. package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +11 -0
  73. package/esm/shuvi-app/react/redox-react/runtime.d.ts +2 -0
  74. package/esm/shuvi-app/react/redox-react/runtime.js +16 -0
  75. package/esm/shuvi-app/react/shuvi-runtime-api.d.ts +5 -0
  76. package/esm/shuvi-app/react/shuvi-runtime-api.js +5 -0
  77. package/esm/shuvi-app/react/types.d.ts +14 -0
  78. package/esm/shuvi-app/react/types.js +1 -0
  79. package/esm/shuvi-app/react/useLoaderData.d.ts +2 -0
  80. package/esm/shuvi-app/react/useLoaderData.js +27 -0
  81. package/esm/shuvi-app/react/utils/getDisplayName.d.ts +2 -0
  82. package/esm/shuvi-app/react/utils/getDisplayName.js +3 -0
  83. package/esm/shuvi-app/react/utils/requestIdleCallback.d.ts +2 -0
  84. package/esm/shuvi-app/react/utils/requestIdleCallback.js +20 -0
  85. package/esm/shuvi-app/react/utils/useIntersection.d.ts +8 -0
  86. package/esm/shuvi-app/react/utils/useIntersection.jsx +91 -0
  87. package/esm/shuvi-app/react/view/ReactView.client.d.ts +5 -0
  88. package/esm/shuvi-app/react/view/ReactView.client.jsx +64 -0
  89. package/esm/shuvi-app/react/view/ReactView.server.d.ts +4 -0
  90. package/esm/shuvi-app/react/view/ReactView.server.jsx +109 -0
  91. package/esm/shuvi-app/react/view/clientView.d.ts +3 -0
  92. package/esm/shuvi-app/react/view/clientView.js +2 -0
  93. package/esm/shuvi-app/react/view/index.d.ts +2 -0
  94. package/esm/shuvi-app/react/view/index.js +7 -0
  95. package/esm/shuvi-app/react/view/render-action.d.ts +10 -0
  96. package/esm/shuvi-app/react/view/render-action.js +29 -0
  97. package/esm/shuvi-app/react/view/serverView.d.ts +3 -0
  98. package/esm/shuvi-app/react/view/serverView.js +2 -0
  99. package/esm/shuvi-app/react/view/transformRoutes.d.ts +2 -0
  100. package/esm/shuvi-app/react/view/transformRoutes.js +3 -0
  101. package/esm/shuvi-app/shuvi-runtime-index.d.ts +4 -0
  102. package/esm/shuvi-app/shuvi-runtime-index.js +2 -0
  103. package/esm/shuvi-app/shuvi-runtime-server.d.ts +6 -0
  104. package/esm/shuvi-app/shuvi-runtime-server.js +1 -0
  105. package/lib/node/features/custom-server/index.d.ts +4 -0
  106. package/lib/node/features/custom-server/index.js +9 -0
  107. package/lib/node/features/custom-server/server.d.ts +2 -0
  108. package/lib/node/features/custom-server/server.js +28 -0
  109. package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +51 -0
  110. package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +237 -0
  111. package/lib/node/features/filesystem-routes/api/apiRoutes.d.ts +7 -0
  112. package/lib/node/features/filesystem-routes/api/apiRoutes.js +35 -0
  113. package/lib/node/features/filesystem-routes/api/index.d.ts +3 -0
  114. package/lib/node/features/filesystem-routes/api/index.js +7 -0
  115. package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -0
  116. package/lib/node/features/filesystem-routes/api/middleware.js +44 -0
  117. package/lib/node/features/filesystem-routes/hooks.d.ts +3 -0
  118. package/lib/node/features/filesystem-routes/hooks.js +6 -0
  119. package/lib/node/features/filesystem-routes/index.d.ts +20 -0
  120. package/lib/node/features/filesystem-routes/index.js +180 -0
  121. package/lib/node/features/filesystem-routes/middleware/index.d.ts +2 -0
  122. package/lib/node/features/filesystem-routes/middleware/index.js +7 -0
  123. package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -0
  124. package/lib/node/features/filesystem-routes/middleware/middleware.js +42 -0
  125. package/lib/node/features/filesystem-routes/middleware/routes.d.ts +9 -0
  126. package/lib/node/features/filesystem-routes/middleware/routes.js +34 -0
  127. package/lib/node/features/filesystem-routes/page/index.d.ts +2 -0
  128. package/lib/node/features/filesystem-routes/page/index.js +21 -0
  129. package/lib/node/features/filesystem-routes/page/routes.d.ts +8 -0
  130. package/lib/node/features/filesystem-routes/page/routes.js +83 -0
  131. package/lib/node/features/filesystem-routes/page/store.d.ts +3 -0
  132. package/lib/node/features/filesystem-routes/page/store.js +10 -0
  133. package/lib/node/features/html-render/index.d.ts +19 -0
  134. package/lib/node/features/html-render/index.js +28 -0
  135. package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -0
  136. package/lib/node/features/html-render/lib/generateFilesByRoutId.js +13 -0
  137. package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -0
  138. package/lib/node/features/html-render/lib/getPageMiddleware.js +56 -0
  139. package/lib/node/features/html-render/lib/index.d.ts +4 -0
  140. package/lib/node/features/html-render/lib/index.js +23 -0
  141. package/lib/node/features/html-render/lib/pageLoader.d.ts +1 -0
  142. package/lib/node/features/html-render/lib/pageLoader.js +42 -0
  143. package/lib/node/features/html-render/lib/renderToHTML.d.ts +6 -0
  144. package/lib/node/features/html-render/lib/renderToHTML.js +81 -0
  145. package/lib/node/features/html-render/lib/renderer/base.d.ts +17 -0
  146. package/lib/node/features/html-render/lib/renderer/base.js +70 -0
  147. package/lib/node/features/html-render/lib/renderer/htmlTag.d.ts +4 -0
  148. package/lib/node/features/html-render/lib/renderer/htmlTag.js +70 -0
  149. package/lib/node/features/html-render/lib/renderer/index.d.ts +15 -0
  150. package/lib/node/features/html-render/lib/renderer/index.js +48 -0
  151. package/lib/node/features/html-render/lib/renderer/spa.d.ts +5 -0
  152. package/lib/node/features/html-render/lib/renderer/spa.js +26 -0
  153. package/lib/node/features/html-render/lib/renderer/ssr.d.ts +5 -0
  154. package/lib/node/features/html-render/lib/renderer/ssr.js +70 -0
  155. package/lib/node/features/html-render/lib/renderer/types.d.ts +20 -0
  156. package/lib/node/features/html-render/lib/renderer/types.js +2 -0
  157. package/lib/node/features/html-render/lib/viewTemplate.d.ts +5 -0
  158. package/lib/node/features/html-render/lib/viewTemplate.js +37 -0
  159. package/lib/node/features/html-render/server.d.ts +2 -0
  160. package/lib/node/features/html-render/server.js +9 -0
  161. package/lib/node/features/html-render/serverHooks.d.ts +10 -0
  162. package/lib/node/features/html-render/serverHooks.js +13 -0
  163. package/lib/node/features/html-render/shuvi-app.d.ts +6 -0
  164. package/lib/node/features/html-render/shuvi-app.js +2 -0
  165. package/lib/node/features/index.d.ts +32 -0
  166. package/lib/node/features/index.js +25 -0
  167. package/lib/node/features/main/buildHtml.d.ts +8 -0
  168. package/lib/node/features/main/buildHtml.js +64 -0
  169. package/lib/node/features/main/generateResource.d.ts +3 -0
  170. package/lib/node/features/main/generateResource.js +56 -0
  171. package/lib/node/features/main/index.d.ts +3 -0
  172. package/lib/node/features/main/index.js +82 -0
  173. package/lib/node/features/middlewares.d.ts +4 -0
  174. package/lib/node/features/middlewares.js +23 -0
  175. package/lib/node/features/model/index.d.ts +21 -0
  176. package/lib/node/features/model/index.js +54 -0
  177. package/lib/node/features/model/runtime.d.ts +13 -0
  178. package/lib/node/features/model/runtime.js +47 -0
  179. package/lib/node/features/model/server.d.ts +3 -0
  180. package/lib/node/features/model/server.js +12 -0
  181. package/lib/node/features/model/shuvi-app.d.ts +6 -0
  182. package/lib/node/features/model/shuvi-app.js +2 -0
  183. package/lib/node/features/on-demand-compile-page/emptyComponent.d.ts +1 -0
  184. package/lib/node/features/on-demand-compile-page/emptyComponent.js +7 -0
  185. package/lib/node/features/on-demand-compile-page/index.d.ts +15 -0
  186. package/lib/node/features/on-demand-compile-page/index.js +36 -0
  187. package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +11 -0
  188. package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +104 -0
  189. package/lib/node/index.d.ts +6 -0
  190. package/lib/node/index.js +38 -0
  191. package/lib/{paths.d.ts → node/paths.d.ts} +1 -2
  192. package/lib/node/paths.js +36 -0
  193. package/lib/node/shuvi-type-extensions-node.d.ts +42 -0
  194. package/lib/node/shuvi-type-extensions-node.js +3 -0
  195. package/lib/node/targets/react/bundler/index.d.ts +16 -0
  196. package/lib/node/targets/react/bundler/index.js +102 -0
  197. package/lib/node/targets/react/index.d.ts +32 -0
  198. package/lib/node/targets/react/index.js +28 -0
  199. package/lib/node/targets/react/redox-react/index.d.ts +18 -0
  200. package/lib/node/targets/react/redox-react/index.js +50 -0
  201. package/lib/shared/appTypes.d.ts +15 -0
  202. package/lib/shared/appTypes.js +2 -0
  203. package/lib/shared/configTypes.d.ts +14 -0
  204. package/lib/shared/configTypes.js +2 -0
  205. package/lib/shared/index.d.ts +5 -0
  206. package/lib/shared/index.js +21 -0
  207. package/lib/shared/renderTypes.d.ts +44 -0
  208. package/lib/shared/renderTypes.js +2 -0
  209. package/lib/shared/routeTypes.d.ts +47 -0
  210. package/lib/shared/routeTypes.js +2 -0
  211. package/lib/shared/serverTypes.d.ts +6 -0
  212. package/lib/shared/serverTypes.js +2 -0
  213. package/package.json +78 -15
  214. package/shuvi-type-extensions-node.d.ts +2 -0
  215. package/shuvi-type-extensions-runtime.d.ts +36 -0
  216. package/lib/index.d.ts +0 -3
  217. package/lib/index.js +0 -44
  218. package/lib/paths.js +0 -7
  219. package/shuvi-app/application/client/create-application-factory.d.ts +0 -3
  220. package/shuvi-app/application/client/create-application-factory.js +0 -70
  221. package/shuvi-app/application/client/create-application-history-browser.d.ts +0 -1
  222. package/shuvi-app/application/client/create-application-history-browser.js +0 -3
  223. package/shuvi-app/application/client/create-application-history-hash.d.ts +0 -1
  224. package/shuvi-app/application/client/create-application-history-hash.js +0 -3
  225. package/shuvi-app/application/client/create-application-history-memory.d.ts +0 -1
  226. package/shuvi-app/application/client/create-application-history-memory.js +0 -3
  227. package/shuvi-app/application/server/create-application-spa.d.ts +0 -2
  228. package/shuvi-app/application/server/create-application-spa.js +0 -8
  229. package/shuvi-app/application/server/create-application.d.ts +0 -2
  230. package/shuvi-app/application/server/create-application.js +0 -25
  231. package/shuvi-app/entry/client/index.d.ts +0 -1
  232. package/shuvi-app/entry/client/index.js +0 -11
  233. package/shuvi-app/entry/client/run.prod.js +0 -3
  234. package/shuvi-app/entry/client/setup-app.d.ts +0 -3
  235. package/shuvi-app/entry/client/setup-app.js +0 -38
  236. package/shuvi-app/entry/client/setup-env.js +0 -27
  237. package/shuvi-app/entry/server/index.d.ts +0 -6
  238. package/shuvi-app/entry/server/index.js +0 -7
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+ import { SideEffectProps, HeadState } from './types';
3
+ declare const _default: () => {
4
+ new (props: any): {
5
+ componentDidMount(): void;
6
+ componentDidUpdate(): void;
7
+ componentWillUnmount(): void;
8
+ render(): React.ReactNode;
9
+ context: unknown;
10
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<React.PropsWithChildren<SideEffectProps>>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
11
+ forceUpdate(callback?: (() => void) | undefined): void;
12
+ readonly props: Readonly<React.PropsWithChildren<SideEffectProps>>;
13
+ state: Readonly<{}>;
14
+ refs: {
15
+ [key: string]: React.ReactInstance;
16
+ };
17
+ shouldComponentUpdate?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextState: Readonly<{}>, nextContext: any): boolean;
18
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
19
+ getSnapshotBeforeUpdate?(prevProps: Readonly<React.PropsWithChildren<SideEffectProps>>, prevState: Readonly<{}>): any;
20
+ componentWillMount?(): void;
21
+ UNSAFE_componentWillMount?(): void;
22
+ componentWillReceiveProps?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextContext: any): void;
23
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextContext: any): void;
24
+ componentWillUpdate?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextState: Readonly<{}>, nextContext: any): void;
25
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextState: Readonly<{}>, nextContext: any): void;
26
+ };
27
+ rewind(): HeadState | undefined;
28
+ contextType?: React.Context<any> | undefined;
29
+ };
30
+ export default _default;
@@ -0,0 +1,44 @@
1
+ // Based on https://github.com/zeit/next.js
2
+ // License: https://github.com/zeit/next.js/blob/977bf8d9ebd2845241b8689317f36e4e487f39d0/license.md
3
+ import { Component } from 'react';
4
+ const isServer = typeof window === 'undefined';
5
+ export default () => {
6
+ const mountedInstances = new Set();
7
+ let state;
8
+ function emitChange(component) {
9
+ state = component.props.reduceComponentsToState([...mountedInstances], component.props);
10
+ if (component.props.handleStateChange) {
11
+ component.props.handleStateChange(state);
12
+ }
13
+ }
14
+ return class extends Component {
15
+ // Used when server rendering
16
+ static rewind() {
17
+ const recordedState = state;
18
+ state = undefined;
19
+ mountedInstances.clear();
20
+ return recordedState;
21
+ }
22
+ constructor(props) {
23
+ super(props);
24
+ if (isServer) {
25
+ mountedInstances.add(this);
26
+ emitChange(this);
27
+ }
28
+ }
29
+ componentDidMount() {
30
+ mountedInstances.add(this);
31
+ emitChange(this);
32
+ }
33
+ componentDidUpdate() {
34
+ emitChange(this);
35
+ }
36
+ componentWillUnmount() {
37
+ mountedInstances.delete(this);
38
+ emitChange(this);
39
+ }
40
+ render() {
41
+ return null;
42
+ }
43
+ };
44
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { IHtmlTag } from '../types';
3
+ export declare type SideEffectProps = {
4
+ reduceComponentsToState: <T>(components: Array<React.ReactElement<any>>, props: T) => HeadState;
5
+ handleStateChange?: (state: HeadState) => void;
6
+ };
7
+ export interface HeadElement {
8
+ type: string;
9
+ props: {
10
+ [name: string]: any;
11
+ children?: string | string[];
12
+ };
13
+ }
14
+ export declare type HeadState = IHtmlTag[];
15
+ export declare type HeadItem = IHtmlTag;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import view from './view';
2
+ import app from './AppComponent';
3
+ import getRoutes from './getRoutes';
4
+ export { view, app, getRoutes };
@@ -0,0 +1,4 @@
1
+ import view from './view';
2
+ import app from './AppComponent';
3
+ import getRoutes from './getRoutes';
4
+ export { view, app, getRoutes };
@@ -0,0 +1,4 @@
1
+ /// <reference lib="dom" />
2
+ import * as React from 'react';
3
+ import { DynamicOptions } from './dynamic';
4
+ export declare function loadRouteComponent(loader: () => Promise<any>, options?: DynamicOptions<any>): React.ComponentType;
@@ -0,0 +1,9 @@
1
+ /// <reference lib="dom" />
2
+ import dynamic from './dynamic';
3
+ export function loadRouteComponent(loader, options) {
4
+ const DynamicComp = dynamic(() => loader().then(mod => {
5
+ const comp = mod.default || mod;
6
+ return comp;
7
+ }), options);
8
+ return DynamicComp;
9
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './loadable';
2
+ export { LoadableContext } from './loadable-context';
@@ -0,0 +1,2 @@
1
+ export { default } from './loadable';
2
+ export { LoadableContext } from './loadable-context';
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ declare type CaptureFn = (moduleName: string) => void;
3
+ export declare const LoadableContext: React.Context<CaptureFn | null>;
4
+ export {};
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ // @ts-ignore for some reason the React types don't like this, but it's correct.
3
+ export const LoadableContext = React.createContext(null);
@@ -0,0 +1,30 @@
1
+ /**
2
+ @copyright (c) 2017-present James Kyle <me@thejameskyle.com>
3
+ MIT License
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
20
+ */
21
+ import * as React from 'react';
22
+ declare type Options = any;
23
+ declare function Loadable<P>(opts: Options): React.ComponentType<P>;
24
+ declare namespace Loadable {
25
+ var Map: typeof LoadableMap;
26
+ var preloadAll: () => Promise<void>;
27
+ var preloadReady: (ids?: (string | number)[]) => Promise<void>;
28
+ }
29
+ declare function LoadableMap<P>(opts: Options): React.ComponentType<P>;
30
+ export default Loadable;
@@ -0,0 +1,277 @@
1
+ // @ts-nocheck
2
+ /**
3
+ @copyright (c) 2017-present James Kyle <me@thejameskyle.com>
4
+ MIT License
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
21
+ */
22
+ // https://github.com/jamiebuilds/react-loadable/blob/v5.5.0/src/index.js
23
+ // Modified to be compatible with webpack 4 / Next.js
24
+ // Modified to be compatible with shuvi.js
25
+ import * as React from 'react';
26
+ import { useSyncExternalStore } from 'use-sync-external-store/shim';
27
+ import { LoadableContext } from './loadable-context';
28
+ const ALL_INITIALIZERS = [];
29
+ const READY_INITIALIZERS = [];
30
+ let initialized = false;
31
+ function load(loader) {
32
+ let promise = loader();
33
+ let state = {
34
+ loading: true,
35
+ loaded: null,
36
+ error: null
37
+ };
38
+ state.promise = promise
39
+ .then(loaded => {
40
+ state.loading = false;
41
+ state.loaded = loaded;
42
+ return loaded;
43
+ })
44
+ .catch(err => {
45
+ state.loading = false;
46
+ state.error = err;
47
+ throw err;
48
+ });
49
+ return state;
50
+ }
51
+ function loadMap(obj) {
52
+ let state = {
53
+ loading: false,
54
+ loaded: {},
55
+ error: null
56
+ };
57
+ let promises = [];
58
+ try {
59
+ Object.keys(obj).forEach(key => {
60
+ let result = load(obj[key]);
61
+ if (!result.loading) {
62
+ state.loaded[key] = result.loaded;
63
+ state.error = result.error;
64
+ }
65
+ else {
66
+ state.loading = true;
67
+ }
68
+ promises.push(result.promise);
69
+ result.promise
70
+ .then(res => {
71
+ state.loaded[key] = res;
72
+ })
73
+ .catch(err => {
74
+ state.error = err;
75
+ });
76
+ });
77
+ }
78
+ catch (err) {
79
+ state.error = err;
80
+ }
81
+ state.promise = Promise.all(promises)
82
+ .then(res => {
83
+ state.loading = false;
84
+ return res;
85
+ })
86
+ .catch(err => {
87
+ state.loading = false;
88
+ throw err;
89
+ });
90
+ return state;
91
+ }
92
+ function resolve(obj) {
93
+ return obj && obj.__esModule ? obj.default : obj;
94
+ }
95
+ function render(loaded, props) {
96
+ return React.createElement(resolve(loaded), props);
97
+ }
98
+ function createLoadableComponent(loadFn, options) {
99
+ let opts = Object.assign({
100
+ loader: null,
101
+ loading: null,
102
+ delay: 200,
103
+ timeout: null,
104
+ render: render,
105
+ webpack: null,
106
+ modules: null
107
+ }, options);
108
+ let subscription = null;
109
+ function init() {
110
+ if (!subscription) {
111
+ const sub = new LoadableSubscription(loadFn, opts);
112
+ subscription = {
113
+ getCurrentValue: sub.getCurrentValue.bind(sub),
114
+ subscribe: sub.subscribe.bind(sub),
115
+ retry: sub.retry.bind(sub),
116
+ promise: sub.promise.bind(sub)
117
+ };
118
+ }
119
+ return subscription.promise();
120
+ }
121
+ // Server only
122
+ if (typeof window === 'undefined') {
123
+ ALL_INITIALIZERS.push(init);
124
+ }
125
+ // Client only
126
+ if (!initialized &&
127
+ typeof window !== 'undefined' &&
128
+ typeof opts.webpack === 'function') {
129
+ const moduleIds = opts.webpack();
130
+ READY_INITIALIZERS.push(ids => {
131
+ for (const moduleId of moduleIds) {
132
+ if (ids.indexOf(moduleId) !== -1) {
133
+ return init();
134
+ }
135
+ }
136
+ });
137
+ }
138
+ const LoadableComponent = React.forwardRef((props, ref) => {
139
+ init();
140
+ const context = React.useContext(LoadableContext);
141
+ const state = useSyncExternalStore(subscription.subscribe, subscription.getCurrentValue, subscription.getCurrentValue);
142
+ React.useImperativeHandle(ref, () => ({
143
+ retry: subscription.retry
144
+ }), []);
145
+ if (context && Array.isArray(opts.modules)) {
146
+ opts.modules.forEach(moduleName => {
147
+ context(moduleName);
148
+ });
149
+ }
150
+ return React.useMemo(() => {
151
+ if (state.loading || state.error) {
152
+ return React.createElement(opts.loading, {
153
+ isLoading: state.loading,
154
+ pastDelay: state.pastDelay,
155
+ timedOut: state.timedOut,
156
+ error: state.error,
157
+ retry: subscription.retry
158
+ });
159
+ }
160
+ else if (state.loaded) {
161
+ return opts.render(state.loaded, props);
162
+ }
163
+ else {
164
+ return null;
165
+ }
166
+ }, [props, state]);
167
+ });
168
+ LoadableComponent.preload = () => init();
169
+ LoadableComponent.displayName = 'LoadableComponent';
170
+ return LoadableComponent;
171
+ }
172
+ class LoadableSubscription {
173
+ constructor(loadFn, opts) {
174
+ this._loadFn = loadFn;
175
+ this._opts = opts;
176
+ this._callbacks = new Set();
177
+ this._delay = null;
178
+ this._timeout = null;
179
+ this.retry();
180
+ }
181
+ promise() {
182
+ return this._res.promise;
183
+ }
184
+ retry() {
185
+ this._clearTimeouts();
186
+ this._res = this._loadFn(this._opts.loader);
187
+ this._state = {
188
+ pastDelay: false,
189
+ timedOut: false
190
+ };
191
+ const { _res: res, _opts: opts } = this;
192
+ if (res.loading) {
193
+ if (typeof opts.delay === 'number') {
194
+ if (opts.delay === 0) {
195
+ this._state.pastDelay = true;
196
+ }
197
+ else {
198
+ this._delay = setTimeout(() => {
199
+ this._update({
200
+ pastDelay: true
201
+ });
202
+ }, opts.delay);
203
+ }
204
+ }
205
+ if (typeof opts.timeout === 'number') {
206
+ this._timeout = setTimeout(() => {
207
+ this._update({ timedOut: true });
208
+ }, opts.timeout);
209
+ }
210
+ }
211
+ this._res.promise
212
+ .then(() => {
213
+ this._update({});
214
+ this._clearTimeouts();
215
+ })
216
+ .catch(_err => {
217
+ this._update({});
218
+ this._clearTimeouts();
219
+ });
220
+ this._update({});
221
+ }
222
+ _update(partial) {
223
+ this._state = Object.assign(Object.assign(Object.assign({}, this._state), { error: this._res.error, loaded: this._res.loaded, loading: this._res.loading }), partial);
224
+ this._callbacks.forEach(callback => callback());
225
+ }
226
+ _clearTimeouts() {
227
+ clearTimeout(this._delay);
228
+ clearTimeout(this._timeout);
229
+ }
230
+ getCurrentValue() {
231
+ return this._state;
232
+ }
233
+ subscribe(callback) {
234
+ this._callbacks.add(callback);
235
+ return () => {
236
+ this._callbacks.delete(callback);
237
+ };
238
+ }
239
+ }
240
+ function Loadable(opts) {
241
+ return createLoadableComponent(load, opts);
242
+ }
243
+ function LoadableMap(opts) {
244
+ if (typeof opts.render !== 'function') {
245
+ throw new Error('LoadableMap requires a `render(loaded, props)` function');
246
+ }
247
+ return createLoadableComponent(loadMap, opts);
248
+ }
249
+ Loadable.Map = LoadableMap;
250
+ function flushInitializers(initializers, ids) {
251
+ let promises = [];
252
+ while (initializers.length) {
253
+ let init = initializers.pop();
254
+ promises.push(init(ids));
255
+ }
256
+ return Promise.all(promises).then(() => {
257
+ if (initializers.length) {
258
+ return flushInitializers(initializers, ids);
259
+ }
260
+ });
261
+ }
262
+ Loadable.preloadAll = () => {
263
+ return new Promise((resolveInitializers, reject) => {
264
+ flushInitializers(ALL_INITIALIZERS).then(resolveInitializers, reject);
265
+ });
266
+ };
267
+ Loadable.preloadReady = (ids = []) => {
268
+ return new Promise(resolvePreload => {
269
+ const res = () => {
270
+ initialized = true;
271
+ return resolvePreload();
272
+ };
273
+ // We always will resolve, errors should be handled within loading UIs.
274
+ flushInitializers(READY_INITIALIZERS, ids).then(res, res);
275
+ });
276
+ };
277
+ export default Loadable;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { IStoreManager } from '@shuvi/redox';
3
+ export declare const RedoxWrapper: (App: any, appContext: {
4
+ storeManager: IStoreManager;
5
+ }) => {
6
+ (appProps: any): JSX.Element;
7
+ displayName: string;
8
+ };
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { RedoxRoot } from '@shuvi/redox-react';
3
+ export const RedoxWrapper = (App, appContext) => {
4
+ function RedoxAppWrapper(appProps) {
5
+ return (<RedoxRoot storeManager={appContext.storeManager}>
6
+ <App {...appProps}/>
7
+ </RedoxRoot>);
8
+ }
9
+ RedoxAppWrapper.displayName = 'RedoxAppWrapper';
10
+ return RedoxAppWrapper;
11
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/platform-shared/shared").CustomRuntimePluginHooks, void>;
2
+ export default _default;
@@ -0,0 +1,16 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { createRuntimePlugin } from '@shuvi/platform-shared/shared';
11
+ import { RedoxWrapper } from './RedoxWrapper';
12
+ export default createRuntimePlugin({
13
+ appComponent: (App, appContext) => __awaiter(void 0, void 0, void 0, function* () {
14
+ return RedoxWrapper(App, appContext);
15
+ })
16
+ });
@@ -0,0 +1,5 @@
1
+ export { default as Head } from './head/head';
2
+ export { default as dynamic } from './dynamic';
3
+ export { useLoaderData } from './useLoaderData';
4
+ export { Link } from './Link';
5
+ export { useParams, useRouter, useCurrentRoute, RouterView } from '@shuvi/router-react';
@@ -0,0 +1,5 @@
1
+ export { default as Head } from './head/head';
2
+ export { default as dynamic } from './dynamic';
3
+ export { useLoaderData } from './useLoaderData';
4
+ export { Link } from './Link';
5
+ export { useParams, useRouter, useCurrentRoute, RouterView } from '@shuvi/router-react';
@@ -0,0 +1,14 @@
1
+ import { IAppState } from '@shuvi/platform-shared/shared';
2
+ import { IHtmlTag, IViewClient, IViewServer } from '../../shared';
3
+ export { IHtmlTag };
4
+ export declare type IReactAppData = {
5
+ appProps?: Record<string, any>;
6
+ errorProps?: {
7
+ notFound: boolean;
8
+ };
9
+ dynamicIds?: Array<string | number>;
10
+ appState?: IAppState;
11
+ loadersData: any;
12
+ };
13
+ export declare type IReactServerView = IViewServer<IReactAppData>;
14
+ export declare type IReactClientView = IViewClient<IReactAppData>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const noLoaderMessage = "Warning: no loader found. Please make sure the page component where `useLoaderData` is called has a `loader` export.";
2
+ export declare const useLoaderData: <T = any>() => T;
@@ -0,0 +1,27 @@
1
+ import { useMatchedRoute } from '@shuvi/router-react';
2
+ import { getLoaderManager } from '@shuvi/platform-shared/shared';
3
+ import { useRef, useEffect, useReducer } from 'react';
4
+ export const noLoaderMessage = 'Warning: no loader found. Please make sure the page component where `useLoaderData` is called has a `loader` export.';
5
+ export const useLoaderData = () => {
6
+ var _a;
7
+ const currentMatch = useMatchedRoute();
8
+ const loaderManager = getLoaderManager();
9
+ const id = (_a = currentMatch.route) === null || _a === void 0 ? void 0 : _a.id;
10
+ const data = loaderManager.getData(id);
11
+ if (data === null) {
12
+ throw Error(noLoaderMessage);
13
+ }
14
+ const dataRef = useRef(data);
15
+ const [_, forceUpdate] = useReducer(state => state * -1, 1);
16
+ useEffect(() => {
17
+ const cancel = loaderManager.subscribe(() => {
18
+ const newData = loaderManager.getData(id);
19
+ if (newData !== data) {
20
+ dataRef.current = newData;
21
+ forceUpdate();
22
+ }
23
+ });
24
+ return cancel;
25
+ }, []);
26
+ return dataRef.current;
27
+ };
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function getDisplayName(WrappedComponent: React.ComponentType): string;
@@ -0,0 +1,3 @@
1
+ export function getDisplayName(WrappedComponent) {
2
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
3
+ }
@@ -0,0 +1,2 @@
1
+ export declare const requestIdleCallback: ((callback: IdleRequestCallback, options?: IdleRequestOptions | undefined) => number) & typeof globalThis.requestIdleCallback;
2
+ export declare const cancelIdleCallback: ((handle: number) => void) & typeof globalThis.cancelIdleCallback;
@@ -0,0 +1,20 @@
1
+ export const requestIdleCallback = (typeof self !== 'undefined' &&
2
+ self.requestIdleCallback &&
3
+ self.requestIdleCallback.bind(window)) ||
4
+ function (cb) {
5
+ let start = Date.now();
6
+ return setTimeout(function () {
7
+ cb({
8
+ didTimeout: false,
9
+ timeRemaining: function () {
10
+ return Math.max(0, 50 - (Date.now() - start));
11
+ }
12
+ });
13
+ }, 1);
14
+ };
15
+ export const cancelIdleCallback = (typeof self !== 'undefined' &&
16
+ self.cancelIdleCallback &&
17
+ self.cancelIdleCallback.bind(window)) ||
18
+ function (id) {
19
+ return clearTimeout(id);
20
+ };
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ declare type UseIntersection = {
3
+ rootRef?: React.RefObject<HTMLElement>;
4
+ rootMargin?: string;
5
+ disabled?: boolean;
6
+ };
7
+ export default function useIntersection<T extends Element>({ rootRef, rootMargin, disabled }: UseIntersection): [(element: T | null) => void, boolean, () => void];
8
+ export {};