react-ui-basics 0.0.174 → 0.0.177
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 -0
- package/AutocompleteSelect.js +9 -23
- package/AutocompleteSelect.js.map +1 -0
- package/Button.js.map +1 -0
- 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 -0
- package/CircleProgress.js.map +1 -0
- package/CommonFields.js.map +1 -0
- package/DNDContainer.js.map +1 -0
- package/DNDDraggable.js.map +1 -0
- package/DNDDroppable.js.map +1 -0
- 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 -0
- package/DropFileInput.js.map +1 -0
- package/DroppableHorizontalList.js.map +1 -0
- package/DroppableList.js.map +1 -0
- package/Dropzone.js.map +1 -0
- package/FilteredList.js +234 -139
- package/FilteredList.js.map +1 -0
- package/FloatingActionButton.js.map +1 -0
- package/FormUploadProgress.js.map +1 -0
- package/ImageGallery.js.map +1 -0
- package/MaterialIcon.js.map +1 -0
- package/Modal.js.map +1 -0
- package/ModalMenu.js.map +1 -0
- package/ReactConstants.js.map +1 -0
- package/ReactCreateElement.js.map +1 -0
- package/ReadyListener.js.map +1 -0
- package/Scrollable.js.map +1 -0
- package/ScrollableTable.js.map +1 -0
- package/Size.js.map +1 -0
- package/Snackbar.js.map +1 -0
- package/SpinningProgress.js.map +1 -0
- package/Switch.js.map +1 -0
- package/Table.js.map +1 -0
- package/TextField.js.map +1 -0
- package/Tools.d.ts +2 -2
- package/Tools.js.map +1 -0
- package/bundle.css +816 -677
- package/index.js +4 -0
- package/index.js.map +1 -0
- 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/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/FilteredList.d.ts +0 -61
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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 {createProxy} from "./ProxyTools";
|
|
4
|
+
|
|
5
|
+
it('test proxy noop', () => {
|
|
6
|
+
const user = {name: 'Bob'};
|
|
7
|
+
const p = createProxy(user);
|
|
8
|
+
expect(p.bake()).toBe(user);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('test proxy change property', () => {
|
|
12
|
+
const user = {name: 'Bob'};
|
|
13
|
+
const p = createProxy(user);
|
|
14
|
+
p.name = 'Tom'
|
|
15
|
+
|
|
16
|
+
expect(user).toEqual({name: 'Bob'});
|
|
17
|
+
expect(p.bake()).toEqual({name: 'Tom'});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('test proxy add property', () => {
|
|
21
|
+
const user = {name: 'Bob'};
|
|
22
|
+
const p = createProxy(user);
|
|
23
|
+
p.age = 16
|
|
24
|
+
p.age = 32
|
|
25
|
+
|
|
26
|
+
expect(user).toEqual({name: 'Bob'});
|
|
27
|
+
expect(p.bake()).toEqual({name: 'Bob', age: 32});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('test proxy delete property', () => {
|
|
31
|
+
const user = {name: 'Bob'};
|
|
32
|
+
const p = createProxy(user);
|
|
33
|
+
delete p.name;
|
|
34
|
+
|
|
35
|
+
expect(user).toEqual({name: 'Bob'});
|
|
36
|
+
expect(p.bake()).toEqual({});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('test proxy set null', () => {
|
|
40
|
+
const user = {name: 'Bob'};
|
|
41
|
+
const p = createProxy(user);
|
|
42
|
+
p.name = null;
|
|
43
|
+
expect(user).toEqual({name: 'Bob'});
|
|
44
|
+
expect(p.bake()).toEqual({name: null});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('test proxy inner properties access noop', () => {
|
|
48
|
+
const user = {name: 'Bob', hobbies: ['chess']};
|
|
49
|
+
const p = createProxy(user);
|
|
50
|
+
|
|
51
|
+
const name = p.name;
|
|
52
|
+
const firstHobby = p.hobbies[0];
|
|
53
|
+
|
|
54
|
+
expect(p.bake()).toBe(user);
|
|
55
|
+
expect(name).toBe('Bob');
|
|
56
|
+
expect(firstHobby).toBe('chess');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('test proxy change inner properties', () => {
|
|
60
|
+
const user = {name: 'Bob', hobbies: ['chess']};
|
|
61
|
+
const p = createProxy(user);
|
|
62
|
+
|
|
63
|
+
p.hobbies.push('poker');
|
|
64
|
+
|
|
65
|
+
expect(user).toEqual({name: 'Bob', hobbies: ['chess']});
|
|
66
|
+
expect(p.bake()).toEqual({name: 'Bob', hobbies: ['chess', 'poker']});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('test proxy change inner properties 2', () => {
|
|
70
|
+
const user = {name: 'Bob', hobbies: ['chess']};
|
|
71
|
+
const p = createProxy(user);
|
|
72
|
+
|
|
73
|
+
p.hobbies = [...p.hobbies, 'poker'];
|
|
74
|
+
|
|
75
|
+
expect(user).toEqual({name: 'Bob', hobbies: ['chess']});
|
|
76
|
+
expect(p.bake()).toEqual({name: 'Bob', hobbies: ['chess', 'poker']});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('test proxy change inner property to null', () => {
|
|
80
|
+
const user = {name: 'Bob', hobbies: ['chess']};
|
|
81
|
+
const p = createProxy(user);
|
|
82
|
+
|
|
83
|
+
p.hobbies = null;
|
|
84
|
+
|
|
85
|
+
expect(user).toEqual({name: 'Bob', hobbies: ['chess']});
|
|
86
|
+
expect(p.bake()).toEqual({name: 'Bob', hobbies: null});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('test proxy change inner properties 3', () => {
|
|
90
|
+
const user = {name: 'Bob', hobbies: [{name: 'chess'}]};
|
|
91
|
+
const p = createProxy(user);
|
|
92
|
+
|
|
93
|
+
p.hobbies[0].name = 'poker';
|
|
94
|
+
|
|
95
|
+
expect(user).toEqual({name: 'Bob', hobbies: [{name: 'chess'}]});
|
|
96
|
+
expect(p.bake()).toEqual({name: 'Bob', hobbies: [{name: 'poker'}]});
|
|
97
|
+
});
|