@@ -31,13 +31,14 @@ export default function (
31
31
32
32
for ( const step of steps ) {
33
33
//console.log(step)
34
- if ( isAddMarkStep ( step ) ) {
35
- unappliedMarks . push ( step )
34
+ const stepId = step . toJSON ( ) [ "stepType" ]
35
+ if ( stepId === "addMark" ) {
36
+ unappliedMarks . push ( step as AddMarkStep )
36
37
continue
37
38
} else {
38
39
flushMarks ( )
39
40
}
40
- oneStep ( spans , step , doc , pmDoc , path )
41
+ oneStep ( spans , stepId , step , doc , pmDoc , path )
41
42
const nextDoc = step . apply ( pmDoc ) . doc
42
43
if ( nextDoc == null ) {
43
44
throw new Error ( "Could not apply step to document" )
@@ -50,41 +51,22 @@ export default function (
50
51
51
52
function oneStep (
52
53
spans : am . Span [ ] ,
54
+ stepId : string ,
53
55
step : Step ,
54
56
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55
57
doc : any ,
56
58
pmDoc : Node ,
57
59
path : Prop [ ] ,
58
60
) {
59
- // This shenanigans with the constructor name is necessary for reasons I
60
- // don't really understand. I _think_ that the `*Step` classs we get
61
- // passed here can be slightly different to the classes we've imported if the
62
- // dependencies are messed up
63
- if (
64
- step . constructor . name === "ReplaceStep" ||
65
- step . constructor . name === "_ReplaceStep"
66
- ) {
61
+ if ( stepId === "replace" ) {
67
62
replaceStep ( spans , step as ReplaceStep , doc , path , pmDoc )
68
- } else if (
69
- step . constructor . name === "ReplaceAroundStep" ||
70
- step . constructor . name === "_ReplaceAroundStep"
71
- ) {
63
+ } else if ( stepId === "replaceAround" ) {
72
64
replaceAroundStep ( step as ReplaceAroundStep , doc , pmDoc , path )
73
- } else if (
74
- step . constructor . name === "RemoveMarkStep" ||
75
- step . constructor . name === "_RemoveMarkStep"
76
- ) {
65
+ } else if ( stepId === "removeMark" ) {
77
66
removeMarkStep ( spans , step as RemoveMarkStep , doc , path )
78
67
}
79
68
}
80
69
81
- function isAddMarkStep ( step : Step ) : step is AddMarkStep {
82
- return (
83
- step . constructor . name === "AddMarkStep" ||
84
- step . constructor . name === "_AddMarkStep"
85
- )
86
- }
87
-
88
70
// eslint-disable-next-line @typescript-eslint/no-explicit-any
89
71
function replaceStep (
90
72
spans : am . Span [ ] ,
0 commit comments