swico 0.5.0-beta11 → 0.5.0-beta13

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.5.0-beta11",
3
+ "version": "0.5.0-beta13",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -10,7 +10,7 @@ export declare const Link: FC<{
10
10
  children: ReactNode;
11
11
  }>;
12
12
  export { Outlet } from 'react-router-dom';
13
- export { useLocation } from './template/react/hooks';
13
+ export { useLocation } from './template/react/history';
14
14
  export interface DefineSwicoConfigType {
15
15
  (env: 'base', config: CustomConfigType['base']): any;
16
16
  (env: 'dev', config: CustomConfigType['dev']): any;
@@ -13,8 +13,8 @@ var Link = function (_a) {
13
13
  exports.Link = Link;
14
14
  var react_router_dom_2 = require("react-router-dom");
15
15
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_dom_2.Outlet; } });
16
- var hooks_1 = require("./template/react/hooks");
17
- Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
16
+ var history_1 = require("./template/react/history");
17
+ Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return history_1.useLocation; } });
18
18
  var defineConfig = function (env, config) { return config; };
19
19
  exports.defineConfig = defineConfig;
20
20
  var defineGlobal = function (config) {
@@ -6,7 +6,8 @@ export declare const getPathNameList: (routes: RoutesItemType[]) => Array<{
6
6
  path: string;
7
7
  name: string;
8
8
  }>;
9
- export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type'], routes: RoutesItemType[]) => {
9
+ export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type']) => {
10
10
  history: SwicoHistoryType;
11
11
  originalHistory: import("history").HashHistory;
12
12
  };
13
+ export declare const useLocation: UseLocationType;
@@ -3,11 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getHistory = exports.getPathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
6
+ exports.useLocation = exports.getHistory = exports.getPathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
7
7
  var qs_1 = __importDefault(require("qs"));
8
8
  var history_1 = require("history");
9
9
  var react_router_dom_1 = require("react-router-dom");
10
- Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
10
+ var react_router_dom_2 = require("react-router-dom");
11
+ var routes_1 = require("./routes");
12
+ var react_router_dom_3 = require("react-router-dom");
13
+ Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_3.unstable_HistoryRouter; } });
11
14
  var interpolatePath = function (pathTemplate, params) {
12
15
  var pathParts = pathTemplate.split('/');
13
16
  var interpolatedParts = pathParts.map(function (part) {
@@ -79,11 +82,12 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
79
82
  }
80
83
  return obj;
81
84
  };
82
- var getHistory = function (routerBase, routerType, routes) {
85
+ var getHistory = function (routerBase, routerType) {
83
86
  var _a;
84
87
  var history;
85
88
  var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
86
- var pathNameList = (0, exports.getPathNameList)(routes);
89
+ console.log('routes1', routes_1.routes);
90
+ var pathNameList = (0, exports.getPathNameList)(routes_1.routes);
87
91
  var lastIndexBase = routerBase[routerBase.length - 1];
88
92
  var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
89
93
  history = {
@@ -123,3 +127,44 @@ var getHistory = function (routerBase, routerType, routes) {
123
127
  return { history: history, originalHistory: originalHistory };
124
128
  };
125
129
  exports.getHistory = getHistory;
130
+ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
131
+ var patternWithValuesParts = urlPatternWithValues.split('/');
132
+ var patternWithParamsParts = urlPatternWithParams.split('/');
133
+ if (patternWithValuesParts.length !== patternWithParamsParts.length) {
134
+ return false;
135
+ }
136
+ for (var i = 0; i < patternWithValuesParts.length; i++) {
137
+ var valuePart = patternWithValuesParts[i];
138
+ var paramPart = patternWithParamsParts[i];
139
+ if (paramPart.startsWith(':') && paramPart !== '') {
140
+ continue;
141
+ }
142
+ if (valuePart !== paramPart) {
143
+ return false;
144
+ }
145
+ }
146
+ return true;
147
+ };
148
+ var useLocation = function () {
149
+ var _a, _b;
150
+ var location = (0, react_router_dom_1.useLocation)();
151
+ var params = (0, react_router_dom_2.useParams)();
152
+ var search = location.search, hash = location.hash, pathname = location.pathname;
153
+ console.log('routes2', routes_1.routes);
154
+ var pathNameList = (0, exports.getPathNameList)(routes_1.routes);
155
+ var name = (_a = pathNameList.find(function (item) {
156
+ return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
157
+ item.path === pathname;
158
+ })) === null || _a === void 0 ? void 0 : _a.name;
159
+ var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
160
+ return {
161
+ name: name,
162
+ path: pathname,
163
+ pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
164
+ search: search,
165
+ query: query,
166
+ hash: hash,
167
+ params: params
168
+ };
169
+ };
170
+ exports.useLocation = useLocation;
@@ -43,7 +43,7 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
43
43
  });
44
44
  };
45
45
  var App = function () {
46
- var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType, routes_1.routes), history = _a.history, originalHistory = _a.originalHistory;
46
+ var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), history = _a.history, originalHistory = _a.originalHistory;
47
47
  if (config_1.routerBase && config_1.routerBase !== '/') {
48
48
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
49
49
  window.location.replace("".concat(config_1.routerBase));