@tamagui/core 1.112.9 → 1.112.11

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.
@@ -3038,7 +3038,7 @@ var require_ThemeManager_native = __commonJS({
3038
3038
  "use strict";
3039
3039
  function ThemeManager2() {
3040
3040
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, parentManager = arguments.length > 1 ? arguments[1] : void 0;
3041
- if (_class_call_check(this, ThemeManager2), _define_property(this, "props", void 0), _define_property(this, "id", void 0), _define_property(this, "themeListeners", void 0), _define_property(this, "parentManager", void 0), _define_property(this, "state", void 0), _define_property(this, "_allKeys", void 0), this.props = props, this.id = 0, this.themeListeners = /* @__PURE__ */ new Set(), this.parentManager = null, this.state = emptyState, this._allKeys = null, uid = (uid + 1) % Number.MAX_VALUE, this.id = uid, parentManager === "root") {
3041
+ if (_class_call_check(this, ThemeManager2), _define_property(this, "props", void 0), _define_property(this, "id", void 0), _define_property(this, "themeListeners", void 0), _define_property(this, "parentManager", void 0), _define_property(this, "state", void 0), _define_property(this, "_allKeys", void 0), _define_property(this, "_selfListener", void 0), this.props = props, this.id = 0, this.themeListeners = /* @__PURE__ */ new Set(), this.parentManager = null, this.state = emptyState, this._allKeys = null, uid = (uid + 1) % Number.MAX_VALUE, this.id = uid, parentManager === "root") {
3042
3042
  this.updateStateFromProps(props, !1);
3043
3043
  return;
3044
3044
  }
@@ -3058,11 +3058,22 @@ var require_ThemeManager_native = __commonJS({
3058
3058
  {
3059
3059
  key: "updateState",
3060
3060
  value: function(nextState) {
3061
- var _this = this, shouldNotify = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
3062
- this.state = nextState, this._allKeys = null, shouldNotify && this.notify();
3061
+ var shouldNotify = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
3062
+ this.state = nextState, this._allKeys = null;
3063
3063
  }
3064
3064
  },
3065
3065
  {
3066
+ // if (shouldNotify) {
3067
+ // if (process.env.TAMAGUI_TARGET === 'native') {
3068
+ // // native is way slower with queueMicrotask
3069
+ // this.notify()
3070
+ // } else {
3071
+ // // web is way faster this way
3072
+ // queueMicrotask(() => {
3073
+ // this.notify()
3074
+ // })
3075
+ // }
3076
+ // }
3066
3077
  key: "getStateIfChanged",
3067
3078
  value: function() {
3068
3079
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.props, state = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.state, parentManager = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : this.parentManager, _ = this.getState(props, parentManager);
@@ -3105,6 +3116,13 @@ var require_ThemeManager_native = __commonJS({
3105
3116
  (_this_ = this[_numChangeEventsSent = "_numChangeEventsSent"]) !== null && _this_ !== void 0 || (this[_numChangeEventsSent] = 0), this._numChangeEventsSent++;
3106
3117
  }
3107
3118
  },
3119
+ {
3120
+ key: "selfUpdate",
3121
+ value: function() {
3122
+ var _this__selfListener, _this;
3123
+ (_this__selfListener = (_this = this)._selfListener) === null || _this__selfListener === void 0 || _this__selfListener.call(_this, this.state.name, this, "self");
3124
+ }
3125
+ },
3108
3126
  {
3109
3127
  key: "onChangeTheme",
3110
3128
  value: function(cb, debugId) {
@@ -3113,7 +3131,7 @@ var require_ThemeManager_native = __commonJS({
3113
3131
  var _this__listeningIds;
3114
3132
  (_this__listeningIds = this._listeningIds) !== null && _this__listeningIds !== void 0 || (this._listeningIds = /* @__PURE__ */ new Set()), this._listeningIds.add(debugId);
3115
3133
  }
3116
- return this.themeListeners.add(cb), function() {
3134
+ return debugId === !0 && (this._selfListener = cb), this.themeListeners.add(cb), function() {
3117
3135
  _this.themeListeners.delete(cb);
3118
3136
  };
3119
3137
  }
@@ -3456,7 +3474,7 @@ var require_useTheme_native = __commonJS({
3456
3474
  if (!theme) return {};
3457
3475
  var config = (0, import_config.getConfig)();
3458
3476
  function track(key) {
3459
- keys && !keys.includes(key) && keys.push(key);
3477
+ keys && !keys.includes(key) && (keys.length || themeManager == null || themeManager.selfUpdate(), keys.push(key));
3460
3478
  }
3461
3479
  return new Proxy(theme, {
3462
3480
  has(_, key) {
@@ -3516,29 +3534,26 @@ var require_useTheme_native = __commonJS({
3516
3534
  var id = _idToUID[t.id] = {};
3517
3535
  _uidToManager.set(id, t);
3518
3536
  }
3519
- }, ogLog = console.error, preventWarnSetState = (
3520
- // temporary fix for logs, they are harmless in that i've tried to rewrite this
3521
- // a few times using the "right" ways, but they are always slower. maybe skill issue
3522
- function(a) {
3523
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) args[_key - 1] = arguments[_key];
3524
- if (!(typeof a == "string" && a.includes("Cannot update a component"))) return ogLog(a, ...args);
3525
- }
3526
- ), useChangeThemeEffect = function(props) {
3537
+ }, useChangeThemeEffect = function(props) {
3527
3538
  var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1, keys = arguments.length > 2 ? arguments[2] : void 0, shouldUpdate = arguments.length > 3 ? arguments[3] : void 0, { disable } = props, parentManagerId = import_react3.default.useContext(import_ThemeManagerContext.ThemeManagerIDContext), parentManager = getThemeManager(parentManagerId);
3528
3539
  if (!isRoot && !parentManager || disable) return {
3529
3540
  isNewTheme: !1,
3530
3541
  state: parentManager == null ? void 0 : parentManager.state,
3531
3542
  themeManager: parentManager
3532
3543
  };
3533
- var [themeState, setThemeState] = import_react3.default.useState(createState), { state, mounted, isNewTheme, themeManager, inversed } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
3544
+ var [themeState, setThemeState] = import_react3.default.useState(createState), { state, mounted, isNewTheme, themeManager, inversed, prevState } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
3534
3545
  function getShouldUpdateTheme() {
3535
- var manager = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : themeManager, nextState = arguments.length > 1 ? arguments[1] : void 0, prevState = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : state, forceShouldChange = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, forceUpdate = shouldUpdate == null ? void 0 : shouldUpdate();
3546
+ var manager = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : themeManager, nextState = arguments.length > 1 ? arguments[1] : void 0, prevState2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : state, forceShouldChange = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, forceUpdate = shouldUpdate == null ? void 0 : shouldUpdate();
3536
3547
  if (!(!manager || !forceShouldChange && forceUpdate === !1)) {
3537
3548
  var next = nextState || manager.getState(props, parentManager);
3538
- if (forceShouldChange || next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState))) return next;
3549
+ if (forceShouldChange || next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState2))) return next;
3539
3550
  }
3540
3551
  }
3541
- if (import_constants2.isServer || import_react3.default.useEffect(function() {
3552
+ if (import_constants2.isServer || (import_react3.default.useLayoutEffect(function() {
3553
+ themeManager && state && prevState && state !== prevState && themeManager.notify();
3554
+ }, [
3555
+ state
3556
+ ]), import_react3.default.useEffect(function() {
3542
3557
  if (themeManager) {
3543
3558
  if (props.inverse && !mounted) {
3544
3559
  setThemeState(function(prev) {
@@ -3551,14 +3566,15 @@ var require_useTheme_native = __commonJS({
3551
3566
  }
3552
3567
  (isNewTheme || getShouldUpdateTheme(themeManager)) && (activeThemeManagers.add(themeManager), setThemeState(createState));
3553
3568
  var selfListenerDispose = themeManager.onChangeTheme(function(_a, _b, forced) {
3554
- forced && (console.error = preventWarnSetState, setThemeState(function(prev) {
3555
- return createState(prev, !0);
3556
- }), console.error = ogLog);
3557
- }), disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(function(name, manager, forced) {
3569
+ forced && setThemeState(function(prev) {
3570
+ var next = createState(prev, forced !== "self");
3571
+ return next;
3572
+ });
3573
+ }, !0), disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(function(name, manager, forced) {
3558
3574
  var force = forced || (shouldUpdate == null ? void 0 : shouldUpdate()) || props.deopt || props["disable-child-theme"], shouldTryUpdate = force ?? !!(keys != null && keys.length || isNewTheme);
3559
- shouldTryUpdate && (console.error = preventWarnSetState, setThemeState(function(prev) {
3575
+ shouldTryUpdate && setThemeState(function(prev) {
3560
3576
  return createState(prev, force);
3561
- }), console.error = ogLog);
3577
+ });
3562
3578
  }, themeManager.id);
3563
3579
  return function() {
3564
3580
  selfListenerDispose(), disposeChangeListener == null || disposeChangeListener(), isNewTheme && activeThemeManagers.delete(themeManager);
@@ -3573,7 +3589,7 @@ var require_useTheme_native = __commonJS({
3573
3589
  props.name,
3574
3590
  props.reset,
3575
3591
  mounted
3576
- ]), import_constants2.isWeb && isInversingOnMount) return {
3592
+ ])), import_constants2.isWeb && isInversingOnMount) return {
3577
3593
  isNewTheme: !1,
3578
3594
  inversed: !1,
3579
3595
  themeManager: parentManager,
@@ -3618,7 +3634,7 @@ var require_useTheme_native = __commonJS({
3618
3634
  (0, import_createShallowSetState.isEqualShallow)(prev, response) && // ... and then compare just the state, because we make a new state obj but is likely the same
3619
3635
  (0, import_createShallowSetState.isEqualShallow)(prev.state, state2);
3620
3636
  if (prev && shouldReturnPrev) return prev;
3621
- if (response.state = state2, !1)
3637
+ if (response.state = state2, response.prevState = prev == null ? void 0 : prev.state, !1)
3622
3638
  var parentState, parentId, themeManagerState;
3623
3639
  return response;
3624
3640
  }