@geoffcox/sterling-svelte 0.0.15 → 0.0.17
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/@types/clickOutside.d.ts +9 -3
- package/{buttons/Button.svelte → Button.svelte} +27 -27
- package/{inputs/Checkbox.svelte → Checkbox.svelte} +16 -16
- package/{surfaces/Dialog.svelte → Dialog.svelte} +34 -21
- package/{inputs/Input.svelte → Input.svelte} +22 -22
- package/Label.svelte +52 -0
- package/Label.svelte.d.ts +42 -0
- package/List.constants.d.ts +1 -0
- package/List.constants.js +1 -0
- package/List.svelte +324 -0
- package/List.svelte.d.ts +69 -0
- package/List.types.d.ts +6 -0
- package/ListItem.svelte +90 -0
- package/ListItem.svelte.d.ts +51 -0
- package/Menu.svelte +115 -0
- package/Menu.svelte.d.ts +20 -0
- package/MenuBar.svelte +97 -0
- package/MenuBar.svelte.d.ts +43 -0
- package/MenuButton.svelte +102 -0
- package/MenuButton.svelte.d.ts +54 -0
- package/MenuItem.svelte +338 -0
- package/MenuItem.svelte.d.ts +61 -0
- package/MenuItemDisplay.svelte +97 -0
- package/MenuItemDisplay.svelte.d.ts +21 -0
- package/MenuSeparator.svelte +42 -0
- package/MenuSeparator.svelte.d.ts +76 -0
- package/Menus.constants.d.ts +2 -0
- package/Menus.constants.js +2 -0
- package/Menus.types.d.ts +22 -0
- package/Menus.utils.d.ts +5 -0
- package/Menus.utils.js +20 -0
- package/Portal.svelte +14 -0
- package/Portal.svelte.d.ts +21 -0
- package/{display/Progress.svelte → Progress.svelte} +14 -14
- package/{inputs/Radio.svelte → Radio.svelte} +15 -15
- package/{inputs/Select.svelte → Select.svelte} +96 -102
- package/{inputs/Select.svelte.d.ts → Select.svelte.d.ts} +20 -25
- package/{inputs/Slider.svelte → Slider.svelte} +49 -24
- package/{inputs/Slider.svelte.d.ts → Slider.svelte.d.ts} +25 -0
- package/{inputs/Switch.svelte → Switch.svelte} +38 -38
- package/Tab.svelte +181 -0
- package/{containers/Tab.svelte.d.ts → Tab.svelte.d.ts} +12 -15
- package/TabList.svelte +247 -0
- package/{containers/TabList.svelte.d.ts → TabList.svelte.d.ts} +21 -21
- package/TabList.types.d.ts +7 -0
- package/{inputs/TextArea.svelte → TextArea.svelte} +23 -23
- package/TextArea.types.js +1 -0
- package/Tooltip.svelte +182 -0
- package/Tooltip.svelte.d.ts +24 -0
- package/Tooltip.types.d.ts +3 -0
- package/Tooltip.types.js +1 -0
- package/Tree.constants.d.ts +2 -0
- package/Tree.constants.js +2 -0
- package/Tree.svelte +142 -0
- package/Tree.svelte.d.ts +25 -0
- package/Tree.types.d.ts +28 -0
- package/Tree.types.js +1 -0
- package/{containers/TreeChevron.svelte → TreeChevron.svelte} +3 -3
- package/TreeItem.svelte +276 -0
- package/TreeItem.svelte.d.ts +65 -0
- package/{containers/TreeItem.svelte → TreeItemDisplay.svelte} +18 -18
- package/{containers/TreeItem.svelte.d.ts → TreeItemDisplay.svelte.d.ts} +11 -14
- package/{clickOutside.js → actions/clickOutside.js} +3 -1
- package/actions/forwardEvents.d.ts +12 -0
- package/actions/forwardEvents.js +32 -0
- package/actions/portal.d.ts +8 -0
- package/actions/portal.js +19 -0
- package/index.d.ts +42 -24
- package/index.js +39 -19
- package/package.json +45 -29
- package/theme/darkTheme.js +66 -74
- package/theme/lightTheme.js +66 -74
- package/containers/List.svelte +0 -249
- package/containers/List.svelte.d.ts +0 -68
- package/containers/ListItem.svelte +0 -48
- package/containers/ListItem.svelte.d.ts +0 -26
- package/containers/Tab.svelte +0 -327
- package/containers/TabList.svelte +0 -126
- package/containers/Tabs.types.d.ts +0 -12
- package/containers/Tree.constants.d.ts +0 -2
- package/containers/Tree.constants.js +0 -2
- package/containers/Tree.svelte +0 -222
- package/containers/Tree.svelte.d.ts +0 -50
- package/containers/Tree.types.d.ts +0 -47
- package/containers/TreeNode.svelte +0 -267
- package/containers/TreeNode.svelte.d.ts +0 -43
- package/display/Label.svelte +0 -27
- package/display/Label.svelte.d.ts +0 -20
- package/surfaces/CloseX.svelte +0 -5
- package/surfaces/CloseX.svelte.d.ts +0 -23
- /package/{buttons/Button.svelte.d.ts → Button.svelte.d.ts} +0 -0
- /package/{buttons/Button.types.d.ts → Button.types.d.ts} +0 -0
- /package/{buttons/Button.types.js → Button.types.js} +0 -0
- /package/{inputs/Checkbox.svelte.d.ts → Checkbox.svelte.d.ts} +0 -0
- /package/{surfaces/Dialog.svelte.d.ts → Dialog.svelte.d.ts} +0 -0
- /package/{inputs/Input.svelte.d.ts → Input.svelte.d.ts} +0 -0
- /package/{containers/Tabs.types.js → List.types.js} +0 -0
- /package/{containers/Tree.types.js → Menus.types.js} +0 -0
- /package/{display/Progress.svelte.d.ts → Progress.svelte.d.ts} +0 -0
- /package/{display/Progress.types.d.ts → Progress.types.d.ts} +0 -0
- /package/{display/Progress.types.js → Progress.types.js} +0 -0
- /package/{inputs/Radio.svelte.d.ts → Radio.svelte.d.ts} +0 -0
- /package/{inputs/Switch.svelte.d.ts → Switch.svelte.d.ts} +0 -0
- /package/{containers/Tabs.constants.d.ts → TabList.constants.d.ts} +0 -0
- /package/{containers/Tabs.constants.js → TabList.constants.js} +0 -0
- /package/{inputs/TextArea.types.js → TabList.types.js} +0 -0
- /package/{inputs/TextArea.svelte.d.ts → TextArea.svelte.d.ts} +0 -0
- /package/{inputs/TextArea.types.d.ts → TextArea.types.d.ts} +0 -0
- /package/{containers/TreeChevron.svelte.d.ts → TreeChevron.svelte.d.ts} +0 -0
- /package/{clickOutside.d.ts → actions/clickOutside.d.ts} +0 -0
package/MenuBar.svelte
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from "svelte";
|
|
2
|
+
import { menuBarContextKey, menuItemContextKey } from "./Menus.constants";
|
|
3
|
+
import { writable } from "svelte/store";
|
|
4
|
+
const dispatch = createEventDispatcher();
|
|
5
|
+
const raiseClose = (value) => {
|
|
6
|
+
dispatch("close", { value });
|
|
7
|
+
};
|
|
8
|
+
const raiseOpen = (value) => {
|
|
9
|
+
dispatch("open", { value });
|
|
10
|
+
};
|
|
11
|
+
const raiseSelect = (value) => {
|
|
12
|
+
dispatch("select", { value });
|
|
13
|
+
};
|
|
14
|
+
const children = writable([]);
|
|
15
|
+
const openPreviousChild = (currentValue) => {
|
|
16
|
+
const index = $children?.findIndex((menuItem) => menuItem.value === currentValue);
|
|
17
|
+
if (index !== -1) {
|
|
18
|
+
const focusIndex = index === 0 ? $children.length - 1 : index - 1;
|
|
19
|
+
$children[focusIndex].focus();
|
|
20
|
+
$children[focusIndex].open();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const openNextChild = (currentValue) => {
|
|
24
|
+
const index = $children?.findIndex((menuItem) => menuItem.value === currentValue);
|
|
25
|
+
if (index !== -1) {
|
|
26
|
+
const focusIndex = (index + 1) % $children.length;
|
|
27
|
+
$children[focusIndex].focus();
|
|
28
|
+
$children[focusIndex].open();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const focusChild = (value) => {
|
|
32
|
+
const focusIndex = $children?.findIndex((menuItem) => menuItem.value === value);
|
|
33
|
+
if (focusIndex !== -1) {
|
|
34
|
+
$children[focusIndex].focus();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
setContext(menuItemContextKey, {
|
|
38
|
+
register: (menuItem) => {
|
|
39
|
+
children.set([...$children, menuItem]);
|
|
40
|
+
},
|
|
41
|
+
unregister: (menuItem) => {
|
|
42
|
+
children.set($children.filter((x) => x.value !== menuItem.value));
|
|
43
|
+
},
|
|
44
|
+
closeMenu: (recursive) => {
|
|
45
|
+
},
|
|
46
|
+
focusPrevious: openPreviousChild,
|
|
47
|
+
focusNext: openNextChild,
|
|
48
|
+
onClose: raiseClose,
|
|
49
|
+
onOpen: raiseOpen,
|
|
50
|
+
onSelect: raiseSelect
|
|
51
|
+
});
|
|
52
|
+
setContext(menuBarContextKey, {
|
|
53
|
+
openPreviousMenu: openPreviousChild,
|
|
54
|
+
openNextMenu: openNextChild
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<div
|
|
59
|
+
class="sterling-menu-bar"
|
|
60
|
+
role="menubar"
|
|
61
|
+
on:blur
|
|
62
|
+
on:click
|
|
63
|
+
on:copy
|
|
64
|
+
on:cut
|
|
65
|
+
on:dblclick
|
|
66
|
+
on:focus
|
|
67
|
+
on:focusin
|
|
68
|
+
on:focusout
|
|
69
|
+
on:keydown
|
|
70
|
+
on:keypress
|
|
71
|
+
on:keyup
|
|
72
|
+
on:mousedown
|
|
73
|
+
on:mouseenter
|
|
74
|
+
on:mouseleave
|
|
75
|
+
on:mousemove
|
|
76
|
+
on:mouseover
|
|
77
|
+
on:mouseout
|
|
78
|
+
on:mouseup
|
|
79
|
+
on:scroll
|
|
80
|
+
on:wheel
|
|
81
|
+
on:paste
|
|
82
|
+
{...$$restProps}
|
|
83
|
+
>
|
|
84
|
+
<slot />
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<style>
|
|
88
|
+
.sterling-menu-bar {
|
|
89
|
+
background-color: transparent;
|
|
90
|
+
align-items: center;
|
|
91
|
+
align-content: stretch;
|
|
92
|
+
display: flex;
|
|
93
|
+
gap: 1em;
|
|
94
|
+
justify-content: flex-start;
|
|
95
|
+
justify-items: flex-start;
|
|
96
|
+
}
|
|
97
|
+
</style>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: never;
|
|
5
|
+
};
|
|
6
|
+
events: {
|
|
7
|
+
blur: FocusEvent;
|
|
8
|
+
click: MouseEvent;
|
|
9
|
+
copy: ClipboardEvent;
|
|
10
|
+
cut: ClipboardEvent;
|
|
11
|
+
dblclick: MouseEvent;
|
|
12
|
+
focus: FocusEvent;
|
|
13
|
+
focusin: FocusEvent;
|
|
14
|
+
focusout: FocusEvent;
|
|
15
|
+
keydown: KeyboardEvent;
|
|
16
|
+
keypress: KeyboardEvent;
|
|
17
|
+
keyup: KeyboardEvent;
|
|
18
|
+
mousedown: MouseEvent;
|
|
19
|
+
mouseenter: MouseEvent;
|
|
20
|
+
mouseleave: MouseEvent;
|
|
21
|
+
mousemove: MouseEvent;
|
|
22
|
+
mouseover: MouseEvent;
|
|
23
|
+
mouseout: MouseEvent;
|
|
24
|
+
mouseup: MouseEvent;
|
|
25
|
+
scroll: Event;
|
|
26
|
+
wheel: WheelEvent;
|
|
27
|
+
paste: ClipboardEvent;
|
|
28
|
+
close: CustomEvent<any>;
|
|
29
|
+
open: CustomEvent<any>;
|
|
30
|
+
select: CustomEvent<any>;
|
|
31
|
+
} & {
|
|
32
|
+
[evt: string]: CustomEvent<any>;
|
|
33
|
+
};
|
|
34
|
+
slots: {
|
|
35
|
+
default: {};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type MenuBarProps = typeof __propDef.props;
|
|
39
|
+
export type MenuBarEvents = typeof __propDef.events;
|
|
40
|
+
export type MenuBarSlots = typeof __propDef.slots;
|
|
41
|
+
export default class MenuBar extends SvelteComponentTyped<MenuBarProps, MenuBarEvents, MenuBarSlots> {
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<script>import { v4 as uuid } from "uuid";
|
|
2
|
+
import { createEventDispatcher, getContext, setContext } from "svelte";
|
|
3
|
+
import { writable } from "svelte/store";
|
|
4
|
+
import Button from "./Button.svelte";
|
|
5
|
+
import Menu from "./Menu.svelte";
|
|
6
|
+
import { menuItemContextKey } from "./Menus.constants";
|
|
7
|
+
import { focusFirstChild, focusNextChild, focusPreviousChild } from "./Menus.utils";
|
|
8
|
+
export let open = false;
|
|
9
|
+
export let shape = "rounded";
|
|
10
|
+
export let value;
|
|
11
|
+
export let variant = "regular";
|
|
12
|
+
const instanceId = uuid();
|
|
13
|
+
let reference;
|
|
14
|
+
$:
|
|
15
|
+
menuId = `${value}-menu-${instanceId}`;
|
|
16
|
+
$:
|
|
17
|
+
hasChildren = $$slots.items;
|
|
18
|
+
const children = writable([]);
|
|
19
|
+
const dispatch = createEventDispatcher();
|
|
20
|
+
const raiseClose = (value2) => {
|
|
21
|
+
dispatch("close", { value: value2 });
|
|
22
|
+
};
|
|
23
|
+
const raiseOpen = (value2) => {
|
|
24
|
+
dispatch("open", { value: value2 });
|
|
25
|
+
};
|
|
26
|
+
const raiseSelect = (value2) => {
|
|
27
|
+
dispatch("select", { value: value2 });
|
|
28
|
+
};
|
|
29
|
+
const onClick = () => {
|
|
30
|
+
open = !open;
|
|
31
|
+
if (open) {
|
|
32
|
+
setTimeout(() => focusFirstChild($children), 10);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
setContext(menuItemContextKey, {
|
|
36
|
+
rootValue: value,
|
|
37
|
+
depth: 1,
|
|
38
|
+
register: (menuItem) => {
|
|
39
|
+
children.set([...$children, menuItem]);
|
|
40
|
+
},
|
|
41
|
+
unregister: (menuItem) => {
|
|
42
|
+
children.set($children.filter((x) => x.value !== menuItem.value));
|
|
43
|
+
},
|
|
44
|
+
closeMenu: (recursive) => {
|
|
45
|
+
open = false;
|
|
46
|
+
},
|
|
47
|
+
focusPrevious: (currentValue) => focusPreviousChild($children, currentValue),
|
|
48
|
+
focusNext: (currentValue) => focusNextChild($children, currentValue),
|
|
49
|
+
onOpen: raiseOpen,
|
|
50
|
+
onClose: raiseClose,
|
|
51
|
+
onSelect: raiseSelect
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<!--
|
|
56
|
+
@component
|
|
57
|
+
A Button that displays a context menu when clicked.
|
|
58
|
+
-->
|
|
59
|
+
<Button
|
|
60
|
+
aria-controls={menuId}
|
|
61
|
+
aria-expanded={open}
|
|
62
|
+
aria-haspopup={hasChildren}
|
|
63
|
+
aria-owns={menuId}
|
|
64
|
+
data-value={value}
|
|
65
|
+
data-root-value={value}
|
|
66
|
+
{variant}
|
|
67
|
+
{shape}
|
|
68
|
+
on:blur
|
|
69
|
+
on:click
|
|
70
|
+
on:click={onClick}
|
|
71
|
+
on:dblclick
|
|
72
|
+
on:focus
|
|
73
|
+
on:focusin
|
|
74
|
+
on:focusout
|
|
75
|
+
on:keydown
|
|
76
|
+
on:keypress
|
|
77
|
+
on:keyup
|
|
78
|
+
on:mousedown
|
|
79
|
+
on:mouseenter
|
|
80
|
+
on:mouseleave
|
|
81
|
+
on:mousemove
|
|
82
|
+
on:mouseover
|
|
83
|
+
on:mouseout
|
|
84
|
+
on:mouseup
|
|
85
|
+
on:pointercancel
|
|
86
|
+
on:pointerdown
|
|
87
|
+
on:pointerenter
|
|
88
|
+
on:pointerleave
|
|
89
|
+
on:pointermove
|
|
90
|
+
on:pointerover
|
|
91
|
+
on:pointerout
|
|
92
|
+
on:pointerup
|
|
93
|
+
on:wheel
|
|
94
|
+
{...$$restProps}
|
|
95
|
+
>
|
|
96
|
+
<div bind:this={reference}>
|
|
97
|
+
<slot />
|
|
98
|
+
<Menu id={menuId} {reference} {open}>
|
|
99
|
+
<slot name="items" />
|
|
100
|
+
</Menu>
|
|
101
|
+
</div>
|
|
102
|
+
</Button>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { ButtonShape, ButtonVariant } from './Button.types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
open?: boolean | undefined;
|
|
7
|
+
shape?: ButtonShape | undefined;
|
|
8
|
+
value: string;
|
|
9
|
+
variant?: ButtonVariant | undefined;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
blur: FocusEvent;
|
|
13
|
+
click: MouseEvent;
|
|
14
|
+
dblclick: MouseEvent;
|
|
15
|
+
focus: FocusEvent;
|
|
16
|
+
focusin: FocusEvent;
|
|
17
|
+
focusout: FocusEvent;
|
|
18
|
+
keydown: KeyboardEvent;
|
|
19
|
+
keypress: KeyboardEvent;
|
|
20
|
+
keyup: KeyboardEvent;
|
|
21
|
+
mousedown: MouseEvent;
|
|
22
|
+
mouseenter: MouseEvent;
|
|
23
|
+
mouseleave: MouseEvent;
|
|
24
|
+
mousemove: MouseEvent;
|
|
25
|
+
mouseover: MouseEvent;
|
|
26
|
+
mouseout: MouseEvent;
|
|
27
|
+
mouseup: MouseEvent;
|
|
28
|
+
pointercancel: PointerEvent;
|
|
29
|
+
pointerdown: PointerEvent;
|
|
30
|
+
pointerenter: PointerEvent;
|
|
31
|
+
pointerleave: PointerEvent;
|
|
32
|
+
pointermove: PointerEvent;
|
|
33
|
+
pointerover: PointerEvent;
|
|
34
|
+
pointerout: PointerEvent;
|
|
35
|
+
pointerup: PointerEvent;
|
|
36
|
+
wheel: WheelEvent;
|
|
37
|
+
close: CustomEvent<any>;
|
|
38
|
+
open: CustomEvent<any>;
|
|
39
|
+
select: CustomEvent<any>;
|
|
40
|
+
} & {
|
|
41
|
+
[evt: string]: CustomEvent<any>;
|
|
42
|
+
};
|
|
43
|
+
slots: {
|
|
44
|
+
default: {};
|
|
45
|
+
items: {};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type MenuButtonProps = typeof __propDef.props;
|
|
49
|
+
export type MenuButtonEvents = typeof __propDef.events;
|
|
50
|
+
export type MenuButtonSlots = typeof __propDef.slots;
|
|
51
|
+
/** A Button that displays a context menu when clicked. */
|
|
52
|
+
export default class MenuButton extends SvelteComponentTyped<MenuButtonProps, MenuButtonEvents, MenuButtonSlots> {
|
|
53
|
+
}
|
|
54
|
+
export {};
|
package/MenuItem.svelte
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
<script>import { createKeyborg } from "keyborg";
|
|
2
|
+
import { v4 as uuid } from "uuid";
|
|
3
|
+
import { getContext, onMount, setContext } from "svelte";
|
|
4
|
+
import { writable } from "svelte/store";
|
|
5
|
+
import { clickOutside } from "./actions/clickOutside";
|
|
6
|
+
import { afterUpdate, createEventDispatcher } from "svelte/internal";
|
|
7
|
+
import MenuItemDisplay from "./MenuItemDisplay.svelte";
|
|
8
|
+
import { menuBarContextKey, menuItemContextKey } from "./Menus.constants";
|
|
9
|
+
import Menu from "./Menu.svelte";
|
|
10
|
+
import {
|
|
11
|
+
focusFirstChild,
|
|
12
|
+
focusLastChild,
|
|
13
|
+
focusNextChild,
|
|
14
|
+
focusPreviousChild
|
|
15
|
+
} from "./Menus.utils";
|
|
16
|
+
export let checked = false;
|
|
17
|
+
export let composed = false;
|
|
18
|
+
export let disabled = false;
|
|
19
|
+
export let open = false;
|
|
20
|
+
export let value;
|
|
21
|
+
export let role = "menuitem";
|
|
22
|
+
export let text = void 0;
|
|
23
|
+
const {
|
|
24
|
+
rootValue = value,
|
|
25
|
+
depth = 0,
|
|
26
|
+
register = void 0,
|
|
27
|
+
unregister = void 0,
|
|
28
|
+
closeMenu = void 0,
|
|
29
|
+
focusPrevious = void 0,
|
|
30
|
+
focusNext = void 0,
|
|
31
|
+
onOpen = void 0,
|
|
32
|
+
onClose = void 0,
|
|
33
|
+
onSelect = void 0
|
|
34
|
+
} = getContext(menuItemContextKey) || {};
|
|
35
|
+
const { openPreviousMenu = void 0, openNextMenu = void 0 } = getContext(menuBarContextKey) || {};
|
|
36
|
+
const instanceId = uuid();
|
|
37
|
+
$:
|
|
38
|
+
displayId = `${value}-display-${instanceId}`;
|
|
39
|
+
$:
|
|
40
|
+
menuId = `${value}-menu-${instanceId}`;
|
|
41
|
+
let menuItemRef;
|
|
42
|
+
const children = writable([]);
|
|
43
|
+
let mounted = false;
|
|
44
|
+
let prevOpen = open;
|
|
45
|
+
$:
|
|
46
|
+
hasChildren = $$slots.default;
|
|
47
|
+
const dispatch = createEventDispatcher();
|
|
48
|
+
const raiseClose = (value2) => {
|
|
49
|
+
dispatch("close", { value: value2 });
|
|
50
|
+
onClose?.(value2);
|
|
51
|
+
};
|
|
52
|
+
const raiseOpen = (value2) => {
|
|
53
|
+
dispatch("open", { value: value2 });
|
|
54
|
+
onOpen?.(value2);
|
|
55
|
+
};
|
|
56
|
+
$: {
|
|
57
|
+
if (hasChildren && open !== prevOpen) {
|
|
58
|
+
open ? raiseOpen(value) : raiseClose(value);
|
|
59
|
+
}
|
|
60
|
+
prevOpen = open;
|
|
61
|
+
}
|
|
62
|
+
const raiseSelect = (value2) => {
|
|
63
|
+
dispatch("select", { value: value2 });
|
|
64
|
+
onSelect?.(value2);
|
|
65
|
+
};
|
|
66
|
+
let keyborg = createKeyborg(window);
|
|
67
|
+
let usingKeyboard = keyborg.isNavigatingWithKeyboard();
|
|
68
|
+
const keyborgHandler = (value2) => {
|
|
69
|
+
usingKeyboard = value2;
|
|
70
|
+
};
|
|
71
|
+
const autoFocusFirstChild = (open2, insideMenu) => {
|
|
72
|
+
if (open2 && insideMenu) {
|
|
73
|
+
setTimeout(() => focusFirstChild($children), 10);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
$:
|
|
77
|
+
autoFocusFirstChild(open, depth > 0);
|
|
78
|
+
onMount(() => {
|
|
79
|
+
mounted = true;
|
|
80
|
+
keyborg.subscribe(keyborgHandler);
|
|
81
|
+
const menuItemSelf = {
|
|
82
|
+
value,
|
|
83
|
+
open: () => {
|
|
84
|
+
open = true;
|
|
85
|
+
},
|
|
86
|
+
close: () => {
|
|
87
|
+
open = false;
|
|
88
|
+
},
|
|
89
|
+
focus: () => {
|
|
90
|
+
menuItemRef?.focus();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
register?.(menuItemSelf);
|
|
94
|
+
return () => {
|
|
95
|
+
keyborg.unsubscribe(keyborgHandler);
|
|
96
|
+
unregister?.(menuItemSelf);
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
afterUpdate(() => {
|
|
100
|
+
prevOpen = open;
|
|
101
|
+
});
|
|
102
|
+
const onKeyDown = (event) => {
|
|
103
|
+
if (!event.altKey && !event.ctrlKey && !event.shiftKey) {
|
|
104
|
+
switch (event.key) {
|
|
105
|
+
case "ArrowDown":
|
|
106
|
+
if (depth === 0 && hasChildren) {
|
|
107
|
+
open = true;
|
|
108
|
+
setTimeout(() => focusFirstChild($children), 10);
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
return false;
|
|
111
|
+
} else if (depth > 0) {
|
|
112
|
+
focusNext?.(value);
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case "ArrowLeft":
|
|
118
|
+
if (depth < 2) {
|
|
119
|
+
open = false;
|
|
120
|
+
closeMenu?.(true);
|
|
121
|
+
openPreviousMenu?.(rootValue);
|
|
122
|
+
} else {
|
|
123
|
+
closeMenu?.();
|
|
124
|
+
}
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
return false;
|
|
127
|
+
case "ArrowRight":
|
|
128
|
+
if (depth > 0 && hasChildren) {
|
|
129
|
+
open = true;
|
|
130
|
+
setTimeout(focusFirstChild, 10);
|
|
131
|
+
} else {
|
|
132
|
+
open = false;
|
|
133
|
+
closeMenu?.(true);
|
|
134
|
+
openNextMenu?.(rootValue);
|
|
135
|
+
}
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
return false;
|
|
138
|
+
case "ArrowUp":
|
|
139
|
+
if (depth === 0 && hasChildren) {
|
|
140
|
+
open = true;
|
|
141
|
+
setTimeout(() => focusLastChild($children), 10);
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
return false;
|
|
144
|
+
} else if (depth > 0) {
|
|
145
|
+
focusPrevious?.(value);
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
case "Escape":
|
|
150
|
+
open = false;
|
|
151
|
+
closeMenu?.(true);
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const onMouseEnter = (event) => {
|
|
158
|
+
setTimeout(() => {
|
|
159
|
+
menuItemRef?.focus();
|
|
160
|
+
}, 10);
|
|
161
|
+
};
|
|
162
|
+
const onMenuItemClick = (event) => {
|
|
163
|
+
if (!disabled) {
|
|
164
|
+
if (hasChildren) {
|
|
165
|
+
open = !open;
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
event.stopPropagation();
|
|
168
|
+
return false;
|
|
169
|
+
} else {
|
|
170
|
+
raiseSelect(value);
|
|
171
|
+
closeMenu?.(true);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const onClickOutside = (event) => {
|
|
176
|
+
const {
|
|
177
|
+
detail: { mouseEvent }
|
|
178
|
+
} = event;
|
|
179
|
+
let element = mouseEvent.target;
|
|
180
|
+
while (element) {
|
|
181
|
+
if (element.getAttribute("data-root-value") === rootValue) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
element = element.parentElement;
|
|
185
|
+
}
|
|
186
|
+
closeMenu?.(true);
|
|
187
|
+
};
|
|
188
|
+
setContext(menuItemContextKey, {
|
|
189
|
+
rootValue,
|
|
190
|
+
depth: depth + 1,
|
|
191
|
+
register: (menuItem) => {
|
|
192
|
+
children.set([...$children, menuItem]);
|
|
193
|
+
},
|
|
194
|
+
unregister: (menuItem) => {
|
|
195
|
+
children.set($children.filter((x) => x.value !== menuItem.value));
|
|
196
|
+
},
|
|
197
|
+
closeMenu: (recursive) => {
|
|
198
|
+
open = false;
|
|
199
|
+
if (recursive) {
|
|
200
|
+
closeMenu?.(recursive);
|
|
201
|
+
}
|
|
202
|
+
if (!recursive || depth === 0) {
|
|
203
|
+
menuItemRef?.focus();
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
focusPrevious: (currentValue) => focusPreviousChild($children, currentValue),
|
|
207
|
+
focusNext: (currentValue) => focusNextChild($children, currentValue),
|
|
208
|
+
onOpen: raiseOpen,
|
|
209
|
+
onClose: raiseClose,
|
|
210
|
+
onSelect: raiseSelect
|
|
211
|
+
});
|
|
212
|
+
</script>
|
|
213
|
+
|
|
214
|
+
<button
|
|
215
|
+
aria-controls={menuId}
|
|
216
|
+
aria-disabled={disabled}
|
|
217
|
+
aria-expanded={open}
|
|
218
|
+
aria-haspopup={hasChildren}
|
|
219
|
+
aria-owns={menuId}
|
|
220
|
+
bind:this={menuItemRef}
|
|
221
|
+
class="sterling-menu-item"
|
|
222
|
+
class:composed
|
|
223
|
+
class:disabled
|
|
224
|
+
class:using-keyboard={usingKeyboard}
|
|
225
|
+
data-value={value}
|
|
226
|
+
data-root-value={rootValue}
|
|
227
|
+
{role}
|
|
228
|
+
tabindex={0}
|
|
229
|
+
type="button"
|
|
230
|
+
use:clickOutside
|
|
231
|
+
on:blur
|
|
232
|
+
on:click
|
|
233
|
+
on:dblclick
|
|
234
|
+
on:focus
|
|
235
|
+
on:focusin
|
|
236
|
+
on:focusout
|
|
237
|
+
on:keydown
|
|
238
|
+
on:keypress
|
|
239
|
+
on:keyup
|
|
240
|
+
on:mousedown
|
|
241
|
+
on:mouseenter
|
|
242
|
+
on:mouseleave
|
|
243
|
+
on:mousemove
|
|
244
|
+
on:mouseover
|
|
245
|
+
on:mouseout
|
|
246
|
+
on:mouseup
|
|
247
|
+
on:pointercancel
|
|
248
|
+
on:pointerdown
|
|
249
|
+
on:pointerenter
|
|
250
|
+
on:pointerleave
|
|
251
|
+
on:pointermove
|
|
252
|
+
on:pointerover
|
|
253
|
+
on:pointerout
|
|
254
|
+
on:pointerup
|
|
255
|
+
on:wheel
|
|
256
|
+
on:click={onMenuItemClick}
|
|
257
|
+
on:click_outside={onClickOutside}
|
|
258
|
+
on:keydown={onKeyDown}
|
|
259
|
+
on:mouseenter={onMouseEnter}
|
|
260
|
+
{...$$restProps}
|
|
261
|
+
>
|
|
262
|
+
<div class="item" id={displayId}>
|
|
263
|
+
<slot name="item" {checked} {disabled} {hasChildren} {depth} {value} {open} {role} {text}>
|
|
264
|
+
<MenuItemDisplay {checked} hasChildren={depth > 0 && hasChildren} menuItemRole={role}
|
|
265
|
+
>{text}</MenuItemDisplay
|
|
266
|
+
>
|
|
267
|
+
</slot>
|
|
268
|
+
</div>
|
|
269
|
+
{#if menuItemRef && open && $$slots.default}
|
|
270
|
+
<Menu id={menuId} {open} reference={menuItemRef}>
|
|
271
|
+
<slot />
|
|
272
|
+
</Menu>
|
|
273
|
+
{/if}
|
|
274
|
+
</button>
|
|
275
|
+
|
|
276
|
+
<style>
|
|
277
|
+
.sterling-menu-item {
|
|
278
|
+
background-color: transparent;
|
|
279
|
+
border-color: transparent;
|
|
280
|
+
border-radius: var(--stsv-Button__border-radius);
|
|
281
|
+
border-style: none;
|
|
282
|
+
border-width: 0;
|
|
283
|
+
box-sizing: border-box;
|
|
284
|
+
color: var(--stsv-Common__color);
|
|
285
|
+
cursor: pointer;
|
|
286
|
+
font: inherit;
|
|
287
|
+
margin: 0;
|
|
288
|
+
padding: 0;
|
|
289
|
+
position: relative;
|
|
290
|
+
outline: none;
|
|
291
|
+
overflow: hidden;
|
|
292
|
+
text-decoration: none;
|
|
293
|
+
text-overflow: ellipsis;
|
|
294
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
295
|
+
white-space: nowrap;
|
|
296
|
+
user-select: none;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.sterling-menu-item:hover {
|
|
300
|
+
background-color: var(--stsv-Button__background-color--hover);
|
|
301
|
+
color: var(--stsv-Button__color--hover);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.sterling-menu-item:focus {
|
|
305
|
+
outline: none;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.sterling-menu-item.using-keyboard:focus {
|
|
309
|
+
border-color: var(--stsv-Button__border-color--focus);
|
|
310
|
+
outline-color: var(--stsv-Common__outline-color);
|
|
311
|
+
outline-offset: var(--stsv-Common__outline-offset);
|
|
312
|
+
outline-style: var(--stsv-Common__outline-style);
|
|
313
|
+
outline-width: var(--stsv-Common__outline-width);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.sterling-menu-item:focus {
|
|
317
|
+
background-color: var(--stsv-Input__background-color--selected);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.sterling-menu-item.disabled {
|
|
321
|
+
color: var(--stsv-Common__color--disabled);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.sterling-menu-item.composed,
|
|
325
|
+
.sterling-menu-item.composed:focus,
|
|
326
|
+
.sterling-menu-item.composed:hover {
|
|
327
|
+
border-width: 0;
|
|
328
|
+
border-color: transparent;
|
|
329
|
+
outline: none;
|
|
330
|
+
background-color: transparent;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
@media (prefers-reduced-motion) {
|
|
334
|
+
.sterling-menu-item {
|
|
335
|
+
transition: none;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
</style>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
checked?: boolean | undefined;
|
|
6
|
+
composed?: boolean | undefined;
|
|
7
|
+
disabled?: boolean | undefined;
|
|
8
|
+
open?: boolean | undefined;
|
|
9
|
+
value: string;
|
|
10
|
+
role?: "menuitem" | "menuitemcheckbox" | "menuitemradio" | undefined;
|
|
11
|
+
text?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
blur: FocusEvent;
|
|
15
|
+
click: MouseEvent;
|
|
16
|
+
dblclick: MouseEvent;
|
|
17
|
+
focus: FocusEvent;
|
|
18
|
+
focusin: FocusEvent;
|
|
19
|
+
focusout: FocusEvent;
|
|
20
|
+
keydown: KeyboardEvent;
|
|
21
|
+
keypress: KeyboardEvent;
|
|
22
|
+
keyup: KeyboardEvent;
|
|
23
|
+
mousedown: MouseEvent;
|
|
24
|
+
mouseenter: MouseEvent;
|
|
25
|
+
mouseleave: MouseEvent;
|
|
26
|
+
mousemove: MouseEvent;
|
|
27
|
+
mouseover: MouseEvent;
|
|
28
|
+
mouseout: MouseEvent;
|
|
29
|
+
mouseup: MouseEvent;
|
|
30
|
+
pointercancel: PointerEvent;
|
|
31
|
+
pointerdown: PointerEvent;
|
|
32
|
+
pointerenter: PointerEvent;
|
|
33
|
+
pointerleave: PointerEvent;
|
|
34
|
+
pointermove: PointerEvent;
|
|
35
|
+
pointerover: PointerEvent;
|
|
36
|
+
pointerout: PointerEvent;
|
|
37
|
+
pointerup: PointerEvent;
|
|
38
|
+
wheel: WheelEvent;
|
|
39
|
+
} & {
|
|
40
|
+
[evt: string]: CustomEvent<any>;
|
|
41
|
+
};
|
|
42
|
+
slots: {
|
|
43
|
+
item: {
|
|
44
|
+
checked: boolean;
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
hasChildren: boolean;
|
|
47
|
+
depth: number;
|
|
48
|
+
value: string;
|
|
49
|
+
open: boolean;
|
|
50
|
+
role: "menuitem" | "menuitemcheckbox" | "menuitemradio";
|
|
51
|
+
text: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
default: {};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export type MenuItemProps = typeof __propDef.props;
|
|
57
|
+
export type MenuItemEvents = typeof __propDef.events;
|
|
58
|
+
export type MenuItemSlots = typeof __propDef.slots;
|
|
59
|
+
export default class MenuItem extends SvelteComponentTyped<MenuItemProps, MenuItemEvents, MenuItemSlots> {
|
|
60
|
+
}
|
|
61
|
+
export {};
|