@marianmeres/stuic 1.72.0 → 1.73.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.
@@ -85,7 +85,8 @@ export function focusTrap(node, options = {}) {
85
85
  // Lifecycle
86
86
  return {
87
87
  update(options = {}) {
88
- options?.enabled ? queryElements(false) : cleanup();
88
+ enabled = !!options?.enabled;
89
+ enabled ? queryElements(false) : cleanup();
89
90
  },
90
91
  destroy() {
91
92
  cleanup();
@@ -0,0 +1,52 @@
1
+ <script>import { createEventDispatcher, onMount } from "svelte";
2
+ import { focusTrap } from "../../actions/focus-trap.js";
3
+ const dispatch = createEventDispatcher();
4
+ export let openOnMount = false;
5
+ export let closeOnOutsideClick = true;
6
+ export let closeOnEscape = true;
7
+ let _class = "";
8
+ export { _class as class };
9
+ export let style = "";
10
+ let _el;
11
+ let _open = !!openOnMount;
12
+ export const doToggle = () => _open = !_open;
13
+ export const doOpen = () => _open = true;
14
+ export const doClose = () => _open = false;
15
+ $:
16
+ _open ? _el?.showModal() : _el?.close();
17
+ $:
18
+ dispatch(_open ? "open" : "close");
19
+ export let isOpen = _open;
20
+ $:
21
+ isOpen = _open;
22
+ onMount(() => {
23
+ const _unsubs = [];
24
+ const _handleClose = (e) => doClose();
25
+ _el.addEventListener("close", _handleClose);
26
+ _unsubs.push(() => _el.removeEventListener("close", _handleClose));
27
+ const _handleCancel = (e) => e.preventDefault();
28
+ _el.addEventListener("cancel", _handleCancel);
29
+ _unsubs.push(() => _el.removeEventListener("cancel", _handleCancel));
30
+ const _handleKeyDown = (e) => closeOnEscape && e.key === "Escape" && doClose();
31
+ document.addEventListener("keydown", _handleKeyDown, true);
32
+ _unsubs.push(() => document.removeEventListener("keydown", _handleKeyDown, true));
33
+ const _handleClick = (e) => {
34
+ closeOnOutsideClick && /dialog/i.test(e.target?.tagName) && doClose();
35
+ };
36
+ _el.addEventListener("click", _handleClick);
37
+ _unsubs.push(() => _el.removeEventListener("click", _handleClick));
38
+ return () => _unsubs.forEach((fn) => fn());
39
+ });
40
+ </script>
41
+
42
+ <!--
43
+ NOTE: the below padding:0 is important because of otherwise not-trivial onOutsideClick implementation
44
+ -->
45
+ <dialog
46
+ bind:this={_el}
47
+ use:focusTrap={{ enabled: _open }}
48
+ style="{style ? `${style}; ` : ''}padding: 0 !important;"
49
+ class={_class}
50
+ >
51
+ <slot />
52
+ </dialog>
@@ -0,0 +1,29 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ openOnMount?: boolean | undefined;
5
+ closeOnOutsideClick?: boolean | undefined;
6
+ closeOnEscape?: boolean | undefined;
7
+ class?: string | undefined;
8
+ style?: string | undefined;
9
+ doToggle?: (() => boolean) | undefined;
10
+ doOpen?: (() => boolean) | undefined;
11
+ doClose?: (() => boolean) | undefined;
12
+ isOpen?: boolean | undefined;
13
+ };
14
+ events: {
15
+ [evt: string]: CustomEvent<any>;
16
+ };
17
+ slots: {
18
+ default: {};
19
+ };
20
+ };
21
+ export type ModalDialogProps = typeof __propDef.props;
22
+ export type ModalDialogEvents = typeof __propDef.events;
23
+ export type ModalDialogSlots = typeof __propDef.slots;
24
+ export default class ModalDialog extends SvelteComponent<ModalDialogProps, ModalDialogEvents, ModalDialogSlots> {
25
+ get doToggle(): () => boolean;
26
+ get doOpen(): () => boolean;
27
+ get doClose(): () => boolean;
28
+ }
29
+ export {};
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { default as FieldCheckbox, FieldCheckboxConfig, type FieldCheckboxConfig
14
14
  export { default as FieldRadios, FieldRadiosConfig, type FieldRadiosConfigClasses, type FieldRadiosConfigClassesBySize, } from './components/Input/FieldRadios.svelte';
15
15
  export { default as FieldSelect, FieldSelectConfig, type FieldSelectConfigClasses, type FieldSelectConfigClassesBySize, } from './components/Input/FieldSelect.svelte';
16
16
  export { default as Fieldset, FieldsetConfig, type FieldsetConfigClasses, } from './components/Input/Fieldset.svelte';
17
+ export { default as ModalDialog } from './components/ModalDialog/ModalDialog.svelte';
17
18
  export { createNotificationsStore, NOTIFICATION_EVENT, type NotiticationsCreateStoreOptions, type NotificationCreateParam, type Notification, type NotificationInput, type NotificationType, type NotificationOnEventHandler, type NotificationsSortOrder, type NotificationKnownClasses, } from './components/Notifications/notifications.js';
18
19
  export { default as Notifications, NotificationsConfig, } from './components/Notifications/Notifications.svelte';
19
20
  export { default as Popover } from './components/Popover/Popover.svelte';
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ export { default as FieldCheckbox, FieldCheckboxConfig, } from './components/Inp
24
24
  export { default as FieldRadios, FieldRadiosConfig, } from './components/Input/FieldRadios.svelte';
25
25
  export { default as FieldSelect, FieldSelectConfig, } from './components/Input/FieldSelect.svelte';
26
26
  export { default as Fieldset, FieldsetConfig, } from './components/Input/Fieldset.svelte';
27
+ export { default as ModalDialog } from './components/ModalDialog/ModalDialog.svelte';
27
28
  //
28
29
  export { createNotificationsStore, NOTIFICATION_EVENT, } from './components/Notifications/notifications.js';
29
30
  export { default as Notifications, NotificationsConfig, } from './components/Notifications/Notifications.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.72.0",
3
+ "version": "1.73.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",