@marianmeres/stuic 1.73.0 → 1.75.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.
@@ -1,6 +1,9 @@
1
- <script>import { createEventDispatcher, onMount } from "svelte";
1
+ <script context="module">import { createEventDispatcher, onMount } from "svelte";
2
2
  import { focusTrap } from "../../actions/focus-trap.js";
3
- const dispatch = createEventDispatcher();
3
+ import { writable } from "svelte/store";
4
+ </script>
5
+
6
+ <script>const dispatch = createEventDispatcher();
4
7
  export let openOnMount = false;
5
8
  export let closeOnOutsideClick = true;
6
9
  export let closeOnEscape = true;
@@ -9,29 +12,35 @@ export { _class as class };
9
12
  export let style = "";
10
13
  let _el;
11
14
  let _open = !!openOnMount;
12
- export const doToggle = () => _open = !_open;
13
- export const doOpen = () => _open = true;
14
- export const doClose = () => _open = false;
15
+ export function toggle() {
16
+ _open = !_open;
17
+ }
18
+ export function open() {
19
+ _open = true;
20
+ }
21
+ export function close() {
22
+ _open = false;
23
+ }
15
24
  $:
16
25
  _open ? _el?.showModal() : _el?.close();
17
26
  $:
18
27
  dispatch(_open ? "open" : "close");
19
- export let isOpen = _open;
28
+ export const isOpen = writable(_open);
20
29
  $:
21
- isOpen = _open;
30
+ $isOpen = _open;
22
31
  onMount(() => {
23
32
  const _unsubs = [];
24
- const _handleClose = (e) => doClose();
33
+ const _handleClose = (e) => close();
25
34
  _el.addEventListener("close", _handleClose);
26
35
  _unsubs.push(() => _el.removeEventListener("close", _handleClose));
27
36
  const _handleCancel = (e) => e.preventDefault();
28
37
  _el.addEventListener("cancel", _handleCancel);
29
38
  _unsubs.push(() => _el.removeEventListener("cancel", _handleCancel));
30
- const _handleKeyDown = (e) => closeOnEscape && e.key === "Escape" && doClose();
39
+ const _handleKeyDown = (e) => closeOnEscape && e.key === "Escape" && close();
31
40
  document.addEventListener("keydown", _handleKeyDown, true);
32
41
  _unsubs.push(() => document.removeEventListener("keydown", _handleKeyDown, true));
33
42
  const _handleClick = (e) => {
34
- closeOnOutsideClick && /dialog/i.test(e.target?.tagName) && doClose();
43
+ closeOnOutsideClick && /dialog/i.test(e.target?.tagName) && close();
35
44
  };
36
45
  _el.addEventListener("click", _handleClick);
37
46
  _unsubs.push(() => _el.removeEventListener("click", _handleClick));
@@ -1,4 +1,10 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ import { type Writable } from 'svelte/store';
3
+ export interface ModalDialogAPI {
4
+ open: () => void;
5
+ close: () => void;
6
+ isOpen: Writable<boolean>;
7
+ }
2
8
  declare const __propDef: {
3
9
  props: {
4
10
  openOnMount?: boolean | undefined;
@@ -6,10 +12,10 @@ declare const __propDef: {
6
12
  closeOnEscape?: boolean | undefined;
7
13
  class?: string | undefined;
8
14
  style?: string | undefined;
9
- doToggle?: (() => boolean) | undefined;
10
- doOpen?: (() => boolean) | undefined;
11
- doClose?: (() => boolean) | undefined;
12
- isOpen?: boolean | undefined;
15
+ toggle?: (() => void) | undefined;
16
+ open?: (() => void) | undefined;
17
+ close?: (() => void) | undefined;
18
+ isOpen?: Writable<boolean> | undefined;
13
19
  };
14
20
  events: {
15
21
  [evt: string]: CustomEvent<any>;
@@ -22,8 +28,9 @@ export type ModalDialogProps = typeof __propDef.props;
22
28
  export type ModalDialogEvents = typeof __propDef.events;
23
29
  export type ModalDialogSlots = typeof __propDef.slots;
24
30
  export default class ModalDialog extends SvelteComponent<ModalDialogProps, ModalDialogEvents, ModalDialogSlots> {
25
- get doToggle(): () => boolean;
26
- get doOpen(): () => boolean;
27
- get doClose(): () => boolean;
31
+ get toggle(): () => void;
32
+ get open(): () => void;
33
+ get close(): () => void;
34
+ get isOpen(): Writable<boolean>;
28
35
  }
29
36
  export {};
@@ -4,6 +4,7 @@ import { twMerge } from "tailwind-merge";
4
4
  import Thc from "../Thc/Thc.svelte";
5
5
  import X from "../X/X.svelte";
6
6
  import { notificationsDefaultIcons } from "./notifications-icons.js";
7
+ import { disableScrollHandling } from "$app/navigation";
7
8
  const X_POSITIONS = ["left", "center", "right"];
8
9
  const Y_POSITIONS = ["top", "center", "bottom"];
9
10
  const DEFAULT = {
@@ -129,64 +130,67 @@ const _iconFn = (o) => o.iconFn ?? defaultIcons?.[o.type];
129
130
  const _isFn = (v) => typeof v === "function";
130
131
  </script>
131
132
 
132
- <div class={_wrapClass} aria-live="assertive">
133
- <div class={_wrapInnerClass}>
134
- {#if $notifications.length}
135
- {#each $notifications as n}
136
- {@const iconFn = _iconFn(n)}
137
- <!-- use your own component -->
138
- {#if n?.component}
139
- <svelte:component
140
- this={n.component.component || n.component}
141
- {...n.component.props || {}}
142
- notification={n}
143
- {notifications}
144
- />
145
- {:else}
146
- <!-- svelte-ignore
133
+ {#if $notifications.length}
134
+ <dialog open>
135
+ <div class={_wrapClass}>
136
+ <div class={_wrapInnerClass}>
137
+ {#each $notifications as n}
138
+ {@const iconFn = _iconFn(n)}
139
+ <!-- use your own component -->
140
+ {#if n?.component}
141
+ <svelte:component
142
+ this={n.component.component || n.component}
143
+ {...n.component.props || {}}
144
+ notification={n}
145
+ {notifications}
146
+ />
147
+ {:else}
148
+ <!-- svelte-ignore
147
149
  a11y-click-events-have-key-events
148
150
  a11y-no-noninteractive-element-interactions
149
151
  a11y-mouse-events-have-key-events -->
150
- <div
151
- transition:fade|global={{ duration: 200 }}
152
- class={_boxClass(n)}
153
- class:cursor-pointer={typeof n.onClick === 'function'}
154
- data-notification-type={n.type}
155
- data-notification-multiple={n.count > 1 ? true : undefined}
156
- role="alert"
157
- on:mouseover={() => notifications.event(n.id, notifications.EVENT.MOUSEOVER)}
158
- on:mouseout={() => notifications.event(n.id, notifications.EVENT.MOUSEOUT)}
159
- on:click={() => notifications.event(n.id, notifications.EVENT.CLICK)}
160
- >
161
- {#if n.count > 1}
162
- <div class={_countClass(n)}>
163
- {n.count}
164
- </div>
165
- {/if}
152
+ <div
153
+ transition:fade|global={{ duration: 200 }}
154
+ class={_boxClass(n)}
155
+ class:cursor-pointer={typeof n.onClick === 'function'}
156
+ data-notification-type={n.type}
157
+ data-notification-multiple={n.count > 1 ? true : undefined}
158
+ role="alert"
159
+ on:mouseover={() =>
160
+ notifications.event(n.id, notifications.EVENT.MOUSEOVER)}
161
+ on:mouseout={() => notifications.event(n.id, notifications.EVENT.MOUSEOUT)}
162
+ on:click={() => notifications.event(n.id, notifications.EVENT.CLICK)}
163
+ >
164
+ {#if n.count > 1}
165
+ <div class={_countClass(n)}>
166
+ {n.count}
167
+ </div>
168
+ {/if}
166
169
 
167
- {#if _isFn(iconFn)}
168
- <div class={_iconClass(n)}>{@html iconFn()}</div>
169
- {/if}
170
+ {#if _isFn(iconFn)}
171
+ <div class={_iconClass(n)}>{@html iconFn()}</div>
172
+ {/if}
170
173
 
171
- <div class={_contentClass(n)}>
172
- <Thc
173
- thc={n.content}
174
- forceAsHtml={n.forceAsHtml ?? forceAsHtml}
175
- notification={n}
176
- {notifications}
177
- />
178
- </div>
174
+ <div class={_contentClass(n)}>
175
+ <Thc
176
+ thc={n.content}
177
+ forceAsHtml={n.forceAsHtml ?? forceAsHtml}
178
+ notification={n}
179
+ {notifications}
180
+ />
181
+ </div>
179
182
 
180
- <button
181
- class={_buttonClass(n)}
182
- aria-label={ariaCloseLabel}
183
- on:click|preventDefault|stopPropagation={() => notifications.remove(n.id)}
184
- >
185
- <X class={_xClass(n)} />
186
- </button>
187
- </div>
188
- {/if}
189
- {/each}
190
- {/if}
191
- </div>
192
- </div>
183
+ <button
184
+ class={_buttonClass(n)}
185
+ aria-label={ariaCloseLabel}
186
+ on:click|preventDefault|stopPropagation={() => notifications.remove(n.id)}
187
+ >
188
+ <X class={_xClass(n)} />
189
+ </button>
190
+ </div>
191
+ {/if}
192
+ {/each}
193
+ </div>
194
+ </div>
195
+ </dialog>
196
+ {/if}
package/dist/index.d.ts CHANGED
@@ -14,7 +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
+ export { default as ModalDialog, type ModalDialogAPI, } from './components/ModalDialog/ModalDialog.svelte';
18
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';
19
19
  export { default as Notifications, NotificationsConfig, } from './components/Notifications/Notifications.svelte';
20
20
  export { default as Popover } from './components/Popover/Popover.svelte';
package/dist/index.js CHANGED
@@ -24,7 +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
+ export { default as ModalDialog, } from './components/ModalDialog/ModalDialog.svelte';
28
28
  //
29
29
  export { createNotificationsStore, NOTIFICATION_EVENT, } from './components/Notifications/notifications.js';
30
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.73.0",
3
+ "version": "1.75.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",