@tiptap/core 2.0.0-beta.218 → 2.0.0-beta.219

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.umd.js CHANGED
@@ -1569,7 +1569,7 @@
1569
1569
  };
1570
1570
  if (typeof content === 'object' && content !== null) {
1571
1571
  try {
1572
- if (Array.isArray(content)) {
1572
+ if (Array.isArray(content) && content.length > 0) {
1573
1573
  return model.Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)));
1574
1574
  }
1575
1575
  return schema.nodeFromJSON(content);
@@ -1654,7 +1654,17 @@
1654
1654
  // if there is only plain text we have to use `insertText`
1655
1655
  // because this will keep the current marks
1656
1656
  if (isOnlyTextContent) {
1657
- tr.insertText(value, from, to);
1657
+ // if value is string, we can use it directly
1658
+ // otherwise if it is an array, we have to join it
1659
+ if (Array.isArray(value)) {
1660
+ tr.insertText(value.map(v => v.text || '').join(''), from, to);
1661
+ }
1662
+ else if (typeof value === 'object' && !!value && !!value.text) {
1663
+ tr.insertText(value.text, from, to);
1664
+ }
1665
+ else {
1666
+ tr.insertText(value, from, to);
1667
+ }
1658
1668
  }
1659
1669
  else {
1660
1670
  tr.replaceWith(from, to, content);
@@ -2244,6 +2254,20 @@
2244
2254
  return marks;
2245
2255
  }
2246
2256
 
2257
+ function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2258
+ return Object.fromEntries(Object
2259
+ .entries(attributes)
2260
+ .filter(([name]) => {
2261
+ const extensionAttribute = extensionAttributes.find(item => {
2262
+ return item.type === typeName && item.name === name;
2263
+ });
2264
+ if (!extensionAttribute) {
2265
+ return false;
2266
+ }
2267
+ return extensionAttribute.attribute.keepOnSplit;
2268
+ }));
2269
+ }
2270
+
2247
2271
  function isMarkActive(state, typeOrName, attributes = {}) {
2248
2272
  const { empty, ranges } = state.selection;
2249
2273
  const type = typeOrName ? getMarkType(typeOrName, state.schema) : null;
@@ -2513,20 +2537,6 @@
2513
2537
  return schemaList.sinkListItem(type)(state, dispatch);
2514
2538
  };
2515
2539
 
2516
- function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2517
- return Object.fromEntries(Object
2518
- .entries(attributes)
2519
- .filter(([name]) => {
2520
- const extensionAttribute = extensionAttributes.find(item => {
2521
- return item.type === typeName && item.name === name;
2522
- });
2523
- if (!extensionAttribute) {
2524
- return false;
2525
- }
2526
- return extensionAttribute.attribute.keepOnSplit;
2527
- }));
2528
- }
2529
-
2530
2540
  function ensureMarks(state, splittableMarks) {
2531
2541
  const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
2532
2542
  if (marks) {
@@ -2673,7 +2683,15 @@
2673
2683
  return false;
2674
2684
  }
2675
2685
  if (dispatch) {
2686
+ const { selection, storedMarks } = state$1;
2687
+ const { splittableMarks } = editor.extensionManager;
2688
+ const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks());
2676
2689
  tr.split($from.pos, 2, types).scrollIntoView();
2690
+ if (!marks || !dispatch) {
2691
+ return true;
2692
+ }
2693
+ const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name));
2694
+ tr.ensureMarks(filteredMarks);
2677
2695
  }
2678
2696
  return true;
2679
2697
  };
@@ -2712,13 +2730,14 @@
2712
2730
  tr.join(after);
2713
2731
  return true;
2714
2732
  };
2715
- const toggleList = (listTypeOrName, itemTypeOrName) => ({ editor, tr, state, dispatch, chain, commands, can, }) => {
2716
- const { extensions } = editor.extensionManager;
2733
+ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks) => ({ editor, tr, state, dispatch, chain, commands, can, }) => {
2734
+ const { extensions, splittableMarks } = editor.extensionManager;
2717
2735
  const listType = getNodeType(listTypeOrName, state.schema);
2718
2736
  const itemType = getNodeType(itemTypeOrName, state.schema);
2719
- const { selection } = state;
2737
+ const { selection, storedMarks } = state;
2720
2738
  const { $from, $to } = selection;
2721
2739
  const range = $from.blockRange($to);
2740
+ const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks());
2722
2741
  if (!range) {
2723
2742
  return false;
2724
2743
  }
@@ -2742,10 +2761,27 @@
2742
2761
  .run();
2743
2762
  }
2744
2763
  }
2764
+ if (!keepMarks || !marks || !dispatch) {
2765
+ return chain()
2766
+ // try to convert node to default node if needed
2767
+ .command(() => {
2768
+ const canWrapInList = can().wrapInList(listType);
2769
+ if (canWrapInList) {
2770
+ return true;
2771
+ }
2772
+ return commands.clearNodes();
2773
+ })
2774
+ .wrapInList(listType)
2775
+ .command(() => joinListBackwards(tr, listType))
2776
+ .command(() => joinListForwards(tr, listType))
2777
+ .run();
2778
+ }
2745
2779
  return (chain()
2746
2780
  // try to convert node to default node if needed
2747
2781
  .command(() => {
2748
2782
  const canWrapInList = can().wrapInList(listType);
2783
+ const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name));
2784
+ tr.ensureMarks(filteredMarks);
2749
2785
  if (canWrapInList) {
2750
2786
  return true;
2751
2787
  }
@@ -3543,8 +3579,8 @@ img.ProseMirror-separator {
3543
3579
  return getText(this.state.doc, {
3544
3580
  blockSeparator,
3545
3581
  textSerializers: {
3546
- ...textSerializers,
3547
3582
  ...getTextSerializersFromSchema(this.schema),
3583
+ ...textSerializers,
3548
3584
  },
3549
3585
  });
3550
3586
  }
@@ -3726,7 +3762,7 @@ img.ProseMirror-separator {
3726
3762
  function wrappingInputRule(config) {
3727
3763
  return new InputRule({
3728
3764
  find: config.find,
3729
- handler: ({ state, range, match }) => {
3765
+ handler: ({ state, range, match, chain, }) => {
3730
3766
  const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
3731
3767
  const tr = state.tr.delete(range.from, range.to);
3732
3768
  const $start = tr.doc.resolve(range.from);
@@ -3736,6 +3772,20 @@ img.ProseMirror-separator {
3736
3772
  return null;
3737
3773
  }
3738
3774
  tr.wrap(blockRange, wrapping);
3775
+ if (config.keepMarks && config.editor) {
3776
+ const { selection, storedMarks } = state;
3777
+ const { splittableMarks } = config.editor.extensionManager;
3778
+ const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks());
3779
+ if (marks) {
3780
+ const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name));
3781
+ tr.ensureMarks(filteredMarks);
3782
+ }
3783
+ }
3784
+ if (config.keepAttributes) {
3785
+ /** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */
3786
+ const nodeType = config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList';
3787
+ chain().updateAttributes(nodeType, attributes).run();
3788
+ }
3739
3789
  const before = tr.doc.resolve(range.from - 1).nodeBefore;
3740
3790
  if (before
3741
3791
  && before.type === config.type
@@ -4214,6 +4264,9 @@ img.ProseMirror-separator {
4214
4264
  exports.Tracker = Tracker;
4215
4265
  exports.callOrReturn = callOrReturn;
4216
4266
  exports.combineTransactionSteps = combineTransactionSteps;
4267
+ exports.createChainableState = createChainableState;
4268
+ exports.createDocument = createDocument;
4269
+ exports.createNodeFromContent = createNodeFromContent;
4217
4270
  exports.createStyleTag = createStyleTag;
4218
4271
  exports.defaultBlockAt = defaultBlockAt;
4219
4272
  exports.deleteProps = deleteProps;
@@ -4230,6 +4283,7 @@ img.ProseMirror-separator {
4230
4283
  exports.generateJSON = generateJSON;
4231
4284
  exports.generateText = generateText;
4232
4285
  exports.getAttributes = getAttributes;
4286
+ exports.getAttributesFromExtensions = getAttributesFromExtensions;
4233
4287
  exports.getChangedRanges = getChangedRanges;
4234
4288
  exports.getDebugJSON = getDebugJSON;
4235
4289
  exports.getExtensionField = getExtensionField;
@@ -4240,14 +4294,21 @@ img.ProseMirror-separator {
4240
4294
  exports.getMarksBetween = getMarksBetween;
4241
4295
  exports.getNodeAttributes = getNodeAttributes;
4242
4296
  exports.getNodeType = getNodeType;
4297
+ exports.getRenderedAttributes = getRenderedAttributes;
4243
4298
  exports.getSchema = getSchema;
4299
+ exports.getSchemaByResolvedExtensions = getSchemaByResolvedExtensions;
4300
+ exports.getSchemaTypeByName = getSchemaTypeByName;
4301
+ exports.getSchemaTypeNameByName = getSchemaTypeNameByName;
4302
+ exports.getSplittedAttributes = getSplittedAttributes;
4244
4303
  exports.getText = getText;
4245
4304
  exports.getTextBetween = getTextBetween;
4246
4305
  exports.getTextContentFromNodes = getTextContentFromNodes;
4247
4306
  exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
4307
+ exports.injectExtensionAttributesToParseRule = injectExtensionAttributesToParseRule;
4248
4308
  exports.inputRulesPlugin = inputRulesPlugin;
4249
4309
  exports.isActive = isActive;
4250
4310
  exports.isEmptyObject = isEmptyObject;
4311
+ exports.isExtensionRulesEnabled = isExtensionRulesEnabled;
4251
4312
  exports.isFunction = isFunction;
4252
4313
  exports.isList = isList;
4253
4314
  exports.isMacOS = isMacOS;
@@ -4272,6 +4333,9 @@ img.ProseMirror-separator {
4272
4333
  exports.pasteRulesPlugin = pasteRulesPlugin;
4273
4334
  exports.posToDOMRect = posToDOMRect;
4274
4335
  exports.removeDuplicates = removeDuplicates;
4336
+ exports.resolveFocusPosition = resolveFocusPosition;
4337
+ exports.selectionToInsertionEnd = selectionToInsertionEnd;
4338
+ exports.splitExtensions = splitExtensions;
4275
4339
  exports.textInputRule = textInputRule;
4276
4340
  exports.textPasteRule = textPasteRule;
4277
4341
  exports.textblockTypeInputRule = textblockTypeInputRule;