@bagelink/vue 1.9.54 → 1.9.59

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.
@@ -52,7 +52,7 @@ export declare function getDatePartsMap(date: Date, locale: Intl.LocalesArgument
52
52
  YYYY: string;
53
53
  };
54
54
  export interface FormatDateOptions extends Partial<Pick<Intl.DateTimeFormatOptions, 'hour12'>> {
55
- fmt?: DateTimeAcceptedFormats;
55
+ format?: DateTimeAcceptedFormats;
56
56
  locale?: Intl.LocalesArgument;
57
57
  tz?: string;
58
58
  }
@@ -67,7 +67,7 @@ export declare function formatDate(date?: DateLike, format?: DateTimeAcceptedFor
67
67
  * Formats a date based on the provided options.
68
68
  * @param date The date to format (string or Date object).
69
69
  * @param opts Options for formatting the date.
70
- * @param opts.fmt The format string (default is 'DD.MM.YY').
70
+ * @param opts.format The format string (default is 'DD.MM.YY').
71
71
  * @param opts.locale The locale to use for formatting (default is browser's locale).
72
72
  * @param opts.tz The timezone to use for formatting (default is local timezone).
73
73
  * @returns Formatted date string.
@@ -1 +1 @@
1
- {"version":3,"file":"dateUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/calendar/dateUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,uBAAuB,EAAY,MAAM,sBAAsB,CAAA;AAG7E,UAAU,gBAAgB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAA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package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.9.54",
4
+ "version": "1.9.59",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { Btn, CheckInput, TextInput, ToggleInput, localRef, ListItem, Dropdown, useI18n } from '@bagelink/vue'
2
+ import { Btn, CheckInput, TextInput, ToggleInput, useLocalStore, ListItem, Dropdown, useI18n } from '@bagelink/vue'
3
3
  import { computed, ref, watch, nextTick, onUnmounted } from 'vue'
4
4
  import SpreadsheetTable from './SpreadsheetTable.vue'
5
5
 
@@ -229,7 +229,7 @@ interface CellPosition {
229
229
  const isSelecting = ref(false)
230
230
  const selectionStart = ref<CellPosition | null>(null)
231
231
  const selectionEnd = ref<CellPosition | null>(null)
232
- const wrapText = localRef('wrapText', false)
232
+ const { wrapText } = useLocalStore()
233
233
 
234
234
  // Reactive variable to track the currently editing cell
235
235
  const editingCell = ref<CellPosition | null>(null)
@@ -165,7 +165,7 @@ onUnmounted(() => {
165
165
  >
166
166
  <div class="event-content">
167
167
  <div class="event-time">
168
- {{ formatDate(event.start_time, { fmt: 'HH:mm' }) }}
168
+ {{ formatDate(event.start_time, { format: 'HH:mm' }) }}
169
169
  </div>
170
170
  <div class="event-details">
171
171
  <div class="event-title">
@@ -233,7 +233,7 @@ onUnmounted(() => {
233
233
  {{ event.title }}
234
234
  </div>
235
235
  <div class="event-time opacity-8">
236
- {{ formatDate(new Date(event.start_time), { fmt: 'HH:mm' }) }} - {{ formatDate(new Date(event.end_time), { fmt: 'HH:mm' }) }}
236
+ {{ formatDate(new Date(event.start_time), { format: 'HH:mm' }) }} - {{ formatDate(new Date(event.end_time), { format: 'HH:mm' }) }}
237
237
  </div>
238
238
  </div>
239
239
  </div>
@@ -251,9 +251,9 @@ onUnmounted(() => {
251
251
  }"
252
252
  >
253
253
  <div class="color-primary txt-12 p-025">
254
- {{ dragState.startTime ? formatDate(dragState.startTime, { fmt: 'HH:mm' }) : '' }}
254
+ {{ dragState.startTime ? formatDate(dragState.startTime, { format: 'HH:mm' }) : '' }}
255
255
  -
256
- {{ dragState.endTime ? formatDate(dragState.endTime, { fmt: 'HH:mm' }) : '' }}
256
+ {{ dragState.endTime ? formatDate(dragState.endTime, { format: 'HH:mm' }) : '' }}
257
257
  </div>
258
258
  </div>
259
259
  </div>
@@ -122,7 +122,7 @@ function handleEventSelection(event: CalendarEvent, domEvent?: MouseEvent) {
122
122
  }"
123
123
  >
124
124
  <div class="day-number">
125
- {{ formatDate(day.date, { fmt: 'DD' }) }}
125
+ {{ formatDate(day.date, { format: 'DD' }) }}
126
126
  </div>
127
127
  <div class="day-events">
128
128
  <template v-if="isMobile">
@@ -432,14 +432,14 @@ onUnmounted(() => {
432
432
  <div ref="calendarGrid" class="weekGrid border-bottom me-1">
433
433
  <div />
434
434
  <div v-for="day in weekDays" :key="day.toISOString()" class="day-header p-05 txt-center m_txt12">
435
- {{ formatDate(day, { fmt: 'DDD' }) }}
435
+ {{ formatDate(day, { format: 'DDD' }) }}
436
436
  <span
437
437
  class="txt-12 round p-025" :class="{
438
438
  'color-gray': day.toDateString() !== new Date().toDateString(),
439
439
  'bg-primary color-white': day.toDateString() === new Date().toDateString(),
440
440
  }"
441
441
  >
442
- {{ formatDate(day, { fmt: 'DD' }) }}
442
+ {{ formatDate(day, { format: 'DD' }) }}
443
443
  </span>
444
444
  </div>
445
445
  </div>
@@ -487,8 +487,8 @@ onUnmounted(() => {
487
487
  {{ event.title }}
488
488
  </div>
489
489
  <div class="txt10 opacity-8 user-select-none">
490
- {{ formatDate(event.start_time, { fmt: 'HH:mm' }) }} - {{ formatDate(event.end_time,
491
- { fmt: 'HH:mm' }) }}
490
+ {{ formatDate(event.start_time, { format: 'HH:mm' }) }} - {{ formatDate(event.end_time,
491
+ { format: 'HH:mm' }) }}
492
492
  </div>
493
493
  </div>
494
494
  </div>
@@ -507,9 +507,9 @@ onUnmounted(() => {
507
507
  }"
508
508
  >
509
509
  <div class="color-primary txt-12 p-025">
510
- {{ dragState.startTime ? formatDate(dragState.startTime, { fmt: 'HH:mm' }) : '' }} - {{
510
+ {{ dragState.startTime ? formatDate(dragState.startTime, { format: 'HH:mm' }) : '' }} - {{
511
511
  dragState.endTime
512
- ? formatDate(dragState.endTime, { fmt: 'HH:mm' }) : '' }}
512
+ ? formatDate(dragState.endTime, { format: 'HH:mm' }) : '' }}
513
513
  </div>
514
514
  </div>
515
515
  </div>
@@ -48,7 +48,7 @@ const isOpen = ref(false)
48
48
  // Formatting utilities
49
49
  function formatDisplayDate(date: Date | string | undefined): string {
50
50
  if (date === undefined || date === '') return ''
51
- return formatDate(date, { fmt: props.enableTime ? 'DD.MM.YY HH:mm' : 'DD.MM.YY' })
51
+ return formatDate(date, { format: props.enableTime ? 'DD.MM.YY HH:mm' : 'DD.MM.YY' })
52
52
  }
53
53
 
54
54
  function parseUserInput(input: string): Date | null {
@@ -1,6 +1,6 @@
1
- import type { BglFormSchemaT, IfAny } from '@bagelink/vue'
1
+ import type { BglFormSchemaT } from '@bagelink/vue'
2
2
 
3
- import type { MaybeRefOrGetter, Ref, UnwrapRef } from 'vue'
3
+ import type { MaybeRefOrGetter, Ref } from 'vue'
4
4
  import { getFallbackSchema } from '@bagelink/vue'
5
5
  import { computed, ref, toValue, watch } from 'vue'
6
6
 
@@ -9,6 +9,32 @@ export { useDevice } from './useDevice'
9
9
  export { useExcel } from './useExcel'
10
10
  export { usePolling } from './usePolling'
11
11
  export { useTheme } from './useTheme'
12
+
13
+ const _localStoreCache: Record<string, Ref> = {}
14
+ let _storageListenerRegistered = false
15
+
16
+ export function useLocalStore() {
17
+ if (!_storageListenerRegistered) {
18
+ _storageListenerRegistered = true
19
+ window.addEventListener('storage', (e) => {
20
+ if (e.key && _localStoreCache[e.key]) {
21
+ _localStoreCache[e.key].value = e.newValue !== null ? JSON.parse(e.newValue) : null
22
+ }
23
+ })
24
+ }
25
+ return new Proxy({} as Record<string, Ref>, {
26
+ get(_, key: string) {
27
+ if (!_localStoreCache[key]) {
28
+ const stored = localStorage.getItem(key)
29
+ _localStoreCache[key] = ref(stored !== null ? JSON.parse(stored) : null)
30
+ watch(_localStoreCache[key], (val) => {
31
+ localStorage.setItem(key, JSON.stringify(val))
32
+ })
33
+ }
34
+ return _localStoreCache[key]
35
+ },
36
+ })
37
+ }
12
38
  interface UseBglSchemaParamsT<T> {
13
39
  schema?: MaybeRefOrGetter<BglFormSchemaT<T>>
14
40
  columns?: MaybeRefOrGetter<string[]>
@@ -31,22 +57,4 @@ export function useBglSchema<T = { [key: string]: unknown }>(
31
57
  return getFallbackSchema(data, _columns.value)
32
58
  }
33
59
 
34
- export function localRef<T>(
35
- key: string,
36
- initialValue: T
37
- ): [T] extends [Ref<any, any>] ?
38
- IfAny<T, Ref<T, T>, T> :
39
- Ref<UnwrapRef<T>, T | UnwrapRef<T>> {
40
- const storedValue = localStorage.getItem(key)
41
- const initial = storedValue !== null ? JSON.parse(storedValue) : initialValue
42
- const value = ref<T>(initial)
43
-
44
- watch(() => value.value, (val) => {
45
- localStorage.setItem(key, JSON.stringify(val))
46
- }, { immediate: true, deep: true })
47
-
48
- return value as any
49
- }
50
-
51
- export const useLocalStorage = localRef
52
60
  export { useValidateFieldValue } from './useValidateFieldValue'
package/src/i18n/index.ts CHANGED
@@ -20,42 +20,48 @@ const bagelinkLocales = {
20
20
  } as const
21
21
 
22
22
  export interface CreateBagelI18nOptions {
23
- /** Default language (default: 'en') */
24
- defaultLang?: string
25
- /** Initial language (default: 'en') */
26
- language?: string
27
- /** Available languages (default: all bagelink locales) */
28
- availableLangs?: string[]
29
- /** User's custom messages (merged with bagelink's) */
23
+ /** Active locale (default: 'en'). Same as vue-i18n's `locale`. */
24
+ locale?: string
25
+ /** Fallback locale (default: 'en'). Same as vue-i18n's `fallbackLocale`. */
26
+ fallbackLocale?: string
27
+ /** User's custom messages merged with bagelink's built-in translations. Same as vue-i18n's `messages`. */
30
28
  messages?: Record<string, Record<string, unknown>>
31
29
  }
32
30
 
33
31
  let i18nInstance: I18n | null = null
34
32
 
35
33
  /**
36
- * Creates an i18n instance with bagelink's translations merged with user's
34
+ * Creates an i18n instance with bagelink's translations merged with user's.
35
+ * Options mirror vue-i18n's `createI18n` for consistency.
37
36
  */
38
37
  export function createI18n(options: CreateBagelI18nOptions = {}): I18n {
39
38
  const {
40
- defaultLang = 'en',
41
- language = 'en',
42
- availableLangs = Object.keys(bagelinkLocales),
39
+ locale = 'en',
40
+ fallbackLocale = 'en',
43
41
  messages = {},
44
42
  } = options
45
43
 
46
- // Merge bagelink locales with user messages
44
+ // Merge bagelink locales with user messages for all supported locales
45
+ const supportedLocales = Object.keys(bagelinkLocales)
47
46
  const mergedMessages: Record<string, Record<string, unknown>> = {}
48
47
 
49
- for (const lang of availableLangs) {
48
+ for (const lang of supportedLocales) {
50
49
  mergedMessages[lang] = {
51
50
  ...(bagelinkLocales[lang as keyof typeof bagelinkLocales] || {}),
52
51
  ...(messages[lang] || {}),
53
52
  }
54
53
  }
55
54
 
55
+ // Also include any user-provided locales not in bagelink's built-ins
56
+ for (const lang of Object.keys(messages)) {
57
+ if (!mergedMessages[lang]) {
58
+ mergedMessages[lang] = messages[lang]
59
+ }
60
+ }
61
+
56
62
  i18nInstance = createVueI18n({
57
- locale: language,
58
- fallbackLocale: defaultLang,
63
+ locale,
64
+ fallbackLocale,
59
65
  messages: mergedMessages as any,
60
66
  legacy: false,
61
67
  globalInjection: true,
@@ -219,6 +219,19 @@ function getBrowserNavigatorLocale(): string {
219
219
  : navigator.language
220
220
  }
221
221
 
222
+ /**
223
+ * Returns the active i18n locale if initialized, otherwise falls back to
224
+ * the browser's navigator locale. Used as the default for formatDate.
225
+ */
226
+ function getActiveLocale(): string {
227
+ try {
228
+ const { locale } = getI18n().global
229
+ return typeof locale === 'string' ? locale : locale.value
230
+ } catch {
231
+ return getBrowserNavigatorLocale()
232
+ }
233
+ }
234
+
222
235
  /**
223
236
  * Adjust a date for a specific timezone
224
237
  * @param date The date to adjust
@@ -310,7 +323,7 @@ const _orderedDateTokens = (
310
323
  const _tokenRegExPattern = new RegExp(_orderedDateTokens.map(token => token).join('|'), 'g')
311
324
 
312
325
  export interface FormatDateOptions extends Partial<Pick<Intl.DateTimeFormatOptions, 'hour12'>> {
313
- fmt?: DateTimeAcceptedFormats
326
+ format?: DateTimeAcceptedFormats
314
327
  locale?: Intl.LocalesArgument
315
328
  tz?: string
316
329
  }
@@ -327,7 +340,7 @@ export function formatDate(date?: DateLike, format?: DateTimeAcceptedFormats): s
327
340
  * Formats a date based on the provided options.
328
341
  * @param date The date to format (string or Date object).
329
342
  * @param opts Options for formatting the date.
330
- * @param opts.fmt The format string (default is 'DD.MM.YY').
343
+ * @param opts.format The format string (default is 'DD.MM.YY').
331
344
  * @param opts.locale The locale to use for formatting (default is browser's locale).
332
345
  * @param opts.tz The timezone to use for formatting (default is local timezone).
333
346
  * @returns Formatted date string.
@@ -355,7 +368,7 @@ export function formatDate(
355
368
  format = formatOrOpts
356
369
  } else if (formatOrOpts && typeof formatOrOpts === 'object') {
357
370
  // Second overload: options object
358
- format = formatOrOpts.fmt
371
+ format = formatOrOpts.format
359
372
  locale = formatOrOpts.locale
360
373
  timeZone = formatOrOpts.tz
361
374
  rest = formatOrOpts
@@ -364,7 +377,7 @@ export function formatDate(
364
377
  if (!date) { return '' }
365
378
  format = format || 'DD.MM.YY'
366
379
 
367
- locale = locale || getBrowserNavigatorLocale()
380
+ locale = locale || getActiveLocale()
368
381
  try {
369
382
  // Validate the date
370
383
  const d = typeof date === 'string' || typeof date === 'number' ? new Date(date) : date