@stoplight/elements 7.15.1 → 7.15.3

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.
@@ -2,6 +2,13 @@ import { ExportButtonProps } from '@stoplight/elements-core';
2
2
  import * as React from 'react';
3
3
  import { ServiceNode } from '../../utils/oas/types';
4
4
  declare type TryItCredentialsPolicy = 'omit' | 'include' | 'same-origin';
5
+ interface Location {
6
+ pathname: string;
7
+ search: string;
8
+ hash: string;
9
+ state: unknown;
10
+ key: string;
11
+ }
5
12
  declare type StackedLayoutProps = {
6
13
  serviceNode: ServiceNode;
7
14
  hideTryIt?: boolean;
@@ -10,6 +17,7 @@ declare type StackedLayoutProps = {
10
17
  tryItCredentialsPolicy?: TryItCredentialsPolicy;
11
18
  tryItCorsProxy?: string;
12
19
  showPoweredByLink?: boolean;
20
+ location: Location;
13
21
  };
14
22
  export declare const APIWithStackedLayout: React.FC<StackedLayoutProps>;
15
23
  export {};
package/index.esm.js CHANGED
@@ -3,10 +3,10 @@ import { Box, Flex, Icon, Tabs, TabList, Tab, TabPanels, TabPanel, Heading } fro
3
3
  import { NodeType } from '@stoplight/types';
4
4
  import cn from 'classnames';
5
5
  import * as React from 'react';
6
- import { useLocation, Redirect, Link } from 'react-router-dom';
7
6
  import defaults from 'lodash/defaults.js';
8
7
  import flow from 'lodash/flow.js';
9
8
  import { useQuery } from 'react-query';
9
+ import { useLocation, Redirect, Link } from 'react-router-dom';
10
10
  import { safeStringify } from '@stoplight/yaml';
11
11
  import saver from 'file-saver';
12
12
  import { transformOas2Service, transformOas2Operation } from '@stoplight/http-spec/oas2';
@@ -158,26 +158,36 @@ const isInternal = (node) => {
158
158
  };
159
159
 
160
160
  const itemMatchesHash = (hash, item) => {
161
- return hash.substr(1) === `${item.name}-${item.data.method}`;
161
+ return hash.substr(1) === `${item.data.path}-${item.data.method}`;
162
162
  };
163
163
  const TryItContext = React.createContext({
164
164
  hideTryIt: false,
165
165
  tryItCredentialsPolicy: 'omit',
166
166
  });
167
167
  TryItContext.displayName = 'TryItContext';
168
- const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, }) => {
169
- const location = useLocation();
168
+ const LocationContext = React.createContext({
169
+ location: {
170
+ hash: '',
171
+ key: '',
172
+ pathname: '',
173
+ search: '',
174
+ state: '',
175
+ },
176
+ });
177
+ LocationContext.displayName = 'LocationContext';
178
+ const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, location, }) => {
170
179
  const { groups } = computeTagGroups(serviceNode);
171
- return (React.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
172
- React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
173
- React.createElement(Box, { w: "full", borderB: true },
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 })),
175
- groups.map(group => (React.createElement(Group, { key: group.title, group: group }))))));
180
+ return (React.createElement(LocationContext.Provider, { value: { location } },
181
+ React.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
182
+ React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
183
+ React.createElement(Box, { w: "full", borderB: true },
184
+ 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 })),
185
+ groups.map(group => (React.createElement(Group, { key: group.title, group: group })))))));
176
186
  };
177
187
  const Group = React.memo(({ group }) => {
178
188
  const [isExpanded, setIsExpanded] = React.useState(false);
179
- const { hash } = useLocation();
180
189
  const scrollRef = React.useRef(null);
190
+ const { location: { hash }, } = React.useContext(LocationContext);
181
191
  const urlHashMatches = hash.substr(1) === group.title;
182
192
  const onClick = React.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
183
193
  const shouldExpand = React.useMemo(() => {
@@ -201,7 +211,7 @@ const Group = React.memo(({ group }) => {
201
211
  }))));
202
212
  });
203
213
  const Item = React.memo(({ item }) => {
204
- const location = useLocation();
214
+ const { location } = React.useContext(LocationContext);
205
215
  const { hash } = location;
206
216
  const [isExpanded, setIsExpanded] = React.useState(false);
207
217
  const scrollRef = React.useRef(null);
@@ -486,6 +496,7 @@ const propsAreWithDocument = (props) => {
486
496
  };
487
497
  const APIImpl = props => {
488
498
  const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, } = props;
499
+ const location = useLocation();
489
500
  const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
490
501
  const { data: fetchedDocument, error } = useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
491
502
  if (res.ok) {
@@ -512,7 +523,7 @@ const APIImpl = props => {
512
523
  return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
513
524
  React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
514
525
  }
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 }))));
526
+ 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, location: location })) : (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
516
527
  };
517
528
  const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
518
529
 
package/index.js CHANGED
@@ -7,10 +7,10 @@ var mosaic = require('@stoplight/mosaic');
7
7
  var types = require('@stoplight/types');
8
8
  var cn = require('classnames');
9
9
  var React = require('react');
10
- var reactRouterDom = require('react-router-dom');
11
10
  var defaults = require('lodash/defaults.js');
12
11
  var flow = require('lodash/flow.js');
13
12
  var reactQuery = require('react-query');
13
+ var reactRouterDom = require('react-router-dom');
14
14
  var yaml = require('@stoplight/yaml');
15
15
  var saver = require('file-saver');
16
16
  var oas2 = require('@stoplight/http-spec/oas2');
@@ -191,26 +191,36 @@ const isInternal = (node) => {
191
191
  };
192
192
 
193
193
  const itemMatchesHash = (hash, item) => {
194
- return hash.substr(1) === `${item.name}-${item.data.method}`;
194
+ return hash.substr(1) === `${item.data.path}-${item.data.method}`;
195
195
  };
196
196
  const TryItContext = React__namespace.createContext({
197
197
  hideTryIt: false,
198
198
  tryItCredentialsPolicy: 'omit',
199
199
  });
200
200
  TryItContext.displayName = 'TryItContext';
201
- const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, }) => {
202
- const location = reactRouterDom.useLocation();
201
+ const LocationContext = React__namespace.createContext({
202
+ location: {
203
+ hash: '',
204
+ key: '',
205
+ pathname: '',
206
+ search: '',
207
+ state: '',
208
+ },
209
+ });
210
+ LocationContext.displayName = 'LocationContext';
211
+ const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, location, }) => {
203
212
  const { groups } = computeTagGroups(serviceNode);
204
- return (React__namespace.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
205
- React__namespace.createElement(mosaic.Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
206
- React__namespace.createElement(mosaic.Box, { w: "full", borderB: true },
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 })),
208
- groups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group }))))));
213
+ return (React__namespace.createElement(LocationContext.Provider, { value: { location } },
214
+ React__namespace.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
215
+ React__namespace.createElement(mosaic.Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
216
+ React__namespace.createElement(mosaic.Box, { w: "full", borderB: true },
217
+ 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 })),
218
+ groups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group })))))));
209
219
  };
210
220
  const Group = React__namespace.memo(({ group }) => {
211
221
  const [isExpanded, setIsExpanded] = React__namespace.useState(false);
212
- const { hash } = reactRouterDom.useLocation();
213
222
  const scrollRef = React__namespace.useRef(null);
223
+ const { location: { hash }, } = React__namespace.useContext(LocationContext);
214
224
  const urlHashMatches = hash.substr(1) === group.title;
215
225
  const onClick = React__namespace.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
216
226
  const shouldExpand = React__namespace.useMemo(() => {
@@ -234,7 +244,7 @@ const Group = React__namespace.memo(({ group }) => {
234
244
  }))));
235
245
  });
236
246
  const Item = React__namespace.memo(({ item }) => {
237
- const location = reactRouterDom.useLocation();
247
+ const { location } = React__namespace.useContext(LocationContext);
238
248
  const { hash } = location;
239
249
  const [isExpanded, setIsExpanded] = React__namespace.useState(false);
240
250
  const scrollRef = React__namespace.useRef(null);
@@ -519,6 +529,7 @@ const propsAreWithDocument = (props) => {
519
529
  };
520
530
  const APIImpl = props => {
521
531
  const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, } = props;
532
+ const location = reactRouterDom.useLocation();
522
533
  const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
523
534
  const { data: fetchedDocument, error } = reactQuery.useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
524
535
  if (res.ok) {
@@ -545,7 +556,7 @@ const APIImpl = props => {
545
556
  return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
546
557
  React__namespace.createElement(elementsCore.NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
547
558
  }
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 }))));
559
+ 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, location: location })) : (React__namespace.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
549
560
  };
550
561
  const API = flow__default["default"](elementsCore.withRouter, elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(APIImpl);
551
562
 
package/index.mjs CHANGED
@@ -3,10 +3,10 @@ import { Box, Flex, Icon, Tabs, TabList, Tab, TabPanels, TabPanel, Heading } fro
3
3
  import { NodeType } from '@stoplight/types';
4
4
  import cn from 'classnames';
5
5
  import * as React from 'react';
6
- import { useLocation, Redirect, Link } from 'react-router-dom';
7
6
  import defaults from 'lodash/defaults.js';
8
7
  import flow from 'lodash/flow.js';
9
8
  import { useQuery } from 'react-query';
9
+ import { useLocation, Redirect, Link } from 'react-router-dom';
10
10
  import { safeStringify } from '@stoplight/yaml';
11
11
  import saver from 'file-saver';
12
12
  import { transformOas2Service, transformOas2Operation } from '@stoplight/http-spec/oas2';
@@ -158,26 +158,36 @@ const isInternal = (node) => {
158
158
  };
159
159
 
160
160
  const itemMatchesHash = (hash, item) => {
161
- return hash.substr(1) === `${item.name}-${item.data.method}`;
161
+ return hash.substr(1) === `${item.data.path}-${item.data.method}`;
162
162
  };
163
163
  const TryItContext = React.createContext({
164
164
  hideTryIt: false,
165
165
  tryItCredentialsPolicy: 'omit',
166
166
  });
167
167
  TryItContext.displayName = 'TryItContext';
168
- const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, }) => {
169
- const location = useLocation();
168
+ const LocationContext = React.createContext({
169
+ location: {
170
+ hash: '',
171
+ key: '',
172
+ pathname: '',
173
+ search: '',
174
+ state: '',
175
+ },
176
+ });
177
+ LocationContext.displayName = 'LocationContext';
178
+ const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, showPoweredByLink = true, location, }) => {
170
179
  const { groups } = computeTagGroups(serviceNode);
171
- return (React.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
172
- React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
173
- React.createElement(Box, { w: "full", borderB: true },
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 })),
175
- groups.map(group => (React.createElement(Group, { key: group.title, group: group }))))));
180
+ return (React.createElement(LocationContext.Provider, { value: { location } },
181
+ React.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
182
+ React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
183
+ React.createElement(Box, { w: "full", borderB: true },
184
+ 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 })),
185
+ groups.map(group => (React.createElement(Group, { key: group.title, group: group })))))));
176
186
  };
177
187
  const Group = React.memo(({ group }) => {
178
188
  const [isExpanded, setIsExpanded] = React.useState(false);
179
- const { hash } = useLocation();
180
189
  const scrollRef = React.useRef(null);
190
+ const { location: { hash }, } = React.useContext(LocationContext);
181
191
  const urlHashMatches = hash.substr(1) === group.title;
182
192
  const onClick = React.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
183
193
  const shouldExpand = React.useMemo(() => {
@@ -201,7 +211,7 @@ const Group = React.memo(({ group }) => {
201
211
  }))));
202
212
  });
203
213
  const Item = React.memo(({ item }) => {
204
- const location = useLocation();
214
+ const { location } = React.useContext(LocationContext);
205
215
  const { hash } = location;
206
216
  const [isExpanded, setIsExpanded] = React.useState(false);
207
217
  const scrollRef = React.useRef(null);
@@ -486,6 +496,7 @@ const propsAreWithDocument = (props) => {
486
496
  };
487
497
  const APIImpl = props => {
488
498
  const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, } = props;
499
+ const location = useLocation();
489
500
  const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
490
501
  const { data: fetchedDocument, error } = useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
491
502
  if (res.ok) {
@@ -512,7 +523,7 @@ const APIImpl = props => {
512
523
  return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
513
524
  React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
514
525
  }
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 }))));
526
+ 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, location: location })) : (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }))));
516
527
  };
517
528
  const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
518
529
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements",
3
- "version": "7.15.1",
3
+ "version": "7.15.3",
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.15.0",
29
+ "@stoplight/elements-core": "~7.15.1",
30
30
  "@stoplight/http-spec": "^6.0.0",
31
31
  "@stoplight/json": "^3.18.1",
32
- "@stoplight/mosaic": "^1.44.4",
32
+ "@stoplight/mosaic": "^1.46.1",
33
33
  "@stoplight/types": "^14.0.0",
34
34
  "@stoplight/yaml": "^4.2.3",
35
35
  "classnames": "^2.2.6",