@fluentui/global-context 9.0.0-beta.1 → 9.0.0-beta.100
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/CHANGELOG.md +1010 -2
- package/README.md +1 -1
- package/lib/global-context-selector.js +25 -32
- package/lib/global-context-selector.js.map +1 -1
- package/lib/global-context.js +24 -32
- package/lib/global-context.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/types.js +1 -2
- package/lib/types.js.map +1 -1
- package/lib/utils.js +2 -4
- package/lib/utils.js.map +1 -1
- package/lib-commonjs/global-context-selector.js +43 -57
- package/lib-commonjs/global-context-selector.js.map +1 -1
- package/lib-commonjs/global-context.js +42 -57
- package/lib-commonjs/global-context.js.map +1 -1
- package/lib-commonjs/index.js +16 -21
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types.js +3 -3
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/utils.js +11 -12
- package/lib-commonjs/utils.js.map +1 -1
- package/package.json +25 -31
- package/CHANGELOG.json +0 -59
- package/dist/tsdoc-metadata.json +0 -11
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @fluentui/global-context
|
|
2
2
|
|
|
3
|
-
**Global Context for [Fluent UI React](https://
|
|
3
|
+
**Global Context for [Fluent UI React](https://react.fluentui.dev)**
|
|
4
4
|
|
|
5
5
|
This package contains a shim for `React.createContext` API that will register the context object to the global
|
|
6
6
|
scope (`window` for browsers, `global` for nodejs). This means that contexts will be real singletons.
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
1
3
|
import { createContext as baseCreateContext } from '@fluentui/react-context-selector';
|
|
2
4
|
import { canUseDOM } from '@fluentui/react-utilities';
|
|
3
5
|
import { getMajorVersion } from './utils';
|
|
4
|
-
const isBrowser =
|
|
5
|
-
const globalObject = isBrowser ? window : global;
|
|
6
|
+
const isBrowser = canUseDOM();
|
|
7
|
+
const globalObject = isBrowser ? window : global;
|
|
8
|
+
// Identifier for the symbol, for easy idenfitifaction of symbols created by this util
|
|
6
9
|
// Useful for clearning global object during SSR reloads
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
export const SYMBOL_NAMESPACE = 'global-context-selector:';
|
|
11
|
+
// During SSR the global object persists with the server process
|
|
9
12
|
// Clean out the global object during server reload during development
|
|
10
|
-
|
|
11
13
|
if (!isBrowser && process.env.NODE_ENV !== 'production') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
});
|
|
14
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
15
|
+
globalSymbols.forEach((sym)=>{
|
|
16
|
+
var _Symbol_keyFor;
|
|
17
|
+
if ((_Symbol_keyFor = Symbol.keyFor(sym)) === null || _Symbol_keyFor === void 0 ? void 0 : _Symbol_keyFor.startsWith(SYMBOL_NAMESPACE)) {
|
|
18
|
+
delete globalObject[sym];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Wrapper around @see createContext from \@fluentui/react-context-selector that implements context registration
|
|
@@ -31,22 +31,15 @@ if (!isBrowser && process.env.NODE_ENV !== 'production') {
|
|
|
31
31
|
* @param packageName - name of the npm package where the module is used
|
|
32
32
|
* @param packageVersion - version of the npm package where the module is used
|
|
33
33
|
* @returns @see React.createContext
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
46
|
-
globalObject[sym] = baseCreateContext(defaultValue);
|
|
47
|
-
} // @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return globalObject[sym];
|
|
34
|
+
*/ export const createContext = (defaultValue, name, packageName, packageVersion)=>{
|
|
35
|
+
// Symbol guaranteed to be unique for the entire runtime
|
|
36
|
+
const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${getMajorVersion(packageVersion)}`);
|
|
37
|
+
// Objects keyed with symbols are not visible with console.log
|
|
38
|
+
// Object symbol properties can't be iterated with `for` or `Object.keys`
|
|
39
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
40
|
+
if (!globalSymbols.includes(sym)) {
|
|
41
|
+
// eslint-disable-next-line @fluentui/no-context-default-value
|
|
42
|
+
globalObject[sym] = baseCreateContext(defaultValue);
|
|
43
|
+
}
|
|
44
|
+
return globalObject[sym];
|
|
51
45
|
};
|
|
52
|
-
//# sourceMappingURL=global-context-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["global-context-selector.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/global-context-selector.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext as baseCreateContext } from '@fluentui/react-context-selector';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { getMajorVersion } from './utils';\nimport { GlobalObject } from './types';\n\nconst isBrowser = canUseDOM();\nconst globalObject: GlobalObject = isBrowser\n ? // eslint-disable-next-line @nx/workspace-no-restricted-globals\n window\n : global;\n\n// Identifier for the symbol, for easy idenfitifaction of symbols created by this util\n// Useful for clearning global object during SSR reloads\nexport const SYMBOL_NAMESPACE = 'global-context-selector:';\n\n// During SSR the global object persists with the server process\n// Clean out the global object during server reload during development\nif (!isBrowser && process.env.NODE_ENV !== 'production') {\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n globalSymbols.forEach(sym => {\n if (Symbol.keyFor(sym)?.startsWith(SYMBOL_NAMESPACE)) {\n delete globalObject[sym];\n }\n });\n}\n\n/**\n * Wrapper around @see createContext from \\@fluentui/react-context-selector that implements context registration\n * in the globalThis object to avoid duplicate contexts. Contexts are keyed with\n * a unique sybmol for the package name, version and name of the context.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol}\n *\n * @param defaultValue - @see React.createContext\n * @param name - name of the context\n * @param packageName - name of the npm package where the module is used\n * @param packageVersion - version of the npm package where the module is used\n * @returns @see React.createContext\n */\nexport const createContext = <T>(\n defaultValue: T,\n name: string,\n packageName: string,\n packageVersion: string,\n): React.Context<T> => {\n // Symbol guaranteed to be unique for the entire runtime\n const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${getMajorVersion(packageVersion)}`);\n\n // Objects keyed with symbols are not visible with console.log\n // Object symbol properties can't be iterated with `for` or `Object.keys`\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n if (!globalSymbols.includes(sym)) {\n // eslint-disable-next-line @fluentui/no-context-default-value\n globalObject[sym] = baseCreateContext<unknown>(defaultValue);\n }\n\n return globalObject[sym] as React.Context<T>;\n};\n"],"names":["React","createContext","baseCreateContext","canUseDOM","getMajorVersion","isBrowser","globalObject","window","global","SYMBOL_NAMESPACE","process","env","NODE_ENV","globalSymbols","Object","getOwnPropertySymbols","forEach","sym","Symbol","keyFor","startsWith","defaultValue","name","packageName","packageVersion","for","includes"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,iBAAiBC,iBAAiB,QAAQ,mCAAmC;AACtF,SAASC,SAAS,QAAQ,4BAA4B;AACtD,SAASC,eAAe,QAAQ,UAAU;AAG1C,MAAMC,YAAYF;AAClB,MAAMG,eAA6BD,YAE/BE,SACAC;AAEJ,sFAAsF;AACtF,wDAAwD;AACxD,OAAO,MAAMC,mBAAmB,2BAA2B;AAE3D,gEAAgE;AAChE,sEAAsE;AACtE,IAAI,CAACJ,aAAaK,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACvD,MAAMC,gBAAgBC,OAAOC,qBAAqB,CAACT;IACnDO,cAAcG,OAAO,CAACC,CAAAA;YAChBC;QAAJ,KAAIA,iBAAAA,OAAOC,MAAM,CAACF,kBAAdC,qCAAAA,eAAoBE,UAAU,CAACX,mBAAmB;YACpD,OAAOH,YAAY,CAACW,IAAI;QAC1B;IACF;AACF;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMhB,gBAAgB,CAC3BoB,cACAC,MACAC,aACAC;IAEA,wDAAwD;IACxD,MAAMP,MAAMC,OAAOO,GAAG,CAAC,GAAGhB,mBAAmBc,YAAY,CAAC,EAAED,KAAK,EAAE,EAAElB,gBAAgBoB,iBAAiB;IAEtG,8DAA8D;IAC9D,yEAAyE;IACzE,MAAMX,gBAAgBC,OAAOC,qBAAqB,CAACT;IACnD,IAAI,CAACO,cAAca,QAAQ,CAACT,MAAM;QAChC,8DAA8D;QAC9DX,YAAY,CAACW,IAAI,GAAGf,kBAA2BmB;IACjD;IAEA,OAAOf,YAAY,CAACW,IAAI;AAC1B,EAAE"}
|
package/lib/global-context.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { canUseDOM } from '@fluentui/react-utilities';
|
|
3
4
|
import { getMajorVersion } from './utils';
|
|
4
|
-
const isBrowser =
|
|
5
|
-
const globalObject = isBrowser ? window : global;
|
|
5
|
+
const isBrowser = canUseDOM();
|
|
6
|
+
const globalObject = isBrowser ? window : global;
|
|
7
|
+
// Identifier for the symbol, for easy idenfitifaction of symbols created by this util
|
|
6
8
|
// Useful for clearning global object during SSR reloads
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
export const SYMBOL_NAMESPACE = 'global-context:';
|
|
10
|
+
// During SSR the global object persists with the server process
|
|
9
11
|
// Clean out the global object during server reload during development
|
|
10
|
-
|
|
11
12
|
if (!isBrowser && process.env.NODE_ENV !== 'production') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
});
|
|
13
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
14
|
+
globalSymbols.forEach((sym)=>{
|
|
15
|
+
var _Symbol_keyFor;
|
|
16
|
+
if ((_Symbol_keyFor = Symbol.keyFor(sym)) === null || _Symbol_keyFor === void 0 ? void 0 : _Symbol_keyFor.startsWith(SYMBOL_NAMESPACE)) {
|
|
17
|
+
delete globalObject[sym];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Wrapper around @see React.createContext that implements context registration
|
|
@@ -31,22 +30,15 @@ if (!isBrowser && process.env.NODE_ENV !== 'production') {
|
|
|
31
30
|
* @param packageName - name of the npm package where the module is used
|
|
32
31
|
* @param packageVersion - version of the npm package where the module is used
|
|
33
32
|
* @returns @see React.createContext
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
46
|
-
globalObject[sym] = /*#__PURE__*/React.createContext(defaultValue);
|
|
47
|
-
} // @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return globalObject[sym];
|
|
33
|
+
*/ export const createContext = (defaultValue, name, packageName, packageVersion)=>{
|
|
34
|
+
// Symbol guaranteed to be unique for the entire runtime
|
|
35
|
+
const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${getMajorVersion(packageVersion)}`);
|
|
36
|
+
// Objects keyed with symbols are not visible with console.log
|
|
37
|
+
// Object symbol properties can't be iterated with `for` or `Object.keys`
|
|
38
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
39
|
+
if (!globalSymbols.includes(sym)) {
|
|
40
|
+
// eslint-disable-next-line @fluentui/no-context-default-value
|
|
41
|
+
globalObject[sym] = React.createContext(defaultValue);
|
|
42
|
+
}
|
|
43
|
+
return globalObject[sym];
|
|
51
44
|
};
|
|
52
|
-
//# sourceMappingURL=global-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["global-context.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/global-context.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { GlobalObject } from './types';\nimport { getMajorVersion } from './utils';\n\nconst isBrowser = canUseDOM();\nconst globalObject: GlobalObject = isBrowser\n ? // eslint-disable-next-line @nx/workspace-no-restricted-globals\n window\n : global;\n\n// Identifier for the symbol, for easy idenfitifaction of symbols created by this util\n// Useful for clearning global object during SSR reloads\nexport const SYMBOL_NAMESPACE = 'global-context:';\n\n// During SSR the global object persists with the server process\n// Clean out the global object during server reload during development\nif (!isBrowser && process.env.NODE_ENV !== 'production') {\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n globalSymbols.forEach(sym => {\n if (Symbol.keyFor(sym)?.startsWith(SYMBOL_NAMESPACE)) {\n delete globalObject[sym];\n }\n });\n}\n\n/**\n * Wrapper around @see React.createContext that implements context registration\n * in the globalThis object to avoid duplicate contexts. Contexts are keyed with\n * a unique sybmol for the package name, version and name of the context.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol}\n *\n * @param defaultValue - @see React.createContext\n * @param name - name of the context\n * @param packageName - name of the npm package where the module is used\n * @param packageVersion - version of the npm package where the module is used\n * @returns @see React.createContext\n */\nexport const createContext = <T>(\n defaultValue: T,\n name: string,\n packageName: string,\n packageVersion: string,\n): React.Context<T> => {\n // Symbol guaranteed to be unique for the entire runtime\n const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${getMajorVersion(packageVersion)}`);\n\n // Objects keyed with symbols are not visible with console.log\n // Object symbol properties can't be iterated with `for` or `Object.keys`\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n if (!globalSymbols.includes(sym)) {\n // eslint-disable-next-line @fluentui/no-context-default-value\n globalObject[sym] = React.createContext<unknown>(defaultValue);\n }\n\n return globalObject[sym] as React.Context<T>;\n};\n"],"names":["React","canUseDOM","getMajorVersion","isBrowser","globalObject","window","global","SYMBOL_NAMESPACE","process","env","NODE_ENV","globalSymbols","Object","getOwnPropertySymbols","forEach","sym","Symbol","keyFor","startsWith","createContext","defaultValue","name","packageName","packageVersion","for","includes"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,SAAS,QAAQ,4BAA4B;AAEtD,SAASC,eAAe,QAAQ,UAAU;AAE1C,MAAMC,YAAYF;AAClB,MAAMG,eAA6BD,YAE/BE,SACAC;AAEJ,sFAAsF;AACtF,wDAAwD;AACxD,OAAO,MAAMC,mBAAmB,kBAAkB;AAElD,gEAAgE;AAChE,sEAAsE;AACtE,IAAI,CAACJ,aAAaK,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACvD,MAAMC,gBAAgBC,OAAOC,qBAAqB,CAACT;IACnDO,cAAcG,OAAO,CAACC,CAAAA;YAChBC;QAAJ,KAAIA,iBAAAA,OAAOC,MAAM,CAACF,kBAAdC,qCAAAA,eAAoBE,UAAU,CAACX,mBAAmB;YACpD,OAAOH,YAAY,CAACW,IAAI;QAC1B;IACF;AACF;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMI,gBAAgB,CAC3BC,cACAC,MACAC,aACAC;IAEA,wDAAwD;IACxD,MAAMR,MAAMC,OAAOQ,GAAG,CAAC,GAAGjB,mBAAmBe,YAAY,CAAC,EAAED,KAAK,EAAE,EAAEnB,gBAAgBqB,iBAAiB;IAEtG,8DAA8D;IAC9D,yEAAyE;IACzE,MAAMZ,gBAAgBC,OAAOC,qBAAqB,CAACT;IACnD,IAAI,CAACO,cAAcc,QAAQ,CAACV,MAAM;QAChC,8DAA8D;QAC9DX,YAAY,CAACW,IAAI,GAAGf,MAAMmB,aAAa,CAAUC;IACnD;IAEA,OAAOhB,YAAY,CAACW,IAAI;AAC1B,EAAE"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { createContext } from './global-context';\nexport { createContext as createContextSelector } from './global-context-selector';\n"],"names":["createContext","createContextSelector"],"mappings":"AAAA,SAASA,aAAa,QAAQ,mBAAmB;AACjD,SAASA,iBAAiBC,qBAAqB,QAAQ,4BAA4B"}
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
import * as React from 'react';
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type GlobalObject = typeof globalThis & Record<symbol, React.Context<unknown>>;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
package/lib/utils.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param version - semver version string
|
|
3
3
|
* @returns The major version number
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
return Number(version.split('.')[0]);
|
|
4
|
+
*/ export function getMajorVersion(version) {
|
|
5
|
+
return Number(version.split('.')[0]);
|
|
7
6
|
}
|
|
8
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * @param version - semver version string\n * @returns The major version number\n */\nexport function getMajorVersion(version: string): number {\n return Number(version.split('.')[0]);\n}\n"],"names":["getMajorVersion","version","Number","split"],"mappings":"AAAA;;;CAGC,GACD,OAAO,SAASA,gBAAgBC,OAAe;IAC7C,OAAOC,OAAOD,QAAQE,KAAK,CAAC,IAAI,CAAC,EAAE;AACrC"}
|
|
@@ -1,64 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
"use strict";
|
|
2
|
-
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
SYMBOL_NAMESPACE: function() {
|
|
14
|
+
return SYMBOL_NAMESPACE;
|
|
15
|
+
},
|
|
16
|
+
createContext: function() {
|
|
17
|
+
return createContext;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
21
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
22
|
+
const _reactcontextselector = require("@fluentui/react-context-selector");
|
|
23
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
24
|
+
const _utils = require("./utils");
|
|
25
|
+
const isBrowser = (0, _reactutilities.canUseDOM)();
|
|
26
|
+
const globalObject = isBrowser ? window : global;
|
|
27
|
+
const SYMBOL_NAMESPACE = 'global-context-selector:';
|
|
28
|
+
// During SSR the global object persists with the server process
|
|
19
29
|
// Clean out the global object during server reload during development
|
|
20
|
-
|
|
21
30
|
if (!isBrowser && process.env.NODE_ENV !== 'production') {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
32
|
+
globalSymbols.forEach((sym)=>{
|
|
33
|
+
var _Symbol_keyFor;
|
|
34
|
+
if ((_Symbol_keyFor = Symbol.keyFor(sym)) === null || _Symbol_keyFor === void 0 ? void 0 : _Symbol_keyFor.startsWith(SYMBOL_NAMESPACE)) {
|
|
35
|
+
delete globalObject[sym];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
31
38
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @returns @see React.createContext
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const createContext = (defaultValue, name, packageName, packageVersion) => {
|
|
48
|
-
// Symbol guaranteed to be unique for the entire runtime
|
|
49
|
-
const sym = Symbol.for(`${exports.SYMBOL_NAMESPACE}${packageName}/${name}/@${utils_1.getMajorVersion(packageVersion)}`); // Objects keyed with symbols are not visible with console.log
|
|
50
|
-
// Object symbol properties can't be iterated with `for` or `Object.keys`
|
|
51
|
-
|
|
52
|
-
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
53
|
-
|
|
54
|
-
if (!globalSymbols.includes(sym)) {
|
|
55
|
-
// @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
56
|
-
globalObject[sym] = react_context_selector_1.createContext(defaultValue);
|
|
57
|
-
} // @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return globalObject[sym];
|
|
39
|
+
const createContext = (defaultValue, name, packageName, packageVersion)=>{
|
|
40
|
+
// Symbol guaranteed to be unique for the entire runtime
|
|
41
|
+
const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${(0, _utils.getMajorVersion)(packageVersion)}`);
|
|
42
|
+
// Objects keyed with symbols are not visible with console.log
|
|
43
|
+
// Object symbol properties can't be iterated with `for` or `Object.keys`
|
|
44
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
45
|
+
if (!globalSymbols.includes(sym)) {
|
|
46
|
+
// eslint-disable-next-line @fluentui/no-context-default-value
|
|
47
|
+
globalObject[sym] = (0, _reactcontextselector.createContext)(defaultValue);
|
|
48
|
+
}
|
|
49
|
+
return globalObject[sym];
|
|
61
50
|
};
|
|
62
|
-
|
|
63
|
-
exports.createContext = createContext;
|
|
64
|
-
//# sourceMappingURL=global-context-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["global-context-selector.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/global-context-selector.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext as baseCreateContext } from '@fluentui/react-context-selector';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { getMajorVersion } from './utils';\nimport { GlobalObject } from './types';\n\nconst isBrowser = canUseDOM();\nconst globalObject: GlobalObject = isBrowser\n ? // eslint-disable-next-line @nx/workspace-no-restricted-globals\n window\n : global;\n\n// Identifier for the symbol, for easy idenfitifaction of symbols created by this util\n// Useful for clearning global object during SSR reloads\nexport const SYMBOL_NAMESPACE = 'global-context-selector:';\n\n// During SSR the global object persists with the server process\n// Clean out the global object during server reload during development\nif (!isBrowser && process.env.NODE_ENV !== 'production') {\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n globalSymbols.forEach(sym => {\n if (Symbol.keyFor(sym)?.startsWith(SYMBOL_NAMESPACE)) {\n delete globalObject[sym];\n }\n });\n}\n\n/**\n * Wrapper around @see createContext from \\@fluentui/react-context-selector that implements context registration\n * in the globalThis object to avoid duplicate contexts. Contexts are keyed with\n * a unique sybmol for the package name, version and name of the context.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol}\n *\n * @param defaultValue - @see React.createContext\n * @param name - name of the context\n * @param packageName - name of the npm package where the module is used\n * @param packageVersion - version of the npm package where the module is used\n * @returns @see React.createContext\n */\nexport const createContext = <T>(\n defaultValue: T,\n name: string,\n packageName: string,\n packageVersion: string,\n): React.Context<T> => {\n // Symbol guaranteed to be unique for the entire runtime\n const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${getMajorVersion(packageVersion)}`);\n\n // Objects keyed with symbols are not visible with console.log\n // Object symbol properties can't be iterated with `for` or `Object.keys`\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n if (!globalSymbols.includes(sym)) {\n // eslint-disable-next-line @fluentui/no-context-default-value\n globalObject[sym] = baseCreateContext<unknown>(defaultValue);\n }\n\n return globalObject[sym] as React.Context<T>;\n};\n"],"names":["SYMBOL_NAMESPACE","createContext","isBrowser","canUseDOM","globalObject","window","global","process","env","NODE_ENV","globalSymbols","Object","getOwnPropertySymbols","forEach","sym","Symbol","keyFor","startsWith","defaultValue","name","packageName","packageVersion","for","getMajorVersion","includes","baseCreateContext"],"mappings":"AAAA;;;;;;;;;;;;IAgBaA,gBAAgB;eAAhBA;;IA0BAC,aAAa;eAAbA;;;;iEAxCU;sCAC4B;gCACzB;uBACM;AAGhC,MAAMC,YAAYC,IAAAA,yBAAS;AAC3B,MAAMC,eAA6BF,YAE/BG,SACAC;AAIG,MAAMN,mBAAmB;AAEhC,gEAAgE;AAChE,sEAAsE;AACtE,IAAI,CAACE,aAAaK,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACvD,MAAMC,gBAAgBC,OAAOC,qBAAqB,CAACR;IACnDM,cAAcG,OAAO,CAACC,CAAAA;YAChBC;QAAJ,KAAIA,iBAAAA,OAAOC,MAAM,CAACF,kBAAdC,qCAAAA,eAAoBE,UAAU,CAACjB,mBAAmB;YACpD,OAAOI,YAAY,CAACU,IAAI;QAC1B;IACF;AACF;AAeO,MAAMb,gBAAgB,CAC3BiB,cACAC,MACAC,aACAC;IAEA,wDAAwD;IACxD,MAAMP,MAAMC,OAAOO,GAAG,CAAC,GAAGtB,mBAAmBoB,YAAY,CAAC,EAAED,KAAK,EAAE,EAAEI,IAAAA,sBAAe,EAACF,iBAAiB;IAEtG,8DAA8D;IAC9D,yEAAyE;IACzE,MAAMX,gBAAgBC,OAAOC,qBAAqB,CAACR;IACnD,IAAI,CAACM,cAAcc,QAAQ,CAACV,MAAM;QAChC,8DAA8D;QAC9DV,YAAY,CAACU,IAAI,GAAGW,IAAAA,mCAAiB,EAAUP;IACjD;IAEA,OAAOd,YAAY,CAACU,IAAI;AAC1B"}
|
|
@@ -1,64 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
"use strict";
|
|
2
|
-
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
SYMBOL_NAMESPACE: function() {
|
|
14
|
+
return SYMBOL_NAMESPACE;
|
|
15
|
+
},
|
|
16
|
+
createContext: function() {
|
|
17
|
+
return createContext;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
21
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
22
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
23
|
+
const _utils = require("./utils");
|
|
24
|
+
const isBrowser = (0, _reactutilities.canUseDOM)();
|
|
25
|
+
const globalObject = isBrowser ? window : global;
|
|
26
|
+
const SYMBOL_NAMESPACE = 'global-context:';
|
|
27
|
+
// During SSR the global object persists with the server process
|
|
19
28
|
// Clean out the global object during server reload during development
|
|
20
|
-
|
|
21
29
|
if (!isBrowser && process.env.NODE_ENV !== 'production') {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
30
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
31
|
+
globalSymbols.forEach((sym)=>{
|
|
32
|
+
var _Symbol_keyFor;
|
|
33
|
+
if ((_Symbol_keyFor = Symbol.keyFor(sym)) === null || _Symbol_keyFor === void 0 ? void 0 : _Symbol_keyFor.startsWith(SYMBOL_NAMESPACE)) {
|
|
34
|
+
delete globalObject[sym];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @returns @see React.createContext
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const createContext = (defaultValue, name, packageName, packageVersion) => {
|
|
48
|
-
// Symbol guaranteed to be unique for the entire runtime
|
|
49
|
-
const sym = Symbol.for(`${exports.SYMBOL_NAMESPACE}${packageName}/${name}/@${utils_1.getMajorVersion(packageVersion)}`); // Objects keyed with symbols are not visible with console.log
|
|
50
|
-
// Object symbol properties can't be iterated with `for` or `Object.keys`
|
|
51
|
-
|
|
52
|
-
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
53
|
-
|
|
54
|
-
if (!globalSymbols.includes(sym)) {
|
|
55
|
-
// @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
56
|
-
globalObject[sym] = React.createContext(defaultValue);
|
|
57
|
-
} // @ts-expect-error - Indexing object with symbols not supported until TS 4.4
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return globalObject[sym];
|
|
38
|
+
const createContext = (defaultValue, name, packageName, packageVersion)=>{
|
|
39
|
+
// Symbol guaranteed to be unique for the entire runtime
|
|
40
|
+
const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${(0, _utils.getMajorVersion)(packageVersion)}`);
|
|
41
|
+
// Objects keyed with symbols are not visible with console.log
|
|
42
|
+
// Object symbol properties can't be iterated with `for` or `Object.keys`
|
|
43
|
+
const globalSymbols = Object.getOwnPropertySymbols(globalObject);
|
|
44
|
+
if (!globalSymbols.includes(sym)) {
|
|
45
|
+
// eslint-disable-next-line @fluentui/no-context-default-value
|
|
46
|
+
globalObject[sym] = _react.createContext(defaultValue);
|
|
47
|
+
}
|
|
48
|
+
return globalObject[sym];
|
|
61
49
|
};
|
|
62
|
-
|
|
63
|
-
exports.createContext = createContext;
|
|
64
|
-
//# sourceMappingURL=global-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["global-context.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/global-context.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { GlobalObject } from './types';\nimport { getMajorVersion } from './utils';\n\nconst isBrowser = canUseDOM();\nconst globalObject: GlobalObject = isBrowser\n ? // eslint-disable-next-line @nx/workspace-no-restricted-globals\n window\n : global;\n\n// Identifier for the symbol, for easy idenfitifaction of symbols created by this util\n// Useful for clearning global object during SSR reloads\nexport const SYMBOL_NAMESPACE = 'global-context:';\n\n// During SSR the global object persists with the server process\n// Clean out the global object during server reload during development\nif (!isBrowser && process.env.NODE_ENV !== 'production') {\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n globalSymbols.forEach(sym => {\n if (Symbol.keyFor(sym)?.startsWith(SYMBOL_NAMESPACE)) {\n delete globalObject[sym];\n }\n });\n}\n\n/**\n * Wrapper around @see React.createContext that implements context registration\n * in the globalThis object to avoid duplicate contexts. Contexts are keyed with\n * a unique sybmol for the package name, version and name of the context.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol}\n *\n * @param defaultValue - @see React.createContext\n * @param name - name of the context\n * @param packageName - name of the npm package where the module is used\n * @param packageVersion - version of the npm package where the module is used\n * @returns @see React.createContext\n */\nexport const createContext = <T>(\n defaultValue: T,\n name: string,\n packageName: string,\n packageVersion: string,\n): React.Context<T> => {\n // Symbol guaranteed to be unique for the entire runtime\n const sym = Symbol.for(`${SYMBOL_NAMESPACE}${packageName}/${name}/@${getMajorVersion(packageVersion)}`);\n\n // Objects keyed with symbols are not visible with console.log\n // Object symbol properties can't be iterated with `for` or `Object.keys`\n const globalSymbols = Object.getOwnPropertySymbols(globalObject);\n if (!globalSymbols.includes(sym)) {\n // eslint-disable-next-line @fluentui/no-context-default-value\n globalObject[sym] = React.createContext<unknown>(defaultValue);\n }\n\n return globalObject[sym] as React.Context<T>;\n};\n"],"names":["SYMBOL_NAMESPACE","createContext","isBrowser","canUseDOM","globalObject","window","global","process","env","NODE_ENV","globalSymbols","Object","getOwnPropertySymbols","forEach","sym","Symbol","keyFor","startsWith","defaultValue","name","packageName","packageVersion","for","getMajorVersion","includes","React"],"mappings":"AAAA;;;;;;;;;;;;IAeaA,gBAAgB;eAAhBA;;IA0BAC,aAAa;eAAbA;;;;iEAvCU;gCACG;uBAEM;AAEhC,MAAMC,YAAYC,IAAAA,yBAAS;AAC3B,MAAMC,eAA6BF,YAE/BG,SACAC;AAIG,MAAMN,mBAAmB;AAEhC,gEAAgE;AAChE,sEAAsE;AACtE,IAAI,CAACE,aAAaK,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACvD,MAAMC,gBAAgBC,OAAOC,qBAAqB,CAACR;IACnDM,cAAcG,OAAO,CAACC,CAAAA;YAChBC;QAAJ,KAAIA,iBAAAA,OAAOC,MAAM,CAACF,kBAAdC,qCAAAA,eAAoBE,UAAU,CAACjB,mBAAmB;YACpD,OAAOI,YAAY,CAACU,IAAI;QAC1B;IACF;AACF;AAeO,MAAMb,gBAAgB,CAC3BiB,cACAC,MACAC,aACAC;IAEA,wDAAwD;IACxD,MAAMP,MAAMC,OAAOO,GAAG,CAAC,GAAGtB,mBAAmBoB,YAAY,CAAC,EAAED,KAAK,EAAE,EAAEI,IAAAA,sBAAe,EAACF,iBAAiB;IAEtG,8DAA8D;IAC9D,yEAAyE;IACzE,MAAMX,gBAAgBC,OAAOC,qBAAqB,CAACR;IACnD,IAAI,CAACM,cAAcc,QAAQ,CAACV,MAAM;QAChC,8DAA8D;QAC9DV,YAAY,CAACU,IAAI,GAAGW,OAAMxB,aAAa,CAAUiB;IACnD;IAEA,OAAOd,YAAY,CAACU,IAAI;AAC1B"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
createContext: function() {
|
|
13
|
+
return _globalcontext.createContext;
|
|
14
|
+
},
|
|
15
|
+
createContextSelector: function() {
|
|
16
|
+
return _globalcontextselector.createContext;
|
|
17
|
+
}
|
|
15
18
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "createContextSelector", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return global_context_selector_1.createContext;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
19
|
+
const _globalcontext = require("./global-context");
|
|
20
|
+
const _globalcontextselector = require("./global-context-selector");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { createContext } from './global-context';\nexport { createContext as createContextSelector } from './global-context-selector';\n"],"names":["createContext","createContextSelector"],"mappings":";;;;;;;;;;;IAASA,aAAa;eAAbA,4BAAa;;IACIC,qBAAqB;eAAtCD,oCAAa;;;+BADQ;uCACyB"}
|
package/lib-commonjs/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
5
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
6
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type GlobalObject = typeof globalThis & Record<symbol, React.Context<unknown>>;\n"],"names":[],"mappings":";;;;;iEAAuB"}
|
package/lib-commonjs/utils.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getMajorVersion = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* @param version - semver version string
|
|
9
3
|
* @returns The major version number
|
|
10
|
-
*/
|
|
11
|
-
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "getMajorVersion", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return getMajorVersion;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
12
14
|
function getMajorVersion(version) {
|
|
13
|
-
|
|
15
|
+
return Number(version.split('.')[0]);
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
exports.getMajorVersion = getMajorVersion;
|
|
17
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * @param version - semver version string\n * @returns The major version number\n */\nexport function getMajorVersion(version: string): number {\n return Number(version.split('.')[0]);\n}\n"],"names":["getMajorVersion","version","Number","split"],"mappings":"AAAA;;;CAGC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,gBAAgBC,OAAe;IAC7C,OAAOC,OAAOD,QAAQE,KAAK,CAAC,IAAI,CAAC,EAAE;AACrC"}
|