@tamagui/core 1.0.1-beta.216 → 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 +37 -86
- 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/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 +39 -92
- 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/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 +50 -109
- package/src/createTamagui.ts +2 -2
- 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
|
@@ -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,MAAM,yCAAyC,KAAK;AAAA,MAChE;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF;AACF,IACC,CAAC;AAIR,MAAM,YAAmD,CAAC;AAEnD,SAAS,sBAAsB,KAAoB,IAAmB;AAC3E,MAAI,QAAQ,IAAI,aAAa,iBAAiB,IAAI,OAAO,KAAK;AAE5D,YAAQ,KAAK,kEAAkE;AAAA,EACjF;AACA,YAAU,OAAO,UAAU,QAAQ,oBAAI,IAAI;AAC3C,YAAU,KAAK,IAAI,EAAE;AACrB,SAAO,MAAM,yBAAyB,KAAK,EAAE;AAC/C;AAEO,SAAS,yBAAyB,KAAoB,IAAmB;AAlDhF;AAmDE,kBAAU,SAAV,mBAAgB,OAAO;AACzB;AAEO,MAAM,mBAAiC,CAAC;AAExC,MAAM,WAAW,MAAM;AAG9B,IAAI;AACG,MAAM,uBAAuB,MAAM;AACxC,cAAQ,yBAAU,EAAE,aAAa,aAAa,cAAc,CAAC;AAC/D;AAEA,IAAI;AACG,MAAM,wBAAwB,CAAC,QAEpC,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O,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,16 +26,11 @@ 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";
|
|
37
33
|
import { proxyThemeVariables } from "./helpers/proxyThemeVariables";
|
|
38
|
-
import { pseudoDescriptors } from "./helpers/pseudoDescriptors";
|
|
39
34
|
import { useShallowSetState } from "./helpers/useShallowSetState";
|
|
40
35
|
import { getRect, measureLayout, useElementLayout } from "./hooks/useElementLayout";
|
|
41
36
|
import { addMediaQueryListener, getInitialMediaState } from "./hooks/useMedia";
|
|
@@ -88,7 +83,6 @@ function createComponent(configIn, ParentComponent) {
|
|
|
88
83
|
let defaultNativeStyle;
|
|
89
84
|
let tamaguiDefaultProps;
|
|
90
85
|
let defaultTag;
|
|
91
|
-
let initialSplitStyles;
|
|
92
86
|
const component = forwardRef((propsIn, forwardedRef) => {
|
|
93
87
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
94
88
|
let props;
|
|
@@ -122,13 +116,19 @@ function createComponent(configIn, ParentComponent) {
|
|
|
122
116
|
staticConfig.isReactNative || isAnimated && tamaguiConfig.animations.isReactNative
|
|
123
117
|
);
|
|
124
118
|
if (process.env.NODE_ENV === "development") {
|
|
125
|
-
if (
|
|
119
|
+
if (debugProp) {
|
|
126
120
|
const name = `${componentName || (Component == null ? void 0 : Component.displayName) || (Component == null ? void 0 : Component.name) || "[Unnamed Component]"}`;
|
|
127
121
|
const type = isReactNative ? "(rnw)" : "";
|
|
128
122
|
const dataIs = propsIn["data-is"] || "";
|
|
129
123
|
const banner = `${name}${dataIs ? ` ${dataIs}` : ""} ${type}`;
|
|
130
124
|
console.group(`%c ${banner}`, "background: yellow;");
|
|
131
|
-
|
|
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
|
+
}
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
const forceUpdate = useForceUpdate();
|
|
@@ -157,19 +157,18 @@ function createComponent(configIn, ParentComponent) {
|
|
|
157
157
|
let elementType = isText ? (isAnimated ? AnimatedText : null) || BaseTextComponent : (isAnimated ? AnimatedView : null) || BaseViewComponent;
|
|
158
158
|
elementType = Component || elementType;
|
|
159
159
|
const isStringElement = typeof elementType === "string";
|
|
160
|
-
const splitStyleState = {
|
|
161
|
-
...state,
|
|
162
|
-
noClassNames,
|
|
163
|
-
dynamicStylesInline: noClassNames,
|
|
164
|
-
hasTextAncestor,
|
|
165
|
-
resolveVariablesAs: "value"
|
|
166
|
-
};
|
|
167
160
|
const splitStyles = useSplitStyles(
|
|
168
161
|
props,
|
|
169
162
|
staticConfig,
|
|
170
163
|
theme,
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
{
|
|
165
|
+
...state,
|
|
166
|
+
noClassNames,
|
|
167
|
+
dynamicStylesInline: noClassNames,
|
|
168
|
+
hasTextAncestor,
|
|
169
|
+
resolveVariablesAs: "value"
|
|
170
|
+
},
|
|
171
|
+
null,
|
|
173
172
|
languageContext || void 0,
|
|
174
173
|
elementType,
|
|
175
174
|
debugProp
|
|
@@ -412,11 +411,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
412
411
|
styles = [isWeb ? null : defaultNativeStyle, animationStyles ?? splitStylesStyle, medias];
|
|
413
412
|
if (shouldForcePseudo) {
|
|
414
413
|
const next = {};
|
|
415
|
-
|
|
416
|
-
if (style) {
|
|
417
|
-
Object.assign(next, style);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
414
|
+
styles.forEach((style) => Object.assign(next, style));
|
|
420
415
|
Object.assign(splitStyles.style, next);
|
|
421
416
|
}
|
|
422
417
|
}
|
|
@@ -482,15 +477,13 @@ function createComponent(configIn, ParentComponent) {
|
|
|
482
477
|
}
|
|
483
478
|
viewProps.style = styles;
|
|
484
479
|
}
|
|
485
|
-
const
|
|
486
|
-
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);
|
|
487
481
|
const attachPress = !!(runtimePressStyle || onPress || onPressOut || onPressIn || onClick);
|
|
488
|
-
const
|
|
489
|
-
const
|
|
490
|
-
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);
|
|
491
484
|
const handlesPressEvents = !isWeb && !asChild;
|
|
492
485
|
const shouldAttach = asChild ? false : Boolean(
|
|
493
|
-
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)
|
|
494
487
|
);
|
|
495
488
|
const events = shouldAttach && !isRSC && !isDisabled ? {
|
|
496
489
|
onPressOut: attachPress ? (e) => {
|
|
@@ -498,25 +491,25 @@ function createComponent(configIn, ParentComponent) {
|
|
|
498
491
|
onPressOut == null ? void 0 : onPressOut(e);
|
|
499
492
|
onMouseUp == null ? void 0 : onMouseUp(e);
|
|
500
493
|
} : void 0,
|
|
501
|
-
...
|
|
502
|
-
onMouseEnter:
|
|
494
|
+
...isHoverable && {
|
|
495
|
+
onMouseEnter: isHoverable ? (e) => {
|
|
503
496
|
const next = {};
|
|
504
|
-
if (
|
|
497
|
+
if (isHoverable) {
|
|
505
498
|
next.hover = true;
|
|
506
499
|
}
|
|
507
500
|
if (state.pressIn) {
|
|
508
501
|
next.press = true;
|
|
509
502
|
}
|
|
510
|
-
if (
|
|
503
|
+
if (isHoverable || state.pressIn) {
|
|
511
504
|
setStateShallow(next);
|
|
512
505
|
}
|
|
513
506
|
onHoverIn == null ? void 0 : onHoverIn(e);
|
|
514
507
|
onMouseEnter == null ? void 0 : onMouseEnter(e);
|
|
515
508
|
} : void 0,
|
|
516
|
-
onMouseLeave:
|
|
509
|
+
onMouseLeave: isHoverable ? (e) => {
|
|
517
510
|
const next = {};
|
|
518
511
|
mouseUps.add(unPress);
|
|
519
|
-
if (
|
|
512
|
+
if (isHoverable) {
|
|
520
513
|
next.hover = false;
|
|
521
514
|
}
|
|
522
515
|
if (state.pressIn) {
|
|
@@ -593,7 +586,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
593
586
|
};
|
|
594
587
|
}
|
|
595
588
|
if (process.env.TAMAGUI_TARGET === "native") {
|
|
596
|
-
const attachFocus = !!
|
|
589
|
+
const attachFocus = !!pseudos.focusStyle;
|
|
597
590
|
if (attachFocus) {
|
|
598
591
|
viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {
|
|
599
592
|
setStateShallow({ focus: true });
|
|
@@ -639,7 +632,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
639
632
|
console.log("children", content);
|
|
640
633
|
console.groupEnd();
|
|
641
634
|
if (typeof window !== "undefined") {
|
|
642
|
-
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 });
|
|
643
636
|
}
|
|
644
637
|
console.groupEnd();
|
|
645
638
|
}
|
|
@@ -693,38 +686,16 @@ function createComponent(configIn, ParentComponent) {
|
|
|
693
686
|
);
|
|
694
687
|
}
|
|
695
688
|
const debug = defaultPropsIn["debug"];
|
|
696
|
-
const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {}
|
|
689
|
+
const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {});
|
|
697
690
|
if (ourProps.tag) {
|
|
698
691
|
defaultTag = ourProps.tag;
|
|
699
692
|
}
|
|
700
693
|
const noClassNames = !staticConfig.acceptsClassName;
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
unmounted: false,
|
|
707
|
-
hover: false,
|
|
708
|
-
press: false,
|
|
709
|
-
pressIn: false,
|
|
710
|
-
focus: false,
|
|
711
|
-
resolveVariablesAs: "both",
|
|
712
|
-
noClassNames
|
|
713
|
-
},
|
|
714
|
-
void 0,
|
|
715
|
-
void 0,
|
|
716
|
-
debug
|
|
717
|
-
);
|
|
718
|
-
const [defaults, defaultsClassnames] = mergeProps(
|
|
719
|
-
component.defaultProps,
|
|
720
|
-
isWeb ? { ...initialSplitStyles.pseudos, ...initialSplitStyles.viewProps } : initialSplitStyles.viewProps,
|
|
721
|
-
true
|
|
722
|
-
);
|
|
723
|
-
initialSplitStyles.classNames = {
|
|
724
|
-
...defaultsClassnames,
|
|
725
|
-
...initialSplitStyles.classNames,
|
|
726
|
-
...ourClassNames
|
|
727
|
-
};
|
|
694
|
+
const { name, variants, defaultVariants, ...restProps } = ourProps;
|
|
695
|
+
const [defaults, defaultsClassnames] = mergeProps(component.defaultProps, {
|
|
696
|
+
...defaultVariants,
|
|
697
|
+
...restProps
|
|
698
|
+
});
|
|
728
699
|
defaultNativeStyle = {};
|
|
729
700
|
const validStyles2 = staticConfig.validStyles || stylePropsView;
|
|
730
701
|
if (!isWeb) {
|
|
@@ -739,34 +710,10 @@ function createComponent(configIn, ParentComponent) {
|
|
|
739
710
|
}
|
|
740
711
|
}
|
|
741
712
|
}
|
|
742
|
-
|
|
743
|
-
tamaguiDefaultProps = defaults;
|
|
744
|
-
if (!isWeb) {
|
|
745
|
-
Object.keys(pseudoDescriptors).forEach((k) => {
|
|
746
|
-
if (ourProps[k]) {
|
|
747
|
-
initialSplitStyles.pseudos[k] = null;
|
|
748
|
-
tamaguiDefaultProps[k] = ourProps[k];
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
713
|
+
tamaguiDefaultProps = defaults;
|
|
753
714
|
if (process.env.NODE_ENV === "development" && debug) {
|
|
754
715
|
if (process.env.IS_STATIC !== "is_static") {
|
|
755
|
-
console.log(`\u{1F41B} [${staticConfig.componentName || "Component"}]`, {
|
|
756
|
-
staticConfig,
|
|
757
|
-
initialSplitStyles,
|
|
758
|
-
tamaguiDefaultProps,
|
|
759
|
-
defaultNativeStyle,
|
|
760
|
-
defaults,
|
|
761
|
-
defaultPropsIn,
|
|
762
|
-
defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps),
|
|
763
|
-
defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [k, defaultPropsIn[k]]),
|
|
764
|
-
ourProps,
|
|
765
|
-
ourClassNames,
|
|
766
|
-
defaultsClassnames,
|
|
767
|
-
defaultTag,
|
|
768
|
-
noClassNames
|
|
769
|
-
});
|
|
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 });
|
|
770
717
|
}
|
|
771
718
|
}
|
|
772
719
|
});
|