Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fluentui/react-tabster

Package Overview
Dependencies
Maintainers
12
Versions
900
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluentui/react-tabster - npm Package Compare versions

Comparing version 0.0.0-nightly-20240823-0407.1 to 0.0.0-nightly-20240823-1802.1

89

lib-commonjs/hooks/useMergeTabsterAttributes.js

@@ -16,64 +16,37 @@ "use strict";

'use no memo';
const stringAttributes = attributes.reduce((acc, curr)=>{
if (curr[_tabster.TABSTER_ATTRIBUTE_NAME]) {
acc.push(curr[_tabster.TABSTER_ATTRIBUTE_NAME]);
const stringAttributes = attributes.map((attribute)=>attribute[_tabster.TABSTER_ATTRIBUTE_NAME]).filter(Boolean);
return _react.useMemo(()=>{
let attribute = stringAttributes[0];
attributes.shift();
for (const attr of stringAttributes){
attribute = mergeAttributes(attribute, attr);
}
return acc;
}, []);
if (process.env.NODE_ENV !== 'production') {
// ignoring rules of hooks because this is a condition based on the environment
// it's safe to ignore the rule
// eslint-disable-next-line react-hooks/rules-of-hooks
useWarnIfUnstableAttributes(stringAttributes);
}
return _react.useMemo(()=>({
[_tabster.TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined
}), // this is safe because the collection of attributes is not expected to change at runtime
return {
[_tabster.TABSTER_ATTRIBUTE_NAME]: attribute
};
// eslint-disable-next-line react-hooks/exhaustive-deps
stringAttributes);
}, stringAttributes);
};
/**
* Merges two JSON strings into one.
*/ const mergeJSONStrings = (a, b)=>JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));
/**
* Tries to parse a JSON string and returns an object.
* If the JSON string is invalid, an empty object is returned.
*/ const safelyParseJSON = (json)=>{
try {
return JSON.parse(json);
} catch {
return {};
function mergeAttributes(a, b) {
if (!b) {
return a;
}
};
/**
* Helper hook that ensures that the attributes passed to the hook are stable.
* This is necessary because the attributes are expected to not change at runtime.
*
* This hook will console.warn if the attributes change at runtime.
*/ const useWarnIfUnstableAttributes = (attributes)=>{
'use no memo';
const initialAttributesRef = _react.useRef(attributes);
let isStable = initialAttributesRef.current.length === attributes.length;
if (initialAttributesRef.current !== attributes && isStable) {
for(let i = 0; i < attributes.length; i++){
if (initialAttributesRef.current[i] !== attributes[i]) {
isStable = false;
break;
}
}
let aParsed = {};
let bParsed = {};
if (a) {
try {
aParsed = JSON.parse(a);
// eslint-disable-next-line no-empty
} catch {}
}
_react.useEffect(()=>{
if (!isStable) {
const error = new Error();
// eslint-disable-next-line no-console
console.warn(/** #__DE-INDENT__ */ `
@fluentui/react-tabster [useMergedTabsterAttributes]:
The attributes passed to the hook changed at runtime.
This might lead to unexpected behavior, please ensure that the attributes are stable.
${error.stack}
`);
}
}, [
isStable
]);
};
if (b) {
try {
bParsed = JSON.parse(b);
// eslint-disable-next-line no-empty
} catch {}
}
return JSON.stringify({
...aParsed,
...bParsed
});
}

@@ -12,65 +12,37 @@ import * as React from 'react';

'use no memo';
const stringAttributes = attributes.reduce((acc, curr)=>{
if (curr[TABSTER_ATTRIBUTE_NAME]) {
acc.push(curr[TABSTER_ATTRIBUTE_NAME]);
const stringAttributes = attributes.map((attribute)=>attribute[TABSTER_ATTRIBUTE_NAME]).filter(Boolean);
return React.useMemo(()=>{
let attribute = stringAttributes[0];
attributes.shift();
for (const attr of stringAttributes){
attribute = mergeAttributes(attribute, attr);
}
return acc;
}, []);
if (process.env.NODE_ENV !== 'production') {
// ignoring rules of hooks because this is a condition based on the environment
// it's safe to ignore the rule
// eslint-disable-next-line react-hooks/rules-of-hooks
useWarnIfUnstableAttributes(stringAttributes);
}
return React.useMemo(()=>({
[TABSTER_ATTRIBUTE_NAME]: stringAttributes.length > 0 ? stringAttributes.reduce(mergeJSONStrings) : undefined
}), // disable exhaustive-deps because we want to memoize the result of the reduction
// this is safe because the collection of attributes is not expected to change at runtime
return {
[TABSTER_ATTRIBUTE_NAME]: attribute
};
// eslint-disable-next-line react-hooks/exhaustive-deps
stringAttributes);
}, stringAttributes);
};
/**
* Merges two JSON strings into one.
*/ const mergeJSONStrings = (a, b)=>JSON.stringify(Object.assign(safelyParseJSON(a), safelyParseJSON(b)));
/**
* Tries to parse a JSON string and returns an object.
* If the JSON string is invalid, an empty object is returned.
*/ const safelyParseJSON = (json)=>{
try {
return JSON.parse(json);
} catch {
return {};
function mergeAttributes(a, b) {
if (!b) {
return a;
}
};
/**
* Helper hook that ensures that the attributes passed to the hook are stable.
* This is necessary because the attributes are expected to not change at runtime.
*
* This hook will console.warn if the attributes change at runtime.
*/ const useWarnIfUnstableAttributes = (attributes)=>{
'use no memo';
const initialAttributesRef = React.useRef(attributes);
let isStable = initialAttributesRef.current.length === attributes.length;
if (initialAttributesRef.current !== attributes && isStable) {
for(let i = 0; i < attributes.length; i++){
if (initialAttributesRef.current[i] !== attributes[i]) {
isStable = false;
break;
}
}
let aParsed = {};
let bParsed = {};
if (a) {
try {
aParsed = JSON.parse(a);
// eslint-disable-next-line no-empty
} catch {}
}
React.useEffect(()=>{
if (!isStable) {
const error = new Error();
// eslint-disable-next-line no-console
console.warn(/** #__DE-INDENT__ */ `
@fluentui/react-tabster [useMergedTabsterAttributes]:
The attributes passed to the hook changed at runtime.
This might lead to unexpected behavior, please ensure that the attributes are stable.
${error.stack}
`);
}
}, [
isStable
]);
};
if (b) {
try {
bParsed = JSON.parse(b);
// eslint-disable-next-line no-empty
} catch {}
}
return JSON.stringify({
...aParsed,
...bParsed
});
}
{
"name": "@fluentui/react-tabster",
"version": "0.0.0-nightly-20240823-0407.1",
"version": "0.0.0-nightly-20240823-1802.1",
"description": "Utilities for focus management and facade for tabster",

@@ -34,5 +34,5 @@ "main": "lib-commonjs/index.js",

"dependencies": {
"@fluentui/react-shared-contexts": "0.0.0-nightly-20240823-0407.1",
"@fluentui/react-theme": "0.0.0-nightly-20240823-0407.1",
"@fluentui/react-utilities": "0.0.0-nightly-20240823-0407.1",
"@fluentui/react-shared-contexts": "0.0.0-nightly-20240823-1802.1",
"@fluentui/react-theme": "0.0.0-nightly-20240823-1802.1",
"@fluentui/react-utilities": "0.0.0-nightly-20240823-1802.1",
"@griffel/react": "^1.5.22",

@@ -39,0 +39,0 @@ "@swc/helpers": "^0.5.1",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc