@gramps-connect/story 0.5.0 → 0.6.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/README.md +1 -1
- package/dist/editor.js.map +2 -2
- package/dist/types/editor/model.d.ts +12 -11
- package/package.json +1 -1
- package/src/editor/model.ts +12 -11
|
@@ -79,18 +79,19 @@ export declare function pruneMedia(doc: StoryDoc, files: Map<string, Uint8Array>
|
|
|
79
79
|
/** "Josef Meyer" -> "Josef Meyer.story.zip", minus characters some file
|
|
80
80
|
* systems refuse. */
|
|
81
81
|
export declare function storyFileName(title: string): string;
|
|
82
|
-
/** Undo and redo over whole documents
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
/** Undo and redo over whole documents (a StoryDoc here; any value that's
|
|
83
|
+
* replaced, never changed in place, works). Typing in one field makes one
|
|
84
|
+
* step, not one per keystroke: a change with the same `key` within
|
|
85
|
+
* COALESCE_MS of the last replaces it. */
|
|
86
|
+
export interface History<T = StoryDoc> {
|
|
87
|
+
past: T[];
|
|
88
|
+
present: T;
|
|
89
|
+
future: T[];
|
|
89
90
|
lastKey?: string;
|
|
90
91
|
lastAt?: number;
|
|
91
92
|
}
|
|
92
93
|
export declare const COALESCE_MS = 1500;
|
|
93
|
-
export declare function startHistory(doc:
|
|
94
|
-
export declare function record(history: History
|
|
95
|
-
export declare function undo(history: History): History
|
|
96
|
-
export declare function redo(history: History): History
|
|
94
|
+
export declare function startHistory<T = StoryDoc>(doc: T): History<T>;
|
|
95
|
+
export declare function record<T>(history: History<T>, next: T, key?: string, now?: number): History<T>;
|
|
96
|
+
export declare function undo<T>(history: History<T>): History<T>;
|
|
97
|
+
export declare function redo<T>(history: History<T>): History<T>;
|
package/package.json
CHANGED
package/src/editor/model.ts
CHANGED
|
@@ -228,13 +228,14 @@ export function storyFileName(title: string): string {
|
|
|
228
228
|
return `${safe || "story"}.story.zip`;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
/** Undo and redo over whole documents
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
/** Undo and redo over whole documents (a StoryDoc here; any value that's
|
|
232
|
+
* replaced, never changed in place, works). Typing in one field makes one
|
|
233
|
+
* step, not one per keystroke: a change with the same `key` within
|
|
234
|
+
* COALESCE_MS of the last replaces it. */
|
|
235
|
+
export interface History<T = StoryDoc> {
|
|
236
|
+
past: T[];
|
|
237
|
+
present: T;
|
|
238
|
+
future: T[];
|
|
238
239
|
lastKey?: string;
|
|
239
240
|
lastAt?: number;
|
|
240
241
|
}
|
|
@@ -242,24 +243,24 @@ export interface History {
|
|
|
242
243
|
export const COALESCE_MS = 1500;
|
|
243
244
|
const MAX_STEPS = 200;
|
|
244
245
|
|
|
245
|
-
export function startHistory(doc:
|
|
246
|
+
export function startHistory<T = StoryDoc>(doc: T): History<T> {
|
|
246
247
|
return { past: [], present: doc, future: [] };
|
|
247
248
|
}
|
|
248
249
|
|
|
249
|
-
export function record(history: History
|
|
250
|
+
export function record<T>(history: History<T>, next: T, key?: string, now = Date.now()): History<T> {
|
|
250
251
|
if (next === history.present) return history;
|
|
251
252
|
const coalesce = key !== undefined && key === history.lastKey && history.lastAt !== undefined && now - history.lastAt < COALESCE_MS;
|
|
252
253
|
const past = coalesce ? history.past : [...history.past, history.present].slice(-MAX_STEPS);
|
|
253
254
|
return { past, present: next, future: [], lastKey: key, lastAt: now };
|
|
254
255
|
}
|
|
255
256
|
|
|
256
|
-
export function undo(history: History): History {
|
|
257
|
+
export function undo<T>(history: History<T>): History<T> {
|
|
257
258
|
const previous = history.past[history.past.length - 1];
|
|
258
259
|
if (!previous) return history;
|
|
259
260
|
return { past: history.past.slice(0, -1), present: previous, future: [history.present, ...history.future] };
|
|
260
261
|
}
|
|
261
262
|
|
|
262
|
-
export function redo(history: History): History {
|
|
263
|
+
export function redo<T>(history: History<T>): History<T> {
|
|
263
264
|
const [next, ...future] = history.future;
|
|
264
265
|
if (!next) return history;
|
|
265
266
|
return { past: [...history.past, history.present], present: next, future };
|