@stoplight/elements-core 9.0.13-alpha-0.8 → 9.0.13-alpha-0.10

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
@@ -1803,20 +1803,15 @@ const generateExamplesFromJsonSchema = (schema) => {
1803
1803
  }
1804
1804
  }
1805
1805
  }
1806
- if (examples.length && 'x-stoplight' in schema) {
1806
+ if (examples.length) {
1807
1807
  return examples;
1808
1808
  }
1809
1809
  try {
1810
- let originalExamples = [];
1811
- if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.examples)) {
1812
- originalExamples = JSON.parse(JSON.stringify(schema.examples));
1813
- delete schema.examples;
1814
- }
1815
1810
  const generated = Sampler.sample(schema, {
1816
1811
  maxSampleDepth: 4,
1817
1812
  ticks: 6000,
1818
1813
  });
1819
- let updatedExamples = generated !== null
1814
+ return generated !== null
1820
1815
  ? [
1821
1816
  {
1822
1817
  label: 'default',
@@ -1824,16 +1819,6 @@ const generateExamplesFromJsonSchema = (schema) => {
1824
1819
  },
1825
1820
  ]
1826
1821
  : [{ label: 'default', data: '' }];
1827
- if (originalExamples.length) {
1828
- schema.examples = originalExamples;
1829
- examples.forEach(item => {
1830
- item.data = updatedExamples[0].data;
1831
- });
1832
- return examples;
1833
- }
1834
- else {
1835
- return updatedExamples;
1836
- }
1837
1822
  }
1838
1823
  catch (e) {
1839
1824
  return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
@@ -3341,7 +3326,7 @@ const HttpServiceComponent = React.memo(({ data: unresolvedData, location = {},
3341
3326
  var _a, _b, _c, _d;
3342
3327
  const { nodeHasChanged } = useOptionsCtx();
3343
3328
  const data = useResolvedObject(unresolvedData);
3344
- const { ref: layoutRef, isCompact } = useIsCompact(layoutOptions);
3329
+ const { ref: layoutRef } = useIsCompact(layoutOptions);
3345
3330
  const { search, pathname } = location;
3346
3331
  const mocking = React.useContext(MockingContext);
3347
3332
  const query = new URLSearchParams(search);
@@ -3353,7 +3338,7 @@ const HttpServiceComponent = React.memo(({ data: unresolvedData, location = {},
3353
3338
  React.createElement(Box, { pos: "relative" },
3354
3339
  React.createElement(Heading, { size: 1, mb: 4, fontWeight: "semibold" }, data.name),
3355
3340
  React.createElement(NodeAnnotation, { change: nameChanged })),
3356
- exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React.createElement(ExportButton, Object.assign({}, exportProps)))),
3341
+ exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React.createElement(ExportButton, Object.assign({}, exportProps)))),
3357
3342
  data.version && (React.createElement(Box, { mb: 5, pos: "relative" },
3358
3343
  React.createElement(VersionBadge, { value: data.version }),
3359
3344
  React.createElement(NodeAnnotation, { change: versionChanged }))),
@@ -3389,7 +3374,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
3389
3374
  isDeprecated && React.createElement(DeprecatedBadge, null),
3390
3375
  isInternal && React.createElement(InternalBadge, null))),
3391
3376
  React.createElement(NodeAnnotation, { change: titleChanged })),
3392
- exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React.createElement(ExportButton, Object.assign({}, exportProps))));
3377
+ exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React.createElement(ExportButton, Object.assign({}, exportProps))));
3393
3378
  const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && React.createElement(ModelExamples, { data: data, isCollapsible: isCompact });
3394
3379
  const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId, attr: 'description' });
3395
3380
  const description = (React.createElement(VStack, { spacing: 10 },
@@ -3621,33 +3606,33 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3621
3606
  });
3622
3607
  }, []);
3623
3608
  const updatedTree = updateTocTree(tree, '');
3624
- const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3625
- let firstMatch;
3626
- let hasAnyLastIndexMatch = false;
3627
- if (!id)
3628
- return [firstMatch, hasAnyLastIndexMatch];
3629
- const walk = (arr, stack) => {
3630
- for (const itm of arr) {
3631
- const newStack = stack.concat(itm);
3632
- const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3633
- if (matches) {
3634
- if (!firstMatch)
3635
- firstMatch = itm;
3636
- const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3637
- if (hasLastIndexMatch)
3638
- hasAnyLastIndexMatch = true;
3609
+ function findMatchingItems(updateTree, activeId, lastActiveIndex) {
3610
+ let exactMatch;
3611
+ let partialMatch;
3612
+ const searchInChildren = (items) => {
3613
+ for (const item of items) {
3614
+ const isIdMatch = item.slug === activeId || item.id === activeId;
3615
+ if (isIdMatch) {
3616
+ if (item.index === lastActiveIndex) {
3617
+ exactMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : item;
3618
+ }
3619
+ else {
3620
+ partialMatch = partialMatch !== null && partialMatch !== void 0 ? partialMatch : item;
3621
+ }
3639
3622
  }
3640
- if ('items' in itm && Array.isArray(itm.items)) {
3641
- if (walk(itm.items, newStack))
3642
- return true;
3623
+ if (Array.isArray(item.items)) {
3624
+ searchInChildren(item.items);
3643
3625
  }
3644
3626
  }
3645
- return false;
3646
3627
  };
3647
- walk(items, []);
3648
- return [firstMatch, hasAnyLastIndexMatch];
3649
- }, [lastActiveIndex]);
3650
- const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3628
+ searchInChildren(updateTree);
3629
+ const hasExactMatch = exactMatch !== undefined;
3630
+ const bestMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : partialMatch;
3631
+ return [bestMatch, hasExactMatch];
3632
+ }
3633
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => {
3634
+ return findMatchingItems(updatedTree, activeId, lastActiveIndex);
3635
+ }, [updatedTree, activeId, lastActiveIndex]);
3651
3636
  React.useEffect(() => {
3652
3637
  if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3653
3638
  setLastActiveIndex(firstMatchItem.index);
package/index.js CHANGED
@@ -1824,20 +1824,15 @@ const generateExamplesFromJsonSchema = (schema) => {
1824
1824
  }
1825
1825
  }
1826
1826
  }
1827
- if (examples.length && 'x-stoplight' in schema) {
1827
+ if (examples.length) {
1828
1828
  return examples;
1829
1829
  }
1830
1830
  try {
1831
- let originalExamples = [];
1832
- if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.examples)) {
1833
- originalExamples = JSON.parse(JSON.stringify(schema.examples));
1834
- delete schema.examples;
1835
- }
1836
1831
  const generated = Sampler__namespace.sample(schema, {
1837
1832
  maxSampleDepth: 4,
1838
1833
  ticks: 6000,
1839
1834
  });
1840
- let updatedExamples = generated !== null
1835
+ return generated !== null
1841
1836
  ? [
1842
1837
  {
1843
1838
  label: 'default',
@@ -1845,16 +1840,6 @@ const generateExamplesFromJsonSchema = (schema) => {
1845
1840
  },
1846
1841
  ]
1847
1842
  : [{ label: 'default', data: '' }];
1848
- if (originalExamples.length) {
1849
- schema.examples = originalExamples;
1850
- examples.forEach(item => {
1851
- item.data = updatedExamples[0].data;
1852
- });
1853
- return examples;
1854
- }
1855
- else {
1856
- return updatedExamples;
1857
- }
1858
1843
  }
1859
1844
  catch (e) {
1860
1845
  return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
@@ -3362,7 +3347,7 @@ const HttpServiceComponent = React__namespace.memo(({ data: unresolvedData, loca
3362
3347
  var _a, _b, _c, _d;
3363
3348
  const { nodeHasChanged } = useOptionsCtx();
3364
3349
  const data = useResolvedObject(unresolvedData);
3365
- const { ref: layoutRef, isCompact } = useIsCompact(layoutOptions);
3350
+ const { ref: layoutRef } = useIsCompact(layoutOptions);
3366
3351
  const { search, pathname } = location;
3367
3352
  const mocking = React__namespace.useContext(MockingContext);
3368
3353
  const query = new URLSearchParams(search);
@@ -3374,7 +3359,7 @@ const HttpServiceComponent = React__namespace.memo(({ data: unresolvedData, loca
3374
3359
  React__namespace.createElement(mosaic.Box, { pos: "relative" },
3375
3360
  React__namespace.createElement(mosaic.Heading, { size: 1, mb: 4, fontWeight: "semibold" }, data.name),
3376
3361
  React__namespace.createElement(mosaic.NodeAnnotation, { change: nameChanged })),
3377
- exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React__namespace.createElement(ExportButton, Object.assign({}, exportProps)))),
3362
+ exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React__namespace.createElement(ExportButton, Object.assign({}, exportProps)))),
3378
3363
  data.version && (React__namespace.createElement(mosaic.Box, { mb: 5, pos: "relative" },
3379
3364
  React__namespace.createElement(VersionBadge, { value: data.version }),
3380
3365
  React__namespace.createElement(mosaic.NodeAnnotation, { change: versionChanged }))),
@@ -3410,7 +3395,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
3410
3395
  isDeprecated && React__namespace.createElement(DeprecatedBadge, null),
3411
3396
  isInternal && React__namespace.createElement(InternalBadge, null))),
3412
3397
  React__namespace.createElement(mosaic.NodeAnnotation, { change: titleChanged })),
3413
- exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React__namespace.createElement(ExportButton, Object.assign({}, exportProps))));
3398
+ exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React__namespace.createElement(ExportButton, Object.assign({}, exportProps))));
3414
3399
  const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && React__namespace.createElement(ModelExamples, { data: data, isCollapsible: isCompact });
3415
3400
  const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId, attr: 'description' });
3416
3401
  const description = (React__namespace.createElement(mosaic.VStack, { spacing: 10 },
@@ -3642,33 +3627,33 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
3642
3627
  });
3643
3628
  }, []);
3644
3629
  const updatedTree = updateTocTree(tree, '');
3645
- const findFirstMatchAndIndexMatch = React__namespace.useCallback((items, id) => {
3646
- let firstMatch;
3647
- let hasAnyLastIndexMatch = false;
3648
- if (!id)
3649
- return [firstMatch, hasAnyLastIndexMatch];
3650
- const walk = (arr, stack) => {
3651
- for (const itm of arr) {
3652
- const newStack = stack.concat(itm);
3653
- const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3654
- if (matches) {
3655
- if (!firstMatch)
3656
- firstMatch = itm;
3657
- const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3658
- if (hasLastIndexMatch)
3659
- hasAnyLastIndexMatch = true;
3630
+ function findMatchingItems(updateTree, activeId, lastActiveIndex) {
3631
+ let exactMatch;
3632
+ let partialMatch;
3633
+ const searchInChildren = (items) => {
3634
+ for (const item of items) {
3635
+ const isIdMatch = item.slug === activeId || item.id === activeId;
3636
+ if (isIdMatch) {
3637
+ if (item.index === lastActiveIndex) {
3638
+ exactMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : item;
3639
+ }
3640
+ else {
3641
+ partialMatch = partialMatch !== null && partialMatch !== void 0 ? partialMatch : item;
3642
+ }
3660
3643
  }
3661
- if ('items' in itm && Array.isArray(itm.items)) {
3662
- if (walk(itm.items, newStack))
3663
- return true;
3644
+ if (Array.isArray(item.items)) {
3645
+ searchInChildren(item.items);
3664
3646
  }
3665
3647
  }
3666
- return false;
3667
3648
  };
3668
- walk(items, []);
3669
- return [firstMatch, hasAnyLastIndexMatch];
3670
- }, [lastActiveIndex]);
3671
- const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3649
+ searchInChildren(updateTree);
3650
+ const hasExactMatch = exactMatch !== undefined;
3651
+ const bestMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : partialMatch;
3652
+ return [bestMatch, hasExactMatch];
3653
+ }
3654
+ const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => {
3655
+ return findMatchingItems(updatedTree, activeId, lastActiveIndex);
3656
+ }, [updatedTree, activeId, lastActiveIndex]);
3672
3657
  React__namespace.useEffect(() => {
3673
3658
  if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3674
3659
  setLastActiveIndex(firstMatchItem.index);
package/index.mjs CHANGED
@@ -1803,20 +1803,15 @@ const generateExamplesFromJsonSchema = (schema) => {
1803
1803
  }
1804
1804
  }
1805
1805
  }
1806
- if (examples.length && 'x-stoplight' in schema) {
1806
+ if (examples.length) {
1807
1807
  return examples;
1808
1808
  }
1809
1809
  try {
1810
- let originalExamples = [];
1811
- if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.examples)) {
1812
- originalExamples = JSON.parse(JSON.stringify(schema.examples));
1813
- delete schema.examples;
1814
- }
1815
1810
  const generated = Sampler.sample(schema, {
1816
1811
  maxSampleDepth: 4,
1817
1812
  ticks: 6000,
1818
1813
  });
1819
- let updatedExamples = generated !== null
1814
+ return generated !== null
1820
1815
  ? [
1821
1816
  {
1822
1817
  label: 'default',
@@ -1824,16 +1819,6 @@ const generateExamplesFromJsonSchema = (schema) => {
1824
1819
  },
1825
1820
  ]
1826
1821
  : [{ label: 'default', data: '' }];
1827
- if (originalExamples.length) {
1828
- schema.examples = originalExamples;
1829
- examples.forEach(item => {
1830
- item.data = updatedExamples[0].data;
1831
- });
1832
- return examples;
1833
- }
1834
- else {
1835
- return updatedExamples;
1836
- }
1837
1822
  }
1838
1823
  catch (e) {
1839
1824
  return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
@@ -3341,7 +3326,7 @@ const HttpServiceComponent = React.memo(({ data: unresolvedData, location = {},
3341
3326
  var _a, _b, _c, _d;
3342
3327
  const { nodeHasChanged } = useOptionsCtx();
3343
3328
  const data = useResolvedObject(unresolvedData);
3344
- const { ref: layoutRef, isCompact } = useIsCompact(layoutOptions);
3329
+ const { ref: layoutRef } = useIsCompact(layoutOptions);
3345
3330
  const { search, pathname } = location;
3346
3331
  const mocking = React.useContext(MockingContext);
3347
3332
  const query = new URLSearchParams(search);
@@ -3353,7 +3338,7 @@ const HttpServiceComponent = React.memo(({ data: unresolvedData, location = {},
3353
3338
  React.createElement(Box, { pos: "relative" },
3354
3339
  React.createElement(Heading, { size: 1, mb: 4, fontWeight: "semibold" }, data.name),
3355
3340
  React.createElement(NodeAnnotation, { change: nameChanged })),
3356
- exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React.createElement(ExportButton, Object.assign({}, exportProps)))),
3341
+ exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React.createElement(ExportButton, Object.assign({}, exportProps)))),
3357
3342
  data.version && (React.createElement(Box, { mb: 5, pos: "relative" },
3358
3343
  React.createElement(VersionBadge, { value: data.version }),
3359
3344
  React.createElement(NodeAnnotation, { change: versionChanged }))),
@@ -3389,7 +3374,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
3389
3374
  isDeprecated && React.createElement(DeprecatedBadge, null),
3390
3375
  isInternal && React.createElement(InternalBadge, null))),
3391
3376
  React.createElement(NodeAnnotation, { change: titleChanged })),
3392
- exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React.createElement(ExportButton, Object.assign({}, exportProps))));
3377
+ exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React.createElement(ExportButton, Object.assign({}, exportProps))));
3393
3378
  const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && React.createElement(ModelExamples, { data: data, isCollapsible: isCompact });
3394
3379
  const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId, attr: 'description' });
3395
3380
  const description = (React.createElement(VStack, { spacing: 10 },
@@ -3621,33 +3606,33 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3621
3606
  });
3622
3607
  }, []);
3623
3608
  const updatedTree = updateTocTree(tree, '');
3624
- const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3625
- let firstMatch;
3626
- let hasAnyLastIndexMatch = false;
3627
- if (!id)
3628
- return [firstMatch, hasAnyLastIndexMatch];
3629
- const walk = (arr, stack) => {
3630
- for (const itm of arr) {
3631
- const newStack = stack.concat(itm);
3632
- const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3633
- if (matches) {
3634
- if (!firstMatch)
3635
- firstMatch = itm;
3636
- const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3637
- if (hasLastIndexMatch)
3638
- hasAnyLastIndexMatch = true;
3609
+ function findMatchingItems(updateTree, activeId, lastActiveIndex) {
3610
+ let exactMatch;
3611
+ let partialMatch;
3612
+ const searchInChildren = (items) => {
3613
+ for (const item of items) {
3614
+ const isIdMatch = item.slug === activeId || item.id === activeId;
3615
+ if (isIdMatch) {
3616
+ if (item.index === lastActiveIndex) {
3617
+ exactMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : item;
3618
+ }
3619
+ else {
3620
+ partialMatch = partialMatch !== null && partialMatch !== void 0 ? partialMatch : item;
3621
+ }
3639
3622
  }
3640
- if ('items' in itm && Array.isArray(itm.items)) {
3641
- if (walk(itm.items, newStack))
3642
- return true;
3623
+ if (Array.isArray(item.items)) {
3624
+ searchInChildren(item.items);
3643
3625
  }
3644
3626
  }
3645
- return false;
3646
3627
  };
3647
- walk(items, []);
3648
- return [firstMatch, hasAnyLastIndexMatch];
3649
- }, [lastActiveIndex]);
3650
- const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3628
+ searchInChildren(updateTree);
3629
+ const hasExactMatch = exactMatch !== undefined;
3630
+ const bestMatch = exactMatch !== null && exactMatch !== void 0 ? exactMatch : partialMatch;
3631
+ return [bestMatch, hasExactMatch];
3632
+ }
3633
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => {
3634
+ return findMatchingItems(updatedTree, activeId, lastActiveIndex);
3635
+ }, [updatedTree, activeId, lastActiveIndex]);
3651
3636
  React.useEffect(() => {
3652
3637
  if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3653
3638
  setLastActiveIndex(firstMatchItem.index);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "9.0.13-alpha-0.8",
3
+ "version": "9.0.13-alpha-0.10",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",