@oxyhq/bloom 0.6.19 → 0.6.21
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/lib/commonjs/theme/color-scope/index.js +3 -0
- package/lib/commonjs/theme/color-scope/index.js.map +1 -1
- package/lib/commonjs/theme/color-scope/index.web.js +21 -5
- package/lib/commonjs/theme/color-scope/index.web.js.map +1 -1
- package/lib/module/theme/color-scope/index.js +4 -1
- package/lib/module/theme/color-scope/index.js.map +1 -1
- package/lib/module/theme/color-scope/index.web.js +22 -6
- package/lib/module/theme/color-scope/index.web.js.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts +5 -2
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts +5 -2
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.d.ts +5 -2
- package/lib/typescript/module/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.web.d.ts +5 -2
- package/lib/typescript/module/theme/color-scope/index.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/BloomColorScope.test.tsx +79 -0
- package/src/theme/color-scope/index.tsx +7 -2
- package/src/theme/color-scope/index.web.tsx +33 -4
|
@@ -22,6 +22,9 @@ function BloomColorScope({
|
|
|
22
22
|
if (!parent) {
|
|
23
23
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
24
24
|
}
|
|
25
|
+
if (!colorPreset) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
26
|
+
children: children
|
|
27
|
+
});
|
|
25
28
|
const resolvedMode = parent.theme.mode;
|
|
26
29
|
const contextValue = (0, _react.useMemo)(() => {
|
|
27
30
|
const theme = (0, _buildTheme.buildTheme)(colorPreset, resolvedMode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildNativePresetStyle","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","jsx","Fragment","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildNativePresetStyle","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","View","flex","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAEA,IAAAI,aAAA,GAAAJ,OAAA;AAAyD,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAD,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAA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AAC;EAC5C,IAAI,CAACF,MAAM,EAAE;IACX,MAAM,IAAIG,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,MAAMG,YAAY,GAAGN,MAAM,CAACO,KAAK,CAACC,IAAI;EACtC,OAAO,IAAAE,cAAO,EACZ,MAAM,IAAAG,oCAAsB,EAACjB,WAAW,EAAEU,YAAY,CAAC,EACvD,CAACV,WAAW,EAAEU,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -11,6 +11,16 @@ var _buildTheme = require("../build-theme.js");
|
|
|
11
11
|
var _styleBuilder = require("./style-builder.js");
|
|
12
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
13
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
/**
|
|
15
|
+
* On web, the single `asChild` child is frequently a react-native-web
|
|
16
|
+
* component (e.g. RN `<View>`) whose `style` prop is a *style array* (or a
|
|
17
|
+
* numeric registered-style id), not a plain `React.CSSProperties` object.
|
|
18
|
+
* react-native-web flattens nested style arrays, so the cloned child must
|
|
19
|
+
* receive an array — spreading an array into an object literal would copy its
|
|
20
|
+
* numeric indices as keys and crash RNW when it commits them to the DOM
|
|
21
|
+
* (`Failed to set an indexed property [0] on 'CSSStyleDeclaration'`).
|
|
22
|
+
*/
|
|
23
|
+
|
|
14
24
|
function BloomColorScope({
|
|
15
25
|
colorPreset,
|
|
16
26
|
asChild = false,
|
|
@@ -21,6 +31,9 @@ function BloomColorScope({
|
|
|
21
31
|
if (!parent) {
|
|
22
32
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
23
33
|
}
|
|
34
|
+
if (!colorPreset) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
35
|
+
children: children
|
|
36
|
+
});
|
|
24
37
|
const resolvedMode = parent.theme.mode;
|
|
25
38
|
const contextValue = (0, _react.useMemo)(() => {
|
|
26
39
|
const theme = (0, _buildTheme.buildTheme)(colorPreset, resolvedMode);
|
|
@@ -37,16 +50,19 @@ function BloomColorScope({
|
|
|
37
50
|
if (! /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
|
38
51
|
throw new Error('BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
39
52
|
}
|
|
53
|
+
// Merge as a style ARRAY (the RNW-safe form): scope vars first, then the
|
|
54
|
+
// caller's `style`, then the child's own `style` last so its explicit
|
|
55
|
+
// styles win. react-native-web flattens nested arrays correctly; spreading
|
|
56
|
+
// the child's style (which is often an RN style array or numeric id) into an
|
|
57
|
+
// object literal would copy numeric indices as keys and crash RNW.
|
|
40
58
|
const childStyle = child.props.style;
|
|
41
|
-
const mergedStyle =
|
|
42
|
-
...varsStyle,
|
|
43
|
-
...style,
|
|
44
|
-
...childStyle
|
|
45
|
-
};
|
|
59
|
+
const mergedStyle = [varsStyle, style, childStyle];
|
|
46
60
|
content = /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
47
61
|
style: mergedStyle
|
|
48
62
|
});
|
|
49
63
|
} else {
|
|
64
|
+
// A plain DOM `<div>` does NOT accept style arrays — only the cloned child
|
|
65
|
+
// path can, so the wrapper keeps using an object spread.
|
|
50
66
|
const mergedStyle = {
|
|
51
67
|
...varsStyle,
|
|
52
68
|
...style
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildScopeVars","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","jsx","Fragment","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildScopeVars","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAAiD,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAD,wBAAAM,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,CAAAM,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX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,YAAY,GAAGN,MAAM,CAACO,KAAK,CAACC,IAAI;EACtC,OAAO,IAAAE,cAAO,EACZ,MAAM,IAAAG,4BAAc,EAACjB,WAAW,EAAEU,YAAY,CAAwB,EACtE,CAACV,WAAW,EAAEU,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import { View } from 'react-native';
|
|
|
5
5
|
import { BloomThemeContext } from "../BloomThemeProvider.js";
|
|
6
6
|
import { buildTheme } from "../build-theme.js";
|
|
7
7
|
import { buildNativePresetStyle } from "./style-builder.js";
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export function BloomColorScope({
|
|
10
10
|
colorPreset,
|
|
11
11
|
asChild = false,
|
|
@@ -16,6 +16,9 @@ export function BloomColorScope({
|
|
|
16
16
|
if (!parent) {
|
|
17
17
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
18
18
|
}
|
|
19
|
+
if (!colorPreset) return /*#__PURE__*/_jsx(_Fragment, {
|
|
20
|
+
children: children
|
|
21
|
+
});
|
|
19
22
|
const resolvedMode = parent.theme.mode;
|
|
20
23
|
const contextValue = useMemo(() => {
|
|
21
24
|
const theme = buildTheme(colorPreset, resolvedMode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","View","BloomThemeContext","buildTheme","buildNativePresetStyle","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","content","child","only","childStyle","props","mergedStyle","flex","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC1F,SAASC,IAAI,QAAwC,cAAc;AAEnE,SAASC,iBAAiB,QAAqC,0BAAuB;AACtF,SAASC,UAAU,QAAQ,mBAAgB;AAE3C,SAASC,sBAAsB,QAAQ,oBAAiB;AAAC,SAAAC,GAAA,IAAAC,IAAA;
|
|
1
|
+
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","View","BloomThemeContext","buildTheme","buildNativePresetStyle","Fragment","_Fragment","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","content","child","only","childStyle","props","mergedStyle","flex","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC1F,SAASC,IAAI,QAAwC,cAAc;AAEnE,SAASC,iBAAiB,QAAqC,0BAAuB;AACtF,SAASC,UAAU,QAAQ,mBAAgB;AAE3C,SAASC,sBAAsB,QAAQ,oBAAiB;AAAC,SAAAC,QAAA,IAAAC,SAAA,EAAAC,GAAA,IAAAC,IAAA;AAsBzD,OAAO,SAASC,eAAeA,CAAC;EAC9BC,WAAW;EACXC,OAAO,GAAG,KAAK;EACfC,KAAK;EACLC;AACoB,CAAC,EAAE;EACvB,MAAMC,MAAM,GAAGf,UAAU,CAACG,iBAAiB,CAAC;EAC5C,IAAI,CAACY,MAAM,EAAE;IACX,MAAM,IAAIC,KAAK,CAAC,4DAA4D,CAAC;EAC/E;EAEA,IAAI,CAACL,WAAW,EAAE,oBAAOF,IAAA,CAAAF,SAAA;IAAAO,QAAA,EAAGA;EAAQ,CAAG,CAAC;EAExC,MAAMG,YAAY,GAAGF,MAAM,CAACG,KAAK,CAACC,IAAI;EAEtC,MAAMC,YAAY,GAAGnB,OAAO,CAAyB,MAAM;IACzD,MAAMiB,KAAK,GAAGd,UAAU,CAACO,WAAW,EAAEM,YAAY,CAA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,GAAGF,MAAM,CAACG,KAAK,CAACC,IAAI;EACtC,OAAOlB,OAAO,CACZ,MAAMI,sBAAsB,CAACM,WAAW,EAAEM,YAAY,CAAC,EACvD,CAACN,WAAW,EAAEM,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -4,7 +4,17 @@ import React, { Children, cloneElement, isValidElement, useContext, useMemo } fr
|
|
|
4
4
|
import { BloomThemeContext } from "../BloomThemeProvider.js";
|
|
5
5
|
import { buildTheme } from "../build-theme.js";
|
|
6
6
|
import { buildScopeVars } from "./style-builder.js";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* On web, the single `asChild` child is frequently a react-native-web
|
|
10
|
+
* component (e.g. RN `<View>`) whose `style` prop is a *style array* (or a
|
|
11
|
+
* numeric registered-style id), not a plain `React.CSSProperties` object.
|
|
12
|
+
* react-native-web flattens nested style arrays, so the cloned child must
|
|
13
|
+
* receive an array — spreading an array into an object literal would copy its
|
|
14
|
+
* numeric indices as keys and crash RNW when it commits them to the DOM
|
|
15
|
+
* (`Failed to set an indexed property [0] on 'CSSStyleDeclaration'`).
|
|
16
|
+
*/
|
|
17
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
8
18
|
export function BloomColorScope({
|
|
9
19
|
colorPreset,
|
|
10
20
|
asChild = false,
|
|
@@ -15,6 +25,9 @@ export function BloomColorScope({
|
|
|
15
25
|
if (!parent) {
|
|
16
26
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
17
27
|
}
|
|
28
|
+
if (!colorPreset) return /*#__PURE__*/_jsx(_Fragment, {
|
|
29
|
+
children: children
|
|
30
|
+
});
|
|
18
31
|
const resolvedMode = parent.theme.mode;
|
|
19
32
|
const contextValue = useMemo(() => {
|
|
20
33
|
const theme = buildTheme(colorPreset, resolvedMode);
|
|
@@ -31,16 +44,19 @@ export function BloomColorScope({
|
|
|
31
44
|
if (! /*#__PURE__*/isValidElement(child)) {
|
|
32
45
|
throw new Error('BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
33
46
|
}
|
|
47
|
+
// Merge as a style ARRAY (the RNW-safe form): scope vars first, then the
|
|
48
|
+
// caller's `style`, then the child's own `style` last so its explicit
|
|
49
|
+
// styles win. react-native-web flattens nested arrays correctly; spreading
|
|
50
|
+
// the child's style (which is often an RN style array or numeric id) into an
|
|
51
|
+
// object literal would copy numeric indices as keys and crash RNW.
|
|
34
52
|
const childStyle = child.props.style;
|
|
35
|
-
const mergedStyle =
|
|
36
|
-
...varsStyle,
|
|
37
|
-
...style,
|
|
38
|
-
...childStyle
|
|
39
|
-
};
|
|
53
|
+
const mergedStyle = [varsStyle, style, childStyle];
|
|
40
54
|
content = /*#__PURE__*/cloneElement(child, {
|
|
41
55
|
style: mergedStyle
|
|
42
56
|
});
|
|
43
57
|
} else {
|
|
58
|
+
// A plain DOM `<div>` does NOT accept style arrays — only the cloned child
|
|
59
|
+
// path can, so the wrapper keeps using an object spread.
|
|
44
60
|
const mergedStyle = {
|
|
45
61
|
...varsStyle,
|
|
46
62
|
...style
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","BloomThemeContext","buildTheme","buildScopeVars","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","content","child","only","childStyle","props","mergedStyle","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAE1F,SAASC,iBAAiB,QAAqC,0BAAuB;AACtF,SAASC,UAAU,QAAQ,mBAAgB;AAE3C,SAASC,cAAc,QAAQ,oBAAiB;
|
|
1
|
+
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","BloomThemeContext","buildTheme","buildScopeVars","Fragment","_Fragment","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","content","child","only","childStyle","props","mergedStyle","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAE1F,SAASC,iBAAiB,QAAqC,0BAAuB;AACtF,SAASC,UAAU,QAAQ,mBAAgB;AAE3C,SAASC,cAAc,QAAQ,oBAAiB;;AAkBhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AARA,SAAAC,QAAA,IAAAC,SAAA,EAAAC,GAAA,IAAAC,IAAA;AAqBA,OAAO,SAASC,eAAeA,CAAC;EAC9BC,WAAW;EACXC,OAAO,GAAG,KAAK;EACfC,KAAK;EACLC;AACoB,CAAC,EAAE;EACvB,MAAMC,MAAM,GAAGd,UAAU,CAACE,iBAAiB,CAAC;EAC5C,IAAI,CAACY,MAAM,EAAE;IACX,MAAM,IAAIC,KAAK,CAAC,4DAA4D,CAAC;EAC/E;EAEA,IAAI,CAACL,WAAW,EAAE,oBAAOF,IAAA,CAAAF,SAAA;IAAAO,QAAA,EAAGA;EAAQ,CAAG,CAAC;EAExC,MAAMG,YAAY,GAAGF,MAAM,CAACG,KAAK,CAACC,IAAI;EAEtC,MAAMC,YAAY,GAAGlB,OAAO,CAAyB,MAAM;IACzD,MAAMgB,KAAK,GAAGd,UAAU,CAACO,WAAW,EAAEM,YAAY,CAAC;IACnD,OAAO;MAAE,GAAGF,MAAM;MAAEG,KAAK;MAAEP;IAAY,CAAC;EAC1C,CAAC,EAAE,CAACA,WAAW,EAAEM,YAAY,EAAEF,MAAM,CAAC,CAAC;EAEvC,MAAMM,SAAS,GAAGnB,OAAO,CACvB,MAAMG,cAAc,CAACM,WAAW,EAAEM,YA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2,11 @@ import React from 'react';
|
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
import type { AppColorName } from '../color-presets';
|
|
4
4
|
export interface BloomColorScopeProps {
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
7
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
8
|
+
*/
|
|
9
|
+
colorPreset: AppColorName | undefined;
|
|
7
10
|
/**
|
|
8
11
|
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
9
12
|
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAoCtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAUlF"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { AppColorName } from '../color-presets';
|
|
3
3
|
export interface BloomColorScopeProps {
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
6
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
7
|
+
*/
|
|
8
|
+
colorPreset: AppColorName | undefined;
|
|
6
9
|
/**
|
|
7
10
|
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
8
11
|
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAuBD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CA4CtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAUjF"}
|
|
@@ -2,8 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
import type { AppColorName } from '../color-presets';
|
|
4
4
|
export interface BloomColorScopeProps {
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
7
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
8
|
+
*/
|
|
9
|
+
colorPreset: AppColorName | undefined;
|
|
7
10
|
/**
|
|
8
11
|
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
9
12
|
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAoCtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAUlF"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { AppColorName } from '../color-presets';
|
|
3
3
|
export interface BloomColorScopeProps {
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
6
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
7
|
+
*/
|
|
8
|
+
colorPreset: AppColorName | undefined;
|
|
6
9
|
/**
|
|
7
10
|
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
8
11
|
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAuBD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CA4CtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAUjF"}
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { render } from '@testing-library/react-native';
|
|
|
4
4
|
|
|
5
5
|
import { BloomThemeProvider } from '../theme/BloomThemeProvider';
|
|
6
6
|
import { BloomColorScope } from '../theme/color-scope';
|
|
7
|
+
import { BloomColorScope as BloomColorScopeWeb } from '../theme/color-scope/index.web';
|
|
7
8
|
import { useBloomTheme } from '../theme/use-theme';
|
|
8
9
|
|
|
9
10
|
function CurrentPreset() {
|
|
@@ -48,6 +49,18 @@ describe('BloomColorScope', () => {
|
|
|
48
49
|
);
|
|
49
50
|
});
|
|
50
51
|
|
|
52
|
+
it('is a no-op when colorPreset is undefined (children inherit parent scope)', () => {
|
|
53
|
+
const { getByTestId } = render(
|
|
54
|
+
<BloomThemeProvider defaultColorPreset="blue" fonts={false}>
|
|
55
|
+
<BloomColorScope colorPreset={undefined}>
|
|
56
|
+
<CurrentPreset />
|
|
57
|
+
</BloomColorScope>
|
|
58
|
+
</BloomThemeProvider>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(getByTestId('preset').props.children).toBe('blue');
|
|
62
|
+
});
|
|
63
|
+
|
|
51
64
|
it('throws when asChild has multiple children', () => {
|
|
52
65
|
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
53
66
|
expect(() =>
|
|
@@ -74,4 +87,70 @@ describe('BloomColorScope', () => {
|
|
|
74
87
|
).toThrow('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
75
88
|
consoleError.mockRestore();
|
|
76
89
|
});
|
|
90
|
+
|
|
91
|
+
// Web variant: regression for the production crash on mention.earth profile
|
|
92
|
+
// screens. On web the `asChild` child is frequently an RNW component whose
|
|
93
|
+
// `style` is a React Native style ARRAY. The web variant must merge styles as
|
|
94
|
+
// an array (RNW flattens it) and must NOT spread the array into an object
|
|
95
|
+
// literal — that copies the array's numeric indices as keys and makes RNW
|
|
96
|
+
// throw `Failed to set an indexed property [0] on 'CSSStyleDeclaration'`.
|
|
97
|
+
describe('web variant (index.web)', () => {
|
|
98
|
+
it('merges an array-valued child style without producing numeric index keys (asChild)', () => {
|
|
99
|
+
const { getByTestId } = render(
|
|
100
|
+
<BloomThemeProvider defaultColorPreset="blue" fonts={false}>
|
|
101
|
+
<BloomColorScopeWeb colorPreset="purple" asChild>
|
|
102
|
+
<StyledChild style={[{ padding: 8 }, { margin: 4 }]} />
|
|
103
|
+
</BloomColorScopeWeb>
|
|
104
|
+
</BloomThemeProvider>,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(getByTestId('preset').props.children).toBe('purple');
|
|
108
|
+
|
|
109
|
+
const mergedStyle = getByTestId('styled-child').props.style;
|
|
110
|
+
// The merge must be an array (the RNW-safe form), never an object literal
|
|
111
|
+
// with the array's numeric indices spread in as keys.
|
|
112
|
+
expect(Array.isArray(mergedStyle)).toBe(true);
|
|
113
|
+
|
|
114
|
+
// No numeric index keys must appear anywhere in the merged style. If the
|
|
115
|
+
// child array had been spread into an object literal, we'd see '0', '1'.
|
|
116
|
+
const collectKeys = (value: unknown): string[] => {
|
|
117
|
+
if (Array.isArray(value)) return value.flatMap(collectKeys);
|
|
118
|
+
if (value && typeof value === 'object') return Object.keys(value);
|
|
119
|
+
return [];
|
|
120
|
+
};
|
|
121
|
+
const keys = collectKeys(mergedStyle);
|
|
122
|
+
expect(keys).not.toContain('0');
|
|
123
|
+
expect(keys).not.toContain('1');
|
|
124
|
+
|
|
125
|
+
// The child's own array styles must be preserved (and win over scope vars).
|
|
126
|
+
const flat = (Array.isArray(mergedStyle) ? mergedStyle : [mergedStyle])
|
|
127
|
+
.flat(Infinity)
|
|
128
|
+
.filter((entry): entry is Record<string, unknown> => Boolean(entry) && typeof entry === 'object');
|
|
129
|
+
expect(flat).toEqual(
|
|
130
|
+
expect.arrayContaining([
|
|
131
|
+
expect.objectContaining({ padding: 8 }),
|
|
132
|
+
expect.objectContaining({ margin: 4 }),
|
|
133
|
+
]),
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('clones the single child and merges scope vars into its style array (asChild)', () => {
|
|
138
|
+
const { getByTestId } = render(
|
|
139
|
+
<BloomThemeProvider defaultColorPreset="blue" fonts={false}>
|
|
140
|
+
<BloomColorScopeWeb colorPreset="purple" asChild>
|
|
141
|
+
<StyledChild style={{ padding: 8 }} />
|
|
142
|
+
</BloomColorScopeWeb>
|
|
143
|
+
</BloomThemeProvider>,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const mergedStyle = getByTestId('styled-child').props.style;
|
|
147
|
+
expect(Array.isArray(mergedStyle)).toBe(true);
|
|
148
|
+
const flat = (Array.isArray(mergedStyle) ? mergedStyle : [mergedStyle])
|
|
149
|
+
.flat(Infinity)
|
|
150
|
+
.filter((entry): entry is Record<string, unknown> => Boolean(entry) && typeof entry === 'object');
|
|
151
|
+
expect(flat).toEqual(
|
|
152
|
+
expect.arrayContaining([expect.objectContaining({ padding: 8 })]),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
77
156
|
});
|
|
@@ -7,8 +7,11 @@ import type { AppColorName } from '../color-presets';
|
|
|
7
7
|
import { buildNativePresetStyle } from './style-builder';
|
|
8
8
|
|
|
9
9
|
export interface BloomColorScopeProps {
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
12
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
13
|
+
*/
|
|
14
|
+
colorPreset: AppColorName | undefined;
|
|
12
15
|
/**
|
|
13
16
|
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
14
17
|
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
@@ -34,6 +37,8 @@ export function BloomColorScope({
|
|
|
34
37
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
if (!colorPreset) return <>{children}</>;
|
|
41
|
+
|
|
37
42
|
const resolvedMode = parent.theme.mode;
|
|
38
43
|
|
|
39
44
|
const contextValue = useMemo<BloomThemeContextValue>(() => {
|
|
@@ -6,8 +6,11 @@ import type { AppColorName } from '../color-presets';
|
|
|
6
6
|
import { buildScopeVars } from './style-builder';
|
|
7
7
|
|
|
8
8
|
export interface BloomColorScopeProps {
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
11
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
12
|
+
*/
|
|
13
|
+
colorPreset: AppColorName | undefined;
|
|
11
14
|
/**
|
|
12
15
|
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
13
16
|
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
@@ -18,8 +21,25 @@ export interface BloomColorScopeProps {
|
|
|
18
21
|
children: React.ReactNode;
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
/**
|
|
25
|
+
* On web, the single `asChild` child is frequently a react-native-web
|
|
26
|
+
* component (e.g. RN `<View>`) whose `style` prop is a *style array* (or a
|
|
27
|
+
* numeric registered-style id), not a plain `React.CSSProperties` object.
|
|
28
|
+
* react-native-web flattens nested style arrays, so the cloned child must
|
|
29
|
+
* receive an array — spreading an array into an object literal would copy its
|
|
30
|
+
* numeric indices as keys and crash RNW when it commits them to the DOM
|
|
31
|
+
* (`Failed to set an indexed property [0] on 'CSSStyleDeclaration'`).
|
|
32
|
+
*/
|
|
33
|
+
type WebStyle =
|
|
34
|
+
| React.CSSProperties
|
|
35
|
+
| number
|
|
36
|
+
| null
|
|
37
|
+
| undefined
|
|
38
|
+
| false
|
|
39
|
+
| ReadonlyArray<WebStyle>;
|
|
40
|
+
|
|
21
41
|
interface StyleableProps {
|
|
22
|
-
style?:
|
|
42
|
+
style?: WebStyle;
|
|
23
43
|
}
|
|
24
44
|
|
|
25
45
|
export function BloomColorScope({
|
|
@@ -33,6 +53,8 @@ export function BloomColorScope({
|
|
|
33
53
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
34
54
|
}
|
|
35
55
|
|
|
56
|
+
if (!colorPreset) return <>{children}</>;
|
|
57
|
+
|
|
36
58
|
const resolvedMode = parent.theme.mode;
|
|
37
59
|
|
|
38
60
|
const contextValue = useMemo<BloomThemeContextValue>(() => {
|
|
@@ -53,10 +75,17 @@ export function BloomColorScope({
|
|
|
53
75
|
'BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.',
|
|
54
76
|
);
|
|
55
77
|
}
|
|
78
|
+
// Merge as a style ARRAY (the RNW-safe form): scope vars first, then the
|
|
79
|
+
// caller's `style`, then the child's own `style` last so its explicit
|
|
80
|
+
// styles win. react-native-web flattens nested arrays correctly; spreading
|
|
81
|
+
// the child's style (which is often an RN style array or numeric id) into an
|
|
82
|
+
// object literal would copy numeric indices as keys and crash RNW.
|
|
56
83
|
const childStyle = child.props.style;
|
|
57
|
-
const mergedStyle:
|
|
84
|
+
const mergedStyle: WebStyle = [varsStyle, style, childStyle];
|
|
58
85
|
content = cloneElement(child, { style: mergedStyle });
|
|
59
86
|
} else {
|
|
87
|
+
// A plain DOM `<div>` does NOT accept style arrays — only the cloned child
|
|
88
|
+
// path can, so the wrapper keeps using an object spread.
|
|
60
89
|
const mergedStyle: React.CSSProperties = { ...varsStyle, ...style };
|
|
61
90
|
content = <div style={mergedStyle}>{children}</div>;
|
|
62
91
|
}
|