piral-core 1.0.0-pre.2296 → 1.0.1-beta.5640
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +12 -4
- package/app.codegen +36 -0
- package/app.codegen.d.ts +29 -0
- package/dist/codegen.js +5308 -0
- package/esm/Piral.d.ts +4 -4
- package/esm/Piral.js +8 -11
- package/esm/Piral.js.map +1 -1
- package/esm/PiralContext.d.ts +21 -0
- package/esm/PiralContext.js +34 -0
- package/esm/PiralContext.js.map +1 -0
- package/esm/RootListener.d.ts +2 -0
- package/esm/RootListener.js +23 -0
- package/esm/RootListener.js.map +1 -0
- package/esm/actions/app.d.ts +7 -4
- package/esm/actions/app.js +24 -14
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/components.js +5 -6
- package/esm/actions/components.js.map +1 -1
- package/esm/actions/data.js +16 -17
- package/esm/actions/data.js.map +1 -1
- package/esm/actions/define.js +2 -3
- package/esm/actions/define.js.map +1 -1
- package/esm/actions/portal.d.ts +2 -0
- package/esm/actions/portal.js +9 -4
- package/esm/actions/portal.js.map +1 -1
- package/esm/actions/state.js +7 -4
- package/esm/actions/state.js.map +1 -1
- package/esm/components/ErrorBoundary.d.ts +14 -31
- package/esm/components/ErrorBoundary.js +22 -28
- package/esm/components/ErrorBoundary.js.map +1 -1
- package/esm/components/ExtensionSlot.d.ts +1 -0
- package/esm/components/ExtensionSlot.js +34 -11
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/components/ForeignComponentContainer.d.ts +19 -0
- package/esm/components/ForeignComponentContainer.js +46 -0
- package/esm/components/ForeignComponentContainer.js.map +1 -0
- package/esm/components/Mediator.js +15 -12
- package/esm/components/Mediator.js.map +1 -1
- package/esm/components/PiralGlobals.d.ts +6 -0
- package/esm/components/PiralGlobals.js +13 -0
- package/esm/components/PiralGlobals.js.map +1 -0
- package/esm/components/PiralRoutes.d.ts +5 -0
- package/esm/components/PiralRoutes.js +6 -11
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/PiralSuspense.d.ts +5 -0
- package/esm/components/PiralSuspense.js +8 -0
- package/esm/components/PiralSuspense.js.map +1 -0
- package/esm/components/PiralView.d.ts +10 -1
- package/esm/components/PiralView.js +12 -25
- package/esm/components/PiralView.js.map +1 -1
- package/esm/components/PortalRenderer.d.ts +5 -0
- package/esm/components/PortalRenderer.js +7 -0
- package/esm/components/PortalRenderer.js.map +1 -0
- package/esm/components/ResponsiveLayout.d.ts +9 -1
- package/esm/components/ResponsiveLayout.js +5 -13
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/SwitchErrorInfo.js +12 -10
- package/esm/components/SwitchErrorInfo.js.map +1 -1
- package/esm/components/components.d.ts +18 -6
- package/esm/components/components.js +21 -9
- package/esm/components/components.js.map +1 -1
- package/esm/components/index.d.ts +4 -10
- package/esm/components/index.js +4 -10
- package/esm/components/index.js.map +1 -1
- package/esm/components/wrapComponent.d.ts +7 -0
- package/esm/components/wrapComponent.js +42 -0
- package/esm/components/wrapComponent.js.map +1 -0
- package/esm/createInstance.d.ts +2 -2
- package/esm/createInstance.js +34 -30
- package/esm/createInstance.js.map +1 -1
- package/esm/defaults/DefaultErrorInfo.js +10 -0
- package/esm/defaults/DefaultErrorInfo.js.map +1 -0
- package/esm/{components → defaults}/DefaultLayout.js +1 -4
- package/esm/defaults/DefaultLayout.js.map +1 -0
- package/esm/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +2 -2
- package/esm/defaults/DefaultLoadingIndicator.js.map +1 -0
- package/esm/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/esm/defaults/DefaultRouteSwitch_v5.js +11 -0
- package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/esm/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/esm/defaults/DefaultRouter_v5.d.ts +3 -0
- package/esm/defaults/DefaultRouter_v5.js +7 -0
- package/esm/defaults/DefaultRouter_v5.js.map +1 -0
- package/esm/defaults/DefaultRouter_v6.d.ts +3 -0
- package/esm/defaults/DefaultRouter_v6.js +7 -0
- package/esm/defaults/DefaultRouter_v6.js.map +1 -0
- package/esm/defaults/navigator_none.d.ts +5 -0
- package/esm/defaults/navigator_none.js +30 -0
- package/esm/defaults/navigator_none.js.map +1 -0
- package/esm/defaults/navigator_v5.d.ts +6 -0
- package/esm/defaults/navigator_v5.js +81 -0
- package/esm/defaults/navigator_v5.js.map +1 -0
- package/esm/defaults/navigator_v6.d.ts +6 -0
- package/esm/defaults/navigator_v6.js +77 -0
- package/esm/defaults/navigator_v6.js.map +1 -0
- package/esm/helpers.d.ts +12 -26
- package/esm/helpers.js +14 -72
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/action.js +2 -3
- package/esm/hooks/action.js.map +1 -1
- package/esm/hooks/actions.js +1 -1
- package/esm/hooks/actions.js.map +1 -1
- package/esm/hooks/globalState.d.ts +7 -0
- package/esm/hooks/globalState.js +10 -8
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/hooks/index.d.ts +2 -5
- package/esm/hooks/index.js +2 -5
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/media.js +8 -7
- package/esm/hooks/media.js.map +1 -1
- package/esm/hooks/piletApi.d.ts +7 -0
- package/esm/hooks/piletApi.js +14 -0
- package/esm/hooks/piletApi.js.map +1 -0
- package/esm/hooks/routes.d.ts +2 -0
- package/esm/hooks/routes.js +11 -0
- package/esm/hooks/routes.js.map +1 -0
- package/esm/hooks/setter.js +3 -2
- package/esm/hooks/setter.js.map +1 -1
- package/esm/hooks/sharedData.js +2 -2
- package/esm/hooks/sharedData.js.map +1 -1
- package/esm/index.d.ts +3 -1
- package/esm/index.js +3 -1
- package/esm/index.js.map +1 -1
- package/esm/modules/api.d.ts +2 -5
- package/esm/modules/api.js +9 -69
- package/esm/modules/api.js.map +1 -1
- package/esm/modules/core.d.ts +3 -0
- package/esm/modules/core.js +50 -0
- package/esm/modules/core.js.map +1 -0
- package/esm/modules/dependencies.d.ts +5 -6
- package/esm/modules/dependencies.js +9 -24
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/modules/element.d.ts +5 -0
- package/esm/modules/element.js +169 -0
- package/esm/modules/element.js.map +1 -0
- package/esm/modules/index.d.ts +1 -0
- package/esm/modules/index.js +1 -0
- package/esm/modules/index.js.map +1 -1
- package/esm/setters/SetComponent.js +11 -0
- package/esm/setters/SetComponent.js.map +1 -0
- package/esm/setters/SetError.js +11 -0
- package/esm/setters/SetError.js.map +1 -0
- package/esm/setters/SetErrors.js +9 -0
- package/esm/setters/SetErrors.js.map +1 -0
- package/esm/setters/SetLayout.js +9 -0
- package/esm/setters/SetLayout.js.map +1 -0
- package/esm/setters/SetProvider.js +11 -0
- package/esm/setters/SetProvider.js.map +1 -0
- package/esm/setters/SetRedirect.js +12 -0
- package/esm/setters/SetRedirect.js.map +1 -0
- package/{lib/components → esm/setters}/SetRoute.d.ts +6 -2
- package/esm/setters/SetRoute.js +11 -0
- package/esm/setters/SetRoute.js.map +1 -0
- package/esm/setters/index.d.ts +7 -0
- package/esm/setters/index.js +8 -0
- package/esm/setters/index.js.map +1 -0
- package/esm/state/createActions.d.ts +2 -2
- package/esm/state/createActions.js +8 -12
- package/esm/state/createActions.js.map +1 -1
- package/esm/state/createGlobalState.d.ts +1 -2
- package/esm/state/createGlobalState.js +9 -34
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/state/stateContext.js +1 -1
- package/esm/state/stateContext.js.map +1 -1
- package/esm/state/withApi.d.ts +1 -1
- package/esm/state/withApi.js +19 -104
- package/esm/state/withApi.js.map +1 -1
- package/esm/tools/codegen.d.ts +21 -0
- package/esm/tools/codegen.js +145 -0
- package/esm/tools/codegen.js.map +1 -0
- package/esm/tools/debugger.d.ts +4 -0
- package/esm/tools/debugger.js +54 -0
- package/esm/tools/debugger.js.map +1 -0
- package/esm/tools/emulator.d.ts +3 -0
- package/esm/tools/emulator.js +11 -0
- package/esm/tools/emulator.js.map +1 -0
- package/esm/types/api.d.ts +34 -9
- package/esm/types/common.d.ts +11 -11
- package/esm/types/components.d.ts +74 -8
- package/esm/types/config.d.ts +24 -17
- package/esm/types/data.d.ts +2 -2
- package/esm/types/extension.d.ts +31 -4
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/types/instance.d.ts +26 -4
- package/esm/types/layout.d.ts +3 -3
- package/esm/types/navigation.d.ts +94 -0
- package/esm/types/navigation.js +2 -0
- package/esm/types/navigation.js.map +1 -0
- package/esm/types/plugin.d.ts +1 -14
- package/esm/types/state.d.ts +66 -27
- package/esm/types/utils.d.ts +1 -1
- package/esm/utils/compare.d.ts +1 -1
- package/esm/utils/compare.js +24 -7
- package/esm/utils/compare.js.map +1 -1
- package/esm/utils/data.js +6 -7
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/extension.d.ts +16 -0
- package/esm/utils/extension.js +37 -0
- package/esm/utils/extension.js.map +1 -0
- package/esm/utils/foreign.d.ts +7 -2
- package/esm/utils/foreign.js +20 -9
- package/esm/utils/foreign.js.map +1 -1
- package/esm/utils/guid.js +3 -3
- package/esm/utils/guid.js.map +1 -1
- package/esm/utils/helpers.d.ts +11 -8
- package/esm/utils/helpers.js +29 -18
- package/esm/utils/helpers.js.map +1 -1
- package/esm/utils/index.d.ts +3 -1
- package/esm/utils/index.js +3 -1
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/media.js +8 -8
- package/esm/utils/media.js.map +1 -1
- package/esm/utils/state.d.ts +57 -0
- package/esm/utils/state.js +83 -0
- package/esm/utils/state.js.map +1 -0
- package/esm/utils/storage.js +13 -14
- package/esm/utils/storage.js.map +1 -1
- package/lib/Piral.d.ts +4 -4
- package/lib/Piral.js +11 -13
- package/lib/Piral.js.map +1 -1
- package/lib/PiralContext.d.ts +21 -0
- package/lib/PiralContext.js +38 -0
- package/lib/PiralContext.js.map +1 -0
- package/lib/RootListener.d.ts +2 -0
- package/lib/RootListener.js +27 -0
- package/lib/RootListener.js.map +1 -0
- package/lib/actions/app.d.ts +7 -4
- package/lib/actions/app.js +27 -16
- package/lib/actions/app.js.map +1 -1
- package/lib/actions/components.js +5 -6
- package/lib/actions/components.js.map +1 -1
- package/lib/actions/data.js +17 -18
- package/lib/actions/data.js.map +1 -1
- package/lib/actions/define.js +2 -3
- package/lib/actions/define.js.map +1 -1
- package/lib/actions/index.js +1 -1
- package/lib/actions/portal.d.ts +2 -0
- package/lib/actions/portal.js +12 -5
- package/lib/actions/portal.js.map +1 -1
- package/lib/actions/state.js +7 -4
- package/lib/actions/state.js.map +1 -1
- package/lib/components/ErrorBoundary.d.ts +14 -31
- package/lib/components/ErrorBoundary.js +23 -28
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/ExtensionSlot.d.ts +1 -0
- package/lib/components/ExtensionSlot.js +37 -14
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/ForeignComponentContainer.d.ts +19 -0
- package/lib/components/ForeignComponentContainer.js +50 -0
- package/lib/components/ForeignComponentContainer.js.map +1 -0
- package/lib/components/Mediator.js +18 -14
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/PiralGlobals.d.ts +6 -0
- package/lib/components/PiralGlobals.js +17 -0
- package/lib/components/PiralGlobals.js.map +1 -0
- package/lib/components/PiralRoutes.d.ts +5 -0
- package/lib/components/PiralRoutes.js +8 -12
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralSuspense.d.ts +5 -0
- package/lib/components/PiralSuspense.js +12 -0
- package/lib/components/PiralSuspense.js.map +1 -0
- package/lib/components/PiralView.d.ts +10 -1
- package/lib/components/PiralView.js +15 -27
- package/lib/components/PiralView.js.map +1 -1
- package/lib/components/PortalRenderer.d.ts +5 -0
- package/lib/components/PortalRenderer.js +11 -0
- package/lib/components/PortalRenderer.js.map +1 -0
- package/lib/components/ResponsiveLayout.d.ts +9 -1
- package/lib/components/ResponsiveLayout.js +7 -14
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SwitchErrorInfo.js +15 -12
- package/lib/components/SwitchErrorInfo.js.map +1 -1
- package/lib/components/components.d.ts +18 -6
- package/lib/components/components.js +24 -12
- package/lib/components/components.js.map +1 -1
- package/lib/components/index.d.ts +4 -10
- package/lib/components/index.js +5 -11
- package/lib/components/index.js.map +1 -1
- package/lib/components/wrapComponent.d.ts +7 -0
- package/lib/components/wrapComponent.js +46 -0
- package/lib/components/wrapComponent.js.map +1 -0
- package/lib/createInstance.d.ts +2 -2
- package/lib/createInstance.js +40 -36
- package/lib/createInstance.js.map +1 -1
- package/lib/defaults/DefaultErrorInfo.js +14 -0
- package/lib/defaults/DefaultErrorInfo.js.map +1 -0
- package/lib/{components → defaults}/DefaultLayout.js +3 -5
- package/lib/defaults/DefaultLayout.js.map +1 -0
- package/lib/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +4 -3
- package/lib/defaults/DefaultLoadingIndicator.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v5.js +15 -0
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v5.js +11 -0
- package/lib/defaults/DefaultRouter_v5.js.map +1 -0
- package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v6.js +11 -0
- package/lib/defaults/DefaultRouter_v6.js.map +1 -0
- package/lib/defaults/navigator_none.d.ts +5 -0
- package/lib/defaults/navigator_none.js +37 -0
- package/lib/defaults/navigator_none.js.map +1 -0
- package/lib/defaults/navigator_v5.d.ts +6 -0
- package/lib/defaults/navigator_v5.js +88 -0
- package/lib/defaults/navigator_v5.js.map +1 -0
- package/lib/defaults/navigator_v6.d.ts +6 -0
- package/lib/defaults/navigator_v6.js +84 -0
- package/lib/defaults/navigator_v6.js.map +1 -0
- package/lib/helpers.d.ts +12 -26
- package/lib/helpers.js +15 -75
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/action.js +2 -3
- package/lib/hooks/action.js.map +1 -1
- package/lib/hooks/actions.js +4 -4
- package/lib/hooks/actions.js.map +1 -1
- package/lib/hooks/globalState.d.ts +7 -0
- package/lib/hooks/globalState.js +14 -11
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/hooks/index.d.ts +2 -5
- package/lib/hooks/index.js +3 -6
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/media.js +10 -9
- package/lib/hooks/media.js.map +1 -1
- package/lib/hooks/piletApi.d.ts +7 -0
- package/lib/hooks/piletApi.js +18 -0
- package/lib/hooks/piletApi.js.map +1 -0
- package/lib/hooks/routes.d.ts +2 -0
- package/lib/hooks/routes.js +15 -0
- package/lib/hooks/routes.js.map +1 -0
- package/lib/hooks/setter.js +4 -3
- package/lib/hooks/setter.js.map +1 -1
- package/lib/hooks/sharedData.js +3 -3
- package/lib/hooks/sharedData.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/modules/api.d.ts +2 -5
- package/lib/modules/api.js +12 -75
- package/lib/modules/api.js.map +1 -1
- package/lib/modules/core.d.ts +3 -0
- package/lib/modules/core.js +54 -0
- package/lib/modules/core.js.map +1 -0
- package/lib/modules/dependencies.d.ts +5 -6
- package/lib/modules/dependencies.js +12 -27
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/modules/element.d.ts +5 -0
- package/lib/modules/element.js +173 -0
- package/lib/modules/element.js.map +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -1
- package/lib/modules/index.js.map +1 -1
- package/lib/setters/SetComponent.js +15 -0
- package/lib/setters/SetComponent.js.map +1 -0
- package/lib/setters/SetError.js +15 -0
- package/lib/setters/SetError.js.map +1 -0
- package/lib/setters/SetErrors.js +13 -0
- package/lib/setters/SetErrors.js.map +1 -0
- package/lib/setters/SetLayout.js +13 -0
- package/lib/setters/SetLayout.js.map +1 -0
- package/lib/{components → setters}/SetProvider.js +4 -5
- package/lib/setters/SetProvider.js.map +1 -0
- package/lib/setters/SetRedirect.js +16 -0
- package/lib/setters/SetRedirect.js.map +1 -0
- package/{esm/components → lib/setters}/SetRoute.d.ts +6 -2
- package/lib/setters/SetRoute.js +15 -0
- package/lib/setters/SetRoute.js.map +1 -0
- package/lib/setters/index.d.ts +7 -0
- package/lib/setters/index.js +11 -0
- package/lib/setters/index.js.map +1 -0
- package/lib/state/createActions.d.ts +2 -2
- package/lib/state/createActions.js +9 -13
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.d.ts +1 -2
- package/lib/state/createGlobalState.js +9 -34
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/index.js +1 -1
- package/lib/state/stateContext.js +1 -1
- package/lib/state/stateContext.js.map +1 -1
- package/lib/state/withApi.d.ts +1 -1
- package/lib/state/withApi.js +20 -105
- package/lib/state/withApi.js.map +1 -1
- package/lib/tools/codegen.d.ts +21 -0
- package/lib/tools/codegen.js +152 -0
- package/lib/tools/codegen.js.map +1 -0
- package/lib/tools/debugger.d.ts +4 -0
- package/lib/tools/debugger.js +58 -0
- package/lib/tools/debugger.js.map +1 -0
- package/lib/tools/emulator.d.ts +3 -0
- package/lib/tools/emulator.js +15 -0
- package/lib/tools/emulator.js.map +1 -0
- package/lib/types/api.d.ts +34 -9
- package/lib/types/common.d.ts +11 -11
- package/lib/types/components.d.ts +74 -8
- package/lib/types/config.d.ts +24 -17
- package/lib/types/data.d.ts +2 -2
- package/lib/types/extension.d.ts +31 -4
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/instance.d.ts +26 -4
- package/lib/types/layout.d.ts +3 -3
- package/lib/types/navigation.d.ts +94 -0
- package/lib/types/navigation.js +3 -0
- package/lib/types/navigation.js.map +1 -0
- package/lib/types/plugin.d.ts +1 -14
- package/lib/types/state.d.ts +66 -27
- package/lib/types/utils.d.ts +1 -1
- package/lib/utils/compare.d.ts +1 -1
- package/lib/utils/compare.js +26 -9
- package/lib/utils/compare.js.map +1 -1
- package/lib/utils/data.js +6 -7
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/extension.d.ts +16 -0
- package/lib/utils/extension.js +42 -0
- package/lib/utils/extension.js.map +1 -0
- package/lib/utils/foreign.d.ts +7 -2
- package/lib/utils/foreign.js +25 -12
- package/lib/utils/foreign.js.map +1 -1
- package/lib/utils/guid.js +3 -3
- package/lib/utils/guid.js.map +1 -1
- package/lib/utils/helpers.d.ts +11 -8
- package/lib/utils/helpers.js +31 -18
- package/lib/utils/helpers.js.map +1 -1
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +7 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/media.js +7 -7
- package/lib/utils/media.js.map +1 -1
- package/lib/utils/react.js +1 -1
- package/lib/utils/react.js.map +1 -1
- package/lib/utils/state.d.ts +57 -0
- package/lib/utils/state.js +94 -0
- package/lib/utils/state.js.map +1 -0
- package/lib/utils/storage.js +11 -12
- package/lib/utils/storage.js.map +1 -1
- package/package.json +51 -20
- package/src/Piral.test.tsx +7 -16
- package/src/Piral.tsx +12 -11
- package/src/PiralContext.tsx +43 -0
- package/src/RootListener.test.tsx +46 -0
- package/src/RootListener.tsx +26 -0
- package/src/actions/app.test.ts +114 -44
- package/src/actions/app.ts +33 -23
- package/src/actions/components.test.ts +11 -11
- package/src/actions/components.ts +5 -33
- package/src/actions/data.test.ts +50 -50
- package/src/actions/define.test.ts +2 -2
- package/src/actions/portal.test.ts +62 -17
- package/src/actions/portal.ts +19 -1
- package/src/actions/state.test.ts +3 -3
- package/src/actions/state.ts +8 -4
- package/src/components/ErrorBoundary.tsx +22 -49
- package/src/components/ExtensionSlot.test.tsx +115 -30
- package/src/components/ExtensionSlot.tsx +57 -18
- package/src/components/ForeignComponentContainer.test.tsx +100 -0
- package/src/components/ForeignComponentContainer.tsx +63 -0
- package/src/components/Mediator.test.tsx +16 -14
- package/src/components/Mediator.tsx +17 -9
- package/src/components/PiralGlobals.tsx +16 -0
- package/src/components/PiralRoutes.test.tsx +65 -57
- package/src/components/PiralRoutes.tsx +10 -17
- package/src/components/PiralSuspense.tsx +19 -0
- package/src/components/PiralView-server.test.tsx +61 -0
- package/src/components/PiralView.test.tsx +27 -26
- package/src/components/PiralView.tsx +28 -35
- package/src/components/PortalRenderer.tsx +12 -0
- package/src/components/ResponsiveLayout.test.tsx +18 -37
- package/src/components/ResponsiveLayout.tsx +18 -15
- package/src/components/SwitchErrorInfo.test.tsx +36 -0
- package/src/components/SwitchErrorInfo.tsx +5 -1
- package/src/components/components.tsx +20 -6
- package/src/components/index.ts +4 -10
- package/src/components/wrapComponent.tsx +74 -0
- package/src/createInstance.test.tsx +10 -0
- package/src/createInstance.tsx +19 -14
- package/src/{components → defaults}/DefaultErrorInfo.test.tsx +15 -18
- package/src/{components → defaults}/DefaultErrorInfo.tsx +2 -3
- package/src/defaults/DefaultLayout.test.tsx +23 -0
- package/src/defaults/DefaultLoadingIndicator.test.tsx +10 -0
- package/src/defaults/DefaultRouteSwitch_v5.tsx +15 -0
- package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
- package/src/defaults/DefaultRouter_v5.tsx +8 -0
- package/src/defaults/DefaultRouter_v6.tsx +8 -0
- package/src/defaults/navigator_none.tsx +35 -0
- package/src/defaults/navigator_v5.tsx +99 -0
- package/src/defaults/navigator_v6.tsx +96 -0
- package/src/helpers.test.tsx +30 -49
- package/src/helpers.tsx +31 -108
- package/src/hooks/action.ts +2 -3
- package/src/hooks/globalState.ts +10 -9
- package/src/hooks/index.ts +2 -5
- package/src/hooks/media.ts +2 -1
- package/src/hooks/piletApi.ts +14 -0
- package/src/hooks/routes.ts +14 -0
- package/src/hooks/setter-server.test.ts +22 -0
- package/src/hooks/setter.test.ts +18 -0
- package/src/hooks/setter.ts +2 -1
- package/src/index.tsx +3 -1
- package/src/modules/api.test.ts +15 -26
- package/src/modules/api.ts +3 -66
- package/src/modules/core.test.ts +148 -0
- package/src/modules/core.ts +52 -0
- package/src/modules/dependencies.test.ts +16 -5
- package/src/modules/dependencies.ts +13 -31
- package/src/modules/element-server.test.ts +29 -0
- package/src/modules/element.test.ts +67 -0
- package/src/modules/element.ts +212 -0
- package/src/modules/index.ts +1 -0
- package/src/{components → setters}/SetComponent.test.tsx +9 -8
- package/src/{components → setters}/SetComponent.tsx +2 -2
- package/src/{components → setters}/SetError.test.tsx +9 -8
- package/src/{components → setters}/SetError.tsx +2 -2
- package/src/{components → setters}/SetErrors.test.tsx +9 -8
- package/src/{components → setters}/SetLayout.test.tsx +9 -8
- package/src/{components → setters}/SetProvider.test.tsx +9 -8
- package/src/{components → setters}/SetProvider.tsx +2 -2
- package/src/{components → setters}/SetRedirect.test.tsx +9 -8
- package/src/{components → setters}/SetRedirect.tsx +4 -4
- package/src/{components → setters}/SetRoute.test.tsx +9 -8
- package/src/{components → setters}/SetRoute.tsx +7 -4
- package/src/setters/index.ts +7 -0
- package/src/state/createActions.test.ts +2 -2
- package/src/state/createActions.ts +5 -3
- package/src/state/createGlobalState.test.ts +55 -54
- package/src/state/createGlobalState.ts +4 -28
- package/src/state/withApi.test.tsx +87 -40
- package/src/state/withApi.tsx +31 -165
- package/src/tools/codegen.ts +193 -0
- package/src/tools/debugger.ts +84 -0
- package/src/tools/emulator.ts +13 -0
- package/src/types/api.ts +47 -10
- package/src/types/components.ts +76 -7
- package/src/types/config.ts +23 -17
- package/src/types/extension.ts +38 -5
- package/src/types/index.ts +1 -0
- package/src/types/instance.ts +28 -4
- package/src/types/navigation.ts +101 -0
- package/src/types/plugin.ts +1 -15
- package/src/types/state.ts +65 -25
- package/src/types/utils.ts +1 -1
- package/src/utils/compare.test.ts +15 -15
- package/src/utils/compare.ts +23 -3
- package/src/utils/extension.test.tsx +21 -0
- package/src/utils/extension.tsx +48 -0
- package/src/utils/foreign.test.ts +29 -11
- package/src/utils/foreign.ts +34 -7
- package/src/utils/guid.test.ts +6 -1
- package/src/utils/helpers.test.ts +52 -0
- package/src/utils/helpers.ts +22 -8
- package/src/utils/index.ts +4 -1
- package/src/utils/media-server.test.ts +13 -0
- package/src/utils/media.ts +2 -2
- package/src/utils/state.test.ts +37 -0
- package/src/utils/state.ts +131 -0
- package/dependencies.codegen +0 -9
- package/dependencies.codegen.native.js +0 -2
- package/esm/components/DefaultErrorInfo.js +0 -12
- package/esm/components/DefaultErrorInfo.js.map +0 -1
- package/esm/components/DefaultLayout.js.map +0 -1
- package/esm/components/DefaultLoader.js.map +0 -1
- package/esm/components/SetComponent.js +0 -12
- package/esm/components/SetComponent.js.map +0 -1
- package/esm/components/SetError.js +0 -12
- package/esm/components/SetError.js.map +0 -1
- package/esm/components/SetErrors.js +0 -10
- package/esm/components/SetErrors.js.map +0 -1
- package/esm/components/SetLayout.js +0 -10
- package/esm/components/SetLayout.js.map +0 -1
- package/esm/components/SetProvider.js +0 -12
- package/esm/components/SetProvider.js.map +0 -1
- package/esm/components/SetRedirect.js +0 -14
- package/esm/components/SetRedirect.js.map +0 -1
- package/esm/components/SetRoute.js +0 -12
- package/esm/components/SetRoute.js.map +0 -1
- package/esm/hooks/debounce.d.ts +0 -8
- package/esm/hooks/debounce.js +0 -18
- package/esm/hooks/debounce.js.map +0 -1
- package/esm/hooks/lockBodyScroll.d.ts +0 -6
- package/esm/hooks/lockBodyScroll.js +0 -13
- package/esm/hooks/lockBodyScroll.js.map +0 -1
- package/esm/hooks/onClickOutside.d.ts +0 -8
- package/esm/hooks/onClickOutside.js +0 -23
- package/esm/hooks/onClickOutside.js.map +0 -1
- package/esm/hooks/onScreenVisible.d.ts +0 -11
- package/esm/hooks/onScreenVisible.js +0 -28
- package/esm/hooks/onScreenVisible.js.map +0 -1
- package/esm/hooks/promise.d.ts +0 -13
- package/esm/hooks/promise.js +0 -21
- package/esm/hooks/promise.js.map +0 -1
- package/esm/utils/events.d.ts +0 -3
- package/esm/utils/events.js +0 -35
- package/esm/utils/events.js.map +0 -1
- package/lib/components/DefaultErrorInfo.js +0 -15
- package/lib/components/DefaultErrorInfo.js.map +0 -1
- package/lib/components/DefaultLayout.js.map +0 -1
- package/lib/components/DefaultLoader.js.map +0 -1
- package/lib/components/SetComponent.js +0 -16
- package/lib/components/SetComponent.js.map +0 -1
- package/lib/components/SetError.js +0 -16
- package/lib/components/SetError.js.map +0 -1
- package/lib/components/SetErrors.js +0 -14
- package/lib/components/SetErrors.js.map +0 -1
- package/lib/components/SetLayout.js +0 -14
- package/lib/components/SetLayout.js.map +0 -1
- package/lib/components/SetProvider.js.map +0 -1
- package/lib/components/SetRedirect.js +0 -18
- package/lib/components/SetRedirect.js.map +0 -1
- package/lib/components/SetRoute.js +0 -16
- package/lib/components/SetRoute.js.map +0 -1
- package/lib/hooks/debounce.d.ts +0 -8
- package/lib/hooks/debounce.js +0 -22
- package/lib/hooks/debounce.js.map +0 -1
- package/lib/hooks/lockBodyScroll.d.ts +0 -6
- package/lib/hooks/lockBodyScroll.js +0 -17
- package/lib/hooks/lockBodyScroll.js.map +0 -1
- package/lib/hooks/onClickOutside.d.ts +0 -8
- package/lib/hooks/onClickOutside.js +0 -27
- package/lib/hooks/onClickOutside.js.map +0 -1
- package/lib/hooks/onScreenVisible.d.ts +0 -11
- package/lib/hooks/onScreenVisible.js +0 -32
- package/lib/hooks/onScreenVisible.js.map +0 -1
- package/lib/hooks/promise.d.ts +0 -13
- package/lib/hooks/promise.js +0 -25
- package/lib/hooks/promise.js.map +0 -1
- package/lib/utils/events.d.ts +0 -3
- package/lib/utils/events.js +0 -39
- package/lib/utils/events.js.map +0 -1
- package/src/components/DefaultLayout.test.tsx +0 -23
- package/src/components/DefaultLoader.test.tsx +0 -10
- package/src/hooks/debounce.test.ts +0 -67
- package/src/hooks/debounce.ts +0 -19
- package/src/hooks/globalState.test.ts +0 -47
- package/src/hooks/lockBodyScroll.test.ts +0 -24
- package/src/hooks/lockBodyScroll.ts +0 -13
- package/src/hooks/onClickOutside.test.ts +0 -113
- package/src/hooks/onClickOutside.ts +0 -25
- package/src/hooks/onScreenVisible.test.ts +0 -68
- package/src/hooks/onScreenVisible.ts +0 -28
- package/src/hooks/promise.test.ts +0 -76
- package/src/hooks/promise.ts +0 -35
- package/src/utils/events.test.ts +0 -65
- package/src/utils/events.ts +0 -39
- package/esm/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
- package/esm/{components → defaults}/DefaultLayout.d.ts +0 -0
- package/esm/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
- package/esm/{components → setters}/SetComponent.d.ts +0 -0
- package/esm/{components → setters}/SetError.d.ts +0 -0
- package/esm/{components → setters}/SetErrors.d.ts +0 -0
- package/esm/{components → setters}/SetLayout.d.ts +0 -0
- package/esm/{components → setters}/SetProvider.d.ts +0 -0
- package/esm/{components → setters}/SetRedirect.d.ts +0 -0
- package/lib/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
- package/lib/{components → defaults}/DefaultLayout.d.ts +0 -0
- package/lib/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
- package/lib/{components → setters}/SetComponent.d.ts +0 -0
- package/lib/{components → setters}/SetError.d.ts +0 -0
- package/lib/{components → setters}/SetErrors.d.ts +0 -0
- package/lib/{components → setters}/SetLayout.d.ts +0 -0
- package/lib/{components → setters}/SetProvider.d.ts +0 -0
- package/lib/{components → setters}/SetRedirect.d.ts +0 -0
- package/src/{components → defaults}/DefaultLayout.tsx +1 -1
- /package/src/{components/DefaultLoader.tsx → defaults/DefaultLoadingIndicator.tsx} +0 -0
- /package/src/{components → setters}/SetErrors.tsx +0 -0
- /package/src/{components → setters}/SetLayout.tsx +0 -0
package/src/helpers.tsx
CHANGED
|
@@ -1,135 +1,58 @@
|
|
|
1
|
-
import { addChangeHandler } from '@dbeining/react-atom';
|
|
2
1
|
import {
|
|
3
2
|
PiletApiCreator,
|
|
4
3
|
LoadPiletsOptions,
|
|
5
4
|
CustomSpecLoaders,
|
|
6
5
|
DefaultLoaderConfig,
|
|
7
|
-
PiletDependencyFetcher,
|
|
8
|
-
getDependencyResolver,
|
|
9
6
|
getDefaultLoader,
|
|
10
7
|
extendLoader,
|
|
11
8
|
PiletLoader,
|
|
9
|
+
PiletLifecycleHooks,
|
|
12
10
|
} from 'piral-base';
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
PiletRequester,
|
|
18
|
-
GlobalStateContext,
|
|
19
|
-
PiletDependencyGetter,
|
|
20
|
-
PiletLoadingStrategy,
|
|
21
|
-
} from './types';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates a dependency getter that sets the shared dependencies explicitly.
|
|
25
|
-
* Overrides the potentially set shared dependencies from the Piral CLI, but
|
|
26
|
-
* keeps all global dependencies such as react, react-dom, ...
|
|
27
|
-
* @param sharedDependencies The shared dependencies to declare.
|
|
28
|
-
*/
|
|
29
|
-
export function setSharedDependencies(sharedDependencies: AvailableDependencies) {
|
|
30
|
-
const dependencies = {
|
|
31
|
-
...globalDependencies,
|
|
32
|
-
...sharedDependencies,
|
|
33
|
-
};
|
|
34
|
-
return () => dependencies;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Creates a dependency getter that extends the shared dependencies with additional dependencies.
|
|
39
|
-
* @param additionalDependencies The additional dependencies to declare.
|
|
40
|
-
*/
|
|
41
|
-
export function extendSharedDependencies(additionalDependencies: AvailableDependencies) {
|
|
42
|
-
const dependencies = {
|
|
43
|
-
...getLocalDependencies(),
|
|
44
|
-
...additionalDependencies,
|
|
45
|
-
};
|
|
46
|
-
return () => dependencies;
|
|
47
|
-
}
|
|
11
|
+
import type { DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
12
|
+
import { globalDependencies } from './modules';
|
|
13
|
+
import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, DependencySelector } from './types';
|
|
14
|
+
import { integrateDebugger, integrateEmulator } from '../app.codegen';
|
|
48
15
|
|
|
49
16
|
export interface PiletOptionsConfig {
|
|
17
|
+
context: GlobalStateContext;
|
|
18
|
+
hooks?: PiletLifecycleHooks;
|
|
19
|
+
loaders?: CustomSpecLoaders;
|
|
20
|
+
loaderConfig?: DefaultLoaderConfig;
|
|
50
21
|
availablePilets: Array<Pilet>;
|
|
51
|
-
createApi: PiletApiCreator;
|
|
52
|
-
fetchDependency: PiletDependencyFetcher;
|
|
53
|
-
getDependencies: PiletDependencyGetter;
|
|
54
22
|
strategy: PiletLoadingStrategy;
|
|
55
|
-
|
|
56
|
-
loaderConfig?: DefaultLoaderConfig;
|
|
57
|
-
loaders?: CustomSpecLoaders;
|
|
23
|
+
createApi: PiletApiCreator;
|
|
58
24
|
loadPilet: PiletLoader;
|
|
59
|
-
|
|
25
|
+
requestPilets: PiletRequester;
|
|
26
|
+
shareDependencies: DependencySelector;
|
|
27
|
+
debug?: DebuggerExtensionOptions;
|
|
60
28
|
}
|
|
61
29
|
|
|
62
30
|
export function createPiletOptions({
|
|
31
|
+
hooks,
|
|
63
32
|
context,
|
|
64
|
-
|
|
65
|
-
availablePilets,
|
|
66
|
-
fetchDependency,
|
|
67
|
-
getDependencies,
|
|
33
|
+
loaders,
|
|
68
34
|
loaderConfig,
|
|
69
|
-
|
|
35
|
+
availablePilets,
|
|
70
36
|
strategy,
|
|
71
|
-
|
|
37
|
+
createApi,
|
|
38
|
+
loadPilet,
|
|
72
39
|
requestPilets,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (process.env.DEBUG_PIRAL) {
|
|
79
|
-
const { installPiralDebug } = require('piral-debug-utils');
|
|
80
|
-
|
|
81
|
-
installPiralDebug({
|
|
82
|
-
context,
|
|
83
|
-
createApi,
|
|
84
|
-
getDependencies,
|
|
85
|
-
loadPilet,
|
|
86
|
-
requestPilets,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// we watch the state container for changes
|
|
90
|
-
addChangeHandler(context.state, 'debugging', ({ current, previous }) => {
|
|
91
|
-
const viewState = sessionStorage.getItem('dbg:view-state') !== 'off';
|
|
92
|
-
|
|
93
|
-
if (viewState) {
|
|
94
|
-
const infos = new Error().stack;
|
|
95
|
-
|
|
96
|
-
if (infos) {
|
|
97
|
-
// Chrome, Firefox, ... (full capability)
|
|
98
|
-
const action = infos.split('\n')[7].replace(/^\s+at\s+(Atom\.|Object\.)?/, '');
|
|
99
|
-
console.group(
|
|
100
|
-
`%c Piral State Change %c ${new Date().toLocaleTimeString()}`,
|
|
101
|
-
'color: gray; font-weight: lighter;',
|
|
102
|
-
'color: black; font-weight: bold;',
|
|
103
|
-
);
|
|
104
|
-
console.log('%c Previous', `color: #9E9E9E; font-weight: bold`, previous);
|
|
105
|
-
console.log('%c Action', `color: #03A9F4; font-weight: bold`, action);
|
|
106
|
-
console.log('%c Next', `color: #4CAF50; font-weight: bold`, current);
|
|
107
|
-
console.groupEnd();
|
|
108
|
-
} else {
|
|
109
|
-
// IE 11, ... (does not know colors etc.)
|
|
110
|
-
console.log('Changed state', previous, current);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (process.env.DEBUG_PILET) {
|
|
117
|
-
const { withEmulatorPilets } = require('piral-debug-utils');
|
|
118
|
-
|
|
119
|
-
requestPilets = withEmulatorPilets(requestPilets, {
|
|
120
|
-
inject: context.injectPilet,
|
|
121
|
-
createApi,
|
|
122
|
-
loadPilet,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return {
|
|
40
|
+
shareDependencies,
|
|
41
|
+
debug,
|
|
42
|
+
}: PiletOptionsConfig) {
|
|
43
|
+
const options: LoadPiletsOptions = {
|
|
44
|
+
config: loaderConfig,
|
|
127
45
|
strategy,
|
|
128
|
-
loadPilet,
|
|
46
|
+
loadPilet: extendLoader(loadPilet ?? getDefaultLoader(loaderConfig), loaders),
|
|
129
47
|
createApi,
|
|
130
|
-
getDependencies,
|
|
131
48
|
pilets: availablePilets,
|
|
132
49
|
fetchPilets: requestPilets,
|
|
133
|
-
|
|
50
|
+
hooks,
|
|
51
|
+
dependencies: shareDependencies(globalDependencies),
|
|
134
52
|
};
|
|
53
|
+
|
|
54
|
+
integrateDebugger(context, options, debug);
|
|
55
|
+
integrateEmulator(context, options, debug);
|
|
56
|
+
|
|
57
|
+
return options;
|
|
135
58
|
}
|
package/src/hooks/action.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StateContext } from '../state/stateContext';
|
|
1
|
+
import { useGlobalStateContext } from './globalState';
|
|
3
2
|
import { PiralActions, GlobalStateContext } from '../types';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -7,6 +6,6 @@ import { PiralActions, GlobalStateContext } from '../types';
|
|
|
7
6
|
* @param action The name of the action to retrieve.
|
|
8
7
|
*/
|
|
9
8
|
export function useAction<T extends keyof PiralActions>(action: T): GlobalStateContext[T] {
|
|
10
|
-
const ctx =
|
|
9
|
+
const ctx = useGlobalStateContext();
|
|
11
10
|
return ctx[action];
|
|
12
11
|
}
|
package/src/hooks/globalState.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import { useAtom, deref } from '@dbeining/react-atom';
|
|
3
2
|
import { StateContext } from '../state/stateContext';
|
|
4
3
|
import { GlobalState } from '../types';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Hook to obtain the global state context, which gives you directly
|
|
7
|
+
* all actions, state, and more of the Piral instance.
|
|
8
|
+
* If you are only interested in reading out the state, use the
|
|
9
|
+
* `useGlobalState` hook instead.
|
|
10
|
+
*/
|
|
11
|
+
export function useGlobalStateContext() {
|
|
12
|
+
return useContext(StateContext);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -25,6 +26,6 @@ export function useGlobalState(): GlobalState;
|
|
|
25
26
|
export function useGlobalState<R>(select: (state: GlobalState) => R): R;
|
|
26
27
|
|
|
27
28
|
export function useGlobalState<R>(select?: (state: GlobalState) => R) {
|
|
28
|
-
const { state } =
|
|
29
|
-
return
|
|
29
|
+
const { state: useState } = useGlobalStateContext();
|
|
30
|
+
return useState(select);
|
|
30
31
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export * from './action';
|
|
2
2
|
export * from './actions';
|
|
3
|
-
export * from './debounce';
|
|
4
3
|
export * from './globalState';
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './piletApi';
|
|
6
5
|
export * from './media';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './onScreenVisible';
|
|
9
|
-
export * from './promise';
|
|
6
|
+
export * from './routes';
|
|
10
7
|
export * from './setter';
|
|
11
8
|
export * from './sharedData';
|
package/src/hooks/media.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
+
import { none } from '../utils/helpers';
|
|
2
3
|
import { getCurrentLayout } from '../utils/media';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -17,7 +18,7 @@ export function useMedia<T>(queries: Array<string>, values: Array<T>, defaultVal
|
|
|
17
18
|
window.addEventListener('resize', handler);
|
|
18
19
|
return () => window.removeEventListener('resize', handler);
|
|
19
20
|
}
|
|
20
|
-
},
|
|
21
|
+
}, none);
|
|
21
22
|
|
|
22
23
|
return value;
|
|
23
24
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useGlobalStateContext } from "./globalState";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Uses the global state context to retrieve the pilet API stored
|
|
6
|
+
* for the root pilet. This allows interaction with the pilet API
|
|
7
|
+
* from the app shell.
|
|
8
|
+
* @returns The pilet API object of the root pilet.
|
|
9
|
+
*/
|
|
10
|
+
export function usePiletApi() {
|
|
11
|
+
const context = useGlobalStateContext();
|
|
12
|
+
const [api] = useState(() => Object.values(context.apis).shift());
|
|
13
|
+
return api;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useGlobalState } from './globalState';
|
|
2
|
+
import { useRouteFilter } from '../../app.codegen';
|
|
3
|
+
import { AppPath } from '../types';
|
|
4
|
+
|
|
5
|
+
export function useRoutes() {
|
|
6
|
+
const routes = useGlobalState((s) => s.routes);
|
|
7
|
+
const pages = useGlobalState((s) => s.registry.pages);
|
|
8
|
+
const paths: Array<AppPath> = [];
|
|
9
|
+
|
|
10
|
+
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
11
|
+
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
12
|
+
|
|
13
|
+
return useRouteFilter(paths);
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { renderToString } from 'react-dom/server';
|
|
7
|
+
import { useSetter } from './setter';
|
|
8
|
+
|
|
9
|
+
describe('UseSetter Hook Module', () => {
|
|
10
|
+
it('UseSetter', () => {
|
|
11
|
+
const cb = jest.fn();
|
|
12
|
+
|
|
13
|
+
const MyComponent = () => {
|
|
14
|
+
useSetter(cb);
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const result = renderToString(React.createElement(MyComponent));
|
|
19
|
+
expect(result).toEqual('');
|
|
20
|
+
expect(cb).toHaveBeenCalled();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, act } from '@testing-library/react';
|
|
3
|
+
import { useSetter } from './setter';
|
|
4
|
+
|
|
5
|
+
describe('UseSetter Hook Module', () => {
|
|
6
|
+
it('UseSetter', async () => {
|
|
7
|
+
const cb = jest.fn();
|
|
8
|
+
|
|
9
|
+
const MyComponent = () => {
|
|
10
|
+
useSetter(cb);
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
render(React.createElement(MyComponent));
|
|
15
|
+
await act(() => new Promise((resolve) => setTimeout(resolve, 5)));
|
|
16
|
+
expect(cb).toHaveBeenCalled();
|
|
17
|
+
});
|
|
18
|
+
});
|
package/src/hooks/setter.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect as useSideEffect } from 'react';
|
|
2
|
+
import { none } from '../utils/helpers';
|
|
2
3
|
|
|
3
4
|
function useMainEffect(cb: () => void) {
|
|
4
5
|
cb();
|
|
@@ -11,5 +12,5 @@ const useEffect = typeof window !== 'undefined' ? useSideEffect : useMainEffect;
|
|
|
11
12
|
* @param cb The callback to be invoked on mounting.
|
|
12
13
|
*/
|
|
13
14
|
export function useSetter(cb: () => void) {
|
|
14
|
-
useEffect(cb,
|
|
15
|
+
useEffect(cb, none);
|
|
15
16
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './createInstance';
|
|
2
|
-
export * from './Piral';
|
|
3
2
|
export * from './helpers';
|
|
4
3
|
export * from './components';
|
|
5
4
|
export * from './hooks';
|
|
5
|
+
export * from './setters';
|
|
6
6
|
export * from './state';
|
|
7
7
|
export * from './utils';
|
|
8
|
+
export * from './Piral';
|
|
9
|
+
export * from './PiralContext';
|
|
8
10
|
export * from './types';
|
package/src/modules/api.test.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as hooks from '../hooks';
|
|
2
1
|
import { createElement, FC } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import { defaultApiFactory } from './api';
|
|
4
3
|
|
|
5
4
|
jest.mock('../hooks');
|
|
6
5
|
|
|
@@ -22,31 +21,21 @@ function createMockContainer() {
|
|
|
22
21
|
off: jest.fn(),
|
|
23
22
|
emit: jest.fn(),
|
|
24
23
|
converters: {},
|
|
24
|
+
apis: {},
|
|
25
25
|
readState() {
|
|
26
26
|
return undefined;
|
|
27
27
|
},
|
|
28
28
|
} as any,
|
|
29
|
-
api: {} as any,
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
function createApi(container) {
|
|
34
|
-
|
|
35
|
-
return
|
|
32
|
+
function createApi(container, apis = []) {
|
|
33
|
+
const api = defaultApiFactory(container.context, apis);
|
|
34
|
+
return api(moduleMetadata);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
describe('API Module', () => {
|
|
39
|
-
it('
|
|
40
|
-
const container = createMockContainer();
|
|
41
|
-
const api = initializeApi(moduleMetadata, container.context);
|
|
42
|
-
expect(api.meta).toEqual({
|
|
43
|
-
name: moduleMetadata.name,
|
|
44
|
-
version: moduleMetadata.version,
|
|
45
|
-
hash: moduleMetadata.hash,
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('createCoreApi can register and unregister a page', () => {
|
|
38
|
+
it('defaultApiFactory can register and unregister a page', () => {
|
|
50
39
|
const container = createMockContainer();
|
|
51
40
|
container.context.registerPage = jest.fn();
|
|
52
41
|
container.context.unregisterPage = jest.fn();
|
|
@@ -59,7 +48,7 @@ describe('API Module', () => {
|
|
|
59
48
|
expect(container.context.unregisterPage.mock.calls[0][0]).toBe(container.context.registerPage.mock.calls[0][0]);
|
|
60
49
|
});
|
|
61
50
|
|
|
62
|
-
it('
|
|
51
|
+
it('defaultApiFactory can dispose a registered page', () => {
|
|
63
52
|
const container = createMockContainer();
|
|
64
53
|
container.context.registerPage = jest.fn();
|
|
65
54
|
container.context.unregisterPage = jest.fn();
|
|
@@ -72,7 +61,7 @@ describe('API Module', () => {
|
|
|
72
61
|
expect(container.context.unregisterPage.mock.calls[0][0]).toBe(container.context.registerPage.mock.calls[0][0]);
|
|
73
62
|
});
|
|
74
63
|
|
|
75
|
-
it('
|
|
64
|
+
it('defaultApiFactory can register and unregister an extension', () => {
|
|
76
65
|
const container = createMockContainer();
|
|
77
66
|
container.context.registerExtension = jest.fn();
|
|
78
67
|
container.context.unregisterExtension = jest.fn();
|
|
@@ -87,7 +76,7 @@ describe('API Module', () => {
|
|
|
87
76
|
);
|
|
88
77
|
});
|
|
89
78
|
|
|
90
|
-
it('
|
|
79
|
+
it('defaultApiFactory can dispose an registered extension', () => {
|
|
91
80
|
const container = createMockContainer();
|
|
92
81
|
container.context.registerExtension = jest.fn();
|
|
93
82
|
container.context.unregisterExtension = jest.fn();
|
|
@@ -102,7 +91,7 @@ describe('API Module', () => {
|
|
|
102
91
|
);
|
|
103
92
|
});
|
|
104
93
|
|
|
105
|
-
it('
|
|
94
|
+
it('defaultApiFactory read data by its name', () => {
|
|
106
95
|
const container = createMockContainer();
|
|
107
96
|
container.context.readDataValue = jest.fn((name) => name);
|
|
108
97
|
const api = createApi(container);
|
|
@@ -111,7 +100,7 @@ describe('API Module', () => {
|
|
|
111
100
|
expect(container.context.readDataValue).toHaveBeenCalled();
|
|
112
101
|
});
|
|
113
102
|
|
|
114
|
-
it('
|
|
103
|
+
it('defaultApiFactory write data without options shall pass, but memory should not emit events', () => {
|
|
115
104
|
const container = createMockContainer();
|
|
116
105
|
container.context.tryWriteDataItem = jest.fn(() => true);
|
|
117
106
|
const api = createApi(container);
|
|
@@ -120,7 +109,7 @@ describe('API Module', () => {
|
|
|
120
109
|
expect(container.context.emit).not.toHaveBeenCalled();
|
|
121
110
|
});
|
|
122
111
|
|
|
123
|
-
it('
|
|
112
|
+
it('defaultApiFactory write data with empty options shall pass, but memory should not emit events', () => {
|
|
124
113
|
const container = createMockContainer();
|
|
125
114
|
container.context.tryWriteDataItem = jest.fn(() => true);
|
|
126
115
|
const api = createApi(container);
|
|
@@ -129,7 +118,7 @@ describe('API Module', () => {
|
|
|
129
118
|
expect(container.context.emit).not.toHaveBeenCalled();
|
|
130
119
|
});
|
|
131
120
|
|
|
132
|
-
it('
|
|
121
|
+
it('defaultApiFactory write data by the simple option should not pass, never emitting events', () => {
|
|
133
122
|
const container = createMockContainer();
|
|
134
123
|
container.context.tryWriteDataItem = jest.fn(() => false);
|
|
135
124
|
const api = createApi(container);
|
|
@@ -138,7 +127,7 @@ describe('API Module', () => {
|
|
|
138
127
|
expect(container.context.emit).not.toHaveBeenCalled();
|
|
139
128
|
});
|
|
140
129
|
|
|
141
|
-
it('
|
|
130
|
+
it('defaultApiFactory write data by the simple option shall pass with remote', () => {
|
|
142
131
|
const container = createMockContainer();
|
|
143
132
|
container.context.tryWriteDataItem = jest.fn(() => true);
|
|
144
133
|
const api = createApi(container);
|
|
@@ -146,7 +135,7 @@ describe('API Module', () => {
|
|
|
146
135
|
expect(container.context.tryWriteDataItem).toHaveBeenCalled();
|
|
147
136
|
});
|
|
148
137
|
|
|
149
|
-
it('
|
|
138
|
+
it('defaultApiFactory write data by the object options shall pass with remote', () => {
|
|
150
139
|
const container = createMockContainer();
|
|
151
140
|
container.context.tryWriteDataItem = jest.fn(() => true);
|
|
152
141
|
const api = createApi(container);
|
package/src/modules/api.ts
CHANGED
|
@@ -1,70 +1,7 @@
|
|
|
1
|
-
import { isfunc, PiletApiCreator } from 'piral-base';
|
|
1
|
+
import { isfunc, PiletApiCreator, initializeApi, mergeApis } from 'piral-base';
|
|
2
2
|
import { __assign } from 'tslib';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createDataOptions, getDataExpiration, renderInDom } from '../utils';
|
|
6
|
-
import { PiletApi, PiletMetadata, GlobalStateContext, PiletCoreApi, PiralPlugin, PiletApiExtender } from '../types';
|
|
7
|
-
|
|
8
|
-
export function createCoreApi(context: GlobalStateContext): PiletApiExtender<PiletCoreApi> {
|
|
9
|
-
return (api, target) => {
|
|
10
|
-
const pilet = target.name;
|
|
11
|
-
return {
|
|
12
|
-
getData(name) {
|
|
13
|
-
return context.readDataValue(name);
|
|
14
|
-
},
|
|
15
|
-
setData(name, value, options) {
|
|
16
|
-
const { target = 'memory', expires } = createDataOptions(options);
|
|
17
|
-
const expiration = getDataExpiration(expires);
|
|
18
|
-
return context.tryWriteDataItem(name, value, pilet, target, expiration);
|
|
19
|
-
},
|
|
20
|
-
registerPage(route, arg, meta) {
|
|
21
|
-
context.registerPage(route, {
|
|
22
|
-
pilet,
|
|
23
|
-
meta,
|
|
24
|
-
component: withApi(context, arg, api, 'page'),
|
|
25
|
-
});
|
|
26
|
-
return () => api.unregisterPage(route);
|
|
27
|
-
},
|
|
28
|
-
unregisterPage(route) {
|
|
29
|
-
context.unregisterPage(route);
|
|
30
|
-
},
|
|
31
|
-
registerExtension(name, arg, defaults) {
|
|
32
|
-
context.registerExtension(name as string, {
|
|
33
|
-
pilet,
|
|
34
|
-
component: withApi(context, arg, api, 'extension'),
|
|
35
|
-
reference: arg,
|
|
36
|
-
defaults,
|
|
37
|
-
});
|
|
38
|
-
return () => api.unregisterExtension(name, arg);
|
|
39
|
-
},
|
|
40
|
-
unregisterExtension(name, arg) {
|
|
41
|
-
context.unregisterExtension(name as string, arg);
|
|
42
|
-
},
|
|
43
|
-
renderHtmlExtension(element, props) {
|
|
44
|
-
const id = renderInDom(context, element, ExtensionSlot, props);
|
|
45
|
-
return () => context.destroyPortal(id);
|
|
46
|
-
},
|
|
47
|
-
Extension: ExtensionSlot,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function initializeApi(target: PiletMetadata, context: GlobalStateContext) {
|
|
53
|
-
return {
|
|
54
|
-
on: context.on,
|
|
55
|
-
off: context.off,
|
|
56
|
-
emit: context.emit,
|
|
57
|
-
meta: {
|
|
58
|
-
...target,
|
|
59
|
-
},
|
|
60
|
-
} as PiletApi;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function mergeApis(api: PiletApi, extenders: Array<PiletApiExtender<Partial<PiletApi>>>, target: PiletMetadata) {
|
|
64
|
-
const frags = extenders.map((extender) => extender(api, target));
|
|
65
|
-
__assign(api, ...frags);
|
|
66
|
-
return api;
|
|
67
|
-
}
|
|
3
|
+
import { createCoreApi } from './core';
|
|
4
|
+
import { GlobalStateContext, PiralPlugin } from '../types';
|
|
68
5
|
|
|
69
6
|
export function createExtenders(context: GlobalStateContext, apis: Array<PiralPlugin>) {
|
|
70
7
|
const creators: Array<PiralPlugin> = [createCoreApi, ...apis.filter(isfunc)];
|