swico 0.9.0-beta → 0.9.0-beta2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "0.9.0-beta",
3
+ "version": "0.9.0-beta2",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -87,12 +87,13 @@ var getPathNameList = function (routes) {
87
87
  };
88
88
  exports.pathNameList = getPathNameList(routes_1.default);
89
89
  var getLocation = function (originalHistory) {
90
- var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
90
+ var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search, _b = _a.state, state = _b === void 0 ? {} : _b;
91
91
  var routerBaseLength = formatRouterBase.length;
92
92
  var path = pathname.slice(routerBaseLength);
93
93
  var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
94
94
  var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
95
95
  return {
96
+ state: state,
96
97
  hash: hash,
97
98
  search: search,
98
99
  pathname: pathname,
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -11,7 +22,7 @@ var useLocation = function () {
11
22
  var _a, _b;
12
23
  var location = (0, react_router_dom_1.useLocation)();
13
24
  var params = (0, react_router_dom_1.useParams)();
14
- var search = location.search, hash = location.hash, pathname = location.pathname;
25
+ var search = location.search, hash = location.hash, pathname = location.pathname, _c = location.state, state = _c === void 0 ? {} : _c;
15
26
  var name = (_a = history_1.pathNameList.find(function (item) {
16
27
  return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
17
28
  item.path === pathname;
@@ -19,6 +30,7 @@ var useLocation = function () {
19
30
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
20
31
  return {
21
32
  name: name,
33
+ state: state,
22
34
  path: pathname,
23
35
  pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
24
36
  search: '',
@@ -49,7 +61,7 @@ var useNav = function () {
49
61
  navigate(to);
50
62
  break;
51
63
  case 'object':
52
- navigate(getFormatNavPath(to), options);
64
+ navigate(getFormatNavPath(to), __assign(__assign({}, (options || {})), { state: to.state }));
53
65
  break;
54
66
  default:
55
67
  throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
@@ -36,9 +36,10 @@ var getRouter = function () {
36
36
  back: router.back,
37
37
  forward: router.forward,
38
38
  get location() {
39
+ var _a;
39
40
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
40
41
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
41
- var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
42
+ var _b = router.currentRoute.value, path = _b.path, params = _b.params, query = _b.query, name = _b.name, hash = _b.hash, fullPath = _b.fullPath;
42
43
  return {
43
44
  path: path,
44
45
  pathname: formatRouterBase + path,
@@ -46,6 +47,7 @@ var getRouter = function () {
46
47
  query: query,
47
48
  name: name,
48
49
  hash: hash,
50
+ state: (_a = window.history.state) !== null && _a !== void 0 ? _a : {},
49
51
  search: query ? qs_1.default.stringify(query) : ''
50
52
  };
51
53
  }
@@ -19,6 +19,7 @@ var useLocation = function () {
19
19
  name: '',
20
20
  path: '',
21
21
  search: '',
22
+ state: {},
22
23
  hash: '',
23
24
  pathname: '',
24
25
  params: {},
@@ -34,6 +35,7 @@ var useLocation = function () {
34
35
  location.query = query;
35
36
  location.hash = hash;
36
37
  location.params = params;
38
+ location.state = window.history.state || {};
37
39
  });
38
40
  return location;
39
41
  };
@@ -6,6 +6,7 @@ export type SwicoLocationType = {
6
6
  path: string;
7
7
  pathname: string;
8
8
  search: string;
9
+ state?: Record<string, any>;
9
10
  };
10
11
  export type SwicoHistoryOptionType = {
11
12
  query?: Record<string, any>;