diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db53975..97155fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ English | [简体中文](./CHANGELOG_CN.md) - `Fix(Log)` Fix `window.onerror` missing line breaks. - `Fix(Log)` Fix unclickable `vc-cmd-clear-btn` on iOS Safari. (PR #564) - `Fix(Log)` Fix a typo that misjudged circular reference objects. (issue #566) +- `Fix(Storage)` Fix storage pannel sorting error when setting `storage.defaultStorages` option. (issue #560) - `Fix(Core)` Fix plugin panel sorting error when setting `pluginOrder` option. (issue #559) - `Chore` Add option `env['no-core-js']` to disable core-js polyfill. (PR #562) diff --git a/CHANGELOG_CN.md b/CHANGELOG_CN.md index 9e00d271..141df9db 100644 --- a/CHANGELOG_CN.md +++ b/CHANGELOG_CN.md @@ -6,6 +6,7 @@ - `Fix(Log)` 修复 `window.onerror` 丢失换行的问题。 - `Fix(Log)` 修复清除命令行按钮在 iOS Safari 中无法点击的问题。 (PR #564) - `Fix(Log)` 修复一处误判循环引用对象的笔误。 (issue #566) +- `Fix(Storage)` 修复因设置 `storage.defaultStorages` 导致 Storage 面板排序错误的问题。 (issue #560) - `Fix(Core)` 修复因设置 `pluginOrder` 导致插件面板排序错误的问题。 (issue #559) - `Chore` 添加 `env['no-core-js']` 选项来停用构建时使用 core-js polyfill。 (PR #562) diff --git a/dev/storage.html b/dev/storage.html index b7a154be..c9fdb0c5 100644 --- a/dev/storage.html +++ b/dev/storage.html @@ -18,6 +18,7 @@ XSS defaultStorages: clear defaultStorages: add + defaultStorages: update @@ -28,7 +29,7 @@ window.vConsole = new window.VConsole({ // disableLogScrolling: true, storage: { - // defaultStorages: [], + // defaultStorages: ['sessionStorage', 'cookies', 'localStorage'], }, onReady: function() { console.log('vConsole is ready.'); @@ -140,4 +141,8 @@ window.wx = {}; vConsole.setOption('storage.defaultStorages', ['wxStorage', 'localStorage']); } + +function defaultStoragesUpdate() { + vConsole.setOption('storage.defaultStorages', ['localStorage', 'unknownStorage', 'sessionStorage']); +} \ No newline at end of file diff --git a/src/storage/storage.ts b/src/storage/storage.ts index c821486b..95275da3 100644 --- a/src/storage/storage.ts +++ b/src/storage/storage.ts @@ -1,4 +1,5 @@ import { get } from 'svelte/store'; +import { isArray } from '../lib/tool'; import { VConsoleSveltePlugin } from '../lib/sveltePlugin'; import { VConsoleStorageModel, storageStore } from './storage.model'; import { default as StorageComp } from './storage.svelte'; @@ -53,9 +54,14 @@ export class VConsoleStoragePlugin extends VConsoleSveltePlugin { } public onUpdateOption() { - if (typeof this.vConsole.option.storage?.defaultStorages !== 'undefined') { - storageStore.defaultStorages.set(this.vConsole.option.storage?.defaultStorages || []); - this.updateTopBar(); + let defaultStorages = this.vConsole.option.storage?.defaultStorages; + if (isArray(defaultStorages)) { + defaultStorages = defaultStorages.length > 0 ? defaultStorages : ['cookies']; + if (defaultStorages !== get(storageStore.defaultStorages)) { + storageStore.defaultStorages.set(defaultStorages); + storageStore.activedName.set(defaultStorages[0]); + this.updateTopBar(); + } } } @@ -73,7 +79,7 @@ export class VConsoleStoragePlugin extends VConsoleSveltePlugin { data: { name: name, }, - actived: i === 0, + actived: name === get(storageStore.activedName), onClick: (e: PointerEvent, data: { name: string }) => { const activedName = get(storageStore.activedName); if (data.name === activedName) {