fix(stage-ui,ui): histoire wasn't configured correctly

This commit is contained in:
Neko Ayaka
2026-04-22 16:57:35 +08:00
parent ca4c99f074
commit 94031bf1c4
9 changed files with 100 additions and 265 deletions
+5
View File
@@ -1,7 +1,12 @@
import { useDark, useToggle } from '@vueuse/core'
import { LocalStorageShim } from '../utils'
const isDark = useDark({
disableTransition: true,
// NOTICE: for histoire, used in packages/stage-ui, localStorage global variable exists but `storage.getItem is not a function` wil
// thrown, here we added LocalStorageShim to avoid this issue, and it will fallback to real localStorage when it's available.
storage: 'localStorage' in globalThis && localStorage != null && 'getItem' in localStorage && typeof localStorage.getItem === 'function' ? localStorage : new LocalStorageShim(),
})
const toggleDark = useToggle(isDark)
+1
View File
@@ -0,0 +1 @@
export { LocalStorageShim } from './shim'
+1
View File
@@ -0,0 +1 @@
export { LocalStorageShim } from './local-storage'
@@ -0,0 +1,27 @@
export class LocalStorageShim implements Storage {
private map = new Map<string, any>()
clear() {
this.map.clear()
}
getItem(key: string) {
return this.map.get(key) || null
}
key(index: number) {
return Array.from(this.map.keys())[index] || null
}
get length() {
return this.map.size
}
setItem(key: string, value: string) {
this.map.set(key, value)
}
removeItem(key: string) {
this.map.delete(key)
}
}