@tamagui/react-native-web-internals 1.116.1 → 1.116.3
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/cjs/StyleSheet/__tests__/compiler-createReactDOMStyle-test.js +192 -0
- package/dist/cjs/StyleSheet/__tests__/compiler-test.js +378 -0
- package/dist/cjs/StyleSheet/__tests__/dom-createOrderedCSSStyleSheet-test.js +117 -0
- package/dist/cjs/StyleSheet/__tests__/index-test.js +347 -0
- package/dist/cjs/StyleSheet/__tests__/preprocess-test.js +77 -0
- package/dist/cjs/StyleSheet/__tests__/validate-test.js +18 -0
- package/dist/cjs/StyleSheet/compiler/createReactDOMStyle.js +121 -0
- package/dist/cjs/StyleSheet/compiler/hash.js +21 -0
- package/dist/cjs/StyleSheet/compiler/hyphenateStyleName.js +31 -0
- package/dist/cjs/StyleSheet/compiler/index.js +253 -0
- package/dist/cjs/StyleSheet/compiler/normalizeColor.js +42 -0
- package/dist/cjs/StyleSheet/compiler/normalizeValueWithProperty.js +45 -0
- package/dist/cjs/StyleSheet/compiler/resolveShadowValue.js +35 -0
- package/dist/cjs/StyleSheet/dom/createCSSStyleSheet.js +44 -0
- package/dist/cjs/StyleSheet/dom/createOrderedCSSStyleSheet.js +94 -0
- package/dist/cjs/StyleSheet/dom/index.js +74 -0
- package/dist/cjs/StyleSheet/index.js +52 -0
- package/dist/cjs/StyleSheet/preprocess.js +67 -0
- package/dist/cjs/StyleSheet/validate.js +66 -0
- package/dist/cjs/TextAncestorContext.js +24 -0
- package/dist/cjs/colorProps.js +32 -0
- package/dist/cjs/index.js +73 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/modules/AccessibilityUtil/__tests__/propsToAccessibilityComponent-test.js +46 -0
- package/dist/cjs/modules/AccessibilityUtil/__tests__/propsToAriaRole-test.js +30 -0
- package/dist/cjs/modules/AccessibilityUtil/index.js +36 -0
- package/dist/cjs/modules/AccessibilityUtil/isDisabled.js +22 -0
- package/dist/cjs/modules/AccessibilityUtil/propsToAccessibilityComponent.js +60 -0
- package/dist/cjs/modules/AccessibilityUtil/propsToAriaRole.js +43 -0
- package/dist/cjs/modules/AssetRegistry/index.js +28 -0
- package/dist/cjs/modules/ImageLoader/index.js +102 -0
- package/dist/cjs/modules/InteractionManager.js +68 -0
- package/dist/cjs/modules/Platform/__tests__/index-test.js +46 -0
- package/dist/cjs/modules/Platform/index.js +26 -0
- package/dist/cjs/modules/TextInputState/index.js +59 -0
- package/dist/cjs/modules/UIManager/__tests__/index-test.js +66 -0
- package/dist/cjs/modules/UIManager/index.js +101 -0
- package/dist/cjs/modules/canUseDOM.js +23 -0
- package/dist/cjs/modules/createDOMProps/__tests__/index-test.js +106 -0
- package/dist/cjs/modules/createDOMProps/index.js +121 -0
- package/dist/cjs/modules/createEventHandle/__tests__/index-test.js +242 -0
- package/dist/cjs/modules/createEventHandle/index.js +74 -0
- package/dist/cjs/modules/dismissKeyboard/index.js +33 -0
- package/dist/cjs/modules/forwardedProps/index.js +145 -0
- package/dist/cjs/modules/getBoundingClientRect/index.js +25 -0
- package/dist/cjs/modules/invariant.js +35 -0
- package/dist/cjs/modules/isSelectionValid/index.js +27 -0
- package/dist/cjs/modules/isWebColor/index.js +22 -0
- package/dist/cjs/modules/mergeRefs/__tests__/index-test.js +34 -0
- package/dist/cjs/modules/mergeRefs/index.js +41 -0
- package/dist/cjs/modules/modality/__tests__/index-test.js +20 -0
- package/dist/cjs/modules/modality/index.js +90 -0
- package/dist/cjs/modules/multiplyStyleLengthValue/__tests__/index-test.js +28 -0
- package/dist/cjs/modules/multiplyStyleLengthValue/index.js +28 -0
- package/dist/cjs/modules/normalizeColor/index.js +40 -0
- package/dist/cjs/modules/pick/index.js +26 -0
- package/dist/cjs/modules/processColor/__tests__/index-test.js +64 -0
- package/dist/cjs/modules/processColor/index.js +36 -0
- package/dist/cjs/modules/requestIdleCallback/index.js +44 -0
- package/dist/cjs/modules/setValueForStyles/dangerousStyleValue.js +34 -0
- package/dist/cjs/modules/setValueForStyles/index.js +39 -0
- package/dist/cjs/modules/unitlessNumbers/index.js +80 -0
- package/dist/cjs/modules/useElementLayout/index.js +65 -0
- package/dist/cjs/modules/useEvent/__tests__/index-test.js +289 -0
- package/dist/cjs/modules/useEvent/index.js +45 -0
- package/dist/cjs/modules/useHover/__tests__/index-test.js +195 -0
- package/dist/cjs/modules/useHover/index.js +81 -0
- package/dist/cjs/modules/useLayoutEffect/index.js +31 -0
- package/dist/cjs/modules/useLocale/index.js +54 -0
- package/dist/cjs/modules/useLocale/isLocaleRTL.js +91 -0
- package/dist/cjs/modules/useMergeRefs/__tests__/index-test.js +68 -0
- package/dist/cjs/modules/useMergeRefs/index.js +36 -0
- package/dist/cjs/modules/usePlatformMethods/index.js +39 -0
- package/dist/cjs/modules/useStable/__tests__/index-test.js +69 -0
- package/dist/cjs/modules/useStable/index.js +34 -0
- package/dist/cjs/styleTypes.js +14 -0
- package/dist/cjs/types.js +14 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +7 -7
- package/src/index.tsx +10 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/dist/cjs/index.cjs.map +0 -6
- /package/dist/cjs/StyleSheet/__tests__/{compiler-createReactDOMStyle-test.cjs.map → compiler-createReactDOMStyle-test.js.map} +0 -0
- /package/dist/cjs/StyleSheet/__tests__/{compiler-test.cjs.map → compiler-test.js.map} +0 -0
- /package/dist/cjs/StyleSheet/__tests__/{dom-createOrderedCSSStyleSheet-test.cjs.map → dom-createOrderedCSSStyleSheet-test.js.map} +0 -0
- /package/dist/cjs/StyleSheet/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/StyleSheet/__tests__/{preprocess-test.cjs.map → preprocess-test.js.map} +0 -0
- /package/dist/cjs/StyleSheet/__tests__/{validate-test.cjs.map → validate-test.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{createReactDOMStyle.cjs.map → createReactDOMStyle.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{hash.cjs.map → hash.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{hyphenateStyleName.cjs.map → hyphenateStyleName.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{normalizeColor.cjs.map → normalizeColor.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{normalizeValueWithProperty.cjs.map → normalizeValueWithProperty.js.map} +0 -0
- /package/dist/cjs/StyleSheet/compiler/{resolveShadowValue.cjs.map → resolveShadowValue.js.map} +0 -0
- /package/dist/cjs/StyleSheet/dom/{createCSSStyleSheet.cjs.map → createCSSStyleSheet.js.map} +0 -0
- /package/dist/cjs/StyleSheet/dom/{createOrderedCSSStyleSheet.cjs.map → createOrderedCSSStyleSheet.js.map} +0 -0
- /package/dist/cjs/StyleSheet/dom/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/StyleSheet/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/StyleSheet/{preprocess.cjs.map → preprocess.js.map} +0 -0
- /package/dist/cjs/StyleSheet/{validate.cjs.map → validate.js.map} +0 -0
- /package/dist/cjs/{TextAncestorContext.cjs.map → TextAncestorContext.js.map} +0 -0
- /package/dist/cjs/{colorProps.cjs.map → colorProps.js.map} +0 -0
- /package/dist/cjs/modules/AccessibilityUtil/__tests__/{propsToAccessibilityComponent-test.cjs.map → propsToAccessibilityComponent-test.js.map} +0 -0
- /package/dist/cjs/modules/AccessibilityUtil/__tests__/{propsToAriaRole-test.cjs.map → propsToAriaRole-test.js.map} +0 -0
- /package/dist/cjs/modules/AccessibilityUtil/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/AccessibilityUtil/{isDisabled.cjs.map → isDisabled.js.map} +0 -0
- /package/dist/cjs/modules/AccessibilityUtil/{propsToAccessibilityComponent.cjs.map → propsToAccessibilityComponent.js.map} +0 -0
- /package/dist/cjs/modules/AccessibilityUtil/{propsToAriaRole.cjs.map → propsToAriaRole.js.map} +0 -0
- /package/dist/cjs/modules/AssetRegistry/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/ImageLoader/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/{InteractionManager.cjs.map → InteractionManager.js.map} +0 -0
- /package/dist/cjs/modules/Platform/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/Platform/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/TextInputState/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/UIManager/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/UIManager/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/{canUseDOM.cjs.map → canUseDOM.js.map} +0 -0
- /package/dist/cjs/modules/createDOMProps/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/createDOMProps/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/createEventHandle/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/createEventHandle/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/dismissKeyboard/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/forwardedProps/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/getBoundingClientRect/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/{invariant.cjs.map → invariant.js.map} +0 -0
- /package/dist/cjs/modules/isSelectionValid/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/isWebColor/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/mergeRefs/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/mergeRefs/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/modality/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/modality/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/multiplyStyleLengthValue/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/multiplyStyleLengthValue/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/normalizeColor/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/pick/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/processColor/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/processColor/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/requestIdleCallback/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/setValueForStyles/{dangerousStyleValue.cjs.map → dangerousStyleValue.js.map} +0 -0
- /package/dist/cjs/modules/setValueForStyles/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/unitlessNumbers/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useElementLayout/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useEvent/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/useEvent/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useHover/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/useHover/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useLayoutEffect/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useLocale/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useLocale/{isLocaleRTL.cjs.map → isLocaleRTL.js.map} +0 -0
- /package/dist/cjs/modules/useMergeRefs/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/useMergeRefs/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/usePlatformMethods/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/modules/useStable/__tests__/{index-test.cjs.map → index-test.js.map} +0 -0
- /package/dist/cjs/modules/useStable/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/{styleTypes.cjs.map → styleTypes.js.map} +0 -0
- /package/dist/cjs/{types.cjs.map → types.js.map} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
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 unitlessNumbers_exports = {};
|
|
16
|
+
__export(unitlessNumbers_exports, {
|
|
17
|
+
default: () => unitlessNumbers_default,
|
|
18
|
+
unitlessNumbers: () => unitlessNumbers
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(unitlessNumbers_exports);
|
|
21
|
+
const unitlessNumbers = {
|
|
22
|
+
animationIterationCount: !0,
|
|
23
|
+
aspectRatio: !0,
|
|
24
|
+
borderImageOutset: !0,
|
|
25
|
+
borderImageSlice: !0,
|
|
26
|
+
borderImageWidth: !0,
|
|
27
|
+
boxFlex: !0,
|
|
28
|
+
boxFlexGroup: !0,
|
|
29
|
+
boxOrdinalGroup: !0,
|
|
30
|
+
columnCount: !0,
|
|
31
|
+
flex: !0,
|
|
32
|
+
flexGrow: !0,
|
|
33
|
+
flexOrder: !0,
|
|
34
|
+
flexPositive: !0,
|
|
35
|
+
flexShrink: !0,
|
|
36
|
+
flexNegative: !0,
|
|
37
|
+
fontWeight: !0,
|
|
38
|
+
gap: !0,
|
|
39
|
+
columnGap: !0,
|
|
40
|
+
rowGap: !0,
|
|
41
|
+
gridRow: !0,
|
|
42
|
+
gridRowEnd: !0,
|
|
43
|
+
gridRowGap: !0,
|
|
44
|
+
gridRowStart: !0,
|
|
45
|
+
gridColumn: !0,
|
|
46
|
+
gridColumnEnd: !0,
|
|
47
|
+
gridColumnGap: !0,
|
|
48
|
+
gridColumnStart: !0,
|
|
49
|
+
lineClamp: !0,
|
|
50
|
+
opacity: !0,
|
|
51
|
+
order: !0,
|
|
52
|
+
orphans: !0,
|
|
53
|
+
tabSize: !0,
|
|
54
|
+
widows: !0,
|
|
55
|
+
zIndex: !0,
|
|
56
|
+
zoom: !0,
|
|
57
|
+
// SVG-related
|
|
58
|
+
fillOpacity: !0,
|
|
59
|
+
floodOpacity: !0,
|
|
60
|
+
stopOpacity: !0,
|
|
61
|
+
strokeDasharray: !0,
|
|
62
|
+
strokeDashoffset: !0,
|
|
63
|
+
strokeMiterlimit: !0,
|
|
64
|
+
strokeOpacity: !0,
|
|
65
|
+
strokeWidth: !0,
|
|
66
|
+
// transform types
|
|
67
|
+
scale: !0,
|
|
68
|
+
scaleX: !0,
|
|
69
|
+
scaleY: !0,
|
|
70
|
+
scaleZ: !0,
|
|
71
|
+
// RN properties
|
|
72
|
+
shadowOpacity: !0
|
|
73
|
+
}, prefixes = ["ms", "Moz", "O", "Webkit"], prefixKey = (prefix, key) => prefix + key.charAt(0).toUpperCase() + key.substring(1);
|
|
74
|
+
Object.keys(unitlessNumbers).forEach((prop) => {
|
|
75
|
+
prefixes.forEach((prefix) => {
|
|
76
|
+
unitlessNumbers[prefixKey(prefix, prop)] = unitlessNumbers[prop];
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
var unitlessNumbers_default = unitlessNumbers;
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var useElementLayout_exports = {};
|
|
24
|
+
__export(useElementLayout_exports, {
|
|
25
|
+
default: () => useElementLayout
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useElementLayout_exports);
|
|
28
|
+
var import_canUseDOM = __toESM(require("../canUseDOM")), import_UIManager = __toESM(require("../UIManager/index")), import_useLayoutEffect = __toESM(require("../useLayoutEffect/index"));
|
|
29
|
+
const DOM_LAYOUT_HANDLER_NAME = "__reactLayoutHandler";
|
|
30
|
+
let didWarn = !import_canUseDOM.default, resizeObserver = null;
|
|
31
|
+
function getResizeObserver() {
|
|
32
|
+
return import_canUseDOM.default && typeof window.ResizeObserver < "u" ? resizeObserver == null && (resizeObserver = new window.ResizeObserver(function(entries) {
|
|
33
|
+
entries.forEach((entry) => {
|
|
34
|
+
const node = entry.target, onLayout = node[DOM_LAYOUT_HANDLER_NAME];
|
|
35
|
+
typeof onLayout == "function" && import_UIManager.default.measure(node, (x, y, width, height, left, top) => {
|
|
36
|
+
const event = {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
nativeEvent: {
|
|
39
|
+
layout: { x, y, width, height, left, top }
|
|
40
|
+
},
|
|
41
|
+
timeStamp: Date.now()
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(event.nativeEvent, "target", {
|
|
44
|
+
enumerable: !0,
|
|
45
|
+
get: () => entry.target
|
|
46
|
+
}), onLayout(event);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
})) : didWarn || process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && (console.warn(
|
|
50
|
+
"onLayout relies on ResizeObserver which is not supported by your browser. Please include a polyfill, e.g., https://github.com/que-etc/resize-observer-polyfill."
|
|
51
|
+
), didWarn = !0), resizeObserver;
|
|
52
|
+
}
|
|
53
|
+
function useElementLayout(ref, onLayout) {
|
|
54
|
+
const observer = getResizeObserver();
|
|
55
|
+
(0, import_useLayoutEffect.default)(() => {
|
|
56
|
+
const node = ref.current;
|
|
57
|
+
node != null && (node[DOM_LAYOUT_HANDLER_NAME] = onLayout);
|
|
58
|
+
}, [ref, onLayout]), (0, import_useLayoutEffect.default)(() => {
|
|
59
|
+
const node = ref.current;
|
|
60
|
+
return node != null && observer != null && (typeof node[DOM_LAYOUT_HANDLER_NAME] == "function" ? observer.observe(node) : observer.unobserve(node)), () => {
|
|
61
|
+
node != null && observer != null && observer.unobserve(node);
|
|
62
|
+
};
|
|
63
|
+
}, [ref, observer]);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
13
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
14
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
15
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
16
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
var import_dom_event_testing_library = require("dom-event-testing-library"), React = __toESM(require("react")), ReactDOM = __toESM(require("react-dom")), import_test_utils = require("react-dom/test-utils"), import__ = __toESM(require("..")), import_jsx_runtime = require("react/jsx-runtime");
|
|
21
|
+
function createRoot(rootNode) {
|
|
22
|
+
return {
|
|
23
|
+
render(element) {
|
|
24
|
+
ReactDOM.render(element, rootNode);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
describe("use-event", () => {
|
|
29
|
+
let root, rootNode;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
rootNode = document.createElement("div"), document.body.appendChild(rootNode), root = createRoot(rootNode);
|
|
32
|
+
}), afterEach(() => {
|
|
33
|
+
root.render(null), document.body.removeChild(rootNode), rootNode = null, root = null;
|
|
34
|
+
}), describe("setListener()", () => {
|
|
35
|
+
test("event dispatched on target", () => {
|
|
36
|
+
const listener = jest.fn(), targetRef = React.createRef();
|
|
37
|
+
function Component() {
|
|
38
|
+
const addClickListener = (0, import__.default)("click");
|
|
39
|
+
return React.useEffect(() => {
|
|
40
|
+
addClickListener(targetRef.current, listener);
|
|
41
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
42
|
+
}
|
|
43
|
+
(0, import_test_utils.act)(() => {
|
|
44
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
45
|
+
});
|
|
46
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(targetRef.current);
|
|
47
|
+
(0, import_test_utils.act)(() => {
|
|
48
|
+
target.click();
|
|
49
|
+
}), expect(listener).toBeCalledTimes(1);
|
|
50
|
+
}), test("event dispatched on parent", () => {
|
|
51
|
+
const listener = jest.fn(), listenerCapture = jest.fn(), targetRef = React.createRef(), parentRef = React.createRef();
|
|
52
|
+
function Component() {
|
|
53
|
+
const addClickListener = (0, import__.default)("click"), addClickCaptureListener = (0, import__.default)("click", { capture: !0 });
|
|
54
|
+
return React.useEffect(() => {
|
|
55
|
+
addClickListener(targetRef.current, listener), addClickCaptureListener(targetRef.current, listenerCapture);
|
|
56
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: parentRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef }) });
|
|
57
|
+
}
|
|
58
|
+
(0, import_test_utils.act)(() => {
|
|
59
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
60
|
+
});
|
|
61
|
+
const parent = (0, import_dom_event_testing_library.createEventTarget)(parentRef.current);
|
|
62
|
+
(0, import_test_utils.act)(() => {
|
|
63
|
+
parent.click();
|
|
64
|
+
}), expect(listener).toBeCalledTimes(0), expect(listenerCapture).toBeCalledTimes(0);
|
|
65
|
+
}), test("event dispatched on child", () => {
|
|
66
|
+
const log = [], listener = jest.fn(() => {
|
|
67
|
+
log.push("bubble");
|
|
68
|
+
}), listenerCapture = jest.fn(() => {
|
|
69
|
+
log.push("capture");
|
|
70
|
+
}), targetRef = React.createRef(), childRef = React.createRef();
|
|
71
|
+
function Component() {
|
|
72
|
+
const addClickListener = (0, import__.default)("click"), addClickCaptureListener = (0, import__.default)("click", { capture: !0 });
|
|
73
|
+
return React.useEffect(() => {
|
|
74
|
+
addClickListener(targetRef.current, listener), addClickCaptureListener(targetRef.current, listenerCapture);
|
|
75
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: childRef }) });
|
|
76
|
+
}
|
|
77
|
+
(0, import_test_utils.act)(() => {
|
|
78
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
79
|
+
});
|
|
80
|
+
const child = (0, import_dom_event_testing_library.createEventTarget)(childRef.current);
|
|
81
|
+
(0, import_test_utils.act)(() => {
|
|
82
|
+
child.click();
|
|
83
|
+
}), expect(listenerCapture).toBeCalledTimes(1), expect(listener).toBeCalledTimes(1), expect(log).toEqual(["capture", "bubble"]);
|
|
84
|
+
}), test("event dispatched on text node", () => {
|
|
85
|
+
const listener = jest.fn(), targetRef = React.createRef(), childRef = React.createRef();
|
|
86
|
+
function Component() {
|
|
87
|
+
const addClickListener = (0, import__.default)("click");
|
|
88
|
+
return React.useEffect(() => {
|
|
89
|
+
addClickListener(targetRef.current, listener);
|
|
90
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: childRef, children: "text" }) });
|
|
91
|
+
}
|
|
92
|
+
(0, import_test_utils.act)(() => {
|
|
93
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
94
|
+
});
|
|
95
|
+
const text = (0, import_dom_event_testing_library.createEventTarget)(childRef.current.firstChild);
|
|
96
|
+
(0, import_test_utils.act)(() => {
|
|
97
|
+
text.click();
|
|
98
|
+
}), expect(listener).toBeCalledTimes(1);
|
|
99
|
+
}), test("listener can be attached to document ", () => {
|
|
100
|
+
const listener = jest.fn(), targetRef = React.createRef();
|
|
101
|
+
function Component({ target: target2 }) {
|
|
102
|
+
const addClickListener = (0, import__.default)("click");
|
|
103
|
+
return React.useEffect(() => {
|
|
104
|
+
addClickListener(target2, listener);
|
|
105
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
106
|
+
}
|
|
107
|
+
(0, import_test_utils.act)(() => {
|
|
108
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { target: document }));
|
|
109
|
+
});
|
|
110
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(targetRef.current);
|
|
111
|
+
(0, import_test_utils.act)(() => {
|
|
112
|
+
target.click();
|
|
113
|
+
}), expect(listener).toBeCalledTimes(1);
|
|
114
|
+
}), test("listener can be attached to window ", () => {
|
|
115
|
+
const listener = jest.fn(), targetRef = React.createRef();
|
|
116
|
+
function Component({ target: target2 }) {
|
|
117
|
+
const addClickListener = (0, import__.default)("click");
|
|
118
|
+
return React.useEffect(() => {
|
|
119
|
+
addClickListener(target2, listener);
|
|
120
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
121
|
+
}
|
|
122
|
+
(0, import_test_utils.act)(() => {
|
|
123
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { target: window }));
|
|
124
|
+
});
|
|
125
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(targetRef.current);
|
|
126
|
+
(0, import_test_utils.act)(() => {
|
|
127
|
+
target.click();
|
|
128
|
+
}), expect(listener).toBeCalledTimes(1);
|
|
129
|
+
}), test("listener is replaceable", () => {
|
|
130
|
+
const listener = jest.fn(), listenerAlt = jest.fn(), targetRef = React.createRef();
|
|
131
|
+
function Component({ onClick }) {
|
|
132
|
+
const addClickListener = (0, import__.default)("click");
|
|
133
|
+
return React.useEffect(() => {
|
|
134
|
+
addClickListener(targetRef.current, onClick);
|
|
135
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
136
|
+
}
|
|
137
|
+
(0, import_test_utils.act)(() => {
|
|
138
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { onClick: listener }));
|
|
139
|
+
});
|
|
140
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(targetRef.current);
|
|
141
|
+
(0, import_test_utils.act)(() => {
|
|
142
|
+
target.click();
|
|
143
|
+
}), expect(listener).toBeCalledTimes(1), (0, import_test_utils.act)(() => {
|
|
144
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { onClick: listenerAlt }));
|
|
145
|
+
}), (0, import_test_utils.act)(() => {
|
|
146
|
+
target.click();
|
|
147
|
+
}), expect(listener).toBeCalledTimes(1), expect(listenerAlt).toBeCalledTimes(1);
|
|
148
|
+
}), test("listener is removed when value is null", () => {
|
|
149
|
+
const listener = jest.fn(), targetRef = React.createRef();
|
|
150
|
+
function Component({ off }) {
|
|
151
|
+
const addClickListener = (0, import__.default)("click");
|
|
152
|
+
return React.useEffect(() => {
|
|
153
|
+
addClickListener(targetRef.current, off ? null : listener);
|
|
154
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
155
|
+
}
|
|
156
|
+
(0, import_test_utils.act)(() => {
|
|
157
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { off: !1 }));
|
|
158
|
+
});
|
|
159
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(targetRef.current);
|
|
160
|
+
(0, import_test_utils.act)(() => {
|
|
161
|
+
target.click();
|
|
162
|
+
}), expect(listener).toBeCalledTimes(1), (0, import_test_utils.act)(() => {
|
|
163
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { off: !0 }));
|
|
164
|
+
}), listener.mockClear(), (0, import_test_utils.act)(() => {
|
|
165
|
+
target.click();
|
|
166
|
+
}), expect(listener).toBeCalledTimes(0);
|
|
167
|
+
}), test("custom event dispatched on target", () => {
|
|
168
|
+
const listener = jest.fn(), targetRef = React.createRef();
|
|
169
|
+
function Component() {
|
|
170
|
+
const addMagicEventListener = (0, import__.default)("magic-event");
|
|
171
|
+
return React.useEffect(() => {
|
|
172
|
+
addMagicEventListener(targetRef.current, listener);
|
|
173
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
174
|
+
}
|
|
175
|
+
(0, import_test_utils.act)(() => {
|
|
176
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
177
|
+
}), (0, import_test_utils.act)(() => {
|
|
178
|
+
const event = new CustomEvent("magic-event", { bubbles: !0 });
|
|
179
|
+
targetRef.current.dispatchEvent(event);
|
|
180
|
+
}), expect(listener).toBeCalledTimes(1);
|
|
181
|
+
}), test("listeners can be set on multiple targets simultaneously", () => {
|
|
182
|
+
const log = [], targetRef = React.createRef(), parentRef = React.createRef(), childRef = React.createRef(), listener = jest.fn((e) => {
|
|
183
|
+
log.push(["bubble", e.currentTarget.id]);
|
|
184
|
+
}), listenerCapture = jest.fn((e) => {
|
|
185
|
+
log.push(["capture", e.currentTarget.id]);
|
|
186
|
+
});
|
|
187
|
+
function Component() {
|
|
188
|
+
const addClickListener = (0, import__.default)("click"), addClickCaptureListener = (0, import__.default)("click", { capture: !0 });
|
|
189
|
+
return React.useEffect(() => {
|
|
190
|
+
addClickListener(targetRef.current, listener), addClickListener(parentRef.current, listener), addClickCaptureListener(targetRef.current, listenerCapture), addClickCaptureListener(parentRef.current, listenerCapture);
|
|
191
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: "parent", ref: parentRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: "target", ref: targetRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: childRef }) }) });
|
|
192
|
+
}
|
|
193
|
+
(0, import_test_utils.act)(() => {
|
|
194
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
195
|
+
});
|
|
196
|
+
const child = (0, import_dom_event_testing_library.createEventTarget)(childRef.current);
|
|
197
|
+
(0, import_test_utils.act)(() => {
|
|
198
|
+
child.click();
|
|
199
|
+
}), expect(listenerCapture).toBeCalledTimes(2), expect(listener).toBeCalledTimes(2), expect(log).toEqual([
|
|
200
|
+
["capture", "parent"],
|
|
201
|
+
["capture", "target"],
|
|
202
|
+
["bubble", "target"],
|
|
203
|
+
["bubble", "parent"]
|
|
204
|
+
]);
|
|
205
|
+
}), test("listeners are specific to each event handle", () => {
|
|
206
|
+
const log = [], targetRef = React.createRef(), childRef = React.createRef(), listener = jest.fn((e) => {
|
|
207
|
+
log.push(["bubble", "target"]);
|
|
208
|
+
}), listenerAlt = jest.fn((e) => {
|
|
209
|
+
log.push(["bubble", "target-alt"]);
|
|
210
|
+
}), listenerCapture = jest.fn((e) => {
|
|
211
|
+
log.push(["capture", "target"]);
|
|
212
|
+
}), listenerCaptureAlt = jest.fn((e) => {
|
|
213
|
+
log.push(["capture", "target-alt"]);
|
|
214
|
+
});
|
|
215
|
+
function Component() {
|
|
216
|
+
const addClickListener = (0, import__.default)("click"), addClickAltListener = (0, import__.default)("click"), addClickCaptureListener = (0, import__.default)("click", { capture: !0 }), addClickCaptureAltListener = (0, import__.default)("click", { capture: !0 });
|
|
217
|
+
return React.useEffect(() => {
|
|
218
|
+
addClickListener(targetRef.current, listener), addClickAltListener(targetRef.current, listenerAlt), addClickCaptureListener(targetRef.current, listenerCapture), addClickCaptureAltListener(targetRef.current, listenerCaptureAlt);
|
|
219
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: "target", ref: targetRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: childRef }) });
|
|
220
|
+
}
|
|
221
|
+
(0, import_test_utils.act)(() => {
|
|
222
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
223
|
+
});
|
|
224
|
+
const child = (0, import_dom_event_testing_library.createEventTarget)(childRef.current);
|
|
225
|
+
(0, import_test_utils.act)(() => {
|
|
226
|
+
child.click();
|
|
227
|
+
}), expect(listenerCapture).toBeCalledTimes(1), expect(listenerCaptureAlt).toBeCalledTimes(1), expect(listener).toBeCalledTimes(1), expect(listenerAlt).toBeCalledTimes(1), expect(log).toEqual([
|
|
228
|
+
["capture", "target"],
|
|
229
|
+
["capture", "target-alt"],
|
|
230
|
+
["bubble", "target"],
|
|
231
|
+
["bubble", "target-alt"]
|
|
232
|
+
]);
|
|
233
|
+
});
|
|
234
|
+
}), describe("cleanup", () => {
|
|
235
|
+
test("removes all listeners for given event type from targets", () => {
|
|
236
|
+
const clickListener = jest.fn();
|
|
237
|
+
function Component() {
|
|
238
|
+
const addClickListener = (0, import__.default)("click");
|
|
239
|
+
return React.useEffect(() => {
|
|
240
|
+
addClickListener(document, clickListener);
|
|
241
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {});
|
|
242
|
+
}
|
|
243
|
+
(0, import_test_utils.act)(() => {
|
|
244
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})), root.render(null);
|
|
245
|
+
});
|
|
246
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(document);
|
|
247
|
+
(0, import_test_utils.act)(() => {
|
|
248
|
+
target.click();
|
|
249
|
+
}), expect(clickListener).toBeCalledTimes(0);
|
|
250
|
+
});
|
|
251
|
+
}), describe("stopPropagation and stopImmediatePropagation", () => {
|
|
252
|
+
test("stopPropagation works as expected", () => {
|
|
253
|
+
const childListener = jest.fn((e) => {
|
|
254
|
+
e.stopPropagation();
|
|
255
|
+
}), targetListener = jest.fn(), targetRef = React.createRef(), childRef = React.createRef();
|
|
256
|
+
function Component() {
|
|
257
|
+
const addClickListener = (0, import__.default)("click");
|
|
258
|
+
return React.useEffect(() => {
|
|
259
|
+
addClickListener(childRef.current, childListener), addClickListener(targetRef.current, targetListener);
|
|
260
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: childRef }) });
|
|
261
|
+
}
|
|
262
|
+
(0, import_test_utils.act)(() => {
|
|
263
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
264
|
+
});
|
|
265
|
+
const child = (0, import_dom_event_testing_library.createEventTarget)(childRef.current);
|
|
266
|
+
(0, import_test_utils.act)(() => {
|
|
267
|
+
child.click();
|
|
268
|
+
}), expect(childListener).toBeCalledTimes(1), expect(targetListener).toBeCalledTimes(0);
|
|
269
|
+
}), test("stopImmediatePropagation works as expected", () => {
|
|
270
|
+
const firstListener = jest.fn((e) => {
|
|
271
|
+
e.stopImmediatePropagation();
|
|
272
|
+
}), secondListener = jest.fn(), targetRef = React.createRef();
|
|
273
|
+
function Component() {
|
|
274
|
+
const addFirstClickListener = (0, import__.default)("click"), addSecondClickListener = (0, import__.default)("click");
|
|
275
|
+
return React.useEffect(() => {
|
|
276
|
+
addFirstClickListener(targetRef.current, firstListener), addSecondClickListener(targetRef.current, secondListener);
|
|
277
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: targetRef });
|
|
278
|
+
}
|
|
279
|
+
(0, import_test_utils.act)(() => {
|
|
280
|
+
root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}));
|
|
281
|
+
});
|
|
282
|
+
const target = (0, import_dom_event_testing_library.createEventTarget)(targetRef.current);
|
|
283
|
+
(0, import_test_utils.act)(() => {
|
|
284
|
+
target.click();
|
|
285
|
+
}), expect(firstListener).toBeCalledTimes(1), expect(secondListener).toBeCalledTimes(0);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
//# sourceMappingURL=index-test.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var useEvent_exports = {};
|
|
24
|
+
__export(useEvent_exports, {
|
|
25
|
+
default: () => useEvent
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useEvent_exports);
|
|
28
|
+
var import_createEventHandle = __toESM(require("../createEventHandle/index")), import_useLayoutEffect = __toESM(require("../useLayoutEffect/index")), import_useStable = __toESM(require("../useStable/index"));
|
|
29
|
+
function useEvent(event, options) {
|
|
30
|
+
const targetListeners = (0, import_useStable.default)(() => /* @__PURE__ */ new Map()), addListener = (0, import_useStable.default)(() => {
|
|
31
|
+
const addEventListener = (0, import_createEventHandle.default)(event, options);
|
|
32
|
+
return (target, callback) => {
|
|
33
|
+
const removeTargetListener = targetListeners.get(target);
|
|
34
|
+
removeTargetListener?.(), callback == null && targetListeners.delete(target);
|
|
35
|
+
const removeEventListener = addEventListener(target, callback);
|
|
36
|
+
return targetListeners.set(target, removeEventListener), removeEventListener;
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
return (0, import_useLayoutEffect.default)(() => () => {
|
|
40
|
+
targetListeners.forEach((removeListener) => {
|
|
41
|
+
removeListener();
|
|
42
|
+
}), targetListeners.clear();
|
|
43
|
+
}, [targetListeners]), addListener;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|