@splendidlabz/svelte 4.3.1 → 4.5.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/CHANGELOG.md +29 -0
- package/components/Breadcrumbs/Breadcrumbs.svelte +10 -9
- package/components/Breadcrumbs/Crumb.svelte +2 -1
- package/components/ContentList/ContentList.svelte +1 -1
- package/components/Disclosure/Disclosure/DisclosureContent.svelte +6 -8
- package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +34 -9
- package/components/Disclosure/Disclosure/disclosure.svelte.js +61 -79
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +14 -30
- package/components/Disclosure/Drawer/DrawerContent.svelte +58 -74
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +13 -6
- package/components/Disclosure/Drawer/drawer.js +3 -27
- package/components/Disclosure/Drawer/index.js +6 -2
- package/components/Disclosure/Modal/ModalContent.svelte +122 -32
- package/components/Disclosure/Modal/ModalTrigger.svelte +63 -6
- package/components/Disclosure/Modal/index.js +2 -2
- package/components/Disclosure/Popover/PopoverContent.svelte +109 -97
- package/components/Disclosure/Popover/PopoverTrigger.svelte +67 -22
- package/components/Disclosure/Popover/floating.js +278 -117
- package/components/Disclosure/Popover/index.js +3 -2
- package/components/Disclosure/index.js +3 -7
- package/components/Disclosure/shared.js +1 -0
- package/components/DisclosureOld/Drawer/DrawerCloseButton.svelte +37 -0
- package/components/DisclosureOld/Drawer/DrawerContent.svelte +92 -0
- package/components/DisclosureOld/Drawer/DrawerTrigger.svelte +11 -0
- package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/drawer.js +0 -26
- package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/index.js +2 -6
- package/components/DisclosureOld/Modal/ModalContent.svelte +42 -0
- package/components/DisclosureOld/Modal/ModalTrigger.svelte +11 -0
- package/components/DisclosureOld/Modal/index.js +5 -0
- package/components/DisclosureOld/Old/DisclosureContentOld.svelte +97 -0
- package/components/DisclosureOld/Old/DisclosureTriggerOld.svelte +51 -0
- package/components/{Disclosure → DisclosureOld}/Popover/PopoverCloseButton.svelte +4 -1
- package/components/DisclosureOld/Popover/PopoverContent.svelte +107 -0
- package/components/DisclosureOld/Popover/PopoverTrigger.svelte +33 -0
- package/components/DisclosureOld/Popover/floating.js +171 -0
- package/components/DisclosureOld/Popover/index.js +5 -0
- package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipTrigger.svelte +1 -1
- package/components/{Disclosure → DisclosureOld}/disclosure.js +44 -40
- package/components/Form/Combobox/AutocompleteInput.svelte +3 -3
- package/components/Form/Combobox/AutocompleteOptions.svelte +5 -5
- package/components/Form/Combobox/TimepickerInput.svelte +7 -7
- package/components/Form/Combobox/TimepickerOptions.svelte +7 -7
- package/components/Form/Combobox/autocomplete.js +2 -2
- package/components/Form/Combobox/combobox.js +2 -2
- package/components/SVG/SVG.svelte +46 -0
- package/components/SVG/SVGGradient.svelte +37 -0
- package/components/SVG/index.js +2 -1
- package/package.json +3 -3
- package/actions/resize-observer.js +0 -43
- package/actions/scroll-observer.js +0 -47
- package/components/Disclosure/Disclosure/disclosure-popover.svelte.js +0 -7
- package/components/Disclosure/DisclosureNew/DisclosureCloseButton.svelte +0 -38
- package/components/Disclosure/DisclosureNew/DisclosureContent.svelte +0 -53
- package/components/Disclosure/DisclosureNew/DisclosureTrigger.svelte +0 -79
- package/components/Disclosure/DisclosureNew/disclosures.svelte.js +0 -55
- package/components/Disclosure/DisclosureNew/index.js +0 -5
- package/components/Disclosure/Drawer/DrawerNew.svelte +0 -0
- package/components/Disclosure/DrawerNew/DrawerCloseButton.svelte +0 -21
- package/components/Disclosure/DrawerNew/DrawerContent.svelte +0 -45
- package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +0 -15
- package/components/Disclosure/ModalNew/ModalContent.svelte +0 -132
- package/components/Disclosure/ModalNew/ModalTrigger.svelte +0 -68
- package/components/Disclosure/ModalNew/index.js +0 -5
- package/components/Disclosure/PopoverNew/PopoverContent.svelte +0 -119
- package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +0 -77
- package/components/Disclosure/PopoverNew/floating.js +0 -332
- package/components/Disclosure/PopoverNew/index.js +0 -6
- package/components/Disclosure/state.svelte.js +0 -138
- /package/components/Disclosure/{ModalNew → Modal}/ModalClose.svelte +0 -0
- /package/components/Disclosure/{PopoverNew → Popover}/Popover.svelte +0 -0
- /package/components/Disclosure/{PopoverNew → Popover}/PopoverClose.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Drawer/Drawer.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownContent.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownTrigger.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/dropdown.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/index.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/Modal.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/ModalCloseButton.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/exit-intent.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/modal.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Popover/popover.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Popover/references/FollowTheMouse.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/Tooltip.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipContent.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/index.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/tooltip.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/disclosure-store.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/disclosure.svelte.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @splendidlabz/svelte
|
|
2
2
|
|
|
3
|
+
## 4.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8f2cb34: - b4eefd4f Svelte: Rework & Cleanup Disclosure files
|
|
8
|
+
- 3a1c89ef Removed errors from Drawer
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [8f2cb34]
|
|
13
|
+
- Updated dependencies [8f2cb34]
|
|
14
|
+
- @splendidlabz/styles@4.3.1
|
|
15
|
+
- @splendidlabz/utils@1.9.0
|
|
16
|
+
|
|
17
|
+
## 4.4.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 7466ea7: - Reworked Drawer to include disclosure type
|
|
22
|
+
- Improved breadcrumbs with customizable divider icons and classes
|
|
23
|
+
- Add `SVGGradient` component
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- Updated dependencies [7466ea7]
|
|
29
|
+
- @splendidlabz/utils@1.8.2
|
|
30
|
+
- @splendidlabz/styles@4.3.0
|
|
31
|
+
|
|
3
32
|
## 4.3.1
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
class: klass = '',
|
|
11
|
+
ulClass = '',
|
|
11
12
|
|
|
12
13
|
// Slots
|
|
13
14
|
children,
|
|
@@ -20,12 +21,14 @@
|
|
|
20
21
|
crumbs: [],
|
|
21
22
|
labelCase: 'title',
|
|
22
23
|
divider: 'tabler:chevron-right',
|
|
24
|
+
dividerClass: '',
|
|
23
25
|
ariaCurrentType: 'page',
|
|
24
26
|
startingDepth: 0,
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
const opts = mergeOpts(defaultOptions, rest)
|
|
28
|
-
const { startingDepth, ariaCurrentType, labelCase } =
|
|
30
|
+
const { startingDepth, ariaCurrentType, labelCase, divider, dividerClass } =
|
|
31
|
+
opts
|
|
29
32
|
|
|
30
33
|
let trailingSlash = $derived(hasTrailingSlash(pathname))
|
|
31
34
|
let crumbs = $derived(
|
|
@@ -53,6 +56,8 @@
|
|
|
53
56
|
return {
|
|
54
57
|
label: crumb,
|
|
55
58
|
labelCase,
|
|
59
|
+
divider: crumb.divider || divider,
|
|
60
|
+
dividerClass: crumb.dividerClass || dividerClass,
|
|
56
61
|
href:
|
|
57
62
|
'/' +
|
|
58
63
|
urlArray.slice(0, index + 1).join('/') +
|
|
@@ -65,12 +70,12 @@
|
|
|
65
70
|
</script>
|
|
66
71
|
|
|
67
72
|
<nav class={`breadcrumbs ${klass}`} aria-label="Breadcrumbs">
|
|
68
|
-
<ul>
|
|
73
|
+
<ul class={ulClass}>
|
|
69
74
|
{#if before}
|
|
70
75
|
<li class="crumb">
|
|
71
76
|
{@render before?.()}
|
|
72
77
|
<span class="crumb-divider">
|
|
73
|
-
<Icon icon={
|
|
78
|
+
<Icon class={dividerClass} icon={divider} />
|
|
74
79
|
</span>
|
|
75
80
|
</li>
|
|
76
81
|
{/if}
|
|
@@ -78,12 +83,8 @@
|
|
|
78
83
|
{#if children}
|
|
79
84
|
{@render children()}
|
|
80
85
|
{:else}
|
|
81
|
-
{#each crumbs as crumb
|
|
82
|
-
<Crumb
|
|
83
|
-
{...crumb}
|
|
84
|
-
divider={opts.divider}
|
|
85
|
-
isLast={index === crumbs.length - 1}
|
|
86
|
-
/>
|
|
86
|
+
{#each crumbs as crumb (crumb.href)}
|
|
87
|
+
<Crumb {...crumb} />
|
|
87
88
|
{/each}
|
|
88
89
|
{/if}
|
|
89
90
|
{@render after?.()}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
ariaCurrentType = 'page',
|
|
11
11
|
isLast = null,
|
|
12
12
|
divider = 'tabler:chevron-right',
|
|
13
|
+
dividerClass = '',
|
|
13
14
|
href = '',
|
|
14
15
|
labelCase = 'title',
|
|
15
16
|
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
{@render Snippet.block(before)}
|
|
46
47
|
<a class={aClass} {href}>{label}</a>
|
|
47
48
|
<div class="crumb-divider">
|
|
48
|
-
<Icon icon={divider} />
|
|
49
|
+
<Icon class={dividerClass} icon={divider} />
|
|
49
50
|
</div>
|
|
50
51
|
{/if}
|
|
51
52
|
</li>
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
15
15
|
disclosureContent,
|
|
16
16
|
getDisclosure,
|
|
17
|
-
} from '
|
|
17
|
+
} from './disclosure.svelte.js'
|
|
18
18
|
|
|
19
19
|
let { ref = $bindable(null), ...p } = $props()
|
|
20
20
|
|
|
@@ -26,14 +26,12 @@
|
|
|
26
26
|
'aria-labelledBy': ariaLabelledBy,
|
|
27
27
|
'aria-describedby': ariaDescribedBy,
|
|
28
28
|
componentName = 'DisclosureContent',
|
|
29
|
+
|
|
29
30
|
portal = true,
|
|
30
31
|
scrollToAnchor = false,
|
|
31
32
|
|
|
32
33
|
// Slots
|
|
33
34
|
children,
|
|
34
|
-
|
|
35
|
-
// Event handlers are spread directly into ...rest
|
|
36
|
-
// Custom events are onopen and onclose
|
|
37
35
|
...restProps
|
|
38
36
|
} = p
|
|
39
37
|
|
|
@@ -71,14 +69,14 @@
|
|
|
71
69
|
{#snippet dc()}
|
|
72
70
|
<div
|
|
73
71
|
{...remaining}
|
|
72
|
+
bind:this={ref}
|
|
74
73
|
{id}
|
|
75
74
|
class="disclosure-content {klass}"
|
|
76
|
-
{
|
|
77
|
-
bind:this={ref}
|
|
78
|
-
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
75
|
+
aria-describedby={ariaDescribedBy}
|
|
79
76
|
aria-label={ariaLabel}
|
|
80
77
|
aria-labelledby={ariaLabelledBy}
|
|
81
|
-
|
|
78
|
+
{role}
|
|
79
|
+
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
82
80
|
transition:applyTransition|global={transitionOpts}
|
|
83
81
|
>
|
|
84
82
|
{#if children}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import {
|
|
5
5
|
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
6
6
|
disclosureTrigger,
|
|
7
|
-
} from '
|
|
7
|
+
} from './disclosure.svelte.js'
|
|
8
8
|
|
|
9
|
-
let { show = $bindable(false), ...p } = $props()
|
|
9
|
+
let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
|
|
10
10
|
|
|
11
11
|
const {
|
|
12
12
|
class: klass = '',
|
|
@@ -16,8 +16,13 @@
|
|
|
16
16
|
'aria-haspopup': ariaHasPopup = 'dialog',
|
|
17
17
|
target,
|
|
18
18
|
|
|
19
|
+
// Events
|
|
20
|
+
onopen = null,
|
|
21
|
+
onclose = null,
|
|
22
|
+
|
|
19
23
|
// Slots
|
|
20
24
|
children,
|
|
25
|
+
|
|
21
26
|
...restProps
|
|
22
27
|
} = p
|
|
23
28
|
|
|
@@ -26,21 +31,41 @@
|
|
|
26
31
|
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
27
32
|
)
|
|
28
33
|
|
|
34
|
+
const { picked: eventOpts, omitted: final } = splitObject(rest, [
|
|
35
|
+
'onbeforeopen',
|
|
36
|
+
'onbeforeclose',
|
|
37
|
+
'onbeforetoggle',
|
|
38
|
+
'ontoggle',
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
function handleOpen(data) {
|
|
42
|
+
show = true
|
|
43
|
+
if (onopen) onopen(data)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function handleClose(data) {
|
|
47
|
+
show = false
|
|
48
|
+
if (onclose) onclose(data)
|
|
49
|
+
}
|
|
50
|
+
|
|
29
51
|
if (!target)
|
|
30
52
|
throw new Error(`${componentName} must contain a target property`)
|
|
31
|
-
|
|
32
|
-
// TODO: Test creating an IconSnippet to render the icon vs contents
|
|
33
|
-
// <script module> currently breaks when prettier is enabled. So, ¯\_(ツ)_/¯ if we can ever do that.
|
|
34
53
|
</script>
|
|
35
54
|
|
|
36
55
|
<button
|
|
37
|
-
{...
|
|
38
|
-
{
|
|
39
|
-
class="button {klass}"
|
|
56
|
+
{...final}
|
|
57
|
+
class="button disclosure-trigger {klass}"
|
|
40
58
|
aria-haspopup={ariaHasPopup}
|
|
59
|
+
data-show={show}
|
|
60
|
+
{target}
|
|
41
61
|
use:disclosureTrigger={{
|
|
42
62
|
state: { show },
|
|
43
|
-
options:
|
|
63
|
+
options: {
|
|
64
|
+
...triggerOpts,
|
|
65
|
+
...eventOpts,
|
|
66
|
+
onopen: handleOpen,
|
|
67
|
+
onclose: handleClose,
|
|
68
|
+
},
|
|
44
69
|
}}
|
|
45
70
|
>
|
|
46
71
|
{#if children}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import { delay, omitEmpty } from '@splendidlabz/utils'
|
|
1
2
|
import {
|
|
2
3
|
Focusable,
|
|
3
4
|
addListeners,
|
|
4
|
-
getChildrenElements,
|
|
5
|
-
isAncestor,
|
|
6
5
|
isTab,
|
|
7
6
|
manageFocus,
|
|
8
7
|
removeListeners,
|
|
9
8
|
trapFocus,
|
|
10
9
|
} from '@splendidlabz/utils/dom'
|
|
11
|
-
import { delay, omitEmpty } from '@splendidlabz/utils'
|
|
12
10
|
|
|
13
11
|
// ========================================
|
|
14
12
|
// Default Options
|
|
@@ -26,7 +24,6 @@ export const DEFAULT_DISCLOSURE_TRIGGER_OPTS = {
|
|
|
26
24
|
showOnFocus: false,
|
|
27
25
|
hoverCloseDelay: 120,
|
|
28
26
|
closeOthers: true,
|
|
29
|
-
// shiftTabBackToContent: true,
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
export const DISCLOSURE_TRIGGER_OPT_KEYS = Object.keys(
|
|
@@ -35,21 +32,15 @@ export const DISCLOSURE_TRIGGER_OPT_KEYS = Object.keys(
|
|
|
35
32
|
|
|
36
33
|
/**
|
|
37
34
|
* @typedef {Object} DisclosureContentOpts
|
|
38
|
-
* @property {boolean} closeOnOutsideClick - Close disclosure content when clicking outside of contentNode and triggerNode.
|
|
39
|
-
* @property {boolean} closeOnEscapeButton - Close disclosure content when pressing the escape key.
|
|
40
|
-
* @property {boolean} preventBodyScroll - Prevent body from scrolling when disclosure content is open.
|
|
41
35
|
* @property {boolean} trapFocus - Trap focus within disclosure content.
|
|
42
36
|
* @property {(string|HTMLElement)} focusTargetWhenOpening - Focus target when disclosure content is opened. Can be 'first', 'content', or an HTMLElement.
|
|
43
37
|
*/
|
|
44
38
|
export const DEFAULT_DISCLOSURE_CONTENT_OPTS = {
|
|
45
|
-
|
|
46
|
-
closeOnEscapeButton: true,
|
|
39
|
+
lightDismiss: true,
|
|
47
40
|
focusManagement: 'manage', // false, `manage`, `trap`
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
modal: false,
|
|
41
|
+
focusTargetWhenOpen: 'content', // || false, 'first', 'content'. HTMLElement.
|
|
42
|
+
focusTargetWhenClose: 'trigger', // false
|
|
51
43
|
useTriggerWidth: false,
|
|
52
|
-
// preventBodyScroll: false,
|
|
53
44
|
}
|
|
54
45
|
|
|
55
46
|
export const DISCLOSURE_CONTENT_OPT_KEYS = Object.keys(
|
|
@@ -110,7 +101,6 @@ export function disclosureTrigger(node, props = {}) {
|
|
|
110
101
|
|
|
111
102
|
const d = initDisclosure('trigger', disclosureInfo)
|
|
112
103
|
node.setAttribute('aria-expanded', d.state.show)
|
|
113
|
-
node.setAttribute('aria-haspopup', d.options['aria-haspopup'])
|
|
114
104
|
|
|
115
105
|
const listeners = [
|
|
116
106
|
{
|
|
@@ -158,9 +148,8 @@ export function disclosureTrigger(node, props = {}) {
|
|
|
158
148
|
}
|
|
159
149
|
|
|
160
150
|
function closeOnEscapeButton(event) {
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
}
|
|
151
|
+
if (event.key !== 'Escape') return
|
|
152
|
+
if (d.options.lightDismiss) close(d)
|
|
164
153
|
}
|
|
165
154
|
|
|
166
155
|
function tabOntoContent(event) {
|
|
@@ -279,7 +268,8 @@ export function disclosureContent(node, props = {}) {
|
|
|
279
268
|
// ========================
|
|
280
269
|
// Close if click is outside of contentNode and triggerNode
|
|
281
270
|
function handleOutsideClick(event) {
|
|
282
|
-
|
|
271
|
+
const { lightDismiss } = d.options
|
|
272
|
+
if (lightDismiss === false) return
|
|
283
273
|
if (d.nodes.content.contains(event.target)) return
|
|
284
274
|
if (d.nodes.trigger.contains(event.target)) return
|
|
285
275
|
// Only close if state is currently set to show
|
|
@@ -309,7 +299,7 @@ export function disclosureContent(node, props = {}) {
|
|
|
309
299
|
})
|
|
310
300
|
}
|
|
311
301
|
|
|
312
|
-
if (d.options.
|
|
302
|
+
if (d.options.lightDismiss) closeOnEscape(event)
|
|
313
303
|
}
|
|
314
304
|
|
|
315
305
|
function closeOnEscape(event) {
|
|
@@ -333,9 +323,14 @@ export function disclosureContent(node, props = {}) {
|
|
|
333
323
|
// ========================================
|
|
334
324
|
export function open(d) {
|
|
335
325
|
if (d.state.show) return
|
|
326
|
+
const { trigger } = d.nodes
|
|
327
|
+
const { onbeforeopen, onbeforetoggle } = d.options
|
|
328
|
+
|
|
329
|
+
runEventCallback(onbeforeopen, d, { event: 'beforeopen' })
|
|
330
|
+
runEventCallback(onbeforetoggle, d, { event: 'beforetoggle' })
|
|
331
|
+
|
|
336
332
|
d.state.show = true
|
|
337
333
|
|
|
338
|
-
const { trigger } = d.nodes
|
|
339
334
|
trigger.setAttribute('aria-expanded', d.state.show)
|
|
340
335
|
if (d.options.closeOthers) closeOthersExcept(d.id)
|
|
341
336
|
|
|
@@ -344,7 +339,7 @@ export function open(d) {
|
|
|
344
339
|
|
|
345
340
|
function contentOpeningActions(d) {
|
|
346
341
|
const { content: node, contentFocusables } = d.nodes
|
|
347
|
-
const {
|
|
342
|
+
const { focusTargetWhenOpen, useTriggerWidth, onopen, ontoggle } = d.options
|
|
348
343
|
node.setAttribute('tabindex', '-1')
|
|
349
344
|
|
|
350
345
|
if (useTriggerWidth) {
|
|
@@ -352,59 +347,59 @@ function contentOpeningActions(d) {
|
|
|
352
347
|
node.style.width = triggerWidth + 'px'
|
|
353
348
|
}
|
|
354
349
|
|
|
355
|
-
if (modal) {
|
|
356
|
-
node.setAttribute('aria-modal', 'true')
|
|
357
|
-
stopBodyScroll()
|
|
358
|
-
makeOthersInert(d)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
350
|
// Set focus.
|
|
362
351
|
// This requires timeout. Otherwise focus is set too early.
|
|
363
352
|
setTimeout(_ => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
353
|
+
const hasAutofocus = node.querySelector('autofocus')
|
|
354
|
+
|
|
355
|
+
if (focusTargetWhenOpen && !hasAutofocus) {
|
|
356
|
+
if (focusTargetWhenOpen instanceof HTMLElement) {
|
|
357
|
+
focusTargetWhenOpen.focus()
|
|
358
|
+
}
|
|
359
|
+
if (focusTargetWhenOpen === 'content') {
|
|
367
360
|
node.setAttribute('tabindex', '-1')
|
|
368
|
-
console.log(node)
|
|
369
361
|
node.focus()
|
|
370
362
|
}
|
|
371
|
-
if (
|
|
372
|
-
if (
|
|
363
|
+
if (focusTargetWhenOpen === 'first') contentFocusables.first?.focus()
|
|
364
|
+
if (focusTargetWhenOpen === 'second') contentFocusables[1]?.focus()
|
|
373
365
|
}
|
|
374
|
-
|
|
375
|
-
|
|
366
|
+
|
|
367
|
+
runEventCallback(onopen, d, { event: 'open' })
|
|
368
|
+
runEventCallback(ontoggle, d, { event: 'toggle' })
|
|
376
369
|
}, 1)
|
|
377
370
|
}
|
|
378
371
|
|
|
379
372
|
export function close(d, { shouldFocusWhenClosing = true } = {}) {
|
|
380
373
|
if (!d.state.show) return
|
|
381
|
-
d.state.show = false
|
|
382
374
|
|
|
383
|
-
const { trigger
|
|
375
|
+
const { trigger } = d.nodes
|
|
384
376
|
const { isMouseOut } = d.state
|
|
385
|
-
const {
|
|
386
|
-
|
|
377
|
+
const {
|
|
378
|
+
focusTargetWhenClose,
|
|
379
|
+
onbeforeclose,
|
|
380
|
+
onbeforetoggle,
|
|
381
|
+
onclose,
|
|
382
|
+
ontoggle,
|
|
383
|
+
} = d.options
|
|
387
384
|
|
|
388
|
-
|
|
389
|
-
content.removeAttribute('aria-modal')
|
|
390
|
-
revertInert(d)
|
|
391
|
-
}
|
|
385
|
+
d.state.show = false
|
|
392
386
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
387
|
+
runEventCallback(onbeforeclose, d, { event: 'beforeclose' })
|
|
388
|
+
runEventCallback(onbeforetoggle, d, { event: 'beforetoggle' })
|
|
389
|
+
|
|
390
|
+
trigger.setAttribute('aria-expanded', d.state.show)
|
|
396
391
|
|
|
397
392
|
// Decide whether to focus on trigger
|
|
398
|
-
if (
|
|
393
|
+
if (focusTargetWhenClose === false) shouldFocusWhenClosing = false
|
|
399
394
|
// Mouseout can cause focus to jump around
|
|
400
395
|
if (isMouseOut) shouldFocusWhenClosing = false
|
|
401
396
|
|
|
402
397
|
// Focuses on trigger
|
|
403
398
|
if (shouldFocusWhenClosing) trigger.focus()
|
|
404
399
|
|
|
405
|
-
//
|
|
406
|
-
|
|
407
|
-
|
|
400
|
+
// Run close events
|
|
401
|
+
runEventCallback(onclose, d, { event: 'close' })
|
|
402
|
+
runEventCallback(ontoggle, d, { event: 'toggle' })
|
|
408
403
|
}
|
|
409
404
|
|
|
410
405
|
function closeOthersExcept(id) {
|
|
@@ -423,39 +418,26 @@ function clickedOnOtherDisclosureNodes(target, id) {
|
|
|
423
418
|
})
|
|
424
419
|
}
|
|
425
420
|
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// Modals are placed in portals direct descendant of the body element.
|
|
430
|
-
const bodyChildren = getChildrenElements(document.body)
|
|
431
|
-
const elementsToInert = bodyChildren
|
|
432
|
-
.filter(child => !isAncestor(child, d.nodes.content))
|
|
433
|
-
.filter(child => {
|
|
434
|
-
const tagName = child.tagName?.toLowerCase()
|
|
435
|
-
return tagName !== 'script' && tagName !== 'noscript'
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
elementsToInert.forEach(el => el.setAttribute('inert', ''))
|
|
421
|
+
function getEventProps(event, d) {
|
|
422
|
+
let oldState = !d.state.show
|
|
423
|
+
let newState = d.state.show
|
|
439
424
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
425
|
+
if (event.includes('before')) {
|
|
426
|
+
;[oldState, newState] = [newState, oldState]
|
|
427
|
+
}
|
|
443
428
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
429
|
+
return {
|
|
430
|
+
oldState: toPopoverState(oldState),
|
|
431
|
+
newState: toPopoverState(newState),
|
|
432
|
+
}
|
|
448
433
|
}
|
|
449
434
|
|
|
450
|
-
function
|
|
451
|
-
|
|
452
|
-
document.body.style.top = -1 * top + 'px'
|
|
453
|
-
document.body.style.overflow = 'hidden'
|
|
435
|
+
function toPopoverState(state) {
|
|
436
|
+
return state ? 'open' : 'closed'
|
|
454
437
|
}
|
|
455
438
|
|
|
456
|
-
function
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
document.documentElement.scrollTop = top
|
|
439
|
+
function runEventCallback(fn, data, { event }) {
|
|
440
|
+
if (typeof fn === 'function') {
|
|
441
|
+
fn(getEventProps(event || fn.name, data))
|
|
442
|
+
}
|
|
461
443
|
}
|
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { getEntry } from '../../../actions/sync.svelte.js'
|
|
3
|
+
import ModalClose from '../Modal/ModalClose.svelte'
|
|
4
|
+
import PopoverClose from '../Popover/PopoverClose.svelte'
|
|
4
5
|
|
|
5
|
-
const {
|
|
6
|
-
class: klass = '',
|
|
7
|
-
icon = 'tabler:x',
|
|
8
|
-
iconClass = '',
|
|
9
|
-
target = '',
|
|
10
|
-
children,
|
|
11
|
-
...rest
|
|
12
|
-
} = $props()
|
|
6
|
+
const { class: klass = '', target, ...p } = $props()
|
|
13
7
|
|
|
14
|
-
let
|
|
8
|
+
let sync = $derived(getEntry(target))
|
|
9
|
+
let type = $derived(sync?.type)
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
button.closest('.drawer-content').id
|
|
20
|
-
const d = getDisclosure(id)
|
|
21
|
-
close(d, { shouldFocusWhenClosing: true })
|
|
11
|
+
const propsToPass = {
|
|
12
|
+
target,
|
|
13
|
+
class: `drawer-close-button ${klass}`,
|
|
22
14
|
}
|
|
23
15
|
</script>
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
onclick={closeDrawer}
|
|
31
|
-
>
|
|
32
|
-
{#if children}
|
|
33
|
-
{@render children()}
|
|
34
|
-
{:else}
|
|
35
|
-
<Icon class={iconClass} {icon} />
|
|
36
|
-
{/if}
|
|
37
|
-
</button>
|
|
17
|
+
{#if type === 'popover'}
|
|
18
|
+
<PopoverClose {...propsToPass} {...p} />
|
|
19
|
+
{:else}
|
|
20
|
+
<ModalClose {...propsToPass} {...p} />
|
|
21
|
+
{/if}
|