@thalassic/ui 22.15.1 → 22.15.2

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, model, input, signal, computed, booleanAttribute, Directive, ViewContainerRef, DestroyRef, viewChild, contentChild, PLATFORM_ID, Injectable, Component, Renderer2, ElementRef, numberAttribute, output, makeEnvironmentProviders, TemplateRef, forwardRef, effect, afterNextRender, linkedSignal, viewChildren, contentChildren, isDevMode, untracked, provideEnvironmentInitializer, DOCUMENT } from '@angular/core';
2
+ import { InjectionToken, inject, model, input, signal, computed, booleanAttribute, Directive, ViewContainerRef, DestroyRef, viewChild, contentChild, PLATFORM_ID, Component, Injectable, Renderer2, ElementRef, numberAttribute, output, makeEnvironmentProviders, TemplateRef, forwardRef, effect, afterNextRender, linkedSignal, viewChildren, contentChildren, isDevMode, untracked, provideEnvironmentInitializer, DOCUMENT } from '@angular/core';
3
3
  import { Overlay } from '@angular/cdk/overlay';
4
4
  import { TemplatePortal, ComponentPortal, CdkPortalOutlet } from '@angular/cdk/portal';
5
5
  import { takeUntilDestroyed, rxResource, toSignal, toObservable } from '@angular/core/rxjs-interop';
@@ -750,6 +750,16 @@ const buildMonthDays = (anchor, weekStartsOn, weeks) => {
750
750
  return eachDayOfInterval({ start, end });
751
751
  };
752
752
 
753
+ /**
754
+ * Block-axis anchoring of an overlay placed beside its origin, read as an arrow alignment along
755
+ * that edge: an overlay pinned by its top edge grows downward, keeping the origin at its start.
756
+ */
757
+ const OVERLAY_ARROW_BLOCK_ALIGNMENT_MAP = {
758
+ top: 'start',
759
+ center: 'center',
760
+ bottom: 'end',
761
+ };
762
+
753
763
  const OVERLAY_POSITION_MAP = {
754
764
  top: {
755
765
  originX: 'center',
@@ -930,6 +940,34 @@ const removeDescribedBy = (renderer, element, id) => {
930
940
  renderer.setAttribute(element, 'aria-describedby', tokens.join(' '));
931
941
  };
932
942
 
943
+ /**
944
+ * Derives where an arrow belongs from the connection pair the overlay actually settled on,
945
+ * so a panel that fell back to another position moves its arrow with it.
946
+ *
947
+ * The arrow sits on the panel edge facing the origin: an overlay anchored by its bottom edge
948
+ * hangs above the origin and points down from its own bottom. An overlay pinned by one of its
949
+ * edges extends away from that edge, so the origin — and with it the arrow — stays near the
950
+ * pinned end. Axes stay logical (`start` / `end` rather than left / right), so the result flips
951
+ * with the layout direction on its own.
952
+ *
953
+ * A pair that places the overlay neither above/below nor beside the origin — one covering its
954
+ * origin, for instance — has no edge to point from and resolves to `null`.
955
+ */
956
+ const resolveOverlayArrowPosition = (connectionPair) => {
957
+ const { originX, originY, overlayX, overlayY } = connectionPair;
958
+ const isStacked = (originY === 'top' && overlayY === 'bottom') || (originY === 'bottom' && overlayY === 'top');
959
+ if (isStacked)
960
+ return { side: overlayY === 'bottom' ? 'bottom' : 'top', alignment: overlayX };
961
+ const isBeside = (originX === 'start' && overlayX === 'end') || (originX === 'end' && overlayX === 'start');
962
+ if (isBeside) {
963
+ return {
964
+ side: overlayX === 'end' ? 'end' : 'start',
965
+ alignment: OVERLAY_ARROW_BLOCK_ALIGNMENT_MAP[overlayY],
966
+ };
967
+ }
968
+ return null;
969
+ };
970
+
933
971
  /** Reorders Sunday-first weekday labels so the one for `weekStartsOn` comes first. */
934
972
  const rotateWeekDays = (weekDays, weekStartsOn) => [
935
973
  ...weekDays.slice(weekStartsOn),
@@ -939,55 +977,6 @@ const rotateWeekDays = (weekDays, weekStartsOn) => [
939
977
  /** Attribute a delegated tooltip reads its content from, and matches its items by. */
940
978
  const DEFAULT_TOOLTIP_CONTENT_ATTRIBUTE = 'data-tooltip';
941
979
 
942
- class TooltipService {
943
- _overlay = inject(Overlay);
944
- _overlayRef = null;
945
- // Public methods
946
- show(origin, positions, tooltipPortal) {
947
- this.dispose();
948
- const positionStrategy = this._overlay
949
- .position()
950
- .flexibleConnectedTo(origin)
951
- .withPositions(positions);
952
- this._overlayRef = this._overlay.create({
953
- positionStrategy,
954
- scrollStrategy: this._overlay.scrollStrategies.reposition(),
955
- });
956
- return this._overlayRef.attach(tooltipPortal);
957
- }
958
- move(origin, positions) {
959
- if (this._overlayRef) {
960
- const positionStrategy = this._overlay
961
- .position()
962
- .flexibleConnectedTo(origin)
963
- .withPositions(positions);
964
- this._overlayRef.updatePositionStrategy(positionStrategy);
965
- }
966
- }
967
- // Detaches the tooltip so Angular's `animate.leave` plays the exit animation,
968
- // then disposes the pane once that animation finishes. The pane is kept alive
969
- // in the meantime so it is not torn down mid-animation.
970
- hide() {
971
- if (!this._overlayRef)
972
- return;
973
- const overlayRef = this._overlayRef;
974
- this._overlayRef = null;
975
- overlayRef.detach();
976
- disposeAfterLeaveAnimation(overlayRef);
977
- }
978
- dispose() {
979
- if (!this._overlayRef)
980
- return;
981
- this._overlayRef.dispose();
982
- this._overlayRef = null;
983
- }
984
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
985
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipService });
986
- }
987
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipService, decorators: [{
988
- type: Injectable
989
- }] });
990
-
991
980
  class Tooltip {
992
981
  static _counter = 0;
993
982
  id = `tls-tooltip-${++Tooltip._counter}`;
@@ -997,6 +986,14 @@ class Tooltip {
997
986
  ...(ngDevMode ? [{ debugName: "templateData" }] : /* istanbul ignore next */ []));
998
987
  color = model.required(/* @ts-ignore */
999
988
  ...(ngDevMode ? [{ debugName: "color" }] : /* istanbul ignore next */ []));
989
+ arrow = model.required(/* @ts-ignore */
990
+ ...(ngDevMode ? [{ debugName: "arrow" }] : /* istanbul ignore next */ []));
991
+ /**
992
+ * Edge the arrow points from, resolved from the position the overlay settled on. It stays
993
+ * `null` until the overlay reports one, so the arrow never renders on a guessed edge.
994
+ */
995
+ arrowPosition = model(null, /* @ts-ignore */
996
+ ...(ngDevMode ? [{ debugName: "arrowPosition" }] : /* istanbul ignore next */ []));
1000
997
  isString = computed(() => typeof this.content() === 'string', /* @ts-ignore */
1001
998
  ...(ngDevMode ? [{ debugName: "isString" }] : /* istanbul ignore next */ []));
1002
999
  templateRef = computed(() => {
@@ -1009,11 +1006,17 @@ class Tooltip {
1009
1006
  const className = 'tls-tooltip';
1010
1007
  const array = [className];
1011
1008
  array.push(`${className}--${this.color()}`);
1009
+ const arrowPosition = this.arrowPosition();
1010
+ if (this.arrow() && arrowPosition) {
1011
+ array.push(`${className}--arrow`);
1012
+ array.push(`${className}--arrow-${arrowPosition.side}`);
1013
+ array.push(`${className}--arrow-align-${arrowPosition.alignment}`);
1014
+ }
1012
1015
  return array;
1013
1016
  }, /* @ts-ignore */
1014
1017
  ...(ngDevMode ? [{ debugName: "hostClasses" }] : /* istanbul ignore next */ []));
1015
1018
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: Tooltip, deps: [], target: i0.ɵɵFactoryTarget.Component });
1016
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: Tooltip, isStandalone: true, selector: "tls-tooltip", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: true, transformFunction: null }, templateData: { classPropertyName: "templateData", publicName: "templateData", isSignal: true, isRequired: false, transformFunction: null }, color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { content: "contentChange", templateData: "templateDataChange", color: "colorChange" }, host: { attributes: { "role": "tooltip", "animate.enter": "tls-tooltip--enter", "animate.leave": "tls-tooltip--leave" }, properties: { "class": "hostClasses()", "id": "id" } }, ngImport: i0, template: `
1019
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: Tooltip, isStandalone: true, selector: "tls-tooltip", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: true, transformFunction: null }, templateData: { classPropertyName: "templateData", publicName: "templateData", isSignal: true, isRequired: false, transformFunction: null }, color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: true, transformFunction: null }, arrow: { classPropertyName: "arrow", publicName: "arrow", isSignal: true, isRequired: true, transformFunction: null }, arrowPosition: { classPropertyName: "arrowPosition", publicName: "arrowPosition", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { content: "contentChange", templateData: "templateDataChange", color: "colorChange", arrow: "arrowChange", arrowPosition: "arrowPositionChange" }, host: { attributes: { "role": "tooltip", "animate.enter": "tls-tooltip--enter", "animate.leave": "tls-tooltip--leave" }, properties: { "class": "hostClasses()", "id": "id" } }, ngImport: i0, template: `
1017
1020
  @if (isString()) {
1018
1021
  {{ content() }}
1019
1022
  } @else {
@@ -1047,14 +1050,100 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1047
1050
  'animate.leave': 'tls-tooltip--leave',
1048
1051
  },
1049
1052
  }]
1050
- }], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: true }] }, { type: i0.Output, args: ["contentChange"] }], templateData: [{ type: i0.Input, args: [{ isSignal: true, alias: "templateData", required: false }] }, { type: i0.Output, args: ["templateDataChange"] }], color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: true }] }, { type: i0.Output, args: ["colorChange"] }] } });
1053
+ }], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: true }] }, { type: i0.Output, args: ["contentChange"] }], templateData: [{ type: i0.Input, args: [{ isSignal: true, alias: "templateData", required: false }] }, { type: i0.Output, args: ["templateDataChange"] }], color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: true }] }, { type: i0.Output, args: ["colorChange"] }], arrow: [{ type: i0.Input, args: [{ isSignal: true, alias: "arrow", required: true }] }, { type: i0.Output, args: ["arrowChange"] }], arrowPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "arrowPosition", required: false }] }, { type: i0.Output, args: ["arrowPositionChange"] }] } });
1054
+
1055
+ class TooltipService {
1056
+ // Injections
1057
+ _overlay = inject(Overlay);
1058
+ // State
1059
+ _overlayRef = null;
1060
+ _tooltipRef = null;
1061
+ _positionSubscription = null;
1062
+ /**
1063
+ * Edge the visible tooltip settled on. The strategy applies its position while the portal is
1064
+ * still attaching, so the first change arrives before there is a component to hand it to.
1065
+ */
1066
+ _arrowPosition = null;
1067
+ // Public methods
1068
+ show(origin, positions) {
1069
+ this.dispose();
1070
+ this._overlayRef = this._overlay.create({
1071
+ positionStrategy: this._createPositionStrategy(origin, positions),
1072
+ scrollStrategy: this._overlay.scrollStrategies.reposition(),
1073
+ });
1074
+ this._tooltipRef = this._overlayRef.attach(new ComponentPortal(Tooltip));
1075
+ this._tooltipRef.instance.arrowPosition.set(this._arrowPosition);
1076
+ return this._tooltipRef;
1077
+ }
1078
+ move(origin, positions) {
1079
+ if (!this._overlayRef)
1080
+ return;
1081
+ this._overlayRef.updatePositionStrategy(this._createPositionStrategy(origin, positions));
1082
+ }
1083
+ // Detaches the tooltip so Angular's `animate.leave` plays the exit animation,
1084
+ // then disposes the pane once that animation finishes. The pane is kept alive
1085
+ // in the meantime so it is not torn down mid-animation.
1086
+ hide() {
1087
+ if (!this._overlayRef)
1088
+ return;
1089
+ const overlayRef = this._overlayRef;
1090
+ this._overlayRef = null;
1091
+ this._reset();
1092
+ overlayRef.detach();
1093
+ disposeAfterLeaveAnimation(overlayRef);
1094
+ }
1095
+ dispose() {
1096
+ if (!this._overlayRef)
1097
+ return;
1098
+ this._overlayRef.dispose();
1099
+ this._overlayRef = null;
1100
+ this._reset();
1101
+ }
1102
+ // Private methods
1103
+ /**
1104
+ * Builds a strategy that reports where it settled, so the tooltip points its arrow at the
1105
+ * position actually used rather than the one asked for.
1106
+ */
1107
+ _createPositionStrategy(origin, positions) {
1108
+ const positionStrategy = this._overlay
1109
+ .position()
1110
+ .flexibleConnectedTo(origin)
1111
+ .withPositions(positions);
1112
+ if (this._positionSubscription)
1113
+ this._positionSubscription.unsubscribe();
1114
+ this._positionSubscription = positionStrategy.positionChanges.subscribe(change => {
1115
+ this._arrowPosition = resolveOverlayArrowPosition(change.connectionPair);
1116
+ const tooltipRef = this._tooltipRef;
1117
+ if (!tooltipRef)
1118
+ return;
1119
+ tooltipRef.instance.arrowPosition.set(this._arrowPosition);
1120
+ });
1121
+ return positionStrategy;
1122
+ }
1123
+ /** Drops everything tied to the overlay that just went away. */
1124
+ _reset() {
1125
+ this._tooltipRef = null;
1126
+ this._arrowPosition = null;
1127
+ if (!this._positionSubscription)
1128
+ return;
1129
+ this._positionSubscription.unsubscribe();
1130
+ this._positionSubscription = null;
1131
+ }
1132
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1133
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipService });
1134
+ }
1135
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipService, decorators: [{
1136
+ type: Injectable
1137
+ }] });
1051
1138
 
1052
1139
  const DEFAULT_TOOLTIP_CONFIG = {
1053
1140
  positions: undefined,
1054
1141
  position: 'top',
1055
- offset: { x: 4, y: 4 },
1142
+ // Clears the arrow, which protrudes `--tls-tooltip-arrow-height` past the bubble.
1143
+ offset: { x: 8, y: 8 },
1056
1144
  origin: 'element',
1057
1145
  color: 'secondary',
1146
+ arrow: true,
1058
1147
  };
1059
1148
 
1060
1149
  const TOOLTIP_CONFIG = new InjectionToken('TOOLTIP_CONFIG', {
@@ -1089,6 +1178,9 @@ class TooltipTrigger {
1089
1178
  ...(ngDevMode ? [{ debugName: "tooltipOffset" }] : /* istanbul ignore next */ []));
1090
1179
  tooltipColor = input(this._config.color, /* @ts-ignore */
1091
1180
  ...(ngDevMode ? [{ debugName: "tooltipColor" }] : /* istanbul ignore next */ []));
1181
+ /** Points a small arrow at the anchor. Disable it for a plain bubble. */
1182
+ tooltipArrow = input(this._config.arrow, /* @ts-ignore */
1183
+ ...(ngDevMode ? [{ debugName: "tooltipArrow" }] : /* istanbul ignore next */ []));
1092
1184
  // State
1093
1185
  /** Element the visible tooltip is anchored to, `null` while nothing is shown. */
1094
1186
  _anchor = null;
@@ -1127,12 +1219,12 @@ class TooltipTrigger {
1127
1219
  return;
1128
1220
  this._hide();
1129
1221
  this._anchor = anchor;
1130
- const tooltipPortal = new ComponentPortal(Tooltip);
1131
1222
  const origin = this.tooltipOrigin() === 'cursor' && point ? point : anchor;
1132
- const tooltipRef = this._tooltipService.show(origin, this._positions(), tooltipPortal);
1223
+ const tooltipRef = this._tooltipService.show(origin, this._positions());
1133
1224
  tooltipRef.instance.content.set(content);
1134
1225
  tooltipRef.instance.templateData.set(data);
1135
1226
  tooltipRef.instance.color.set(this.tooltipColor());
1227
+ tooltipRef.instance.arrow.set(this.tooltipArrow());
1136
1228
  // A description identical to the accessible name would be announced twice; the tooltip is
1137
1229
  // purely visual then and the link is omitted.
1138
1230
  if (anchor.getAttribute('aria-label') === content)
@@ -1166,7 +1258,7 @@ class TooltipTrigger {
1166
1258
  this._tooltipService.dispose();
1167
1259
  }
1168
1260
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1169
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.5", type: TooltipTrigger, isStandalone: true, inputs: { tooltipDisabled: { classPropertyName: "tooltipDisabled", publicName: "tooltipDisabled", isSignal: true, isRequired: false, transformFunction: null }, tooltipOrigin: { classPropertyName: "tooltipOrigin", publicName: "tooltipOrigin", isSignal: true, isRequired: false, transformFunction: null }, tooltipPositions: { classPropertyName: "tooltipPositions", publicName: "tooltipPositions", isSignal: true, isRequired: false, transformFunction: null }, tooltipPosition: { classPropertyName: "tooltipPosition", publicName: "tooltipPosition", isSignal: true, isRequired: false, transformFunction: null }, tooltipOffset: { classPropertyName: "tooltipOffset", publicName: "tooltipOffset", isSignal: true, isRequired: false, transformFunction: null }, tooltipColor: { classPropertyName: "tooltipColor", publicName: "tooltipColor", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "document:keydown.escape": "onEscape()" } }, ngImport: i0 });
1261
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.5", type: TooltipTrigger, isStandalone: true, inputs: { tooltipDisabled: { classPropertyName: "tooltipDisabled", publicName: "tooltipDisabled", isSignal: true, isRequired: false, transformFunction: null }, tooltipOrigin: { classPropertyName: "tooltipOrigin", publicName: "tooltipOrigin", isSignal: true, isRequired: false, transformFunction: null }, tooltipPositions: { classPropertyName: "tooltipPositions", publicName: "tooltipPositions", isSignal: true, isRequired: false, transformFunction: null }, tooltipPosition: { classPropertyName: "tooltipPosition", publicName: "tooltipPosition", isSignal: true, isRequired: false, transformFunction: null }, tooltipOffset: { classPropertyName: "tooltipOffset", publicName: "tooltipOffset", isSignal: true, isRequired: false, transformFunction: null }, tooltipColor: { classPropertyName: "tooltipColor", publicName: "tooltipColor", isSignal: true, isRequired: false, transformFunction: null }, tooltipArrow: { classPropertyName: "tooltipArrow", publicName: "tooltipArrow", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "document:keydown.escape": "onEscape()" } }, ngImport: i0 });
1170
1262
  }
1171
1263
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: TooltipTrigger, decorators: [{
1172
1264
  type: Directive,
@@ -1175,7 +1267,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1175
1267
  '(document:keydown.escape)': 'onEscape()',
1176
1268
  },
1177
1269
  }]
1178
- }], propDecorators: { tooltipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipDisabled", required: false }] }], tooltipOrigin: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipOrigin", required: false }] }], tooltipPositions: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipPositions", required: false }] }], tooltipPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipPosition", required: false }] }], tooltipOffset: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipOffset", required: false }] }], tooltipColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipColor", required: false }] }] } });
1270
+ }], propDecorators: { tooltipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipDisabled", required: false }] }], tooltipOrigin: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipOrigin", required: false }] }], tooltipPositions: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipPositions", required: false }] }], tooltipPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipPosition", required: false }] }], tooltipOffset: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipOffset", required: false }] }], tooltipColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipColor", required: false }] }], tooltipArrow: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipArrow", required: false }] }] } });
1179
1271
 
1180
1272
  /**
1181
1273
  * Serves tooltips for a whole subtree from one instance. Any descendant carrying the content