@thomasfosterau/effect-richtext 0.0.0 → 0.1.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/LICENSE +48 -0
- package/README.md +117 -1
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/commands/commands.d.ts +323 -0
- package/dist/commands/commands.js +722 -0
- package/dist/commands/internal.js +43 -0
- package/dist/commands/keymaps.d.ts +46 -0
- package/dist/commands/keymaps.js +64 -0
- package/dist/commands.d.ts +3 -0
- package/dist/commands.js +3 -0
- package/dist/compat/commands.d.ts +250 -0
- package/dist/compat/commands.js +275 -0
- package/dist/compat/internal/core.d.ts +20 -0
- package/dist/compat/internal/core.js +148 -0
- package/dist/compat/internal/props.js +82 -0
- package/dist/compat/keymap.d.ts +21 -0
- package/dist/compat/keymap.js +38 -0
- package/dist/compat/model.d.ts +893 -0
- package/dist/compat/model.js +1212 -0
- package/dist/compat/orderedmap.d.ts +74 -0
- package/dist/compat/orderedmap.js +124 -0
- package/dist/compat/schema-basic.d.ts +38 -0
- package/dist/compat/schema-basic.js +238 -0
- package/dist/compat/schema-list.d.ts +81 -0
- package/dist/compat/schema-list.js +156 -0
- package/dist/compat/state.d.ts +415 -0
- package/dist/compat/state.js +689 -0
- package/dist/compat/test-builder.d.ts +98 -0
- package/dist/compat/test-builder.js +197 -0
- package/dist/compat/transform.d.ts +458 -0
- package/dist/compat/transform.js +803 -0
- package/dist/compat/view.d.ts +411 -0
- package/dist/compat/view.js +409 -0
- package/dist/dropcursor.d.ts +46 -0
- package/dist/dropcursor.js +176 -0
- package/dist/extensions/defaults.d.ts +716 -0
- package/dist/extensions/defaults.js +209 -0
- package/dist/extensions/editor.d.ts +246 -0
- package/dist/extensions/editor.js +271 -0
- package/dist/extensions/extension.d.ts +375 -0
- package/dist/extensions/extension.js +233 -0
- package/dist/extensions.d.ts +4 -0
- package/dist/extensions.js +4 -0
- package/dist/gapcursor.d.ts +66 -0
- package/dist/gapcursor.js +273 -0
- package/dist/history.d.ts +178 -0
- package/dist/history.js +412 -0
- package/dist/html.d.ts +158 -0
- package/dist/html.js +164 -0
- package/dist/inputrules.d.ts +271 -0
- package/dist/inputrules.js +321 -0
- package/dist/internal/attempt.js +15 -0
- package/dist/internal/json.js +29 -0
- package/dist/keymap/keymap.d.ts +130 -0
- package/dist/keymap/keymap.js +159 -0
- package/dist/keymap.d.ts +2 -0
- package/dist/keymap.js +1 -0
- package/dist/markdown/errors.d.ts +23 -0
- package/dist/markdown/errors.js +26 -0
- package/dist/markdown/from_markdown.d.ts +185 -0
- package/dist/markdown/from_markdown.js +266 -0
- package/dist/markdown/schema.d.ts +522 -0
- package/dist/markdown/schema.js +292 -0
- package/dist/markdown/to_markdown.d.ts +251 -0
- package/dist/markdown/to_markdown.js +413 -0
- package/dist/markdown.d.ts +5 -0
- package/dist/markdown.js +5 -0
- package/dist/model/attrsCodec.js +48 -0
- package/dist/model/comparedeep.js +17 -0
- package/dist/model/content.d.ts +232 -0
- package/dist/model/content.js +630 -0
- package/dist/model/diff.js +66 -0
- package/dist/model/dom.d.ts +3 -0
- package/dist/model/errors.d.ts +90 -0
- package/dist/model/errors.js +76 -0
- package/dist/model/fragment.d.ts +131 -0
- package/dist/model/fragment.js +262 -0
- package/dist/model/from_dom.d.ts +299 -0
- package/dist/model/from_dom.js +618 -0
- package/dist/model/json.d.ts +37 -0
- package/dist/model/json.js +126 -0
- package/dist/model/mark.d.ts +73 -0
- package/dist/model/mark.js +121 -0
- package/dist/model/node.d.ts +267 -0
- package/dist/model/node.js +434 -0
- package/dist/model/replace.d.ts +78 -0
- package/dist/model/replace.js +207 -0
- package/dist/model/resolvedpos.d.ts +196 -0
- package/dist/model/resolvedpos.js +305 -0
- package/dist/model/schema.d.ts +740 -0
- package/dist/model/schema.js +451 -0
- package/dist/model/to_dom.d.ts +169 -0
- package/dist/model/to_dom.js +238 -0
- package/dist/model.d.ts +12 -0
- package/dist/model.js +12 -0
- package/dist/placeholder.d.ts +53 -0
- package/dist/placeholder.js +79 -0
- package/dist/reactive/observer.d.ts +54 -0
- package/dist/reactive/observer.js +61 -0
- package/dist/reactive/selectors.d.ts +22 -0
- package/dist/reactive/selectors.js +61 -0
- package/dist/reactive/stateref.d.ts +72 -0
- package/dist/reactive/stateref.js +71 -0
- package/dist/reactive/streams.d.ts +83 -0
- package/dist/reactive/streams.js +85 -0
- package/dist/reactive.d.ts +16 -0
- package/dist/reactive.js +26 -0
- package/dist/schema-basic.d.ts +448 -0
- package/dist/schema-basic.js +269 -0
- package/dist/schema-list/commands.d.ts +66 -0
- package/dist/schema-list/commands.js +203 -0
- package/dist/schema-list.d.ts +92 -0
- package/dist/schema-list.js +100 -0
- package/dist/state/errors.d.ts +39 -0
- package/dist/state/errors.js +32 -0
- package/dist/state/plugin.d.ts +232 -0
- package/dist/state/plugin.js +82 -0
- package/dist/state/selection.d.ts +297 -0
- package/dist/state/selection.js +486 -0
- package/dist/state/state.d.ts +212 -0
- package/dist/state/state.js +489 -0
- package/dist/state/transaction.d.ts +145 -0
- package/dist/state/transaction.js +195 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +6 -0
- package/dist/test-builder.d.ts +3582 -0
- package/dist/test-builder.js +239 -0
- package/dist/transform/attr_step.d.ts +60 -0
- package/dist/transform/attr_step.js +105 -0
- package/dist/transform/errors.d.ts +50 -0
- package/dist/transform/errors.js +35 -0
- package/dist/transform/map.d.ts +182 -0
- package/dist/transform/map.js +280 -0
- package/dist/transform/mark.js +98 -0
- package/dist/transform/mark_set_step.js +69 -0
- package/dist/transform/mark_step.d.ts +113 -0
- package/dist/transform/mark_step.js +225 -0
- package/dist/transform/replace.d.ts +18 -0
- package/dist/transform/replace.js +381 -0
- package/dist/transform/replace_step.d.ts +109 -0
- package/dist/transform/replace_step.js +175 -0
- package/dist/transform/step.d.ts +157 -0
- package/dist/transform/step.js +168 -0
- package/dist/transform/structure.d.ts +89 -0
- package/dist/transform/structure.js +350 -0
- package/dist/transform/transform.d.ts +248 -0
- package/dist/transform/transform.js +373 -0
- package/dist/transform.d.ts +10 -0
- package/dist/transform.js +10 -0
- package/dist/view/browser.js +39 -0
- package/dist/view/capturekeys.js +282 -0
- package/dist/view/clipboard.d.ts +8 -0
- package/dist/view/clipboard.js +245 -0
- package/dist/view/decoration.d.ts +339 -0
- package/dist/view/decoration.js +566 -0
- package/dist/view/dom.d.ts +18 -0
- package/dist/view/dom.js +140 -0
- package/dist/view/domchange.js +295 -0
- package/dist/view/domcoords.d.ts +22 -0
- package/dist/view/domcoords.js +448 -0
- package/dist/view/domobserver.d.ts +47 -0
- package/dist/view/domobserver.js +328 -0
- package/dist/view/errors.d.ts +18 -0
- package/dist/view/errors.js +21 -0
- package/dist/view/input.d.ts +58 -0
- package/dist/view/input.js +704 -0
- package/dist/view/selection.js +198 -0
- package/dist/view/view.d.ts +699 -0
- package/dist/view/view.js +623 -0
- package/dist/view/viewdesc.d.ts +236 -0
- package/dist/view/viewdesc.js +1205 -0
- package/dist/view-css.d.ts +43 -0
- package/dist/view-css.js +124 -0
- package/dist/view.d.ts +6 -0
- package/dist/view.js +4 -0
- package/package.json +200 -4
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
import { isModelError } from "../model/errors.js";
|
|
2
|
+
import { MapResult, Mapping as Mapping$1, StepMap } from "../transform/map.js";
|
|
3
|
+
import { Step as Step$1, StepResult as StepResult$1 } from "../transform/step.js";
|
|
4
|
+
import { AttrStep as AttrStep$1, DocAttrStep as DocAttrStep$1 } from "../transform/attr_step.js";
|
|
5
|
+
import { MarkSetStep as MarkSetStep$1 } from "../transform/mark_set_step.js";
|
|
6
|
+
import { AddMarkStep as AddMarkStep$1, AddNodeMarkStep as AddNodeMarkStep$1, RemoveMarkStep as RemoveMarkStep$1, RemoveNodeMarkStep as RemoveNodeMarkStep$1 } from "../transform/mark_step.js";
|
|
7
|
+
import { ReplaceAroundStep as ReplaceAroundStep$1, ReplaceStep as ReplaceStep$1 } from "../transform/replace_step.js";
|
|
8
|
+
import { canJoin as canJoin$1, canSplit as canSplit$1, dropPoint as dropPoint$1, findWrapping as findWrapping$1, insertPoint as insertPoint$1, joinPoint as joinPoint$1, liftTarget as liftTarget$1 } from "../transform/structure.js";
|
|
9
|
+
import { replaceStep as replaceStep$1 } from "../transform/replace.js";
|
|
10
|
+
import { Transform as Transform$1 } from "../transform/transform.js";
|
|
11
|
+
import { BASE, CORE, TransformError, adopt, callBase, guard, link, registerWrapper, unwrap, unwrapArray, wrap } from "./internal/core.js";
|
|
12
|
+
import { Slice } from "./model.js";
|
|
13
|
+
import * as Option from "effect/Option";
|
|
14
|
+
// src/compat/transform.ts
|
|
15
|
+
/**
|
|
16
|
+
* A `prosemirror-transform`-compatible facade over
|
|
17
|
+
* `@thomasfosterau/effect-richtext/transform`.
|
|
18
|
+
*
|
|
19
|
+
* `Step` can be subclassed exactly like ProseMirror's: a subclass of
|
|
20
|
+
* the facade `Step` is adapted into a core step (see `toCore`), so
|
|
21
|
+
* custom steps work in core transforms, transactions and the history.
|
|
22
|
+
* `StepMap` and `MapResult` are the core classes, whose API already
|
|
23
|
+
* matches ProseMirror's.
|
|
24
|
+
*
|
|
25
|
+
* Ported API surface from prosemirror-transform (MIT, Marijn Haverbeke and others).
|
|
26
|
+
*
|
|
27
|
+
* @since 0.1.0
|
|
28
|
+
*/
|
|
29
|
+
const nullable = (o) => wrap(Option.getOrNull(o));
|
|
30
|
+
/**
|
|
31
|
+
* A mapping represents a pipeline of zero or more step maps.
|
|
32
|
+
*
|
|
33
|
+
* @since 0.1.0
|
|
34
|
+
* @category models
|
|
35
|
+
*/
|
|
36
|
+
var Mapping = class {
|
|
37
|
+
/** Create a new mapping with the given position maps. */
|
|
38
|
+
constructor(maps, mirror, from, to) {
|
|
39
|
+
link(this, new Mapping$1(maps, mirror, from, to));
|
|
40
|
+
}
|
|
41
|
+
/** The step maps in this mapping. */
|
|
42
|
+
get maps() {
|
|
43
|
+
return this[CORE].maps;
|
|
44
|
+
}
|
|
45
|
+
/** @internal */
|
|
46
|
+
get mirror() {
|
|
47
|
+
return this[CORE].mirror;
|
|
48
|
+
}
|
|
49
|
+
set mirror(value) {
|
|
50
|
+
this[CORE].mirror = value;
|
|
51
|
+
}
|
|
52
|
+
/** The starting position in the `maps` array, used when `map` or `mapResult` is called. */
|
|
53
|
+
get from() {
|
|
54
|
+
return this[CORE].from;
|
|
55
|
+
}
|
|
56
|
+
set from(value) {
|
|
57
|
+
this[CORE].from = value;
|
|
58
|
+
}
|
|
59
|
+
/** The end position in the `maps` array. */
|
|
60
|
+
get to() {
|
|
61
|
+
return this[CORE].to;
|
|
62
|
+
}
|
|
63
|
+
set to(value) {
|
|
64
|
+
this[CORE].to = value;
|
|
65
|
+
}
|
|
66
|
+
/** Create a mapping that maps only through a part of this one. */
|
|
67
|
+
slice(from = 0, to = this.maps.length) {
|
|
68
|
+
return wrap(this[CORE].slice(from, to));
|
|
69
|
+
}
|
|
70
|
+
/** Add a step map to the end of this mapping. */
|
|
71
|
+
appendMap(map, mirrors) {
|
|
72
|
+
this[CORE].appendMap(map, mirrors);
|
|
73
|
+
}
|
|
74
|
+
/** Add all the step maps in a given mapping to this one (preserving mirroring information). */
|
|
75
|
+
appendMapping(mapping) {
|
|
76
|
+
this[CORE].appendMapping(mapping[CORE]);
|
|
77
|
+
}
|
|
78
|
+
/** Finds the offset of the step map that mirrors the map at the given offset, in this mapping. */
|
|
79
|
+
getMirror(n) {
|
|
80
|
+
return this[CORE].getMirrorOrUndefined(n);
|
|
81
|
+
}
|
|
82
|
+
/** @internal */
|
|
83
|
+
setMirror(n, m) {
|
|
84
|
+
this[CORE].setMirror(n, m);
|
|
85
|
+
}
|
|
86
|
+
/** Append the inverse of the given mapping to this one. */
|
|
87
|
+
appendMappingInverted(mapping) {
|
|
88
|
+
this[CORE].appendMappingInverted(mapping[CORE]);
|
|
89
|
+
}
|
|
90
|
+
/** Create an inverted version of this mapping. */
|
|
91
|
+
invert() {
|
|
92
|
+
return wrap(this[CORE].invert());
|
|
93
|
+
}
|
|
94
|
+
/** Map a position through this mapping. */
|
|
95
|
+
map(pos, assoc = 1) {
|
|
96
|
+
return this[CORE].map(pos, assoc);
|
|
97
|
+
}
|
|
98
|
+
/** Map a position through this mapping, returning a mapping result. */
|
|
99
|
+
mapResult(pos, assoc = 1) {
|
|
100
|
+
return this[CORE].mapResult(pos, assoc);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
registerWrapper(Mapping$1, (core) => adopt(Mapping.prototype, core));
|
|
104
|
+
/**
|
|
105
|
+
* The result of applying a step.
|
|
106
|
+
*
|
|
107
|
+
* @since 0.1.0
|
|
108
|
+
* @category models
|
|
109
|
+
*/
|
|
110
|
+
var StepResult = class StepResult {
|
|
111
|
+
/** @internal */
|
|
112
|
+
constructor(doc, failed) {
|
|
113
|
+
this.doc = doc;
|
|
114
|
+
this.failed = failed;
|
|
115
|
+
}
|
|
116
|
+
/** Create a successful step result. */
|
|
117
|
+
static ok(doc) {
|
|
118
|
+
return new StepResult(doc, null);
|
|
119
|
+
}
|
|
120
|
+
/** Create a failed step result. */
|
|
121
|
+
static fail(message) {
|
|
122
|
+
return new StepResult(null, message);
|
|
123
|
+
}
|
|
124
|
+
/** Call `Node.replace` with the given arguments. Create a successful result if it succeeds, and a failed one if it throws a `ReplaceError`. */
|
|
125
|
+
static fromReplace(doc, from, to, slice) {
|
|
126
|
+
return fromCoreResult(StepResult$1.fromReplace(doc[CORE], from, to, slice[CORE]));
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const fromCoreResult = (result) => new StepResult(wrap(result.docOrNull), result.failedOrNull);
|
|
130
|
+
const toCoreResult = (result) => new StepResult$1(unwrap(result.doc), result.failed);
|
|
131
|
+
/**
|
|
132
|
+
* A step object represents an atomic change. Subclass it to define
|
|
133
|
+
* custom steps: subclasses are adapted into core steps automatically.
|
|
134
|
+
*
|
|
135
|
+
* @since 0.1.0
|
|
136
|
+
* @category models
|
|
137
|
+
*/
|
|
138
|
+
var Step = class {
|
|
139
|
+
constructor() {
|
|
140
|
+
if (!(this instanceof CoreStep)) link(this, new AdaptedStep(this));
|
|
141
|
+
}
|
|
142
|
+
/** Get the step map that represents the changes made by this step. */
|
|
143
|
+
getMap() {
|
|
144
|
+
return StepMap.empty;
|
|
145
|
+
}
|
|
146
|
+
/** Try to merge this step with another one, to be applied directly after it. */
|
|
147
|
+
merge(_other) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
/** Deserialize a step from its JSON representation. */
|
|
151
|
+
static fromJSON(schema, json) {
|
|
152
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], json)));
|
|
153
|
+
}
|
|
154
|
+
/** To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. */
|
|
155
|
+
static jsonID(id, stepClass) {
|
|
156
|
+
try {
|
|
157
|
+
Step$1.jsonID(id, { fromJSONUnsafe: (schema, json) => stepClass.fromJSON(wrap(schema), json)[CORE] });
|
|
158
|
+
} catch (e) {
|
|
159
|
+
throw new RangeError(e.message);
|
|
160
|
+
}
|
|
161
|
+
stepClass.prototype.jsonID = id;
|
|
162
|
+
return stepClass;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/** A core step implemented by a user-defined facade step. @internal */
|
|
166
|
+
var AdaptedStep = class extends Step$1 {
|
|
167
|
+
constructor(facade) {
|
|
168
|
+
super();
|
|
169
|
+
this.facade = facade;
|
|
170
|
+
}
|
|
171
|
+
apply(doc) {
|
|
172
|
+
return toCoreResult(this.facade.apply(wrap(doc)));
|
|
173
|
+
}
|
|
174
|
+
getMap() {
|
|
175
|
+
return this.facade.getMap();
|
|
176
|
+
}
|
|
177
|
+
invert(doc) {
|
|
178
|
+
return this.facade.invert(wrap(doc))[CORE];
|
|
179
|
+
}
|
|
180
|
+
map(mapping) {
|
|
181
|
+
return Option.fromNullishOr(unwrap(this.facade.map(wrap(mapping))));
|
|
182
|
+
}
|
|
183
|
+
merge(other) {
|
|
184
|
+
return Option.fromNullishOr(unwrap(this.facade.merge(wrap(other))));
|
|
185
|
+
}
|
|
186
|
+
toJSON() {
|
|
187
|
+
return this.facade.toJSON();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/** Base class of the facades for the core's built-in steps. @internal */
|
|
191
|
+
var CoreStep = class extends Step {
|
|
192
|
+
apply(doc) {
|
|
193
|
+
const core = this[CORE];
|
|
194
|
+
try {
|
|
195
|
+
return fromCoreResult(callBase(core, "apply", [doc[CORE]]));
|
|
196
|
+
} catch (e) {
|
|
197
|
+
if (isModelError(e)) return new StepResult(null, e.message);
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
getMap() {
|
|
202
|
+
return callBase(this[CORE], "getMap");
|
|
203
|
+
}
|
|
204
|
+
invert(doc) {
|
|
205
|
+
return wrap(guard(() => callBase(this[CORE], "invert", [doc[CORE]])));
|
|
206
|
+
}
|
|
207
|
+
map(mapping) {
|
|
208
|
+
return nullable(callBase(this[CORE], "map", [unwrap(mapping)]));
|
|
209
|
+
}
|
|
210
|
+
merge(other) {
|
|
211
|
+
return nullable(callBase(this[CORE], "merge", [other[CORE]]));
|
|
212
|
+
}
|
|
213
|
+
toJSON() {
|
|
214
|
+
return callBase(this[CORE], "toJSON");
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const adaptedClasses = /* @__PURE__ */ new WeakMap();
|
|
218
|
+
/**
|
|
219
|
+
* The core class used for instances of a subclass of a built-in step
|
|
220
|
+
* facade: a subclass of the core step class whose methods call the
|
|
221
|
+
* facade's overrides, when it has them. @internal
|
|
222
|
+
*/
|
|
223
|
+
const adaptedStepClass = (CoreClass, FacadeClass) => {
|
|
224
|
+
let found = adaptedClasses.get(CoreClass);
|
|
225
|
+
if (!found) {
|
|
226
|
+
const base = FacadeClass.prototype;
|
|
227
|
+
found = class extends CoreClass {
|
|
228
|
+
apply(doc) {
|
|
229
|
+
return this.facade.apply === base.apply ? super.apply(doc) : toCoreResult(this.facade.apply(wrap(doc)));
|
|
230
|
+
}
|
|
231
|
+
getMap() {
|
|
232
|
+
return this.facade.getMap === base.getMap ? super.getMap() : this.facade.getMap();
|
|
233
|
+
}
|
|
234
|
+
invert(doc) {
|
|
235
|
+
return this.facade.invert === base.invert ? super.invert(doc) : this.facade.invert(wrap(doc))[CORE];
|
|
236
|
+
}
|
|
237
|
+
map(mapping) {
|
|
238
|
+
return this.facade.map === base.map ? super.map(mapping) : Option.fromNullishOr(unwrap(this.facade.map(wrap(mapping))));
|
|
239
|
+
}
|
|
240
|
+
merge(other) {
|
|
241
|
+
return this.facade.merge === base.merge ? super.merge(other) : Option.fromNullishOr(unwrap(this.facade.merge(wrap(other))));
|
|
242
|
+
}
|
|
243
|
+
toJSON() {
|
|
244
|
+
return this.facade.toJSON === base.toJSON ? super.toJSON() : this.facade.toJSON();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
found.prototype[BASE] = CoreClass.prototype;
|
|
248
|
+
adaptedClasses.set(CoreClass, found);
|
|
249
|
+
}
|
|
250
|
+
return found;
|
|
251
|
+
};
|
|
252
|
+
/** Create the core step for a built-in step facade (or a subclass of one). @internal */
|
|
253
|
+
const coreStep = (facade, target, FacadeClass, CoreClass, args) => {
|
|
254
|
+
if (target === FacadeClass) return new CoreClass(...args);
|
|
255
|
+
const core = new (adaptedStepClass(CoreClass, FacadeClass))(...args);
|
|
256
|
+
core.facade = facade;
|
|
257
|
+
return core;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Replace a part of the document with a slice of new content.
|
|
261
|
+
*
|
|
262
|
+
* @since 0.1.0
|
|
263
|
+
* @category models
|
|
264
|
+
*/
|
|
265
|
+
var ReplaceStep = class ReplaceStep extends CoreStep {
|
|
266
|
+
/** The given `slice` should fit the 'gap' between `from` and `to`. */
|
|
267
|
+
constructor(from, to, slice, structure = false) {
|
|
268
|
+
super();
|
|
269
|
+
link(this, coreStep(this, new.target, ReplaceStep, ReplaceStep$1, [
|
|
270
|
+
from,
|
|
271
|
+
to,
|
|
272
|
+
slice[CORE],
|
|
273
|
+
structure
|
|
274
|
+
]));
|
|
275
|
+
}
|
|
276
|
+
/** The start position of the replaced range. */
|
|
277
|
+
get from() {
|
|
278
|
+
return this[CORE].from;
|
|
279
|
+
}
|
|
280
|
+
/** The end position of the replaced range. */
|
|
281
|
+
get to() {
|
|
282
|
+
return this[CORE].to;
|
|
283
|
+
}
|
|
284
|
+
/** The slice to insert. */
|
|
285
|
+
get slice() {
|
|
286
|
+
return wrap(this[CORE].slice);
|
|
287
|
+
}
|
|
288
|
+
/** @internal */
|
|
289
|
+
get structure() {
|
|
290
|
+
return this[CORE].structure;
|
|
291
|
+
}
|
|
292
|
+
/** @internal */
|
|
293
|
+
static fromJSON(schema, json) {
|
|
294
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
295
|
+
...json,
|
|
296
|
+
stepType: "replace"
|
|
297
|
+
})));
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Replace a part of the document with a slice of content, but preserve
|
|
302
|
+
* a range of the replaced content by moving it into the slice.
|
|
303
|
+
*
|
|
304
|
+
* @since 0.1.0
|
|
305
|
+
* @category models
|
|
306
|
+
*/
|
|
307
|
+
var ReplaceAroundStep = class ReplaceAroundStep extends CoreStep {
|
|
308
|
+
/** Create a replace-around step with the given range and gap. */
|
|
309
|
+
constructor(from, to, gapFrom, gapTo, slice, insert, structure = false) {
|
|
310
|
+
super();
|
|
311
|
+
link(this, coreStep(this, new.target, ReplaceAroundStep, ReplaceAroundStep$1, [
|
|
312
|
+
from,
|
|
313
|
+
to,
|
|
314
|
+
gapFrom,
|
|
315
|
+
gapTo,
|
|
316
|
+
slice[CORE],
|
|
317
|
+
insert,
|
|
318
|
+
structure
|
|
319
|
+
]));
|
|
320
|
+
}
|
|
321
|
+
/** The start position of the replaced range. */
|
|
322
|
+
get from() {
|
|
323
|
+
return this[CORE].from;
|
|
324
|
+
}
|
|
325
|
+
/** The end position of the replaced range. */
|
|
326
|
+
get to() {
|
|
327
|
+
return this[CORE].to;
|
|
328
|
+
}
|
|
329
|
+
/** The start of preserved range. */
|
|
330
|
+
get gapFrom() {
|
|
331
|
+
return this[CORE].gapFrom;
|
|
332
|
+
}
|
|
333
|
+
/** The end of preserved range. */
|
|
334
|
+
get gapTo() {
|
|
335
|
+
return this[CORE].gapTo;
|
|
336
|
+
}
|
|
337
|
+
/** The slice to insert. */
|
|
338
|
+
get slice() {
|
|
339
|
+
return wrap(this[CORE].slice);
|
|
340
|
+
}
|
|
341
|
+
/** The position in the slice where the preserved range should be inserted. */
|
|
342
|
+
get insert() {
|
|
343
|
+
return this[CORE].insert;
|
|
344
|
+
}
|
|
345
|
+
/** @internal */
|
|
346
|
+
get structure() {
|
|
347
|
+
return this[CORE].structure;
|
|
348
|
+
}
|
|
349
|
+
/** @internal */
|
|
350
|
+
static fromJSON(schema, json) {
|
|
351
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
352
|
+
...json,
|
|
353
|
+
stepType: "replaceAround"
|
|
354
|
+
})));
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* Add a mark to all inline content between two positions.
|
|
359
|
+
*
|
|
360
|
+
* @since 0.1.0
|
|
361
|
+
* @category models
|
|
362
|
+
*/
|
|
363
|
+
var AddMarkStep = class AddMarkStep extends CoreStep {
|
|
364
|
+
/** Create a mark step. */
|
|
365
|
+
constructor(from, to, mark) {
|
|
366
|
+
super();
|
|
367
|
+
link(this, coreStep(this, new.target, AddMarkStep, AddMarkStep$1, [
|
|
368
|
+
from,
|
|
369
|
+
to,
|
|
370
|
+
mark[CORE]
|
|
371
|
+
]));
|
|
372
|
+
}
|
|
373
|
+
/** The start of the marked range. */
|
|
374
|
+
get from() {
|
|
375
|
+
return this[CORE].from;
|
|
376
|
+
}
|
|
377
|
+
/** The end of the marked range. */
|
|
378
|
+
get to() {
|
|
379
|
+
return this[CORE].to;
|
|
380
|
+
}
|
|
381
|
+
/** The mark to add. */
|
|
382
|
+
get mark() {
|
|
383
|
+
return wrap(this[CORE].mark);
|
|
384
|
+
}
|
|
385
|
+
/** @internal */
|
|
386
|
+
static fromJSON(schema, json) {
|
|
387
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
388
|
+
...json,
|
|
389
|
+
stepType: "addMark"
|
|
390
|
+
})));
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* Remove a mark from all inline content between two positions.
|
|
395
|
+
*
|
|
396
|
+
* @since 0.1.0
|
|
397
|
+
* @category models
|
|
398
|
+
*/
|
|
399
|
+
var RemoveMarkStep = class RemoveMarkStep extends CoreStep {
|
|
400
|
+
/** Create a mark-removing step. */
|
|
401
|
+
constructor(from, to, mark) {
|
|
402
|
+
super();
|
|
403
|
+
link(this, coreStep(this, new.target, RemoveMarkStep, RemoveMarkStep$1, [
|
|
404
|
+
from,
|
|
405
|
+
to,
|
|
406
|
+
mark[CORE]
|
|
407
|
+
]));
|
|
408
|
+
}
|
|
409
|
+
/** The start of the unmarked range. */
|
|
410
|
+
get from() {
|
|
411
|
+
return this[CORE].from;
|
|
412
|
+
}
|
|
413
|
+
/** The end of the unmarked range. */
|
|
414
|
+
get to() {
|
|
415
|
+
return this[CORE].to;
|
|
416
|
+
}
|
|
417
|
+
/** The mark to remove. */
|
|
418
|
+
get mark() {
|
|
419
|
+
return wrap(this[CORE].mark);
|
|
420
|
+
}
|
|
421
|
+
/** @internal */
|
|
422
|
+
static fromJSON(schema, json) {
|
|
423
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
424
|
+
...json,
|
|
425
|
+
stepType: "removeMark"
|
|
426
|
+
})));
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
/**
|
|
430
|
+
* Add a mark to a specific node.
|
|
431
|
+
*
|
|
432
|
+
* @since 0.1.0
|
|
433
|
+
* @category models
|
|
434
|
+
*/
|
|
435
|
+
var AddNodeMarkStep = class AddNodeMarkStep extends CoreStep {
|
|
436
|
+
/** Create a node mark step. */
|
|
437
|
+
constructor(pos, mark) {
|
|
438
|
+
super();
|
|
439
|
+
link(this, coreStep(this, new.target, AddNodeMarkStep, AddNodeMarkStep$1, [pos, mark[CORE]]));
|
|
440
|
+
}
|
|
441
|
+
/** The position of the target node. */
|
|
442
|
+
get pos() {
|
|
443
|
+
return this[CORE].pos;
|
|
444
|
+
}
|
|
445
|
+
/** The mark to add. */
|
|
446
|
+
get mark() {
|
|
447
|
+
return wrap(this[CORE].mark);
|
|
448
|
+
}
|
|
449
|
+
/** @internal */
|
|
450
|
+
static fromJSON(schema, json) {
|
|
451
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
452
|
+
...json,
|
|
453
|
+
stepType: "addNodeMark"
|
|
454
|
+
})));
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
/**
|
|
458
|
+
* Remove a mark from a specific node.
|
|
459
|
+
*
|
|
460
|
+
* @since 0.1.0
|
|
461
|
+
* @category models
|
|
462
|
+
*/
|
|
463
|
+
var RemoveNodeMarkStep = class RemoveNodeMarkStep extends CoreStep {
|
|
464
|
+
/** Create a mark-removing step. */
|
|
465
|
+
constructor(pos, mark) {
|
|
466
|
+
super();
|
|
467
|
+
link(this, coreStep(this, new.target, RemoveNodeMarkStep, RemoveNodeMarkStep$1, [pos, mark[CORE]]));
|
|
468
|
+
}
|
|
469
|
+
/** The position of the target node. */
|
|
470
|
+
get pos() {
|
|
471
|
+
return this[CORE].pos;
|
|
472
|
+
}
|
|
473
|
+
/** The mark to remove. */
|
|
474
|
+
get mark() {
|
|
475
|
+
return wrap(this[CORE].mark);
|
|
476
|
+
}
|
|
477
|
+
/** @internal */
|
|
478
|
+
static fromJSON(schema, json) {
|
|
479
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
480
|
+
...json,
|
|
481
|
+
stepType: "removeNodeMark"
|
|
482
|
+
})));
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
var MarkSetStep = class extends CoreStep {
|
|
486
|
+
/** The grouped steps. */
|
|
487
|
+
get steps() {
|
|
488
|
+
return this[CORE].steps.map((s) => wrap(s));
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* Update an attribute in a specific node.
|
|
493
|
+
*
|
|
494
|
+
* @since 0.1.0
|
|
495
|
+
* @category models
|
|
496
|
+
*/
|
|
497
|
+
var AttrStep = class AttrStep extends CoreStep {
|
|
498
|
+
/** Construct an attribute step. */
|
|
499
|
+
constructor(pos, attr, value) {
|
|
500
|
+
super();
|
|
501
|
+
link(this, coreStep(this, new.target, AttrStep, AttrStep$1, [
|
|
502
|
+
pos,
|
|
503
|
+
attr,
|
|
504
|
+
value
|
|
505
|
+
]));
|
|
506
|
+
}
|
|
507
|
+
/** The position of the target node. */
|
|
508
|
+
get pos() {
|
|
509
|
+
return this[CORE].pos;
|
|
510
|
+
}
|
|
511
|
+
/** The attribute to set. */
|
|
512
|
+
get attr() {
|
|
513
|
+
return this[CORE].attr;
|
|
514
|
+
}
|
|
515
|
+
/** The attribute's new value. */
|
|
516
|
+
get value() {
|
|
517
|
+
return this[CORE].value;
|
|
518
|
+
}
|
|
519
|
+
/** @internal */
|
|
520
|
+
static fromJSON(schema, json) {
|
|
521
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
522
|
+
...json,
|
|
523
|
+
stepType: "attr"
|
|
524
|
+
})));
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
/**
|
|
528
|
+
* Update an attribute in the doc node.
|
|
529
|
+
*
|
|
530
|
+
* @since 0.1.0
|
|
531
|
+
* @category models
|
|
532
|
+
*/
|
|
533
|
+
var DocAttrStep = class DocAttrStep extends CoreStep {
|
|
534
|
+
/** Construct an attribute step. */
|
|
535
|
+
constructor(attr, value) {
|
|
536
|
+
super();
|
|
537
|
+
link(this, coreStep(this, new.target, DocAttrStep, DocAttrStep$1, [attr, value]));
|
|
538
|
+
}
|
|
539
|
+
/** The attribute to set. */
|
|
540
|
+
get attr() {
|
|
541
|
+
return this[CORE].attr;
|
|
542
|
+
}
|
|
543
|
+
/** The attribute's new value. */
|
|
544
|
+
get value() {
|
|
545
|
+
return this[CORE].value;
|
|
546
|
+
}
|
|
547
|
+
/** @internal */
|
|
548
|
+
static fromJSON(schema, json) {
|
|
549
|
+
return wrap(guard(() => Step$1.fromJSONUnsafe(schema[CORE], {
|
|
550
|
+
...json,
|
|
551
|
+
stepType: "docAttr"
|
|
552
|
+
})));
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
registerWrapper(ReplaceStep$1, (core) => adopt(ReplaceStep.prototype, core));
|
|
556
|
+
registerWrapper(ReplaceAroundStep$1, (core) => adopt(ReplaceAroundStep.prototype, core));
|
|
557
|
+
registerWrapper(AddMarkStep$1, (core) => adopt(AddMarkStep.prototype, core));
|
|
558
|
+
registerWrapper(RemoveMarkStep$1, (core) => adopt(RemoveMarkStep.prototype, core));
|
|
559
|
+
registerWrapper(AddNodeMarkStep$1, (core) => adopt(AddNodeMarkStep.prototype, core));
|
|
560
|
+
registerWrapper(RemoveNodeMarkStep$1, (core) => adopt(RemoveNodeMarkStep.prototype, core));
|
|
561
|
+
registerWrapper(AttrStep$1, (core) => adopt(AttrStep.prototype, core));
|
|
562
|
+
registerWrapper(DocAttrStep$1, (core) => adopt(DocAttrStep.prototype, core));
|
|
563
|
+
registerWrapper(MarkSetStep$1, (core) => adopt(MarkSetStep.prototype, core));
|
|
564
|
+
registerWrapper(StepResult$1, fromCoreResult);
|
|
565
|
+
const wrappersToCore = (wrappers) => wrappers && wrappers.map((w) => w && {
|
|
566
|
+
type: w.type[CORE],
|
|
567
|
+
attrs: w.attrs ?? null
|
|
568
|
+
});
|
|
569
|
+
/**
|
|
570
|
+
* Try to find a target depth to which the content in the given range
|
|
571
|
+
* can be lifted.
|
|
572
|
+
*
|
|
573
|
+
* @since 0.1.0
|
|
574
|
+
* @category structure
|
|
575
|
+
*/
|
|
576
|
+
const liftTarget = (range) => Option.getOrNull(liftTarget$1(range[CORE]));
|
|
577
|
+
/**
|
|
578
|
+
* Try to find a valid way to wrap the content in the given range in a
|
|
579
|
+
* node of the given type.
|
|
580
|
+
*
|
|
581
|
+
* @since 0.1.0
|
|
582
|
+
* @category structure
|
|
583
|
+
*/
|
|
584
|
+
const findWrapping = (range, nodeType, attrs = null, innerRange = range) => {
|
|
585
|
+
const found = Option.getOrNull(findWrapping$1(range[CORE], nodeType[CORE], attrs, innerRange[CORE]));
|
|
586
|
+
return found && found.map((w) => ({
|
|
587
|
+
type: wrap(w.type),
|
|
588
|
+
attrs: w.attrs ?? null
|
|
589
|
+
}));
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Check whether splitting at the given position is allowed.
|
|
593
|
+
*
|
|
594
|
+
* @since 0.1.0
|
|
595
|
+
* @category structure
|
|
596
|
+
*/
|
|
597
|
+
const canSplit = (doc, pos, depth = 1, typesAfter) => guard(() => canSplit$1(doc[CORE], pos, depth, wrappersToCore(typesAfter)));
|
|
598
|
+
/**
|
|
599
|
+
* Test whether the blocks before and after a given position can be
|
|
600
|
+
* joined.
|
|
601
|
+
*
|
|
602
|
+
* @since 0.1.0
|
|
603
|
+
* @category structure
|
|
604
|
+
*/
|
|
605
|
+
const canJoin = (doc, pos) => guard(() => canJoin$1(doc[CORE], pos));
|
|
606
|
+
/**
|
|
607
|
+
* Find an ancestor of the given position that can be joined to the
|
|
608
|
+
* block before (or after if `dir` is positive).
|
|
609
|
+
*
|
|
610
|
+
* @since 0.1.0
|
|
611
|
+
* @category structure
|
|
612
|
+
*/
|
|
613
|
+
const joinPoint = (doc, pos, dir = -1) => guard(() => Option.getOrNull(joinPoint$1(doc[CORE], pos, dir)));
|
|
614
|
+
/**
|
|
615
|
+
* Try to find a point where a node of the given type can be inserted
|
|
616
|
+
* near `pos`, by searching up the node hierarchy when `pos` itself
|
|
617
|
+
* isn't a valid place but is at the start or end of a node.
|
|
618
|
+
*
|
|
619
|
+
* @since 0.1.0
|
|
620
|
+
* @category structure
|
|
621
|
+
*/
|
|
622
|
+
const insertPoint = (doc, pos, nodeType) => guard(() => Option.getOrNull(insertPoint$1(doc[CORE], pos, nodeType[CORE])));
|
|
623
|
+
/**
|
|
624
|
+
* Finds a position at or around the given position where the given
|
|
625
|
+
* slice can be inserted.
|
|
626
|
+
*
|
|
627
|
+
* @since 0.1.0
|
|
628
|
+
* @category structure
|
|
629
|
+
*/
|
|
630
|
+
const dropPoint = (doc, pos, slice) => guard(() => Option.getOrNull(dropPoint$1(doc[CORE], pos, slice[CORE])));
|
|
631
|
+
/**
|
|
632
|
+
* 'Fit' a slice into a given position in the document, producing a
|
|
633
|
+
* step that inserts it. Will return null if there's no meaningful way
|
|
634
|
+
* to insert the slice here, or inserting it would be a no-op.
|
|
635
|
+
*
|
|
636
|
+
* @since 0.1.0
|
|
637
|
+
* @category structure
|
|
638
|
+
*/
|
|
639
|
+
const replaceStep = (doc, from, to = from, slice = Slice.empty) => guard(() => nullable(replaceStep$1(doc[CORE], from, to, slice[CORE])));
|
|
640
|
+
const contentInput = (content) => Array.isArray(content) ? content.map(unwrap) : unwrap(content);
|
|
641
|
+
/**
|
|
642
|
+
* Abstraction to build up and track an array of steps representing a
|
|
643
|
+
* document transformation.
|
|
644
|
+
*
|
|
645
|
+
* @since 0.1.0
|
|
646
|
+
* @category models
|
|
647
|
+
*/
|
|
648
|
+
var Transform = class {
|
|
649
|
+
/** Create a transform that starts with the given document. */
|
|
650
|
+
constructor(doc) {
|
|
651
|
+
link(this, new Transform$1(doc[CORE]));
|
|
652
|
+
}
|
|
653
|
+
/** The steps in this transform. */
|
|
654
|
+
get steps() {
|
|
655
|
+
return this[CORE].steps.map(wrap);
|
|
656
|
+
}
|
|
657
|
+
/** The documents before each of the steps. */
|
|
658
|
+
get docs() {
|
|
659
|
+
return this[CORE].docs.map(wrap);
|
|
660
|
+
}
|
|
661
|
+
/** A mapping with the maps for each of the steps in this transform. */
|
|
662
|
+
get mapping() {
|
|
663
|
+
return wrap(this[CORE].mapping);
|
|
664
|
+
}
|
|
665
|
+
/** The current document (the result of applying the steps in the transform). */
|
|
666
|
+
get doc() {
|
|
667
|
+
return wrap(this[CORE].doc);
|
|
668
|
+
}
|
|
669
|
+
/** The starting document. */
|
|
670
|
+
get before() {
|
|
671
|
+
return wrap(this[CORE].before);
|
|
672
|
+
}
|
|
673
|
+
/** Apply a new step in this transform, saving the result. Throws an error when the step fails. */
|
|
674
|
+
step(step) {
|
|
675
|
+
guard(() => this[CORE].stepUnsafe(step[CORE]));
|
|
676
|
+
return this;
|
|
677
|
+
}
|
|
678
|
+
/** Try to apply a step in this transformation, ignoring it if it fails. Returns the step result. */
|
|
679
|
+
maybeStep(step) {
|
|
680
|
+
return fromCoreResult(guard(() => this[CORE].maybeStep(step[CORE])));
|
|
681
|
+
}
|
|
682
|
+
/** True when the document has been changed (when there are any steps). */
|
|
683
|
+
get docChanged() {
|
|
684
|
+
return this[CORE].docChanged;
|
|
685
|
+
}
|
|
686
|
+
/** Return a single range, in post-transform document positions, that covers all content changed by this transform. */
|
|
687
|
+
changedRange() {
|
|
688
|
+
return Option.getOrNull(this[CORE].changedRange());
|
|
689
|
+
}
|
|
690
|
+
/** @internal */
|
|
691
|
+
addStep(step, doc) {
|
|
692
|
+
this[CORE].addStep(step[CORE], doc[CORE]);
|
|
693
|
+
}
|
|
694
|
+
/** Replace the part of the document between `from` and `to` with the given `slice`. */
|
|
695
|
+
replace(from, to = from, slice = Slice.empty) {
|
|
696
|
+
guard(() => this[CORE].replaceUnsafe(from, to, slice[CORE]));
|
|
697
|
+
return this;
|
|
698
|
+
}
|
|
699
|
+
/** Replace the given range with the given content, which may be a fragment, node, or array of nodes. */
|
|
700
|
+
replaceWith(from, to, content) {
|
|
701
|
+
guard(() => this[CORE].replaceWithUnsafe(from, to, contentInput(content)));
|
|
702
|
+
return this;
|
|
703
|
+
}
|
|
704
|
+
/** Delete the content between the given positions. */
|
|
705
|
+
delete(from, to) {
|
|
706
|
+
guard(() => this[CORE].deleteUnsafe(from, to));
|
|
707
|
+
return this;
|
|
708
|
+
}
|
|
709
|
+
/** Insert the given content at the given position. */
|
|
710
|
+
insert(pos, content) {
|
|
711
|
+
guard(() => this[CORE].insertUnsafe(pos, contentInput(content)));
|
|
712
|
+
return this;
|
|
713
|
+
}
|
|
714
|
+
/** Replace a range of the document with a given slice, using `from`, `to`, and the slice's `openStart` property as hints, rather than fixed start and end points. */
|
|
715
|
+
replaceRange(from, to, slice) {
|
|
716
|
+
guard(() => this[CORE].replaceRangeUnsafe(from, to, slice[CORE]));
|
|
717
|
+
return this;
|
|
718
|
+
}
|
|
719
|
+
/** Replace the given range with a node, but use `from` and `to` as hints, rather than precise positions. */
|
|
720
|
+
replaceRangeWith(from, to, node) {
|
|
721
|
+
guard(() => this[CORE].replaceRangeWithUnsafe(from, to, node[CORE]));
|
|
722
|
+
return this;
|
|
723
|
+
}
|
|
724
|
+
/** Delete the given range, expanding it to cover fully covered parent nodes until a valid replace is found. */
|
|
725
|
+
deleteRange(from, to) {
|
|
726
|
+
guard(() => this[CORE].deleteRangeUnsafe(from, to));
|
|
727
|
+
return this;
|
|
728
|
+
}
|
|
729
|
+
/** Split the content in the given range off from its parent, if there is sibling content before or after it, and move it up the tree to the depth specified by `target`. */
|
|
730
|
+
lift(range, target) {
|
|
731
|
+
guard(() => this[CORE].liftUnsafe(range[CORE], target));
|
|
732
|
+
return this;
|
|
733
|
+
}
|
|
734
|
+
/** Join the blocks around the given position. */
|
|
735
|
+
join(pos, depth = 1) {
|
|
736
|
+
guard(() => this[CORE].joinUnsafe(pos, depth));
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
/** Wrap the given range in the given set of wrappers. */
|
|
740
|
+
wrap(range, wrappers) {
|
|
741
|
+
guard(() => this[CORE].wrapUnsafe(range[CORE], wrappersToCore(wrappers)));
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
/** Set the type of all textblocks (partly) between `from` and `to` to the given node type with the given attributes. */
|
|
745
|
+
setBlockType(from, to = from, type, attrs = null) {
|
|
746
|
+
const coreAttrs = typeof attrs === "function" ? (node) => attrs(wrap(node)) : attrs;
|
|
747
|
+
guard(() => this[CORE].setBlockTypeUnsafe(from, to, type[CORE], coreAttrs));
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
/** Change the type, attributes, and/or marks of the node at `pos`. */
|
|
751
|
+
setNodeMarkup(pos, type, attrs = null, marks) {
|
|
752
|
+
guard(() => this[CORE].setNodeMarkupUnsafe(pos, type && type[CORE], attrs, marks && unwrapArray(marks)));
|
|
753
|
+
return this;
|
|
754
|
+
}
|
|
755
|
+
/** Set a single attribute on a given node to a new value. */
|
|
756
|
+
setNodeAttribute(pos, attr, value) {
|
|
757
|
+
guard(() => this[CORE].setNodeAttributeUnsafe(pos, attr, value));
|
|
758
|
+
return this;
|
|
759
|
+
}
|
|
760
|
+
/** Set a single attribute on the document to a new value. */
|
|
761
|
+
setDocAttribute(attr, value) {
|
|
762
|
+
guard(() => this[CORE].setDocAttributeUnsafe(attr, value));
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
/** Add a mark to the node at position `pos`. */
|
|
766
|
+
addNodeMark(pos, mark) {
|
|
767
|
+
guard(() => this[CORE].addNodeMarkUnsafe(pos, mark[CORE]));
|
|
768
|
+
return this;
|
|
769
|
+
}
|
|
770
|
+
/** Remove a mark (or all marks of the given type) from the node at position `pos`. */
|
|
771
|
+
removeNodeMark(pos, mark) {
|
|
772
|
+
guard(() => this[CORE].removeNodeMarkUnsafe(pos, mark[CORE]));
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
/** Split the node at the given position, and optionally, if `depth` is greater than one, any number of nodes above that. */
|
|
776
|
+
split(pos, depth = 1, typesAfter) {
|
|
777
|
+
guard(() => this[CORE].splitUnsafe(pos, depth, wrappersToCore(typesAfter)));
|
|
778
|
+
return this;
|
|
779
|
+
}
|
|
780
|
+
/** Add the given mark to the inline content between `from` and `to`. */
|
|
781
|
+
addMark(from, to, mark) {
|
|
782
|
+
guard(() => this[CORE].addMark(from, to, mark[CORE]));
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
/** Remove marks from inline nodes between `from` and `to`. */
|
|
786
|
+
removeMark(from, to, mark) {
|
|
787
|
+
guard(() => this[CORE].removeMark(from, to, mark && mark[CORE]));
|
|
788
|
+
return this;
|
|
789
|
+
}
|
|
790
|
+
/** Removes all marks and nodes from the content of the node at `pos` that don't match the given new parent node type. */
|
|
791
|
+
clearIncompatible(pos, parentType, match) {
|
|
792
|
+
guard(() => this[CORE].clearIncompatibleUnsafe(pos, parentType[CORE], match && match[CORE]));
|
|
793
|
+
return this;
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
registerWrapper(Transform$1, (core) => adopt(Transform.prototype, core));
|
|
797
|
+
function toCore(value) {
|
|
798
|
+
return unwrap(value);
|
|
799
|
+
}
|
|
800
|
+
function fromCore(value) {
|
|
801
|
+
return wrap(value);
|
|
802
|
+
}
|
|
803
|
+
export { AddMarkStep, AddNodeMarkStep, AttrStep, DocAttrStep, MapResult, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, TransformError, canJoin, canSplit, dropPoint, findWrapping, fromCore, insertPoint, joinPoint, liftTarget, replaceStep, toCore };
|