@tiptap/core 3.10.8 → 3.11.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 +132 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -6
- package/dist/index.d.ts +63 -6
- package/dist/index.js +125 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Editor.ts +5 -0
- package/src/Mark.ts +1 -1
- package/src/Node.ts +1 -1
- package/src/commands/index.ts +2 -0
- package/src/commands/setTextDirection.ts +51 -0
- package/src/commands/unsetTextDirection.ts +51 -0
- package/src/extensions/index.ts +1 -0
- package/src/extensions/textDirection.ts +86 -0
- package/src/types.ts +10 -1
package/dist/index.cjs
CHANGED
|
@@ -322,6 +322,7 @@ __export(commands_exports, {
|
|
|
322
322
|
setMeta: () => setMeta,
|
|
323
323
|
setNode: () => setNode,
|
|
324
324
|
setNodeSelection: () => setNodeSelection,
|
|
325
|
+
setTextDirection: () => setTextDirection,
|
|
325
326
|
setTextSelection: () => setTextSelection,
|
|
326
327
|
sinkListItem: () => sinkListItem,
|
|
327
328
|
splitBlock: () => splitBlock,
|
|
@@ -333,6 +334,7 @@ __export(commands_exports, {
|
|
|
333
334
|
undoInputRule: () => undoInputRule,
|
|
334
335
|
unsetAllMarks: () => unsetAllMarks,
|
|
335
336
|
unsetMark: () => unsetMark,
|
|
337
|
+
unsetTextDirection: () => unsetTextDirection,
|
|
336
338
|
updateAttributes: () => updateAttributes,
|
|
337
339
|
wrapIn: () => wrapIn,
|
|
338
340
|
wrapInList: () => wrapInList
|
|
@@ -2456,6 +2458,35 @@ var setNodeSelection = (position) => ({ tr, dispatch }) => {
|
|
|
2456
2458
|
return true;
|
|
2457
2459
|
};
|
|
2458
2460
|
|
|
2461
|
+
// src/commands/setTextDirection.ts
|
|
2462
|
+
var setTextDirection = (direction, position) => ({ tr, state, dispatch }) => {
|
|
2463
|
+
const { selection } = state;
|
|
2464
|
+
let from;
|
|
2465
|
+
let to;
|
|
2466
|
+
if (typeof position === "number") {
|
|
2467
|
+
from = position;
|
|
2468
|
+
to = position;
|
|
2469
|
+
} else if (position && "from" in position && "to" in position) {
|
|
2470
|
+
from = position.from;
|
|
2471
|
+
to = position.to;
|
|
2472
|
+
} else {
|
|
2473
|
+
from = selection.from;
|
|
2474
|
+
to = selection.to;
|
|
2475
|
+
}
|
|
2476
|
+
if (dispatch) {
|
|
2477
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
2478
|
+
if (node.isText) {
|
|
2479
|
+
return;
|
|
2480
|
+
}
|
|
2481
|
+
tr.setNodeMarkup(pos, void 0, {
|
|
2482
|
+
...node.attrs,
|
|
2483
|
+
dir: direction
|
|
2484
|
+
});
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
return true;
|
|
2488
|
+
};
|
|
2489
|
+
|
|
2459
2490
|
// src/commands/setTextSelection.ts
|
|
2460
2491
|
var import_state9 = require("@tiptap/pm/state");
|
|
2461
2492
|
var setTextSelection = (position) => ({ tr, dispatch }) => {
|
|
@@ -2819,6 +2850,34 @@ var unsetMark = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
|
|
|
2819
2850
|
return true;
|
|
2820
2851
|
};
|
|
2821
2852
|
|
|
2853
|
+
// src/commands/unsetTextDirection.ts
|
|
2854
|
+
var unsetTextDirection = (position) => ({ tr, state, dispatch }) => {
|
|
2855
|
+
const { selection } = state;
|
|
2856
|
+
let from;
|
|
2857
|
+
let to;
|
|
2858
|
+
if (typeof position === "number") {
|
|
2859
|
+
from = position;
|
|
2860
|
+
to = position;
|
|
2861
|
+
} else if (position && "from" in position && "to" in position) {
|
|
2862
|
+
from = position.from;
|
|
2863
|
+
to = position.to;
|
|
2864
|
+
} else {
|
|
2865
|
+
from = selection.from;
|
|
2866
|
+
to = selection.to;
|
|
2867
|
+
}
|
|
2868
|
+
if (dispatch) {
|
|
2869
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
2870
|
+
if (node.isText) {
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
const newAttrs = { ...node.attrs };
|
|
2874
|
+
delete newAttrs.dir;
|
|
2875
|
+
tr.setNodeMarkup(pos, void 0, newAttrs);
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2878
|
+
return true;
|
|
2879
|
+
};
|
|
2880
|
+
|
|
2822
2881
|
// src/commands/updateAttributes.ts
|
|
2823
2882
|
var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
|
2824
2883
|
let nodeType = null;
|
|
@@ -2936,7 +2995,7 @@ var wrapInList = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
|
|
2936
2995
|
};
|
|
2937
2996
|
|
|
2938
2997
|
// src/Editor.ts
|
|
2939
|
-
var
|
|
2998
|
+
var import_state22 = require("@tiptap/pm/state");
|
|
2940
2999
|
var import_view = require("@tiptap/pm/view");
|
|
2941
3000
|
|
|
2942
3001
|
// src/EventEmitter.ts
|
|
@@ -3795,6 +3854,7 @@ __export(extensions_exports, {
|
|
|
3795
3854
|
Keymap: () => Keymap,
|
|
3796
3855
|
Paste: () => Paste,
|
|
3797
3856
|
Tabindex: () => Tabindex,
|
|
3857
|
+
TextDirection: () => TextDirection,
|
|
3798
3858
|
focusEventsPluginKey: () => focusEventsPluginKey
|
|
3799
3859
|
});
|
|
3800
3860
|
|
|
@@ -4164,6 +4224,66 @@ var Tabindex = Extension.create({
|
|
|
4164
4224
|
}
|
|
4165
4225
|
});
|
|
4166
4226
|
|
|
4227
|
+
// src/extensions/textDirection.ts
|
|
4228
|
+
var import_state21 = require("@tiptap/pm/state");
|
|
4229
|
+
var TextDirection = Extension.create({
|
|
4230
|
+
name: "textDirection",
|
|
4231
|
+
addOptions() {
|
|
4232
|
+
return {
|
|
4233
|
+
direction: void 0
|
|
4234
|
+
};
|
|
4235
|
+
},
|
|
4236
|
+
addGlobalAttributes() {
|
|
4237
|
+
if (!this.options.direction) {
|
|
4238
|
+
return [];
|
|
4239
|
+
}
|
|
4240
|
+
const { nodeExtensions } = splitExtensions(this.extensions);
|
|
4241
|
+
return [
|
|
4242
|
+
{
|
|
4243
|
+
types: nodeExtensions.filter((extension) => extension.name !== "text").map((extension) => extension.name),
|
|
4244
|
+
attributes: {
|
|
4245
|
+
dir: {
|
|
4246
|
+
default: this.options.direction,
|
|
4247
|
+
parseHTML: (element) => {
|
|
4248
|
+
const dir = element.getAttribute("dir");
|
|
4249
|
+
if (dir && (dir === "ltr" || dir === "rtl" || dir === "auto")) {
|
|
4250
|
+
return dir;
|
|
4251
|
+
}
|
|
4252
|
+
return this.options.direction;
|
|
4253
|
+
},
|
|
4254
|
+
renderHTML: (attributes) => {
|
|
4255
|
+
if (!attributes.dir) {
|
|
4256
|
+
return {};
|
|
4257
|
+
}
|
|
4258
|
+
return {
|
|
4259
|
+
dir: attributes.dir
|
|
4260
|
+
};
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
];
|
|
4266
|
+
},
|
|
4267
|
+
addProseMirrorPlugins() {
|
|
4268
|
+
return [
|
|
4269
|
+
new import_state21.Plugin({
|
|
4270
|
+
key: new import_state21.PluginKey("textDirection"),
|
|
4271
|
+
props: {
|
|
4272
|
+
attributes: () => {
|
|
4273
|
+
const direction = this.options.direction;
|
|
4274
|
+
if (!direction) {
|
|
4275
|
+
return {};
|
|
4276
|
+
}
|
|
4277
|
+
return {
|
|
4278
|
+
dir: direction
|
|
4279
|
+
};
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
})
|
|
4283
|
+
];
|
|
4284
|
+
}
|
|
4285
|
+
});
|
|
4286
|
+
|
|
4167
4287
|
// src/NodePos.ts
|
|
4168
4288
|
var NodePos = class _NodePos {
|
|
4169
4289
|
constructor(pos, editor, isBlock = false, node = null) {
|
|
@@ -4455,6 +4575,7 @@ var Editor = class extends EventEmitter {
|
|
|
4455
4575
|
extensions: [],
|
|
4456
4576
|
autofocus: false,
|
|
4457
4577
|
editable: true,
|
|
4578
|
+
textDirection: void 0,
|
|
4458
4579
|
editorProps: {},
|
|
4459
4580
|
parseOptions: {},
|
|
4460
4581
|
coreExtensionOptions: {},
|
|
@@ -4503,7 +4624,7 @@ var Editor = class extends EventEmitter {
|
|
|
4503
4624
|
this.on("delete", this.options.onDelete);
|
|
4504
4625
|
const initialDoc = this.createDoc();
|
|
4505
4626
|
const selection = resolveFocusPosition(initialDoc, this.options.autofocus);
|
|
4506
|
-
this.editorState =
|
|
4627
|
+
this.editorState = import_state22.EditorState.create({
|
|
4507
4628
|
doc: initialDoc,
|
|
4508
4629
|
schema: this.schema,
|
|
4509
4630
|
selection: selection || void 0
|
|
@@ -4732,7 +4853,10 @@ var Editor = class extends EventEmitter {
|
|
|
4732
4853
|
Tabindex,
|
|
4733
4854
|
Drop,
|
|
4734
4855
|
Paste,
|
|
4735
|
-
Delete
|
|
4856
|
+
Delete,
|
|
4857
|
+
TextDirection.configure({
|
|
4858
|
+
direction: this.options.textDirection
|
|
4859
|
+
})
|
|
4736
4860
|
].filter((ext) => {
|
|
4737
4861
|
if (typeof this.options.enableCoreExtensions === "object") {
|
|
4738
4862
|
return this.options.enableCoreExtensions[ext.name] !== false;
|
|
@@ -5686,11 +5810,11 @@ var ResizableNodeView = class {
|
|
|
5686
5810
|
var ResizableNodeview = ResizableNodeView;
|
|
5687
5811
|
|
|
5688
5812
|
// src/utilities/canInsertNode.ts
|
|
5689
|
-
var
|
|
5813
|
+
var import_state23 = require("@tiptap/pm/state");
|
|
5690
5814
|
function canInsertNode(state, nodeType) {
|
|
5691
5815
|
const { selection } = state;
|
|
5692
5816
|
const { $from } = selection;
|
|
5693
|
-
if (selection instanceof
|
|
5817
|
+
if (selection instanceof import_state23.NodeSelection) {
|
|
5694
5818
|
const index = $from.index();
|
|
5695
5819
|
const parent = $from.parent;
|
|
5696
5820
|
return parent.canReplaceWith(index, index + 1, nodeType);
|
|
@@ -6309,7 +6433,7 @@ var Node3 = class _Node extends Extendable {
|
|
|
6309
6433
|
};
|
|
6310
6434
|
|
|
6311
6435
|
// src/NodeView.ts
|
|
6312
|
-
var
|
|
6436
|
+
var import_state24 = require("@tiptap/pm/state");
|
|
6313
6437
|
var NodeView = class {
|
|
6314
6438
|
constructor(component, props, options) {
|
|
6315
6439
|
this.isDragging = false;
|
|
@@ -6389,7 +6513,7 @@ var NodeView = class {
|
|
|
6389
6513
|
if (typeof pos !== "number") {
|
|
6390
6514
|
return;
|
|
6391
6515
|
}
|
|
6392
|
-
const selection =
|
|
6516
|
+
const selection = import_state24.NodeSelection.create(view.state.doc, pos);
|
|
6393
6517
|
const transaction = view.state.tr.setSelection(selection);
|
|
6394
6518
|
view.dispatch(transaction);
|
|
6395
6519
|
}
|
|
@@ -6415,7 +6539,7 @@ var NodeView = class {
|
|
|
6415
6539
|
const { isEditable } = this.editor;
|
|
6416
6540
|
const { isDragging } = this;
|
|
6417
6541
|
const isDraggable = !!this.node.type.spec.draggable;
|
|
6418
|
-
const isSelectable =
|
|
6542
|
+
const isSelectable = import_state24.NodeSelection.isSelectable(this.node);
|
|
6419
6543
|
const isCopyEvent = event.type === "copy";
|
|
6420
6544
|
const isPasteEvent = event.type === "paste";
|
|
6421
6545
|
const isCutEvent = event.type === "cut";
|