lithesome 0.3.2 → 0.4.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/dist/components/Accordion/Accordion.svelte +3 -3
- package/dist/components/Accordion/Accordion.svelte.d.ts +2 -9
- package/dist/components/Accordion/context.svelte.d.ts +10 -9
- package/dist/components/Accordion/context.svelte.js +30 -39
- package/dist/components/Combobox/Combobox.svelte +3 -3
- package/dist/components/Combobox/Combobox.svelte.d.ts +2 -25
- package/dist/components/Combobox/ComboboxDropdown.svelte +9 -3
- package/dist/components/Combobox/ComboboxInput.svelte +7 -7
- package/dist/components/Combobox/ComboboxOption.svelte +2 -2
- package/dist/components/Combobox/context.svelte.d.ts +21 -24
- package/dist/components/Combobox/context.svelte.js +90 -127
- package/dist/components/Menu/Menu.svelte +2 -2
- package/dist/components/Menu/Menu.svelte.d.ts +2 -18
- package/dist/components/Menu/MenuDropdown.svelte +3 -3
- package/dist/components/Menu/MenuItem.svelte +1 -1
- package/dist/components/Menu/MenuTrigger.svelte +5 -5
- package/dist/components/Menu/context.svelte.d.ts +15 -16
- package/dist/components/Menu/context.svelte.js +41 -64
- package/dist/components/Modal/Modal.svelte +7 -9
- package/dist/components/Modal/Modal.svelte.d.ts +2 -5
- package/dist/components/Modal/context.svelte.d.ts +8 -7
- package/dist/components/Modal/context.svelte.js +12 -16
- package/dist/components/Pin/Pin.svelte +4 -4
- package/dist/components/Pin/Pin.svelte.d.ts +2 -14
- package/dist/components/Pin/PinValue.svelte +1 -1
- package/dist/components/Pin/context.svelte.d.ts +18 -18
- package/dist/components/Pin/context.svelte.js +27 -49
- package/dist/components/Popover/Popover.svelte +17 -16
- package/dist/components/Popover/Popover.svelte.d.ts +2 -11
- package/dist/components/Popover/PopoverContent.svelte +27 -17
- package/dist/components/Popover/PopoverTrigger.svelte +12 -12
- package/dist/components/Popover/context.svelte.d.ts +10 -11
- package/dist/components/Popover/context.svelte.js +18 -36
- package/dist/components/RadioGroup/RadioGroup.svelte +3 -3
- package/dist/components/RadioGroup/RadioGroup.svelte.d.ts +20 -0
- package/dist/components/RadioGroup/RadioGroupItem.svelte +9 -9
- package/dist/components/RadioGroup/context.svelte.d.ts +12 -9
- package/dist/components/RadioGroup/context.svelte.js +25 -28
- package/dist/components/Select/Select.svelte +13 -5
- package/dist/components/Select/Select.svelte.d.ts +2 -23
- package/dist/components/Select/SelectDropdown.svelte +3 -3
- package/dist/components/Select/SelectOption.svelte +8 -8
- package/dist/components/Select/SelectTrigger.svelte +6 -6
- package/dist/components/Select/context.svelte.d.ts +19 -21
- package/dist/components/Select/context.svelte.js +84 -113
- package/dist/components/Tabs/Tabs.svelte +13 -5
- package/dist/components/Tabs/Tabs.svelte.d.ts +2 -10
- package/dist/components/Tabs/context.svelte.d.ts +11 -11
- package/dist/components/Tabs/context.svelte.js +24 -35
- package/dist/components/Tags/context.svelte.d.ts +15 -0
- package/dist/components/Tags/context.svelte.js +15 -0
- package/dist/internal/helpers/context.svelte.d.ts +7 -0
- package/dist/internal/helpers/context.svelte.js +23 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script context="module">import { getContext } from "svelte";
|
|
2
|
-
import {
|
|
2
|
+
import { AccordionContext } from "./context.svelte.js";
|
|
3
3
|
const contextName = "accordion-context";
|
|
4
4
|
export const context = () => getContext(contextName);
|
|
5
5
|
</script>
|
|
@@ -7,11 +7,11 @@ export const context = () => getContext(contextName);
|
|
|
7
7
|
<script>import { useActions, classProp } from "../../internal/index.js";
|
|
8
8
|
import { setContext } from "svelte";
|
|
9
9
|
let { children, use = [], class: klass, self = $bindable(), single = $bindable(false), ...props } = $props();
|
|
10
|
-
const ctx =
|
|
10
|
+
const ctx = new AccordionContext({ single });
|
|
11
11
|
const active = $derived(ctx.activeItems.length > 0);
|
|
12
12
|
setContext(contextName, ctx);
|
|
13
13
|
$effect(() => {
|
|
14
|
-
ctx.
|
|
14
|
+
ctx.single = single;
|
|
15
15
|
});
|
|
16
16
|
</script>
|
|
17
17
|
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
toggle(itemId: string): void;
|
|
5
|
-
register(item: import("./context.svelte.js").Item): void;
|
|
6
|
-
setDisabled(id: string, val: boolean): void;
|
|
7
|
-
setSingle(val: boolean): void;
|
|
8
|
-
readonly items: import("./context.svelte.js").Item[];
|
|
9
|
-
readonly activeItems: string[];
|
|
10
|
-
};
|
|
2
|
+
import { AccordionContext } from './context.svelte.js';
|
|
3
|
+
export declare const context: () => AccordionContext;
|
|
11
4
|
import { type BaseProps } from '../../internal/index.js';
|
|
12
5
|
declare const __propDef: {
|
|
13
6
|
props: BaseProps<HTMLDivElement, {
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { Context } from '../../internal/index.js';
|
|
1
2
|
export interface Item {
|
|
2
3
|
id: string;
|
|
3
4
|
disabled: boolean;
|
|
4
5
|
}
|
|
5
|
-
interface
|
|
6
|
-
single
|
|
6
|
+
interface Init {
|
|
7
|
+
single: boolean;
|
|
7
8
|
}
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
export declare class AccordionContext extends Context {
|
|
10
|
+
items: Item[];
|
|
11
|
+
activeItems: string[];
|
|
12
|
+
single: boolean;
|
|
13
|
+
constructor(init: Init);
|
|
11
14
|
register(item: Item): void;
|
|
15
|
+
toggle(itemId: string): void;
|
|
12
16
|
setDisabled(id: string, val: boolean): void;
|
|
13
|
-
|
|
14
|
-
readonly items: Item[];
|
|
15
|
-
readonly activeItems: string[];
|
|
16
|
-
};
|
|
17
|
+
}
|
|
17
18
|
export {};
|
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
else
|
|
20
|
-
activeItems = [...activeItems, itemId];
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
register(item) {
|
|
24
|
-
items = [...items, item];
|
|
25
|
-
},
|
|
26
|
-
setDisabled(id, val) {
|
|
27
|
-
const index = items.findIndex((el) => el.id === id);
|
|
28
|
-
items[index].disabled = val;
|
|
29
|
-
},
|
|
30
|
-
setSingle(val) {
|
|
31
|
-
single = val;
|
|
32
|
-
},
|
|
33
|
-
get items() {
|
|
34
|
-
return items;
|
|
35
|
-
},
|
|
36
|
-
get activeItems() {
|
|
37
|
-
return activeItems;
|
|
1
|
+
import { Context } from '../../internal/index.js';
|
|
2
|
+
export class AccordionContext extends Context {
|
|
3
|
+
items = $state([]);
|
|
4
|
+
activeItems = $state([]);
|
|
5
|
+
single = $state(false);
|
|
6
|
+
constructor(init) {
|
|
7
|
+
super('accordion');
|
|
8
|
+
this.single = init.single;
|
|
9
|
+
}
|
|
10
|
+
register(item) {
|
|
11
|
+
this.items.push(item);
|
|
12
|
+
}
|
|
13
|
+
toggle(itemId) {
|
|
14
|
+
if (this.single) {
|
|
15
|
+
if (this.activeItems[0] === itemId)
|
|
16
|
+
this.activeItems = [];
|
|
17
|
+
else
|
|
18
|
+
this.activeItems[0] = itemId;
|
|
38
19
|
}
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
else {
|
|
21
|
+
if (this.activeItems.includes(itemId))
|
|
22
|
+
this.activeItems = this.activeItems.filter((el) => el !== itemId);
|
|
23
|
+
else
|
|
24
|
+
this.activeItems.push(itemId);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
setDisabled(id, val) {
|
|
28
|
+
const i = this.items.findIndex((el) => el.id === id);
|
|
29
|
+
this.items[i].disabled = val;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script context="module">import { getContext, onMount, tick } from "svelte";
|
|
2
|
-
import {
|
|
2
|
+
import { ComboboxContext } from "./context.svelte.js";
|
|
3
3
|
const contextName = "combobox-context";
|
|
4
4
|
export const context = () => getContext(contextName);
|
|
5
5
|
</script>
|
|
@@ -18,7 +18,7 @@ let {
|
|
|
18
18
|
...props
|
|
19
19
|
} = $props();
|
|
20
20
|
const multiple = Array.isArray(value);
|
|
21
|
-
const ctx =
|
|
21
|
+
const ctx = new ComboboxContext(
|
|
22
22
|
{ multiple },
|
|
23
23
|
{
|
|
24
24
|
onChange({ newValue, newTouched, newLabel }) {
|
|
@@ -40,7 +40,7 @@ onMount(async () => {
|
|
|
40
40
|
await tick();
|
|
41
41
|
ctx.setInitialSelected(value);
|
|
42
42
|
ctx.close();
|
|
43
|
-
ctx.
|
|
43
|
+
ctx.mounted = true;
|
|
44
44
|
});
|
|
45
45
|
</script>
|
|
46
46
|
|
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
open(): void;
|
|
5
|
-
close(): void;
|
|
6
|
-
toggle(): void;
|
|
7
|
-
queryElements(): void;
|
|
8
|
-
navigateOptions(action: import("../../internal/index.js").CalcIndexAction): void;
|
|
9
|
-
setHoveredOption(optionId?: string | undefined): void;
|
|
10
|
-
setSelectedOptions(): void;
|
|
11
|
-
setInitialSelected(value: unknown): Promise<void>;
|
|
12
|
-
setTrigger(node: HTMLInputElement): void;
|
|
13
|
-
setDropdown(node: HTMLElement): void;
|
|
14
|
-
setMounted(value: boolean): void;
|
|
15
|
-
setTouched(value: boolean): void;
|
|
16
|
-
readonly visible: boolean;
|
|
17
|
-
readonly hoveredIndex: number;
|
|
18
|
-
readonly options: HTMLElement[];
|
|
19
|
-
readonly touched: HTMLElement[];
|
|
20
|
-
readonly dropdown: HTMLElement | null;
|
|
21
|
-
readonly mounted: boolean;
|
|
22
|
-
readonly selectedOptions: HTMLElement[];
|
|
23
|
-
readonly hoveredOption: HTMLElement;
|
|
24
|
-
readonly trigger: HTMLInputElement | null;
|
|
25
|
-
multiple: boolean | undefined;
|
|
26
|
-
};
|
|
2
|
+
import { ComboboxContext } from './context.svelte.js';
|
|
3
|
+
export declare const context: () => ComboboxContext<any>;
|
|
27
4
|
import { type BaseProps } from '../../internal/index.js';
|
|
28
5
|
declare class __sveltets_Render<ValueType> {
|
|
29
6
|
props(): BaseProps<HTMLDivElement, {
|
|
@@ -38,7 +38,7 @@ onMount(() => {
|
|
|
38
38
|
});
|
|
39
39
|
$effect(() => {
|
|
40
40
|
if (ctx.visible && self)
|
|
41
|
-
ctx.
|
|
41
|
+
ctx.dropdown = self;
|
|
42
42
|
});
|
|
43
43
|
$effect(() => {
|
|
44
44
|
if (ctx.visible && ctx.trigger && ctx.dropdown) {
|
|
@@ -58,7 +58,10 @@ $effect(() => {
|
|
|
58
58
|
{#if ctx.visible}
|
|
59
59
|
<div
|
|
60
60
|
bind:this={self}
|
|
61
|
-
use:clickOutside={{
|
|
61
|
+
use:clickOutside={{
|
|
62
|
+
exclude: [ctx.trigger],
|
|
63
|
+
callback: () => ctx.close()
|
|
64
|
+
}}
|
|
62
65
|
use:portal={portalTarget}
|
|
63
66
|
use:useActions={use}
|
|
64
67
|
in:_transition.in.fn={_transition.in.params}
|
|
@@ -72,7 +75,10 @@ $effect(() => {
|
|
|
72
75
|
{:else if ctx.visible}
|
|
73
76
|
<div
|
|
74
77
|
bind:this={self}
|
|
75
|
-
use:clickOutside={{
|
|
78
|
+
use:clickOutside={{
|
|
79
|
+
exclude: [ctx.trigger],
|
|
80
|
+
callback: () => ctx.close()
|
|
81
|
+
}}
|
|
76
82
|
use:portal={portalTarget}
|
|
77
83
|
use:useActions={use}
|
|
78
84
|
{...attrs}
|
|
@@ -21,7 +21,7 @@ const ctx = context();
|
|
|
21
21
|
onMount(() => {
|
|
22
22
|
if (!ctx || !self)
|
|
23
23
|
return;
|
|
24
|
-
ctx.
|
|
24
|
+
ctx.trigger = self;
|
|
25
25
|
});
|
|
26
26
|
const handleClick = (e) => {
|
|
27
27
|
onClick?.(e);
|
|
@@ -35,7 +35,7 @@ const handleKeydown = (e) => {
|
|
|
35
35
|
return;
|
|
36
36
|
const { key } = e;
|
|
37
37
|
if (!PREVENT_KEYS.includes(key)) {
|
|
38
|
-
ctx.
|
|
38
|
+
ctx.touched = true;
|
|
39
39
|
if (!ctx.visible)
|
|
40
40
|
ctx.open();
|
|
41
41
|
}
|
|
@@ -45,19 +45,19 @@ const handleKeydown = (e) => {
|
|
|
45
45
|
ctx.open();
|
|
46
46
|
}
|
|
47
47
|
if (key === KEYS.home)
|
|
48
|
-
ctx.
|
|
48
|
+
ctx.navigate("first");
|
|
49
49
|
if (key === KEYS.end)
|
|
50
|
-
ctx.
|
|
50
|
+
ctx.navigate("last");
|
|
51
51
|
if (key === KEYS.arrowUp)
|
|
52
|
-
ctx.
|
|
52
|
+
ctx.navigate("prev");
|
|
53
53
|
if (key === KEYS.arrowDown)
|
|
54
|
-
ctx.
|
|
54
|
+
ctx.navigate("next");
|
|
55
55
|
if (key === KEYS.escape)
|
|
56
56
|
ctx.close();
|
|
57
57
|
if (key === KEYS.enter) {
|
|
58
58
|
e.preventDefault();
|
|
59
59
|
if (ctx.hoveredOption && ctx.visible) {
|
|
60
|
-
|
|
60
|
+
ctx.hoveredOption.click();
|
|
61
61
|
if (!ctx.multiple)
|
|
62
62
|
ctx.close();
|
|
63
63
|
} else {
|
|
@@ -28,7 +28,7 @@ const label = $derived(labelProp || isBrowser && self ? self?.textContent?.trim(
|
|
|
28
28
|
const handleClick = (e) => {
|
|
29
29
|
onClick?.(e);
|
|
30
30
|
if (!disabled) {
|
|
31
|
-
ctx.
|
|
31
|
+
ctx.setSelected();
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
const handleFocus = (e) => {
|
|
@@ -37,7 +37,7 @@ const handleFocus = (e) => {
|
|
|
37
37
|
const handleMouseover = (e) => {
|
|
38
38
|
onMouseenter?.(e);
|
|
39
39
|
if (!disabled)
|
|
40
|
-
ctx.
|
|
40
|
+
ctx.setHovered(uid());
|
|
41
41
|
};
|
|
42
42
|
onMount(() => {
|
|
43
43
|
ctx.queryElements();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { type CalcIndexAction, type JsonValue } from '../../internal/index.js';
|
|
1
|
+
import { Context, type CalcIndexAction, type JsonValue } from '../../internal/index.js';
|
|
2
2
|
export interface Option {
|
|
3
3
|
value: JsonValue;
|
|
4
4
|
label: string;
|
|
5
5
|
id: string;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
}
|
|
8
|
-
interface
|
|
9
|
-
multiple
|
|
8
|
+
interface Init {
|
|
9
|
+
multiple: boolean;
|
|
10
10
|
}
|
|
11
11
|
interface Hooks<ValueType> {
|
|
12
12
|
onChange?: (values: {
|
|
@@ -15,29 +15,26 @@ interface Hooks<ValueType> {
|
|
|
15
15
|
newLabel?: string;
|
|
16
16
|
}) => void;
|
|
17
17
|
}
|
|
18
|
-
export declare
|
|
19
|
-
|
|
18
|
+
export declare class ComboboxContext<ValueType = any> extends Context<Hooks<ValueType>> {
|
|
19
|
+
#private;
|
|
20
|
+
visible: boolean;
|
|
21
|
+
hoveredIndex: number;
|
|
22
|
+
options: HTMLElement[];
|
|
23
|
+
trigger: HTMLInputElement | null;
|
|
24
|
+
dropdown: HTMLElement | null;
|
|
25
|
+
selectedOptions: HTMLElement[];
|
|
26
|
+
mounted: boolean;
|
|
27
|
+
touched: boolean;
|
|
28
|
+
multiple: boolean;
|
|
29
|
+
hoveredOption: HTMLElement | undefined;
|
|
30
|
+
constructor(init: Init, hooks: Hooks<ValueType>);
|
|
20
31
|
open(): void;
|
|
21
32
|
close(): void;
|
|
22
33
|
toggle(): void;
|
|
23
34
|
queryElements(): void;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
setInitialSelected(value: ValueType):
|
|
28
|
-
|
|
29
|
-
setDropdown(node: HTMLElement): void;
|
|
30
|
-
setMounted(value: boolean): void;
|
|
31
|
-
setTouched(value: boolean): void;
|
|
32
|
-
readonly visible: boolean;
|
|
33
|
-
readonly hoveredIndex: number;
|
|
34
|
-
readonly options: HTMLElement[];
|
|
35
|
-
readonly touched: HTMLElement[];
|
|
36
|
-
readonly dropdown: HTMLElement | null;
|
|
37
|
-
readonly mounted: boolean;
|
|
38
|
-
readonly selectedOptions: HTMLElement[];
|
|
39
|
-
readonly hoveredOption: HTMLElement;
|
|
40
|
-
readonly trigger: HTMLInputElement | null;
|
|
41
|
-
multiple: boolean | undefined;
|
|
42
|
-
};
|
|
35
|
+
navigate(action: CalcIndexAction): void;
|
|
36
|
+
setHovered(optionId?: string): void;
|
|
37
|
+
setSelected(): void;
|
|
38
|
+
setInitialSelected(value: ValueType): void;
|
|
39
|
+
}
|
|
43
40
|
export {};
|
|
@@ -1,134 +1,97 @@
|
|
|
1
|
-
import { calculateIndex, disableScroll, removeDisabledElements,
|
|
1
|
+
import { calculateIndex, disableScroll, removeDisabledElements, Context, effects } from '../../internal/index.js';
|
|
2
2
|
import { tick } from 'svelte';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
export class ComboboxContext extends Context {
|
|
4
|
+
visible = $state(true);
|
|
5
|
+
hoveredIndex = $state(-1);
|
|
6
|
+
options = $state([]);
|
|
7
|
+
trigger = $state(null);
|
|
8
|
+
dropdown = $state(null);
|
|
9
|
+
selectedOptions = $state([]);
|
|
10
|
+
mounted = $state(false);
|
|
11
|
+
touched = $state(false);
|
|
12
|
+
multiple = $state(false);
|
|
13
|
+
hoveredOption = $derived(this.options[this.hoveredIndex]);
|
|
14
|
+
constructor(init, hooks) {
|
|
15
|
+
super('combobox', hooks);
|
|
16
|
+
this.multiple = init.multiple;
|
|
17
|
+
}
|
|
18
|
+
open() {
|
|
19
|
+
this.visible = true;
|
|
20
|
+
}
|
|
21
|
+
close() {
|
|
22
|
+
this.visible = false;
|
|
23
|
+
}
|
|
24
|
+
toggle() {
|
|
25
|
+
this.visible = !this.visible;
|
|
26
|
+
}
|
|
27
|
+
queryElements() {
|
|
28
|
+
const elements = removeDisabledElements(`#${this.uid('dropdown')} [data-comboboxoption]`);
|
|
29
|
+
if (!elements)
|
|
30
|
+
return;
|
|
31
|
+
this.options = elements;
|
|
32
|
+
}
|
|
33
|
+
navigate(action) {
|
|
34
|
+
this.hoveredIndex = calculateIndex(action, this.options, this.hoveredIndex);
|
|
35
|
+
if (this.hoveredOption)
|
|
36
|
+
this.hoveredOption.scrollIntoView({ block: 'nearest' });
|
|
37
|
+
}
|
|
38
|
+
setHovered(optionId) {
|
|
39
|
+
if (!optionId)
|
|
40
|
+
return;
|
|
41
|
+
this.hoveredIndex = this.options.findIndex((el) => el.id === optionId);
|
|
42
|
+
}
|
|
43
|
+
setSelected() {
|
|
44
|
+
if (!this.hoveredOption)
|
|
45
|
+
return;
|
|
46
|
+
if (this.multiple) {
|
|
47
|
+
if (this.selectedOptions.find((el) => el.dataset.value === this.hoveredOption?.dataset.value)) {
|
|
48
|
+
this.selectedOptions = this.selectedOptions.filter((el) => el.dataset.value !== this.hoveredOption?.dataset.value);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.selectedOptions.push(this.hoveredOption);
|
|
52
|
+
}
|
|
27
53
|
}
|
|
28
54
|
else {
|
|
29
|
-
|
|
30
|
-
touched = false;
|
|
55
|
+
this.selectedOptions[0] = this.hoveredOption;
|
|
31
56
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
options
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return;
|
|
62
|
-
hoveredIndex = options.findIndex((el) => el.id === optionId);
|
|
63
|
-
},
|
|
64
|
-
setSelectedOptions() {
|
|
65
|
-
if (!hoveredOption)
|
|
66
|
-
return;
|
|
67
|
-
if (multiple) {
|
|
68
|
-
if (selectedOptions.find((el) => el.dataset.value === hoveredOption.dataset.value)) {
|
|
69
|
-
selectedOptions = selectedOptions.filter((el) => el.dataset.value !== hoveredOption.dataset.value);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
selectedOptions = [...selectedOptions, hoveredOption];
|
|
73
|
-
}
|
|
57
|
+
if (!this.multiple)
|
|
58
|
+
this.visible = false;
|
|
59
|
+
const value = this.multiple
|
|
60
|
+
? this.selectedOptions.map((el) => el.dataset.value)
|
|
61
|
+
: this.selectedOptions[0].dataset.value;
|
|
62
|
+
const label = this.multiple ? '' : this.selectedOptions[0].dataset.label || '';
|
|
63
|
+
this.hooks?.onChange?.({ newValue: value, newLabel: label });
|
|
64
|
+
}
|
|
65
|
+
setInitialSelected(value) {
|
|
66
|
+
this.selectedOptions = this.options.filter((el) => {
|
|
67
|
+
if (!Array.isArray(value) && el.dataset.value === value)
|
|
68
|
+
return el;
|
|
69
|
+
else if (Array.isArray(value) && value.includes(el.dataset.value))
|
|
70
|
+
return el;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
#effects = effects(() => {
|
|
74
|
+
$effect(() => {
|
|
75
|
+
disableScroll(this.visible && !document.body.style.overflow);
|
|
76
|
+
});
|
|
77
|
+
$effect(() => {
|
|
78
|
+
if (!this.visible || !this.options || this.hoveredIndex > this.options.length - 1)
|
|
79
|
+
this.hoveredIndex = -1;
|
|
80
|
+
});
|
|
81
|
+
$effect(() => {
|
|
82
|
+
if (this.visible) {
|
|
83
|
+
tick().then(() => {
|
|
84
|
+
this.hoveredIndex = this.options.findIndex((option) => option.ariaSelected === 'true');
|
|
85
|
+
});
|
|
74
86
|
}
|
|
75
87
|
else {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (!multiple) {
|
|
79
|
-
visible = false;
|
|
88
|
+
this.options = [];
|
|
89
|
+
this.touched = false;
|
|
80
90
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return el;
|
|
89
|
-
else if (Array.isArray(value) && value.includes(el.dataset.value))
|
|
90
|
-
return el;
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
setTrigger(node) {
|
|
94
|
-
trigger = node;
|
|
95
|
-
},
|
|
96
|
-
setDropdown(node) {
|
|
97
|
-
dropdown = node;
|
|
98
|
-
},
|
|
99
|
-
setMounted(value) {
|
|
100
|
-
mounted = value;
|
|
101
|
-
},
|
|
102
|
-
setTouched(value) {
|
|
103
|
-
touched = value;
|
|
104
|
-
},
|
|
105
|
-
get visible() {
|
|
106
|
-
return visible;
|
|
107
|
-
},
|
|
108
|
-
get hoveredIndex() {
|
|
109
|
-
return hoveredIndex;
|
|
110
|
-
},
|
|
111
|
-
get options() {
|
|
112
|
-
return options;
|
|
113
|
-
},
|
|
114
|
-
get touched() {
|
|
115
|
-
return options;
|
|
116
|
-
},
|
|
117
|
-
get dropdown() {
|
|
118
|
-
return dropdown;
|
|
119
|
-
},
|
|
120
|
-
get mounted() {
|
|
121
|
-
return mounted;
|
|
122
|
-
},
|
|
123
|
-
get selectedOptions() {
|
|
124
|
-
return selectedOptions;
|
|
125
|
-
},
|
|
126
|
-
get hoveredOption() {
|
|
127
|
-
return hoveredOption;
|
|
128
|
-
},
|
|
129
|
-
get trigger() {
|
|
130
|
-
return trigger;
|
|
131
|
-
},
|
|
132
|
-
multiple
|
|
133
|
-
};
|
|
134
|
-
};
|
|
91
|
+
});
|
|
92
|
+
$effect(() => {
|
|
93
|
+
if (this.visible)
|
|
94
|
+
this.hooks?.onChange?.({ newTouched: this.touched });
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script context="module">import { getContext } from "svelte";
|
|
2
|
-
import {
|
|
2
|
+
import { MenuContext } from "./context.svelte.js";
|
|
3
3
|
const contextName = "menu-context";
|
|
4
4
|
export const context = () => getContext(contextName);
|
|
5
5
|
</script>
|
|
@@ -7,7 +7,7 @@ export const context = () => getContext(contextName);
|
|
|
7
7
|
<script>import { useActions, classProp } from "../../internal/index.js";
|
|
8
8
|
import { setContext } from "svelte";
|
|
9
9
|
let { children, use = [], class: klass, self = $bindable(), ...props } = $props();
|
|
10
|
-
const ctx =
|
|
10
|
+
const ctx = new MenuContext();
|
|
11
11
|
setContext(contextName, ctx);
|
|
12
12
|
</script>
|
|
13
13
|
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
open(): void;
|
|
5
|
-
close(): void;
|
|
6
|
-
toggle(): void;
|
|
7
|
-
navigateItems(action: import("../../internal/index.js").CalcIndexAction): void;
|
|
8
|
-
register(item: string): void;
|
|
9
|
-
unregister(item: string): void;
|
|
10
|
-
setHoveredItem(itemId: string): void;
|
|
11
|
-
setTrigger(node: HTMLElement): void;
|
|
12
|
-
setDropdown(node: HTMLElement): void;
|
|
13
|
-
readonly visible: boolean;
|
|
14
|
-
readonly hoveredIndex: number;
|
|
15
|
-
readonly trigger: HTMLElement | null;
|
|
16
|
-
readonly dropdown: HTMLElement | null;
|
|
17
|
-
readonly items: string[];
|
|
18
|
-
readonly hoveredItem: string;
|
|
19
|
-
};
|
|
2
|
+
import { MenuContext } from './context.svelte.js';
|
|
3
|
+
export declare const context: () => MenuContext;
|
|
20
4
|
import { type BaseProps } from '../../internal/index.js';
|
|
21
5
|
declare const __propDef: {
|
|
22
6
|
props: BaseProps<HTMLDivElement, {
|
|
@@ -37,7 +37,7 @@ onMount(async () => {
|
|
|
37
37
|
});
|
|
38
38
|
$effect(() => {
|
|
39
39
|
if (ctx.visible && self)
|
|
40
|
-
ctx.
|
|
40
|
+
ctx.dropdown = self;
|
|
41
41
|
});
|
|
42
42
|
$effect(() => {
|
|
43
43
|
if (ctx.visible && ctx.trigger && ctx.dropdown) {
|
|
@@ -57,7 +57,7 @@ $effect(() => {
|
|
|
57
57
|
{#if ctx.visible}
|
|
58
58
|
<div
|
|
59
59
|
bind:this={self}
|
|
60
|
-
use:clickOutside={{ exclude: [ctx.trigger], callback: ctx.close }}
|
|
60
|
+
use:clickOutside={{ exclude: [ctx.trigger], callback: () => ctx.close() }}
|
|
61
61
|
use:portal={portalTarget}
|
|
62
62
|
use:useActions={use}
|
|
63
63
|
in:_transition.in.fn={_transition.in.params}
|
|
@@ -71,7 +71,7 @@ $effect(() => {
|
|
|
71
71
|
{:else if ctx.visible}
|
|
72
72
|
<div
|
|
73
73
|
bind:this={self}
|
|
74
|
-
use:clickOutside={{ exclude: [ctx.trigger], callback: ctx.close }}
|
|
74
|
+
use:clickOutside={{ exclude: [ctx.trigger], callback: () => ctx.close() }}
|
|
75
75
|
use:portal={portalTarget}
|
|
76
76
|
use:useActions={use}
|
|
77
77
|
{...attrs}
|