@backstage/core-components 0.18.2 → 0.18.3-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @backstage/core-components
2
2
 
3
+ ## 0.18.3-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b2bef92: Convert all enums to erasable-syntax compliant patterns
8
+ - Updated dependencies
9
+ - @backstage/core-plugin-api@1.11.2-next.1
10
+
11
+ ## 0.18.3-next.0
12
+
13
+ ### Patch Changes
14
+
15
+ - 05f60e1: Refactored constructor parameter properties to explicit property declarations for compatibility with TypeScript's `erasableSyntaxOnly` setting. This internal refactoring maintains all existing functionality while ensuring TypeScript compilation compatibility.
16
+ - Updated dependencies
17
+ - @backstage/core-plugin-api@1.11.2-next.0
18
+ - @backstage/config@1.3.6-next.0
19
+ - @backstage/errors@1.2.7
20
+ - @backstage/theme@0.7.0
21
+ - @backstage/version-bridge@1.0.11
22
+
3
23
  ## 0.18.2
4
24
 
5
25
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyGraph.esm.js","sources":["../../../src/components/DependencyGraph/DependencyGraph.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SVGProps,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport useMeasure from 'react-use/esm/useMeasure';\nimport classNames from 'classnames';\nimport { once } from 'lodash';\nimport * as d3Zoom from 'd3-zoom';\nimport * as d3Selection from 'd3-selection';\nimport useTheme from '@material-ui/core/styles/useTheme';\nimport dagre from '@dagrejs/dagre';\nimport debounce from 'lodash/debounce';\nimport { DependencyGraphTypes as Types } from './types';\nimport { Node } from './Node';\nimport { Edge, GraphEdge } from './Edge';\nimport { ARROW_MARKER_ID } from './constants';\nimport IconButton from '@material-ui/core/IconButton';\nimport FullscreenIcon from '@material-ui/icons/Fullscreen';\nimport FullscreenExitIcon from '@material-ui/icons/FullscreenExit';\nimport { FullScreen, useFullScreenHandle } from 'react-full-screen';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { coreComponentsTranslationRef } from '../../translation';\n\nconst useStyles = makeStyles((theme: Theme) => ({\n fullscreenButton: {\n position: 'absolute',\n right: 0,\n },\n root: {\n overflow: 'hidden',\n minHeight: '100%',\n minWidth: '100%',\n },\n fixedHeight: {\n maxHeight: '100%',\n },\n fullscreen: {\n backgroundColor: theme.palette.background.paper,\n },\n}));\n\n/**\n * Properties of {@link DependencyGraph}\n *\n * @public\n * @remarks\n * `<NodeData>` and `<EdgeData>` are useful when rendering custom or edge labels\n */\nexport interface DependencyGraphProps<NodeData, EdgeData>\n extends SVGProps<SVGSVGElement> {\n /**\n * Edges of graph\n */\n edges: Types.DependencyEdge<EdgeData>[];\n /**\n * Nodes of Graph\n */\n nodes: Types.DependencyNode<NodeData>[];\n /**\n * Graph {@link DependencyGraphTypes.Direction | direction}\n *\n * @remarks\n *\n * Default: `DependencyGraphTypes.Direction.TOP_BOTTOM`\n */\n direction?: Types.Direction;\n /**\n * Node {@link DependencyGraphTypes.Alignment | alignment}\n */\n align?: Types.Alignment;\n /**\n * Margin between nodes on each rank\n *\n * @remarks\n *\n * Default: 50\n */\n nodeMargin?: number;\n /**\n * Margin between edges\n *\n * @remarks\n *\n * Default: 10\n */\n edgeMargin?: number;\n /**\n * Margin between each rank\n *\n * @remarks\n *\n * Default: 50\n */\n rankMargin?: number;\n /**\n * Margin on left and right of whole graph\n *\n * @remarks\n *\n * Default: 0\n */\n paddingX?: number;\n /**\n * Margin on top and bottom of whole graph\n *\n * @remarks\n *\n * Default: 0\n */\n paddingY?: number;\n /**\n * Heuristic used to find set of edges that will make graph acyclic\n */\n acyclicer?: 'greedy';\n /**\n * {@link DependencyGraphTypes.Ranker | Algorithm} used to rank nodes\n *\n * @remarks\n *\n * Default: `DependencyGraphTypes.Ranker.NETWORK_SIMPLEX`\n */\n ranker?: Types.Ranker;\n /**\n * {@link DependencyGraphTypes.LabelPosition | Position} of label in relation to edge\n *\n * @remarks\n *\n * Default: `DependencyGraphTypes.LabelPosition.RIGHT`\n */\n labelPosition?: Types.LabelPosition;\n /**\n * How much to move label away from edge\n *\n * @remarks\n *\n * Applies only when {@link DependencyGraphProps.labelPosition} is `DependencyGraphTypes.LabelPosition.LEFT` or\n * `DependencyGraphTypes.LabelPosition.RIGHT`\n */\n labelOffset?: number;\n /**\n * Minimum number of ranks to keep between connected nodes\n */\n edgeRanks?: number;\n /**\n * Weight applied to edges in graph\n */\n edgeWeight?: number;\n /**\n * Custom edge rendering component\n */\n renderEdge?: Types.RenderEdgeFunction<EdgeData>;\n /**\n * Custom node rendering component\n */\n renderNode?: Types.RenderNodeFunction<NodeData>;\n /**\n * Custom label rendering component\n */\n renderLabel?: Types.RenderLabelFunction<EdgeData>;\n /**\n * {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs | Defs} shared by rendered SVG to be used by\n * {@link DependencyGraphProps.renderNode} and/or {@link DependencyGraphProps.renderLabel}\n */\n defs?: JSX.Element | JSX.Element[];\n /**\n * Controls zoom behavior of graph\n *\n * @remarks\n *\n * Default: `enabled`\n */\n zoom?: 'enabled' | 'disabled' | 'enable-on-click';\n /**\n * A factory for curve generators addressing both lines and areas.\n *\n * @remarks\n *\n * Default: 'curveMonotoneX'\n */\n curve?: 'curveStepBefore' | 'curveMonotoneX';\n /**\n * Controls if the arrow heads should be rendered or not.\n *\n * Default: false\n */\n showArrowHeads?: boolean;\n /**\n * Controls if the graph should be contained or grow\n *\n * @remarks\n *\n * Default: 'grow'\n */\n fit?: 'grow' | 'contain';\n /**\n * Controls if user can toggle fullscreen mode\n *\n * @remarks\n *\n * Default: true\n */\n allowFullscreen?: boolean;\n}\n\nconst WORKSPACE_ID = 'workspace';\nconst DEPENDENCY_GRAPH_SVG = 'dependency-graph';\n\n/**\n * Graph component used to visualize relations between entities\n *\n * @public\n */\nexport function DependencyGraph<NodeData, EdgeData>(\n props: DependencyGraphProps<NodeData, EdgeData>,\n) {\n const {\n edges,\n nodes,\n renderNode,\n direction = Types.Direction.TOP_BOTTOM,\n align,\n nodeMargin = 50,\n edgeMargin = 10,\n rankMargin = 50,\n paddingX = 0,\n paddingY = 0,\n acyclicer,\n ranker = Types.Ranker.NETWORK_SIMPLEX,\n labelPosition = Types.LabelPosition.RIGHT,\n labelOffset = 10,\n edgeRanks = 1,\n edgeWeight = 1,\n renderEdge,\n renderLabel,\n defs,\n zoom = 'enabled',\n curve = 'curveMonotoneX',\n showArrowHeads = false,\n fit = 'grow',\n allowFullscreen = true,\n ...svgProps\n } = props;\n const theme = useTheme();\n const [containerWidth, setContainerWidth] = useState<number>(100);\n const [containerHeight, setContainerHeight] = useState<number>(100);\n const fullScreenHandle = useFullScreenHandle();\n const styles = useStyles();\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n const graph = useRef<dagre.graphlib.Graph<Types.DependencyNode<NodeData>>>(\n new dagre.graphlib.Graph(),\n );\n const [graphWidth, setGraphWidth] = useState<number>(\n graph.current.graph()?.width || 0,\n );\n const [graphHeight, setGraphHeight] = useState<number>(\n graph.current.graph()?.height || 0,\n );\n const [graphNodes, setGraphNodes] = useState<string[]>([]);\n const [graphEdges, setGraphEdges] = useState<dagre.Edge[]>([]);\n\n const maxWidth = Math.max(graphWidth, containerWidth);\n const maxHeight = Math.max(graphHeight, containerHeight);\n\n const [_measureRef] = useMeasure();\n const measureRef = once(_measureRef);\n\n const scalableHeight =\n fit === 'grow' && !fullScreenHandle.active ? maxHeight : '100%';\n\n const containerRef = useMemo(\n () =>\n debounce((root: HTMLDivElement) => {\n if (!root) {\n return;\n }\n measureRef(root);\n\n // Set up zooming + panning\n const node: SVGSVGElement = root.querySelector(\n `svg#${DEPENDENCY_GRAPH_SVG}`,\n ) as SVGSVGElement;\n if (!node) {\n return;\n }\n const container = d3Selection.select<SVGSVGElement, null>(node);\n const workspace = d3Selection.select(node.getElementById(WORKSPACE_ID));\n\n function enableZoom() {\n container.call(\n d3Zoom\n .zoom<SVGSVGElement, null>()\n .scaleExtent([1, Infinity])\n .on('zoom', event => {\n event.transform.x = Math.min(\n 0,\n Math.max(\n event.transform.x,\n maxWidth - maxWidth * event.transform.k,\n ),\n );\n event.transform.y = Math.min(\n 0,\n Math.max(\n event.transform.y,\n maxHeight - maxHeight * event.transform.k,\n ),\n );\n workspace.attr('transform', event.transform);\n }),\n );\n }\n\n if (zoom === 'enabled') {\n enableZoom();\n } else if (zoom === 'enable-on-click') {\n container.on('click', () => enableZoom());\n }\n\n const { width: newContainerWidth, height: newContainerHeight } =\n root.getBoundingClientRect();\n if (\n containerWidth !== newContainerWidth &&\n newContainerWidth <= maxWidth\n ) {\n setContainerWidth(newContainerWidth);\n }\n if (\n containerHeight !== newContainerHeight &&\n newContainerHeight <= maxHeight\n ) {\n setContainerHeight(newContainerHeight);\n }\n }, 100),\n [measureRef, containerHeight, containerWidth, maxWidth, maxHeight, zoom],\n );\n\n const setNodesAndEdges = useCallback(() => {\n // Cleaning up lingering nodes and edges\n const currentGraphNodes = graph.current.nodes();\n const currentGraphEdges = graph.current.edges();\n\n currentGraphNodes.forEach(nodeId => {\n const remainingNode = nodes.some(node => node.id === nodeId);\n if (!remainingNode) {\n graph.current.removeNode(nodeId);\n }\n });\n\n currentGraphEdges.forEach(e => {\n const remainingEdge = edges.some(\n edge => edge.from === e.v && edge.to === e.w,\n );\n if (!remainingEdge) {\n graph.current.removeEdge(e.v, e.w);\n }\n });\n\n // Adding/updating nodes and edges\n nodes.forEach(node => {\n const existingNode = graph.current\n .nodes()\n .find(nodeId => node.id === nodeId);\n\n if (existingNode && graph.current.node(existingNode)) {\n const { width, height, x, y } = graph.current.node(existingNode);\n graph.current.setNode(existingNode, { ...node, width, height, x, y });\n } else {\n graph.current.setNode(node.id, { ...node, width: 0, height: 0 });\n }\n });\n\n edges.forEach(e => {\n graph.current.setEdge(e.from, e.to, {\n ...e,\n label: e.label,\n width: 0,\n height: 0,\n labelpos: labelPosition,\n labeloffset: labelOffset,\n weight: edgeWeight,\n minlen: edgeRanks,\n });\n });\n }, [edges, nodes, labelPosition, labelOffset, edgeWeight, edgeRanks]);\n\n const updateGraph = useMemo(\n () =>\n debounce(\n () => {\n dagre.layout(graph.current);\n const { height, width } = graph.current.graph();\n const newHeight = Math.max(0, height || 0);\n const newWidth = Math.max(0, width || 0);\n setGraphWidth(newWidth);\n setGraphHeight(newHeight);\n\n setGraphNodes(graph.current.nodes());\n setGraphEdges(graph.current.edges());\n },\n 250,\n { leading: true },\n ),\n [],\n );\n\n useEffect(() => {\n graph.current.setGraph({\n rankdir: direction,\n align,\n nodesep: nodeMargin,\n edgesep: edgeMargin,\n ranksep: rankMargin,\n marginx: paddingX,\n marginy: paddingY,\n acyclicer,\n ranker,\n });\n\n setNodesAndEdges();\n updateGraph();\n\n return updateGraph.cancel;\n }, [\n acyclicer,\n align,\n direction,\n edgeMargin,\n paddingX,\n paddingY,\n nodeMargin,\n rankMargin,\n ranker,\n setNodesAndEdges,\n updateGraph,\n ]);\n\n const setNode = useCallback(\n (id: string, node: Types.DependencyNode<NodeData>) => {\n graph.current.setNode(id, node);\n updateGraph();\n return graph.current;\n },\n [updateGraph],\n );\n\n const setEdge = useCallback(\n (id: dagre.Edge, edge: Types.DependencyEdge<EdgeData>) => {\n graph.current.setEdge(id, edge);\n updateGraph();\n return graph.current;\n },\n [updateGraph],\n );\n\n return (\n <FullScreen\n handle={fullScreenHandle}\n className={classNames(\n fullScreenHandle.active ? styles.fullscreen : styles.root,\n )}\n >\n {allowFullscreen && (\n <Tooltip title={t('dependencyGraph.fullscreenTooltip')}>\n <IconButton\n className={styles.fullscreenButton}\n onClick={\n fullScreenHandle.active\n ? fullScreenHandle.exit\n : fullScreenHandle.enter\n }\n >\n {fullScreenHandle.active ? (\n <FullscreenExitIcon />\n ) : (\n <FullscreenIcon />\n )}\n </IconButton>\n </Tooltip>\n )}\n\n <div ref={containerRef} style={{ width: '100%', height: '100%' }}>\n <svg\n {...svgProps}\n width=\"100%\"\n height={scalableHeight}\n viewBox={`0 0 ${maxWidth} ${maxHeight}`}\n id={DEPENDENCY_GRAPH_SVG}\n >\n <defs>\n <marker\n id={ARROW_MARKER_ID}\n viewBox=\"0 0 24 24\"\n markerWidth=\"14\"\n markerHeight=\"14\"\n refX=\"16\"\n refY=\"12\"\n orient=\"auto\"\n markerUnits=\"strokeWidth\"\n >\n <path\n fill={theme.palette.textSubtle}\n d=\"M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z\"\n />\n </marker>\n {defs}\n </defs>\n <g id={WORKSPACE_ID}>\n <svg\n width={graphWidth}\n height={graphHeight}\n y={maxHeight / 2 - graphHeight / 2}\n x={maxWidth / 2 - graphWidth / 2}\n viewBox={`-25 -25 ${graphWidth + 50} ${graphHeight + 50}`}\n >\n {graphEdges.map(e => {\n const edge = graph.current.edge(e) as GraphEdge<EdgeData>;\n if (!edge) return null;\n if (renderEdge) return renderEdge({ edge, id: e });\n\n return (\n <Edge\n key={`${e.v}-${e.w}`}\n id={e}\n setEdge={setEdge}\n render={renderLabel}\n edge={edge}\n curve={curve}\n showArrowHeads={showArrowHeads}\n />\n );\n })}\n {graphNodes.map((id: string) => {\n const node = graph.current.node(id);\n if (!node) return null;\n return (\n <Node\n key={id}\n setNode={setNode}\n render={renderNode}\n node={node}\n />\n );\n })}\n </svg>\n </g>\n </svg>\n </div>\n </FullScreen>\n );\n}\n"],"names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sBAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,sBAAA,uBACE,GAAA;AAAA,wBAAC,IAAA;AAAA,wBAAA;AAAA,0BAEC,OAAA;AAAA,0BACA,MAAA,EAAQ,UAAA;AAAA,0BACR;AAAA,yBAAA;AAAA,wBAHK;AAAA,uBAIP;AAAA,oBAEJ,CAAC;AAAA;AAAA;AAAA,eACH,EACF;AAAA;AAAA;AAAA,SACF,EACF;AAAA;AAAA;AAAA,GACF;AAEJ;;;;"}
1
+ {"version":3,"file":"DependencyGraph.esm.js","sources":["../../../src/components/DependencyGraph/DependencyGraph.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SVGProps,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport useMeasure from 'react-use/esm/useMeasure';\nimport classNames from 'classnames';\nimport { once } from 'lodash';\nimport * as d3Zoom from 'd3-zoom';\nimport * as d3Selection from 'd3-selection';\nimport useTheme from '@material-ui/core/styles/useTheme';\nimport dagre from '@dagrejs/dagre';\nimport debounce from 'lodash/debounce';\nimport { DependencyGraphTypes as Types } from './types';\nimport { Node } from './Node';\nimport { Edge, GraphEdge } from './Edge';\nimport { ARROW_MARKER_ID } from './constants';\nimport IconButton from '@material-ui/core/IconButton';\nimport FullscreenIcon from '@material-ui/icons/Fullscreen';\nimport FullscreenExitIcon from '@material-ui/icons/FullscreenExit';\nimport { FullScreen, useFullScreenHandle } from 'react-full-screen';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { coreComponentsTranslationRef } from '../../translation';\n\nconst useStyles = makeStyles((theme: Theme) => ({\n fullscreenButton: {\n position: 'absolute',\n right: 0,\n },\n root: {\n overflow: 'hidden',\n minHeight: '100%',\n minWidth: '100%',\n },\n fixedHeight: {\n maxHeight: '100%',\n },\n fullscreen: {\n backgroundColor: theme.palette.background.paper,\n },\n}));\n\n/**\n * Properties of {@link DependencyGraph}\n *\n * @public\n * @remarks\n * `<NodeData>` and `<EdgeData>` are useful when rendering custom or edge labels\n */\nexport interface DependencyGraphProps<NodeData, EdgeData>\n extends SVGProps<SVGSVGElement> {\n /**\n * Edges of graph\n */\n edges: Types.DependencyEdge<EdgeData>[];\n /**\n * Nodes of Graph\n */\n nodes: Types.DependencyNode<NodeData>[];\n /**\n * Graph {@link DependencyGraphTypes.(Direction:namespace) | direction}\n *\n * @remarks\n *\n * Default: `DependencyGraphTypes.Direction.TOP_BOTTOM`\n */\n direction?: Types.Direction;\n /**\n * Node {@link DependencyGraphTypes.(Alignment:namespace) | alignment}\n */\n align?: Types.Alignment;\n /**\n * Margin between nodes on each rank\n *\n * @remarks\n *\n * Default: 50\n */\n nodeMargin?: number;\n /**\n * Margin between edges\n *\n * @remarks\n *\n * Default: 10\n */\n edgeMargin?: number;\n /**\n * Margin between each rank\n *\n * @remarks\n *\n * Default: 50\n */\n rankMargin?: number;\n /**\n * Margin on left and right of whole graph\n *\n * @remarks\n *\n * Default: 0\n */\n paddingX?: number;\n /**\n * Margin on top and bottom of whole graph\n *\n * @remarks\n *\n * Default: 0\n */\n paddingY?: number;\n /**\n * Heuristic used to find set of edges that will make graph acyclic\n */\n acyclicer?: 'greedy';\n /**\n * {@link DependencyGraphTypes.(Ranker:namespace) | Algorithm} used to rank nodes\n *\n * @remarks\n *\n * Default: `DependencyGraphTypes.Ranker.NETWORK_SIMPLEX`\n */\n ranker?: Types.Ranker;\n /**\n * {@link DependencyGraphTypes.(LabelPosition:namespace) | Position} of label in relation to edge\n *\n * @remarks\n *\n * Default: `DependencyGraphTypes.LabelPosition.RIGHT`\n */\n labelPosition?: Types.LabelPosition;\n /**\n * How much to move label away from edge\n *\n * @remarks\n *\n * Applies only when {@link DependencyGraphProps.labelPosition} is `DependencyGraphTypes.LabelPosition.LEFT` or\n * `DependencyGraphTypes.LabelPosition.RIGHT`\n */\n labelOffset?: number;\n /**\n * Minimum number of ranks to keep between connected nodes\n */\n edgeRanks?: number;\n /**\n * Weight applied to edges in graph\n */\n edgeWeight?: number;\n /**\n * Custom edge rendering component\n */\n renderEdge?: Types.RenderEdgeFunction<EdgeData>;\n /**\n * Custom node rendering component\n */\n renderNode?: Types.RenderNodeFunction<NodeData>;\n /**\n * Custom label rendering component\n */\n renderLabel?: Types.RenderLabelFunction<EdgeData>;\n /**\n * {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs | Defs} shared by rendered SVG to be used by\n * {@link DependencyGraphProps.renderNode} and/or {@link DependencyGraphProps.renderLabel}\n */\n defs?: JSX.Element | JSX.Element[];\n /**\n * Controls zoom behavior of graph\n *\n * @remarks\n *\n * Default: `enabled`\n */\n zoom?: 'enabled' | 'disabled' | 'enable-on-click';\n /**\n * A factory for curve generators addressing both lines and areas.\n *\n * @remarks\n *\n * Default: 'curveMonotoneX'\n */\n curve?: 'curveStepBefore' | 'curveMonotoneX';\n /**\n * Controls if the arrow heads should be rendered or not.\n *\n * Default: false\n */\n showArrowHeads?: boolean;\n /**\n * Controls if the graph should be contained or grow\n *\n * @remarks\n *\n * Default: 'grow'\n */\n fit?: 'grow' | 'contain';\n /**\n * Controls if user can toggle fullscreen mode\n *\n * @remarks\n *\n * Default: true\n */\n allowFullscreen?: boolean;\n}\n\nconst WORKSPACE_ID = 'workspace';\nconst DEPENDENCY_GRAPH_SVG = 'dependency-graph';\n\n/**\n * Graph component used to visualize relations between entities\n *\n * @public\n */\nexport function DependencyGraph<NodeData, EdgeData>(\n props: DependencyGraphProps<NodeData, EdgeData>,\n) {\n const {\n edges,\n nodes,\n renderNode,\n direction = Types.Direction.TOP_BOTTOM,\n align,\n nodeMargin = 50,\n edgeMargin = 10,\n rankMargin = 50,\n paddingX = 0,\n paddingY = 0,\n acyclicer,\n ranker = Types.Ranker.NETWORK_SIMPLEX,\n labelPosition = Types.LabelPosition.RIGHT,\n labelOffset = 10,\n edgeRanks = 1,\n edgeWeight = 1,\n renderEdge,\n renderLabel,\n defs,\n zoom = 'enabled',\n curve = 'curveMonotoneX',\n showArrowHeads = false,\n fit = 'grow',\n allowFullscreen = true,\n ...svgProps\n } = props;\n const theme = useTheme();\n const [containerWidth, setContainerWidth] = useState<number>(100);\n const [containerHeight, setContainerHeight] = useState<number>(100);\n const fullScreenHandle = useFullScreenHandle();\n const styles = useStyles();\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n const graph = useRef<dagre.graphlib.Graph<Types.DependencyNode<NodeData>>>(\n new dagre.graphlib.Graph(),\n );\n const [graphWidth, setGraphWidth] = useState<number>(\n graph.current.graph()?.width || 0,\n );\n const [graphHeight, setGraphHeight] = useState<number>(\n graph.current.graph()?.height || 0,\n );\n const [graphNodes, setGraphNodes] = useState<string[]>([]);\n const [graphEdges, setGraphEdges] = useState<dagre.Edge[]>([]);\n\n const maxWidth = Math.max(graphWidth, containerWidth);\n const maxHeight = Math.max(graphHeight, containerHeight);\n\n const [_measureRef] = useMeasure();\n const measureRef = once(_measureRef);\n\n const scalableHeight =\n fit === 'grow' && !fullScreenHandle.active ? maxHeight : '100%';\n\n const containerRef = useMemo(\n () =>\n debounce((root: HTMLDivElement) => {\n if (!root) {\n return;\n }\n measureRef(root);\n\n // Set up zooming + panning\n const node: SVGSVGElement = root.querySelector(\n `svg#${DEPENDENCY_GRAPH_SVG}`,\n ) as SVGSVGElement;\n if (!node) {\n return;\n }\n const container = d3Selection.select<SVGSVGElement, null>(node);\n const workspace = d3Selection.select(node.getElementById(WORKSPACE_ID));\n\n function enableZoom() {\n container.call(\n d3Zoom\n .zoom<SVGSVGElement, null>()\n .scaleExtent([1, Infinity])\n .on('zoom', event => {\n event.transform.x = Math.min(\n 0,\n Math.max(\n event.transform.x,\n maxWidth - maxWidth * event.transform.k,\n ),\n );\n event.transform.y = Math.min(\n 0,\n Math.max(\n event.transform.y,\n maxHeight - maxHeight * event.transform.k,\n ),\n );\n workspace.attr('transform', event.transform);\n }),\n );\n }\n\n if (zoom === 'enabled') {\n enableZoom();\n } else if (zoom === 'enable-on-click') {\n container.on('click', () => enableZoom());\n }\n\n const { width: newContainerWidth, height: newContainerHeight } =\n root.getBoundingClientRect();\n if (\n containerWidth !== newContainerWidth &&\n newContainerWidth <= maxWidth\n ) {\n setContainerWidth(newContainerWidth);\n }\n if (\n containerHeight !== newContainerHeight &&\n newContainerHeight <= maxHeight\n ) {\n setContainerHeight(newContainerHeight);\n }\n }, 100),\n [measureRef, containerHeight, containerWidth, maxWidth, maxHeight, zoom],\n );\n\n const setNodesAndEdges = useCallback(() => {\n // Cleaning up lingering nodes and edges\n const currentGraphNodes = graph.current.nodes();\n const currentGraphEdges = graph.current.edges();\n\n currentGraphNodes.forEach(nodeId => {\n const remainingNode = nodes.some(node => node.id === nodeId);\n if (!remainingNode) {\n graph.current.removeNode(nodeId);\n }\n });\n\n currentGraphEdges.forEach(e => {\n const remainingEdge = edges.some(\n edge => edge.from === e.v && edge.to === e.w,\n );\n if (!remainingEdge) {\n graph.current.removeEdge(e.v, e.w);\n }\n });\n\n // Adding/updating nodes and edges\n nodes.forEach(node => {\n const existingNode = graph.current\n .nodes()\n .find(nodeId => node.id === nodeId);\n\n if (existingNode && graph.current.node(existingNode)) {\n const { width, height, x, y } = graph.current.node(existingNode);\n graph.current.setNode(existingNode, { ...node, width, height, x, y });\n } else {\n graph.current.setNode(node.id, { ...node, width: 0, height: 0 });\n }\n });\n\n edges.forEach(e => {\n graph.current.setEdge(e.from, e.to, {\n ...e,\n label: e.label,\n width: 0,\n height: 0,\n labelpos: labelPosition,\n labeloffset: labelOffset,\n weight: edgeWeight,\n minlen: edgeRanks,\n });\n });\n }, [edges, nodes, labelPosition, labelOffset, edgeWeight, edgeRanks]);\n\n const updateGraph = useMemo(\n () =>\n debounce(\n () => {\n dagre.layout(graph.current);\n const { height, width } = graph.current.graph();\n const newHeight = Math.max(0, height || 0);\n const newWidth = Math.max(0, width || 0);\n setGraphWidth(newWidth);\n setGraphHeight(newHeight);\n\n setGraphNodes(graph.current.nodes());\n setGraphEdges(graph.current.edges());\n },\n 250,\n { leading: true },\n ),\n [],\n );\n\n useEffect(() => {\n graph.current.setGraph({\n rankdir: direction,\n align,\n nodesep: nodeMargin,\n edgesep: edgeMargin,\n ranksep: rankMargin,\n marginx: paddingX,\n marginy: paddingY,\n acyclicer,\n ranker,\n });\n\n setNodesAndEdges();\n updateGraph();\n\n return updateGraph.cancel;\n }, [\n acyclicer,\n align,\n direction,\n edgeMargin,\n paddingX,\n paddingY,\n nodeMargin,\n rankMargin,\n ranker,\n setNodesAndEdges,\n updateGraph,\n ]);\n\n const setNode = useCallback(\n (id: string, node: Types.DependencyNode<NodeData>) => {\n graph.current.setNode(id, node);\n updateGraph();\n return graph.current;\n },\n [updateGraph],\n );\n\n const setEdge = useCallback(\n (id: dagre.Edge, edge: Types.DependencyEdge<EdgeData>) => {\n graph.current.setEdge(id, edge);\n updateGraph();\n return graph.current;\n },\n [updateGraph],\n );\n\n return (\n <FullScreen\n handle={fullScreenHandle}\n className={classNames(\n fullScreenHandle.active ? styles.fullscreen : styles.root,\n )}\n >\n {allowFullscreen && (\n <Tooltip title={t('dependencyGraph.fullscreenTooltip')}>\n <IconButton\n className={styles.fullscreenButton}\n onClick={\n fullScreenHandle.active\n ? fullScreenHandle.exit\n : fullScreenHandle.enter\n }\n >\n {fullScreenHandle.active ? (\n <FullscreenExitIcon />\n ) : (\n <FullscreenIcon />\n )}\n </IconButton>\n </Tooltip>\n )}\n\n <div ref={containerRef} style={{ width: '100%', height: '100%' }}>\n <svg\n {...svgProps}\n width=\"100%\"\n height={scalableHeight}\n viewBox={`0 0 ${maxWidth} ${maxHeight}`}\n id={DEPENDENCY_GRAPH_SVG}\n >\n <defs>\n <marker\n id={ARROW_MARKER_ID}\n viewBox=\"0 0 24 24\"\n markerWidth=\"14\"\n markerHeight=\"14\"\n refX=\"16\"\n refY=\"12\"\n orient=\"auto\"\n markerUnits=\"strokeWidth\"\n >\n <path\n fill={theme.palette.textSubtle}\n d=\"M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z\"\n />\n </marker>\n {defs}\n </defs>\n <g id={WORKSPACE_ID}>\n <svg\n width={graphWidth}\n height={graphHeight}\n y={maxHeight / 2 - graphHeight / 2}\n x={maxWidth / 2 - graphWidth / 2}\n viewBox={`-25 -25 ${graphWidth + 50} ${graphHeight + 50}`}\n >\n {graphEdges.map(e => {\n const edge = graph.current.edge(e) as GraphEdge<EdgeData>;\n if (!edge) return null;\n if (renderEdge) return renderEdge({ edge, id: e });\n\n return (\n <Edge\n key={`${e.v}-${e.w}`}\n id={e}\n setEdge={setEdge}\n render={renderLabel}\n edge={edge}\n curve={curve}\n showArrowHeads={showArrowHeads}\n />\n );\n })}\n {graphNodes.map((id: string) => {\n const node = graph.current.node(id);\n if (!node) return null;\n return (\n <Node\n key={id}\n setNode={setNode}\n render={renderNode}\n node={node}\n />\n );\n })}\n </svg>\n </g>\n </svg>\n </div>\n </FullScreen>\n );\n}\n"],"names":["Types"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,SAAA,GAAY,UAAA,CAAW,CAAC,KAAA,MAAkB;AAAA,EAC9C,gBAAA,EAAkB;AAAA,IAChB,QAAA,EAAU,UAAA;AAAA,IACV,KAAA,EAAO;AAAA,GACT;AAAA,EACA,IAAA,EAAM;AAAA,IACJ,QAAA,EAAU,QAAA;AAAA,IACV,SAAA,EAAW,MAAA;AAAA,IACX,QAAA,EAAU;AAAA,GACZ;AAAA,EACA,WAAA,EAAa;AAAA,IACX,SAAA,E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ypes;
2
2
  ((DependencyGraphTypes2) => {
3
- ((Direction2) => {
4
- Direction2["TOP_BOTTOM"] = "TB";
5
- Direction2["BOTTOM_TOP"] = "BT";
6
- Direction2["LEFT_RIGHT"] = "LR";
7
- Direction2["RIGHT_LEFT"] = "RL";
8
- })(DependencyGraphTypes2.Direction || (DependencyGraphTypes2.Direction = {}));
9
- ((Alignment2) => {
10
- Alignment2["UP_LEFT"] = "UL";
11
- Alignment2["UP_RIGHT"] = "UR";
12
- Alignment2["DOWN_LEFT"] = "DL";
13
- Alignment2["DOWN_RIGHT"] = "DR";
14
- })(DependencyGraphTypes2.Alignment || (DependencyGraphTypes2.Alignment = {}));
15
- ((Ranker2) => {
16
- Ranker2["NETWORK_SIMPLEX"] = "network-simplex";
17
- Ranker2["TIGHT_TREE"] = "tight-tree";
18
- Ranker2["LONGEST_PATH"] = "longest-path";
19
- })(DependencyGraphTypes2.Ranker || (DependencyGraphTypes2.Ranker = {}));
20
- ((LabelPosition2) => {
21
- LabelPosition2["LEFT"] = "l";
22
- LabelPosition2["RIGHT"] = "r";
23
- LabelPosition2["CENTER"] = "c";
24
- })(DependencyGraphTypes2.LabelPosition || (DependencyGraphTypes2.LabelPosition = {}));
3
+ DependencyGraphTypes2.Direction = {
4
+ /**
5
+ * Top to Bottom
6
+ */
7
+ TOP_BOTTOM: "TB",
8
+ /**
9
+ * Bottom to Top
10
+ */
11
+ BOTTOM_TOP: "BT",
12
+ /**
13
+ * Left to Right
14
+ */
15
+ LEFT_RIGHT: "LR",
16
+ /**
17
+ * Right to Left
18
+ */
19
+ RIGHT_LEFT: "RL"
20
+ };
21
+ DependencyGraphTypes2.Alignment = {
22
+ /**
23
+ * Up Left
24
+ */
25
+ UP_LEFT: "UL",
26
+ /**
27
+ * Up Right
28
+ */
29
+ UP_RIGHT: "UR",
30
+ /**
31
+ * Down Left
32
+ */
33
+ DOWN_LEFT: "DL",
34
+ /**
35
+ * Down Right
36
+ */
37
+ DOWN_RIGHT: "DR"
38
+ };
39
+ DependencyGraphTypes2.Ranker = {
40
+ /**
41
+ * {@link https://en.wikipedia.org/wiki/Network_simplex_algorithm | Network Simplex} algorithm
42
+ */
43
+ NETWORK_SIMPLEX: "network-simplex",
44
+ /**
45
+ * Tight Tree algorithm
46
+ */
47
+ TIGHT_TREE: "tight-tree",
48
+ /**
49
+ * Longest path algorithm
50
+ *
51
+ * @remarks
52
+ *
53
+ * Simplest and fastest
54
+ */
55
+ LONGEST_PATH: "longest-path"
56
+ };
57
+ DependencyGraphTypes2.LabelPosition = {
58
+ LEFT: "l",
59
+ RIGHT: "r",
60
+ CENTER: "c"
61
+ };
25
62
  })(DependencyGraphTypes || (DependencyGraphTypes = {}));
26
63
 
27
64
  export { DependencyGraphTypes };
@@ -1 +1 @@
1
- {"version":3,"file":"types.esm.js","sources":["../../../src/components/DependencyGraph/types.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Types used to customize and provide data to {@link DependencyGraph}\n *\n * @packageDocumentation\n */\n\nimport { ReactNode } from 'react';\n\n/**\n * Types for the {@link DependencyGraph} component.\n *\n * @public\n */\nexport namespace DependencyGraphTypes {\n /**\n * Edge of {@link DependencyGraph}\n *\n * @public\n */\n export type DependencyEdge<T = {}> = T & {\n /**\n * ID of {@link DependencyNode} from where the Edge start\n */\n from: string;\n /**\n * ID of {@link DependencyNode} to where the Edge goes to\n */\n to: string;\n /**\n * Label assigned and rendered with the Edge\n */\n label?: string;\n /**\n * Distance to a root entity\n */\n distance?: number;\n };\n\n /**\n * Properties of {@link DependencyGraphTypes.RenderLabelFunction} for {@link DependencyGraphTypes.DependencyEdge}\n *\n * @public\n */\n export type RenderLabelProps<T = unknown> = { edge: DependencyEdge<T> };\n\n /**\n * Custom React component for edge labels\n *\n * @public\n */\n export type RenderLabelFunction<T = {}> = (\n props: RenderLabelProps<T>,\n ) => ReactNode;\n\n /**\n * Node of {@link DependencyGraph}\n *\n * @public\n */\n export type DependencyNode<T = {}> = T & {\n id: string;\n };\n\n /**\n * Properties of {@link DependencyGraphTypes.RenderNodeFunction} for {@link DependencyGraphTypes.DependencyNode}\n *\n * @public\n */\n export type RenderNodeProps<T = unknown> = { node: DependencyNode<T> };\n\n /**\n * Custom React component for graph {@link DependencyGraphTypes.DependencyNode}\n *\n * @public\n */\n export type RenderNodeFunction<T = {}> = (\n props: RenderNodeProps<T>,\n ) => ReactNode;\n\n /**\n * Properties of {@link DependencyGraphTypes.RenderEdgeFunction} for {@link DependencyGraphTypes.DependencyEdge}\n *\n * @public\n */\n export type RenderEdgeProps<T = {}> = {\n edge: T & {\n points: { x: number; y: number }[];\n label?: string;\n labeloffset?: number;\n labelpos?: string;\n width?: number;\n height?: number;\n weight?: number;\n minlen?: number;\n showArrowHeads?: boolean;\n from?: string;\n to?: string;\n relations?: string[];\n };\n id: {\n v: string;\n w: string;\n name?: string | undefined;\n };\n };\n\n /**\n * Custom React component for graph {@link DependencyGraphTypes.DependencyEdge}\n *\n * @public\n */\n export type RenderEdgeFunction<T = {}> = (\n props: RenderEdgeProps<T>,\n ) => ReactNode;\n\n /**\n * Graph direction\n *\n * @public\n */\n export enum Direction {\n /**\n * Top to Bottom\n */\n TOP_BOTTOM = 'TB',\n /**\n * Bottom to Top\n */\n BOTTOM_TOP = 'BT',\n /**\n * Left to Right\n */\n LEFT_RIGHT = 'LR',\n /**\n * Right to Left\n */\n RIGHT_LEFT = 'RL',\n }\n\n /**\n * Node alignment\n *\n * @public\n */\n export enum Alignment {\n /**\n * Up Left\n */\n UP_LEFT = 'UL',\n /**\n * Up Right\n */\n UP_RIGHT = 'UR',\n /**\n * Down Left\n */\n DOWN_LEFT = 'DL',\n /**\n * Down Right\n */\n DOWN_RIGHT = 'DR',\n }\n\n /**\n * Algorithm used to rand nodes in graph\n *\n * @public\n */\n export enum Ranker {\n /**\n * {@link https://en.wikipedia.org/wiki/Network_simplex_algorithm | Network Simplex} algorithm\n */\n NETWORK_SIMPLEX = 'network-simplex',\n /**\n * Tight Tree algorithm\n */\n TIGHT_TREE = 'tight-tree',\n /**\n * Longest path algorithm\n *\n * @remarks\n *\n * Simplest and fastest\n */\n LONGEST_PATH = 'longest-path',\n }\n\n /**\n * Position of label in relation to the edge\n *\n * @public\n */\n export enum LabelPosition {\n LEFT = 'l',\n RIGHT = 'r',\n CENTER = 'c',\n }\n}\n"],"names":["DependencyGraphTypes","Direction","Alignment","Ranker","LabelPosition"],"mappings":"AA6BO,IAAU;AAAA,CAAV,CAAUA,qBAAAA,KAAV;AA2GE,EAAA,CAAA,CAAKC,UAAAA,KAAL;AAIL,IAAAA,WAAA,YAAA,CAAA,GAAa,IAAA;AAIb,IAAAA,WAAA,YAAA,CAAA,GAAa,IAAA;AAIb,IAAAA,WAAA,YAAA,CAAA,GAAa,IAAA;AAIb,IAAAA,WAAA,YAAA,CAAA,GAAa,IAAA;AAAA,EAAA,CAAA,EAhBHD,qBAAAA,CAAA,SAAA,KAAAA,qBAAAA,CAAA,SAAA,GAAA,EAAA,CAAA,CAAA;AAwBL,EAAA,CAAA,CAAKE,UAAAA,KAAL;AAIL,IAAAA,WAAA,SAAA,CAAA,GAAU,IAAA;AAIV,IAAAA,WAAA,UAAA,CAAA,GAAW,IAAA;AAIX,IAAAA,WAAA,WAAA,CAAA,GAAY,IAAA;AAIZ,IAAAA,WAAA,YAAA,CAAA,GAAa,IAAA;AAAA,EAAA,CAAA,EAhBHF,qBAAAA,CAAA,SAAA,KAAAA,qBAAAA,CAAA,SAAA,GAAA,EAAA,CAAA,CAAA;AAwBL,EAAA,CAAA,CAAKG,OAAAA,KAAL;AAIL,IAAAA,QAAA,iBAAA,CAAA,GAAkB,iBAAA;AAIlB,IAAAA,QAAA,YAAA,CAAA,GAAa,YAAA;AAQb,IAAAA,QAAA,cAAA,CAAA,GAAe,cAAA;AAAA,EAAA,CAAA,EAhBLH,qBAAAA,CAAA,MAAA,KAAAA,qBAAAA,CAAA,MAAA,GAAA,EAAA,CAAA,CAAA;AAwBL,EAAA,CAAA,CAAKI,cAAAA,KAAL;AACL,IAAAA,eAAA,MAAA,CAAA,GAAO,GAAA;AACP,IAAAA,eAAA,OAAA,CAAA,GAAQ,GAAA;AACR,IAAAA,eAAA,QAAA,CAAA,GAAS,GAAA;AAAA,EAAA,CAAA,EAHCJ,qBAAAA,CAAA,aAAA,KAAAA,qBAAAA,CAAA,aAAA,GAAA,EAAA,CAAA,CAAA;AAAA,CAAA,EAnLG,oBAAA,KAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"types.esm.js","sources":["../../../src/components/DependencyGraph/types.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/* We want to maintain the same information as an enum, so we disable the redeclaration warning */\n/* eslint-disable @typescript-eslint/no-redeclare */\n\n/**\n * Types used to customize and provide data to {@link DependencyGraph}\n *\n * @packageDocumentation\n */\n\nimport { ReactNode } from 'react';\n\n/**\n * Types for the {@link DependencyGraph} component.\n *\n * @public\n */\nexport namespace DependencyGraphTypes {\n /**\n * Edge of {@link DependencyGraph}\n *\n * @public\n */\n export type DependencyEdge<T = {}> = T & {\n /**\n * ID of {@link DependencyNode} from where the Edge start\n */\n from: string;\n /**\n * ID of {@link DependencyNode} to where the Edge goes to\n */\n to: string;\n /**\n * Label assigned and rendered with the Edge\n */\n label?: string;\n /**\n * Distance to a root entity\n */\n distance?: number;\n };\n\n /**\n * Properties of {@link DependencyGraphTypes.RenderLabelFunction} for {@link DependencyGraphTypes.DependencyEdge}\n *\n * @public\n */\n export type RenderLabelProps<T = unknown> = { edge: DependencyEdge<T> };\n\n /**\n * Custom React component for edge labels\n *\n * @public\n */\n export type RenderLabelFunction<T = {}> = (\n props: RenderLabelProps<T>,\n ) => ReactNode;\n\n /**\n * Node of {@link DependencyGraph}\n *\n * @public\n */\n export type DependencyNode<T = {}> = T & {\n id: string;\n };\n\n /**\n * Properties of {@link DependencyGraphTypes.RenderNodeFunction} for {@link DependencyGraphTypes.DependencyNode}\n *\n * @public\n */\n export type RenderNodeProps<T = unknown> = { node: DependencyNode<T> };\n\n /**\n * Custom React component for graph {@link DependencyGraphTypes.DependencyNode}\n *\n * @public\n */\n export type RenderNodeFunction<T = {}> = (\n props: RenderNodeProps<T>,\n ) => ReactNode;\n\n /**\n * Properties of {@link DependencyGraphTypes.RenderEdgeFunction} for {@link DependencyGraphTypes.DependencyEdge}\n *\n * @public\n */\n export type RenderEdgeProps<T = {}> = {\n edge: T & {\n points: { x: number; y: number }[];\n label?: string;\n labeloffset?: number;\n labelpos?: string;\n width?: number;\n height?: number;\n weight?: number;\n minlen?: number;\n showArrowHeads?: boolean;\n from?: string;\n to?: string;\n relations?: string[];\n };\n id: {\n v: string;\n w: string;\n name?: string | undefined;\n };\n };\n\n /**\n * Custom React component for graph {@link DependencyGraphTypes.DependencyEdge}\n *\n * @public\n */\n export type RenderEdgeFunction<T = {}> = (\n props: RenderEdgeProps<T>,\n ) => ReactNode;\n\n /**\n * Graph direction\n *\n * @public\n */\n export const Direction = {\n /**\n * Top to Bottom\n */\n TOP_BOTTOM: 'TB',\n /**\n * Bottom to Top\n */\n BOTTOM_TOP: 'BT',\n /**\n * Left to Right\n */\n LEFT_RIGHT: 'LR',\n /**\n * Right to Left\n */\n RIGHT_LEFT: 'RL',\n } as const;\n\n /**\n * @public\n */\n export type Direction = (typeof Direction)[keyof typeof Direction];\n\n /**\n * @public\n */\n export namespace Direction {\n export type TOP_BOTTOM = typeof Direction.TOP_BOTTOM;\n export type BOTTOM_TOP = typeof Direction.BOTTOM_TOP;\n export type LEFT_RIGHT = typeof Direction.LEFT_RIGHT;\n export type RIGHT_LEFT = typeof Direction.RIGHT_LEFT;\n }\n\n /**\n * Node alignment\n *\n * @public\n */\n export const Alignment = {\n /**\n * Up Left\n */\n UP_LEFT: 'UL',\n /**\n * Up Right\n */\n UP_RIGHT: 'UR',\n /**\n * Down Left\n */\n DOWN_LEFT: 'DL',\n /**\n * Down Right\n */\n DOWN_RIGHT: 'DR',\n } as const;\n\n /**\n * @public\n */\n export type Alignment = (typeof Alignment)[keyof typeof Alignment];\n\n /**\n * @public\n */\n export namespace Alignment {\n export type UP_LEFT = typeof Alignment.UP_LEFT;\n export type UP_RIGHT = typeof Alignment.UP_RIGHT;\n export type DOWN_LEFT = typeof Alignment.DOWN_LEFT;\n export type DOWN_RIGHT = typeof Alignment.DOWN_RIGHT;\n }\n\n /**\n * Algorithm used to rand nodes in graph\n *\n * @public\n */\n export const Ranker = {\n /**\n * {@link https://en.wikipedia.org/wiki/Network_simplex_algorithm | Network Simplex} algorithm\n */\n NETWORK_SIMPLEX: 'network-simplex',\n /**\n * Tight Tree algorithm\n */\n TIGHT_TREE: 'tight-tree',\n /**\n * Longest path algorithm\n *\n * @remarks\n *\n * Simplest and fastest\n */\n LONGEST_PATH: 'longest-path',\n } as const;\n\n /**\n * @public\n */\n export type Ranker = (typeof Ranker)[keyof typeof Ranker];\n\n /**\n * @public\n */\n export namespace Ranker {\n export type NETWORK_SIMPLEX = typeof Ranker.NETWORK_SIMPLEX;\n export type TIGHT_TREE = typeof Ranker.TIGHT_TREE;\n export type LONGEST_PATH = typeof Ranker.LONGEST_PATH;\n }\n\n /**\n * Position of label in relation to the edge\n *\n * @public\n */\n export const LabelPosition = {\n LEFT: 'l',\n RIGHT: 'r',\n CENTER: 'c',\n } as const;\n\n /**\n * @public\n */\n export type LabelPosition =\n (typeof LabelPosition)[keyof typeof LabelPosition];\n\n /**\n * @public\n */\n export namespace LabelPosition {\n export type LEFT = typeof LabelPosition.LEFT;\n export type RIGHT = typeof LabelPosition.RIGHT;\n export type CENTER = typeof LabelPosition.CENTER;\n }\n}\n"],"names":["DependencyGraphTypes"],"mappings":"AA+BO,IAAU;AAAA,CAAV,CAAUA,qBAAAA,KAAV;AA2GE,EAAMA,sBAAA,SAAA,GAAY;AAAA;AAAA;AAAA;AAAA,IAIvB,UAAA,EAAY,IAAA;AAAA;AAAA;AAAA;AAAA,IAIZ,UAAA,EAAY,IAAA;AAAA;AAAA;AAAA;AAAA,IAIZ,UAAA,EAAY,IAAA;AAAA;AAAA;AAAA;AAAA,IAIZ,UAAA,EAAY;AAAA,GACd;AAsBO,EAAMA,sBAAA,SAAA,GAAY;AAAA;AAAA;AAAA;AAAA,IAIvB,OAAA,EAAS,IAAA;AAAA;AAAA;AAAA;AAAA,IAIT,QAAA,EAAU,IAAA;AAAA;AAAA;AAAA;AAAA,IAIV,SAAA,EAAW,IAAA;AAAA;AAAA;AAAA;AAAA,IAIX,UAAA,EAAY;AAAA,GACd;AAsBO,EAAMA,sBAAA,MAAA,GAAS;AAAA;AAAA;AAAA;AAAA,IAIpB,eAAA,EAAiB,iBAAA;AAAA;AAAA;AAAA;AAAA,IAIjB,UAAA,EAAY,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQZ,YAAA,EAAc;AAAA,GAChB;AAqBO,EAAMA,sBAAA,aAAA,GAAgB;AAAA,IAC3B,IAAA,EAAM,GAAA;AAAA,IACN,KAAA,EAAO,GAAA;AAAA,IACP,MAAA,EAAQ;AAAA,GACV;AAAA,CAAA,EAnOe,oBAAA,KAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
@@ -34,12 +34,14 @@ const codeModifiers = Object.fromEntries(
34
34
  )
35
35
  );
36
36
  class AnsiLine {
37
+ text;
38
+ lineNumber;
39
+ chunks;
37
40
  constructor(lineNumber = 1, chunks = []) {
38
41
  this.lineNumber = lineNumber;
39
42
  this.chunks = chunks;
40
43
  this.text = chunks.map((c) => c.text).join("").toLocaleLowerCase("en-US");
41
44
  }
42
- text;
43
45
  lastChunk() {
44
46
  return this.chunks[this.chunks.length - 1];
45
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AnsiProcessor.esm.js","sources":["../../../src/components/LogViewer/AnsiProcessor.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport ansiRegexMaker from 'ansi-regex';\n\nconst ansiRegex = ansiRegexMaker();\nconst newlineRegex = /\\n\\r?/g;\n\n// A mapping of how each escape code changes the modifiers\nconst codeModifiers = Object.fromEntries(\n Object.entries({\n 1: m => ({ ...m, bold: true }),\n 3: m => ({ ...m, italic: true }),\n 4: m => ({ ...m, underline: true }),\n 22: ({ bold: _, ...m }) => m,\n 23: ({ italic: _, ...m }) => m,\n 24: ({ underline: _, ...m }) => m,\n 30: m => ({ ...m, foreground: 'black' }),\n 31: m => ({ ...m, foreground: 'red' }),\n 32: m => ({ ...m, foreground: 'green' }),\n 33: m => ({ ...m, foreground: 'yellow' }),\n 34: m => ({ ...m, foreground: 'blue' }),\n 35: m => ({ ...m, foreground: 'magenta' }),\n 36: m => ({ ...m, foreground: 'cyan' }),\n 37: m => ({ ...m, foreground: 'white' }),\n 39: ({ foreground: _, ...m }) => m,\n 90: m => ({ ...m, foreground: 'grey' }),\n 40: m => ({ ...m, background: 'black' }),\n 41: m => ({ ...m, background: 'red' }),\n 42: m => ({ ...m, background: 'green' }),\n 43: m => ({ ...m, background: 'yellow' }),\n 44: m => ({ ...m, background: 'blue' }),\n 45: m => ({ ...m, background: 'magenta' }),\n 46: m => ({ ...m, background: 'cyan' }),\n 47: m => ({ ...m, background: 'white' }),\n 49: ({ background: _, ...m }) => m,\n } as Record<string, (m: ChunkModifiers) => ChunkModifiers>).map(\n ([code, modifier]) => [`\\x1b[${code}m`, modifier],\n ),\n);\n\nexport type AnsiColor =\n | 'black'\n | 'red'\n | 'green'\n | 'yellow'\n | 'blue'\n | 'magenta'\n | 'cyan'\n | 'white'\n | 'grey';\n\nexport interface ChunkModifiers {\n foreground?: AnsiColor;\n background?: AnsiColor;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface AnsiChunk {\n text: string;\n modifiers: ChunkModifiers;\n}\n\nexport class AnsiLine {\n text: string;\n\n constructor(\n readonly lineNumber: number = 1,\n readonly chunks: AnsiChunk[] = [],\n ) {\n this.text = chunks\n .map(c => c.text)\n .join('')\n .toLocaleLowerCase('en-US');\n }\n\n lastChunk(): AnsiChunk | undefined {\n return this.chunks[this.chunks.length - 1];\n }\n\n replaceLastChunk(newChunks?: AnsiChunk[]) {\n if (newChunks) {\n this.chunks.splice(this.chunks.length - 1, 1, ...newChunks);\n this.text = this.chunks\n .map(c => c.text)\n .join('')\n .toLocaleLowerCase('en-US');\n }\n }\n}\n\nexport class AnsiProcessor {\n private text: string = '';\n private lines: AnsiLine[] = [];\n\n /**\n * Processes a chunk of text while keeping internal state that optimizes\n * subsequent processing that appends to the text.\n */\n process(text: string): AnsiLine[] {\n if (this.text === text) {\n return this.lines;\n }\n\n if (this.text && text.startsWith(this.text)) {\n const lastLineIndex = this.lines.length > 0 ? this.lines.length - 1 : 0;\n const lastLine = this.lines[lastLineIndex] ?? new AnsiLine();\n const lastChunk = lastLine.lastChunk();\n\n const newLines = this.processLines(\n (lastChunk?.text ?? '') + text.slice(this.text.length),\n lastChunk?.modifiers,\n lastLine?.lineNumber,\n );\n lastLine.replaceLastChunk(newLines[0]?.chunks);\n\n this.lines[lastLineIndex] = lastLine;\n this.lines = this.lines.concat(newLines.slice(1));\n } else {\n this.lines = this.processLines(text);\n }\n this.text = text;\n\n return this.lines;\n }\n\n // Split a chunk of text up into lines and process each line individually\n private processLines = (\n text: string,\n modifiers: ChunkModifiers = {},\n startingLineNumber: number = 1,\n ): AnsiLine[] => {\n const lines: AnsiLine[] = [];\n\n let currentModifiers = modifiers;\n let currentLineNumber = startingLineNumber;\n\n let prevIndex = 0;\n newlineRegex.lastIndex = 0;\n for (;;) {\n const match = newlineRegex.exec(text);\n if (!match) {\n const chunks = this.processText(\n text.slice(prevIndex),\n currentModifiers,\n );\n lines.push(new AnsiLine(currentLineNumber, chunks));\n return lines;\n }\n\n const line = text.slice(prevIndex, match.index);\n prevIndex = match.index + match[0].length;\n\n const chunks = this.processText(line, currentModifiers);\n lines.push(new AnsiLine(currentLineNumber, chunks));\n\n // Modifiers that are active in the last chunk are carried over to the next line\n currentModifiers =\n chunks[chunks.length - 1].modifiers ?? currentModifiers;\n currentLineNumber += 1;\n }\n };\n\n // Processing of a one individual text chunk\n private processText = (\n fullText: string,\n modifiers: ChunkModifiers,\n ): AnsiChunk[] => {\n const chunks: AnsiChunk[] = [];\n\n let currentModifiers = modifiers;\n\n let prevIndex = 0;\n ansiRegex.lastIndex = 0;\n for (;;) {\n const match = ansiRegex.exec(fullText);\n if (!match) {\n chunks.push({\n text: fullText.slice(prevIndex),\n modifiers: currentModifiers,\n });\n return chunks;\n }\n\n const text = fullText.slice(prevIndex, match.index);\n chunks.push({ text, modifiers: currentModifiers });\n\n // For every escape code that we encounter we keep track of where the\n // next chunk of text starts, and what modifiers it has\n prevIndex = match.index + match[0].length;\n currentModifiers = this.processCode(match[0], currentModifiers);\n }\n };\n\n private processCode = (\n code: string,\n modifiers: ChunkModifiers,\n ): ChunkModifiers => {\n return codeModifiers[code]?.(modifiers) ?? modifiers;\n };\n}\n"],"names":["chunks"],"mappings":";;AAkBA,MAAM,YAAY,cAAA,EAAe;AACjC,MAAM,YAAA,GAAe,QAAA;AAGrB,MAAM,gBAAgB,MAAA,CAAO,WAAA;AAAA,EAC3B,OAAO,OAAA,CAAQ;AAAA,IACb,GAAG,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,MAAM,IAAA,EAAK,CAAA;AAAA,IAC5B,GAAG,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,QAAQ,IAAA,EAAK,CAAA;AAAA,IAC9B,GAAG,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,WAAW,IAAA,EAAK,CAAA;AAAA,IACjC,IAAI,CAAC,EAAE,MAAM,CAAA,EAAG,GAAG,GAAE,KAAM,CAAA;AAAA,IAC3B,IAAI,CAAC,EAAE,QAAQ,CAAA,EAAG,GAAG,GAAE,KAAM,CAAA;AAAA,IAC7B,IAAI,CAAC,EAAE,WAAW,CAAA,EAAG,GAAG,GAAE,KAAM,CAAA;AAAA,IAChC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,OAAA,EAAQ,CAAA;AAAA,IACtC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,KAAA,EAAM,CAAA;AAAA,IACpC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,OAAA,EAAQ,CAAA;AAAA,IACtC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,QAAA,EAAS,CAAA;AAAA,IACvC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,MAAA,EAAO,CAAA;AAAA,IACrC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,SAAA,EAAU,CAA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,MAAA;AAAA,MACT;AAEA,MAAA,MAAM,IAAA,GAAO,QAAA,CAAS,KAAA,CAAM,SAAA,EAAW,MAAM,KAAK,CAAA;AAClD,MAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,SAAA,EAAW,kBAAkB,CAAA;AAIjD,MAAA,SAAA,GAAY,KAAA,CAAM,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,CAAE,MAAA;AACnC,MAAA,gBAAA,GAAmB,IAAA,CAAK,WAAA,CAAY,KAAA,CAAM,CAAC,GAAG,gBAAgB,CAAA;AAAA,IAChE;AAAA,EACF,CAAA;AAAA,EAEQ,WAAA,GAAc,CACpB,IAAA,EACA,SAAA,KACmB;AACnB,IAAA,OAAO,aAAA,CAAc,IAAI,CAAA,GAAI,SAAS,CAAA,IAAK,SAAA;AAAA,EAC7C,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"AnsiProcessor.esm.js","sources":["../../../src/components/LogViewer/AnsiProcessor.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport ansiRegexMaker from 'ansi-regex';\n\nconst ansiRegex = ansiRegexMaker();\nconst newlineRegex = /\\n\\r?/g;\n\n// A mapping of how each escape code changes the modifiers\nconst codeModifiers = Object.fromEntries(\n Object.entries({\n 1: m => ({ ...m, bold: true }),\n 3: m => ({ ...m, italic: true }),\n 4: m => ({ ...m, underline: true }),\n 22: ({ bold: _, ...m }) => m,\n 23: ({ italic: _, ...m }) => m,\n 24: ({ underline: _, ...m }) => m,\n 30: m => ({ ...m, foreground: 'black' }),\n 31: m => ({ ...m, foreground: 'red' }),\n 32: m => ({ ...m, foreground: 'green' }),\n 33: m => ({ ...m, foreground: 'yellow' }),\n 34: m => ({ ...m, foreground: 'blue' }),\n 35: m => ({ ...m, foreground: 'magenta' }),\n 36: m => ({ ...m, foreground: 'cyan' }),\n 37: m => ({ ...m, foreground: 'white' }),\n 39: ({ foreground: _, ...m }) => m,\n 90: m => ({ ...m, foreground: 'grey' }),\n 40: m => ({ ...m, background: 'black' }),\n 41: m => ({ ...m, background: 'red' }),\n 42: m => ({ ...m, background: 'green' }),\n 43: m => ({ ...m, background: 'yellow' }),\n 44: m => ({ ...m, background: 'blue' }),\n 45: m => ({ ...m, background: 'magenta' }),\n 46: m => ({ ...m, background: 'cyan' }),\n 47: m => ({ ...m, background: 'white' }),\n 49: ({ background: _, ...m }) => m,\n } as Record<string, (m: ChunkModifiers) => ChunkModifiers>).map(\n ([code, modifier]) => [`\\x1b[${code}m`, modifier],\n ),\n);\n\nexport type AnsiColor =\n | 'black'\n | 'red'\n | 'green'\n | 'yellow'\n | 'blue'\n | 'magenta'\n | 'cyan'\n | 'white'\n | 'grey';\n\nexport interface ChunkModifiers {\n foreground?: AnsiColor;\n background?: AnsiColor;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface AnsiChunk {\n text: string;\n modifiers: ChunkModifiers;\n}\n\nexport class AnsiLine {\n text: string;\n readonly lineNumber: number;\n readonly chunks: AnsiChunk[];\n\n constructor(lineNumber: number = 1, chunks: AnsiChunk[] = []) {\n this.lineNumber = lineNumber;\n this.chunks = chunks;\n this.text = chunks\n .map(c => c.text)\n .join('')\n .toLocaleLowerCase('en-US');\n }\n\n lastChunk(): AnsiChunk | undefined {\n return this.chunks[this.chunks.length - 1];\n }\n\n replaceLastChunk(newChunks?: AnsiChunk[]) {\n if (newChunks) {\n this.chunks.splice(this.chunks.length - 1, 1, ...newChunks);\n this.text = this.chunks\n .map(c => c.text)\n .join('')\n .toLocaleLowerCase('en-US');\n }\n }\n}\n\nexport class AnsiProcessor {\n private text: string = '';\n private lines: AnsiLine[] = [];\n\n /**\n * Processes a chunk of text while keeping internal state that optimizes\n * subsequent processing that appends to the text.\n */\n process(text: string): AnsiLine[] {\n if (this.text === text) {\n return this.lines;\n }\n\n if (this.text && text.startsWith(this.text)) {\n const lastLineIndex = this.lines.length > 0 ? this.lines.length - 1 : 0;\n const lastLine = this.lines[lastLineIndex] ?? new AnsiLine();\n const lastChunk = lastLine.lastChunk();\n\n const newLines = this.processLines(\n (lastChunk?.text ?? '') + text.slice(this.text.length),\n lastChunk?.modifiers,\n lastLine?.lineNumber,\n );\n lastLine.replaceLastChunk(newLines[0]?.chunks);\n\n this.lines[lastLineIndex] = lastLine;\n this.lines = this.lines.concat(newLines.slice(1));\n } else {\n this.lines = this.processLines(text);\n }\n this.text = text;\n\n return this.lines;\n }\n\n // Split a chunk of text up into lines and process each line individually\n private processLines = (\n text: string,\n modifiers: ChunkModifiers = {},\n startingLineNumber: number = 1,\n ): AnsiLine[] => {\n const lines: AnsiLine[] = [];\n\n let currentModifiers = modifiers;\n let currentLineNumber = startingLineNumber;\n\n let prevIndex = 0;\n newlineRegex.lastIndex = 0;\n for (;;) {\n const match = newlineRegex.exec(text);\n if (!match) {\n const chunks = this.processText(\n text.slice(prevIndex),\n currentModifiers,\n );\n lines.push(new AnsiLine(currentLineNumber, chunks));\n return lines;\n }\n\n const line = text.slice(prevIndex, match.index);\n prevIndex = match.index + match[0].length;\n\n const chunks = this.processText(line, currentModifiers);\n lines.push(new AnsiLine(currentLineNumber, chunks));\n\n // Modifiers that are active in the last chunk are carried over to the next line\n currentModifiers =\n chunks[chunks.length - 1].modifiers ?? currentModifiers;\n currentLineNumber += 1;\n }\n };\n\n // Processing of a one individual text chunk\n private processText = (\n fullText: string,\n modifiers: ChunkModifiers,\n ): AnsiChunk[] => {\n const chunks: AnsiChunk[] = [];\n\n let currentModifiers = modifiers;\n\n let prevIndex = 0;\n ansiRegex.lastIndex = 0;\n for (;;) {\n const match = ansiRegex.exec(fullText);\n if (!match) {\n chunks.push({\n text: fullText.slice(prevIndex),\n modifiers: currentModifiers,\n });\n return chunks;\n }\n\n const text = fullText.slice(prevIndex, match.index);\n chunks.push({ text, modifiers: currentModifiers });\n\n // For every escape code that we encounter we keep track of where the\n // next chunk of text starts, and what modifiers it has\n prevIndex = match.index + match[0].length;\n currentModifiers = this.processCode(match[0], currentModifiers);\n }\n };\n\n private processCode = (\n code: string,\n modifiers: ChunkModifiers,\n ): ChunkModifiers => {\n return codeModifiers[code]?.(modifiers) ?? modifiers;\n };\n}\n"],"names":["chunks"],"mappings":";;AAkBA,MAAM,YAAY,cAAA,EAAe;AACjC,MAAM,YAAA,GAAe,QAAA;AAGrB,MAAM,gBAAgB,MAAA,CAAO,WAAA;AAAA,EAC3B,OAAO,OAAA,CAAQ;AAAA,IACb,GAAG,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,MAAM,IAAA,EAAK,CAAA;AAAA,IAC5B,GAAG,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,QAAQ,IAAA,EAAK,CAAA;AAAA,IAC9B,GAAG,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,WAAW,IAAA,EAAK,CAAA;AAAA,IACjC,IAAI,CAAC,EAAE,MAAM,CAAA,EAAG,GAAG,GAAE,KAAM,CAAA;AAAA,IAC3B,IAAI,CAAC,EAAE,QAAQ,CAAA,EAAG,GAAG,GAAE,KAAM,CAAA;AAAA,IAC7B,IAAI,CAAC,EAAE,WAAW,CAAA,EAAG,GAAG,GAAE,KAAM,CAAA;AAAA,IAChC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,OAAA,EAAQ,CAAA;AAAA,IACtC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YAAY,KAAA,EAAM,CAAA;AAAA,IACpC,IAAI,CAAA,CAAA,MAAM,EAAE,GAAG,CAAA,EAAG,YA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AA,SAAA,CAAU,SAAA,GAAY,CAAA;AACtB,IAAA,WAAS;AACP,MAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,IAAA,CAAK,QAAQ,CAAA;AACrC,MAAA,IAAI,CAAC,KAAA,EAAO;AACV,QAAA,MAAA,CAAO,IAAA,CAAK;AAAA,UACV,IAAA,EAAM,QAAA,CAAS,KAAA,CAAM,SAAS,CAAA;AAAA,UAC9B,SAAA,EAAW;AAAA,SACZ,CAAA;AACD,QAAA,OAAO,MAAA;AAAA,MACT;AAEA,MAAA,MAAM,IAAA,GAAO,QAAA,CAAS,KAAA,CAAM,SAAA,EAAW,MAAM,KAAK,CAAA;AAClD,MAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,SAAA,EAAW,kBAAkB,CAAA;AAIjD,MAAA,SAAA,GAAY,KAAA,CAAM,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,CAAE,MAAA;AACnC,MAAA,gBAAA,GAAmB,IAAA,CAAK,WAAA,CAAY,KAAA,CAAM,CAAC,GAAG,gBAAgB,CAAA;AAAA,IAChE;AAAA,EACF,CAAA;AAAA,EAEQ,WAAA,GAAc,CACpB,IAAA,EACA,SAAA,KACmB;AACnB,IAAA,OAAO,aAAA,CAAc,IAAI,CAAA,GAAI,SAAS,CAAA,IAAK,SAAA;AAAA,EAC7C,CAAA;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -419,61 +419,87 @@ declare namespace DependencyGraphTypes {
419
419
  *
420
420
  * @public
421
421
  */
422
- enum Direction {
422
+ const Direction: {
423
423
  /**
424
424
  * Top to Bottom
425
425
  */
426
- TOP_BOTTOM = "TB",
426
+ readonly TOP_BOTTOM: "TB";
427
427
  /**
428
428
  * Bottom to Top
429
429
  */
430
- BOTTOM_TOP = "BT",
430
+ readonly BOTTOM_TOP: "BT";
431
431
  /**
432
432
  * Left to Right
433
433
  */
434
- LEFT_RIGHT = "LR",
434
+ readonly LEFT_RIGHT: "LR";
435
435
  /**
436
436
  * Right to Left
437
437
  */
438
- RIGHT_LEFT = "RL"
438
+ readonly RIGHT_LEFT: "RL";
439
+ };
440
+ /**
441
+ * @public
442
+ */
443
+ type Direction = (typeof Direction)[keyof typeof Direction];
444
+ /**
445
+ * @public
446
+ */
447
+ namespace Direction {
448
+ type TOP_BOTTOM = typeof Direction.TOP_BOTTOM;
449
+ type BOTTOM_TOP = typeof Direction.BOTTOM_TOP;
450
+ type LEFT_RIGHT = typeof Direction.LEFT_RIGHT;
451
+ type RIGHT_LEFT = typeof Direction.RIGHT_LEFT;
439
452
  }
440
453
  /**
441
454
  * Node alignment
442
455
  *
443
456
  * @public
444
457
  */
445
- enum Alignment {
458
+ const Alignment: {
446
459
  /**
447
460
  * Up Left
448
461
  */
449
- UP_LEFT = "UL",
462
+ readonly UP_LEFT: "UL";
450
463
  /**
451
464
  * Up Right
452
465
  */
453
- UP_RIGHT = "UR",
466
+ readonly UP_RIGHT: "UR";
454
467
  /**
455
468
  * Down Left
456
469
  */
457
- DOWN_LEFT = "DL",
470
+ readonly DOWN_LEFT: "DL";
458
471
  /**
459
472
  * Down Right
460
473
  */
461
- DOWN_RIGHT = "DR"
474
+ readonly DOWN_RIGHT: "DR";
475
+ };
476
+ /**
477
+ * @public
478
+ */
479
+ type Alignment = (typeof Alignment)[keyof typeof Alignment];
480
+ /**
481
+ * @public
482
+ */
483
+ namespace Alignment {
484
+ type UP_LEFT = typeof Alignment.UP_LEFT;
485
+ type UP_RIGHT = typeof Alignment.UP_RIGHT;
486
+ type DOWN_LEFT = typeof Alignment.DOWN_LEFT;
487
+ type DOWN_RIGHT = typeof Alignment.DOWN_RIGHT;
462
488
  }
463
489
  /**
464
490
  * Algorithm used to rand nodes in graph
465
491
  *
466
492
  * @public
467
493
  */
468
- enum Ranker {
494
+ const Ranker: {
469
495
  /**
470
496
  * {@link https://en.wikipedia.org/wiki/Network_simplex_algorithm | Network Simplex} algorithm
471
497
  */
472
- NETWORK_SIMPLEX = "network-simplex",
498
+ readonly NETWORK_SIMPLEX: "network-simplex";
473
499
  /**
474
500
  * Tight Tree algorithm
475
501
  */
476
- TIGHT_TREE = "tight-tree",
502
+ readonly TIGHT_TREE: "tight-tree";
477
503
  /**
478
504
  * Longest path algorithm
479
505
  *
@@ -481,17 +507,41 @@ declare namespace DependencyGraphTypes {
481
507
  *
482
508
  * Simplest and fastest
483
509
  */
484
- LONGEST_PATH = "longest-path"
510
+ readonly LONGEST_PATH: "longest-path";
511
+ };
512
+ /**
513
+ * @public
514
+ */
515
+ type Ranker = (typeof Ranker)[keyof typeof Ranker];
516
+ /**
517
+ * @public
518
+ */
519
+ namespace Ranker {
520
+ type NETWORK_SIMPLEX = typeof Ranker.NETWORK_SIMPLEX;
521
+ type TIGHT_TREE = typeof Ranker.TIGHT_TREE;
522
+ type LONGEST_PATH = typeof Ranker.LONGEST_PATH;
485
523
  }
486
524
  /**
487
525
  * Position of label in relation to the edge
488
526
  *
489
527
  * @public
490
528
  */
491
- enum LabelPosition {
492
- LEFT = "l",
493
- RIGHT = "r",
494
- CENTER = "c"
529
+ const LabelPosition: {
530
+ readonly LEFT: "l";
531
+ readonly RIGHT: "r";
532
+ readonly CENTER: "c";
533
+ };
534
+ /**
535
+ * @public
536
+ */
537
+ type LabelPosition = (typeof LabelPosition)[keyof typeof LabelPosition];
538
+ /**
539
+ * @public
540
+ */
541
+ namespace LabelPosition {
542
+ type LEFT = typeof LabelPosition.LEFT;
543
+ type RIGHT = typeof LabelPosition.RIGHT;
544
+ type CENTER = typeof LabelPosition.CENTER;
495
545
  }
496
546
  }
497
547
 
@@ -512,7 +562,7 @@ interface DependencyGraphProps<NodeData, EdgeData> extends SVGProps<SVGSVGElemen
512
562
  */
513
563
  nodes: DependencyGraphTypes.DependencyNode<NodeData>[];
514
564
  /**
515
- * Graph {@link DependencyGraphTypes.Direction | direction}
565
+ * Graph {@link DependencyGraphTypes.(Direction:namespace) | direction}
516
566
  *
517
567
  * @remarks
518
568
  *
@@ -520,7 +570,7 @@ interface DependencyGraphProps<NodeData, EdgeData> extends SVGProps<SVGSVGElemen
520
570
  */
521
571
  direction?: DependencyGraphTypes.Direction;
522
572
  /**
523
- * Node {@link DependencyGraphTypes.Alignment | alignment}
573
+ * Node {@link DependencyGraphTypes.(Alignment:namespace) | alignment}
524
574
  */
525
575
  align?: DependencyGraphTypes.Alignment;
526
576
  /**
@@ -568,7 +618,7 @@ interface DependencyGraphProps<NodeData, EdgeData> extends SVGProps<SVGSVGElemen
568
618
  */
569
619
  acyclicer?: 'greedy';
570
620
  /**
571
- * {@link DependencyGraphTypes.Ranker | Algorithm} used to rank nodes
621
+ * {@link DependencyGraphTypes.(Ranker:namespace) | Algorithm} used to rank nodes
572
622
  *
573
623
  * @remarks
574
624
  *
@@ -576,7 +626,7 @@ interface DependencyGraphProps<NodeData, EdgeData> extends SVGProps<SVGSVGElemen
576
626
  */
577
627
  ranker?: DependencyGraphTypes.Ranker;
578
628
  /**
579
- * {@link DependencyGraphTypes.LabelPosition | Position} of label in relation to edge
629
+ * {@link DependencyGraphTypes.(LabelPosition:namespace) | Position} of label in relation to edge
580
630
  *
581
631
  * @remarks
582
632
  *
@@ -2095,9 +2145,6 @@ type CustomProviderClassKey = 'form' | 'button';
2095
2145
  * @public
2096
2146
  */
2097
2147
  declare class UserIdentity implements IdentityApi {
2098
- private readonly identity;
2099
- private readonly authApi;
2100
- private readonly profile?;
2101
2148
  private profilePromise?;
2102
2149
  /**
2103
2150
  * Creates a new IdentityApi that acts as a Guest User.
@@ -2143,6 +2190,9 @@ declare class UserIdentity implements IdentityApi {
2143
2190
  */
2144
2191
  profile?: ProfileInfo;
2145
2192
  }): IdentityApi;
2193
+ private readonly identity;
2194
+ private readonly authApi;
2195
+ private readonly profile?;
2146
2196
  private constructor();
2147
2197
  /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getUserId} */
2148
2198
  getUserId(): string;
@@ -70,6 +70,11 @@ const useStyles = makeStyles(
70
70
  }),
71
71
  { name: "BackstageSidebar" }
72
72
  );
73
+ const State = {
74
+ Closed: 0,
75
+ Idle: 1,
76
+ Open: 2
77
+ };
73
78
  const DesktopSidebar = (props) => {
74
79
  const { sidebarConfig } = useContext(SidebarConfigContext);
75
80
  const {
@@ -83,7 +88,9 @@ const DesktopSidebar = (props) => {
83
88
  (theme) => theme.breakpoints.down("md"),
84
89
  { noSsr: true }
85
90
  );
86
- const [state, setState] = useState(0 /* Closed */);
91
+ const [state, setState] = useState(
92
+ State.Closed
93
+ );
87
94
  const hoverTimerRef = useRef();
88
95
  const { isPinned, toggleSidebarPinState } = useSidebarPinState();
89
96
  const handleOpen = () => {
@@ -94,12 +101,12 @@ const DesktopSidebar = (props) => {
94
101
  clearTimeout(hoverTimerRef.current);
95
102
  hoverTimerRef.current = void 0;
96
103
  }
97
- if (state !== 2 /* Open */ && !isSmallScreen) {
104
+ if (state !== State.Open && !isSmallScreen) {
98
105
  hoverTimerRef.current = window.setTimeout(() => {
99
106
  hoverTimerRef.current = void 0;
100
- setState(2 /* Open */);
107
+ setState(State.Open);
101
108
  }, openDelayMs);
102
- setState(1 /* Idle */);
109
+ setState(State.Idle);
103
110
  }
104
111
  };
105
112
  const handleClose = () => {
@@ -110,22 +117,22 @@ const DesktopSidebar = (props) => {
110
117
  clearTimeout(hoverTimerRef.current);
111
118
  hoverTimerRef.current = void 0;
112
119
  }
113
- if (state === 1 /* Idle */) {
114
- setState(0 /* Closed */);
115
- } else if (state === 2 /* Open */) {
120
+ if (state === State.Idle) {
121
+ setState(State.Closed);
122
+ } else if (state === State.Open) {
116
123
  hoverTimerRef.current = window.setTimeout(() => {
117
124
  hoverTimerRef.current = void 0;
118
- setState(0 /* Closed */);
125
+ setState(State.Closed);
119
126
  }, closeDelayMs);
120
127
  }
121
128
  };
122
- const isOpen = state === 2 /* Open */ && !isSmallScreen || isPinned;
129
+ const isOpen = state === State.Open && !isSmallScreen || isPinned;
123
130
  const setOpen = (open) => {
124
131
  if (open) {
125
- setState(2 /* Open */);
132
+ setState(State.Open);
126
133
  toggleSidebarPinState();
127
134
  } else {
128
- setState(0 /* Closed */);
135
+ setState(State.Closed);
129
136
  toggleSidebarPinState();
130
137
  }
131
138
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Bar.esm.js","sources":["../../../src/layout/Sidebar/Bar.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Box from '@material-ui/core/Box';\nimport Button from '@material-ui/core/Button';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport useMediaQuery from '@material-ui/core/useMediaQuery';\nimport classnames from 'classnames';\nimport { ReactNode, useContext, useRef, useState } from 'react';\n\nimport {\n makeSidebarConfig,\n makeSidebarSubmenuConfig,\n SidebarConfig,\n SidebarConfigContext,\n SidebarOptions,\n SubmenuConfig,\n SubmenuOptions,\n} from './config';\nimport { MobileSidebar } from './MobileSidebar';\nimport { useContent } from './Page';\nimport { SidebarOpenStateProvider } from './SidebarOpenStateContext';\nimport { useSidebarPinState } from './SidebarPinStateContext';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { coreComponentsTranslationRef } from '../../translation';\n\n/** @public */\nexport type SidebarClassKey = 'drawer' | 'drawerOpen';\nconst useStyles = makeStyles<Theme, { sidebarConfig: SidebarConfig }>(\n theme => ({\n root: {\n left: 0,\n top: 0,\n bottom: 0,\n zIndex: theme.zIndex.appBar,\n position: 'fixed',\n },\n drawer: {\n display: 'flex',\n flexFlow: 'column nowrap',\n alignItems: 'flex-start',\n left: 0,\n top: 0,\n bottom: 0,\n position: 'absolute',\n background: theme.palette.navigation.background,\n overflowX: 'hidden',\n msOverflowStyle: 'none',\n scrollbarWidth: 'none',\n transition: theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: theme.transitions.duration.shortest,\n }),\n '& > *': {\n flexShrink: 0,\n },\n '&::-webkit-scrollbar': {\n display: 'none',\n },\n '@media print': {\n display: 'none',\n },\n },\n drawerWidth: props => ({\n width: props.sidebarConfig.drawerWidthClosed,\n }),\n drawerOpen: props => ({\n width: props.sidebarConfig.drawerWidthOpen,\n transition: theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: theme.transitions.duration.shorter,\n }),\n }),\n visuallyHidden: {\n top: 0,\n position: 'absolute',\n zIndex: 1000,\n transform: 'translateY(-200%)',\n '&:focus': {\n transform: 'translateY(5px)',\n },\n },\n }),\n { name: 'BackstageSidebar' },\n);\n\nenum State {\n Closed,\n Idle,\n Open,\n}\n\n/** @public */\nexport type SidebarProps = {\n openDelayMs?: number;\n closeDelayMs?: number;\n sidebarOptions?: SidebarOptions;\n submenuOptions?: SubmenuOptions;\n disableExpandOnHover?: boolean;\n children?: ReactNode;\n};\n\nexport type DesktopSidebarProps = {\n openDelayMs?: number;\n closeDelayMs?: number;\n disableExpandOnHover?: boolean;\n children?: ReactNode;\n};\n\n/**\n * Places the Sidebar & wraps the children providing context weather the `Sidebar` is open or not.\n *\n * Handles & delays hover events for expanding the `Sidebar`\n *\n * @param props `disableExpandOnHover` disables the default hover behaviour;\n * `openDelayMs` & `closeDelayMs` set delay until sidebar will open/close on hover\n * @returns\n * @internal\n */\nconst DesktopSidebar = (props: DesktopSidebarProps) => {\n const { sidebarConfig } = useContext(SidebarConfigContext);\n const {\n openDelayMs = sidebarConfig.defaultOpenDelayMs,\n closeDelayMs = sidebarConfig.defaultCloseDelayMs,\n disableExpandOnHover,\n children,\n } = props;\n\n const classes = useStyles({ sidebarConfig });\n const isSmallScreen = useMediaQuery<Theme>(\n theme => theme.breakpoints.down('md'),\n { noSsr: true },\n );\n const [state, setState] = useState(State.Closed);\n const hoverTimerRef = useRef<number>();\n const { isPinned, toggleSidebarPinState } = useSidebarPinState();\n\n const handleOpen = () => {\n if (isPinned || disableExpandOnHover) {\n return;\n }\n if (hoverTimerRef.current) {\n clearTimeout(hoverTimerRef.current);\n hoverTimerRef.current = undefined;\n }\n if (state !== State.Open && !isSmallScreen) {\n hoverTimerRef.current = window.setTimeout(() => {\n hoverTimerRef.current = undefined;\n setState(State.Open);\n }, openDelayMs);\n\n setState(State.Idle);\n }\n };\n\n const handleClose = () => {\n if (isPinned || disableExpandOnHover) {\n return;\n }\n if (hoverTimerRef.current) {\n clearTimeout(hoverTimerRef.current);\n hoverTimerRef.current = undefined;\n }\n if (state === State.Idle) {\n setState(State.Closed);\n } else if (state === State.Open) {\n hoverTimerRef.current = window.setTimeout(() => {\n hoverTimerRef.current = undefined;\n setState(State.Closed);\n }, closeDelayMs);\n }\n };\n\n const isOpen = (state === State.Open && !isSmallScreen) || isPinned;\n\n /**\n * Close/Open Sidebar directly without delays. Also toggles `SidebarPinState` to avoid hidden content behind Sidebar.\n */\n const setOpen = (open: boolean) => {\n if (open) {\n setState(State.Open);\n toggleSidebarPinState();\n } else {\n setState(State.Closed);\n toggleSidebarPinState();\n }\n };\n\n return (\n <nav style={{}} aria-label=\"sidebar nav\">\n <A11ySkipSidebar />\n <SidebarOpenStateProvider value={{ isOpen, setOpen }}>\n <Box\n className={classes.root}\n data-testid=\"sidebar-root\"\n onMouseEnter={disableExpandOnHover ? () => {} : handleOpen}\n onFocus={disableExpandOnHover ? () => {} : handleOpen}\n onMouseLeave={disableExpandOnHover ? () => {} : handleClose}\n onBlur={disableExpandOnHover ? () => {} : handleClose}\n >\n <Box\n className={classnames(classes.drawer, classes.drawerWidth, {\n [classes.drawerOpen]: isOpen,\n })}\n >\n {children}\n </Box>\n </Box>\n </SidebarOpenStateProvider>\n </nav>\n );\n};\n\n/**\n * Passing children into the desktop or mobile sidebar depending on the context\n *\n * @public\n */\nexport const Sidebar = (props: SidebarProps) => {\n const sidebarConfig: SidebarConfig = makeSidebarConfig(\n props.sidebarOptions ?? {},\n );\n const submenuConfig: SubmenuConfig = makeSidebarSubmenuConfig(\n props.submenuOptions ?? {},\n );\n const { children, disableExpandOnHover, openDelayMs, closeDelayMs } = props;\n const { isMobile } = useSidebarPinState();\n\n return isMobile ? (\n <MobileSidebar>{children}</MobileSidebar>\n ) : (\n <SidebarConfigContext.Provider value={{ sidebarConfig, submenuConfig }}>\n <DesktopSidebar\n openDelayMs={openDelayMs}\n closeDelayMs={closeDelayMs}\n disableExpandOnHover={disableExpandOnHover}\n >\n {children}\n </DesktopSidebar>\n </SidebarConfigContext.Provider>\n );\n};\n\nfunction A11ySkipSidebar() {\n const { sidebarConfig } = useContext(SidebarConfigContext);\n const { focusContent, contentRef } = useContent();\n const classes = useStyles({ sidebarConfig });\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n if (!contentRef?.current) {\n return null;\n }\n return (\n <Button\n onClick={focusContent}\n variant=\"contained\"\n className={classnames(classes.visuallyHidden)}\n >\n {t('skipToContent')}\n </Button>\n );\n}\n"],"names":["classnames"],"mappings":";;;;;;;;;;;;;;;AAyCA,MAAM,SAAA,GAAY,UAAA;AAAA,EAChB,CAAA,KAAA,MAAU;AAAA,IACR,IAAA,EAAM;AAAA,MACJ,IAAA,EAAM,CAAA;AAAA,MACN,GAAA,EAAK,CAAA;AAAA,MACL,MAAA,EAAQ,CAAA;AAAA,MACR,MAAA,EAAQ,MAAM,MAAA,CAAO,MAAA;AAAA,MACrB,QAAA,EAAU;AAAA,KACZ;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,OAAA,EAAS,MAAA;AAAA,MACT,QAAA,EAAU,eAAA;AAAA,MACV,UAAA,EAAY,YAAA;AAAA,MACZ,IAAA,EAAM,CAAA;AAAA,MACN,GAAA,EAAK,CAAA;AAAA,MACL,MAAA,EAAQ,CAAA;AAAA,MACR,QAAA,EAAU,UAAA;AAAA,MACV,UAAA,EAAY,KAAA,CA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AAA;AACzD,EAAA,MAAM,EAAE,YAAA,EAAc,UAAA,EAAW,GAAI,UAAA,EAAW;AAChD,EAAA,MAAM,OAAA,GAAU,SAAA,CAAU,EAAE,aAAA,EAAe,CAAA;AAC3C,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,4BAA4B,CAAA;AAE5D,EAAA,IAAI,CAAC,YAAY,OAAA,EAAS;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,uBACE,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,OAAA,EAAS,YAAA;AAAA,MACT,OAAA,EAAQ,WAAA;AAAA,MACR,SAAA,EAAWA,UAAA,CAAW,OAAA,CAAQ,cAAc,CAAA;AAAA,MAE3C,YAAE,eAAe;AAAA;AAAA,GACpB;AAEJ;;;;"}
1
+ {"version":3,"file":"Bar.esm.js","sources":["../../../src/layout/Sidebar/Bar.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Box from '@material-ui/core/Box';\nimport Button from '@material-ui/core/Button';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport useMediaQuery from '@material-ui/core/useMediaQuery';\nimport classnames from 'classnames';\nimport { ReactNode, useContext, useRef, useState } from 'react';\n\nimport {\n makeSidebarConfig,\n makeSidebarSubmenuConfig,\n SidebarConfig,\n SidebarConfigContext,\n SidebarOptions,\n SubmenuConfig,\n SubmenuOptions,\n} from './config';\nimport { MobileSidebar } from './MobileSidebar';\nimport { useContent } from './Page';\nimport { SidebarOpenStateProvider } from './SidebarOpenStateContext';\nimport { useSidebarPinState } from './SidebarPinStateContext';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { coreComponentsTranslationRef } from '../../translation';\n\n/** @public */\nexport type SidebarClassKey = 'drawer' | 'drawerOpen';\nconst useStyles = makeStyles<Theme, { sidebarConfig: SidebarConfig }>(\n theme => ({\n root: {\n left: 0,\n top: 0,\n bottom: 0,\n zIndex: theme.zIndex.appBar,\n position: 'fixed',\n },\n drawer: {\n display: 'flex',\n flexFlow: 'column nowrap',\n alignItems: 'flex-start',\n left: 0,\n top: 0,\n bottom: 0,\n position: 'absolute',\n background: theme.palette.navigation.background,\n overflowX: 'hidden',\n msOverflowStyle: 'none',\n scrollbarWidth: 'none',\n transition: theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: theme.transitions.duration.shortest,\n }),\n '& > *': {\n flexShrink: 0,\n },\n '&::-webkit-scrollbar': {\n display: 'none',\n },\n '@media print': {\n display: 'none',\n },\n },\n drawerWidth: props => ({\n width: props.sidebarConfig.drawerWidthClosed,\n }),\n drawerOpen: props => ({\n width: props.sidebarConfig.drawerWidthOpen,\n transition: theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: theme.transitions.duration.shorter,\n }),\n }),\n visuallyHidden: {\n top: 0,\n position: 'absolute',\n zIndex: 1000,\n transform: 'translateY(-200%)',\n '&:focus': {\n transform: 'translateY(5px)',\n },\n },\n }),\n { name: 'BackstageSidebar' },\n);\n\nconst State = {\n Closed: 0,\n Idle: 1,\n Open: 2,\n} as const;\n\n/** @public */\nexport type SidebarProps = {\n openDelayMs?: number;\n closeDelayMs?: number;\n sidebarOptions?: SidebarOptions;\n submenuOptions?: SubmenuOptions;\n disableExpandOnHover?: boolean;\n children?: ReactNode;\n};\n\nexport type DesktopSidebarProps = {\n openDelayMs?: number;\n closeDelayMs?: number;\n disableExpandOnHover?: boolean;\n children?: ReactNode;\n};\n\n/**\n * Places the Sidebar & wraps the children providing context weather the `Sidebar` is open or not.\n *\n * Handles & delays hover events for expanding the `Sidebar`\n *\n * @param props `disableExpandOnHover` disables the default hover behaviour;\n * `openDelayMs` & `closeDelayMs` set delay until sidebar will open/close on hover\n * @returns\n * @internal\n */\nconst DesktopSidebar = (props: DesktopSidebarProps) => {\n const { sidebarConfig } = useContext(SidebarConfigContext);\n const {\n openDelayMs = sidebarConfig.defaultOpenDelayMs,\n closeDelayMs = sidebarConfig.defaultCloseDelayMs,\n disableExpandOnHover,\n children,\n } = props;\n\n const classes = useStyles({ sidebarConfig });\n const isSmallScreen = useMediaQuery<Theme>(\n theme => theme.breakpoints.down('md'),\n { noSsr: true },\n );\n const [state, setState] = useState<(typeof State)[keyof typeof State]>(\n State.Closed,\n );\n const hoverTimerRef = useRef<number>();\n const { isPinned, toggleSidebarPinState } = useSidebarPinState();\n\n const handleOpen = () => {\n if (isPinned || disableExpandOnHover) {\n return;\n }\n if (hoverTimerRef.current) {\n clearTimeout(hoverTimerRef.current);\n hoverTimerRef.current = undefined;\n }\n if (state !== State.Open && !isSmallScreen) {\n hoverTimerRef.current = window.setTimeout(() => {\n hoverTimerRef.current = undefined;\n setState(State.Open);\n }, openDelayMs);\n\n setState(State.Idle);\n }\n };\n\n const handleClose = () => {\n if (isPinned || disableExpandOnHover) {\n return;\n }\n if (hoverTimerRef.current) {\n clearTimeout(hoverTimerRef.current);\n hoverTimerRef.current = undefined;\n }\n if (state === State.Idle) {\n setState(State.Closed);\n } else if (state === State.Open) {\n hoverTimerRef.current = window.setTimeout(() => {\n hoverTimerRef.current = undefined;\n setState(State.Closed);\n }, closeDelayMs);\n }\n };\n\n const isOpen = (state === State.Open && !isSmallScreen) || isPinned;\n\n /**\n * Close/Open Sidebar directly without delays. Also toggles `SidebarPinState` to avoid hidden content behind Sidebar.\n */\n const setOpen = (open: boolean) => {\n if (open) {\n setState(State.Open);\n toggleSidebarPinState();\n } else {\n setState(State.Closed);\n toggleSidebarPinState();\n }\n };\n\n return (\n <nav style={{}} aria-label=\"sidebar nav\">\n <A11ySkipSidebar />\n <SidebarOpenStateProvider value={{ isOpen, setOpen }}>\n <Box\n className={classes.root}\n data-testid=\"sidebar-root\"\n onMouseEnter={disableExpandOnHover ? () => {} : handleOpen}\n onFocus={disableExpandOnHover ? () => {} : handleOpen}\n onMouseLeave={disableExpandOnHover ? () => {} : handleClose}\n onBlur={disableExpandOnHover ? () => {} : handleClose}\n >\n <Box\n className={classnames(classes.drawer, classes.drawerWidth, {\n [classes.drawerOpen]: isOpen,\n })}\n >\n {children}\n </Box>\n </Box>\n </SidebarOpenStateProvider>\n </nav>\n );\n};\n\n/**\n * Passing children into the desktop or mobile sidebar depending on the context\n *\n * @public\n */\nexport const Sidebar = (props: SidebarProps) => {\n const sidebarConfig: SidebarConfig = makeSidebarConfig(\n props.sidebarOptions ?? {},\n );\n const submenuConfig: SubmenuConfig = makeSidebarSubmenuConfig(\n props.submenuOptions ?? {},\n );\n const { children, disableExpandOnHover, openDelayMs, closeDelayMs } = props;\n const { isMobile } = useSidebarPinState();\n\n return isMobile ? (\n <MobileSidebar>{children}</MobileSidebar>\n ) : (\n <SidebarConfigContext.Provider value={{ sidebarConfig, submenuConfig }}>\n <DesktopSidebar\n openDelayMs={openDelayMs}\n closeDelayMs={closeDelayMs}\n disableExpandOnHover={disableExpandOnHover}\n >\n {children}\n </DesktopSidebar>\n </SidebarConfigContext.Provider>\n );\n};\n\nfunction A11ySkipSidebar() {\n const { sidebarConfig } = useContext(SidebarConfigContext);\n const { focusContent, contentRef } = useContent();\n const classes = useStyles({ sidebarConfig });\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n if (!contentRef?.current) {\n return null;\n }\n return (\n <Button\n onClick={focusContent}\n variant=\"contained\"\n className={classnames(classes.visuallyHidden)}\n >\n {t('skipToContent')}\n </Button>\n );\n}\n"],"names":["classnames"],"mappings":";;;;;;;;;;;;;;;AAyCA,MAAM,SAAA,GAAY,UAAA;AAAA,EAChB,CAAA,KAAA,MAAU;AAAA,IACR,IAAA,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+ SIDEBAR_PIN_STATE: "sidebarPinState"
3
+ };
1
4
  const LocalStorage = {
2
5
  getSidebarPinState() {
3
6
  let value;
4
7
  try {
5
8
  value = JSON.parse(
6
- window.localStorage.getItem("sidebarPinState" /* SIDEBAR_PIN_STATE */) || "true"
9
+ window.localStorage.getItem(LocalStorageKeys.SIDEBAR_PIN_STATE) || "true"
7
10
  );
8
11
  } catch {
9
12
  return true;
@@ -12,7 +15,7 @@ const LocalStorage = {
12
15
  },
13
16
  setSidebarPinState(state) {
14
17
  return window.localStorage.setItem(
15
- "sidebarPinState" /* SIDEBAR_PIN_STATE */,
18
+ LocalStorageKeys.SIDEBAR_PIN_STATE,
16
19
  JSON.stringify(state)
17
20
  );
18
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"localStorage.esm.js","sources":["../../../src/layout/Sidebar/localStorage.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nenum LocalStorageKeys {\n SIDEBAR_PIN_STATE = 'sidebarPinState',\n}\n\nexport const LocalStorage = {\n getSidebarPinState(): boolean {\n let value;\n try {\n value = JSON.parse(\n window.localStorage.getItem(LocalStorageKeys.SIDEBAR_PIN_STATE) ||\n 'true',\n );\n } catch {\n return true;\n }\n return !!value;\n },\n setSidebarPinState(state: boolean) {\n return window.localStorage.setItem(\n LocalStorageKeys.SIDEBAR_PIN_STATE,\n JSON.stringify(state),\n );\n },\n};\n"],"names":[],"mappings":"AAoBO,MAAM,YAAA,GAAe;AAAA,EAC1B,kBAAA,GAA8B;AAC5B,IAAA,IAAI,KAAA;AACJ,IAAA,IAAI;AACF,MAAA,KAAA,GAAQ,IAAA,CAAK,KAAA;AAAA,QACX,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,iBAAA,yBAAkC,IAC5D;AAAA,OACJ;AAAA,IACF,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,OAAO,CAAC,CAAC,KAAA;AAAA,EACX,CAAA;AAAA,EACA,mBAAmB,KAAA,EAAgB;AACjC,IAAA,OAAO,OAAO,YAAA,CAAa,OAAA;AAAA,MACzB,iBAAA;AAAA,MACA,IAAA,CAAK,UAAU,KAAK;AAAA,KACtB;AAAA,EACF;AACF;;;;"}
1
+ {"version":3,"file":"localStorage.esm.js","sources":["../../../src/layout/Sidebar/localStorage.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst LocalStorageKeys = {\n SIDEBAR_PIN_STATE: 'sidebarPinState',\n} as const;\n\nexport const LocalStorage = {\n getSidebarPinState(): boolean {\n let value;\n try {\n value = JSON.parse(\n window.localStorage.getItem(LocalStorageKeys.SIDEBAR_PIN_STATE) ||\n 'true',\n );\n } catch {\n return true;\n }\n return !!value;\n },\n setSidebarPinState(state: boolean) {\n return window.localStorage.setItem(\n LocalStorageKeys.SIDEBAR_PIN_STATE,\n JSON.stringify(state),\n );\n },\n};\n"],"names":[],"mappings":"AAgBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,iBAAA,EAAmB;AACrB,CAAA;AAEO,MAAM,YAAA,GAAe;AAAA,EAC1B,kBAAA,GAA8B;AAC5B,IAAA,IAAI,KAAA;AACJ,IAAA,IAAI;AACF,MAAA,KAAA,GAAQ,IAAA,CAAK,KAAA;AAAA,QACX,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,gBAAA,CAAiB,iBAAiB,CAAA,IAC5D;AAAA,OACJ;AAAA,IACF,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,OAAO,CAAC,CAAC,KAAA;AAAA,EACX,CAAA;AAAA,EACA,mBAAmB,KAAA,EAAgB;AACjC,IAAA,OAAO,OAAO,YAAA,CAAa,OAAA;AAAA,MACzB,gBAAA,CAAiB,iBAAA;AAAA,MACjB,IAAA,CAAK,UAAU,KAAK;AAAA,KACtB;AAAA,EACF;AACF;;;;"}
@@ -2,11 +2,6 @@ import { GuestUserIdentity } from './GuestUserIdentity.esm.js';
2
2
  import { LegacyUserIdentity } from './LegacyUserIdentity.esm.js';
3
3
 
4
4
  class UserIdentity {
5
- constructor(identity, authApi, profile) {
6
- this.identity = identity;
7
- this.authApi = authApi;
8
- this.profile = profile;
9
- }
10
5
  profilePromise;
11
6
  /**
12
7
  * Creates a new IdentityApi that acts as a Guest User.
@@ -33,6 +28,14 @@ class UserIdentity {
33
28
  static create(options) {
34
29
  return new UserIdentity(options.identity, options.authApi, options.profile);
35
30
  }
31
+ identity;
32
+ authApi;
33
+ profile;
34
+ constructor(identity, authApi, profile) {
35
+ this.identity = identity;
36
+ this.authApi = authApi;
37
+ this.profile = profile;
38
+ }
36
39
  /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getUserId} */
37
40
  getUserId() {
38
41
  const ref = this.identity.userEntityRef;
@@ -1 +1 @@
1
- {"version":3,"file":"UserIdentity.esm.js","sources":["../../../src/layout/SignInPage/UserIdentity.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n IdentityApi,\n ProfileInfo,\n ProfileInfoApi,\n BackstageUserIdentity,\n BackstageIdentityApi,\n SessionApi,\n} from '@backstage/core-plugin-api';\n\nimport { GuestUserIdentity } from './GuestUserIdentity';\nimport { LegacyUserIdentity } from './LegacyUserIdentity';\n\n// TODO(Rugvip): This and the other IdentityApi implementations still implement\n// the old removed methods. This is to allow for backwards compatibility\n// with old plugins that still consume this API. We will leave these in\n// place as a hidden compatibility for a couple of months.\n// The AppIdentityProxy warns in case any of these methods are called.\n\n/**\n * An implementation of the IdentityApi that is constructed using\n * various backstage user identity representations.\n *\n * @public\n */\nexport class UserIdentity implements IdentityApi {\n private profilePromise?: Promise<ProfileInfo>;\n /**\n * Creates a new IdentityApi that acts as a Guest User.\n *\n * @public\n */\n static createGuest(): IdentityApi {\n return new GuestUserIdentity();\n }\n\n /**\n * Creates a new IdentityApi using a legacy SignInResult object.\n *\n * @public\n */\n static fromLegacy(result: {\n /**\n * User ID that will be returned by the IdentityApi\n */\n userId: string;\n\n profile: ProfileInfo;\n\n /**\n * Function used to retrieve an ID token for the signed in user.\n */\n getIdToken?: () => Promise<string>;\n\n /**\n * Sign out handler that will be called if the user requests to sign out.\n */\n signOut?: () => Promise<void>;\n }): IdentityApi {\n return LegacyUserIdentity.fromResult(result);\n }\n\n /**\n * Creates a new IdentityApi implementation using a user identity\n * and an auth API that will be used to request backstage tokens.\n *\n * @public\n */\n static create(options: {\n identity: BackstageUserIdentity;\n authApi: ProfileInfoApi & BackstageIdentityApi & SessionApi;\n /**\n * Passing a profile synchronously allows the deprecated `getProfile` method to be\n * called by consumers of the {@link @backstage/core-plugin-api#IdentityApi}. If you\n * do not have any consumers of that method then this is safe to leave out.\n *\n * @deprecated Only provide this if you have plugins that call the synchronous `getProfile` method, which is also deprecated.\n */\n profile?: ProfileInfo;\n }): IdentityApi {\n return new UserIdentity(options.identity, options.authApi, options.profile);\n }\n\n private constructor(\n private readonly identity: BackstageUserIdentity,\n private readonly authApi: ProfileInfoApi &\n BackstageIdentityApi &\n SessionApi,\n private readonly profile?: ProfileInfo,\n ) {}\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getUserId} */\n getUserId(): string {\n const ref = this.identity.userEntityRef;\n const match = /^([^:/]+:)?([^:/]+\\/)?([^:/]+)$/.exec(ref);\n if (!match) {\n throw new TypeError(`Invalid user entity reference \"${ref}\"`);\n }\n\n return match[3];\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getIdToken} */\n async getIdToken(): Promise<string | undefined> {\n const identity = await this.authApi.getBackstageIdentity();\n return identity!.token;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getProfile} */\n getProfile(): ProfileInfo {\n if (!this.profile) {\n throw new Error(\n 'The identity API does not implement synchronous profile fetching, use getProfileInfo() instead',\n );\n }\n return this.profile;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getProfileInfo} */\n async getProfileInfo(): Promise<ProfileInfo> {\n if (this.profilePromise) {\n return await this.profilePromise;\n }\n\n try {\n this.profilePromise = this.authApi.getProfile() as Promise<ProfileInfo>;\n return await this.profilePromise;\n } catch (ex) {\n this.profilePromise = undefined;\n throw ex;\n }\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getBackstageIdentity} */\n async getBackstageIdentity(): Promise<BackstageUserIdentity> {\n return this.identity;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getCredentials} */\n async getCredentials(): Promise<{ token?: string | undefined }> {\n const identity = await this.authApi.getBackstageIdentity();\n return { token: identity!.token };\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.signOut} */\n async signOut(): Promise<void> {\n return this.authApi.signOut();\n }\n}\n"],"names":[],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AAC,KAAK,OAAA,EAAS;AACjB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AACA,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA,EAGA,MAAM,cAAA,GAAuC;AAC3C,IAAA,IAAI,KAAK,cAAA,EAAgB;AACvB,MAAA,OAAO,MAAM,IAAA,CAAK,cAAA;AAAA,IACpB;AAEA,IAAA,IAAI;AACF,MAAA,IAAA,CAAK,cAAA,GAAiB,IAAA,CAAK,OAAA,CAAQ,UAAA,EAAW;AAC9C,MAAA,OAAO,MAAM,IAAA,CAAK,cAAA;AAAA,IACpB,SAAS,EAAA,EAAI;AACX,MAAA,IAAA,CAAK,cAAA,GAAiB,MAAA;AACtB,MAAA,MAAM,EAAA;AAAA,IACR;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,oBAAA,GAAuD;AAC3D,IAAA,OAAO,IAAA,CAAK,QAAA;AAAA,EACd;AAAA;AAAA,EAGA,MAAM,cAAA,GAA0D;AAC9D,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,OAAA,CAAQ,oBAAA,EAAqB;AACzD,IAAA,OAAO,EAAE,KAAA,EAAO,QAAA,CAAU,KAAA,EAAM;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,OAAA,GAAyB;AAC7B,IAAA,OAAO,IAAA,CAAK,QAAQ,OAAA,EAAQ;AAAA,EAC9B;AACF;;;;"}
1
+ {"version":3,"file":"UserIdentity.esm.js","sources":["../../../src/layout/SignInPage/UserIdentity.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n IdentityApi,\n ProfileInfo,\n ProfileInfoApi,\n BackstageUserIdentity,\n BackstageIdentityApi,\n SessionApi,\n} from '@backstage/core-plugin-api';\n\nimport { GuestUserIdentity } from './GuestUserIdentity';\nimport { LegacyUserIdentity } from './LegacyUserIdentity';\n\n// TODO(Rugvip): This and the other IdentityApi implementations still implement\n// the old removed methods. This is to allow for backwards compatibility\n// with old plugins that still consume this API. We will leave these in\n// place as a hidden compatibility for a couple of months.\n// The AppIdentityProxy warns in case any of these methods are called.\n\n/**\n * An implementation of the IdentityApi that is constructed using\n * various backstage user identity representations.\n *\n * @public\n */\nexport class UserIdentity implements IdentityApi {\n private profilePromise?: Promise<ProfileInfo>;\n /**\n * Creates a new IdentityApi that acts as a Guest User.\n *\n * @public\n */\n static createGuest(): IdentityApi {\n return new GuestUserIdentity();\n }\n\n /**\n * Creates a new IdentityApi using a legacy SignInResult object.\n *\n * @public\n */\n static fromLegacy(result: {\n /**\n * User ID that will be returned by the IdentityApi\n */\n userId: string;\n\n profile: ProfileInfo;\n\n /**\n * Function used to retrieve an ID token for the signed in user.\n */\n getIdToken?: () => Promise<string>;\n\n /**\n * Sign out handler that will be called if the user requests to sign out.\n */\n signOut?: () => Promise<void>;\n }): IdentityApi {\n return LegacyUserIdentity.fromResult(result);\n }\n\n /**\n * Creates a new IdentityApi implementation using a user identity\n * and an auth API that will be used to request backstage tokens.\n *\n * @public\n */\n static create(options: {\n identity: BackstageUserIdentity;\n authApi: ProfileInfoApi & BackstageIdentityApi & SessionApi;\n /**\n * Passing a profile synchronously allows the deprecated `getProfile` method to be\n * called by consumers of the {@link @backstage/core-plugin-api#IdentityApi}. If you\n * do not have any consumers of that method then this is safe to leave out.\n *\n * @deprecated Only provide this if you have plugins that call the synchronous `getProfile` method, which is also deprecated.\n */\n profile?: ProfileInfo;\n }): IdentityApi {\n return new UserIdentity(options.identity, options.authApi, options.profile);\n }\n\n private readonly identity: BackstageUserIdentity;\n private readonly authApi: ProfileInfoApi & BackstageIdentityApi & SessionApi;\n private readonly profile?: ProfileInfo;\n\n private constructor(\n identity: BackstageUserIdentity,\n authApi: ProfileInfoApi & BackstageIdentityApi & SessionApi,\n profile?: ProfileInfo,\n ) {\n this.identity = identity;\n this.authApi = authApi;\n this.profile = profile;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getUserId} */\n getUserId(): string {\n const ref = this.identity.userEntityRef;\n const match = /^([^:/]+:)?([^:/]+\\/)?([^:/]+)$/.exec(ref);\n if (!match) {\n throw new TypeError(`Invalid user entity reference \"${ref}\"`);\n }\n\n return match[3];\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getIdToken} */\n async getIdToken(): Promise<string | undefined> {\n const identity = await this.authApi.getBackstageIdentity();\n return identity!.token;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getProfile} */\n getProfile(): ProfileInfo {\n if (!this.profile) {\n throw new Error(\n 'The identity API does not implement synchronous profile fetching, use getProfileInfo() instead',\n );\n }\n return this.profile;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getProfileInfo} */\n async getProfileInfo(): Promise<ProfileInfo> {\n if (this.profilePromise) {\n return await this.profilePromise;\n }\n\n try {\n this.profilePromise = this.authApi.getProfile() as Promise<ProfileInfo>;\n return await this.profilePromise;\n } catch (ex) {\n this.profilePromise = undefined;\n throw ex;\n }\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getBackstageIdentity} */\n async getBackstageIdentity(): Promise<BackstageUserIdentity> {\n return this.identity;\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getCredentials} */\n async getCredentials(): Promise<{ token?: string | undefined }> {\n const identity = await this.authApi.getBackstageIdentity();\n return { token: identity!.token };\n }\n\n /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.signOut} */\n async signOut(): Promise<void> {\n return this.authApi.signOut();\n }\n}\n"],"names":[],"mappings":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EAGA,UAAA,GAA0B;AACxB,IAAA,IAAI,CAAC,KAAK,OAAA,EAAS;AACjB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AACA,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA,EAGA,MAAM,cAAA,GAAuC;AAC3C,IAAA,IAAI,KAAK,cAAA,EAAgB;AACvB,MAAA,OAAO,MAAM,IAAA,CAAK,cAAA;AAAA,IACpB;AAEA,IAAA,IAAI;AACF,MAAA,IAAA,CAAK,cAAA,GAAiB,IAAA,CAAK,OAAA,CAAQ,UAAA,EAAW;AAC9C,MAAA,OAAO,MAAM,IAAA,CAAK,cAAA;AAAA,IACpB,SAAS,EAAA,EAAI;AACX,MAAA,IAAA,CAAK,cAAA,GAAiB,MAAA;AACtB,MAAA,MAAM,EAAA;AAAA,IACR;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,oBAAA,GAAuD;AAC3D,IAAA,OAAO,IAAA,CAAK,QAAA;AAAA,EACd;AAAA;AAAA,EAGA,MAAM,cAAA,GAA0D;AAC9D,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,OAAA,CAAQ,oBAAA,EAAqB;AACzD,IAAA,OAAO,EAAE,KAAA,EAAO,QAAA,CAAU,KAAA,EAAM;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,OAAA,GAAyB;AAC7B,IAAA,OAAO,IAAA,CAAK,QAAQ,OAAA,EAAQ;AAAA,EAC9B;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/core-components",
3
- "version": "0.18.2",
3
+ "version": "0.18.3-next.1",
4
4
  "description": "Core components used by Backstage plugins and apps",
5
5
  "backstage": {
6
6
  "role": "web-library"
@@ -66,11 +66,11 @@
66
66
  "test": "backstage-cli package test"
67
67
  },
68
68
  "dependencies": {
69
- "@backstage/config": "^1.3.5",
70
- "@backstage/core-plugin-api": "^1.11.1",
71
- "@backstage/errors": "^1.2.7",
72
- "@backstage/theme": "^0.7.0",
73
- "@backstage/version-bridge": "^1.0.11",
69
+ "@backstage/config": "1.3.6-next.0",
70
+ "@backstage/core-plugin-api": "1.11.2-next.1",
71
+ "@backstage/errors": "1.2.7",
72
+ "@backstage/theme": "0.7.0",
73
+ "@backstage/version-bridge": "1.0.11",
74
74
  "@dagrejs/dagre": "^1.1.4",
75
75
  "@date-io/core": "^1.3.13",
76
76
  "@material-table/core": "^3.1.0",
@@ -107,10 +107,10 @@
107
107
  "zod": "^3.22.4"
108
108
  },
109
109
  "devDependencies": {
110
- "@backstage/app-defaults": "^1.7.1",
111
- "@backstage/cli": "^0.34.4",
112
- "@backstage/core-app-api": "^1.19.1",
113
- "@backstage/test-utils": "^1.7.12",
110
+ "@backstage/app-defaults": "1.7.2-next.0",
111
+ "@backstage/cli": "0.34.5-next.1",
112
+ "@backstage/core-app-api": "1.19.2-next.1",
113
+ "@backstage/test-utils": "1.7.13-next.0",
114
114
  "@testing-library/dom": "^10.0.0",
115
115
  "@testing-library/jest-dom": "^6.0.0",
116
116
  "@testing-library/user-event": "^14.0.0",