Skip to content

Commit f921906

Browse files
committed
feat(playground): Add playgorund and update to core 3.2.0
1 parent 38defda commit f921906

13 files changed

Lines changed: 195 additions & 33 deletions

File tree

.github/workflows/pages.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy playground to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v6
23+
24+
- uses: actions/setup-node@v6
25+
with:
26+
node-version: 22
27+
28+
- run: npm i -g --force corepack@latest && corepack enable
29+
30+
- name: Install dependencies
31+
run: npx nypm@latest i
32+
33+
- name: Prepare module and playground
34+
run: npm run dev:prepare
35+
36+
- name: Generate static playground
37+
run: npm run dev:generate
38+
env:
39+
NUXT_APP_BASE_URL: /module-persistence/
40+
41+
- name: Upload Pages artifact
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: playground/.output/public
45+
46+
deploy:
47+
needs: build
48+
runs-on: ubuntu-latest
49+
environment:
50+
name: github-pages
51+
url: ${{ steps.deployment.outputs.page_url }}
52+
steps:
53+
- name: Deploy to GitHub Pages
54+
id: deployment
55+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
node_modules
2+
.nuxt
3+
dist
4+
.output
5+
playground/.nuxt
6+
playground/node_modules
7+
._*

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
</p>
44
<h1 align="center">Persistence Module</h1>
55
<h3 align="center">
6-
Pinia with LocalForage for Open Web Desktop.
6+
Pinia persistence for Open Web Desktop (IndexedDB via idb-keyval).
77
</h3>
88

99
## Overview
1010

11-
This module enables [localForage](https://www.npmjs.com/package/localforage) within Pinia to store application states persistently.
11+
This module registers [`pinia-plugin-persistedstate-2`](https://github.com/wobsoriano/pinia-plugin-persistedstate-2) with storage backed by [`idb-keyval`](https://github.com/jakearchibald/idb-keyval) (small ESM library on IndexedDB). It avoids legacy UMD packages such as `localforage`, which break under Vite’s native ESM handling (`does not provide an export named 'default'`).
1212

1313
## Features
1414

15-
- Configures `pinia-plugin-persistedstate-2` to use `localforage`
16-
- Enables persistent storage for Pinia stores
17-
- Works seamlessly with Nuxt
15+
- Async `getItem` / `setItem` / `removeItem` compatible with the persisted-state plugin
16+
- Client-only Nuxt plugin (same pattern as before)
1817

1918
## Installation
2019

2120
```bash
22-
owd install-module @owdproject/module-pinia-localforage
21+
pnpm desktop add @owdproject/module-persistence
2322
```
2423

2524
## License

package.json

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
{
22
"name": "@owdproject/module-persistence",
33
"version": "0.0.1",
4-
"description": "Enables localforage within Pinia to store states persistently",
4+
"description": "Pinia persistence via IndexedDB (idb-keyval), ESM-friendly",
55
"license": "MIT",
66
"homepage": "https://github.com/owdproject/module-persistence",
77
"author": {
88
"name": "Open Web Desktop Team",
99
"url": "https://github.com/owdproject"
1010
},
11-
"repository": {
12-
"type": "git",
13-
"url": "git+https://github.com/owdproject/module-persistence"
11+
"type": "module",
12+
"exports": {
13+
".": {
14+
"types": "./dist/types.d.mts",
15+
"import": "./dist/module.mjs"
16+
}
1417
},
15-
"bugs": {
16-
"url": "https://github.com/owdproject/module-persistence/issues"
18+
"main": "./dist/module.mjs",
19+
"typesVersions": {
20+
"*": {
21+
".": ["./dist/types.d.mts"]
22+
}
23+
},
24+
"files": ["dist"],
25+
"nx": { "name": "module-persistence" },
26+
"scripts": {
27+
"prepack": "nuxt-module-build build",
28+
"dev": "pnpm run dev:prepare && cd playground && pnpm exec nuxt dev",
29+
"dev:build": "nuxt build playground",
30+
"dev:generate": "NUXT_APP_BASE_URL=${NUXT_APP_BASE_URL:-/module-persistence/} nuxt generate playground",
31+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && cd playground && pnpm exec nuxt prepare",
32+
"validate": "desktop validate ."
1733
},
18-
"keywords": [
19-
"owdproject",
20-
"owd-client",
21-
"pinia",
22-
"nuxt",
23-
"persist",
24-
"state"
25-
],
2634
"dependencies": {
27-
"localforage": "^1.10.0",
35+
"@nuxt/kit": "^4.3.0",
36+
"idb-keyval": "^6.2.2",
2837
"pinia-plugin-persistedstate-2": "^2.0.30"
2938
},
39+
"devDependencies": {
40+
"@nuxt/module-builder": "^1.0.2",
41+
"@owdproject/app-todo": "workspace:*",
42+
"@owdproject/core": "workspace:*",
43+
"@owdproject/theme-nova": "workspace:*",
44+
"nuxt": "^4.3.0",
45+
"typescript": "~5.9.3"
46+
},
3047
"peerDependencies": {
31-
"@owdproject/core": "^3.1.0"
48+
"@owdproject/core": "^3.2.0",
49+
"pinia": "^3.0.0"
3250
}
3351
}

playground/app/app.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<Desktop />
3+
</template>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { nextTick } from 'vue'
2+
import { defineNuxtPlugin } from 'nuxt/app'
3+
import { useApplicationManager } from '@owdproject/core/runtime/composables/useApplicationManager'
4+
5+
const APP_ID = 'org.owdproject.todo'
6+
const WINDOW_MODEL = 'main'
7+
8+
export default defineNuxtPlugin({
9+
name: 'module-persistence-playground-launch',
10+
dependsOn: ['owd-app-todo-register'],
11+
async setup(nuxtApp) {
12+
if (!import.meta.dev) return
13+
14+
const applicationManager = useApplicationManager()
15+
16+
async function surfaceWindow() {
17+
if (!applicationManager.isAppDefined(APP_ID)) return false
18+
const app = applicationManager.getAppById(APP_ID)!
19+
if (app.storeWindows.$persistedState) {
20+
await app.storeWindows.$persistedState.isReady()
21+
}
22+
app.closeAllWindows()
23+
app.storeWindows.windows = {}
24+
await applicationManager.execAppCommand(APP_ID, 'todo')
25+
const window = app.getFirstWindowByModel(WINDOW_MODEL)
26+
if (window) {
27+
window.actions.setActive(true)
28+
window.actions.bringToFront()
29+
}
30+
return Boolean(window)
31+
}
32+
33+
nuxtApp.hook('app:mounted', async () => {
34+
await nextTick()
35+
for (let i = 0; i < 80; i++) {
36+
if (await surfaceWindow()) return
37+
await new Promise((resolve) => setTimeout(resolve, 50))
38+
}
39+
})
40+
},
41+
})

playground/desktop.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineDesktopConfig } from '@owdproject/core'
2+
3+
export default defineDesktopConfig({
4+
theme: '@owdproject/theme-nova',
5+
modules: ['@owdproject/module-persistence'],
6+
apps: ['@owdproject/app-todo'],
7+
systemBar: { enabled: true, startButton: true },
8+
})

playground/nuxt.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default defineNuxtConfig({
2+
modules: ['@owdproject/core'],
3+
app: {
4+
baseURL: process.env.NUXT_APP_BASE_URL || '/',
5+
},
6+
i18n: {
7+
strategy: 'no_prefix',
8+
},
9+
devtools: { enabled: true },
10+
compatibilityDate: 'latest',
11+
ssr: false,
12+
})

playground/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@owdproject/module-persistence-playground",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "nuxt dev",
7+
"build": "nuxt build",
8+
"generate": "nuxt generate"
9+
},
10+
"dependencies": {
11+
"@owdproject/app-todo": "workspace:*",
12+
"@owdproject/core": "workspace:*",
13+
"@owdproject/module-persistence": "workspace:*",
14+
"@owdproject/theme-nova": "workspace:*",
15+
"nuxt": "^4.4.4"
16+
}
17+
}

playground/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.json"
3+
}

0 commit comments

Comments
 (0)