import { type as assertType } from "@heydovetail/assert"; import { Node, Schema } from "prosemirror-model"; import { Mapping, Step, StepMap, StepResult } from "prosemirror-transform"; import { Range } from "./types"; interface RangeSetAttrsJson { stepType: "range.setAttrs"; id: Range["id"]; type: Range["type"]; prev: Range["attrs"]; curr: Range["attrs"]; } export class RangeSetAttrsStep extends Step { constructor(public readonly id: Range["id"], public readonly type: Range["type"], public readonly prev: Range["attrs"], public readonly curr: Range["attrs"]) { super(); } public apply(doc: Node) { return StepResult.ok(doc); } public getMap() { return new StepMap([]); } public invert() { return new RangeSetAttrsStep(this.id, this.type, this.curr, this.prev); } public map(_: Mapping) { return new RangeSetAttrsStep(this.id, this.type, this.prev, this.curr); } public merge() { return null; } public toJSON(): RangeSetAttrsJson { return { stepType: "range.setAttrs", id: this.id, type: this.type, prev: this.prev, curr: this.curr }; } public static fromJSON(_: Schema, json: RangeSetAttrsJson): RangeSetAttrsStep { return new RangeSetAttrsStep(json.id, json.type, json.prev, json.curr); } } Step.jsonID(assertType("range.setAttrs"), RangeSetAttrsStep);