@xfe-repo/web-register 1.3.2 → 1.3.4

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.
@@ -0,0 +1,63 @@
1
+ import { ComponentType } from 'react';
2
+
3
+ declare class ContextStorageClass<ExtendContext = null> implements ContextStorage<ExtendContext> {
4
+ constructor(context: RegisterContext<ExtendContext>);
5
+ private storage;
6
+ get context(): RegisterContext<ExtendContext>;
7
+ }
8
+
9
+ declare const createRegister: <ExtendConfig = null, ExtendContext = null, P = any>(options?: CreateOptions<ExtendConfig, ExtendContext, P>) => Register<ExtendConfig, ExtendContext, P>;
10
+ declare const register: Register<null, null, any>;
11
+
12
+ type CreateOptions<ExtendConfig = null, ExtendContext = null, P = any> = {
13
+ plugins?: RegisterPlugin<ExtendConfig, ExtendContext>[];
14
+ onError?: Function;
15
+ LoadFullback?: ComponentType<any> | null;
16
+ ErrorFullback?: ComponentType<any> | null;
17
+ renderTitle?: (name: string, context: RegisterContext<ExtendContext, P>) => string;
18
+ getQuery?: (context: RegisterContext<ExtendContext, P>) => string | Partial<Record<string, string>>;
19
+ };
20
+ type ORegisterConfig = {
21
+ name?: string;
22
+ onLoad?: (context: RegisterContext) => Promise<any>;
23
+ onLeave?: (context: ORegisterContext) => Promise<boolean>;
24
+ };
25
+ type ORegisterContext<P = {}, Q = {}, R = {}> = {
26
+ payload: Readonly<P>;
27
+ query: Q;
28
+ result?: R;
29
+ error?: Error;
30
+ isPreload?: boolean;
31
+ };
32
+ type RegisterConfig<ExtendConfig = null> = ExtendConfig extends null ? ORegisterConfig & CreateOptions : ORegisterConfig & CreateOptions & ExtendConfig;
33
+ type RegisterContext<ExtendContext = null, P = any, Q = any, R = any> = ExtendContext extends null ? ORegisterContext<P, Q, R> : ORegisterContext<P, Q, R> & ExtendContext;
34
+ type LoadParams<Q = any> = {
35
+ isPreload?: boolean;
36
+ query: Q;
37
+ };
38
+ type RegisterComponentStatic<ExtendContext = null, P = any> = {
39
+ config?: RegisterConfig;
40
+ emitOnLoad?: <Q, R>(params?: LoadParams<Q>) => Promise<RegisterContext<ExtendContext, P, Q, R>>;
41
+ emitOnLeave?: () => Promise<boolean>;
42
+ };
43
+ type RegisterComponentType<P = any> = ComponentType<P> & RegisterComponentStatic;
44
+ type RegisterPlugin<ExtendConfig = null, ExtendContext = null> = {
45
+ registerHook?: (config: RegisterConfig<ExtendConfig>, WrappedComponent: RegisterComponentType) => ComponentType<any> | void;
46
+ loadHook?: (config: RegisterConfig<ExtendConfig>, context: RegisterContext<ExtendContext>) => Promise<any>;
47
+ leaveHook?: (config: RegisterConfig<ExtendConfig>, context: RegisterContext<ExtendContext>) => Promise<boolean>;
48
+ };
49
+ type ContextStorage<ExtendContext = null, P = any, Q = any, R = any> = {
50
+ context: RegisterContext<ExtendContext, P, Q, R>;
51
+ };
52
+ type SetContextStorage<ExtendContext = null, P = any> = <Q = any, R = any>(contextStorage: ContextStorage<ExtendContext, P, Q, R>) => void;
53
+ type GetContext<ExtendContext = null, P = any> = <Q = any, R = any>() => RegisterContext<ExtendContext, P, Q, R>;
54
+ interface Register<ExtendConfig = null, ExtendContext = null, P = any> {
55
+ (config: RegisterConfig<ExtendConfig>): (WrappedComponent: any) => any;
56
+ setContextStorage: SetContextStorage<ExtendContext, P>;
57
+ getContext: GetContext<ExtendContext, P>;
58
+ }
59
+ type WithRegisterContext<ExtendContext = null, P = any, Q = any, R = any> = {
60
+ context: RegisterContext<ExtendContext, P, Q, R>;
61
+ };
62
+
63
+ export { type ContextStorage, ContextStorageClass, type CreateOptions, type GetContext, type LoadParams, type ORegisterConfig, type ORegisterContext, type Register, type RegisterComponentStatic, type RegisterComponentType, type RegisterConfig, type RegisterContext, type RegisterPlugin, type SetContextStorage, type WithRegisterContext, createRegister, register as default };
package/dist/index.js CHANGED
@@ -441,9 +441,7 @@ var createRegister = function(options) {
441
441
  case 0:
442
442
  onLoad = config.onLoad, onError = config.onError, _config_plugins = config.plugins, plugins = _config_plugins === void 0 ? [] : _config_plugins;
443
443
  context = getContext();
444
- if (params === null || params === void 0 ? void 0 : params.isPreload) {
445
- context.isPreload = true;
446
- }
444
+ if (params === null || params === void 0 ? void 0 : params.isPreload) context.isPreload = true;
447
445
  context.query = (params === null || params === void 0 ? void 0 : params.query) || {};
448
446
  delete context.error;
449
447
  finalResult = {};
package/dist/index.mjs ADDED
@@ -0,0 +1,606 @@
1
+ // src/index.ts
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _array_without_holes(arr) {
11
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
12
+ }
13
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
+ try {
15
+ var info = gen[key](arg);
16
+ var value = info.value;
17
+ } catch (error) {
18
+ reject(error);
19
+ return;
20
+ }
21
+ if (info.done) {
22
+ resolve(value);
23
+ } else {
24
+ Promise.resolve(value).then(_next, _throw);
25
+ }
26
+ }
27
+ function _async_to_generator(fn) {
28
+ return function() {
29
+ var self = this, args = arguments;
30
+ return new Promise(function(resolve, reject) {
31
+ var gen = fn.apply(self, args);
32
+ function _next(value) {
33
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
34
+ }
35
+ function _throw(err) {
36
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
37
+ }
38
+ _next(undefined);
39
+ });
40
+ };
41
+ }
42
+ function _class_call_check(instance, Constructor) {
43
+ if (!(instance instanceof Constructor)) {
44
+ throw new TypeError("Cannot call a class as a function");
45
+ }
46
+ }
47
+ function _defineProperties(target, props) {
48
+ for(var i = 0; i < props.length; i++){
49
+ var descriptor = props[i];
50
+ descriptor.enumerable = descriptor.enumerable || false;
51
+ descriptor.configurable = true;
52
+ if ("value" in descriptor) descriptor.writable = true;
53
+ Object.defineProperty(target, descriptor.key, descriptor);
54
+ }
55
+ }
56
+ function _create_class(Constructor, protoProps, staticProps) {
57
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
58
+ if (staticProps) _defineProperties(Constructor, staticProps);
59
+ return Constructor;
60
+ }
61
+ function _define_property(obj, key, value) {
62
+ if (key in obj) {
63
+ Object.defineProperty(obj, key, {
64
+ value: value,
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true
68
+ });
69
+ } else {
70
+ obj[key] = value;
71
+ }
72
+ return obj;
73
+ }
74
+ function _instanceof(left, right) {
75
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
76
+ return !!right[Symbol.hasInstance](left);
77
+ } else {
78
+ return left instanceof right;
79
+ }
80
+ }
81
+ function _iterable_to_array(iter) {
82
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
83
+ }
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
+ function _non_iterable_spread() {
112
+ 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
+ }
114
+ function _object_spread(target) {
115
+ for(var i = 1; i < arguments.length; i++){
116
+ var source = arguments[i] != null ? arguments[i] : {};
117
+ var ownKeys = Object.keys(source);
118
+ if (typeof Object.getOwnPropertySymbols === "function") {
119
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
120
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
121
+ }));
122
+ }
123
+ ownKeys.forEach(function(key) {
124
+ _define_property(target, key, source[key]);
125
+ });
126
+ }
127
+ return target;
128
+ }
129
+ function ownKeys(object, enumerableOnly) {
130
+ var keys = Object.keys(object);
131
+ if (Object.getOwnPropertySymbols) {
132
+ var symbols = Object.getOwnPropertySymbols(object);
133
+ if (enumerableOnly) {
134
+ symbols = symbols.filter(function(sym) {
135
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
136
+ });
137
+ }
138
+ keys.push.apply(keys, symbols);
139
+ }
140
+ return keys;
141
+ }
142
+ function _object_spread_props(target, source) {
143
+ source = source != null ? source : {};
144
+ if (Object.getOwnPropertyDescriptors) {
145
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
146
+ } else {
147
+ ownKeys(Object(source)).forEach(function(key) {
148
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
149
+ });
150
+ }
151
+ return target;
152
+ }
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
+ function _to_consumable_array(arr) {
157
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
158
+ }
159
+ function _unsupported_iterable_to_array(o, minLen) {
160
+ if (!o) return;
161
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
162
+ var n = Object.prototype.toString.call(o).slice(8, -1);
163
+ if (n === "Object" && o.constructor) n = o.constructor.name;
164
+ if (n === "Map" || n === "Set") return Array.from(n);
165
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
166
+ }
167
+ function _ts_generator(thisArg, body) {
168
+ var f, y, t, g, _ = {
169
+ label: 0,
170
+ sent: function() {
171
+ if (t[0] & 1) throw t[1];
172
+ return t[1];
173
+ },
174
+ trys: [],
175
+ ops: []
176
+ };
177
+ return g = {
178
+ next: verb(0),
179
+ "throw": verb(1),
180
+ "return": verb(2)
181
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
182
+ return this;
183
+ }), g;
184
+ function verb(n) {
185
+ return function(v) {
186
+ return step([
187
+ n,
188
+ v
189
+ ]);
190
+ };
191
+ }
192
+ function step(op) {
193
+ if (f) throw new TypeError("Generator is already executing.");
194
+ while(_)try {
195
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
196
+ if (y = 0, t) op = [
197
+ op[0] & 2,
198
+ t.value
199
+ ];
200
+ switch(op[0]){
201
+ case 0:
202
+ case 1:
203
+ t = op;
204
+ break;
205
+ case 4:
206
+ _.label++;
207
+ return {
208
+ value: op[1],
209
+ done: false
210
+ };
211
+ case 5:
212
+ _.label++;
213
+ y = op[1];
214
+ op = [
215
+ 0
216
+ ];
217
+ continue;
218
+ case 7:
219
+ op = _.ops.pop();
220
+ _.trys.pop();
221
+ continue;
222
+ default:
223
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
224
+ _ = 0;
225
+ continue;
226
+ }
227
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
228
+ _.label = op[1];
229
+ break;
230
+ }
231
+ if (op[0] === 6 && _.label < t[1]) {
232
+ _.label = t[1];
233
+ t = op;
234
+ break;
235
+ }
236
+ if (t && _.label < t[2]) {
237
+ _.label = t[2];
238
+ _.ops.push(op);
239
+ break;
240
+ }
241
+ if (t[2]) _.ops.pop();
242
+ _.trys.pop();
243
+ continue;
244
+ }
245
+ op = body.call(thisArg, _);
246
+ } catch (e) {
247
+ op = [
248
+ 6,
249
+ e
250
+ ];
251
+ y = 0;
252
+ } finally{
253
+ f = t = 0;
254
+ }
255
+ if (op[0] & 5) throw op[1];
256
+ return {
257
+ value: op[0] ? op[1] : void 0,
258
+ done: true
259
+ };
260
+ }
261
+ }
262
+ import hoistNonReactStatic from "hoist-non-react-statics";
263
+ // src/Register.tsx
264
+ import { memo, Fragment, useEffect, useState, useCallback, useMemo } from "react";
265
+ import { Helmet } from "react-helmet";
266
+ import queryString from "query-string";
267
+ import { jsx, jsxs } from "react/jsx-runtime";
268
+ var createRegisterComponent = function(config, getContext, WrappedComponent) {
269
+ var RegisterComponent = memo(function(props) {
270
+ var context = getContext();
271
+ var isPreload = context.isPreload;
272
+ var name = config.name, ErrorFullback = config.ErrorFullback, LoadFullback = config.LoadFullback, renderTitle = config.renderTitle, getQuery = config.getQuery;
273
+ var query = useMemo(function() {
274
+ var query2 = (getQuery === null || getQuery === void 0 ? void 0 : getQuery(context)) || "";
275
+ var isParsed = typeof query2 === "object";
276
+ return isParsed ? query2 : queryString.parse(query2, {
277
+ parseBooleans: true,
278
+ parseNumbers: true
279
+ });
280
+ }, []);
281
+ var _useState = _sliced_to_array(useState(!isPreload), 2), needLoad = _useState[0], setNeedLoad = _useState[1];
282
+ var _useState1 = _sliced_to_array(useState(), 2), loadError = _useState1[0], setLoadError = _useState1[1];
283
+ var isLeave = false;
284
+ var emitLoad = useCallback(/*#__PURE__*/ _async_to_generator(function() {
285
+ var _WrappedComponent_emitOnLoad, error;
286
+ return _ts_generator(this, function(_state) {
287
+ switch(_state.label){
288
+ case 0:
289
+ if (!needLoad || loadError) return [
290
+ 2
291
+ ];
292
+ return [
293
+ 4,
294
+ (_WrappedComponent_emitOnLoad = WrappedComponent.emitOnLoad) === null || _WrappedComponent_emitOnLoad === void 0 ? void 0 : _WrappedComponent_emitOnLoad.call(WrappedComponent, {
295
+ query: query
296
+ })
297
+ ];
298
+ case 1:
299
+ error = (_state.sent() || {}).error;
300
+ if (isLeave) return [
301
+ 2
302
+ ];
303
+ ErrorFullback && setLoadError(error);
304
+ LoadFullback && setNeedLoad(false);
305
+ return [
306
+ 2
307
+ ];
308
+ }
309
+ });
310
+ }), [
311
+ needLoad,
312
+ loadError
313
+ ]);
314
+ void emitLoad();
315
+ if (isPreload) delete context.isPreload;
316
+ useEffect(function() {
317
+ return function() {
318
+ var _WrappedComponent_emitOnLeave;
319
+ isLeave = true;
320
+ (_WrappedComponent_emitOnLeave = WrappedComponent.emitOnLeave) === null || _WrappedComponent_emitOnLeave === void 0 ? void 0 : _WrappedComponent_emitOnLeave.call(WrappedComponent);
321
+ };
322
+ }, []);
323
+ var content = /* @__PURE__ */ jsx(WrappedComponent, _object_spread_props(_object_spread({}, props), {
324
+ context: context
325
+ }));
326
+ if (loadError && ErrorFullback) content = /* @__PURE__ */ jsx(ErrorFullback, {});
327
+ if (needLoad && LoadFullback) content = /* @__PURE__ */ jsx(LoadFullback, {});
328
+ return /* @__PURE__ */ jsxs(Fragment, {
329
+ children: [
330
+ renderTitle && name && /* @__PURE__ */ jsx(Helmet, {
331
+ title: renderTitle(name, context)
332
+ }),
333
+ content
334
+ ]
335
+ });
336
+ });
337
+ var componentName = WrappedComponent.displayName || WrappedComponent.name || "Component";
338
+ RegisterComponent.displayName = "Register(".concat(componentName, ")");
339
+ return RegisterComponent;
340
+ };
341
+ // src/storage/client.ts
342
+ var ContextStorageClass = /*#__PURE__*/ function() {
343
+ "use strict";
344
+ function ContextStorageClass(context) {
345
+ _class_call_check(this, ContextStorageClass);
346
+ this.storage = {
347
+ context: context
348
+ };
349
+ }
350
+ _create_class(ContextStorageClass, [
351
+ {
352
+ key: "context",
353
+ get: function get() {
354
+ var context = this.storage.context;
355
+ if (!context) throw new Error("Can not find context in ContextStorage");
356
+ return this.storage.context;
357
+ }
358
+ }
359
+ ]);
360
+ return ContextStorageClass;
361
+ }();
362
+ // src/index.ts
363
+ var createRegister = function(options) {
364
+ var _contextStorage;
365
+ var _emitOnLoad = function() {
366
+ var _ref = _async_to_generator(function(config, getContext, params) {
367
+ var onLoad, onError, _config_plugins, plugins, context, finalResult, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, loadHook, result, err, result1, e;
368
+ return _ts_generator(this, function(_state) {
369
+ switch(_state.label){
370
+ case 0:
371
+ onLoad = config.onLoad, onError = config.onError, _config_plugins = config.plugins, plugins = _config_plugins === void 0 ? [] : _config_plugins;
372
+ context = getContext();
373
+ if (params === null || params === void 0 ? void 0 : params.isPreload) context.isPreload = true;
374
+ context.query = (params === null || params === void 0 ? void 0 : params.query) || {};
375
+ delete context.error;
376
+ finalResult = {};
377
+ _state.label = 1;
378
+ case 1:
379
+ _state.trys.push([
380
+ 1,
381
+ 12,
382
+ ,
383
+ 13
384
+ ]);
385
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
386
+ _state.label = 2;
387
+ case 2:
388
+ _state.trys.push([
389
+ 2,
390
+ 7,
391
+ 8,
392
+ 9
393
+ ]);
394
+ _iterator = plugins[Symbol.iterator]();
395
+ _state.label = 3;
396
+ case 3:
397
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
398
+ 3,
399
+ 6
400
+ ];
401
+ loadHook = _step.value.loadHook;
402
+ return [
403
+ 4,
404
+ loadHook === null || loadHook === void 0 ? void 0 : loadHook(config, context)
405
+ ];
406
+ case 4:
407
+ result = _state.sent();
408
+ finalResult = _object_spread({}, finalResult, result);
409
+ _state.label = 5;
410
+ case 5:
411
+ _iteratorNormalCompletion = true;
412
+ return [
413
+ 3,
414
+ 3
415
+ ];
416
+ case 6:
417
+ return [
418
+ 3,
419
+ 9
420
+ ];
421
+ case 7:
422
+ err = _state.sent();
423
+ _didIteratorError = true;
424
+ _iteratorError = err;
425
+ return [
426
+ 3,
427
+ 9
428
+ ];
429
+ case 8:
430
+ try {
431
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
432
+ _iterator.return();
433
+ }
434
+ } finally{
435
+ if (_didIteratorError) {
436
+ throw _iteratorError;
437
+ }
438
+ }
439
+ return [
440
+ 7
441
+ ];
442
+ case 9:
443
+ if (!onLoad) return [
444
+ 3,
445
+ 11
446
+ ];
447
+ return [
448
+ 4,
449
+ onLoad(context)
450
+ ];
451
+ case 10:
452
+ result1 = _state.sent();
453
+ finalResult = _object_spread({}, finalResult, result1);
454
+ _state.label = 11;
455
+ case 11:
456
+ context.result = finalResult;
457
+ return [
458
+ 3,
459
+ 13
460
+ ];
461
+ case 12:
462
+ e = _state.sent();
463
+ context.error = _instanceof(e, Error) ? e : new Error("register onLoad error");
464
+ onError ? onError(e) : console.error(e);
465
+ return [
466
+ 3,
467
+ 13
468
+ ];
469
+ case 13:
470
+ return [
471
+ 2,
472
+ context
473
+ ];
474
+ }
475
+ });
476
+ });
477
+ return function _emitOnLoad(config, getContext, params) {
478
+ return _ref.apply(this, arguments);
479
+ };
480
+ }();
481
+ var _emitOnLeave = function() {
482
+ var _ref = _async_to_generator(function(config, getContext) {
483
+ var onLeave, onError, _config_plugins, plugins, context, canLeave, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, leaveHook, e;
484
+ return _ts_generator(this, function(_state) {
485
+ switch(_state.label){
486
+ case 0:
487
+ onLeave = config.onLeave, onError = config.onError, _config_plugins = config.plugins, plugins = _config_plugins === void 0 ? [] : _config_plugins;
488
+ context = getContext();
489
+ canLeave = true;
490
+ _state.label = 1;
491
+ case 1:
492
+ _state.trys.push([
493
+ 1,
494
+ 4,
495
+ ,
496
+ 5
497
+ ]);
498
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
499
+ try {
500
+ for(_iterator = plugins[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
501
+ leaveHook = _step.value.leaveHook;
502
+ canLeave = !!(leaveHook === null || leaveHook === void 0 ? void 0 : leaveHook(config, context));
503
+ }
504
+ } catch (err) {
505
+ _didIteratorError = true;
506
+ _iteratorError = err;
507
+ } finally{
508
+ try {
509
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
510
+ _iterator.return();
511
+ }
512
+ } finally{
513
+ if (_didIteratorError) {
514
+ throw _iteratorError;
515
+ }
516
+ }
517
+ }
518
+ if (!onLeave) return [
519
+ 3,
520
+ 3
521
+ ];
522
+ return [
523
+ 4,
524
+ onLeave(context)
525
+ ];
526
+ case 2:
527
+ canLeave = _state.sent();
528
+ _state.label = 3;
529
+ case 3:
530
+ return [
531
+ 3,
532
+ 5
533
+ ];
534
+ case 4:
535
+ e = _state.sent();
536
+ onError ? onError(e) : console.error(e);
537
+ return [
538
+ 3,
539
+ 5
540
+ ];
541
+ case 5:
542
+ return [
543
+ 2,
544
+ canLeave
545
+ ];
546
+ }
547
+ });
548
+ });
549
+ return function _emitOnLeave(config, getContext) {
550
+ return _ref.apply(this, arguments);
551
+ };
552
+ }();
553
+ var register2 = function(config) {
554
+ return function(WrappedComponent) {
555
+ var finalPlugin = _to_consumable_array((options === null || options === void 0 ? void 0 : options.plugins) || []).concat(_to_consumable_array((config === null || config === void 0 ? void 0 : config.plugins) || []));
556
+ config = _object_spread_props(_object_spread({}, options, config), {
557
+ plugins: finalPlugin
558
+ });
559
+ var TempRegisterComponent = WrappedComponent;
560
+ TempRegisterComponent.config = config;
561
+ TempRegisterComponent.emitOnLoad = function(params) {
562
+ return _emitOnLoad(config, register2.getContext, params);
563
+ };
564
+ TempRegisterComponent.emitOnLeave = function() {
565
+ return _emitOnLeave(config, register2.getContext);
566
+ };
567
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
568
+ try {
569
+ for(var _iterator = finalPlugin[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
570
+ var registerHook = _step.value.registerHook;
571
+ if (!registerHook) continue;
572
+ var ExtendWrappedComponent = registerHook(config, TempRegisterComponent);
573
+ if (!ExtendWrappedComponent) continue;
574
+ hoistNonReactStatic(ExtendWrappedComponent, TempRegisterComponent);
575
+ TempRegisterComponent = ExtendWrappedComponent;
576
+ }
577
+ } catch (err) {
578
+ _didIteratorError = true;
579
+ _iteratorError = err;
580
+ } finally{
581
+ try {
582
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
583
+ _iterator.return();
584
+ }
585
+ } finally{
586
+ if (_didIteratorError) {
587
+ throw _iteratorError;
588
+ }
589
+ }
590
+ }
591
+ var FinalRegisterComponent = createRegisterComponent(config, register2.getContext, TempRegisterComponent);
592
+ hoistNonReactStatic(FinalRegisterComponent, TempRegisterComponent);
593
+ return FinalRegisterComponent;
594
+ };
595
+ };
596
+ register2.setContextStorage = function(contextStorage) {
597
+ _contextStorage = contextStorage;
598
+ };
599
+ register2.getContext = function() {
600
+ return _contextStorage.context;
601
+ };
602
+ return register2;
603
+ };
604
+ var register = createRegister();
605
+ var src_default = register;
606
+ export { ContextStorageClass, createRegister, src_default as default };
package/package.json CHANGED
@@ -1,9 +1,21 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-register",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "sideEffects": false,
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ }
18
+ },
7
19
  "files": [
8
20
  "dist"
9
21
  ],