@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/components/Docs/Article/index.d.ts +2 -2
- package/components/Docs/story-helper.d.ts +1 -1
- package/components/MarkdownViewer/CustomComponents/ResolvedImage.d.ts +1 -1
- package/core.css +77 -0
- package/index.esm.js +15 -109
- package/index.js +7 -102
- package/index.mjs +15 -109
- package/package.json +5 -7
- package/styles.min.css +1 -1
- package/types.d.ts +2 -14
- package/utils/guards.d.ts +2 -2
- package/components/Docs/Article/Headings.d.ts +0 -5
- package/hooks/useComponentSize.d.ts +0 -4
- package/hooks/useComputeMarkdownHeadings.d.ts +0 -4
- package/hooks/useLocationHash.d.ts +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMarkdownViewerProps } from '@stoplight/markdown-viewer';
|
|
2
2
|
import { DocsComponentProps } from '..';
|
|
3
|
-
declare type ArticleProps = DocsComponentProps<
|
|
3
|
+
declare type ArticleProps = DocsComponentProps<IMarkdownViewerProps['markdown']>;
|
|
4
4
|
export declare const Article: import("react").FunctionComponent<ArticleProps & import("@stoplight/react-error-boundary").ErrorBoundaryProps<{}>>;
|
|
5
5
|
export {};
|
|
@@ -5,5 +5,5 @@ interface HelperReturn<P> {
|
|
|
5
5
|
createStory(name: string, input: Partial<P>): Story<P>;
|
|
6
6
|
createHoistedStory(input: Partial<P>): Story<P>;
|
|
7
7
|
}
|
|
8
|
-
export declare const createStoriesForDocsComponent: <P>(Component: React.ComponentType<P
|
|
8
|
+
export declare const createStoriesForDocsComponent: <P>(Component: React.ComponentType<P>, title?: string | undefined) => HelperReturn<P>;
|
|
9
9
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BundledBranchNode } from '../../../types';
|
|
3
|
-
export declare const createResolvedImageComponent: (branchNode: BundledBranchNode) => React.NamedExoticComponent<import("react").ImgHTMLAttributes<
|
|
3
|
+
export declare const createResolvedImageComponent: (branchNode: BundledBranchNode) => React.NamedExoticComponent<import("react").ImgHTMLAttributes<HTMLImageElement> & import("@stoplight/markdown/ast-types/hast").ImageProperties>;
|
package/core.css
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
.sl-elements {
|
|
2
|
+
font-size: 13px;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.sl-elements .svg-inline--fa {
|
|
6
|
+
display: inline-block;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* Docs */
|
|
10
|
+
|
|
11
|
+
.sl-elements .DocsSkeleton {
|
|
12
|
+
animation: 500ms linear infinite alternate skeleton-glow;
|
|
13
|
+
background: rgba(206, 217, 224, 0.2);
|
|
14
|
+
background-clip: padding-box !important;
|
|
15
|
+
border-color: rgba(206, 217, 224, 0.2) !important;
|
|
16
|
+
border-radius: 2px;
|
|
17
|
+
box-shadow: none !important;
|
|
18
|
+
color: transparent !important;
|
|
19
|
+
cursor: default;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
user-select: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sl-elements .Model {
|
|
25
|
+
--fs-code: 12px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Table of Contents */
|
|
29
|
+
|
|
30
|
+
.sl-elements .ElementsTableOfContentsItem:hover {
|
|
31
|
+
text-decoration: none;
|
|
32
|
+
color: inherit;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* TryIt */
|
|
36
|
+
|
|
37
|
+
.sl-elements .ParameterGrid {
|
|
38
|
+
display: grid;
|
|
39
|
+
grid-template-columns: fit-content(120px) 20px auto;
|
|
40
|
+
row-gap: 3px;
|
|
41
|
+
align-items: center;
|
|
42
|
+
padding-bottom: 0;
|
|
43
|
+
margin-bottom: 16px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.sl-elements .TryItPanel > :nth-child(2) {
|
|
47
|
+
/* This, along with the padding:0 margin: 16s above causes margin collapse to guarantee correct spacing around the panels & send button */
|
|
48
|
+
overflow: auto;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.sl-elements .OperationParametersContent {
|
|
52
|
+
max-height: 162px; /* 4.5 lines plus padding */
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.sl-elements .TextRequestBody {
|
|
56
|
+
max-height: 200px;
|
|
57
|
+
overflow-y: auto;
|
|
58
|
+
padding-bottom: 0;
|
|
59
|
+
margin-bottom: 16px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* HttpOperation */
|
|
63
|
+
|
|
64
|
+
.sl-elements .HttpOperation .JsonSchemaViewer .sl-markdown-viewer p {
|
|
65
|
+
font-size: 12px;
|
|
66
|
+
line-height: 1.5em;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.sl-elements .HttpOperation__Parameters .sl-markdown-viewer p {
|
|
70
|
+
font-size: 12px;
|
|
71
|
+
line-height: 1.5em;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.sl-elements .Model .JsonSchemaViewer .sl-markdown-viewer p {
|
|
75
|
+
font-size: 12px;
|
|
76
|
+
line-height: 1.5em;
|
|
77
|
+
}
|
package/index.esm.js
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
|
|
11
|
-
import { isArray as isArray$1, Box,
|
|
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
|
|
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
|
-
|
|
312
|
-
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
2601
|
+
React.createElement(Heading, { size: 4, mb: 4 }, title),
|
|
2696
2602
|
React.createElement(Text, null, description)));
|
|
2697
2603
|
};
|
|
2698
2604
|
|
package/index.js
CHANGED
|
@@ -8,17 +8,14 @@ var json = require('@stoplight/json');
|
|
|
8
8
|
var isArray = require('lodash/isArray.js');
|
|
9
9
|
var isObject = require('lodash/isObject.js');
|
|
10
10
|
var isPlainObject = require('lodash/isPlainObject.js');
|
|
11
|
-
var markdown = require('@stoplight/markdown');
|
|
12
11
|
var types = require('@stoplight/types');
|
|
13
12
|
var yaml = require('@stoplight/yaml');
|
|
14
13
|
var mosaic = require('@stoplight/mosaic');
|
|
15
14
|
var reactErrorBoundary = require('@stoplight/react-error-boundary');
|
|
16
15
|
var markdownViewer = require('@stoplight/markdown-viewer');
|
|
17
|
-
var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
|
|
18
|
-
var throttle = require('lodash/throttle.js');
|
|
19
|
-
var unistUtilSelect = require('unist-util-select');
|
|
20
16
|
var cn = require('classnames');
|
|
21
17
|
var utils = require('jotai/utils');
|
|
18
|
+
var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
|
|
22
19
|
var jotai = require('jotai');
|
|
23
20
|
var URI = require('urijs');
|
|
24
21
|
var mosaicCodeViewer = require('@stoplight/mosaic-code-viewer');
|
|
@@ -78,7 +75,6 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
78
75
|
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
|
|
79
76
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
80
77
|
var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
|
|
81
|
-
var throttle__default = /*#__PURE__*/_interopDefaultLegacy(throttle);
|
|
82
78
|
var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
|
|
83
79
|
var URI__default = /*#__PURE__*/_interopDefaultLegacy(URI);
|
|
84
80
|
var HTTPSnippet__default = /*#__PURE__*/_interopDefaultLegacy(HTTPSnippet);
|
|
@@ -219,13 +215,7 @@ const parserMap = {
|
|
|
219
215
|
[types.NodeType.Unknown]: parseUnknown,
|
|
220
216
|
};
|
|
221
217
|
function parseArticleData(rawData) {
|
|
222
|
-
if (typeof rawData === 'string') {
|
|
223
|
-
return {
|
|
224
|
-
type: types.NodeType.Article,
|
|
225
|
-
data: markdown.parse(rawData),
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
if (isSMDASTRoot(rawData)) {
|
|
218
|
+
if (typeof rawData === 'string' || isSMDASTRoot(rawData)) {
|
|
229
219
|
return {
|
|
230
220
|
type: types.NodeType.Article,
|
|
231
221
|
data: rawData,
|
|
@@ -283,94 +273,9 @@ const MarkdownViewer = (props) => {
|
|
|
283
273
|
};
|
|
284
274
|
MarkdownViewer.displayName = 'MarkdownViewer';
|
|
285
275
|
|
|
286
|
-
function useComponentSize(container) {
|
|
287
|
-
const [componentSize, setComponentSize] = React__namespace.useState({ width: 0, height: 0 });
|
|
288
|
-
React__namespace.useEffect(() => {
|
|
289
|
-
if (!container) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const updateComponentSize = throttle__default["default"](() => (container ? setComponentSize(container.getBoundingClientRect()) : { width: 0, height: 0 }), 1000, {
|
|
293
|
-
trailing: true,
|
|
294
|
-
});
|
|
295
|
-
updateComponentSize();
|
|
296
|
-
window.addEventListener('resize', updateComponentSize);
|
|
297
|
-
return () => {
|
|
298
|
-
updateComponentSize.cancel();
|
|
299
|
-
window.removeEventListener('resize', updateComponentSize);
|
|
300
|
-
};
|
|
301
|
-
}, [container]);
|
|
302
|
-
return componentSize;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function useComputeMarkdownHeadings(tree) {
|
|
306
|
-
return React__namespace.useMemo(() => computeMarkdownHeadings(tree), [tree]);
|
|
307
|
-
}
|
|
308
|
-
function computeMarkdownHeadings(tree) {
|
|
309
|
-
return unistUtilSelect.selectAll(':root > [type=heading]', tree)
|
|
310
|
-
.map((heading) => {
|
|
311
|
-
var _a;
|
|
312
|
-
return ({
|
|
313
|
-
title: findTitle(heading),
|
|
314
|
-
id: ((_a = heading.data) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
315
|
-
depth: heading.depth - 1,
|
|
316
|
-
});
|
|
317
|
-
})
|
|
318
|
-
.filter((item) => item.depth >= 1 && item.depth <= 2);
|
|
319
|
-
}
|
|
320
|
-
const findTitle = (parent) => {
|
|
321
|
-
return unistUtilSelect.selectAll('[type=text]', parent).map(textNode => String(textNode.value)).join(' ');
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
function useLocationHash() {
|
|
325
|
-
const isBrowser = typeof window !== 'undefined';
|
|
326
|
-
const [locationHash, setLocationHash] = React__namespace.useState(isBrowser && window.location.hash);
|
|
327
|
-
React__namespace.useEffect(() => {
|
|
328
|
-
if (!isBrowser)
|
|
329
|
-
return;
|
|
330
|
-
const hashChange = () => setLocationHash(window.location.hash);
|
|
331
|
-
window.addEventListener('hashchange', hashChange, false);
|
|
332
|
-
return () => window.removeEventListener('hashchange', hashChange);
|
|
333
|
-
}, [isBrowser]);
|
|
334
|
-
return locationHash;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const ArticleHeadings = ({ tree, container }) => {
|
|
338
|
-
const { width } = useComponentSize(container);
|
|
339
|
-
const showHeadings = width >= 768;
|
|
340
|
-
const headings = useComputeMarkdownHeadings(tree);
|
|
341
|
-
return React__namespace.createElement(Headings, { className: "ArticleHeadings", headings: headings, minimal: !showHeadings, maxWidth: 300 });
|
|
342
|
-
};
|
|
343
|
-
const Headings = ({ headings, className, title = 'On This Page', minimal, maxWidth }) => {
|
|
344
|
-
const locationHash = useLocationHash();
|
|
345
|
-
if (!headings || !headings.length)
|
|
346
|
-
return null;
|
|
347
|
-
const component = (React__namespace.createElement(mosaic.Box, { overflowY: "auto", style: { maxHeight: '85vh', maxWidth } },
|
|
348
|
-
title && (React__namespace.createElement(mosaic.Flex, { py: 2, alignItems: "center", fontSize: "sm", fontWeight: "medium", color: "muted", style: { paddingLeft: 18 } },
|
|
349
|
-
React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, icon: freeSolidSvgIcons.faStream, mr: 2 }),
|
|
350
|
-
title)),
|
|
351
|
-
headings.map((heading, i) => (React__namespace.createElement(Heading, { key: i, item: heading, isSelected: locationHash === `#${heading.id}` })))));
|
|
352
|
-
const button = React__namespace.createElement(mosaic.Button, { pos: "sticky", size: "sm", borderColor: "light", icon: freeSolidSvgIcons.faStream, style: { top: 10 } });
|
|
353
|
-
if (minimal) {
|
|
354
|
-
return (React__namespace.createElement(mosaic.Box, { pos: "sticky", top: 0, right: 0, style: { top: 10 } },
|
|
355
|
-
React__namespace.createElement(mosaic.Popover, { renderTrigger: button, placement: "bottom" },
|
|
356
|
-
React__namespace.createElement(mosaic.Box, { className: className }, component))));
|
|
357
|
-
}
|
|
358
|
-
return (React__namespace.createElement(mosaic.Box, { pos: "sticky", pr: 4, pl: 16, h: "full", overflowX: "auto", overflowY: "auto", className: className, style: { top: 30 } },
|
|
359
|
-
React__namespace.createElement(mosaic.Box, { borderL: true, borderColor: "light" }, component)));
|
|
360
|
-
};
|
|
361
|
-
const Heading = ({ item, isSelected }) => {
|
|
362
|
-
return (React__namespace.createElement(mosaic.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));
|
|
363
|
-
};
|
|
364
|
-
|
|
365
276
|
const ArticleComponent = React__namespace.memo(({ data }) => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (tree === null)
|
|
369
|
-
return null;
|
|
370
|
-
return (React__namespace.createElement(mosaic.Flex, { className: "sl-elements-article", justifyContent: "evenly", w: "full", pos: "relative", ref: setContainer },
|
|
371
|
-
React__namespace.createElement(mosaic.Box, { className: "sl-elements-article-content", style: { width: 0 }, flex: 1 },
|
|
372
|
-
React__namespace.createElement(MarkdownViewer, { markdown: tree })),
|
|
373
|
-
React__namespace.createElement(ArticleHeadings, { tree: tree, container: container })));
|
|
277
|
+
return (React__namespace.createElement(mosaic.Box, { className: "sl-elements-article" },
|
|
278
|
+
React__namespace.createElement(MarkdownViewer, { className: "sl-elements-article-content", markdown: data, includeToc: true })));
|
|
374
279
|
});
|
|
375
280
|
const Article = reactErrorBoundary.withErrorBoundary(ArticleComponent, { recoverableProps: ['data'] });
|
|
376
281
|
|
|
@@ -2444,7 +2349,7 @@ const SidebarLayout = React__namespace.forwardRef(({ sidebar, children, maxConte
|
|
|
2444
2349
|
paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
|
|
2445
2350
|
minWidth: `${sidebarWidth}px`,
|
|
2446
2351
|
} }, sidebar),
|
|
2447
|
-
React__namespace.createElement(mosaic.Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1,
|
|
2352
|
+
React__namespace.createElement(mosaic.Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, w: "full", overflowY: "auto" },
|
|
2448
2353
|
React__namespace.createElement(mosaic.Box, { style: { maxWidth: `${maxContentWidth - sidebarWidth}px` }, py: 16 }, children))));
|
|
2449
2354
|
});
|
|
2450
2355
|
|
|
@@ -2499,8 +2404,8 @@ const SchemaAndDescription = ({ title: titleProp, schema }) => {
|
|
|
2499
2404
|
React__default["default"].createElement(jsonSchemaViewer.JsonSchemaViewer, { resolveRef: resolveRef, schema: getOriginalObject(schema) })));
|
|
2500
2405
|
};
|
|
2501
2406
|
const CodeComponent = props => {
|
|
2502
|
-
const { title, jsonSchema, http, children } = props;
|
|
2503
|
-
const value = String(Array.isArray(children) ? children[0] : children);
|
|
2407
|
+
const { title, jsonSchema, http, resolved, children } = props;
|
|
2408
|
+
const value = resolved || String(Array.isArray(children) ? children[0] : children);
|
|
2504
2409
|
const parsedValue = useParsedValue(value);
|
|
2505
2410
|
if (jsonSchema) {
|
|
2506
2411
|
if (!isJSONSchema(parsedValue)) {
|