@uxf/core-react 11.72.3 → 11.74.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/README.md +70 -0
- package/package.json +1 -1
- package/clickable/_use-simulated-button.d.ts +0 -17
- package/clickable/_use-simulated-button.js +0 -61
- package/clickable/add-busy-and-disabled-classnames.d.ts +0 -9
- package/clickable/add-busy-and-disabled-classnames.js +0 -17
- package/clickable/types.d.ts +0 -3
- package/clickable/types.js +0 -2
- package/clickable/use-anchor-props.d.ts +0 -9
- package/clickable/use-anchor-props.js +0 -67
- package/clickable/use-button-props.d.ts +0 -7
- package/clickable/use-button-props.js +0 -60
- package/clickable/use-clickable-props.d.ts +0 -9
- package/clickable/use-clickable-props.js +0 -45
- package/components/hide.d.ts +0 -7
- package/components/hide.js +0 -13
- package/components/show.d.ts +0 -7
- package/components/show.js +0 -13
- package/components/viewport-height-polyfill.d.ts +0 -2
- package/components/viewport-height-polyfill.js +0 -49
- package/hooks/use-body-scroll-lock.d.ts +0 -6
- package/hooks/use-body-scroll-lock.js +0 -34
- package/hooks/use-debounce.d.ts +0 -1
- package/hooks/use-debounce.js +0 -15
- package/hooks/use-focus-return.d.ts +0 -1
- package/hooks/use-focus-return.js +0 -34
- package/hooks/use-focus-trap.d.ts +0 -2
- package/hooks/use-focus-trap.js +0 -145
- package/hooks/use-increment.d.ts +0 -2
- package/hooks/use-increment.js +0 -11
- package/hooks/use-increment.test.d.ts +0 -1
- package/hooks/use-increment.test.js +0 -61
- package/hooks/use-input-focus.d.ts +0 -7
- package/hooks/use-input-focus.js +0 -26
- package/hooks/use-is-mounted.d.ts +0 -1
- package/hooks/use-is-mounted.js +0 -9
- package/hooks/use-isomorphic-layout-effect.d.ts +0 -2
- package/hooks/use-isomorphic-layout-effect.js +0 -6
- package/hooks/use-key.d.ts +0 -10
- package/hooks/use-key.js +0 -27
- package/hooks/use-latest.d.ts +0 -1
- package/hooks/use-latest.js +0 -9
- package/hooks/use-media-query.d.ts +0 -1
- package/hooks/use-media-query.js +0 -18
- package/hooks/use-min-window-width.d.ts +0 -1
- package/hooks/use-min-window-width.js +0 -28
- package/hooks/use-mouse-drag-to-scroll.d.ts +0 -2
- package/hooks/use-mouse-drag-to-scroll.js +0 -38
- package/hooks/use-on-mount.d.ts +0 -2
- package/hooks/use-on-mount.js +0 -9
- package/hooks/use-on-unmount.d.ts +0 -2
- package/hooks/use-on-unmount.js +0 -14
- package/hooks/use-on-update.d.ts +0 -2
- package/hooks/use-on-update.js +0 -14
- package/hooks/use-pagination.d.ts +0 -2
- package/hooks/use-pagination.js +0 -20
- package/hooks/use-pagination.test.d.ts +0 -1
- package/hooks/use-pagination.test.js +0 -58
- package/hooks/use-previous.d.ts +0 -1
- package/hooks/use-previous.js +0 -11
- package/hooks/use-raf-state.d.ts +0 -2
- package/hooks/use-raf-state.js +0 -17
- package/hooks/use-toggle.d.ts +0 -2
- package/hooks/use-toggle.js +0 -11
- package/hooks/use-toggle.test.d.ts +0 -1
- package/hooks/use-toggle.test.js +0 -46
- package/hooks/use-window-scroll.d.ts +0 -4
- package/hooks/use-window-scroll.js +0 -21
- package/hooks/use-window-scroll.test.d.ts +0 -1
- package/hooks/use-window-scroll.test.js +0 -47
- package/hooks/use-window-size.d.ts +0 -4
- package/hooks/use-window-size.js +0 -18
- package/hooks/use-window-size.test.d.ts +0 -1
- package/hooks/use-window-size.test.js +0 -36
- package/string/nl2br.d.ts +0 -2
- package/string/nl2br.js +0 -37
- package/swipeable/types.d.ts +0 -152
- package/swipeable/types.js +0 -7
- package/swipeable/use-swipeable.d.ts +0 -3
- package/swipeable/use-swipeable.js +0 -314
- package/utils/compose-refs.d.ts +0 -2
- package/utils/compose-refs.js +0 -15
- package/utils/compose-refs.test.d.ts +0 -1
- package/utils/compose-refs.test.js +0 -41
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UP = exports.RIGHT = exports.LEFT = exports.DOWN = void 0;
|
|
4
|
-
exports.useSwipeable = useSwipeable;
|
|
5
|
-
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const types_1 = require("./types");
|
|
8
|
-
Object.defineProperty(exports, "DOWN", { enumerable: true, get: function () { return types_1.DOWN; } });
|
|
9
|
-
Object.defineProperty(exports, "LEFT", { enumerable: true, get: function () { return types_1.LEFT; } });
|
|
10
|
-
Object.defineProperty(exports, "RIGHT", { enumerable: true, get: function () { return types_1.RIGHT; } });
|
|
11
|
-
Object.defineProperty(exports, "UP", { enumerable: true, get: function () { return types_1.UP; } });
|
|
12
|
-
const defaultProps = {
|
|
13
|
-
delta: 10,
|
|
14
|
-
preventScrollOnSwipe: false,
|
|
15
|
-
rotationAngle: 0,
|
|
16
|
-
trackMouse: false,
|
|
17
|
-
trackTouch: true,
|
|
18
|
-
swipeDuration: Infinity,
|
|
19
|
-
touchEventOptions: { passive: true },
|
|
20
|
-
};
|
|
21
|
-
const initialState = {
|
|
22
|
-
first: true,
|
|
23
|
-
initial: [0, 0],
|
|
24
|
-
start: 0,
|
|
25
|
-
swiping: false,
|
|
26
|
-
xy: [0, 0],
|
|
27
|
-
};
|
|
28
|
-
const mouseMove = "mousemove";
|
|
29
|
-
const mouseUp = "mouseup";
|
|
30
|
-
const touchEnd = "touchend";
|
|
31
|
-
const touchMove = "touchmove";
|
|
32
|
-
const touchStart = "touchstart";
|
|
33
|
-
function getDirection(absX, absY, deltaX, deltaY) {
|
|
34
|
-
if (absX > absY) {
|
|
35
|
-
if (deltaX > 0) {
|
|
36
|
-
return types_1.RIGHT;
|
|
37
|
-
}
|
|
38
|
-
return types_1.LEFT;
|
|
39
|
-
}
|
|
40
|
-
else if (deltaY > 0) {
|
|
41
|
-
return types_1.DOWN;
|
|
42
|
-
}
|
|
43
|
-
return types_1.UP;
|
|
44
|
-
}
|
|
45
|
-
function rotateXYByAngle(pos, angle) {
|
|
46
|
-
if (angle === 0) {
|
|
47
|
-
return pos;
|
|
48
|
-
}
|
|
49
|
-
const angleInRadians = (Math.PI / 180) * angle;
|
|
50
|
-
const x = pos[0] * Math.cos(angleInRadians) + pos[1] * Math.sin(angleInRadians);
|
|
51
|
-
const y = pos[1] * Math.cos(angleInRadians) - pos[0] * Math.sin(angleInRadians);
|
|
52
|
-
return [x, y];
|
|
53
|
-
}
|
|
54
|
-
function getHandlers(set, handlerProps) {
|
|
55
|
-
const onStart = (event) => {
|
|
56
|
-
const isTouch = "touches" in event;
|
|
57
|
-
// if more than a single touch don't track, for now...
|
|
58
|
-
if (isTouch && event.touches.length > 1) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
set((state, props) => {
|
|
62
|
-
var _a;
|
|
63
|
-
// setup mouse listeners on document to track swipe since swipe can leave container
|
|
64
|
-
if (props.trackMouse && !isTouch) {
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
66
|
-
document.addEventListener(mouseMove, onMove);
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
68
|
-
document.addEventListener(mouseUp, onUp);
|
|
69
|
-
}
|
|
70
|
-
const { clientX, clientY } = isTouch ? event.touches[0] : event;
|
|
71
|
-
const xy = rotateXYByAngle([clientX, clientY], props.rotationAngle);
|
|
72
|
-
(_a = props.onTouchStartOrOnMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, { event });
|
|
73
|
-
return {
|
|
74
|
-
...state,
|
|
75
|
-
...initialState,
|
|
76
|
-
initial: xy.slice(),
|
|
77
|
-
xy,
|
|
78
|
-
start: event.timeStamp || 0,
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
const onMove = (event) => {
|
|
83
|
-
// eslint-disable-next-line complexity
|
|
84
|
-
set((state, props) => {
|
|
85
|
-
var _a, _b;
|
|
86
|
-
const isTouch = "touches" in event;
|
|
87
|
-
// Discount a swipe if additional touches are present after
|
|
88
|
-
// a swipe has started.
|
|
89
|
-
if (isTouch && event.touches.length > 1) {
|
|
90
|
-
return state;
|
|
91
|
-
}
|
|
92
|
-
// if swipe has exceeded duration stop tracking
|
|
93
|
-
if (event.timeStamp - state.start > props.swipeDuration) {
|
|
94
|
-
return state.swiping ? { ...state, swiping: false } : state;
|
|
95
|
-
}
|
|
96
|
-
const { clientX, clientY } = isTouch ? event.touches[0] : event;
|
|
97
|
-
const [x, y] = rotateXYByAngle([clientX, clientY], props.rotationAngle);
|
|
98
|
-
const deltaX = x - state.xy[0];
|
|
99
|
-
const deltaY = y - state.xy[1];
|
|
100
|
-
const absX = Math.abs(deltaX);
|
|
101
|
-
const absY = Math.abs(deltaY);
|
|
102
|
-
const time = (event.timeStamp || 0) - state.start;
|
|
103
|
-
const velocity = Math.sqrt(absX * absX + absY * absY) / (time || 1);
|
|
104
|
-
const vxvy = [deltaX / (time || 1), deltaY / (time || 1)];
|
|
105
|
-
const dir = getDirection(absX, absY, deltaX, deltaY);
|
|
106
|
-
// if swipe is under delta and we have not started to track a swipe: skip update
|
|
107
|
-
const delta = typeof props.delta === "number"
|
|
108
|
-
? props.delta
|
|
109
|
-
: props.delta[dir.toLowerCase()] || defaultProps.delta;
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
if (absX < delta && absY < delta && !state.swiping) {
|
|
113
|
-
return state;
|
|
114
|
-
}
|
|
115
|
-
const eventData = {
|
|
116
|
-
absX,
|
|
117
|
-
absY,
|
|
118
|
-
deltaX,
|
|
119
|
-
deltaY,
|
|
120
|
-
dir,
|
|
121
|
-
event,
|
|
122
|
-
first: state.first,
|
|
123
|
-
initial: state.initial,
|
|
124
|
-
velocity,
|
|
125
|
-
vxvy,
|
|
126
|
-
};
|
|
127
|
-
// call onSwipeStart if present and is first swipe event
|
|
128
|
-
if (eventData.first) {
|
|
129
|
-
(_a = props.onSwipeStart) === null || _a === void 0 ? void 0 : _a.call(props, eventData);
|
|
130
|
-
}
|
|
131
|
-
// call onSwiping if present
|
|
132
|
-
(_b = props.onSwiping) === null || _b === void 0 ? void 0 : _b.call(props, eventData);
|
|
133
|
-
// track if a swipe is cancelable (handler for swiping or swiped(dir) exists)
|
|
134
|
-
// so we can call preventDefault if needed
|
|
135
|
-
let cancelablePageSwipe = false;
|
|
136
|
-
if (props.onSwiping || props.onSwiped || props[`onSwiped${dir}`]) {
|
|
137
|
-
cancelablePageSwipe = true;
|
|
138
|
-
}
|
|
139
|
-
if (cancelablePageSwipe && props.preventScrollOnSwipe && props.trackTouch && event.cancelable) {
|
|
140
|
-
event.preventDefault();
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
...state,
|
|
144
|
-
// first is now always false
|
|
145
|
-
first: false,
|
|
146
|
-
eventData,
|
|
147
|
-
swiping: true,
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
const onEnd = (event) => {
|
|
152
|
-
set((state, props) => {
|
|
153
|
-
var _a, _b, _c;
|
|
154
|
-
let eventData;
|
|
155
|
-
if (state.swiping && state.eventData) {
|
|
156
|
-
// if swipe is less than duration fire swiped callbacks
|
|
157
|
-
if (event.timeStamp - state.start < props.swipeDuration) {
|
|
158
|
-
eventData = { ...state.eventData, event };
|
|
159
|
-
(_a = props.onSwiped) === null || _a === void 0 ? void 0 : _a.call(props, eventData);
|
|
160
|
-
const onSwipedDir = props[`onSwiped${eventData.dir}`];
|
|
161
|
-
onSwipedDir === null || onSwipedDir === void 0 ? void 0 : onSwipedDir(eventData);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
(_b = props.onTap) === null || _b === void 0 ? void 0 : _b.call(props, { event });
|
|
166
|
-
}
|
|
167
|
-
(_c = props.onTouchEndOrOnMouseUp) === null || _c === void 0 ? void 0 : _c.call(props, { event });
|
|
168
|
-
return { ...state, ...initialState, eventData };
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
const cleanUpMouse = () => {
|
|
172
|
-
// safe to just call removeEventListener
|
|
173
|
-
document.removeEventListener(mouseMove, onMove);
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
175
|
-
document.removeEventListener(mouseUp, onUp);
|
|
176
|
-
};
|
|
177
|
-
const onUp = (e) => {
|
|
178
|
-
cleanUpMouse();
|
|
179
|
-
onEnd(e);
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* The value of passive on touchMove depends on `preventScrollOnSwipe`:
|
|
183
|
-
* - true => { passive: false }
|
|
184
|
-
* - false => { passive: true } // Default
|
|
185
|
-
*
|
|
186
|
-
* NOTE: When preventScrollOnSwipe is true, we attempt to call preventDefault to prevent scroll.
|
|
187
|
-
*
|
|
188
|
-
* props.touchEventOptions can also be set for all touch event listeners,
|
|
189
|
-
* but for `touchmove` specifically when `preventScrollOnSwipe` it will
|
|
190
|
-
* supersede and force passive to false.
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
const attachTouch = (el, props) => {
|
|
194
|
-
// eslint-disable-next-line no-empty-function
|
|
195
|
-
let cleanup = () => { };
|
|
196
|
-
if ((0, is_not_nil_1.isNotNil)(el) && (0, is_not_nil_1.isNotNil)(el.addEventListener)) {
|
|
197
|
-
const baseOptions = {
|
|
198
|
-
...defaultProps.touchEventOptions,
|
|
199
|
-
...props.touchEventOptions,
|
|
200
|
-
};
|
|
201
|
-
// attach touch event listeners and handlers
|
|
202
|
-
const tls = [
|
|
203
|
-
[touchStart, onStart, baseOptions],
|
|
204
|
-
// preventScrollOnSwipe option supersedes touchEventOptions.passive
|
|
205
|
-
[
|
|
206
|
-
touchMove,
|
|
207
|
-
onMove,
|
|
208
|
-
{
|
|
209
|
-
...baseOptions,
|
|
210
|
-
...(props.preventScrollOnSwipe ? { passive: false } : {}),
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
[touchEnd, onEnd, baseOptions],
|
|
214
|
-
];
|
|
215
|
-
tls.forEach(([e, h, o]) => el.addEventListener(e, h, o));
|
|
216
|
-
// return properly scoped cleanup method for removing listeners, options not required
|
|
217
|
-
cleanup = () => tls.forEach(([e, h]) => el.removeEventListener(e, h));
|
|
218
|
-
}
|
|
219
|
-
return cleanup;
|
|
220
|
-
};
|
|
221
|
-
const onRef = (el) => {
|
|
222
|
-
// "inline" ref functions are called twice on render, once with null then again with DOM element
|
|
223
|
-
// ignore null here
|
|
224
|
-
if (el === null) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
set((state, props) => {
|
|
228
|
-
// if the same DOM el as previous just return state
|
|
229
|
-
if (state.el === el) {
|
|
230
|
-
return state;
|
|
231
|
-
}
|
|
232
|
-
const addState = {};
|
|
233
|
-
// if new DOM el clean up old DOM and reset cleanUpTouch
|
|
234
|
-
if (state.el && state.el !== el && state.cleanUpTouch) {
|
|
235
|
-
state.cleanUpTouch();
|
|
236
|
-
addState.cleanUpTouch = void 0;
|
|
237
|
-
}
|
|
238
|
-
// only attach if we want to track touch
|
|
239
|
-
if (props.trackTouch) {
|
|
240
|
-
addState.cleanUpTouch = attachTouch(el, props);
|
|
241
|
-
}
|
|
242
|
-
// store event attached DOM el for comparison, clean up, and re-attachment
|
|
243
|
-
return { ...state, el, ...addState };
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
|
-
// set ref callback to attach touch event listeners
|
|
247
|
-
const output = {
|
|
248
|
-
ref: onRef,
|
|
249
|
-
};
|
|
250
|
-
// if track mouse attach mouse down listener
|
|
251
|
-
if (handlerProps.trackMouse) {
|
|
252
|
-
output.onMouseDown = onStart;
|
|
253
|
-
}
|
|
254
|
-
return [output, attachTouch];
|
|
255
|
-
}
|
|
256
|
-
function updateTransientState(state, props, previousProps, attachTouch) {
|
|
257
|
-
// if trackTouch is off or there is no el, then remove handlers if necessary and exit
|
|
258
|
-
if (!props.trackTouch || !state.el) {
|
|
259
|
-
if (state.cleanUpTouch) {
|
|
260
|
-
state.cleanUpTouch();
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
...state,
|
|
264
|
-
cleanUpTouch: undefined,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
// trackTouch is on, so if there are no handlers attached, attach them and exit
|
|
268
|
-
if (!state.cleanUpTouch) {
|
|
269
|
-
return {
|
|
270
|
-
...state,
|
|
271
|
-
cleanUpTouch: attachTouch(state.el, props),
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
// trackTouch is on and handlers are already attached, so if preventScrollOnSwipe changes value,
|
|
275
|
-
// remove and reattach handlers (this is required to update the passive option when attaching
|
|
276
|
-
// the handlers)
|
|
277
|
-
if (props.preventScrollOnSwipe !== previousProps.preventScrollOnSwipe ||
|
|
278
|
-
props.touchEventOptions.passive !== previousProps.touchEventOptions.passive) {
|
|
279
|
-
state.cleanUpTouch();
|
|
280
|
-
return {
|
|
281
|
-
...state,
|
|
282
|
-
cleanUpTouch: attachTouch(state.el, props),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
return state;
|
|
286
|
-
}
|
|
287
|
-
function useSwipeable(options) {
|
|
288
|
-
const { trackMouse } = options;
|
|
289
|
-
const transientState = (0, react_1.useRef)({ ...initialState });
|
|
290
|
-
const transientProps = (0, react_1.useRef)({
|
|
291
|
-
...defaultProps,
|
|
292
|
-
});
|
|
293
|
-
// track previous rendered props
|
|
294
|
-
const previousProps = (0, react_1.useRef)({
|
|
295
|
-
...transientProps.current,
|
|
296
|
-
});
|
|
297
|
-
previousProps.current = { ...transientProps.current };
|
|
298
|
-
// update current render props & defaults
|
|
299
|
-
transientProps.current = {
|
|
300
|
-
...defaultProps,
|
|
301
|
-
...options,
|
|
302
|
-
};
|
|
303
|
-
// Force defaults for config properties
|
|
304
|
-
let defaultKey;
|
|
305
|
-
for (defaultKey in defaultProps) {
|
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
307
|
-
if (transientProps.current[defaultKey] === void 0) {
|
|
308
|
-
transientProps.current[defaultKey] = defaultProps[defaultKey];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
const [handlers, attachTouch] = (0, react_1.useMemo)(() => getHandlers((stateSetter) => (transientState.current = stateSetter(transientState.current, transientProps.current)), { trackMouse }), [trackMouse]);
|
|
312
|
-
transientState.current = updateTransientState(transientState.current, transientProps.current, previousProps.current, attachTouch);
|
|
313
|
-
return handlers;
|
|
314
|
-
}
|
package/utils/compose-refs.d.ts
DELETED
package/utils/compose-refs.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.composeRefs = composeRefs;
|
|
4
|
-
function composeRefs(...refs) {
|
|
5
|
-
return (value) => refs.forEach((ref) => {
|
|
6
|
-
if (!ref) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (typeof ref === "function") {
|
|
10
|
-
ref(value);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
ref.current = value;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const compose_refs_1 = require("./compose-refs");
|
|
4
|
-
describe("composeRefs", () => {
|
|
5
|
-
it("should call ref if it is a function", () => {
|
|
6
|
-
const refCallback = jest.fn();
|
|
7
|
-
const composedRef = (0, compose_refs_1.composeRefs)(refCallback);
|
|
8
|
-
composedRef("test-value");
|
|
9
|
-
expect(refCallback).toHaveBeenCalledWith("test-value");
|
|
10
|
-
});
|
|
11
|
-
it("should assign value to a MutableRefObject", () => {
|
|
12
|
-
const refObject = { current: null };
|
|
13
|
-
const composedRef = (0, compose_refs_1.composeRefs)(refObject);
|
|
14
|
-
composedRef("test-value");
|
|
15
|
-
expect(refObject.current).toBe("test-value");
|
|
16
|
-
});
|
|
17
|
-
it("should ignore undefined refs", () => {
|
|
18
|
-
const composedRef = (0, compose_refs_1.composeRefs)(undefined);
|
|
19
|
-
expect(() => composedRef("test-value")).not.toThrow();
|
|
20
|
-
});
|
|
21
|
-
it("should handle both function and MutableRefObject refs", () => {
|
|
22
|
-
const refCallback = jest.fn();
|
|
23
|
-
const refObject = { current: null };
|
|
24
|
-
const composedRef = (0, compose_refs_1.composeRefs)(refCallback, refObject);
|
|
25
|
-
composedRef("test-value");
|
|
26
|
-
expect(refCallback).toHaveBeenCalledWith("test-value");
|
|
27
|
-
expect(refObject.current).toBe("test-value");
|
|
28
|
-
});
|
|
29
|
-
it("should handle multiple refs", () => {
|
|
30
|
-
const refCallback1 = jest.fn();
|
|
31
|
-
const refCallback2 = jest.fn();
|
|
32
|
-
const refObject1 = { current: null };
|
|
33
|
-
const refObject2 = { current: null };
|
|
34
|
-
const composedRef = (0, compose_refs_1.composeRefs)(refCallback1, refObject1, refCallback2, refObject2);
|
|
35
|
-
composedRef("test-value");
|
|
36
|
-
expect(refCallback1).toHaveBeenCalledWith("test-value");
|
|
37
|
-
expect(refCallback2).toHaveBeenCalledWith("test-value");
|
|
38
|
-
expect(refObject1.current).toBe("test-value");
|
|
39
|
-
expect(refObject2.current).toBe("test-value");
|
|
40
|
-
});
|
|
41
|
-
});
|