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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { defineAction, defineActions } from './define';
|
|
3
3
|
|
|
4
4
|
function createMockContainer(initialState = {}) {
|
|
5
|
-
const state =
|
|
5
|
+
const state = create(() => initialState);
|
|
6
6
|
return {
|
|
7
7
|
context: {
|
|
8
8
|
on: jest.fn(),
|
|
@@ -1,48 +1,93 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { showPortal, destroyPortal } from './portal';
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { showPortal, destroyPortal, hidePortal, updatePortal } from './portal';
|
|
4
4
|
|
|
5
5
|
describe('Piral-Core portal actions', () => {
|
|
6
|
-
it('
|
|
6
|
+
it('destroyPortal removes a portal', () => {
|
|
7
|
+
const children = React.createElement('div');
|
|
8
|
+
const portal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
9
|
+
|
|
10
|
+
const state = create(() => ({
|
|
11
|
+
portals: { test: { portal } },
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const ctx: any = {
|
|
15
|
+
state,
|
|
16
|
+
dispatch(update) {
|
|
17
|
+
state.setState(update(state.getState()));
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
destroyPortal(ctx, 'test');
|
|
22
|
+
const { portals } = ctx.state.getState();
|
|
23
|
+
expect(portals).not.toBeNull();
|
|
24
|
+
expect(portals.test).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('hidePortal hides a portal', () => {
|
|
7
28
|
const children = React.createElement('div');
|
|
8
29
|
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
9
30
|
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
10
31
|
|
|
11
|
-
const state =
|
|
32
|
+
const state = create(() => ({
|
|
12
33
|
portals: { p1: { portal } },
|
|
13
|
-
});
|
|
34
|
+
}));
|
|
14
35
|
|
|
15
36
|
const ctx: any = {
|
|
16
37
|
state,
|
|
17
38
|
dispatch(update) {
|
|
18
|
-
|
|
39
|
+
state.setState(update(state.getState()));
|
|
19
40
|
},
|
|
20
41
|
};
|
|
21
42
|
|
|
22
|
-
|
|
23
|
-
const { portals } =
|
|
43
|
+
hidePortal(ctx, 'test', newPortal);
|
|
44
|
+
const { portals } = ctx.state.getState();
|
|
24
45
|
expect(portals).not.toBeNull();
|
|
25
46
|
expect(portals.test).not.toBeNull();
|
|
26
47
|
});
|
|
27
48
|
|
|
28
|
-
it('
|
|
49
|
+
it('updatePortal updates a portal', () => {
|
|
29
50
|
const children = React.createElement('div');
|
|
30
|
-
const
|
|
51
|
+
const current: React.ReactPortal = { key: 'current', children: { children }, type: 'div', props: null };
|
|
52
|
+
const next: React.ReactPortal = { key: 'next', children: { children }, type: 'div', props: null };
|
|
53
|
+
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
31
54
|
|
|
32
|
-
const state =
|
|
33
|
-
portals: {
|
|
34
|
-
});
|
|
55
|
+
const state = create(() => ({
|
|
56
|
+
portals: { p1: { portal } },
|
|
57
|
+
}));
|
|
35
58
|
|
|
36
59
|
const ctx: any = {
|
|
37
60
|
state,
|
|
38
61
|
dispatch(update) {
|
|
39
|
-
|
|
62
|
+
state.setState(update(state.getState()));
|
|
40
63
|
},
|
|
41
64
|
};
|
|
42
65
|
|
|
43
|
-
|
|
44
|
-
const { portals } =
|
|
66
|
+
updatePortal(ctx, 'test', current, next);
|
|
67
|
+
const { portals } = ctx.state.getState();
|
|
45
68
|
expect(portals).not.toBeNull();
|
|
46
|
-
expect(portals.test).
|
|
69
|
+
expect(portals.test).not.toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('showPortal adds a portal', () => {
|
|
73
|
+
const children = React.createElement('div');
|
|
74
|
+
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
75
|
+
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
76
|
+
|
|
77
|
+
const state = create(() => ({
|
|
78
|
+
portals: { p1: { portal } },
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
const ctx: any = {
|
|
82
|
+
state,
|
|
83
|
+
dispatch(update) {
|
|
84
|
+
state.setState(update(state.getState()));
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
showPortal(ctx, 'test', newPortal);
|
|
89
|
+
const { portals } = ctx.state.getState();
|
|
90
|
+
expect(portals).not.toBeNull();
|
|
91
|
+
expect(portals.test).not.toBeNull();
|
|
47
92
|
});
|
|
48
93
|
});
|
package/src/actions/portal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactPortal } from 'react';
|
|
2
|
-
import { withoutKey, includeItem,
|
|
2
|
+
import { withoutKey, withKey, includeItem, excludeItem, replaceOrAddItem } from '../utils';
|
|
3
3
|
import { GlobalStateContext } from '../types';
|
|
4
4
|
|
|
5
5
|
export function destroyPortal(ctx: GlobalStateContext, id: string) {
|
|
@@ -9,6 +9,24 @@ export function destroyPortal(ctx: GlobalStateContext, id: string) {
|
|
|
9
9
|
}));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export function hidePortal(ctx: GlobalStateContext, id: string, entry: ReactPortal) {
|
|
13
|
+
ctx.dispatch((state) => ({
|
|
14
|
+
...state,
|
|
15
|
+
portals: withKey(state.portals, id, excludeItem(state.portals[id], entry)),
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function updatePortal(ctx: GlobalStateContext, id: string, current: ReactPortal, next: ReactPortal) {
|
|
20
|
+
ctx.dispatch((state) => ({
|
|
21
|
+
...state,
|
|
22
|
+
portals: withKey(
|
|
23
|
+
state.portals,
|
|
24
|
+
id,
|
|
25
|
+
replaceOrAddItem(state.portals[id], next, (m) => m === current),
|
|
26
|
+
),
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
export function showPortal(ctx: GlobalStateContext, id: string, entry: ReactPortal) {
|
|
13
31
|
ctx.dispatch((state) => ({
|
|
14
32
|
...state,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { readState, dispatch } from './state';
|
|
3
3
|
|
|
4
4
|
function createMockContainer(initialState = {}) {
|
|
5
|
-
const state =
|
|
5
|
+
const state = create(() => initialState);
|
|
6
6
|
return {
|
|
7
7
|
context: {
|
|
8
8
|
on: jest.fn(),
|
|
@@ -11,7 +11,7 @@ function createMockContainer(initialState = {}) {
|
|
|
11
11
|
defineActions() {},
|
|
12
12
|
state,
|
|
13
13
|
read() {
|
|
14
|
-
return
|
|
14
|
+
return state.getState();
|
|
15
15
|
},
|
|
16
16
|
} as any,
|
|
17
17
|
};
|
package/src/actions/state.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isSame } from '../utils';
|
|
2
2
|
import { GlobalState, GlobalStateContext } from '../types';
|
|
3
3
|
|
|
4
4
|
export function dispatch(ctx: GlobalStateContext, update: (state: GlobalState) => GlobalState) {
|
|
5
|
-
|
|
5
|
+
const oldState = ctx.state.getState();
|
|
6
|
+
const newState = update(oldState);
|
|
7
|
+
|
|
8
|
+
if (!isSame(oldState, newState)) {
|
|
9
|
+
ctx.state.setState(newState);
|
|
10
|
+
}
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
export function readState<S>(ctx: GlobalStateContext, read: (state: GlobalState) => S) {
|
|
9
|
-
|
|
10
|
-
return read(state);
|
|
14
|
+
return read(ctx.state.getState());
|
|
11
15
|
}
|
|
@@ -1,42 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { RegisteredErrorInfo, RegisteredLoadingIndicator } from './components';
|
|
3
|
+
import { Errors, PiletApi } from '../types';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
* The options to be used for determining the boundary's behavior.
|
|
6
|
-
*/
|
|
7
|
-
export interface ErrorBoundaryOptions<T> {
|
|
8
|
-
/**
|
|
9
|
-
* Callback to be used in case of an emitted error.
|
|
10
|
-
* @param error The error caught by the boundary.
|
|
11
|
-
*/
|
|
12
|
-
onError(error: Error): void;
|
|
5
|
+
export interface ErrorBoundaryProps {
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param error The error caught by the boundary.
|
|
16
|
-
* @param props The props used by the boundary.
|
|
7
|
+
* The type of error to indicate when caught.
|
|
17
8
|
*/
|
|
18
|
-
|
|
9
|
+
errorType: keyof Errors;
|
|
19
10
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param children The standard children to render.
|
|
22
|
-
* @param props The props used by the boundary.
|
|
11
|
+
* The associated pilet api for the metadata.
|
|
23
12
|
*/
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The props of the ErrorBoundary component.
|
|
29
|
-
*/
|
|
30
|
-
export interface ErrorBoundaryProps<T> extends ErrorBoundaryOptions<T> {
|
|
13
|
+
piral: PiletApi;
|
|
31
14
|
/**
|
|
32
|
-
* The render
|
|
15
|
+
* The content to render (i.e., where to apply the boundary to).
|
|
33
16
|
*/
|
|
34
|
-
|
|
17
|
+
children: React.ReactNode;
|
|
35
18
|
}
|
|
36
19
|
|
|
37
|
-
/**
|
|
38
|
-
* The state of the ErrorBoundary component.
|
|
39
|
-
*/
|
|
40
20
|
export interface ErrorBoundaryState {
|
|
41
21
|
/**
|
|
42
22
|
* The current error (if any) caught by the boundary.
|
|
@@ -45,22 +25,17 @@ export interface ErrorBoundaryState {
|
|
|
45
25
|
}
|
|
46
26
|
|
|
47
27
|
/**
|
|
48
|
-
* The
|
|
28
|
+
* The component for catching errors and displaying error information.
|
|
49
29
|
*/
|
|
50
|
-
export class ErrorBoundary
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
error: undefined,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
30
|
+
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
31
|
+
state = {
|
|
32
|
+
error: undefined,
|
|
33
|
+
};
|
|
57
34
|
|
|
58
35
|
componentDidCatch(error: Error) {
|
|
59
|
-
const {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
onError(error);
|
|
63
|
-
}
|
|
36
|
+
const { piral, errorType } = this.props;
|
|
37
|
+
const pilet = piral.meta.name;
|
|
38
|
+
console.error(`[${pilet}] Exception in component of type "${errorType}".`, error);
|
|
64
39
|
|
|
65
40
|
this.setState({
|
|
66
41
|
error,
|
|
@@ -68,17 +43,15 @@ export class ErrorBoundary<T> extends React.Component<ErrorBoundaryProps<T>, Err
|
|
|
68
43
|
}
|
|
69
44
|
|
|
70
45
|
render() {
|
|
71
|
-
const { children,
|
|
46
|
+
const { children, piral, errorType, ...renderProps } = this.props;
|
|
72
47
|
const { error } = this.state;
|
|
48
|
+
const rest: any = renderProps;
|
|
73
49
|
|
|
74
50
|
if (error) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return <div style={{ whiteSpace: 'pre-wrap' }}>{error && error.message}</div>;
|
|
51
|
+
const pilet = piral.meta.name;
|
|
52
|
+
return <RegisteredErrorInfo type={errorType} error={error} pilet={pilet} {...rest} />;
|
|
80
53
|
}
|
|
81
54
|
|
|
82
|
-
return
|
|
55
|
+
return <React.Suspense fallback={<RegisteredLoadingIndicator />}>{children}</React.Suspense>;
|
|
83
56
|
}
|
|
84
57
|
}
|
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
3
|
import { ExtensionSlot } from './ExtensionSlot';
|
|
4
4
|
|
|
5
5
|
jest.mock('../hooks/globalState', () => ({
|
|
6
|
-
useGlobalState(select: any)
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
useGlobalState: (select: any) => select(state),
|
|
7
|
+
useGlobalStateContext: () => ({
|
|
8
|
+
converters: {
|
|
9
|
+
html: ({ component }) => component,
|
|
10
|
+
},
|
|
11
|
+
apis: {
|
|
12
|
+
_: {
|
|
13
|
+
meta: {
|
|
14
|
+
name: 'PiletName',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
navigation: {
|
|
19
|
+
router: undefined,
|
|
20
|
+
},
|
|
21
|
+
readState() {
|
|
22
|
+
return '/';
|
|
23
|
+
},
|
|
24
|
+
destroyPortal: jest.fn(),
|
|
25
|
+
}),
|
|
9
26
|
}));
|
|
10
27
|
|
|
11
|
-
|
|
28
|
+
(React as any).useMemo = (cb) => cb();
|
|
29
|
+
|
|
30
|
+
const StubComponent1: React.FC<any> = (props) => <div role="stub1" children={props.children} />;
|
|
12
31
|
StubComponent1.displayName = 'StubComponent1';
|
|
13
32
|
|
|
14
|
-
const StubComponent2: React.FC = (props) => <div children={props.children} />;
|
|
33
|
+
const StubComponent2: React.FC<any> = (props) => <div role="stub2" children={props.children} />;
|
|
15
34
|
StubComponent2.displayName = 'StubComponent2';
|
|
16
35
|
|
|
36
|
+
const StubComponent3: React.FC<any> = (props) => <div role="stub3" children={props.children} />;
|
|
37
|
+
|
|
17
38
|
const state = {
|
|
39
|
+
portals: {},
|
|
18
40
|
registry: {
|
|
19
41
|
extensions: {
|
|
20
42
|
foo: [],
|
|
@@ -29,62 +51,125 @@ const state = {
|
|
|
29
51
|
component: StubComponent2,
|
|
30
52
|
},
|
|
31
53
|
],
|
|
54
|
+
bla: [
|
|
55
|
+
{
|
|
56
|
+
component: StubComponent3,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
lol: [
|
|
60
|
+
{
|
|
61
|
+
component: StubComponent1,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
32
64
|
},
|
|
33
65
|
},
|
|
34
66
|
};
|
|
35
67
|
|
|
36
|
-
(React as any).useMemo = (cb) => cb();
|
|
37
|
-
|
|
38
68
|
describe('Extension Module', () => {
|
|
69
|
+
it('is able to default render not available extension with no name', () => {
|
|
70
|
+
const node = render(<ExtensionSlot />);
|
|
71
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
72
|
+
expect(node.container.querySelectorAll('div').length).toBe(0);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('is able to default render given component with no name', () => {
|
|
76
|
+
const component = {
|
|
77
|
+
type: 'html',
|
|
78
|
+
component: {
|
|
79
|
+
mount(element) {
|
|
80
|
+
const container = document.createElement('strong');
|
|
81
|
+
container.textContent = 'Hello!';
|
|
82
|
+
element.appendChild(container);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const node = render(<ExtensionSlot params={{ component }} />);
|
|
87
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
88
|
+
expect(node.container.querySelectorAll('strong').length).toBe(1);
|
|
89
|
+
expect(node.container.textContent).toContain('Hello!');
|
|
90
|
+
});
|
|
91
|
+
|
|
39
92
|
it('is able to default render not available extension', () => {
|
|
40
|
-
const node =
|
|
41
|
-
expect(node.
|
|
42
|
-
expect(node.find(StubComponent1).length).toBe(0);
|
|
93
|
+
const node = render(<ExtensionSlot name="qxz" />);
|
|
94
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
43
95
|
});
|
|
44
96
|
|
|
45
97
|
it('is able to (default) render empty extension', () => {
|
|
46
|
-
const node =
|
|
47
|
-
expect(node.
|
|
48
|
-
expect(node.find(StubComponent1).length).toBe(0);
|
|
98
|
+
const node = render(<ExtensionSlot name="foo" />);
|
|
99
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
49
100
|
});
|
|
50
101
|
|
|
51
102
|
it('is able to custom render not available extension', () => {
|
|
52
|
-
const node =
|
|
53
|
-
expect(node.
|
|
103
|
+
const node = render(<ExtensionSlot name="qxz" render={() => <StubComponent1 />} />);
|
|
104
|
+
expect(node.queryAllByRole("stub1").length).toBe(1);
|
|
54
105
|
});
|
|
55
106
|
|
|
56
107
|
it('is able to (custom) render empty extension', () => {
|
|
57
|
-
const node =
|
|
58
|
-
expect(node.
|
|
108
|
+
const node = render(<ExtensionSlot name="foo" render={() => <StubComponent1 />} />);
|
|
109
|
+
expect(node.queryAllByRole("stub1").length).toBe(1);
|
|
59
110
|
});
|
|
60
111
|
|
|
61
112
|
it('is able to render extension with multiple entries', () => {
|
|
62
|
-
const node =
|
|
63
|
-
expect(node.
|
|
64
|
-
expect(node.
|
|
113
|
+
const node = render(<ExtensionSlot name="bar" />);
|
|
114
|
+
expect(node.queryAllByRole("stub1").length).toBe(2);
|
|
115
|
+
expect(node.queryAllByRole("stub2").length).toBe(1);
|
|
116
|
+
expect(node.queryAllByRole("stub3").length).toBe(0);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('is able to render extension without displayName', () => {
|
|
120
|
+
const node = render(<ExtensionSlot name="bla" />);
|
|
121
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
122
|
+
expect(node.queryAllByRole("stub2").length).toBe(0);
|
|
123
|
+
expect(node.queryAllByRole("stub3").length).toBe(1);
|
|
65
124
|
});
|
|
66
125
|
|
|
67
126
|
it('overrides the empty renderer on not available extension', () => {
|
|
68
|
-
const node =
|
|
69
|
-
expect(node.
|
|
70
|
-
expect(node.
|
|
127
|
+
const node = render(<ExtensionSlot name="qxz" empty={() => <StubComponent1 key="empty" />} />);
|
|
128
|
+
expect(node.queryAllByRole("stub1").length).toBe(1);
|
|
129
|
+
expect(node.queryAllByRole("stub2").length).toBe(0);
|
|
71
130
|
});
|
|
72
131
|
|
|
73
132
|
it('overrides the empty renderer on an available extension', () => {
|
|
74
|
-
const node =
|
|
75
|
-
expect(node.
|
|
76
|
-
expect(node.
|
|
133
|
+
const node = render(<ExtensionSlot name="foo" empty={() => <StubComponent2 key="empty" />} />);
|
|
134
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
135
|
+
expect(node.queryAllByRole("stub2").length).toBe(1);
|
|
77
136
|
});
|
|
78
137
|
|
|
79
138
|
it('overrides the empty and default renderer on an available extension', () => {
|
|
80
|
-
const node =
|
|
139
|
+
const node = render(
|
|
140
|
+
<ExtensionSlot
|
|
141
|
+
name="foo"
|
|
142
|
+
empty={() => <StubComponent2 key="empty" />}
|
|
143
|
+
render={(nodes) => <StubComponent1 children={nodes} />}
|
|
144
|
+
/>,
|
|
145
|
+
);
|
|
146
|
+
expect(node.queryAllByRole("stub1").length).toBe(1);
|
|
147
|
+
expect(node.queryAllByRole("stub2").length).toBe(1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('does not use the render function with empty when emptySkipsRender is set', () => {
|
|
151
|
+
const node = render(
|
|
81
152
|
<ExtensionSlot
|
|
82
153
|
name="foo"
|
|
154
|
+
emptySkipsRender
|
|
155
|
+
empty={() => <StubComponent2 key="empty" />}
|
|
156
|
+
render={(nodes) => <StubComponent1 children={nodes} />}
|
|
157
|
+
/>,
|
|
158
|
+
);
|
|
159
|
+
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
160
|
+
expect(node.queryAllByRole("stub2").length).toBe(1);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('does use the render function without empty independent if emptySkipsRender is set', () => {
|
|
164
|
+
const node = render(
|
|
165
|
+
<ExtensionSlot
|
|
166
|
+
name="lol"
|
|
167
|
+
emptySkipsRender
|
|
83
168
|
empty={() => <StubComponent2 key="empty" />}
|
|
84
169
|
render={(nodes) => <StubComponent1 children={nodes} />}
|
|
85
170
|
/>,
|
|
86
171
|
);
|
|
87
|
-
expect(node.
|
|
88
|
-
expect(node.
|
|
172
|
+
expect(node.queryAllByRole("stub1").length).toBe(2);
|
|
173
|
+
expect(node.queryAllByRole("stub2").length).toBe(0);
|
|
89
174
|
});
|
|
90
175
|
});
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { isfunc } from 'piral-base';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { wrapComponent } from './wrapComponent';
|
|
4
|
+
import { useGlobalState, useGlobalStateContext } from '../hooks';
|
|
5
|
+
import { defaultRender, none } from '../utils';
|
|
6
|
+
import { ExtensionRegistration, ExtensionSlotProps } from '../types';
|
|
7
|
+
|
|
8
|
+
const wrapper = ({ children }) => defaultRender(children);
|
|
9
|
+
|
|
10
|
+
const renderExtensions: [ExtensionRegistration] = [
|
|
11
|
+
{
|
|
12
|
+
component: (props) => {
|
|
13
|
+
const context = useGlobalStateContext();
|
|
14
|
+
const converters = context.converters;
|
|
15
|
+
const piral = context.apis._;
|
|
16
|
+
const { component, props: args } = props.params;
|
|
17
|
+
const Component = React.useMemo(() => wrapComponent(converters, component, { piral }, wrapper), [component]);
|
|
18
|
+
return <Component {...args} />;
|
|
19
|
+
},
|
|
20
|
+
defaults: {},
|
|
21
|
+
pilet: '',
|
|
22
|
+
reference: {
|
|
23
|
+
displayName: 'AnyComponent',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function defaultOrder(extensions: Array<ExtensionRegistration>) {
|
|
29
|
+
return extensions;
|
|
30
|
+
}
|
|
6
31
|
|
|
7
32
|
/**
|
|
8
33
|
* The extension slot component to be used when the available
|
|
@@ -10,21 +35,35 @@ import { ExtensionSlotProps } from '../types';
|
|
|
10
35
|
* location.
|
|
11
36
|
*/
|
|
12
37
|
export function ExtensionSlot<T extends string>(props: ExtensionSlotProps<T>) {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
const {
|
|
39
|
+
name,
|
|
40
|
+
render = defaultRender,
|
|
41
|
+
empty,
|
|
42
|
+
params,
|
|
43
|
+
children,
|
|
44
|
+
emptySkipsRender = false,
|
|
45
|
+
order = defaultOrder,
|
|
46
|
+
} = props;
|
|
47
|
+
const extensions = useGlobalState((s) => (name ? s.registry.extensions[name] || none : renderExtensions));
|
|
48
|
+
const isEmpty = extensions.length === 0 && isfunc(empty);
|
|
49
|
+
const content = isEmpty
|
|
50
|
+
? [defaultRender(empty(), 'empty')]
|
|
51
|
+
: order(extensions).map(({ component: Component, reference, defaults = {} }, i) => (
|
|
52
|
+
<Component
|
|
53
|
+
key={`${reference?.displayName || '_'}${i}`}
|
|
54
|
+
children={children}
|
|
55
|
+
params={{
|
|
56
|
+
...defaults,
|
|
57
|
+
...params,
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
));
|
|
61
|
+
|
|
62
|
+
if (isEmpty && emptySkipsRender) {
|
|
63
|
+
return content[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return render(content);
|
|
28
67
|
}
|
|
29
68
|
|
|
30
69
|
ExtensionSlot.displayName = `ExtensionSlot`;
|