@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.js CHANGED
@@ -1571,7 +1571,7 @@ function createNodeFromContent(content, schema, options) {
1571
1571
  };
1572
1572
  if (typeof content === 'object' && content !== null) {
1573
1573
  try {
1574
- if (Array.isArray(content)) {
1574
+ if (Array.isArray(content) && content.length > 0) {
1575
1575
  return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)));
1576
1576
  }
1577
1577
  return schema.nodeFromJSON(content);
@@ -1656,7 +1656,17 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
1656
1656
  // if there is only plain text we have to use `insertText`
1657
1657
  // because this will keep the current marks
1658
1658
  if (isOnlyTextContent) {
1659
- tr.insertText(value, from, to);
1659
+ // if value is string, we can use it directly
1660
+ // otherwise if it is an array, we have to join it
1661
+ if (Array.isArray(value)) {
1662
+ tr.insertText(value.map(v => v.text || '').join(''), from, to);
1663
+ }
1664
+ else if (typeof value === 'object' && !!value && !!value.text) {
1665
+ tr.insertText(value.text, from, to);
1666
+ }
1667
+ else {
1668
+ tr.insertText(value, from, to);
1669
+ }
1660
1670
  }
1661
1671
  else {
1662
1672
  tr.replaceWith(from, to, content);
@@ -2246,6 +2256,20 @@ function getMarksBetween(from, to, doc) {
2246
2256
  return marks;
2247
2257
  }
2248
2258
 
2259
+ function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2260
+ return Object.fromEntries(Object
2261
+ .entries(attributes)
2262
+ .filter(([name]) => {
2263
+ const extensionAttribute = extensionAttributes.find(item => {
2264
+ return item.type === typeName && item.name === name;
2265
+ });
2266
+ if (!extensionAttribute) {
2267
+ return false;
2268
+ }
2269
+ return extensionAttribute.attribute.keepOnSplit;
2270
+ }));
2271
+ }
2272
+
2249
2273
  function isMarkActive(state, typeOrName, attributes = {}) {
2250
2274
  const { empty, ranges } = state.selection;
2251
2275
  const type = typeOrName ? getMarkType(typeOrName, state.schema) : null;
@@ -2515,20 +2539,6 @@ const sinkListItem = typeOrName => ({ state, dispatch }) => {
2515
2539
  return sinkListItem$1(type)(state, dispatch);
2516
2540
  };
2517
2541
 
2518
- function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2519
- return Object.fromEntries(Object
2520
- .entries(attributes)
2521
- .filter(([name]) => {
2522
- const extensionAttribute = extensionAttributes.find(item => {
2523
- return item.type === typeName && item.name === name;
2524
- });
2525
- if (!extensionAttribute) {
2526
- return false;
2527
- }
2528
- return extensionAttribute.attribute.keepOnSplit;
2529
- }));
2530
- }
2531
-
2532
2542
  function ensureMarks(state, splittableMarks) {
2533
2543
  const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
2534
2544
  if (marks) {
@@ -2675,7 +2685,15 @@ const splitListItem = typeOrName => ({ tr, state, dispatch, editor, }) => {
2675
2685
  return false;
2676
2686
  }
2677
2687
  if (dispatch) {
2688
+ const { selection, storedMarks } = state;
2689
+ const { splittableMarks } = editor.extensionManager;
2690
+ const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks());
2678
2691
  tr.split($from.pos, 2, types).scrollIntoView();
2692
+ if (!marks || !dispatch) {
2693
+ return true;
2694
+ }
2695
+ const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name));
2696
+ tr.ensureMarks(filteredMarks);
2679
2697
  }
2680
2698
  return true;
2681
2699
  };
@@ -2714,13 +2732,14 @@ const joinListForwards = (tr, listType) => {
2714
2732
  tr.join(after);
2715
2733
  return true;
2716
2734
  };
2717
- const toggleList = (listTypeOrName, itemTypeOrName) => ({ editor, tr, state, dispatch, chain, commands, can, }) => {
2718
- const { extensions } = editor.extensionManager;
2735
+ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks) => ({ editor, tr, state, dispatch, chain, commands, can, }) => {
2736
+ const { extensions, splittableMarks } = editor.extensionManager;
2719
2737
  const listType = getNodeType(listTypeOrName, state.schema);
2720
2738
  const itemType = getNodeType(itemTypeOrName, state.schema);
2721
- const { selection } = state;
2739
+ const { selection, storedMarks } = state;
2722
2740
  const { $from, $to } = selection;
2723
2741
  const range = $from.blockRange($to);
2742
+ const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks());
2724
2743
  if (!range) {
2725
2744
  return false;
2726
2745
  }
@@ -2744,10 +2763,27 @@ const toggleList = (listTypeOrName, itemTypeOrName) => ({ editor, tr, state, dis
2744
2763
  .run();
2745
2764
  }
2746
2765
  }
2766
+ if (!keepMarks || !marks || !dispatch) {
2767
+ return chain()
2768
+ // try to convert node to default node if needed
2769
+ .command(() => {
2770
+ const canWrapInList = can().wrapInList(listType);
2771
+ if (canWrapInList) {
2772
+ return true;
2773
+ }
2774
+ return commands.clearNodes();
2775
+ })
2776
+ .wrapInList(listType)
2777
+ .command(() => joinListBackwards(tr, listType))
2778
+ .command(() => joinListForwards(tr, listType))
2779
+ .run();
2780
+ }
2747
2781
  return (chain()
2748
2782
  // try to convert node to default node if needed
2749
2783
  .command(() => {
2750
2784
  const canWrapInList = can().wrapInList(listType);
2785
+ const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name));
2786
+ tr.ensureMarks(filteredMarks);
2751
2787
  if (canWrapInList) {
2752
2788
  return true;
2753
2789
  }
@@ -3545,8 +3581,8 @@ class Editor extends EventEmitter {
3545
3581
  return getText(this.state.doc, {
3546
3582
  blockSeparator,
3547
3583
  textSerializers: {
3548
- ...textSerializers,
3549
3584
  ...getTextSerializersFromSchema(this.schema),
3585
+ ...textSerializers,
3550
3586
  },
3551
3587
  });
3552
3588
  }
@@ -3728,7 +3764,7 @@ function textInputRule(config) {
3728
3764
  function wrappingInputRule(config) {
3729
3765
  return new InputRule({
3730
3766
  find: config.find,
3731
- handler: ({ state, range, match }) => {
3767
+ handler: ({ state, range, match, chain, }) => {
3732
3768
  const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
3733
3769
  const tr = state.tr.delete(range.from, range.to);
3734
3770
  const $start = tr.doc.resolve(range.from);
@@ -3738,6 +3774,20 @@ function wrappingInputRule(config) {
3738
3774
  return null;
3739
3775
  }
3740
3776
  tr.wrap(blockRange, wrapping);
3777
+ if (config.keepMarks && config.editor) {
3778
+ const { selection, storedMarks } = state;
3779
+ const { splittableMarks } = config.editor.extensionManager;
3780
+ const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks());
3781
+ if (marks) {
3782
+ const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name));
3783
+ tr.ensureMarks(filteredMarks);
3784
+ }
3785
+ }
3786
+ if (config.keepAttributes) {
3787
+ /** If the nodeType is `bulletList` or `orderedList` set the `nodeType` as `listItem` */
3788
+ const nodeType = config.type.name === 'bulletList' || config.type.name === 'orderedList' ? 'listItem' : 'taskList';
3789
+ chain().updateAttributes(nodeType, attributes).run();
3790
+ }
3741
3791
  const before = tr.doc.resolve(range.from - 1).nodeBefore;
3742
3792
  if (before
3743
3793
  && before.type === config.type
@@ -4205,5 +4255,5 @@ class Tracker {
4205
4255
  }
4206
4256
  }
4207
4257
 
4208
- export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, inputRulesPlugin, isActive, isEmptyObject, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
4258
+ export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveFocusPosition, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
4209
4259
  //# sourceMappingURL=index.js.map