@fluentui/react-tabster 9.22.4 → 9.22.5

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 CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui/react-tabster
2
2
 
3
- This log was last generated on Thu, 15 Aug 2024 08:18:56 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 15 Aug 2024 13:46:54 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.22.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.22.5)
8
+
9
+ Thu, 15 Aug 2024 13:46:54 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.22.4..@fluentui/react-tabster_v9.22.5)
11
+
12
+ ### Patches
13
+
14
+ - chore: simplifies useMergedTabsterAttributes internals ([PR #32303](https://github.com/microsoft/fluentui/pull/32303) by bernardo.sunderhus@gmail.com)
15
+
7
16
  ## [9.22.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-tabster_v9.22.4)
8
17
 
9
- Thu, 15 Aug 2024 08:18:56 GMT
18
+ Thu, 15 Aug 2024 08:22:14 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tabster_v9.22.3..@fluentui/react-tabster_v9.22.4)
11
20
 
12
21
  ### Patches
@@ -9,39 +9,67 @@ import { TABSTER_ATTRIBUTE_NAME } from 'tabster';
9
9
  * @returns single merged tabster attribute
10
10
  */ export const useMergedTabsterAttributes_unstable = (...attributes)=>{
11
11
  'use no memo';
12
- const stringAttributes = attributes.map((attribute)=>attribute[TABSTER_ATTRIBUTE_NAME]).filter(Boolean);
13
- return React.useMemo(()=>{
14
- let attribute = stringAttributes[0];
15
- attributes.shift();
16
- for (const attr of stringAttributes){
17
- attribute = mergeAttributes(attribute, attr);
12
+ const stringAttributes = attributes.reduce((acc, curr)=>{
13
+ if (curr[TABSTER_ATTRIBUTE_NAME]) {
14
+ acc.push(curr[TABSTER_ATTRIBUTE_NAME]);
18
15
  }
19
- return {
20
- [TABSTER_ATTRIBUTE_NAME]: attribute
21
- };
16
+ return acc;
17
+ }, []);
18
+ if (process.env.NODE_ENV !== 'production') {
19
+ // ignoring rules of hooks because this is a condition based on the environment
20
+ // it's safe to ignore the rule
21
+ // eslint-disable-next-line react-hooks/rules-of-hooks
22
+ useWarnIfUnstableAttributes(stringAttributes);
23
+ }
24
+ return React.useMemo(()=>({
25
+ [TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined
26
+ }), // disable exhaustive-deps because we want to memoize the result of the reduction
27
+ // this is safe because the collection of attributes is not expected to change at runtime
22
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
23
- }, stringAttributes);
29
+ stringAttributes);
24
30
  };
25
- function mergeAttributes(a, b) {
26
- if (!b) {
27
- return a;
28
- }
29
- let aParsed = {};
30
- let bParsed = {};
31
- if (a) {
32
- try {
33
- aParsed = JSON.parse(a);
34
- // eslint-disable-next-line no-empty
35
- } catch {}
31
+ /**
32
+ * Merges two JSON strings into one.
33
+ */ const mergeJSONStrings = (a, b)=>JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));
34
+ /**
35
+ * Tries to parse a JSON string and returns an object.
36
+ * If the JSON string is invalid, an empty object is returned.
37
+ */ const safelyParseJSON = (json)=>{
38
+ try {
39
+ return JSON.parse(json);
40
+ } catch {
41
+ return {};
36
42
  }
37
- if (b) {
38
- try {
39
- bParsed = JSON.parse(b);
40
- // eslint-disable-next-line no-empty
41
- } catch {}
43
+ };
44
+ /**
45
+ * Helper hook that ensures that the attributes passed to the hook are stable.
46
+ * This is necessary because the attributes are expected to not change at runtime.
47
+ *
48
+ * This hook will console.warn if the attributes change at runtime.
49
+ */ const useWarnIfUnstableAttributes = (attributes)=>{
50
+ 'use no memo';
51
+ const initialAttributesRef = React.useRef(attributes);
52
+ let isStable = initialAttributesRef.current.length === attributes.length;
53
+ if (initialAttributesRef.current !== attributes && isStable) {
54
+ for(let i = 0; i < attributes.length; i++){
55
+ if (initialAttributesRef.current[i] !== attributes[i]) {
56
+ isStable = false;
57
+ break;
58
+ }
59
+ }
42
60
  }
43
- return JSON.stringify({
44
- ...aParsed,
45
- ...bParsed
46
- });
47
- }
61
+ React.useEffect(()=>{
62
+ if (!isStable) {
63
+ const error = new Error();
64
+ // eslint-disable-next-line no-console
65
+ console.warn(/** #__DE-INDENT__ */ `
66
+ @fluentui/react-tabster [useMergedTabsterAttributes]:
67
+ The attributes passed to the hook changed at runtime.
68
+ This might lead to unexpected behavior, please ensure that the attributes are stable.
69
+ ${error.stack}
70
+ `);
71
+ }
72
+ }, [
73
+ isStable
74
+ ]);
75
+ };
@@ -1 +1 @@
1
- {"version":3,"sources":["useMergeTabsterAttributes.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types, TABSTER_ATTRIBUTE_NAME } from 'tabster';\n\n/**\n * Merges a collection of tabster attributes.\n *\n * ⚠️The attributes passed as arguments to this hook cannot change at runtime.\n * @internal\n * @param attributes - collection of tabster attributes from other react-tabster hooks\n * @returns single merged tabster attribute\n */\nexport const useMergedTabsterAttributes_unstable = (\n ...attributes: Partial<Types.TabsterDOMAttribute>[]\n): Types.TabsterDOMAttribute => {\n 'use no memo';\n\n const stringAttributes = attributes.map(attribute => attribute[TABSTER_ATTRIBUTE_NAME]).filter(Boolean) as string[];\n\n return React.useMemo(() => {\n let attribute = stringAttributes[0];\n attributes.shift();\n\n for (const attr of stringAttributes) {\n attribute = mergeAttributes(attribute, attr);\n }\n\n return { [TABSTER_ATTRIBUTE_NAME]: attribute };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, stringAttributes);\n};\n\nfunction mergeAttributes(a: string, b?: string): string {\n if (!b) {\n return a;\n }\n\n let aParsed = {};\n let bParsed = {};\n if (a) {\n try {\n aParsed = JSON.parse(a);\n // eslint-disable-next-line no-empty\n } catch {}\n }\n\n if (b) {\n try {\n bParsed = JSON.parse(b);\n // eslint-disable-next-line no-empty\n } catch {}\n }\n\n return JSON.stringify({ ...aParsed, ...bParsed });\n}\n"],"names":["React","TABSTER_ATTRIBUTE_NAME","useMergedTabsterAttributes_unstable","attributes","stringAttributes","map","attribute","filter","Boolean","useMemo","shift","attr","mergeAttributes","a","b","aParsed","bParsed","JSON","parse","stringify"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAAgBC,sBAAsB,QAAQ,UAAU;AAExD;;;;;;;CAOC,GACD,OAAO,MAAMC,sCAAsC,CACjD,GAAGC;IAEH;IAEA,MAAMC,mBAAmBD,WAAWE,GAAG,CAACC,CAAAA,YAAaA,SAAS,CAACL,uBAAuB,EAAEM,MAAM,CAACC;IAE/F,OAAOR,MAAMS,OAAO,CAAC;QACnB,IAAIH,YAAYF,gBAAgB,CAAC,EAAE;QACnCD,WAAWO,KAAK;QAEhB,KAAK,MAAMC,QAAQP,iBAAkB;YACnCE,YAAYM,gBAAgBN,WAAWK;QACzC;QAEA,OAAO;YAAE,CAACV,uBAAuB,EAAEK;QAAU;IAC7C,uDAAuD;IACzD,GAAGF;AACL,EAAE;AAEF,SAASQ,gBAAgBC,CAAS,EAAEC,CAAU;IAC5C,IAAI,CAACA,GAAG;QACN,OAAOD;IACT;IAEA,IAAIE,UAAU,CAAC;IACf,IAAIC,UAAU,CAAC;IACf,IAAIH,GAAG;QACL,IAAI;YACFE,UAAUE,KAAKC,KAAK,CAACL;QACrB,oCAAoC;QACtC,EAAE,OAAM,CAAC;IACX;IAEA,IAAIC,GAAG;QACL,IAAI;YACFE,UAAUC,KAAKC,KAAK,CAACJ;QACrB,oCAAoC;QACtC,EAAE,OAAM,CAAC;IACX;IAEA,OAAOG,KAAKE,SAAS,CAAC;QAAE,GAAGJ,OAAO;QAAE,GAAGC,OAAO;IAAC;AACjD"}
1
+ {"version":3,"sources":["useMergeTabsterAttributes.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types, TABSTER_ATTRIBUTE_NAME } from 'tabster';\n\n/**\n * Merges a collection of tabster attributes.\n *\n * ⚠️The attributes passed as arguments to this hook cannot change at runtime.\n * @internal\n * @param attributes - collection of tabster attributes from other react-tabster hooks\n * @returns single merged tabster attribute\n */\nexport const useMergedTabsterAttributes_unstable = (\n ...attributes: Partial<Types.TabsterDOMAttribute>[]\n): Types.TabsterDOMAttribute => {\n 'use no memo';\n\n const stringAttributes = attributes.reduce<string[]>((acc, curr) => {\n if (curr[TABSTER_ATTRIBUTE_NAME]) {\n acc.push(curr[TABSTER_ATTRIBUTE_NAME]);\n }\n return acc;\n }, []);\n\n if (process.env.NODE_ENV !== 'production') {\n // ignoring rules of hooks because this is a condition based on the environment\n // it's safe to ignore the rule\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useWarnIfUnstableAttributes(stringAttributes);\n }\n\n return React.useMemo(\n () => ({\n [TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined,\n }),\n // disable exhaustive-deps because we want to memoize the result of the reduction\n // this is safe because the collection of attributes is not expected to change at runtime\n // eslint-disable-next-line react-hooks/exhaustive-deps\n stringAttributes,\n );\n};\n\n/**\n * Merges two JSON strings into one.\n */\nconst mergeJSONStrings = (a: string, b: string): string =>\n JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));\n\n/**\n * Tries to parse a JSON string and returns an object.\n * If the JSON string is invalid, an empty object is returned.\n */\nconst safelyParseJSON = (json: string): object => {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n};\n\n/**\n * Helper hook that ensures that the attributes passed to the hook are stable.\n * This is necessary because the attributes are expected to not change at runtime.\n *\n * This hook will console.warn if the attributes change at runtime.\n */\nconst useWarnIfUnstableAttributes = (attributes: string[]) => {\n 'use no memo';\n\n const initialAttributesRef = React.useRef(attributes);\n\n let isStable = initialAttributesRef.current.length === attributes.length;\n if (initialAttributesRef.current !== attributes && isStable) {\n for (let i = 0; i < attributes.length; i++) {\n if (initialAttributesRef.current[i] !== attributes[i]) {\n isStable = false;\n break;\n }\n }\n }\n React.useEffect(() => {\n if (!isStable) {\n const error = new Error();\n // eslint-disable-next-line no-console\n console.warn(/** #__DE-INDENT__ */ `\n @fluentui/react-tabster [useMergedTabsterAttributes]:\n The attributes passed to the hook changed at runtime.\n This might lead to unexpected behavior, please ensure that the attributes are stable.\n ${error.stack}\n `);\n }\n }, [isStable]);\n};\n"],"names":["React","TABSTER_ATTRIBUTE_NAME","useMergedTabsterAttributes_unstable","attributes","stringAttributes","reduce","acc","curr","push","process","env","NODE_ENV","useWarnIfUnstableAttributes","useMemo","length","mergeJSONStrings","undefined","a","b","JSON","stringify","Object","assign","safelyParseJSON","json","parse","initialAttributesRef","useRef","isStable","current","i","useEffect","error","Error","console","warn","stack"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAAgBC,sBAAsB,QAAQ,UAAU;AAExD;;;;;;;CAOC,GACD,OAAO,MAAMC,sCAAsC,CACjD,GAAGC;IAEH;IAEA,MAAMC,mBAAmBD,WAAWE,MAAM,CAAW,CAACC,KAAKC;QACzD,IAAIA,IAAI,CAACN,uBAAuB,EAAE;YAChCK,IAAIE,IAAI,CAACD,IAAI,CAACN,uBAAuB;QACvC;QACA,OAAOK;IACT,GAAG,EAAE;IAEL,IAAIG,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,+EAA+E;QAC/E,+BAA+B;QAC/B,sDAAsD;QACtDC,4BAA4BR;IAC9B;IAEA,OAAOJ,MAAMa,OAAO,CAClB,IAAO,CAAA;YACL,CAACZ,uBAAuB,EAAEG,iBAAiBU,MAAM,GAAG,IAAIV,iBAAiBC,MAAM,CAACU,oBAAoBC;QACtG,CAAA,GACA,iFAAiF;IACjF,yFAAyF;IACzF,uDAAuD;IACvDZ;AAEJ,EAAE;AAEF;;CAEC,GACD,MAAMW,mBAAmB,CAACE,GAAWC,IACnCC,KAAKC,SAAS,CAACC,OAAOC,MAAM,CAACC,gBAAgBN,IAAIM,gBAAgBL;AAEnE;;;CAGC,GACD,MAAMK,kBAAkB,CAACC;IACvB,IAAI;QACF,OAAOL,KAAKM,KAAK,CAACD;IACpB,EAAE,OAAM;QACN,OAAO,CAAC;IACV;AACF;AAEA;;;;;CAKC,GACD,MAAMZ,8BAA8B,CAACT;IACnC;IAEA,MAAMuB,uBAAuB1B,MAAM2B,MAAM,CAACxB;IAE1C,IAAIyB,WAAWF,qBAAqBG,OAAO,CAACf,MAAM,KAAKX,WAAWW,MAAM;IACxE,IAAIY,qBAAqBG,OAAO,KAAK1B,cAAcyB,UAAU;QAC3D,IAAK,IAAIE,IAAI,GAAGA,IAAI3B,WAAWW,MAAM,EAAEgB,IAAK;YAC1C,IAAIJ,qBAAqBG,OAAO,CAACC,EAAE,KAAK3B,UAAU,CAAC2B,EAAE,EAAE;gBACrDF,WAAW;gBACX;YACF;QACF;IACF;IACA5B,MAAM+B,SAAS,CAAC;QACd,IAAI,CAACH,UAAU;YACb,MAAMI,QAAQ,IAAIC;YAClB,sCAAsC;YACtCC,QAAQC,IAAI,CAAC,mBAAmB,GAAG,CAAC;;;;QAIlC,EAAEH,MAAMI,KAAK,CAAC;MAChB,CAAC;QACH;IACF,GAAG;QAACR;KAAS;AACf"}
@@ -13,39 +13,66 @@ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
13
  const _tabster = require("tabster");
14
14
  const useMergedTabsterAttributes_unstable = (...attributes)=>{
15
15
  'use no memo';
16
- const stringAttributes = attributes.map((attribute)=>attribute[_tabster.TABSTER_ATTRIBUTE_NAME]).filter(Boolean);
17
- return _react.useMemo(()=>{
18
- let attribute = stringAttributes[0];
19
- attributes.shift();
20
- for (const attr of stringAttributes){
21
- attribute = mergeAttributes(attribute, attr);
16
+ const stringAttributes = attributes.reduce((acc, curr)=>{
17
+ if (curr[_tabster.TABSTER_ATTRIBUTE_NAME]) {
18
+ acc.push(curr[_tabster.TABSTER_ATTRIBUTE_NAME]);
22
19
  }
23
- return {
24
- [_tabster.TABSTER_ATTRIBUTE_NAME]: attribute
25
- };
20
+ return acc;
21
+ }, []);
22
+ if (process.env.NODE_ENV !== 'production') {
23
+ // ignoring rules of hooks because this is a condition based on the environment
24
+ // it's safe to ignore the rule
25
+ // eslint-disable-next-line react-hooks/rules-of-hooks
26
+ useWarnIfUnstableAttributes(stringAttributes);
27
+ }
28
+ return _react.useMemo(()=>({
29
+ [_tabster.TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined
30
+ }), // this is safe because the collection of attributes is not expected to change at runtime
26
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
27
- }, stringAttributes);
32
+ stringAttributes);
28
33
  };
29
- function mergeAttributes(a, b) {
30
- if (!b) {
31
- return a;
32
- }
33
- let aParsed = {};
34
- let bParsed = {};
35
- if (a) {
36
- try {
37
- aParsed = JSON.parse(a);
38
- // eslint-disable-next-line no-empty
39
- } catch {}
34
+ /**
35
+ * Merges two JSON strings into one.
36
+ */ const mergeJSONStrings = (a, b)=>JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));
37
+ /**
38
+ * Tries to parse a JSON string and returns an object.
39
+ * If the JSON string is invalid, an empty object is returned.
40
+ */ const safelyParseJSON = (json)=>{
41
+ try {
42
+ return JSON.parse(json);
43
+ } catch {
44
+ return {};
40
45
  }
41
- if (b) {
42
- try {
43
- bParsed = JSON.parse(b);
44
- // eslint-disable-next-line no-empty
45
- } catch {}
46
+ };
47
+ /**
48
+ * Helper hook that ensures that the attributes passed to the hook are stable.
49
+ * This is necessary because the attributes are expected to not change at runtime.
50
+ *
51
+ * This hook will console.warn if the attributes change at runtime.
52
+ */ const useWarnIfUnstableAttributes = (attributes)=>{
53
+ 'use no memo';
54
+ const initialAttributesRef = _react.useRef(attributes);
55
+ let isStable = initialAttributesRef.current.length === attributes.length;
56
+ if (initialAttributesRef.current !== attributes && isStable) {
57
+ for(let i = 0; i < attributes.length; i++){
58
+ if (initialAttributesRef.current[i] !== attributes[i]) {
59
+ isStable = false;
60
+ break;
61
+ }
62
+ }
46
63
  }
47
- return JSON.stringify({
48
- ...aParsed,
49
- ...bParsed
50
- });
51
- }
64
+ _react.useEffect(()=>{
65
+ if (!isStable) {
66
+ const error = new Error();
67
+ // eslint-disable-next-line no-console
68
+ console.warn(/** #__DE-INDENT__ */ `
69
+ @fluentui/react-tabster [useMergedTabsterAttributes]:
70
+ The attributes passed to the hook changed at runtime.
71
+ This might lead to unexpected behavior, please ensure that the attributes are stable.
72
+ ${error.stack}
73
+ `);
74
+ }
75
+ }, [
76
+ isStable
77
+ ]);
78
+ };
@@ -1 +1 @@
1
- {"version":3,"sources":["useMergeTabsterAttributes.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types, TABSTER_ATTRIBUTE_NAME } from 'tabster';\n\n/**\n * Merges a collection of tabster attributes.\n *\n * ⚠️The attributes passed as arguments to this hook cannot change at runtime.\n * @internal\n * @param attributes - collection of tabster attributes from other react-tabster hooks\n * @returns single merged tabster attribute\n */\nexport const useMergedTabsterAttributes_unstable = (\n ...attributes: Partial<Types.TabsterDOMAttribute>[]\n): Types.TabsterDOMAttribute => {\n 'use no memo';\n\n const stringAttributes = attributes.map(attribute => attribute[TABSTER_ATTRIBUTE_NAME]).filter(Boolean) as string[];\n\n return React.useMemo(() => {\n let attribute = stringAttributes[0];\n attributes.shift();\n\n for (const attr of stringAttributes) {\n attribute = mergeAttributes(attribute, attr);\n }\n\n return { [TABSTER_ATTRIBUTE_NAME]: attribute };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, stringAttributes);\n};\n\nfunction mergeAttributes(a: string, b?: string): string {\n if (!b) {\n return a;\n }\n\n let aParsed = {};\n let bParsed = {};\n if (a) {\n try {\n aParsed = JSON.parse(a);\n // eslint-disable-next-line no-empty\n } catch {}\n }\n\n if (b) {\n try {\n bParsed = JSON.parse(b);\n // eslint-disable-next-line no-empty\n } catch {}\n }\n\n return JSON.stringify({ ...aParsed, ...bParsed });\n}\n"],"names":["useMergedTabsterAttributes_unstable","attributes","stringAttributes","map","attribute","TABSTER_ATTRIBUTE_NAME","filter","Boolean","React","useMemo","shift","attr","mergeAttributes","a","b","aParsed","bParsed","JSON","parse","stringify"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWaA;;;eAAAA;;;;iEAXU;yBACuB;AAUvC,MAAMA,sCAAsC,CACjD,GAAGC;IAEH;IAEA,MAAMC,mBAAmBD,WAAWE,GAAG,CAACC,CAAAA,YAAaA,SAAS,CAACC,+BAAAA,CAAuB,EAAEC,MAAM,CAACC;IAE/F,OAAOC,OAAMC,OAAO,CAAC;QACnB,IAAIL,YAAYF,gBAAgB,CAAC,EAAE;QACnCD,WAAWS,KAAK;QAEhB,KAAK,MAAMC,QAAQT,iBAAkB;YACnCE,YAAYQ,gBAAgBR,WAAWO;QACzC;QAEA,OAAO;YAAE,CAACN,+BAAAA,CAAuB,EAAED;QAAU;IAC7C,uDAAuD;IACzD,GAAGF;AACL;AAEA,SAASU,gBAAgBC,CAAS,EAAEC,CAAU;IAC5C,IAAI,CAACA,GAAG;QACN,OAAOD;IACT;IAEA,IAAIE,UAAU,CAAC;IACf,IAAIC,UAAU,CAAC;IACf,IAAIH,GAAG;QACL,IAAI;YACFE,UAAUE,KAAKC,KAAK,CAACL;QACrB,oCAAoC;QACtC,EAAE,OAAM,CAAC;IACX;IAEA,IAAIC,GAAG;QACL,IAAI;YACFE,UAAUC,KAAKC,KAAK,CAACJ;QACrB,oCAAoC;QACtC,EAAE,OAAM,CAAC;IACX;IAEA,OAAOG,KAAKE,SAAS,CAAC;QAAE,GAAGJ,OAAO;QAAE,GAAGC,OAAO;IAAC;AACjD"}
1
+ {"version":3,"sources":["useMergeTabsterAttributes.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types, TABSTER_ATTRIBUTE_NAME } from 'tabster';\n\n/**\n * Merges a collection of tabster attributes.\n *\n * ⚠️The attributes passed as arguments to this hook cannot change at runtime.\n * @internal\n * @param attributes - collection of tabster attributes from other react-tabster hooks\n * @returns single merged tabster attribute\n */\nexport const useMergedTabsterAttributes_unstable = (\n ...attributes: Partial<Types.TabsterDOMAttribute>[]\n): Types.TabsterDOMAttribute => {\n 'use no memo';\n\n const stringAttributes = attributes.reduce<string[]>((acc, curr) => {\n if (curr[TABSTER_ATTRIBUTE_NAME]) {\n acc.push(curr[TABSTER_ATTRIBUTE_NAME]);\n }\n return acc;\n }, []);\n\n if (process.env.NODE_ENV !== 'production') {\n // ignoring rules of hooks because this is a condition based on the environment\n // it's safe to ignore the rule\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useWarnIfUnstableAttributes(stringAttributes);\n }\n\n return React.useMemo(\n () => ({\n [TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined,\n }),\n // disable exhaustive-deps because we want to memoize the result of the reduction\n // this is safe because the collection of attributes is not expected to change at runtime\n // eslint-disable-next-line react-hooks/exhaustive-deps\n stringAttributes,\n );\n};\n\n/**\n * Merges two JSON strings into one.\n */\nconst mergeJSONStrings = (a: string, b: string): string =>\n JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));\n\n/**\n * Tries to parse a JSON string and returns an object.\n * If the JSON string is invalid, an empty object is returned.\n */\nconst safelyParseJSON = (json: string): object => {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n};\n\n/**\n * Helper hook that ensures that the attributes passed to the hook are stable.\n * This is necessary because the attributes are expected to not change at runtime.\n *\n * This hook will console.warn if the attributes change at runtime.\n */\nconst useWarnIfUnstableAttributes = (attributes: string[]) => {\n 'use no memo';\n\n const initialAttributesRef = React.useRef(attributes);\n\n let isStable = initialAttributesRef.current.length === attributes.length;\n if (initialAttributesRef.current !== attributes && isStable) {\n for (let i = 0; i < attributes.length; i++) {\n if (initialAttributesRef.current[i] !== attributes[i]) {\n isStable = false;\n break;\n }\n }\n }\n React.useEffect(() => {\n if (!isStable) {\n const error = new Error();\n // eslint-disable-next-line no-console\n console.warn(/** #__DE-INDENT__ */ `\n @fluentui/react-tabster [useMergedTabsterAttributes]:\n The attributes passed to the hook changed at runtime.\n This might lead to unexpected behavior, please ensure that the attributes are stable.\n ${error.stack}\n `);\n }\n }, [isStable]);\n};\n"],"names":["useMergedTabsterAttributes_unstable","attributes","stringAttributes","reduce","acc","curr","TABSTER_ATTRIBUTE_NAME","push","process","env","NODE_ENV","useWarnIfUnstableAttributes","React","useMemo","length","mergeJSONStrings","undefined","a","b","JSON","stringify","Object","assign","safelyParseJSON","json","parse","initialAttributesRef","useRef","isStable","current","i","useEffect","error","Error","console","warn","stack"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWaA;;;eAAAA;;;;iEAXU;yBACuB;AAUvC,MAAMA,sCAAsC,CACjD,GAAGC;IAEH;IAEA,MAAMC,mBAAmBD,WAAWE,MAAM,CAAW,CAACC,KAAKC;QACzD,IAAIA,IAAI,CAACC,+BAAAA,CAAuB,EAAE;YAChCF,IAAIG,IAAI,CAACF,IAAI,CAACC,+BAAAA,CAAuB;QACvC;QACA,OAAOF;IACT,GAAG,EAAE;IAEL,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,+EAA+E;QAC/E,+BAA+B;QAC/B,sDAAsD;QACtDC,4BAA4BT;IAC9B;IAEA,OAAOU,OAAMC,OAAO,CAClB,IAAO,CAAA;YACL,CAACP,+BAAAA,CAAuB,EAAEJ,iBAAiBY,MAAM,GAAG,IAAIZ,iBAAiBC,MAAM,CAACY,oBAAoBC;QACtG,CAAA,GAEA,yFAAyF;IACzF,uDAAuD;IACvDd;AAEJ;AAEA;;CAEC,GACD,MAAMa,mBAAmB,CAACE,GAAWC,IACnCC,KAAKC,SAAS,CAACC,OAAOC,MAAM,CAACC,gBAAgBN,IAAIM,gBAAgBL;AAEnE;;;CAGC,GACD,MAAMK,kBAAkB,CAACC;IACvB,IAAI;QACF,OAAOL,KAAKM,KAAK,CAACD;IACpB,EAAE,OAAM;QACN,OAAO,CAAC;IACV;AACF;AAEA;;;;;CAKC,GACD,MAAMb,8BAA8B,CAACV;IACnC;IAEA,MAAMyB,uBAAuBd,OAAMe,MAAM,CAAC1B;IAE1C,IAAI2B,WAAWF,qBAAqBG,OAAO,CAACf,MAAM,KAAKb,WAAWa,MAAM;IACxE,IAAIY,qBAAqBG,OAAO,KAAK5B,cAAc2B,UAAU;QAC3D,IAAK,IAAIE,IAAI,GAAGA,IAAI7B,WAAWa,MAAM,EAAEgB,IAAK;YAC1C,IAAIJ,qBAAqBG,OAAO,CAACC,EAAE,KAAK7B,UAAU,CAAC6B,EAAE,EAAE;gBACrDF,WAAW;gBACX;YACF;QACF;IACF;IACAhB,OAAMmB,SAAS,CAAC;QACd,IAAI,CAACH,UAAU;YACb,MAAMI,QAAQ,IAAIC;YAClB,sCAAsC;YACtCC,QAAQC,IAAI,CAAC,mBAAmB,GAAG,CAAC;;;;QAIlC,EAAEH,MAAMI,KAAK,CAAC;MAChB,CAAC;QACH;IACF,GAAG;QAACR;KAAS;AACf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-tabster",
3
- "version": "9.22.4",
3
+ "version": "9.22.5",
4
4
  "description": "Utilities for focus management and facade for tabster",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",