@lm_fe/components 0.2.2
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 +47 -0
- package/dist/keep-alive/common.d.ts +46 -0
- package/dist/keep-alive/components/AsyncComponent.d.ts +27 -0
- package/dist/keep-alive/components/Comment.d.ts +18 -0
- package/dist/keep-alive/components/Consumer.d.ts +20 -0
- package/dist/keep-alive/components/keepAlive.d.ts +4 -0
- package/dist/keep-alive/components/provider.d.ts +31 -0
- package/dist/keep-alive/contexts/IdentificationContext.d.ts +12 -0
- package/dist/keep-alive/contexts/KeepAliveContext.d.ts +5 -0
- package/dist/keep-alive/index.d.ts +7 -0
- package/dist/keep-alive/index.js +1901 -0
- package/dist/keep-alive/utils/bindLifecycle.d.ts +3 -0
- package/dist/keep-alive/utils/changePositionByComment.d.ts +1 -0
- package/dist/keep-alive/utils/createEventEmitter.d.ts +11 -0
- package/dist/keep-alive/utils/createStoreElement.d.ts +1 -0
- package/dist/keep-alive/utils/createUniqueIdentification.d.ts +8 -0
- package/dist/keep-alive/utils/debug.d.ts +3 -0
- package/dist/keep-alive/utils/getDisplayName.d.ts +2 -0
- package/dist/keep-alive/utils/getKeepAlive.d.ts +3 -0
- package/dist/keep-alive/utils/getKeyByFiberNode.d.ts +1 -0
- package/dist/keep-alive/utils/isRegExp.d.ts +1 -0
- package/dist/keep-alive/utils/keepAliveDecorator.d.ts +17 -0
- package/dist/keep-alive/utils/md5.d.ts +1 -0
- package/dist/keep-alive/utils/noop.d.ts +2 -0
- package/dist/keep-alive/utils/shallowEqual.d.ts +2 -0
- package/dist/keep-alive/utils/useKeepAliveEffect.d.ts +2 -0
- package/dist/keep-alive/utils/withIdentificationContextConsumer.d.ts +10 -0
- package/dist/keep-alive/utils/withKeepAliveContextConsumer.d.ts +10 -0
- package/dist/src/ArraySingle/Inner.d.ts +3 -0
- package/dist/src/ArraySingle/index.d.ts +2 -0
- package/dist/src/CaseTempleteEdit/Inner.d.ts +4 -0
- package/dist/src/CaseTempleteEdit/config.d.ts +20 -0
- package/dist/src/CaseTempleteEdit/index.d.ts +4 -0
- package/dist/src/CaseTempleteEdit/types.d.ts +19 -0
- package/dist/src/CaseTempleteEdit/utils.d.ts +2 -0
- package/dist/src/CaseTempleteEditEmr/Inner.d.ts +3 -0
- package/dist/src/CaseTempleteEditEmr/demo_text.d.ts +1 -0
- package/dist/src/CaseTempleteEditEmr/index.d.ts +2 -0
- package/dist/src/CaseTempleteEditEmr/types.d.ts +6 -0
- package/dist/src/CaseTempleteEditEmr/utils.d.ts +3 -0
- package/dist/src/ContainerDimensions/index.d.ts +10 -0
- package/dist/src/GlobalModal/index.d.ts +8 -0
- package/dist/src/GlobalModal/utils.d.ts +65 -0
- package/dist/src/Monaco/Inner.d.ts +12 -0
- package/dist/src/Monaco/index.d.ts +1 -0
- package/dist/src/MyAddress/Inner.d.ts +3 -0
- package/dist/src/MyAddress/Old/InnerOld.d.ts +3 -0
- package/dist/src/MyAddress/Old/index.d.ts +3 -0
- package/dist/src/MyAddress/Old/options.d.ts +25 -0
- package/dist/src/MyAddress/index.d.ts +6 -0
- package/dist/src/MyAddress/type.d.ts +16 -0
- package/dist/src/MyAddress/utils.d.ts +6 -0
- package/dist/src/MyImageEditor/Inner.d.ts +4 -0
- package/dist/src/MyImageEditor/index.d.ts +16 -0
- package/dist/src/MyImageEditor/init_delete_control.d.ts +1 -0
- package/dist/src/MyImageEditor/utils.d.ts +36 -0
- package/dist/src/MyInput/index.d.ts +5 -0
- package/dist/src/MyInput/types.d.ts +9 -0
- package/dist/src/MyLazyComponent/index.d.ts +6 -0
- package/dist/src/PDF_Frame_View/Inner.d.ts +3 -0
- package/dist/src/PDF_Frame_View/index.d.ts +5 -0
- package/dist/src/PDF_Frame_View/types.d.ts +32 -0
- package/dist/src/PDF_Frame_View/utils.d.ts +9 -0
- package/dist/src/PatientSelect/Inner.d.ts +16 -0
- package/dist/src/PatientSelect/index.d.ts +3 -0
- package/dist/src/SimpleForm/Inner.d.ts +5 -0
- package/dist/src/SimpleForm/components/TabForm/index.d.ts +15 -0
- package/dist/src/SimpleForm/components/extra/Custom.d.ts +8 -0
- package/dist/src/SimpleForm/components/extra/MultiInput.d.ts +6 -0
- package/dist/src/SimpleForm/components/extra/SimpleSelect.d.ts +6 -0
- package/dist/src/SimpleForm/components/extra/SwitchSelect.d.ts +4 -0
- package/dist/src/SimpleForm/components/index.d.ts +34 -0
- package/dist/src/SimpleForm/index.d.ts +17 -0
- package/dist/src/SimpleForm/types/help.d.ts +3 -0
- package/dist/src/SimpleForm/types/metaTypes.d.ts +29 -0
- package/dist/src/SimpleForm/types.d.ts +24 -0
- package/dist/src/a_chunks/index.js +550 -0
- package/dist/src/a_chunks/root..js +187 -0
- package/dist/src/a_chunks/root.2.js +318 -0
- package/dist/src/a_chunks/root.3.js +622 -0
- package/dist/src/a_chunks/root.4.js +235 -0
- package/dist/src/a_chunks/root.5.js +156 -0
- package/dist/src/a_chunks/root.6.js +310 -0
- package/dist/src/a_chunks/root.7.js +867 -0
- package/dist/src/a_chunks/root.8.js +281 -0
- package/dist/src/a_chunks/root.9.js +19 -0
- package/dist/src/a_chunks/style-inject.es.js +25 -0
- package/dist/src/config.d.ts +1 -0
- package/dist/src/hooks/index.d.ts +3 -0
- package/dist/src/hooks/useMchcDriverStatus.d.ts +3 -0
- package/dist/src/hooks/useMyEffect.d.ts +4 -0
- package/dist/src/hooks/use_fuck.d.ts +5 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +10 -0
- package/dist/src/pack_components.d.ts +213 -0
- package/dist/src/style/index.d.ts +1 -0
- package/dist/src/utils/getInputStyle.d.ts +1 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/other.d.ts +3 -0
- package/package.json +67 -0
|
@@ -0,0 +1,1901 @@
|
|
|
1
|
+
import React, { useEffect, useContext, useRef } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { mchcLogger } from '@lm_fe/env';
|
|
4
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
5
|
+
|
|
6
|
+
const noop = () => undefined;
|
|
7
|
+
|
|
8
|
+
class ReactComment extends React.PureComponent {
|
|
9
|
+
static defaultProps = {
|
|
10
|
+
onLoaded: noop
|
|
11
|
+
};
|
|
12
|
+
parentNode;
|
|
13
|
+
currentNode;
|
|
14
|
+
commentNode;
|
|
15
|
+
content;
|
|
16
|
+
componentDidMount() {
|
|
17
|
+
const node = ReactDOM.findDOMNode(this);
|
|
18
|
+
const commentNode = this.createComment();
|
|
19
|
+
this.commentNode = commentNode;
|
|
20
|
+
this.currentNode = node;
|
|
21
|
+
this.parentNode = node.parentNode;
|
|
22
|
+
this.parentNode.replaceChild(commentNode, node);
|
|
23
|
+
ReactDOM.unmountComponentAtNode(node);
|
|
24
|
+
this.props.onLoaded();
|
|
25
|
+
}
|
|
26
|
+
componentWillUnmount() {
|
|
27
|
+
try {
|
|
28
|
+
this.parentNode.replaceChild(this.currentNode, this.commentNode);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
mchcLogger.error('replaceChild', {
|
|
31
|
+
error,
|
|
32
|
+
currentNode: this.currentNode,
|
|
33
|
+
parent: this.parentNode,
|
|
34
|
+
commentNode: this.commentNode
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
createComment() {
|
|
39
|
+
let content = this.props.children;
|
|
40
|
+
if (typeof content !== 'string') {
|
|
41
|
+
content = '';
|
|
42
|
+
}
|
|
43
|
+
this.content = content.trim();
|
|
44
|
+
return document.createComment(this.content);
|
|
45
|
+
}
|
|
46
|
+
render() {
|
|
47
|
+
return /*#__PURE__*/React.createElement("div", null);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const KeepAliveContext = /*#__PURE__*/React.createContext({});
|
|
52
|
+
|
|
53
|
+
let warn = () => undefined;
|
|
54
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
55
|
+
/**
|
|
56
|
+
* Prints a warning in the console if it exists.
|
|
57
|
+
*
|
|
58
|
+
* @param {*} message
|
|
59
|
+
*/
|
|
60
|
+
warn = message => {
|
|
61
|
+
if (typeof console !== undefined && typeof console.error === 'function') {
|
|
62
|
+
console.error(message);
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error(message);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createEventEmitter() {
|
|
70
|
+
let events = Object.create(null);
|
|
71
|
+
function on(eventNames, listener, direction = false) {
|
|
72
|
+
eventNames = getEventNames(eventNames);
|
|
73
|
+
let current = events;
|
|
74
|
+
const maxIndex = eventNames.length - 1;
|
|
75
|
+
for (let i = 0; i < eventNames.length; i++) {
|
|
76
|
+
const key = eventNames[i];
|
|
77
|
+
if (!current[key]) {
|
|
78
|
+
current[key] = i === maxIndex ? [] : {};
|
|
79
|
+
}
|
|
80
|
+
current = current[key];
|
|
81
|
+
}
|
|
82
|
+
if (!Array.isArray(current)) {
|
|
83
|
+
warn('[React Keep Alive] Access path error.');
|
|
84
|
+
}
|
|
85
|
+
if (direction) {
|
|
86
|
+
current.unshift(listener);
|
|
87
|
+
} else {
|
|
88
|
+
current.push(listener);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function off(eventNames, listener) {
|
|
92
|
+
const listeners = getListeners(eventNames);
|
|
93
|
+
if (!listeners) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const matchIndex = listeners.findIndex(v => v === listener);
|
|
97
|
+
if (matchIndex !== -1) {
|
|
98
|
+
listeners.splice(matchIndex, 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function removeAllListeners(eventNames) {
|
|
102
|
+
const listeners = getListeners(eventNames);
|
|
103
|
+
if (!listeners) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
eventNames = getEventNames(eventNames);
|
|
107
|
+
const lastEventName = eventNames.pop();
|
|
108
|
+
if (lastEventName) {
|
|
109
|
+
const event = eventNames.reduce((obj, key) => obj[key], events);
|
|
110
|
+
event[lastEventName] = [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function emit(eventNames, ...args) {
|
|
114
|
+
const listeners = getListeners(eventNames);
|
|
115
|
+
if (!listeners) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
for (const listener of listeners) {
|
|
119
|
+
if (listener) {
|
|
120
|
+
listener(...args);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function listenerCount(eventNames) {
|
|
125
|
+
const listeners = getListeners(eventNames);
|
|
126
|
+
return listeners ? listeners.length : 0;
|
|
127
|
+
}
|
|
128
|
+
function clear() {
|
|
129
|
+
events = Object.create(null);
|
|
130
|
+
}
|
|
131
|
+
function getListeners(eventNames) {
|
|
132
|
+
eventNames = getEventNames(eventNames);
|
|
133
|
+
try {
|
|
134
|
+
return eventNames.reduce((obj, key) => obj[key], events);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getEventNames(eventNames) {
|
|
140
|
+
if (!eventNames) {
|
|
141
|
+
warn('[React Keep Alive] Must exist event name.');
|
|
142
|
+
}
|
|
143
|
+
if (typeof eventNames === 'string') {
|
|
144
|
+
eventNames = [eventNames];
|
|
145
|
+
}
|
|
146
|
+
return eventNames;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
on,
|
|
150
|
+
off,
|
|
151
|
+
emit,
|
|
152
|
+
clear,
|
|
153
|
+
listenerCount,
|
|
154
|
+
removeAllListeners
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const hexDigits = '0123456789abcdef';
|
|
159
|
+
const prefix = 'keep-alive';
|
|
160
|
+
/**
|
|
161
|
+
* Create UUID
|
|
162
|
+
* Reference: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
|
163
|
+
* @export
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
function createUniqueIdentification(length = 6) {
|
|
167
|
+
const strings = [];
|
|
168
|
+
for (let i = 0; i < length; i++) {
|
|
169
|
+
strings[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
170
|
+
}
|
|
171
|
+
return `${prefix}-${strings.join('')}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function createStoreElement() {
|
|
175
|
+
const keepAliveDOM = document.createElement('div');
|
|
176
|
+
keepAliveDOM.dataset.type = prefix;
|
|
177
|
+
keepAliveDOM.style.display = 'none';
|
|
178
|
+
document.body.appendChild(keepAliveDOM);
|
|
179
|
+
return keepAliveDOM;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
var LIFECYCLE;
|
|
183
|
+
(function (LIFECYCLE) {
|
|
184
|
+
LIFECYCLE[LIFECYCLE["MOUNTED"] = 1] = "MOUNTED";
|
|
185
|
+
LIFECYCLE[LIFECYCLE["UPDATING"] = 2] = "UPDATING";
|
|
186
|
+
LIFECYCLE[LIFECYCLE["UNMOUNTED"] = 3] = "UNMOUNTED";
|
|
187
|
+
})(LIFECYCLE || (LIFECYCLE = {}));
|
|
188
|
+
const keepAliveProviderTypeName = '$$KeepAliveProvider';
|
|
189
|
+
const START_MOUNTING_DOM = 'startMountingDOM';
|
|
190
|
+
|
|
191
|
+
class KeepAliveProvider extends React.PureComponent {
|
|
192
|
+
static displayName = keepAliveProviderTypeName;
|
|
193
|
+
static defaultProps = {
|
|
194
|
+
max: 10
|
|
195
|
+
};
|
|
196
|
+
storeElement;
|
|
197
|
+
// Sometimes data that changes with setState cannot be synchronized, so force refresh
|
|
198
|
+
cache = Object.create(null);
|
|
199
|
+
keys = [];
|
|
200
|
+
eventEmitter = createEventEmitter();
|
|
201
|
+
existed = true;
|
|
202
|
+
needRerender = false;
|
|
203
|
+
providerIdentification = createUniqueIdentification();
|
|
204
|
+
componentDidMount() {
|
|
205
|
+
this.storeElement = createStoreElement();
|
|
206
|
+
this.forceUpdate();
|
|
207
|
+
}
|
|
208
|
+
componentDidUpdate() {
|
|
209
|
+
if (this.needRerender) {
|
|
210
|
+
this.needRerender = false;
|
|
211
|
+
this.forceUpdate();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
componentWillUnmount() {
|
|
215
|
+
this.existed = false;
|
|
216
|
+
document.body.removeChild(this.storeElement);
|
|
217
|
+
}
|
|
218
|
+
isExisted = () => {
|
|
219
|
+
return this.existed;
|
|
220
|
+
};
|
|
221
|
+
setCache = (identification, value) => {
|
|
222
|
+
const {
|
|
223
|
+
cache,
|
|
224
|
+
keys
|
|
225
|
+
} = this;
|
|
226
|
+
const {
|
|
227
|
+
max
|
|
228
|
+
} = this.props;
|
|
229
|
+
const currentCache = cache[identification];
|
|
230
|
+
if (!currentCache) {
|
|
231
|
+
keys.push(identification);
|
|
232
|
+
}
|
|
233
|
+
this.cache[identification] = {
|
|
234
|
+
...currentCache,
|
|
235
|
+
...value
|
|
236
|
+
};
|
|
237
|
+
for (const key in cache) {
|
|
238
|
+
if (Object.prototype.hasOwnProperty.call(cache, key)) {
|
|
239
|
+
if (keys.indexOf(key) === -1) {
|
|
240
|
+
delete cache[key];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
this.forceUpdate(() => {
|
|
245
|
+
// If the maximum value is set, the value in the cache is deleted after it goes out.
|
|
246
|
+
if (currentCache) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!max) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const difference = keys.length - max;
|
|
253
|
+
if (difference <= 0) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const spliceKeys = keys.splice(0, difference);
|
|
257
|
+
this.forceUpdate(() => {
|
|
258
|
+
spliceKeys.forEach(key => {
|
|
259
|
+
delete cache[key];
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
removeCache = name => {
|
|
265
|
+
const {
|
|
266
|
+
cache,
|
|
267
|
+
keys
|
|
268
|
+
} = this;
|
|
269
|
+
const needDeletedCacheKeys = [];
|
|
270
|
+
for (const key in cache) {
|
|
271
|
+
if (Object.prototype.hasOwnProperty.call(cache, key)) {
|
|
272
|
+
const keepAliveObject = cache[key];
|
|
273
|
+
// if name is array, mutiple delete caches
|
|
274
|
+
if (Object.prototype.toString.call(name) === '[object Array]') {
|
|
275
|
+
if (name.indexOf(keepAliveObject.children._owner.key) > -1) {
|
|
276
|
+
needDeletedCacheKeys.push(key);
|
|
277
|
+
delete cache[key];
|
|
278
|
+
}
|
|
279
|
+
} else if (Object.prototype.toString.call(name) === '[object String]') {
|
|
280
|
+
if (name.indexOf(keepAliveObject.children._owner.key) > -1) {
|
|
281
|
+
needDeletedCacheKeys.push(key);
|
|
282
|
+
delete cache[key];
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
throw new Error("name can be only string or string array");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
this.keys = keys.filter(key => needDeletedCacheKeys.indexOf(key) === -1);
|
|
290
|
+
this.forceUpdate();
|
|
291
|
+
};
|
|
292
|
+
unactivate = identification => {
|
|
293
|
+
const {
|
|
294
|
+
cache
|
|
295
|
+
} = this;
|
|
296
|
+
this.cache[identification] = {
|
|
297
|
+
...cache[identification],
|
|
298
|
+
activated: false,
|
|
299
|
+
lifecycle: LIFECYCLE.UNMOUNTED
|
|
300
|
+
};
|
|
301
|
+
this.forceUpdate();
|
|
302
|
+
};
|
|
303
|
+
startMountingDOM = identification => {
|
|
304
|
+
this.eventEmitter.emit([identification, START_MOUNTING_DOM]);
|
|
305
|
+
};
|
|
306
|
+
render() {
|
|
307
|
+
const {
|
|
308
|
+
cache,
|
|
309
|
+
keys,
|
|
310
|
+
providerIdentification,
|
|
311
|
+
isExisted,
|
|
312
|
+
setCache,
|
|
313
|
+
removeCache,
|
|
314
|
+
existed,
|
|
315
|
+
unactivate,
|
|
316
|
+
storeElement,
|
|
317
|
+
eventEmitter
|
|
318
|
+
} = this;
|
|
319
|
+
const {
|
|
320
|
+
children: innerChildren,
|
|
321
|
+
include,
|
|
322
|
+
exclude
|
|
323
|
+
} = this.props;
|
|
324
|
+
if (!storeElement) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
return /*#__PURE__*/React.createElement(KeepAliveContext.Provider, {
|
|
328
|
+
value: {
|
|
329
|
+
cache,
|
|
330
|
+
keys,
|
|
331
|
+
existed,
|
|
332
|
+
providerIdentification,
|
|
333
|
+
isExisted,
|
|
334
|
+
setCache,
|
|
335
|
+
removeCache,
|
|
336
|
+
unactivate,
|
|
337
|
+
storeElement,
|
|
338
|
+
eventEmitter,
|
|
339
|
+
include,
|
|
340
|
+
exclude
|
|
341
|
+
}
|
|
342
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, innerChildren, /*#__PURE__*/ReactDOM.createPortal(keys.map(identification => {
|
|
343
|
+
const currentCache = cache[identification];
|
|
344
|
+
const {
|
|
345
|
+
keepAlive,
|
|
346
|
+
children,
|
|
347
|
+
lifecycle
|
|
348
|
+
} = currentCache;
|
|
349
|
+
let cacheChildren = children;
|
|
350
|
+
if (lifecycle === LIFECYCLE.MOUNTED && !keepAlive) {
|
|
351
|
+
// If the cache was last enabled, then the components of this keepAlive package are used,
|
|
352
|
+
// and the cache is not enabled, the UI needs to be reset.
|
|
353
|
+
cacheChildren = null;
|
|
354
|
+
this.needRerender = true;
|
|
355
|
+
currentCache.lifecycle = LIFECYCLE.UPDATING;
|
|
356
|
+
}
|
|
357
|
+
// current true, previous true | undefined, keepAlive false, not cache
|
|
358
|
+
// current true, previous true | undefined, keepAlive true, cache
|
|
359
|
+
// current true, previous false, keepAlive true, cache
|
|
360
|
+
// current true, previous false, keepAlive false, not cache
|
|
361
|
+
return cacheChildren ? (/*#__PURE__*/React.createElement(React.Fragment, {
|
|
362
|
+
key: identification
|
|
363
|
+
}, /*#__PURE__*/React.createElement(ReactComment, null, identification), cacheChildren, /*#__PURE__*/React.createElement(ReactComment, {
|
|
364
|
+
onLoaded: () => this.startMountingDOM(identification)
|
|
365
|
+
}, identification))) : null;
|
|
366
|
+
}), storeElement)));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const WithKeepAliveContext = /*#__PURE__*/React.createContext({});
|
|
371
|
+
|
|
372
|
+
class Consumer extends React.PureComponent {
|
|
373
|
+
renderElement;
|
|
374
|
+
commentRef;
|
|
375
|
+
identification = this.props.identification;
|
|
376
|
+
componentDidMount() {
|
|
377
|
+
const {
|
|
378
|
+
setCache,
|
|
379
|
+
children,
|
|
380
|
+
keepAlive
|
|
381
|
+
} = this.props;
|
|
382
|
+
this.renderElement = this.commentRef.parentNode;
|
|
383
|
+
setCache(this.identification, {
|
|
384
|
+
children,
|
|
385
|
+
keepAlive,
|
|
386
|
+
lifecycle: LIFECYCLE.MOUNTED,
|
|
387
|
+
renderElement: this.renderElement,
|
|
388
|
+
activated: true
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
componentDidUpdate() {
|
|
392
|
+
const {
|
|
393
|
+
setCache,
|
|
394
|
+
children,
|
|
395
|
+
keepAlive
|
|
396
|
+
} = this.props;
|
|
397
|
+
setCache(this.identification, {
|
|
398
|
+
children,
|
|
399
|
+
keepAlive,
|
|
400
|
+
lifecycle: LIFECYCLE.UPDATING
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
componentWillUnmount() {
|
|
404
|
+
const {
|
|
405
|
+
unactivate
|
|
406
|
+
} = this.props;
|
|
407
|
+
unactivate(this.identification);
|
|
408
|
+
}
|
|
409
|
+
render() {
|
|
410
|
+
const {
|
|
411
|
+
identification
|
|
412
|
+
} = this;
|
|
413
|
+
return /*#__PURE__*/React.createElement(ReactComment, {
|
|
414
|
+
ref: ref => this.commentRef = ref
|
|
415
|
+
}, identification);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
420
|
+
|
|
421
|
+
var md5$1 = {exports: {}};
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* [js-md5]{@link https://github.com/emn178/js-md5}
|
|
425
|
+
*
|
|
426
|
+
* @namespace md5
|
|
427
|
+
* @version 0.7.3
|
|
428
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
429
|
+
* @copyright Chen, Yi-Cyuan 2014-2017
|
|
430
|
+
* @license MIT
|
|
431
|
+
*/
|
|
432
|
+
(function (module) {
|
|
433
|
+
(function () {
|
|
434
|
+
|
|
435
|
+
var ERROR = 'input is invalid type';
|
|
436
|
+
var WINDOW = typeof window === 'object';
|
|
437
|
+
var root = WINDOW ? window : {};
|
|
438
|
+
if (root.JS_MD5_NO_WINDOW) {
|
|
439
|
+
WINDOW = false;
|
|
440
|
+
}
|
|
441
|
+
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
|
442
|
+
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
|
443
|
+
if (NODE_JS) {
|
|
444
|
+
root = commonjsGlobal;
|
|
445
|
+
} else if (WEB_WORKER) {
|
|
446
|
+
root = self;
|
|
447
|
+
}
|
|
448
|
+
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && 'object' === 'object' && module.exports;
|
|
449
|
+
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
450
|
+
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
451
|
+
var EXTRA = [128, 32768, 8388608, -2147483648];
|
|
452
|
+
var SHIFT = [0, 8, 16, 24];
|
|
453
|
+
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
|
|
454
|
+
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
|
455
|
+
var blocks = [],
|
|
456
|
+
buffer8;
|
|
457
|
+
if (ARRAY_BUFFER) {
|
|
458
|
+
var buffer = new ArrayBuffer(68);
|
|
459
|
+
buffer8 = new Uint8Array(buffer);
|
|
460
|
+
blocks = new Uint32Array(buffer);
|
|
461
|
+
}
|
|
462
|
+
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
|
|
463
|
+
Array.isArray = function (obj) {
|
|
464
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
468
|
+
ArrayBuffer.isView = function (obj) {
|
|
469
|
+
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @method hex
|
|
475
|
+
* @memberof md5
|
|
476
|
+
* @description Output hash as hex string
|
|
477
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
478
|
+
* @returns {String} Hex string
|
|
479
|
+
* @example
|
|
480
|
+
* md5.hex('The quick brown fox jumps over the lazy dog');
|
|
481
|
+
* // equal to
|
|
482
|
+
* md5('The quick brown fox jumps over the lazy dog');
|
|
483
|
+
*/
|
|
484
|
+
/**
|
|
485
|
+
* @method digest
|
|
486
|
+
* @memberof md5
|
|
487
|
+
* @description Output hash as bytes array
|
|
488
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
489
|
+
* @returns {Array} Bytes array
|
|
490
|
+
* @example
|
|
491
|
+
* md5.digest('The quick brown fox jumps over the lazy dog');
|
|
492
|
+
*/
|
|
493
|
+
/**
|
|
494
|
+
* @method array
|
|
495
|
+
* @memberof md5
|
|
496
|
+
* @description Output hash as bytes array
|
|
497
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
498
|
+
* @returns {Array} Bytes array
|
|
499
|
+
* @example
|
|
500
|
+
* md5.array('The quick brown fox jumps over the lazy dog');
|
|
501
|
+
*/
|
|
502
|
+
/**
|
|
503
|
+
* @method arrayBuffer
|
|
504
|
+
* @memberof md5
|
|
505
|
+
* @description Output hash as ArrayBuffer
|
|
506
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
507
|
+
* @returns {ArrayBuffer} ArrayBuffer
|
|
508
|
+
* @example
|
|
509
|
+
* md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
|
|
510
|
+
*/
|
|
511
|
+
/**
|
|
512
|
+
* @method buffer
|
|
513
|
+
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
|
514
|
+
* @memberof md5
|
|
515
|
+
* @description Output hash as ArrayBuffer
|
|
516
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
517
|
+
* @returns {ArrayBuffer} ArrayBuffer
|
|
518
|
+
* @example
|
|
519
|
+
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
|
520
|
+
*/
|
|
521
|
+
/**
|
|
522
|
+
* @method base64
|
|
523
|
+
* @memberof md5
|
|
524
|
+
* @description Output hash as base64 string
|
|
525
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
526
|
+
* @returns {String} base64 string
|
|
527
|
+
* @example
|
|
528
|
+
* md5.base64('The quick brown fox jumps over the lazy dog');
|
|
529
|
+
*/
|
|
530
|
+
var createOutputMethod = function (outputType) {
|
|
531
|
+
return function (message) {
|
|
532
|
+
return new Md5(true).update(message)[outputType]();
|
|
533
|
+
};
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @method create
|
|
538
|
+
* @memberof md5
|
|
539
|
+
* @description Create Md5 object
|
|
540
|
+
* @returns {Md5} Md5 object.
|
|
541
|
+
* @example
|
|
542
|
+
* var hash = md5.create();
|
|
543
|
+
*/
|
|
544
|
+
/**
|
|
545
|
+
* @method update
|
|
546
|
+
* @memberof md5
|
|
547
|
+
* @description Create and update Md5 object
|
|
548
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
549
|
+
* @returns {Md5} Md5 object.
|
|
550
|
+
* @example
|
|
551
|
+
* var hash = md5.update('The quick brown fox jumps over the lazy dog');
|
|
552
|
+
* // equal to
|
|
553
|
+
* var hash = md5.create();
|
|
554
|
+
* hash.update('The quick brown fox jumps over the lazy dog');
|
|
555
|
+
*/
|
|
556
|
+
var createMethod = function () {
|
|
557
|
+
var method = createOutputMethod('hex');
|
|
558
|
+
if (NODE_JS) {
|
|
559
|
+
method = nodeWrap(method);
|
|
560
|
+
}
|
|
561
|
+
method.create = function () {
|
|
562
|
+
return new Md5();
|
|
563
|
+
};
|
|
564
|
+
method.update = function (message) {
|
|
565
|
+
return method.create().update(message);
|
|
566
|
+
};
|
|
567
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
568
|
+
var type = OUTPUT_TYPES[i];
|
|
569
|
+
method[type] = createOutputMethod(type);
|
|
570
|
+
}
|
|
571
|
+
return method;
|
|
572
|
+
};
|
|
573
|
+
var nodeWrap = function (method) {
|
|
574
|
+
var crypto = eval("require('crypto')");
|
|
575
|
+
var Buffer = eval("require('buffer').Buffer");
|
|
576
|
+
var nodeMethod = function (message) {
|
|
577
|
+
if (typeof message === 'string') {
|
|
578
|
+
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
|
579
|
+
} else {
|
|
580
|
+
if (message === null || message === undefined) {
|
|
581
|
+
throw ERROR;
|
|
582
|
+
} else if (message.constructor === ArrayBuffer) {
|
|
583
|
+
message = new Uint8Array(message);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer) {
|
|
587
|
+
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
|
|
588
|
+
} else {
|
|
589
|
+
return method(message);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
return nodeMethod;
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Md5 class
|
|
597
|
+
* @class Md5
|
|
598
|
+
* @description This is internal class.
|
|
599
|
+
* @see {@link md5.create}
|
|
600
|
+
*/
|
|
601
|
+
function Md5(sharedMemory) {
|
|
602
|
+
if (sharedMemory) {
|
|
603
|
+
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
604
|
+
this.blocks = blocks;
|
|
605
|
+
this.buffer8 = buffer8;
|
|
606
|
+
} else {
|
|
607
|
+
if (ARRAY_BUFFER) {
|
|
608
|
+
var buffer = new ArrayBuffer(68);
|
|
609
|
+
this.buffer8 = new Uint8Array(buffer);
|
|
610
|
+
this.blocks = new Uint32Array(buffer);
|
|
611
|
+
} else {
|
|
612
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
|
|
616
|
+
this.finalized = this.hashed = false;
|
|
617
|
+
this.first = true;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* @method update
|
|
622
|
+
* @memberof Md5
|
|
623
|
+
* @instance
|
|
624
|
+
* @description Update hash
|
|
625
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
626
|
+
* @returns {Md5} Md5 object.
|
|
627
|
+
* @see {@link md5.update}
|
|
628
|
+
*/
|
|
629
|
+
Md5.prototype.update = function (message) {
|
|
630
|
+
if (this.finalized) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
var notString,
|
|
634
|
+
type = typeof message;
|
|
635
|
+
if (type !== 'string') {
|
|
636
|
+
if (type === 'object') {
|
|
637
|
+
if (message === null) {
|
|
638
|
+
throw ERROR;
|
|
639
|
+
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
640
|
+
message = new Uint8Array(message);
|
|
641
|
+
} else if (!Array.isArray(message)) {
|
|
642
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
643
|
+
throw ERROR;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
} else {
|
|
647
|
+
throw ERROR;
|
|
648
|
+
}
|
|
649
|
+
notString = true;
|
|
650
|
+
}
|
|
651
|
+
var code,
|
|
652
|
+
index = 0,
|
|
653
|
+
i,
|
|
654
|
+
length = message.length,
|
|
655
|
+
blocks = this.blocks;
|
|
656
|
+
var buffer8 = this.buffer8;
|
|
657
|
+
while (index < length) {
|
|
658
|
+
if (this.hashed) {
|
|
659
|
+
this.hashed = false;
|
|
660
|
+
blocks[0] = blocks[16];
|
|
661
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
662
|
+
}
|
|
663
|
+
if (notString) {
|
|
664
|
+
if (ARRAY_BUFFER) {
|
|
665
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
666
|
+
buffer8[i++] = message[index];
|
|
667
|
+
}
|
|
668
|
+
} else {
|
|
669
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
670
|
+
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
} else {
|
|
674
|
+
if (ARRAY_BUFFER) {
|
|
675
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
676
|
+
code = message.charCodeAt(index);
|
|
677
|
+
if (code < 0x80) {
|
|
678
|
+
buffer8[i++] = code;
|
|
679
|
+
} else if (code < 0x800) {
|
|
680
|
+
buffer8[i++] = 0xc0 | code >> 6;
|
|
681
|
+
buffer8[i++] = 0x80 | code & 0x3f;
|
|
682
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
683
|
+
buffer8[i++] = 0xe0 | code >> 12;
|
|
684
|
+
buffer8[i++] = 0x80 | code >> 6 & 0x3f;
|
|
685
|
+
buffer8[i++] = 0x80 | code & 0x3f;
|
|
686
|
+
} else {
|
|
687
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | message.charCodeAt(++index) & 0x3ff);
|
|
688
|
+
buffer8[i++] = 0xf0 | code >> 18;
|
|
689
|
+
buffer8[i++] = 0x80 | code >> 12 & 0x3f;
|
|
690
|
+
buffer8[i++] = 0x80 | code >> 6 & 0x3f;
|
|
691
|
+
buffer8[i++] = 0x80 | code & 0x3f;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
} else {
|
|
695
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
696
|
+
code = message.charCodeAt(index);
|
|
697
|
+
if (code < 0x80) {
|
|
698
|
+
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
699
|
+
} else if (code < 0x800) {
|
|
700
|
+
blocks[i >> 2] |= (0xc0 | code >> 6) << SHIFT[i++ & 3];
|
|
701
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
702
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
703
|
+
blocks[i >> 2] |= (0xe0 | code >> 12) << SHIFT[i++ & 3];
|
|
704
|
+
blocks[i >> 2] |= (0x80 | code >> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
705
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
706
|
+
} else {
|
|
707
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | message.charCodeAt(++index) & 0x3ff);
|
|
708
|
+
blocks[i >> 2] |= (0xf0 | code >> 18) << SHIFT[i++ & 3];
|
|
709
|
+
blocks[i >> 2] |= (0x80 | code >> 12 & 0x3f) << SHIFT[i++ & 3];
|
|
710
|
+
blocks[i >> 2] |= (0x80 | code >> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
711
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
this.lastByteIndex = i;
|
|
717
|
+
this.bytes += i - this.start;
|
|
718
|
+
if (i >= 64) {
|
|
719
|
+
this.start = i - 64;
|
|
720
|
+
this.hash();
|
|
721
|
+
this.hashed = true;
|
|
722
|
+
} else {
|
|
723
|
+
this.start = i;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (this.bytes > 4294967295) {
|
|
727
|
+
this.hBytes += this.bytes / 4294967296 << 0;
|
|
728
|
+
this.bytes = this.bytes % 4294967296;
|
|
729
|
+
}
|
|
730
|
+
return this;
|
|
731
|
+
};
|
|
732
|
+
Md5.prototype.finalize = function () {
|
|
733
|
+
if (this.finalized) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
this.finalized = true;
|
|
737
|
+
var blocks = this.blocks,
|
|
738
|
+
i = this.lastByteIndex;
|
|
739
|
+
blocks[i >> 2] |= EXTRA[i & 3];
|
|
740
|
+
if (i >= 56) {
|
|
741
|
+
if (!this.hashed) {
|
|
742
|
+
this.hash();
|
|
743
|
+
}
|
|
744
|
+
blocks[0] = blocks[16];
|
|
745
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
746
|
+
}
|
|
747
|
+
blocks[14] = this.bytes << 3;
|
|
748
|
+
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
|
|
749
|
+
this.hash();
|
|
750
|
+
};
|
|
751
|
+
Md5.prototype.hash = function () {
|
|
752
|
+
var a,
|
|
753
|
+
b,
|
|
754
|
+
c,
|
|
755
|
+
d,
|
|
756
|
+
bc,
|
|
757
|
+
da,
|
|
758
|
+
blocks = this.blocks;
|
|
759
|
+
if (this.first) {
|
|
760
|
+
a = blocks[0] - 680876937;
|
|
761
|
+
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
|
762
|
+
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
|
763
|
+
d = (d << 12 | d >>> 20) + a << 0;
|
|
764
|
+
c = (-271733879 ^ d & (a ^ -271733879)) + blocks[2] - 1126478375;
|
|
765
|
+
c = (c << 17 | c >>> 15) + d << 0;
|
|
766
|
+
b = (a ^ c & (d ^ a)) + blocks[3] - 1316259209;
|
|
767
|
+
b = (b << 22 | b >>> 10) + c << 0;
|
|
768
|
+
} else {
|
|
769
|
+
a = this.h0;
|
|
770
|
+
b = this.h1;
|
|
771
|
+
c = this.h2;
|
|
772
|
+
d = this.h3;
|
|
773
|
+
a += (d ^ b & (c ^ d)) + blocks[0] - 680876936;
|
|
774
|
+
a = (a << 7 | a >>> 25) + b << 0;
|
|
775
|
+
d += (c ^ a & (b ^ c)) + blocks[1] - 389564586;
|
|
776
|
+
d = (d << 12 | d >>> 20) + a << 0;
|
|
777
|
+
c += (b ^ d & (a ^ b)) + blocks[2] + 606105819;
|
|
778
|
+
c = (c << 17 | c >>> 15) + d << 0;
|
|
779
|
+
b += (a ^ c & (d ^ a)) + blocks[3] - 1044525330;
|
|
780
|
+
b = (b << 22 | b >>> 10) + c << 0;
|
|
781
|
+
}
|
|
782
|
+
a += (d ^ b & (c ^ d)) + blocks[4] - 176418897;
|
|
783
|
+
a = (a << 7 | a >>> 25) + b << 0;
|
|
784
|
+
d += (c ^ a & (b ^ c)) + blocks[5] + 1200080426;
|
|
785
|
+
d = (d << 12 | d >>> 20) + a << 0;
|
|
786
|
+
c += (b ^ d & (a ^ b)) + blocks[6] - 1473231341;
|
|
787
|
+
c = (c << 17 | c >>> 15) + d << 0;
|
|
788
|
+
b += (a ^ c & (d ^ a)) + blocks[7] - 45705983;
|
|
789
|
+
b = (b << 22 | b >>> 10) + c << 0;
|
|
790
|
+
a += (d ^ b & (c ^ d)) + blocks[8] + 1770035416;
|
|
791
|
+
a = (a << 7 | a >>> 25) + b << 0;
|
|
792
|
+
d += (c ^ a & (b ^ c)) + blocks[9] - 1958414417;
|
|
793
|
+
d = (d << 12 | d >>> 20) + a << 0;
|
|
794
|
+
c += (b ^ d & (a ^ b)) + blocks[10] - 42063;
|
|
795
|
+
c = (c << 17 | c >>> 15) + d << 0;
|
|
796
|
+
b += (a ^ c & (d ^ a)) + blocks[11] - 1990404162;
|
|
797
|
+
b = (b << 22 | b >>> 10) + c << 0;
|
|
798
|
+
a += (d ^ b & (c ^ d)) + blocks[12] + 1804603682;
|
|
799
|
+
a = (a << 7 | a >>> 25) + b << 0;
|
|
800
|
+
d += (c ^ a & (b ^ c)) + blocks[13] - 40341101;
|
|
801
|
+
d = (d << 12 | d >>> 20) + a << 0;
|
|
802
|
+
c += (b ^ d & (a ^ b)) + blocks[14] - 1502002290;
|
|
803
|
+
c = (c << 17 | c >>> 15) + d << 0;
|
|
804
|
+
b += (a ^ c & (d ^ a)) + blocks[15] + 1236535329;
|
|
805
|
+
b = (b << 22 | b >>> 10) + c << 0;
|
|
806
|
+
a += (c ^ d & (b ^ c)) + blocks[1] - 165796510;
|
|
807
|
+
a = (a << 5 | a >>> 27) + b << 0;
|
|
808
|
+
d += (b ^ c & (a ^ b)) + blocks[6] - 1069501632;
|
|
809
|
+
d = (d << 9 | d >>> 23) + a << 0;
|
|
810
|
+
c += (a ^ b & (d ^ a)) + blocks[11] + 643717713;
|
|
811
|
+
c = (c << 14 | c >>> 18) + d << 0;
|
|
812
|
+
b += (d ^ a & (c ^ d)) + blocks[0] - 373897302;
|
|
813
|
+
b = (b << 20 | b >>> 12) + c << 0;
|
|
814
|
+
a += (c ^ d & (b ^ c)) + blocks[5] - 701558691;
|
|
815
|
+
a = (a << 5 | a >>> 27) + b << 0;
|
|
816
|
+
d += (b ^ c & (a ^ b)) + blocks[10] + 38016083;
|
|
817
|
+
d = (d << 9 | d >>> 23) + a << 0;
|
|
818
|
+
c += (a ^ b & (d ^ a)) + blocks[15] - 660478335;
|
|
819
|
+
c = (c << 14 | c >>> 18) + d << 0;
|
|
820
|
+
b += (d ^ a & (c ^ d)) + blocks[4] - 405537848;
|
|
821
|
+
b = (b << 20 | b >>> 12) + c << 0;
|
|
822
|
+
a += (c ^ d & (b ^ c)) + blocks[9] + 568446438;
|
|
823
|
+
a = (a << 5 | a >>> 27) + b << 0;
|
|
824
|
+
d += (b ^ c & (a ^ b)) + blocks[14] - 1019803690;
|
|
825
|
+
d = (d << 9 | d >>> 23) + a << 0;
|
|
826
|
+
c += (a ^ b & (d ^ a)) + blocks[3] - 187363961;
|
|
827
|
+
c = (c << 14 | c >>> 18) + d << 0;
|
|
828
|
+
b += (d ^ a & (c ^ d)) + blocks[8] + 1163531501;
|
|
829
|
+
b = (b << 20 | b >>> 12) + c << 0;
|
|
830
|
+
a += (c ^ d & (b ^ c)) + blocks[13] - 1444681467;
|
|
831
|
+
a = (a << 5 | a >>> 27) + b << 0;
|
|
832
|
+
d += (b ^ c & (a ^ b)) + blocks[2] - 51403784;
|
|
833
|
+
d = (d << 9 | d >>> 23) + a << 0;
|
|
834
|
+
c += (a ^ b & (d ^ a)) + blocks[7] + 1735328473;
|
|
835
|
+
c = (c << 14 | c >>> 18) + d << 0;
|
|
836
|
+
b += (d ^ a & (c ^ d)) + blocks[12] - 1926607734;
|
|
837
|
+
b = (b << 20 | b >>> 12) + c << 0;
|
|
838
|
+
bc = b ^ c;
|
|
839
|
+
a += (bc ^ d) + blocks[5] - 378558;
|
|
840
|
+
a = (a << 4 | a >>> 28) + b << 0;
|
|
841
|
+
d += (bc ^ a) + blocks[8] - 2022574463;
|
|
842
|
+
d = (d << 11 | d >>> 21) + a << 0;
|
|
843
|
+
da = d ^ a;
|
|
844
|
+
c += (da ^ b) + blocks[11] + 1839030562;
|
|
845
|
+
c = (c << 16 | c >>> 16) + d << 0;
|
|
846
|
+
b += (da ^ c) + blocks[14] - 35309556;
|
|
847
|
+
b = (b << 23 | b >>> 9) + c << 0;
|
|
848
|
+
bc = b ^ c;
|
|
849
|
+
a += (bc ^ d) + blocks[1] - 1530992060;
|
|
850
|
+
a = (a << 4 | a >>> 28) + b << 0;
|
|
851
|
+
d += (bc ^ a) + blocks[4] + 1272893353;
|
|
852
|
+
d = (d << 11 | d >>> 21) + a << 0;
|
|
853
|
+
da = d ^ a;
|
|
854
|
+
c += (da ^ b) + blocks[7] - 155497632;
|
|
855
|
+
c = (c << 16 | c >>> 16) + d << 0;
|
|
856
|
+
b += (da ^ c) + blocks[10] - 1094730640;
|
|
857
|
+
b = (b << 23 | b >>> 9) + c << 0;
|
|
858
|
+
bc = b ^ c;
|
|
859
|
+
a += (bc ^ d) + blocks[13] + 681279174;
|
|
860
|
+
a = (a << 4 | a >>> 28) + b << 0;
|
|
861
|
+
d += (bc ^ a) + blocks[0] - 358537222;
|
|
862
|
+
d = (d << 11 | d >>> 21) + a << 0;
|
|
863
|
+
da = d ^ a;
|
|
864
|
+
c += (da ^ b) + blocks[3] - 722521979;
|
|
865
|
+
c = (c << 16 | c >>> 16) + d << 0;
|
|
866
|
+
b += (da ^ c) + blocks[6] + 76029189;
|
|
867
|
+
b = (b << 23 | b >>> 9) + c << 0;
|
|
868
|
+
bc = b ^ c;
|
|
869
|
+
a += (bc ^ d) + blocks[9] - 640364487;
|
|
870
|
+
a = (a << 4 | a >>> 28) + b << 0;
|
|
871
|
+
d += (bc ^ a) + blocks[12] - 421815835;
|
|
872
|
+
d = (d << 11 | d >>> 21) + a << 0;
|
|
873
|
+
da = d ^ a;
|
|
874
|
+
c += (da ^ b) + blocks[15] + 530742520;
|
|
875
|
+
c = (c << 16 | c >>> 16) + d << 0;
|
|
876
|
+
b += (da ^ c) + blocks[2] - 995338651;
|
|
877
|
+
b = (b << 23 | b >>> 9) + c << 0;
|
|
878
|
+
a += (c ^ (b | ~d)) + blocks[0] - 198630844;
|
|
879
|
+
a = (a << 6 | a >>> 26) + b << 0;
|
|
880
|
+
d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
|
|
881
|
+
d = (d << 10 | d >>> 22) + a << 0;
|
|
882
|
+
c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
|
|
883
|
+
c = (c << 15 | c >>> 17) + d << 0;
|
|
884
|
+
b += (d ^ (c | ~a)) + blocks[5] - 57434055;
|
|
885
|
+
b = (b << 21 | b >>> 11) + c << 0;
|
|
886
|
+
a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
|
|
887
|
+
a = (a << 6 | a >>> 26) + b << 0;
|
|
888
|
+
d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
|
|
889
|
+
d = (d << 10 | d >>> 22) + a << 0;
|
|
890
|
+
c += (a ^ (d | ~b)) + blocks[10] - 1051523;
|
|
891
|
+
c = (c << 15 | c >>> 17) + d << 0;
|
|
892
|
+
b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
|
|
893
|
+
b = (b << 21 | b >>> 11) + c << 0;
|
|
894
|
+
a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
|
|
895
|
+
a = (a << 6 | a >>> 26) + b << 0;
|
|
896
|
+
d += (b ^ (a | ~c)) + blocks[15] - 30611744;
|
|
897
|
+
d = (d << 10 | d >>> 22) + a << 0;
|
|
898
|
+
c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
|
|
899
|
+
c = (c << 15 | c >>> 17) + d << 0;
|
|
900
|
+
b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
|
|
901
|
+
b = (b << 21 | b >>> 11) + c << 0;
|
|
902
|
+
a += (c ^ (b | ~d)) + blocks[4] - 145523070;
|
|
903
|
+
a = (a << 6 | a >>> 26) + b << 0;
|
|
904
|
+
d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
|
|
905
|
+
d = (d << 10 | d >>> 22) + a << 0;
|
|
906
|
+
c += (a ^ (d | ~b)) + blocks[2] + 718787259;
|
|
907
|
+
c = (c << 15 | c >>> 17) + d << 0;
|
|
908
|
+
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
|
909
|
+
b = (b << 21 | b >>> 11) + c << 0;
|
|
910
|
+
if (this.first) {
|
|
911
|
+
this.h0 = a + 1732584193 << 0;
|
|
912
|
+
this.h1 = b - 271733879 << 0;
|
|
913
|
+
this.h2 = c - 1732584194 << 0;
|
|
914
|
+
this.h3 = d + 271733878 << 0;
|
|
915
|
+
this.first = false;
|
|
916
|
+
} else {
|
|
917
|
+
this.h0 = this.h0 + a << 0;
|
|
918
|
+
this.h1 = this.h1 + b << 0;
|
|
919
|
+
this.h2 = this.h2 + c << 0;
|
|
920
|
+
this.h3 = this.h3 + d << 0;
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* @method hex
|
|
926
|
+
* @memberof Md5
|
|
927
|
+
* @instance
|
|
928
|
+
* @description Output hash as hex string
|
|
929
|
+
* @returns {String} Hex string
|
|
930
|
+
* @see {@link md5.hex}
|
|
931
|
+
* @example
|
|
932
|
+
* hash.hex();
|
|
933
|
+
*/
|
|
934
|
+
Md5.prototype.hex = function () {
|
|
935
|
+
this.finalize();
|
|
936
|
+
var h0 = this.h0,
|
|
937
|
+
h1 = this.h1,
|
|
938
|
+
h2 = this.h2,
|
|
939
|
+
h3 = this.h3;
|
|
940
|
+
return HEX_CHARS[h0 >> 4 & 0x0F] + HEX_CHARS[h0 & 0x0F] + HEX_CHARS[h0 >> 12 & 0x0F] + HEX_CHARS[h0 >> 8 & 0x0F] + HEX_CHARS[h0 >> 20 & 0x0F] + HEX_CHARS[h0 >> 16 & 0x0F] + HEX_CHARS[h0 >> 28 & 0x0F] + HEX_CHARS[h0 >> 24 & 0x0F] + HEX_CHARS[h1 >> 4 & 0x0F] + HEX_CHARS[h1 & 0x0F] + HEX_CHARS[h1 >> 12 & 0x0F] + HEX_CHARS[h1 >> 8 & 0x0F] + HEX_CHARS[h1 >> 20 & 0x0F] + HEX_CHARS[h1 >> 16 & 0x0F] + HEX_CHARS[h1 >> 28 & 0x0F] + HEX_CHARS[h1 >> 24 & 0x0F] + HEX_CHARS[h2 >> 4 & 0x0F] + HEX_CHARS[h2 & 0x0F] + HEX_CHARS[h2 >> 12 & 0x0F] + HEX_CHARS[h2 >> 8 & 0x0F] + HEX_CHARS[h2 >> 20 & 0x0F] + HEX_CHARS[h2 >> 16 & 0x0F] + HEX_CHARS[h2 >> 28 & 0x0F] + HEX_CHARS[h2 >> 24 & 0x0F] + HEX_CHARS[h3 >> 4 & 0x0F] + HEX_CHARS[h3 & 0x0F] + HEX_CHARS[h3 >> 12 & 0x0F] + HEX_CHARS[h3 >> 8 & 0x0F] + HEX_CHARS[h3 >> 20 & 0x0F] + HEX_CHARS[h3 >> 16 & 0x0F] + HEX_CHARS[h3 >> 28 & 0x0F] + HEX_CHARS[h3 >> 24 & 0x0F];
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* @method toString
|
|
945
|
+
* @memberof Md5
|
|
946
|
+
* @instance
|
|
947
|
+
* @description Output hash as hex string
|
|
948
|
+
* @returns {String} Hex string
|
|
949
|
+
* @see {@link md5.hex}
|
|
950
|
+
* @example
|
|
951
|
+
* hash.toString();
|
|
952
|
+
*/
|
|
953
|
+
Md5.prototype.toString = Md5.prototype.hex;
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* @method digest
|
|
957
|
+
* @memberof Md5
|
|
958
|
+
* @instance
|
|
959
|
+
* @description Output hash as bytes array
|
|
960
|
+
* @returns {Array} Bytes array
|
|
961
|
+
* @see {@link md5.digest}
|
|
962
|
+
* @example
|
|
963
|
+
* hash.digest();
|
|
964
|
+
*/
|
|
965
|
+
Md5.prototype.digest = function () {
|
|
966
|
+
this.finalize();
|
|
967
|
+
var h0 = this.h0,
|
|
968
|
+
h1 = this.h1,
|
|
969
|
+
h2 = this.h2,
|
|
970
|
+
h3 = this.h3;
|
|
971
|
+
return [h0 & 0xFF, h0 >> 8 & 0xFF, h0 >> 16 & 0xFF, h0 >> 24 & 0xFF, h1 & 0xFF, h1 >> 8 & 0xFF, h1 >> 16 & 0xFF, h1 >> 24 & 0xFF, h2 & 0xFF, h2 >> 8 & 0xFF, h2 >> 16 & 0xFF, h2 >> 24 & 0xFF, h3 & 0xFF, h3 >> 8 & 0xFF, h3 >> 16 & 0xFF, h3 >> 24 & 0xFF];
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* @method array
|
|
976
|
+
* @memberof Md5
|
|
977
|
+
* @instance
|
|
978
|
+
* @description Output hash as bytes array
|
|
979
|
+
* @returns {Array} Bytes array
|
|
980
|
+
* @see {@link md5.array}
|
|
981
|
+
* @example
|
|
982
|
+
* hash.array();
|
|
983
|
+
*/
|
|
984
|
+
Md5.prototype.array = Md5.prototype.digest;
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* @method arrayBuffer
|
|
988
|
+
* @memberof Md5
|
|
989
|
+
* @instance
|
|
990
|
+
* @description Output hash as ArrayBuffer
|
|
991
|
+
* @returns {ArrayBuffer} ArrayBuffer
|
|
992
|
+
* @see {@link md5.arrayBuffer}
|
|
993
|
+
* @example
|
|
994
|
+
* hash.arrayBuffer();
|
|
995
|
+
*/
|
|
996
|
+
Md5.prototype.arrayBuffer = function () {
|
|
997
|
+
this.finalize();
|
|
998
|
+
var buffer = new ArrayBuffer(16);
|
|
999
|
+
var blocks = new Uint32Array(buffer);
|
|
1000
|
+
blocks[0] = this.h0;
|
|
1001
|
+
blocks[1] = this.h1;
|
|
1002
|
+
blocks[2] = this.h2;
|
|
1003
|
+
blocks[3] = this.h3;
|
|
1004
|
+
return buffer;
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* @method buffer
|
|
1009
|
+
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
|
1010
|
+
* @memberof Md5
|
|
1011
|
+
* @instance
|
|
1012
|
+
* @description Output hash as ArrayBuffer
|
|
1013
|
+
* @returns {ArrayBuffer} ArrayBuffer
|
|
1014
|
+
* @see {@link md5.buffer}
|
|
1015
|
+
* @example
|
|
1016
|
+
* hash.buffer();
|
|
1017
|
+
*/
|
|
1018
|
+
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* @method base64
|
|
1022
|
+
* @memberof Md5
|
|
1023
|
+
* @instance
|
|
1024
|
+
* @description Output hash as base64 string
|
|
1025
|
+
* @returns {String} base64 string
|
|
1026
|
+
* @see {@link md5.base64}
|
|
1027
|
+
* @example
|
|
1028
|
+
* hash.base64();
|
|
1029
|
+
*/
|
|
1030
|
+
Md5.prototype.base64 = function () {
|
|
1031
|
+
var v1,
|
|
1032
|
+
v2,
|
|
1033
|
+
v3,
|
|
1034
|
+
base64Str = '',
|
|
1035
|
+
bytes = this.array();
|
|
1036
|
+
for (var i = 0; i < 15;) {
|
|
1037
|
+
v1 = bytes[i++];
|
|
1038
|
+
v2 = bytes[i++];
|
|
1039
|
+
v3 = bytes[i++];
|
|
1040
|
+
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] + BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] + BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] + BASE64_ENCODE_CHAR[v3 & 63];
|
|
1041
|
+
}
|
|
1042
|
+
v1 = bytes[i];
|
|
1043
|
+
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] + BASE64_ENCODE_CHAR[v1 << 4 & 63] + '==';
|
|
1044
|
+
return base64Str;
|
|
1045
|
+
};
|
|
1046
|
+
var exports = createMethod();
|
|
1047
|
+
if (COMMON_JS) {
|
|
1048
|
+
module.exports = exports;
|
|
1049
|
+
} else {
|
|
1050
|
+
/**
|
|
1051
|
+
* @method md5
|
|
1052
|
+
* @description Md5 hash function, export to global in browsers.
|
|
1053
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
1054
|
+
* @returns {String} md5 hashes
|
|
1055
|
+
* @example
|
|
1056
|
+
* md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
|
1057
|
+
* md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
|
|
1058
|
+
* md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
|
|
1059
|
+
*
|
|
1060
|
+
* // It also supports UTF-8 encoding
|
|
1061
|
+
* md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
|
1062
|
+
*
|
|
1063
|
+
* // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
|
1064
|
+
* md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
|
1065
|
+
* md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
|
1066
|
+
*/
|
|
1067
|
+
root.md5 = exports;
|
|
1068
|
+
}
|
|
1069
|
+
})();
|
|
1070
|
+
})(md5$1);
|
|
1071
|
+
var md5 = md5$1.exports;
|
|
1072
|
+
|
|
1073
|
+
function createMD5(value = '', length = 6) {
|
|
1074
|
+
return `${prefix}-${md5(value).substr(0, length)}`;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
function getDisplayName(Component) {
|
|
1078
|
+
return Component.displayName || Component.name || 'Component';
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const WithKeepAliveContextConsumerDisplayName = 'withKeepAliveContextConsumer';
|
|
1082
|
+
function withKeepAliveContextConsumer(Component) {
|
|
1083
|
+
const WithKeepAliveContextConsumer = props => (/*#__PURE__*/React.createElement(KeepAliveContext.Consumer, null, contextProps => /*#__PURE__*/React.createElement(Component, {
|
|
1084
|
+
_keepAliveContextProps: contextProps,
|
|
1085
|
+
...props
|
|
1086
|
+
})));
|
|
1087
|
+
WithKeepAliveContextConsumer.displayName = `${WithKeepAliveContextConsumerDisplayName}(${getDisplayName(Component)})`;
|
|
1088
|
+
return WithKeepAliveContextConsumer;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
function getKeyByFiberNode(fiberNode) {
|
|
1092
|
+
if (!fiberNode) {
|
|
1093
|
+
return null;
|
|
1094
|
+
}
|
|
1095
|
+
const {
|
|
1096
|
+
key,
|
|
1097
|
+
type
|
|
1098
|
+
} = fiberNode;
|
|
1099
|
+
if (type.displayName && type.displayName.indexOf(WithKeepAliveContextConsumerDisplayName) !== -1) {
|
|
1100
|
+
return key;
|
|
1101
|
+
}
|
|
1102
|
+
return getKeyByFiberNode(fiberNode.return);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
const withIdentificationContextConsumerDisplayName = 'withIdentificationContextConsumer';
|
|
1106
|
+
function withIdentificationContextConsumer(Component) {
|
|
1107
|
+
const WithIdentificationContextConsumer = props => (/*#__PURE__*/React.createElement(WithKeepAliveContext.Consumer, null, contextProps => /*#__PURE__*/React.createElement(Component, {
|
|
1108
|
+
_identificationContextProps: contextProps,
|
|
1109
|
+
...props
|
|
1110
|
+
})));
|
|
1111
|
+
WithIdentificationContextConsumer.displayName = `${withIdentificationContextConsumerDisplayName}(${getDisplayName(Component)})`;
|
|
1112
|
+
return WithIdentificationContextConsumer;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* From react
|
|
1117
|
+
*/
|
|
1118
|
+
function is(x, y) {
|
|
1119
|
+
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
|
1120
|
+
;
|
|
1121
|
+
}
|
|
1122
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1123
|
+
function shallowEqual(objA, objB) {
|
|
1124
|
+
if (is(objA, objB)) {
|
|
1125
|
+
return true;
|
|
1126
|
+
}
|
|
1127
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
const keysA = Object.keys(objA);
|
|
1131
|
+
const keysB = Object.keys(objB);
|
|
1132
|
+
if (keysA.length !== keysB.length) {
|
|
1133
|
+
return false;
|
|
1134
|
+
}
|
|
1135
|
+
// Test for A's keys different from B.
|
|
1136
|
+
for (const key of keysA) {
|
|
1137
|
+
if (!hasOwnProperty.call(objB, key) || !is(objA[key], objB[key])) {
|
|
1138
|
+
return false;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return true;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function isRegExp(value) {
|
|
1145
|
+
return value && Object.prototype.toString.call(value) === '[object RegExp]';
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
function matches(pattern, name) {
|
|
1149
|
+
if (Array.isArray(pattern)) {
|
|
1150
|
+
return pattern.indexOf(name) > -1;
|
|
1151
|
+
} else if (typeof pattern === 'string') {
|
|
1152
|
+
return pattern.split(',').indexOf(name) > -1;
|
|
1153
|
+
} else if (isRegExp(pattern)) {
|
|
1154
|
+
return pattern.test(name);
|
|
1155
|
+
}
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
function getKeepAlive(name, include, exclude, disabled) {
|
|
1159
|
+
if (disabled !== undefined) {
|
|
1160
|
+
return !disabled;
|
|
1161
|
+
}
|
|
1162
|
+
if (include && (!name || !matches(include, name)) || exclude && name && matches(exclude, name)) {
|
|
1163
|
+
return false;
|
|
1164
|
+
}
|
|
1165
|
+
return true;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
var COMMAND;
|
|
1169
|
+
(function (COMMAND) {
|
|
1170
|
+
COMMAND["UNACTIVATE"] = "unactivate";
|
|
1171
|
+
COMMAND["UNMOUNT"] = "unmount";
|
|
1172
|
+
COMMAND["ACTIVATE"] = "activate";
|
|
1173
|
+
COMMAND["CURRENT_UNMOUNT"] = "current_unmount";
|
|
1174
|
+
COMMAND["CURRENT_UNACTIVATE"] = "current_unactivate";
|
|
1175
|
+
})(COMMAND || (COMMAND = {}));
|
|
1176
|
+
/**
|
|
1177
|
+
* Decorating the <KeepAlive> component, the main function is to listen to events emitted by the upper <KeepAlive> component, triggering events of the current <KeepAlive> component.
|
|
1178
|
+
*
|
|
1179
|
+
* @export
|
|
1180
|
+
* @template P
|
|
1181
|
+
* @param {React.ComponentType<any>} Component
|
|
1182
|
+
* @returns {React.ComponentType<P>}
|
|
1183
|
+
*/
|
|
1184
|
+
function keepAliveDecorator(Component) {
|
|
1185
|
+
class TriggerLifecycleContainer extends React.PureComponent {
|
|
1186
|
+
identification;
|
|
1187
|
+
activated = false;
|
|
1188
|
+
ifStillActivate = false;
|
|
1189
|
+
// Let the lifecycle of the cached component be called normally.
|
|
1190
|
+
needActivate = true;
|
|
1191
|
+
lifecycle = LIFECYCLE.MOUNTED;
|
|
1192
|
+
constructor(props, ...args) {
|
|
1193
|
+
super(props, ...args);
|
|
1194
|
+
const {
|
|
1195
|
+
_keepAliveContextProps: {
|
|
1196
|
+
cache
|
|
1197
|
+
}
|
|
1198
|
+
} = props;
|
|
1199
|
+
if (!cache) {
|
|
1200
|
+
warn('[React Keep Alive] You should not use <KeepAlive> outside a <Provider>.');
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
componentDidMount() {
|
|
1204
|
+
if (!this.ifStillActivate) {
|
|
1205
|
+
this.activate();
|
|
1206
|
+
}
|
|
1207
|
+
const {
|
|
1208
|
+
keepAlive,
|
|
1209
|
+
_keepAliveContextProps: {
|
|
1210
|
+
eventEmitter
|
|
1211
|
+
}
|
|
1212
|
+
} = this.props;
|
|
1213
|
+
if (keepAlive) {
|
|
1214
|
+
this.needActivate = true;
|
|
1215
|
+
eventEmitter.emit([this.identification, COMMAND.ACTIVATE]);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
componentDidCatch() {
|
|
1219
|
+
if (!this.activated) {
|
|
1220
|
+
this.activate();
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
componentWillUnmount() {
|
|
1224
|
+
const {
|
|
1225
|
+
getCombinedKeepAlive,
|
|
1226
|
+
_keepAliveContextProps: {
|
|
1227
|
+
eventEmitter,
|
|
1228
|
+
isExisted
|
|
1229
|
+
}
|
|
1230
|
+
} = this.props;
|
|
1231
|
+
const keepAlive = getCombinedKeepAlive();
|
|
1232
|
+
if (!keepAlive || !isExisted()) {
|
|
1233
|
+
eventEmitter.emit([this.identification, COMMAND.CURRENT_UNMOUNT]);
|
|
1234
|
+
eventEmitter.emit([this.identification, COMMAND.UNMOUNT]);
|
|
1235
|
+
}
|
|
1236
|
+
// When the Provider components are unmounted, the cache is not needed,
|
|
1237
|
+
// so you don't have to execute the componentWillUnactivate lifecycle.
|
|
1238
|
+
if (keepAlive && isExisted()) {
|
|
1239
|
+
eventEmitter.emit([this.identification, COMMAND.CURRENT_UNACTIVATE]);
|
|
1240
|
+
eventEmitter.emit([this.identification, COMMAND.UNACTIVATE]);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
activate = () => {
|
|
1244
|
+
this.activated = true;
|
|
1245
|
+
};
|
|
1246
|
+
reactivate = () => {
|
|
1247
|
+
this.ifStillActivate = false;
|
|
1248
|
+
this.forceUpdate();
|
|
1249
|
+
};
|
|
1250
|
+
isNeedActivate = () => {
|
|
1251
|
+
return this.needActivate;
|
|
1252
|
+
};
|
|
1253
|
+
notNeedActivate = () => {
|
|
1254
|
+
this.needActivate = false;
|
|
1255
|
+
};
|
|
1256
|
+
getLifecycle = () => {
|
|
1257
|
+
return this.lifecycle;
|
|
1258
|
+
};
|
|
1259
|
+
setLifecycle = lifecycle => {
|
|
1260
|
+
this.lifecycle = lifecycle;
|
|
1261
|
+
};
|
|
1262
|
+
render() {
|
|
1263
|
+
const {
|
|
1264
|
+
propKey,
|
|
1265
|
+
keepAlive,
|
|
1266
|
+
extra,
|
|
1267
|
+
getCombinedKeepAlive,
|
|
1268
|
+
_keepAliveContextProps: {
|
|
1269
|
+
isExisted,
|
|
1270
|
+
storeElement,
|
|
1271
|
+
cache,
|
|
1272
|
+
eventEmitter,
|
|
1273
|
+
setCache,
|
|
1274
|
+
unactivate,
|
|
1275
|
+
providerIdentification
|
|
1276
|
+
},
|
|
1277
|
+
...wrapperProps
|
|
1278
|
+
} = this.props;
|
|
1279
|
+
if (!this.identification) {
|
|
1280
|
+
// We need to generate a corresponding unique identifier based on the information of the component.
|
|
1281
|
+
this.identification = createMD5(`${providerIdentification}${propKey}`);
|
|
1282
|
+
// The last activated component must be unactivated before it can be activated again.
|
|
1283
|
+
const currentCache = cache[this.identification];
|
|
1284
|
+
if (currentCache) {
|
|
1285
|
+
this.ifStillActivate = currentCache.activated;
|
|
1286
|
+
currentCache.ifStillActivate = this.ifStillActivate;
|
|
1287
|
+
currentCache.reactivate = this.reactivate;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
const {
|
|
1291
|
+
isNeedActivate,
|
|
1292
|
+
notNeedActivate,
|
|
1293
|
+
activated,
|
|
1294
|
+
getLifecycle,
|
|
1295
|
+
setLifecycle,
|
|
1296
|
+
identification,
|
|
1297
|
+
ifStillActivate
|
|
1298
|
+
} = this;
|
|
1299
|
+
return !ifStillActivate ? (/*#__PURE__*/React.createElement(Consumer, {
|
|
1300
|
+
identification: identification,
|
|
1301
|
+
keepAlive: keepAlive,
|
|
1302
|
+
cache: cache,
|
|
1303
|
+
setCache: setCache,
|
|
1304
|
+
unactivate: unactivate
|
|
1305
|
+
}, /*#__PURE__*/React.createElement(WithKeepAliveContext.Provider, {
|
|
1306
|
+
value: {
|
|
1307
|
+
identification,
|
|
1308
|
+
eventEmitter,
|
|
1309
|
+
keepAlive,
|
|
1310
|
+
activated,
|
|
1311
|
+
getLifecycle,
|
|
1312
|
+
isExisted,
|
|
1313
|
+
extra
|
|
1314
|
+
}
|
|
1315
|
+
}, /*#__PURE__*/React.createElement(Component, {
|
|
1316
|
+
...wrapperProps,
|
|
1317
|
+
_container: {
|
|
1318
|
+
isNeedActivate,
|
|
1319
|
+
notNeedActivate,
|
|
1320
|
+
setLifecycle,
|
|
1321
|
+
eventEmitter,
|
|
1322
|
+
identification,
|
|
1323
|
+
storeElement,
|
|
1324
|
+
keepAlive,
|
|
1325
|
+
cache
|
|
1326
|
+
}
|
|
1327
|
+
})))) : null;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
class ListenUpperKeepAliveContainer extends React.Component {
|
|
1331
|
+
combinedKeepAlive;
|
|
1332
|
+
state = {
|
|
1333
|
+
activated: true
|
|
1334
|
+
};
|
|
1335
|
+
activate;
|
|
1336
|
+
unactivate;
|
|
1337
|
+
unmount;
|
|
1338
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
1339
|
+
if (this.state.activated !== nextState.activated) {
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
const {
|
|
1343
|
+
_keepAliveContextProps,
|
|
1344
|
+
_identificationContextProps,
|
|
1345
|
+
...rest
|
|
1346
|
+
} = this.props;
|
|
1347
|
+
const {
|
|
1348
|
+
_keepAliveContextProps: nextKeepAliveContextProps,
|
|
1349
|
+
_identificationContextProps: nextIdentificationContextProps,
|
|
1350
|
+
...nextRest
|
|
1351
|
+
} = nextProps;
|
|
1352
|
+
if (!shallowEqual(rest, nextRest)) {
|
|
1353
|
+
return true;
|
|
1354
|
+
}
|
|
1355
|
+
if (!shallowEqual(_keepAliveContextProps, nextKeepAliveContextProps) || !shallowEqual(_identificationContextProps, nextIdentificationContextProps)) {
|
|
1356
|
+
return true;
|
|
1357
|
+
}
|
|
1358
|
+
return false;
|
|
1359
|
+
}
|
|
1360
|
+
componentDidMount() {
|
|
1361
|
+
this.listenUpperKeepAlive();
|
|
1362
|
+
}
|
|
1363
|
+
componentWillUnmount() {
|
|
1364
|
+
this.unlistenUpperKeepAlive();
|
|
1365
|
+
}
|
|
1366
|
+
listenUpperKeepAlive() {
|
|
1367
|
+
const {
|
|
1368
|
+
identification,
|
|
1369
|
+
eventEmitter
|
|
1370
|
+
} = this.props._identificationContextProps;
|
|
1371
|
+
if (!identification) {
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
eventEmitter.on([identification, COMMAND.ACTIVATE], this.activate = () => this.setState({
|
|
1375
|
+
activated: true
|
|
1376
|
+
}), true);
|
|
1377
|
+
eventEmitter.on([identification, COMMAND.UNACTIVATE], this.unactivate = () => this.setState({
|
|
1378
|
+
activated: false
|
|
1379
|
+
}), true);
|
|
1380
|
+
eventEmitter.on([identification, COMMAND.UNMOUNT], this.unmount = () => this.setState({
|
|
1381
|
+
activated: false
|
|
1382
|
+
}), true);
|
|
1383
|
+
}
|
|
1384
|
+
unlistenUpperKeepAlive() {
|
|
1385
|
+
const {
|
|
1386
|
+
identification,
|
|
1387
|
+
eventEmitter
|
|
1388
|
+
} = this.props._identificationContextProps;
|
|
1389
|
+
if (!identification) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
eventEmitter.off([identification, COMMAND.ACTIVATE], this.activate);
|
|
1393
|
+
eventEmitter.off([identification, COMMAND.UNACTIVATE], this.unactivate);
|
|
1394
|
+
eventEmitter.off([identification, COMMAND.UNMOUNT], this.unmount);
|
|
1395
|
+
}
|
|
1396
|
+
getCombinedKeepAlive = () => {
|
|
1397
|
+
return this.combinedKeepAlive;
|
|
1398
|
+
};
|
|
1399
|
+
render() {
|
|
1400
|
+
const {
|
|
1401
|
+
_identificationContextProps: {
|
|
1402
|
+
identification,
|
|
1403
|
+
keepAlive: upperKeepAlive,
|
|
1404
|
+
getLifecycle
|
|
1405
|
+
},
|
|
1406
|
+
disabled,
|
|
1407
|
+
name,
|
|
1408
|
+
...wrapperProps
|
|
1409
|
+
} = this.props;
|
|
1410
|
+
const {
|
|
1411
|
+
activated
|
|
1412
|
+
} = this.state;
|
|
1413
|
+
const {
|
|
1414
|
+
_keepAliveContextProps: {
|
|
1415
|
+
include,
|
|
1416
|
+
exclude
|
|
1417
|
+
}
|
|
1418
|
+
} = wrapperProps;
|
|
1419
|
+
// When the parent KeepAlive component is mounted or unmounted,
|
|
1420
|
+
// use the keepAlive prop of the parent KeepAlive component.
|
|
1421
|
+
const propKey = name || getKeyByFiberNode(this._reactInternalFiber);
|
|
1422
|
+
if (!propKey) {
|
|
1423
|
+
warn('[React Keep Alive] <KeepAlive> components must have key or name.');
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
const newKeepAlive = getKeepAlive(propKey, include, exclude, disabled);
|
|
1427
|
+
this.combinedKeepAlive = getLifecycle === undefined || getLifecycle() === LIFECYCLE.UPDATING ? newKeepAlive : identification ? upperKeepAlive && newKeepAlive : newKeepAlive;
|
|
1428
|
+
return activated ? (/*#__PURE__*/React.createElement(TriggerLifecycleContainer, {
|
|
1429
|
+
...wrapperProps,
|
|
1430
|
+
key: propKey,
|
|
1431
|
+
propKey: propKey,
|
|
1432
|
+
keepAlive: this.combinedKeepAlive,
|
|
1433
|
+
getCombinedKeepAlive: this.getCombinedKeepAlive
|
|
1434
|
+
})) : null;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
const KeepAlive = withKeepAliveContextConsumer(withIdentificationContextConsumer(ListenUpperKeepAliveContainer));
|
|
1438
|
+
return hoistNonReactStatics(KeepAlive, Component);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
const bindLifecycleTypeName = '$$bindLifecycle';
|
|
1442
|
+
function bindLifecycle(Component) {
|
|
1443
|
+
const WrappedComponent = Component.WrappedComponent || Component.wrappedComponent || Component;
|
|
1444
|
+
const {
|
|
1445
|
+
componentDidMount = noop,
|
|
1446
|
+
componentDidUpdate = noop,
|
|
1447
|
+
componentDidActivate = noop,
|
|
1448
|
+
componentWillUnactivate = noop,
|
|
1449
|
+
componentWillUnmount = noop,
|
|
1450
|
+
shouldComponentUpdate = noop
|
|
1451
|
+
} = WrappedComponent.prototype;
|
|
1452
|
+
WrappedComponent.prototype.componentDidMount = function () {
|
|
1453
|
+
componentDidMount.call(this);
|
|
1454
|
+
this._needActivate = false;
|
|
1455
|
+
const {
|
|
1456
|
+
_container: {
|
|
1457
|
+
identification,
|
|
1458
|
+
eventEmitter,
|
|
1459
|
+
activated
|
|
1460
|
+
},
|
|
1461
|
+
keepAlive
|
|
1462
|
+
} = this.props;
|
|
1463
|
+
// Determine whether to execute the componentDidActivate life cycle of the current component based on the activation state of the KeepAlive components
|
|
1464
|
+
if (!activated && keepAlive !== false) {
|
|
1465
|
+
componentDidActivate.call(this);
|
|
1466
|
+
}
|
|
1467
|
+
eventEmitter.on([identification, COMMAND.ACTIVATE], this._bindActivate = () => this._needActivate = true, true);
|
|
1468
|
+
eventEmitter.on([identification, COMMAND.UNACTIVATE], this._bindUnactivate = () => {
|
|
1469
|
+
componentWillUnactivate.call(this);
|
|
1470
|
+
this._unmounted = false;
|
|
1471
|
+
}, true);
|
|
1472
|
+
eventEmitter.on([identification, COMMAND.UNMOUNT], this._bindUnmount = () => {
|
|
1473
|
+
componentWillUnmount.call(this);
|
|
1474
|
+
this._unmounted = true;
|
|
1475
|
+
}, true);
|
|
1476
|
+
};
|
|
1477
|
+
// In order to be able to re-update after transferring the DOM, we need to block the first update.
|
|
1478
|
+
WrappedComponent.prototype.shouldComponentUpdate = function (...args) {
|
|
1479
|
+
if (this._needActivate) {
|
|
1480
|
+
this.forceUpdate();
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
return shouldComponentUpdate.call(this, ...args) || true;
|
|
1484
|
+
};
|
|
1485
|
+
WrappedComponent.prototype.componentDidUpdate = function (...args) {
|
|
1486
|
+
componentDidUpdate.call(this, ...args);
|
|
1487
|
+
if (this._needActivate) {
|
|
1488
|
+
this._needActivate = false;
|
|
1489
|
+
componentDidActivate.call(this);
|
|
1490
|
+
}
|
|
1491
|
+
};
|
|
1492
|
+
WrappedComponent.prototype.componentWillUnmount = function () {
|
|
1493
|
+
if (!this._unmounted) {
|
|
1494
|
+
componentWillUnmount.call(this);
|
|
1495
|
+
}
|
|
1496
|
+
const {
|
|
1497
|
+
_container: {
|
|
1498
|
+
identification,
|
|
1499
|
+
eventEmitter
|
|
1500
|
+
}
|
|
1501
|
+
} = this.props;
|
|
1502
|
+
eventEmitter.off([identification, COMMAND.ACTIVATE], this._bindActivate);
|
|
1503
|
+
eventEmitter.off([identification, COMMAND.UNACTIVATE], this._bindUnactivate);
|
|
1504
|
+
eventEmitter.off([identification, COMMAND.UNMOUNT], this._bindUnmount);
|
|
1505
|
+
};
|
|
1506
|
+
const BindLifecycleHOC = withIdentificationContextConsumer(({
|
|
1507
|
+
forwardRef,
|
|
1508
|
+
_identificationContextProps: {
|
|
1509
|
+
identification,
|
|
1510
|
+
eventEmitter,
|
|
1511
|
+
activated,
|
|
1512
|
+
keepAlive,
|
|
1513
|
+
extra
|
|
1514
|
+
},
|
|
1515
|
+
...wrapperProps
|
|
1516
|
+
}) => {
|
|
1517
|
+
if (!identification) {
|
|
1518
|
+
warn('[React Keep Alive] You should not use bindLifecycle outside a <KeepAlive>.');
|
|
1519
|
+
return null;
|
|
1520
|
+
}
|
|
1521
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
1522
|
+
...extra,
|
|
1523
|
+
...wrapperProps,
|
|
1524
|
+
ref: forwardRef || noop,
|
|
1525
|
+
_container: {
|
|
1526
|
+
identification,
|
|
1527
|
+
eventEmitter,
|
|
1528
|
+
activated,
|
|
1529
|
+
keepAlive
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
});
|
|
1533
|
+
const BindLifecycle = /*#__PURE__*/React.forwardRef((props, ref) => (/*#__PURE__*/React.createElement(BindLifecycleHOC, {
|
|
1534
|
+
...props,
|
|
1535
|
+
forwardRef: ref
|
|
1536
|
+
})));
|
|
1537
|
+
BindLifecycle.WrappedComponent = WrappedComponent;
|
|
1538
|
+
BindLifecycle.displayName = `${bindLifecycleTypeName}(${getDisplayName(Component)})`;
|
|
1539
|
+
return hoistNonReactStatics(BindLifecycle, Component);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
class AsyncComponent extends React.Component {
|
|
1543
|
+
state = {
|
|
1544
|
+
component: null
|
|
1545
|
+
};
|
|
1546
|
+
/**
|
|
1547
|
+
* Force update child nodes
|
|
1548
|
+
*
|
|
1549
|
+
* @private
|
|
1550
|
+
* @returns
|
|
1551
|
+
* @memberof AsyncComponent
|
|
1552
|
+
*/
|
|
1553
|
+
forceUpdateChildren() {
|
|
1554
|
+
if (!this.props.children) {
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
const root = this._reactInternalFiber || this._reactInternalInstance;
|
|
1558
|
+
if (!root) return;
|
|
1559
|
+
let node = root.child;
|
|
1560
|
+
let sibling = node;
|
|
1561
|
+
while (sibling) {
|
|
1562
|
+
while (true) {
|
|
1563
|
+
if (node.type && node.type.displayName && node.type.displayName.indexOf(bindLifecycleTypeName) !== -1) {
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
if (node.stateNode) {
|
|
1567
|
+
break;
|
|
1568
|
+
}
|
|
1569
|
+
node = node.child;
|
|
1570
|
+
}
|
|
1571
|
+
if (typeof node.type === 'function') {
|
|
1572
|
+
node.stateNode.forceUpdate();
|
|
1573
|
+
}
|
|
1574
|
+
sibling = sibling.sibling;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
componentDidMount() {
|
|
1578
|
+
const {
|
|
1579
|
+
children
|
|
1580
|
+
} = this.props;
|
|
1581
|
+
Promise.resolve().then(() => this.setState({
|
|
1582
|
+
component: children
|
|
1583
|
+
}));
|
|
1584
|
+
}
|
|
1585
|
+
componentDidUpdate() {
|
|
1586
|
+
this.props.onUpdate();
|
|
1587
|
+
}
|
|
1588
|
+
// Delayed update
|
|
1589
|
+
// In order to be able to get real DOM data
|
|
1590
|
+
shouldComponentUpdate() {
|
|
1591
|
+
if (!this.state.component) {
|
|
1592
|
+
// If it is already mounted asynchronously, you don't need to do it again when you update it.
|
|
1593
|
+
this.props.setMounted(false);
|
|
1594
|
+
return true;
|
|
1595
|
+
}
|
|
1596
|
+
Promise.resolve().then(() => {
|
|
1597
|
+
if (this.props.getMounted()) {
|
|
1598
|
+
this.props.setMounted(false);
|
|
1599
|
+
this.forceUpdateChildren();
|
|
1600
|
+
this.props.onUpdate();
|
|
1601
|
+
}
|
|
1602
|
+
});
|
|
1603
|
+
return false;
|
|
1604
|
+
}
|
|
1605
|
+
render() {
|
|
1606
|
+
return this.state.component;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
var NODE_TYPES;
|
|
1611
|
+
(function (NODE_TYPES) {
|
|
1612
|
+
NODE_TYPES[NODE_TYPES["ELEMENT"] = 1] = "ELEMENT";
|
|
1613
|
+
NODE_TYPES[NODE_TYPES["COMMENT"] = 8] = "COMMENT";
|
|
1614
|
+
})(NODE_TYPES || (NODE_TYPES = {}));
|
|
1615
|
+
function findElementsBetweenComments(node, identification) {
|
|
1616
|
+
const elements = [];
|
|
1617
|
+
const childNodes = node.childNodes;
|
|
1618
|
+
let startCommentExist = false;
|
|
1619
|
+
for (const child of childNodes) {
|
|
1620
|
+
if (child.nodeType === NODE_TYPES.COMMENT && child.nodeValue.trim() === identification && !startCommentExist) {
|
|
1621
|
+
startCommentExist = true;
|
|
1622
|
+
} else if (startCommentExist && child.nodeType === NODE_TYPES.ELEMENT) {
|
|
1623
|
+
elements.push(child);
|
|
1624
|
+
} else if (child.nodeType === NODE_TYPES.COMMENT && startCommentExist) {
|
|
1625
|
+
return elements;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
return elements;
|
|
1629
|
+
}
|
|
1630
|
+
function findComment(node, identification) {
|
|
1631
|
+
const childNodes = node.childNodes;
|
|
1632
|
+
for (const child of childNodes) {
|
|
1633
|
+
if (child.nodeType === NODE_TYPES.COMMENT && child.nodeValue.trim() === identification) {
|
|
1634
|
+
return child;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
function changePositionByComment(identification, presentParentNode, originalParentNode) {
|
|
1639
|
+
if (!presentParentNode || !originalParentNode) {
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
const elementNodes = findElementsBetweenComments(originalParentNode, identification);
|
|
1643
|
+
const commentNode = findComment(presentParentNode, identification);
|
|
1644
|
+
if (!elementNodes.length || !commentNode) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
elementNodes.push(elementNodes[elementNodes.length - 1].nextSibling);
|
|
1648
|
+
elementNodes.unshift(elementNodes[0].previousSibling);
|
|
1649
|
+
// Deleting comment elements when using commet components will result in component uninstallation errors
|
|
1650
|
+
for (let i = elementNodes.length - 1; i >= 0; i--) {
|
|
1651
|
+
try {
|
|
1652
|
+
presentParentNode.insertBefore(elementNodes[i], commentNode);
|
|
1653
|
+
} catch (error) {
|
|
1654
|
+
mchcLogger.error('insertBefore', {
|
|
1655
|
+
presentParentNode,
|
|
1656
|
+
elementNodes: elementNodes[i],
|
|
1657
|
+
commentNode
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
originalParentNode.appendChild(commentNode);
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
class KeepAlive extends React.PureComponent {
|
|
1665
|
+
bindUnmount = null;
|
|
1666
|
+
bindUnactivate = null;
|
|
1667
|
+
unmounted = false;
|
|
1668
|
+
mounted = false;
|
|
1669
|
+
ref = null;
|
|
1670
|
+
refNextSibling = null;
|
|
1671
|
+
childNodes = [];
|
|
1672
|
+
componentDidMount() {
|
|
1673
|
+
const {
|
|
1674
|
+
_container
|
|
1675
|
+
} = this.props;
|
|
1676
|
+
console.log('pro', this.props, this.props._container.eventEmitter);
|
|
1677
|
+
const {
|
|
1678
|
+
notNeedActivate,
|
|
1679
|
+
identification,
|
|
1680
|
+
eventEmitter,
|
|
1681
|
+
keepAlive
|
|
1682
|
+
} = _container;
|
|
1683
|
+
notNeedActivate();
|
|
1684
|
+
const cb = () => {
|
|
1685
|
+
this.mount();
|
|
1686
|
+
this.listen();
|
|
1687
|
+
eventEmitter.off([identification, START_MOUNTING_DOM], cb);
|
|
1688
|
+
};
|
|
1689
|
+
eventEmitter.on([identification, START_MOUNTING_DOM], cb);
|
|
1690
|
+
if (keepAlive) {
|
|
1691
|
+
this.componentDidActivate();
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
componentDidActivate() {
|
|
1695
|
+
// tslint-disable
|
|
1696
|
+
}
|
|
1697
|
+
componentDidUpdate() {
|
|
1698
|
+
const {
|
|
1699
|
+
_container
|
|
1700
|
+
} = this.props;
|
|
1701
|
+
const {
|
|
1702
|
+
notNeedActivate,
|
|
1703
|
+
isNeedActivate
|
|
1704
|
+
} = _container;
|
|
1705
|
+
if (isNeedActivate()) {
|
|
1706
|
+
notNeedActivate();
|
|
1707
|
+
this.mount();
|
|
1708
|
+
this.listen();
|
|
1709
|
+
this.unmounted = false;
|
|
1710
|
+
this.componentDidActivate();
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
componentWillUnactivate() {
|
|
1714
|
+
this.unmount();
|
|
1715
|
+
this.unlisten();
|
|
1716
|
+
}
|
|
1717
|
+
componentWillUnmount() {
|
|
1718
|
+
if (!this.unmounted) {
|
|
1719
|
+
this.unmounted = true;
|
|
1720
|
+
this.unmount();
|
|
1721
|
+
this.unlisten();
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
mount() {
|
|
1725
|
+
const {
|
|
1726
|
+
_container: {
|
|
1727
|
+
cache,
|
|
1728
|
+
identification,
|
|
1729
|
+
storeElement,
|
|
1730
|
+
setLifecycle
|
|
1731
|
+
}
|
|
1732
|
+
} = this.props;
|
|
1733
|
+
this.setMounted(true);
|
|
1734
|
+
const {
|
|
1735
|
+
renderElement
|
|
1736
|
+
} = cache[identification];
|
|
1737
|
+
setLifecycle(LIFECYCLE.UPDATING);
|
|
1738
|
+
changePositionByComment(identification, renderElement, storeElement);
|
|
1739
|
+
}
|
|
1740
|
+
correctionPosition = () => {
|
|
1741
|
+
if (this.ref && this.ref.parentNode && this.ref.nextSibling) {
|
|
1742
|
+
const childNodes = this.ref.childNodes;
|
|
1743
|
+
this.refNextSibling = this.ref.nextSibling;
|
|
1744
|
+
this.childNodes = [];
|
|
1745
|
+
while (childNodes.length) {
|
|
1746
|
+
const child = childNodes[0];
|
|
1747
|
+
this.childNodes.push(child);
|
|
1748
|
+
try {
|
|
1749
|
+
this.ref.parentNode.insertBefore(child, this.ref.nextSibling);
|
|
1750
|
+
} catch (error) {
|
|
1751
|
+
mchcLogger.error('insertBefore', {
|
|
1752
|
+
error,
|
|
1753
|
+
ref: this.ref,
|
|
1754
|
+
child,
|
|
1755
|
+
parent: this.ref.parentNode,
|
|
1756
|
+
nextSibling: this.ref.nextSibling
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
this.ref.parentNode.removeChild(this.ref);
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
mchcLogger.error('removeChild', {
|
|
1764
|
+
error,
|
|
1765
|
+
ref: this.ref,
|
|
1766
|
+
parent: this.ref.parentNode
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
retreatPosition = () => {
|
|
1772
|
+
if (this.ref && this.refNextSibling && this.refNextSibling.parentNode) {
|
|
1773
|
+
for (const child of this.childNodes) {
|
|
1774
|
+
this.ref.appendChild(child);
|
|
1775
|
+
}
|
|
1776
|
+
try {
|
|
1777
|
+
this.refNextSibling.parentNode.insertBefore(this.ref, this.refNextSibling);
|
|
1778
|
+
} catch (error) {
|
|
1779
|
+
mchcLogger.error('insertBefore', {
|
|
1780
|
+
error,
|
|
1781
|
+
ref: this.ref,
|
|
1782
|
+
parent: this.refNextSibling.parentNode,
|
|
1783
|
+
nextSibling: this.refNextSibling
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
unmount() {
|
|
1789
|
+
const {
|
|
1790
|
+
_container: {
|
|
1791
|
+
identification,
|
|
1792
|
+
storeElement,
|
|
1793
|
+
cache,
|
|
1794
|
+
setLifecycle
|
|
1795
|
+
}
|
|
1796
|
+
} = this.props;
|
|
1797
|
+
if (cache[identification]) {
|
|
1798
|
+
const {
|
|
1799
|
+
renderElement,
|
|
1800
|
+
ifStillActivate,
|
|
1801
|
+
reactivate
|
|
1802
|
+
} = cache[identification];
|
|
1803
|
+
setLifecycle(LIFECYCLE.UNMOUNTED);
|
|
1804
|
+
this.retreatPosition();
|
|
1805
|
+
changePositionByComment(identification, storeElement, renderElement);
|
|
1806
|
+
if (ifStillActivate) {
|
|
1807
|
+
reactivate();
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
listen() {
|
|
1812
|
+
const {
|
|
1813
|
+
_container: {
|
|
1814
|
+
identification,
|
|
1815
|
+
eventEmitter
|
|
1816
|
+
}
|
|
1817
|
+
} = this.props;
|
|
1818
|
+
eventEmitter.on([identification, COMMAND.CURRENT_UNMOUNT], this.bindUnmount = this.componentWillUnmount.bind(this));
|
|
1819
|
+
eventEmitter.on([identification, COMMAND.CURRENT_UNACTIVATE], this.bindUnactivate = this.componentWillUnactivate.bind(this));
|
|
1820
|
+
}
|
|
1821
|
+
unlisten() {
|
|
1822
|
+
const {
|
|
1823
|
+
_container: {
|
|
1824
|
+
identification,
|
|
1825
|
+
eventEmitter
|
|
1826
|
+
}
|
|
1827
|
+
} = this.props;
|
|
1828
|
+
eventEmitter.off([identification, COMMAND.CURRENT_UNMOUNT], this.bindUnmount);
|
|
1829
|
+
eventEmitter.off([identification, COMMAND.CURRENT_UNACTIVATE], this.bindUnactivate);
|
|
1830
|
+
}
|
|
1831
|
+
setMounted = value => {
|
|
1832
|
+
this.mounted = value;
|
|
1833
|
+
};
|
|
1834
|
+
getMounted = () => {
|
|
1835
|
+
return this.mounted;
|
|
1836
|
+
};
|
|
1837
|
+
render() {
|
|
1838
|
+
// The purpose of this div is to not report an error when moving the DOM,
|
|
1839
|
+
// so you need to remove this div later.
|
|
1840
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1841
|
+
ref: ref => this.ref = ref
|
|
1842
|
+
}, /*#__PURE__*/React.createElement(AsyncComponent, {
|
|
1843
|
+
setMounted: this.setMounted,
|
|
1844
|
+
getMounted: this.getMounted,
|
|
1845
|
+
onUpdate: this.correctionPosition
|
|
1846
|
+
}, this.props.children));
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
var keepAlive = keepAliveDecorator(KeepAlive);
|
|
1850
|
+
|
|
1851
|
+
function useKeepAliveEffect(effect) {
|
|
1852
|
+
if (!useEffect) {
|
|
1853
|
+
warn('[React Keep Alive] useKeepAliveEffect API requires react 16.8 or later.');
|
|
1854
|
+
}
|
|
1855
|
+
const {
|
|
1856
|
+
eventEmitter,
|
|
1857
|
+
identification
|
|
1858
|
+
} = useContext(WithKeepAliveContext);
|
|
1859
|
+
const effectRef = useRef(effect);
|
|
1860
|
+
effectRef.current = effect;
|
|
1861
|
+
useEffect(() => {
|
|
1862
|
+
if (!eventEmitter) {
|
|
1863
|
+
console.log('pro', 'eventEmitter not found');
|
|
1864
|
+
return useEffect(effectRef.current);
|
|
1865
|
+
}
|
|
1866
|
+
let bindActivate = null;
|
|
1867
|
+
let bindUnactivate = null;
|
|
1868
|
+
let bindUnmount = null;
|
|
1869
|
+
let effectResult = effectRef.current();
|
|
1870
|
+
let unmounted = false;
|
|
1871
|
+
eventEmitter.on([identification, COMMAND.ACTIVATE], bindActivate = () => {
|
|
1872
|
+
// Delayed update
|
|
1873
|
+
Promise.resolve().then(() => {
|
|
1874
|
+
effectResult = effectRef.current();
|
|
1875
|
+
});
|
|
1876
|
+
unmounted = false;
|
|
1877
|
+
}, true);
|
|
1878
|
+
eventEmitter.on([identification, COMMAND.UNACTIVATE], bindUnactivate = () => {
|
|
1879
|
+
if (effectResult) {
|
|
1880
|
+
effectResult();
|
|
1881
|
+
unmounted = true;
|
|
1882
|
+
}
|
|
1883
|
+
}, true);
|
|
1884
|
+
eventEmitter.on([identification, COMMAND.UNMOUNT], bindUnmount = () => {
|
|
1885
|
+
if (effectResult) {
|
|
1886
|
+
effectResult();
|
|
1887
|
+
unmounted = true;
|
|
1888
|
+
}
|
|
1889
|
+
}, true);
|
|
1890
|
+
return () => {
|
|
1891
|
+
if (effectResult && !unmounted) {
|
|
1892
|
+
effectResult();
|
|
1893
|
+
}
|
|
1894
|
+
eventEmitter.off([identification, COMMAND.ACTIVATE], bindActivate);
|
|
1895
|
+
eventEmitter.off([identification, COMMAND.UNACTIVATE], bindUnactivate);
|
|
1896
|
+
eventEmitter.off([identification, COMMAND.UNMOUNT], bindUnmount);
|
|
1897
|
+
};
|
|
1898
|
+
}, []);
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
export { keepAlive as KeepAlive, KeepAliveProvider as Provider, bindLifecycle, useKeepAliveEffect };
|