@backstage/plugin-techdocs 1.10.1-next.1 → 1.10.1-next.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.
Files changed (23) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/alpha/package.json +1 -1
  3. package/dist/alpha.esm.js +4 -4
  4. package/dist/esm/{DocsCardGrid-66754d32.esm.js → DocsCardGrid-fbb00234.esm.js} +3 -3
  5. package/dist/esm/{DocsCardGrid-66754d32.esm.js.map → DocsCardGrid-fbb00234.esm.js.map} +1 -1
  6. package/dist/esm/{Router-79dfcddc.esm.js → Router-b8749e05.esm.js} +7 -7
  7. package/dist/esm/{Router-79dfcddc.esm.js.map → Router-b8749e05.esm.js.map} +1 -1
  8. package/dist/esm/{TechDocsCustomHome-114f3198.esm.js → TechDocsCustomHome-69a5491c.esm.js} +4 -4
  9. package/dist/esm/{TechDocsCustomHome-114f3198.esm.js.map → TechDocsCustomHome-69a5491c.esm.js.map} +1 -1
  10. package/dist/esm/{TechDocsIndexPage-a43a1a1c.esm.js → TechDocsIndexPage-e9cb1b46.esm.js} +2 -2
  11. package/dist/esm/{TechDocsIndexPage-a43a1a1c.esm.js.map → TechDocsIndexPage-e9cb1b46.esm.js.map} +1 -1
  12. package/dist/esm/{TechDocsReaderPage-b432d0c4.esm.js → TechDocsReaderPage-769fb741.esm.js} +85 -18
  13. package/dist/esm/TechDocsReaderPage-769fb741.esm.js.map +1 -0
  14. package/dist/esm/{index-233633bc.esm.js → index-82b70369.esm.js} +3 -3
  15. package/dist/esm/index-82b70369.esm.js.map +1 -0
  16. package/dist/esm/{routes-691e552c.esm.js → routes-100c0069.esm.js} +12 -1
  17. package/dist/esm/routes-100c0069.esm.js.map +1 -0
  18. package/dist/index.d.ts +3 -0
  19. package/dist/index.esm.js +6 -6
  20. package/package.json +12 -12
  21. package/dist/esm/TechDocsReaderPage-b432d0c4.esm.js.map +0 -1
  22. package/dist/esm/index-233633bc.esm.js.map +0 -1
  23. package/dist/esm/routes-691e552c.esm.js.map +0 -1
@@ -1,13 +1,13 @@
1
1
  import React, { useReducer, useRef, useMemo, createContext, useContext, useState, useEffect, useCallback, Children } from 'react';
2
2
  import { useParams, useNavigate, useLocation, useOutlet } from 'react-router-dom';
3
- import { LogViewer, ErrorPage, useSidebarPinState, Content, HeaderLabel, Header, Page } from '@backstage/core-components';
4
- import { techdocsStorageApiRef, useTechDocsReaderPage, SHADOW_DOM_STYLE_LOAD_EVENT, useShadowDomStylesLoading, useTechDocsAddons, TechDocsAddonLocations, useShadowRootElements, TechDocsShadowDom, TECHDOCS_ADDONS_WRAPPER_KEY, TECHDOCS_ADDONS_KEY, TechDocsReaderPageProvider } from '@backstage/plugin-techdocs-react';
3
+ import { LogViewer, ErrorPage, useSidebarPinState, Content, HeaderLabel, Header, ErrorPanel, Page } from '@backstage/core-components';
4
+ import { techdocsStorageApiRef, useTechDocsReaderPage, SHADOW_DOM_STYLE_LOAD_EVENT, useShadowDomStylesLoading, useTechDocsAddons, TechDocsAddonLocations, useShadowRootElements, TechDocsShadowDom, techdocsApiRef, TECHDOCS_ADDONS_WRAPPER_KEY, TECHDOCS_ADDONS_KEY, TechDocsReaderPageProvider } from '@backstage/plugin-techdocs-react';
5
5
  import { makeStyles, createStyles, Button, Drawer, Grid, Typography, IconButton, CircularProgress, lighten, alpha, useTheme, withStyles, Tooltip, ThemeProvider, SvgIcon, useMediaQuery, Portal, Toolbar, Box, Menu } from '@material-ui/core';
6
6
  import { SearchContextProvider, useSearch, SearchAutocomplete } from '@backstage/plugin-search-react';
7
7
  import { TechDocsSearchResultListItem } from './TechDocsSearchResultListItem-4736f829.esm.js';
8
8
  import { Alert, Skeleton } from '@material-ui/lab';
9
9
  import Close from '@material-ui/icons/Close';
10
- import { useApi, configApiRef, useAnalytics, useRouteRef, useRouteRefParams, getComponentData } from '@backstage/core-plugin-api';
10
+ import { useApi, configApiRef, useAnalytics, useRouteRef, useApp, useRouteRefParams, getComponentData } from '@backstage/core-plugin-api';
11
11
  import useAsync from 'react-use/lib/useAsync';
12
12
  import useAsyncRetry from 'react-use/lib/useAsyncRetry';
13
13
  import { scmIntegrationsApiRef } from '@backstage/integration-react';
@@ -24,7 +24,7 @@ import CodeIcon from '@material-ui/icons/Code';
24
24
  import { getEntityRelations, EntityRefLink, EntityRefLinks } from '@backstage/plugin-catalog-react';
25
25
  import { RELATION_OWNED_BY } from '@backstage/catalog-model';
26
26
  import { capitalize } from 'lodash';
27
- import { r as rootRouteRef, b as rootDocsRouteRef } from './routes-691e552c.esm.js';
27
+ import { r as rootRouteRef, b as rootDocsRouteRef } from './routes-100c0069.esm.js';
28
28
  import SettingsIcon from '@material-ui/icons/Settings';
29
29
 
30
30
  function calculateDisplayState({
@@ -1461,12 +1461,12 @@ const useTechDocsReaderDom = (entityRef) => {
1461
1461
  const { state, path, content: rawPage } = useTechDocsReader();
1462
1462
  const [dom, setDom] = useState(null);
1463
1463
  const isStyleLoading = useShadowDomStylesLoading(dom);
1464
- const updateSidebarPosition = useCallback(() => {
1464
+ const updateSidebarPositionAndHeight = useCallback(() => {
1465
1465
  if (!dom)
1466
1466
  return;
1467
1467
  const sidebars = dom.querySelectorAll(".md-sidebar");
1468
1468
  sidebars.forEach((element) => {
1469
- var _a, _b, _c;
1469
+ var _a, _b, _c, _d;
1470
1470
  if (isMobileMedia) {
1471
1471
  element.style.top = "0px";
1472
1472
  } else {
@@ -1478,19 +1478,27 @@ const useTechDocsReaderDom = (entityRef) => {
1478
1478
  if (domTop < pageTop) {
1479
1479
  domTop = pageTop;
1480
1480
  }
1481
- element.style.top = `${Math.max(domTop, 0) + tabsHeight}px`;
1481
+ const scrollbarTopPx = Math.max(domTop, 0) + tabsHeight;
1482
+ element.style.top = `${scrollbarTopPx}px`;
1483
+ const footer = dom.querySelector(".md-container > .md-footer");
1484
+ const scrollbarEndPx = (_d = footer == null ? void 0 : footer.getBoundingClientRect().top) != null ? _d : window.innerHeight;
1485
+ element.style.height = `${scrollbarEndPx - scrollbarTopPx}px`;
1482
1486
  }
1483
1487
  element.style.setProperty("opacity", "1");
1484
1488
  });
1485
1489
  }, [dom, isMobileMedia]);
1486
1490
  useEffect(() => {
1487
- window.addEventListener("resize", updateSidebarPosition);
1488
- window.addEventListener("scroll", updateSidebarPosition, true);
1491
+ window.addEventListener("resize", updateSidebarPositionAndHeight);
1492
+ window.addEventListener("scroll", updateSidebarPositionAndHeight, true);
1489
1493
  return () => {
1490
- window.removeEventListener("resize", updateSidebarPosition);
1491
- window.removeEventListener("scroll", updateSidebarPosition, true);
1494
+ window.removeEventListener("resize", updateSidebarPositionAndHeight);
1495
+ window.removeEventListener(
1496
+ "scroll",
1497
+ updateSidebarPositionAndHeight,
1498
+ true
1499
+ );
1492
1500
  };
1493
- }, [dom, updateSidebarPosition]);
1501
+ }, [dom, updateSidebarPositionAndHeight]);
1494
1502
  const updateFooterWidth = useCallback(() => {
1495
1503
  if (!dom)
1496
1504
  return;
@@ -1508,9 +1516,14 @@ const useTechDocsReaderDom = (entityRef) => {
1508
1516
  useEffect(() => {
1509
1517
  if (!isStyleLoading) {
1510
1518
  updateFooterWidth();
1511
- updateSidebarPosition();
1519
+ updateSidebarPositionAndHeight();
1512
1520
  }
1513
- }, [state, isStyleLoading, updateFooterWidth, updateSidebarPosition]);
1521
+ }, [
1522
+ state,
1523
+ isStyleLoading,
1524
+ updateFooterWidth,
1525
+ updateSidebarPositionAndHeight
1526
+ ]);
1514
1527
  const preRender = useCallback(
1515
1528
  (rawContent, contentPath) => transform(rawContent, [
1516
1529
  sanitizerTransformer,
@@ -1881,6 +1894,60 @@ const TechDocsReaderPageSubheader = (props) => {
1881
1894
  ));
1882
1895
  };
1883
1896
 
1897
+ function useTechDocsCookie() {
1898
+ const techdocsApi = useApi(techdocsApiRef);
1899
+ const { retry, ...state } = useAsyncRetry(async () => {
1900
+ return await techdocsApi.getCookie();
1901
+ }, [techdocsApi]);
1902
+ const refresh = useCallback(
1903
+ (expiresAt) => {
1904
+ const refreshingMargin = (1 + 3 * Math.random()) * 6e4;
1905
+ const delay = Date.parse(expiresAt) - Date.now() - refreshingMargin;
1906
+ const timeout = setTimeout(retry, delay);
1907
+ return () => clearTimeout(timeout);
1908
+ },
1909
+ [retry]
1910
+ );
1911
+ return { ...state, retry, refresh };
1912
+ }
1913
+ function TechDocsAuthProvider({ children }) {
1914
+ const app = useApp();
1915
+ const { Progress } = app.getComponents();
1916
+ const [channel] = useState(
1917
+ () => new BroadcastChannel("techdocs-cookie-refresh")
1918
+ );
1919
+ const { loading, error, value, retry, refresh } = useTechDocsCookie();
1920
+ useEffect(() => {
1921
+ if (!value)
1922
+ return () => {
1923
+ };
1924
+ channel.postMessage({
1925
+ action: "TECHDOCS_COOKIE_REFRESHED",
1926
+ payload: value
1927
+ });
1928
+ let cancel = refresh(value.expiresAt);
1929
+ const handleMessage = (event) => {
1930
+ const { action, payload } = event.data;
1931
+ if (action === "TECHDOCS_COOKIE_REFRESHED") {
1932
+ cancel();
1933
+ cancel = refresh(payload.expiresAt);
1934
+ }
1935
+ };
1936
+ channel.addEventListener("message", handleMessage);
1937
+ return () => {
1938
+ cancel();
1939
+ channel.removeEventListener("message", handleMessage);
1940
+ };
1941
+ }, [value, refresh, channel]);
1942
+ if (error) {
1943
+ return /* @__PURE__ */ React.createElement(ErrorPanel, { error }, /* @__PURE__ */ React.createElement(Button, { variant: "outlined", onClick: retry }, "Retry"));
1944
+ }
1945
+ if (loading) {
1946
+ return /* @__PURE__ */ React.createElement(Progress, null);
1947
+ }
1948
+ return children;
1949
+ }
1950
+
1884
1951
  const TechDocsReaderLayout = (props) => {
1885
1952
  const { withSearch, withHeader = true } = props;
1886
1953
  return /* @__PURE__ */ React.createElement(Page, { themeId: "documentation" }, withHeader && /* @__PURE__ */ React.createElement(TechDocsReaderPageHeader, null), /* @__PURE__ */ React.createElement(TechDocsReaderPageSubheader, null), /* @__PURE__ */ React.createElement(TechDocsReaderPageContent, { withSearch }));
@@ -1900,15 +1967,15 @@ const TechDocsReaderPage = (props) => {
1900
1967
  const page = grandChildren.find(
1901
1968
  (grandChild) => !getComponentData(grandChild, TECHDOCS_ADDONS_WRAPPER_KEY) && !getComponentData(grandChild, TECHDOCS_ADDONS_KEY)
1902
1969
  );
1903
- return /* @__PURE__ */ React.createElement(TechDocsReaderPageProvider, { entityRef }, page || /* @__PURE__ */ React.createElement(TechDocsReaderLayout, null));
1970
+ return /* @__PURE__ */ React.createElement(TechDocsAuthProvider, null, /* @__PURE__ */ React.createElement(TechDocsReaderPageProvider, { entityRef }, page || /* @__PURE__ */ React.createElement(TechDocsReaderLayout, null)));
1904
1971
  }
1905
- return /* @__PURE__ */ React.createElement(TechDocsReaderPageProvider, { entityRef }, ({ metadata, entityMetadata, onReady }) => /* @__PURE__ */ React.createElement("div", { className: "techdocs-reader-page" }, /* @__PURE__ */ React.createElement(Page, { themeId: "documentation" }, children instanceof Function ? children({
1972
+ return /* @__PURE__ */ React.createElement(TechDocsAuthProvider, null, /* @__PURE__ */ React.createElement(TechDocsReaderPageProvider, { entityRef }, ({ metadata, entityMetadata, onReady }) => /* @__PURE__ */ React.createElement("div", { className: "techdocs-reader-page" }, /* @__PURE__ */ React.createElement(Page, { themeId: "documentation" }, children instanceof Function ? children({
1906
1973
  entityRef,
1907
1974
  techdocsMetadataValue: metadata.value,
1908
1975
  entityMetadataValue: entityMetadata.value,
1909
1976
  onReady
1910
- }) : children)));
1977
+ }) : children))));
1911
1978
  };
1912
1979
 
1913
1980
  export { Reader as R, TechDocsReaderProvider as T, TechDocsReaderLayout as a, TechDocsReaderPageHeader as b, TechDocsReaderPageContent as c, TechDocsReaderPageSubheader as d, TechDocsSearch as e, TechDocsReaderPage as f };
1914
- //# sourceMappingURL=TechDocsReaderPage-b432d0c4.esm.js.map
1981
+ //# sourceMappingURL=TechDocsReaderPage-769fb741.esm.js.map