@stoplight/elements 7.15.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/index.d.ts +1 -0
- package/index.esm.js +41 -41
- package/index.js +41 -40
- package/index.mjs +41 -41
- package/package.json +1 -1
- 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/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";
|
|
@@ -516,4 +516,4 @@ const APIImpl = props => {
|
|
|
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";
|
|
@@ -550,5 +550,6 @@ const APIImpl = props => {
|
|
|
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";
|
|
@@ -516,4 +516,4 @@ const APIImpl = props => {
|
|
|
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 };
|