@griffel/react 1.3.2 → 1.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/index.cjs.js +2 -0
- package/index.cjs.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.esm.js +1 -0
- package/index.esm.js.map +1 -1
- package/makeResetStyles.cjs.js +30 -0
- package/makeResetStyles.cjs.js.map +1 -0
- package/makeResetStyles.d.ts +2 -0
- package/makeResetStyles.esm.js +26 -0
- package/makeResetStyles.esm.js.map +1 -0
- package/makeStyles.cjs.js +2 -42
- package/makeStyles.cjs.js.map +1 -1
- package/makeStyles.esm.js +1 -21
- package/makeStyles.esm.js.map +1 -1
- package/package.json +2 -2
- package/utils/isInsideComponent.cjs.js +48 -0
- package/utils/isInsideComponent.cjs.js.map +1 -0
- package/utils/isInsideComponent.d.ts +1 -0
- package/utils/isInsideComponent.esm.js +24 -0
- package/utils/isInsideComponent.esm.js.map +1 -0
package/index.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@griffel/core');
|
|
6
6
|
var makeStyles = require('./makeStyles.cjs.js');
|
|
7
|
+
var makeResetStyles = require('./makeResetStyles.cjs.js');
|
|
7
8
|
var makeStaticStyles = require('./makeStaticStyles.cjs.js');
|
|
8
9
|
var renderToStyleElements = require('./renderToStyleElements.cjs.js');
|
|
9
10
|
var RendererContext = require('./RendererContext.cjs.js');
|
|
@@ -26,6 +27,7 @@ Object.defineProperty(exports, 'shorthands', {
|
|
|
26
27
|
get: function () { return core.shorthands; }
|
|
27
28
|
});
|
|
28
29
|
exports.makeStyles = makeStyles.makeStyles;
|
|
30
|
+
exports.makeResetStyles = makeResetStyles.makeResetStyles;
|
|
29
31
|
exports.makeStaticStyles = makeStaticStyles.makeStaticStyles;
|
|
30
32
|
exports.renderToStyleElements = renderToStyleElements.renderToStyleElements;
|
|
31
33
|
exports.RendererProvider = RendererContext.RendererProvider;
|
package/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { shorthands, mergeClasses, createDOMRenderer } from '@griffel/core';
|
|
2
2
|
export type { GriffelStyle, CreateDOMRendererOptions, GriffelRenderer } from '@griffel/core';
|
|
3
3
|
export { makeStyles } from './makeStyles';
|
|
4
|
+
export { makeResetStyles } from './makeResetStyles';
|
|
4
5
|
export { makeStaticStyles } from './makeStaticStyles';
|
|
5
6
|
export { renderToStyleElements } from './renderToStyleElements';
|
|
6
7
|
export { RendererProvider, useRenderer as useRenderer_unstable } from './RendererContext';
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createDOMRenderer, mergeClasses, shorthands } from '@griffel/core';
|
|
2
2
|
export { makeStyles } from './makeStyles.esm.js';
|
|
3
|
+
export { makeResetStyles } from './makeResetStyles.esm.js';
|
|
3
4
|
export { makeStaticStyles } from './makeStaticStyles.esm.js';
|
|
4
5
|
export { renderToStyleElements } from './renderToStyleElements.esm.js';
|
|
5
6
|
export { RendererProvider, useRenderer as useRenderer_unstable } from './RendererContext.esm.js';
|
package/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@griffel/core');
|
|
6
|
+
var isInsideComponent = require('./utils/isInsideComponent.cjs.js');
|
|
7
|
+
var RendererContext = require('./RendererContext.cjs.js');
|
|
8
|
+
var TextDirectionContext = require('./TextDirectionContext.cjs.js');
|
|
9
|
+
|
|
10
|
+
function makeResetStyles(styles) {
|
|
11
|
+
const getStyles = core.makeResetStyles(styles);
|
|
12
|
+
|
|
13
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
+
if (isInsideComponent.isInsideComponent()) {
|
|
15
|
+
throw new Error(["makeResetStyles(): this function cannot be called in component's scope.", 'All makeResetStyles() calls should be top level i.e. in a root scope of a file.'].join(' '));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return function useClassName() {
|
|
20
|
+
const dir = TextDirectionContext.useTextDirection();
|
|
21
|
+
const renderer = RendererContext.useRenderer();
|
|
22
|
+
return getStyles({
|
|
23
|
+
dir,
|
|
24
|
+
renderer
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.makeResetStyles = makeResetStyles;
|
|
30
|
+
//# sourceMappingURL=makeResetStyles.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeResetStyles.cjs.js","sources":["../../../packages/react/src/makeResetStyles.ts"],"sourcesContent":["import { makeResetStyles as vanillaMakeResetStyles } from '@griffel/core';\nimport type { GriffelResetStyle } from '@griffel/core';\n\nimport { isInsideComponent } from './utils/isInsideComponent';\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\nexport function makeResetStyles(styles: GriffelResetStyle) {\n const getStyles = vanillaMakeResetStyles(styles);\n\n if (process.env.NODE_ENV !== 'production') {\n if (isInsideComponent()) {\n throw new Error(\n [\n \"makeResetStyles(): this function cannot be called in component's scope.\",\n 'All makeResetStyles() calls should be top level i.e. in a root scope of a file.',\n ].join(' '),\n );\n }\n }\n\n return function useClassName(): string {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["makeResetStyles","styles","getStyles","vanillaMakeResetStyles","process","env","NODE_ENV","isInsideComponent","Error","join","useClassName","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;;;;;SAOgBA,gBAAgBC;EAC9B,MAAMC,SAAS,GAAGC,oBAAsB,CAACF,MAAD,CAAxC;;EAEA,IAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAIC,mCAAiB,EAArB,EAAyB;MACvB,MAAM,IAAIC,KAAJ,CACJ,CACE,yEADF,EAEE,iFAFF,EAGEC,IAHF,CAGO,GAHP,CADI,CAAN;;;;EASJ,OAAO,SAASC,YAAT;IACL,MAAMC,GAAG,GAAGC,qCAAgB,EAA5B;IACA,MAAMC,QAAQ,GAAGC,2BAAW,EAA5B;IAEA,OAAOZ,SAAS,CAAC;MAAES,GAAF;MAAOE;KAAR,CAAhB;GAJF;AAMD;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { makeResetStyles as makeResetStyles$1 } from '@griffel/core';
|
|
2
|
+
import { isInsideComponent } from './utils/isInsideComponent.esm.js';
|
|
3
|
+
import { useRenderer } from './RendererContext.esm.js';
|
|
4
|
+
import { useTextDirection } from './TextDirectionContext.esm.js';
|
|
5
|
+
|
|
6
|
+
function makeResetStyles(styles) {
|
|
7
|
+
const getStyles = makeResetStyles$1(styles);
|
|
8
|
+
|
|
9
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
10
|
+
if (isInsideComponent()) {
|
|
11
|
+
throw new Error(["makeResetStyles(): this function cannot be called in component's scope.", 'All makeResetStyles() calls should be top level i.e. in a root scope of a file.'].join(' '));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return function useClassName() {
|
|
16
|
+
const dir = useTextDirection();
|
|
17
|
+
const renderer = useRenderer();
|
|
18
|
+
return getStyles({
|
|
19
|
+
dir,
|
|
20
|
+
renderer
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { makeResetStyles };
|
|
26
|
+
//# sourceMappingURL=makeResetStyles.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeResetStyles.esm.js","sources":["../../../packages/react/src/makeResetStyles.ts"],"sourcesContent":["import { makeResetStyles as vanillaMakeResetStyles } from '@griffel/core';\nimport type { GriffelResetStyle } from '@griffel/core';\n\nimport { isInsideComponent } from './utils/isInsideComponent';\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\nexport function makeResetStyles(styles: GriffelResetStyle) {\n const getStyles = vanillaMakeResetStyles(styles);\n\n if (process.env.NODE_ENV !== 'production') {\n if (isInsideComponent()) {\n throw new Error(\n [\n \"makeResetStyles(): this function cannot be called in component's scope.\",\n 'All makeResetStyles() calls should be top level i.e. in a root scope of a file.',\n ].join(' '),\n );\n }\n }\n\n return function useClassName(): string {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["makeResetStyles","styles","getStyles","vanillaMakeResetStyles","process","env","NODE_ENV","isInsideComponent","Error","join","useClassName","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;SAOgBA,gBAAgBC;EAC9B,MAAMC,SAAS,GAAGC,iBAAsB,CAACF,MAAD,CAAxC;;EAEA,IAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAIC,iBAAiB,EAArB,EAAyB;MACvB,MAAM,IAAIC,KAAJ,CACJ,CACE,yEADF,EAEE,iFAFF,EAGEC,IAHF,CAGO,GAHP,CADI,CAAN;;;;EASJ,OAAO,SAASC,YAAT;IACL,MAAMC,GAAG,GAAGC,gBAAgB,EAA5B;IACA,MAAMC,QAAQ,GAAGC,WAAW,EAA5B;IAEA,OAAOZ,SAAS,CAAC;MAAES,GAAF;MAAOE;KAAR,CAAhB;GAJF;AAMD;;;;"}
|
package/makeStyles.cjs.js
CHANGED
|
@@ -3,55 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@griffel/core');
|
|
6
|
-
var
|
|
6
|
+
var isInsideComponent = require('./utils/isInsideComponent.cjs.js');
|
|
7
7
|
var RendererContext = require('./RendererContext.cjs.js');
|
|
8
8
|
var TextDirectionContext = require('./TextDirectionContext.cjs.js');
|
|
9
9
|
|
|
10
|
-
function _interopNamespace(e) {
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
12
|
-
var n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
Object.keys(e).forEach(function (k) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
n["default"] = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
-
|
|
30
|
-
function isInsideComponent() {
|
|
31
|
-
// React 18 always logs errors if a dispatcher is not present:
|
|
32
|
-
// https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36
|
|
33
|
-
try {
|
|
34
|
-
// @ts-expect-error "SECRET_INTERNALS" are not typed
|
|
35
|
-
const dispatcher = React__namespace.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current; // Before any React component was rendered "dispatcher" will be "null"
|
|
36
|
-
|
|
37
|
-
if (dispatcher === null || dispatcher === undefined) {
|
|
38
|
-
return false;
|
|
39
|
-
} // A check with hooks call (i.e. call "React.useContext()" outside a component) will always produce errors, but
|
|
40
|
-
// a call on the dispatcher don't
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
dispatcher.useContext({});
|
|
44
|
-
return true;
|
|
45
|
-
} catch (e) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
10
|
function makeStyles(stylesBySlots) {
|
|
51
11
|
const getStyles = core.makeStyles(stylesBySlots);
|
|
52
12
|
|
|
53
13
|
if (process.env.NODE_ENV !== 'production') {
|
|
54
|
-
if (isInsideComponent()) {
|
|
14
|
+
if (isInsideComponent.isInsideComponent()) {
|
|
55
15
|
throw new Error(["makeStyles(): this function cannot be called in component's scope.", 'All makeStyles() calls should be top level i.e. in a root scope of a file.'].join(' '));
|
|
56
16
|
}
|
|
57
17
|
}
|
package/makeStyles.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeStyles.cjs.js","sources":["../../../packages/react/src/makeStyles.ts"],"sourcesContent":["import { makeStyles as vanillaMakeStyles } from '@griffel/core';\nimport
|
|
1
|
+
{"version":3,"file":"makeStyles.cjs.js","sources":["../../../packages/react/src/makeStyles.ts"],"sourcesContent":["import { makeStyles as vanillaMakeStyles } from '@griffel/core';\nimport type { GriffelStyle } from '@griffel/core';\n\nimport { isInsideComponent } from './utils/isInsideComponent';\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\nexport function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>) {\n const getStyles = vanillaMakeStyles(stylesBySlots);\n\n if (process.env.NODE_ENV !== 'production') {\n if (isInsideComponent()) {\n throw new Error(\n [\n \"makeStyles(): this function cannot be called in component's scope.\",\n 'All makeStyles() calls should be top level i.e. in a root scope of a file.',\n ].join(' '),\n );\n }\n }\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["makeStyles","stylesBySlots","getStyles","vanillaMakeStyles","process","env","NODE_ENV","isInsideComponent","Error","join","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;;;;;SAOgBA,WAA0CC;EACxD,MAAMC,SAAS,GAAGC,eAAiB,CAACF,aAAD,CAAnC;;EAEA,IAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAIC,mCAAiB,EAArB,EAAyB;MACvB,MAAM,IAAIC,KAAJ,CACJ,CACE,oEADF,EAEE,4EAFF,EAGEC,IAHF,CAGO,GAHP,CADI,CAAN;;;;EASJ,OAAO,SAASC,UAAT;IACL,MAAMC,GAAG,GAAGC,qCAAgB,EAA5B;IACA,MAAMC,QAAQ,GAAGC,2BAAW,EAA5B;IAEA,OAAOZ,SAAS,CAAC;MAAES,GAAF;MAAOE;KAAR,CAAhB;GAJF;AAMD;;;;"}
|
package/makeStyles.esm.js
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { makeStyles as makeStyles$1 } from '@griffel/core';
|
|
2
|
-
import
|
|
2
|
+
import { isInsideComponent } from './utils/isInsideComponent.esm.js';
|
|
3
3
|
import { useRenderer } from './RendererContext.esm.js';
|
|
4
4
|
import { useTextDirection } from './TextDirectionContext.esm.js';
|
|
5
5
|
|
|
6
|
-
function isInsideComponent() {
|
|
7
|
-
// React 18 always logs errors if a dispatcher is not present:
|
|
8
|
-
// https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36
|
|
9
|
-
try {
|
|
10
|
-
// @ts-expect-error "SECRET_INTERNALS" are not typed
|
|
11
|
-
const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current; // Before any React component was rendered "dispatcher" will be "null"
|
|
12
|
-
|
|
13
|
-
if (dispatcher === null || dispatcher === undefined) {
|
|
14
|
-
return false;
|
|
15
|
-
} // A check with hooks call (i.e. call "React.useContext()" outside a component) will always produce errors, but
|
|
16
|
-
// a call on the dispatcher don't
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
dispatcher.useContext({});
|
|
20
|
-
return true;
|
|
21
|
-
} catch (e) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
6
|
function makeStyles(stylesBySlots) {
|
|
27
7
|
const getStyles = makeStyles$1(stylesBySlots);
|
|
28
8
|
|
package/makeStyles.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeStyles.esm.js","sources":["../../../packages/react/src/makeStyles.ts"],"sourcesContent":["import { makeStyles as vanillaMakeStyles } from '@griffel/core';\nimport
|
|
1
|
+
{"version":3,"file":"makeStyles.esm.js","sources":["../../../packages/react/src/makeStyles.ts"],"sourcesContent":["import { makeStyles as vanillaMakeStyles } from '@griffel/core';\nimport type { GriffelStyle } from '@griffel/core';\n\nimport { isInsideComponent } from './utils/isInsideComponent';\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\nexport function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>) {\n const getStyles = vanillaMakeStyles(stylesBySlots);\n\n if (process.env.NODE_ENV !== 'production') {\n if (isInsideComponent()) {\n throw new Error(\n [\n \"makeStyles(): this function cannot be called in component's scope.\",\n 'All makeStyles() calls should be top level i.e. in a root scope of a file.',\n ].join(' '),\n );\n }\n }\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["makeStyles","stylesBySlots","getStyles","vanillaMakeStyles","process","env","NODE_ENV","isInsideComponent","Error","join","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;SAOgBA,WAA0CC;EACxD,MAAMC,SAAS,GAAGC,YAAiB,CAACF,aAAD,CAAnC;;EAEA,IAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAIC,iBAAiB,EAArB,EAAyB;MACvB,MAAM,IAAIC,KAAJ,CACJ,CACE,oEADF,EAEE,4EAFF,EAGEC,IAHF,CAGO,GAHP,CADI,CAAN;;;;EASJ,OAAO,SAASC,UAAT;IACL,MAAMC,GAAG,GAAGC,gBAAgB,EAA5B;IACA,MAAMC,QAAQ,GAAGC,WAAW,EAA5B;IAEA,OAAOZ,SAAS,CAAC;MAAES,GAAF;MAAOE;KAAR,CAAhB;GAJF;AAMD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griffel/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "React implementation of Atomic CSS-in-JS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@griffel/core": "^1.
|
|
12
|
+
"@griffel/core": "^1.7.0",
|
|
13
13
|
"tslib": "^2.1.0"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n["default"] = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
26
|
+
|
|
27
|
+
function isInsideComponent() {
|
|
28
|
+
// React 18 always logs errors if a dispatcher is not present:
|
|
29
|
+
// https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36
|
|
30
|
+
try {
|
|
31
|
+
// @ts-expect-error "SECRET_INTERNALS" are not typed
|
|
32
|
+
const dispatcher = React__namespace.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current; // Before any React component was rendered "dispatcher" will be "null"
|
|
33
|
+
|
|
34
|
+
if (dispatcher === null || dispatcher === undefined) {
|
|
35
|
+
return false;
|
|
36
|
+
} // A check with hooks call (i.e. call "React.useContext()" outside a component) will always produce errors, but
|
|
37
|
+
// a call on the dispatcher wont
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
dispatcher.useContext({});
|
|
41
|
+
return true;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.isInsideComponent = isInsideComponent;
|
|
48
|
+
//# sourceMappingURL=isInsideComponent.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isInsideComponent.cjs.js","sources":["../../../../packages/react/src/utils/isInsideComponent.ts"],"sourcesContent":["import * as React from 'react';\n\nexport function isInsideComponent() {\n // React 18 always logs errors if a dispatcher is not present:\n // https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36\n try {\n // @ts-expect-error \"SECRET_INTERNALS\" are not typed\n const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;\n\n // Before any React component was rendered \"dispatcher\" will be \"null\"\n if (dispatcher === null || dispatcher === undefined) {\n return false;\n }\n\n // A check with hooks call (i.e. call \"React.useContext()\" outside a component) will always produce errors, but\n // a call on the dispatcher wont\n dispatcher.useContext({});\n return true;\n } catch (e) {\n return false;\n }\n}\n"],"names":["isInsideComponent","dispatcher","React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","current","undefined","useContext","e"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;SAEgBA;;;EAGd,IAAI;;IAEF,MAAMC,UAAU,GAAGC,gBAAK,CAACC,kDAAN,CAAyDC,sBAAzD,CAAgFC,OAAnG,CAFE;;IAKF,IAAIJ,UAAU,KAAK,IAAf,IAAuBA,UAAU,KAAKK,SAA1C,EAAqD;MACnD,OAAO,KAAP;KANA;;;;IAWFL,UAAU,CAACM,UAAX,CAAsB,EAAtB;IACA,OAAO,IAAP;GAZF,CAaE,OAAOC,CAAP,EAAU;IACV,OAAO,KAAP;;AAEH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isInsideComponent(): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
function isInsideComponent() {
|
|
4
|
+
// React 18 always logs errors if a dispatcher is not present:
|
|
5
|
+
// https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36
|
|
6
|
+
try {
|
|
7
|
+
// @ts-expect-error "SECRET_INTERNALS" are not typed
|
|
8
|
+
const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current; // Before any React component was rendered "dispatcher" will be "null"
|
|
9
|
+
|
|
10
|
+
if (dispatcher === null || dispatcher === undefined) {
|
|
11
|
+
return false;
|
|
12
|
+
} // A check with hooks call (i.e. call "React.useContext()" outside a component) will always produce errors, but
|
|
13
|
+
// a call on the dispatcher wont
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
dispatcher.useContext({});
|
|
17
|
+
return true;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { isInsideComponent };
|
|
24
|
+
//# sourceMappingURL=isInsideComponent.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isInsideComponent.esm.js","sources":["../../../../packages/react/src/utils/isInsideComponent.ts"],"sourcesContent":["import * as React from 'react';\n\nexport function isInsideComponent() {\n // React 18 always logs errors if a dispatcher is not present:\n // https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36\n try {\n // @ts-expect-error \"SECRET_INTERNALS\" are not typed\n const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;\n\n // Before any React component was rendered \"dispatcher\" will be \"null\"\n if (dispatcher === null || dispatcher === undefined) {\n return false;\n }\n\n // A check with hooks call (i.e. call \"React.useContext()\" outside a component) will always produce errors, but\n // a call on the dispatcher wont\n dispatcher.useContext({});\n return true;\n } catch (e) {\n return false;\n }\n}\n"],"names":["isInsideComponent","dispatcher","React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","current","undefined","useContext","e"],"mappings":";;SAEgBA;;;EAGd,IAAI;;IAEF,MAAMC,UAAU,GAAGC,KAAK,CAACC,kDAAN,CAAyDC,sBAAzD,CAAgFC,OAAnG,CAFE;;IAKF,IAAIJ,UAAU,KAAK,IAAf,IAAuBA,UAAU,KAAKK,SAA1C,EAAqD;MACnD,OAAO,KAAP;KANA;;;;IAWFL,UAAU,CAACM,UAAX,CAAsB,EAAtB;IACA,OAAO,IAAP;GAZF,CAaE,OAAOC,CAAP,EAAU;IACV,OAAO,KAAP;;AAEH;;;;"}
|