@tamagui/core 1.0.1-rc.9 → 1.0.1
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 +25 -27
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +2 -1
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +4 -2
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/Unwrap.js +29 -0
- package/dist/cjs/helpers/Unwrap.js.map +7 -0
- package/dist/cjs/helpers/cache.js +7 -11
- package/dist/cjs/helpers/cache.js.map +2 -2
- package/dist/cjs/helpers/expandStyle.js +29 -41
- package/dist/cjs/helpers/expandStyle.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +8 -14
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +10 -11
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +0 -2
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +45 -50
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/views/TamaguiProvider.js +3 -0
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/cjs/views/Theme.js +15 -21
- package/dist/cjs/views/Theme.js.map +3 -3
- package/dist/esm/createComponent.js +26 -28
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +2 -1
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +4 -2
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/Unwrap.js +5 -0
- package/dist/esm/helpers/Unwrap.js.map +7 -0
- package/dist/esm/helpers/cache.js +7 -10
- package/dist/esm/helpers/cache.js.map +2 -2
- package/dist/esm/helpers/expandStyle.js +26 -38
- package/dist/esm/helpers/expandStyle.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +8 -14
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +10 -11
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +0 -2
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +45 -50
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/views/TamaguiProvider.js +3 -0
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/views/Theme.js +14 -14
- package/dist/esm/views/Theme.js.map +2 -2
- package/package.json +13 -13
- package/src/createComponent.tsx +47 -43
- package/src/createTamagui.ts +2 -1
- package/src/helpers/ThemeManager.tsx +7 -2
- package/src/helpers/cache.ts +7 -9
- package/src/helpers/expandStyle.ts +27 -41
- package/src/helpers/getSplitStyles.tsx +23 -14
- package/src/helpers/getStylesAtomic.ts +15 -15
- package/src/helpers/insertStyleRule.tsx +0 -2
- package/src/hooks/useTheme.tsx +67 -48
- package/src/views/TamaguiProvider.tsx +6 -0
- package/src/views/Theme.tsx +15 -22
- package/types/createComponent.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/cache.d.ts +2 -4
- package/types/hooks/useTheme.d.ts +1 -1
- package/types/views/Theme.d.ts +1 -1
|
@@ -55,13 +55,11 @@ function addTransform(identifier, css, rule) {
|
|
|
55
55
|
const isClient = typeof document !== "undefined";
|
|
56
56
|
const scannedNum = /* @__PURE__ */ new WeakMap();
|
|
57
57
|
const totalSheetSelectors = /* @__PURE__ */ new Map();
|
|
58
|
-
const referencesInSheet = /* @__PURE__ */ new WeakMap();
|
|
59
58
|
function listenForSheetChanges() {
|
|
60
59
|
if (!isClient)
|
|
61
60
|
return;
|
|
62
61
|
function handleNode(node, remove = false) {
|
|
63
62
|
if (node instanceof HTMLStyleElement && node.sheet) {
|
|
64
|
-
console.warn("update", node.sheet);
|
|
65
63
|
updateSheetStyles(node.sheet, remove);
|
|
66
64
|
}
|
|
67
65
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/insertStyleRule.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { StyleObject } from '@tamagui/helpers'\n\nconst allSelectors: Record<string, string> = {}\nconst allRules: Record<string, string> = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getAllRules = () => Object.values(allRules)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n console.error(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n }\n return false\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n if (!insertedTransforms[identifier]) {\n insertedTransforms[identifier] = value\n return true\n }\n return false\n}\n\nconst isClient = typeof document !== 'undefined'\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\n\n// multiple sheets could have the same ids so we have to count\n\nconst scannedNum = new WeakMap<CSSStyleSheet, number>()\nconst totalSheetSelectors = new Map<string, number>()\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,MAAM,eAAuC,CAAC;AAC9C,MAAM,WAAmC,CAAC;AACnC,MAAM,qBAAqB,CAAC;AAE5B,MAAM,kBAAkB,MAAM;AAC9B,MAAM,cAAc,MAAM,OAAO,OAAO,QAAQ;AAChD,MAAM,mBAAmB,MAAM;AAGtC,SAAS,aAAa,YAAoB,KAAa,MAAgB;AACrE,QAAM,IAAI,IAAI,QAAQ,YAAY;AAClC,MAAI,MAAM,IAAI;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,MAAM,0DAAqD,YAAY;AAAA,IACjF;AACA,WAAO;AAAA,EACT;AACA,QAAM,SAAS,IAAI,aAAa;AAChC,QAAM,OAAO,IAAI,QAAQ,GAAG;AAC5B,QAAM,QAAQ,IAAI,MAAM,QAAQ,IAAI;AACpC,MAAI,CAAC,mBAAmB,aAAa;AACnC,uBAAmB,cAAc;AACjC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,MAAM,WAAW,OAAO,aAAa;AAWrC,MAAM,aAAa,oBAAI,QAA+B;AACtD,MAAM,sBAAsB,oBAAI,IAAoB;
|
|
4
|
+
"sourcesContent": ["import type { StyleObject } from '@tamagui/helpers'\n\nconst allSelectors: Record<string, string> = {}\nconst allRules: Record<string, string> = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getAllRules = () => Object.values(allRules)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n console.error(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n }\n return false\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n if (!insertedTransforms[identifier]) {\n insertedTransforms[identifier] = value\n return true\n }\n return false\n}\n\nconst isClient = typeof document !== 'undefined'\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\n\n// multiple sheets could have the same ids so we have to count\n\nconst scannedNum = new WeakMap<CSSStyleSheet, number>()\nconst totalSheetSelectors = new Map<string, number>()\n\nexport function listenForSheetChanges() {\n if (!isClient) return\n function handleNode(node: Node, remove = false) {\n if (node instanceof HTMLStyleElement && node.sheet) {\n updateSheetStyles(node.sheet, remove)\n }\n }\n const mo = new MutationObserver((entries) => {\n for (const entry of entries) {\n entry.addedNodes.forEach((node) => handleNode(node))\n entry.removedNodes.forEach((node) => handleNode(node, true))\n }\n })\n mo.observe(document.head, {\n childList: true,\n })\n}\n\nexport function scanAllSheets() {\n if (process.env.NODE_ENV === 'test') return\n if (!isClient) return\n const sheets = document.styleSheets\n if (!sheets) return\n for (let i = 0; i < sheets.length; i++) {\n const sheet = sheets[i]\n if (!sheet) continue\n updateSheetStyles(sheet)\n }\n}\n\nfunction track(id: string, remove = false) {\n const next = (totalSheetSelectors.get(id) || 0) + (remove ? -1 : 1)\n totalSheetSelectors.set(id, next)\n return next\n}\n\nfunction updateSheetStyles(sheet: CSSStyleSheet, remove = false) {\n // avoid errors on cross origin sheets\n // https://stackoverflow.com/questions/49993633/uncaught-domexception-failed-to-read-the-cssrules-property\n let rules: CSSRuleList\n try {\n rules = sheet.cssRules\n } catch {\n return\n }\n\n const len = rules.length\n const lastScanned = scannedNum.get(sheet) || 0\n\n if (!remove) {\n // avoid work dumb but works\n if (lastScanned === len) {\n return\n }\n }\n\n for (let i = lastScanned; i < len; i++) {\n const rule = rules[i]\n const response = getTamaguiSelector(rule)\n if (!response) {\n return\n }\n\n const [identifier, cssRule] = response\n\n // track references\n const total = track(identifier, remove)\n\n if (remove) {\n if (total === 0) {\n delete allSelectors[identifier]\n }\n } else {\n if (!(identifier in allSelectors)) {\n const isTransform = identifier.startsWith('_transform')\n const shouldInsert = isTransform\n ? addTransform(identifier, cssRule.cssText, cssRule)\n : true\n if (shouldInsert) {\n allSelectors[identifier] = cssRule.cssText\n }\n }\n }\n }\n\n scannedNum.set(sheet, len)\n}\n\nfunction getTamaguiSelector(\n rule: CSSRule | null\n): readonly [string, CSSStyleRule] | null {\n if (rule instanceof CSSStyleRule) {\n const text = rule.selectorText\n // .startsWith('._')\n if (text[0] === '.' && text[1] === '_') {\n return [text.slice(1), rule]\n }\n if (text.startsWith(':root') && text.includes('._')) {\n return [getIdentifierFromTamaguiSelector(text), rule]\n }\n } else if (rule instanceof CSSMediaRule) {\n // tamagui only ever inserts 1 rule per media\n if (rule.cssRules.length > 1) return null\n return getTamaguiSelector(rule.cssRules[0])\n }\n return null\n}\n\nconst getIdentifierFromTamaguiSelector = (selector: string) =>\n selector\n .replace(/(:root)+\\s+/, '')\n .replace(/:[a-z]+$/, '')\n .slice(1)\n\nconst sheet = isClient\n ? document.head.appendChild(document.createElement('style')).sheet\n : null\n\nexport function updateRules(identifier: string, rules: string[]) {\n if (allRules[identifier]) return false\n allRules[identifier] = rules.join(' ')\n if (identifier.startsWith('_transform')) {\n return addTransform(identifier, rules[0])\n }\n return true\n}\n\n// [property, identifier, rules]\nexport type PartialStyleObject = Pick<StyleObject, 'identifier' | 'property' | 'rules'>\nexport type RulesToInsert = PartialStyleObject[]\n\nexport function insertStyleRules(rulesToInsert: RulesToInsert) {\n if (!rulesToInsert.length) return\n if (isClient && !sheet) {\n if (process.env.NODE_ENV === 'development') throw 'impossible'\n return\n }\n for (const { identifier, rules } of rulesToInsert) {\n if (identifier in allSelectors) continue\n allSelectors[identifier] =\n process.env.NODE_ENV === 'development' ? rules.join('\\n') : ' '\n updateRules(identifier, rules)\n if (sheet) {\n for (const rule of rules) {\n sheet.insertRule(rule, sheet.cssRules.length)\n }\n }\n }\n}\n\nconst IS_STATIC = process.env.IS_STATIC === 'is_static'\n\nexport function shouldInsertStyleRules(styleObject: PartialStyleObject) {\n if (IS_STATIC) {\n return true\n }\n return !(styleObject.identifier in allSelectors)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,MAAM,eAAuC,CAAC;AAC9C,MAAM,WAAmC,CAAC;AACnC,MAAM,qBAAqB,CAAC;AAE5B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cAAc;AACrC;",
|
|
6
6
|
"names": ["sheet"]
|
|
7
7
|
}
|
|
@@ -33,6 +33,7 @@ var import_createProxy = require("../helpers/createProxy");
|
|
|
33
33
|
var import_ThemeManager = require("../helpers/ThemeManager");
|
|
34
34
|
var import_ThemeManagerContext = require("../helpers/ThemeManagerContext");
|
|
35
35
|
var import_getThemeUnwrapped = require("./getThemeUnwrapped");
|
|
36
|
+
var import_useServerHooks = require("./useServerHooks");
|
|
36
37
|
const emptyProps = { name: null };
|
|
37
38
|
function getDefaultThemeProxied() {
|
|
38
39
|
const config = (0, import_config.getConfig)();
|
|
@@ -43,13 +44,24 @@ function getDefaultThemeProxied() {
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
const useTheme = (props = emptyProps) => {
|
|
46
|
-
var _a;
|
|
47
|
+
var _a, _b;
|
|
47
48
|
if (import_constants.isRSC) {
|
|
48
49
|
return getDefaultThemeProxied();
|
|
49
50
|
}
|
|
50
|
-
const
|
|
51
|
+
const state = (0, import_useServerHooks.useServerRef)();
|
|
52
|
+
if (import_constants.isClient && !state.current) {
|
|
53
|
+
state.current = {
|
|
54
|
+
keys: /* @__PURE__ */ new Set()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
(_a = state.current) == null ? void 0 : _a.keys.clear();
|
|
58
|
+
const { name, theme, themeManager, className, isNewTheme } = useChangeThemeEffect(
|
|
59
|
+
props,
|
|
60
|
+
false,
|
|
61
|
+
import_constants.isClient ? () => state.current.keys.size === 0 : void 0
|
|
62
|
+
);
|
|
51
63
|
if (process.env.NODE_ENV === "development") {
|
|
52
|
-
if (import_constants.isWeb && isNewTheme && className === ((
|
|
64
|
+
if (import_constants.isWeb && isNewTheme && className === ((_b = themeManager == null ? void 0 : themeManager.parentManager) == null ? void 0 : _b.state.className)) {
|
|
53
65
|
console.error("Should always change, duplicating ThemeMananger bug", themeManager);
|
|
54
66
|
}
|
|
55
67
|
if (props.debug === "verbose") {
|
|
@@ -73,7 +85,8 @@ const useTheme = (props = emptyProps) => {
|
|
|
73
85
|
theme,
|
|
74
86
|
name,
|
|
75
87
|
className,
|
|
76
|
-
themeManager
|
|
88
|
+
themeManager,
|
|
89
|
+
state
|
|
77
90
|
});
|
|
78
91
|
}, [theme, isNewTheme, name, className, themeManager]);
|
|
79
92
|
};
|
|
@@ -82,7 +95,8 @@ function getThemeProxied({
|
|
|
82
95
|
name,
|
|
83
96
|
className,
|
|
84
97
|
themeManager,
|
|
85
|
-
isNewTheme
|
|
98
|
+
isNewTheme,
|
|
99
|
+
state
|
|
86
100
|
}) {
|
|
87
101
|
return (0, import_createProxy.createProxy)(theme, {
|
|
88
102
|
has(_, key) {
|
|
@@ -112,7 +126,20 @@ function getThemeProxied({
|
|
|
112
126
|
if (!themeManager) {
|
|
113
127
|
return theme[key];
|
|
114
128
|
}
|
|
115
|
-
|
|
129
|
+
const val = themeManager.getValue(key);
|
|
130
|
+
if (val && state) {
|
|
131
|
+
if (import_constants.isClient) {
|
|
132
|
+
return new Proxy(val, {
|
|
133
|
+
get(_2, subkey) {
|
|
134
|
+
if (subkey === "val") {
|
|
135
|
+
state.current.keys.add(key);
|
|
136
|
+
}
|
|
137
|
+
return Reflect.get(val, subkey);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return val;
|
|
116
143
|
}
|
|
117
144
|
});
|
|
118
145
|
}
|
|
@@ -121,7 +148,7 @@ const GetIsNewTheme = Symbol();
|
|
|
121
148
|
const getThemeManager = (theme) => theme == null ? void 0 : theme[GetThemeManager];
|
|
122
149
|
const getThemeIsNewTheme = (theme) => theme == null ? void 0 : theme[GetIsNewTheme];
|
|
123
150
|
const activeThemeManagers = /* @__PURE__ */ new Set();
|
|
124
|
-
const useChangeThemeEffect = (props, root = false) => {
|
|
151
|
+
const useChangeThemeEffect = (props, root = false, disableUpdate) => {
|
|
125
152
|
if (import_constants.isRSC) {
|
|
126
153
|
return {
|
|
127
154
|
...createState().state,
|
|
@@ -153,20 +180,8 @@ const useChangeThemeEffect = (props, root = false) => {
|
|
|
153
180
|
return;
|
|
154
181
|
}
|
|
155
182
|
activeThemeManagers.add(themeManager);
|
|
156
|
-
const disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(() => {
|
|
157
|
-
if (!(isNewTheme || import_constants.isWeb)) {
|
|
158
|
-
setThemeState({
|
|
159
|
-
...themeState,
|
|
160
|
-
state: { ...themeManager.state },
|
|
161
|
-
isNewTheme: false
|
|
162
|
-
});
|
|
163
|
-
} else {
|
|
164
|
-
updateState();
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
183
|
return () => {
|
|
168
184
|
activeThemeManagers.delete(themeManager);
|
|
169
|
-
disposeChangeListener == null ? void 0 : disposeChangeListener();
|
|
170
185
|
};
|
|
171
186
|
}, [disable, state, isNewTheme, debug]);
|
|
172
187
|
}
|
|
@@ -176,12 +191,7 @@ const useChangeThemeEffect = (props, root = false) => {
|
|
|
176
191
|
if (!parentManager)
|
|
177
192
|
throw "impossible";
|
|
178
193
|
if (process.env.NODE_ENV === "development" && props.debug === "verbose")
|
|
179
|
-
console.log(
|
|
180
|
-
"useTheme hasNoThemeUpdatingProps",
|
|
181
|
-
parentManager.state.name,
|
|
182
|
-
"isInversingOnMount",
|
|
183
|
-
isInversingOnMount
|
|
184
|
-
);
|
|
194
|
+
console.log("useTheme hasNoThemeUpdatingProps", parentManager.state.name, "isInversingOnMount", isInversingOnMount);
|
|
185
195
|
return {
|
|
186
196
|
...parentManager.state,
|
|
187
197
|
className: isInversingOnMount ? "" : parentManager.state.className,
|
|
@@ -196,27 +206,11 @@ const useChangeThemeEffect = (props, root = false) => {
|
|
|
196
206
|
themeManager
|
|
197
207
|
};
|
|
198
208
|
function createState(prev) {
|
|
209
|
+
if (prev && (disableUpdate == null ? void 0 : disableUpdate())) {
|
|
210
|
+
return prev;
|
|
211
|
+
}
|
|
199
212
|
const _ = new import_ThemeManager.ThemeManager(props, root ? "root" : parentManager);
|
|
200
213
|
const isNewTheme2 = _ !== parentManager;
|
|
201
|
-
if (process.env.NODE_ENV === "development" && debug)
|
|
202
|
-
[
|
|
203
|
-
console.groupCollapsed("useTheme create() isNewTheme", isNewTheme2),
|
|
204
|
-
console.log(
|
|
205
|
-
"parent.state.name",
|
|
206
|
-
parentManager == null ? void 0 : parentManager.state.name,
|
|
207
|
-
"\n",
|
|
208
|
-
"props",
|
|
209
|
-
props,
|
|
210
|
-
"\n",
|
|
211
|
-
import_constants.isClient ? parentManager : "",
|
|
212
|
-
"getState",
|
|
213
|
-
isNewTheme2 && import_constants.isClient ? _.getState(props) : "",
|
|
214
|
-
"\n",
|
|
215
|
-
"state",
|
|
216
|
-
import_constants.isClient ? { ..._.state } : ""
|
|
217
|
-
),
|
|
218
|
-
console.groupEnd()
|
|
219
|
-
];
|
|
220
214
|
const mounted2 = !props.inverse ? true : root || (prev == null ? void 0 : prev.mounted);
|
|
221
215
|
return {
|
|
222
216
|
isNewTheme: isNewTheme2,
|
|
@@ -225,12 +219,13 @@ const useChangeThemeEffect = (props, root = false) => {
|
|
|
225
219
|
mounted: mounted2
|
|
226
220
|
};
|
|
227
221
|
}
|
|
228
|
-
function updateState() {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
);
|
|
222
|
+
function updateState(updatingManager) {
|
|
223
|
+
if (disableUpdate == null ? void 0 : disableUpdate()) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const manager = updatingManager ?? themeManager;
|
|
227
|
+
const next = manager.getState(props, parentManager);
|
|
228
|
+
const shouldChange = manager.getStateShouldChange(next, isNewTheme ? state : null);
|
|
234
229
|
if (shouldChange) {
|
|
235
230
|
setThemeState(createState);
|
|
236
231
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AACjD,
|
|
6
|
-
"names": ["isNewTheme", "mounted"]
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n ThemeManager,\n ThemeManagerState,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeParsed, ThemeProps } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport type ChangedThemeResponse = {\n themeManager: ThemeManager | null\n name: string\n isNewTheme?: boolean\n theme?: ThemeParsed | null\n className?: string\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\ninterface UseThemeState {\n keys: Set<string>\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n if (isRSC) {\n return getDefaultThemeProxied()\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (isClient && !state.current) {\n state.current = {\n keys: new Set(),\n }\n }\n state.current?.keys.clear()\n\n const { name, theme, themeManager, className, isNewTheme } = useChangeThemeEffect(\n props,\n false,\n isClient ? () => state.current.keys.size === 0 : undefined\n )\n\n if (process.env.NODE_ENV === 'development') {\n // ensure we aren't creating too many ThemeManagers\n if (\n isWeb &&\n isNewTheme &&\n className === themeManager?.parentManager?.state.className\n ) {\n console.error('Should always change, duplicating ThemeMananger bug', themeManager)\n }\n if (props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n }\n\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return getDefaultThemeProxied()\n }\n\n return useMemo(() => {\n return getThemeProxied({\n isNewTheme,\n theme,\n name,\n className,\n themeManager,\n state,\n })\n }, [theme, isNewTheme, name, className, themeManager])\n}\n\nfunction getThemeProxied({\n theme,\n name,\n className,\n themeManager,\n isNewTheme,\n state,\n}: {\n theme: any\n name: string\n className?: string\n themeManager?: ThemeManager | null\n isNewTheme?: boolean\n state?: React.RefObject<UseThemeState>\n}) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n } else if (key === GetThemeManager) {\n return themeManager\n } else if (key === GetIsNewTheme) {\n return isNewTheme\n } else if (key === 'name') {\n return name\n } else if (key === 'className') {\n return className\n } else if (\n !name ||\n key === '__proto__' ||\n typeof key === 'symbol' ||\n key === '$typeof'\n ) {\n return Reflect.get(_, key)\n }\n // auto convert variables to plain\n if (key[0] === '$') key = key.slice(1)\n if (!themeManager) {\n return theme[key]\n }\n const val = themeManager.getValue(key)\n if (val && state) {\n if (isClient) {\n return new Proxy(val as any, {\n get(_, subkey) {\n if (subkey === 'val') {\n state.current!.keys.add(key as any)\n }\n return Reflect.get(val, subkey)\n },\n })\n }\n }\n return val\n },\n })\n}\n\nconst GetThemeManager = Symbol()\nconst GetIsNewTheme = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined =>\n theme?.[GetThemeManager]\nexport const getThemeIsNewTheme = (theme: any): ThemeManager | undefined =>\n theme?.[GetIsNewTheme]\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n ...createState().state,\n themeManager: null,\n }\n }\n const parentManager = useContext(ThemeManagerContext)\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw new Error('Disable topmost')\n return {\n ...parentManager.state,\n isNewTheme: false,\n themeManager: parentManager,\n }\n }\n\n type State = {\n isNewTheme: boolean\n state: ThemeManagerState\n themeManager: ThemeManager\n mounted?: boolean\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { isNewTheme, state, themeManager, mounted } = themeState\n\n if (!isServer) {\n useEffect(() => {\n if (disable) return\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n activeThemeManagers.add(themeManager)\n // const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n // // console.log('hi', props, state, name, manager)\n // if (state.theme !== manager.state.theme) {\n // console.warn('now update to', manager.state.name)\n // updateState(manager)\n // }\n // })\n return () => {\n activeThemeManagers.delete(themeManager)\n // disposeChangeListener?.()\n }\n }, [disable, state, isNewTheme, debug])\n }\n\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = hasNoThemeUpdatingProps(props) || isInversingOnMount\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n // prettier-ignore\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('useTheme hasNoThemeUpdatingProps', parentManager.state.name, 'isInversingOnMount', isInversingOnMount)\n return {\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n isNewTheme: false,\n }\n }\n\n // run inline in render\n updateState()\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State) {\n if (prev && disableUpdate?.()) {\n return prev\n }\n // returns previous theme manager if no change\n const _ = new ThemeManager(props, root ? 'root' : parentManager)\n const isNewTheme = _ !== parentManager\n // prettier-ignore\n\n // if (prev?.isNewTheme && _.state.theme !== parentManager?.state.theme) {\n // console.warn('notify')\n // _.notify()\n // }\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n return {\n // ThemeManager returns parentManager if no change\n isNewTheme,\n state: { ..._.state },\n themeManager: _,\n mounted,\n }\n }\n\n function updateState(updatingManager?: ThemeManager) {\n if (disableUpdate?.()) {\n return\n }\n const manager = updatingManager ?? themeManager\n const next = manager.getState(props, parentManager)\n const shouldChange = manager.getStateShouldChange(next, isNewTheme ? state : null)\n // console.log(`got it`, next, isNewTheme, shouldChange, { ...updatingManager?.state })\n if (shouldChange) {\n setThemeState(createState)\n } else {\n if (!next && parentManager?.state.name !== state.name) {\n // were changing back to parent state\n setThemeState(createState)\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AACjD,mBAAyD;AAEzD,oBAA0B;AAC1B,wBAA2B;AAC3B,yBAA4B;AAC5B,0BAIO;AACP,iCAAoC;AAEpC,+BAAkC;AAClC,4BAA6B;AAU7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,aAAS,yBAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AACxC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAMO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AAxCzE;AAyCE,MAAI,wBAAO;AACT,WAAO,uBAAuB;AAAA,EAChC;AAEA,QAAM,YAAQ,oCAAa;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AQ,mDAAmB;AAC7B,aAAO;AAAA,IACT;AAEA,UAAM,IAAI,IAAI,iCAAa,OAAO,OAAO,SAAS,aAAa;AAC/D,UAAMC,cAAa,MAAM;AASzB,UAAMC,WAAU,CAAC,MAAM,UAAU,OAAO,SAAQ,6BAAM;AACtD,WAAO;AAAA,MAEL,YAAAD;AAAA,MACA,OAAO,EAAE,GAAG,EAAE,MAAM;AAAA,MACpB,cAAc;AAAA,MACd,SAAAC;AAAA,IACF;AAAA,EACF;AAEA,WAAS,YAAY,iBAAgC;AACnD,QAAI,kDAAmB;AACrB;AAAA,IACF;AACA,UAAM,UAAU,mBAAmB;AACnC,UAAM,OAAO,QAAQ,SAAS,OAAO,aAAa;AAClD,UAAM,eAAe,QAAQ,qBAAqB,MAAM,aAAa,QAAQ,IAAI;AAEjF,QAAI,cAAc;AAChB,oBAAc,WAAW;AAAA,IAC3B,OAAO;AACL,UAAI,CAAC,SAAQ,+CAAe,MAAM,UAAS,MAAM,MAAM;AAErD,sBAAc,WAAW;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["_", "isNewTheme", "mounted"]
|
|
7
7
|
}
|
|
@@ -52,6 +52,9 @@ function TamaguiProvider({
|
|
|
52
52
|
}
|
|
53
53
|
if (import_constants.isClient) {
|
|
54
54
|
React.useLayoutEffect(() => {
|
|
55
|
+
if (document.documentElement.classList.contains("t_unmounted")) {
|
|
56
|
+
document.documentElement.classList.remove("t_unmounted");
|
|
57
|
+
}
|
|
55
58
|
if (disableInjectCSS)
|
|
56
59
|
return;
|
|
57
60
|
const style = document.createElement("style");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/TamaguiProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport * as React from 'react'\n\nimport { ButtonNestingContext } from '../contexts/ButtonNestingContext'\nimport { TextAncestorContext } from '../contexts/TextAncestorContext'\nimport { useMediaListeners } from '../hooks/useMedia'\nimport type { TamaguiProviderProps } from '../types'\nimport { ThemeProvider } from './ThemeProvider'\n\nexport function TamaguiProvider({\n children,\n disableInjectCSS,\n config,\n ...themePropsProvider\n}: TamaguiProviderProps) {\n if (isRSC) {\n return (\n <span\n style={{ display: 'contents' }}\n className={`t_${Object.keys(config.themes)[0] || 'light'}`}\n >\n {children}\n </span>\n )\n }\n\n if (!(isWeb && isServer)) {\n useMediaListeners(config)\n }\n\n if (isClient) {\n // inject CSS if asked to (not SSR compliant)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useLayoutEffect(() => {\n if (disableInjectCSS) return\n const style = document.createElement('style')\n style.appendChild(document.createTextNode(config.getCSS()))\n document.head.appendChild(style)\n return () => {\n document.head.removeChild(style)\n }\n }, [config, disableInjectCSS])\n }\n\n return (\n <ButtonNestingContext.Provider value={false}>\n <TextAncestorContext.Provider value={false}>\n <ThemeProvider\n themeClassNameOnRoot={config.themeClassNameOnRoot}\n disableRootThemeClass={config.disableRootThemeClass}\n {...themePropsProvider}\n defaultTheme={themePropsProvider.defaultTheme ?? Object.keys(config.themes)[0]}\n >\n {children}\n </ThemeProvider>\n </TextAncestorContext.Provider>\n </ButtonNestingContext.Provider>\n )\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBM;AAjBN,uBAAiD;AACjD,YAAuB;AAEvB,kCAAqC;AACrC,iCAAoC;AACpC,sBAAkC;AAElC,2BAA8B;AAEvB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,KACG;AACL,GAAyB;AACvB,MAAI,wBAAO;AACT,WACE,4CAAC;AAAA,MACC,OAAO,EAAE,SAAS,WAAW;AAAA,MAC7B,WAAW,KAAK,OAAO,KAAK,OAAO,MAAM,EAAE,MAAM;AAAA,MAEhD;AAAA,KACH;AAAA,EAEJ;AAEA,MAAI,EAAE,0BAAS,4BAAW;AACxB,2CAAkB,MAAM;AAAA,EAC1B;AAEA,MAAI,2BAAU;AAGZ,UAAM,gBAAgB,MAAM;
|
|
4
|
+
"sourcesContent": ["import { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport * as React from 'react'\n\nimport { ButtonNestingContext } from '../contexts/ButtonNestingContext'\nimport { TextAncestorContext } from '../contexts/TextAncestorContext'\nimport { useMediaListeners } from '../hooks/useMedia'\nimport type { TamaguiProviderProps } from '../types'\nimport { ThemeProvider } from './ThemeProvider'\n\nexport function TamaguiProvider({\n children,\n disableInjectCSS,\n config,\n ...themePropsProvider\n}: TamaguiProviderProps) {\n if (isRSC) {\n return (\n <span\n style={{ display: 'contents' }}\n className={`t_${Object.keys(config.themes)[0] || 'light'}`}\n >\n {children}\n </span>\n )\n }\n\n if (!(isWeb && isServer)) {\n useMediaListeners(config)\n }\n\n if (isClient) {\n // inject CSS if asked to (not SSR compliant)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useLayoutEffect(() => {\n // for easier support of hidden-until-js mount animations\n // user must set t_unmounted on documentElement from SSR\n if (document.documentElement.classList.contains('t_unmounted')) {\n document.documentElement.classList.remove('t_unmounted')\n }\n\n if (disableInjectCSS) return\n const style = document.createElement('style')\n style.appendChild(document.createTextNode(config.getCSS()))\n document.head.appendChild(style)\n return () => {\n document.head.removeChild(style)\n }\n }, [config, disableInjectCSS])\n }\n\n return (\n <ButtonNestingContext.Provider value={false}>\n <TextAncestorContext.Provider value={false}>\n <ThemeProvider\n themeClassNameOnRoot={config.themeClassNameOnRoot}\n disableRootThemeClass={config.disableRootThemeClass}\n {...themePropsProvider}\n defaultTheme={themePropsProvider.defaultTheme ?? Object.keys(config.themes)[0]}\n >\n {children}\n </ThemeProvider>\n </TextAncestorContext.Provider>\n </ButtonNestingContext.Provider>\n )\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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+1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,20 +15,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
19
|
var Theme_exports = {};
|
|
26
20
|
__export(Theme_exports, {
|
|
27
21
|
Theme: () => Theme,
|
|
28
|
-
|
|
22
|
+
useThemeManagerContext: () => useThemeManagerContext
|
|
29
23
|
});
|
|
30
24
|
module.exports = __toCommonJS(Theme_exports);
|
|
31
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
26
|
var import_constants = require("@tamagui/constants");
|
|
33
|
-
var import_react =
|
|
27
|
+
var import_react = require("react");
|
|
34
28
|
var import_createVariable = require("../createVariable");
|
|
35
29
|
var import_ThemeManagerContext = require("../helpers/ThemeManagerContext");
|
|
36
30
|
var import_useTheme = require("../hooks/useTheme");
|
|
@@ -39,16 +33,16 @@ function Theme(props) {
|
|
|
39
33
|
return props.children;
|
|
40
34
|
}
|
|
41
35
|
const isRoot = !!props["_isRoot"];
|
|
42
|
-
const { name, theme, themeManager,
|
|
43
|
-
props,
|
|
44
|
-
isRoot
|
|
45
|
-
);
|
|
36
|
+
const { name, theme, themeManager, className } = (0, import_useTheme.useChangeThemeEffect)(props, isRoot);
|
|
46
37
|
const disableThemeClass = props.disableThemeClass;
|
|
47
38
|
const missingTheme = !(name && theme);
|
|
48
|
-
let contents = (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
let contents = useThemeManagerContext(
|
|
40
|
+
props["data-themeable"] ? import_react.Children.map(
|
|
41
|
+
props.children,
|
|
42
|
+
(child) => (0, import_react.cloneElement)(child, { ["data-themeable"]: true })
|
|
43
|
+
) : props.children,
|
|
44
|
+
themeManager
|
|
45
|
+
);
|
|
52
46
|
if (process.env.NODE_ENV === "development" && missingTheme) {
|
|
53
47
|
name && !theme && console.warn(`No theme found by name ${name}`);
|
|
54
48
|
return props.children;
|
|
@@ -68,10 +62,10 @@ function Theme(props) {
|
|
|
68
62
|
}
|
|
69
63
|
return contents;
|
|
70
64
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
65
|
+
function useThemeManagerContext(children, themeManager, shouldReset) {
|
|
66
|
+
const value = themeManager;
|
|
67
|
+
if (!value)
|
|
73
68
|
return children;
|
|
74
|
-
}
|
|
75
69
|
let next = children;
|
|
76
70
|
if (shouldReset && themeManager) {
|
|
77
71
|
next = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Theme, {
|
|
@@ -80,13 +74,13 @@ function wrapThemeManagerContext(children, themeManager, shouldReset) {
|
|
|
80
74
|
});
|
|
81
75
|
}
|
|
82
76
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThemeManagerContext.ThemeManagerContext.Provider, {
|
|
83
|
-
value
|
|
77
|
+
value,
|
|
84
78
|
children: next
|
|
85
79
|
});
|
|
86
80
|
}
|
|
87
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
82
|
0 && (module.exports = {
|
|
89
83
|
Theme,
|
|
90
|
-
|
|
84
|
+
useThemeManagerContext
|
|
91
85
|
});
|
|
92
86
|
//# sourceMappingURL=Theme.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/Theme.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport React, { useMemo } from 'react'\n\nimport { variableToString } from '../createVariable'\nimport { ThemeManager } from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { useChangeThemeEffect } from '../hooks/useTheme'\nimport { ThemeProps } from '../types'\n\nexport function Theme(props: ThemeProps) {\n // @ts-expect-error only for internal views\n if (props.disable) {\n return props.children\n }\n\n const isRoot = !!props['_isRoot']\n const { name, theme, themeManager,
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport React, { Children, cloneElement, useMemo } from 'react'\n\nimport { variableToString } from '../createVariable'\nimport { ThemeManager } from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { useChangeThemeEffect } from '../hooks/useTheme'\nimport { ThemeProps } from '../types'\n\nexport function Theme(props: ThemeProps) {\n // @ts-expect-error only for internal views\n if (props.disable) {\n return props.children\n }\n\n const isRoot = !!props['_isRoot']\n const { name, theme, themeManager, className } = useChangeThemeEffect(props, isRoot)\n const disableThemeClass = props.disableThemeClass\n const missingTheme = !(name && theme)\n\n // memo here, changing theme without re-rendering all children is a critical optimization\n // may require some effort of end user to memoize but without this memo they'd have no option\n let contents = useThemeManagerContext(\n props['data-themeable']\n ? Children.map(props.children, (child) =>\n cloneElement(child, { ['data-themeable']: true })\n )\n : props.children,\n themeManager\n )\n\n if (process.env.NODE_ENV === 'development' && missingTheme) {\n // eslint-disable-next-line no-console\n name && !theme && console.warn(`No theme found by name ${name}`)\n return props.children\n }\n\n if (disableThemeClass || missingTheme) {\n return contents\n }\n\n if (isWeb) {\n const cn = [props.className, className, '_dsp_contents'].filter(Boolean).join(' ')\n contents = (\n <span\n className={cn}\n style={{\n // in order to provide currentColor, set color by default\n color: variableToString(theme?.color),\n }}\n >\n {contents}\n </span>\n )\n }\n\n return contents\n}\n\nexport function useThemeManagerContext(\n children: any,\n themeManager?: ThemeManager | null,\n shouldReset?: boolean\n) {\n // disabled super memoize it - listener first strategy\n const value = themeManager // useMemo(() => themeManager, [!!themeManager])\n // be sure to memoize themeManager to avoid reparenting\n if (!value) return children\n // be sure to memoize shouldReset to avoid reparenting\n let next = children\n // TODO likely not necessary if we do reset logic now in useTheme?\n // reset to parent theme\n if (shouldReset && themeManager) {\n next = <Theme name={themeManager.state.parentName}>{next}</Theme>\n }\n return <ThemeManagerContext.Provider value={value}>{next}</ThemeManagerContext.Provider>\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4CM;AA5CN,uBAAsB;AACtB,mBAAuD;AAEvD,4BAAiC;AAEjC,iCAAoC;AACpC,sBAAqC;AAG9B,SAAS,MAAM,OAAmB;AAEvC,MAAI,MAAM,SAAS;AACjB,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,SAAS,CAAC,CAAC,MAAM;AACvB,QAAM,EAAE,MAAM,OAAO,cAAc,UAAU,QAAI,sCAAqB,OAAO,MAAM;AACnF,QAAM,oBAAoB,MAAM;AAChC,QAAM,eAAe,EAAE,QAAQ;AAI/B,MAAI,WAAW;AAAA,IACb,MAAM,oBACF,sBAAS;AAAA,MAAI,MAAM;AAAA,MAAU,CAAC,cAC5B,2BAAa,OAAO,EAAE,CAAC,mBAAmB,KAAK,CAAC;AAAA,IAClD,IACA,MAAM;AAAA,IACV;AAAA,EACF;AAEA,MAAI,QAAQ,IAAI,aAAa,iBAAiB,cAAc;AAE1D,YAAQ,CAAC,SAAS,QAAQ,KAAK,0BAA0B,MAAM;AAC/D,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,qBAAqB,cAAc;AACrC,WAAO;AAAA,EACT;AAEA,MAAI,wBAAO;AACT,UAAM,KAAK,CAAC,MAAM,WAAW,WAAW,eAAe,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AACjF,eACE,4CAAC;AAAA,MACC,WAAW;AAAA,MACX,OAAO;AAAA,QAEL,WAAO,wCAAiB,+BAAO,KAAK;AAAA,MACtC;AAAA,MAEC;AAAA,KACH;AAAA,EAEJ;AAEA,SAAO;AACT;AAEO,SAAS,uBACd,UACA,cACA,aACA;AAEA,QAAM,QAAQ;AAEd,MAAI,CAAC;AAAO,WAAO;AAEnB,MAAI,OAAO;AAGX,MAAI,eAAe,cAAc;AAC/B,WAAO,4CAAC;AAAA,MAAM,MAAM,aAAa,MAAM;AAAA,MAAa;AAAA,KAAK;AAAA,EAC3D;AACA,SAAO,4CAAC,+CAAoB,UAApB;AAAA,IAA6B;AAAA,IAAe;AAAA,GAAK;AAC3D;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -43,7 +43,7 @@ import { useServerRef, useServerState } from "./hooks/useServerHooks";
|
|
|
43
43
|
import { getThemeIsNewTheme, getThemeManager, useTheme } from "./hooks/useTheme";
|
|
44
44
|
import { usePressability } from "./vendor/Pressability";
|
|
45
45
|
import { Slot, mergeEvent } from "./views/Slot";
|
|
46
|
-
import {
|
|
46
|
+
import { useThemeManagerContext } from "./views/Theme";
|
|
47
47
|
process.env.TAMAGUI_TARGET;
|
|
48
48
|
let defaultComponentState = null;
|
|
49
49
|
let defaultComponentStateMounted = null;
|
|
@@ -368,7 +368,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
368
368
|
viewProps.ref = useComposedRefs(hostRef, forwardedRef);
|
|
369
369
|
if (process.env.NODE_ENV === "development" && !isText && isWeb) {
|
|
370
370
|
Children.toArray(props.children).forEach((item) => {
|
|
371
|
-
if (typeof item === "string") {
|
|
371
|
+
if (typeof item === "string" && item !== "\n") {
|
|
372
372
|
console.error(
|
|
373
373
|
`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`
|
|
374
374
|
);
|
|
@@ -392,10 +392,16 @@ function createComponent(configIn, ParentComponent) {
|
|
|
392
392
|
useEffect(() => {
|
|
393
393
|
if (!shouldSetMounted)
|
|
394
394
|
return;
|
|
395
|
+
if (state.unmounted === true && needsMount) {
|
|
396
|
+
setStateShallow({
|
|
397
|
+
unmounted: false
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
395
401
|
setStateShallow({
|
|
396
402
|
unmounted: false
|
|
397
403
|
});
|
|
398
|
-
}, [shouldSetMounted]);
|
|
404
|
+
}, [shouldSetMounted, state.unmounted]);
|
|
399
405
|
let styles;
|
|
400
406
|
if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {
|
|
401
407
|
styles = {
|
|
@@ -416,6 +422,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
416
422
|
}
|
|
417
423
|
const fontFamilyClassName = fontFamily ? `font_${fontFamily}` : "";
|
|
418
424
|
const classList = [
|
|
425
|
+
hasEnterStyle && (state.unmounted && needsMount || !isClient) ? "t_will-mount" : "",
|
|
419
426
|
componentName ? componentClassName : "",
|
|
420
427
|
fontFamilyClassName,
|
|
421
428
|
themeIsNew ? theme.className : "",
|
|
@@ -556,7 +563,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
556
563
|
if (themeShouldReset) {
|
|
557
564
|
stateRef.current.themeShouldReset = true;
|
|
558
565
|
}
|
|
559
|
-
const
|
|
566
|
+
const innerContent = useThemeManagerContext(
|
|
560
567
|
spacedChildren({
|
|
561
568
|
separator,
|
|
562
569
|
children,
|
|
@@ -567,7 +574,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
567
574
|
stateRef.current.hasProvidedThemeManager ? themeManager : void 0,
|
|
568
575
|
stateRef.current.themeShouldReset
|
|
569
576
|
);
|
|
570
|
-
let content;
|
|
577
|
+
let content = !children || asChild ? children : innerContent;
|
|
571
578
|
if (asChild) {
|
|
572
579
|
elementType = Slot;
|
|
573
580
|
viewProps = {
|
|
@@ -596,7 +603,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
596
603
|
}
|
|
597
604
|
}
|
|
598
605
|
}
|
|
599
|
-
content = createElement(elementType, viewProps,
|
|
606
|
+
content = createElement(elementType, viewProps, content);
|
|
600
607
|
if (process.env.TAMAGUI_TARGET === "web") {
|
|
601
608
|
if (events || isAnimatedReactNativeWeb) {
|
|
602
609
|
content = /* @__PURE__ */ jsx("span", {
|
|
@@ -642,7 +649,6 @@ function createComponent(configIn, ParentComponent) {
|
|
|
642
649
|
styles,
|
|
643
650
|
pseudos,
|
|
644
651
|
content,
|
|
645
|
-
childEls,
|
|
646
652
|
shouldAvoidClasses,
|
|
647
653
|
avoidClasses: avoidClassesWhileAnimating,
|
|
648
654
|
animation: props.animation,
|
|
@@ -822,15 +828,9 @@ const Spacer = createComponent({
|
|
|
822
828
|
}
|
|
823
829
|
}
|
|
824
830
|
});
|
|
825
|
-
function spacedChildren({
|
|
826
|
-
|
|
827
|
-
children,
|
|
828
|
-
space,
|
|
829
|
-
direction,
|
|
830
|
-
spaceFlex,
|
|
831
|
-
separator
|
|
832
|
-
}) {
|
|
833
|
-
var _a;
|
|
831
|
+
function spacedChildren(props) {
|
|
832
|
+
var _a, _b, _c;
|
|
833
|
+
const { isZStack, children, space, direction, spaceFlex, separator } = props;
|
|
834
834
|
const hasSpace = !!(space || spaceFlex);
|
|
835
835
|
const hasSeparator = !(separator === void 0 || separator === null);
|
|
836
836
|
if (!(hasSpace || hasSeparator || isZStack)) {
|
|
@@ -838,22 +838,20 @@ function spacedChildren({
|
|
|
838
838
|
}
|
|
839
839
|
const childrenList = Children.toArray(children);
|
|
840
840
|
const len = childrenList.length;
|
|
841
|
-
if (len <= 1 && !isZStack) {
|
|
842
|
-
if (len === 1) {
|
|
843
|
-
const [onlyChild] = childrenList;
|
|
844
|
-
if (React.isValidElement(onlyChild) && ((_a = onlyChild.type) == null ? void 0 : _a["shouldForwardSpace"])) {
|
|
845
|
-
return React.cloneElement(onlyChild, {
|
|
846
|
-
space,
|
|
847
|
-
spaceFlex,
|
|
848
|
-
separator
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
}
|
|
841
|
+
if (len <= 1 && !isZStack && !((_b = (_a = childrenList[0]) == null ? void 0 : _a["type"]) == null ? void 0 : _b["shouldForwardSpace"])) {
|
|
852
842
|
return childrenList;
|
|
853
843
|
}
|
|
854
844
|
const final = [];
|
|
855
|
-
for (
|
|
845
|
+
for (let [index, child] of childrenList.entries()) {
|
|
856
846
|
const isEmpty = child === null || child === void 0 || Array.isArray(child) && child.length === 0;
|
|
847
|
+
if (!isEmpty && React.isValidElement(child) && ((_c = child.type) == null ? void 0 : _c["shouldForwardSpace"])) {
|
|
848
|
+
child = React.cloneElement(child, {
|
|
849
|
+
space,
|
|
850
|
+
spaceFlex,
|
|
851
|
+
separator,
|
|
852
|
+
key: child.key
|
|
853
|
+
});
|
|
854
|
+
}
|
|
857
855
|
if (isEmpty || !child || child["key"] && !isZStack) {
|
|
858
856
|
final.push(child);
|
|
859
857
|
} else {
|