react-ui-basics 0.0.218 → 0.0.220
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/Button.d.ts +24 -0
- package/Button.js +45 -75
- package/Button.js.map +1 -1
- package/CalendarMonthView.d.ts +1 -0
- package/CircleProgress.d.ts +1 -0
- package/DNDContainer.js +10 -5
- package/DNDContainer.js.map +1 -1
- package/DNDDraggable.d.ts +29 -0
- package/DNDDraggable.js +27 -44
- package/DNDDraggable.js.map +1 -1
- package/DNDDroppable.d.ts +28 -0
- package/DNDDroppable.js +32 -46
- package/DNDDroppable.js.map +1 -1
- package/DroppableHorizontalList.js +28 -27
- package/DroppableHorizontalList.js.map +1 -1
- package/DroppableList.js +29 -34
- package/DroppableList.js.map +1 -1
- package/Dropzone.js.map +1 -1
- package/MaterialIcon.d.ts +1 -0
- package/ReactConstants.d.ts +1 -0
- package/ReactConstants.js +17 -2
- package/ReactConstants.js.map +1 -1
- package/ScrollableTable.d.ts +4 -2
- package/ScrollableTable.js +5 -6
- package/ScrollableTable.js.map +1 -1
- package/Size.d.ts +1 -0
- package/SpinningProgress.d.ts +1 -0
- package/Table.js +1 -1
- package/Table.js.map +1 -1
- package/TextField.d.ts +36 -0
- package/TextField.js +73 -134
- package/TextField.js.map +1 -1
- package/Tools.d.ts +1 -1
- package/Tools.js +1 -1
- package/Tools.js.map +1 -1
- package/bundle.css +684 -684
- package/package.json +1 -1
- package/src/Button.tsx +97 -0
- package/src/DNDContainer.tsx +19 -10
- package/src/{DNDDraggable.js → DNDDraggable.tsx} +35 -9
- package/src/{DNDDroppable.js → DNDDroppable.tsx} +35 -8
- package/src/DroppableHorizontalList.js +33 -32
- package/src/DroppableList.js +34 -41
- package/src/Dropzone.tsx +1 -1
- package/src/ReactConstants.ts +21 -1
- package/src/ScrollableTable.tsx +7 -7
- package/src/Table.tsx +3 -3
- package/src/{TextField.js → TextField.tsx} +42 -44
- package/src/Tools.ts +2 -2
- package/src/store/Store.test.js +1 -1
- package/src/store/Store.ts +8 -26
- package/store/Store.d.ts +3 -4
- package/store/Store.js +5 -21
- package/store/Store.js.map +1 -1
- package/src/Button.js +0 -98
package/package.json
CHANGED
package/src/Button.tsx
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, {FocusEventHandler, MouseEventHandler, ReactElement, ReactNode} from 'react';
|
|
2
|
+
import ReactCreateElement from './ReactCreateElement';
|
|
3
|
+
import './Button.css'
|
|
4
|
+
import {classNames, DOCUMENT, addEventListener, createRef, orNoop} from "./Tools";
|
|
5
|
+
import PropTypes from "prop-types";
|
|
6
|
+
import {PureComponent, render, stateGS, props} from "./ReactConstants";
|
|
7
|
+
|
|
8
|
+
export interface ButtonProps {
|
|
9
|
+
flat?: boolean,
|
|
10
|
+
raised?: boolean,
|
|
11
|
+
round?: boolean,
|
|
12
|
+
disabled?: boolean,
|
|
13
|
+
withRipple?: boolean,
|
|
14
|
+
type?: 'button' | 'submit' | 'reset',
|
|
15
|
+
className?: string,
|
|
16
|
+
onClick?: MouseEventHandler,
|
|
17
|
+
onFocus?: FocusEventHandler,
|
|
18
|
+
style?: any,
|
|
19
|
+
children?: ReactNode,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class Button extends PureComponent<ButtonProps> {
|
|
23
|
+
static defaultProps = {
|
|
24
|
+
type: 'button',
|
|
25
|
+
withRipple: true,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor(properties) {
|
|
29
|
+
super(properties);
|
|
30
|
+
|
|
31
|
+
const that = this;
|
|
32
|
+
const el = createRef<HTMLButtonElement>();
|
|
33
|
+
const ripple = createRef<HTMLSpanElement>();
|
|
34
|
+
|
|
35
|
+
const rippleClassName = stateGS<string>(that);
|
|
36
|
+
|
|
37
|
+
const onMouseDown = (e) => {
|
|
38
|
+
if (!props(that).withRipple) return;
|
|
39
|
+
|
|
40
|
+
const rect = el().getBoundingClientRect();
|
|
41
|
+
const rippleElement = ripple();
|
|
42
|
+
const style = rippleElement.style;
|
|
43
|
+
const body = DOCUMENT.body;
|
|
44
|
+
|
|
45
|
+
style.height = style.width = Math.max(rect.width, rect.height) + 'px';
|
|
46
|
+
style.top = (e.pageY - rect.top - rippleElement.offsetHeight / 2 - body.scrollTop) + 'px';
|
|
47
|
+
style.left = (e.pageX - rect.left - rippleElement.offsetWidth / 2 - body.scrollLeft) + 'px';
|
|
48
|
+
|
|
49
|
+
rippleClassName('show');
|
|
50
|
+
|
|
51
|
+
addEventListener(rippleElement, 'animationend', () => {
|
|
52
|
+
rippleClassName('showed');
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const onFocus = e => {
|
|
57
|
+
orNoop(props(that).onFocus)(e)
|
|
58
|
+
if (rippleClassName() === 'show')
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
const rect = el().getBoundingClientRect();
|
|
62
|
+
const style = ripple().style;
|
|
63
|
+
|
|
64
|
+
let size = Math.max(rect.width, rect.height) * 0.8
|
|
65
|
+
style.height = style.width = size + 'px';
|
|
66
|
+
style.top = (rect.height / 2 - size / 2) + 'px';
|
|
67
|
+
style.left = (rect.width / 2 - size / 2) + 'px';
|
|
68
|
+
|
|
69
|
+
rippleClassName('focused');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
that[render] = () => {
|
|
73
|
+
const {children, type, className, onClick, flat, raised = !flat, round, style, disabled} = props(that);
|
|
74
|
+
return (
|
|
75
|
+
<button className={classNames('Button',
|
|
76
|
+
className,
|
|
77
|
+
disabled && 'disabled',
|
|
78
|
+
raised && 'raised',
|
|
79
|
+
flat && 'flat',
|
|
80
|
+
round && 'round')
|
|
81
|
+
}
|
|
82
|
+
onFocus={onFocus}
|
|
83
|
+
disabled={disabled}
|
|
84
|
+
style={style}
|
|
85
|
+
type={type}
|
|
86
|
+
onClick={onClick}
|
|
87
|
+
onMouseDown={onMouseDown}
|
|
88
|
+
ref={el}>
|
|
89
|
+
{children}
|
|
90
|
+
<span className={classNames(`ripple`, rippleClassName())} ref={ripple}/>
|
|
91
|
+
</button>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default Button;
|
package/src/DNDContainer.tsx
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
UNDEFINED
|
|
19
19
|
} from "./Tools";
|
|
20
20
|
import {propsGetter, render, componentDidMount} from "./ReactConstants";
|
|
21
|
+
import Droppable from "./DNDDroppable";
|
|
22
|
+
import Draggable from "./DNDDraggable";
|
|
21
23
|
|
|
22
24
|
const clearSelection = () => {
|
|
23
25
|
const getSelection = WINDOW.getSelection;
|
|
@@ -113,9 +115,9 @@ class DNDContainer extends Component<DNDContainerProps, DNDContainerState> {
|
|
|
113
115
|
draggable = null;
|
|
114
116
|
};
|
|
115
117
|
|
|
116
|
-
const draggableInitializer = (item) => {
|
|
118
|
+
const draggableInitializer = (item: Draggable) => {
|
|
117
119
|
const handle = item.props.handle;
|
|
118
|
-
const draggableElement = (handle && item.element.
|
|
120
|
+
const draggableElement: HTMLElement = ((handle && item.element.firstElementChild as HTMLElement) || item.element);
|
|
119
121
|
draggableElement.draggable = true;
|
|
120
122
|
|
|
121
123
|
const dragStartListener = (e) => {
|
|
@@ -131,7 +133,7 @@ class DNDContainer extends Component<DNDContainerProps, DNDContainerState> {
|
|
|
131
133
|
item.width = itemOffset.width;
|
|
132
134
|
item.height = itemOffset.height;
|
|
133
135
|
|
|
134
|
-
let clone = orNoop(item.props.copy)((it) => {
|
|
136
|
+
let clone = orNoop(item.props.copy)((it: Draggable) => {
|
|
135
137
|
let style = it.element.style;
|
|
136
138
|
|
|
137
139
|
const offsetLeft = totalOffsetLeft(container) + (e.clientX - itemOffset.left);
|
|
@@ -177,7 +179,7 @@ class DNDContainer extends Component<DNDContainerProps, DNDContainerState> {
|
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
181
|
onDragStart(e);
|
|
180
|
-
setTimeout(() => item.setState({placeholder: true}), 1)
|
|
182
|
+
return setTimeout(() => item.setState({placeholder: true}), 1)
|
|
181
183
|
};
|
|
182
184
|
addListener(draggableElement, item, 'dragend', (e) => {
|
|
183
185
|
if (item.state.placeholder)
|
|
@@ -232,7 +234,7 @@ class DNDContainer extends Component<DNDContainerProps, DNDContainerState> {
|
|
|
232
234
|
});
|
|
233
235
|
}
|
|
234
236
|
|
|
235
|
-
const droppableInitializer = (item) => {
|
|
237
|
+
const droppableInitializer = (item: Droppable) => {
|
|
236
238
|
droppables.push(item);
|
|
237
239
|
|
|
238
240
|
addEventListener(item.element, 'drop', (e) => {
|
|
@@ -242,27 +244,34 @@ class DNDContainer extends Component<DNDContainerProps, DNDContainerState> {
|
|
|
242
244
|
data && orNoop(item.props.onDrop)(data);
|
|
243
245
|
}
|
|
244
246
|
}, false);
|
|
245
|
-
addEventListener(item.element, '
|
|
247
|
+
addEventListener(item.element, 'mouseenter', (e) => {
|
|
248
|
+
if(!draggable)
|
|
249
|
+
return
|
|
250
|
+
|
|
246
251
|
if (item.state.allow) {
|
|
247
252
|
preventDefault(e);
|
|
248
253
|
item.isHover(e, draggable, true)
|
|
249
254
|
}
|
|
250
255
|
});
|
|
251
|
-
addEventListener(item.element, '
|
|
256
|
+
addEventListener(item.element, 'mouseleave', (e) => {
|
|
257
|
+
if(!draggable)
|
|
258
|
+
return
|
|
259
|
+
|
|
252
260
|
if (item.state.allow) {
|
|
253
261
|
preventDefault(e);
|
|
254
262
|
item.isHover(e, draggable, false)
|
|
255
263
|
}
|
|
256
264
|
});
|
|
257
265
|
|
|
258
|
-
item.onDragStart = (e, draggable) => {
|
|
266
|
+
item.onDragStart = (e, draggable: Draggable) => {
|
|
259
267
|
item.bounds = item.element.getBoundingClientRect();
|
|
260
268
|
let allow = (orNoop(item.props.onDragStart)(e, data));
|
|
261
269
|
if (allow === UNDEFINED)
|
|
262
270
|
allow = true
|
|
263
|
-
item.setState({allow});
|
|
271
|
+
item.setState({allow: allow as boolean});
|
|
272
|
+
item.isHover(e, draggable)
|
|
264
273
|
};
|
|
265
|
-
item.isHover = (e, draggable, hover) => {
|
|
274
|
+
item.isHover = (e, draggable, hover?: boolean) => {
|
|
266
275
|
const bounds = item.bounds;
|
|
267
276
|
if (!bounds)
|
|
268
277
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, {MouseEventHandler} from 'react';
|
|
2
2
|
import ReactCreateElement from './ReactCreateElement';
|
|
3
3
|
import {classNames, orNoop, ref} from "./Tools";
|
|
4
4
|
import {componentDidUpdate, props, state, render, children, className, componentDidMount, componentWillUnmount, PureComponent} from "./ReactConstants";
|
|
@@ -12,35 +12,61 @@ const hover = 'hover',
|
|
|
12
12
|
|
|
13
13
|
const init = that => orNoop(props(that)[initializer])(that);
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
interface DraggableProps {
|
|
16
|
+
id: string | number
|
|
17
|
+
data: any
|
|
18
|
+
copy?: (initializer: (it: Draggable) => Draggable, classname: string, item: Draggable) => Draggable
|
|
19
|
+
onClick?: MouseEventHandler<HTMLDivElement>
|
|
20
|
+
children?: React.ReactNode
|
|
21
|
+
className?: string,
|
|
22
|
+
handle?: React.ReactNode
|
|
23
|
+
initializer?: (draggable: Draggable) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface DraggableState {
|
|
27
|
+
dragged?: boolean,
|
|
28
|
+
placeholder?: boolean,
|
|
29
|
+
hover?: boolean,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
abstract class AbstractDraggable extends PureComponent<DraggableProps, DraggableState> {
|
|
33
|
+
onUnmount?: () => void
|
|
34
|
+
element: HTMLDivElement
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
createPositionListener: (e, style, itemOffset, container) => any;
|
|
38
|
+
initDraggedStyles: (style, itemOffset) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class Draggable extends AbstractDraggable {
|
|
16
42
|
|
|
17
43
|
constructor(properties) {
|
|
18
44
|
super(properties);
|
|
19
45
|
const that = this;
|
|
20
46
|
that.state = {};
|
|
21
|
-
that[
|
|
47
|
+
that[componentDidUpdate] = (prevProps) => {
|
|
22
48
|
if (prevProps[handle] !== props(that)[handle] || prevProps[initializer] !== props(that)[initializer])
|
|
23
49
|
init(that)
|
|
24
50
|
};
|
|
25
|
-
that[
|
|
51
|
+
that[componentDidMount] = () => {
|
|
26
52
|
init(that)
|
|
27
53
|
};
|
|
28
|
-
that[
|
|
54
|
+
that[componentWillUnmount] = () => {
|
|
29
55
|
orNoop(that.onUnmount)();
|
|
30
56
|
};
|
|
31
|
-
that[
|
|
57
|
+
that[render] = () => {
|
|
32
58
|
const _state = state(that),
|
|
33
59
|
_props = props(that);
|
|
34
|
-
return <div className={classNames('Draggable', _props[
|
|
60
|
+
return <div className={classNames('Draggable', _props[className],
|
|
35
61
|
_state[dragged] && dragged,
|
|
36
62
|
_state[placeholder] && placeholder,
|
|
37
63
|
_state[hover] && hover,
|
|
38
64
|
)}
|
|
39
|
-
onClick={_props
|
|
65
|
+
onClick={_props.onClick}
|
|
40
66
|
ref={ref('element', that)}
|
|
41
67
|
>
|
|
42
68
|
{_props[handle]}
|
|
43
|
-
{_props[
|
|
69
|
+
{_props[children]}
|
|
44
70
|
</div>;
|
|
45
71
|
}
|
|
46
72
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import ReactCreateElement from './ReactCreateElement';
|
|
3
3
|
import {classNames, orNoop, ref, preventDefault, stopPropagation} from "./Tools";
|
|
4
4
|
import {componentDidMount, componentDidUpdate, render, props, state, componentWillUnmount, children, className, PureComponent} from "./ReactConstants";
|
|
5
|
+
import Draggable from "./DNDDraggable";
|
|
5
6
|
|
|
6
7
|
const hover = 'hover',
|
|
7
8
|
allow = 'allow',
|
|
@@ -10,32 +11,58 @@ const hover = 'hover',
|
|
|
10
11
|
|
|
11
12
|
const init = that => orNoop(props(that)[initializer])(that);
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
interface DroppableProps {
|
|
15
|
+
children?: React.ReactNode
|
|
16
|
+
className?: string,
|
|
17
|
+
initializer?: (draggable: Droppable) => void
|
|
18
|
+
onDrop?: (data: any) => void
|
|
19
|
+
onHover?: (e, draggable: Draggable) => void
|
|
20
|
+
onDragStart?: (e, data: any) => boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface DroppableState {
|
|
24
|
+
allow?: boolean,
|
|
25
|
+
hover?: boolean,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
abstract class AbstractDroppable extends PureComponent<DroppableProps, DroppableState> {
|
|
29
|
+
onUnmount?: () => void
|
|
30
|
+
element: HTMLDivElement
|
|
31
|
+
onDragStart: (e, draggable: Draggable) => void
|
|
32
|
+
bounds: DOMRect
|
|
33
|
+
isHover: (e, draggable: Draggable, hover?: boolean) => void;
|
|
34
|
+
onDragEnd: () => void;
|
|
35
|
+
dropIfHover: () => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class Droppable extends AbstractDroppable {
|
|
39
|
+
|
|
14
40
|
|
|
15
41
|
constructor(properties) {
|
|
16
42
|
super(properties);
|
|
17
43
|
const that = this;
|
|
44
|
+
that.state = {}
|
|
18
45
|
|
|
19
|
-
that[
|
|
46
|
+
that[componentDidUpdate] = (prevProps) => {
|
|
20
47
|
if (prevProps[initializer] !== props(that)[initializer])
|
|
21
48
|
init(that)
|
|
22
49
|
};
|
|
23
50
|
|
|
24
|
-
that[
|
|
51
|
+
that[componentDidMount] = () => {
|
|
25
52
|
init(that)
|
|
26
53
|
};
|
|
27
54
|
|
|
28
|
-
that[
|
|
55
|
+
that[componentWillUnmount] = () => {
|
|
29
56
|
orNoop(that.onUnmount)();
|
|
30
57
|
};
|
|
31
58
|
|
|
32
|
-
that[
|
|
59
|
+
that[render] = () => {
|
|
33
60
|
const _props = props(that),
|
|
34
61
|
_state = state(that);
|
|
35
62
|
return <div className={
|
|
36
63
|
classNames(
|
|
37
64
|
'Droppable',
|
|
38
|
-
_props[
|
|
65
|
+
_props[className],
|
|
39
66
|
_state[hover] && hover,
|
|
40
67
|
_state[allow] && allow,
|
|
41
68
|
)}
|
|
@@ -46,7 +73,7 @@ class Droppable extends PureComponent {
|
|
|
46
73
|
}
|
|
47
74
|
}}
|
|
48
75
|
ref={ref('element', that)}>
|
|
49
|
-
{_props[
|
|
76
|
+
{_props[children]}
|
|
50
77
|
</div>;
|
|
51
78
|
};
|
|
52
79
|
}
|
|
@@ -39,6 +39,37 @@ class DroppableHorizontalList extends Component {
|
|
|
39
39
|
let oldIndex;
|
|
40
40
|
let newIndex;
|
|
41
41
|
|
|
42
|
+
const onHover = (e, draggable) => {
|
|
43
|
+
const offset = __pageX(e) - that.scrollOffsetX;
|
|
44
|
+
const transformLeft = 'translateX(' + __width(draggable) + 'px)';
|
|
45
|
+
const transformRight = 'translateX(-' + __width(draggable) + 'px)';
|
|
46
|
+
list.forEach((id, i) => {
|
|
47
|
+
if (i !== oldIndex) {
|
|
48
|
+
const d = draggables[id];
|
|
49
|
+
const bounds = d.bounds;
|
|
50
|
+
const style = d.element.style;
|
|
51
|
+
if (i > oldIndex) {
|
|
52
|
+
if (offset >= __left(bounds))
|
|
53
|
+
style.transform = transformRight;
|
|
54
|
+
else
|
|
55
|
+
style.transform = '';
|
|
56
|
+
} else {
|
|
57
|
+
if (offset <= bounds.right)
|
|
58
|
+
style.transform = transformLeft;
|
|
59
|
+
else
|
|
60
|
+
style.transform = '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let i = list.findIndex(id => {
|
|
66
|
+
let bounds = draggables[id].bounds;
|
|
67
|
+
return offset >= __left(bounds) && offset <= bounds.right
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
newIndex = i !== -1 ? i : __length(list);
|
|
71
|
+
};
|
|
72
|
+
|
|
42
73
|
that[ReactConstants[0]] = () => {
|
|
43
74
|
let inTransition = false;
|
|
44
75
|
orNoop(props().provideDraggableEnhancer)(initializer => it => {
|
|
@@ -46,6 +77,7 @@ class DroppableHorizontalList extends Component {
|
|
|
46
77
|
it.createPositionListener = (e, style) => {
|
|
47
78
|
const offset = __pageX(e);
|
|
48
79
|
return e => {
|
|
80
|
+
onHover(e, it)
|
|
49
81
|
__pageX(e) && (style.transform = 'translateX(' + (__pageX(e) - offset) + 'px)');
|
|
50
82
|
};
|
|
51
83
|
};
|
|
@@ -80,41 +112,10 @@ class DroppableHorizontalList extends Component {
|
|
|
80
112
|
})
|
|
81
113
|
};
|
|
82
114
|
|
|
83
|
-
const onHover = (e, draggable) => {
|
|
84
|
-
const offset = __pageX(e) - that.scrollOffsetX;
|
|
85
|
-
const transformLeft = 'translateX(' + __width(draggable) + 'px)';
|
|
86
|
-
const transformRight = 'translateX(-' + __width(draggable) + 'px)';
|
|
87
|
-
list.forEach((id, i) => {
|
|
88
|
-
if (i !== oldIndex) {
|
|
89
|
-
const d = draggables[id];
|
|
90
|
-
const bounds = d.bounds;
|
|
91
|
-
const style = d.element.style;
|
|
92
|
-
if (i > oldIndex) {
|
|
93
|
-
if (offset >= __left(bounds))
|
|
94
|
-
style.transform = transformRight;
|
|
95
|
-
else
|
|
96
|
-
style.transform = '';
|
|
97
|
-
} else {
|
|
98
|
-
if (offset <= bounds.right)
|
|
99
|
-
style.transform = transformLeft;
|
|
100
|
-
else
|
|
101
|
-
style.transform = '';
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
let i = list.findIndex(id => {
|
|
107
|
-
let bounds = draggables[id].bounds;
|
|
108
|
-
return offset >= __left(bounds) && offset <= bounds.right
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
newIndex = i !== -1 ? i : __length(list);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
115
|
const onDragStart = (e, draggable) => {
|
|
115
116
|
dragging = true;
|
|
116
117
|
dropped = false;
|
|
117
|
-
oldIndex = list.indexOf(
|
|
118
|
+
oldIndex = list.indexOf(draggable.id);
|
|
118
119
|
that.scrollOffsetX = __pageX(e) - e.clientX;
|
|
119
120
|
|
|
120
121
|
list.forEach((id) => {
|
package/src/DroppableList.js
CHANGED
|
@@ -39,6 +39,37 @@ class DroppableList extends Component {
|
|
|
39
39
|
let oldIndex;
|
|
40
40
|
let newIndex;
|
|
41
41
|
|
|
42
|
+
const onHover = (e, draggable) => {
|
|
43
|
+
const y = __pageY(e) - that.scrollOffsetY;
|
|
44
|
+
const transformUp = 'translateY(' + __height(draggable) + 'px)';
|
|
45
|
+
const transformDown = 'translateY(-' + __height(draggable) + 'px)';
|
|
46
|
+
list.forEach((id, i) => {
|
|
47
|
+
if (i !== oldIndex) {
|
|
48
|
+
const d = draggables[id];
|
|
49
|
+
const bounds = d.bounds;
|
|
50
|
+
const style = d.element.style;
|
|
51
|
+
if (i > oldIndex) {
|
|
52
|
+
if (y >= __top(bounds))
|
|
53
|
+
style.transform = transformDown;
|
|
54
|
+
else
|
|
55
|
+
style.transform = '';
|
|
56
|
+
} else {
|
|
57
|
+
if (y <= bounds.bottom)
|
|
58
|
+
style.transform = transformUp;
|
|
59
|
+
else
|
|
60
|
+
style.transform = '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let i = list.findIndex(id => {
|
|
66
|
+
let bounds = draggables[id].bounds;
|
|
67
|
+
return y >= __top(bounds) && y <= bounds.bottom
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
newIndex = i !== -1 ? i : __length(list);
|
|
71
|
+
};
|
|
72
|
+
|
|
42
73
|
that[ReactConstants[0]] = () => {
|
|
43
74
|
let inTransition = false;
|
|
44
75
|
orNoop(props().provideDraggableEnhancer)(initializer => it => {
|
|
@@ -46,7 +77,8 @@ class DroppableList extends Component {
|
|
|
46
77
|
it.createPositionListener = (e, style) => {
|
|
47
78
|
const offsetTop = __pageY(e);
|
|
48
79
|
return e => {
|
|
49
|
-
|
|
80
|
+
onHover(e, it)
|
|
81
|
+
__pageY(e) && (style.transform = 'translateY(' + (__pageY(e) - offsetTop) + 'px)');
|
|
50
82
|
};
|
|
51
83
|
};
|
|
52
84
|
it.initDraggedStyles = NOOP;
|
|
@@ -79,52 +111,13 @@ class DroppableList extends Component {
|
|
|
79
111
|
draggables[getProps(it).id] = it;
|
|
80
112
|
})
|
|
81
113
|
|
|
82
|
-
orNoop(props().provideScrollListener)(e => {
|
|
83
|
-
if (!dragging)
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
that.scrollDiff = that.scroll - orNoop(props().getScrollPosition)() || 0;
|
|
87
|
-
})
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const onHover = (e, draggable) => {
|
|
91
|
-
const y = __pageY(e) - that.scrollOffsetY - that.scrollDiff;
|
|
92
|
-
const transformUp = 'translateY(' + __height(draggable) + 'px)';
|
|
93
|
-
const transformDown = 'translateY(-' + __height(draggable) + 'px)';
|
|
94
|
-
list.forEach((id, i) => {
|
|
95
|
-
if (i !== oldIndex) {
|
|
96
|
-
const d = draggables[id];
|
|
97
|
-
const bounds = d.bounds;
|
|
98
|
-
const style = d.element.style;
|
|
99
|
-
if (i > oldIndex) {
|
|
100
|
-
if (y >= __top(bounds))
|
|
101
|
-
style.transform = transformDown;
|
|
102
|
-
else
|
|
103
|
-
style.transform = '';
|
|
104
|
-
} else {
|
|
105
|
-
if (y <= bounds.bottom)
|
|
106
|
-
style.transform = transformUp;
|
|
107
|
-
else
|
|
108
|
-
style.transform = '';
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
let i = list.findIndex(id => {
|
|
114
|
-
let bounds = draggables[id].bounds;
|
|
115
|
-
return y >= __top(bounds) && y <= bounds.bottom
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
newIndex = i !== -1 ? i : __length(list);
|
|
119
114
|
};
|
|
120
115
|
|
|
121
116
|
const onDragStart = (e, draggable) => {
|
|
122
117
|
dragging = true;
|
|
123
118
|
dropped = false;
|
|
124
|
-
oldIndex = list.indexOf(
|
|
119
|
+
oldIndex = list.indexOf(draggable.id);
|
|
125
120
|
that.scrollOffsetY = __pageY(e) - e.clientY;
|
|
126
|
-
that.scroll = orNoop(props().getScrollPosition)() || 0;
|
|
127
|
-
that.scrollDiff = 0;
|
|
128
121
|
|
|
129
122
|
list.forEach((id) => {
|
|
130
123
|
draggables[id].bounds = draggables[id].element.getBoundingClientRect();
|
package/src/Dropzone.tsx
CHANGED
package/src/ReactConstants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, {useEffect, useReducer, useRef} from 'react';
|
|
2
2
|
|
|
3
3
|
const EMPTY = {};
|
|
4
4
|
export const props: <P>(that: React.Component<P>) => P = that => that.props;
|
|
@@ -29,6 +29,26 @@ export const stateGSs = (that, num) => {
|
|
|
29
29
|
return result;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
type GetSnapshot<T> = () => T;
|
|
33
|
+
type Subscribe = (onStoreChange: () => void) => () => void;
|
|
34
|
+
const useSyncExternalStoreShim = <T>(subscribe: Subscribe, getSnapshot: GetSnapshot<T>) => {
|
|
35
|
+
const [_, forceUpdate] = useReducer(x => x + 1, 0);
|
|
36
|
+
const cb = useRef<GetSnapshot<T>>();
|
|
37
|
+
cb.current = getSnapshot;
|
|
38
|
+
let value = getSnapshot()
|
|
39
|
+
|
|
40
|
+
useEffect(() => subscribe(() => {
|
|
41
|
+
let next = cb.current()
|
|
42
|
+
if (value !== next) {
|
|
43
|
+
value = next
|
|
44
|
+
forceUpdate()
|
|
45
|
+
}
|
|
46
|
+
}), []);
|
|
47
|
+
return value
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const useSyncExternalStore = React['useSyncExternalStore'] || useSyncExternalStoreShim
|
|
51
|
+
|
|
32
52
|
export const componentDidMount = 'componentDidMount';
|
|
33
53
|
export const componentWillUnmount = 'componentWillUnmount';
|
|
34
54
|
export const componentDidUpdate = 'componentDidUpdate';
|
package/src/ScrollableTable.tsx
CHANGED
|
@@ -13,13 +13,17 @@ export interface ScrollableTableProps<T> extends TableProps<T> {
|
|
|
13
13
|
scrollableProps?: any
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
class
|
|
16
|
+
abstract class AbstractScrollableTable<T> extends PureComponent<ScrollableTableProps<T>, TableState<T>> {
|
|
17
|
+
getScrollable: () => Scrollable
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class ScrollableTable<T> extends AbstractScrollableTable<T> implements WithScrollable {
|
|
17
21
|
|
|
18
22
|
constructor(properties) {
|
|
19
23
|
super(properties);
|
|
20
24
|
const that = this;
|
|
21
25
|
|
|
22
|
-
const scrollableRef = createRef();
|
|
26
|
+
const scrollableRef = createRef<Scrollable>();
|
|
23
27
|
|
|
24
28
|
that[render] = () => {
|
|
25
29
|
return <div className={`ScrollableTable`}>
|
|
@@ -28,11 +32,7 @@ class ScrollableTable<T> extends PureComponent<ScrollableTableProps<T>, TableSta
|
|
|
28
32
|
</Scrollable>
|
|
29
33
|
</div>;
|
|
30
34
|
}
|
|
31
|
-
that.getScrollable =
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getScrollable(): Scrollable {
|
|
35
|
-
return undefined;
|
|
35
|
+
that.getScrollable = scrollableRef
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
package/src/Table.tsx
CHANGED
|
@@ -123,14 +123,14 @@ class Table<T> extends Component<TableProps<T>, TableState<T>> {
|
|
|
123
123
|
super(properties);
|
|
124
124
|
const props = propsGetter(this);
|
|
125
125
|
|
|
126
|
-
const headers = createRef();
|
|
126
|
+
const headers = createRef<HTMLTableRowElement>();
|
|
127
127
|
let updateHeadersInterval = 0;
|
|
128
128
|
|
|
129
129
|
const updateHeaders = () => {
|
|
130
130
|
const hidden = headers().querySelectorAll('.hidden');
|
|
131
131
|
const fixed = headers().querySelectorAll('.fixed');
|
|
132
132
|
for (let i = 0; i < hidden.length; i++) {
|
|
133
|
-
fixed[i].style.width = hidden[i].offsetWidth + 'px'
|
|
133
|
+
(fixed[i] as HTMLElement).style.width = (hidden[i] as HTMLElement).offsetWidth + 'px'
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
@@ -339,7 +339,7 @@ class Row<T> extends PureComponent<RowProps<T>> {
|
|
|
339
339
|
onClick={onClick}>
|
|
340
340
|
{displayEditor && !column.editor && (
|
|
341
341
|
<TextField
|
|
342
|
-
value={value}
|
|
342
|
+
value={String(value)}
|
|
343
343
|
focused={editing.focused}
|
|
344
344
|
onFocus={() => {
|
|
345
345
|
setEditing(item, i, j, value, true)
|