react-ui-basics 0.0.180 → 0.0.182

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.
@@ -1,263 +0,0 @@
1
- import ReactConstants from "./../ReactConstants";
2
- import {clientHeight as __clientHeight, clientWidth as __clientWidth, createAccessor as __createAccessor, data as __data, height as __height, left as __left, length as __length, pageX as __pageX, pageY as __pageY, props as __props, scrollLeft as __scrollLeft, scrollTop as __scrollTop, state as __state, style as __style, target as __target, top as __top, value as __value, width as __width} from "./../CommonFields";
3
- import React, {Component} from 'react';
4
- import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers";
5
- import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers";
6
- import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers";
7
- import './DNDContainer.css';
8
- import ReactCreateElement from './ReactCreateElement';
9
- import './DNDContainer.css'
10
- import {classNames, NOOP, orNoop, preventDefault, ref, DOCUMENT, WINDOW, addEventListener, removeEventListener, setTimeout, clearTimeout, requestAnimationFrame} from "./Tools";
11
-
12
- const clearSelection = () => {
13
- const getSelection = WINDOW.getSelection;
14
- if (getSelection) {
15
- if (getSelection().empty) { // Chrome
16
- getSelection().empty();
17
- } else if (getSelection().removeAllRanges) { // Firefox
18
- getSelection().removeAllRanges();
19
- }
20
- } else if (DOCUMENT.selection) { // IE?
21
- DOCUMENT.selection.empty();
22
- }
23
- };
24
-
25
- const droppables = 'ds';
26
- const positionListener = 'pl';
27
-
28
- class DNDContainer extends Component {
29
-
30
- constructor(props) {
31
- super(props);
32
-
33
- this.state = {
34
- draggable: null,
35
- };
36
-
37
- this[droppables] = [];
38
- this[positionListener] = NOOP;
39
- }
40
-
41
- render() {
42
- const {children, className} = __props(this);
43
- const {draggable} = __state(this);
44
- return <div className={classNames('DNDContainer', className)} ref={ref('container', this)}>
45
- {children}
46
- <div className="overlay">{draggable}</div>
47
- </div>;
48
- };
49
-
50
- componentDidMount() {
51
- const {
52
- provideDraggableInitializer,
53
- provideDroppableInitializer,
54
- } = __props(this);
55
-
56
- orNoop(provideDraggableInitializer)(this.draggableInitializer);
57
- orNoop(provideDroppableInitializer)(this.droppableInitializer);
58
- addEventListener(this.container, 'dragover', this.onDrag, {capture: true, passive: true})
59
- };
60
-
61
- draggableInitializer = (item) => {
62
- const handle = __props(item).handle;
63
- const draggableElement = (handle && item.element.childNodes[0]) || item.element;
64
- draggableElement.draggable = true;
65
-
66
- const dragStartListener = (e) => {
67
- clearSelection();
68
- const container = this.container;
69
- this.data = __props(item).data;
70
- this.draggable = item;
71
- this.scrollOffsetX = __pageX(e) - e.clientX;
72
- this.scrollOffsetY = __pageY(e) - e.clientY;
73
- const dataTransfer = e.dataTransfer;
74
- const itemOffset = item.element.getBoundingClientRect();
75
-
76
- item.width = __width(itemOffset);
77
- item.height = __height(itemOffset);
78
-
79
- let clone = orNoop(__props(item).copy)((it) => {
80
- let style = it.element.style;
81
-
82
- const offsetLeft = totalOffsetLeft(container) + (e.clientX - __left(itemOffset));
83
- const offsetTop = totalOffsetTop(container) + (e.clientY - __top(itemOffset));
84
- this[positionListener] = orNoop(it.createPositionListener)(e, style, itemOffset, container) || ((e) => {
85
- if (__pageX(e) === 0)
86
- return;
87
-
88
- style.transform = 'translate(' + (__pageX(e) - offsetLeft) + 'px, ' + (__pageY(e) - offsetTop) + 'px)';
89
- });
90
-
91
-
92
- requestAnimationFrame(() => {
93
- if (dataTransfer && !dataTransfer.setDragImage) {
94
- style.opacity = '0'; // hide dragged element in ie and edge
95
- }
96
- if (it.initDraggedStyles)
97
- it.initDraggedStyles(style, itemOffset);
98
- else {
99
- style.position = 'absolute';
100
- style.pointerEvents = 'none';
101
- style.opacity = '1';
102
- style.top = '0px';
103
- style.left = '0px';
104
- style.width = __width(itemOffset) + 'px';
105
- style.height = __height(itemOffset) + 'px';
106
- }
107
-
108
- this.onDrag(e);
109
- it.setState({dragged: true});
110
- });
111
- return it;
112
- }, 'copy', item);
113
-
114
- dataTransfer && dataTransfer.setData && dataTransfer.setData('text', ''); // required by firefox
115
- dataTransfer && (dataTransfer.dropEffect = "move");
116
- if (clone) {
117
- if (dataTransfer && dataTransfer.setDragImage) {
118
- clone !== item && this.setState({draggable: clone});
119
- const img = document.createElement('img');
120
- img.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
121
- dataTransfer.setDragImage(img, 0, 0);
122
- }
123
- }
124
- this.onDragStart(e);
125
- setTimeout(() => item.setState({placeholder: true}), 1)
126
- };
127
- addListener(draggableElement, item, 'dragend', (e) => {
128
- item.setState({placeholder: false});
129
- this.onDragEnd()
130
- });
131
- addListener(draggableElement, item, 'dragstart', dragStartListener);
132
-
133
- let longTouch;
134
- let dragStarted = false;
135
- let dragged = false;
136
- addListener(draggableElement, item, 'touchstart', e => {
137
- if (e.touches.length > 1)
138
- return;
139
-
140
- dragged = dragStarted = false;
141
- const touch = e.targetTouches[0];
142
- longTouch = setTimeout(() => longTouch && (dragStarted = true) && (longTouch = dragStartListener(touch)), !handle ? 500 : 0)
143
- });
144
-
145
- addListener(draggableElement, item, 'touchmove', e => {
146
- if (longTouch) {
147
- longTouch = clearTimeout(longTouch);
148
- return;
149
- }
150
- if (!dragStarted)
151
- return;
152
-
153
- if (e.touches.length > 1)
154
- return;
155
-
156
- preventDefault(e);
157
- dragged = true;
158
- const touch = e.targetTouches[0];
159
- this[positionListener](touch);
160
- this[droppables].forEach(it => it.isHover(touch, item))
161
- });
162
-
163
- addListener(draggableElement, item, 'touchend', e => {
164
- longTouch = clearTimeout(longTouch);
165
- if (!dragged)
166
- return;
167
-
168
- item.setState({placeholder: false});
169
- if (e.touches.length > 0)
170
- return;
171
-
172
- this[droppables].forEach(it => it.dropIfHover());
173
- this.onDragEnd();
174
- });
175
- };
176
-
177
-
178
- droppableInitializer = (item) => {
179
- this[droppables].push(item);
180
-
181
- addEventListener(item.element, 'drop', (e) => {
182
- preventDefault(e);
183
- __data(this) && orNoop(__props(item).onDrop)(__data(this));
184
- }, false);
185
-
186
- item.onDragStart = (e, draggable) => {
187
- item.bounds = item.element.getBoundingClientRect();
188
- item.setState({allow: true});
189
- orNoop(__props(item).onDragStart)(e, draggable);
190
- };
191
- item.isHover = (e, draggable) => {
192
- const bounds = item.bounds;
193
- if (!bounds)
194
- return;
195
-
196
- let y = __pageY(e) - this.scrollOffsetY;
197
- let x = __pageX(e) - this.scrollOffsetX;
198
- let hover = __left(bounds) <= x && bounds.right >= x && __top(bounds) <= y && bounds.bottom >= y;
199
-
200
- hover && orNoop(__props(item).onHover)(e, draggable);
201
-
202
- if (hover)
203
- !__state(item).hover && item.setState({hover});
204
- else
205
- __state(item).hover && item.setState({hover});
206
- };
207
- item.dropIfHover = () => {
208
- __data(this) && __state(item).hover && orNoop(__props(item).onDrop)(__data(this));
209
- };
210
- item.onDragEnd = () => {
211
- orNoop(orNoop(this.draggable).onDragEnd)();
212
- item.setState({allow: false, hover: false});
213
- };
214
- item.onUnmount = () => this[droppables].splice(this[droppables].indexOf(item), 1);
215
- };
216
-
217
- onDrag = (e) => {
218
- if (!this.draggable)
219
- return;
220
-
221
- this[positionListener](e);
222
- this[droppables].forEach(it => it.isHover(e, this.draggable))
223
- };
224
- onDragStart = (e) => {
225
- this[droppables].forEach(it => it.onDragStart(e, this.draggable))
226
- };
227
- onDragEnd = () => {
228
- const draggable = this.draggable;
229
- if (draggable.element) {
230
- let style = draggable.element.style;
231
- style.position = '';
232
- style.pointerEvents = '';
233
- style.width = ``;
234
- style.height = ``;
235
- style.opacity = '';
236
- }
237
- draggable.setState({dragged: false});
238
-
239
- this.setState({draggable: null});
240
-
241
- this[droppables].forEach(it => {
242
- it.onDragEnd();
243
- orNoop(__props(it).onDragEnd)(this.draggable)
244
- });
245
- this.data = null;
246
- this.draggable = null;
247
- };
248
- }
249
-
250
- export const removeListener = (el, item, type) => item[type] && removeEventListener(el, type, item[type]);
251
- export const addListener = (el, item, type, listener) => {
252
- removeListener(el, item, type);
253
- addEventListener(el, type, item[type] = listener);
254
- };
255
-
256
- const totalOffsetTop = (el) => {
257
- return el.getBoundingClientRect().top + (WINDOW.pageYOffset || DOCUMENT.documentElement.scrollTop);
258
- };
259
- const totalOffsetLeft = (el) => {
260
- return el.getBoundingClientRect().left + (WINDOW.pageXOffset || DOCUMENT.documentElement.scrollLeft);
261
- };
262
-
263
- export default DNDContainer;