piral-core 1.0.0-pre.2296 → 1.0.1-beta.5640
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/LICENSE +1 -1
- package/README.md +12 -4
- package/app.codegen +36 -0
- package/app.codegen.d.ts +29 -0
- package/dist/codegen.js +5308 -0
- package/esm/Piral.d.ts +4 -4
- package/esm/Piral.js +8 -11
- package/esm/Piral.js.map +1 -1
- package/esm/PiralContext.d.ts +21 -0
- package/esm/PiralContext.js +34 -0
- package/esm/PiralContext.js.map +1 -0
- package/esm/RootListener.d.ts +2 -0
- package/esm/RootListener.js +23 -0
- package/esm/RootListener.js.map +1 -0
- package/esm/actions/app.d.ts +7 -4
- package/esm/actions/app.js +24 -14
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/components.js +5 -6
- package/esm/actions/components.js.map +1 -1
- package/esm/actions/data.js +16 -17
- package/esm/actions/data.js.map +1 -1
- package/esm/actions/define.js +2 -3
- package/esm/actions/define.js.map +1 -1
- package/esm/actions/portal.d.ts +2 -0
- package/esm/actions/portal.js +9 -4
- package/esm/actions/portal.js.map +1 -1
- package/esm/actions/state.js +7 -4
- package/esm/actions/state.js.map +1 -1
- package/esm/components/ErrorBoundary.d.ts +14 -31
- package/esm/components/ErrorBoundary.js +22 -28
- package/esm/components/ErrorBoundary.js.map +1 -1
- package/esm/components/ExtensionSlot.d.ts +1 -0
- package/esm/components/ExtensionSlot.js +34 -11
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/components/ForeignComponentContainer.d.ts +19 -0
- package/esm/components/ForeignComponentContainer.js +46 -0
- package/esm/components/ForeignComponentContainer.js.map +1 -0
- package/esm/components/Mediator.js +15 -12
- package/esm/components/Mediator.js.map +1 -1
- package/esm/components/PiralGlobals.d.ts +6 -0
- package/esm/components/PiralGlobals.js +13 -0
- package/esm/components/PiralGlobals.js.map +1 -0
- package/esm/components/PiralRoutes.d.ts +5 -0
- package/esm/components/PiralRoutes.js +6 -11
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/PiralSuspense.d.ts +5 -0
- package/esm/components/PiralSuspense.js +8 -0
- package/esm/components/PiralSuspense.js.map +1 -0
- package/esm/components/PiralView.d.ts +10 -1
- package/esm/components/PiralView.js +12 -25
- package/esm/components/PiralView.js.map +1 -1
- package/esm/components/PortalRenderer.d.ts +5 -0
- package/esm/components/PortalRenderer.js +7 -0
- package/esm/components/PortalRenderer.js.map +1 -0
- package/esm/components/ResponsiveLayout.d.ts +9 -1
- package/esm/components/ResponsiveLayout.js +5 -13
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/SwitchErrorInfo.js +12 -10
- package/esm/components/SwitchErrorInfo.js.map +1 -1
- package/esm/components/components.d.ts +18 -6
- package/esm/components/components.js +21 -9
- package/esm/components/components.js.map +1 -1
- package/esm/components/index.d.ts +4 -10
- package/esm/components/index.js +4 -10
- package/esm/components/index.js.map +1 -1
- package/esm/components/wrapComponent.d.ts +7 -0
- package/esm/components/wrapComponent.js +42 -0
- package/esm/components/wrapComponent.js.map +1 -0
- package/esm/createInstance.d.ts +2 -2
- package/esm/createInstance.js +34 -30
- package/esm/createInstance.js.map +1 -1
- package/esm/defaults/DefaultErrorInfo.js +10 -0
- package/esm/defaults/DefaultErrorInfo.js.map +1 -0
- package/esm/{components → defaults}/DefaultLayout.js +1 -4
- package/esm/defaults/DefaultLayout.js.map +1 -0
- package/esm/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +2 -2
- package/esm/defaults/DefaultLoadingIndicator.js.map +1 -0
- package/esm/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/esm/defaults/DefaultRouteSwitch_v5.js +11 -0
- package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/esm/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/esm/defaults/DefaultRouter_v5.d.ts +3 -0
- package/esm/defaults/DefaultRouter_v5.js +7 -0
- package/esm/defaults/DefaultRouter_v5.js.map +1 -0
- package/esm/defaults/DefaultRouter_v6.d.ts +3 -0
- package/esm/defaults/DefaultRouter_v6.js +7 -0
- package/esm/defaults/DefaultRouter_v6.js.map +1 -0
- package/esm/defaults/navigator_none.d.ts +5 -0
- package/esm/defaults/navigator_none.js +30 -0
- package/esm/defaults/navigator_none.js.map +1 -0
- package/esm/defaults/navigator_v5.d.ts +6 -0
- package/esm/defaults/navigator_v5.js +81 -0
- package/esm/defaults/navigator_v5.js.map +1 -0
- package/esm/defaults/navigator_v6.d.ts +6 -0
- package/esm/defaults/navigator_v6.js +77 -0
- package/esm/defaults/navigator_v6.js.map +1 -0
- package/esm/helpers.d.ts +12 -26
- package/esm/helpers.js +14 -72
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/action.js +2 -3
- package/esm/hooks/action.js.map +1 -1
- package/esm/hooks/actions.js +1 -1
- package/esm/hooks/actions.js.map +1 -1
- package/esm/hooks/globalState.d.ts +7 -0
- package/esm/hooks/globalState.js +10 -8
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/hooks/index.d.ts +2 -5
- package/esm/hooks/index.js +2 -5
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/media.js +8 -7
- package/esm/hooks/media.js.map +1 -1
- package/esm/hooks/piletApi.d.ts +7 -0
- package/esm/hooks/piletApi.js +14 -0
- package/esm/hooks/piletApi.js.map +1 -0
- package/esm/hooks/routes.d.ts +2 -0
- package/esm/hooks/routes.js +11 -0
- package/esm/hooks/routes.js.map +1 -0
- package/esm/hooks/setter.js +3 -2
- package/esm/hooks/setter.js.map +1 -1
- package/esm/hooks/sharedData.js +2 -2
- package/esm/hooks/sharedData.js.map +1 -1
- package/esm/index.d.ts +3 -1
- package/esm/index.js +3 -1
- package/esm/index.js.map +1 -1
- package/esm/modules/api.d.ts +2 -5
- package/esm/modules/api.js +9 -69
- package/esm/modules/api.js.map +1 -1
- package/esm/modules/core.d.ts +3 -0
- package/esm/modules/core.js +50 -0
- package/esm/modules/core.js.map +1 -0
- package/esm/modules/dependencies.d.ts +5 -6
- package/esm/modules/dependencies.js +9 -24
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/modules/element.d.ts +5 -0
- package/esm/modules/element.js +169 -0
- package/esm/modules/element.js.map +1 -0
- package/esm/modules/index.d.ts +1 -0
- package/esm/modules/index.js +1 -0
- package/esm/modules/index.js.map +1 -1
- package/esm/setters/SetComponent.js +11 -0
- package/esm/setters/SetComponent.js.map +1 -0
- package/esm/setters/SetError.js +11 -0
- package/esm/setters/SetError.js.map +1 -0
- package/esm/setters/SetErrors.js +9 -0
- package/esm/setters/SetErrors.js.map +1 -0
- package/esm/setters/SetLayout.js +9 -0
- package/esm/setters/SetLayout.js.map +1 -0
- package/esm/setters/SetProvider.js +11 -0
- package/esm/setters/SetProvider.js.map +1 -0
- package/esm/setters/SetRedirect.js +12 -0
- package/esm/setters/SetRedirect.js.map +1 -0
- package/{lib/components → esm/setters}/SetRoute.d.ts +6 -2
- package/esm/setters/SetRoute.js +11 -0
- package/esm/setters/SetRoute.js.map +1 -0
- package/esm/setters/index.d.ts +7 -0
- package/esm/setters/index.js +8 -0
- package/esm/setters/index.js.map +1 -0
- package/esm/state/createActions.d.ts +2 -2
- package/esm/state/createActions.js +8 -12
- package/esm/state/createActions.js.map +1 -1
- package/esm/state/createGlobalState.d.ts +1 -2
- package/esm/state/createGlobalState.js +9 -34
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/state/stateContext.js +1 -1
- package/esm/state/stateContext.js.map +1 -1
- package/esm/state/withApi.d.ts +1 -1
- package/esm/state/withApi.js +19 -104
- package/esm/state/withApi.js.map +1 -1
- package/esm/tools/codegen.d.ts +21 -0
- package/esm/tools/codegen.js +145 -0
- package/esm/tools/codegen.js.map +1 -0
- package/esm/tools/debugger.d.ts +4 -0
- package/esm/tools/debugger.js +54 -0
- package/esm/tools/debugger.js.map +1 -0
- package/esm/tools/emulator.d.ts +3 -0
- package/esm/tools/emulator.js +11 -0
- package/esm/tools/emulator.js.map +1 -0
- package/esm/types/api.d.ts +34 -9
- package/esm/types/common.d.ts +11 -11
- package/esm/types/components.d.ts +74 -8
- package/esm/types/config.d.ts +24 -17
- package/esm/types/data.d.ts +2 -2
- package/esm/types/extension.d.ts +31 -4
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/types/instance.d.ts +26 -4
- package/esm/types/layout.d.ts +3 -3
- package/esm/types/navigation.d.ts +94 -0
- package/esm/types/navigation.js +2 -0
- package/esm/types/navigation.js.map +1 -0
- package/esm/types/plugin.d.ts +1 -14
- package/esm/types/state.d.ts +66 -27
- package/esm/types/utils.d.ts +1 -1
- package/esm/utils/compare.d.ts +1 -1
- package/esm/utils/compare.js +24 -7
- package/esm/utils/compare.js.map +1 -1
- package/esm/utils/data.js +6 -7
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/extension.d.ts +16 -0
- package/esm/utils/extension.js +37 -0
- package/esm/utils/extension.js.map +1 -0
- package/esm/utils/foreign.d.ts +7 -2
- package/esm/utils/foreign.js +20 -9
- package/esm/utils/foreign.js.map +1 -1
- package/esm/utils/guid.js +3 -3
- package/esm/utils/guid.js.map +1 -1
- package/esm/utils/helpers.d.ts +11 -8
- package/esm/utils/helpers.js +29 -18
- package/esm/utils/helpers.js.map +1 -1
- package/esm/utils/index.d.ts +3 -1
- package/esm/utils/index.js +3 -1
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/media.js +8 -8
- package/esm/utils/media.js.map +1 -1
- package/esm/utils/state.d.ts +57 -0
- package/esm/utils/state.js +83 -0
- package/esm/utils/state.js.map +1 -0
- package/esm/utils/storage.js +13 -14
- package/esm/utils/storage.js.map +1 -1
- package/lib/Piral.d.ts +4 -4
- package/lib/Piral.js +11 -13
- package/lib/Piral.js.map +1 -1
- package/lib/PiralContext.d.ts +21 -0
- package/lib/PiralContext.js +38 -0
- package/lib/PiralContext.js.map +1 -0
- package/lib/RootListener.d.ts +2 -0
- package/lib/RootListener.js +27 -0
- package/lib/RootListener.js.map +1 -0
- package/lib/actions/app.d.ts +7 -4
- package/lib/actions/app.js +27 -16
- package/lib/actions/app.js.map +1 -1
- package/lib/actions/components.js +5 -6
- package/lib/actions/components.js.map +1 -1
- package/lib/actions/data.js +17 -18
- package/lib/actions/data.js.map +1 -1
- package/lib/actions/define.js +2 -3
- package/lib/actions/define.js.map +1 -1
- package/lib/actions/index.js +1 -1
- package/lib/actions/portal.d.ts +2 -0
- package/lib/actions/portal.js +12 -5
- package/lib/actions/portal.js.map +1 -1
- package/lib/actions/state.js +7 -4
- package/lib/actions/state.js.map +1 -1
- package/lib/components/ErrorBoundary.d.ts +14 -31
- package/lib/components/ErrorBoundary.js +23 -28
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/ExtensionSlot.d.ts +1 -0
- package/lib/components/ExtensionSlot.js +37 -14
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/ForeignComponentContainer.d.ts +19 -0
- package/lib/components/ForeignComponentContainer.js +50 -0
- package/lib/components/ForeignComponentContainer.js.map +1 -0
- package/lib/components/Mediator.js +18 -14
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/PiralGlobals.d.ts +6 -0
- package/lib/components/PiralGlobals.js +17 -0
- package/lib/components/PiralGlobals.js.map +1 -0
- package/lib/components/PiralRoutes.d.ts +5 -0
- package/lib/components/PiralRoutes.js +8 -12
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralSuspense.d.ts +5 -0
- package/lib/components/PiralSuspense.js +12 -0
- package/lib/components/PiralSuspense.js.map +1 -0
- package/lib/components/PiralView.d.ts +10 -1
- package/lib/components/PiralView.js +15 -27
- package/lib/components/PiralView.js.map +1 -1
- package/lib/components/PortalRenderer.d.ts +5 -0
- package/lib/components/PortalRenderer.js +11 -0
- package/lib/components/PortalRenderer.js.map +1 -0
- package/lib/components/ResponsiveLayout.d.ts +9 -1
- package/lib/components/ResponsiveLayout.js +7 -14
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SwitchErrorInfo.js +15 -12
- package/lib/components/SwitchErrorInfo.js.map +1 -1
- package/lib/components/components.d.ts +18 -6
- package/lib/components/components.js +24 -12
- package/lib/components/components.js.map +1 -1
- package/lib/components/index.d.ts +4 -10
- package/lib/components/index.js +5 -11
- package/lib/components/index.js.map +1 -1
- package/lib/components/wrapComponent.d.ts +7 -0
- package/lib/components/wrapComponent.js +46 -0
- package/lib/components/wrapComponent.js.map +1 -0
- package/lib/createInstance.d.ts +2 -2
- package/lib/createInstance.js +40 -36
- package/lib/createInstance.js.map +1 -1
- package/lib/defaults/DefaultErrorInfo.js +14 -0
- package/lib/defaults/DefaultErrorInfo.js.map +1 -0
- package/lib/{components → defaults}/DefaultLayout.js +3 -5
- package/lib/defaults/DefaultLayout.js.map +1 -0
- package/lib/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +4 -3
- package/lib/defaults/DefaultLoadingIndicator.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v5.js +15 -0
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v5.js +11 -0
- package/lib/defaults/DefaultRouter_v5.js.map +1 -0
- package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v6.js +11 -0
- package/lib/defaults/DefaultRouter_v6.js.map +1 -0
- package/lib/defaults/navigator_none.d.ts +5 -0
- package/lib/defaults/navigator_none.js +37 -0
- package/lib/defaults/navigator_none.js.map +1 -0
- package/lib/defaults/navigator_v5.d.ts +6 -0
- package/lib/defaults/navigator_v5.js +88 -0
- package/lib/defaults/navigator_v5.js.map +1 -0
- package/lib/defaults/navigator_v6.d.ts +6 -0
- package/lib/defaults/navigator_v6.js +84 -0
- package/lib/defaults/navigator_v6.js.map +1 -0
- package/lib/helpers.d.ts +12 -26
- package/lib/helpers.js +15 -75
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/action.js +2 -3
- package/lib/hooks/action.js.map +1 -1
- package/lib/hooks/actions.js +4 -4
- package/lib/hooks/actions.js.map +1 -1
- package/lib/hooks/globalState.d.ts +7 -0
- package/lib/hooks/globalState.js +14 -11
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/hooks/index.d.ts +2 -5
- package/lib/hooks/index.js +3 -6
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/media.js +10 -9
- package/lib/hooks/media.js.map +1 -1
- package/lib/hooks/piletApi.d.ts +7 -0
- package/lib/hooks/piletApi.js +18 -0
- package/lib/hooks/piletApi.js.map +1 -0
- package/lib/hooks/routes.d.ts +2 -0
- package/lib/hooks/routes.js +15 -0
- package/lib/hooks/routes.js.map +1 -0
- package/lib/hooks/setter.js +4 -3
- package/lib/hooks/setter.js.map +1 -1
- package/lib/hooks/sharedData.js +3 -3
- package/lib/hooks/sharedData.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/modules/api.d.ts +2 -5
- package/lib/modules/api.js +12 -75
- package/lib/modules/api.js.map +1 -1
- package/lib/modules/core.d.ts +3 -0
- package/lib/modules/core.js +54 -0
- package/lib/modules/core.js.map +1 -0
- package/lib/modules/dependencies.d.ts +5 -6
- package/lib/modules/dependencies.js +12 -27
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/modules/element.d.ts +5 -0
- package/lib/modules/element.js +173 -0
- package/lib/modules/element.js.map +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -1
- package/lib/modules/index.js.map +1 -1
- package/lib/setters/SetComponent.js +15 -0
- package/lib/setters/SetComponent.js.map +1 -0
- package/lib/setters/SetError.js +15 -0
- package/lib/setters/SetError.js.map +1 -0
- package/lib/setters/SetErrors.js +13 -0
- package/lib/setters/SetErrors.js.map +1 -0
- package/lib/setters/SetLayout.js +13 -0
- package/lib/setters/SetLayout.js.map +1 -0
- package/lib/{components → setters}/SetProvider.js +4 -5
- package/lib/setters/SetProvider.js.map +1 -0
- package/lib/setters/SetRedirect.js +16 -0
- package/lib/setters/SetRedirect.js.map +1 -0
- package/{esm/components → lib/setters}/SetRoute.d.ts +6 -2
- package/lib/setters/SetRoute.js +15 -0
- package/lib/setters/SetRoute.js.map +1 -0
- package/lib/setters/index.d.ts +7 -0
- package/lib/setters/index.js +11 -0
- package/lib/setters/index.js.map +1 -0
- package/lib/state/createActions.d.ts +2 -2
- package/lib/state/createActions.js +9 -13
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.d.ts +1 -2
- package/lib/state/createGlobalState.js +9 -34
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/index.js +1 -1
- package/lib/state/stateContext.js +1 -1
- package/lib/state/stateContext.js.map +1 -1
- package/lib/state/withApi.d.ts +1 -1
- package/lib/state/withApi.js +20 -105
- package/lib/state/withApi.js.map +1 -1
- package/lib/tools/codegen.d.ts +21 -0
- package/lib/tools/codegen.js +152 -0
- package/lib/tools/codegen.js.map +1 -0
- package/lib/tools/debugger.d.ts +4 -0
- package/lib/tools/debugger.js +58 -0
- package/lib/tools/debugger.js.map +1 -0
- package/lib/tools/emulator.d.ts +3 -0
- package/lib/tools/emulator.js +15 -0
- package/lib/tools/emulator.js.map +1 -0
- package/lib/types/api.d.ts +34 -9
- package/lib/types/common.d.ts +11 -11
- package/lib/types/components.d.ts +74 -8
- package/lib/types/config.d.ts +24 -17
- package/lib/types/data.d.ts +2 -2
- package/lib/types/extension.d.ts +31 -4
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/instance.d.ts +26 -4
- package/lib/types/layout.d.ts +3 -3
- package/lib/types/navigation.d.ts +94 -0
- package/lib/types/navigation.js +3 -0
- package/lib/types/navigation.js.map +1 -0
- package/lib/types/plugin.d.ts +1 -14
- package/lib/types/state.d.ts +66 -27
- package/lib/types/utils.d.ts +1 -1
- package/lib/utils/compare.d.ts +1 -1
- package/lib/utils/compare.js +26 -9
- package/lib/utils/compare.js.map +1 -1
- package/lib/utils/data.js +6 -7
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/extension.d.ts +16 -0
- package/lib/utils/extension.js +42 -0
- package/lib/utils/extension.js.map +1 -0
- package/lib/utils/foreign.d.ts +7 -2
- package/lib/utils/foreign.js +25 -12
- package/lib/utils/foreign.js.map +1 -1
- package/lib/utils/guid.js +3 -3
- package/lib/utils/guid.js.map +1 -1
- package/lib/utils/helpers.d.ts +11 -8
- package/lib/utils/helpers.js +31 -18
- package/lib/utils/helpers.js.map +1 -1
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +7 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/media.js +7 -7
- package/lib/utils/media.js.map +1 -1
- package/lib/utils/react.js +1 -1
- package/lib/utils/react.js.map +1 -1
- package/lib/utils/state.d.ts +57 -0
- package/lib/utils/state.js +94 -0
- package/lib/utils/state.js.map +1 -0
- package/lib/utils/storage.js +11 -12
- package/lib/utils/storage.js.map +1 -1
- package/package.json +51 -20
- package/src/Piral.test.tsx +7 -16
- package/src/Piral.tsx +12 -11
- package/src/PiralContext.tsx +43 -0
- package/src/RootListener.test.tsx +46 -0
- package/src/RootListener.tsx +26 -0
- package/src/actions/app.test.ts +114 -44
- package/src/actions/app.ts +33 -23
- package/src/actions/components.test.ts +11 -11
- package/src/actions/components.ts +5 -33
- package/src/actions/data.test.ts +50 -50
- package/src/actions/define.test.ts +2 -2
- package/src/actions/portal.test.ts +62 -17
- package/src/actions/portal.ts +19 -1
- package/src/actions/state.test.ts +3 -3
- package/src/actions/state.ts +8 -4
- package/src/components/ErrorBoundary.tsx +22 -49
- package/src/components/ExtensionSlot.test.tsx +115 -30
- package/src/components/ExtensionSlot.tsx +57 -18
- package/src/components/ForeignComponentContainer.test.tsx +100 -0
- package/src/components/ForeignComponentContainer.tsx +63 -0
- package/src/components/Mediator.test.tsx +16 -14
- package/src/components/Mediator.tsx +17 -9
- package/src/components/PiralGlobals.tsx +16 -0
- package/src/components/PiralRoutes.test.tsx +65 -57
- package/src/components/PiralRoutes.tsx +10 -17
- package/src/components/PiralSuspense.tsx +19 -0
- package/src/components/PiralView-server.test.tsx +61 -0
- package/src/components/PiralView.test.tsx +27 -26
- package/src/components/PiralView.tsx +28 -35
- package/src/components/PortalRenderer.tsx +12 -0
- package/src/components/ResponsiveLayout.test.tsx +18 -37
- package/src/components/ResponsiveLayout.tsx +18 -15
- package/src/components/SwitchErrorInfo.test.tsx +36 -0
- package/src/components/SwitchErrorInfo.tsx +5 -1
- package/src/components/components.tsx +20 -6
- package/src/components/index.ts +4 -10
- package/src/components/wrapComponent.tsx +74 -0
- package/src/createInstance.test.tsx +10 -0
- package/src/createInstance.tsx +19 -14
- package/src/{components → defaults}/DefaultErrorInfo.test.tsx +15 -18
- package/src/{components → defaults}/DefaultErrorInfo.tsx +2 -3
- package/src/defaults/DefaultLayout.test.tsx +23 -0
- package/src/defaults/DefaultLoadingIndicator.test.tsx +10 -0
- package/src/defaults/DefaultRouteSwitch_v5.tsx +15 -0
- package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
- package/src/defaults/DefaultRouter_v5.tsx +8 -0
- package/src/defaults/DefaultRouter_v6.tsx +8 -0
- package/src/defaults/navigator_none.tsx +35 -0
- package/src/defaults/navigator_v5.tsx +99 -0
- package/src/defaults/navigator_v6.tsx +96 -0
- package/src/helpers.test.tsx +30 -49
- package/src/helpers.tsx +31 -108
- package/src/hooks/action.ts +2 -3
- package/src/hooks/globalState.ts +10 -9
- package/src/hooks/index.ts +2 -5
- package/src/hooks/media.ts +2 -1
- package/src/hooks/piletApi.ts +14 -0
- package/src/hooks/routes.ts +14 -0
- package/src/hooks/setter-server.test.ts +22 -0
- package/src/hooks/setter.test.ts +18 -0
- package/src/hooks/setter.ts +2 -1
- package/src/index.tsx +3 -1
- package/src/modules/api.test.ts +15 -26
- package/src/modules/api.ts +3 -66
- package/src/modules/core.test.ts +148 -0
- package/src/modules/core.ts +52 -0
- package/src/modules/dependencies.test.ts +16 -5
- package/src/modules/dependencies.ts +13 -31
- package/src/modules/element-server.test.ts +29 -0
- package/src/modules/element.test.ts +67 -0
- package/src/modules/element.ts +212 -0
- package/src/modules/index.ts +1 -0
- package/src/{components → setters}/SetComponent.test.tsx +9 -8
- package/src/{components → setters}/SetComponent.tsx +2 -2
- package/src/{components → setters}/SetError.test.tsx +9 -8
- package/src/{components → setters}/SetError.tsx +2 -2
- package/src/{components → setters}/SetErrors.test.tsx +9 -8
- package/src/{components → setters}/SetLayout.test.tsx +9 -8
- package/src/{components → setters}/SetProvider.test.tsx +9 -8
- package/src/{components → setters}/SetProvider.tsx +2 -2
- package/src/{components → setters}/SetRedirect.test.tsx +9 -8
- package/src/{components → setters}/SetRedirect.tsx +4 -4
- package/src/{components → setters}/SetRoute.test.tsx +9 -8
- package/src/{components → setters}/SetRoute.tsx +7 -4
- package/src/setters/index.ts +7 -0
- package/src/state/createActions.test.ts +2 -2
- package/src/state/createActions.ts +5 -3
- package/src/state/createGlobalState.test.ts +55 -54
- package/src/state/createGlobalState.ts +4 -28
- package/src/state/withApi.test.tsx +87 -40
- package/src/state/withApi.tsx +31 -165
- package/src/tools/codegen.ts +193 -0
- package/src/tools/debugger.ts +84 -0
- package/src/tools/emulator.ts +13 -0
- package/src/types/api.ts +47 -10
- package/src/types/components.ts +76 -7
- package/src/types/config.ts +23 -17
- package/src/types/extension.ts +38 -5
- package/src/types/index.ts +1 -0
- package/src/types/instance.ts +28 -4
- package/src/types/navigation.ts +101 -0
- package/src/types/plugin.ts +1 -15
- package/src/types/state.ts +65 -25
- package/src/types/utils.ts +1 -1
- package/src/utils/compare.test.ts +15 -15
- package/src/utils/compare.ts +23 -3
- package/src/utils/extension.test.tsx +21 -0
- package/src/utils/extension.tsx +48 -0
- package/src/utils/foreign.test.ts +29 -11
- package/src/utils/foreign.ts +34 -7
- package/src/utils/guid.test.ts +6 -1
- package/src/utils/helpers.test.ts +52 -0
- package/src/utils/helpers.ts +22 -8
- package/src/utils/index.ts +4 -1
- package/src/utils/media-server.test.ts +13 -0
- package/src/utils/media.ts +2 -2
- package/src/utils/state.test.ts +37 -0
- package/src/utils/state.ts +131 -0
- package/dependencies.codegen +0 -9
- package/dependencies.codegen.native.js +0 -2
- package/esm/components/DefaultErrorInfo.js +0 -12
- package/esm/components/DefaultErrorInfo.js.map +0 -1
- package/esm/components/DefaultLayout.js.map +0 -1
- package/esm/components/DefaultLoader.js.map +0 -1
- package/esm/components/SetComponent.js +0 -12
- package/esm/components/SetComponent.js.map +0 -1
- package/esm/components/SetError.js +0 -12
- package/esm/components/SetError.js.map +0 -1
- package/esm/components/SetErrors.js +0 -10
- package/esm/components/SetErrors.js.map +0 -1
- package/esm/components/SetLayout.js +0 -10
- package/esm/components/SetLayout.js.map +0 -1
- package/esm/components/SetProvider.js +0 -12
- package/esm/components/SetProvider.js.map +0 -1
- package/esm/components/SetRedirect.js +0 -14
- package/esm/components/SetRedirect.js.map +0 -1
- package/esm/components/SetRoute.js +0 -12
- package/esm/components/SetRoute.js.map +0 -1
- package/esm/hooks/debounce.d.ts +0 -8
- package/esm/hooks/debounce.js +0 -18
- package/esm/hooks/debounce.js.map +0 -1
- package/esm/hooks/lockBodyScroll.d.ts +0 -6
- package/esm/hooks/lockBodyScroll.js +0 -13
- package/esm/hooks/lockBodyScroll.js.map +0 -1
- package/esm/hooks/onClickOutside.d.ts +0 -8
- package/esm/hooks/onClickOutside.js +0 -23
- package/esm/hooks/onClickOutside.js.map +0 -1
- package/esm/hooks/onScreenVisible.d.ts +0 -11
- package/esm/hooks/onScreenVisible.js +0 -28
- package/esm/hooks/onScreenVisible.js.map +0 -1
- package/esm/hooks/promise.d.ts +0 -13
- package/esm/hooks/promise.js +0 -21
- package/esm/hooks/promise.js.map +0 -1
- package/esm/utils/events.d.ts +0 -3
- package/esm/utils/events.js +0 -35
- package/esm/utils/events.js.map +0 -1
- package/lib/components/DefaultErrorInfo.js +0 -15
- package/lib/components/DefaultErrorInfo.js.map +0 -1
- package/lib/components/DefaultLayout.js.map +0 -1
- package/lib/components/DefaultLoader.js.map +0 -1
- package/lib/components/SetComponent.js +0 -16
- package/lib/components/SetComponent.js.map +0 -1
- package/lib/components/SetError.js +0 -16
- package/lib/components/SetError.js.map +0 -1
- package/lib/components/SetErrors.js +0 -14
- package/lib/components/SetErrors.js.map +0 -1
- package/lib/components/SetLayout.js +0 -14
- package/lib/components/SetLayout.js.map +0 -1
- package/lib/components/SetProvider.js.map +0 -1
- package/lib/components/SetRedirect.js +0 -18
- package/lib/components/SetRedirect.js.map +0 -1
- package/lib/components/SetRoute.js +0 -16
- package/lib/components/SetRoute.js.map +0 -1
- package/lib/hooks/debounce.d.ts +0 -8
- package/lib/hooks/debounce.js +0 -22
- package/lib/hooks/debounce.js.map +0 -1
- package/lib/hooks/lockBodyScroll.d.ts +0 -6
- package/lib/hooks/lockBodyScroll.js +0 -17
- package/lib/hooks/lockBodyScroll.js.map +0 -1
- package/lib/hooks/onClickOutside.d.ts +0 -8
- package/lib/hooks/onClickOutside.js +0 -27
- package/lib/hooks/onClickOutside.js.map +0 -1
- package/lib/hooks/onScreenVisible.d.ts +0 -11
- package/lib/hooks/onScreenVisible.js +0 -32
- package/lib/hooks/onScreenVisible.js.map +0 -1
- package/lib/hooks/promise.d.ts +0 -13
- package/lib/hooks/promise.js +0 -25
- package/lib/hooks/promise.js.map +0 -1
- package/lib/utils/events.d.ts +0 -3
- package/lib/utils/events.js +0 -39
- package/lib/utils/events.js.map +0 -1
- package/src/components/DefaultLayout.test.tsx +0 -23
- package/src/components/DefaultLoader.test.tsx +0 -10
- package/src/hooks/debounce.test.ts +0 -67
- package/src/hooks/debounce.ts +0 -19
- package/src/hooks/globalState.test.ts +0 -47
- package/src/hooks/lockBodyScroll.test.ts +0 -24
- package/src/hooks/lockBodyScroll.ts +0 -13
- package/src/hooks/onClickOutside.test.ts +0 -113
- package/src/hooks/onClickOutside.ts +0 -25
- package/src/hooks/onScreenVisible.test.ts +0 -68
- package/src/hooks/onScreenVisible.ts +0 -28
- package/src/hooks/promise.test.ts +0 -76
- package/src/hooks/promise.ts +0 -35
- package/src/utils/events.test.ts +0 -65
- package/src/utils/events.ts +0 -39
- package/esm/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
- package/esm/{components → defaults}/DefaultLayout.d.ts +0 -0
- package/esm/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
- package/esm/{components → setters}/SetComponent.d.ts +0 -0
- package/esm/{components → setters}/SetError.d.ts +0 -0
- package/esm/{components → setters}/SetErrors.d.ts +0 -0
- package/esm/{components → setters}/SetLayout.d.ts +0 -0
- package/esm/{components → setters}/SetProvider.d.ts +0 -0
- package/esm/{components → setters}/SetRedirect.d.ts +0 -0
- package/lib/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
- package/lib/{components → defaults}/DefaultLayout.d.ts +0 -0
- package/lib/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
- package/lib/{components → setters}/SetComponent.d.ts +0 -0
- package/lib/{components → setters}/SetError.d.ts +0 -0
- package/lib/{components → setters}/SetErrors.d.ts +0 -0
- package/lib/{components → setters}/SetLayout.d.ts +0 -0
- package/lib/{components → setters}/SetProvider.d.ts +0 -0
- package/lib/{components → setters}/SetRedirect.d.ts +0 -0
- package/src/{components → defaults}/DefaultLayout.tsx +1 -1
- /package/src/{components/DefaultLoader.tsx → defaults/DefaultLoadingIndicator.tsx} +0 -0
- /package/src/{components → setters}/SetErrors.tsx +0 -0
- /package/src/{components → setters}/SetLayout.tsx +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, act } from '@testing-library/react';
|
|
3
|
+
import { ForeignComponentContainer } from './ForeignComponentContainer';
|
|
4
|
+
|
|
5
|
+
function resolveAfter(time = 5) {
|
|
6
|
+
return new Promise<void>((resolve) => setTimeout(resolve, time));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('ForeignComponentContainer component', () => {
|
|
10
|
+
it('mounts an HTML component', async () => {
|
|
11
|
+
const mount = jest.fn();
|
|
12
|
+
const component = { mount };
|
|
13
|
+
const container = render(
|
|
14
|
+
<ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
|
|
15
|
+
);
|
|
16
|
+
await act(resolveAfter);
|
|
17
|
+
expect(mount).toHaveBeenCalled();
|
|
18
|
+
container.unmount();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('unmounts an HTML component', async () => {
|
|
22
|
+
const mount = jest.fn();
|
|
23
|
+
const unmount = jest.fn();
|
|
24
|
+
const component = { mount, unmount };
|
|
25
|
+
const container = render(
|
|
26
|
+
<ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
|
|
27
|
+
);
|
|
28
|
+
await act(resolveAfter);
|
|
29
|
+
expect(mount).toHaveBeenCalled();
|
|
30
|
+
expect(unmount).not.toHaveBeenCalled();
|
|
31
|
+
container.unmount();
|
|
32
|
+
expect(unmount).toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('updates an HTML component', async () => {
|
|
36
|
+
const mount = jest.fn();
|
|
37
|
+
const update = jest.fn();
|
|
38
|
+
const component = { mount, update };
|
|
39
|
+
const container = render(
|
|
40
|
+
<ForeignComponentContainer
|
|
41
|
+
$component={component}
|
|
42
|
+
$context={undefined}
|
|
43
|
+
$portalId="foo"
|
|
44
|
+
innerProps={{ a: 'bar' }}
|
|
45
|
+
/>,
|
|
46
|
+
);
|
|
47
|
+
await act(resolveAfter);
|
|
48
|
+
expect(mount).toHaveBeenCalled();
|
|
49
|
+
expect(update).not.toHaveBeenCalled();
|
|
50
|
+
container.rerender(
|
|
51
|
+
<ForeignComponentContainer
|
|
52
|
+
$component={component}
|
|
53
|
+
$context={undefined}
|
|
54
|
+
$portalId="foo"
|
|
55
|
+
innerProps={{ a: 'foo' }}
|
|
56
|
+
/>,
|
|
57
|
+
);
|
|
58
|
+
await act(resolveAfter);
|
|
59
|
+
expect(update).toHaveBeenCalled();
|
|
60
|
+
container.unmount();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('forces re-rendering of an HTML component', async () => {
|
|
64
|
+
const componentDidMount = ForeignComponentContainer.prototype.componentDidMount;
|
|
65
|
+
ForeignComponentContainer.prototype.componentDidMount = function () {
|
|
66
|
+
componentDidMount.call(this);
|
|
67
|
+
this.previous = {
|
|
68
|
+
removeEventListener() {},
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const mount = jest.fn();
|
|
72
|
+
const update = jest.fn();
|
|
73
|
+
const unmount = jest.fn();
|
|
74
|
+
const component = { mount, update, unmount };
|
|
75
|
+
const container = render(
|
|
76
|
+
<ForeignComponentContainer
|
|
77
|
+
$component={component}
|
|
78
|
+
$context={undefined}
|
|
79
|
+
$portalId="foo"
|
|
80
|
+
innerProps={{ a: 'bar' }}
|
|
81
|
+
/>,
|
|
82
|
+
);
|
|
83
|
+
await act(resolveAfter);
|
|
84
|
+
expect(mount).toHaveBeenCalled();
|
|
85
|
+
expect(unmount).not.toHaveBeenCalled();
|
|
86
|
+
expect(update).not.toHaveBeenCalled();
|
|
87
|
+
container.rerender(
|
|
88
|
+
<ForeignComponentContainer
|
|
89
|
+
$component={component}
|
|
90
|
+
$context={undefined}
|
|
91
|
+
$portalId="foo"
|
|
92
|
+
innerProps={{ a: 'foo' }}
|
|
93
|
+
/>,
|
|
94
|
+
);
|
|
95
|
+
await act(resolveAfter);
|
|
96
|
+
expect(update).not.toHaveBeenCalled();
|
|
97
|
+
expect(unmount).toHaveBeenCalled();
|
|
98
|
+
container.unmount();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isfunc } from 'piral-base';
|
|
3
|
+
import type {} from 'piral-debug-utils';
|
|
4
|
+
import type { ForeignComponent, BaseComponentProps, ComponentContext } from '../types';
|
|
5
|
+
|
|
6
|
+
interface ForeignComponentContainerProps<T> {
|
|
7
|
+
$portalId: string;
|
|
8
|
+
$component: ForeignComponent<T>;
|
|
9
|
+
$context: ComponentContext;
|
|
10
|
+
innerProps: T & BaseComponentProps;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
|
|
14
|
+
private locals?: Record<string, any> = {};
|
|
15
|
+
private current?: HTMLElement;
|
|
16
|
+
private previous?: HTMLElement;
|
|
17
|
+
|
|
18
|
+
private setNode = (node: HTMLDivElement) => {
|
|
19
|
+
this.current = node;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
componentDidMount() {
|
|
23
|
+
const { current } = this;
|
|
24
|
+
const { $component, $context, innerProps } = this.props;
|
|
25
|
+
const { mount } = $component;
|
|
26
|
+
|
|
27
|
+
if (current && isfunc(mount)) {
|
|
28
|
+
mount(current, innerProps, $context, this.locals);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.previous = current;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
componentDidUpdate() {
|
|
35
|
+
const { current, previous } = this;
|
|
36
|
+
const { $component, $context, innerProps } = this.props;
|
|
37
|
+
const { update } = $component;
|
|
38
|
+
|
|
39
|
+
if (current !== previous) {
|
|
40
|
+
previous && this.componentWillUnmount();
|
|
41
|
+
current && this.componentDidMount();
|
|
42
|
+
} else if (isfunc(update)) {
|
|
43
|
+
update(current, innerProps, $context, this.locals);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
componentWillUnmount() {
|
|
48
|
+
const { previous } = this;
|
|
49
|
+
const { $component } = this.props;
|
|
50
|
+
const { unmount } = $component;
|
|
51
|
+
|
|
52
|
+
if (previous && isfunc(unmount)) {
|
|
53
|
+
unmount(previous, this.locals);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.previous = undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
const { $portalId } = this.props;
|
|
61
|
+
return <piral-portal pid={$portalId} ref={this.setNode} />;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
2
4
|
import { Mediator } from './Mediator';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
|
-
import { mount } from 'enzyme';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
import { PiletMetadata } from '../types';
|
|
7
7
|
|
|
8
8
|
function createMockContainer() {
|
|
9
|
-
const state =
|
|
9
|
+
const state = create(() => ({
|
|
10
10
|
app: {
|
|
11
11
|
layout: 'tablet',
|
|
12
12
|
loading: false,
|
|
13
13
|
error: undefined,
|
|
14
14
|
},
|
|
15
|
-
});
|
|
15
|
+
}));
|
|
16
16
|
return {
|
|
17
17
|
context: {
|
|
18
18
|
on: jest.fn(),
|
|
@@ -20,18 +20,22 @@ function createMockContainer() {
|
|
|
20
20
|
emit: jest.fn(),
|
|
21
21
|
state,
|
|
22
22
|
dispatch(update) {
|
|
23
|
-
|
|
23
|
+
state.setState(update(state.getState()));
|
|
24
|
+
},
|
|
25
|
+
readState(select) {
|
|
26
|
+
return select(state.getState());
|
|
24
27
|
},
|
|
25
28
|
initialize(loading, error, modules) {
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const s = state.getState();
|
|
30
|
+
state.setState({
|
|
31
|
+
...s,
|
|
28
32
|
app: {
|
|
29
|
-
...
|
|
33
|
+
...s.app,
|
|
30
34
|
error,
|
|
31
35
|
loading,
|
|
32
36
|
},
|
|
33
37
|
modules,
|
|
34
|
-
})
|
|
38
|
+
} as any);
|
|
35
39
|
},
|
|
36
40
|
} as any,
|
|
37
41
|
};
|
|
@@ -42,17 +46,15 @@ describe('Component Mediator', () => {
|
|
|
42
46
|
const options = {
|
|
43
47
|
createApi: jest.fn(),
|
|
44
48
|
fetchPilets: () => {
|
|
45
|
-
return new Promise<Array<PiletMetadata>>((resolve
|
|
46
|
-
resolve([]);
|
|
47
|
-
});
|
|
49
|
+
return new Promise<Array<PiletMetadata>>((resolve) => resolve([]));
|
|
48
50
|
},
|
|
49
51
|
};
|
|
50
52
|
const { context } = createMockContainer();
|
|
51
|
-
|
|
53
|
+
render(
|
|
52
54
|
<StateContext.Provider value={context}>
|
|
53
55
|
<Mediator options={options} />
|
|
54
56
|
</StateContext.Provider>,
|
|
55
57
|
);
|
|
56
|
-
expect(
|
|
58
|
+
expect(context.state.getState().app.layout).toEqual('tablet');
|
|
57
59
|
});
|
|
58
60
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { LoadPiletsOptions, startLoadingPilets, PiletsLoading } from 'piral-base';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext } from '../hooks';
|
|
4
|
+
import { none } from '../utils';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The props of the Mediator component.
|
|
@@ -16,15 +17,22 @@ export interface MediatorProps {
|
|
|
16
17
|
* The Mediator component for interfacing with pilets loading.
|
|
17
18
|
*/
|
|
18
19
|
export const Mediator: React.FC<MediatorProps> = ({ options }) => {
|
|
19
|
-
const initialize =
|
|
20
|
+
const { initialize, readState } = useGlobalStateContext();
|
|
21
|
+
|
|
20
22
|
React.useEffect(() => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const shouldLoad = readState(s => s.app.loading);
|
|
24
|
+
|
|
25
|
+
if (shouldLoad) {
|
|
26
|
+
const { connect, disconnect } = startLoadingPilets(options);
|
|
27
|
+
const notifier: PiletsLoading = (error, pilets, loaded) => {
|
|
28
|
+
initialize(!loaded, error, pilets);
|
|
29
|
+
};
|
|
30
|
+
connect(notifier);
|
|
31
|
+
return () => disconnect(notifier);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}, none);
|
|
35
|
+
|
|
28
36
|
// tslint:disable-next-line:no-null-keyword
|
|
29
37
|
return null;
|
|
30
38
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PortalRenderer } from './PortalRenderer';
|
|
3
|
+
import { RegisteredDebug } from './components';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Integrates the global portal renderer and the debug utilities
|
|
7
|
+
* (if registered).
|
|
8
|
+
*/
|
|
9
|
+
export const PiralGlobals: React.FC = () => {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<PortalRenderer id="root" />
|
|
13
|
+
<RegisteredDebug />
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as hooks from '../hooks';
|
|
3
3
|
import { MemoryRouter } from 'react-router';
|
|
4
|
-
import {
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
5
|
import { PiralRoutes } from './PiralRoutes';
|
|
6
|
+
import { DefaultRouteSwitch } from '../defaults/DefaultRouteSwitch_v5';
|
|
6
7
|
|
|
7
8
|
const mountWithRouter = (node, url = '/') =>
|
|
8
|
-
|
|
9
|
+
render(
|
|
9
10
|
<MemoryRouter initialEntries={[url]} initialIndex={0}>
|
|
10
11
|
{node}
|
|
11
12
|
</MemoryRouter>,
|
|
@@ -13,91 +14,98 @@ const mountWithRouter = (node, url = '/') =>
|
|
|
13
14
|
|
|
14
15
|
jest.mock('../hooks');
|
|
15
16
|
|
|
16
|
-
(hooks as any).
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
(hooks as any).useRoutes = () => [
|
|
18
|
+
{
|
|
19
|
+
path: '/',
|
|
20
|
+
Component: StubHome,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
path: '/custom',
|
|
24
|
+
Component: StubCustomPage,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
path: '/foo',
|
|
28
|
+
Component: StubFooPage,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: '/foo/bar',
|
|
32
|
+
Component: StubFooBarPage,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: '/bar',
|
|
36
|
+
Component: StubBarPage,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const StubHome: React.FC = (props) => <div role="home" />;
|
|
33
41
|
StubHome.displayName = 'StubHome';
|
|
34
42
|
|
|
35
|
-
const StubCustomPage: React.FC = (props) => <div />;
|
|
43
|
+
const StubCustomPage: React.FC = (props) => <div role="custom-page" />;
|
|
36
44
|
StubCustomPage.displayName = 'StubCustomPage';
|
|
37
45
|
|
|
38
|
-
const StubNotFound: React.FC = (props) => <div />;
|
|
46
|
+
const StubNotFound: React.FC = (props) => <div role="not-found" />;
|
|
39
47
|
StubNotFound.displayName = 'StubNotFound';
|
|
40
48
|
|
|
41
|
-
const StubComponent: React.FC<{ data: any }> = (props) => <div />;
|
|
49
|
+
const StubComponent: React.FC<{ data: any }> = (props) => <div role="component" />;
|
|
42
50
|
StubComponent.displayName = 'StubComponent';
|
|
43
51
|
|
|
44
|
-
const StubFooPage: React.FC<{ data: any }> = (props) => <div />;
|
|
52
|
+
const StubFooPage: React.FC<{ data: any }> = (props) => <div role="foo-page" />;
|
|
45
53
|
StubFooPage.displayName = 'StubFooPage';
|
|
46
54
|
|
|
47
|
-
const StubFooBarPage: React.FC<{ data: any }> = (props) => <div />;
|
|
55
|
+
const StubFooBarPage: React.FC<{ data: any }> = (props) => <div role="foo-bar-page" />;
|
|
48
56
|
StubFooBarPage.displayName = 'StubFooBarPage';
|
|
49
57
|
|
|
50
|
-
const StubBarPage: React.FC<{ data: any }> = (props) => <div />;
|
|
58
|
+
const StubBarPage: React.FC<{ data: any }> = (props) => <div role="bar-page" />;
|
|
51
59
|
StubBarPage.displayName = 'StubBarPage';
|
|
52
60
|
|
|
53
61
|
describe('Routes Module', () => {
|
|
54
62
|
it('always goes to the given home on "/"', () => {
|
|
55
|
-
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/');
|
|
56
|
-
expect(node.
|
|
57
|
-
expect(node.
|
|
58
|
-
expect(node.
|
|
59
|
-
expect(node.
|
|
63
|
+
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/');
|
|
64
|
+
expect(node.queryAllByRole('home').length).toBe(1);
|
|
65
|
+
expect(node.queryAllByRole('not-found').length).toBe(0);
|
|
66
|
+
expect(node.queryAllByRole('custom-page').length).toBe(0);
|
|
67
|
+
expect(node.queryAllByRole('foo-bar-page').length).toBe(0);
|
|
60
68
|
});
|
|
61
69
|
|
|
62
70
|
it('goes to the not found on an invalid path', () => {
|
|
63
|
-
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/qxz');
|
|
64
|
-
expect(node.
|
|
65
|
-
expect(node.
|
|
66
|
-
expect(node.
|
|
67
|
-
expect(node.
|
|
71
|
+
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/qxz');
|
|
72
|
+
expect(node.queryAllByRole('home').length).toBe(0);
|
|
73
|
+
expect(node.queryAllByRole('not-found').length).toBe(1);
|
|
74
|
+
expect(node.queryAllByRole('custom-page').length).toBe(0);
|
|
75
|
+
expect(node.queryAllByRole('foo-bar-page').length).toBe(0);
|
|
68
76
|
});
|
|
69
77
|
|
|
70
78
|
it('goes to the custom page on "/custom"', () => {
|
|
71
|
-
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/custom');
|
|
72
|
-
expect(node.
|
|
73
|
-
expect(node.
|
|
74
|
-
expect(node.
|
|
75
|
-
expect(node.
|
|
79
|
+
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/custom');
|
|
80
|
+
expect(node.queryAllByRole('home').length).toBe(0);
|
|
81
|
+
expect(node.queryAllByRole('not-found').length).toBe(0);
|
|
82
|
+
expect(node.queryAllByRole('custom-page').length).toBe(1);
|
|
83
|
+
expect(node.queryAllByRole('foo-bar-page').length).toBe(0);
|
|
76
84
|
});
|
|
77
85
|
|
|
78
86
|
it('goes exactly to the page on "/foo/bar"', () => {
|
|
79
|
-
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/foo/bar');
|
|
80
|
-
expect(node.
|
|
81
|
-
expect(node.
|
|
82
|
-
expect(node.
|
|
83
|
-
expect(node.
|
|
87
|
+
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/foo/bar');
|
|
88
|
+
expect(node.queryAllByRole('home').length).toBe(0);
|
|
89
|
+
expect(node.queryAllByRole('not-found').length).toBe(0);
|
|
90
|
+
expect(node.queryAllByRole('custom-page').length).toBe(0);
|
|
91
|
+
expect(node.queryAllByRole('foo-bar-page').length).toBe(1);
|
|
84
92
|
});
|
|
85
93
|
|
|
86
94
|
it('goes exactly to the page on "/foo"', () => {
|
|
87
|
-
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/foo');
|
|
88
|
-
expect(node.
|
|
89
|
-
expect(node.
|
|
90
|
-
expect(node.
|
|
91
|
-
expect(node.
|
|
92
|
-
expect(node.
|
|
95
|
+
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/foo');
|
|
96
|
+
expect(node.queryAllByRole('home').length).toBe(0);
|
|
97
|
+
expect(node.queryAllByRole('not-found').length).toBe(0);
|
|
98
|
+
expect(node.queryAllByRole('custom-page').length).toBe(0);
|
|
99
|
+
expect(node.queryAllByRole('foo-bar-page').length).toBe(0);
|
|
100
|
+
expect(node.queryAllByRole('foo-page').length).toBe(1);
|
|
93
101
|
});
|
|
94
102
|
|
|
95
103
|
it('goes exactly to the page on "/bar"', () => {
|
|
96
|
-
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/bar');
|
|
97
|
-
expect(node.
|
|
98
|
-
expect(node.
|
|
99
|
-
expect(node.
|
|
100
|
-
expect(node.
|
|
101
|
-
expect(node.
|
|
104
|
+
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/bar');
|
|
105
|
+
expect(node.queryAllByRole('home').length).toBe(0);
|
|
106
|
+
expect(node.queryAllByRole('not-found').length).toBe(0);
|
|
107
|
+
expect(node.queryAllByRole('custom-page').length).toBe(0);
|
|
108
|
+
expect(node.queryAllByRole('foo-bar-page').length).toBe(0);
|
|
109
|
+
expect(node.queryAllByRole('bar-page').length).toBe(1);
|
|
102
110
|
});
|
|
103
111
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
|
+
import { useRoutes } from '../hooks';
|
|
4
|
+
import { RouteSwitchProps } from '../types';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The props used by the PiralRoutes component.
|
|
@@ -10,25 +11,17 @@ export interface RoutesProps extends SwitchProps {
|
|
|
10
11
|
* Sets the component for showing the not found page.
|
|
11
12
|
*/
|
|
12
13
|
NotFound: React.ComponentType<RouteComponentProps>;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the component for actually switching the routes.
|
|
16
|
+
*/
|
|
17
|
+
RouteSwitch: React.ComponentType<RouteSwitchProps>;
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* The component for defining the exclusive routes to be used.
|
|
17
22
|
*/
|
|
18
|
-
export const PiralRoutes: React.FC<RoutesProps> = ({ NotFound, ...props }) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<Switch {...props}>
|
|
24
|
-
{Object.keys(routes).map((url) => (
|
|
25
|
-
<Route exact key={url} path={url} component={routes[url]} />
|
|
26
|
-
))}
|
|
27
|
-
{Object.keys(pages).map((url) => (
|
|
28
|
-
<Route exact key={url} path={url} component={pages[url].component} />
|
|
29
|
-
))}
|
|
30
|
-
<Route component={NotFound} />
|
|
31
|
-
</Switch>
|
|
32
|
-
);
|
|
23
|
+
export const PiralRoutes: React.FC<RoutesProps> = ({ NotFound, RouteSwitch, ...props }) => {
|
|
24
|
+
const paths = useRoutes();
|
|
25
|
+
return <RouteSwitch NotFound={NotFound} paths={paths} {...props} />;
|
|
33
26
|
};
|
|
34
27
|
PiralRoutes.displayName = 'Routes';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RegisteredErrorInfo, RegisteredLoadingIndicator } from './components';
|
|
3
|
+
import { useGlobalState } from '../hooks';
|
|
4
|
+
|
|
5
|
+
export interface PiralSuspenseProps {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PiralSuspense: React.FC<PiralSuspenseProps> = ({ children }) => {
|
|
10
|
+
const { error, loading } = useGlobalState((m) => m.app);
|
|
11
|
+
|
|
12
|
+
return error ? (
|
|
13
|
+
<RegisteredErrorInfo type="loading" error={error} />
|
|
14
|
+
) : loading ? (
|
|
15
|
+
<RegisteredLoadingIndicator />
|
|
16
|
+
) : (
|
|
17
|
+
<>{children}</>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import * as hooks from '../hooks';
|
|
7
|
+
import * as routes from './PiralRoutes';
|
|
8
|
+
import { renderToString } from 'react-dom/server';
|
|
9
|
+
import { PiralView } from './PiralView';
|
|
10
|
+
|
|
11
|
+
const StubDashboard: React.FC = () => <div />;
|
|
12
|
+
StubDashboard.displayName = 'StubDashboard';
|
|
13
|
+
|
|
14
|
+
const StubErrorInfo: React.FC = () => <div />;
|
|
15
|
+
StubErrorInfo.displayName = 'StubErrorInfo';
|
|
16
|
+
|
|
17
|
+
const StubLoader: React.FC = () => <div />;
|
|
18
|
+
StubLoader.displayName = 'StubLoader';
|
|
19
|
+
|
|
20
|
+
const StubRouter: React.FC<React.PropsWithChildren<{}>> = ({ children }) => <div>{children}</div>;
|
|
21
|
+
StubRouter.displayName = 'StubRouter';
|
|
22
|
+
|
|
23
|
+
const StubLayout: React.FC<React.PropsWithChildren<{}>> = ({ children }) => <div>{children}</div>;
|
|
24
|
+
StubLayout.displayName = 'StubLayout';
|
|
25
|
+
|
|
26
|
+
jest.mock('../hooks');
|
|
27
|
+
jest.mock('./PiralRoutes');
|
|
28
|
+
|
|
29
|
+
const state = {
|
|
30
|
+
app: {
|
|
31
|
+
error: undefined,
|
|
32
|
+
loading: true,
|
|
33
|
+
},
|
|
34
|
+
components: {
|
|
35
|
+
ErrorInfo: StubErrorInfo,
|
|
36
|
+
LoadingIndicator: StubLoader,
|
|
37
|
+
Router: StubRouter,
|
|
38
|
+
Layout: StubLayout,
|
|
39
|
+
},
|
|
40
|
+
registry: {
|
|
41
|
+
pages: {},
|
|
42
|
+
extensions: {},
|
|
43
|
+
},
|
|
44
|
+
portals: {},
|
|
45
|
+
routes: {},
|
|
46
|
+
provider: undefined,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
(hooks as any).useGlobalState = (select: any) => select(state);
|
|
50
|
+
|
|
51
|
+
(routes as any).PiralRoutes = ({}) => <StubDashboard />;
|
|
52
|
+
|
|
53
|
+
describe('Portal Module', () => {
|
|
54
|
+
it('In this test window should be undefined', () => {
|
|
55
|
+
state.app.loading = false;
|
|
56
|
+
state.app.error = undefined;
|
|
57
|
+
const html = renderToString(<PiralView children={undefined} />);
|
|
58
|
+
expect(typeof window).toBe('undefined');
|
|
59
|
+
expect(html).not.toBe('');
|
|
60
|
+
});
|
|
61
|
+
});
|