@hypericon/mico 0.3.19 → 0.3.20
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/components/drag-handler/DragHandler.d.ts +40 -0
- package/dist/components/drag-handler/DragHandler.js +110 -0
- package/dist/components/drag-handler/index.d.ts +1 -0
- package/dist/components/drag-handler/index.js +17 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import m from "mithril";
|
|
2
|
+
export interface DragHandlerAttrs {
|
|
3
|
+
/** Enable dragging this element */
|
|
4
|
+
enableDrag?: boolean;
|
|
5
|
+
/** Enable dropping dragged elements on this element */
|
|
6
|
+
enableDrop?: boolean;
|
|
7
|
+
/** Optionally specify what sort of effect should be allowed using this drag */
|
|
8
|
+
dragEffect?: "link" | "copy" | "none" | "copyLink" | "copyMove" | "linkMove" | "move" | "all" | "uninitialized";
|
|
9
|
+
dragData?: string | (() => string);
|
|
10
|
+
onDragStart?: (args: {
|
|
11
|
+
ev: DragEvent;
|
|
12
|
+
dragData?: string;
|
|
13
|
+
}) => any;
|
|
14
|
+
onDragOver?: (args: {
|
|
15
|
+
ev: DragEvent;
|
|
16
|
+
dragData?: string;
|
|
17
|
+
}) => any;
|
|
18
|
+
onDrop?: (args: {
|
|
19
|
+
ev: DragEvent;
|
|
20
|
+
dragData?: string;
|
|
21
|
+
}) => any;
|
|
22
|
+
/** Enable debug logging for events */
|
|
23
|
+
enableLogging?: boolean;
|
|
24
|
+
/** CSS classes to apply to the wrapper div */
|
|
25
|
+
class?: string;
|
|
26
|
+
/** CSS styles to apply to the wrapper div */
|
|
27
|
+
style?: string;
|
|
28
|
+
/** CSS classes to apply to the div while it is being dragged (if dragging is enabled) */
|
|
29
|
+
classDragging?: string;
|
|
30
|
+
/** CSS styles to apply to the div while it is being dragged (if dragging is enabled) */
|
|
31
|
+
styleDragging?: string;
|
|
32
|
+
/** CSS classes to apply to the div while it is being dragged over (if dropping is enabled) */
|
|
33
|
+
classDraggingOver?: string;
|
|
34
|
+
/** CSS styles to apply to the div while it is being dragged over (if dropping is enabled) */
|
|
35
|
+
styleDraggingOver?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const DragHandler: m.Component<DragHandlerAttrs, {
|
|
38
|
+
isDragging: boolean;
|
|
39
|
+
isDraggingOver: boolean;
|
|
40
|
+
}>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DragHandler = void 0;
|
|
7
|
+
const mithril_1 = __importDefault(require("mithril"));
|
|
8
|
+
const DEFAULT_DATA_FORMAT = "application/mico-drag-handler";
|
|
9
|
+
exports.DragHandler = {
|
|
10
|
+
oninit() {
|
|
11
|
+
this.isDragging = false;
|
|
12
|
+
this.isDraggingOver = false;
|
|
13
|
+
},
|
|
14
|
+
view({ attrs, children }) {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f;
|
|
16
|
+
return (0, mithril_1.default)("", {
|
|
17
|
+
class: `${(_a = attrs.class) !== null && _a !== void 0 ? _a : ""} ${this.isDragging ? (_b = attrs.classDragging) !== null && _b !== void 0 ? _b : "" : ""} ${this.isDraggingOver ? (_c = attrs.classDraggingOver) !== null && _c !== void 0 ? _c : "" : ""}`,
|
|
18
|
+
style: `${(_d = attrs.style) !== null && _d !== void 0 ? _d : ""} ${this.isDragging ? (_e = attrs.classDragging) !== null && _e !== void 0 ? _e : "" : ""} ${this.isDraggingOver ? (_f = attrs.classDraggingOver) !== null && _f !== void 0 ? _f : "" : ""}`,
|
|
19
|
+
draggable: attrs.enableDrag,
|
|
20
|
+
ondragstart: (ev) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (!attrs.enableDrag)
|
|
23
|
+
return;
|
|
24
|
+
if (!ev.dataTransfer)
|
|
25
|
+
return;
|
|
26
|
+
let dragData;
|
|
27
|
+
if (attrs.dragData !== undefined) {
|
|
28
|
+
if (typeof attrs.dragData === "function") {
|
|
29
|
+
dragData = (_a = attrs.dragData) === null || _a === void 0 ? void 0 : _a.call(attrs);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
dragData = attrs.dragData;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (dragData !== undefined) {
|
|
36
|
+
ev.dataTransfer.setData(DEFAULT_DATA_FORMAT, dragData);
|
|
37
|
+
}
|
|
38
|
+
if (attrs.dragEffect) {
|
|
39
|
+
ev.dataTransfer.effectAllowed = attrs.dragEffect;
|
|
40
|
+
}
|
|
41
|
+
this.isDragging = true;
|
|
42
|
+
attrs.enableLogging && console.log(`start dragging, effect: ${ev.dataTransfer.effectAllowed}, data:`, dragData);
|
|
43
|
+
(_b = attrs.onDragStart) === null || _b === void 0 ? void 0 : _b.call(attrs, { ev, dragData });
|
|
44
|
+
},
|
|
45
|
+
ondrag: (ev) => {
|
|
46
|
+
// attrs.enableLogging && console.log(`on drag`, item.data);
|
|
47
|
+
},
|
|
48
|
+
// ondragenter: (ev: DragEvent) => {
|
|
49
|
+
// ev.preventDefault();
|
|
50
|
+
// if (!attrs.enableDrop) return false;
|
|
51
|
+
// if (attrs.enableLogging) {
|
|
52
|
+
// const dragData = ev.dataTransfer?.getData(DEFAULT_DATA_FORMAT);
|
|
53
|
+
// console.log(`drag enter, effect: ${attrs.dragEffect}, data:`, dragData);
|
|
54
|
+
// }
|
|
55
|
+
// this.isDraggingOver = true;
|
|
56
|
+
// },
|
|
57
|
+
ondragover: (ev) => {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
ev.preventDefault();
|
|
60
|
+
if (!attrs.enableDrop)
|
|
61
|
+
return false;
|
|
62
|
+
// const overDiv = ev.currentTarget as HTMLElement;
|
|
63
|
+
// const targetRect = overDiv.getBoundingClientRect();
|
|
64
|
+
// const topToMouse = ev.clientY - targetRect.top;
|
|
65
|
+
// const isAbove = topToMouse < (targetRect.height - topToMouse);
|
|
66
|
+
// this.isTargettingAbove = isAbove;
|
|
67
|
+
this.isDraggingOver = true;
|
|
68
|
+
const dragData = (_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData(DEFAULT_DATA_FORMAT);
|
|
69
|
+
attrs.enableLogging && console.log(`drag over, effect: ${(_b = ev.dataTransfer) === null || _b === void 0 ? void 0 : _b.effectAllowed}, data:`, dragData);
|
|
70
|
+
(_c = attrs.onDragOver) === null || _c === void 0 ? void 0 : _c.call(attrs, { ev, dragData });
|
|
71
|
+
return false;
|
|
72
|
+
},
|
|
73
|
+
ondragleave: (ev) => {
|
|
74
|
+
this.isDraggingOver = false;
|
|
75
|
+
},
|
|
76
|
+
ondrop: (ev) => {
|
|
77
|
+
var _a, _b, _c;
|
|
78
|
+
ev.stopPropagation();
|
|
79
|
+
ev.preventDefault();
|
|
80
|
+
if (!attrs.enableDrop)
|
|
81
|
+
return;
|
|
82
|
+
// if (ev.dataTransfer) {
|
|
83
|
+
// ev.dataTransfer.dropEffect = "move";
|
|
84
|
+
// const movedNodeData = JSON.parse(ev.dataTransfer.getData(DEFAULT_DATA_FORMAT)) as TNodeData;
|
|
85
|
+
// attrs.enableLogging && console.log(`on drop`, movedNodeData, "on", node.data);
|
|
86
|
+
// // attrs.reorderfinish?.();
|
|
87
|
+
// const droppedOnSelf = compareObjects(movedNodeData, node.data);
|
|
88
|
+
// if (!droppedOnSelf) {
|
|
89
|
+
// attrs.onreorder?.({ moved: movedNodeData, target: node.data, above: this.isTargettingAbove });
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
this.isDragging = false;
|
|
93
|
+
this.isDraggingOver = false;
|
|
94
|
+
const dragData = (_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData(DEFAULT_DATA_FORMAT);
|
|
95
|
+
attrs.enableLogging && console.log(`on drop, effect:`, (_b = ev.dataTransfer) === null || _b === void 0 ? void 0 : _b.dropEffect, "dragData:", dragData);
|
|
96
|
+
(_c = attrs.onDrop) === null || _c === void 0 ? void 0 : _c.call(attrs, { ev, dragData });
|
|
97
|
+
},
|
|
98
|
+
ondragend: (ev) => {
|
|
99
|
+
var _a;
|
|
100
|
+
attrs.enableLogging && console.log(`drag end, dropEffect:`, (_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.dropEffect);
|
|
101
|
+
// "move" on success, "none" on failure/cancellation
|
|
102
|
+
// attrs.reorderfinish?.();
|
|
103
|
+
this.isDragging = false;
|
|
104
|
+
this.isDraggingOver = false;
|
|
105
|
+
},
|
|
106
|
+
}, [
|
|
107
|
+
children,
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./DragHandler";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./DragHandler"), exports);
|
package/dist/components/index.js
CHANGED
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
// export * from "./data-table";
|
|
20
20
|
__exportStar(require("./dialog"), exports);
|
|
21
21
|
// export * from "./drawer";
|
|
22
|
+
__exportStar(require("./drag-handler"), exports);
|
|
22
23
|
__exportStar(require("./drop-target"), exports);
|
|
23
24
|
// export * from "./form";
|
|
24
25
|
__exportStar(require("./icon"), exports);
|