@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.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EditorView } from '@tiptap/pm/view';
|
|
|
3
3
|
import { keymap } from '@tiptap/pm/keymap';
|
|
4
4
|
import { Schema, Fragment, DOMParser, DOMSerializer, Node as Node$1, Slice } from '@tiptap/pm/model';
|
|
5
5
|
import { liftTarget, ReplaceStep, ReplaceAroundStep, joinPoint, Transform, canSplit, canJoin, findWrapping } from '@tiptap/pm/transform';
|
|
6
|
-
import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from '@tiptap/pm/commands';
|
|
6
|
+
import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, joinTextblockBackward as joinTextblockBackward$1, joinTextblockForward as joinTextblockForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from '@tiptap/pm/commands';
|
|
7
7
|
import { liftListItem as liftListItem$1, sinkListItem as sinkListItem$1, wrapInList as wrapInList$1 } from '@tiptap/pm/schema-list';
|
|
8
8
|
|
|
9
9
|
function createChainableState(config) {
|
|
@@ -15,7 +15,6 @@ function createChainableState(config) {
|
|
|
15
15
|
...state,
|
|
16
16
|
apply: state.apply.bind(state),
|
|
17
17
|
applyTransaction: state.applyTransaction.bind(state),
|
|
18
|
-
filterTransaction: state.filterTransaction,
|
|
19
18
|
plugins: state.plugins,
|
|
20
19
|
schema: state.schema,
|
|
21
20
|
reconfigure: state.reconfigure.bind(state),
|
|
@@ -730,11 +729,11 @@ class PasteRule {
|
|
|
730
729
|
this.handler = config.handler;
|
|
731
730
|
}
|
|
732
731
|
}
|
|
733
|
-
const pasteRuleMatcherHandler = (text, find) => {
|
|
732
|
+
const pasteRuleMatcherHandler = (text, find, event) => {
|
|
734
733
|
if (isRegExp(find)) {
|
|
735
734
|
return [...text.matchAll(find)];
|
|
736
735
|
}
|
|
737
|
-
const matches = find(text);
|
|
736
|
+
const matches = find(text, event);
|
|
738
737
|
if (!matches) {
|
|
739
738
|
return [];
|
|
740
739
|
}
|
|
@@ -766,7 +765,7 @@ function run(config) {
|
|
|
766
765
|
const resolvedFrom = Math.max(from, pos);
|
|
767
766
|
const resolvedTo = Math.min(to, pos + node.content.size);
|
|
768
767
|
const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
|
|
769
|
-
const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
|
|
768
|
+
const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent);
|
|
770
769
|
matches.forEach(match => {
|
|
771
770
|
if (match.index === undefined) {
|
|
772
771
|
return;
|
|
@@ -1140,14 +1139,14 @@ class Extension {
|
|
|
1140
1139
|
this.child = null;
|
|
1141
1140
|
this.config = {
|
|
1142
1141
|
name: this.name,
|
|
1143
|
-
defaultOptions:
|
|
1142
|
+
defaultOptions: {},
|
|
1144
1143
|
};
|
|
1145
1144
|
this.config = {
|
|
1146
1145
|
...this.config,
|
|
1147
1146
|
...config,
|
|
1148
1147
|
};
|
|
1149
1148
|
this.name = this.config.name;
|
|
1150
|
-
if (config.defaultOptions) {
|
|
1149
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
1151
1150
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
1152
1151
|
}
|
|
1153
1152
|
// TODO: remove `addOptions` fallback
|
|
@@ -1753,6 +1752,14 @@ const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
|
1753
1752
|
}
|
|
1754
1753
|
};
|
|
1755
1754
|
|
|
1755
|
+
const joinTextblockBackward = () => ({ state, dispatch }) => {
|
|
1756
|
+
return joinTextblockBackward$1(state, dispatch);
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
const joinTextblockForward = () => ({ state, dispatch }) => {
|
|
1760
|
+
return joinTextblockForward$1(state, dispatch);
|
|
1761
|
+
};
|
|
1762
|
+
|
|
1756
1763
|
function isMacOS() {
|
|
1757
1764
|
return typeof navigator !== 'undefined'
|
|
1758
1765
|
? /Mac/.test(navigator.platform)
|
|
@@ -2307,6 +2314,9 @@ function getMarksBetween(from, to, doc) {
|
|
|
2307
2314
|
}
|
|
2308
2315
|
else {
|
|
2309
2316
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
2317
|
+
if (!node || node.nodeSize === undefined) {
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2310
2320
|
marks.push(...node.marks.map(mark => ({
|
|
2311
2321
|
from: pos,
|
|
2312
2322
|
to: pos + node.nodeSize,
|
|
@@ -3084,6 +3094,8 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3084
3094
|
joinForward: joinForward,
|
|
3085
3095
|
joinItemBackward: joinItemBackward,
|
|
3086
3096
|
joinItemForward: joinItemForward,
|
|
3097
|
+
joinTextblockBackward: joinTextblockBackward,
|
|
3098
|
+
joinTextblockForward: joinTextblockForward,
|
|
3087
3099
|
keyboardShortcut: keyboardShortcut,
|
|
3088
3100
|
lift: lift,
|
|
3089
3101
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3309,6 +3321,151 @@ var extensions = /*#__PURE__*/Object.freeze({
|
|
|
3309
3321
|
Tabindex: Tabindex
|
|
3310
3322
|
});
|
|
3311
3323
|
|
|
3324
|
+
class NodePos {
|
|
3325
|
+
constructor(pos, editor) {
|
|
3326
|
+
this.resolvedPos = pos;
|
|
3327
|
+
this.editor = editor;
|
|
3328
|
+
}
|
|
3329
|
+
get node() {
|
|
3330
|
+
return this.resolvedPos.node();
|
|
3331
|
+
}
|
|
3332
|
+
get element() {
|
|
3333
|
+
return this.editor.view.domAtPos(this.pos).node;
|
|
3334
|
+
}
|
|
3335
|
+
get depth() {
|
|
3336
|
+
return this.resolvedPos.depth;
|
|
3337
|
+
}
|
|
3338
|
+
get pos() {
|
|
3339
|
+
return this.resolvedPos.pos;
|
|
3340
|
+
}
|
|
3341
|
+
get content() {
|
|
3342
|
+
return this.node.content;
|
|
3343
|
+
}
|
|
3344
|
+
set content(content) {
|
|
3345
|
+
this.editor.commands.insertContentAt({ from: this.from, to: this.to }, content);
|
|
3346
|
+
}
|
|
3347
|
+
get attributes() {
|
|
3348
|
+
return this.node.attrs;
|
|
3349
|
+
}
|
|
3350
|
+
get textContent() {
|
|
3351
|
+
return this.node.textContent;
|
|
3352
|
+
}
|
|
3353
|
+
get size() {
|
|
3354
|
+
return this.node.nodeSize;
|
|
3355
|
+
}
|
|
3356
|
+
get from() {
|
|
3357
|
+
return this.resolvedPos.start(this.resolvedPos.depth);
|
|
3358
|
+
}
|
|
3359
|
+
get range() {
|
|
3360
|
+
return {
|
|
3361
|
+
from: this.from,
|
|
3362
|
+
to: this.to,
|
|
3363
|
+
};
|
|
3364
|
+
}
|
|
3365
|
+
get to() {
|
|
3366
|
+
return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1);
|
|
3367
|
+
}
|
|
3368
|
+
get parent() {
|
|
3369
|
+
if (this.depth === 0) {
|
|
3370
|
+
return null;
|
|
3371
|
+
}
|
|
3372
|
+
const parentPos = this.resolvedPos.start(this.resolvedPos.depth - 1);
|
|
3373
|
+
const $pos = this.resolvedPos.doc.resolve(parentPos);
|
|
3374
|
+
return new NodePos($pos, this.editor);
|
|
3375
|
+
}
|
|
3376
|
+
get before() {
|
|
3377
|
+
let $pos = this.resolvedPos.doc.resolve(this.from - 2);
|
|
3378
|
+
if ($pos.depth !== this.depth) {
|
|
3379
|
+
$pos = this.resolvedPos.doc.resolve(this.from - 3);
|
|
3380
|
+
}
|
|
3381
|
+
return new NodePos($pos, this.editor);
|
|
3382
|
+
}
|
|
3383
|
+
get after() {
|
|
3384
|
+
let $pos = this.resolvedPos.doc.resolve(this.to + 2);
|
|
3385
|
+
if ($pos.depth !== this.depth) {
|
|
3386
|
+
$pos = this.resolvedPos.doc.resolve(this.to + 3);
|
|
3387
|
+
}
|
|
3388
|
+
return new NodePos($pos, this.editor);
|
|
3389
|
+
}
|
|
3390
|
+
get children() {
|
|
3391
|
+
const children = [];
|
|
3392
|
+
this.node.content.forEach((node, offset) => {
|
|
3393
|
+
const targetPos = this.pos + offset + 1;
|
|
3394
|
+
const $pos = this.resolvedPos.doc.resolve(targetPos);
|
|
3395
|
+
if ($pos.depth === this.depth) {
|
|
3396
|
+
return;
|
|
3397
|
+
}
|
|
3398
|
+
children.push(new NodePos($pos, this.editor));
|
|
3399
|
+
});
|
|
3400
|
+
return children;
|
|
3401
|
+
}
|
|
3402
|
+
get firstChild() {
|
|
3403
|
+
return this.children[0] || null;
|
|
3404
|
+
}
|
|
3405
|
+
get lastChild() {
|
|
3406
|
+
const children = this.children;
|
|
3407
|
+
return children[children.length - 1] || null;
|
|
3408
|
+
}
|
|
3409
|
+
closest(selector, attributes = {}) {
|
|
3410
|
+
let node = null;
|
|
3411
|
+
let currentNode = this.parent;
|
|
3412
|
+
while (currentNode && !node) {
|
|
3413
|
+
if (currentNode.node.type.name === selector) {
|
|
3414
|
+
if (Object.keys(attributes).length > 0) {
|
|
3415
|
+
const nodeAttributes = currentNode.node.attrs;
|
|
3416
|
+
const attrKeys = Object.keys(attributes);
|
|
3417
|
+
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3418
|
+
const key = attrKeys[index];
|
|
3419
|
+
if (nodeAttributes[key] !== attributes[key]) {
|
|
3420
|
+
break;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
else {
|
|
3425
|
+
node = currentNode;
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
currentNode = currentNode.parent;
|
|
3429
|
+
}
|
|
3430
|
+
return node;
|
|
3431
|
+
}
|
|
3432
|
+
querySelector(selector, attributes = {}) {
|
|
3433
|
+
return this.querySelectorAll(selector, attributes, true)[0] || null;
|
|
3434
|
+
}
|
|
3435
|
+
querySelectorAll(selector, attributes = {}, firstItemOnly = false) {
|
|
3436
|
+
let nodes = [];
|
|
3437
|
+
// iterate through children recursively finding all nodes which match the selector with the node name
|
|
3438
|
+
if (!this.children || this.children.length === 0) {
|
|
3439
|
+
return nodes;
|
|
3440
|
+
}
|
|
3441
|
+
this.children.forEach(node => {
|
|
3442
|
+
if (node.node.type.name === selector) {
|
|
3443
|
+
if (Object.keys(attributes).length > 0) {
|
|
3444
|
+
const nodeAttributes = node.node.attrs;
|
|
3445
|
+
const attrKeys = Object.keys(attributes);
|
|
3446
|
+
for (let index = 0; index < attrKeys.length; index += 1) {
|
|
3447
|
+
const key = attrKeys[index];
|
|
3448
|
+
if (nodeAttributes[key] !== attributes[key]) {
|
|
3449
|
+
return;
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
nodes.push(node);
|
|
3454
|
+
if (firstItemOnly) {
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
nodes = nodes.concat(node.querySelectorAll(selector));
|
|
3459
|
+
});
|
|
3460
|
+
return nodes;
|
|
3461
|
+
}
|
|
3462
|
+
setAttribute(attributes) {
|
|
3463
|
+
const oldSelection = this.editor.state.selection;
|
|
3464
|
+
this.editor.chain().setTextSelection(this.from).updateAttributes(this.node.type.name, attributes).setTextSelection(oldSelection.from)
|
|
3465
|
+
.run();
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
|
|
3312
3469
|
const style = `.ProseMirror {
|
|
3313
3470
|
position: relative;
|
|
3314
3471
|
}
|
|
@@ -3754,6 +3911,21 @@ class Editor extends EventEmitter {
|
|
|
3754
3911
|
// @ts-ignore
|
|
3755
3912
|
return !((_a = this.view) === null || _a === void 0 ? void 0 : _a.docView);
|
|
3756
3913
|
}
|
|
3914
|
+
$node(selector, attributes) {
|
|
3915
|
+
var _a;
|
|
3916
|
+
return ((_a = this.$doc) === null || _a === void 0 ? void 0 : _a.querySelector(selector, attributes)) || null;
|
|
3917
|
+
}
|
|
3918
|
+
$nodes(selector, attributes) {
|
|
3919
|
+
var _a;
|
|
3920
|
+
return ((_a = this.$doc) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selector, attributes)) || null;
|
|
3921
|
+
}
|
|
3922
|
+
$pos(pos) {
|
|
3923
|
+
const $pos = this.state.doc.resolve(pos);
|
|
3924
|
+
return new NodePos($pos, this);
|
|
3925
|
+
}
|
|
3926
|
+
get $doc() {
|
|
3927
|
+
return this.$pos(0);
|
|
3928
|
+
}
|
|
3757
3929
|
}
|
|
3758
3930
|
|
|
3759
3931
|
/**
|
|
@@ -3943,14 +4115,14 @@ class Mark {
|
|
|
3943
4115
|
this.child = null;
|
|
3944
4116
|
this.config = {
|
|
3945
4117
|
name: this.name,
|
|
3946
|
-
defaultOptions:
|
|
4118
|
+
defaultOptions: {},
|
|
3947
4119
|
};
|
|
3948
4120
|
this.config = {
|
|
3949
4121
|
...this.config,
|
|
3950
4122
|
...config,
|
|
3951
4123
|
};
|
|
3952
4124
|
this.name = this.config.name;
|
|
3953
|
-
if (config.defaultOptions) {
|
|
4125
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
3954
4126
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
3955
4127
|
}
|
|
3956
4128
|
// TODO: remove `addOptions` fallback
|
|
@@ -4026,14 +4198,14 @@ class Node {
|
|
|
4026
4198
|
this.child = null;
|
|
4027
4199
|
this.config = {
|
|
4028
4200
|
name: this.name,
|
|
4029
|
-
defaultOptions:
|
|
4201
|
+
defaultOptions: {},
|
|
4030
4202
|
};
|
|
4031
4203
|
this.config = {
|
|
4032
4204
|
...this.config,
|
|
4033
4205
|
...config,
|
|
4034
4206
|
};
|
|
4035
4207
|
this.name = this.config.name;
|
|
4036
|
-
if (config.defaultOptions) {
|
|
4208
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
4037
4209
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
4038
4210
|
}
|
|
4039
4211
|
// TODO: remove `addOptions` fallback
|
|
@@ -4396,5 +4568,5 @@ class Tracker {
|
|
|
4396
4568
|
}
|
|
4397
4569
|
}
|
|
4398
4570
|
|
|
4399
|
-
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveFocusPosition, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4571
|
+
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodePos, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveFocusPosition, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4400
4572
|
//# sourceMappingURL=index.js.map
|