@tiptap/core 2.2.0 → 2.2.1
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/index.cjs +44 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -15
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +44 -15
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/NodePos.d.ts +5 -1
- package/package.json +2 -2
- package/src/NodePos.ts +56 -15
package/dist/index.cjs
CHANGED
|
@@ -3340,18 +3340,26 @@ var extensions = /*#__PURE__*/Object.freeze({
|
|
|
3340
3340
|
});
|
|
3341
3341
|
|
|
3342
3342
|
class NodePos {
|
|
3343
|
-
constructor(pos, editor) {
|
|
3343
|
+
constructor(pos, editor, isBlock = false, node = null) {
|
|
3344
|
+
this.currentNode = null;
|
|
3345
|
+
this.actualDepth = null;
|
|
3346
|
+
this.isBlock = isBlock;
|
|
3344
3347
|
this.resolvedPos = pos;
|
|
3345
3348
|
this.editor = editor;
|
|
3349
|
+
this.currentNode = node;
|
|
3350
|
+
}
|
|
3351
|
+
get name() {
|
|
3352
|
+
return this.node.type.name;
|
|
3346
3353
|
}
|
|
3347
3354
|
get node() {
|
|
3348
|
-
return this.resolvedPos.node();
|
|
3355
|
+
return this.currentNode || this.resolvedPos.node();
|
|
3349
3356
|
}
|
|
3350
3357
|
get element() {
|
|
3351
3358
|
return this.editor.view.domAtPos(this.pos).node;
|
|
3352
3359
|
}
|
|
3353
3360
|
get depth() {
|
|
3354
|
-
|
|
3361
|
+
var _a;
|
|
3362
|
+
return (_a = this.actualDepth) !== null && _a !== void 0 ? _a : this.resolvedPos.depth;
|
|
3355
3363
|
}
|
|
3356
3364
|
get pos() {
|
|
3357
3365
|
return this.resolvedPos.pos;
|
|
@@ -3360,7 +3368,17 @@ class NodePos {
|
|
|
3360
3368
|
return this.node.content;
|
|
3361
3369
|
}
|
|
3362
3370
|
set content(content) {
|
|
3363
|
-
|
|
3371
|
+
let from = this.from;
|
|
3372
|
+
let to = this.to;
|
|
3373
|
+
if (this.isBlock) {
|
|
3374
|
+
if (this.content.size === 0) {
|
|
3375
|
+
console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);
|
|
3376
|
+
return;
|
|
3377
|
+
}
|
|
3378
|
+
from = this.from + 1;
|
|
3379
|
+
to = this.to - 1;
|
|
3380
|
+
}
|
|
3381
|
+
this.editor.commands.insertContentAt({ from, to }, content);
|
|
3364
3382
|
}
|
|
3365
3383
|
get attributes() {
|
|
3366
3384
|
return this.node.attrs;
|
|
@@ -3372,6 +3390,9 @@ class NodePos {
|
|
|
3372
3390
|
return this.node.nodeSize;
|
|
3373
3391
|
}
|
|
3374
3392
|
get from() {
|
|
3393
|
+
if (this.isBlock) {
|
|
3394
|
+
return this.pos;
|
|
3395
|
+
}
|
|
3375
3396
|
return this.resolvedPos.start(this.resolvedPos.depth);
|
|
3376
3397
|
}
|
|
3377
3398
|
get range() {
|
|
@@ -3381,6 +3402,9 @@ class NodePos {
|
|
|
3381
3402
|
};
|
|
3382
3403
|
}
|
|
3383
3404
|
get to() {
|
|
3405
|
+
if (this.isBlock) {
|
|
3406
|
+
return this.pos + this.size;
|
|
3407
|
+
}
|
|
3384
3408
|
return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1);
|
|
3385
3409
|
}
|
|
3386
3410
|
get parent() {
|
|
@@ -3392,14 +3416,14 @@ class NodePos {
|
|
|
3392
3416
|
return new NodePos($pos, this.editor);
|
|
3393
3417
|
}
|
|
3394
3418
|
get before() {
|
|
3395
|
-
let $pos = this.resolvedPos.doc.resolve(this.from - 2);
|
|
3419
|
+
let $pos = this.resolvedPos.doc.resolve(this.from - (this.isBlock ? 1 : 2));
|
|
3396
3420
|
if ($pos.depth !== this.depth) {
|
|
3397
3421
|
$pos = this.resolvedPos.doc.resolve(this.from - 3);
|
|
3398
3422
|
}
|
|
3399
3423
|
return new NodePos($pos, this.editor);
|
|
3400
3424
|
}
|
|
3401
3425
|
get after() {
|
|
3402
|
-
let $pos = this.resolvedPos.doc.resolve(this.to + 2);
|
|
3426
|
+
let $pos = this.resolvedPos.doc.resolve(this.to + (this.isBlock ? 2 : 1));
|
|
3403
3427
|
if ($pos.depth !== this.depth) {
|
|
3404
3428
|
$pos = this.resolvedPos.doc.resolve(this.to + 3);
|
|
3405
3429
|
}
|
|
@@ -3408,12 +3432,17 @@ class NodePos {
|
|
|
3408
3432
|
get children() {
|
|
3409
3433
|
const children = [];
|
|
3410
3434
|
this.node.content.forEach((node, offset) => {
|
|
3411
|
-
const
|
|
3435
|
+
const isBlock = node.isBlock && !node.isTextblock;
|
|
3436
|
+
const targetPos = this.pos + offset + (isBlock ? 0 : 1);
|
|
3412
3437
|
const $pos = this.resolvedPos.doc.resolve(targetPos);
|
|
3413
|
-
if ($pos.depth
|
|
3438
|
+
if (!isBlock && $pos.depth <= this.depth) {
|
|
3414
3439
|
return;
|
|
3415
3440
|
}
|
|
3416
|
-
|
|
3441
|
+
const childNodePos = new NodePos($pos, this.editor, isBlock, isBlock ? node : null);
|
|
3442
|
+
if (isBlock) {
|
|
3443
|
+
childNodePos.actualDepth = this.depth + 1;
|
|
3444
|
+
}
|
|
3445
|
+
children.push(new NodePos($pos, this.editor, isBlock, isBlock ? node : null));
|
|
3417
3446
|
});
|
|
3418
3447
|
return children;
|
|
3419
3448
|
}
|
|
@@ -3453,13 +3482,13 @@ class NodePos {
|
|
|
3453
3482
|
querySelectorAll(selector, attributes = {}, firstItemOnly = false) {
|
|
3454
3483
|
let nodes = [];
|
|
3455
3484
|
// iterate through children recursively finding all nodes which match the selector with the node name
|
|
3456
|
-
if (!this.children || this.children.length === 0) {
|
|
3485
|
+
if (this.isBlock || !this.children || this.children.length === 0) {
|
|
3457
3486
|
return nodes;
|
|
3458
3487
|
}
|
|
3459
|
-
this.children.forEach(
|
|
3460
|
-
if (
|
|
3488
|
+
this.children.forEach(childPos => {
|
|
3489
|
+
if (childPos.node.type.name === selector) {
|
|
3461
3490
|
if (Object.keys(attributes).length > 0) {
|
|
3462
|
-
const nodeAttributes =
|
|
3491
|
+
const nodeAttributes = childPos.node.attrs;
|
|
3463
3492
|
const attrKeys = Object.keys(attributes);
|
|
3464
3493
|
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3465
3494
|
const key = attrKeys[index];
|
|
@@ -3468,12 +3497,12 @@ class NodePos {
|
|
|
3468
3497
|
}
|
|
3469
3498
|
}
|
|
3470
3499
|
}
|
|
3471
|
-
nodes.push(
|
|
3500
|
+
nodes.push(childPos);
|
|
3472
3501
|
if (firstItemOnly) {
|
|
3473
3502
|
return;
|
|
3474
3503
|
}
|
|
3475
3504
|
}
|
|
3476
|
-
nodes = nodes.concat(
|
|
3505
|
+
nodes = nodes.concat(childPos.querySelectorAll(selector));
|
|
3477
3506
|
});
|
|
3478
3507
|
return nodes;
|
|
3479
3508
|
}
|