@infinite-canvas-tutorial/webcomponents
Version:
WebComponents UI implementation
59 lines • 2.12 kB
JavaScript
/**
* Borrow from https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/change.ts#L399
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppStateChange = void 0;
const Delta_1 = require("./Delta");
class AppStateChange {
constructor(delta) {
this.delta = delta;
}
static empty() {
return new AppStateChange(Delta_1.Delta.create({}, {}));
}
static calculate(prevAppState, nextAppState) {
const delta = Delta_1.Delta.calculate(prevAppState, nextAppState, undefined);
return new AppStateChange(delta);
}
// private static postProcess<T extends ObservedAppState>(
// deleted: Partial<T>,
// inserted: Partial<T>,
// ): [Partial<T>, Partial<T>] {
// try {
// Delta.diffObjects(
// deleted,
// inserted,
// "selectedElementIds",
// // ts language server has a bit trouble resolving this, so we are giving it a little push
// (_) => true as ValueOf<T["selectedElementIds"]>,
// );
// Delta.diffObjects(
// deleted,
// inserted,
// "selectedGroupIds",
// (prevValue) => (prevValue ?? false) as ValueOf<T["selectedGroupIds"]>,
// );
// } catch (e) {
// // if postprocessing fails it does not make sense to bubble up, but let's make sure we know about it
// console.error(`Couldn't postprocess appstate change deltas.`);
// } finally {
// return [deleted, inserted];
// }
// }
inverse() {
const inversedDelta = Delta_1.Delta.create(this.delta.inserted, this.delta.deleted);
return new AppStateChange(inversedDelta);
}
applyTo(appState, nextElements) {
// TODO: selected elements
console.log('applyTo', appState);
const nextAppState = Object.assign({}, appState);
return [nextAppState, false];
}
isEmpty() {
return Delta_1.Delta.isEmpty(this.delta);
}
}
exports.AppStateChange = AppStateChange;
//# sourceMappingURL=AppStateChange.js.map
;