@stoplight/elements-core 9.0.16 → 9.0.17

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.
Files changed (4) hide show
  1. package/index.esm.js +32 -41
  2. package/index.js +31 -40
  3. package/index.mjs +32 -41
  4. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -10,7 +10,7 @@ import { parse } from '@stoplight/yaml';
10
10
  import { isArray as isArray$1, Box, useBreakpoints, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading as LinkHeading$1, NodeAnnotation, Callout, useModalState, Modal, ListBox, ListBoxItem, TabList, Tab, Tabs, TabPanels, TabPanel, Heading, useClipboard, Drawer, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
11
11
  import isObject from 'lodash/isObject.js';
12
12
  import { withErrorBoundary } from '@stoplight/react-error-boundary';
13
- import { useLocation, Link as Link$1, BrowserRouter, MemoryRouter, HashRouter, useInRouterContext, Routes, Route } from 'react-router-dom';
13
+ import { useLocation, Link as Link$1, HashRouter, MemoryRouter, BrowserRouter, useInRouterContext, Routes, Route } from 'react-router-dom';
14
14
  import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
15
15
  export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
16
16
  import cn from 'classnames';
@@ -2702,20 +2702,7 @@ const SubSectionPanel = ({ title, children, hasContent, rightComponent, defaultI
2702
2702
  };
2703
2703
 
2704
2704
  const operation = {
2705
- id: '?http-operation-id?',
2706
- iid: 'GET-simple',
2707
- method: 'get',
2708
- path: '/todos',
2709
- summary: 'Get 200',
2710
- responses: [
2711
- {
2712
- id: '?http-response-200?',
2713
- code: '200',
2714
- description: 'OK',
2715
- },
2716
- ],
2717
- servers: [{ id: '?http-server-0?', url: 'https://todos.stoplight.io' }],
2718
- };
2705
+ id: '?http-operation-id?'};
2719
2706
 
2720
2707
  const oauthFlowNames = {
2721
2708
  implicit: 'Implicit',
@@ -3606,33 +3593,37 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3606
3593
  });
3607
3594
  }, []);
3608
3595
  const updatedTree = updateTocTree(tree, '');
3609
- const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3610
- let firstMatch;
3611
- let hasAnyLastIndexMatch = false;
3612
- if (!id)
3613
- return [firstMatch, hasAnyLastIndexMatch];
3614
- const walk = (arr, stack) => {
3615
- for (const itm of arr) {
3616
- const newStack = stack.concat(itm);
3617
- const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3618
- if (matches) {
3619
- if (!firstMatch)
3620
- firstMatch = itm;
3621
- const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3622
- if (hasLastIndexMatch)
3623
- hasAnyLastIndexMatch = true;
3596
+ const findMatchingItems = (updateTree, activeId, lastActiveIndex) => {
3597
+ let exactMatch;
3598
+ let partialMatch;
3599
+ const searchInChildren = (items) => {
3600
+ for (const item of items) {
3601
+ const hasSlug = 'slug' in item;
3602
+ const hasId = 'id' in item;
3603
+ const isIdMatch = (hasSlug && item.slug === activeId) || (hasId && item.id === activeId);
3604
+ if (isIdMatch) {
3605
+ const hasIndex = 'index' in item;
3606
+ if (hasIndex && item.index === lastActiveIndex) {
3607
+ exactMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : item;
3608
+ }
3609
+ else {
3610
+ partialMatch = partialMatch !== null && partialMatch !== void 0 ? partialMatch : item;
3611
+ }
3624
3612
  }
3625
- if ('items' in itm && Array.isArray(itm.items)) {
3626
- if (walk(itm.items, newStack))
3627
- return true;
3613
+ const hasItems = 'items' in item;
3614
+ if (hasItems && Array.isArray(item.items)) {
3615
+ searchInChildren(item.items);
3628
3616
  }
3629
3617
  }
3630
- return false;
3631
3618
  };
3632
- walk(items, []);
3633
- return [firstMatch, hasAnyLastIndexMatch];
3634
- }, [lastActiveIndex]);
3635
- const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3619
+ searchInChildren(updateTree);
3620
+ const hasExactMatch = exactMatch !== undefined;
3621
+ const bestMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : partialMatch;
3622
+ return [bestMatch, hasExactMatch];
3623
+ };
3624
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => {
3625
+ return findMatchingItems(updatedTree, activeId, lastActiveIndex);
3626
+ }, [updatedTree, activeId, lastActiveIndex]);
3636
3627
  React.useEffect(() => {
3637
3628
  if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3638
3629
  setLastActiveIndex(firstMatchItem.index);
@@ -4175,15 +4166,15 @@ const useRouter = (router, basePath, staticRouterPath) => {
4175
4166
  const components = {
4176
4167
  a: ReactRouterMarkdownLink,
4177
4168
  h2: (_a) => {
4178
- var props = __rest(_a, ["color"]);
4169
+ var { color } = _a, props = __rest(_a, ["color"]);
4179
4170
  return React.createElement(LinkHeading, Object.assign({ size: 2 }, props));
4180
4171
  },
4181
4172
  h3: (_a) => {
4182
- var props = __rest(_a, ["color"]);
4173
+ var { color } = _a, props = __rest(_a, ["color"]);
4183
4174
  return React.createElement(LinkHeading, Object.assign({ size: 3 }, props));
4184
4175
  },
4185
4176
  h4: (_a) => {
4186
- var props = __rest(_a, ["color"]);
4177
+ var { color } = _a, props = __rest(_a, ["color"]);
4187
4178
  return React.createElement(LinkHeading, Object.assign({ size: 4 }, props));
4188
4179
  },
4189
4180
  };
package/index.js CHANGED
@@ -2723,20 +2723,7 @@ const SubSectionPanel = ({ title, children, hasContent, rightComponent, defaultI
2723
2723
  };
2724
2724
 
2725
2725
  const operation = {
2726
- id: '?http-operation-id?',
2727
- iid: 'GET-simple',
2728
- method: 'get',
2729
- path: '/todos',
2730
- summary: 'Get 200',
2731
- responses: [
2732
- {
2733
- id: '?http-response-200?',
2734
- code: '200',
2735
- description: 'OK',
2736
- },
2737
- ],
2738
- servers: [{ id: '?http-server-0?', url: 'https://todos.stoplight.io' }],
2739
- };
2726
+ id: '?http-operation-id?'};
2740
2727
 
2741
2728
  const oauthFlowNames = {
2742
2729
  implicit: 'Implicit',
@@ -3627,33 +3614,37 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
3627
3614
  });
3628
3615
  }, []);
3629
3616
  const updatedTree = updateTocTree(tree, '');
3630
- const findFirstMatchAndIndexMatch = React__namespace.useCallback((items, id) => {
3631
- let firstMatch;
3632
- let hasAnyLastIndexMatch = false;
3633
- if (!id)
3634
- return [firstMatch, hasAnyLastIndexMatch];
3635
- const walk = (arr, stack) => {
3636
- for (const itm of arr) {
3637
- const newStack = stack.concat(itm);
3638
- const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3639
- if (matches) {
3640
- if (!firstMatch)
3641
- firstMatch = itm;
3642
- const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3643
- if (hasLastIndexMatch)
3644
- hasAnyLastIndexMatch = true;
3617
+ const findMatchingItems = (updateTree, activeId, lastActiveIndex) => {
3618
+ let exactMatch;
3619
+ let partialMatch;
3620
+ const searchInChildren = (items) => {
3621
+ for (const item of items) {
3622
+ const hasSlug = 'slug' in item;
3623
+ const hasId = 'id' in item;
3624
+ const isIdMatch = (hasSlug && item.slug === activeId) || (hasId && item.id === activeId);
3625
+ if (isIdMatch) {
3626
+ const hasIndex = 'index' in item;
3627
+ if (hasIndex && item.index === lastActiveIndex) {
3628
+ exactMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : item;
3629
+ }
3630
+ else {
3631
+ partialMatch = partialMatch !== null && partialMatch !== void 0 ? partialMatch : item;
3632
+ }
3645
3633
  }
3646
- if ('items' in itm && Array.isArray(itm.items)) {
3647
- if (walk(itm.items, newStack))
3648
- return true;
3634
+ const hasItems = 'items' in item;
3635
+ if (hasItems && Array.isArray(item.items)) {
3636
+ searchInChildren(item.items);
3649
3637
  }
3650
3638
  }
3651
- return false;
3652
3639
  };
3653
- walk(items, []);
3654
- return [firstMatch, hasAnyLastIndexMatch];
3655
- }, [lastActiveIndex]);
3656
- const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3640
+ searchInChildren(updateTree);
3641
+ const hasExactMatch = exactMatch !== undefined;
3642
+ const bestMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : partialMatch;
3643
+ return [bestMatch, hasExactMatch];
3644
+ };
3645
+ const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => {
3646
+ return findMatchingItems(updatedTree, activeId, lastActiveIndex);
3647
+ }, [updatedTree, activeId, lastActiveIndex]);
3657
3648
  React__namespace.useEffect(() => {
3658
3649
  if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3659
3650
  setLastActiveIndex(firstMatchItem.index);
@@ -4196,15 +4187,15 @@ const useRouter = (router, basePath, staticRouterPath) => {
4196
4187
  const components = {
4197
4188
  a: ReactRouterMarkdownLink,
4198
4189
  h2: (_a) => {
4199
- var props = tslib.__rest(_a, ["color"]);
4190
+ var { color } = _a, props = tslib.__rest(_a, ["color"]);
4200
4191
  return React__namespace.createElement(LinkHeading, Object.assign({ size: 2 }, props));
4201
4192
  },
4202
4193
  h3: (_a) => {
4203
- var props = tslib.__rest(_a, ["color"]);
4194
+ var { color } = _a, props = tslib.__rest(_a, ["color"]);
4204
4195
  return React__namespace.createElement(LinkHeading, Object.assign({ size: 3 }, props));
4205
4196
  },
4206
4197
  h4: (_a) => {
4207
- var props = tslib.__rest(_a, ["color"]);
4198
+ var { color } = _a, props = tslib.__rest(_a, ["color"]);
4208
4199
  return React__namespace.createElement(LinkHeading, Object.assign({ size: 4 }, props));
4209
4200
  },
4210
4201
  };
package/index.mjs CHANGED
@@ -10,7 +10,7 @@ import { parse } from '@stoplight/yaml';
10
10
  import { isArray as isArray$1, Box, useBreakpoints, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading as LinkHeading$1, NodeAnnotation, Callout, useModalState, Modal, ListBox, ListBoxItem, TabList, Tab, Tabs, TabPanels, TabPanel, Heading, useClipboard, Drawer, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
11
11
  import isObject from 'lodash/isObject.js';
12
12
  import { withErrorBoundary } from '@stoplight/react-error-boundary';
13
- import { useLocation, Link as Link$1, BrowserRouter, MemoryRouter, HashRouter, useInRouterContext, Routes, Route } from 'react-router-dom';
13
+ import { useLocation, Link as Link$1, HashRouter, MemoryRouter, BrowserRouter, useInRouterContext, Routes, Route } from 'react-router-dom';
14
14
  import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
15
15
  export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
16
16
  import cn from 'classnames';
@@ -2702,20 +2702,7 @@ const SubSectionPanel = ({ title, children, hasContent, rightComponent, defaultI
2702
2702
  };
2703
2703
 
2704
2704
  const operation = {
2705
- id: '?http-operation-id?',
2706
- iid: 'GET-simple',
2707
- method: 'get',
2708
- path: '/todos',
2709
- summary: 'Get 200',
2710
- responses: [
2711
- {
2712
- id: '?http-response-200?',
2713
- code: '200',
2714
- description: 'OK',
2715
- },
2716
- ],
2717
- servers: [{ id: '?http-server-0?', url: 'https://todos.stoplight.io' }],
2718
- };
2705
+ id: '?http-operation-id?'};
2719
2706
 
2720
2707
  const oauthFlowNames = {
2721
2708
  implicit: 'Implicit',
@@ -3606,33 +3593,37 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3606
3593
  });
3607
3594
  }, []);
3608
3595
  const updatedTree = updateTocTree(tree, '');
3609
- const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3610
- let firstMatch;
3611
- let hasAnyLastIndexMatch = false;
3612
- if (!id)
3613
- return [firstMatch, hasAnyLastIndexMatch];
3614
- const walk = (arr, stack) => {
3615
- for (const itm of arr) {
3616
- const newStack = stack.concat(itm);
3617
- const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3618
- if (matches) {
3619
- if (!firstMatch)
3620
- firstMatch = itm;
3621
- const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3622
- if (hasLastIndexMatch)
3623
- hasAnyLastIndexMatch = true;
3596
+ const findMatchingItems = (updateTree, activeId, lastActiveIndex) => {
3597
+ let exactMatch;
3598
+ let partialMatch;
3599
+ const searchInChildren = (items) => {
3600
+ for (const item of items) {
3601
+ const hasSlug = 'slug' in item;
3602
+ const hasId = 'id' in item;
3603
+ const isIdMatch = (hasSlug && item.slug === activeId) || (hasId && item.id === activeId);
3604
+ if (isIdMatch) {
3605
+ const hasIndex = 'index' in item;
3606
+ if (hasIndex && item.index === lastActiveIndex) {
3607
+ exactMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : item;
3608
+ }
3609
+ else {
3610
+ partialMatch = partialMatch !== null && partialMatch !== void 0 ? partialMatch : item;
3611
+ }
3624
3612
  }
3625
- if ('items' in itm && Array.isArray(itm.items)) {
3626
- if (walk(itm.items, newStack))
3627
- return true;
3613
+ const hasItems = 'items' in item;
3614
+ if (hasItems && Array.isArray(item.items)) {
3615
+ searchInChildren(item.items);
3628
3616
  }
3629
3617
  }
3630
- return false;
3631
3618
  };
3632
- walk(items, []);
3633
- return [firstMatch, hasAnyLastIndexMatch];
3634
- }, [lastActiveIndex]);
3635
- const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3619
+ searchInChildren(updateTree);
3620
+ const hasExactMatch = exactMatch !== undefined;
3621
+ const bestMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : partialMatch;
3622
+ return [bestMatch, hasExactMatch];
3623
+ };
3624
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => {
3625
+ return findMatchingItems(updatedTree, activeId, lastActiveIndex);
3626
+ }, [updatedTree, activeId, lastActiveIndex]);
3636
3627
  React.useEffect(() => {
3637
3628
  if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3638
3629
  setLastActiveIndex(firstMatchItem.index);
@@ -4175,15 +4166,15 @@ const useRouter = (router, basePath, staticRouterPath) => {
4175
4166
  const components = {
4176
4167
  a: ReactRouterMarkdownLink,
4177
4168
  h2: (_a) => {
4178
- var props = __rest(_a, ["color"]);
4169
+ var { color } = _a, props = __rest(_a, ["color"]);
4179
4170
  return React.createElement(LinkHeading, Object.assign({ size: 2 }, props));
4180
4171
  },
4181
4172
  h3: (_a) => {
4182
- var props = __rest(_a, ["color"]);
4173
+ var { color } = _a, props = __rest(_a, ["color"]);
4183
4174
  return React.createElement(LinkHeading, Object.assign({ size: 3 }, props));
4184
4175
  },
4185
4176
  h4: (_a) => {
4186
- var props = __rest(_a, ["color"]);
4177
+ var { color } = _a, props = __rest(_a, ["color"]);
4187
4178
  return React.createElement(LinkHeading, Object.assign({ size: 4 }, props));
4188
4179
  },
4189
4180
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "9.0.16",
3
+ "version": "9.0.17",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",