Skip to content

Commit c4fddb6

Browse files
Copilotmikebarkmin
andauthored
Add custom data table to Dexie store for user-managed state persistence (#1035)
* Initial plan * Add custom data table to Dexie store with comprehensive documentation Co-authored-by: mikebarkmin <[email protected]> * Update versions and add changeset for custom data store feature - Bump @hyperbook/markdown to 0.40.0 - Bump hyperbook to 0.66.0 - Bump hyperbook-studio to 0.42.0 - Add changeset file for custom data store feature - Update CHANGELOG.md files for all affected packages - Update website changelog with v0.66.0 entry Co-authored-by: mikebarkmin <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mikebarkmin <[email protected]>
1 parent 835f279 commit c4fddb6

File tree

11 files changed

+294
-3
lines changed

11 files changed

+294
-3
lines changed

.changeset/custom-data-store.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@hyperbook/markdown": minor
3+
"hyperbook": minor
4+
"hyperbook-studio": minor
5+
---
6+
7+
Add custom data table to Dexie store for user-managed state persistence
8+
9+
This adds a new `custom` table to the Hyperbook Dexie store, enabling users to persist arbitrary JSON data in the browser's IndexedDB.
10+
11+
Features:
12+
- New `custom` table with schema `id, payload` for storing user-defined data
13+
- Comprehensive documentation in the advanced section showing how to use the API
14+
- Automatic inclusion in existing export/import functionality
15+
- Full support for storing and retrieving JSON data using `store.custom.put()` and `store.custom.get()`

packages/hyperbook/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# hyperbook
22

3+
## 0.66.0
4+
5+
### Minor Changes
6+
7+
- Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Add custom data table to Dexie store for user-managed state persistence
8+
9+
This adds a new `custom` table to the Hyperbook Dexie store, enabling users to persist arbitrary JSON data in the browser's IndexedDB.
10+
11+
Features:
12+
13+
- New `custom` table with schema `id, payload` for storing user-defined data
14+
- Comprehensive documentation in the advanced section showing how to use the API
15+
- Automatic inclusion in existing export/import functionality
16+
- Full support for storing and retrieving JSON data using `store.custom.put()` and `store.custom.get()`
17+
18+
### Patch Changes
19+
20+
- Updated dependencies:
21+
- @hyperbook/markdown@0.40.0
22+
323
## 0.65.0
424

525
### Minor Changes

packages/hyperbook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hyperbook",
3-
"version": "0.65.0",
3+
"version": "0.66.0",
44
"author": "Mike Barkmin",
55
"homepage": "https://github.com/openpatch/hyperbook#readme",
66
"license": "MIT",

packages/markdown/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# @hyperbook/markdown
22

3+
## 0.40.0
4+
5+
### Minor Changes
6+
7+
- Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Add custom data table to Dexie store for user-managed state persistence
8+
9+
This adds a new `custom` table to the Hyperbook Dexie store, enabling users to persist arbitrary JSON data in the browser's IndexedDB.
10+
11+
Features:
12+
13+
- New `custom` table with schema `id, payload` for storing user-defined data
14+
- Comprehensive documentation in the advanced section showing how to use the API
15+
- Automatic inclusion in existing export/import functionality
16+
- Full support for storing and retrieving JSON data using `store.custom.put()` and `store.custom.get()`
17+
318
## 0.39.0
419

520
### Minor Changes

packages/markdown/assets/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ store.version(1).stores({
2828
geogebra: `id,state`,
2929
learningmap: `id,nodes,x,y,zoom`,
3030
textinput: `id,text`,
31+
custom: `id,payload`,
3132
});
3233
var sqlIdeDB = new Dexie("SQL-IDE");
3334
sqlIdeDB.version(0.1).stores({

packages/markdown/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperbook/markdown",
3-
"version": "0.39.0",
3+
"version": "0.40.0",
44
"author": "Mike Barkmin",
55
"homepage": "https://github.com/openpatch/hyperbook#readme",
66
"license": "MIT",

platforms/vscode/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# @hyperbook/vscode-extension
22

3+
## 0.42.0
4+
5+
### Minor Changes
6+
7+
- Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Add custom data table to Dexie store for user-managed state persistence
8+
9+
This adds a new `custom` table to the Hyperbook Dexie store, enabling users to persist arbitrary JSON data in the browser's IndexedDB.
10+
11+
Features:
12+
13+
- New `custom` table with schema `id, payload` for storing user-defined data
14+
- Comprehensive documentation in the advanced section showing how to use the API
15+
- Automatic inclusion in existing export/import functionality
16+
- Full support for storing and retrieving JSON data using `store.custom.put()` and `store.custom.get()`
17+
18+
### Patch Changes
19+
20+
- Updated dependencies:
21+
- @hyperbook/markdown@0.40.0
22+
323
## 0.41.0
424

525
### Minor Changes

platforms/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"homepage": "https://hyperbook.openpatch.org",
1313
"main": "./out/extension.js",
14-
"version": "0.41.0",
14+
"version": "0.42.0",
1515
"engines": {
1616
"vscode": "^1.71.0"
1717
},

website/de/book/advanced/custom-scripts.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,107 @@ for (let el of els) {
2828
```
2929

3030
<div class="random-color">Am I a Chameleon?</div>
31+
32+
## Verwendung der Hyperbook Store API
33+
34+
Hyperbook stellt eine integrierte Dexie-Datenbank zur Verfügung, mit der du benutzerdefinierte Daten in der IndexedDB des Browsers speichern und abrufen kannst. Dies ist nützlich zum Speichern von Benutzereinstellungen, Fortschrittsverfolgung oder anderen benutzerdefinierten Daten, die nach dem Neuladen der Seite erhalten bleiben sollen.
35+
36+
### Custom Data Tabelle
37+
38+
Der Hyperbook-Store enthält eine `custom`-Tabelle, die speziell für deine benutzerdefinierten Datenanforderungen entwickelt wurde. Das Tabellenschema ist:
39+
40+
- `id` - Eine eindeutige Kennung für deinen Dateneintrag (String)
41+
- `payload` - Deine benutzerdefinierten Daten, typischerweise als JSON gespeichert
42+
43+
### Daten speichern
44+
45+
Du kannst benutzerdefinierte JSON-Daten mit der Methode `store.custom.put()` speichern:
46+
47+
```js
48+
// Benutzereinstellungen speichern
49+
await store.custom.put({
50+
id: "user-preferences",
51+
payload: JSON.stringify({
52+
theme: "dark",
53+
fontSize: 16,
54+
language: "de"
55+
})
56+
});
57+
58+
// Benutzerfortschritt speichern
59+
await store.custom.put({
60+
id: "chapter-progress",
61+
payload: JSON.stringify({
62+
currentChapter: 5,
63+
completedExercises: [1, 2, 3],
64+
lastVisited: new Date().toISOString()
65+
})
66+
});
67+
```
68+
69+
### Daten abrufen
70+
71+
Du kannst deine Daten mit der Methode `store.custom.get()` abrufen:
72+
73+
```js
74+
// Benutzereinstellungen abrufen
75+
const prefs = await store.custom.get("user-preferences");
76+
if (prefs) {
77+
const preferences = JSON.parse(prefs.payload);
78+
console.log(preferences.theme); // "dark"
79+
}
80+
81+
// Benutzerfortschritt abrufen
82+
const progress = await store.custom.get("chapter-progress");
83+
if (progress) {
84+
const data = JSON.parse(progress.payload);
85+
console.log(data.currentChapter); // 5
86+
}
87+
```
88+
89+
### Vollständiges Beispiel
90+
91+
Hier ist ein vollständiges Beispiel, das das Speichern und Laden benutzerdefinierter Daten demonstriert:
92+
93+
```js title="user-preferences.js"
94+
// Einstellungen initialisieren oder laden
95+
async function initPreferences() {
96+
const stored = await store.custom.get("my-app-settings");
97+
98+
let settings;
99+
if (stored) {
100+
settings = JSON.parse(stored.payload);
101+
} else {
102+
// Standardeinstellungen
103+
settings = {
104+
notifications: true,
105+
autoSave: true,
106+
lastLogin: new Date().toISOString()
107+
};
108+
await savePreferences(settings);
109+
}
110+
111+
return settings;
112+
}
113+
114+
// Einstellungen speichern
115+
async function savePreferences(settings) {
116+
await store.custom.put({
117+
id: "my-app-settings",
118+
payload: JSON.stringify(settings)
119+
});
120+
}
121+
122+
// Beispielverwendung
123+
initPreferences().then(settings => {
124+
console.log("Aktuelle Einstellungen:", settings);
125+
126+
// Eine Einstellung aktualisieren
127+
settings.notifications = false;
128+
savePreferences(settings);
129+
});
130+
```
131+
132+
### Datenexport und -import
133+
134+
Deine benutzerdefinierten Daten werden automatisch eingeschlossen, wenn Benutzer ihre Hyperbook-Daten mit der Funktion `hyperbookExport()` exportieren. Ebenso werden sie wiederhergestellt, wenn sie `hyperbookImport()` verwenden. Dadurch wird sichergestellt, dass deine benutzerdefinierten Daten über Browser-Sitzungen hinweg erhalten bleiben und zwischen Geräten übertragen werden können.

website/en/book/advanced/custom-scripts.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,107 @@ for (let el of els) {
2727
```
2828

2929
<div class="random-color">Am I a Chameleon?</div>
30+
31+
## Using the Hyperbook Store API
32+
33+
Hyperbook provides a built-in Dexie database that allows you to store and retrieve custom data in the browser's IndexedDB. This is useful for persisting user preferences, progress tracking, or any other custom data that should survive page reloads.
34+
35+
### Custom Data Table
36+
37+
The hyperbook store includes a `custom` table specifically designed for your custom data needs. The table schema is:
38+
39+
- `id` - A unique identifier for your data entry (string)
40+
- `payload` - Your custom data, typically stored as JSON
41+
42+
### Saving Data
43+
44+
You can save custom JSON data using the `store.custom.put()` method:
45+
46+
```js
47+
// Save user preferences
48+
await store.custom.put({
49+
id: "user-preferences",
50+
payload: JSON.stringify({
51+
theme: "dark",
52+
fontSize: 16,
53+
language: "en"
54+
})
55+
});
56+
57+
// Save user progress
58+
await store.custom.put({
59+
id: "chapter-progress",
60+
payload: JSON.stringify({
61+
currentChapter: 5,
62+
completedExercises: [1, 2, 3],
63+
lastVisited: new Date().toISOString()
64+
})
65+
});
66+
```
67+
68+
### Retrieving Data
69+
70+
You can retrieve your data using the `store.custom.get()` method:
71+
72+
```js
73+
// Get user preferences
74+
const prefs = await store.custom.get("user-preferences");
75+
if (prefs) {
76+
const preferences = JSON.parse(prefs.payload);
77+
console.log(preferences.theme); // "dark"
78+
}
79+
80+
// Get user progress
81+
const progress = await store.custom.get("chapter-progress");
82+
if (progress) {
83+
const data = JSON.parse(progress.payload);
84+
console.log(data.currentChapter); // 5
85+
}
86+
```
87+
88+
### Complete Example
89+
90+
Here's a complete example that demonstrates saving and loading custom data:
91+
92+
```js title="user-preferences.js"
93+
// Initialize or load preferences
94+
async function initPreferences() {
95+
const stored = await store.custom.get("my-app-settings");
96+
97+
let settings;
98+
if (stored) {
99+
settings = JSON.parse(stored.payload);
100+
} else {
101+
// Default settings
102+
settings = {
103+
notifications: true,
104+
autoSave: true,
105+
lastLogin: new Date().toISOString()
106+
};
107+
await savePreferences(settings);
108+
}
109+
110+
return settings;
111+
}
112+
113+
// Save preferences
114+
async function savePreferences(settings) {
115+
await store.custom.put({
116+
id: "my-app-settings",
117+
payload: JSON.stringify(settings)
118+
});
119+
}
120+
121+
// Example usage
122+
initPreferences().then(settings => {
123+
console.log("Current settings:", settings);
124+
125+
// Update a setting
126+
settings.notifications = false;
127+
savePreferences(settings);
128+
});
129+
```
130+
131+
### Data Export and Import
132+
133+
Your custom data is automatically included when users export their hyperbook data using the `hyperbookExport()` function. Similarly, it will be restored when they use `hyperbookImport()`. This ensures your custom data is preserved across browser sessions and can be transferred between devices.

0 commit comments

Comments
 (0)