@tamagui/core 1.0.1-beta.215 → 1.0.1-beta.217
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/createComponent.js +39 -81
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +2 -2
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +44 -38
- package/dist/cjs/helpers/getSplitStyles.js.map +3 -3
- package/dist/cjs/helpers/mergeProps.js.map +2 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js +7 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/useShallowSetState.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +43 -38
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/views/ThemeInverse.js +1 -2
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/esm/createComponent.js +41 -87
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +2 -2
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +44 -38
- package/dist/esm/helpers/getSplitStyles.js.map +3 -3
- package/dist/esm/helpers/mergeProps.js.map +2 -2
- package/dist/esm/helpers/normalizeValueWithProperty.js +7 -2
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/useShallowSetState.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +44 -39
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/views/ThemeInverse.js +1 -2
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/package.json +16 -16
- package/src/createComponent.tsx +52 -103
- package/src/createTamagui.ts +2 -2
- package/src/helpers/createPropMapper.ts +1 -0
- package/src/helpers/getSplitStyles.tsx +44 -37
- package/src/helpers/mergeProps.ts +7 -7
- package/src/helpers/normalizeValueWithProperty.ts +9 -2
- package/src/helpers/useShallowSetState.tsx +3 -1
- package/src/hooks/useMedia.tsx +49 -41
- package/src/views/ThemeInverse.tsx +1 -2
- package/types/helpers/mergeProps.d.ts +2 -2
- package/types/helpers/useShallowSetState.d.ts +2 -1
|
@@ -33,7 +33,6 @@ __export(useMedia_exports, {
|
|
|
33
33
|
useMediaPropsActive: () => useMediaPropsActive
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(useMedia_exports);
|
|
36
|
-
var import_constants = require("@tamagui/constants");
|
|
37
36
|
var import_react = require("react");
|
|
38
37
|
var import_config = require("../config");
|
|
39
38
|
var import_createProxy = require("../helpers/createProxy");
|
|
@@ -64,13 +63,10 @@ function removeMediaQueryListener(key, cb) {
|
|
|
64
63
|
(_a = listeners[key]) == null ? void 0 : _a.delete(cb);
|
|
65
64
|
}
|
|
66
65
|
const mediaQueryConfig = {};
|
|
67
|
-
const getMedia = () =>
|
|
68
|
-
return mediaState;
|
|
69
|
-
};
|
|
70
|
-
let curState;
|
|
66
|
+
const getMedia = () => mediaState;
|
|
71
67
|
let initState;
|
|
72
68
|
const getInitialMediaState = () => {
|
|
73
|
-
return ((0, import_config.getConfig)().disableSSR ?
|
|
69
|
+
return ((0, import_config.getConfig)().disableSSR ? mediaState : initState) || {};
|
|
74
70
|
};
|
|
75
71
|
let mediaKeysOrdered;
|
|
76
72
|
const getMediaKeyImportance = (key) => mediaKeysOrdered.indexOf(key[0] === "$" ? key.slice(1) : key) + 2;
|
|
@@ -83,8 +79,8 @@ const configureMedia = (config) => {
|
|
|
83
79
|
mediaState[key] = (mediaQueryDefaultActive == null ? void 0 : mediaQueryDefaultActive[key]) || false;
|
|
84
80
|
}
|
|
85
81
|
Object.assign(mediaQueryConfig, media);
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
initState = { ...mediaState };
|
|
83
|
+
updateCurrentState();
|
|
88
84
|
mediaKeysOrdered = Object.keys(media);
|
|
89
85
|
if (config.disableSSR) {
|
|
90
86
|
setupMediaListeners();
|
|
@@ -108,7 +104,7 @@ function setupMediaListeners() {
|
|
|
108
104
|
if (next === mediaState[key])
|
|
109
105
|
return;
|
|
110
106
|
mediaState[key] = next;
|
|
111
|
-
|
|
107
|
+
updateCurrentState();
|
|
112
108
|
const cur = listeners[key];
|
|
113
109
|
if (cur == null ? void 0 : cur.size) {
|
|
114
110
|
cur.forEach((cb) => cb(next));
|
|
@@ -134,39 +130,48 @@ function useMediaListeners(config) {
|
|
|
134
130
|
return unlisten;
|
|
135
131
|
}, []);
|
|
136
132
|
}
|
|
133
|
+
const nextTick = process.nextTick || setImmediate;
|
|
134
|
+
const currentStateListeners = /* @__PURE__ */ new Set();
|
|
135
|
+
let isUpdating = false;
|
|
136
|
+
function updateCurrentState() {
|
|
137
|
+
if (isUpdating)
|
|
138
|
+
return;
|
|
139
|
+
isUpdating = true;
|
|
140
|
+
nextTick(() => {
|
|
141
|
+
currentStateListeners.forEach((cb) => cb(mediaState));
|
|
142
|
+
isUpdating = false;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function subscribe(subscriber) {
|
|
146
|
+
currentStateListeners.add(subscriber);
|
|
147
|
+
return () => currentStateListeners.delete(subscriber);
|
|
148
|
+
}
|
|
137
149
|
function useMedia() {
|
|
138
|
-
const keys = (0, import_useSafeRef.useSafeRef)({});
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
150
|
+
const keys = (0, import_useSafeRef.useSafeRef)({ prev: initState });
|
|
151
|
+
const state = (0, import_react.useSyncExternalStore)(
|
|
152
|
+
subscribe,
|
|
153
|
+
() => {
|
|
154
|
+
const { prev, ...curKeys } = keys.current;
|
|
155
|
+
const shouldUpdate = !prev || Object.keys(curKeys).some((k) => mediaState[k] !== prev[k]);
|
|
156
|
+
if (shouldUpdate) {
|
|
157
|
+
const next = { ...mediaState };
|
|
158
|
+
keys.current.prev = next;
|
|
159
|
+
return next;
|
|
146
160
|
}
|
|
147
161
|
return prev;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
(key)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}, [keys.current]);
|
|
159
|
-
return state;
|
|
160
|
-
}
|
|
161
|
-
function getMediaState(state, keys) {
|
|
162
|
-
return new Proxy(state, {
|
|
163
|
-
get(_, key) {
|
|
164
|
-
if (!keys.current[key]) {
|
|
165
|
-
keys.current[key] = true;
|
|
162
|
+
},
|
|
163
|
+
() => initState
|
|
164
|
+
);
|
|
165
|
+
return (0, import_react.useMemo)(() => {
|
|
166
|
+
return new Proxy(state, {
|
|
167
|
+
get(_, key) {
|
|
168
|
+
if (!keys.current[key]) {
|
|
169
|
+
keys.current[key] = true;
|
|
170
|
+
}
|
|
171
|
+
return Reflect.get(state, key);
|
|
166
172
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
173
|
+
});
|
|
174
|
+
}, [state]);
|
|
170
175
|
}
|
|
171
176
|
function useMediaPropsActive(props) {
|
|
172
177
|
const media = useMedia();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useMedia.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { MutableRefObject, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development time safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\ntype MediaListener = (next: boolean) => void\n\nconst listeners: { [key: string]: Set<MediaListener> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n // eslint-disable-next-line no-console\n console.warn(`Warning, listening to media queries shouldn't use the \"$\" prefix`)\n }\n listeners[key] = listeners[key] || new Set()\n listeners[key].add(cb)\n return () => removeMediaQueryListener(key, cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n listeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () =>
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { MutableRefObject, useEffect, useMemo, useState, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development time safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\ntype MediaListener = (next: boolean) => void\n\nconst listeners: { [key: string]: Set<MediaListener> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n // eslint-disable-next-line no-console\n console.warn(`Warning, listening to media queries shouldn't use the \"$\" prefix`)\n }\n listeners[key] = listeners[key] || new Set()\n listeners[key].add(cb)\n return () => removeMediaQueryListener(key, cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n listeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () => mediaState\n\n// for SSR capture it at time of startup\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? mediaState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) =>\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n mediaKeysOrdered.indexOf(key[0] === '$' ? key.slice(1) : key) + 2\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n }\n Object.assign(mediaQueryConfig, media)\n initState = { ...mediaState }\n updateCurrentState()\n mediaKeysOrdered = Object.keys(media)\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) {\n return\n }\n configuredKey = nextKey\n\n // hmr, undo existing before re-binding\n unlisten()\n\n for (const key in mediaQueryConfig) {\n const str = mediaObjectToString(mediaQueryConfig[key])\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match) {\n throw new Error('\u26A0\uFE0F No match')\n }\n // react native needs these deprecated apis for now\n match.addListener(update)\n dispose.add(() => match.removeListener(update))\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n updateCurrentState()\n const cur = listeners[key]\n if (cur?.size) {\n cur.forEach((cb) => cb(next))\n }\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n return unlisten\n }, [])\n}\n\nconst nextTick = process.nextTick || setImmediate\nconst currentStateListeners = new Set<any>()\nlet isUpdating = false\nfunction updateCurrentState() {\n if (isUpdating) return\n isUpdating = true\n nextTick(() => {\n currentStateListeners.forEach((cb) => cb(mediaState))\n isUpdating = false\n })\n}\nfunction subscribe(subscriber: any) {\n currentStateListeners.add(subscriber)\n return () => currentStateListeners.delete(subscriber)\n}\n\ntype MediaKeysState = {\n [key: string]: any\n}\n\nexport function useMedia(): {\n [key in MediaQueryKey]: boolean\n} {\n const keys = useSafeRef<MediaKeysState>({ prev: initState })\n\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const { prev, ...curKeys } = keys.current\n const shouldUpdate = !prev || Object.keys(curKeys).some((k) => mediaState[k] !== prev[k])\n if (shouldUpdate) {\n const next = { ...mediaState }\n keys.current.prev = next\n return next\n }\n return prev\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state, {\n get(_, key: string) {\n if (!keys.current[key]) {\n keys.current[key] = true\n }\n return Reflect.get(state, key)\n },\n })\n }, [state])\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, is will loop props and trigger re-render on all media queries.\n *\n * */\nexport function useMediaPropsActive<A extends Object>(\n props: A\n): {\n // remove all media\n [Key in keyof A extends `$${string}` ? never : keyof A]?: A[Key]\n} {\n const media = useMedia()\n\n return useMemo(() => {\n const next = {} as A\n const importancesUsed = {}\n const propNames = Object.keys(props)\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n if (!media[key.slice(1)]) {\n continue\n }\n if (val && typeof val === 'object') {\n const subKeys = Object.keys(val)\n for (let j = subKeys.length; j--; j >= 0) {\n const subKey = subKeys[j]\n mergeMediaByImportance(next, subKey, val[subKey], importancesUsed)\n }\n }\n } else {\n mergeMediaByImportance(next, key, val, importancesUsed)\n }\n }\n\n return next\n }, [media, props])\n}\n\nexport function mergeMediaByImportance(\n onto: Record<string, any>,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaKeyImportance(key)\n if (importancesUsed[key] > importance) {\n return false\n }\n importancesUsed[key] = importance\n onto[key] = value\n return true\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqF;AAErF,oBAA0B;AAC1B,yBAA4B;AAC5B,wBAA2B;AAQ3B,wBAA2B;AAEpB,MAAM,aAEX,QAAQ,IAAI,aAAa,oBACrB;AAAA,EACE,CAAC;AAAA,EACD;AAAA,IACE,IAAI,QAAQ,KAAK;AACf,UACE,OAAO,QAAQ,YACf,IAAI,OAAO,OAEX,IAAI,OAAO,KACX;AACA,cAAM,IAAI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;AAAA,MACxD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,OAAO,KAAK,CAAC;AACnB;AAEO,SAAS,uBACd,MACA,KACA,OACA,iBACA;AACA,QAAM,aAAa,sBAAsB,GAAG;AAC5C,MAAI,gBAAgB,OAAO,YAAY;AACrC,WAAO;AAAA,EACT;AACA,kBAAgB,OAAO;AACvB,OAAK,OAAO;AACZ,SAAO;AACT;AAEA,SAAS,cAAc,KAAa;AAClC,SAAO,IAAI,QAAQ,UAAU,CAAC,MAAM,IAAI,EAAE,YAAY,GAAG,EAAE,YAAY;AACzE;AAEO,SAAS,oBAAoB,OAAkC;AACpE,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,SAAO,OAAO,QAAQ,KAAK,EACxB,IAAI,CAAC,CAAC,SAAS,KAAK,MAAM;AACzB,cAAU,cAAc,OAAO;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,YAAY;AAAA,IACzB;AACA,QAAI,OAAO,UAAU,YAAY,kBAAkB,KAAK,OAAO,GAAG;AAChE,cAAQ,GAAG;AAAA,IACb;AACA,WAAO,IAAI,YAAY;AAAA,EACzB,CAAC,EACA,KAAK,OAAO;AACjB;",
|
|
6
6
|
"names": ["update"]
|
|
7
7
|
}
|
|
@@ -36,8 +36,7 @@ const ThemeInverse = ({
|
|
|
36
36
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
37
37
|
if (themeName.startsWith("dark")) {
|
|
38
38
|
setName("light");
|
|
39
|
-
}
|
|
40
|
-
if (themeName.startsWith("light")) {
|
|
39
|
+
} else if (themeName.startsWith("light")) {
|
|
41
40
|
setName("dark");
|
|
42
41
|
}
|
|
43
42
|
}, [defaultTheme, themeName]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeInverse.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n }
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n } else if (themeName.startsWith('light')) {\n setName('dark')\n }\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BS;AA9BT,uBAA0C;AAC1C,mBAAgC;AAEhC,sBAAkD;AAClD,mBAAsB;AAEf,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAGM;AACJ,QAAM,gBAAY,8BAAa;AAC/B,QAAM,mBAAe,qCAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAwB,IAAI;AAGpD,kDAA0B,MAAM;AAC9B,QAAI,UAAU,WAAW,MAAM,GAAG;AAChC,cAAQ,OAAO;AAAA,IACjB,WAAW,UAAU,WAAW,OAAO,GAAG;AACxC,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,4CAAC;AAAA,IAAM;AAAA,IAAa;AAAA,GAAS;AACtC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
-
import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
|
+
import { isClient, isRSC, isServer, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
4
4
|
import {
|
|
5
5
|
composeEventHandlers,
|
|
6
6
|
stylePropsTransform,
|
|
@@ -26,11 +26,7 @@ import { stackDefaultStyles } from "./constants/constants";
|
|
|
26
26
|
import { FontLanguageContext } from "./contexts/FontLanguageContext";
|
|
27
27
|
import { TextAncestorContext } from "./contexts/TextAncestorContext";
|
|
28
28
|
import { extendStaticConfig, parseStaticConfig } from "./helpers/extendStaticConfig";
|
|
29
|
-
import {
|
|
30
|
-
getSubStyle,
|
|
31
|
-
insertSplitStyles,
|
|
32
|
-
useSplitStyles
|
|
33
|
-
} from "./helpers/getSplitStyles";
|
|
29
|
+
import { getSubStyle, useSplitStyles } from "./helpers/getSplitStyles";
|
|
34
30
|
import { getAllSelectors } from "./helpers/insertStyleRule";
|
|
35
31
|
import { mergeProps } from "./helpers/mergeProps";
|
|
36
32
|
import { mergeTransform } from "./helpers/mergeTransform";
|
|
@@ -87,7 +83,6 @@ function createComponent(configIn, ParentComponent) {
|
|
|
87
83
|
let defaultNativeStyle;
|
|
88
84
|
let tamaguiDefaultProps;
|
|
89
85
|
let defaultTag;
|
|
90
|
-
let initialSplitStyles;
|
|
91
86
|
const component = forwardRef((propsIn, forwardedRef) => {
|
|
92
87
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
93
88
|
let props;
|
|
@@ -121,13 +116,19 @@ function createComponent(configIn, ParentComponent) {
|
|
|
121
116
|
staticConfig.isReactNative || isAnimated && tamaguiConfig.animations.isReactNative
|
|
122
117
|
);
|
|
123
118
|
if (process.env.NODE_ENV === "development") {
|
|
124
|
-
if (
|
|
119
|
+
if (debugProp) {
|
|
125
120
|
const name = `${componentName || (Component == null ? void 0 : Component.displayName) || (Component == null ? void 0 : Component.name) || "[Unnamed Component]"}`;
|
|
126
121
|
const type = isReactNative ? "(rnw)" : "";
|
|
127
122
|
const dataIs = propsIn["data-is"] || "";
|
|
128
123
|
const banner = `${name}${dataIs ? ` ${dataIs}` : ""} ${type}`;
|
|
129
124
|
console.group(`%c ${banner}`, "background: yellow;");
|
|
130
|
-
|
|
125
|
+
if (!isServer) {
|
|
126
|
+
console.log(`state`, state);
|
|
127
|
+
console.groupCollapsed("props");
|
|
128
|
+
console.log(props);
|
|
129
|
+
console.log("order", Object.keys(props));
|
|
130
|
+
console.groupEnd();
|
|
131
|
+
}
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
const forceUpdate = useForceUpdate();
|
|
@@ -156,19 +157,18 @@ function createComponent(configIn, ParentComponent) {
|
|
|
156
157
|
let elementType = isText ? (isAnimated ? AnimatedText : null) || BaseTextComponent : (isAnimated ? AnimatedView : null) || BaseViewComponent;
|
|
157
158
|
elementType = Component || elementType;
|
|
158
159
|
const isStringElement = typeof elementType === "string";
|
|
159
|
-
const splitStyleState = {
|
|
160
|
-
...state,
|
|
161
|
-
noClassNames,
|
|
162
|
-
dynamicStylesInline: noClassNames,
|
|
163
|
-
hasTextAncestor,
|
|
164
|
-
resolveVariablesAs: "value"
|
|
165
|
-
};
|
|
166
160
|
const splitStyles = useSplitStyles(
|
|
167
161
|
props,
|
|
168
162
|
staticConfig,
|
|
169
163
|
theme,
|
|
170
|
-
|
|
171
|
-
|
|
164
|
+
{
|
|
165
|
+
...state,
|
|
166
|
+
noClassNames,
|
|
167
|
+
dynamicStylesInline: noClassNames,
|
|
168
|
+
hasTextAncestor,
|
|
169
|
+
resolveVariablesAs: "value"
|
|
170
|
+
},
|
|
171
|
+
null,
|
|
172
172
|
languageContext || void 0,
|
|
173
173
|
elementType,
|
|
174
174
|
debugProp
|
|
@@ -411,11 +411,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
411
411
|
styles = [isWeb ? null : defaultNativeStyle, animationStyles ?? splitStylesStyle, medias];
|
|
412
412
|
if (shouldForcePseudo) {
|
|
413
413
|
const next = {};
|
|
414
|
-
|
|
415
|
-
if (style) {
|
|
416
|
-
Object.assign(next, style);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
414
|
+
styles.forEach((style) => Object.assign(next, style));
|
|
419
415
|
Object.assign(splitStyles.style, next);
|
|
420
416
|
}
|
|
421
417
|
}
|
|
@@ -481,15 +477,13 @@ function createComponent(configIn, ParentComponent) {
|
|
|
481
477
|
}
|
|
482
478
|
viewProps.style = styles;
|
|
483
479
|
}
|
|
484
|
-
const
|
|
485
|
-
const runtimePressStyle = noClassNames && ((pseudos == null ? void 0 : pseudos.pressStyle) || (initialPseudos == null ? void 0 : initialPseudos.pressStyle));
|
|
480
|
+
const runtimePressStyle = !disabled && noClassNames && (pseudos == null ? void 0 : pseudos.pressStyle);
|
|
486
481
|
const attachPress = !!(runtimePressStyle || onPress || onPressOut || onPressIn || onClick);
|
|
487
|
-
const
|
|
488
|
-
const
|
|
489
|
-
const attachHover = isHoverable && !!(runtimeHoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);
|
|
482
|
+
const runtimeHoverStyle = !disabled && noClassNames && (pseudos == null ? void 0 : pseudos.hoverStyle);
|
|
483
|
+
const isHoverable = isWeb && !!(runtimeHoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);
|
|
490
484
|
const handlesPressEvents = !isWeb && !asChild;
|
|
491
485
|
const shouldAttach = asChild ? false : Boolean(
|
|
492
|
-
attachPress ||
|
|
486
|
+
attachPress || isHoverable || "pressStyle" in props || "onPress" in props || "onPressIn" in props || "onPressOut" in props || isWeb && ("hoverStyle" in props || "onHoverIn" in props || "onHoverOut" in props || "onMouseEnter" in props || "onMouseLeave" in props)
|
|
493
487
|
);
|
|
494
488
|
const events = shouldAttach && !isRSC && !isDisabled ? {
|
|
495
489
|
onPressOut: attachPress ? (e) => {
|
|
@@ -497,25 +491,25 @@ function createComponent(configIn, ParentComponent) {
|
|
|
497
491
|
onPressOut == null ? void 0 : onPressOut(e);
|
|
498
492
|
onMouseUp == null ? void 0 : onMouseUp(e);
|
|
499
493
|
} : void 0,
|
|
500
|
-
...
|
|
501
|
-
onMouseEnter:
|
|
494
|
+
...isHoverable && {
|
|
495
|
+
onMouseEnter: isHoverable ? (e) => {
|
|
502
496
|
const next = {};
|
|
503
|
-
if (
|
|
497
|
+
if (isHoverable) {
|
|
504
498
|
next.hover = true;
|
|
505
499
|
}
|
|
506
500
|
if (state.pressIn) {
|
|
507
501
|
next.press = true;
|
|
508
502
|
}
|
|
509
|
-
if (
|
|
503
|
+
if (isHoverable || state.pressIn) {
|
|
510
504
|
setStateShallow(next);
|
|
511
505
|
}
|
|
512
506
|
onHoverIn == null ? void 0 : onHoverIn(e);
|
|
513
507
|
onMouseEnter == null ? void 0 : onMouseEnter(e);
|
|
514
508
|
} : void 0,
|
|
515
|
-
onMouseLeave:
|
|
509
|
+
onMouseLeave: isHoverable ? (e) => {
|
|
516
510
|
const next = {};
|
|
517
511
|
mouseUps.add(unPress);
|
|
518
|
-
if (
|
|
512
|
+
if (isHoverable) {
|
|
519
513
|
next.hover = false;
|
|
520
514
|
}
|
|
521
515
|
if (state.pressIn) {
|
|
@@ -592,7 +586,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
592
586
|
};
|
|
593
587
|
}
|
|
594
588
|
if (process.env.TAMAGUI_TARGET === "native") {
|
|
595
|
-
const attachFocus = !!
|
|
589
|
+
const attachFocus = !!pseudos.focusStyle;
|
|
596
590
|
if (attachFocus) {
|
|
597
591
|
viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {
|
|
598
592
|
setStateShallow({ focus: true });
|
|
@@ -638,7 +632,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
638
632
|
console.log("children", content);
|
|
639
633
|
console.groupEnd();
|
|
640
634
|
if (typeof window !== "undefined") {
|
|
641
|
-
console.log({ state, shouldProvideThemeManager, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: (_f = props.className) == null ? void 0 : _f.split(" "), classNamesOut: (_g = viewProps.className) == null ? void 0 : _g.split(" "), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, defaultNativeStyle,
|
|
635
|
+
console.log({ state, shouldProvideThemeManager, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: (_f = props.className) == null ? void 0 : _f.split(" "), classNamesOut: (_g = viewProps.className) == null ? void 0 : _g.split(" "), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, defaultNativeStyle, ...typeof window !== "undefined" ? { theme, themeClassName: theme.className, staticConfig, tamaguiConfig, events, shouldAvoidClasses, shouldForcePseudo, classNames: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) } : null });
|
|
642
636
|
}
|
|
643
637
|
console.groupEnd();
|
|
644
638
|
}
|
|
@@ -692,38 +686,16 @@ function createComponent(configIn, ParentComponent) {
|
|
|
692
686
|
);
|
|
693
687
|
}
|
|
694
688
|
const debug = defaultPropsIn["debug"];
|
|
695
|
-
const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {}
|
|
689
|
+
const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {});
|
|
696
690
|
if (ourProps.tag) {
|
|
697
691
|
defaultTag = ourProps.tag;
|
|
698
692
|
}
|
|
699
693
|
const noClassNames = !staticConfig.acceptsClassName;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
unmounted: false,
|
|
706
|
-
hover: false,
|
|
707
|
-
press: false,
|
|
708
|
-
pressIn: false,
|
|
709
|
-
focus: false,
|
|
710
|
-
resolveVariablesAs: "both",
|
|
711
|
-
noClassNames
|
|
712
|
-
},
|
|
713
|
-
void 0,
|
|
714
|
-
void 0,
|
|
715
|
-
debug
|
|
716
|
-
);
|
|
717
|
-
const [defaults, defaultsClassnames] = mergeProps(
|
|
718
|
-
component.defaultProps,
|
|
719
|
-
{ ...initialSplitStyles.pseudos, ...initialSplitStyles.viewProps },
|
|
720
|
-
true
|
|
721
|
-
);
|
|
722
|
-
initialSplitStyles.classNames = {
|
|
723
|
-
...defaultsClassnames,
|
|
724
|
-
...initialSplitStyles.classNames,
|
|
725
|
-
...ourClassNames
|
|
726
|
-
};
|
|
694
|
+
const { name, variants, defaultVariants, ...restProps } = ourProps;
|
|
695
|
+
const [defaults, defaultsClassnames] = mergeProps(component.defaultProps, {
|
|
696
|
+
...defaultVariants,
|
|
697
|
+
...restProps
|
|
698
|
+
});
|
|
727
699
|
defaultNativeStyle = {};
|
|
728
700
|
const validStyles2 = staticConfig.validStyles || stylePropsView;
|
|
729
701
|
if (!isWeb) {
|
|
@@ -738,26 +710,10 @@ function createComponent(configIn, ParentComponent) {
|
|
|
738
710
|
}
|
|
739
711
|
}
|
|
740
712
|
}
|
|
741
|
-
|
|
742
|
-
tamaguiDefaultProps = defaults;
|
|
743
|
-
}
|
|
713
|
+
tamaguiDefaultProps = defaults;
|
|
744
714
|
if (process.env.NODE_ENV === "development" && debug) {
|
|
745
715
|
if (process.env.IS_STATIC !== "is_static") {
|
|
746
|
-
console.log(`\u{1F41B} [${staticConfig.componentName || "Component"}]`, {
|
|
747
|
-
staticConfig,
|
|
748
|
-
initialSplitStyles,
|
|
749
|
-
tamaguiDefaultProps,
|
|
750
|
-
defaultNativeStyle,
|
|
751
|
-
defaults,
|
|
752
|
-
defaultPropsIn,
|
|
753
|
-
defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps),
|
|
754
|
-
defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [k, defaultPropsIn[k]]),
|
|
755
|
-
ourProps,
|
|
756
|
-
ourClassNames,
|
|
757
|
-
defaultsClassnames,
|
|
758
|
-
defaultTag,
|
|
759
|
-
noClassNames
|
|
760
|
-
});
|
|
716
|
+
console.log(`\u{1F41B} [${staticConfig.componentName || "Component"}]`, { staticConfig, tamaguiDefaultProps, defaultNativeStyle, defaults, defaultPropsIn, defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps), defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [k, defaultPropsIn[k]]), ourProps, ourClassNames, defaultsClassnames, defaultTag, noClassNames });
|
|
761
717
|
}
|
|
762
718
|
}
|
|
763
719
|
});
|
|
@@ -862,12 +818,10 @@ function spacedChildren({
|
|
|
862
818
|
}, index)
|
|
863
819
|
);
|
|
864
820
|
}
|
|
865
|
-
if (isUnspaced(child) && index === 0)
|
|
821
|
+
if (isUnspaced(child) && index === 0)
|
|
866
822
|
continue;
|
|
867
|
-
|
|
868
|
-
if (isZStack) {
|
|
823
|
+
if (isZStack)
|
|
869
824
|
continue;
|
|
870
|
-
}
|
|
871
825
|
const next = childrenList[index + 1];
|
|
872
826
|
if (next && !isUnspaced(next)) {
|
|
873
827
|
if (separator) {
|