@stoplight/elements-dev-portal 2.1.1 → 2.1.3

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
@@ -59,8 +59,8 @@ const BranchSelector = ({ branchSlug, branches, onChange }) => {
59
59
  };
60
60
 
61
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);
62
+ const PlatformProvider = ({ platformUrl = 'https://stoplight.io', platformAuthToken, isLoggedIn, children, }) => {
63
+ return (React__namespace.createElement(PlatformContext.Provider, { value: { platformUrl, platformAuthToken, isLoggedIn } }, children));
64
64
  };
65
65
  const DevPortalProvider = elementsCore.withPersistenceBoundary(elementsCore.withQueryClientProvider(elementsCore.withMosaicProvider(PlatformProvider)));
66
66
 
@@ -286,29 +286,11 @@ const NotFound = () => (React__default["default"].createElement(mosaic.Flex, { a
286
286
  React__default["default"].createElement(mosaic.Heading, { size: 1 }, "Not Found"),
287
287
  React__default["default"].createElement(mosaic.Box, { as: "p" }, "Could not find what you are looking for"))));
288
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
-
307
289
  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" },
308
290
  React__default["default"].createElement(mosaic.Icon, { icon: ['fas', 'exclamation-triangle'], size: "4x" }),
309
291
  React__default["default"].createElement(mosaic.Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
310
292
 
311
- const appVersion = '2.1.1';
293
+ const appVersion = '2.1.3';
312
294
 
313
295
  class ResponseError extends Error {
314
296
  constructor(message, responseCode) {
@@ -353,17 +335,160 @@ const getBranches = ({ projectId, platformUrl = 'https://stoplight.io', platform
353
335
  });
354
336
 
355
337
  function useGetBranches({ projectId }) {
356
- const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
357
- return reactQuery.useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, platformAuthToken], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
338
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
339
+ return reactQuery.useQuery([...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn], () => getBranches({ projectId, platformUrl, platformAuthToken }), {
358
340
  enabled: projectId ? true : false,
359
341
  });
360
342
  }
361
343
 
362
344
  function useGetNodeContent({ nodeSlug, projectId, branchSlug, }) {
363
- const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
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 });
345
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
346
+ return reactQuery.useQuery([...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : '', nodeSlug), platformUrl, isLoggedIn], () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: nodeSlug && projectId ? true : false });
347
+ }
348
+
349
+ const getTableOfContents = ({ projectId, branchSlug, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
350
+ const encodedProjectId = encodeURIComponent(projectId);
351
+ const encodedBranchSlug = branchSlug ? encodeURIComponent(branchSlug) : '';
352
+ const branchQuery = encodedBranchSlug ? `?branch=${encodedBranchSlug}` : '';
353
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}/table-of-contents${branchQuery}`, {
354
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
355
+ });
356
+ const data = yield response.json();
357
+ if (!response.ok) {
358
+ throw new Error(data);
359
+ }
360
+ return data;
361
+ });
362
+
363
+ function useGetTableOfContents({ projectId, branchSlug }) {
364
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
365
+ return reactQuery.useQuery([...devPortalCacheKeys.branchTOC(projectId, branchSlug !== null && branchSlug !== void 0 ? branchSlug : ''), platformUrl, isLoggedIn], () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }), { enabled: projectId ? true : false });
365
366
  }
366
367
 
368
+ const StoplightProjectImpl = ({ projectId, hideTryIt, hideMocking, hideExport, collapseTableOfContents = false, tryItCredentialsPolicy, tryItCorsProxy, }) => {
369
+ const { branchSlug: encodedBranchSlug = '', nodeSlug = '' } = reactRouterDom.useParams();
370
+ const branchSlug = decodeURIComponent(encodedBranchSlug);
371
+ const history = reactRouterDom.useHistory();
372
+ const { data: tableOfContents, isFetched: isTocFetched } = useGetTableOfContents({ projectId, branchSlug });
373
+ const { data: branches } = useGetBranches({ projectId });
374
+ const { data: node, isLoading: isLoadingNode, isError, error: nodeError, } = useGetNodeContent({
375
+ nodeSlug,
376
+ projectId,
377
+ branchSlug,
378
+ });
379
+ const container = React__namespace.useRef(null);
380
+ if (!nodeSlug && isTocFetched && (tableOfContents === null || tableOfContents === void 0 ? void 0 : tableOfContents.items)) {
381
+ const firstNode = elementsCore.findFirstNode(tableOfContents.items);
382
+ if (firstNode) {
383
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${firstNode.slug}` : `/${firstNode.slug}` });
384
+ }
385
+ }
386
+ let elem;
387
+ if (isLoadingNode || !isTocFetched) {
388
+ elem = React__namespace.createElement(Loading, null);
389
+ }
390
+ else if (isError) {
391
+ if (nodeError instanceof ResponseError) {
392
+ if (nodeError.code === 402) {
393
+ elem = React__namespace.createElement(UpgradeToStarter, null);
394
+ }
395
+ else if (nodeError.code === 403) {
396
+ elem = React__namespace.createElement(Forbidden, null);
397
+ }
398
+ else {
399
+ elem = React__namespace.createElement(NotFound, null);
400
+ }
401
+ }
402
+ else {
403
+ elem = React__namespace.createElement(NotFound, null);
404
+ }
405
+ }
406
+ else if (!node) {
407
+ elem = React__namespace.createElement(NotFound, null);
408
+ }
409
+ else if ((node === null || node === void 0 ? void 0 : node.slug) && nodeSlug !== node.slug) {
410
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: branchSlug ? `/branches/${branchSlug}/${node.slug}` : `/${node.slug}` });
411
+ }
412
+ else {
413
+ elem = (React__namespace.createElement(NodeContent, { node: node, Link: elementsCore.ReactRouterMarkdownLink, hideTryIt: hideTryIt, hideMocking: hideMocking, hideExport: hideExport, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy }));
414
+ }
415
+ const handleTocClick = () => {
416
+ if (container.current) {
417
+ container.current.scrollIntoView();
418
+ }
419
+ };
420
+ return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: React__namespace.createElement(React__namespace.Fragment, null,
421
+ branches && branches.items.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches.items, onChange: branch => {
422
+ const encodedBranchSlug = encodeURIComponent(branch.slug);
423
+ history.push(branch.is_default ? `/${nodeSlug}` : `/branches/${encodedBranchSlug}/${nodeSlug}`);
424
+ } })) : null,
425
+ 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));
426
+ };
427
+ const StoplightProjectRouter = (_a) => {
428
+ var { platformUrl, basePath = '/', staticRouterPath = '', router = 'history' } = _a, props = __rest(_a, ["platformUrl", "basePath", "staticRouterPath", "router"]);
429
+ const { Router, routerProps } = elementsCore.useRouter(router, basePath, staticRouterPath);
430
+ return (React__namespace.createElement(DevPortalProvider, { platformUrl: platformUrl },
431
+ React__namespace.createElement(elementsCore.RouterTypeContext.Provider, { value: router },
432
+ React__namespace.createElement(Router, Object.assign({}, routerProps, { key: basePath }),
433
+ React__namespace.createElement(reactRouterDom.Switch, null,
434
+ React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug+", exact: true },
435
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
436
+ React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug+", exact: true },
437
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
438
+ React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
439
+ React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))))))));
440
+ };
441
+ const StoplightProject = elementsCore.withStyles(StoplightProjectRouter);
442
+
443
+ const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
444
+ const queryParams = [];
445
+ let fetchedWorkspaceId = workspaceId || '';
446
+ if (!workspaceId && (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length)) {
447
+ const encodedProjectId = encodeURIComponent(projectIds[0]);
448
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
449
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
450
+ });
451
+ const data = yield response.json();
452
+ fetchedWorkspaceId = data.workspace.id;
453
+ }
454
+ if (projectIds && projectIds.length) {
455
+ queryParams.push(...projectIds.map((projectId, index) => {
456
+ const encodedProjectId = encodeURIComponent(projectId);
457
+ return `project_ids[${index}]=${encodedProjectId}`;
458
+ }));
459
+ }
460
+ if (search) {
461
+ const encodedSearch = encodeURIComponent(search);
462
+ queryParams.push(`search=${encodedSearch}`);
463
+ }
464
+ if (branchSlug) {
465
+ const encodedBranchSlug = encodeURIComponent(branchSlug);
466
+ queryParams.push(`branch=${encodedBranchSlug}`);
467
+ }
468
+ const query = queryParams.length ? `?${queryParams.join('&')}` : '';
469
+ const encodedWorkspaceId = encodeURIComponent(fetchedWorkspaceId);
470
+ const response = yield fetch(`${platformUrl}/api/v1/workspaces/${encodedWorkspaceId}/nodes${query}`, {
471
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
472
+ });
473
+ const data = yield response.json();
474
+ if (!response.ok) {
475
+ throw new Error(data);
476
+ }
477
+ return data;
478
+ });
479
+
480
+ const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
481
+ const encodedProjectId = encodeURIComponent(projectIds[0]);
482
+ const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
483
+ headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
484
+ });
485
+ const data = yield response.json();
486
+ if (!response.ok) {
487
+ throw new Error(data);
488
+ }
489
+ return data;
490
+ });
491
+
367
492
  /**
368
493
  * Creates a debounced function that delays invoking `func` until after `wait`
369
494
  * milliseconds have elapsed since the last time the debounced function was
@@ -591,175 +716,16 @@ function useDebounce(value, delay, options) {
591
716
  return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
592
717
  }
593
718
 
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
-
631
719
  function useGetNodes({ search, workspaceId, projectIds, branch, pause, }) {
632
- const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
720
+ const { platformUrl, platformAuthToken, isLoggedIn } = React__namespace.useContext(PlatformContext);
633
721
  const [debounceSearch] = useDebounce(search, 500);
634
722
  return reactQuery.useQuery([
635
723
  ...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
636
724
  platformUrl,
637
- platformAuthToken,
725
+ isLoggedIn,
638
726
  ], () => getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause, keepPreviousData: true });
639
727
  }
640
728
 
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.items.length > 1 ? (React__namespace.createElement(BranchSelector, { branchSlug: branchSlug, branches: branches.items, 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.Switch, null,
742
- React__namespace.createElement(reactRouterDom.Route, { path: "/branches/:branchSlug/:nodeSlug+", exact: true },
743
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
744
- React__namespace.createElement(reactRouterDom.Route, { path: "/:nodeSlug+", exact: true },
745
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))),
746
- React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
747
- React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))))))));
748
- };
749
- const StoplightProject = elementsCore.withStyles(StoplightProjectRouter);
750
-
751
- const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
752
- const encodedProjectId = encodeURIComponent(projectIds[0]);
753
- const response = yield fetch(`${platformUrl}/api/v1/projects/${encodedProjectId}`, {
754
- headers: Object.assign({ 'Stoplight-Elements-Version': appVersion }, (platformAuthToken && { Authorization: `Bearer ${platformAuthToken}` })),
755
- });
756
- const data = yield response.json();
757
- if (!response.ok) {
758
- throw new Error(data);
759
- }
760
- return data;
761
- });
762
-
763
729
  function useGetWorkspace({ projectIds }) {
764
730
  const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
765
731
  return reactQuery.useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () => getWorkspace({ projectIds, platformUrl, platformAuthToken }));