piral-core 0.14.0-pre.3018 → 0.14.0-pre.3085
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/debug-pilet.d.ts +3 -0
- package/debug-pilet.js +12 -0
- package/debug-pilet.ts +11 -0
- package/debug-piral.d.ts +4 -0
- package/debug-piral.js +59 -0
- package/debug-piral.ts +74 -0
- package/esm/Piral.js +6 -8
- package/esm/Piral.js.map +1 -1
- package/esm/actions/app.js +9 -10
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/components.js +4 -5
- 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 +1 -1
- package/esm/actions/state.js.map +1 -1
- package/esm/components/DefaultErrorInfo.js +1 -2
- package/esm/components/DefaultErrorInfo.js.map +1 -1
- package/esm/components/DefaultLayout.js +1 -4
- package/esm/components/DefaultLayout.js.map +1 -1
- package/esm/components/DefaultLoader.js +1 -1
- package/esm/components/DefaultLoader.js.map +1 -1
- package/esm/components/ErrorBoundary.js +13 -18
- package/esm/components/ErrorBoundary.js.map +1 -1
- package/esm/components/ExtensionSlot.js +5 -9
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/components/Mediator.js +8 -8
- package/esm/components/Mediator.js.map +1 -1
- package/esm/components/PiralRoutes.js +8 -8
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/PiralView.js +11 -16
- 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.js +5 -6
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/SetComponent.js +3 -4
- package/esm/components/SetComponent.js.map +1 -1
- package/esm/components/SetError.js +3 -4
- package/esm/components/SetError.js.map +1 -1
- package/esm/components/SetErrors.js +2 -3
- package/esm/components/SetErrors.js.map +1 -1
- package/esm/components/SetLayout.js +2 -3
- package/esm/components/SetLayout.js.map +1 -1
- package/esm/components/SetProvider.js +3 -4
- package/esm/components/SetProvider.js.map +1 -1
- package/esm/components/SetRedirect.js +3 -4
- package/esm/components/SetRedirect.js.map +1 -1
- package/esm/components/SetRoute.js +3 -4
- package/esm/components/SetRoute.js.map +1 -1
- package/esm/components/SwitchErrorInfo.js +12 -10
- package/esm/components/SwitchErrorInfo.js.map +1 -1
- package/esm/components/components.js +8 -9
- package/esm/components/components.js.map +1 -1
- package/esm/components/index.d.ts +1 -0
- package/esm/components/index.js +1 -0
- package/esm/components/index.js.map +1 -1
- package/esm/createInstance.js +24 -25
- package/esm/createInstance.js.map +1 -1
- package/esm/helpers.d.ts +11 -26
- package/esm/helpers.js +18 -56
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/action.js +1 -1
- 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.js +5 -5
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/hooks/index.d.ts +0 -5
- package/esm/hooks/index.js +0 -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/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/modules/api.js +79 -28
- package/esm/modules/api.js.map +1 -1
- package/esm/modules/dependencies.d.ts +3 -4
- package/esm/modules/dependencies.js +11 -14
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/state/createActions.js +7 -12
- package/esm/state/createActions.js.map +1 -1
- package/esm/state/createGlobalState.js +6 -8
- 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.js +59 -62
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/config.d.ts +23 -16
- package/esm/types/state.d.ts +13 -0
- package/esm/utils/compare.js +4 -4
- 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/foreign.d.ts +4 -2
- package/esm/utils/foreign.js +16 -8
- 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 +28 -17
- package/esm/utils/helpers.js.map +1 -1
- package/esm/utils/media.js +8 -7
- package/esm/utils/media.js.map +1 -1
- package/esm/utils/storage.js +13 -14
- package/esm/utils/storage.js.map +1 -1
- package/lib/Piral.js +9 -11
- package/lib/Piral.js.map +1 -1
- package/lib/actions/app.js +11 -12
- 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 +7 -7
- package/lib/actions/index.js.map +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 +3 -3
- package/lib/actions/state.js.map +1 -1
- package/lib/components/DefaultErrorInfo.js +4 -5
- package/lib/components/DefaultErrorInfo.js.map +1 -1
- package/lib/components/DefaultLayout.js +2 -5
- package/lib/components/DefaultLayout.js.map +1 -1
- package/lib/components/DefaultLoader.js +2 -2
- package/lib/components/DefaultLoader.js.map +1 -1
- package/lib/components/ErrorBoundary.js +18 -22
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/ExtensionSlot.js +10 -14
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/Mediator.js +11 -11
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/PiralRoutes.js +11 -11
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralView.js +16 -21
- 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.js +9 -10
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SetComponent.js +4 -5
- package/lib/components/SetComponent.js.map +1 -1
- package/lib/components/SetError.js +4 -5
- package/lib/components/SetError.js.map +1 -1
- package/lib/components/SetErrors.js +4 -5
- package/lib/components/SetErrors.js.map +1 -1
- package/lib/components/SetLayout.js +4 -5
- package/lib/components/SetLayout.js.map +1 -1
- package/lib/components/SetProvider.js +4 -5
- package/lib/components/SetProvider.js.map +1 -1
- package/lib/components/SetRedirect.js +6 -7
- package/lib/components/SetRedirect.js.map +1 -1
- package/lib/components/SetRoute.js +4 -5
- package/lib/components/SetRoute.js.map +1 -1
- package/lib/components/SwitchErrorInfo.js +14 -12
- package/lib/components/SwitchErrorInfo.js.map +1 -1
- package/lib/components/components.js +5 -6
- package/lib/components/components.js.map +1 -1
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +20 -19
- package/lib/components/index.js.map +1 -1
- package/lib/createInstance.js +31 -32
- package/lib/createInstance.js.map +1 -1
- package/lib/helpers.d.ts +11 -26
- package/lib/helpers.js +19 -59
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/action.js +3 -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.js +8 -8
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/hooks/index.d.ts +0 -5
- package/lib/hooks/index.js +7 -12
- 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/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.js +9 -9
- package/lib/index.js.map +1 -1
- package/lib/modules/api.js +86 -35
- package/lib/modules/api.js.map +1 -1
- package/lib/modules/dependencies.d.ts +3 -4
- package/lib/modules/dependencies.js +13 -16
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/modules/index.js +3 -3
- package/lib/modules/index.js.map +1 -1
- package/lib/state/createActions.js +8 -13
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.js +9 -11
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/index.js +5 -5
- package/lib/state/index.js.map +1 -1
- package/lib/state/stateContext.js +1 -1
- package/lib/state/stateContext.js.map +1 -1
- package/lib/state/withApi.js +67 -70
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/config.d.ts +23 -16
- package/lib/types/index.js +13 -13
- package/lib/types/index.js.map +1 -1
- package/lib/types/state.d.ts +13 -0
- package/lib/utils/compare.js +4 -4
- 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/foreign.d.ts +4 -2
- package/lib/utils/foreign.js +21 -11
- 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 +30 -17
- package/lib/utils/helpers.js.map +1 -1
- package/lib/utils/index.js +9 -9
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/media.js +7 -6
- 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/storage.js +11 -12
- package/lib/utils/storage.js.map +1 -1
- package/package.json +12 -5
- package/src/Piral.tsx +2 -1
- package/src/actions/portal.ts +19 -1
- package/src/components/ExtensionSlot.tsx +2 -2
- package/src/components/Mediator.tsx +2 -1
- package/src/components/PortalRenderer.tsx +12 -0
- package/src/components/SwitchErrorInfo.tsx +5 -1
- package/src/components/index.ts +1 -0
- package/src/createInstance.tsx +6 -7
- package/src/helpers.test.tsx +7 -39
- package/src/helpers.tsx +32 -85
- package/src/hooks/index.ts +0 -5
- package/src/hooks/media.ts +2 -1
- package/src/hooks/setter.ts +2 -1
- package/src/modules/api.ts +72 -4
- package/src/modules/dependencies.test.ts +18 -5
- package/src/modules/dependencies.ts +12 -18
- package/src/state/withApi.tsx +12 -14
- package/src/types/config.ts +23 -17
- package/src/types/state.ts +13 -0
- package/src/utils/foreign.test.ts +4 -4
- package/src/utils/foreign.ts +28 -5
- package/src/utils/helpers.ts +21 -7
- package/src/utils/media.ts +2 -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 -15
- 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/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 -19
- 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/src/hooks/debounce.test.ts +0 -67
- package/src/hooks/debounce.ts +0 -19
- package/src/hooks/lockBodyScroll.test.ts +0 -24
- package/src/hooks/lockBodyScroll.ts +0 -15
- 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/state/withApi.tsx
CHANGED
|
@@ -2,9 +2,9 @@ import * as React from 'react';
|
|
|
2
2
|
import { isfunc } from 'piral-base';
|
|
3
3
|
import { __RouterContext } from 'react-router';
|
|
4
4
|
import { StateContext } from './stateContext';
|
|
5
|
-
import { PiralError, PiralLoadingIndicator, ErrorBoundary, ErrorBoundaryOptions } from '../components';
|
|
6
|
-
import {
|
|
7
|
-
import { defaultRender, convertComponent } from '../utils';
|
|
5
|
+
import { PiralError, PiralLoadingIndicator, ErrorBoundary, ErrorBoundaryOptions, PortalRenderer } from '../components';
|
|
6
|
+
import { useActions } from '../hooks';
|
|
7
|
+
import { defaultRender, convertComponent, none } from '../utils';
|
|
8
8
|
import {
|
|
9
9
|
AnyComponent,
|
|
10
10
|
Errors,
|
|
@@ -16,19 +16,10 @@ import {
|
|
|
16
16
|
GlobalStateContext,
|
|
17
17
|
} from '../types';
|
|
18
18
|
|
|
19
|
+
// this is an arbitrary start number to have 6 digits
|
|
19
20
|
let portalIdBase = 123456;
|
|
20
|
-
const none = [];
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
id: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const PortalRenderer: React.FC<PortalRendererProps> = ({ id }) => {
|
|
27
|
-
const children = useGlobalState((m) => m.portals[id]) || none;
|
|
28
|
-
return defaultRender(children);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const DefaultWrapper: React.FC = (props) => <>{props.children}</>;
|
|
22
|
+
const DefaultWrapper: React.FC = (props) => defaultRender(props.children);
|
|
32
23
|
|
|
33
24
|
interface ForeignComponentContainerProps<T> {
|
|
34
25
|
$portalId: string;
|
|
@@ -40,6 +31,11 @@ interface ForeignComponentContainerProps<T> {
|
|
|
40
31
|
class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
|
|
41
32
|
private current?: HTMLElement;
|
|
42
33
|
private previous?: HTMLElement;
|
|
34
|
+
private handler = (ev: CustomEvent) => {
|
|
35
|
+
const { innerProps } = this.props;
|
|
36
|
+
ev.stopPropagation();
|
|
37
|
+
innerProps.piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
|
|
38
|
+
};
|
|
43
39
|
|
|
44
40
|
private setNode = (node: HTMLDivElement) => {
|
|
45
41
|
this.current = node;
|
|
@@ -52,6 +48,7 @@ class ForeignComponentContainer<T> extends React.Component<ForeignComponentConta
|
|
|
52
48
|
|
|
53
49
|
if (node && isfunc(mount)) {
|
|
54
50
|
mount(node, innerProps, $context);
|
|
51
|
+
node.addEventListener('render-html', this.handler, false);
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
this.previous = node;
|
|
@@ -77,6 +74,7 @@ class ForeignComponentContainer<T> extends React.Component<ForeignComponentConta
|
|
|
77
74
|
|
|
78
75
|
if (node && isfunc(unmount)) {
|
|
79
76
|
unmount(node);
|
|
77
|
+
node.removeEventListener('render-html', this.handler, false);
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
this.previous = undefined;
|
package/src/types/config.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
PiletRequester,
|
|
3
|
-
PiletDependencyFetcher,
|
|
4
|
-
PiletDependencyGetter,
|
|
5
3
|
PiletLoadingStrategy,
|
|
6
4
|
PiletLoader,
|
|
7
5
|
Pilet,
|
|
@@ -10,24 +8,30 @@ import type {
|
|
|
10
8
|
DefaultLoaderConfig,
|
|
11
9
|
PiletApiCreator,
|
|
12
10
|
} from 'piral-base';
|
|
11
|
+
import { DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
13
12
|
import type { NestedPartial } from './common';
|
|
14
13
|
import type { PiralPlugin } from './plugin';
|
|
15
14
|
import type { GlobalState, GlobalStateContext, PiralDefineActions } from './state';
|
|
16
15
|
|
|
17
|
-
export { PiletLoadingStrategy,
|
|
16
|
+
export { PiletLoadingStrategy, PiletRequester, AvailableDependencies };
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
19
|
+
* Definition for customizing the shared dependencies.
|
|
21
20
|
*/
|
|
22
|
-
export interface
|
|
23
|
-
/**
|
|
24
|
-
* The callback for defining how a dependency will be fetched.
|
|
25
|
-
*/
|
|
26
|
-
fetchDependency?: PiletDependencyFetcher;
|
|
21
|
+
export interface DependencySelector {
|
|
27
22
|
/**
|
|
28
|
-
*
|
|
23
|
+
* Selects the dependencies to share from the currently available dependencies.
|
|
24
|
+
* @param currentDependencies The currently available dependencies.
|
|
25
|
+
* @default currentDependencies All current dependencies are shared
|
|
26
|
+
* @returns The dependencies selected to be shared.
|
|
29
27
|
*/
|
|
30
|
-
|
|
28
|
+
(currentDependencies: AvailableDependencies): AvailableDependencies;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The configuration for loading the pilets of the Piral instance.
|
|
33
|
+
*/
|
|
34
|
+
export interface PiralPiletConfiguration {
|
|
31
35
|
/**
|
|
32
36
|
* Function to load the modules asynchronously, e.g., from a server 🚚.
|
|
33
37
|
*/
|
|
@@ -44,6 +48,10 @@ export interface PiralPiletConfiguration {
|
|
|
44
48
|
* Optionally, configures the default loader.
|
|
45
49
|
*/
|
|
46
50
|
loaderConfig?: DefaultLoaderConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Optionally, configures explicitly what dependencies are shared.
|
|
53
|
+
*/
|
|
54
|
+
shareDependencies?: DependencySelector;
|
|
47
55
|
/**
|
|
48
56
|
* Determines that pilets are loaded asynchronously, essentially showing the
|
|
49
57
|
* app right away without waiting for the pilets to load and evaluate.
|
|
@@ -55,12 +63,6 @@ export interface PiralPiletConfiguration {
|
|
|
55
63
|
* This can be used for customization or for debugging purposes.
|
|
56
64
|
*/
|
|
57
65
|
availablePilets?: Array<Pilet>;
|
|
58
|
-
/**
|
|
59
|
-
* Optionally provides a function to extend the API creator with some additional
|
|
60
|
-
* functionality.
|
|
61
|
-
* @deprecated Use plugins instead.
|
|
62
|
-
*/
|
|
63
|
-
extendApi?: PiralPlugin | Array<PiralPlugin>;
|
|
64
66
|
/**
|
|
65
67
|
* Extends the Piral instance with additional capabilities.
|
|
66
68
|
*/
|
|
@@ -95,6 +97,10 @@ export interface PiralStateConfiguration {
|
|
|
95
97
|
* Optionally, sets up some initial custom actions ⚡️.
|
|
96
98
|
*/
|
|
97
99
|
actions?: PiralDefineActions;
|
|
100
|
+
/**
|
|
101
|
+
* Optionally, sets up additional configuration for the debug tooling 🤖.
|
|
102
|
+
*/
|
|
103
|
+
debug?: DebuggerExtensionOptions;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
package/src/types/state.ts
CHANGED
|
@@ -294,6 +294,19 @@ export interface PiralActions extends PiralCustomActions {
|
|
|
294
294
|
* @param entry The child to render.
|
|
295
295
|
*/
|
|
296
296
|
showPortal(id: string, entry: ReactPortal): void;
|
|
297
|
+
/**
|
|
298
|
+
* Hides the provided portal in the rendering pipeline.
|
|
299
|
+
* @param id The id of the portal to use.
|
|
300
|
+
* @param entry The child to remove.
|
|
301
|
+
*/
|
|
302
|
+
hidePortal(id: string, entry: ReactPortal): void;
|
|
303
|
+
/**
|
|
304
|
+
* Updates the provided portal in the rendering pipeline.
|
|
305
|
+
* @param id The id of the portal to use.
|
|
306
|
+
* @param current The currently displayed child.
|
|
307
|
+
* @param next The updated child that should be displayed.
|
|
308
|
+
*/
|
|
309
|
+
updatePortal(id: string, current: ReactPortal, next: ReactPortal): void;
|
|
297
310
|
/**
|
|
298
311
|
* Dispatches a state change.
|
|
299
312
|
* @param update The update function creating a new state.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createElement
|
|
1
|
+
import { createElement } from 'react';
|
|
2
2
|
import { convertComponent, renderInDom } from './foreign';
|
|
3
3
|
import { ForeignComponent } from '../types';
|
|
4
4
|
import { DefaultLoadingIndicator } from '../components/DefaultLoader';
|
|
@@ -28,7 +28,7 @@ describe('Util Foreign.', () => {
|
|
|
28
28
|
const portalId = 'data-portal-id';
|
|
29
29
|
const element = document.createElement('div') as HTMLDivElement;
|
|
30
30
|
element.setAttribute(portalId, '100');
|
|
31
|
-
var result = renderInDom(context, element, DefaultLoadingIndicator, {});
|
|
31
|
+
var [result] = renderInDom(context, element, DefaultLoadingIndicator, {});
|
|
32
32
|
expect(result).toBe('100');
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -37,7 +37,7 @@ describe('Util Foreign.', () => {
|
|
|
37
37
|
showPortal: jest.fn(),
|
|
38
38
|
} as any;
|
|
39
39
|
const element = document.createElement('div') as HTMLDivElement;
|
|
40
|
-
var result = renderInDom(context, element, DefaultLoadingIndicator, {});
|
|
41
|
-
expect(result).
|
|
40
|
+
var [result] = renderInDom(context, element, DefaultLoadingIndicator, {});
|
|
41
|
+
expect(result).toBe('root');
|
|
42
42
|
});
|
|
43
43
|
});
|
package/src/utils/foreign.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { createElement, ComponentType } from 'react';
|
|
1
|
+
import { createElement, ComponentType, ReactPortal } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { GlobalStateContext, ForeignComponent } from '../types';
|
|
4
4
|
|
|
5
|
+
export function attachDomPortal<TProps>(
|
|
6
|
+
id: string,
|
|
7
|
+
context: GlobalStateContext,
|
|
8
|
+
element: HTMLElement | ShadowRoot,
|
|
9
|
+
component: ComponentType<TProps>,
|
|
10
|
+
props: TProps,
|
|
11
|
+
): [string, ReactPortal] {
|
|
12
|
+
const portal = createPortal(createElement(component, props), element as HTMLElement);
|
|
13
|
+
context.showPortal(id, portal);
|
|
14
|
+
return [id, portal];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function changeDomPortal<TProps>(
|
|
18
|
+
id: string,
|
|
19
|
+
current: ReactPortal,
|
|
20
|
+
context: GlobalStateContext,
|
|
21
|
+
element: HTMLElement | ShadowRoot,
|
|
22
|
+
component: ComponentType<TProps>,
|
|
23
|
+
props: TProps,
|
|
24
|
+
): [string, ReactPortal] {
|
|
25
|
+
const next = createPortal(createElement(component, props), element as HTMLElement);
|
|
26
|
+
context.updatePortal(id, current, next);
|
|
27
|
+
return [id, next];
|
|
28
|
+
}
|
|
29
|
+
|
|
5
30
|
export function convertComponent<T extends { type: string }, U>(
|
|
6
31
|
converter: (component: T) => ForeignComponent<U>,
|
|
7
32
|
component: T,
|
|
@@ -24,14 +49,12 @@ export function renderInDom<TProps>(
|
|
|
24
49
|
|
|
25
50
|
while (parent) {
|
|
26
51
|
if (parent instanceof Element && parent.hasAttribute(portalId)) {
|
|
27
|
-
const portal = createPortal(createElement(component, props), element as HTMLElement);
|
|
28
52
|
const id = parent.getAttribute(portalId);
|
|
29
|
-
|
|
30
|
-
return id;
|
|
53
|
+
return attachDomPortal(id, context, element, component, props);
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
parent = parent.parentNode || (parent as ShadowRoot).host;
|
|
34
57
|
}
|
|
35
58
|
|
|
36
|
-
return
|
|
59
|
+
return attachDomPortal('root', context, element, component, props);
|
|
37
60
|
}
|
package/src/utils/helpers.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
// tslint:disable-next-line
|
|
2
2
|
export const removeIndicator = null;
|
|
3
3
|
|
|
4
|
+
// to avoid creating unnecessary empty arrays
|
|
5
|
+
export const none = [];
|
|
6
|
+
|
|
7
|
+
// to avoid creating unnecessary empty functions
|
|
8
|
+
export const noop = () => {};
|
|
9
|
+
|
|
4
10
|
export function prependItem<T>(items: Array<T>, item: T) {
|
|
5
|
-
return [item, ...(items ||
|
|
11
|
+
return [item, ...(items || none)];
|
|
6
12
|
}
|
|
7
13
|
|
|
8
14
|
export function appendItem<T>(items: Array<T>, item: T) {
|
|
9
|
-
return [...(items ||
|
|
15
|
+
return [...(items || none), item];
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
export function prependItems<T>(items: Array<T>, newItems: Array<T>) {
|
|
13
|
-
return [...newItems, ...(items ||
|
|
19
|
+
return [...newItems, ...(items || none)];
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
export function appendItems<T>(items: Array<T>, newItems: Array<T>) {
|
|
17
|
-
return [...(items ||
|
|
23
|
+
return [...(items || none), ...newItems];
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export function excludeItem<T>(items: Array<T>, item: T) {
|
|
21
|
-
return (items ||
|
|
27
|
+
return (items || none).filter((m) => m !== item);
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export function includeItem<T>(items: Array<T>, item: T) {
|
|
@@ -26,7 +32,7 @@ export function includeItem<T>(items: Array<T>, item: T) {
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
export function replaceOrAddItem<T>(items: Array<T>, item: T, predicate: (item: T) => boolean) {
|
|
29
|
-
const newItems = [...(items ||
|
|
35
|
+
const newItems = [...(items || none)];
|
|
30
36
|
|
|
31
37
|
for (let i = 0; i < newItems.length; i++) {
|
|
32
38
|
if (predicate(newItems[i])) {
|
|
@@ -59,7 +65,7 @@ export function removeNested<T, U = any>(obj: T, predicate: (item: U) => boolean
|
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
export function excludeOn<T>(items: Array<T>, predicate: (item: T) => boolean) {
|
|
62
|
-
return (items ||
|
|
68
|
+
return (items || none).filter((m) => !predicate(m));
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
export function updateKey<T, TKey extends keyof T>(obj: T, key: TKey, value: T[TKey]): T {
|
|
@@ -77,3 +83,11 @@ export function withoutKey<T, TKey extends keyof T>(obj: T, key: TKey): T {
|
|
|
77
83
|
const { [key]: _, ...newObj } = obj || {};
|
|
78
84
|
return newObj as any;
|
|
79
85
|
}
|
|
86
|
+
|
|
87
|
+
export function tryParseJson(content: string) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(content);
|
|
90
|
+
} catch {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
}
|
package/src/utils/media.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isfunc } from 'piral-base';
|
|
2
|
+
import { none } from './helpers';
|
|
2
3
|
import { LayoutTypes, LayoutBreakpoints } from '../types';
|
|
3
4
|
|
|
4
5
|
export const defaultLayouts: LayoutTypes = ['desktop', 'tablet', 'mobile'];
|
|
@@ -7,7 +8,7 @@ export const defaultBreakpoints: LayoutBreakpoints = ['(min-width: 991px)', '(mi
|
|
|
7
8
|
|
|
8
9
|
const mm =
|
|
9
10
|
typeof window === 'undefined' || !isfunc(window.matchMedia)
|
|
10
|
-
? () => ({ matches:
|
|
11
|
+
? () => ({ matches: none })
|
|
11
12
|
: (q: string) => window.matchMedia(q);
|
|
12
13
|
|
|
13
14
|
export function getCurrentLayout<T>(breakpoints: Array<string>, layouts: Array<T>, defaultLayout: T) {
|
package/esm/hooks/debounce.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that returns the debounced (i.e., delayed) value.
|
|
3
|
-
* Useful when user input should not fire immediately, but rather
|
|
4
|
-
* only after a certain timespan without any changes passed.
|
|
5
|
-
* @param value The value to consider.
|
|
6
|
-
* @param delay The timespan to pass before applying the value.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useDebounce<T>(value: T, delay?: number): T;
|
package/esm/hooks/debounce.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that returns the debounced (i.e., delayed) value.
|
|
4
|
-
* Useful when user input should not fire immediately, but rather
|
|
5
|
-
* only after a certain timespan without any changes passed.
|
|
6
|
-
* @param value The value to consider.
|
|
7
|
-
* @param delay The timespan to pass before applying the value.
|
|
8
|
-
*/
|
|
9
|
-
export function useDebounce(value, delay) {
|
|
10
|
-
if (delay === void 0) { delay = 300; }
|
|
11
|
-
var _a = useState(value), debouncedValue = _a[0], setDebouncedValue = _a[1];
|
|
12
|
-
useEffect(function () {
|
|
13
|
-
var handler = setTimeout(function () { return setDebouncedValue(value); }, delay);
|
|
14
|
-
return function () { return clearTimeout(handler); };
|
|
15
|
-
}, [value, delay]);
|
|
16
|
-
return debouncedValue;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=debounce.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/hooks/debounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAI,KAAQ,EAAE,KAAW;IAAX,sBAAA,EAAA,WAAW;IAC5C,IAAA,KAAsC,QAAQ,CAAC,KAAK,CAAC,EAApD,cAAc,QAAA,EAAE,iBAAiB,QAAmB,CAAC;IAE5D,SAAS,CAAC;QACR,IAAM,OAAO,GAAG,UAAU,CAAC,cAAM,OAAA,iBAAiB,CAAC,KAAK,CAAC,EAAxB,CAAwB,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,cAAM,OAAA,YAAY,CAAC,OAAO,CAAC,EAArB,CAAqB,CAAC;IACrC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that locks scrolling on the main document.
|
|
4
|
-
* Useful for preventing the standard scrolling in context of
|
|
5
|
-
* a modal dialog.
|
|
6
|
-
*/
|
|
7
|
-
export function useLockBodyScroll() {
|
|
8
|
-
useLayoutEffect(function () {
|
|
9
|
-
document.body.style.overflow = 'hidden';
|
|
10
|
-
return function () {
|
|
11
|
-
document.body.style.overflow = 'visible';
|
|
12
|
-
};
|
|
13
|
-
}, []);
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=lockBodyScroll.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/lockBodyScroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,eAAe,CAAC;QACd,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxC,OAAO;YACL,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a click outside the given reference
|
|
4
|
-
* has been performed.
|
|
5
|
-
* @param ref The reference to the element.
|
|
6
|
-
* @param handler The callback to invoke when an outside click happened.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useOnClickOutside<T extends HTMLElement>(ref: RefObject<T>, handler: (event: MouseEvent) => void): void;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a click outside the given reference
|
|
4
|
-
* has been performed.
|
|
5
|
-
* @param ref The reference to the element.
|
|
6
|
-
* @param handler The callback to invoke when an outside click happened.
|
|
7
|
-
*/
|
|
8
|
-
export function useOnClickOutside(ref, handler) {
|
|
9
|
-
useEffect(function () {
|
|
10
|
-
var listener = function (event) {
|
|
11
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
12
|
-
handler(event);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
document.addEventListener('mousedown', listener);
|
|
16
|
-
document.addEventListener('touchstart', listener);
|
|
17
|
-
return function () {
|
|
18
|
-
document.removeEventListener('mousedown', listener);
|
|
19
|
-
document.removeEventListener('touchstart', listener);
|
|
20
|
-
};
|
|
21
|
-
}, [handler]);
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=onClickOutside.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onClickOutside.js","sourceRoot":"","sources":["../../src/hooks/onClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAwB,GAAiB,EAAE,OAAoC;IAC9G,SAAS,CAAC;QACR,IAAM,QAAQ,GAAG,UAAC,KAAiB;YACjC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAc,CAAC,EAAE;gBAC9D,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;QACH,CAAC,CAAC;QAEF,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,QAAQ,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAElD,OAAO;YACL,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACpD,QAAQ,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a reference element within the main document is
|
|
4
|
-
* visible.
|
|
5
|
-
* Useful for performing some animation or triggering certain actions (e.g.,
|
|
6
|
-
* loading data for infinity scrolling) when an element appears or is close
|
|
7
|
-
* to appear on screen.
|
|
8
|
-
* @param ref The reference element to be visible.
|
|
9
|
-
* @param rootMargin The tolerance level to the reference element.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useOnScreenVisible<T extends HTMLElement>(ref: RefObject<T>, rootMargin?: string): boolean;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a reference element within the main document is
|
|
4
|
-
* visible.
|
|
5
|
-
* Useful for performing some animation or triggering certain actions (e.g.,
|
|
6
|
-
* loading data for infinity scrolling) when an element appears or is close
|
|
7
|
-
* to appear on screen.
|
|
8
|
-
* @param ref The reference element to be visible.
|
|
9
|
-
* @param rootMargin The tolerance level to the reference element.
|
|
10
|
-
*/
|
|
11
|
-
export function useOnScreenVisible(ref, rootMargin) {
|
|
12
|
-
if (rootMargin === void 0) { rootMargin = '0px'; }
|
|
13
|
-
var _a = useState(false), isIntersecting = _a[0], setIntersecting = _a[1];
|
|
14
|
-
useEffect(function () {
|
|
15
|
-
var observer = new IntersectionObserver(function (_a) {
|
|
16
|
-
var entry = _a[0];
|
|
17
|
-
return setIntersecting(entry.isIntersecting);
|
|
18
|
-
}, {
|
|
19
|
-
rootMargin: rootMargin,
|
|
20
|
-
});
|
|
21
|
-
if (ref.current) {
|
|
22
|
-
observer.observe(ref.current);
|
|
23
|
-
}
|
|
24
|
-
return function () { return observer.unobserve(ref.current); };
|
|
25
|
-
}, []);
|
|
26
|
-
return isIntersecting;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=onScreenVisible.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onScreenVisible.js","sourceRoot":"","sources":["../../src/hooks/onScreenVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAwB,GAAiB,EAAE,UAAkB;IAAlB,2BAAA,EAAA,kBAAkB;IACvF,IAAA,KAAoC,QAAQ,CAAC,KAAK,CAAC,EAAlD,cAAc,QAAA,EAAE,eAAe,QAAmB,CAAC;IAE1D,SAAS,CAAC;QACR,IAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,UAAC,EAAO;gBAAN,KAAK,QAAA;YAAM,OAAA,eAAe,CAAC,KAAK,CAAC,cAAc,CAAC;QAArC,CAAqC,EAAE;YAC5F,UAAU,YAAA;SACX,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,OAAO,EAAE;YACf,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAC/B;QAED,OAAO,cAAM,OAAA,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAA/B,CAA+B,CAAC;IAC/C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
package/esm/hooks/promise.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The currently captured Promise state.
|
|
3
|
-
*/
|
|
4
|
-
export interface UsePromiseResult<T> {
|
|
5
|
-
loading: boolean;
|
|
6
|
-
data: T;
|
|
7
|
-
error: any;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Hook for introducing a complete local loading state for a promise.
|
|
11
|
-
* @param promise The callback for the promise to wait for.
|
|
12
|
-
*/
|
|
13
|
-
export declare function usePromise<T>(promise: () => Promise<T>): UsePromiseResult<T>;
|
package/esm/hooks/promise.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook for introducing a complete local loading state for a promise.
|
|
4
|
-
* @param promise The callback for the promise to wait for.
|
|
5
|
-
*/
|
|
6
|
-
export function usePromise(promise) {
|
|
7
|
-
var _a = useState({
|
|
8
|
-
loading: true,
|
|
9
|
-
data: undefined,
|
|
10
|
-
error: undefined,
|
|
11
|
-
}), result = _a[0], setResult = _a[1];
|
|
12
|
-
useEffect(function () {
|
|
13
|
-
var cancelled = false;
|
|
14
|
-
promise().then(function (data) { return !cancelled && setResult({ data: data, error: undefined, loading: false }); }, function (error) { return !cancelled && setResult({ data: undefined, error: error, loading: false }); });
|
|
15
|
-
return function () {
|
|
16
|
-
cancelled = true;
|
|
17
|
-
};
|
|
18
|
-
}, []);
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=promise.js.map
|
package/esm/hooks/promise.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/hooks/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAW5C;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAI,OAAyB;IAC/C,IAAA,KAAsB,QAAQ,CAAsB;QACxD,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC,EAJK,MAAM,QAAA,EAAE,SAAS,QAItB,CAAC;IACH,SAAS,CAAC;QACR,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,OAAO,EAAE,CAAC,IAAI,CACZ,UAAC,IAAI,IAAK,OAAA,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,MAAA,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAnE,CAAmE,EAC7E,UAAC,KAAK,IAAK,OAAA,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,OAAA,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAnE,CAAmE,CAC/E,CAAC;QAEF,OAAO;YACL,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/lib/hooks/debounce.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that returns the debounced (i.e., delayed) value.
|
|
3
|
-
* Useful when user input should not fire immediately, but rather
|
|
4
|
-
* only after a certain timespan without any changes passed.
|
|
5
|
-
* @param value The value to consider.
|
|
6
|
-
* @param delay The timespan to pass before applying the value.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useDebounce<T>(value: T, delay?: number): T;
|
package/lib/hooks/debounce.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useDebounce = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* Hook that returns the debounced (i.e., delayed) value.
|
|
7
|
-
* Useful when user input should not fire immediately, but rather
|
|
8
|
-
* only after a certain timespan without any changes passed.
|
|
9
|
-
* @param value The value to consider.
|
|
10
|
-
* @param delay The timespan to pass before applying the value.
|
|
11
|
-
*/
|
|
12
|
-
function useDebounce(value, delay) {
|
|
13
|
-
if (delay === void 0) { delay = 300; }
|
|
14
|
-
var _a = react_1.useState(value), debouncedValue = _a[0], setDebouncedValue = _a[1];
|
|
15
|
-
react_1.useEffect(function () {
|
|
16
|
-
var handler = setTimeout(function () { return setDebouncedValue(value); }, delay);
|
|
17
|
-
return function () { return clearTimeout(handler); };
|
|
18
|
-
}, [value, delay]);
|
|
19
|
-
return debouncedValue;
|
|
20
|
-
}
|
|
21
|
-
exports.useDebounce = useDebounce;
|
|
22
|
-
//# sourceMappingURL=debounce.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/hooks/debounce.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAE5C;;;;;;GAMG;AACH,SAAgB,WAAW,CAAI,KAAQ,EAAE,KAAW;IAAX,sBAAA,EAAA,WAAW;IAC5C,IAAA,KAAsC,gBAAQ,CAAC,KAAK,CAAC,EAApD,cAAc,QAAA,EAAE,iBAAiB,QAAmB,CAAC;IAE5D,iBAAS,CAAC;QACR,IAAM,OAAO,GAAG,UAAU,CAAC,cAAM,OAAA,iBAAiB,CAAC,KAAK,CAAC,EAAxB,CAAwB,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,cAAM,OAAA,YAAY,CAAC,OAAO,CAAC,EAArB,CAAqB,CAAC;IACrC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AACxB,CAAC;AATD,kCASC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLockBodyScroll = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* Hook that locks scrolling on the main document.
|
|
7
|
-
* Useful for preventing the standard scrolling in context of
|
|
8
|
-
* a modal dialog.
|
|
9
|
-
*/
|
|
10
|
-
function useLockBodyScroll() {
|
|
11
|
-
react_1.useLayoutEffect(function () {
|
|
12
|
-
document.body.style.overflow = 'hidden';
|
|
13
|
-
return function () {
|
|
14
|
-
document.body.style.overflow = 'visible';
|
|
15
|
-
};
|
|
16
|
-
}, []);
|
|
17
|
-
}
|
|
18
|
-
exports.useLockBodyScroll = useLockBodyScroll;
|
|
19
|
-
//# sourceMappingURL=lockBodyScroll.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/lockBodyScroll.ts"],"names":[],"mappings":";;;AAAA,+BAAwC;AAExC;;;;GAIG;AACH,SAAgB,iBAAiB;IAC/B,uBAAe,CAAC;QACd,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxC,OAAO;YACL,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAPD,8CAOC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a click outside the given reference
|
|
4
|
-
* has been performed.
|
|
5
|
-
* @param ref The reference to the element.
|
|
6
|
-
* @param handler The callback to invoke when an outside click happened.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useOnClickOutside<T extends HTMLElement>(ref: RefObject<T>, handler: (event: MouseEvent) => void): void;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useOnClickOutside = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* Hook that detects if a click outside the given reference
|
|
7
|
-
* has been performed.
|
|
8
|
-
* @param ref The reference to the element.
|
|
9
|
-
* @param handler The callback to invoke when an outside click happened.
|
|
10
|
-
*/
|
|
11
|
-
function useOnClickOutside(ref, handler) {
|
|
12
|
-
react_1.useEffect(function () {
|
|
13
|
-
var listener = function (event) {
|
|
14
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
15
|
-
handler(event);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
document.addEventListener('mousedown', listener);
|
|
19
|
-
document.addEventListener('touchstart', listener);
|
|
20
|
-
return function () {
|
|
21
|
-
document.removeEventListener('mousedown', listener);
|
|
22
|
-
document.removeEventListener('touchstart', listener);
|
|
23
|
-
};
|
|
24
|
-
}, [handler]);
|
|
25
|
-
}
|
|
26
|
-
exports.useOnClickOutside = useOnClickOutside;
|
|
27
|
-
//# sourceMappingURL=onClickOutside.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onClickOutside.js","sourceRoot":"","sources":["../../src/hooks/onClickOutside.ts"],"names":[],"mappings":";;;AAAA,+BAA6C;AAE7C;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAwB,GAAiB,EAAE,OAAoC;IAC9G,iBAAS,CAAC;QACR,IAAM,QAAQ,GAAG,UAAC,KAAiB;YACjC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAc,CAAC,EAAE;gBAC9D,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;QACH,CAAC,CAAC;QAEF,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,QAAQ,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAElD,OAAO;YACL,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACpD,QAAQ,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,CAAC;AAhBD,8CAgBC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a reference element within the main document is
|
|
4
|
-
* visible.
|
|
5
|
-
* Useful for performing some animation or triggering certain actions (e.g.,
|
|
6
|
-
* loading data for infinity scrolling) when an element appears or is close
|
|
7
|
-
* to appear on screen.
|
|
8
|
-
* @param ref The reference element to be visible.
|
|
9
|
-
* @param rootMargin The tolerance level to the reference element.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useOnScreenVisible<T extends HTMLElement>(ref: RefObject<T>, rootMargin?: string): boolean;
|