@skeletonlabs/skeleton 2.6.1 → 2.7.0-dev.e374b42e
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/actions/Clipboard/clipboard.d.ts +5 -4
- package/dist/actions/Clipboard/clipboard.js +1 -1
- package/dist/actions/FocusTrap/focusTrap.js +28 -4
- package/dist/components/Avatar/Avatar.svelte +1 -1
- package/dist/components/Stepper/Step.svelte +6 -20
- package/dist/components/Stepper/Step.svelte.d.ts +4 -2
- package/dist/components/Stepper/Stepper.svelte +19 -1
- package/dist/utilities/Modal/Modal.svelte +43 -13
- package/dist/utilities/Modal/Modal.svelte.d.ts +3 -3
- package/package.json +1 -1
- package/dist/actions/Clipboard/additional-svelte-typings.d.ts +0 -5
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { ActionReturn } from 'svelte/action';
|
|
1
2
|
type ClipboardArgs = string | {
|
|
2
3
|
element: string;
|
|
3
4
|
} | {
|
|
4
5
|
input: string;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
type ClipboardAttributes = {
|
|
8
|
+
'on:copyComplete'?: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function clipboard(node: HTMLElement, args: ClipboardArgs): ActionReturn<ClipboardArgs, ClipboardAttributes>;
|
|
10
11
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function clipboard(node, args) {
|
|
2
2
|
if (!window.isSecureContext) {
|
|
3
3
|
console.error('Clipboard action failed: app not running in secure context, see: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard');
|
|
4
|
-
return;
|
|
4
|
+
return {};
|
|
5
5
|
}
|
|
6
6
|
const fireCopyCompleteEvent = () => {
|
|
7
7
|
node.dispatchEvent(new CustomEvent('copyComplete'));
|
|
@@ -17,18 +17,42 @@ export function focusTrap(node, enabled) {
|
|
|
17
17
|
elemFirst.focus();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
// Sort focusable elements by tabindex, positive first, then 0
|
|
21
|
+
const sortByTabIndex = (focusableElems) => {
|
|
22
|
+
return focusableElems
|
|
23
|
+
.filter((elem) => elem.tabIndex >= 0)
|
|
24
|
+
.sort((a, b) => {
|
|
25
|
+
if (a.tabIndex === 0 && b.tabIndex > 0)
|
|
26
|
+
return 1; // Move 0 to end of array
|
|
27
|
+
else if (a.tabIndex > 0 && b.tabIndex === 0)
|
|
28
|
+
return -1; // Move 0 to end of array
|
|
29
|
+
else
|
|
30
|
+
return a.tabIndex - b.tabIndex; // Sort non-zero values in ascending order
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
// Get element with smallest focusindex value, or first focusable element
|
|
34
|
+
const getFocusTrapTarget = (elemFirst) => {
|
|
35
|
+
// Get elements with data-focusindex attribute
|
|
36
|
+
const focusindexElements = [...node.querySelectorAll('[data-focusindex]')];
|
|
37
|
+
if (!focusindexElements || focusindexElements.length === 0)
|
|
38
|
+
return elemFirst;
|
|
39
|
+
// return smallest focusindex element or elemFirst
|
|
40
|
+
return (focusindexElements.sort((a, b) => {
|
|
41
|
+
return +a.dataset.focusindex - +b.dataset.focusindex;
|
|
42
|
+
})[0] || elemFirst);
|
|
43
|
+
};
|
|
20
44
|
const onScanElements = (fromObserver) => {
|
|
21
45
|
if (enabled === false)
|
|
22
46
|
return;
|
|
23
|
-
// Gather all focusable elements
|
|
24
|
-
const focusableElems = Array.from(node.querySelectorAll(elemWhitelist));
|
|
47
|
+
// Gather all focusable elements, sorted according to tabindex
|
|
48
|
+
const focusableElems = sortByTabIndex(Array.from(node.querySelectorAll(elemWhitelist)));
|
|
25
49
|
if (focusableElems.length) {
|
|
26
50
|
// Set first/last focusable elements
|
|
27
51
|
elemFirst = focusableElems[0];
|
|
28
52
|
elemLast = focusableElems[focusableElems.length - 1];
|
|
29
|
-
// Auto-focus first focusable element only when not called from observer
|
|
53
|
+
// Auto-focus focusTrapTarget or first focusable element only when not called from observer
|
|
30
54
|
if (!fromObserver)
|
|
31
|
-
elemFirst.focus();
|
|
55
|
+
getFocusTrapTarget(elemFirst).focus();
|
|
32
56
|
// Listen for keydown on first & last element
|
|
33
57
|
elemFirst.addEventListener('keydown', onFirstElemKeydown);
|
|
34
58
|
elemLast.addEventListener('keydown', onLastElemKeydown);
|
|
@@ -13,7 +13,7 @@ export let rounded = "rounded-full";
|
|
|
13
13
|
export let shadow = "";
|
|
14
14
|
export let cursor = "";
|
|
15
15
|
let cBase = "flex aspect-square text-surface-50 font-semibold justify-center items-center overflow-hidden isolate";
|
|
16
|
-
let cImage = "w-full
|
|
16
|
+
let cImage = "w-full object-cover";
|
|
17
17
|
$:
|
|
18
18
|
classesBase = `${cBase} ${background} ${width} ${border} ${rounded} ${shadow} ${cursor} ${$$props.class ?? ""}`;
|
|
19
19
|
function prunedRestProps() {
|
|
@@ -6,10 +6,12 @@ export let regionHeader = "";
|
|
|
6
6
|
export let regionContent = "";
|
|
7
7
|
export let regionNavigation = "";
|
|
8
8
|
export let state = getContext("state");
|
|
9
|
-
export let dispatchParent = getContext("dispatchParent");
|
|
10
9
|
export let stepTerm = getContext("stepTerm");
|
|
11
10
|
export let gap = getContext("gap");
|
|
12
11
|
export let justify = getContext("justify");
|
|
12
|
+
export let onNext = getContext("onNext");
|
|
13
|
+
export let onBack = getContext("onBack");
|
|
14
|
+
export let onComplete = getContext("onComplete");
|
|
13
15
|
export let buttonBack = getContext("buttonBack");
|
|
14
16
|
export let buttonBackType = getContext("buttonBackType");
|
|
15
17
|
export let buttonBackLabel = getContext("buttonBackLabel");
|
|
@@ -30,22 +32,6 @@ const cBase = "space-y-4";
|
|
|
30
32
|
const cHeader = "text-2xl font-bold";
|
|
31
33
|
const cContent = "space-y-4";
|
|
32
34
|
const cNavigation = "flex";
|
|
33
|
-
async function onNext() {
|
|
34
|
-
await new Promise((resolve) => setTimeout(resolve));
|
|
35
|
-
if (locked)
|
|
36
|
-
return;
|
|
37
|
-
$state.current++;
|
|
38
|
-
dispatchParent("next", { step: stepIndex, state: $state });
|
|
39
|
-
dispatchParent("step", { step: stepIndex, state: $state });
|
|
40
|
-
}
|
|
41
|
-
function onBack() {
|
|
42
|
-
$state.current--;
|
|
43
|
-
dispatchParent("back", { step: stepIndex, state: $state });
|
|
44
|
-
dispatchParent("step", { step: stepIndex, state: $state });
|
|
45
|
-
}
|
|
46
|
-
function onComplete() {
|
|
47
|
-
dispatchParent("complete", { step: stepIndex, state: $state });
|
|
48
|
-
}
|
|
49
35
|
$:
|
|
50
36
|
classesBase = `${cBase} ${$$props.class ?? ""}`;
|
|
51
37
|
$:
|
|
@@ -83,13 +69,13 @@ onDestroy(() => {
|
|
|
83
69
|
</div>
|
|
84
70
|
{:else}
|
|
85
71
|
<!-- Button: Back -->
|
|
86
|
-
<button type={buttonBackType} class="btn {buttonBack}" on:click={onBack} disabled={$state.current === 0}>
|
|
72
|
+
<button type={buttonBackType} class="btn {buttonBack}" on:click={() => onBack(stepIndex)} disabled={$state.current === 0}>
|
|
87
73
|
{@html buttonBackLabel}
|
|
88
74
|
</button>
|
|
89
75
|
{/if}
|
|
90
76
|
{#if stepIndex < $state.total - 1}
|
|
91
77
|
<!-- Button: Next -->
|
|
92
|
-
<button type={buttonNextType} class="btn {buttonNext}" on:click={onNext} disabled={locked}>
|
|
78
|
+
<button type={buttonNextType} class="btn {buttonNext}" on:click={() => onNext(locked, stepIndex)} disabled={locked}>
|
|
93
79
|
{#if locked}
|
|
94
80
|
<svg class="w-3 aspect-square fill-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
|
|
95
81
|
<path
|
|
@@ -101,7 +87,7 @@ onDestroy(() => {
|
|
|
101
87
|
</button>
|
|
102
88
|
{:else}
|
|
103
89
|
<!-- Button: Complete -->
|
|
104
|
-
<button type={buttonCompleteType} class="btn {buttonComplete}" on:click={onComplete} disabled={locked}>
|
|
90
|
+
<button type={buttonCompleteType} class="btn {buttonComplete}" on:click={() => onComplete(stepIndex)} disabled={locked}>
|
|
105
91
|
{@html buttonCompleteLabel}
|
|
106
92
|
</button>
|
|
107
93
|
{/if}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { Writable } from 'svelte/store';
|
|
3
|
-
import type {
|
|
3
|
+
import type { StepperState } from './types.js';
|
|
4
4
|
import type { Transition, TransitionParams } from '../../index.js';
|
|
5
5
|
declare class __sveltets_Render<TransitionIn extends Transition, TransitionOut extends Transition> {
|
|
6
6
|
props(): {
|
|
@@ -13,10 +13,12 @@ declare class __sveltets_Render<TransitionIn extends Transition, TransitionOut e
|
|
|
13
13
|
/** Provide arbitrary classes to the step navigation region.*/
|
|
14
14
|
regionNavigation?: string | undefined;
|
|
15
15
|
state?: Writable<StepperState> | undefined;
|
|
16
|
-
dispatchParent?: StepperEventDispatcher | undefined;
|
|
17
16
|
stepTerm?: string | undefined;
|
|
18
17
|
gap?: string | undefined;
|
|
19
18
|
justify?: string | undefined;
|
|
19
|
+
onNext?: ((locked: boolean, stepIndex: number) => void) | undefined;
|
|
20
|
+
onBack?: ((stepIndex: number) => void) | undefined;
|
|
21
|
+
onComplete?: ((stepIndex: number) => void) | undefined;
|
|
20
22
|
buttonBack?: string | undefined;
|
|
21
23
|
buttonBackType?: "button" | "reset" | "submit" | undefined;
|
|
22
24
|
buttonBackLabel?: string | undefined;
|
|
@@ -30,11 +30,29 @@ export let transitionInParams = { duration: 100 };
|
|
|
30
30
|
export let transitionOut = fade;
|
|
31
31
|
export let transitionOutParams = { duration: 100 };
|
|
32
32
|
let state = writable({ current: start, total: 0 });
|
|
33
|
+
async function onNext(locked, stepIndex) {
|
|
34
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
35
|
+
if (locked)
|
|
36
|
+
return;
|
|
37
|
+
$state.current++;
|
|
38
|
+
dispatch("next", { step: stepIndex, state: $state });
|
|
39
|
+
dispatch("step", { step: stepIndex, state: $state });
|
|
40
|
+
}
|
|
41
|
+
function onBack(stepIndex) {
|
|
42
|
+
$state.current--;
|
|
43
|
+
dispatch("back", { step: stepIndex, state: $state });
|
|
44
|
+
dispatch("step", { step: stepIndex, state: $state });
|
|
45
|
+
}
|
|
46
|
+
function onComplete(stepIndex) {
|
|
47
|
+
dispatch("complete", { step: stepIndex, state: $state });
|
|
48
|
+
}
|
|
33
49
|
setContext("state", state);
|
|
34
|
-
setContext("dispatchParent", dispatch);
|
|
35
50
|
setContext("stepTerm", stepTerm);
|
|
36
51
|
setContext("gap", gap);
|
|
37
52
|
setContext("justify", justify);
|
|
53
|
+
setContext("onNext", onNext);
|
|
54
|
+
setContext("onBack", onBack);
|
|
55
|
+
setContext("onComplete", onComplete);
|
|
38
56
|
setContext("buttonBack", buttonBack);
|
|
39
57
|
setContext("buttonBackType", buttonBackType);
|
|
40
58
|
setContext("buttonBackLabel", buttonBackLabel);
|
|
@@ -7,8 +7,8 @@ import { dynamicTransition } from "../../internal/transitions.js";
|
|
|
7
7
|
const dispatch = createEventDispatcher();
|
|
8
8
|
import { focusTrap } from "../../actions/FocusTrap/focusTrap.js";
|
|
9
9
|
import { getModalStore } from "./stores.js";
|
|
10
|
-
export let position = "items-center";
|
|
11
10
|
export let components = {};
|
|
11
|
+
export let position = "items-center";
|
|
12
12
|
export let background = "bg-surface-100-800-token";
|
|
13
13
|
export let width = "w-modal";
|
|
14
14
|
export let height = "h-auto";
|
|
@@ -22,7 +22,7 @@ export let buttonPositive = "variant-filled";
|
|
|
22
22
|
export let buttonTextCancel = "Cancel";
|
|
23
23
|
export let buttonTextConfirm = "Confirm";
|
|
24
24
|
export let buttonTextSubmit = "Submit";
|
|
25
|
-
export let regionBackdrop = "
|
|
25
|
+
export let regionBackdrop = "";
|
|
26
26
|
export let regionHeader = "text-2xl font-bold";
|
|
27
27
|
export let regionBody = "max-h-[200px] overflow-hidden";
|
|
28
28
|
export let regionFooter = "flex justify-end space-x-2";
|
|
@@ -31,8 +31,8 @@ export let transitionIn = fly;
|
|
|
31
31
|
export let transitionInParams = { duration: 150, opacity: 0, x: 0, y: 100 };
|
|
32
32
|
export let transitionOut = fly;
|
|
33
33
|
export let transitionOutParams = { duration: 150, opacity: 0, x: 0, y: 100 };
|
|
34
|
-
const cBackdrop = "fixed top-0 left-0 right-0 bottom-0
|
|
35
|
-
const cTransitionLayer = "w-full h-fit min-h-full
|
|
34
|
+
const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 bg-surface-backdrop-token p-4";
|
|
35
|
+
const cTransitionLayer = "w-full h-fit min-h-full overflow-y-auto flex justify-center";
|
|
36
36
|
const cModal = "block overflow-y-auto";
|
|
37
37
|
const cModalImage = "w-full h-auto";
|
|
38
38
|
let promptValue;
|
|
@@ -43,17 +43,35 @@ const buttonTextDefaults = {
|
|
|
43
43
|
};
|
|
44
44
|
let currentComponent;
|
|
45
45
|
let registeredInteractionWithBackdrop = false;
|
|
46
|
+
let modalElement;
|
|
47
|
+
let windowHeight;
|
|
48
|
+
let backdropOverflow = "overflow-y-hidden";
|
|
46
49
|
const modalStore = getModalStore();
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
+
$:
|
|
51
|
+
if ($modalStore.length)
|
|
52
|
+
handleModals($modalStore);
|
|
53
|
+
function handleModals(modals) {
|
|
50
54
|
if (modals[0].type === "prompt")
|
|
51
55
|
promptValue = modals[0].value;
|
|
52
56
|
buttonTextCancel = modals[0].buttonTextCancel || buttonTextDefaults.buttonTextCancel;
|
|
53
57
|
buttonTextConfirm = modals[0].buttonTextConfirm || buttonTextDefaults.buttonTextConfirm;
|
|
54
58
|
buttonTextSubmit = modals[0].buttonTextSubmit || buttonTextDefaults.buttonTextSubmit;
|
|
55
59
|
currentComponent = typeof modals[0].component === "string" ? components[modals[0].component] : modals[0].component;
|
|
56
|
-
}
|
|
60
|
+
}
|
|
61
|
+
function onModalHeightChange(modal) {
|
|
62
|
+
let modalHeight = modal?.clientHeight;
|
|
63
|
+
if (!modalHeight)
|
|
64
|
+
modalHeight = modal?.firstChild?.clientHeight;
|
|
65
|
+
if (!modalHeight)
|
|
66
|
+
return;
|
|
67
|
+
if (modalHeight > windowHeight) {
|
|
68
|
+
backdropOverflow = "overflow-y-auto";
|
|
69
|
+
} else {
|
|
70
|
+
backdropOverflow = "overflow-y-hidden";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
$:
|
|
74
|
+
onModalHeightChange(modalElement);
|
|
57
75
|
function onBackdropInteractionBegin(event) {
|
|
58
76
|
if (!(event.target instanceof Element))
|
|
59
77
|
return;
|
|
@@ -86,8 +104,12 @@ function onConfirm() {
|
|
|
86
104
|
}
|
|
87
105
|
function onPromptSubmit(event) {
|
|
88
106
|
event.preventDefault();
|
|
89
|
-
if ($modalStore[0].response)
|
|
90
|
-
$modalStore[0].
|
|
107
|
+
if ($modalStore[0].response) {
|
|
108
|
+
if ($modalStore[0].valueAttr !== void 0 && "type" in $modalStore[0].valueAttr && $modalStore[0].valueAttr.type === "number")
|
|
109
|
+
$modalStore[0].response(parseInt(promptValue));
|
|
110
|
+
else
|
|
111
|
+
$modalStore[0].response(promptValue);
|
|
112
|
+
}
|
|
91
113
|
modalStore.close();
|
|
92
114
|
}
|
|
93
115
|
function onKeyDown(event) {
|
|
@@ -131,7 +153,7 @@ $:
|
|
|
131
153
|
};
|
|
132
154
|
</script>
|
|
133
155
|
|
|
134
|
-
<svelte:window on:keydown={onKeyDown} />
|
|
156
|
+
<svelte:window bind:innerHeight={windowHeight} on:keydown={onKeyDown} />
|
|
135
157
|
|
|
136
158
|
{#if $modalStore.length > 0}
|
|
137
159
|
{#key $modalStore}
|
|
@@ -139,7 +161,7 @@ $:
|
|
|
139
161
|
<!-- FIXME: resolve a11y warnings -->
|
|
140
162
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
141
163
|
<div
|
|
142
|
-
class="modal-backdrop {classesBackdrop}"
|
|
164
|
+
class="modal-backdrop {classesBackdrop} {backdropOverflow}"
|
|
143
165
|
data-testid="modal-backdrop"
|
|
144
166
|
on:mousedown={onBackdropInteractionBegin}
|
|
145
167
|
on:mouseup={onBackdropInteractionEnd}
|
|
@@ -156,7 +178,14 @@ $:
|
|
|
156
178
|
>
|
|
157
179
|
{#if $modalStore[0].type !== 'component'}
|
|
158
180
|
<!-- Modal: Presets -->
|
|
159
|
-
<div
|
|
181
|
+
<div
|
|
182
|
+
class="modal {classesModal}"
|
|
183
|
+
bind:this={modalElement}
|
|
184
|
+
data-testid="modal"
|
|
185
|
+
role="dialog"
|
|
186
|
+
aria-modal="true"
|
|
187
|
+
aria-label={$modalStore[0].title ?? ''}
|
|
188
|
+
>
|
|
160
189
|
<!-- Header -->
|
|
161
190
|
{#if $modalStore[0]?.title}
|
|
162
191
|
<header class="modal-header {regionHeader}">{@html $modalStore[0].title}</header>
|
|
@@ -196,6 +225,7 @@ $:
|
|
|
196
225
|
<!-- Modal: Components -->
|
|
197
226
|
<!-- Note: keep `contents` class to allow widths from children -->
|
|
198
227
|
<div
|
|
228
|
+
bind:this={modalElement}
|
|
199
229
|
class="modal contents {$modalStore[0]?.modalClasses ?? ''}"
|
|
200
230
|
data-testid="modal-component"
|
|
201
231
|
role="dialog"
|
|
@@ -6,10 +6,10 @@ import type { ModalComponent } from './types.js';
|
|
|
6
6
|
declare class __sveltets_Render<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> {
|
|
7
7
|
props(): {
|
|
8
8
|
[x: string]: any;
|
|
9
|
-
/** Set the modal position within the backdrop container*/
|
|
10
|
-
position?: string | undefined;
|
|
11
9
|
/** Register a list of reusable component modals.*/
|
|
12
10
|
components?: Record<string, ModalComponent> | undefined;
|
|
11
|
+
/** Set the modal position within the backdrop container*/
|
|
12
|
+
position?: string | undefined;
|
|
13
13
|
/** Provide classes to style the modal background.*/
|
|
14
14
|
background?: string | undefined;
|
|
15
15
|
/** Provide classes to style the modal width.*/
|
|
@@ -36,7 +36,7 @@ declare class __sveltets_Render<TransitionIn extends Transition = FlyTransition,
|
|
|
36
36
|
buttonTextConfirm?: string | undefined;
|
|
37
37
|
/** Override the text for the Submit button.*/
|
|
38
38
|
buttonTextSubmit?: string | undefined;
|
|
39
|
-
/** Provide classes to
|
|
39
|
+
/** Provide arbitrary classes to the backdrop region.*/
|
|
40
40
|
regionBackdrop?: string | undefined;
|
|
41
41
|
/** Provide arbitrary classes to modal header region.*/
|
|
42
42
|
regionHeader?: string | undefined;
|
package/package.json
CHANGED