@tiptap/core 2.2.0-rc.6 → 2.2.0-rc.8
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 +180 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +181 -9
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +180 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/Editor.d.ts +9 -0
- package/dist/packages/core/src/NodePos.d.ts +40 -0
- package/dist/packages/core/src/PasteRule.d.ts +1 -1
- package/dist/packages/core/src/commands/index.d.ts +2 -0
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -0
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -0
- package/dist/packages/core/src/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/Editor.ts +22 -1
- package/src/Extension.ts +1 -1
- package/src/Mark.ts +1 -1
- package/src/Node.ts +1 -1
- package/src/NodePos.ts +201 -0
- package/src/PasteRule.ts +4 -3
- package/src/commands/index.ts +2 -0
- package/src/commands/joinTextblockBackward.ts +18 -0
- package/src/commands/joinTextblockForward.ts +18 -0
- package/src/helpers/createChainableState.ts +0 -1
- package/src/helpers/getMarksBetween.ts +4 -0
- package/src/index.ts +1 -0
package/dist/index.umd.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
...state,
|
|
14
14
|
apply: state.apply.bind(state),
|
|
15
15
|
applyTransaction: state.applyTransaction.bind(state),
|
|
16
|
-
filterTransaction: state.filterTransaction,
|
|
17
16
|
plugins: state.plugins,
|
|
18
17
|
schema: state.schema,
|
|
19
18
|
reconfigure: state.reconfigure.bind(state),
|
|
@@ -728,11 +727,11 @@
|
|
|
728
727
|
this.handler = config.handler;
|
|
729
728
|
}
|
|
730
729
|
}
|
|
731
|
-
const pasteRuleMatcherHandler = (text, find) => {
|
|
730
|
+
const pasteRuleMatcherHandler = (text, find, event) => {
|
|
732
731
|
if (isRegExp(find)) {
|
|
733
732
|
return [...text.matchAll(find)];
|
|
734
733
|
}
|
|
735
|
-
const matches = find(text);
|
|
734
|
+
const matches = find(text, event);
|
|
736
735
|
if (!matches) {
|
|
737
736
|
return [];
|
|
738
737
|
}
|
|
@@ -764,7 +763,7 @@
|
|
|
764
763
|
const resolvedFrom = Math.max(from, pos);
|
|
765
764
|
const resolvedTo = Math.min(to, pos + node.content.size);
|
|
766
765
|
const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
|
|
767
|
-
const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
|
|
766
|
+
const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent);
|
|
768
767
|
matches.forEach(match => {
|
|
769
768
|
if (match.index === undefined) {
|
|
770
769
|
return;
|
|
@@ -1145,7 +1144,7 @@
|
|
|
1145
1144
|
...config,
|
|
1146
1145
|
};
|
|
1147
1146
|
this.name = this.config.name;
|
|
1148
|
-
if (config.defaultOptions) {
|
|
1147
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
1149
1148
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
1150
1149
|
}
|
|
1151
1150
|
// TODO: remove `addOptions` fallback
|
|
@@ -1751,6 +1750,14 @@
|
|
|
1751
1750
|
}
|
|
1752
1751
|
};
|
|
1753
1752
|
|
|
1753
|
+
const joinTextblockBackward = () => ({ state, dispatch }) => {
|
|
1754
|
+
return commands$1.joinTextblockBackward(state, dispatch);
|
|
1755
|
+
};
|
|
1756
|
+
|
|
1757
|
+
const joinTextblockForward = () => ({ state, dispatch }) => {
|
|
1758
|
+
return commands$1.joinTextblockForward(state, dispatch);
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1754
1761
|
function isMacOS() {
|
|
1755
1762
|
return typeof navigator !== 'undefined'
|
|
1756
1763
|
? /Mac/.test(navigator.platform)
|
|
@@ -2305,6 +2312,9 @@
|
|
|
2305
2312
|
}
|
|
2306
2313
|
else {
|
|
2307
2314
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
2315
|
+
if (!node || node.nodeSize === undefined) {
|
|
2316
|
+
return;
|
|
2317
|
+
}
|
|
2308
2318
|
marks.push(...node.marks.map(mark => ({
|
|
2309
2319
|
from: pos,
|
|
2310
2320
|
to: pos + node.nodeSize,
|
|
@@ -3082,6 +3092,8 @@
|
|
|
3082
3092
|
joinForward: joinForward,
|
|
3083
3093
|
joinItemBackward: joinItemBackward,
|
|
3084
3094
|
joinItemForward: joinItemForward,
|
|
3095
|
+
joinTextblockBackward: joinTextblockBackward,
|
|
3096
|
+
joinTextblockForward: joinTextblockForward,
|
|
3085
3097
|
keyboardShortcut: keyboardShortcut,
|
|
3086
3098
|
lift: lift,
|
|
3087
3099
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3307,6 +3319,151 @@
|
|
|
3307
3319
|
Tabindex: Tabindex
|
|
3308
3320
|
});
|
|
3309
3321
|
|
|
3322
|
+
class NodePos {
|
|
3323
|
+
constructor(pos, editor) {
|
|
3324
|
+
this.resolvedPos = pos;
|
|
3325
|
+
this.editor = editor;
|
|
3326
|
+
}
|
|
3327
|
+
get node() {
|
|
3328
|
+
return this.resolvedPos.node();
|
|
3329
|
+
}
|
|
3330
|
+
get element() {
|
|
3331
|
+
return this.editor.view.domAtPos(this.pos).node;
|
|
3332
|
+
}
|
|
3333
|
+
get depth() {
|
|
3334
|
+
return this.resolvedPos.depth;
|
|
3335
|
+
}
|
|
3336
|
+
get pos() {
|
|
3337
|
+
return this.resolvedPos.pos;
|
|
3338
|
+
}
|
|
3339
|
+
get content() {
|
|
3340
|
+
return this.node.content;
|
|
3341
|
+
}
|
|
3342
|
+
set content(content) {
|
|
3343
|
+
this.editor.commands.insertContentAt({ from: this.from, to: this.to }, content);
|
|
3344
|
+
}
|
|
3345
|
+
get attributes() {
|
|
3346
|
+
return this.node.attrs;
|
|
3347
|
+
}
|
|
3348
|
+
get textContent() {
|
|
3349
|
+
return this.node.textContent;
|
|
3350
|
+
}
|
|
3351
|
+
get size() {
|
|
3352
|
+
return this.node.nodeSize;
|
|
3353
|
+
}
|
|
3354
|
+
get from() {
|
|
3355
|
+
return this.resolvedPos.start(this.resolvedPos.depth);
|
|
3356
|
+
}
|
|
3357
|
+
get range() {
|
|
3358
|
+
return {
|
|
3359
|
+
from: this.from,
|
|
3360
|
+
to: this.to,
|
|
3361
|
+
};
|
|
3362
|
+
}
|
|
3363
|
+
get to() {
|
|
3364
|
+
return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1);
|
|
3365
|
+
}
|
|
3366
|
+
get parent() {
|
|
3367
|
+
if (this.depth === 0) {
|
|
3368
|
+
return null;
|
|
3369
|
+
}
|
|
3370
|
+
const parentPos = this.resolvedPos.start(this.resolvedPos.depth - 1);
|
|
3371
|
+
const $pos = this.resolvedPos.doc.resolve(parentPos);
|
|
3372
|
+
return new NodePos($pos, this.editor);
|
|
3373
|
+
}
|
|
3374
|
+
get before() {
|
|
3375
|
+
let $pos = this.resolvedPos.doc.resolve(this.from - 2);
|
|
3376
|
+
if ($pos.depth !== this.depth) {
|
|
3377
|
+
$pos = this.resolvedPos.doc.resolve(this.from - 3);
|
|
3378
|
+
}
|
|
3379
|
+
return new NodePos($pos, this.editor);
|
|
3380
|
+
}
|
|
3381
|
+
get after() {
|
|
3382
|
+
let $pos = this.resolvedPos.doc.resolve(this.to + 2);
|
|
3383
|
+
if ($pos.depth !== this.depth) {
|
|
3384
|
+
$pos = this.resolvedPos.doc.resolve(this.to + 3);
|
|
3385
|
+
}
|
|
3386
|
+
return new NodePos($pos, this.editor);
|
|
3387
|
+
}
|
|
3388
|
+
get children() {
|
|
3389
|
+
const children = [];
|
|
3390
|
+
this.node.content.forEach((node, offset) => {
|
|
3391
|
+
const targetPos = this.pos + offset + 1;
|
|
3392
|
+
const $pos = this.resolvedPos.doc.resolve(targetPos);
|
|
3393
|
+
if ($pos.depth === this.depth) {
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
children.push(new NodePos($pos, this.editor));
|
|
3397
|
+
});
|
|
3398
|
+
return children;
|
|
3399
|
+
}
|
|
3400
|
+
get firstChild() {
|
|
3401
|
+
return this.children[0] || null;
|
|
3402
|
+
}
|
|
3403
|
+
get lastChild() {
|
|
3404
|
+
const children = this.children;
|
|
3405
|
+
return children[children.length - 1] || null;
|
|
3406
|
+
}
|
|
3407
|
+
closest(selector, attributes = {}) {
|
|
3408
|
+
let node = null;
|
|
3409
|
+
let currentNode = this.parent;
|
|
3410
|
+
while (currentNode && !node) {
|
|
3411
|
+
if (currentNode.node.type.name === selector) {
|
|
3412
|
+
if (Object.keys(attributes).length > 0) {
|
|
3413
|
+
const nodeAttributes = currentNode.node.attrs;
|
|
3414
|
+
const attrKeys = Object.keys(attributes);
|
|
3415
|
+
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3416
|
+
const key = attrKeys[index];
|
|
3417
|
+
if (nodeAttributes[key] !== attributes[key]) {
|
|
3418
|
+
break;
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
else {
|
|
3423
|
+
node = currentNode;
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
currentNode = currentNode.parent;
|
|
3427
|
+
}
|
|
3428
|
+
return node;
|
|
3429
|
+
}
|
|
3430
|
+
querySelector(selector, attributes = {}) {
|
|
3431
|
+
return this.querySelectorAll(selector, attributes, true)[0] || null;
|
|
3432
|
+
}
|
|
3433
|
+
querySelectorAll(selector, attributes = {}, firstItemOnly = false) {
|
|
3434
|
+
let nodes = [];
|
|
3435
|
+
// iterate through children recursively finding all nodes which match the selector with the node name
|
|
3436
|
+
if (!this.children || this.children.length === 0) {
|
|
3437
|
+
return nodes;
|
|
3438
|
+
}
|
|
3439
|
+
this.children.forEach(node => {
|
|
3440
|
+
if (node.node.type.name === selector) {
|
|
3441
|
+
if (Object.keys(attributes).length > 0) {
|
|
3442
|
+
const nodeAttributes = node.node.attrs;
|
|
3443
|
+
const attrKeys = Object.keys(attributes);
|
|
3444
|
+
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3445
|
+
const key = attrKeys[index];
|
|
3446
|
+
if (nodeAttributes[key] !== attributes[key]) {
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
nodes.push(node);
|
|
3452
|
+
if (firstItemOnly) {
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
nodes = nodes.concat(node.querySelectorAll(selector));
|
|
3457
|
+
});
|
|
3458
|
+
return nodes;
|
|
3459
|
+
}
|
|
3460
|
+
setAttribute(attributes) {
|
|
3461
|
+
const oldSelection = this.editor.state.selection;
|
|
3462
|
+
this.editor.chain().setTextSelection(this.from).updateAttributes(this.node.type.name, attributes).setTextSelection(oldSelection.from)
|
|
3463
|
+
.run();
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3310
3467
|
const style = `.ProseMirror {
|
|
3311
3468
|
position: relative;
|
|
3312
3469
|
}
|
|
@@ -3752,6 +3909,21 @@ img.ProseMirror-separator {
|
|
|
3752
3909
|
// @ts-ignore
|
|
3753
3910
|
return !((_a = this.view) === null || _a === void 0 ? void 0 : _a.docView);
|
|
3754
3911
|
}
|
|
3912
|
+
$node(selector, attributes) {
|
|
3913
|
+
var _a;
|
|
3914
|
+
return ((_a = this.$doc) === null || _a === void 0 ? void 0 : _a.querySelector(selector, attributes)) || null;
|
|
3915
|
+
}
|
|
3916
|
+
$nodes(selector, attributes) {
|
|
3917
|
+
var _a;
|
|
3918
|
+
return ((_a = this.$doc) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selector, attributes)) || null;
|
|
3919
|
+
}
|
|
3920
|
+
$pos(pos) {
|
|
3921
|
+
const $pos = this.state.doc.resolve(pos);
|
|
3922
|
+
return new NodePos($pos, this);
|
|
3923
|
+
}
|
|
3924
|
+
get $doc() {
|
|
3925
|
+
return this.$pos(0);
|
|
3926
|
+
}
|
|
3755
3927
|
}
|
|
3756
3928
|
|
|
3757
3929
|
/**
|
|
@@ -3948,7 +4120,7 @@ img.ProseMirror-separator {
|
|
|
3948
4120
|
...config,
|
|
3949
4121
|
};
|
|
3950
4122
|
this.name = this.config.name;
|
|
3951
|
-
if (config.defaultOptions) {
|
|
4123
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
3952
4124
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
3953
4125
|
}
|
|
3954
4126
|
// TODO: remove `addOptions` fallback
|
|
@@ -4031,7 +4203,7 @@ img.ProseMirror-separator {
|
|
|
4031
4203
|
...config,
|
|
4032
4204
|
};
|
|
4033
4205
|
this.name = this.config.name;
|
|
4034
|
-
if (config.defaultOptions) {
|
|
4206
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
4035
4207
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
4036
4208
|
}
|
|
4037
4209
|
// TODO: remove `addOptions` fallback
|
|
@@ -4400,6 +4572,7 @@ img.ProseMirror-separator {
|
|
|
4400
4572
|
exports.InputRule = InputRule;
|
|
4401
4573
|
exports.Mark = Mark;
|
|
4402
4574
|
exports.Node = Node;
|
|
4575
|
+
exports.NodePos = NodePos;
|
|
4403
4576
|
exports.NodeView = NodeView;
|
|
4404
4577
|
exports.PasteRule = PasteRule;
|
|
4405
4578
|
exports.Tracker = Tracker;
|