mn-angular-lib 2.0.22 → 2.0.24

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.
@@ -5,7 +5,7 @@ import { CommonModule, NgClass, NgTemplateOutlet } from '@angular/common';
5
5
  import * as i1$1 from '@angular/forms';
6
6
  import { NgControl, Validators, FormsModule } from '@angular/forms';
7
7
  import { tv } from 'tailwind-variants';
8
- import { MnConfigService, MN_SECTION_PATH, MN_INSTANCE_ID, MnLanguageService, lucideIcons } from 'mn-angular-lib/core';
8
+ import { MnConfigService, MN_SECTION_PATH, MN_INSTANCE_ID, MnLanguageService, lucideIcons, MN_IN_BOTTOM_SHEET, MN_IN_MODAL } from 'mn-angular-lib/core';
9
9
  import { skip } from 'rxjs';
10
10
  import { LucideDynamicIcon } from '@lucide/angular';
11
11
  import * as lucide from 'lucide';
@@ -2270,16 +2270,25 @@ class MnSelect {
2270
2270
  /** Reference to the trigger element for positioning the dropdown. */
2271
2271
  triggerRef;
2272
2272
  /** Layout classes for the anchored popover panel. The mobile sheet is rendered by
2273
- * mn-bottom-sheet instead, so it no longer needs a branch here. */
2274
- panelClasses = 'fixed z-9999 w-max bg-base-100 border border-base-300 rounded-md shadow-lg max-h-60 overflow-auto';
2273
+ * mn-bottom-sheet instead, so it no longer needs a branch here. Inside a sheet the panel
2274
+ * shares the sheet's background, where a soft shadow does not show (least of all in dark
2275
+ * mode), so it gets a firmer edge and a deeper shadow there. */
2276
+ get panelClasses() {
2277
+ const edge = this.insideSheet ? 'z-[10001] border-base-content/30 shadow-2xl' : 'z-9999 border-base-300 shadow-lg';
2278
+ return `fixed w-max bg-base-100 border ${edge} rounded-md max-h-60 overflow-auto`;
2279
+ }
2275
2280
  /** The panel's own height cap in pixels: the `max-h-60` above, restated for the placement maths. */
2276
2281
  static PANEL_MAX_HEIGHT_PX = 240;
2277
2282
  /** Space kept between a widened panel and the viewport's right edge. */
2278
2283
  static PANEL_EDGE_GAP_PX = 8;
2279
- /** Layout classes for the invisible click shield rendered under the anchored panel.
2284
+ /** Layout classes for the click shield rendered under the anchored panel.
2280
2285
  * One step below the panel's z-index so the panel itself stays clickable, and above
2281
- * any modal/drawer chrome (which tops out well under 9998). */
2282
- shieldClasses = 'fixed inset-0 z-9998';
2286
+ * any modal/drawer chrome (which tops out well under 9998). Invisible, except inside a
2287
+ * sheet: there it dims the sheet a little, so the open list is the one thing in front. */
2288
+ get shieldClasses() {
2289
+ // Above the sheet (z-9999) inside one, or the dim would land behind it.
2290
+ return this.insideSheet ? 'fixed inset-0 z-[10000] bg-black/30' : 'fixed inset-0 z-9998';
2291
+ }
2283
2292
  /** Option count at which the search input auto-enables when `searchable` is unset. */
2284
2293
  static DEFAULT_SEARCH_THRESHOLD = 8;
2285
2294
  /** Tailwind's `sm` breakpoint — below this the panel renders as a bottom sheet.
@@ -2441,9 +2450,18 @@ class MnSelect {
2441
2450
  fullWidth: this.props.fullWidth,
2442
2451
  });
2443
2452
  }
2444
- /** Whether the panel should currently render as a bottom sheet. */
2453
+ /**
2454
+ * Whether this select already sits in a sheet: an `mn-bottom-sheet`, or a modal (which is a
2455
+ * sheet on a phone). Its own options sheet would then stack a second sheet on top.
2456
+ */
2457
+ insideSheet = inject(MN_IN_BOTTOM_SHEET) || inject(MN_IN_MODAL);
2458
+ /**
2459
+ * Whether the panel should currently render as a bottom sheet: on a narrow screen, unless the
2460
+ * consumer turned it off or the select is already inside a sheet, where it opens as an
2461
+ * anchored dropdown instead.
2462
+ */
2445
2463
  get isSheet() {
2446
- return this.props.mobileSheet !== false && this.isNarrowViewport;
2464
+ return this.props.mobileSheet !== false && this.isNarrowViewport && !this.insideSheet;
2447
2465
  }
2448
2466
  /**
2449
2467
  * Whether the search input is shown: the explicit `searchable` prop when set, otherwise
@@ -3034,14 +3052,23 @@ class MnMultiSelect {
3034
3052
  /** Reference to the trigger element for positioning the dropdown */
3035
3053
  triggerRef;
3036
3054
  /** Layout classes for the anchored popover panel. The mobile sheet is rendered by
3037
- * mn-bottom-sheet instead, so it no longer needs a branch here. */
3038
- panelClasses = 'fixed z-9999 bg-base-100 border border-base-300 rounded-md shadow-lg max-h-60 overflow-auto';
3055
+ * mn-bottom-sheet instead, so it no longer needs a branch here. Inside a sheet the panel
3056
+ * shares the sheet's background, where a soft shadow does not show (least of all in dark
3057
+ * mode), so it gets a firmer edge and a deeper shadow there. */
3058
+ get panelClasses() {
3059
+ const edge = this.insideSheet ? 'z-[10001] border-base-content/30 shadow-2xl' : 'z-9999 border-base-300 shadow-lg';
3060
+ return `fixed bg-base-100 border ${edge} rounded-md max-h-60 overflow-auto`;
3061
+ }
3039
3062
  /** The panel's own height cap in pixels: the `max-h-60` above, restated for the placement maths. */
3040
3063
  static PANEL_MAX_HEIGHT_PX = 240;
3041
- /** Layout classes for the invisible click shield rendered under the anchored panel.
3064
+ /** Layout classes for the click shield rendered under the anchored panel.
3042
3065
  * One step below the panel's z-index so the panel itself stays clickable, and above
3043
- * any modal/drawer chrome (which tops out well under 9998). */
3044
- shieldClasses = 'fixed inset-0 z-9998';
3066
+ * any modal/drawer chrome (which tops out well under 9998). Invisible, except inside a
3067
+ * sheet: there it dims the sheet a little, so the open list is the one thing in front. */
3068
+ get shieldClasses() {
3069
+ // Above the sheet (z-9999) inside one, or the dim would land behind it.
3070
+ return this.insideSheet ? 'fixed inset-0 z-[10000] bg-black/30' : 'fixed inset-0 z-9998';
3071
+ }
3045
3072
  /** The anchored popover panel currently moved into `document.body`, if any. */
3046
3073
  movedPanel = null;
3047
3074
  /** The click shield currently moved into `document.body`, if any. */
@@ -3250,9 +3277,18 @@ class MnMultiSelect {
3250
3277
  this.updateDropdownPosition();
3251
3278
  this.startWatchingTrigger();
3252
3279
  }
3253
- /** Whether the panel should currently render as a bottom sheet. */
3280
+ /**
3281
+ * Whether this multi-select already sits in a sheet: an `mn-bottom-sheet`, or a modal (which
3282
+ * is a sheet on a phone). Its own options sheet would then stack a second sheet on top.
3283
+ */
3284
+ insideSheet = inject(MN_IN_BOTTOM_SHEET) || inject(MN_IN_MODAL);
3285
+ /**
3286
+ * Whether the panel should currently render as a bottom sheet: on a narrow screen, unless the
3287
+ * consumer turned it off or the multi-select is already inside a sheet, where it opens as an
3288
+ * anchored dropdown instead.
3289
+ */
3254
3290
  get isSheet() {
3255
- return this.props.mobileSheet !== false && this.isNarrowViewport;
3291
+ return this.props.mobileSheet !== false && this.isNarrowViewport && !this.insideSheet;
3256
3292
  }
3257
3293
  /**
3258
3294
  * Whether the search input is shown: the explicit `searchable` prop when set,
@@ -3923,12 +3959,18 @@ class MnDropdown {
3923
3959
  * rendered by mn-bottom-sheet instead, so it needs no branch here.
3924
3960
  */
3925
3961
  get panelClasses() {
3926
- const base = 'fixed z-9999 min-w-48 max-w-[min(20rem,90vw)] bg-base-100 border border-base-300 rounded-md shadow-lg py-1 max-h-[60vh] -translate-x-full';
3962
+ const base = 'fixed z-9999 min-w-48 max-w-[min(20rem,90vw)] bg-base-100 border border-base-300 rounded-md shadow-lg py-1 max-h-[60vh]' +
3963
+ (this.alignStart ? '' : ' -translate-x-full');
3927
3964
  return this.isSearchable ? `${base} flex flex-col overflow-hidden` : `${base} overflow-auto`;
3928
3965
  }
3929
3966
  /** Tailwind's `sm` breakpoint — below this the menu renders as a bottom sheet.
3930
3967
  * Kept in step with the same constant in mn-bottom-sheet / mn-multi-select. */
3931
3968
  static SHEET_MAX_WIDTH = 639.98;
3969
+ /**
3970
+ * Whether the popover opens rightwards from the trigger's left edge instead of leftwards from
3971
+ * its right edge. Set by {@link fitIntoViewport} when there is no room on the left.
3972
+ */
3973
+ alignStart = false;
3932
3974
  /** The anchored popover panel currently moved into `document.body`, if any. */
3933
3975
  movedPanel = null;
3934
3976
  /** The bottom-sheet host, for outside-click tests. The sheet owns its own placement. */
@@ -3994,6 +4036,8 @@ class MnDropdown {
3994
4036
  set dropdownRef(ref) {
3995
4037
  const el = ref?.nativeElement ?? null;
3996
4038
  this.movedPanel = this.portal(el, this.movedPanel);
4039
+ if (el)
4040
+ this.fitIntoViewport(el);
3997
4041
  if (el)
3998
4042
  this.focusPendingItem();
3999
4043
  if (el && this.isSearchable) {
@@ -4264,6 +4308,7 @@ class MnDropdown {
4264
4308
  updateDropdownPosition() {
4265
4309
  if (!this.triggerRef)
4266
4310
  return;
4311
+ this.alignStart = false;
4267
4312
  const rect = this.triggerRef.nativeElement.getBoundingClientRect();
4268
4313
  // The panel is right-aligned to the trigger via a `-translate-x-full` class, so
4269
4314
  // `left` is anchored to the trigger's right edge.
@@ -4274,6 +4319,32 @@ class MnDropdown {
4274
4319
  left: `${rect.right}px`,
4275
4320
  };
4276
4321
  }
4322
+ /**
4323
+ * Keeps the opened popover inside the window. It normally hangs leftwards from the trigger's
4324
+ * right edge; near the left edge of the window that pushed it off-screen, so it then opens
4325
+ * rightwards from the trigger's left edge instead, and it never comes closer than 8 px to
4326
+ * either edge. Applied to the element directly as well as to the bound state, in the same pass
4327
+ * the panel appears, so no frame is drawn off-screen first.
4328
+ * @param panel The popover panel, already in the document with its content.
4329
+ */
4330
+ fitIntoViewport(panel) {
4331
+ const trigger = this.triggerRef?.nativeElement;
4332
+ if (!trigger || typeof window === 'undefined')
4333
+ return;
4334
+ const margin = 8;
4335
+ const rect = trigger.getBoundingClientRect();
4336
+ const width = panel.offsetWidth;
4337
+ // The usable width: innerWidth would count a page scrollbar as room.
4338
+ const viewport = document.documentElement.clientWidth || window.innerWidth;
4339
+ const alignStart = rect.right - width < margin;
4340
+ const left = alignStart
4341
+ ? Math.max(margin, Math.min(rect.left, viewport - width - margin))
4342
+ : Math.min(rect.right, viewport - margin);
4343
+ this.alignStart = alignStart;
4344
+ this.dropdownStyle = { ...this.dropdownStyle, left: `${left}px` };
4345
+ panel.style.left = `${left}px`;
4346
+ panel.classList.toggle('-translate-x-full', !alignStart);
4347
+ }
4277
4348
  startWatchingTrigger() {
4278
4349
  this.stopWatchingTrigger();
4279
4350
  const trigger = this.triggerRef?.nativeElement;