@tamagui/core 1.0.0-alpha.45 → 1.0.0-alpha.46
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 +9 -6
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/addStylesUsingClassname.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +5 -3
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/esm/createComponent.js +10 -7
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/helpers/addStylesUsingClassname.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +6 -4
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/jsx/createComponent.js +10 -7
- package/dist/jsx/hooks/useTheme.js +6 -4
- package/package.json +2 -2
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/addStylesUsingClassname.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
|
@@ -117,7 +117,6 @@ function createComponent(configIn) {
|
|
|
117
117
|
let defaultsClassName = "";
|
|
118
118
|
let initialTheme;
|
|
119
119
|
const component = (0, import_react.forwardRef)((props, forwardedRef) => {
|
|
120
|
-
var _b;
|
|
121
120
|
const forceUpdate = (0, import_use_force_update.useForceUpdate)();
|
|
122
121
|
const features = (0, import_useFeatures.useFeatures)(props, { forceUpdate });
|
|
123
122
|
const theme = (0, import_useTheme.useTheme)();
|
|
@@ -250,7 +249,8 @@ function createComponent(configIn) {
|
|
|
250
249
|
internal.current.isMounted = false;
|
|
251
250
|
};
|
|
252
251
|
}, []);
|
|
253
|
-
const
|
|
252
|
+
const isInternalComponent = !Component || typeof Component === "string";
|
|
253
|
+
const element = import_platform.isWeb ? isInternalComponent ? tag || Component : Component : Component;
|
|
254
254
|
const ReactView = !import_platform.isWeb ? import_react_native.View : element || (hasTextAncestor ? "span" : "div");
|
|
255
255
|
const ReactText = !import_platform.isWeb ? import_react_native.Text : element || "span";
|
|
256
256
|
const ViewComponent = isText ? ReactText : ReactView;
|
|
@@ -395,7 +395,12 @@ function createComponent(configIn) {
|
|
|
395
395
|
const domProps = import_rnw.rnw.createDOMProps(viewProps);
|
|
396
396
|
const className = domProps.className && domProps.className !== viewProps.className ? `${domProps.className} ${viewProps.className}` : viewProps.className;
|
|
397
397
|
Object.assign(viewProps, domProps);
|
|
398
|
-
|
|
398
|
+
if (ViewComponent === import_react_native.TextInput) {
|
|
399
|
+
viewProps.dataSet = viewProps.dataSet || {};
|
|
400
|
+
Object.assign(viewProps.dataSet, { __className: className });
|
|
401
|
+
} else {
|
|
402
|
+
viewProps.className = className;
|
|
403
|
+
}
|
|
399
404
|
content = (0, import_react.createElement)(ViewComponent, viewProps, childEls);
|
|
400
405
|
} else {
|
|
401
406
|
content = (0, import_react.createElement)(ViewComponent, viewProps, childEls);
|
|
@@ -409,11 +414,9 @@ function createComponent(configIn) {
|
|
|
409
414
|
viewProps["debug"] = true;
|
|
410
415
|
console.log("\u{1F95A} props in:", props);
|
|
411
416
|
console.log("\u{1F95A} props out:", viewProps);
|
|
412
|
-
console.log((_b = props.onClick) == null ? void 0 : _b.toString());
|
|
413
417
|
console.log("\u{1F95A} etc:", { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn });
|
|
414
|
-
if (import_platform.isWeb)
|
|
418
|
+
if (import_platform.isWeb)
|
|
415
419
|
console.log("\u{1F95A} component info", { staticConfig, tamaguiConfig });
|
|
416
|
-
}
|
|
417
420
|
}
|
|
418
421
|
}
|
|
419
422
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, features, content);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createComponent.tsx"],
|
|
4
|
-
"sourcesContent": ["import { concatClassName, stylePropsView } from '@tamagui/helpers'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, View, ViewStyle } from 'react-native'\n\nimport { onConfiguredOnce } from './conf'\nimport { stackDefaultStyles } from './constants/constants'\nimport { isTouchDevice, isWeb } from './constants/platform'\nimport { rnw } from './constants/rnw'\nimport { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { getSplitStyles } from './helpers/getSplitStyles'\nimport { useFeatures } from './hooks/useFeatures'\nimport { usePressable } from './hooks/usePressable'\nimport { useTheme } from './hooks/useTheme'\nimport {\n SpaceTokens,\n StaticComponent,\n StaticConfig,\n StaticConfigParsed,\n TamaguiInternalConfig,\n} from './types'\nimport { TextAncestorContext } from './views/TextAncestorContext'\n\nexport const mouseUps = new Set<Function>()\n\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\ntype DefaultProps = {}\n\nconst defaultComponentState = {\n hover: false,\n press: false,\n pressIn: false,\n}\n\ntype ComponentState = typeof defaultComponentState\n\nfunction createShallowUpdate(setter: React.Dispatch<React.SetStateAction<ComponentState>>) {\n return (next: Partial<ComponentState>) => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return { ...prev, ...next }\n }\n }\n return prev\n })\n }\n}\n\nexport function createComponent<A extends Object = DefaultProps>(\n configIn: Partial<StaticConfig> | StaticConfigParsed\n) {\n let staticConfig: StaticConfigParsed\n if ('parsed' in configIn) {\n staticConfig = configIn\n } else {\n staticConfig = parseStaticConfig(configIn)\n }\n\n const { Component, validStyles, isText, isZStack } = staticConfig\n const validStyleProps = validStyles ?? stylePropsView\n\n // split out default styles vs props so we can assign it to component.defaultProps\n let defaultProps = null as any\n let tamaguiConfig: TamaguiInternalConfig\n\n // web uses className, native uses style\n let defaultNativeStyle: StyleSheet.NamedStyles<{ base: {} }> | null = null\n let defaultsClassName = ''\n let initialTheme: any\n\n // see onConfiguredOnce below which attaches a name then to this component\n\n const component = forwardRef<View, A>((props: any, forwardedRef) => {\n const forceUpdate = useForceUpdate()\n const features = useFeatures(props, { forceUpdate })\n const theme = useTheme()\n const [state, set_] = useState<ComponentState>(defaultComponentState)\n const set = createShallowUpdate(set_)\n\n // from react-native-web\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false\n const hostRef = useRef(null)\n\n const {\n viewProps: viewPropsIn,\n pseudos,\n style,\n classNames,\n } = getSplitStyles(props, staticConfig, theme)\n\n const {\n tag,\n hitSlop,\n children,\n pointerEvents,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n space,\n disabled,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\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 onMouseDown,\n onClick,\n\n accessible,\n accessibilityRole,\n\n // TODO feature load layout hook\n onLayout,\n ...viewProps\n } = viewPropsIn\n\n if (!isWeb) {\n if (accessible) viewProps.accessible = accessible\n if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole\n }\n\n if (isWeb) {\n // from react-native-web\n rnw.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 })\n }\n\n // hasEverHadEvents prevents repareting if you remove onPress or similar...\n const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useEffect(() => {\n internal.current!.isMounted = true\n return () => {\n mouseUps.delete(unPress)\n internal.current!.isMounted = false\n }\n }, [])\n\n // element\n const element = isWeb\n ? !Component || typeof Component === 'string'\n ? // default to tag, fallback to component (when both strings)\n tag || Component\n : Component\n : Component\n const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n const ReactText = !isWeb ? Text : element || 'span'\n const ViewComponent = isText ? ReactText : ReactView\n\n // styles\n const isHovering = !isTouchDevice && !disabled && pseudos && state.hover\n const isPressing = !disabled && pseudos && state.press\n\n const styles = [\n defaultNativeStyle ? defaultNativeStyle.base : null,\n // parity w react-native-web, only for text in text\n // TODO this should be able to be done w css to replicate after extraction:\n // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)\n // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,\n style,\n isHovering ? pseudos.hoverStyle || null : null,\n isPressing ? pseudos.pressStyle || null : null,\n ]\n\n if (isWeb) {\n const stylesClassNames = useStylesAsClassname(styles)\n const classList = isText\n ? [\n defaultsClassName,\n // hasTextAncestor === true && cssText.textHasAncestor,\n // TODO MOVE TO VARIANTS [number] [any]\n // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,\n classNames,\n stylesClassNames,\n props.className,\n ]\n : [defaultsClassName, props.className, classNames, stylesClassNames]\n\n // @ts-ignore we are optimizing using arguments\n const className = concatClassName(...classList)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.log('\uD83E\uDD5A className', { style, styles, classList, stylesClassNames, className })\n }\n }\n viewProps.className = className\n } else {\n viewProps.style = styles\n }\n\n if (pointerEvents) {\n viewProps.pointerEvents = pointerEvents\n }\n\n if (isWeb) {\n // from react-native-web\n const platformMethodsRef = rnw.usePlatformMethods(viewProps)\n const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)\n viewProps.ref = setRef\n if (props.href != null && hrefAttrs != null) {\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 } else {\n if (forwardedRef) {\n viewProps.ref = forwardedRef\n }\n }\n\n const attachPress = !!(\n (pseudos && pseudos.pressStyle) ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n const attachHover =\n isWeb &&\n !isTouchDevice &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n // while avoiding reparenting...\n // once proper reparenting is supported, we can remove this and use that...\n const shouldAttach =\n internal.current.hasEverHadEvents ||\n attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onClick' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props))\n\n // never remove events as we wrap in a div (for now, may be able to remove..)\n if (shouldAttach) {\n internal.current.hasEverHadEvents = true\n }\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n set({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n ...(!isWeb && {\n // non web\n onPressOut: (e) => {\n unPress()\n onPressOut?.(e)\n },\n }),\n ...(isWeb &&\n !isTouchDevice && {\n onMouseEnter:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n onMouseDown: attachPress\n ? (e) => {\n set({\n press: true,\n pressIn: true,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n }\n : (onPressIn as any),\n onClick: attachPress\n ? (e) => {\n // this caused issue with next.js passing href\n // e.preventDefault()\n onPress?.(e)\n onClick?.(e)\n unPress()\n onPressOut?.(e)\n }\n : (onPressOut as any),\n }\n : null\n\n if (events) {\n if (typeof ViewComponent !== 'string') {\n // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic\n const [pressProps] = usePressable({\n disabled,\n hitSlop,\n onPressIn: events.onMouseDown,\n onPressOut: events.onPressOut,\n onPress: events.onClick,\n })\n Object.assign(viewProps, pressProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n\n const childEls = spacedChildren({\n children,\n space,\n flexDirection: props.flexDirection || defaultProps?.flexDirection,\n isZStack: isZStack,\n })\n\n let content: any\n\n // replicate react-native-web's `createElement`\n if (isWeb && rnw) {\n const domProps = rnw.createDOMProps(viewProps)\n const className =\n domProps.className && domProps.className !== viewProps.className\n ? `${domProps.className} ${viewProps.className}`\n : viewProps.className\n Object.assign(viewProps, domProps)\n viewProps.className = className\n content = createElement(ViewComponent, viewProps, childEls)\n } else {\n content = createElement(ViewComponent, viewProps, childEls)\n }\n\n const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n if (shouldWrapTextAncestor) {\n // from react-native-web\n // @ts-ignore\n content = createElement(TextAncestorContext.Provider, { value: true }, content)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n viewProps['debug'] = true\n console.log('\uD83E\uDD5A props in:', props)\n console.log('\uD83E\uDD5A props out:', viewProps)\n console.log(props.onClick?.toString())\n // prettier-ignore\n console.log('\uD83E\uDD5A etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn })\n // only on browser because node expands it huge\n if (isWeb) {\n console.log('\uD83E\uDD5A component info', { staticConfig, tamaguiConfig })\n }\n }\n }\n\n return (\n <>\n {features}\n {content}\n </>\n )\n })\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n tamaguiConfig = conf\n initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]\n const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)\n if (isWeb) {\n if (next.classNames) {\n defaultsClassName += next.classNames + ' '\n }\n defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])\n } else {\n // native, create a default StyleSheet\n // TODO handle next.pseudos\n const sheetStyles = {}\n for (const style of next.style) {\n Object.assign(sheetStyles, style)\n }\n defaultNativeStyle = StyleSheet.create({\n base: sheetStyles,\n })\n }\n // @ts-ignore\n component.defaultProps = {\n ...next.viewProps,\n ...component.defaultProps,\n }\n if (process.env.NODE_ENV === 'development') {\n if (staticConfig.defaultProps?.debug) {\n console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)\n }\n }\n })\n\n component['staticConfig'] = {\n validStyles: validStyleProps,\n ...staticConfig,\n }\n\n const res = component as any as StaticComponent<A, void>\n\n // add extractable HoC\n res['extractable'] = (Component: any, conf?: StaticConfig) => {\n Component['staticConfig'] = extendStaticConfig(res, {\n ...conf,\n neverFlatten: true,\n defaultProps: {\n ...Component.defaultProps,\n ...conf?.defaultProps,\n },\n })\n return Component\n }\n\n return res\n}\n\nlet hasWarnedOnce = false\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n return {\n width: tokens.size[size] ?? size,\n height: tokens.size[size] ?? size,\n }\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n },\n vertical: {\n width: 0,\n },\n },\n },\n})\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n flexDirection,\n}: {\n isZStack?: boolean\n children: any\n space?: any\n flexDirection?: ViewStyle['flexDirection']\n}) {\n if (!space && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n const len = childrenList.length\n if (len === 1) {\n return children\n }\n const next: any[] = []\n for (const [index, child] of childrenList.entries()) {\n if (child === null || child === undefined) {\n continue\n }\n\n const key = `${child?.['key'] ?? index}`\n\n next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)\n\n // allows for custom visually hidden components that dont insert spacing\n if (child?.['type']?.['isVisuallyHidden']) {\n continue\n }\n\n if (index !== len - 1) {\n if (space) {\n next.push(\n <Spacer\n key={`${key}_spacer`}\n // @ts-ignore TODO\n direction={\n flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'\n }\n size={space}\n />\n )\n }\n }\n }\n return next\n}\n\n// for now not so \"tamagui-y\"\nconst Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>\nconst sheet = StyleSheet.create({\n fullscreen: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n})\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgD;AAChD,8BAA+B;AAC/B,mBAUO;AACP,
|
|
4
|
+
"sourcesContent": ["import { concatClassName, stylePropsView } from '@tamagui/helpers'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, TextInput, View, ViewStyle } from 'react-native'\n\nimport { onConfiguredOnce } from './conf'\nimport { stackDefaultStyles } from './constants/constants'\nimport { isTouchDevice, isWeb } from './constants/platform'\nimport { rnw } from './constants/rnw'\nimport { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { getSplitStyles } from './helpers/getSplitStyles'\nimport { useFeatures } from './hooks/useFeatures'\nimport { usePressable } from './hooks/usePressable'\nimport { useTheme } from './hooks/useTheme'\nimport {\n SpaceTokens,\n StaticComponent,\n StaticConfig,\n StaticConfigParsed,\n TamaguiInternalConfig,\n} from './types'\nimport { TextAncestorContext } from './views/TextAncestorContext'\n\nexport const mouseUps = new Set<Function>()\n\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\ntype DefaultProps = {}\n\nconst defaultComponentState = {\n hover: false,\n press: false,\n pressIn: false,\n}\n\ntype ComponentState = typeof defaultComponentState\n\nfunction createShallowUpdate(setter: React.Dispatch<React.SetStateAction<ComponentState>>) {\n return (next: Partial<ComponentState>) => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return { ...prev, ...next }\n }\n }\n return prev\n })\n }\n}\n\nexport function createComponent<A extends Object = DefaultProps>(\n configIn: Partial<StaticConfig> | StaticConfigParsed\n) {\n let staticConfig: StaticConfigParsed\n if ('parsed' in configIn) {\n staticConfig = configIn\n } else {\n staticConfig = parseStaticConfig(configIn)\n }\n\n const { Component, validStyles, isText, isZStack } = staticConfig\n const validStyleProps = validStyles ?? stylePropsView\n\n // split out default styles vs props so we can assign it to component.defaultProps\n let defaultProps = null as any\n let tamaguiConfig: TamaguiInternalConfig\n\n // web uses className, native uses style\n let defaultNativeStyle: StyleSheet.NamedStyles<{ base: {} }> | null = null\n let defaultsClassName = ''\n let initialTheme: any\n\n // see onConfiguredOnce below which attaches a name then to this component\n\n const component = forwardRef<View, A>((props: any, forwardedRef) => {\n const forceUpdate = useForceUpdate()\n const features = useFeatures(props, { forceUpdate })\n const theme = useTheme()\n const [state, set_] = useState<ComponentState>(defaultComponentState)\n const set = createShallowUpdate(set_)\n\n // from react-native-web\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false\n const hostRef = useRef(null)\n\n const {\n viewProps: viewPropsIn,\n pseudos,\n style,\n classNames,\n } = getSplitStyles(props, staticConfig, theme)\n\n const {\n tag,\n hitSlop,\n children,\n pointerEvents,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n space,\n disabled,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\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 onMouseDown,\n onClick,\n\n accessible,\n accessibilityRole,\n\n // TODO feature load layout hook\n onLayout,\n ...viewProps\n } = viewPropsIn\n\n if (!isWeb) {\n if (accessible) viewProps.accessible = accessible\n if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole\n }\n\n if (isWeb) {\n // from react-native-web\n rnw.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 })\n }\n\n // hasEverHadEvents prevents repareting if you remove onPress or similar...\n const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useEffect(() => {\n internal.current!.isMounted = true\n return () => {\n mouseUps.delete(unPress)\n internal.current!.isMounted = false\n }\n }, [])\n\n // element\n const isInternalComponent = !Component || typeof Component === 'string'\n // default to tag, fallback to component (when both strings)\n const element = isWeb ? (isInternalComponent ? tag || Component : Component) : Component\n const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n const ReactText = !isWeb ? Text : element || 'span'\n const ViewComponent = isText ? ReactText : ReactView\n\n // styles\n const isHovering = !isTouchDevice && !disabled && pseudos && state.hover\n const isPressing = !disabled && pseudos && state.press\n\n const styles = [\n defaultNativeStyle ? defaultNativeStyle.base : null,\n // parity w react-native-web, only for text in text\n // TODO this should be able to be done w css to replicate after extraction:\n // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)\n // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,\n style,\n isHovering ? pseudos.hoverStyle || null : null,\n isPressing ? pseudos.pressStyle || null : null,\n ]\n\n if (isWeb) {\n const stylesClassNames = useStylesAsClassname(styles)\n const classList = isText\n ? [\n defaultsClassName,\n // hasTextAncestor === true && cssText.textHasAncestor,\n // TODO MOVE TO VARIANTS [number] [any]\n // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,\n classNames,\n stylesClassNames,\n props.className,\n ]\n : [defaultsClassName, props.className, classNames, stylesClassNames]\n\n // @ts-ignore we are optimizing using arguments\n const className = concatClassName(...classList)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.log('\uD83E\uDD5A className', { style, styles, classList, stylesClassNames, className })\n }\n }\n viewProps.className = className\n } else {\n viewProps.style = styles\n }\n\n if (pointerEvents) {\n viewProps.pointerEvents = pointerEvents\n }\n\n if (isWeb) {\n // from react-native-web\n const platformMethodsRef = rnw.usePlatformMethods(viewProps)\n const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)\n viewProps.ref = setRef\n if (props.href != null && hrefAttrs != null) {\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 } else {\n if (forwardedRef) {\n viewProps.ref = forwardedRef\n }\n }\n\n const attachPress = !!(\n (pseudos && pseudos.pressStyle) ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n const attachHover =\n isWeb &&\n !isTouchDevice &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n // while avoiding reparenting...\n // once proper reparenting is supported, we can remove this and use that...\n const shouldAttach =\n internal.current.hasEverHadEvents ||\n attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onClick' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props))\n\n // never remove events as we wrap in a div (for now, may be able to remove..)\n if (shouldAttach) {\n internal.current.hasEverHadEvents = true\n }\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n set({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n ...(!isWeb && {\n // non web\n onPressOut: (e) => {\n unPress()\n onPressOut?.(e)\n },\n }),\n ...(isWeb &&\n !isTouchDevice && {\n onMouseEnter:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n onMouseDown: attachPress\n ? (e) => {\n set({\n press: true,\n pressIn: true,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n }\n : (onPressIn as any),\n onClick: attachPress\n ? (e) => {\n // this caused issue with next.js passing href\n // e.preventDefault()\n onPress?.(e)\n onClick?.(e)\n unPress()\n onPressOut?.(e)\n }\n : (onPressOut as any),\n }\n : null\n\n if (events) {\n if (typeof ViewComponent !== 'string') {\n // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic\n const [pressProps] = usePressable({\n disabled,\n hitSlop,\n onPressIn: events.onMouseDown,\n onPressOut: events.onPressOut,\n onPress: events.onClick,\n })\n Object.assign(viewProps, pressProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n\n const childEls = spacedChildren({\n children,\n space,\n flexDirection: props.flexDirection || defaultProps?.flexDirection,\n isZStack: isZStack,\n })\n\n let content: any\n\n // replicate react-native-web's `createElement`\n if (isWeb && rnw) {\n const domProps = rnw.createDOMProps(viewProps)\n const className =\n domProps.className && domProps.className !== viewProps.className\n ? `${domProps.className} ${viewProps.className}`\n : viewProps.className\n Object.assign(viewProps, domProps)\n\n // hacky workaround to pass classnames until we get stylex\n if (ViewComponent === TextInput) {\n viewProps.dataSet = viewProps.dataSet || {}\n Object.assign(viewProps.dataSet, { __className: className })\n } else {\n // we already handle Text/View properly\n viewProps.className = className\n }\n\n content = createElement(ViewComponent, viewProps, childEls)\n } else {\n content = createElement(ViewComponent, viewProps, childEls)\n }\n\n const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n if (shouldWrapTextAncestor) {\n // from react-native-web\n content = createElement(TextAncestorContext.Provider, { value: true }, content)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n viewProps['debug'] = true\n console.log('\uD83E\uDD5A props in:', props)\n console.log('\uD83E\uDD5A props out:', viewProps)\n // prettier-ignore\n console.log('\uD83E\uDD5A etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn })\n // only on browser because node expands it huge\n if (isWeb) console.log('\uD83E\uDD5A component info', { staticConfig, tamaguiConfig })\n }\n }\n\n return (\n <>\n {features}\n {content}\n </>\n )\n })\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n tamaguiConfig = conf\n initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]\n const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)\n if (isWeb) {\n if (next.classNames) {\n defaultsClassName += next.classNames + ' '\n }\n defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])\n } else {\n // native, create a default StyleSheet\n // TODO handle next.pseudos\n const sheetStyles = {}\n for (const style of next.style) {\n Object.assign(sheetStyles, style)\n }\n defaultNativeStyle = StyleSheet.create({\n base: sheetStyles,\n })\n }\n // @ts-ignore\n component.defaultProps = {\n ...next.viewProps,\n ...component.defaultProps,\n }\n if (process.env.NODE_ENV === 'development') {\n if (staticConfig.defaultProps?.debug) {\n console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)\n }\n }\n })\n\n component['staticConfig'] = {\n validStyles: validStyleProps,\n ...staticConfig,\n }\n\n const res = component as any as StaticComponent<A, void>\n\n // add extractable HoC\n res['extractable'] = (Component: any, conf?: StaticConfig) => {\n Component['staticConfig'] = extendStaticConfig(res, {\n ...conf,\n neverFlatten: true,\n defaultProps: {\n ...Component.defaultProps,\n ...conf?.defaultProps,\n },\n })\n return Component\n }\n\n return res\n}\n\nlet hasWarnedOnce = false\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n return {\n width: tokens.size[size] ?? size,\n height: tokens.size[size] ?? size,\n }\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n },\n vertical: {\n width: 0,\n },\n },\n },\n})\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n flexDirection,\n}: {\n isZStack?: boolean\n children: any\n space?: any\n flexDirection?: ViewStyle['flexDirection']\n}) {\n if (!space && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n const len = childrenList.length\n if (len === 1) {\n return children\n }\n const next: any[] = []\n for (const [index, child] of childrenList.entries()) {\n if (child === null || child === undefined) {\n continue\n }\n\n const key = `${child?.['key'] ?? index}`\n\n next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)\n\n // allows for custom visually hidden components that dont insert spacing\n if (child?.['type']?.['isVisuallyHidden']) {\n continue\n }\n\n if (index !== len - 1) {\n if (space) {\n next.push(\n <Spacer\n key={`${key}_spacer`}\n // @ts-ignore TODO\n direction={\n flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'\n }\n size={space}\n />\n )\n }\n }\n }\n return next\n}\n\n// for now not so \"tamagui-y\"\nconst Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>\nconst sheet = StyleSheet.create({\n fullscreen: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n})\n"],
|
|
5
|
+
"mappings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,UAAM,MAAM,GAAG,gCAAQ,WAAU;AAEjC,SAAK,KAAK,mDAAC,uBAAD;AAAA,MAAU;AAAA,OAAW,WAAW,mDAAC,UAAD,MAAW,SAAoB;AAGzE,QAAI,qCAAQ,YAAR,mBAAkB,qBAAqB;AACzC;AAAA;AAGF,QAAI,UAAU,MAAM,GAAG;AACrB,UAAI,OAAO;AACT,aAAK,KACH,mDAAC,QAAD;AAAA,UACE,KAAK,GAAG;AAAA,UAER,WACE,kBAAkB,SAAS,kBAAkB,gBAAgB,eAAe;AAAA,UAE9E,MAAM;AAAA;AAAA;AAAA;AAAA;AAMhB,SAAO;AAAA;AAjDO;AAqDhB,MAAM,WAAW,wBAAC,EAAE,eAAe,mDAAC,0BAAD;AAAA,EAAM,OAAO,MAAM;AAAA,GAAa,WAAlD;AACjB,MAAM,QAAQ,+BAAW,OAAO;AAAA,EAC9B,YAAY;AAAA,IACV,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/addStylesUsingClassname.tsx"],
|
|
4
|
-
"sourcesContent": ["// @ts-ignore\nimport { useInsertionEffect } from 'react'\n\nimport { getStylesAtomic } from './getStylesAtomic'\nimport { insertStyleRule } from './insertStyleRule'\n\n// uses new useInsertionEffect for better perf if available\n\n// could be cleared occasionally\nlet added = new Set<string>()\n\nexport function useStylesAsClassname(styles: any[]) {\n if (!useInsertionEffect) {\n return addStylesUsingClassname(styles)\n } else {\n const insertions: any[] = []\n const className = addStylesUsingClassname(styles, (_, rules) => {\n for (const rule of rules) {\n insertions.push(rule)\n }\n })\n\n useInsertionEffect(() => {\n for (const ruleset of insertions) {\n insertStyleRule(ruleset)\n }\n })\n\n return className\n }\n}\n\nexport function addStylesUsingClassname(\n styles: any[],\n onAdd?: (identifier: string, rules: string[]) => any\n) {\n let className = ''\n for (const style of styles) {\n if (!style) continue\n if (Array.isArray(style)) {\n className += ' ' + addStylesUsingClassname(style)\n continue\n }\n for (const { identifier, rules } of getStylesAtomic(style)) {\n className += ` ${identifier}`\n if (added.has(identifier)) {\n continue\n }\n added.add(identifier)\n if (onAdd) {\n onAdd(identifier, rules)\n } else {\n for (const rule of rules) {\n insertStyleRule(rule)\n }\n }\n }\n }\n return className\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmC;AAEnC,6BAAgC;AAChC,6BAAgC;
|
|
4
|
+
"sourcesContent": ["// @ts-ignore\nimport { useInsertionEffect } from 'react'\n\nimport { getStylesAtomic } from './getStylesAtomic'\nimport { insertStyleRule } from './insertStyleRule'\n\n// TODO can drop most of this code once we drop support for 17\n// uses new useInsertionEffect for better perf if available\n\n// could be cleared occasionally\nlet added = new Set<string>()\n\nexport function useStylesAsClassname(styles: any[]) {\n if (!useInsertionEffect) {\n return addStylesUsingClassname(styles)\n } else {\n const insertions: any[] = []\n const className = addStylesUsingClassname(styles, (_, rules) => {\n for (const rule of rules) {\n insertions.push(rule)\n }\n })\n\n useInsertionEffect(() => {\n for (const ruleset of insertions) {\n insertStyleRule(ruleset)\n }\n })\n\n return className\n }\n}\n\nexport function addStylesUsingClassname(\n styles: any[],\n onAdd?: (identifier: string, rules: string[]) => any\n) {\n let className = ''\n for (const style of styles) {\n if (!style) continue\n if (Array.isArray(style)) {\n className += ' ' + addStylesUsingClassname(style)\n continue\n }\n for (const { identifier, rules } of getStylesAtomic(style)) {\n className += ` ${identifier}`\n if (added.has(identifier)) {\n continue\n }\n added.add(identifier)\n if (onAdd) {\n onAdd(identifier, rules)\n } else {\n for (const rule of rules) {\n insertStyleRule(rule)\n }\n }\n }\n }\n return className\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmC;AAEnC,6BAAgC;AAChC,6BAAgC;AAMhC,IAAI,QAAQ,oBAAI;AAET,8BAA8B,QAAe;AAClD,MAAI,CAAC,iCAAoB;AACvB,WAAO,wBAAwB;AAAA,SAC1B;AACL,UAAM,aAAoB;AAC1B,UAAM,YAAY,wBAAwB,QAAQ,CAAC,GAAG,UAAU;AAC9D,iBAAW,QAAQ,OAAO;AACxB,mBAAW,KAAK;AAAA;AAAA;AAIpB,yCAAmB,MAAM;AACvB,iBAAW,WAAW,YAAY;AAChC,oDAAgB;AAAA;AAAA;AAIpB,WAAO;AAAA;AAAA;AAjBK;AAqBT,iCACL,QACA,OACA;AACA,MAAI,YAAY;AAChB,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC;AAAO;AACZ,QAAI,MAAM,QAAQ,QAAQ;AACxB,mBAAa,MAAM,wBAAwB;AAC3C;AAAA;AAEF,eAAW,EAAE,YAAY,WAAW,4CAAgB,QAAQ;AAC1D,mBAAa,IAAI;AACjB,UAAI,MAAM,IAAI,aAAa;AACzB;AAAA;AAEF,YAAM,IAAI;AACV,UAAI,OAAO;AACT,cAAM,YAAY;AAAA,aACb;AACL,mBAAW,QAAQ,OAAO;AACxB,sDAAgB;AAAA;AAAA;AAAA;AAAA;AAKxB,SAAO;AAAA;AA1BO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -60,7 +60,7 @@ const useDefaultThemeName = /* @__PURE__ */ __name(() => {
|
|
|
60
60
|
const useTheme = /* @__PURE__ */ __name(() => {
|
|
61
61
|
const forceUpdate = (0, import_use_force_update.useForceUpdate)();
|
|
62
62
|
const manager = (0, import_react.useContext)(import_ThemeManagerContext.ThemeManagerContext);
|
|
63
|
-
const themes = (0, import_react.useContext)(import_ThemeContext.ThemeContext);
|
|
63
|
+
const themes = (0, import_react.useContext)(import_ThemeContext.ThemeContext) || {};
|
|
64
64
|
const state = (0, import_react.useRef)();
|
|
65
65
|
if (!state.current) {
|
|
66
66
|
state.current = {
|
|
@@ -81,7 +81,7 @@ const useTheme = /* @__PURE__ */ __name(() => {
|
|
|
81
81
|
(0, import_react.useEffect)(() => {
|
|
82
82
|
return manager.onUpdate(state.current.uuid, forceUpdate);
|
|
83
83
|
}, []);
|
|
84
|
-
const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light;
|
|
84
|
+
const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light ?? {};
|
|
85
85
|
return (0, import_react.useMemo)(() => {
|
|
86
86
|
return new Proxy(theme, {
|
|
87
87
|
get(_, key) {
|
|
@@ -91,7 +91,9 @@ const useTheme = /* @__PURE__ */ __name(() => {
|
|
|
91
91
|
}
|
|
92
92
|
let activeTheme = themes[name];
|
|
93
93
|
if (!activeTheme) {
|
|
94
|
-
|
|
94
|
+
if (process.env.NODE_ENV !== "test") {
|
|
95
|
+
console.error("No theme by name", name, "only:", themes, "keeping current theme");
|
|
96
|
+
}
|
|
95
97
|
activeTheme = theme;
|
|
96
98
|
}
|
|
97
99
|
const val = activeTheme[key];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { GET_DEFAULT_THEME } from '../constants/constants'\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { Variable } from '../createVariable'\nimport { ThemeName, ThemeObject } from '../types'\nimport { ThemeContext } from '../views/ThemeContext'\nimport { ThemeManagerContext } from '../views/ThemeManagerContext'\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nconst areEqualSets = (a: Set<string>, b: Set<string>) => {\n if (a.size !== b.size) return false\n for (const val in a) {\n if (!b.has(val)) {\n return false\n }\n }\n return true\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent.name)\n\n useIsomorphicLayoutEffect(() => {\n return parent.onChangeTheme((next, manager) => {\n setName(opts?.parent ? manager.parentName : next)\n })\n }, [parent])\n\n return name || 'light'\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)[GET_DEFAULT_THEME] as any as ThemeName\n}\n\nexport const useTheme = (): ThemeObject => {\n const forceUpdate = useForceUpdate()\n const manager = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext)\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = manager.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n manager.track(st.uuid, st.keys)\n }\n })\n\n useEffect(() => {\n return manager.onUpdate(state.current.uuid, forceUpdate)\n }, [])\n\n const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light\n\n return useMemo(\n () => {\n return new Proxy(theme, {\n get(_, key: string) {\n const name = manager.name\n if (!name) {\n return Reflect.get(_, key)\n }\n let activeTheme = themes[name]\n if (!activeTheme) {\n console.error('No theme by name', name, 'only:', themes, 'keeping current theme')\n activeTheme = theme\n }\n const val = activeTheme[key]\n if (process.env.NODE_ENV === 'development') {\n if (typeof val === 'undefined') {\n console.warn(`No theme value \"${String(key)}\" in`, activeTheme, themes)\n return null\n }\n if (!(val instanceof Variable)) {\n console.warn('Non variable!', val)\n }\n if (val.name !== key) {\n console.warn('Non-matching name for variable to key', key, val.name)\n }\n }\n if (state.current.isRendering) {\n state.current.keys.add(key)\n }\n return val\n },\n })\n },\n [\n /* if concurrent mode wanted put manager.name here */\n ]\n )\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA+B;AAC/B,mBAAwE;AAExE,uBAAkC;AAClC,sBAA0C;AAC1C,4BAAyB;AAEzB,0BAA6B;AAC7B,iCAAoC;AAQpC,MAAM,eAAe,wBAAC,GAAgB,MAAmB;AACvD,MAAI,EAAE,SAAS,EAAE;AAAM,WAAO;AAC9B,aAAW,OAAO,GAAG;AACnB,QAAI,CAAC,EAAE,IAAI,MAAM;AACf,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA,GAPY;AAUd,MAAM,eAAe,wBAAC,SAA6B;AACxD,QAAM,SAAS,6BAAW;AAC1B,QAAM,CAAC,MAAM,WAAW,2BAAS,OAAO;AAExC,iDAA0B,MAAM;AAC9B,WAAO,OAAO,cAAc,CAAC,MAAM,YAAY;AAC7C,cAAQ,8BAAM,UAAS,QAAQ,aAAa;AAAA;AAAA,KAE7C,CAAC;AAEJ,SAAO,QAAQ;AAAA,GAVW;AAarB,MAAM,sBAAsB,6BAAM;AACvC,SAAO,6BAAW,kCAAc;AAAA,GADC;AAI5B,MAAM,WAAW,6BAAmB;AACzC,QAAM,cAAc;AACpB,QAAM,UAAU,6BAAW;AAC3B,QAAM,SAAS,6BAAW;
|
|
4
|
+
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { GET_DEFAULT_THEME } from '../constants/constants'\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { Variable } from '../createVariable'\nimport { ThemeName, ThemeObject } from '../types'\nimport { ThemeContext } from '../views/ThemeContext'\nimport { ThemeManagerContext } from '../views/ThemeManagerContext'\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nconst areEqualSets = (a: Set<string>, b: Set<string>) => {\n if (a.size !== b.size) return false\n for (const val in a) {\n if (!b.has(val)) {\n return false\n }\n }\n return true\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent.name)\n\n useIsomorphicLayoutEffect(() => {\n return parent.onChangeTheme((next, manager) => {\n setName(opts?.parent ? manager.parentName : next)\n })\n }, [parent])\n\n return name || 'light'\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)[GET_DEFAULT_THEME] as any as ThemeName\n}\n\nexport const useTheme = (): ThemeObject => {\n const forceUpdate = useForceUpdate()\n const manager = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext) || {}\n\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = manager.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n manager.track(st.uuid, st.keys)\n }\n })\n\n useEffect(() => {\n return manager.onUpdate(state.current.uuid, forceUpdate)\n }, [])\n\n const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light ?? {}\n\n return useMemo(\n () => {\n return new Proxy(theme, {\n get(_, key: string) {\n const name = manager.name\n if (!name) {\n return Reflect.get(_, key)\n }\n let activeTheme = themes[name]\n if (!activeTheme) {\n if (process.env.NODE_ENV !== 'test') {\n console.error('No theme by name', name, 'only:', themes, 'keeping current theme')\n }\n activeTheme = theme\n }\n const val = activeTheme[key]\n if (process.env.NODE_ENV === 'development') {\n if (typeof val === 'undefined') {\n console.warn(`No theme value \"${String(key)}\" in`, activeTheme, themes)\n return null\n }\n if (!(val instanceof Variable)) {\n console.warn('Non variable!', val)\n }\n if (val.name !== key) {\n console.warn('Non-matching name for variable to key', key, val.name)\n }\n }\n if (state.current.isRendering) {\n state.current.keys.add(key)\n }\n return val\n },\n })\n },\n [\n /* if concurrent mode wanted put manager.name here */\n ]\n )\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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,OAAO,UAAU,OAAO,SAAS;AAEtF,SAAO,0BACL,MAAM;AACJ,WAAO,IAAI,MAAM,OAAO;AAAA,MACtB,IAAI,GAAG,KAAa;AAClB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,MAAM;AACT,iBAAO,QAAQ,IAAI,GAAG;AAAA;AAExB,YAAI,cAAc,OAAO;AACzB,YAAI,CAAC,aAAa;AAChB,cAAI,QAAQ,IAAI,aAAa,QAAQ;AACnC,oBAAQ,MAAM,oBAAoB,MAAM,SAAS,QAAQ;AAAA;AAE3D,wBAAc;AAAA;AAEhB,cAAM,MAAM,YAAY;AACxB,YAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAI,OAAO,QAAQ,aAAa;AAC9B,oBAAQ,KAAK,mBAAmB,OAAO,YAAY,aAAa;AAChE,mBAAO;AAAA;AAET,cAAI,CAAE,gBAAe,iCAAW;AAC9B,oBAAQ,KAAK,iBAAiB;AAAA;AAEhC,cAAI,IAAI,SAAS,KAAK;AACpB,oBAAQ,KAAK,yCAAyC,KAAK,IAAI;AAAA;AAAA;AAGnE,YAAI,MAAM,QAAQ,aAAa;AAC7B,gBAAM,QAAQ,KAAK,IAAI;AAAA;AAEzB,eAAO;AAAA;AAAA;AAAA,KAIb;AAAA,GAlEoB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ import React, {
|
|
|
13
13
|
useRef,
|
|
14
14
|
useState
|
|
15
15
|
} from "react";
|
|
16
|
-
import { StyleSheet, Text, View } from "react-native";
|
|
16
|
+
import { StyleSheet, Text, TextInput, View } from "react-native";
|
|
17
17
|
import { onConfiguredOnce } from "./conf";
|
|
18
18
|
import { stackDefaultStyles } from "./constants/constants";
|
|
19
19
|
import { isTouchDevice, isWeb } from "./constants/platform";
|
|
@@ -65,7 +65,6 @@ function createComponent(configIn) {
|
|
|
65
65
|
let defaultsClassName = "";
|
|
66
66
|
let initialTheme;
|
|
67
67
|
const component = forwardRef((props, forwardedRef) => {
|
|
68
|
-
var _a;
|
|
69
68
|
const forceUpdate = useForceUpdate();
|
|
70
69
|
const features = useFeatures(props, { forceUpdate });
|
|
71
70
|
const theme = useTheme();
|
|
@@ -163,7 +162,8 @@ function createComponent(configIn) {
|
|
|
163
162
|
internal.current.isMounted = false;
|
|
164
163
|
};
|
|
165
164
|
}, []);
|
|
166
|
-
const
|
|
165
|
+
const isInternalComponent = !Component || typeof Component === "string";
|
|
166
|
+
const element = isWeb ? isInternalComponent ? tag || Component : Component : Component;
|
|
167
167
|
const ReactView = !isWeb ? View : element || (hasTextAncestor ? "span" : "div");
|
|
168
168
|
const ReactText = !isWeb ? Text : element || "span";
|
|
169
169
|
const ViewComponent = isText ? ReactText : ReactView;
|
|
@@ -310,7 +310,12 @@ function createComponent(configIn) {
|
|
|
310
310
|
const domProps = rnw.createDOMProps(viewProps);
|
|
311
311
|
const className = domProps.className && domProps.className !== viewProps.className ? `${domProps.className} ${viewProps.className}` : viewProps.className;
|
|
312
312
|
Object.assign(viewProps, domProps);
|
|
313
|
-
|
|
313
|
+
if (ViewComponent === TextInput) {
|
|
314
|
+
viewProps.dataSet = viewProps.dataSet || {};
|
|
315
|
+
Object.assign(viewProps.dataSet, { __className: className });
|
|
316
|
+
} else {
|
|
317
|
+
viewProps.className = className;
|
|
318
|
+
}
|
|
314
319
|
content = createElement(ViewComponent, viewProps, childEls);
|
|
315
320
|
} else {
|
|
316
321
|
content = createElement(ViewComponent, viewProps, childEls);
|
|
@@ -324,11 +329,9 @@ function createComponent(configIn) {
|
|
|
324
329
|
viewProps["debug"] = true;
|
|
325
330
|
console.log("\u{1F95A} props in:", props);
|
|
326
331
|
console.log("\u{1F95A} props out:", viewProps);
|
|
327
|
-
console.log((_a = props.onClick) == null ? void 0 : _a.toString());
|
|
328
332
|
console.log("\u{1F95A} etc:", { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn });
|
|
329
|
-
if (isWeb)
|
|
333
|
+
if (isWeb)
|
|
330
334
|
console.log("\u{1F95A} component info", { staticConfig, tamaguiConfig });
|
|
331
|
-
}
|
|
332
335
|
}
|
|
333
336
|
}
|
|
334
337
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, features, content);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createComponent.tsx"],
|
|
4
|
-
"sourcesContent": ["import { concatClassName, stylePropsView } from '@tamagui/helpers'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, View, ViewStyle } from 'react-native'\n\nimport { onConfiguredOnce } from './conf'\nimport { stackDefaultStyles } from './constants/constants'\nimport { isTouchDevice, isWeb } from './constants/platform'\nimport { rnw } from './constants/rnw'\nimport { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { getSplitStyles } from './helpers/getSplitStyles'\nimport { useFeatures } from './hooks/useFeatures'\nimport { usePressable } from './hooks/usePressable'\nimport { useTheme } from './hooks/useTheme'\nimport {\n SpaceTokens,\n StaticComponent,\n StaticConfig,\n StaticConfigParsed,\n TamaguiInternalConfig,\n} from './types'\nimport { TextAncestorContext } from './views/TextAncestorContext'\n\nexport const mouseUps = new Set<Function>()\n\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\ntype DefaultProps = {}\n\nconst defaultComponentState = {\n hover: false,\n press: false,\n pressIn: false,\n}\n\ntype ComponentState = typeof defaultComponentState\n\nfunction createShallowUpdate(setter: React.Dispatch<React.SetStateAction<ComponentState>>) {\n return (next: Partial<ComponentState>) => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return { ...prev, ...next }\n }\n }\n return prev\n })\n }\n}\n\nexport function createComponent<A extends Object = DefaultProps>(\n configIn: Partial<StaticConfig> | StaticConfigParsed\n) {\n let staticConfig: StaticConfigParsed\n if ('parsed' in configIn) {\n staticConfig = configIn\n } else {\n staticConfig = parseStaticConfig(configIn)\n }\n\n const { Component, validStyles, isText, isZStack } = staticConfig\n const validStyleProps = validStyles ?? stylePropsView\n\n // split out default styles vs props so we can assign it to component.defaultProps\n let defaultProps = null as any\n let tamaguiConfig: TamaguiInternalConfig\n\n // web uses className, native uses style\n let defaultNativeStyle: StyleSheet.NamedStyles<{ base: {} }> | null = null\n let defaultsClassName = ''\n let initialTheme: any\n\n // see onConfiguredOnce below which attaches a name then to this component\n\n const component = forwardRef<View, A>((props: any, forwardedRef) => {\n const forceUpdate = useForceUpdate()\n const features = useFeatures(props, { forceUpdate })\n const theme = useTheme()\n const [state, set_] = useState<ComponentState>(defaultComponentState)\n const set = createShallowUpdate(set_)\n\n // from react-native-web\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false\n const hostRef = useRef(null)\n\n const {\n viewProps: viewPropsIn,\n pseudos,\n style,\n classNames,\n } = getSplitStyles(props, staticConfig, theme)\n\n const {\n tag,\n hitSlop,\n children,\n pointerEvents,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n space,\n disabled,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\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 onMouseDown,\n onClick,\n\n accessible,\n accessibilityRole,\n\n // TODO feature load layout hook\n onLayout,\n ...viewProps\n } = viewPropsIn\n\n if (!isWeb) {\n if (accessible) viewProps.accessible = accessible\n if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole\n }\n\n if (isWeb) {\n // from react-native-web\n rnw.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 })\n }\n\n // hasEverHadEvents prevents repareting if you remove onPress or similar...\n const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useEffect(() => {\n internal.current!.isMounted = true\n return () => {\n mouseUps.delete(unPress)\n internal.current!.isMounted = false\n }\n }, [])\n\n // element\n const element = isWeb\n ? !Component || typeof Component === 'string'\n ? // default to tag, fallback to component (when both strings)\n tag || Component\n : Component\n : Component\n const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n const ReactText = !isWeb ? Text : element || 'span'\n const ViewComponent = isText ? ReactText : ReactView\n\n // styles\n const isHovering = !isTouchDevice && !disabled && pseudos && state.hover\n const isPressing = !disabled && pseudos && state.press\n\n const styles = [\n defaultNativeStyle ? defaultNativeStyle.base : null,\n // parity w react-native-web, only for text in text\n // TODO this should be able to be done w css to replicate after extraction:\n // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)\n // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,\n style,\n isHovering ? pseudos.hoverStyle || null : null,\n isPressing ? pseudos.pressStyle || null : null,\n ]\n\n if (isWeb) {\n const stylesClassNames = useStylesAsClassname(styles)\n const classList = isText\n ? [\n defaultsClassName,\n // hasTextAncestor === true && cssText.textHasAncestor,\n // TODO MOVE TO VARIANTS [number] [any]\n // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,\n classNames,\n stylesClassNames,\n props.className,\n ]\n : [defaultsClassName, props.className, classNames, stylesClassNames]\n\n // @ts-ignore we are optimizing using arguments\n const className = concatClassName(...classList)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.log('\uD83E\uDD5A className', { style, styles, classList, stylesClassNames, className })\n }\n }\n viewProps.className = className\n } else {\n viewProps.style = styles\n }\n\n if (pointerEvents) {\n viewProps.pointerEvents = pointerEvents\n }\n\n if (isWeb) {\n // from react-native-web\n const platformMethodsRef = rnw.usePlatformMethods(viewProps)\n const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)\n viewProps.ref = setRef\n if (props.href != null && hrefAttrs != null) {\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 } else {\n if (forwardedRef) {\n viewProps.ref = forwardedRef\n }\n }\n\n const attachPress = !!(\n (pseudos && pseudos.pressStyle) ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n const attachHover =\n isWeb &&\n !isTouchDevice &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n // while avoiding reparenting...\n // once proper reparenting is supported, we can remove this and use that...\n const shouldAttach =\n internal.current.hasEverHadEvents ||\n attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onClick' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props))\n\n // never remove events as we wrap in a div (for now, may be able to remove..)\n if (shouldAttach) {\n internal.current.hasEverHadEvents = true\n }\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n set({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n ...(!isWeb && {\n // non web\n onPressOut: (e) => {\n unPress()\n onPressOut?.(e)\n },\n }),\n ...(isWeb &&\n !isTouchDevice && {\n onMouseEnter:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n onMouseDown: attachPress\n ? (e) => {\n set({\n press: true,\n pressIn: true,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n }\n : (onPressIn as any),\n onClick: attachPress\n ? (e) => {\n // this caused issue with next.js passing href\n // e.preventDefault()\n onPress?.(e)\n onClick?.(e)\n unPress()\n onPressOut?.(e)\n }\n : (onPressOut as any),\n }\n : null\n\n if (events) {\n if (typeof ViewComponent !== 'string') {\n // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic\n const [pressProps] = usePressable({\n disabled,\n hitSlop,\n onPressIn: events.onMouseDown,\n onPressOut: events.onPressOut,\n onPress: events.onClick,\n })\n Object.assign(viewProps, pressProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n\n const childEls = spacedChildren({\n children,\n space,\n flexDirection: props.flexDirection || defaultProps?.flexDirection,\n isZStack: isZStack,\n })\n\n let content: any\n\n // replicate react-native-web's `createElement`\n if (isWeb && rnw) {\n const domProps = rnw.createDOMProps(viewProps)\n const className =\n domProps.className && domProps.className !== viewProps.className\n ? `${domProps.className} ${viewProps.className}`\n : viewProps.className\n Object.assign(viewProps, domProps)\n viewProps.className = className\n content = createElement(ViewComponent, viewProps, childEls)\n } else {\n content = createElement(ViewComponent, viewProps, childEls)\n }\n\n const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n if (shouldWrapTextAncestor) {\n // from react-native-web\n // @ts-ignore\n content = createElement(TextAncestorContext.Provider, { value: true }, content)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n viewProps['debug'] = true\n console.log('\uD83E\uDD5A props in:', props)\n console.log('\uD83E\uDD5A props out:', viewProps)\n console.log(props.onClick?.toString())\n // prettier-ignore\n console.log('\uD83E\uDD5A etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn })\n // only on browser because node expands it huge\n if (isWeb) {\n console.log('\uD83E\uDD5A component info', { staticConfig, tamaguiConfig })\n }\n }\n }\n\n return (\n <>\n {features}\n {content}\n </>\n )\n })\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n tamaguiConfig = conf\n initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]\n const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)\n if (isWeb) {\n if (next.classNames) {\n defaultsClassName += next.classNames + ' '\n }\n defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])\n } else {\n // native, create a default StyleSheet\n // TODO handle next.pseudos\n const sheetStyles = {}\n for (const style of next.style) {\n Object.assign(sheetStyles, style)\n }\n defaultNativeStyle = StyleSheet.create({\n base: sheetStyles,\n })\n }\n // @ts-ignore\n component.defaultProps = {\n ...next.viewProps,\n ...component.defaultProps,\n }\n if (process.env.NODE_ENV === 'development') {\n if (staticConfig.defaultProps?.debug) {\n console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)\n }\n }\n })\n\n component['staticConfig'] = {\n validStyles: validStyleProps,\n ...staticConfig,\n }\n\n const res = component as any as StaticComponent<A, void>\n\n // add extractable HoC\n res['extractable'] = (Component: any, conf?: StaticConfig) => {\n Component['staticConfig'] = extendStaticConfig(res, {\n ...conf,\n neverFlatten: true,\n defaultProps: {\n ...Component.defaultProps,\n ...conf?.defaultProps,\n },\n })\n return Component\n }\n\n return res\n}\n\nlet hasWarnedOnce = false\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n return {\n width: tokens.size[size] ?? size,\n height: tokens.size[size] ?? size,\n }\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n },\n vertical: {\n width: 0,\n },\n },\n },\n})\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n flexDirection,\n}: {\n isZStack?: boolean\n children: any\n space?: any\n flexDirection?: ViewStyle['flexDirection']\n}) {\n if (!space && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n const len = childrenList.length\n if (len === 1) {\n return children\n }\n const next: any[] = []\n for (const [index, child] of childrenList.entries()) {\n if (child === null || child === undefined) {\n continue\n }\n\n const key = `${child?.['key'] ?? index}`\n\n next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)\n\n // allows for custom visually hidden components that dont insert spacing\n if (child?.['type']?.['isVisuallyHidden']) {\n continue\n }\n\n if (index !== len - 1) {\n if (space) {\n next.push(\n <Spacer\n key={`${key}_spacer`}\n // @ts-ignore TODO\n direction={\n flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'\n }\n size={space}\n />\n )\n }\n }\n }\n return next\n}\n\n// for now not so \"tamagui-y\"\nconst Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>\nconst sheet = StyleSheet.create({\n fullscreen: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n})\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQA;AAEO,MAAM,WAAW,oBAAI;AAE5B,IAAI,OAAO,aAAa,aAAa;AACnC,WAAS,iBAAiB,WAAW,MAAM;AACzC,aAAS,QAAQ,CAAC,MAAM;AACxB,aAAS;AAAA;AAAA;AAMb,MAAM,wBAAwB;AAAA,EAC5B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS;AAAA;AAKX,6BAA6B,QAA8D;AACzF,SAAO,CAAC,SAAkC;AACxC,WAAO,CAAC,SAAS;AACf,iBAAW,OAAO,MAAM;AACtB,YAAI,KAAK,SAAS,KAAK,MAAM;AAC3B,iBAAO,KAAK,SAAS;AAAA;AAAA;AAGzB,aAAO;AAAA;AAAA;AAAA;AARJ;AAaF,yBACL,UACA;AACA,MAAI;AACJ,MAAI,YAAY,UAAU;AACxB,mBAAe;AAAA,SACV;AACL,mBAAe,kBAAkB;AAAA;AAGnC,QAAM,EAAE,WAAW,aAAa,QAAQ,aAAa;AACrD,QAAM,kBAAkB,oCAAe;AAGvC,MAAI,eAAe;AACnB,MAAI;AAGJ,MAAI,qBAAkE;AACtE,MAAI,oBAAoB;AACxB,MAAI;AAIJ,QAAM,YAAY,WAAoB,CAAC,OAAY,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import { concatClassName, stylePropsView } from '@tamagui/helpers'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, TextInput, View, ViewStyle } from 'react-native'\n\nimport { onConfiguredOnce } from './conf'\nimport { stackDefaultStyles } from './constants/constants'\nimport { isTouchDevice, isWeb } from './constants/platform'\nimport { rnw } from './constants/rnw'\nimport { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { getSplitStyles } from './helpers/getSplitStyles'\nimport { useFeatures } from './hooks/useFeatures'\nimport { usePressable } from './hooks/usePressable'\nimport { useTheme } from './hooks/useTheme'\nimport {\n SpaceTokens,\n StaticComponent,\n StaticConfig,\n StaticConfigParsed,\n TamaguiInternalConfig,\n} from './types'\nimport { TextAncestorContext } from './views/TextAncestorContext'\n\nexport const mouseUps = new Set<Function>()\n\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\ntype DefaultProps = {}\n\nconst defaultComponentState = {\n hover: false,\n press: false,\n pressIn: false,\n}\n\ntype ComponentState = typeof defaultComponentState\n\nfunction createShallowUpdate(setter: React.Dispatch<React.SetStateAction<ComponentState>>) {\n return (next: Partial<ComponentState>) => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return { ...prev, ...next }\n }\n }\n return prev\n })\n }\n}\n\nexport function createComponent<A extends Object = DefaultProps>(\n configIn: Partial<StaticConfig> | StaticConfigParsed\n) {\n let staticConfig: StaticConfigParsed\n if ('parsed' in configIn) {\n staticConfig = configIn\n } else {\n staticConfig = parseStaticConfig(configIn)\n }\n\n const { Component, validStyles, isText, isZStack } = staticConfig\n const validStyleProps = validStyles ?? stylePropsView\n\n // split out default styles vs props so we can assign it to component.defaultProps\n let defaultProps = null as any\n let tamaguiConfig: TamaguiInternalConfig\n\n // web uses className, native uses style\n let defaultNativeStyle: StyleSheet.NamedStyles<{ base: {} }> | null = null\n let defaultsClassName = ''\n let initialTheme: any\n\n // see onConfiguredOnce below which attaches a name then to this component\n\n const component = forwardRef<View, A>((props: any, forwardedRef) => {\n const forceUpdate = useForceUpdate()\n const features = useFeatures(props, { forceUpdate })\n const theme = useTheme()\n const [state, set_] = useState<ComponentState>(defaultComponentState)\n const set = createShallowUpdate(set_)\n\n // from react-native-web\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false\n const hostRef = useRef(null)\n\n const {\n viewProps: viewPropsIn,\n pseudos,\n style,\n classNames,\n } = getSplitStyles(props, staticConfig, theme)\n\n const {\n tag,\n hitSlop,\n children,\n pointerEvents,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n space,\n disabled,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\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 onMouseDown,\n onClick,\n\n accessible,\n accessibilityRole,\n\n // TODO feature load layout hook\n onLayout,\n ...viewProps\n } = viewPropsIn\n\n if (!isWeb) {\n if (accessible) viewProps.accessible = accessible\n if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole\n }\n\n if (isWeb) {\n // from react-native-web\n rnw.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 })\n }\n\n // hasEverHadEvents prevents repareting if you remove onPress or similar...\n const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useEffect(() => {\n internal.current!.isMounted = true\n return () => {\n mouseUps.delete(unPress)\n internal.current!.isMounted = false\n }\n }, [])\n\n // element\n const isInternalComponent = !Component || typeof Component === 'string'\n // default to tag, fallback to component (when both strings)\n const element = isWeb ? (isInternalComponent ? tag || Component : Component) : Component\n const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n const ReactText = !isWeb ? Text : element || 'span'\n const ViewComponent = isText ? ReactText : ReactView\n\n // styles\n const isHovering = !isTouchDevice && !disabled && pseudos && state.hover\n const isPressing = !disabled && pseudos && state.press\n\n const styles = [\n defaultNativeStyle ? defaultNativeStyle.base : null,\n // parity w react-native-web, only for text in text\n // TODO this should be able to be done w css to replicate after extraction:\n // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)\n // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,\n style,\n isHovering ? pseudos.hoverStyle || null : null,\n isPressing ? pseudos.pressStyle || null : null,\n ]\n\n if (isWeb) {\n const stylesClassNames = useStylesAsClassname(styles)\n const classList = isText\n ? [\n defaultsClassName,\n // hasTextAncestor === true && cssText.textHasAncestor,\n // TODO MOVE TO VARIANTS [number] [any]\n // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,\n classNames,\n stylesClassNames,\n props.className,\n ]\n : [defaultsClassName, props.className, classNames, stylesClassNames]\n\n // @ts-ignore we are optimizing using arguments\n const className = concatClassName(...classList)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.log('\uD83E\uDD5A className', { style, styles, classList, stylesClassNames, className })\n }\n }\n viewProps.className = className\n } else {\n viewProps.style = styles\n }\n\n if (pointerEvents) {\n viewProps.pointerEvents = pointerEvents\n }\n\n if (isWeb) {\n // from react-native-web\n const platformMethodsRef = rnw.usePlatformMethods(viewProps)\n const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)\n viewProps.ref = setRef\n if (props.href != null && hrefAttrs != null) {\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 } else {\n if (forwardedRef) {\n viewProps.ref = forwardedRef\n }\n }\n\n const attachPress = !!(\n (pseudos && pseudos.pressStyle) ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n const attachHover =\n isWeb &&\n !isTouchDevice &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n // while avoiding reparenting...\n // once proper reparenting is supported, we can remove this and use that...\n const shouldAttach =\n internal.current.hasEverHadEvents ||\n attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onClick' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props))\n\n // never remove events as we wrap in a div (for now, may be able to remove..)\n if (shouldAttach) {\n internal.current.hasEverHadEvents = true\n }\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n set({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n ...(!isWeb && {\n // non web\n onPressOut: (e) => {\n unPress()\n onPressOut?.(e)\n },\n }),\n ...(isWeb &&\n !isTouchDevice && {\n onMouseEnter:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n onMouseDown: attachPress\n ? (e) => {\n set({\n press: true,\n pressIn: true,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n }\n : (onPressIn as any),\n onClick: attachPress\n ? (e) => {\n // this caused issue with next.js passing href\n // e.preventDefault()\n onPress?.(e)\n onClick?.(e)\n unPress()\n onPressOut?.(e)\n }\n : (onPressOut as any),\n }\n : null\n\n if (events) {\n if (typeof ViewComponent !== 'string') {\n // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic\n const [pressProps] = usePressable({\n disabled,\n hitSlop,\n onPressIn: events.onMouseDown,\n onPressOut: events.onPressOut,\n onPress: events.onClick,\n })\n Object.assign(viewProps, pressProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n\n const childEls = spacedChildren({\n children,\n space,\n flexDirection: props.flexDirection || defaultProps?.flexDirection,\n isZStack: isZStack,\n })\n\n let content: any\n\n // replicate react-native-web's `createElement`\n if (isWeb && rnw) {\n const domProps = rnw.createDOMProps(viewProps)\n const className =\n domProps.className && domProps.className !== viewProps.className\n ? `${domProps.className} ${viewProps.className}`\n : viewProps.className\n Object.assign(viewProps, domProps)\n\n // hacky workaround to pass classnames until we get stylex\n if (ViewComponent === TextInput) {\n viewProps.dataSet = viewProps.dataSet || {}\n Object.assign(viewProps.dataSet, { __className: className })\n } else {\n // we already handle Text/View properly\n viewProps.className = className\n }\n\n content = createElement(ViewComponent, viewProps, childEls)\n } else {\n content = createElement(ViewComponent, viewProps, childEls)\n }\n\n const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n if (shouldWrapTextAncestor) {\n // from react-native-web\n content = createElement(TextAncestorContext.Provider, { value: true }, content)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n viewProps['debug'] = true\n console.log('\uD83E\uDD5A props in:', props)\n console.log('\uD83E\uDD5A props out:', viewProps)\n // prettier-ignore\n console.log('\uD83E\uDD5A etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn })\n // only on browser because node expands it huge\n if (isWeb) console.log('\uD83E\uDD5A component info', { staticConfig, tamaguiConfig })\n }\n }\n\n return (\n <>\n {features}\n {content}\n </>\n )\n })\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n tamaguiConfig = conf\n initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]\n const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)\n if (isWeb) {\n if (next.classNames) {\n defaultsClassName += next.classNames + ' '\n }\n defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])\n } else {\n // native, create a default StyleSheet\n // TODO handle next.pseudos\n const sheetStyles = {}\n for (const style of next.style) {\n Object.assign(sheetStyles, style)\n }\n defaultNativeStyle = StyleSheet.create({\n base: sheetStyles,\n })\n }\n // @ts-ignore\n component.defaultProps = {\n ...next.viewProps,\n ...component.defaultProps,\n }\n if (process.env.NODE_ENV === 'development') {\n if (staticConfig.defaultProps?.debug) {\n console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)\n }\n }\n })\n\n component['staticConfig'] = {\n validStyles: validStyleProps,\n ...staticConfig,\n }\n\n const res = component as any as StaticComponent<A, void>\n\n // add extractable HoC\n res['extractable'] = (Component: any, conf?: StaticConfig) => {\n Component['staticConfig'] = extendStaticConfig(res, {\n ...conf,\n neverFlatten: true,\n defaultProps: {\n ...Component.defaultProps,\n ...conf?.defaultProps,\n },\n })\n return Component\n }\n\n return res\n}\n\nlet hasWarnedOnce = false\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n return {\n width: tokens.size[size] ?? size,\n height: tokens.size[size] ?? size,\n }\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n },\n vertical: {\n width: 0,\n },\n },\n },\n})\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n flexDirection,\n}: {\n isZStack?: boolean\n children: any\n space?: any\n flexDirection?: ViewStyle['flexDirection']\n}) {\n if (!space && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n const len = childrenList.length\n if (len === 1) {\n return children\n }\n const next: any[] = []\n for (const [index, child] of childrenList.entries()) {\n if (child === null || child === undefined) {\n continue\n }\n\n const key = `${child?.['key'] ?? index}`\n\n next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)\n\n // allows for custom visually hidden components that dont insert spacing\n if (child?.['type']?.['isVisuallyHidden']) {\n continue\n }\n\n if (index !== len - 1) {\n if (space) {\n next.push(\n <Spacer\n key={`${key}_spacer`}\n // @ts-ignore TODO\n direction={\n flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'\n }\n size={space}\n />\n )\n }\n }\n }\n return next\n}\n\n// for now not so \"tamagui-y\"\nconst Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>\nconst sheet = StyleSheet.create({\n fullscreen: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n})\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQA;AAEO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
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/addStylesUsingClassname.tsx"],
|
|
4
|
-
"sourcesContent": ["// @ts-ignore\nimport { useInsertionEffect } from 'react'\n\nimport { getStylesAtomic } from './getStylesAtomic'\nimport { insertStyleRule } from './insertStyleRule'\n\n// uses new useInsertionEffect for better perf if available\n\n// could be cleared occasionally\nlet added = new Set<string>()\n\nexport function useStylesAsClassname(styles: any[]) {\n if (!useInsertionEffect) {\n return addStylesUsingClassname(styles)\n } else {\n const insertions: any[] = []\n const className = addStylesUsingClassname(styles, (_, rules) => {\n for (const rule of rules) {\n insertions.push(rule)\n }\n })\n\n useInsertionEffect(() => {\n for (const ruleset of insertions) {\n insertStyleRule(ruleset)\n }\n })\n\n return className\n }\n}\n\nexport function addStylesUsingClassname(\n styles: any[],\n onAdd?: (identifier: string, rules: string[]) => any\n) {\n let className = ''\n for (const style of styles) {\n if (!style) continue\n if (Array.isArray(style)) {\n className += ' ' + addStylesUsingClassname(style)\n continue\n }\n for (const { identifier, rules } of getStylesAtomic(style)) {\n className += ` ${identifier}`\n if (added.has(identifier)) {\n continue\n }\n added.add(identifier)\n if (onAdd) {\n onAdd(identifier, rules)\n } else {\n for (const rule of rules) {\n insertStyleRule(rule)\n }\n }\n }\n }\n return className\n}\n"],
|
|
5
|
-
"mappings": ";;AACA;AAEA;AACA;
|
|
4
|
+
"sourcesContent": ["// @ts-ignore\nimport { useInsertionEffect } from 'react'\n\nimport { getStylesAtomic } from './getStylesAtomic'\nimport { insertStyleRule } from './insertStyleRule'\n\n// TODO can drop most of this code once we drop support for 17\n// uses new useInsertionEffect for better perf if available\n\n// could be cleared occasionally\nlet added = new Set<string>()\n\nexport function useStylesAsClassname(styles: any[]) {\n if (!useInsertionEffect) {\n return addStylesUsingClassname(styles)\n } else {\n const insertions: any[] = []\n const className = addStylesUsingClassname(styles, (_, rules) => {\n for (const rule of rules) {\n insertions.push(rule)\n }\n })\n\n useInsertionEffect(() => {\n for (const ruleset of insertions) {\n insertStyleRule(ruleset)\n }\n })\n\n return className\n }\n}\n\nexport function addStylesUsingClassname(\n styles: any[],\n onAdd?: (identifier: string, rules: string[]) => any\n) {\n let className = ''\n for (const style of styles) {\n if (!style) continue\n if (Array.isArray(style)) {\n className += ' ' + addStylesUsingClassname(style)\n continue\n }\n for (const { identifier, rules } of getStylesAtomic(style)) {\n className += ` ${identifier}`\n if (added.has(identifier)) {\n continue\n }\n added.add(identifier)\n if (onAdd) {\n onAdd(identifier, rules)\n } else {\n for (const rule of rules) {\n insertStyleRule(rule)\n }\n }\n }\n }\n return className\n}\n"],
|
|
5
|
+
"mappings": ";;AACA;AAEA;AACA;AAMA,IAAI,QAAQ,oBAAI;AAET,8BAA8B,QAAe;AAClD,MAAI,CAAC,oBAAoB;AACvB,WAAO,wBAAwB;AAAA,SAC1B;AACL,UAAM,aAAoB;AAC1B,UAAM,YAAY,wBAAwB,QAAQ,CAAC,GAAG,UAAU;AAC9D,iBAAW,QAAQ,OAAO;AACxB,mBAAW,KAAK;AAAA;AAAA;AAIpB,uBAAmB,MAAM;AACvB,iBAAW,WAAW,YAAY;AAChC,wBAAgB;AAAA;AAAA;AAIpB,WAAO;AAAA;AAAA;AAjBK;AAqBT,iCACL,QACA,OACA;AACA,MAAI,YAAY;AAChB,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC;AAAO;AACZ,QAAI,MAAM,QAAQ,QAAQ;AACxB,mBAAa,MAAM,wBAAwB;AAC3C;AAAA;AAEF,eAAW,EAAE,YAAY,WAAW,gBAAgB,QAAQ;AAC1D,mBAAa,IAAI;AACjB,UAAI,MAAM,IAAI,aAAa;AACzB;AAAA;AAEF,YAAM,IAAI;AACV,UAAI,OAAO;AACT,cAAM,YAAY;AAAA,aACb;AACL,mBAAW,QAAQ,OAAO;AACxB,0BAAgB;AAAA;AAAA;AAAA;AAAA;AAKxB,SAAO;AAAA;AA1BO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -31,10 +31,10 @@ const useDefaultThemeName = /* @__PURE__ */ __name(() => {
|
|
|
31
31
|
return useContext(ThemeContext)[GET_DEFAULT_THEME];
|
|
32
32
|
}, "useDefaultThemeName");
|
|
33
33
|
const useTheme = /* @__PURE__ */ __name(() => {
|
|
34
|
-
var _a;
|
|
34
|
+
var _a, _b;
|
|
35
35
|
const forceUpdate = useForceUpdate();
|
|
36
36
|
const manager = useContext(ThemeManagerContext);
|
|
37
|
-
const themes = useContext(ThemeContext);
|
|
37
|
+
const themes = useContext(ThemeContext) || {};
|
|
38
38
|
const state = useRef();
|
|
39
39
|
if (!state.current) {
|
|
40
40
|
state.current = {
|
|
@@ -55,7 +55,7 @@ const useTheme = /* @__PURE__ */ __name(() => {
|
|
|
55
55
|
useEffect(() => {
|
|
56
56
|
return manager.onUpdate(state.current.uuid, forceUpdate);
|
|
57
57
|
}, []);
|
|
58
|
-
const theme = (_a = manager.name ? themes[manager.name] : themes.light) != null ? _a : themes.light;
|
|
58
|
+
const theme = (_b = (_a = manager.name ? themes[manager.name] : themes.light) != null ? _a : themes.light) != null ? _b : {};
|
|
59
59
|
return useMemo(() => {
|
|
60
60
|
return new Proxy(theme, {
|
|
61
61
|
get(_, key) {
|
|
@@ -65,7 +65,9 @@ const useTheme = /* @__PURE__ */ __name(() => {
|
|
|
65
65
|
}
|
|
66
66
|
let activeTheme = themes[name];
|
|
67
67
|
if (!activeTheme) {
|
|
68
|
-
|
|
68
|
+
if (process.env.NODE_ENV !== "test") {
|
|
69
|
+
console.error("No theme by name", name, "only:", themes, "keeping current theme");
|
|
70
|
+
}
|
|
69
71
|
activeTheme = theme;
|
|
70
72
|
}
|
|
71
73
|
const val = activeTheme[key];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { GET_DEFAULT_THEME } from '../constants/constants'\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { Variable } from '../createVariable'\nimport { ThemeName, ThemeObject } from '../types'\nimport { ThemeContext } from '../views/ThemeContext'\nimport { ThemeManagerContext } from '../views/ThemeManagerContext'\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nconst areEqualSets = (a: Set<string>, b: Set<string>) => {\n if (a.size !== b.size) return false\n for (const val in a) {\n if (!b.has(val)) {\n return false\n }\n }\n return true\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent.name)\n\n useIsomorphicLayoutEffect(() => {\n return parent.onChangeTheme((next, manager) => {\n setName(opts?.parent ? manager.parentName : next)\n })\n }, [parent])\n\n return name || 'light'\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)[GET_DEFAULT_THEME] as any as ThemeName\n}\n\nexport const useTheme = (): ThemeObject => {\n const forceUpdate = useForceUpdate()\n const manager = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext)\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = manager.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n manager.track(st.uuid, st.keys)\n }\n })\n\n useEffect(() => {\n return manager.onUpdate(state.current.uuid, forceUpdate)\n }, [])\n\n const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light\n\n return useMemo(\n () => {\n return new Proxy(theme, {\n get(_, key: string) {\n const name = manager.name\n if (!name) {\n return Reflect.get(_, key)\n }\n let activeTheme = themes[name]\n if (!activeTheme) {\n console.error('No theme by name', name, 'only:', themes, 'keeping current theme')\n activeTheme = theme\n }\n const val = activeTheme[key]\n if (process.env.NODE_ENV === 'development') {\n if (typeof val === 'undefined') {\n console.warn(`No theme value \"${String(key)}\" in`, activeTheme, themes)\n return null\n }\n if (!(val instanceof Variable)) {\n console.warn('Non variable!', val)\n }\n if (val.name !== key) {\n console.warn('Non-matching name for variable to key', key, val.name)\n }\n }\n if (state.current.isRendering) {\n state.current.keys.add(key)\n }\n return val\n },\n })\n },\n [\n /* if concurrent mode wanted put manager.name here */\n ]\n )\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAQA,MAAM,eAAe,wBAAC,GAAgB,MAAmB;AACvD,MAAI,EAAE,SAAS,EAAE;AAAM,WAAO;AAC9B,aAAW,OAAO,GAAG;AACnB,QAAI,CAAC,EAAE,IAAI,MAAM;AACf,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA,GAPY;AAUd,MAAM,eAAe,wBAAC,SAA6B;AACxD,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,MAAM,WAAW,SAAS,OAAO;AAExC,4BAA0B,MAAM;AAC9B,WAAO,OAAO,cAAc,CAAC,MAAM,YAAY;AAC7C,cAAQ,8BAAM,UAAS,QAAQ,aAAa;AAAA;AAAA,KAE7C,CAAC;AAEJ,SAAO,QAAQ;AAAA,GAVW;AAarB,MAAM,sBAAsB,6BAAM;AACvC,SAAO,WAAW,cAAc;AAAA,GADC;AAI5B,MAAM,WAAW,6BAAmB;AA3C3C;AA4CE,QAAM,cAAc;AACpB,QAAM,UAAU,WAAW;AAC3B,QAAM,SAAS,WAAW;
|
|
4
|
+
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { GET_DEFAULT_THEME } from '../constants/constants'\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { Variable } from '../createVariable'\nimport { ThemeName, ThemeObject } from '../types'\nimport { ThemeContext } from '../views/ThemeContext'\nimport { ThemeManagerContext } from '../views/ThemeManagerContext'\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nconst areEqualSets = (a: Set<string>, b: Set<string>) => {\n if (a.size !== b.size) return false\n for (const val in a) {\n if (!b.has(val)) {\n return false\n }\n }\n return true\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent.name)\n\n useIsomorphicLayoutEffect(() => {\n return parent.onChangeTheme((next, manager) => {\n setName(opts?.parent ? manager.parentName : next)\n })\n }, [parent])\n\n return name || 'light'\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)[GET_DEFAULT_THEME] as any as ThemeName\n}\n\nexport const useTheme = (): ThemeObject => {\n const forceUpdate = useForceUpdate()\n const manager = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext) || {}\n\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = manager.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n manager.track(st.uuid, st.keys)\n }\n })\n\n useEffect(() => {\n return manager.onUpdate(state.current.uuid, forceUpdate)\n }, [])\n\n const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light ?? {}\n\n return useMemo(\n () => {\n return new Proxy(theme, {\n get(_, key: string) {\n const name = manager.name\n if (!name) {\n return Reflect.get(_, key)\n }\n let activeTheme = themes[name]\n if (!activeTheme) {\n if (process.env.NODE_ENV !== 'test') {\n console.error('No theme by name', name, 'only:', themes, 'keeping current theme')\n }\n activeTheme = theme\n }\n const val = activeTheme[key]\n if (process.env.NODE_ENV === 'development') {\n if (typeof val === 'undefined') {\n console.warn(`No theme value \"${String(key)}\" in`, activeTheme, themes)\n return null\n }\n if (!(val instanceof Variable)) {\n console.warn('Non variable!', val)\n }\n if (val.name !== key) {\n console.warn('Non-matching name for variable to key', key, val.name)\n }\n }\n if (state.current.isRendering) {\n state.current.keys.add(key)\n }\n return val\n },\n })\n },\n [\n /* if concurrent mode wanted put manager.name here */\n ]\n )\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAQA,MAAM,eAAe,wBAAC,GAAgB,MAAmB;AACvD,MAAI,EAAE,SAAS,EAAE;AAAM,WAAO;AAC9B,aAAW,OAAO,GAAG;AACnB,QAAI,CAAC,EAAE,IAAI,MAAM;AACf,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA,GAPY;AAUd,MAAM,eAAe,wBAAC,SAA6B;AACxD,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,MAAM,WAAW,SAAS,OAAO;AAExC,4BAA0B,MAAM;AAC9B,WAAO,OAAO,cAAc,CAAC,MAAM,YAAY;AAC7C,cAAQ,8BAAM,UAAS,QAAQ,aAAa;AAAA;AAAA,KAE7C,CAAC;AAEJ,SAAO,QAAQ;AAAA,GAVW;AAarB,MAAM,sBAAsB,6BAAM;AACvC,SAAO,WAAW,cAAc;AAAA,GADC;AAI5B,MAAM,WAAW,6BAAmB;AA3C3C;AA4CE,QAAM,cAAc;AACpB,QAAM,UAAU,WAAW;AAC3B,QAAM,SAAS,WAAW,iBAAiB;AAE3C,QAAM,QAAQ;AACd,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM;AAAA,MACN,MAAM,oBAAI;AAAA,MACV,aAAa;AAAA;AAAA;AAGjB,QAAM,QAAQ,cAAc;AAG5B,4BAA0B,MAAM;AAC9B,UAAM,KAAK,MAAM;AACjB,OAAG,cAAc;AACjB,UAAM,MAAM,QAAQ,KAAK,IAAI,GAAG;AAChC,QAAI,CAAC,OAAO,CAAC,aAAa,GAAG,MAAM,MAAM;AACvC,cAAQ,MAAM,GAAG,MAAM,GAAG;AAAA;AAAA;AAI9B,YAAU,MAAM;AACd,WAAO,QAAQ,SAAS,MAAM,QAAQ,MAAM;AAAA,KAC3C;AAEH,QAAM,QAAS,oBAAQ,OAAO,OAAO,QAAQ,QAAQ,OAAO,UAA7C,YAAuD,OAAO,UAA9D,YAAuE;AAEtF,SAAO,QACL,MAAM;AACJ,WAAO,IAAI,MAAM,OAAO;AAAA,MACtB,IAAI,GAAG,KAAa;AAClB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,MAAM;AACT,iBAAO,QAAQ,IAAI,GAAG;AAAA;AAExB,YAAI,cAAc,OAAO;AACzB,YAAI,CAAC,aAAa;AAChB,cAAI,QAAQ,IAAI,aAAa,QAAQ;AACnC,oBAAQ,MAAM,oBAAoB,MAAM,SAAS,QAAQ;AAAA;AAE3D,wBAAc;AAAA;AAEhB,cAAM,MAAM,YAAY;AACxB,YAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAI,OAAO,QAAQ,aAAa;AAC9B,oBAAQ,KAAK,mBAAmB,OAAO,YAAY,aAAa;AAChE,mBAAO;AAAA;AAET,cAAI,CAAE,gBAAe,WAAW;AAC9B,oBAAQ,KAAK,iBAAiB;AAAA;AAEhC,cAAI,IAAI,SAAS,KAAK;AACpB,oBAAQ,KAAK,yCAAyC,KAAK,IAAI;AAAA;AAAA;AAGnE,YAAI,MAAM,QAAQ,aAAa;AAC7B,gBAAM,QAAQ,KAAK,IAAI;AAAA;AAEzB,eAAO;AAAA;AAAA;AAAA,KAIb;AAAA,GAlEoB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
useRef,
|
|
14
14
|
useState
|
|
15
15
|
} from "react";
|
|
16
|
-
import { StyleSheet, Text, View } from "react-native";
|
|
16
|
+
import { StyleSheet, Text, TextInput, View } from "react-native";
|
|
17
17
|
import { onConfiguredOnce } from "./conf";
|
|
18
18
|
import { stackDefaultStyles } from "./constants/constants";
|
|
19
19
|
import { isTouchDevice, isWeb } from "./constants/platform";
|
|
@@ -65,7 +65,6 @@ function createComponent(configIn) {
|
|
|
65
65
|
let defaultsClassName = "";
|
|
66
66
|
let initialTheme;
|
|
67
67
|
const component = forwardRef((props, forwardedRef) => {
|
|
68
|
-
var _a;
|
|
69
68
|
const forceUpdate = useForceUpdate();
|
|
70
69
|
const features = useFeatures(props, { forceUpdate });
|
|
71
70
|
const theme = useTheme();
|
|
@@ -163,7 +162,8 @@ function createComponent(configIn) {
|
|
|
163
162
|
internal.current.isMounted = false;
|
|
164
163
|
};
|
|
165
164
|
}, []);
|
|
166
|
-
const
|
|
165
|
+
const isInternalComponent = !Component || typeof Component === "string";
|
|
166
|
+
const element = isWeb ? isInternalComponent ? tag || Component : Component : Component;
|
|
167
167
|
const ReactView = !isWeb ? View : element || (hasTextAncestor ? "span" : "div");
|
|
168
168
|
const ReactText = !isWeb ? Text : element || "span";
|
|
169
169
|
const ViewComponent = isText ? ReactText : ReactView;
|
|
@@ -310,7 +310,12 @@ function createComponent(configIn) {
|
|
|
310
310
|
const domProps = rnw.createDOMProps(viewProps);
|
|
311
311
|
const className = domProps.className && domProps.className !== viewProps.className ? `${domProps.className} ${viewProps.className}` : viewProps.className;
|
|
312
312
|
Object.assign(viewProps, domProps);
|
|
313
|
-
|
|
313
|
+
if (ViewComponent === TextInput) {
|
|
314
|
+
viewProps.dataSet = viewProps.dataSet || {};
|
|
315
|
+
Object.assign(viewProps.dataSet, { __className: className });
|
|
316
|
+
} else {
|
|
317
|
+
viewProps.className = className;
|
|
318
|
+
}
|
|
314
319
|
content = createElement(ViewComponent, viewProps, childEls);
|
|
315
320
|
} else {
|
|
316
321
|
content = createElement(ViewComponent, viewProps, childEls);
|
|
@@ -324,11 +329,9 @@ function createComponent(configIn) {
|
|
|
324
329
|
viewProps["debug"] = true;
|
|
325
330
|
console.log("\u{1F95A} props in:", props);
|
|
326
331
|
console.log("\u{1F95A} props out:", viewProps);
|
|
327
|
-
console.log((_a = props.onClick) == null ? void 0 : _a.toString());
|
|
328
332
|
console.log("\u{1F95A} etc:", { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls, configIn });
|
|
329
|
-
if (isWeb)
|
|
333
|
+
if (isWeb)
|
|
330
334
|
console.log("\u{1F95A} component info", { staticConfig, tamaguiConfig });
|
|
331
|
-
}
|
|
332
335
|
}
|
|
333
336
|
}
|
|
334
337
|
return <>
|
|
@@ -31,10 +31,10 @@ const useDefaultThemeName = /* @__PURE__ */ __name(() => {
|
|
|
31
31
|
return useContext(ThemeContext)[GET_DEFAULT_THEME];
|
|
32
32
|
}, "useDefaultThemeName");
|
|
33
33
|
const useTheme = /* @__PURE__ */ __name(() => {
|
|
34
|
-
var _a;
|
|
34
|
+
var _a, _b;
|
|
35
35
|
const forceUpdate = useForceUpdate();
|
|
36
36
|
const manager = useContext(ThemeManagerContext);
|
|
37
|
-
const themes = useContext(ThemeContext);
|
|
37
|
+
const themes = useContext(ThemeContext) || {};
|
|
38
38
|
const state = useRef();
|
|
39
39
|
if (!state.current) {
|
|
40
40
|
state.current = {
|
|
@@ -55,7 +55,7 @@ const useTheme = /* @__PURE__ */ __name(() => {
|
|
|
55
55
|
useEffect(() => {
|
|
56
56
|
return manager.onUpdate(state.current.uuid, forceUpdate);
|
|
57
57
|
}, []);
|
|
58
|
-
const theme = (_a = manager.name ? themes[manager.name] : themes.light) != null ? _a : themes.light;
|
|
58
|
+
const theme = (_b = (_a = manager.name ? themes[manager.name] : themes.light) != null ? _a : themes.light) != null ? _b : {};
|
|
59
59
|
return useMemo(() => {
|
|
60
60
|
return new Proxy(theme, {
|
|
61
61
|
get(_, key) {
|
|
@@ -65,7 +65,9 @@ const useTheme = /* @__PURE__ */ __name(() => {
|
|
|
65
65
|
}
|
|
66
66
|
let activeTheme = themes[name];
|
|
67
67
|
if (!activeTheme) {
|
|
68
|
-
|
|
68
|
+
if (process.env.NODE_ENV !== "test") {
|
|
69
|
+
console.error("No theme by name", name, "only:", themes, "keeping current theme");
|
|
70
|
+
}
|
|
69
71
|
activeTheme = theme;
|
|
70
72
|
}
|
|
71
73
|
const val = activeTheme[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.46",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9043b00ecae482a1694ea28c0df4168b71397be3"
|
|
38
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAqC,SAAS,EAAE,MAAM,cAAc,CAAA;AAY3E,OAAO,EAEL,eAAe,EACf,YAAY,EACZ,kBAAkB,EAEnB,MAAM,SAAS,CAAA;AAGhB,eAAO,MAAM,QAAQ,eAAsB,CAAA;AAS3C,aAAK,YAAY,GAAG,EAAE,CAAA;AAuBtB,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,EAC7D,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,kBAAkB,qDAucrD;AAOD,eAAO,MAAM,MAAM;;;iCAyBjB,CAAA;AAEF,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,aAAa,GACd,EAAE;IACD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,GAAG,CAAA;IACb,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,aAAa,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,CAAA;CAC3C,OAwCA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addStylesUsingClassname.d.ts","sourceRoot":"","sources":["../../src/helpers/addStylesUsingClassname.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addStylesUsingClassname.d.ts","sourceRoot":"","sources":["../../src/helpers/addStylesUsingClassname.tsx"],"names":[],"mappings":"AAYA,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,UAmBjD;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,EAAE,EACb,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,UAyBrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAa,WAAW,EAAE,MAAM,UAAU,CAAA;AAoBjD,eAAO,MAAM,YAAY;;wBAWxB,CAAA;AAED,eAAO,MAAM,mBAAmB,uBAE/B,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,
|
|
1
|
+
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAa,WAAW,EAAE,MAAM,UAAU,CAAA;AAoBjD,eAAO,MAAM,YAAY;;wBAWxB,CAAA;AAED,eAAO,MAAM,mBAAmB,uBAE/B,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,WAsE3B,CAAA"}
|