delta-component
Version:
embeddable react component
43 lines (33 loc) • 1.16 kB
JavaScript
import { documents } from './helpers';
function _tick(waitMsec) {
return new Promise(function (resolve) {
setTimeout(function () {
resolve();
}, waitMsec)
})
}
async function playHistory(history, stepMsec=200) {
const timeline = await history.getTimelineOfChanges();
for (const date of timeline) {
await _tick(stepMsec);
await history.rewindTo(date);
};
}
export function historicalDocument() {
const doc = documents()[0];
const history = doc.getHistory();
window.myeditor.onExternalDocumentLocked(() => {});
window.myeditor.setActiveDocument(history);
history.getTimelineOfChanges().then(timeline => {
window.mydoc = doc;
window.myHistory = history;
window.mytimeline = timeline;
window.playThisDocHistory = function() {
return playHistory(history, 100).catch(error => alert(error));
};
playHistory(history, 100).catch(error => alert(error));
});
}
historicalDocument.keyToBind = 'W';
historicalDocument.description = 'Поработать с историей документов';
;