react-ui-basics 0.0.175 → 0.0.178
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/Animated.js.map +1 -1
- package/AutocompleteSelect.js.map +1 -1
- package/Button.js.map +1 -1
- package/CalendarMonthView.css +20 -0
- package/CalendarMonthView.d.ts +12 -0
- package/CalendarMonthView.js +52 -0
- package/CalendarMonthView.js.map +1 -0
- package/Checkbox.js.map +1 -1
- package/CircleProgress.js.map +1 -1
- package/CommonFields.js.map +1 -1
- package/DNDContainer.js.map +1 -1
- package/DNDDraggable.js.map +1 -1
- package/DNDDroppable.js.map +1 -1
- package/DatePicker.css +93 -0
- package/DatePicker.d.ts +32 -0
- package/DatePicker.js +116 -0
- package/DatePicker.js.map +1 -0
- package/DateTools.d.ts +39 -0
- package/DateTools.js +73 -0
- package/DateTools.js.map +1 -0
- package/Dialog.js.map +1 -1
- package/DropFileInput.js.map +1 -1
- package/DroppableHorizontalList.js.map +1 -1
- package/DroppableList.js.map +1 -1
- package/Dropzone.js.map +1 -1
- package/FilteredList.js.map +1 -1
- package/FloatingActionButton.js.map +1 -1
- package/FormUploadProgress.js.map +1 -1
- package/ImageGallery.js.map +1 -1
- package/MaterialIcon.js.map +1 -1
- package/Modal.js.map +1 -1
- package/ModalMenu.js.map +1 -1
- package/ReactConstants.js.map +1 -1
- package/ReactCreateElement.js.map +1 -1
- package/ReadyListener.js.map +1 -1
- package/Scrollable.js.map +1 -1
- package/ScrollableTable.js.map +1 -1
- package/Size.js.map +1 -1
- package/Snackbar.js.map +1 -1
- package/SpinningProgress.js.map +1 -1
- package/Switch.js.map +1 -1
- package/Table.js.map +1 -1
- package/Tabs.css +65 -0
- package/Tabs.d.ts +22 -0
- package/TextField.js.map +1 -1
- package/Tools.d.ts +2 -2
- package/Tools.js.map +1 -1
- package/bundle.css +726 -587
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/router/HistoryTools.js.map +1 -1
- package/router/Link.js.map +1 -1
- package/router/NavLink.js.map +1 -1
- package/router/Route.js.map +1 -1
- package/router/index.js.map +1 -1
- package/src/Animated.css +7 -0
- package/src/Animated.js +219 -0
- package/src/Animated.scss +8 -0
- package/src/AutocompleteSelect.css +256 -0
- package/src/AutocompleteSelect.js +473 -0
- package/src/AutocompleteSelect.scss +322 -0
- package/src/Button.css +138 -0
- package/src/Button.js +104 -0
- package/src/Button.scss +177 -0
- package/src/CalendarMonthView.css +20 -0
- package/src/CalendarMonthView.scss +25 -0
- package/src/CalendarMonthView.tsx +80 -0
- package/src/Checkbox.css +56 -0
- package/src/Checkbox.js +52 -0
- package/src/Checkbox.scss +87 -0
- package/src/CircleProgress.css +11 -0
- package/src/CircleProgress.js +38 -0
- package/src/CircleProgress.scss +13 -0
- package/src/CommonFields.js +21 -0
- package/src/DNDContainer.css +26 -0
- package/src/DNDContainer.js +263 -0
- package/src/DNDContainer.scss +33 -0
- package/src/DNDDraggable.js +55 -0
- package/src/DNDDroppable.js +58 -0
- package/src/DatePicker.css +93 -0
- package/src/DatePicker.scss +118 -0
- package/src/DatePicker.tsx +179 -0
- package/src/DateTools.ts +85 -0
- package/src/Dialog.css +36 -0
- package/src/Dialog.js +160 -0
- package/src/Dialog.scss +42 -0
- package/src/DropFileInput.css +24 -0
- package/src/DropFileInput.js +45 -0
- package/src/DropFileInput.scss +28 -0
- package/src/DroppableHorizontalList.js +190 -0
- package/src/DroppableList.css +14 -0
- package/src/DroppableList.js +201 -0
- package/src/DroppableList.scss +27 -0
- package/src/Dropzone.css +54 -0
- package/src/Dropzone.js +140 -0
- package/src/Dropzone.scss +66 -0
- package/src/FilteredList.css +68 -0
- package/src/FilteredList.js +196 -0
- package/src/FilteredList.scss +86 -0
- package/src/FloatingActionButton.css +20 -0
- package/src/FloatingActionButton.js +35 -0
- package/src/FloatingActionButton.scss +25 -0
- package/src/FormUploadProgress.css +61 -0
- package/src/FormUploadProgress.js +87 -0
- package/src/FormUploadProgress.scss +78 -0
- package/src/ImageGallery.css +196 -0
- package/src/ImageGallery.js +935 -0
- package/src/ImageGallery.scss +256 -0
- package/src/MaterialIcon.js +1837 -0
- package/src/Modal.css +61 -0
- package/src/Modal.js +160 -0
- package/src/Modal.scss +73 -0
- package/src/ModalMenu.css +30 -0
- package/src/ModalMenu.js +59 -0
- package/src/ModalMenu.scss +36 -0
- package/src/ReactConstants.ts +42 -0
- package/src/ReactCreateElement.js +5 -0
- package/src/ReadyListener.js +53 -0
- package/src/ResizeObserver.ts +50 -0
- package/src/Scrollable.css +80 -0
- package/src/Scrollable.js +388 -0
- package/src/Scrollable.scss +100 -0
- package/src/ScrollableTable.css +6 -0
- package/src/ScrollableTable.scss +12 -0
- package/src/ScrollableTable.tsx +39 -0
- package/src/Size.js +56 -0
- package/src/Snackbar.css +40 -0
- package/src/Snackbar.js +71 -0
- package/src/Snackbar.scss +47 -0
- package/src/SpinningProgress.css +49 -0
- package/src/SpinningProgress.js +19 -0
- package/src/SpinningProgress.scss +57 -0
- package/src/Switch.css +69 -0
- package/src/Switch.js +54 -0
- package/src/Switch.scss +73 -0
- package/src/Table.css +94 -0
- package/src/Table.scss +121 -0
- package/src/Table.tsx +360 -0
- package/src/Tabs.css +65 -0
- package/src/Tabs.scss +77 -0
- package/src/Tabs.tsx +63 -0
- package/src/TextField.css +122 -0
- package/src/TextField.js +162 -0
- package/src/TextField.scss +160 -0
- package/src/Tools.test.js +105 -0
- package/src/Tools.ts +231 -0
- package/src/global.css +1 -0
- package/src/global.scss +6 -0
- package/src/index.js +84 -0
- package/src/router/HistoryTools.js +32 -0
- package/src/router/Link.js +27 -0
- package/src/router/NavLink.js +25 -0
- package/src/router/README.md +55 -0
- package/src/router/Route.js +209 -0
- package/src/router/Route.test.js +139 -0
- package/src/router/index.js +14 -0
- package/src/store/ProxyTools.js +91 -0
- package/src/store/ProxyTools.test.js +97 -0
- package/src/store/Store.ts +91 -0
- package/store/ProxyTools.js.map +1 -1
- package/store/Store.js.map +1 -1
package/src/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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 Animated from "./Animated";
|
|
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 AutocompleteSelect from "./AutocompleteSelect";
|
|
8
|
+
import Button from "./Button";
|
|
9
|
+
import CalendarMonthView from "./CalendarMonthView";
|
|
10
|
+
import Checkbox from "./Checkbox";
|
|
11
|
+
import CircleProgress from "./CircleProgress";
|
|
12
|
+
import * as CommonFields from "./CommonFields";
|
|
13
|
+
import DatePicker from "./DatePicker";
|
|
14
|
+
import * as DateTools from "./DateTools";
|
|
15
|
+
import Dialog from "./Dialog";
|
|
16
|
+
import DNDContainer from "./DNDContainer";
|
|
17
|
+
import DNDDraggable from "./DNDDraggable";
|
|
18
|
+
import DNDDroppable from "./DNDDroppable";
|
|
19
|
+
import DropFileInput from "./DropFileInput";
|
|
20
|
+
import Dropzone from "./Dropzone";
|
|
21
|
+
import FilteredList from "./FilteredList";
|
|
22
|
+
import FloatingActionButton from "./FloatingActionButton";
|
|
23
|
+
import FormUploadProgress from "./FormUploadProgress";
|
|
24
|
+
import ImageGallery from "./ImageGallery";
|
|
25
|
+
import {ImageGalleryContainer} from "./ImageGallery";
|
|
26
|
+
import MaterialIcon from "./MaterialIcon";
|
|
27
|
+
import Modal from "./Modal";
|
|
28
|
+
import ModalMenu from "./ModalMenu";
|
|
29
|
+
import Router from "./router";
|
|
30
|
+
import Scrollable from "./Scrollable";
|
|
31
|
+
import Size from "./Size";
|
|
32
|
+
import Snackbar from "./Snackbar";
|
|
33
|
+
import SpinningProgress from "./SpinningProgress";
|
|
34
|
+
import Switch from "./Switch";
|
|
35
|
+
import ReactConstants from './ReactConstants'
|
|
36
|
+
import ReactCreateElement from './ReactCreateElement'
|
|
37
|
+
import * as ReadyListener from './ReadyListener'
|
|
38
|
+
import TextField from "./TextField";
|
|
39
|
+
import Table from "./Table";
|
|
40
|
+
import ScrollableTable from "./ScrollableTable";
|
|
41
|
+
import DroppableList from "./DroppableList";
|
|
42
|
+
import DroppableHorizontalList from "./DroppableHorizontalList";
|
|
43
|
+
import * as StoreTools from "./store/Store";
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
Animated,
|
|
47
|
+
AutocompleteSelect,
|
|
48
|
+
Button,
|
|
49
|
+
CalendarMonthView,
|
|
50
|
+
Checkbox,
|
|
51
|
+
CircleProgress,
|
|
52
|
+
CommonFields,
|
|
53
|
+
DatePicker,
|
|
54
|
+
DateTools,
|
|
55
|
+
Dialog,
|
|
56
|
+
DNDContainer,
|
|
57
|
+
DNDDraggable,
|
|
58
|
+
DNDDroppable,
|
|
59
|
+
DroppableList,
|
|
60
|
+
DroppableHorizontalList,
|
|
61
|
+
DropFileInput,
|
|
62
|
+
Dropzone,
|
|
63
|
+
FilteredList,
|
|
64
|
+
FloatingActionButton,
|
|
65
|
+
FormUploadProgress,
|
|
66
|
+
ImageGallery,
|
|
67
|
+
ImageGalleryContainer,
|
|
68
|
+
MaterialIcon,
|
|
69
|
+
Modal,
|
|
70
|
+
ModalMenu,
|
|
71
|
+
Router,
|
|
72
|
+
Scrollable,
|
|
73
|
+
ScrollableTable,
|
|
74
|
+
Size,
|
|
75
|
+
Snackbar,
|
|
76
|
+
SpinningProgress,
|
|
77
|
+
Switch,
|
|
78
|
+
ReactConstants,
|
|
79
|
+
ReactCreateElement,
|
|
80
|
+
ReadyListener,
|
|
81
|
+
Table,
|
|
82
|
+
TextField,
|
|
83
|
+
StoreTools,
|
|
84
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 {DOCUMENT, WINDOW} from "../Tools";
|
|
4
|
+
|
|
5
|
+
const history = WINDOW.history;
|
|
6
|
+
|
|
7
|
+
const events = ['pushState', 'replaceState'];
|
|
8
|
+
events.forEach(e => {
|
|
9
|
+
var original = history[e];
|
|
10
|
+
history[e] = function () {
|
|
11
|
+
original.apply(history, arguments);
|
|
12
|
+
fireEvent(e);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const fireEvent = (name) => {
|
|
17
|
+
const event = DOCUMENT.createEvent('Event');
|
|
18
|
+
event.initEvent(name, true, true);
|
|
19
|
+
WINDOW.dispatchEvent(event);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const pushLocation = (path) => path !== WINDOW.location.pathname && history[events[0]](null, null, path);
|
|
23
|
+
|
|
24
|
+
export const replaceLocation = (path) => history[events[1]](null, null, path);
|
|
25
|
+
|
|
26
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
27
|
+
// will be removed in production build
|
|
28
|
+
// needed only to prevent bundler to remove 'unused' functions
|
|
29
|
+
window['history-tools'] = {
|
|
30
|
+
replaceLocation
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 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 ReactCreateElement from '../ReactCreateElement';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import './HistoryTools'
|
|
10
|
+
import {pushLocation} from "./HistoryTools";
|
|
11
|
+
import {preventDefault} from "../Tools";
|
|
12
|
+
|
|
13
|
+
const Link = ({children, href, className}) =>
|
|
14
|
+
<a href={href} className={className} onClick={(e) => {
|
|
15
|
+
if (!e.ctrlKey) {
|
|
16
|
+
preventDefault(e);
|
|
17
|
+
pushLocation(href);
|
|
18
|
+
}
|
|
19
|
+
}}>{children}</a>;
|
|
20
|
+
|
|
21
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
22
|
+
Link.propTypes = {
|
|
23
|
+
href: PropTypes.string.isRequired,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default Link;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 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 ReactCreateElement from '../ReactCreateElement';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import './HistoryTools'
|
|
10
|
+
import Route from "./Route";
|
|
11
|
+
import Link from "./Link";
|
|
12
|
+
import {classNames} from "../Tools";
|
|
13
|
+
|
|
14
|
+
const NavLink = ({children, href, highlightPath, className, activeClassName}) =>
|
|
15
|
+
<Route path={highlightPath || href}
|
|
16
|
+
controller={matches => <Link href={href} className={classNames(className, matches && activeClassName)}>
|
|
17
|
+
{children}
|
|
18
|
+
</Link>}
|
|
19
|
+
/>;
|
|
20
|
+
|
|
21
|
+
if(process.env.NODE_ENV !== 'production') {
|
|
22
|
+
NavLink.propTypes = Link.propTypes;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default NavLink;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
# Router
|
|
3
|
+
|
|
4
|
+
#### Basic usage:
|
|
5
|
+
|
|
6
|
+
```javascript
|
|
7
|
+
const A = ()=> <div>A</div>;
|
|
8
|
+
<Route path="/a"> <A/> </Route>;
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
#### With variables:
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const AB = ({a, b})=> <div>{a} {b}</div>;
|
|
15
|
+
<Route path="/:a/:b"> <AB/> </Route>;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
#### With optional variables:
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const AB = ({a = 'a', b = 'b'})=> <div>{a} {b}</div>;
|
|
22
|
+
<Route path="/:a?/:b?"> <AB/> </Route>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
#### With not matcher:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const A = ()=> <div>A</div>;
|
|
29
|
+
const NotA = ()=> <div>not A</div>;
|
|
30
|
+
<div>
|
|
31
|
+
<Route path="/a"> <A/> </Route>
|
|
32
|
+
<Route path="/!a"> <NotA/> </Route>
|
|
33
|
+
</div>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### With any matcher:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const A = ()=> <div>A</div>;
|
|
40
|
+
<div>
|
|
41
|
+
<Route path="/*"> <A/> </Route>
|
|
42
|
+
</div>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### With nested routes:
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
const A = (a)=> <div>{a}</div>;
|
|
49
|
+
const Nested = ()=> <Route path="/*/:a"> <A/> </Route>;
|
|
50
|
+
|
|
51
|
+
<div>
|
|
52
|
+
<Route path="/nested/*"> <Nested/> </Route>
|
|
53
|
+
</div>
|
|
54
|
+
```
|
|
55
|
+
|
|
@@ -0,0 +1,209 @@
|
|
|
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 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 ReactCreateElement from '../ReactCreateElement';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import './HistoryTools'
|
|
10
|
+
import {allPropsExcept, isDifferent, orNoop, setOf, WINDOW, addEventListener, removeEventListener} from "../Tools";
|
|
11
|
+
import {componentDidUpdate, render, PureComponent, componentDidMount, componentWillUnmount, propsGetter, stateGSs, setState} from "../ReactConstants";
|
|
12
|
+
|
|
13
|
+
const historyEvents = ['popstate', 'pushState', 'replaceState'];
|
|
14
|
+
|
|
15
|
+
const cleanPath = (path) => {
|
|
16
|
+
if (__length(path) > 1 && path.lastIndexOf('/') === __length(path) - 1)
|
|
17
|
+
return path.substring(0, __length(path) - 1);
|
|
18
|
+
|
|
19
|
+
return path;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const createUrlMatcher = path => {
|
|
23
|
+
let matcher;
|
|
24
|
+
const segments = path.split('/');
|
|
25
|
+
const optionals = segments.map(it => it === '*' || it.indexOf('?') === __length(it) - 1);
|
|
26
|
+
const containsVariables = path.indexOf(':') !== -1;
|
|
27
|
+
const containsAnySegment = path.indexOf('*') !== -1;
|
|
28
|
+
const containsNot = path.indexOf('!') !== -1;
|
|
29
|
+
|
|
30
|
+
if (!containsAnySegment && !containsVariables && !containsNot) {
|
|
31
|
+
matcher = (p) => p === path
|
|
32
|
+
} else {
|
|
33
|
+
const endsWithAny = path.lastIndexOf('*') === __length(path) - 1;
|
|
34
|
+
const matchers = segments.map((segment, i) => {
|
|
35
|
+
let matcher;
|
|
36
|
+
const variableNameIndex = segment.indexOf(':');
|
|
37
|
+
if (segment === '*')
|
|
38
|
+
matcher = () => true;
|
|
39
|
+
else if (variableNameIndex !== -1) {
|
|
40
|
+
let variable = segment.substring(variableNameIndex + 1);
|
|
41
|
+
let regex = null
|
|
42
|
+
if (variable.indexOf('?') !== -1)
|
|
43
|
+
variable = variable.substring(0, variable.indexOf('?'));
|
|
44
|
+
if (variable.indexOf('(') !== -1) {
|
|
45
|
+
let regexStart = variable.indexOf('(');
|
|
46
|
+
regex = new RegExp(variable.substring(regexStart))
|
|
47
|
+
variable = variable.substring(0, regexStart);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const prefix = variableNameIndex && segment.substring(0, variableNameIndex);
|
|
51
|
+
matcher = (p, params) => {
|
|
52
|
+
if (regex && !!p && !p.match(regex))
|
|
53
|
+
return false
|
|
54
|
+
|
|
55
|
+
if (!p && !optionals[i])
|
|
56
|
+
return false;
|
|
57
|
+
if (prefix) {
|
|
58
|
+
if (p.indexOf(prefix) === 0)
|
|
59
|
+
p = p.substring(variableNameIndex);
|
|
60
|
+
else
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
params[variable] = p;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
} else if (segment.indexOf('!') === 0) {
|
|
68
|
+
const not = segment.substring(1);
|
|
69
|
+
matcher = (p) => p !== not;
|
|
70
|
+
} else
|
|
71
|
+
matcher = (p) => p === segment;
|
|
72
|
+
return matcher;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
matcher = (path, params) => {
|
|
76
|
+
const segments = path.split('/');
|
|
77
|
+
const length = Math.min(__length(matchers), __length(segments));
|
|
78
|
+
|
|
79
|
+
// only exact match if mapping not ends with *
|
|
80
|
+
if (!endsWithAny && __length(matchers) < __length(segments))
|
|
81
|
+
return false;
|
|
82
|
+
|
|
83
|
+
// check that each segment matches
|
|
84
|
+
for (let i = 0; i < length; i++) {
|
|
85
|
+
if (!matchers[i](segments[i], params))
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// check that all other segments are optional
|
|
90
|
+
for (let i = length; i < __length(optionals); i++) {
|
|
91
|
+
if (!optionals[i])
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return matcher
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const createUrlMatchers = path => {
|
|
102
|
+
if (Array.isArray(path)) {
|
|
103
|
+
const matchers = path.map(it => createUrlMatcher(it));
|
|
104
|
+
return (path, params) => {
|
|
105
|
+
for (let i = 0; i < __length(matchers); i++) {
|
|
106
|
+
let props = {};
|
|
107
|
+
if (matchers[i](path, props)) {
|
|
108
|
+
__extends(params, props);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
return createUrlMatcher(path);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const selfProps = setOf([
|
|
120
|
+
'children',
|
|
121
|
+
'path',
|
|
122
|
+
'controller',
|
|
123
|
+
'onToggle',
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
class Route extends PureComponent {
|
|
127
|
+
|
|
128
|
+
constructor(properties) {
|
|
129
|
+
super(properties);
|
|
130
|
+
const that = this;
|
|
131
|
+
that.state = {};
|
|
132
|
+
let matcher;
|
|
133
|
+
|
|
134
|
+
const props = propsGetter(that);
|
|
135
|
+
const [
|
|
136
|
+
isRendering,
|
|
137
|
+
paramsState,
|
|
138
|
+
mergedPropsState,
|
|
139
|
+
] = stateGSs(that, 3);
|
|
140
|
+
|
|
141
|
+
const process = () => {
|
|
142
|
+
let params = {};
|
|
143
|
+
let nextState = {};
|
|
144
|
+
let isMatching = matcher(cleanPath(WINDOW.location.pathname), params);
|
|
145
|
+
|
|
146
|
+
const toggle = isMatching !== isRendering();
|
|
147
|
+
toggle && (nextState[isRendering] = isMatching);
|
|
148
|
+
|
|
149
|
+
if (isDifferent(paramsState(), params)) {
|
|
150
|
+
nextState[mergedPropsState] = __extends(allPropsExcept(props(), selfProps), params);
|
|
151
|
+
nextState[paramsState] = params;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//set new state just once to avoid several renders
|
|
155
|
+
setState(that, nextState, () => {
|
|
156
|
+
toggle && orNoop(props().onToggle)(isMatching);
|
|
157
|
+
})
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
that[ReactConstants[2]] = (prevProps, prevState) => {
|
|
161
|
+
if (props() !== prevProps) {
|
|
162
|
+
let mergedProps = __extends(allPropsExcept(props(), selfProps), paramsState());
|
|
163
|
+
if (isDifferent(mergedProps, mergedPropsState()))
|
|
164
|
+
mergedPropsState(mergedProps);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
that[ReactConstants[3]] = () => {
|
|
169
|
+
const {children, controller} = props();
|
|
170
|
+
return (controller || DefaultController)(isRendering(), children, mergedPropsState());
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
that[ReactConstants[0]] = () => {
|
|
174
|
+
matcher = createUrlMatchers(props().path);
|
|
175
|
+
|
|
176
|
+
historyEvents.forEach(it => {
|
|
177
|
+
addEventListener(WINDOW, it, process);
|
|
178
|
+
});
|
|
179
|
+
process();
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
that[ReactConstants[1]] = () => {
|
|
183
|
+
historyEvents.forEach(it => {
|
|
184
|
+
removeEventListener(WINDOW, it, process);
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
191
|
+
Route.propTypes = {
|
|
192
|
+
path: PropTypes.oneOfType([
|
|
193
|
+
PropTypes.string,
|
|
194
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
195
|
+
]).isRequired,
|
|
196
|
+
controller: PropTypes.func,
|
|
197
|
+
onToggle: PropTypes.func,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const DefaultController = (matches, children, props) => {
|
|
202
|
+
if (!matches || !children) return null;
|
|
203
|
+
if (Object.keys(props).length > 0) {
|
|
204
|
+
return React.Children.map(children, child => React.cloneElement(child, props));
|
|
205
|
+
}
|
|
206
|
+
return children;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export default Route;
|
|
@@ -0,0 +1,139 @@
|
|
|
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 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 Route from "./Route";
|
|
8
|
+
import {mount} from 'enzyme';
|
|
9
|
+
import {pushLocation} from './HistoryTools'
|
|
10
|
+
|
|
11
|
+
it('renders exact path', () => {
|
|
12
|
+
pushLocation('/test');
|
|
13
|
+
expect(mount(<Route path="/test">
|
|
14
|
+
<div>test</div>
|
|
15
|
+
</Route>)).toContainReact(<div>test</div>);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('renders exact path with / on the end', () => {
|
|
19
|
+
pushLocation('/test/');
|
|
20
|
+
expect(mount(<Route path="/test">
|
|
21
|
+
<div>test</div>
|
|
22
|
+
</Route>)).toContainReact(<div>test</div>);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('renders not url', () => {
|
|
26
|
+
const wrapper = mount(<div>
|
|
27
|
+
<Route path="/!test">
|
|
28
|
+
not test
|
|
29
|
+
</Route>
|
|
30
|
+
<Route path="/test">
|
|
31
|
+
test
|
|
32
|
+
</Route>
|
|
33
|
+
</div>);
|
|
34
|
+
|
|
35
|
+
pushLocation('/');
|
|
36
|
+
expect(wrapper).toHaveHTML('<div>not test</div>');
|
|
37
|
+
|
|
38
|
+
pushLocation('/test');
|
|
39
|
+
expect(wrapper).toHaveHTML('<div>test</div>');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('do not render not matching url', () => {
|
|
43
|
+
pushLocation('/');
|
|
44
|
+
expect(mount(<Route path="/test">
|
|
45
|
+
<div>test</div>
|
|
46
|
+
</Route>)).not.toContainReact(<div>test</div>);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders /*', () => {
|
|
50
|
+
expect(mount(<Route path="/*">
|
|
51
|
+
<div>test</div>
|
|
52
|
+
</Route>)).toContainReact(<div>test</div>);
|
|
53
|
+
|
|
54
|
+
pushLocation('/test');
|
|
55
|
+
expect(mount(<Route path="/*">
|
|
56
|
+
<div>test</div>
|
|
57
|
+
</Route>)).toContainReact(<div>test</div>);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders path with variable', () => {
|
|
61
|
+
pushLocation('/test');
|
|
62
|
+
const WithVariable = ({id}) => <div>{id}</div>;
|
|
63
|
+
expect(mount(<Route path="/:id">
|
|
64
|
+
<WithVariable/>
|
|
65
|
+
</Route>)).toContainReact(<div>test</div>);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('do not render if require variable', () => {
|
|
69
|
+
pushLocation('/');
|
|
70
|
+
const WithVariable = ({id}) => <div>{id}</div>;
|
|
71
|
+
expect(mount(<div>
|
|
72
|
+
<Route path="/:id">
|
|
73
|
+
<WithVariable/>
|
|
74
|
+
</Route>
|
|
75
|
+
</div>)).toHaveHTML('<div></div>');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('renders path with variable and prefix', () => {
|
|
79
|
+
pushLocation('/test-123');
|
|
80
|
+
const WithVariable = ({id}) => <div>{id}</div>;
|
|
81
|
+
expect(mount(<Route path="/test-:id">
|
|
82
|
+
<WithVariable/>
|
|
83
|
+
</Route>)).toContainReact(<div>123</div>);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('renders path with optional variable', () => {
|
|
87
|
+
const WithVariable = ({id}) => <div>optional: {id || 'default value'}</div>;
|
|
88
|
+
|
|
89
|
+
const wrapper = mount(<Route path="/:id?">
|
|
90
|
+
<WithVariable/>
|
|
91
|
+
</Route>);
|
|
92
|
+
|
|
93
|
+
pushLocation('/');
|
|
94
|
+
expect(wrapper).toHaveHTML('<div>optional: default value</div>');
|
|
95
|
+
|
|
96
|
+
pushLocation('/test');
|
|
97
|
+
expect(wrapper).toHaveHTML('<div>optional: test</div>');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('simple check for log urls', () => {
|
|
101
|
+
pushLocation('/a/b/c');
|
|
102
|
+
expect(mount(<div><Route path="/:a">
|
|
103
|
+
<div>test</div>
|
|
104
|
+
</Route></div>)).toHaveHTML('<div></div>');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('test call onToggle', () => {
|
|
108
|
+
let onToggleMatches = false;
|
|
109
|
+
|
|
110
|
+
const wrapper = mount(<div><Route path="/test" onToggle={matches => onToggleMatches = matches}>
|
|
111
|
+
test
|
|
112
|
+
</Route></div>);
|
|
113
|
+
|
|
114
|
+
pushLocation('/test');
|
|
115
|
+
expect(wrapper).toHaveHTML('<div>test</div>');
|
|
116
|
+
expect(onToggleMatches).toBe(true);
|
|
117
|
+
|
|
118
|
+
pushLocation('/');
|
|
119
|
+
expect(wrapper).toHaveHTML('<div></div>');
|
|
120
|
+
expect(onToggleMatches).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('renders path with variable and regex', () => {
|
|
124
|
+
pushLocation('/123');
|
|
125
|
+
const WithVariable = ({id}) => <div>{id}</div>;
|
|
126
|
+
expect(mount(<Route path="/:id([0-9]+)">
|
|
127
|
+
<WithVariable/>
|
|
128
|
+
</Route>)).toContainReact(<div>123</div>);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('do not render if regex does not match ', () => {
|
|
132
|
+
pushLocation('/test');
|
|
133
|
+
const WithVariable = ({id}) => <div>{id}</div>;
|
|
134
|
+
expect(mount(<div>
|
|
135
|
+
<Route path="/:id([0-9]+)">
|
|
136
|
+
<WithVariable/>
|
|
137
|
+
</Route>
|
|
138
|
+
</div>)).toHaveHTML('<div></div>');
|
|
139
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
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 Link from "./Link";
|
|
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 NavLink from "./NavLink";
|
|
8
|
+
import Route from "./Route";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
Link,
|
|
12
|
+
NavLink,
|
|
13
|
+
Route
|
|
14
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
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 {UNDEFINED} from "../Tools";
|
|
4
|
+
|
|
5
|
+
export const createProxy = (target) => {
|
|
6
|
+
if(!target)
|
|
7
|
+
return target
|
|
8
|
+
if (target.__isProxy)
|
|
9
|
+
return target;
|
|
10
|
+
|
|
11
|
+
let changedValue = UNDEFINED;
|
|
12
|
+
let deletedKeys = UNDEFINED;
|
|
13
|
+
let innerProxies = UNDEFINED
|
|
14
|
+
const isChanged = () => changedValue || (innerProxies && Object.values(innerProxies).some(it => it.__changed));
|
|
15
|
+
|
|
16
|
+
return new Proxy(target, {
|
|
17
|
+
get: function (target, prop) {
|
|
18
|
+
if (prop === '__isProxy')
|
|
19
|
+
return true
|
|
20
|
+
if (prop === '__changed')
|
|
21
|
+
return isChanged();
|
|
22
|
+
if (prop === 'bake')
|
|
23
|
+
return () => {
|
|
24
|
+
// console.log('bake', changedValue, innerProxies)
|
|
25
|
+
if (!isChanged())
|
|
26
|
+
return target
|
|
27
|
+
|
|
28
|
+
if (changedValue && !innerProxies)
|
|
29
|
+
return changedValue
|
|
30
|
+
|
|
31
|
+
if (innerProxies) {
|
|
32
|
+
const result = changedValue || (Array.isArray(target) ? [...target] : {...target});
|
|
33
|
+
|
|
34
|
+
for (let key in innerProxies) {
|
|
35
|
+
result[key] = innerProxies[key].bake()
|
|
36
|
+
}
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw new Error('state not implemented yet')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// console.log('get', {target, prop})
|
|
44
|
+
const innerProxy = innerProxies && innerProxies[prop];
|
|
45
|
+
if (innerProxy)
|
|
46
|
+
return innerProxy
|
|
47
|
+
|
|
48
|
+
const changed = changedValue && changedValue[prop]
|
|
49
|
+
if (changed !== UNDEFINED)
|
|
50
|
+
return changed
|
|
51
|
+
|
|
52
|
+
if (deletedKeys && deletedKeys[prop])
|
|
53
|
+
return null
|
|
54
|
+
|
|
55
|
+
const value = target[prop];
|
|
56
|
+
if (value && typeof value === 'object') {
|
|
57
|
+
!innerProxies && (innerProxies = {})
|
|
58
|
+
return innerProxies[prop] = createProxy(value)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return value;
|
|
62
|
+
},
|
|
63
|
+
set: function (target, prop, newval) {
|
|
64
|
+
// console.log('set', {target, prop, newval})
|
|
65
|
+
if (!changedValue) changedValue = Array.isArray(target) ? [...target] : {...target}
|
|
66
|
+
|
|
67
|
+
if (newval && typeof newval === 'object') {
|
|
68
|
+
!innerProxies && (innerProxies = {})
|
|
69
|
+
innerProxies[prop] = newval = createProxy(newval)
|
|
70
|
+
} else {
|
|
71
|
+
innerProxies && (delete innerProxies[prop])
|
|
72
|
+
}
|
|
73
|
+
changedValue[prop] = newval
|
|
74
|
+
// console.log('changedValue', changedValue)
|
|
75
|
+
return true;
|
|
76
|
+
},
|
|
77
|
+
deleteProperty: function (target, prop) {
|
|
78
|
+
// console.log('delete', {target, prop})
|
|
79
|
+
!changedValue && (changedValue = Array.isArray(target) ? [...target] : {...target})
|
|
80
|
+
|
|
81
|
+
if (!prop in changedValue)
|
|
82
|
+
return false;
|
|
83
|
+
|
|
84
|
+
delete changedValue[prop]
|
|
85
|
+
innerProxies && delete innerProxies[prop]
|
|
86
|
+
!deletedKeys && (deletedKeys = {})
|
|
87
|
+
deletedKeys[prop] = true;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
}
|