@jpmorganchase/elemental-dev-portal 2.9.2 → 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/BranchSelector/BranchSelector.spec.d.ts +2 -15
- package/components/DevPortalProvider/index.d.ts +1 -0
- package/components/NodeContent/NodeContent.d.ts +3 -2
- package/components/Search/SearchOverlay.d.ts +16 -0
- package/containers/StoplightProject.d.ts +2 -0
- package/handlers/getBranches.d.ts +2 -2
- package/hooks/useGetBranches.d.ts +1 -1
- package/index.esm.js +436 -382
- package/index.js +454 -407
- package/index.mjs +436 -382
- package/package.json +7 -7
- package/styles.min.css +1 -1
- package/types.d.ts +3 -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,197 +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);
|
37
|
-
|
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
|
-
label: branch.name || branch.slug,
|
54
|
-
value: branch.slug,
|
55
|
-
meta: branch.is_default ? 'Default' : undefined,
|
56
|
-
})),
|
57
|
-
},
|
58
|
-
] }));
|
59
|
-
};
|
60
|
-
|
61
|
-
const PlatformContext = React__namespace.createContext({ platformUrl: 'https://stoplight.io' });
|
62
|
-
const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthToken, children, }) => {
|
63
|
-
return React__namespace.createElement(PlatformContext.Provider, { value: { platformUrl, platformAuthToken } }, children);
|
64
|
-
};
|
65
|
-
const DevPortalProvider = elementalCore.withPersistenceBoundary(elementalCore.withQueryClientProvider(elementalCore.withMosaicProvider(PlatformProvider)));
|
29
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
66
30
|
|
67
|
-
const
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
: undefined, tryItCredentialsPolicy: tryItCredentialsPolicy, nodeHasChanged: nodeHasChanged, nodeUnsupported: nodeUnsupported })))));
|
89
|
-
};
|
90
|
-
const NodeLinkContext = React__namespace.createContext(undefined);
|
91
|
-
const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
|
92
|
-
const LinkComponent = ({ children, href, title }) => {
|
93
|
-
const ctx = React__namespace.useContext(NodeLinkContext);
|
94
|
-
if (href && externalRegex.test(href)) {
|
95
|
-
return (React__namespace.createElement("a", { href: href, target: "_blank", rel: "noreferrer", title: title ? title : undefined }, children));
|
96
|
-
}
|
97
|
-
if (href && ctx) {
|
98
|
-
const [node, Link] = ctx;
|
99
|
-
const { fileUri } = getNodeUriParts(node.uri);
|
100
|
-
const { fileUri: hrefFileUri } = getNodeUriParts(href);
|
101
|
-
let resolvedUri;
|
102
|
-
if (hrefFileUri) {
|
103
|
-
resolvedUri = path.resolve(path.dirname(fileUri), href);
|
104
|
-
}
|
105
|
-
else {
|
106
|
-
resolvedUri = path.resolve(fileUri, href);
|
107
|
-
}
|
108
|
-
const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
|
109
|
-
const decodedUrl = decodeURIComponent(href);
|
110
|
-
const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
|
111
|
-
const edge = node.outbound_edges.find(edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor);
|
112
|
-
if (edge) {
|
113
|
-
return React__namespace.createElement(Link, { to: `${edge.slug}${hash ? `#${hash}` : ''}` }, children);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
return React__namespace.createElement("a", { href: href }, children);
|
117
|
-
};
|
118
|
-
function getBundledUrl(url) {
|
119
|
-
if (url === undefined)
|
120
|
-
return undefined;
|
121
|
-
const bundledUrl = new URL(url);
|
122
|
-
const searchParams = new URLSearchParams(bundledUrl.search);
|
123
|
-
searchParams.append('deref', 'optimizedBundle');
|
124
|
-
bundledUrl.search = searchParams.toString();
|
125
|
-
return bundledUrl.toString();
|
126
|
-
}
|
127
|
-
const getNodeUriParts = (uri) => {
|
128
|
-
const parts = uri.split(/(\.yaml|\.yml|\.json|\.md)/);
|
129
|
-
if (parts.length === 1) {
|
130
|
-
return { fileUri: '', pointer: parts[0] || '' };
|
131
|
-
}
|
132
|
-
const fileUri = `${parts[0] || ''}${parts[1] || ''}`;
|
133
|
-
return { fileUri, pointer: parts[2] || '' };
|
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
|
+
] }));
|
134
52
|
};
|
135
53
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
* Copyright 2022 Fonticons, Inc.
|
140
|
-
*/
|
141
|
-
var faCircleNotch = {
|
142
|
-
prefix: 'fas',
|
143
|
-
iconName: 'circle-notch',
|
144
|
-
icon: [512, 512, [], "f1ce", "M222.7 32.15C227.7 49.08 218.1 66.9 201.1 71.94C121.8 95.55 64 169.1 64 255.1C64 362 149.1 447.1 256 447.1C362 447.1 448 362 448 255.1C448 169.1 390.2 95.55 310.9 71.94C293.9 66.9 284.3 49.08 289.3 32.15C294.4 15.21 312.2 5.562 329.1 10.6C434.9 42.07 512 139.1 512 255.1C512 397.4 397.4 511.1 256 511.1C114.6 511.1 0 397.4 0 255.1C0 139.1 77.15 42.07 182.9 10.6C199.8 5.562 217.6 15.21 222.7 32.15V32.15z"]
|
145
|
-
};
|
146
|
-
var faMagnifyingGlass = {
|
147
|
-
prefix: 'fas',
|
148
|
-
iconName: 'magnifying-glass',
|
149
|
-
icon: [512, 512, [128269, "search"], "f002", "M500.3 443.7l-119.7-119.7c27.22-40.41 40.65-90.9 33.46-144.7C401.8 87.79 326.8 13.32 235.2 1.723C99.01-15.51-15.51 99.01 1.724 235.2c11.6 91.64 86.08 166.7 177.6 178.9c53.8 7.189 104.3-6.236 144.7-33.46l119.7 119.7c15.62 15.62 40.95 15.62 56.57 0C515.9 484.7 515.9 459.3 500.3 443.7zM79.1 208c0-70.58 57.42-128 128-128s128 57.42 128 128c0 70.58-57.42 128-128 128S79.1 278.6 79.1 208z"]
|
150
|
-
};
|
151
|
-
var faSearch = faMagnifyingGlass;
|
152
|
-
var faSpinner = {
|
153
|
-
prefix: 'fas',
|
154
|
-
iconName: 'spinner',
|
155
|
-
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"]
|
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));
|
156
57
|
};
|
58
|
+
const DevPortalProvider = elementalCore.withPersistenceBoundary(elementalCore.withQueryClientProvider(elementalCore.withMosaicProvider(PlatformProvider)));
|
157
59
|
|
158
|
-
|
159
|
-
const listBoxRef = React__namespace.useRef(null);
|
160
|
-
const onChange = React__namespace.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
|
161
|
-
const onKeyDown = React__namespace.useCallback(e => {
|
162
|
-
var _a;
|
163
|
-
if (e.key === 'ArrowDown') {
|
164
|
-
e.preventDefault();
|
165
|
-
(_a = listBoxRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
166
|
-
}
|
167
|
-
}, []);
|
168
|
-
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 },
|
169
|
-
React__namespace.createElement(SearchResultsList, { searchResults: searchResults, onClick: onClick })));
|
170
|
-
};
|
171
|
-
const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = true, }) => {
|
172
|
-
const listBoxRef = React__namespace.useRef(null);
|
173
|
-
const onSelectionChange = React__namespace.useCallback(keys => {
|
174
|
-
const selectedId = keys.values().next().value;
|
175
|
-
const selectedResult = searchResults === null || searchResults === void 0 ? void 0 : searchResults.find(searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId);
|
176
|
-
if (selectedResult) {
|
177
|
-
onClick(selectedResult);
|
178
|
-
}
|
179
|
-
}, [searchResults, onClick]);
|
180
|
-
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) => {
|
181
|
-
var _a, _b;
|
182
|
-
return (React__namespace.createElement(mosaic.ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
|
183
|
-
React__namespace.createElement(mosaic.Box, { p: 3, borderB: !showDivider ? undefined : true },
|
184
|
-
React__namespace.createElement(mosaic.Flex, { align: "center" },
|
185
|
-
React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, w: 4, icon: elementalCore.NodeTypeIconDefs[searchResult.type], style: { color: elementalCore.NodeTypeColors[searchResult.type] } }),
|
186
|
-
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 }),
|
187
|
-
React__namespace.createElement(mosaic.Box, { fontSize: "sm", color: "muted" }, searchResult.project_name)),
|
188
|
-
React__namespace.createElement(mosaic.Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
|
189
|
-
})) : (React__namespace.createElement(mosaic.Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
|
190
|
-
};
|
191
|
-
const SearchResults = flow__default["default"](elementalCore.withStyles, elementalCore.withPersistenceBoundary, elementalCore.withMosaicProvider, elementalCore.withQueryClientProvider)(SearchResultsList);
|
192
|
-
const Search = flow__default["default"](elementalCore.withStyles, elementalCore.withPersistenceBoundary, elementalCore.withMosaicProvider, elementalCore.withQueryClientProvider)(SearchImpl);
|
193
|
-
|
194
|
-
/*! *****************************************************************************
|
60
|
+
/******************************************************************************
|
195
61
|
Copyright (c) Microsoft Corporation.
|
196
62
|
|
197
63
|
Permission to use, copy, modify, and/or distribute this software for any
|
@@ -205,6 +71,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
205
71
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
206
72
|
PERFORMANCE OF THIS SOFTWARE.
|
207
73
|
***************************************************************************** */
|
74
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
75
|
+
|
208
76
|
|
209
77
|
function __rest(s, e) {
|
210
78
|
var t = {};
|
@@ -226,252 +94,431 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
226
94
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
227
95
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
228
96
|
});
|
97
|
+
}
|
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();
|
229
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] || '' };
|
207
|
+
};
|
230
208
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
209
|
+
/*!
|
210
|
+
* Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com
|
211
|
+
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
212
|
+
* Copyright 2022 Fonticons, Inc.
|
213
|
+
*/
|
214
|
+
var faCircleNotch = {
|
215
|
+
prefix: 'fas',
|
216
|
+
iconName: 'circle-notch',
|
217
|
+
icon: [512, 512, [], "f1ce", "M222.7 32.15C227.7 49.08 218.1 66.9 201.1 71.94C121.8 95.55 64 169.1 64 255.1C64 362 149.1 447.1 256 447.1C362 447.1 448 362 448 255.1C448 169.1 390.2 95.55 310.9 71.94C293.9 66.9 284.3 49.08 289.3 32.15C294.4 15.21 312.2 5.562 329.1 10.6C434.9 42.07 512 139.1 512 255.1C512 397.4 397.4 511.1 256 511.1C114.6 511.1 0 397.4 0 255.1C0 139.1 77.15 42.07 182.9 10.6C199.8 5.562 217.6 15.21 222.7 32.15V32.15z"]
|
218
|
+
};
|
219
|
+
var faMagnifyingGlass = {
|
220
|
+
prefix: 'fas',
|
221
|
+
iconName: 'magnifying-glass',
|
222
|
+
icon: [512, 512, [128269, "search"], "f002", "M500.3 443.7l-119.7-119.7c27.22-40.41 40.65-90.9 33.46-144.7C401.8 87.79 326.8 13.32 235.2 1.723C99.01-15.51-15.51 99.01 1.724 235.2c11.6 91.64 86.08 166.7 177.6 178.9c53.8 7.189 104.3-6.236 144.7-33.46l119.7 119.7c15.62 15.62 40.95 15.62 56.57 0C515.9 484.7 515.9 459.3 500.3 443.7zM79.1 208c0-70.58 57.42-128 128-128s128 57.42 128 128c0 70.58-57.42 128-128 128S79.1 278.6 79.1 208z"]
|
223
|
+
};
|
224
|
+
var faSearch = faMagnifyingGlass;
|
225
|
+
var faSpinner = {
|
226
|
+
prefix: 'fas',
|
227
|
+
iconName: 'spinner',
|
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"]
|
237
229
|
};
|
238
230
|
|
239
|
-
const
|
240
|
-
const
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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" }))));
|
260
273
|
};
|
261
274
|
|
262
|
-
const
|
263
|
-
|
264
|
-
|
265
|
-
|
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
|
+
],
|
296
|
+
};
|
266
297
|
|
267
|
-
const
|
268
|
-
|
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"))));
|
269
302
|
|
270
|
-
const
|
271
|
-
|
272
|
-
React__default["default"].createElement(mosaic.Heading, { size: 1 }, "Not Found"),
|
273
|
-
React__default["default"].createElement(mosaic.Box, { as: "p" }, "Could not find what you are looking for"))));
|
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 })));
|
274
305
|
|
275
|
-
const
|
276
|
-
|
277
|
-
|
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"))));
|
278
310
|
|
279
|
-
const
|
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.")));
|
280
314
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
const
|
292
|
-
const
|
293
|
-
const
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
315
|
+
const appVersion = '2.11.1';
|
316
|
+
|
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;
|
309
345
|
});
|
310
346
|
|
311
|
-
const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
312
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
313
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/branches`, {
|
314
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
315
|
-
});
|
316
|
-
const data = yield response.json();
|
317
|
-
if (!response.ok) {
|
318
|
-
throw new Error(data);
|
319
|
-
}
|
320
|
-
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;
|
321
357
|
});
|
322
358
|
|
323
|
-
function useGetBranches({ projectId }) {
|
324
|
-
const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
|
325
|
-
return reactQuery.useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl,
|
326
|
-
enabled: projectId ? true : false,
|
327
|
-
});
|
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
|
+
});
|
328
364
|
}
|
329
365
|
|
330
|
-
function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
|
331
|
-
const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
|
332
|
-
return reactQuery.useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl,
|
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 });
|
333
369
|
}
|
334
370
|
|
335
|
-
const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
336
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
337
|
-
const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
|
338
|
-
const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
|
339
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
|
340
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
341
|
-
});
|
342
|
-
const data = yield response.json();
|
343
|
-
if (!response.ok) {
|
344
|
-
throw new Error(data);
|
345
|
-
}
|
346
|
-
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;
|
347
383
|
});
|
348
384
|
|
349
|
-
function useGetTableOfContents({ projectId, branchSlug }) {
|
350
|
-
const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
|
351
|
-
return reactQuery.useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl,
|
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 });
|
352
388
|
}
|
353
389
|
|
354
|
-
const StoplightProjectImpl = ({ projectId,
|
355
|
-
const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
|
356
|
-
const branchSlug = decodeURIComponent(encodedBranchSlug);
|
357
|
-
const
|
358
|
-
const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
|
359
|
-
const { data: branches } = useGetBranches({ projectId });
|
360
|
-
const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
|
361
|
-
nodeSlug,
|
362
|
-
projectId,
|
363
|
-
branchSlug,
|
364
|
-
});
|
365
|
-
const container = React__namespace.useRef(null);
|
366
|
-
if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
|
367
|
-
const firstNode = elementalCore.findFirstNode(tableOfContents.items);
|
368
|
-
if (firstNode) {
|
369
|
-
return React__namespace.createElement(reactRouterDom.
|
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
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
}
|
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
|
+
};
|
426
473
|
const StoplightProject = elementalCore.withStyles(StoplightProjectRouter);
|
427
474
|
|
428
|
-
const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
429
|
-
const queryParams = [];
|
430
|
-
let fetchedWorkspaceId = workspaceId || '';
|
431
|
-
if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
|
432
|
-
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
433
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
434
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
435
|
-
});
|
436
|
-
const data = yield response.json();
|
437
|
-
fetchedWorkspaceId = data.workspace.id;
|
438
|
-
}
|
439
|
-
if (projectIds && projectIds.length) {
|
440
|
-
queryParams.push(...projectIds.map((projectId, index) => {
|
441
|
-
const encodedProjectId = encodeURIComponent(projectId);
|
442
|
-
return `project_ids[${index}]=${encodedProjectId}`;
|
443
|
-
}));
|
444
|
-
}
|
445
|
-
if (search) {
|
446
|
-
const encodedSearch = encodeURIComponent(search);
|
447
|
-
queryParams.push(`search=${encodedSearch}`);
|
448
|
-
}
|
449
|
-
if (branchSlug) {
|
450
|
-
const encodedBranchSlug = encodeURIComponent(branchSlug);
|
451
|
-
queryParams.push(`branch=${encodedBranchSlug}`);
|
452
|
-
}
|
453
|
-
const query = queryParams.length ? `?${queryParams.join('&')}` : '';
|
454
|
-
const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
|
455
|
-
const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
|
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;
|
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;
|
463
510
|
});
|
464
511
|
|
465
|
-
const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
466
|
-
const encodedProjectId = encodeURIComponent(projectIds[0]);
|
467
|
-
const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
|
468
|
-
headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
|
469
|
-
});
|
470
|
-
const data = yield response.json();
|
471
|
-
if (!response.ok) {
|
472
|
-
throw new Error(data);
|
473
|
-
}
|
474
|
-
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;
|
475
522
|
});
|
476
523
|
|
477
524
|
/**
|
@@ -687,7 +734,7 @@ function useStateIgnoreCallback(initialState) {
|
|
687
734
|
return [state, setStateIgnoreCallback];
|
688
735
|
}
|
689
736
|
function useDebounce(value, delay, options) {
|
690
|
-
var eq =
|
737
|
+
var eq = valueEquality;
|
691
738
|
var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
|
692
739
|
var debounced = useDebouncedCallback(React.useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
|
693
740
|
var previousValue = React.useRef(value);
|
@@ -701,19 +748,19 @@ function useDebounce(value, delay, options) {
|
|
701
748
|
return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
|
702
749
|
}
|
703
750
|
|
704
|
-
function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
|
705
|
-
const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
|
706
|
-
const [debounceSearch] = useDebounce(search, 500);
|
707
|
-
return reactQuery.useQuery([
|
708
|
-
...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
|
709
|
-
platformUrl,
|
710
|
-
|
711
|
-
], () => 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 });
|
712
759
|
}
|
713
760
|
|
714
|
-
function useGetWorkspace({ projectIds }) {
|
715
|
-
const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
|
716
|
-
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 }));
|
717
764
|
}
|
718
765
|
|
719
766
|
exports.BranchSelector = BranchSelector;
|