@juspay/svelte-ui-components 4.56.0 → 4.57.1

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.
@@ -21,8 +21,11 @@
21
21
  // Not $state: it's read-once bookkeeping for the mount/destroy pair, not
22
22
  // something the template reacts to.
23
23
  let previouslyFocusedElement: HTMLElement | null = null;
24
+ let mountedRestoreFocusTo: ModalProperties['restoreFocusTo'];
25
+ let restoreFocusDocument: Document | null = null;
24
26
 
25
27
  let {
28
+ restoreFocusTo,
26
29
  containFocus = false,
27
30
  size = 'fit-content',
28
31
  align = 'center',
@@ -232,6 +235,9 @@
232
235
 
233
236
  onMount(() => {
234
237
  const ownerDocument = modalContent?.ownerDocument ?? document;
238
+ // Keep this open instance's option, not a newer presentation's prop.
239
+ mountedRestoreFocusTo = restoreFocusTo;
240
+ restoreFocusDocument = ownerDocument;
235
241
  ownerDocument.addEventListener('focusin', handleFocusIn, true);
236
242
  releaseFocusGuard = () => ownerDocument.removeEventListener('focusin', handleFocusIn, true);
237
243
  releaseDismissible = registerDismissible({
@@ -284,8 +290,30 @@
284
290
  // isConnected: the trigger can have been unmounted while the modal was
285
291
  // open (e.g. the page navigated), and .focus() on a detached element is
286
292
  // a silent no-op at best.
287
- if (previouslyFocusedElement !== null && previouslyFocusedElement.isConnected) {
288
- previouslyFocusedElement.focus();
293
+ if (typeof mountedRestoreFocusTo === 'undefined') {
294
+ if (previouslyFocusedElement !== null && previouslyFocusedElement.isConnected) {
295
+ previouslyFocusedElement.focus();
296
+ }
297
+ } else {
298
+ try {
299
+ const target =
300
+ typeof mountedRestoreFocusTo === 'function'
301
+ ? mountedRestoreFocusTo()
302
+ : mountedRestoreFocusTo;
303
+ const OwnerNode = restoreFocusDocument?.defaultView?.Node;
304
+ if (
305
+ target !== null &&
306
+ target.ownerDocument === restoreFocusDocument &&
307
+ target.namespaceURI === 'http://www.w3.org/1999/xhtml' &&
308
+ target.isConnected &&
309
+ typeof OwnerNode === 'function' &&
310
+ OwnerNode.prototype.getRootNode.call(target, { composed: true }) === restoreFocusDocument
311
+ ) {
312
+ target.focus();
313
+ }
314
+ } catch {
315
+ // An explicit owner can withdraw its target; never restore the old opener instead.
316
+ }
289
317
  }
290
318
  });
291
319
  </script>
@@ -20,6 +20,15 @@ export type ModalEntryAnimation = 'fade' | 'slide-up' | 'slide-down';
20
20
  export type ModalRole = 'dialog' | 'alertdialog';
21
21
  export type ModalProperties = OptionalModalProperties & ModalEventProperties;
22
22
  export type OptionalModalProperties = {
23
+ /**
24
+ * Focus destination snapshotted once per mounted open. Omit to restore the
25
+ * previously focused element unchanged. A getter resolves once at actual
26
+ * teardown, after dismissal/scroll cleanup; it must only return a target.
27
+ * Explicit null, a null/throwing getter, or a disconnected/foreign-document
28
+ * element skips restoration without falling back. Changes while mounted
29
+ * apply to the next mount. Custom elements accept property assignment only.
30
+ */
31
+ restoreFocusTo?: HTMLElement | (() => HTMLElement | null) | null;
23
32
  /** Pull programmatic/background focus back into this modal while it owns the foreground. */
24
33
  containFocus?: boolean;
25
34
  /** Scroll owner, resolved once per open span. Omit for the overlay's ownerDocument.body.
@@ -8,7 +8,8 @@
8
8
  import { toStore } from 'svelte/store';
9
9
  import Button from '../Button/Button.svelte';
10
10
  import { focusTrapTabTarget, getActiveElement } from '../_interaction/focus';
11
- import { registerDismissible } from '../_interaction/dismissal';
11
+ import { registerDismissible, isTopmostDismissible } from '../_interaction/dismissal';
12
+ import { composedParent } from '../_interaction/focusable';
12
13
 
13
14
  let {
14
15
  open = $bindable(false),
@@ -155,10 +156,12 @@
155
156
  let scrollLockNode: HTMLElement | null = null;
156
157
  let releaseScrollLock: (() => void) | null = null;
157
158
  let scrollLockSpanEnded = false;
159
+ let reopenFocusRevision = 0;
158
160
 
159
161
  onMount(() =>
160
162
  toStore(() => open).subscribe((isOpen) => {
161
163
  if (!isOpen) {
164
+ reopenFocusRevision += 1;
162
165
  scrollLockSpanEnded = true;
163
166
  } else if (scrollLockSpanEnded && scrollLockNode !== null) {
164
167
  // Reversing an outro reuses the action. Resolve the next logical open's
@@ -169,6 +172,34 @@
169
172
  );
170
173
  releaseScrollLock?.();
171
174
  releaseScrollLock = releaseNext;
175
+ const node = scrollLockNode;
176
+ const panel = untrack(() => sheetPanel);
177
+ const revision = ++reopenFocusRevision;
178
+ void tick().then(() => {
179
+ if (
180
+ revision !== reopenFocusRevision ||
181
+ !open ||
182
+ scrollLockNode !== node ||
183
+ sheetPanel !== panel ||
184
+ panel === null ||
185
+ !node.isConnected ||
186
+ !panel.isConnected ||
187
+ !isTopmostDismissible(panel)
188
+ ) {
189
+ return;
190
+ }
191
+ // Keep focus/selection already owned through slot or shadow projection.
192
+ for (
193
+ let current = getActiveElement(panel);
194
+ current !== null;
195
+ current = composedParent(current)
196
+ ) {
197
+ if (current === panel) {
198
+ return;
199
+ }
200
+ }
201
+ panel.focus();
202
+ });
172
203
  }
173
204
  })
174
205
  );
@@ -201,6 +232,7 @@
201
232
  return {
202
233
  destroy() {
203
234
  active = false;
235
+ reopenFocusRevision += 1;
204
236
  releaseDismissible();
205
237
  releaseScrollLock?.();
206
238
  releaseScrollLock = null;
package/dist-wc/index.js CHANGED
@@ -22313,12 +22313,12 @@ var root_1$50 = /* @__PURE__ */ from_html("<button type=\"button\" class=\"modal
22313
22313
  };
22314
22314
  function Modal(e, t) {
22315
22315
  push(t, !0), append_styles$1(e, $$css$103);
22316
- let n = /* @__PURE__ */ state(null), i = /* @__PURE__ */ state(null), a = /* @__PURE__ */ state(null), o = /* @__PURE__ */ state(!1), s = null, c = prop(t, "containFocus", 7, !1), l = prop(t, "size", 7, "fit-content"), u = prop(t, "align", 7, "center"), f = prop(t, "showOverlay", 7, !0), p = prop(t, "supportHardwareBackPress", 7, !1), h = prop(t, "enableTransition", 7, !0), S = prop(t, "transitionType", 7, "ALL"), C = prop(t, "entryAnimation", 7), k = prop(t, "header", 23, () => ({})), R = prop(t, "footer", 7), te = prop(t, "debounceTime", 7, 700), ne = prop(t, "leftImageTestId", 7), G = prop(t, "leftImageAriaLabel", 7), re = prop(t, "testId", 7), be = prop(t, "content", 7), Me = prop(t, "footerSnippet", 7), Re = prop(t, "onclose", 7), Ue = prop(t, "onheaderrightimageclick", 7), it = prop(t, "onheaderleftimageclick", 7), at = prop(t, "onprimarybuttonclick", 7), ot = prop(t, "onsecondarybuttonclick", 7), ct = prop(t, "onoverlayclick", 7), lt = prop(t, "onkeydown", 7), ut = prop(t, "ondismiss", 7), dt = prop(t, "classes", 7), ft = prop(t, "overlayBackdropFilter", 7), pt = prop(t, "overlayFadeIn", 7, !1), mt = prop(t, "usePortal", 7, !1), ht = prop(t, "lockScroll", 7, !0), gt = prop(t, "scrollContainer", 7), _t = prop(t, "autoDismissAfter", 7, null), vt = prop(t, "ariaLabel", 7), yt = prop(t, "ariaDescribedby", 7), bt = prop(t, "role", 7), xt = prop(t, "overlayAriaLabel", 7), St = /* @__PURE__ */ user_derived(() => typeof ct() == "function" || typeof ut() == "function"), Ct = null, wt = createDebouncer(() => te()), Tt = (e) => {
22316
+ let n = /* @__PURE__ */ state(null), i = /* @__PURE__ */ state(null), a = /* @__PURE__ */ state(null), o = /* @__PURE__ */ state(!1), s = null, c, l = null, u = prop(t, "restoreFocusTo", 7), f = prop(t, "containFocus", 7, !1), p = prop(t, "size", 7, "fit-content"), h = prop(t, "align", 7, "center"), S = prop(t, "showOverlay", 7, !0), C = prop(t, "supportHardwareBackPress", 7, !1), k = prop(t, "enableTransition", 7, !0), R = prop(t, "transitionType", 7, "ALL"), te = prop(t, "entryAnimation", 7), ne = prop(t, "header", 23, () => ({})), G = prop(t, "footer", 7), re = prop(t, "debounceTime", 7, 700), be = prop(t, "leftImageTestId", 7), Me = prop(t, "leftImageAriaLabel", 7), Re = prop(t, "testId", 7), Ue = prop(t, "content", 7), it = prop(t, "footerSnippet", 7), at = prop(t, "onclose", 7), ot = prop(t, "onheaderrightimageclick", 7), ct = prop(t, "onheaderleftimageclick", 7), lt = prop(t, "onprimarybuttonclick", 7), ut = prop(t, "onsecondarybuttonclick", 7), dt = prop(t, "onoverlayclick", 7), ft = prop(t, "onkeydown", 7), pt = prop(t, "ondismiss", 7), mt = prop(t, "classes", 7), ht = prop(t, "overlayBackdropFilter", 7), gt = prop(t, "overlayFadeIn", 7, !1), _t = prop(t, "usePortal", 7, !1), vt = prop(t, "lockScroll", 7, !0), yt = prop(t, "scrollContainer", 7), bt = prop(t, "autoDismissAfter", 7, null), xt = prop(t, "ariaLabel", 7), St = prop(t, "ariaDescribedby", 7), Ct = prop(t, "role", 7), wt = prop(t, "overlayAriaLabel", 7), Tt = /* @__PURE__ */ user_derived(() => typeof dt() == "function" || typeof pt() == "function"), Et = null, Dt = createDebouncer(() => re()), Ot = (e) => {
22317
22317
  let t = e.getRootNode();
22318
22318
  return t instanceof ShadowRoot ? t : document.body;
22319
- }, Et = (e, t) => {
22319
+ }, kt = (e, t) => {
22320
22320
  if (!t.usePortal || typeof document > "u" || !document.body) return;
22321
- let n = Tt(e);
22321
+ let n = Ot(e);
22322
22322
  return n.appendChild(e), {
22323
22323
  update(t) {
22324
22324
  t.usePortal && e.parentNode !== n && n.appendChild(e);
@@ -22327,24 +22327,24 @@ function Modal(e, t) {
22327
22327
  e.parentNode?.removeChild(e);
22328
22328
  }
22329
22329
  };
22330
- }, Dt = () => {
22331
- set(o, !0), wt(() => {
22332
- Re()?.(), ut()?.();
22330
+ }, At = () => {
22331
+ set(o, !0), Dt(() => {
22332
+ at()?.(), pt()?.();
22333
22333
  });
22334
- }, Ot = (e) => {
22335
- Ue()?.(e);
22336
- }, kt = (e) => {
22337
- it()?.(e);
22338
- }, At = (e) => {
22339
- at()?.(e);
22340
22334
  }, jt = (e) => {
22341
22335
  ot()?.(e);
22342
22336
  }, Mt = (e) => {
22343
- (e.target === get(n) || e.target === get(i)) && wt(() => {
22344
- ct()?.(), ut()?.();
22345
- });
22337
+ ct()?.(e);
22346
22338
  }, Nt = (e) => {
22347
- if (lt()?.(e), e?.key === "Tab") {
22339
+ lt()?.(e);
22340
+ }, Pt = (e) => {
22341
+ ut()?.(e);
22342
+ }, It = (e) => {
22343
+ (e.target === get(n) || e.target === get(i)) && Dt(() => {
22344
+ dt()?.(), pt()?.();
22345
+ });
22346
+ }, Lt = (e) => {
22347
+ if (ft()?.(e), e?.key === "Tab") {
22348
22348
  let t = focusTrapTabTarget({
22349
22349
  container: get(a),
22350
22350
  activeElement: getActiveElement(get(a)),
@@ -22352,268 +22352,278 @@ function Modal(e, t) {
22352
22352
  });
22353
22353
  t !== null && (e.preventDefault(), t.focus());
22354
22354
  }
22355
- }, Pt = () => {
22356
- wt(() => {
22357
- ct()?.(), ut()?.();
22355
+ }, Rt = () => {
22356
+ Dt(() => {
22357
+ dt()?.(), pt()?.();
22358
22358
  });
22359
- }, It = (e) => {
22360
- (e.key === "Enter" || e.key === " ") && (e.preventDefault(), it()?.(new MouseEvent("click")));
22361
- }, Lt = (e) => {
22362
- (e.key === "Enter" || e.key === " ") && (e.preventDefault(), Ue()?.(new MouseEvent("click")));
22363
- }, Rt = null, zt = null, Bt = null, Ht = (e) => {
22364
- c() && get(a) && isTopmostDismissible(get(a)) && !eventHitsInside(get(a), e) && focusEntryPoint(get(a));
22359
+ }, zt = (e) => {
22360
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), ct()?.(new MouseEvent("click")));
22361
+ }, Bt = (e) => {
22362
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), ot()?.(new MouseEvent("click")));
22363
+ }, Ht = null, Gt = null, qt = null, Zt = (e) => {
22364
+ f() && get(a) && isTopmostDismissible(get(a)) && !eventHitsInside(get(a), e) && focusEntryPoint(get(a));
22365
22365
  };
22366
22366
  onMount(() => {
22367
22367
  let e = get(a)?.ownerDocument ?? document;
22368
- e.addEventListener("focusin", Ht, !0), Bt = () => e.removeEventListener("focusin", Ht, !0), zt = registerDismissible({
22368
+ c = u(), l = e, e.addEventListener("focusin", Zt, !0), qt = () => e.removeEventListener("focusin", Zt, !0), Gt = registerDismissible({
22369
22369
  element: () => get(a),
22370
- onEscape: Pt
22371
- }), ht() && (Rt = acquireScrollLock(resolveScrollContainer(get(a), gt()))), typeof _t() == "number" && (Ct = setTimeout(() => Re()?.(), _t())), p() && (history.pushState(null, "", window.location.href), window.addEventListener("popstate", Dt)), tick().then(() => {
22370
+ onEscape: Rt
22371
+ }), vt() && (Ht = acquireScrollLock(resolveScrollContainer(get(a), yt()))), typeof bt() == "number" && (Et = setTimeout(() => at()?.(), bt())), C() && (history.pushState(null, "", window.location.href), window.addEventListener("popstate", At)), tick().then(() => {
22372
22372
  let e = getActiveElement(get(a));
22373
22373
  s = e instanceof HTMLElement ? e : null, focusEntryPoint(get(a));
22374
22374
  });
22375
22375
  }), onDestroy(() => {
22376
- Bt?.(), Bt = null, zt?.(), zt = null, Ct !== null && clearTimeout(Ct), typeof window < "u" && (Rt?.(), Rt = null, p() && (get(o) || history.back(), window.removeEventListener("popstate", Dt))), s !== null && s.isConnected && s.focus();
22376
+ if (qt?.(), qt = null, Gt?.(), Gt = null, Et !== null && clearTimeout(Et), typeof window < "u" && (Ht?.(), Ht = null, C() && (get(o) || history.back(), window.removeEventListener("popstate", At))), c === void 0) s !== null && s.isConnected && s.focus();
22377
+ else try {
22378
+ let e = typeof c == "function" ? c() : c, t = l?.defaultView?.Node;
22379
+ e !== null && e.ownerDocument === l && e.namespaceURI === "http://www.w3.org/1999/xhtml" && e.isConnected && typeof t == "function" && t.prototype.getRootNode.call(e, { composed: !0 }) === l && e.focus();
22380
+ } catch {}
22377
22381
  });
22378
- var Gt = {
22382
+ var Qt = {
22383
+ get restoreFocusTo() {
22384
+ return u();
22385
+ },
22386
+ set restoreFocusTo(e) {
22387
+ u(e), flushSync();
22388
+ },
22379
22389
  get containFocus() {
22380
- return c();
22390
+ return f();
22381
22391
  },
22382
22392
  set containFocus(e = !1) {
22383
- c(e), flushSync();
22393
+ f(e), flushSync();
22384
22394
  },
22385
22395
  get size() {
22386
- return l();
22396
+ return p();
22387
22397
  },
22388
22398
  set size(e = "fit-content") {
22389
- l(e), flushSync();
22399
+ p(e), flushSync();
22390
22400
  },
22391
22401
  get align() {
22392
- return u();
22402
+ return h();
22393
22403
  },
22394
22404
  set align(e = "center") {
22395
- u(e), flushSync();
22405
+ h(e), flushSync();
22396
22406
  },
22397
22407
  get showOverlay() {
22398
- return f();
22408
+ return S();
22399
22409
  },
22400
22410
  set showOverlay(e = !0) {
22401
- f(e), flushSync();
22411
+ S(e), flushSync();
22402
22412
  },
22403
22413
  get supportHardwareBackPress() {
22404
- return p();
22414
+ return C();
22405
22415
  },
22406
22416
  set supportHardwareBackPress(e = !1) {
22407
- p(e), flushSync();
22417
+ C(e), flushSync();
22408
22418
  },
22409
22419
  get enableTransition() {
22410
- return h();
22420
+ return k();
22411
22421
  },
22412
22422
  set enableTransition(e = !0) {
22413
- h(e), flushSync();
22423
+ k(e), flushSync();
22414
22424
  },
22415
22425
  get transitionType() {
22416
- return S();
22426
+ return R();
22417
22427
  },
22418
22428
  set transitionType(e = "ALL") {
22419
- S(e), flushSync();
22429
+ R(e), flushSync();
22420
22430
  },
22421
22431
  get entryAnimation() {
22422
- return C();
22432
+ return te();
22423
22433
  },
22424
22434
  set entryAnimation(e) {
22425
- C(e), flushSync();
22435
+ te(e), flushSync();
22426
22436
  },
22427
22437
  get header() {
22428
- return k();
22438
+ return ne();
22429
22439
  },
22430
22440
  set header(e = {}) {
22431
- k(e), flushSync();
22441
+ ne(e), flushSync();
22432
22442
  },
22433
22443
  get footer() {
22434
- return R();
22444
+ return G();
22435
22445
  },
22436
22446
  set footer(e) {
22437
- R(e), flushSync();
22447
+ G(e), flushSync();
22438
22448
  },
22439
22449
  get debounceTime() {
22440
- return te();
22450
+ return re();
22441
22451
  },
22442
22452
  set debounceTime(e = 700) {
22443
- te(e), flushSync();
22453
+ re(e), flushSync();
22444
22454
  },
22445
22455
  get leftImageTestId() {
22446
- return ne();
22456
+ return be();
22447
22457
  },
22448
22458
  set leftImageTestId(e) {
22449
- ne(e), flushSync();
22459
+ be(e), flushSync();
22450
22460
  },
22451
22461
  get leftImageAriaLabel() {
22452
- return G();
22462
+ return Me();
22453
22463
  },
22454
22464
  set leftImageAriaLabel(e) {
22455
- G(e), flushSync();
22465
+ Me(e), flushSync();
22456
22466
  },
22457
22467
  get testId() {
22458
- return re();
22468
+ return Re();
22459
22469
  },
22460
22470
  set testId(e) {
22461
- re(e), flushSync();
22471
+ Re(e), flushSync();
22462
22472
  },
22463
22473
  get content() {
22464
- return be();
22474
+ return Ue();
22465
22475
  },
22466
22476
  set content(e) {
22467
- be(e), flushSync();
22477
+ Ue(e), flushSync();
22468
22478
  },
22469
22479
  get footerSnippet() {
22470
- return Me();
22480
+ return it();
22471
22481
  },
22472
22482
  set footerSnippet(e) {
22473
- Me(e), flushSync();
22483
+ it(e), flushSync();
22474
22484
  },
22475
22485
  get onclose() {
22476
- return Re();
22486
+ return at();
22477
22487
  },
22478
22488
  set onclose(e) {
22479
- Re(e), flushSync();
22489
+ at(e), flushSync();
22480
22490
  },
22481
22491
  get onheaderrightimageclick() {
22482
- return Ue();
22492
+ return ot();
22483
22493
  },
22484
22494
  set onheaderrightimageclick(e) {
22485
- Ue(e), flushSync();
22495
+ ot(e), flushSync();
22486
22496
  },
22487
22497
  get onheaderleftimageclick() {
22488
- return it();
22498
+ return ct();
22489
22499
  },
22490
22500
  set onheaderleftimageclick(e) {
22491
- it(e), flushSync();
22501
+ ct(e), flushSync();
22492
22502
  },
22493
22503
  get onprimarybuttonclick() {
22494
- return at();
22504
+ return lt();
22495
22505
  },
22496
22506
  set onprimarybuttonclick(e) {
22497
- at(e), flushSync();
22507
+ lt(e), flushSync();
22498
22508
  },
22499
22509
  get onsecondarybuttonclick() {
22500
- return ot();
22510
+ return ut();
22501
22511
  },
22502
22512
  set onsecondarybuttonclick(e) {
22503
- ot(e), flushSync();
22513
+ ut(e), flushSync();
22504
22514
  },
22505
22515
  get onoverlayclick() {
22506
- return ct();
22516
+ return dt();
22507
22517
  },
22508
22518
  set onoverlayclick(e) {
22509
- ct(e), flushSync();
22519
+ dt(e), flushSync();
22510
22520
  },
22511
22521
  get onkeydown() {
22512
- return lt();
22522
+ return ft();
22513
22523
  },
22514
22524
  set onkeydown(e) {
22515
- lt(e), flushSync();
22525
+ ft(e), flushSync();
22516
22526
  },
22517
22527
  get ondismiss() {
22518
- return ut();
22528
+ return pt();
22519
22529
  },
22520
22530
  set ondismiss(e) {
22521
- ut(e), flushSync();
22531
+ pt(e), flushSync();
22522
22532
  },
22523
22533
  get classes() {
22524
- return dt();
22534
+ return mt();
22525
22535
  },
22526
22536
  set classes(e) {
22527
- dt(e), flushSync();
22537
+ mt(e), flushSync();
22528
22538
  },
22529
22539
  get overlayBackdropFilter() {
22530
- return ft();
22540
+ return ht();
22531
22541
  },
22532
22542
  set overlayBackdropFilter(e) {
22533
- ft(e), flushSync();
22543
+ ht(e), flushSync();
22534
22544
  },
22535
22545
  get overlayFadeIn() {
22536
- return pt();
22546
+ return gt();
22537
22547
  },
22538
22548
  set overlayFadeIn(e = !1) {
22539
- pt(e), flushSync();
22549
+ gt(e), flushSync();
22540
22550
  },
22541
22551
  get usePortal() {
22542
- return mt();
22552
+ return _t();
22543
22553
  },
22544
22554
  set usePortal(e = !1) {
22545
- mt(e), flushSync();
22555
+ _t(e), flushSync();
22546
22556
  },
22547
22557
  get lockScroll() {
22548
- return ht();
22558
+ return vt();
22549
22559
  },
22550
22560
  set lockScroll(e = !0) {
22551
- ht(e), flushSync();
22561
+ vt(e), flushSync();
22552
22562
  },
22553
22563
  get scrollContainer() {
22554
- return gt();
22564
+ return yt();
22555
22565
  },
22556
22566
  set scrollContainer(e) {
22557
- gt(e), flushSync();
22567
+ yt(e), flushSync();
22558
22568
  },
22559
22569
  get autoDismissAfter() {
22560
- return _t();
22570
+ return bt();
22561
22571
  },
22562
22572
  set autoDismissAfter(e = null) {
22563
- _t(e), flushSync();
22573
+ bt(e), flushSync();
22564
22574
  },
22565
22575
  get ariaLabel() {
22566
- return vt();
22576
+ return xt();
22567
22577
  },
22568
22578
  set ariaLabel(e) {
22569
- vt(e), flushSync();
22579
+ xt(e), flushSync();
22570
22580
  },
22571
22581
  get ariaDescribedby() {
22572
- return yt();
22582
+ return St();
22573
22583
  },
22574
22584
  set ariaDescribedby(e) {
22575
- yt(e), flushSync();
22585
+ St(e), flushSync();
22576
22586
  },
22577
22587
  get role() {
22578
- return bt();
22588
+ return Ct();
22579
22589
  },
22580
22590
  set role(e) {
22581
- bt(e), flushSync();
22591
+ Ct(e), flushSync();
22582
22592
  },
22583
22593
  get overlayAriaLabel() {
22584
- return xt();
22594
+ return wt();
22585
22595
  },
22586
22596
  set overlayAriaLabel(e) {
22587
- xt(e), flushSync();
22597
+ wt(e), flushSync();
22588
22598
  }
22589
- }, qt = comment();
22590
- event("keydown", $window, Nt);
22591
- var Zt = first_child(qt), Qt = (e) => {
22599
+ }, $t = comment();
22600
+ event("keydown", $window, Lt);
22601
+ var en = first_child($t), tn = (e) => {
22592
22602
  OverlayAnimation(e, {
22593
22603
  get fadeIn() {
22594
- return pt();
22604
+ return gt();
22595
22605
  },
22596
22606
  children: (e, t) => {
22597
22607
  var o = root_11$17(), s = child(o), c = (e) => {
22598
22608
  var t = root_1$50();
22599
22609
  bind_this(t, (e) => set(i, e), () => get(i)), template_effect(() => {
22600
- set_attribute(t, "aria-label", xt() ?? "Dismiss modal"), set_attribute(t, "tabindex", bt() === "dialog" || bt() === "alertdialog" ? -1 : 0);
22610
+ set_attribute(t, "aria-label", wt() ?? "Dismiss modal"), set_attribute(t, "tabindex", Ct() === "dialog" || Ct() === "alertdialog" ? -1 : 0);
22601
22611
  }), append(e, t);
22602
22612
  };
22603
22613
  if_block(s, (e) => {
22604
- get(St) && e(c);
22614
+ get(Tt) && e(c);
22605
22615
  }), ModalAnimation(sibling(s, 2), {
22606
22616
  get enable() {
22607
- return h();
22617
+ return k();
22608
22618
  },
22609
22619
  get align() {
22610
- return u();
22620
+ return h();
22611
22621
  },
22612
22622
  get transitionType() {
22613
- return S();
22623
+ return R();
22614
22624
  },
22615
22625
  get entryAnimation() {
22616
- return C();
22626
+ return te();
22617
22627
  },
22618
22628
  children: (e, t) => {
22619
22629
  var n = root_10$18(), i = child(n), o = (e) => {
@@ -22628,95 +22638,96 @@ function Modal(e, t) {
22628
22638
  fallback: "",
22629
22639
  classes: "header-left-img"
22630
22640
  });
22631
- }, n = /* @__PURE__ */ user_derived(() => k().leftImage);
22641
+ }, n = /* @__PURE__ */ user_derived(() => ne().leftImage);
22632
22642
  var i = comment(), a = first_child(i), o = (e) => {
22633
22643
  var n = root_2$40();
22634
22644
  t(child(n)), reset(n), template_effect(() => {
22635
- set_attribute(n, "aria-label", G() ?? null), set_attribute(n, "data-pw", ne()), set_attribute(n, "testid", ne());
22636
- }), delegated("click", n, kt), delegated("keydown", n, It), append(e, n);
22645
+ set_attribute(n, "aria-label", Me() ?? null), set_attribute(n, "data-pw", be()), set_attribute(n, "testid", be());
22646
+ }), delegated("click", n, Mt), delegated("keydown", n, zt), append(e, n);
22637
22647
  }, s = (e) => {
22638
22648
  var n = root_3$37();
22639
22649
  t(child(n)), reset(n), template_effect(() => {
22640
- set_attribute(n, "data-pw", ne()), set_attribute(n, "testid", ne());
22650
+ set_attribute(n, "data-pw", be()), set_attribute(n, "testid", be());
22641
22651
  }), append(e, n);
22642
22652
  };
22643
22653
  if_block(a, (e) => {
22644
- typeof it() == "function" ? e(o) : e(s, -1);
22654
+ typeof ct() == "function" ? e(o) : e(s, -1);
22645
22655
  }), append(e, i);
22646
22656
  };
22647
22657
  if_block(n, (e) => {
22648
- typeof k().leftImage == "string" && k().leftImage.length > 0 && e(i);
22658
+ typeof ne().leftImage == "string" && ne().leftImage.length > 0 && e(i);
22649
22659
  });
22650
22660
  var a = sibling(n, 2), o = (e) => {
22651
22661
  var t = root_4$32(), n = child(t, !0);
22652
22662
  reset(t), template_effect(() => {
22653
- set_attribute(t, "data-pw", k().testId), set_attribute(t, "testid", k().testId), set_text(n, k().text);
22663
+ set_attribute(t, "data-pw", ne().testId), set_attribute(t, "testid", ne().testId), set_text(n, ne().text);
22654
22664
  }), append(e, t);
22655
22665
  };
22656
22666
  if_block(a, (e) => {
22657
- typeof k().text == "string" && k().text.length > 0 && e(o);
22667
+ typeof ne().text == "string" && ne().text.length > 0 && e(o);
22658
22668
  });
22659
22669
  var s = sibling(a, 2), c = (e) => {
22660
22670
  var t = root_2$40();
22661
22671
  Img(child(t), {
22662
22672
  inlineSvg: !0,
22663
22673
  get src() {
22664
- return k().rightImage;
22674
+ return ne().rightImage;
22665
22675
  },
22666
22676
  alt: "",
22667
22677
  fallback: "",
22668
22678
  classes: "header-right-img"
22669
22679
  }), reset(t), template_effect(() => {
22670
- set_attribute(t, "aria-label", k().buttonAriaLabel ?? null), set_attribute(t, "data-pw", k().buttonTestId), set_attribute(t, "testid", k().buttonTestId);
22671
- }), delegated("click", t, Ot), delegated("keydown", t, Lt), append(e, t);
22680
+ set_attribute(t, "aria-label", ne().buttonAriaLabel ?? null), set_attribute(t, "data-pw", ne().buttonTestId), set_attribute(t, "testid", ne().buttonTestId);
22681
+ }), delegated("click", t, jt), delegated("keydown", t, Bt), append(e, t);
22672
22682
  };
22673
22683
  if_block(s, (e) => {
22674
- typeof k().rightImage == "string" && k().rightImage.length > 0 && e(c);
22684
+ typeof ne().rightImage == "string" && ne().rightImage.length > 0 && e(c);
22675
22685
  }), reset(t), append(e, t);
22676
22686
  };
22677
22687
  if_block(i, (e) => {
22678
- (typeof k()?.leftImage == "string" && k().leftImage.length > 0 || typeof k()?.text == "string" && k().text.length > 0 || typeof k()?.rightImage == "string" && k().rightImage.length > 0) && e(o);
22688
+ (typeof ne()?.leftImage == "string" && ne().leftImage.length > 0 || typeof ne()?.text == "string" && ne().text.length > 0 || typeof ne()?.rightImage == "string" && ne().rightImage.length > 0) && e(o);
22679
22689
  });
22680
22690
  var s = sibling(i, 2);
22681
- snippet(child(s), () => be() ?? noop), reset(s);
22682
- var c = sibling(s, 2), u = (e) => {
22691
+ snippet(child(s), () => Ue() ?? noop), reset(s);
22692
+ var c = sibling(s, 2), l = (e) => {
22683
22693
  var t = root_6$25();
22684
- snippet(child(t), () => Me() ?? noop), reset(t), append(e, t);
22685
- }, f = (e) => {
22694
+ snippet(child(t), () => it() ?? noop), reset(t), append(e, t);
22695
+ }, u = (e) => {
22686
22696
  var t = root_9$18(), n = child(t), i = child(n), a = (e) => {
22687
22697
  var t = root_7$23();
22688
- Button(child(t), spread_props(() => R().secondaryButton, { onclick: jt })), reset(t), append(e, t);
22698
+ Button(child(t), spread_props(() => G().secondaryButton, { onclick: Pt })), reset(t), append(e, t);
22689
22699
  };
22690
22700
  if_block(i, (e) => {
22691
- R().secondaryButton && e(a);
22701
+ G().secondaryButton && e(a);
22692
22702
  });
22693
22703
  var o = sibling(i, 2), s = (e) => {
22694
22704
  var t = root_8$23();
22695
- Button(child(t), spread_props(() => R().primaryButton, { onclick: At })), reset(t), append(e, t);
22705
+ Button(child(t), spread_props(() => G().primaryButton, { onclick: Nt })), reset(t), append(e, t);
22696
22706
  };
22697
22707
  if_block(o, (e) => {
22698
- R().primaryButton && e(s);
22708
+ G().primaryButton && e(s);
22699
22709
  }), reset(n), reset(t), append(e, t);
22700
22710
  };
22701
22711
  if_block(c, (e) => {
22702
- typeof Me() == "function" ? e(u) : (typeof R()?.primaryButton == "object" || typeof R()?.secondaryButton == "object") && e(f, 1);
22712
+ typeof it() == "function" ? e(l) : (typeof G()?.primaryButton == "object" || typeof G()?.secondaryButton == "object") && e(u, 1);
22703
22713
  }), reset(n), bind_this(n, (e) => set(a, e), () => get(a)), template_effect(() => {
22704
- set_class(n, 1, `modal-content ${l() ?? ""}`, "svelte-lnufm"), set_attribute(n, "role", bt() ?? null), set_attribute(n, "aria-modal", bt() == null ? null : "true"), set_attribute(n, "aria-label", vt() ?? null), set_attribute(n, "aria-describedby", yt() ?? null);
22714
+ set_class(n, 1, `modal-content ${p() ?? ""}`, "svelte-lnufm"), set_attribute(n, "role", Ct() ?? null), set_attribute(n, "aria-modal", Ct() == null ? null : "true"), set_attribute(n, "aria-label", xt() ?? null), set_attribute(n, "aria-describedby", St() ?? null);
22705
22715
  }), append(e, n);
22706
22716
  },
22707
22717
  $$slots: { default: !0 }
22708
- }), reset(o), bind_this(o, (e) => set(n, e), () => get(n)), action(o, (e, t) => Et?.(e, t), () => ({ usePortal: mt() })), template_effect(() => {
22709
- set_class(o, 1, `modal ${u() ?? ""} ${f() ? "overlay-active" : "overlay-inactive"} ${dt() ?? "" ?? ""}`, "svelte-lnufm"), set_style(o, ft() == null ? null : `--modal-overlay-backdrop-filter: ${ft()};`), set_attribute(o, "data-pw", re()), set_attribute(o, "testid", re());
22710
- }), delegated("click", o, Mt), append(e, o);
22718
+ }), reset(o), bind_this(o, (e) => set(n, e), () => get(n)), action(o, (e, t) => kt?.(e, t), () => ({ usePortal: _t() })), template_effect(() => {
22719
+ set_class(o, 1, `modal ${h() ?? ""} ${S() ? "overlay-active" : "overlay-inactive"} ${mt() ?? "" ?? ""}`, "svelte-lnufm"), set_style(o, ht() == null ? null : `--modal-overlay-backdrop-filter: ${ht()};`), set_attribute(o, "data-pw", Re()), set_attribute(o, "testid", Re());
22720
+ }), delegated("click", o, It), append(e, o);
22711
22721
  },
22712
22722
  $$slots: { default: !0 }
22713
22723
  });
22714
22724
  };
22715
- return if_block(Zt, (e) => {
22716
- typeof be() == "function" && e(Qt);
22717
- }), append(e, qt), pop(Gt);
22725
+ return if_block(en, (e) => {
22726
+ typeof Ue() == "function" && e(tn);
22727
+ }), append(e, $t), pop(Qt);
22718
22728
  }
22719
22729
  delegate(["click", "keydown"]), create_custom_element(Modal, {
22730
+ restoreFocusTo: {},
22720
22731
  containFocus: {},
22721
22732
  size: {},
22722
22733
  align: {},
@@ -22849,6 +22860,7 @@ customElements.define("sui-modal", create_custom_element(Modal_wc, {
22849
22860
  type: "Boolean"
22850
22861
  },
22851
22862
  scrollContainer: { type: "Object" },
22863
+ restoreFocusTo: { type: "Object" },
22852
22864
  size: {
22853
22865
  reflect: !0,
22854
22866
  type: "String"
@@ -24839,16 +24851,23 @@ function Sheet(e, t) {
24839
24851
  t !== null && (e.preventDefault(), t.focus());
24840
24852
  }
24841
24853
  }
24842
- let it = null, at = null, ot = !1;
24854
+ let it = null, at = null, ot = !1, ct = 0;
24843
24855
  onMount(() => toStore(() => n()).subscribe((e) => {
24844
- if (!e) ot = !0;
24856
+ if (!e) ct += 1, ot = !0;
24845
24857
  else if (ot && it !== null) {
24846
24858
  ot = !1;
24847
24859
  let e = untrack(() => acquireScrollLock(resolveScrollContainer(it, i())));
24848
24860
  at?.(), at = e;
24861
+ let t = it, a = untrack(() => get(G)), o = ++ct;
24862
+ tick().then(() => {
24863
+ if (!(o !== ct || !n() || it !== t || get(G) !== a || a === null || !t.isConnected || !a.isConnected || !isTopmostDismissible(a))) {
24864
+ for (let e = getActiveElement(a); e !== null; e = composedParent(e)) if (e === a) return;
24865
+ a.focus();
24866
+ }
24867
+ });
24849
24868
  }
24850
24869
  }));
24851
- function ct(e) {
24870
+ function lt(e) {
24852
24871
  let t = getActiveElement(e), n = !0;
24853
24872
  it = e, ot = !1, at = acquireScrollLock(resolveScrollContainer(e, i()));
24854
24873
  let a = registerDismissible({
@@ -24858,19 +24877,19 @@ function Sheet(e, t) {
24858
24877
  return tick().then(() => {
24859
24878
  n && get(G) !== null && get(G).focus();
24860
24879
  }), { destroy() {
24861
- n = !1, a(), at?.(), at = null, it = null;
24880
+ n = !1, ct += 1, a(), at?.(), at = null, it = null;
24862
24881
  let i = getActiveElement(e);
24863
24882
  t instanceof HTMLElement && t.isConnected && (i === null || i === document.body || e.contains(i)) && t.focus();
24864
24883
  } };
24865
24884
  }
24866
- function lt() {
24885
+ function ut() {
24867
24886
  typeof k() == "function" && k()();
24868
24887
  }
24869
- function ut() {
24888
+ function dt() {
24870
24889
  typeof R() == "function" && R()();
24871
24890
  }
24872
- let dt = /* @__PURE__ */ user_derived(() => typeof f() == "number" && Number.isInteger(f()) && f() >= 1 && f() <= 6 ? `h${f()}` : null);
24873
- var ft = {
24891
+ let ft = /* @__PURE__ */ user_derived(() => typeof f() == "number" && Number.isInteger(f()) && f() >= 1 && f() <= 6 ? `h${f()}` : null);
24892
+ var pt = {
24874
24893
  get open() {
24875
24894
  return n();
24876
24895
  },
@@ -24967,12 +24986,12 @@ function Sheet(e, t) {
24967
24986
  set classes(e) {
24968
24987
  te(e), flushSync();
24969
24988
  }
24970
- }, pt = comment(), mt = first_child(pt), ht = (e) => {
24989
+ }, mt = comment(), ht = first_child(mt), gt = (e) => {
24971
24990
  var t = root_4$28(), n = child(t), i = child(n), f = (e) => {
24972
24991
  var t = root_2$35(), n = child(t), i = (e) => {
24973
24992
  var t = comment(), n = first_child(t), i = (e) => {
24974
24993
  var t = comment();
24975
- element(first_child(t), () => get(dt), !1, (e, t) => {
24994
+ element(first_child(t), () => get(ft), !1, (e, t) => {
24976
24995
  set_class(e, 0, "sheet-title svelte-1dln6bq");
24977
24996
  var n = text();
24978
24997
  template_effect(() => set_text(n, o())), append(t, n);
@@ -24982,7 +25001,7 @@ function Sheet(e, t) {
24982
25001
  reset(t), template_effect(() => set_text(n, o())), append(e, t);
24983
25002
  };
24984
25003
  if_block(n, (e) => {
24985
- get(dt) === null ? e(a, -1) : e(i);
25004
+ get(ft) === null ? e(a, -1) : e(i);
24986
25005
  }), append(e, t);
24987
25006
  };
24988
25007
  if_block(n, (e) => {
@@ -25015,13 +25034,13 @@ function Sheet(e, t) {
25015
25034
  };
25016
25035
  if_block(k, (e) => {
25017
25036
  typeof S() == "function" && e(R);
25018
- }), reset(n), bind_this(n, (e) => set(G, e), () => get(G)), reset(t), bind_this(t, (e) => set(ne, e), () => get(ne)), action(t, (e) => ct?.(e)), template_effect((e) => {
25037
+ }), reset(n), bind_this(n, (e) => set(G, e), () => get(G)), reset(t), bind_this(t, (e) => set(ne, e), () => get(ne)), action(t, (e) => lt?.(e)), template_effect((e) => {
25019
25038
  set_class(t, 1, `sheet-overlay ${s() ? "overlay-visible" : "overlay-invisible"} ${s() || c() ? "overlay-interactive" : "overlay-noninteractive"} ${te() ?? "" ?? ""}`, "svelte-1dln6bq"), set_attribute(t, "role", c() ? "button" : null), set_attribute(t, "aria-label", e), set_attribute(t, "data-pw", typeof p() == "string" ? p() : null), set_attribute(t, "testid", typeof p() == "string" ? p() : null), set_class(n, 1, `sheet-panel ${a() ?? ""}`, "svelte-1dln6bq"), set_attribute(n, "aria-label", o() ?? "Sheet"), set_attribute(n, "data-pw", typeof p() == "string" ? `${p()}-panel` : null), set_attribute(n, "testid", typeof p() == "string" ? `${p()}-panel` : null);
25020
- }, [() => c() ? l()?.trim() || "Close sheet" : null]), delegated("click", t, Re), delegated("keydown", t, Ue), event("introend", n, lt), event("outroend", n, ut), transition(7, n, () => tokenizedFly, () => get(be)), transition(3, t, () => fade, () => ({ duration: 200 })), append(e, t);
25039
+ }, [() => c() ? l()?.trim() || "Close sheet" : null]), delegated("click", t, Re), delegated("keydown", t, Ue), event("introend", n, ut), event("outroend", n, dt), transition(7, n, () => tokenizedFly, () => get(be)), transition(3, t, () => fade, () => ({ duration: 200 })), append(e, t);
25021
25040
  };
25022
- return if_block(mt, (e) => {
25023
- n() && e(ht);
25024
- }), append(e, pt), pop(ft);
25041
+ return if_block(ht, (e) => {
25042
+ n() && e(gt);
25043
+ }), append(e, mt), pop(pt);
25025
25044
  }
25026
25045
  delegate(["click", "keydown"]), create_custom_element(Sheet, {
25027
25046
  open: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "4.56.0",
3
+ "version": "4.57.1",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",