@lvce-editor/virtual-dom 4.1.0 → 5.0.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.
Files changed (2) hide show
  1. package/dist/index.js +43 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -648,7 +648,7 @@ const acquire = id => {
648
648
  return promise;
649
649
  };
650
650
  const getFileHandles = async ids => {
651
- const promises = ids.map(id => acquire(id));
651
+ const promises = ids.map(acquire);
652
652
  const handles = await Promise.all(promises);
653
653
  return handles;
654
654
  };
@@ -691,7 +691,7 @@ const applyDragInfoMaybe = event => {
691
691
  }
692
692
  } else {
693
693
  for (const item of dragInfo.items) {
694
- dataTransfer.items.add(item.data, item.data);
694
+ dataTransfer.items.add(item.data, item.type);
695
695
  }
696
696
  if (dragInfo.label) {
697
697
  setDragImage(dataTransfer, dragInfo.label);
@@ -714,9 +714,49 @@ const enabled = () => {
714
714
  return ignore;
715
715
  };
716
716
 
717
+ const unwrapItemString = async item => {
718
+ const {
719
+ resolve,
720
+ promise
721
+ } = Promise.withResolvers();
722
+ item.getAsString(resolve);
723
+ const value = await promise;
724
+ return {
725
+ kind: 'string',
726
+ type: item.type,
727
+ value
728
+ };
729
+ };
730
+ const unwrapItemFile = async item => {
731
+ // @ts-ignore
732
+ const file = await item.getAsFileSystemHandle();
733
+ return {
734
+ kind: 'file',
735
+ type: item.type,
736
+ value: file
737
+ };
738
+ };
739
+ const unknownItem = {
740
+ kind: 'unknown',
741
+ type: '',
742
+ value: ''
743
+ };
744
+ const unwrapItem = item => {
745
+ switch (item.kind) {
746
+ case 'file':
747
+ return unwrapItemFile(item);
748
+ case 'string':
749
+ return unwrapItemString(item);
750
+ default:
751
+ return unknownItem;
752
+ }
753
+ };
717
754
  const handleDataTransferFiles = event => {
755
+ if (!event.dataTransfer) {
756
+ return [];
757
+ }
718
758
  const items = [...event.dataTransfer.items];
719
- const promises = items.map(item => item.getAsFileSystemHandle());
759
+ const promises = items.map(unwrapItem);
720
760
  const ids = promises.map(promise => add(promise));
721
761
  return ids;
722
762
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "4.1.0",
3
+ "version": "5.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/virtual-dom.git"