@xfe-repo/web-register 1.3.4 → 1.3.5
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/dist/index.js +43 -68
- package/dist/index.mjs +44 -69
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -4,9 +4,6 @@ function _array_like_to_array(arr, len) {
|
|
|
4
4
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
5
|
return arr2;
|
|
6
6
|
}
|
|
7
|
-
function _array_with_holes(arr) {
|
|
8
|
-
if (Array.isArray(arr)) return arr;
|
|
9
|
-
}
|
|
10
7
|
function _array_without_holes(arr) {
|
|
11
8
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
9
|
}
|
|
@@ -81,33 +78,6 @@ function _instanceof(left, right) {
|
|
|
81
78
|
function _iterable_to_array(iter) {
|
|
82
79
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
83
80
|
}
|
|
84
|
-
function _iterable_to_array_limit(arr, i) {
|
|
85
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
86
|
-
if (_i == null) return;
|
|
87
|
-
var _arr = [];
|
|
88
|
-
var _n = true;
|
|
89
|
-
var _d = false;
|
|
90
|
-
var _s, _e;
|
|
91
|
-
try {
|
|
92
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
93
|
-
_arr.push(_s.value);
|
|
94
|
-
if (i && _arr.length === i) break;
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
_d = true;
|
|
98
|
-
_e = err;
|
|
99
|
-
} finally{
|
|
100
|
-
try {
|
|
101
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
102
|
-
} finally{
|
|
103
|
-
if (_d) throw _e;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return _arr;
|
|
107
|
-
}
|
|
108
|
-
function _non_iterable_rest() {
|
|
109
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
110
|
-
}
|
|
111
81
|
function _non_iterable_spread() {
|
|
112
82
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
113
83
|
}
|
|
@@ -150,9 +120,6 @@ function _object_spread_props(target, source) {
|
|
|
150
120
|
}
|
|
151
121
|
return target;
|
|
152
122
|
}
|
|
153
|
-
function _sliced_to_array(arr, i) {
|
|
154
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
155
|
-
}
|
|
156
123
|
function _to_consumable_array(arr) {
|
|
157
124
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
158
125
|
}
|
|
@@ -334,33 +301,47 @@ module.exports = __toCommonJS(src_exports);
|
|
|
334
301
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
335
302
|
// src/Register.tsx
|
|
336
303
|
var import_react = require("react");
|
|
304
|
+
var import_react_use = require("react-use");
|
|
337
305
|
var import_react_helmet = require("react-helmet");
|
|
338
306
|
var import_query_string = __toESM(require("query-string"));
|
|
339
307
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
340
308
|
var createRegisterComponent = function(config, getContext, WrappedComponent) {
|
|
341
309
|
var RegisterComponent = (0, import_react.memo)(function(props) {
|
|
342
310
|
var context = getContext();
|
|
343
|
-
var isPreload =
|
|
311
|
+
var _getContext = getContext(), isPreload = _getContext.isPreload, error = _getContext.error;
|
|
344
312
|
var name = config.name, ErrorFullback = config.ErrorFullback, LoadFullback = config.LoadFullback, renderTitle = config.renderTitle, getQuery = config.getQuery;
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
var
|
|
354
|
-
var _ref1 = _sliced_to_array((0, import_react.useState)(), 2), loadError = _ref1[0], setLoadError = _ref1[1];
|
|
355
|
-
var isLeave = false;
|
|
313
|
+
var forceUpdate = (0, import_react_use.useUpdate)();
|
|
314
|
+
var registerStateRef = (0, import_react.useRef)({
|
|
315
|
+
isPreload: !!isPreload,
|
|
316
|
+
isLeaved: false,
|
|
317
|
+
hasError: !!error,
|
|
318
|
+
loading: !isPreload
|
|
319
|
+
});
|
|
320
|
+
var showError = registerStateRef.current.hasError && ErrorFullback;
|
|
321
|
+
var showLoading = registerStateRef.current.loading && LoadFullback;
|
|
356
322
|
var emitLoad = (0, import_react.useCallback)(/*#__PURE__*/ _async_to_generator(function() {
|
|
357
|
-
var _WrappedComponent_emitOnLoad,
|
|
323
|
+
var _WrappedComponent_emitOnLoad, _registerStateRef_current, hasError, isPreload2, isLeaved, queryFromContext, isParsed, query, _ref, error2, needUpdate;
|
|
358
324
|
return _ts_generator(this, function(_state) {
|
|
359
325
|
switch(_state.label){
|
|
360
326
|
case 0:
|
|
361
|
-
|
|
327
|
+
_registerStateRef_current = registerStateRef.current, hasError = _registerStateRef_current.hasError, isPreload2 = _registerStateRef_current.isPreload, isLeaved = _registerStateRef_current.isLeaved;
|
|
328
|
+
if (hasError) {
|
|
329
|
+
registerStateRef.current.hasError = false;
|
|
330
|
+
delete getContext().error;
|
|
331
|
+
}
|
|
332
|
+
if (isPreload2) {
|
|
333
|
+
registerStateRef.current.isPreload = false;
|
|
334
|
+
delete getContext().isPreload;
|
|
335
|
+
}
|
|
336
|
+
if (hasError || isPreload2 || isLeaved) return [
|
|
362
337
|
2
|
|
363
338
|
];
|
|
339
|
+
queryFromContext = (getQuery === null || getQuery === void 0 ? void 0 : getQuery(context)) || "";
|
|
340
|
+
isParsed = typeof queryFromContext === "object";
|
|
341
|
+
query = isParsed ? queryFromContext : import_query_string.default.parse(queryFromContext, {
|
|
342
|
+
parseBooleans: true,
|
|
343
|
+
parseNumbers: true
|
|
344
|
+
});
|
|
364
345
|
return [
|
|
365
346
|
4,
|
|
366
347
|
(_WrappedComponent_emitOnLoad = WrappedComponent.emitOnLoad) === null || _WrappedComponent_emitOnLoad === void 0 ? void 0 : _WrappedComponent_emitOnLoad.call(WrappedComponent, {
|
|
@@ -368,35 +349,29 @@ var createRegisterComponent = function(config, getContext, WrappedComponent) {
|
|
|
368
349
|
})
|
|
369
350
|
];
|
|
370
351
|
case 1:
|
|
371
|
-
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
352
|
+
_ref = _state.sent() || {}, error2 = _ref.error;
|
|
353
|
+
if (error2) registerStateRef.current.hasError = true;
|
|
354
|
+
needUpdate = false;
|
|
355
|
+
if (registerStateRef.current.hasError && ErrorFullback) needUpdate = true;
|
|
356
|
+
if (registerStateRef.current.loading && LoadFullback) needUpdate = true;
|
|
357
|
+
if (needUpdate) forceUpdate();
|
|
377
358
|
return [
|
|
378
359
|
2
|
|
379
360
|
];
|
|
380
361
|
}
|
|
381
362
|
});
|
|
382
|
-
}), [
|
|
383
|
-
needLoad,
|
|
384
|
-
loadError
|
|
385
|
-
]);
|
|
363
|
+
}), []);
|
|
386
364
|
void emitLoad();
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
(_WrappedComponent_emitOnLeave = WrappedComponent.emitOnLeave) === null || _WrappedComponent_emitOnLeave === void 0 ? void 0 : _WrappedComponent_emitOnLeave.call(WrappedComponent);
|
|
393
|
-
};
|
|
394
|
-
}, []);
|
|
365
|
+
(0, import_react_use.useUnmount)(function() {
|
|
366
|
+
var _WrappedComponent_emitOnLeave;
|
|
367
|
+
registerStateRef.current.isLeaved = true;
|
|
368
|
+
(_WrappedComponent_emitOnLeave = WrappedComponent.emitOnLeave) === null || _WrappedComponent_emitOnLeave === void 0 ? void 0 : _WrappedComponent_emitOnLeave.call(WrappedComponent);
|
|
369
|
+
});
|
|
395
370
|
var content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, _object_spread_props(_object_spread({}, props), {
|
|
396
371
|
context: context
|
|
397
372
|
}));
|
|
398
|
-
if (
|
|
399
|
-
if (
|
|
373
|
+
if (showError) content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorFullback, {});
|
|
374
|
+
if (showLoading) content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadFullback, {});
|
|
400
375
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, {
|
|
401
376
|
children: [
|
|
402
377
|
renderTitle && name && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_helmet.Helmet, {
|
|
@@ -531,7 +506,7 @@ var createRegister = function(options) {
|
|
|
531
506
|
];
|
|
532
507
|
case 12:
|
|
533
508
|
e = _state.sent();
|
|
534
|
-
context.error = _instanceof(e, Error) ? e : new Error("register onLoad error");
|
|
509
|
+
context.error = _instanceof(e, Error) ? e : new Error(String(e) || "register onLoad error");
|
|
535
510
|
onError ? onError(e) : console.error(e);
|
|
536
511
|
return [
|
|
537
512
|
3,
|
package/dist/index.mjs
CHANGED
|
@@ -4,9 +4,6 @@ function _array_like_to_array(arr, len) {
|
|
|
4
4
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
5
|
return arr2;
|
|
6
6
|
}
|
|
7
|
-
function _array_with_holes(arr) {
|
|
8
|
-
if (Array.isArray(arr)) return arr;
|
|
9
|
-
}
|
|
10
7
|
function _array_without_holes(arr) {
|
|
11
8
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
9
|
}
|
|
@@ -81,33 +78,6 @@ function _instanceof(left, right) {
|
|
|
81
78
|
function _iterable_to_array(iter) {
|
|
82
79
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
83
80
|
}
|
|
84
|
-
function _iterable_to_array_limit(arr, i) {
|
|
85
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
86
|
-
if (_i == null) return;
|
|
87
|
-
var _arr = [];
|
|
88
|
-
var _n = true;
|
|
89
|
-
var _d = false;
|
|
90
|
-
var _s, _e;
|
|
91
|
-
try {
|
|
92
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
93
|
-
_arr.push(_s.value);
|
|
94
|
-
if (i && _arr.length === i) break;
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
_d = true;
|
|
98
|
-
_e = err;
|
|
99
|
-
} finally{
|
|
100
|
-
try {
|
|
101
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
102
|
-
} finally{
|
|
103
|
-
if (_d) throw _e;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return _arr;
|
|
107
|
-
}
|
|
108
|
-
function _non_iterable_rest() {
|
|
109
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
110
|
-
}
|
|
111
81
|
function _non_iterable_spread() {
|
|
112
82
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
113
83
|
}
|
|
@@ -150,9 +120,6 @@ function _object_spread_props(target, source) {
|
|
|
150
120
|
}
|
|
151
121
|
return target;
|
|
152
122
|
}
|
|
153
|
-
function _sliced_to_array(arr, i) {
|
|
154
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
155
|
-
}
|
|
156
123
|
function _to_consumable_array(arr) {
|
|
157
124
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
158
125
|
}
|
|
@@ -261,34 +228,48 @@ function _ts_generator(thisArg, body) {
|
|
|
261
228
|
}
|
|
262
229
|
import hoistNonReactStatic from "hoist-non-react-statics";
|
|
263
230
|
// src/Register.tsx
|
|
264
|
-
import { memo, Fragment,
|
|
231
|
+
import { memo, Fragment, useRef, useCallback } from "react";
|
|
232
|
+
import { useUpdate, useUnmount } from "react-use";
|
|
265
233
|
import { Helmet } from "react-helmet";
|
|
266
234
|
import queryString from "query-string";
|
|
267
235
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
268
236
|
var createRegisterComponent = function(config, getContext, WrappedComponent) {
|
|
269
237
|
var RegisterComponent = memo(function(props) {
|
|
270
238
|
var context = getContext();
|
|
271
|
-
var isPreload =
|
|
239
|
+
var _getContext = getContext(), isPreload = _getContext.isPreload, error = _getContext.error;
|
|
272
240
|
var name = config.name, ErrorFullback = config.ErrorFullback, LoadFullback = config.LoadFullback, renderTitle = config.renderTitle, getQuery = config.getQuery;
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
var
|
|
282
|
-
var _useState1 = _sliced_to_array(useState(), 2), loadError = _useState1[0], setLoadError = _useState1[1];
|
|
283
|
-
var isLeave = false;
|
|
241
|
+
var forceUpdate = useUpdate();
|
|
242
|
+
var registerStateRef = useRef({
|
|
243
|
+
isPreload: !!isPreload,
|
|
244
|
+
isLeaved: false,
|
|
245
|
+
hasError: !!error,
|
|
246
|
+
loading: !isPreload
|
|
247
|
+
});
|
|
248
|
+
var showError = registerStateRef.current.hasError && ErrorFullback;
|
|
249
|
+
var showLoading = registerStateRef.current.loading && LoadFullback;
|
|
284
250
|
var emitLoad = useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
285
|
-
var _WrappedComponent_emitOnLoad,
|
|
251
|
+
var _WrappedComponent_emitOnLoad, _registerStateRef_current, hasError, isPreload2, isLeaved, queryFromContext, isParsed, query, _ref, error2, needUpdate;
|
|
286
252
|
return _ts_generator(this, function(_state) {
|
|
287
253
|
switch(_state.label){
|
|
288
254
|
case 0:
|
|
289
|
-
|
|
255
|
+
_registerStateRef_current = registerStateRef.current, hasError = _registerStateRef_current.hasError, isPreload2 = _registerStateRef_current.isPreload, isLeaved = _registerStateRef_current.isLeaved;
|
|
256
|
+
if (hasError) {
|
|
257
|
+
registerStateRef.current.hasError = false;
|
|
258
|
+
delete getContext().error;
|
|
259
|
+
}
|
|
260
|
+
if (isPreload2) {
|
|
261
|
+
registerStateRef.current.isPreload = false;
|
|
262
|
+
delete getContext().isPreload;
|
|
263
|
+
}
|
|
264
|
+
if (hasError || isPreload2 || isLeaved) return [
|
|
290
265
|
2
|
|
291
266
|
];
|
|
267
|
+
queryFromContext = (getQuery === null || getQuery === void 0 ? void 0 : getQuery(context)) || "";
|
|
268
|
+
isParsed = typeof queryFromContext === "object";
|
|
269
|
+
query = isParsed ? queryFromContext : queryString.parse(queryFromContext, {
|
|
270
|
+
parseBooleans: true,
|
|
271
|
+
parseNumbers: true
|
|
272
|
+
});
|
|
292
273
|
return [
|
|
293
274
|
4,
|
|
294
275
|
(_WrappedComponent_emitOnLoad = WrappedComponent.emitOnLoad) === null || _WrappedComponent_emitOnLoad === void 0 ? void 0 : _WrappedComponent_emitOnLoad.call(WrappedComponent, {
|
|
@@ -296,35 +277,29 @@ var createRegisterComponent = function(config, getContext, WrappedComponent) {
|
|
|
296
277
|
})
|
|
297
278
|
];
|
|
298
279
|
case 1:
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
280
|
+
_ref = _state.sent() || {}, error2 = _ref.error;
|
|
281
|
+
if (error2) registerStateRef.current.hasError = true;
|
|
282
|
+
needUpdate = false;
|
|
283
|
+
if (registerStateRef.current.hasError && ErrorFullback) needUpdate = true;
|
|
284
|
+
if (registerStateRef.current.loading && LoadFullback) needUpdate = true;
|
|
285
|
+
if (needUpdate) forceUpdate();
|
|
305
286
|
return [
|
|
306
287
|
2
|
|
307
288
|
];
|
|
308
289
|
}
|
|
309
290
|
});
|
|
310
|
-
}), [
|
|
311
|
-
needLoad,
|
|
312
|
-
loadError
|
|
313
|
-
]);
|
|
291
|
+
}), []);
|
|
314
292
|
void emitLoad();
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
(_WrappedComponent_emitOnLeave = WrappedComponent.emitOnLeave) === null || _WrappedComponent_emitOnLeave === void 0 ? void 0 : _WrappedComponent_emitOnLeave.call(WrappedComponent);
|
|
321
|
-
};
|
|
322
|
-
}, []);
|
|
293
|
+
useUnmount(function() {
|
|
294
|
+
var _WrappedComponent_emitOnLeave;
|
|
295
|
+
registerStateRef.current.isLeaved = true;
|
|
296
|
+
(_WrappedComponent_emitOnLeave = WrappedComponent.emitOnLeave) === null || _WrappedComponent_emitOnLeave === void 0 ? void 0 : _WrappedComponent_emitOnLeave.call(WrappedComponent);
|
|
297
|
+
});
|
|
323
298
|
var content = /* @__PURE__ */ jsx(WrappedComponent, _object_spread_props(_object_spread({}, props), {
|
|
324
299
|
context: context
|
|
325
300
|
}));
|
|
326
|
-
if (
|
|
327
|
-
if (
|
|
301
|
+
if (showError) content = /* @__PURE__ */ jsx(ErrorFullback, {});
|
|
302
|
+
if (showLoading) content = /* @__PURE__ */ jsx(LoadFullback, {});
|
|
328
303
|
return /* @__PURE__ */ jsxs(Fragment, {
|
|
329
304
|
children: [
|
|
330
305
|
renderTitle && name && /* @__PURE__ */ jsx(Helmet, {
|
|
@@ -460,7 +435,7 @@ var createRegister = function(options) {
|
|
|
460
435
|
];
|
|
461
436
|
case 12:
|
|
462
437
|
e = _state.sent();
|
|
463
|
-
context.error = _instanceof(e, Error) ? e : new Error("register onLoad error");
|
|
438
|
+
context.error = _instanceof(e, Error) ? e : new Error(String(e) || "register onLoad error");
|
|
464
439
|
onError ? onError(e) : console.error(e);
|
|
465
440
|
return [
|
|
466
441
|
3,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-register",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"hoist-non-react-statics": "^3.3.2",
|
|
24
24
|
"query-string": "^7.1.3",
|
|
25
|
-
"react-helmet": "^6.1.0"
|
|
25
|
+
"react-helmet": "^6.1.0",
|
|
26
|
+
"react-use": "^17.6.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/hoist-non-react-statics": "^3.3.5",
|