@bigbinary/neeto-editor 1.41.1 → 1.42.0-beta1
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/dist/Editor.js +10968 -6179
- package/dist/Editor.js.map +1 -1
- package/dist/FormikEditor.js +3 -2
- package/dist/FormikEditor.js.map +1 -1
- package/dist/Menu.js +2 -2
- package/dist/{chunk-5a82ef66.js → chunk-53f86c77.js} +1154 -205
- package/dist/chunk-53f86c77.js.map +1 -0
- package/dist/{chunk-66821a1e.js → chunk-bdd72077.js} +3 -4
- package/dist/{chunk-66821a1e.js.map → chunk-bdd72077.js.map} +1 -1
- package/dist/cjs/Editor.cjs.js +10966 -6177
- package/dist/cjs/Editor.cjs.js.map +1 -1
- package/dist/cjs/FormikEditor.cjs.js +3 -2
- package/dist/cjs/FormikEditor.cjs.js.map +1 -1
- package/dist/cjs/Menu.cjs.js +2 -2
- package/dist/cjs/{chunk-42becde2.cjs.js → chunk-b18ba907.cjs.js} +2 -4
- package/dist/cjs/{chunk-42becde2.cjs.js.map → chunk-b18ba907.cjs.js.map} +1 -1
- package/dist/cjs/{chunk-c2f54026.cjs.js → chunk-eee94a18.cjs.js} +1141 -192
- package/dist/cjs/chunk-eee94a18.cjs.js.map +1 -0
- package/dist/cjs/index.cjs.js +4 -3
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/utils.cjs.js +1 -1
- package/dist/editor-stats.html +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/utils.js +1 -1
- package/package.json +8 -2
- package/dist/chunk-5a82ef66.js.map +0 -1
- package/dist/cjs/chunk-c2f54026.cjs.js.map +0 -1
|
@@ -7,7 +7,7 @@ var React = require('react');
|
|
|
7
7
|
var ramda = require('ramda');
|
|
8
8
|
var injectCss = require('./chunk-da9ee471.cjs.js');
|
|
9
9
|
var i18n = require('i18next');
|
|
10
|
-
var utils = require('./chunk-
|
|
10
|
+
var utils = require('./chunk-b18ba907.cjs.js');
|
|
11
11
|
var tippy = require('tippy.js');
|
|
12
12
|
var ReactDOM = require('react-dom');
|
|
13
13
|
var classnames = require('classnames');
|
|
@@ -6060,17 +6060,17 @@ function keydownHandler(bindings) {
|
|
|
6060
6060
|
// decode these, since those clip to 32 bits, which we might in rare
|
|
6061
6061
|
// cases want to overflow. A 64-bit float can represent 48-bit
|
|
6062
6062
|
// integers precisely.
|
|
6063
|
-
const lower16 = 0xffff;
|
|
6064
|
-
const factor16 = Math.pow(2, 16);
|
|
6065
|
-
function makeRecover(index, offset) { return index + offset * factor16; }
|
|
6066
|
-
function recoverIndex(value) { return value & lower16; }
|
|
6067
|
-
function recoverOffset(value) { return (value - (value & lower16)) / factor16; }
|
|
6068
|
-
const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;
|
|
6063
|
+
const lower16$1 = 0xffff;
|
|
6064
|
+
const factor16$1 = Math.pow(2, 16);
|
|
6065
|
+
function makeRecover$1(index, offset) { return index + offset * factor16$1; }
|
|
6066
|
+
function recoverIndex$1(value) { return value & lower16$1; }
|
|
6067
|
+
function recoverOffset$1(value) { return (value - (value & lower16$1)) / factor16$1; }
|
|
6068
|
+
const DEL_BEFORE$1 = 1, DEL_AFTER$1 = 2, DEL_ACROSS$1 = 4, DEL_SIDE$1 = 8;
|
|
6069
6069
|
/**
|
|
6070
6070
|
An object representing a mapped position with extra
|
|
6071
6071
|
information.
|
|
6072
6072
|
*/
|
|
6073
|
-
class MapResult {
|
|
6073
|
+
class MapResult$1 {
|
|
6074
6074
|
/**
|
|
6075
6075
|
@internal
|
|
6076
6076
|
*/
|
|
@@ -6096,21 +6096,21 @@ class MapResult {
|
|
|
6096
6096
|
step removed the token on the side queried (via the `assoc`)
|
|
6097
6097
|
argument from the document.
|
|
6098
6098
|
*/
|
|
6099
|
-
get deleted() { return (this.delInfo & DEL_SIDE) > 0; }
|
|
6099
|
+
get deleted() { return (this.delInfo & DEL_SIDE$1) > 0; }
|
|
6100
6100
|
/**
|
|
6101
6101
|
Tells you whether the token before the mapped position was deleted.
|
|
6102
6102
|
*/
|
|
6103
|
-
get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; }
|
|
6103
|
+
get deletedBefore() { return (this.delInfo & (DEL_BEFORE$1 | DEL_ACROSS$1)) > 0; }
|
|
6104
6104
|
/**
|
|
6105
6105
|
True when the token after the mapped position was deleted.
|
|
6106
6106
|
*/
|
|
6107
|
-
get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; }
|
|
6107
|
+
get deletedAfter() { return (this.delInfo & (DEL_AFTER$1 | DEL_ACROSS$1)) > 0; }
|
|
6108
6108
|
/**
|
|
6109
6109
|
Tells whether any of the steps mapped through deletes across the
|
|
6110
6110
|
position (including both the token before and after the
|
|
6111
6111
|
position).
|
|
6112
6112
|
*/
|
|
6113
|
-
get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; }
|
|
6113
|
+
get deletedAcross() { return (this.delInfo & DEL_ACROSS$1) > 0; }
|
|
6114
6114
|
}
|
|
6115
6115
|
/**
|
|
6116
6116
|
A map describing the deletions and insertions made by a step, which
|
|
@@ -6118,7 +6118,7 @@ can be used to find the correspondence between positions in the
|
|
|
6118
6118
|
pre-step version of a document and the same position in the
|
|
6119
6119
|
post-step version.
|
|
6120
6120
|
*/
|
|
6121
|
-
class StepMap {
|
|
6121
|
+
class StepMap$1 {
|
|
6122
6122
|
/**
|
|
6123
6123
|
Create a position map. The modifications to the document are
|
|
6124
6124
|
represented as an array of numbers, in which each group of three
|
|
@@ -6135,18 +6135,18 @@ class StepMap {
|
|
|
6135
6135
|
inverted = false) {
|
|
6136
6136
|
this.ranges = ranges;
|
|
6137
6137
|
this.inverted = inverted;
|
|
6138
|
-
if (!ranges.length && StepMap.empty)
|
|
6139
|
-
return StepMap.empty;
|
|
6138
|
+
if (!ranges.length && StepMap$1.empty)
|
|
6139
|
+
return StepMap$1.empty;
|
|
6140
6140
|
}
|
|
6141
6141
|
/**
|
|
6142
6142
|
@internal
|
|
6143
6143
|
*/
|
|
6144
6144
|
recover(value) {
|
|
6145
|
-
let diff = 0, index = recoverIndex(value);
|
|
6145
|
+
let diff = 0, index = recoverIndex$1(value);
|
|
6146
6146
|
if (!this.inverted)
|
|
6147
6147
|
for (let i = 0; i < index; i++)
|
|
6148
6148
|
diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
|
|
6149
|
-
return this.ranges[index * 3] + diff + recoverOffset(value);
|
|
6149
|
+
return this.ranges[index * 3] + diff + recoverOffset$1(value);
|
|
6150
6150
|
}
|
|
6151
6151
|
mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }
|
|
6152
6152
|
map(pos, assoc = 1) { return this._map(pos, assoc, true); }
|
|
@@ -6165,21 +6165,21 @@ class StepMap {
|
|
|
6165
6165
|
let result = start + diff + (side < 0 ? 0 : newSize);
|
|
6166
6166
|
if (simple)
|
|
6167
6167
|
return result;
|
|
6168
|
-
let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
|
|
6169
|
-
let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
|
|
6168
|
+
let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover$1(i / 3, pos - start);
|
|
6169
|
+
let del = pos == start ? DEL_AFTER$1 : pos == end ? DEL_BEFORE$1 : DEL_ACROSS$1;
|
|
6170
6170
|
if (assoc < 0 ? pos != start : pos != end)
|
|
6171
|
-
del |= DEL_SIDE;
|
|
6172
|
-
return new MapResult(result, del, recover);
|
|
6171
|
+
del |= DEL_SIDE$1;
|
|
6172
|
+
return new MapResult$1(result, del, recover);
|
|
6173
6173
|
}
|
|
6174
6174
|
diff += newSize - oldSize;
|
|
6175
6175
|
}
|
|
6176
|
-
return simple ? pos + diff : new MapResult(pos + diff, 0, null);
|
|
6176
|
+
return simple ? pos + diff : new MapResult$1(pos + diff, 0, null);
|
|
6177
6177
|
}
|
|
6178
6178
|
/**
|
|
6179
6179
|
@internal
|
|
6180
6180
|
*/
|
|
6181
6181
|
touches(pos, recover) {
|
|
6182
|
-
let diff = 0, index = recoverIndex(recover);
|
|
6182
|
+
let diff = 0, index = recoverIndex$1(recover);
|
|
6183
6183
|
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
6184
6184
|
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
6185
6185
|
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
@@ -6210,7 +6210,7 @@ class StepMap {
|
|
|
6210
6210
|
map positions in the post-step document to the pre-step document.
|
|
6211
6211
|
*/
|
|
6212
6212
|
invert() {
|
|
6213
|
-
return new StepMap(this.ranges, !this.inverted);
|
|
6213
|
+
return new StepMap$1(this.ranges, !this.inverted);
|
|
6214
6214
|
}
|
|
6215
6215
|
/**
|
|
6216
6216
|
@internal
|
|
@@ -6224,13 +6224,13 @@ class StepMap {
|
|
|
6224
6224
|
sub-document to a larger document, or vice-versa.
|
|
6225
6225
|
*/
|
|
6226
6226
|
static offset(n) {
|
|
6227
|
-
return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
6227
|
+
return n == 0 ? StepMap$1.empty : new StepMap$1(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
6228
6228
|
}
|
|
6229
6229
|
}
|
|
6230
6230
|
/**
|
|
6231
6231
|
A StepMap that contains no changed ranges.
|
|
6232
6232
|
*/
|
|
6233
|
-
StepMap.empty = new StepMap([]);
|
|
6233
|
+
StepMap$1.empty = new StepMap$1([]);
|
|
6234
6234
|
/**
|
|
6235
6235
|
A mapping represents a pipeline of zero or more [step
|
|
6236
6236
|
maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
|
|
@@ -6367,11 +6367,11 @@ class Mapping {
|
|
|
6367
6367
|
delInfo |= result.delInfo;
|
|
6368
6368
|
pos = result.pos;
|
|
6369
6369
|
}
|
|
6370
|
-
return simple ? pos : new MapResult(pos, delInfo, null);
|
|
6370
|
+
return simple ? pos : new MapResult$1(pos, delInfo, null);
|
|
6371
6371
|
}
|
|
6372
6372
|
}
|
|
6373
6373
|
|
|
6374
|
-
const stepsByID = Object.create(null);
|
|
6374
|
+
const stepsByID$1 = Object.create(null);
|
|
6375
6375
|
/**
|
|
6376
6376
|
A step object represents an atomic change. It generally applies
|
|
6377
6377
|
only to the document it was created for, since the positions
|
|
@@ -6383,13 +6383,13 @@ methods, and registering your class with a unique
|
|
|
6383
6383
|
JSON-serialization identifier using
|
|
6384
6384
|
[`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).
|
|
6385
6385
|
*/
|
|
6386
|
-
class Step {
|
|
6386
|
+
class Step$1 {
|
|
6387
6387
|
/**
|
|
6388
6388
|
Get the step map that represents the changes made by this step,
|
|
6389
6389
|
and which can be used to transform between positions in the old
|
|
6390
6390
|
and the new document.
|
|
6391
6391
|
*/
|
|
6392
|
-
getMap() { return StepMap.empty; }
|
|
6392
|
+
getMap() { return StepMap$1.empty; }
|
|
6393
6393
|
/**
|
|
6394
6394
|
Try to merge this step with another one, to be applied directly
|
|
6395
6395
|
after it. Returns the merged step when possible, null if the
|
|
@@ -6403,7 +6403,7 @@ class Step {
|
|
|
6403
6403
|
static fromJSON(schema, json) {
|
|
6404
6404
|
if (!json || !json.stepType)
|
|
6405
6405
|
throw new RangeError("Invalid input for Step.fromJSON");
|
|
6406
|
-
let type = stepsByID[json.stepType];
|
|
6406
|
+
let type = stepsByID$1[json.stepType];
|
|
6407
6407
|
if (!type)
|
|
6408
6408
|
throw new RangeError(`No step type ${json.stepType} defined`);
|
|
6409
6409
|
return type.fromJSON(schema, json);
|
|
@@ -6415,9 +6415,9 @@ class Step {
|
|
|
6415
6415
|
that's unlikely to clash with steps from other modules.
|
|
6416
6416
|
*/
|
|
6417
6417
|
static jsonID(id, stepClass) {
|
|
6418
|
-
if (id in stepsByID)
|
|
6418
|
+
if (id in stepsByID$1)
|
|
6419
6419
|
throw new RangeError("Duplicate use of step JSON ID " + id);
|
|
6420
|
-
stepsByID[id] = stepClass;
|
|
6420
|
+
stepsByID$1[id] = stepClass;
|
|
6421
6421
|
stepClass.prototype.jsonID = id;
|
|
6422
6422
|
return stepClass;
|
|
6423
6423
|
}
|
|
@@ -6426,7 +6426,7 @@ class Step {
|
|
|
6426
6426
|
The result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a
|
|
6427
6427
|
new document or a failure value.
|
|
6428
6428
|
*/
|
|
6429
|
-
class StepResult {
|
|
6429
|
+
class StepResult$1 {
|
|
6430
6430
|
/**
|
|
6431
6431
|
@internal
|
|
6432
6432
|
*/
|
|
@@ -6445,11 +6445,11 @@ class StepResult {
|
|
|
6445
6445
|
/**
|
|
6446
6446
|
Create a successful step result.
|
|
6447
6447
|
*/
|
|
6448
|
-
static ok(doc) { return new StepResult(doc, null); }
|
|
6448
|
+
static ok(doc) { return new StepResult$1(doc, null); }
|
|
6449
6449
|
/**
|
|
6450
6450
|
Create a failed step result.
|
|
6451
6451
|
*/
|
|
6452
|
-
static fail(message) { return new StepResult(null, message); }
|
|
6452
|
+
static fail(message) { return new StepResult$1(null, message); }
|
|
6453
6453
|
/**
|
|
6454
6454
|
Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
|
|
6455
6455
|
arguments. Create a successful result if it succeeds, and a
|
|
@@ -6457,22 +6457,22 @@ class StepResult {
|
|
|
6457
6457
|
*/
|
|
6458
6458
|
static fromReplace(doc, from, to, slice) {
|
|
6459
6459
|
try {
|
|
6460
|
-
return StepResult.ok(doc.replace(from, to, slice));
|
|
6460
|
+
return StepResult$1.ok(doc.replace(from, to, slice));
|
|
6461
6461
|
}
|
|
6462
6462
|
catch (e) {
|
|
6463
6463
|
if (e instanceof utils.ReplaceError)
|
|
6464
|
-
return StepResult.fail(e.message);
|
|
6464
|
+
return StepResult$1.fail(e.message);
|
|
6465
6465
|
throw e;
|
|
6466
6466
|
}
|
|
6467
6467
|
}
|
|
6468
6468
|
}
|
|
6469
6469
|
|
|
6470
|
-
function mapFragment(fragment, f, parent) {
|
|
6470
|
+
function mapFragment$1(fragment, f, parent) {
|
|
6471
6471
|
let mapped = [];
|
|
6472
6472
|
for (let i = 0; i < fragment.childCount; i++) {
|
|
6473
6473
|
let child = fragment.child(i);
|
|
6474
6474
|
if (child.content.size)
|
|
6475
|
-
child = child.copy(mapFragment(child.content, f, child));
|
|
6475
|
+
child = child.copy(mapFragment$1(child.content, f, child));
|
|
6476
6476
|
if (child.isInline)
|
|
6477
6477
|
child = f(child, parent, i);
|
|
6478
6478
|
mapped.push(child);
|
|
@@ -6482,7 +6482,7 @@ function mapFragment(fragment, f, parent) {
|
|
|
6482
6482
|
/**
|
|
6483
6483
|
Add a mark to all inline content between two positions.
|
|
6484
6484
|
*/
|
|
6485
|
-
class AddMarkStep extends Step {
|
|
6485
|
+
class AddMarkStep$1 extends Step$1 {
|
|
6486
6486
|
/**
|
|
6487
6487
|
Create a mark step.
|
|
6488
6488
|
*/
|
|
@@ -6507,27 +6507,27 @@ class AddMarkStep extends Step {
|
|
|
6507
6507
|
apply(doc) {
|
|
6508
6508
|
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
|
|
6509
6509
|
let parent = $from.node($from.sharedDepth(this.to));
|
|
6510
|
-
let slice = new utils.Slice(mapFragment(oldSlice.content, (node, parent) => {
|
|
6510
|
+
let slice = new utils.Slice(mapFragment$1(oldSlice.content, (node, parent) => {
|
|
6511
6511
|
if (!node.isAtom || !parent.type.allowsMarkType(this.mark.type))
|
|
6512
6512
|
return node;
|
|
6513
6513
|
return node.mark(this.mark.addToSet(node.marks));
|
|
6514
6514
|
}, parent), oldSlice.openStart, oldSlice.openEnd);
|
|
6515
|
-
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
6515
|
+
return StepResult$1.fromReplace(doc, this.from, this.to, slice);
|
|
6516
6516
|
}
|
|
6517
6517
|
invert() {
|
|
6518
|
-
return new RemoveMarkStep(this.from, this.to, this.mark);
|
|
6518
|
+
return new RemoveMarkStep$1(this.from, this.to, this.mark);
|
|
6519
6519
|
}
|
|
6520
6520
|
map(mapping) {
|
|
6521
6521
|
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
6522
6522
|
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
6523
6523
|
return null;
|
|
6524
|
-
return new AddMarkStep(from.pos, to.pos, this.mark);
|
|
6524
|
+
return new AddMarkStep$1(from.pos, to.pos, this.mark);
|
|
6525
6525
|
}
|
|
6526
6526
|
merge(other) {
|
|
6527
|
-
if (other instanceof AddMarkStep &&
|
|
6527
|
+
if (other instanceof AddMarkStep$1 &&
|
|
6528
6528
|
other.mark.eq(this.mark) &&
|
|
6529
6529
|
this.from <= other.to && this.to >= other.from)
|
|
6530
|
-
return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
6530
|
+
return new AddMarkStep$1(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
6531
6531
|
return null;
|
|
6532
6532
|
}
|
|
6533
6533
|
toJSON() {
|
|
@@ -6540,14 +6540,14 @@ class AddMarkStep extends Step {
|
|
|
6540
6540
|
static fromJSON(schema, json) {
|
|
6541
6541
|
if (typeof json.from != "number" || typeof json.to != "number")
|
|
6542
6542
|
throw new RangeError("Invalid input for AddMarkStep.fromJSON");
|
|
6543
|
-
return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
6543
|
+
return new AddMarkStep$1(json.from, json.to, schema.markFromJSON(json.mark));
|
|
6544
6544
|
}
|
|
6545
6545
|
}
|
|
6546
|
-
Step.jsonID("addMark", AddMarkStep);
|
|
6546
|
+
Step$1.jsonID("addMark", AddMarkStep$1);
|
|
6547
6547
|
/**
|
|
6548
6548
|
Remove a mark from all inline content between two positions.
|
|
6549
6549
|
*/
|
|
6550
|
-
class RemoveMarkStep extends Step {
|
|
6550
|
+
class RemoveMarkStep$1 extends Step$1 {
|
|
6551
6551
|
/**
|
|
6552
6552
|
Create a mark-removing step.
|
|
6553
6553
|
*/
|
|
@@ -6571,25 +6571,25 @@ class RemoveMarkStep extends Step {
|
|
|
6571
6571
|
}
|
|
6572
6572
|
apply(doc) {
|
|
6573
6573
|
let oldSlice = doc.slice(this.from, this.to);
|
|
6574
|
-
let slice = new utils.Slice(mapFragment(oldSlice.content, node => {
|
|
6574
|
+
let slice = new utils.Slice(mapFragment$1(oldSlice.content, node => {
|
|
6575
6575
|
return node.mark(this.mark.removeFromSet(node.marks));
|
|
6576
6576
|
}, doc), oldSlice.openStart, oldSlice.openEnd);
|
|
6577
|
-
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
6577
|
+
return StepResult$1.fromReplace(doc, this.from, this.to, slice);
|
|
6578
6578
|
}
|
|
6579
6579
|
invert() {
|
|
6580
|
-
return new AddMarkStep(this.from, this.to, this.mark);
|
|
6580
|
+
return new AddMarkStep$1(this.from, this.to, this.mark);
|
|
6581
6581
|
}
|
|
6582
6582
|
map(mapping) {
|
|
6583
6583
|
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
6584
6584
|
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
6585
6585
|
return null;
|
|
6586
|
-
return new RemoveMarkStep(from.pos, to.pos, this.mark);
|
|
6586
|
+
return new RemoveMarkStep$1(from.pos, to.pos, this.mark);
|
|
6587
6587
|
}
|
|
6588
6588
|
merge(other) {
|
|
6589
|
-
if (other instanceof RemoveMarkStep &&
|
|
6589
|
+
if (other instanceof RemoveMarkStep$1 &&
|
|
6590
6590
|
other.mark.eq(this.mark) &&
|
|
6591
6591
|
this.from <= other.to && this.to >= other.from)
|
|
6592
|
-
return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
6592
|
+
return new RemoveMarkStep$1(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
6593
6593
|
return null;
|
|
6594
6594
|
}
|
|
6595
6595
|
toJSON() {
|
|
@@ -6602,14 +6602,14 @@ class RemoveMarkStep extends Step {
|
|
|
6602
6602
|
static fromJSON(schema, json) {
|
|
6603
6603
|
if (typeof json.from != "number" || typeof json.to != "number")
|
|
6604
6604
|
throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
|
|
6605
|
-
return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
6605
|
+
return new RemoveMarkStep$1(json.from, json.to, schema.markFromJSON(json.mark));
|
|
6606
6606
|
}
|
|
6607
6607
|
}
|
|
6608
|
-
Step.jsonID("removeMark", RemoveMarkStep);
|
|
6608
|
+
Step$1.jsonID("removeMark", RemoveMarkStep$1);
|
|
6609
6609
|
/**
|
|
6610
6610
|
Add a mark to a specific node.
|
|
6611
6611
|
*/
|
|
6612
|
-
class AddNodeMarkStep extends Step {
|
|
6612
|
+
class AddNodeMarkStep$1 extends Step$1 {
|
|
6613
6613
|
/**
|
|
6614
6614
|
Create a node mark step.
|
|
6615
6615
|
*/
|
|
@@ -6629,9 +6629,9 @@ class AddNodeMarkStep extends Step {
|
|
|
6629
6629
|
apply(doc) {
|
|
6630
6630
|
let node = doc.nodeAt(this.pos);
|
|
6631
6631
|
if (!node)
|
|
6632
|
-
return StepResult.fail("No node at mark step's position");
|
|
6632
|
+
return StepResult$1.fail("No node at mark step's position");
|
|
6633
6633
|
let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
|
|
6634
|
-
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
6634
|
+
return StepResult$1.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
6635
6635
|
}
|
|
6636
6636
|
invert(doc) {
|
|
6637
6637
|
let node = doc.nodeAt(this.pos);
|
|
@@ -6640,15 +6640,15 @@ class AddNodeMarkStep extends Step {
|
|
|
6640
6640
|
if (newSet.length == node.marks.length) {
|
|
6641
6641
|
for (let i = 0; i < node.marks.length; i++)
|
|
6642
6642
|
if (!node.marks[i].isInSet(newSet))
|
|
6643
|
-
return new AddNodeMarkStep(this.pos, node.marks[i]);
|
|
6644
|
-
return new AddNodeMarkStep(this.pos, this.mark);
|
|
6643
|
+
return new AddNodeMarkStep$1(this.pos, node.marks[i]);
|
|
6644
|
+
return new AddNodeMarkStep$1(this.pos, this.mark);
|
|
6645
6645
|
}
|
|
6646
6646
|
}
|
|
6647
|
-
return new RemoveNodeMarkStep(this.pos, this.mark);
|
|
6647
|
+
return new RemoveNodeMarkStep$1(this.pos, this.mark);
|
|
6648
6648
|
}
|
|
6649
6649
|
map(mapping) {
|
|
6650
6650
|
let pos = mapping.mapResult(this.pos, 1);
|
|
6651
|
-
return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
|
|
6651
|
+
return pos.deletedAfter ? null : new AddNodeMarkStep$1(pos.pos, this.mark);
|
|
6652
6652
|
}
|
|
6653
6653
|
toJSON() {
|
|
6654
6654
|
return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
@@ -6659,14 +6659,14 @@ class AddNodeMarkStep extends Step {
|
|
|
6659
6659
|
static fromJSON(schema, json) {
|
|
6660
6660
|
if (typeof json.pos != "number")
|
|
6661
6661
|
throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
|
|
6662
|
-
return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
6662
|
+
return new AddNodeMarkStep$1(json.pos, schema.markFromJSON(json.mark));
|
|
6663
6663
|
}
|
|
6664
6664
|
}
|
|
6665
|
-
Step.jsonID("addNodeMark", AddNodeMarkStep);
|
|
6665
|
+
Step$1.jsonID("addNodeMark", AddNodeMarkStep$1);
|
|
6666
6666
|
/**
|
|
6667
6667
|
Remove a mark from a specific node.
|
|
6668
6668
|
*/
|
|
6669
|
-
class RemoveNodeMarkStep extends Step {
|
|
6669
|
+
class RemoveNodeMarkStep$1 extends Step$1 {
|
|
6670
6670
|
/**
|
|
6671
6671
|
Create a mark-removing step.
|
|
6672
6672
|
*/
|
|
@@ -6686,19 +6686,19 @@ class RemoveNodeMarkStep extends Step {
|
|
|
6686
6686
|
apply(doc) {
|
|
6687
6687
|
let node = doc.nodeAt(this.pos);
|
|
6688
6688
|
if (!node)
|
|
6689
|
-
return StepResult.fail("No node at mark step's position");
|
|
6689
|
+
return StepResult$1.fail("No node at mark step's position");
|
|
6690
6690
|
let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
|
|
6691
|
-
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
6691
|
+
return StepResult$1.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
6692
6692
|
}
|
|
6693
6693
|
invert(doc) {
|
|
6694
6694
|
let node = doc.nodeAt(this.pos);
|
|
6695
6695
|
if (!node || !this.mark.isInSet(node.marks))
|
|
6696
6696
|
return this;
|
|
6697
|
-
return new AddNodeMarkStep(this.pos, this.mark);
|
|
6697
|
+
return new AddNodeMarkStep$1(this.pos, this.mark);
|
|
6698
6698
|
}
|
|
6699
6699
|
map(mapping) {
|
|
6700
6700
|
let pos = mapping.mapResult(this.pos, 1);
|
|
6701
|
-
return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
|
|
6701
|
+
return pos.deletedAfter ? null : new RemoveNodeMarkStep$1(pos.pos, this.mark);
|
|
6702
6702
|
}
|
|
6703
6703
|
toJSON() {
|
|
6704
6704
|
return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
@@ -6709,15 +6709,15 @@ class RemoveNodeMarkStep extends Step {
|
|
|
6709
6709
|
static fromJSON(schema, json) {
|
|
6710
6710
|
if (typeof json.pos != "number")
|
|
6711
6711
|
throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
|
|
6712
|
-
return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
6712
|
+
return new RemoveNodeMarkStep$1(json.pos, schema.markFromJSON(json.mark));
|
|
6713
6713
|
}
|
|
6714
6714
|
}
|
|
6715
|
-
Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
|
|
6715
|
+
Step$1.jsonID("removeNodeMark", RemoveNodeMarkStep$1);
|
|
6716
6716
|
|
|
6717
6717
|
/**
|
|
6718
6718
|
Replace a part of the document with a slice of new content.
|
|
6719
6719
|
*/
|
|
6720
|
-
class ReplaceStep extends Step {
|
|
6720
|
+
class ReplaceStep$1 extends Step$1 {
|
|
6721
6721
|
/**
|
|
6722
6722
|
The given `slice` should fit the 'gap' between `from` and
|
|
6723
6723
|
`to`—the depths must line up, and the surrounding nodes must be
|
|
@@ -6751,34 +6751,34 @@ class ReplaceStep extends Step {
|
|
|
6751
6751
|
this.structure = structure;
|
|
6752
6752
|
}
|
|
6753
6753
|
apply(doc) {
|
|
6754
|
-
if (this.structure && contentBetween(doc, this.from, this.to))
|
|
6755
|
-
return StepResult.fail("Structure replace would overwrite content");
|
|
6756
|
-
return StepResult.fromReplace(doc, this.from, this.to, this.slice);
|
|
6754
|
+
if (this.structure && contentBetween$1(doc, this.from, this.to))
|
|
6755
|
+
return StepResult$1.fail("Structure replace would overwrite content");
|
|
6756
|
+
return StepResult$1.fromReplace(doc, this.from, this.to, this.slice);
|
|
6757
6757
|
}
|
|
6758
6758
|
getMap() {
|
|
6759
|
-
return new StepMap([this.from, this.to - this.from, this.slice.size]);
|
|
6759
|
+
return new StepMap$1([this.from, this.to - this.from, this.slice.size]);
|
|
6760
6760
|
}
|
|
6761
6761
|
invert(doc) {
|
|
6762
|
-
return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
6762
|
+
return new ReplaceStep$1(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
6763
6763
|
}
|
|
6764
6764
|
map(mapping) {
|
|
6765
6765
|
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
6766
6766
|
if (from.deletedAcross && to.deletedAcross)
|
|
6767
6767
|
return null;
|
|
6768
|
-
return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice);
|
|
6768
|
+
return new ReplaceStep$1(from.pos, Math.max(from.pos, to.pos), this.slice);
|
|
6769
6769
|
}
|
|
6770
6770
|
merge(other) {
|
|
6771
|
-
if (!(other instanceof ReplaceStep) || other.structure || this.structure)
|
|
6771
|
+
if (!(other instanceof ReplaceStep$1) || other.structure || this.structure)
|
|
6772
6772
|
return null;
|
|
6773
6773
|
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
|
|
6774
6774
|
let slice = this.slice.size + other.slice.size == 0 ? utils.Slice.empty
|
|
6775
6775
|
: new utils.Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
|
|
6776
|
-
return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
6776
|
+
return new ReplaceStep$1(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
6777
6777
|
}
|
|
6778
6778
|
else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
|
|
6779
6779
|
let slice = this.slice.size + other.slice.size == 0 ? utils.Slice.empty
|
|
6780
6780
|
: new utils.Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
|
|
6781
|
-
return new ReplaceStep(other.from, this.to, slice, this.structure);
|
|
6781
|
+
return new ReplaceStep$1(other.from, this.to, slice, this.structure);
|
|
6782
6782
|
}
|
|
6783
6783
|
else {
|
|
6784
6784
|
return null;
|
|
@@ -6798,16 +6798,16 @@ class ReplaceStep extends Step {
|
|
|
6798
6798
|
static fromJSON(schema, json) {
|
|
6799
6799
|
if (typeof json.from != "number" || typeof json.to != "number")
|
|
6800
6800
|
throw new RangeError("Invalid input for ReplaceStep.fromJSON");
|
|
6801
|
-
return new ReplaceStep(json.from, json.to, utils.Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
6801
|
+
return new ReplaceStep$1(json.from, json.to, utils.Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
6802
6802
|
}
|
|
6803
6803
|
}
|
|
6804
|
-
Step.jsonID("replace", ReplaceStep);
|
|
6804
|
+
Step$1.jsonID("replace", ReplaceStep$1);
|
|
6805
6805
|
/**
|
|
6806
6806
|
Replace a part of the document with a slice of content, but
|
|
6807
6807
|
preserve a range of the replaced content by moving it into the
|
|
6808
6808
|
slice.
|
|
6809
6809
|
*/
|
|
6810
|
-
class ReplaceAroundStep extends Step {
|
|
6810
|
+
class ReplaceAroundStep$1 extends Step$1 {
|
|
6811
6811
|
/**
|
|
6812
6812
|
Create a replace-around step with the given range and gap.
|
|
6813
6813
|
`insert` should be the point in the slice into which the content
|
|
@@ -6854,24 +6854,24 @@ class ReplaceAroundStep extends Step {
|
|
|
6854
6854
|
this.structure = structure;
|
|
6855
6855
|
}
|
|
6856
6856
|
apply(doc) {
|
|
6857
|
-
if (this.structure && (contentBetween(doc, this.from, this.gapFrom) ||
|
|
6858
|
-
contentBetween(doc, this.gapTo, this.to)))
|
|
6859
|
-
return StepResult.fail("Structure gap-replace would overwrite content");
|
|
6857
|
+
if (this.structure && (contentBetween$1(doc, this.from, this.gapFrom) ||
|
|
6858
|
+
contentBetween$1(doc, this.gapTo, this.to)))
|
|
6859
|
+
return StepResult$1.fail("Structure gap-replace would overwrite content");
|
|
6860
6860
|
let gap = doc.slice(this.gapFrom, this.gapTo);
|
|
6861
6861
|
if (gap.openStart || gap.openEnd)
|
|
6862
|
-
return StepResult.fail("Gap is not a flat range");
|
|
6862
|
+
return StepResult$1.fail("Gap is not a flat range");
|
|
6863
6863
|
let inserted = this.slice.insertAt(this.insert, gap.content);
|
|
6864
6864
|
if (!inserted)
|
|
6865
|
-
return StepResult.fail("Content does not fit in gap");
|
|
6866
|
-
return StepResult.fromReplace(doc, this.from, this.to, inserted);
|
|
6865
|
+
return StepResult$1.fail("Content does not fit in gap");
|
|
6866
|
+
return StepResult$1.fromReplace(doc, this.from, this.to, inserted);
|
|
6867
6867
|
}
|
|
6868
6868
|
getMap() {
|
|
6869
|
-
return new StepMap([this.from, this.gapFrom - this.from, this.insert,
|
|
6869
|
+
return new StepMap$1([this.from, this.gapFrom - this.from, this.insert,
|
|
6870
6870
|
this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);
|
|
6871
6871
|
}
|
|
6872
6872
|
invert(doc) {
|
|
6873
6873
|
let gap = this.gapTo - this.gapFrom;
|
|
6874
|
-
return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
6874
|
+
return new ReplaceAroundStep$1(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
6875
6875
|
}
|
|
6876
6876
|
map(mapping) {
|
|
6877
6877
|
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
@@ -6879,7 +6879,7 @@ class ReplaceAroundStep extends Step {
|
|
|
6879
6879
|
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
6880
6880
|
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)
|
|
6881
6881
|
return null;
|
|
6882
|
-
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
6882
|
+
return new ReplaceAroundStep$1(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
6883
6883
|
}
|
|
6884
6884
|
toJSON() {
|
|
6885
6885
|
let json = { stepType: "replaceAround", from: this.from, to: this.to,
|
|
@@ -6897,11 +6897,11 @@ class ReplaceAroundStep extends Step {
|
|
|
6897
6897
|
if (typeof json.from != "number" || typeof json.to != "number" ||
|
|
6898
6898
|
typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
|
|
6899
6899
|
throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
6900
|
-
return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, utils.Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
6900
|
+
return new ReplaceAroundStep$1(json.from, json.to, json.gapFrom, json.gapTo, utils.Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
6901
6901
|
}
|
|
6902
6902
|
}
|
|
6903
|
-
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
6904
|
-
function contentBetween(doc, from, to) {
|
|
6903
|
+
Step$1.jsonID("replaceAround", ReplaceAroundStep$1);
|
|
6904
|
+
function contentBetween$1(doc, from, to) {
|
|
6905
6905
|
let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
|
|
6906
6906
|
while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
|
|
6907
6907
|
depth--;
|
|
@@ -6934,13 +6934,13 @@ function addMark(tr, from, to, mark) {
|
|
|
6934
6934
|
if (removing && removing.to == start && removing.mark.eq(marks[i]))
|
|
6935
6935
|
removing.to = end;
|
|
6936
6936
|
else
|
|
6937
|
-
removed.push(removing = new RemoveMarkStep(start, end, marks[i]));
|
|
6937
|
+
removed.push(removing = new RemoveMarkStep$1(start, end, marks[i]));
|
|
6938
6938
|
}
|
|
6939
6939
|
}
|
|
6940
6940
|
if (adding && adding.to == start)
|
|
6941
6941
|
adding.to = end;
|
|
6942
6942
|
else
|
|
6943
|
-
added.push(adding = new AddMarkStep(start, end, mark));
|
|
6943
|
+
added.push(adding = new AddMarkStep$1(start, end, mark));
|
|
6944
6944
|
}
|
|
6945
6945
|
});
|
|
6946
6946
|
removed.forEach(s => tr.step(s));
|
|
@@ -6986,7 +6986,7 @@ function removeMark(tr, from, to, mark) {
|
|
|
6986
6986
|
}
|
|
6987
6987
|
}
|
|
6988
6988
|
});
|
|
6989
|
-
matched.forEach(m => tr.step(new RemoveMarkStep(m.from, m.to, m.style)));
|
|
6989
|
+
matched.forEach(m => tr.step(new RemoveMarkStep$1(m.from, m.to, m.style)));
|
|
6990
6990
|
}
|
|
6991
6991
|
function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch, clearNewlines = true) {
|
|
6992
6992
|
let node = tr.doc.nodeAt(pos);
|
|
@@ -6995,19 +6995,19 @@ function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch,
|
|
|
6995
6995
|
let child = node.child(i), end = cur + child.nodeSize;
|
|
6996
6996
|
let allowed = match.matchType(child.type);
|
|
6997
6997
|
if (!allowed) {
|
|
6998
|
-
replSteps.push(new ReplaceStep(cur, end, utils.Slice.empty));
|
|
6998
|
+
replSteps.push(new ReplaceStep$1(cur, end, utils.Slice.empty));
|
|
6999
6999
|
}
|
|
7000
7000
|
else {
|
|
7001
7001
|
match = allowed;
|
|
7002
7002
|
for (let j = 0; j < child.marks.length; j++)
|
|
7003
7003
|
if (!parentType.allowsMarkType(child.marks[j].type))
|
|
7004
|
-
tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
|
|
7004
|
+
tr.step(new RemoveMarkStep$1(cur, end, child.marks[j]));
|
|
7005
7005
|
if (clearNewlines && child.isText && parentType.whitespace != "pre") {
|
|
7006
7006
|
let m, newline = /\r?\n|\r/g, slice;
|
|
7007
7007
|
while (m = newline.exec(child.text)) {
|
|
7008
7008
|
if (!slice)
|
|
7009
7009
|
slice = new utils.Slice(utils.Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0);
|
|
7010
|
-
replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));
|
|
7010
|
+
replSteps.push(new ReplaceStep$1(cur + m.index, cur + m.index + m[0].length, slice));
|
|
7011
7011
|
}
|
|
7012
7012
|
}
|
|
7013
7013
|
}
|
|
@@ -7021,7 +7021,7 @@ function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch,
|
|
|
7021
7021
|
tr.step(replSteps[i]);
|
|
7022
7022
|
}
|
|
7023
7023
|
|
|
7024
|
-
function canCut(node, start, end) {
|
|
7024
|
+
function canCut$1(node, start, end) {
|
|
7025
7025
|
return (start == 0 || node.canReplace(start, node.childCount)) &&
|
|
7026
7026
|
(end == node.childCount || node.canReplace(0, end));
|
|
7027
7027
|
}
|
|
@@ -7030,7 +7030,7 @@ Try to find a target depth to which the content in the given range
|
|
|
7030
7030
|
can be lifted. Will not go across
|
|
7031
7031
|
[isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.
|
|
7032
7032
|
*/
|
|
7033
|
-
function liftTarget(range) {
|
|
7033
|
+
function liftTarget$1(range) {
|
|
7034
7034
|
let parent = range.parent;
|
|
7035
7035
|
let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
|
|
7036
7036
|
for (let depth = range.depth;; --depth) {
|
|
@@ -7038,7 +7038,7 @@ function liftTarget(range) {
|
|
|
7038
7038
|
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);
|
|
7039
7039
|
if (depth < range.depth && node.canReplace(index, endIndex, content))
|
|
7040
7040
|
return depth;
|
|
7041
|
-
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
|
|
7041
|
+
if (depth == 0 || node.type.spec.isolating || !canCut$1(node, index, endIndex))
|
|
7042
7042
|
break;
|
|
7043
7043
|
}
|
|
7044
7044
|
return null;
|
|
@@ -7067,7 +7067,7 @@ function lift$2(tr, range, target) {
|
|
|
7067
7067
|
else {
|
|
7068
7068
|
end++;
|
|
7069
7069
|
}
|
|
7070
|
-
tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new utils.Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
|
|
7070
|
+
tr.step(new ReplaceAroundStep$1(start, end, gapStart, gapEnd, new utils.Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
|
|
7071
7071
|
}
|
|
7072
7072
|
/**
|
|
7073
7073
|
Try to find a valid way to wrap the content in the given range in a
|
|
@@ -7077,16 +7077,16 @@ could be found. When `innerRange` is given, that range's content is
|
|
|
7077
7077
|
used as the content to fit into the wrapping, instead of the
|
|
7078
7078
|
content of `range`.
|
|
7079
7079
|
*/
|
|
7080
|
-
function findWrapping(range, nodeType, attrs = null, innerRange = range) {
|
|
7081
|
-
let around = findWrappingOutside(range, nodeType);
|
|
7082
|
-
let inner = around && findWrappingInside(innerRange, nodeType);
|
|
7080
|
+
function findWrapping$1(range, nodeType, attrs = null, innerRange = range) {
|
|
7081
|
+
let around = findWrappingOutside$1(range, nodeType);
|
|
7082
|
+
let inner = around && findWrappingInside$1(innerRange, nodeType);
|
|
7083
7083
|
if (!inner)
|
|
7084
7084
|
return null;
|
|
7085
|
-
return around.map(withAttrs)
|
|
7086
|
-
.concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));
|
|
7085
|
+
return around.map(withAttrs$1)
|
|
7086
|
+
.concat({ type: nodeType, attrs }).concat(inner.map(withAttrs$1));
|
|
7087
7087
|
}
|
|
7088
|
-
function withAttrs(type) { return { type, attrs: null }; }
|
|
7089
|
-
function findWrappingOutside(range, type) {
|
|
7088
|
+
function withAttrs$1(type) { return { type, attrs: null }; }
|
|
7089
|
+
function findWrappingOutside$1(range, type) {
|
|
7090
7090
|
let { parent, startIndex, endIndex } = range;
|
|
7091
7091
|
let around = parent.contentMatchAt(startIndex).findWrapping(type);
|
|
7092
7092
|
if (!around)
|
|
@@ -7094,7 +7094,7 @@ function findWrappingOutside(range, type) {
|
|
|
7094
7094
|
let outer = around.length ? around[0] : type;
|
|
7095
7095
|
return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;
|
|
7096
7096
|
}
|
|
7097
|
-
function findWrappingInside(range, type) {
|
|
7097
|
+
function findWrappingInside$1(range, type) {
|
|
7098
7098
|
let { parent, startIndex, endIndex } = range;
|
|
7099
7099
|
let inner = parent.child(startIndex);
|
|
7100
7100
|
let inside = type.contentMatch.findWrapping(inner.type);
|
|
@@ -7119,14 +7119,16 @@ function wrap(tr, range, wrappers) {
|
|
|
7119
7119
|
content = utils.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
|
|
7120
7120
|
}
|
|
7121
7121
|
let start = range.start, end = range.end;
|
|
7122
|
-
tr.step(new ReplaceAroundStep(start, end, start, end, new utils.Slice(content, 0, 0), wrappers.length, true));
|
|
7122
|
+
tr.step(new ReplaceAroundStep$1(start, end, start, end, new utils.Slice(content, 0, 0), wrappers.length, true));
|
|
7123
7123
|
}
|
|
7124
7124
|
function setBlockType$1(tr, from, to, type, attrs) {
|
|
7125
7125
|
if (!type.isTextblock)
|
|
7126
7126
|
throw new RangeError("Type given to setBlockType should be a textblock");
|
|
7127
7127
|
let mapFrom = tr.steps.length;
|
|
7128
7128
|
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
7129
|
-
|
|
7129
|
+
let attrsHere = typeof attrs == "function" ? attrs(node) : attrs;
|
|
7130
|
+
if (node.isTextblock && !node.hasMarkup(type, attrsHere) &&
|
|
7131
|
+
canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {
|
|
7130
7132
|
let convertNewlines = null;
|
|
7131
7133
|
if (type.schema.linebreakReplacement) {
|
|
7132
7134
|
let pre = type.whitespace == "pre", supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement);
|
|
@@ -7141,7 +7143,7 @@ function setBlockType$1(tr, from, to, type, attrs) {
|
|
|
7141
7143
|
clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null);
|
|
7142
7144
|
let mapping = tr.mapping.slice(mapFrom);
|
|
7143
7145
|
let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
|
|
7144
|
-
tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new utils.Slice(utils.Fragment.from(type.create(
|
|
7146
|
+
tr.step(new ReplaceAroundStep$1(startM, endM, startM + 1, endM - 1, new utils.Slice(utils.Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true));
|
|
7145
7147
|
if (convertNewlines === true)
|
|
7146
7148
|
replaceNewlines(tr, node, pos, mapFrom);
|
|
7147
7149
|
return false;
|
|
@@ -7186,12 +7188,12 @@ function setNodeMarkup(tr, pos, type, attrs, marks) {
|
|
|
7186
7188
|
return tr.replaceWith(pos, pos + node.nodeSize, newNode);
|
|
7187
7189
|
if (!type.validContent(node.content))
|
|
7188
7190
|
throw new RangeError("Invalid content for node type " + type.name);
|
|
7189
|
-
tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new utils.Slice(utils.Fragment.from(newNode), 0, 0), 1, true));
|
|
7191
|
+
tr.step(new ReplaceAroundStep$1(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new utils.Slice(utils.Fragment.from(newNode), 0, 0), 1, true));
|
|
7190
7192
|
}
|
|
7191
7193
|
/**
|
|
7192
7194
|
Check whether splitting at the given position is allowed.
|
|
7193
7195
|
*/
|
|
7194
|
-
function canSplit(doc, pos, depth = 1, typesAfter) {
|
|
7196
|
+
function canSplit$1(doc, pos, depth = 1, typesAfter) {
|
|
7195
7197
|
let $pos = doc.resolve(pos), base = $pos.depth - depth;
|
|
7196
7198
|
let innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent;
|
|
7197
7199
|
if (base < 0 || $pos.parent.type.spec.isolating ||
|
|
@@ -7221,18 +7223,18 @@ function split(tr, pos, depth = 1, typesAfter) {
|
|
|
7221
7223
|
let typeAfter = typesAfter && typesAfter[i];
|
|
7222
7224
|
after = utils.Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));
|
|
7223
7225
|
}
|
|
7224
|
-
tr.step(new ReplaceStep(pos, pos, new utils.Slice(before.append(after), depth, depth), true));
|
|
7226
|
+
tr.step(new ReplaceStep$1(pos, pos, new utils.Slice(before.append(after), depth, depth), true));
|
|
7225
7227
|
}
|
|
7226
7228
|
/**
|
|
7227
7229
|
Test whether the blocks before and after a given position can be
|
|
7228
7230
|
joined.
|
|
7229
7231
|
*/
|
|
7230
|
-
function canJoin(doc, pos) {
|
|
7232
|
+
function canJoin$1(doc, pos) {
|
|
7231
7233
|
let $pos = doc.resolve(pos), index = $pos.index();
|
|
7232
|
-
return joinable($pos.nodeBefore, $pos.nodeAfter) &&
|
|
7234
|
+
return joinable$1($pos.nodeBefore, $pos.nodeAfter) &&
|
|
7233
7235
|
$pos.parent.canReplace(index, index + 1);
|
|
7234
7236
|
}
|
|
7235
|
-
function joinable(a, b) {
|
|
7237
|
+
function joinable$1(a, b) {
|
|
7236
7238
|
return !!(a && b && !a.isLeaf && a.canAppend(b));
|
|
7237
7239
|
}
|
|
7238
7240
|
/**
|
|
@@ -7257,7 +7259,7 @@ function joinPoint(doc, pos, dir = -1) {
|
|
|
7257
7259
|
before = $pos.node(d).maybeChild(index - 1);
|
|
7258
7260
|
after = $pos.node(d + 1);
|
|
7259
7261
|
}
|
|
7260
|
-
if (before && !before.isTextblock && joinable(before, after) &&
|
|
7262
|
+
if (before && !before.isTextblock && joinable$1(before, after) &&
|
|
7261
7263
|
$pos.node(d).canReplace(index, index + 1))
|
|
7262
7264
|
return pos;
|
|
7263
7265
|
if (d == 0)
|
|
@@ -7266,7 +7268,7 @@ function joinPoint(doc, pos, dir = -1) {
|
|
|
7266
7268
|
}
|
|
7267
7269
|
}
|
|
7268
7270
|
function join(tr, pos, depth) {
|
|
7269
|
-
let step = new ReplaceStep(pos - depth, pos + depth, utils.Slice.empty, true);
|
|
7271
|
+
let step = new ReplaceStep$1(pos - depth, pos + depth, utils.Slice.empty, true);
|
|
7270
7272
|
tr.step(step);
|
|
7271
7273
|
}
|
|
7272
7274
|
/**
|
|
@@ -7310,7 +7312,7 @@ function replaceStep(doc, from, to = from, slice = utils.Slice.empty) {
|
|
|
7310
7312
|
let $from = doc.resolve(from), $to = doc.resolve(to);
|
|
7311
7313
|
// Optimization -- avoid work if it's obvious that it's not needed.
|
|
7312
7314
|
if (fitsTrivially($from, $to, slice))
|
|
7313
|
-
return new ReplaceStep(from, to, slice);
|
|
7315
|
+
return new ReplaceStep$1(from, to, slice);
|
|
7314
7316
|
return new Fitter($from, $to, slice).fit();
|
|
7315
7317
|
}
|
|
7316
7318
|
function fitsTrivially($from, $to, slice) {
|
|
@@ -7384,9 +7386,9 @@ class Fitter {
|
|
|
7384
7386
|
}
|
|
7385
7387
|
let slice = new utils.Slice(content, openStart, openEnd);
|
|
7386
7388
|
if (moveInline > -1)
|
|
7387
|
-
return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
|
|
7389
|
+
return new ReplaceAroundStep$1($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
|
|
7388
7390
|
if (slice.size || $from.pos != this.$to.pos) // Don't generate no-op steps
|
|
7389
|
-
return new ReplaceStep($from.pos, $to.pos, slice);
|
|
7391
|
+
return new ReplaceStep$1($from.pos, $to.pos, slice);
|
|
7390
7392
|
return null;
|
|
7391
7393
|
}
|
|
7392
7394
|
// Find a position on the start spine of `this.unplaced` that has
|
|
@@ -7617,7 +7619,7 @@ function replaceRange(tr, from, to, slice) {
|
|
|
7617
7619
|
return tr.deleteRange(from, to);
|
|
7618
7620
|
let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
|
|
7619
7621
|
if (fitsTrivially($from, $to, slice))
|
|
7620
|
-
return tr.step(new ReplaceStep(from, to, slice));
|
|
7622
|
+
return tr.step(new ReplaceStep$1(from, to, slice));
|
|
7621
7623
|
let targetDepths = coveredDepths($from, tr.doc.resolve(to));
|
|
7622
7624
|
// Can't replace the whole document, so remove 0 if it's present
|
|
7623
7625
|
if (targetDepths[targetDepths.length - 1] == 0)
|
|
@@ -7747,7 +7749,7 @@ function coveredDepths($from, $to) {
|
|
|
7747
7749
|
/**
|
|
7748
7750
|
Update an attribute in a specific node.
|
|
7749
7751
|
*/
|
|
7750
|
-
class AttrStep extends Step {
|
|
7752
|
+
class AttrStep$1 extends Step$1 {
|
|
7751
7753
|
/**
|
|
7752
7754
|
Construct an attribute step.
|
|
7753
7755
|
*/
|
|
@@ -7770,23 +7772,23 @@ class AttrStep extends Step {
|
|
|
7770
7772
|
apply(doc) {
|
|
7771
7773
|
let node = doc.nodeAt(this.pos);
|
|
7772
7774
|
if (!node)
|
|
7773
|
-
return StepResult.fail("No node at attribute step's position");
|
|
7775
|
+
return StepResult$1.fail("No node at attribute step's position");
|
|
7774
7776
|
let attrs = Object.create(null);
|
|
7775
7777
|
for (let name in node.attrs)
|
|
7776
7778
|
attrs[name] = node.attrs[name];
|
|
7777
7779
|
attrs[this.attr] = this.value;
|
|
7778
7780
|
let updated = node.type.create(attrs, null, node.marks);
|
|
7779
|
-
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
7781
|
+
return StepResult$1.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
7780
7782
|
}
|
|
7781
7783
|
getMap() {
|
|
7782
|
-
return StepMap.empty;
|
|
7784
|
+
return StepMap$1.empty;
|
|
7783
7785
|
}
|
|
7784
7786
|
invert(doc) {
|
|
7785
|
-
return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
7787
|
+
return new AttrStep$1(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
7786
7788
|
}
|
|
7787
7789
|
map(mapping) {
|
|
7788
7790
|
let pos = mapping.mapResult(this.pos, 1);
|
|
7789
|
-
return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
|
|
7791
|
+
return pos.deletedAfter ? null : new AttrStep$1(pos.pos, this.attr, this.value);
|
|
7790
7792
|
}
|
|
7791
7793
|
toJSON() {
|
|
7792
7794
|
return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
|
|
@@ -7794,14 +7796,14 @@ class AttrStep extends Step {
|
|
|
7794
7796
|
static fromJSON(schema, json) {
|
|
7795
7797
|
if (typeof json.pos != "number" || typeof json.attr != "string")
|
|
7796
7798
|
throw new RangeError("Invalid input for AttrStep.fromJSON");
|
|
7797
|
-
return new AttrStep(json.pos, json.attr, json.value);
|
|
7799
|
+
return new AttrStep$1(json.pos, json.attr, json.value);
|
|
7798
7800
|
}
|
|
7799
7801
|
}
|
|
7800
|
-
Step.jsonID("attr", AttrStep);
|
|
7802
|
+
Step$1.jsonID("attr", AttrStep$1);
|
|
7801
7803
|
/**
|
|
7802
7804
|
Update an attribute in the doc node.
|
|
7803
7805
|
*/
|
|
7804
|
-
class DocAttrStep extends Step {
|
|
7806
|
+
class DocAttrStep$1 extends Step$1 {
|
|
7805
7807
|
/**
|
|
7806
7808
|
Construct an attribute step.
|
|
7807
7809
|
*/
|
|
@@ -7822,13 +7824,13 @@ class DocAttrStep extends Step {
|
|
|
7822
7824
|
attrs[name] = doc.attrs[name];
|
|
7823
7825
|
attrs[this.attr] = this.value;
|
|
7824
7826
|
let updated = doc.type.create(attrs, doc.content, doc.marks);
|
|
7825
|
-
return StepResult.ok(updated);
|
|
7827
|
+
return StepResult$1.ok(updated);
|
|
7826
7828
|
}
|
|
7827
7829
|
getMap() {
|
|
7828
|
-
return StepMap.empty;
|
|
7830
|
+
return StepMap$1.empty;
|
|
7829
7831
|
}
|
|
7830
7832
|
invert(doc) {
|
|
7831
|
-
return new DocAttrStep(this.attr, doc.attrs[this.attr]);
|
|
7833
|
+
return new DocAttrStep$1(this.attr, doc.attrs[this.attr]);
|
|
7832
7834
|
}
|
|
7833
7835
|
map(mapping) {
|
|
7834
7836
|
return this;
|
|
@@ -7839,24 +7841,24 @@ class DocAttrStep extends Step {
|
|
|
7839
7841
|
static fromJSON(schema, json) {
|
|
7840
7842
|
if (typeof json.attr != "string")
|
|
7841
7843
|
throw new RangeError("Invalid input for DocAttrStep.fromJSON");
|
|
7842
|
-
return new DocAttrStep(json.attr, json.value);
|
|
7844
|
+
return new DocAttrStep$1(json.attr, json.value);
|
|
7843
7845
|
}
|
|
7844
7846
|
}
|
|
7845
|
-
Step.jsonID("docAttr", DocAttrStep);
|
|
7847
|
+
Step$1.jsonID("docAttr", DocAttrStep$1);
|
|
7846
7848
|
|
|
7847
7849
|
/**
|
|
7848
7850
|
@internal
|
|
7849
7851
|
*/
|
|
7850
|
-
let TransformError = class extends Error {
|
|
7852
|
+
let TransformError$1 = class extends Error {
|
|
7851
7853
|
};
|
|
7852
|
-
TransformError = function TransformError(message) {
|
|
7854
|
+
TransformError$1 = function TransformError(message) {
|
|
7853
7855
|
let err = Error.call(this, message);
|
|
7854
7856
|
err.__proto__ = TransformError.prototype;
|
|
7855
7857
|
return err;
|
|
7856
7858
|
};
|
|
7857
|
-
TransformError.prototype = Object.create(Error.prototype);
|
|
7858
|
-
TransformError.prototype.constructor = TransformError;
|
|
7859
|
-
TransformError.prototype.name = "TransformError";
|
|
7859
|
+
TransformError$1.prototype = Object.create(Error.prototype);
|
|
7860
|
+
TransformError$1.prototype.constructor = TransformError$1;
|
|
7861
|
+
TransformError$1.prototype.name = "TransformError";
|
|
7860
7862
|
/**
|
|
7861
7863
|
Abstraction to build up and track an array of
|
|
7862
7864
|
[steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.
|
|
@@ -7899,7 +7901,7 @@ class Transform {
|
|
|
7899
7901
|
step(step) {
|
|
7900
7902
|
let result = this.maybeStep(step);
|
|
7901
7903
|
if (result.failed)
|
|
7902
|
-
throw new TransformError(result.failed);
|
|
7904
|
+
throw new TransformError$1(result.failed);
|
|
7903
7905
|
return this;
|
|
7904
7906
|
}
|
|
7905
7907
|
/**
|
|
@@ -8051,21 +8053,21 @@ class Transform {
|
|
|
8051
8053
|
to set attributes on the document itself.
|
|
8052
8054
|
*/
|
|
8053
8055
|
setNodeAttribute(pos, attr, value) {
|
|
8054
|
-
this.step(new AttrStep(pos, attr, value));
|
|
8056
|
+
this.step(new AttrStep$1(pos, attr, value));
|
|
8055
8057
|
return this;
|
|
8056
8058
|
}
|
|
8057
8059
|
/**
|
|
8058
8060
|
Set a single attribute on the document to a new value.
|
|
8059
8061
|
*/
|
|
8060
8062
|
setDocAttribute(attr, value) {
|
|
8061
|
-
this.step(new DocAttrStep(attr, value));
|
|
8063
|
+
this.step(new DocAttrStep$1(attr, value));
|
|
8062
8064
|
return this;
|
|
8063
8065
|
}
|
|
8064
8066
|
/**
|
|
8065
8067
|
Add a mark to the node at position `pos`.
|
|
8066
8068
|
*/
|
|
8067
8069
|
addNodeMark(pos, mark) {
|
|
8068
|
-
this.step(new AddNodeMarkStep(pos, mark));
|
|
8070
|
+
this.step(new AddNodeMarkStep$1(pos, mark));
|
|
8069
8071
|
return this;
|
|
8070
8072
|
}
|
|
8071
8073
|
/**
|
|
@@ -8081,7 +8083,7 @@ class Transform {
|
|
|
8081
8083
|
if (!mark)
|
|
8082
8084
|
return this;
|
|
8083
8085
|
}
|
|
8084
|
-
this.step(new RemoveNodeMarkStep(pos, mark));
|
|
8086
|
+
this.step(new RemoveNodeMarkStep$1(pos, mark));
|
|
8085
8087
|
return this;
|
|
8086
8088
|
}
|
|
8087
8089
|
/**
|
|
@@ -8166,21 +8168,26 @@ const joinBackward$1 = (state, dispatch, view) => {
|
|
|
8166
8168
|
}
|
|
8167
8169
|
let before = $cut.nodeBefore;
|
|
8168
8170
|
// Apply the joining algorithm
|
|
8169
|
-
if (
|
|
8171
|
+
if (deleteBarrier(state, $cut, dispatch, -1))
|
|
8170
8172
|
return true;
|
|
8171
8173
|
// If the node below has no content and the node above is
|
|
8172
8174
|
// selectable, delete the node below and select the one above.
|
|
8173
8175
|
if ($cursor.parent.content.size == 0 &&
|
|
8174
8176
|
(textblockAt(before, "end") || utils.NodeSelection.isSelectable(before))) {
|
|
8175
|
-
let
|
|
8176
|
-
|
|
8177
|
-
if (
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8177
|
+
for (let depth = $cursor.depth;; depth--) {
|
|
8178
|
+
let delStep = utils.replaceStep(state.doc, $cursor.before(depth), $cursor.after(depth), utils.Slice.empty);
|
|
8179
|
+
if (delStep && delStep.slice.size < delStep.to - delStep.from) {
|
|
8180
|
+
if (dispatch) {
|
|
8181
|
+
let tr = state.tr.step(delStep);
|
|
8182
|
+
tr.setSelection(textblockAt(before, "end")
|
|
8183
|
+
? utils.Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos, -1)), -1)
|
|
8184
|
+
: utils.NodeSelection.create(tr.doc, $cut.pos - before.nodeSize));
|
|
8185
|
+
dispatch(tr.scrollIntoView());
|
|
8186
|
+
}
|
|
8187
|
+
return true;
|
|
8182
8188
|
}
|
|
8183
|
-
|
|
8189
|
+
if (depth == 1 || $cursor.node(depth - 1).childCount > 1)
|
|
8190
|
+
break;
|
|
8184
8191
|
}
|
|
8185
8192
|
}
|
|
8186
8193
|
// If the node before is an atom, delete it
|
|
@@ -8312,7 +8319,7 @@ const joinForward$1 = (state, dispatch, view) => {
|
|
|
8312
8319
|
return false;
|
|
8313
8320
|
let after = $cut.nodeAfter;
|
|
8314
8321
|
// Try the joining algorithm
|
|
8315
|
-
if (deleteBarrier(state, $cut, dispatch))
|
|
8322
|
+
if (deleteBarrier(state, $cut, dispatch, 1))
|
|
8316
8323
|
return true;
|
|
8317
8324
|
// If the node above has no content and the node below is
|
|
8318
8325
|
// selectable, delete the node above and select the one below.
|
|
@@ -8544,13 +8551,12 @@ function joinMaybeClear(state, $pos, dispatch) {
|
|
|
8544
8551
|
.scrollIntoView());
|
|
8545
8552
|
return true;
|
|
8546
8553
|
}
|
|
8547
|
-
function deleteBarrier(state, $cut, dispatch) {
|
|
8554
|
+
function deleteBarrier(state, $cut, dispatch, dir) {
|
|
8548
8555
|
let before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match;
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
if (joinMaybeClear(state, $cut, dispatch))
|
|
8556
|
+
let isolated = before.type.spec.isolating || after.type.spec.isolating;
|
|
8557
|
+
if (!isolated && joinMaybeClear(state, $cut, dispatch))
|
|
8552
8558
|
return true;
|
|
8553
|
-
let canDelAfter = $cut.parent.canReplace($cut.index(), $cut.index() + 1);
|
|
8559
|
+
let canDelAfter = !isolated && $cut.parent.canReplace($cut.index(), $cut.index() + 1);
|
|
8554
8560
|
if (canDelAfter &&
|
|
8555
8561
|
(conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) &&
|
|
8556
8562
|
match.matchType(conn[0] || after.type).validEnd) {
|
|
@@ -8567,7 +8573,7 @@ function deleteBarrier(state, $cut, dispatch) {
|
|
|
8567
8573
|
}
|
|
8568
8574
|
return true;
|
|
8569
8575
|
}
|
|
8570
|
-
let selAfter = utils.Selection.findFrom($cut, 1);
|
|
8576
|
+
let selAfter = after.type.spec.isolating || (dir > 0 && isolated) ? null : utils.Selection.findFrom($cut, 1);
|
|
8571
8577
|
let range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && utils.liftTarget(range);
|
|
8572
8578
|
if (target != null && target >= $cut.depth) {
|
|
8573
8579
|
if (dispatch)
|
|
@@ -8678,6 +8684,949 @@ typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform)
|
|
|
8678
8684
|
// @ts-ignore
|
|
8679
8685
|
: typeof os != "undefined" && os.platform ? os.platform() == "darwin" : false;
|
|
8680
8686
|
|
|
8687
|
+
// Recovery values encode a range index and an offset. They are
|
|
8688
|
+
// represented as numbers, because tons of them will be created when
|
|
8689
|
+
// mapping, for example, a large number of decorations. The number's
|
|
8690
|
+
// lower 16 bits provide the index, the remaining bits the offset.
|
|
8691
|
+
//
|
|
8692
|
+
// Note: We intentionally don't use bit shift operators to en- and
|
|
8693
|
+
// decode these, since those clip to 32 bits, which we might in rare
|
|
8694
|
+
// cases want to overflow. A 64-bit float can represent 48-bit
|
|
8695
|
+
// integers precisely.
|
|
8696
|
+
const lower16 = 0xffff;
|
|
8697
|
+
const factor16 = Math.pow(2, 16);
|
|
8698
|
+
function makeRecover(index, offset) { return index + offset * factor16; }
|
|
8699
|
+
function recoverIndex(value) { return value & lower16; }
|
|
8700
|
+
function recoverOffset(value) { return (value - (value & lower16)) / factor16; }
|
|
8701
|
+
const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;
|
|
8702
|
+
/**
|
|
8703
|
+
An object representing a mapped position with extra
|
|
8704
|
+
information.
|
|
8705
|
+
*/
|
|
8706
|
+
class MapResult {
|
|
8707
|
+
/**
|
|
8708
|
+
@internal
|
|
8709
|
+
*/
|
|
8710
|
+
constructor(
|
|
8711
|
+
/**
|
|
8712
|
+
The mapped version of the position.
|
|
8713
|
+
*/
|
|
8714
|
+
pos,
|
|
8715
|
+
/**
|
|
8716
|
+
@internal
|
|
8717
|
+
*/
|
|
8718
|
+
delInfo,
|
|
8719
|
+
/**
|
|
8720
|
+
@internal
|
|
8721
|
+
*/
|
|
8722
|
+
recover) {
|
|
8723
|
+
this.pos = pos;
|
|
8724
|
+
this.delInfo = delInfo;
|
|
8725
|
+
this.recover = recover;
|
|
8726
|
+
}
|
|
8727
|
+
/**
|
|
8728
|
+
Tells you whether the position was deleted, that is, whether the
|
|
8729
|
+
step removed the token on the side queried (via the `assoc`)
|
|
8730
|
+
argument from the document.
|
|
8731
|
+
*/
|
|
8732
|
+
get deleted() { return (this.delInfo & DEL_SIDE) > 0; }
|
|
8733
|
+
/**
|
|
8734
|
+
Tells you whether the token before the mapped position was deleted.
|
|
8735
|
+
*/
|
|
8736
|
+
get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; }
|
|
8737
|
+
/**
|
|
8738
|
+
True when the token after the mapped position was deleted.
|
|
8739
|
+
*/
|
|
8740
|
+
get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; }
|
|
8741
|
+
/**
|
|
8742
|
+
Tells whether any of the steps mapped through deletes across the
|
|
8743
|
+
position (including both the token before and after the
|
|
8744
|
+
position).
|
|
8745
|
+
*/
|
|
8746
|
+
get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; }
|
|
8747
|
+
}
|
|
8748
|
+
/**
|
|
8749
|
+
A map describing the deletions and insertions made by a step, which
|
|
8750
|
+
can be used to find the correspondence between positions in the
|
|
8751
|
+
pre-step version of a document and the same position in the
|
|
8752
|
+
post-step version.
|
|
8753
|
+
*/
|
|
8754
|
+
class StepMap {
|
|
8755
|
+
/**
|
|
8756
|
+
Create a position map. The modifications to the document are
|
|
8757
|
+
represented as an array of numbers, in which each group of three
|
|
8758
|
+
represents a modified chunk as `[start, oldSize, newSize]`.
|
|
8759
|
+
*/
|
|
8760
|
+
constructor(
|
|
8761
|
+
/**
|
|
8762
|
+
@internal
|
|
8763
|
+
*/
|
|
8764
|
+
ranges,
|
|
8765
|
+
/**
|
|
8766
|
+
@internal
|
|
8767
|
+
*/
|
|
8768
|
+
inverted = false) {
|
|
8769
|
+
this.ranges = ranges;
|
|
8770
|
+
this.inverted = inverted;
|
|
8771
|
+
if (!ranges.length && StepMap.empty)
|
|
8772
|
+
return StepMap.empty;
|
|
8773
|
+
}
|
|
8774
|
+
/**
|
|
8775
|
+
@internal
|
|
8776
|
+
*/
|
|
8777
|
+
recover(value) {
|
|
8778
|
+
let diff = 0, index = recoverIndex(value);
|
|
8779
|
+
if (!this.inverted)
|
|
8780
|
+
for (let i = 0; i < index; i++)
|
|
8781
|
+
diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
|
|
8782
|
+
return this.ranges[index * 3] + diff + recoverOffset(value);
|
|
8783
|
+
}
|
|
8784
|
+
mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }
|
|
8785
|
+
map(pos, assoc = 1) { return this._map(pos, assoc, true); }
|
|
8786
|
+
/**
|
|
8787
|
+
@internal
|
|
8788
|
+
*/
|
|
8789
|
+
_map(pos, assoc, simple) {
|
|
8790
|
+
let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
8791
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
8792
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
8793
|
+
if (start > pos)
|
|
8794
|
+
break;
|
|
8795
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
|
|
8796
|
+
if (pos <= end) {
|
|
8797
|
+
let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
|
|
8798
|
+
let result = start + diff + (side < 0 ? 0 : newSize);
|
|
8799
|
+
if (simple)
|
|
8800
|
+
return result;
|
|
8801
|
+
let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
|
|
8802
|
+
let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
|
|
8803
|
+
if (assoc < 0 ? pos != start : pos != end)
|
|
8804
|
+
del |= DEL_SIDE;
|
|
8805
|
+
return new MapResult(result, del, recover);
|
|
8806
|
+
}
|
|
8807
|
+
diff += newSize - oldSize;
|
|
8808
|
+
}
|
|
8809
|
+
return simple ? pos + diff : new MapResult(pos + diff, 0, null);
|
|
8810
|
+
}
|
|
8811
|
+
/**
|
|
8812
|
+
@internal
|
|
8813
|
+
*/
|
|
8814
|
+
touches(pos, recover) {
|
|
8815
|
+
let diff = 0, index = recoverIndex(recover);
|
|
8816
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
8817
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
8818
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
8819
|
+
if (start > pos)
|
|
8820
|
+
break;
|
|
8821
|
+
let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
|
|
8822
|
+
if (pos <= end && i == index * 3)
|
|
8823
|
+
return true;
|
|
8824
|
+
diff += this.ranges[i + newIndex] - oldSize;
|
|
8825
|
+
}
|
|
8826
|
+
return false;
|
|
8827
|
+
}
|
|
8828
|
+
/**
|
|
8829
|
+
Calls the given function on each of the changed ranges included in
|
|
8830
|
+
this map.
|
|
8831
|
+
*/
|
|
8832
|
+
forEach(f) {
|
|
8833
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
8834
|
+
for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
|
|
8835
|
+
let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
|
|
8836
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
|
|
8837
|
+
f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
|
|
8838
|
+
diff += newSize - oldSize;
|
|
8839
|
+
}
|
|
8840
|
+
}
|
|
8841
|
+
/**
|
|
8842
|
+
Create an inverted version of this map. The result can be used to
|
|
8843
|
+
map positions in the post-step document to the pre-step document.
|
|
8844
|
+
*/
|
|
8845
|
+
invert() {
|
|
8846
|
+
return new StepMap(this.ranges, !this.inverted);
|
|
8847
|
+
}
|
|
8848
|
+
/**
|
|
8849
|
+
@internal
|
|
8850
|
+
*/
|
|
8851
|
+
toString() {
|
|
8852
|
+
return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
|
|
8853
|
+
}
|
|
8854
|
+
/**
|
|
8855
|
+
Create a map that moves all positions by offset `n` (which may be
|
|
8856
|
+
negative). This can be useful when applying steps meant for a
|
|
8857
|
+
sub-document to a larger document, or vice-versa.
|
|
8858
|
+
*/
|
|
8859
|
+
static offset(n) {
|
|
8860
|
+
return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
8861
|
+
}
|
|
8862
|
+
}
|
|
8863
|
+
/**
|
|
8864
|
+
A StepMap that contains no changed ranges.
|
|
8865
|
+
*/
|
|
8866
|
+
StepMap.empty = new StepMap([]);
|
|
8867
|
+
|
|
8868
|
+
const stepsByID = Object.create(null);
|
|
8869
|
+
/**
|
|
8870
|
+
A step object represents an atomic change. It generally applies
|
|
8871
|
+
only to the document it was created for, since the positions
|
|
8872
|
+
stored in it will only make sense for that document.
|
|
8873
|
+
|
|
8874
|
+
New steps are defined by creating classes that extend `Step`,
|
|
8875
|
+
overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`
|
|
8876
|
+
methods, and registering your class with a unique
|
|
8877
|
+
JSON-serialization identifier using
|
|
8878
|
+
[`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).
|
|
8879
|
+
*/
|
|
8880
|
+
class Step {
|
|
8881
|
+
/**
|
|
8882
|
+
Get the step map that represents the changes made by this step,
|
|
8883
|
+
and which can be used to transform between positions in the old
|
|
8884
|
+
and the new document.
|
|
8885
|
+
*/
|
|
8886
|
+
getMap() { return StepMap.empty; }
|
|
8887
|
+
/**
|
|
8888
|
+
Try to merge this step with another one, to be applied directly
|
|
8889
|
+
after it. Returns the merged step when possible, null if the
|
|
8890
|
+
steps can't be merged.
|
|
8891
|
+
*/
|
|
8892
|
+
merge(other) { return null; }
|
|
8893
|
+
/**
|
|
8894
|
+
Deserialize a step from its JSON representation. Will call
|
|
8895
|
+
through to the step class' own implementation of this method.
|
|
8896
|
+
*/
|
|
8897
|
+
static fromJSON(schema, json) {
|
|
8898
|
+
if (!json || !json.stepType)
|
|
8899
|
+
throw new RangeError("Invalid input for Step.fromJSON");
|
|
8900
|
+
let type = stepsByID[json.stepType];
|
|
8901
|
+
if (!type)
|
|
8902
|
+
throw new RangeError(`No step type ${json.stepType} defined`);
|
|
8903
|
+
return type.fromJSON(schema, json);
|
|
8904
|
+
}
|
|
8905
|
+
/**
|
|
8906
|
+
To be able to serialize steps to JSON, each step needs a string
|
|
8907
|
+
ID to attach to its JSON representation. Use this method to
|
|
8908
|
+
register an ID for your step classes. Try to pick something
|
|
8909
|
+
that's unlikely to clash with steps from other modules.
|
|
8910
|
+
*/
|
|
8911
|
+
static jsonID(id, stepClass) {
|
|
8912
|
+
if (id in stepsByID)
|
|
8913
|
+
throw new RangeError("Duplicate use of step JSON ID " + id);
|
|
8914
|
+
stepsByID[id] = stepClass;
|
|
8915
|
+
stepClass.prototype.jsonID = id;
|
|
8916
|
+
return stepClass;
|
|
8917
|
+
}
|
|
8918
|
+
}
|
|
8919
|
+
/**
|
|
8920
|
+
The result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a
|
|
8921
|
+
new document or a failure value.
|
|
8922
|
+
*/
|
|
8923
|
+
class StepResult {
|
|
8924
|
+
/**
|
|
8925
|
+
@internal
|
|
8926
|
+
*/
|
|
8927
|
+
constructor(
|
|
8928
|
+
/**
|
|
8929
|
+
The transformed document, if successful.
|
|
8930
|
+
*/
|
|
8931
|
+
doc,
|
|
8932
|
+
/**
|
|
8933
|
+
The failure message, if unsuccessful.
|
|
8934
|
+
*/
|
|
8935
|
+
failed) {
|
|
8936
|
+
this.doc = doc;
|
|
8937
|
+
this.failed = failed;
|
|
8938
|
+
}
|
|
8939
|
+
/**
|
|
8940
|
+
Create a successful step result.
|
|
8941
|
+
*/
|
|
8942
|
+
static ok(doc) { return new StepResult(doc, null); }
|
|
8943
|
+
/**
|
|
8944
|
+
Create a failed step result.
|
|
8945
|
+
*/
|
|
8946
|
+
static fail(message) { return new StepResult(null, message); }
|
|
8947
|
+
/**
|
|
8948
|
+
Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
|
|
8949
|
+
arguments. Create a successful result if it succeeds, and a
|
|
8950
|
+
failed one if it throws a `ReplaceError`.
|
|
8951
|
+
*/
|
|
8952
|
+
static fromReplace(doc, from, to, slice) {
|
|
8953
|
+
try {
|
|
8954
|
+
return StepResult.ok(doc.replace(from, to, slice));
|
|
8955
|
+
}
|
|
8956
|
+
catch (e) {
|
|
8957
|
+
if (e instanceof utils.ReplaceError)
|
|
8958
|
+
return StepResult.fail(e.message);
|
|
8959
|
+
throw e;
|
|
8960
|
+
}
|
|
8961
|
+
}
|
|
8962
|
+
}
|
|
8963
|
+
|
|
8964
|
+
function mapFragment(fragment, f, parent) {
|
|
8965
|
+
let mapped = [];
|
|
8966
|
+
for (let i = 0; i < fragment.childCount; i++) {
|
|
8967
|
+
let child = fragment.child(i);
|
|
8968
|
+
if (child.content.size)
|
|
8969
|
+
child = child.copy(mapFragment(child.content, f, child));
|
|
8970
|
+
if (child.isInline)
|
|
8971
|
+
child = f(child, parent, i);
|
|
8972
|
+
mapped.push(child);
|
|
8973
|
+
}
|
|
8974
|
+
return utils.Fragment.fromArray(mapped);
|
|
8975
|
+
}
|
|
8976
|
+
/**
|
|
8977
|
+
Add a mark to all inline content between two positions.
|
|
8978
|
+
*/
|
|
8979
|
+
class AddMarkStep extends Step {
|
|
8980
|
+
/**
|
|
8981
|
+
Create a mark step.
|
|
8982
|
+
*/
|
|
8983
|
+
constructor(
|
|
8984
|
+
/**
|
|
8985
|
+
The start of the marked range.
|
|
8986
|
+
*/
|
|
8987
|
+
from,
|
|
8988
|
+
/**
|
|
8989
|
+
The end of the marked range.
|
|
8990
|
+
*/
|
|
8991
|
+
to,
|
|
8992
|
+
/**
|
|
8993
|
+
The mark to add.
|
|
8994
|
+
*/
|
|
8995
|
+
mark) {
|
|
8996
|
+
super();
|
|
8997
|
+
this.from = from;
|
|
8998
|
+
this.to = to;
|
|
8999
|
+
this.mark = mark;
|
|
9000
|
+
}
|
|
9001
|
+
apply(doc) {
|
|
9002
|
+
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
|
|
9003
|
+
let parent = $from.node($from.sharedDepth(this.to));
|
|
9004
|
+
let slice = new utils.Slice(mapFragment(oldSlice.content, (node, parent) => {
|
|
9005
|
+
if (!node.isAtom || !parent.type.allowsMarkType(this.mark.type))
|
|
9006
|
+
return node;
|
|
9007
|
+
return node.mark(this.mark.addToSet(node.marks));
|
|
9008
|
+
}, parent), oldSlice.openStart, oldSlice.openEnd);
|
|
9009
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
9010
|
+
}
|
|
9011
|
+
invert() {
|
|
9012
|
+
return new RemoveMarkStep(this.from, this.to, this.mark);
|
|
9013
|
+
}
|
|
9014
|
+
map(mapping) {
|
|
9015
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
9016
|
+
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
9017
|
+
return null;
|
|
9018
|
+
return new AddMarkStep(from.pos, to.pos, this.mark);
|
|
9019
|
+
}
|
|
9020
|
+
merge(other) {
|
|
9021
|
+
if (other instanceof AddMarkStep &&
|
|
9022
|
+
other.mark.eq(this.mark) &&
|
|
9023
|
+
this.from <= other.to && this.to >= other.from)
|
|
9024
|
+
return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
9025
|
+
return null;
|
|
9026
|
+
}
|
|
9027
|
+
toJSON() {
|
|
9028
|
+
return { stepType: "addMark", mark: this.mark.toJSON(),
|
|
9029
|
+
from: this.from, to: this.to };
|
|
9030
|
+
}
|
|
9031
|
+
/**
|
|
9032
|
+
@internal
|
|
9033
|
+
*/
|
|
9034
|
+
static fromJSON(schema, json) {
|
|
9035
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
9036
|
+
throw new RangeError("Invalid input for AddMarkStep.fromJSON");
|
|
9037
|
+
return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
9038
|
+
}
|
|
9039
|
+
}
|
|
9040
|
+
Step.jsonID("addMark", AddMarkStep);
|
|
9041
|
+
/**
|
|
9042
|
+
Remove a mark from all inline content between two positions.
|
|
9043
|
+
*/
|
|
9044
|
+
class RemoveMarkStep extends Step {
|
|
9045
|
+
/**
|
|
9046
|
+
Create a mark-removing step.
|
|
9047
|
+
*/
|
|
9048
|
+
constructor(
|
|
9049
|
+
/**
|
|
9050
|
+
The start of the unmarked range.
|
|
9051
|
+
*/
|
|
9052
|
+
from,
|
|
9053
|
+
/**
|
|
9054
|
+
The end of the unmarked range.
|
|
9055
|
+
*/
|
|
9056
|
+
to,
|
|
9057
|
+
/**
|
|
9058
|
+
The mark to remove.
|
|
9059
|
+
*/
|
|
9060
|
+
mark) {
|
|
9061
|
+
super();
|
|
9062
|
+
this.from = from;
|
|
9063
|
+
this.to = to;
|
|
9064
|
+
this.mark = mark;
|
|
9065
|
+
}
|
|
9066
|
+
apply(doc) {
|
|
9067
|
+
let oldSlice = doc.slice(this.from, this.to);
|
|
9068
|
+
let slice = new utils.Slice(mapFragment(oldSlice.content, node => {
|
|
9069
|
+
return node.mark(this.mark.removeFromSet(node.marks));
|
|
9070
|
+
}, doc), oldSlice.openStart, oldSlice.openEnd);
|
|
9071
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
9072
|
+
}
|
|
9073
|
+
invert() {
|
|
9074
|
+
return new AddMarkStep(this.from, this.to, this.mark);
|
|
9075
|
+
}
|
|
9076
|
+
map(mapping) {
|
|
9077
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
9078
|
+
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
9079
|
+
return null;
|
|
9080
|
+
return new RemoveMarkStep(from.pos, to.pos, this.mark);
|
|
9081
|
+
}
|
|
9082
|
+
merge(other) {
|
|
9083
|
+
if (other instanceof RemoveMarkStep &&
|
|
9084
|
+
other.mark.eq(this.mark) &&
|
|
9085
|
+
this.from <= other.to && this.to >= other.from)
|
|
9086
|
+
return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
9087
|
+
return null;
|
|
9088
|
+
}
|
|
9089
|
+
toJSON() {
|
|
9090
|
+
return { stepType: "removeMark", mark: this.mark.toJSON(),
|
|
9091
|
+
from: this.from, to: this.to };
|
|
9092
|
+
}
|
|
9093
|
+
/**
|
|
9094
|
+
@internal
|
|
9095
|
+
*/
|
|
9096
|
+
static fromJSON(schema, json) {
|
|
9097
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
9098
|
+
throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
|
|
9099
|
+
return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
9100
|
+
}
|
|
9101
|
+
}
|
|
9102
|
+
Step.jsonID("removeMark", RemoveMarkStep);
|
|
9103
|
+
/**
|
|
9104
|
+
Add a mark to a specific node.
|
|
9105
|
+
*/
|
|
9106
|
+
class AddNodeMarkStep extends Step {
|
|
9107
|
+
/**
|
|
9108
|
+
Create a node mark step.
|
|
9109
|
+
*/
|
|
9110
|
+
constructor(
|
|
9111
|
+
/**
|
|
9112
|
+
The position of the target node.
|
|
9113
|
+
*/
|
|
9114
|
+
pos,
|
|
9115
|
+
/**
|
|
9116
|
+
The mark to add.
|
|
9117
|
+
*/
|
|
9118
|
+
mark) {
|
|
9119
|
+
super();
|
|
9120
|
+
this.pos = pos;
|
|
9121
|
+
this.mark = mark;
|
|
9122
|
+
}
|
|
9123
|
+
apply(doc) {
|
|
9124
|
+
let node = doc.nodeAt(this.pos);
|
|
9125
|
+
if (!node)
|
|
9126
|
+
return StepResult.fail("No node at mark step's position");
|
|
9127
|
+
let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
|
|
9128
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
9129
|
+
}
|
|
9130
|
+
invert(doc) {
|
|
9131
|
+
let node = doc.nodeAt(this.pos);
|
|
9132
|
+
if (node) {
|
|
9133
|
+
let newSet = this.mark.addToSet(node.marks);
|
|
9134
|
+
if (newSet.length == node.marks.length) {
|
|
9135
|
+
for (let i = 0; i < node.marks.length; i++)
|
|
9136
|
+
if (!node.marks[i].isInSet(newSet))
|
|
9137
|
+
return new AddNodeMarkStep(this.pos, node.marks[i]);
|
|
9138
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
9139
|
+
}
|
|
9140
|
+
}
|
|
9141
|
+
return new RemoveNodeMarkStep(this.pos, this.mark);
|
|
9142
|
+
}
|
|
9143
|
+
map(mapping) {
|
|
9144
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
9145
|
+
return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
|
|
9146
|
+
}
|
|
9147
|
+
toJSON() {
|
|
9148
|
+
return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
9149
|
+
}
|
|
9150
|
+
/**
|
|
9151
|
+
@internal
|
|
9152
|
+
*/
|
|
9153
|
+
static fromJSON(schema, json) {
|
|
9154
|
+
if (typeof json.pos != "number")
|
|
9155
|
+
throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
|
|
9156
|
+
return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
9157
|
+
}
|
|
9158
|
+
}
|
|
9159
|
+
Step.jsonID("addNodeMark", AddNodeMarkStep);
|
|
9160
|
+
/**
|
|
9161
|
+
Remove a mark from a specific node.
|
|
9162
|
+
*/
|
|
9163
|
+
class RemoveNodeMarkStep extends Step {
|
|
9164
|
+
/**
|
|
9165
|
+
Create a mark-removing step.
|
|
9166
|
+
*/
|
|
9167
|
+
constructor(
|
|
9168
|
+
/**
|
|
9169
|
+
The position of the target node.
|
|
9170
|
+
*/
|
|
9171
|
+
pos,
|
|
9172
|
+
/**
|
|
9173
|
+
The mark to remove.
|
|
9174
|
+
*/
|
|
9175
|
+
mark) {
|
|
9176
|
+
super();
|
|
9177
|
+
this.pos = pos;
|
|
9178
|
+
this.mark = mark;
|
|
9179
|
+
}
|
|
9180
|
+
apply(doc) {
|
|
9181
|
+
let node = doc.nodeAt(this.pos);
|
|
9182
|
+
if (!node)
|
|
9183
|
+
return StepResult.fail("No node at mark step's position");
|
|
9184
|
+
let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
|
|
9185
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
9186
|
+
}
|
|
9187
|
+
invert(doc) {
|
|
9188
|
+
let node = doc.nodeAt(this.pos);
|
|
9189
|
+
if (!node || !this.mark.isInSet(node.marks))
|
|
9190
|
+
return this;
|
|
9191
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
9192
|
+
}
|
|
9193
|
+
map(mapping) {
|
|
9194
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
9195
|
+
return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
|
|
9196
|
+
}
|
|
9197
|
+
toJSON() {
|
|
9198
|
+
return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
9199
|
+
}
|
|
9200
|
+
/**
|
|
9201
|
+
@internal
|
|
9202
|
+
*/
|
|
9203
|
+
static fromJSON(schema, json) {
|
|
9204
|
+
if (typeof json.pos != "number")
|
|
9205
|
+
throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
|
|
9206
|
+
return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
9207
|
+
}
|
|
9208
|
+
}
|
|
9209
|
+
Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
|
|
9210
|
+
|
|
9211
|
+
/**
|
|
9212
|
+
Replace a part of the document with a slice of new content.
|
|
9213
|
+
*/
|
|
9214
|
+
class ReplaceStep extends Step {
|
|
9215
|
+
/**
|
|
9216
|
+
The given `slice` should fit the 'gap' between `from` and
|
|
9217
|
+
`to`—the depths must line up, and the surrounding nodes must be
|
|
9218
|
+
able to be joined with the open sides of the slice. When
|
|
9219
|
+
`structure` is true, the step will fail if the content between
|
|
9220
|
+
from and to is not just a sequence of closing and then opening
|
|
9221
|
+
tokens (this is to guard against rebased replace steps
|
|
9222
|
+
overwriting something they weren't supposed to).
|
|
9223
|
+
*/
|
|
9224
|
+
constructor(
|
|
9225
|
+
/**
|
|
9226
|
+
The start position of the replaced range.
|
|
9227
|
+
*/
|
|
9228
|
+
from,
|
|
9229
|
+
/**
|
|
9230
|
+
The end position of the replaced range.
|
|
9231
|
+
*/
|
|
9232
|
+
to,
|
|
9233
|
+
/**
|
|
9234
|
+
The slice to insert.
|
|
9235
|
+
*/
|
|
9236
|
+
slice,
|
|
9237
|
+
/**
|
|
9238
|
+
@internal
|
|
9239
|
+
*/
|
|
9240
|
+
structure = false) {
|
|
9241
|
+
super();
|
|
9242
|
+
this.from = from;
|
|
9243
|
+
this.to = to;
|
|
9244
|
+
this.slice = slice;
|
|
9245
|
+
this.structure = structure;
|
|
9246
|
+
}
|
|
9247
|
+
apply(doc) {
|
|
9248
|
+
if (this.structure && contentBetween(doc, this.from, this.to))
|
|
9249
|
+
return StepResult.fail("Structure replace would overwrite content");
|
|
9250
|
+
return StepResult.fromReplace(doc, this.from, this.to, this.slice);
|
|
9251
|
+
}
|
|
9252
|
+
getMap() {
|
|
9253
|
+
return new StepMap([this.from, this.to - this.from, this.slice.size]);
|
|
9254
|
+
}
|
|
9255
|
+
invert(doc) {
|
|
9256
|
+
return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
9257
|
+
}
|
|
9258
|
+
map(mapping) {
|
|
9259
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
9260
|
+
if (from.deletedAcross && to.deletedAcross)
|
|
9261
|
+
return null;
|
|
9262
|
+
return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice);
|
|
9263
|
+
}
|
|
9264
|
+
merge(other) {
|
|
9265
|
+
if (!(other instanceof ReplaceStep) || other.structure || this.structure)
|
|
9266
|
+
return null;
|
|
9267
|
+
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
|
|
9268
|
+
let slice = this.slice.size + other.slice.size == 0 ? utils.Slice.empty
|
|
9269
|
+
: new utils.Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
|
|
9270
|
+
return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
9271
|
+
}
|
|
9272
|
+
else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
|
|
9273
|
+
let slice = this.slice.size + other.slice.size == 0 ? utils.Slice.empty
|
|
9274
|
+
: new utils.Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
|
|
9275
|
+
return new ReplaceStep(other.from, this.to, slice, this.structure);
|
|
9276
|
+
}
|
|
9277
|
+
else {
|
|
9278
|
+
return null;
|
|
9279
|
+
}
|
|
9280
|
+
}
|
|
9281
|
+
toJSON() {
|
|
9282
|
+
let json = { stepType: "replace", from: this.from, to: this.to };
|
|
9283
|
+
if (this.slice.size)
|
|
9284
|
+
json.slice = this.slice.toJSON();
|
|
9285
|
+
if (this.structure)
|
|
9286
|
+
json.structure = true;
|
|
9287
|
+
return json;
|
|
9288
|
+
}
|
|
9289
|
+
/**
|
|
9290
|
+
@internal
|
|
9291
|
+
*/
|
|
9292
|
+
static fromJSON(schema, json) {
|
|
9293
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
9294
|
+
throw new RangeError("Invalid input for ReplaceStep.fromJSON");
|
|
9295
|
+
return new ReplaceStep(json.from, json.to, utils.Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
9296
|
+
}
|
|
9297
|
+
}
|
|
9298
|
+
Step.jsonID("replace", ReplaceStep);
|
|
9299
|
+
/**
|
|
9300
|
+
Replace a part of the document with a slice of content, but
|
|
9301
|
+
preserve a range of the replaced content by moving it into the
|
|
9302
|
+
slice.
|
|
9303
|
+
*/
|
|
9304
|
+
class ReplaceAroundStep extends Step {
|
|
9305
|
+
/**
|
|
9306
|
+
Create a replace-around step with the given range and gap.
|
|
9307
|
+
`insert` should be the point in the slice into which the content
|
|
9308
|
+
of the gap should be moved. `structure` has the same meaning as
|
|
9309
|
+
it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
|
|
9310
|
+
*/
|
|
9311
|
+
constructor(
|
|
9312
|
+
/**
|
|
9313
|
+
The start position of the replaced range.
|
|
9314
|
+
*/
|
|
9315
|
+
from,
|
|
9316
|
+
/**
|
|
9317
|
+
The end position of the replaced range.
|
|
9318
|
+
*/
|
|
9319
|
+
to,
|
|
9320
|
+
/**
|
|
9321
|
+
The start of preserved range.
|
|
9322
|
+
*/
|
|
9323
|
+
gapFrom,
|
|
9324
|
+
/**
|
|
9325
|
+
The end of preserved range.
|
|
9326
|
+
*/
|
|
9327
|
+
gapTo,
|
|
9328
|
+
/**
|
|
9329
|
+
The slice to insert.
|
|
9330
|
+
*/
|
|
9331
|
+
slice,
|
|
9332
|
+
/**
|
|
9333
|
+
The position in the slice where the preserved range should be
|
|
9334
|
+
inserted.
|
|
9335
|
+
*/
|
|
9336
|
+
insert,
|
|
9337
|
+
/**
|
|
9338
|
+
@internal
|
|
9339
|
+
*/
|
|
9340
|
+
structure = false) {
|
|
9341
|
+
super();
|
|
9342
|
+
this.from = from;
|
|
9343
|
+
this.to = to;
|
|
9344
|
+
this.gapFrom = gapFrom;
|
|
9345
|
+
this.gapTo = gapTo;
|
|
9346
|
+
this.slice = slice;
|
|
9347
|
+
this.insert = insert;
|
|
9348
|
+
this.structure = structure;
|
|
9349
|
+
}
|
|
9350
|
+
apply(doc) {
|
|
9351
|
+
if (this.structure && (contentBetween(doc, this.from, this.gapFrom) ||
|
|
9352
|
+
contentBetween(doc, this.gapTo, this.to)))
|
|
9353
|
+
return StepResult.fail("Structure gap-replace would overwrite content");
|
|
9354
|
+
let gap = doc.slice(this.gapFrom, this.gapTo);
|
|
9355
|
+
if (gap.openStart || gap.openEnd)
|
|
9356
|
+
return StepResult.fail("Gap is not a flat range");
|
|
9357
|
+
let inserted = this.slice.insertAt(this.insert, gap.content);
|
|
9358
|
+
if (!inserted)
|
|
9359
|
+
return StepResult.fail("Content does not fit in gap");
|
|
9360
|
+
return StepResult.fromReplace(doc, this.from, this.to, inserted);
|
|
9361
|
+
}
|
|
9362
|
+
getMap() {
|
|
9363
|
+
return new StepMap([this.from, this.gapFrom - this.from, this.insert,
|
|
9364
|
+
this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);
|
|
9365
|
+
}
|
|
9366
|
+
invert(doc) {
|
|
9367
|
+
let gap = this.gapTo - this.gapFrom;
|
|
9368
|
+
return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
9369
|
+
}
|
|
9370
|
+
map(mapping) {
|
|
9371
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
9372
|
+
let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
|
|
9373
|
+
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
9374
|
+
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)
|
|
9375
|
+
return null;
|
|
9376
|
+
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
9377
|
+
}
|
|
9378
|
+
toJSON() {
|
|
9379
|
+
let json = { stepType: "replaceAround", from: this.from, to: this.to,
|
|
9380
|
+
gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert };
|
|
9381
|
+
if (this.slice.size)
|
|
9382
|
+
json.slice = this.slice.toJSON();
|
|
9383
|
+
if (this.structure)
|
|
9384
|
+
json.structure = true;
|
|
9385
|
+
return json;
|
|
9386
|
+
}
|
|
9387
|
+
/**
|
|
9388
|
+
@internal
|
|
9389
|
+
*/
|
|
9390
|
+
static fromJSON(schema, json) {
|
|
9391
|
+
if (typeof json.from != "number" || typeof json.to != "number" ||
|
|
9392
|
+
typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
|
|
9393
|
+
throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
9394
|
+
return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, utils.Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
9395
|
+
}
|
|
9396
|
+
}
|
|
9397
|
+
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
9398
|
+
function contentBetween(doc, from, to) {
|
|
9399
|
+
let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
|
|
9400
|
+
while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
|
|
9401
|
+
depth--;
|
|
9402
|
+
dist--;
|
|
9403
|
+
}
|
|
9404
|
+
if (dist > 0) {
|
|
9405
|
+
let next = $from.node(depth).maybeChild($from.indexAfter(depth));
|
|
9406
|
+
while (dist > 0) {
|
|
9407
|
+
if (!next || next.isLeaf)
|
|
9408
|
+
return true;
|
|
9409
|
+
next = next.firstChild;
|
|
9410
|
+
dist--;
|
|
9411
|
+
}
|
|
9412
|
+
}
|
|
9413
|
+
return false;
|
|
9414
|
+
}
|
|
9415
|
+
|
|
9416
|
+
function canCut(node, start, end) {
|
|
9417
|
+
return (start == 0 || node.canReplace(start, node.childCount)) &&
|
|
9418
|
+
(end == node.childCount || node.canReplace(0, end));
|
|
9419
|
+
}
|
|
9420
|
+
/**
|
|
9421
|
+
Try to find a target depth to which the content in the given range
|
|
9422
|
+
can be lifted. Will not go across
|
|
9423
|
+
[isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.
|
|
9424
|
+
*/
|
|
9425
|
+
function liftTarget(range) {
|
|
9426
|
+
let parent = range.parent;
|
|
9427
|
+
let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
|
|
9428
|
+
for (let depth = range.depth;; --depth) {
|
|
9429
|
+
let node = range.$from.node(depth);
|
|
9430
|
+
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);
|
|
9431
|
+
if (depth < range.depth && node.canReplace(index, endIndex, content))
|
|
9432
|
+
return depth;
|
|
9433
|
+
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
|
|
9434
|
+
break;
|
|
9435
|
+
}
|
|
9436
|
+
return null;
|
|
9437
|
+
}
|
|
9438
|
+
/**
|
|
9439
|
+
Try to find a valid way to wrap the content in the given range in a
|
|
9440
|
+
node of the given type. May introduce extra nodes around and inside
|
|
9441
|
+
the wrapper node, if necessary. Returns null if no valid wrapping
|
|
9442
|
+
could be found. When `innerRange` is given, that range's content is
|
|
9443
|
+
used as the content to fit into the wrapping, instead of the
|
|
9444
|
+
content of `range`.
|
|
9445
|
+
*/
|
|
9446
|
+
function findWrapping(range, nodeType, attrs = null, innerRange = range) {
|
|
9447
|
+
let around = findWrappingOutside(range, nodeType);
|
|
9448
|
+
let inner = around && findWrappingInside(innerRange, nodeType);
|
|
9449
|
+
if (!inner)
|
|
9450
|
+
return null;
|
|
9451
|
+
return around.map(withAttrs)
|
|
9452
|
+
.concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));
|
|
9453
|
+
}
|
|
9454
|
+
function withAttrs(type) { return { type, attrs: null }; }
|
|
9455
|
+
function findWrappingOutside(range, type) {
|
|
9456
|
+
let { parent, startIndex, endIndex } = range;
|
|
9457
|
+
let around = parent.contentMatchAt(startIndex).findWrapping(type);
|
|
9458
|
+
if (!around)
|
|
9459
|
+
return null;
|
|
9460
|
+
let outer = around.length ? around[0] : type;
|
|
9461
|
+
return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;
|
|
9462
|
+
}
|
|
9463
|
+
function findWrappingInside(range, type) {
|
|
9464
|
+
let { parent, startIndex, endIndex } = range;
|
|
9465
|
+
let inner = parent.child(startIndex);
|
|
9466
|
+
let inside = type.contentMatch.findWrapping(inner.type);
|
|
9467
|
+
if (!inside)
|
|
9468
|
+
return null;
|
|
9469
|
+
let lastType = inside.length ? inside[inside.length - 1] : type;
|
|
9470
|
+
let innerMatch = lastType.contentMatch;
|
|
9471
|
+
for (let i = startIndex; innerMatch && i < endIndex; i++)
|
|
9472
|
+
innerMatch = innerMatch.matchType(parent.child(i).type);
|
|
9473
|
+
if (!innerMatch || !innerMatch.validEnd)
|
|
9474
|
+
return null;
|
|
9475
|
+
return inside;
|
|
9476
|
+
}
|
|
9477
|
+
/**
|
|
9478
|
+
Check whether splitting at the given position is allowed.
|
|
9479
|
+
*/
|
|
9480
|
+
function canSplit(doc, pos, depth = 1, typesAfter) {
|
|
9481
|
+
let $pos = doc.resolve(pos), base = $pos.depth - depth;
|
|
9482
|
+
let innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent;
|
|
9483
|
+
if (base < 0 || $pos.parent.type.spec.isolating ||
|
|
9484
|
+
!$pos.parent.canReplace($pos.index(), $pos.parent.childCount) ||
|
|
9485
|
+
!innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))
|
|
9486
|
+
return false;
|
|
9487
|
+
for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {
|
|
9488
|
+
let node = $pos.node(d), index = $pos.index(d);
|
|
9489
|
+
if (node.type.spec.isolating)
|
|
9490
|
+
return false;
|
|
9491
|
+
let rest = node.content.cutByIndex(index, node.childCount);
|
|
9492
|
+
let overrideChild = typesAfter && typesAfter[i + 1];
|
|
9493
|
+
if (overrideChild)
|
|
9494
|
+
rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
|
|
9495
|
+
let after = (typesAfter && typesAfter[i]) || node;
|
|
9496
|
+
if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
|
|
9497
|
+
return false;
|
|
9498
|
+
}
|
|
9499
|
+
let index = $pos.indexAfter(base);
|
|
9500
|
+
let baseType = typesAfter && typesAfter[0];
|
|
9501
|
+
return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);
|
|
9502
|
+
}
|
|
9503
|
+
/**
|
|
9504
|
+
Test whether the blocks before and after a given position can be
|
|
9505
|
+
joined.
|
|
9506
|
+
*/
|
|
9507
|
+
function canJoin(doc, pos) {
|
|
9508
|
+
let $pos = doc.resolve(pos), index = $pos.index();
|
|
9509
|
+
return joinable($pos.nodeBefore, $pos.nodeAfter) &&
|
|
9510
|
+
$pos.parent.canReplace(index, index + 1);
|
|
9511
|
+
}
|
|
9512
|
+
function joinable(a, b) {
|
|
9513
|
+
return !!(a && b && !a.isLeaf && a.canAppend(b));
|
|
9514
|
+
}
|
|
9515
|
+
|
|
9516
|
+
/**
|
|
9517
|
+
Update an attribute in a specific node.
|
|
9518
|
+
*/
|
|
9519
|
+
class AttrStep extends Step {
|
|
9520
|
+
/**
|
|
9521
|
+
Construct an attribute step.
|
|
9522
|
+
*/
|
|
9523
|
+
constructor(
|
|
9524
|
+
/**
|
|
9525
|
+
The position of the target node.
|
|
9526
|
+
*/
|
|
9527
|
+
pos,
|
|
9528
|
+
/**
|
|
9529
|
+
The attribute to set.
|
|
9530
|
+
*/
|
|
9531
|
+
attr,
|
|
9532
|
+
// The attribute's new value.
|
|
9533
|
+
value) {
|
|
9534
|
+
super();
|
|
9535
|
+
this.pos = pos;
|
|
9536
|
+
this.attr = attr;
|
|
9537
|
+
this.value = value;
|
|
9538
|
+
}
|
|
9539
|
+
apply(doc) {
|
|
9540
|
+
let node = doc.nodeAt(this.pos);
|
|
9541
|
+
if (!node)
|
|
9542
|
+
return StepResult.fail("No node at attribute step's position");
|
|
9543
|
+
let attrs = Object.create(null);
|
|
9544
|
+
for (let name in node.attrs)
|
|
9545
|
+
attrs[name] = node.attrs[name];
|
|
9546
|
+
attrs[this.attr] = this.value;
|
|
9547
|
+
let updated = node.type.create(attrs, null, node.marks);
|
|
9548
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new utils.Slice(utils.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
9549
|
+
}
|
|
9550
|
+
getMap() {
|
|
9551
|
+
return StepMap.empty;
|
|
9552
|
+
}
|
|
9553
|
+
invert(doc) {
|
|
9554
|
+
return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
9555
|
+
}
|
|
9556
|
+
map(mapping) {
|
|
9557
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
9558
|
+
return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
|
|
9559
|
+
}
|
|
9560
|
+
toJSON() {
|
|
9561
|
+
return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
|
|
9562
|
+
}
|
|
9563
|
+
static fromJSON(schema, json) {
|
|
9564
|
+
if (typeof json.pos != "number" || typeof json.attr != "string")
|
|
9565
|
+
throw new RangeError("Invalid input for AttrStep.fromJSON");
|
|
9566
|
+
return new AttrStep(json.pos, json.attr, json.value);
|
|
9567
|
+
}
|
|
9568
|
+
}
|
|
9569
|
+
Step.jsonID("attr", AttrStep);
|
|
9570
|
+
/**
|
|
9571
|
+
Update an attribute in the doc node.
|
|
9572
|
+
*/
|
|
9573
|
+
class DocAttrStep extends Step {
|
|
9574
|
+
/**
|
|
9575
|
+
Construct an attribute step.
|
|
9576
|
+
*/
|
|
9577
|
+
constructor(
|
|
9578
|
+
/**
|
|
9579
|
+
The attribute to set.
|
|
9580
|
+
*/
|
|
9581
|
+
attr,
|
|
9582
|
+
// The attribute's new value.
|
|
9583
|
+
value) {
|
|
9584
|
+
super();
|
|
9585
|
+
this.attr = attr;
|
|
9586
|
+
this.value = value;
|
|
9587
|
+
}
|
|
9588
|
+
apply(doc) {
|
|
9589
|
+
let attrs = Object.create(null);
|
|
9590
|
+
for (let name in doc.attrs)
|
|
9591
|
+
attrs[name] = doc.attrs[name];
|
|
9592
|
+
attrs[this.attr] = this.value;
|
|
9593
|
+
let updated = doc.type.create(attrs, doc.content, doc.marks);
|
|
9594
|
+
return StepResult.ok(updated);
|
|
9595
|
+
}
|
|
9596
|
+
getMap() {
|
|
9597
|
+
return StepMap.empty;
|
|
9598
|
+
}
|
|
9599
|
+
invert(doc) {
|
|
9600
|
+
return new DocAttrStep(this.attr, doc.attrs[this.attr]);
|
|
9601
|
+
}
|
|
9602
|
+
map(mapping) {
|
|
9603
|
+
return this;
|
|
9604
|
+
}
|
|
9605
|
+
toJSON() {
|
|
9606
|
+
return { stepType: "docAttr", attr: this.attr, value: this.value };
|
|
9607
|
+
}
|
|
9608
|
+
static fromJSON(schema, json) {
|
|
9609
|
+
if (typeof json.attr != "string")
|
|
9610
|
+
throw new RangeError("Invalid input for DocAttrStep.fromJSON");
|
|
9611
|
+
return new DocAttrStep(json.attr, json.value);
|
|
9612
|
+
}
|
|
9613
|
+
}
|
|
9614
|
+
Step.jsonID("docAttr", DocAttrStep);
|
|
9615
|
+
|
|
9616
|
+
/**
|
|
9617
|
+
@internal
|
|
9618
|
+
*/
|
|
9619
|
+
let TransformError = class extends Error {
|
|
9620
|
+
};
|
|
9621
|
+
TransformError = function TransformError(message) {
|
|
9622
|
+
let err = Error.call(this, message);
|
|
9623
|
+
err.__proto__ = TransformError.prototype;
|
|
9624
|
+
return err;
|
|
9625
|
+
};
|
|
9626
|
+
TransformError.prototype = Object.create(Error.prototype);
|
|
9627
|
+
TransformError.prototype.constructor = TransformError;
|
|
9628
|
+
TransformError.prototype.name = "TransformError";
|
|
9629
|
+
|
|
8681
9630
|
/**
|
|
8682
9631
|
Returns a command function that wraps the selection in a list with
|
|
8683
9632
|
the given type an attributes. If `dispatch` is null, only return a
|
|
@@ -8701,7 +9650,7 @@ function wrapInList$1(listType, attrs = null) {
|
|
|
8701
9650
|
range = new utils.NodeRange($from, state.doc.resolve($to.end(range.depth)), range.depth);
|
|
8702
9651
|
doJoin = true;
|
|
8703
9652
|
}
|
|
8704
|
-
let wrap =
|
|
9653
|
+
let wrap = findWrapping(outerRange, listType, attrs, range);
|
|
8705
9654
|
if (!wrap)
|
|
8706
9655
|
return false;
|
|
8707
9656
|
if (dispatch)
|
|
@@ -8713,7 +9662,7 @@ function doWrapInList(tr, range, wrappers, joinBefore, listType) {
|
|
|
8713
9662
|
let content = utils.Fragment.empty;
|
|
8714
9663
|
for (let i = wrappers.length - 1; i >= 0; i--)
|
|
8715
9664
|
content = utils.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
|
|
8716
|
-
tr.step(new
|
|
9665
|
+
tr.step(new ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new utils.Slice(content, 0, 0), wrappers.length, true));
|
|
8717
9666
|
let found = 0;
|
|
8718
9667
|
for (let i = 0; i < wrappers.length; i++)
|
|
8719
9668
|
if (wrappers[i].type == listType)
|
|
@@ -8721,7 +9670,7 @@ function doWrapInList(tr, range, wrappers, joinBefore, listType) {
|
|
|
8721
9670
|
let splitDepth = wrappers.length - found;
|
|
8722
9671
|
let splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0), parent = range.parent;
|
|
8723
9672
|
for (let i = range.startIndex, e = range.endIndex, first = true; i < e; i++, first = false) {
|
|
8724
|
-
if (!first &&
|
|
9673
|
+
if (!first && canSplit(tr.doc, splitPos, splitDepth)) {
|
|
8725
9674
|
tr.split(splitPos, splitDepth);
|
|
8726
9675
|
splitPos += 2 * splitDepth;
|
|
8727
9676
|
}
|
|
@@ -8752,15 +9701,15 @@ function liftToOuterList(state, dispatch, itemType, range) {
|
|
|
8752
9701
|
if (end < endOfList) {
|
|
8753
9702
|
// There are siblings after the lifted items, which must become
|
|
8754
9703
|
// children of the last item
|
|
8755
|
-
tr.step(new
|
|
9704
|
+
tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new utils.Slice(utils.Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true));
|
|
8756
9705
|
range = new utils.NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
|
|
8757
9706
|
}
|
|
8758
|
-
const target =
|
|
9707
|
+
const target = liftTarget(range);
|
|
8759
9708
|
if (target == null)
|
|
8760
9709
|
return false;
|
|
8761
9710
|
tr.lift(range, target);
|
|
8762
9711
|
let after = tr.mapping.map(end, -1) - 1;
|
|
8763
|
-
if (
|
|
9712
|
+
if (canJoin(tr.doc, after))
|
|
8764
9713
|
tr.join(after);
|
|
8765
9714
|
dispatch(tr.scrollIntoView());
|
|
8766
9715
|
return true;
|
|
@@ -8783,7 +9732,7 @@ function liftOutOfList(state, dispatch, range) {
|
|
|
8783
9732
|
// Strip off the surrounding list. At the sides where we're not at
|
|
8784
9733
|
// the end of the list, the existing list is closed. At sides where
|
|
8785
9734
|
// this is the end, it is overwritten to its end.
|
|
8786
|
-
tr.step(new
|
|
9735
|
+
tr.step(new ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, new utils.Slice((atStart ? utils.Fragment.empty : utils.Fragment.from(list.copy(utils.Fragment.empty)))
|
|
8787
9736
|
.append(atEnd ? utils.Fragment.empty : utils.Fragment.from(list.copy(utils.Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
|
|
8788
9737
|
dispatch(tr.scrollIntoView());
|
|
8789
9738
|
return true;
|
|
@@ -8809,7 +9758,7 @@ function sinkListItem$1(itemType) {
|
|
|
8809
9758
|
let inner = utils.Fragment.from(nestedBefore ? itemType.create() : null);
|
|
8810
9759
|
let slice = new utils.Slice(utils.Fragment.from(itemType.create(null, utils.Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
|
|
8811
9760
|
let before = range.start, after = range.end;
|
|
8812
|
-
dispatch(state.tr.step(new
|
|
9761
|
+
dispatch(state.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice, 1, true))
|
|
8813
9762
|
.scrollIntoView());
|
|
8814
9763
|
}
|
|
8815
9764
|
return true;
|
|
@@ -10247,7 +11196,7 @@ const clearNodes = () => ({ state, tr, dispatch }) => {
|
|
|
10247
11196
|
if (!nodeRange) {
|
|
10248
11197
|
return;
|
|
10249
11198
|
}
|
|
10250
|
-
const targetLiftDepth = liftTarget(nodeRange);
|
|
11199
|
+
const targetLiftDepth = liftTarget$1(nodeRange);
|
|
10251
11200
|
if (node.type.isTextblock) {
|
|
10252
11201
|
const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
|
|
10253
11202
|
tr.setNodeMarkup(nodeRange.start, defaultType);
|
|
@@ -10642,7 +11591,7 @@ function selectionToInsertionEnd(tr, startLen, bias) {
|
|
|
10642
11591
|
return;
|
|
10643
11592
|
}
|
|
10644
11593
|
const step = tr.steps[last];
|
|
10645
|
-
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
|
|
11594
|
+
if (!(step instanceof ReplaceStep$1 || step instanceof ReplaceAroundStep$1)) {
|
|
10646
11595
|
return;
|
|
10647
11596
|
}
|
|
10648
11597
|
const map = tr.mapping.maps[last];
|
|
@@ -11717,7 +12666,7 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
|
|
|
11717
12666
|
const extensionAttributes = editor.extensionManager.attributes;
|
|
11718
12667
|
const newAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs);
|
|
11719
12668
|
if (selection instanceof utils.NodeSelection && selection.node.isBlock) {
|
|
11720
|
-
if (!$from.parentOffset || !canSplit(doc, $from.pos)) {
|
|
12669
|
+
if (!$from.parentOffset || !canSplit$1(doc, $from.pos)) {
|
|
11721
12670
|
return false;
|
|
11722
12671
|
}
|
|
11723
12672
|
if (dispatch) {
|
|
@@ -11743,10 +12692,10 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
|
|
|
11743
12692
|
},
|
|
11744
12693
|
]
|
|
11745
12694
|
: undefined;
|
|
11746
|
-
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
|
|
12695
|
+
let can = canSplit$1(tr.doc, tr.mapping.map($from.pos), 1, types);
|
|
11747
12696
|
if (!types
|
|
11748
12697
|
&& !can
|
|
11749
|
-
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
|
|
12698
|
+
&& canSplit$1(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
|
|
11750
12699
|
can = true;
|
|
11751
12700
|
types = deflt
|
|
11752
12701
|
? [
|
|
@@ -11846,7 +12795,7 @@ const splitListItem = typeOrName => ({ tr, state, dispatch, editor, }) => {
|
|
|
11846
12795
|
{ type: nextType, attrs: newNextTypeAttributes },
|
|
11847
12796
|
]
|
|
11848
12797
|
: [{ type, attrs: newTypeAttributes }];
|
|
11849
|
-
if (!canSplit(tr.doc, $from.pos, 2)) {
|
|
12798
|
+
if (!canSplit$1(tr.doc, $from.pos, 2)) {
|
|
11850
12799
|
return false;
|
|
11851
12800
|
}
|
|
11852
12801
|
if (dispatch) {
|
|
@@ -11873,7 +12822,7 @@ const joinListBackwards = (tr, listType) => {
|
|
|
11873
12822
|
return true;
|
|
11874
12823
|
}
|
|
11875
12824
|
const nodeBefore = tr.doc.nodeAt(before);
|
|
11876
|
-
const canJoinBackwards = list.node.type === (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.type) && canJoin(tr.doc, list.pos);
|
|
12825
|
+
const canJoinBackwards = list.node.type === (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.type) && canJoin$1(tr.doc, list.pos);
|
|
11877
12826
|
if (!canJoinBackwards) {
|
|
11878
12827
|
return true;
|
|
11879
12828
|
}
|
|
@@ -11890,7 +12839,7 @@ const joinListForwards = (tr, listType) => {
|
|
|
11890
12839
|
return true;
|
|
11891
12840
|
}
|
|
11892
12841
|
const nodeAfter = tr.doc.nodeAt(after);
|
|
11893
|
-
const canJoinForwards = list.node.type === (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.type) && canJoin(tr.doc, after);
|
|
12842
|
+
const canJoinForwards = list.node.type === (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.type) && canJoin$1(tr.doc, after);
|
|
11894
12843
|
if (!canJoinForwards) {
|
|
11895
12844
|
return true;
|
|
11896
12845
|
}
|
|
@@ -13169,7 +14118,7 @@ function wrappingInputRule(config) {
|
|
|
13169
14118
|
const tr = state.tr.delete(range.from, range.to);
|
|
13170
14119
|
const $start = tr.doc.resolve(range.from);
|
|
13171
14120
|
const blockRange = $start.blockRange();
|
|
13172
|
-
const wrapping = blockRange && findWrapping(blockRange, config.type, attributes);
|
|
14121
|
+
const wrapping = blockRange && findWrapping$1(blockRange, config.type, attributes);
|
|
13173
14122
|
if (!wrapping) {
|
|
13174
14123
|
return null;
|
|
13175
14124
|
}
|
|
@@ -13191,7 +14140,7 @@ function wrappingInputRule(config) {
|
|
|
13191
14140
|
const before = tr.doc.resolve(range.from - 1).nodeBefore;
|
|
13192
14141
|
if (before
|
|
13193
14142
|
&& before.type === config.type
|
|
13194
|
-
&& canJoin(tr.doc, range.from - 1)
|
|
14143
|
+
&& canJoin$1(tr.doc, range.from - 1)
|
|
13195
14144
|
&& (!config.joinPredicate || config.joinPredicate(match, before))) {
|
|
13196
14145
|
tr.join(range.from - 1);
|
|
13197
14146
|
}
|
|
@@ -18486,7 +19435,7 @@ exports.getMarksBetween = getMarksBetween;
|
|
|
18486
19435
|
exports.highlightFocussedNode = highlightFocussedNode;
|
|
18487
19436
|
exports.isNodeSelection = isNodeSelection;
|
|
18488
19437
|
exports.keydownHandler = keydownHandler;
|
|
18489
|
-
exports.liftTarget = liftTarget;
|
|
19438
|
+
exports.liftTarget = liftTarget$1;
|
|
18490
19439
|
exports.markInputRule = markInputRule;
|
|
18491
19440
|
exports.markPasteRule = markPasteRule;
|
|
18492
19441
|
exports.mergeAttributes = mergeAttributes;
|
|
@@ -18497,4 +19446,4 @@ exports.useEditor = useEditor;
|
|
|
18497
19446
|
exports.useEditorState = useEditorState$1;
|
|
18498
19447
|
exports.validateUrl = validateUrl;
|
|
18499
19448
|
exports.wrappingInputRule = wrappingInputRule;
|
|
18500
|
-
//# sourceMappingURL=chunk-
|
|
19449
|
+
//# sourceMappingURL=chunk-eee94a18.cjs.js.map
|