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
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export { isfunc, requireModule } from 'piral-base';
|
|
1
2
|
export * from './compare';
|
|
2
3
|
export * from './data';
|
|
3
|
-
export * from './
|
|
4
|
+
export * from './extension';
|
|
4
5
|
export * from './foreign';
|
|
5
6
|
export * from './guid';
|
|
6
7
|
export * from './helpers';
|
|
7
8
|
export * from './media';
|
|
8
9
|
export * from './react';
|
|
10
|
+
export * from './state';
|
|
9
11
|
export * from './storage';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.requireModule = exports.isfunc = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var piral_base_1 = require("piral-base");
|
|
6
|
+
Object.defineProperty(exports, "isfunc", { enumerable: true, get: function () { return piral_base_1.isfunc; } });
|
|
7
|
+
Object.defineProperty(exports, "requireModule", { enumerable: true, get: function () { return piral_base_1.requireModule; } });
|
|
4
8
|
tslib_1.__exportStar(require("./compare"), exports);
|
|
5
9
|
tslib_1.__exportStar(require("./data"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./
|
|
10
|
+
tslib_1.__exportStar(require("./extension"), exports);
|
|
7
11
|
tslib_1.__exportStar(require("./foreign"), exports);
|
|
8
12
|
tslib_1.__exportStar(require("./guid"), exports);
|
|
9
13
|
tslib_1.__exportStar(require("./helpers"), exports);
|
|
10
14
|
tslib_1.__exportStar(require("./media"), exports);
|
|
11
15
|
tslib_1.__exportStar(require("./react"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./state"), exports);
|
|
12
17
|
tslib_1.__exportStar(require("./storage"), exports);
|
|
13
18
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAmD;AAA1C,oGAAA,MAAM,OAAA;AAAE,2GAAA,aAAa,OAAA;AAE9B,oDAA0B;AAC1B,iDAAuB;AACvB,sDAA4B;AAC5B,oDAA0B;AAC1B,iDAAuB;AACvB,oDAA0B;AAC1B,kDAAwB;AACxB,kDAAwB;AACxB,kDAAwB;AACxB,oDAA0B"}
|
package/lib/utils/media.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCurrentLayout = exports.defaultBreakpoints = exports.defaultLayouts = void 0;
|
|
4
|
-
|
|
4
|
+
const piral_base_1 = require("piral-base");
|
|
5
5
|
exports.defaultLayouts = ['desktop', 'tablet', 'mobile'];
|
|
6
6
|
exports.defaultBreakpoints = ['(min-width: 991px)', '(min-width: 481px)', '(max-width: 480px)'];
|
|
7
|
-
|
|
8
|
-
?
|
|
9
|
-
:
|
|
10
|
-
function getCurrentLayout(breakpoints, layouts, defaultLayout) {
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const mm = typeof window === 'undefined' || !(0, piral_base_1.isfunc)(window.matchMedia)
|
|
8
|
+
? () => ({ matches: undefined })
|
|
9
|
+
: (q) => window.matchMedia(q);
|
|
10
|
+
function getCurrentLayout(breakpoints = exports.defaultBreakpoints, layouts, defaultLayout) {
|
|
11
|
+
const query = breakpoints.findIndex((q) => mm(q).matches);
|
|
12
|
+
const layout = layouts[query];
|
|
13
13
|
return layout !== undefined ? layout : defaultLayout;
|
|
14
14
|
}
|
|
15
15
|
exports.getCurrentLayout = getCurrentLayout;
|
package/lib/utils/media.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AAGvB,QAAA,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE9D,QAAA,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,SAAgB,gBAAgB,CAAI,cAA6B,0BAAkB,EAAE,OAAiB,EAAE,aAAgB;IACtH,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC;AAJD,4CAIC"}
|
package/lib/utils/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultRender = void 0;
|
|
4
|
-
|
|
4
|
+
const React = require("react");
|
|
5
5
|
function defaultRender(children, key) {
|
|
6
6
|
return React.createElement(React.Fragment, { key: key }, children);
|
|
7
7
|
}
|
package/lib/utils/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/utils/react.tsx"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/utils/react.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B,SAAgB,aAAa,CAAC,QAAyB,EAAE,GAAY;IACnE,OAAO,oBAAC,KAAK,CAAC,QAAQ,IAAC,GAAG,EAAE,GAAG,IAAG,QAAQ,CAAkB,CAAC;AAC/D,CAAC;AAFD,sCAEC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { RouteComponentProps } from 'react-router';
|
|
3
|
+
import { GlobalState, PageRegistration, ExtensionRegistration } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Returns a dispatcher that includes all mentioned dispatchers.
|
|
6
|
+
* @param dispatchers The dispatchers to include.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withAll(...dispatchers: Array<(state: GlobalState) => GlobalState>): (state: GlobalState) => GlobalState;
|
|
9
|
+
/**
|
|
10
|
+
* Returns a dispatcher that adds a page registration.
|
|
11
|
+
* @param name The path of the page to register.
|
|
12
|
+
* @param value The value of the page to register.
|
|
13
|
+
* @returns The dispatcher.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withPage(name: string, value: PageRegistration): (state: GlobalState) => GlobalState;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a dispatcher that removes a page registration.
|
|
18
|
+
* @param name The path of the page to unregister.
|
|
19
|
+
* @returns The dispatcher.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withoutPage(name: string): (state: GlobalState) => GlobalState;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a dispatcher that adds an extension registration.
|
|
24
|
+
* @param name The name of the extension to register.
|
|
25
|
+
* @param value The value of the extension to register.
|
|
26
|
+
* @returns The dispatcher.
|
|
27
|
+
*/
|
|
28
|
+
export declare function withExtension(name: string, value: ExtensionRegistration): (state: GlobalState) => GlobalState;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a dispatcher that removes an extension registration.
|
|
31
|
+
* @param name The name of the extension to unregister.
|
|
32
|
+
* @param reference The reference for the extension.
|
|
33
|
+
* @returns The dispatcher.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withoutExtension(name: string, reference: any): (state: GlobalState) => GlobalState;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a dispatcher that adds an extension registration from the root (no Pilet API).
|
|
38
|
+
* @param name The name of the extension to register.
|
|
39
|
+
* @param component The extension's component to use.
|
|
40
|
+
* @returns The dispatcher.
|
|
41
|
+
*/
|
|
42
|
+
export declare function withRootExtension<T>(name: string, component: ComponentType<T>): (state: GlobalState) => GlobalState;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a dispatcher that adds another provider.
|
|
45
|
+
* @param provider The provider to include.
|
|
46
|
+
* @returns The dispatcher.
|
|
47
|
+
*/
|
|
48
|
+
export declare function withProvider(provider: JSX.Element): (state: GlobalState) => GlobalState;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a dispatcher that registers another route.
|
|
51
|
+
* @param path The path of the route to register.
|
|
52
|
+
* @param component The component representing the route.
|
|
53
|
+
* @returns The dispatcher.
|
|
54
|
+
*/
|
|
55
|
+
export declare function withRoute<T extends {
|
|
56
|
+
[K in keyof T]?: string;
|
|
57
|
+
} = {}>(path: string, component: ComponentType<RouteComponentProps<T>>): (state: GlobalState) => GlobalState;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withRoute = exports.withProvider = exports.withRootExtension = exports.withoutExtension = exports.withExtension = exports.withoutPage = exports.withPage = exports.withAll = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const extension_1 = require("./extension");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
/**
|
|
8
|
+
* Returns a dispatcher that includes all mentioned dispatchers.
|
|
9
|
+
* @param dispatchers The dispatchers to include.
|
|
10
|
+
*/
|
|
11
|
+
function withAll(...dispatchers) {
|
|
12
|
+
return (state) => {
|
|
13
|
+
for (const dispatcher of dispatchers) {
|
|
14
|
+
state = dispatcher(state);
|
|
15
|
+
}
|
|
16
|
+
return state;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.withAll = withAll;
|
|
20
|
+
/**
|
|
21
|
+
* Returns a dispatcher that adds a page registration.
|
|
22
|
+
* @param name The path of the page to register.
|
|
23
|
+
* @param value The value of the page to register.
|
|
24
|
+
* @returns The dispatcher.
|
|
25
|
+
*/
|
|
26
|
+
function withPage(name, value) {
|
|
27
|
+
return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: (0, helpers_1.withKey)(state.registry.pages, name, value) }) }));
|
|
28
|
+
}
|
|
29
|
+
exports.withPage = withPage;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a dispatcher that removes a page registration.
|
|
32
|
+
* @param name The path of the page to unregister.
|
|
33
|
+
* @returns The dispatcher.
|
|
34
|
+
*/
|
|
35
|
+
function withoutPage(name) {
|
|
36
|
+
return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: (0, helpers_1.withoutKey)(state.registry.pages, name) }) }));
|
|
37
|
+
}
|
|
38
|
+
exports.withoutPage = withoutPage;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a dispatcher that adds an extension registration.
|
|
41
|
+
* @param name The name of the extension to register.
|
|
42
|
+
* @param value The value of the extension to register.
|
|
43
|
+
* @returns The dispatcher.
|
|
44
|
+
*/
|
|
45
|
+
function withExtension(name, value) {
|
|
46
|
+
return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: (0, helpers_1.withKey)(state.registry.extensions, name, (0, helpers_1.appendItem)(state.registry.extensions[name], value)) }) }));
|
|
47
|
+
}
|
|
48
|
+
exports.withExtension = withExtension;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a dispatcher that removes an extension registration.
|
|
51
|
+
* @param name The name of the extension to unregister.
|
|
52
|
+
* @param reference The reference for the extension.
|
|
53
|
+
* @returns The dispatcher.
|
|
54
|
+
*/
|
|
55
|
+
function withoutExtension(name, reference) {
|
|
56
|
+
return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: (0, helpers_1.withKey)(state.registry.extensions, name, (0, helpers_1.excludeOn)(state.registry.extensions[name], (m) => m.reference === reference)) }) }));
|
|
57
|
+
}
|
|
58
|
+
exports.withoutExtension = withoutExtension;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a dispatcher that adds an extension registration from the root (no Pilet API).
|
|
61
|
+
* @param name The name of the extension to register.
|
|
62
|
+
* @param component The extension's component to use.
|
|
63
|
+
* @returns The dispatcher.
|
|
64
|
+
*/
|
|
65
|
+
function withRootExtension(name, component) {
|
|
66
|
+
return withExtension(name, {
|
|
67
|
+
component: (0, extension_1.toExtension)(component),
|
|
68
|
+
defaults: {},
|
|
69
|
+
pilet: '',
|
|
70
|
+
reference: component,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.withRootExtension = withRootExtension;
|
|
74
|
+
/**
|
|
75
|
+
* Returns a dispatcher that adds another provider.
|
|
76
|
+
* @param provider The provider to include.
|
|
77
|
+
* @returns The dispatcher.
|
|
78
|
+
*/
|
|
79
|
+
function withProvider(provider) {
|
|
80
|
+
const wrapper = (props) => (0, react_1.cloneElement)(provider, props);
|
|
81
|
+
return (state) => (Object.assign(Object.assign({}, state), { provider: !state.provider ? wrapper : (props) => (0, react_1.createElement)(state.provider, undefined, wrapper(props)) }));
|
|
82
|
+
}
|
|
83
|
+
exports.withProvider = withProvider;
|
|
84
|
+
/**
|
|
85
|
+
* Returns a dispatcher that registers another route.
|
|
86
|
+
* @param path The path of the route to register.
|
|
87
|
+
* @param component The component representing the route.
|
|
88
|
+
* @returns The dispatcher.
|
|
89
|
+
*/
|
|
90
|
+
function withRoute(path, component) {
|
|
91
|
+
return (state) => (Object.assign(Object.assign({}, state), { routes: (0, helpers_1.withKey)(state.routes, path, component) }));
|
|
92
|
+
}
|
|
93
|
+
exports.withRoute = withRoute;
|
|
94
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/utils/state.ts"],"names":[],"mappings":";;;AAAA,iCAAmE;AAEnE,2CAA0C;AAC1C,uCAAuE;AAGvE;;;GAGG;AACH,SAAgB,OAAO,CAAC,GAAG,WAAuD;IAChF,OAAO,CAAC,KAAkB,EAAe,EAAE;QACzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YACpC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;SAC3B;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AARD,0BAQC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,IAAY,EAAE,KAAuB;IAC5D,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,KAAK,EAAE,IAAA,iBAAO,EAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,OAEnD,CAAC;AACL,CAAC;AARD,4BAQC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,KAAK,EAAE,IAAA,oBAAU,EAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,OAE/C,CAAC;AACL,CAAC;AARD,kCAQC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,IAAY,EAAE,KAA4B;IACtE,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,UAAU,EAAE,IAAA,iBAAO,EAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,EAAE,IAAA,oBAAU,EAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,OAE1G,CAAC;AACL,CAAC;AARD,sCAQC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAY,EAAE,SAAc;IAC3D,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,UAAU,EAAE,IAAA,iBAAO,EACjB,KAAK,CAAC,QAAQ,CAAC,UAAU,EACzB,IAAI,EACJ,IAAA,mBAAS,EAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAC7E,OAEH,CAAC;AACL,CAAC;AAZD,4CAYC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAI,IAAY,EAAE,SAA2B;IAC5E,OAAO,aAAa,CAAC,IAAI,EAAE;QACzB,SAAS,EAAE,IAAA,uBAAW,EAAC,SAAS,CAAC;QACjC,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,SAAS;KACrB,CAAC,CAAC;AACL,CAAC;AAPD,8CAOC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,QAAqB;IAChD,MAAM,OAAO,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEnE,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,QAAQ,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,IACzG,CAAC;AACL,CAAC;AAPD,oCAOC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CACvB,IAAY,EACZ,SAAgD;IAEhD,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,MAAM,EAAE,IAAA,iBAAO,EAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,IAC9C,CAAC;AACL,CAAC;AARD,8BAQC"}
|
package/lib/utils/storage.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cookie = exports.storage = void 0;
|
|
4
|
-
|
|
4
|
+
const crx = /\s*(.*?)=(.*?)($|;|,(?! ))/g;
|
|
5
5
|
exports.storage = {
|
|
6
|
-
setItem
|
|
6
|
+
setItem(name, data) {
|
|
7
7
|
return localStorage.setItem(name, data);
|
|
8
8
|
},
|
|
9
|
-
getItem
|
|
9
|
+
getItem(name) {
|
|
10
10
|
return localStorage.getItem(name);
|
|
11
11
|
},
|
|
12
|
-
removeItem
|
|
12
|
+
removeItem(name) {
|
|
13
13
|
return localStorage.removeItem(name);
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
exports.cookie = {
|
|
17
|
-
setItem
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
document.cookie = name + "=" + encodeURIComponent(data) + ";expires=\"" + expires + "\";path=/;" + domainPart;
|
|
17
|
+
setItem(name, data, expires = '') {
|
|
18
|
+
const domain = location.hostname;
|
|
19
|
+
const domainPart = domain ? `domain=.${domain};` : '';
|
|
20
|
+
document.cookie = `${name}=${encodeURIComponent(data)};expires="${expires}";path=/;${domainPart}`;
|
|
22
21
|
},
|
|
23
|
-
getItem
|
|
24
|
-
return document.cookie.replace(crx,
|
|
22
|
+
getItem(name) {
|
|
23
|
+
return document.cookie.replace(crx, (_m, p1, p2) => (name === p1 ? p2 : ''));
|
|
25
24
|
},
|
|
26
|
-
removeItem
|
|
25
|
+
removeItem(name) {
|
|
27
26
|
this.setItem(name, '', '-1');
|
|
28
27
|
},
|
|
29
28
|
};
|
package/lib/utils/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":";;;AAEA,MAAM,GAAG,GAAG,6BAA6B,CAAC;AAE7B,QAAA,OAAO,GAAiB;IACnC,OAAO,CAAC,IAAY,EAAE,IAAY;QAChC,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,CAAC,IAAY;QAClB,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,UAAU,CAAC,IAAY;QACrB,OAAO,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF,CAAC;AAEW,QAAA,MAAM,GAAiB;IAClC,OAAO,CAAC,IAAY,EAAE,IAAY,EAAE,OAAO,GAAG,EAAE;QAC9C,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC;QACjC,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,kBAAkB,CAAC,IAAI,CAAC,aAAa,OAAO,YAAY,UAAU,EAAE,CAAC;IACpG,CAAC;IACD,OAAO,CAAC,IAAY;QAClB,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAO,EAAE,EAAU,EAAE,EAAU,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpG,CAAC;IACD,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.5640",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -11,19 +11,45 @@
|
|
|
11
11
|
"core",
|
|
12
12
|
"functional"
|
|
13
13
|
],
|
|
14
|
+
"importmap": {
|
|
15
|
+
"imports": {
|
|
16
|
+
"react": "react",
|
|
17
|
+
"react-dom": "react-dom",
|
|
18
|
+
"react-router": "react-router",
|
|
19
|
+
"react-router-dom": "react-router-dom"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
14
22
|
"author": "smapiot",
|
|
15
23
|
"homepage": "https://piral.io",
|
|
16
24
|
"license": "MIT",
|
|
17
25
|
"module": "esm/index.js",
|
|
18
26
|
"main": "lib/index.js",
|
|
19
27
|
"typings": "lib/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./esm/index.js",
|
|
31
|
+
"require": "./lib/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./esm/*": {
|
|
34
|
+
"import": "./esm/*"
|
|
35
|
+
},
|
|
36
|
+
"./lib/*": {
|
|
37
|
+
"require": "./lib/*"
|
|
38
|
+
},
|
|
39
|
+
"./_/*": {
|
|
40
|
+
"import": "./esm/*.js",
|
|
41
|
+
"require": "./lib/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
20
45
|
"sideEffects": false,
|
|
21
46
|
"files": [
|
|
47
|
+
"dist",
|
|
22
48
|
"esm",
|
|
23
49
|
"lib",
|
|
24
50
|
"src",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
51
|
+
"app.codegen",
|
|
52
|
+
"app.codegen.d.ts"
|
|
27
53
|
],
|
|
28
54
|
"funding": {
|
|
29
55
|
"type": "github",
|
|
@@ -37,30 +63,35 @@
|
|
|
37
63
|
"url": "https://github.com/smapiot/piral/issues"
|
|
38
64
|
},
|
|
39
65
|
"scripts": {
|
|
40
|
-
"
|
|
66
|
+
"cleanup": "rimraf dist esm lib",
|
|
67
|
+
"build": "yarn build:commonjs && yarn build:esnext && yarn build:codegen",
|
|
41
68
|
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
|
|
42
69
|
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
70
|
+
"build:codegen": "esbuild src/tools/codegen.ts --bundle --outfile=dist/codegen.js --format=cjs --platform=node --external:pnpapi",
|
|
43
71
|
"typedoc": "typedoc --json ../../../docs/types/piral-core.json src --exclude \"src/**/*.test.*\"",
|
|
44
72
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
45
73
|
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"piral-base": "1.0.1-beta.5640",
|
|
76
|
+
"piral-debug-utils": "1.0.1-beta.5640",
|
|
77
|
+
"zustand": "^3.0.0"
|
|
78
|
+
},
|
|
46
79
|
"devDependencies": {
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/react": "^
|
|
80
|
+
"@types/react": "^18.0.0",
|
|
81
|
+
"@types/react-dom": "^18.0.0",
|
|
49
82
|
"@types/react-router": "^5.1.8",
|
|
50
83
|
"@types/react-router-dom": "^5.1.6",
|
|
51
|
-
"react": "^
|
|
52
|
-
"react-dom": "^
|
|
84
|
+
"react": "^18.0.0",
|
|
85
|
+
"react-dom": "^18.0.0",
|
|
86
|
+
"react-router": "^5.2.0",
|
|
87
|
+
"react-router-dom": "^5.2.0"
|
|
53
88
|
},
|
|
54
|
-
"
|
|
55
|
-
"react"
|
|
56
|
-
"react-dom"
|
|
57
|
-
"react-router"
|
|
58
|
-
"react-router-dom"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"piral-base": "^1.0.0-pre.2296",
|
|
63
|
-
"piral-debug-utils": "^1.0.0-pre.2296"
|
|
64
|
-
},
|
|
65
|
-
"gitHead": "8dc47ff93be1eefcc3e226a1e7dd4d58615b4e0c"
|
|
89
|
+
"sharedDependencies": [
|
|
90
|
+
"react",
|
|
91
|
+
"react-dom",
|
|
92
|
+
"react-router",
|
|
93
|
+
"react-router-dom",
|
|
94
|
+
"tslib"
|
|
95
|
+
],
|
|
96
|
+
"gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
|
|
66
97
|
}
|
package/src/Piral.test.tsx
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { act } from '
|
|
3
|
-
import { mount, ReactWrapper } from 'enzyme';
|
|
2
|
+
import { render, act } from '@testing-library/react';
|
|
4
3
|
import { Piral } from './Piral';
|
|
5
|
-
import { PiralRouter } from './components';
|
|
6
4
|
import { createInstance } from './createInstance';
|
|
7
5
|
|
|
8
|
-
async function waitForComponentToPaint<P = {}>(wrapper: ReactWrapper<P>, amount = 0) {
|
|
9
|
-
await act(async () => {
|
|
10
|
-
await new Promise((resolve) => setTimeout(resolve, amount));
|
|
11
|
-
wrapper.update();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
6
|
describe('Piral Component', () => {
|
|
16
7
|
it('renders the Piral instance with default settings', async () => {
|
|
17
|
-
const node =
|
|
18
|
-
await
|
|
19
|
-
expect(node.
|
|
8
|
+
const node = render(<Piral />);
|
|
9
|
+
await act(() => Promise.resolve());
|
|
10
|
+
expect(node.container.childNodes.length).toBe(1);
|
|
20
11
|
});
|
|
21
12
|
|
|
22
13
|
it('renders the Piral instance with custom settings', async () => {
|
|
23
14
|
const instance = createInstance();
|
|
24
|
-
const node =
|
|
25
|
-
await
|
|
26
|
-
expect(node.
|
|
15
|
+
const node = render(<Piral instance={instance} />);
|
|
16
|
+
await act(() => Promise.resolve());
|
|
17
|
+
expect(node.container.childNodes.length).toBe(1);
|
|
27
18
|
});
|
|
28
19
|
});
|
package/src/Piral.tsx
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { StateContext } from './state';
|
|
3
2
|
import { createInstance } from './createInstance';
|
|
4
|
-
import { PiralView,
|
|
5
|
-
import
|
|
3
|
+
import { PiralView, RegisteredRouter } from './components';
|
|
4
|
+
import { PiralContext } from './PiralContext';
|
|
5
|
+
import { publicPath } from '../app.codegen';
|
|
6
|
+
import type { PiralProps } from './types';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Represents the Piral app shell frame. Use this component together
|
|
9
10
|
* with an existing instance to render the app shell.
|
|
10
|
-
* Includes layout and routing handling.
|
|
11
|
-
* to the generated views.
|
|
11
|
+
* Includes layout and routing handling. Connects the Piral context
|
|
12
|
+
* and the React router to the generated views.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
```jsx
|
|
@@ -19,11 +20,11 @@ const app = (
|
|
|
19
20
|
);
|
|
20
21
|
```
|
|
21
22
|
*/
|
|
22
|
-
export const Piral: React.FC<
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
</
|
|
23
|
+
export const Piral: React.FC<PiralProps> = ({ instance = createInstance(), breakpoints, children }) => (
|
|
24
|
+
<PiralContext instance={instance}>
|
|
25
|
+
<RegisteredRouter publicPath={publicPath}>
|
|
26
|
+
<PiralView breakpoints={breakpoints}>{children}</PiralView>
|
|
27
|
+
</RegisteredRouter>
|
|
28
|
+
</PiralContext>
|
|
28
29
|
);
|
|
29
30
|
Piral.displayName = 'Piral';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { StateContext } from './state';
|
|
3
|
+
import { createInstance } from './createInstance';
|
|
4
|
+
import { Mediator } from './components';
|
|
5
|
+
import { useGlobalState } from './hooks';
|
|
6
|
+
import { RootListener } from './RootListener';
|
|
7
|
+
import type { PiralContextProps } from './types';
|
|
8
|
+
|
|
9
|
+
interface PiralProviderProps {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const PiralProvider: React.FC<PiralProviderProps> = ({ children }) => {
|
|
14
|
+
const Provider = useGlobalState((m) => m.provider || React.Fragment);
|
|
15
|
+
return <Provider>{children}</Provider>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represents the Piral app shell frame. Use this component together
|
|
20
|
+
* with an existing instance to render components from micro frontends
|
|
21
|
+
* in your app.
|
|
22
|
+
* Wires the state container together with the global providers.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
```jsx
|
|
26
|
+
const app = (
|
|
27
|
+
<MyRouter>
|
|
28
|
+
<PiralContext instance={yourPiralInstance}>
|
|
29
|
+
<PiralGlobals />
|
|
30
|
+
<MyAppContent />
|
|
31
|
+
</PiralContext>
|
|
32
|
+
</MyRouter>
|
|
33
|
+
);
|
|
34
|
+
```
|
|
35
|
+
*/
|
|
36
|
+
export const PiralContext: React.FC<PiralContextProps> = ({ instance = createInstance(), children }) => (
|
|
37
|
+
<StateContext.Provider value={instance.context}>
|
|
38
|
+
<Mediator options={instance.options} key={instance.id} />
|
|
39
|
+
<RootListener />
|
|
40
|
+
<PiralProvider>{children}</PiralProvider>
|
|
41
|
+
</StateContext.Provider>
|
|
42
|
+
);
|
|
43
|
+
PiralContext.displayName = 'PiralContext';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, act } from '@testing-library/react';
|
|
3
|
+
import { RootListener } from './RootListener';
|
|
4
|
+
|
|
5
|
+
jest.mock('./hooks/globalState', () => ({
|
|
6
|
+
useGlobalStateContext: () => ({
|
|
7
|
+
showPortal() {},
|
|
8
|
+
}),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
function resolveAfter(time = 5) {
|
|
12
|
+
return new Promise<void>((resolve) => setTimeout(resolve, time));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('RootListener Component', () => {
|
|
16
|
+
it('renders the RootListener instance with default settings', async () => {
|
|
17
|
+
const element = document.createElement('div');
|
|
18
|
+
const removed = jest.fn();
|
|
19
|
+
document.body.appendChild(element);
|
|
20
|
+
render(<RootListener />);
|
|
21
|
+
document.body.removeEventListener = removed;
|
|
22
|
+
await act(() => {
|
|
23
|
+
const event = new CustomEvent('render-html', {
|
|
24
|
+
bubbles: true,
|
|
25
|
+
detail: {
|
|
26
|
+
target: element,
|
|
27
|
+
props: {},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
element.dispatchEvent(event);
|
|
31
|
+
return resolveAfter();
|
|
32
|
+
});
|
|
33
|
+
await act(resolveAfter);
|
|
34
|
+
expect(removed).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('removes the RootListener successfully', async () => {
|
|
38
|
+
const removed = jest.fn();
|
|
39
|
+
const container = render(<RootListener />);
|
|
40
|
+
document.body.removeEventListener = removed;
|
|
41
|
+
await act(resolveAfter);
|
|
42
|
+
container.unmount();
|
|
43
|
+
await act(resolveAfter);
|
|
44
|
+
expect(removed).toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useGlobalStateContext } from './hooks';
|
|
3
|
+
import { renderElement } from './modules';
|
|
4
|
+
|
|
5
|
+
export const RootListener: React.FC = () => {
|
|
6
|
+
const context = useGlobalStateContext();
|
|
7
|
+
|
|
8
|
+
React.useLayoutEffect(() => {
|
|
9
|
+
if (typeof document !== 'undefined') {
|
|
10
|
+
const handler = (ev: CustomEvent) => {
|
|
11
|
+
ev.stopPropagation();
|
|
12
|
+
const { target, props } = ev.detail;
|
|
13
|
+
const [dispose, update] = renderElement(context, target, props);
|
|
14
|
+
target.dispose = dispose;
|
|
15
|
+
target.update = update;
|
|
16
|
+
};
|
|
17
|
+
document.body.addEventListener('render-html', handler, false);
|
|
18
|
+
|
|
19
|
+
return () => {
|
|
20
|
+
document.body.removeEventListener('render-html', handler, false);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}, [context]);
|
|
24
|
+
|
|
25
|
+
return null;
|
|
26
|
+
};
|