@stoplight/elements-dev-portal 2.3.3 → 2.4.0

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/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var mosaic = require('@stoplight/mosaic');
6
4
  var React = require('react');
7
5
  var elementsCore = require('@stoplight/elements-core');
@@ -11,60 +9,55 @@ var flow = require('lodash/flow.js');
11
9
  var reactRouterDom = require('react-router-dom');
12
10
  var reactQuery = require('react-query');
13
11
 
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
-
16
- function _interopNamespace(e) {
17
- if (e && e.__esModule) return e;
18
- var n = Object.create(null);
19
- if (e) {
20
- Object.keys(e).forEach(function (k) {
21
- if (k !== 'default') {
22
- var d = Object.getOwnPropertyDescriptor(e, k);
23
- Object.defineProperty(n, k, d.get ? d : {
24
- enumerable: true,
25
- get: function () { return e[k]; }
12
+ function _interopNamespaceDefault(e) {
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
26
23
  });
27
- }
28
- });
29
- }
30
- n["default"] = e;
31
- return Object.freeze(n);
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
32
27
  }
33
28
 
34
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
35
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
36
- var flow__default = /*#__PURE__*/_interopDefaultLegacy(flow);
29
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
37
30
 
38
- const BranchSelector = ({ branchSlug, branches, onChange }) => {
39
- const currentBranch = branches.find(branch => (!branchSlug ? branch.is_default : branch.slug === branchSlug));
40
- const handleChange = React__namespace.useCallback((selectedSlug) => {
41
- const selectedBranch = branches.find(branch => branch.slug === selectedSlug);
42
- if (selectedBranch) {
43
- onChange(selectedBranch);
44
- }
45
- }, [onChange, branches]);
46
- return (React__namespace.createElement(mosaic.Menu, { "aria-label": "Versions", placement: "bottom left", closeOnPress: true, matchTriggerWidth: true, renderTrigger: ({ isOpen }) => (React__namespace.createElement(mosaic.FieldButton, { w: "full", icon: "layer-group", px: 4, h: "md", active: isOpen, borderR: 0, roundedR: "none" }, (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.name) || (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.slug) || 'Choose a version')), items: [
47
- {
48
- type: 'option_group',
49
- title: 'Versions',
50
- onChange: handleChange,
51
- value: (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.slug) || '',
52
- children: branches.map(branch => ({
53
- title: branch.name || branch.slug,
54
- value: branch.slug,
55
- meta: branch.is_default ? 'Default' : undefined,
56
- })),
57
- },
58
- ] }));
31
+ const BranchSelector = ({ branchSlug, branches, onChange }) => {
32
+ const currentBranch = branches.find(branch => (!branchSlug ? branch.is_default : branch.slug === branchSlug));
33
+ const handleChange = React__namespace.useCallback((selectedSlug) => {
34
+ const selectedBranch = branches.find(branch => branch.slug === selectedSlug);
35
+ if (selectedBranch) {
36
+ onChange(selectedBranch);
37
+ }
38
+ }, [onChange, branches]);
39
+ return (React__namespace.createElement(mosaic.Menu, { "aria-label": "Versions", placement: "bottom left", closeOnPress: true, matchTriggerWidth: true, renderTrigger: ({ isOpen }) => (React__namespace.createElement(mosaic.FieldButton, { w: "full", icon: "layer-group", px: 4, h: "md", active: isOpen, borderR: 0, roundedR: "none" }, (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.name) || (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.slug) || 'Choose a version')), items: [
40
+ {
41
+ type: 'option_group',
42
+ title: 'Versions',
43
+ onChange: handleChange,
44
+ value: (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.slug) || '',
45
+ children: branches.map(branch => ({
46
+ title: branch.name || branch.slug,
47
+ value: branch.slug,
48
+ meta: branch.is_default ? 'Default' : undefined,
49
+ })),
50
+ },
51
+ ] }));
59
52
  };
60
53
 
61
- const PlatformContext = React__namespace.createContext({ platformUrl: 'https://stoplight.io' });
62
- const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthToken, isLoggedIn, children, }) => {
63
- return (React__namespace.createElement(PlatformContext.Provider, { value: { platformUrl, platformAuthToken, isLoggedIn } }, children));
64
- };
54
+ const PlatformContext = React__namespace.createContext({ platformUrl: 'https://stoplight.io' });
55
+ const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthToken, isLoggedIn, children, }) => {
56
+ return (React__namespace.createElement(PlatformContext.Provider, { value: { platformUrl, platformAuthToken, isLoggedIn } }, children));
57
+ };
65
58
  const DevPortalProvider = elementsCore.withPersistenceBoundary(elementsCore.withQueryClientProvider(elementsCore.withMosaicProvider(PlatformProvider)));
66
59
 
67
- /*! *****************************************************************************
60
+ /******************************************************************************
68
61
  Copyright (c) Microsoft Corporation.
69
62
 
70
63
  Permission to use, copy, modify, and/or distribute this software for any
@@ -78,6 +71,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
78
71
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
79
72
  PERFORMANCE OF THIS SOFTWARE.
80
73
  ***************************************************************************** */
74
+ /* global Reflect, Promise, SuppressedError, Symbol */
75
+
81
76
 
82
77
  function __rest(s, e) {
83
78
  var t = {};
@@ -99,89 +94,97 @@ function __awaiter(thisArg, _arguments, P, generator) {
99
94
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
100
95
  step((generator = generator.apply(thisArg, _arguments || [])).next());
101
96
  });
102
- }
103
-
104
- const NodeContent = ({ node, Link, hideMocking, refResolver, maxRefDepth, tryItCorsProxy, tryItCredentialsPolicy, nodeHasChanged, nodeUnsupported, compact, hideTryIt, hideTryItPanel, hideExport, onExportRequest, }) => {
105
- var _a, _b, _c, _d;
106
- return (React__namespace.createElement(NodeLinkContext.Provider, { value: [node, Link] },
107
- React__namespace.createElement(elementsCore.MarkdownComponentsProvider, { value: {
108
- a: LinkComponent,
109
- h2: (_a) => {
110
- var props = __rest(_a, ["color"]);
111
- return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 2 }, props));
112
- },
113
- h3: (_a) => {
114
- var props = __rest(_a, ["color"]);
115
- return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 3 }, props));
116
- },
117
- h4: (_a) => {
118
- var props = __rest(_a, ["color"]);
119
- return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 4 }, props));
120
- },
121
- } },
122
- React__namespace.createElement(elementsCore.MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
123
- React__namespace.createElement(elementsCore.Docs, { nodeType: node.type, nodeData: node.data, nodeTitle: node.title, layoutOptions: {
124
- compact,
125
- hideTryIt: hideTryIt,
126
- hideTryItPanel: hideTryItPanel,
127
- hideExport: hideExport ||
128
- ((_b = (_a = node.links.export_url) !== null && _a !== void 0 ? _a : node.links.export_original_file_url) !== null && _b !== void 0 ? _b : node.links.export_bundled_file_url) ===
129
- undefined,
130
- }, useNodeForRefResolving: true, refResolver: refResolver, maxRefDepth: maxRefDepth, tryItCorsProxy: tryItCorsProxy, exportProps: [types.NodeType.HttpService, types.NodeType.Model].includes(node.type)
131
- ? {
132
- original: onExportRequest
133
- ? { onPress: () => onExportRequest('original') }
134
- : { href: (_c = node.links.export_original_file_url) !== null && _c !== void 0 ? _c : node.links.export_url },
135
- bundled: onExportRequest
136
- ? { onPress: () => onExportRequest('bundled') }
137
- : { href: (_d = node.links.export_bundled_file_url) !== null && _d !== void 0 ? _d : getBundledUrl(node.links.export_url) },
138
- }
139
- : undefined, tryItCredentialsPolicy: tryItCredentialsPolicy, nodeHasChanged: nodeHasChanged, nodeUnsupported: nodeUnsupported })))));
140
- };
141
- const NodeLinkContext = React__namespace.createContext(undefined);
142
- const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
143
- const LinkComponent = ({ children, href, title }) => {
144
- const ctx = React__namespace.useContext(NodeLinkContext);
145
- if (href && externalRegex.test(href)) {
146
- return (React__namespace.createElement("a", { href: href, target: "_blank", rel: "noreferrer", title: title ? title : undefined }, children));
147
- }
148
- if (href && ctx) {
149
- const [node, Link] = ctx;
150
- const { fileUri } = getNodeUriParts(node.uri);
151
- const { fileUri: hrefFileUri } = getNodeUriParts(href);
152
- let resolvedUri;
153
- if (hrefFileUri) {
154
- resolvedUri = path.resolve(path.dirname(fileUri), href);
155
- }
156
- else {
157
- resolvedUri = path.resolve(fileUri, href);
158
- }
159
- const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
160
- const decodedUrl = decodeURIComponent(href);
161
- const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
162
- const edge = node.outbound_edges.find(edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor);
163
- if (edge) {
164
- return React__namespace.createElement(Link, { to: `${edge.slug}${hash ? `#${hash}` : ''}` }, children);
165
- }
166
- }
167
- return React__namespace.createElement("a", { href: href }, children);
168
- };
169
- function getBundledUrl(url) {
170
- if (url === undefined)
171
- return undefined;
172
- const bundledUrl = new URL(url);
173
- const searchParams = new URLSearchParams(bundledUrl.search);
174
- searchParams.append('deref', 'optimizedBundle');
175
- bundledUrl.search = searchParams.toString();
176
- return bundledUrl.toString();
177
97
  }
178
- const getNodeUriParts = (uri) => {
179
- const parts = uri.split(/(\.yaml|\.yml|\.json|\.md)/);
180
- if (parts.length === 1) {
181
- return { fileUri: '', pointer: parts[0] || '' };
182
- }
183
- const fileUri = `${parts[0] || ''}${parts[1] || ''}`;
184
- return { fileUri, pointer: parts[2] || '' };
98
+
99
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
100
+ var e = new Error(message);
101
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
102
+ };
103
+
104
+ const NodeContent = ({ node, Link, hideMocking, refResolver, maxRefDepth, tryItCorsProxy, tryItCredentialsPolicy, nodeHasChanged, nodeUnsupported, compact, hideTryIt, hideSamples, hideTryItPanel, hideSecurityInfo, hideServerInfo, hideExport, onExportRequest, }) => {
105
+ var _a, _b, _c, _d;
106
+ return (React__namespace.createElement(NodeLinkContext.Provider, { value: [node, Link] },
107
+ React__namespace.createElement(elementsCore.MarkdownComponentsProvider, { value: {
108
+ a: LinkComponent,
109
+ h2: (_a) => {
110
+ var props = __rest(_a, ["color"]);
111
+ return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 2 }, props));
112
+ },
113
+ h3: (_a) => {
114
+ var props = __rest(_a, ["color"]);
115
+ return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 3 }, props));
116
+ },
117
+ h4: (_a) => {
118
+ var props = __rest(_a, ["color"]);
119
+ return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 4 }, props));
120
+ },
121
+ } },
122
+ React__namespace.createElement(elementsCore.MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
123
+ React__namespace.createElement(elementsCore.Docs, { nodeType: node.type, nodeData: node.data, nodeTitle: node.title, layoutOptions: {
124
+ compact,
125
+ hideTryIt: hideTryIt,
126
+ hideTryItPanel: hideTryItPanel,
127
+ hideSamples,
128
+ hideSecurityInfo: hideSecurityInfo,
129
+ hideServerInfo: hideServerInfo,
130
+ hideExport: hideExport ||
131
+ ((_b = (_a = node.links.export_url) !== null && _a !== void 0 ? _a : node.links.export_original_file_url) !== null && _b !== void 0 ? _b : node.links.export_bundled_file_url) ===
132
+ undefined,
133
+ }, useNodeForRefResolving: true, refResolver: refResolver, maxRefDepth: maxRefDepth, tryItCorsProxy: tryItCorsProxy, exportProps: [types.NodeType.HttpService, types.NodeType.Model].includes(node.type)
134
+ ? {
135
+ original: onExportRequest
136
+ ? { onPress: () => onExportRequest('original') }
137
+ : { href: (_c = node.links.export_original_file_url) !== null && _c !== void 0 ? _c : node.links.export_url },
138
+ bundled: onExportRequest
139
+ ? { onPress: () => onExportRequest('bundled') }
140
+ : { href: (_d = node.links.export_bundled_file_url) !== null && _d !== void 0 ? _d : getBundledUrl(node.links.export_url) },
141
+ }
142
+ : undefined, tryItCredentialsPolicy: tryItCredentialsPolicy, nodeHasChanged: nodeHasChanged, nodeUnsupported: nodeUnsupported })))));
143
+ };
144
+ const NodeLinkContext = React__namespace.createContext(undefined);
145
+ const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
146
+ const LinkComponent = ({ children, href, title }) => {
147
+ const ctx = React__namespace.useContext(NodeLinkContext);
148
+ if (href && externalRegex.test(href)) {
149
+ return (React__namespace.createElement("a", { href: href, target: "_blank", rel: "noreferrer", title: title ? title : undefined }, children));
150
+ }
151
+ if (href && ctx) {
152
+ const [node, Link] = ctx;
153
+ const { fileUri } = getNodeUriParts(node.uri);
154
+ const { fileUri: hrefFileUri } = getNodeUriParts(href);
155
+ let resolvedUri;
156
+ if (hrefFileUri) {
157
+ resolvedUri = path.resolve(path.dirname(fileUri), href);
158
+ }
159
+ else {
160
+ resolvedUri = path.resolve(fileUri, href);
161
+ }
162
+ const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
163
+ const decodedUrl = decodeURIComponent(href);
164
+ const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
165
+ const edge = node.outbound_edges.find(edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor);
166
+ if (edge) {
167
+ return React__namespace.createElement(Link, { to: `${edge.slug}${hash ? `#${hash}` : ''}` }, children);
168
+ }
169
+ }
170
+ return React__namespace.createElement("a", { href: href }, children);
171
+ };
172
+ function getBundledUrl(url) {
173
+ if (url === undefined)
174
+ return undefined;
175
+ const bundledUrl = new URL(url);
176
+ const searchParams = new URLSearchParams(bundledUrl.search);
177
+ searchParams.append('deref', 'optimizedBundle');
178
+ bundledUrl.search = searchParams.toString();
179
+ return bundledUrl.toString();
180
+ }
181
+ const getNodeUriParts = (uri) => {
182
+ const parts = uri.split(/(\.yaml|\.yml|\.json|\.md)/);
183
+ if (parts.length === 1) {
184
+ return { fileUri: '', pointer: parts[0] || '' };
185
+ }
186
+ const fileUri = `${parts[0] || ''}${parts[1] || ''}`;
187
+ return { fileUri, pointer: parts[2] || '' };
185
188
  };
186
189
 
187
190
  /*!
@@ -206,287 +209,287 @@ var faSpinner = {
206
209
  icon: [512, 512, [], "f110", "M304 48C304 74.51 282.5 96 256 96C229.5 96 208 74.51 208 48C208 21.49 229.5 0 256 0C282.5 0 304 21.49 304 48zM304 464C304 490.5 282.5 512 256 512C229.5 512 208 490.5 208 464C208 437.5 229.5 416 256 416C282.5 416 304 437.5 304 464zM0 256C0 229.5 21.49 208 48 208C74.51 208 96 229.5 96 256C96 282.5 74.51 304 48 304C21.49 304 0 282.5 0 256zM512 256C512 282.5 490.5 304 464 304C437.5 304 416 282.5 416 256C416 229.5 437.5 208 464 208C490.5 208 512 229.5 512 256zM74.98 437C56.23 418.3 56.23 387.9 74.98 369.1C93.73 350.4 124.1 350.4 142.9 369.1C161.6 387.9 161.6 418.3 142.9 437C124.1 455.8 93.73 455.8 74.98 437V437zM142.9 142.9C124.1 161.6 93.73 161.6 74.98 142.9C56.24 124.1 56.24 93.73 74.98 74.98C93.73 56.23 124.1 56.23 142.9 74.98C161.6 93.73 161.6 124.1 142.9 142.9zM369.1 369.1C387.9 350.4 418.3 350.4 437 369.1C455.8 387.9 455.8 418.3 437 437C418.3 455.8 387.9 455.8 369.1 437C350.4 418.3 350.4 387.9 369.1 369.1V369.1z"]
207
210
  };
208
211
 
209
- const SearchImpl = ({ isLoading, search, searchResults, isOpen, onClose, onClick, onSearch }) => {
210
- const listBoxRef = React__namespace.useRef(null);
211
- const onChange = React__namespace.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
212
- const onKeyDown = React__namespace.useCallback(e => {
213
- var _a;
214
- if (e.key === 'ArrowDown') {
215
- e.preventDefault();
216
- (_a = listBoxRef.current) === null || _a === void 0 ? void 0 : _a.focus();
217
- }
218
- }, []);
219
- return (React__namespace.createElement(mosaic.Modal, { renderHeader: () => (React__namespace.createElement(mosaic.Input, { appearance: "minimal", borderB: true, size: "lg", icon: React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, ml: 1, icon: isLoading ? faSpinner : faSearch, spin: isLoading }), autoFocus: true, placeholder: "Search...", value: search, onChange: onChange, onKeyDown: onKeyDown })), isOpen: !!isOpen, onClose: onClose },
220
- React__namespace.createElement(SearchResultsList, { searchResults: searchResults, onClick: onClick })));
221
- };
222
- const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = true, }) => {
223
- const listBoxRef = React__namespace.useRef(null);
224
- const onSelectionChange = React__namespace.useCallback(keys => {
225
- const selectedId = keys.values().next().value;
226
- const selectedResult = searchResults === null || searchResults === void 0 ? void 0 : searchResults.find(searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId);
227
- if (selectedResult) {
228
- onClick(selectedResult);
229
- }
230
- }, [searchResults, onClick]);
231
- return (React__namespace.createElement(React__namespace.Fragment, null, searchResults && searchResults.length > 0 ? (React__namespace.createElement(mosaic.ListBox, { ref: listBoxRef, "aria-label": "Search", overflowY: "auto", h: isEmbedded ? undefined : 80, m: -5, items: searchResults, selectionMode: "single", onSelectionChange: onSelectionChange }, (searchResult) => {
232
- var _a, _b;
233
- return (React__namespace.createElement(mosaic.ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
234
- React__namespace.createElement(mosaic.Box, { p: 3, borderB: !showDivider ? undefined : true },
235
- React__namespace.createElement(mosaic.Flex, { align: "center" },
236
- React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, w: 4, icon: elementsCore.NodeTypeIconDefs[searchResult.type], style: { color: elementsCore.NodeTypeColors[searchResult.type] } }),
237
- React__namespace.createElement(mosaic.Box, { flex: 1, fontSize: "lg", dangerouslySetInnerHTML: { __html: (_a = searchResult.highlighted.name) !== null && _a !== void 0 ? _a : '' }, fontWeight: "medium", textOverflow: "overflow-ellipsis", mx: 2 }),
238
- React__namespace.createElement(mosaic.Box, { fontSize: "sm", color: "muted" }, searchResult.project_name)),
239
- React__namespace.createElement(mosaic.Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
240
- })) : (React__namespace.createElement(mosaic.Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
241
- };
242
- const SearchResults = flow__default["default"](elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchResultsList);
243
- const Search = flow__default["default"](elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchImpl);
244
-
245
- const TableOfContents = (_a) => {
246
- var { tableOfContents, activeId, Link, collapseTableOfContents = false, externalScrollbar, isInResponsiveMode = false, onLinkClick } = _a, boxProps = __rest(_a, ["tableOfContents", "activeId", "Link", "collapseTableOfContents", "externalScrollbar", "isInResponsiveMode", "onLinkClick"]);
247
- return (React__namespace.createElement(mosaic.Flex, Object.assign({ bg: isInResponsiveMode ? 'canvas' : 'canvas-100' }, boxProps, { flexDirection: "col", maxH: "full" }),
248
- React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto" },
249
- React__namespace.createElement(elementsCore.TableOfContents, { tree: tableOfContents.items, activeId: activeId, Link: Link, maxDepthOpenByDefault: collapseTableOfContents ? 0 : 1, externalScrollbar: externalScrollbar, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode })),
250
- tableOfContents.hide_powered_by ? null : (React__namespace.createElement(elementsCore.PoweredByLink, { source: activeId, pathname: typeof window !== 'undefined' ? window.location.pathname : '', packageType: "elements-dev-portal" }))));
212
+ const SearchImpl = ({ isLoading, search, searchResults, isOpen, onClose, onClick, onSearch }) => {
213
+ const listBoxRef = React__namespace.useRef(null);
214
+ const onChange = React__namespace.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
215
+ const onKeyDown = React__namespace.useCallback(e => {
216
+ var _a;
217
+ if (e.key === 'ArrowDown') {
218
+ e.preventDefault();
219
+ (_a = listBoxRef.current) === null || _a === void 0 ? void 0 : _a.focus();
220
+ }
221
+ }, []);
222
+ return (React__namespace.createElement(mosaic.Modal, { renderHeader: () => (React__namespace.createElement(mosaic.Input, { appearance: "minimal", borderB: true, size: "lg", icon: React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, ml: 1, icon: isLoading ? faSpinner : faSearch, spin: isLoading }), autoFocus: true, placeholder: "Search...", value: search, onChange: onChange, onKeyDown: onKeyDown })), isOpen: !!isOpen, onClose: onClose },
223
+ React__namespace.createElement(SearchResultsList, { searchResults: searchResults, onClick: onClick })));
224
+ };
225
+ const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = true, }) => {
226
+ const listBoxRef = React__namespace.useRef(null);
227
+ const onSelectionChange = React__namespace.useCallback(keys => {
228
+ const selectedId = keys.values().next().value;
229
+ const selectedResult = searchResults === null || searchResults === void 0 ? void 0 : searchResults.find(searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId);
230
+ if (selectedResult) {
231
+ onClick(selectedResult);
232
+ }
233
+ }, [searchResults, onClick]);
234
+ return (React__namespace.createElement(React__namespace.Fragment, null, searchResults && searchResults.length > 0 ? (React__namespace.createElement(mosaic.ListBox, { ref: listBoxRef, "aria-label": "Search", overflowY: "auto", h: isEmbedded ? undefined : 80, m: -5, items: searchResults, selectionMode: "single", onSelectionChange: onSelectionChange }, (searchResult) => {
235
+ var _a, _b;
236
+ return (React__namespace.createElement(mosaic.ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
237
+ React__namespace.createElement(mosaic.Box, { p: 3, borderB: !showDivider ? undefined : true },
238
+ React__namespace.createElement(mosaic.Flex, { align: "center" },
239
+ React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, w: 4, icon: elementsCore.NodeTypeIconDefs[searchResult.type], style: { color: elementsCore.NodeTypeColors[searchResult.type] } }),
240
+ React__namespace.createElement(mosaic.Box, { flex: 1, fontSize: "lg", dangerouslySetInnerHTML: { __html: (_a = searchResult.highlighted.name) !== null && _a !== void 0 ? _a : '' }, fontWeight: "medium", textOverflow: "overflow-ellipsis", mx: 2 }),
241
+ React__namespace.createElement(mosaic.Box, { fontSize: "sm", color: "muted" }, searchResult.project_name)),
242
+ React__namespace.createElement(mosaic.Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
243
+ })) : (React__namespace.createElement(mosaic.Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
244
+ };
245
+ const SearchResults = flow(elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchResultsList);
246
+ const Search = flow(elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchImpl);
247
+
248
+ const TableOfContents = (_a) => {
249
+ var { tableOfContents, activeId, Link, collapseTableOfContents = false, externalScrollbar, isInResponsiveMode = false, onLinkClick } = _a, boxProps = __rest(_a, ["tableOfContents", "activeId", "Link", "collapseTableOfContents", "externalScrollbar", "isInResponsiveMode", "onLinkClick"]);
250
+ return (React__namespace.createElement(mosaic.Flex, Object.assign({ bg: isInResponsiveMode ? 'canvas' : 'canvas-100' }, boxProps, { flexDirection: "col", maxH: "full" }),
251
+ React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto" },
252
+ React__namespace.createElement(elementsCore.TableOfContents, { tree: tableOfContents.items, activeId: activeId, Link: Link, maxDepthOpenByDefault: collapseTableOfContents ? 0 : 1, externalScrollbar: externalScrollbar, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode })),
253
+ tableOfContents.hide_powered_by ? null : (React__namespace.createElement(elementsCore.PoweredByLink, { source: activeId, pathname: typeof window !== 'undefined' ? window.location.pathname : '', packageType: "elements-dev-portal" }))));
251
254
  };
252
255
 
253
- const ROOT_CACHE_KEY = '@stoplight/elements-dev-portal/client-query';
254
- const devPortalCacheKeys = {
255
- all: [ROOT_CACHE_KEY],
256
- projects: () => [ROOT_CACHE_KEY, 'projects'],
257
- project: (projectId) => [...devPortalCacheKeys.projects(), projectId],
258
- projectsList: () => [...devPortalCacheKeys.projects(), 'list'],
259
- projectDetails: (projectId) => [...devPortalCacheKeys.project(projectId), 'details'],
260
- branches: (projectId) => [...devPortalCacheKeys.project(projectId), 'branches'],
261
- branch: (projectId, branch) => [...devPortalCacheKeys.branches(projectId), branch],
262
- branchesList: (projectId) => [...devPortalCacheKeys.branches(projectId), 'list'],
263
- branchDetails: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'details'],
264
- branchTOC: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'toc'],
265
- branchNodes: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'nodes'],
266
- branchNode: (projectId, branch, node) => [...devPortalCacheKeys.branchNodes(projectId, branch), node],
267
- branchNodesList: (projectId, branch) => [...devPortalCacheKeys.branchNodes(projectId, branch), 'list'],
268
- branchNodeDetails: (projectId, branch, node) => [...devPortalCacheKeys.branchNode(projectId, branch, node), 'details'],
269
- search: () => [...devPortalCacheKeys.all, 'search'],
270
- searchNodes: (filters) => [
271
- ...devPortalCacheKeys.search(),
272
- filters,
273
- ],
256
+ const ROOT_CACHE_KEY = '@stoplight/elements-dev-portal/client-query';
257
+ const devPortalCacheKeys = {
258
+ all: [ROOT_CACHE_KEY],
259
+ projects: () => [ROOT_CACHE_KEY, 'projects'],
260
+ project: (projectId) => [...devPortalCacheKeys.projects(), projectId],
261
+ projectsList: () => [...devPortalCacheKeys.projects(), 'list'],
262
+ projectDetails: (projectId) => [...devPortalCacheKeys.project(projectId), 'details'],
263
+ branches: (projectId) => [...devPortalCacheKeys.project(projectId), 'branches'],
264
+ branch: (projectId, branch) => [...devPortalCacheKeys.branches(projectId), branch],
265
+ branchesList: (projectId) => [...devPortalCacheKeys.branches(projectId), 'list'],
266
+ branchDetails: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'details'],
267
+ branchTOC: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'toc'],
268
+ branchNodes: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'nodes'],
269
+ branchNode: (projectId, branch, node) => [...devPortalCacheKeys.branchNodes(projectId, branch), node],
270
+ branchNodesList: (projectId, branch) => [...devPortalCacheKeys.branchNodes(projectId, branch), 'list'],
271
+ branchNodeDetails: (projectId, branch, node) => [...devPortalCacheKeys.branchNode(projectId, branch, node), 'details'],
272
+ search: () => [...devPortalCacheKeys.all, 'search'],
273
+ searchNodes: (filters) => [
274
+ ...devPortalCacheKeys.search(),
275
+ filters,
276
+ ],
274
277
  };
275
278
 
276
- const Forbidden = () => (React__default["default"].createElement(mosaic.Flex, { align: "center", justify: "center", flexGrow: true },
277
- React__default["default"].createElement(mosaic.VStack, { spacing: 4, align: "center" },
278
- React__default["default"].createElement(mosaic.Heading, { size: 1 }, "Forbidden"),
279
- React__default["default"].createElement(mosaic.Box, { as: "p" }, "You don't have permission to access this resource"))));
279
+ const Forbidden = () => (React.createElement(mosaic.Flex, { align: "center", justify: "center", flexGrow: true },
280
+ React.createElement(mosaic.VStack, { spacing: 4, align: "center" },
281
+ React.createElement(mosaic.Heading, { size: 1 }, "Forbidden"),
282
+ React.createElement(mosaic.Box, { as: "p" }, "You don't have permission to access this resource"))));
280
283
 
281
- const Loading = () => (React__default["default"].createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted" },
282
- React__default["default"].createElement(mosaic.Icon, { icon: faCircleNotch, size: "3x", spin: true })));
284
+ const Loading = () => (React.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted" },
285
+ React.createElement(mosaic.Icon, { icon: faCircleNotch, size: "3x", spin: true })));
283
286
 
284
- const NotFound = () => (React__default["default"].createElement(mosaic.Flex, { align: "center", justify: "center", flexGrow: true },
285
- React__default["default"].createElement(mosaic.VStack, { spacing: 4, align: "center" },
286
- React__default["default"].createElement(mosaic.Heading, { size: 1 }, "Not Found"),
287
- React__default["default"].createElement(mosaic.Box, { as: "p" }, "Could not find what you are looking for"))));
287
+ const NotFound = () => (React.createElement(mosaic.Flex, { align: "center", justify: "center", flexGrow: true },
288
+ React.createElement(mosaic.VStack, { spacing: 4, align: "center" },
289
+ React.createElement(mosaic.Heading, { size: 1 }, "Not Found"),
290
+ React.createElement(mosaic.Box, { as: "p" }, "Could not find what you are looking for"))));
288
291
 
289
- const UpgradeToStarter = () => (React__default["default"].createElement(mosaic.Flex, { as: "a", href: "https://stoplight.io/pricing/", target: "_blank", rel: "noreferrer noopener", justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted", flexDirection: "col" },
290
- React__default["default"].createElement(mosaic.Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
291
- React__default["default"].createElement(mosaic.Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
292
+ const UpgradeToStarter = () => (React.createElement(mosaic.Flex, { as: "a", href: "https://stoplight.io/pricing/", target: "_blank", rel: "noreferrer noopener", justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted", flexDirection: "col" },
293
+ React.createElement(mosaic.Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
294
+ React.createElement(mosaic.Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
292
295
 
293
- const appVersion = '2.3.3';
296
+ const appVersion = '2.4.0';
294
297
 
295
- class ResponseError extends Error {
296
- constructor(message, responseCode) {
297
- super(message);
298
- this.name = 'ResponseError';
299
- this.code = responseCode;
300
- }
301
- }
302
- const getNodeContent = ({ nodeSlug, projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
303
- const encodedNodeSlug = encodeURIComponent(nodeSlug);
304
- const encodedProjectId = encodeURIComponent(projectId);
305
- const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
306
- const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
307
- const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/nodes/${encodedNodeSlug}${branchQuery}`, {
308
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
309
- });
310
- const data = yield response.json();
311
- if (!response.ok) {
312
- if (response.status === 402) {
313
- throw new ResponseError('Payment Required', response.status);
314
- }
315
- else if (response.status === 403) {
316
- throw new ResponseError('Forbidden', response.status);
317
- }
318
- else {
319
- throw new ResponseError('Something went wrong', response.status);
320
- }
321
- }
322
- return data;
298
+ class ResponseError extends Error {
299
+ constructor(message, responseCode) {
300
+ super(message);
301
+ this.name = 'ResponseError';
302
+ this.code = responseCode;
303
+ }
304
+ }
305
+ const getNodeContent = ({ nodeSlug, projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
306
+ const encodedNodeSlug = encodeURIComponent(nodeSlug);
307
+ const encodedProjectId = encodeURIComponent(projectId);
308
+ const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
309
+ const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
310
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/nodes/${encodedNodeSlug}${branchQuery}`, {
311
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
312
+ });
313
+ const data = yield response.json();
314
+ if (!response.ok) {
315
+ if (response.status === 402) {
316
+ throw new ResponseError('Payment Required', response.status);
317
+ }
318
+ else if (response.status === 403) {
319
+ throw new ResponseError('Forbidden', response.status);
320
+ }
321
+ else {
322
+ throw new ResponseError('Something went wrong', response.status);
323
+ }
324
+ }
325
+ return data;
323
326
  });
324
327
 
325
- const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
326
- const encodedProjectId = encodeURIComponent(projectId);
327
- const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/branches`, {
328
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
329
- });
330
- const data = yield response.json();
331
- if (!response.ok) {
332
- throw new Error(data);
333
- }
334
- return data;
328
+ const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
329
+ const encodedProjectId = encodeURIComponent(projectId);
330
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/branches`, {
331
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
332
+ });
333
+ const data = yield response.json();
334
+ if (!response.ok) {
335
+ throw new Error(data);
336
+ }
337
+ return data;
335
338
  });
336
339
 
337
- function useGetBranches({ projectId }) {
338
- const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
339
- return reactQuery.useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
340
- enabled: projectId ? true : false,
341
- });
340
+ function useGetBranches({ projectId }) {
341
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
342
+ return reactQuery.useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
343
+ enabled: projectId ? true : false,
344
+ });
342
345
  }
343
346
 
344
- function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
345
- const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
346
- return reactQuery.useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl, isLoggedIn], () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: nodeSlug && projectId ? true : false });
347
+ function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
348
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
349
+ return reactQuery.useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl, isLoggedIn], () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: nodeSlug && projectId ? true : false });
347
350
  }
348
351
 
349
- const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
350
- const encodedProjectId = encodeURIComponent(projectId);
351
- const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
352
- const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
353
- const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
354
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
355
- });
356
- const data = yield response.json();
357
- if (!response.ok) {
358
- throw new Error(data);
359
- }
360
- return data;
352
+ const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
353
+ const encodedProjectId = encodeURIComponent(projectId);
354
+ const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
355
+ const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
356
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
357
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
358
+ });
359
+ const data = yield response.json();
360
+ if (!response.ok) {
361
+ throw new Error(data);
362
+ }
363
+ return data;
361
364
  });
362
365
 
363
- function useGetTableOfContents({ projectId, branchSlug }) {
364
- const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
365
- return reactQuery.useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, isLoggedIn], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
366
+ function useGetTableOfContents({ projectId, branchSlug }) {
367
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
368
+ return reactQuery.useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, isLoggedIn], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
366
369
  }
367
370
 
368
- const StoplightProjectImpl = ({ projectId, hideTryIt, hideMocking, hideExport, collapseTableOfContents = false, tryItCredentialsPolicy, tryItCorsProxy, }) => {
369
- const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
370
- const branchSlug = decodeURIComponent(encodedBranchSlug);
371
- const history = reactRouterDom.useHistory();
372
- const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
373
- const { data: branches } = useGetBranches({ projectId });
374
- const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
375
- nodeSlug,
376
- projectId,
377
- branchSlug,
378
- });
379
- const container = React__namespace.useRef(null);
380
- if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
381
- const firstNode = elementsCore.findFirstNode(tableOfContents.items);
382
- if (firstNode) {
383
- return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${firstNode.slug}` : `/${firstNode.slug}` });
384
- }
385
- }
386
- let elem;
387
- if (isLoadingNode || !isTocFetched) {
388
- elem = React__namespace.createElement(Loading, null);
389
- }
390
- else if (isError) {
391
- if (nodeError instanceof ResponseError) {
392
- if (nodeError.code === 402) {
393
- elem = React__namespace.createElement(UpgradeToStarter, null);
394
- }
395
- else if (nodeError.code === 403) {
396
- elem = React__namespace.createElement(Forbidden, null);
397
- }
398
- else {
399
- elem = React__namespace.createElement(NotFound, null);
400
- }
401
- }
402
- else {
403
- elem = React__namespace.createElement(NotFound, null);
404
- }
405
- }
406
- else if (!node) {
407
- elem = React__namespace.createElement(NotFound, null);
408
- }
409
- else if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
410
- return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}` });
411
- }
412
- else {
413
- elem = (React__namespace.createElement(NodeContent, { node: node, Link: elementsCore.ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }));
414
- }
415
- const handleTocClick = () => {
416
- if (container.current) {
417
- container.current.scrollIntoView();
418
- }
419
- };
420
- return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: React__namespace.createElement(React__namespace.Fragment, null,
421
- branches && branches.items.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches.items, onChange: branch => {
422
- const encodedBranchSlug = encodeURIComponent(branch.slug);
423
- history.push(branch.is_default ? `/${nodeSlug}` : `/branches/${encodedBranchSlug}/${nodeSlug}`);
424
- } })) : null,
425
- tableOfContents ? (React__namespace.createElement(TableOfContents, { activeId: (node === null || node === void 0 ? void 0 : node.id) || (nodeSlug === null || nodeSlug === void 0 ? void 0 : nodeSlug.split('-')[0]) || '', tableOfContents: tableOfContents, Link: reactRouterDom.Link, collapseTableOfContents: collapseTableOfContents, onLinkClick: handleTocClick })) : null) }, elem));
426
- };
427
- const StoplightProjectRouter = (_a) => {
428
- var { platformUrl, basePath = '/', staticRouterPath = '', router = 'history' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
429
- const { Router, routerProps } = elementsCore.useRouter(router, basePath, staticRouterPath);
430
- return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
431
- React__namespace.createElement(elementsCore.RouterTypeContext.Provider, { value: router },
432
- React__namespace.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
433
- React__namespace.createElement(reactRouterDom.Switch, null,
434
- React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug+", exact: true },
435
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
436
- React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug+", exact: true },
437
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
438
- React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
439
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))))))));
440
- };
371
+ const StoplightProjectImpl = ({ projectId, hideTryIt, hideSecurityInfo, hideServerInfo, hideMocking, hideExport, collapseTableOfContents = false, tryItCredentialsPolicy, tryItCorsProxy, }) => {
372
+ const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
373
+ const branchSlug = decodeURIComponent(encodedBranchSlug);
374
+ const history = reactRouterDom.useHistory();
375
+ const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
376
+ const { data: branches } = useGetBranches({ projectId });
377
+ const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
378
+ nodeSlug,
379
+ projectId,
380
+ branchSlug,
381
+ });
382
+ const container = React__namespace.useRef(null);
383
+ if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
384
+ const firstNode = elementsCore.findFirstNode(tableOfContents.items);
385
+ if (firstNode) {
386
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${firstNode.slug}` : `/${firstNode.slug}` });
387
+ }
388
+ }
389
+ let elem;
390
+ if (isLoadingNode || !isTocFetched) {
391
+ elem = React__namespace.createElement(Loading, null);
392
+ }
393
+ else if (isError) {
394
+ if (nodeError instanceof ResponseError) {
395
+ if (nodeError.code === 402) {
396
+ elem = React__namespace.createElement(UpgradeToStarter, null);
397
+ }
398
+ else if (nodeError.code === 403) {
399
+ elem = React__namespace.createElement(Forbidden, null);
400
+ }
401
+ else {
402
+ elem = React__namespace.createElement(NotFound, null);
403
+ }
404
+ }
405
+ else {
406
+ elem = React__namespace.createElement(NotFound, null);
407
+ }
408
+ }
409
+ else if (!node) {
410
+ elem = React__namespace.createElement(NotFound, null);
411
+ }
412
+ else if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
413
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}` });
414
+ }
415
+ else {
416
+ elem = (React__namespace.createElement(NodeContent, { node: node, Link: elementsCore.ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, hideSecurityInfo: hideSecurityInfo, hideServerInfo: hideServerInfo, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }));
417
+ }
418
+ const handleTocClick = () => {
419
+ if (container.current) {
420
+ container.current.scrollIntoView();
421
+ }
422
+ };
423
+ return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: React__namespace.createElement(React__namespace.Fragment, null,
424
+ branches && branches.items.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches.items, onChange: branch => {
425
+ const encodedBranchSlug = encodeURIComponent(branch.slug);
426
+ history.push(branch.is_default ? `/${nodeSlug}` : `/branches/${encodedBranchSlug}/${nodeSlug}`);
427
+ } })) : null,
428
+ tableOfContents ? (React__namespace.createElement(TableOfContents, { activeId: (node === null || node === void 0 ? void 0 : node.id) || (nodeSlug === null || nodeSlug === void 0 ? void 0 : nodeSlug.split('-')[0]) || '', tableOfContents: tableOfContents, Link: reactRouterDom.Link, collapseTableOfContents: collapseTableOfContents, onLinkClick: handleTocClick })) : null) }, elem));
429
+ };
430
+ const StoplightProjectRouter = (_a) => {
431
+ var { platformUrl, basePath = '/', staticRouterPath = '', router = 'history' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
432
+ const { Router, routerProps } = elementsCore.useRouter(router, basePath, staticRouterPath);
433
+ return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
434
+ React__namespace.createElement(elementsCore.RouterTypeContext.Provider, { value: router },
435
+ React__namespace.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
436
+ React__namespace.createElement(reactRouterDom.Switch, null,
437
+ React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug+", exact: true },
438
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
439
+ React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug+", exact: true },
440
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
441
+ React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
442
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))))))));
443
+ };
441
444
  const StoplightProject = elementsCore.withStyles(StoplightProjectRouter);
442
445
 
443
- const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
444
- const queryParams = [];
445
- let fetchedWorkspaceId = workspaceId || '';
446
- if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
447
- const encodedProjectId = encodeURIComponent(projectIds[0]);
448
- const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
449
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
450
- });
451
- const data = yield response.json();
452
- fetchedWorkspaceId = data.workspace.id;
453
- }
454
- if (projectIds && projectIds.length) {
455
- queryParams.push(...projectIds.map((projectId, index) => {
456
- const encodedProjectId = encodeURIComponent(projectId);
457
- return `project_ids[${index}]=${encodedProjectId}`;
458
- }));
459
- }
460
- if (search) {
461
- const encodedSearch = encodeURIComponent(search);
462
- queryParams.push(`search=${encodedSearch}`);
463
- }
464
- if (branchSlug) {
465
- const encodedBranchSlug = encodeURIComponent(branchSlug);
466
- queryParams.push(`branch=${encodedBranchSlug}`);
467
- }
468
- const query = queryParams.length ? `?${queryParams.join('&')}` : '';
469
- const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
470
- const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
471
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
472
- });
473
- const data = yield response.json();
474
- if (!response.ok) {
475
- throw new Error(data);
476
- }
477
- return data;
446
+ const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
447
+ const queryParams = [];
448
+ let fetchedWorkspaceId = workspaceId || '';
449
+ if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
450
+ const encodedProjectId = encodeURIComponent(projectIds[0]);
451
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
452
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
453
+ });
454
+ const data = yield response.json();
455
+ fetchedWorkspaceId = data.workspace.id;
456
+ }
457
+ if (projectIds && projectIds.length) {
458
+ queryParams.push(...projectIds.map((projectId, index) => {
459
+ const encodedProjectId = encodeURIComponent(projectId);
460
+ return `project_ids[${index}]=${encodedProjectId}`;
461
+ }));
462
+ }
463
+ if (search) {
464
+ const encodedSearch = encodeURIComponent(search);
465
+ queryParams.push(`search=${encodedSearch}`);
466
+ }
467
+ if (branchSlug) {
468
+ const encodedBranchSlug = encodeURIComponent(branchSlug);
469
+ queryParams.push(`branch=${encodedBranchSlug}`);
470
+ }
471
+ const query = queryParams.length ? `?${queryParams.join('&')}` : '';
472
+ const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
473
+ const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
474
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
475
+ });
476
+ const data = yield response.json();
477
+ if (!response.ok) {
478
+ throw new Error(data);
479
+ }
480
+ return data;
478
481
  });
479
482
 
480
- const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
481
- const encodedProjectId = encodeURIComponent(projectIds[0]);
482
- const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
483
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
484
- });
485
- const data = yield response.json();
486
- if (!response.ok) {
487
- throw new Error(data);
488
- }
489
- return data;
483
+ const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
484
+ const encodedProjectId = encodeURIComponent(projectIds[0]);
485
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
486
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
487
+ });
488
+ const data = yield response.json();
489
+ if (!response.ok) {
490
+ throw new Error(data);
491
+ }
492
+ return data;
490
493
  });
491
494
 
492
495
  /**
@@ -702,7 +705,7 @@ function useStateIgnoreCallback(initialState) {
702
705
  return [state, setStateIgnoreCallback];
703
706
  }
704
707
  function useDebounce(value, delay, options) {
705
- var eq = (options && options.equalityFn) || valueEquality;
708
+ var eq = valueEquality;
706
709
  var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
707
710
  var debounced = useDebouncedCallback(React.useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
708
711
  var previousValue = React.useRef(value);
@@ -716,19 +719,19 @@ function useDebounce(value, delay, options) {
716
719
  return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
717
720
  }
718
721
 
719
- function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
720
- const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
721
- const [debounceSearch] = useDebounce(search, 500);
722
- return reactQuery.useQuery([
723
- ...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
724
- platformUrl,
725
- isLoggedIn,
726
- ], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
722
+ function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
723
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
724
+ const [debounceSearch] = useDebounce(search, 500);
725
+ return reactQuery.useQuery([
726
+ ...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
727
+ platformUrl,
728
+ isLoggedIn,
729
+ ], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
727
730
  }
728
731
 
729
- function useGetWorkspace({ projectIds }) {
730
- const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
731
- return reactQuery.useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));
732
+ function useGetWorkspace({ projectIds }) {
733
+ const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
734
+ return reactQuery.useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));
732
735
  }
733
736
 
734
737
  exports.BranchSelector = BranchSelector;