@darajs/ui-utils 0.4.8
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 +201 -0
- package/dist/clipboard-utils.d.ts +26 -0
- package/dist/clipboard-utils.d.ts.map +1 -0
- package/dist/clipboard-utils.js +67 -0
- package/dist/clipboard-utils.js.map +1 -0
- package/dist/constants.d.ts +35 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +37 -0
- package/dist/constants.js.map +1 -0
- package/dist/get-status-color.d.ts +32 -0
- package/dist/get-status-color.d.ts.map +1 -0
- package/dist/get-status-color.js +34 -0
- package/dist/get-status-color.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/path-utils.d.ts +23 -0
- package/dist/path-utils.d.ts.map +1 -0
- package/dist/path-utils.js +29 -0
- package/dist/path-utils.js.map +1 -0
- package/dist/request-utils.d.ts +67 -0
- package/dist/request-utils.d.ts.map +1 -0
- package/dist/request-utils.js +177 -0
- package/dist/request-utils.js.map +1 -0
- package/dist/rx-utils.d.ts +9 -0
- package/dist/rx-utils.d.ts.map +1 -0
- package/dist/rx-utils.js +33 -0
- package/dist/rx-utils.js.map +1 -0
- package/dist/use-d3-axis.d.ts +45 -0
- package/dist/use-d3-axis.d.ts.map +1 -0
- package/dist/use-d3-axis.js +83 -0
- package/dist/use-d3-axis.js.map +1 -0
- package/dist/use-deep-compare.d.ts +13 -0
- package/dist/use-deep-compare.d.ts.map +1 -0
- package/dist/use-deep-compare.js +37 -0
- package/dist/use-deep-compare.js.map +1 -0
- package/dist/use-dimensions.d.ts +22 -0
- package/dist/use-dimensions.d.ts.map +1 -0
- package/dist/use-dimensions.js +47 -0
- package/dist/use-dimensions.js.map +1 -0
- package/dist/use-intersection-observer.d.ts +30 -0
- package/dist/use-intersection-observer.d.ts.map +1 -0
- package/dist/use-intersection-observer.js +51 -0
- package/dist/use-intersection-observer.js.map +1 -0
- package/dist/use-on-click-outside.d.ts +9 -0
- package/dist/use-on-click-outside.d.ts.map +1 -0
- package/dist/use-on-click-outside.js +42 -0
- package/dist/use-on-click-outside.js.map +1 -0
- package/dist/use-throttle.d.ts +25 -0
- package/dist/use-throttle.d.ts.map +1 -0
- package/dist/use-throttle.js +49 -0
- package/dist/use-throttle.js.map +1 -0
- package/dist/use-update-effect.d.ts +26 -0
- package/dist/use-update-effect.d.ts.map +1 -0
- package/dist/use-update-effect.js +36 -0
- package/dist/use-update-effect.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { useEffect, useState } from 'react';
|
|
18
|
+
/**
|
|
19
|
+
* The useIntersectionObserver hook allows a component to track whether an element is intersecting with an ancestor
|
|
20
|
+
* element or with a top-level document's viewport.
|
|
21
|
+
*
|
|
22
|
+
* @param ref the ref to the element that is to be observed
|
|
23
|
+
* @param rootMargin the amount of the element that is to be intersecting for the observer's callback to be executed.
|
|
24
|
+
* @param threshold Either a single number or an array of numbers which indicate at what percentage of the target's
|
|
25
|
+
* visibility the observer's callback should be executed.
|
|
26
|
+
* @returns boolean indicating whether element is intersecting or not
|
|
27
|
+
*/
|
|
28
|
+
function useIntersectionObserver(ref, rootMargin = '0px', threshold = 1.0) {
|
|
29
|
+
const [isIntersecting, setIntersecting] = useState(false);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const observer = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting), {
|
|
32
|
+
rootMargin,
|
|
33
|
+
threshold,
|
|
34
|
+
});
|
|
35
|
+
if (ref.current) {
|
|
36
|
+
observer.observe(ref.current);
|
|
37
|
+
}
|
|
38
|
+
const currentRef = ref.current;
|
|
39
|
+
return () => {
|
|
40
|
+
if (currentRef) {
|
|
41
|
+
observer.unobserve(currentRef);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
observer.disconnect();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, [ref, rootMargin, threshold]);
|
|
48
|
+
return isIntersecting;
|
|
49
|
+
}
|
|
50
|
+
export default useIntersectionObserver;
|
|
51
|
+
//# sourceMappingURL=use-intersection-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intersection-observer.js","sourceRoot":"","sources":["../src/use-intersection-observer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAoB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9D;;;;;;;;;GASG;AAEH,SAAS,uBAAuB,CAC5B,GAAwB,EACxB,UAAU,GAAG,KAAK,EAClB,SAAS,GAAG,GAAG;IAEf,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAEnE,SAAS,CAAC,GAAG,EAAE;QACX,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;YAC1F,UAAU;YACV,SAAS;SACZ,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YACd,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAED,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC;QAE/B,OAAO,GAAG,EAAE;YACR,IAAI,UAAU,EAAE,CAAC;gBACb,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACJ,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC1B,CAAC;QACL,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;IACjC,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The useOnClickOutside hook allows for a component to track whether a click was made outside an element
|
|
3
|
+
*
|
|
4
|
+
* @param element any element that the hook should handle the click outside of
|
|
5
|
+
* @param handler callback for when a click outside of the given element occurs
|
|
6
|
+
*/
|
|
7
|
+
declare function useOnClickOutside(element: HTMLElement, handler: () => void): void;
|
|
8
|
+
export default useOnClickOutside;
|
|
9
|
+
//# sourceMappingURL=use-on-click-outside.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-on-click-outside.d.ts","sourceRoot":"","sources":["../src/use-on-click-outside.tsx"],"names":[],"mappings":"AAkBA;;;;;GAKG;AAEH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAgB1E;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { useEffect } from 'react';
|
|
18
|
+
/**
|
|
19
|
+
* The useOnClickOutside hook allows for a component to track whether a click was made outside an element
|
|
20
|
+
*
|
|
21
|
+
* @param element any element that the hook should handle the click outside of
|
|
22
|
+
* @param handler callback for when a click outside of the given element occurs
|
|
23
|
+
*/
|
|
24
|
+
function useOnClickOutside(element, handler) {
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const listener = (event) => {
|
|
27
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
28
|
+
if (!element || element.contains(event.target)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
handler();
|
|
32
|
+
};
|
|
33
|
+
document.addEventListener('mousedown', listener);
|
|
34
|
+
document.addEventListener('touchstart', listener);
|
|
35
|
+
return () => {
|
|
36
|
+
document.removeEventListener('mousedown', listener);
|
|
37
|
+
document.removeEventListener('touchstart', listener);
|
|
38
|
+
};
|
|
39
|
+
}, [element, handler]);
|
|
40
|
+
}
|
|
41
|
+
export default useOnClickOutside;
|
|
42
|
+
//# sourceMappingURL=use-on-click-outside.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-on-click-outside.js","sourceRoot":"","sources":["../src/use-on-click-outside.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;GAKG;AAEH,SAAS,iBAAiB,CAAC,OAAoB,EAAE,OAAmB;IAChE,SAAS,CAAC,GAAG,EAAE;QACX,MAAM,QAAQ,GAAG,CAAC,KAAiB,EAAQ,EAAE;YACzC,8DAA8D;YAC9D,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAc,CAAC,EAAE,CAAC;gBACrD,OAAO;YACX,CAAC;YACD,OAAO,EAAE,CAAC;QACd,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,QAAQ,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAClD,OAAO,GAAG,EAAE;YACR,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACpD,QAAQ,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACzD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface ThrottleOptions {
|
|
2
|
+
leading?: boolean;
|
|
3
|
+
trailing?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Create a throttled version of the callback passed. A hook is required to persist the state of the throttle between
|
|
7
|
+
* renders
|
|
8
|
+
*
|
|
9
|
+
* @param cb the function to throttle
|
|
10
|
+
* @param delay how long between each throttled event
|
|
11
|
+
* @param options whether to throttle on the leading or trailing edge, see lodash throttle docs for context
|
|
12
|
+
*/
|
|
13
|
+
export declare function useThrottle(cb: (...args: Array<any>) => any, delay: number, options?: ThrottleOptions): (...args: Array<any>) => any;
|
|
14
|
+
/**
|
|
15
|
+
* A throttled version of useState that allows for state to only be updated every so often. This is useful when setting
|
|
16
|
+
* state that may trigger network requests. Exposes a throttled and immediate version of the setState function for
|
|
17
|
+
* greater control
|
|
18
|
+
*
|
|
19
|
+
* @param initialValue the initial state value
|
|
20
|
+
* @param delay how long between each throttled update
|
|
21
|
+
* @param options whether to throttle on the leading or trailing edge, see lodash throttle docs for context
|
|
22
|
+
*/
|
|
23
|
+
export declare function useThrottledState<T>(initialValue: T, delay: number, options?: ThrottleOptions): [T, (value: T) => void, (value: T) => void];
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=use-throttle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-throttle.d.ts","sourceRoot":"","sources":["../src/use-throttle.tsx"],"names":[],"mappings":"AAmBA,UAAU,eAAe;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACvB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,EAChC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GAC1B,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAU9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAC/B,YAAY,EAAE,CAAC,EACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoD,GAC9D,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAI7C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import throttle from 'lodash/throttle';
|
|
18
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
19
|
+
/**
|
|
20
|
+
* Create a throttled version of the callback passed. A hook is required to persist the state of the throttle between
|
|
21
|
+
* renders
|
|
22
|
+
*
|
|
23
|
+
* @param cb the function to throttle
|
|
24
|
+
* @param delay how long between each throttled event
|
|
25
|
+
* @param options whether to throttle on the leading or trailing edge, see lodash throttle docs for context
|
|
26
|
+
*/
|
|
27
|
+
export function useThrottle(cb, delay, options) {
|
|
28
|
+
const cbRef = useRef(cb);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
cbRef.current = cb;
|
|
31
|
+
});
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
return useCallback(throttle((...args) => cbRef.current(...args), delay, options), [delay, options]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A throttled version of useState that allows for state to only be updated every so often. This is useful when setting
|
|
37
|
+
* state that may trigger network requests. Exposes a throttled and immediate version of the setState function for
|
|
38
|
+
* greater control
|
|
39
|
+
*
|
|
40
|
+
* @param initialValue the initial state value
|
|
41
|
+
* @param delay how long between each throttled update
|
|
42
|
+
* @param options whether to throttle on the leading or trailing edge, see lodash throttle docs for context
|
|
43
|
+
*/
|
|
44
|
+
export function useThrottledState(initialValue, delay, options = { leading: false, trailing: true }) {
|
|
45
|
+
const [value, setValue] = useState(initialValue);
|
|
46
|
+
const throttledSetValue = useThrottle(setValue, delay, options);
|
|
47
|
+
return [value, throttledSetValue, setValue];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=use-throttle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-throttle.js","sourceRoot":"","sources":["../src/use-throttle.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOjE;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACvB,EAAgC,EAChC,KAAa,EACb,OAAyB;IAEzB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACzB,SAAS,CAAC,GAAG,EAAE;QACX,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,uDAAuD;IACvD,OAAO,WAAW,CACd,QAAQ,CAAC,CAAC,GAAG,IAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EACzE,CAAC,KAAK,EAAE,OAAO,CAAC,CACnB,CAAC;AACN,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC7B,YAAe,EACf,KAAa,EACb,UAA2B,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;IAE7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IACjD,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { useEffect } from 'react';
|
|
18
|
+
/**
|
|
19
|
+
* Like React useEffect except ignores the first invocation.
|
|
20
|
+
*
|
|
21
|
+
* @param effect Imperative function that can return a cleanup function
|
|
22
|
+
* @param deps If present, effect will only activate if the values in the list change.
|
|
23
|
+
*/
|
|
24
|
+
declare const useUpdateEffect: typeof useEffect;
|
|
25
|
+
export default useUpdateEffect;
|
|
26
|
+
//# sourceMappingURL=use-update-effect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-update-effect.d.ts","sourceRoot":"","sources":["../src/use-update-effect.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,SAAS,EAAU,MAAM,OAAO,CAAC;AAE1C;;;;;GAKG;AACH,QAAA,MAAM,eAAe,EAAE,OAAO,SAW7B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { useEffect, useRef } from 'react';
|
|
18
|
+
/**
|
|
19
|
+
* Like React useEffect except ignores the first invocation.
|
|
20
|
+
*
|
|
21
|
+
* @param effect Imperative function that can return a cleanup function
|
|
22
|
+
* @param deps If present, effect will only activate if the values in the list change.
|
|
23
|
+
*/
|
|
24
|
+
const useUpdateEffect = (effect, deps) => {
|
|
25
|
+
const isMounted = useRef(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isMounted.current) {
|
|
28
|
+
isMounted.current = true;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return effect();
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, deps);
|
|
34
|
+
};
|
|
35
|
+
export default useUpdateEffect;
|
|
36
|
+
//# sourceMappingURL=use-update-effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-update-effect.js","sourceRoot":"","sources":["../src/use-update-effect.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,eAAe,GAAqB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;IACvD,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEhC,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YACrB,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;YACzB,OAAO;QACX,CAAC;QACD,OAAO,MAAM,EAAE,CAAC;QAChB,uDAAuD;IAC3D,CAAC,EAAE,IAAI,CAAC,CAAC;AACb,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@darajs/ui-utils",
|
|
3
|
+
"version": "0.4.8",
|
|
4
|
+
"description": "General utilities for the Dara UI framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"jsnext:main": "dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rimraf dist && tsc",
|
|
10
|
+
"lint": "eslint src --ext .tsx --max-warnings 0 && stylelint './src/**/*.tsx'",
|
|
11
|
+
"format": "prettier src --write",
|
|
12
|
+
"format:check": "prettier src --check",
|
|
13
|
+
"lint:fix": "eslint src --ext .tsx --max-warnings 0 --fix && stylelint './src/**/*.tsx' --fix",
|
|
14
|
+
"test-watch": "jest --watch"
|
|
15
|
+
},
|
|
16
|
+
"author": "Krzysztof Bielikowicz <krzysztof@causalens.com>",
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"prettier": "@darajs/prettier-config",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@babel/core": "^7.15.5",
|
|
21
|
+
"@babel/preset-env": "^7.15.6",
|
|
22
|
+
"@babel/preset-react": "^7.14.5",
|
|
23
|
+
"@darajs/eslint-config": "0.4.8",
|
|
24
|
+
"@darajs/prettier-config": "0.4.8",
|
|
25
|
+
"@darajs/stylelint-config": "0.4.8",
|
|
26
|
+
"@types/jest": "^25.2.3",
|
|
27
|
+
"@types/lodash": "^4.14.155",
|
|
28
|
+
"@types/react": "^18.0",
|
|
29
|
+
"babel-jest": "^29.5.0",
|
|
30
|
+
"babel-loader": "^8.2.2",
|
|
31
|
+
"babel-plugin-styled-components": "^1.13.2",
|
|
32
|
+
"eslint": "^7.32.0",
|
|
33
|
+
"jest": "^29.5.0",
|
|
34
|
+
"prettier": "^3.0.0",
|
|
35
|
+
"react-test-renderer": "^17.0",
|
|
36
|
+
"rimraf": "^3.0.2",
|
|
37
|
+
"stylelint": "^15.0.0",
|
|
38
|
+
"ts-jest": "^29.1.0",
|
|
39
|
+
"typescript": "^5.0.4"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"d3-scale": "3.2.1",
|
|
43
|
+
"lodash": "4.17.21",
|
|
44
|
+
"nanoid": "^3.3.0",
|
|
45
|
+
"react": "^18.0",
|
|
46
|
+
"rxjs": "^7.0.0"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist"
|
|
50
|
+
],
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "28ec9380d883a6f5f0fcd05f27beda7e412fa95f"
|
|
55
|
+
}
|