pimelon-ui 0.1.89 → 0.1.91

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pimelon-ui",
3
- "version": "0.1.89",
3
+ "version": "0.1.91",
4
4
  "description": "A set of components and utilities for rapid UI development",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -47,10 +47,10 @@
47
47
  "@tiptap/suggestion": "^2.0.3",
48
48
  "@tiptap/vue-3": "^2.0.3",
49
49
  "@vueuse/core": "^10.4.1",
50
+ "dayjs": "^1.11.13",
50
51
  "feather-icons": "^4.28.0",
51
52
  "husky": "^9.1.7",
52
53
  "idb-keyval": "^6.2.0",
53
- "luxon": "^3.5.0",
54
54
  "prettier": "^3.3.2",
55
55
  "radix-vue": "^1.5.3",
56
56
  "showdown": "^2.1.0",
@@ -126,16 +126,17 @@
126
126
  <script setup lang="ts">
127
127
  import { computed, onMounted } from 'vue'
128
128
 
129
- import Input from './Input.vue'
130
- import { Button } from './Button'
131
- import Popover from './Popover.vue'
132
- import FeatherIcon from './FeatherIcon.vue'
133
- import TextInput from './TextInput.vue'
129
+ import Input from '../Input.vue'
130
+ import { Button } from '../Button'
131
+ import Popover from '../Popover.vue'
132
+ import FeatherIcon from '../FeatherIcon.vue'
133
+ import TextInput from '../TextInput.vue'
134
134
 
135
- import { getDate, getDateValue, luxonDate } from '../utils/dates'
136
- import { useDatePicker } from '../utils/useDatePicker'
135
+ import { getDate, getDateValue } from './utils'
136
+ import { useDatePicker } from './useDatePicker'
137
+ import { dayjsLocal } from '../../utils/dayjs'
137
138
 
138
- import type { DatePickerEmits, DatePickerProps } from './types/DatePicker'
139
+ import type { DatePickerEmits, DatePickerProps } from './DatePicker'
139
140
 
140
141
  const props = defineProps<DatePickerProps>()
141
142
  const emit = defineEmits<DatePickerEmits>()
@@ -167,9 +168,7 @@ const dateValue = computed(() => {
167
168
  })
168
169
 
169
170
  function selectDate(date: Date | string, isNow: boolean = false) {
170
- if (isNow && window.timezone?.user) {
171
- date = luxonDate(date).setZone(window.timezone.user)
172
- }
171
+ date = isNow ? dayjsLocal(date) : date
173
172
  emit('change', getDateValue(date))
174
173
  emit('update:modelValue', getDateValue(date))
175
174
  }
@@ -122,16 +122,16 @@
122
122
  <script setup lang="ts">
123
123
  import { computed, ref, onMounted } from 'vue'
124
124
 
125
- import Input from './Input.vue'
126
- import { Button } from './Button'
127
- import Popover from './Popover.vue'
128
- import FeatherIcon from './FeatherIcon.vue'
129
- import TextInput from './TextInput.vue'
125
+ import Input from '../Input.vue'
126
+ import { Button } from '../Button'
127
+ import Popover from '../Popover.vue'
128
+ import FeatherIcon from '../FeatherIcon.vue'
129
+ import TextInput from '../TextInput.vue'
130
130
 
131
- import { getDate, getDateValue } from '../utils/dates'
132
- import { useDatePicker } from '../utils/useDatePicker'
131
+ import { getDate, getDateValue } from './utils'
132
+ import { useDatePicker } from './useDatePicker'
133
133
 
134
- import type { DatePickerEmits, DatePickerProps } from './types/DatePicker'
134
+ import type { DatePickerEmits, DatePickerProps } from './DatePicker'
135
135
 
136
136
  const props = defineProps<DatePickerProps>()
137
137
  const emit = defineEmits<DatePickerEmits>()
@@ -62,7 +62,7 @@
62
62
  class="text-sm"
63
63
  @click="
64
64
  () => {
65
- selectDate(getDate(), false, true)
65
+ selectDate(getDate(), true)
66
66
  togglePopover()
67
67
  }
68
68
  "
@@ -189,21 +189,17 @@
189
189
  <script setup lang="ts">
190
190
  import { ref, computed, onMounted } from 'vue'
191
191
 
192
- import Input from './Input.vue'
193
- import { Button } from './Button'
194
- import Popover from './Popover.vue'
195
- import FeatherIcon from './FeatherIcon.vue'
196
- import TextInput from './TextInput.vue'
192
+ import Input from '../Input.vue'
193
+ import { Button } from '../Button'
194
+ import Popover from '../Popover.vue'
195
+ import FeatherIcon from '../FeatherIcon.vue'
196
+ import TextInput from '../TextInput.vue'
197
197
 
198
- import {
199
- getDate,
200
- convertToUserTimezone,
201
- convertToSystemTimezone,
202
- luxonDate,
203
- } from '../utils/dates'
204
- import { useDatePicker } from '../utils/useDatePicker'
198
+ import { getDate } from './utils'
199
+ import { useDatePicker } from './useDatePicker'
200
+ import { dayjs, dayjsLocal, dayjsSystem } from '../../utils/dayjs'
205
201
 
206
- import type { DatePickerEmits, DatePickerProps } from './types/DatePicker'
202
+ import type { DatePickerEmits, DatePickerProps } from './DatePicker'
207
203
 
208
204
  const props = defineProps<DatePickerProps>()
209
205
  const emit = defineEmits<DatePickerEmits>()
@@ -236,55 +232,38 @@ const second = ref<number>(0)
236
232
 
237
233
  const dateValue = computed(() => {
238
234
  let date = props.value ? props.value : props.modelValue
239
- return date ? convertToUserTimezone(date) : ''
235
+ return date ? dayjsLocal(date).format('YYYY-MM-DD HH:mm:ss') : ''
240
236
  })
241
237
 
242
238
  function changeTime() {
243
239
  let date = dateValue.value ? getDate(dateValue.value) : getDate()
244
- selectDate(date, true)
240
+ selectDate(date)
245
241
  }
246
242
 
247
- function selectDate(
248
- date: Date | string,
249
- isTimeChange: boolean = false,
250
- isNow: boolean = false,
251
- ) {
252
- if (!isTimeChange) {
253
- let currentDate = luxonDate()
254
- if (dateValue.value && !isNow) {
255
- currentDate = luxonDate(dateValue.value)
256
- } else if (isNow && window.timezone?.user) {
257
- currentDate = currentDate.setZone(window.timezone.user)
258
- // set only date part of currentDate to date
259
- date = luxonDate(date)
260
- .set({
261
- year: currentDate.year,
262
- month: currentDate.month,
263
- day: currentDate.day,
264
- })
265
- .toJSDate()
266
- }
267
-
268
- hour.value = currentDate.hour
269
- minute.value = currentDate.minute
270
- second.value = currentDate.second
243
+ function selectDate(date: Date | string, isNow: boolean = false) {
244
+ if (isNow) {
245
+ date = dayjsLocal(date)
246
+ hour.value = date.hour()
247
+ minute.value = date.minute()
248
+ second.value = date.second()
271
249
  }
272
250
 
273
- emit('change', convertToSystemTimezone(toValue(date)))
274
- emit('update:modelValue', convertToSystemTimezone(toValue(date)))
251
+ let systemParsedDate = date
252
+ ? dayjsSystem(toValue(date)).format('YYYY-MM-DD HH:mm:ss')
253
+ : ''
254
+ emit('change', systemParsedDate)
255
+ emit('update:modelValue', systemParsedDate)
275
256
  }
276
257
 
277
258
  function toValue(date: Date | string) {
278
259
  if (!date || date.toString() === 'Invalid Date') return ''
279
260
 
280
- // "YYYY-MM-DD HH:MM:SS"
281
- return luxonDate(date)
282
- .set({
283
- hours: hour.value,
284
- minutes: minute.value,
285
- seconds: second.value,
286
- })
287
- .toFormat('yyyy-MM-dd HH:mm:ss')
261
+ // "YYYY-MM-DD HH:mm:ss"
262
+ return dayjs(date)
263
+ .set('hour', hour.value)
264
+ .set('minute', minute.value)
265
+ .set('second', second.value)
266
+ .format('YYYY-MM-DD HH:mm:ss')
288
267
  }
289
268
 
290
269
  function twoDigit(number: number) {
@@ -296,7 +275,7 @@ function updateDate(date: Date | string) {
296
275
  hour.value = date.getHours()
297
276
  minute.value = date.getMinutes()
298
277
  second.value = date.getSeconds()
299
- selectDate(date, true)
278
+ selectDate(date)
300
279
  }
301
280
 
302
281
  function selectCurrentMonthYear() {
@@ -1,5 +1,5 @@
1
1
  import { computed, ref } from 'vue'
2
- import { getDate, getDatesAfter, getDaysInMonth } from './dates'
2
+ import { getDate, getDatesAfter, getDaysInMonth } from './utils'
3
3
 
4
4
  export function useDatePicker() {
5
5
  const currentYear = ref<number>(0)
@@ -0,0 +1,60 @@
1
+ import { dayjs } from '../../utils/dayjs'
2
+
3
+ type DateConstructorParam = string | number | Date
4
+
5
+ function getDate(...args: DateConstructorParam[]): Date {
6
+ return new Date(...(args as [DateConstructorParam]))
7
+ }
8
+
9
+ function getDateValue(date: Date | string) {
10
+ if (!date || date.toString() === 'Invalid Date') return ''
11
+
12
+ return dayjs(date)
13
+ .set('hour', 0)
14
+ .set('minute', 0)
15
+ .set('second', 0)
16
+ .set('millisecond', 0)
17
+ .format('YYYY-MM-DD')
18
+ }
19
+
20
+ function getDatesAfter(date: Date, count: number) {
21
+ let incrementer = 1
22
+ if (count < 0) {
23
+ incrementer = -1
24
+ count = Math.abs(count)
25
+ }
26
+ const dates: Date[] = []
27
+
28
+ while (count) {
29
+ date = getDate(
30
+ date.getFullYear(),
31
+ date.getMonth(),
32
+ date.getDate() + incrementer,
33
+ )
34
+ dates.push(date)
35
+ count--
36
+ }
37
+
38
+ if (incrementer === -1) {
39
+ return dates.reverse()
40
+ }
41
+ return dates
42
+ }
43
+
44
+ function getDaysInMonth(monthIndex: number, year: number) {
45
+ const daysInMonthMap = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
46
+ const daysInMonth = daysInMonthMap[monthIndex]
47
+ if (monthIndex === 1 && isLeapYear(year)) {
48
+ return 29
49
+ }
50
+ return daysInMonth
51
+ }
52
+
53
+ function isLeapYear(year: number) {
54
+ if (year % 400 === 0) return true
55
+ if (year % 100 === 0) return false
56
+ if (year % 4 === 0) return true
57
+ return false
58
+ }
59
+
60
+ export { getDate, getDateValue, getDatesAfter, getDaysInMonth, isLeapYear }
package/src/index.js CHANGED
@@ -7,9 +7,9 @@ export { default as Breadcrumbs } from './components/Breadcrumbs.vue'
7
7
  export * from './components/Button'
8
8
  export { default as Card } from './components/Card.vue'
9
9
  export { default as Checkbox } from './components/Checkbox.vue'
10
- export { default as DatePicker } from './components/DatePicker.vue'
11
- export { default as DateTimePicker } from './components/DateTimePicker.vue'
12
- export { default as DateRangePicker } from './components/DateRangePicker.vue'
10
+ export { default as DatePicker } from './components/DatePicker/DatePicker.vue'
11
+ export { default as DateTimePicker } from './components/DatePicker/DateTimePicker.vue'
12
+ export { default as DateRangePicker } from './components/DatePicker/DateRangePicker.vue'
13
13
  export { default as Dialog } from './components/Dialog.vue'
14
14
  export { default as Dialogs } from './components/Dialogs.vue'
15
15
  export { default as Divider } from './components/Divider.vue'
@@ -79,7 +79,7 @@ export { default as debounce } from './utils/debounce.ts'
79
79
  export { default as fileToBase64 } from './utils/file-to-base64.js'
80
80
  export { default as FileUploadHandler } from './utils/fileUploadHandler.ts'
81
81
  export { usePageMeta } from './utils/pageMeta.js'
82
- export * from './utils/dates.ts'
82
+ export { dayjsLocal, dayjs } from './utils/dayjs.js'
83
83
 
84
84
  // data-fetching, resources
85
85
  export {
@@ -0,0 +1,45 @@
1
+ import _dayjs from 'dayjs/esm'
2
+ import relativeTime from 'dayjs/esm/plugin/relativeTime'
3
+ import localizedFormat from 'dayjs/esm/plugin/localizedFormat'
4
+ import updateLocale from 'dayjs/esm/plugin/updateLocale'
5
+ import isToday from 'dayjs/esm/plugin/isToday'
6
+ import duration from 'dayjs/esm/plugin/duration'
7
+ import utc from 'dayjs/esm/plugin/utc'
8
+ import timezone from 'dayjs/esm/plugin/timezone'
9
+ import advancedFormat from 'dayjs/esm/plugin/advancedFormat'
10
+ import { getConfig } from './config'
11
+
12
+ _dayjs.extend(updateLocale)
13
+ _dayjs.extend(relativeTime)
14
+ _dayjs.extend(localizedFormat)
15
+ _dayjs.extend(isToday)
16
+ _dayjs.extend(duration)
17
+ _dayjs.extend(utc)
18
+ _dayjs.extend(timezone)
19
+ _dayjs.extend(advancedFormat)
20
+
21
+ function getBrowserTimezone() {
22
+ return Intl.DateTimeFormat().resolvedOptions().timeZone
23
+ }
24
+
25
+ export function dayjsLocal(dateTimeString) {
26
+ let systemTimezone = getConfig('systemTimezone')
27
+ let localTimezone = getConfig('localTimezone') || getBrowserTimezone()
28
+
29
+ if (!systemTimezone) return _dayjs(dateTimeString)
30
+
31
+ if (!dateTimeString) return _dayjs().tz(localTimezone)
32
+ return _dayjs.tz(dateTimeString, systemTimezone).tz(localTimezone)
33
+ }
34
+
35
+ export function dayjsSystem(dateTimeString) {
36
+ let systemTimezone = getConfig('systemTimezone')
37
+ let localTimezone = getConfig('localTimezone') || getBrowserTimezone()
38
+
39
+ if (!systemTimezone) return _dayjs(dateTimeString)
40
+
41
+ if (!dateTimeString) return _dayjs().tz(systemTimezone)
42
+ return _dayjs.tz(dateTimeString, localTimezone).tz(systemTimezone)
43
+ }
44
+
45
+ export let dayjs = _dayjs
@@ -1,126 +0,0 @@
1
- import { DateTime } from 'luxon'
2
-
3
- declare global {
4
- interface Window {
5
- timezone?: {
6
- system?: string
7
- user?: string
8
- }
9
- }
10
- }
11
-
12
- type DateConstructorParam = string | number | Date
13
-
14
- function getDate(...args: DateConstructorParam[]): Date {
15
- return new Date(...(args as [DateConstructorParam]))
16
- }
17
-
18
- function getDateValue(date: Date | string) {
19
- if (!date || date.toString() === 'Invalid Date') return ''
20
-
21
- return luxonDate(date)
22
- .set({ hours: 0, minutes: 0, seconds: 0, milliseconds: 0 })
23
- .toFormat('yyyy-MM-dd')
24
- }
25
-
26
- function getDatesAfter(date: Date, count: number) {
27
- let incrementer = 1
28
- if (count < 0) {
29
- incrementer = -1
30
- count = Math.abs(count)
31
- }
32
- const dates: Date[] = []
33
-
34
- while (count) {
35
- date = getDate(
36
- date.getFullYear(),
37
- date.getMonth(),
38
- date.getDate() + incrementer,
39
- )
40
- dates.push(date)
41
- count--
42
- }
43
-
44
- if (incrementer === -1) {
45
- return dates.reverse()
46
- }
47
- return dates
48
- }
49
-
50
- function getDaysInMonth(monthIndex: number, year: number) {
51
- const daysInMonthMap = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
52
- const daysInMonth = daysInMonthMap[monthIndex]
53
- if (monthIndex === 1 && isLeapYear(year)) {
54
- return 29
55
- }
56
- return daysInMonth
57
- }
58
-
59
- function isLeapYear(year: number) {
60
- if (year % 400 === 0) return true
61
- if (year % 100 === 0) return false
62
- if (year % 4 === 0) return true
63
- return false
64
- }
65
-
66
- function convertToUserTimezone(date: string, format = 'yyyy-MM-dd HH:mm:ss') {
67
- if (!date) return ''
68
-
69
- const systemTimeZone = window.timezone?.system || null
70
- const userTimeZone = window.timezone?.user || null
71
- const isTimezoneEnabled = systemTimeZone && userTimeZone
72
-
73
- if (!isTimezoneEnabled) return formatDate(date, format)
74
-
75
- // Convert the date from system to the user's time zone
76
- let systemTimezoneDate = luxonDate(date).setZone(systemTimeZone, {
77
- keepLocalTime: true,
78
- })
79
- let userTimezoneDate = systemTimezoneDate.setZone(userTimeZone)
80
-
81
- return userTimezoneDate.toFormat(format)
82
- }
83
-
84
- function convertToSystemTimezone(date: string, format = 'yyyy-MM-dd HH:mm:ss') {
85
- if (!date) return ''
86
-
87
- const systemTimeZone = window.timezone?.system || null
88
- const userTimeZone = window.timezone?.user || null
89
- const isTimezoneEnabled = systemTimeZone && userTimeZone
90
-
91
- if (!isTimezoneEnabled) return formatDate(date, format)
92
- // Convert the date from user's to the system time zone
93
- let userTimezoneDate = luxonDate(date).setZone(userTimeZone, {
94
- keepLocalTime: true,
95
- })
96
- let systemTimezoneDate = userTimezoneDate.setZone(systemTimeZone)
97
-
98
- return systemTimezoneDate.toFormat(format)
99
- }
100
-
101
- function formatDate(date: string | Date, format: string) {
102
- return luxonDate(date).toFormat(format)
103
- }
104
-
105
- function luxonDate(date: string | Date | DateTime | null = null) {
106
- if (!date) return DateTime.local()
107
- if (typeof date === 'string') {
108
- date = new Date(date)
109
- } else if (date.isLuxonDateTime) {
110
- return date
111
- }
112
- return DateTime.fromJSDate(date)
113
- }
114
-
115
- export {
116
- getDate,
117
- getDateValue,
118
- getDatesAfter,
119
- getDaysInMonth,
120
- isLeapYear,
121
- convertToUserTimezone,
122
- convertToSystemTimezone,
123
- formatDate,
124
- luxonDate,
125
- DateTime,
126
- }