@nanahoshi/mona-ui 0.24.8 → 0.24.10

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.
Files changed (83) hide show
  1. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
  2. package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
  3. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
  4. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +2 -2
  5. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
  6. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +342 -102
  7. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
  8. package/fesm2022/nanahoshi-mona-ui-editor.mjs +1054 -452
  9. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DdyHnUIr.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
  10. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-B6gq7Hu3.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-DdUY3I7P.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DG8Bu4Dy.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
  13. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CVqpbMcb.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +9 -9
  14. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  15. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +23 -0
  16. package/fesm2022/nanahoshi-mona-ui-internal.mjs +567 -33
  17. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +20 -0
  18. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +20 -0
  19. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +20 -0
  20. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +20 -0
  21. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +20 -0
  22. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +20 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +20 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +20 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +20 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +20 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +20 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +20 -0
  29. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +20 -0
  30. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
  31. package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
  32. package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
  33. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
  34. package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
  35. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
  36. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
  37. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
  38. package/fesm2022/nanahoshi-mona-ui-window.mjs +594 -311
  39. package/i18n/catalogs/en-US.messages.json +24 -4
  40. package/locales/ar-sa/ar-sa.messages.json +20 -0
  41. package/locales/de-de/de-de.messages.json +20 -0
  42. package/locales/es-es/es-es.messages.json +20 -0
  43. package/locales/fr-fr/fr-fr.messages.json +20 -0
  44. package/locales/id-id/id-id.messages.json +20 -0
  45. package/locales/it-it/it-it.messages.json +20 -0
  46. package/locales/ja-jp/ja-jp.messages.json +20 -0
  47. package/locales/ko-kr/ko-kr.messages.json +20 -0
  48. package/locales/pt-br/pt-br.messages.json +20 -0
  49. package/locales/ru-ru/ru-ru.messages.json +20 -0
  50. package/locales/tr-tr/tr-tr.messages.json +20 -0
  51. package/locales/zh-cn/zh-cn.messages.json +20 -0
  52. package/locales/zh-tw/zh-tw.messages.json +20 -0
  53. package/package.json +1 -1
  54. package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
  55. package/types/nanahoshi-mona-ui-button.d.ts +20 -3
  56. package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
  57. package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
  58. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
  59. package/types/nanahoshi-mona-ui-editor.d.ts +118 -21
  60. package/types/nanahoshi-mona-ui-i18n.d.ts +37 -0
  61. package/types/nanahoshi-mona-ui-internal.d.ts +142 -16
  62. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +20 -0
  63. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +20 -0
  64. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +20 -0
  65. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +20 -0
  66. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +20 -0
  67. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +20 -0
  68. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +20 -0
  69. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +20 -0
  70. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +20 -0
  71. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +20 -0
  72. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +20 -0
  73. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +20 -0
  74. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +20 -0
  75. package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
  76. package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
  77. package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
  78. package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
  79. package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
  80. package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
  81. package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
  82. package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
  83. package/types/nanahoshi-mona-ui-window.d.ts +103 -14
@@ -1,13 +1,13 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, inject, DestroyRef, DOCUMENT, ElementRef, NgZone, input, afterNextRender, Pipe, ApplicationRef, Injector, signal, ViewContainerRef, computed, viewChild, TemplateRef, createComponent, Component, forwardRef, Injectable, contentChild, output, model, effect, untracked } from '@angular/core';
2
+ import { Directive, inject, DestroyRef, DOCUMENT, ElementRef, NgZone, input, afterNextRender, Pipe, Injector, viewChild, ViewContainerRef, computed, signal, TemplateRef, effect, untracked, isDevMode, Component, InjectionToken, forwardRef, Injectable, contentChild, output, model } from '@angular/core';
3
3
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
- import { fromEvent, Subject, asapScheduler, map, take } from 'rxjs';
5
- import { themeOverlaySurfaceClasses, createElementControlId, focusElement, setWindowStyles } from '@nanahoshi/mona-ui/internal';
4
+ import { themeOverlaySurfaceClasses, createElementControlId, focusElement, positionGlobalOverlay, inertOutside } from '@nanahoshi/mona-ui/internal';
6
5
  import { PopupDataInjectionToken, PopupCloseEvent, PopupCloseSource, PopupService } from '@nanahoshi/mona-ui/popup';
6
+ import { fromEvent, ReplaySubject, Subject, asapScheduler, take, takeUntil, merge, map } from 'rxjs';
7
7
  import * as i1 from '@angular/cdk/a11y';
8
8
  import { CdkTrapFocus } from '@angular/cdk/a11y';
9
9
  import { NgTemplateOutlet } from '@angular/common';
10
- import { LucideMinimize, LucideMaximize, LucideMinus, LucideDynamicIcon, LucideX } from '@lucide/angular';
10
+ import { LucideMinimize, LucideMaximize, LucideAppWindow, LucideMinus, LucideDynamicIcon, LucideX } from '@lucide/angular';
11
11
  import { ButtonDirective } from '@nanahoshi/mona-ui/button';
12
12
  import { MonaI18nService, mergeMessages } from '@nanahoshi/mona-ui/i18n';
13
13
  import { cva } from 'class-variance-authority';
@@ -61,8 +61,16 @@ const DEFAULT_MAX_WINDOW_WIDTH = 1200;
61
61
  const DEFAULT_MIN_WINDOW_HEIGHT = 50;
62
62
  const DEFAULT_MIN_WINDOW_WIDTH = 50;
63
63
 
64
- const KEYBOARD_MOVE_STEP = 10;
65
- const KEYBOARD_MOVE_STEP_FINE = 1;
64
+ const KEYBOARD_STEP = 10;
65
+ const KEYBOARD_STEP_FINE = 1;
66
+ /** How far the pointer travels before a press on the title bar becomes a drag, so a click or double-click isn't. */
67
+ const DRAG_THRESHOLD = 3;
68
+ /** Controls inside the title bar (its buttons, an action template) that take the pointer and keys themselves. */
69
+ const INTERACTIVE$1 = "a[href], button, input, select, textarea, [contenteditable]:not([contenteditable='false']), [tabindex]";
70
+ /**
71
+ * The window's title bar: dragging it with the pointer moves the window, and while it has focus the arrow keys move
72
+ * the window and Control (or Command) with the arrow keys resizes it. Shift makes either step 1px instead of 10px.
73
+ */
66
74
  class WindowDragHandlerDirective {
67
75
  #destroyRef;
68
76
  #document;
@@ -76,91 +84,158 @@ class WindowDragHandlerDirective {
76
84
  this.#zone = inject(NgZone);
77
85
  this.draggable = input(true, /* @ts-ignore */
78
86
  ...(ngDevMode ? [{ debugName: "draggable" }] : /* istanbul ignore next */ []));
87
+ this.maxHeight = input(/* @ts-ignore */
88
+ ...(ngDevMode ? [undefined, { debugName: "maxHeight" }] : /* istanbul ignore next */ []));
89
+ this.maxWidth = input(/* @ts-ignore */
90
+ ...(ngDevMode ? [undefined, { debugName: "maxWidth" }] : /* istanbul ignore next */ []));
91
+ this.minHeight = input(/* @ts-ignore */
92
+ ...(ngDevMode ? [undefined, { debugName: "minHeight" }] : /* istanbul ignore next */ []));
93
+ this.minWidth = input(/* @ts-ignore */
94
+ ...(ngDevMode ? [undefined, { debugName: "minWidth" }] : /* istanbul ignore next */ []));
95
+ this.resizable = input(false, /* @ts-ignore */
96
+ ...(ngDevMode ? [{ debugName: "resizable" }] : /* istanbul ignore next */ []));
79
97
  this.windowRef = input.required(/* @ts-ignore */
80
98
  ...(ngDevMode ? [{ debugName: "windowRef" }] : /* istanbul ignore next */ []));
81
99
  afterNextRender({
82
- read: () => this.#setEvents()
100
+ write: () => this.#setEvents()
83
101
  });
84
102
  this.#destroyRef.onDestroy(() => this.#activeCleanup?.());
85
103
  }
86
104
  onKeydown(event) {
87
- if (!this.draggable()) {
105
+ // Keys pressed on the title bar's own buttons, or on controls in an action template, are theirs.
106
+ if (event.target !== this.#hostElementRef.nativeElement || event.altKey) {
88
107
  return;
89
108
  }
90
- const step = event.shiftKey ? KEYBOARD_MOVE_STEP_FINE : KEYBOARD_MOVE_STEP;
91
- const element = this.windowRef().element;
92
- const innerWidth = this.#document.defaultView?.innerWidth || DEFAULT_MAX_WINDOW_WIDTH;
93
- const innerHeight = this.#document.defaultView?.innerHeight || DEFAULT_MAX_WINDOW_HEIGHT;
94
- const initialTop = element.getBoundingClientRect().top;
95
- const initialLeft = element.getBoundingClientRect().left;
96
- let top = initialTop;
97
- let left = initialLeft;
98
- switch (event.key) {
99
- case "ArrowUp":
100
- top = Math.max(0, initialTop - step);
101
- break;
102
- case "ArrowDown":
103
- top = Math.min(innerHeight, initialTop + step);
104
- break;
105
- case "ArrowLeft":
106
- left = Math.max(0, initialLeft - step);
107
- break;
108
- case "ArrowRight":
109
- left = Math.min(innerWidth, initialLeft + step);
110
- break;
111
- default:
112
- return;
109
+ const deltas = {
110
+ ArrowDown: [0, 1],
111
+ ArrowLeft: [-1, 0],
112
+ ArrowRight: [1, 0],
113
+ ArrowUp: [0, -1]
114
+ };
115
+ const delta = deltas[event.key];
116
+ if (!delta) {
117
+ return;
118
+ }
119
+ const step = event.shiftKey ? KEYBOARD_STEP_FINE : KEYBOARD_STEP;
120
+ const [deltaX, deltaY] = [delta[0] * step, delta[1] * step];
121
+ const handled = event.ctrlKey || event.metaKey ? this.#resizeBy(deltaX, deltaY) : this.#moveBy(deltaX, deltaY);
122
+ if (handled) {
123
+ event.preventDefault();
113
124
  }
114
- event.preventDefault();
115
- element.style.top = `${top}px`;
116
- element.style.left = `${left}px`;
117
- this.windowRef().moveStart$$.next();
118
- this.windowRef().move$$.next({ top, left });
119
- this.windowRef().moveEnd$$.next();
120
125
  }
121
- #onPointerDown(event) {
126
+ /** Moves the window by the given amount, keeping all of it in the viewport. */
127
+ #moveBy(deltaX, deltaY) {
122
128
  if (!this.draggable()) {
129
+ return false;
130
+ }
131
+ const windowRef = this.windowRef();
132
+ const rect = windowRef.element.getBoundingClientRect();
133
+ const { innerHeight, innerWidth } = this.#viewport();
134
+ const left = Math.round(Math.min(Math.max(0, rect.left + deltaX), Math.max(0, innerWidth - rect.width)));
135
+ const top = Math.round(Math.min(Math.max(0, rect.top + deltaY), Math.max(0, innerHeight - rect.height)));
136
+ windowRef.moveStart$$.next();
137
+ windowRef.move({ left, top });
138
+ windowRef.move$$.next({ left, top });
139
+ windowRef.moveEnd$$.next();
140
+ return true;
141
+ }
142
+ #onPointerDown(event) {
143
+ if (!this.draggable() || event.button !== 0 || !event.isPrimary) {
123
144
  return;
124
145
  }
125
- const element = this.windowRef().element;
146
+ const host = this.#hostElementRef.nativeElement;
147
+ const target = event.target instanceof Element ? event.target.closest(INTERACTIVE$1) : null;
148
+ if (target && target !== host && host.contains(target)) {
149
+ return;
150
+ }
151
+ const windowRef = this.windowRef();
152
+ const rect = windowRef.element.getBoundingClientRect();
153
+ const { innerHeight, innerWidth } = this.#viewport();
154
+ const pointerId = event.pointerId;
126
155
  const initialX = event.clientX;
127
156
  const initialY = event.clientY;
128
- const initialTop = element.getBoundingClientRect().top;
129
- const initialLeft = element.getBoundingClientRect().left;
130
- const innerWidth = this.#document.defaultView?.innerWidth || DEFAULT_MAX_WINDOW_WIDTH;
131
- const innerHeight = this.#document.defaultView?.innerHeight || DEFAULT_MAX_WINDOW_HEIGHT;
132
- let dragInitiated = false;
133
- const onPointerMove = (event) => {
134
- if (!dragInitiated) {
135
- dragInitiated = true;
136
- this.windowRef().moveStart$$.next();
157
+ let dragging = false;
158
+ const onPointerMove = (moveEvent) => {
159
+ if (moveEvent.pointerId !== pointerId) {
160
+ return;
161
+ }
162
+ const deltaX = moveEvent.clientX - initialX;
163
+ const deltaY = moveEvent.clientY - initialY;
164
+ if (!dragging) {
165
+ if (Math.hypot(deltaX, deltaY) < DRAG_THRESHOLD) {
166
+ return;
167
+ }
168
+ dragging = true;
169
+ windowRef.moveStart$$.next();
137
170
  }
138
- if (event.clientX < 0 || event.clientX > innerWidth || event.clientY < 0 || event.clientY > innerHeight) {
171
+ if (moveEvent.clientX < 0 ||
172
+ moveEvent.clientX > innerWidth ||
173
+ moveEvent.clientY < 0 ||
174
+ moveEvent.clientY > innerHeight) {
139
175
  return;
140
176
  }
141
- const deltaX = event.clientX - initialX;
142
- const deltaY = event.clientY - initialY;
143
- const top = initialTop + deltaY;
144
- const left = initialLeft + deltaX;
145
- element.style.top = `${top}px`;
146
- element.style.left = `${left}px`;
147
- this.windowRef().move$$.next({ top, left });
177
+ // The title bar stays below the top edge, where it can still be grabbed.
178
+ const top = Math.max(0, Math.round(rect.top + deltaY));
179
+ const left = Math.round(rect.left + deltaX);
180
+ windowRef.move({ left, top });
181
+ windowRef.move$$.next({ left, top });
148
182
  };
149
183
  const cleanup = () => {
150
184
  this.#document.removeEventListener("pointermove", onPointerMove);
151
- this.#document.removeEventListener("pointerup", onPointerUp);
185
+ this.#document.removeEventListener("pointerup", onPointerEnd);
186
+ this.#document.removeEventListener("pointercancel", onPointerEnd);
187
+ if (host.hasPointerCapture?.(pointerId)) {
188
+ host.releasePointerCapture(pointerId);
189
+ }
152
190
  this.#activeCleanup = undefined;
153
191
  };
154
- const onPointerUp = () => {
192
+ const onPointerEnd = (endEvent) => {
193
+ if (endEvent.pointerId !== pointerId) {
194
+ return;
195
+ }
155
196
  cleanup();
156
- if (dragInitiated) {
157
- this.windowRef().moveEnd$$.next();
158
- dragInitiated = false;
197
+ if (dragging) {
198
+ dragging = false;
199
+ windowRef.moveEnd$$.next();
159
200
  }
160
201
  };
202
+ this.#activeCleanup?.();
161
203
  this.#activeCleanup = cleanup;
204
+ try {
205
+ host.setPointerCapture?.(pointerId);
206
+ }
207
+ catch {
208
+ // The pointer may already be gone; the document listeners still finish the drag.
209
+ }
162
210
  this.#document.addEventListener("pointermove", onPointerMove);
163
- this.#document.addEventListener("pointerup", onPointerUp);
211
+ this.#document.addEventListener("pointerup", onPointerEnd);
212
+ this.#document.addEventListener("pointercancel", onPointerEnd);
213
+ }
214
+ /**
215
+ * Resizes the window from its bottom and right edges by the given amount, within its minimum and maximum sizes
216
+ * and the viewport.
217
+ */
218
+ #resizeBy(deltaX, deltaY) {
219
+ if (!this.resizable()) {
220
+ return false;
221
+ }
222
+ const windowRef = this.windowRef();
223
+ const rect = windowRef.element.getBoundingClientRect();
224
+ const { innerHeight, innerWidth } = this.#viewport();
225
+ const clamp = (value, min, max) => Math.round(Math.max(min, Math.min(value, max)));
226
+ const minWidth = this.minWidth() ?? DEFAULT_MIN_WINDOW_WIDTH;
227
+ const minHeight = this.minHeight() ?? DEFAULT_MIN_WINDOW_HEIGHT;
228
+ const maxWidth = Math.max(minWidth, Math.min(this.maxWidth() ?? innerWidth, innerWidth - rect.left));
229
+ const maxHeight = Math.max(minHeight, Math.min(this.maxHeight() ?? innerHeight, innerHeight - rect.top));
230
+ const width = deltaX === 0 ? Math.round(rect.width) : clamp(rect.width + deltaX, minWidth, maxWidth);
231
+ const height = deltaY === 0 ? Math.round(rect.height) : clamp(rect.height + deltaY, minHeight, maxHeight);
232
+ const left = Math.round(rect.left);
233
+ const top = Math.round(rect.top);
234
+ // Pin the window where it is, so a centered window grows from its top-left corner like a dragged edge.
235
+ windowRef.move({ left, top });
236
+ windowRef.resize({ height, width });
237
+ windowRef.resize$$.next({ height, left, top, width });
238
+ return true;
164
239
  }
165
240
  #setEvents() {
166
241
  this.#zone.runOutsideAngular(() => {
@@ -169,8 +244,15 @@ class WindowDragHandlerDirective {
169
244
  .subscribe(event => this.#onPointerDown(event));
170
245
  });
171
246
  }
247
+ #viewport() {
248
+ const view = this.#document.defaultView;
249
+ return {
250
+ innerHeight: view?.innerHeight || DEFAULT_MAX_WINDOW_HEIGHT,
251
+ innerWidth: view?.innerWidth || DEFAULT_MAX_WINDOW_WIDTH
252
+ };
253
+ }
172
254
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowDragHandlerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
173
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: WindowDragHandlerDirective, isStandalone: true, selector: "div[monaWindowDragHandler]", inputs: { draggable: { classPropertyName: "draggable", publicName: "draggable", isSignal: true, isRequired: false, transformFunction: null }, windowRef: { classPropertyName: "windowRef", publicName: "windowRef", isSignal: true, isRequired: true, transformFunction: null } }, host: { listeners: { "keydown": "onKeydown($event)" } }, ngImport: i0 }); }
255
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: WindowDragHandlerDirective, isStandalone: true, selector: "div[monaWindowDragHandler]", inputs: { draggable: { classPropertyName: "draggable", publicName: "draggable", isSignal: true, isRequired: false, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null }, minHeight: { classPropertyName: "minHeight", publicName: "minHeight", isSignal: true, isRequired: false, transformFunction: null }, minWidth: { classPropertyName: "minWidth", publicName: "minWidth", isSignal: true, isRequired: false, transformFunction: null }, resizable: { classPropertyName: "resizable", publicName: "resizable", isSignal: true, isRequired: false, transformFunction: null }, windowRef: { classPropertyName: "windowRef", publicName: "windowRef", isSignal: true, isRequired: true, transformFunction: null } }, host: { listeners: { "keydown": "onKeydown($event)" } }, ngImport: i0 }); }
174
256
  }
175
257
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowDragHandlerDirective, decorators: [{
176
258
  type: Directive,
@@ -180,10 +262,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
180
262
  "(keydown)": "onKeydown($event)"
181
263
  }
182
264
  }]
183
- }], ctorParameters: () => [], propDecorators: { draggable: [{ type: i0.Input, args: [{ isSignal: true, alias: "draggable", required: false }] }], windowRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowRef", required: true }] }] } });
265
+ }], ctorParameters: () => [], propDecorators: { draggable: [{ type: i0.Input, args: [{ isSignal: true, alias: "draggable", required: false }] }], maxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxHeight", required: false }] }], maxWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxWidth", required: false }] }], minHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "minHeight", required: false }] }], minWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "minWidth", required: false }] }], resizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "resizable", required: false }] }], windowRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowRef", required: true }] }] } });
184
266
 
185
- const KEYBOARD_RESIZE_STEP = 10;
186
- const KEYBOARD_RESIZE_STEP_FINE = 1;
267
+ /**
268
+ * A resize handle on a window's edge or corner, for the pointer. The keyboard resizes from the title bar instead
269
+ * (see `WindowDragHandlerDirective`), so the handles stay out of the Tab order.
270
+ */
187
271
  class WindowResizeHandlerDirective {
188
272
  #destroyRef;
189
273
  #document;
@@ -208,54 +292,16 @@ class WindowResizeHandlerDirective {
208
292
  this.windowRef = input.required(/* @ts-ignore */
209
293
  ...(ngDevMode ? [{ debugName: "windowRef" }] : /* istanbul ignore next */ []));
210
294
  afterNextRender({
211
- read: () => this.#setEvents()
295
+ write: () => this.#setEvents()
212
296
  });
213
297
  this.#destroyRef.onDestroy(() => this.#activeCleanup?.());
214
298
  }
215
- onKeydown(event) {
216
- const step = event.shiftKey ? KEYBOARD_RESIZE_STEP_FINE : KEYBOARD_RESIZE_STEP;
217
- let deltaX = 0;
218
- let deltaY = 0;
219
- switch (event.key) {
220
- case "ArrowUp":
221
- deltaY = -step;
222
- break;
223
- case "ArrowDown":
224
- deltaY = step;
225
- break;
226
- case "ArrowLeft":
227
- deltaX = -step;
228
- break;
229
- case "ArrowRight":
230
- deltaX = step;
231
- break;
232
- default:
233
- return;
234
- }
235
- const element = this.windowRef().element;
236
- const rect = element.getBoundingClientRect();
237
- const initial = { width: rect.width, height: rect.height, top: rect.top, left: rect.left };
238
- const result = this.#computeResize(this.direction(), deltaX, deltaY, initial, this.#bounds());
239
- if (!result) {
240
- return;
241
- }
242
- event.preventDefault();
243
- this.#applyResize(element, result, initial);
244
- }
245
- #applyResize(element, result, initial) {
246
- if (result.height != null) {
247
- element.style.height = `${result.height}px`;
248
- }
249
- if (result.top != null) {
250
- element.style.top = `${result.top}px`;
251
- }
252
- if (result.width != null) {
253
- element.style.width = `${result.width}px`;
254
- }
255
- if (result.left != null) {
256
- element.style.left = `${result.left}px`;
257
- }
258
- this.windowRef().resize$$.next({
299
+ #applyResize(result, initial) {
300
+ const windowRef = this.windowRef();
301
+ // Pin both axes first, so the edge that isn't dragged stays put even when the window was centered.
302
+ windowRef.move({ left: result.left ?? initial.left, top: result.top ?? initial.top });
303
+ windowRef.resize({ height: result.height, width: result.width });
304
+ windowRef.resize$$.next({
259
305
  width: result.width ?? initial.width,
260
306
  height: result.height ?? initial.height,
261
307
  left: result.left ?? initial.left,
@@ -315,7 +361,7 @@ class WindowResizeHandlerDirective {
315
361
  }
316
362
  height = initial.height - deltaY;
317
363
  top = initial.top + deltaY;
318
- if (initial.width + deltaX < 100 || initial.left + initial.width + deltaX > innerWidth) {
364
+ if (initial.width + deltaX < minWidth || initial.left + initial.width + deltaX > innerWidth) {
319
365
  return null;
320
366
  }
321
367
  width = initial.width + deltaX;
@@ -379,6 +425,12 @@ class WindowResizeHandlerDirective {
379
425
  return { width, height, left, top };
380
426
  }
381
427
  #onPointerDown(event) {
428
+ if (event.button !== 0 || !event.isPrimary) {
429
+ return;
430
+ }
431
+ event.preventDefault();
432
+ const handle = this.#hostElementRef.nativeElement;
433
+ const pointerId = event.pointerId;
382
434
  const element = this.windowRef().element;
383
435
  const rect = element.getBoundingClientRect();
384
436
  const initial = { width: rect.width, height: rect.height, top: rect.top, left: rect.left };
@@ -389,28 +441,45 @@ class WindowResizeHandlerDirective {
389
441
  this.#document.onselectstart = () => false;
390
442
  this.#document.ondragstart = () => false;
391
443
  const bounds = this.#bounds();
392
- const onPointerMove = (event) => {
393
- const deltaX = event.clientX - initialX;
394
- const deltaY = event.clientY - initialY;
444
+ const onPointerMove = (moveEvent) => {
445
+ if (moveEvent.pointerId !== pointerId) {
446
+ return;
447
+ }
448
+ const deltaX = moveEvent.clientX - initialX;
449
+ const deltaY = moveEvent.clientY - initialY;
395
450
  const result = this.#computeResize(this.direction(), deltaX, deltaY, initial, bounds);
396
451
  if (!result) {
397
452
  return;
398
453
  }
399
- this.#applyResize(element, result, initial);
454
+ this.#applyResize(result, initial);
400
455
  };
401
456
  const cleanup = () => {
402
457
  this.#document.removeEventListener("pointermove", onPointerMove);
403
- this.#document.removeEventListener("pointerup", onPointerUp);
458
+ this.#document.removeEventListener("pointerup", onPointerEnd);
459
+ this.#document.removeEventListener("pointercancel", onPointerEnd);
404
460
  this.#document.onselectstart = oldSelectStart;
405
461
  this.#document.ondragstart = oldDragStart;
462
+ if (handle.hasPointerCapture?.(pointerId)) {
463
+ handle.releasePointerCapture(pointerId);
464
+ }
406
465
  this.#activeCleanup = undefined;
407
466
  };
408
- const onPointerUp = () => {
409
- cleanup();
467
+ const onPointerEnd = (endEvent) => {
468
+ if (endEvent.pointerId === pointerId) {
469
+ cleanup();
470
+ }
410
471
  };
472
+ this.#activeCleanup?.();
411
473
  this.#activeCleanup = cleanup;
474
+ try {
475
+ handle.setPointerCapture?.(pointerId);
476
+ }
477
+ catch {
478
+ // The pointer may already be gone; the document listeners still finish the resize.
479
+ }
412
480
  this.#document.addEventListener("pointermove", onPointerMove);
413
- this.#document.addEventListener("pointerup", onPointerUp);
481
+ this.#document.addEventListener("pointerup", onPointerEnd);
482
+ this.#document.addEventListener("pointercancel", onPointerEnd);
414
483
  }
415
484
  #setEvents() {
416
485
  this.#zone.runOutsideAngular(() => {
@@ -420,15 +489,12 @@ class WindowResizeHandlerDirective {
420
489
  });
421
490
  }
422
491
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowResizeHandlerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
423
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: WindowResizeHandlerDirective, isStandalone: true, selector: "div[monaWindowResizeHandler]", inputs: { direction: { classPropertyName: "direction", publicName: "direction", isSignal: true, isRequired: true, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null }, minHeight: { classPropertyName: "minHeight", publicName: "minHeight", isSignal: true, isRequired: false, transformFunction: null }, minWidth: { classPropertyName: "minWidth", publicName: "minWidth", isSignal: true, isRequired: false, transformFunction: null }, windowRef: { classPropertyName: "windowRef", publicName: "windowRef", isSignal: true, isRequired: true, transformFunction: null } }, host: { listeners: { "keydown": "onKeydown($event)" } }, ngImport: i0 }); }
492
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: WindowResizeHandlerDirective, isStandalone: true, selector: "div[monaWindowResizeHandler]", inputs: { direction: { classPropertyName: "direction", publicName: "direction", isSignal: true, isRequired: true, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null }, minHeight: { classPropertyName: "minHeight", publicName: "minHeight", isSignal: true, isRequired: false, transformFunction: null }, minWidth: { classPropertyName: "minWidth", publicName: "minWidth", isSignal: true, isRequired: false, transformFunction: null }, windowRef: { classPropertyName: "windowRef", publicName: "windowRef", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 }); }
424
493
  }
425
494
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowResizeHandlerDirective, decorators: [{
426
495
  type: Directive,
427
496
  args: [{
428
- selector: "div[monaWindowResizeHandler]",
429
- host: {
430
- "(keydown)": "onKeydown($event)"
431
- }
497
+ selector: "div[monaWindowResizeHandler]"
432
498
  }]
433
499
  }], ctorParameters: () => [], propDecorators: { direction: [{ type: i0.Input, args: [{ isSignal: true, alias: "direction", required: true }] }], maxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxHeight", required: false }] }], maxWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxWidth", required: false }] }], minHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "minHeight", required: false }] }], minWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "minWidth", required: false }] }], windowRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowRef", required: true }] }] } });
434
500
 
@@ -439,6 +505,7 @@ const WINDOW_DEFAULT_MESSAGES = {
439
505
  closeWindow: "Close window",
440
506
  maximize: "Maximize",
441
507
  minimize: "Minimize",
508
+ moveOrResizeWindow: "Move or resize window. Use arrow keys to move, or Control and arrow keys to resize.",
442
509
  moveWindow: "Move window. Use arrow keys to move.",
443
510
  resizeBottom: "Resize window from the bottom. Use arrow keys to resize.",
444
511
  resizeBottomLeft: "Resize window from the bottom-left corner. Use arrow keys to resize.",
@@ -448,6 +515,7 @@ const WINDOW_DEFAULT_MESSAGES = {
448
515
  resizeTop: "Resize window from the top. Use arrow keys to resize.",
449
516
  resizeTopLeft: "Resize window from the top-left corner. Use arrow keys to resize.",
450
517
  resizeTopRight: "Resize window from the top-right corner. Use arrow keys to resize.",
518
+ resizeWindow: "Resize window. Use Control and arrow keys to resize.",
451
519
  restore: "Restore"
452
520
  };
453
521
 
@@ -486,7 +554,7 @@ const windowContentThemeVariants = cva(`
486
554
  [scrollbar-color:var(--color-scrollbar-thumb)_var(--color-scrollbar-track)] [scrollbar-width:thin]
487
555
  `);
488
556
  const windowResizerThemeVariants = cva(`
489
- absolute flex
557
+ absolute flex touch-none
490
558
  `, {
491
559
  variants: {
492
560
  position: {
@@ -554,36 +622,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
554
622
  }]
555
623
  }] });
556
624
 
625
+ /** Targets inside the title bar whose double-click is their own. */
626
+ const INTERACTIVE = "a[href], button, input, select, textarea, [contenteditable]:not([contenteditable='false'])";
557
627
  class WindowContentComponent {
558
- #appRef;
559
- #document;
628
+ #destroyRef;
560
629
  #hostElementRef;
561
630
  #i18n;
562
631
  #injector;
563
632
  #localeMessages;
564
- #sizeBeforeMaximize;
565
- #sizeBeforeMinimize;
566
633
  #trapFocus;
567
- #viewContainerRef;
634
+ #beforeMaximize;
635
+ #beforeMinimize;
636
+ #componentRef;
568
637
  constructor() {
569
- this.#appRef = inject(ApplicationRef);
570
- this.#document = inject(DOCUMENT);
638
+ this.#destroyRef = inject(DestroyRef);
571
639
  this.#hostElementRef = inject(ElementRef);
572
640
  this.#i18n = inject(MonaI18nService);
573
641
  this.#injector = inject(Injector);
574
642
  this.#localeMessages = this.#i18n.componentMessages("window", WINDOW_DEFAULT_MESSAGES);
575
- this.#sizeBeforeMaximize = signal({ width: 0, height: 0, top: 0, left: 0 }, /* @ts-ignore */
576
- ...(ngDevMode ? [{ debugName: "#sizeBeforeMaximize" }] : /* istanbul ignore next */ []));
577
- this.#sizeBeforeMinimize = signal(0, /* @ts-ignore */
578
- ...(ngDevMode ? [{ debugName: "#sizeBeforeMinimize" }] : /* istanbul ignore next */ []));
579
643
  this.#trapFocus = inject(CdkTrapFocus);
580
- this.#viewContainerRef = inject(ViewContainerRef);
644
+ this.#beforeMaximize = null;
645
+ this.#beforeMinimize = null;
646
+ this.#componentRef = null;
647
+ this.componentHost = viewChild("componentHost", { ...(ngDevMode ? { debugName: "componentHost" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
581
648
  this.baseClass = computed(() => {
582
649
  const rounded = this.windowData.rounded;
583
650
  return windowBaseThemeVariants({ rounded });
584
651
  }, /* @ts-ignore */
585
652
  ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
586
- this.componentAnchor = viewChild.required("componentAnchor", { ...(ngDevMode ? { debugName: "componentAnchor" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
587
653
  this.contentClass = computed(() => {
588
654
  return windowContentThemeVariants();
589
655
  }, /* @ts-ignore */
@@ -593,16 +659,9 @@ class WindowContentComponent {
593
659
  return windowContentContainerThemeVariants({ rounded });
594
660
  }, /* @ts-ignore */
595
661
  ...(ngDevMode ? [{ debugName: "contentContainerClass" }] : /* istanbul ignore next */ []));
596
- this.contentTemplate = computed(() => {
597
- const content = this.windowData.content;
598
- return content instanceof TemplateRef ? content : null;
599
- }, /* @ts-ignore */
600
- ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
601
- this.contentType = signal("template", /* @ts-ignore */
602
- ...(ngDevMode ? [{ debugName: "contentType" }] : /* istanbul ignore next */ []));
603
662
  this.headerId = createElementControlId();
604
663
  this.maximizeIcon = computed(() => {
605
- return this.maximized() && !this.minimized() ? LucideMinimize : LucideMaximize;
664
+ return this.maximized() ? LucideMinimize : LucideMaximize;
606
665
  }, /* @ts-ignore */
607
666
  ...(ngDevMode ? [{ debugName: "maximizeIcon" }] : /* istanbul ignore next */ []));
608
667
  this.maximized = signal(false, /* @ts-ignore */
@@ -611,8 +670,22 @@ class WindowContentComponent {
611
670
  return mergeMessages(this.#localeMessages(), this.windowData.messages);
612
671
  }, /* @ts-ignore */
613
672
  ...(ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []));
673
+ this.minimizeIcon = computed(() => {
674
+ return this.minimized() ? LucideAppWindow : LucideMinus;
675
+ }, /* @ts-ignore */
676
+ ...(ngDevMode ? [{ debugName: "minimizeIcon" }] : /* istanbul ignore next */ []));
614
677
  this.minimized = signal(false, /* @ts-ignore */
615
678
  ...(ngDevMode ? [{ debugName: "minimized" }] : /* istanbul ignore next */ []));
679
+ this.resizeDirections = [
680
+ "north",
681
+ "south",
682
+ "east",
683
+ "west",
684
+ "northeast",
685
+ "northwest",
686
+ "southeast",
687
+ "southwest"
688
+ ];
616
689
  this.titleBarActionClass = computed(() => {
617
690
  return windowTitleBarActionThemeVariants();
618
691
  }, /* @ts-ignore */
@@ -623,6 +696,19 @@ class WindowContentComponent {
623
696
  return windowTitleBarThemeVariants({ look, rounded });
624
697
  }, /* @ts-ignore */
625
698
  ...(ngDevMode ? [{ debugName: "titleBarClass" }] : /* istanbul ignore next */ []));
699
+ /** The title bar's name, which also says which keys move or resize the window; none when it does neither. */
700
+ this.titleBarLabel = computed(() => {
701
+ const { draggable, resizable } = this.windowData;
702
+ const messages = this.messages();
703
+ if (draggable && resizable) {
704
+ return messages.moveOrResizeWindow;
705
+ }
706
+ if (draggable) {
707
+ return messages.moveWindow;
708
+ }
709
+ return resizable ? messages.resizeWindow : null;
710
+ }, /* @ts-ignore */
711
+ ...(ngDevMode ? [{ debugName: "titleBarLabel" }] : /* istanbul ignore next */ []));
626
712
  this.titleClass = computed(() => {
627
713
  const look = this.windowData.look;
628
714
  return windowTitleThemeVariants({ look });
@@ -633,89 +719,128 @@ class WindowContentComponent {
633
719
  }, /* @ts-ignore */
634
720
  ...(ngDevMode ? [{ debugName: "titleContainerClass" }] : /* istanbul ignore next */ []));
635
721
  this.windowData = inject(PopupDataInjectionToken);
722
+ this.windowRef = this.windowData.windowReference.windowRef;
723
+ const content = this.windowData.content;
724
+ this.contentTemplate = content instanceof TemplateRef ? content : null;
725
+ this.contentComponent = content && !(content instanceof TemplateRef) ? content : null;
726
+ this.hasTitle = !!this.windowData.title || !!this.windowData.titleTemplate;
636
727
  this.#trapFocus.autoCapture = true;
637
728
  this.#trapFocus.enabled = this.windowData.modal ?? false;
638
- if (this.windowData.content instanceof TemplateRef) {
639
- this.contentType.set("template");
640
- }
641
- else if (this.windowData.content) {
642
- this.contentType.set("component");
643
- this.componentRef = createComponent(this.windowData.content, {
644
- environmentInjector: this.#appRef.injector,
645
- elementInjector: this.#injector
646
- });
647
- }
729
+ effect(() => {
730
+ const host = this.componentHost();
731
+ untracked(() => this.#renderComponent(host));
732
+ });
733
+ // Capture phase: the window is raised before the title bar captures the pointer for a drag, since moving
734
+ // the overlay in the DOM would release that capture.
735
+ const raise = () => this.windowData.windowReference.bringToFront();
736
+ const host = this.#hostElementRef.nativeElement;
737
+ host.addEventListener("pointerdown", raise, { capture: true });
738
+ this.#destroyRef.onDestroy(() => {
739
+ host.removeEventListener("pointerdown", raise, { capture: true });
740
+ this.#componentRef?.destroy();
741
+ this.windowData.windowReference.setComponentRef(undefined);
742
+ });
648
743
  afterNextRender({
649
- read: () => {
650
- this.#createView();
744
+ write: () => {
651
745
  this.focusElement();
746
+ if (isDevMode()) {
747
+ this.#warnIfUnnamed();
748
+ }
652
749
  }
653
750
  });
654
751
  }
655
752
  onCloseClick(event) {
656
753
  this.closeWindow(event);
657
754
  }
755
+ /** Focus arriving from outside raises the window, as a click does. */
756
+ onFocusIn(event) {
757
+ const from = event.relatedTarget;
758
+ if (from instanceof Node && this.#hostElementRef.nativeElement.contains(from)) {
759
+ return;
760
+ }
761
+ this.windowData.windowReference.bringToFront();
762
+ }
658
763
  onMaximizeClick() {
659
- const innerWidth = this.#document.defaultView?.innerWidth;
660
- const innerHeight = this.#document.defaultView?.innerHeight;
661
764
  if (this.minimized()) {
662
- this.minimized.set(false);
663
- this.windowData.windowReference.resize({
664
- width: this.maximized() ? innerWidth : this.#sizeBeforeMaximize().width,
665
- height: this.maximized() ? innerHeight : this.#sizeBeforeMaximize().height,
666
- center: false
667
- });
668
- return;
765
+ this.#restoreFromMinimize();
669
766
  }
670
767
  if (this.maximized()) {
671
- this.maximized.set(false);
672
- this.windowData.windowReference.resize({
673
- width: this.#sizeBeforeMaximize().width,
674
- height: this.#sizeBeforeMaximize().height
675
- });
676
- this.windowData.windowReference.move({
677
- top: this.#sizeBeforeMaximize().top,
678
- left: this.#sizeBeforeMaximize().left
679
- });
768
+ this.#restoreFromMaximize();
680
769
  }
681
770
  else {
682
- const element = this.windowData.windowReference.element;
683
- this.#sizeBeforeMaximize.set({
684
- width: this.windowData.windowReference.width,
685
- height: this.windowData.windowReference.height,
686
- top: element.offsetTop,
687
- left: element.offsetLeft
688
- });
689
- this.maximized.set(true);
690
- this.windowData.windowReference.resize({
691
- width: innerWidth,
692
- height: innerHeight
693
- });
694
- this.windowData.windowReference.move({ top: 0, left: 0 });
771
+ this.#maximize();
695
772
  }
696
773
  }
697
774
  onMinimizeClick() {
698
775
  if (this.minimized()) {
699
- this.minimized.set(false);
700
- this.windowData.windowReference.resize({
701
- width: this.windowData.windowReference.width,
702
- height: this.#sizeBeforeMinimize()
703
- });
776
+ this.#restoreFromMinimize();
704
777
  }
705
778
  else {
706
- this.#sizeBeforeMinimize.set(this.windowData.windowReference.height);
707
- this.minimized.set(true);
708
- this.windowData.windowReference.resize({
709
- width: this.windowData.windowReference.width,
710
- height: undefined
711
- });
779
+ this.#minimize();
712
780
  }
713
781
  }
714
- closeWindow(event) {
715
- const closeEvent = new PopupCloseEvent({ event, via: PopupCloseSource.CloseButton, originalEvent: event });
716
- if (this.windowData.preventClose && this.windowData.preventClose(closeEvent)) {
782
+ onTitleBarDoubleClick(event) {
783
+ if (!this.windowData.maximizable) {
784
+ return;
785
+ }
786
+ const target = event.target instanceof Element ? event.target.closest(INTERACTIVE) : null;
787
+ if (target) {
788
+ return;
789
+ }
790
+ this.onMaximizeClick();
791
+ }
792
+ #maximize() {
793
+ const reference = this.windowData.windowReference;
794
+ const { height, width } = reference.size;
795
+ this.#beforeMaximize = { placement: reference.placement, size: { height, width } };
796
+ this.maximized.set(true);
797
+ // CSS lengths follow the viewport as it resizes, within the window's maxWidth and maxHeight.
798
+ reference.setSize({ height: "100dvh", width: "100dvw" });
799
+ reference.center();
800
+ }
801
+ #minimize() {
802
+ const reference = this.windowData.windowReference;
803
+ const { height, minHeight, width } = reference.size;
804
+ this.#beforeMinimize = { height, minHeight, width };
805
+ this.minimized.set(true);
806
+ // Keep the width it has, so a window sized by its content doesn't shrink to its title.
807
+ reference.setSize({ height: "fit-content", minHeight: 0, width: width ?? reference.width });
808
+ }
809
+ #renderComponent(host) {
810
+ const type = this.contentComponent;
811
+ if (!host || !type || this.#componentRef) {
717
812
  return;
718
813
  }
814
+ host.clear();
815
+ this.#componentRef = host.createComponent(type, { injector: this.#injector });
816
+ this.windowData.windowReference.setComponentRef(this.#componentRef);
817
+ }
818
+ #restoreFromMaximize() {
819
+ const saved = this.#beforeMaximize;
820
+ this.#beforeMaximize = null;
821
+ this.maximized.set(false);
822
+ if (saved) {
823
+ this.windowData.windowReference.setSize(saved.size);
824
+ this.windowData.windowReference.place(saved.placement);
825
+ }
826
+ }
827
+ #restoreFromMinimize() {
828
+ const saved = this.#beforeMinimize;
829
+ this.#beforeMinimize = null;
830
+ this.minimized.set(false);
831
+ if (saved) {
832
+ this.windowData.windowReference.setSize(saved);
833
+ }
834
+ }
835
+ #warnIfUnnamed() {
836
+ if (this.hasTitle || this.windowData.ariaLabel) {
837
+ return;
838
+ }
839
+ console.warn("[Mona Window] A window needs an accessible name. Set title, a title template or ariaLabel.", this.#hostElementRef.nativeElement);
840
+ }
841
+ closeWindow(event) {
842
+ // preventClose and close$ get their say inside close(); this button doesn't ask a second time.
843
+ const closeEvent = new PopupCloseEvent({ event, via: PopupCloseSource.CloseButton, originalEvent: event });
719
844
  this.windowData.windowReference.close(closeEvent);
720
845
  }
721
846
  focusElement() {
@@ -724,20 +849,12 @@ class WindowContentComponent {
724
849
  return;
725
850
  }
726
851
  const windowElement = this.#hostElementRef.nativeElement;
727
- focusElement(windowElement, element);
728
- }
729
- #createView() {
730
- if (this.contentType() === "component" && this.componentAnchor() && this.componentRef) {
731
- const index = this.#viewContainerRef.indexOf(this.componentRef.hostView);
732
- if (index !== -1) {
733
- this.#viewContainerRef.detach(index);
734
- }
735
- this.componentAnchor().insert(this.componentRef.hostView, 0);
736
- this.componentRef.changeDetectorRef.detectChanges();
737
- }
852
+ // The focus trap moves focus to its first tabbable element after this runs; marking the target makes it
853
+ // land here instead.
854
+ focusElement(windowElement, element)?.setAttribute("cdkFocusInitial", "");
738
855
  }
739
856
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowContentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
740
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: WindowContentComponent, isStandalone: true, selector: "mona-window-content", host: { attributes: { "role": "dialog" }, properties: { "class": "baseClass()", "attr.aria-labelledby": "headerId", "attr.aria-modal": "windowData.modal ?? false" } }, viewQueries: [{ propertyName: "componentAnchor", first: true, predicate: ["componentAnchor"], descendants: true, read: ViewContainerRef, isSignal: true }], hostDirectives: [{ directive: i1.CdkTrapFocus }], ngImport: i0, template: "<div [class]=\"contentContainerClass()\">\n <div\n [class]=\"titleBarClass()\"\n monaWindowDragHandler\n (dblclick)=\"onMaximizeClick()\"\n [draggable]=\"windowData.draggable\"\n [windowRef]=\"windowData.windowReference\"\n [attr.tabindex]=\"windowData.draggable ? 0 : null\"\n [attr.aria-label]=\"windowData.draggable ? messages().moveWindow : null\">\n <div [id]=\"headerId\" [class]=\"titleContainerClass()\">\n @if (windowData.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"windowData.titleTemplate\"></ng-container>\n } @else {\n <span [class]=\"titleClass()\">{{ windowData.title ?? \"\" }}</span>\n }\n </div>\n <div [class]=\"titleBarActionClass()\">\n @if (windowData.actionTemplate) {\n <ng-container\n [ngTemplateOutlet]=\"windowData.actionTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: windowData.windowReference.windowRef }\">\n </ng-container>\n }\n @let maximizeTitle = maximized() || minimized() ? messages().restore : messages().maximize;\n @if (windowData.minimizable && !minimized()) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"messages().minimize\"\n [attr.aria-label]=\"messages().minimize\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMinimizeClick()\">\n <svg lucideMinus [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.maximizable) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"maximizeTitle\"\n [attr.aria-label]=\"maximizeTitle\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMaximizeClick()\">\n <svg [lucideIcon]=\"maximizeIcon()\" [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.closable) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"messages().close\"\n [attr.aria-label]=\"messages().closeWindow\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onCloseClick($event)\">\n <svg lucideX [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n </div>\n </div>\n @if (!minimized()) {\n <div [class]=\"contentClass()\">\n @switch (contentType()) {\n @case (\"template\") {\n <ng-container [ngTemplateOutlet]=\"contentTemplate()!\"></ng-container>\n }\n @case (\"component\") {\n <ng-container #componentAnchor></ng-container>\n }\n }\n </div>\n @if (windowData.footerTemplate) {\n <div>\n <ng-container [ngTemplateOutlet]=\"windowData.footerTemplate\"></ng-container>\n </div>\n }\n }\n @if (windowData.resizable && !maximized()) {\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"north\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeTop\"\n [class]=\"'north' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"south\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeBottom\"\n [class]=\"'south' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"east\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeRight\"\n [class]=\"'east' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"west\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeLeft\"\n [class]=\"'west' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"northeast\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeTopRight\"\n [class]=\"'northeast' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"northwest\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeTopLeft\"\n [class]=\"'northwest' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"southeast\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeBottomRight\"\n [class]=\"'southeast' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"southwest\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeBottomLeft\"\n [class]=\"'southwest' | monaResizePosition\"></div>\n }\n</div>\n", dependencies: [{ kind: "directive", type: WindowDragHandlerDirective, selector: "div[monaWindowDragHandler]", inputs: ["draggable", "windowRef"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "directive", type: WindowResizeHandlerDirective, selector: "div[monaWindowResizeHandler]", inputs: ["direction", "maxHeight", "maxWidth", "minHeight", "minWidth", "windowRef"] }, { kind: "component", type: LucideMinus, selector: "svg[lucideMinus]" }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }, { kind: "pipe", type: ResizePositionPipe, name: "monaResizePosition" }] }); }
857
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: WindowContentComponent, isStandalone: true, selector: "mona-window-content", host: { attributes: { "role": "dialog" }, listeners: { "focusin": "onFocusIn($event)" }, properties: { "class": "baseClass()", "attr.aria-label": "hasTitle ? null : windowData.ariaLabel || null", "attr.aria-labelledby": "hasTitle ? headerId : null", "attr.aria-modal": "windowData.modal ? 'true' : 'false'" } }, viewQueries: [{ propertyName: "componentHost", first: true, predicate: ["componentHost"], descendants: true, read: ViewContainerRef, isSignal: true }], hostDirectives: [{ directive: i1.CdkTrapFocus }], ngImport: i0, template: "<div [class]=\"contentContainerClass()\">\n <div\n [class]=\"titleBarClass()\"\n [class.touch-none]=\"windowData.draggable\"\n monaWindowDragHandler\n (dblclick)=\"onTitleBarDoubleClick($event)\"\n [draggable]=\"windowData.draggable && !maximized()\"\n [resizable]=\"windowData.resizable && !maximized() && !minimized()\"\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n [attr.tabindex]=\"titleBarLabel() ? 0 : null\"\n [attr.role]=\"titleBarLabel() ? 'group' : null\"\n [attr.aria-label]=\"titleBarLabel()\">\n <div [id]=\"headerId\" [class]=\"titleContainerClass()\">\n @if (windowData.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"windowData.titleTemplate\"></ng-container>\n } @else {\n <span [class]=\"titleClass()\">{{ windowData.title ?? \"\" }}</span>\n }\n </div>\n <div [class]=\"titleBarActionClass()\">\n @if (windowData.actionTemplate) {\n <ng-container\n [ngTemplateOutlet]=\"windowData.actionTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: windowRef }\">\n </ng-container>\n }\n @if (windowData.minimizable) {\n @let minimizeTitle = minimized() ? messages().restore : messages().minimize;\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"minimizeTitle\"\n [attr.aria-label]=\"minimizeTitle\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMinimizeClick()\">\n <svg [lucideIcon]=\"minimizeIcon()\" [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.maximizable) {\n @let maximizeTitle = maximized() ? messages().restore : messages().maximize;\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"maximizeTitle\"\n [attr.aria-label]=\"maximizeTitle\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMaximizeClick()\">\n <svg [lucideIcon]=\"maximizeIcon()\" [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.closable) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"messages().close\"\n [attr.aria-label]=\"messages().closeWindow\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onCloseClick($event)\">\n <svg lucideX [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n </div>\n </div>\n <!-- Minimizing hides the content instead of destroying it, so its state survives a restore. -->\n <div [class]=\"contentClass()\" [hidden]=\"minimized()\" [attr.inert]=\"minimized() ? '' : null\">\n @if (contentTemplate) {\n <ng-container\n [ngTemplateOutlet]=\"contentTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: windowData.data, windowRef: windowRef }\"></ng-container>\n } @else if (contentComponent) {\n <ng-container #componentHost></ng-container>\n }\n </div>\n @if (windowData.footerTemplate) {\n <div [hidden]=\"minimized()\" [attr.inert]=\"minimized() ? '' : null\">\n <ng-container [ngTemplateOutlet]=\"windowData.footerTemplate\"></ng-container>\n </div>\n }\n @if (windowData.resizable && !maximized() && !minimized()) {\n @for (direction of resizeDirections; track direction) {\n <div\n monaWindowResizeHandler\n aria-hidden=\"true\"\n [attr.data-direction]=\"direction\"\n [direction]=\"direction\"\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n [class]=\"direction | monaResizePosition\"></div>\n }\n }\n</div>\n", dependencies: [{ kind: "directive", type: WindowDragHandlerDirective, selector: "div[monaWindowDragHandler]", inputs: ["draggable", "maxHeight", "maxWidth", "minHeight", "minWidth", "resizable", "windowRef"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "directive", type: WindowResizeHandlerDirective, selector: "div[monaWindowResizeHandler]", inputs: ["direction", "maxHeight", "maxWidth", "minHeight", "minWidth", "windowRef"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }, { kind: "pipe", type: ResizePositionPipe, name: "monaResizePosition" }] }); }
741
858
  }
742
859
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowContentComponent, decorators: [{
743
860
  type: Component,
@@ -747,54 +864,90 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
747
864
  ButtonDirective,
748
865
  WindowResizeHandlerDirective,
749
866
  ResizePositionPipe,
750
- LucideMinus,
751
867
  LucideDynamicIcon,
752
868
  LucideX
753
869
  ], host: {
754
870
  "[class]": "baseClass()",
755
- "[attr.aria-labelledby]": "headerId",
756
- "[attr.aria-modal]": "windowData.modal ?? false",
871
+ "[attr.aria-label]": "hasTitle ? null : windowData.ariaLabel || null",
872
+ "[attr.aria-labelledby]": "hasTitle ? headerId : null",
873
+ "[attr.aria-modal]": "windowData.modal ? 'true' : 'false'",
874
+ "(focusin)": "onFocusIn($event)",
757
875
  role: "dialog"
758
- }, hostDirectives: [CdkTrapFocus], template: "<div [class]=\"contentContainerClass()\">\n <div\n [class]=\"titleBarClass()\"\n monaWindowDragHandler\n (dblclick)=\"onMaximizeClick()\"\n [draggable]=\"windowData.draggable\"\n [windowRef]=\"windowData.windowReference\"\n [attr.tabindex]=\"windowData.draggable ? 0 : null\"\n [attr.aria-label]=\"windowData.draggable ? messages().moveWindow : null\">\n <div [id]=\"headerId\" [class]=\"titleContainerClass()\">\n @if (windowData.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"windowData.titleTemplate\"></ng-container>\n } @else {\n <span [class]=\"titleClass()\">{{ windowData.title ?? \"\" }}</span>\n }\n </div>\n <div [class]=\"titleBarActionClass()\">\n @if (windowData.actionTemplate) {\n <ng-container\n [ngTemplateOutlet]=\"windowData.actionTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: windowData.windowReference.windowRef }\">\n </ng-container>\n }\n @let maximizeTitle = maximized() || minimized() ? messages().restore : messages().maximize;\n @if (windowData.minimizable && !minimized()) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"messages().minimize\"\n [attr.aria-label]=\"messages().minimize\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMinimizeClick()\">\n <svg lucideMinus [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.maximizable) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"maximizeTitle\"\n [attr.aria-label]=\"maximizeTitle\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMaximizeClick()\">\n <svg [lucideIcon]=\"maximizeIcon()\" [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.closable) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"messages().close\"\n [attr.aria-label]=\"messages().closeWindow\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onCloseClick($event)\">\n <svg lucideX [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n </div>\n </div>\n @if (!minimized()) {\n <div [class]=\"contentClass()\">\n @switch (contentType()) {\n @case (\"template\") {\n <ng-container [ngTemplateOutlet]=\"contentTemplate()!\"></ng-container>\n }\n @case (\"component\") {\n <ng-container #componentAnchor></ng-container>\n }\n }\n </div>\n @if (windowData.footerTemplate) {\n <div>\n <ng-container [ngTemplateOutlet]=\"windowData.footerTemplate\"></ng-container>\n </div>\n }\n }\n @if (windowData.resizable && !maximized()) {\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"north\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeTop\"\n [class]=\"'north' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"south\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeBottom\"\n [class]=\"'south' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"east\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeRight\"\n [class]=\"'east' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"west\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeLeft\"\n [class]=\"'west' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"northeast\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeTopRight\"\n [class]=\"'northeast' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"northwest\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeTopLeft\"\n [class]=\"'northwest' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"southeast\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeBottomRight\"\n [class]=\"'southeast' | monaResizePosition\"></div>\n <div\n monaWindowResizeHandler\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n direction=\"southwest\"\n tabindex=\"0\"\n [attr.aria-label]=\"messages().resizeBottomLeft\"\n [class]=\"'southwest' | monaResizePosition\"></div>\n }\n</div>\n" }]
759
- }], ctorParameters: () => [], propDecorators: { componentAnchor: [{ type: i0.ViewChild, args: ["componentAnchor", { ...{
760
- read: ViewContainerRef
761
- }, isSignal: true }] }] } });
876
+ }, hostDirectives: [CdkTrapFocus], template: "<div [class]=\"contentContainerClass()\">\n <div\n [class]=\"titleBarClass()\"\n [class.touch-none]=\"windowData.draggable\"\n monaWindowDragHandler\n (dblclick)=\"onTitleBarDoubleClick($event)\"\n [draggable]=\"windowData.draggable && !maximized()\"\n [resizable]=\"windowData.resizable && !maximized() && !minimized()\"\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n [attr.tabindex]=\"titleBarLabel() ? 0 : null\"\n [attr.role]=\"titleBarLabel() ? 'group' : null\"\n [attr.aria-label]=\"titleBarLabel()\">\n <div [id]=\"headerId\" [class]=\"titleContainerClass()\">\n @if (windowData.titleTemplate) {\n <ng-container [ngTemplateOutlet]=\"windowData.titleTemplate\"></ng-container>\n } @else {\n <span [class]=\"titleClass()\">{{ windowData.title ?? \"\" }}</span>\n }\n </div>\n <div [class]=\"titleBarActionClass()\">\n @if (windowData.actionTemplate) {\n <ng-container\n [ngTemplateOutlet]=\"windowData.actionTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: windowRef }\">\n </ng-container>\n }\n @if (windowData.minimizable) {\n @let minimizeTitle = minimized() ? messages().restore : messages().minimize;\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"minimizeTitle\"\n [attr.aria-label]=\"minimizeTitle\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMinimizeClick()\">\n <svg [lucideIcon]=\"minimizeIcon()\" [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.maximizable) {\n @let maximizeTitle = maximized() ? messages().restore : messages().maximize;\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"maximizeTitle\"\n [attr.aria-label]=\"maximizeTitle\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onMaximizeClick()\">\n <svg [lucideIcon]=\"maximizeIcon()\" [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n @if (windowData.closable) {\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n type=\"button\"\n [iconOnly]=\"true\"\n [rounded]=\"windowData.rounded\"\n [title]=\"messages().close\"\n [attr.aria-label]=\"messages().closeWindow\"\n (dblclick)=\"$event.stopPropagation()\"\n (click)=\"onCloseClick($event)\">\n <svg lucideX [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n </div>\n </div>\n <!-- Minimizing hides the content instead of destroying it, so its state survives a restore. -->\n <div [class]=\"contentClass()\" [hidden]=\"minimized()\" [attr.inert]=\"minimized() ? '' : null\">\n @if (contentTemplate) {\n <ng-container\n [ngTemplateOutlet]=\"contentTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: windowData.data, windowRef: windowRef }\"></ng-container>\n } @else if (contentComponent) {\n <ng-container #componentHost></ng-container>\n }\n </div>\n @if (windowData.footerTemplate) {\n <div [hidden]=\"minimized()\" [attr.inert]=\"minimized() ? '' : null\">\n <ng-container [ngTemplateOutlet]=\"windowData.footerTemplate\"></ng-container>\n </div>\n }\n @if (windowData.resizable && !maximized() && !minimized()) {\n @for (direction of resizeDirections; track direction) {\n <div\n monaWindowResizeHandler\n aria-hidden=\"true\"\n [attr.data-direction]=\"direction\"\n [direction]=\"direction\"\n [minWidth]=\"windowData.minWidth\"\n [minHeight]=\"windowData.minHeight\"\n [maxWidth]=\"windowData.maxWidth\"\n [maxHeight]=\"windowData.maxHeight\"\n [windowRef]=\"windowData.windowReference\"\n [class]=\"direction | monaResizePosition\"></div>\n }\n }\n</div>\n" }]
877
+ }], ctorParameters: () => [], propDecorators: { componentHost: [{ type: i0.ViewChild, args: ["componentHost", { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
878
+
879
+ /**
880
+ * The `data` a window was opened with, for a component given as its `content`.
881
+ * @example
882
+ * ```ts
883
+ * readonly #data = inject<{ name: string }>(WINDOW_DATA);
884
+ * ```
885
+ */
886
+ const WINDOW_DATA = new InjectionToken("WINDOW_DATA");
762
887
 
888
+ /**
889
+ * A handle on an open window.
890
+ * @typeParam R the type of the value passed to `close(value)`
891
+ */
763
892
  class WindowRef {
764
893
  #options;
765
894
  constructor(options) {
766
895
  this.#options = options;
767
896
  }
897
+ /**
898
+ * Centers the window in the viewport. It stays centered as its size changes, until it is moved.
899
+ */
768
900
  center() {
769
901
  this.#options.center();
770
902
  }
903
+ /**
904
+ * Closes the window. `close$` can still prevent it.
905
+ * @param result the value `closed$` reports
906
+ */
771
907
  close(result) {
772
908
  this.#options.close(result);
773
909
  }
774
910
  closeWithDelay(delay, result) {
775
911
  this.#options.closeWithDelay(delay, result);
776
912
  }
913
+ /**
914
+ * Moves the window, in pixels from the viewport's top-left corner. An axis that isn't given keeps its place.
915
+ */
777
916
  move(params) {
778
917
  this.#options.move(params);
779
918
  }
919
+ /**
920
+ * Resizes the window, in pixels. A dimension that isn't given keeps its size; `center` centers the window
921
+ * afterward.
922
+ */
780
923
  resize(params) {
781
924
  this.#options.resize(params);
782
925
  }
926
+ /**
927
+ * Emits before the window closes, whatever closes it. Call `preventDefault()` to keep it open. Completes once the
928
+ * window has closed.
929
+ */
783
930
  get close$() {
784
931
  return this.#options.close$;
785
932
  }
933
+ /**
934
+ * Emits how the window closed, once it has closed, then completes. Replays to late subscribers.
935
+ */
786
936
  get closed$() {
787
937
  return this.#options.closed$;
788
938
  }
789
939
  get component() {
790
940
  return this.#options.component;
791
941
  }
942
+ /** Emits while the window is dragged. Completes when it closes. */
792
943
  get drag$() {
793
944
  return this.#options.drag$;
794
945
  }
946
+ /** Emits when a drag ends. Completes when the window closes. */
795
947
  get dragEnd$() {
796
948
  return this.#options.dragEnd$;
797
949
  }
950
+ /** Emits when a drag starts. Completes when the window closes. */
798
951
  get dragStart$() {
799
952
  return this.#options.dragStart$;
800
953
  }
@@ -807,6 +960,7 @@ class WindowRef {
807
960
  get popupRef() {
808
961
  return this.#options.popupRef;
809
962
  }
963
+ /** Emits while the window is resized by the user. Completes when it closes. */
810
964
  get resize$() {
811
965
  return this.#options.resize$;
812
966
  }
@@ -815,28 +969,56 @@ class WindowRef {
815
969
  }
816
970
  }
817
971
 
972
+ /** Marks the overlay hosts that hold a window, so a window can be raised above the other windows. */
973
+ const WINDOW_HOST_CLASS = "mona-window-host";
818
974
  /**
819
975
  * @internal - used by WindowService. Do not export.
820
976
  */
821
977
  class WindowReference {
978
+ #closed$;
979
+ #document;
980
+ #options;
822
981
  #windowRef;
982
+ #left;
983
+ #top;
823
984
  constructor(options, document) {
824
- this.options = options;
825
- this.document = document;
985
+ this.#closed$ = new ReplaySubject(1);
986
+ this.#left = null;
987
+ this.#top = null;
826
988
  this.move$$ = new Subject();
827
989
  this.moveEnd$$ = new Subject();
828
990
  this.moveStart$$ = new Subject();
829
991
  this.resize$$ = new Subject();
992
+ this.#options = options;
993
+ this.#document = document;
830
994
  this.#windowRef = new WindowRef(this);
831
995
  }
996
+ /**
997
+ * Raises the window above the other open windows, keeping focus where it was inside it. Other overlays keep
998
+ * their order.
999
+ */
1000
+ bringToFront() {
1001
+ const host = this.#popupRefOrThrow.overlayRef.hostElement;
1002
+ const container = host.parentElement;
1003
+ if (!container) {
1004
+ return;
1005
+ }
1006
+ const windows = Array.from(container.children).filter(child => child.classList.contains(WINDOW_HOST_CLASS));
1007
+ const topmost = windows.at(-1);
1008
+ if (!topmost || topmost === host) {
1009
+ return;
1010
+ }
1011
+ const active = this.#document.activeElement;
1012
+ const focused = active instanceof HTMLElement && host.contains(active) ? active : null;
1013
+ topmost.after(host);
1014
+ if (focused && this.#document.activeElement !== focused) {
1015
+ focused.focus({ preventScroll: true });
1016
+ }
1017
+ }
832
1018
  center() {
833
- const element = this.#popupRefOrThrow.overlayRef.overlayElement;
834
- const width = element.getBoundingClientRect().width;
835
- const height = element.getBoundingClientRect().height;
836
- const left = (this.document.defaultView?.innerWidth || DEFAULT_MAX_WINDOW_WIDTH - width) / 2;
837
- const top = (this.document.defaultView?.innerHeight || DEFAULT_MAX_WINDOW_HEIGHT - height) / 2;
838
- element.style.left = `${left}px`;
839
- element.style.top = `${top}px`;
1019
+ this.#left = null;
1020
+ this.#top = null;
1021
+ this.#place();
840
1022
  }
841
1023
  close(result) {
842
1024
  const event = result instanceof PopupCloseEvent
@@ -847,48 +1029,95 @@ class WindowReference {
847
1029
  closeWithDelay(delay, result) {
848
1030
  asapScheduler.schedule(() => this.close(result), delay);
849
1031
  }
850
- initializePopupRef(popupRef) {
851
- this.options.popupRef = popupRef;
1032
+ /**
1033
+ * Connects the window to its popup and places it: at `left`/`top`, or centered on an axis that isn't given.
1034
+ */
1035
+ initializePopupRef(popupRef, placement = {}) {
1036
+ this.#options.popupRef = popupRef;
1037
+ this.#left = placement.left ?? null;
1038
+ this.#top = placement.top ?? null;
1039
+ popupRef.overlayRef.hostElement.classList.add(WINDOW_HOST_CLASS);
1040
+ this.#place();
1041
+ popupRef.closed.pipe(take(1)).subscribe(event => {
1042
+ this.move$$.complete();
1043
+ this.moveEnd$$.complete();
1044
+ this.moveStart$$.complete();
1045
+ this.resize$$.complete();
1046
+ this.#closed$.next({
1047
+ value: event.result,
1048
+ via: event.via ?? PopupCloseSource.Programmatic
1049
+ });
1050
+ this.#closed$.complete();
1051
+ });
852
1052
  }
1053
+ /**
1054
+ * Moves the window. An axis that isn't given keeps its place.
1055
+ */
853
1056
  move(params) {
854
- const element = this.#popupRefOrThrow.overlayRef.overlayElement;
855
- const top = params.top != null ? `${params.top}px` : ``;
856
- const left = params.left != null ? `${params.left}px` : ``;
857
- element.style.top = top;
858
- element.style.left = left;
859
- }
1057
+ if (params.left != null) {
1058
+ this.#left = params.left;
1059
+ }
1060
+ if (params.top != null) {
1061
+ this.#top = params.top;
1062
+ }
1063
+ this.#place();
1064
+ }
1065
+ /**
1066
+ * Places the window on both axes at once; `null` centers it on that axis.
1067
+ */
1068
+ place(placement) {
1069
+ this.#left = placement.left;
1070
+ this.#top = placement.top;
1071
+ this.#place();
1072
+ }
1073
+ /**
1074
+ * Resizes the window. A dimension that isn't given keeps its size.
1075
+ */
860
1076
  resize(params) {
861
- const element = this.#popupRefOrThrow.overlayRef.overlayElement;
862
- const width = params.width ? `${params.width}px` : ``;
863
- const height = params.height ? `${params.height}px` : ``;
864
- element.style.width = width;
865
- element.style.height = height;
1077
+ const size = {};
1078
+ if (params.width != null) {
1079
+ size.width = params.width;
1080
+ }
1081
+ if (params.height != null) {
1082
+ size.height = params.height;
1083
+ }
1084
+ if (size.width != null || size.height != null) {
1085
+ this.setSize(size);
1086
+ }
866
1087
  if (params.center) {
867
- asapScheduler.schedule(() => this.center());
1088
+ this.center();
868
1089
  }
869
1090
  }
1091
+ setComponentRef(componentRef) {
1092
+ this.#options.componentRef = componentRef;
1093
+ }
1094
+ /**
1095
+ * Sets any of the overlay's sizes, CSS lengths included. Sizes that aren't given keep their value.
1096
+ */
1097
+ setSize(size) {
1098
+ this.#popupRefOrThrow.overlayRef.updateSize(size);
1099
+ }
1100
+ #place() {
1101
+ positionGlobalOverlay(this.#popupRefOrThrow.overlayRef, { left: this.#left, top: this.#top });
1102
+ }
870
1103
  get close$() {
871
- return this.#popupRefOrThrow.beforeClose.pipe(map(event => event));
1104
+ const popupRef = this.#popupRefOrThrow;
1105
+ return popupRef.beforeClose.pipe(takeUntil(merge(popupRef.closed, this.#closed$).pipe(take(1))), map(event => event));
872
1106
  }
873
1107
  get closed$() {
874
- return this.#popupRefOrThrow.closed.pipe(map(() => undefined));
1108
+ return this.#closed$.asObservable();
875
1109
  }
876
1110
  get component() {
877
- // The type of component is ComponentRef<WindowContentComponent>. It is set as unknown to avoid circular dependency.
878
- const popupComponent = this.popupRef.component;
879
- if (!popupComponent) {
880
- return null;
881
- }
882
- return popupComponent.instance.componentRef ?? null;
1111
+ return this.#options.componentRef ?? null;
883
1112
  }
884
1113
  get drag$() {
885
- return this.move$$;
1114
+ return this.move$$.asObservable();
886
1115
  }
887
1116
  get dragEnd$() {
888
- return this.moveEnd$$;
1117
+ return this.moveEnd$$.asObservable();
889
1118
  }
890
1119
  get dragStart$() {
891
- return this.moveStart$$;
1120
+ return this.moveStart$$.asObservable();
892
1121
  }
893
1122
  get element() {
894
1123
  return this.#popupRefOrThrow.overlayRef.overlayElement;
@@ -896,11 +1125,20 @@ class WindowReference {
896
1125
  get height() {
897
1126
  return this.element.offsetHeight;
898
1127
  }
1128
+ /** Where the window was last placed; `null` on an axis it is centered on. */
1129
+ get placement() {
1130
+ return { left: this.#left, top: this.#top };
1131
+ }
899
1132
  get popupRef() {
900
1133
  return this.#popupRefOrThrow;
901
1134
  }
902
1135
  get resize$() {
903
- return this.resize$$;
1136
+ return this.resize$$.asObservable();
1137
+ }
1138
+ /** The sizes the overlay was last given, as set (pixels or CSS lengths). */
1139
+ get size() {
1140
+ const { height, maxHeight, maxWidth, minHeight, minWidth, width } = this.#popupRefOrThrow.overlayRef.getConfig();
1141
+ return { height, maxHeight, maxWidth, minHeight, minWidth, width };
904
1142
  }
905
1143
  get width() {
906
1144
  return this.element.offsetWidth;
@@ -909,19 +1147,21 @@ class WindowReference {
909
1147
  return this.#windowRef;
910
1148
  }
911
1149
  get #popupRefOrThrow() {
912
- if (!this.options.popupRef) {
1150
+ if (!this.#options.popupRef) {
913
1151
  throw new Error("WindowReference: popupRef has not been initialized.");
914
1152
  }
915
- return this.options.popupRef;
1153
+ return this.#options.popupRef;
916
1154
  }
917
1155
  }
918
1156
 
919
1157
  const createWindowInjectorData = (settings) => {
920
1158
  return {
921
1159
  actionTemplate: settings.actionTemplate,
1160
+ ariaLabel: settings.ariaLabel,
922
1161
  closable: settings.closable ?? true,
923
1162
  closeOnEscape: settings.closeOnEscape ?? true,
924
1163
  content: settings.content,
1164
+ data: settings.data,
925
1165
  draggable: settings.draggable ?? false,
926
1166
  focusedElement: settings.focusedElement,
927
1167
  footerTemplate: settings.footerTemplate,
@@ -932,13 +1172,12 @@ const createWindowInjectorData = (settings) => {
932
1172
  maxWidth: settings.maxWidth,
933
1173
  maximizable: settings.maximizable ?? true,
934
1174
  messages: settings.messages,
935
- minHeight: settings.minHeight ?? 50,
936
- minWidth: settings.minWidth ?? 50,
1175
+ minHeight: settings.minHeight ?? DEFAULT_MIN_WINDOW_HEIGHT,
1176
+ minWidth: settings.minWidth ?? DEFAULT_MIN_WINDOW_WIDTH,
937
1177
  minimizable: settings.minimizable ?? true,
938
1178
  modal: settings.modal,
939
- rounded: settings.rounded ?? "medium",
940
- preventClose: settings.preventClose,
941
1179
  resizable: settings.resizable ?? false,
1180
+ rounded: settings.rounded ?? "medium",
942
1181
  title: typeof settings.title === "string" ? settings.title : undefined,
943
1182
  titleTemplate: typeof settings.title === "string" ? undefined : settings.title,
944
1183
  top: settings.top,
@@ -950,47 +1189,60 @@ class WindowService {
950
1189
  #document = inject(DOCUMENT);
951
1190
  #injector = inject(Injector);
952
1191
  #popupService = inject(PopupService);
1192
+ /**
1193
+ * Opens a window.
1194
+ * @typeParam R the type of the value passed to `WindowRef.close(value)`
1195
+ * @typeParam D the type of `data`
1196
+ */
953
1197
  open(settings) {
1198
+ const modal = settings.modal ?? false;
954
1199
  const windowReference = new WindowReference({}, this.#document);
955
- const injectorData = { ...createWindowInjectorData(settings), windowReference };
1200
+ const injectorData = {
1201
+ ...createWindowInjectorData(settings),
1202
+ windowReference: windowReference
1203
+ };
1204
+ const windowClass = typeof settings.windowClass === "string" ? [settings.windowClass] : settings.windowClass;
956
1205
  const popupRef = this.#popupService.create({
957
1206
  anchor: this.#document.body,
958
- backdropClass: settings.modal
1207
+ backdropClass: modal
959
1208
  ? ["fixed", "inset-0", "bg-background/50", "transition-opacity", "z-40", "backdrop-blur-xs"]
960
1209
  : "transparent",
1210
+ blockScroll: modal,
961
1211
  closeOnBackdropClick: false,
962
1212
  closeOnEscape: settings.closeOnEscape ?? true,
963
1213
  closeOnOutsideClick: false,
964
1214
  content: WindowContentComponent,
965
1215
  data: injectorData,
966
- hasBackdrop: settings.modal,
967
- height: settings.height || "fit-content",
968
- maxHeight: settings.maxHeight,
969
- maxWidth: settings.maxWidth,
1216
+ hasBackdrop: modal,
1217
+ height: settings.height ?? "fit-content",
1218
+ injector: settings.injector,
1219
+ maxHeight: settings.maxHeight ?? "100dvh",
1220
+ maxWidth: settings.maxWidth ?? "100dvw",
970
1221
  minHeight: settings.minHeight,
971
1222
  minWidth: settings.minWidth,
1223
+ // A window dragged past an edge keeps its size instead of shrinking to fit the overlay wrapper.
1224
+ popupClass: [
1225
+ "shrink-0",
1226
+ ...(windowClass ?? []).flatMap(name => name.split(/\s+/)).filter(name => name !== "")
1227
+ ],
1228
+ popupWrapperClass: "mona-popup-constrain-height",
972
1229
  positionStrategy: "global",
973
- preventClose: (event) => {
974
- if (settings.preventClose) {
975
- return settings.preventClose(event);
976
- }
977
- return false;
978
- },
1230
+ preventClose: settings.preventClose,
979
1231
  providers: [
980
- {
981
- provide: WindowRef,
982
- useFactory: forwardRef(() => windowReference.windowRef)
983
- }
1232
+ { provide: WindowRef, useFactory: forwardRef(() => windowReference.windowRef) },
1233
+ { provide: WINDOW_DATA, useValue: settings.data }
984
1234
  ],
985
1235
  width: settings.width
986
1236
  });
987
- windowReference.initializePopupRef(popupRef);
988
- afterNextRender({
989
- read: () => {
990
- const element = popupRef.overlayRef.overlayElement;
991
- setWindowStyles(element, settings);
992
- }
993
- }, { injector: this.#injector });
1237
+ windowReference.initializePopupRef(popupRef, { left: settings.left, top: settings.top });
1238
+ if (modal) {
1239
+ const release = inertOutside(popupRef.overlayRef.hostElement);
1240
+ merge(popupRef.closeStart, popupRef.closed)
1241
+ .pipe(take(1))
1242
+ .subscribe(() => release());
1243
+ }
1244
+ // Once rendered, center again from the real size, in case the content changed it.
1245
+ afterNextRender({ write: () => popupRef.overlayRef.updatePosition() }, { injector: this.#injector });
994
1246
  return windowReference.windowRef;
995
1247
  }
996
1248
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
@@ -1006,20 +1258,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
1006
1258
  class WindowComponent {
1007
1259
  #destroyRef;
1008
1260
  #windowService;
1261
+ #destroyed;
1009
1262
  #windowRef;
1010
1263
  constructor() {
1011
1264
  this.#destroyRef = inject(DestroyRef);
1012
1265
  this.#windowService = inject(WindowService);
1266
+ this.#destroyed = false;
1013
1267
  this.actionTemplate = contentChild(WindowActionTemplateDirective, { ...(ngDevMode ? { debugName: "actionTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
1014
1268
  this.contentTemplate = contentChild(WindowContentTemplateDirective, { ...(ngDevMode ? { debugName: "contentTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
1015
1269
  this.footerTemplate = contentChild(WindowFooterTemplateDirective, { ...(ngDevMode ? { debugName: "footerTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
1270
+ this.projectedContent = viewChild.required("projectedContent", { ...(ngDevMode ? { debugName: "projectedContent" } : /* istanbul ignore next */ {}), read: TemplateRef });
1016
1271
  this.titleTemplate = contentChild(WindowTitleTemplateDirective, { ...(ngDevMode ? { debugName: "titleTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
1272
+ /**
1273
+ * @description Accessible name for the window when it has no `title` or title template.
1274
+ */
1275
+ this.ariaLabel = input(/* @ts-ignore */
1276
+ ...(ngDevMode ? [undefined, { debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
1017
1277
  /**
1018
1278
  * @description Sets the visibility of the close button in the window header.
1019
1279
  * @default true
1020
1280
  */
1021
1281
  this.closable = input(true, /* @ts-ignore */
1022
1282
  ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
1283
+ /**
1284
+ * @description Emits before the window closes, whatever closes it: the close button, Escape, a programmatic close,
1285
+ * or the component being destroyed. Call `preventDefault()` to keep it open (a close caused by destruction can't
1286
+ * be kept).
1287
+ */
1023
1288
  // eslint-disable-next-line @angular-eslint/no-output-native
1024
1289
  this.close = output();
1025
1290
  /**
@@ -1149,37 +1414,45 @@ class WindowComponent {
1149
1414
  const center = untracked(() => this.top() == null && this.left() == null);
1150
1415
  this.#windowRef?.resize({ height, width, center });
1151
1416
  });
1152
- afterNextRender({ read: () => this.#openWindow() });
1153
- this.#destroyRef.onDestroy(() => this.#windowRef?.close());
1417
+ afterNextRender({ write: () => this.#openWindow() });
1418
+ this.#destroyRef.onDestroy(() => {
1419
+ // Outputs can't emit once the component is destroyed, so this close is silent.
1420
+ this.#destroyed = true;
1421
+ this.#windowRef?.close();
1422
+ });
1154
1423
  }
1155
1424
  closeWindow() {
1156
1425
  this.#windowRef?.close();
1157
1426
  }
1427
+ /**
1428
+ * Moves the window, in pixels. An axis that isn't given keeps its place.
1429
+ */
1158
1430
  move(position) {
1159
- if (position.top !== undefined) {
1160
- this.#windowRef?.move({ top: position.top });
1161
- }
1162
- if (position.left !== undefined) {
1163
- this.#windowRef?.move({ left: position.left });
1164
- }
1431
+ this.#windowRef?.move(position);
1165
1432
  }
1433
+ /**
1434
+ * Opens the window. Called once after the first render; call it again to reopen a window that was closed. Does
1435
+ * nothing while the window is open.
1436
+ */
1166
1437
  openWindow() {
1167
1438
  this.#openWindow();
1168
1439
  }
1440
+ /**
1441
+ * Resizes the window, in pixels. A dimension that isn't given keeps its size.
1442
+ */
1169
1443
  resize(dimensions) {
1170
- if (dimensions.width !== undefined) {
1171
- this.#windowRef?.resize({ width: dimensions.width });
1172
- }
1173
- if (dimensions.height !== undefined) {
1174
- this.#windowRef?.resize({ height: dimensions.height });
1175
- }
1444
+ this.#windowRef?.resize(dimensions);
1176
1445
  }
1177
1446
  #openWindow() {
1447
+ if (this.#windowRef || this.#destroyed) {
1448
+ return;
1449
+ }
1178
1450
  this.#windowRef = this.#windowService.open({
1179
1451
  actionTemplate: this.actionTemplate(),
1452
+ ariaLabel: this.ariaLabel(),
1180
1453
  closable: this.closable(),
1181
1454
  closeOnEscape: this.closeOnEscape(),
1182
- content: this.contentTemplate(),
1455
+ content: this.contentTemplate() ?? this.projectedContent(),
1183
1456
  draggable: this.draggable(),
1184
1457
  focusedElement: this.focusedElement(),
1185
1458
  footerTemplate: this.footerTemplate(),
@@ -1203,14 +1476,23 @@ class WindowComponent {
1203
1476
  this.#setSubscriptions();
1204
1477
  }
1205
1478
  #setCloseSubscription() {
1206
- if (!this.#windowRef) {
1479
+ const windowRef = this.#windowRef;
1480
+ if (!windowRef) {
1207
1481
  return;
1208
1482
  }
1209
- this.#windowRef.popupRef.beforeClose.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(event => {
1210
- this.close.emit(event);
1483
+ // Not tied to this component's lifetime: destroying it closes the window, and these finish with it.
1484
+ windowRef.close$.subscribe(event => {
1485
+ if (!this.#destroyed) {
1486
+ this.close.emit(event);
1487
+ }
1211
1488
  });
1212
- this.#windowRef.closed$.pipe(take(1), takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
1213
- this.closed.emit();
1489
+ windowRef.closed$.subscribe(() => {
1490
+ if (this.#windowRef === windowRef) {
1491
+ this.#windowRef = undefined;
1492
+ }
1493
+ if (!this.#destroyed) {
1494
+ this.closed.emit();
1495
+ }
1214
1496
  });
1215
1497
  }
1216
1498
  #setDragSubscription() {
@@ -1257,18 +1539,19 @@ class WindowComponent {
1257
1539
  this.#setResizeSubscription();
1258
1540
  }
1259
1541
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1260
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: WindowComponent, isStandalone: true, selector: "mona-window", inputs: { closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, draggable: { classPropertyName: "draggable", publicName: "draggable", isSignal: true, isRequired: false, transformFunction: null }, focusedElement: { classPropertyName: "focusedElement", publicName: "focusedElement", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, left: { classPropertyName: "left", publicName: "left", isSignal: true, isRequired: false, transformFunction: null }, look: { classPropertyName: "look", publicName: "look", isSignal: true, isRequired: false, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null }, maximizable: { classPropertyName: "maximizable", publicName: "maximizable", isSignal: true, isRequired: false, transformFunction: null }, messages: { classPropertyName: "messages", publicName: "messages", isSignal: true, isRequired: false, transformFunction: null }, minHeight: { classPropertyName: "minHeight", publicName: "minHeight", isSignal: true, isRequired: false, transformFunction: null }, minWidth: { classPropertyName: "minWidth", publicName: "minWidth", isSignal: true, isRequired: false, transformFunction: null }, minimizable: { classPropertyName: "minimizable", publicName: "minimizable", isSignal: true, isRequired: false, transformFunction: null }, modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, resizable: { classPropertyName: "resizable", publicName: "resizable", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, top: { classPropertyName: "top", publicName: "top", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { close: "close", closed: "closed", dragEnd: "dragEnd", dragStart: "dragStart", height: "heightChange", left: "leftChange", top: "topChange", width: "widthChange" }, host: { classAttribute: "hidden" }, queries: [{ propertyName: "actionTemplate", first: true, predicate: WindowActionTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "contentTemplate", first: true, predicate: WindowContentTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "footerTemplate", first: true, predicate: WindowFooterTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "titleTemplate", first: true, predicate: WindowTitleTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: ``, isInline: true }); }
1542
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: WindowComponent, isStandalone: true, selector: "mona-window", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, draggable: { classPropertyName: "draggable", publicName: "draggable", isSignal: true, isRequired: false, transformFunction: null }, focusedElement: { classPropertyName: "focusedElement", publicName: "focusedElement", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, left: { classPropertyName: "left", publicName: "left", isSignal: true, isRequired: false, transformFunction: null }, look: { classPropertyName: "look", publicName: "look", isSignal: true, isRequired: false, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null }, maximizable: { classPropertyName: "maximizable", publicName: "maximizable", isSignal: true, isRequired: false, transformFunction: null }, messages: { classPropertyName: "messages", publicName: "messages", isSignal: true, isRequired: false, transformFunction: null }, minHeight: { classPropertyName: "minHeight", publicName: "minHeight", isSignal: true, isRequired: false, transformFunction: null }, minWidth: { classPropertyName: "minWidth", publicName: "minWidth", isSignal: true, isRequired: false, transformFunction: null }, minimizable: { classPropertyName: "minimizable", publicName: "minimizable", isSignal: true, isRequired: false, transformFunction: null }, modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, resizable: { classPropertyName: "resizable", publicName: "resizable", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, top: { classPropertyName: "top", publicName: "top", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { close: "close", closed: "closed", dragEnd: "dragEnd", dragStart: "dragStart", height: "heightChange", left: "leftChange", top: "topChange", width: "widthChange" }, host: { classAttribute: "hidden" }, queries: [{ propertyName: "actionTemplate", first: true, predicate: WindowActionTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "contentTemplate", first: true, predicate: WindowContentTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "footerTemplate", first: true, predicate: WindowFooterTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "titleTemplate", first: true, predicate: WindowTitleTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "projectedContent", first: true, predicate: ["projectedContent"], descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: `<ng-template #projectedContent><ng-content /></ng-template>`, isInline: true }); }
1261
1543
  }
1262
1544
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowComponent, decorators: [{
1263
1545
  type: Component,
1264
1546
  args: [{
1265
1547
  selector: "mona-window",
1266
- template: ``,
1548
+ // Content placed directly inside <mona-window> is the window's content, unless a monaWindowContentTemplate is given.
1549
+ template: `<ng-template #projectedContent><ng-content /></ng-template>`,
1267
1550
  host: {
1268
1551
  class: "hidden"
1269
1552
  }
1270
1553
  }]
1271
- }], ctorParameters: () => [], propDecorators: { actionTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowActionTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], contentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowContentTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], footerTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowFooterTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], titleTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowTitleTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], close: [{ type: i0.Output, args: ["close"] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], closed: [{ type: i0.Output, args: ["closed"] }], dragEnd: [{ type: i0.Output, args: ["dragEnd"] }], dragStart: [{ type: i0.Output, args: ["dragStart"] }], draggable: [{ type: i0.Input, args: [{ isSignal: true, alias: "draggable", required: false }] }], focusedElement: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusedElement", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }, { type: i0.Output, args: ["heightChange"] }], left: [{ type: i0.Input, args: [{ isSignal: true, alias: "left", required: false }] }, { type: i0.Output, args: ["leftChange"] }], look: [{ type: i0.Input, args: [{ isSignal: true, alias: "look", required: false }] }], maxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxHeight", required: false }] }], maxWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxWidth", required: false }] }], maximizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "maximizable", required: false }] }], messages: [{ type: i0.Input, args: [{ isSignal: true, alias: "messages", required: false }] }], minHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "minHeight", required: false }] }], minWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "minWidth", required: false }] }], minimizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "minimizable", required: false }] }], modal: [{ type: i0.Input, args: [{ isSignal: true, alias: "modal", required: false }] }], resizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "resizable", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], top: [{ type: i0.Input, args: [{ isSignal: true, alias: "top", required: false }] }, { type: i0.Output, args: ["topChange"] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }, { type: i0.Output, args: ["widthChange"] }] } });
1554
+ }], ctorParameters: () => [], propDecorators: { actionTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowActionTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], contentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowContentTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], footerTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowFooterTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], projectedContent: [{ type: i0.ViewChild, args: ["projectedContent", { ...{ read: TemplateRef }, isSignal: true }] }], titleTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => WindowTitleTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], close: [{ type: i0.Output, args: ["close"] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], closed: [{ type: i0.Output, args: ["closed"] }], dragEnd: [{ type: i0.Output, args: ["dragEnd"] }], dragStart: [{ type: i0.Output, args: ["dragStart"] }], draggable: [{ type: i0.Input, args: [{ isSignal: true, alias: "draggable", required: false }] }], focusedElement: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusedElement", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }, { type: i0.Output, args: ["heightChange"] }], left: [{ type: i0.Input, args: [{ isSignal: true, alias: "left", required: false }] }, { type: i0.Output, args: ["leftChange"] }], look: [{ type: i0.Input, args: [{ isSignal: true, alias: "look", required: false }] }], maxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxHeight", required: false }] }], maxWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxWidth", required: false }] }], maximizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "maximizable", required: false }] }], messages: [{ type: i0.Input, args: [{ isSignal: true, alias: "messages", required: false }] }], minHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "minHeight", required: false }] }], minWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "minWidth", required: false }] }], minimizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "minimizable", required: false }] }], modal: [{ type: i0.Input, args: [{ isSignal: true, alias: "modal", required: false }] }], resizable: [{ type: i0.Input, args: [{ isSignal: true, alias: "resizable", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], top: [{ type: i0.Input, args: [{ isSignal: true, alias: "top", required: false }] }, { type: i0.Output, args: ["topChange"] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }, { type: i0.Output, args: ["widthChange"] }] } });
1272
1555
 
1273
1556
  /*
1274
1557
  * Public API Surface of @nanahoshi/mona-ui/window
@@ -1278,5 +1561,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
1278
1561
  * Generated bundle index. Do not edit.
1279
1562
  */
1280
1563
 
1281
- export { WINDOW_DEFAULT_MESSAGES, WindowActionTemplateDirective, WindowComponent, WindowContentTemplateDirective, WindowFooterTemplateDirective, WindowRef, WindowService, WindowTitleTemplateDirective };
1564
+ export { WINDOW_DATA, WINDOW_DEFAULT_MESSAGES, WindowActionTemplateDirective, WindowComponent, WindowContentTemplateDirective, WindowFooterTemplateDirective, WindowRef, WindowService, WindowTitleTemplateDirective };
1282
1565
  //# sourceMappingURL=nanahoshi-mona-ui-window.mjs.map