@casinogate/ui 1.10.2 → 1.10.3
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.
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
onChangeDependency,
|
|
44
44
|
clearOnDependencyChange = true,
|
|
45
45
|
|
|
46
|
+
onSelect,
|
|
47
|
+
|
|
46
48
|
...restProps
|
|
47
49
|
}: SelectAsyncProps = $props();
|
|
48
50
|
|
|
@@ -98,6 +100,30 @@
|
|
|
98
100
|
return placeholderProp ?? '';
|
|
99
101
|
});
|
|
100
102
|
|
|
103
|
+
let previousValue: string | string[] = value;
|
|
104
|
+
|
|
105
|
+
watch(
|
|
106
|
+
() => value,
|
|
107
|
+
(newValue) => {
|
|
108
|
+
if (!onSelect) {
|
|
109
|
+
previousValue = newValue;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (typeof newValue === 'string') {
|
|
114
|
+
const item = newValue ? (collection.find(newValue) ?? null) : null;
|
|
115
|
+
onSelect(newValue, item);
|
|
116
|
+
} else if (Array.isArray(newValue)) {
|
|
117
|
+
const prev = Array.isArray(previousValue) ? previousValue : [];
|
|
118
|
+
const added = newValue.find((v) => !prev.includes(v));
|
|
119
|
+
onSelect(newValue, added ? (collection.find(added) ?? null) : null);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
previousValue = newValue;
|
|
123
|
+
},
|
|
124
|
+
{ lazy: true }
|
|
125
|
+
);
|
|
126
|
+
|
|
101
127
|
const fetchData = async (page: number, append = false) => {
|
|
102
128
|
if (isLoading) return;
|
|
103
129
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
+
import type { SelectCollectionOptions, SelectItem, SelectProps } from './types.js';
|
|
3
|
+
|
|
2
4
|
export function createSelectCollection(options: SelectCollectionOptions): ListCollection<SelectItem> {
|
|
3
5
|
const { items, groups = [], groupSort } = options;
|
|
4
6
|
|
|
@@ -26,11 +28,10 @@
|
|
|
26
28
|
</script>
|
|
27
29
|
|
|
28
30
|
<script lang="ts">
|
|
29
|
-
import type { SelectCollectionOptions, SelectItem, SelectProps } from './types.js';
|
|
30
|
-
|
|
31
31
|
import { Icon } from '../icons/index.js';
|
|
32
32
|
import { createListCollection, type ListCollection } from '../../internal/index.js';
|
|
33
33
|
import { cn } from '../../internal/utils/common.js';
|
|
34
|
+
import { watch } from 'runed';
|
|
34
35
|
import { cubicInOut } from 'svelte/easing';
|
|
35
36
|
import { fly } from 'svelte/transition';
|
|
36
37
|
import Content from './components/select.content.svelte';
|
|
@@ -62,6 +63,8 @@
|
|
|
62
63
|
|
|
63
64
|
disabledPortal = false,
|
|
64
65
|
|
|
66
|
+
onSelect,
|
|
67
|
+
|
|
65
68
|
...restProps
|
|
66
69
|
}: SelectProps = $props();
|
|
67
70
|
|
|
@@ -88,6 +91,37 @@
|
|
|
88
91
|
|
|
89
92
|
return placeholderProp ?? '';
|
|
90
93
|
});
|
|
94
|
+
|
|
95
|
+
let previousValue: string | string[] = value;
|
|
96
|
+
|
|
97
|
+
watch(
|
|
98
|
+
() => value,
|
|
99
|
+
(newValue) => {
|
|
100
|
+
if (!onSelect) {
|
|
101
|
+
previousValue = newValue;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log('newValue', newValue);
|
|
106
|
+
|
|
107
|
+
if (typeof newValue === 'string') {
|
|
108
|
+
const item = newValue ? (collection.find(newValue) ?? null) : null;
|
|
109
|
+
|
|
110
|
+
onSelect(newValue, item);
|
|
111
|
+
} else if (Array.isArray(newValue)) {
|
|
112
|
+
const prev = Array.isArray(previousValue) ? previousValue : [];
|
|
113
|
+
|
|
114
|
+
const added = newValue.find((v) => !prev.includes(v));
|
|
115
|
+
|
|
116
|
+
const option = added ? (collection.find(added) ?? null) : null;
|
|
117
|
+
|
|
118
|
+
onSelect(newValue, option);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
previousValue = newValue;
|
|
122
|
+
},
|
|
123
|
+
{ lazy: true }
|
|
124
|
+
);
|
|
91
125
|
</script>
|
|
92
126
|
|
|
93
127
|
{#snippet defaultItemRenderer(item: SelectItem)}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare function createSelectCollection(options: SelectCollectionOptions): ListCollection<SelectItem>;
|
|
2
1
|
import type { SelectCollectionOptions, SelectItem, SelectProps } from './types.js';
|
|
2
|
+
export declare function createSelectCollection(options: SelectCollectionOptions): ListCollection<SelectItem>;
|
|
3
3
|
import { type ListCollection } from '../../internal/index.js';
|
|
4
4
|
declare const Select: import("svelte").Component<SelectProps, {}, "value" | "open" | "contentRef">;
|
|
5
5
|
type Select = ReturnType<typeof Select>;
|
|
@@ -83,6 +83,8 @@ export type SelectProps = SelectRootProps & {
|
|
|
83
83
|
contentRef?: HTMLDivElement | null;
|
|
84
84
|
contentClass?: string;
|
|
85
85
|
disabledPortal?: boolean;
|
|
86
|
+
/** Callback when selection changes. Provides value(s) and the item that was just selected, or null on deselect. */
|
|
87
|
+
onSelect?: (value: string | string[], item: SelectItem | null) => void;
|
|
86
88
|
};
|
|
87
89
|
export type SelectAsyncCallbackParams = {
|
|
88
90
|
page: number;
|