@bagelink/vue 1.9.56 → 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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.9.56",
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)
@@ -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'