@shopgate/pwa-common 7.30.0-alpha.9 → 7.30.0-beta.1
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/App.js +28 -13
- package/actions/app/handleUniversalLink.js +0 -2
- package/collections/AuthRoutes.js +15 -13
- package/collections/Configuration.js +11 -10
- package/collections/EmbeddedMedia.js +21 -19
- package/collections/PersistedReducers.js +11 -9
- package/collections/Redirects.js +15 -13
- package/collections/media-providers/MediaProvider.js +23 -21
- package/collections/media-providers/Vimeo.js +28 -22
- package/collections/media-providers/YouTube.js +17 -10
- package/components/Backdrop/index.js +15 -13
- package/components/Backdrop/spec.js +3 -2
- package/components/Button/index.js +41 -29
- package/components/Button/spec.js +16 -10
- package/components/Checkbox/index.js +36 -28
- package/components/Checkbox/spec.js +40 -27
- package/components/Consume/index.js +4 -1
- package/components/CountdownTimer/index.js +27 -20
- package/components/CountdownTimer/spec.js +2 -1
- package/components/Drawer/index.js +31 -23
- package/components/Drawer/spec.js +7 -6
- package/components/Dropdown/index.js +27 -18
- package/components/Ellipsis/index.js +5 -3
- package/components/Ellipsis/spec.js +5 -3
- package/components/EmbeddedMedia/index.js +9 -6
- package/components/EmbeddedMedia/spec.js +11 -2
- package/components/ErrorBoundary/index.js +26 -16
- package/components/Grid/components/Item/index.js +13 -6
- package/components/Grid/components/Item/spec.js +4 -3
- package/components/Grid/index.js +13 -6
- package/components/Grid/spec.js +4 -3
- package/components/HtmlSanitizer/index.js +42 -45
- package/components/HtmlSanitizer/spec.js +16 -12
- package/components/I18n/components/FormatDate/index.js +11 -4
- package/components/I18n/components/FormatDate/spec.js +22 -14
- package/components/I18n/components/FormatNumber/index.js +8 -6
- package/components/I18n/components/FormatNumber/spec.js +10 -5
- package/components/I18n/components/FormatPrice/index.js +5 -3
- package/components/I18n/components/FormatPrice/spec.js +22 -14
- package/components/I18n/components/FormatTime/index.js +11 -4
- package/components/I18n/components/FormatTime/spec.js +22 -14
- package/components/I18n/components/I18nProvider/index.js +18 -11
- package/components/I18n/components/I18nProvider/spec.js +2 -1
- package/components/I18n/components/Placeholder/index.js +10 -3
- package/components/I18n/components/Placeholder/spec.js +12 -5
- package/components/I18n/components/Translate/index.js +12 -8
- package/components/I18n/components/Translate/spec.js +9 -6
- package/components/Icon/index.js +2 -1
- package/components/Image/Image.js +23 -21
- package/components/Image/ImageInner.js +2 -1
- package/components/InfiniteContainer/index.js +59 -53
- package/components/InfiniteContainer/spec.js +10 -5
- package/components/Input/components/MultiLineInput.js +33 -26
- package/components/Input/components/SimpleInput.js +70 -54
- package/components/Input/index.js +7 -17
- package/components/Input/spec.js +12 -11
- package/components/KeyboardConsumer/index.js +19 -13
- package/components/Link/index.js +28 -20
- package/components/Link/spec.js +13 -9
- package/components/List/components/Item/index.js +5 -3
- package/components/List/index.js +5 -3
- package/components/List/spec.js +6 -9
- package/components/Loading/index.js +1 -3
- package/components/Modal/index.js +13 -10
- package/components/ModalContainer/spec.js +24 -20
- package/components/Picker/components/Button/index.js +18 -12
- package/components/Picker/components/List/index.js +19 -16
- package/components/Picker/components/Modal/index.js +34 -25
- package/components/Picker/index.js +44 -33
- package/components/Picker/spec.js +4 -1
- package/components/Portal/index.js +26 -17
- package/components/ProductCharacteristics/index.js +65 -57
- package/components/RangeSlider/components/Handle/index.js +7 -5
- package/components/RangeSlider/index.js +98 -84
- package/components/Route/RouteNotFound.js +30 -19
- package/components/Route/index.js +31 -21
- package/components/Router/index.js +51 -34
- package/components/ScannerContainer/index.js +17 -10
- package/components/Select/components/Item/index.js +5 -3
- package/components/Select/index.js +59 -47
- package/components/Select/spec.js +7 -6
- package/components/SelectBox/components/Item/index.js +23 -13
- package/components/SelectBox/index.js +83 -80
- package/components/SelectBox/spec.js +8 -5
- package/components/SurroundPortals/index.js +15 -11
- package/components/Swiper/components/SwiperItem/index.js +6 -5
- package/components/Swiper/components/SwiperItem/spec.js +8 -4
- package/components/Swiper/index.js +23 -20
- package/components/Toaster/index.js +4 -1
- package/components/Transition/index.js +19 -12
- package/components/Widgets/components/Widget/index.js +27 -16
- package/components/Widgets/components/Widget/spec.js +5 -4
- package/components/Widgets/components/WidgetGrid/index.js +27 -19
- package/components/Widgets/components/WidgetGrid/spec.js +4 -3
- package/components/Widgets/index.js +33 -26
- package/components/Widgets/spec.js +12 -13
- package/helpers/data/index.js +1 -1
- package/helpers/portals/portalCollection.js +13 -10
- package/helpers/redux/mutable.js +2 -2
- package/package.json +5 -5
- package/providers/loading/index.js +71 -57
- package/providers/toast/index.js +39 -28
- package/reducers/modal/index.js +1 -1
- package/store/index.js +1 -1
- package/subscriptions/helpers/buildRegisterUrl.js +1 -0
- package/components/Input/components/DateInput.js +0 -273
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
3
|
import React, { Component } from 'react';
|
|
2
4
|
import PropTypes from 'prop-types';
|
|
3
5
|
import { logger } from '@shopgate/pwa-core/helpers';
|
|
@@ -10,20 +12,22 @@ import { generateLinearEasingCallback, generateExponentialEasingCallback, getRan
|
|
|
10
12
|
* @deprecated Will be remove in v7.0.0.
|
|
11
13
|
* Please use `import { RangeSlider } from '@shopgate/engage/components'` instead.
|
|
12
14
|
*/
|
|
13
|
-
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
let RangeSlider = /*#__PURE__*/function (_Component) {
|
|
14
17
|
/**
|
|
15
18
|
* Constructor
|
|
16
19
|
* @param {Object} props The component properties
|
|
17
20
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
function RangeSlider(props) {
|
|
22
|
+
var _this;
|
|
23
|
+
_this = _Component.call(this, props) || this;
|
|
20
24
|
/**
|
|
21
25
|
* Processes touch start events on handles.
|
|
22
26
|
* @param {Object} event The touch event
|
|
23
27
|
* @param {number} index The index of the touched handle.
|
|
24
28
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
_this.handleTouchStart = (event, index) => {
|
|
30
|
+
_this.draggedHandle = index;
|
|
27
31
|
|
|
28
32
|
// Calculate the relative offset to the handles center
|
|
29
33
|
const handleDOMElement = event.target;
|
|
@@ -32,97 +36,100 @@ class RangeSlider extends Component {
|
|
|
32
36
|
// ... and calculate its absolute center.
|
|
33
37
|
const handleCenterX = handleRect.left + handleDOMElement.offsetWidth / 2;
|
|
34
38
|
// Store the signed distanced between the current touch offset and the handle center.
|
|
35
|
-
|
|
39
|
+
_this.touchOffset = getTouchPositionX(event) - handleCenterX;
|
|
36
40
|
};
|
|
37
41
|
/**
|
|
38
42
|
* Processes move events on handles.
|
|
39
43
|
* @param {Object} event The touch event
|
|
40
44
|
*/
|
|
41
|
-
|
|
42
|
-
if (
|
|
45
|
+
_this.handleTouchMove = event => {
|
|
46
|
+
if (_this.props.min === _this.props.max) {
|
|
43
47
|
return;
|
|
44
48
|
}
|
|
45
|
-
if (
|
|
49
|
+
if (_this.draggedHandle === null) {
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
48
52
|
const {
|
|
49
53
|
offsetWidth,
|
|
50
54
|
offsetLeft
|
|
51
|
-
} =
|
|
55
|
+
} = _this.domElement;
|
|
52
56
|
// Calculate the absolute offset where the element was touched...
|
|
53
|
-
let deltaX = getTouchPositionX(event) - offsetLeft -
|
|
57
|
+
let deltaX = getTouchPositionX(event) - offsetLeft - _this.touchOffset;
|
|
54
58
|
|
|
55
59
|
// ...and convert it into a relative value between [0...1].
|
|
56
60
|
deltaX = Math.max(0, Math.min(1, deltaX / offsetWidth));
|
|
57
61
|
const stateUpdate = {};
|
|
58
|
-
if (
|
|
62
|
+
if (_this.draggedHandle === 1) {
|
|
59
63
|
// Right handle dragged
|
|
60
|
-
if (
|
|
64
|
+
if (_this.state.rangeMin < deltaX) {
|
|
61
65
|
stateUpdate.rangeMax = Math.min(1, deltaX);
|
|
62
|
-
|
|
66
|
+
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMax - _this.state.rangeMax);
|
|
63
67
|
} else {
|
|
64
68
|
// Not in valid range, swap handles
|
|
65
|
-
|
|
66
|
-
stateUpdate.rangeMax =
|
|
69
|
+
_this.draggedHandle = 0;
|
|
70
|
+
stateUpdate.rangeMax = _this.state.rangeMin;
|
|
67
71
|
stateUpdate.rangeMin = deltaX;
|
|
68
|
-
|
|
72
|
+
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMin - _this.state.rangeMin);
|
|
69
73
|
}
|
|
70
|
-
} else if (
|
|
74
|
+
} else if (_this.draggedHandle === 0) {
|
|
71
75
|
// Left handle dragged
|
|
72
|
-
if (
|
|
76
|
+
if (_this.state.rangeMax > deltaX) {
|
|
73
77
|
stateUpdate.rangeMin = Math.max(0, deltaX);
|
|
74
|
-
|
|
78
|
+
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMin - _this.state.rangeMin);
|
|
75
79
|
} else {
|
|
76
80
|
// Not in valid range, swap handles
|
|
77
|
-
|
|
78
|
-
stateUpdate.rangeMin =
|
|
81
|
+
_this.draggedHandle = 1;
|
|
82
|
+
stateUpdate.rangeMin = _this.state.rangeMax;
|
|
79
83
|
stateUpdate.rangeMax = deltaX;
|
|
80
|
-
|
|
84
|
+
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMax - _this.state.rangeMax);
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
_this.draggedHandlePixelOffset *= _this.domElement.offsetWidth;
|
|
88
|
+
_this.setState(stateUpdate, _this.triggerChangeCallback);
|
|
85
89
|
};
|
|
86
90
|
/**
|
|
87
91
|
* Processes global touch end events for handles.
|
|
88
92
|
* @param {Object} e The touch event
|
|
89
93
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
_this.handleTouchEnd = () => {
|
|
95
|
+
_this.touchOffset = 0;
|
|
96
|
+
_this.draggedHandle = null;
|
|
93
97
|
};
|
|
94
98
|
/**
|
|
95
99
|
* Processes outer range touch end events.
|
|
96
100
|
* @param {Object} event The touch event
|
|
97
101
|
*/
|
|
98
|
-
|
|
102
|
+
_this.handleRangeTouch = event => {
|
|
99
103
|
const {
|
|
100
104
|
offsetWidth,
|
|
101
105
|
offsetLeft
|
|
102
|
-
} =
|
|
106
|
+
} = _this.domElement;
|
|
103
107
|
const dx = (getTouchPositionX(event) - offsetLeft) / offsetWidth;
|
|
104
|
-
const d0 = Math.abs(
|
|
105
|
-
const d1 = Math.abs(
|
|
108
|
+
const d0 = Math.abs(_this.state.rangeMin - dx);
|
|
109
|
+
const d1 = Math.abs(_this.state.rangeMax - dx);
|
|
106
110
|
if (d0 < d1) {
|
|
107
|
-
|
|
111
|
+
_this.draggedHandle = 0;
|
|
108
112
|
} else {
|
|
109
|
-
|
|
113
|
+
_this.draggedHandle = 1;
|
|
110
114
|
}
|
|
111
|
-
|
|
115
|
+
_this.handleTouchMove(event);
|
|
112
116
|
};
|
|
113
117
|
logger.warn('===== RangeSlider deprecated =====\nThe RangeSlider component and it\'s related components (@shopgate/pwa-common/component/RangeSlider) are deprecated and will be removed in @shopgate/engage v7.0.0.\nPlease use: import { RangeSlider } from \'@shopgate/engage/components\'.\n===================================');
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
_this.draggedHandle = null; // 0 for left handle, 1 for right handle or null
|
|
119
|
+
_this.domElement = null;
|
|
120
|
+
_this.touchOffset = 0;
|
|
121
|
+
_this.draggedHandlePixelOffset = 0; // The absolute pixel delta of the last handle move event.
|
|
118
122
|
|
|
119
|
-
|
|
123
|
+
_this.state = _this.getRange(props);
|
|
124
|
+
return _this;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
/**
|
|
123
128
|
* Sets the global event listeners when component mounts.
|
|
124
129
|
*/
|
|
125
|
-
|
|
130
|
+
_inheritsLoose(RangeSlider, _Component);
|
|
131
|
+
var _proto = RangeSlider.prototype;
|
|
132
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
126
133
|
document.addEventListener('touchend', this.handleTouchEnd);
|
|
127
134
|
document.addEventListener('touchmove', this.handleTouchMove);
|
|
128
135
|
}
|
|
@@ -130,45 +137,28 @@ class RangeSlider extends Component {
|
|
|
130
137
|
/**
|
|
131
138
|
* Updates the component properties.
|
|
132
139
|
* @param {Object} newProps The new component properties.
|
|
133
|
-
|
|
134
|
-
UNSAFE_componentWillReceiveProps(newProps) {
|
|
140
|
+
*/;
|
|
141
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(newProps) {
|
|
135
142
|
this.setState(this.getRange(newProps));
|
|
136
143
|
}
|
|
137
144
|
|
|
138
145
|
/**
|
|
139
146
|
* Removes the global event listeners when component unmounts.
|
|
140
|
-
|
|
141
|
-
componentWillUnmount() {
|
|
147
|
+
*/;
|
|
148
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
142
149
|
document.removeEventListener('touchend', this.handleTouchEnd);
|
|
143
150
|
document.removeEventListener('touchmove', this.handleTouchMove);
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
/**
|
|
147
154
|
* Get the easing function.
|
|
148
|
-
|
|
149
|
-
get ease() {
|
|
150
|
-
return {
|
|
151
|
-
linear: generateLinearEasingCallback(this.props.resolution),
|
|
152
|
-
exponential: generateExponentialEasingCallback(this.props.factor)
|
|
153
|
-
}[this.props.easing];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Get the function to invert an eased value to it's original value.
|
|
158
|
-
*/
|
|
159
|
-
get invertedEase() {
|
|
160
|
-
return {
|
|
161
|
-
linear: generateLinearEasingCallback(this.props.resolution),
|
|
162
|
-
exponential: generateExponentialEasingCallback(1 / this.props.factor)
|
|
163
|
-
}[this.props.easing];
|
|
164
|
-
}
|
|
165
|
-
|
|
155
|
+
*/;
|
|
166
156
|
/**
|
|
167
157
|
* Get range min and max from props.
|
|
168
158
|
* @param {Object} props The component props.
|
|
169
159
|
* @returns {Object} The new state
|
|
170
160
|
*/
|
|
171
|
-
getRange(props) {
|
|
161
|
+
_proto.getRange = function getRange(props) {
|
|
172
162
|
const {
|
|
173
163
|
value,
|
|
174
164
|
min,
|
|
@@ -178,11 +168,11 @@ class RangeSlider extends Component {
|
|
|
178
168
|
rangeMin: this.invertedEase(getRelativeValue(value[0], min, max)),
|
|
179
169
|
rangeMax: this.invertedEase(getRelativeValue(value[1], min, max))
|
|
180
170
|
};
|
|
181
|
-
}
|
|
171
|
+
};
|
|
182
172
|
/**
|
|
183
173
|
* Calls the change callback in case of a state update.
|
|
184
174
|
*/
|
|
185
|
-
triggerChangeCallback() {
|
|
175
|
+
_proto.triggerChangeCallback = function triggerChangeCallback() {
|
|
186
176
|
const {
|
|
187
177
|
value,
|
|
188
178
|
onChange,
|
|
@@ -202,9 +192,9 @@ class RangeSlider extends Component {
|
|
|
202
192
|
* Creates a new handle component.
|
|
203
193
|
* @param {number} index The index of the component. Must be either 0 or 1.
|
|
204
194
|
* @returns {JSX}
|
|
205
|
-
|
|
206
|
-
makeHandle(index) {
|
|
207
|
-
return /*#__PURE__*/
|
|
195
|
+
*/;
|
|
196
|
+
_proto.makeHandle = function makeHandle(index) {
|
|
197
|
+
return /*#__PURE__*/_jsx(RangeSliderHandle, {
|
|
208
198
|
index: index,
|
|
209
199
|
onTouchStart: this.handleTouchStart,
|
|
210
200
|
active: this.draggedHandle === index,
|
|
@@ -215,25 +205,49 @@ class RangeSlider extends Component {
|
|
|
215
205
|
/**
|
|
216
206
|
* Renders the component.
|
|
217
207
|
* @returns {JSX}
|
|
218
|
-
|
|
219
|
-
render() {
|
|
208
|
+
*/;
|
|
209
|
+
_proto.render = function render() {
|
|
220
210
|
// Calculate the animation speed.
|
|
221
211
|
const animationSpeed = Math.round(1000 / this.props.animationSpeed * this.draggedHandlePixelOffset);
|
|
222
212
|
const rangeStyle = getRangeStyle(this.state.rangeMin, this.state.rangeMax, animationSpeed > 10 ? animationSpeed : 0);
|
|
223
|
-
return /*#__PURE__*/
|
|
213
|
+
return /*#__PURE__*/_jsx("div", {
|
|
224
214
|
className: `${this.props.classNames.container || ''} common__range-slider`,
|
|
225
|
-
onTouchStart: this.handleRangeTouch
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
215
|
+
onTouchStart: this.handleRangeTouch,
|
|
216
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
217
|
+
className: `${this.props.classNames.outerRange || ''} ${styles.outerRange}`,
|
|
218
|
+
ref: ref => {
|
|
219
|
+
this.domElement = ref;
|
|
220
|
+
},
|
|
221
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
222
|
+
className: `${this.props.classNames.range || ''} ${styles.range}`,
|
|
223
|
+
style: rangeStyle,
|
|
224
|
+
children: [this.makeHandle(0), this.makeHandle(1)]
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
return _createClass(RangeSlider, [{
|
|
230
|
+
key: "ease",
|
|
231
|
+
get: function () {
|
|
232
|
+
return {
|
|
233
|
+
linear: generateLinearEasingCallback(this.props.resolution),
|
|
234
|
+
exponential: generateExponentialEasingCallback(this.props.factor)
|
|
235
|
+
}[this.props.easing];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get the function to invert an eased value to it's original value.
|
|
240
|
+
*/
|
|
241
|
+
}, {
|
|
242
|
+
key: "invertedEase",
|
|
243
|
+
get: function () {
|
|
244
|
+
return {
|
|
245
|
+
linear: generateLinearEasingCallback(this.props.resolution),
|
|
246
|
+
exponential: generateExponentialEasingCallback(1 / this.props.factor)
|
|
247
|
+
}[this.props.easing];
|
|
248
|
+
}
|
|
249
|
+
}]);
|
|
250
|
+
}(Component);
|
|
237
251
|
RangeSlider.defaultProps = {
|
|
238
252
|
animationSpeed: 500,
|
|
239
253
|
classNames: {},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import PropTypes from 'prop-types';
|
|
3
5
|
import { router } from '@virtuous/conductor';
|
|
@@ -7,21 +9,17 @@ import ErrorBoundary from "../ErrorBoundary";
|
|
|
7
9
|
/**
|
|
8
10
|
* The RouteNotFound component
|
|
9
11
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
get currentRoute() {
|
|
15
|
-
const {
|
|
16
|
-
[router.routeIndex]: [, route]
|
|
17
|
-
} = this.context.stack;
|
|
18
|
-
return route;
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
let RouteNotFound = /*#__PURE__*/function (_React$Component) {
|
|
14
|
+
function RouteNotFound() {
|
|
15
|
+
return _React$Component.apply(this, arguments) || this;
|
|
19
16
|
}
|
|
20
|
-
|
|
17
|
+
_inheritsLoose(RouteNotFound, _React$Component);
|
|
18
|
+
var _proto = RouteNotFound.prototype;
|
|
21
19
|
/**
|
|
22
20
|
* @returns {JSX}
|
|
23
21
|
*/
|
|
24
|
-
render() {
|
|
22
|
+
_proto.render = function render() {
|
|
25
23
|
if (router.match(this.currentRoute.pathname)) {
|
|
26
24
|
return null;
|
|
27
25
|
}
|
|
@@ -36,13 +34,26 @@ class RouteNotFound extends React.Component {
|
|
|
36
34
|
context.visible = true;
|
|
37
35
|
context.pattern = '';
|
|
38
36
|
context.is404 = true;
|
|
39
|
-
return /*#__PURE__*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
|
|
37
|
+
return /*#__PURE__*/_jsx(ErrorBoundary, {
|
|
38
|
+
children: /*#__PURE__*/_jsx(RouteContext.Provider, {
|
|
39
|
+
value: context,
|
|
40
|
+
children: /*#__PURE__*/_jsx(Component, {})
|
|
41
|
+
}, "404")
|
|
42
|
+
}, "error.404");
|
|
43
|
+
};
|
|
44
|
+
return _createClass(RouteNotFound, [{
|
|
45
|
+
key: "currentRoute",
|
|
46
|
+
get:
|
|
47
|
+
/**
|
|
48
|
+
* @returns {Object}
|
|
49
|
+
*/
|
|
50
|
+
function () {
|
|
51
|
+
const {
|
|
52
|
+
[router.routeIndex]: [, route]
|
|
53
|
+
} = this.context.stack;
|
|
54
|
+
return route;
|
|
55
|
+
}
|
|
56
|
+
}]);
|
|
57
|
+
}(React.Component);
|
|
47
58
|
RouteNotFound.contextType = RouterContext;
|
|
48
59
|
export default RouteNotFound;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
3
|
import React, { Suspense } from 'react';
|
|
2
4
|
import PropTypes from 'prop-types';
|
|
3
5
|
import { router } from '@virtuous/conductor';
|
|
@@ -9,29 +11,27 @@ import RouteNotFound from "./RouteNotFound";
|
|
|
9
11
|
/**
|
|
10
12
|
* The Route component.
|
|
11
13
|
*/
|
|
12
|
-
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
let Route = /*#__PURE__*/function (_React$Component) {
|
|
13
16
|
/**
|
|
14
17
|
* @param {Object} props The component props.
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
function Route(props) {
|
|
20
|
+
var _this;
|
|
21
|
+
_this = _React$Component.call(this, props) || this;
|
|
18
22
|
router.register(props.pattern, props.transform);
|
|
23
|
+
return _this;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* TODO: Move to router
|
|
23
28
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[router.routeIndex]: [, route]
|
|
27
|
-
} = this.context.stack;
|
|
28
|
-
return route;
|
|
29
|
-
}
|
|
30
|
-
|
|
29
|
+
_inheritsLoose(Route, _React$Component);
|
|
30
|
+
var _proto = Route.prototype;
|
|
31
31
|
/**
|
|
32
32
|
* @returns {JSX}
|
|
33
33
|
*/
|
|
34
|
-
render() {
|
|
34
|
+
_proto.render = function render() {
|
|
35
35
|
const {
|
|
36
36
|
cache,
|
|
37
37
|
component: Component,
|
|
@@ -67,17 +67,27 @@ class Route extends React.Component {
|
|
|
67
67
|
* to enforce re-remounting routes which where replaced by itself.
|
|
68
68
|
*/
|
|
69
69
|
const replaceRouteId = context?.state?.replaceRouteId || '';
|
|
70
|
-
return /*#__PURE__*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
return /*#__PURE__*/_jsx(ErrorBoundary, {
|
|
71
|
+
children: /*#__PURE__*/_jsx(RouteContext.Provider, {
|
|
72
|
+
value: context,
|
|
73
|
+
children: /*#__PURE__*/_jsx(Suspense, {
|
|
74
|
+
fallback: /*#__PURE__*/_jsx(Loading, {}),
|
|
75
|
+
children: /*#__PURE__*/_jsx(Component, {})
|
|
76
|
+
})
|
|
77
|
+
}, `${route.id}_${replaceRouteId}`)
|
|
78
|
+
}, `error.${route.id}_${replaceRouteId}`);
|
|
78
79
|
});
|
|
79
|
-
}
|
|
80
|
-
|
|
80
|
+
};
|
|
81
|
+
return _createClass(Route, [{
|
|
82
|
+
key: "currentRoute",
|
|
83
|
+
get: function () {
|
|
84
|
+
const {
|
|
85
|
+
[router.routeIndex]: [, route]
|
|
86
|
+
} = this.context.stack;
|
|
87
|
+
return route;
|
|
88
|
+
}
|
|
89
|
+
}]);
|
|
90
|
+
}(React.Component);
|
|
81
91
|
Route.contextType = RouterContext;
|
|
82
92
|
Route.NotFound = RouteNotFound;
|
|
83
93
|
Route.defaultProps = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import "core-js/modules/es.string.replace.js";
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
@@ -16,6 +17,7 @@ import connect from "./connector";
|
|
|
16
17
|
* Adds additional history listeners to compensate bugs and improve the behaviour within
|
|
17
18
|
* browser environments.
|
|
18
19
|
*/
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
21
|
const createBrowserListeners = () => {
|
|
20
22
|
const {
|
|
21
23
|
history
|
|
@@ -63,17 +65,18 @@ const createBrowserListeners = () => {
|
|
|
63
65
|
/**
|
|
64
66
|
* The Router component.
|
|
65
67
|
*/
|
|
66
|
-
|
|
68
|
+
let Router = /*#__PURE__*/function (_React$Component) {
|
|
67
69
|
/**
|
|
68
70
|
* @param {Object} props The component props.
|
|
69
71
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
function Router(props) {
|
|
73
|
+
var _this;
|
|
74
|
+
_this = _React$Component.call(this, props) || this;
|
|
72
75
|
/**
|
|
73
76
|
* Updates the user initialized component state
|
|
74
77
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
_this.setUserInitialized = () => {
|
|
79
|
+
_this.setState({
|
|
77
80
|
userInitialized: true
|
|
78
81
|
});
|
|
79
82
|
};
|
|
@@ -81,7 +84,7 @@ class Router extends React.Component {
|
|
|
81
84
|
* Determines the current location from the browser history
|
|
82
85
|
* @returns {string}
|
|
83
86
|
*/
|
|
84
|
-
|
|
87
|
+
_this.getHistoryLocation = () => {
|
|
85
88
|
const {
|
|
86
89
|
hash,
|
|
87
90
|
pathname,
|
|
@@ -93,11 +96,11 @@ class Router extends React.Component {
|
|
|
93
96
|
* Determines if the current route is a protected route
|
|
94
97
|
* @returns {null|string}
|
|
95
98
|
*/
|
|
96
|
-
|
|
99
|
+
_this.getRouteProtector = () => authRoutes.getProtector(_this.getHistoryLocation());
|
|
97
100
|
/**
|
|
98
101
|
* @param {Object} data Data for the update method
|
|
99
102
|
*/
|
|
100
|
-
|
|
103
|
+
_this.update = data => {
|
|
101
104
|
const {
|
|
102
105
|
prev,
|
|
103
106
|
next
|
|
@@ -107,12 +110,12 @@ class Router extends React.Component {
|
|
|
107
110
|
* The only change right now compared to the original component. When invoked for "onUpdate"
|
|
108
111
|
* only the updated route is passed instead of an object with prev and next.
|
|
109
112
|
*/
|
|
110
|
-
|
|
113
|
+
_this.setState({
|
|
111
114
|
updated: Date.now()
|
|
112
115
|
});
|
|
113
116
|
return;
|
|
114
117
|
}
|
|
115
|
-
|
|
118
|
+
_this.setState({
|
|
116
119
|
prev: prev ? prev.id : null,
|
|
117
120
|
next: next.id,
|
|
118
121
|
updated: Date.now()
|
|
@@ -121,22 +124,24 @@ class Router extends React.Component {
|
|
|
121
124
|
if (typeof props.history === 'function') {
|
|
122
125
|
router.constructor(props.history);
|
|
123
126
|
}
|
|
124
|
-
|
|
127
|
+
_this.contextValue = null;
|
|
128
|
+
_this.state = {
|
|
125
129
|
prev: null,
|
|
126
130
|
next: null,
|
|
127
131
|
updated: null,
|
|
128
132
|
userInitialized: false,
|
|
129
|
-
initialRouteProtected: !!
|
|
133
|
+
initialRouteProtected: !!_this.getRouteProtector()
|
|
130
134
|
};
|
|
131
|
-
UIEvents.addListener(EVENT_USER_INITIALIZED,
|
|
132
|
-
onDidPush(
|
|
133
|
-
onDidPop(
|
|
134
|
-
onDidReplace(
|
|
135
|
-
onDidReset(
|
|
136
|
-
onUpdate(
|
|
135
|
+
UIEvents.addListener(EVENT_USER_INITIALIZED, _this.setUserInitialized);
|
|
136
|
+
onDidPush(_this.update);
|
|
137
|
+
onDidPop(_this.update);
|
|
138
|
+
onDidReplace(_this.update);
|
|
139
|
+
onDidReset(_this.update);
|
|
140
|
+
onUpdate(_this.update);
|
|
137
141
|
if (hasWebBridge() || hasSGJavaScriptBridge()) {
|
|
138
142
|
createBrowserListeners();
|
|
139
143
|
}
|
|
144
|
+
return _this;
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
/**
|
|
@@ -144,7 +149,9 @@ class Router extends React.Component {
|
|
|
144
149
|
* @param {Object} nextState The next component state.
|
|
145
150
|
* @returns {boolean}
|
|
146
151
|
*/
|
|
147
|
-
|
|
152
|
+
_inheritsLoose(Router, _React$Component);
|
|
153
|
+
var _proto = Router.prototype;
|
|
154
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
148
155
|
const {
|
|
149
156
|
isUserLoggedIn
|
|
150
157
|
} = this.props;
|
|
@@ -159,8 +166,8 @@ class Router extends React.Component {
|
|
|
159
166
|
* Replaces the initial route with a protector if necessary
|
|
160
167
|
* @param {Object} nextProps The next component props
|
|
161
168
|
* @param {Object} nextState The next components state
|
|
162
|
-
|
|
163
|
-
UNSAFE_componentWillUpdate(nextProps, nextState) {
|
|
169
|
+
*/;
|
|
170
|
+
_proto.UNSAFE_componentWillUpdate = function UNSAFE_componentWillUpdate(nextProps, nextState) {
|
|
164
171
|
const {
|
|
165
172
|
isUserLoggedIn
|
|
166
173
|
} = nextProps;
|
|
@@ -203,6 +210,8 @@ class Router extends React.Component {
|
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
212
|
});
|
|
213
|
+
|
|
214
|
+
// eslint-disable-next-line react/no-will-update-set-state
|
|
206
215
|
this.setState({
|
|
207
216
|
initialRouteProtected: false
|
|
208
217
|
});
|
|
@@ -211,14 +220,14 @@ class Router extends React.Component {
|
|
|
211
220
|
|
|
212
221
|
/**
|
|
213
222
|
* Removes the listener for the EVENT_USER_INITIALIZED event
|
|
214
|
-
|
|
215
|
-
componentWillUnmount() {
|
|
223
|
+
*/;
|
|
224
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
216
225
|
UIEvents.removeListener(EVENT_USER_INITIALIZED, this.setUserInitialized);
|
|
217
|
-
}
|
|
226
|
+
};
|
|
218
227
|
/**
|
|
219
228
|
* @returns {JSX}
|
|
220
229
|
*/
|
|
221
|
-
render() {
|
|
230
|
+
_proto.render = function render() {
|
|
222
231
|
const {
|
|
223
232
|
children
|
|
224
233
|
} = this.props;
|
|
@@ -236,15 +245,23 @@ class Router extends React.Component {
|
|
|
236
245
|
return null;
|
|
237
246
|
}
|
|
238
247
|
const stack = Array.from(routeStack.getAll());
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
const nextContextValue = {
|
|
249
|
+
prev,
|
|
250
|
+
next,
|
|
251
|
+
stack
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// Only update the reference if something actually changed.
|
|
255
|
+
if (!this.contextValue || this.contextValue.prev !== prev || this.contextValue.next !== next || this.contextValue.stack !== stack) {
|
|
256
|
+
this.contextValue = nextContextValue;
|
|
257
|
+
}
|
|
258
|
+
return /*#__PURE__*/_jsx(RouterContext.Provider, {
|
|
259
|
+
value: this.contextValue,
|
|
260
|
+
children: children
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
return Router;
|
|
264
|
+
}(React.Component);
|
|
248
265
|
Router.defaultProps = {
|
|
249
266
|
history: null,
|
|
250
267
|
isUserLoggedIn: false
|