@tiptap/core 3.10.7 → 3.10.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.d.cts CHANGED
@@ -1297,17 +1297,71 @@ interface EditorOptions {
1297
1297
  */
1298
1298
  type HTMLContent = string;
1299
1299
  /**
1300
- * Loosely describes a JSON representation of a Prosemirror document or node
1300
+ * A Tiptap JSON node or document. Tiptap JSON is the standard format for
1301
+ * storing and manipulating Tiptap content. It is equivalent to the JSON
1302
+ * representation of a Prosemirror node.
1303
+ *
1304
+ * Tiptap JSON documents are trees of nodes. The root node is usually of type
1305
+ * `doc`. Nodes can have other nodes as children. Nodes can also have marks and
1306
+ * attributes. Text nodes (nodes with type `text`) have a `text` property and no
1307
+ * children.
1308
+ *
1309
+ * @example
1310
+ * ```ts
1311
+ * const content: JSONContent = {
1312
+ * type: 'doc',
1313
+ * content: [
1314
+ * {
1315
+ * type: 'paragraph',
1316
+ * content: [
1317
+ * {
1318
+ * type: 'text',
1319
+ * text: 'Hello ',
1320
+ * },
1321
+ * {
1322
+ * type: 'text',
1323
+ * text: 'world',
1324
+ * marks: [{ type: 'bold' }],
1325
+ * },
1326
+ * ],
1327
+ * },
1328
+ * ],
1329
+ * }
1330
+ * ```
1301
1331
  */
1302
1332
  type JSONContent = {
1333
+ /**
1334
+ * The type of the node
1335
+ */
1303
1336
  type?: string;
1337
+ /**
1338
+ * The attributes of the node. Attributes can have any JSON-serializable value.
1339
+ */
1304
1340
  attrs?: Record<string, any> | undefined;
1341
+ /**
1342
+ * The children of the node. A node can have other nodes as children.
1343
+ */
1305
1344
  content?: JSONContent[];
1345
+ /**
1346
+ * A list of marks of the node. Inline nodes can have marks.
1347
+ */
1306
1348
  marks?: {
1349
+ /**
1350
+ * The type of the mark
1351
+ */
1307
1352
  type: string;
1353
+ /**
1354
+ * The attributes of the mark. Attributes can have any JSON-serializable value.
1355
+ */
1308
1356
  attrs?: Record<string, any>;
1309
1357
  [key: string]: any;
1310
1358
  }[];
1359
+ /**
1360
+ * The text content of the node. This property is only present on text nodes
1361
+ * (i.e. nodes with `type: 'text'`).
1362
+ *
1363
+ * Text nodes cannot have children, but they can have marks.
1364
+ */
1311
1365
  text?: string;
1312
1366
  [key: string]: any;
1313
1367
  };
package/dist/index.d.ts CHANGED
@@ -1297,17 +1297,71 @@ interface EditorOptions {
1297
1297
  */
1298
1298
  type HTMLContent = string;
1299
1299
  /**
1300
- * Loosely describes a JSON representation of a Prosemirror document or node
1300
+ * A Tiptap JSON node or document. Tiptap JSON is the standard format for
1301
+ * storing and manipulating Tiptap content. It is equivalent to the JSON
1302
+ * representation of a Prosemirror node.
1303
+ *
1304
+ * Tiptap JSON documents are trees of nodes. The root node is usually of type
1305
+ * `doc`. Nodes can have other nodes as children. Nodes can also have marks and
1306
+ * attributes. Text nodes (nodes with type `text`) have a `text` property and no
1307
+ * children.
1308
+ *
1309
+ * @example
1310
+ * ```ts
1311
+ * const content: JSONContent = {
1312
+ * type: 'doc',
1313
+ * content: [
1314
+ * {
1315
+ * type: 'paragraph',
1316
+ * content: [
1317
+ * {
1318
+ * type: 'text',
1319
+ * text: 'Hello ',
1320
+ * },
1321
+ * {
1322
+ * type: 'text',
1323
+ * text: 'world',
1324
+ * marks: [{ type: 'bold' }],
1325
+ * },
1326
+ * ],
1327
+ * },
1328
+ * ],
1329
+ * }
1330
+ * ```
1301
1331
  */
1302
1332
  type JSONContent = {
1333
+ /**
1334
+ * The type of the node
1335
+ */
1303
1336
  type?: string;
1337
+ /**
1338
+ * The attributes of the node. Attributes can have any JSON-serializable value.
1339
+ */
1304
1340
  attrs?: Record<string, any> | undefined;
1341
+ /**
1342
+ * The children of the node. A node can have other nodes as children.
1343
+ */
1305
1344
  content?: JSONContent[];
1345
+ /**
1346
+ * A list of marks of the node. Inline nodes can have marks.
1347
+ */
1306
1348
  marks?: {
1349
+ /**
1350
+ * The type of the mark
1351
+ */
1307
1352
  type: string;
1353
+ /**
1354
+ * The attributes of the mark. Attributes can have any JSON-serializable value.
1355
+ */
1308
1356
  attrs?: Record<string, any>;
1309
1357
  [key: string]: any;
1310
1358
  }[];
1359
+ /**
1360
+ * The text content of the node. This property is only present on text nodes
1361
+ * (i.e. nodes with `type: 'text'`).
1362
+ *
1363
+ * Text nodes cannot have children, but they can have marks.
1364
+ */
1311
1365
  text?: string;
1312
1366
  [key: string]: any;
1313
1367
  };
package/dist/index.js CHANGED
@@ -1044,23 +1044,28 @@ var resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
1044
1044
  if (schemaType === "mark") {
1045
1045
  markType = getMarkType(typeOrName, state.schema);
1046
1046
  }
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) {
1047
+ let canReset = false;
1048
+ tr.selection.ranges.forEach((range) => {
1049
+ state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
1050
+ if (nodeType && nodeType === node.type) {
1051
+ canReset = true;
1052
+ if (dispatch) {
1051
1053
  tr.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes));
1052
1054
  }
1053
- if (markType && node.marks.length) {
1054
- node.marks.forEach((mark) => {
1055
- if (markType === mark.type) {
1055
+ }
1056
+ if (markType && node.marks.length) {
1057
+ node.marks.forEach((mark) => {
1058
+ if (markType === mark.type) {
1059
+ canReset = true;
1060
+ if (dispatch) {
1056
1061
  tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)));
1057
1062
  }
1058
- });
1059
- }
1060
- });
1063
+ }
1064
+ });
1065
+ }
1061
1066
  });
1062
- }
1063
- return true;
1067
+ });
1068
+ return canReset;
1064
1069
  };
1065
1070
 
1066
1071
  // src/commands/scrollIntoView.ts
@@ -1500,12 +1505,12 @@ function cleanUpSchemaItem(data) {
1500
1505
  );
1501
1506
  }
1502
1507
  function buildAttributeSpec(extensionAttribute) {
1503
- var _a, _b, _c;
1508
+ var _a, _b;
1504
1509
  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) {
1510
+ if (!((_a = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a.isRequired) && "default" in ((extensionAttribute == null ? void 0 : extensionAttribute.attribute) || {})) {
1506
1511
  spec.default = extensionAttribute.attribute.default;
1507
1512
  }
1508
- if (((_c = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _c.validate) !== void 0) {
1513
+ if (((_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate) !== void 0) {
1509
1514
  spec.validate = extensionAttribute.attribute.validate;
1510
1515
  }
1511
1516
  return [extensionAttribute.name, spec];
@@ -2703,41 +2708,48 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
2703
2708
  if (schemaType === "mark") {
2704
2709
  markType = getMarkType(typeOrName, state.schema);
2705
2710
  }
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) => {
2711
+ let canUpdate = false;
2712
+ tr.selection.ranges.forEach((range) => {
2713
+ const from = range.$from.pos;
2714
+ const to = range.$to.pos;
2715
+ let lastPos;
2716
+ let lastNode;
2717
+ let trimmedFrom;
2718
+ let trimmedTo;
2719
+ if (tr.selection.empty) {
2720
+ state.doc.nodesBetween(from, to, (node, pos) => {
2721
+ if (nodeType && nodeType === node.type) {
2722
+ canUpdate = true;
2723
+ trimmedFrom = Math.max(pos, from);
2724
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2725
+ lastPos = pos;
2726
+ lastNode = node;
2727
+ }
2728
+ });
2729
+ } else {
2730
+ state.doc.nodesBetween(from, to, (node, pos) => {
2731
+ if (pos < from && nodeType && nodeType === node.type) {
2732
+ canUpdate = true;
2733
+ trimmedFrom = Math.max(pos, from);
2734
+ trimmedTo = Math.min(pos + node.nodeSize, to);
2735
+ lastPos = pos;
2736
+ lastNode = node;
2737
+ }
2738
+ if (pos >= from && pos <= to) {
2716
2739
  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) {
2740
+ canUpdate = true;
2741
+ if (dispatch) {
2733
2742
  tr.setNodeMarkup(pos, void 0, {
2734
2743
  ...node.attrs,
2735
2744
  ...attributes
2736
2745
  });
2737
2746
  }
2738
- if (markType && node.marks.length) {
2739
- node.marks.forEach((mark) => {
2740
- if (markType === mark.type) {
2747
+ }
2748
+ if (markType && node.marks.length) {
2749
+ node.marks.forEach((mark) => {
2750
+ if (markType === mark.type) {
2751
+ canUpdate = true;
2752
+ if (dispatch) {
2741
2753
  const trimmedFrom2 = Math.max(pos, from);
2742
2754
  const trimmedTo2 = Math.min(pos + node.nodeSize, to);
2743
2755
  tr.addMark(
@@ -2749,36 +2761,36 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
2749
2761
  })
2750
2762
  );
2751
2763
  }
2752
- });
2753
- }
2764
+ }
2765
+ });
2754
2766
  }
2767
+ }
2768
+ });
2769
+ }
2770
+ if (lastNode) {
2771
+ if (lastPos !== void 0 && dispatch) {
2772
+ tr.setNodeMarkup(lastPos, void 0, {
2773
+ ...lastNode.attrs,
2774
+ ...attributes
2755
2775
  });
2756
2776
  }
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
- }
2777
+ if (markType && lastNode.marks.length) {
2778
+ lastNode.marks.forEach((mark) => {
2779
+ if (markType === mark.type && dispatch) {
2780
+ tr.addMark(
2781
+ trimmedFrom,
2782
+ trimmedTo,
2783
+ markType.create({
2784
+ ...mark.attrs,
2785
+ ...attributes
2786
+ })
2787
+ );
2788
+ }
2789
+ });
2778
2790
  }
2779
- });
2780
- }
2781
- return true;
2791
+ }
2792
+ });
2793
+ return canUpdate;
2782
2794
  };
2783
2795
 
2784
2796
  // src/commands/wrapIn.ts
@@ -5974,6 +5986,8 @@ function parseIndentedBlocks(src, config, lexer) {
5974
5986
  break;
5975
5987
  } else if (currentLine.trim() === "") {
5976
5988
  i += 1;
5989
+ totalRaw = `${totalRaw}${currentLine}
5990
+ `;
5977
5991
  continue;
5978
5992
  } else {
5979
5993
  return void 0;
@@ -6034,7 +6048,7 @@ function parseIndentedBlocks(src, config, lexer) {
6034
6048
  }
6035
6049
  return {
6036
6050
  items,
6037
- raw: totalRaw.trim()
6051
+ raw: totalRaw
6038
6052
  };
6039
6053
  }
6040
6054