@stoplight/elements-core 7.3.6 → 7.3.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.
@@ -1,5 +1,6 @@
1
1
  import { MDAST } from '@stoplight/markdown';
2
+ import * as React from 'react';
2
3
  import { DocsComponentProps } from '..';
3
4
  declare type ArticleProps = DocsComponentProps<string | MDAST.Root>;
4
- export declare const Article: import("react").FunctionComponent<ArticleProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
5
+ export declare const Article: React.FunctionComponent<ArticleProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
5
6
  export {};
@@ -1,4 +1,5 @@
1
1
  import { IHttpOperation } from '@stoplight/types';
2
+ import * as React from 'react';
2
3
  import { DocsComponentProps } from '..';
3
4
  export declare type HttpOperationProps = DocsComponentProps<IHttpOperation>;
4
- export declare const HttpOperation: import("react").FunctionComponent<HttpOperationProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
5
+ export declare const HttpOperation: React.FunctionComponent<HttpOperationProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
@@ -1,4 +1,5 @@
1
1
  import { IHttpService } from '@stoplight/types';
2
+ import * as React from 'react';
2
3
  import { DocsComponentProps } from '..';
3
4
  export declare type HttpServiceProps = DocsComponentProps<Partial<IHttpService>>;
4
- export declare const HttpService: import("react").FunctionComponent<HttpServiceProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
5
+ export declare const HttpService: React.FunctionComponent<HttpServiceProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
@@ -1,4 +1,5 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
+ import * as React from 'react';
2
3
  import { DocsComponentProps } from '..';
3
4
  export declare type ModelProps = DocsComponentProps<JSONSchema7>;
4
- export declare const Model: import("react").FunctionComponent<ModelProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
5
+ export declare const Model: React.FunctionComponent<ModelProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ interface LoadMoreProps {
3
+ loading: boolean;
4
+ onClick: () => void;
5
+ }
6
+ export declare const LoadMore: React.FC<LoadMoreProps>;
7
+ export {};
package/index.esm.js CHANGED
@@ -1187,6 +1187,7 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
1187
1187
  }
1188
1188
  catch (e) {
1189
1189
  console.warn(e);
1190
+ return `Example cannot be created for this schema\n${e}`;
1190
1191
  }
1191
1192
  return '';
1192
1193
  };
@@ -1216,17 +1217,26 @@ const generateExamplesFromJsonSchema = (schema) => {
1216
1217
  if (examples.length) {
1217
1218
  return examples;
1218
1219
  }
1219
- const generated = Sampler.sample(schema, {
1220
- maxSampleDepth: 4,
1221
- });
1222
- return generated !== null
1223
- ? [
1224
- {
1225
- label: 'default',
1226
- data: (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1227
- },
1228
- ]
1229
- : [{ label: 'default', data: '' }];
1220
+ try {
1221
+ const generated = Sampler.sample(schema, {
1222
+ maxSampleDepth: 4,
1223
+ });
1224
+ return generated !== null
1225
+ ? [
1226
+ {
1227
+ label: 'default',
1228
+ data: (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1229
+ },
1230
+ ]
1231
+ : [{ label: 'default', data: '' }];
1232
+ }
1233
+ catch (e) {
1234
+ console.error(e);
1235
+ return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
1236
+ }
1237
+ };
1238
+ const exceedsSize = (example, size = 500) => {
1239
+ return example.split(/\r\n|\r|\n/).length > size;
1230
1240
  };
1231
1241
 
1232
1242
  const useTextRequestBodyState = (mediaTypeContent) => {
@@ -1747,6 +1757,12 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
1747
1757
  response && 'error' in response && React.createElement(ResponseError, { state: response })));
1748
1758
  };
1749
1759
 
1760
+ const LoadMore = ({ loading, onClick }) => {
1761
+ return (React.createElement(Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
1762
+ React.createElement(Button, { "aria-label": "load-example", onPress: onClick, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
1763
+ React.createElement(Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default.")));
1764
+ };
1765
+
1750
1766
  const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode }) => {
1751
1767
  var _a;
1752
1768
  const [chosenExampleIndex, setChosenExampleIndex] = React__default.useState(0);
@@ -1761,7 +1777,10 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
1761
1777
  const responseExample = useGenerateExampleFromMediaTypeContent(responseContents, chosenExampleIndex, {
1762
1778
  skipWriteOnly: true,
1763
1779
  });
1764
- const exceededSize = responseExample.split(/\r\n|\r|\n/).length > 500;
1780
+ const handleLoadMore = () => {
1781
+ setLoading(true);
1782
+ setTimeout(() => setShow(true), 50);
1783
+ };
1765
1784
  if (!userDefinedExamples && responseMediaType !== 'application/json')
1766
1785
  return null;
1767
1786
  if (!responseExample)
@@ -1769,12 +1788,7 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
1769
1788
  const examplesSelect = userDefinedExamples && userDefinedExamples.length > 1 && (React__default.createElement(Select, { "aria-label": "Response Example", value: String(chosenExampleIndex), options: userDefinedExamples.map((example, index) => ({ value: index, label: example.key })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Response Example: " }));
1770
1789
  return (React__default.createElement(Panel, { rounded: true, isCollapsible: false },
1771
1790
  React__default.createElement(Panel.Titlebar, null, examplesSelect || React__default.createElement(Text, { color: "body" }, "Response Example")),
1772
- React__default.createElement(Panel.Content, { p: 0 }, (exceededSize && show) || !exceededSize ? (React__default.createElement(CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default.createElement(Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
1773
- React__default.createElement(Button, { "aria-label": "load-example", onPress: () => {
1774
- setLoading(true);
1775
- setTimeout(() => setShow(true), 50);
1776
- }, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
1777
- React__default.createElement(Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default."))))));
1791
+ React__default.createElement(Panel.Content, { p: 0 }, show || !exceedsSize(responseExample) ? (React__default.createElement(CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default.createElement(LoadMore, { loading: loading, onClick: handleLoadMore })))));
1778
1792
  };
1779
1793
 
1780
1794
  const TryItWithRequestSamples = (_a) => {
@@ -2158,10 +2172,16 @@ const HttpService = withErrorBoundary(HttpServiceComponent, { recoverableProps:
2158
2172
  const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
2159
2173
  var _a;
2160
2174
  const [chosenExampleIndex, setChosenExampleIndex] = React.useState(0);
2175
+ const [show, setShow] = React.useState(false);
2176
+ const [loading, setLoading] = React.useState(false);
2161
2177
  const resolveRef = useInlineRefResolver();
2162
2178
  const data = useResolvedObject(unresolvedData);
2163
2179
  const title = (_a = data.title) !== null && _a !== void 0 ? _a : nodeTitle;
2164
2180
  const isInternal = !!data['x-internal'];
2181
+ const handleLoadMorePress = () => {
2182
+ setLoading(true);
2183
+ setTimeout(() => setShow(true), 50);
2184
+ };
2165
2185
  const examples = React.useMemo(() => generateExamplesFromJsonSchema(data), [data]);
2166
2186
  const shouldDisplayHeader = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && (title !== undefined || (exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport)));
2167
2187
  const header = (shouldDisplayHeader || isInternal) && (React.createElement(React.Fragment, null,
@@ -2176,8 +2196,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
2176
2196
  const examplesSelect = examples.length > 1 && (React.createElement(Select, { "aria-label": "Example", value: String(chosenExampleIndex), options: examples.map(({ label }, index) => ({ value: index, label })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Example: " }));
2177
2197
  const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && (React.createElement(Panel, { rounded: true, isCollapsible: false },
2178
2198
  React.createElement(Panel.Titlebar, null, examplesSelect || (React.createElement(Text, { color: "body", role: "heading" }, "Example"))),
2179
- React.createElement(Panel.Content, { p: 0 },
2180
- React.createElement(CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true }))));
2199
+ React.createElement(Panel.Content, { p: 0 }, show || !exceedsSize(examples[chosenExampleIndex].data) ? (React.createElement(CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true })) : (React.createElement(LoadMore, { loading: loading, onClick: handleLoadMorePress })))));
2181
2200
  return (React.createElement(TwoColumnLayout, { className: cn('Model', className), header: header, left: description, right: modelExamples }));
2182
2201
  };
2183
2202
  const Model = withErrorBoundary(ModelComponent, { recoverableProps: ['data'] });
package/index.js CHANGED
@@ -1220,6 +1220,7 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
1220
1220
  }
1221
1221
  catch (e) {
1222
1222
  console.warn(e);
1223
+ return `Example cannot be created for this schema\n${e}`;
1223
1224
  }
1224
1225
  return '';
1225
1226
  };
@@ -1249,17 +1250,26 @@ const generateExamplesFromJsonSchema = (schema) => {
1249
1250
  if (examples.length) {
1250
1251
  return examples;
1251
1252
  }
1252
- const generated = Sampler__namespace.sample(schema, {
1253
- maxSampleDepth: 4,
1254
- });
1255
- return generated !== null
1256
- ? [
1257
- {
1258
- label: 'default',
1259
- data: (_b = json.safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1260
- },
1261
- ]
1262
- : [{ label: 'default', data: '' }];
1253
+ try {
1254
+ const generated = Sampler__namespace.sample(schema, {
1255
+ maxSampleDepth: 4,
1256
+ });
1257
+ return generated !== null
1258
+ ? [
1259
+ {
1260
+ label: 'default',
1261
+ data: (_b = json.safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1262
+ },
1263
+ ]
1264
+ : [{ label: 'default', data: '' }];
1265
+ }
1266
+ catch (e) {
1267
+ console.error(e);
1268
+ return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
1269
+ }
1270
+ };
1271
+ const exceedsSize = (example, size = 500) => {
1272
+ return example.split(/\r\n|\r|\n/).length > size;
1263
1273
  };
1264
1274
 
1265
1275
  const useTextRequestBodyState = (mediaTypeContent) => {
@@ -1780,6 +1790,12 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
1780
1790
  response && 'error' in response && React__namespace.createElement(ResponseError, { state: response })));
1781
1791
  };
1782
1792
 
1793
+ const LoadMore = ({ loading, onClick }) => {
1794
+ return (React__namespace.createElement(mosaic.Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
1795
+ React__namespace.createElement(mosaic.Button, { "aria-label": "load-example", onPress: onClick, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
1796
+ React__namespace.createElement(mosaic.Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default.")));
1797
+ };
1798
+
1783
1799
  const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode }) => {
1784
1800
  var _a;
1785
1801
  const [chosenExampleIndex, setChosenExampleIndex] = React__default["default"].useState(0);
@@ -1794,7 +1810,10 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
1794
1810
  const responseExample = useGenerateExampleFromMediaTypeContent(responseContents, chosenExampleIndex, {
1795
1811
  skipWriteOnly: true,
1796
1812
  });
1797
- const exceededSize = responseExample.split(/\r\n|\r|\n/).length > 500;
1813
+ const handleLoadMore = () => {
1814
+ setLoading(true);
1815
+ setTimeout(() => setShow(true), 50);
1816
+ };
1798
1817
  if (!userDefinedExamples && responseMediaType !== 'application/json')
1799
1818
  return null;
1800
1819
  if (!responseExample)
@@ -1802,12 +1821,7 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
1802
1821
  const examplesSelect = userDefinedExamples && userDefinedExamples.length > 1 && (React__default["default"].createElement(mosaic.Select, { "aria-label": "Response Example", value: String(chosenExampleIndex), options: userDefinedExamples.map((example, index) => ({ value: index, label: example.key })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Response Example: " }));
1803
1822
  return (React__default["default"].createElement(mosaic.Panel, { rounded: true, isCollapsible: false },
1804
1823
  React__default["default"].createElement(mosaic.Panel.Titlebar, null, examplesSelect || React__default["default"].createElement(mosaic.Text, { color: "body" }, "Response Example")),
1805
- React__default["default"].createElement(mosaic.Panel.Content, { p: 0 }, (exceededSize && show) || !exceededSize ? (React__default["default"].createElement(mosaicCodeViewer.CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default["default"].createElement(mosaic.Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
1806
- React__default["default"].createElement(mosaic.Button, { "aria-label": "load-example", onPress: () => {
1807
- setLoading(true);
1808
- setTimeout(() => setShow(true), 50);
1809
- }, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
1810
- React__default["default"].createElement(mosaic.Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default."))))));
1824
+ React__default["default"].createElement(mosaic.Panel.Content, { p: 0 }, show || !exceedsSize(responseExample) ? (React__default["default"].createElement(mosaicCodeViewer.CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default["default"].createElement(LoadMore, { loading: loading, onClick: handleLoadMore })))));
1811
1825
  };
1812
1826
 
1813
1827
  const TryItWithRequestSamples = (_a) => {
@@ -2191,10 +2205,16 @@ const HttpService = reactErrorBoundary.withErrorBoundary(HttpServiceComponent, {
2191
2205
  const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
2192
2206
  var _a;
2193
2207
  const [chosenExampleIndex, setChosenExampleIndex] = React__namespace.useState(0);
2208
+ const [show, setShow] = React__namespace.useState(false);
2209
+ const [loading, setLoading] = React__namespace.useState(false);
2194
2210
  const resolveRef = useInlineRefResolver();
2195
2211
  const data = useResolvedObject(unresolvedData);
2196
2212
  const title = (_a = data.title) !== null && _a !== void 0 ? _a : nodeTitle;
2197
2213
  const isInternal = !!data['x-internal'];
2214
+ const handleLoadMorePress = () => {
2215
+ setLoading(true);
2216
+ setTimeout(() => setShow(true), 50);
2217
+ };
2198
2218
  const examples = React__namespace.useMemo(() => generateExamplesFromJsonSchema(data), [data]);
2199
2219
  const shouldDisplayHeader = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && (title !== undefined || (exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport)));
2200
2220
  const header = (shouldDisplayHeader || isInternal) && (React__namespace.createElement(React__namespace.Fragment, null,
@@ -2209,8 +2229,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
2209
2229
  const examplesSelect = examples.length > 1 && (React__namespace.createElement(mosaic.Select, { "aria-label": "Example", value: String(chosenExampleIndex), options: examples.map(({ label }, index) => ({ value: index, label })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Example: " }));
2210
2230
  const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && (React__namespace.createElement(mosaic.Panel, { rounded: true, isCollapsible: false },
2211
2231
  React__namespace.createElement(mosaic.Panel.Titlebar, null, examplesSelect || (React__namespace.createElement(mosaic.Text, { color: "body", role: "heading" }, "Example"))),
2212
- React__namespace.createElement(mosaic.Panel.Content, { p: 0 },
2213
- React__namespace.createElement(mosaicCodeViewer.CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true }))));
2232
+ React__namespace.createElement(mosaic.Panel.Content, { p: 0 }, show || !exceedsSize(examples[chosenExampleIndex].data) ? (React__namespace.createElement(mosaicCodeViewer.CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true })) : (React__namespace.createElement(LoadMore, { loading: loading, onClick: handleLoadMorePress })))));
2214
2233
  return (React__namespace.createElement(TwoColumnLayout, { className: cn__default["default"]('Model', className), header: header, left: description, right: modelExamples }));
2215
2234
  };
2216
2235
  const Model = reactErrorBoundary.withErrorBoundary(ModelComponent, { recoverableProps: ['data'] });
package/index.mjs CHANGED
@@ -1187,6 +1187,7 @@ const generateExampleFromMediaTypeContent = (mediaTypeContent, document, chosenE
1187
1187
  }
1188
1188
  catch (e) {
1189
1189
  console.warn(e);
1190
+ return `Example cannot be created for this schema\n${e}`;
1190
1191
  }
1191
1192
  return '';
1192
1193
  };
@@ -1216,17 +1217,26 @@ const generateExamplesFromJsonSchema = (schema) => {
1216
1217
  if (examples.length) {
1217
1218
  return examples;
1218
1219
  }
1219
- const generated = Sampler.sample(schema, {
1220
- maxSampleDepth: 4,
1221
- });
1222
- return generated !== null
1223
- ? [
1224
- {
1225
- label: 'default',
1226
- data: (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1227
- },
1228
- ]
1229
- : [{ label: 'default', data: '' }];
1220
+ try {
1221
+ const generated = Sampler.sample(schema, {
1222
+ maxSampleDepth: 4,
1223
+ });
1224
+ return generated !== null
1225
+ ? [
1226
+ {
1227
+ label: 'default',
1228
+ data: (_b = safeStringify(generated, undefined, 2)) !== null && _b !== void 0 ? _b : '',
1229
+ },
1230
+ ]
1231
+ : [{ label: 'default', data: '' }];
1232
+ }
1233
+ catch (e) {
1234
+ console.error(e);
1235
+ return [{ label: '', data: `Example cannot be created for this schema\n${e}` }];
1236
+ }
1237
+ };
1238
+ const exceedsSize = (example, size = 500) => {
1239
+ return example.split(/\r\n|\r|\n/).length > size;
1230
1240
  };
1231
1241
 
1232
1242
  const useTextRequestBodyState = (mediaTypeContent) => {
@@ -1747,6 +1757,12 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
1747
1757
  response && 'error' in response && React.createElement(ResponseError, { state: response })));
1748
1758
  };
1749
1759
 
1760
+ const LoadMore = ({ loading, onClick }) => {
1761
+ return (React.createElement(Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
1762
+ React.createElement(Button, { "aria-label": "load-example", onPress: onClick, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
1763
+ React.createElement(Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default.")));
1764
+ };
1765
+
1750
1766
  const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode }) => {
1751
1767
  var _a;
1752
1768
  const [chosenExampleIndex, setChosenExampleIndex] = React__default.useState(0);
@@ -1761,7 +1777,10 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
1761
1777
  const responseExample = useGenerateExampleFromMediaTypeContent(responseContents, chosenExampleIndex, {
1762
1778
  skipWriteOnly: true,
1763
1779
  });
1764
- const exceededSize = responseExample.split(/\r\n|\r|\n/).length > 500;
1780
+ const handleLoadMore = () => {
1781
+ setLoading(true);
1782
+ setTimeout(() => setShow(true), 50);
1783
+ };
1765
1784
  if (!userDefinedExamples && responseMediaType !== 'application/json')
1766
1785
  return null;
1767
1786
  if (!responseExample)
@@ -1769,12 +1788,7 @@ const ResponseExamples = ({ httpOperation, responseMediaType, responseStatusCode
1769
1788
  const examplesSelect = userDefinedExamples && userDefinedExamples.length > 1 && (React__default.createElement(Select, { "aria-label": "Response Example", value: String(chosenExampleIndex), options: userDefinedExamples.map((example, index) => ({ value: index, label: example.key })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Response Example: " }));
1770
1789
  return (React__default.createElement(Panel, { rounded: true, isCollapsible: false },
1771
1790
  React__default.createElement(Panel.Titlebar, null, examplesSelect || React__default.createElement(Text, { color: "body" }, "Response Example")),
1772
- React__default.createElement(Panel.Content, { p: 0 }, (exceededSize && show) || !exceededSize ? (React__default.createElement(CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default.createElement(Flex, { flexDirection: "col", justifyContent: "center", alignItems: "center", style: { height: '400px' } },
1773
- React__default.createElement(Button, { "aria-label": "load-example", onPress: () => {
1774
- setLoading(true);
1775
- setTimeout(() => setShow(true), 50);
1776
- }, appearance: "minimal", loading: loading, disabled: loading }, loading ? 'Loading...' : 'Load examples'),
1777
- React__default.createElement(Text, { fontSize: "base", textAlign: "center" }, "Large examples are not rendered by default."))))));
1791
+ React__default.createElement(Panel.Content, { p: 0 }, show || !exceedsSize(responseExample) ? (React__default.createElement(CodeViewer, { "aria-label": responseExample, noCopyButton: true, maxHeight: "400px", language: "json", value: responseExample, showLineNumbers: true })) : (React__default.createElement(LoadMore, { loading: loading, onClick: handleLoadMore })))));
1778
1792
  };
1779
1793
 
1780
1794
  const TryItWithRequestSamples = (_a) => {
@@ -2158,10 +2172,16 @@ const HttpService = withErrorBoundary(HttpServiceComponent, { recoverableProps:
2158
2172
  const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
2159
2173
  var _a;
2160
2174
  const [chosenExampleIndex, setChosenExampleIndex] = React.useState(0);
2175
+ const [show, setShow] = React.useState(false);
2176
+ const [loading, setLoading] = React.useState(false);
2161
2177
  const resolveRef = useInlineRefResolver();
2162
2178
  const data = useResolvedObject(unresolvedData);
2163
2179
  const title = (_a = data.title) !== null && _a !== void 0 ? _a : nodeTitle;
2164
2180
  const isInternal = !!data['x-internal'];
2181
+ const handleLoadMorePress = () => {
2182
+ setLoading(true);
2183
+ setTimeout(() => setShow(true), 50);
2184
+ };
2165
2185
  const examples = React.useMemo(() => generateExamplesFromJsonSchema(data), [data]);
2166
2186
  const shouldDisplayHeader = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && (title !== undefined || (exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport)));
2167
2187
  const header = (shouldDisplayHeader || isInternal) && (React.createElement(React.Fragment, null,
@@ -2176,8 +2196,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
2176
2196
  const examplesSelect = examples.length > 1 && (React.createElement(Select, { "aria-label": "Example", value: String(chosenExampleIndex), options: examples.map(({ label }, index) => ({ value: index, label })), onChange: (value) => setChosenExampleIndex(parseInt(String(value), 10)), size: "sm", triggerTextPrefix: "Example: " }));
2177
2197
  const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && (React.createElement(Panel, { rounded: true, isCollapsible: false },
2178
2198
  React.createElement(Panel.Titlebar, null, examplesSelect || (React.createElement(Text, { color: "body", role: "heading" }, "Example"))),
2179
- React.createElement(Panel.Content, { p: 0 },
2180
- React.createElement(CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true }))));
2199
+ React.createElement(Panel.Content, { p: 0 }, show || !exceedsSize(examples[chosenExampleIndex].data) ? (React.createElement(CodeViewer, { "aria-label": examples[chosenExampleIndex].data, noCopyButton: true, maxHeight: "500px", language: "json", value: examples[chosenExampleIndex].data, showLineNumbers: true })) : (React.createElement(LoadMore, { loading: loading, onClick: handleLoadMorePress })))));
2181
2200
  return (React.createElement(TwoColumnLayout, { className: cn('Model', className), header: header, left: description, right: modelExamples }));
2182
2201
  };
2183
2202
  const Model = withErrorBoundary(ModelComponent, { recoverableProps: ['data'] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "7.3.6",
3
+ "version": "7.3.7",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",
@@ -29,13 +29,13 @@
29
29
  "@fortawesome/react-fontawesome": "^0.1.11",
30
30
  "@stoplight/json": "^3.10.0",
31
31
  "@stoplight/json-schema-ref-parser": "^9.0.5",
32
- "@stoplight/json-schema-sampler": "0.2.1",
32
+ "@stoplight/json-schema-sampler": "0.2.2",
33
33
  "@stoplight/json-schema-viewer": "^4.3.1",
34
34
  "@stoplight/markdown": "^3.1.1",
35
35
  "@stoplight/markdown-viewer": "^5.3.2",
36
- "@stoplight/mosaic": "^1.5.0",
37
- "@stoplight/mosaic-code-editor": "^1.5.0",
38
- "@stoplight/mosaic-code-viewer": "^1.5.0",
36
+ "@stoplight/mosaic": "^1.8.2",
37
+ "@stoplight/mosaic-code-editor": "^1.8.2",
38
+ "@stoplight/mosaic-code-viewer": "^1.8.2",
39
39
  "@stoplight/path": "^1.3.2",
40
40
  "@stoplight/react-error-boundary": "^1.1.0",
41
41
  "@stoplight/types": "^12.0.0",
@@ -9,4 +9,5 @@ export declare type GenerateExampleFromMediaTypeContentOptions = Sampler.Options
9
9
  export declare const useGenerateExampleFromMediaTypeContent: (mediaTypeContent: IMediaTypeContent | undefined, chosenExampleIndex?: number | undefined, { skipReadOnly, skipWriteOnly, skipNonRequired }?: GenerateExampleFromMediaTypeContentOptions) => string;
10
10
  export declare const generateExampleFromMediaTypeContent: (mediaTypeContent: IMediaTypeContent | undefined, document: any, chosenExampleIndex?: number, options?: Sampler.Options | undefined) => string;
11
11
  export declare const generateExamplesFromJsonSchema: (schema: JSONSchema7) => Example[];
12
+ export declare const exceedsSize: (example: string, size?: number) => boolean;
12
13
  export {};