fluent-svelte-extra 1.0.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/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/package.json +83 -0
- package/src/app.html +12 -0
- package/src/global.d.ts +1 -0
- package/src/lib/AutoSuggestBox/AutoSuggestBox.scss +44 -0
- package/src/lib/AutoSuggestBox/AutoSuggestBox.svelte +173 -0
- package/src/lib/Button/Button.scss +94 -0
- package/src/lib/Button/Button.svelte +48 -0
- package/src/lib/CalendarDatePicker/CalendarDatePicker.scss +15 -0
- package/src/lib/CalendarDatePicker/CalendarDatePicker.svelte +86 -0
- package/src/lib/CalendarView/CalendarView.scss +156 -0
- package/src/lib/CalendarView/CalendarView.svelte +753 -0
- package/src/lib/CalendarView/CalendarViewItem.scss +130 -0
- package/src/lib/CalendarView/CalendarViewItem.svelte +33 -0
- package/src/lib/Checkbox/Checkbox.scss +117 -0
- package/src/lib/Checkbox/Checkbox.svelte +81 -0
- package/src/lib/ComboBox/ComboBox.scss +152 -0
- package/src/lib/ComboBox/ComboBox.svelte +360 -0
- package/src/lib/ComboBox/ComboBoxItem.scss +80 -0
- package/src/lib/ComboBox/ComboBoxItem.svelte +30 -0
- package/src/lib/ContentDialog/ContentDialog.scss +68 -0
- package/src/lib/ContentDialog/ContentDialog.svelte +123 -0
- package/src/lib/ContextMenu/ContextMenu.scss +11 -0
- package/src/lib/ContextMenu/ContextMenu.svelte +104 -0
- package/src/lib/Expander/Expander.scss +134 -0
- package/src/lib/Expander/Expander.svelte +123 -0
- package/src/lib/Flipper/Flipper.svelte +49 -0
- package/src/lib/Flyout/FlyoutSurface.scss +14 -0
- package/src/lib/Flyout/FlyoutSurface.svelte +21 -0
- package/src/lib/Flyout/FlyoutWrapper.scss +81 -0
- package/src/lib/Flyout/FlyoutWrapper.svelte +126 -0
- package/src/lib/IconButton/IconButton.scss +31 -0
- package/src/lib/IconButton/IconButton.svelte +49 -0
- package/src/lib/InfoBadge/InfoBadge.scss +39 -0
- package/src/lib/InfoBadge/InfoBadge.svelte +81 -0
- package/src/lib/InfoBar/InfoBar.scss +122 -0
- package/src/lib/InfoBar/InfoBar.svelte +133 -0
- package/src/lib/ListItem/ListItem.scss +74 -0
- package/src/lib/ListItem/ListItem.svelte +88 -0
- package/src/lib/MenuBar/MenuBar.scss +10 -0
- package/src/lib/MenuBar/MenuBar.svelte +49 -0
- package/src/lib/MenuBar/MenuBarItem.scss +38 -0
- package/src/lib/MenuBar/MenuBarItem.svelte +135 -0
- package/src/lib/MenuBar/flyoutState.ts +5 -0
- package/src/lib/MenuFlyout/MenuFlyoutDivider.scss +7 -0
- package/src/lib/MenuFlyout/MenuFlyoutDivider.svelte +14 -0
- package/src/lib/MenuFlyout/MenuFlyoutItem.scss +147 -0
- package/src/lib/MenuFlyout/MenuFlyoutItem.svelte +239 -0
- package/src/lib/MenuFlyout/MenuFlyoutSurface.scss +42 -0
- package/src/lib/MenuFlyout/MenuFlyoutSurface.svelte +28 -0
- package/src/lib/MenuFlyout/MenuFlyoutWrapper.scss +64 -0
- package/src/lib/MenuFlyout/MenuFlyoutWrapper.svelte +114 -0
- package/src/lib/NavigationView/NavigationView.scss +0 -0
- package/src/lib/NavigationView/NavigationView.svelte +82 -0
- package/src/lib/NumberBox/NumberBox.scss +31 -0
- package/src/lib/NumberBox/NumberBox.svelte +267 -0
- package/src/lib/PersonPicture/PersonPicture.scss +35 -0
- package/src/lib/PersonPicture/PersonPicture.svelte +62 -0
- package/src/lib/ProgressBar/ProgressBar.scss +83 -0
- package/src/lib/ProgressBar/ProgressBar.svelte +60 -0
- package/src/lib/ProgressRing/ProgressRing.scss +37 -0
- package/src/lib/ProgressRing/ProgressRing.svelte +73 -0
- package/src/lib/RadioButton/RadioButton.scss +114 -0
- package/src/lib/RadioButton/RadioButton.svelte +67 -0
- package/src/lib/RangeSlider/RangeSlider.svelte +91 -0
- package/src/lib/ScrollView/ScrollView.svelte +9 -0
- package/src/lib/Slider/Slider.scss +263 -0
- package/src/lib/Slider/Slider.svelte +261 -0
- package/src/lib/TextBlock/TextBlock.scss +62 -0
- package/src/lib/TextBlock/TextBlock.svelte +70 -0
- package/src/lib/TextBox/TextBox.scss +108 -0
- package/src/lib/TextBox/TextBox.svelte +225 -0
- package/src/lib/TextBox/TextBoxButton.scss +34 -0
- package/src/lib/TextBox/TextBoxButton.svelte +27 -0
- package/src/lib/ToggleSwitch/ToggleSwitch.scss +118 -0
- package/src/lib/ToggleSwitch/ToggleSwitch.svelte +55 -0
- package/src/lib/Tooltip/TooltipSurface.scss +16 -0
- package/src/lib/Tooltip/TooltipSurface.svelte +27 -0
- package/src/lib/Tooltip/TooltipWrapper.scss +66 -0
- package/src/lib/Tooltip/TooltipWrapper.svelte +117 -0
- package/src/lib/_mixins.scss +130 -0
- package/src/lib/index.ts +33 -0
- package/src/lib/internal.ts +213 -0
- package/src/lib/svelte-jsx.d.ts +14 -0
- package/src/lib/theme.css +414 -0
- package/src/routes/__layout.svelte +48 -0
- package/src/routes/docs/__layout.svelte +122 -0
- package/src/routes/docs/components/button.md +43 -0
- package/src/routes/docs/components/calendarview.md +188 -0
- package/src/routes/docs/components/checkbox.md +87 -0
- package/src/routes/docs/components/contentdialog.md +155 -0
- package/src/routes/docs/components/expander.md +115 -0
- package/src/routes/docs/components/flyout.md +107 -0
- package/src/routes/docs/components/iconbutton.md +39 -0
- package/src/routes/docs/components/infobadge.md +54 -0
- package/src/routes/docs/components/infobar.md +102 -0
- package/src/routes/docs/components/listitem.md +87 -0
- package/src/routes/docs/components/personpicture.md +125 -0
- package/src/routes/docs/components/progressring.md +83 -0
- package/src/routes/docs/components/radiobutton.md +88 -0
- package/src/routes/docs/components/slider.md +165 -0
- package/src/routes/docs/components/textblock.md +46 -0
- package/src/routes/docs/components/textbox.md +124 -0
- package/src/routes/docs/components/toggleswitch.md +73 -0
- package/src/routes/docs/getting-started.md +116 -0
- package/src/routes/docs/index.md +37 -0
- package/src/routes/docs/internals/index.md +0 -0
- package/src/routes/index.svelte +121 -0
- package/src/routes/test/__layout-test.svelte +1 -0
- package/src/routes/test/index.svelte +757 -0
- package/src/routes/test/nav.svelte +7 -0
- package/src/site/data/docs.ts +176 -0
- package/src/site/data/home.ts +12 -0
- package/src/site/lib/APIDocs/APIDocs.svelte +178 -0
- package/src/site/lib/APIDocs/ParsedComponent.d.ts +85 -0
- package/src/site/lib/CopyBox/CopyBox.svelte +23 -0
- package/src/site/lib/Example/Example.scss +33 -0
- package/src/site/lib/Example/Example.svelte +18 -0
- package/src/site/lib/HeroCard/HeroCard.scss +24 -0
- package/src/site/lib/HeroCard/HeroCard.svelte +36 -0
- package/src/site/lib/Metadata/Metadata.svelte +14 -0
- package/src/site/lib/Navbar/Navbar.scss +92 -0
- package/src/site/lib/Navbar/Navbar.svelte +47 -0
- package/src/site/lib/PageSection/PageSection.scss +57 -0
- package/src/site/lib/PageSection/PageSection.svelte +10 -0
- package/src/site/lib/Showcase/Showcase.scss +53 -0
- package/src/site/lib/Showcase/Showcase.svelte +67 -0
- package/src/site/lib/Toc/Toc.scss +18 -0
- package/src/site/lib/Toc/Toc.svelte +59 -0
- package/src/site/lib/TreeView/TreeView.svelte +89 -0
- package/src/site/lib/index.ts +9 -0
- package/src/site/styles/_markdown.scss +260 -0
- package/src/site/styles/_mixins.scss +319 -0
- package/src/site/styles/global.scss +40 -0
- package/src/site/styles/pages/docs.scss +74 -0
- package/src/site/styles/pages/home.scss +134 -0
- package/static/bloom-mica-dark.png +0 -0
- package/static/bloom-mica-light.png +0 -0
- package/static/logo.svg +11 -0
- package/svelte.config.js +57 -0
- package/tsconfig.json +38 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
@use "sass:selector";
|
|
2
|
+
|
|
3
|
+
@mixin unify-parent($child) {
|
|
4
|
+
@at-root #{selector.unify(&, $child)} {
|
|
5
|
+
@content;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@mixin flex(
|
|
10
|
+
$direction: false,
|
|
11
|
+
$justify: false,
|
|
12
|
+
$align: false,
|
|
13
|
+
$inline: false,
|
|
14
|
+
$wrap: false,
|
|
15
|
+
$gap: false
|
|
16
|
+
) {
|
|
17
|
+
// display: flex/inline-flex
|
|
18
|
+
@if $inline {
|
|
19
|
+
display: inline-flex;
|
|
20
|
+
} @else {
|
|
21
|
+
display: flex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// flex-direction
|
|
25
|
+
@if $direction != false {
|
|
26
|
+
@if $direction == row {
|
|
27
|
+
flex-direction: row;
|
|
28
|
+
} @else if $direction == column {
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
} @else if $direction == row-reverse {
|
|
31
|
+
flex-direction: row-reverse;
|
|
32
|
+
} @else if $direction == column-reverse {
|
|
33
|
+
flex-direction: column-reverse;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// justify-content
|
|
38
|
+
@if $justify != false {
|
|
39
|
+
@if $justify == normal {
|
|
40
|
+
justify-content: normal;
|
|
41
|
+
} @else if $justify == center {
|
|
42
|
+
justify-content: center;
|
|
43
|
+
} @else if $justify == start {
|
|
44
|
+
justify-content: flex-start;
|
|
45
|
+
} @else if $justify == end {
|
|
46
|
+
justify-content: flex-end;
|
|
47
|
+
} @else if $justify == between {
|
|
48
|
+
justify-content: space-between;
|
|
49
|
+
} @else if $justify == around {
|
|
50
|
+
justify-content: space-around;
|
|
51
|
+
} @else if $justify == evenly {
|
|
52
|
+
justify-content: space-evenly;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// align-items/align-content
|
|
57
|
+
@if $align != false {
|
|
58
|
+
@if $align == normal {
|
|
59
|
+
align-items: normal;
|
|
60
|
+
} @else if $align == center {
|
|
61
|
+
align-items: center;
|
|
62
|
+
} @else if $align == start {
|
|
63
|
+
align-items: flex-start;
|
|
64
|
+
} @else if $align == end {
|
|
65
|
+
align-items: flex-end;
|
|
66
|
+
} @else if $align == between {
|
|
67
|
+
align-content: space-between;
|
|
68
|
+
} @else if $align == around {
|
|
69
|
+
align-content: space-around;
|
|
70
|
+
} @else if $align == evenly {
|
|
71
|
+
align-content: space-evenly;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// flex-wrap
|
|
76
|
+
@if $wrap {
|
|
77
|
+
flex-wrap: wrap;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// gap
|
|
81
|
+
@if $gap {
|
|
82
|
+
gap: $gap;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@mixin icon($size: var(--body-font-size)) {
|
|
87
|
+
inline-size: $size;
|
|
88
|
+
block-size: auto;
|
|
89
|
+
fill: currentColor;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@mixin typography-body {
|
|
93
|
+
user-select: none;
|
|
94
|
+
font: {
|
|
95
|
+
family: var(--font-family-text);
|
|
96
|
+
size: var(--body-font-size);
|
|
97
|
+
weight: normal;
|
|
98
|
+
}
|
|
99
|
+
line-height: 20px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// can't use this until chromium fixes their compositor
|
|
103
|
+
@mixin acrylic-brush {
|
|
104
|
+
background-color: var(--fds-solid-background-quarternary);
|
|
105
|
+
@supports (backdrop-filter: var(--fds-acrylic-blur-factor)) {
|
|
106
|
+
background-color: transparent;
|
|
107
|
+
&::before,
|
|
108
|
+
&::after {
|
|
109
|
+
content: "";
|
|
110
|
+
position: absolute;
|
|
111
|
+
inset: 0;
|
|
112
|
+
inline-size: 100%;
|
|
113
|
+
block-size: 100%;
|
|
114
|
+
}
|
|
115
|
+
&::after {
|
|
116
|
+
content: "";
|
|
117
|
+
background: var(--acrylic-noise-asset) center/256px repeat;
|
|
118
|
+
inset: 0;
|
|
119
|
+
z-index: -1;
|
|
120
|
+
opacity: 0.02;
|
|
121
|
+
}
|
|
122
|
+
&::before {
|
|
123
|
+
z-index: 0;
|
|
124
|
+
mix-blend-mode: luminosity;
|
|
125
|
+
background: var(--fds-acrylic-background-default);
|
|
126
|
+
background-blend-mode: color, luminosity;
|
|
127
|
+
backdrop-filter: var(--fds-acrylic-blur-factor);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { default as Button } from "./Button/Button.svelte";
|
|
2
|
+
export { default as Checkbox } from "./Checkbox/Checkbox.svelte";
|
|
3
|
+
export { default as ToggleSwitch } from "./ToggleSwitch/ToggleSwitch.svelte";
|
|
4
|
+
export { default as RadioButton } from "./RadioButton/RadioButton.svelte";
|
|
5
|
+
export { default as ProgressRing } from "./ProgressRing/ProgressRing.svelte";
|
|
6
|
+
export { default as ProgressBar } from "./ProgressBar/ProgressBar.svelte";
|
|
7
|
+
export { default as ComboBox } from "./ComboBox/ComboBox.svelte";
|
|
8
|
+
export { default as InfoBadge } from "./InfoBadge/InfoBadge.svelte";
|
|
9
|
+
export { default as Flyout } from "./Flyout/FlyoutWrapper.svelte";
|
|
10
|
+
export { default as InfoBar } from "./InfoBar/InfoBar.svelte";
|
|
11
|
+
export { default as TextBox } from "./TextBox/TextBox.svelte";
|
|
12
|
+
export { default as TextBoxButton } from "./TextBox/TextBoxButton.svelte";
|
|
13
|
+
export { default as NumberBox } from "./NumberBox/NumberBox.svelte";
|
|
14
|
+
export { default as AutoSuggestBox } from "./AutoSuggestBox/AutoSuggestBox.svelte";
|
|
15
|
+
export { default as Slider } from "./Slider/Slider.svelte";
|
|
16
|
+
export { default as PersonPicture } from "./PersonPicture/PersonPicture.svelte";
|
|
17
|
+
export { default as Tooltip } from "./Tooltip/TooltipWrapper.svelte";
|
|
18
|
+
export { default as ContentDialog } from "./ContentDialog/ContentDialog.svelte";
|
|
19
|
+
export { default as Expander } from "./Expander/Expander.svelte";
|
|
20
|
+
export { default as TextBlock } from "./TextBlock/TextBlock.svelte";
|
|
21
|
+
export { default as IconButton } from "./IconButton/IconButton.svelte";
|
|
22
|
+
export { default as ListItem } from "./ListItem/ListItem.svelte";
|
|
23
|
+
export { default as MenuBar } from "./MenuBar/MenuBar.svelte";
|
|
24
|
+
export { default as MenuBarItem } from "./MenuBar/MenuBarItem.svelte";
|
|
25
|
+
export { default as MenuFlyout } from "./MenuFlyout/MenuFlyoutWrapper.svelte";
|
|
26
|
+
export { default as MenuFlyoutItem } from "./MenuFlyout/MenuFlyoutItem.svelte";
|
|
27
|
+
export { default as MenuFlyoutDivider } from "./MenuFlyout/MenuFlyoutDivider.svelte";
|
|
28
|
+
export { default as ContextMenu } from "./ContextMenu/ContextMenu.svelte";
|
|
29
|
+
export { default as CalendarView } from "./CalendarView/CalendarView.svelte";
|
|
30
|
+
export { default as CalendarDatePicker } from "./CalendarDatePicker/CalendarDatePicker.svelte";
|
|
31
|
+
export { default as NavigationView } from "./NavigationView/NavigationView.svelte";
|
|
32
|
+
export { default as RangeSlider } from "./RangeSlider/RangeSlider.svelte";
|
|
33
|
+
export { default as Flipper } from "./Flipper/Flipper.svelte";
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Options as FocusTrapOptions } from "focus-trap";
|
|
3
|
+
|
|
4
|
+
import { bubble, listen } from "svelte/internal";
|
|
5
|
+
|
|
6
|
+
import { tabbable } from "tabbable";
|
|
7
|
+
import { createFocusTrap } from "focus-trap";
|
|
8
|
+
|
|
9
|
+
export { default as ComboBoxItem } from "./ComboBox/ComboBoxItem.svelte";
|
|
10
|
+
export { default as FlyoutSurface } from "./Flyout/FlyoutSurface.svelte";
|
|
11
|
+
export { default as TooltipSurface } from "./Tooltip/TooltipSurface.svelte";
|
|
12
|
+
export { default as MenuFlyoutSurface } from "./MenuFlyout/MenuFlyoutSurface.svelte";
|
|
13
|
+
export { default as CalendarViewItem } from "./CalendarView/CalendarViewItem.svelte";
|
|
14
|
+
|
|
15
|
+
// Svelte action for handling outer mouse
|
|
16
|
+
interface ExternalMouseEventOptions {
|
|
17
|
+
type?: string;
|
|
18
|
+
stopPropagation?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export function externalMouseEvents(
|
|
21
|
+
node: HTMLElement,
|
|
22
|
+
options: ExternalMouseEventOptions = { type: "click", stopPropagation: false }
|
|
23
|
+
) {
|
|
24
|
+
const { type, stopPropagation } = options;
|
|
25
|
+
const handleEvent = (event: MouseEvent) => {
|
|
26
|
+
if (stopPropagation) event.stopPropagation();
|
|
27
|
+
if (node && !node.contains(event.target as HTMLElement) && !event.defaultPrevented) {
|
|
28
|
+
node.dispatchEvent(
|
|
29
|
+
new CustomEvent(`outer${type}`, {
|
|
30
|
+
detail: event
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
document.addEventListener(type, handleEvent, true);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
destroy() {
|
|
40
|
+
document.removeEventListener(type, handleEvent, true);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Basic wrapper action around focus-trap
|
|
46
|
+
export function focusTrap(node: HTMLElement, options?: FocusTrapOptions) {
|
|
47
|
+
const trap = createFocusTrap(node, (options = { ...options, fallbackFocus: node }));
|
|
48
|
+
trap.activate();
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
destroy() {
|
|
52
|
+
trap.deactivate();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ID generator for handling WAI-ARIA related attributes
|
|
58
|
+
export function uid(prefix: string) {
|
|
59
|
+
return (
|
|
60
|
+
prefix +
|
|
61
|
+
String.fromCharCode(Math.floor(Math.random() * 26) + 97) +
|
|
62
|
+
Math.random().toString(16).slice(2) +
|
|
63
|
+
Date.now().toString(16).split(".")[0]
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface ArrowNavigationOptions {
|
|
68
|
+
preventTab?: boolean;
|
|
69
|
+
stopPropagation?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Controls the focus of a list of elements by using the arrow keys
|
|
73
|
+
export function arrowNavigation(
|
|
74
|
+
node: HTMLElement,
|
|
75
|
+
options: ArrowNavigationOptions = { preventTab: false, stopPropagation: false }
|
|
76
|
+
) {
|
|
77
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
78
|
+
const { key } = event;
|
|
79
|
+
const { activeElement } = document;
|
|
80
|
+
|
|
81
|
+
let tabOrder = <HTMLElement[]>tabbable(node);
|
|
82
|
+
// if (directChildren) tabOrder = tabOrder.filter(child => child.parentElement === node);
|
|
83
|
+
const activeIndex = tabOrder.indexOf(document.activeElement as HTMLElement);
|
|
84
|
+
|
|
85
|
+
if (tabOrder.length < 0) return;
|
|
86
|
+
if (
|
|
87
|
+
key === "ArrowUp" ||
|
|
88
|
+
key === "ArrowDown" ||
|
|
89
|
+
key === "Home" ||
|
|
90
|
+
key === "End" ||
|
|
91
|
+
(key === "Tab" && options.preventTab)
|
|
92
|
+
) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
if (options.stopPropagation) event.stopPropagation();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (key === "ArrowUp") {
|
|
98
|
+
if (tabOrder[0] === activeElement) {
|
|
99
|
+
tabOrder[tabOrder.length - 1].focus();
|
|
100
|
+
} else if (tabOrder.includes(<HTMLElement>activeElement)) {
|
|
101
|
+
tabOrder[activeIndex - 1].focus();
|
|
102
|
+
}
|
|
103
|
+
} else if (key === "ArrowDown") {
|
|
104
|
+
if (tabOrder[tabOrder.length - 1] === activeElement) {
|
|
105
|
+
tabOrder[0].focus();
|
|
106
|
+
} else if (tabOrder.includes(<HTMLElement>activeElement)) {
|
|
107
|
+
tabOrder[activeIndex + 1].focus();
|
|
108
|
+
}
|
|
109
|
+
} else if (key === "Home") {
|
|
110
|
+
tabOrder[0].focus();
|
|
111
|
+
} else if (key === "End") {
|
|
112
|
+
tabOrder[tabOrder.length - 1].focus();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
node.addEventListener("keydown", handleKeyDown);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
destroy: () => node.removeEventListener("keydown", handleKeyDown)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Returns a number representing the duration of a specified CSS custom property in ms
|
|
124
|
+
export function getCSSDuration(property) {
|
|
125
|
+
const duration = window.getComputedStyle(document.documentElement).getPropertyValue(property);
|
|
126
|
+
|
|
127
|
+
return parseFloat(duration) * (/\ds$/.test(duration) ? 1000 : 1) || 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Function for forwarding DOM events to the component's declaration
|
|
131
|
+
// Adapted from rgossiaux/svelte-headlessui which is modified from hperrin/svelte-material-ui
|
|
132
|
+
export function createEventForwarder(component: SvelteComponent, exclude: string[] = []) {
|
|
133
|
+
type EventCallback = (event: any) => void;
|
|
134
|
+
|
|
135
|
+
// This is our pseudo $on function. It is defined on component mount.
|
|
136
|
+
let $on: (eventType: string, callback: EventCallback) => () => void;
|
|
137
|
+
|
|
138
|
+
// This is a list of events bound before mount.
|
|
139
|
+
let events: [string, EventCallback][] = [];
|
|
140
|
+
|
|
141
|
+
// Monkeypatch SvelteComponent.$on with our own forward-compatible version
|
|
142
|
+
component.$on = (eventType: string, callback: EventCallback) => {
|
|
143
|
+
let destructor = () => {};
|
|
144
|
+
if (exclude.includes(eventType)) {
|
|
145
|
+
// Bail out of the event forwarding and run the normal Svelte $on() code
|
|
146
|
+
const callbacks =
|
|
147
|
+
component.$$.callbacks[eventType] || (component.$$.callbacks[eventType] = []);
|
|
148
|
+
callbacks.push(callback);
|
|
149
|
+
return () => {
|
|
150
|
+
const index = callbacks.indexOf(callback);
|
|
151
|
+
if (index !== -1) callbacks.splice(index, 1);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if ($on) {
|
|
155
|
+
destructor = $on(eventType, callback); // The event was bound programmatically.
|
|
156
|
+
} else {
|
|
157
|
+
events.push([eventType, callback]); // The event was bound before mount by Svelte.
|
|
158
|
+
}
|
|
159
|
+
return () => destructor();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return (node: HTMLElement | SVGElement) => {
|
|
163
|
+
const destructors: (() => void)[] = [];
|
|
164
|
+
const forwardDestructors: { [k: string]: () => void } = {};
|
|
165
|
+
const forward = (e: Event) => bubble(component, e);
|
|
166
|
+
|
|
167
|
+
// This function is responsible for listening and forwarding
|
|
168
|
+
// all bound events.
|
|
169
|
+
$on = (eventType, callback) => {
|
|
170
|
+
let handler = callback;
|
|
171
|
+
// DOM addEventListener options argument.
|
|
172
|
+
let options: boolean | AddEventListenerOptions = false;
|
|
173
|
+
|
|
174
|
+
// Listen for the event directly, with the given options.
|
|
175
|
+
const off = listen(node, eventType, handler, options);
|
|
176
|
+
const destructor = () => {
|
|
177
|
+
off();
|
|
178
|
+
const idx = destructors.indexOf(destructor);
|
|
179
|
+
if (idx > -1) {
|
|
180
|
+
destructors.splice(idx, 1);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
destructors.push(destructor);
|
|
185
|
+
|
|
186
|
+
// Forward the event from Svelte.
|
|
187
|
+
if (!(eventType in forwardDestructors)) {
|
|
188
|
+
forwardDestructors[eventType] = listen(node, eventType, forward);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return destructor;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// Listen to all the events added before mount.
|
|
195
|
+
for (const event of events) {
|
|
196
|
+
$on(event[0], event[1]);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
destroy: () => {
|
|
201
|
+
// Remove all event listeners.
|
|
202
|
+
for (const destructor of destructors) {
|
|
203
|
+
destructor();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Remove all event forwarders.
|
|
207
|
+
for (let entry of Object.entries(forwardDestructors)) {
|
|
208
|
+
entry[1]();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace svelte.JSX {
|
|
2
|
+
interface HTMLAttributes<T> {
|
|
3
|
+
onouterclick?: () => void;
|
|
4
|
+
onoutercontextmenu?: () => void;
|
|
5
|
+
onouterdblclick?: () => void;
|
|
6
|
+
onoutermousedown?: () => void;
|
|
7
|
+
onoutermouseenter?: () => void;
|
|
8
|
+
onoutermouseleave?: () => void;
|
|
9
|
+
onoutermousemove?: () => void;
|
|
10
|
+
onoutermouseout?: () => void;
|
|
11
|
+
onoutermouseover?: () => void;
|
|
12
|
+
onoutermouseup?: () => void;
|
|
13
|
+
}
|
|
14
|
+
}
|