@stoplight/elements-core 9.0.13 → 9.0.14
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.esm.js +32 -0
- package/index.js +32 -0
- package/index.mjs +32 -0
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -3535,6 +3535,38 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
|
|
|
3535
3535
|
});
|
|
3536
3536
|
}, []);
|
|
3537
3537
|
const updatedTree = updateTocTree(tree, '');
|
|
3538
|
+
const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
|
|
3539
|
+
let firstMatch;
|
|
3540
|
+
let hasAnyLastIndexMatch = false;
|
|
3541
|
+
if (!id)
|
|
3542
|
+
return [firstMatch, hasAnyLastIndexMatch];
|
|
3543
|
+
const walk = (arr, stack) => {
|
|
3544
|
+
for (const itm of arr) {
|
|
3545
|
+
const newStack = stack.concat(itm);
|
|
3546
|
+
const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
|
|
3547
|
+
if (matches) {
|
|
3548
|
+
if (!firstMatch)
|
|
3549
|
+
firstMatch = itm;
|
|
3550
|
+
const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
|
|
3551
|
+
if (hasLastIndexMatch)
|
|
3552
|
+
hasAnyLastIndexMatch = true;
|
|
3553
|
+
}
|
|
3554
|
+
if ('items' in itm && Array.isArray(itm.items)) {
|
|
3555
|
+
if (walk(itm.items, newStack))
|
|
3556
|
+
return true;
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
return false;
|
|
3560
|
+
};
|
|
3561
|
+
walk(items, []);
|
|
3562
|
+
return [firstMatch, hasAnyLastIndexMatch];
|
|
3563
|
+
}, [lastActiveIndex]);
|
|
3564
|
+
const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
|
|
3565
|
+
React.useEffect(() => {
|
|
3566
|
+
if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
|
|
3567
|
+
setLastActiveIndex(firstMatchItem.index);
|
|
3568
|
+
}
|
|
3569
|
+
}, [firstMatchItem, hasAnyLastIndexMatch]);
|
|
3538
3570
|
const container = React.useRef(null);
|
|
3539
3571
|
const child = React.useRef(null);
|
|
3540
3572
|
const firstRender = useFirstRender();
|
package/index.js
CHANGED
|
@@ -3556,6 +3556,38 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
|
|
|
3556
3556
|
});
|
|
3557
3557
|
}, []);
|
|
3558
3558
|
const updatedTree = updateTocTree(tree, '');
|
|
3559
|
+
const findFirstMatchAndIndexMatch = React__namespace.useCallback((items, id) => {
|
|
3560
|
+
let firstMatch;
|
|
3561
|
+
let hasAnyLastIndexMatch = false;
|
|
3562
|
+
if (!id)
|
|
3563
|
+
return [firstMatch, hasAnyLastIndexMatch];
|
|
3564
|
+
const walk = (arr, stack) => {
|
|
3565
|
+
for (const itm of arr) {
|
|
3566
|
+
const newStack = stack.concat(itm);
|
|
3567
|
+
const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
|
|
3568
|
+
if (matches) {
|
|
3569
|
+
if (!firstMatch)
|
|
3570
|
+
firstMatch = itm;
|
|
3571
|
+
const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
|
|
3572
|
+
if (hasLastIndexMatch)
|
|
3573
|
+
hasAnyLastIndexMatch = true;
|
|
3574
|
+
}
|
|
3575
|
+
if ('items' in itm && Array.isArray(itm.items)) {
|
|
3576
|
+
if (walk(itm.items, newStack))
|
|
3577
|
+
return true;
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
return false;
|
|
3581
|
+
};
|
|
3582
|
+
walk(items, []);
|
|
3583
|
+
return [firstMatch, hasAnyLastIndexMatch];
|
|
3584
|
+
}, [lastActiveIndex]);
|
|
3585
|
+
const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
|
|
3586
|
+
React__namespace.useEffect(() => {
|
|
3587
|
+
if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
|
|
3588
|
+
setLastActiveIndex(firstMatchItem.index);
|
|
3589
|
+
}
|
|
3590
|
+
}, [firstMatchItem, hasAnyLastIndexMatch]);
|
|
3559
3591
|
const container = React__namespace.useRef(null);
|
|
3560
3592
|
const child = React__namespace.useRef(null);
|
|
3561
3593
|
const firstRender = useFirstRender();
|
package/index.mjs
CHANGED
|
@@ -3535,6 +3535,38 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
|
|
|
3535
3535
|
});
|
|
3536
3536
|
}, []);
|
|
3537
3537
|
const updatedTree = updateTocTree(tree, '');
|
|
3538
|
+
const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
|
|
3539
|
+
let firstMatch;
|
|
3540
|
+
let hasAnyLastIndexMatch = false;
|
|
3541
|
+
if (!id)
|
|
3542
|
+
return [firstMatch, hasAnyLastIndexMatch];
|
|
3543
|
+
const walk = (arr, stack) => {
|
|
3544
|
+
for (const itm of arr) {
|
|
3545
|
+
const newStack = stack.concat(itm);
|
|
3546
|
+
const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
|
|
3547
|
+
if (matches) {
|
|
3548
|
+
if (!firstMatch)
|
|
3549
|
+
firstMatch = itm;
|
|
3550
|
+
const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
|
|
3551
|
+
if (hasLastIndexMatch)
|
|
3552
|
+
hasAnyLastIndexMatch = true;
|
|
3553
|
+
}
|
|
3554
|
+
if ('items' in itm && Array.isArray(itm.items)) {
|
|
3555
|
+
if (walk(itm.items, newStack))
|
|
3556
|
+
return true;
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
return false;
|
|
3560
|
+
};
|
|
3561
|
+
walk(items, []);
|
|
3562
|
+
return [firstMatch, hasAnyLastIndexMatch];
|
|
3563
|
+
}, [lastActiveIndex]);
|
|
3564
|
+
const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
|
|
3565
|
+
React.useEffect(() => {
|
|
3566
|
+
if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
|
|
3567
|
+
setLastActiveIndex(firstMatchItem.index);
|
|
3568
|
+
}
|
|
3569
|
+
}, [firstMatchItem, hasAnyLastIndexMatch]);
|
|
3538
3570
|
const container = React.useRef(null);
|
|
3539
3571
|
const child = React.useRef(null);
|
|
3540
3572
|
const firstRender = useFirstRender();
|