@openpresentation/opf-editor 0.26.8 → 0.26.9
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/README.md +1 -1
- package/dist/persistence.d.ts +1 -1
- package/dist/persistence.js +26 -17
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -707,7 +707,7 @@ const persistence = createPersistence(editor, {
|
|
|
707
707
|
storage: "indexeddb", // default; or "localstorage", "memory", false, or your own { get, set, delete } adapter
|
|
708
708
|
onRestorePrompt: ui.prompt, // or return "restore" | "discard" | "later" (or a promise) yourself
|
|
709
709
|
onStatus: ui.status, // "Saved on this device at 2:03 PM", or why autosave is off
|
|
710
|
-
beforeFlush: () => canvas.commit(), // commit a draft before
|
|
710
|
+
beforeFlush: () => canvas.commit(), // commit a draft before an explicit flush and before the page unloads (the debounced write leaves a draft alone)
|
|
711
711
|
});
|
|
712
712
|
await persistence.ready; // { available, offered }: storage opened and read (it does not wait for the user's decision)
|
|
713
713
|
await persistence.markSaved(); // after the host saved the document somewhere of its own: not unsaved, and the stored copy says so
|
package/dist/persistence.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export interface PersistenceOptions {
|
|
|
63
63
|
onRestorePrompt?: (offer: RestoreOffer, actions: { restore(): Promise<boolean>; discard(): Promise<boolean> }) => RestoreChoice | Promise<RestoreChoice>;
|
|
64
64
|
/** Called on every status change, for an indicator. */
|
|
65
65
|
onStatus?: (status: AutosaveStatus) => void;
|
|
66
|
-
/** Called synchronously before each explicit
|
|
66
|
+
/** Called synchronously before each explicit or lifecycle flush (`flush()`, `markSaved()`, `beforeunload`, `pagehide`), even before any session edit. The debounced autosave does not call it: it writes the committed document and leaves an edit in progress alone. Commit the active draft; returning false or throwing refuses the write and reports a draft error. */
|
|
67
67
|
beforeFlush?: () => boolean | void;
|
|
68
68
|
/** Warn before the page closes while the document is `dirty` (default true). */
|
|
69
69
|
warnOnUnload?: boolean;
|
package/dist/persistence.js
CHANGED
|
@@ -223,29 +223,38 @@ export function createPersistence(editor, options = {}) {
|
|
|
223
223
|
if (!firstDirtyAt) firstDirtyAt = at;
|
|
224
224
|
clearTimeout(timer);
|
|
225
225
|
const wait = Math.max(0, Math.min(debounceMs, firstDirtyAt + maxWaitMs - at));
|
|
226
|
-
timer = setTimeout(() => { void
|
|
226
|
+
timer = setTimeout(() => { void flushNow(false); }, wait);
|
|
227
227
|
}
|
|
228
228
|
/** Write the document now (cancelling the debounce) and resolve when it is stored. Resolves false when nothing could be written. */
|
|
229
229
|
function flush() {
|
|
230
|
+
return flushNow(true);
|
|
231
|
+
}
|
|
232
|
+
// The debounce timer writes what is committed and leaves an edit in progress alone: committing it would close the inline editor
|
|
233
|
+
// under the user's hands, a moment after an earlier change (the timer starts at that change) and long before they stop typing.
|
|
234
|
+
// The draft is not lost: the page is still open, and every flush that precedes leaving (unload, page hide, `flush()`, `markSaved()`)
|
|
235
|
+
// commits it first.
|
|
236
|
+
function flushNow(commitDraft) {
|
|
230
237
|
clearTimeout(timer);
|
|
231
238
|
firstDirtyAt = 0;
|
|
232
239
|
if (destroyed) return Promise.resolve(false);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
240
|
+
if (commitDraft) {
|
|
241
|
+
// Commit synchronously, including a draft in an otherwise untouched session. The lifecycle
|
|
242
|
+
// warning below must see that edit before it decides whether leaving would lose work.
|
|
243
|
+
// A commit emits a change; clear its debounce again and avoid recursive host flush hooks.
|
|
244
|
+
if (preparingFlush) return chain;
|
|
245
|
+
preparingFlush = true;
|
|
246
|
+
try {
|
|
247
|
+
if (options.beforeFlush?.() === false) throw new Error("Commit or cancel the active draft first.");
|
|
248
|
+
flushRefused = false;
|
|
249
|
+
} catch (error) {
|
|
250
|
+
flushRefused = true;
|
|
251
|
+
setStatus({ state: "error", error: "draft", message: `Autosave could not commit the active draft (${String(error?.message ?? error)}). Keep this page open to recover your work.` });
|
|
252
|
+
return Promise.resolve(false);
|
|
253
|
+
} finally {
|
|
254
|
+
preparingFlush = false;
|
|
255
|
+
clearTimeout(timer);
|
|
256
|
+
firstDirtyAt = 0;
|
|
257
|
+
}
|
|
249
258
|
}
|
|
250
259
|
if (!touched) return chain.then(() => true);
|
|
251
260
|
chain = chain.then(writeRecord, writeRecord);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpresentation/opf-editor",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.9",
|
|
4
4
|
"description": "Embeddable local OPF editor primitives built on the deterministic renderer.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -287,10 +287,10 @@
|
|
|
287
287
|
"@lezer/highlight": "1.2.5",
|
|
288
288
|
"jsonc-parser": "3.3.1",
|
|
289
289
|
"yaml": "^2.9.1",
|
|
290
|
-
"@openpresentation/opf": "^0.26.
|
|
290
|
+
"@openpresentation/opf": "^0.26.9"
|
|
291
291
|
},
|
|
292
292
|
"peerDependencies": {
|
|
293
|
-
"@openpresentation/opf-render": "^0.26.
|
|
293
|
+
"@openpresentation/opf-render": "^0.26.9"
|
|
294
294
|
},
|
|
295
295
|
"peerDependenciesMeta": {
|
|
296
296
|
"@openpresentation/opf-render": {
|
|
@@ -349,9 +349,9 @@
|
|
|
349
349
|
"pdf-lib": "1.17.1",
|
|
350
350
|
"pdfjs-dist": "6.4.299",
|
|
351
351
|
"playwright": "1.64.0",
|
|
352
|
-
"@openpresentation/
|
|
353
|
-
"@openpresentation/
|
|
354
|
-
"@openpresentation/opf-render": "0.26.
|
|
352
|
+
"@openpresentation/opf-pptx": "0.26.9",
|
|
353
|
+
"@openpresentation/gallery": "0.26.9",
|
|
354
|
+
"@openpresentation/opf-render": "0.26.9"
|
|
355
355
|
},
|
|
356
356
|
"scripts": {
|
|
357
357
|
"build": "node scripts/build.mjs",
|
|
@@ -402,5 +402,5 @@
|
|
|
402
402
|
"test:export-menu-browser": "node test/export-menu-browser.mjs",
|
|
403
403
|
"test:agent-handoff-browser": "node test/agent-handoff-browser.mjs"
|
|
404
404
|
},
|
|
405
|
-
"gitHead": "
|
|
405
|
+
"gitHead": "7563d8dea2ba24a36b032614a50f665876d145e5"
|
|
406
406
|
}
|