feat: add backpack with localStorage persistence#214
Merged
Conversation
Add localStorage storage backend to backpack-api.js, ported from xcratch. When host is set to 'localStorage', getBackpackContents/saveBackpackObject/ deleteBackpackObject operate on localStorage instead of a remote API server. Also add getLocalStorageBackpackAssetURL for asset URL resolution. Refs: #213
- Default token/username to 'localToken'/'localUser' when no session or URL params, enabling getContents() to work with localStorage host - Skip asset server presave in handleDrop when host is 'localStorage' Refs: #213
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feature/backpack-localstorage/ |
When backpackHost is 'localStorage', getBackpackAssetURL returns a data: URL by looking up the asset in localStorage, instead of returning an invalid 'localStorage/assetId.format' path URL. Refs: #213
- Set backpackVisible to true (backpack always shown) - Default backpackHost to 'localStorage' when no URL param - URL param ?backpack_host= still allows custom remote API Refs: #213
- Remove describe.skip (tests are now active) - Replace 'Coming Soon' test with localStorage-based visibility test - Add test for empty state when backpack first expanded - Add test for localStorage persistence across page reload Refs: #213
CSS Modules transforms class names, so use kebab-case 'backpack-list-inner' (the original CSS class name) instead of camelCase 'backpackItem' on li elements. Also add waitForLoadingFinished after page reload for stability. Refs: #213
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #213
Scratch 公式の backpack API はフォークには公開されていないため、xcratch の実装を参考に localStorage をバックエンドとして使用するバックパック機能を実装する。
Implementation Steps
backpack-api.js— localStorage バックエンド追加containers/backpack.jsx— localStorage 対応legacy-storage.ts— localStorage アセット URL 対応render-gui.jsx— バックパック有効化Changes
packages/scratch-gui/src/lib/backpack-api.js: localStorage バックエンド追加(host === 'localStorage'分岐)packages/scratch-gui/src/containers/backpack.jsx: token/username デフォルト値、localStorage アセットサーバースキップpackages/scratch-gui/src/lib/legacy-storage.ts: localStorage アセット URL 生成(data: URL)対応packages/scratch-gui/src/playground/render-gui.jsx: バックパック有効化、デフォルト localStoragepackages/scratch-gui/test/unit/lib/backpack-api.test.js: unit tests 追加 (9 tests)packages/scratch-gui/test/unit/containers/backpack.test.jsx: unit tests 追加 (2 tests)packages/scratch-gui/test/unit/lib/legacy-storage.test.js: unit tests 追加 (5 tests)packages/scratch-gui/test/integration/backpack.test.js: integration tests 更新 (4 tests, describe.skip 削除)Test Coverage