@stoplight/elements 7.14.0 → 7.15.1
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/API/APIWithStackedLayout.d.ts +1 -0
- package/containers/API.d.ts +1 -0
- package/containers/API.stories.d.ts +11 -12
- package/index.d.ts +1 -0
- package/index.esm.js +43 -43
- package/index.js +43 -42
- package/index.mjs +43 -43
- package/package.json +2 -2
- package/web-components.min.js +1 -1
|
@@ -9,6 +9,7 @@ declare type StackedLayoutProps = {
|
|
|
9
9
|
exportProps?: ExportButtonProps;
|
|
10
10
|
tryItCredentialsPolicy?: TryItCredentialsPolicy;
|
|
11
11
|
tryItCorsProxy?: string;
|
|
12
|
+
showPoweredByLink?: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare const APIWithStackedLayout: React.FC<StackedLayoutProps>;
|
|
14
15
|
export {};
|
package/containers/API.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface CommonAPIProps extends RoutingProps {
|
|
|
17
17
|
hideExport?: boolean;
|
|
18
18
|
tryItCredentialsPolicy?: 'omit' | 'include' | 'same-origin';
|
|
19
19
|
tryItCorsProxy?: string;
|
|
20
|
+
maxRefDepth?: number;
|
|
20
21
|
}
|
|
21
22
|
export declare const APIImpl: React.FC<APIProps>;
|
|
22
23
|
export declare const API: React.FC<APIProps>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Story } from '@storybook/react';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { APIProps } from './API';
|
|
4
3
|
declare const _default: {
|
|
@@ -44,14 +43,14 @@ declare const _default: {
|
|
|
44
43
|
};
|
|
45
44
|
};
|
|
46
45
|
export default _default;
|
|
47
|
-
export declare const APIWithYamlProvidedDirectly:
|
|
48
|
-
export declare const APIWithJSONProvidedDirectly:
|
|
49
|
-
export declare const APIWithoutDescription:
|
|
50
|
-
export declare const APIWithInternalOperations:
|
|
51
|
-
export declare const OpenApi3Schema:
|
|
52
|
-
export declare const BadgesForSchema:
|
|
53
|
-
export declare const StackedLayout:
|
|
54
|
-
export declare const Box:
|
|
55
|
-
export declare const DigitalOcean:
|
|
56
|
-
export declare const Github:
|
|
57
|
-
export declare const Instagram:
|
|
46
|
+
export declare const APIWithYamlProvidedDirectly: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
47
|
+
export declare const APIWithJSONProvidedDirectly: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
48
|
+
export declare const APIWithoutDescription: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
49
|
+
export declare const APIWithInternalOperations: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
50
|
+
export declare const OpenApi3Schema: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
51
|
+
export declare const BadgesForSchema: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
52
|
+
export declare const StackedLayout: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
53
|
+
export declare const Box: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
54
|
+
export declare const DigitalOcean: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
55
|
+
export declare const Github: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
|
56
|
+
export declare const Instagram: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, APIProps>;
|
package/index.d.ts
CHANGED
package/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { isHttpOperation, isHttpService,
|
|
2
|
-
import {
|
|
3
|
-
import flow from 'lodash/flow.js';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { useQuery } from 'react-query';
|
|
1
|
+
import { isHttpOperation, isHttpService, HttpMethodColors, DeprecatedBadge, ParsedDocs, TryItWithRequestSamples, Docs, Logo, TableOfContents, PoweredByLink, SidebarLayout, slugify, withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider, useParsedValue, useBundleRefsIntoDocument, NonIdealState, InlineRefResolverProvider } from '@stoplight/elements-core';
|
|
2
|
+
import { Box, Flex, Icon, Tabs, TabList, Tab, TabPanels, TabPanel, Heading } from '@stoplight/mosaic';
|
|
6
3
|
import { NodeType } from '@stoplight/types';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import * as React from 'react';
|
|
7
6
|
import { useLocation, Redirect, Link } from 'react-router-dom';
|
|
8
7
|
import defaults from 'lodash/defaults.js';
|
|
9
|
-
import
|
|
8
|
+
import flow from 'lodash/flow.js';
|
|
9
|
+
import { useQuery } from 'react-query';
|
|
10
10
|
import { safeStringify } from '@stoplight/yaml';
|
|
11
11
|
import saver from 'file-saver';
|
|
12
12
|
import { transformOas2Service, transformOas2Operation } from '@stoplight/http-spec/oas2';
|
|
@@ -157,38 +157,6 @@ const isInternal = (node) => {
|
|
|
157
157
|
return !!data['x-internal'];
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
161
|
-
const container = React.useRef(null);
|
|
162
|
-
const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
|
163
|
-
const location = useLocation();
|
|
164
|
-
const { pathname } = location;
|
|
165
|
-
const isRootPath = !pathname || pathname === '/';
|
|
166
|
-
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
|
167
|
-
const layoutOptions = React.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService }), [hideTryIt, hideExport, node]);
|
|
168
|
-
if (!node) {
|
|
169
|
-
const firstSlug = findFirstNodeSlug(tree);
|
|
170
|
-
if (firstSlug) {
|
|
171
|
-
return React.createElement(Redirect, { to: firstSlug });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (hideInternal && node && isInternal(node)) {
|
|
175
|
-
return React.createElement(Redirect, { to: "/" });
|
|
176
|
-
}
|
|
177
|
-
const handleTocClick = () => {
|
|
178
|
-
if (container.current) {
|
|
179
|
-
container.current.scrollIntoView();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const sidebar = (React.createElement(React.Fragment, null,
|
|
183
|
-
React.createElement(Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
184
|
-
logo ? (React.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React.createElement(Logo, { logo: serviceNode.data.logo })),
|
|
185
|
-
React.createElement(Heading, { size: 4 }, serviceNode.name)),
|
|
186
|
-
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
187
|
-
React.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: Link, onLinkClick: handleTocClick })),
|
|
188
|
-
React.createElement(PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
|
189
|
-
return (React.createElement(SidebarLayout, { ref: container, sidebar: sidebar }, node && (React.createElement(ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
160
|
const itemMatchesHash = (hash, item) => {
|
|
193
161
|
return hash.substr(1) === `${item.name}-${item.data.method}`;
|
|
194
162
|
};
|
|
@@ -197,13 +165,13 @@ const TryItContext = React.createContext({
|
|
|
197
165
|
tryItCredentialsPolicy: 'omit',
|
|
198
166
|
});
|
|
199
167
|
TryItContext.displayName = 'TryItContext';
|
|
200
|
-
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
168
|
+
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, }) => {
|
|
201
169
|
const location = useLocation();
|
|
202
170
|
const { groups } = computeTagGroups(serviceNode);
|
|
203
171
|
return (React.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
|
|
204
172
|
React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
|
|
205
173
|
React.createElement(Box, { w: "full", borderB: true },
|
|
206
|
-
React.createElement(Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink
|
|
174
|
+
React.createElement(Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink, hideExport }, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy })),
|
|
207
175
|
groups.map(group => (React.createElement(Group, { key: group.title, group: group }))))));
|
|
208
176
|
};
|
|
209
177
|
const Group = React.memo(({ group }) => {
|
|
@@ -273,6 +241,38 @@ const Collapse = ({ isOpen, children }) => {
|
|
|
273
241
|
return React.createElement(Box, null, children);
|
|
274
242
|
};
|
|
275
243
|
|
|
244
|
+
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
245
|
+
const container = React.useRef(null);
|
|
246
|
+
const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
|
247
|
+
const location = useLocation();
|
|
248
|
+
const { pathname } = location;
|
|
249
|
+
const isRootPath = !pathname || pathname === '/';
|
|
250
|
+
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
|
251
|
+
const layoutOptions = React.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService }), [hideTryIt, hideExport, node]);
|
|
252
|
+
if (!node) {
|
|
253
|
+
const firstSlug = findFirstNodeSlug(tree);
|
|
254
|
+
if (firstSlug) {
|
|
255
|
+
return React.createElement(Redirect, { to: firstSlug });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (hideInternal && node && isInternal(node)) {
|
|
259
|
+
return React.createElement(Redirect, { to: "/" });
|
|
260
|
+
}
|
|
261
|
+
const handleTocClick = () => {
|
|
262
|
+
if (container.current) {
|
|
263
|
+
container.current.scrollIntoView();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const sidebar = (React.createElement(React.Fragment, null,
|
|
267
|
+
React.createElement(Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
268
|
+
logo ? (React.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React.createElement(Logo, { logo: serviceNode.data.logo })),
|
|
269
|
+
React.createElement(Heading, { size: 4 }, serviceNode.name)),
|
|
270
|
+
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
271
|
+
React.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: Link, onLinkClick: handleTocClick })),
|
|
272
|
+
React.createElement(PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
|
273
|
+
return (React.createElement(SidebarLayout, { ref: container, sidebar: sidebar }, node && (React.createElement(ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
274
|
+
};
|
|
275
|
+
|
|
276
276
|
var NodeTypes;
|
|
277
277
|
(function (NodeTypes) {
|
|
278
278
|
NodeTypes["Paths"] = "paths";
|
|
@@ -485,7 +485,7 @@ const propsAreWithDocument = (props) => {
|
|
|
485
485
|
return props.hasOwnProperty('apiDescriptionDocument');
|
|
486
486
|
};
|
|
487
487
|
const APIImpl = props => {
|
|
488
|
-
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, } = props;
|
|
488
|
+
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, } = props;
|
|
489
489
|
const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
|
|
490
490
|
const { data: fetchedDocument, error } = useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
|
|
491
491
|
if (res.ok) {
|
|
@@ -512,8 +512,8 @@ const APIImpl = props => {
|
|
|
512
512
|
return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
|
|
513
513
|
React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
|
|
514
514
|
}
|
|
515
|
-
return (React.createElement(InlineRefResolverProvider, { document: parsedDocument }, layout === 'stacked' ? (React.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })) : (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
515
|
+
return (React.createElement(InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth }, layout === 'stacked' ? (React.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })) : (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
516
516
|
};
|
|
517
517
|
const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
|
|
518
518
|
|
|
519
|
-
export { API, transformOasToServiceNode, useExportDocumentProps };
|
|
519
|
+
export { API, APIWithStackedLayout, transformOasToServiceNode, useExportDocumentProps };
|
package/index.js
CHANGED
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var elementsCore = require('@stoplight/elements-core');
|
|
6
6
|
var mosaic = require('@stoplight/mosaic');
|
|
7
|
-
var flow = require('lodash/flow.js');
|
|
8
|
-
var React = require('react');
|
|
9
|
-
var reactQuery = require('react-query');
|
|
10
7
|
var types = require('@stoplight/types');
|
|
8
|
+
var cn = require('classnames');
|
|
9
|
+
var React = require('react');
|
|
11
10
|
var reactRouterDom = require('react-router-dom');
|
|
12
11
|
var defaults = require('lodash/defaults.js');
|
|
13
|
-
var
|
|
12
|
+
var flow = require('lodash/flow.js');
|
|
13
|
+
var reactQuery = require('react-query');
|
|
14
14
|
var yaml = require('@stoplight/yaml');
|
|
15
15
|
var saver = require('file-saver');
|
|
16
16
|
var oas2 = require('@stoplight/http-spec/oas2');
|
|
@@ -40,10 +40,10 @@ function _interopNamespace(e) {
|
|
|
40
40
|
return Object.freeze(n);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
var
|
|
43
|
+
var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
|
|
44
44
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
45
45
|
var defaults__default = /*#__PURE__*/_interopDefaultLegacy(defaults);
|
|
46
|
-
var
|
|
46
|
+
var flow__default = /*#__PURE__*/_interopDefaultLegacy(flow);
|
|
47
47
|
var saver__default = /*#__PURE__*/_interopDefaultLegacy(saver);
|
|
48
48
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
49
49
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
@@ -190,38 +190,6 @@ const isInternal = (node) => {
|
|
|
190
190
|
return !!data['x-internal'];
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
194
|
-
const container = React__namespace.useRef(null);
|
|
195
|
-
const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
|
196
|
-
const location = reactRouterDom.useLocation();
|
|
197
|
-
const { pathname } = location;
|
|
198
|
-
const isRootPath = !pathname || pathname === '/';
|
|
199
|
-
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
|
200
|
-
const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node]);
|
|
201
|
-
if (!node) {
|
|
202
|
-
const firstSlug = findFirstNodeSlug(tree);
|
|
203
|
-
if (firstSlug) {
|
|
204
|
-
return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (hideInternal && node && isInternal(node)) {
|
|
208
|
-
return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
|
|
209
|
-
}
|
|
210
|
-
const handleTocClick = () => {
|
|
211
|
-
if (container.current) {
|
|
212
|
-
container.current.scrollIntoView();
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
const sidebar = (React__namespace.createElement(React__namespace.Fragment, null,
|
|
216
|
-
React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
217
|
-
logo ? (React__namespace.createElement(elementsCore.Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React__namespace.createElement(elementsCore.Logo, { logo: serviceNode.data.logo })),
|
|
218
|
-
React__namespace.createElement(mosaic.Heading, { size: 4 }, serviceNode.name)),
|
|
219
|
-
React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
220
|
-
React__namespace.createElement(elementsCore.TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: handleTocClick })),
|
|
221
|
-
React__namespace.createElement(elementsCore.PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
|
222
|
-
return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: sidebar }, node && (React__namespace.createElement(elementsCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
223
|
-
};
|
|
224
|
-
|
|
225
193
|
const itemMatchesHash = (hash, item) => {
|
|
226
194
|
return hash.substr(1) === `${item.name}-${item.data.method}`;
|
|
227
195
|
};
|
|
@@ -230,13 +198,13 @@ const TryItContext = React__namespace.createContext({
|
|
|
230
198
|
tryItCredentialsPolicy: 'omit',
|
|
231
199
|
});
|
|
232
200
|
TryItContext.displayName = 'TryItContext';
|
|
233
|
-
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
201
|
+
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, }) => {
|
|
234
202
|
const location = reactRouterDom.useLocation();
|
|
235
203
|
const { groups } = computeTagGroups(serviceNode);
|
|
236
204
|
return (React__namespace.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
|
|
237
205
|
React__namespace.createElement(mosaic.Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
|
|
238
206
|
React__namespace.createElement(mosaic.Box, { w: "full", borderB: true },
|
|
239
|
-
React__namespace.createElement(elementsCore.Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: types.NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink
|
|
207
|
+
React__namespace.createElement(elementsCore.Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: types.NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink, hideExport }, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy })),
|
|
240
208
|
groups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group }))))));
|
|
241
209
|
};
|
|
242
210
|
const Group = React__namespace.memo(({ group }) => {
|
|
@@ -306,6 +274,38 @@ const Collapse = ({ isOpen, children }) => {
|
|
|
306
274
|
return React__namespace.createElement(mosaic.Box, null, children);
|
|
307
275
|
};
|
|
308
276
|
|
|
277
|
+
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
278
|
+
const container = React__namespace.useRef(null);
|
|
279
|
+
const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
|
280
|
+
const location = reactRouterDom.useLocation();
|
|
281
|
+
const { pathname } = location;
|
|
282
|
+
const isRootPath = !pathname || pathname === '/';
|
|
283
|
+
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
|
284
|
+
const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node]);
|
|
285
|
+
if (!node) {
|
|
286
|
+
const firstSlug = findFirstNodeSlug(tree);
|
|
287
|
+
if (firstSlug) {
|
|
288
|
+
return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (hideInternal && node && isInternal(node)) {
|
|
292
|
+
return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
|
|
293
|
+
}
|
|
294
|
+
const handleTocClick = () => {
|
|
295
|
+
if (container.current) {
|
|
296
|
+
container.current.scrollIntoView();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const sidebar = (React__namespace.createElement(React__namespace.Fragment, null,
|
|
300
|
+
React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
301
|
+
logo ? (React__namespace.createElement(elementsCore.Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React__namespace.createElement(elementsCore.Logo, { logo: serviceNode.data.logo })),
|
|
302
|
+
React__namespace.createElement(mosaic.Heading, { size: 4 }, serviceNode.name)),
|
|
303
|
+
React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
304
|
+
React__namespace.createElement(elementsCore.TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: handleTocClick })),
|
|
305
|
+
React__namespace.createElement(elementsCore.PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
|
306
|
+
return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: sidebar }, node && (React__namespace.createElement(elementsCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
307
|
+
};
|
|
308
|
+
|
|
309
309
|
var NodeTypes;
|
|
310
310
|
(function (NodeTypes) {
|
|
311
311
|
NodeTypes["Paths"] = "paths";
|
|
@@ -518,7 +518,7 @@ const propsAreWithDocument = (props) => {
|
|
|
518
518
|
return props.hasOwnProperty('apiDescriptionDocument');
|
|
519
519
|
};
|
|
520
520
|
const APIImpl = props => {
|
|
521
|
-
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, } = props;
|
|
521
|
+
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, } = props;
|
|
522
522
|
const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
|
|
523
523
|
const { data: fetchedDocument, error } = reactQuery.useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
|
|
524
524
|
if (res.ok) {
|
|
@@ -545,10 +545,11 @@ const APIImpl = props => {
|
|
|
545
545
|
return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
|
|
546
546
|
React__namespace.createElement(elementsCore.NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
|
|
547
547
|
}
|
|
548
|
-
return (React__namespace.createElement(elementsCore.InlineRefResolverProvider, { document: parsedDocument }, layout === 'stacked' ? (React__namespace.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })) : (React__namespace.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
548
|
+
return (React__namespace.createElement(elementsCore.InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth }, layout === 'stacked' ? (React__namespace.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })) : (React__namespace.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
549
549
|
};
|
|
550
550
|
const API = flow__default["default"](elementsCore.withRouter, elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(APIImpl);
|
|
551
551
|
|
|
552
552
|
exports.API = API;
|
|
553
|
+
exports.APIWithStackedLayout = APIWithStackedLayout;
|
|
553
554
|
exports.transformOasToServiceNode = transformOasToServiceNode;
|
|
554
555
|
exports.useExportDocumentProps = useExportDocumentProps;
|
package/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { isHttpOperation, isHttpService,
|
|
2
|
-
import {
|
|
3
|
-
import flow from 'lodash/flow.js';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { useQuery } from 'react-query';
|
|
1
|
+
import { isHttpOperation, isHttpService, HttpMethodColors, DeprecatedBadge, ParsedDocs, TryItWithRequestSamples, Docs, Logo, TableOfContents, PoweredByLink, SidebarLayout, slugify, withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider, useParsedValue, useBundleRefsIntoDocument, NonIdealState, InlineRefResolverProvider } from '@stoplight/elements-core';
|
|
2
|
+
import { Box, Flex, Icon, Tabs, TabList, Tab, TabPanels, TabPanel, Heading } from '@stoplight/mosaic';
|
|
6
3
|
import { NodeType } from '@stoplight/types';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import * as React from 'react';
|
|
7
6
|
import { useLocation, Redirect, Link } from 'react-router-dom';
|
|
8
7
|
import defaults from 'lodash/defaults.js';
|
|
9
|
-
import
|
|
8
|
+
import flow from 'lodash/flow.js';
|
|
9
|
+
import { useQuery } from 'react-query';
|
|
10
10
|
import { safeStringify } from '@stoplight/yaml';
|
|
11
11
|
import saver from 'file-saver';
|
|
12
12
|
import { transformOas2Service, transformOas2Operation } from '@stoplight/http-spec/oas2';
|
|
@@ -157,38 +157,6 @@ const isInternal = (node) => {
|
|
|
157
157
|
return !!data['x-internal'];
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
161
|
-
const container = React.useRef(null);
|
|
162
|
-
const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
|
163
|
-
const location = useLocation();
|
|
164
|
-
const { pathname } = location;
|
|
165
|
-
const isRootPath = !pathname || pathname === '/';
|
|
166
|
-
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
|
167
|
-
const layoutOptions = React.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService }), [hideTryIt, hideExport, node]);
|
|
168
|
-
if (!node) {
|
|
169
|
-
const firstSlug = findFirstNodeSlug(tree);
|
|
170
|
-
if (firstSlug) {
|
|
171
|
-
return React.createElement(Redirect, { to: firstSlug });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (hideInternal && node && isInternal(node)) {
|
|
175
|
-
return React.createElement(Redirect, { to: "/" });
|
|
176
|
-
}
|
|
177
|
-
const handleTocClick = () => {
|
|
178
|
-
if (container.current) {
|
|
179
|
-
container.current.scrollIntoView();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const sidebar = (React.createElement(React.Fragment, null,
|
|
183
|
-
React.createElement(Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
184
|
-
logo ? (React.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React.createElement(Logo, { logo: serviceNode.data.logo })),
|
|
185
|
-
React.createElement(Heading, { size: 4 }, serviceNode.name)),
|
|
186
|
-
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
187
|
-
React.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: Link, onLinkClick: handleTocClick })),
|
|
188
|
-
React.createElement(PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
|
189
|
-
return (React.createElement(SidebarLayout, { ref: container, sidebar: sidebar }, node && (React.createElement(ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
160
|
const itemMatchesHash = (hash, item) => {
|
|
193
161
|
return hash.substr(1) === `${item.name}-${item.data.method}`;
|
|
194
162
|
};
|
|
@@ -197,13 +165,13 @@ const TryItContext = React.createContext({
|
|
|
197
165
|
tryItCredentialsPolicy: 'omit',
|
|
198
166
|
});
|
|
199
167
|
TryItContext.displayName = 'TryItContext';
|
|
200
|
-
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
168
|
+
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, }) => {
|
|
201
169
|
const location = useLocation();
|
|
202
170
|
const { groups } = computeTagGroups(serviceNode);
|
|
203
171
|
return (React.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
|
|
204
172
|
React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
|
|
205
173
|
React.createElement(Box, { w: "full", borderB: true },
|
|
206
|
-
React.createElement(Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink
|
|
174
|
+
React.createElement(Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink, hideExport }, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy })),
|
|
207
175
|
groups.map(group => (React.createElement(Group, { key: group.title, group: group }))))));
|
|
208
176
|
};
|
|
209
177
|
const Group = React.memo(({ group }) => {
|
|
@@ -273,6 +241,38 @@ const Collapse = ({ isOpen, children }) => {
|
|
|
273
241
|
return React.createElement(Box, null, children);
|
|
274
242
|
};
|
|
275
243
|
|
|
244
|
+
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
|
245
|
+
const container = React.useRef(null);
|
|
246
|
+
const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
|
247
|
+
const location = useLocation();
|
|
248
|
+
const { pathname } = location;
|
|
249
|
+
const isRootPath = !pathname || pathname === '/';
|
|
250
|
+
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
|
251
|
+
const layoutOptions = React.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService }), [hideTryIt, hideExport, node]);
|
|
252
|
+
if (!node) {
|
|
253
|
+
const firstSlug = findFirstNodeSlug(tree);
|
|
254
|
+
if (firstSlug) {
|
|
255
|
+
return React.createElement(Redirect, { to: firstSlug });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (hideInternal && node && isInternal(node)) {
|
|
259
|
+
return React.createElement(Redirect, { to: "/" });
|
|
260
|
+
}
|
|
261
|
+
const handleTocClick = () => {
|
|
262
|
+
if (container.current) {
|
|
263
|
+
container.current.scrollIntoView();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const sidebar = (React.createElement(React.Fragment, null,
|
|
267
|
+
React.createElement(Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
268
|
+
logo ? (React.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React.createElement(Logo, { logo: serviceNode.data.logo })),
|
|
269
|
+
React.createElement(Heading, { size: 4 }, serviceNode.name)),
|
|
270
|
+
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
271
|
+
React.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: Link, onLinkClick: handleTocClick })),
|
|
272
|
+
React.createElement(PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
|
273
|
+
return (React.createElement(SidebarLayout, { ref: container, sidebar: sidebar }, node && (React.createElement(ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
274
|
+
};
|
|
275
|
+
|
|
276
276
|
var NodeTypes;
|
|
277
277
|
(function (NodeTypes) {
|
|
278
278
|
NodeTypes["Paths"] = "paths";
|
|
@@ -485,7 +485,7 @@ const propsAreWithDocument = (props) => {
|
|
|
485
485
|
return props.hasOwnProperty('apiDescriptionDocument');
|
|
486
486
|
};
|
|
487
487
|
const APIImpl = props => {
|
|
488
|
-
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, } = props;
|
|
488
|
+
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, } = props;
|
|
489
489
|
const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
|
|
490
490
|
const { data: fetchedDocument, error } = useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
|
|
491
491
|
if (res.ok) {
|
|
@@ -512,8 +512,8 @@ const APIImpl = props => {
|
|
|
512
512
|
return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
|
|
513
513
|
React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
|
|
514
514
|
}
|
|
515
|
-
return (React.createElement(InlineRefResolverProvider, { document: parsedDocument }, layout === 'stacked' ? (React.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })) : (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
515
|
+
return (React.createElement(InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth }, layout === 'stacked' ? (React.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })) : (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
|
|
516
516
|
};
|
|
517
517
|
const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
|
|
518
518
|
|
|
519
|
-
export { API, transformOasToServiceNode, useExportDocumentProps };
|
|
519
|
+
export { API, APIWithStackedLayout, transformOasToServiceNode, useExportDocumentProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoplight/elements",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.15.1",
|
|
4
4
|
"description": "UI components for composing beautiful developer documentation.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"main": "./index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react-dom": ">=16.8"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@stoplight/elements-core": "~7.
|
|
29
|
+
"@stoplight/elements-core": "~7.15.0",
|
|
30
30
|
"@stoplight/http-spec": "^6.0.0",
|
|
31
31
|
"@stoplight/json": "^3.18.1",
|
|
32
32
|
"@stoplight/mosaic": "^1.44.4",
|