@backstage/core-components 0.14.7 → 0.14.8-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 +26 -0
- package/alpha/package.json +1 -1
- package/dist/components/AlertDisplay/AlertDisplay.esm.js +1 -1
- package/dist/components/AlertDisplay/AlertDisplay.esm.js.map +1 -1
- package/dist/components/AutoLogout/AutoLogout.esm.js +5 -6
- package/dist/components/AutoLogout/AutoLogout.esm.js.map +1 -1
- package/dist/components/Avatar/Avatar.esm.js +2 -3
- package/dist/components/Avatar/Avatar.esm.js.map +1 -1
- package/dist/components/Avatar/utils.esm.js +1 -2
- package/dist/components/Avatar/utils.esm.js.map +1 -1
- package/dist/components/CodeSnippet/CodeSnippet.esm.js +1 -1
- package/dist/components/CodeSnippet/CodeSnippet.esm.js.map +1 -1
- package/dist/components/DependencyGraph/DependencyGraph.esm.js +2 -3
- package/dist/components/DependencyGraph/DependencyGraph.esm.js.map +1 -1
- package/dist/components/DismissableBanner/DismissableBanner.esm.js +47 -52
- package/dist/components/DismissableBanner/DismissableBanner.esm.js.map +1 -1
- package/dist/components/ErrorPanel/ErrorPanel.esm.js +1 -1
- package/dist/components/ErrorPanel/ErrorPanel.esm.js.map +1 -1
- package/dist/components/FeatureDiscovery/FeatureCalloutCircular.esm.js +8 -8
- package/dist/components/FeatureDiscovery/FeatureCalloutCircular.esm.js.map +1 -1
- package/dist/components/Link/Link.esm.js +3 -5
- package/dist/components/Link/Link.esm.js.map +1 -1
- package/dist/components/LogViewer/AnsiProcessor.esm.js +57 -68
- package/dist/components/LogViewer/AnsiProcessor.esm.js.map +1 -1
- package/dist/components/LogViewer/LogViewerControls.esm.js +1 -2
- package/dist/components/LogViewer/LogViewerControls.esm.js.map +1 -1
- package/dist/components/LogViewer/useLogViewerSearch.esm.js +3 -4
- package/dist/components/LogViewer/useLogViewerSearch.esm.js.map +1 -1
- package/dist/components/LogViewer/useLogViewerSelection.esm.js +1 -1
- package/dist/components/LogViewer/useLogViewerSelection.esm.js.map +1 -1
- package/dist/components/MarkdownContent/MarkdownContent.esm.js +1 -1
- package/dist/components/MarkdownContent/MarkdownContent.esm.js.map +1 -1
- package/dist/components/OAuthRequestDialog/OAuthRequestDialog.esm.js +1 -2
- package/dist/components/OAuthRequestDialog/OAuthRequestDialog.esm.js.map +1 -1
- package/dist/components/OverflowTooltip/OverflowTooltip.esm.js +2 -2
- package/dist/components/OverflowTooltip/OverflowTooltip.esm.js.map +1 -1
- package/dist/components/ResponseErrorPanel/ResponseErrorPanel.esm.js +3 -4
- package/dist/components/ResponseErrorPanel/ResponseErrorPanel.esm.js.map +1 -1
- package/dist/components/Select/Select.esm.js +14 -18
- package/dist/components/Select/Select.esm.js.map +1 -1
- package/dist/components/SupportButton/SupportButton.esm.js +13 -10
- package/dist/components/SupportButton/SupportButton.esm.js.map +1 -1
- package/dist/components/TabbedLayout/RoutedTabs.esm.js +5 -6
- package/dist/components/TabbedLayout/RoutedTabs.esm.js.map +1 -1
- package/dist/components/Table/Filters.esm.js +1 -2
- package/dist/components/Table/Filters.esm.js.map +1 -1
- package/dist/components/Table/Table.esm.js +5 -10
- package/dist/components/Table/Table.esm.js.map +1 -1
- package/dist/components/TrendLine/TrendLine.esm.js +1 -2
- package/dist/components/TrendLine/TrendLine.esm.js.map +1 -1
- package/dist/components/WarningPanel/WarningPanel.esm.js +1 -1
- package/dist/components/WarningPanel/WarningPanel.esm.js.map +1 -1
- package/dist/hooks/useSupportConfig.esm.js +11 -14
- package/dist/hooks/useSupportConfig.esm.js.map +1 -1
- package/dist/icons/icons.esm.js +1 -2
- package/dist/icons/icons.esm.js.map +1 -1
- package/dist/layout/HeaderLabel/HeaderLabel.esm.js +1 -1
- package/dist/layout/HeaderLabel/HeaderLabel.esm.js.map +1 -1
- package/dist/layout/HeaderTabs/HeaderTabs.esm.js +1 -1
- package/dist/layout/HeaderTabs/HeaderTabs.esm.js.map +1 -1
- package/dist/layout/ItemCard/ItemCard.esm.js +1 -1
- package/dist/layout/ItemCard/ItemCard.esm.js.map +1 -1
- package/dist/layout/ProxiedSignInPage/ProxiedSignInIdentity.esm.js +3 -9
- package/dist/layout/ProxiedSignInPage/ProxiedSignInIdentity.esm.js.map +1 -1
- package/dist/layout/Sidebar/Bar.esm.js +3 -4
- package/dist/layout/Sidebar/Bar.esm.js.map +1 -1
- package/dist/layout/Sidebar/Items.esm.js +110 -113
- package/dist/layout/Sidebar/Items.esm.js.map +1 -1
- package/dist/layout/Sidebar/Page.esm.js +2 -3
- package/dist/layout/Sidebar/Page.esm.js.map +1 -1
- package/dist/layout/Sidebar/SidebarSubmenu.esm.js +30 -33
- package/dist/layout/Sidebar/SidebarSubmenu.esm.js.map +1 -1
- package/dist/layout/Sidebar/SidebarSubmenuItem.esm.js +66 -70
- package/dist/layout/Sidebar/SidebarSubmenuItem.esm.js.map +1 -1
- package/dist/layout/SignInPage/LegacyUserIdentity.esm.js +4 -7
- package/dist/layout/SignInPage/LegacyUserIdentity.esm.js.map +1 -1
- package/dist/layout/SignInPage/UserIdentity.esm.js +1 -7
- package/dist/layout/SignInPage/UserIdentity.esm.js.map +1 -1
- package/dist/layout/SignInPage/customProvider.esm.js +1 -1
- package/dist/layout/SignInPage/customProvider.esm.js.map +1 -1
- package/dist/layout/SignInPage/providers.esm.js +3 -6
- package/dist/layout/SignInPage/providers.esm.js.map +1 -1
- package/dist/layout/TabbedCard/TabbedCard.esm.js +3 -3
- package/dist/layout/TabbedCard/TabbedCard.esm.js.map +1 -1
- package/dist/testUtils.esm.js +12 -15
- package/dist/testUtils.esm.js.map +1 -1
- package/package.json +7 -7
- package/testUtils/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @backstage/core-components
|
|
2
2
|
|
|
3
|
+
## 0.14.8-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a0b46f6: Having tooltip inherit font size for consistency in catalog table columns
|
|
8
|
+
- eae0e4d: Fixed an issue causing `SidebarSubmenu` text to not follow the theme color
|
|
9
|
+
- 3e175c8: Removed max width from `Select` component.
|
|
10
|
+
- 57d7582: Fixed a bug in `SupportButton` where the title was rendered with the characteristics of a button.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/core-plugin-api@1.9.3-next.0
|
|
13
|
+
- @backstage/config@1.2.0
|
|
14
|
+
- @backstage/errors@1.2.4
|
|
15
|
+
- @backstage/theme@0.5.6-next.0
|
|
16
|
+
- @backstage/version-bridge@1.0.8
|
|
17
|
+
|
|
18
|
+
## 0.14.8-next.0
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
- @backstage/theme@0.5.6-next.0
|
|
24
|
+
- @backstage/config@1.2.0
|
|
25
|
+
- @backstage/core-plugin-api@1.9.2
|
|
26
|
+
- @backstage/errors@1.2.4
|
|
27
|
+
- @backstage/version-bridge@1.0.8
|
|
28
|
+
|
|
3
29
|
## 0.14.7
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -16,7 +16,7 @@ function AlertDisplay(props) {
|
|
|
16
16
|
anchorOrigin = { vertical: "top", horizontal: "center" },
|
|
17
17
|
transientTimeoutMs
|
|
18
18
|
} = props;
|
|
19
|
-
const timeoutMs = transientTimeoutMs
|
|
19
|
+
const timeoutMs = transientTimeoutMs ?? 5e3;
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
const subscription = alertApi.alert$().subscribe((message) => setMessages((msgs) => msgs.concat(message)));
|
|
22
22
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlertDisplay.esm.js","sources":["../../../src/components/AlertDisplay/AlertDisplay.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 */\nimport { alertApiRef, AlertMessage, useApi } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport IconButton from '@material-ui/core/IconButton';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport Typography from '@material-ui/core/Typography';\nimport CloseIcon from '@material-ui/icons/Close';\nimport Alert from '@material-ui/lab/Alert';\nimport React, { useEffect, useState } from 'react';\nimport { coreComponentsTranslationRef } from '../../translation';\n\n/**\n * Properties for {@link AlertDisplay}\n *\n * @public\n */\nexport type AlertDisplayProps = {\n anchorOrigin?: {\n vertical: 'top' | 'bottom';\n horizontal: 'left' | 'center' | 'right';\n };\n transientTimeoutMs?: number;\n};\n\n/**\n * Displays alerts from {@link @backstage/core-plugin-api#AlertApi}\n *\n * @public\n * @remarks\n *\n * Shown as SnackBar at the center top of the page by default. Configurable with props.\n *\n * @param anchorOrigin - The `vertical` property will set the vertical orientation of where the AlertDisplay will be located\n * and the `horizontal` property will set the horizontal orientation of where the AlertDisplay will be located\n * @param transientTimeoutMs - Number of milliseconds a transient alert will stay open for. Default value is 5000\n *\n * @example\n * Here's some examples:\n * ```\n * // This example shows the default usage, the SnackBar will show up at the top in the center and any transient messages will stay open for 5000ms\n * <AlertDisplay />\n *\n * // With this example the SnackBar will show up in the bottom right hand corner and any transient messages will stay open for 2500ms\n * <AlertDisplay transientTimeoutMs={2500} anchorOrigin={{vertical: 'bottom', horizontal: 'right'}}/>\n *\n * // If you want to just set the time a transientTimeoutMs, you can do that like this:\n * <AlertDisplay transientTimeoutMs={10000} />\n * ```\n */\nexport function AlertDisplay(props: AlertDisplayProps) {\n const [messages, setMessages] = useState<Array<AlertMessage>>([]);\n const alertApi = useApi(alertApiRef);\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n const {\n anchorOrigin = { vertical: 'top', horizontal: 'center' },\n transientTimeoutMs,\n } = props;\n const timeoutMs = transientTimeoutMs ?? 5000;\n\n useEffect(() => {\n const subscription = alertApi\n .alert$()\n .subscribe(message => setMessages(msgs => msgs.concat(message)));\n\n return () => {\n subscription.unsubscribe();\n };\n }, [alertApi]);\n\n const [firstMessage] = messages;\n\n useEffect(() => {\n if (firstMessage && firstMessage.display === 'transient') {\n const timeout = setTimeout(() => {\n setMessages(msgs => {\n const newMsgs = msgs.filter(msg => msg !== firstMessage);\n return newMsgs.length === msgs.length ? msgs : newMsgs;\n });\n }, timeoutMs);\n return () => clearTimeout(timeout);\n }\n return undefined;\n }, [firstMessage, timeoutMs]);\n\n if (messages.length === 0) {\n return null;\n }\n\n const handleClose = () => {\n setMessages(msgs => msgs.filter(msg => msg !== firstMessage));\n };\n\n return (\n <Snackbar open anchorOrigin={anchorOrigin}>\n <Alert\n action={\n <IconButton\n color=\"inherit\"\n size=\"small\"\n onClick={handleClose}\n data-testid=\"error-button-close\"\n >\n <CloseIcon />\n </IconButton>\n }\n severity={firstMessage.severity}\n >\n <Typography component=\"span\">\n {String(firstMessage.message)}\n {messages.length > 1 && (\n <em>\n {t('alertDisplay.message', {\n count: messages.length - 1,\n })}\n </em>\n )}\n </Typography>\n </Alert>\n </Snackbar>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+DO,SAAS,aAAa,KAA0B,EAAA;AACrD,EAAA,MAAM,CAAC,QAAU,EAAA,WAAW,CAAI,GAAA,QAAA,CAA8B,EAAE,CAAA,CAAA;AAChE,EAAM,MAAA,QAAA,GAAW,OAAO,WAAW,CAAA,CAAA;AACnC,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,4BAA4B,CAAA,CAAA;AAE5D,EAAM,MAAA;AAAA,IACJ,YAAe,GAAA,EAAE,QAAU,EAAA,KAAA,EAAO,YAAY,QAAS,EAAA;AAAA,IACvD,kBAAA;AAAA,GACE,GAAA,KAAA,CAAA;AACJ,EAAA,MAAM,YAAY,kBAAsB,IAAA,
|
|
1
|
+
{"version":3,"file":"AlertDisplay.esm.js","sources":["../../../src/components/AlertDisplay/AlertDisplay.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 */\nimport { alertApiRef, AlertMessage, useApi } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport IconButton from '@material-ui/core/IconButton';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport Typography from '@material-ui/core/Typography';\nimport CloseIcon from '@material-ui/icons/Close';\nimport Alert from '@material-ui/lab/Alert';\nimport React, { useEffect, useState } from 'react';\nimport { coreComponentsTranslationRef } from '../../translation';\n\n/**\n * Properties for {@link AlertDisplay}\n *\n * @public\n */\nexport type AlertDisplayProps = {\n anchorOrigin?: {\n vertical: 'top' | 'bottom';\n horizontal: 'left' | 'center' | 'right';\n };\n transientTimeoutMs?: number;\n};\n\n/**\n * Displays alerts from {@link @backstage/core-plugin-api#AlertApi}\n *\n * @public\n * @remarks\n *\n * Shown as SnackBar at the center top of the page by default. Configurable with props.\n *\n * @param anchorOrigin - The `vertical` property will set the vertical orientation of where the AlertDisplay will be located\n * and the `horizontal` property will set the horizontal orientation of where the AlertDisplay will be located\n * @param transientTimeoutMs - Number of milliseconds a transient alert will stay open for. Default value is 5000\n *\n * @example\n * Here's some examples:\n * ```\n * // This example shows the default usage, the SnackBar will show up at the top in the center and any transient messages will stay open for 5000ms\n * <AlertDisplay />\n *\n * // With this example the SnackBar will show up in the bottom right hand corner and any transient messages will stay open for 2500ms\n * <AlertDisplay transientTimeoutMs={2500} anchorOrigin={{vertical: 'bottom', horizontal: 'right'}}/>\n *\n * // If you want to just set the time a transientTimeoutMs, you can do that like this:\n * <AlertDisplay transientTimeoutMs={10000} />\n * ```\n */\nexport function AlertDisplay(props: AlertDisplayProps) {\n const [messages, setMessages] = useState<Array<AlertMessage>>([]);\n const alertApi = useApi(alertApiRef);\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n const {\n anchorOrigin = { vertical: 'top', horizontal: 'center' },\n transientTimeoutMs,\n } = props;\n const timeoutMs = transientTimeoutMs ?? 5000;\n\n useEffect(() => {\n const subscription = alertApi\n .alert$()\n .subscribe(message => setMessages(msgs => msgs.concat(message)));\n\n return () => {\n subscription.unsubscribe();\n };\n }, [alertApi]);\n\n const [firstMessage] = messages;\n\n useEffect(() => {\n if (firstMessage && firstMessage.display === 'transient') {\n const timeout = setTimeout(() => {\n setMessages(msgs => {\n const newMsgs = msgs.filter(msg => msg !== firstMessage);\n return newMsgs.length === msgs.length ? msgs : newMsgs;\n });\n }, timeoutMs);\n return () => clearTimeout(timeout);\n }\n return undefined;\n }, [firstMessage, timeoutMs]);\n\n if (messages.length === 0) {\n return null;\n }\n\n const handleClose = () => {\n setMessages(msgs => msgs.filter(msg => msg !== firstMessage));\n };\n\n return (\n <Snackbar open anchorOrigin={anchorOrigin}>\n <Alert\n action={\n <IconButton\n color=\"inherit\"\n size=\"small\"\n onClick={handleClose}\n data-testid=\"error-button-close\"\n >\n <CloseIcon />\n </IconButton>\n }\n severity={firstMessage.severity}\n >\n <Typography component=\"span\">\n {String(firstMessage.message)}\n {messages.length > 1 && (\n <em>\n {t('alertDisplay.message', {\n count: messages.length - 1,\n })}\n </em>\n )}\n </Typography>\n </Alert>\n </Snackbar>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+DO,SAAS,aAAa,KAA0B,EAAA;AACrD,EAAA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|
"visibilitychange"
|
|
83
83
|
];
|
|
84
84
|
const parseConfig = (configApi, props) => {
|
|
85
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
86
85
|
return {
|
|
87
|
-
enabled:
|
|
88
|
-
idleTimeoutMinutes:
|
|
89
|
-
promptBeforeIdleSeconds:
|
|
90
|
-
useWorkerTimers:
|
|
91
|
-
logoutIfDisconnected:
|
|
86
|
+
enabled: configApi.getOptionalBoolean("auth.autologout.enabled") ?? props.enabled ?? defaultConfig.enabled,
|
|
87
|
+
idleTimeoutMinutes: configApi.getOptionalNumber("auth.autologout.idleTimeoutMinutes") ?? props.idleTimeoutMinutes ?? defaultConfig.idleTimeoutMinutes,
|
|
88
|
+
promptBeforeIdleSeconds: configApi.getOptionalNumber("auth.autologout.promptBeforeIdleSeconds") ?? props.promptBeforeIdleSeconds ?? defaultConfig.promptBeforeIdleSeconds,
|
|
89
|
+
useWorkerTimers: configApi.getOptionalBoolean("auth.autologout.useWorkerTimers") ?? props.useWorkerTimers ?? defaultConfig.useWorkerTimers,
|
|
90
|
+
logoutIfDisconnected: configApi.getOptionalBoolean("auth.autologout.logoutIfDisconnected") ?? props.logoutIfDisconnected ?? defaultConfig.logoutIfDisconnected
|
|
92
91
|
};
|
|
93
92
|
};
|
|
94
93
|
const AutoLogout = (props) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoLogout.esm.js","sources":["../../../src/components/AutoLogout/AutoLogout.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 ConfigApi,\n configApiRef,\n IdentityApi,\n identityApiRef,\n useApi,\n} from '@backstage/core-plugin-api';\nimport React, { useEffect, useMemo, useState } from 'react';\nimport {\n EventsType,\n IIdleTimer,\n workerTimers,\n useIdleTimer,\n} from 'react-idle-timer';\n\nimport {\n LAST_SEEN_ONLINE_STORAGE_KEY,\n useLogoutDisconnectedUserEffect,\n} from './disconnectedUsers';\nimport { StillTherePrompt } from './StillTherePrompt';\nimport { DefaultTimestampStore, TimestampStore } from './timestampStore';\n\ntype AutoLogoutTrackableEvent = EventsType;\n\n/** @public */\nexport type AutoLogoutProps = {\n /**\n * Enable/disable the AutoLogoutMechanism.\n * defauls to true.\n */\n enabled?: boolean;\n /**\n * The amount of time (in minutes) of inactivity\n * after which the user is automatically logged out.\n * defaults to 60 minutes.\n */\n idleTimeoutMinutes?: number;\n /**\n * The number of seconds before the idleTimeout expires,\n * at which the user will be alerted by a Dialog that\n * they are about to be logged out.\n * defaults to 10 seconds\n */\n promptBeforeIdleSeconds?: number;\n /**\n * Enable/disable the usage of Node's worker thread timers instead of main thread timers.\n * This is helpful if you notice that the your browser is killing inactive tab's timers, like the one used by AutoLogout.\n * If you experience some browser incompatibility, you may try to set this to false.\n * defaults to true.\n */\n useWorkerTimers?: boolean;\n /**\n * Enable/disable the autologout for disconnected users.\n * disconnected users are the ones that are logged in but have no Backstage tab open in their browsers.\n * If enabled, disconnected users will be automatically logged out after `idleTimeoutMinutes`\n * defaults to true\n */\n logoutIfDisconnected?: boolean;\n};\n\ntype AutoLogoutInternalProps = Omit<Required<AutoLogoutProps>, 'enabled'> & {\n events: AutoLogoutTrackableEvent[];\n promptOpen: boolean;\n setPromptOpen: (value: boolean) => void;\n remainingTimeCountdown: number;\n setRemainingTimeCountdown: (amount: number) => void;\n identityApi: IdentityApi;\n lastSeenOnlineStore: TimestampStore;\n};\n\nconst ConditionalAutoLogout = ({\n idleTimeoutMinutes,\n events,\n useWorkerTimers,\n logoutIfDisconnected,\n promptBeforeIdleSeconds,\n promptOpen,\n setPromptOpen,\n remainingTimeCountdown,\n setRemainingTimeCountdown,\n identityApi,\n lastSeenOnlineStore,\n}: AutoLogoutInternalProps): JSX.Element => {\n const promptBeforeIdleMillis = promptBeforeIdleSeconds * 1000;\n const promptBeforeIdle = promptBeforeIdleMillis > 0 ? true : false;\n\n const onPrompt = async () => {\n // onPrompt will be called `promptBeforeIdle` milliseconds before `timeout`.\n // All events are disabled while the prompt is active.\n // If the user wishes to stay active, call the `activate()` method.\n // You can get the remaining prompt time with the `getRemainingTime()` method,\n setPromptOpen(true);\n setRemainingTimeCountdown(promptBeforeIdleMillis);\n };\n\n const onIdle = () => {\n // onIdle will be called after the timeout is reached.\n // Events will be rebound as long as `stopOnMount` is not set.\n setPromptOpen(false);\n setRemainingTimeCountdown(0);\n identityApi.signOut();\n };\n\n const onActive = () => {\n // onActive will only be called if `activate()` is called while `isPrompted()`\n // is true. Here you will also want to close your modal and perform\n // any active actions.\n setPromptOpen(false);\n setRemainingTimeCountdown(0);\n };\n\n const onAction = (\n _event?: Event | undefined,\n _idleTimer?: IIdleTimer | null,\n ) => {\n // onAction will be called if any user event is detected. The list of events that triggers a user event detection is the list of configured events\n // If any user event is detected we update the Last seen online in storage\n lastSeenOnlineStore.save(new Date());\n };\n\n const timer = useIdleTimer({\n timeout: idleTimeoutMinutes * 60 * 1000,\n events: events,\n crossTab: true,\n name: 'autologout-timer',\n timers: useWorkerTimers ? workerTimers : undefined,\n onIdle: onIdle,\n onActive: promptBeforeIdle ? onActive : undefined,\n onAction: logoutIfDisconnected ? onAction : undefined,\n onPrompt: promptBeforeIdle ? onPrompt : undefined,\n promptBeforeIdle: promptBeforeIdle ? promptBeforeIdleMillis : undefined,\n syncTimers: 1000,\n });\n\n return (\n <>\n {promptBeforeIdle && (\n <StillTherePrompt\n idleTimer={timer}\n open={promptOpen}\n setOpen={setPromptOpen}\n remainingTime={remainingTimeCountdown}\n setRemainingTime={setRemainingTimeCountdown}\n promptTimeoutMillis={promptBeforeIdleMillis}\n />\n )}\n </>\n );\n};\n\nconst defaultConfig: Required<AutoLogoutProps> = {\n enabled: true,\n idleTimeoutMinutes: 0.5,\n promptBeforeIdleSeconds: 10,\n useWorkerTimers: true,\n logoutIfDisconnected: true,\n};\n\n/**\n * A list of DOM events that the activity tracker will use to determine if the user is active or not.\n */\nconst defaultTrackedEvents: AutoLogoutTrackableEvent[] = [\n 'mousemove',\n 'keydown',\n 'wheel',\n 'DOMMouseScroll',\n 'mousewheel',\n 'mousedown',\n 'touchstart',\n 'touchmove',\n 'MSPointerDown',\n 'MSPointerMove',\n 'visibilitychange',\n];\n\n/**\n * Parses configuration for the AutoLogout. Properties configured in `app-config` take precedence over the props passed to the React component.\n * If neither props nor config properties are found, a default value will be set accordingly.\n */\nconst parseConfig = (\n configApi: ConfigApi,\n props: AutoLogoutProps,\n): Required<AutoLogoutProps> => {\n return {\n enabled:\n configApi.getOptionalBoolean('auth.autologout.enabled') ??\n props.enabled ??\n defaultConfig.enabled,\n idleTimeoutMinutes:\n configApi.getOptionalNumber('auth.autologout.idleTimeoutMinutes') ??\n props.idleTimeoutMinutes ??\n defaultConfig.idleTimeoutMinutes,\n promptBeforeIdleSeconds:\n configApi.getOptionalNumber('auth.autologout.promptBeforeIdleSeconds') ??\n props.promptBeforeIdleSeconds ??\n defaultConfig.promptBeforeIdleSeconds,\n useWorkerTimers:\n configApi.getOptionalBoolean('auth.autologout.useWorkerTimers') ??\n props.useWorkerTimers ??\n defaultConfig.useWorkerTimers,\n logoutIfDisconnected:\n configApi.getOptionalBoolean('auth.autologout.logoutIfDisconnected') ??\n props.logoutIfDisconnected ??\n defaultConfig.logoutIfDisconnected,\n };\n};\n\n/**\n * The Autologout feature enables platform engineers to add a mechanism to log out users after a configurable amount of time of inactivity.\n * When enabled, the mechanism will track user actions (mouse movement, mouse click, key pressing, taps, etc.) in order to determine if they are active or not.\n * After a certain amount of inactivity/idle time, the user session is invalidated and they are required to sign in again.\n *\n * @public\n */\nexport const AutoLogout = (props: AutoLogoutProps): JSX.Element | null => {\n const identityApi = useApi(identityApiRef);\n const configApi = useApi(configApiRef);\n const [isLogged, setIsLogged] = useState(false);\n useEffect(() => {\n // if the user is not logged in, the autologout feature won't affect the app even if enabled\n async function isLoggedIn(identity: IdentityApi) {\n if ((await identity.getCredentials()).token) {\n setIsLogged(true);\n } else {\n setIsLogged(false);\n }\n }\n isLoggedIn(identityApi);\n }, [identityApi]);\n\n const {\n enabled,\n idleTimeoutMinutes,\n promptBeforeIdleSeconds,\n logoutIfDisconnected,\n useWorkerTimers,\n }: AutoLogoutProps = useMemo(() => {\n return parseConfig(configApi, props);\n }, [configApi, props]);\n\n useEffect(() => {\n if (idleTimeoutMinutes < 0.5) {\n throw new Error(\n '❌ idleTimeoutMinutes property should be >= 0.5 minutes (30 seconds).',\n );\n }\n\n if (promptBeforeIdleSeconds < 0) {\n throw new Error(\n '❌ promptBeforeIdleSeconds property should be >= 0 seconds. Set to 0 to disable the prompt.',\n );\n }\n\n if (idleTimeoutMinutes * 60 <= promptBeforeIdleSeconds) {\n throw new Error(\n `❌ promptBeforeIdleSeconds should be smaller than idleTimeoutMinutes`,\n );\n }\n }, [idleTimeoutMinutes, promptBeforeIdleSeconds]);\n\n const lastSeenOnlineStore: TimestampStore = useMemo(\n () => new DefaultTimestampStore(LAST_SEEN_ONLINE_STORAGE_KEY),\n [],\n );\n const [promptOpen, setPromptOpen] = useState<boolean>(false);\n\n const [remainingTimeCountdown, setRemainingTimeCountdown] =\n useState<number>(0);\n\n useLogoutDisconnectedUserEffect({\n enableEffect: logoutIfDisconnected,\n autologoutIsEnabled: enabled && isLogged,\n idleTimeoutSeconds: idleTimeoutMinutes * 60,\n lastSeenOnlineStore,\n identityApi,\n });\n\n if (!enabled || !isLogged) {\n return null;\n }\n\n return (\n <ConditionalAutoLogout\n idleTimeoutMinutes={idleTimeoutMinutes}\n promptBeforeIdleSeconds={promptBeforeIdleSeconds}\n useWorkerTimers={useWorkerTimers}\n events={defaultTrackedEvents}\n logoutIfDisconnected={logoutIfDisconnected}\n promptOpen={promptOpen}\n setPromptOpen={setPromptOpen}\n remainingTimeCountdown={remainingTimeCountdown}\n setRemainingTimeCountdown={setRemainingTimeCountdown}\n identityApi={identityApi}\n lastSeenOnlineStore={lastSeenOnlineStore}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;AAsFA,MAAM,wBAAwB,CAAC;AAAA,EAC7B,kBAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA;AAAA,EACA,oBAAA;AAAA,EACA,uBAAA;AAAA,EACA,UAAA;AAAA,EACA,aAAA;AAAA,EACA,sBAAA;AAAA,EACA,yBAAA;AAAA,EACA,WAAA;AAAA,EACA,mBAAA;AACF,CAA4C,KAAA;AAC1C,EAAA,MAAM,yBAAyB,uBAA0B,GAAA,GAAA,CAAA;AACzD,EAAM,MAAA,gBAAA,GAAmB,sBAAyB,GAAA,CAAA,GAAI,IAAO,GAAA,KAAA,CAAA;AAE7D,EAAA,MAAM,WAAW,YAAY;AAK3B,IAAA,aAAA,CAAc,IAAI,CAAA,CAAA;AAClB,IAAA,yBAAA,CAA0B,sBAAsB,CAAA,CAAA;AAAA,GAClD,CAAA;AAEA,EAAA,MAAM,SAAS,MAAM;AAGnB,IAAA,aAAA,CAAc,KAAK,CAAA,CAAA;AACnB,IAAA,yBAAA,CAA0B,CAAC,CAAA,CAAA;AAC3B,IAAA,WAAA,CAAY,OAAQ,EAAA,CAAA;AAAA,GACtB,CAAA;AAEA,EAAA,MAAM,WAAW,MAAM;AAIrB,IAAA,aAAA,CAAc,KAAK,CAAA,CAAA;AACnB,IAAA,yBAAA,CAA0B,CAAC,CAAA,CAAA;AAAA,GAC7B,CAAA;AAEA,EAAM,MAAA,QAAA,GAAW,CACf,MAAA,EACA,UACG,KAAA;AAGH,IAAoB,mBAAA,CAAA,IAAA,iBAAS,IAAA,IAAA,EAAM,CAAA,CAAA;AAAA,GACrC,CAAA;AAEA,EAAA,MAAM,QAAQ,YAAa,CAAA;A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A;AACA,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,SAAkB,KAAK,CAAA,CAAA;AAE3D,EAAA,MAAM,CAAC,sBAAA,EAAwB,yBAAyB,CAAA,GACtD,SAAiB,CAAC,CAAA,CAAA;AAEpB,EAAgC,+BAAA,CAAA;AAAA,IAC9B,YAAc,EAAA,oBAAA;AAAA,IACd,qBAAqB,OAAW,IAAA,QAAA;AAAA,IAChC,oBAAoB,kBAAqB,GAAA,EAAA;AAAA,IACzC,mBAAA;AAAA,IACA,WAAA;AAAA,GACD,CAAA,CAAA;AAED,EAAI,IAAA,CAAC,OAAW,IAAA,CAAC,QAAU,EAAA;AACzB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,qBAAA;AAAA,IAAA;AAAA,MACC,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,eAAA;AAAA,MACA,MAAQ,EAAA,oBAAA;AAAA,MACR,oBAAA;AAAA,MACA,UAAA;AAAA,MACA,aAAA;AAAA,MACA,sBAAA;AAAA,MACA,yBAAA;AAAA,MACA,WAAA;AAAA,MACA,mBAAA;AAAA,KAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"AutoLogout.esm.js","sources":["../../../src/components/AutoLogout/AutoLogout.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 ConfigApi,\n configApiRef,\n IdentityApi,\n identityApiRef,\n useApi,\n} from '@backstage/core-plugin-api';\nimport React, { useEffect, useMemo, useState } from 'react';\nimport {\n EventsType,\n IIdleTimer,\n workerTimers,\n useIdleTimer,\n} from 'react-idle-timer';\n\nimport {\n LAST_SEEN_ONLINE_STORAGE_KEY,\n useLogoutDisconnectedUserEffect,\n} from './disconnectedUsers';\nimport { StillTherePrompt } from './StillTherePrompt';\nimport { DefaultTimestampStore, TimestampStore } from './timestampStore';\n\ntype AutoLogoutTrackableEvent = EventsType;\n\n/** @public */\nexport type AutoLogoutProps = {\n /**\n * Enable/disable the AutoLogoutMechanism.\n * defauls to true.\n */\n enabled?: boolean;\n /**\n * The amount of time (in minutes) of inactivity\n * after which the user is automatically logged out.\n * defaults to 60 minutes.\n */\n idleTimeoutMinutes?: number;\n /**\n * The number of seconds before the idleTimeout expires,\n * at which the user will be alerted by a Dialog that\n * they are about to be logged out.\n * defaults to 10 seconds\n */\n promptBeforeIdleSeconds?: number;\n /**\n * Enable/disable the usage of Node's worker thread timers instead of main thread timers.\n * This is helpful if you notice that the your browser is killing inactive tab's timers, like the one used by AutoLogout.\n * If you experience some browser incompatibility, you may try to set this to false.\n * defaults to true.\n */\n useWorkerTimers?: boolean;\n /**\n * Enable/disable the autologout for disconnected users.\n * disconnected users are the ones that are logged in but have no Backstage tab open in their browsers.\n * If enabled, disconnected users will be automatically logged out after `idleTimeoutMinutes`\n * defaults to true\n */\n logoutIfDisconnected?: boolean;\n};\n\ntype AutoLogoutInternalProps = Omit<Required<AutoLogoutProps>, 'enabled'> & {\n events: AutoLogoutTrackableEvent[];\n promptOpen: boolean;\n setPromptOpen: (value: boolean) => void;\n remainingTimeCountdown: number;\n setRemainingTimeCountdown: (amount: number) => void;\n identityApi: IdentityApi;\n lastSeenOnlineStore: TimestampStore;\n};\n\nconst ConditionalAutoLogout = ({\n idleTimeoutMinutes,\n events,\n useWorkerTimers,\n logoutIfDisconnected,\n promptBeforeIdleSeconds,\n promptOpen,\n setPromptOpen,\n remainingTimeCountdown,\n setRemainingTimeCountdown,\n identityApi,\n lastSeenOnlineStore,\n}: AutoLogoutInternalProps): JSX.Element => {\n const promptBeforeIdleMillis = promptBeforeIdleSeconds * 1000;\n const promptBeforeIdle = promptBeforeIdleMillis > 0 ? true : false;\n\n const onPrompt = async () => {\n // onPrompt will be called `promptBeforeIdle` milliseconds before `timeout`.\n // All events are disabled while the prompt is active.\n // If the user wishes to stay active, call the `activate()` method.\n // You can get the remaining prompt time with the `getRemainingTime()` method,\n setPromptOpen(true);\n setRemainingTimeCountdown(promptBeforeIdleMillis);\n };\n\n const onIdle = () => {\n // onIdle will be called after the timeout is reached.\n // Events will be rebound as long as `stopOnMount` is not set.\n setPromptOpen(false);\n setRemainingTimeCountdown(0);\n identityApi.signOut();\n };\n\n const onActive = () => {\n // onActive will only be called if `activate()` is called while `isPrompted()`\n // is true. Here you will also want to close your modal and perform\n // any active actions.\n setPromptOpen(false);\n setRemainingTimeCountdown(0);\n };\n\n const onAction = (\n _event?: Event | undefined,\n _idleTimer?: IIdleTimer | null,\n ) => {\n // onAction will be called if any user event is detected. The list of events that triggers a user event detection is the list of configured events\n // If any user event is detected we update the Last seen online in storage\n lastSeenOnlineStore.save(new Date());\n };\n\n const timer = useIdleTimer({\n timeout: idleTimeoutMinutes * 60 * 1000,\n events: events,\n crossTab: true,\n name: 'autologout-timer',\n timers: useWorkerTimers ? workerTimers : undefined,\n onIdle: onIdle,\n onActive: promptBeforeIdle ? onActive : undefined,\n onAction: logoutIfDisconnected ? onAction : undefined,\n onPrompt: promptBeforeIdle ? onPrompt : undefined,\n promptBeforeIdle: promptBeforeIdle ? promptBeforeIdleMillis : undefined,\n syncTimers: 1000,\n });\n\n return (\n <>\n {promptBeforeIdle && (\n <StillTherePrompt\n idleTimer={timer}\n open={promptOpen}\n setOpen={setPromptOpen}\n remainingTime={remainingTimeCountdown}\n setRemainingTime={setRemainingTimeCountdown}\n promptTimeoutMillis={promptBeforeIdleMillis}\n />\n )}\n </>\n );\n};\n\nconst defaultConfig: Required<AutoLogoutProps> = {\n enabled: true,\n idleTimeoutMinutes: 0.5,\n promptBeforeIdleSeconds: 10,\n useWorkerTimers: true,\n logoutIfDisconnected: true,\n};\n\n/**\n * A list of DOM events that the activity tracker will use to determine if the user is active or not.\n */\nconst defaultTrackedEvents: AutoLogoutTrackableEvent[] = [\n 'mousemove',\n 'keydown',\n 'wheel',\n 'DOMMouseScroll',\n 'mousewheel',\n 'mousedown',\n 'touchstart',\n 'touchmove',\n 'MSPointerDown',\n 'MSPointerMove',\n 'visibilitychange',\n];\n\n/**\n * Parses configuration for the AutoLogout. Properties configured in `app-config` take precedence over the props passed to the React component.\n * If neither props nor config properties are found, a default value will be set accordingly.\n */\nconst parseConfig = (\n configApi: ConfigApi,\n props: AutoLogoutProps,\n): Required<AutoLogoutProps> => {\n return {\n enabled:\n configApi.getOptionalBoolean('auth.autologout.enabled') ??\n props.enabled ??\n defaultConfig.enabled,\n idleTimeoutMinutes:\n configApi.getOptionalNumber('auth.autologout.idleTimeoutMinutes') ??\n props.idleTimeoutMinutes ??\n defaultConfig.idleTimeoutMinutes,\n promptBeforeIdleSeconds:\n configApi.getOptionalNumber('auth.autologout.promptBeforeIdleSeconds') ??\n props.promptBeforeIdleSeconds ??\n defaultConfig.promptBeforeIdleSeconds,\n useWorkerTimers:\n configApi.getOptionalBoolean('auth.autologout.useWorkerTimers') ??\n props.useWorkerTimers ??\n defaultConfig.useWorkerTimers,\n logoutIfDisconnected:\n configApi.getOptionalBoolean('auth.autologout.logoutIfDisconnected') ??\n props.logoutIfDisconnected ??\n defaultConfig.logoutIfDisconnected,\n };\n};\n\n/**\n * The Autologout feature enables platform engineers to add a mechanism to log out users after a configurable amount of time of inactivity.\n * When enabled, the mechanism will track user actions (mouse movement, mouse click, key pressing, taps, etc.) in order to determine if they are active or not.\n * After a certain amount of inactivity/idle time, the user session is invalidated and they are required to sign in again.\n *\n * @public\n */\nexport const AutoLogout = (props: AutoLogoutProps): JSX.Element | null => {\n const identityApi = useApi(identityApiRef);\n const configApi = useApi(configApiRef);\n const [isLogged, setIsLogged] = useState(false);\n useEffect(() => {\n // if the user is not logged in, the autologout feature won't affect the app even if enabled\n async function isLoggedIn(identity: IdentityApi) {\n if ((await identity.getCredentials()).token) {\n setIsLogged(true);\n } else {\n setIsLogged(false);\n }\n }\n isLoggedIn(identityApi);\n }, [identityApi]);\n\n const {\n enabled,\n idleTimeoutMinutes,\n promptBeforeIdleSeconds,\n logoutIfDisconnected,\n useWorkerTimers,\n }: AutoLogoutProps = useMemo(() => {\n return parseConfig(configApi, props);\n }, [configApi, props]);\n\n useEffect(() => {\n if (idleTimeoutMinutes < 0.5) {\n throw new Error(\n '❌ idleTimeoutMinutes property should be >= 0.5 minutes (30 seconds).',\n );\n }\n\n if (promptBeforeIdleSeconds < 0) {\n throw new Error(\n '❌ promptBeforeIdleSeconds property should be >= 0 seconds. Set to 0 to disable the prompt.',\n );\n }\n\n if (idleTimeoutMinutes * 60 <= promptBeforeIdleSeconds) {\n throw new Error(\n `❌ promptBeforeIdleSeconds should be smaller than idleTimeoutMinutes`,\n );\n }\n }, [idleTimeoutMinutes, promptBeforeIdleSeconds]);\n\n const lastSeenOnlineStore: TimestampStore = useMemo(\n () => new DefaultTimestampStore(LAST_SEEN_ONLINE_STORAGE_KEY),\n [],\n );\n const [promptOpen, setPromptOpen] = useState<boolean>(false);\n\n const [remainingTimeCountdown, setRemainingTimeCountdown] =\n useState<number>(0);\n\n useLogoutDisconnectedUserEffect({\n enableEffect: logoutIfDisconnected,\n autologoutIsEnabled: enabled && isLogged,\n idleTimeoutSeconds: idleTimeoutMinutes * 60,\n lastSeenOnlineStore,\n identityApi,\n });\n\n if (!enabled || !isLogged) {\n return null;\n }\n\n return (\n <ConditionalAutoLogout\n idleTimeoutMinutes={idleTimeoutMinutes}\n promptBeforeIdleSeconds={promptBeforeIdleSeconds}\n useWorkerTimers={useWorkerTimers}\n events={defaultTrackedEvents}\n logoutIfDisconnected={logoutIfDisconnected}\n promptOpen={promptOpen}\n setPromptOpen={setPromptOpen}\n remainingTimeCountdown={remainingTimeCountdown}\n setRemainingTimeCountdown={setRemainingTimeCountdown}\n identityApi={identityApi}\n lastSeenOnlineStore={lastSeenOnlineStore}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;AAsFA,MAAM,wBAAwB,CAAC;AAAA,EAC7B,kBAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA;AAAA,EACA,oBAAA;AAAA,EACA,uBAAA;AAAA,EACA,UAAA;AAAA,EACA,aAAA;AAAA,EACA,sBAAA;AAAA,EACA,yBAAA;AAAA,EACA,WAAA;AAAA,EACA,mBAAA;AACF,CAA4C,KAAA;AAC1C,EAAA,MAAM,yBAAyB,uBAA0B,GAAA,GAAA,CAAA;AACzD,EAAM,MAAA,gBAAA,GAAmB,sBAAyB,GAAA,CAAA,GAAI,IAAO,GAAA,KAAA,CAAA;AAE7D,EAAA,MAAM,WAAW,YAAY;AAK3B,IAAA,aAAA,CAAc,IAAI,CAAA,CAAA;AAClB,IAAA,yBAAA,CAA0B,sBAAsB,CAAA,CAAA;AAAA,GAClD,CAAA;AAEA,EAAA,MAAM,SAAS,MAAM;AAGnB,IAAA,aAAA,CAAc,KAAK,CAAA,CAAA;AACnB,IAAA,yBAAA,CAA0B,CAAC,CAAA,CAAA;AAC3B,IAAA,WAAA,CAAY,OAAQ,EAAA,CAAA;AAAA,GACtB,CAAA;AAEA,EAAA,MAAM,WAAW,MAAM;AAIrB,IAAA,aAAA,CAAc,KAAK,CAAA,CAAA;AACnB,IAAA,yBAAA,CAA0B,CAAC,CAAA,CAAA;AAAA,GAC7B,CAAA;AAEA,EAAM,MAAA,QAAA,GAAW,CACf,MAAA,EACA,UACG,KAAA;AAGH,IAAoB,mBAAA,CAAA,IAAA,iBAAS,IAAA,IAAA,EAAM,CAAA,CAAA;AAAA,GACrC,CAAA;AAEA,EAAA,MAAM,QAAQ,YAAa,CAAA;AAAA,IACzB,OAAA,EAAS,qBAAqB,EAAK,GAAA,GAAA;AAAA,IACnC,MAAA;AAA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AAA,aAAA;AAAA,IAAC,qBAAA;AAAA,IAAA;AAAA,MACC,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,eAAA;AAAA,MACA,MAAQ,EAAA,oBAAA;AAAA,MACR,oBAAA;AAAA,MACA,UAAA;AAAA,MACA,aAAA;AAAA,MACA,sBAAA;AAAA,MACA,yBAAA;AAAA,MACA,WAAA;AAAA,MACA,mBAAA;AAAA,KAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
@@ -22,7 +22,6 @@ const useStyles = makeStyles(
|
|
|
22
22
|
{ name: "BackstageAvatar" }
|
|
23
23
|
);
|
|
24
24
|
function Avatar(props) {
|
|
25
|
-
var _a, _b;
|
|
26
25
|
const { displayName, picture, customStyles } = props;
|
|
27
26
|
const styles = { ...customStyles };
|
|
28
27
|
const fontStyles = {
|
|
@@ -33,9 +32,9 @@ function Avatar(props) {
|
|
|
33
32
|
const classes = useStyles(
|
|
34
33
|
!picture ? { backgroundColor: stringToColor(displayName || "") } : {}
|
|
35
34
|
);
|
|
36
|
-
const avatarClassNames = classNames(
|
|
35
|
+
const avatarClassNames = classNames(props.classes?.avatar, classes.avatar);
|
|
37
36
|
const avatarTextClassNames = classNames(
|
|
38
|
-
|
|
37
|
+
props.classes?.avatarText,
|
|
39
38
|
classes.avatarText
|
|
40
39
|
);
|
|
41
40
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.esm.js","sources":["../../../src/components/Avatar/Avatar.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 */\nimport MaterialAvatar from '@material-ui/core/Avatar';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport Typography from '@material-ui/core/Typography';\nimport React, { CSSProperties } from 'react';\n\nimport { extractInitials, stringToColor } from './utils';\nimport classNames from 'classnames';\n\n/** @public */\nexport type AvatarClassKey = 'avatar';\n\nconst useStyles = makeStyles(\n (theme: Theme) => ({\n avatar: {\n width: '4rem',\n height: '4rem',\n color: theme.palette.common.white,\n backgroundColor: (props: { backgroundColor?: string }) =>\n props.backgroundColor,\n },\n avatarText: {\n fontWeight: theme.typography.fontWeightBold,\n letterSpacing: '1px',\n textTransform: 'uppercase',\n },\n }),\n { name: 'BackstageAvatar' },\n);\n\n/**\n * Properties for {@link Avatar}.\n *\n * @public\n */\nexport interface AvatarProps {\n /**\n * A display name, which will be used to generate initials as a fallback in case a picture is not provided.\n */\n displayName?: string;\n /**\n * URL to avatar image source\n */\n picture?: string;\n /**\n * Custom styles applied to avatar\n * @deprecated - use the classes property instead\n */\n customStyles?: CSSProperties;\n\n /**\n * Custom styles applied to avatar\n */\n classes?: { [key in 'avatar' | 'avatarText']?: string };\n}\n\n/**\n * Component rendering an Avatar\n *\n * @public\n * @remarks\n *\n * Based on https://v4.mui.com/components/avatars/#avatar with some styling adjustment and two-letter initials\n */\nexport function Avatar(props: AvatarProps) {\n const { displayName, picture, customStyles } = props;\n const styles = { ...customStyles };\n\n // TODO: Remove this with the customStyles deprecation\n const fontStyles = {\n fontFamily: styles.fontFamily,\n fontSize: styles.fontSize,\n fontWeight: styles.fontWeight,\n };\n\n // We only calculate the background color if there's not an avatar\n // picture. If there is a picture, it might have a transparent\n // background and we don't know whether the calculated background\n // color will clash.\n const classes = useStyles(\n !picture ? { backgroundColor: stringToColor(displayName || '') } : {},\n );\n\n const avatarClassNames = classNames(props.classes?.avatar, classes.avatar);\n const avatarTextClassNames = classNames(\n props.classes?.avatarText,\n classes.avatarText,\n );\n\n return (\n <MaterialAvatar\n alt={displayName}\n src={picture}\n className={avatarClassNames}\n style={styles}\n >\n {displayName && (\n <Typography\n variant=\"h6\"\n component=\"span\"\n className={avatarTextClassNames}\n style={fontStyles}\n >\n {extractInitials(displayName)}\n </Typography>\n )}\n </MaterialAvatar>\n );\n}\n"],"names":[],"mappings":";;;;;;;AA0BA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,CAAC,KAAkB,MAAA;AAAA,IACjB,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA,MAAA;AAAA,MACP,MAAQ,EAAA,MAAA;AAAA,MACR,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,KAAA;AAAA,MAC5B,eAAA,EAAiB,CAAC,KAAA,KAChB,KAAM,CAAA,eAAA;AAAA,KACV;AAAA,IACA,UAAY,EAAA;AAAA,MACV,UAAA,EAAY,MAAM,UAAW,CAAA,cAAA;AAAA,MAC7B,aAAe,EAAA,KAAA;AAAA,MACf,aAAe,EAAA,WAAA;AAAA,KACjB;AAAA,GACF,CAAA;AAAA,EACA,EAAE,MAAM,iBAAkB,EAAA;AAC5B,CAAA,CAAA;AAoCO,SAAS,OAAO,KAAoB,EAAA;
|
|
1
|
+
{"version":3,"file":"Avatar.esm.js","sources":["../../../src/components/Avatar/Avatar.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 */\nimport MaterialAvatar from '@material-ui/core/Avatar';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport Typography from '@material-ui/core/Typography';\nimport React, { CSSProperties } from 'react';\n\nimport { extractInitials, stringToColor } from './utils';\nimport classNames from 'classnames';\n\n/** @public */\nexport type AvatarClassKey = 'avatar';\n\nconst useStyles = makeStyles(\n (theme: Theme) => ({\n avatar: {\n width: '4rem',\n height: '4rem',\n color: theme.palette.common.white,\n backgroundColor: (props: { backgroundColor?: string }) =>\n props.backgroundColor,\n },\n avatarText: {\n fontWeight: theme.typography.fontWeightBold,\n letterSpacing: '1px',\n textTransform: 'uppercase',\n },\n }),\n { name: 'BackstageAvatar' },\n);\n\n/**\n * Properties for {@link Avatar}.\n *\n * @public\n */\nexport interface AvatarProps {\n /**\n * A display name, which will be used to generate initials as a fallback in case a picture is not provided.\n */\n displayName?: string;\n /**\n * URL to avatar image source\n */\n picture?: string;\n /**\n * Custom styles applied to avatar\n * @deprecated - use the classes property instead\n */\n customStyles?: CSSProperties;\n\n /**\n * Custom styles applied to avatar\n */\n classes?: { [key in 'avatar' | 'avatarText']?: string };\n}\n\n/**\n * Component rendering an Avatar\n *\n * @public\n * @remarks\n *\n * Based on https://v4.mui.com/components/avatars/#avatar with some styling adjustment and two-letter initials\n */\nexport function Avatar(props: AvatarProps) {\n const { displayName, picture, customStyles } = props;\n const styles = { ...customStyles };\n\n // TODO: Remove this with the customStyles deprecation\n const fontStyles = {\n fontFamily: styles.fontFamily,\n fontSize: styles.fontSize,\n fontWeight: styles.fontWeight,\n };\n\n // We only calculate the background color if there's not an avatar\n // picture. If there is a picture, it might have a transparent\n // background and we don't know whether the calculated background\n // color will clash.\n const classes = useStyles(\n !picture ? { backgroundColor: stringToColor(displayName || '') } : {},\n );\n\n const avatarClassNames = classNames(props.classes?.avatar, classes.avatar);\n const avatarTextClassNames = classNames(\n props.classes?.avatarText,\n classes.avatarText,\n );\n\n return (\n <MaterialAvatar\n alt={displayName}\n src={picture}\n className={avatarClassNames}\n style={styles}\n >\n {displayName && (\n <Typography\n variant=\"h6\"\n component=\"span\"\n className={avatarTextClassNames}\n style={fontStyles}\n >\n {extractInitials(displayName)}\n </Typography>\n )}\n </MaterialAvatar>\n );\n}\n"],"names":[],"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KAAA,CAAA,aAAA;AAAA,IAAC,cAAA;AAAA,IAAA;AAAA,MACC,GAAK,EAAA,WAAA;AAAA,MACL,GAAK,EAAA,OAAA;AAAA,MACL,SAAW,EAAA,gBAAA;AAAA,MACX,KAAO,EAAA,MAAA;AAAA,KAAA;AAAA,IAEN,WACC,oBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,UAAA;AAAA,MAAA;AAAA,QACC,OAAQ,EAAA,IAAA;AAAA,QACR,SAAU,EAAA,MAAA;AAAA,QACV,SAAW,EAAA,oBAAA;AAAA,QACX,KAAO,EAAA,UAAA;AAAA,OAAA;AAAA,MAEN,gBAAgB,WAAW,CAAA;AAAA,KAC9B;AAAA,GAEJ,CAAA;AAEJ;;;;"}
|
|
@@ -11,9 +11,8 @@ function stringToColor(str) {
|
|
|
11
11
|
return color;
|
|
12
12
|
}
|
|
13
13
|
function extractInitials(name) {
|
|
14
|
-
var _a;
|
|
15
14
|
const names = name.trim().split(" ");
|
|
16
|
-
const firstName =
|
|
15
|
+
const firstName = names[0] ?? "";
|
|
17
16
|
const lastName = names.length > 1 ? names[names.length - 1] : "";
|
|
18
17
|
return firstName && lastName ? `${firstName.charAt(0)}${lastName.charAt(0)}` : firstName.charAt(0);
|
|
19
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../../src/components/Avatar/utils.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\nexport function stringToColor(str: string) {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash);\n }\n let color = '#';\n for (let i = 0; i < 3; i++) {\n const value = (hash >> (i * 8)) & 0xff;\n color += `00${value.toString(16)}`.slice(-2);\n }\n return color;\n}\n\nexport function extractInitials(name: string) {\n const names = name.trim().split(' ');\n const firstName = names[0] ?? '';\n const lastName = names.length > 1 ? names[names.length - 1] : '';\n return firstName && lastName\n ? `${firstName.charAt(0)}${lastName.charAt(0)}`\n : firstName.charAt(0);\n}\n"],"names":[],"mappings":"AAgBO,SAAS,cAAc,GAAa,EAAA;AACzC,EAAA,IAAI,IAAO,GAAA,CAAA,CAAA;AACX,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,GAAA,CAAI,QAAQ,CAAK,EAAA,EAAA;AACnC,IAAA,IAAA,GAAO,GAAI,CAAA,UAAA,CAAW,CAAC,CAAA,IAAA,CAAM,QAAQ,CAAK,IAAA,IAAA,CAAA,CAAA;AAAA,GAC5C;AACA,EAAA,IAAI,KAAQ,GAAA,GAAA,CAAA;AACZ,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,CAAA,EAAG,CAAK,EAAA,EAAA;AAC1B,IAAM,MAAA,KAAA,GAAS,IAAS,IAAA,CAAA,GAAI,CAAM,GAAA,GAAA,CAAA;AAClC,IAAA,KAAA,IAAS,KAAK,KAAM,CAAA,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,CAAG,MAAM,CAAE,CAAA,CAAA,CAAA;AAAA,GAC7C;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEO,SAAS,gBAAgB,IAAc,EAAA;
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../../src/components/Avatar/utils.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\nexport function stringToColor(str: string) {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash);\n }\n let color = '#';\n for (let i = 0; i < 3; i++) {\n const value = (hash >> (i * 8)) & 0xff;\n color += `00${value.toString(16)}`.slice(-2);\n }\n return color;\n}\n\nexport function extractInitials(name: string) {\n const names = name.trim().split(' ');\n const firstName = names[0] ?? '';\n const lastName = names.length > 1 ? names[names.length - 1] : '';\n return firstName && lastName\n ? `${firstName.charAt(0)}${lastName.charAt(0)}`\n : firstName.charAt(0);\n}\n"],"names":[],"mappings":"AAgBO,SAAS,cAAc,GAAa,EAAA;AACzC,EAAA,IAAI,IAAO,GAAA,CAAA,CAAA;AACX,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,GAAA,CAAI,QAAQ,CAAK,EAAA,EAAA;AACnC,IAAA,IAAA,GAAO,GAAI,CAAA,UAAA,CAAW,CAAC,CAAA,IAAA,CAAM,QAAQ,CAAK,IAAA,IAAA,CAAA,CAAA;AAAA,GAC5C;AACA,EAAA,IAAI,KAAQ,GAAA,GAAA,CAAA;AACZ,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,CAAA,EAAG,CAAK,EAAA,EAAA;AAC1B,IAAM,MAAA,KAAA,GAAS,IAAS,IAAA,CAAA,GAAI,CAAM,GAAA,GAAA,CAAA;AAClC,IAAA,KAAA,IAAS,KAAK,KAAM,CAAA,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,CAAG,MAAM,CAAE,CAAA,CAAA,CAAA;AAAA,GAC7C;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEO,SAAS,gBAAgB,IAAc,EAAA;AAC5C,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAK,IAAK,EAAA,CAAE,MAAM,GAAG,CAAA,CAAA;AACnC,EAAM,MAAA,SAAA,GAAY,KAAM,CAAA,CAAC,CAAK,IAAA,EAAA,CAAA;AAC9B,EAAM,MAAA,QAAA,GAAW,MAAM,MAAS,GAAA,CAAA,GAAI,MAAM,KAAM,CAAA,MAAA,GAAS,CAAC,CAAI,GAAA,EAAA,CAAA;AAC9D,EAAA,OAAO,SAAa,IAAA,QAAA,GAChB,CAAG,EAAA,SAAA,CAAU,OAAO,CAAC,CAAC,CAAG,EAAA,QAAA,CAAS,OAAO,CAAC,CAAC,CAC3C,CAAA,GAAA,SAAA,CAAU,OAAO,CAAC,CAAA,CAAA;AACxB;;;;"}
|
|
@@ -27,7 +27,7 @@ function CodeSnippet(props) {
|
|
|
27
27
|
showLineNumbers,
|
|
28
28
|
wrapLines: true,
|
|
29
29
|
lineNumberStyle: { color: theme.palette.textVerySubtle },
|
|
30
|
-
lineProps: (lineNumber) =>
|
|
30
|
+
lineProps: (lineNumber) => highlightedNumbers?.includes(lineNumber) ? {
|
|
31
31
|
style: {
|
|
32
32
|
backgroundColor: highlightColor
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeSnippet.esm.js","sources":["../../../src/components/CodeSnippet/CodeSnippet.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 { useTheme } from '@material-ui/core/styles';\nimport React from 'react';\nimport type {} from 'react-syntax-highlighter';\nimport LightAsync from 'react-syntax-highlighter/dist/esm/light-async';\nimport dark from 'react-syntax-highlighter/dist/esm/styles/hljs/dark';\nimport docco from 'react-syntax-highlighter/dist/esm/styles/hljs/docco';\n\nimport { CopyTextButton } from '../CopyTextButton';\n\n/**\n * Properties for {@link CodeSnippet}\n *\n * @public\n */\nexport interface CodeSnippetProps {\n /**\n * Code Snippet text\n */\n text: string;\n /**\n * Language used by {@link CodeSnippetProps.text}\n */\n language: string;\n /**\n * Whether to show line number\n *\n * @remarks\n *\n * Default: false\n */\n showLineNumbers?: boolean;\n /**\n * Whether to show button to copy code snippet\n *\n * @remarks\n *\n * Default: false\n */\n showCopyCodeButton?: boolean;\n /**\n * Array of line numbers to highlight\n */\n highlightedNumbers?: number[];\n /**\n * Custom styles applied to code\n *\n * @remarks\n *\n * Passed to {@link https://react-syntax-highlighter.github.io/react-syntax-highlighter/ | react-syntax-highlighter}\n */\n customStyle?: any;\n}\n\n/**\n * Thin wrapper on top of {@link https://react-syntax-highlighter.github.io/react-syntax-highlighter/ | react-syntax-highlighter}\n * providing consistent theming and copy code button\n *\n * @public\n */\nexport function CodeSnippet(props: CodeSnippetProps) {\n const {\n text,\n language,\n showLineNumbers = false,\n highlightedNumbers,\n customStyle,\n showCopyCodeButton = false,\n } = props;\n const theme = useTheme();\n const mode = theme.palette.type === 'dark' ? dark : docco;\n const highlightColor = theme.palette.type === 'dark' ? '#256bf3' : '#e6ffed';\n\n return (\n <Box position=\"relative\">\n <LightAsync\n customStyle={customStyle}\n language={language}\n style={mode}\n showLineNumbers={showLineNumbers}\n wrapLines\n lineNumberStyle={{ color: theme.palette.textVerySubtle }}\n lineProps={(lineNumber: number) =>\n highlightedNumbers?.includes(lineNumber)\n ? {\n style: {\n backgroundColor: highlightColor,\n },\n }\n : {}\n }\n >\n {text}\n </LightAsync>\n {showCopyCodeButton && (\n <Box position=\"absolute\" top={0} right={0}>\n <CopyTextButton text={text} />\n </Box>\n )}\n </Box>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AA4EO,SAAS,YAAY,KAAyB,EAAA;AACnD,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA,QAAA;AAAA,IACA,eAAkB,GAAA,KAAA;AAAA,IAClB,kBAAA;AAAA,IACA,WAAA;AAAA,IACA,kBAAqB,GAAA,KAAA;AAAA,GACnB,GAAA,KAAA,CAAA;AACJ,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAA,MAAM,IAAO,GAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,KAAS,SAAS,IAAO,GAAA,KAAA,CAAA;AACpD,EAAA,MAAM,cAAiB,GAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,KAAS,SAAS,SAAY,GAAA,SAAA,CAAA;AAEnE,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,GAAI,EAAA,EAAA,QAAA,EAAS,UACZ,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,WAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAO,EAAA,IAAA;AAAA,MACP,eAAA;AAAA,MACA,SAAS,EAAA,IAAA;AAAA,MACT,eAAiB,EAAA,EAAE,KAAO,EAAA,KAAA,CAAM,QAAQ,cAAe,EAAA;AAAA,MACvD,
|
|
1
|
+
{"version":3,"file":"CodeSnippet.esm.js","sources":["../../../src/components/CodeSnippet/CodeSnippet.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 { useTheme } from '@material-ui/core/styles';\nimport React from 'react';\nimport type {} from 'react-syntax-highlighter';\nimport LightAsync from 'react-syntax-highlighter/dist/esm/light-async';\nimport dark from 'react-syntax-highlighter/dist/esm/styles/hljs/dark';\nimport docco from 'react-syntax-highlighter/dist/esm/styles/hljs/docco';\n\nimport { CopyTextButton } from '../CopyTextButton';\n\n/**\n * Properties for {@link CodeSnippet}\n *\n * @public\n */\nexport interface CodeSnippetProps {\n /**\n * Code Snippet text\n */\n text: string;\n /**\n * Language used by {@link CodeSnippetProps.text}\n */\n language: string;\n /**\n * Whether to show line number\n *\n * @remarks\n *\n * Default: false\n */\n showLineNumbers?: boolean;\n /**\n * Whether to show button to copy code snippet\n *\n * @remarks\n *\n * Default: false\n */\n showCopyCodeButton?: boolean;\n /**\n * Array of line numbers to highlight\n */\n highlightedNumbers?: number[];\n /**\n * Custom styles applied to code\n *\n * @remarks\n *\n * Passed to {@link https://react-syntax-highlighter.github.io/react-syntax-highlighter/ | react-syntax-highlighter}\n */\n customStyle?: any;\n}\n\n/**\n * Thin wrapper on top of {@link https://react-syntax-highlighter.github.io/react-syntax-highlighter/ | react-syntax-highlighter}\n * providing consistent theming and copy code button\n *\n * @public\n */\nexport function CodeSnippet(props: CodeSnippetProps) {\n const {\n text,\n language,\n showLineNumbers = false,\n highlightedNumbers,\n customStyle,\n showCopyCodeButton = false,\n } = props;\n const theme = useTheme();\n const mode = theme.palette.type === 'dark' ? dark : docco;\n const highlightColor = theme.palette.type === 'dark' ? '#256bf3' : '#e6ffed';\n\n return (\n <Box position=\"relative\">\n <LightAsync\n customStyle={customStyle}\n language={language}\n style={mode}\n showLineNumbers={showLineNumbers}\n wrapLines\n lineNumberStyle={{ color: theme.palette.textVerySubtle }}\n lineProps={(lineNumber: number) =>\n highlightedNumbers?.includes(lineNumber)\n ? {\n style: {\n backgroundColor: highlightColor,\n },\n }\n : {}\n }\n >\n {text}\n </LightAsync>\n {showCopyCodeButton && (\n <Box position=\"absolute\" top={0} right={0}>\n <CopyTextButton text={text} />\n </Box>\n )}\n </Box>\n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;;;;"}
|
|
@@ -11,7 +11,6 @@ import { ARROW_MARKER_ID } from './constants.esm.js';
|
|
|
11
11
|
|
|
12
12
|
const WORKSPACE_ID = "workspace";
|
|
13
13
|
function DependencyGraph(props) {
|
|
14
|
-
var _a, _b;
|
|
15
14
|
const {
|
|
16
15
|
edges,
|
|
17
16
|
nodes,
|
|
@@ -42,10 +41,10 @@ function DependencyGraph(props) {
|
|
|
42
41
|
const [containerHeight, setContainerHeight] = React.useState(100);
|
|
43
42
|
const graph = React.useRef(new dagre.graphlib.Graph());
|
|
44
43
|
const [graphWidth, setGraphWidth] = React.useState(
|
|
45
|
-
|
|
44
|
+
graph.current.graph()?.width || 0
|
|
46
45
|
);
|
|
47
46
|
const [graphHeight, setGraphHeight] = React.useState(
|
|
48
|
-
|
|
47
|
+
graph.current.graph()?.height || 0
|
|
49
48
|
);
|
|
50
49
|
const [graphNodes, setGraphNodes] = React.useState([]);
|
|
51
50
|
const [graphEdges, setGraphEdges] = React.useState([]);
|
|
@@ -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 React from 'react';\nimport * as d3Zoom from 'd3-zoom';\nimport * as d3Selection from 'd3-selection';\nimport useTheme from '@material-ui/core/styles/useTheme';\nimport dagre from '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';\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 React.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 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\nconst WORKSPACE_ID = 'workspace';\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 renderLabel,\n defs,\n zoom = 'enabled',\n curve = 'curveMonotoneX',\n showArrowHeads = false,\n fit = 'grow',\n ...svgProps\n } = props;\n const theme = useTheme();\n const [containerWidth, setContainerWidth] = React.useState<number>(100);\n const [containerHeight, setContainerHeight] = React.useState<number>(100);\n\n const graph = React.useRef<\n dagre.graphlib.Graph<Types.DependencyNode<NodeData>>\n >(new dagre.graphlib.Graph());\n const [graphWidth, setGraphWidth] = React.useState<number>(\n graph.current.graph()?.width || 0,\n );\n const [graphHeight, setGraphHeight] = React.useState<number>(\n graph.current.graph()?.height || 0,\n );\n const [graphNodes, setGraphNodes] = React.useState<string[]>([]);\n const [graphEdges, setGraphEdges] = React.useState<dagre.Edge[]>([]);\n\n const maxWidth = Math.max(graphWidth, containerWidth);\n const maxHeight = Math.max(graphHeight, containerHeight);\n const minHeight = Math.min(graphHeight, containerHeight);\n\n const scalableHeight = fit === 'grow' ? maxHeight : minHeight;\n\n const containerRef = React.useMemo(\n () =>\n debounce((node: SVGSVGElement) => {\n if (!node) {\n return;\n }\n // Set up zooming + panning\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 node.getBoundingClientRect();\n if (containerWidth !== newContainerWidth) {\n setContainerWidth(newContainerWidth);\n }\n if (containerHeight !== newContainerHeight) {\n setContainerHeight(newContainerHeight);\n }\n }, 100),\n [containerHeight, containerWidth, maxWidth, maxHeight, zoom],\n );\n\n const setNodesAndEdges = React.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 = React.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 React.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 function setNode(id: string, node: Types.DependencyNode<NodeData>) {\n graph.current.setNode(id, node);\n updateGraph();\n return graph.current;\n }\n\n function setEdge(id: dagre.Edge, edge: Types.DependencyEdge<EdgeData>) {\n graph.current.setEdge(id, edge);\n updateGraph();\n return graph.current;\n }\n\n return (\n <svg\n ref={containerRef}\n {...svgProps}\n width=\"100%\"\n height={scalableHeight}\n viewBox={`0 0 ${maxWidth} ${maxHeight}`}\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={`0 0 ${graphWidth} ${graphHeight}`}\n >\n {graphEdges.map(e => {\n const edge = graph.current.edge(e) as GraphEdge<EdgeData>;\n if (!edge) return null;\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 );\n}\n"],"names":["Types"],"mappings":";;;;;;;;;;;AAkLA,MAAM,YAAe,GAAA,WAAA,CAAA;AAOd,SAAS,gBACd,KACA,EAAA;AA3LF,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AA4LE,EAAM,MAAA;AAAA,IACJ,KAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,SAAA,GAAYA,qBAAM,SAAU,CAAA,UAAA;AAAA,IAC5B,KAAA;AAAA,IACA,UAAa,GAAA,EAAA;AAAA,I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GAAI,UAAa,GAAA,CAAA;AAAA,QAC/B,OAAS,EAAA,CAAA,IAAA,EAAO,UAAU,CAAA,CAAA,EAAI,WAAW,CAAA,CAAA;AAAA,OAAA;AAAA,MAExC,UAAA,CAAW,IAAI,CAAK,CAAA,KAAA;AACnB,QAAA,MAAM,IAAO,GAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,CAAC,CAAA,CAAA;AACjC,QAAA,IAAI,CAAC,IAAA;AAAM,UAAO,OAAA,IAAA,CAAA;AAClB,QACE,uBAAA,KAAA,CAAA,aAAA;AAAA,UAAC,IAAA;AAAA,UAAA;AAAA,YACC,KAAK,CAAG,EAAA,CAAA,CAAE,CAAC,CAAA,CAAA,EAAI,EAAE,CAAC,CAAA,CAAA;AAAA,YAClB,EAAI,EAAA,CAAA;AAAA,YACJ,OAAA;AAAA,YACA,MAAQ,EAAA,WAAA;AAAA,YACR,IAAA;AAAA,YACA,KAAA;AAAA,YACA,cAAA;AAAA,WAAA;AAAA,SACF,CAAA;AAAA,OAEH,CAAA;AAAA,MACA,UAAA,CAAW,GAAI,CAAA,CAAC,EAAe,KAAA;AAC9B,QAAA,MAAM,IAAO,GAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,EAAE,CAAA,CAAA;AAClC,QAAA,IAAI,CAAC,IAAA;AAAM,UAAO,OAAA,IAAA,CAAA;AAClB,QACE,uBAAA,KAAA,CAAA,aAAA;AAAA,UAAC,IAAA;AAAA,UAAA;AAAA,YACC,GAAK,EAAA,EAAA;AAAA,YACL,OAAA;AAAA,YACA,MAAQ,EAAA,UAAA;AAAA,YACR,IAAA;AAAA,WAAA;AAAA,SACF,CAAA;AAAA,OAEH,CAAA;AAAA,KAEL,CAAA;AAAA,GACF,CAAA;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 React from 'react';\nimport * as d3Zoom from 'd3-zoom';\nimport * as d3Selection from 'd3-selection';\nimport useTheme from '@material-ui/core/styles/useTheme';\nimport dagre from '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';\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 React.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 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\nconst WORKSPACE_ID = 'workspace';\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 renderLabel,\n defs,\n zoom = 'enabled',\n curve = 'curveMonotoneX',\n showArrowHeads = false,\n fit = 'grow',\n ...svgProps\n } = props;\n const theme = useTheme();\n const [containerWidth, setContainerWidth] = React.useState<number>(100);\n const [containerHeight, setContainerHeight] = React.useState<number>(100);\n\n const graph = React.useRef<\n dagre.graphlib.Graph<Types.DependencyNode<NodeData>>\n >(new dagre.graphlib.Graph());\n const [graphWidth, setGraphWidth] = React.useState<number>(\n graph.current.graph()?.width || 0,\n );\n const [graphHeight, setGraphHeight] = React.useState<number>(\n graph.current.graph()?.height || 0,\n );\n const [graphNodes, setGraphNodes] = React.useState<string[]>([]);\n const [graphEdges, setGraphEdges] = React.useState<dagre.Edge[]>([]);\n\n const maxWidth = Math.max(graphWidth, containerWidth);\n const maxHeight = Math.max(graphHeight, containerHeight);\n const minHeight = Math.min(graphHeight, containerHeight);\n\n const scalableHeight = fit === 'grow' ? maxHeight : minHeight;\n\n const containerRef = React.useMemo(\n () =>\n debounce((node: SVGSVGElement) => {\n if (!node) {\n return;\n }\n // Set up zooming + panning\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 node.getBoundingClientRect();\n if (containerWidth !== newContainerWidth) {\n setContainerWidth(newContainerWidth);\n }\n if (containerHeight !== newContainerHeight) {\n setContainerHeight(newContainerHeight);\n }\n }, 100),\n [containerHeight, containerWidth, maxWidth, maxHeight, zoom],\n );\n\n const setNodesAndEdges = React.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 = React.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 React.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 function setNode(id: string, node: Types.DependencyNode<NodeData>) {\n graph.current.setNode(id, node);\n updateGraph();\n return graph.current;\n }\n\n function setEdge(id: dagre.Edge, edge: Types.DependencyEdge<EdgeData>) {\n graph.current.setEdge(id, edge);\n updateGraph();\n return graph.current;\n }\n\n return (\n <svg\n ref={containerRef}\n {...svgProps}\n width=\"100%\"\n height={scalableHeight}\n viewBox={`0 0 ${maxWidth} ${maxHeight}`}\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={`0 0 ${graphWidth} ${graphHeight}`}\n >\n {graphEdges.map(e => {\n const edge = graph.current.edge(e) as GraphEdge<EdgeData>;\n if (!edge) return null;\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 );\n}\n"],"names":["Types"],"mappings":";;;;;;;;;;;AAkLA,MAAM,YAAe,GAAA,WAAA,CAAA;AAOd,SAAS,gBACd,KACA,EAAA;AACA,EAAM,MAAA;AAAA,IACJ,KAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,SAAA,GAAYA,qBAAM,SAAU,CAAA,UAAA;AAAA,IAC5B,KAAA;AAAA,IACA,UAAa,GAAA,EAAA;AAAA,IACb,UAAa,GAAA,EAAA;AAAA,IACb,UAAa,GAAA,EAAA;AAAA,IACb,QAAW,GAAA,CAAA;AAAA,IACX,QAAW,GAAA,CAAA;AAAA,IACX,SAAA;AAAA,IACA,MAAA,GAASA,qBAAM,MAAO,CAAA,eAAA;AAAA,IACtB,aAAA,GAAgBA,qBAAM,aAAc,CAAA,KAAA;AAAA,IACpC,WAAc,GAAA,EAAA;AAAA,IACd,SAAY,GAAA,CAAA;AAAA,IACZ,UAAa,GAAA,CAAA;AAAA,IACb,WAAA;AAAA,IACA,IAAA;AAAA,IACA,IAAO,GAAA,SAAA;AAAA,IACP,KAAQ,GAAA,gBAAA;AAAA,IACR,cAAiB,GAAA,KAAA;AAAA,IACjB,GAAM,GAAA,MAAA;AAAA,IACN,GAAG,QAAA;AAAA,GACD,GAAA,KAAA,CAAA;AACJ,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAA,MAAM,CAAC,cAAgB,EAAA,iBAAiB,CAAI,GAAA,KAAA,CAAM,SAAiB,GAAG,CAAA,CAAA;AACtE,EAAA,MAAM,CAAC,eAAiB,EAAA,kBAAkB,CAAI,GAAA,KAAA,CAAM,SAAiB,GAAG,CAAA,CAAA;AAExE,EAAA,MAAM,QAAQ,KAAM,CAAA,MAAA,CAElB,IAAI,KAAM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AA;AAAA,UAAC,IAAA;AAAA,UAAA;AAAA,YACC,GAAK,EAAA,EAAA;AAAA,YACL,OAAA;AAAA,YACA,MAAQ,EAAA,UAAA;AAAA,YACR,IAAA;AAAA,WAAA;AAAA,SACF,CAAA;AAAA,OAEH,CAAA;AAAA,KAEL,CAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
@@ -9,62 +9,58 @@ import IconButton from '@material-ui/core/IconButton';
|
|
|
9
9
|
import CloseIcon from '@material-ui/icons/Close';
|
|
10
10
|
|
|
11
11
|
const useStyles = makeStyles(
|
|
12
|
-
(theme) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"& a": {
|
|
42
|
-
color: theme.palette.banner.link
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
button: {
|
|
46
|
-
color: (_a = theme.palette.banner.closeButtonColor) != null ? _a : "inherit"
|
|
47
|
-
},
|
|
48
|
-
info: {
|
|
49
|
-
backgroundColor: theme.palette.banner.info
|
|
50
|
-
},
|
|
51
|
-
error: {
|
|
52
|
-
backgroundColor: theme.palette.banner.error
|
|
53
|
-
},
|
|
54
|
-
warning: {
|
|
55
|
-
backgroundColor: (_b = theme.palette.banner.warning) != null ? _b : theme.palette.banner.error
|
|
12
|
+
(theme) => ({
|
|
13
|
+
root: {
|
|
14
|
+
padding: theme.spacing(0),
|
|
15
|
+
marginBottom: theme.spacing(0),
|
|
16
|
+
marginTop: theme.spacing(0),
|
|
17
|
+
display: "flex",
|
|
18
|
+
flexFlow: "row nowrap"
|
|
19
|
+
},
|
|
20
|
+
// showing on top
|
|
21
|
+
topPosition: {
|
|
22
|
+
position: "relative",
|
|
23
|
+
marginBottom: theme.spacing(6),
|
|
24
|
+
marginTop: -theme.spacing(3),
|
|
25
|
+
zIndex: "unset"
|
|
26
|
+
},
|
|
27
|
+
icon: {
|
|
28
|
+
fontSize: theme.typography.h6.fontSize
|
|
29
|
+
},
|
|
30
|
+
content: {
|
|
31
|
+
width: "100%",
|
|
32
|
+
maxWidth: "inherit",
|
|
33
|
+
flexWrap: "nowrap",
|
|
34
|
+
color: theme.palette.banner.text
|
|
35
|
+
},
|
|
36
|
+
message: {
|
|
37
|
+
display: "flex",
|
|
38
|
+
alignItems: "center",
|
|
39
|
+
"& a": {
|
|
40
|
+
color: theme.palette.banner.link
|
|
56
41
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
42
|
+
},
|
|
43
|
+
button: {
|
|
44
|
+
color: theme.palette.banner.closeButtonColor ?? "inherit"
|
|
45
|
+
},
|
|
46
|
+
info: {
|
|
47
|
+
backgroundColor: theme.palette.banner.info
|
|
48
|
+
},
|
|
49
|
+
error: {
|
|
50
|
+
backgroundColor: theme.palette.banner.error
|
|
51
|
+
},
|
|
52
|
+
warning: {
|
|
53
|
+
backgroundColor: theme.palette.banner.warning ?? theme.palette.banner.error
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
59
56
|
{ name: "BackstageDismissableBanner" }
|
|
60
57
|
);
|
|
61
58
|
const DismissableBanner = (props) => {
|
|
62
|
-
var _a;
|
|
63
59
|
const { variant, message, id, fixed = false } = props;
|
|
64
60
|
const classes = useStyles();
|
|
65
61
|
const storageApi = useApi(storageApiRef);
|
|
66
62
|
const notificationsStore = storageApi.forBucket("notifications");
|
|
67
|
-
const rawDismissedBanners =
|
|
63
|
+
const rawDismissedBanners = notificationsStore.snapshot("dismissedBanners").value ?? [];
|
|
68
64
|
const [dismissedBanners, setDismissedBanners] = useState(
|
|
69
65
|
new Set(rawDismissedBanners)
|
|
70
66
|
);
|
|
@@ -72,12 +68,11 @@ const DismissableBanner = (props) => {
|
|
|
72
68
|
notificationsStore.observe$("dismissedBanners")
|
|
73
69
|
);
|
|
74
70
|
useEffect(() => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const currentValue = (_a2 = observedItems == null ? void 0 : observedItems.value) != null ? _a2 : [];
|
|
71
|
+
if (observedItems?.value) {
|
|
72
|
+
const currentValue = observedItems?.value ?? [];
|
|
78
73
|
setDismissedBanners(new Set(currentValue));
|
|
79
74
|
}
|
|
80
|
-
}, [observedItems
|
|
75
|
+
}, [observedItems?.value]);
|
|
81
76
|
const handleClick = () => {
|
|
82
77
|
notificationsStore.set("dismissedBanners", [...dismissedBanners, id]);
|
|
83
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DismissableBanner.esm.js","sources":["../../../src/components/DismissableBanner/DismissableBanner.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 React, { ReactNode, useState, useEffect } from 'react';\nimport { useApi, storageApiRef } from '@backstage/core-plugin-api';\nimport useObservable from 'react-use/esm/useObservable';\nimport classNames from 'classnames';\nimport { makeStyles } from '@material-ui/core/styles';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport SnackbarContent from '@material-ui/core/SnackbarContent';\nimport IconButton from '@material-ui/core/IconButton';\nimport Close from '@material-ui/icons/Close';\n\n/** @public */\nexport type DismissableBannerClassKey =\n | 'root'\n | 'topPosition'\n | 'icon'\n | 'content'\n | 'message'\n | 'info'\n | 'error';\n\n/**\n * @public\n * @deprecated This type contained a typo, please use DismissableBannerClassKey instead\n */\nexport type DismissbleBannerClassKey = DismissableBannerClassKey;\n\nconst useStyles = makeStyles(\n theme => ({\n root: {\n padding: theme.spacing(0),\n marginBottom: theme.spacing(0),\n marginTop: theme.spacing(0),\n display: 'flex',\n flexFlow: 'row nowrap',\n },\n // showing on top\n topPosition: {\n position: 'relative',\n marginBottom: theme.spacing(6),\n marginTop: -theme.spacing(3),\n zIndex: 'unset',\n },\n icon: {\n fontSize: theme.typography.h6.fontSize,\n },\n content: {\n width: '100%',\n maxWidth: 'inherit',\n flexWrap: 'nowrap',\n color: theme.palette.banner.text,\n },\n message: {\n display: 'flex',\n alignItems: 'center',\n '& a': {\n color: theme.palette.banner.link,\n },\n },\n button: {\n color: theme.palette.banner.closeButtonColor ?? 'inherit',\n },\n info: {\n backgroundColor: theme.palette.banner.info,\n },\n error: {\n backgroundColor: theme.palette.banner.error,\n },\n warning: {\n backgroundColor:\n theme.palette.banner.warning ?? theme.palette.banner.error,\n },\n }),\n { name: 'BackstageDismissableBanner' },\n);\n\nexport type Props = {\n variant: 'info' | 'error' | 'warning';\n message: ReactNode;\n id: string;\n fixed?: boolean;\n};\n\n/** @public */\nexport const DismissableBanner = (props: Props) => {\n const { variant, message, id, fixed = false } = props;\n const classes = useStyles();\n const storageApi = useApi(storageApiRef);\n const notificationsStore = storageApi.forBucket('notifications');\n const rawDismissedBanners =\n notificationsStore.snapshot<string[]>('dismissedBanners').value ?? [];\n\n const [dismissedBanners, setDismissedBanners] = useState(\n new Set(rawDismissedBanners),\n );\n\n const observedItems = useObservable(\n notificationsStore.observe$<string[]>('dismissedBanners'),\n );\n\n useEffect(() => {\n if (observedItems?.value) {\n const currentValue = observedItems?.value ?? [];\n setDismissedBanners(new Set(currentValue));\n }\n }, [observedItems?.value]);\n\n const handleClick = () => {\n notificationsStore.set('dismissedBanners', [...dismissedBanners, id]);\n };\n\n return (\n <Snackbar\n anchorOrigin={\n fixed\n ? { vertical: 'bottom', horizontal: 'center' }\n : { vertical: 'top', horizontal: 'center' }\n }\n open={!dismissedBanners.has(id)}\n classes={{\n root: classNames(classes.root, !fixed && classes.topPosition),\n }}\n >\n <SnackbarContent\n classes={{\n root: classNames(classes.content, classes[variant]),\n message: classes.message,\n }}\n message={message}\n action={[\n <IconButton\n key=\"dismiss\"\n title=\"Permanently dismiss this message\"\n className={classes.button}\n onClick={handleClick}\n >\n <Close className={classes.icon} />\n </IconButton>,\n ]}\n />\n </Snackbar>\n );\n};\n"],"names":["
|
|
1
|
+
{"version":3,"file":"DismissableBanner.esm.js","sources":["../../../src/components/DismissableBanner/DismissableBanner.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 React, { ReactNode, useState, useEffect } from 'react';\nimport { useApi, storageApiRef } from '@backstage/core-plugin-api';\nimport useObservable from 'react-use/esm/useObservable';\nimport classNames from 'classnames';\nimport { makeStyles } from '@material-ui/core/styles';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport SnackbarContent from '@material-ui/core/SnackbarContent';\nimport IconButton from '@material-ui/core/IconButton';\nimport Close from '@material-ui/icons/Close';\n\n/** @public */\nexport type DismissableBannerClassKey =\n | 'root'\n | 'topPosition'\n | 'icon'\n | 'content'\n | 'message'\n | 'info'\n | 'error';\n\n/**\n * @public\n * @deprecated This type contained a typo, please use DismissableBannerClassKey instead\n */\nexport type DismissbleBannerClassKey = DismissableBannerClassKey;\n\nconst useStyles = makeStyles(\n theme => ({\n root: {\n padding: theme.spacing(0),\n marginBottom: theme.spacing(0),\n marginTop: theme.spacing(0),\n display: 'flex',\n flexFlow: 'row nowrap',\n },\n // showing on top\n topPosition: {\n position: 'relative',\n marginBottom: theme.spacing(6),\n marginTop: -theme.spacing(3),\n zIndex: 'unset',\n },\n icon: {\n fontSize: theme.typography.h6.fontSize,\n },\n content: {\n width: '100%',\n maxWidth: 'inherit',\n flexWrap: 'nowrap',\n color: theme.palette.banner.text,\n },\n message: {\n display: 'flex',\n alignItems: 'center',\n '& a': {\n color: theme.palette.banner.link,\n },\n },\n button: {\n color: theme.palette.banner.closeButtonColor ?? 'inherit',\n },\n info: {\n backgroundColor: theme.palette.banner.info,\n },\n error: {\n backgroundColor: theme.palette.banner.error,\n },\n warning: {\n backgroundColor:\n theme.palette.banner.warning ?? theme.palette.banner.error,\n },\n }),\n { name: 'BackstageDismissableBanner' },\n);\n\nexport type Props = {\n variant: 'info' | 'error' | 'warning';\n message: ReactNode;\n id: string;\n fixed?: boolean;\n};\n\n/** @public */\nexport const DismissableBanner = (props: Props) => {\n const { variant, message, id, fixed = false } = props;\n const classes = useStyles();\n const storageApi = useApi(storageApiRef);\n const notificationsStore = storageApi.forBucket('notifications');\n const rawDismissedBanners =\n notificationsStore.snapshot<string[]>('dismissedBanners').value ?? [];\n\n const [dismissedBanners, setDismissedBanners] = useState(\n new Set(rawDismissedBanners),\n );\n\n const observedItems = useObservable(\n notificationsStore.observe$<string[]>('dismissedBanners'),\n );\n\n useEffect(() => {\n if (observedItems?.value) {\n const currentValue = observedItems?.value ?? [];\n setDismissedBanners(new Set(currentValue));\n }\n }, [observedItems?.value]);\n\n const handleClick = () => {\n notificationsStore.set('dismissedBanners', [...dismissedBanners, id]);\n };\n\n return (\n <Snackbar\n anchorOrigin={\n fixed\n ? { vertical: 'bottom', horizontal: 'center' }\n : { vertical: 'top', horizontal: 'center' }\n }\n open={!dismissedBanners.has(id)}\n classes={{\n root: classNames(classes.root, !fixed && classes.topPosition),\n }}\n >\n <SnackbarContent\n classes={{\n root: classNames(classes.content, classes[variant]),\n message: classes.message,\n }}\n message={message}\n action={[\n <IconButton\n key=\"dismiss\"\n title=\"Permanently dismiss this message\"\n className={classes.button}\n onClick={handleClick}\n >\n <Close className={classes.icon} />\n </IconButton>,\n ]}\n />\n </Snackbar>\n );\n};\n"],"names":["Close"],"mappings":";;;;;;;;;;AA0CA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,CAAU,KAAA,MAAA;AAAA,IACR,IAAM,EAAA;AAAA,MACJ,OAAA,EAAS,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACxB,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC7B,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC1B,OAAS,EAAA,MAAA;AAAA,MACT,QAAU,EAAA,YAAA;AAAA,KACZ;AAAA;AAAA,IAEA,WAAa,EAAA;AAAA,MACX,QAAU,EAAA,UAAA;AAAA,MACV,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC7B,SAAW,EAAA,CAAC,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC3B,MAAQ,EAAA,OAAA;AAAA,KACV;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,QAAA,EAAU,KAAM,CAAA,UAAA,CAAW,EAAG,CAAA,QAAA;AAAA,KAChC;AAAA,IACA,OAAS,EAAA;AAAA,MACP,KAAO,EAAA,MAAA;AAAA,MACP,QAAU,EAAA,SAAA;AAAA,MACV,QAAU,EAAA,QAAA;AAAA,MACV,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,IAAA;AAAA,KAC9B;AAAA,IACA,OAAS,EAAA;AAAA,MACP,OAAS,EAAA,MAAA;AAAA,MACT,UAAY,EAAA,QAAA;AAAA,MACZ,KAAO,EAAA;AAAA,QACL,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,IAA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