cbvirtua 1.0.3 → 1.0.5

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.
@@ -0,0 +1,17 @@
1
+ // @vue/component
2
+ export default {
3
+ methods: {
4
+ show(...args) {
5
+ return this.$refs.popper.show(...args);
6
+ },
7
+ hide(...args) {
8
+ return this.$refs.popper.hide(...args);
9
+ },
10
+ dispose(...args) {
11
+ return this.$refs.popper.dispose(...args);
12
+ },
13
+ onResize(...args) {
14
+ return this.$refs.popper.onResize(...args);
15
+ },
16
+ },
17
+ };
@@ -0,0 +1,9 @@
1
+ import { getThemeClasses } from '../config';
2
+ // @vue/component
3
+ export default {
4
+ computed: {
5
+ themeClass() {
6
+ return getThemeClasses(this.theme);
7
+ },
8
+ },
9
+ };
@@ -0,0 +1,133 @@
1
+ export const config = {
2
+ // Disable popper components
3
+ disabled: false,
4
+ // Default position offset along main axis (px)
5
+ distance: 5,
6
+ // Default position offset along cross axis (px)
7
+ skidding: 0,
8
+ // Default container where the tooltip will be appended
9
+ container: 'body',
10
+ // Element used to compute position and size boundaries
11
+ boundary: undefined,
12
+ // Skip delay & CSS transitions when another popper is shown, so that the popper appear to instanly move to the new position.
13
+ instantMove: false,
14
+ // Auto destroy tooltip DOM nodes (ms)
15
+ disposeTimeout: 5000,
16
+ // Triggers on the popper itself
17
+ popperTriggers: [],
18
+ // Positioning strategy
19
+ strategy: 'absolute',
20
+ // Prevent overflow
21
+ preventOverflow: true,
22
+ // Flip to the opposite placement if needed
23
+ flip: true,
24
+ // Shift on the cross axis to prevent the popper from overflowing
25
+ shift: true,
26
+ // Overflow padding (px)
27
+ overflowPadding: 0,
28
+ // Arrow padding (px)
29
+ arrowPadding: 0,
30
+ // Compute arrow overflow (useful to hide it)
31
+ arrowOverflow: true,
32
+ // Themes
33
+ themes: {
34
+ tooltip: {
35
+ // Default tooltip placement relative to target element
36
+ placement: 'top',
37
+ // Default events that trigger the tooltip
38
+ triggers: ['hover', 'focus', 'touch'],
39
+ // Close tooltip on click on tooltip target
40
+ hideTriggers: events => [...events, 'click'],
41
+ // Delay (ms)
42
+ delay: {
43
+ show: 200,
44
+ hide: 0,
45
+ },
46
+ // Update popper on content resize
47
+ handleResize: false,
48
+ // Enable HTML content in directive
49
+ html: false,
50
+ // Displayed when tooltip content is loading
51
+ loadingContent: '...',
52
+ },
53
+ dropdown: {
54
+ // Default dropdown placement relative to target element
55
+ placement: 'bottom',
56
+ // Default events that trigger the dropdown
57
+ triggers: ['click'],
58
+ // Delay (ms)
59
+ delay: 0,
60
+ // Update popper on content resize
61
+ handleResize: true,
62
+ // Hide on clock outside
63
+ autoHide: true,
64
+ },
65
+ menu: {
66
+ $extend: 'dropdown',
67
+ triggers: ['hover', 'focus'],
68
+ popperTriggers: ['hover', 'focus'],
69
+ delay: {
70
+ show: 0,
71
+ hide: 400,
72
+ },
73
+ },
74
+ },
75
+ };
76
+ /**
77
+ * Get default config value depending on theme
78
+ */
79
+ export function getDefaultConfig(theme, key) {
80
+ let themeConfig = config.themes[theme] || {};
81
+ let value;
82
+ do {
83
+ value = themeConfig[key];
84
+ if (typeof value === 'undefined') {
85
+ // Support theme extend
86
+ if (themeConfig.$extend) {
87
+ themeConfig = config.themes[themeConfig.$extend] || {};
88
+ }
89
+ else {
90
+ // Base config
91
+ themeConfig = null;
92
+ value = config[key];
93
+ }
94
+ }
95
+ else {
96
+ themeConfig = null;
97
+ }
98
+ } while (themeConfig);
99
+ return value;
100
+ }
101
+ /**
102
+ * Theme CSS inheritance
103
+ */
104
+ export function getThemeClasses(theme) {
105
+ const result = [theme];
106
+ let themeConfig = config.themes[theme] || {};
107
+ do {
108
+ // Support theme extend
109
+ if (themeConfig.$extend && !themeConfig.$resetCss) {
110
+ result.push(themeConfig.$extend);
111
+ themeConfig = config.themes[themeConfig.$extend] || {};
112
+ }
113
+ else {
114
+ themeConfig = null;
115
+ }
116
+ } while (themeConfig);
117
+ return result.map(c => `v-popper--theme-${c}`);
118
+ }
119
+ export function getAllParentThemes(theme) {
120
+ const result = [theme];
121
+ let themeConfig = config.themes[theme] || {};
122
+ do {
123
+ // Support theme extend
124
+ if (themeConfig.$extend) {
125
+ result.push(themeConfig.$extend);
126
+ themeConfig = config.themes[themeConfig.$extend] || {};
127
+ }
128
+ else {
129
+ themeConfig = null;
130
+ }
131
+ } while (themeConfig);
132
+ return result;
133
+ }
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <div class="meow">
3
+ <VDropdown
4
+ :triggers="['hover']"
5
+ :popper-triggers="['hover']"
6
+ >
7
+ <button>Meow</button>
8
+
9
+ <template #popper>
10
+ Menu
11
+ </template>
12
+ </VDropdown>
13
+ </div>
14
+ </template>
15
+
16
+ <style scoped>
17
+ .meow {
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ }
22
+ </style>
@@ -0,0 +1,87 @@
1
+ <template>
2
+ <div class="example flex justify-center items-center gap-6">
3
+ <VMenu placement="bottom-start">
4
+ <button class="border border-gray-300 rounded px-4 py-2">
5
+ Hover me
6
+ </button>
7
+
8
+ <template #popper>
9
+ <div class="px-4 py-1">
10
+ Sub menus:
11
+ </div>
12
+
13
+ <VMenu
14
+ v-for="n in 5"
15
+ :key="n"
16
+ placement="right-start"
17
+ instant-move
18
+ >
19
+ <button class="rounded hover:bg-green-100 px-4 py-2">
20
+ Sub menu >
21
+ </button>
22
+
23
+ <template #popper>
24
+ <VMenu
25
+ v-for="n in 5"
26
+ :key="n"
27
+ placement="right-start"
28
+ instant-move
29
+ >
30
+ <button class="rounded hover:bg-green-100 px-4 py-2">
31
+ Option {{ n }} >
32
+ </button>
33
+
34
+ <template #popper>
35
+ <div class="px-6 py-2">
36
+ Hello
37
+ </div>
38
+ </template>
39
+ </VMenu>
40
+ </template>
41
+ </VMenu>
42
+ </template>
43
+ </VMenu>
44
+
45
+ <VDropdown placement="bottom-start">
46
+ <button class="border border-gray-300 rounded px-4 py-2">
47
+ Click me
48
+ </button>
49
+
50
+ <template #popper>
51
+ <div class="px-4 py-1">
52
+ Sub menus:
53
+ </div>
54
+
55
+ <VDropdown
56
+ v-for="n in 5"
57
+ :key="n"
58
+ placement="right-start"
59
+ instant-move
60
+ >
61
+ <button class="rounded hover:bg-green-100 px-4 py-2">
62
+ Sub menu >
63
+ </button>
64
+
65
+ <template #popper>
66
+ <VDropdown
67
+ v-for="n in 5"
68
+ :key="n"
69
+ placement="right-start"
70
+ instant-move
71
+ >
72
+ <button class="rounded hover:bg-green-100 px-4 py-2">
73
+ Option {{ n }} >
74
+ </button>
75
+
76
+ <template #popper>
77
+ <div class="px-6 py-2">
78
+ Hello
79
+ </div>
80
+ </template>
81
+ </VDropdown>
82
+ </template>
83
+ </VDropdown>
84
+ </template>
85
+ </VDropdown>
86
+ </div>
87
+ </template>
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <div class="meow">
3
+ <button
4
+ v-tooltip="{
5
+ content: 'Tooltip',
6
+ triggers: ['hover'],
7
+ popperTriggers: ['hover'],
8
+ }"
9
+ >Meow</button>
10
+ </div>
11
+ </template>
12
+
13
+ <style scoped>
14
+ .meow {
15
+ display: flex;
16
+ align-items: center;
17
+ justify-content: center;
18
+ }
19
+ </style>
@@ -0,0 +1,67 @@
1
+ import { supportsPassive } from '../util/env';
2
+ function addListeners(el) {
3
+ el.addEventListener('click', onClick);
4
+ el.addEventListener('touchstart', onTouchStart, supportsPassive
5
+ ? {
6
+ passive: true,
7
+ }
8
+ : false);
9
+ }
10
+ function removeListeners(el) {
11
+ el.removeEventListener('click', onClick);
12
+ el.removeEventListener('touchstart', onTouchStart);
13
+ el.removeEventListener('touchend', onTouchEnd);
14
+ el.removeEventListener('touchcancel', onTouchCancel);
15
+ }
16
+ function onClick(event) {
17
+ const el = event.currentTarget;
18
+ event.closePopover = !el.$_vclosepopover_touch;
19
+ event.closeAllPopover = el.$_closePopoverModifiers && !!el.$_closePopoverModifiers.all;
20
+ }
21
+ function onTouchStart(event) {
22
+ if (event.changedTouches.length === 1) {
23
+ const el = event.currentTarget;
24
+ el.$_vclosepopover_touch = true;
25
+ const touch = event.changedTouches[0];
26
+ el.$_vclosepopover_touchPoint = touch;
27
+ el.addEventListener('touchend', onTouchEnd);
28
+ el.addEventListener('touchcancel', onTouchCancel);
29
+ }
30
+ }
31
+ function onTouchEnd(event) {
32
+ const el = event.currentTarget;
33
+ el.$_vclosepopover_touch = false;
34
+ if (event.changedTouches.length === 1) {
35
+ const touch = event.changedTouches[0];
36
+ const firstTouch = el.$_vclosepopover_touchPoint;
37
+ event.closePopover = (Math.abs(touch.screenY - firstTouch.screenY) < 20 &&
38
+ Math.abs(touch.screenX - firstTouch.screenX) < 20);
39
+ event.closeAllPopover = el.$_closePopoverModifiers && !!el.$_closePopoverModifiers.all;
40
+ }
41
+ }
42
+ function onTouchCancel(event) {
43
+ const el = event.currentTarget;
44
+ el.$_vclosepopover_touch = false;
45
+ }
46
+ export default {
47
+ bind(el, { value, modifiers }) {
48
+ el.$_closePopoverModifiers = modifiers;
49
+ if (typeof value === 'undefined' || value) {
50
+ addListeners(el);
51
+ }
52
+ },
53
+ update(el, { value, oldValue, modifiers }) {
54
+ el.$_closePopoverModifiers = modifiers;
55
+ if (value !== oldValue) {
56
+ if (typeof value === 'undefined' || value) {
57
+ addListeners(el);
58
+ }
59
+ else {
60
+ removeListeners(el);
61
+ }
62
+ }
63
+ },
64
+ unbind(el) {
65
+ removeListeners(el);
66
+ },
67
+ };
@@ -0,0 +1,116 @@
1
+ import Vue from 'vue';
2
+ import TooltipDirective from '../components/TooltipDirective.vue';
3
+ import { getDefaultConfig } from '../config';
4
+ import PopperMethods from '../components/PopperMethods';
5
+ import { placements } from '../util/popper';
6
+ const TARGET_CLASS = 'v-popper--has-tooltip';
7
+ /**
8
+ * Support placement as directive modifier
9
+ */
10
+ export function getPlacement(options, modifiers) {
11
+ let result = options.placement;
12
+ if (!result && modifiers) {
13
+ for (const pos of placements) {
14
+ if (modifiers[pos]) {
15
+ result = pos;
16
+ }
17
+ }
18
+ }
19
+ if (!result) {
20
+ result = getDefaultConfig(options.theme || 'tooltip', 'placement');
21
+ }
22
+ return result;
23
+ }
24
+ export function getOptions(el, value, modifiers) {
25
+ let options;
26
+ const type = typeof value;
27
+ if (type === 'string') {
28
+ options = { content: value };
29
+ }
30
+ else if (value && type === 'object') {
31
+ options = value;
32
+ }
33
+ else {
34
+ options = { content: false };
35
+ }
36
+ options.placement = getPlacement(options, modifiers);
37
+ options.targetNodes = () => [el];
38
+ options.referenceNode = () => el;
39
+ return options;
40
+ }
41
+ export function createTooltip(el, value, modifiers) {
42
+ const options = getOptions(el, value, modifiers);
43
+ const tooltipApp = el.$_popper = new Vue({
44
+ mixins: [
45
+ PopperMethods,
46
+ ],
47
+ data() {
48
+ return {
49
+ options,
50
+ };
51
+ },
52
+ render(h) {
53
+ const { theme, html, content, loadingContent, ...otherOptions } = this.options;
54
+ return h(TooltipDirective, {
55
+ props: {
56
+ theme,
57
+ html,
58
+ content,
59
+ loadingContent,
60
+ },
61
+ attrs: otherOptions,
62
+ ref: 'popper',
63
+ });
64
+ },
65
+ // @ts-expect-error custom option
66
+ devtools: {
67
+ hide: true,
68
+ },
69
+ });
70
+ const mountTarget = document.createElement('div');
71
+ document.body.appendChild(mountTarget);
72
+ tooltipApp.$mount(mountTarget);
73
+ // Class on target
74
+ if (el.classList) {
75
+ el.classList.add(TARGET_CLASS);
76
+ }
77
+ return tooltipApp;
78
+ }
79
+ export function destroyTooltip(el) {
80
+ if (el.$_popper) {
81
+ el.$_popper.$destroy();
82
+ delete el.$_popper;
83
+ delete el.$_popperOldShown;
84
+ }
85
+ if (el.classList) {
86
+ el.classList.remove(TARGET_CLASS);
87
+ }
88
+ }
89
+ export function bind(el, { value, oldValue, modifiers }) {
90
+ const options = getOptions(el, value, modifiers);
91
+ if (!options.content || getDefaultConfig(options.theme || 'tooltip', 'disabled')) {
92
+ destroyTooltip(el);
93
+ }
94
+ else {
95
+ let tooltipApp;
96
+ if (el.$_popper) {
97
+ tooltipApp = el.$_popper;
98
+ tooltipApp.options = options;
99
+ }
100
+ else {
101
+ tooltipApp = createTooltip(el, value, modifiers);
102
+ }
103
+ // Manual show
104
+ if (typeof value.shown !== 'undefined' && value.shown !== el.$_popperOldShown) {
105
+ el.$_popperOldShown = value.shown;
106
+ value.shown ? tooltipApp.show() : tooltipApp.hide();
107
+ }
108
+ }
109
+ }
110
+ export default {
111
+ bind,
112
+ update: bind,
113
+ unbind(el) {
114
+ destroyTooltip(el);
115
+ },
116
+ };
@@ -0,0 +1,28 @@
1
+ import { describe, test, expect } from '@peeky/test';
2
+ import * as VTooltip from './v-tooltip';
3
+ describe('getPlacement', () => {
4
+ test('object notation', () => {
5
+ const value = {
6
+ placement: 'bottom',
7
+ };
8
+ const modifiers = {};
9
+ const result = VTooltip.getPlacement(value, modifiers);
10
+ expect(result).toBe('bottom');
11
+ });
12
+ test('modifier', () => {
13
+ const value = {};
14
+ const modifiers = {
15
+ 'top-end': true,
16
+ };
17
+ const result = VTooltip.getPlacement(value, modifiers);
18
+ expect(result).toBe('top-end');
19
+ });
20
+ test('invalid modifier', () => {
21
+ const value = {};
22
+ const modifiers = {
23
+ 'left-middle': true,
24
+ };
25
+ const result = VTooltip.getPlacement(value, modifiers);
26
+ expect(result).toBe('top');
27
+ });
28
+ });
@@ -0,0 +1,74 @@
1
+ import { assign } from './util/assign-deep';
2
+ import { config } from './config';
3
+ import 'vue-resize/dist/vue-resize.css';
4
+ // Components
5
+ import PrivateDropdown from './components/Dropdown.vue';
6
+ import PrivateMenu from './components/Menu.vue';
7
+ import PrivatePopper from './components/Popper';
8
+ import PrivatePopperContent from './components/PopperContent.vue';
9
+ import PrivatePopperMethods from './components/PopperMethods';
10
+ import PrivatePopperWrapper from './components/PopperWrapper.vue';
11
+ import PrivateThemeClass from './components/ThemeClass';
12
+ import PrivateTooltip from './components/Tooltip.vue';
13
+ import PrivateTooltipDirective from './components/TooltipDirective.vue';
14
+ // Directives
15
+ import PrivateVTooltip from './directives/v-tooltip';
16
+ import PrivateVClosePopper from './directives/v-close-popper';
17
+ /* Exports */
18
+ export const options = config;
19
+ // Directive
20
+ export const VTooltip = PrivateVTooltip;
21
+ export { createTooltip, destroyTooltip } from './directives/v-tooltip';
22
+ export const VClosePopper = PrivateVClosePopper;
23
+ // Components
24
+ export const Dropdown = PrivateDropdown;
25
+ export const Menu = PrivateMenu;
26
+ export const Popper = PrivatePopper;
27
+ export const PopperContent = PrivatePopperContent;
28
+ export const PopperMethods = PrivatePopperMethods;
29
+ export const PopperWrapper = PrivatePopperWrapper;
30
+ export const ThemeClass = PrivateThemeClass;
31
+ export const Tooltip = PrivateTooltip;
32
+ export const TooltipDirective = PrivateTooltipDirective;
33
+ // Utils
34
+ export { hideAllPoppers } from './components/Popper';
35
+ export * from './util/events';
36
+ export { placements } from './util/popper';
37
+ /* Vue plugin */
38
+ export function install(app, options = {}) {
39
+ if (app.$_vTooltipInstalled)
40
+ return;
41
+ app.$_vTooltipInstalled = true;
42
+ assign(config, options);
43
+ // Directive
44
+ app.directive('tooltip', PrivateVTooltip);
45
+ app.directive('close-popper', PrivateVClosePopper);
46
+ // Components
47
+ // eslint-disable-next-line vue/component-definition-name-casing
48
+ app.component('v-tooltip', PrivateTooltip);
49
+ app.component('VTooltip', PrivateTooltip);
50
+ // eslint-disable-next-line vue/component-definition-name-casing
51
+ app.component('v-dropdown', PrivateDropdown);
52
+ app.component('VDropdown', PrivateDropdown);
53
+ // eslint-disable-next-line vue/component-definition-name-casing
54
+ app.component('v-menu', PrivateMenu);
55
+ app.component('VMenu', PrivateMenu);
56
+ }
57
+ const plugin = {
58
+ // eslint-disable-next-line no-undef
59
+ version: VERSION,
60
+ install,
61
+ options: config,
62
+ };
63
+ // Auto-install
64
+ let GlobalVue = null;
65
+ if (typeof window !== 'undefined') {
66
+ GlobalVue = window.Vue;
67
+ }
68
+ else if (typeof global !== 'undefined') {
69
+ GlobalVue = global.Vue;
70
+ }
71
+ if (GlobalVue) {
72
+ GlobalVue.use(plugin);
73
+ }
74
+ export default plugin;
@@ -0,0 +1,12 @@
1
+ export function assign(to, from) {
2
+ for (const key in from) {
3
+ if (Object.prototype.hasOwnProperty.call(from, key)) {
4
+ if (typeof from[key] === 'object' && to[key]) {
5
+ assign(to[key], from[key]);
6
+ }
7
+ else {
8
+ to[key] = from[key];
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,18 @@
1
+ export let supportsPassive = false;
2
+ if (typeof window !== 'undefined') {
3
+ supportsPassive = false;
4
+ try {
5
+ const opts = Object.defineProperty({}, 'passive', {
6
+ get() {
7
+ supportsPassive = true;
8
+ },
9
+ });
10
+ window.addEventListener('test', null, opts);
11
+ }
12
+ catch (e) { }
13
+ }
14
+ export let isIOS = false;
15
+ if (typeof window !== 'undefined' && typeof navigator !== 'undefined') {
16
+ // @ts-expect-error MSStream is missing in window type
17
+ isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
18
+ }
@@ -0,0 +1,12 @@
1
+ export const SHOW_EVENT_MAP = {
2
+ hover: 'mouseenter',
3
+ focus: 'focus',
4
+ click: 'click',
5
+ touch: 'touchstart',
6
+ };
7
+ export const HIDE_EVENT_MAP = {
8
+ hover: 'mouseleave',
9
+ focus: 'blur',
10
+ click: 'click',
11
+ touch: 'touchend',
12
+ };
@@ -0,0 +1,5 @@
1
+ export function nextFrame() {
2
+ return new Promise(resolve => requestAnimationFrame(() => {
3
+ requestAnimationFrame(resolve);
4
+ }));
5
+ }
@@ -0,0 +1,6 @@
1
+ export function removeFromArray(array, item) {
2
+ const index = array.indexOf(item);
3
+ if (index !== -1) {
4
+ array.splice(index, 1);
5
+ }
6
+ }
@@ -0,0 +1,5 @@
1
+ export const placements = ['auto', 'top', 'bottom', 'left', 'right'].reduce((acc, base) => acc.concat([
2
+ base,
3
+ `${base}-start`,
4
+ `${base}-end`,
5
+ ]), []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbvirtua",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {