@portabletext/editor 3.2.5 → 3.3.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/lib/index.js CHANGED
@@ -19,10 +19,10 @@ import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, ra
19
19
  import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
20
20
  import { htmlToBlocks } from "@portabletext/block-tools";
21
21
  import { toHTML } from "@portabletext/to-html";
22
+ import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
22
23
  import { Schema } from "@sanity/schema";
23
24
  import flatten from "lodash/flatten.js";
24
25
  import { set, applyAll, unset, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
25
- import { createDraft, finishDraft } from "immer";
26
26
  import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
27
27
  import isPlainObject from "lodash/isPlainObject.js";
28
28
  import { EditorContext } from "./_chunks-es/use-editor.js";
@@ -2734,6 +2734,57 @@ function createConverterTextHtml(legacySchema) {
2734
2734
  }
2735
2735
  };
2736
2736
  }
2737
+ const converterTextMarkdown = {
2738
+ mimeType: "text/markdown",
2739
+ serialize: ({
2740
+ snapshot,
2741
+ event
2742
+ }) => {
2743
+ if (!snapshot.context.selection)
2744
+ return {
2745
+ type: "serialization.failure",
2746
+ mimeType: "text/markdown",
2747
+ reason: "No selection",
2748
+ originEvent: event.originEvent
2749
+ };
2750
+ const blocks = getSelectedValue(snapshot);
2751
+ return {
2752
+ type: "serialization.success",
2753
+ data: portableTextToMarkdown(blocks),
2754
+ mimeType: "text/markdown",
2755
+ originEvent: event.originEvent
2756
+ };
2757
+ },
2758
+ deserialize: ({
2759
+ snapshot,
2760
+ event
2761
+ }) => {
2762
+ const parsedBlocks = markdownToPortableText(event.data, {
2763
+ keyGenerator: snapshot.context.keyGenerator,
2764
+ schema: snapshot.context.schema
2765
+ }).flatMap((block) => {
2766
+ const parsedBlock = parseBlock({
2767
+ context: snapshot.context,
2768
+ block,
2769
+ options: {
2770
+ normalize: !1,
2771
+ removeUnusedMarkDefs: !0,
2772
+ validateFields: !1
2773
+ }
2774
+ });
2775
+ return parsedBlock ? [parsedBlock] : [];
2776
+ });
2777
+ return parsedBlocks.length === 0 ? {
2778
+ type: "deserialization.failure",
2779
+ mimeType: "text/markdown",
2780
+ reason: "No blocks deserialized"
2781
+ } : {
2782
+ type: "deserialization.success",
2783
+ data: parsedBlocks,
2784
+ mimeType: "text/markdown"
2785
+ };
2786
+ }
2787
+ };
2737
2788
  function createConverterTextPlain(legacySchema) {
2738
2789
  return {
2739
2790
  mimeType: "text/plain",
@@ -2797,7 +2848,7 @@ function escapeHtml(str) {
2797
2848
  return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
2798
2849
  }
2799
2850
  function createCoreConverters(legacySchema) {
2800
- return [converterJson, converterPortableText, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
2851
+ return [converterJson, converterPortableText, converterTextMarkdown, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
2801
2852
  }
2802
2853
  function compileType(rawType) {
2803
2854
  return Schema.compile({
@@ -6509,17 +6560,16 @@ function getParent(context, root, path) {
6509
6560
  return block;
6510
6561
  }
6511
6562
  function applyOperationToPortableText(context, value, operation) {
6512
- const draft = createDraft({
6563
+ const root = {
6513
6564
  children: value
6514
- });
6565
+ };
6515
6566
  try {
6516
- applyOperationToPortableTextDraft(context, draft, operation);
6567
+ return applyOperationToPortableTextImmutable(context, root, operation).children;
6517
6568
  } catch (e) {
6518
- console.error(e);
6569
+ return console.error(e), value;
6519
6570
  }
6520
- return finishDraft(draft).children;
6521
6571
  }
6522
- function applyOperationToPortableTextDraft(context, root, operation) {
6572
+ function applyOperationToPortableTextImmutable(context, root, operation) {
6523
6573
  switch (operation.type) {
6524
6574
  case "insert_node": {
6525
6575
  const {
@@ -6527,45 +6577,55 @@ function applyOperationToPortableTextDraft(context, root, operation) {
6527
6577
  node: insertedNode
6528
6578
  } = operation, parent = getParent(context, root, path), index = path[path.length - 1];
6529
6579
  if (!parent || index > parent.children.length)
6530
- break;
6580
+ return root;
6531
6581
  if (path.length === 1) {
6532
6582
  if (isTextBlockNode(context, insertedNode)) {
6533
- parent.children.splice(index, 0, {
6583
+ const newBlock = {
6534
6584
  ...insertedNode,
6535
6585
  children: insertedNode.children.map((child) => "__inline" in child ? {
6536
6586
  _key: child._key,
6537
6587
  _type: child._type,
6538
6588
  ..."value" in child && typeof child.value == "object" ? child.value : {}
6539
6589
  } : child)
6540
- });
6541
- break;
6590
+ };
6591
+ return {
6592
+ ...root,
6593
+ children: insertChildren(root.children, index, newBlock)
6594
+ };
6542
6595
  }
6543
6596
  if (Element$1.isElement(insertedNode) && !("__inline" in insertedNode)) {
6544
- parent.children.splice(index, 0, {
6597
+ const newBlock = {
6545
6598
  _key: insertedNode._key,
6546
6599
  _type: insertedNode._type,
6547
6600
  ..."value" in insertedNode && typeof insertedNode.value == "object" ? insertedNode.value : {}
6548
- });
6549
- break;
6601
+ };
6602
+ return {
6603
+ ...root,
6604
+ children: insertChildren(root.children, index, newBlock)
6605
+ };
6550
6606
  }
6551
6607
  }
6552
6608
  if (path.length === 2) {
6609
+ const blockIndex = path[0];
6553
6610
  if (!isTextBlockNode(context, parent))
6554
- break;
6555
- if (isPartialSpanNode(insertedNode)) {
6556
- parent.children.splice(index, 0, insertedNode);
6557
- break;
6558
- }
6559
- if ("__inline" in insertedNode) {
6560
- parent.children.splice(index, 0, {
6611
+ return root;
6612
+ let newChild;
6613
+ if (isPartialSpanNode(insertedNode))
6614
+ newChild = insertedNode;
6615
+ else if ("__inline" in insertedNode)
6616
+ newChild = {
6561
6617
  _key: insertedNode._key,
6562
6618
  _type: insertedNode._type,
6563
6619
  ..."value" in insertedNode && typeof insertedNode.value == "object" ? insertedNode.value : {}
6564
- });
6565
- break;
6566
- }
6620
+ };
6621
+ else
6622
+ return root;
6623
+ return updateTextBlockAtIndex(context, root, blockIndex, (block) => ({
6624
+ ...block,
6625
+ children: insertChildren(block.children, index, newChild)
6626
+ }));
6567
6627
  }
6568
- break;
6628
+ return root;
6569
6629
  }
6570
6630
  case "insert_text": {
6571
6631
  const {
@@ -6573,29 +6633,50 @@ function applyOperationToPortableTextDraft(context, root, operation) {
6573
6633
  offset,
6574
6634
  text
6575
6635
  } = operation;
6576
- if (text.length === 0) break;
6636
+ if (text.length === 0) return root;
6577
6637
  const span = getSpan(context, root, path);
6578
6638
  if (!span)
6579
- break;
6580
- const before = span.text.slice(0, offset), after = span.text.slice(offset);
6581
- span.text = before + text + after;
6582
- break;
6639
+ return root;
6640
+ const blockIndex = path[0], childIndex = path[1], before = span.text.slice(0, offset), after = span.text.slice(offset), newSpan = {
6641
+ ...span,
6642
+ text: before + text + after
6643
+ };
6644
+ return updateTextBlockAtIndex(context, root, blockIndex, (block) => ({
6645
+ ...block,
6646
+ children: replaceChild(block.children, childIndex, newSpan)
6647
+ }));
6583
6648
  }
6584
6649
  case "merge_node": {
6585
6650
  const {
6586
6651
  path
6587
6652
  } = operation, node = getNode(context, root, path), prevPath = Path.previous(path), prev = getNode(context, root, prevPath), parent = getParent(context, root, path);
6588
6653
  if (!node || !prev || !parent)
6589
- break;
6654
+ return root;
6590
6655
  const index = path[path.length - 1];
6591
- if (isPartialSpanNode(node) && isPartialSpanNode(prev))
6592
- prev.text += node.text;
6593
- else if (isTextBlockNode(context, node) && isTextBlockNode(context, prev))
6594
- prev.children.push(...node.children);
6595
- else
6596
- break;
6597
- parent.children.splice(index, 1);
6598
- break;
6656
+ if (isPartialSpanNode(node) && isPartialSpanNode(prev)) {
6657
+ const blockIndex = path[0], newPrev = {
6658
+ ...prev,
6659
+ text: prev.text + node.text
6660
+ };
6661
+ return updateTextBlockAtIndex(context, root, blockIndex, (block) => {
6662
+ const newChildren = replaceChild(block.children, index - 1, newPrev);
6663
+ return {
6664
+ ...block,
6665
+ children: removeChildren(newChildren, index)
6666
+ };
6667
+ });
6668
+ }
6669
+ if (isTextBlockNode(context, node) && isTextBlockNode(context, prev)) {
6670
+ const newPrev = {
6671
+ ...prev,
6672
+ children: [...prev.children, ...node.children]
6673
+ }, newChildren = replaceChild(root.children, index - 1, newPrev);
6674
+ return {
6675
+ ...root,
6676
+ children: removeChildren(newChildren, index)
6677
+ };
6678
+ }
6679
+ return root;
6599
6680
  }
6600
6681
  case "move_node": {
6601
6682
  const {
@@ -6603,23 +6684,58 @@ function applyOperationToPortableTextDraft(context, root, operation) {
6603
6684
  newPath
6604
6685
  } = operation;
6605
6686
  if (Path.isAncestor(path, newPath))
6606
- break;
6687
+ return root;
6607
6688
  const node = getNode(context, root, path), parent = getParent(context, root, path), index = path[path.length - 1];
6608
6689
  if (!node || !parent)
6609
- break;
6610
- parent.children.splice(index, 1);
6611
- const truePath = Path.transform(path, operation), newParent = getNode(context, root, Path.parent(truePath)), newIndex = truePath[truePath.length - 1];
6612
- if (!newParent || !("children" in newParent) || !Array.isArray(newParent.children))
6613
- break;
6614
- newParent.children.splice(newIndex, 0, node);
6615
- break;
6690
+ return root;
6691
+ let newRoot;
6692
+ if (path.length === 1)
6693
+ newRoot = {
6694
+ ...root,
6695
+ children: removeChildren(root.children, index)
6696
+ };
6697
+ else if (path.length === 2) {
6698
+ const blockIndex = path[0];
6699
+ newRoot = updateTextBlockAtIndex(context, root, blockIndex, (block) => ({
6700
+ ...block,
6701
+ children: removeChildren(block.children, index)
6702
+ }));
6703
+ } else
6704
+ return root;
6705
+ const truePath = Path.transform(path, operation), newIndex = truePath[truePath.length - 1];
6706
+ if (truePath.length === 1)
6707
+ return {
6708
+ ...newRoot,
6709
+ children: insertChildren(newRoot.children, newIndex, node)
6710
+ };
6711
+ if (truePath.length === 2) {
6712
+ const newBlockIndex = truePath[0], newParent = newRoot.children[newBlockIndex];
6713
+ return !newParent || !isTextBlockNode(context, newParent) ? root : updateTextBlockAtIndex(context, newRoot, newBlockIndex, (block) => ({
6714
+ ...block,
6715
+ children: insertChildren(block.children, newIndex, node)
6716
+ }));
6717
+ }
6718
+ return root;
6616
6719
  }
6617
6720
  case "remove_node": {
6618
6721
  const {
6619
6722
  path
6620
6723
  } = operation, index = path[path.length - 1];
6621
- getParent(context, root, path)?.children.splice(index, 1);
6622
- break;
6724
+ if (!getParent(context, root, path))
6725
+ return root;
6726
+ if (path.length === 1)
6727
+ return {
6728
+ ...root,
6729
+ children: removeChildren(root.children, index)
6730
+ };
6731
+ if (path.length === 2) {
6732
+ const blockIndex = path[0];
6733
+ return updateTextBlockAtIndex(context, root, blockIndex, (block) => ({
6734
+ ...block,
6735
+ children: removeChildren(block.children, index)
6736
+ }));
6737
+ }
6738
+ return root;
6623
6739
  }
6624
6740
  case "remove_text": {
6625
6741
  const {
@@ -6628,13 +6744,18 @@ function applyOperationToPortableTextDraft(context, root, operation) {
6628
6744
  text
6629
6745
  } = operation;
6630
6746
  if (text.length === 0)
6631
- break;
6747
+ return root;
6632
6748
  const span = getSpan(context, root, path);
6633
6749
  if (!span)
6634
- break;
6635
- const before = span.text.slice(0, offset), after = span.text.slice(offset + text.length);
6636
- span.text = before + after;
6637
- break;
6750
+ return root;
6751
+ const blockIndex = path[0], childIndex = path[1], before = span.text.slice(0, offset), after = span.text.slice(offset + text.length), newSpan = {
6752
+ ...span,
6753
+ text: before + after
6754
+ };
6755
+ return updateTextBlockAtIndex(context, root, blockIndex, (block) => ({
6756
+ ...block,
6757
+ children: replaceChild(block.children, childIndex, newSpan)
6758
+ }));
6638
6759
  }
6639
6760
  case "set_node": {
6640
6761
  const {
@@ -6643,48 +6764,68 @@ function applyOperationToPortableTextDraft(context, root, operation) {
6643
6764
  newProperties
6644
6765
  } = operation, node = getNode(context, root, path);
6645
6766
  if (!node || isEditorNode(node))
6646
- break;
6767
+ return root;
6647
6768
  if (isObjectNode(context, node)) {
6648
- const valueBefore = "value" in properties && typeof properties.value == "object" ? properties.value : {}, valueAfter = "value" in newProperties && typeof newProperties.value == "object" ? newProperties.value : {};
6769
+ const valueBefore = "value" in properties && typeof properties.value == "object" ? properties.value : {}, valueAfter = "value" in newProperties && typeof newProperties.value == "object" ? newProperties.value : {}, newNode = {
6770
+ ...node
6771
+ };
6649
6772
  for (const key in newProperties) {
6650
6773
  if (key === "value")
6651
6774
  continue;
6652
6775
  const value = newProperties[key];
6653
- value == null ? delete node[key] : node[key] = value;
6776
+ value == null ? delete newNode[key] : newNode[key] = value;
6654
6777
  }
6655
6778
  for (const key in properties)
6656
- key !== "value" && (newProperties.hasOwnProperty(key) || delete node[key]);
6779
+ key !== "value" && (newProperties.hasOwnProperty(key) || delete newNode[key]);
6657
6780
  for (const key in valueAfter) {
6658
6781
  const value = valueAfter[key];
6659
- value == null ? delete node[key] : node[key] = value;
6782
+ value == null ? delete newNode[key] : newNode[key] = value;
6660
6783
  }
6661
6784
  for (const key in valueBefore)
6662
- valueAfter.hasOwnProperty(key) || delete node[key];
6663
- break;
6785
+ valueAfter.hasOwnProperty(key) || delete newNode[key];
6786
+ return path.length === 1 ? {
6787
+ ...root,
6788
+ children: replaceChild(root.children, path[0], newNode)
6789
+ } : path.length === 2 ? updateTextBlockAtIndex(context, root, path[0], (block) => ({
6790
+ ...block,
6791
+ children: replaceChild(block.children, path[1], newNode)
6792
+ })) : root;
6664
6793
  }
6665
6794
  if (isTextBlockNode(context, node)) {
6795
+ const newNode = {
6796
+ ...node
6797
+ };
6666
6798
  for (const key in newProperties) {
6667
6799
  if (key === "children" || key === "text")
6668
- break;
6800
+ continue;
6669
6801
  const value = newProperties[key];
6670
- value == null ? delete node[key] : node[key] = value;
6802
+ value == null ? delete newNode[key] : newNode[key] = value;
6671
6803
  }
6672
6804
  for (const key in properties)
6673
- newProperties.hasOwnProperty(key) || delete node[key];
6674
- break;
6805
+ newProperties.hasOwnProperty(key) || delete newNode[key];
6806
+ return {
6807
+ ...root,
6808
+ children: replaceChild(root.children, path[0], newNode)
6809
+ };
6675
6810
  }
6676
6811
  if (isPartialSpanNode(node)) {
6812
+ const newNode = {
6813
+ ...node
6814
+ };
6677
6815
  for (const key in newProperties) {
6678
6816
  if (key === "text")
6679
- break;
6817
+ continue;
6680
6818
  const value = newProperties[key];
6681
- value == null ? delete node[key] : node[key] = value;
6819
+ value == null ? delete newNode[key] : newNode[key] = value;
6682
6820
  }
6683
6821
  for (const key in properties)
6684
- newProperties.hasOwnProperty(key) || delete node[key];
6685
- break;
6822
+ newProperties.hasOwnProperty(key) || delete newNode[key];
6823
+ return updateTextBlockAtIndex(context, root, path[0], (block) => ({
6824
+ ...block,
6825
+ children: replaceChild(block.children, path[1], newNode)
6826
+ }));
6686
6827
  }
6687
- break;
6828
+ return root;
6688
6829
  }
6689
6830
  case "split_node": {
6690
6831
  const {
@@ -6693,40 +6834,65 @@ function applyOperationToPortableTextDraft(context, root, operation) {
6693
6834
  properties
6694
6835
  } = operation;
6695
6836
  if (path.length === 0)
6696
- break;
6837
+ return root;
6697
6838
  const parent = getParent(context, root, path), index = path[path.length - 1];
6698
6839
  if (!parent)
6699
- break;
6840
+ return root;
6700
6841
  if (isEditorNode(parent)) {
6701
6842
  const block = getBlock(root, path);
6702
6843
  if (!block || !isTextBlockNode(context, block))
6703
- break;
6704
- const before = block.children.slice(0, position), after = block.children.slice(position);
6705
- block.children = before;
6706
- const newTextBlockNode = {
6844
+ return root;
6845
+ const before = block.children.slice(0, position), after = block.children.slice(position), updatedTextBlockNode = {
6846
+ ...block,
6847
+ children: before
6848
+ }, newTextBlockNode = {
6707
6849
  ...properties,
6708
6850
  children: after,
6709
6851
  _type: context.schema.block.name
6710
6852
  };
6711
- parent.children.splice(index + 1, 0, newTextBlockNode);
6712
- break;
6853
+ return {
6854
+ ...root,
6855
+ children: insertChildren(replaceChild(root.children, index, updatedTextBlockNode), index + 1, newTextBlockNode)
6856
+ };
6713
6857
  }
6714
6858
  if (isTextBlockNode(context, parent)) {
6715
6859
  const node = getNode(context, root, path);
6716
6860
  if (!node || !isSpanNode(context, node))
6717
- break;
6718
- const before = node.text.slice(0, position), after = node.text.slice(position);
6719
- node.text = before;
6720
- const newSpanNode = {
6861
+ return root;
6862
+ const blockIndex = path[0], before = node.text.slice(0, position), after = node.text.slice(position), updatedSpanNode = {
6863
+ ...node,
6864
+ text: before
6865
+ }, newSpanNode = {
6721
6866
  ...properties,
6722
6867
  text: after
6723
6868
  };
6724
- parent.children.splice(index + 1, 0, newSpanNode);
6869
+ return updateTextBlockAtIndex(context, root, blockIndex, (block) => ({
6870
+ ...block,
6871
+ children: insertChildren(replaceChild(block.children, index, updatedSpanNode), index + 1, newSpanNode)
6872
+ }));
6725
6873
  }
6726
- break;
6874
+ return root;
6727
6875
  }
6728
6876
  }
6729
- return root;
6877
+ }
6878
+ function insertChildren(children, index, ...nodes) {
6879
+ return [...children.slice(0, index), ...nodes, ...children.slice(index)];
6880
+ }
6881
+ function removeChildren(children, index, count = 1) {
6882
+ return [...children.slice(0, index), ...children.slice(index + count)];
6883
+ }
6884
+ function replaceChild(children, index, newChild) {
6885
+ return [...children.slice(0, index), newChild, ...children.slice(index + 1)];
6886
+ }
6887
+ function updateTextBlockAtIndex(context, root, blockIndex, updater) {
6888
+ const block = root.children.at(blockIndex);
6889
+ if (!block || !isTextBlockNode(context, block))
6890
+ return root;
6891
+ const newBlock = updater(block);
6892
+ return {
6893
+ ...root,
6894
+ children: replaceChild(root.children, blockIndex, newBlock)
6895
+ };
6730
6896
  }
6731
6897
  function pluginUpdateValue(context, editor) {
6732
6898
  const {
@@ -8492,41 +8658,37 @@ const abstractAnnotationBehaviors = [defineBehavior({
8492
8658
  ...event,
8493
8659
  type: "delete"
8494
8660
  })]]
8495
- })], abstractDeserializeBehaviors = [
8661
+ })], mimeTypePriority = ["application/x-portable-text", "application/json", "text/markdown", "text/html", "text/plain"];
8662
+ function getFirstAvailableData({
8663
+ dataTransfer,
8664
+ startAfter
8665
+ }) {
8666
+ const startIndex = startAfter ? mimeTypePriority.indexOf(startAfter) + 1 : 0;
8667
+ for (let index = startIndex; index < mimeTypePriority.length; index++) {
8668
+ const mimeType = mimeTypePriority.at(index);
8669
+ if (!mimeType)
8670
+ continue;
8671
+ const data = dataTransfer.getData(mimeType);
8672
+ if (data)
8673
+ return {
8674
+ mimeType,
8675
+ data
8676
+ };
8677
+ }
8678
+ }
8679
+ const abstractDeserializeBehaviors = [
8496
8680
  defineBehavior({
8497
8681
  on: "deserialize",
8498
8682
  guard: ({
8499
8683
  event
8500
8684
  }) => {
8501
- const portableText = event.originEvent.originEvent.dataTransfer.getData("application/x-portable-text");
8502
- if (portableText)
8503
- return {
8504
- type: "deserialize.data",
8505
- mimeType: "application/x-portable-text",
8506
- data: portableText,
8507
- originEvent: event.originEvent
8508
- };
8509
- const json = event.originEvent.originEvent.dataTransfer.getData("application/json");
8510
- if (json)
8511
- return {
8512
- type: "deserialize.data",
8513
- mimeType: "application/json",
8514
- data: json,
8515
- originEvent: event.originEvent
8516
- };
8517
- const html = event.originEvent.originEvent.dataTransfer.getData("text/html");
8518
- if (html)
8519
- return {
8520
- type: "deserialize.data",
8521
- mimeType: "text/html",
8522
- data: html,
8523
- originEvent: event.originEvent
8524
- };
8525
- const text = event.originEvent.originEvent.dataTransfer.getData("text/plain");
8526
- return text ? {
8685
+ const availableData = getFirstAvailableData({
8686
+ dataTransfer: event.originEvent.originEvent.dataTransfer
8687
+ });
8688
+ return availableData ? {
8527
8689
  type: "deserialize.data",
8528
- mimeType: "text/plain",
8529
- data: text,
8690
+ mimeType: availableData.mimeType,
8691
+ data: availableData.data,
8530
8692
  originEvent: event.originEvent
8531
8693
  } : !1;
8532
8694
  },
@@ -8633,37 +8795,18 @@ const abstractAnnotationBehaviors = [defineBehavior({
8633
8795
  guard: ({
8634
8796
  event
8635
8797
  }) => {
8636
- if (event.mimeType === "application/x-portable-text") {
8637
- const json = event.originEvent.originEvent.dataTransfer.getData("application/json");
8638
- if (json)
8639
- return {
8640
- type: "deserialize.data",
8641
- mimeType: "application/json",
8642
- data: json,
8643
- originEvent: event.originEvent
8644
- };
8645
- }
8646
- if (event.mimeType === "application/json") {
8647
- const html = event.originEvent.originEvent.dataTransfer.getData("text/html");
8648
- if (html)
8649
- return {
8650
- type: "deserialize.data",
8651
- mimeType: "text/html",
8652
- data: html,
8653
- originEvent: event.originEvent
8654
- };
8655
- }
8656
- if (event.mimeType === "text/html") {
8657
- const text = event.originEvent.originEvent.dataTransfer.getData("text/plain");
8658
- if (text)
8659
- return {
8660
- type: "deserialize.data",
8661
- mimeType: "text/plain",
8662
- data: text,
8663
- originEvent: event.originEvent
8664
- };
8665
- }
8666
- return !1;
8798
+ if (event.mimeType === "*/*")
8799
+ return !1;
8800
+ const availableData = getFirstAvailableData({
8801
+ dataTransfer: event.originEvent.originEvent.dataTransfer,
8802
+ startAfter: event.mimeType
8803
+ });
8804
+ return availableData ? {
8805
+ type: "deserialize.data",
8806
+ mimeType: availableData.mimeType,
8807
+ data: availableData.data,
8808
+ originEvent: event.originEvent
8809
+ } : !1;
8667
8810
  },
8668
8811
  actions: [(_, deserializeDataEvent) => [raise(deserializeDataEvent)]]
8669
8812
  }),