@tamagui/core 1.0.1-rc.1 → 1.0.1-rc.1.2

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.
@@ -43,9 +43,13 @@ export const getInitialMediaState = () => {
43
43
  }
44
44
 
45
45
  let mediaKeysOrdered: string[]
46
- export const getMediaKeyImportance = (key: string) =>
46
+ export const getMediaKeyImportance = (key: string) => {
47
+ if (process.env.NODE_ENV === 'development' && key[0] === '$') {
48
+ throw new Error(`use short key`)
49
+ }
47
50
  // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1
48
- mediaKeysOrdered.indexOf(key[0] === '$' ? key.slice(1) : key) + 2
51
+ return mediaKeysOrdered.indexOf(key) + 2
52
+ }
49
53
 
50
54
  const dispose = new Set<Function>()
51
55
 
@@ -78,9 +82,7 @@ let configuredKey = ''
78
82
  function setupMediaListeners() {
79
83
  // avoid setting up more than once per config
80
84
  const nextKey = JSON.stringify(mediaQueryConfig)
81
- if (nextKey === configuredKey) {
82
- return
83
- }
85
+ if (nextKey === configuredKey) return
84
86
  configuredKey = nextKey
85
87
 
86
88
  // hmr, undo existing before re-binding
@@ -221,18 +223,17 @@ export function useMediaPropsActive<A extends Object>(
221
223
  const key = propNames[i]
222
224
  const val = props[key]
223
225
  if (key[0] === '$') {
224
- if (!media[key.slice(1)]) {
225
- continue
226
- }
226
+ const mediaKey = key.slice(1)
227
+ if (!media[mediaKey]) continue
227
228
  if (val && typeof val === 'object') {
228
229
  const subKeys = Object.keys(val)
229
230
  for (let j = subKeys.length; j--; j >= 0) {
230
231
  const subKey = subKeys[j]
231
- mergeMediaByImportance(next, subKey, val[subKey], importancesUsed)
232
+ mergeMediaByImportance(next, mediaKey, subKey, val[subKey], importancesUsed)
232
233
  }
233
234
  }
234
235
  } else {
235
- mergeMediaByImportance(next, key, val, importancesUsed)
236
+ mergeMediaByImportance(next, '', key, val, importancesUsed)
236
237
  }
237
238
  }
238
239
 
@@ -241,20 +242,22 @@ export function useMediaPropsActive<A extends Object>(
241
242
  }
242
243
 
243
244
  export const getMediaImportanceIfMoreImportant = (
245
+ mediaKey: string,
244
246
  key: string,
245
247
  importancesUsed: Record<string, number>
246
248
  ) => {
247
- const importance = getMediaKeyImportance(key)
249
+ const importance = getMediaKeyImportance(mediaKey)
248
250
  return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null
249
251
  }
250
252
 
251
253
  export function mergeMediaByImportance(
252
254
  onto: Record<string, any>,
255
+ mediaKey: string,
253
256
  key: string,
254
257
  value: any,
255
258
  importancesUsed: Record<string, number>
256
259
  ) {
257
- const importance = getMediaImportanceIfMoreImportant(key, importancesUsed)
260
+ const importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed)
258
261
  if (importance === null) {
259
262
  return false
260
263
  }
@@ -21,8 +21,8 @@ export declare function useMedia(): UseMediaState;
21
21
  export declare function useMediaPropsActive<A extends Object>(props: A): {
22
22
  [Key in keyof A extends `$${string}` ? never : keyof A]?: A[Key];
23
23
  };
24
- export declare const getMediaImportanceIfMoreImportant: (key: string, importancesUsed: Record<string, number>) => number | null;
25
- export declare function mergeMediaByImportance(onto: Record<string, any>, key: string, value: any, importancesUsed: Record<string, number>): boolean;
24
+ export declare const getMediaImportanceIfMoreImportant: (mediaKey: string, key: string, importancesUsed: Record<string, number>) => number | null;
25
+ export declare function mergeMediaByImportance(onto: Record<string, any>, mediaKey: string, key: string, value: any, importancesUsed: Record<string, number>): boolean;
26
26
  export declare function mediaObjectToString(query: string | MediaQueryObject): string;
27
27
  export {};
28
28
  //# sourceMappingURL=useMedia.d.ts.map