@bagelink/vue 1.2.25 → 1.2.39

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.
@@ -1,7 +1,8 @@
1
1
  <script setup lang="ts">
2
+ import type { SetupContext } from 'vue'
2
3
  import type { CalendarEvent, WeekStart } from '../CalendarTypes'
3
4
  import type { PopoverState } from '../utils'
4
- import { Card, formatDate } from '@bagelink/vue'
5
+ import { Card, fmtDate } from '@bagelink/vue'
5
6
  import { ref, computed, onMounted, onUnmounted, useSlots } from 'vue'
6
7
  import {
7
8
  openPopover as openPopoverUtil,
@@ -32,7 +33,7 @@ const emit = defineEmits<{
32
33
  (e: 'eventCreate', event: { start_time: Date, end_time: Date }): void
33
34
  }>()
34
35
 
35
- const slots = useSlots()
36
+ const slots: SetupContext['slots'] = useSlots()
36
37
 
37
38
  // Configuration constants
38
39
  const slotHeight = 60
@@ -128,7 +129,7 @@ const processedEvents = computed(() => {
128
129
  top,
129
130
  height,
130
131
  left: 0,
131
- width: 95,
132
+ width: 100,
132
133
  overlappingEvents: 0,
133
134
  position: 0
134
135
  }
@@ -274,7 +275,7 @@ onUnmounted(() => {
274
275
  v-for="day in weekDays" :key="day.toISOString()"
275
276
  class="day-header p-05 txt-center"
276
277
  >
277
- {{ formatDate(day, 'DDD') }}
278
+ {{ fmtDate(day, { fmt: 'DDD' }) }}
278
279
  <span
279
280
  class="txt-12 round p-025"
280
281
  :class="{
@@ -282,7 +283,7 @@ onUnmounted(() => {
282
283
  'bg-primary color-white': day.toDateString() === new Date().toDateString(),
283
284
  }"
284
285
  >
285
- {{ formatDate(day, 'DD') }}
286
+ {{ fmtDate(day, { fmt: 'DD' }) }}
286
287
  </span>
287
288
  </div>
288
289
  </div>
@@ -316,12 +317,12 @@ onUnmounted(() => {
316
317
  }"
317
318
  @click.stop="slots.eventContent ? openPopover(event, $event) : emit('eventClick', event)"
318
319
  >
319
- <div class="overflow-hidden color-text-light p-025 txt12 h-100p">
320
+ <div class="overflow-hidden color-white p-025 txt12 h-100p">
320
321
  <div class="white-space ellipsis-1">
321
322
  {{ event.title }}
322
323
  </div>
323
324
  <div class="txt10 opacity-8">
324
- {{ formatDate(event.start_time, 'HH:mm') }}
325
+ {{ fmtDate(event.start_time, { fmt: 'HH:mm' }) }}
325
326
  </div>
326
327
  </div>
327
328
  </div>
@@ -348,11 +349,11 @@ onUnmounted(() => {
348
349
  ref="popoverRef"
349
350
  v-click-outside="closePopover"
350
351
  thin
351
- class="custom-popover fixed z-999 radius-05 bg-white w350"
352
+ class="custom-popover fixed z-999 radius-1 bg-white "
352
353
  :style="{
353
354
  top: `${popoverPosition.top}px`,
354
355
  left: `${popoverPosition.left}px`,
355
- maxWidth: `${popoverPosition.width}px`,
356
+
356
357
  }"
357
358
  >
358
359
  <slot name="eventContent" :event="activeEvent" />
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import type { ModeType } from '../../../utils/calendar/typings'
3
- import { TextInput, Dropdown, formatDate } from '@bagelink/vue'
3
+ import { TextInput, Dropdown, fmtDate } from '@bagelink/vue'
4
4
  import { onClickOutside } from '@vueuse/core'
5
5
  import { ref, onMounted } from 'vue'
6
6
  import { WEEK_START_DAY } from '../../../utils/calendar/time'
@@ -47,7 +47,7 @@ const isOpen = ref(false)
47
47
  function useFormatting() {
48
48
  const formatDisplayDate = (date: Date | string | undefined): string => {
49
49
  if (!date) return ''
50
- return formatDate(date, props.enableTime ? 'DD.MM.YY HH:mm' : 'DD.MM.YY')
50
+ return fmtDate(date, { fmt: props.enableTime ? 'DD.MM.YY HH:mm' : 'DD.MM.YY' })
51
51
  }
52
52
 
53
53
  const parseUserInput = (input: string): Date | null => {
@@ -150,7 +150,7 @@ onMounted(() => {
150
150
  <template>
151
151
  <div class="bagel-input" :class="{ small }" :title="label" @focusin="handleFocus">
152
152
  <label v-if="label">
153
- {{ label }}
153
+ <!-- {{ label }} -->
154
154
  <span v-if="required" class="required">*</span>
155
155
  </label>
156
156
  <Dropdown
@@ -163,7 +163,7 @@ onMounted(() => {
163
163
  <div ref="datePickerRef" class="date-picker-container" @mousedown.stop @click.stop>
164
164
  <TextInput
165
165
  :modelValue="formatDisplayDate(selectedDate)"
166
- icon="calendar"
166
+ iconStart="calendar"
167
167
  :min="formatDisplayDate(min)"
168
168
  :max="formatDisplayDate(max)"
169
169
  :required="required"
@@ -196,8 +196,17 @@ onMounted(() => {
196
196
  </div>
197
197
  </template>
198
198
 
199
- <style scoped>
199
+ <style>
200
200
  .date-picker-container {
201
201
  width: 100%;
202
202
  }
203
+ .date-picker-container .date-input{
204
+ --input-bg: transparent;
205
+ --input-font-size: 12px;
206
+ opacity: 0.6;
207
+ --input-height: 20px;
208
+ }
209
+ .date-picker-container .date-input .bagel-input input{
210
+ padding: 0 !important;
211
+ }
203
212
  </style>
@@ -1,3 +1,4 @@
1
+ import type { DateLike } from '@vueuse/core'
1
2
  import type { AvailableTimeLanguages, DateTimeAcceptedFormats, LanguageTranslations, TimeUnit } from '../../types/timeAgoT'
2
3
 
3
4
  interface TimeDeltaOptions {
@@ -157,9 +158,9 @@ function getBrowserNavigatorLocale(): string {
157
158
  * @param timeZone The timezone to use (e.g., 'UTC', 'America/New_York')
158
159
  * @returns Date parts with timezone adjustment applied
159
160
  */
160
- export function handleTimezone(date: Date, timeZone: string): Date {
161
+ export function handleTimezone(date: Date, locale: Intl.LocalesArgument, intFmtOpt: Intl.DateTimeFormatOptions): Date {
161
162
  // If timeZone is UTC, convert to UTC directly
162
- if (timeZone === 'UTC') {
163
+ if (intFmtOpt.timeZone === 'UTC') {
163
164
  const utcDate = new Date(date.getTime())
164
165
  utcDate.setMinutes(utcDate.getMinutes() + date.getTimezoneOffset())
165
166
  return utcDate
@@ -168,16 +169,7 @@ export function handleTimezone(date: Date, timeZone: string): Date {
168
169
  // For other timezones, use the Intl API
169
170
  try {
170
171
  // Get the target timezone's offset at this specific date
171
- const formatter = new Intl.DateTimeFormat('en-US', {
172
- timeZone,
173
- timeZoneName: 'short',
174
- year: 'numeric',
175
- month: 'numeric',
176
- day: 'numeric',
177
- hour: 'numeric',
178
- minute: 'numeric',
179
- second: 'numeric',
180
- })
172
+ const formatter = new Intl.DateTimeFormat(locale, intFmtOpt)
181
173
 
182
174
  // Format the date in the target timezone
183
175
  const formattedParts = formatter.formatToParts(date)
@@ -202,14 +194,15 @@ export function handleTimezone(date: Date, timeZone: string): Date {
202
194
 
203
195
  return adjustedDate
204
196
  } catch (error) {
205
- console.warn(`Error handling timezone ${timeZone}:`, error)
197
+ console.warn(`Error handling timezone ${intFmtOpt.timeZone}:`, error)
206
198
  return date // Return original date on error
207
199
  }
208
200
  }
209
201
 
210
- export function getDatePartsMap(date: Date, locale: Intl.LocalesArgument, timeZone?: string) {
202
+ export function getDatePartsMap(date: Date, locale: Intl.LocalesArgument, intFmtOpt?: Intl.DateTimeFormatOptions) {
211
203
  // Apply timezone adjustment if specified
212
- const d = timeZone ? handleTimezone(date, timeZone) : date
204
+ const d = intFmtOpt?.timeZone ? handleTimezone(date, locale, intFmtOpt) : date
205
+ // const d = date
213
206
 
214
207
  /// keep-sorted
215
208
  return {
@@ -241,36 +234,33 @@ const _orderedDateTokens = (
241
234
  // ? no longer creating the Regex Objs it in a loop
242
235
  const _tokenRegExPattern = new RegExp(_orderedDateTokens.map(token => token).join('|'), 'g')
243
236
 
244
- export type FormatDateFn = (
245
- date?: string | Date,
246
- format?: DateTimeAcceptedFormats,
247
- locale?: string,
248
- timeZone?: string
249
- ) => string
250
-
251
- export type FormatDateFnParams = Parameters<FormatDateFn>
252
- export type FormatDateFnReturn = ReturnType<FormatDateFn>
253
-
254
- export interface FormatDateOptions {
255
- date?: FormatDateFnParams[0]
256
- format?: FormatDateFnParams[1]
257
- locale?: FormatDateFnParams[2]
258
- timeZone?: FormatDateFnParams[3]
237
+ export interface FormatDateOptions extends Partial<Pick<Intl.DateTimeFormatOptions, 'hour12'>> {
238
+ fmt?: DateTimeAcceptedFormats
239
+ locale?: Intl.LocalesArgument
240
+ tz?: string
259
241
  }
242
+ /**
243
+ * Formats a date based on the provided format string, locale, and timezone.
244
+ * @param date The date to format (string or Date object).
245
+ * @param opts Options for formatting the date.
246
+ * @param opts.fmt The format string (default is 'DD.MM.YY').
247
+ * @param opts.locale The locale to use for formatting (default is browser's locale).
248
+ * @param opts.tz The timezone to use for formatting (default is local timezone).
249
+ * @returns Formatted date string.
250
+ */
251
+ export function formatDate(
252
+ date?: DateLike,
253
+ opts: FormatDateOptions = {},
254
+ ): string {
255
+ let { fmt: format, locale, tz: timeZone, ...rest } = opts
260
256
 
261
- export const formatDate: FormatDateFn = (
262
- date,
263
- format,
264
- locale,
265
- timeZone,
266
- ) => {
267
257
  if (!date) return ''
268
258
  format = format || 'DD.MM.YY'
269
259
 
270
260
  locale = locale || getBrowserNavigatorLocale()
271
261
  try {
272
262
  // Validate the date
273
- const d = typeof date === 'string' ? new Date(date) : date
263
+ const d = typeof date === 'string' || typeof date === 'number' ? new Date(date) : date
274
264
 
275
265
  // Check if date is valid
276
266
  if (Number.isNaN(d.getTime())) {
@@ -278,24 +268,29 @@ export const formatDate: FormatDateFn = (
278
268
  return ''
279
269
  }
280
270
 
281
- const datePartsMap = getDatePartsMap(d, locale, timeZone)
282
-
283
271
  // For more complex formats that need localization, use Intl.DateTimeFormat
284
272
  /// keep-sorted
285
- const formatter = new Intl.DateTimeFormat(locale, {
273
+ const intFmtOpt: Intl.DateTimeFormatOptions = {
286
274
  day: 'numeric',
287
275
  hour: '2-digit',
288
- hour12: true,
276
+
277
+ // Set default hour12 to true if not explicitly set
278
+ // hour12: true,
279
+ hour12: rest.hour12 === undefined ? true : rest.hour12,
289
280
  minute: '2-digit',
290
281
  month: 'long',
291
282
  second: '2-digit',
292
283
  timeZone, // Add timeZone if provided
293
284
  weekday: 'long',
294
285
  year: 'numeric',
295
- })
286
+ }
287
+
288
+ const datePartsMap = getDatePartsMap(d, locale, intFmtOpt)
289
+
290
+ const formatter = new Intl.DateTimeFormat(locale, intFmtOpt)
296
291
 
297
292
  const formattedParts = formatter.formatToParts(d)
298
- const partsMap: Record<string, string> = {}
293
+ const partsMap: Partial<Record<Intl.DateTimeFormatPartTypes, string>> = {}
299
294
 
300
295
  formattedParts.forEach((part) => {
301
296
  if (part.type !== 'literal') {
@@ -328,8 +323,4 @@ export const formatDate: FormatDateFn = (
328
323
  return ''
329
324
  }
330
325
  }
331
-
332
- export function fmtDate(opts: FormatDateOptions): FormatDateFnReturn {
333
- const { date, format, locale, timeZone } = opts
334
- return formatDate(date, format, locale, timeZone)
335
- }
326
+ export const fmtDate = formatDate