piral-core 1.0.0-pre.2217 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -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 -68
- 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 +37 -10
- 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 -74
- 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 +37 -10
- 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 +55 -18
- 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 -65
- 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 +50 -11
- 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
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { DefaultErrorInfo, DefaultLoadingIndicator, DefaultLayout } from '../components';
|
|
1
|
+
import create from 'zustand';
|
|
2
|
+
import { createDefaultState } from '../../app.codegen';
|
|
4
3
|
import { GlobalState, NestedPartial } from '../types';
|
|
5
4
|
|
|
6
5
|
function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
@@ -19,29 +18,6 @@ function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export function createGlobalState(customState: NestedPartial<GlobalState> = {}) {
|
|
22
|
-
const defaultState: GlobalState =
|
|
23
|
-
|
|
24
|
-
error: undefined,
|
|
25
|
-
loading: typeof window !== 'undefined',
|
|
26
|
-
layout: 'desktop',
|
|
27
|
-
},
|
|
28
|
-
components: {
|
|
29
|
-
ErrorInfo: DefaultErrorInfo,
|
|
30
|
-
LoadingIndicator: DefaultLoadingIndicator,
|
|
31
|
-
Router: BrowserRouter,
|
|
32
|
-
Layout: DefaultLayout,
|
|
33
|
-
},
|
|
34
|
-
errorComponents: {},
|
|
35
|
-
registry: {
|
|
36
|
-
extensions: {},
|
|
37
|
-
pages: {},
|
|
38
|
-
wrappers: {},
|
|
39
|
-
},
|
|
40
|
-
routes: {},
|
|
41
|
-
data: {},
|
|
42
|
-
portals: {},
|
|
43
|
-
modules: [],
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return Atom.of(extend(defaultState, customState));
|
|
21
|
+
const defaultState: GlobalState = createDefaultState();
|
|
22
|
+
return create(() => extend(defaultState, customState));
|
|
47
23
|
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { Atom } from '@dbeining/react-atom';
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
5
4
|
import { withApi } from './withApi';
|
|
6
5
|
import { StateContext } from '../state';
|
|
7
6
|
|
|
8
7
|
function createMockContainer() {
|
|
9
|
-
const state =
|
|
8
|
+
const state = create(() => ({
|
|
9
|
+
app: {},
|
|
10
|
+
components: {
|
|
11
|
+
ErrorInfo: StubErrorInfo,
|
|
12
|
+
},
|
|
13
|
+
registry: {
|
|
14
|
+
wrappers: { feed: 'test', '*': 'test' },
|
|
15
|
+
},
|
|
10
16
|
portals: {},
|
|
11
|
-
});
|
|
17
|
+
}));
|
|
12
18
|
return {
|
|
13
19
|
context: {
|
|
14
|
-
converters: {
|
|
15
|
-
readState() {
|
|
16
|
-
return
|
|
20
|
+
converters: {},
|
|
21
|
+
readState(cb) {
|
|
22
|
+
return cb(state.getState());
|
|
23
|
+
},
|
|
24
|
+
navigation: {
|
|
25
|
+
router: undefined,
|
|
17
26
|
},
|
|
18
27
|
on: jest.fn(),
|
|
19
28
|
off: jest.fn(),
|
|
@@ -24,46 +33,76 @@ function createMockContainer() {
|
|
|
24
33
|
};
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(hooks as any).useGlobalState = (select: any) =>
|
|
30
|
-
select({
|
|
36
|
+
function createMockContainerWithNoWrappers() {
|
|
37
|
+
const state = create(() => ({
|
|
31
38
|
components: {
|
|
32
39
|
ErrorInfo: StubErrorInfo,
|
|
33
40
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
registry: {},
|
|
42
|
+
portals: {},
|
|
43
|
+
}));
|
|
44
|
+
return {
|
|
45
|
+
context: {
|
|
46
|
+
converters: {},
|
|
47
|
+
readState(cb) {
|
|
48
|
+
return cb({
|
|
49
|
+
registry: {
|
|
50
|
+
wrappers: {},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
on: jest.fn(),
|
|
55
|
+
off: jest.fn(),
|
|
56
|
+
emit: jest.fn(),
|
|
57
|
+
state,
|
|
58
|
+
destroyPortal: (id) => {},
|
|
59
|
+
} as any,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
39
62
|
|
|
40
|
-
const StubErrorInfo: React.FC = (
|
|
63
|
+
const StubErrorInfo: React.FC<any> = ({ type }) => <div role="error">{type}</div>;
|
|
41
64
|
StubErrorInfo.displayName = 'StubErrorInfo';
|
|
42
65
|
|
|
43
|
-
const StubComponent: React.FC<{ shouldCrash?: boolean }> = ({ shouldCrash }) => {
|
|
66
|
+
const StubComponent: React.FC<{ shouldCrash?: boolean; piral?: any }> = ({ shouldCrash, piral }) => {
|
|
44
67
|
if (shouldCrash) {
|
|
45
68
|
throw new Error('I should crash!');
|
|
46
69
|
}
|
|
47
|
-
return <div
|
|
70
|
+
return <div role="component">{piral && 'piral'}</div>;
|
|
48
71
|
};
|
|
49
72
|
StubComponent.displayName = 'StubComponent';
|
|
50
73
|
|
|
51
74
|
describe('withApi Module', () => {
|
|
52
75
|
it('wraps a component and forwards the API as piral', () => {
|
|
53
|
-
const api: any = {
|
|
76
|
+
const api: any = {
|
|
77
|
+
meta: {
|
|
78
|
+
name: 'foo',
|
|
79
|
+
},
|
|
80
|
+
};
|
|
54
81
|
const { context } = createMockContainer();
|
|
55
82
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
56
|
-
const node =
|
|
57
|
-
|
|
83
|
+
const node = render(
|
|
84
|
+
<StateContext.Provider value={context}>
|
|
85
|
+
<Component />
|
|
86
|
+
</StateContext.Provider>,
|
|
87
|
+
);
|
|
88
|
+
expect(node.getByRole('component').textContent).toBe('piral');
|
|
58
89
|
});
|
|
59
90
|
|
|
60
91
|
it('is protected against a component crash', () => {
|
|
61
92
|
console.error = jest.fn();
|
|
62
|
-
const api: any = {
|
|
93
|
+
const api: any = {
|
|
94
|
+
meta: {
|
|
95
|
+
name: 'foo',
|
|
96
|
+
},
|
|
97
|
+
};
|
|
63
98
|
const { context } = createMockContainer();
|
|
64
99
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
65
|
-
const node =
|
|
66
|
-
|
|
100
|
+
const node = render(
|
|
101
|
+
<StateContext.Provider value={context}>
|
|
102
|
+
<Component shouldCrash />
|
|
103
|
+
</StateContext.Provider>,
|
|
104
|
+
);
|
|
105
|
+
expect(node.getByRole('error').textContent).toBe('feed');
|
|
67
106
|
});
|
|
68
107
|
|
|
69
108
|
it('reports to console.error when an error is hit', () => {
|
|
@@ -75,40 +114,48 @@ describe('withApi Module', () => {
|
|
|
75
114
|
};
|
|
76
115
|
const { context } = createMockContainer();
|
|
77
116
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
78
|
-
|
|
117
|
+
render(
|
|
118
|
+
<StateContext.Provider value={context}>
|
|
119
|
+
<Component shouldCrash />
|
|
120
|
+
</StateContext.Provider>,
|
|
121
|
+
);
|
|
79
122
|
expect(console.error).toHaveBeenCalled();
|
|
80
123
|
});
|
|
81
124
|
|
|
82
125
|
it('Wraps component of type object', () => {
|
|
83
|
-
const api: any = {
|
|
126
|
+
const api: any = {
|
|
127
|
+
meta: {
|
|
128
|
+
name: 'foo',
|
|
129
|
+
},
|
|
130
|
+
};
|
|
84
131
|
const { context } = createMockContainer();
|
|
85
132
|
context.converters = {
|
|
86
|
-
html: (component) =>
|
|
87
|
-
return component.component;
|
|
88
|
-
},
|
|
133
|
+
html: ({ component }) => component,
|
|
89
134
|
};
|
|
90
135
|
const Component = withApi(context, { type: 'html', component: { mount: () => {} } }, api, 'unknown');
|
|
91
136
|
|
|
92
|
-
const node =
|
|
137
|
+
const node = render(
|
|
93
138
|
<StateContext.Provider value={context}>
|
|
94
139
|
<Component />
|
|
95
140
|
</StateContext.Provider>,
|
|
96
141
|
);
|
|
97
142
|
|
|
98
|
-
expect(node.children.length).toBe(1);
|
|
143
|
+
expect(node.container.children.length).toBe(1);
|
|
99
144
|
});
|
|
100
145
|
|
|
101
146
|
it('Wraps component which is object == null.', () => {
|
|
102
|
-
const api: any = {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
html: (component) => {
|
|
106
|
-
return component.component;
|
|
147
|
+
const api: any = {
|
|
148
|
+
meta: {
|
|
149
|
+
name: 'foo',
|
|
107
150
|
},
|
|
108
151
|
};
|
|
109
|
-
const
|
|
152
|
+
const { context } = createMockContainerWithNoWrappers();
|
|
153
|
+
context.converters = {
|
|
154
|
+
html: ({ component }) => component,
|
|
155
|
+
};
|
|
156
|
+
const Component = withApi(context, null as any, api, 'unknown');
|
|
110
157
|
|
|
111
|
-
|
|
158
|
+
render(
|
|
112
159
|
<StateContext.Provider value={context}>
|
|
113
160
|
<Component />
|
|
114
161
|
</StateContext.Provider>,
|
package/src/state/withApi.tsx
CHANGED
|
@@ -1,165 +1,40 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { PiralError, PiralLoadingIndicator, ErrorBoundary, ErrorBoundaryOptions } from '../components';
|
|
6
|
-
import { useGlobalState, useActions } from '../hooks';
|
|
7
|
-
import { defaultRender, convertComponent } from '../utils';
|
|
8
|
-
import {
|
|
9
|
-
AnyComponent,
|
|
10
|
-
Errors,
|
|
11
|
-
ComponentConverters,
|
|
12
|
-
ForeignComponent,
|
|
13
|
-
PiletApi,
|
|
14
|
-
BaseComponentProps,
|
|
15
|
-
ComponentContext,
|
|
16
|
-
GlobalStateContext,
|
|
17
|
-
} from '../types';
|
|
2
|
+
import { ErrorBoundary, wrapComponent } from '../components';
|
|
3
|
+
import { defaultRender } from '../utils';
|
|
4
|
+
import { AnyComponent, Errors, PiletApi, BaseComponentProps, GlobalStateContext } from '../types';
|
|
18
5
|
|
|
19
|
-
|
|
6
|
+
const DefaultWrapper: React.FC<React.PropsWithChildren<{}>> = (props) => defaultRender(props.children);
|
|
20
7
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const PortalRenderer: React.FC<PortalRendererProps> = ({ id }) => {
|
|
26
|
-
const children = useGlobalState((m) => m.portals[id] || []);
|
|
27
|
-
return defaultRender(children);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const DefaultWrapper: React.FC = (props) => <>{props.children}</>;
|
|
31
|
-
|
|
32
|
-
interface ForeignComponentContainerProps<T> {
|
|
33
|
-
$portalId: string;
|
|
34
|
-
$component: ForeignComponent<T>;
|
|
35
|
-
$context: ComponentContext;
|
|
36
|
-
innerProps: T & BaseComponentProps;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
|
|
40
|
-
private current?: HTMLElement;
|
|
41
|
-
private previous?: HTMLElement;
|
|
42
|
-
|
|
43
|
-
componentDidMount() {
|
|
44
|
-
const node = this.current;
|
|
45
|
-
const { $component, $context, innerProps } = this.props;
|
|
46
|
-
const { mount } = $component;
|
|
47
|
-
|
|
48
|
-
if (node && isfunc(mount)) {
|
|
49
|
-
mount(node, innerProps, $context);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.previous = node;
|
|
53
|
-
}
|
|
8
|
+
function getWrapper(wrappers: Record<string, React.ComponentType<any>>, wrapperType: string) {
|
|
9
|
+
const WrapAll = wrappers['*'];
|
|
10
|
+
const WrapType = wrappers[wrapperType];
|
|
54
11
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (current !== previous) {
|
|
61
|
-
previous && this.componentWillUnmount();
|
|
62
|
-
current && this.componentDidMount();
|
|
63
|
-
} else if (isfunc(update)) {
|
|
64
|
-
update(current, innerProps, $context);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
componentWillUnmount() {
|
|
69
|
-
const node = this.previous;
|
|
70
|
-
const { $component } = this.props;
|
|
71
|
-
const { unmount } = $component;
|
|
72
|
-
|
|
73
|
-
if (node && isfunc(unmount)) {
|
|
74
|
-
unmount(node);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.previous = undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
render() {
|
|
81
|
-
const { $portalId } = this.props;
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<div
|
|
85
|
-
data-portal-id={$portalId}
|
|
86
|
-
ref={(node) => {
|
|
87
|
-
this.current = node;
|
|
88
|
-
}}
|
|
89
|
-
/>
|
|
12
|
+
if (WrapAll && WrapType) {
|
|
13
|
+
return (props) => (
|
|
14
|
+
<WrapAll {...props}>
|
|
15
|
+
<WrapType {...props} />
|
|
16
|
+
</WrapAll>
|
|
90
17
|
);
|
|
91
18
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function wrapReactComponent<T>(
|
|
95
|
-
Component: React.ComponentType<T & BaseComponentProps>,
|
|
96
|
-
stasisOptions: ErrorBoundaryOptions<T>,
|
|
97
|
-
piral: PiletApi,
|
|
98
|
-
Wrapper: React.ComponentType<any>,
|
|
99
|
-
): React.ComponentType<T> {
|
|
100
|
-
return (props: T) => (
|
|
101
|
-
<Wrapper {...props} piral={piral}>
|
|
102
|
-
<ErrorBoundary {...stasisOptions} renderProps={props}>
|
|
103
|
-
<Component {...props} piral={piral} />
|
|
104
|
-
</ErrorBoundary>
|
|
105
|
-
</Wrapper>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function wrapForeignComponent<T>(
|
|
110
|
-
component: ForeignComponent<T & BaseComponentProps>,
|
|
111
|
-
stasisOptions: ErrorBoundaryOptions<T>,
|
|
112
|
-
piral: PiletApi,
|
|
113
|
-
Wrapper: React.ComponentType<any>,
|
|
114
|
-
): React.ComponentType<T> {
|
|
115
|
-
return (props: T) => {
|
|
116
|
-
const { destroyPortal } = useActions();
|
|
117
|
-
const [id] = React.useState(() => (portalIdBase++).toString(26));
|
|
118
|
-
const router = React.useContext(__RouterContext);
|
|
119
|
-
const { state } = React.useContext(StateContext);
|
|
120
|
-
const innerProps = { ...props, piral };
|
|
121
|
-
|
|
122
|
-
React.useEffect(() => () => destroyPortal(id), []);
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<Wrapper {...innerProps}>
|
|
126
|
-
<ErrorBoundary {...stasisOptions} renderProps={props}>
|
|
127
|
-
<PortalRenderer id={id} />
|
|
128
|
-
<ForeignComponentContainer
|
|
129
|
-
innerProps={innerProps}
|
|
130
|
-
$portalId={id}
|
|
131
|
-
$component={component}
|
|
132
|
-
$context={{ router, state }}
|
|
133
|
-
/>
|
|
134
|
-
</ErrorBoundary>
|
|
135
|
-
</Wrapper>
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
19
|
|
|
140
|
-
|
|
141
|
-
return !(component as React.ExoticComponent).$$typeof;
|
|
20
|
+
return WrapType || WrapAll || DefaultWrapper;
|
|
142
21
|
}
|
|
143
22
|
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
)
|
|
151
|
-
if (!component) {
|
|
152
|
-
console.error('The given value is not a valid component.');
|
|
153
|
-
// tslint:disable-next-line:no-null-keyword
|
|
154
|
-
component = () => null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (typeof component === 'object' && isNotExotic(component)) {
|
|
158
|
-
const result = convertComponent(converters[component.type], component);
|
|
159
|
-
return wrapForeignComponent<T>(result, stasisOptions, piral, Wrapper);
|
|
160
|
-
}
|
|
23
|
+
function makeWrapper<TProps>(
|
|
24
|
+
context: GlobalStateContext,
|
|
25
|
+
outerProps: any,
|
|
26
|
+
wrapperType: string,
|
|
27
|
+
errorType: keyof Errors,
|
|
28
|
+
): React.FC<React.PropsWithChildren<TProps>> {
|
|
29
|
+
const OuterWrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
|
|
161
30
|
|
|
162
|
-
return
|
|
31
|
+
return (props) => (
|
|
32
|
+
<OuterWrapper {...outerProps} {...props}>
|
|
33
|
+
<ErrorBoundary {...outerProps} {...props} errorType={errorType}>
|
|
34
|
+
{props.children}
|
|
35
|
+
</ErrorBoundary>
|
|
36
|
+
</OuterWrapper>
|
|
37
|
+
);
|
|
163
38
|
}
|
|
164
39
|
|
|
165
40
|
export function withApi<TProps>(
|
|
@@ -168,19 +43,10 @@ export function withApi<TProps>(
|
|
|
168
43
|
piral: PiletApi,
|
|
169
44
|
errorType: keyof Errors,
|
|
170
45
|
wrapperType: string = errorType,
|
|
46
|
+
captured = {},
|
|
171
47
|
) {
|
|
48
|
+
const outerProps = { ...captured, piral };
|
|
172
49
|
const converters = context.converters;
|
|
173
|
-
const Wrapper = context
|
|
174
|
-
|
|
175
|
-
return wrapComponent<TProps>(converters, component, piral, Wrapper, {
|
|
176
|
-
onError(error) {
|
|
177
|
-
console.error(piral, error);
|
|
178
|
-
},
|
|
179
|
-
renderChild(child) {
|
|
180
|
-
return <React.Suspense fallback={<PiralLoadingIndicator />}>{child}</React.Suspense>;
|
|
181
|
-
},
|
|
182
|
-
renderError(error, props: any) {
|
|
183
|
-
return <PiralError type={errorType} error={error} {...props} />;
|
|
184
|
-
},
|
|
185
|
-
});
|
|
50
|
+
const Wrapper = makeWrapper<TProps>(context, outerProps, wrapperType, errorType);
|
|
51
|
+
return wrapComponent(converters, component, outerProps, Wrapper);
|
|
186
52
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// this file is bundled, so the references here will not be at runtime (i.e., for a user)
|
|
2
|
+
import { getModulePath } from 'piral-cli/src/external/resolve';
|
|
3
|
+
|
|
4
|
+
function getRouterVersion(root: string) {
|
|
5
|
+
const router = 'react-router';
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const modulePath = getModulePath(root, `${router}/package.json`);
|
|
9
|
+
const { version } = require(modulePath);
|
|
10
|
+
const [major] = version.split('.');
|
|
11
|
+
return parseInt(major, 10);
|
|
12
|
+
} catch {
|
|
13
|
+
console.warn(`⚠ Could not determine version of ${router}. Falling back to v5.`);
|
|
14
|
+
return 5;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getIdentifiers(root: string, packageName: string) {
|
|
19
|
+
const packageJson = `${packageName}/package.json`;
|
|
20
|
+
const identifiers = [packageName];
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const modulePath = getModulePath(root, packageJson);
|
|
24
|
+
const details = require(modulePath);
|
|
25
|
+
|
|
26
|
+
if (details.version) {
|
|
27
|
+
identifiers.push(`${packageName}@${details.version}`);
|
|
28
|
+
|
|
29
|
+
if (details.name !== packageName) {
|
|
30
|
+
identifiers.push(`${details.name}@${details.version}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch {}
|
|
34
|
+
|
|
35
|
+
return identifiers;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getModulePathOrDefault(root: string, name: string) {
|
|
39
|
+
try {
|
|
40
|
+
return getModulePath(root, name);
|
|
41
|
+
} catch {
|
|
42
|
+
return name;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface CodegenOptions {
|
|
47
|
+
root: string;
|
|
48
|
+
cat: string;
|
|
49
|
+
appName: string;
|
|
50
|
+
externals: Array<string>;
|
|
51
|
+
publicPath: string;
|
|
52
|
+
debug?: {
|
|
53
|
+
viewState?: boolean;
|
|
54
|
+
loadPilets?: boolean;
|
|
55
|
+
hardRefresh?: boolean;
|
|
56
|
+
viewOrigins?: boolean;
|
|
57
|
+
extensionCatalogue?: boolean;
|
|
58
|
+
clearConsole?: boolean;
|
|
59
|
+
};
|
|
60
|
+
emulator: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createDependencies(imports: Array<string>, exports: Array<string>, opts: CodegenOptions) {
|
|
64
|
+
const { root, appName, externals } = opts;
|
|
65
|
+
const assignments: Array<string> = [];
|
|
66
|
+
|
|
67
|
+
if (appName) {
|
|
68
|
+
assignments.push(`deps['${appName}']={}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const name of externals) {
|
|
72
|
+
const identifiers = getIdentifiers(root, name);
|
|
73
|
+
const path = getModulePathOrDefault(root, name);
|
|
74
|
+
const ref = `_${imports.length}`;
|
|
75
|
+
imports.push(`import * as ${ref} from ${JSON.stringify(path)}`);
|
|
76
|
+
|
|
77
|
+
for (const id of identifiers) {
|
|
78
|
+
assignments.push(`deps[${JSON.stringify(id)}]=${ref}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.push(`
|
|
83
|
+
export function fillDependencies(deps) {
|
|
84
|
+
${assignments.join(';')}
|
|
85
|
+
}
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function createDefaultState(imports: Array<string>, exports: Array<string>, opts: CodegenOptions) {
|
|
90
|
+
const { root, cat, publicPath } = opts;
|
|
91
|
+
const routerVersion = getRouterVersion(root);
|
|
92
|
+
|
|
93
|
+
imports.push(
|
|
94
|
+
`import { DefaultErrorInfo } from 'piral-core/${cat}/defaults/DefaultErrorInfo';`,
|
|
95
|
+
`import { DefaultLoadingIndicator } from 'piral-core/${cat}/defaults/DefaultLoadingIndicator';`,
|
|
96
|
+
`import { DefaultLayout } from 'piral-core/${cat}/defaults/DefaultLayout';`,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (routerVersion < 6) {
|
|
100
|
+
imports.push(
|
|
101
|
+
`import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v5';`,
|
|
102
|
+
`import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v5';`,
|
|
103
|
+
`import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v5'`,
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
imports.push(
|
|
107
|
+
`import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v6';`,
|
|
108
|
+
`import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v6';`,
|
|
109
|
+
`import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v6'`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.push(`
|
|
114
|
+
export { createRedirect, createNavigation, useRouterContext };
|
|
115
|
+
`);
|
|
116
|
+
|
|
117
|
+
exports.push(`
|
|
118
|
+
export const publicPath = ${JSON.stringify(publicPath)};
|
|
119
|
+
`);
|
|
120
|
+
|
|
121
|
+
exports.push(`
|
|
122
|
+
export function createDefaultState() {
|
|
123
|
+
return {
|
|
124
|
+
app: {
|
|
125
|
+
error: undefined,
|
|
126
|
+
loading: typeof window !== 'undefined',
|
|
127
|
+
},
|
|
128
|
+
components: {
|
|
129
|
+
ErrorInfo: DefaultErrorInfo,
|
|
130
|
+
LoadingIndicator: DefaultLoadingIndicator,
|
|
131
|
+
Router: DefaultRouter,
|
|
132
|
+
RouteSwitch: DefaultRouteSwitch,
|
|
133
|
+
Layout: DefaultLayout,
|
|
134
|
+
},
|
|
135
|
+
errorComponents: {},
|
|
136
|
+
registry: {
|
|
137
|
+
extensions: {},
|
|
138
|
+
pages: {},
|
|
139
|
+
wrappers: {},
|
|
140
|
+
},
|
|
141
|
+
routes: {},
|
|
142
|
+
data: {},
|
|
143
|
+
portals: {},
|
|
144
|
+
modules: [],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function createDebugHandler(imports: Array<string>, exports: Array<string>, opts: CodegenOptions) {
|
|
151
|
+
const { cat, debug, emulator } = opts;
|
|
152
|
+
|
|
153
|
+
// if we build the debug version of piral (debug and emulator build)
|
|
154
|
+
if (debug) {
|
|
155
|
+
const originalCall = `originalDebugger(context, options, { defaultSettings: ${JSON.stringify(debug)}, ...debug })`;
|
|
156
|
+
imports.push(`import { integrateDebugger as originalDebugger } from "piral-core/${cat}/tools/debugger"`);
|
|
157
|
+
exports.push(`export function integrateDebugger(context, options, debug) { return ${originalCall}; }`);
|
|
158
|
+
} else {
|
|
159
|
+
exports.push(`export function integrateDebugger() {}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// if we build the emulator version of piral (shipped to pilets)
|
|
163
|
+
if (emulator) {
|
|
164
|
+
imports.push(`import { integrateEmulator } from "piral-core/${cat}/tools/emulator"`);
|
|
165
|
+
exports.push(`export { integrateEmulator }`);
|
|
166
|
+
} else {
|
|
167
|
+
exports.push(`export function integrateEmulator() {}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function createRouteHandler(imports: Array<string>, exports: Array<string>, opts: CodegenOptions) {
|
|
172
|
+
const { cat, emulator } = opts;
|
|
173
|
+
const assignments = [];
|
|
174
|
+
|
|
175
|
+
imports.push(`import { useGlobalStateContext } from 'piral-core/${cat}/hooks/globalState';`);
|
|
176
|
+
|
|
177
|
+
assignments.push(`
|
|
178
|
+
useCurrentNavigation();
|
|
179
|
+
`);
|
|
180
|
+
|
|
181
|
+
if (emulator) {
|
|
182
|
+
imports.push(`import { useDebugRouteFilter } from 'piral-debug-utils';`);
|
|
183
|
+
assignments.push('return useDebugRouteFilter(paths);');
|
|
184
|
+
} else {
|
|
185
|
+
assignments.push('return paths;');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
exports.push(`
|
|
189
|
+
export function useRouteFilter(paths) {
|
|
190
|
+
${assignments.join('\n')}
|
|
191
|
+
}
|
|
192
|
+
`);
|
|
193
|
+
}
|