@pixerate/editor 0.278.0 → 0.279.0
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/canvas/editorDocument.d.cts +53 -0
- package/dist/canvas/editorDocument.d.ts +53 -0
- package/dist/canvas/index.cjs +169 -22
- package/dist/canvas/index.js +148 -1
- package/dist/chart/index.cjs +1 -1
- package/dist/chart/index.js +1 -1
- package/dist/{chunk-T2HUQBRC.cjs → chunk-DK33HLA2.cjs} +331 -10
- package/dist/{chunk-JV7DKLMX.js → chunk-KBH6CM3U.js} +326 -5
- package/dist/persistence/autosave.d.cts +15 -1
- package/dist/persistence/autosave.d.ts +15 -1
- package/dist/persistence/editorAutosave.d.cts +12 -1
- package/dist/persistence/editorAutosave.d.ts +12 -1
- package/dist/persistence/index.cjs +6 -2
- package/dist/persistence/index.d.cts +1 -0
- package/dist/persistence/index.d.ts +1 -0
- package/dist/persistence/index.js +5 -1
- package/dist/persistence/remoteSync.d.cts +152 -0
- package/dist/persistence/remoteSync.d.ts +152 -0
- package/package.json +1 -1
|
@@ -473,6 +473,10 @@ function createAutosaveController(options) {
|
|
|
473
473
|
return rev;
|
|
474
474
|
};
|
|
475
475
|
const docName = () => typeof options.name === "function" ? options.name() : options.name;
|
|
476
|
+
const readBaseVersion = () => {
|
|
477
|
+
const v = typeof options.baseVersion === "function" ? options.baseVersion() : options.baseVersion;
|
|
478
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
479
|
+
};
|
|
476
480
|
const run = (action, rev) => {
|
|
477
481
|
if (action.type === "writeSnapshot") {
|
|
478
482
|
setInfo({ status: "saving", nextAttemptAt: null });
|
|
@@ -482,11 +486,13 @@ function createAutosaveController(options) {
|
|
|
482
486
|
try {
|
|
483
487
|
const text = serialize(getSnapshot());
|
|
484
488
|
await storage.set(key, text);
|
|
489
|
+
const baseVersion = readBaseVersion();
|
|
485
490
|
const meta = {
|
|
486
491
|
dirty: true,
|
|
487
492
|
revision: action.revision,
|
|
488
493
|
time: wallClock(),
|
|
489
|
-
name: docName()
|
|
494
|
+
name: docName(),
|
|
495
|
+
...baseVersion !== void 0 ? { baseVersion } : {}
|
|
490
496
|
};
|
|
491
497
|
await storage.set(metaKey, JSON.stringify(meta));
|
|
492
498
|
ok = true;
|
|
@@ -607,7 +613,7 @@ function createAutosaveController(options) {
|
|
|
607
613
|
tick();
|
|
608
614
|
await whenIdle();
|
|
609
615
|
},
|
|
610
|
-
async checkRecovery() {
|
|
616
|
+
async checkRecovery(checkOptions) {
|
|
611
617
|
if (policy.ownsSnapshot) return null;
|
|
612
618
|
let meta;
|
|
613
619
|
try {
|
|
@@ -618,6 +624,12 @@ function createAutosaveController(options) {
|
|
|
618
624
|
return null;
|
|
619
625
|
}
|
|
620
626
|
if (!meta || meta.dirty !== true) return null;
|
|
627
|
+
const required = checkOptions?.minimumBaseVersion ?? readBaseVersion();
|
|
628
|
+
if (required !== void 0 && (typeof meta.baseVersion === "number" ? meta.baseVersion : 0) < required) {
|
|
629
|
+
await storage.remove(metaKey).catch(() => void 0);
|
|
630
|
+
await storage.remove(key).catch(() => void 0);
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
621
633
|
const text = await storage.get(key).catch(() => null);
|
|
622
634
|
if (text === null) return null;
|
|
623
635
|
try {
|
|
@@ -726,10 +738,36 @@ function createEditorAutosave(doc, options) {
|
|
|
726
738
|
savedRevision: revisions.savedRevision
|
|
727
739
|
});
|
|
728
740
|
const unsubscribe = revisions.subscribe(() => controller.notify());
|
|
741
|
+
const retireRecovery = async () => {
|
|
742
|
+
await controller.discardRecovery();
|
|
743
|
+
controller.ready();
|
|
744
|
+
await collect();
|
|
745
|
+
};
|
|
729
746
|
return {
|
|
730
747
|
controller,
|
|
731
748
|
revisions,
|
|
732
749
|
checkRecovery: () => controller.checkRecovery(),
|
|
750
|
+
async recoverIfNewer(minimumBaseVersion) {
|
|
751
|
+
const recovery = await controller.checkRecovery(
|
|
752
|
+
minimumBaseVersion !== void 0 ? { minimumBaseVersion } : void 0
|
|
753
|
+
);
|
|
754
|
+
if (!recovery) {
|
|
755
|
+
controller.ready();
|
|
756
|
+
return null;
|
|
757
|
+
}
|
|
758
|
+
if (!recovery.snapshot) {
|
|
759
|
+
await retireRecovery();
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
try {
|
|
763
|
+
const report = doc.loadDocument(recovery.snapshot, { history: "reset" });
|
|
764
|
+
controller.ready();
|
|
765
|
+
return report;
|
|
766
|
+
} catch {
|
|
767
|
+
await retireRecovery();
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
},
|
|
733
771
|
restore(recovery) {
|
|
734
772
|
if (!recovery.snapshot) throw recovery.error ?? new Error("The recovered snapshot could not be read.");
|
|
735
773
|
const report = doc.loadDocument(recovery.snapshot, { history: "reset" });
|
|
@@ -737,9 +775,7 @@ function createEditorAutosave(doc, options) {
|
|
|
737
775
|
return report;
|
|
738
776
|
},
|
|
739
777
|
async discard() {
|
|
740
|
-
await
|
|
741
|
-
controller.ready();
|
|
742
|
-
await collect();
|
|
778
|
+
await retireRecovery();
|
|
743
779
|
},
|
|
744
780
|
async markClean() {
|
|
745
781
|
revisions.markSaved();
|
|
@@ -754,6 +790,289 @@ function createEditorAutosave(doc, options) {
|
|
|
754
790
|
};
|
|
755
791
|
}
|
|
756
792
|
|
|
793
|
+
// src/persistence/remoteSync.ts
|
|
794
|
+
var EditorRemoteConflictError = class extends Error {
|
|
795
|
+
constructor(serverVersion) {
|
|
796
|
+
super(
|
|
797
|
+
serverVersion === void 0 ? "The document changed on the server since it was loaded; local edits were not saved." : `The document is at version ${serverVersion} on the server; local edits were not saved.`
|
|
798
|
+
);
|
|
799
|
+
this.serverVersion = serverVersion;
|
|
800
|
+
this.name = "EditorRemoteConflictError";
|
|
801
|
+
}
|
|
802
|
+
serverVersion;
|
|
803
|
+
};
|
|
804
|
+
var cloneSnapshot = (value) => {
|
|
805
|
+
try {
|
|
806
|
+
return JSON.parse(JSON.stringify(value));
|
|
807
|
+
} catch {
|
|
808
|
+
return value;
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
function createEditorRemoteSync(doc, options) {
|
|
812
|
+
const debounceMs = options.debounceMs ?? 500;
|
|
813
|
+
const now = options.now ?? Date.now;
|
|
814
|
+
let localVersion = options.initialVersion ?? 0;
|
|
815
|
+
let confirmedVersion = localVersion;
|
|
816
|
+
let localSequence = 0;
|
|
817
|
+
let savedSequence = 0;
|
|
818
|
+
let baselineSnapshot = cloneSnapshot(doc.getDocument());
|
|
819
|
+
let savedSnapshot = baselineSnapshot;
|
|
820
|
+
let state = "idle";
|
|
821
|
+
let lastSavedAt = null;
|
|
822
|
+
let lastError = void 0;
|
|
823
|
+
let isApplyingRemote = false;
|
|
824
|
+
let conflictRetries = 0;
|
|
825
|
+
let destroyed = false;
|
|
826
|
+
let debounceTimer = null;
|
|
827
|
+
let inFlightPromise = null;
|
|
828
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
829
|
+
const getStatus = () => ({
|
|
830
|
+
status: state,
|
|
831
|
+
version: localVersion,
|
|
832
|
+
savedVersion: confirmedVersion,
|
|
833
|
+
dirty: localSequence > savedSequence,
|
|
834
|
+
lastSavedAt,
|
|
835
|
+
...lastError !== void 0 ? { error: lastError } : {}
|
|
836
|
+
});
|
|
837
|
+
const emit = () => {
|
|
838
|
+
const currentStatus = getStatus();
|
|
839
|
+
listeners.forEach((listener) => {
|
|
840
|
+
try {
|
|
841
|
+
listener(currentStatus);
|
|
842
|
+
} catch (error) {
|
|
843
|
+
console.error("[remoteSync] Error in status listener:", error);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
const clearTimer = () => {
|
|
848
|
+
if (debounceTimer !== null) {
|
|
849
|
+
clearTimeout(debounceTimer);
|
|
850
|
+
debounceTimer = null;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
const hasChanged = (current, baseline) => {
|
|
854
|
+
if (options.diff) {
|
|
855
|
+
const diff = options.diff(current, baseline);
|
|
856
|
+
const empty = options.isEmptyDiff ? options.isEmptyDiff(diff, current, baseline) : JSON.stringify(current) === JSON.stringify(baseline);
|
|
857
|
+
return { changed: !empty, diff };
|
|
858
|
+
}
|
|
859
|
+
return { changed: JSON.stringify(current) !== JSON.stringify(baseline) };
|
|
860
|
+
};
|
|
861
|
+
const suppressed = (fn) => {
|
|
862
|
+
const wasApplying = isApplyingRemote;
|
|
863
|
+
isApplyingRemote = true;
|
|
864
|
+
try {
|
|
865
|
+
return fn();
|
|
866
|
+
} finally {
|
|
867
|
+
isApplyingRemote = wasApplying;
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
const executeSave = async () => {
|
|
871
|
+
if (inFlightPromise) {
|
|
872
|
+
await inFlightPromise;
|
|
873
|
+
if (localSequence > savedSequence) {
|
|
874
|
+
return executeSave();
|
|
875
|
+
}
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
878
|
+
if (localSequence <= savedSequence) {
|
|
879
|
+
return true;
|
|
880
|
+
}
|
|
881
|
+
clearTimer();
|
|
882
|
+
const targetSequence = localSequence;
|
|
883
|
+
const snapshotToSave = cloneSnapshot(baselineSnapshot);
|
|
884
|
+
const diffToSave = options.diff ? options.diff(snapshotToSave, savedSnapshot) : void 0;
|
|
885
|
+
const versionToSave = Math.max(localVersion, confirmedVersion + 1);
|
|
886
|
+
localVersion = versionToSave;
|
|
887
|
+
state = "saving";
|
|
888
|
+
lastError = void 0;
|
|
889
|
+
emit();
|
|
890
|
+
const run = (async () => {
|
|
891
|
+
try {
|
|
892
|
+
const result = await options.save({
|
|
893
|
+
document: snapshotToSave,
|
|
894
|
+
version: versionToSave,
|
|
895
|
+
baseVersion: confirmedVersion,
|
|
896
|
+
diff: diffToSave
|
|
897
|
+
});
|
|
898
|
+
if (result && typeof result === "object" && result.conflict) {
|
|
899
|
+
const serverVersion = typeof result.version === "number" ? result.version : void 0;
|
|
900
|
+
if (!options.onConflict || conflictRetries >= (options.maxConflictRetries ?? 3)) {
|
|
901
|
+
conflictRetries = 0;
|
|
902
|
+
throw new EditorRemoteConflictError(serverVersion);
|
|
903
|
+
}
|
|
904
|
+
conflictRetries++;
|
|
905
|
+
const resolution = await options.onConflict({
|
|
906
|
+
document: snapshotToSave,
|
|
907
|
+
base: savedSnapshot,
|
|
908
|
+
serverVersion,
|
|
909
|
+
apply: (fn) => suppressed(fn)
|
|
910
|
+
});
|
|
911
|
+
confirmedVersion = resolution.serverVersion;
|
|
912
|
+
localVersion = Math.max(localVersion, confirmedVersion);
|
|
913
|
+
if (resolution.serverDocument !== void 0) savedSnapshot = cloneSnapshot(resolution.serverDocument);
|
|
914
|
+
baselineSnapshot = cloneSnapshot(doc.getDocument());
|
|
915
|
+
localSequence++;
|
|
916
|
+
state = "pending";
|
|
917
|
+
emit();
|
|
918
|
+
return true;
|
|
919
|
+
}
|
|
920
|
+
conflictRetries = 0;
|
|
921
|
+
const returnedVersion = typeof result === "number" ? result : result && typeof result === "object" && typeof result.version === "number" ? result.version : versionToSave;
|
|
922
|
+
confirmedVersion = Math.max(confirmedVersion, versionToSave, returnedVersion);
|
|
923
|
+
if (returnedVersion > localVersion) {
|
|
924
|
+
localVersion = returnedVersion;
|
|
925
|
+
}
|
|
926
|
+
savedSequence = Math.max(savedSequence, targetSequence);
|
|
927
|
+
savedSnapshot = snapshotToSave;
|
|
928
|
+
lastSavedAt = now();
|
|
929
|
+
lastError = void 0;
|
|
930
|
+
if (localSequence <= savedSequence) {
|
|
931
|
+
state = "saved";
|
|
932
|
+
try {
|
|
933
|
+
await options.autosave?.markClean();
|
|
934
|
+
} catch (error) {
|
|
935
|
+
console.error("[remoteSync] autosave.markClean failed:", error);
|
|
936
|
+
}
|
|
937
|
+
} else {
|
|
938
|
+
state = "pending";
|
|
939
|
+
}
|
|
940
|
+
options.onSaved?.({ document: snapshotToSave, version: confirmedVersion });
|
|
941
|
+
emit();
|
|
942
|
+
return true;
|
|
943
|
+
} catch (error) {
|
|
944
|
+
lastError = error;
|
|
945
|
+
state = "error";
|
|
946
|
+
options.onError?.(error);
|
|
947
|
+
emit();
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
})();
|
|
951
|
+
inFlightPromise = run;
|
|
952
|
+
let ok;
|
|
953
|
+
try {
|
|
954
|
+
ok = await run;
|
|
955
|
+
} finally {
|
|
956
|
+
if (inFlightPromise === run) inFlightPromise = null;
|
|
957
|
+
}
|
|
958
|
+
if (ok && localSequence > savedSequence && debounceTimer === null) {
|
|
959
|
+
return executeSave();
|
|
960
|
+
}
|
|
961
|
+
return ok;
|
|
962
|
+
};
|
|
963
|
+
const scheduleSave = () => {
|
|
964
|
+
clearTimer();
|
|
965
|
+
if (debounceMs <= 0) {
|
|
966
|
+
void executeSave();
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
debounceTimer = setTimeout(() => {
|
|
970
|
+
debounceTimer = null;
|
|
971
|
+
if (!destroyed) {
|
|
972
|
+
void executeSave();
|
|
973
|
+
}
|
|
974
|
+
}, debounceMs);
|
|
975
|
+
};
|
|
976
|
+
const notify = () => {
|
|
977
|
+
if (isApplyingRemote || destroyed) return false;
|
|
978
|
+
const current = cloneSnapshot(doc.getDocument());
|
|
979
|
+
const { changed, diff } = hasChanged(current, baselineSnapshot);
|
|
980
|
+
if (!changed) return false;
|
|
981
|
+
const previousBaseline = baselineSnapshot;
|
|
982
|
+
baselineSnapshot = current;
|
|
983
|
+
localSequence++;
|
|
984
|
+
localVersion = Math.max(localVersion, confirmedVersion) + 1;
|
|
985
|
+
if (state !== "saving") {
|
|
986
|
+
state = "pending";
|
|
987
|
+
}
|
|
988
|
+
emit();
|
|
989
|
+
options.onLocalChange?.({
|
|
990
|
+
document: current,
|
|
991
|
+
baseline: previousBaseline,
|
|
992
|
+
diff,
|
|
993
|
+
version: localVersion
|
|
994
|
+
});
|
|
995
|
+
scheduleSave();
|
|
996
|
+
return true;
|
|
997
|
+
};
|
|
998
|
+
const flush = async () => {
|
|
999
|
+
clearTimer();
|
|
1000
|
+
notify();
|
|
1001
|
+
if (localSequence <= savedSequence && !inFlightPromise) {
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
return executeSave();
|
|
1005
|
+
};
|
|
1006
|
+
const unsubscribeDoc = doc.subscribe(() => {
|
|
1007
|
+
notify();
|
|
1008
|
+
});
|
|
1009
|
+
return {
|
|
1010
|
+
version: () => localVersion,
|
|
1011
|
+
savedVersion: () => confirmedVersion,
|
|
1012
|
+
dirty: () => localSequence > savedSequence,
|
|
1013
|
+
status: getStatus,
|
|
1014
|
+
baseline: () => baselineSnapshot,
|
|
1015
|
+
notify,
|
|
1016
|
+
applyRemote(fn, remoteVersion) {
|
|
1017
|
+
const wasApplying = isApplyingRemote;
|
|
1018
|
+
const wasDirty = localSequence > savedSequence;
|
|
1019
|
+
isApplyingRemote = true;
|
|
1020
|
+
try {
|
|
1021
|
+
const result = fn();
|
|
1022
|
+
baselineSnapshot = cloneSnapshot(doc.getDocument());
|
|
1023
|
+
if (typeof remoteVersion === "number" && Number.isFinite(remoteVersion)) {
|
|
1024
|
+
confirmedVersion = Math.max(confirmedVersion, remoteVersion);
|
|
1025
|
+
localVersion = Math.max(localVersion, remoteVersion);
|
|
1026
|
+
}
|
|
1027
|
+
if (!wasDirty) {
|
|
1028
|
+
savedSequence = localSequence;
|
|
1029
|
+
savedSnapshot = baselineSnapshot;
|
|
1030
|
+
}
|
|
1031
|
+
emit();
|
|
1032
|
+
return result;
|
|
1033
|
+
} finally {
|
|
1034
|
+
isApplyingRemote = wasApplying;
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
1037
|
+
resetBaseline(remoteVersion) {
|
|
1038
|
+
clearTimer();
|
|
1039
|
+
baselineSnapshot = cloneSnapshot(doc.getDocument());
|
|
1040
|
+
savedSnapshot = baselineSnapshot;
|
|
1041
|
+
if (typeof remoteVersion === "number" && Number.isFinite(remoteVersion)) {
|
|
1042
|
+
localVersion = remoteVersion;
|
|
1043
|
+
confirmedVersion = remoteVersion;
|
|
1044
|
+
}
|
|
1045
|
+
savedSequence = localSequence;
|
|
1046
|
+
lastError = void 0;
|
|
1047
|
+
state = "idle";
|
|
1048
|
+
emit();
|
|
1049
|
+
},
|
|
1050
|
+
flush,
|
|
1051
|
+
async whenIdle() {
|
|
1052
|
+
while (debounceTimer !== null || inFlightPromise) {
|
|
1053
|
+
if (debounceTimer !== null) {
|
|
1054
|
+
await flush();
|
|
1055
|
+
} else if (inFlightPromise) {
|
|
1056
|
+
await inFlightPromise.catch(() => false);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
},
|
|
1060
|
+
subscribe(listener) {
|
|
1061
|
+
listeners.add(listener);
|
|
1062
|
+
listener(getStatus());
|
|
1063
|
+
return () => {
|
|
1064
|
+
listeners.delete(listener);
|
|
1065
|
+
};
|
|
1066
|
+
},
|
|
1067
|
+
destroy() {
|
|
1068
|
+
destroyed = true;
|
|
1069
|
+
clearTimer();
|
|
1070
|
+
unsubscribeDoc();
|
|
1071
|
+
listeners.clear();
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
|
|
757
1076
|
// src/persistence/documentStore.ts
|
|
758
1077
|
function slugifyDocumentName(name) {
|
|
759
1078
|
const slug = name.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
@@ -1067,6 +1386,8 @@ export {
|
|
|
1067
1386
|
createAutosaveController,
|
|
1068
1387
|
createRevisionTracker,
|
|
1069
1388
|
createEditorAutosave,
|
|
1389
|
+
EditorRemoteConflictError,
|
|
1390
|
+
createEditorRemoteSync,
|
|
1070
1391
|
slugifyDocumentName,
|
|
1071
1392
|
createEditorDocumentStore,
|
|
1072
1393
|
createDocumentToolProvider
|
|
@@ -21,6 +21,8 @@ export interface RecoveryMeta {
|
|
|
21
21
|
time?: number;
|
|
22
22
|
/** Document name, for the "Restore unsaved changes from …?" prompt. */
|
|
23
23
|
name?: string;
|
|
24
|
+
/** The server / host version the edits in the snapshot were made on (`baseVersion` option). */
|
|
25
|
+
baseVersion?: number;
|
|
24
26
|
}
|
|
25
27
|
export interface AutosaveRecovery<T = unknown> {
|
|
26
28
|
/** The parsed snapshot (`undefined` when `deserialize` threw; see `error`). */
|
|
@@ -65,6 +67,18 @@ export interface AutosaveControllerOptions<T> {
|
|
|
65
67
|
clearTimeout?: (handle: any) => void;
|
|
66
68
|
/** Start hydrated, i.e. as if `ready()` was already called (default `false`). */
|
|
67
69
|
ready?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The server / host version of the document that is loaded now. It is stored in each
|
|
72
|
+
* snapshot's meta, and `checkRecovery` retires (deletes and does not return) a snapshot whose
|
|
73
|
+
* edits were made on an older version, so it never overwrites newer server state. A snapshot
|
|
74
|
+
* without a stored version counts as version 0.
|
|
75
|
+
*/
|
|
76
|
+
baseVersion?: number | (() => number | undefined);
|
|
77
|
+
}
|
|
78
|
+
/** Options for `AutosaveController.checkRecovery`. */
|
|
79
|
+
export interface CheckRecoveryOptions {
|
|
80
|
+
/** Retire snapshots made on a version older than this (default the `baseVersion` option). */
|
|
81
|
+
minimumBaseVersion?: number;
|
|
68
82
|
}
|
|
69
83
|
export interface AutosaveController<T = unknown> {
|
|
70
84
|
/** Current status. */
|
|
@@ -91,7 +105,7 @@ export interface AutosaveController<T = unknown> {
|
|
|
91
105
|
* A dirty snapshot left by an earlier session, or `null`. Returns `null` once
|
|
92
106
|
* this session has written its own snapshot.
|
|
93
107
|
*/
|
|
94
|
-
checkRecovery(): Promise<AutosaveRecovery<T> | null>;
|
|
108
|
+
checkRecovery(options?: CheckRecoveryOptions): Promise<AutosaveRecovery<T> | null>;
|
|
95
109
|
/** Deletes an earlier session's snapshot. No-op once this session wrote its own. */
|
|
96
110
|
discardRecovery(): Promise<boolean>;
|
|
97
111
|
/** Runs one scheduling step now (normally driven by `notify` and timers). */
|
|
@@ -21,6 +21,8 @@ export interface RecoveryMeta {
|
|
|
21
21
|
time?: number;
|
|
22
22
|
/** Document name, for the "Restore unsaved changes from …?" prompt. */
|
|
23
23
|
name?: string;
|
|
24
|
+
/** The server / host version the edits in the snapshot were made on (`baseVersion` option). */
|
|
25
|
+
baseVersion?: number;
|
|
24
26
|
}
|
|
25
27
|
export interface AutosaveRecovery<T = unknown> {
|
|
26
28
|
/** The parsed snapshot (`undefined` when `deserialize` threw; see `error`). */
|
|
@@ -65,6 +67,18 @@ export interface AutosaveControllerOptions<T> {
|
|
|
65
67
|
clearTimeout?: (handle: any) => void;
|
|
66
68
|
/** Start hydrated, i.e. as if `ready()` was already called (default `false`). */
|
|
67
69
|
ready?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The server / host version of the document that is loaded now. It is stored in each
|
|
72
|
+
* snapshot's meta, and `checkRecovery` retires (deletes and does not return) a snapshot whose
|
|
73
|
+
* edits were made on an older version, so it never overwrites newer server state. A snapshot
|
|
74
|
+
* without a stored version counts as version 0.
|
|
75
|
+
*/
|
|
76
|
+
baseVersion?: number | (() => number | undefined);
|
|
77
|
+
}
|
|
78
|
+
/** Options for `AutosaveController.checkRecovery`. */
|
|
79
|
+
export interface CheckRecoveryOptions {
|
|
80
|
+
/** Retire snapshots made on a version older than this (default the `baseVersion` option). */
|
|
81
|
+
minimumBaseVersion?: number;
|
|
68
82
|
}
|
|
69
83
|
export interface AutosaveController<T = unknown> {
|
|
70
84
|
/** Current status. */
|
|
@@ -91,7 +105,7 @@ export interface AutosaveController<T = unknown> {
|
|
|
91
105
|
* A dirty snapshot left by an earlier session, or `null`. Returns `null` once
|
|
92
106
|
* this session has written its own snapshot.
|
|
93
107
|
*/
|
|
94
|
-
checkRecovery(): Promise<AutosaveRecovery<T> | null>;
|
|
108
|
+
checkRecovery(options?: CheckRecoveryOptions): Promise<AutosaveRecovery<T> | null>;
|
|
95
109
|
/** Deletes an earlier session's snapshot. No-op once this session wrote its own. */
|
|
96
110
|
discardRecovery(): Promise<boolean>;
|
|
97
111
|
/** Runs one scheduling step now (normally driven by `notify` and timers). */
|
|
@@ -11,6 +11,12 @@ export interface EditorAutosaveOptions extends Omit<AutosaveControllerOptions<Ed
|
|
|
11
11
|
* saved state needs no snapshot. Without it, every change counts until `markClean()`.
|
|
12
12
|
*/
|
|
13
13
|
dirty?: DirtyFlagSource;
|
|
14
|
+
/**
|
|
15
|
+
* The server / host version of the loaded document, stored with each snapshot.
|
|
16
|
+
* `checkRecovery` / `recoverIfNewer` retire snapshots made on an older version instead of
|
|
17
|
+
* offering them (see `AutosaveControllerOptions.baseVersion`).
|
|
18
|
+
*/
|
|
19
|
+
baseVersion?: number | (() => number | undefined);
|
|
14
20
|
/**
|
|
15
21
|
* For documents with `assets`: after `markClean` or `discard` retire a snapshot, delete the
|
|
16
22
|
* stored assets nothing refers to any more (`collectEditorAssetGarbage`, best effort, keeping
|
|
@@ -21,8 +27,13 @@ export interface EditorAutosaveOptions extends Omit<AutosaveControllerOptions<Ed
|
|
|
21
27
|
export interface EditorAutosave {
|
|
22
28
|
readonly controller: AutosaveController<EditorDocumentFile>;
|
|
23
29
|
readonly revisions: RevisionTracker;
|
|
24
|
-
/** An earlier session's unsaved snapshot of this document, or `null
|
|
30
|
+
/** An earlier session's unsaved snapshot of this document, or `null` (snapshots made on a version older than `baseVersion` are retired). */
|
|
25
31
|
checkRecovery(): Promise<AutosaveRecovery<EditorDocumentFile> | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks for an earlier session's unsaved snapshot, restoring it into `doc` if it is valid and
|
|
34
|
+
* at least as new as `baseVersion`, or retiring it and starting autosave cleanly if stale/invalid.
|
|
35
|
+
*/
|
|
36
|
+
recoverIfNewer(minimumBaseVersion?: number): Promise<LoadReport | null>;
|
|
26
37
|
/** Loads a recovered snapshot into the document and starts autosaving. */
|
|
27
38
|
restore(recovery: AutosaveRecovery<EditorDocumentFile>): LoadReport;
|
|
28
39
|
/** Deletes the earlier session's snapshot and starts autosaving. */
|
|
@@ -11,6 +11,12 @@ export interface EditorAutosaveOptions extends Omit<AutosaveControllerOptions<Ed
|
|
|
11
11
|
* saved state needs no snapshot. Without it, every change counts until `markClean()`.
|
|
12
12
|
*/
|
|
13
13
|
dirty?: DirtyFlagSource;
|
|
14
|
+
/**
|
|
15
|
+
* The server / host version of the loaded document, stored with each snapshot.
|
|
16
|
+
* `checkRecovery` / `recoverIfNewer` retire snapshots made on an older version instead of
|
|
17
|
+
* offering them (see `AutosaveControllerOptions.baseVersion`).
|
|
18
|
+
*/
|
|
19
|
+
baseVersion?: number | (() => number | undefined);
|
|
14
20
|
/**
|
|
15
21
|
* For documents with `assets`: after `markClean` or `discard` retire a snapshot, delete the
|
|
16
22
|
* stored assets nothing refers to any more (`collectEditorAssetGarbage`, best effort, keeping
|
|
@@ -21,8 +27,13 @@ export interface EditorAutosaveOptions extends Omit<AutosaveControllerOptions<Ed
|
|
|
21
27
|
export interface EditorAutosave {
|
|
22
28
|
readonly controller: AutosaveController<EditorDocumentFile>;
|
|
23
29
|
readonly revisions: RevisionTracker;
|
|
24
|
-
/** An earlier session's unsaved snapshot of this document, or `null
|
|
30
|
+
/** An earlier session's unsaved snapshot of this document, or `null` (snapshots made on a version older than `baseVersion` are retired). */
|
|
25
31
|
checkRecovery(): Promise<AutosaveRecovery<EditorDocumentFile> | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks for an earlier session's unsaved snapshot, restoring it into `doc` if it is valid and
|
|
34
|
+
* at least as new as `baseVersion`, or retiring it and starting autosave cleanly if stale/invalid.
|
|
35
|
+
*/
|
|
36
|
+
recoverIfNewer(minimumBaseVersion?: number): Promise<LoadReport | null>;
|
|
26
37
|
/** Loads a recovered snapshot into the document and starts autosaving. */
|
|
27
38
|
restore(recovery: AutosaveRecovery<EditorDocumentFile>): LoadReport;
|
|
28
39
|
/** Deletes the earlier session's snapshot and starts autosaving. */
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunkDK33HLA2cjs = require('../chunk-DK33HLA2.cjs');
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
|
|
@@ -92,4 +94,6 @@ require('../chunk-2BSBFBOA.cjs');
|
|
|
92
94
|
|
|
93
95
|
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
exports.EDITOR_ASSET_PREFIX = _chunkSJ2CPTQCcjs.EDITOR_ASSET_PREFIX; exports.EDITOR_DOCUMENT_FORMAT = _chunkSJ2CPTQCcjs.EDITOR_DOCUMENT_FORMAT; exports.EditorDocumentLoadError = _chunkSJ2CPTQCcjs.EditorDocumentLoadError; exports.EditorRemoteConflictError = _chunkDK33HLA2cjs.EditorRemoteConflictError; exports.InjectedStorageError = _chunkDK33HLA2cjs.InjectedStorageError; exports.StorageUnavailableError = _chunkDK33HLA2cjs.StorageUnavailableError; exports.collectAssetRefs = _chunkSJ2CPTQCcjs.collectAssetRefs; exports.collectEditorAssetGarbage = _chunkSJ2CPTQCcjs.collectEditorAssetGarbage; exports.collectRetiredEditorAssets = _chunkSJ2CPTQCcjs.collectRetiredEditorAssets; exports.createAutosaveController = _chunkDK33HLA2cjs.createAutosaveController; exports.createDocumentToolProvider = _chunkDK33HLA2cjs.createDocumentToolProvider; exports.createEditorAssetRegistry = _chunkSJ2CPTQCcjs.createEditorAssetRegistry; exports.createEditorAutosave = _chunkDK33HLA2cjs.createEditorAutosave; exports.createEditorDocumentStore = _chunkDK33HLA2cjs.createEditorDocumentStore; exports.createEditorRemoteSync = _chunkDK33HLA2cjs.createEditorRemoteSync; exports.createIndexedDbAdapter = _chunkDK33HLA2cjs.createIndexedDbAdapter; exports.createLoadReport = _chunkSJ2CPTQCcjs.createLoadReport; exports.createLocalStorageAdapter = _chunkDK33HLA2cjs.createLocalStorageAdapter; exports.createMemoryStorage = _chunkDK33HLA2cjs.createMemoryStorage; exports.createOpfsAdapter = _chunkDK33HLA2cjs.createOpfsAdapter; exports.createRecoveryPolicy = _chunkDK33HLA2cjs.createRecoveryPolicy; exports.createRevisionTracker = _chunkDK33HLA2cjs.createRevisionTracker; exports.defineEditorDocument = _chunkSJ2CPTQCcjs.defineEditorDocument; exports.exponentialBackoff = _chunkDK33HLA2cjs.exponentialBackoff; exports.externalizeAssets = _chunkSJ2CPTQCcjs.externalizeAssets; exports.formatRecoveryMessage = _chunkDK33HLA2cjs.formatRecoveryMessage; exports.hasLoadProblems = _chunkSJ2CPTQCcjs.hasLoadProblems; exports.internalizeAssets = _chunkSJ2CPTQCcjs.internalizeAssets; exports.isEditorDocumentFile = _chunkSJ2CPTQCcjs.isEditorDocumentFile; exports.isIndexedDbAvailable = _chunkDK33HLA2cjs.isIndexedDbAvailable; exports.isInlineAsset = _chunkSJ2CPTQCcjs.isInlineAsset; exports.isLocalStorageAvailable = _chunkDK33HLA2cjs.isLocalStorageAvailable; exports.isOpfsAvailable = _chunkDK33HLA2cjs.isOpfsAvailable; exports.loadDocument = _chunkSJ2CPTQCcjs.loadDocument; exports.loadSections = _chunkSJ2CPTQCcjs.loadSections; exports.migrateDocument = _chunkSJ2CPTQCcjs.migrateDocument; exports.parseEditorDocument = _chunkSJ2CPTQCcjs.parseEditorDocument; exports.persistEditorAssets = _chunkSJ2CPTQCcjs.persistEditorAssets; exports.preloadEditorAssets = _chunkSJ2CPTQCcjs.preloadEditorAssets; exports.recoveryMetaKey = _chunkDK33HLA2cjs.recoveryMetaKey; exports.serializeEditorDocument = _chunkSJ2CPTQCcjs.serializeEditorDocument; exports.slugifyDocumentName = _chunkDK33HLA2cjs.slugifyDocumentName; exports.toEditorDocumentFile = _chunkSJ2CPTQCcjs.toEditorDocumentFile; exports.tryCollectEditorAssetGarbage = _chunkSJ2CPTQCcjs.tryCollectEditorAssetGarbage; exports.withEditorAssets = _chunkSJ2CPTQCcjs.withEditorAssets; exports.withStorageFailures = _chunkDK33HLA2cjs.withStorageFailures;
|
|
@@ -5,6 +5,7 @@ export * from "./migrate.cjs";
|
|
|
5
5
|
export * from "./revisions.cjs";
|
|
6
6
|
export * from "./editorDocument.cjs";
|
|
7
7
|
export * from "./editorAutosave.cjs";
|
|
8
|
+
export * from "./remoteSync.cjs";
|
|
8
9
|
export * from "./documentStore.cjs";
|
|
9
10
|
export * from "./documentTools.cjs";
|
|
10
11
|
export * from "./assets.cjs";
|
|
@@ -5,6 +5,7 @@ export * from "./migrate.js";
|
|
|
5
5
|
export * from "./revisions.js";
|
|
6
6
|
export * from "./editorDocument.js";
|
|
7
7
|
export * from "./editorAutosave.js";
|
|
8
|
+
export * from "./remoteSync.js";
|
|
8
9
|
export * from "./documentStore.js";
|
|
9
10
|
export * from "./documentTools.js";
|
|
10
11
|
export * from "./assets.js";
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
EditorRemoteConflictError,
|
|
2
3
|
InjectedStorageError,
|
|
3
4
|
StorageUnavailableError,
|
|
4
5
|
createAutosaveController,
|
|
5
6
|
createDocumentToolProvider,
|
|
6
7
|
createEditorAutosave,
|
|
7
8
|
createEditorDocumentStore,
|
|
9
|
+
createEditorRemoteSync,
|
|
8
10
|
createIndexedDbAdapter,
|
|
9
11
|
createLocalStorageAdapter,
|
|
10
12
|
createMemoryStorage,
|
|
@@ -19,7 +21,7 @@ import {
|
|
|
19
21
|
recoveryMetaKey,
|
|
20
22
|
slugifyDocumentName,
|
|
21
23
|
withStorageFailures
|
|
22
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-KBH6CM3U.js";
|
|
23
25
|
import {
|
|
24
26
|
EDITOR_ASSET_PREFIX,
|
|
25
27
|
EDITOR_DOCUMENT_FORMAT,
|
|
@@ -51,6 +53,7 @@ export {
|
|
|
51
53
|
EDITOR_ASSET_PREFIX,
|
|
52
54
|
EDITOR_DOCUMENT_FORMAT,
|
|
53
55
|
EditorDocumentLoadError,
|
|
56
|
+
EditorRemoteConflictError,
|
|
54
57
|
InjectedStorageError,
|
|
55
58
|
StorageUnavailableError,
|
|
56
59
|
collectAssetRefs,
|
|
@@ -61,6 +64,7 @@ export {
|
|
|
61
64
|
createEditorAssetRegistry,
|
|
62
65
|
createEditorAutosave,
|
|
63
66
|
createEditorDocumentStore,
|
|
67
|
+
createEditorRemoteSync,
|
|
64
68
|
createIndexedDbAdapter,
|
|
65
69
|
createLoadReport,
|
|
66
70
|
createLocalStorageAdapter,
|