@nectary/components 5.50.7 → 5.51.1

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/bundle.js CHANGED
@@ -3687,7 +3687,7 @@ const enableOverscroll = () => {
3687
3687
  document.documentElement.style.removeProperty("overscroll-behavior");
3688
3688
  }
3689
3689
  };
3690
- const templateHTML$Z = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}:host(:not([open])) slot[name=content]{display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
3690
+ const templateHTML$Z = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}:host(:not([open])) slot[name=content]{display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1);transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y))}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
3691
3691
  const template$Z = document.createElement("template");
3692
3692
  template$Z.innerHTML = templateHTML$Z;
3693
3693
  class Pop extends NectaryElement {
@@ -4461,7 +4461,7 @@ const getPopOrientation$1 = (orientation) => {
4461
4461
  }
4462
4462
  return orientation;
4463
4463
  };
4464
- const templateHTML$Y = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
4464
+ const templateHTML$Y = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#text.hidden{display:none}#content-slot{display:block;font:var(--sinch-comp-tooltip-font-body);color:var(--sinch-comp-tooltip-color-text);word-break:break-word}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}:host([text-align=right]) #content-slot{text-align:right}:host([text-align=center]) #content-slot{text-align:center}:host([text-align=left]) #content-slot{text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><slot id="content-slot"></slot><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
4465
4465
  const TIP_SIZE$1 = 8;
4466
4466
  const SHOW_DELAY_SLOW = 1e3;
4467
4467
  const SHOW_DELAY_FAST = 250;
@@ -4469,6 +4469,7 @@ const HIDE_DELAY = 0;
4469
4469
  const ANIMATION_DURATION = 100;
4470
4470
  const FOCUSABLE_OUTSIDE_TARGET_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable=""], [contenteditable="true"]';
4471
4471
  const OPEN_FLOATING_LAYER_SELECTOR = "sinch-popover[open], sinch-pop[open], dialog[open]";
4472
+ const CONTENT_SLOT_NAME = "tooltip-content";
4472
4473
  const OVERLAP_TOLERANCE = 1;
4473
4474
  const MAX_ZERO_DIMENSION_PLACEMENT_RETRIES = 8;
4474
4475
  const MIN_FIRST_REVEAL_STABILITY_FRAMES = 3;
@@ -4479,6 +4480,17 @@ let hoveredTooltip = null;
4479
4480
  let suspendedFocusedTooltip = null;
4480
4481
  const template$Y = document.createElement("template");
4481
4482
  template$Y.innerHTML = templateHTML$Y;
4483
+ const TEXT_BREAK_TAGS = ["BR", "P", "DIV", "UL", "OL", "LI"];
4484
+ function getNodeText(node) {
4485
+ if (!(node instanceof Element)) {
4486
+ return node.textContent ?? "";
4487
+ }
4488
+ let text = "";
4489
+ for (const child of node.childNodes) {
4490
+ text += child instanceof Element && TEXT_BREAK_TAGS.includes(child.tagName) ? ` ${getNodeText(child)} ` : getNodeText(child);
4491
+ }
4492
+ return text;
4493
+ }
4482
4494
  class Tooltip extends NectaryElement {
4483
4495
  #$pop;
4484
4496
  #$tooltipText;
@@ -4486,6 +4498,7 @@ class Tooltip extends NectaryElement {
4486
4498
  #$contentWrapper;
4487
4499
  #$tip;
4488
4500
  #$target;
4501
+ #$contentSlot;
4489
4502
  #targetElements = [];
4490
4503
  #resizeObserver = null;
4491
4504
  #tooltipState;
@@ -4512,6 +4525,7 @@ class Tooltip extends NectaryElement {
4512
4525
  this.#$contentWrapper = shadowRoot.querySelector("#content-wrapper");
4513
4526
  this.#$tip = shadowRoot.querySelector("#tip");
4514
4527
  this.#$target = shadowRoot.querySelector("#target");
4528
+ this.#$contentSlot = shadowRoot.querySelector("#content-slot");
4515
4529
  this.#shouldReduceMotion = shouldReduceMotion();
4516
4530
  this.#controller = null;
4517
4531
  this.#tooltipState = new TooltipState({
@@ -4532,11 +4546,26 @@ class Tooltip extends NectaryElement {
4532
4546
  };
4533
4547
  this.#$pop.addEventListener("-close", this.#onPopClose, options);
4534
4548
  this.#$target.addEventListener("slotchange", this.#onTargetSlotChange, options);
4549
+ this.#$contentSlot.addEventListener("slotchange", this.#onContentSlotChange, options);
4535
4550
  this.#assignTargetNodes();
4536
- this.#childObserver = new MutationObserver(() => {
4537
- this.#assignTargetNodes();
4551
+ this.#childObserver = new MutationObserver((mutations) => {
4552
+ const affectsAssignment = mutations.some((mutation) => {
4553
+ return mutation.type === "childList" ? mutation.target === this : mutation.target.parentNode === this;
4554
+ });
4555
+ if (affectsAssignment) {
4556
+ this.#assignTargetNodes();
4557
+ }
4558
+ if (this.#hasSlottedContent()) {
4559
+ this.#updatePopA11yAttrs();
4560
+ }
4561
+ });
4562
+ this.#childObserver.observe(this, {
4563
+ childList: true,
4564
+ subtree: true,
4565
+ characterData: true,
4566
+ attributes: true,
4567
+ attributeFilter: ["slot", "text"]
4538
4568
  });
4539
- this.#childObserver.observe(this, { childList: true });
4540
4569
  this.addEventListener("-show", this.#onShowReactHandler, options);
4541
4570
  this.addEventListener("-hide", this.#onHideReactHandler, options);
4542
4571
  this.#resizeObserver = new ResizeObserver(() => {
@@ -4841,7 +4870,18 @@ class Tooltip extends NectaryElement {
4841
4870
  const nodes = Array.from(this.childNodes).filter(
4842
4871
  (node) => node instanceof Element || node instanceof Text
4843
4872
  );
4844
- this.#$target.assign(...nodes);
4873
+ const contentNodes = nodes.filter((node) => {
4874
+ return node instanceof Element && node.getAttribute("slot") === CONTENT_SLOT_NAME;
4875
+ });
4876
+ const targetNodes = nodes.filter((node) => !contentNodes.includes(node));
4877
+ this.#$target.assign(...targetNodes);
4878
+ this.#$contentSlot.assign(...contentNodes);
4879
+ }
4880
+ #hasSlottedContent() {
4881
+ return this.#$contentSlot.assignedNodes().length !== 0;
4882
+ }
4883
+ #hasContent() {
4884
+ return this.text.length !== 0 || this.#hasSlottedContent();
4845
4885
  }
4846
4886
  #targetContains(node) {
4847
4887
  return this.#$target.assignedElements().some((el) => composedContains(el, node));
@@ -5110,6 +5150,24 @@ class Tooltip extends NectaryElement {
5110
5150
  });
5111
5151
  }
5112
5152
  };
5153
+ // Pulls an overlap shift back toward zero until the bubble stays inside the viewport.
5154
+ // Never flips the shift or makes it larger than the overlap correction requested.
5155
+ #keepOverlapOffsetInView(offset, start, end, limit) {
5156
+ if (offset === 0) {
5157
+ return 0;
5158
+ }
5159
+ let next = offset;
5160
+ if (start + next < 0) {
5161
+ next = -start;
5162
+ }
5163
+ if (end + next > limit) {
5164
+ next = limit - end;
5165
+ }
5166
+ if (offset > 0) {
5167
+ return Math.min(offset, Math.max(0, next));
5168
+ }
5169
+ return Math.max(offset, Math.min(0, next));
5170
+ }
5113
5171
  #resolveOverlap(placementContext) {
5114
5172
  const orientation = this.orientation;
5115
5173
  const targetRect = toLocalRect(this.#$pop.footprintRect, placementContext);
@@ -5140,6 +5198,10 @@ class Tooltip extends NectaryElement {
5140
5198
  offsetX = targetRight - leftEdge;
5141
5199
  }
5142
5200
  }
5201
+ if (placementContext.transformedAncestor == null && !getBooleanAttribute(this, "allow-scroll")) {
5202
+ offsetX = this.#keepOverlapOffsetInView(offsetX, leftEdge, rightEdge, placementContext.boundsWidth);
5203
+ offsetY = this.#keepOverlapOffsetInView(offsetY, topEdge, bottomEdge, placementContext.boundsHeight);
5204
+ }
5143
5205
  this.#applyContentOffset(offsetX, offsetY);
5144
5206
  return offsetX !== 0 || offsetY !== 0;
5145
5207
  }
@@ -5188,14 +5250,23 @@ class Tooltip extends NectaryElement {
5188
5250
  }
5189
5251
  const text = this.text;
5190
5252
  this.#$tooltipText.textContent = text;
5191
- if (text.length !== 0) {
5253
+ if (this.#hasContent()) {
5192
5254
  this.#subscribeMouseEnterEvent();
5193
5255
  }
5194
5256
  }
5257
+ #updateTextVisibility() {
5258
+ setClass(this.#$tooltipText, "hidden", this.#hasSlottedContent());
5259
+ }
5260
+ #getContentText() {
5261
+ if (!this.#hasSlottedContent()) {
5262
+ return this.text;
5263
+ }
5264
+ return this.#$contentSlot.assignedNodes().map((node) => getNodeText(node)).join(" ").replace(/\s+/g, " ").trim();
5265
+ }
5195
5266
  #updatePopA11yAttrs() {
5196
5267
  const rawAriaLabel = getAttribute(this, "aria-label");
5197
5268
  const explicitAriaLabel = rawAriaLabel !== null && rawAriaLabel.trim().length > 0 ? rawAriaLabel.trim() : null;
5198
- const fallbackAriaLabel = this.text ?? "";
5269
+ const fallbackAriaLabel = this.#getContentText();
5199
5270
  const ariaLabel = explicitAriaLabel ?? (fallbackAriaLabel.length === 0 ? null : fallbackAriaLabel);
5200
5271
  updateAttribute(this.#$content, "aria-label", ariaLabel);
5201
5272
  const rawAriaDescription = getAttribute(this, "aria-description");
@@ -5210,7 +5281,7 @@ class Tooltip extends NectaryElement {
5210
5281
  this.#targetElements = this.#getTargetElements();
5211
5282
  if (this.#targetElements.length === 0) {
5212
5283
  requestAnimationFrame(() => {
5213
- if (!this.isDomConnected || this.#isSubscribed || this.text.length === 0) {
5284
+ if (!this.isDomConnected || this.#isSubscribed || !this.#hasContent()) {
5214
5285
  return;
5215
5286
  }
5216
5287
  this.#subscribeMouseEnterEvent();
@@ -5250,8 +5321,23 @@ class Tooltip extends NectaryElement {
5250
5321
  this.#$contentWrapper.removeEventListener("mouseenter", this.#onContentMouseEnter);
5251
5322
  this.#$contentWrapper.removeEventListener("mouseleave", this.#onMouseLeave);
5252
5323
  }
5324
+ #onContentSlotChange = () => {
5325
+ if (!this.isDomConnected) {
5326
+ return;
5327
+ }
5328
+ this.#updateTextVisibility();
5329
+ this.#updatePopA11yAttrs();
5330
+ if (!this.#hasContent()) {
5331
+ if (this.#isSubscribed) {
5332
+ this.#tooltipState.destroy();
5333
+ this.#unsubscribeMouseEnterEvent();
5334
+ }
5335
+ return;
5336
+ }
5337
+ this.#subscribeMouseEnterEvent();
5338
+ };
5253
5339
  #onTargetSlotChange = () => {
5254
- if (!this.isDomConnected || this.text.length === 0) {
5340
+ if (!this.isDomConnected || !this.#hasContent()) {
5255
5341
  return;
5256
5342
  }
5257
5343
  const isOpen = this.#isOpen();
@@ -7599,7 +7685,9 @@ const orientationValues = [
7599
7685
  "left",
7600
7686
  "right",
7601
7687
  "bottom",
7602
- "top"
7688
+ "top",
7689
+ "top-center",
7690
+ "bottom-center"
7603
7691
  ];
7604
7692
  const getPopOrientation = (orientation) => {
7605
7693
  if (orientation === "top") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.50.7",
3
+ "version": "5.51.1",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/pop/index.js CHANGED
@@ -8,7 +8,7 @@ import { getReactEventHandler } from "../utils/get-react-event-handler.js";
8
8
  import { isTargetEqual } from "../utils/event-target.js";
9
9
  import { getPlacementContext, toLocalRect } from "../utils/placement.js";
10
10
  import { orientationValues, disableOverscroll, enableOverscroll, getAnchorPosition, clampPosition } from "./utils.js";
11
- const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}:host(:not([open])) slot[name=content]{display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
11
+ const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}:host(:not([open])) slot[name=content]{display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1);transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y))}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
12
12
  const template = document.createElement("template");
13
13
  template.innerHTML = templateHTML;
14
14
  class Pop extends NectaryElement {
@@ -1,5 +1,5 @@
1
1
  import type { NectaryComponentReactByType, NectaryComponentVanillaByType, TRect, NectaryComponentReact, NectaryComponentVanilla } from '../types';
2
- export type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top' | 'left' | 'right';
2
+ export type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top' | 'top-center' | 'bottom-center' | 'left' | 'right';
3
3
  export type TSinchPopoverProps = {
4
4
  /** Allow scrolling of the page when popover is open */
5
5
  'allow-scroll'?: boolean;
package/popover/utils.js CHANGED
@@ -6,7 +6,9 @@ const orientationValues = [
6
6
  "left",
7
7
  "right",
8
8
  "bottom",
9
- "top"
9
+ "top",
10
+ "top-center",
11
+ "bottom-center"
10
12
  ];
11
13
  const getPopOrientation = (orientation) => {
12
14
  if (orientation === "top") {
package/tooltip/index.js CHANGED
@@ -7,7 +7,7 @@ import { getReactEventHandler } from "../utils/get-react-event-handler.js";
7
7
  import { getPlacementContext, toLocalRect } from "../utils/placement.js";
8
8
  import { TooltipState } from "./tooltip-state.js";
9
9
  import { getPopOrientation, orientationValues, textAlignValues, typeValues } from "./utils.js";
10
- const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
10
+ const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#text.hidden{display:none}#content-slot{display:block;font:var(--sinch-comp-tooltip-font-body);color:var(--sinch-comp-tooltip-color-text);word-break:break-word}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}:host([text-align=right]) #content-slot{text-align:right}:host([text-align=center]) #content-slot{text-align:center}:host([text-align=left]) #content-slot{text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><slot id="content-slot"></slot><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
11
11
  const TIP_SIZE = 8;
12
12
  const SHOW_DELAY_SLOW = 1e3;
13
13
  const SHOW_DELAY_FAST = 250;
@@ -15,6 +15,7 @@ const HIDE_DELAY = 0;
15
15
  const ANIMATION_DURATION = 100;
16
16
  const FOCUSABLE_OUTSIDE_TARGET_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable=""], [contenteditable="true"]';
17
17
  const OPEN_FLOATING_LAYER_SELECTOR = "sinch-popover[open], sinch-pop[open], dialog[open]";
18
+ const CONTENT_SLOT_NAME = "tooltip-content";
18
19
  const OVERLAP_TOLERANCE = 1;
19
20
  const MAX_ZERO_DIMENSION_PLACEMENT_RETRIES = 8;
20
21
  const MIN_FIRST_REVEAL_STABILITY_FRAMES = 3;
@@ -25,6 +26,17 @@ let hoveredTooltip = null;
25
26
  let suspendedFocusedTooltip = null;
26
27
  const template = document.createElement("template");
27
28
  template.innerHTML = templateHTML;
29
+ const TEXT_BREAK_TAGS = ["BR", "P", "DIV", "UL", "OL", "LI"];
30
+ function getNodeText(node) {
31
+ if (!(node instanceof Element)) {
32
+ return node.textContent ?? "";
33
+ }
34
+ let text = "";
35
+ for (const child of node.childNodes) {
36
+ text += child instanceof Element && TEXT_BREAK_TAGS.includes(child.tagName) ? ` ${getNodeText(child)} ` : getNodeText(child);
37
+ }
38
+ return text;
39
+ }
28
40
  class Tooltip extends NectaryElement {
29
41
  #$pop;
30
42
  #$tooltipText;
@@ -32,6 +44,7 @@ class Tooltip extends NectaryElement {
32
44
  #$contentWrapper;
33
45
  #$tip;
34
46
  #$target;
47
+ #$contentSlot;
35
48
  #targetElements = [];
36
49
  #resizeObserver = null;
37
50
  #tooltipState;
@@ -58,6 +71,7 @@ class Tooltip extends NectaryElement {
58
71
  this.#$contentWrapper = shadowRoot.querySelector("#content-wrapper");
59
72
  this.#$tip = shadowRoot.querySelector("#tip");
60
73
  this.#$target = shadowRoot.querySelector("#target");
74
+ this.#$contentSlot = shadowRoot.querySelector("#content-slot");
61
75
  this.#shouldReduceMotion = shouldReduceMotion();
62
76
  this.#controller = null;
63
77
  this.#tooltipState = new TooltipState({
@@ -78,11 +92,26 @@ class Tooltip extends NectaryElement {
78
92
  };
79
93
  this.#$pop.addEventListener("-close", this.#onPopClose, options);
80
94
  this.#$target.addEventListener("slotchange", this.#onTargetSlotChange, options);
95
+ this.#$contentSlot.addEventListener("slotchange", this.#onContentSlotChange, options);
81
96
  this.#assignTargetNodes();
82
- this.#childObserver = new MutationObserver(() => {
83
- this.#assignTargetNodes();
97
+ this.#childObserver = new MutationObserver((mutations) => {
98
+ const affectsAssignment = mutations.some((mutation) => {
99
+ return mutation.type === "childList" ? mutation.target === this : mutation.target.parentNode === this;
100
+ });
101
+ if (affectsAssignment) {
102
+ this.#assignTargetNodes();
103
+ }
104
+ if (this.#hasSlottedContent()) {
105
+ this.#updatePopA11yAttrs();
106
+ }
107
+ });
108
+ this.#childObserver.observe(this, {
109
+ childList: true,
110
+ subtree: true,
111
+ characterData: true,
112
+ attributes: true,
113
+ attributeFilter: ["slot", "text"]
84
114
  });
85
- this.#childObserver.observe(this, { childList: true });
86
115
  this.addEventListener("-show", this.#onShowReactHandler, options);
87
116
  this.addEventListener("-hide", this.#onHideReactHandler, options);
88
117
  this.#resizeObserver = new ResizeObserver(() => {
@@ -387,7 +416,18 @@ class Tooltip extends NectaryElement {
387
416
  const nodes = Array.from(this.childNodes).filter(
388
417
  (node) => node instanceof Element || node instanceof Text
389
418
  );
390
- this.#$target.assign(...nodes);
419
+ const contentNodes = nodes.filter((node) => {
420
+ return node instanceof Element && node.getAttribute("slot") === CONTENT_SLOT_NAME;
421
+ });
422
+ const targetNodes = nodes.filter((node) => !contentNodes.includes(node));
423
+ this.#$target.assign(...targetNodes);
424
+ this.#$contentSlot.assign(...contentNodes);
425
+ }
426
+ #hasSlottedContent() {
427
+ return this.#$contentSlot.assignedNodes().length !== 0;
428
+ }
429
+ #hasContent() {
430
+ return this.text.length !== 0 || this.#hasSlottedContent();
391
431
  }
392
432
  #targetContains(node) {
393
433
  return this.#$target.assignedElements().some((el) => composedContains(el, node));
@@ -656,6 +696,24 @@ class Tooltip extends NectaryElement {
656
696
  });
657
697
  }
658
698
  };
699
+ // Pulls an overlap shift back toward zero until the bubble stays inside the viewport.
700
+ // Never flips the shift or makes it larger than the overlap correction requested.
701
+ #keepOverlapOffsetInView(offset, start, end, limit) {
702
+ if (offset === 0) {
703
+ return 0;
704
+ }
705
+ let next = offset;
706
+ if (start + next < 0) {
707
+ next = -start;
708
+ }
709
+ if (end + next > limit) {
710
+ next = limit - end;
711
+ }
712
+ if (offset > 0) {
713
+ return Math.min(offset, Math.max(0, next));
714
+ }
715
+ return Math.max(offset, Math.min(0, next));
716
+ }
659
717
  #resolveOverlap(placementContext) {
660
718
  const orientation = this.orientation;
661
719
  const targetRect = toLocalRect(this.#$pop.footprintRect, placementContext);
@@ -686,6 +744,10 @@ class Tooltip extends NectaryElement {
686
744
  offsetX = targetRight - leftEdge;
687
745
  }
688
746
  }
747
+ if (placementContext.transformedAncestor == null && !getBooleanAttribute(this, "allow-scroll")) {
748
+ offsetX = this.#keepOverlapOffsetInView(offsetX, leftEdge, rightEdge, placementContext.boundsWidth);
749
+ offsetY = this.#keepOverlapOffsetInView(offsetY, topEdge, bottomEdge, placementContext.boundsHeight);
750
+ }
689
751
  this.#applyContentOffset(offsetX, offsetY);
690
752
  return offsetX !== 0 || offsetY !== 0;
691
753
  }
@@ -734,14 +796,23 @@ class Tooltip extends NectaryElement {
734
796
  }
735
797
  const text = this.text;
736
798
  this.#$tooltipText.textContent = text;
737
- if (text.length !== 0) {
799
+ if (this.#hasContent()) {
738
800
  this.#subscribeMouseEnterEvent();
739
801
  }
740
802
  }
803
+ #updateTextVisibility() {
804
+ setClass(this.#$tooltipText, "hidden", this.#hasSlottedContent());
805
+ }
806
+ #getContentText() {
807
+ if (!this.#hasSlottedContent()) {
808
+ return this.text;
809
+ }
810
+ return this.#$contentSlot.assignedNodes().map((node) => getNodeText(node)).join(" ").replace(/\s+/g, " ").trim();
811
+ }
741
812
  #updatePopA11yAttrs() {
742
813
  const rawAriaLabel = getAttribute(this, "aria-label");
743
814
  const explicitAriaLabel = rawAriaLabel !== null && rawAriaLabel.trim().length > 0 ? rawAriaLabel.trim() : null;
744
- const fallbackAriaLabel = this.text ?? "";
815
+ const fallbackAriaLabel = this.#getContentText();
745
816
  const ariaLabel = explicitAriaLabel ?? (fallbackAriaLabel.length === 0 ? null : fallbackAriaLabel);
746
817
  updateAttribute(this.#$content, "aria-label", ariaLabel);
747
818
  const rawAriaDescription = getAttribute(this, "aria-description");
@@ -756,7 +827,7 @@ class Tooltip extends NectaryElement {
756
827
  this.#targetElements = this.#getTargetElements();
757
828
  if (this.#targetElements.length === 0) {
758
829
  requestAnimationFrame(() => {
759
- if (!this.isDomConnected || this.#isSubscribed || this.text.length === 0) {
830
+ if (!this.isDomConnected || this.#isSubscribed || !this.#hasContent()) {
760
831
  return;
761
832
  }
762
833
  this.#subscribeMouseEnterEvent();
@@ -796,8 +867,23 @@ class Tooltip extends NectaryElement {
796
867
  this.#$contentWrapper.removeEventListener("mouseenter", this.#onContentMouseEnter);
797
868
  this.#$contentWrapper.removeEventListener("mouseleave", this.#onMouseLeave);
798
869
  }
870
+ #onContentSlotChange = () => {
871
+ if (!this.isDomConnected) {
872
+ return;
873
+ }
874
+ this.#updateTextVisibility();
875
+ this.#updatePopA11yAttrs();
876
+ if (!this.#hasContent()) {
877
+ if (this.#isSubscribed) {
878
+ this.#tooltipState.destroy();
879
+ this.#unsubscribeMouseEnterEvent();
880
+ }
881
+ return;
882
+ }
883
+ this.#subscribeMouseEnterEvent();
884
+ };
799
885
  #onTargetSlotChange = () => {
800
- if (!this.isDomConnected || this.text.length === 0) {
886
+ if (!this.isDomConnected || !this.#hasContent()) {
801
887
  return;
802
888
  }
803
889
  const isOpen = this.#isOpen();
@@ -4,8 +4,11 @@ export type TSinchTooltipTextAlign = 'center' | 'right' | 'left';
4
4
  export type TSinchTooltipType = 'slow' | 'fast';
5
5
  export type TSinchTooltipProps = {
6
6
  'is-opened'?: string;
7
- /** Text */
8
- text: string;
7
+ /**
8
+ * Text. Rendered as plain text; use a `slot="tooltip-content"` child for markup.
9
+ * Ignored when a `slot="tooltip-content"` child is present.
10
+ */
11
+ text?: string;
9
12
  /** Orientation, where it *points to* from origin */
10
13
  orientation?: TSinchTooltipOrientation;
11
14
  /** Type */