react-ui-basics 0.0.246 → 0.0.248
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.d.ts +36 -0
- package/Animated.js +125 -124
- package/Animated.js.map +1 -1
- package/AutocompleteSelect.js +30 -18
- package/AutocompleteSelect.js.map +1 -1
- package/ReactConstants.d.ts +5 -0
- package/ReactConstants.js.map +1 -1
- package/bundle.css +754 -754
- package/package.json +1 -1
- package/router/Link.js +1 -2
- package/router/Link.js.map +1 -1
- package/router/NavLink.js +1 -2
- package/router/NavLink.js.map +1 -1
- package/router/Route.d.ts +14 -0
- package/router/Route.js +163 -159
- package/router/Route.js.map +1 -1
- package/router/index.d.ts +8 -0
- package/router/index.js +3 -3
- package/router/index.js.map +1 -1
- package/src/{Animated.js → Animated.tsx} +77 -74
- package/src/AutocompleteSelect.js +27 -14
- package/src/ReactConstants.ts +12 -0
- package/src/router/{Route.js → Route.tsx} +50 -46
- package/src/router/index.ts +9 -0
- package/src/router/index.js +0 -9
|
@@ -1,35 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ReactCreateElement from './ReactCreateElement';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import React, {CSSProperties} from 'react';
|
|
4
2
|
import './Animated.css'
|
|
5
|
-
import {allPropsExcept, classNames,
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import {allPropsExcept, classNames, clearTimeout, requestAnimationFrame, setOf, setTimeout} from "./Tools";
|
|
4
|
+
import {
|
|
5
|
+
children,
|
|
6
|
+
className,
|
|
7
|
+
componentDidMount,
|
|
8
|
+
componentDidUpdate,
|
|
9
|
+
componentWillUnmount,
|
|
10
|
+
props,
|
|
11
|
+
PureComponent,
|
|
12
|
+
render,
|
|
13
|
+
setState,
|
|
14
|
+
state
|
|
15
|
+
} from "./ReactConstants";
|
|
16
|
+
|
|
17
|
+
const mounting = 'mounting',
|
|
9
18
|
unmounting = 'unmounting',
|
|
10
19
|
mounted = 'mounted',
|
|
11
20
|
enabled = 'enabled',
|
|
12
21
|
mountingDelay = 'mountingDelay',
|
|
13
22
|
unmountingDelay = 'unmountingDelay',
|
|
14
23
|
timeout = 'timeout',
|
|
15
|
-
value = 'value'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
value,
|
|
27
|
-
]);
|
|
24
|
+
value = 'value',
|
|
25
|
+
selfProps = setOf([
|
|
26
|
+
children,
|
|
27
|
+
className,
|
|
28
|
+
'styles',
|
|
29
|
+
mountingDelay,
|
|
30
|
+
unmountingDelay,
|
|
31
|
+
mounting,
|
|
32
|
+
unmounting,
|
|
33
|
+
value,
|
|
34
|
+
]);
|
|
28
35
|
|
|
29
36
|
const clearTimer = that => clearTimeout(that[timeout]);
|
|
30
37
|
|
|
31
|
-
const animatedState = (isEnabled, isMounting, isMounted, isUnMounting) => {
|
|
32
|
-
const r = {};
|
|
38
|
+
const animatedState = (isEnabled: boolean, isMounting?: boolean, isMounted?: boolean, isUnMounting?: boolean): AnimatedState => {
|
|
39
|
+
const r = {} as AnimatedState;
|
|
33
40
|
r[enabled] = isEnabled;
|
|
34
41
|
r[mounting] = isMounting;
|
|
35
42
|
r[mounted] = isMounted;
|
|
@@ -37,13 +44,13 @@ const animatedState = (isEnabled, isMounting, isMounted, isUnMounting) => {
|
|
|
37
44
|
return r;
|
|
38
45
|
};
|
|
39
46
|
|
|
40
|
-
const doMounting = (that, duration) => {
|
|
47
|
+
const doMounting = (that, duration: number) => {
|
|
41
48
|
setState(that, animatedState(true, true, false, false));
|
|
42
49
|
|
|
43
50
|
that[timeout] = setTimeout(setState, duration, that, animatedState(true, false, true, false))
|
|
44
51
|
};
|
|
45
52
|
|
|
46
|
-
const processMounting = (that, duration, mountingDelay) => {
|
|
53
|
+
const processMounting = (that, duration: number, mountingDelay: number) => {
|
|
47
54
|
const _state = state(that);
|
|
48
55
|
if (_state[mounting] || _state[mounted]) return;
|
|
49
56
|
clearTimer(that);
|
|
@@ -61,12 +68,12 @@ const processMounting = (that, duration, mountingDelay) => {
|
|
|
61
68
|
}
|
|
62
69
|
};
|
|
63
70
|
|
|
64
|
-
const doUnmounting = (that, duration) => {
|
|
71
|
+
const doUnmounting = (that, duration: number) => {
|
|
65
72
|
setState(that, animatedState(true, false, false, true));
|
|
66
73
|
that[timeout] = setTimeout(setState, duration, that, animatedState(false, false, false, false));
|
|
67
74
|
};
|
|
68
75
|
|
|
69
|
-
const processUnmounting = (that, duration, unmountingDelay) => {
|
|
76
|
+
const processUnmounting = (that, duration: number, unmountingDelay: number) => {
|
|
70
77
|
const _state = state(that);
|
|
71
78
|
if (_state[unmounting]) return;
|
|
72
79
|
clearTimer(that);
|
|
@@ -84,24 +91,56 @@ const processUnmounting = (that, duration, unmountingDelay) => {
|
|
|
84
91
|
}
|
|
85
92
|
};
|
|
86
93
|
|
|
87
|
-
|
|
94
|
+
export interface AnimatedStyles {
|
|
95
|
+
mounting?: CSSProperties,
|
|
96
|
+
mounted?: CSSProperties,
|
|
97
|
+
unmounting?: CSSProperties,
|
|
98
|
+
default?: CSSProperties,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface AnimatedProps {
|
|
102
|
+
value: boolean,
|
|
103
|
+
className?: string,
|
|
104
|
+
styles?: AnimatedStyles,
|
|
105
|
+
mountingDelay?: number,
|
|
106
|
+
unmountingDelay?: number,
|
|
107
|
+
mounting?: number,
|
|
108
|
+
unmounting?: number,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface AnimatedState {
|
|
112
|
+
enabled: boolean
|
|
113
|
+
mounting: boolean,
|
|
114
|
+
unmounting: boolean,
|
|
115
|
+
mounted: boolean,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
class Animated extends PureComponent<AnimatedProps, AnimatedState> {
|
|
119
|
+
static defaultProps = {
|
|
120
|
+
[className]: 'animated',
|
|
121
|
+
[mounting]: 250,
|
|
122
|
+
[unmounting]: 250,
|
|
123
|
+
styles: {},
|
|
124
|
+
[mountingDelay]: 0,
|
|
125
|
+
[unmountingDelay]: 0,
|
|
126
|
+
}
|
|
88
127
|
|
|
89
128
|
constructor(properties) {
|
|
90
129
|
super(properties);
|
|
91
130
|
const that = this;
|
|
92
131
|
that.state = animatedState(!!properties[value]);
|
|
93
132
|
|
|
94
|
-
that[
|
|
133
|
+
that[componentDidMount] = () => {
|
|
95
134
|
const _props = props(that);
|
|
96
135
|
if (!!_props[value])
|
|
97
136
|
processMounting(that, _props[mounting], _props[mountingDelay])
|
|
98
137
|
};
|
|
99
138
|
|
|
100
|
-
that[
|
|
139
|
+
that[componentWillUnmount] = () => {
|
|
101
140
|
clearTimer(that)
|
|
102
141
|
};
|
|
103
142
|
|
|
104
|
-
that[
|
|
143
|
+
that[render] = () => {
|
|
105
144
|
const _state = state(that);
|
|
106
145
|
if (!_state[enabled]) return null;
|
|
107
146
|
|
|
@@ -122,24 +161,23 @@ class Animated extends PureComponent {
|
|
|
122
161
|
childStyles = styles[mounted] || styles[mounting];
|
|
123
162
|
|
|
124
163
|
const otherProps = allPropsExcept(_props, selfProps);
|
|
125
|
-
return React.Children.map(_props[
|
|
164
|
+
return React.Children.map(_props[children], child =>
|
|
126
165
|
child && React.cloneElement(child, {
|
|
127
|
-
[
|
|
128
|
-
props(child)[
|
|
129
|
-
_props[
|
|
166
|
+
[className]: classNames(
|
|
167
|
+
props(child)[className],
|
|
168
|
+
_props[className],
|
|
130
169
|
isMounting && mounting,
|
|
131
170
|
isMounted && mounted,
|
|
132
171
|
isUnMounting && unmounting
|
|
133
172
|
),
|
|
134
|
-
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
style: {...props(child).style, ...childStyles},
|
|
135
175
|
...otherProps,
|
|
136
176
|
}));
|
|
137
177
|
};
|
|
138
178
|
|
|
139
|
-
that[
|
|
140
|
-
const
|
|
141
|
-
const t = that;
|
|
142
|
-
const _props = p(t)||props(that),
|
|
179
|
+
that[componentDidUpdate] = () => {
|
|
180
|
+
const _props = props(that),
|
|
143
181
|
_state = state(that),
|
|
144
182
|
{
|
|
145
183
|
[value]: v,
|
|
@@ -175,39 +213,4 @@ class Animated extends PureComponent {
|
|
|
175
213
|
}
|
|
176
214
|
}
|
|
177
215
|
|
|
178
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
179
|
-
Animated.propTypes = {
|
|
180
|
-
[value]: PropTypes.bool,
|
|
181
|
-
[ReactConstants[5]]: PropTypes.string,
|
|
182
|
-
styles: PropTypes.shape({
|
|
183
|
-
[mounting]: PropTypes.object,
|
|
184
|
-
[mounted]: PropTypes.object,
|
|
185
|
-
[unmounting]: PropTypes.object,
|
|
186
|
-
}),
|
|
187
|
-
[mountingDelay]: PropTypes.number,
|
|
188
|
-
[unmountingDelay]: PropTypes.number,
|
|
189
|
-
[mounting]: PropTypes.number,
|
|
190
|
-
[unmounting]: PropTypes.number,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
Animated.defaultProps = {
|
|
195
|
-
[ReactConstants[5]]: 'animated',
|
|
196
|
-
[mounting]: 250,
|
|
197
|
-
[unmounting]: 250,
|
|
198
|
-
styles: {},
|
|
199
|
-
[mountingDelay]: 0,
|
|
200
|
-
[unmountingDelay]: 0,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// forcing webpack to NOT inline constant fields
|
|
204
|
-
// mounting = mounting || 1;
|
|
205
|
-
// mounted = mounted || 1;
|
|
206
|
-
// unmounting = unmounting || 1;
|
|
207
|
-
// enabled = enabled || 1;
|
|
208
|
-
// mountingDelay = mountingDelay || 1;
|
|
209
|
-
// unmountingDelay = unmountingDelay || 1;
|
|
210
|
-
// value = value || 1;
|
|
211
|
-
// timeout = timeout || 1;
|
|
212
|
-
|
|
213
216
|
export default Animated
|
|
@@ -170,6 +170,7 @@ class AutocompleteSelect extends PureComponent {
|
|
|
170
170
|
selectCustomOnClickOutside: true,
|
|
171
171
|
withReset: false,
|
|
172
172
|
scrollToValue: false,
|
|
173
|
+
disabled: false,
|
|
173
174
|
mode: MODE_DEFAULT,
|
|
174
175
|
selectedMode: 'full',
|
|
175
176
|
listPortalPosition: 'left',
|
|
@@ -204,6 +205,7 @@ class AutocompleteSelect extends PureComponent {
|
|
|
204
205
|
className,
|
|
205
206
|
scrollToValue,
|
|
206
207
|
scroll,
|
|
208
|
+
disabled,
|
|
207
209
|
required,
|
|
208
210
|
allowCustom,
|
|
209
211
|
inlineSelected,
|
|
@@ -227,17 +229,21 @@ class AutocompleteSelect extends PureComponent {
|
|
|
227
229
|
const selectedIds = Object.values(selected);
|
|
228
230
|
const hasSelected = __length(selectedIds) !== 0;
|
|
229
231
|
const setActive = (e) => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
if (!disabled) {
|
|
233
|
+
stopPropagation(e);
|
|
234
|
+
this.setState({isActive: true}, () => {
|
|
235
|
+
scrollToValue && __length(selectedIds) > 0 && data.includes(selectedIds[0]) && this.list.selected(selectedIds[0]);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
234
238
|
};
|
|
235
239
|
const toggle = (e) => {
|
|
236
|
-
if (!
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
if (!disabled) {
|
|
241
|
+
if (!__state(this).isActive) {
|
|
242
|
+
setActive(e);
|
|
243
|
+
} else {
|
|
244
|
+
stopPropagation(e);
|
|
245
|
+
this.setState({isActive: false});
|
|
246
|
+
}
|
|
241
247
|
}
|
|
242
248
|
};
|
|
243
249
|
|
|
@@ -278,6 +284,7 @@ class AutocompleteSelect extends PureComponent {
|
|
|
278
284
|
errored && 'errored',
|
|
279
285
|
inlineSelected && 'inlineSelected',
|
|
280
286
|
hasSelected && 'hasSelected',
|
|
287
|
+
disabled && 'disabled',
|
|
281
288
|
)}
|
|
282
289
|
ref={ref('el', this)}>
|
|
283
290
|
{label && <label className={classNames(`label`, (hasSelected || filterValue) && 'active', hasSelected && 'hasSelected')}
|
|
@@ -297,6 +304,7 @@ class AutocompleteSelect extends PureComponent {
|
|
|
297
304
|
<div
|
|
298
305
|
className={classNames('selected',
|
|
299
306
|
!label && 'nolabel',
|
|
307
|
+
disabled && 'disabled',
|
|
300
308
|
(mode === MODE_MULTIPLE_MINI || mode === MODE_MINI || mode === MODE_MULTIPLE_MINI_INLINE) && 'clickable',
|
|
301
309
|
selectedMode)}
|
|
302
310
|
onClick={toggle}>
|
|
@@ -305,8 +313,10 @@ class AutocompleteSelect extends PureComponent {
|
|
|
305
313
|
<div className="value" key={id}>
|
|
306
314
|
{React.createElement(selectedComponent, {...childProps, id, label: getLabel(labels, id), [ReactConstants[6]]: setActive})}
|
|
307
315
|
<div className="button remove" onClick={e => {
|
|
308
|
-
|
|
309
|
-
|
|
316
|
+
if (!disabled) {
|
|
317
|
+
stopPropagation(e);
|
|
318
|
+
this.remove(id);
|
|
319
|
+
}
|
|
310
320
|
}}>
|
|
311
321
|
{removeIcon}
|
|
312
322
|
</div>
|
|
@@ -319,7 +329,7 @@ class AutocompleteSelect extends PureComponent {
|
|
|
319
329
|
</React.Fragment>
|
|
320
330
|
)}
|
|
321
331
|
{!label && withArrow && <span className="arrow"/>}
|
|
322
|
-
{withReset && <Button className="reset" raised={false} onClick={this.clean}>
|
|
332
|
+
{withReset && <Button className="reset" disabled={disabled} raised={false} onClick={this.clean}>
|
|
323
333
|
{removeIcon}
|
|
324
334
|
</Button>}
|
|
325
335
|
</div>
|
|
@@ -330,8 +340,10 @@ class AutocompleteSelect extends PureComponent {
|
|
|
330
340
|
<div className="value" key={id}>
|
|
331
341
|
{React.createElement(selectedComponent, {...childProps, id, label: getLabel(labels, id), [ReactConstants[6]]: setActive})}
|
|
332
342
|
<div className="button remove" onClick={e => {
|
|
333
|
-
|
|
334
|
-
|
|
343
|
+
if (!disabled) {
|
|
344
|
+
stopPropagation(e);
|
|
345
|
+
this.remove(id);
|
|
346
|
+
}
|
|
335
347
|
}}>
|
|
336
348
|
{removeIcon}
|
|
337
349
|
</div>
|
|
@@ -352,6 +364,7 @@ class AutocompleteSelect extends PureComponent {
|
|
|
352
364
|
focused={isActive}
|
|
353
365
|
value={filterValue}
|
|
354
366
|
label={inputLabel}
|
|
367
|
+
disabled={disabled}
|
|
355
368
|
onChange={this[ReactConstants[7]]}
|
|
356
369
|
onFocus={e => this.setState({isActive: true})}
|
|
357
370
|
check={__props(this).filterCheck}
|
package/src/ReactConstants.ts
CHANGED
|
@@ -12,6 +12,18 @@ export const stateFieldSetter = (that, key, cb?: () => void) => (value, cb2?) =>
|
|
|
12
12
|
setState(that, {[key]: value}, cb2 || cb);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
export type Callback = () => void;
|
|
16
|
+
export const createStateGetterSetter = <C extends React.Component, K extends keyof C["state"]>(that: C, key: K, cb?: Callback): {
|
|
17
|
+
(): C["state"][K];
|
|
18
|
+
(value: C["state"][K], cb2?: Callback): void;
|
|
19
|
+
} => (function (value?: C["state"][K], cb2?: Callback): C["state"][K] {
|
|
20
|
+
return arguments.length === 0 ?
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
state(that)[key]
|
|
23
|
+
:
|
|
24
|
+
setState(that, {[key]: value} as any, cb2 ?? cb)
|
|
25
|
+
});
|
|
26
|
+
|
|
15
27
|
type GetterSetter<T> = (v?: T, cb?: () => void) => T;
|
|
16
28
|
export const stateGS: (<T>(that: React.Component) => GetterSetter<T>) = (that) => {
|
|
17
29
|
!that['sfc'] && (that['sfc'] = 0);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, {ReactNode} from 'react';
|
|
2
2
|
import ReactCreateElement from '../ReactCreateElement';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
3
|
import './HistoryTools'
|
|
5
4
|
import {allPropsExcept, isDifferent, orNoop, setOf, WINDOW, addEventListener, removeEventListener} from "../Tools";
|
|
6
5
|
import {componentDidUpdate, render, PureComponent, componentDidMount, componentWillUnmount, propsGetter, stateGSs, setState} from "../ReactConstants";
|
|
7
6
|
|
|
7
|
+
const indexOf = (src: string, search: string) => src.indexOf(search);
|
|
8
|
+
const substring = (src: string, start: number, end?: number) => src.substring(start, end);
|
|
9
|
+
|
|
8
10
|
const historyEvents = ['popstate', 'pushState', 'replaceState'];
|
|
9
11
|
|
|
10
12
|
const cleanPath = (path) => {
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
13
|
+
if (path.length > 1 && path.lastIndexOf('/') === path.length - 1)
|
|
14
|
+
return substring(path, 0, path.length - 1);
|
|
13
15
|
|
|
14
16
|
return path;
|
|
15
17
|
};
|
|
@@ -17,32 +19,32 @@ const cleanPath = (path) => {
|
|
|
17
19
|
const createUrlMatcher = path => {
|
|
18
20
|
let matcher;
|
|
19
21
|
const segments = path.split('/');
|
|
20
|
-
const optionals = segments.map(it => it === '*' ||
|
|
21
|
-
const containsVariables =
|
|
22
|
-
const containsAnySegment =
|
|
23
|
-
const containsNot =
|
|
22
|
+
const optionals = segments.map(it => it === '*' || indexOf(it, '?') === it.length - 1);
|
|
23
|
+
const containsVariables = indexOf(path, ':') !== -1;
|
|
24
|
+
const containsAnySegment = indexOf(path, '*') !== -1;
|
|
25
|
+
const containsNot = indexOf(path, '!') !== -1;
|
|
24
26
|
|
|
25
27
|
if (!containsAnySegment && !containsVariables && !containsNot) {
|
|
26
28
|
matcher = (p) => p === path
|
|
27
29
|
} else {
|
|
28
|
-
const endsWithAny = path.lastIndexOf('*') ===
|
|
30
|
+
const endsWithAny = path.lastIndexOf('*') === path.length - 1;
|
|
29
31
|
const matchers = segments.map((segment, i) => {
|
|
30
32
|
let matcher;
|
|
31
|
-
const variableNameIndex =
|
|
33
|
+
const variableNameIndex = indexOf(segment, ':');
|
|
32
34
|
if (segment === '*')
|
|
33
35
|
matcher = () => true;
|
|
34
36
|
else if (variableNameIndex !== -1) {
|
|
35
|
-
let variable =
|
|
37
|
+
let variable = substring(segment, variableNameIndex + 1);
|
|
36
38
|
let regex = null
|
|
37
|
-
if (
|
|
38
|
-
variable =
|
|
39
|
-
if (
|
|
40
|
-
let regexStart =
|
|
41
|
-
regex = new RegExp(
|
|
42
|
-
variable =
|
|
39
|
+
if (indexOf(variable, '?') !== -1)
|
|
40
|
+
variable = substring(variable, 0, indexOf(variable, '?'));
|
|
41
|
+
if (indexOf(variable, '(') !== -1) {
|
|
42
|
+
let regexStart = indexOf(variable, '(');
|
|
43
|
+
regex = new RegExp(substring(variable, regexStart))
|
|
44
|
+
variable = substring(variable, 0, regexStart);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const prefix = variableNameIndex &&
|
|
47
|
+
const prefix = variableNameIndex && substring(segment, 0, variableNameIndex);
|
|
46
48
|
matcher = (p, params) => {
|
|
47
49
|
if (regex && !!p && !p.match(regex))
|
|
48
50
|
return false
|
|
@@ -50,8 +52,8 @@ const createUrlMatcher = path => {
|
|
|
50
52
|
if (!p && !optionals[i])
|
|
51
53
|
return false;
|
|
52
54
|
if (prefix) {
|
|
53
|
-
if (
|
|
54
|
-
p =
|
|
55
|
+
if (indexOf(p, prefix) === 0)
|
|
56
|
+
p = substring(p, variableNameIndex);
|
|
55
57
|
else
|
|
56
58
|
return false;
|
|
57
59
|
}
|
|
@@ -59,8 +61,8 @@ const createUrlMatcher = path => {
|
|
|
59
61
|
params[variable] = p;
|
|
60
62
|
return true;
|
|
61
63
|
}
|
|
62
|
-
} else if (
|
|
63
|
-
const not =
|
|
64
|
+
} else if (indexOf(segment, '!') === 0) {
|
|
65
|
+
const not = substring(segment, 1);
|
|
64
66
|
matcher = (p) => p !== not;
|
|
65
67
|
} else
|
|
66
68
|
matcher = (p) => p === segment;
|
|
@@ -69,10 +71,10 @@ const createUrlMatcher = path => {
|
|
|
69
71
|
|
|
70
72
|
matcher = (path, params) => {
|
|
71
73
|
const segments = path.split('/');
|
|
72
|
-
const length = Math.min(
|
|
74
|
+
const length = Math.min(matchers.length, segments.length);
|
|
73
75
|
|
|
74
76
|
// only exact match if mapping not ends with *
|
|
75
|
-
if (!endsWithAny &&
|
|
77
|
+
if (!endsWithAny && matchers.length < segments.length)
|
|
76
78
|
return false;
|
|
77
79
|
|
|
78
80
|
// check that each segment matches
|
|
@@ -82,7 +84,7 @@ const createUrlMatcher = path => {
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
// check that all other segments are optional
|
|
85
|
-
for (let i = length; i <
|
|
87
|
+
for (let i = length; i < optionals.length; i++) {
|
|
86
88
|
if (!optionals[i])
|
|
87
89
|
return false;
|
|
88
90
|
}
|
|
@@ -97,10 +99,10 @@ const createUrlMatchers = path => {
|
|
|
97
99
|
if (Array.isArray(path)) {
|
|
98
100
|
const matchers = path.map(it => createUrlMatcher(it));
|
|
99
101
|
return (path, params) => {
|
|
100
|
-
for (let i = 0; i <
|
|
102
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
101
103
|
let props = {};
|
|
102
104
|
if (matchers[i](path, props)) {
|
|
103
|
-
|
|
105
|
+
Object.assign(params, props);
|
|
104
106
|
return true;
|
|
105
107
|
}
|
|
106
108
|
}
|
|
@@ -118,7 +120,16 @@ const selfProps = setOf([
|
|
|
118
120
|
'onToggle',
|
|
119
121
|
]);
|
|
120
122
|
|
|
121
|
-
|
|
123
|
+
export type Controller = (matches: boolean, children: ReactNode, props: any) => ReactNode;
|
|
124
|
+
|
|
125
|
+
export interface RouteProps {
|
|
126
|
+
path: string | string[],
|
|
127
|
+
controller?: Controller,
|
|
128
|
+
onToggle?: (matches: boolean) => void,
|
|
129
|
+
children?: ReactNode,
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
class Route extends PureComponent<RouteProps> {
|
|
122
133
|
|
|
123
134
|
constructor(properties) {
|
|
124
135
|
super(properties);
|
|
@@ -139,10 +150,13 @@ class Route extends PureComponent {
|
|
|
139
150
|
let isMatching = matcher(cleanPath(WINDOW.location.pathname), params);
|
|
140
151
|
|
|
141
152
|
const toggle = isMatching !== isRendering();
|
|
153
|
+
// @ts-ignore
|
|
142
154
|
toggle && (nextState[isRendering] = isMatching);
|
|
143
155
|
|
|
144
156
|
if (isDifferent(paramsState(), params)) {
|
|
145
|
-
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
nextState[mergedPropsState] = Object.assign(allPropsExcept(props(), selfProps), params);
|
|
159
|
+
// @ts-ignore
|
|
146
160
|
nextState[paramsState] = params;
|
|
147
161
|
}
|
|
148
162
|
|
|
@@ -152,20 +166,20 @@ class Route extends PureComponent {
|
|
|
152
166
|
})
|
|
153
167
|
};
|
|
154
168
|
|
|
155
|
-
that[
|
|
169
|
+
that[componentDidUpdate] = (prevProps, prevState) => {
|
|
156
170
|
if (props() !== prevProps) {
|
|
157
|
-
let mergedProps =
|
|
171
|
+
let mergedProps = Object.assign(allPropsExcept(props(), selfProps), paramsState());
|
|
158
172
|
if (isDifferent(mergedProps, mergedPropsState()))
|
|
159
173
|
mergedPropsState(mergedProps);
|
|
160
174
|
}
|
|
161
175
|
};
|
|
162
176
|
|
|
163
|
-
that[
|
|
177
|
+
that[render] = () => {
|
|
164
178
|
const {children, controller} = props();
|
|
165
179
|
return (controller || DefaultController)(isRendering(), children, mergedPropsState());
|
|
166
180
|
};
|
|
167
181
|
|
|
168
|
-
that[
|
|
182
|
+
that[componentDidMount] = () => {
|
|
169
183
|
matcher = createUrlMatchers(props().path);
|
|
170
184
|
|
|
171
185
|
historyEvents.forEach(it => {
|
|
@@ -174,7 +188,7 @@ class Route extends PureComponent {
|
|
|
174
188
|
process();
|
|
175
189
|
};
|
|
176
190
|
|
|
177
|
-
that[
|
|
191
|
+
that[componentWillUnmount] = () => {
|
|
178
192
|
historyEvents.forEach(it => {
|
|
179
193
|
removeEventListener(WINDOW, it, process);
|
|
180
194
|
});
|
|
@@ -182,20 +196,10 @@ class Route extends PureComponent {
|
|
|
182
196
|
}
|
|
183
197
|
}
|
|
184
198
|
|
|
185
|
-
|
|
186
|
-
Route.propTypes = {
|
|
187
|
-
path: PropTypes.oneOfType([
|
|
188
|
-
PropTypes.string,
|
|
189
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
190
|
-
]).isRequired,
|
|
191
|
-
controller: PropTypes.func,
|
|
192
|
-
onToggle: PropTypes.func,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const DefaultController = (matches, children, props) => {
|
|
199
|
+
const DefaultController: Controller = (matches, children, props) => {
|
|
197
200
|
if (!matches || !children) return null;
|
|
198
201
|
if (Object.keys(props).length > 0) {
|
|
202
|
+
// @ts-ignore
|
|
199
203
|
return React.Children.map(children, child => React.cloneElement(child, props));
|
|
200
204
|
}
|
|
201
205
|
return children;
|
package/src/router/index.js
DELETED
|
@@ -1,9 +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 Link from "./Link";
|
|
2
|
-
import NavLink from "./NavLink";
|
|
3
|
-
import Route from "./Route";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
Link,
|
|
7
|
-
NavLink,
|
|
8
|
-
Route
|
|
9
|
-
};
|