@hkdigital/lib-sveltekit 0.1.31 → 0.1.33
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.
@@ -5,7 +5,10 @@
|
|
5
5
|
* a time.
|
6
6
|
*/
|
7
7
|
|
8
|
-
|
8
|
+
import { onMount } from 'svelte';
|
9
|
+
import { findFirst } from '../../util/array/index.js';
|
10
|
+
|
11
|
+
/** @typedef {{text?: string, value?: any, label?: string, props?: Object}} ButtonDef */
|
9
12
|
|
10
13
|
/**
|
11
14
|
* @type {{
|
@@ -13,7 +16,8 @@
|
|
13
16
|
* bg?: string,
|
14
17
|
* classes?: string,
|
15
18
|
* buttons: Array<ButtonDef>,
|
16
|
-
* selected?: (ButtonDef|null)
|
19
|
+
* selected?: (ButtonDef|null),
|
20
|
+
* select?: ( label:string ) => void,
|
17
21
|
* buttonSnippet: import('svelte').Snippet<[{text: string, props: Object}]>,
|
18
22
|
* [attr: string]: any
|
19
23
|
* }}
|
@@ -24,6 +28,7 @@
|
|
24
28
|
classes = '',
|
25
29
|
buttons = [],
|
26
30
|
selected = $bindable(null),
|
31
|
+
select = $bindable(),
|
27
32
|
buttonSnippet,
|
28
33
|
...attrs
|
29
34
|
} = $props();
|
@@ -34,11 +39,25 @@
|
|
34
39
|
* Handle button selection
|
35
40
|
*/
|
36
41
|
function handleSelect(index) {
|
37
|
-
if (!buttons[index].disabled) {
|
42
|
+
if (!buttons[index].props?.disabled) {
|
38
43
|
selectedIndex = index;
|
39
44
|
selected = buttons[selectedIndex] ?? null;
|
40
45
|
}
|
41
46
|
}
|
47
|
+
|
48
|
+
function handleSelectByLabel(label) {
|
49
|
+
for (let j = 0; j < buttons.length; j = j + 1) {
|
50
|
+
if (buttons[j].label === label) {
|
51
|
+
selectedIndex = j;
|
52
|
+
selected = buttons[j] ?? null;
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
onMount(() => {
|
59
|
+
select = handleSelectByLabel;
|
60
|
+
});
|
42
61
|
</script>
|
43
62
|
|
44
63
|
<div
|
@@ -53,8 +72,7 @@
|
|
53
72
|
text: button.text,
|
54
73
|
props: {
|
55
74
|
...(button.props || {}),
|
56
|
-
|
57
|
-
active: index === selectedIndex,
|
75
|
+
selected: index === selectedIndex,
|
58
76
|
onclick: () => handleSelect(index)
|
59
77
|
}
|
60
78
|
})}
|
@@ -5,17 +5,20 @@ declare const ButtonGroup: import("svelte").Component<{
|
|
5
5
|
bg?: string;
|
6
6
|
classes?: string;
|
7
7
|
buttons: Array<{
|
8
|
-
text
|
9
|
-
|
8
|
+
text?: string;
|
9
|
+
value?: any;
|
10
|
+
label?: string;
|
10
11
|
props?: any;
|
11
12
|
}>;
|
12
13
|
selected?: ({
|
13
|
-
text
|
14
|
-
|
14
|
+
text?: string;
|
15
|
+
value?: any;
|
16
|
+
label?: string;
|
15
17
|
props?: any;
|
16
18
|
} | null);
|
19
|
+
select?: (label: string) => void;
|
17
20
|
buttonSnippet: import("svelte").Snippet<[{
|
18
21
|
text: string;
|
19
22
|
props: any;
|
20
23
|
}]>;
|
21
|
-
}, {}, "selected">;
|
24
|
+
}, {}, "select" | "selected">;
|
@@ -29,6 +29,8 @@ export class PresenterState {
|
|
29
29
|
pendingSlideName: string;
|
30
30
|
/** @type {boolean} */
|
31
31
|
configured: boolean;
|
32
|
+
/** @type {Map<Symbol, () => void>} */
|
33
|
+
onUpdateListeners: Map<Symbol, () => void>;
|
32
34
|
/**
|
33
35
|
* Configure the presentation
|
34
36
|
*
|
@@ -81,5 +83,6 @@ export type PresenterRef = {
|
|
81
83
|
* - Get the current slide name
|
82
84
|
*/
|
83
85
|
getCurrentSlideName: () => string;
|
86
|
+
onUpdate: (callback: any) => Function;
|
84
87
|
};
|
85
88
|
import { HkPromise } from '../../classes/promise/index.js';
|
@@ -28,6 +28,7 @@ import { HkPromise } from '../../classes/promise/index.js';
|
|
28
28
|
* @typedef {Object} PresenterRef
|
29
29
|
* @property {(name: string) => void} gotoSlide - Navigate to a slide by name
|
30
30
|
* @property {() => string} getCurrentSlideName - Get the current slide name
|
31
|
+
* @property {(callback)=>Function} onUpdate
|
31
32
|
*/
|
32
33
|
|
33
34
|
const Z_BACK = 0;
|
@@ -94,6 +95,9 @@ export class PresenterState {
|
|
94
95
|
/** @type {boolean} */
|
95
96
|
configured = false;
|
96
97
|
|
98
|
+
/** @type {Map<Symbol, () => void>} */
|
99
|
+
onUpdateListeners = new Map();
|
100
|
+
|
97
101
|
/**
|
98
102
|
* Initialize the presenter state and set up reactivity
|
99
103
|
*/
|
@@ -400,6 +404,14 @@ export class PresenterState {
|
|
400
404
|
}
|
401
405
|
});
|
402
406
|
}
|
407
|
+
|
408
|
+
this.#CallUpdateListeners();
|
409
|
+
}
|
410
|
+
|
411
|
+
#CallUpdateListeners() {
|
412
|
+
for (const fn of this.onUpdateListeners.values()) {
|
413
|
+
fn();
|
414
|
+
}
|
403
415
|
}
|
404
416
|
|
405
417
|
/**
|
@@ -544,7 +556,15 @@ export class PresenterState {
|
|
544
556
|
getPresenterRef() {
|
545
557
|
return {
|
546
558
|
gotoSlide: (name) => this.gotoSlide(name),
|
547
|
-
getCurrentSlideName: () => this.currentSlideName
|
559
|
+
getCurrentSlideName: () => this.currentSlideName,
|
560
|
+
onUpdate: (callback) => {
|
561
|
+
const key = Symbol();
|
562
|
+
this.onUpdateListeners.set(key, callback);
|
563
|
+
|
564
|
+
return () => {
|
565
|
+
this.onUpdateListeners.delete(key);
|
566
|
+
};
|
567
|
+
}
|
548
568
|
};
|
549
569
|
}
|
550
570
|
|