@vingy/vueltip 1.0.0 → 1.1.0

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/dist/index.d.mts CHANGED
@@ -252,13 +252,16 @@ type Binding = string | {
252
252
  content: string | Content;
253
253
  placement: Placement;
254
254
  };
255
- type TooltipDirective = Directive<HTMLElement, Binding>;
255
+ type Modifier = 'x' | 'y' | 'none' | 'both';
256
+ type TooltipDirective = Directive<HTMLElement, Binding, Modifier>;
256
257
  type Options = {
257
- /** @default 'tooltip-placement' */placementAttribute: string; /** @default 'tooltip-key' */
258
- keyAttribute: string; /** @default 0 */
258
+ /** @default 'vueltip-placement' */placementAttribute: string; /** @default 'vueltip-key' */
259
+ keyAttribute: string; /** @default 'vueltip-truncate' */
260
+ truncateAttribute: string; /** @default 0 */
259
261
  showDelay: number; /** @default 200 */
260
262
  hideDelay: number; /** @default false */
261
- handleDialogModals: boolean;
263
+ handleDialogModals: boolean; /** @default 'both' */
264
+ defaultTruncateDetection: Modifier;
262
265
  };
263
266
  type UseTooltipOptions = {
264
267
  tooltipElement: Readonly<ShallowRef<HTMLElement | null>>;
@@ -307,8 +310,8 @@ declare const useVueltip: ({
307
310
  //#endregion
308
311
  //#region src/directive.d.ts
309
312
  declare const vueltipDirective: {
310
- updated: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, string, any>) => void;
311
- created: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, string, any>) => void;
313
+ updated: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, Modifier, any>) => void;
314
+ created: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, Modifier, any>) => void;
312
315
  beforeUnmount: (el: HTMLElement) => void;
313
316
  };
314
317
  //#endregion
package/dist/index.mjs CHANGED
@@ -1392,9 +1392,11 @@ function useFloating(reference, floating, options) {
1392
1392
  let options = {
1393
1393
  placementAttribute: "vueltip-placement",
1394
1394
  keyAttribute: "vueltip-key",
1395
+ truncateAttribute: "vueltip-truncate",
1395
1396
  showDelay: 0,
1396
1397
  hideDelay: 200,
1397
- handleDialogModals: false
1398
+ handleDialogModals: false,
1399
+ defaultTruncateDetection: "both"
1398
1400
  };
1399
1401
  const setOptions = (opts) => {
1400
1402
  options = {
@@ -1497,7 +1499,18 @@ const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, ar
1497
1499
  //#endregion
1498
1500
  //#region src/utils.ts
1499
1501
  function isTruncated(el) {
1500
- return el.offsetWidth < el.scrollWidth - 1 || el.offsetHeight < el.scrollHeight - 1;
1502
+ const direction = getTruncationDirection(el);
1503
+ const x = el.offsetWidth < el.scrollWidth - 1;
1504
+ const y = el.offsetHeight < el.scrollHeight - 1;
1505
+ switch (direction) {
1506
+ case "x": return x;
1507
+ case "y": return y;
1508
+ case "both": return x || y;
1509
+ case "none": return true;
1510
+ }
1511
+ }
1512
+ function getTruncationDirection(el) {
1513
+ return el.getAttribute(options.truncateAttribute) ?? options.defaultTruncateDetection;
1501
1514
  }
1502
1515
  function elementContainsText(el, text) {
1503
1516
  if (isInputElement(el) || isTextAreaElement(el)) return getInputValue(el).includes(text);
@@ -1547,6 +1560,14 @@ const onMouseout = ensureEventTarget((target) => {
1547
1560
  //#region src/directive.ts
1548
1561
  const toContent = (value) => typeof value === "string" ? { text: value } : typeof value.content === "string" ? { text: value.content } : value.content;
1549
1562
  const extractPlacement = (value) => typeof value === "string" ? "top" : value.placement;
1563
+ const truncationDirection = (modifiers) => {
1564
+ if (modifiers.none) return "none";
1565
+ if (modifiers.both) return "both";
1566
+ if (modifiers.x && modifiers.y) return "both";
1567
+ if (modifiers.x) return "x";
1568
+ if (modifiers.y) return "y";
1569
+ return options.defaultTruncateDetection;
1570
+ };
1550
1571
  const vueltipDirective = {
1551
1572
  updated: (el, binding) => {
1552
1573
  ensureKey(el, (key) => setContent(key, toContent(binding.value)));
@@ -1556,6 +1577,7 @@ const vueltipDirective = {
1556
1577
  setContent(key, toContent(binding.value));
1557
1578
  el.setAttribute(options.keyAttribute, key);
1558
1579
  el.setAttribute(options.placementAttribute, extractPlacement(binding.value));
1580
+ el.setAttribute(options.truncateAttribute, truncationDirection(binding.modifiers ?? {}));
1559
1581
  el.addEventListener("mouseenter", onMouseover);
1560
1582
  el.addEventListener("focus", onMouseover);
1561
1583
  el.addEventListener("mouseleave", onMouseout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vingy/vueltip",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Headless tooltip which only shows when necessary.",
5
5
  "keywords": [
6
6
  "composition-api",