hyperbook 0.84.3 → 0.84.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/cloud.js +191 -154
- package/dist/assets/directive-onlineide/include/online-ide-embedded.js +3 -3
- package/dist/assets/directive-sqlide/include/includeIDE.js +22 -11
- package/dist/assets/directive-sqlide/include/sql-ide-embedded.js +30 -30
- package/dist/assets/store.js +21 -147
- package/dist/index.js +28 -13
- package/package.json +4 -4
package/dist/assets/store.js
CHANGED
|
@@ -29,145 +29,13 @@ store.version(2).stores({
|
|
|
29
29
|
learningmap: `id,nodes,x,y,zoom`,
|
|
30
30
|
textinput: `id,text`,
|
|
31
31
|
custom: `id,payload`,
|
|
32
|
+
onlineide: `scriptId,script`,
|
|
33
|
+
sqlideScripts: `scriptId,script`,
|
|
34
|
+
sqlideDatabases: `databaseId,database`,
|
|
32
35
|
multievent: `id,state`,
|
|
33
36
|
typst: `id,code`,
|
|
34
37
|
});
|
|
35
38
|
|
|
36
|
-
/**
|
|
37
|
-
* Read all data from an external IndexedDB database using the raw API.
|
|
38
|
-
* Returns a Dexie-export-compatible object, or null if the DB doesn't exist.
|
|
39
|
-
*/
|
|
40
|
-
function exportExternalDB(dbName) {
|
|
41
|
-
return new Promise((resolve) => {
|
|
42
|
-
const request = indexedDB.open(dbName);
|
|
43
|
-
request.onerror = () => resolve(null);
|
|
44
|
-
request.onsuccess = (event) => {
|
|
45
|
-
const db = event.target.result;
|
|
46
|
-
const storeNames = Array.from(db.objectStoreNames);
|
|
47
|
-
if (storeNames.length === 0) {
|
|
48
|
-
db.close();
|
|
49
|
-
resolve(null);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const result = {
|
|
53
|
-
formatName: "dexie",
|
|
54
|
-
formatVersion: 1,
|
|
55
|
-
data: {
|
|
56
|
-
databaseName: dbName,
|
|
57
|
-
databaseVersion: db.version,
|
|
58
|
-
tables: [],
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
const tx = db.transaction(storeNames, "readonly");
|
|
62
|
-
let pending = storeNames.length;
|
|
63
|
-
storeNames.forEach((name) => {
|
|
64
|
-
const objectStore = tx.objectStore(name);
|
|
65
|
-
const tableInfo = {
|
|
66
|
-
name: name,
|
|
67
|
-
schema: objectStore.keyPath ? `${objectStore.keyPath}` : "++id",
|
|
68
|
-
rowCount: 0,
|
|
69
|
-
rows: [],
|
|
70
|
-
};
|
|
71
|
-
const cursorReq = objectStore.openCursor();
|
|
72
|
-
cursorReq.onsuccess = (e) => {
|
|
73
|
-
const cursor = e.target.result;
|
|
74
|
-
if (cursor) {
|
|
75
|
-
tableInfo.rows.push(cursor.value);
|
|
76
|
-
cursor.continue();
|
|
77
|
-
} else {
|
|
78
|
-
tableInfo.rowCount = tableInfo.rows.length;
|
|
79
|
-
result.data.tables.push(tableInfo);
|
|
80
|
-
pending--;
|
|
81
|
-
if (pending === 0) {
|
|
82
|
-
db.close();
|
|
83
|
-
resolve(result);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
cursorReq.onerror = () => {
|
|
88
|
-
pending--;
|
|
89
|
-
if (pending === 0) {
|
|
90
|
-
db.close();
|
|
91
|
-
resolve(result);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Import data into an external IndexedDB database using the raw API.
|
|
101
|
-
* Accepts a Dexie-export-compatible object. Clears existing data before importing.
|
|
102
|
-
*/
|
|
103
|
-
function importExternalDB(dbName, exportData) {
|
|
104
|
-
return new Promise((resolve, reject) => {
|
|
105
|
-
const tables = exportData?.data?.tables;
|
|
106
|
-
if (!tables || tables.length === 0) { resolve(); return; }
|
|
107
|
-
|
|
108
|
-
// Determine the version the external tool uses (keep it in sync)
|
|
109
|
-
const request = indexedDB.open(dbName);
|
|
110
|
-
request.onerror = () => reject(request.error);
|
|
111
|
-
|
|
112
|
-
request.onupgradeneeded = (event) => {
|
|
113
|
-
// DB didn't exist yet — create the object stores from the export data
|
|
114
|
-
const db = event.target.result;
|
|
115
|
-
tables.forEach((table) => {
|
|
116
|
-
if (!db.objectStoreNames.contains(table.name)) {
|
|
117
|
-
const keyPath = table.schema && !table.schema.startsWith('++')
|
|
118
|
-
? table.schema.split(',')[0].trim()
|
|
119
|
-
: null;
|
|
120
|
-
db.createObjectStore(table.name, keyPath ? { keyPath } : { autoIncrement: true });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
request.onsuccess = (event) => {
|
|
126
|
-
const db = event.target.result;
|
|
127
|
-
const storeNames = tables
|
|
128
|
-
.map((t) => t.name)
|
|
129
|
-
.filter((n) => db.objectStoreNames.contains(n));
|
|
130
|
-
if (storeNames.length === 0) { db.close(); resolve(); return; }
|
|
131
|
-
|
|
132
|
-
const tx = db.transaction(storeNames, "readwrite");
|
|
133
|
-
// Clear then re-populate each store
|
|
134
|
-
storeNames.forEach((name) => {
|
|
135
|
-
const objectStore = tx.objectStore(name);
|
|
136
|
-
objectStore.clear();
|
|
137
|
-
const table = tables.find((t) => t.name === name);
|
|
138
|
-
if (table && table.rows) {
|
|
139
|
-
table.rows.forEach((row) => objectStore.put(row));
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
tx.oncomplete = () => { db.close(); resolve(); };
|
|
143
|
-
tx.onerror = () => { db.close(); reject(tx.error); };
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Clear all tables in an external IndexedDB database using the raw API.
|
|
150
|
-
*/
|
|
151
|
-
function clearExternalDB(dbName) {
|
|
152
|
-
return new Promise((resolve) => {
|
|
153
|
-
const request = indexedDB.open(dbName);
|
|
154
|
-
request.onerror = () => resolve();
|
|
155
|
-
request.onsuccess = (event) => {
|
|
156
|
-
const db = event.target.result;
|
|
157
|
-
const storeNames = Array.from(db.objectStoreNames);
|
|
158
|
-
if (storeNames.length === 0) {
|
|
159
|
-
db.close();
|
|
160
|
-
resolve();
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const tx = db.transaction(storeNames, "readwrite");
|
|
164
|
-
storeNames.forEach((name) => tx.objectStore(name).clear());
|
|
165
|
-
tx.oncomplete = () => { db.close(); resolve(); };
|
|
166
|
-
tx.onerror = () => { db.close(); resolve(); };
|
|
167
|
-
};
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
39
|
const initStore = async () => {
|
|
172
40
|
store.currentState.put({
|
|
173
41
|
id: 1,
|
|
@@ -200,16 +68,12 @@ initStore();
|
|
|
200
68
|
|
|
201
69
|
async function hyperbookExport() {
|
|
202
70
|
const hyperbook = await store.export({ prettyJson: true });
|
|
203
|
-
const sqlIde = await exportExternalDB('SQL-IDE');
|
|
204
|
-
const learnJ = await exportExternalDB('LearnJ');
|
|
205
71
|
|
|
206
72
|
const data = {
|
|
207
73
|
version: 1,
|
|
208
74
|
origin: window.location.origin,
|
|
209
75
|
data: {
|
|
210
76
|
hyperbook: JSON.parse(await hyperbook.text()),
|
|
211
|
-
sqlIde: sqlIde || {},
|
|
212
|
-
learnJ: learnJ || {},
|
|
213
77
|
},
|
|
214
78
|
};
|
|
215
79
|
|
|
@@ -236,8 +100,15 @@ async function hyperbookReset() {
|
|
|
236
100
|
}
|
|
237
101
|
|
|
238
102
|
clearTable(store);
|
|
239
|
-
|
|
240
|
-
|
|
103
|
+
|
|
104
|
+
// Send empty snapshot to cloud
|
|
105
|
+
if (window.hyperbook && window.hyperbook.cloud) {
|
|
106
|
+
try {
|
|
107
|
+
await window.hyperbook.cloud.sendSnapshot();
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.error("Failed to sync reset to cloud:", e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
241
112
|
|
|
242
113
|
alert(i18n.get("store-reset-sucessful"));
|
|
243
114
|
window.location.reload();
|
|
@@ -269,18 +140,21 @@ async function hyperbookImport() {
|
|
|
269
140
|
return;
|
|
270
141
|
}
|
|
271
142
|
|
|
272
|
-
const { hyperbook
|
|
143
|
+
const { hyperbook } = data.data;
|
|
273
144
|
|
|
274
145
|
const hyperbookBlob = new Blob([JSON.stringify(hyperbook)], {
|
|
275
146
|
type: "application/json",
|
|
276
147
|
});
|
|
277
148
|
|
|
278
149
|
await store.import(hyperbookBlob, { clearTablesBeforeImport: true });
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
150
|
+
|
|
151
|
+
// Send full snapshot to cloud after import
|
|
152
|
+
if (window.hyperbook && window.hyperbook.cloud) {
|
|
153
|
+
try {
|
|
154
|
+
await window.hyperbook.cloud.sendSnapshot();
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.error("Failed to sync import to cloud:", e);
|
|
157
|
+
}
|
|
284
158
|
}
|
|
285
159
|
|
|
286
160
|
alert(i18n.get("store-import-sucessful"));
|
package/dist/index.js
CHANGED
|
@@ -55558,7 +55558,7 @@ async function runBuild(root, rootProject, basePath, prefix, out, filter) {
|
|
|
55558
55558
|
const baseCtx = {
|
|
55559
55559
|
root,
|
|
55560
55560
|
config: hyperbookJson,
|
|
55561
|
-
makeUrl: (path, base, page) => {
|
|
55561
|
+
makeUrl: (path, base, page, options = { versioned: true }) => {
|
|
55562
55562
|
if (typeof path === "string") {
|
|
55563
55563
|
// Handle absolute URLs
|
|
55564
55564
|
if (path.includes("://") || path.startsWith("data:")) {
|
|
@@ -55602,7 +55602,11 @@ async function runBuild(root, rootProject, basePath, prefix, out, filter) {
|
|
|
55602
55602
|
return `${path_1.posix.join("/", basePath || "", exports.ASSETS_FOLDER, ...path)}`;
|
|
55603
55603
|
}
|
|
55604
55604
|
else {
|
|
55605
|
-
|
|
55605
|
+
let p = `${path_1.posix.join("/", basePath || "", exports.ASSETS_FOLDER, ...path)}`;
|
|
55606
|
+
if (options === null || options === void 0 ? void 0 : options.versioned) {
|
|
55607
|
+
p += `?v=${package_json_1.default.version}`;
|
|
55608
|
+
}
|
|
55609
|
+
return p;
|
|
55606
55610
|
}
|
|
55607
55611
|
}
|
|
55608
55612
|
},
|
|
@@ -176692,7 +176696,18 @@ var remarkDirectiveSqlIde_default = (ctx) => () => {
|
|
|
176692
176696
|
const attributes4 = node3.attributes || {};
|
|
176693
176697
|
const {
|
|
176694
176698
|
id = hash(node3),
|
|
176695
|
-
db = ctx.config.elements?.sqlide?.db ||
|
|
176699
|
+
db = ctx.config.elements?.sqlide?.db || ctx.makeUrl(
|
|
176700
|
+
[
|
|
176701
|
+
"directive-sqlide",
|
|
176702
|
+
"include",
|
|
176703
|
+
"assets",
|
|
176704
|
+
"databases",
|
|
176705
|
+
"world1.sqLite"
|
|
176706
|
+
],
|
|
176707
|
+
"assets",
|
|
176708
|
+
void 0,
|
|
176709
|
+
{ versioned: false }
|
|
176710
|
+
),
|
|
176696
176711
|
height = ctx.config.elements?.sqlide?.height || "600px"
|
|
176697
176712
|
} = attributes4;
|
|
176698
176713
|
expectContainerDirective(node3, file, name);
|
|
@@ -178370,6 +178385,15 @@ ${ctx.config.cloud ? `HYPERBOOK_CLOUD = ${JSON.stringify(ctx.config.cloud).repla
|
|
|
178370
178385
|
properties: {},
|
|
178371
178386
|
children: [
|
|
178372
178387
|
...originalChildren,
|
|
178388
|
+
{
|
|
178389
|
+
type: "element",
|
|
178390
|
+
tagName: "script",
|
|
178391
|
+
properties: {
|
|
178392
|
+
src: makeUrl(["client.js"], "assets"),
|
|
178393
|
+
defer: true
|
|
178394
|
+
},
|
|
178395
|
+
children: []
|
|
178396
|
+
},
|
|
178373
178397
|
...ctx.config.cloud ? [
|
|
178374
178398
|
{
|
|
178375
178399
|
type: "element",
|
|
@@ -178381,15 +178405,6 @@ ${ctx.config.cloud ? `HYPERBOOK_CLOUD = ${JSON.stringify(ctx.config.cloud).repla
|
|
|
178381
178405
|
children: []
|
|
178382
178406
|
}
|
|
178383
178407
|
] : [],
|
|
178384
|
-
{
|
|
178385
|
-
type: "element",
|
|
178386
|
-
tagName: "script",
|
|
178387
|
-
properties: {
|
|
178388
|
-
src: makeUrl(["client.js"], "assets"),
|
|
178389
|
-
defer: true
|
|
178390
|
-
},
|
|
178391
|
-
children: []
|
|
178392
|
-
},
|
|
178393
178408
|
...Object.entries(directives).flatMap(
|
|
178394
178409
|
([directive2, { scripts }]) => scripts.filter(
|
|
178395
178410
|
(script) => typeof script !== "object" || script.position == "body"
|
|
@@ -200718,7 +200733,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
|
|
|
200718
200733
|
/***/ ((module) => {
|
|
200719
200734
|
|
|
200720
200735
|
"use strict";
|
|
200721
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.84.
|
|
200736
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.84.4","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=18"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"create-hyperbook":"workspace:*","@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
|
|
200722
200737
|
|
|
200723
200738
|
/***/ })
|
|
200724
200739
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyperbook",
|
|
3
|
-
"version": "0.84.
|
|
3
|
+
"version": "0.84.4",
|
|
4
4
|
"author": "Mike Barkmin",
|
|
5
5
|
"homepage": "https://github.com/openpatch/hyperbook#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"tar": "7.4.3",
|
|
57
57
|
"update-check": "1.5.4",
|
|
58
58
|
"ws": "^8.18.0",
|
|
59
|
-
"create-hyperbook": "0.3.4",
|
|
60
|
-
"@hyperbook/markdown": "0.55.3",
|
|
61
59
|
"@hyperbook/fs": "0.24.2",
|
|
62
|
-
"
|
|
60
|
+
"create-hyperbook": "0.3.5",
|
|
61
|
+
"@hyperbook/markdown": "0.55.4",
|
|
62
|
+
"@hyperbook/types": "0.22.1"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"version": "pnpm build",
|