react-ui-basics 0.0.245 → 0.0.247
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/Button.d.ts +2 -2
- package/Button.js +6 -6
- package/Button.js.map +1 -1
- package/CalendarMonthView.js +4 -4
- package/CalendarMonthView.js.map +1 -1
- package/Checkbox.js +1 -1
- package/Checkbox.js.map +1 -1
- package/CircleProgress.js +1 -1
- package/CircleProgress.js.map +1 -1
- package/DNDContainer.js +1 -1
- package/DNDContainer.js.map +1 -1
- package/DNDDraggable.js +7 -1
- package/DNDDraggable.js.map +1 -1
- package/DNDDroppable.js +9 -2
- package/DNDDroppable.js.map +1 -1
- package/DatePicker.js +38 -35
- package/DatePicker.js.map +1 -1
- package/DateTools.js +9 -7
- package/DateTools.js.map +1 -1
- package/Dialog.d.ts +3 -3
- package/Dialog.js +10 -8
- package/Dialog.js.map +1 -1
- package/DropFileInput.js +1 -1
- package/DropFileInput.js.map +1 -1
- package/Dropzone.js +2 -2
- package/Dropzone.js.map +1 -1
- package/FilteredList.d.ts +1 -1
- package/FilteredList.js +93 -86
- package/FilteredList.js.map +1 -1
- package/FloatingActionButton.js +1 -1
- package/FloatingActionButton.js.map +1 -1
- package/FormUploadProgress.js +2 -2
- package/FormUploadProgress.js.map +1 -1
- package/HttpTools.d.ts +3 -3
- package/HttpTools.js +20 -9
- package/HttpTools.js.map +1 -1
- package/MaterialIcon.d.ts +1 -1
- package/MaterialIcon.js +1 -1
- package/MaterialIcon.js.map +1 -1
- package/Modal.d.ts +1 -1
- package/Modal.js +11 -9
- package/Modal.js.map +1 -1
- package/ModalMenu.js +2 -2
- package/ModalMenu.js.map +1 -1
- package/ReactConstants.d.ts +7 -2
- package/ReactConstants.js.map +1 -1
- package/Scrollable.d.ts +1 -1
- package/Scrollable.js +10 -5
- package/Scrollable.js.map +1 -1
- package/ScrollableTable.js +2 -1
- package/ScrollableTable.js.map +1 -1
- package/Size.d.ts +1 -1
- package/Size.js +1 -1
- package/Size.js.map +1 -1
- package/Snackbar.js +1 -1
- package/Snackbar.js.map +1 -1
- package/SpinningProgress.js +1 -1
- package/SpinningProgress.js.map +1 -1
- package/Switch.js +1 -1
- package/Switch.js.map +1 -1
- package/Table.d.ts +5 -5
- package/Table.js +16 -10
- package/Table.js.map +1 -1
- package/TextField.js +5 -2
- package/TextField.js.map +1 -1
- package/Tools.d.ts +4 -4
- package/Tools.js +41 -41
- package/Tools.js.map +1 -1
- package/bundle.css +665 -666
- package/misc/SimpleSentryClient.d.ts +1 -1
- package/misc/SimpleSentryClient.js +7 -4
- package/misc/SimpleSentryClient.js.map +1 -1
- package/package.json +1 -1
- package/router/HistoryTools.d.ts +3 -3
- package/router/Link.js +4 -5
- package/router/Link.js.map +1 -1
- package/router/NavLink.js +4 -5
- 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/Button.tsx +11 -14
- package/src/ReactConstants.ts +17 -0
- package/src/router/{Route.js → Route.tsx} +50 -46
- package/src/router/index.ts +9 -0
- package/store/ProxyTools.js +2 -2
- package/store/ProxyTools.js.map +1 -1
- package/store/Store.d.ts +4 -4
- package/store/Store.js +11 -1
- package/store/Store.js.map +1 -1
- 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
|
package/src/Button.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React, {FocusEventHandler, MouseEventHandler, ReactElement, ReactNode} from 'react';
|
|
1
|
+
import React, {ButtonHTMLAttributes, FocusEventHandler, MouseEventHandler, ReactElement, ReactNode} from 'react';
|
|
2
2
|
import ReactCreateElement from './ReactCreateElement';
|
|
3
3
|
import './Button.css'
|
|
4
4
|
import {classNames, DOCUMENT, addEventListener, createRef, orNoop} from "./Tools";
|
|
5
5
|
import {PureComponent, render, stateGS, props} from "./ReactConstants";
|
|
6
6
|
|
|
7
|
-
export interface ButtonProps {
|
|
7
|
+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
8
8
|
flat?: boolean,
|
|
9
9
|
raised?: boolean,
|
|
10
10
|
round?: boolean,
|
|
@@ -69,20 +69,17 @@ class Button extends PureComponent<ButtonProps> {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
that[render] = () => {
|
|
72
|
-
const {children,
|
|
72
|
+
const {children, className, flat, raised = !flat, round, disabled, withRipple, ...other} = props(that);
|
|
73
73
|
return (
|
|
74
|
-
<button
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
<button {...other}
|
|
75
|
+
className={classNames('Button',
|
|
76
|
+
className,
|
|
77
|
+
disabled && 'disabled',
|
|
78
|
+
raised && 'raised',
|
|
79
|
+
flat && 'flat',
|
|
80
|
+
round && 'round')
|
|
81
|
+
}
|
|
81
82
|
onFocus={onFocus}
|
|
82
|
-
disabled={disabled}
|
|
83
|
-
style={style}
|
|
84
|
-
type={type}
|
|
85
|
-
onClick={onClick}
|
|
86
83
|
onMouseDown={onMouseDown}
|
|
87
84
|
ref={el}>
|
|
88
85
|
{children}
|
package/src/ReactConstants.ts
CHANGED
|
@@ -12,6 +12,23 @@ 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 function 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
|
+
} {
|
|
20
|
+
return ((value?: C["state"][K], cb2?: Callback): C["state"][K] => {
|
|
21
|
+
if (arguments.length === 0) {
|
|
22
|
+
// getter
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
return that.state[key];
|
|
25
|
+
} else {
|
|
26
|
+
// setter
|
|
27
|
+
that.setState({[key]: value} as any, cb2 ?? cb);
|
|
28
|
+
}
|
|
29
|
+
}) as any;
|
|
30
|
+
}
|
|
31
|
+
|
|
15
32
|
type GetterSetter<T> = (v?: T, cb?: () => void) => T;
|
|
16
33
|
export const stateGS: (<T>(that: React.Component) => GetterSetter<T>) = (that) => {
|
|
17
34
|
!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/store/ProxyTools.js
CHANGED
|
@@ -10,10 +10,10 @@ const createProxy = (target) => {
|
|
|
10
10
|
let innerProxies = UNDEFINED;
|
|
11
11
|
const isChanged = () => changedValue || (innerProxies && Object.values(innerProxies).some(it => it[FIELD_CHANGED]));
|
|
12
12
|
const initChangedValue = (target) => {
|
|
13
|
-
!changedValue && (changedValue = Array.isArray(target) ? [...target] :
|
|
13
|
+
!changedValue && (changedValue = Array.isArray(target) ? [...target] : { ...target });
|
|
14
14
|
};
|
|
15
15
|
const compile = (changedValue, innerProxies) => {
|
|
16
|
-
let result = changedValue || (Array.isArray(target) ? [...target] :
|
|
16
|
+
let result = changedValue || (Array.isArray(target) ? [...target] : { ...target });
|
|
17
17
|
for (let key in innerProxies) {
|
|
18
18
|
result[key] = innerProxies[key][FIELD_BAKE]();
|
|
19
19
|
}
|
package/store/ProxyTools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyTools.js","sources":["../src/store/ProxyTools.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAC/B,MAAM,UAAU,GAAG,MAAM,CAAC;AAEb,MAAA,WAAW,GAAG,CAAmB,MAAS,KAAI;AACvD,IAAA,IAAI,CAAC,MAAM;AACP,QAAA,OAAO,MAAM,CAAA;IAEjB,IAAI,YAAY,GAAG,SAAS,C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EAAE,MAAM,KAAI;;YAE7B,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAEzB,YAAA,IAAI,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE;AAC5B,gBAAA,CAAC,YAAY,KAAK,YAAY,GAAG,EAAE,CAAC,CAAA;gBACpC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;AACpD,aAAA;AAAM,iBAAA;AACH,gBAAA,YAAY,IAAI,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;AAChD,aAAA;AACD,YAAA,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAA;;AAE3B,YAAA,OAAO,IAAI,CAAC;SACf;AACD,QAAA,cAAc,EAAE,CAAC,MAAS,EAAE,IAAI,KAAI;;YAEhC,gBAAgB,CAAC,MAAM,CAAC,CAAC;YAEzB,IAAI,IAAI,IAAI,YAAY,EAAE;AACtB,gBAAA,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;AAC7B,gBAAA,YAAY,IAAI,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;AAC7C,gBAAA,CAAC,WAAW,KAAK,WAAW,GAAG,EAAE,CAAC,CAAA;AAClC,gBAAA,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC5B,aAAA;AACD,YAAA,OAAO,IAAI,CAAC;SACf;AACJ,KAAA,CAAC,CAAA;AACN;;;;"}
|
package/store/Store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type Setter<T> = (oldState: T) => T | void;
|
|
2
|
+
type ListenerFn = () => void;
|
|
3
|
+
type UnsubscribeFn = () => void;
|
|
4
4
|
declare abstract class AbstractStore<T> {
|
|
5
5
|
get: () => T;
|
|
6
6
|
set: (setter: T | Partial<T> | (Setter<T>)) => void;
|
|
@@ -18,7 +18,7 @@ export declare class Store<T> extends AbstractStore<T> {
|
|
|
18
18
|
}
|
|
19
19
|
export default Store;
|
|
20
20
|
export declare function getGlobalState(): Map<Symbol, Store<any>>;
|
|
21
|
-
export
|
|
21
|
+
export type Selector<T, R> = (t: T) => R;
|
|
22
22
|
export declare function useStore<T, R>(store: Store<T>, selector: Selector<T, R>): R;
|
|
23
23
|
export declare function useStore<T>(store: Store<T>, selector?: undefined): T;
|
|
24
24
|
export declare const useStore: <T, R>(store: Store<T>, selector?: Selector<T, R>) => R;
|
package/store/Store.js
CHANGED
|
@@ -4,6 +4,16 @@ import { useSyncExternalStore } from '../ReactConstants.js';
|
|
|
4
4
|
|
|
5
5
|
const STORES = new Map();
|
|
6
6
|
class AbstractStore {
|
|
7
|
+
get;
|
|
8
|
+
set;
|
|
9
|
+
reset;
|
|
10
|
+
/**
|
|
11
|
+
* Return unsubscribe function
|
|
12
|
+
*
|
|
13
|
+
* @returns unsubscribe function.
|
|
14
|
+
*/
|
|
15
|
+
subscribe;
|
|
16
|
+
toString;
|
|
7
17
|
}
|
|
8
18
|
class Store extends AbstractStore {
|
|
9
19
|
constructor(initialState, name) {
|
|
@@ -26,7 +36,7 @@ class Store extends AbstractStore {
|
|
|
26
36
|
result = proxy.bake();
|
|
27
37
|
}
|
|
28
38
|
else if (isObject(setter)) {
|
|
29
|
-
result =
|
|
39
|
+
result = { ...value, ...setter };
|
|
30
40
|
}
|
|
31
41
|
else {
|
|
32
42
|
result = setter;
|
package/store/Store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Store.js","sources":["../src/store/Store.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAA;AAM5C,MAAe,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"Store.js","sources":["../src/store/Store.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAA;AAM5C,MAAe,a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AACnB,SAAC,CAAA;AACD,QAAA,IAAI,CAAC,KAAK,GAAG,MAAK;YACd,KAAK,GAAG,YAAY,CAAA;AACpB,YAAA,YAAY,EAAE,CAAC;AACnB,SAAC,CAAA;AAED,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC,EAAc,KAAI;AAChC,YAAA,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;AACrB,YAAA,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AACtB,YAAA,OAAO,MAAK;AACR,gBAAA,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACzB,aAAC,CAAA;AACL,SAAC,CAAA;AAED,QAAA,IAAI,CAAC,QAAQ,GAAG,MAAc,IAAI,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAA;KAC7B;AACJ,CAAA;SAIe,cAAc,GAAA;AAC1B,IAAA,OAAO,MAAM,CAAA;AACjB,CAAC;AAQD;AACa,MAAA,QAAQ,GAAG,CAAO,KAAe,EAAE,QAAyB,KACrE,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG;;;;"}
|
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
|
-
};
|