react-ui-basics 0.0.220 → 0.0.222

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 (48) hide show
  1. package/Animated.js +1 -0
  2. package/Animated.js.map +1 -1
  3. package/Button.js.map +1 -1
  4. package/Dialog.d.ts +29 -0
  5. package/Dialog.js +84 -143
  6. package/Dialog.js.map +1 -1
  7. package/FilteredList.css +1 -1
  8. package/FilteredList.d.ts +62 -0
  9. package/FilteredList.js +128 -232
  10. package/FilteredList.js.map +1 -1
  11. package/FormUploadProgress.d.ts +19 -0
  12. package/FormUploadProgress.js +14 -39
  13. package/FormUploadProgress.js.map +1 -1
  14. package/Modal.d.ts +31 -0
  15. package/Modal.js +102 -134
  16. package/Modal.js.map +1 -1
  17. package/ReactConstants.d.ts +6 -2
  18. package/ReactConstants.js.map +1 -1
  19. package/ReactCreateElement.d.ts +3 -0
  20. package/ReactCreateElement.js.map +1 -1
  21. package/ReadyListener.d.ts +34 -0
  22. package/ReadyListener.js +34 -56
  23. package/ReadyListener.js.map +1 -1
  24. package/Scrollable.css +0 -1
  25. package/Scrollable.d.ts +33 -0
  26. package/Scrollable.js +310 -325
  27. package/Scrollable.js.map +1 -1
  28. package/_virtual/_rollupPluginBabelHelpers.js +0 -15
  29. package/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  30. package/bundle.css +829 -830
  31. package/package.json +1 -1
  32. package/router/Route.js +1 -0
  33. package/router/Route.js.map +1 -1
  34. package/src/Button.tsx +0 -1
  35. package/src/{Dialog.js → Dialog.tsx} +63 -44
  36. package/src/FilteredList.css +1 -1
  37. package/src/FilteredList.scss +1 -1
  38. package/src/{FilteredList.js → FilteredList.tsx} +95 -45
  39. package/src/{FormUploadProgress.js → FormUploadProgress.tsx} +13 -22
  40. package/src/{Modal.js → Modal.tsx} +48 -33
  41. package/src/ReactConstants.ts +9 -3
  42. package/src/ReactCreateElement.tsx +3 -0
  43. package/src/ReadyListener.tsx +58 -0
  44. package/src/Scrollable.css +0 -1
  45. package/src/Scrollable.scss +0 -1
  46. package/src/{Scrollable.js → Scrollable.tsx} +78 -64
  47. package/src/ReactCreateElement.js +0 -3
  48. package/src/ReadyListener.js +0 -48
@@ -1,4 +1,4 @@
1
- import ReactConstants from "./../ReactConstants"; 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"; import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers"; import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers"; import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers"; import './Modal.css'; import React from 'react';
1
+ import React, {ReactElement, ReactNode} from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import ReactCreateElement from './ReactCreateElement';
4
4
  import './Modal.css'
@@ -6,7 +6,6 @@ import Button from "./Button";
6
6
  import {classNames, orNoop, setTimeout, DOCUMENT, addEventListener, removeEventListener, createRef, UNDEFINED, stopPropagation} from "./Tools";
7
7
  import {PureComponent, componentDidMount, render, propsGetter, stateGSs, componentDidUpdate} from "./ReactConstants";
8
8
  import MaterialIcon from "./MaterialIcon";
9
- import PropTypes from "prop-types";
10
9
 
11
10
  let listenerRef;
12
11
  let zIndex = 100;
@@ -26,7 +25,32 @@ const addListener = (modal, listener) => {
26
25
  addEventListener(DOCUMENT, EVENT_TYPE, listenerRef = listener);
27
26
  };
28
27
 
29
- class Modal extends PureComponent {
28
+ type VoidFunction = () => void;
29
+
30
+ export interface ModalProps {
31
+ className?: string
32
+ top?: number
33
+ container?: Element | DocumentFragment
34
+ children?: ReactNode
35
+ closeIcon?: string | ReactElement
36
+ beforeClose?: (close: VoidFunction) => void
37
+ onOpen?: VoidFunction
38
+ onClose?: VoidFunction
39
+ open?: (open: VoidFunction) => void
40
+ close?: (open: VoidFunction) => void
41
+ show?: boolean
42
+ }
43
+
44
+ abstract class AbstractModal extends PureComponent<ModalProps> {
45
+ close: VoidFunction
46
+ open: VoidFunction
47
+ }
48
+
49
+ class Modal extends AbstractModal {
50
+
51
+ static defaultContainer = UNDEFINED
52
+ static pollListener = pollListener
53
+ static addListener = addListener
30
54
 
31
55
  static defaultProps = {
32
56
  closeIcon: <MaterialIcon icon="close"/>,
@@ -41,22 +65,22 @@ class Modal extends PureComponent {
41
65
  isShow,
42
66
  getMenu,
43
67
  getBeforeClose,
44
- ] = stateGSs(that, 3);
45
- const overlay = createRef();
46
- const el = createRef();
47
- const content = createRef();
68
+ ] = stateGSs<[boolean, any, (close: VoidFunction) => void]>(that, 3);
69
+ const overlay = createRef<HTMLDivElement>();
70
+ const el = createRef<HTMLDivElement>();
71
+ const content = createRef<HTMLDivElement>();
48
72
  const props = propsGetter(that);
49
73
 
50
74
  const beforeClose = (e) => {
51
75
  stopPropagation(e);
52
76
  const bc = getBeforeClose() || props().beforeClose;
53
77
  if (!bc || bc(that.close))
54
- that.close(e);
78
+ that.close();
55
79
  };
56
80
 
57
81
  const shouldClose = (e) => {
58
- const isSameModal = __style(el()).zIndex == zIndex - 1;
59
- !(e && content().contains(__target(e))) && isSameModal && beforeClose(e);
82
+ const isSameModal = el().style.zIndex == (zIndex - 1) + '';
83
+ !(e && content().contains(e.target)) && isSameModal && beforeClose(e);
60
84
  };
61
85
 
62
86
  const addTransitionListener = () => {
@@ -64,11 +88,11 @@ class Modal extends PureComponent {
64
88
  let listener = () => {
65
89
  removeEventListener(overlay(), transitionend, listener);
66
90
  orNoop(isShow() ? props().onOpen : orNoop(props().onClose))();
67
- el() && (__style(el()).paddingBottom = isShow() ? '1px' : '0px'); // force invalidate scroll
91
+ el() && (el().style.paddingBottom = isShow() ? '1px' : '0px'); // force invalidate scroll
68
92
  };
69
93
  addEventListener(overlay(), transitionend, listener);
70
94
  };
71
- that[ReactConstants[3]] = () => {
95
+ that[render] = () => {
72
96
  const {className, top, container = Modal.defaultContainer, children, closeIcon} = props();
73
97
  const menu = getMenu();
74
98
  const show = isShow();
@@ -79,10 +103,13 @@ class Modal extends PureComponent {
79
103
  style={top && {top: top + 'px'}}
80
104
  ref={content}
81
105
  >
82
- {React.Children.map(children, child => React.cloneElement(child, {
83
- modalMenuConsumer: getMenu,
84
- modalBeforeCloseConsumer: getBeforeClose
85
- }))}
106
+ {React.Children.map(children, child => {
107
+ // @ts-ignore
108
+ return React.cloneElement(child, {
109
+ modalMenuConsumer: getMenu,
110
+ modalBeforeCloseConsumer: getBeforeClose
111
+ });
112
+ })}
86
113
  {menu}
87
114
  <Button className="close" flat={true} round={true} onClick={beforeClose}>
88
115
  {closeIcon}
@@ -107,20 +134,20 @@ class Modal extends PureComponent {
107
134
  if (isShow())
108
135
  return;
109
136
 
110
- el() && (__style(el()).zIndex = zIndex++);
137
+ el() && (el().style.zIndex = '' + (zIndex++));
111
138
  addTransitionListener();
112
139
  isShow(true);
113
140
 
114
141
  let listener = event => {
115
142
  if (!event.defaultPrevented && event.keyCode === 27/*escape*/)
116
- beforeClose();
143
+ beforeClose(event);
117
144
  return true;
118
145
  };
119
146
 
120
147
  addListener(that, listener)
121
148
  };
122
149
 
123
- that[ReactConstants[0]] = () => {
150
+ that[componentDidMount] = () => {
124
151
  const _props = props();
125
152
  orNoop(_props.open)(() => {
126
153
  setTimeout(open, 0);
@@ -130,7 +157,7 @@ class Modal extends PureComponent {
130
157
  });
131
158
  _props.show && setTimeout(open, 0)
132
159
  };
133
- that[ReactConstants[2]] = (prevProps) => {
160
+ that[componentDidUpdate] = (prevProps) => {
134
161
  const show = props().show;
135
162
  if (show !== prevProps.show) {
136
163
  show ? open() : close();
@@ -139,16 +166,4 @@ class Modal extends PureComponent {
139
166
  }
140
167
  }
141
168
 
142
- Modal.defaultContainer = UNDEFINED;
143
- Modal.pollListener = pollListener;
144
- Modal.addListener = addListener;
145
-
146
- export default Modal;
147
-
148
- if (process.env.NODE_ENV !== 'production') {
149
- Modal.propTypes = {
150
- [ReactConstants[5]]: PropTypes.string,
151
- top: PropTypes.number,
152
- container: PropTypes.node,
153
- };
154
- }
169
+ export default Modal;
@@ -11,7 +11,9 @@ export const setState = (that: React.Component, data, cb?) => {
11
11
  export const stateFieldSetter = (that, key, cb?: () => void) => (value, cb2?) => {
12
12
  setState(that, {[key]: value}, cb2 || cb);
13
13
  };
14
- export const stateGS: (<T>(that: React.Component) => (v?: T, cb?: () => void) => T) = (that) => {
14
+
15
+ type GetterSetter<T> = (v?: T, cb?: () => void) => T;
16
+ export const stateGS: (<T>(that: React.Component) => GetterSetter<T>) = (that) => {
15
17
  !that['sfc'] && (that['sfc'] = 0);
16
18
  const key = '_' + (that['sfc']++);
17
19
  const setter = stateFieldSetter(that, key);
@@ -21,12 +23,16 @@ export const stateGS: (<T>(that: React.Component) => (v?: T, cb?: () => void) =>
21
23
  result.toString = () => key;
22
24
  return result;
23
25
  };
24
- export const stateGSs = (that, num) => {
26
+
27
+ type TupleToGetterSetter<T extends any[]> = {
28
+ [K in keyof T]: GetterSetter<T[K]>;
29
+ };
30
+ export const stateGSs = <T extends any[]>(that, num): TupleToGetterSetter<T> => {
25
31
  const result = [];
26
32
  for (let i = 0; i < num; i++) {
27
33
  result.push(stateGS(that));
28
34
  }
29
- return result;
35
+ return result as TupleToGetterSetter<T>;
30
36
  };
31
37
 
32
38
  type GetSnapshot<T> = () => T;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+
3
+ export default React.createElement;
@@ -0,0 +1,58 @@
1
+ import React, {ReactNode} from 'react';
2
+ import ReactCreateElement from './ReactCreateElement';
3
+ import {componentDidMount, render, componentWillUnmount, setState, props, state, componentDidUpdate, children, PureComponent} from "./ReactConstants";
4
+ import {orNoop} from "./Tools";
5
+
6
+ export interface NotReadyIndicatorProps {
7
+ onChange?: (ready: boolean) => void
8
+ render?: (ready: boolean) => JSX.Element | ReactNode
9
+ children?: ReactNode
10
+ }
11
+
12
+ interface NotReadyIndicatorState {
13
+ r: boolean
14
+ }
15
+
16
+ export const createReadyListener = () => {
17
+ let indicator,
18
+ count = 0;
19
+
20
+ class NotReadyIndicator extends PureComponent<NotReadyIndicatorProps, NotReadyIndicatorState> {
21
+ constructor(properties) {
22
+ super(properties);
23
+ const that = this;
24
+ that.state = {r: true};
25
+ indicator = that;
26
+ that[render] = () => {
27
+ const _props = props(that),
28
+ renderer = _props[render],
29
+ ready = state(that).r;
30
+
31
+ if (renderer)
32
+ return renderer(ready);
33
+ else
34
+ return (!ready && _props[children]) || null;
35
+ };
36
+ that[componentDidMount] = that[componentDidUpdate] = () => {
37
+ orNoop(props(that).onChange)(state(that).r);
38
+ }
39
+ }
40
+ }
41
+
42
+ class NotReady extends PureComponent {
43
+ constructor(props) {
44
+ super(props);
45
+ const that = this;
46
+ that[componentDidMount] = () => {
47
+ count++;
48
+ setState(indicator, {r: false});
49
+ };
50
+ that[componentWillUnmount] = () => {
51
+ setState(indicator, {r: --count === 0});
52
+ };
53
+ that[render] = () => null;
54
+ }
55
+ }
56
+
57
+ return [NotReadyIndicator, NotReady]
58
+ };
@@ -16,7 +16,6 @@
16
16
  overflow-y: scroll;
17
17
  overflow-x: scroll;
18
18
  max-height: 100%;
19
- scroll-behavior: smooth;
20
19
  scrollbar-width: none;
21
20
  }
22
21
  .Scrollable .viewport::-webkit-scrollbar {
@@ -17,7 +17,6 @@
17
17
  overflow-y: scroll;
18
18
  overflow-x: scroll;
19
19
  max-height: 100%;
20
- scroll-behavior: smooth;
21
20
 
22
21
  scrollbar-width: none;
23
22
 
@@ -1,4 +1,4 @@
1
- import ReactConstants from "./../ReactConstants"; 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"; import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers"; import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers"; import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers"; import './Scrollable.css'; import React from 'react';
1
+ import React, {CSSProperties, ReactNode} from 'react';
2
2
  import ReactCreateElement from './ReactCreateElement';
3
3
  import PropTypes from 'prop-types';
4
4
  import './Scrollable.css'
@@ -40,7 +40,32 @@ const scrollBarModeOf = createFieldGetter('scrollBarMode');
40
40
  const onScroll = createFieldGetter('onScroll');
41
41
  const horizontalScrollBarModeOf = createFieldGetter('horizontalScrollBarMode');
42
42
 
43
- class Scrollable extends PureComponent {
43
+ type ScrollbarMode = typeof SCROLLBAR_MODE_HIDDEN | typeof SCROLLBAR_MODE_VISIBLE | typeof SCROLLBAR_MODE_AUTO | typeof SCROLLBAR_RESIZE_DISABLED;
44
+
45
+ export interface ScrollableProps {
46
+ scrollBarMode?: ScrollbarMode
47
+ horizontalScrollBarMode?: ScrollbarMode
48
+ className?: string
49
+ style?: CSSProperties
50
+ onScrolledToBottom?: () => void
51
+ onScrolledToTop?: () => void
52
+ autoScrollTop?: boolean
53
+ children?: ReactNode
54
+ }
55
+
56
+ abstract class AbstractScrollable extends PureComponent<ScrollableProps> {
57
+ el: HTMLDivElement
58
+ setScroll: (y) => void
59
+ getScroll: () => number
60
+ getScrollHeight: () => number
61
+ getHeight: () => number
62
+ }
63
+
64
+ class Scrollable extends AbstractScrollable {
65
+ static defaultProps = {
66
+ autoScrollTop: true,
67
+ horizontalScrollBarMode: SCROLLBAR_MODE_HIDDEN
68
+ }
44
69
 
45
70
  constructor(properties) {
46
71
  super(properties);
@@ -48,14 +73,14 @@ class Scrollable extends PureComponent {
48
73
  that.state = {};
49
74
 
50
75
  const props = propsGetter(that);
51
- const status = stateGS(that);
52
- const statusH = stateGS(that);
76
+ const status = stateGS<typeof WITHOUT_SCROLL | typeof WITH_SCROLL>(that);
77
+ const statusH = stateGS<typeof WITHOUT_SCROLL | typeof WITH_SCROLL>(that);
53
78
 
54
- const viewportRef = createRef();
55
- const scrollbarRef = createRef();
56
- const horizontalScrollbarRef = createRef();
57
- const thumbRef = createRef();
58
- const horizontalThumbRef = createRef();
79
+ const viewportRef = createRef<HTMLDivElement>();
80
+ const scrollbarRef = createRef<HTMLDivElement>();
81
+ const horizontalScrollbarRef = createRef<HTMLDivElement>();
82
+ const thumbRef = createRef<HTMLDivElement>();
83
+ const horizontalThumbRef = createRef<HTMLDivElement>();
59
84
 
60
85
  let resizeInterval;
61
86
  let initTimeout;
@@ -81,7 +106,7 @@ class Scrollable extends PureComponent {
81
106
  const thumb = thumbRef();
82
107
  const thumbH = horizontalThumbRef();
83
108
 
84
- let scrolling = false;
109
+ let scrolling = '';
85
110
  let scrolledToBottom = false;
86
111
  let scrolledToTop = false;
87
112
  let adjustedScrollWidth = false;
@@ -98,8 +123,8 @@ class Scrollable extends PureComponent {
98
123
  const offsetWidth = offsetWidthOf(viewport);
99
124
  const scrollbarHeight = offsetHeightOf(scrollbar);
100
125
  const scrollbarWidth = offsetWidthOf(scrollbarH);
101
- let position = __scrollTop(viewport) / (scrollHeight - offsetHeight);
102
- const positionH = __scrollLeft(viewport) / (scrollWidth - offsetWidth);
126
+ let position = viewport.scrollTop / (scrollHeight - offsetHeight);
127
+ const positionH = viewport.scrollLeft / (scrollWidth - offsetWidth);
103
128
 
104
129
  if (position > 1) {
105
130
  viewport.scrollTop = scrollHeight - offsetHeight;
@@ -128,8 +153,8 @@ class Scrollable extends PureComponent {
128
153
  const reset = () => {
129
154
  removeEventListener(WINDOW, 'mouseup', reset);
130
155
  removeEventListener(WINDOW, 'mousemove', moveListener);
131
- __style(viewport).scrollBehavior = ''
132
- scrolling = false;
156
+ viewport.style.scrollBehavior = ''
157
+ scrolling = '';
133
158
  };
134
159
  const moveListener = (e) => {
135
160
  if (!scrolling)
@@ -147,7 +172,7 @@ class Scrollable extends PureComponent {
147
172
  lastY = e.clientY;
148
173
  scrolling = 'v';
149
174
  ratio = scrollHeightOf(viewport) / offsetHeightOf(viewport);
150
- __style(viewport).scrollBehavior = 'unset'
175
+ viewport.style.scrollBehavior = 'unset'
151
176
 
152
177
  addEventListener(WINDOW, 'mouseup', reset);
153
178
  addEventListener(WINDOW, 'mousemove', moveListener);
@@ -159,7 +184,7 @@ class Scrollable extends PureComponent {
159
184
  lastX = e.clientX;
160
185
  scrolling = 'h';
161
186
  ratioH = scrollWidthOf(viewport) / offsetWidthOf(viewport);
162
- __style(viewport).scrollBehavior = 'unset'
187
+ viewport.style.scrollBehavior = 'unset'
163
188
 
164
189
  addEventListener(WINDOW, 'mouseup', reset);
165
190
  addEventListener(WINDOW, 'mousemove', moveListener);
@@ -168,27 +193,27 @@ class Scrollable extends PureComponent {
168
193
  thumbH.onmouseup = reset;
169
194
 
170
195
  scrollbar.onclick = (e) => {
171
- if (__target(e) === scrollbar) {
172
- let thumbPosition = parseInt(__top(styleOf(thumb)));
196
+ if (e.target === scrollbar) {
197
+ let thumbPosition = parseInt(styleOf(thumb).top);
173
198
  viewport.scrollTop += offsetHeightOf(viewport) * 0.9 * (e.offsetY < thumbPosition ? -1 : 1);
174
199
  }
175
200
  };
176
201
  scrollbarH.onclick = (e) => {
177
- if (__target(e) === scrollbarH) {
178
- let thumbPosition = parseInt(__left(styleOf(thumbH)));
202
+ if (e.target === scrollbarH) {
203
+ let thumbPosition = parseInt(styleOf(thumbH).left);
179
204
  viewport.scrollLeft += offsetWidthOf(viewport) * 0.9 * (e.offsetX < thumbPosition ? -1 : 1);
180
205
  }
181
206
  };
182
207
 
183
208
  const adjustScrollWidth = () => {
184
209
  if (NATIVE_SCROLL_WIDTH < 0) {
185
- NATIVE_SCROLL_WIDTH = viewport.offsetWidth - __clientWidth(viewport);
210
+ NATIVE_SCROLL_WIDTH = viewport.offsetWidth - viewport.clientWidth;
186
211
  if (NATIVE_SCROLL_WIDTH === 0 && scrollHeightOf(viewport) !== offsetHeightOf(viewport)) {
187
212
  NATIVE_SCROLL_WIDTH = -1;
188
213
  }
189
214
  }
190
215
  if (NATIVE_SCROLL_HEIGHT < 0) {
191
- NATIVE_SCROLL_HEIGHT = viewport.offsetHeight - __clientHeight(viewport);
216
+ NATIVE_SCROLL_HEIGHT = viewport.offsetHeight - viewport.clientHeight;
192
217
  if (NATIVE_SCROLL_HEIGHT === 0 && scrollWidthOf(viewport) !== offsetWidthOf(viewport)) {
193
218
  NATIVE_SCROLL_HEIGHT = -1;
194
219
  }
@@ -196,12 +221,12 @@ class Scrollable extends PureComponent {
196
221
 
197
222
  if (!adjustedScrollWidth) {
198
223
  if (NATIVE_SCROLL_WIDTH >= 0 && status() !== WITHOUT_SCROLL) {
199
- styleOf(viewport).paddingRight = (NATIVE_SCROLL_WIDTH) + __clientWidth(scrollbar) + 'px';
200
- styleOf(viewport).marginRight = -(NATIVE_SCROLL_WIDTH) - __clientWidth(scrollbar) + 'px';
224
+ styleOf(viewport).paddingRight = (NATIVE_SCROLL_WIDTH) + scrollbar.clientWidth + 'px';
225
+ styleOf(viewport).marginRight = -(NATIVE_SCROLL_WIDTH) - scrollbar.clientWidth + 'px';
201
226
  }
202
227
  if (NATIVE_SCROLL_HEIGHT >= 0 && statusH() !== WITHOUT_SCROLL) {
203
- styleOf(viewport).paddingBottom = (NATIVE_SCROLL_HEIGHT) + __clientHeight(scrollbarH) + 'px';
204
- styleOf(viewport).marginBottom = -(NATIVE_SCROLL_HEIGHT) - __clientHeight(scrollbarH) + 'px';
228
+ styleOf(viewport).paddingBottom = (NATIVE_SCROLL_HEIGHT) + scrollbarH.clientHeight + 'px';
229
+ styleOf(viewport).marginBottom = -(NATIVE_SCROLL_HEIGHT) - scrollbarH.clientHeight + 'px';
205
230
  }
206
231
  adjustedScrollWidth = true;
207
232
  }
@@ -249,16 +274,18 @@ class Scrollable extends PureComponent {
249
274
  !adjustedScrollWidth && adjustScrollWidth();
250
275
 
251
276
  const newRatio = scrollHeight / scrollbarHeight;
252
- if (!containerHeight || (ratio === newRatio && Number.isFinite(newRatio)) || Number.isNaN(newRatio)) return;
277
+ if ((ratio === newRatio && Number.isFinite(newRatio)) || Number.isNaN(newRatio)) return;
253
278
 
254
279
  const offsetHeight = offsetHeightOf(viewport);
255
- const horizontalScrollBarOffset = statusH() !== WITHOUT_SCROLL ? __clientHeight(scrollbarH) + Math.max(NATIVE_SCROLL_HEIGHT, 0) : 0;
280
+ const horizontalScrollBarOffset = statusH() !== WITHOUT_SCROLL ? scrollbarH.clientHeight + Math.max(NATIVE_SCROLL_HEIGHT, 0) : 0;
256
281
 
257
282
  let containerOffsetHeight = containerHeight + horizontalScrollBarOffset;
258
- if (containerOffsetHeight > scrollHeight && status() === WITHOUT_SCROLL)
283
+ if (containerOffsetHeight === scrollHeight && status() === WITHOUT_SCROLL) {
284
+ ratio = newRatio;
259
285
  return;
286
+ }
260
287
 
261
- if (props().autoScrollTop && scrollHeight - offsetHeight - __scrollTop(viewport) <= 20 && newRatio < ratio && Number.isFinite(newRatio) && Number.isFinite(ratio)) {
288
+ if (props().autoScrollTop && scrollHeight - offsetHeight - viewport.scrollTop <= 20 && newRatio < ratio && Number.isFinite(newRatio) && Number.isFinite(ratio)) {
262
289
  viewport.scrollTop = 0; // scroll to top if scrollbar gets smaller
263
290
  }
264
291
 
@@ -276,7 +303,7 @@ class Scrollable extends PureComponent {
276
303
  return
277
304
  }
278
305
 
279
- if (containerOffsetHeight <= scrollHeight) {
306
+ if (containerOffsetHeight < scrollHeight) {
280
307
  adjustedScrollWidth = false;
281
308
  showScrollbar(scrollbar, viewport, adjustScrollWidth);
282
309
  } else {
@@ -286,7 +313,7 @@ class Scrollable extends PureComponent {
286
313
  scrolledToBottom = false;
287
314
  scrolledToTop = false;
288
315
 
289
- const position = __scrollTop(viewport) / (scrollHeight - offsetHeight);
316
+ const position = viewport.scrollTop / (scrollHeight - offsetHeight);
290
317
  styleOf(thumb).top = (position * (scrollbarHeight - offsetHeightOf(thumb))) + 'px';
291
318
  };
292
319
 
@@ -298,16 +325,16 @@ class Scrollable extends PureComponent {
298
325
  !adjustedScrollWidth && adjustScrollWidth();
299
326
 
300
327
  const newRatio = scrollWidth / scrollbarWidth;
301
- if (!containerWidth || (ratioH === newRatio && Number.isFinite(newRatio)) || Number.isNaN(newRatio)) return;
328
+ if ((ratioH === newRatio && Number.isFinite(newRatio)) || Number.isNaN(newRatio)) return;
302
329
 
303
330
  const offsetWidth = offsetWidthOf(viewport);
304
- const verticalScrollBarOffset = status() !== WITHOUT_SCROLL ? __clientWidth(scrollbar) + Math.max(NATIVE_SCROLL_WIDTH, 0) : 0;
331
+ const verticalScrollBarOffset = status() !== WITHOUT_SCROLL ? scrollbar.clientWidth + Math.max(NATIVE_SCROLL_WIDTH, 0) : 0;
305
332
 
333
+ ratioH = newRatio;
306
334
  let containerOffsetWidth = containerWidth + verticalScrollBarOffset;
307
- if (containerOffsetWidth > scrollWidth && statusH() === WITHOUT_SCROLL)
335
+ if (containerOffsetWidth === scrollWidth && statusH() === WITHOUT_SCROLL)
308
336
  return;
309
337
 
310
- ratioH = newRatio;
311
338
  if (newRatio > 1.02)
312
339
  styleOf(thumbH).width = (scrollbarWidth / newRatio) + 'px';
313
340
 
@@ -322,21 +349,21 @@ class Scrollable extends PureComponent {
322
349
  styleOf(container).width = (scrollWidth - verticalScrollBarOffset) + 'px';
323
350
  containerOffsetWidth = containerWidth + verticalScrollBarOffset;
324
351
 
325
- if (containerOffsetWidth <= scrollWidth) {
352
+ if (containerOffsetWidth < scrollWidth) {
326
353
  adjustedScrollWidth = false;
327
354
  showHorizontalScrollbar(scrollbarH, viewport, adjustScrollWidth);
328
355
  } else {
329
356
  hideHorizontalScrollbar(scrollbarH, viewport);
330
357
  }
331
358
 
332
- const position = __scrollLeft(viewport) / (scrollWidth - offsetWidth);
359
+ const position = viewport.scrollLeft / (scrollWidth - offsetWidth);
333
360
  styleOf(thumbH).left = (position * (scrollbarWidth - offsetWidthOf(thumbH))) + 'px';
334
361
  };
335
362
 
336
363
  let update;
337
364
  let sbm = scrollBarModeOf(props());
338
365
  let hsbm = horizontalScrollBarModeOf(props());
339
- if (sbm !== SCROLLBAR_RESIZE_DISABLED && !hsbm === SCROLLBAR_RESIZE_DISABLED) {
366
+ if (sbm !== SCROLLBAR_RESIZE_DISABLED && hsbm !== SCROLLBAR_RESIZE_DISABLED) {
340
367
  update = () => {
341
368
  updateVerticalScrollbar();
342
369
  updateHorizontalScrollbar();
@@ -348,15 +375,15 @@ class Scrollable extends PureComponent {
348
375
 
349
376
  if (update) {
350
377
  initTimeout = setTimeout(() => {
351
- resizeInterval = setInterval(update, 50);
378
+ resizeInterval = setInterval(update, 16);
352
379
  }, 200)
353
380
  }
354
381
  };
355
382
 
356
- that[ReactConstants[0]] = init;
357
- that[ReactConstants[1]] = clear;
383
+ that[componentDidMount] = init;
384
+ that[componentWillUnmount] = clear;
358
385
 
359
- that[ReactConstants[2]] = (prevProps) => {
386
+ that[componentDidUpdate] = (prevProps) => {
360
387
  if (scrollBarModeOf(props()) !== scrollBarModeOf(prevProps))
361
388
  init();
362
389
  else if (onScroll(props()) !== onScroll(prevProps))
@@ -366,15 +393,19 @@ class Scrollable extends PureComponent {
366
393
  that.setScroll = (y) => {
367
394
  viewportRef().scrollTop = y
368
395
  };
369
- that.getScroll = () => __scrollTop(viewportRef());
396
+ that.getScroll = () => viewportRef().scrollTop;
370
397
  that.getScrollHeight = () => scrollHeightOf(viewportRef());
371
398
  that.getHeight = () => that.el.clientHeight;
372
399
 
373
- that[ReactConstants[3]] = () => {
400
+ that[render] = () => {
374
401
  const _props = props();
375
402
  const {className, children} = _props;
403
+
376
404
  return (
377
- <div className={classNames('Scrollable', className, status() || WITH_SCROLL, statusH() + '-horizontal')} style={styleOf(_props)} ref={ref('el', this)}>
405
+ <div className={classNames('Scrollable', className, status() || WITH_SCROLL, statusH() + '-horizontal')}
406
+ style={styleOf(_props)}
407
+ ref={ref('el', this)}
408
+ >
378
409
  <div className="viewport" ref={viewportRef}>
379
410
  {children}
380
411
  </div>
@@ -390,21 +421,4 @@ class Scrollable extends PureComponent {
390
421
  }
391
422
  }
392
423
 
393
- export default Scrollable
394
-
395
- Scrollable.defaultProps = {
396
- autoScrollTop: true,
397
- horizontalScrollBarMode: SCROLLBAR_MODE_HIDDEN
398
- };
399
-
400
- if (process.env.NODE_ENV !== 'production') {
401
- Scrollable.propTypes = {
402
- scrollBarMode: PropTypes.oneOf([SCROLLBAR_MODE_AUTO, SCROLLBAR_MODE_HIDDEN, SCROLLBAR_MODE_VISIBLE, SCROLLBAR_RESIZE_DISABLED]),
403
- horizontalScrollBarMode: PropTypes.oneOf([SCROLLBAR_MODE_AUTO, SCROLLBAR_MODE_HIDDEN, SCROLLBAR_MODE_VISIBLE, SCROLLBAR_RESIZE_DISABLED]),
404
- [ReactConstants[5]]: PropTypes.string,
405
- style: PropTypes.object,
406
- onScrolledToBottom: PropTypes.func,
407
- onScrolledToTop: PropTypes.func,
408
- autoScrollTop: PropTypes.bool,
409
- }
410
- }
424
+ export default Scrollable
@@ -1,3 +0,0 @@
1
- import ReactConstants from "./../ReactConstants"; 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"; import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers"; import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers"; import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers"; import React from 'react';
2
-
3
- export default React.createElement;
@@ -1,48 +0,0 @@
1
- import ReactConstants from "./../ReactConstants"; 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"; import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers"; import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers"; import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers"; import React from 'react';
2
- import ReactCreateElement from './ReactCreateElement';
3
- import {componentDidMount, render, componentWillUnmount, setState, props, state, componentDidUpdate, children, PureComponent} from "./ReactConstants";
4
- import {orNoop} from "./Tools";
5
-
6
- export const createReadyListener = () => {
7
- let indicator,
8
- count = 0;
9
-
10
- class NotReadyIndicator extends PureComponent {
11
- constructor(properties) {
12
- super(properties);
13
- const that = this;
14
- that.state = {r: true};
15
- indicator = that;
16
- that[ReactConstants[3]] = () => {
17
- const _props = props(that),
18
- renderer = _props[ReactConstants[3]],
19
- ready = state(that).r;
20
-
21
- if (renderer)
22
- return renderer(ready);
23
- else
24
- return (!ready && _props[ReactConstants[4]]) || null;
25
- };
26
- that[ReactConstants[0]] = that[ReactConstants[2]] = () => {
27
- orNoop(props(that)[ReactConstants[7]])(state(that).r);
28
- }
29
- }
30
- }
31
-
32
- class NotReady extends PureComponent {
33
- constructor(props) {
34
- super(props);
35
- const that = this;
36
- that[ReactConstants[0]] = () => {
37
- count++;
38
- setState(indicator, {r: false});
39
- };
40
- that[ReactConstants[1]] = () => {
41
- setState(indicator, {r: --count === 0});
42
- };
43
- that[ReactConstants[3]] = () => null;
44
- }
45
- }
46
-
47
- return [NotReadyIndicator, NotReady]
48
- };