@ai-matrx/design-system 0.43.0 → 0.44.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.
@@ -212,6 +212,15 @@ function useIsMobile() {
212
212
  return isMobile;
213
213
  }
214
214
 
215
+ // src/layer-front.ts
216
+ var LAYER_FRONT_EVENT = "matrx:layer-front";
217
+ function announceLayerFront(element) {
218
+ if (typeof document === "undefined") return;
219
+ document.dispatchEvent(
220
+ new CustomEvent(LAYER_FRONT_EVENT, { detail: { element } })
221
+ );
222
+ }
223
+
215
224
  // src/dialog.tsx
216
225
  import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
217
226
  var DialogWindowedByDefaultContext = React5.createContext(false);
@@ -282,6 +291,8 @@ var DialogContent = React5.forwardRef(
282
291
  dismissOnOutsideClick = false,
283
292
  onInteractOutside,
284
293
  onEscapeKeyDown,
294
+ onPointerDownCapture,
295
+ onFocusCapture,
285
296
  style,
286
297
  ...props
287
298
  }, ref) => {
@@ -294,6 +305,24 @@ var DialogContent = React5.forwardRef(
294
305
  const [containerEl, setContainerEl] = React5.useState(
295
306
  null
296
307
  );
308
+ const stacks = windowed && windowedByDefault;
309
+ const [behind, setBehind] = React5.useState(false);
310
+ React5.useEffect(() => {
311
+ if (!stacks || !containerEl) return;
312
+ const onFront = (event) => {
313
+ const element = event.detail?.element ?? null;
314
+ if (element && (element === containerEl || containerEl.contains(element))) return;
315
+ setBehind(true);
316
+ };
317
+ document.addEventListener(LAYER_FRONT_EVENT, onFront);
318
+ announceLayerFront(containerEl);
319
+ return () => document.removeEventListener(LAYER_FRONT_EVENT, onFront);
320
+ }, [stacks, containerEl]);
321
+ const bringToFront = () => {
322
+ if (!stacks || !containerEl) return;
323
+ setBehind(false);
324
+ announceLayerFront(containerEl);
325
+ };
297
326
  const [offset, setOffset] = React5.useState({ x: 0, y: 0 });
298
327
  const dragRef = React5.useRef(null);
299
328
  const handle = React5.useMemo(() => {
@@ -352,10 +381,20 @@ var DialogContent = React5.forwardRef(
352
381
  // z=1000); staying below that boundary makes a newly focused window
353
382
  // usable without coupling the two systems.
354
383
  !isModal && !windowedByDefault && "z-[900]",
384
+ // Another layer came to the front after this window (layer-front.ts).
385
+ stacks && behind && "z-[999]",
355
386
  // Without an overlay the card needs its own separation from the page.
356
387
  windowed && "shadow-2xl ring-1 ring-border/60"
357
388
  ),
358
389
  style: windowed && (offset.x !== 0 || offset.y !== 0) ? { ...style, translate: `${offset.x}px ${offset.y}px` } : style,
390
+ onPointerDownCapture: (event) => {
391
+ onPointerDownCapture?.(event);
392
+ if (behind) bringToFront();
393
+ },
394
+ onFocusCapture: (event) => {
395
+ onFocusCapture?.(event);
396
+ if (behind) bringToFront();
397
+ },
359
398
  onInteractOutside: (event) => {
360
399
  onInteractOutside?.(event);
361
400
  if (windowed && !dismissOnOutsideClick) event.preventDefault();