sheer-ui 0.4.0 → 0.4.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.
- package/package.json +1 -1
- package/src/lib/components/accordion/components/accordion-item.svelte +3 -3
- package/src/lib/components/accordion/components/accordion.svelte +29 -13
- package/src/lib/components/accordion/types.ts +3 -3
- package/src/lib/components/avatar/avatar.svelte.ts +34 -37
- package/src/lib/components/avatar/components/avatar-fallback.svelte +9 -6
- package/src/lib/components/avatar/components/avatar-image.svelte +18 -9
- package/src/lib/components/avatar/components/avatar.svelte +20 -16
- package/src/lib/components/checkbox/checkbox.svelte.ts +45 -55
- package/src/lib/components/checkbox/components/checkbox-group-label.svelte +9 -6
- package/src/lib/components/checkbox/components/checkbox-group.svelte +25 -14
- package/src/lib/components/checkbox/components/checkbox.svelte +39 -21
- package/src/lib/components/combobox/components/combobox.svelte +2 -2
- package/src/lib/components/combobox/select/components/select.svelte +2 -2
- package/src/lib/components/context-menu/components/context-menu-trigger.svelte +1 -1
- package/src/lib/components/date-field/date-field.svelte.ts +2 -3
- package/src/lib/components/dialog/components/dialog-close.svelte +13 -8
- package/src/lib/components/dialog/components/dialog-content-headless.svelte +14 -11
- package/src/lib/components/dialog/components/dialog-description.svelte +9 -6
- package/src/lib/components/dialog/components/dialog-overlay.svelte +10 -7
- package/src/lib/components/dialog/components/dialog-title.svelte +12 -7
- package/src/lib/components/dialog/components/dialog-trigger.svelte +12 -7
- package/src/lib/components/dialog/components/dialog.svelte +10 -4
- package/src/lib/components/dialog/components/modal-surface.svelte +11 -8
- package/src/lib/components/dialog/dialog.svelte.ts +73 -61
- package/src/lib/components/drawer/drawer.svelte +8 -3
- package/src/lib/components/link-preview/components/link-preview-content.svelte +15 -8
- package/src/lib/components/link-preview/components/link-preview-trigger.svelte +9 -6
- package/src/lib/components/link-preview/components/link-preview.svelte +19 -11
- package/src/lib/components/link-preview/link-preview.svelte.ts +42 -43
- package/src/lib/components/menu/components/menu-checkbox-group.svelte +6 -4
- package/src/lib/components/menu/components/menu-checkbox-item.svelte +11 -7
- package/src/lib/components/menu/menu.svelte.ts +29 -19
- package/src/lib/components/menubar/menubar.svelte.ts +7 -6
- package/src/lib/components/meter/components/meter.svelte +18 -9
- package/src/lib/components/meter/meter.svelte.ts +15 -18
- package/src/lib/components/navigation-menu/components/navigation-menu-content.svelte +1 -1
- package/src/lib/components/navigation-menu/components/navigation-menu-indicator.svelte +2 -2
- package/src/lib/components/navigation-menu/components/navigation-menu-trigger.svelte +1 -1
- package/src/lib/components/navigation-menu/navigation-menu.svelte.ts +57 -60
- package/src/lib/components/pagination/components/pagination-next-button.svelte +12 -7
- package/src/lib/components/pagination/components/pagination-page.svelte +15 -8
- package/src/lib/components/pagination/components/pagination-prev-button.svelte +12 -7
- package/src/lib/components/pagination/components/pagination.svelte +31 -18
- package/src/lib/components/pagination/pagination.svelte.ts +48 -64
- package/src/lib/components/pin-input/pin-input.svelte.ts +7 -8
- package/src/lib/components/pin-input/usePasswordManager.svelte.ts +2 -2
- package/src/lib/components/popover/components/popover-close.svelte +9 -6
- package/src/lib/components/popover/components/popover-content.svelte +12 -7
- package/src/lib/components/popover/components/popover-trigger.svelte +21 -10
- package/src/lib/components/popover/components/popover.svelte +9 -8
- package/src/lib/components/popover/popover.svelte.ts +68 -74
- package/src/lib/components/progress/components/progress.svelte +18 -9
- package/src/lib/components/progress/progress.svelte.ts +14 -17
- package/src/lib/components/scroll-area/scroll-area.svelte.ts +9 -10
- package/src/lib/components/separator/components/separator.svelte +15 -8
- package/src/lib/components/separator/separator.svelte.ts +12 -15
- package/src/lib/components/sidebar/sidebar-mobile-surface.svelte +8 -4
- package/src/lib/components/slider/components/slider.svelte +2 -1
- package/src/lib/components/tabs/components/tabs-content.svelte +12 -7
- package/src/lib/components/tabs/components/tabs-list.svelte +9 -6
- package/src/lib/components/tabs/components/tabs-trigger.svelte +15 -8
- package/src/lib/components/tabs/components/tabs.svelte +28 -17
- package/src/lib/components/tabs/tabs.svelte.ts +51 -67
- package/src/lib/components/time-field/time-field.svelte.ts +2 -2
- package/src/lib/components/toggle/components/toggle.svelte +19 -14
- package/src/lib/components/toggle/toggle.svelte.ts +15 -20
- package/src/lib/components/toggle-group/components/toggle-group-item.svelte +15 -8
- package/src/lib/components/toggle-group/components/toggle-group.svelte +28 -16
- package/src/lib/components/toggle-group/toggle-group.svelte.ts +33 -35
- package/src/lib/components/toolbar/components/toolbar-group-item.svelte +15 -8
- package/src/lib/components/toolbar/components/toolbar-group.svelte +19 -14
- package/src/lib/components/toolbar/toolbar.svelte.ts +28 -30
- package/src/lib/components/tooltip/components/tooltip-content.svelte +15 -8
- package/src/lib/components/tooltip/components/tooltip-provider.svelte +18 -7
- package/src/lib/components/tooltip/components/tooltip-trigger.svelte +21 -10
- package/src/lib/components/tooltip/components/tooltip.svelte +34 -21
- package/src/lib/components/tooltip/tooltip.svelte.ts +101 -125
- package/src/lib/internal/dismissible-layer/use-dismissable-layer.svelte.ts +3 -4
- package/src/lib/internal/escape-layer/use-escape-layer.svelte.ts +13 -29
- package/src/lib/internal/floating-layer/use-floating-layer.svelte.ts +26 -30
- package/src/lib/internal/group-value.svelte.ts +11 -10
- package/src/lib/internal/native-popover.svelte.ts +6 -6
- package/src/lib/internal/{roving-focus-group.ts → roving-focus-group.svelte.ts} +17 -19
- package/src/lib/internal/roving-focus-item.svelte.ts +12 -17
- package/src/lib/internal/selection.svelte.ts +55 -41
- package/src/lib/internal/{state-machine.ts → state-machine.svelte.ts} +6 -8
- package/src/lib/internal/timeout-fn.svelte.ts +6 -4
- package/src/lib/internal/tools/box.svelte.ts +5 -114
- package/src/lib/internal/tools/index.ts +1 -11
- package/src/lib/internal/tools/types.ts +0 -3
- package/src/lib/internal/typeahead.svelte.ts +9 -13
- package/src/lib/internal/types.ts +6 -0
- package/src/lib/internal/vaul/use-drawer-content.svelte.ts +2 -2
- package/src/lib/internal/vaul/use-drawer-root.svelte.ts +12 -7
- package/src/lib/components/accordion/accordion.svelte.ts +0 -43
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PaginationNextButtonProps } from '../types.js';
|
|
5
4
|
import { PaginationButtonState } from '../pagination.svelte.js';
|
|
@@ -21,12 +20,18 @@
|
|
|
21
20
|
|
|
22
21
|
const nextButtonState = PaginationButtonState.create({
|
|
23
22
|
type: 'next',
|
|
24
|
-
id
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
get id() {
|
|
24
|
+
return id;
|
|
25
|
+
},
|
|
26
|
+
get disabled() {
|
|
27
|
+
return Boolean(disabled);
|
|
28
|
+
},
|
|
29
|
+
get ref() {
|
|
30
|
+
return ref;
|
|
31
|
+
},
|
|
32
|
+
set ref(v) {
|
|
33
|
+
ref = v;
|
|
34
|
+
},
|
|
30
35
|
});
|
|
31
36
|
|
|
32
37
|
const mergedProps = $derived(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PaginationPageProps } from '../types.js';
|
|
5
4
|
import { PaginationPageState } from '../pagination.svelte.js';
|
|
@@ -25,13 +24,21 @@
|
|
|
25
24
|
} = $props();
|
|
26
25
|
|
|
27
26
|
const pageState = PaginationPageState.create({
|
|
28
|
-
id
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
disabled
|
|
27
|
+
get id() {
|
|
28
|
+
return id;
|
|
29
|
+
},
|
|
30
|
+
get page() {
|
|
31
|
+
return page;
|
|
32
|
+
},
|
|
33
|
+
get disabled() {
|
|
34
|
+
return Boolean(disabled);
|
|
35
|
+
},
|
|
36
|
+
get ref() {
|
|
37
|
+
return ref;
|
|
38
|
+
},
|
|
39
|
+
set ref(v) {
|
|
40
|
+
ref = v;
|
|
41
|
+
},
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
const mergedProps = $derived(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PaginationPrevButtonProps } from '../types.js';
|
|
5
4
|
import { PaginationButtonState } from '../pagination.svelte.js';
|
|
@@ -21,12 +20,18 @@
|
|
|
21
20
|
|
|
22
21
|
const prevButtonState = PaginationButtonState.create({
|
|
23
22
|
type: 'prev',
|
|
24
|
-
id
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
get id() {
|
|
24
|
+
return id;
|
|
25
|
+
},
|
|
26
|
+
get disabled() {
|
|
27
|
+
return Boolean(disabled);
|
|
28
|
+
},
|
|
29
|
+
get ref() {
|
|
30
|
+
return ref;
|
|
31
|
+
},
|
|
32
|
+
set ref(v) {
|
|
33
|
+
ref = v;
|
|
34
|
+
},
|
|
30
35
|
});
|
|
31
36
|
|
|
32
37
|
const mergedProps = $derived(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PaginationRootProps } from '../types.js';
|
|
5
4
|
import { PaginationRootState } from '../pagination.svelte.js';
|
|
@@ -23,23 +22,37 @@
|
|
|
23
22
|
}: PaginationRootProps = $props();
|
|
24
23
|
|
|
25
24
|
const rootState = PaginationRootState.create({
|
|
26
|
-
id
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
()
|
|
41
|
-
|
|
42
|
-
)
|
|
25
|
+
get id() {
|
|
26
|
+
return id;
|
|
27
|
+
},
|
|
28
|
+
get count() {
|
|
29
|
+
return count;
|
|
30
|
+
},
|
|
31
|
+
get perPage() {
|
|
32
|
+
return perPage;
|
|
33
|
+
},
|
|
34
|
+
get page() {
|
|
35
|
+
return page;
|
|
36
|
+
},
|
|
37
|
+
set page(v) {
|
|
38
|
+
page = v;
|
|
39
|
+
onPageChange?.(v);
|
|
40
|
+
},
|
|
41
|
+
get loop() {
|
|
42
|
+
return loop;
|
|
43
|
+
},
|
|
44
|
+
get siblingCount() {
|
|
45
|
+
return siblingCount;
|
|
46
|
+
},
|
|
47
|
+
get orientation() {
|
|
48
|
+
return orientation;
|
|
49
|
+
},
|
|
50
|
+
get ref() {
|
|
51
|
+
return ref;
|
|
52
|
+
},
|
|
53
|
+
set ref(v) {
|
|
54
|
+
ref = v;
|
|
55
|
+
},
|
|
43
56
|
});
|
|
44
57
|
|
|
45
58
|
const mergedProps = $derived(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createContext } from 'svelte';
|
|
2
|
-
import { attachRef
|
|
2
|
+
import { attachRef } from '../../internal/tools/index.js';
|
|
3
3
|
import type { Page, PageItem } from './types.js';
|
|
4
|
-
import type { BitsKeyboardEvent, BitsMouseEvent, RefAttachment,
|
|
4
|
+
import type { BitsKeyboardEvent, BitsMouseEvent, RefAttachment, RefOpts } from '../../internal/types.js';
|
|
5
5
|
import { createBitsAttrs } from '../../internal/attrs.js';
|
|
6
6
|
import { kbd } from '../../internal/kbd.js';
|
|
7
|
-
import { RovingFocusGroup } from '../../internal/roving-focus-group.js';
|
|
7
|
+
import { RovingFocusGroup } from '../../internal/roving-focus-group.svelte.js';
|
|
8
8
|
import { type Orientation } from '../../internal/index.js';
|
|
9
9
|
|
|
10
10
|
const paginationAttrs = createBitsAttrs({
|
|
@@ -14,19 +14,14 @@ const paginationAttrs = createBitsAttrs({
|
|
|
14
14
|
|
|
15
15
|
const [getPaginationRoot, setPaginationRoot] = createContext<PaginationRootState>();
|
|
16
16
|
|
|
17
|
-
interface PaginationRootStateOpts
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
loop: boolean;
|
|
26
|
-
}>,
|
|
27
|
-
WritableBoxedValues<{
|
|
28
|
-
page: number;
|
|
29
|
-
}> {}
|
|
17
|
+
interface PaginationRootStateOpts extends RefOpts {
|
|
18
|
+
readonly count: number;
|
|
19
|
+
readonly perPage: number;
|
|
20
|
+
readonly siblingCount: number;
|
|
21
|
+
readonly orientation: Orientation;
|
|
22
|
+
readonly loop: boolean;
|
|
23
|
+
page: number;
|
|
24
|
+
}
|
|
30
25
|
|
|
31
26
|
export class PaginationRootState {
|
|
32
27
|
static create(opts: PaginationRootStateOpts) {
|
|
@@ -35,73 +30,66 @@ export class PaginationRootState {
|
|
|
35
30
|
readonly opts: PaginationRootStateOpts;
|
|
36
31
|
readonly attachment: RefAttachment;
|
|
37
32
|
readonly totalPages = $derived.by(() => {
|
|
38
|
-
if (this.opts.count
|
|
39
|
-
return Math.ceil(this.opts.count
|
|
33
|
+
if (this.opts.count === 0) return 1;
|
|
34
|
+
return Math.ceil(this.opts.count / this.opts.perPage);
|
|
40
35
|
});
|
|
41
36
|
readonly range = $derived.by(() => {
|
|
42
|
-
const start = (this.opts.page
|
|
43
|
-
const end = Math.min(start + this.opts.perPage
|
|
37
|
+
const start = (this.opts.page - 1) * this.opts.perPage;
|
|
38
|
+
const end = Math.min(start + this.opts.perPage, this.opts.count);
|
|
44
39
|
return { start: start + 1, end };
|
|
45
40
|
});
|
|
46
41
|
readonly pages = $derived.by(() =>
|
|
47
42
|
getPageItems({
|
|
48
|
-
page: this.opts.page
|
|
43
|
+
page: this.opts.page,
|
|
49
44
|
totalPages: this.totalPages,
|
|
50
|
-
siblingCount: this.opts.siblingCount
|
|
45
|
+
siblingCount: this.opts.siblingCount,
|
|
51
46
|
}),
|
|
52
47
|
);
|
|
53
|
-
readonly hasPrevPage = $derived.by(() => this.opts.page
|
|
54
|
-
readonly hasNextPage = $derived.by(() => this.opts.page
|
|
48
|
+
readonly hasPrevPage = $derived.by(() => this.opts.page > 1);
|
|
49
|
+
readonly hasNextPage = $derived.by(() => this.opts.page < this.totalPages);
|
|
55
50
|
|
|
56
51
|
readonly rovingFocusGroup: RovingFocusGroup;
|
|
57
52
|
|
|
58
53
|
constructor(opts: PaginationRootStateOpts) {
|
|
59
54
|
this.opts = opts;
|
|
60
|
-
this.attachment = attachRef(
|
|
55
|
+
this.attachment = attachRef<HTMLElement>((v) => (opts.ref = v));
|
|
61
56
|
this.rovingFocusGroup = new RovingFocusGroup({
|
|
62
57
|
candidateSelector: [paginationAttrs.selector('prev'), paginationAttrs.selector('page'), paginationAttrs.selector('next')].join(', '),
|
|
63
|
-
rootNode:
|
|
64
|
-
loop:
|
|
65
|
-
orientation:
|
|
58
|
+
rootNode: () => opts.ref,
|
|
59
|
+
loop: () => opts.loop,
|
|
60
|
+
orientation: () => opts.orientation,
|
|
66
61
|
});
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
setPage(page: number) {
|
|
70
|
-
this.opts.page.current = page;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
64
|
prevPage() {
|
|
74
|
-
this.opts.page
|
|
65
|
+
this.opts.page = Math.max(this.opts.page - 1, 1);
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
nextPage() {
|
|
78
|
-
this.opts.page
|
|
69
|
+
this.opts.page = Math.min(this.opts.page + 1, this.totalPages);
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
readonly snippetProps = $derived.by(() => ({
|
|
82
73
|
pages: this.pages,
|
|
83
74
|
range: this.range,
|
|
84
|
-
currentPage: this.opts.page
|
|
75
|
+
currentPage: this.opts.page,
|
|
85
76
|
}));
|
|
86
77
|
|
|
87
78
|
readonly props = $derived.by(
|
|
88
79
|
() =>
|
|
89
80
|
({
|
|
90
|
-
id: this.opts.id
|
|
91
|
-
'data-orientation': this.opts.orientation
|
|
81
|
+
id: this.opts.id,
|
|
82
|
+
'data-orientation': this.opts.orientation,
|
|
92
83
|
[paginationAttrs.root]: '',
|
|
93
84
|
...this.attachment,
|
|
94
85
|
}) as const,
|
|
95
86
|
);
|
|
96
87
|
}
|
|
97
88
|
|
|
98
|
-
interface PaginationPageStateOpts
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
page: Page;
|
|
103
|
-
disabled: boolean;
|
|
104
|
-
}> {}
|
|
89
|
+
interface PaginationPageStateOpts extends RefOpts {
|
|
90
|
+
readonly page: Page;
|
|
91
|
+
readonly disabled: boolean;
|
|
92
|
+
}
|
|
105
93
|
|
|
106
94
|
export class PaginationPageState {
|
|
107
95
|
static create(opts: PaginationPageStateOpts) {
|
|
@@ -110,38 +98,38 @@ export class PaginationPageState {
|
|
|
110
98
|
readonly opts: PaginationPageStateOpts;
|
|
111
99
|
readonly root: PaginationRootState;
|
|
112
100
|
readonly attachment: RefAttachment;
|
|
113
|
-
readonly #isSelected = $derived.by(() => this.opts.page.
|
|
101
|
+
readonly #isSelected = $derived.by(() => this.opts.page.value === this.root.opts.page);
|
|
114
102
|
|
|
115
103
|
constructor(opts: PaginationPageStateOpts, root: PaginationRootState) {
|
|
116
104
|
this.opts = opts;
|
|
117
105
|
this.root = root;
|
|
118
|
-
this.attachment = attachRef(
|
|
106
|
+
this.attachment = attachRef<HTMLElement>((v) => (opts.ref = v));
|
|
119
107
|
|
|
120
108
|
this.onclick = this.onclick.bind(this);
|
|
121
109
|
this.onkeydown = this.onkeydown.bind(this);
|
|
122
110
|
}
|
|
123
111
|
|
|
124
112
|
onclick(e: BitsMouseEvent) {
|
|
125
|
-
if (this.opts.disabled
|
|
113
|
+
if (this.opts.disabled) return;
|
|
126
114
|
if (e.button !== 0) return;
|
|
127
|
-
this.root.
|
|
115
|
+
this.root.opts.page = this.opts.page.value;
|
|
128
116
|
}
|
|
129
117
|
|
|
130
118
|
onkeydown(e: BitsKeyboardEvent) {
|
|
131
119
|
if (e.key === kbd.SPACE || e.key === kbd.ENTER) {
|
|
132
120
|
e.preventDefault();
|
|
133
|
-
this.root.
|
|
121
|
+
this.root.opts.page = this.opts.page.value;
|
|
134
122
|
} else {
|
|
135
|
-
this.root.rovingFocusGroup.handleKeydown(this.opts.ref
|
|
123
|
+
this.root.rovingFocusGroup.handleKeydown(this.opts.ref, e);
|
|
136
124
|
}
|
|
137
125
|
}
|
|
138
126
|
|
|
139
127
|
readonly props = $derived.by(
|
|
140
128
|
() =>
|
|
141
129
|
({
|
|
142
|
-
id: this.opts.id
|
|
143
|
-
'aria-label': `Page ${this.opts.page.
|
|
144
|
-
'data-value': `${this.opts.page.
|
|
130
|
+
id: this.opts.id,
|
|
131
|
+
'aria-label': `Page ${this.opts.page.value}`,
|
|
132
|
+
'data-value': `${this.opts.page.value}`,
|
|
145
133
|
'data-selected': this.#isSelected ? '' : undefined,
|
|
146
134
|
[paginationAttrs.page]: '',
|
|
147
135
|
//
|
|
@@ -156,12 +144,8 @@ export class PaginationPageState {
|
|
|
156
144
|
// NEXT/PREV BUTTON
|
|
157
145
|
//
|
|
158
146
|
|
|
159
|
-
interface PaginationButtonStateOpts
|
|
160
|
-
|
|
161
|
-
WithRefOpts,
|
|
162
|
-
ReadableBoxedValues<{
|
|
163
|
-
disabled: boolean;
|
|
164
|
-
}> {
|
|
147
|
+
interface PaginationButtonStateOpts extends RefOpts {
|
|
148
|
+
readonly disabled: boolean;
|
|
165
149
|
type: 'prev' | 'next';
|
|
166
150
|
}
|
|
167
151
|
|
|
@@ -176,7 +160,7 @@ export class PaginationButtonState {
|
|
|
176
160
|
constructor(opts: PaginationButtonStateOpts, root: PaginationRootState) {
|
|
177
161
|
this.opts = opts;
|
|
178
162
|
this.root = root;
|
|
179
|
-
this.attachment = attachRef(
|
|
163
|
+
this.attachment = attachRef<HTMLElement>((v) => (opts.ref = v));
|
|
180
164
|
|
|
181
165
|
this.onclick = this.onclick.bind(this);
|
|
182
166
|
this.onkeydown = this.onkeydown.bind(this);
|
|
@@ -187,14 +171,14 @@ export class PaginationButtonState {
|
|
|
187
171
|
}
|
|
188
172
|
|
|
189
173
|
readonly #isDisabled = $derived.by(() => {
|
|
190
|
-
if (this.opts.disabled
|
|
174
|
+
if (this.opts.disabled) return true;
|
|
191
175
|
if (this.opts.type === 'prev') return !this.root.hasPrevPage;
|
|
192
176
|
if (this.opts.type === 'next') return !this.root.hasNextPage;
|
|
193
177
|
return false;
|
|
194
178
|
});
|
|
195
179
|
|
|
196
180
|
onclick(e: BitsMouseEvent) {
|
|
197
|
-
if (this.opts.disabled
|
|
181
|
+
if (this.opts.disabled) return;
|
|
198
182
|
if (e.button !== 0) return;
|
|
199
183
|
this.#action();
|
|
200
184
|
}
|
|
@@ -204,14 +188,14 @@ export class PaginationButtonState {
|
|
|
204
188
|
e.preventDefault();
|
|
205
189
|
this.#action();
|
|
206
190
|
} else {
|
|
207
|
-
this.root.rovingFocusGroup.handleKeydown(this.opts.ref
|
|
191
|
+
this.root.rovingFocusGroup.handleKeydown(this.opts.ref, e);
|
|
208
192
|
}
|
|
209
193
|
}
|
|
210
194
|
|
|
211
195
|
readonly props = $derived.by(
|
|
212
196
|
() =>
|
|
213
197
|
({
|
|
214
|
-
id: this.opts.id
|
|
198
|
+
id: this.opts.id,
|
|
215
199
|
[paginationAttrs[this.opts.type]]: '',
|
|
216
200
|
disabled: this.#isDisabled,
|
|
217
201
|
//
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
DOMContext,
|
|
6
6
|
type ReadableBoxedValues,
|
|
7
7
|
type WritableBoxedValues,
|
|
8
|
-
simpleBox,
|
|
9
8
|
} from '../../internal/tools/index.js';
|
|
10
9
|
import { usePasswordManagerBadge } from './usePasswordManager.svelte.js';
|
|
11
10
|
import type { PinInputCell, PinInputRootProps as RootComponentProps } from './types.js';
|
|
@@ -80,7 +79,7 @@ export class PinInputRootState {
|
|
|
80
79
|
readonly attachment: RefAttachment;
|
|
81
80
|
readonly inputAttachment: RefAttachment<HTMLInputElement>;
|
|
82
81
|
#isHoveringInput = $state(false);
|
|
83
|
-
|
|
82
|
+
isFocused = $state(false);
|
|
84
83
|
#mirrorSelectionStart = $state<number | null>(null);
|
|
85
84
|
#mirrorSelectionEnd = $state<number | null>(null);
|
|
86
85
|
|
|
@@ -129,7 +128,7 @@ export class PinInputRootState {
|
|
|
129
128
|
this.#pwmb = usePasswordManagerBadge({
|
|
130
129
|
containerRef: this.opts.ref,
|
|
131
130
|
inputRef: this.opts.inputRef,
|
|
132
|
-
isFocused: this
|
|
131
|
+
isFocused: () => this.isFocused,
|
|
133
132
|
pushPasswordManagerStrategy: this.opts.pushPasswordManagerStrategy,
|
|
134
133
|
domContext: this.domContext,
|
|
135
134
|
});
|
|
@@ -152,7 +151,7 @@ export class PinInputRootState {
|
|
|
152
151
|
|
|
153
152
|
this.#onDocumentSelectionChange();
|
|
154
153
|
if (this.domContext.getActiveElement() === input) {
|
|
155
|
-
this
|
|
154
|
+
this.isFocused = true;
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
if (!this.domContext.getElementById('pin-input-style')) {
|
|
@@ -386,7 +385,7 @@ export class PinInputRootState {
|
|
|
386
385
|
this.#mirrorSelectionStart = start;
|
|
387
386
|
this.#mirrorSelectionEnd = end;
|
|
388
387
|
}
|
|
389
|
-
this
|
|
388
|
+
this.isFocused = true;
|
|
390
389
|
};
|
|
391
390
|
|
|
392
391
|
onpaste = (e: BitsEvent<ClipboardEvent>) => {
|
|
@@ -440,7 +439,7 @@ export class PinInputRootState {
|
|
|
440
439
|
this.#prevInputMetadata.willSyntheticBlur = false;
|
|
441
440
|
return;
|
|
442
441
|
}
|
|
443
|
-
this
|
|
442
|
+
this.isFocused = false;
|
|
444
443
|
};
|
|
445
444
|
|
|
446
445
|
readonly inputProps = $derived.by(() => ({
|
|
@@ -469,7 +468,7 @@ export class PinInputRootState {
|
|
|
469
468
|
readonly #cells = $derived.by(() =>
|
|
470
469
|
Array.from({ length: this.opts.maxLength.current }).map((_, idx) => {
|
|
471
470
|
const isActive =
|
|
472
|
-
this
|
|
471
|
+
this.isFocused &&
|
|
473
472
|
this.#mirrorSelectionStart !== null &&
|
|
474
473
|
this.#mirrorSelectionEnd !== null &&
|
|
475
474
|
((this.#mirrorSelectionStart === this.#mirrorSelectionEnd && idx === this.#mirrorSelectionStart) ||
|
|
@@ -487,7 +486,7 @@ export class PinInputRootState {
|
|
|
487
486
|
|
|
488
487
|
readonly snippetProps = $derived.by(() => ({
|
|
489
488
|
cells: this.#cells,
|
|
490
|
-
isFocused: this
|
|
489
|
+
isFocused: this.isFocused,
|
|
491
490
|
isHovering: this.#isHoveringInput,
|
|
492
491
|
}));
|
|
493
492
|
}
|
|
@@ -16,7 +16,7 @@ type UsePasswordManagerBadgeProps = {
|
|
|
16
16
|
containerRef: WritableBox<HTMLElement | null>;
|
|
17
17
|
inputRef: WritableBox<HTMLInputElement | null>;
|
|
18
18
|
pushPasswordManagerStrategy: ReadableBox<PinInputRootPropsWithoutHTML['pushPasswordManagerStrategy']>;
|
|
19
|
-
isFocused:
|
|
19
|
+
isFocused: () => boolean;
|
|
20
20
|
domContext: DOMContext;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -91,7 +91,7 @@ export function usePasswordManagerBadge({
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
$effect(() => {
|
|
94
|
-
const focused = isFocused
|
|
94
|
+
const focused = isFocused() || domContext.getActiveElement() === inputRef.current;
|
|
95
95
|
|
|
96
96
|
if (pushPasswordManagerStrategy.current === 'none' || !focused) return;
|
|
97
97
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PopoverCloseProps } from '../types.js';
|
|
5
4
|
import { PopoverCloseState } from '../popover.svelte.js';
|
|
@@ -11,11 +10,15 @@
|
|
|
11
10
|
let { child, children, id = createId(uid), ref = $bindable(null), ...restProps }: PopoverCloseProps = $props();
|
|
12
11
|
|
|
13
12
|
const closeState = PopoverCloseState.create({
|
|
14
|
-
id
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
get id() {
|
|
14
|
+
return id;
|
|
15
|
+
},
|
|
16
|
+
get ref() {
|
|
17
|
+
return ref;
|
|
18
|
+
},
|
|
19
|
+
set ref(v) {
|
|
20
|
+
ref = v;
|
|
21
|
+
},
|
|
19
22
|
});
|
|
20
23
|
|
|
21
24
|
const mergedProps = $derived(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PopoverContentProps } from '../types.js';
|
|
5
4
|
import { PopoverContentState } from '../popover.svelte.js';
|
|
@@ -36,12 +35,18 @@
|
|
|
36
35
|
}: PopoverContentProps = $props();
|
|
37
36
|
|
|
38
37
|
const contentState = PopoverContentState.create({
|
|
39
|
-
id
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
get id() {
|
|
39
|
+
return id;
|
|
40
|
+
},
|
|
41
|
+
get customAnchor() {
|
|
42
|
+
return customAnchor;
|
|
43
|
+
},
|
|
44
|
+
get ref() {
|
|
45
|
+
return ref;
|
|
46
|
+
},
|
|
47
|
+
set ref(v) {
|
|
48
|
+
ref = v;
|
|
49
|
+
},
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
const lifecycleProps = useNativePopoverLifecycle(contentState, { anchor: () => customAnchor, mode: 'auto' });
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
3
2
|
import { mergeProps } from '../../../internal/merge-props.js';
|
|
4
3
|
import type { PopoverTriggerProps } from '../types.js';
|
|
5
4
|
import { PopoverTriggerState } from '../popover.svelte.js';
|
|
@@ -21,15 +20,27 @@
|
|
|
21
20
|
}: PopoverTriggerProps = $props();
|
|
22
21
|
|
|
23
22
|
const triggerState = PopoverTriggerState.create({
|
|
24
|
-
id
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
openOnHover
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
get id() {
|
|
24
|
+
return id;
|
|
25
|
+
},
|
|
26
|
+
get disabled() {
|
|
27
|
+
return Boolean(disabled);
|
|
28
|
+
},
|
|
29
|
+
get openOnHover() {
|
|
30
|
+
return openOnHover;
|
|
31
|
+
},
|
|
32
|
+
get openDelay() {
|
|
33
|
+
return openDelay;
|
|
34
|
+
},
|
|
35
|
+
get closeDelay() {
|
|
36
|
+
return closeDelay;
|
|
37
|
+
},
|
|
38
|
+
get ref() {
|
|
39
|
+
return ref;
|
|
40
|
+
},
|
|
41
|
+
set ref(v) {
|
|
42
|
+
ref = v;
|
|
43
|
+
},
|
|
33
44
|
});
|
|
34
45
|
|
|
35
46
|
const mergedProps = $derived(mergeProps({ 'data-slot': 'popover-trigger' }, restProps, triggerState.props, { type }));
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import type { PopoverRootProps } from '../types.js';
|
|
3
3
|
import { PopoverRootState } from '../popover.svelte.js';
|
|
4
4
|
import { OpenCell } from '../../../internal/open-cell.svelte.js';
|
|
5
|
-
import { boxWith } from '../../../internal/tools/index.js';
|
|
6
5
|
|
|
7
6
|
let { open = false, onOpenChangeComplete = () => {}, state, children }: PopoverRootProps = $props();
|
|
8
7
|
|
|
@@ -10,16 +9,18 @@
|
|
|
10
9
|
// derivation source, and the children snippet is the only way the cell leaves.
|
|
11
10
|
// A caller-built `state` cell (with its own source/writer) takes over both roles.
|
|
12
11
|
// The cell's identity is fixed at mount — swapping `state` later is not supported.
|
|
13
|
-
// The engine keeps its boxed-open interface (vendored, ADR 0006); the box is a
|
|
14
|
-
// bridge over the cell, so the cell stays the one owner of `open`.
|
|
15
12
|
// svelte-ignore state_referenced_locally
|
|
16
13
|
const popover = state ?? new OpenCell(() => open);
|
|
17
14
|
PopoverRootState.create({
|
|
18
|
-
open
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
|
|
15
|
+
get open() {
|
|
16
|
+
return popover.open;
|
|
17
|
+
},
|
|
18
|
+
set open(value) {
|
|
19
|
+
popover.open = value;
|
|
20
|
+
},
|
|
21
|
+
get onOpenChangeComplete() {
|
|
22
|
+
return onOpenChangeComplete;
|
|
23
|
+
},
|
|
23
24
|
});
|
|
24
25
|
</script>
|
|
25
26
|
|