@stoplight/elements 7.6.2 → 7.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { ExportButtonProps } from '@stoplight/elements-core';
1
+ import { ExportButtonProps, RoutingProps } from '@stoplight/elements-core';
2
2
  import * as React from 'react';
3
3
  import { ServiceNode } from '../../utils/oas/types';
4
4
  declare type SidebarLayoutProps = {
@@ -11,6 +11,7 @@ declare type SidebarLayoutProps = {
11
11
  exportProps?: ExportButtonProps;
12
12
  tryItCredentialsPolicy?: 'omit' | 'include' | 'same-origin';
13
13
  tryItCorsProxy?: string;
14
+ router?: RoutingProps['router'];
14
15
  };
15
16
  export declare const APIWithSidebarLayout: React.FC<SidebarLayoutProps>;
16
17
  export {};
package/index.esm.js CHANGED
@@ -157,17 +157,21 @@ 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, }) => {
160
+ const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, router, }) => {
161
161
  const container = React.useRef(null);
162
162
  const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
163
163
  const location = useLocation();
164
164
  const { pathname } = location;
165
165
  const isRootPath = !pathname || pathname === '/';
166
- const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
166
+ let node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
167
+ const isHashRouter = router === 'hash';
167
168
  const layoutOptions = React.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService }), [hideTryIt, hideExport, node]);
168
169
  if (!node) {
169
170
  const firstSlug = findFirstNodeSlug(tree);
170
- if (firstSlug) {
171
+ if (isHashRouter) {
172
+ node = serviceNode;
173
+ }
174
+ else if (firstSlug) {
171
175
  return React.createElement(Redirect, { to: firstSlug });
172
176
  }
173
177
  }
@@ -509,7 +513,7 @@ const APIImpl = props => {
509
513
  return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
510
514
  React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
511
515
  }
512
- 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 }))));
516
+ 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, router: props.router }))));
513
517
  };
514
518
  const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
515
519
 
package/index.js CHANGED
@@ -190,17 +190,21 @@ 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, }) => {
193
+ const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, router, }) => {
194
194
  const container = React__namespace.useRef(null);
195
195
  const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
196
196
  const location = reactRouterDom.useLocation();
197
197
  const { pathname } = location;
198
198
  const isRootPath = !pathname || pathname === '/';
199
- const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
199
+ let node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
200
+ const isHashRouter = router === 'hash';
200
201
  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
202
  if (!node) {
202
203
  const firstSlug = findFirstNodeSlug(tree);
203
- if (firstSlug) {
204
+ if (isHashRouter) {
205
+ node = serviceNode;
206
+ }
207
+ else if (firstSlug) {
204
208
  return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
205
209
  }
206
210
  }
@@ -542,7 +546,7 @@ const APIImpl = props => {
542
546
  return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
543
547
  React__namespace.createElement(elementsCore.NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
544
548
  }
545
- 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 }))));
549
+ 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, router: props.router }))));
546
550
  };
547
551
  const API = flow__default["default"](elementsCore.withRouter, elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(APIImpl);
548
552
 
package/index.mjs CHANGED
@@ -157,17 +157,21 @@ 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, }) => {
160
+ const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, router, }) => {
161
161
  const container = React.useRef(null);
162
162
  const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
163
163
  const location = useLocation();
164
164
  const { pathname } = location;
165
165
  const isRootPath = !pathname || pathname === '/';
166
- const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
166
+ let node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
167
+ const isHashRouter = router === 'hash';
167
168
  const layoutOptions = React.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService }), [hideTryIt, hideExport, node]);
168
169
  if (!node) {
169
170
  const firstSlug = findFirstNodeSlug(tree);
170
- if (firstSlug) {
171
+ if (isHashRouter) {
172
+ node = serviceNode;
173
+ }
174
+ else if (firstSlug) {
171
175
  return React.createElement(Redirect, { to: firstSlug });
172
176
  }
173
177
  }
@@ -509,7 +513,7 @@ const APIImpl = props => {
509
513
  return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
510
514
  React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
511
515
  }
512
- 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 }))));
516
+ 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, router: props.router }))));
513
517
  };
514
518
  const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
515
519
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements",
3
- "version": "7.6.2",
3
+ "version": "7.6.5",
4
4
  "description": "UI components for composing beautiful developer documentation.",
5
5
  "keywords": [],
6
6
  "main": "./index.js",
@@ -26,10 +26,10 @@
26
26
  "react-dom": ">=16.8"
27
27
  },
28
28
  "dependencies": {
29
- "@stoplight/elements-core": "~7.6.2",
29
+ "@stoplight/elements-core": "~7.6.5",
30
30
  "@stoplight/http-spec": "^5.1.4",
31
31
  "@stoplight/json": "^3.18.1",
32
- "@stoplight/mosaic": "^1.24.2",
32
+ "@stoplight/mosaic": "^1.24.5",
33
33
  "@stoplight/types": "^13.0.0",
34
34
  "@stoplight/yaml": "^4.2.3",
35
35
  "classnames": "^2.2.6",