@take-out/hooks 0.2.9 → 0.3.0-1775080607310
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/dist/esm/index.js +13 -13
- package/dist/esm/index.js.map +1 -6
- package/package.json +3 -3
- package/src/useDebouncePrepend.ts +2 -2
- package/src/useDeepMemoizedObject.test.ts +13 -13
- package/src/useDeepMemoizedObject.ts +7 -7
- package/src/useEffectOnceGlobally.ts +1 -1
- package/src/useMemoStable.ts +1 -1
- package/src/useWarnIfDepsChange.ts +2 -2
- package/src/useWarnIfMemoChangesOften.ts +1 -1
- package/dist/cjs/index.js +0 -27
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useClickOutside.js +0 -37
- package/dist/cjs/useClickOutside.js.map +0 -6
- package/dist/cjs/useDebouncePrepend.js +0 -40
- package/dist/cjs/useDebouncePrepend.js.map +0 -6
- package/dist/cjs/useDeepMemoizedObject.js +0 -122
- package/dist/cjs/useDeepMemoizedObject.js.map +0 -6
- package/dist/cjs/useDeepMemoizedObject.test.js +0 -187
- package/dist/cjs/useDeepMemoizedObject.test.js.map +0 -6
- package/dist/cjs/useDeferredBoolean.js +0 -29
- package/dist/cjs/useDeferredBoolean.js.map +0 -6
- package/dist/cjs/useEffectOnceGlobally.js +0 -28
- package/dist/cjs/useEffectOnceGlobally.js.map +0 -6
- package/dist/cjs/useEvent.js +0 -25
- package/dist/cjs/useEvent.js.map +0 -6
- package/dist/cjs/useIsMounted.js +0 -27
- package/dist/cjs/useIsMounted.js.map +0 -6
- package/dist/cjs/useLastValue.js +0 -24
- package/dist/cjs/useLastValue.js.map +0 -6
- package/dist/cjs/useLastValueIf.js +0 -25
- package/dist/cjs/useLastValueIf.js.map +0 -6
- package/dist/cjs/useMemoStable.js +0 -26
- package/dist/cjs/useMemoStable.js.map +0 -6
- package/dist/cjs/useMemoizedObjectList.js +0 -36
- package/dist/cjs/useMemoizedObjectList.js.map +0 -6
- package/dist/cjs/useThrottle.js +0 -30
- package/dist/cjs/useThrottle.js.map +0 -6
- package/dist/cjs/useWarnIfDepsChange.js +0 -46
- package/dist/cjs/useWarnIfDepsChange.js.map +0 -6
- package/dist/cjs/useWarnIfMemoChangesOften.js +0 -29
- package/dist/cjs/useWarnIfMemoChangesOften.js.map +0 -6
- package/dist/esm/useClickOutside.js +0 -22
- package/dist/esm/useClickOutside.js.map +0 -6
- package/dist/esm/useDebouncePrepend.js +0 -25
- package/dist/esm/useDebouncePrepend.js.map +0 -6
- package/dist/esm/useDeepMemoizedObject.js +0 -106
- package/dist/esm/useDeepMemoizedObject.js.map +0 -6
- package/dist/esm/useDeepMemoizedObject.test.js +0 -188
- package/dist/esm/useDeepMemoizedObject.test.js.map +0 -6
- package/dist/esm/useDeferredBoolean.js +0 -13
- package/dist/esm/useDeferredBoolean.js.map +0 -6
- package/dist/esm/useEffectOnceGlobally.js +0 -12
- package/dist/esm/useEffectOnceGlobally.js.map +0 -6
- package/dist/esm/useEvent.js +0 -9
- package/dist/esm/useEvent.js.map +0 -6
- package/dist/esm/useIsMounted.js +0 -11
- package/dist/esm/useIsMounted.js.map +0 -6
- package/dist/esm/useLastValue.js +0 -8
- package/dist/esm/useLastValue.js.map +0 -6
- package/dist/esm/useLastValueIf.js +0 -9
- package/dist/esm/useLastValueIf.js.map +0 -6
- package/dist/esm/useMemoStable.js +0 -11
- package/dist/esm/useMemoStable.js.map +0 -6
- package/dist/esm/useMemoizedObjectList.js +0 -21
- package/dist/esm/useMemoizedObjectList.js.map +0 -6
- package/dist/esm/useThrottle.js +0 -15
- package/dist/esm/useThrottle.js.map +0 -6
- package/dist/esm/useWarnIfDepsChange.js +0 -31
- package/dist/esm/useWarnIfDepsChange.js.map +0 -6
- package/dist/esm/useWarnIfMemoChangesOften.js +0 -14
- package/dist/esm/useWarnIfMemoChangesOften.js.map +0 -6
package/dist/esm/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export * from "./useClickOutside";
|
|
2
|
-
export * from "./useDebouncePrepend";
|
|
3
|
-
export * from "./useDeepMemoizedObject";
|
|
4
|
-
export * from "./useDeferredBoolean";
|
|
5
|
-
export * from "./useEffectOnceGlobally";
|
|
6
|
-
export * from "./useIsMounted";
|
|
7
|
-
export * from "./useLastValue";
|
|
8
|
-
export * from "./useLastValueIf";
|
|
9
|
-
export * from "./useMemoizedObjectList";
|
|
10
|
-
export * from "./useMemoStable";
|
|
11
|
-
export * from "./useThrottle";
|
|
12
|
-
export * from "./useWarnIfDepsChange";
|
|
13
|
-
export * from "./useWarnIfMemoChangesOften";
|
|
1
|
+
export * from "./useClickOutside.mjs";
|
|
2
|
+
export * from "./useDebouncePrepend.mjs";
|
|
3
|
+
export * from "./useDeepMemoizedObject.mjs";
|
|
4
|
+
export * from "./useDeferredBoolean.mjs";
|
|
5
|
+
export * from "./useEffectOnceGlobally.mjs";
|
|
6
|
+
export * from "./useIsMounted.mjs";
|
|
7
|
+
export * from "./useLastValue.mjs";
|
|
8
|
+
export * from "./useLastValueIf.mjs";
|
|
9
|
+
export * from "./useMemoizedObjectList.mjs";
|
|
10
|
+
export * from "./useMemoStable.mjs";
|
|
11
|
+
export * from "./useThrottle.mjs";
|
|
12
|
+
export * from "./useWarnIfDepsChange.mjs";
|
|
13
|
+
export * from "./useWarnIfMemoChangesOften.mjs";
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@take-out/hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-1775080607310",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@take-out/helpers": "0.
|
|
38
|
+
"@take-out/helpers": "0.3.0-1775080607310"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "*",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@tamagui/build": "2.0.0-rc.
|
|
50
|
+
"@tamagui/build": "2.0.0-rc.36",
|
|
51
51
|
"react": "*",
|
|
52
52
|
"react-native": "*"
|
|
53
53
|
},
|
|
@@ -3,7 +3,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
|
3
3
|
|
|
4
4
|
export function useDebouncePrepend<T extends readonly { id: any }[]>(
|
|
5
5
|
list: T,
|
|
6
|
-
delay: number
|
|
6
|
+
delay: number,
|
|
7
7
|
): T {
|
|
8
8
|
const [current, setCurrent] = useState(list)
|
|
9
9
|
const [previous, setPrevious] = useState(list)
|
|
@@ -40,7 +40,7 @@ export function useDebouncePrepend<T extends readonly { id: any }[]>(
|
|
|
40
40
|
return newList
|
|
41
41
|
})
|
|
42
42
|
},
|
|
43
|
-
[previous, pendingUpdate, debouncedUpdate]
|
|
43
|
+
[previous, pendingUpdate, debouncedUpdate],
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
useEffect(() => {
|
|
@@ -4,7 +4,7 @@ import { deepMemoize, type Options } from './useDeepMemoizedObject'
|
|
|
4
4
|
|
|
5
5
|
function testMemoization<T>(
|
|
6
6
|
initialValue: T,
|
|
7
|
-
options?: Options
|
|
7
|
+
options?: Options,
|
|
8
8
|
): { current: T; update: (value: T) => void } {
|
|
9
9
|
let previousValue = initialValue
|
|
10
10
|
|
|
@@ -17,7 +17,7 @@ function testMemoization<T>(
|
|
|
17
17
|
value,
|
|
18
18
|
previousValue,
|
|
19
19
|
[],
|
|
20
|
-
options?.immutableToNestedChanges
|
|
20
|
+
options?.immutableToNestedChanges,
|
|
21
21
|
)
|
|
22
22
|
},
|
|
23
23
|
}
|
|
@@ -123,33 +123,33 @@ describe('useDeepMemoizedObject', () => {
|
|
|
123
123
|
expect(secondResult.server.channels).not.toBe(firstResult.server.channels)
|
|
124
124
|
expect(secondResult.server.channels[0]).not.toBe(firstResult.server.channels[0])
|
|
125
125
|
expect(secondResult.server.channels[0]!.messages).not.toBe(
|
|
126
|
-
firstResult.server.channels[0]!.messages
|
|
126
|
+
firstResult.server.channels[0]!.messages,
|
|
127
127
|
)
|
|
128
128
|
|
|
129
129
|
expect(secondResult.server.channels[0]!.messages[0]).toBe(
|
|
130
|
-
firstResult.server.channels[0]!.messages[0]
|
|
130
|
+
firstResult.server.channels[0]!.messages[0],
|
|
131
131
|
)
|
|
132
132
|
expect(secondResult.server.channels[0]!.messages[1]).toBe(
|
|
133
|
-
firstResult.server.channels[0]!.messages[1]
|
|
133
|
+
firstResult.server.channels[0]!.messages[1],
|
|
134
134
|
)
|
|
135
135
|
expect(secondResult.server.channels[0]!.messages[2]).not.toBe(
|
|
136
|
-
firstResult.server.channels[0]!.messages[2]
|
|
136
|
+
firstResult.server.channels[0]!.messages[2],
|
|
137
137
|
)
|
|
138
138
|
|
|
139
139
|
expect(secondResult.server.channels[0]!.messages[2]!.reactions).not.toBe(
|
|
140
|
-
firstResult.server.channels[0]!.messages[2]!.reactions
|
|
140
|
+
firstResult.server.channels[0]!.messages[2]!.reactions,
|
|
141
141
|
)
|
|
142
142
|
expect(secondResult.server.channels[0]!.messages[2]!.reactions![0]).toBe(
|
|
143
|
-
firstResult.server.channels[0]!.messages[2]!.reactions![0]
|
|
143
|
+
firstResult.server.channels[0]!.messages[2]!.reactions![0],
|
|
144
144
|
)
|
|
145
145
|
expect(secondResult.server.channels[0]!.messages[2]!.reactions![1]).toBe(
|
|
146
|
-
firstResult.server.channels[0]!.messages[2]!.reactions![1]
|
|
146
|
+
firstResult.server.channels[0]!.messages[2]!.reactions![1],
|
|
147
147
|
)
|
|
148
148
|
expect(secondResult.server.channels[0]!.messages[2]!.reactions![2]).not.toBe(
|
|
149
|
-
firstResult.server.channels[0]!.messages[2]!.reactions![2]
|
|
149
|
+
firstResult.server.channels[0]!.messages[2]!.reactions![2],
|
|
150
150
|
)
|
|
151
151
|
expect(secondResult.server.channels[0]!.messages[2]!.reactions![3]).toBe(
|
|
152
|
-
firstResult.server.channels[0]!.messages[2]!.reactions![3]
|
|
152
|
+
firstResult.server.channels[0]!.messages[2]!.reactions![3],
|
|
153
153
|
)
|
|
154
154
|
})
|
|
155
155
|
|
|
@@ -213,11 +213,11 @@ describe('useDeepMemoizedObject', () => {
|
|
|
213
213
|
expect(secondResult.server.channels[0]!.messages).not.toBe(originalMessages)
|
|
214
214
|
expect(secondResult.server.channels[0]!.messages[5]).not.toBe(originalMessage5)
|
|
215
215
|
expect(secondResult.server.channels[0]!.messages[5]!.reactions).not.toBe(
|
|
216
|
-
originalReactions
|
|
216
|
+
originalReactions,
|
|
217
217
|
)
|
|
218
218
|
// Verify the actual change was applied
|
|
219
219
|
expect(secondResult.server.channels[0]!.messages[5]!.reactions![2]!.updatedAt).toBe(
|
|
220
|
-
'2024-01-02'
|
|
220
|
+
'2024-01-02',
|
|
221
221
|
)
|
|
222
222
|
})
|
|
223
223
|
|
|
@@ -8,7 +8,7 @@ export interface Options {
|
|
|
8
8
|
|
|
9
9
|
export function shouldBeImmutable(
|
|
10
10
|
path: string[],
|
|
11
|
-
immutableToNestedChanges?: ImmutableToNestedChanges
|
|
11
|
+
immutableToNestedChanges?: ImmutableToNestedChanges,
|
|
12
12
|
): boolean {
|
|
13
13
|
if (!immutableToNestedChanges) return false
|
|
14
14
|
|
|
@@ -69,7 +69,7 @@ function deepMemoizeWithTracking<T>(
|
|
|
69
69
|
previous: T,
|
|
70
70
|
path: string[],
|
|
71
71
|
immutableToNestedChanges?: ImmutableToNestedChanges,
|
|
72
|
-
parentIsImmutable: boolean = false
|
|
72
|
+
parentIsImmutable: boolean = false,
|
|
73
73
|
): MemoResult<T> {
|
|
74
74
|
if (current === previous) {
|
|
75
75
|
return { value: previous, hasChanges: false, hasImmutableMutation: false }
|
|
@@ -107,7 +107,7 @@ function deepMemoizeWithTracking<T>(
|
|
|
107
107
|
previous[i],
|
|
108
108
|
itemPath,
|
|
109
109
|
immutableToNestedChanges,
|
|
110
|
-
false
|
|
110
|
+
false,
|
|
111
111
|
)
|
|
112
112
|
memoizedArray[i] = result.value
|
|
113
113
|
if (result.hasChanges) {
|
|
@@ -152,7 +152,7 @@ function deepMemoizeWithTracking<T>(
|
|
|
152
152
|
previousValue,
|
|
153
153
|
propPath,
|
|
154
154
|
immutableToNestedChanges,
|
|
155
|
-
shouldMutateInPlace
|
|
155
|
+
shouldMutateInPlace,
|
|
156
156
|
)
|
|
157
157
|
|
|
158
158
|
memoizedObject[key] = result.value
|
|
@@ -191,14 +191,14 @@ export function deepMemoize<T>(
|
|
|
191
191
|
current: T,
|
|
192
192
|
previous: T,
|
|
193
193
|
path: string[] = [],
|
|
194
|
-
immutableToNestedChanges?: ImmutableToNestedChanges
|
|
194
|
+
immutableToNestedChanges?: ImmutableToNestedChanges,
|
|
195
195
|
): T {
|
|
196
196
|
const result = deepMemoizeWithTracking(
|
|
197
197
|
current,
|
|
198
198
|
previous,
|
|
199
199
|
path,
|
|
200
200
|
immutableToNestedChanges,
|
|
201
|
-
false
|
|
201
|
+
false,
|
|
202
202
|
)
|
|
203
203
|
|
|
204
204
|
// If root has immutable mutation but no changes, we need to force a new reference
|
|
@@ -222,7 +222,7 @@ export function useDeepMemoizedObject<T>(value: T, options?: Options): T {
|
|
|
222
222
|
value,
|
|
223
223
|
previousValueRef.current,
|
|
224
224
|
[],
|
|
225
|
-
options?.immutableToNestedChanges
|
|
225
|
+
options?.immutableToNestedChanges,
|
|
226
226
|
)
|
|
227
227
|
|
|
228
228
|
previousValueRef.current = memoizedValue
|
|
@@ -12,7 +12,7 @@ type KeyType<T> = string | string[] | WithId | WithId[] | readonly WithId[] | un
|
|
|
12
12
|
*/
|
|
13
13
|
export function useEffectOnceGlobally<T extends KeyType<T>>(
|
|
14
14
|
key: T,
|
|
15
|
-
callback: T extends undefined ? () => void : (value: NonNullable<T>) => void
|
|
15
|
+
callback: T extends undefined ? () => void : (value: NonNullable<T>) => void,
|
|
16
16
|
) {
|
|
17
17
|
const keyString = !key
|
|
18
18
|
? undefined
|
package/src/useMemoStable.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface UseWarnIfDepsChangeOptions {
|
|
|
9
9
|
|
|
10
10
|
export function useWarnIfDepsChange<T extends readonly unknown[]>(
|
|
11
11
|
deps: T,
|
|
12
|
-
options: UseWarnIfDepsChangeOptions
|
|
12
|
+
options: UseWarnIfDepsChangeOptions,
|
|
13
13
|
): void {
|
|
14
14
|
const { maxChanges = 0, name, ignoreIndexBefore = 0 } = options
|
|
15
15
|
|
|
@@ -49,7 +49,7 @@ export function useWarnIfDepsChange<T extends readonly unknown[]>(
|
|
|
49
49
|
`🔄 useWarnIfDepsChange "${name}" is changing too often! Changed ${changeCountRef.current} times (max: ${maxChanges})`,
|
|
50
50
|
changedDeps,
|
|
51
51
|
`\n id (${id}) at:`,
|
|
52
|
-
getCurrentComponentStack('short')
|
|
52
|
+
getCurrentComponentStack('short'),
|
|
53
53
|
)
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -16,7 +16,7 @@ export const useWarnIfMemoChangesOften =
|
|
|
16
16
|
if (countRef.current > threshold) {
|
|
17
17
|
const warningName = name || 'Memoized value'
|
|
18
18
|
console.warn(
|
|
19
|
-
`🔄 ${warningName} is changing too often! Changed ${countRef.current} times (threshold: ${threshold})
|
|
19
|
+
`🔄 ${warningName} is changing too often! Changed ${countRef.current} times (threshold: ${threshold})`,
|
|
20
20
|
)
|
|
21
21
|
}
|
|
22
22
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var index_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(index_exports);
|
|
14
|
-
__reExport(index_exports, require("./useClickOutside"), module.exports);
|
|
15
|
-
__reExport(index_exports, require("./useDebouncePrepend"), module.exports);
|
|
16
|
-
__reExport(index_exports, require("./useDeepMemoizedObject"), module.exports);
|
|
17
|
-
__reExport(index_exports, require("./useDeferredBoolean"), module.exports);
|
|
18
|
-
__reExport(index_exports, require("./useEffectOnceGlobally"), module.exports);
|
|
19
|
-
__reExport(index_exports, require("./useIsMounted"), module.exports);
|
|
20
|
-
__reExport(index_exports, require("./useLastValue"), module.exports);
|
|
21
|
-
__reExport(index_exports, require("./useLastValueIf"), module.exports);
|
|
22
|
-
__reExport(index_exports, require("./useMemoizedObjectList"), module.exports);
|
|
23
|
-
__reExport(index_exports, require("./useMemoStable"), module.exports);
|
|
24
|
-
__reExport(index_exports, require("./useThrottle"), module.exports);
|
|
25
|
-
__reExport(index_exports, require("./useWarnIfDepsChange"), module.exports);
|
|
26
|
-
__reExport(index_exports, require("./useWarnIfMemoChangesOften"), module.exports);
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,8BAAd;AACA,0BAAc,iCADd;AAEA,0BAAc,oCAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,oCAJd;AAKA,0BAAc,2BALd;AAMA,0BAAc,2BANd;AAOA,0BAAc,6BAPd;AAQA,0BAAc,oCARd;AASA,0BAAc,4BATd;AAUA,0BAAc,0BAVd;AAWA,0BAAc,kCAXd;AAYA,0BAAc,wCAZd;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var useClickOutside_exports = {};
|
|
16
|
-
__export(useClickOutside_exports, {
|
|
17
|
-
useClickOutside: () => useClickOutside
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(useClickOutside_exports);
|
|
20
|
-
var import_helpers = require("@take-out/helpers"), import_react = require("react");
|
|
21
|
-
const useClickOutside = ({
|
|
22
|
-
ref,
|
|
23
|
-
active,
|
|
24
|
-
onClickOutside
|
|
25
|
-
}) => {
|
|
26
|
-
(0, import_react.useEffect)(() => {
|
|
27
|
-
if (!import_helpers.isWeb || !active || !onClickOutside) return;
|
|
28
|
-
const handleClickOutside = (e) => {
|
|
29
|
-
const node = ref.current;
|
|
30
|
-
node && e.target instanceof HTMLElement && (node.contains(e.target) || onClickOutside());
|
|
31
|
-
};
|
|
32
|
-
return document.addEventListener("click", handleClickOutside), () => {
|
|
33
|
-
document.removeEventListener("click", handleClickOutside);
|
|
34
|
-
};
|
|
35
|
-
}, [ref, active, onClickOutside]);
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=useClickOutside.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useClickOutside.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsB,8BACtB,eAA0B;AAQnB,MAAM,kBAAkB,CAAC;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,MAA4B;AAC1B,8BAAU,MAAM;AAGd,QAFI,CAAC,wBACD,CAAC,UACD,CAAC,eAAgB;AAErB,UAAM,qBAAqB,CAAC,MAAkB;AAC5C,YAAM,OAAO,IAAI;AACjB,MAAK,QACC,EAAE,kBAAkB,gBACrB,KAAK,SAAS,EAAE,MAAM,KACzB,eAAe;AAAA,IAEnB;AAEA,oBAAS,iBAAiB,SAAS,kBAAkB,GAC9C,MAAM;AACX,eAAS,oBAAoB,SAAS,kBAAkB;AAAA,IAC1D;AAAA,EACF,GAAG,CAAC,KAAK,QAAQ,cAAc,CAAC;AAClC;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var useDebouncePrepend_exports = {};
|
|
16
|
-
__export(useDebouncePrepend_exports, {
|
|
17
|
-
useDebouncePrepend: () => useDebouncePrepend
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(useDebouncePrepend_exports);
|
|
20
|
-
var import_helpers = require("@take-out/helpers"), import_react = require("react");
|
|
21
|
-
function useDebouncePrepend(list, delay) {
|
|
22
|
-
const [current, setCurrent] = (0, import_react.useState)(list), [previous, setPrevious] = (0, import_react.useState)(list), [pendingUpdate, setPendingUpdate] = (0, import_react.useState)(null), debouncedUpdate = (0, import_react.useMemo)(() => (0, import_helpers.debounce)((newList) => {
|
|
23
|
-
setCurrent(newList), setPendingUpdate(null);
|
|
24
|
-
}, delay), [delay]), updateState = (0, import_react.useCallback)(
|
|
25
|
-
(newList) => {
|
|
26
|
-
setCurrent((prevCurrent) => {
|
|
27
|
-
const currentList = pendingUpdate || prevCurrent;
|
|
28
|
-
return newList.length > previous.length && newList[0]?.id !== previous[0]?.id ? (debouncedUpdate.cancel(), setPendingUpdate(newList), debouncedUpdate(newList), currentList) : (debouncedUpdate.cancel(), setPendingUpdate(null), newList);
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
[previous, pendingUpdate, debouncedUpdate]
|
|
32
|
-
);
|
|
33
|
-
return (0, import_react.useEffect)(() => {
|
|
34
|
-
if (list !== previous)
|
|
35
|
-
return setPrevious(list), updateState(list), () => {
|
|
36
|
-
debouncedUpdate.cancel();
|
|
37
|
-
};
|
|
38
|
-
}, [list, previous, updateState, debouncedUpdate]), current;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=useDebouncePrepend.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useDebouncePrepend.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAyB,8BACzB,eAA0D;AAEnD,SAAS,mBACd,MACA,OACG;AACH,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,IAAI,GACrC,CAAC,UAAU,WAAW,QAAI,uBAAS,IAAI,GACvC,CAAC,eAAe,gBAAgB,QAAI,uBAAmB,IAAI,GAE3D,sBAAkB,sBAAQ,UACvB,yBAAS,CAAC,YAAe;AAC9B,eAAW,OAAO,GAClB,iBAAiB,IAAI;AAAA,EACvB,GAAG,KAAK,GACP,CAAC,KAAK,CAAC,GAEJ,kBAAc;AAAA,IAClB,CAAC,YAAe;AACd,iBAAW,CAAC,gBAAgB;AAE1B,cAAM,cAAc,iBAAiB;AAMrC,eAFE,QAAQ,SAAS,SAAS,UAAU,QAAQ,CAAC,GAAG,OAAO,SAAS,CAAC,GAAG,MAIpE,gBAAgB,OAAO,GACvB,iBAAiB,OAAO,GACxB,gBAAgB,OAAO,GAChB,gBAIT,gBAAgB,OAAO,GACvB,iBAAiB,IAAI,GACd;AAAA,MACT,CAAC;AAAA,IACH;AAAA,IACA,CAAC,UAAU,eAAe,eAAe;AAAA,EAC3C;AAEA,qCAAU,MAAM;AACd,QAAI,SAAS;AAKb,yBAAY,IAAI,GAGhB,YAAY,IAAI,GAET,MAAM;AACX,wBAAgB,OAAO;AAAA,MACzB;AAAA,EACF,GAAG,CAAC,MAAM,UAAU,aAAa,eAAe,CAAC,GAE1C;AACT;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var useDeepMemoizedObject_exports = {};
|
|
16
|
-
__export(useDeepMemoizedObject_exports, {
|
|
17
|
-
deepMemoize: () => deepMemoize,
|
|
18
|
-
shouldBeImmutable: () => shouldBeImmutable,
|
|
19
|
-
useDeepMemoizedObject: () => useDeepMemoizedObject
|
|
20
|
-
});
|
|
21
|
-
module.exports = __toCommonJS(useDeepMemoizedObject_exports);
|
|
22
|
-
var import_react = require("react");
|
|
23
|
-
function shouldBeImmutable(path, immutableToNestedChanges) {
|
|
24
|
-
if (!immutableToNestedChanges) return !1;
|
|
25
|
-
const currentPath = path.join(".");
|
|
26
|
-
for (const pattern in immutableToNestedChanges)
|
|
27
|
-
if (immutableToNestedChanges[pattern] && currentPath === pattern)
|
|
28
|
-
return !0;
|
|
29
|
-
return !1;
|
|
30
|
-
}
|
|
31
|
-
function deepMutateInPlace(target, source) {
|
|
32
|
-
if (!(typeof target != "object" || target === null || typeof source != "object" || source === null)) {
|
|
33
|
-
if (Array.isArray(target) && Array.isArray(source)) {
|
|
34
|
-
target.length = 0, target.push(...source);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
for (const key in source) {
|
|
38
|
-
const targetValue = target[key], sourceValue = source[key];
|
|
39
|
-
typeof sourceValue == "object" && sourceValue !== null && typeof targetValue == "object" && targetValue !== null ? deepMutateInPlace(targetValue, sourceValue) : target[key] = sourceValue;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, parentIsImmutable = !1) {
|
|
44
|
-
if (current === previous)
|
|
45
|
-
return { value: previous, hasChanges: !1, hasImmutableMutation: !1 };
|
|
46
|
-
if (typeof current != "object" || current === null)
|
|
47
|
-
return { value: current, hasChanges: !0, hasImmutableMutation: !1 };
|
|
48
|
-
if (typeof previous != "object" || previous === null)
|
|
49
|
-
return { value: current, hasChanges: !0, hasImmutableMutation: !1 };
|
|
50
|
-
const shouldMutateInPlace = shouldBeImmutable(path, immutableToNestedChanges) || parentIsImmutable;
|
|
51
|
-
if (Array.isArray(current)) {
|
|
52
|
-
if (!Array.isArray(previous))
|
|
53
|
-
return { value: current, hasChanges: !0, hasImmutableMutation: !1 };
|
|
54
|
-
if (current.length !== previous.length)
|
|
55
|
-
return { value: current, hasChanges: !0, hasImmutableMutation: !1 };
|
|
56
|
-
let hasChanges2 = !1, hasImmutableMutation2 = !1;
|
|
57
|
-
const memoizedArray = [];
|
|
58
|
-
for (let i = 0; i < current.length; i++) {
|
|
59
|
-
const itemPath = [...path, String(i)], result = deepMemoizeWithTracking(
|
|
60
|
-
current[i],
|
|
61
|
-
previous[i],
|
|
62
|
-
itemPath,
|
|
63
|
-
immutableToNestedChanges,
|
|
64
|
-
!1
|
|
65
|
-
);
|
|
66
|
-
memoizedArray[i] = result.value, result.hasChanges && (hasChanges2 = !0), result.hasImmutableMutation && (hasImmutableMutation2 = !0);
|
|
67
|
-
}
|
|
68
|
-
return hasChanges2 || hasImmutableMutation2 ? { value: memoizedArray, hasChanges: !0, hasImmutableMutation: !1 } : { value: previous, hasChanges: !1, hasImmutableMutation: !1 };
|
|
69
|
-
}
|
|
70
|
-
const currentKeys = Object.keys(current), previousKeys = Object.keys(previous);
|
|
71
|
-
if (currentKeys.length !== previousKeys.length)
|
|
72
|
-
return { value: current, hasChanges: !0, hasImmutableMutation: !1 };
|
|
73
|
-
if (!currentKeys.every((key) => key in previous))
|
|
74
|
-
return { value: current, hasChanges: !0, hasImmutableMutation: !1 };
|
|
75
|
-
let hasChanges = !1, hasImmutableMutation = !1;
|
|
76
|
-
const memoizedObject = {};
|
|
77
|
-
for (const key of currentKeys) {
|
|
78
|
-
const propPath = [...path, key], currentValue = current[key], previousValue = previous[key], result = deepMemoizeWithTracking(
|
|
79
|
-
currentValue,
|
|
80
|
-
previousValue,
|
|
81
|
-
propPath,
|
|
82
|
-
immutableToNestedChanges,
|
|
83
|
-
shouldMutateInPlace
|
|
84
|
-
);
|
|
85
|
-
memoizedObject[key] = result.value, result.hasChanges && (hasChanges = !0), result.hasImmutableMutation && (hasImmutableMutation = !0);
|
|
86
|
-
}
|
|
87
|
-
if (shouldMutateInPlace && (hasChanges || hasImmutableMutation)) {
|
|
88
|
-
if (parentIsImmutable)
|
|
89
|
-
deepMutateInPlace(previous, current);
|
|
90
|
-
else
|
|
91
|
-
for (const key of currentKeys)
|
|
92
|
-
previous[key] = memoizedObject[key];
|
|
93
|
-
return { value: previous, hasChanges: !1, hasImmutableMutation: !0 };
|
|
94
|
-
}
|
|
95
|
-
return hasChanges || hasImmutableMutation ? { value: memoizedObject, hasChanges: !0, hasImmutableMutation: !1 } : { value: previous, hasChanges: !1, hasImmutableMutation: !1 };
|
|
96
|
-
}
|
|
97
|
-
function deepMemoize(current, previous, path = [], immutableToNestedChanges) {
|
|
98
|
-
const result = deepMemoizeWithTracking(
|
|
99
|
-
current,
|
|
100
|
-
previous,
|
|
101
|
-
path,
|
|
102
|
-
immutableToNestedChanges,
|
|
103
|
-
!1
|
|
104
|
-
);
|
|
105
|
-
if (path.length === 0 && result.hasImmutableMutation && !result.hasChanges) {
|
|
106
|
-
if (Array.isArray(result.value))
|
|
107
|
-
return [...result.value];
|
|
108
|
-
if (typeof result.value == "object" && result.value !== null)
|
|
109
|
-
return { ...result.value };
|
|
110
|
-
}
|
|
111
|
-
return result.value;
|
|
112
|
-
}
|
|
113
|
-
function useDeepMemoizedObject(value, options) {
|
|
114
|
-
const previousValueRef = (0, import_react.useRef)(value), memoizedValue = deepMemoize(
|
|
115
|
-
value,
|
|
116
|
-
previousValueRef.current,
|
|
117
|
-
[],
|
|
118
|
-
options?.immutableToNestedChanges
|
|
119
|
-
);
|
|
120
|
-
return previousValueRef.current = memoizedValue, memoizedValue;
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=useDeepMemoizedObject.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useDeepMemoizedObject.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuB;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