@tamagui/core 1.2.8 → 1.2.10
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/helpers/getBoundingClientRect.mjs +10 -0
- package/dist/esm/helpers/getBoundingClientRect.mjs.map +7 -0
- package/dist/esm/helpers/getRect.mjs +12 -0
- package/dist/esm/helpers/getRect.mjs.map +7 -0
- package/dist/esm/hooks/useElementLayout.mjs +59 -0
- package/dist/esm/hooks/useElementLayout.mjs.map +7 -0
- package/dist/esm/hooks/usePlatformMethods.mjs +24 -0
- package/dist/esm/hooks/usePlatformMethods.mjs.map +7 -0
- package/dist/esm/index.mjs +159 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/inject-styles.mjs +16 -0
- package/dist/esm/inject-styles.mjs.map +7 -0
- package/dist/esm/reactNativeTypes.mjs +1 -0
- package/dist/esm/reactNativeTypes.mjs.map +7 -0
- package/dist/esm/vendor/Pressability.mjs +7 -0
- package/dist/esm/vendor/Pressability.mjs.map +7 -0
- package/dist/esm/vendor/Pressability.native.mjs +7 -0
- package/dist/esm/vendor/Pressability.native.mjs.map +7 -0
- package/package.json +12 -7
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const getBoundingClientRect = (node) => {
|
|
2
|
+
var _a;
|
|
3
|
+
if (!node || node.nodeType !== 1)
|
|
4
|
+
return;
|
|
5
|
+
return (_a = node.getBoundingClientRect) == null ? void 0 : _a.call(node);
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
getBoundingClientRect
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=getBoundingClientRect.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/getBoundingClientRect.tsx"],
|
|
4
|
+
"sourcesContent": ["export const getBoundingClientRect = (node: HTMLElement | null): void | DOMRect => {\n if (!node || node.nodeType !== 1) return\n return node.getBoundingClientRect?.()\n}\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,wBAAwB,CAAC,SAA6C;AAAnF;AACE,MAAI,CAAC,QAAQ,KAAK,aAAa;AAAG;AAClC,UAAO,UAAK,0BAAL;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getBoundingClientRect } from "./getBoundingClientRect";
|
|
2
|
+
const getRect = (node) => {
|
|
3
|
+
const rect = getBoundingClientRect(node);
|
|
4
|
+
if (!rect)
|
|
5
|
+
return;
|
|
6
|
+
const { x, y, top, left } = rect;
|
|
7
|
+
return { x, y, width: node.offsetWidth, height: node.offsetHeight, top, left };
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
getRect
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=getRect.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/getRect.tsx"],
|
|
4
|
+
"sourcesContent": ["import { getBoundingClientRect } from './getBoundingClientRect'\n\nexport const getRect = (node: HTMLElement) => {\n const rect = getBoundingClientRect(node)\n if (!rect) return\n const { x, y, top, left } = rect\n return { x, y, width: node.offsetWidth, height: node.offsetHeight, top, left }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,6BAA6B;AAE/B,MAAM,UAAU,CAAC,SAAsB;AAC5C,QAAM,OAAO,sBAAsB,IAAI;AACvC,MAAI,CAAC;AAAM;AACX,QAAM,EAAE,GAAG,GAAG,KAAK,KAAK,IAAI;AAC5B,SAAO,EAAE,GAAG,GAAG,OAAO,KAAK,aAAa,QAAQ,KAAK,cAAc,KAAK,KAAK;AAC/E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { useEvent } from "@tamagui/use-event";
|
|
3
|
+
import { getBoundingClientRect } from "../helpers/getBoundingClientRect";
|
|
4
|
+
import { getRect } from "../helpers/getRect";
|
|
5
|
+
const LayoutHandlers = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
let resizeObserver = null;
|
|
7
|
+
if (typeof window !== "undefined" && "ResizeObserver" in window) {
|
|
8
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
9
|
+
for (const { target } of entries) {
|
|
10
|
+
const onLayout = LayoutHandlers.get(target);
|
|
11
|
+
if (typeof onLayout !== "function")
|
|
12
|
+
return;
|
|
13
|
+
measureLayout(target, null, (x, y, width, height, left, top) => {
|
|
14
|
+
onLayout({
|
|
15
|
+
nativeEvent: {
|
|
16
|
+
layout: { x, y, width, height, left, top },
|
|
17
|
+
target
|
|
18
|
+
},
|
|
19
|
+
timeStamp: Date.now()
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const measureLayout = (node, relativeTo, callback) => {
|
|
26
|
+
const relativeNode = relativeTo || (node == null ? void 0 : node.parentNode);
|
|
27
|
+
if (relativeNode instanceof HTMLElement) {
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
const relativeRect = getBoundingClientRect(relativeNode);
|
|
30
|
+
const { height, left, top, width } = getRect(node);
|
|
31
|
+
const x = left - relativeRect.left;
|
|
32
|
+
const y = top - relativeRect.top;
|
|
33
|
+
callback(x, y, width, height, left, top);
|
|
34
|
+
}, 0);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const idFn = () => {
|
|
38
|
+
};
|
|
39
|
+
function useElementLayout(ref, onLayout) {
|
|
40
|
+
const hasLayoutEvent = !!onLayout;
|
|
41
|
+
const onLayoutEvent = useEvent(onLayout || idFn);
|
|
42
|
+
useIsomorphicLayoutEffect(() => {
|
|
43
|
+
if (!resizeObserver || !hasLayoutEvent)
|
|
44
|
+
return;
|
|
45
|
+
const node = ref.current;
|
|
46
|
+
if (!node)
|
|
47
|
+
return;
|
|
48
|
+
LayoutHandlers.set(node, onLayoutEvent);
|
|
49
|
+
resizeObserver.observe(node);
|
|
50
|
+
return () => {
|
|
51
|
+
resizeObserver == null ? void 0 : resizeObserver.unobserve(node);
|
|
52
|
+
};
|
|
53
|
+
}, [ref, hasLayoutEvent]);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
measureLayout,
|
|
57
|
+
useElementLayout
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=useElementLayout.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useElementLayout.tsx"],
|
|
4
|
+
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useEvent } from '@tamagui/use-event'\nimport { RefObject } from 'react'\n\nimport { getBoundingClientRect } from '../helpers/getBoundingClientRect'\nimport { getRect } from '../helpers/getRect'\n\nconst LayoutHandlers = new WeakMap<Element, Function>()\n\nexport type LayoutValue = {\n x: number\n y: number\n width: number\n height: number\n left: number\n top: number\n}\n\nexport type LayoutEvent = {\n nativeEvent: {\n layout: LayoutValue\n target: any\n }\n timeStamp: number\n}\n\nlet resizeObserver: ResizeObserver | null = null\n\nif (typeof window !== 'undefined' && 'ResizeObserver' in window) {\n resizeObserver = new ResizeObserver((entries) => {\n for (const { target } of entries) {\n const onLayout = LayoutHandlers.get(target)\n if (typeof onLayout !== 'function') return\n measureLayout(target as HTMLElement, null, (x, y, width, height, left, top) => {\n onLayout({\n nativeEvent: {\n layout: { x, y, width, height, left, top },\n target,\n },\n timeStamp: Date.now(),\n })\n })\n }\n })\n}\n\nexport const measureLayout = (\n node: HTMLElement,\n relativeTo: HTMLElement | null,\n callback: Function\n) => {\n const relativeNode = relativeTo || node?.parentNode\n if (relativeNode instanceof HTMLElement) {\n setTimeout(() => {\n const relativeRect = getBoundingClientRect(relativeNode)!\n const { height, left, top, width } = getRect(node)!\n const x = left - relativeRect.left\n const y = top - relativeRect.top\n callback(x, y, width, height, left, top)\n }, 0)\n }\n}\n\nconst idFn = () => {}\n\nexport function useElementLayout(\n ref: RefObject<Element>,\n onLayout?: ((e: LayoutEvent) => void) | null\n) {\n const hasLayoutEvent = !!onLayout\n const onLayoutEvent = useEvent(onLayout || idFn)\n\n // Observing is done in a separate effect to avoid this effect running\n // when 'onLayout' changes.\n useIsomorphicLayoutEffect(() => {\n if (!resizeObserver || !hasLayoutEvent) return\n const node = ref.current\n if (!node) return\n LayoutHandlers.set(node, onLayoutEvent)\n resizeObserver.observe(node)\n return () => {\n resizeObserver?.unobserve(node)\n }\n }, [ref, hasLayoutEvent])\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AAGzB,SAAS,6BAA6B;AACtC,SAAS,eAAe;AAExB,MAAM,iBAAiB,oBAAI,QAA2B;AAmBtD,IAAI,iBAAwC;AAE5C,IAAI,OAAO,WAAW,eAAe,oBAAoB,QAAQ;AAC/D,mBAAiB,IAAI,eAAe,CAAC,YAAY;AAC/C,eAAW,EAAE,OAAO,KAAK,SAAS;AAChC,YAAM,WAAW,eAAe,IAAI,MAAM;AAC1C,UAAI,OAAO,aAAa;AAAY;AACpC,oBAAc,QAAuB,MAAM,CAAC,GAAG,GAAG,OAAO,QAAQ,MAAM,QAAQ;AAC7E,iBAAS;AAAA,UACP,aAAa;AAAA,YACX,QAAQ,EAAE,GAAG,GAAG,OAAO,QAAQ,MAAM,IAAI;AAAA,YACzC;AAAA,UACF;AAAA,UACA,WAAW,KAAK,IAAI;AAAA,QACtB,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;AAEO,MAAM,gBAAgB,CAC3B,MACA,YACA,aACG;AACH,QAAM,eAAe,eAAc,6BAAM;AACzC,MAAI,wBAAwB,aAAa;AACvC,eAAW,MAAM;AACf,YAAM,eAAe,sBAAsB,YAAY;AACvD,YAAM,EAAE,QAAQ,MAAM,KAAK,MAAM,IAAI,QAAQ,IAAI;AACjD,YAAM,IAAI,OAAO,aAAa;AAC9B,YAAM,IAAI,MAAM,aAAa;AAC7B,eAAS,GAAG,GAAG,OAAO,QAAQ,MAAM,GAAG;AAAA,IACzC,GAAG,CAAC;AAAA,EACN;AACF;AAEA,MAAM,OAAO,MAAM;AAAC;AAEb,SAAS,iBACd,KACA,UACA;AACA,QAAM,iBAAiB,CAAC,CAAC;AACzB,QAAM,gBAAgB,SAAS,YAAY,IAAI;AAI/C,4BAA0B,MAAM;AAC9B,QAAI,CAAC,kBAAkB,CAAC;AAAgB;AACxC,UAAM,OAAO,IAAI;AACjB,QAAI,CAAC;AAAM;AACX,mBAAe,IAAI,MAAM,aAAa;AACtC,mBAAe,QAAQ,IAAI;AAC3B,WAAO,MAAM;AACX,uDAAgB,UAAU;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,KAAK,cAAc,CAAC;AAC1B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "@tamagui/web";
|
|
2
|
+
import { getRect } from "../helpers/getRect";
|
|
3
|
+
import { measureLayout } from "./useElementLayout";
|
|
4
|
+
function usePlatformMethods(hostRef) {
|
|
5
|
+
useIsomorphicLayoutEffect(() => {
|
|
6
|
+
const node = hostRef.current;
|
|
7
|
+
if (!node)
|
|
8
|
+
return;
|
|
9
|
+
node.measure = (callback) => measureLayout(node, null, callback);
|
|
10
|
+
node.measureLayout = (relativeToNode, success) => measureLayout(node, relativeToNode, success);
|
|
11
|
+
node.measureInWindow = (callback) => {
|
|
12
|
+
if (!node)
|
|
13
|
+
return;
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
const { height, left, top, width } = getRect(node);
|
|
16
|
+
callback(left, top, width, height);
|
|
17
|
+
}, 0);
|
|
18
|
+
};
|
|
19
|
+
}, [hostRef]);
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
usePlatformMethods
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=usePlatformMethods.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/usePlatformMethods.ts"],
|
|
4
|
+
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/web'\nimport { RefObject } from 'react'\n\nimport { getRect } from '../helpers/getRect'\nimport { measureLayout } from './useElementLayout'\n\n// react native compat (web only)\nexport function usePlatformMethods(hostRef: RefObject<Element>) {\n useIsomorphicLayoutEffect(() => {\n const node = hostRef.current\n if (!node) return\n // @ts-ignore\n node.measure = (callback) => measureLayout(node, null, callback)\n // @ts-ignore\n node.measureLayout = (relativeToNode, success) =>\n measureLayout(node as HTMLElement, relativeToNode, success)\n // @ts-ignore\n node.measureInWindow = (callback) => {\n if (!node) return\n setTimeout(() => {\n const { height, left, top, width } = getRect(node as HTMLElement)!\n callback(left, top, width, height)\n }, 0)\n }\n }, [hostRef])\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iCAAiC;AAG1C,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAGvB,SAAS,mBAAmB,SAA6B;AAC9D,4BAA0B,MAAM;AAC9B,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC;AAAM;AAEX,SAAK,UAAU,CAAC,aAAa,cAAc,MAAM,MAAM,QAAQ;AAE/D,SAAK,gBAAgB,CAAC,gBAAgB,YACpC,cAAc,MAAqB,gBAAgB,OAAO;AAE5D,SAAK,kBAAkB,CAAC,aAAa;AACnC,UAAI,CAAC;AAAM;AACX,iBAAW,MAAM;AACf,cAAM,EAAE,QAAQ,MAAM,KAAK,MAAM,IAAI,QAAQ,IAAmB;AAChE,iBAAS,MAAM,KAAK,OAAO,MAAM;AAAA,MACnC,GAAG,CAAC;AAAA,IACN;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AACd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { useResponderEvents } from "@tamagui/react-native-use-responder-events";
|
|
2
|
+
import {
|
|
3
|
+
Stack as WebStack,
|
|
4
|
+
Text as WebText,
|
|
5
|
+
composeEventHandlers,
|
|
6
|
+
isRSC,
|
|
7
|
+
mergeEvent,
|
|
8
|
+
setupHooks,
|
|
9
|
+
styled
|
|
10
|
+
} from "@tamagui/web";
|
|
11
|
+
import { useElementLayout } from "./hooks/useElementLayout";
|
|
12
|
+
import { usePlatformMethods } from "./hooks/usePlatformMethods";
|
|
13
|
+
import { usePressability } from "./vendor/Pressability";
|
|
14
|
+
export * from "@tamagui/web";
|
|
15
|
+
const Stack = WebStack;
|
|
16
|
+
const Text = WebText;
|
|
17
|
+
const T = styled(Stack, {
|
|
18
|
+
backgroundColor: "red",
|
|
19
|
+
variants: {
|
|
20
|
+
red: {
|
|
21
|
+
true: {
|
|
22
|
+
backgroundColor: "red"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const T2 = styled(T, {
|
|
28
|
+
red: true
|
|
29
|
+
});
|
|
30
|
+
setupHooks({
|
|
31
|
+
getBaseViews() {
|
|
32
|
+
const native = require("react-native");
|
|
33
|
+
return {
|
|
34
|
+
View: native.View || native.default.View,
|
|
35
|
+
Text: native.Text || native.default.Text
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
usePropsTransform(elementType, propsIn, hostRef) {
|
|
39
|
+
const {
|
|
40
|
+
// event props
|
|
41
|
+
onMoveShouldSetResponder,
|
|
42
|
+
onMoveShouldSetResponderCapture,
|
|
43
|
+
onResponderEnd,
|
|
44
|
+
onResponderGrant,
|
|
45
|
+
onResponderMove,
|
|
46
|
+
onResponderReject,
|
|
47
|
+
onResponderRelease,
|
|
48
|
+
onResponderStart,
|
|
49
|
+
onResponderTerminate,
|
|
50
|
+
onResponderTerminationRequest,
|
|
51
|
+
onScrollShouldSetResponder,
|
|
52
|
+
onScrollShouldSetResponderCapture,
|
|
53
|
+
onSelectionChangeShouldSetResponder,
|
|
54
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
55
|
+
onStartShouldSetResponder,
|
|
56
|
+
onStartShouldSetResponderCapture,
|
|
57
|
+
// android
|
|
58
|
+
collapsable,
|
|
59
|
+
focusable,
|
|
60
|
+
// deprecated,
|
|
61
|
+
accessible,
|
|
62
|
+
accessibilityDisabled,
|
|
63
|
+
onLayout,
|
|
64
|
+
hrefAttrs,
|
|
65
|
+
...viewProps
|
|
66
|
+
} = propsIn;
|
|
67
|
+
if (!isRSC) {
|
|
68
|
+
usePlatformMethods(hostRef);
|
|
69
|
+
useElementLayout(hostRef, onLayout);
|
|
70
|
+
useResponderEvents(hostRef, {
|
|
71
|
+
onMoveShouldSetResponder,
|
|
72
|
+
onMoveShouldSetResponderCapture,
|
|
73
|
+
onResponderEnd,
|
|
74
|
+
onResponderGrant,
|
|
75
|
+
onResponderMove,
|
|
76
|
+
onResponderReject,
|
|
77
|
+
onResponderRelease,
|
|
78
|
+
onResponderStart,
|
|
79
|
+
onResponderTerminate,
|
|
80
|
+
onResponderTerminationRequest,
|
|
81
|
+
onScrollShouldSetResponder,
|
|
82
|
+
onScrollShouldSetResponderCapture,
|
|
83
|
+
onSelectionChangeShouldSetResponder,
|
|
84
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
85
|
+
onStartShouldSetResponder,
|
|
86
|
+
onStartShouldSetResponderCapture
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (viewProps.href !== void 0 && hrefAttrs !== void 0) {
|
|
90
|
+
const { download, rel, target } = hrefAttrs;
|
|
91
|
+
if (download != null) {
|
|
92
|
+
viewProps.download = download;
|
|
93
|
+
}
|
|
94
|
+
if (rel != null) {
|
|
95
|
+
viewProps.rel = rel;
|
|
96
|
+
}
|
|
97
|
+
if (typeof target === "string") {
|
|
98
|
+
viewProps.target = target.charAt(0) !== "_" ? `_${target}` : target;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!viewProps.tabIndex) {
|
|
102
|
+
const _focusable = focusable !== void 0 ? focusable : accessible;
|
|
103
|
+
const role = viewProps.role;
|
|
104
|
+
if (_focusable === false) {
|
|
105
|
+
viewProps.tabIndex = "-1";
|
|
106
|
+
}
|
|
107
|
+
if (
|
|
108
|
+
// These native elements are focusable by default
|
|
109
|
+
elementType === "a" || elementType === "button" || elementType === "input" || elementType === "select" || elementType === "textarea"
|
|
110
|
+
) {
|
|
111
|
+
if (_focusable === false || accessibilityDisabled === true) {
|
|
112
|
+
viewProps.tabIndex = "-1";
|
|
113
|
+
}
|
|
114
|
+
} else if (
|
|
115
|
+
// These roles are made focusable by default
|
|
116
|
+
role === "button" || role === "checkbox" || role === "link" || role === "radio" || role === "textbox" || role === "switch"
|
|
117
|
+
) {
|
|
118
|
+
if (_focusable !== false) {
|
|
119
|
+
viewProps.tabIndex = "0";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (_focusable === true) {
|
|
123
|
+
viewProps.tabIndex = "0";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return viewProps;
|
|
127
|
+
},
|
|
128
|
+
useEvents(viewProps, events, { pseudos }, setStateShallow) {
|
|
129
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
130
|
+
const attachFocus = !!(pseudos == null ? void 0 : pseudos.focusStyle);
|
|
131
|
+
if (attachFocus) {
|
|
132
|
+
viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {
|
|
133
|
+
setStateShallow({ focus: true });
|
|
134
|
+
});
|
|
135
|
+
viewProps.onBlur = mergeEvent(viewProps.onBlur, () => {
|
|
136
|
+
setStateShallow({ focus: false });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const pressability = usePressability(
|
|
140
|
+
events ? { ...events, hitSlop: viewProps.hitSlop } : {}
|
|
141
|
+
);
|
|
142
|
+
if (events == null ? void 0 : events.onPress) {
|
|
143
|
+
for (const key in pressability) {
|
|
144
|
+
const og = viewProps[key];
|
|
145
|
+
const val = pressability[key];
|
|
146
|
+
viewProps[key] = og && !dontComposePressabilityKeys[key] ? composeEventHandlers(og, val) : val;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const dontComposePressabilityKeys = {
|
|
153
|
+
onClick: true
|
|
154
|
+
};
|
|
155
|
+
export {
|
|
156
|
+
Stack,
|
|
157
|
+
Text
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { useResponderEvents } from '@tamagui/react-native-use-responder-events'\nimport {\n StackProps,\n StackPropsBase,\n TamaguiComponent,\n TextProps,\n TextPropsBase,\n Stack as WebStack,\n Text as WebText,\n composeEventHandlers,\n isRSC,\n mergeEvent,\n setupHooks,\n styled,\n} from '@tamagui/web'\nimport { RefObject } from 'react'\nimport type { Text as RNText, View as RNView } from 'react-native'\n\nimport { useElementLayout } from './hooks/useElementLayout'\nimport { usePlatformMethods } from './hooks/usePlatformMethods'\nimport type { RNTextProps, RNViewProps } from './reactNativeTypes'\nimport { usePressability } from './vendor/Pressability'\n\n// re-exports all of @tamagui/web just adds hooks\nexport * from '@tamagui/web'\n\n// adds extra types to Stack/Text:\n\nexport const Stack = WebStack as TamaguiComponent<\n StackProps & RNViewProps,\n RNView,\n StackPropsBase & RNViewProps\n>\n\nexport const Text = WebText as TamaguiComponent<\n TextProps & RNTextProps,\n RNText,\n TextPropsBase & RNTextProps\n>\n\nconst T = styled(Stack, {\n backgroundColor: 'red',\n variants: {\n red: {\n true: {\n backgroundColor: 'red',\n },\n },\n },\n})\n\nconst T2 = styled(T, {\n red: true,\n})\n\n// setup internal hooks:\n\nsetupHooks({\n getBaseViews() {\n const native = require('react-native')\n return {\n View: native.View || native.default.View,\n Text: native.Text || native.default.Text,\n }\n },\n\n usePropsTransform(elementType, propsIn, hostRef) {\n // otherwise replicate react-native-web functionality\n const {\n // event props\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n\n // android\n collapsable,\n focusable,\n\n // deprecated,\n accessible,\n accessibilityDisabled,\n\n onLayout,\n hrefAttrs,\n\n ...viewProps\n } = propsIn\n\n if (!isRSC) {\n usePlatformMethods(hostRef as RefObject<Element>)\n useElementLayout(hostRef as RefObject<Element>, onLayout as any)\n useResponderEvents(hostRef, {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n } as any)\n }\n\n // TODO move into getSplitStyles inital `if (process.env.TAMAGUI_TARGET === 'web')` block\n\n if (viewProps.href !== undefined && hrefAttrs !== undefined) {\n const { download, rel, target } = hrefAttrs\n if (download != null) {\n viewProps.download = download\n }\n if (rel != null) {\n viewProps.rel = rel\n }\n if (typeof target === 'string') {\n viewProps.target = target.charAt(0) !== '_' ? `_${target}` : target\n }\n }\n\n // FOCUS\n // \"focusable\" indicates that an element may be a keyboard tab-stop.\n // ported from RNW: TODO move into getSplitStyles\n if (!viewProps.tabIndex) {\n const _focusable = focusable !== undefined ? focusable : accessible\n const role = viewProps.role\n if (_focusable === false) {\n viewProps.tabIndex = '-1'\n }\n if (\n // These native elements are focusable by default\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n ) {\n if (_focusable === false || accessibilityDisabled === true) {\n viewProps.tabIndex = '-1'\n }\n } else if (\n // These roles are made focusable by default\n role === 'button' ||\n role === 'checkbox' ||\n role === 'link' ||\n role === 'radio' ||\n role === 'textbox' ||\n role === 'switch'\n ) {\n if (_focusable !== false) {\n viewProps.tabIndex = '0'\n }\n }\n // Everything else must explicitly set the prop\n if (_focusable === true) {\n viewProps.tabIndex = '0'\n }\n }\n\n return viewProps\n },\n\n useEvents(viewProps, events, { pseudos }, setStateShallow) {\n if (process.env.TAMAGUI_TARGET === 'native') {\n const attachFocus = !!pseudos?.focusStyle\n if (attachFocus) {\n viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {\n setStateShallow({ focus: true })\n })\n viewProps.onBlur = mergeEvent(viewProps.onBlur, () => {\n setStateShallow({ focus: false })\n })\n }\n\n // use Pressability to get smooth unPress when you press + hold + move out\n // only ever create once, use .configure() to update later\n const pressability = usePressability(\n events ? { ...events, hitSlop: viewProps.hitSlop } : {}\n )\n if (events?.onPress) {\n for (const key in pressability) {\n const og = viewProps[key]\n const val = pressability[key]\n viewProps[key] =\n og && !dontComposePressabilityKeys[key] ? composeEventHandlers(og, val) : val\n }\n }\n }\n },\n})\n\nconst dontComposePressabilityKeys = {\n onClick: true,\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,0BAA0B;AACnC;AAAA,EAME,SAAS;AAAA,EACT,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB;AAGhC,cAAc;AAIP,MAAM,QAAQ;AAMd,MAAM,OAAO;AAMpB,MAAM,IAAI,OAAO,OAAO;AAAA,EACtB,iB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AG;AAC5B,oBAAU,GAAG,IACX,MAAM,CAAC,4BAA4B,GAAG,IAAI,qBAAqB,IAAI,GAAG,IAAI;AAAA,QAC9E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAED,MAAM,8BAA8B;AAAA,EAClC,SAAS;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const stylesheets = {};
|
|
2
|
+
const injectStyles = ({ filePath, css }) => {
|
|
3
|
+
let stylesheet = stylesheets[filePath];
|
|
4
|
+
if (!stylesheet) {
|
|
5
|
+
const styleEl = document.createElement("style");
|
|
6
|
+
styleEl.setAttribute("data-file", filePath);
|
|
7
|
+
styleEl.setAttribute("type", "text/css");
|
|
8
|
+
stylesheet = stylesheets[filePath] = styleEl;
|
|
9
|
+
document.head.appendChild(styleEl);
|
|
10
|
+
}
|
|
11
|
+
stylesheet.innerHTML = css;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
injectStyles
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=inject-styles.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/inject-styles.ts"],
|
|
4
|
+
"sourcesContent": ["// for vite dev mode\n\nconst stylesheets: Record<string, HTMLElement> = {}\n\ninterface InjectStylesOptions {\n filePath: string\n css: string\n}\n\nexport const injectStyles = ({ filePath, css }: InjectStylesOptions) => {\n let stylesheet = stylesheets[filePath]\n if (!stylesheet) {\n const styleEl = document.createElement('style')\n styleEl.setAttribute('data-file', filePath)\n styleEl.setAttribute('type', 'text/css')\n stylesheet = stylesheets[filePath] = styleEl\n document.head.appendChild(styleEl)\n }\n stylesheet.innerHTML = css\n}\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,cAA2C,CAAC;AAO3C,MAAM,eAAe,CAAC,EAAE,UAAU,IAAI,MAA2B;AACtE,MAAI,aAAa,YAAY,QAAQ;AACrC,MAAI,CAAC,YAAY;AACf,UAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,YAAQ,aAAa,aAAa,QAAQ;AAC1C,YAAQ,aAAa,QAAQ,UAAU;AACvC,iBAAa,YAAY,QAAQ,IAAI;AACrC,aAAS,KAAK,YAAY,OAAO;AAAA,EACnC;AACA,aAAW,YAAY;AACzB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=reactNativeTypes.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const Pressability = require("react-native/Libraries/Pressability/Pressability").default;
|
|
2
|
+
const usePressability = require("react-native/Libraries/Pressability/usePressability").default;
|
|
3
|
+
export {
|
|
4
|
+
Pressability,
|
|
5
|
+
usePressability
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=Pressability.native.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/vendor/Pressability.native.tsx"],
|
|
4
|
+
"sourcesContent": ["export const Pressability =\n require('react-native/Libraries/Pressability/Pressability').default\nexport const usePressability =\n require('react-native/Libraries/Pressability/usePressability').default\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,eACX,QAAQ,kDAAkD,EAAE;AACvD,MAAM,kBACX,QAAQ,qDAAqD,EAAE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"reset.css"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/react-native-use-pressable": "^1.2.
|
|
31
|
-
"@tamagui/react-native-use-responder-events": "^1.2.
|
|
32
|
-
"@tamagui/web": "^1.2.
|
|
30
|
+
"@tamagui/react-native-use-pressable": "^1.2.10",
|
|
31
|
+
"@tamagui/react-native-use-responder-events": "^1.2.10",
|
|
32
|
+
"@tamagui/web": "^1.2.10"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "*",
|
|
36
36
|
"react-dom": "*"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tamagui/build": "^1.2.
|
|
39
|
+
"@tamagui/build": "^1.2.10",
|
|
40
40
|
"@testing-library/react": "^13.4.0",
|
|
41
41
|
"csstype": "^3.0.10",
|
|
42
42
|
"react": "^18.2.0",
|
|
@@ -49,13 +49,18 @@
|
|
|
49
49
|
"./reset.css": "./reset.css",
|
|
50
50
|
".": {
|
|
51
51
|
"types": "./types/index.d.ts",
|
|
52
|
-
"import": "./dist/esm/index.
|
|
52
|
+
"import": "./dist/esm/index.mjs",
|
|
53
53
|
"require": "./dist/cjs/index.js"
|
|
54
54
|
},
|
|
55
55
|
"./inject-styles": {
|
|
56
56
|
"types": "./types/inject-styles.d.ts",
|
|
57
|
-
"import": "./dist/esm/inject-styles.
|
|
57
|
+
"import": "./dist/esm/inject-styles.mjs",
|
|
58
58
|
"require": "./dist/cjs/inject-styles.js"
|
|
59
|
+
},
|
|
60
|
+
"./reactNativeTypes": {
|
|
61
|
+
"types": "./types/reactNativeTypes.d.ts",
|
|
62
|
+
"import": "./dist/esm/reactNativeTypes.js",
|
|
63
|
+
"require": "./dist/cjs/reactNativeTypes.js"
|
|
59
64
|
}
|
|
60
65
|
},
|
|
61
66
|
"repository": {
|