@tiptap/core 3.10.7 → 3.11.0

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 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
@@ -1172,23 +1174,28 @@ var resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
1172
1174
  if (schemaType === "mark") {
1173
1175
  markType = getMarkType(typeOrName, state.schema);
1174
1176
  }
1175
- if (dispatch) {
1176
- tr.selection.ranges.forEach((range) => {
1177
- state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
1178
- if (nodeType && nodeType === node.type) {
1177
+ let canReset = false;
1178
+ tr.selection.ranges.forEach((range) => {
1179
+ state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
1180
+ if (nodeType && nodeType === node.type) {
1181
+ canReset = true;
1182
+ if (dispatch) {
1179
1183
  tr.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes));
1180
1184
  }
1181
- if (markType && node.marks.length) {
1182
- node.marks.forEach((mark) => {
1183
- if (markType === mark.type) {
1185
+ }
1186
+ if (markType && node.marks.length) {
1187
+ node.marks.forEach((mark) => {
1188
+ if (markType === mark.type) {
1189
+ canReset = true;
1190
+ if (dispatch) {
1184
1191
  tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)));
1185
1192
  }
1186
- });
1187
- }
1188
- });
1193
+ }
1194
+ });
1195
+ }
1189
1196
  });
1190
- }
1191
- return true;
1197
+ });
1198
+ return canReset;
1192
1199
  };
1193
1200
 
1194
1201
  // src/commands/scrollIntoView.ts
@@ -1628,12 +1635,12 @@ function cleanUpSchemaItem(data) {
1628
1635
  );
1629
1636
  }
1630
1637
  function buildAttributeSpec(extensionAttribute) {
1631
- var _a, _b, _c;
1638
+ var _a, _b;
1632
1639
  const spec = {};
1633
- if (!((_a = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a.isRequired) && ((_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.default) !== void 0) {
1640
+ if (!((_a = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a.isRequired) && "default" in ((extensionAttribute == null ? void 0 : extensionAttribute.attribute) || {})) {
1634
1641
  spec.default = extensionAttribute.attribute.default;
1635
1642
  }
1636
- if (((_c = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _c.validate) !== void 0) {
1643
+ if (((_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate) !== void 0) {
1637
1644
  spec.validate = extensionAttribute.attribute.validate;
1638
1645
  }
1639
1646
  return [extensionAttribute.name, spec];
@@ -2451,6 +2458,35 @@ var setNodeSelection = (position) => ({ tr, dispatch }) => {
2451
2458
  return true;
2452
2459
  };
2453
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
+
2454
2490
  // src/commands/setTextSelection.ts
2455
2491
  var import_state9 = require("@tiptap/pm/state");
2456
2492
  var setTextSelection = (position) => ({ tr, dispatch }) => {
@@ -2814,6 +2850,34 @@ var unsetMark = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
2814
2850
  return true;
2815
2851
  };
2816
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
+
2817
2881
  // src/commands/updateAttributes.ts
2818
2882
  var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
2819
2883
  let nodeType = null;
@@ -2831,41 +2895,48 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
2831
2895
  if (schemaType === "mark") {
2832
2896
  markType = getMarkType(typeOrName, state.schema);
2833
2897
  }
2834
- if (dispatch) {
2835
- tr.selection.ranges.forEach((range) => {
2836
- const from = range.$from.pos;
2837
- const to = range.$to.pos;
2838
- let lastPos;
2839
- let lastNode;
2840
- let trimmedFrom;
2841
- let trimmedTo;
2842
- if (tr.selection.empty) {
2843
- state.doc.nodesBetween(from, to, (node, pos) => {
2898
+ let canUpdate = false;
2899
+ tr.selection.ranges.forEach((range) => {
2900
+ const from = range.$from.pos;
2901
+ const to = range.$to.pos;
2902
+ let lastPos;
2903
+ let lastNode;
2904
+ let trimmedFrom;
2905
+ let trimmedTo;
2906
+ if (tr.selection.empty) {
2907
+ state.doc.nodesBetween(from, to, (node, pos) => {
2908
+ if (nodeType && nodeType === node.type) {
2909
+ canUpdate = true;
2910
+ trimmedFrom = Math.max(pos, from);
2911
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2912
+ lastPos = pos;
2913
+ lastNode = node;
2914
+ }
2915
+ });
2916
+ } else {
2917
+ state.doc.nodesBetween(from, to, (node, pos) => {
2918
+ if (pos < from && nodeType && nodeType === node.type) {
2919
+ canUpdate = true;
2920
+ trimmedFrom = Math.max(pos, from);
2921
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2922
+ lastPos = pos;
2923
+ lastNode = node;
2924
+ }
2925
+ if (pos >= from && pos <= to) {
2844
2926
  if (nodeType && nodeType === node.type) {
2845
- trimmedFrom = Math.max(pos, from);
2846
- trimmedTo = Math.min(pos + node.nodeSize, to);
2847
- lastPos = pos;
2848
- lastNode = node;
2849
- }
2850
- });
2851
- } else {
2852
- state.doc.nodesBetween(from, to, (node, pos) => {
2853
- if (pos < from && nodeType && nodeType === node.type) {
2854
- trimmedFrom = Math.max(pos, from);
2855
- trimmedTo = Math.min(pos + node.nodeSize, to);
2856
- lastPos = pos;
2857
- lastNode = node;
2858
- }
2859
- if (pos >= from && pos <= to) {
2860
- if (nodeType && nodeType === node.type) {
2927
+ canUpdate = true;
2928
+ if (dispatch) {
2861
2929
  tr.setNodeMarkup(pos, void 0, {
2862
2930
  ...node.attrs,
2863
2931
  ...attributes
2864
2932
  });
2865
2933
  }
2866
- if (markType && node.marks.length) {
2867
- node.marks.forEach((mark) => {
2868
- if (markType === mark.type) {
2934
+ }
2935
+ if (markType && node.marks.length) {
2936
+ node.marks.forEach((mark) => {
2937
+ if (markType === mark.type) {
2938
+ canUpdate = true;
2939
+ if (dispatch) {
2869
2940
  const trimmedFrom2 = Math.max(pos, from);
2870
2941
  const trimmedTo2 = Math.min(pos + node.nodeSize, to);
2871
2942
  tr.addMark(
@@ -2877,36 +2948,36 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
2877
2948
  })
2878
2949
  );
2879
2950
  }
2880
- });
2881
- }
2951
+ }
2952
+ });
2882
2953
  }
2954
+ }
2955
+ });
2956
+ }
2957
+ if (lastNode) {
2958
+ if (lastPos !== void 0 && dispatch) {
2959
+ tr.setNodeMarkup(lastPos, void 0, {
2960
+ ...lastNode.attrs,
2961
+ ...attributes
2883
2962
  });
2884
2963
  }
2885
- if (lastNode) {
2886
- if (lastPos !== void 0) {
2887
- tr.setNodeMarkup(lastPos, void 0, {
2888
- ...lastNode.attrs,
2889
- ...attributes
2890
- });
2891
- }
2892
- if (markType && lastNode.marks.length) {
2893
- lastNode.marks.forEach((mark) => {
2894
- if (markType === mark.type) {
2895
- tr.addMark(
2896
- trimmedFrom,
2897
- trimmedTo,
2898
- markType.create({
2899
- ...mark.attrs,
2900
- ...attributes
2901
- })
2902
- );
2903
- }
2904
- });
2905
- }
2964
+ if (markType && lastNode.marks.length) {
2965
+ lastNode.marks.forEach((mark) => {
2966
+ if (markType === mark.type && dispatch) {
2967
+ tr.addMark(
2968
+ trimmedFrom,
2969
+ trimmedTo,
2970
+ markType.create({
2971
+ ...mark.attrs,
2972
+ ...attributes
2973
+ })
2974
+ );
2975
+ }
2976
+ });
2906
2977
  }
2907
- });
2908
- }
2909
- return true;
2978
+ }
2979
+ });
2980
+ return canUpdate;
2910
2981
  };
2911
2982
 
2912
2983
  // src/commands/wrapIn.ts
@@ -2924,7 +2995,7 @@ var wrapInList = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
2924
2995
  };
2925
2996
 
2926
2997
  // src/Editor.ts
2927
- var import_state21 = require("@tiptap/pm/state");
2998
+ var import_state22 = require("@tiptap/pm/state");
2928
2999
  var import_view = require("@tiptap/pm/view");
2929
3000
 
2930
3001
  // src/EventEmitter.ts
@@ -3783,6 +3854,7 @@ __export(extensions_exports, {
3783
3854
  Keymap: () => Keymap,
3784
3855
  Paste: () => Paste,
3785
3856
  Tabindex: () => Tabindex,
3857
+ TextDirection: () => TextDirection,
3786
3858
  focusEventsPluginKey: () => focusEventsPluginKey
3787
3859
  });
3788
3860
 
@@ -4152,6 +4224,66 @@ var Tabindex = Extension.create({
4152
4224
  }
4153
4225
  });
4154
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
+
4155
4287
  // src/NodePos.ts
4156
4288
  var NodePos = class _NodePos {
4157
4289
  constructor(pos, editor, isBlock = false, node = null) {
@@ -4443,6 +4575,7 @@ var Editor = class extends EventEmitter {
4443
4575
  extensions: [],
4444
4576
  autofocus: false,
4445
4577
  editable: true,
4578
+ textDirection: void 0,
4446
4579
  editorProps: {},
4447
4580
  parseOptions: {},
4448
4581
  coreExtensionOptions: {},
@@ -4491,7 +4624,7 @@ var Editor = class extends EventEmitter {
4491
4624
  this.on("delete", this.options.onDelete);
4492
4625
  const initialDoc = this.createDoc();
4493
4626
  const selection = resolveFocusPosition(initialDoc, this.options.autofocus);
4494
- this.editorState = import_state21.EditorState.create({
4627
+ this.editorState = import_state22.EditorState.create({
4495
4628
  doc: initialDoc,
4496
4629
  schema: this.schema,
4497
4630
  selection: selection || void 0
@@ -4720,7 +4853,10 @@ var Editor = class extends EventEmitter {
4720
4853
  Tabindex,
4721
4854
  Drop,
4722
4855
  Paste,
4723
- Delete
4856
+ Delete,
4857
+ TextDirection.configure({
4858
+ direction: this.options.textDirection
4859
+ })
4724
4860
  ].filter((ext) => {
4725
4861
  if (typeof this.options.enableCoreExtensions === "object") {
4726
4862
  return this.options.enableCoreExtensions[ext.name] !== false;
@@ -5674,11 +5810,11 @@ var ResizableNodeView = class {
5674
5810
  var ResizableNodeview = ResizableNodeView;
5675
5811
 
5676
5812
  // src/utilities/canInsertNode.ts
5677
- var import_state22 = require("@tiptap/pm/state");
5813
+ var import_state23 = require("@tiptap/pm/state");
5678
5814
  function canInsertNode(state, nodeType) {
5679
5815
  const { selection } = state;
5680
5816
  const { $from } = selection;
5681
- if (selection instanceof import_state22.NodeSelection) {
5817
+ if (selection instanceof import_state23.NodeSelection) {
5682
5818
  const index = $from.index();
5683
5819
  const parent = $from.parent;
5684
5820
  return parent.canReplaceWith(index, index + 1, nodeType);
@@ -6102,6 +6238,8 @@ function parseIndentedBlocks(src, config, lexer) {
6102
6238
  break;
6103
6239
  } else if (currentLine.trim() === "") {
6104
6240
  i += 1;
6241
+ totalRaw = `${totalRaw}${currentLine}
6242
+ `;
6105
6243
  continue;
6106
6244
  } else {
6107
6245
  return void 0;
@@ -6162,7 +6300,7 @@ function parseIndentedBlocks(src, config, lexer) {
6162
6300
  }
6163
6301
  return {
6164
6302
  items,
6165
- raw: totalRaw.trim()
6303
+ raw: totalRaw
6166
6304
  };
6167
6305
  }
6168
6306
 
@@ -6295,7 +6433,7 @@ var Node3 = class _Node extends Extendable {
6295
6433
  };
6296
6434
 
6297
6435
  // src/NodeView.ts
6298
- var import_state23 = require("@tiptap/pm/state");
6436
+ var import_state24 = require("@tiptap/pm/state");
6299
6437
  var NodeView = class {
6300
6438
  constructor(component, props, options) {
6301
6439
  this.isDragging = false;
@@ -6375,7 +6513,7 @@ var NodeView = class {
6375
6513
  if (typeof pos !== "number") {
6376
6514
  return;
6377
6515
  }
6378
- const selection = import_state23.NodeSelection.create(view.state.doc, pos);
6516
+ const selection = import_state24.NodeSelection.create(view.state.doc, pos);
6379
6517
  const transaction = view.state.tr.setSelection(selection);
6380
6518
  view.dispatch(transaction);
6381
6519
  }
@@ -6401,7 +6539,7 @@ var NodeView = class {
6401
6539
  const { isEditable } = this.editor;
6402
6540
  const { isDragging } = this;
6403
6541
  const isDraggable = !!this.node.type.spec.draggable;
6404
- const isSelectable = import_state23.NodeSelection.isSelectable(this.node);
6542
+ const isSelectable = import_state24.NodeSelection.isSelectable(this.node);
6405
6543
  const isCopyEvent = event.type === "copy";
6406
6544
  const isPasteEvent = event.type === "paste";
6407
6545
  const isCutEvent = event.type === "cut";