asma-ui-core 3.110.0 → 3.112.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,91 +1,119 @@
1
- import { createContext as v, useContext as y, useEffect as p, useRef as O } from "react";
2
- function _() {
1
+ import { findTopmostConnectedModalDialog as w } from "./useTopLayer.hook.js";
2
+ import { createContext as O, useContext as k, useEffect as p, useRef as B } from "react";
3
+ function v() {
3
4
  return {
4
5
  version: 1,
5
6
  entries: [],
6
7
  adapter: { unregister: null }
7
8
  };
8
9
  }
9
- function a() {
10
+ function s() {
10
11
  if (!(typeof window > "u"))
11
12
  return window.rawWindow ?? document.defaultView ?? window;
12
13
  }
13
- function l() {
14
- const e = a();
15
- return e ? e.__asmaOverlayBackRegistry__ ??= _() : k ??= _();
14
+ function c() {
15
+ const e = s(), n = e ? e.__asmaOverlayBackRegistry__ ??= v() : h ??= v();
16
+ return n.entries = A(n.entries), n;
16
17
  }
17
- var k, B = (e) => typeof e == "object" && e !== null && typeof e.then == "function";
18
+ var h, L = (e) => typeof e == "object" && e !== null && typeof e.then == "function";
18
19
  function d(e, n) {
19
20
  if (e.parentOwnerRef && e.parentOwnerRef === n.ownerRef) return !0;
20
21
  const t = e.parentOwnerRef?.current ?? e.parentOwner, i = n.ownerRef?.current ?? n.owner;
21
22
  return !!t && !!i && (t === i || i.contains(t));
22
23
  }
23
- function w(e) {
24
- if (e.adapter.unregister) return;
25
- const n = a()?.__ASMA__SHELL__?.overlayBack;
26
- n?.v !== 1 || typeof n.register != "function" || (e.adapter.unregister = n.register(() => S()));
24
+ function S(e) {
25
+ return c().entries.some((n) => (n.ownerRef?.current ?? n.owner) === e);
27
26
  }
27
+ var _ = /* @__PURE__ */ new WeakSet();
28
28
  function A(e) {
29
+ if (_.has(e)) return e;
30
+ _.add(e);
31
+ const n = e.reduce.bind(e);
32
+ return Object.defineProperty(e, "reduce", {
33
+ configurable: !0,
34
+ value(t, i) {
35
+ return n((o, r, u, f) => y(r) ? o : t(o, r, u, f), i);
36
+ }
37
+ }), e;
38
+ }
39
+ function y(e) {
40
+ const n = w((i) => i.open || S(i));
41
+ if (!n) return !1;
42
+ const t = e.ownerRef?.current ?? e.owner;
43
+ return !t || n.contains(t) ? !1 : !E(t);
44
+ }
45
+ function E(e) {
46
+ return !(e instanceof HTMLElement) || typeof e.showPopover != "function" ? !1 : e.matches(":popover-open");
47
+ }
48
+ function R(e) {
49
+ if (e.adapter.unregister) return;
50
+ const n = s()?.__ASMA__SHELL__?.overlayBack;
51
+ n?.v !== 1 || typeof n.register != "function" || (e.adapter.unregister = n.register(() => b()));
52
+ }
53
+ function m(e) {
29
54
  e.adapter.unregister && Promise.resolve().then(() => {
30
55
  if (e.entries.length > 0) return;
31
56
  const n = e.adapter.unregister;
32
57
  e.adapter.unregister = null, n?.();
33
58
  });
34
59
  }
35
- function L(e, n = null, t = null, i, o) {
36
- const r = l(), s = {
60
+ function C(e, n = null, t = null, i, o) {
61
+ const r = c(), u = {
37
62
  requestClose: e,
38
63
  pending: !1,
39
64
  owner: n,
40
65
  parentOwner: t,
41
66
  ownerRef: i,
42
67
  parentOwnerRef: o
43
- }, c = n || i ? r.entries.findIndex((u) => i !== void 0 && u.parentOwnerRef === i || n !== null && u.parentOwner === n || n !== null && u.owner !== null && n.contains(u.owner)) : -1;
44
- r.entries.splice(c === -1 ? r.entries.length : c, 0, s), r.entries.length === 1 && w(r);
45
- let f = !1;
68
+ }, f = n || i ? r.entries.findIndex((a) => i !== void 0 && a.parentOwnerRef === i || n !== null && a.parentOwner === n || n !== null && a.owner !== null && n.contains(a.owner)) : -1;
69
+ r.entries.splice(f === -1 ? r.entries.length : f, 0, u), r.entries.length === 1 && R(r);
70
+ let l = !1;
46
71
  return () => {
47
- if (f) return;
48
- f = !0;
49
- const u = r.entries.indexOf(s);
50
- if (u !== -1 && r.entries.splice(u, 1), r.entries.length === 0) {
51
- A(r);
72
+ if (l) return;
73
+ l = !0;
74
+ const a = r.entries.indexOf(u);
75
+ if (a !== -1 && r.entries.splice(a, 1), r.entries.length === 0) {
76
+ m(r);
52
77
  return;
53
78
  }
54
79
  queueMicrotask(() => {
55
- const g = a()?.__ASMA__SHELL__?.overlayBack;
80
+ const g = s()?.__ASMA__SHELL__?.overlayBack;
56
81
  r.entries.length > 0 && g?.pendingNavigation && g.continuePendingNavigation?.();
57
82
  });
58
83
  };
59
84
  }
60
- var R = v(void 0);
61
- function S(e) {
62
- const { entries: n } = l(), t = n.reduce((o, r) => !o || d(r, o) ? r : d(o, r) ? o : r, void 0);
63
- if (!t) return;
85
+ var M = O(void 0);
86
+ function b(e) {
87
+ const { entries: n } = c(), t = n.reduce((o, r) => y(r) ? o : !o || d(r, o) ? r : d(o, r) ? o : r, void 0);
88
+ if (!t) return n.length > 0 ? !1 : void 0;
64
89
  if (t.pending) return !1;
65
90
  const i = t.requestClose(e);
66
- if (B(i)) {
91
+ if (L(i)) {
67
92
  t.pending = !0;
68
93
  const o = () => {
69
94
  t.pending = !1, globalThis.setTimeout(() => {
70
- const r = l(), s = a()?.__ASMA__SHELL__?.overlayBack;
71
- r.entries.includes(t) && s?.pendingNavigation && s.failOpenPendingNavigation?.();
95
+ const r = c(), u = s()?.__ASMA__SHELL__?.overlayBack;
96
+ r.entries.includes(t) && u?.pendingNavigation && u.failOpenPendingNavigation?.();
72
97
  }, 0);
73
98
  };
74
99
  i.then(o, o);
75
100
  }
76
101
  return i;
77
102
  }
78
- function E() {
79
- const e = a()?.__ASMA__SHELL__?.overlayBack;
103
+ function I() {
104
+ return s()?.__ASMA__SHELL__?.overlayBack?.pendingNavigation === !0;
105
+ }
106
+ function N() {
107
+ const e = s()?.__ASMA__SHELL__?.overlayBack;
80
108
  return e?.v === 1 && e.enabled === !0;
81
109
  }
82
- function m({ active: e, requestClose: n, ownerRef: t }) {
83
- const i = y(R), o = O(n);
110
+ function T({ active: e, requestClose: n, ownerRef: t }) {
111
+ const i = k(M), o = B(n);
84
112
  p(() => {
85
113
  o.current = n;
86
114
  }, [n]), p(() => {
87
115
  if (e)
88
- return L((r) => o.current(r), t?.current ?? null, i?.current ?? null, t, i);
116
+ return C((r) => o.current(r), t?.current ?? null, i?.current ?? null, t, i);
89
117
  }, [
90
118
  e,
91
119
  t,
@@ -93,8 +121,9 @@ function m({ active: e, requestClose: n, ownerRef: t }) {
93
121
  ]);
94
122
  }
95
123
  export {
96
- R as OverlayBackOwnerContext,
97
- E as isOverlayBackEnabled,
98
- S as requestCloseTopOverlayBack,
99
- m as useBackCloses
124
+ M as OverlayBackOwnerContext,
125
+ N as isOverlayBackEnabled,
126
+ I as isOverlayBackNavigationPending,
127
+ b as requestCloseTopOverlayBack,
128
+ T as useBackCloses
100
129
  };
@@ -1,15 +1,15 @@
1
- import { useCallback as r, useSyncExternalStore as s } from "react";
2
- var c = { popover: "manual" }, p = {
1
+ import { useCallback as s, useSyncExternalStore as a } from "react";
2
+ var p = { popover: "manual" }, g = {
3
3
  margin: 0,
4
4
  inset: "auto"
5
5
  };
6
- function f(e) {
6
+ function w(e) {
7
7
  if (!(e instanceof Element)) return;
8
8
  const o = e.closest("dialog");
9
9
  return o instanceof HTMLDialogElement && o.open ? o : void 0;
10
10
  }
11
11
  function t() {
12
- if (typeof window > "u") return a ??= {
12
+ if (typeof window > "u") return l ??= {
13
13
  dialogs: [],
14
14
  listeners: /* @__PURE__ */ new Set()
15
15
  };
@@ -19,34 +19,37 @@ function t() {
19
19
  listeners: /* @__PURE__ */ new Set()
20
20
  };
21
21
  }
22
- var a, i = () => {
22
+ var l, r = () => {
23
23
  for (const e of [...t().listeners]) e();
24
24
  };
25
- function g(e) {
26
- return t().dialogs.push(e), i(), () => {
25
+ function v(e) {
26
+ return t().dialogs.push(e), r(), () => {
27
27
  const { dialogs: o } = t(), n = o.indexOf(e);
28
- n !== -1 && (o.splice(n, 1), i());
28
+ n !== -1 && (o.splice(n, 1), r());
29
29
  };
30
30
  }
31
- function l() {
32
- const { dialogs: e } = t();
33
- for (let o = e.length - 1; o >= 0; o -= 1) {
34
- const n = e[o];
35
- if (n?.isConnected && n.open) return n;
31
+ function u(e) {
32
+ const { dialogs: o } = t();
33
+ for (let n = o.length - 1; n >= 0; n -= 1) {
34
+ const i = o[n];
35
+ if (i?.isConnected && e(i)) return i;
36
36
  }
37
37
  }
38
- var u = (e) => (t().listeners.add(e), () => {
38
+ function d() {
39
+ return u((e) => e.open);
40
+ }
41
+ var c = (e) => (t().listeners.add(e), () => {
39
42
  t().listeners.delete(e);
40
43
  });
41
- function w() {
42
- return s(u, l, () => {
44
+ function m() {
45
+ return a(c, d, () => {
43
46
  });
44
47
  }
45
- function v(e) {
48
+ function O(e) {
46
49
  return e == null;
47
50
  }
48
- function O(e, o = !0) {
49
- return r((n) => {
51
+ function T(e, o = !0) {
52
+ return s((n) => {
50
53
  if (e(n), !(!n || !o))
51
54
  try {
52
55
  typeof n.showPopover == "function" && !n.matches(":popover-open") && n.showPopover();
@@ -55,11 +58,12 @@ function O(e, o = !0) {
55
58
  }, [e, o]);
56
59
  }
57
60
  export {
58
- c as TOP_LAYER_PROPS,
59
- p as TOP_LAYER_RESET_STYLE,
60
- f as getOpenModalDialogAncestor,
61
- g as registerOpenModalDialog,
62
- v as shouldUsePopoverTopLayer,
63
- O as useTopLayerRef,
64
- w as useTopmostOpenModalDialog
61
+ p as TOP_LAYER_PROPS,
62
+ g as TOP_LAYER_RESET_STYLE,
63
+ u as findTopmostConnectedModalDialog,
64
+ w as getOpenModalDialogAncestor,
65
+ v as registerOpenModalDialog,
66
+ O as shouldUsePopoverTopLayer,
67
+ T as useTopLayerRef,
68
+ m as useTopmostOpenModalDialog
65
69
  };