@pushwoosh/kit-helpers 4.6.3 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grid.d.ts +20 -0
- package/grid.js +1 -1
- package/hooks/useAsyncFunction.d.ts +29 -0
- package/hooks/useAsyncFunction.js +44 -0
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
package/grid.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ export declare const toCssValue: (value: number | string) => string;
|
|
|
2
2
|
export declare const GridContainer: import("styled-components").StyledComponent<"div", any, {
|
|
3
3
|
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
4
4
|
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
5
|
+
$bgColor?: string | undefined;
|
|
6
|
+
$border?: string | undefined;
|
|
7
|
+
$borderRadius?: string | number | undefined;
|
|
8
|
+
$boxShadow?: string | undefined;
|
|
5
9
|
$gap?: string | number | undefined;
|
|
6
10
|
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
7
11
|
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
@@ -13,6 +17,10 @@ export declare const GridContainer: import("styled-components").StyledComponent<
|
|
|
13
17
|
export declare const Columns: import("styled-components").StyledComponent<"div", any, {
|
|
14
18
|
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
15
19
|
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
20
|
+
$bgColor?: string | undefined;
|
|
21
|
+
$border?: string | undefined;
|
|
22
|
+
$borderRadius?: string | number | undefined;
|
|
23
|
+
$boxShadow?: string | undefined;
|
|
16
24
|
$gap?: string | number | undefined;
|
|
17
25
|
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
18
26
|
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
@@ -26,6 +34,10 @@ export declare const Columns: import("styled-components").StyledComponent<"div",
|
|
|
26
34
|
export declare const Rows: import("styled-components").StyledComponent<"div", any, {
|
|
27
35
|
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
28
36
|
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
37
|
+
$bgColor?: string | undefined;
|
|
38
|
+
$border?: string | undefined;
|
|
39
|
+
$borderRadius?: string | number | undefined;
|
|
40
|
+
$boxShadow?: string | undefined;
|
|
29
41
|
$gap?: string | number | undefined;
|
|
30
42
|
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
31
43
|
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
@@ -39,6 +51,10 @@ export declare const Rows: import("styled-components").StyledComponent<"div", an
|
|
|
39
51
|
export declare const Horizontal: import("styled-components").StyledComponent<"div", any, {
|
|
40
52
|
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
41
53
|
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
54
|
+
$bgColor?: string | undefined;
|
|
55
|
+
$border?: string | undefined;
|
|
56
|
+
$borderRadius?: string | number | undefined;
|
|
57
|
+
$boxShadow?: string | undefined;
|
|
42
58
|
$gap?: string | number | undefined;
|
|
43
59
|
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
44
60
|
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
@@ -52,6 +68,10 @@ export declare const Horizontal: import("styled-components").StyledComponent<"di
|
|
|
52
68
|
export declare const Vertical: import("styled-components").StyledComponent<"div", any, {
|
|
53
69
|
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
54
70
|
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
71
|
+
$bgColor?: string | undefined;
|
|
72
|
+
$border?: string | undefined;
|
|
73
|
+
$borderRadius?: string | number | undefined;
|
|
74
|
+
$boxShadow?: string | undefined;
|
|
55
75
|
$gap?: string | number | undefined;
|
|
56
76
|
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
57
77
|
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
package/grid.js
CHANGED
|
@@ -11,7 +11,7 @@ const createCssDeclaration = (property, value, valueConvert) => {
|
|
|
11
11
|
export const GridContainer = styled.div.withConfig({
|
|
12
12
|
displayName: "GridContainer",
|
|
13
13
|
componentId: "sc-1mpmh7u-0"
|
|
14
|
-
})(["display:grid;", " ", " ", " ", " ", " ", " ", " ", " ", ""], props => createCssDeclaration('align-content', props.$alignContent), props => createCssDeclaration('align-items', props.$alignItems), props => createCssDeclaration('gap', props.$gap, toCssValue), props => createCssDeclaration('grid-auto-flow', props.$gridAutoFlow), props => createCssDeclaration('justify-content', props.$justifyContent), props => createCssDeclaration('justify-items', props.$justifyItems), props => createCssDeclaration('margin', props.$margin, toCssValue), props => createCssDeclaration('padding', props.$padding, toCssValue), props => createCssDeclaration('place-items', props.$placeItems));
|
|
14
|
+
})(["display:grid;", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", ""], props => createCssDeclaration('align-content', props.$alignContent), props => createCssDeclaration('align-items', props.$alignItems), props => createCssDeclaration('background-color', props.$bgColor), props => createCssDeclaration('border', props.$border), props => createCssDeclaration('border-radius', props.$borderRadius, toCssValue), props => createCssDeclaration('box-shadow', props.$boxShadow), props => createCssDeclaration('gap', props.$gap, toCssValue), props => createCssDeclaration('grid-auto-flow', props.$gridAutoFlow), props => createCssDeclaration('justify-content', props.$justifyContent), props => createCssDeclaration('justify-items', props.$justifyItems), props => createCssDeclaration('margin', props.$margin, toCssValue), props => createCssDeclaration('padding', props.$padding, toCssValue), props => createCssDeclaration('place-items', props.$placeItems));
|
|
15
15
|
export const Columns = styled(GridContainer).withConfig({
|
|
16
16
|
displayName: "Columns",
|
|
17
17
|
componentId: "sc-1mpmh7u-1"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FunctionReturningPromise, PromiseType } from './types';
|
|
2
|
+
export type AsyncFunctionState<T> = {
|
|
3
|
+
loading: boolean;
|
|
4
|
+
count: number;
|
|
5
|
+
error?: undefined;
|
|
6
|
+
value?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
loading: true;
|
|
9
|
+
count: number;
|
|
10
|
+
error?: Error | undefined;
|
|
11
|
+
value?: T;
|
|
12
|
+
} | {
|
|
13
|
+
loading: false;
|
|
14
|
+
count: number;
|
|
15
|
+
error: Error;
|
|
16
|
+
value?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
loading: false;
|
|
19
|
+
count: number;
|
|
20
|
+
error?: undefined;
|
|
21
|
+
value: T;
|
|
22
|
+
};
|
|
23
|
+
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncFunctionState<PromiseType<ReturnType<T>>>;
|
|
24
|
+
export type AsyncFunctionReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
|
|
25
|
+
StateFromFunctionReturningPromise<T>,
|
|
26
|
+
T
|
|
27
|
+
];
|
|
28
|
+
export default function useAsyncFunction<T extends FunctionReturningPromise>(fn: T): AsyncFunctionReturn<T>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
import useMountedState from './useMountedState';
|
|
3
|
+
import usePersistentFunction from './usePersistentFunction';
|
|
4
|
+
const getDefaultState = () => ({
|
|
5
|
+
loading: false,
|
|
6
|
+
count: 0
|
|
7
|
+
});
|
|
8
|
+
export default function useAsyncFunction(fn) {
|
|
9
|
+
const countRef = useRef(0);
|
|
10
|
+
const isMounted = useMountedState();
|
|
11
|
+
const [state, setState] = useState(getDefaultState);
|
|
12
|
+
const execute = usePersistentFunction((...args) => {
|
|
13
|
+
// eslint-disable-next-line no-plusplus
|
|
14
|
+
const count = ++countRef.current;
|
|
15
|
+
const canSet = () => isMounted() && count === countRef.current;
|
|
16
|
+
if (canSet()) {
|
|
17
|
+
setState(prevState => ({
|
|
18
|
+
...prevState,
|
|
19
|
+
count,
|
|
20
|
+
loading: true
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
return fn(...args).then(value => {
|
|
24
|
+
if (canSet()) {
|
|
25
|
+
setState(prevState => ({
|
|
26
|
+
...prevState,
|
|
27
|
+
value,
|
|
28
|
+
loading: false
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}, error => {
|
|
33
|
+
if (canSet()) {
|
|
34
|
+
setState(prevState => ({
|
|
35
|
+
...prevState,
|
|
36
|
+
error,
|
|
37
|
+
loading: false
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return [state, execute];
|
|
44
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export { default as useAsync } from './hooks/useAsync';
|
|
|
10
10
|
export { default as useAsyncFn } from './hooks/useAsyncFn';
|
|
11
11
|
export { default as useDelayedValue } from './hooks/useDelayedValue';
|
|
12
12
|
export { default as useDelayedEffect } from './hooks/useDelayedEffect';
|
|
13
|
+
export { default as useAsyncFunction } from './hooks/useAsyncFunction';
|
package/index.js
CHANGED
|
@@ -9,4 +9,5 @@ export { default as useUnmount } from './hooks/useUnmount';
|
|
|
9
9
|
export { default as useAsync } from './hooks/useAsync';
|
|
10
10
|
export { default as useAsyncFn } from './hooks/useAsyncFn';
|
|
11
11
|
export { default as useDelayedValue } from './hooks/useDelayedValue';
|
|
12
|
-
export { default as useDelayedEffect } from './hooks/useDelayedEffect';
|
|
12
|
+
export { default as useDelayedEffect } from './hooks/useDelayedEffect';
|
|
13
|
+
export { default as useAsyncFunction } from './hooks/useAsyncFunction';
|