@vingy/vueltip 0.3.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 +36 -9
- package/dist/index.mjs +34 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __reExport, t as __exportAll } from "./chunk-CtajNgzt.mjs";
|
|
2
2
|
import * as Vue from "vue";
|
|
3
|
-
import { App, Component, ShallowRef, StyleValue } from "vue";
|
|
3
|
+
import { App, Component, Directive, ShallowRef, StyleValue } from "vue";
|
|
4
4
|
|
|
5
5
|
//#region ../../node_modules/.pnpm/@floating-ui+utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.d.mts
|
|
6
6
|
declare type AlignedPlacement = `${Side}-${Alignment}`;
|
|
@@ -248,12 +248,20 @@ declare type UseFloatingOptions<T extends ReferenceElement = ReferenceElement> =
|
|
|
248
248
|
interface Content {
|
|
249
249
|
text: string;
|
|
250
250
|
}
|
|
251
|
+
type Binding = string | {
|
|
252
|
+
content: string | Content;
|
|
253
|
+
placement: Placement;
|
|
254
|
+
};
|
|
255
|
+
type Modifier = 'x' | 'y' | 'none' | 'both';
|
|
256
|
+
type TooltipDirective = Directive<HTMLElement, Binding, Modifier>;
|
|
251
257
|
type Options = {
|
|
252
|
-
/** @default '
|
|
253
|
-
keyAttribute: string; /** @default
|
|
258
|
+
/** @default 'vueltip-placement' */placementAttribute: string; /** @default 'vueltip-key' */
|
|
259
|
+
keyAttribute: string; /** @default 'vueltip-truncate' */
|
|
260
|
+
truncateAttribute: string; /** @default 0 */
|
|
254
261
|
showDelay: number; /** @default 200 */
|
|
255
262
|
hideDelay: number; /** @default false */
|
|
256
|
-
handleDialogModals: boolean;
|
|
263
|
+
handleDialogModals: boolean; /** @default 'both' */
|
|
264
|
+
defaultTruncateDetection: Modifier;
|
|
257
265
|
};
|
|
258
266
|
type UseTooltipOptions = {
|
|
259
267
|
tooltipElement: Readonly<ShallowRef<HTMLElement | null>>;
|
|
@@ -263,9 +271,18 @@ type UseTooltipOptions = {
|
|
|
263
271
|
arrowSize?: number;
|
|
264
272
|
floatingOptions?: UseFloatingOptions<HTMLElement>;
|
|
265
273
|
};
|
|
274
|
+
declare module 'vue' {
|
|
275
|
+
interface GlobalDirectives {
|
|
276
|
+
vTooltip: TooltipDirective;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region ../shared/dist/types.d.mts
|
|
281
|
+
//#region src/types.d.ts
|
|
282
|
+
type Maybe<T> = T | null | undefined; //#endregion
|
|
266
283
|
//#endregion
|
|
267
284
|
//#region src/composables.d.ts
|
|
268
|
-
declare const
|
|
285
|
+
declare const useVueltip: ({
|
|
269
286
|
tooltipElement,
|
|
270
287
|
arrowElement,
|
|
271
288
|
offset: _offset,
|
|
@@ -291,11 +308,21 @@ declare const useTooltip: ({
|
|
|
291
308
|
content: Vue.Ref<Maybe<Content>, Maybe<Content>>;
|
|
292
309
|
};
|
|
293
310
|
//#endregion
|
|
311
|
+
//#region src/directive.d.ts
|
|
312
|
+
declare const vueltipDirective: {
|
|
313
|
+
updated: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, Modifier, any>) => void;
|
|
314
|
+
created: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, Modifier, any>) => void;
|
|
315
|
+
beforeUnmount: (el: HTMLElement) => void;
|
|
316
|
+
};
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/options.d.ts
|
|
319
|
+
declare const setOptions: (opts?: Partial<Options>) => void;
|
|
320
|
+
//#endregion
|
|
294
321
|
//#region src/plugin.d.ts
|
|
295
|
-
declare const
|
|
296
|
-
install: (app: App, options: Partial<Options
|
|
322
|
+
declare const vueltipPlugin: {
|
|
323
|
+
install: (app: App, options: Partial<Options & {
|
|
297
324
|
component: Component;
|
|
298
|
-
}) => void;
|
|
325
|
+
}>) => void;
|
|
299
326
|
};
|
|
300
327
|
//#endregion
|
|
301
|
-
export { type Content,
|
|
328
|
+
export { type Content, setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1390,11 +1390,13 @@ function useFloating(reference, floating, options) {
|
|
|
1390
1390
|
//#endregion
|
|
1391
1391
|
//#region src/options.ts
|
|
1392
1392
|
let options = {
|
|
1393
|
-
placementAttribute: "
|
|
1394
|
-
keyAttribute: "
|
|
1393
|
+
placementAttribute: "vueltip-placement",
|
|
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 = {
|
|
@@ -1441,7 +1443,7 @@ const sideMap = {
|
|
|
1441
1443
|
bottom: "top",
|
|
1442
1444
|
left: "right"
|
|
1443
1445
|
};
|
|
1444
|
-
const
|
|
1446
|
+
const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, arrowSize, floatingOptions }) => {
|
|
1445
1447
|
let initialParent;
|
|
1446
1448
|
onMounted(() => {
|
|
1447
1449
|
initialParent = tooltipElement.value?.parentElement;
|
|
@@ -1497,7 +1499,18 @@ const useTooltip = ({ tooltipElement, arrowElement, offset: _offset, padding, ar
|
|
|
1497
1499
|
//#endregion
|
|
1498
1500
|
//#region src/utils.ts
|
|
1499
1501
|
function isTruncated(el) {
|
|
1500
|
-
|
|
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,7 +1560,15 @@ 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;
|
|
1550
|
-
const
|
|
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
|
+
};
|
|
1571
|
+
const vueltipDirective = {
|
|
1551
1572
|
updated: (el, binding) => {
|
|
1552
1573
|
ensureKey(el, (key) => setContent(key, toContent(binding.value)));
|
|
1553
1574
|
},
|
|
@@ -1556,6 +1577,7 @@ const tooltipDirective = {
|
|
|
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);
|
|
@@ -1572,16 +1594,17 @@ const tooltipDirective = {
|
|
|
1572
1594
|
|
|
1573
1595
|
//#endregion
|
|
1574
1596
|
//#region src/plugin.ts
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1597
|
+
const vueltipPlugin = { install: (app, options) => {
|
|
1598
|
+
const { component, ...rest } = options;
|
|
1599
|
+
setOptions(rest);
|
|
1600
|
+
if (!component) return;
|
|
1578
1601
|
const container = document.createElement("div");
|
|
1579
1602
|
container.id = "__vueltip_root__";
|
|
1580
1603
|
document.body.appendChild(container);
|
|
1581
|
-
const tooltipApp = createApp(
|
|
1604
|
+
const tooltipApp = createApp(component);
|
|
1582
1605
|
tooltipApp._context = app._context;
|
|
1583
1606
|
tooltipApp.mount(container);
|
|
1584
1607
|
} };
|
|
1585
1608
|
|
|
1586
1609
|
//#endregion
|
|
1587
|
-
export {
|
|
1610
|
+
export { setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|