@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.js CHANGED
@@ -189,6 +189,7 @@ __export(commands_exports, {
189
189
  setMeta: () => setMeta,
190
190
  setNode: () => setNode,
191
191
  setNodeSelection: () => setNodeSelection,
192
+ setTextDirection: () => setTextDirection,
192
193
  setTextSelection: () => setTextSelection,
193
194
  sinkListItem: () => sinkListItem,
194
195
  splitBlock: () => splitBlock,
@@ -200,6 +201,7 @@ __export(commands_exports, {
200
201
  undoInputRule: () => undoInputRule,
201
202
  unsetAllMarks: () => unsetAllMarks,
202
203
  unsetMark: () => unsetMark,
204
+ unsetTextDirection: () => unsetTextDirection,
203
205
  updateAttributes: () => updateAttributes,
204
206
  wrapIn: () => wrapIn,
205
207
  wrapInList: () => wrapInList
@@ -1044,23 +1046,28 @@ var resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
1044
1046
  if (schemaType === "mark") {
1045
1047
  markType = getMarkType(typeOrName, state.schema);
1046
1048
  }
1047
- if (dispatch) {
1048
- tr.selection.ranges.forEach((range) => {
1049
- state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
1050
- if (nodeType && nodeType === node.type) {
1049
+ let canReset = false;
1050
+ tr.selection.ranges.forEach((range) => {
1051
+ state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
1052
+ if (nodeType && nodeType === node.type) {
1053
+ canReset = true;
1054
+ if (dispatch) {
1051
1055
  tr.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes));
1052
1056
  }
1053
- if (markType && node.marks.length) {
1054
- node.marks.forEach((mark) => {
1055
- if (markType === mark.type) {
1057
+ }
1058
+ if (markType && node.marks.length) {
1059
+ node.marks.forEach((mark) => {
1060
+ if (markType === mark.type) {
1061
+ canReset = true;
1062
+ if (dispatch) {
1056
1063
  tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)));
1057
1064
  }
1058
- });
1059
- }
1060
- });
1065
+ }
1066
+ });
1067
+ }
1061
1068
  });
1062
- }
1063
- return true;
1069
+ });
1070
+ return canReset;
1064
1071
  };
1065
1072
 
1066
1073
  // src/commands/scrollIntoView.ts
@@ -1500,12 +1507,12 @@ function cleanUpSchemaItem(data) {
1500
1507
  );
1501
1508
  }
1502
1509
  function buildAttributeSpec(extensionAttribute) {
1503
- var _a, _b, _c;
1510
+ var _a, _b;
1504
1511
  const spec = {};
1505
- 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) {
1512
+ if (!((_a = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a.isRequired) && "default" in ((extensionAttribute == null ? void 0 : extensionAttribute.attribute) || {})) {
1506
1513
  spec.default = extensionAttribute.attribute.default;
1507
1514
  }
1508
- if (((_c = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _c.validate) !== void 0) {
1515
+ if (((_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate) !== void 0) {
1509
1516
  spec.validate = extensionAttribute.attribute.validate;
1510
1517
  }
1511
1518
  return [extensionAttribute.name, spec];
@@ -2323,6 +2330,35 @@ var setNodeSelection = (position) => ({ tr, dispatch }) => {
2323
2330
  return true;
2324
2331
  };
2325
2332
 
2333
+ // src/commands/setTextDirection.ts
2334
+ var setTextDirection = (direction, position) => ({ tr, state, dispatch }) => {
2335
+ const { selection } = state;
2336
+ let from;
2337
+ let to;
2338
+ if (typeof position === "number") {
2339
+ from = position;
2340
+ to = position;
2341
+ } else if (position && "from" in position && "to" in position) {
2342
+ from = position.from;
2343
+ to = position.to;
2344
+ } else {
2345
+ from = selection.from;
2346
+ to = selection.to;
2347
+ }
2348
+ if (dispatch) {
2349
+ tr.doc.nodesBetween(from, to, (node, pos) => {
2350
+ if (node.isText) {
2351
+ return;
2352
+ }
2353
+ tr.setNodeMarkup(pos, void 0, {
2354
+ ...node.attrs,
2355
+ dir: direction
2356
+ });
2357
+ });
2358
+ }
2359
+ return true;
2360
+ };
2361
+
2326
2362
  // src/commands/setTextSelection.ts
2327
2363
  import { TextSelection as TextSelection5 } from "@tiptap/pm/state";
2328
2364
  var setTextSelection = (position) => ({ tr, dispatch }) => {
@@ -2686,6 +2722,34 @@ var unsetMark = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
2686
2722
  return true;
2687
2723
  };
2688
2724
 
2725
+ // src/commands/unsetTextDirection.ts
2726
+ var unsetTextDirection = (position) => ({ tr, state, dispatch }) => {
2727
+ const { selection } = state;
2728
+ let from;
2729
+ let to;
2730
+ if (typeof position === "number") {
2731
+ from = position;
2732
+ to = position;
2733
+ } else if (position && "from" in position && "to" in position) {
2734
+ from = position.from;
2735
+ to = position.to;
2736
+ } else {
2737
+ from = selection.from;
2738
+ to = selection.to;
2739
+ }
2740
+ if (dispatch) {
2741
+ tr.doc.nodesBetween(from, to, (node, pos) => {
2742
+ if (node.isText) {
2743
+ return;
2744
+ }
2745
+ const newAttrs = { ...node.attrs };
2746
+ delete newAttrs.dir;
2747
+ tr.setNodeMarkup(pos, void 0, newAttrs);
2748
+ });
2749
+ }
2750
+ return true;
2751
+ };
2752
+
2689
2753
  // src/commands/updateAttributes.ts
2690
2754
  var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
2691
2755
  let nodeType = null;
@@ -2703,41 +2767,48 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
2703
2767
  if (schemaType === "mark") {
2704
2768
  markType = getMarkType(typeOrName, state.schema);
2705
2769
  }
2706
- if (dispatch) {
2707
- tr.selection.ranges.forEach((range) => {
2708
- const from = range.$from.pos;
2709
- const to = range.$to.pos;
2710
- let lastPos;
2711
- let lastNode;
2712
- let trimmedFrom;
2713
- let trimmedTo;
2714
- if (tr.selection.empty) {
2715
- state.doc.nodesBetween(from, to, (node, pos) => {
2770
+ let canUpdate = false;
2771
+ tr.selection.ranges.forEach((range) => {
2772
+ const from = range.$from.pos;
2773
+ const to = range.$to.pos;
2774
+ let lastPos;
2775
+ let lastNode;
2776
+ let trimmedFrom;
2777
+ let trimmedTo;
2778
+ if (tr.selection.empty) {
2779
+ state.doc.nodesBetween(from, to, (node, pos) => {
2780
+ if (nodeType && nodeType === node.type) {
2781
+ canUpdate = true;
2782
+ trimmedFrom = Math.max(pos, from);
2783
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2784
+ lastPos = pos;
2785
+ lastNode = node;
2786
+ }
2787
+ });
2788
+ } else {
2789
+ state.doc.nodesBetween(from, to, (node, pos) => {
2790
+ if (pos < from && nodeType && nodeType === node.type) {
2791
+ canUpdate = true;
2792
+ trimmedFrom = Math.max(pos, from);
2793
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2794
+ lastPos = pos;
2795
+ lastNode = node;
2796
+ }
2797
+ if (pos >= from && pos <= to) {
2716
2798
  if (nodeType && nodeType === node.type) {
2717
- trimmedFrom = Math.max(pos, from);
2718
- trimmedTo = Math.min(pos + node.nodeSize, to);
2719
- lastPos = pos;
2720
- lastNode = node;
2721
- }
2722
- });
2723
- } else {
2724
- state.doc.nodesBetween(from, to, (node, pos) => {
2725
- if (pos < from && nodeType && nodeType === node.type) {
2726
- trimmedFrom = Math.max(pos, from);
2727
- trimmedTo = Math.min(pos + node.nodeSize, to);
2728
- lastPos = pos;
2729
- lastNode = node;
2730
- }
2731
- if (pos >= from && pos <= to) {
2732
- if (nodeType && nodeType === node.type) {
2799
+ canUpdate = true;
2800
+ if (dispatch) {
2733
2801
  tr.setNodeMarkup(pos, void 0, {
2734
2802
  ...node.attrs,
2735
2803
  ...attributes
2736
2804
  });
2737
2805
  }
2738
- if (markType && node.marks.length) {
2739
- node.marks.forEach((mark) => {
2740
- if (markType === mark.type) {
2806
+ }
2807
+ if (markType && node.marks.length) {
2808
+ node.marks.forEach((mark) => {
2809
+ if (markType === mark.type) {
2810
+ canUpdate = true;
2811
+ if (dispatch) {
2741
2812
  const trimmedFrom2 = Math.max(pos, from);
2742
2813
  const trimmedTo2 = Math.min(pos + node.nodeSize, to);
2743
2814
  tr.addMark(
@@ -2749,36 +2820,36 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
2749
2820
  })
2750
2821
  );
2751
2822
  }
2752
- });
2753
- }
2823
+ }
2824
+ });
2754
2825
  }
2826
+ }
2827
+ });
2828
+ }
2829
+ if (lastNode) {
2830
+ if (lastPos !== void 0 && dispatch) {
2831
+ tr.setNodeMarkup(lastPos, void 0, {
2832
+ ...lastNode.attrs,
2833
+ ...attributes
2755
2834
  });
2756
2835
  }
2757
- if (lastNode) {
2758
- if (lastPos !== void 0) {
2759
- tr.setNodeMarkup(lastPos, void 0, {
2760
- ...lastNode.attrs,
2761
- ...attributes
2762
- });
2763
- }
2764
- if (markType && lastNode.marks.length) {
2765
- lastNode.marks.forEach((mark) => {
2766
- if (markType === mark.type) {
2767
- tr.addMark(
2768
- trimmedFrom,
2769
- trimmedTo,
2770
- markType.create({
2771
- ...mark.attrs,
2772
- ...attributes
2773
- })
2774
- );
2775
- }
2776
- });
2777
- }
2836
+ if (markType && lastNode.marks.length) {
2837
+ lastNode.marks.forEach((mark) => {
2838
+ if (markType === mark.type && dispatch) {
2839
+ tr.addMark(
2840
+ trimmedFrom,
2841
+ trimmedTo,
2842
+ markType.create({
2843
+ ...mark.attrs,
2844
+ ...attributes
2845
+ })
2846
+ );
2847
+ }
2848
+ });
2778
2849
  }
2779
- });
2780
- }
2781
- return true;
2850
+ }
2851
+ });
2852
+ return canUpdate;
2782
2853
  };
2783
2854
 
2784
2855
  // src/commands/wrapIn.ts
@@ -3655,6 +3726,7 @@ __export(extensions_exports, {
3655
3726
  Keymap: () => Keymap,
3656
3727
  Paste: () => Paste,
3657
3728
  Tabindex: () => Tabindex,
3729
+ TextDirection: () => TextDirection,
3658
3730
  focusEventsPluginKey: () => focusEventsPluginKey
3659
3731
  });
3660
3732
 
@@ -4024,6 +4096,66 @@ var Tabindex = Extension.create({
4024
4096
  }
4025
4097
  });
4026
4098
 
4099
+ // src/extensions/textDirection.ts
4100
+ import { Plugin as Plugin10, PluginKey as PluginKey8 } from "@tiptap/pm/state";
4101
+ var TextDirection = Extension.create({
4102
+ name: "textDirection",
4103
+ addOptions() {
4104
+ return {
4105
+ direction: void 0
4106
+ };
4107
+ },
4108
+ addGlobalAttributes() {
4109
+ if (!this.options.direction) {
4110
+ return [];
4111
+ }
4112
+ const { nodeExtensions } = splitExtensions(this.extensions);
4113
+ return [
4114
+ {
4115
+ types: nodeExtensions.filter((extension) => extension.name !== "text").map((extension) => extension.name),
4116
+ attributes: {
4117
+ dir: {
4118
+ default: this.options.direction,
4119
+ parseHTML: (element) => {
4120
+ const dir = element.getAttribute("dir");
4121
+ if (dir && (dir === "ltr" || dir === "rtl" || dir === "auto")) {
4122
+ return dir;
4123
+ }
4124
+ return this.options.direction;
4125
+ },
4126
+ renderHTML: (attributes) => {
4127
+ if (!attributes.dir) {
4128
+ return {};
4129
+ }
4130
+ return {
4131
+ dir: attributes.dir
4132
+ };
4133
+ }
4134
+ }
4135
+ }
4136
+ }
4137
+ ];
4138
+ },
4139
+ addProseMirrorPlugins() {
4140
+ return [
4141
+ new Plugin10({
4142
+ key: new PluginKey8("textDirection"),
4143
+ props: {
4144
+ attributes: () => {
4145
+ const direction = this.options.direction;
4146
+ if (!direction) {
4147
+ return {};
4148
+ }
4149
+ return {
4150
+ dir: direction
4151
+ };
4152
+ }
4153
+ }
4154
+ })
4155
+ ];
4156
+ }
4157
+ });
4158
+
4027
4159
  // src/NodePos.ts
4028
4160
  var NodePos = class _NodePos {
4029
4161
  constructor(pos, editor, isBlock = false, node = null) {
@@ -4315,6 +4447,7 @@ var Editor = class extends EventEmitter {
4315
4447
  extensions: [],
4316
4448
  autofocus: false,
4317
4449
  editable: true,
4450
+ textDirection: void 0,
4318
4451
  editorProps: {},
4319
4452
  parseOptions: {},
4320
4453
  coreExtensionOptions: {},
@@ -4592,7 +4725,10 @@ var Editor = class extends EventEmitter {
4592
4725
  Tabindex,
4593
4726
  Drop,
4594
4727
  Paste,
4595
- Delete
4728
+ Delete,
4729
+ TextDirection.configure({
4730
+ direction: this.options.textDirection
4731
+ })
4596
4732
  ].filter((ext) => {
4597
4733
  if (typeof this.options.enableCoreExtensions === "object") {
4598
4734
  return this.options.enableCoreExtensions[ext.name] !== false;
@@ -5974,6 +6110,8 @@ function parseIndentedBlocks(src, config, lexer) {
5974
6110
  break;
5975
6111
  } else if (currentLine.trim() === "") {
5976
6112
  i += 1;
6113
+ totalRaw = `${totalRaw}${currentLine}
6114
+ `;
5977
6115
  continue;
5978
6116
  } else {
5979
6117
  return void 0;
@@ -6034,7 +6172,7 @@ function parseIndentedBlocks(src, config, lexer) {
6034
6172
  }
6035
6173
  return {
6036
6174
  items,
6037
- raw: totalRaw.trim()
6175
+ raw: totalRaw
6038
6176
  };
6039
6177
  }
6040
6178