anu-verzum 1.0.0
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/README.md +1997 -0
- package/babel-preset.js +13 -0
- package/dist/core/components/AnulyticsProvider.js +227 -0
- package/dist/core/components/Component.js +34 -0
- package/dist/core/components/Connector.js +133 -0
- package/dist/core/components/Context.js +98 -0
- package/dist/core/components/Feature.js +24 -0
- package/dist/core/components/Fragment.js +24 -0
- package/dist/core/components/History.js +163 -0
- package/dist/core/components/Intl.js +168 -0
- package/dist/core/domUtils.js +95 -0
- package/dist/core/elements.js +26 -0
- package/dist/core/reconciler.js +379 -0
- package/dist/index.js +55 -0
- package/dist/misc/async.js +24 -0
- package/dist/misc/polyfill.js +1 -0
- package/dist/misc/utils.js +27 -0
- package/dist/server-api/server-api.js +111 -0
- package/dist/store/store.js +171 -0
- package/package.json +43 -0
package/babel-preset.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.trackStateChange = exports.trackRouteChange = exports.trackEvent = exports.default = void 0;
|
|
7
|
+
var _Component = require("./Component");
|
|
8
|
+
var _serverApi = _interopRequireDefault(require("../../server-api/server-api"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
const EventTypes = {
|
|
11
|
+
INITIALIZATION: 'initialization',
|
|
12
|
+
USER_ACTION: 'userAction',
|
|
13
|
+
STATE_CHANGE: 'stateChange',
|
|
14
|
+
NAVIGATION: 'navigation',
|
|
15
|
+
PAGE_LEAVE: 'pageLeave'
|
|
16
|
+
};
|
|
17
|
+
const AnulyticsState = (() => {
|
|
18
|
+
const initStart = new Date().getTime();
|
|
19
|
+
let _anulyticsInstanceExist = false;
|
|
20
|
+
const setAnulyticsInstanceExist = instanceExist => {
|
|
21
|
+
_anulyticsInstanceExist = instanceExist;
|
|
22
|
+
};
|
|
23
|
+
const getAnulyticsInstanceExist = () => _anulyticsInstanceExist;
|
|
24
|
+
let _anulytics = {
|
|
25
|
+
startDate: initStart,
|
|
26
|
+
events: [{
|
|
27
|
+
[EventTypes.INITIALIZATION]: {
|
|
28
|
+
eventType: window.location.pathname,
|
|
29
|
+
timestamp: initStart,
|
|
30
|
+
properties: {}
|
|
31
|
+
}
|
|
32
|
+
}],
|
|
33
|
+
user: {}
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
getAnulyticsInstanceExist,
|
|
37
|
+
setAnulyticsInstanceExist,
|
|
38
|
+
addEvent: (key, val) => {
|
|
39
|
+
_anulytics.events.push({
|
|
40
|
+
[key]: val
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
trackEvent: ({
|
|
44
|
+
type,
|
|
45
|
+
keyCode = null,
|
|
46
|
+
pageX = 0,
|
|
47
|
+
pageY = 0,
|
|
48
|
+
target: {
|
|
49
|
+
id,
|
|
50
|
+
name,
|
|
51
|
+
nodeName,
|
|
52
|
+
value
|
|
53
|
+
} = {
|
|
54
|
+
id: '',
|
|
55
|
+
name: '',
|
|
56
|
+
nodeName: '',
|
|
57
|
+
value: ''
|
|
58
|
+
}
|
|
59
|
+
}, rawProps) => {
|
|
60
|
+
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
|
|
61
|
+
const scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
|
|
62
|
+
const props = typeof rawProps === 'object' && !Array.isArray(rawProps) ? rawProps : null;
|
|
63
|
+
const event = {
|
|
64
|
+
[EventTypes.USER_ACTION]: {
|
|
65
|
+
eventType: type,
|
|
66
|
+
timestamp: new Date().getTime(),
|
|
67
|
+
properties: {
|
|
68
|
+
id,
|
|
69
|
+
keyCode,
|
|
70
|
+
name,
|
|
71
|
+
nodeName,
|
|
72
|
+
value,
|
|
73
|
+
pageX,
|
|
74
|
+
pageY,
|
|
75
|
+
scrollTop,
|
|
76
|
+
scrollLeft,
|
|
77
|
+
url: window.location.pathname,
|
|
78
|
+
props
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
_anulytics.events.push(event);
|
|
83
|
+
},
|
|
84
|
+
trackStateChange: (prevState, action, nextState) => {
|
|
85
|
+
const event = {
|
|
86
|
+
[EventTypes.STATE_CHANGE]: {
|
|
87
|
+
eventType: action.type,
|
|
88
|
+
timestamp: new Date().getTime(),
|
|
89
|
+
properties: {
|
|
90
|
+
url: window.location.pathname,
|
|
91
|
+
prevState,
|
|
92
|
+
action,
|
|
93
|
+
nextState
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
_anulytics.events.push(event);
|
|
98
|
+
},
|
|
99
|
+
setUser: user => {
|
|
100
|
+
_anulytics.user = user || {};
|
|
101
|
+
},
|
|
102
|
+
getAnulyticsData: () => _anulytics
|
|
103
|
+
};
|
|
104
|
+
})();
|
|
105
|
+
const _isBot = window.phantom || window._phantom || window.__nightmare || window.navigator.webdriver || window.Cypress;
|
|
106
|
+
const _isInstalled = () => {
|
|
107
|
+
if (window.navigator.standalone) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (window.matchMedia('(display-mode: standalone)').matches) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
115
|
+
const trackEvent = (event, props) => {
|
|
116
|
+
if (AnulyticsState.getAnulyticsInstanceExist()) {
|
|
117
|
+
AnulyticsState.trackEvent(event, props);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
exports.trackEvent = trackEvent;
|
|
121
|
+
const trackStateChange = (prevState, action, nextState) => {
|
|
122
|
+
if (AnulyticsState.getAnulyticsInstanceExist()) {
|
|
123
|
+
AnulyticsState.trackStateChange(prevState, action, nextState);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.trackStateChange = trackStateChange;
|
|
127
|
+
const trackRouteChange = path => {
|
|
128
|
+
if (AnulyticsState.getAnulyticsInstanceExist()) {
|
|
129
|
+
const url = path || window.location.pathname;
|
|
130
|
+
const event = {
|
|
131
|
+
eventType: url,
|
|
132
|
+
timestamp: new Date().getTime(),
|
|
133
|
+
properties: {}
|
|
134
|
+
};
|
|
135
|
+
AnulyticsState.addEvent(EventTypes.NAVIGATION, event);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
exports.trackRouteChange = trackRouteChange;
|
|
139
|
+
class AnulyticsProvider extends _Component.Component {
|
|
140
|
+
constructor(props) {
|
|
141
|
+
super(props);
|
|
142
|
+
AnulyticsState.setAnulyticsInstanceExist(true);
|
|
143
|
+
this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
|
|
144
|
+
}
|
|
145
|
+
componentDidMount() {
|
|
146
|
+
const {
|
|
147
|
+
userData
|
|
148
|
+
} = this.props;
|
|
149
|
+
AnulyticsState.setUser(userData);
|
|
150
|
+
document.addEventListener('visibilitychange', this.handleVisibilityChange, {
|
|
151
|
+
passive: true
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
componentWillUnmount() {
|
|
155
|
+
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
|
|
156
|
+
AnulyticsState.setAnulyticsInstanceExist(false);
|
|
157
|
+
}
|
|
158
|
+
handleVisibilityChange() {
|
|
159
|
+
const {
|
|
160
|
+
analyticsUrl,
|
|
161
|
+
onSuccess,
|
|
162
|
+
onFail
|
|
163
|
+
} = this.props;
|
|
164
|
+
if (_isBot) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (document.visibilityState === 'hidden') {
|
|
168
|
+
const url = window.location.pathname;
|
|
169
|
+
const event = {
|
|
170
|
+
eventType: url,
|
|
171
|
+
timestamp: new Date().getTime(),
|
|
172
|
+
properties: {}
|
|
173
|
+
};
|
|
174
|
+
let ua;
|
|
175
|
+
AnulyticsState.addEvent(EventTypes.PAGE_LEAVE, event);
|
|
176
|
+
if (window.navigator.userAgentData) {
|
|
177
|
+
const {
|
|
178
|
+
brands,
|
|
179
|
+
mobile,
|
|
180
|
+
platform
|
|
181
|
+
} = window.navigator.userAgentData;
|
|
182
|
+
ua = {
|
|
183
|
+
userAgent: brands,
|
|
184
|
+
mobile,
|
|
185
|
+
platform
|
|
186
|
+
};
|
|
187
|
+
} else {
|
|
188
|
+
ua = {
|
|
189
|
+
userAgent: window.navigator.userAgent,
|
|
190
|
+
mobile: false,
|
|
191
|
+
platform: ''
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const data = {
|
|
195
|
+
...AnulyticsState.getAnulyticsData(),
|
|
196
|
+
endDate: new Date().getTime(),
|
|
197
|
+
system: {
|
|
198
|
+
referrer: document.referrer || null,
|
|
199
|
+
innerWidth: window.innerWidth,
|
|
200
|
+
isMobileAppInstalled: _isInstalled(),
|
|
201
|
+
userAgentData: ua
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
_serverApi.default.post(analyticsUrl, data).then(({
|
|
205
|
+
response
|
|
206
|
+
}) => onSuccess(response)).catch(({
|
|
207
|
+
status
|
|
208
|
+
}) => onFail(status));
|
|
209
|
+
} else {
|
|
210
|
+
this.setState();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
render() {
|
|
214
|
+
const {
|
|
215
|
+
children
|
|
216
|
+
} = this.props;
|
|
217
|
+
try {
|
|
218
|
+
if (children.length !== 1) {
|
|
219
|
+
throw new Error('Provider must have one child element!');
|
|
220
|
+
}
|
|
221
|
+
return children;
|
|
222
|
+
} catch (err) {
|
|
223
|
+
console.error(err);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
var _default = exports.default = AnulyticsProvider;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Component = void 0;
|
|
7
|
+
var _reconciler = require("../reconciler");
|
|
8
|
+
class Component {
|
|
9
|
+
constructor(props, context) {
|
|
10
|
+
this.props = props || {};
|
|
11
|
+
this.context = {
|
|
12
|
+
...this.context,
|
|
13
|
+
...context
|
|
14
|
+
} || {};
|
|
15
|
+
this.state = this.state || {};
|
|
16
|
+
}
|
|
17
|
+
setState(partialState = {}) {
|
|
18
|
+
let partialStateObject = this.state;
|
|
19
|
+
let partialStateCallback;
|
|
20
|
+
if (typeof partialState === 'object') {
|
|
21
|
+
partialStateObject = {
|
|
22
|
+
...partialStateObject,
|
|
23
|
+
...partialState
|
|
24
|
+
};
|
|
25
|
+
} else if (typeof partialState === 'function') {
|
|
26
|
+
partialStateCallback = partialState;
|
|
27
|
+
}
|
|
28
|
+
(0, _reconciler.scheduleUpdate)(this, partialStateObject, partialStateCallback);
|
|
29
|
+
}
|
|
30
|
+
componentDidMount() {}
|
|
31
|
+
componentDidUpdate(prevProps, prevState) {}
|
|
32
|
+
componentWillUnmount() {}
|
|
33
|
+
}
|
|
34
|
+
exports.Component = Component;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _elements = require("../elements");
|
|
8
|
+
var _Component = require("./Component");
|
|
9
|
+
const providedStore = (context = {}) => {
|
|
10
|
+
let providerContext = {
|
|
11
|
+
...context
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
getContext: () => providerContext,
|
|
15
|
+
setContext: context => {
|
|
16
|
+
providerContext = {
|
|
17
|
+
...providerContext,
|
|
18
|
+
...context
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const providerStore = providedStore();
|
|
24
|
+
class Provider extends _Component.Component {
|
|
25
|
+
constructor(props, context) {
|
|
26
|
+
super(props, context);
|
|
27
|
+
this.store = props.store;
|
|
28
|
+
this.context.store = props.store;
|
|
29
|
+
this.context.parentSub = null;
|
|
30
|
+
providerStore.setContext({
|
|
31
|
+
...this.context
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
const {
|
|
36
|
+
children
|
|
37
|
+
} = this.props;
|
|
38
|
+
try {
|
|
39
|
+
if (children.length !== 1) {
|
|
40
|
+
throw new Error('Provider must have one child element!');
|
|
41
|
+
}
|
|
42
|
+
return children;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error(err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class Subscription {
|
|
49
|
+
constructor(store, parentSub, onStateChange) {
|
|
50
|
+
this.store = store;
|
|
51
|
+
this.parentSub = parentSub;
|
|
52
|
+
this.onStateChange = onStateChange;
|
|
53
|
+
this.subscribed = false;
|
|
54
|
+
this.listeners = [];
|
|
55
|
+
}
|
|
56
|
+
notifyNestedSubs() {
|
|
57
|
+
this.listeners.forEach(listener => listener());
|
|
58
|
+
}
|
|
59
|
+
trySubscribe() {
|
|
60
|
+
if (!this.subscribed) {
|
|
61
|
+
if (this.parentSub !== null) {
|
|
62
|
+
this.parentSub.addNestedSub(this.onStateChange);
|
|
63
|
+
} else {
|
|
64
|
+
this.store.subscribe(this.onStateChange);
|
|
65
|
+
}
|
|
66
|
+
this.subscribed = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
addNestedSub(listener) {
|
|
70
|
+
this.trySubscribe();
|
|
71
|
+
this.listeners.push(listener);
|
|
72
|
+
}
|
|
73
|
+
tryUnsubscribe() {
|
|
74
|
+
if (this.subscribed) {
|
|
75
|
+
if (this.parentSub !== null) {
|
|
76
|
+
this.parentSub.removeNestedSub(this.onStateChange);
|
|
77
|
+
} else {
|
|
78
|
+
this.store.unsubscribe(this.onStateChange);
|
|
79
|
+
}
|
|
80
|
+
this.subscribed = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
removeNestedSub(listener) {
|
|
84
|
+
this.tryUnsubscribe();
|
|
85
|
+
const index = this.listeners.indexOf(listener);
|
|
86
|
+
if (index >= 0) {
|
|
87
|
+
this.listeners.splice(index, 1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const connectHOC = (mapStateToProps, mapDispatchToProps) => WrappedComponent => {
|
|
92
|
+
class Connect extends _Component.Component {
|
|
93
|
+
constructor(props, context) {
|
|
94
|
+
super(props, context);
|
|
95
|
+
this.context = {
|
|
96
|
+
...this.context,
|
|
97
|
+
...providerStore.getContext()
|
|
98
|
+
};
|
|
99
|
+
this.store = this.context.store;
|
|
100
|
+
const parentSub = this.context.parentSub;
|
|
101
|
+
this.subscription = new Subscription(this.store, parentSub, this.onStateChange.bind(this));
|
|
102
|
+
this.context.parentSub = this.subscription;
|
|
103
|
+
}
|
|
104
|
+
componentDidMount() {
|
|
105
|
+
this.subscription.trySubscribe();
|
|
106
|
+
}
|
|
107
|
+
componentWillUnmount() {
|
|
108
|
+
this.subscription.tryUnsubscribe();
|
|
109
|
+
}
|
|
110
|
+
componentDidUpdate() {
|
|
111
|
+
this.subscription.notifyNestedSubs();
|
|
112
|
+
}
|
|
113
|
+
onStateChange() {
|
|
114
|
+
this.setState({});
|
|
115
|
+
}
|
|
116
|
+
render() {
|
|
117
|
+
const stateProps = mapStateToProps ? mapStateToProps(this.store.getState(), this.props) : {};
|
|
118
|
+
const dispatchProps = mapDispatchToProps ? mapDispatchToProps(this.store.dispatch, this.props) : {};
|
|
119
|
+
const passedProps = {
|
|
120
|
+
...this.props,
|
|
121
|
+
...stateProps,
|
|
122
|
+
...dispatchProps
|
|
123
|
+
};
|
|
124
|
+
return (0, _elements.createElement)(WrappedComponent, passedProps);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return Connect;
|
|
128
|
+
};
|
|
129
|
+
const Connector = {
|
|
130
|
+
connect: connectHOC,
|
|
131
|
+
Provider
|
|
132
|
+
};
|
|
133
|
+
var _default = exports.default = Connector;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createContext = void 0;
|
|
7
|
+
var _utils = require("../../misc/utils");
|
|
8
|
+
var _Component = require("./Component");
|
|
9
|
+
const createContext = context => {
|
|
10
|
+
const providerContext = {
|
|
11
|
+
defaultContext: {
|
|
12
|
+
value: context
|
|
13
|
+
},
|
|
14
|
+
value: {}
|
|
15
|
+
};
|
|
16
|
+
const getPureProps = props => {
|
|
17
|
+
const pureProps = {};
|
|
18
|
+
Object.keys(props).forEach(key => {
|
|
19
|
+
if (key !== 'children') {
|
|
20
|
+
pureProps[key] = props[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return pureProps;
|
|
24
|
+
};
|
|
25
|
+
class ContextProvider extends _Component.Component {
|
|
26
|
+
constructor(props) {
|
|
27
|
+
super(props);
|
|
28
|
+
providerContext.value = {
|
|
29
|
+
...getPureProps(props)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
componentDidUpdate() {
|
|
33
|
+
const pureProps = getPureProps(this.props);
|
|
34
|
+
if (!(0, _utils.deepEqual)(providerContext.value, pureProps)) {
|
|
35
|
+
providerContext.value = {
|
|
36
|
+
...pureProps
|
|
37
|
+
};
|
|
38
|
+
this.setState();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
render() {
|
|
42
|
+
const {
|
|
43
|
+
children
|
|
44
|
+
} = this.props;
|
|
45
|
+
try {
|
|
46
|
+
if (children.length !== 1) {
|
|
47
|
+
throw new Error('Context Component must have exactly one child element!');
|
|
48
|
+
}
|
|
49
|
+
return children;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error(err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class ContextConsumer extends _Component.Component {
|
|
56
|
+
constructor(props) {
|
|
57
|
+
super(props);
|
|
58
|
+
}
|
|
59
|
+
componentDidUpdate() {
|
|
60
|
+
if (providerContext.__notifySub) {
|
|
61
|
+
this.setState();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
const {
|
|
66
|
+
children
|
|
67
|
+
} = this.props;
|
|
68
|
+
const {
|
|
69
|
+
value,
|
|
70
|
+
defaultContext
|
|
71
|
+
} = providerContext;
|
|
72
|
+
try {
|
|
73
|
+
if (children.length !== 1) {
|
|
74
|
+
throw new Error('Context Component must have exactly one child element!');
|
|
75
|
+
}
|
|
76
|
+
const {
|
|
77
|
+
type
|
|
78
|
+
} = children[0];
|
|
79
|
+
const childProps = {
|
|
80
|
+
value,
|
|
81
|
+
defaultContext
|
|
82
|
+
};
|
|
83
|
+
if (typeof type === 'function') {
|
|
84
|
+
return type(childProps);
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error('Context component child element must be a function!');
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
console.error(err);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
Provider: ContextProvider,
|
|
95
|
+
Consumer: ContextConsumer
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
exports.createContext = createContext;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _elements = require("../elements");
|
|
8
|
+
var _Context = require("./Context");
|
|
9
|
+
const defaultFeatures = {};
|
|
10
|
+
const FeaturesContext = (0, _Context.createContext)(defaultFeatures);
|
|
11
|
+
const FeatureToggle = ({
|
|
12
|
+
name,
|
|
13
|
+
children,
|
|
14
|
+
defaultComponent = null
|
|
15
|
+
}) => (0, _elements.createElement)(FeaturesContext.ContextConsumer, {}, ({
|
|
16
|
+
value: {
|
|
17
|
+
features
|
|
18
|
+
}
|
|
19
|
+
}) => features[name] === true ? children : defaultComponent);
|
|
20
|
+
const Feature = {
|
|
21
|
+
Provider: FeaturesContext.ContextProvider,
|
|
22
|
+
Toggle: FeatureToggle
|
|
23
|
+
};
|
|
24
|
+
var _default = exports.default = Feature;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Fragment = void 0;
|
|
7
|
+
var _Component = require("./Component");
|
|
8
|
+
class Fragment extends _Component.Component {
|
|
9
|
+
render() {
|
|
10
|
+
const {
|
|
11
|
+
children
|
|
12
|
+
} = this.props;
|
|
13
|
+
try {
|
|
14
|
+
if (!children.length) {
|
|
15
|
+
throw new Error('Fragment must have at least one child element!');
|
|
16
|
+
}
|
|
17
|
+
return children;
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error(err);
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Fragment = Fragment;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.goTo = exports.default = void 0;
|
|
7
|
+
var _elements = require("../elements");
|
|
8
|
+
var _Component = require("./Component");
|
|
9
|
+
var _AnulyticsProvider = require("./AnulyticsProvider");
|
|
10
|
+
const instances = [];
|
|
11
|
+
const register = comp => {
|
|
12
|
+
instances.push(comp);
|
|
13
|
+
};
|
|
14
|
+
const unregister = comp => {
|
|
15
|
+
const index = instances.indexOf(comp);
|
|
16
|
+
if (index >= 0) {
|
|
17
|
+
instances.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const hasHistoryAPI = typeof window !== 'undefined' && typeof window.history !== 'undefined' && typeof window.history.pushState === 'function';
|
|
21
|
+
const historyPush = path => {
|
|
22
|
+
(0, _AnulyticsProvider.trackRouteChange)(path);
|
|
23
|
+
if (hasHistoryAPI) {
|
|
24
|
+
history.pushState({}, null, path);
|
|
25
|
+
} else {
|
|
26
|
+
console.warn('History API not available - running in non-browser environment');
|
|
27
|
+
}
|
|
28
|
+
instances.forEach(instance => {
|
|
29
|
+
instance.setState();
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const historyReplace = path => {
|
|
33
|
+
(0, _AnulyticsProvider.trackRouteChange)(path);
|
|
34
|
+
if (hasHistoryAPI) {
|
|
35
|
+
history.replaceState({}, null, path);
|
|
36
|
+
} else {
|
|
37
|
+
console.warn('History API not available - running in non-browser environment');
|
|
38
|
+
}
|
|
39
|
+
instances.forEach(instance => {
|
|
40
|
+
instance.setState();
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const matchPath = (pathname, options) => {
|
|
44
|
+
const {
|
|
45
|
+
exact = false,
|
|
46
|
+
path
|
|
47
|
+
} = options;
|
|
48
|
+
if (!path) {
|
|
49
|
+
return {
|
|
50
|
+
path: null,
|
|
51
|
+
url: pathname,
|
|
52
|
+
isExact: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const match = new RegExp(`^${path}`).exec(pathname);
|
|
56
|
+
if (!match) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const url = match[0];
|
|
60
|
+
const isExact = pathname === url;
|
|
61
|
+
if (exact && !isExact) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
path,
|
|
66
|
+
url,
|
|
67
|
+
isExact
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
class HistoryRoute extends _Component.Component {
|
|
71
|
+
constructor(props) {
|
|
72
|
+
super(props);
|
|
73
|
+
this.handlePop = this.handlePop.bind(this);
|
|
74
|
+
}
|
|
75
|
+
componentDidMount() {
|
|
76
|
+
window.addEventListener("popstate", this.handlePop);
|
|
77
|
+
register(this);
|
|
78
|
+
}
|
|
79
|
+
componentWillUnmount() {
|
|
80
|
+
unregister(this);
|
|
81
|
+
window.removeEventListener("popstate", this.handlePop);
|
|
82
|
+
}
|
|
83
|
+
handlePop() {
|
|
84
|
+
this.setState();
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
const {
|
|
88
|
+
path,
|
|
89
|
+
exact,
|
|
90
|
+
component,
|
|
91
|
+
render
|
|
92
|
+
} = this.props;
|
|
93
|
+
const match = matchPath(window.location.pathname, {
|
|
94
|
+
path,
|
|
95
|
+
exact
|
|
96
|
+
});
|
|
97
|
+
if (match !== null) {
|
|
98
|
+
if (component) {
|
|
99
|
+
return (0, _elements.createElement)(component, {
|
|
100
|
+
match
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (render) {
|
|
104
|
+
return render({
|
|
105
|
+
match
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class HistoryLink extends _Component.Component {
|
|
113
|
+
constructor(props) {
|
|
114
|
+
super(props);
|
|
115
|
+
this.handleClick = this.handleClick.bind(this);
|
|
116
|
+
}
|
|
117
|
+
handleClick(event) {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
const {
|
|
120
|
+
replace,
|
|
121
|
+
to
|
|
122
|
+
} = this.props;
|
|
123
|
+
replace ? historyReplace(to) : historyPush(to);
|
|
124
|
+
}
|
|
125
|
+
render() {
|
|
126
|
+
const {
|
|
127
|
+
to,
|
|
128
|
+
children,
|
|
129
|
+
...restProps
|
|
130
|
+
} = this.props;
|
|
131
|
+
const {
|
|
132
|
+
ariaLabel
|
|
133
|
+
} = restProps;
|
|
134
|
+
return (0, _elements.createElement)('a', {
|
|
135
|
+
href: to,
|
|
136
|
+
ariaLabel: `historyLink${ariaLabel ? `-${ariaLabel}` : ''}`,
|
|
137
|
+
onClick: this.handleClick,
|
|
138
|
+
...restProps
|
|
139
|
+
}, children);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
class HistoryRedirect extends _Component.Component {
|
|
143
|
+
componentDidMount() {
|
|
144
|
+
const {
|
|
145
|
+
to,
|
|
146
|
+
push
|
|
147
|
+
} = this.props;
|
|
148
|
+
push ? historyPush(to) : historyReplace(to);
|
|
149
|
+
}
|
|
150
|
+
render() {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const goTo = (path = '/', replace) => {
|
|
155
|
+
replace ? historyReplace(path) : historyPush(path);
|
|
156
|
+
};
|
|
157
|
+
exports.goTo = goTo;
|
|
158
|
+
const History = {
|
|
159
|
+
Link: HistoryLink,
|
|
160
|
+
Redirect: HistoryRedirect,
|
|
161
|
+
Route: HistoryRoute
|
|
162
|
+
};
|
|
163
|
+
var _default = exports.default = History;
|