@stoplight/elements-dev-portal 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -64,10 +64,61 @@ const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthTo
64
64
  };
65
65
  const DevPortalProvider = elementsCore.withPersistenceBoundary(elementsCore.withQueryClientProvider(elementsCore.withMosaicProvider(PlatformProvider)));
66
66
 
67
+ /*! *****************************************************************************
68
+ Copyright (c) Microsoft Corporation.
69
+
70
+ Permission to use, copy, modify, and/or distribute this software for any
71
+ purpose with or without fee is hereby granted.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
74
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
75
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
76
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
77
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
78
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
79
+ PERFORMANCE OF THIS SOFTWARE.
80
+ ***************************************************************************** */
81
+
82
+ function __rest(s, e) {
83
+ var t = {};
84
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
85
+ t[p] = s[p];
86
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
87
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
88
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
89
+ t[p[i]] = s[p[i]];
90
+ }
91
+ return t;
92
+ }
93
+
94
+ function __awaiter(thisArg, _arguments, P, generator) {
95
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
96
+ return new (P || (P = Promise))(function (resolve, reject) {
97
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
98
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
99
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
100
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
101
+ });
102
+ }
103
+
67
104
  const NodeContent = ({ node, Link, hideMocking, refResolver, maxRefDepth, tryItCorsProxy, tryItCredentialsPolicy, nodeHasChanged, nodeUnsupported, compact, hideTryIt, hideTryItPanel, hideExport, onExportRequest, }) => {
68
105
  var _a, _b, _c, _d;
69
106
  return (React__namespace.createElement(NodeLinkContext.Provider, { value: [node, Link] },
70
- React__namespace.createElement(elementsCore.MarkdownComponentsProvider, { value: { a: LinkComponent } },
107
+ React__namespace.createElement(elementsCore.MarkdownComponentsProvider, { value: {
108
+ a: LinkComponent,
109
+ h2: (_a) => {
110
+ var props = __rest(_a, ["color"]);
111
+ return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 2 }, props));
112
+ },
113
+ h3: (_a) => {
114
+ var props = __rest(_a, ["color"]);
115
+ return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 3 }, props));
116
+ },
117
+ h4: (_a) => {
118
+ var props = __rest(_a, ["color"]);
119
+ return React__namespace.createElement(elementsCore.LinkHeading, Object.assign({ size: 4 }, props));
120
+ },
121
+ } },
71
122
  React__namespace.createElement(elementsCore.MockingProvider, { mockUrl: node.links.mock_url, hideMocking: hideMocking },
72
123
  React__namespace.createElement(elementsCore.Docs, { nodeType: node.type, nodeData: node.data, nodeTitle: node.title, layoutOptions: {
73
124
  compact,
@@ -191,43 +242,6 @@ const SearchResultsList = ({ searchResults, onClick, isEmbedded, showDivider = t
191
242
  const SearchResults = flow__default["default"](elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchResultsList);
192
243
  const Search = flow__default["default"](elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchImpl);
193
244
 
194
- /*! *****************************************************************************
195
- Copyright (c) Microsoft Corporation.
196
-
197
- Permission to use, copy, modify, and/or distribute this software for any
198
- purpose with or without fee is hereby granted.
199
-
200
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
201
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
202
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
203
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
204
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
205
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
206
- PERFORMANCE OF THIS SOFTWARE.
207
- ***************************************************************************** */
208
-
209
- function __rest(s, e) {
210
- var t = {};
211
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
212
- t[p] = s[p];
213
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
214
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
215
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
216
- t[p[i]] = s[p[i]];
217
- }
218
- return t;
219
- }
220
-
221
- function __awaiter(thisArg, _arguments, P, generator) {
222
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
223
- return new (P || (P = Promise))(function (resolve, reject) {
224
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
225
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
226
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
227
- step((generator = generator.apply(thisArg, _arguments || [])).next());
228
- });
229
- }
230
-
231
245
  const TableOfContents = (_a) => {
232
246
  var { tableOfContents, activeId, Link, collapseTableOfContents = false, externalScrollbar, isInResponsiveMode = false, onLinkClick } = _a, boxProps = __rest(_a, ["tableOfContents", "activeId", "Link", "collapseTableOfContents", "externalScrollbar", "isInResponsiveMode", "onLinkClick"]);
233
247
  return (React__namespace.createElement(mosaic.Flex, Object.assign({ bg: isInResponsiveMode ? 'canvas' : 'canvas-100' }, boxProps, { flexDirection: "col", maxH: "full" }),
@@ -272,11 +286,29 @@ const NotFound = () => (React__default["default"].createElement(mosaic.Flex, { a
272
286
  React__default["default"].createElement(mosaic.Heading, { size: 1 }, "Not Found"),
273
287
  React__default["default"].createElement(mosaic.Box, { as: "p" }, "Could not find what you are looking for"))));
274
288
 
289
+ const SearchOverlay = ({ isFetching, search, setSearch, data, toc, nodeSlug, projectSlug, branchSlug, isSearchShowing, onClose, onClick, }) => {
290
+ return (React__namespace.createElement(mosaic.Modal, { isOpen: isSearchShowing, onClose: onClose },
291
+ React__namespace.createElement(mosaic.Box, { className: "sl-overlay", bg: "canvas", overflowY: "scroll", "data-test": "search-overlay" },
292
+ React__namespace.createElement(mosaic.Flex, { alignItems: "center", h: "3xl", px: 7, bg: "canvas", borderB: true, pos: "sticky", zIndex: 20 },
293
+ React__namespace.createElement(mosaic.Flex, { w: "full" },
294
+ React__namespace.createElement(mosaic.Box, { pt: 1, pr: 2 },
295
+ React__namespace.createElement(mosaic.Button, { appearance: "minimal", onClick: () => {
296
+ onClose();
297
+ }, "data-test": "search-overlay-back-button" },
298
+ React__namespace.createElement(mosaic.Icon, { icon: ['fas', 'arrow-left'], color: "gray", size: "lg" }))),
299
+ React__namespace.createElement(mosaic.Input, { border: true, "data-test": "docs-search-input", display: "inline-block", appearance: "minimal", icon: React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, ml: 1, icon: isFetching ? faSpinner : faSearch, spin: isFetching }), autoFocus: true, placeholder: projectSlug ? 'Search within the project' : 'Search...', value: search, onChange: e => {
300
+ setSearch(e.currentTarget.value);
301
+ }, type: "search", w: "full", size: "lg" }))),
302
+ React__namespace.createElement(mosaic.Box, { px: 5, py: toc && !search ? 0 : 5, "data-test": "responsive-project-toc" },
303
+ toc && !search && projectSlug && (React__namespace.createElement(TableOfContents, { tableOfContents: Object.assign(Object.assign({}, toc), { hide_powered_by: true }), activeId: nodeSlug || '', Link: reactRouterDom.Link, onLinkClick: onClick })),
304
+ search && (React__namespace.createElement(SearchResults, { searchResults: data, onClick: item => onClick(item), isEmbedded: true, showDivider: false }))))));
305
+ };
306
+
275
307
  const UpgradeToStarter = () => (React__default["default"].createElement(mosaic.Flex, { as: "a", href: "https://stoplight.io/pricing/", target: "_blank", rel: "noreferrer noopener", justify: "center", alignItems: "center", w: "full", minH: "screen", color: "muted", flexDirection: "col" },
276
308
  React__default["default"].createElement(mosaic.Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
277
309
  React__default["default"].createElement(mosaic.Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
278
310
 
279
- const appVersion = '2.0.0';
311
+ const appVersion = '2.0.2';
280
312
 
281
313
  class ResponseError extends Error {
282
314
  constructor(message, responseCode) {
@@ -332,148 +364,6 @@ function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
332
364
  return reactQuery.useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl, platformAuthToken], () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: nodeSlug && projectId ? true : false });
333
365
  }
334
366
 
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;
347
- });
348
-
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, platformAuthToken], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
352
- }
353
-
354
- const StoplightProjectImpl = ({ projectId, hideTryIt, hideMocking, hideExport, collapseTableOfContents = false, tryItCredentialsPolicy, tryItCorsProxy, }) => {
355
- const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
356
- const branchSlug = decodeURIComponent(encodedBranchSlug);
357
- const history = reactRouterDom.useHistory();
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 = elementsCore.findFirstNode(tableOfContents.items);
368
- if (firstNode) {
369
- return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${firstNode.slug}` : `/${firstNode.slug}` });
370
- }
371
- }
372
- let elem;
373
- if (isLoadingNode || !isTocFetched) {
374
- elem = React__namespace.createElement(Loading, null);
375
- }
376
- else if (isError) {
377
- if (nodeError instanceof ResponseError) {
378
- if (nodeError.code === 402) {
379
- elem = React__namespace.createElement(UpgradeToStarter, null);
380
- }
381
- else if (nodeError.code === 403) {
382
- elem = React__namespace.createElement(Forbidden, null);
383
- }
384
- else {
385
- elem = React__namespace.createElement(NotFound, null);
386
- }
387
- }
388
- else {
389
- elem = React__namespace.createElement(NotFound, null);
390
- }
391
- }
392
- else if (!node) {
393
- elem = React__namespace.createElement(NotFound, null);
394
- }
395
- else if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
396
- return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}` });
397
- }
398
- else {
399
- elem = (React__namespace.createElement(NodeContent, { node: node, Link: elementsCore.ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }));
400
- }
401
- const handleTocClick = () => {
402
- if (container.current) {
403
- container.current.scrollIntoView();
404
- }
405
- };
406
- return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: React__namespace.createElement(React__namespace.Fragment, null,
407
- branches && branches.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches, onChange: branch => {
408
- const encodedBranchSlug = encodeURIComponent(branch.slug);
409
- history.push(branch.is_default ? `/${nodeSlug}` : `/branches/${encodedBranchSlug}/${nodeSlug}`);
410
- } })) : null,
411
- tableOfContents ? (React__namespace.createElement(TableOfContents, { activeId: (node === null || node === void 0 ? void 0 : node.id) || (nodeSlug === null || nodeSlug === void 0 ? void 0 : nodeSlug.split('-')[0]) || '', tableOfContents: tableOfContents, Link: reactRouterDom.Link, collapseTableOfContents: collapseTableOfContents, onLinkClick: handleTocClick })) : null) }, elem));
412
- };
413
- const StoplightProjectRouter = (_a) => {
414
- var { platformUrl, basePath = '/', staticRouterPath = '', router = 'history' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
415
- const { Router, routerProps } = elementsCore.useRouter(router, basePath, staticRouterPath);
416
- return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
417
- React__namespace.createElement(elementsCore.RouterTypeContext.Provider, { value: router },
418
- React__namespace.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
419
- React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug+", exact: true },
420
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
421
- React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug+", exact: true },
422
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
423
- React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
424
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props)))))));
425
- };
426
- const StoplightProject = elementsCore.withStyles(StoplightProjectRouter);
427
-
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;
463
- });
464
-
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;
475
- });
476
-
477
367
  /**
478
368
  * Creates a debounced function that delays invoking `func` until after `wait`
479
369
  * milliseconds have elapsed since the last time the debounced function was
@@ -701,6 +591,43 @@ function useDebounce(value, delay, options) {
701
591
  return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
702
592
  }
703
593
 
594
+ const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
595
+ const queryParams = [];
596
+ let fetchedWorkspaceId = workspaceId || '';
597
+ if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
598
+ const encodedProjectId = encodeURIComponent(projectIds[0]);
599
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
600
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
601
+ });
602
+ const data = yield response.json();
603
+ fetchedWorkspaceId = data.workspace.id;
604
+ }
605
+ if (projectIds && projectIds.length) {
606
+ queryParams.push(...projectIds.map((projectId, index) => {
607
+ const encodedProjectId = encodeURIComponent(projectId);
608
+ return `project_ids[${index}]=${encodedProjectId}`;
609
+ }));
610
+ }
611
+ if (search) {
612
+ const encodedSearch = encodeURIComponent(search);
613
+ queryParams.push(`search=${encodedSearch}`);
614
+ }
615
+ if (branchSlug) {
616
+ const encodedBranchSlug = encodeURIComponent(branchSlug);
617
+ queryParams.push(`branch=${encodedBranchSlug}`);
618
+ }
619
+ const query = queryParams.length ? `?${queryParams.join('&')}` : '';
620
+ const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
621
+ const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
622
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
623
+ });
624
+ const data = yield response.json();
625
+ if (!response.ok) {
626
+ throw new Error(data);
627
+ }
628
+ return data;
629
+ });
630
+
704
631
  function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
705
632
  const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
706
633
  const [debounceSearch] = useDebounce(search, 500);
@@ -711,6 +638,127 @@ function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
711
638
  ], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
712
639
  }
713
640
 
641
+ const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
642
+ const encodedProjectId = encodeURIComponent(projectId);
643
+ const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
644
+ const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
645
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
646
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
647
+ });
648
+ const data = yield response.json();
649
+ if (!response.ok) {
650
+ throw new Error(data);
651
+ }
652
+ return data;
653
+ });
654
+
655
+ function useGetTableOfContents({ projectId, branchSlug }) {
656
+ const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
657
+ return reactQuery.useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, platformAuthToken], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
658
+ }
659
+
660
+ const StoplightProjectImpl = ({ projectId, hideTryIt, hideMocking, hideExport, collapseTableOfContents = false, tryItCredentialsPolicy, tryItCorsProxy, }) => {
661
+ const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
662
+ const branchSlug = decodeURIComponent(encodedBranchSlug);
663
+ const history = reactRouterDom.useHistory();
664
+ const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
665
+ const { data: branches } = useGetBranches({ projectId });
666
+ const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
667
+ nodeSlug,
668
+ projectId,
669
+ branchSlug,
670
+ });
671
+ const { isOpen, open, close } = mosaic.useModalState();
672
+ const [search, setSearch] = React__namespace.useState('');
673
+ const onSearchResultClick = (item) => {
674
+ close();
675
+ };
676
+ const { isResponsiveLayoutEnabled } = elementsCore.useResponsiveLayout();
677
+ const { data, isFetching } = useGetNodes({
678
+ search,
679
+ projectIds: [projectId],
680
+ pause: !isResponsiveLayoutEnabled,
681
+ });
682
+ const container = React__namespace.useRef(null);
683
+ if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
684
+ const firstNode = elementsCore.findFirstNode(tableOfContents.items);
685
+ if (firstNode) {
686
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${firstNode.slug}` : `/${firstNode.slug}` });
687
+ }
688
+ }
689
+ let elem;
690
+ if (isLoadingNode || !isTocFetched) {
691
+ elem = React__namespace.createElement(Loading, null);
692
+ }
693
+ else if (isError) {
694
+ if (nodeError instanceof ResponseError) {
695
+ if (nodeError.code === 402) {
696
+ elem = React__namespace.createElement(UpgradeToStarter, null);
697
+ }
698
+ else if (nodeError.code === 403) {
699
+ elem = React__namespace.createElement(Forbidden, null);
700
+ }
701
+ else {
702
+ elem = React__namespace.createElement(NotFound, null);
703
+ }
704
+ }
705
+ else {
706
+ elem = React__namespace.createElement(NotFound, null);
707
+ }
708
+ }
709
+ else if (!node) {
710
+ elem = React__namespace.createElement(NotFound, null);
711
+ }
712
+ else if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
713
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}` });
714
+ }
715
+ else {
716
+ elem = (React__namespace.createElement(React__namespace.Fragment, null,
717
+ React__namespace.createElement(mosaic.Button, { "data-test": "show-project-search-overlay", onPress: open, appearance: "default", w: "full", rounded: "lg", borderColor: "light" },
718
+ React__namespace.createElement(mosaic.Icon, { icon: faSearch }),
719
+ React__namespace.createElement(mosaic.Box, { pl: 2 }, node.title)),
720
+ React__namespace.createElement(SearchOverlay, { toc: tableOfContents, projectSlug: nodeSlug, branchSlug: branchSlug, nodeSlug: nodeSlug, isFetching: isFetching || !isTocFetched, search: search, setSearch: setSearch, data: data, isSearchShowing: isOpen, onClose: close, onClick: onSearchResultClick }),
721
+ React__namespace.createElement(NodeContent, { node: node, Link: elementsCore.ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy })));
722
+ }
723
+ const handleTocClick = () => {
724
+ if (container.current) {
725
+ container.current.scrollIntoView();
726
+ }
727
+ };
728
+ return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: React__namespace.createElement(React__namespace.Fragment, null,
729
+ branches && branches.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches, onChange: branch => {
730
+ const encodedBranchSlug = encodeURIComponent(branch.slug);
731
+ history.push(branch.is_default ? `/${nodeSlug}` : `/branches/${encodedBranchSlug}/${nodeSlug}`);
732
+ } })) : null,
733
+ tableOfContents ? (React__namespace.createElement(TableOfContents, { activeId: (node === null || node === void 0 ? void 0 : node.id) || (nodeSlug === null || nodeSlug === void 0 ? void 0 : nodeSlug.split('-')[0]) || '', tableOfContents: tableOfContents, Link: reactRouterDom.Link, collapseTableOfContents: collapseTableOfContents, onLinkClick: handleTocClick })) : null) }, elem));
734
+ };
735
+ const StoplightProjectRouter = (_a) => {
736
+ var { platformUrl, basePath = '/', staticRouterPath = '', router = 'history' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
737
+ const { Router, routerProps } = elementsCore.useRouter(router, basePath, staticRouterPath);
738
+ return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
739
+ React__namespace.createElement(elementsCore.RouterTypeContext.Provider, { value: router },
740
+ React__namespace.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
741
+ React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug+", exact: true },
742
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
743
+ React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug+", exact: true },
744
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
745
+ React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
746
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props)))))));
747
+ };
748
+ const StoplightProject = elementsCore.withStyles(StoplightProjectRouter);
749
+
750
+ const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
751
+ const encodedProjectId = encodeURIComponent(projectIds[0]);
752
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
753
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
754
+ });
755
+ const data = yield response.json();
756
+ if (!response.ok) {
757
+ throw new Error(data);
758
+ }
759
+ return data;
760
+ });
761
+
714
762
  function useGetWorkspace({ projectIds }) {
715
763
  const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
716
764
  return reactQuery.useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));