@jpmorganchase/elemental-dev-portal 2.10.1 → 2.12.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.js
CHANGED
@@ -1,70 +1,63 @@
|
|
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 elementalCore = require('@jpmorganchase/elemental-core');
|
8
6
|
var path = require('@stoplight/path');
|
9
7
|
var types = require('@stoplight/types');
|
10
|
-
var flow = require('lodash/flow.js');
|
11
8
|
var reactRouterDom = require('react-router-dom');
|
9
|
+
var flow = require('lodash/flow.js');
|
12
10
|
var reactQuery = require('react-query');
|
13
11
|
|
14
|
-
function
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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__*/
|
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 = elementalCore.withPersistenceBoundary(elementalCore.withQueryClientProvider(elementalCore.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, Iterator */
|
75
|
+
|
81
76
|
|
82
77
|
function __rest(s, e) {
|
83
78
|
var t = {};
|
@@ -99,89 +94,116 @@ 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(elementalCore.MarkdownComponentsProvider, { value: {
|
108
|
-
a: LinkComponent,
|
109
|
-
h2: (_a) => {
|
110
|
-
var props = __rest(_a, ["color"]);
|
111
|
-
return React__namespace.createElement(elementalCore.LinkHeading, Object.assign({ size: 2 }, props));
|
112
|
-
},
|
113
|
-
h3: (_a) => {
|
114
|
-
var props = __rest(_a, ["color"]);
|
115
|
-
return React__namespace.createElement(elementalCore.LinkHeading, Object.assign({ size: 3 }, props));
|
116
|
-
},
|
117
|
-
h4: (_a) => {
|
118
|
-
var props = __rest(_a, ["color"]);
|
119
|
-
return React__namespace.createElement(elementalCore.LinkHeading, Object.assign({ size: 4 }, props));
|
120
|
-
},
|
121
|
-
} },
|
122
|
-
React__namespace.createElement(elementalCore.MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
|
123
|
-
React__namespace.createElement(elementalCore.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
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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(elementalCore.MarkdownComponentsProvider, { value: {
|
108
|
+
a: LinkComponent,
|
109
|
+
h2: (_a) => {
|
110
|
+
var props = __rest(_a, ["color"]);
|
111
|
+
return React__namespace.createElement(elementalCore.LinkHeading, Object.assign({ size: 2 }, props));
|
112
|
+
},
|
113
|
+
h3: (_a) => {
|
114
|
+
var props = __rest(_a, ["color"]);
|
115
|
+
return React__namespace.createElement(elementalCore.LinkHeading, Object.assign({ size: 3 }, props));
|
116
|
+
},
|
117
|
+
h4: (_a) => {
|
118
|
+
var props = __rest(_a, ["color"]);
|
119
|
+
return React__namespace.createElement(elementalCore.LinkHeading, Object.assign({ size: 4 }, props));
|
120
|
+
},
|
121
|
+
} },
|
122
|
+
React__namespace.createElement(elementalCore.MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
|
123
|
+
React__namespace.createElement(elementalCore.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
|
+
const routerKind = React__namespace.useContext(elementalCore.RouterTypeContext);
|
149
|
+
const { pathname } = reactRouterDom.useLocation();
|
150
|
+
const route = pathname.split('#')[0];
|
151
|
+
try {
|
152
|
+
if (href && externalRegex.test(href)) {
|
153
|
+
const baseURL = window.location.host;
|
154
|
+
const hrefURL = new URL(href).host;
|
155
|
+
if (baseURL === hrefURL) {
|
156
|
+
return (React__namespace.createElement("a", { href: href, title: title ? title : undefined }, children));
|
157
|
+
}
|
158
|
+
return (React__namespace.createElement("a", { href: href, target: "_blank", rel: "noreferrer", title: title ? title : undefined }, children));
|
159
|
+
}
|
160
|
+
}
|
161
|
+
catch (error) {
|
162
|
+
console.error(error);
|
163
|
+
}
|
164
|
+
if (href && ctx) {
|
165
|
+
const [node, Link] = ctx;
|
166
|
+
const { fileUri } = getNodeUriParts(node.uri);
|
167
|
+
const { fileUri: hrefFileUri } = getNodeUriParts(href);
|
168
|
+
let resolvedUri;
|
169
|
+
if (hrefFileUri) {
|
170
|
+
resolvedUri = path.resolve(path.dirname(fileUri), href);
|
171
|
+
}
|
172
|
+
else {
|
173
|
+
resolvedUri = path.resolve(fileUri, href);
|
174
|
+
}
|
175
|
+
const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
|
176
|
+
const decodedUrl = decodeURIComponent(href);
|
177
|
+
const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
|
178
|
+
const [pagePathWithoutHash] = pathname.split('#');
|
179
|
+
let edge = node.outbound_edges.find(edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor);
|
180
|
+
if (!edge) {
|
181
|
+
edge = node.outbound_edges.find(edge => pagePathWithoutHash === `/${edge.slug}`);
|
182
|
+
}
|
183
|
+
if (edge) {
|
184
|
+
const slug = routerKind === 'hash' ? `#${route.replace(node.slug, edge.slug)}` : edge.slug;
|
185
|
+
return React__namespace.createElement(Link, { to: `${slug}${hash ? `#${hash}` : ''}` }, children);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
const fullHref = routerKind === 'hash' ? `#${route}${href}` : href;
|
189
|
+
return React__namespace.createElement("a", { href: fullHref }, children);
|
190
|
+
};
|
191
|
+
function getBundledUrl(url) {
|
192
|
+
if (url === undefined)
|
193
|
+
return undefined;
|
194
|
+
const bundledUrl = new URL(url);
|
195
|
+
const searchParams = new URLSearchParams(bundledUrl.search);
|
196
|
+
searchParams.append('deref', 'optimizedBundle');
|
197
|
+
bundledUrl.search = searchParams.toString();
|
198
|
+
return bundledUrl.toString();
|
199
|
+
}
|
200
|
+
const getNodeUriParts = (uri) => {
|
201
|
+
const parts = uri.split(/(\.yaml|\.yml|\.json|\.md)/);
|
202
|
+
if (parts.length === 1) {
|
203
|
+
return { fileUri: '', pointer: parts[0] || '' };
|
204
|
+
}
|
205
|
+
const fileUri = `${parts[0] || ''}${parts[1] || ''}`;
|
206
|
+
return { fileUri, pointer: parts[2] || '' };
|
185
207
|
};
|
186
208
|
|
187
209
|
/*!
|
@@ -206,287 +228,297 @@ var faSpinner = {
|
|
206
228
|
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
229
|
};
|
208
230
|
|
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: elementalCore.NodeTypeIconDefs[searchResult.type], style: { color: elementalCore.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 =
|
243
|
-
const Search =
|
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(elementalCore.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(elementalCore.PoweredByLink, { source: activeId, pathname: typeof window !== 'undefined' ? window.location.pathname : '', packageType: "elements-dev-portal" }))));
|
231
|
+
const SearchImpl = ({ isLoading, search, searchResults, isOpen, onClose, onClick, onSearch }) => {
|
232
|
+
const listBoxRef = React__namespace.useRef(null);
|
233
|
+
const onChange = React__namespace.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
|
234
|
+
const onKeyDown = React__namespace.useCallback(e => {
|
235
|
+
var _a;
|
236
|
+
if (e.key === 'ArrowDown') {
|
237
|
+
e.preventDefault();
|
238
|
+
(_a = listBoxRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
239
|
+
}
|
240
|
+
}, []);
|
241
|
+
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 },
|
242
|
+
React__namespace.createElement(SearchResultsList, { searchResults: searchResults, onClick: onClick })));
|
243
|
+
};
|
244
|
+
const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = true, }) => {
|
245
|
+
const listBoxRef = React__namespace.useRef(null);
|
246
|
+
const onSelectionChange = React__namespace.useCallback(keys => {
|
247
|
+
const selectedId = keys.values().next().value;
|
248
|
+
const selectedResult = searchResults === null || searchResults === void 0 ? void 0 : searchResults.find(searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId);
|
249
|
+
if (selectedResult) {
|
250
|
+
onClick(selectedResult);
|
251
|
+
}
|
252
|
+
}, [searchResults, onClick]);
|
253
|
+
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) => {
|
254
|
+
var _a, _b;
|
255
|
+
return (React__namespace.createElement(mosaic.ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
|
256
|
+
React__namespace.createElement(mosaic.Box, { p: 3, borderB: !showDivider ? undefined : true },
|
257
|
+
React__namespace.createElement(mosaic.Flex, { align: "center" },
|
258
|
+
React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, w: 4, icon: elementalCore.NodeTypeIconDefs[searchResult.type], style: { color: elementalCore.NodeTypeColors[searchResult.type] } }),
|
259
|
+
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 }),
|
260
|
+
React__namespace.createElement(mosaic.Box, { fontSize: "sm", color: "muted" }, searchResult.project_name)),
|
261
|
+
React__namespace.createElement(mosaic.Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
|
262
|
+
})) : (React__namespace.createElement(mosaic.Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
|
263
|
+
};
|
264
|
+
const SearchResults = flow(elementalCore.withStyles, elementalCore.withPersistenceBoundary, elementalCore.withMosaicProvider, elementalCore.withQueryClientProvider)(SearchResultsList);
|
265
|
+
const Search = flow(elementalCore.withStyles, elementalCore.withPersistenceBoundary, elementalCore.withMosaicProvider, elementalCore.withQueryClientProvider)(SearchImpl);
|
266
|
+
|
267
|
+
const TableOfContents = (_a) => {
|
268
|
+
var { tableOfContents, activeId, Link, collapseTableOfContents = false, externalScrollbar, isInResponsiveMode = false, onLinkClick } = _a, boxProps = __rest(_a, ["tableOfContents", "activeId", "Link", "collapseTableOfContents", "externalScrollbar", "isInResponsiveMode", "onLinkClick"]);
|
269
|
+
return (React__namespace.createElement(mosaic.Flex, Object.assign({ bg: isInResponsiveMode ? 'canvas' : 'canvas-100' }, boxProps, { flexDirection: "col", maxH: "full" }),
|
270
|
+
React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto" },
|
271
|
+
React__namespace.createElement(elementalCore.TableOfContents, { tree: tableOfContents.items, activeId: activeId, Link: Link, maxDepthOpenByDefault: collapseTableOfContents ? 0 : 1, externalScrollbar: externalScrollbar, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode })),
|
272
|
+
tableOfContents.hide_powered_by ? null : (React__namespace.createElement(elementalCore.PoweredByLink, { source: activeId, pathname: typeof window !== 'undefined' ? window.location.pathname : '', packageType: "elements-dev-portal" }))));
|
251
273
|
};
|
252
274
|
|
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
|
-
],
|
275
|
+
const ROOT_CACHE_KEY = '@stoplight/elements-dev-portal/client-query';
|
276
|
+
const devPortalCacheKeys = {
|
277
|
+
all: [ROOT_CACHE_KEY],
|
278
|
+
projects: () => [ROOT_CACHE_KEY, 'projects'],
|
279
|
+
project: (projectId) => [...devPortalCacheKeys.projects(), projectId],
|
280
|
+
projectsList: () => [...devPortalCacheKeys.projects(), 'list'],
|
281
|
+
projectDetails: (projectId) => [...devPortalCacheKeys.project(projectId), 'details'],
|
282
|
+
branches: (projectId) => [...devPortalCacheKeys.project(projectId), 'branches'],
|
283
|
+
branch: (projectId, branch) => [...devPortalCacheKeys.branches(projectId), branch],
|
284
|
+
branchesList: (projectId) => [...devPortalCacheKeys.branches(projectId), 'list'],
|
285
|
+
branchDetails: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'details'],
|
286
|
+
branchTOC: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'toc'],
|
287
|
+
branchNodes: (projectId, branch) => [...devPortalCacheKeys.branch(projectId, branch), 'nodes'],
|
288
|
+
branchNode: (projectId, branch, node) => [...devPortalCacheKeys.branchNodes(projectId, branch), node],
|
289
|
+
branchNodesList: (projectId, branch) => [...devPortalCacheKeys.branchNodes(projectId, branch), 'list'],
|
290
|
+
branchNodeDetails: (projectId, branch, node) => [...devPortalCacheKeys.branchNode(projectId, branch, node), 'details'],
|
291
|
+
search: () => [...devPortalCacheKeys.all, 'search'],
|
292
|
+
searchNodes: (filters) => [
|
293
|
+
...devPortalCacheKeys.search(),
|
294
|
+
filters,
|
295
|
+
],
|
274
296
|
};
|
275
297
|
|
276
|
-
const Forbidden = () => (
|
277
|
-
|
278
|
-
|
279
|
-
|
298
|
+
const Forbidden = () => (React.createElement(mosaic.Flex, { align: "center", justify: "center", flexGrow: true },
|
299
|
+
React.createElement(mosaic.VStack, { spacing: 4, align: "center" },
|
300
|
+
React.createElement(mosaic.Heading, { size: 1 }, "Forbidden"),
|
301
|
+
React.createElement(mosaic.Box, { as: "p" }, "You don't have permission to access this resource"))));
|
280
302
|
|
281
|
-
const Loading = () => (
|
282
|
-
|
303
|
+
const Loading = () => (React.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted" },
|
304
|
+
React.createElement(mosaic.Icon, { icon: faCircleNotch, size: "3x", spin: true })));
|
283
305
|
|
284
|
-
const NotFound = () => (
|
285
|
-
|
286
|
-
|
287
|
-
|
306
|
+
const NotFound = () => (React.createElement(mosaic.Flex, { align: "center", justify: "center", flexGrow: true },
|
307
|
+
React.createElement(mosaic.VStack, { spacing: 4, align: "center" },
|
308
|
+
React.createElement(mosaic.Heading, { size: 1 }, "Not Found"),
|
309
|
+
React.createElement(mosaic.Box, { as: "p" }, "Could not find what you are looking for"))));
|
288
310
|
|
289
|
-
const UpgradeToStarter = () => (
|
290
|
-
|
291
|
-
|
311
|
+
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" },
|
312
|
+
React.createElement(mosaic.Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
|
313
|
+
React.createElement(mosaic.Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
|
292
314
|
|
293
|
-
const appVersion = '2.
|
315
|
+
const appVersion = '2.12.1';
|
294
316
|
|
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;
|
317
|
+
class ResponseError extends Error {
|
318
|
+
constructor(message, responseCode) {
|
319
|
+
super(message);
|
320
|
+
this.name = 'ResponseError';
|
321
|
+
this.code = responseCode;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
const getNodeContent = ({ nodeSlug, projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
325
|
+
const encodedNodeSlug = encodeURIComponent(nodeSlug);
|
326
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
327
|
+
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
328
|
+
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
329
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/nodes/${encodedNodeSlug}${branchQuery}`, {
|
330
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
331
|
+
});
|
332
|
+
const data = yield response.json();
|
333
|
+
if (!response.ok) {
|
334
|
+
if (response.status === 402) {
|
335
|
+
throw new ResponseError('Payment Required', response.status);
|
336
|
+
}
|
337
|
+
else if (response.status === 403) {
|
338
|
+
throw new ResponseError('Forbidden', response.status);
|
339
|
+
}
|
340
|
+
else {
|
341
|
+
throw new ResponseError('Something went wrong', response.status);
|
342
|
+
}
|
343
|
+
}
|
344
|
+
return data;
|
323
345
|
});
|
324
346
|
|
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;
|
347
|
+
const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
348
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
349
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/branches`, {
|
350
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
351
|
+
});
|
352
|
+
const data = yield response.json();
|
353
|
+
if (!response.ok) {
|
354
|
+
throw new Error(data);
|
355
|
+
}
|
356
|
+
return data;
|
335
357
|
});
|
336
358
|
|
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
|
-
});
|
359
|
+
function useGetBranches({ projectId }) {
|
360
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
|
361
|
+
return reactQuery.useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
|
362
|
+
enabled: projectId ? true : false,
|
363
|
+
});
|
342
364
|
}
|
343
365
|
|
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 });
|
366
|
+
function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
|
367
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
|
368
|
+
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
369
|
}
|
348
370
|
|
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;
|
371
|
+
const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
372
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
373
|
+
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
374
|
+
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
375
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
|
376
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
377
|
+
});
|
378
|
+
const data = yield response.json();
|
379
|
+
if (!response.ok) {
|
380
|
+
throw new Error(data);
|
381
|
+
}
|
382
|
+
return data;
|
361
383
|
});
|
362
384
|
|
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 });
|
385
|
+
function useGetTableOfContents({ projectId, branchSlug }) {
|
386
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
|
387
|
+
return reactQuery.useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, isLoggedIn], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
|
366
388
|
}
|
367
389
|
|
368
|
-
const StoplightProjectImpl = ({ projectId,
|
369
|
-
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
|
370
|
-
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
371
|
-
const
|
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 = elementalCore.findFirstNode(tableOfContents.items);
|
382
|
-
if (firstNode) {
|
383
|
-
return React__namespace.createElement(reactRouterDom.
|
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
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
};
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
};
|
390
|
+
const StoplightProjectImpl = ({ projectId, collapseTableOfContents = false }) => {
|
391
|
+
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
|
392
|
+
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
393
|
+
const navigate = reactRouterDom.useNavigate();
|
394
|
+
const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
|
395
|
+
const { data: branches } = useGetBranches({ projectId });
|
396
|
+
const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
|
397
|
+
nodeSlug,
|
398
|
+
projectId,
|
399
|
+
branchSlug,
|
400
|
+
});
|
401
|
+
const container = React__namespace.useRef(null);
|
402
|
+
if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
|
403
|
+
const firstNode = elementalCore.findFirstNode(tableOfContents.items);
|
404
|
+
if (firstNode) {
|
405
|
+
return React__namespace.createElement(reactRouterDom.Navigate, { to: branchSlug ? `branches/${branchSlug}/${firstNode.slug}` : `${firstNode.slug}`, replace: true });
|
406
|
+
}
|
407
|
+
}
|
408
|
+
const handleTocClick = () => {
|
409
|
+
if (container.current) {
|
410
|
+
container.current.scrollIntoView();
|
411
|
+
}
|
412
|
+
};
|
413
|
+
return (React__namespace.createElement(elementalCore.SidebarLayout, { ref: container, sidebar: React__namespace.createElement(React__namespace.Fragment, null,
|
414
|
+
branches && branches.items.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches.items, onChange: branch => {
|
415
|
+
const encodedBranchSlug = encodeURIComponent(branch.slug);
|
416
|
+
navigate(branch.is_default ? `${nodeSlug}` : `branches/${encodedBranchSlug}/${nodeSlug}`);
|
417
|
+
} })) : null,
|
418
|
+
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) },
|
419
|
+
React__namespace.createElement(reactRouterDom.Outlet, { context: [isLoadingNode, isTocFetched, isError, nodeError, node] })));
|
420
|
+
};
|
421
|
+
const ProjectNode = ({ hideTryIt, hideSecurityInfo, hideServerInfo, hideMocking, hideExport, tryItCredentialsPolicy, tryItCorsProxy, }) => {
|
422
|
+
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
|
423
|
+
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
424
|
+
const [isLoadingNode, isTocFetched, isError, nodeError, node] = reactRouterDom.useOutletContext();
|
425
|
+
if (isLoadingNode || !isTocFetched) {
|
426
|
+
return React__namespace.createElement(Loading, null);
|
427
|
+
}
|
428
|
+
if (isError) {
|
429
|
+
if (nodeError instanceof ResponseError) {
|
430
|
+
if (nodeError.code === 402) {
|
431
|
+
return React__namespace.createElement(UpgradeToStarter, null);
|
432
|
+
}
|
433
|
+
else if (nodeError.code === 403) {
|
434
|
+
return React__namespace.createElement(Forbidden, null);
|
435
|
+
}
|
436
|
+
else {
|
437
|
+
return React__namespace.createElement(NotFound, null);
|
438
|
+
}
|
439
|
+
}
|
440
|
+
else {
|
441
|
+
return React__namespace.createElement(NotFound, null);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
if (!node) {
|
445
|
+
return React__namespace.createElement(NotFound, null);
|
446
|
+
}
|
447
|
+
if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
|
448
|
+
return React__namespace.createElement(reactRouterDom.Navigate, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}`, replace: true });
|
449
|
+
}
|
450
|
+
return (React__namespace.createElement(React__namespace.Fragment, null,
|
451
|
+
React__namespace.createElement(elementalCore.ScrollToHashElement, null),
|
452
|
+
React__namespace.createElement(NodeContent, { node: node, Link: elementalCore.ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, hideSecurityInfo: hideSecurityInfo, hideServerInfo: hideServerInfo, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })));
|
453
|
+
};
|
454
|
+
const StoplightProjectRouter = (_a) => {
|
455
|
+
var { platformUrl, basePath = '/', staticRouterPath = '', router = 'hash' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
|
456
|
+
const { Router, routerProps } = elementalCore.useRouter(router, basePath, staticRouterPath);
|
457
|
+
const outerRouter = reactRouterDom.useInRouterContext();
|
458
|
+
const InternalRoutes = () => (React__namespace.createElement(reactRouterDom.Routes, null,
|
459
|
+
React__namespace.createElement(reactRouterDom.Route, { path: "/", element: React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props)) },
|
460
|
+
React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug/*", element: React__namespace.createElement(ProjectNode, Object.assign({}, props)) }),
|
461
|
+
React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug/*", element: React__namespace.createElement(ProjectNode, Object.assign({}, props)) }),
|
462
|
+
React__namespace.createElement(reactRouterDom.Route, { element: React__namespace.createElement(ProjectNode, Object.assign({}, props)) }))));
|
463
|
+
if (!outerRouter) {
|
464
|
+
return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
|
465
|
+
React__namespace.createElement(elementalCore.RouterTypeContext.Provider, { value: router },
|
466
|
+
React__namespace.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
|
467
|
+
React__namespace.createElement(InternalRoutes, null)))));
|
468
|
+
}
|
469
|
+
return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
|
470
|
+
React__namespace.createElement(elementalCore.RouterTypeContext.Provider, { value: router },
|
471
|
+
React__namespace.createElement(InternalRoutes, null))));
|
472
|
+
};
|
441
473
|
const StoplightProject = elementalCore.withStyles(StoplightProjectRouter);
|
442
474
|
|
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;
|
475
|
+
const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
476
|
+
const queryParams = [];
|
477
|
+
let fetchedWorkspaceId = workspaceId || '';
|
478
|
+
if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
|
479
|
+
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
480
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
481
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
482
|
+
});
|
483
|
+
const data = yield response.json();
|
484
|
+
fetchedWorkspaceId = data.workspace.id;
|
485
|
+
}
|
486
|
+
if (projectIds && projectIds.length) {
|
487
|
+
queryParams.push(...projectIds.map((projectId, index) => {
|
488
|
+
const encodedProjectId = encodeURIComponent(projectId);
|
489
|
+
return `project_ids[${index}]=${encodedProjectId}`;
|
490
|
+
}));
|
491
|
+
}
|
492
|
+
if (search) {
|
493
|
+
const encodedSearch = encodeURIComponent(search);
|
494
|
+
queryParams.push(`search=${encodedSearch}`);
|
495
|
+
}
|
496
|
+
if (branchSlug) {
|
497
|
+
const encodedBranchSlug = encodeURIComponent(branchSlug);
|
498
|
+
queryParams.push(`branch=${encodedBranchSlug}`);
|
499
|
+
}
|
500
|
+
const query = queryParams.length ? `?${queryParams.join('&')}` : '';
|
501
|
+
const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
|
502
|
+
const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
|
503
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
504
|
+
});
|
505
|
+
const data = yield response.json();
|
506
|
+
if (!response.ok) {
|
507
|
+
throw new Error(data);
|
508
|
+
}
|
509
|
+
return data;
|
478
510
|
});
|
479
511
|
|
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;
|
512
|
+
const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
513
|
+
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
514
|
+
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
515
|
+
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
516
|
+
});
|
517
|
+
const data = yield response.json();
|
518
|
+
if (!response.ok) {
|
519
|
+
throw new Error(data);
|
520
|
+
}
|
521
|
+
return data;
|
490
522
|
});
|
491
523
|
|
492
524
|
/**
|
@@ -702,7 +734,7 @@ function useStateIgnoreCallback(initialState) {
|
|
702
734
|
return [state, setStateIgnoreCallback];
|
703
735
|
}
|
704
736
|
function useDebounce(value, delay, options) {
|
705
|
-
var eq =
|
737
|
+
var eq = valueEquality;
|
706
738
|
var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
|
707
739
|
var debounced = useDebouncedCallback(React.useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
|
708
740
|
var previousValue = React.useRef(value);
|
@@ -716,19 +748,19 @@ function useDebounce(value, delay, options) {
|
|
716
748
|
return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
|
717
749
|
}
|
718
750
|
|
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 });
|
751
|
+
function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
|
752
|
+
const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
|
753
|
+
const [debounceSearch] = useDebounce(search, 500);
|
754
|
+
return reactQuery.useQuery([
|
755
|
+
...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
|
756
|
+
platformUrl,
|
757
|
+
isLoggedIn,
|
758
|
+
], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
|
727
759
|
}
|
728
760
|
|
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 }));
|
761
|
+
function useGetWorkspace({ projectIds }) {
|
762
|
+
const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
|
763
|
+
return reactQuery.useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));
|
732
764
|
}
|
733
765
|
|
734
766
|
exports.BranchSelector = BranchSelector;
|