@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.
@@ -250,6 +250,15 @@ function useIsMobile() {
250
250
  return isMobile;
251
251
  }
252
252
 
253
+ // src/layer-front.ts
254
+ var LAYER_FRONT_EVENT = "matrx:layer-front";
255
+ function announceLayerFront(element) {
256
+ if (typeof document === "undefined") return;
257
+ document.dispatchEvent(
258
+ new CustomEvent(LAYER_FRONT_EVENT, { detail: { element } })
259
+ );
260
+ }
261
+
253
262
  // src/dialog.tsx
254
263
  var import_jsx_runtime5 = require("react/jsx-runtime");
255
264
  var DialogWindowedByDefaultContext = React5.createContext(false);
@@ -320,6 +329,8 @@ var DialogContent = React5.forwardRef(
320
329
  dismissOnOutsideClick = false,
321
330
  onInteractOutside,
322
331
  onEscapeKeyDown,
332
+ onPointerDownCapture,
333
+ onFocusCapture,
323
334
  style,
324
335
  ...props
325
336
  }, ref) => {
@@ -332,6 +343,24 @@ var DialogContent = React5.forwardRef(
332
343
  const [containerEl, setContainerEl] = React5.useState(
333
344
  null
334
345
  );
346
+ const stacks = windowed && windowedByDefault;
347
+ const [behind, setBehind] = React5.useState(false);
348
+ React5.useEffect(() => {
349
+ if (!stacks || !containerEl) return;
350
+ const onFront = (event) => {
351
+ const element = event.detail?.element ?? null;
352
+ if (element && (element === containerEl || containerEl.contains(element))) return;
353
+ setBehind(true);
354
+ };
355
+ document.addEventListener(LAYER_FRONT_EVENT, onFront);
356
+ announceLayerFront(containerEl);
357
+ return () => document.removeEventListener(LAYER_FRONT_EVENT, onFront);
358
+ }, [stacks, containerEl]);
359
+ const bringToFront = () => {
360
+ if (!stacks || !containerEl) return;
361
+ setBehind(false);
362
+ announceLayerFront(containerEl);
363
+ };
335
364
  const [offset, setOffset] = React5.useState({ x: 0, y: 0 });
336
365
  const dragRef = React5.useRef(null);
337
366
  const handle = React5.useMemo(() => {
@@ -390,10 +419,20 @@ var DialogContent = React5.forwardRef(
390
419
  // z=1000); staying below that boundary makes a newly focused window
391
420
  // usable without coupling the two systems.
392
421
  !isModal && !windowedByDefault && "z-[900]",
422
+ // Another layer came to the front after this window (layer-front.ts).
423
+ stacks && behind && "z-[999]",
393
424
  // Without an overlay the card needs its own separation from the page.
394
425
  windowed && "shadow-2xl ring-1 ring-border/60"
395
426
  ),
396
427
  style: windowed && (offset.x !== 0 || offset.y !== 0) ? { ...style, translate: `${offset.x}px ${offset.y}px` } : style,
428
+ onPointerDownCapture: (event) => {
429
+ onPointerDownCapture?.(event);
430
+ if (behind) bringToFront();
431
+ },
432
+ onFocusCapture: (event) => {
433
+ onFocusCapture?.(event);
434
+ if (behind) bringToFront();
435
+ },
397
436
  onInteractOutside: (event) => {
398
437
  onInteractOutside?.(event);
399
438
  if (windowed && !dismissOnOutsideClick) event.preventDefault();