@jpmorganchase/elemental-dev-portal 2.10.1 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/NodeContent/NodeContent.d.ts +2 -2
- package/containers/StoplightProject.d.ts +2 -0
- package/index.esm.js +411 -372
- package/index.js +431 -399
- package/index.mjs +411 -372
- package/package.json +5 -5
- package/styles.min.css +1 -1
- package/version.d.ts +1 -1
- package/web-components.min.js +1 -1
- package/web-components.min.js.LICENSE.txt +34 -25
package/index.esm.js
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
import { Menu, FieldButton, Modal, Input, Box, Icon, ListBox, ListBoxItem, Flex, VStack, Heading } from '@stoplight/mosaic';
|
2
2
|
import * as React from 'react';
|
3
3
|
import React__default, { useRef, useEffect, useMemo, useCallback, useState } from 'react';
|
4
|
-
import { withPersistenceBoundary, withQueryClientProvider, withMosaicProvider, MarkdownComponentsProvider, LinkHeading, MockingProvider, Docs, withStyles, NodeTypeIconDefs, NodeTypeColors, TableOfContents as TableOfContents$1, PoweredByLink, useRouter,
|
4
|
+
import { withPersistenceBoundary, withQueryClientProvider, withMosaicProvider, MarkdownComponentsProvider, LinkHeading, MockingProvider, Docs, RouterTypeContext, withStyles, NodeTypeIconDefs, NodeTypeColors, TableOfContents as TableOfContents$1, PoweredByLink, useRouter, findFirstNode, SidebarLayout, ScrollToHashElement, ReactRouterMarkdownLink } from '@jpmorganchase/elemental-core';
|
5
5
|
import { resolve, dirname } from '@stoplight/path';
|
6
6
|
import { NodeType } from '@stoplight/types';
|
7
|
+
import { useLocation, useInRouterContext, Routes, Route, useParams, useNavigate, Navigate, Link, Outlet, useOutletContext } from 'react-router-dom';
|
7
8
|
import flow from 'lodash/flow.js';
|
8
|
-
import { Switch, Route, useParams, useHistory, Redirect, Link } from 'react-router-dom';
|
9
9
|
import { useQuery } from 'react-query';
|
10
10
|
|
11
|
-
const BranchSelector = ({ branchSlug, branches, onChange }) => {
|
12
|
-
const currentBranch = branches.find(branch => (!branchSlug ? branch.is_default : branch.slug === branchSlug));
|
13
|
-
const handleChange = React.useCallback((selectedSlug) => {
|
14
|
-
const selectedBranch = branches.find(branch => branch.slug === selectedSlug);
|
15
|
-
if (selectedBranch) {
|
16
|
-
onChange(selectedBranch);
|
17
|
-
}
|
18
|
-
}, [onChange, branches]);
|
19
|
-
return (React.createElement(Menu, { "aria-label": "Versions", placement: "bottom left", closeOnPress: true, matchTriggerWidth: true, renderTrigger: ({ isOpen }) => (React.createElement(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: [
|
20
|
-
{
|
21
|
-
type: 'option_group',
|
22
|
-
title: 'Versions',
|
23
|
-
onChange: handleChange,
|
24
|
-
value: (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.slug) || '',
|
25
|
-
children: branches.map(branch => ({
|
26
|
-
title: branch.name || branch.slug,
|
27
|
-
value: branch.slug,
|
28
|
-
meta: branch.is_default ? 'Default' : undefined,
|
29
|
-
})),
|
30
|
-
},
|
31
|
-
] }));
|
11
|
+
const BranchSelector = ({ branchSlug, branches, onChange }) => {
|
12
|
+
const currentBranch = branches.find(branch => (!branchSlug ? branch.is_default : branch.slug === branchSlug));
|
13
|
+
const handleChange = React.useCallback((selectedSlug) => {
|
14
|
+
const selectedBranch = branches.find(branch => branch.slug === selectedSlug);
|
15
|
+
if (selectedBranch) {
|
16
|
+
onChange(selectedBranch);
|
17
|
+
}
|
18
|
+
}, [onChange, branches]);
|
19
|
+
return (React.createElement(Menu, { "aria-label": "Versions", placement: "bottom left", closeOnPress: true, matchTriggerWidth: true, renderTrigger: ({ isOpen }) => (React.createElement(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: [
|
20
|
+
{
|
21
|
+
type: 'option_group',
|
22
|
+
title: 'Versions',
|
23
|
+
onChange: handleChange,
|
24
|
+
value: (currentBranch === null || currentBranch === void 0 ? void 0 : currentBranch.slug) || '',
|
25
|
+
children: branches.map(branch => ({
|
26
|
+
title: branch.name || branch.slug,
|
27
|
+
value: branch.slug,
|
28
|
+
meta: branch.is_default ? 'Default' : undefined,
|
29
|
+
})),
|
30
|
+
},
|
31
|
+
] }));
|
32
32
|
};
|
33
33
|
|
34
|
-
const PlatformContext = React.createContext({ platformUrl: 'https://stoplight.io' });
|
35
|
-
const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthToken, isLoggedIn, children, }) => {
|
36
|
-
return (React.createElement(PlatformContext.Provider, { value: { platformUrl, platformAuthToken, isLoggedIn } }, children));
|
37
|
-
};
|
34
|
+
const PlatformContext = React.createContext({ platformUrl: 'https://stoplight.io' });
|
35
|
+
const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthToken, isLoggedIn, children, }) => {
|
36
|
+
return (React.createElement(PlatformContext.Provider, { value: { platformUrl, platformAuthToken, isLoggedIn } }, children));
|
37
|
+
};
|
38
38
|
const DevPortalProvider = withPersistenceBoundary(withQueryClientProvider(withMosaicProvider(PlatformProvider)));
|
39
39
|
|
40
|
-
|
40
|
+
/******************************************************************************
|
41
41
|
Copyright (c) Microsoft Corporation.
|
42
42
|
|
43
43
|
Permission to use, copy, modify, and/or distribute this software for any
|
@@ -51,6 +51,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
51
51
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
52
52
|
PERFORMANCE OF THIS SOFTWARE.
|
53
53
|
***************************************************************************** */
|
54
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
55
|
+
|
54
56
|
|
55
57
|
function __rest(s, e) {
|
56
58
|
var t = {};
|
@@ -72,89 +74,116 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
72
74
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
73
75
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
74
76
|
});
|
75
|
-
}
|
76
|
-
|
77
|
-
const NodeContent = ({ node, Link, hideMocking, refResolver, maxRefDepth, tryItCorsProxy, tryItCredentialsPolicy, nodeHasChanged, nodeUnsupported, compact, hideTryIt, hideTryItPanel, hideExport, onExportRequest, }) => {
|
78
|
-
var _a, _b, _c, _d;
|
79
|
-
return (React.createElement(NodeLinkContext.Provider, { value: [node, Link] },
|
80
|
-
React.createElement(MarkdownComponentsProvider, { value: {
|
81
|
-
a: LinkComponent,
|
82
|
-
h2: (_a) => {
|
83
|
-
var props = __rest(_a, ["color"]);
|
84
|
-
return React.createElement(LinkHeading, Object.assign({ size: 2 }, props));
|
85
|
-
},
|
86
|
-
h3: (_a) => {
|
87
|
-
var props = __rest(_a, ["color"]);
|
88
|
-
return React.createElement(LinkHeading, Object.assign({ size: 3 }, props));
|
89
|
-
},
|
90
|
-
h4: (_a) => {
|
91
|
-
var props = __rest(_a, ["color"]);
|
92
|
-
return React.createElement(LinkHeading, Object.assign({ size: 4 }, props));
|
93
|
-
},
|
94
|
-
} },
|
95
|
-
React.createElement(MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
|
96
|
-
React.createElement(Docs, { nodeType: node.type, nodeData: node.data, nodeTitle: node.title, layoutOptions: {
|
97
|
-
compact,
|
98
|
-
hideTryIt: hideTryIt,
|
99
|
-
hideTryItPanel: hideTryItPanel,
|
100
|
-
hideExport: hideExport ||
|
101
|
-
((_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) ===
|
102
|
-
undefined,
|
103
|
-
}, useNodeForRefResolving: true, refResolver: refResolver, maxRefDepth: maxRefDepth, tryItCorsProxy: tryItCorsProxy, exportProps: [NodeType.HttpService, NodeType.Model].includes(node.type)
|
104
|
-
? {
|
105
|
-
original: onExportRequest
|
106
|
-
? { onPress: () => onExportRequest('original') }
|
107
|
-
: { href: (_c = node.links.export_original_file_url) !== null && _c !== void 0 ? _c : node.links.export_url },
|
108
|
-
bundled: onExportRequest
|
109
|
-
? { onPress: () => onExportRequest('bundled') }
|
110
|
-
: { href: (_d = node.links.export_bundled_file_url) !== null && _d !== void 0 ? _d : getBundledUrl(node.links.export_url) },
|
111
|
-
}
|
112
|
-
: undefined, tryItCredentialsPolicy: tryItCredentialsPolicy, nodeHasChanged: nodeHasChanged, nodeUnsupported: nodeUnsupported })))));
|
113
|
-
};
|
114
|
-
const NodeLinkContext = React.createContext(undefined);
|
115
|
-
const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
|
116
|
-
const LinkComponent = ({ children, href, title }) => {
|
117
|
-
const ctx = React.useContext(NodeLinkContext);
|
118
|
-
if (href && externalRegex.test(href)) {
|
119
|
-
return (React.createElement("a", { href: href, target: "_blank", rel: "noreferrer", title: title ? title : undefined }, children));
|
120
|
-
}
|
121
|
-
if (href && ctx) {
|
122
|
-
const [node, Link] = ctx;
|
123
|
-
const { fileUri } = getNodeUriParts(node.uri);
|
124
|
-
const { fileUri: hrefFileUri } = getNodeUriParts(href);
|
125
|
-
let resolvedUri;
|
126
|
-
if (hrefFileUri) {
|
127
|
-
resolvedUri = resolve(dirname(fileUri), href);
|
128
|
-
}
|
129
|
-
else {
|
130
|
-
resolvedUri = resolve(fileUri, href);
|
131
|
-
}
|
132
|
-
const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
|
133
|
-
const decodedUrl = decodeURIComponent(href);
|
134
|
-
const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
|
135
|
-
const edge = node.outbound_edges.find(edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor);
|
136
|
-
if (edge) {
|
137
|
-
return React.createElement(Link, { to: `${edge.slug}${hash ? `#${hash}` : ''}` }, children);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
return React.createElement("a", { href: href }, children);
|
141
|
-
};
|
142
|
-
function getBundledUrl(url) {
|
143
|
-
if (url === undefined)
|
144
|
-
return undefined;
|
145
|
-
const bundledUrl = new URL(url);
|
146
|
-
const searchParams = new URLSearchParams(bundledUrl.search);
|
147
|
-
searchParams.append('deref', 'optimizedBundle');
|
148
|
-
bundledUrl.search = searchParams.toString();
|
149
|
-
return bundledUrl.toString();
|
150
77
|
}
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
78
|
+
|
79
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
80
|
+
var e = new Error(message);
|
81
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
82
|
+
};
|
83
|
+
|
84
|
+
const NodeContent = ({ node, Link, hideMocking, refResolver, maxRefDepth, tryItCorsProxy, tryItCredentialsPolicy, nodeHasChanged, nodeUnsupported, compact, hideTryIt, hideSamples, hideTryItPanel, hideSecurityInfo, hideServerInfo, hideExport, onExportRequest, }) => {
|
85
|
+
var _a, _b, _c, _d;
|
86
|
+
return (React.createElement(NodeLinkContext.Provider, { value: [node, Link] },
|
87
|
+
React.createElement(MarkdownComponentsProvider, { value: {
|
88
|
+
a: LinkComponent,
|
89
|
+
h2: (_a) => {
|
90
|
+
var props = __rest(_a, ["color"]);
|
91
|
+
return React.createElement(LinkHeading, Object.assign({ size: 2 }, props));
|
92
|
+
},
|
93
|
+
h3: (_a) => {
|
94
|
+
var props = __rest(_a, ["color"]);
|
95
|
+
return React.createElement(LinkHeading, Object.assign({ size: 3 }, props));
|
96
|
+
},
|
97
|
+
h4: (_a) => {
|
98
|
+
var props = __rest(_a, ["color"]);
|
99
|
+
return React.createElement(LinkHeading, Object.assign({ size: 4 }, props));
|
100
|
+
},
|
101
|
+
} },
|
102
|
+
React.createElement(MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
|
103
|
+
React.createElement(Docs, { nodeType: node.type, nodeData: node.data, nodeTitle: node.title, layoutOptions: {
|
104
|
+
compact,
|
105
|
+
hideTryIt: hideTryIt,
|
106
|
+
hideTryItPanel: hideTryItPanel,
|
107
|
+
hideSamples,
|
108
|
+
hideSecurityInfo: hideSecurityInfo,
|
109
|
+
hideServerInfo: hideServerInfo,
|
110
|
+
hideExport: hideExport ||
|
111
|
+
((_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) ===
|
112
|
+
undefined,
|
113
|
+
}, useNodeForRefResolving: true, refResolver: refResolver, maxRefDepth: maxRefDepth, tryItCorsProxy: tryItCorsProxy, exportProps: [NodeType.HttpService, NodeType.Model].includes(node.type)
|
114
|
+
? {
|
115
|
+
original: onExportRequest
|
116
|
+
? { onPress: () => onExportRequest('original') }
|
117
|
+
: { href: (_c = node.links.export_original_file_url) !== null && _c !== void 0 ? _c : node.links.export_url },
|
118
|
+
bundled: onExportRequest
|
119
|
+
? { onPress: () => onExportRequest('bundled') }
|
120
|
+
: { href: (_d = node.links.export_bundled_file_url) !== null && _d !== void 0 ? _d : getBundledUrl(node.links.export_url) },
|
121
|
+
}
|
122
|
+
: undefined, tryItCredentialsPolicy: tryItCredentialsPolicy, nodeHasChanged: nodeHasChanged, nodeUnsupported: nodeUnsupported })))));
|
123
|
+
};
|
124
|
+
const NodeLinkContext = React.createContext(undefined);
|
125
|
+
const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
|
126
|
+
const LinkComponent = ({ children, href, title }) => {
|
127
|
+
const ctx = React.useContext(NodeLinkContext);
|
128
|
+
const routerKind = React.useContext(RouterTypeContext);
|
129
|
+
const { pathname } = useLocation();
|
130
|
+
const route = pathname.split('#')[0];
|
131
|
+
try {
|
132
|
+
if (href && externalRegex.test(href)) {
|
133
|
+
const baseURL = window.location.host;
|
134
|
+
const hrefURL = new URL(href).host;
|
135
|
+
if (baseURL === hrefURL) {
|
136
|
+
return (React.createElement("a", { href: href, title: title ? title : undefined }, children));
|
137
|
+
}
|
138
|
+
return (React.createElement("a", { href: href, target: "_blank", rel: "noreferrer", title: title ? title : undefined }, children));
|
139
|
+
}
|
140
|
+
}
|
141
|
+
catch (error) {
|
142
|
+
console.error(error);
|
143
|
+
}
|
144
|
+
if (href && ctx) {
|
145
|
+
const [node, Link] = ctx;
|
146
|
+
const { fileUri } = getNodeUriParts(node.uri);
|
147
|
+
const { fileUri: hrefFileUri } = getNodeUriParts(href);
|
148
|
+
let resolvedUri;
|
149
|
+
if (hrefFileUri) {
|
150
|
+
resolvedUri = resolve(dirname(fileUri), href);
|
151
|
+
}
|
152
|
+
else {
|
153
|
+
resolvedUri = resolve(fileUri, href);
|
154
|
+
}
|
155
|
+
const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
|
156
|
+
const decodedUrl = decodeURIComponent(href);
|
157
|
+
const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
|
158
|
+
const [pagePathWithoutHash] = pathname.split('#');
|
159
|
+
let edge = node.outbound_edges.find(edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor);
|
160
|
+
if (!edge) {
|
161
|
+
edge = node.outbound_edges.find(edge => pagePathWithoutHash === `/${edge.slug}`);
|
162
|
+
}
|
163
|
+
if (edge) {
|
164
|
+
const slug = routerKind === 'hash' ? `#${route.replace(node.slug, edge.slug)}` : edge.slug;
|
165
|
+
return React.createElement(Link, { to: `${slug}${hash ? `#${hash}` : ''}` }, children);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
const fullHref = routerKind === 'hash' ? `#${route}${href}` : href;
|
169
|
+
return React.createElement("a", { href: fullHref }, children);
|
170
|
+
};
|
171
|
+
function getBundledUrl(url) {
|
172
|
+
if (url === undefined)
|
173
|
+
return undefined;
|
174
|
+
const bundledUrl = new URL(url);
|
175
|
+
const searchParams = new URLSearchParams(bundledUrl.search);
|
176
|
+
searchParams.append('deref', 'optimizedBundle');
|
177
|
+
bundledUrl.search = searchParams.toString();
|
178
|
+
return bundledUrl.toString();
|
179
|
+
}
|
180
|
+
const getNodeUriParts = (uri) => {
|
181
|
+
const parts = uri.split(/(\.yaml|\.yml|\.json|\.md)/);
|
182
|
+
if (parts.length === 1) {
|
183
|
+
return { fileUri: '', pointer: parts[0] || '' };
|
184
|
+
}
|
185
|
+
const fileUri = `${parts[0] || ''}${parts[1] || ''}`;
|
186
|
+
return { fileUri, pointer: parts[2] || '' };
|
158
187
|
};
|
159
188
|
|
160
189
|
/*!
|
@@ -179,287 +208,297 @@ var faSpinner = {
|
|
179
208
|
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"]
|
180
209
|
};
|
181
210
|
|
182
|
-
const SearchImpl = ({ isLoading, search, searchResults, isOpen, onClose, onClick, onSearch }) => {
|
183
|
-
const listBoxRef = React.useRef(null);
|
184
|
-
const onChange = React.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
|
185
|
-
const onKeyDown = React.useCallback(e => {
|
186
|
-
var _a;
|
187
|
-
if (e.key === 'ArrowDown') {
|
188
|
-
e.preventDefault();
|
189
|
-
(_a = listBoxRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
190
|
-
}
|
191
|
-
}, []);
|
192
|
-
return (React.createElement(Modal, { renderHeader: () => (React.createElement(Input, { appearance: "minimal", borderB: true, size: "lg", icon: React.createElement(Box, { as: Icon, ml: 1, icon: isLoading ? faSpinner : faSearch, spin: isLoading }), autoFocus: true, placeholder: "Search...", value: search, onChange: onChange, onKeyDown: onKeyDown })), isOpen: !!isOpen, onClose: onClose },
|
193
|
-
React.createElement(SearchResultsList, { searchResults: searchResults, onClick: onClick })));
|
194
|
-
};
|
195
|
-
const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = true, }) => {
|
196
|
-
const listBoxRef = React.useRef(null);
|
197
|
-
const onSelectionChange = React.useCallback(keys => {
|
198
|
-
const selectedId = keys.values().next().value;
|
199
|
-
const selectedResult = searchResults === null || searchResults === void 0 ? void 0 : searchResults.find(searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId);
|
200
|
-
if (selectedResult) {
|
201
|
-
onClick(selectedResult);
|
202
|
-
}
|
203
|
-
}, [searchResults, onClick]);
|
204
|
-
return (React.createElement(React.Fragment, null, searchResults && searchResults.length > 0 ? (React.createElement(ListBox, { ref: listBoxRef, "aria-label": "Search", overflowY: "auto", h: isEmbedded ? undefined : 80, m: -5, items: searchResults, selectionMode: "single", onSelectionChange: onSelectionChange }, (searchResult) => {
|
205
|
-
var _a, _b;
|
206
|
-
return (React.createElement(ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
|
207
|
-
React.createElement(Box, { p: 3, borderB: !showDivider ? undefined : true },
|
208
|
-
React.createElement(Flex, { align: "center" },
|
209
|
-
React.createElement(Box, { as: Icon, w: 4, icon: NodeTypeIconDefs[searchResult.type], style: { color: NodeTypeColors[searchResult.type] } }),
|
210
|
-
React.createElement(Box, { flex: 1, fontSize: "lg", dangerouslySetInnerHTML: { __html: (_a = searchResult.highlighted.name) !== null && _a !== void 0 ? _a : '' }, fontWeight: "medium", textOverflow: "overflow-ellipsis", mx: 2 }),
|
211
|
-
React.createElement(Box, { fontSize: "sm", color: "muted" }, searchResult.project_name)),
|
212
|
-
React.createElement(Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
|
213
|
-
})) : (React.createElement(Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
|
214
|
-
};
|
215
|
-
const SearchResults = flow(withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(SearchResultsList);
|
211
|
+
const SearchImpl = ({ isLoading, search, searchResults, isOpen, onClose, onClick, onSearch }) => {
|
212
|
+
const listBoxRef = React.useRef(null);
|
213
|
+
const onChange = React.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
|
214
|
+
const onKeyDown = React.useCallback(e => {
|
215
|
+
var _a;
|
216
|
+
if (e.key === 'ArrowDown') {
|
217
|
+
e.preventDefault();
|
218
|
+
(_a = listBoxRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
219
|
+
}
|
220
|
+
}, []);
|
221
|
+
return (React.createElement(Modal, { renderHeader: () => (React.createElement(Input, { appearance: "minimal", borderB: true, size: "lg", icon: React.createElement(Box, { as: Icon, ml: 1, icon: isLoading ? faSpinner : faSearch, spin: isLoading }), autoFocus: true, placeholder: "Search...", value: search, onChange: onChange, onKeyDown: onKeyDown })), isOpen: !!isOpen, onClose: onClose },
|
222
|
+
React.createElement(SearchResultsList, { searchResults: searchResults, onClick: onClick })));
|
223
|
+
};
|
224
|
+
const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = true, }) => {
|
225
|
+
const listBoxRef = React.useRef(null);
|
226
|
+
const onSelectionChange = React.useCallback(keys => {
|
227
|
+
const selectedId = keys.values().next().value;
|
228
|
+
const selectedResult = searchResults === null || searchResults === void 0 ? void 0 : searchResults.find(searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId);
|
229
|
+
if (selectedResult) {
|
230
|
+
onClick(selectedResult);
|
231
|
+
}
|
232
|
+
}, [searchResults, onClick]);
|
233
|
+
return (React.createElement(React.Fragment, null, searchResults && searchResults.length > 0 ? (React.createElement(ListBox, { ref: listBoxRef, "aria-label": "Search", overflowY: "auto", h: isEmbedded ? undefined : 80, m: -5, items: searchResults, selectionMode: "single", onSelectionChange: onSelectionChange }, (searchResult) => {
|
234
|
+
var _a, _b;
|
235
|
+
return (React.createElement(ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
|
236
|
+
React.createElement(Box, { p: 3, borderB: !showDivider ? undefined : true },
|
237
|
+
React.createElement(Flex, { align: "center" },
|
238
|
+
React.createElement(Box, { as: Icon, w: 4, icon: NodeTypeIconDefs[searchResult.type], style: { color: NodeTypeColors[searchResult.type] } }),
|
239
|
+
React.createElement(Box, { flex: 1, fontSize: "lg", dangerouslySetInnerHTML: { __html: (_a = searchResult.highlighted.name) !== null && _a !== void 0 ? _a : '' }, fontWeight: "medium", textOverflow: "overflow-ellipsis", mx: 2 }),
|
240
|
+
React.createElement(Box, { fontSize: "sm", color: "muted" }, searchResult.project_name)),
|
241
|
+
React.createElement(Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
|
242
|
+
})) : (React.createElement(Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
|
243
|
+
};
|
244
|
+
const SearchResults = flow(withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(SearchResultsList);
|
216
245
|
const Search = flow(withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(SearchImpl);
|
217
246
|
|
218
|
-
const TableOfContents = (_a) => {
|
219
|
-
var { tableOfContents, activeId, Link, collapseTableOfContents = false, externalScrollbar, isInResponsiveMode = false, onLinkClick } = _a, boxProps = __rest(_a, ["tableOfContents", "activeId", "Link", "collapseTableOfContents", "externalScrollbar", "isInResponsiveMode", "onLinkClick"]);
|
220
|
-
return (React.createElement(Flex, Object.assign({ bg: isInResponsiveMode ? 'canvas' : 'canvas-100' }, boxProps, { flexDirection: "col", maxH: "full" }),
|
221
|
-
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto" },
|
222
|
-
React.createElement(TableOfContents$1, { tree: tableOfContents.items, activeId: activeId, Link: Link, maxDepthOpenByDefault: collapseTableOfContents ? 0 : 1, externalScrollbar: externalScrollbar, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode })),
|
223
|
-
tableOfContents.hide_powered_by ? null : (React.createElement(PoweredByLink, { source: activeId, pathname: typeof window !== 'undefined' ? window.location.pathname : '', packageType: "elements-dev-portal" }))));
|
247
|
+
const TableOfContents = (_a) => {
|
248
|
+
var { tableOfContents, activeId, Link, collapseTableOfContents = false, externalScrollbar, isInResponsiveMode = false, onLinkClick } = _a, boxProps = __rest(_a, ["tableOfContents", "activeId", "Link", "collapseTableOfContents", "externalScrollbar", "isInResponsiveMode", "onLinkClick"]);
|
249
|
+
return (React.createElement(Flex, Object.assign({ bg: isInResponsiveMode ? 'canvas' : 'canvas-100' }, boxProps, { flexDirection: "col", maxH: "full" }),
|
250
|
+
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto" },
|
251
|
+
React.createElement(TableOfContents$1, { tree: tableOfContents.items, activeId: activeId, Link: Link, maxDepthOpenByDefault: collapseTableOfContents ? 0 : 1, externalScrollbar: externalScrollbar, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode })),
|
252
|
+
tableOfContents.hide_powered_by ? null : (React.createElement(PoweredByLink, { source: activeId, pathname: typeof window !== 'undefined' ? window.location.pathname : '', packageType: "elements-dev-portal" }))));
|
224
253
|
};
|
225
254
|
|
226
|
-
const ROOT_CACHE_KEY = '@stoplight/elements-dev-portal/client-query';
|
227
|
-
const devPortalCacheKeys = {
|
228
|
-
all: [ROOT_CACHE_KEY],
|
229
|
-
projects: () => [ROOT_CACHE_KEY, 'projects'],
|
230
|
-
project: (projectId) => [...devPortalCacheKeys.projects(), projectId],
|
231
|
-
projectsList: () => [...devPortalCacheKeys.projects(), 'list'],
|
232
|
-
projectDetails: (projectId) => [...devPortalCacheKeys.project(projectId), 'details'],
|
233
|
-
branches: (projectId) => [...devPortalCacheKeys.project(projectId), 'branches'],
|
234
|
-
branch: (projectId, branch) => [...devPortalCacheKeys.branches(projectId), branch],
|
235
|
-
branchesList: (projectId) => [...devPortalCacheKeys.branches(projectId), 'list'],
|
236
|
-
branchDetails: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'details'],
|
237
|
-
branchTOC: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'toc'],
|
238
|
-
branchNodes: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'nodes'],
|
239
|
-
branchNode: (projectId, branch, node) => [...devPortalCacheKeys.branchNodes(projectId, branch), node],
|
240
|
-
branchNodesList: (projectId, branch) => [...devPortalCacheKeys.branchNodes(projectId, branch), 'list'],
|
241
|
-
branchNodeDetails: (projectId, branch, node) => [...devPortalCacheKeys.branchNode(projectId, branch, node), 'details'],
|
242
|
-
search: () => [...devPortalCacheKeys.all, 'search'],
|
243
|
-
searchNodes: (filters) => [
|
244
|
-
...devPortalCacheKeys.search(),
|
245
|
-
filters,
|
246
|
-
],
|
255
|
+
const ROOT_CACHE_KEY = '@stoplight/elements-dev-portal/client-query';
|
256
|
+
const devPortalCacheKeys = {
|
257
|
+
all: [ROOT_CACHE_KEY],
|
258
|
+
projects: () => [ROOT_CACHE_KEY, 'projects'],
|
259
|
+
project: (projectId) => [...devPortalCacheKeys.projects(), projectId],
|
260
|
+
projectsList: () => [...devPortalCacheKeys.projects(), 'list'],
|
261
|
+
projectDetails: (projectId) => [...devPortalCacheKeys.project(projectId), 'details'],
|
262
|
+
branches: (projectId) => [...devPortalCacheKeys.project(projectId), 'branches'],
|
263
|
+
branch: (projectId, branch) => [...devPortalCacheKeys.branches(projectId), branch],
|
264
|
+
branchesList: (projectId) => [...devPortalCacheKeys.branches(projectId), 'list'],
|
265
|
+
branchDetails: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'details'],
|
266
|
+
branchTOC: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'toc'],
|
267
|
+
branchNodes: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'nodes'],
|
268
|
+
branchNode: (projectId, branch, node) => [...devPortalCacheKeys.branchNodes(projectId, branch), node],
|
269
|
+
branchNodesList: (projectId, branch) => [...devPortalCacheKeys.branchNodes(projectId, branch), 'list'],
|
270
|
+
branchNodeDetails: (projectId, branch, node) => [...devPortalCacheKeys.branchNode(projectId, branch, node), 'details'],
|
271
|
+
search: () => [...devPortalCacheKeys.all, 'search'],
|
272
|
+
searchNodes: (filters) => [
|
273
|
+
...devPortalCacheKeys.search(),
|
274
|
+
filters,
|
275
|
+
],
|
247
276
|
};
|
248
277
|
|
249
|
-
const Forbidden = () => (React__default.createElement(Flex, { align: "center", justify: "center", flexGrow: true },
|
250
|
-
React__default.createElement(VStack, { spacing: 4, align: "center" },
|
251
|
-
React__default.createElement(Heading, { size: 1 }, "Forbidden"),
|
278
|
+
const Forbidden = () => (React__default.createElement(Flex, { align: "center", justify: "center", flexGrow: true },
|
279
|
+
React__default.createElement(VStack, { spacing: 4, align: "center" },
|
280
|
+
React__default.createElement(Heading, { size: 1 }, "Forbidden"),
|
252
281
|
React__default.createElement(Box, { as: "p" }, "You don't have permission to access this resource"))));
|
253
282
|
|
254
|
-
const Loading = () => (React__default.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted" },
|
283
|
+
const Loading = () => (React__default.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted" },
|
255
284
|
React__default.createElement(Icon, { icon: faCircleNotch, size: "3x", spin: true })));
|
256
285
|
|
257
|
-
const NotFound = () => (React__default.createElement(Flex, { align: "center", justify: "center", flexGrow: true },
|
258
|
-
React__default.createElement(VStack, { spacing: 4, align: "center" },
|
259
|
-
React__default.createElement(Heading, { size: 1 }, "Not Found"),
|
286
|
+
const NotFound = () => (React__default.createElement(Flex, { align: "center", justify: "center", flexGrow: true },
|
287
|
+
React__default.createElement(VStack, { spacing: 4, align: "center" },
|
288
|
+
React__default.createElement(Heading, { size: 1 }, "Not Found"),
|
260
289
|
React__default.createElement(Box, { as: "p" }, "Could not find what you are looking for"))));
|
261
290
|
|
262
|
-
const UpgradeToStarter = () => (React__default.createElement(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" },
|
263
|
-
React__default.createElement(Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
|
291
|
+
const UpgradeToStarter = () => (React__default.createElement(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" },
|
292
|
+
React__default.createElement(Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
|
264
293
|
React__default.createElement(Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
|
265
294
|
|
266
|
-
const appVersion = '2.
|
295
|
+
const appVersion = '2.11.1';
|
267
296
|
|
268
|
-
class ResponseError extends Error {
|
269
|
-
constructor(message, responseCode) {
|
270
|
-
super(message);
|
271
|
-
this.name = 'ResponseError';
|
272
|
-
this.code = responseCode;
|
273
|
-
}
|
274
|
-
}
|
275
|
-
const getNodeContent = ({ nodeSlug, projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
276
|
-
const encodedNodeSlug = encodeURIComponent(nodeSlug);
|
277
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
278
|
-
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
279
|
-
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
280
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/nodes/${encodedNodeSlug}${branchQuery}`, {
|
281
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
282
|
-
});
|
283
|
-
const data = yield response.json();
|
284
|
-
if (!response.ok) {
|
285
|
-
if (response.status === 402) {
|
286
|
-
throw new ResponseError('Payment Required', response.status);
|
287
|
-
}
|
288
|
-
else if (response.status === 403) {
|
289
|
-
throw new ResponseError('Forbidden', response.status);
|
290
|
-
}
|
291
|
-
else {
|
292
|
-
throw new ResponseError('Something went wrong', response.status);
|
293
|
-
}
|
294
|
-
}
|
295
|
-
return data;
|
297
|
+
class ResponseError extends Error {
|
298
|
+
constructor(message, responseCode) {
|
299
|
+
super(message);
|
300
|
+
this.name = 'ResponseError';
|
301
|
+
this.code = responseCode;
|
302
|
+
}
|
303
|
+
}
|
304
|
+
const getNodeContent = ({ nodeSlug, projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
305
|
+
const encodedNodeSlug = encodeURIComponent(nodeSlug);
|
306
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
307
|
+
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
308
|
+
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
309
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/nodes/${encodedNodeSlug}${branchQuery}`, {
|
310
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
311
|
+
});
|
312
|
+
const data = yield response.json();
|
313
|
+
if (!response.ok) {
|
314
|
+
if (response.status === 402) {
|
315
|
+
throw new ResponseError('Payment Required', response.status);
|
316
|
+
}
|
317
|
+
else if (response.status === 403) {
|
318
|
+
throw new ResponseError('Forbidden', response.status);
|
319
|
+
}
|
320
|
+
else {
|
321
|
+
throw new ResponseError('Something went wrong', response.status);
|
322
|
+
}
|
323
|
+
}
|
324
|
+
return data;
|
296
325
|
});
|
297
326
|
|
298
|
-
const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
299
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
300
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/branches`, {
|
301
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
302
|
-
});
|
303
|
-
const data = yield response.json();
|
304
|
-
if (!response.ok) {
|
305
|
-
throw new Error(data);
|
306
|
-
}
|
307
|
-
return data;
|
327
|
+
const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
328
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
329
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/branches`, {
|
330
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
331
|
+
});
|
332
|
+
const data = yield response.json();
|
333
|
+
if (!response.ok) {
|
334
|
+
throw new Error(data);
|
335
|
+
}
|
336
|
+
return data;
|
308
337
|
});
|
309
338
|
|
310
|
-
function useGetBranches({ projectId }) {
|
311
|
-
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
312
|
-
return useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
|
313
|
-
enabled: projectId ? true : false,
|
314
|
-
});
|
339
|
+
function useGetBranches({ projectId }) {
|
340
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
341
|
+
return useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
|
342
|
+
enabled: projectId ? true : false,
|
343
|
+
});
|
315
344
|
}
|
316
345
|
|
317
|
-
function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
|
318
|
-
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
319
|
-
return useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl, isLoggedIn], () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: nodeSlug && projectId ? true : false });
|
346
|
+
function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
|
347
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
348
|
+
return useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl, isLoggedIn], () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: nodeSlug && projectId ? true : false });
|
320
349
|
}
|
321
350
|
|
322
|
-
const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
323
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
324
|
-
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
325
|
-
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
326
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
|
327
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
328
|
-
});
|
329
|
-
const data = yield response.json();
|
330
|
-
if (!response.ok) {
|
331
|
-
throw new Error(data);
|
332
|
-
}
|
333
|
-
return data;
|
351
|
+
const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
352
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
353
|
+
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
354
|
+
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
355
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
|
356
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
357
|
+
});
|
358
|
+
const data = yield response.json();
|
359
|
+
if (!response.ok) {
|
360
|
+
throw new Error(data);
|
361
|
+
}
|
362
|
+
return data;
|
334
363
|
});
|
335
364
|
|
336
|
-
function useGetTableOfContents({ projectId, branchSlug }) {
|
337
|
-
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
338
|
-
return useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, isLoggedIn], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
|
365
|
+
function useGetTableOfContents({ projectId, branchSlug }) {
|
366
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
367
|
+
return useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, isLoggedIn], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
|
339
368
|
}
|
340
369
|
|
341
|
-
const StoplightProjectImpl = ({ projectId,
|
342
|
-
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = useParams();
|
343
|
-
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
344
|
-
const
|
345
|
-
const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
|
346
|
-
const { data: branches } = useGetBranches({ projectId });
|
347
|
-
const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
|
348
|
-
nodeSlug,
|
349
|
-
projectId,
|
350
|
-
branchSlug,
|
351
|
-
});
|
352
|
-
const container = React.useRef(null);
|
353
|
-
if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
|
354
|
-
const firstNode = findFirstNode(tableOfContents.items);
|
355
|
-
if (firstNode) {
|
356
|
-
return React.createElement(
|
357
|
-
}
|
358
|
-
}
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
}
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
};
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
};
|
370
|
+
const StoplightProjectImpl = ({ projectId, collapseTableOfContents = false }) => {
|
371
|
+
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = useParams();
|
372
|
+
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
373
|
+
const navigate = useNavigate();
|
374
|
+
const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
|
375
|
+
const { data: branches } = useGetBranches({ projectId });
|
376
|
+
const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
|
377
|
+
nodeSlug,
|
378
|
+
projectId,
|
379
|
+
branchSlug,
|
380
|
+
});
|
381
|
+
const container = React.useRef(null);
|
382
|
+
if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
|
383
|
+
const firstNode = findFirstNode(tableOfContents.items);
|
384
|
+
if (firstNode) {
|
385
|
+
return React.createElement(Navigate, { to: branchSlug ? `branches/${branchSlug}/${firstNode.slug}` : `${firstNode.slug}`, replace: true });
|
386
|
+
}
|
387
|
+
}
|
388
|
+
const handleTocClick = () => {
|
389
|
+
if (container.current) {
|
390
|
+
container.current.scrollIntoView();
|
391
|
+
}
|
392
|
+
};
|
393
|
+
return (React.createElement(SidebarLayout, { ref: container, sidebar: React.createElement(React.Fragment, null,
|
394
|
+
branches && branches.items.length > 1 ? (React.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches.items, onChange: branch => {
|
395
|
+
const encodedBranchSlug = encodeURIComponent(branch.slug);
|
396
|
+
navigate(branch.is_default ? `${nodeSlug}` : `branches/${encodedBranchSlug}/${nodeSlug}`);
|
397
|
+
} })) : null,
|
398
|
+
tableOfContents ? (React.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: Link, collapseTableOfContents: collapseTableOfContents, onLinkClick: handleTocClick })) : null) },
|
399
|
+
React.createElement(Outlet, { context: [isLoadingNode, isTocFetched, isError, nodeError, node] })));
|
400
|
+
};
|
401
|
+
const ProjectNode = ({ hideTryIt, hideSecurityInfo, hideServerInfo, hideMocking, hideExport, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
402
|
+
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = useParams();
|
403
|
+
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
404
|
+
const [isLoadingNode, isTocFetched, isError, nodeError, node] = useOutletContext();
|
405
|
+
if (isLoadingNode || !isTocFetched) {
|
406
|
+
return React.createElement(Loading, null);
|
407
|
+
}
|
408
|
+
if (isError) {
|
409
|
+
if (nodeError instanceof ResponseError) {
|
410
|
+
if (nodeError.code === 402) {
|
411
|
+
return React.createElement(UpgradeToStarter, null);
|
412
|
+
}
|
413
|
+
else if (nodeError.code === 403) {
|
414
|
+
return React.createElement(Forbidden, null);
|
415
|
+
}
|
416
|
+
else {
|
417
|
+
return React.createElement(NotFound, null);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
else {
|
421
|
+
return React.createElement(NotFound, null);
|
422
|
+
}
|
423
|
+
}
|
424
|
+
if (!node) {
|
425
|
+
return React.createElement(NotFound, null);
|
426
|
+
}
|
427
|
+
if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
|
428
|
+
return React.createElement(Navigate, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}`, replace: true });
|
429
|
+
}
|
430
|
+
return (React.createElement(React.Fragment, null,
|
431
|
+
React.createElement(ScrollToHashElement, null),
|
432
|
+
React.createElement(NodeContent, { node: node, Link: ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, hideSecurityInfo: hideSecurityInfo, hideServerInfo: hideServerInfo, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })));
|
433
|
+
};
|
434
|
+
const StoplightProjectRouter = (_a) => {
|
435
|
+
var { platformUrl, basePath = '/', staticRouterPath = '', router = 'hash' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
|
436
|
+
const { Router, routerProps } = useRouter(router, basePath, staticRouterPath);
|
437
|
+
const outerRouter = useInRouterContext();
|
438
|
+
const InternalRoutes = () => (React.createElement(Routes, null,
|
439
|
+
React.createElement(Route, { path: "/", element: React.createElement(StoplightProjectImpl, Object.assign({}, props)) },
|
440
|
+
React.createElement(Route, { path: "/branches/:branchSlug/:nodeSlug/*", element: React.createElement(ProjectNode, Object.assign({}, props)) }),
|
441
|
+
React.createElement(Route, { path: "/:nodeSlug/*", element: React.createElement(ProjectNode, Object.assign({}, props)) }),
|
442
|
+
React.createElement(Route, { element: React.createElement(ProjectNode, Object.assign({}, props)) }))));
|
443
|
+
if (!outerRouter) {
|
444
|
+
return (React.createElement(DevPortalProvider, { platformUrl: platformUrl },
|
445
|
+
React.createElement(RouterTypeContext.Provider, { value: router },
|
446
|
+
React.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
|
447
|
+
React.createElement(InternalRoutes, null)))));
|
448
|
+
}
|
449
|
+
return (React.createElement(DevPortalProvider, { platformUrl: platformUrl },
|
450
|
+
React.createElement(RouterTypeContext.Provider, { value: router },
|
451
|
+
React.createElement(InternalRoutes, null))));
|
452
|
+
};
|
414
453
|
const StoplightProject = withStyles(StoplightProjectRouter);
|
415
454
|
|
416
|
-
const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
417
|
-
const queryParams = [];
|
418
|
-
let fetchedWorkspaceId = workspaceId || '';
|
419
|
-
if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
|
420
|
-
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
421
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
422
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
423
|
-
});
|
424
|
-
const data = yield response.json();
|
425
|
-
fetchedWorkspaceId = data.workspace.id;
|
426
|
-
}
|
427
|
-
if (projectIds && projectIds.length) {
|
428
|
-
queryParams.push(...projectIds.map((projectId, index) => {
|
429
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
430
|
-
return `project_ids[${index}]=${encodedProjectId}`;
|
431
|
-
}));
|
432
|
-
}
|
433
|
-
if (search) {
|
434
|
-
const encodedSearch = encodeURIComponent(search);
|
435
|
-
queryParams.push(`search=${encodedSearch}`);
|
436
|
-
}
|
437
|
-
if (branchSlug) {
|
438
|
-
const encodedBranchSlug = encodeURIComponent(branchSlug);
|
439
|
-
queryParams.push(`branch=${encodedBranchSlug}`);
|
440
|
-
}
|
441
|
-
const query = queryParams.length ? `?${queryParams.join('&')}` : '';
|
442
|
-
const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
|
443
|
-
const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
|
444
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
445
|
-
});
|
446
|
-
const data = yield response.json();
|
447
|
-
if (!response.ok) {
|
448
|
-
throw new Error(data);
|
449
|
-
}
|
450
|
-
return data;
|
455
|
+
const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
456
|
+
const queryParams = [];
|
457
|
+
let fetchedWorkspaceId = workspaceId || '';
|
458
|
+
if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
|
459
|
+
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
460
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
461
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
462
|
+
});
|
463
|
+
const data = yield response.json();
|
464
|
+
fetchedWorkspaceId = data.workspace.id;
|
465
|
+
}
|
466
|
+
if (projectIds && projectIds.length) {
|
467
|
+
queryParams.push(...projectIds.map((projectId, index) => {
|
468
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
469
|
+
return `project_ids[${index}]=${encodedProjectId}`;
|
470
|
+
}));
|
471
|
+
}
|
472
|
+
if (search) {
|
473
|
+
const encodedSearch = encodeURIComponent(search);
|
474
|
+
queryParams.push(`search=${encodedSearch}`);
|
475
|
+
}
|
476
|
+
if (branchSlug) {
|
477
|
+
const encodedBranchSlug = encodeURIComponent(branchSlug);
|
478
|
+
queryParams.push(`branch=${encodedBranchSlug}`);
|
479
|
+
}
|
480
|
+
const query = queryParams.length ? `?${queryParams.join('&')}` : '';
|
481
|
+
const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
|
482
|
+
const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
|
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;
|
451
490
|
});
|
452
491
|
|
453
|
-
const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
454
|
-
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
455
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
456
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
457
|
-
});
|
458
|
-
const data = yield response.json();
|
459
|
-
if (!response.ok) {
|
460
|
-
throw new Error(data);
|
461
|
-
}
|
462
|
-
return data;
|
492
|
+
const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
493
|
+
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
494
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
495
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
496
|
+
});
|
497
|
+
const data = yield response.json();
|
498
|
+
if (!response.ok) {
|
499
|
+
throw new Error(data);
|
500
|
+
}
|
501
|
+
return data;
|
463
502
|
});
|
464
503
|
|
465
504
|
/**
|
@@ -675,7 +714,7 @@ function useStateIgnoreCallback(initialState) {
|
|
675
714
|
return [state, setStateIgnoreCallback];
|
676
715
|
}
|
677
716
|
function useDebounce(value, delay, options) {
|
678
|
-
var eq =
|
717
|
+
var eq = valueEquality;
|
679
718
|
var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
|
680
719
|
var debounced = useDebouncedCallback(useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
|
681
720
|
var previousValue = useRef(value);
|
@@ -689,19 +728,19 @@ function useDebounce(value, delay, options) {
|
|
689
728
|
return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
|
690
729
|
}
|
691
730
|
|
692
|
-
function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
|
693
|
-
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
694
|
-
const [debounceSearch] = useDebounce(search, 500);
|
695
|
-
return useQuery([
|
696
|
-
...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
|
697
|
-
platformUrl,
|
698
|
-
isLoggedIn,
|
699
|
-
], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
|
731
|
+
function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
|
732
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
|
733
|
+
const [debounceSearch] = useDebounce(search, 500);
|
734
|
+
return useQuery([
|
735
|
+
...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
|
736
|
+
platformUrl,
|
737
|
+
isLoggedIn,
|
738
|
+
], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
|
700
739
|
}
|
701
740
|
|
702
|
-
function useGetWorkspace({ projectIds }) {
|
703
|
-
const { platformUrl, platformAuthToken } = React.useContext(PlatformContext);
|
704
|
-
return useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));
|
741
|
+
function useGetWorkspace({ projectIds }) {
|
742
|
+
const { platformUrl, platformAuthToken } = React.useContext(PlatformContext);
|
743
|
+
return useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));
|
705
744
|
}
|
706
745
|
|
707
746
|
export { BranchSelector, DevPortalProvider, NodeContent, ResponseError, Search, SearchResults, StoplightProject, TableOfContents, devPortalCacheKeys, getBranches, getNodeContent, getNodes, getTableOfContents, getWorkspace, useGetBranches, useGetNodeContent, useGetNodes, useGetTableOfContents, useGetWorkspace };
|