v-calendar-3 1.0.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/LICENSE +9 -0
- package/README.md +142 -0
- package/dist/cjs/index.css +1133 -0
- package/dist/cjs/index.js +10699 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/es/index.js +10678 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/style.css +1134 -0
- package/dist/iife/index.js +2 -0
- package/dist/iife/index.js.map +1 -0
- package/dist/mjs/index.mjs +10678 -0
- package/dist/mjs/index.mjs.map +1 -0
- package/dist/mjs/style.css +1134 -0
- package/dist/style.css +1134 -0
- package/dist/types/components/BaseIcon/BaseIcon.vue.d.ts +41 -0
- package/dist/types/components/BaseIcon/icons/IconChevronDown.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/IconChevronLeft.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/IconChevronRight.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/IconClock.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/index.d.ts +4 -0
- package/dist/types/components/BaseSelect/BaseSelect.vue.d.ts +26 -0
- package/dist/types/components/Calendar/Calendar.vue.d.ts +2526 -0
- package/dist/types/components/Calendar/CalendarDay.vue.d.ts +83 -0
- package/dist/types/components/Calendar/CalendarDayPopover.vue.d.ts +3 -0
- package/dist/types/components/Calendar/CalendarHeader.vue.d.ts +13 -0
- package/dist/types/components/Calendar/CalendarNav.vue.d.ts +4 -0
- package/dist/types/components/Calendar/CalendarNavPopover.vue.d.ts +3 -0
- package/dist/types/components/Calendar/CalendarPage.vue.d.ts +3 -0
- package/dist/types/components/Calendar/CalendarPageProvider.vue.d.ts +17 -0
- package/dist/types/components/Calendar/CalendarSlot.vue.d.ts +15 -0
- package/dist/types/components/Calendar/CalendarTitleSelect.vue.d.ts +15 -0
- package/dist/types/components/CalendarGrid/CalendarCell.vue.d.ts +9 -0
- package/dist/types/components/CalendarGrid/CalendarCellPopover.vue.d.ts +209 -0
- package/dist/types/components/CalendarGrid/CalendarDayCell.vue.d.ts +8 -0
- package/dist/types/components/CalendarGrid/CalendarEventDetails.vue.d.ts +15 -0
- package/dist/types/components/CalendarGrid/CalendarEventEdit.vue.d.ts +26 -0
- package/dist/types/components/CalendarGrid/CalendarGrid.vue.d.ts +134 -0
- package/dist/types/components/CalendarGrid/CalendarGridWeek.vue.d.ts +8 -0
- package/dist/types/components/CalendarGrid/CalendarViewSelect.vue.d.ts +3 -0
- package/dist/types/components/CalendarGrid/CalendarWeekCell.vue.d.ts +10 -0
- package/dist/types/components/CalendarGrid/Constraints.d.ts +16 -0
- package/dist/types/components/DatePicker/DatePicker.vue.d.ts +15251 -0
- package/dist/types/components/DatePicker/DatePickerBase.vue.d.ts +3 -0
- package/dist/types/components/DatePicker/DatePickerPopover.vue.d.ts +3 -0
- package/dist/types/components/DatePicker/TimePicker.vue.d.ts +10089 -0
- package/dist/types/components/Popover/Popover.vue.d.ts +72 -0
- package/dist/types/components/Popover/PopoverRow.vue.d.ts +17 -0
- package/dist/types/components/index.d.ts +4 -0
- package/dist/types/index.d.cts +40981 -0
- package/dist/types/index.d.mts +40981 -0
- package/dist/types/index.d.ts +40981 -0
- package/dist/types/use/base.d.ts +67 -0
- package/dist/types/use/calendar.d.ts +2422 -0
- package/dist/types/use/calendarGrid.d.ts +9370 -0
- package/dist/types/use/datePicker.d.ts +20210 -0
- package/dist/types/use/page.d.ts +20 -0
- package/dist/types/use/slots.d.ts +5 -0
- package/dist/types/use/timePicker.d.ts +10089 -0
- package/dist/types/utils/attribute.d.ts +49 -0
- package/dist/types/utils/cache.d.ts +10 -0
- package/dist/types/utils/calendar/event.d.ts +111 -0
- package/dist/types/utils/config/index.d.ts +5 -0
- package/dist/types/utils/date/helpers.d.ts +161 -0
- package/dist/types/utils/date/range.d.ts +74 -0
- package/dist/types/utils/date/repeat.d.ts +34 -0
- package/dist/types/utils/date/rules.d.ts +82 -0
- package/dist/types/utils/defaults/index.d.ts +30 -0
- package/dist/types/utils/defaults/locales.d.ts +9 -0
- package/dist/types/utils/glyph.d.ts +58 -0
- package/dist/types/utils/helpers.d.ts +49 -0
- package/dist/types/utils/locale.d.ts +48 -0
- package/dist/types/utils/page.d.ts +95 -0
- package/dist/types/utils/plugins/index.d.ts +4 -0
- package/dist/types/utils/popovers.d.ts +47 -0
- package/dist/types/utils/theme.d.ts +17 -0
- package/dist/types/utils/touch.d.ts +8 -0
- package/dist/types/utils/useDisplayMode.d.ts +12 -0
- package/dist/types/utils/watchers.d.ts +6 -0
- package/package.json +115 -0
- package/src/components/BaseIcon/BaseIcon.vue +29 -0
- package/src/components/BaseIcon/icons/IconChevronDown.vue +5 -0
- package/src/components/BaseIcon/icons/IconChevronLeft.vue +5 -0
- package/src/components/BaseIcon/icons/IconChevronRight.vue +5 -0
- package/src/components/BaseIcon/icons/IconClock.vue +11 -0
- package/src/components/BaseIcon/icons/index.ts +4 -0
- package/src/components/BaseSelect/BaseSelect.vue +136 -0
- package/src/components/Calendar/Calendar.vue +116 -0
- package/src/components/Calendar/CalendarDay.vue +422 -0
- package/src/components/Calendar/CalendarDayPopover.vue +44 -0
- package/src/components/Calendar/CalendarHeader.vue +203 -0
- package/src/components/Calendar/CalendarNav.vue +325 -0
- package/src/components/Calendar/CalendarNavPopover.vue +24 -0
- package/src/components/Calendar/CalendarPage.vue +140 -0
- package/src/components/Calendar/CalendarPageProvider.vue +15 -0
- package/src/components/Calendar/CalendarSlot.vue +36 -0
- package/src/components/Calendar/CalendarTitleSelect.vue +72 -0
- package/src/components/CalendarGrid/CalendarCell.vue +112 -0
- package/src/components/CalendarGrid/CalendarCellPopover.vue +93 -0
- package/src/components/CalendarGrid/CalendarDayCell.vue +57 -0
- package/src/components/CalendarGrid/CalendarEventDetails.vue +71 -0
- package/src/components/CalendarGrid/CalendarEventEdit.vue +195 -0
- package/src/components/CalendarGrid/CalendarGrid.vue +715 -0
- package/src/components/CalendarGrid/CalendarGridWeek.vue +60 -0
- package/src/components/CalendarGrid/CalendarViewSelect.vue +34 -0
- package/src/components/CalendarGrid/CalendarWeekCell.vue +52 -0
- package/src/components/CalendarGrid/Constraints.ts +40 -0
- package/src/components/DatePicker/DatePicker.vue +27 -0
- package/src/components/DatePicker/DatePickerBase.vue +53 -0
- package/src/components/DatePicker/DatePickerPopover.vue +37 -0
- package/src/components/DatePicker/TimePicker.vue +167 -0
- package/src/components/Popover/Popover.vue +572 -0
- package/src/components/Popover/PopoverRow.vue +94 -0
- package/src/components/index.ts +4 -0
- package/src/index.ts +24 -0
- package/src/styles/index.css +48 -0
- package/src/styles/theme.css +322 -0
- package/src/styles/transitions.css +77 -0
- package/src/use/base.ts +144 -0
- package/src/use/calendar.ts +796 -0
- package/src/use/calendarGrid.ts +954 -0
- package/src/use/datePicker.ts +909 -0
- package/src/use/page.ts +78 -0
- package/src/use/slots.ts +17 -0
- package/src/use/timePicker.ts +194 -0
- package/src/utils/attribute.ts +107 -0
- package/src/utils/cache.ts +30 -0
- package/src/utils/calendar/event.ts +335 -0
- package/src/utils/config/index.ts +11 -0
- package/src/utils/date/helpers.ts +1039 -0
- package/src/utils/date/range.ts +274 -0
- package/src/utils/date/repeat.ts +135 -0
- package/src/utils/date/rules.ts +290 -0
- package/src/utils/defaults/index.ts +77 -0
- package/src/utils/defaults/locales.ts +123 -0
- package/src/utils/defaults/masks.json +15 -0
- package/src/utils/defaults/touch.json +5 -0
- package/src/utils/glyph.ts +305 -0
- package/src/utils/helpers.ts +181 -0
- package/src/utils/locale.ts +275 -0
- package/src/utils/page.ts +608 -0
- package/src/utils/plugins/index.ts +24 -0
- package/src/utils/popovers.ts +216 -0
- package/src/utils/theme.ts +58 -0
- package/src/utils/touch.ts +72 -0
- package/src/utils/useDisplayMode.ts +198 -0
- package/src/utils/watchers.ts +26 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="vc-popover-content-wrapper"
|
|
4
|
+
:class="{ 'is-interactive': isInteractive }"
|
|
5
|
+
ref="popoverRef"
|
|
6
|
+
@click="onClick"
|
|
7
|
+
@mouseover="onMouseOver"
|
|
8
|
+
@mouseleave="onMouseLeave"
|
|
9
|
+
@focusin="onFocusIn"
|
|
10
|
+
@focusout="onFocusOut"
|
|
11
|
+
>
|
|
12
|
+
<Transition
|
|
13
|
+
:name="`vc-${transition}`"
|
|
14
|
+
appear
|
|
15
|
+
@before-enter="beforeEnter"
|
|
16
|
+
@after-enter="afterEnter"
|
|
17
|
+
@before-leave="beforeLeave"
|
|
18
|
+
@after-leave="afterLeave"
|
|
19
|
+
>
|
|
20
|
+
<div
|
|
21
|
+
v-if="isVisible"
|
|
22
|
+
tabindex="-1"
|
|
23
|
+
:class="`vc-popover-content direction-${direction}`"
|
|
24
|
+
v-bind="$attrs"
|
|
25
|
+
>
|
|
26
|
+
<slot
|
|
27
|
+
:direction="direction"
|
|
28
|
+
:alignment="alignment"
|
|
29
|
+
:data="data"
|
|
30
|
+
:hide="hide"
|
|
31
|
+
>
|
|
32
|
+
{{ data }}
|
|
33
|
+
</slot>
|
|
34
|
+
<span
|
|
35
|
+
:class="[
|
|
36
|
+
'vc-popover-caret',
|
|
37
|
+
`direction-${direction}`,
|
|
38
|
+
`align-${alignment}`,
|
|
39
|
+
]"
|
|
40
|
+
/>
|
|
41
|
+
</div>
|
|
42
|
+
</Transition>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script lang="ts">
|
|
47
|
+
import {
|
|
48
|
+
type Instance,
|
|
49
|
+
type OptionsGeneric,
|
|
50
|
+
type State as PopperState,
|
|
51
|
+
type PositioningStrategy,
|
|
52
|
+
createPopper,
|
|
53
|
+
} from '@popperjs/core';
|
|
54
|
+
import {
|
|
55
|
+
computed,
|
|
56
|
+
defineComponent,
|
|
57
|
+
nextTick,
|
|
58
|
+
onMounted,
|
|
59
|
+
onUnmounted,
|
|
60
|
+
reactive,
|
|
61
|
+
ref,
|
|
62
|
+
toRefs,
|
|
63
|
+
watch,
|
|
64
|
+
} from 'vue';
|
|
65
|
+
import { elementContains, off, omit, on, resolveEl } from '../../utils/helpers';
|
|
66
|
+
import type {
|
|
67
|
+
PopoverEvent,
|
|
68
|
+
PopoverOptions,
|
|
69
|
+
PopoverState,
|
|
70
|
+
} from '../../utils/popovers';
|
|
71
|
+
|
|
72
|
+
export default defineComponent({
|
|
73
|
+
inheritAttrs: false,
|
|
74
|
+
emits: ['before-show', 'after-show', 'before-hide', 'after-hide'],
|
|
75
|
+
props: {
|
|
76
|
+
id: { type: [Number, String, Symbol], required: true },
|
|
77
|
+
showDelay: { type: Number, default: 0 },
|
|
78
|
+
hideDelay: { type: Number, default: 110 },
|
|
79
|
+
boundarySelector: { type: String },
|
|
80
|
+
},
|
|
81
|
+
setup(props, { emit }) {
|
|
82
|
+
let timeout: number | undefined = undefined;
|
|
83
|
+
const popoverRef = ref<HTMLElement>();
|
|
84
|
+
let resizeObserver: ResizeObserver | null = null;
|
|
85
|
+
let triggerObserver: MutationObserver | null = null;
|
|
86
|
+
let popper: Instance | null = null;
|
|
87
|
+
let ownerDocument: Document | null = null;
|
|
88
|
+
let isUnmounted = false;
|
|
89
|
+
|
|
90
|
+
const state: PopoverState = reactive({
|
|
91
|
+
isVisible: false,
|
|
92
|
+
target: null,
|
|
93
|
+
data: null,
|
|
94
|
+
transition: 'slide-fade',
|
|
95
|
+
placement: 'bottom',
|
|
96
|
+
direction: '',
|
|
97
|
+
positionFixed: false,
|
|
98
|
+
modifiers: [],
|
|
99
|
+
isInteractive: true,
|
|
100
|
+
visibility: 'click',
|
|
101
|
+
isHovered: false,
|
|
102
|
+
isFocused: false,
|
|
103
|
+
autoHide: false,
|
|
104
|
+
force: false,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function updateDirection(placement?: string) {
|
|
108
|
+
if (placement) state.direction = placement.split('-')[0];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function onPopperUpdate({ placement, options }: Partial<PopperState>) {
|
|
112
|
+
updateDirection(placement || options?.placement);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const popperOptions = computed<Partial<OptionsGeneric<any>>>(() => {
|
|
116
|
+
return {
|
|
117
|
+
placement: state.placement,
|
|
118
|
+
strategy: (state.positionFixed
|
|
119
|
+
? 'fixed'
|
|
120
|
+
: 'absolute') as PositioningStrategy,
|
|
121
|
+
boundary: '',
|
|
122
|
+
modifiers: [
|
|
123
|
+
{
|
|
124
|
+
name: 'onUpdate',
|
|
125
|
+
enabled: true,
|
|
126
|
+
phase: 'afterWrite',
|
|
127
|
+
fn: onPopperUpdate,
|
|
128
|
+
},
|
|
129
|
+
...(state.modifiers || []),
|
|
130
|
+
],
|
|
131
|
+
onFirstUpdate: onPopperUpdate,
|
|
132
|
+
};
|
|
133
|
+
// if (props.boundarySelector) {
|
|
134
|
+
// const boundary = document.querySelector(props.boundarySelector);
|
|
135
|
+
// modifiers.push({
|
|
136
|
+
// name: 'boundary',
|
|
137
|
+
// enabled: true,
|
|
138
|
+
// phase: 'main',
|
|
139
|
+
// requiresIfExists: ['offset'],
|
|
140
|
+
// fn({ state }) {
|
|
141
|
+
// console.log(
|
|
142
|
+
// detectOverflow(state, {
|
|
143
|
+
// boundary,
|
|
144
|
+
// altBoundary: true,
|
|
145
|
+
// }),
|
|
146
|
+
// );
|
|
147
|
+
// },
|
|
148
|
+
// });
|
|
149
|
+
// }
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const alignment = computed(() => {
|
|
153
|
+
const isLeftRight =
|
|
154
|
+
state.direction === 'left' || state.direction === 'right';
|
|
155
|
+
let alignment = '';
|
|
156
|
+
if (state.placement) {
|
|
157
|
+
const parts = state.placement.split('-');
|
|
158
|
+
if (parts.length > 1) alignment = parts[1];
|
|
159
|
+
}
|
|
160
|
+
if (['start', 'top', 'left'].includes(alignment)) {
|
|
161
|
+
return isLeftRight ? 'top' : 'left';
|
|
162
|
+
}
|
|
163
|
+
if (['end', 'bottom', 'right'].includes(alignment)) {
|
|
164
|
+
return isLeftRight ? 'bottom' : 'right';
|
|
165
|
+
}
|
|
166
|
+
return isLeftRight ? 'middle' : 'center';
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
function destroyPopper() {
|
|
170
|
+
triggerObserver?.disconnect();
|
|
171
|
+
triggerObserver = null;
|
|
172
|
+
if (popper) {
|
|
173
|
+
popper.destroy();
|
|
174
|
+
popper = null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function setupPopper() {
|
|
179
|
+
nextTick(() => {
|
|
180
|
+
if (isUnmounted) return;
|
|
181
|
+
const el = resolveEl(state.target);
|
|
182
|
+
if (!el || !popoverRef.value) return;
|
|
183
|
+
if (popper && popper.state.elements.reference !== el) {
|
|
184
|
+
destroyPopper();
|
|
185
|
+
}
|
|
186
|
+
if (!popper) {
|
|
187
|
+
popper = createPopper(
|
|
188
|
+
el as Element,
|
|
189
|
+
popoverRef.value,
|
|
190
|
+
popperOptions.value,
|
|
191
|
+
);
|
|
192
|
+
} else {
|
|
193
|
+
popper.update();
|
|
194
|
+
}
|
|
195
|
+
const targetDocument = el.ownerDocument;
|
|
196
|
+
const Observer = targetDocument?.defaultView?.MutationObserver;
|
|
197
|
+
if (Observer && targetDocument && el.isConnected && !triggerObserver) {
|
|
198
|
+
triggerObserver = new Observer(() => {
|
|
199
|
+
if (el.isConnected) return;
|
|
200
|
+
state.force = false;
|
|
201
|
+
state.isVisible = false;
|
|
202
|
+
destroyPopper();
|
|
203
|
+
});
|
|
204
|
+
triggerObserver.observe(targetDocument.documentElement, {
|
|
205
|
+
childList: true,
|
|
206
|
+
subtree: true,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function updateState(newState: Partial<PopoverState>) {
|
|
213
|
+
Object.assign(state, omit(newState, 'force'));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function setTimer(delay: number, fn: Function) {
|
|
217
|
+
clearTimeout(timeout);
|
|
218
|
+
if (delay > 0) {
|
|
219
|
+
timeout = setTimeout(fn, delay);
|
|
220
|
+
} else {
|
|
221
|
+
fn();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function isCurrentTarget(target: unknown) {
|
|
226
|
+
if (!target || !popper) return false;
|
|
227
|
+
const el = resolveEl(target);
|
|
228
|
+
return el === popper.state.elements.reference;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function show(opts: Partial<PopoverOptions> = {}) {
|
|
232
|
+
if (state.force) return;
|
|
233
|
+
if (opts.force) state.force = true;
|
|
234
|
+
|
|
235
|
+
setTimer(opts.showDelay ?? props.showDelay, () => {
|
|
236
|
+
const target = resolveEl(opts.target ?? state.target);
|
|
237
|
+
if (!target) return;
|
|
238
|
+
if (state.isVisible) {
|
|
239
|
+
state.force = false;
|
|
240
|
+
}
|
|
241
|
+
updateState({
|
|
242
|
+
...opts,
|
|
243
|
+
isVisible: true,
|
|
244
|
+
});
|
|
245
|
+
setupPopper();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function hide(opts: Partial<PopoverOptions> = {}) {
|
|
250
|
+
if (opts.target && popper && !isCurrentTarget(opts.target)) return;
|
|
251
|
+
if (!popper && !state.isVisible) return;
|
|
252
|
+
|
|
253
|
+
if (state.force) return;
|
|
254
|
+
if (opts.force) state.force = true;
|
|
255
|
+
|
|
256
|
+
setTimer(opts.hideDelay ?? props.hideDelay, () => {
|
|
257
|
+
if (!state.isVisible) state.force = false;
|
|
258
|
+
state.isVisible = false;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function toggle(opts: Partial<PopoverOptions> = {}) {
|
|
263
|
+
if (opts.target == null) return;
|
|
264
|
+
if (state.isVisible && isCurrentTarget(opts.target)) {
|
|
265
|
+
hide(opts);
|
|
266
|
+
} else {
|
|
267
|
+
show(opts);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function onDocumentClick(e: CustomEvent) {
|
|
272
|
+
if (!popper) return;
|
|
273
|
+
const reference = popper.state.elements.reference;
|
|
274
|
+
if (!popoverRef.value || !reference) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
// Don't hide if target element is contained within popover ref or content
|
|
278
|
+
const target = e.target as Node;
|
|
279
|
+
if (
|
|
280
|
+
elementContains(popoverRef.value, target) ||
|
|
281
|
+
elementContains(reference as Node, target)
|
|
282
|
+
) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
// Hide the popover
|
|
286
|
+
hide({ force: true });
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function onDocumentKeydown(e: KeyboardEvent) {
|
|
290
|
+
if (e.key === 'Esc' || e.key === 'Escape') {
|
|
291
|
+
hide();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function onDocumentShowPopover({ detail }: PopoverEvent) {
|
|
296
|
+
if (!detail.id || detail.id !== props.id) return;
|
|
297
|
+
show(detail);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function onDocumentHidePopover({ detail }: PopoverEvent) {
|
|
301
|
+
if (!detail.id || detail.id !== props.id) return;
|
|
302
|
+
hide(detail);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function onDocumentTogglePopover({ detail }: PopoverEvent) {
|
|
306
|
+
if (!detail.id || detail.id !== props.id) return;
|
|
307
|
+
toggle(detail);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function addEvents(doc: Document) {
|
|
311
|
+
on(doc, 'keydown', onDocumentKeydown);
|
|
312
|
+
on(doc, 'pointerdown', onDocumentClick);
|
|
313
|
+
on(doc, 'show-popover', onDocumentShowPopover);
|
|
314
|
+
on(doc, 'hide-popover', onDocumentHidePopover);
|
|
315
|
+
on(doc, 'toggle-popover', onDocumentTogglePopover);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function removeEvents(doc: Document) {
|
|
319
|
+
off(doc, 'keydown', onDocumentKeydown);
|
|
320
|
+
off(doc, 'pointerdown', onDocumentClick);
|
|
321
|
+
off(doc, 'show-popover', onDocumentShowPopover);
|
|
322
|
+
off(doc, 'hide-popover', onDocumentHidePopover);
|
|
323
|
+
off(doc, 'toggle-popover', onDocumentTogglePopover);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function beforeEnter(el: Element) {
|
|
327
|
+
emit('before-show', el);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function afterEnter(el: Element) {
|
|
331
|
+
state.force = false;
|
|
332
|
+
emit('after-show', el);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function beforeLeave(el: Element) {
|
|
336
|
+
emit('before-hide', el);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function afterLeave(el: Element) {
|
|
340
|
+
state.force = false;
|
|
341
|
+
destroyPopper();
|
|
342
|
+
emit('after-hide', el);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function onClick(e: MouseEvent) {
|
|
346
|
+
e.stopPropagation();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function onMouseOver() {
|
|
350
|
+
state.isHovered = true;
|
|
351
|
+
if (
|
|
352
|
+
state.isInteractive &&
|
|
353
|
+
['hover', 'hover-focus'].includes(state.visibility)
|
|
354
|
+
) {
|
|
355
|
+
show();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function onMouseLeave() {
|
|
360
|
+
state.isHovered = false;
|
|
361
|
+
if (!popper) return;
|
|
362
|
+
const popperRef = popper.state.elements.reference;
|
|
363
|
+
if (
|
|
364
|
+
state.autoHide &&
|
|
365
|
+
!state.isFocused &&
|
|
366
|
+
(!popperRef || popperRef !== ownerDocument?.activeElement) &&
|
|
367
|
+
['hover', 'hover-focus'].includes(state.visibility)
|
|
368
|
+
) {
|
|
369
|
+
hide();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function onFocusIn() {
|
|
374
|
+
state.isFocused = true;
|
|
375
|
+
if (
|
|
376
|
+
state.isInteractive &&
|
|
377
|
+
['focus', 'hover-focus'].includes(state.visibility)
|
|
378
|
+
) {
|
|
379
|
+
show();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function onFocusOut(e: FocusEvent) {
|
|
384
|
+
if (
|
|
385
|
+
['focus', 'hover-focus'].includes(state.visibility) &&
|
|
386
|
+
(!e.relatedTarget ||
|
|
387
|
+
!elementContains(popoverRef.value!, e.relatedTarget as Node))
|
|
388
|
+
) {
|
|
389
|
+
state.isFocused = false;
|
|
390
|
+
if (!state.isHovered && state.autoHide) hide();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function cleanupRO() {
|
|
395
|
+
if (resizeObserver != null) {
|
|
396
|
+
resizeObserver.disconnect();
|
|
397
|
+
resizeObserver = null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
watch(
|
|
402
|
+
() => popoverRef.value,
|
|
403
|
+
val => {
|
|
404
|
+
cleanupRO();
|
|
405
|
+
if (!val) return;
|
|
406
|
+
const Observer = val.ownerDocument.defaultView?.ResizeObserver;
|
|
407
|
+
if (!Observer) return;
|
|
408
|
+
resizeObserver = new Observer(() => {
|
|
409
|
+
if (popper) popper.update();
|
|
410
|
+
});
|
|
411
|
+
resizeObserver.observe(val);
|
|
412
|
+
},
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
watch(() => state.placement, updateDirection, {
|
|
416
|
+
immediate: true,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
onMounted(() => {
|
|
420
|
+
ownerDocument = popoverRef.value?.ownerDocument ?? null;
|
|
421
|
+
if (ownerDocument) addEvents(ownerDocument);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
onUnmounted(() => {
|
|
425
|
+
isUnmounted = true;
|
|
426
|
+
clearTimeout(timeout);
|
|
427
|
+
destroyPopper();
|
|
428
|
+
cleanupRO();
|
|
429
|
+
if (ownerDocument) removeEvents(ownerDocument);
|
|
430
|
+
ownerDocument = null;
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
...toRefs(state),
|
|
435
|
+
popoverRef,
|
|
436
|
+
alignment,
|
|
437
|
+
hide,
|
|
438
|
+
setupPopper,
|
|
439
|
+
beforeEnter,
|
|
440
|
+
afterEnter,
|
|
441
|
+
beforeLeave,
|
|
442
|
+
afterLeave,
|
|
443
|
+
onClick,
|
|
444
|
+
onMouseOver,
|
|
445
|
+
onMouseLeave,
|
|
446
|
+
onFocusIn,
|
|
447
|
+
onFocusOut,
|
|
448
|
+
};
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
</script>
|
|
452
|
+
|
|
453
|
+
<style lang="css">
|
|
454
|
+
.vc-popover-content-wrapper {
|
|
455
|
+
--popover-horizontal-content-offset: 8px;
|
|
456
|
+
--popover-vertical-content-offset: 10px;
|
|
457
|
+
--popover-caret-horizontal-offset: 18px;
|
|
458
|
+
--popover-caret-vertical-offset: 8px;
|
|
459
|
+
|
|
460
|
+
position: absolute;
|
|
461
|
+
display: block;
|
|
462
|
+
outline: none;
|
|
463
|
+
z-index: 10;
|
|
464
|
+
&:not(.is-interactive) {
|
|
465
|
+
pointer-events: none;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.vc-popover-content {
|
|
470
|
+
position: relative;
|
|
471
|
+
color: var(--vc-popover-content-color);
|
|
472
|
+
font-weight: var(--vc-font-medium);
|
|
473
|
+
background-color: var(--vc-popover-content-bg);
|
|
474
|
+
border: 1px solid;
|
|
475
|
+
border-color: var(--vc-popover-content-border);
|
|
476
|
+
border-radius: var(--vc-rounded-lg);
|
|
477
|
+
padding: 4px;
|
|
478
|
+
outline: none;
|
|
479
|
+
z-index: 10;
|
|
480
|
+
box-shadow: var(--vc-shadow-lg);
|
|
481
|
+
&.direction-bottom {
|
|
482
|
+
margin-top: var(--popover-vertical-content-offset);
|
|
483
|
+
}
|
|
484
|
+
&.direction-top {
|
|
485
|
+
margin-bottom: var(--popover-vertical-content-offset);
|
|
486
|
+
}
|
|
487
|
+
&.direction-left {
|
|
488
|
+
margin-right: var(--popover-horizontal-content-offset);
|
|
489
|
+
}
|
|
490
|
+
&.direction-right {
|
|
491
|
+
margin-left: var(--popover-horizontal-content-offset);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.vc-popover-caret {
|
|
496
|
+
content: '';
|
|
497
|
+
position: absolute;
|
|
498
|
+
display: block;
|
|
499
|
+
width: 12px;
|
|
500
|
+
height: 12px;
|
|
501
|
+
border-top: inherit;
|
|
502
|
+
border-left: inherit;
|
|
503
|
+
background-color: inherit;
|
|
504
|
+
z-index: -1;
|
|
505
|
+
&.direction-bottom {
|
|
506
|
+
top: 0;
|
|
507
|
+
&.align-left {
|
|
508
|
+
transform: translateY(-50%) rotate(45deg);
|
|
509
|
+
}
|
|
510
|
+
&.align-center {
|
|
511
|
+
transform: translateX(-50%) translateY(-50%) rotate(45deg);
|
|
512
|
+
}
|
|
513
|
+
&.align-right {
|
|
514
|
+
transform: translateY(-50%) rotate(45deg);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
&.direction-top {
|
|
518
|
+
top: 100%;
|
|
519
|
+
&.align-left {
|
|
520
|
+
transform: translateY(-50%) rotate(-135deg);
|
|
521
|
+
}
|
|
522
|
+
&.align-center {
|
|
523
|
+
transform: translateX(-50%) translateY(-50%) rotate(-135deg);
|
|
524
|
+
}
|
|
525
|
+
&.align-right {
|
|
526
|
+
transform: translateY(-50%) rotate(-135deg);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
&.direction-left {
|
|
530
|
+
left: 100%;
|
|
531
|
+
&.align-top {
|
|
532
|
+
transform: translateX(-50%) rotate(135deg);
|
|
533
|
+
}
|
|
534
|
+
&.align-middle {
|
|
535
|
+
transform: translateY(-50%) translateX(-50%) rotate(135deg);
|
|
536
|
+
}
|
|
537
|
+
&.align-bottom {
|
|
538
|
+
transform: translateX(-50%) rotate(135deg);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
&.direction-right {
|
|
542
|
+
left: 0;
|
|
543
|
+
&.align-top {
|
|
544
|
+
transform: translateX(-50%) rotate(-45deg);
|
|
545
|
+
}
|
|
546
|
+
&.align-middle {
|
|
547
|
+
transform: translateY(-50%) translateX(-50%) rotate(-45deg);
|
|
548
|
+
}
|
|
549
|
+
&.align-bottom {
|
|
550
|
+
transform: translateX(-50%) rotate(-45deg);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
&.align-left {
|
|
554
|
+
left: var(--popover-caret-horizontal-offset);
|
|
555
|
+
}
|
|
556
|
+
&.align-center {
|
|
557
|
+
left: 50%;
|
|
558
|
+
}
|
|
559
|
+
&.align-right {
|
|
560
|
+
right: var(--popover-caret-horizontal-offset);
|
|
561
|
+
}
|
|
562
|
+
&.align-top {
|
|
563
|
+
top: var(--popover-caret-vertical-offset);
|
|
564
|
+
}
|
|
565
|
+
&.align-middle {
|
|
566
|
+
top: 50%;
|
|
567
|
+
}
|
|
568
|
+
&.align-bottom {
|
|
569
|
+
bottom: var(--popover-caret-vertical-offset);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
</style>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- Content row -->
|
|
3
|
+
<div class="vc-day-popover-row">
|
|
4
|
+
<!-- Indicator -->
|
|
5
|
+
<div v-if="indicator" class="vc-day-popover-row-indicator">
|
|
6
|
+
<span :class="indicator.class" />
|
|
7
|
+
</div>
|
|
8
|
+
<!-- Content -->
|
|
9
|
+
<div class="vc-day-popover-row-label">
|
|
10
|
+
<slot>{{
|
|
11
|
+
attribute.popover ? attribute.popover.label : 'No content provided'
|
|
12
|
+
}}</slot>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import { computed } from 'vue';
|
|
19
|
+
import { Attribute } from '../../utils/attribute';
|
|
20
|
+
|
|
21
|
+
const props = defineProps<{
|
|
22
|
+
attribute: Attribute;
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
const indicator = computed(() => {
|
|
26
|
+
const { content, highlight, dot, bar, popover } = props.attribute;
|
|
27
|
+
if (popover && popover.hideIndicator) return null;
|
|
28
|
+
if (content) {
|
|
29
|
+
return {
|
|
30
|
+
class: `vc-bar vc-day-popover-row-bar vc-attr vc-${content.base.color}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (highlight) {
|
|
34
|
+
return {
|
|
35
|
+
class: `vc-highlight-bg-solid vc-day-popover-row-highlight vc-attr vc-${highlight.base.color}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (dot) {
|
|
39
|
+
return {
|
|
40
|
+
class: `vc-dot vc-attr vc-${dot.base.color}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (bar) {
|
|
44
|
+
return {
|
|
45
|
+
class: `vc-bar vc-day-popover-row-bar vc-attr vc-${bar.base.color}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<style lang="css">
|
|
53
|
+
.vc-day-popover-row {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
transition: var(--vc-day-content-transition);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.vc-day-popover-row-indicator {
|
|
60
|
+
display: flex;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
align-items: center;
|
|
63
|
+
flex-grow: 0;
|
|
64
|
+
width: 15px;
|
|
65
|
+
& span {
|
|
66
|
+
transition: var(--vc-day-content-transition);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.vc-day-popover-row-label {
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
flex-wrap: none;
|
|
74
|
+
flex-grow: 1;
|
|
75
|
+
width: max-content;
|
|
76
|
+
margin-left: 4px;
|
|
77
|
+
margin-right: 4px;
|
|
78
|
+
font-size: var(--vc-text-xs);
|
|
79
|
+
line-height: var(--vc-leading-normal);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.vc-day-popover-row-highlight {
|
|
83
|
+
width: 8px;
|
|
84
|
+
height: 5px;
|
|
85
|
+
border-radius: 3px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.vc-day-popover-row-dot {
|
|
89
|
+
}
|
|
90
|
+
.vc-day-popover-row-bar {
|
|
91
|
+
width: 10px;
|
|
92
|
+
height: 3px;
|
|
93
|
+
}
|
|
94
|
+
</style>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import * as components from './components/index';
|
|
3
|
+
import './styles/index.css';
|
|
4
|
+
import { setVueInstance } from './utils/config/index';
|
|
5
|
+
import { type Defaults, setupDefaults } from './utils/defaults';
|
|
6
|
+
|
|
7
|
+
const install = (app: App, defaults: Defaults = {}) => {
|
|
8
|
+
setVueInstance(app);
|
|
9
|
+
app.use(setupDefaults, defaults);
|
|
10
|
+
const prefix = app.config.globalProperties.$VCalendar.componentPrefix;
|
|
11
|
+
for (const componentKey in components) {
|
|
12
|
+
const component = (components as any)[componentKey];
|
|
13
|
+
app.component(`${prefix}${componentKey}`, component);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default { install };
|
|
18
|
+
export * from './components';
|
|
19
|
+
export { setupDefaults as setupCalendar } from './utils/defaults';
|
|
20
|
+
export { popoverDirective } from './utils/popovers';
|
|
21
|
+
export type { PopoverOptions } from './utils/popovers';
|
|
22
|
+
|
|
23
|
+
export { createCalendar, useCalendar } from './use/calendar';
|
|
24
|
+
export { createDatePicker, useDatePicker } from './use/datePicker';
|