@tamagui/web 2.3.3 → 2.4.0
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/.turbo/turbo-build.log +1 -1
- package/dist/cjs/createComponent.native.js +1 -1
- package/dist/cjs/createComponent.native.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.cjs +5 -0
- package/dist/cjs/helpers/getSplitStyles.native.js +9 -0
- package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/cjs/helpers/pointerEvents.native.js +26 -20
- package/dist/cjs/helpers/pointerEvents.native.js.map +1 -1
- package/dist/cjs/hooks/useComponentState.cjs +25 -1
- package/dist/cjs/hooks/useComponentState.native.js +25 -1
- package/dist/cjs/hooks/useComponentState.native.js.map +1 -1
- package/dist/cjs/hooks/useMedia.cjs +107 -42
- package/dist/cjs/hooks/useMedia.native.js +149 -60
- package/dist/cjs/hooks/useMedia.native.js.map +1 -1
- package/dist/cjs/hooks/useTheme.cjs +17 -4
- package/dist/cjs/hooks/useTheme.native.js +18 -4
- package/dist/cjs/hooks/useTheme.native.js.map +1 -1
- package/dist/cjs/hooks/useThemeState.cjs +132 -67
- package/dist/cjs/hooks/useThemeState.native.js +144 -70
- package/dist/cjs/hooks/useThemeState.native.js.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.native.js +2 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/views/Theme.cjs +1 -1
- package/dist/cjs/views/Theme.native.js +1 -1
- package/dist/cjs/views/Theme.native.js.map +1 -1
- package/dist/esm/createComponent.native.js +2 -2
- package/dist/esm/createComponent.native.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.mjs +5 -0
- package/dist/esm/helpers/getSplitStyles.mjs.map +1 -1
- package/dist/esm/helpers/getSplitStyles.native.js +9 -0
- package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/esm/helpers/pointerEvents.native.js +26 -20
- package/dist/esm/helpers/pointerEvents.native.js.map +1 -1
- package/dist/esm/hooks/useComponentState.mjs +26 -2
- package/dist/esm/hooks/useComponentState.mjs.map +1 -1
- package/dist/esm/hooks/useComponentState.native.js +26 -2
- package/dist/esm/hooks/useComponentState.native.js.map +1 -1
- package/dist/esm/hooks/useMedia.mjs +108 -43
- package/dist/esm/hooks/useMedia.mjs.map +1 -1
- package/dist/esm/hooks/useMedia.native.js +150 -61
- package/dist/esm/hooks/useMedia.native.js.map +1 -1
- package/dist/esm/hooks/useTheme.mjs +17 -4
- package/dist/esm/hooks/useTheme.mjs.map +1 -1
- package/dist/esm/hooks/useTheme.native.js +18 -4
- package/dist/esm/hooks/useTheme.native.js.map +1 -1
- package/dist/esm/hooks/useThemeState.mjs +133 -68
- package/dist/esm/hooks/useThemeState.mjs.map +1 -1
- package/dist/esm/hooks/useThemeState.native.js +145 -71
- package/dist/esm/hooks/useThemeState.native.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +3 -3
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/views/Theme.mjs +1 -1
- package/dist/esm/views/Theme.mjs.map +1 -1
- package/dist/esm/views/Theme.native.js +1 -1
- package/dist/esm/views/Theme.native.js.map +1 -1
- package/package.json +13 -13
- package/src/createComponent.tsx +8 -2
- package/src/helpers/getSplitStyles.tsx +33 -0
- package/src/helpers/pointerEvents.native.ts +26 -19
- package/src/hooks/useComponentState.ts +39 -2
- package/src/hooks/useMedia.tsx +147 -42
- package/src/hooks/useTheme.tsx +27 -5
- package/src/hooks/useThemeState.ts +263 -137
- package/src/index.ts +7 -1
- package/src/types.tsx +53 -5
- package/src/views/Theme.tsx +4 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/pointerEvents.native.d.ts.map +1 -1
- package/types/hooks/useComponentState.d.ts +1 -1
- package/types/hooks/useComponentState.d.ts.map +1 -1
- package/types/hooks/useMedia.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/hooks/useThemeState.d.ts +1 -1
- package/types/hooks/useThemeState.d.ts.map +1 -1
- package/types/index.d.ts +2 -2
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +3 -1
- package/types/types.d.ts.map +1 -1
- package/types/views/Theme.d.ts.map +1 -1
|
@@ -79,6 +79,7 @@ var configureMedia = function (config) {
|
|
|
79
79
|
if (!media) return;
|
|
80
80
|
mediaVersion++;
|
|
81
81
|
(0, import_createMediaStyle.resetMediaStyleCache)();
|
|
82
|
+
resetMediaTouchTracker();
|
|
82
83
|
for (var key in media) {
|
|
83
84
|
(0, import_mediaState.getMedia)()[key] = (mediaQueryDefaultActive === null || mediaQueryDefaultActive === void 0 ? void 0 : mediaQueryDefaultActive[key]) || false;
|
|
84
85
|
import_mediaState.mediaKeys.add(`$${key}`);
|
|
@@ -136,6 +137,53 @@ function updateMediaListeners() {
|
|
|
136
137
|
});
|
|
137
138
|
}
|
|
138
139
|
var States = /* @__PURE__ */new WeakMap();
|
|
140
|
+
var touchTrackerProto = null;
|
|
141
|
+
var refSlot = /* @__PURE__ */Symbol("mediaRefSlot");
|
|
142
|
+
function buildTouchTrackerProto() {
|
|
143
|
+
var proto = {};
|
|
144
|
+
var _iteratorNormalCompletion = true,
|
|
145
|
+
_didIteratorError = false,
|
|
146
|
+
_iteratorError = void 0;
|
|
147
|
+
try {
|
|
148
|
+
var _loop = function () {
|
|
149
|
+
var fullKey = _step.value;
|
|
150
|
+
var key = fullKey[0] === "$" ? fullKey.slice(1) : fullKey;
|
|
151
|
+
proto[key] = {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
configurable: true,
|
|
154
|
+
get() {
|
|
155
|
+
var slot = this[refSlot];
|
|
156
|
+
if (!disableMediaTouch) {
|
|
157
|
+
slot.keys.add(key);
|
|
158
|
+
}
|
|
159
|
+
return slot.proxyTarget[key];
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
for (var _iterator = import_mediaState.mediaKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _loop();
|
|
164
|
+
} catch (err) {
|
|
165
|
+
_didIteratorError = true;
|
|
166
|
+
_iteratorError = err;
|
|
167
|
+
} finally {
|
|
168
|
+
try {
|
|
169
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
170
|
+
_iterator.return();
|
|
171
|
+
}
|
|
172
|
+
} finally {
|
|
173
|
+
if (_didIteratorError) {
|
|
174
|
+
throw _iteratorError;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return Object.create(null, proto);
|
|
179
|
+
}
|
|
180
|
+
function getTouchTrackerProto() {
|
|
181
|
+
if (!touchTrackerProto) touchTrackerProto = buildTouchTrackerProto();
|
|
182
|
+
return touchTrackerProto;
|
|
183
|
+
}
|
|
184
|
+
function resetMediaTouchTracker() {
|
|
185
|
+
touchTrackerProto = null;
|
|
186
|
+
}
|
|
139
187
|
function setMediaShouldUpdate(ref, enabled, keys) {
|
|
140
188
|
var cur = States.get(ref);
|
|
141
189
|
if (!cur || cur.enabled !== enabled || keys) {
|
|
@@ -155,80 +203,121 @@ function subscribe(subscriber) {
|
|
|
155
203
|
function useMedia(componentContext, debug) {
|
|
156
204
|
"use no memo";
|
|
157
205
|
|
|
158
|
-
var componentState = componentContext ? States.get(componentContext) : null;
|
|
159
206
|
var internalRef = (0, import_react.useRef)(null);
|
|
160
207
|
if (!internalRef.current) {
|
|
161
|
-
|
|
208
|
+
var initial = (0, import_mediaState.getMedia)();
|
|
209
|
+
var r = {
|
|
162
210
|
keys: /* @__PURE__ */new Set(),
|
|
163
|
-
lastState:
|
|
211
|
+
lastState: initial,
|
|
212
|
+
renderVersion: 0,
|
|
213
|
+
proxyTarget: initial,
|
|
214
|
+
proxy: void 0,
|
|
215
|
+
getSnapshot: void 0,
|
|
216
|
+
componentContext,
|
|
217
|
+
debug
|
|
164
218
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
pendingState
|
|
181
|
-
} = internalRef.current;
|
|
182
|
-
if (!curKeys.size) {
|
|
183
|
-
return lastState;
|
|
184
|
-
}
|
|
185
|
-
var ms = (0, import_mediaState.getMedia)();
|
|
186
|
-
var _iteratorNormalCompletion = true,
|
|
187
|
-
_didIteratorError = false,
|
|
188
|
-
_iteratorError = void 0;
|
|
189
|
-
try {
|
|
190
|
-
for (var _iterator = curKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
191
|
-
var key = _step.value;
|
|
192
|
-
if (ms[key] !== (pendingState || lastState)[key]) {
|
|
193
|
-
if (process.env.NODE_ENV === "development" && debug) {
|
|
194
|
-
console.warn(`useMedia() \u270D\uFE0F`, key, lastState[key], "=>", ms[key]);
|
|
195
|
-
}
|
|
196
|
-
if (componentContext === null || componentContext === void 0 ? void 0 : componentContext.mediaEmit) {
|
|
197
|
-
componentContext.mediaEmit(ms);
|
|
198
|
-
internalRef.current.pendingState = ms;
|
|
199
|
-
return lastState;
|
|
200
|
-
}
|
|
201
|
-
internalRef.current.lastState = ms;
|
|
202
|
-
return ms;
|
|
203
|
-
}
|
|
219
|
+
var tracker = Object.create(getTouchTrackerProto());
|
|
220
|
+
tracker[refSlot] = {
|
|
221
|
+
proxyTarget: initial,
|
|
222
|
+
keys: r.keys
|
|
223
|
+
};
|
|
224
|
+
r.proxy = tracker;
|
|
225
|
+
r.getSnapshot = function () {
|
|
226
|
+
var _States_get;
|
|
227
|
+
var curKeys = r.componentContext ? ((_States_get = States.get(r.componentContext)) === null || _States_get === void 0 ? void 0 : _States_get.keys) || r.keys : r.keys;
|
|
228
|
+
var {
|
|
229
|
+
lastState,
|
|
230
|
+
pendingState
|
|
231
|
+
} = r;
|
|
232
|
+
if (!curKeys.size) {
|
|
233
|
+
return lastState;
|
|
204
234
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
235
|
+
var ms = (0, import_mediaState.getMedia)();
|
|
236
|
+
var _iteratorNormalCompletion = true,
|
|
237
|
+
_didIteratorError = false,
|
|
238
|
+
_iteratorError = void 0;
|
|
209
239
|
try {
|
|
210
|
-
|
|
211
|
-
|
|
240
|
+
for (var _iterator = curKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
241
|
+
var key = _step.value;
|
|
242
|
+
if (ms[key] !== (pendingState || lastState)[key]) {
|
|
243
|
+
var _r_componentContext;
|
|
244
|
+
if (process.env.NODE_ENV === "development" && r.debug) {
|
|
245
|
+
console.warn(`useMedia() \u270D\uFE0F`, key, lastState[key], "=>", ms[key]);
|
|
246
|
+
}
|
|
247
|
+
if ((_r_componentContext = r.componentContext) === null || _r_componentContext === void 0 ? void 0 : _r_componentContext.mediaEmit) {
|
|
248
|
+
r.componentContext.mediaEmit(ms);
|
|
249
|
+
r.pendingState = ms;
|
|
250
|
+
return lastState;
|
|
251
|
+
}
|
|
252
|
+
r.lastState = ms;
|
|
253
|
+
return ms;
|
|
254
|
+
}
|
|
212
255
|
}
|
|
256
|
+
} catch (err) {
|
|
257
|
+
_didIteratorError = true;
|
|
258
|
+
_iteratorError = err;
|
|
213
259
|
} finally {
|
|
214
|
-
|
|
215
|
-
|
|
260
|
+
try {
|
|
261
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
262
|
+
_iterator.return();
|
|
263
|
+
}
|
|
264
|
+
} finally {
|
|
265
|
+
if (_didIteratorError) {
|
|
266
|
+
throw _iteratorError;
|
|
267
|
+
}
|
|
216
268
|
}
|
|
217
269
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
270
|
+
return lastState;
|
|
271
|
+
};
|
|
272
|
+
internalRef.current = r;
|
|
273
|
+
} else {
|
|
274
|
+
internalRef.current.componentContext = componentContext;
|
|
275
|
+
internalRef.current.debug = debug;
|
|
276
|
+
}
|
|
277
|
+
var ref = internalRef.current;
|
|
278
|
+
ref.renderVersion++;
|
|
279
|
+
if (ref.pendingState) {
|
|
280
|
+
ref.lastState = ref.pendingState;
|
|
281
|
+
ref.pendingState = void 0;
|
|
282
|
+
}
|
|
283
|
+
if (ref.keys.size) {
|
|
284
|
+
ref.keys.clear();
|
|
285
|
+
}
|
|
286
|
+
var [, forceUpdate] = (0, import_react.useReducer)(incReducer, 0);
|
|
287
|
+
var state = import_constants.isServer ? initState : ref.getSnapshot();
|
|
288
|
+
ref.proxyTarget = state;
|
|
289
|
+
ref.proxy[refSlot].proxyTarget = state;
|
|
290
|
+
(0, import_react.useEffect)(function () {
|
|
291
|
+
var _States_get;
|
|
292
|
+
var renderVersion = ref.renderVersion;
|
|
293
|
+
var shouldSubscribe = !ref.componentContext || !!((_States_get = States.get(ref.componentContext)) === null || _States_get === void 0 ? void 0 : _States_get.enabled);
|
|
294
|
+
if (shouldSubscribe) {
|
|
295
|
+
if (!ref.unsubscribe) {
|
|
296
|
+
ref.unsubscribe = subscribe(function () {
|
|
297
|
+
var next = ref.getSnapshot();
|
|
298
|
+
if (next !== ref.proxyTarget) {
|
|
299
|
+
ref.proxyTarget = next;
|
|
300
|
+
ref.proxy[refSlot].proxyTarget = next;
|
|
301
|
+
forceUpdate();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
225
304
|
}
|
|
226
|
-
|
|
305
|
+
} else if (ref.unsubscribe) {
|
|
306
|
+
ref.unsubscribe();
|
|
307
|
+
ref.unsubscribe = void 0;
|
|
227
308
|
}
|
|
309
|
+
return function () {
|
|
310
|
+
if (ref.renderVersion === renderVersion) {
|
|
311
|
+
var _ref_unsubscribe;
|
|
312
|
+
(_ref_unsubscribe = ref.unsubscribe) === null || _ref_unsubscribe === void 0 ? void 0 : _ref_unsubscribe.call(ref);
|
|
313
|
+
ref.unsubscribe = void 0;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
228
316
|
});
|
|
317
|
+
return ref.proxy;
|
|
229
318
|
}
|
|
230
|
-
var
|
|
231
|
-
return
|
|
319
|
+
var incReducer = function (c) {
|
|
320
|
+
return c + 1;
|
|
232
321
|
};
|
|
233
322
|
var disableMediaTouch = false;
|
|
234
323
|
function _disableMediaTouch(val) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useMedia_exports","__export","_disableMediaTouch","configureMedia","getMediaImportanceIfMoreImportant","getMediaKey","getMediaKeyImportance","getMediaState","isMediaKey","mediaKeyMatch","mediaKeyToQuery","setMediaShouldUpdate","setupMediaListeners","updateMediaListeners","useMedia","module","exports","import_constants","require","import_react","import_config","import_createMediaStyle","import_matchMedia","import_mediaObjectToString","import_mediaState","import_pseudoDescriptors","mediaKeyRegex","key","mediaKeys","has","test","match","initState","mediaKeysOrdered","process","env","NODE_ENV","Error","indexOf","dispose","Set","mediaVersion","config","media","mediaQueryDefaultActive","getSetting","resetMediaStyleCache","getMedia","add","Object","assign","mediaQueryConfig","keys","unlisten","forEach","cb","clear","setupVersion","_loop","key2","str","mediaObjectToString","getMatch","matchMedia","addListener","update","removeListener","next","matches","setMediaState","isWeb","isServer","IS_STATIC","listeners","States","WeakMap","
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useMedia_exports","__export","_disableMediaTouch","configureMedia","getMediaImportanceIfMoreImportant","getMediaKey","getMediaKeyImportance","getMediaState","isMediaKey","mediaKeyMatch","mediaKeyToQuery","setMediaShouldUpdate","setupMediaListeners","updateMediaListeners","useMedia","module","exports","import_constants","require","import_react","import_config","import_createMediaStyle","import_matchMedia","import_mediaObjectToString","import_mediaState","import_pseudoDescriptors","mediaKeyRegex","key","mediaKeys","has","test","match","initState","mediaKeysOrdered","process","env","NODE_ENV","Error","indexOf","dispose","Set","mediaVersion","config","media","mediaQueryDefaultActive","getSetting","resetMediaStyleCache","resetMediaTouchTracker","getMedia","add","Object","assign","mediaQueryConfig","keys","unlisten","forEach","cb","clear","setupVersion","_loop","key2","str","mediaObjectToString","getMatch","matchMedia","addListener","update","removeListener","next","matches","setMediaState","isWeb","isServer","IS_STATIC","listeners","States","WeakMap","touchTrackerProto","refSlot","Symbol","buildTouchTrackerProto","proto","_iteratorNormalCompletion","_didIteratorError","_iteratorError","fullKey","_step","slice","enumerable","configurable","get","slot","disableMediaTouch","proxyTarget","_iterator","iterator","done","err","return","create","getTouchTrackerProto","ref","enabled","cur","set","subscribe","subscriber","delete","componentContext","debug","internalRef","useRef","current","initial","r","lastState","renderVersion","proxy","getSnapshot","tracker","_States_get","curKeys","pendingState","size","ms","_r_componentContext","console","warn","mediaEmit","forceUpdate","useReducer","incReducer","state","useEffect","shouldSubscribe","unsubscribe"],"sources":["../../../src/hooks/useMedia.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA,kBAAA;EAAAC,cAAA,EAAAA,CAAA,KAAAA,cAAA;EAAAC,iCAAA,EAAAA,CAAA,KAAAA,iCAAA;EAAAC,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAA,qBAAA;EAAAC,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,UAAA,EAAAA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WithState = (props, isRoot = false) => {
|
|
40
|
+
const useThemeWithState = (props, isRoot = false, forThemeView = false) => {
|
|
41
41
|
"use no memo";
|
|
42
42
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const bag = (0, import_react.useRef)(null);
|
|
44
|
+
if (!bag.current) {
|
|
45
|
+
bag.current = {
|
|
46
|
+
keys: {
|
|
47
|
+
current: null
|
|
48
|
+
},
|
|
49
|
+
schemeKeys: {
|
|
50
|
+
current: null
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const {
|
|
55
|
+
keys,
|
|
56
|
+
schemeKeys
|
|
57
|
+
} = bag.current;
|
|
58
|
+
const themeState = (0, import_useThemeState.useThemeState)(props, isRoot, keys, schemeKeys, forThemeView);
|
|
46
59
|
if (process.env.NODE_ENV === "development") {
|
|
47
60
|
if (!props.passThrough && !themeState?.theme) {
|
|
48
61
|
if (process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1") {
|
|
@@ -42,10 +42,24 @@ var useTheme = function () {
|
|
|
42
42
|
var useThemeWithState = function (props) {
|
|
43
43
|
"use no memo";
|
|
44
44
|
|
|
45
|
-
var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
45
|
+
var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false,
|
|
46
|
+
forThemeView = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
47
|
+
var bag = (0, import_react.useRef)(null);
|
|
48
|
+
if (!bag.current) {
|
|
49
|
+
bag.current = {
|
|
50
|
+
keys: {
|
|
51
|
+
current: null
|
|
52
|
+
},
|
|
53
|
+
schemeKeys: {
|
|
54
|
+
current: null
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var {
|
|
59
|
+
keys,
|
|
60
|
+
schemeKeys
|
|
61
|
+
} = bag.current;
|
|
62
|
+
var themeState = (0, import_useThemeState.useThemeState)(props, isRoot, keys, schemeKeys, forThemeView);
|
|
49
63
|
if (process.env.NODE_ENV === "development") {
|
|
50
64
|
if (!props.passThrough && !(themeState === null || themeState === void 0 ? void 0 : themeState.theme)) {
|
|
51
65
|
if (process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useTheme_exports","__export","useTheme","useThemeWithState","module","exports","import_react","require","import_getThemeProxied","import_useThemeState","EMPTY","theme","res","props","isRoot","arguments","length","
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useTheme_exports","__export","useTheme","useThemeWithState","module","exports","import_react","require","import_getThemeProxied","import_useThemeState","EMPTY","theme","res","props","isRoot","arguments","length","forThemeView","bag","useRef","current","keys","schemeKeys","themeState","useThemeState","process","env","NODE_ENV","passThrough","TAMAGUI_DISABLE_NO_THEME_WARNING","console","error","JSON","stringify","themeProxied","getThemeProxied"],"sources":["../../../src/hooks/useTheme.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA,QAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAA8C,CAAAK,gBAAA;AAE9C,IAAAM,YAAA,GAAAC,OAAA,QAAmD;AACnD,IAAAC,sBAAA,GAA8BD,OAAA;AAE9B,IAAAE,oBAAe,GAAAF,OAAA;AAOR,IAAAG,KAAM;AACX,IAAAR,QAAA,YAAAA,CAAA;EAEA,aAAY;;EACZ,KAAAS,KAAM,IAAMR,iBAAA,CAAAO,KAAA;EACZ,IAAAE,GAAO,GAAAD,KAAA;EACT,OAAAC,GAAA;AAOO;AAYL,IAAAT,iBAAA,YAAAA,CAAAU,KAAA;EAKA,aAAM;;EACN,IAAIC,MAAK,GAAAC,SAAS,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;IAAAE,YAAA,GAAAF,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAChB,IAAAG,GAAI,OAAAZ,YAAU,CAAAa,MAAA;EAAA,IACZ,CAAAD,GAAA,CAAAE,OAAQ;IAAcF,GACtB,CAAAE,OAAA,GAAY;MACdC,IAAA;QACFD,OAAA;MACA;MACAE,UAAM;QAEFF,OAAQ;MACV;IACE;EACE;EAAQ;IAAAC,IACN;IAAAC;EAAA,IAAAJ,GAAA,CAAAE,OAAA;EAAgG,IAAAG,UAC9F,OAAAd,oBAAA,CAAAe,aAAA,EAAAX,KAAA,EAAAC,MAAA,EAAAO,IAAA,EAAAC,UAAA,EAAAL,YAAA;EAAA,IAAAQ,OACD,CAAAC,GAAA,CAAAC,QAAA;IAAA,KAAAd,KAAA,CAAAe,WAAA,MAAAL,UAAA,aAAAA,UAAA,uBAAAA,UAAA,CAAAZ,KAAA;MAAA,IAAAc,OAAA,CAAAC,GAAA,CAAAG,gCAAA;QACHC,OAAA,CAAAC,KAAA,4FAAAC,IAAA,CAAAC,SAAA,CAAApB,KAAA;AAAA;AACF,sKACF;MACF;IAEA;EAIA;EACF,IAAAqB,YAAA,GAAArB,KAAA,CAAAe,WAAA,YAAApB,sBAAA,CAAA2B,eAAA,EAAAtB,KAAA,EAAAU,UAAA,EAAAF,IAAA,EAAAC,UAAA","ignoreList":[]}
|
|
@@ -56,7 +56,8 @@ let themeNameCacheVer = -1;
|
|
|
56
56
|
let themes = null;
|
|
57
57
|
let rootThemeState = null;
|
|
58
58
|
const getRootThemeState = () => rootThemeState;
|
|
59
|
-
const
|
|
59
|
+
const incReducer = c => c + 1;
|
|
60
|
+
const useThemeState = (props, isRoot = false, keys, schemeKeys, cascadeOnChange = false) => {
|
|
60
61
|
"use no memo";
|
|
61
62
|
|
|
62
63
|
const {
|
|
@@ -72,69 +73,68 @@ Looked for theme${props.name ? ` "${props.name}"` : ""}${props.componentName ? `
|
|
|
72
73
|
theme: (0, import_config.getConfig)().themes.light
|
|
73
74
|
};
|
|
74
75
|
const id = (0, import_react.useId)();
|
|
75
|
-
const subscribe = (0, import_react.useCallback)(cb => {
|
|
76
|
-
listenersByParent[parentId] = listenersByParent[parentId] || /* @__PURE__ */new Set();
|
|
77
|
-
listenersByParent[parentId].add(id);
|
|
78
|
-
allListeners.set(id, () => {
|
|
79
|
-
PendingUpdate.set(id, shouldForce ? "force" : true);
|
|
80
|
-
cb();
|
|
81
|
-
});
|
|
82
|
-
return () => {
|
|
83
|
-
allListeners.delete(id);
|
|
84
|
-
listenersByParent[parentId].delete(id);
|
|
85
|
-
localStates.delete(id);
|
|
86
|
-
states.delete(id);
|
|
87
|
-
PendingUpdate.delete(id);
|
|
88
|
-
};
|
|
89
|
-
}, [id, parentId]);
|
|
90
76
|
const propsKey = getPropsKey(props);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (process.env.NODE_ENV === "development" && props.debug === "verbose") {
|
|
111
|
-
console.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, ">", next.name);
|
|
112
|
-
console.info({
|
|
113
|
-
props,
|
|
114
|
-
propsKey,
|
|
115
|
-
isRoot,
|
|
116
|
-
parentId,
|
|
117
|
-
local,
|
|
118
|
-
next,
|
|
119
|
-
needsUpdate,
|
|
120
|
-
isSchemeOnlyChange,
|
|
121
|
-
allKeysSchemeOptimized,
|
|
122
|
-
canSkipForSchemeChange
|
|
123
|
-
});
|
|
124
|
-
console.groupEnd();
|
|
125
|
-
}
|
|
126
|
-
if (next !== local) {
|
|
127
|
-
Object.assign(local, next);
|
|
128
|
-
local.id = id;
|
|
129
|
-
}
|
|
130
|
-
local._parentName = parentState?.name;
|
|
131
|
-
local._propsKey = propsKey;
|
|
132
|
-
states.set(id, next);
|
|
133
|
-
return local;
|
|
134
|
-
};
|
|
77
|
+
const ref = (0, import_react.useRef)(null);
|
|
78
|
+
if (!ref.current) ref.current = {
|
|
79
|
+
id,
|
|
80
|
+
parentId,
|
|
81
|
+
props,
|
|
82
|
+
propsKey,
|
|
83
|
+
isRoot,
|
|
84
|
+
keys,
|
|
85
|
+
schemeKeys,
|
|
86
|
+
renderVersion: 0
|
|
87
|
+
};else {
|
|
88
|
+
ref.current.props = props;
|
|
89
|
+
ref.current.propsKey = propsKey;
|
|
90
|
+
ref.current.isRoot = isRoot;
|
|
91
|
+
ref.current.keys = keys;
|
|
92
|
+
ref.current.schemeKeys = schemeKeys;
|
|
93
|
+
ref.current.parentId = parentId;
|
|
94
|
+
}
|
|
95
|
+
ref.current.renderVersion++;
|
|
135
96
|
if (process.env.NODE_ENV === "development" && globalThis.time) globalThis.time`theme-prep-uses`;
|
|
136
|
-
const
|
|
137
|
-
(
|
|
97
|
+
const [, forceUpdate] = (0, import_react.useReducer)(incReducer, 0);
|
|
98
|
+
const state = getSnapshotImpl(ref.current);
|
|
99
|
+
ref.current.lastSnap = state;
|
|
100
|
+
(0, import_react.useEffect)(() => {
|
|
101
|
+
const r = ref.current;
|
|
102
|
+
const renderVersion = r.renderVersion;
|
|
103
|
+
if (r.unsubscribe && r.subscribedParentId !== r.parentId) cleanupThemeSubscription(r);
|
|
104
|
+
if (shouldSubscribeToTheme(r, cascadeOnChange)) {
|
|
105
|
+
if (!r.unsubscribe) {
|
|
106
|
+
const pid = r.parentId;
|
|
107
|
+
const sid = r.id;
|
|
108
|
+
const cb = () => {
|
|
109
|
+
const next = getSnapshotImpl(r);
|
|
110
|
+
if (next !== r.lastSnap) {
|
|
111
|
+
r.lastSnap = next;
|
|
112
|
+
forceUpdate();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
listenersByParent[pid] = listenersByParent[pid] || /* @__PURE__ */new Set();
|
|
116
|
+
listenersByParent[pid].add(sid);
|
|
117
|
+
allListeners.set(sid, () => {
|
|
118
|
+
PendingUpdate.set(sid, shouldForce ? "force" : true);
|
|
119
|
+
cb();
|
|
120
|
+
});
|
|
121
|
+
r.subscribedParentId = pid;
|
|
122
|
+
r.unsubscribe = () => {
|
|
123
|
+
allListeners.delete(sid);
|
|
124
|
+
listenersByParent[pid]?.delete(sid);
|
|
125
|
+
localStates.delete(sid);
|
|
126
|
+
states.delete(sid);
|
|
127
|
+
PendingUpdate.delete(sid);
|
|
128
|
+
r.unsubscribe = void 0;
|
|
129
|
+
r.subscribedParentId = void 0;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
} else if (r.unsubscribe) cleanupThemeSubscription(r);
|
|
133
|
+
return () => {
|
|
134
|
+
if (r.renderVersion === renderVersion) cleanupThemeState(r);
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
if (cascadeOnChange) (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
138
138
|
if (!HasRenderedOnce.get(keys)) {
|
|
139
139
|
HasRenderedOnce.set(keys, true);
|
|
140
140
|
return;
|
|
@@ -150,6 +150,70 @@ Looked for theme${props.name ? ` "${props.name}"` : ""}${props.componentName ? `
|
|
|
150
150
|
}, [keys, propsKey]);
|
|
151
151
|
return state;
|
|
152
152
|
};
|
|
153
|
+
const shouldSubscribeToTheme = (r, cascadeOnChange) => r.isRoot || cascadeOnChange || hasThemeUpdatingProps(r.props) || !!r.keys.current?.size || !!r.props.needsUpdate?.();
|
|
154
|
+
function cleanupThemeSubscription(r) {
|
|
155
|
+
r.unsubscribe?.();
|
|
156
|
+
}
|
|
157
|
+
function cleanupThemeState(r) {
|
|
158
|
+
if (r.unsubscribe) cleanupThemeSubscription(r);else {
|
|
159
|
+
localStates.delete(r.id);
|
|
160
|
+
states.delete(r.id);
|
|
161
|
+
PendingUpdate.delete(r.id);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const getSnapshotImpl = r => {
|
|
165
|
+
const {
|
|
166
|
+
id,
|
|
167
|
+
parentId,
|
|
168
|
+
props,
|
|
169
|
+
propsKey,
|
|
170
|
+
isRoot,
|
|
171
|
+
keys,
|
|
172
|
+
schemeKeys
|
|
173
|
+
} = r;
|
|
174
|
+
let local = localStates.get(id);
|
|
175
|
+
const parentState = states.get(parentId);
|
|
176
|
+
if (local && !PendingUpdate.has(id)) {
|
|
177
|
+
if (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;
|
|
178
|
+
}
|
|
179
|
+
const isSchemeOnlyChange = false;
|
|
180
|
+
const keysSize = keys?.current?.size ?? 0;
|
|
181
|
+
const allKeysSchemeOptimized = (schemeKeys?.current?.size ?? 0) === keysSize && keysSize > 0;
|
|
182
|
+
const canSkipForSchemeChange = isSchemeOnlyChange;
|
|
183
|
+
const needsUpdate = props.passThrough ? false : isRoot || props.name === "light" || props.name === "dark" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : keys?.current?.size ? true : props.needsUpdate?.();
|
|
184
|
+
const [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));
|
|
185
|
+
PendingUpdate.delete(id);
|
|
186
|
+
if (!local || rerender) {
|
|
187
|
+
local = {
|
|
188
|
+
...next
|
|
189
|
+
};
|
|
190
|
+
localStates.set(id, local);
|
|
191
|
+
}
|
|
192
|
+
if (process.env.NODE_ENV === "development" && props.debug === "verbose") {
|
|
193
|
+
console.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, ">", next.name);
|
|
194
|
+
console.info({
|
|
195
|
+
props,
|
|
196
|
+
propsKey,
|
|
197
|
+
isRoot,
|
|
198
|
+
parentId,
|
|
199
|
+
local,
|
|
200
|
+
next,
|
|
201
|
+
needsUpdate,
|
|
202
|
+
isSchemeOnlyChange,
|
|
203
|
+
allKeysSchemeOptimized,
|
|
204
|
+
canSkipForSchemeChange
|
|
205
|
+
});
|
|
206
|
+
console.groupEnd();
|
|
207
|
+
}
|
|
208
|
+
if (next !== local) {
|
|
209
|
+
Object.assign(local, next);
|
|
210
|
+
local.id = id;
|
|
211
|
+
}
|
|
212
|
+
local._parentName = parentState?.name;
|
|
213
|
+
local._propsKey = propsKey;
|
|
214
|
+
states.set(id, next);
|
|
215
|
+
return local;
|
|
216
|
+
};
|
|
153
217
|
const getNextState = (lastState, props, propsKey, isRoot = false, id, parentId, needsUpdate, pendingUpdate) => {
|
|
154
218
|
const {
|
|
155
219
|
debug
|
|
@@ -184,12 +248,13 @@ const getNextState = (lastState, props, propsKey, isRoot = false, id, parentId,
|
|
|
184
248
|
}];
|
|
185
249
|
}
|
|
186
250
|
if (!name) {
|
|
187
|
-
const next = lastState ?? parentState
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
251
|
+
const next = lastState ?? parentState ?? rootThemeState ?? {
|
|
252
|
+
id,
|
|
253
|
+
name: "light",
|
|
254
|
+
theme: (0, import_config.getConfig)().themes.light
|
|
255
|
+
};
|
|
191
256
|
if (shouldRerender) return [true, {
|
|
192
|
-
...(parentState || lastState)
|
|
257
|
+
...(parentState || lastState || next)
|
|
193
258
|
}];
|
|
194
259
|
return [false, next];
|
|
195
260
|
}
|