@stoplight/elements-core 9.0.13-alpha-0.5 → 9.0.13-alpha-0.7

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 CHANGED
@@ -3594,6 +3594,38 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3594
3594
  });
3595
3595
  }, []);
3596
3596
  const updatedTree = updateTocTree(tree, '');
3597
+ const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3598
+ let firstMatch;
3599
+ let hasAnyLastIndexMatch = false;
3600
+ if (!id)
3601
+ return [firstMatch, hasAnyLastIndexMatch];
3602
+ const walk = (arr, stack) => {
3603
+ for (const itm of arr) {
3604
+ const newStack = stack.concat(itm);
3605
+ const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3606
+ if (matches) {
3607
+ if (!firstMatch)
3608
+ firstMatch = itm;
3609
+ const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3610
+ if (hasLastIndexMatch)
3611
+ hasAnyLastIndexMatch = true;
3612
+ }
3613
+ if ('items' in itm && Array.isArray(itm.items)) {
3614
+ if (walk(itm.items, newStack))
3615
+ return true;
3616
+ }
3617
+ }
3618
+ return false;
3619
+ };
3620
+ walk(items, []);
3621
+ return [firstMatch, hasAnyLastIndexMatch];
3622
+ }, [lastActiveIndex]);
3623
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3624
+ React.useEffect(() => {
3625
+ if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3626
+ setLastActiveIndex(firstMatchItem.index);
3627
+ }
3628
+ }, [firstMatchItem, hasAnyLastIndexMatch]);
3597
3629
  const container = React.useRef(null);
3598
3630
  const child = React.useRef(null);
3599
3631
  const firstRender = useFirstRender();
package/index.js CHANGED
@@ -3615,6 +3615,38 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
3615
3615
  });
3616
3616
  }, []);
3617
3617
  const updatedTree = updateTocTree(tree, '');
3618
+ const findFirstMatchAndIndexMatch = React__namespace.useCallback((items, id) => {
3619
+ let firstMatch;
3620
+ let hasAnyLastIndexMatch = false;
3621
+ if (!id)
3622
+ return [firstMatch, hasAnyLastIndexMatch];
3623
+ const walk = (arr, stack) => {
3624
+ for (const itm of arr) {
3625
+ const newStack = stack.concat(itm);
3626
+ const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3627
+ if (matches) {
3628
+ if (!firstMatch)
3629
+ firstMatch = itm;
3630
+ const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3631
+ if (hasLastIndexMatch)
3632
+ hasAnyLastIndexMatch = true;
3633
+ }
3634
+ if ('items' in itm && Array.isArray(itm.items)) {
3635
+ if (walk(itm.items, newStack))
3636
+ return true;
3637
+ }
3638
+ }
3639
+ return false;
3640
+ };
3641
+ walk(items, []);
3642
+ return [firstMatch, hasAnyLastIndexMatch];
3643
+ }, [lastActiveIndex]);
3644
+ const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3645
+ React__namespace.useEffect(() => {
3646
+ if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3647
+ setLastActiveIndex(firstMatchItem.index);
3648
+ }
3649
+ }, [firstMatchItem, hasAnyLastIndexMatch]);
3618
3650
  const container = React__namespace.useRef(null);
3619
3651
  const child = React__namespace.useRef(null);
3620
3652
  const firstRender = useFirstRender();
package/index.mjs CHANGED
@@ -3594,6 +3594,38 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3594
3594
  });
3595
3595
  }, []);
3596
3596
  const updatedTree = updateTocTree(tree, '');
3597
+ const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3598
+ let firstMatch;
3599
+ let hasAnyLastIndexMatch = false;
3600
+ if (!id)
3601
+ return [firstMatch, hasAnyLastIndexMatch];
3602
+ const walk = (arr, stack) => {
3603
+ for (const itm of arr) {
3604
+ const newStack = stack.concat(itm);
3605
+ const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3606
+ if (matches) {
3607
+ if (!firstMatch)
3608
+ firstMatch = itm;
3609
+ const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3610
+ if (hasLastIndexMatch)
3611
+ hasAnyLastIndexMatch = true;
3612
+ }
3613
+ if ('items' in itm && Array.isArray(itm.items)) {
3614
+ if (walk(itm.items, newStack))
3615
+ return true;
3616
+ }
3617
+ }
3618
+ return false;
3619
+ };
3620
+ walk(items, []);
3621
+ return [firstMatch, hasAnyLastIndexMatch];
3622
+ }, [lastActiveIndex]);
3623
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3624
+ React.useEffect(() => {
3625
+ if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3626
+ setLastActiveIndex(firstMatchItem.index);
3627
+ }
3628
+ }, [firstMatchItem, hasAnyLastIndexMatch]);
3597
3629
  const container = React.useRef(null);
3598
3630
  const child = React.useRef(null);
3599
3631
  const firstRender = useFirstRender();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "9.0.13-alpha-0.5",
3
+ "version": "9.0.13-alpha-0.7",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",