@sentry/scraps 0.4.0 → 0.5.0
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/README.md +6 -5
- package/dist/alert/alert.js +0 -3
- package/dist/badge/badge.js +1 -2
- package/dist/badge/tag.js +0 -2
- package/dist/button/index.d.ts +0 -1
- package/dist/button/index.js +0 -1
- package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
- package/dist/clipboard/copyToClipboardButton.js +32 -0
- package/dist/clipboard/index.d.ts +1 -0
- package/dist/clipboard/index.js +1 -0
- package/dist/code/index.d.ts +1 -0
- package/dist/code/index.js +1 -0
- package/dist/codeBlock/codeBlock.d.ts +68 -0
- package/dist/codeBlock/codeBlock.js +242 -0
- package/dist/codeBlock/index.d.ts +2 -0
- package/dist/codeBlock/index.js +2 -0
- package/dist/codeBlock/prism.d.ts +11 -0
- package/dist/codeBlock/prism.js +101 -0
- package/dist/codeBlock/styles.d.ts +2 -0
- package/dist/codeBlock/styles.js +133 -0
- package/dist/compactSelect/compactSelect.d.ts +21 -0
- package/dist/compactSelect/compactSelect.js +150 -0
- package/dist/compactSelect/composite.d.ts +54 -0
- package/dist/compactSelect/composite.js +101 -0
- package/dist/compactSelect/control.d.ts +112 -0
- package/dist/compactSelect/control.js +354 -0
- package/dist/compactSelect/fzf.d.ts +8 -0
- package/dist/compactSelect/fzf.js +151 -0
- package/dist/compactSelect/gridList/index.d.ts +46 -0
- package/dist/compactSelect/gridList/index.js +102 -0
- package/dist/compactSelect/gridList/option.d.ts +15 -0
- package/dist/compactSelect/gridList/option.js +111 -0
- package/dist/compactSelect/gridList/section.d.ts +15 -0
- package/dist/compactSelect/gridList/section.js +58 -0
- package/dist/compactSelect/highlightText.d.ts +6 -0
- package/dist/compactSelect/highlightText.js +33 -0
- package/dist/compactSelect/index.d.ts +9 -0
- package/dist/compactSelect/index.js +8 -0
- package/dist/compactSelect/list.d.ts +94 -0
- package/dist/compactSelect/list.js +167 -0
- package/dist/compactSelect/listBox/index.d.ts +84 -0
- package/dist/compactSelect/listBox/index.js +175 -0
- package/dist/compactSelect/listBox/option.d.ts +19 -0
- package/dist/compactSelect/listBox/option.js +101 -0
- package/dist/compactSelect/listBox/section.d.ts +21 -0
- package/dist/compactSelect/listBox/section.js +58 -0
- package/dist/compactSelect/menuComponents.d.ts +89 -0
- package/dist/compactSelect/menuComponents.js +117 -0
- package/dist/compactSelect/selectFilterContext.d.ts +2 -0
- package/dist/compactSelect/selectFilterContext.js +3 -0
- package/dist/compactSelect/styles.d.ts +39 -0
- package/dist/compactSelect/styles.js +155 -0
- package/dist/compactSelect/types.d.ts +1 -0
- package/dist/compactSelect/types.js +0 -0
- package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
- package/dist/compactSelect/useVirtualizedItems.js +74 -0
- package/dist/compactSelect/utils.d.ts +80 -0
- package/dist/compactSelect/utils.js +268 -0
- package/dist/confirm/index.d.ts +153 -0
- package/dist/confirm/index.js +132 -0
- package/dist/descriptionList/descriptionList.js +4 -3
- package/dist/disclosure/disclosure.js +2 -2
- package/dist/dragHandle/dragHandle.d.ts +3 -1
- package/dist/dragHandle/dragHandle.js +8 -5
- package/dist/drawer/components.d.ts +46 -0
- package/dist/drawer/components.js +265 -0
- package/dist/drawer/globalDrawer.d.ts +106 -0
- package/dist/drawer/globalDrawer.js +173 -0
- package/dist/drawer/index.d.ts +3 -0
- package/dist/drawer/index.js +2 -0
- package/dist/drawer/useDrawerResizing.d.ts +19 -0
- package/dist/drawer/useDrawerResizing.js +111 -0
- package/dist/drawer/useDrawerWidth.d.ts +1 -0
- package/dist/drawer/useDrawerWidth.js +42 -0
- package/dist/dropdownMenu/content.d.ts +1 -0
- package/dist/dropdownMenu/content.js +1 -0
- package/dist/dropdownMenu/context.d.ts +24 -0
- package/dist/dropdownMenu/context.js +3 -0
- package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
- package/dist/dropdownMenu/dropdownMenu.js +103 -0
- package/dist/dropdownMenu/index.d.ts +2 -0
- package/dist/dropdownMenu/index.js +1 -0
- package/dist/dropdownMenu/item.d.ts +136 -0
- package/dist/dropdownMenu/item.js +182 -0
- package/dist/dropdownMenu/list.d.ts +59 -0
- package/dist/dropdownMenu/list.js +410 -0
- package/dist/dropdownMenu/search.d.ts +16 -0
- package/dist/dropdownMenu/search.js +16 -0
- package/dist/dropdownMenu/section.d.ts +21 -0
- package/dist/dropdownMenu/section.js +40 -0
- package/dist/dropdownMenu/separator.d.ts +7 -0
- package/dist/dropdownMenu/separator.js +15 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +260 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +55 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
- package/dist/dropdownMenu/useSafetyTriangle.d.ts +12 -0
- package/dist/dropdownMenu/useSafetyTriangle.js +119 -0
- package/dist/dropdownMenu/utils.d.ts +21 -0
- package/dist/dropdownMenu/utils.js +57 -0
- package/dist/form/FormSearch.d.ts +19 -0
- package/dist/form/FormSearch.js +4 -0
- package/dist/form/autoSaveForm.d.ts +110 -0
- package/dist/form/autoSaveForm.js +100 -0
- package/dist/{formPresentation → form}/displayField.js +2 -2
- package/dist/form/field/baseField.d.ts +23 -0
- package/dist/form/field/baseField.js +116 -0
- package/dist/form/field/checkboxField.d.ts +11 -0
- package/dist/form/field/checkboxField.js +42 -0
- package/dist/form/field/checkboxGroupField.d.ts +16 -0
- package/dist/form/field/checkboxGroupField.js +80 -0
- package/dist/form/field/compactSelectField.d.ts +19 -0
- package/dist/form/field/compactSelectField.js +77 -0
- package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
- package/dist/form/field/inputField.d.ts +19 -0
- package/dist/form/field/inputField.js +31 -0
- package/dist/{formPresentation → form/field}/meta.js +6 -6
- package/dist/form/field/numberField.d.ts +5 -0
- package/dist/form/field/numberField.js +11 -0
- package/dist/form/field/passwordField.d.ts +3 -0
- package/dist/form/field/passwordField.js +27 -0
- package/dist/form/field/radioGroupField.d.ts +16 -0
- package/dist/form/field/radioGroupField.js +92 -0
- package/dist/form/field/rangeField.d.ts +8 -0
- package/dist/form/field/rangeField.js +34 -0
- package/dist/form/field/selectAsyncField.d.ts +31 -0
- package/dist/form/field/selectAsyncField.js +22 -0
- package/dist/form/field/selectField.d.ts +9 -0
- package/dist/form/field/selectField.js +72 -0
- package/dist/form/field/switchField.d.ts +7 -0
- package/dist/form/field/switchField.js +37 -0
- package/dist/form/field/textAreaField.d.ts +7 -0
- package/dist/form/field/textAreaField.js +25 -0
- package/dist/{formPresentation → form}/formContext.js +1 -1
- package/dist/form/formErrorContext/index.d.ts +9 -0
- package/dist/form/formErrorContext/index.js +7 -0
- package/dist/form/index.d.ts +9 -0
- package/dist/form/index.js +8 -0
- package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
- package/dist/{formPresentation → form/layout}/base.js +1 -1
- package/dist/form/layout/fieldGroup.d.ts +6 -0
- package/dist/form/layout/fieldGroup.js +60 -0
- package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
- package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
- package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
- package/dist/form/scrapsForm.d.ts +220 -0
- package/dist/form/scrapsForm.js +126 -0
- package/dist/hotkey/hotkey.d.ts +9 -8
- package/dist/hotkey/hotkey.js +13 -6
- package/dist/hotkey/index.d.ts +2 -1
- package/dist/hotkey/index.js +2 -1
- package/dist/hotkey/keyMappings.d.ts +1 -15
- package/dist/hotkey/keyMappings.js +29 -174
- package/dist/hotkey/useHotkeys.d.ts +3 -47
- package/dist/hotkey/useHotkeys.js +8 -42
- package/dist/image/image.js +2 -1
- package/dist/info/infoTip.d.ts +1 -1
- package/dist/info/infoTip.js +4 -3
- package/dist/input/index.d.ts +0 -3
- package/dist/input/index.js +0 -2
- package/dist/input/input.d.ts +2 -0
- package/dist/input/input.js +2 -0
- package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
- package/dist/input/passwordManagerIgnoreProps.js +8 -0
- package/dist/layout/index.d.ts +2 -2
- package/dist/layout/index.js +1 -1
- package/dist/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +2 -0
- package/dist/link/linkBehaviorContext.js +17 -10
- package/dist/menu/index.d.ts +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/menu.d.ts +14 -6
- package/dist/menu/menu.js +160 -56
- package/dist/modal/components.d.ts +19 -0
- package/dist/modal/components.js +99 -0
- package/dist/modal/errorBoundary.d.ts +2 -0
- package/dist/modal/errorBoundary.js +35 -0
- package/dist/modal/index.d.ts +33 -0
- package/dist/modal/index.js +260 -0
- package/dist/modal/portal.d.ts +1 -0
- package/dist/modal/portal.js +10 -0
- package/dist/modal/state.d.ts +17 -0
- package/dist/modal/state.js +41 -0
- package/dist/modal/types.d.ts +75 -0
- package/dist/modal/types.js +0 -0
- package/dist/numberInput/index.d.ts +3 -0
- package/dist/numberInput/index.js +2 -0
- package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberDragInput.js +1 -1
- package/dist/{input → numberInput}/numberInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberInput.js +1 -1
- package/dist/overlayContext.d.ts +29 -0
- package/dist/overlayContext.js +7 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/pagination.d.ts +24 -0
- package/dist/pagination/pagination.js +63 -0
- package/dist/pictureInPicture/index.d.ts +2 -0
- package/dist/pictureInPicture/index.js +2 -0
- package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
- package/dist/pictureInPicture/pictureInPicture.js +100 -0
- package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
- package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
- package/dist/pictureInPicture/portalContext.d.ts +2 -0
- package/dist/pictureInPicture/portalContext.js +3 -0
- package/dist/revealOnHover/revealOnHover.js +1 -1
- package/dist/segmentedControl/segmentedControl.js +1 -1
- package/dist/select/filter.d.ts +4 -0
- package/dist/select/filter.js +12 -0
- package/dist/select/index.d.ts +3 -0
- package/dist/select/index.js +2 -0
- package/dist/select/option.d.ts +16 -0
- package/dist/select/option.js +81 -0
- package/dist/select/reactSelectWrapper.d.ts +8 -0
- package/dist/select/reactSelectWrapper.js +25 -0
- package/dist/select/select.d.ts +79 -0
- package/dist/select/select.js +454 -0
- package/dist/select/styles.d.ts +9 -0
- package/dist/select/styles.js +27 -0
- package/dist/select/types.d.ts +60 -0
- package/dist/select/types.js +0 -0
- package/dist/select/virtualizedMenuList.d.ts +24 -0
- package/dist/select/virtualizedMenuList.js +123 -0
- package/dist/slideOverPanel.d.ts +20 -0
- package/dist/slideOverPanel.js +141 -0
- package/dist/splitPanel/splitPanel.d.ts +3 -1
- package/dist/splitPanel/splitPanel.js +2 -1
- package/dist/table/table.d.ts +1 -1
- package/dist/table/table.js +39 -20
- package/dist/table/useColumnResize.d.ts +6 -5
- package/dist/table/useColumnResize.js +5 -4
- package/dist/tabs/index.d.ts +4 -0
- package/dist/tabs/index.js +3 -0
- package/dist/tabs/item.d.ts +13 -0
- package/dist/tabs/item.js +4 -0
- package/dist/tabs/tab.d.ts +22 -0
- package/dist/tabs/tab.js +205 -0
- package/dist/tabs/tabList.d.ts +18 -0
- package/dist/tabs/tabList.js +256 -0
- package/dist/tabs/tabPanels.d.ts +14 -0
- package/dist/tabs/tabPanels.js +62 -0
- package/dist/tabs/tabs.d.ts +38 -0
- package/dist/tabs/tabs.js +56 -0
- package/dist/tabs/utils.d.ts +3 -0
- package/dist/tabs/utils.js +6 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/heading.js +1 -1
- package/dist/text/styles.js +1 -1
- package/dist/text/text.d.ts +1 -1
- package/dist/text/text.js +1 -1
- package/dist/theme/dark.js +9 -9
- package/dist/theme/light.js +9 -9
- package/dist/tooltip/tooltip.js +2 -5
- package/dist/useMedia.d.ts +15 -0
- package/dist/useMedia.js +24 -0
- package/dist/useOnClickOutside.d.ts +2 -0
- package/dist/useOnClickOutside.js +22 -0
- package/dist/useOverlay.d.ts +1 -0
- package/dist/useOverlay.js +1 -0
- package/dist/useVirtualCollection.d.ts +154 -0
- package/dist/useVirtualCollection.js +143 -0
- package/dist/useVirtualRows.d.ts +26 -0
- package/dist/useVirtualRows.js +26 -0
- package/dist/virtualCollectionLayout.d.ts +51 -0
- package/dist/virtualCollectionLayout.js +49 -0
- package/package.json +115 -16
- package/dist/formPresentation/index.d.ts +0 -8
- package/dist/formPresentation/index.js +0 -8
- package/dist/interactionStateLayer/index.d.ts +0 -1
- package/dist/interactionStateLayer/index.js +0 -1
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
- package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
- package/dist/unreachable.d.ts +0 -1
- package/dist/unreachable.js +0 -4
- /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
- /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
- /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
- /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.js +0 -0
- /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ The source code is open, but the system is designed for Sentry and is not intend
|
|
|
6
6
|
|
|
7
7
|
## Development in Sentry
|
|
8
8
|
|
|
9
|
-
The package source lives in [src](./src). Component
|
|
9
|
+
The package source lives in [src](./src). Component docs (`.mdx`) sit next to their components and render in the app's Scraps viewer; `.npmignore` and the build config keep them out of the published package.
|
|
10
10
|
|
|
11
|
-
Move components and their
|
|
11
|
+
Move components, their tests, and their docs into `src` as they become isolated. The [Scraps contribution guide](../../app/components/core/overview/contributing.mdx) covers component contributions and the Figma process for changing design tokens.
|
|
12
12
|
|
|
13
13
|
Run package checks from the repository root:
|
|
14
14
|
|
|
@@ -43,9 +43,10 @@ Import from its explicit subpaths, including `@sentry/scraps/code/inlineCode`
|
|
|
43
43
|
and `@sentry/scraps/hotkey/kbd`. The package has no root export; unlisted module
|
|
44
44
|
paths remain private.
|
|
45
45
|
Add an entry only when its runtime and type dependencies belong to the package
|
|
46
|
-
or are declared dependencies.
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
or are declared dependencies. Both `Hotkey` and `Kbd` are isolated and exported
|
|
47
|
+
from `@sentry/scraps/hotkey`; `Kbd` also has its own `@sentry/scraps/hotkey/kbd`
|
|
48
|
+
entry point. App stories cover more components than this API. Published consumers
|
|
49
|
+
have no fallback to app components.
|
|
49
50
|
|
|
50
51
|
Consumers provide Emotion's `ThemeProvider` with `lightTheme` or `darkTheme`.
|
|
51
52
|
The package does not include application providers, global CSS, or fonts.
|
package/dist/alert/alert.js
CHANGED
|
@@ -13,7 +13,6 @@ import { Container, Flex, Grid } from "../layout/index.js";
|
|
|
13
13
|
import { PanelProvider } from "../panelProvider.js";
|
|
14
14
|
import { Text } from "../text/index.js";
|
|
15
15
|
import { useTranslation } from "../translation/useTranslation.js";
|
|
16
|
-
import { unreachable } from "../unreachable.js";
|
|
17
16
|
const AlertPanel = styled('div')`
|
|
18
17
|
position: relative;
|
|
19
18
|
display: grid;
|
|
@@ -83,7 +82,6 @@ function getAlertTokens(variant, theme) {
|
|
|
83
82
|
border: theme.tokens.border.primary
|
|
84
83
|
};
|
|
85
84
|
default:
|
|
86
|
-
unreachable(variant);
|
|
87
85
|
}
|
|
88
86
|
throw new TypeError(`Invalid alert variant, got ${variant}`);
|
|
89
87
|
}
|
|
@@ -240,7 +238,6 @@ function AlertIcon({ variant }) {
|
|
|
240
238
|
case 'muted':
|
|
241
239
|
return /*#__PURE__*/ jsx(IconInfo, {});
|
|
242
240
|
default:
|
|
243
|
-
unreachable(variant);
|
|
244
241
|
}
|
|
245
242
|
return null;
|
|
246
243
|
}
|
package/dist/badge/badge.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import styled from "@emotion/styled";
|
|
2
|
-
import { unreachable } from "../unreachable.js";
|
|
3
2
|
const Badge = styled('span')`
|
|
4
3
|
${(p)=>({
|
|
5
4
|
...makeBadgeTheme(p, p.theme)
|
|
@@ -73,7 +72,7 @@ function makeBadgeTheme(p, theme) {
|
|
|
73
72
|
background: theme.tokens.background.transparent.success.muted
|
|
74
73
|
};
|
|
75
74
|
default:
|
|
76
|
-
|
|
75
|
+
p.variant;
|
|
77
76
|
throw new TypeError(`Unsupported badge variant: ${p.variant}`);
|
|
78
77
|
}
|
|
79
78
|
}
|
package/dist/badge/tag.js
CHANGED
|
@@ -4,7 +4,6 @@ import { IconClose } from "@sentry/icons/close";
|
|
|
4
4
|
import { IconDefaultsProvider } from "@sentry/icons/useIconDefaults";
|
|
5
5
|
import { Button } from "../button/index.js";
|
|
6
6
|
import { useTranslation } from "../translation/useTranslation.js";
|
|
7
|
-
import { unreachable } from "../unreachable.js";
|
|
8
7
|
function Tag({ ref, variant, icon, onDismiss, children, ...props }) {
|
|
9
8
|
const { t } = useTranslation();
|
|
10
9
|
return /*#__PURE__*/ jsxs(TagPill, {
|
|
@@ -91,7 +90,6 @@ function makeTagPillTheme(type, theme) {
|
|
|
91
90
|
background: theme.tokens.background.transparent.success.muted
|
|
92
91
|
};
|
|
93
92
|
default:
|
|
94
|
-
unreachable(type);
|
|
95
93
|
throw new TypeError(`Unsupported badge type: ${type}`);
|
|
96
94
|
}
|
|
97
95
|
}
|
package/dist/button/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { Button, type ButtonProps } from './button.js';
|
|
2
2
|
export { ButtonBar, type ButtonBarProps } from './buttonBar.js';
|
|
3
3
|
export { LinkButton, type LinkButtonProps } from './linkButton.js';
|
|
4
|
-
export { DO_NOT_USE_getButtonStyles } from './styles.js';
|
|
5
4
|
export type { ButtonSize } from './types.js';
|
package/dist/button/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type ButtonProps } from '../button/index.js';
|
|
3
|
+
export interface CopyToClipboardButtonProps extends Omit<Extract<ButtonProps, {
|
|
4
|
+
'aria-label': string;
|
|
5
|
+
}>, 'children' | 'onCopy' | 'onError'> {
|
|
6
|
+
text: string;
|
|
7
|
+
children?: never;
|
|
8
|
+
/** Custom failure feedback. Pass false to suppress the toast. */
|
|
9
|
+
errorMessage?: React.ReactNode;
|
|
10
|
+
onCopy?: (copiedText: string) => void;
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
/** Custom success feedback. Pass false to suppress the toast. */
|
|
13
|
+
successMessage?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function CopyToClipboardButton({ onCopy, onError, onClick, text, icon, errorMessage, successMessage, ...props }: CopyToClipboardButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { IconCopy } from "@sentry/icons/copy";
|
|
3
|
+
import { Button } from "../button/index.js";
|
|
4
|
+
import { toast } from "../toast/index.js";
|
|
5
|
+
import { useTranslation } from "../translation/index.js";
|
|
6
|
+
function CopyToClipboardButton({ onCopy, onError, onClick, text, icon, errorMessage, successMessage, ...props }) {
|
|
7
|
+
const { t } = useTranslation();
|
|
8
|
+
async function copy() {
|
|
9
|
+
try {
|
|
10
|
+
await navigator.clipboard.writeText(text);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
const message = errorMessage ?? t('Error copying to clipboard');
|
|
13
|
+
if (message) toast.error(message);
|
|
14
|
+
onError?.(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const message = successMessage ?? t('Copied to clipboard');
|
|
18
|
+
if (message) toast.success(message);
|
|
19
|
+
onCopy?.(text);
|
|
20
|
+
}
|
|
21
|
+
return /*#__PURE__*/ jsx(Button, {
|
|
22
|
+
...props,
|
|
23
|
+
onClick: (event)=>{
|
|
24
|
+
copy();
|
|
25
|
+
onClick?.(event);
|
|
26
|
+
},
|
|
27
|
+
icon: icon ?? /*#__PURE__*/ jsx(IconCopy, {
|
|
28
|
+
variant: "muted"
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export { CopyToClipboardButton };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CopyToClipboardButton, type CopyToClipboardButtonProps, } from './copyToClipboardButton.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CopyToClipboardButton } from "./copyToClipboardButton.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InlineCode, inlineCodeStyles } from './inlineCode.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InlineCode, inlineCodeStyles } from "./inlineCode.js";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
export interface CodeBlockProps {
|
|
3
|
+
children: string;
|
|
4
|
+
/**
|
|
5
|
+
* Keeps the copy button visible when it floats over the code snippet.
|
|
6
|
+
*/
|
|
7
|
+
alwaysShowCopyButton?: boolean;
|
|
8
|
+
className?: string;
|
|
9
|
+
dark?: boolean;
|
|
10
|
+
['data-render-inline']?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Makes the text of the element and its sub-elements not selectable.
|
|
13
|
+
* Useful when loading parts of a code snippet, and
|
|
14
|
+
* we wish to avoid users copying them manually.
|
|
15
|
+
*/
|
|
16
|
+
disableUserSelection?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Name of the file to be displayed at the top of the code snippet.
|
|
19
|
+
*/
|
|
20
|
+
filename?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Hides the copy button in the top right.
|
|
23
|
+
*/
|
|
24
|
+
hideCopyButton?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Adds an icon to the top right, next to the copy button.
|
|
27
|
+
*/
|
|
28
|
+
icon?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Controls whether the snippet wrapper has rounded corners.
|
|
31
|
+
*/
|
|
32
|
+
isRounded?: boolean;
|
|
33
|
+
language?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Line numbers of the code that will be visually highlighted.
|
|
36
|
+
*/
|
|
37
|
+
linesToHighlight?: number[];
|
|
38
|
+
/**
|
|
39
|
+
* Fires after the code snippet is highlighted and all DOM nodes are available
|
|
40
|
+
* @param element The root element of the code snippet
|
|
41
|
+
*/
|
|
42
|
+
onAfterHighlight?: (element: HTMLElement) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Fires with the user presses the copy button.
|
|
45
|
+
*/
|
|
46
|
+
onCopy?: (copiedCode: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Fires when the user selects and copies code snippet manually
|
|
49
|
+
*/
|
|
50
|
+
onSelectAndCopy?: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Fires when the user switches tabs.
|
|
53
|
+
*/
|
|
54
|
+
onTabClick?: (tab: string) => void;
|
|
55
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
56
|
+
selectedTab?: string;
|
|
57
|
+
tabs?: Array<{
|
|
58
|
+
label: string;
|
|
59
|
+
value: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Controls whether long lines scroll horizontally or wrap within the snippet.
|
|
63
|
+
*
|
|
64
|
+
* @default 'scroll'
|
|
65
|
+
*/
|
|
66
|
+
wrapMode?: 'scroll' | 'wrap';
|
|
67
|
+
}
|
|
68
|
+
export declare function CodeBlock({ alwaysShowCopyButton, children, className, dark, 'data-render-inline': dataRenderInline, disableUserSelection, filename, hideCopyButton, language, linesToHighlight, icon, isRounded, onAfterHighlight, onCopy, onSelectAndCopy, onTabClick, ref: forwardedRef, selectedTab, tabs, wrapMode, }: CodeBlockProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { ThemeProvider, css, useTheme } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { IconCopy } from "@sentry/icons/copy";
|
|
6
|
+
import prismjs from "prismjs";
|
|
7
|
+
import { Button } from "../button/index.js";
|
|
8
|
+
import { Container } from "../layout/index.js";
|
|
9
|
+
import { darkTheme } from "../theme/index.js";
|
|
10
|
+
import { useTranslation } from "../translation/index.js";
|
|
11
|
+
import { getPrismLanguage, loadPrismLanguage } from "./prism.js";
|
|
12
|
+
import { codeBlockStyles } from "./styles.js";
|
|
13
|
+
function CodeBlock({ alwaysShowCopyButton, children, className, dark, 'data-render-inline': dataRenderInline, disableUserSelection, filename, hideCopyButton, language, linesToHighlight, icon, isRounded = true, onAfterHighlight, onCopy, onSelectAndCopy, onTabClick, ref: forwardedRef, selectedTab, tabs, wrapMode = 'scroll' }) {
|
|
14
|
+
const { t } = useTranslation();
|
|
15
|
+
const ref = useRef(null);
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
const [lineHighlightLoaded, setLineHighlightLoaded] = useState(false);
|
|
18
|
+
useEffect(()=>{
|
|
19
|
+
async function loadLineHighlight() {
|
|
20
|
+
await import("prismjs/plugins/line-highlight/prism-line-highlight.js");
|
|
21
|
+
setLineHighlightLoaded(true);
|
|
22
|
+
}
|
|
23
|
+
if (linesToHighlight) loadLineHighlight();
|
|
24
|
+
}, [
|
|
25
|
+
linesToHighlight
|
|
26
|
+
]);
|
|
27
|
+
useEffect(()=>{
|
|
28
|
+
const element = ref.current;
|
|
29
|
+
if (!element) return;
|
|
30
|
+
if (!language || !getPrismLanguage(language)) return;
|
|
31
|
+
if (language in prismjs.languages) return void prismjs.highlightElement(element, false, ()=>onAfterHighlight?.(element));
|
|
32
|
+
loadPrismLanguage(language, {
|
|
33
|
+
onLoad: ()=>prismjs.highlightElement(element, false, ()=>onAfterHighlight?.(element))
|
|
34
|
+
});
|
|
35
|
+
}, [
|
|
36
|
+
children,
|
|
37
|
+
language,
|
|
38
|
+
onAfterHighlight,
|
|
39
|
+
lineHighlightLoaded
|
|
40
|
+
]);
|
|
41
|
+
const [tooltipState, setTooltipState] = useState('copy');
|
|
42
|
+
const handleCopy = ()=>{
|
|
43
|
+
navigator.clipboard.writeText(ref.current?.textContent ?? '').then(()=>{
|
|
44
|
+
setTooltipState('copied');
|
|
45
|
+
}).catch(()=>{
|
|
46
|
+
setTooltipState('error');
|
|
47
|
+
});
|
|
48
|
+
onCopy?.(children);
|
|
49
|
+
};
|
|
50
|
+
const hasTabs = tabs && tabs.length > 0;
|
|
51
|
+
const hasFloatingHeader = !(filename || hasTabs);
|
|
52
|
+
const tooltipTitle = 'copy' === tooltipState ? t('Copy') : 'copied' === tooltipState ? t('Copied') : t('Unable to copy');
|
|
53
|
+
const snippet = /*#__PURE__*/ jsxs(Wrapper, {
|
|
54
|
+
ref: forwardedRef,
|
|
55
|
+
reserveCopyButtonSpace: alwaysShowCopyButton && hasFloatingHeader,
|
|
56
|
+
isRounded: isRounded,
|
|
57
|
+
wrapMode: wrapMode,
|
|
58
|
+
className: `${dark ? 'prism-dark ' : ''}${className ?? ''}`,
|
|
59
|
+
"data-render-inline": dataRenderInline,
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ jsxs(Header, {
|
|
62
|
+
isFloating: hasFloatingHeader,
|
|
63
|
+
children: [
|
|
64
|
+
hasTabs && /*#__PURE__*/ jsxs(Fragment, {
|
|
65
|
+
children: [
|
|
66
|
+
/*#__PURE__*/ jsx(TabsWrapper, {
|
|
67
|
+
children: tabs.map(({ label, value })=>/*#__PURE__*/ jsx(Tab, {
|
|
68
|
+
type: "button",
|
|
69
|
+
isSelected: selectedTab === value,
|
|
70
|
+
onClick: ()=>onTabClick?.(value),
|
|
71
|
+
children: label
|
|
72
|
+
}, value))
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ jsx(Container, {
|
|
75
|
+
flexGrow: 1
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
}),
|
|
79
|
+
icon,
|
|
80
|
+
filename && /*#__PURE__*/ jsx(FileName, {
|
|
81
|
+
children: filename
|
|
82
|
+
}),
|
|
83
|
+
!hasTabs && /*#__PURE__*/ jsx(Container, {
|
|
84
|
+
flexGrow: 1
|
|
85
|
+
}),
|
|
86
|
+
!hideCopyButton && /*#__PURE__*/ jsx(CopyButton, {
|
|
87
|
+
type: "button",
|
|
88
|
+
size: "xs",
|
|
89
|
+
variant: "transparent",
|
|
90
|
+
onClick: handleCopy,
|
|
91
|
+
tooltipProps: {
|
|
92
|
+
position: 'left',
|
|
93
|
+
title: tooltipTitle
|
|
94
|
+
},
|
|
95
|
+
onMouseLeave: ()=>setTooltipState('copy'),
|
|
96
|
+
isAlwaysVisible: alwaysShowCopyButton || !hasFloatingHeader || !!icon && hasFloatingHeader,
|
|
97
|
+
"aria-label": t('Copy snippet'),
|
|
98
|
+
icon: /*#__PURE__*/ jsx(IconCopy, {})
|
|
99
|
+
})
|
|
100
|
+
]
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ jsx(ScrollWrapper, {
|
|
103
|
+
reserveCopyButtonSpace: alwaysShowCopyButton && hasFloatingHeader,
|
|
104
|
+
wrapMode: wrapMode,
|
|
105
|
+
children: /*#__PURE__*/ jsx("pre", {
|
|
106
|
+
className: `language-${String(language)}`,
|
|
107
|
+
"data-line": linesToHighlight?.join(','),
|
|
108
|
+
children: /*#__PURE__*/ jsx(Code, {
|
|
109
|
+
ref: ref,
|
|
110
|
+
className: `language-${String(language)}`,
|
|
111
|
+
onCopy: onSelectAndCopy,
|
|
112
|
+
disableUserSelection: disableUserSelection,
|
|
113
|
+
wrapMode: wrapMode,
|
|
114
|
+
children: children
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
]
|
|
119
|
+
});
|
|
120
|
+
return /*#__PURE__*/ jsx(ThemeProvider, {
|
|
121
|
+
theme: dark ? darkTheme : theme,
|
|
122
|
+
children: snippet
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const Wrapper = styled('div')`
|
|
126
|
+
${(p)=>codeBlockStyles(p.theme)};
|
|
127
|
+
|
|
128
|
+
position: relative;
|
|
129
|
+
height: 100%;
|
|
130
|
+
min-width: 0;
|
|
131
|
+
background: var(--prism-block-background);
|
|
132
|
+
border-radius: ${(p)=>p.isRounded ? p.theme.radius.md : '0px'};
|
|
133
|
+
|
|
134
|
+
&& code[class*='language-'] {
|
|
135
|
+
white-space: ${(p)=>'wrap' === p.wrapMode ? 'pre-wrap' : 'pre'};
|
|
136
|
+
overflow-wrap: ${(p)=>'wrap' === p.wrapMode ? 'anywhere' : 'normal'};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
&& pre[class*='language-'] {
|
|
140
|
+
margin: 0;
|
|
141
|
+
height: 100%;
|
|
142
|
+
width: ${(p)=>'wrap' === p.wrapMode ? '100%' : 'max-content'};
|
|
143
|
+
min-width: 100%;
|
|
144
|
+
white-space: ${(p)=>'wrap' === p.wrapMode ? 'pre-wrap' : 'pre'};
|
|
145
|
+
overflow-wrap: ${(p)=>'wrap' === p.wrapMode ? 'anywhere' : 'normal'};
|
|
146
|
+
|
|
147
|
+
${(p)=>'wrap' === p.wrapMode && p.reserveCopyButtonSpace && css`
|
|
148
|
+
&::before {
|
|
149
|
+
content: '';
|
|
150
|
+
float: right;
|
|
151
|
+
width: ${p.theme.space.lg};
|
|
152
|
+
height: ${p.theme.space.xl};
|
|
153
|
+
}
|
|
154
|
+
`}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&[data-render-inline='true'] pre {
|
|
158
|
+
padding: 0;
|
|
159
|
+
}
|
|
160
|
+
`;
|
|
161
|
+
const Header = styled('div')`
|
|
162
|
+
display: flex;
|
|
163
|
+
align-items: center;
|
|
164
|
+
|
|
165
|
+
font-family: ${(p)=>p.theme.font.family.mono};
|
|
166
|
+
font-size: ${(p)=>p.theme.font.size.sm};
|
|
167
|
+
color: var(--prism-base);
|
|
168
|
+
font-weight: ${(p)=>p.theme.font.weight.mono.medium};
|
|
169
|
+
z-index: 2;
|
|
170
|
+
|
|
171
|
+
${(p)=>p.isFloating ? css`
|
|
172
|
+
gap: ${p.theme.space['2xs']};
|
|
173
|
+
justify-content: flex-end;
|
|
174
|
+
position: absolute;
|
|
175
|
+
top: 0;
|
|
176
|
+
right: 0;
|
|
177
|
+
width: max-content;
|
|
178
|
+
height: max-content;
|
|
179
|
+
max-height: 100%;
|
|
180
|
+
padding: ${p.theme.space.xs};
|
|
181
|
+
` : css`
|
|
182
|
+
gap: ${p.theme.space.sm};
|
|
183
|
+
padding: ${p.theme.space.xs} ${p.theme.space.xs} 0 ${p.theme.space.md};
|
|
184
|
+
border-bottom: solid 1px ${p.theme.tokens.border.primary};
|
|
185
|
+
`}
|
|
186
|
+
`;
|
|
187
|
+
const FileName = styled('span')`
|
|
188
|
+
display: block;
|
|
189
|
+
white-space: nowrap;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
text-overflow: ellipsis;
|
|
192
|
+
width: auto;
|
|
193
|
+
`;
|
|
194
|
+
const TabsWrapper = styled('div')`
|
|
195
|
+
padding: 0;
|
|
196
|
+
display: flex;
|
|
197
|
+
overflow-x: auto;
|
|
198
|
+
`;
|
|
199
|
+
const Tab = styled('button')`
|
|
200
|
+
box-sizing: border-box;
|
|
201
|
+
display: block;
|
|
202
|
+
margin: 0;
|
|
203
|
+
border: none;
|
|
204
|
+
background: none;
|
|
205
|
+
padding: ${(p)=>p.theme.space.md} ${(p)=>p.theme.space.md};
|
|
206
|
+
color: var(--prism-comment);
|
|
207
|
+
${(p)=>p.isSelected ? css`
|
|
208
|
+
border-bottom: 3px solid ${p.theme.tokens.graphics.accent.vibrant};
|
|
209
|
+
padding-bottom: 5px;
|
|
210
|
+
color: var(--prism-base);
|
|
211
|
+
` : ''}
|
|
212
|
+
`;
|
|
213
|
+
const CopyButton = styled(Button)`
|
|
214
|
+
color: var(--prism-comment);
|
|
215
|
+
transition: opacity 0.1s ease-out;
|
|
216
|
+
opacity: 0;
|
|
217
|
+
|
|
218
|
+
div:hover > div > &, /* if Wrapper is hovered */
|
|
219
|
+
&:focus-visible {
|
|
220
|
+
opacity: 1;
|
|
221
|
+
}
|
|
222
|
+
&:hover {
|
|
223
|
+
color: var(--prism-base);
|
|
224
|
+
}
|
|
225
|
+
${(p)=>p.isAlwaysVisible ? 'opacity: 1;' : ''}
|
|
226
|
+
`;
|
|
227
|
+
const ScrollWrapper = styled('div')`
|
|
228
|
+
overflow-x: ${(p)=>'wrap' === p.wrapMode ? 'hidden' : 'auto'};
|
|
229
|
+
height: 100%;
|
|
230
|
+
margin-right: ${(p)=>'scroll' === p.wrapMode && p.reserveCopyButtonSpace ? p.theme.space['3xl'] : '0'};
|
|
231
|
+
`;
|
|
232
|
+
const Code = styled('code')`
|
|
233
|
+
user-select: ${(p)=>p.disableUserSelection ? 'none' : 'auto'};
|
|
234
|
+
|
|
235
|
+
${(p)=>'wrap' === p.wrapMode && css`
|
|
236
|
+
&& {
|
|
237
|
+
white-space: pre-wrap;
|
|
238
|
+
overflow-wrap: anywhere;
|
|
239
|
+
}
|
|
240
|
+
`}
|
|
241
|
+
`;
|
|
242
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const getPrismLanguage: (lang: string) => string | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Loads the specified Prism language (aliases like `js` for `javascript` also work).
|
|
4
|
+
* Will log a warning if a) the language doesn't exist (unless `suppressExistenceWarning`
|
|
5
|
+
* is true) or b) there was a problem downloading the grammar file.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadPrismLanguage(lang: string, { onError, onLoad, suppressExistenceWarning, }: {
|
|
8
|
+
onError?: (error: unknown) => void;
|
|
9
|
+
onLoad?: () => void;
|
|
10
|
+
suppressExistenceWarning?: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import prismjs from "prismjs";
|
|
2
|
+
import components from "prismjs/components.js";
|
|
3
|
+
const prismLanguages = components.languages;
|
|
4
|
+
prismjs.manual = true;
|
|
5
|
+
const PRISM_LANGUAGE_MAP = Object.fromEntries(Object.entries(prismLanguages).flatMap(([lang, value])=>{
|
|
6
|
+
if (!value.alias) return [
|
|
7
|
+
[
|
|
8
|
+
lang,
|
|
9
|
+
lang
|
|
10
|
+
]
|
|
11
|
+
];
|
|
12
|
+
return [
|
|
13
|
+
[
|
|
14
|
+
lang,
|
|
15
|
+
lang
|
|
16
|
+
],
|
|
17
|
+
...Array.isArray(value.alias) ? value.alias.map((alias)=>[
|
|
18
|
+
alias,
|
|
19
|
+
lang
|
|
20
|
+
]) : [
|
|
21
|
+
[
|
|
22
|
+
value.alias,
|
|
23
|
+
lang
|
|
24
|
+
]
|
|
25
|
+
]
|
|
26
|
+
];
|
|
27
|
+
}));
|
|
28
|
+
const EXTRA_LANGUAGE_ALIASES = {
|
|
29
|
+
cc: 'cpp',
|
|
30
|
+
erl: 'erlang',
|
|
31
|
+
ex: 'elixir',
|
|
32
|
+
h: 'c',
|
|
33
|
+
m: 'objectivec',
|
|
34
|
+
pl: 'perl',
|
|
35
|
+
pm: 'perl',
|
|
36
|
+
pyx: 'python',
|
|
37
|
+
rs: 'rust',
|
|
38
|
+
jbuilder: 'ruby',
|
|
39
|
+
ru: 'ruby',
|
|
40
|
+
rake: 'ruby',
|
|
41
|
+
rabl: 'ruby',
|
|
42
|
+
cjs: "javascript",
|
|
43
|
+
mjs: "javascript",
|
|
44
|
+
jsbundle: "javascript",
|
|
45
|
+
bundle: "javascript",
|
|
46
|
+
astro: "javascript",
|
|
47
|
+
vue: "javascript",
|
|
48
|
+
svelte: "javascript",
|
|
49
|
+
'js?': "javascript",
|
|
50
|
+
'ts?': "typescript",
|
|
51
|
+
'tsx?': 'tsx',
|
|
52
|
+
mts: "typescript",
|
|
53
|
+
clj: 'clojure',
|
|
54
|
+
cljc: 'clojure',
|
|
55
|
+
cljs: 'clojure',
|
|
56
|
+
php5: 'php',
|
|
57
|
+
phtml: 'php',
|
|
58
|
+
arb: 'json',
|
|
59
|
+
ps1: 'powershell',
|
|
60
|
+
jinja: 'jinja2',
|
|
61
|
+
gd: "gdscript"
|
|
62
|
+
};
|
|
63
|
+
const getPrismLanguage = (lang)=>{
|
|
64
|
+
const language = lang.toLowerCase();
|
|
65
|
+
const aliased = EXTRA_LANGUAGE_ALIASES[language];
|
|
66
|
+
return PRISM_LANGUAGE_MAP[aliased ?? language];
|
|
67
|
+
};
|
|
68
|
+
const pendingGrammars = new Map();
|
|
69
|
+
function loadGrammar(language) {
|
|
70
|
+
if (prismjs.languages[language]) return Promise.resolve();
|
|
71
|
+
const pending = pendingGrammars.get(language);
|
|
72
|
+
if (pending) return pending;
|
|
73
|
+
const load = async ()=>{
|
|
74
|
+
const required = prismLanguages[language]?.require;
|
|
75
|
+
const dependencies = Array.isArray(required) ? required : required ? [
|
|
76
|
+
required
|
|
77
|
+
] : [];
|
|
78
|
+
for (const dependency of dependencies)await loadGrammar(dependency);
|
|
79
|
+
await import(`prismjs/components/prism-${language}.min.js`);
|
|
80
|
+
};
|
|
81
|
+
const promise = load().finally(()=>pendingGrammars.delete(language));
|
|
82
|
+
pendingGrammars.set(language, promise);
|
|
83
|
+
return promise;
|
|
84
|
+
}
|
|
85
|
+
async function loadPrismLanguage(lang, { onError, onLoad, suppressExistenceWarning }) {
|
|
86
|
+
try {
|
|
87
|
+
const language = getPrismLanguage(lang);
|
|
88
|
+
if (language && prismjs.languages[language]) return void onLoad?.();
|
|
89
|
+
if (!language) {
|
|
90
|
+
if (!suppressExistenceWarning) console.warn(`No Prism grammar file for \`${lang}\` exists. Check the \`lang\` argument passed to \`loadPrismLanguage()\`.`);
|
|
91
|
+
onError?.(new Error(`No Prism grammar file for \`${lang}\` exists.`));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await loadGrammar(language);
|
|
95
|
+
onLoad?.();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.warn(`Cannot download Prism grammar file for \`${lang}\`. Check the internet connection, and the \`lang\` argument passed to \`loadPrismLanguage()\`.`);
|
|
98
|
+
onError?.(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export { getPrismLanguage, loadPrismLanguage };
|