@xfe-repo/web-micro 1.2.3 → 1.2.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.
package/dist/index.d.mts CHANGED
@@ -21,6 +21,11 @@ type MicroAppLinkProps = LinkProps & {
21
21
  microApp?: string;
22
22
  };
23
23
  declare const MicroAppLink: React.MemoExoticComponent<(props: MicroAppLinkProps) => react_jsx_runtime.JSX.Element>;
24
+ type NavigateToWithMicroAppOptions = {
25
+ replace?: boolean;
26
+ state?: any;
27
+ };
28
+ declare const navigateToWithMicroApp: (to: string, options?: NavigateToWithMicroAppOptions) => void;
24
29
 
25
30
  declare enum MicroAppEventEnum {
26
31
  DISPATCH_ACTION = "dispatchAction"
@@ -58,4 +63,4 @@ declare class MicroAppEventCenter {
58
63
 
59
64
  declare const microApp: _micro_zoe_micro_app.MicroApp;
60
65
 
61
- export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, MicroAppLink, type MicroAppProps, MicroAppRoute, microApp };
66
+ export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, MicroAppLink, type MicroAppProps, MicroAppRoute, type NavigateToWithMicroAppOptions, microApp, navigateToWithMicroApp };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,11 @@ type MicroAppLinkProps = LinkProps & {
21
21
  microApp?: string;
22
22
  };
23
23
  declare const MicroAppLink: React.MemoExoticComponent<(props: MicroAppLinkProps) => react_jsx_runtime.JSX.Element>;
24
+ type NavigateToWithMicroAppOptions = {
25
+ replace?: boolean;
26
+ state?: any;
27
+ };
28
+ declare const navigateToWithMicroApp: (to: string, options?: NavigateToWithMicroAppOptions) => void;
24
29
 
25
30
  declare enum MicroAppEventEnum {
26
31
  DISPATCH_ACTION = "dispatchAction"
@@ -58,4 +63,4 @@ declare class MicroAppEventCenter {
58
63
 
59
64
  declare const microApp: _micro_zoe_micro_app.MicroApp;
60
65
 
61
- export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, MicroAppLink, type MicroAppProps, MicroAppRoute, microApp };
66
+ export { type MicroAppActionMetaType, type MicroAppActionType, type MicroAppDispatchListener, MicroAppEventCenter, type MicroAppEventCenterConfig, MicroAppEventEnum, type MicroAppGlobalDataType, MicroAppLink, type MicroAppProps, MicroAppRoute, type NavigateToWithMicroAppOptions, microApp, navigateToWithMicroApp };
package/dist/index.js CHANGED
@@ -294,12 +294,15 @@ __export(src_exports, {
294
294
  },
295
295
  microApp: function() {
296
296
  return microApp2;
297
+ },
298
+ navigateToWithMicroApp: function() {
299
+ return navigateToWithMicroApp;
297
300
  }
298
301
  });
299
302
  module.exports = __toCommonJS(src_exports);
300
- var import_micro_app2 = __toESM(require("@micro-zoe/micro-app"));
301
303
  var import_env = require("@xfe-repo/web-utils/env");
302
304
  var import_tools = require("@xfe-repo/web-utils/tools");
305
+ var import_micro_app2 = __toESM(require("@micro-zoe/micro-app"));
303
306
  __reExport(src_exports, require("@micro-zoe/micro-app"), module.exports);
304
307
  // src/MicroAppRoute.tsx
305
308
  var import_react = require("react");
@@ -308,19 +311,13 @@ var import_micro_app = __toESM(require("@micro-zoe/micro-app"));
308
311
  var import_jsx_custom_event = __toESM(require("@micro-zoe/micro-app/polyfill/jsx-custom-event.js"));
309
312
  var MicroAppRoute = (0, import_react.memo)(function(props) {
310
313
  var name = props.name, baseRoute = props.baseRoute, url = props.url, keepAlive = props.keepAlive, className = props.className, data = props.data, loadingFallback = props.loadingFallback, errorFallback = props.errorFallback;
311
- var navigate = (0, import_web_router.useNavigate)();
312
- var location = (0, import_web_router.useLocation)();
313
314
  var _ref = _sliced_to_array((0, import_react.useState)(false), 2), microAppIsShow = _ref[0], setMicroAppIsShow = _ref[1];
314
315
  var _ref1 = _sliced_to_array((0, import_react.useState)(false), 2), microAppIsError = _ref1[0], setMicroAppIsError = _ref1[1];
315
316
  var handleMicroAppMounted = (0, import_react.useCallback)(function() {
316
- var path = location.pathname + location.search;
317
- navigate(path, {
318
- replace: true
319
- });
317
+ var navigator = (0, import_web_router.getClientNavigator)();
318
+ navigator.replace(location.pathname + location.search, history.state);
320
319
  setMicroAppIsShow(true);
321
- }, [
322
- location
323
- ]);
320
+ }, []);
324
321
  var handleMicroAppAfterShow = (0, import_react.useCallback)(function() {
325
322
  var path = location.pathname + location.search;
326
323
  import_micro_app.default.router.push({
@@ -331,9 +328,7 @@ var MicroAppRoute = (0, import_react.memo)(function(props) {
331
328
  return console.error(e);
332
329
  });
333
330
  setMicroAppIsShow(true);
334
- }, [
335
- location
336
- ]);
331
+ }, []);
337
332
  var handleMicroAppError = (0, import_react.useCallback)(function() {
338
333
  setMicroAppIsError(true);
339
334
  }, []);
@@ -361,27 +356,13 @@ var import_react2 = require("react");
361
356
  var import_web_router2 = require("@xfe-repo/web-router");
362
357
  var import_jsx_runtime = require("react/jsx-runtime");
363
358
  var MicroAppLink = (0, import_react2.memo)(function(props) {
364
- var microAppBaseName = props.microApp, to = props.to, children = props.children, replace = props.replace, className = props.className;
365
- var navigate = (0, import_web_router2.useNavigate)();
359
+ var to = props.to, children = props.children, replace = props.replace, className = props.className;
366
360
  var handleLink = (0, import_react2.useCallback)(function(e) {
367
361
  e.preventDefault();
368
- navigate(to, {
362
+ navigateToWithMicroApp(to, {
369
363
  replace: replace
370
364
  });
371
- if (!microAppBaseName) return;
372
- var activeApps = microApp2.getActiveApps({
373
- excludeHiddenApp: true
374
- });
375
- if (activeApps.includes(microAppBaseName)) microApp2.router.push({
376
- name: microAppBaseName,
377
- path: to,
378
- replace: replace
379
- }).catch(function(e2) {
380
- return e2;
381
- });
382
365
  }, [
383
- navigate,
384
- microAppBaseName,
385
366
  to,
386
367
  replace
387
368
  ]);
@@ -392,6 +373,24 @@ var MicroAppLink = (0, import_react2.memo)(function(props) {
392
373
  children: children
393
374
  });
394
375
  });
376
+ var navigateToWithMicroApp = function(to, options) {
377
+ var _ref = options || {}, replace = _ref.replace, state = _ref.state;
378
+ var navigator = (0, import_web_router2.getClientNavigator)();
379
+ replace ? navigator.replace(to, state) : navigator.push(to, state);
380
+ var microAppBaseName = to.split("/")[1];
381
+ if (!microAppBaseName) return;
382
+ var activeApps = microApp2.getActiveApps({
383
+ excludeHiddenApp: true
384
+ });
385
+ if (activeApps.includes(microAppBaseName)) microApp2.router.push({
386
+ name: microAppBaseName,
387
+ path: to,
388
+ replace: replace,
389
+ state: state
390
+ }).catch(function(e) {
391
+ return e;
392
+ });
393
+ };
395
394
  // src/index.ts
396
395
  var MicroAppEventEnum = /* @__PURE__ */ function(MicroAppEventEnum2) {
397
396
  MicroAppEventEnum2["DISPATCH_ACTION"] = "dispatchAction";
@@ -577,5 +576,6 @@ var microApp2 = import_micro_app2.default;
577
576
  MicroAppEventEnum: MicroAppEventEnum,
578
577
  MicroAppLink: MicroAppLink,
579
578
  MicroAppRoute: MicroAppRoute,
580
- microApp: microApp
579
+ microApp: microApp,
580
+ navigateToWithMicroApp: navigateToWithMicroApp
581
581
  }, require("@micro-zoe/micro-app")));
package/dist/index.mjs CHANGED
@@ -216,30 +216,24 @@ function _ts_generator(thisArg, body) {
216
216
  };
217
217
  }
218
218
  }
219
- import originMicroApp, { EventCenterForMicroApp } from "@micro-zoe/micro-app";
220
219
  import { isProduction } from "@xfe-repo/web-utils/env";
221
220
  import { uuid } from "@xfe-repo/web-utils/tools";
221
+ import originMicroApp, { EventCenterForMicroApp } from "@micro-zoe/micro-app";
222
222
  export * from "@micro-zoe/micro-app";
223
223
  // src/MicroAppRoute.tsx
224
224
  import { memo, useCallback, useState } from "react";
225
- import { useNavigate, useLocation } from "@xfe-repo/web-router";
225
+ import { getClientNavigator } from "@xfe-repo/web-router";
226
226
  import microApp from "@micro-zoe/micro-app";
227
227
  import jsxCustomEvent from "@micro-zoe/micro-app/polyfill/jsx-custom-event.js";
228
228
  var MicroAppRoute = memo(function(props) {
229
229
  var name = props.name, baseRoute = props.baseRoute, url = props.url, keepAlive = props.keepAlive, className = props.className, data = props.data, loadingFallback = props.loadingFallback, errorFallback = props.errorFallback;
230
- var navigate = useNavigate();
231
- var location = useLocation();
232
230
  var _useState = _sliced_to_array(useState(false), 2), microAppIsShow = _useState[0], setMicroAppIsShow = _useState[1];
233
231
  var _useState1 = _sliced_to_array(useState(false), 2), microAppIsError = _useState1[0], setMicroAppIsError = _useState1[1];
234
232
  var handleMicroAppMounted = useCallback(function() {
235
- var path = location.pathname + location.search;
236
- navigate(path, {
237
- replace: true
238
- });
233
+ var navigator = getClientNavigator();
234
+ navigator.replace(location.pathname + location.search, history.state);
239
235
  setMicroAppIsShow(true);
240
- }, [
241
- location
242
- ]);
236
+ }, []);
243
237
  var handleMicroAppAfterShow = useCallback(function() {
244
238
  var path = location.pathname + location.search;
245
239
  microApp.router.push({
@@ -250,9 +244,7 @@ var MicroAppRoute = memo(function(props) {
250
244
  return console.error(e);
251
245
  });
252
246
  setMicroAppIsShow(true);
253
- }, [
254
- location
255
- ]);
247
+ }, []);
256
248
  var handleMicroAppError = useCallback(function() {
257
249
  setMicroAppIsError(true);
258
250
  }, []);
@@ -277,30 +269,16 @@ var MicroAppRoute = memo(function(props) {
277
269
  });
278
270
  // src/MicroAppLink.tsx
279
271
  import { memo as memo2, useCallback as useCallback2 } from "react";
280
- import { useNavigate as useNavigate2 } from "@xfe-repo/web-router";
272
+ import { getClientNavigator as getClientNavigator2 } from "@xfe-repo/web-router";
281
273
  import { jsx } from "react/jsx-runtime";
282
274
  var MicroAppLink = memo2(function(props) {
283
- var microAppBaseName = props.microApp, to = props.to, children = props.children, replace = props.replace, className = props.className;
284
- var navigate = useNavigate2();
275
+ var to = props.to, children = props.children, replace = props.replace, className = props.className;
285
276
  var handleLink = useCallback2(function(e) {
286
277
  e.preventDefault();
287
- navigate(to, {
288
- replace: replace
289
- });
290
- if (!microAppBaseName) return;
291
- var activeApps = microApp2.getActiveApps({
292
- excludeHiddenApp: true
293
- });
294
- if (activeApps.includes(microAppBaseName)) microApp2.router.push({
295
- name: microAppBaseName,
296
- path: to,
278
+ navigateToWithMicroApp(to, {
297
279
  replace: replace
298
- }).catch(function(e2) {
299
- return e2;
300
280
  });
301
281
  }, [
302
- navigate,
303
- microAppBaseName,
304
282
  to,
305
283
  replace
306
284
  ]);
@@ -311,6 +289,24 @@ var MicroAppLink = memo2(function(props) {
311
289
  children: children
312
290
  });
313
291
  });
292
+ var navigateToWithMicroApp = function(to, options) {
293
+ var _ref = options || {}, replace = _ref.replace, state = _ref.state;
294
+ var navigator = getClientNavigator2();
295
+ replace ? navigator.replace(to, state) : navigator.push(to, state);
296
+ var microAppBaseName = to.split("/")[1];
297
+ if (!microAppBaseName) return;
298
+ var activeApps = microApp2.getActiveApps({
299
+ excludeHiddenApp: true
300
+ });
301
+ if (activeApps.includes(microAppBaseName)) microApp2.router.push({
302
+ name: microAppBaseName,
303
+ path: to,
304
+ replace: replace,
305
+ state: state
306
+ }).catch(function(e) {
307
+ return e;
308
+ });
309
+ };
314
310
  // src/index.ts
315
311
  var MicroAppEventEnum = /* @__PURE__ */ function(MicroAppEventEnum2) {
316
312
  MicroAppEventEnum2["DISPATCH_ACTION"] = "dispatchAction";
@@ -491,4 +487,4 @@ var MicroAppEventCenter = /*#__PURE__*/ function() {
491
487
  return MicroAppEventCenter;
492
488
  }();
493
489
  var microApp2 = originMicroApp;
494
- export { MicroAppEventCenter, MicroAppEventEnum, MicroAppLink, MicroAppRoute, microApp2 as microApp };
490
+ export { MicroAppEventCenter, MicroAppEventEnum, MicroAppLink, MicroAppRoute, microApp2 as microApp, navigateToWithMicroApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-micro",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "sideEffects": false,
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "devDependencies": {
28
28
  "@types/node": "^20.16.5",
29
29
  "@types/react": "^18",
30
- "@xfe-repo/eslint-config": "0.0.5",
31
- "@xfe-repo/typescript-config": "0.0.6"
30
+ "@xfe-repo/typescript-config": "0.0.6",
31
+ "@xfe-repo/eslint-config": "0.0.5"
32
32
  },
33
33
  "publishConfig": {
34
34
  "registry": "https://registry.npmjs.org/"