@tamagui/core 1.0.1-beta.227 → 1.0.1-beta.228

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.
Files changed (109) hide show
  1. package/dist/cjs/constants/platform.js +65 -0
  2. package/dist/cjs/constants/platform.js.map +7 -0
  3. package/dist/cjs/constants/platform.native.js +62 -0
  4. package/dist/cjs/constants/platform.native.js.map +7 -0
  5. package/dist/cjs/createComponent.js +17 -24
  6. package/dist/cjs/createComponent.js.map +2 -2
  7. package/dist/cjs/createVariable.js +1 -1
  8. package/dist/cjs/createVariable.js.map +2 -2
  9. package/dist/cjs/helpers/ThemeManager.js +1 -1
  10. package/dist/cjs/helpers/ThemeManager.js.map +2 -2
  11. package/dist/cjs/helpers/ThemeManager.test.js +16 -0
  12. package/dist/cjs/helpers/ThemeManager.test.js.map +2 -2
  13. package/dist/cjs/helpers/assignNativePropsToWeb.js +188 -0
  14. package/dist/cjs/helpers/assignNativePropsToWeb.js.map +7 -0
  15. package/dist/cjs/helpers/assignNativePropsToWeb.native.js +30 -0
  16. package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +7 -0
  17. package/dist/cjs/helpers/calc.js +71 -0
  18. package/dist/cjs/helpers/calc.js.map +7 -0
  19. package/dist/cjs/helpers/createPropMapper.js +3 -5
  20. package/dist/cjs/helpers/createPropMapper.js.map +2 -2
  21. package/dist/cjs/helpers/createShallowUpdate.js +44 -0
  22. package/dist/cjs/helpers/createShallowUpdate.js.map +7 -0
  23. package/dist/cjs/helpers/getFont.js +66 -0
  24. package/dist/cjs/helpers/getFont.js.map +7 -0
  25. package/dist/cjs/helpers/getSplitStyles.js +24 -24
  26. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  27. package/dist/cjs/helpers/getStackSize.js +46 -0
  28. package/dist/cjs/helpers/getStackSize.js.map +7 -0
  29. package/dist/cjs/helpers/startTransition.js +36 -0
  30. package/dist/cjs/helpers/startTransition.js.map +7 -0
  31. package/dist/cjs/helpers/timer.js +35 -0
  32. package/dist/cjs/helpers/timer.js.map +7 -0
  33. package/dist/cjs/helpers/validate.js +2 -0
  34. package/dist/cjs/helpers/validate.js.map +7 -0
  35. package/dist/cjs/hooks/useConstant.js +39 -0
  36. package/dist/cjs/hooks/useConstant.js.map +7 -0
  37. package/dist/cjs/hooks/useIsMounted.js +40 -0
  38. package/dist/cjs/hooks/useIsMounted.js.map +7 -0
  39. package/dist/cjs/hooks/useIsSSR.js +46 -0
  40. package/dist/cjs/hooks/useIsSSR.js.map +7 -0
  41. package/dist/cjs/hooks/usePressable.js +36 -0
  42. package/dist/cjs/hooks/usePressable.js.map +7 -0
  43. package/dist/cjs/hooks/useUnmountEffect.js +32 -0
  44. package/dist/cjs/hooks/useUnmountEffect.js.map +7 -0
  45. package/dist/cjs/injectStyles.js +40 -0
  46. package/dist/cjs/injectStyles.js.map +7 -0
  47. package/dist/cjs/views/ThemeInverse.js +18 -25
  48. package/dist/cjs/views/ThemeInverse.js.map +2 -2
  49. package/dist/cjs/views/ThemeReset.js +12 -12
  50. package/dist/cjs/views/ThemeReset.js.map +2 -2
  51. package/dist/esm/constants/platform.js +30 -0
  52. package/dist/esm/constants/platform.js.map +7 -0
  53. package/dist/esm/constants/platform.native.js +28 -0
  54. package/dist/esm/constants/platform.native.js.map +7 -0
  55. package/dist/esm/createComponent.js +17 -24
  56. package/dist/esm/createComponent.js.map +2 -2
  57. package/dist/esm/createVariable.js +1 -1
  58. package/dist/esm/createVariable.js.map +2 -2
  59. package/dist/esm/helpers/ThemeManager.js +1 -1
  60. package/dist/esm/helpers/ThemeManager.js.map +2 -2
  61. package/dist/esm/helpers/ThemeManager.test.js +16 -0
  62. package/dist/esm/helpers/ThemeManager.test.js.map +2 -2
  63. package/dist/esm/helpers/assignNativePropsToWeb.js +164 -0
  64. package/dist/esm/helpers/assignNativePropsToWeb.js.map +7 -0
  65. package/dist/esm/helpers/assignNativePropsToWeb.native.js +6 -0
  66. package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +7 -0
  67. package/dist/esm/helpers/calc.js +47 -0
  68. package/dist/esm/helpers/calc.js.map +7 -0
  69. package/dist/esm/helpers/createPropMapper.js +3 -5
  70. package/dist/esm/helpers/createPropMapper.js.map +2 -2
  71. package/dist/esm/helpers/createShallowUpdate.js +20 -0
  72. package/dist/esm/helpers/createShallowUpdate.js.map +7 -0
  73. package/dist/esm/helpers/getFont.js +42 -0
  74. package/dist/esm/helpers/getFont.js.map +7 -0
  75. package/dist/esm/helpers/getSplitStyles.js +24 -24
  76. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  77. package/dist/esm/helpers/getStackSize.js +22 -0
  78. package/dist/esm/helpers/getStackSize.js.map +7 -0
  79. package/dist/esm/helpers/startTransition.js +6 -0
  80. package/dist/esm/helpers/startTransition.js.map +7 -0
  81. package/dist/esm/helpers/timer.js +11 -0
  82. package/dist/esm/helpers/timer.js.map +7 -0
  83. package/dist/esm/helpers/validate.js +1 -0
  84. package/dist/esm/helpers/validate.js.map +7 -0
  85. package/dist/esm/hooks/useConstant.js +15 -0
  86. package/dist/esm/hooks/useConstant.js.map +7 -0
  87. package/dist/esm/hooks/useIsMounted.js +16 -0
  88. package/dist/esm/hooks/useIsMounted.js.map +7 -0
  89. package/dist/esm/hooks/useIsSSR.js +22 -0
  90. package/dist/esm/hooks/useIsSSR.js.map +7 -0
  91. package/dist/esm/hooks/usePressable.js +12 -0
  92. package/dist/esm/hooks/usePressable.js.map +7 -0
  93. package/dist/esm/hooks/useUnmountEffect.js +8 -0
  94. package/dist/esm/hooks/useUnmountEffect.js.map +7 -0
  95. package/dist/esm/injectStyles.js +16 -0
  96. package/dist/esm/injectStyles.js.map +7 -0
  97. package/dist/esm/views/ThemeInverse.js +17 -23
  98. package/dist/esm/views/ThemeInverse.js.map +2 -2
  99. package/dist/esm/views/ThemeReset.js +12 -12
  100. package/dist/esm/views/ThemeReset.js.map +2 -2
  101. package/package.json +11 -11
  102. package/src/createComponent.tsx +15 -35
  103. package/src/createVariable.ts +1 -1
  104. package/src/helpers/ThemeManager.test.tsx +17 -0
  105. package/src/helpers/ThemeManager.tsx +4 -3
  106. package/src/helpers/createPropMapper.ts +4 -5
  107. package/src/helpers/getSplitStyles.tsx +26 -29
  108. package/src/helpers/timer.ts +9 -0
  109. package/types/helpers/timer.d.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.1-beta.227",
3
+ "version": "1.0.1-beta.228",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -28,15 +28,15 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@expo/match-media": "^0.3.0",
31
- "@tamagui/compose-refs": "^1.0.1-beta.227",
32
- "@tamagui/constants": "^1.0.1-beta.227",
33
- "@tamagui/helpers": "^1.0.1-beta.227",
34
- "@tamagui/react-native-use-pressable": "^1.0.1-beta.227",
35
- "@tamagui/react-native-use-responder-events": "^1.0.1-beta.227",
36
- "@tamagui/types-react-native": "^1.0.1-beta.227",
37
- "@tamagui/use-did-finish-ssr": "^1.0.1-beta.227",
38
- "@tamagui/use-event": "^1.0.1-beta.227",
39
- "@tamagui/use-force-update": "^1.0.1-beta.227",
31
+ "@tamagui/compose-refs": "^1.0.1-beta.228",
32
+ "@tamagui/constants": "^1.0.1-beta.228",
33
+ "@tamagui/helpers": "^1.0.1-beta.228",
34
+ "@tamagui/react-native-use-pressable": "^1.0.1-beta.228",
35
+ "@tamagui/react-native-use-responder-events": "^1.0.1-beta.228",
36
+ "@tamagui/types-react-native": "^1.0.1-beta.228",
37
+ "@tamagui/use-did-finish-ssr": "^1.0.1-beta.228",
38
+ "@tamagui/use-event": "^1.0.1-beta.228",
39
+ "@tamagui/use-force-update": "^1.0.1-beta.228",
40
40
  "normalize-css-color": "^1.0.2"
41
41
  },
42
42
  "peerDependencies": {
@@ -44,7 +44,7 @@
44
44
  "react-dom": ">=18"
45
45
  },
46
46
  "devDependencies": {
47
- "@tamagui/build": "^1.0.1-beta.227",
47
+ "@tamagui/build": "^1.0.1-beta.228",
48
48
  "@types/node": "^16.11.9",
49
49
  "@types/react": "^18.0.15",
50
50
  "@types/react-native": "^0.69.2",
@@ -146,8 +146,6 @@ export function createComponent<
146
146
  props = propsIn
147
147
  }
148
148
 
149
- // time`mergeProps`
150
-
151
149
  const debugProp = props['debug'] as DebugProp
152
150
  const { Component, isText, isZStack } = staticConfig
153
151
  const componentName = props.componentName || staticConfig.componentName
@@ -283,8 +281,6 @@ export function createComponent<
283
281
  elementType = Component || elementType
284
282
  const isStringElement = typeof elementType === 'string'
285
283
 
286
- // time`setupStateConf`
287
-
288
284
  const isExiting = presence?.[0] === false
289
285
  const splitStyles = useSplitStyles(
290
286
  props,
@@ -304,8 +300,6 @@ export function createComponent<
304
300
  debugProp
305
301
  )
306
302
 
307
- // time`splitStyles`
308
-
309
303
  const hostRef = useServerRef<TamaguiElement>(null)
310
304
 
311
305
  // animation setup
@@ -369,34 +363,26 @@ export function createComponent<
369
363
  }
370
364
  }
371
365
 
372
- // time`animations`
373
-
374
366
  // media queries
375
367
  useIsomorphicLayoutEffect(() => {
376
- if (!mediaKeys.length) return
377
- const disposers: any[] = []
378
- for (const key of mediaKeys) {
379
- disposers.push(
380
- addMediaQueryListener(key, (next: boolean) => {
381
- setState((prev) => {
382
- if (prev.mediaState![key] !== next) {
383
- return {
384
- ...prev,
385
- mediaState: getMediaStateObject({
386
- ...prev.mediaState,
387
- [key]: next,
388
- }),
389
- }
368
+ const disposers = mediaKeys.map((key) => {
369
+ return addMediaQueryListener(key, (next: boolean) => {
370
+ setState((prev) => {
371
+ if (prev.mediaState![key] !== next) {
372
+ return {
373
+ ...prev,
374
+ mediaState: getMediaStateObject({
375
+ ...prev.mediaState,
376
+ [key]: next,
377
+ }),
390
378
  }
391
- return prev
392
- })
379
+ }
380
+ return prev
393
381
  })
394
- )
395
- }
382
+ })
383
+ })
396
384
  return () => {
397
- for (const disposer of disposers) {
398
- disposer()
399
- }
385
+ disposers.forEach((d) => d())
400
386
  }
401
387
  }, [mediaKeys.join(',')])
402
388
 
@@ -563,8 +549,6 @@ export function createComponent<
563
549
  })
564
550
  }
565
551
 
566
- // time`webHooks`
567
-
568
552
  const unPress = useCallback(() => {
569
553
  setStateShallow({
570
554
  press: false,
@@ -782,8 +766,6 @@ export function createComponent<
782
766
  }
783
767
  : null
784
768
 
785
- // time`events`
786
-
787
769
  let space = spaceProp
788
770
 
789
771
  // find space by media query
@@ -906,8 +888,6 @@ export function createComponent<
906
888
  }
907
889
  }
908
890
 
909
- // time`done`
910
-
911
891
  return content
912
892
  })
913
893
 
@@ -39,7 +39,7 @@ export function variableToString(vrble?: any, getValue = false) {
39
39
  }
40
40
 
41
41
  export function isVariable(v: Variable | any): v is Variable {
42
- return !!(v && v[IS_VAR])
42
+ return v && typeof v === 'object' && IS_VAR in v
43
43
  }
44
44
 
45
45
  export function getVariable(nameOrVariable: Variable | string) {
@@ -477,4 +477,21 @@ describe('ThemeManager', () => {
477
477
  )
478
478
  expect(child.state.name).toBe('dark_yellow_Button')
479
479
  })
480
+
481
+ test(`Component name + name finds one up when component name missing`, () => {
482
+ const parent = new ThemeManager(
483
+ {
484
+ name: 'dark_red_alt1',
485
+ },
486
+ 'root'
487
+ )
488
+ const child = new ThemeManager(
489
+ {
490
+ name: 'alt2',
491
+ componentName: 'Missing',
492
+ },
493
+ parent
494
+ )
495
+ expect(child.state.name).toBe('dark_red_alt2')
496
+ })
480
497
  })
@@ -176,9 +176,10 @@ function getState(
176
176
  ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)
177
177
  : parentName
178
178
  const max = base.length
179
- const min = componentName
180
- ? max // component themes don't search upwards
181
- : 0
179
+ const min =
180
+ componentName && !nextName
181
+ ? max // component name only don't search upwards
182
+ : 0
182
183
 
183
184
  // prettier-ignore
184
185
  // eslint-disable-next-line no-console
@@ -35,6 +35,8 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
35
35
  // temp remove classnames
36
36
  const defaultProps = mergeProps(staticConfig.defaultProps || {}, {}, false)[0]
37
37
 
38
+ let conf: TamaguiInternalConfig
39
+
38
40
  const mapper: PropMapper = (
39
41
  key,
40
42
  value,
@@ -45,10 +47,7 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
45
47
  avoidDefaultProps = false,
46
48
  debug
47
49
  ) => {
48
- const conf = getConfig()
49
- if (!conf) {
50
- throw new Error(`No tamagui config setup`)
51
- }
50
+ conf ||= getConfig()
52
51
 
53
52
  const props = state.fallbackProps || propsIn
54
53
  const returnVariablesAs = getReturnVariablesAs(props, state)
@@ -85,7 +84,7 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
85
84
  let shouldReturn = value !== undefined && value !== null
86
85
 
87
86
  // handle shorthands
88
- if (conf.shorthands[key]) {
87
+ if (key in conf.shorthands) {
89
88
  shouldReturn = true
90
89
  key = conf.shorthands[key]
91
90
  }
@@ -204,6 +204,16 @@ export const getSplitStyles: StyleSplitter = (
204
204
  debug
205
205
  ) => {
206
206
  conf = conf || getConfig()
207
+ const { shorthands } = conf
208
+ const {
209
+ defaultVariants,
210
+ variants,
211
+ propMapper,
212
+ isReactNative,
213
+ deoptProps,
214
+ inlineProps,
215
+ inlineWhenUnflattened,
216
+ } = staticConfig
207
217
  const validStyleProps = staticConfig.isText ? stylePropsText : validStyles
208
218
  const mediaKeys: string[] = []
209
219
  const viewProps: GetStyleResult['viewProps'] = {}
@@ -252,7 +262,7 @@ export const getSplitStyles: StyleSplitter = (
252
262
  const isMedia = mediaOrPseudo[0] === '_'
253
263
  const isPseudo = mediaOrPseudo[0] === '0'
254
264
  const isMediaOrPseudo = isMedia || isPseudo
255
- let fullKey = conf.shorthands[shorthand]
265
+ let fullKey = shorthands[shorthand]
256
266
  if (isMedia) {
257
267
  // is media
258
268
  let mediaShortKey = mediaOrPseudo.slice(1)
@@ -286,13 +296,13 @@ export const getSplitStyles: StyleSplitter = (
286
296
  const valInit = props[keyInit]
287
297
 
288
298
  // normalize shorthands up front
289
- const expandedKey = conf.shorthands[keyInit]
299
+ const expandedKey = keyInit in shorthands
290
300
  if (expandedKey) {
291
- keyInit = expandedKey
301
+ keyInit = shorthands[keyInit]
292
302
  }
293
303
 
294
- if (usedKeys[keyInit]) continue
295
- if (skipProps[keyInit]) continue
304
+ if (keyInit in usedKeys) continue
305
+ if (keyInit in skipProps) continue
296
306
  if (!isWeb && keyInit.startsWith('data-')) continue
297
307
 
298
308
  if (validStyleProps[keyInit] || keyInit.includes('-')) {
@@ -341,14 +351,14 @@ export const getSplitStyles: StyleSplitter = (
341
351
  ) {
342
352
  viewProps.disabled = true
343
353
  }
344
- if (!staticConfig.variants?.disabled) {
354
+ if (!variants?.disabled) {
345
355
  continue
346
356
  }
347
357
  }
348
358
 
349
359
  if (keyInit === 'testID') {
350
360
  usedKeys[keyInit] = 1
351
- if (staticConfig.isReactNative) {
361
+ if (isReactNative) {
352
362
  viewProps.testId = valInit
353
363
  } else {
354
364
  viewProps['data-testid'] = valInit
@@ -358,7 +368,7 @@ export const getSplitStyles: StyleSplitter = (
358
368
 
359
369
  if (keyInit === 'id' || keyInit === 'nativeID') {
360
370
  usedKeys[keyInit] = 1
361
- if (staticConfig.isReactNative) {
371
+ if (isReactNative) {
362
372
  viewProps.nativeID = valInit
363
373
  } else {
364
374
  viewProps.id = valInit
@@ -368,7 +378,7 @@ export const getSplitStyles: StyleSplitter = (
368
378
 
369
379
  let didUseKeyInit = true
370
380
 
371
- if (staticConfig.isReactNative) {
381
+ if (isReactNative) {
372
382
  didUseKeyInit = false
373
383
  // pass along to react-native-web
374
384
  if (accessibilityDirectMap[keyInit] || keyInit.startsWith('accessibility')) {
@@ -468,10 +478,10 @@ export const getSplitStyles: StyleSplitter = (
468
478
  }
469
479
 
470
480
  if (
471
- (staticConfig.defaultVariants && keyInit in staticConfig.defaultVariants) ||
481
+ (defaultVariants && keyInit in defaultVariants) ||
472
482
  // may want to just: not compile styled() into classnames, always do this, and always pass in all values in extras.props
473
483
  // but we'd want to add styled({ extracted: true }) or something at compile time to save on parsing a bit...
474
- (state.keepVariantsAsProps && staticConfig.variants && keyInit in staticConfig.variants)
484
+ (state.keepVariantsAsProps && variants && keyInit in variants)
475
485
  ) {
476
486
  viewProps[keyInit] = valInit
477
487
  }
@@ -489,9 +499,9 @@ export const getSplitStyles: StyleSplitter = (
489
499
  if (
490
500
  !isMedia &&
491
501
  !isPseudo &&
492
- !staticConfig.variants?.[keyInit] &&
502
+ !variants?.[keyInit] &&
493
503
  !validStyleProps[keyInit] &&
494
- !conf.shorthands[keyInit]
504
+ !shorthands[keyInit]
495
505
  ) {
496
506
  // web-only, exclude all other accessibility props not handled above
497
507
  if (isWeb && keyInit.includes('ccessibility')) {
@@ -510,16 +520,7 @@ export const getSplitStyles: StyleSplitter = (
510
520
  const expanded =
511
521
  isMedia || isPseudo
512
522
  ? [[keyInit, valInit]]
513
- : staticConfig.propMapper(
514
- keyInit,
515
- valInit,
516
- theme,
517
- props,
518
- state,
519
- languageContext,
520
- undefined,
521
- debug
522
- )
523
+ : propMapper(keyInit, valInit, theme, props, state, languageContext, undefined, debug)
523
524
 
524
525
  if (!fontFamily) {
525
526
  fontFamily = getPropMappedFontFamily(expanded)
@@ -547,11 +548,7 @@ export const getSplitStyles: StyleSplitter = (
547
548
  continue
548
549
  }
549
550
 
550
- if (
551
- staticConfig.deoptProps?.has(key) ||
552
- staticConfig.inlineProps?.has(key) ||
553
- staticConfig.inlineWhenUnflattened?.has(key)
554
- ) {
551
+ if (deoptProps?.has(key) || inlineProps?.has(key) || inlineWhenUnflattened?.has(key)) {
555
552
  usedKeys[key] = 1
556
553
  viewProps[key] = props[key] ?? val
557
554
  }
@@ -689,7 +686,7 @@ export const getSplitStyles: StyleSplitter = (
689
686
  }
690
687
 
691
688
  // pass to view props
692
- if (!staticConfig.variants || !(key in staticConfig.variants)) {
689
+ if (!variants || !(key in variants)) {
693
690
  if (!skipProps[key]) {
694
691
  viewProps[key] = val
695
692
  usedKeys[key] = 1
@@ -0,0 +1,9 @@
1
+ const timer = require('@tamagui/timer').timer()
2
+
3
+ setTimeout(() => {
4
+ timer.print()
5
+ }, 2000)
6
+
7
+ export const time = timer.start({
8
+ quiet: true,
9
+ })
@@ -0,0 +1,2 @@
1
+ export declare const time: any;
2
+ //# sourceMappingURL=timer.d.ts.map