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