@ims360/svelte-ivory 0.0.54 → 0.0.56
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/README.md +5 -0
- package/dist/components/layout/hiddenBackground/HiddenBackground.svelte +2 -2
- package/dist/components/layout/modal/Modal.svelte +4 -2
- package/dist/components/layout/modal/Modal.svelte.d.ts.map +1 -1
- package/dist/utils/actions/index.d.ts +1 -1
- package/dist/utils/actions/index.d.ts.map +1 -1
- package/dist/utils/actions/index.js +1 -1
- package/dist/utils/actions/shortcut.svelte.d.ts +10 -0
- package/dist/utils/actions/shortcut.svelte.d.ts.map +1 -0
- package/dist/utils/actions/shortcut.svelte.js +43 -0
- package/package.json +1 -1
- package/src/lib/components/layout/hiddenBackground/HiddenBackground.svelte +2 -2
- package/src/lib/components/layout/modal/Modal.svelte +4 -2
- package/src/lib/utils/actions/index.ts +1 -1
- package/src/lib/utils/actions/shortcut.svelte.ts +63 -0
- package/dist/utils/actions/shortcut.d.ts +0 -11
- package/dist/utils/actions/shortcut.d.ts.map +0 -1
- package/dist/utils/actions/shortcut.js +0 -25
- package/src/lib/utils/actions/shortcut.ts +0 -35
package/README.md
CHANGED
|
@@ -20,3 +20,8 @@ _You may need to adjust the path if your `app.css` is not located in `/src`_
|
|
|
20
20
|
- [x] Basic layout components (modal, tabs, popover, etc.)
|
|
21
21
|
- [x] Table
|
|
22
22
|
- [ ] Input components
|
|
23
|
+
|
|
24
|
+
## TODOs
|
|
25
|
+
|
|
26
|
+
- [ ] Bindings to exported functions
|
|
27
|
+
- [ ] Replace `<Portal>` with `<dialog>` element in Modal, Popover and Drawer
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
}: Props = $props();
|
|
54
54
|
|
|
55
55
|
function close() {
|
|
56
|
-
if (preventClosing) return;
|
|
57
56
|
b_open = false;
|
|
58
57
|
}
|
|
59
58
|
|
|
@@ -70,7 +69,10 @@
|
|
|
70
69
|
{#if b_open}
|
|
71
70
|
<Portal>
|
|
72
71
|
<HiddenBackground
|
|
73
|
-
onclose={
|
|
72
|
+
onclose={() => {
|
|
73
|
+
if (preventClosing) return;
|
|
74
|
+
close();
|
|
75
|
+
}}
|
|
74
76
|
class="flex h-full w-full flex-col items-center justify-start p-8 lg:p-12 xl:p-16"
|
|
75
77
|
>
|
|
76
78
|
{#if modal}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/layout/modal/Modal.svelte.ts"],"names":[],"mappings":"AAGI,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKrE,sFAAsF;AACtF,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG;IACvC,iEAAiE;IACjE,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,wCAAwC;IACxC,MAAM,EAAE,OAAO,CAAC;IAChB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qEAAqE;IACrE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE,UAAU,KAAM,SAAQ,UAAU;IAC9B,sGAAsG;IACtG,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"Modal.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/layout/modal/Modal.svelte.ts"],"names":[],"mappings":"AAGI,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKrE,sFAAsF;AACtF,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG;IACvC,iEAAiE;IACjE,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,wCAAwC;IACxC,MAAM,EAAE,OAAO,CAAC;IAChB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qEAAqE;IACrE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE,UAAU,KAAM,SAAQ,UAAU;IAC9B,sGAAsG;IACtG,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAwFL,oFAAoF;AACpF,QAAA,MAAM,KAAK,iDAAwC,CAAC;AACpD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
|
|
@@ -2,6 +2,6 @@ export { clickOutside } from './clickOutside';
|
|
|
2
2
|
export { focusTrap } from './focusTrap';
|
|
3
3
|
export { portal } from './portal';
|
|
4
4
|
export { resize } from './resize';
|
|
5
|
-
export { shortcut } from './shortcut';
|
|
5
|
+
export { shortcut } from './shortcut.svelte';
|
|
6
6
|
export { onFirstVisible } from './visible';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -2,5 +2,5 @@ export { clickOutside } from './clickOutside';
|
|
|
2
2
|
export { focusTrap } from './focusTrap';
|
|
3
3
|
export { portal } from './portal';
|
|
4
4
|
export { resize } from './resize';
|
|
5
|
-
export { shortcut } from './shortcut';
|
|
5
|
+
export { shortcut } from './shortcut.svelte';
|
|
6
6
|
export { onFirstVisible } from './visible';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Attachment } from 'svelte/attachments';
|
|
2
|
+
export interface ShortcutParams {
|
|
3
|
+
alt?: boolean;
|
|
4
|
+
shift?: boolean;
|
|
5
|
+
control?: boolean;
|
|
6
|
+
code: string;
|
|
7
|
+
callback: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function shortcut(params: ShortcutParams): Attachment;
|
|
10
|
+
//# sourceMappingURL=shortcut.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcut.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/actions/shortcut.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,IAAI,CAAC;CACxB;AA4CD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,UAAU,CAQ3D"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { browser } from '$app/environment';
|
|
2
|
+
import { pseudoRandomId } from '../functions';
|
|
3
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
4
|
+
const callbacks = new Map();
|
|
5
|
+
function setupListener() {
|
|
6
|
+
if (!browser)
|
|
7
|
+
return;
|
|
8
|
+
window.addEventListener('keydown', (e) => {
|
|
9
|
+
const key = mapKey({
|
|
10
|
+
code: e.code,
|
|
11
|
+
alt: e.altKey,
|
|
12
|
+
shift: e.shiftKey,
|
|
13
|
+
control: e.ctrlKey
|
|
14
|
+
});
|
|
15
|
+
const value = callbacks.get(key);
|
|
16
|
+
if (!value || value.length === 0)
|
|
17
|
+
return;
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
e.stopPropagation();
|
|
20
|
+
value[value.length - 1].callback();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
setupListener();
|
|
24
|
+
function mapKey(config) {
|
|
25
|
+
return `${config.alt ? 'alt' : ''}${config.shift ? 'shift' : ''}${config.control ? 'ctrl' : ''}${config.code}`;
|
|
26
|
+
}
|
|
27
|
+
function registerCallback(config) {
|
|
28
|
+
const key = mapKey(config);
|
|
29
|
+
callbacks.set(key, [...(callbacks.get(key) || []), config]);
|
|
30
|
+
}
|
|
31
|
+
function unregisterCallback(config) {
|
|
32
|
+
const key = mapKey(config);
|
|
33
|
+
callbacks.set(key, callbacks.get(key)?.filter((c) => c.id !== config.id) ?? []);
|
|
34
|
+
}
|
|
35
|
+
export function shortcut(params) {
|
|
36
|
+
const id = pseudoRandomId();
|
|
37
|
+
return (_node) => {
|
|
38
|
+
registerCallback({ ...params, id });
|
|
39
|
+
return () => {
|
|
40
|
+
unregisterCallback({ ...params, id });
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
}: Props = $props();
|
|
54
54
|
|
|
55
55
|
function close() {
|
|
56
|
-
if (preventClosing) return;
|
|
57
56
|
b_open = false;
|
|
58
57
|
}
|
|
59
58
|
|
|
@@ -70,7 +69,10 @@
|
|
|
70
69
|
{#if b_open}
|
|
71
70
|
<Portal>
|
|
72
71
|
<HiddenBackground
|
|
73
|
-
onclose={
|
|
72
|
+
onclose={() => {
|
|
73
|
+
if (preventClosing) return;
|
|
74
|
+
close();
|
|
75
|
+
}}
|
|
74
76
|
class="flex h-full w-full flex-col items-center justify-start p-8 lg:p-12 xl:p-16"
|
|
75
77
|
>
|
|
76
78
|
{#if modal}
|
|
@@ -2,5 +2,5 @@ export { clickOutside } from './clickOutside';
|
|
|
2
2
|
export { focusTrap } from './focusTrap';
|
|
3
3
|
export { portal } from './portal';
|
|
4
4
|
export { resize } from './resize';
|
|
5
|
-
export { shortcut } from './shortcut';
|
|
5
|
+
export { shortcut } from './shortcut.svelte';
|
|
6
6
|
export { onFirstVisible } from './visible';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { browser } from '$app/environment';
|
|
2
|
+
import type { Attachment } from 'svelte/attachments';
|
|
3
|
+
import { pseudoRandomId } from '../functions';
|
|
4
|
+
|
|
5
|
+
export interface ShortcutParams {
|
|
6
|
+
alt?: boolean;
|
|
7
|
+
shift?: boolean;
|
|
8
|
+
control?: boolean;
|
|
9
|
+
code: string;
|
|
10
|
+
callback: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
14
|
+
const callbacks: Map<string, IdShortcutParams[]> = new Map();
|
|
15
|
+
|
|
16
|
+
function setupListener() {
|
|
17
|
+
if (!browser) return;
|
|
18
|
+
window.addEventListener('keydown', (e) => {
|
|
19
|
+
const key = mapKey({
|
|
20
|
+
code: e.code,
|
|
21
|
+
alt: e.altKey,
|
|
22
|
+
shift: e.shiftKey,
|
|
23
|
+
control: e.ctrlKey
|
|
24
|
+
});
|
|
25
|
+
const value = callbacks.get(key);
|
|
26
|
+
if (!value || value.length === 0) return;
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
e.stopPropagation();
|
|
29
|
+
value[value.length - 1].callback();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setupListener();
|
|
34
|
+
|
|
35
|
+
function mapKey(config: Omit<ShortcutParams, 'callback'>) {
|
|
36
|
+
return `${config.alt ? 'alt' : ''}${config.shift ? 'shift' : ''}${
|
|
37
|
+
config.control ? 'ctrl' : ''
|
|
38
|
+
}${config.code}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function registerCallback(config: IdShortcutParams) {
|
|
42
|
+
const key = mapKey(config);
|
|
43
|
+
callbacks.set(key, [...(callbacks.get(key) || []), config]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function unregisterCallback(config: IdShortcutParams) {
|
|
47
|
+
const key = mapKey(config);
|
|
48
|
+
callbacks.set(key, callbacks.get(key)?.filter((c) => c.id !== config.id) ?? []);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface IdShortcutParams extends ShortcutParams {
|
|
52
|
+
id: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function shortcut(params: ShortcutParams): Attachment {
|
|
56
|
+
const id = pseudoRandomId();
|
|
57
|
+
return (_node: Element) => {
|
|
58
|
+
registerCallback({ ...params, id });
|
|
59
|
+
return () => {
|
|
60
|
+
unregisterCallback({ ...params, id });
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const shortcut: (node: HTMLElement, params?: {
|
|
2
|
-
alt?: boolean;
|
|
3
|
-
shift?: boolean;
|
|
4
|
-
control?: boolean;
|
|
5
|
-
code: string;
|
|
6
|
-
callback: () => void;
|
|
7
|
-
}) => {
|
|
8
|
-
update: () => void;
|
|
9
|
-
destroy: () => void;
|
|
10
|
-
} | undefined;
|
|
11
|
-
//# sourceMappingURL=shortcut.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shortcut.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/actions/shortcut.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GACjB,MAAM,WAAW,EACjB,SAAS;IACL,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,IAAI,CAAC;CACxB;;;aA0BJ,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export const shortcut = (node, params) => {
|
|
2
|
-
if (!params)
|
|
3
|
-
return;
|
|
4
|
-
let handler;
|
|
5
|
-
const removeHandler = () => window.removeEventListener('keydown', handler);
|
|
6
|
-
const setHandler = () => {
|
|
7
|
-
removeHandler();
|
|
8
|
-
handler = (e) => {
|
|
9
|
-
if (!!params.alt != e.altKey ||
|
|
10
|
-
!!params.shift != e.shiftKey ||
|
|
11
|
-
!!params.control != (e.ctrlKey || e.metaKey) ||
|
|
12
|
-
params.code != e.code)
|
|
13
|
-
return;
|
|
14
|
-
e.preventDefault();
|
|
15
|
-
e.stopPropagation();
|
|
16
|
-
params.callback();
|
|
17
|
-
};
|
|
18
|
-
window.addEventListener('keydown', handler);
|
|
19
|
-
};
|
|
20
|
-
setHandler();
|
|
21
|
-
return {
|
|
22
|
-
update: setHandler,
|
|
23
|
-
destroy: removeHandler
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const shortcut = (
|
|
2
|
-
node: HTMLElement,
|
|
3
|
-
params?: {
|
|
4
|
-
alt?: boolean;
|
|
5
|
-
shift?: boolean;
|
|
6
|
-
control?: boolean;
|
|
7
|
-
code: string;
|
|
8
|
-
callback: () => void;
|
|
9
|
-
}
|
|
10
|
-
) => {
|
|
11
|
-
if (!params) return;
|
|
12
|
-
let handler: (e: KeyboardEvent) => void;
|
|
13
|
-
const removeHandler = () => window.removeEventListener('keydown', handler);
|
|
14
|
-
const setHandler = () => {
|
|
15
|
-
removeHandler();
|
|
16
|
-
handler = (e) => {
|
|
17
|
-
if (
|
|
18
|
-
!!params.alt != e.altKey ||
|
|
19
|
-
!!params.shift != e.shiftKey ||
|
|
20
|
-
!!params.control != (e.ctrlKey || e.metaKey) ||
|
|
21
|
-
params.code != e.code
|
|
22
|
-
)
|
|
23
|
-
return;
|
|
24
|
-
e.preventDefault();
|
|
25
|
-
e.stopPropagation();
|
|
26
|
-
params.callback();
|
|
27
|
-
};
|
|
28
|
-
window.addEventListener('keydown', handler);
|
|
29
|
-
};
|
|
30
|
-
setHandler();
|
|
31
|
-
return {
|
|
32
|
-
update: setHandler,
|
|
33
|
-
destroy: removeHandler
|
|
34
|
-
};
|
|
35
|
-
};
|