@nanahoshi/mona-ui 0.24.7 → 0.24.9
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.
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
- package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
- package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +339 -101
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
- package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-vXXNWmEN.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-DDgNmgE0.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Dzf6Vbs_.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DAPNqnWV.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-B9rmDLq8.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +10 -10
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +44 -3
- package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +20 -4
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +335 -45
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +565 -197
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +465 -23
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +598 -208
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +193 -71
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +40 -3
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +49 -3
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +205 -140
- package/fesm2022/nanahoshi-mona-ui-window.mjs +591 -310
- package/i18n/catalogs/en-US.messages.json +32 -6
- package/locales/ar-sa/ar-sa.messages.json +29 -3
- package/locales/de-de/de-de.messages.json +29 -3
- package/locales/es-es/es-es.messages.json +29 -3
- package/locales/fr-fr/fr-fr.messages.json +29 -3
- package/locales/id-id/id-id.messages.json +29 -3
- package/locales/it-it/it-it.messages.json +29 -3
- package/locales/ja-jp/ja-jp.messages.json +29 -3
- package/locales/ko-kr/ko-kr.messages.json +29 -3
- package/locales/pt-br/pt-br.messages.json +29 -3
- package/locales/ru-ru/ru-ru.messages.json +29 -3
- package/locales/tr-tr/tr-tr.messages.json +29 -3
- package/locales/zh-cn/zh-cn.messages.json +29 -3
- package/locales/zh-tw/zh-tw.messages.json +29 -3
- package/package.json +1 -1
- package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
- package/types/nanahoshi-mona-ui-button.d.ts +20 -3
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
- package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
- package/types/nanahoshi-mona-ui-i18n.d.ts +69 -0
- package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +14 -2
- package/types/nanahoshi-mona-ui-internal-list.d.ts +89 -10
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +155 -40
- package/types/nanahoshi-mona-ui-internal.d.ts +128 -16
- package/types/nanahoshi-mona-ui-list-box.d.ts +148 -47
- package/types/nanahoshi-mona-ui-list-view.d.ts +112 -21
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +26 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
- package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
- package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
- package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
- package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
- package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
- package/types/nanahoshi-mona-ui-tree-view.d.ts +84 -40
- 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,
|
|
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 {
|
|
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
|
|
65
|
-
const
|
|
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
|
-
|
|
100
|
+
write: () => this.#setEvents()
|
|
83
101
|
});
|
|
84
102
|
this.#destroyRef.onDestroy(() => this.#activeCleanup?.());
|
|
85
103
|
}
|
|
86
104
|
onKeydown(event) {
|
|
87
|
-
|
|
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
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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 (
|
|
171
|
+
if (moveEvent.clientX < 0 ||
|
|
172
|
+
moveEvent.clientX > innerWidth ||
|
|
173
|
+
moveEvent.clientY < 0 ||
|
|
174
|
+
moveEvent.clientY > innerHeight) {
|
|
139
175
|
return;
|
|
140
176
|
}
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
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",
|
|
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
|
|
192
|
+
const onPointerEnd = (endEvent) => {
|
|
193
|
+
if (endEvent.pointerId !== pointerId) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
155
196
|
cleanup();
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
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",
|
|
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
|
-
|
|
186
|
-
|
|
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
|
-
|
|
295
|
+
write: () => this.#setEvents()
|
|
212
296
|
});
|
|
213
297
|
this.#destroyRef.onDestroy(() => this.#activeCleanup?.());
|
|
214
298
|
}
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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 <
|
|
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 = (
|
|
393
|
-
|
|
394
|
-
|
|
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(
|
|
454
|
+
this.#applyResize(result, initial);
|
|
400
455
|
};
|
|
401
456
|
const cleanup = () => {
|
|
402
457
|
this.#document.removeEventListener("pointermove", onPointerMove);
|
|
403
|
-
this.#document.removeEventListener("pointerup",
|
|
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
|
|
409
|
-
|
|
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",
|
|
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 } },
|
|
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
|
-
#
|
|
559
|
-
#document;
|
|
628
|
+
#destroyRef;
|
|
560
629
|
#hostElementRef;
|
|
561
630
|
#i18n;
|
|
562
631
|
#injector;
|
|
563
632
|
#localeMessages;
|
|
564
|
-
#sizeBeforeMaximize;
|
|
565
|
-
#sizeBeforeMinimize;
|
|
566
633
|
#trapFocus;
|
|
567
|
-
#
|
|
634
|
+
#beforeMaximize;
|
|
635
|
+
#beforeMinimize;
|
|
636
|
+
#componentRef;
|
|
568
637
|
constructor() {
|
|
569
|
-
this.#
|
|
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.#
|
|
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()
|
|
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
|
-
|
|
639
|
-
this.
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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.#
|
|
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
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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() {
|
|
@@ -726,18 +851,8 @@ class WindowContentComponent {
|
|
|
726
851
|
const windowElement = this.#hostElementRef.nativeElement;
|
|
727
852
|
focusElement(windowElement, element);
|
|
728
853
|
}
|
|
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
|
-
}
|
|
738
|
-
}
|
|
739
854
|
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
|
|
855
|
+
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
856
|
}
|
|
742
857
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowContentComponent, decorators: [{
|
|
743
858
|
type: Component,
|
|
@@ -747,54 +862,90 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
|
|
|
747
862
|
ButtonDirective,
|
|
748
863
|
WindowResizeHandlerDirective,
|
|
749
864
|
ResizePositionPipe,
|
|
750
|
-
LucideMinus,
|
|
751
865
|
LucideDynamicIcon,
|
|
752
866
|
LucideX
|
|
753
867
|
], host: {
|
|
754
868
|
"[class]": "baseClass()",
|
|
755
|
-
"[attr.aria-
|
|
756
|
-
"[attr.aria-
|
|
869
|
+
"[attr.aria-label]": "hasTitle ? null : windowData.ariaLabel || null",
|
|
870
|
+
"[attr.aria-labelledby]": "hasTitle ? headerId : null",
|
|
871
|
+
"[attr.aria-modal]": "windowData.modal ? 'true' : 'false'",
|
|
872
|
+
"(focusin)": "onFocusIn($event)",
|
|
757
873
|
role: "dialog"
|
|
758
|
-
}, hostDirectives: [CdkTrapFocus], template: "<div [class]=\"contentContainerClass()\">\n <div\n [class]=\"titleBarClass()\"\n monaWindowDragHandler\n (dblclick)=\"
|
|
759
|
-
}], ctorParameters: () => [], propDecorators: {
|
|
760
|
-
|
|
761
|
-
|
|
874
|
+
}, 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" }]
|
|
875
|
+
}], ctorParameters: () => [], propDecorators: { componentHost: [{ type: i0.ViewChild, args: ["componentHost", { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* The `data` a window was opened with, for a component given as its `content`.
|
|
879
|
+
* @example
|
|
880
|
+
* ```ts
|
|
881
|
+
* readonly #data = inject<{ name: string }>(WINDOW_DATA);
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
const WINDOW_DATA = new InjectionToken("WINDOW_DATA");
|
|
762
885
|
|
|
886
|
+
/**
|
|
887
|
+
* A handle on an open window.
|
|
888
|
+
* @typeParam R the type of the value passed to `close(value)`
|
|
889
|
+
*/
|
|
763
890
|
class WindowRef {
|
|
764
891
|
#options;
|
|
765
892
|
constructor(options) {
|
|
766
893
|
this.#options = options;
|
|
767
894
|
}
|
|
895
|
+
/**
|
|
896
|
+
* Centers the window in the viewport. It stays centered as its size changes, until it is moved.
|
|
897
|
+
*/
|
|
768
898
|
center() {
|
|
769
899
|
this.#options.center();
|
|
770
900
|
}
|
|
901
|
+
/**
|
|
902
|
+
* Closes the window. `close$` can still prevent it.
|
|
903
|
+
* @param result the value `closed$` reports
|
|
904
|
+
*/
|
|
771
905
|
close(result) {
|
|
772
906
|
this.#options.close(result);
|
|
773
907
|
}
|
|
774
908
|
closeWithDelay(delay, result) {
|
|
775
909
|
this.#options.closeWithDelay(delay, result);
|
|
776
910
|
}
|
|
911
|
+
/**
|
|
912
|
+
* Moves the window, in pixels from the viewport's top-left corner. An axis that isn't given keeps its place.
|
|
913
|
+
*/
|
|
777
914
|
move(params) {
|
|
778
915
|
this.#options.move(params);
|
|
779
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Resizes the window, in pixels. A dimension that isn't given keeps its size; `center` centers the window
|
|
919
|
+
* afterward.
|
|
920
|
+
*/
|
|
780
921
|
resize(params) {
|
|
781
922
|
this.#options.resize(params);
|
|
782
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* Emits before the window closes, whatever closes it. Call `preventDefault()` to keep it open. Completes once the
|
|
926
|
+
* window has closed.
|
|
927
|
+
*/
|
|
783
928
|
get close$() {
|
|
784
929
|
return this.#options.close$;
|
|
785
930
|
}
|
|
931
|
+
/**
|
|
932
|
+
* Emits how the window closed, once it has closed, then completes. Replays to late subscribers.
|
|
933
|
+
*/
|
|
786
934
|
get closed$() {
|
|
787
935
|
return this.#options.closed$;
|
|
788
936
|
}
|
|
789
937
|
get component() {
|
|
790
938
|
return this.#options.component;
|
|
791
939
|
}
|
|
940
|
+
/** Emits while the window is dragged. Completes when it closes. */
|
|
792
941
|
get drag$() {
|
|
793
942
|
return this.#options.drag$;
|
|
794
943
|
}
|
|
944
|
+
/** Emits when a drag ends. Completes when the window closes. */
|
|
795
945
|
get dragEnd$() {
|
|
796
946
|
return this.#options.dragEnd$;
|
|
797
947
|
}
|
|
948
|
+
/** Emits when a drag starts. Completes when the window closes. */
|
|
798
949
|
get dragStart$() {
|
|
799
950
|
return this.#options.dragStart$;
|
|
800
951
|
}
|
|
@@ -807,6 +958,7 @@ class WindowRef {
|
|
|
807
958
|
get popupRef() {
|
|
808
959
|
return this.#options.popupRef;
|
|
809
960
|
}
|
|
961
|
+
/** Emits while the window is resized by the user. Completes when it closes. */
|
|
810
962
|
get resize$() {
|
|
811
963
|
return this.#options.resize$;
|
|
812
964
|
}
|
|
@@ -815,28 +967,56 @@ class WindowRef {
|
|
|
815
967
|
}
|
|
816
968
|
}
|
|
817
969
|
|
|
970
|
+
/** Marks the overlay hosts that hold a window, so a window can be raised above the other windows. */
|
|
971
|
+
const WINDOW_HOST_CLASS = "mona-window-host";
|
|
818
972
|
/**
|
|
819
973
|
* @internal - used by WindowService. Do not export.
|
|
820
974
|
*/
|
|
821
975
|
class WindowReference {
|
|
976
|
+
#closed$;
|
|
977
|
+
#document;
|
|
978
|
+
#options;
|
|
822
979
|
#windowRef;
|
|
980
|
+
#left;
|
|
981
|
+
#top;
|
|
823
982
|
constructor(options, document) {
|
|
824
|
-
this
|
|
825
|
-
this
|
|
983
|
+
this.#closed$ = new ReplaySubject(1);
|
|
984
|
+
this.#left = null;
|
|
985
|
+
this.#top = null;
|
|
826
986
|
this.move$$ = new Subject();
|
|
827
987
|
this.moveEnd$$ = new Subject();
|
|
828
988
|
this.moveStart$$ = new Subject();
|
|
829
989
|
this.resize$$ = new Subject();
|
|
990
|
+
this.#options = options;
|
|
991
|
+
this.#document = document;
|
|
830
992
|
this.#windowRef = new WindowRef(this);
|
|
831
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* Raises the window above the other open windows, keeping focus where it was inside it. Other overlays keep
|
|
996
|
+
* their order.
|
|
997
|
+
*/
|
|
998
|
+
bringToFront() {
|
|
999
|
+
const host = this.#popupRefOrThrow.overlayRef.hostElement;
|
|
1000
|
+
const container = host.parentElement;
|
|
1001
|
+
if (!container) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
const windows = Array.from(container.children).filter(child => child.classList.contains(WINDOW_HOST_CLASS));
|
|
1005
|
+
const topmost = windows.at(-1);
|
|
1006
|
+
if (!topmost || topmost === host) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
const active = this.#document.activeElement;
|
|
1010
|
+
const focused = active instanceof HTMLElement && host.contains(active) ? active : null;
|
|
1011
|
+
topmost.after(host);
|
|
1012
|
+
if (focused && this.#document.activeElement !== focused) {
|
|
1013
|
+
focused.focus({ preventScroll: true });
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
832
1016
|
center() {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
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`;
|
|
1017
|
+
this.#left = null;
|
|
1018
|
+
this.#top = null;
|
|
1019
|
+
this.#place();
|
|
840
1020
|
}
|
|
841
1021
|
close(result) {
|
|
842
1022
|
const event = result instanceof PopupCloseEvent
|
|
@@ -847,48 +1027,95 @@ class WindowReference {
|
|
|
847
1027
|
closeWithDelay(delay, result) {
|
|
848
1028
|
asapScheduler.schedule(() => this.close(result), delay);
|
|
849
1029
|
}
|
|
850
|
-
|
|
851
|
-
|
|
1030
|
+
/**
|
|
1031
|
+
* Connects the window to its popup and places it: at `left`/`top`, or centered on an axis that isn't given.
|
|
1032
|
+
*/
|
|
1033
|
+
initializePopupRef(popupRef, placement = {}) {
|
|
1034
|
+
this.#options.popupRef = popupRef;
|
|
1035
|
+
this.#left = placement.left ?? null;
|
|
1036
|
+
this.#top = placement.top ?? null;
|
|
1037
|
+
popupRef.overlayRef.hostElement.classList.add(WINDOW_HOST_CLASS);
|
|
1038
|
+
this.#place();
|
|
1039
|
+
popupRef.closed.pipe(take(1)).subscribe(event => {
|
|
1040
|
+
this.move$$.complete();
|
|
1041
|
+
this.moveEnd$$.complete();
|
|
1042
|
+
this.moveStart$$.complete();
|
|
1043
|
+
this.resize$$.complete();
|
|
1044
|
+
this.#closed$.next({
|
|
1045
|
+
value: event.result,
|
|
1046
|
+
via: event.via ?? PopupCloseSource.Programmatic
|
|
1047
|
+
});
|
|
1048
|
+
this.#closed$.complete();
|
|
1049
|
+
});
|
|
852
1050
|
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Moves the window. An axis that isn't given keeps its place.
|
|
1053
|
+
*/
|
|
853
1054
|
move(params) {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
1055
|
+
if (params.left != null) {
|
|
1056
|
+
this.#left = params.left;
|
|
1057
|
+
}
|
|
1058
|
+
if (params.top != null) {
|
|
1059
|
+
this.#top = params.top;
|
|
1060
|
+
}
|
|
1061
|
+
this.#place();
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Places the window on both axes at once; `null` centers it on that axis.
|
|
1065
|
+
*/
|
|
1066
|
+
place(placement) {
|
|
1067
|
+
this.#left = placement.left;
|
|
1068
|
+
this.#top = placement.top;
|
|
1069
|
+
this.#place();
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Resizes the window. A dimension that isn't given keeps its size.
|
|
1073
|
+
*/
|
|
860
1074
|
resize(params) {
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1075
|
+
const size = {};
|
|
1076
|
+
if (params.width != null) {
|
|
1077
|
+
size.width = params.width;
|
|
1078
|
+
}
|
|
1079
|
+
if (params.height != null) {
|
|
1080
|
+
size.height = params.height;
|
|
1081
|
+
}
|
|
1082
|
+
if (size.width != null || size.height != null) {
|
|
1083
|
+
this.setSize(size);
|
|
1084
|
+
}
|
|
866
1085
|
if (params.center) {
|
|
867
|
-
|
|
1086
|
+
this.center();
|
|
868
1087
|
}
|
|
869
1088
|
}
|
|
1089
|
+
setComponentRef(componentRef) {
|
|
1090
|
+
this.#options.componentRef = componentRef;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Sets any of the overlay's sizes, CSS lengths included. Sizes that aren't given keep their value.
|
|
1094
|
+
*/
|
|
1095
|
+
setSize(size) {
|
|
1096
|
+
this.#popupRefOrThrow.overlayRef.updateSize(size);
|
|
1097
|
+
}
|
|
1098
|
+
#place() {
|
|
1099
|
+
positionGlobalOverlay(this.#popupRefOrThrow.overlayRef, { left: this.#left, top: this.#top });
|
|
1100
|
+
}
|
|
870
1101
|
get close$() {
|
|
871
|
-
|
|
1102
|
+
const popupRef = this.#popupRefOrThrow;
|
|
1103
|
+
return popupRef.beforeClose.pipe(takeUntil(merge(popupRef.closed, this.#closed$).pipe(take(1))), map(event => event));
|
|
872
1104
|
}
|
|
873
1105
|
get closed$() {
|
|
874
|
-
return this.#
|
|
1106
|
+
return this.#closed$.asObservable();
|
|
875
1107
|
}
|
|
876
1108
|
get component() {
|
|
877
|
-
|
|
878
|
-
const popupComponent = this.popupRef.component;
|
|
879
|
-
if (!popupComponent) {
|
|
880
|
-
return null;
|
|
881
|
-
}
|
|
882
|
-
return popupComponent.instance.componentRef ?? null;
|
|
1109
|
+
return this.#options.componentRef ?? null;
|
|
883
1110
|
}
|
|
884
1111
|
get drag$() {
|
|
885
|
-
return this.move
|
|
1112
|
+
return this.move$$.asObservable();
|
|
886
1113
|
}
|
|
887
1114
|
get dragEnd$() {
|
|
888
|
-
return this.moveEnd
|
|
1115
|
+
return this.moveEnd$$.asObservable();
|
|
889
1116
|
}
|
|
890
1117
|
get dragStart$() {
|
|
891
|
-
return this.moveStart
|
|
1118
|
+
return this.moveStart$$.asObservable();
|
|
892
1119
|
}
|
|
893
1120
|
get element() {
|
|
894
1121
|
return this.#popupRefOrThrow.overlayRef.overlayElement;
|
|
@@ -896,11 +1123,20 @@ class WindowReference {
|
|
|
896
1123
|
get height() {
|
|
897
1124
|
return this.element.offsetHeight;
|
|
898
1125
|
}
|
|
1126
|
+
/** Where the window was last placed; `null` on an axis it is centered on. */
|
|
1127
|
+
get placement() {
|
|
1128
|
+
return { left: this.#left, top: this.#top };
|
|
1129
|
+
}
|
|
899
1130
|
get popupRef() {
|
|
900
1131
|
return this.#popupRefOrThrow;
|
|
901
1132
|
}
|
|
902
1133
|
get resize$() {
|
|
903
|
-
return this.resize
|
|
1134
|
+
return this.resize$$.asObservable();
|
|
1135
|
+
}
|
|
1136
|
+
/** The sizes the overlay was last given, as set (pixels or CSS lengths). */
|
|
1137
|
+
get size() {
|
|
1138
|
+
const { height, maxHeight, maxWidth, minHeight, minWidth, width } = this.#popupRefOrThrow.overlayRef.getConfig();
|
|
1139
|
+
return { height, maxHeight, maxWidth, minHeight, minWidth, width };
|
|
904
1140
|
}
|
|
905
1141
|
get width() {
|
|
906
1142
|
return this.element.offsetWidth;
|
|
@@ -909,19 +1145,21 @@ class WindowReference {
|
|
|
909
1145
|
return this.#windowRef;
|
|
910
1146
|
}
|
|
911
1147
|
get #popupRefOrThrow() {
|
|
912
|
-
if (!this
|
|
1148
|
+
if (!this.#options.popupRef) {
|
|
913
1149
|
throw new Error("WindowReference: popupRef has not been initialized.");
|
|
914
1150
|
}
|
|
915
|
-
return this
|
|
1151
|
+
return this.#options.popupRef;
|
|
916
1152
|
}
|
|
917
1153
|
}
|
|
918
1154
|
|
|
919
1155
|
const createWindowInjectorData = (settings) => {
|
|
920
1156
|
return {
|
|
921
1157
|
actionTemplate: settings.actionTemplate,
|
|
1158
|
+
ariaLabel: settings.ariaLabel,
|
|
922
1159
|
closable: settings.closable ?? true,
|
|
923
1160
|
closeOnEscape: settings.closeOnEscape ?? true,
|
|
924
1161
|
content: settings.content,
|
|
1162
|
+
data: settings.data,
|
|
925
1163
|
draggable: settings.draggable ?? false,
|
|
926
1164
|
focusedElement: settings.focusedElement,
|
|
927
1165
|
footerTemplate: settings.footerTemplate,
|
|
@@ -932,13 +1170,12 @@ const createWindowInjectorData = (settings) => {
|
|
|
932
1170
|
maxWidth: settings.maxWidth,
|
|
933
1171
|
maximizable: settings.maximizable ?? true,
|
|
934
1172
|
messages: settings.messages,
|
|
935
|
-
minHeight: settings.minHeight ??
|
|
936
|
-
minWidth: settings.minWidth ??
|
|
1173
|
+
minHeight: settings.minHeight ?? DEFAULT_MIN_WINDOW_HEIGHT,
|
|
1174
|
+
minWidth: settings.minWidth ?? DEFAULT_MIN_WINDOW_WIDTH,
|
|
937
1175
|
minimizable: settings.minimizable ?? true,
|
|
938
1176
|
modal: settings.modal,
|
|
939
|
-
rounded: settings.rounded ?? "medium",
|
|
940
|
-
preventClose: settings.preventClose,
|
|
941
1177
|
resizable: settings.resizable ?? false,
|
|
1178
|
+
rounded: settings.rounded ?? "medium",
|
|
942
1179
|
title: typeof settings.title === "string" ? settings.title : undefined,
|
|
943
1180
|
titleTemplate: typeof settings.title === "string" ? undefined : settings.title,
|
|
944
1181
|
top: settings.top,
|
|
@@ -950,47 +1187,60 @@ class WindowService {
|
|
|
950
1187
|
#document = inject(DOCUMENT);
|
|
951
1188
|
#injector = inject(Injector);
|
|
952
1189
|
#popupService = inject(PopupService);
|
|
1190
|
+
/**
|
|
1191
|
+
* Opens a window.
|
|
1192
|
+
* @typeParam R the type of the value passed to `WindowRef.close(value)`
|
|
1193
|
+
* @typeParam D the type of `data`
|
|
1194
|
+
*/
|
|
953
1195
|
open(settings) {
|
|
1196
|
+
const modal = settings.modal ?? false;
|
|
954
1197
|
const windowReference = new WindowReference({}, this.#document);
|
|
955
|
-
const injectorData = {
|
|
1198
|
+
const injectorData = {
|
|
1199
|
+
...createWindowInjectorData(settings),
|
|
1200
|
+
windowReference: windowReference
|
|
1201
|
+
};
|
|
1202
|
+
const windowClass = typeof settings.windowClass === "string" ? [settings.windowClass] : settings.windowClass;
|
|
956
1203
|
const popupRef = this.#popupService.create({
|
|
957
1204
|
anchor: this.#document.body,
|
|
958
|
-
backdropClass:
|
|
1205
|
+
backdropClass: modal
|
|
959
1206
|
? ["fixed", "inset-0", "bg-background/50", "transition-opacity", "z-40", "backdrop-blur-xs"]
|
|
960
1207
|
: "transparent",
|
|
1208
|
+
blockScroll: modal,
|
|
961
1209
|
closeOnBackdropClick: false,
|
|
962
1210
|
closeOnEscape: settings.closeOnEscape ?? true,
|
|
963
1211
|
closeOnOutsideClick: false,
|
|
964
1212
|
content: WindowContentComponent,
|
|
965
1213
|
data: injectorData,
|
|
966
|
-
hasBackdrop:
|
|
967
|
-
height: settings.height
|
|
968
|
-
|
|
969
|
-
|
|
1214
|
+
hasBackdrop: modal,
|
|
1215
|
+
height: settings.height ?? "fit-content",
|
|
1216
|
+
injector: settings.injector,
|
|
1217
|
+
maxHeight: settings.maxHeight ?? "100dvh",
|
|
1218
|
+
maxWidth: settings.maxWidth ?? "100dvw",
|
|
970
1219
|
minHeight: settings.minHeight,
|
|
971
1220
|
minWidth: settings.minWidth,
|
|
1221
|
+
// A window dragged past an edge keeps its size instead of shrinking to fit the overlay wrapper.
|
|
1222
|
+
popupClass: [
|
|
1223
|
+
"shrink-0",
|
|
1224
|
+
...(windowClass ?? []).flatMap(name => name.split(/\s+/)).filter(name => name !== "")
|
|
1225
|
+
],
|
|
1226
|
+
popupWrapperClass: "mona-popup-constrain-height",
|
|
972
1227
|
positionStrategy: "global",
|
|
973
|
-
preventClose:
|
|
974
|
-
if (settings.preventClose) {
|
|
975
|
-
return settings.preventClose(event);
|
|
976
|
-
}
|
|
977
|
-
return false;
|
|
978
|
-
},
|
|
1228
|
+
preventClose: settings.preventClose,
|
|
979
1229
|
providers: [
|
|
980
|
-
{
|
|
981
|
-
|
|
982
|
-
useFactory: forwardRef(() => windowReference.windowRef)
|
|
983
|
-
}
|
|
1230
|
+
{ provide: WindowRef, useFactory: forwardRef(() => windowReference.windowRef) },
|
|
1231
|
+
{ provide: WINDOW_DATA, useValue: settings.data }
|
|
984
1232
|
],
|
|
985
1233
|
width: settings.width
|
|
986
1234
|
});
|
|
987
|
-
windowReference.initializePopupRef(popupRef);
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
1235
|
+
windowReference.initializePopupRef(popupRef, { left: settings.left, top: settings.top });
|
|
1236
|
+
if (modal) {
|
|
1237
|
+
const release = inertOutside(popupRef.overlayRef.hostElement);
|
|
1238
|
+
merge(popupRef.closeStart, popupRef.closed)
|
|
1239
|
+
.pipe(take(1))
|
|
1240
|
+
.subscribe(() => release());
|
|
1241
|
+
}
|
|
1242
|
+
// Once rendered, center again from the real size, in case the content changed it.
|
|
1243
|
+
afterNextRender({ write: () => popupRef.overlayRef.updatePosition() }, { injector: this.#injector });
|
|
994
1244
|
return windowReference.windowRef;
|
|
995
1245
|
}
|
|
996
1246
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
@@ -1006,20 +1256,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
|
|
|
1006
1256
|
class WindowComponent {
|
|
1007
1257
|
#destroyRef;
|
|
1008
1258
|
#windowService;
|
|
1259
|
+
#destroyed;
|
|
1009
1260
|
#windowRef;
|
|
1010
1261
|
constructor() {
|
|
1011
1262
|
this.#destroyRef = inject(DestroyRef);
|
|
1012
1263
|
this.#windowService = inject(WindowService);
|
|
1264
|
+
this.#destroyed = false;
|
|
1013
1265
|
this.actionTemplate = contentChild(WindowActionTemplateDirective, { ...(ngDevMode ? { debugName: "actionTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
|
|
1014
1266
|
this.contentTemplate = contentChild(WindowContentTemplateDirective, { ...(ngDevMode ? { debugName: "contentTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
|
|
1015
1267
|
this.footerTemplate = contentChild(WindowFooterTemplateDirective, { ...(ngDevMode ? { debugName: "footerTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
|
|
1268
|
+
this.projectedContent = viewChild.required("projectedContent", { ...(ngDevMode ? { debugName: "projectedContent" } : /* istanbul ignore next */ {}), read: TemplateRef });
|
|
1016
1269
|
this.titleTemplate = contentChild(WindowTitleTemplateDirective, { ...(ngDevMode ? { debugName: "titleTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
|
|
1270
|
+
/**
|
|
1271
|
+
* @description Accessible name for the window when it has no `title` or title template.
|
|
1272
|
+
*/
|
|
1273
|
+
this.ariaLabel = input(/* @ts-ignore */
|
|
1274
|
+
...(ngDevMode ? [undefined, { debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
1017
1275
|
/**
|
|
1018
1276
|
* @description Sets the visibility of the close button in the window header.
|
|
1019
1277
|
* @default true
|
|
1020
1278
|
*/
|
|
1021
1279
|
this.closable = input(true, /* @ts-ignore */
|
|
1022
1280
|
...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
|
|
1281
|
+
/**
|
|
1282
|
+
* @description Emits before the window closes, whatever closes it: the close button, Escape, a programmatic close,
|
|
1283
|
+
* or the component being destroyed. Call `preventDefault()` to keep it open (a close caused by destruction can't
|
|
1284
|
+
* be kept).
|
|
1285
|
+
*/
|
|
1023
1286
|
// eslint-disable-next-line @angular-eslint/no-output-native
|
|
1024
1287
|
this.close = output();
|
|
1025
1288
|
/**
|
|
@@ -1149,37 +1412,45 @@ class WindowComponent {
|
|
|
1149
1412
|
const center = untracked(() => this.top() == null && this.left() == null);
|
|
1150
1413
|
this.#windowRef?.resize({ height, width, center });
|
|
1151
1414
|
});
|
|
1152
|
-
afterNextRender({
|
|
1153
|
-
this.#destroyRef.onDestroy(() =>
|
|
1415
|
+
afterNextRender({ write: () => this.#openWindow() });
|
|
1416
|
+
this.#destroyRef.onDestroy(() => {
|
|
1417
|
+
// Outputs can't emit once the component is destroyed, so this close is silent.
|
|
1418
|
+
this.#destroyed = true;
|
|
1419
|
+
this.#windowRef?.close();
|
|
1420
|
+
});
|
|
1154
1421
|
}
|
|
1155
1422
|
closeWindow() {
|
|
1156
1423
|
this.#windowRef?.close();
|
|
1157
1424
|
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Moves the window, in pixels. An axis that isn't given keeps its place.
|
|
1427
|
+
*/
|
|
1158
1428
|
move(position) {
|
|
1159
|
-
|
|
1160
|
-
this.#windowRef?.move({ top: position.top });
|
|
1161
|
-
}
|
|
1162
|
-
if (position.left !== undefined) {
|
|
1163
|
-
this.#windowRef?.move({ left: position.left });
|
|
1164
|
-
}
|
|
1429
|
+
this.#windowRef?.move(position);
|
|
1165
1430
|
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Opens the window. Called once after the first render; call it again to reopen a window that was closed. Does
|
|
1433
|
+
* nothing while the window is open.
|
|
1434
|
+
*/
|
|
1166
1435
|
openWindow() {
|
|
1167
1436
|
this.#openWindow();
|
|
1168
1437
|
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Resizes the window, in pixels. A dimension that isn't given keeps its size.
|
|
1440
|
+
*/
|
|
1169
1441
|
resize(dimensions) {
|
|
1170
|
-
|
|
1171
|
-
this.#windowRef?.resize({ width: dimensions.width });
|
|
1172
|
-
}
|
|
1173
|
-
if (dimensions.height !== undefined) {
|
|
1174
|
-
this.#windowRef?.resize({ height: dimensions.height });
|
|
1175
|
-
}
|
|
1442
|
+
this.#windowRef?.resize(dimensions);
|
|
1176
1443
|
}
|
|
1177
1444
|
#openWindow() {
|
|
1445
|
+
if (this.#windowRef || this.#destroyed) {
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1178
1448
|
this.#windowRef = this.#windowService.open({
|
|
1179
1449
|
actionTemplate: this.actionTemplate(),
|
|
1450
|
+
ariaLabel: this.ariaLabel(),
|
|
1180
1451
|
closable: this.closable(),
|
|
1181
1452
|
closeOnEscape: this.closeOnEscape(),
|
|
1182
|
-
content: this.contentTemplate(),
|
|
1453
|
+
content: this.contentTemplate() ?? this.projectedContent(),
|
|
1183
1454
|
draggable: this.draggable(),
|
|
1184
1455
|
focusedElement: this.focusedElement(),
|
|
1185
1456
|
footerTemplate: this.footerTemplate(),
|
|
@@ -1203,14 +1474,23 @@ class WindowComponent {
|
|
|
1203
1474
|
this.#setSubscriptions();
|
|
1204
1475
|
}
|
|
1205
1476
|
#setCloseSubscription() {
|
|
1206
|
-
|
|
1477
|
+
const windowRef = this.#windowRef;
|
|
1478
|
+
if (!windowRef) {
|
|
1207
1479
|
return;
|
|
1208
1480
|
}
|
|
1209
|
-
this
|
|
1210
|
-
|
|
1481
|
+
// Not tied to this component's lifetime: destroying it closes the window, and these finish with it.
|
|
1482
|
+
windowRef.close$.subscribe(event => {
|
|
1483
|
+
if (!this.#destroyed) {
|
|
1484
|
+
this.close.emit(event);
|
|
1485
|
+
}
|
|
1211
1486
|
});
|
|
1212
|
-
|
|
1213
|
-
this
|
|
1487
|
+
windowRef.closed$.subscribe(() => {
|
|
1488
|
+
if (this.#windowRef === windowRef) {
|
|
1489
|
+
this.#windowRef = undefined;
|
|
1490
|
+
}
|
|
1491
|
+
if (!this.#destroyed) {
|
|
1492
|
+
this.closed.emit();
|
|
1493
|
+
}
|
|
1214
1494
|
});
|
|
1215
1495
|
}
|
|
1216
1496
|
#setDragSubscription() {
|
|
@@ -1257,18 +1537,19 @@ class WindowComponent {
|
|
|
1257
1537
|
this.#setResizeSubscription();
|
|
1258
1538
|
}
|
|
1259
1539
|
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:
|
|
1540
|
+
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
1541
|
}
|
|
1262
1542
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: WindowComponent, decorators: [{
|
|
1263
1543
|
type: Component,
|
|
1264
1544
|
args: [{
|
|
1265
1545
|
selector: "mona-window",
|
|
1266
|
-
|
|
1546
|
+
// Content placed directly inside <mona-window> is the window's content, unless a monaWindowContentTemplate is given.
|
|
1547
|
+
template: `<ng-template #projectedContent><ng-content /></ng-template>`,
|
|
1267
1548
|
host: {
|
|
1268
1549
|
class: "hidden"
|
|
1269
1550
|
}
|
|
1270
1551
|
}]
|
|
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"] }] } });
|
|
1552
|
+
}], 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
1553
|
|
|
1273
1554
|
/*
|
|
1274
1555
|
* Public API Surface of @nanahoshi/mona-ui/window
|
|
@@ -1278,5 +1559,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
|
|
|
1278
1559
|
* Generated bundle index. Do not edit.
|
|
1279
1560
|
*/
|
|
1280
1561
|
|
|
1281
|
-
export { WINDOW_DEFAULT_MESSAGES, WindowActionTemplateDirective, WindowComponent, WindowContentTemplateDirective, WindowFooterTemplateDirective, WindowRef, WindowService, WindowTitleTemplateDirective };
|
|
1562
|
+
export { WINDOW_DATA, WINDOW_DEFAULT_MESSAGES, WindowActionTemplateDirective, WindowComponent, WindowContentTemplateDirective, WindowFooterTemplateDirective, WindowRef, WindowService, WindowTitleTemplateDirective };
|
|
1282
1563
|
//# sourceMappingURL=nanahoshi-mona-ui-window.mjs.map
|