@tiptap/core 2.2.0-rc.7 → 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 +183 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +184 -12
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +183 -10
- 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 +2 -2
- package/src/Mark.ts +2 -2
- package/src/Node.ts +2 -2
- 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.cjs
CHANGED
|
@@ -19,7 +19,6 @@ function createChainableState(config) {
|
|
|
19
19
|
...state,
|
|
20
20
|
apply: state.apply.bind(state),
|
|
21
21
|
applyTransaction: state.applyTransaction.bind(state),
|
|
22
|
-
filterTransaction: state.filterTransaction,
|
|
23
22
|
plugins: state.plugins,
|
|
24
23
|
schema: state.schema,
|
|
25
24
|
reconfigure: state.reconfigure.bind(state),
|
|
@@ -734,11 +733,11 @@ class PasteRule {
|
|
|
734
733
|
this.handler = config.handler;
|
|
735
734
|
}
|
|
736
735
|
}
|
|
737
|
-
const pasteRuleMatcherHandler = (text, find) => {
|
|
736
|
+
const pasteRuleMatcherHandler = (text, find, event) => {
|
|
738
737
|
if (isRegExp(find)) {
|
|
739
738
|
return [...text.matchAll(find)];
|
|
740
739
|
}
|
|
741
|
-
const matches = find(text);
|
|
740
|
+
const matches = find(text, event);
|
|
742
741
|
if (!matches) {
|
|
743
742
|
return [];
|
|
744
743
|
}
|
|
@@ -770,7 +769,7 @@ function run(config) {
|
|
|
770
769
|
const resolvedFrom = Math.max(from, pos);
|
|
771
770
|
const resolvedTo = Math.min(to, pos + node.content.size);
|
|
772
771
|
const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
|
|
773
|
-
const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
|
|
772
|
+
const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent);
|
|
774
773
|
matches.forEach(match => {
|
|
775
774
|
if (match.index === undefined) {
|
|
776
775
|
return;
|
|
@@ -1144,14 +1143,14 @@ class Extension {
|
|
|
1144
1143
|
this.child = null;
|
|
1145
1144
|
this.config = {
|
|
1146
1145
|
name: this.name,
|
|
1147
|
-
defaultOptions:
|
|
1146
|
+
defaultOptions: {},
|
|
1148
1147
|
};
|
|
1149
1148
|
this.config = {
|
|
1150
1149
|
...this.config,
|
|
1151
1150
|
...config,
|
|
1152
1151
|
};
|
|
1153
1152
|
this.name = this.config.name;
|
|
1154
|
-
if (config.defaultOptions) {
|
|
1153
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
1155
1154
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
1156
1155
|
}
|
|
1157
1156
|
// TODO: remove `addOptions` fallback
|
|
@@ -1757,6 +1756,14 @@ const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
|
1757
1756
|
}
|
|
1758
1757
|
};
|
|
1759
1758
|
|
|
1759
|
+
const joinTextblockBackward = () => ({ state, dispatch }) => {
|
|
1760
|
+
return commands$1.joinTextblockBackward(state, dispatch);
|
|
1761
|
+
};
|
|
1762
|
+
|
|
1763
|
+
const joinTextblockForward = () => ({ state, dispatch }) => {
|
|
1764
|
+
return commands$1.joinTextblockForward(state, dispatch);
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1760
1767
|
function isMacOS() {
|
|
1761
1768
|
return typeof navigator !== 'undefined'
|
|
1762
1769
|
? /Mac/.test(navigator.platform)
|
|
@@ -2311,6 +2318,9 @@ function getMarksBetween(from, to, doc) {
|
|
|
2311
2318
|
}
|
|
2312
2319
|
else {
|
|
2313
2320
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
2321
|
+
if (!node || node.nodeSize === undefined) {
|
|
2322
|
+
return;
|
|
2323
|
+
}
|
|
2314
2324
|
marks.push(...node.marks.map(mark => ({
|
|
2315
2325
|
from: pos,
|
|
2316
2326
|
to: pos + node.nodeSize,
|
|
@@ -3088,6 +3098,8 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3088
3098
|
joinForward: joinForward,
|
|
3089
3099
|
joinItemBackward: joinItemBackward,
|
|
3090
3100
|
joinItemForward: joinItemForward,
|
|
3101
|
+
joinTextblockBackward: joinTextblockBackward,
|
|
3102
|
+
joinTextblockForward: joinTextblockForward,
|
|
3091
3103
|
keyboardShortcut: keyboardShortcut,
|
|
3092
3104
|
lift: lift,
|
|
3093
3105
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3313,6 +3325,151 @@ var extensions = /*#__PURE__*/Object.freeze({
|
|
|
3313
3325
|
Tabindex: Tabindex
|
|
3314
3326
|
});
|
|
3315
3327
|
|
|
3328
|
+
class NodePos {
|
|
3329
|
+
constructor(pos, editor) {
|
|
3330
|
+
this.resolvedPos = pos;
|
|
3331
|
+
this.editor = editor;
|
|
3332
|
+
}
|
|
3333
|
+
get node() {
|
|
3334
|
+
return this.resolvedPos.node();
|
|
3335
|
+
}
|
|
3336
|
+
get element() {
|
|
3337
|
+
return this.editor.view.domAtPos(this.pos).node;
|
|
3338
|
+
}
|
|
3339
|
+
get depth() {
|
|
3340
|
+
return this.resolvedPos.depth;
|
|
3341
|
+
}
|
|
3342
|
+
get pos() {
|
|
3343
|
+
return this.resolvedPos.pos;
|
|
3344
|
+
}
|
|
3345
|
+
get content() {
|
|
3346
|
+
return this.node.content;
|
|
3347
|
+
}
|
|
3348
|
+
set content(content) {
|
|
3349
|
+
this.editor.commands.insertContentAt({ from: this.from, to: this.to }, content);
|
|
3350
|
+
}
|
|
3351
|
+
get attributes() {
|
|
3352
|
+
return this.node.attrs;
|
|
3353
|
+
}
|
|
3354
|
+
get textContent() {
|
|
3355
|
+
return this.node.textContent;
|
|
3356
|
+
}
|
|
3357
|
+
get size() {
|
|
3358
|
+
return this.node.nodeSize;
|
|
3359
|
+
}
|
|
3360
|
+
get from() {
|
|
3361
|
+
return this.resolvedPos.start(this.resolvedPos.depth);
|
|
3362
|
+
}
|
|
3363
|
+
get range() {
|
|
3364
|
+
return {
|
|
3365
|
+
from: this.from,
|
|
3366
|
+
to: this.to,
|
|
3367
|
+
};
|
|
3368
|
+
}
|
|
3369
|
+
get to() {
|
|
3370
|
+
return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1);
|
|
3371
|
+
}
|
|
3372
|
+
get parent() {
|
|
3373
|
+
if (this.depth === 0) {
|
|
3374
|
+
return null;
|
|
3375
|
+
}
|
|
3376
|
+
const parentPos = this.resolvedPos.start(this.resolvedPos.depth - 1);
|
|
3377
|
+
const $pos = this.resolvedPos.doc.resolve(parentPos);
|
|
3378
|
+
return new NodePos($pos, this.editor);
|
|
3379
|
+
}
|
|
3380
|
+
get before() {
|
|
3381
|
+
let $pos = this.resolvedPos.doc.resolve(this.from - 2);
|
|
3382
|
+
if ($pos.depth !== this.depth) {
|
|
3383
|
+
$pos = this.resolvedPos.doc.resolve(this.from - 3);
|
|
3384
|
+
}
|
|
3385
|
+
return new NodePos($pos, this.editor);
|
|
3386
|
+
}
|
|
3387
|
+
get after() {
|
|
3388
|
+
let $pos = this.resolvedPos.doc.resolve(this.to + 2);
|
|
3389
|
+
if ($pos.depth !== this.depth) {
|
|
3390
|
+
$pos = this.resolvedPos.doc.resolve(this.to + 3);
|
|
3391
|
+
}
|
|
3392
|
+
return new NodePos($pos, this.editor);
|
|
3393
|
+
}
|
|
3394
|
+
get children() {
|
|
3395
|
+
const children = [];
|
|
3396
|
+
this.node.content.forEach((node, offset) => {
|
|
3397
|
+
const targetPos = this.pos + offset + 1;
|
|
3398
|
+
const $pos = this.resolvedPos.doc.resolve(targetPos);
|
|
3399
|
+
if ($pos.depth === this.depth) {
|
|
3400
|
+
return;
|
|
3401
|
+
}
|
|
3402
|
+
children.push(new NodePos($pos, this.editor));
|
|
3403
|
+
});
|
|
3404
|
+
return children;
|
|
3405
|
+
}
|
|
3406
|
+
get firstChild() {
|
|
3407
|
+
return this.children[0] || null;
|
|
3408
|
+
}
|
|
3409
|
+
get lastChild() {
|
|
3410
|
+
const children = this.children;
|
|
3411
|
+
return children[children.length - 1] || null;
|
|
3412
|
+
}
|
|
3413
|
+
closest(selector, attributes = {}) {
|
|
3414
|
+
let node = null;
|
|
3415
|
+
let currentNode = this.parent;
|
|
3416
|
+
while (currentNode && !node) {
|
|
3417
|
+
if (currentNode.node.type.name === selector) {
|
|
3418
|
+
if (Object.keys(attributes).length > 0) {
|
|
3419
|
+
const nodeAttributes = currentNode.node.attrs;
|
|
3420
|
+
const attrKeys = Object.keys(attributes);
|
|
3421
|
+
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3422
|
+
const key = attrKeys[index];
|
|
3423
|
+
if (nodeAttributes[key] !== attributes[key]) {
|
|
3424
|
+
break;
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
else {
|
|
3429
|
+
node = currentNode;
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
currentNode = currentNode.parent;
|
|
3433
|
+
}
|
|
3434
|
+
return node;
|
|
3435
|
+
}
|
|
3436
|
+
querySelector(selector, attributes = {}) {
|
|
3437
|
+
return this.querySelectorAll(selector, attributes, true)[0] || null;
|
|
3438
|
+
}
|
|
3439
|
+
querySelectorAll(selector, attributes = {}, firstItemOnly = false) {
|
|
3440
|
+
let nodes = [];
|
|
3441
|
+
// iterate through children recursively finding all nodes which match the selector with the node name
|
|
3442
|
+
if (!this.children || this.children.length === 0) {
|
|
3443
|
+
return nodes;
|
|
3444
|
+
}
|
|
3445
|
+
this.children.forEach(node => {
|
|
3446
|
+
if (node.node.type.name === selector) {
|
|
3447
|
+
if (Object.keys(attributes).length > 0) {
|
|
3448
|
+
const nodeAttributes = node.node.attrs;
|
|
3449
|
+
const attrKeys = Object.keys(attributes);
|
|
3450
|
+
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3451
|
+
const key = attrKeys[index];
|
|
3452
|
+
if (nodeAttributes[key] !== attributes[key]) {
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
nodes.push(node);
|
|
3458
|
+
if (firstItemOnly) {
|
|
3459
|
+
return;
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
nodes = nodes.concat(node.querySelectorAll(selector));
|
|
3463
|
+
});
|
|
3464
|
+
return nodes;
|
|
3465
|
+
}
|
|
3466
|
+
setAttribute(attributes) {
|
|
3467
|
+
const oldSelection = this.editor.state.selection;
|
|
3468
|
+
this.editor.chain().setTextSelection(this.from).updateAttributes(this.node.type.name, attributes).setTextSelection(oldSelection.from)
|
|
3469
|
+
.run();
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3316
3473
|
const style = `.ProseMirror {
|
|
3317
3474
|
position: relative;
|
|
3318
3475
|
}
|
|
@@ -3758,6 +3915,21 @@ class Editor extends EventEmitter {
|
|
|
3758
3915
|
// @ts-ignore
|
|
3759
3916
|
return !((_a = this.view) === null || _a === void 0 ? void 0 : _a.docView);
|
|
3760
3917
|
}
|
|
3918
|
+
$node(selector, attributes) {
|
|
3919
|
+
var _a;
|
|
3920
|
+
return ((_a = this.$doc) === null || _a === void 0 ? void 0 : _a.querySelector(selector, attributes)) || null;
|
|
3921
|
+
}
|
|
3922
|
+
$nodes(selector, attributes) {
|
|
3923
|
+
var _a;
|
|
3924
|
+
return ((_a = this.$doc) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selector, attributes)) || null;
|
|
3925
|
+
}
|
|
3926
|
+
$pos(pos) {
|
|
3927
|
+
const $pos = this.state.doc.resolve(pos);
|
|
3928
|
+
return new NodePos($pos, this);
|
|
3929
|
+
}
|
|
3930
|
+
get $doc() {
|
|
3931
|
+
return this.$pos(0);
|
|
3932
|
+
}
|
|
3761
3933
|
}
|
|
3762
3934
|
|
|
3763
3935
|
/**
|
|
@@ -3947,14 +4119,14 @@ class Mark {
|
|
|
3947
4119
|
this.child = null;
|
|
3948
4120
|
this.config = {
|
|
3949
4121
|
name: this.name,
|
|
3950
|
-
defaultOptions:
|
|
4122
|
+
defaultOptions: {},
|
|
3951
4123
|
};
|
|
3952
4124
|
this.config = {
|
|
3953
4125
|
...this.config,
|
|
3954
4126
|
...config,
|
|
3955
4127
|
};
|
|
3956
4128
|
this.name = this.config.name;
|
|
3957
|
-
if (config.defaultOptions) {
|
|
4129
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
3958
4130
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
3959
4131
|
}
|
|
3960
4132
|
// TODO: remove `addOptions` fallback
|
|
@@ -4030,14 +4202,14 @@ class Node {
|
|
|
4030
4202
|
this.child = null;
|
|
4031
4203
|
this.config = {
|
|
4032
4204
|
name: this.name,
|
|
4033
|
-
defaultOptions:
|
|
4205
|
+
defaultOptions: {},
|
|
4034
4206
|
};
|
|
4035
4207
|
this.config = {
|
|
4036
4208
|
...this.config,
|
|
4037
4209
|
...config,
|
|
4038
4210
|
};
|
|
4039
4211
|
this.name = this.config.name;
|
|
4040
|
-
if (config.defaultOptions) {
|
|
4212
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
4041
4213
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
4042
4214
|
}
|
|
4043
4215
|
// TODO: remove `addOptions` fallback
|
|
@@ -4406,6 +4578,7 @@ exports.Extension = Extension;
|
|
|
4406
4578
|
exports.InputRule = InputRule;
|
|
4407
4579
|
exports.Mark = Mark;
|
|
4408
4580
|
exports.Node = Node;
|
|
4581
|
+
exports.NodePos = NodePos;
|
|
4409
4582
|
exports.NodeView = NodeView;
|
|
4410
4583
|
exports.PasteRule = PasteRule;
|
|
4411
4584
|
exports.Tracker = Tracker;
|