@ramathibodi/nuxt-commons 4.0.24 → 4.0.25

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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.3.1"
6
6
  },
7
- "version": "4.0.24",
7
+ "version": "4.0.25",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,7 +1,7 @@
1
1
  import '@fullcalendar/vue3/skeleton.css';
2
2
  import '@fullcalendar/vue3/themes/classic/theme.css';
3
3
  import '@fullcalendar/vue3/themes/classic/palette.css';
4
- import type { CalendarEvent, CalendarRange, CalendarToolbar, CalendarView } from '../types/calendar.js';
4
+ import type { CalendarEvent, CalendarEventChange, CalendarRange, CalendarToolbar, CalendarView } from '../types/calendar.js';
5
5
  interface Props {
6
6
  /** Array mode: redraws whenever the array changes. */
7
7
  events?: CalendarEvent[];
@@ -20,15 +20,24 @@ interface Props {
20
20
  slotMinTime?: string;
21
21
  slotMaxTime?: string;
22
22
  selectable?: boolean;
23
+ /**
24
+ * Lets users drag events to move them and drag their end edge to resize them. Each gesture emits
25
+ * `event-change`; persist it there, or call `revert()` to undo it.
26
+ */
27
+ editable?: boolean;
23
28
  /** Last resort, FullCalendar-specific and unstable: merged over everything else. */
24
29
  options?: Record<string, unknown>;
25
30
  }
26
31
  declare var __VLS_10: {
27
32
  event: CalendarEvent;
28
33
  timeText: any;
34
+ }, __VLS_18: {
35
+ event: CalendarEvent;
29
36
  };
30
37
  type __VLS_Slots = {} & {
31
38
  event?: (props: typeof __VLS_10) => any;
39
+ } & {
40
+ 'event-tooltip'?: (props: typeof __VLS_18) => any;
32
41
  };
33
42
  declare const __VLS_base: import("vue").DefineComponent<Props, {
34
43
  currentView: Readonly<import("vue").Ref<CalendarView, CalendarView>>;
@@ -59,6 +68,7 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
59
68
  date: Date;
60
69
  allDay: boolean;
61
70
  }) => any;
71
+ "event-change": (value: CalendarEventChange) => any;
62
72
  "dates-set": (value: {
63
73
  start: Date;
64
74
  end: Date;
@@ -78,6 +88,7 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
78
88
  date: Date;
79
89
  allDay: boolean;
80
90
  }) => any) | undefined;
91
+ "onEvent-change"?: ((value: CalendarEventChange) => any) | undefined;
81
92
  "onDates-set"?: ((value: {
82
93
  start: Date;
83
94
  end: Date;
@@ -98,6 +109,7 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
98
109
  slotMinTime: string;
99
110
  slotMaxTime: string;
100
111
  selectable: boolean;
112
+ editable: boolean;
101
113
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
102
114
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
103
115
  declare const _default: typeof __VLS_export;
@@ -9,7 +9,8 @@ import thLocale from "@fullcalendar/vue3/locales/th";
9
9
  import "@fullcalendar/vue3/skeleton.css";
10
10
  import "@fullcalendar/vue3/themes/classic/theme.css";
11
11
  import "@fullcalendar/vue3/themes/classic/palette.css";
12
- import { computed, readonly, ref, useSlots, watch } from "vue";
12
+ import { Comment, Fragment, Text, computed, readonly, ref, shallowRef, useSlots, watch } from "vue";
13
+ import { useMediaQuery } from "@vueuse/core";
13
14
  import { fromFcView, toCalendarEvent, toFcEvent, toFcToolbar, toFcView } from "../calendar/mapping";
14
15
  const props = defineProps({
15
16
  events: { type: Array, required: false, default: void 0 },
@@ -23,10 +24,38 @@ const props = defineProps({
23
24
  slotMinTime: { type: String, required: false, default: "07:00" },
24
25
  slotMaxTime: { type: String, required: false, default: "20:00" },
25
26
  selectable: { type: Boolean, required: false, default: false },
27
+ editable: { type: Boolean, required: false, default: false },
26
28
  options: { type: Object, required: false, default: void 0 }
27
29
  });
28
- const emit = defineEmits(["event-click", "date-click", "select", "dates-set", "loading", "update:view", "update:date"]);
30
+ const emit = defineEmits(["event-click", "date-click", "select", "event-change", "dates-set", "loading", "update:view", "update:date"]);
29
31
  const slots = useSlots();
32
+ const canHover = useMediaQuery("(hover: hover)");
33
+ const hovered = shallowRef(null);
34
+ const tooltipOpen = ref(false);
35
+ const interacting = ref(false);
36
+ function isBlank(nodes) {
37
+ return !nodes || nodes.every((node) => node.type === Comment || node.type === Text && !String(node.children ?? "").trim() || node.type === Fragment && isBlank(node.children));
38
+ }
39
+ function onEventHover(info) {
40
+ const tooltipSlot = slots["event-tooltip"];
41
+ if (!tooltipSlot || !canHover.value || interacting.value) return;
42
+ const event = toCalendarEvent(info.event);
43
+ if (isBlank(tooltipSlot({ event }))) return;
44
+ hovered.value = { el: info.el, event };
45
+ tooltipOpen.value = true;
46
+ }
47
+ function setInteracting(value) {
48
+ interacting.value = value;
49
+ tooltipOpen.value = false;
50
+ }
51
+ function emitChange(kind, info) {
52
+ emit("event-change", {
53
+ kind,
54
+ event: toCalendarEvent(info.event),
55
+ oldEvent: toCalendarEvent(info.oldEvent),
56
+ revert: info.revert
57
+ });
58
+ }
30
59
  const fc = ref();
31
60
  const api = () => fc.value?.getApi?.();
32
61
  const currentView = ref(props.view);
@@ -53,12 +82,26 @@ const calendarOptions = computed(() => ({
53
82
  slotMinTime: props.slotMinTime,
54
83
  slotMaxTime: props.slotMaxTime,
55
84
  selectable: props.selectable,
85
+ editable: props.editable,
56
86
  nowIndicator: true,
57
87
  dayMaxEvents: true,
58
88
  events: eventSource.value,
59
- eventClick: (info) => emit("event-click", toCalendarEvent(info.event)),
89
+ eventClick: (info) => {
90
+ tooltipOpen.value = false;
91
+ emit("event-click", toCalendarEvent(info.event));
92
+ },
93
+ eventMouseEnter: onEventHover,
94
+ eventMouseLeave: () => {
95
+ tooltipOpen.value = false;
96
+ },
97
+ eventDragStart: () => setInteracting(true),
98
+ eventDragStop: () => setInteracting(false),
99
+ eventResizeStart: () => setInteracting(true),
100
+ eventResizeStop: () => setInteracting(false),
60
101
  dateClick: (info) => emit("date-click", { date: info.date, allDay: info.allDay }),
61
102
  select: (info) => emit("select", { start: info.start, end: info.end, allDay: info.allDay }),
103
+ eventDrop: (info) => emitChange("move", info),
104
+ eventResize: (info) => emitChange("resize", info),
62
105
  loading: (isLoading) => emit("loading", isLoading),
63
106
  datesSet: (info) => {
64
107
  const view = fromFcView(info.view.type);
@@ -73,6 +116,9 @@ const calendarOptions = computed(() => ({
73
116
  },
74
117
  ...props.options ?? {}
75
118
  }));
119
+ watch(eventSource, () => {
120
+ tooltipOpen.value = false;
121
+ });
76
122
  watch(() => props.view, (view) => {
77
123
  if (view && view !== currentView.value) api()?.changeView(toFcView(view));
78
124
  });
@@ -98,19 +144,34 @@ defineExpose({
98
144
  </script>
99
145
 
100
146
  <template>
101
- <FullCalendar
102
- ref="fc"
103
- :options="calendarOptions"
104
- >
105
- <template
106
- v-if="slots.event"
107
- #eventContent="arg"
147
+ <div class="calendar">
148
+ <FullCalendar
149
+ ref="fc"
150
+ :options="calendarOptions"
151
+ >
152
+ <template
153
+ v-if="slots.event"
154
+ #eventContent="arg"
155
+ >
156
+ <slot
157
+ name="event"
158
+ :event="toCalendarEvent(arg.event)"
159
+ :time-text="arg.timeText"
160
+ />
161
+ </template>
162
+ </FullCalendar>
163
+ <v-tooltip
164
+ v-if="slots['event-tooltip']"
165
+ :model-value="tooltipOpen"
166
+ :activator="hovered?.el"
167
+ location="top"
168
+ max-width="360"
108
169
  >
109
170
  <slot
110
- name="event"
111
- :event="toCalendarEvent(arg.event)"
112
- :time-text="arg.timeText"
171
+ v-if="hovered"
172
+ name="event-tooltip"
173
+ :event="hovered.event"
113
174
  />
114
- </template>
115
- </FullCalendar>
175
+ </v-tooltip>
176
+ </div>
116
177
  </template>
@@ -1,7 +1,7 @@
1
1
  import '@fullcalendar/vue3/skeleton.css';
2
2
  import '@fullcalendar/vue3/themes/classic/theme.css';
3
3
  import '@fullcalendar/vue3/themes/classic/palette.css';
4
- import type { CalendarEvent, CalendarRange, CalendarToolbar, CalendarView } from '../types/calendar.js';
4
+ import type { CalendarEvent, CalendarEventChange, CalendarRange, CalendarToolbar, CalendarView } from '../types/calendar.js';
5
5
  interface Props {
6
6
  /** Array mode: redraws whenever the array changes. */
7
7
  events?: CalendarEvent[];
@@ -20,15 +20,24 @@ interface Props {
20
20
  slotMinTime?: string;
21
21
  slotMaxTime?: string;
22
22
  selectable?: boolean;
23
+ /**
24
+ * Lets users drag events to move them and drag their end edge to resize them. Each gesture emits
25
+ * `event-change`; persist it there, or call `revert()` to undo it.
26
+ */
27
+ editable?: boolean;
23
28
  /** Last resort, FullCalendar-specific and unstable: merged over everything else. */
24
29
  options?: Record<string, unknown>;
25
30
  }
26
31
  declare var __VLS_10: {
27
32
  event: CalendarEvent;
28
33
  timeText: any;
34
+ }, __VLS_18: {
35
+ event: CalendarEvent;
29
36
  };
30
37
  type __VLS_Slots = {} & {
31
38
  event?: (props: typeof __VLS_10) => any;
39
+ } & {
40
+ 'event-tooltip'?: (props: typeof __VLS_18) => any;
32
41
  };
33
42
  declare const __VLS_base: import("vue").DefineComponent<Props, {
34
43
  currentView: Readonly<import("vue").Ref<CalendarView, CalendarView>>;
@@ -59,6 +68,7 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
59
68
  date: Date;
60
69
  allDay: boolean;
61
70
  }) => any;
71
+ "event-change": (value: CalendarEventChange) => any;
62
72
  "dates-set": (value: {
63
73
  start: Date;
64
74
  end: Date;
@@ -78,6 +88,7 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
78
88
  date: Date;
79
89
  allDay: boolean;
80
90
  }) => any) | undefined;
91
+ "onEvent-change"?: ((value: CalendarEventChange) => any) | undefined;
81
92
  "onDates-set"?: ((value: {
82
93
  start: Date;
83
94
  end: Date;
@@ -98,6 +109,7 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
98
109
  slotMinTime: string;
99
110
  slotMaxTime: string;
100
111
  selectable: boolean;
112
+ editable: boolean;
101
113
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
102
114
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
103
115
  declare const _default: typeof __VLS_export;
@@ -52,8 +52,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
52
52
  readonly: boolean;
53
53
  saveCaption: string;
54
54
  cancelCaption: string;
55
- closeCaption: string;
56
55
  saveAndStay: boolean;
56
+ closeCaption: string;
57
57
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
58
58
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
59
59
  declare const _default: typeof __VLS_export;
@@ -52,8 +52,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
52
52
  readonly: boolean;
53
53
  saveCaption: string;
54
54
  cancelCaption: string;
55
- closeCaption: string;
56
55
  saveAndStay: boolean;
56
+ closeCaption: string;
57
57
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
58
58
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
59
59
  declare const _default: typeof __VLS_export;
@@ -16,6 +16,17 @@ export interface CalendarEvent {
16
16
  extendedProps?: Record<string, any> | null
17
17
  }
18
18
 
19
+ /** A drag (`move`) or edge-drag (`resize`) the user finished on an editable calendar. */
20
+ export interface CalendarEventChange {
21
+ kind: 'move' | 'resize'
22
+ /** The event with its new start/end. */
23
+ event: CalendarEvent
24
+ /** The event as it was before the gesture. */
25
+ oldEvent: CalendarEvent
26
+ /** Puts the event back where it was, e.g. when saving the change fails. */
27
+ revert: () => void
28
+ }
29
+
19
30
  export interface CalendarRange { start: Date, end: Date }
20
31
 
21
32
  export interface CalendarToolbar {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "4.0.24",
3
+ "version": "4.0.25",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",