@mt-gloss/ui 0.1.84 → 0.1.86

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,219 +0,0 @@
1
- import { jsx as a, jsxs as u, Fragment as I } from "react/jsx-runtime";
2
- import { createContext as h, useContext as p, useReducer as g, useRef as i, useEffect as r, useMemo as f, useCallback as v, useLayoutEffect as C } from "react";
3
- const c = h(null);
4
- function m() {
5
- const e = p(c);
6
- if (!e)
7
- throw new Error(
8
- "[panels] usePanelContext must be used inside <PanelProvider>. See @mt-gloss/ui/composites/panels."
9
- );
10
- return e;
11
- }
12
- function O() {
13
- return p(c);
14
- }
15
- const S = {
16
- activePanelId: null,
17
- lastClose: null,
18
- pendingSideEffects: []
19
- };
20
- function _(e, n) {
21
- switch (n.type) {
22
- case "OPEN_PANEL":
23
- return n.panelId === "notification-center" && e.activePanelId === null ? {
24
- activePanelId: "notification-center",
25
- lastClose: null,
26
- // reset lastClose on fresh open
27
- pendingSideEffects: e.pendingSideEffects
28
- // preserve any draining queue
29
- } : n.panelId === "notification-center" && e.activePanelId === "notification-center" ? e : {
30
- ...e,
31
- pendingSideEffects: [
32
- ...e.pendingSideEffects,
33
- {
34
- type: "INVALID_DISPATCH",
35
- reason: `panel-not-supported-in-P1:${n.panelId}`
36
- }
37
- ]
38
- };
39
- case "CLOSE_PANEL":
40
- return e.activePanelId === null ? e : {
41
- activePanelId: null,
42
- lastClose: { panelId: e.activePanelId, reason: n.reason },
43
- pendingSideEffects: e.pendingSideEffects
44
- };
45
- case "DRAIN_SIDE_EFFECTS":
46
- return e.pendingSideEffects.length === 0 ? e : {
47
- ...e,
48
- pendingSideEffects: []
49
- };
50
- default:
51
- return e;
52
- }
53
- }
54
- function y(e) {
55
- return e.activePanelId === "notification-center" ? "notif-center" : (e.activePanelId != null, "idle");
56
- }
57
- function N() {
58
- const [e, n] = g(_, S), t = i([]);
59
- i(null), r(() => {
60
- if (e.pendingSideEffects.length !== 0) {
61
- for (const o of e.pendingSideEffects)
62
- o.type === "SCHEDULE_TIMER" ? window.setTimeout(() => n(o.action), Math.max(0, o.ms)) : o.type === "INVALID_DISPATCH" && process.env.NODE_ENV !== "production" && console.warn("[panels] INVALID_DISPATCH:", o.reason);
63
- n({ type: "DRAIN_SIDE_EFFECTS" });
64
- }
65
- }, [e.pendingSideEffects]), r(() => {
66
- if (!e.lastClose) return;
67
- const o = {
68
- panelId: e.lastClose.panelId,
69
- reason: e.lastClose.reason,
70
- at: Date.now(),
71
- note: e.lastClose.reason === "nav-escape-hatch" ? "F21: backdrop-click OR page-nav escape" : void 0
72
- };
73
- t.current = [
74
- ...t.current.slice(-99),
75
- o
76
- ];
77
- }, [e.lastClose]);
78
- const l = f(
79
- () => y(e),
80
- // eslint-disable-next-line react-hooks/exhaustive-deps
81
- [e.activePanelId]
82
- ), s = v(() => t.current.slice(), []);
83
- return { state: e, surfaceState: l, dispatch: n, getCloseLog: s };
84
- }
85
- function k({ children: e }) {
86
- const n = N(), t = f(
87
- () => n,
88
- // Re-publish only when one of the four coordinator fields changes identity.
89
- // dispatch + getCloseLog are stable. state + surfaceState change on dispatch.
90
- [n.state, n.surfaceState, n.dispatch, n.getCloseLog]
91
- );
92
- return /* @__PURE__ */ a(c.Provider, { value: t, children: e });
93
- }
94
- const x = {
95
- position: "relative",
96
- pointerEvents: "auto"
97
- };
98
- function L({ children: e, onClose: n, isOpen: t = !0 }) {
99
- return /* @__PURE__ */ u(
100
- "div",
101
- {
102
- "data-chrome": "panel",
103
- "data-open": t ? "true" : "false",
104
- role: "dialog",
105
- "aria-modal": "true",
106
- className: "gloss-panel-chrome",
107
- style: x,
108
- children: [
109
- /* @__PURE__ */ a("div", { className: "gloss-panel-chrome__header", children: /* @__PURE__ */ a(
110
- "button",
111
- {
112
- id: "panel-close",
113
- type: "button",
114
- "aria-label": "Close panel",
115
- className: "gloss-panel-chrome__close",
116
- onClick: n,
117
- children: "×"
118
- }
119
- ) }),
120
- /* @__PURE__ */ a("div", { className: "gloss-panel-chrome__body", children: e })
121
- ]
122
- }
123
- );
124
- }
125
- const b = {
126
- position: "fixed",
127
- top: 0,
128
- left: 0,
129
- right: 0,
130
- height: "var(--tb-h, 60px)",
131
- perspective: "1200px",
132
- perspectiveOrigin: "center bottom",
133
- overflow: "visible",
134
- pointerEvents: "none",
135
- zIndex: 55
136
- }, w = {
137
- position: "fixed",
138
- top: "var(--tb-h, 60px)",
139
- left: 0,
140
- right: 0,
141
- bottom: 0,
142
- zIndex: 1,
143
- pointerEvents: "auto",
144
- background: "rgba(0, 0, 0, 0.04)"
145
- };
146
- function H({ panelComponents: e }) {
147
- const { state: n, dispatch: t, getCloseLog: l } = m(), s = n.activePanelId ? e[n.activePanelId] : null;
148
- n.activePanelId && !s && process.env.NODE_ENV !== "production" && console.error(
149
- "[panels] No panel component registered for activePanelId:",
150
- n.activePanelId
151
- ), r(() => {
152
- if (n.activePanelId == null) return;
153
- function d(P) {
154
- P.key === "Escape" && t({ type: "CLOSE_PANEL", reason: "escape-key" });
155
- }
156
- return document.addEventListener("keydown", d), () => {
157
- document.removeEventListener("keydown", d);
158
- };
159
- }, [n.activePanelId, t]);
160
- const o = i(n);
161
- C(() => {
162
- o.current = n;
163
- }), r(() => {
164
- if (process.env.NODE_ENV !== "production")
165
- return window.__panelsHostHandle = {
166
- dispatch: t,
167
- getState: () => o.current,
168
- getCloseLog: l
169
- }, () => {
170
- delete window.__panelsHostHandle;
171
- };
172
- }, [t, l]);
173
- const E = v(() => {
174
- t({ type: "CLOSE_PANEL", reason: "nav-escape-hatch" });
175
- }, [t]);
176
- return /* @__PURE__ */ a("div", { "data-panel-host": "true", style: b, children: n.activePanelId != null && s != null && /* @__PURE__ */ u(I, { children: [
177
- /* @__PURE__ */ a(
178
- "div",
179
- {
180
- "data-panel-scrim": "true",
181
- style: w,
182
- onClick: E
183
- }
184
- ),
185
- /* @__PURE__ */ a(
186
- L,
187
- {
188
- isOpen: !0,
189
- onClose: () => t({ type: "CLOSE_PANEL", reason: "header-x" }),
190
- children: /* @__PURE__ */ a(s, { isOpen: !0 })
191
- }
192
- )
193
- ] }) });
194
- }
195
- const R = {
196
- "apply-button": !0,
197
- // the ONLY commit reason
198
- "cancel-button": !1,
199
- "header-x": !1,
200
- "escape-key": !1,
201
- "page-nav": !1,
202
- "mutex-handoff": !1,
203
- "ghost-anchor": !1,
204
- "viewport-collapse": !1,
205
- unmount: !1,
206
- "nav-escape-hatch": !1
207
- };
208
- export {
209
- R as C,
210
- k as P,
211
- O as a,
212
- H as b,
213
- L as c,
214
- N as d,
215
- y as e,
216
- S as i,
217
- _ as r,
218
- m as u
219
- };