@stoplight/elements-core 7.5.8 → 7.5.12

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.mjs CHANGED
@@ -5,18 +5,15 @@ import { resolveInlineRef, isPlainObject as isPlainObject$1, safeParse, safeStri
5
5
  import isArray from 'lodash/isArray.js';
6
6
  import isObject from 'lodash/isObject.js';
7
7
  import isPlainObject from 'lodash/isPlainObject.js';
8
- import { parse } from '@stoplight/markdown';
9
8
  import { NodeType, HttpParamStyles } from '@stoplight/types';
10
- import { parse as parse$1 } from '@stoplight/yaml';
11
- import { isArray as isArray$1, Box, Flex, Icon, Button, Popover, Panel, CopyButton, Menu, Text, Input, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading, Tabs, TabList, Tab, TabPanels, TabPanel, Heading as Heading$1, useClipboard, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
9
+ import { parse } from '@stoplight/yaml';
10
+ import { isArray as isArray$1, Box, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading, Tabs, TabList, Tab, TabPanels, TabPanel, Heading, useClipboard, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
12
11
  import { withErrorBoundary } from '@stoplight/react-error-boundary';
13
12
  import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
14
13
  export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
15
- import { faStream, faCrosshairs, faCloud, faBookOpen, faCube, faDatabase, faQuestionCircle, faExclamationCircle, faServer, faExclamationTriangle, faEye, faBolt, faCopy, faCheck } from '@fortawesome/free-solid-svg-icons';
16
- import throttle from 'lodash/throttle.js';
17
- import { selectAll } from 'unist-util-select';
18
14
  import cn from 'classnames';
19
15
  import { atomWithStorage, useAtomValue } from 'jotai/utils';
16
+ import { faCrosshairs, faCloud, faBookOpen, faCube, faDatabase, faQuestionCircle, faExclamationCircle, faServer, faExclamationTriangle, faEye, faBolt, faCopy, faCheck } from '@fortawesome/free-solid-svg-icons';
20
17
  import { atom, useAtom, Provider } from 'jotai';
21
18
  import URI from 'urijs';
22
19
  import { CodeViewer } from '@stoplight/mosaic-code-viewer';
@@ -164,13 +161,7 @@ const parserMap = {
164
161
  [NodeType.Unknown]: parseUnknown,
165
162
  };
166
163
  function parseArticleData(rawData) {
167
- if (typeof rawData === 'string') {
168
- return {
169
- type: NodeType.Article,
170
- data: parse(rawData),
171
- };
172
- }
173
- if (isSMDASTRoot(rawData)) {
164
+ if (typeof rawData === 'string' || isSMDASTRoot(rawData)) {
174
165
  return {
175
166
  type: NodeType.Article,
176
167
  data: rawData,
@@ -213,7 +204,7 @@ function tryParseYamlOrObject(yamlOrObject) {
213
204
  return yamlOrObject;
214
205
  if (typeof yamlOrObject === 'string') {
215
206
  try {
216
- return parse$1(yamlOrObject);
207
+ return parse(yamlOrObject);
217
208
  }
218
209
  catch (e) { }
219
210
  }
@@ -228,94 +219,9 @@ const MarkdownViewer = (props) => {
228
219
  };
229
220
  MarkdownViewer.displayName = 'MarkdownViewer';
230
221
 
231
- function useComponentSize(container) {
232
- const [componentSize, setComponentSize] = React.useState({ width: 0, height: 0 });
233
- React.useEffect(() => {
234
- if (!container) {
235
- return;
236
- }
237
- const updateComponentSize = throttle(() => (container ? setComponentSize(container.getBoundingClientRect()) : { width: 0, height: 0 }), 1000, {
238
- trailing: true,
239
- });
240
- updateComponentSize();
241
- window.addEventListener('resize', updateComponentSize);
242
- return () => {
243
- updateComponentSize.cancel();
244
- window.removeEventListener('resize', updateComponentSize);
245
- };
246
- }, [container]);
247
- return componentSize;
248
- }
249
-
250
- function useComputeMarkdownHeadings(tree) {
251
- return React.useMemo(() => computeMarkdownHeadings(tree), [tree]);
252
- }
253
- function computeMarkdownHeadings(tree) {
254
- return selectAll(':root > [type=heading]', tree)
255
- .map((heading) => {
256
- var _a;
257
- return ({
258
- title: findTitle(heading),
259
- id: ((_a = heading.data) === null || _a === void 0 ? void 0 : _a.id) || '',
260
- depth: heading.depth - 1,
261
- });
262
- })
263
- .filter((item) => item.depth >= 1 && item.depth <= 2);
264
- }
265
- const findTitle = (parent) => {
266
- return selectAll('[type=text]', parent).map(textNode => String(textNode.value)).join(' ');
267
- };
268
-
269
- function useLocationHash() {
270
- const isBrowser = typeof window !== 'undefined';
271
- const [locationHash, setLocationHash] = React.useState(isBrowser && window.location.hash);
272
- React.useEffect(() => {
273
- if (!isBrowser)
274
- return;
275
- const hashChange = () => setLocationHash(window.location.hash);
276
- window.addEventListener('hashchange', hashChange, false);
277
- return () => window.removeEventListener('hashchange', hashChange);
278
- }, [isBrowser]);
279
- return locationHash;
280
- }
281
-
282
- const ArticleHeadings = ({ tree, container }) => {
283
- const { width } = useComponentSize(container);
284
- const showHeadings = width >= 768;
285
- const headings = useComputeMarkdownHeadings(tree);
286
- return React.createElement(Headings, { className: "ArticleHeadings", headings: headings, minimal: !showHeadings, maxWidth: 300 });
287
- };
288
- const Headings = ({ headings, className, title = 'On This Page', minimal, maxWidth }) => {
289
- const locationHash = useLocationHash();
290
- if (!headings || !headings.length)
291
- return null;
292
- const component = (React.createElement(Box, { overflowY: "auto", style: { maxHeight: '85vh', maxWidth } },
293
- title && (React.createElement(Flex, { py: 2, alignItems: "center", fontSize: "sm", fontWeight: "medium", color: "muted", style: { paddingLeft: 18 } },
294
- React.createElement(Box, { as: Icon, icon: faStream, mr: 2 }),
295
- title)),
296
- headings.map((heading, i) => (React.createElement(Heading, { key: i, item: heading, isSelected: locationHash === `#${heading.id}` })))));
297
- const button = React.createElement(Button, { pos: "sticky", size: "sm", borderColor: "light", icon: faStream, style: { top: 10 } });
298
- if (minimal) {
299
- return (React.createElement(Box, { pos: "sticky", top: 0, right: 0, style: { top: 10 } },
300
- React.createElement(Popover, { renderTrigger: button, placement: "bottom" },
301
- React.createElement(Box, { className: className }, component))));
302
- }
303
- return (React.createElement(Box, { pos: "sticky", pr: 4, pl: 16, h: "full", overflowX: "auto", overflowY: "auto", className: className, style: { top: 30 } },
304
- React.createElement(Box, { borderL: true, borderColor: "light" }, component)));
305
- };
306
- const Heading = ({ item, isSelected }) => {
307
- return (React.createElement(Box, { as: "a", href: `#${item.id}`, textOverflow: "truncate", display: "block", py: 2, pr: 8, fontWeight: "medium", fontSize: "sm", color: isSelected ? 'primary' : 'muted', style: { paddingLeft: `${3 + item.depth * 15}px` } }, item.title));
308
- };
309
-
310
222
  const ArticleComponent = React.memo(({ data }) => {
311
- const [container, setContainer] = React.useState(null);
312
- const tree = React.useMemo(() => (typeof data === 'object' ? data : parse(data)), [data]);
313
- if (tree === null)
314
- return null;
315
- return (React.createElement(Flex, { className: "sl-elements-article", justifyContent: "evenly", w: "full", pos: "relative", ref: setContainer },
316
- React.createElement(Box, { className: "sl-elements-article-content", style: { width: 0 }, flex: 1 },
317
- React.createElement(MarkdownViewer, { markdown: tree })),
318
- React.createElement(ArticleHeadings, { tree: tree, container: container })));
223
+ return (React.createElement(Box, { className: "sl-elements-article" },
224
+ React.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true })));
319
225
  });
320
226
  const Article = withErrorBoundary(ArticleComponent, { recoverableProps: ['data'] });
321
227
 
@@ -2177,7 +2083,7 @@ const HttpOperationComponent = React.memo(({ className, data: unresolvedData, la
2177
2083
  const hasBadges = isDeprecated || isInternal;
2178
2084
  const header = (!(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) || hasBadges) && (React.createElement(VStack, { spacing: 5 },
2179
2085
  React.createElement(HStack, { spacing: 5 },
2180
- !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && prettyName ? (React.createElement(Heading$1, { size: 1, fontWeight: "semibold" }, prettyName)) : null,
2086
+ !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && prettyName ? (React.createElement(Heading, { size: 1, fontWeight: "semibold" }, prettyName)) : null,
2181
2087
  React.createElement(HStack, { spacing: 2 },
2182
2088
  isDeprecated && React.createElement(DeprecatedBadge, null),
2183
2089
  isInternal && React.createElement(InternalBadge, { isHttpService: true }))),
@@ -2301,7 +2207,7 @@ const HttpServiceComponent = React.memo(({ data, location = {}, layoutOptions, e
2301
2207
  const query = new URLSearchParams(search);
2302
2208
  return (React.createElement(Box, { mb: 10 },
2303
2209
  data.name && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && (React.createElement(Flex, { justifyContent: "between", alignItems: "center" },
2304
- React.createElement(Heading$1, { size: 1, mb: 4, fontWeight: "semibold" }, data.name),
2210
+ React.createElement(Heading, { size: 1, mb: 4, fontWeight: "semibold" }, data.name),
2305
2211
  exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React.createElement(ExportButton, Object.assign({}, exportProps)))),
2306
2212
  data.version && (React.createElement(Box, { mb: 5 },
2307
2213
  React.createElement(VersionBadge, { value: data.version }))),
@@ -2332,7 +2238,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
2332
2238
  const shouldDisplayHeader = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.noHeading) && (title !== undefined || (exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport)));
2333
2239
  const header = (shouldDisplayHeader || isInternal) && (React.createElement(Flex, { justifyContent: "between", alignItems: "center" },
2334
2240
  React.createElement(HStack, { spacing: 5 },
2335
- title && (React.createElement(Heading$1, { size: 1, fontWeight: "semibold" }, title)),
2241
+ title && (React.createElement(Heading, { size: 1, fontWeight: "semibold" }, title)),
2336
2242
  React.createElement(HStack, { spacing: 2 }, isInternal && React.createElement(InternalBadge, null))),
2337
2243
  exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && React.createElement(ExportButton, Object.assign({}, exportProps))));
2338
2244
  const description = (React.createElement(VStack, { spacing: 10 },
@@ -2389,7 +2295,7 @@ const SidebarLayout = React.forwardRef(({ sidebar, children, maxContentWidth = M
2389
2295
  paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
2390
2296
  minWidth: `${sidebarWidth}px`,
2391
2297
  } }, sidebar),
2392
- React.createElement(Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, overflowY: "auto", overflowX: "hidden", w: "full" },
2298
+ React.createElement(Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, w: "full", overflowY: "auto" },
2393
2299
  React.createElement(Box, { style: { maxWidth: `${maxContentWidth - sidebarWidth}px` }, py: 16 }, children))));
2394
2300
  });
2395
2301
 
@@ -2418,7 +2324,7 @@ function useParsedValue(value) {
2418
2324
  let parsedValue = value;
2419
2325
  if (typeof value === 'string') {
2420
2326
  try {
2421
- parsedValue = parse$1(value);
2327
+ parsedValue = parse(value);
2422
2328
  }
2423
2329
  catch (error) {
2424
2330
  }
@@ -2444,8 +2350,8 @@ const SchemaAndDescription = ({ title: titleProp, schema }) => {
2444
2350
  React__default.createElement(JsonSchemaViewer, { resolveRef: resolveRef, schema: getOriginalObject(schema) })));
2445
2351
  };
2446
2352
  const CodeComponent = props => {
2447
- const { title, jsonSchema, http, children } = props;
2448
- const value = String(Array.isArray(children) ? children[0] : children);
2353
+ const { title, jsonSchema, http, resolved, children } = props;
2354
+ const value = resolved || String(Array.isArray(children) ? children[0] : children);
2449
2355
  const parsedValue = useParsedValue(value);
2450
2356
  if (jsonSchema) {
2451
2357
  if (!isJSONSchema(parsedValue)) {
@@ -2692,7 +2598,7 @@ const Version = ({ value }) => {
2692
2598
  const NonIdealState = ({ description, icon, title }) => {
2693
2599
  return (React.createElement(Flex, { flexDirection: "col", alignItems: "center", justifyContent: "center", textAlign: "center", w: "full", h: "full" },
2694
2600
  React.createElement(Box, { as: Icon, icon: icon || faExclamationTriangle, color: "light", fontSize: "6xl", mb: 4 }),
2695
- React.createElement(Heading$1, { size: 4, mb: 4 }, title),
2601
+ React.createElement(Heading, { size: 4, mb: 4 }, title),
2696
2602
  React.createElement(Text, null, description)));
2697
2603
  };
2698
2604
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "7.5.8",
3
+ "version": "7.5.12",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",
@@ -29,11 +29,10 @@
29
29
  "@stoplight/json-schema-ref-parser": "^9.0.5",
30
30
  "@stoplight/json-schema-sampler": "0.2.2",
31
31
  "@stoplight/json-schema-viewer": "^4.5.0",
32
- "@stoplight/markdown": "^3.1.1",
33
- "@stoplight/markdown-viewer": "^5.3.2",
34
- "@stoplight/mosaic": "^1.15.2",
35
- "@stoplight/mosaic-code-editor": "^1.15.2",
36
- "@stoplight/mosaic-code-viewer": "^1.15.2",
32
+ "@stoplight/markdown-viewer": "^5.4.2",
33
+ "@stoplight/mosaic": "^1.15.4",
34
+ "@stoplight/mosaic-code-editor": "^1.15.4",
35
+ "@stoplight/mosaic-code-viewer": "^1.15.4",
37
36
  "@stoplight/path": "^1.3.2",
38
37
  "@stoplight/react-error-boundary": "^2.0.0",
39
38
  "@stoplight/types": "^12.0.0",
@@ -49,7 +48,6 @@
49
48
  "react-router-dom": "^5.2.0",
50
49
  "react-router-hash-link": "^2.1.0",
51
50
  "tslib": "^2.1.0",
52
- "unist-util-select": "^3.0.1",
53
51
  "urijs": "^1.19.6",
54
52
  "util": "^0.12.4",
55
53
  "xml-formatter": "^2.4.0"