@tiptap/core 3.22.1 → 3.22.2
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 +81 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/toggleList.ts +69 -7
- package/src/pasteRules/markPasteRule.ts +10 -1
package/dist/index.cjs
CHANGED
|
@@ -2793,6 +2793,7 @@ var splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state, dispatch,
|
|
|
2793
2793
|
};
|
|
2794
2794
|
|
|
2795
2795
|
// src/commands/toggleList.ts
|
|
2796
|
+
var import_state12 = require("@tiptap/pm/state");
|
|
2796
2797
|
var import_transform8 = require("@tiptap/pm/transform");
|
|
2797
2798
|
var joinListBackwards = (tr, listType) => {
|
|
2798
2799
|
const list = findParentNode((node) => node.type === listType)(tr.selection);
|
|
@@ -2828,6 +2829,16 @@ var joinListForwards = (tr, listType) => {
|
|
|
2828
2829
|
tr.join(after);
|
|
2829
2830
|
return true;
|
|
2830
2831
|
};
|
|
2832
|
+
function createInnerSelectionForWholeDocList(tr) {
|
|
2833
|
+
const doc = tr.doc;
|
|
2834
|
+
const list = doc.firstChild;
|
|
2835
|
+
if (!list) {
|
|
2836
|
+
return null;
|
|
2837
|
+
}
|
|
2838
|
+
const from = 1;
|
|
2839
|
+
const to = list.nodeSize - 1;
|
|
2840
|
+
return import_state12.TextSelection.create(doc, from, to);
|
|
2841
|
+
}
|
|
2831
2842
|
var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr, state, dispatch, chain, commands, can }) => {
|
|
2832
2843
|
const { extensions, splittableMarks } = editor.extensionManager;
|
|
2833
2844
|
const listType = getNodeType(listTypeOrName, state.schema);
|
|
@@ -2840,13 +2851,37 @@ var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>
|
|
|
2840
2851
|
return false;
|
|
2841
2852
|
}
|
|
2842
2853
|
const parentList = findParentNode((node) => isList(node.type.name, extensions))(selection);
|
|
2843
|
-
|
|
2844
|
-
|
|
2854
|
+
const isAllSelection = selection.from === 0 && selection.to === state.doc.content.size;
|
|
2855
|
+
const topLevelNodes = state.doc.content.content;
|
|
2856
|
+
const soleTopLevelNode = topLevelNodes.length === 1 ? topLevelNodes[0] : null;
|
|
2857
|
+
const allSelectionList = isAllSelection && soleTopLevelNode && isList(soleTopLevelNode.type.name, extensions) ? {
|
|
2858
|
+
node: soleTopLevelNode,
|
|
2859
|
+
pos: 0,
|
|
2860
|
+
depth: 0
|
|
2861
|
+
} : null;
|
|
2862
|
+
const currentList = parentList != null ? parentList : allSelectionList;
|
|
2863
|
+
const isInsideExistingList = !!parentList && range.depth >= 1 && range.depth - parentList.depth <= 1;
|
|
2864
|
+
const hasWholeDocSelectedList = !!allSelectionList;
|
|
2865
|
+
if ((isInsideExistingList || hasWholeDocSelectedList) && currentList) {
|
|
2866
|
+
if (currentList.node.type === listType) {
|
|
2867
|
+
if (isAllSelection && hasWholeDocSelectedList) {
|
|
2868
|
+
return chain().command(({ tr: trx, dispatch: disp }) => {
|
|
2869
|
+
const nextSelection = createInnerSelectionForWholeDocList(trx);
|
|
2870
|
+
if (!nextSelection) {
|
|
2871
|
+
return false;
|
|
2872
|
+
}
|
|
2873
|
+
trx.setSelection(nextSelection);
|
|
2874
|
+
if (disp) {
|
|
2875
|
+
disp(trx);
|
|
2876
|
+
}
|
|
2877
|
+
return true;
|
|
2878
|
+
}).liftListItem(itemType).run();
|
|
2879
|
+
}
|
|
2845
2880
|
return commands.liftListItem(itemType);
|
|
2846
2881
|
}
|
|
2847
|
-
if (isList(
|
|
2882
|
+
if (isList(currentList.node.type.name, extensions) && listType.validContent(currentList.node.content)) {
|
|
2848
2883
|
return chain().command(() => {
|
|
2849
|
-
tr.setNodeMarkup(
|
|
2884
|
+
tr.setNodeMarkup(currentList.pos, listType);
|
|
2850
2885
|
return true;
|
|
2851
2886
|
}).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
2852
2887
|
}
|
|
@@ -3121,7 +3156,7 @@ var wrapInList = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
|
|
3121
3156
|
};
|
|
3122
3157
|
|
|
3123
3158
|
// src/Editor.ts
|
|
3124
|
-
var
|
|
3159
|
+
var import_state23 = require("@tiptap/pm/state");
|
|
3125
3160
|
var import_view = require("@tiptap/pm/view");
|
|
3126
3161
|
|
|
3127
3162
|
// src/EventEmitter.ts
|
|
@@ -3171,7 +3206,7 @@ var import_keymap = require("@tiptap/pm/keymap");
|
|
|
3171
3206
|
|
|
3172
3207
|
// src/InputRule.ts
|
|
3173
3208
|
var import_model9 = require("@tiptap/pm/model");
|
|
3174
|
-
var
|
|
3209
|
+
var import_state13 = require("@tiptap/pm/state");
|
|
3175
3210
|
var InputRule = class {
|
|
3176
3211
|
constructor(config) {
|
|
3177
3212
|
var _a;
|
|
@@ -3264,7 +3299,7 @@ function run(config) {
|
|
|
3264
3299
|
}
|
|
3265
3300
|
function inputRulesPlugin(props) {
|
|
3266
3301
|
const { editor, rules } = props;
|
|
3267
|
-
const plugin = new
|
|
3302
|
+
const plugin = new import_state13.Plugin({
|
|
3268
3303
|
state: {
|
|
3269
3304
|
init() {
|
|
3270
3305
|
return null;
|
|
@@ -3480,7 +3515,7 @@ var Mark = class _Mark extends Extendable {
|
|
|
3480
3515
|
|
|
3481
3516
|
// src/PasteRule.ts
|
|
3482
3517
|
var import_model10 = require("@tiptap/pm/model");
|
|
3483
|
-
var
|
|
3518
|
+
var import_state14 = require("@tiptap/pm/state");
|
|
3484
3519
|
|
|
3485
3520
|
// src/utilities/isNumber.ts
|
|
3486
3521
|
function isNumber(value) {
|
|
@@ -3616,7 +3651,7 @@ function pasteRulesPlugin(props) {
|
|
|
3616
3651
|
return tr;
|
|
3617
3652
|
};
|
|
3618
3653
|
const plugins = rules.map((rule) => {
|
|
3619
|
-
return new
|
|
3654
|
+
return new import_state14.Plugin({
|
|
3620
3655
|
// we register a global drag handler to track the current drag source element
|
|
3621
3656
|
view(view) {
|
|
3622
3657
|
const handleDragstart = (event) => {
|
|
@@ -4047,7 +4082,7 @@ __export(extensions_exports, {
|
|
|
4047
4082
|
});
|
|
4048
4083
|
|
|
4049
4084
|
// src/extensions/clipboardTextSerializer.ts
|
|
4050
|
-
var
|
|
4085
|
+
var import_state15 = require("@tiptap/pm/state");
|
|
4051
4086
|
|
|
4052
4087
|
// src/Extension.ts
|
|
4053
4088
|
var Extension = class _Extension extends Extendable {
|
|
@@ -4082,8 +4117,8 @@ var ClipboardTextSerializer = Extension.create({
|
|
|
4082
4117
|
},
|
|
4083
4118
|
addProseMirrorPlugins() {
|
|
4084
4119
|
return [
|
|
4085
|
-
new
|
|
4086
|
-
key: new
|
|
4120
|
+
new import_state15.Plugin({
|
|
4121
|
+
key: new import_state15.PluginKey("clipboardTextSerializer"),
|
|
4087
4122
|
props: {
|
|
4088
4123
|
clipboardTextSerializer: () => {
|
|
4089
4124
|
const { editor } = this;
|
|
@@ -4190,13 +4225,13 @@ var Delete = Extension.create({
|
|
|
4190
4225
|
});
|
|
4191
4226
|
|
|
4192
4227
|
// src/extensions/drop.ts
|
|
4193
|
-
var
|
|
4228
|
+
var import_state16 = require("@tiptap/pm/state");
|
|
4194
4229
|
var Drop = Extension.create({
|
|
4195
4230
|
name: "drop",
|
|
4196
4231
|
addProseMirrorPlugins() {
|
|
4197
4232
|
return [
|
|
4198
|
-
new
|
|
4199
|
-
key: new
|
|
4233
|
+
new import_state16.Plugin({
|
|
4234
|
+
key: new import_state16.PluginKey("tiptapDrop"),
|
|
4200
4235
|
props: {
|
|
4201
4236
|
handleDrop: (_, e, slice, moved) => {
|
|
4202
4237
|
this.editor.emit("drop", {
|
|
@@ -4213,13 +4248,13 @@ var Drop = Extension.create({
|
|
|
4213
4248
|
});
|
|
4214
4249
|
|
|
4215
4250
|
// src/extensions/editable.ts
|
|
4216
|
-
var
|
|
4251
|
+
var import_state17 = require("@tiptap/pm/state");
|
|
4217
4252
|
var Editable = Extension.create({
|
|
4218
4253
|
name: "editable",
|
|
4219
4254
|
addProseMirrorPlugins() {
|
|
4220
4255
|
return [
|
|
4221
|
-
new
|
|
4222
|
-
key: new
|
|
4256
|
+
new import_state17.Plugin({
|
|
4257
|
+
key: new import_state17.PluginKey("editable"),
|
|
4223
4258
|
props: {
|
|
4224
4259
|
editable: () => this.editor.options.editable
|
|
4225
4260
|
}
|
|
@@ -4229,14 +4264,14 @@ var Editable = Extension.create({
|
|
|
4229
4264
|
});
|
|
4230
4265
|
|
|
4231
4266
|
// src/extensions/focusEvents.ts
|
|
4232
|
-
var
|
|
4233
|
-
var focusEventsPluginKey = new
|
|
4267
|
+
var import_state18 = require("@tiptap/pm/state");
|
|
4268
|
+
var focusEventsPluginKey = new import_state18.PluginKey("focusEvents");
|
|
4234
4269
|
var FocusEvents = Extension.create({
|
|
4235
4270
|
name: "focusEvents",
|
|
4236
4271
|
addProseMirrorPlugins() {
|
|
4237
4272
|
const { editor } = this;
|
|
4238
4273
|
return [
|
|
4239
|
-
new
|
|
4274
|
+
new import_state18.Plugin({
|
|
4240
4275
|
key: focusEventsPluginKey,
|
|
4241
4276
|
props: {
|
|
4242
4277
|
handleDOMEvents: {
|
|
@@ -4260,7 +4295,7 @@ var FocusEvents = Extension.create({
|
|
|
4260
4295
|
});
|
|
4261
4296
|
|
|
4262
4297
|
// src/extensions/keymap.ts
|
|
4263
|
-
var
|
|
4298
|
+
var import_state19 = require("@tiptap/pm/state");
|
|
4264
4299
|
var Keymap = Extension.create({
|
|
4265
4300
|
name: "keymap",
|
|
4266
4301
|
addKeyboardShortcuts() {
|
|
@@ -4274,7 +4309,7 @@ var Keymap = Extension.create({
|
|
|
4274
4309
|
const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor;
|
|
4275
4310
|
const parentIsIsolating = $parentPos.parent.type.spec.isolating;
|
|
4276
4311
|
const parentPos = $anchor.pos - $anchor.parentOffset;
|
|
4277
|
-
const isAtStart = parentIsIsolating && $parentPos.parent.childCount === 1 ? parentPos === $anchor.pos :
|
|
4312
|
+
const isAtStart = parentIsIsolating && $parentPos.parent.childCount === 1 ? parentPos === $anchor.pos : import_state19.Selection.atStart(doc).from === pos;
|
|
4278
4313
|
if (!empty || !parent.type.isTextblock || parent.textContent.length || !isAtStart || isAtStart && $anchor.parent.type.name === "paragraph") {
|
|
4279
4314
|
return false;
|
|
4280
4315
|
}
|
|
@@ -4332,8 +4367,8 @@ var Keymap = Extension.create({
|
|
|
4332
4367
|
// to a paragraph if necessary.
|
|
4333
4368
|
// This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
|
|
4334
4369
|
// with many other commands.
|
|
4335
|
-
new
|
|
4336
|
-
key: new
|
|
4370
|
+
new import_state19.Plugin({
|
|
4371
|
+
key: new import_state19.PluginKey("clearDocument"),
|
|
4337
4372
|
appendTransaction: (transactions, oldState, newState) => {
|
|
4338
4373
|
if (transactions.some((tr2) => tr2.getMeta("composition"))) {
|
|
4339
4374
|
return;
|
|
@@ -4344,8 +4379,8 @@ var Keymap = Extension.create({
|
|
|
4344
4379
|
return;
|
|
4345
4380
|
}
|
|
4346
4381
|
const { empty, from, to } = oldState.selection;
|
|
4347
|
-
const allFrom =
|
|
4348
|
-
const allEnd =
|
|
4382
|
+
const allFrom = import_state19.Selection.atStart(oldState.doc).from;
|
|
4383
|
+
const allEnd = import_state19.Selection.atEnd(oldState.doc).to;
|
|
4349
4384
|
const allWasSelected = from === allFrom && to === allEnd;
|
|
4350
4385
|
if (empty || !allWasSelected) {
|
|
4351
4386
|
return;
|
|
@@ -4375,13 +4410,13 @@ var Keymap = Extension.create({
|
|
|
4375
4410
|
});
|
|
4376
4411
|
|
|
4377
4412
|
// src/extensions/paste.ts
|
|
4378
|
-
var
|
|
4413
|
+
var import_state20 = require("@tiptap/pm/state");
|
|
4379
4414
|
var Paste = Extension.create({
|
|
4380
4415
|
name: "paste",
|
|
4381
4416
|
addProseMirrorPlugins() {
|
|
4382
4417
|
return [
|
|
4383
|
-
new
|
|
4384
|
-
key: new
|
|
4418
|
+
new import_state20.Plugin({
|
|
4419
|
+
key: new import_state20.PluginKey("tiptapPaste"),
|
|
4385
4420
|
props: {
|
|
4386
4421
|
handlePaste: (_view, e, slice) => {
|
|
4387
4422
|
this.editor.emit("paste", {
|
|
@@ -4397,13 +4432,13 @@ var Paste = Extension.create({
|
|
|
4397
4432
|
});
|
|
4398
4433
|
|
|
4399
4434
|
// src/extensions/tabindex.ts
|
|
4400
|
-
var
|
|
4435
|
+
var import_state21 = require("@tiptap/pm/state");
|
|
4401
4436
|
var Tabindex = Extension.create({
|
|
4402
4437
|
name: "tabindex",
|
|
4403
4438
|
addProseMirrorPlugins() {
|
|
4404
4439
|
return [
|
|
4405
|
-
new
|
|
4406
|
-
key: new
|
|
4440
|
+
new import_state21.Plugin({
|
|
4441
|
+
key: new import_state21.PluginKey("tabindex"),
|
|
4407
4442
|
props: {
|
|
4408
4443
|
attributes: () => this.editor.isEditable ? { tabindex: "0" } : {}
|
|
4409
4444
|
}
|
|
@@ -4413,7 +4448,7 @@ var Tabindex = Extension.create({
|
|
|
4413
4448
|
});
|
|
4414
4449
|
|
|
4415
4450
|
// src/extensions/textDirection.ts
|
|
4416
|
-
var
|
|
4451
|
+
var import_state22 = require("@tiptap/pm/state");
|
|
4417
4452
|
var TextDirection = Extension.create({
|
|
4418
4453
|
name: "textDirection",
|
|
4419
4454
|
addOptions() {
|
|
@@ -4454,8 +4489,8 @@ var TextDirection = Extension.create({
|
|
|
4454
4489
|
},
|
|
4455
4490
|
addProseMirrorPlugins() {
|
|
4456
4491
|
return [
|
|
4457
|
-
new
|
|
4458
|
-
key: new
|
|
4492
|
+
new import_state22.Plugin({
|
|
4493
|
+
key: new import_state22.PluginKey("textDirection"),
|
|
4459
4494
|
props: {
|
|
4460
4495
|
attributes: () => {
|
|
4461
4496
|
const direction = this.options.direction;
|
|
@@ -4821,7 +4856,7 @@ var Editor = class extends EventEmitter {
|
|
|
4821
4856
|
this.on("delete", this.options.onDelete);
|
|
4822
4857
|
const initialDoc = this.createDoc();
|
|
4823
4858
|
const selection = resolveFocusPosition(initialDoc, this.options.autofocus);
|
|
4824
|
-
this.editorState =
|
|
4859
|
+
this.editorState = import_state23.EditorState.create({
|
|
4825
4860
|
doc: initialDoc,
|
|
4826
4861
|
schema: this.schema,
|
|
4827
4862
|
selection: selection || void 0
|
|
@@ -6056,11 +6091,11 @@ var ResizableNodeView = class {
|
|
|
6056
6091
|
var ResizableNodeview = ResizableNodeView;
|
|
6057
6092
|
|
|
6058
6093
|
// src/utilities/canInsertNode.ts
|
|
6059
|
-
var
|
|
6094
|
+
var import_state24 = require("@tiptap/pm/state");
|
|
6060
6095
|
function canInsertNode(state, nodeType) {
|
|
6061
6096
|
const { selection } = state;
|
|
6062
6097
|
const { $from } = selection;
|
|
6063
|
-
if (selection instanceof
|
|
6098
|
+
if (selection instanceof import_state24.NodeSelection) {
|
|
6064
6099
|
const index = $from.index();
|
|
6065
6100
|
const parent = $from.parent;
|
|
6066
6101
|
return parent.canReplaceWith(index, index + 1, nodeType);
|
|
@@ -6741,7 +6776,7 @@ var Node3 = class _Node extends Extendable {
|
|
|
6741
6776
|
};
|
|
6742
6777
|
|
|
6743
6778
|
// src/NodeView.ts
|
|
6744
|
-
var
|
|
6779
|
+
var import_state25 = require("@tiptap/pm/state");
|
|
6745
6780
|
var NodeView = class {
|
|
6746
6781
|
constructor(component, props, options) {
|
|
6747
6782
|
this.isDragging = false;
|
|
@@ -6821,7 +6856,7 @@ var NodeView = class {
|
|
|
6821
6856
|
if (typeof pos !== "number") {
|
|
6822
6857
|
return;
|
|
6823
6858
|
}
|
|
6824
|
-
const selection =
|
|
6859
|
+
const selection = import_state25.NodeSelection.create(view.state.doc, pos);
|
|
6825
6860
|
const transaction = view.state.tr.setSelection(selection);
|
|
6826
6861
|
view.dispatch(transaction);
|
|
6827
6862
|
}
|
|
@@ -6848,7 +6883,7 @@ var NodeView = class {
|
|
|
6848
6883
|
const { isEditable } = this.editor;
|
|
6849
6884
|
const { isDragging } = this;
|
|
6850
6885
|
const isDraggable = !!this.node.type.spec.draggable;
|
|
6851
|
-
const isSelectable =
|
|
6886
|
+
const isSelectable = import_state25.NodeSelection.isSelectable(this.node);
|
|
6852
6887
|
const isCopyEvent = event.type === "copy";
|
|
6853
6888
|
const isPasteEvent = event.type === "paste";
|
|
6854
6889
|
const isCutEvent = event.type === "cut";
|
|
@@ -6986,7 +7021,10 @@ function markPasteRule(config) {
|
|
|
6986
7021
|
}
|
|
6987
7022
|
markEnd = range.from + startSpaces + captureGroup.length;
|
|
6988
7023
|
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
|
|
6989
|
-
|
|
7024
|
+
const isMatchAtEndOfText = match.index !== void 0 && match.input !== void 0 && match.index + match[0].length >= match.input.length;
|
|
7025
|
+
if (!isMatchAtEndOfText) {
|
|
7026
|
+
tr.removeStoredMark(config.type);
|
|
7027
|
+
}
|
|
6990
7028
|
}
|
|
6991
7029
|
}
|
|
6992
7030
|
});
|