source: imaps-frontend/node_modules/react-use/lib/useDropArea.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useMountedState_1 = tslib_1.__importDefault(require("./useMountedState"));
6var util_1 = require("./misc/util");
7/*
8const defaultState: DropAreaState = {
9 over: false,
10};
11*/
12var createProcess = function (options, mounted) { return function (dataTransfer, event) {
13 var uri = dataTransfer.getData('text/uri-list');
14 if (uri) {
15 (options.onUri || util_1.noop)(uri, event);
16 return;
17 }
18 if (dataTransfer.files && dataTransfer.files.length) {
19 (options.onFiles || util_1.noop)(Array.from(dataTransfer.files), event);
20 return;
21 }
22 if (dataTransfer.items && dataTransfer.items.length) {
23 dataTransfer.items[0].getAsString(function (text) {
24 if (mounted) {
25 (options.onText || util_1.noop)(text, event);
26 }
27 });
28 }
29}; };
30var createBond = function (process, setOver) { return ({
31 onDragOver: function (event) {
32 event.preventDefault();
33 },
34 onDragEnter: function (event) {
35 event.preventDefault();
36 setOver(true);
37 },
38 onDragLeave: function () {
39 setOver(false);
40 },
41 onDrop: function (event) {
42 event.preventDefault();
43 event.persist();
44 setOver(false);
45 process(event.dataTransfer, event);
46 },
47 onPaste: function (event) {
48 event.persist();
49 process(event.clipboardData, event);
50 },
51}); };
52var useDropArea = function (options) {
53 if (options === void 0) { options = {}; }
54 var onFiles = options.onFiles, onText = options.onText, onUri = options.onUri;
55 var isMounted = useMountedState_1.default();
56 var _a = react_1.useState(false), over = _a[0], setOver = _a[1];
57 var process = react_1.useMemo(function () { return createProcess(options, isMounted()); }, [onFiles, onText, onUri]);
58 var bond = react_1.useMemo(function () { return createBond(process, setOver); }, [process, setOver]);
59 return [bond, { over: over }];
60};
61exports.default = useDropArea;
Note: See TracBrowser for help on using the repository browser.