wj-elements 0.0.11 → 0.0.13
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/localize-20081fd1.js +55 -0
- package/dist/router-links-26e4a166.js +204 -0
- package/dist/style.css +2243 -2
- package/dist/wj-animation.js +35 -23
- package/dist/wj-aside.js +22 -16
- package/dist/wj-avatar.js +49 -30
- package/dist/wj-badge.js +22 -18
- package/dist/wj-breadcrumb.js +102 -50
- package/dist/wj-breadcrumbs.js +36 -19
- package/dist/wj-button-group.js +36 -22
- package/dist/wj-button.js +104 -39
- package/dist/wj-card-content.js +18 -14
- package/dist/wj-card-controls.js +18 -14
- package/dist/wj-card-header.js +20 -14
- package/dist/wj-card-subtitle.js +19 -15
- package/dist/wj-card-title.js +18 -14
- package/dist/wj-card.js +20 -14
- package/dist/wj-carousel-item.js +22 -16
- package/dist/wj-carousel.js +169 -92
- package/dist/wj-checkbox.js +46 -24
- package/dist/wj-chip.js +39 -21
- package/dist/wj-col.js +31 -17
- package/dist/wj-color-picker.js +877 -509
- package/dist/wj-container.js +20 -16
- package/dist/wj-copy-button.js +112 -64
- package/dist/wj-dialog.js +68 -42
- package/dist/wj-divider.js +20 -14
- package/dist/wj-dropdown.js +29 -17
- package/dist/wj-element.js +415 -241
- package/dist/wj-fetchAndParseCSS.js +49 -32
- package/dist/wj-file-upload-item.js +64 -38
- package/dist/wj-file-upload.js +237 -137
- package/dist/wj-footer.js +18 -14
- package/dist/wj-form.js +18 -14
- package/dist/wj-format-digital.js +40 -25
- package/dist/wj-grid.js +20 -16
- package/dist/wj-header.js +22 -16
- package/dist/wj-icon-picker.js +122 -68
- package/dist/wj-icon.js +144 -64
- package/dist/wj-img-comparer.js +72 -41
- package/dist/wj-img.js +31 -19
- package/dist/wj-infinite-scroll.js +90 -52
- package/dist/wj-input-file.js +50 -27
- package/dist/wj-input.js +169 -70
- package/dist/wj-item.js +34 -17
- package/dist/wj-label.js +21 -19
- package/dist/wj-list.js +20 -15
- package/dist/wj-main.js +18 -14
- package/dist/wj-masonry.js +140 -83
- package/dist/wj-master.js +492 -350
- package/dist/wj-menu-button.js +19 -15
- package/dist/wj-menu-item.js +150 -64
- package/dist/wj-menu-label.js +21 -17
- package/dist/wj-menu.js +24 -18
- package/dist/wj-popup.js +1140 -712
- package/dist/wj-progress-bar.js +100 -40
- package/dist/wj-radio-group.js +38 -25
- package/dist/wj-radio.js +46 -22
- package/dist/wj-rate.js +121 -71
- package/dist/wj-relative-time.js +48 -24
- package/dist/wj-route.js +11 -8
- package/dist/wj-router-link.js +22 -17
- package/dist/wj-router-outlet.js +135 -71
- package/dist/wj-routerx.js +1124 -641
- package/dist/wj-row.js +21 -19
- package/dist/wj-slider.js +97 -55
- package/dist/wj-split-view.js +81 -43
- package/dist/wj-store.js +195 -110
- package/dist/wj-textarea.js +86 -37
- package/dist/wj-thumbnail.js +19 -15
- package/dist/wj-toast.js +87 -34
- package/dist/wj-toggle.js +42 -24
- package/dist/wj-toolbar-action.js +27 -16
- package/dist/wj-toolbar.js +26 -19
- package/dist/wj-tooltip.js +40 -24
- package/dist/wj-visually-hidden.js +18 -14
- package/package.json +1 -1
- package/dist/localize-762a9f0f.js +0 -43
- package/dist/router-links-e0087f84.js +0 -146
package/dist/wj-routerx.js
CHANGED
|
@@ -1,254 +1,379 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import WJElement from "./wj-element.js";
|
|
8
|
+
import { r as routerLinks } from "./router-links-26e4a166.js";
|
|
6
9
|
import "./wj-store.js";
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
var DEFAULT_DELIMITER = "/";
|
|
11
|
+
function balanced(open, close, str, index) {
|
|
12
|
+
var count = 0;
|
|
13
|
+
var i = index;
|
|
14
|
+
while (i < str.length) {
|
|
15
|
+
if (str[i] === "\\") {
|
|
16
|
+
i += 2;
|
|
12
17
|
continue;
|
|
13
18
|
}
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
if (str[i] === close) {
|
|
20
|
+
count--;
|
|
21
|
+
if (count === 0)
|
|
22
|
+
return i + 1;
|
|
23
|
+
}
|
|
24
|
+
if (str[i] === open) {
|
|
25
|
+
count++;
|
|
26
|
+
}
|
|
27
|
+
i++;
|
|
17
28
|
}
|
|
18
29
|
return -1;
|
|
19
30
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
function parse(str, options) {
|
|
32
|
+
if (options === void 0) {
|
|
33
|
+
options = {};
|
|
34
|
+
}
|
|
35
|
+
var _a, _b;
|
|
36
|
+
var tokens = [];
|
|
37
|
+
var defaultDelimiter = (_a = options.delimiter, _a !== null && _a !== void 0 ? _a : DEFAULT_DELIMITER);
|
|
38
|
+
var whitelist = (_b = options.whitelist, _b !== null && _b !== void 0 ? _b : void 0);
|
|
39
|
+
var i = 0;
|
|
40
|
+
var key = 0;
|
|
41
|
+
var path = "";
|
|
42
|
+
var isEscaped = false;
|
|
43
|
+
while (i < str.length) {
|
|
44
|
+
var prefix = "";
|
|
45
|
+
var name = "";
|
|
46
|
+
var pattern = "";
|
|
47
|
+
if (str[i] === "\\") {
|
|
48
|
+
i++;
|
|
49
|
+
path += str[i++];
|
|
50
|
+
isEscaped = true;
|
|
26
51
|
continue;
|
|
27
52
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
var
|
|
53
|
+
if (str[i] === ":") {
|
|
54
|
+
while (++i < str.length) {
|
|
55
|
+
var code = str.charCodeAt(i);
|
|
31
56
|
if (
|
|
32
57
|
// `0-9`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
code >= 48 && code <= 57 || // `A-Z`
|
|
59
|
+
code >= 65 && code <= 90 || // `a-z`
|
|
60
|
+
code >= 97 && code <= 122 || // `_`
|
|
61
|
+
code === 95
|
|
37
62
|
) {
|
|
38
|
-
|
|
63
|
+
name += str[i];
|
|
39
64
|
continue;
|
|
40
65
|
}
|
|
41
66
|
break;
|
|
42
67
|
}
|
|
43
|
-
|
|
68
|
+
if (!name)
|
|
69
|
+
i--;
|
|
44
70
|
}
|
|
45
|
-
if (
|
|
46
|
-
var
|
|
47
|
-
if (
|
|
48
|
-
|
|
71
|
+
if (str[i] === "(") {
|
|
72
|
+
var end = balanced("(", ")", str, i);
|
|
73
|
+
if (end > -1) {
|
|
74
|
+
pattern = str.slice(i + 1, end - 1);
|
|
75
|
+
i = end;
|
|
76
|
+
if (pattern[0] === "?") {
|
|
49
77
|
throw new TypeError("Path pattern must be a capturing group");
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
}
|
|
79
|
+
if (/\((?=[^?])/.test(pattern)) {
|
|
80
|
+
var validPattern = pattern.replace(/\((?=[^?])/, "(?:");
|
|
81
|
+
throw new TypeError("Capturing groups are not allowed in pattern, use a non-capturing group: (" + validPattern + ")");
|
|
53
82
|
}
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
85
|
+
if (name === "" && pattern === "") {
|
|
86
|
+
path += str[i++];
|
|
87
|
+
isEscaped = false;
|
|
58
88
|
continue;
|
|
59
89
|
}
|
|
60
|
-
if (
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
90
|
+
if (path.length && !isEscaped) {
|
|
91
|
+
var char = path[path.length - 1];
|
|
92
|
+
var matches = whitelist ? whitelist.indexOf(char) > -1 : true;
|
|
93
|
+
if (matches) {
|
|
94
|
+
prefix = char;
|
|
95
|
+
path = path.slice(0, -1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (path.length) {
|
|
99
|
+
tokens.push(path);
|
|
100
|
+
path = "";
|
|
101
|
+
}
|
|
102
|
+
var repeat = str[i] === "+" || str[i] === "*";
|
|
103
|
+
var optional = str[i] === "?" || str[i] === "*";
|
|
104
|
+
var delimiter = prefix || defaultDelimiter;
|
|
105
|
+
if (repeat || optional)
|
|
106
|
+
i++;
|
|
107
|
+
tokens.push({
|
|
108
|
+
name: name || key++,
|
|
109
|
+
prefix,
|
|
110
|
+
delimiter,
|
|
111
|
+
optional,
|
|
112
|
+
repeat,
|
|
113
|
+
pattern: pattern || "[^" + escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter) + "]+?"
|
|
73
114
|
});
|
|
74
115
|
}
|
|
75
|
-
|
|
116
|
+
if (path.length)
|
|
117
|
+
tokens.push(path);
|
|
118
|
+
return tokens;
|
|
76
119
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
120
|
+
function escapeString(str) {
|
|
121
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
79
122
|
}
|
|
80
|
-
function
|
|
81
|
-
return
|
|
123
|
+
function flags(options) {
|
|
124
|
+
return options && options.sensitive ? "" : "i";
|
|
82
125
|
}
|
|
83
|
-
function
|
|
84
|
-
if (!
|
|
85
|
-
return
|
|
86
|
-
var
|
|
87
|
-
if (
|
|
88
|
-
for (var
|
|
89
|
-
|
|
90
|
-
name:
|
|
126
|
+
function regexpToRegexp(path, keys2) {
|
|
127
|
+
if (!keys2)
|
|
128
|
+
return path;
|
|
129
|
+
var groups = path.source.match(/\((?!\?)/g);
|
|
130
|
+
if (groups) {
|
|
131
|
+
for (var i = 0; i < groups.length; i++) {
|
|
132
|
+
keys2.push({
|
|
133
|
+
name: i,
|
|
91
134
|
prefix: "",
|
|
92
135
|
delimiter: "",
|
|
93
|
-
optional:
|
|
94
|
-
repeat:
|
|
136
|
+
optional: false,
|
|
137
|
+
repeat: false,
|
|
95
138
|
pattern: ""
|
|
96
139
|
});
|
|
97
|
-
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return path;
|
|
98
143
|
}
|
|
99
|
-
function
|
|
100
|
-
var
|
|
101
|
-
return
|
|
144
|
+
function arrayToRegexp(paths, keys2, options) {
|
|
145
|
+
var parts = paths.map(function(path) {
|
|
146
|
+
return pathToRegexp(path, keys2, options).source;
|
|
102
147
|
});
|
|
103
|
-
return new RegExp("(?:" +
|
|
148
|
+
return new RegExp("(?:" + parts.join("|") + ")", flags(options));
|
|
104
149
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
150
|
+
function stringToRegexp(path, keys2, options) {
|
|
151
|
+
return tokensToRegexp(parse(path, options), keys2, options);
|
|
107
152
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
153
|
+
function tokensToRegexp(tokens, keys2, options) {
|
|
154
|
+
if (options === void 0) {
|
|
155
|
+
options = {};
|
|
156
|
+
}
|
|
157
|
+
var strict = options.strict, _a = options.start, start = _a === void 0 ? true : _a, _b = options.end, end = _b === void 0 ? true : _b, _c = options.delimiter, delimiter = _c === void 0 ? DEFAULT_DELIMITER : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
|
|
158
|
+
return x;
|
|
159
|
+
} : _d;
|
|
160
|
+
var endsWith = (typeof options.endsWith === "string" ? options.endsWith.split("") : options.endsWith || []).map(escapeString).concat("$").join("|");
|
|
161
|
+
var route = start ? "^" : "";
|
|
162
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
163
|
+
var token = tokens_1[_i];
|
|
164
|
+
if (typeof token === "string") {
|
|
165
|
+
route += escapeString(encode(token));
|
|
166
|
+
} else {
|
|
167
|
+
var capture = token.repeat ? "(?:" + token.pattern + ")(?:" + escapeString(token.delimiter) + "(?:" + token.pattern + "))*" : token.pattern;
|
|
168
|
+
if (keys2)
|
|
169
|
+
keys2.push(token);
|
|
170
|
+
if (token.optional) {
|
|
171
|
+
if (!token.prefix) {
|
|
172
|
+
route += "(" + capture + ")?";
|
|
173
|
+
} else {
|
|
174
|
+
route += "(?:" + escapeString(token.prefix) + "(" + capture + "))?";
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
route += escapeString(token.prefix) + "(" + capture + ")";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (end) {
|
|
182
|
+
if (!strict)
|
|
183
|
+
route += "(?:" + escapeString(delimiter) + ")?";
|
|
184
|
+
route += endsWith === "$" ? "$" : "(?=" + endsWith + ")";
|
|
185
|
+
} else {
|
|
186
|
+
var endToken = tokens[tokens.length - 1];
|
|
187
|
+
var isEndDelimited = typeof endToken === "string" ? endToken[endToken.length - 1] === delimiter : (
|
|
125
188
|
// tslint:disable-next-line
|
|
126
|
-
|
|
189
|
+
endToken === void 0
|
|
127
190
|
);
|
|
128
|
-
|
|
191
|
+
if (!strict) {
|
|
192
|
+
route += "(?:" + escapeString(delimiter) + "(?=" + endsWith + "))?";
|
|
193
|
+
}
|
|
194
|
+
if (!isEndDelimited) {
|
|
195
|
+
route += "(?=" + escapeString(delimiter) + "|" + endsWith + ")";
|
|
196
|
+
}
|
|
129
197
|
}
|
|
130
|
-
return new RegExp(
|
|
198
|
+
return new RegExp(route, flags(options));
|
|
131
199
|
}
|
|
132
|
-
function
|
|
133
|
-
|
|
200
|
+
function pathToRegexp(path, keys2, options) {
|
|
201
|
+
if (path instanceof RegExp) {
|
|
202
|
+
return regexpToRegexp(path, keys2);
|
|
203
|
+
}
|
|
204
|
+
if (Array.isArray(path)) {
|
|
205
|
+
return arrayToRegexp(path, keys2, options);
|
|
206
|
+
}
|
|
207
|
+
return stringToRegexp(path, keys2, options);
|
|
134
208
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
209
|
+
const assoc = (obj, attr, val) => {
|
|
210
|
+
obj[attr] = val;
|
|
211
|
+
return obj;
|
|
212
|
+
};
|
|
213
|
+
const isArray = Array.isArray;
|
|
214
|
+
const keys = Object.keys;
|
|
215
|
+
const clone = (obj) => obj ? isArray(obj) ? obj.slice(0) : extend({}, obj) : obj;
|
|
216
|
+
const pick = (obj, attrs) => attrs.reduce((acc, attr) => obj[attr] === void 0 ? acc : assoc(acc, attr, obj[attr]), {});
|
|
217
|
+
const isEqual$1 = (obj1, obj2) => {
|
|
218
|
+
const keys1 = keys(obj1);
|
|
219
|
+
return keys1.length === keys(obj2).length && keys1.every((key) => obj2[key] === obj1[key]);
|
|
220
|
+
};
|
|
221
|
+
const extend = Object.assign;
|
|
222
|
+
function invariant(condition, format, ...args) {
|
|
223
|
+
if (!condition) {
|
|
224
|
+
let argIndex = 0;
|
|
142
225
|
throw new Error(
|
|
143
|
-
"Invariant Violation: " +
|
|
226
|
+
"Invariant Violation: " + format.replace(/%s/g, () => args[argIndex++])
|
|
144
227
|
);
|
|
145
228
|
}
|
|
146
229
|
}
|
|
147
|
-
function
|
|
148
|
-
let
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
options
|
|
230
|
+
function functionDsl(callback) {
|
|
231
|
+
let ancestors = [];
|
|
232
|
+
const matches = {};
|
|
233
|
+
const names = {};
|
|
234
|
+
callback(function route(name, options, childrenCallback) {
|
|
235
|
+
let routes;
|
|
236
|
+
invariant(!names[name], 'Route names must be unique, but route "%s" is declared multiple times', name);
|
|
237
|
+
names[name] = true;
|
|
238
|
+
if (arguments.length === 1) {
|
|
239
|
+
options = {};
|
|
240
|
+
}
|
|
241
|
+
if (arguments.length === 2 && typeof options === "function") {
|
|
242
|
+
childrenCallback = options;
|
|
243
|
+
options = {};
|
|
244
|
+
}
|
|
245
|
+
if (typeof options.path !== "string") {
|
|
246
|
+
const parts = name.split(".");
|
|
247
|
+
options.path = parts[parts.length - 1];
|
|
248
|
+
}
|
|
249
|
+
if (childrenCallback) {
|
|
250
|
+
ancestors = ancestors.concat(name);
|
|
251
|
+
childrenCallback();
|
|
252
|
+
routes = pop();
|
|
253
|
+
ancestors.splice(-1);
|
|
254
|
+
}
|
|
255
|
+
push({
|
|
256
|
+
name,
|
|
257
|
+
path: options.path,
|
|
258
|
+
routes: routes || [],
|
|
259
|
+
options
|
|
161
260
|
});
|
|
162
261
|
});
|
|
163
|
-
function
|
|
164
|
-
return
|
|
262
|
+
function pop() {
|
|
263
|
+
return matches[currentLevel()] || [];
|
|
165
264
|
}
|
|
166
|
-
function
|
|
167
|
-
const
|
|
168
|
-
|
|
265
|
+
function push(route) {
|
|
266
|
+
const level = currentLevel();
|
|
267
|
+
matches[level] = matches[level] || [];
|
|
268
|
+
matches[level].push(route);
|
|
169
269
|
}
|
|
170
|
-
function
|
|
171
|
-
return
|
|
270
|
+
function currentLevel() {
|
|
271
|
+
return ancestors.join(".");
|
|
172
272
|
}
|
|
173
|
-
return
|
|
273
|
+
return pop();
|
|
174
274
|
}
|
|
175
|
-
function
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
if (typeof
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
275
|
+
function arrayDsl(routes) {
|
|
276
|
+
const result = [];
|
|
277
|
+
routes.forEach(({ name, children, ...options }) => {
|
|
278
|
+
if (typeof options.path !== "string") {
|
|
279
|
+
const parts = name.split(".");
|
|
280
|
+
options.path = parts[parts.length - 1];
|
|
281
|
+
}
|
|
282
|
+
result.push(
|
|
183
283
|
{
|
|
184
|
-
name
|
|
185
|
-
path:
|
|
186
|
-
options
|
|
187
|
-
routes:
|
|
284
|
+
name,
|
|
285
|
+
path: options.path,
|
|
286
|
+
options,
|
|
287
|
+
routes: children ? arrayDsl(children) : []
|
|
188
288
|
}
|
|
189
289
|
);
|
|
190
|
-
})
|
|
290
|
+
});
|
|
291
|
+
return result;
|
|
191
292
|
}
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
293
|
+
const paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?+*]?)/g;
|
|
294
|
+
const specialParamChars = /[+*?]$/g;
|
|
295
|
+
const queryMatcher = /\?(.+)/;
|
|
296
|
+
const _compiledPatterns = {};
|
|
297
|
+
function compilePattern(pattern) {
|
|
298
|
+
if (!(pattern in _compiledPatterns)) {
|
|
299
|
+
const paramNames = [];
|
|
300
|
+
const re = pathToRegexp(pattern, paramNames);
|
|
301
|
+
_compiledPatterns[pattern] = {
|
|
302
|
+
matcher: re,
|
|
303
|
+
paramNames: paramNames.map((p) => p.name)
|
|
199
304
|
};
|
|
200
305
|
}
|
|
201
|
-
return
|
|
306
|
+
return _compiledPatterns[pattern];
|
|
202
307
|
}
|
|
203
|
-
function
|
|
204
|
-
return
|
|
308
|
+
function extractParamNames(pattern) {
|
|
309
|
+
return compilePattern(pattern).paramNames;
|
|
205
310
|
}
|
|
206
|
-
function
|
|
207
|
-
const
|
|
208
|
-
|
|
311
|
+
function extractParams(pattern, path) {
|
|
312
|
+
const cp = compilePattern(pattern);
|
|
313
|
+
const matcher = cp.matcher;
|
|
314
|
+
const paramNames = cp.paramNames;
|
|
315
|
+
const match = path.match(matcher);
|
|
316
|
+
if (!match) {
|
|
209
317
|
return null;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
318
|
+
}
|
|
319
|
+
const params = {};
|
|
320
|
+
paramNames.forEach(function(paramName, index) {
|
|
321
|
+
params[paramName] = match[index + 1] && decodeURIComponent(match[index + 1]);
|
|
322
|
+
});
|
|
323
|
+
return params;
|
|
214
324
|
}
|
|
215
|
-
function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
325
|
+
function injectParams(pattern, params) {
|
|
326
|
+
params = params || {};
|
|
327
|
+
return pattern.replace(paramInjectMatcher, function(match, param) {
|
|
328
|
+
const paramName = param.replace(specialParamChars, "");
|
|
329
|
+
const lastChar = param.slice(-1);
|
|
330
|
+
if (lastChar === "?" || lastChar === "*") {
|
|
331
|
+
if (params[paramName] == null) {
|
|
220
332
|
return "";
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
invariant(
|
|
336
|
+
params[paramName] != null,
|
|
224
337
|
"Missing '%s' parameter for path '%s'",
|
|
225
|
-
|
|
226
|
-
|
|
338
|
+
paramName,
|
|
339
|
+
pattern
|
|
227
340
|
);
|
|
228
|
-
|
|
229
|
-
|
|
341
|
+
}
|
|
342
|
+
let paramValue = encodeURIComponent(params[paramName]);
|
|
343
|
+
if (lastChar === "*" || lastChar === "+") {
|
|
344
|
+
paramValue = paramValue.replaceAll("%2F", "/");
|
|
345
|
+
}
|
|
346
|
+
return paramValue;
|
|
230
347
|
});
|
|
231
348
|
}
|
|
232
|
-
function
|
|
233
|
-
const
|
|
234
|
-
return
|
|
349
|
+
function extractQuery(qs2, path) {
|
|
350
|
+
const match = path.match(queryMatcher);
|
|
351
|
+
return match && qs2.parse(match[1]);
|
|
235
352
|
}
|
|
236
|
-
function
|
|
237
|
-
const
|
|
238
|
-
|
|
353
|
+
function withQuery(qs2, path, query) {
|
|
354
|
+
const queryString = qs2.stringify(query, { indices: false });
|
|
355
|
+
if (queryString) {
|
|
356
|
+
return withoutQuery(path) + "?" + queryString;
|
|
357
|
+
}
|
|
358
|
+
return path;
|
|
239
359
|
}
|
|
240
|
-
function
|
|
241
|
-
return
|
|
360
|
+
function withoutQuery(path) {
|
|
361
|
+
return path.replace(queryMatcher, "");
|
|
242
362
|
}
|
|
243
|
-
function
|
|
244
|
-
|
|
363
|
+
function bindEvent(el, type, fn) {
|
|
364
|
+
el.addEventListener(type, fn);
|
|
365
|
+
return fn;
|
|
245
366
|
}
|
|
246
|
-
function
|
|
247
|
-
|
|
367
|
+
function unbindEvent(el, type, fn) {
|
|
368
|
+
el.removeEventListener(type, fn);
|
|
369
|
+
return fn;
|
|
248
370
|
}
|
|
249
|
-
class
|
|
371
|
+
class History {
|
|
250
372
|
constructor() {
|
|
251
|
-
this.handlers = []
|
|
373
|
+
this.handlers = [];
|
|
374
|
+
this.checkUrl = this.checkUrl.bind(this);
|
|
375
|
+
this.location = window.location;
|
|
376
|
+
this.history = window.history;
|
|
252
377
|
}
|
|
253
378
|
// Set up all inheritable **Backbone.History** properties and methods.
|
|
254
379
|
// Are we at the app root?
|
|
@@ -258,32 +383,49 @@ class Ct {
|
|
|
258
383
|
// Gets the true hash value. Cannot use location.hash directly due to bug
|
|
259
384
|
// in Firefox where location.hash will always be decoded.
|
|
260
385
|
getHash() {
|
|
261
|
-
const
|
|
262
|
-
return
|
|
386
|
+
const match = this.location.href.match(/#(.*)$/);
|
|
387
|
+
return match ? match[1] : "";
|
|
263
388
|
}
|
|
264
389
|
// Get the cross-browser normalized URL fragment, either from the URL,
|
|
265
390
|
// the hash, or the override.
|
|
266
|
-
getFragment(
|
|
267
|
-
if (
|
|
268
|
-
if (this._hasPushState || !this._wantsHashChange ||
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
391
|
+
getFragment(fragment, forcePushState) {
|
|
392
|
+
if (fragment == null) {
|
|
393
|
+
if (this._hasPushState || !this._wantsHashChange || forcePushState) {
|
|
394
|
+
fragment = decodeURI(this.location.pathname + this.location.search);
|
|
395
|
+
const root = this.root.replace(trailingSlash, "");
|
|
396
|
+
if (!fragment.indexOf(root))
|
|
397
|
+
fragment = fragment.slice(root.length);
|
|
398
|
+
} else {
|
|
399
|
+
fragment = this.getHash();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return fragment.replace(routeStripper, "");
|
|
275
403
|
}
|
|
276
404
|
// Start the hash change handling, returning `true` if the current URL matches
|
|
277
405
|
// an existing route, and `false` otherwise.
|
|
278
|
-
start(
|
|
279
|
-
this.started =
|
|
280
|
-
|
|
281
|
-
this.
|
|
282
|
-
|
|
406
|
+
start(options = {}) {
|
|
407
|
+
this.started = true;
|
|
408
|
+
this.options = extend({ root: "/" }, options);
|
|
409
|
+
this.location = this.options.location || this.location;
|
|
410
|
+
this.history = this.options.history || this.history;
|
|
411
|
+
this.root = this.options.root;
|
|
412
|
+
this._wantsHashChange = this.options.hashChange !== false;
|
|
413
|
+
this._wantsPushState = !!this.options.pushState;
|
|
414
|
+
this._hasPushState = this._wantsPushState;
|
|
415
|
+
const fragment = this.getFragment();
|
|
416
|
+
this.root = `/${this.root}/`.replace(rootStripper, "/");
|
|
417
|
+
bindEvent(window, this._hasPushState ? "popstate" : "hashchange", this.checkUrl);
|
|
418
|
+
this.fragment = fragment;
|
|
419
|
+
const loc = this.location;
|
|
283
420
|
if (this._wantsHashChange && this._wantsPushState) {
|
|
284
|
-
if (!this._hasPushState && !this.atRoot())
|
|
285
|
-
|
|
286
|
-
|
|
421
|
+
if (!this._hasPushState && !this.atRoot()) {
|
|
422
|
+
this.fragment = this.getFragment(null, true);
|
|
423
|
+
this.location.replace(`${this.root}#${this.fragment}`);
|
|
424
|
+
return true;
|
|
425
|
+
} else if (this._hasPushState && this.atRoot() && loc.hash) {
|
|
426
|
+
this.fragment = this.getHash().replace(routeStripper, "");
|
|
427
|
+
this.history.replaceState({}, document.title, this.root + this.fragment);
|
|
428
|
+
}
|
|
287
429
|
}
|
|
288
430
|
if (!this.options.silent)
|
|
289
431
|
return this.loadUrl();
|
|
@@ -291,27 +433,32 @@ class Ct {
|
|
|
291
433
|
// Disable Backbone.history, perhaps temporarily. Not useful in a real app,
|
|
292
434
|
// but possibly useful for unit testing Routers.
|
|
293
435
|
stop() {
|
|
294
|
-
|
|
436
|
+
unbindEvent(window, this._hasPushState ? "popstate" : "hashchange", this.checkUrl);
|
|
437
|
+
this.started = false;
|
|
295
438
|
}
|
|
296
439
|
// Add a route to be tested when the fragment changes. Routes added later
|
|
297
440
|
// may override previous routes.
|
|
298
|
-
route(
|
|
299
|
-
this.handlers.unshift({ route
|
|
441
|
+
route(route, callback) {
|
|
442
|
+
this.handlers.unshift({ route, callback });
|
|
300
443
|
}
|
|
301
444
|
// Checks the current URL to see if it has changed, and if it has,
|
|
302
445
|
// calls `loadUrl`.
|
|
303
446
|
checkUrl() {
|
|
304
|
-
|
|
305
|
-
|
|
447
|
+
const current = this.getFragment();
|
|
448
|
+
if (current === this.fragment)
|
|
449
|
+
return false;
|
|
306
450
|
this.loadUrl();
|
|
307
451
|
}
|
|
308
452
|
// Attempt to load the current URL fragment. If a route succeeds with a
|
|
309
453
|
// match, returns `true`. If no defined routes matches the fragment,
|
|
310
454
|
// returns `false`.
|
|
311
|
-
loadUrl(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
455
|
+
loadUrl(fragment) {
|
|
456
|
+
fragment = this.fragment = this.getFragment(fragment);
|
|
457
|
+
return this.handlers.some((handler) => {
|
|
458
|
+
if (handler.route.test(fragment)) {
|
|
459
|
+
handler.callback(fragment);
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
315
462
|
});
|
|
316
463
|
}
|
|
317
464
|
// Save a fragment into the hash history, or replace the URL state if the
|
|
@@ -321,52 +468,67 @@ class Ct {
|
|
|
321
468
|
// The options object can contain `trigger: true` if you wish to have the
|
|
322
469
|
// route callback be fired (not usually desirable), or `replace: true`, if
|
|
323
470
|
// you wish to modify the current URL without adding an entry to the history.
|
|
324
|
-
update(
|
|
471
|
+
update(fragment, options) {
|
|
325
472
|
if (!this.started)
|
|
326
|
-
return
|
|
327
|
-
(!
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
473
|
+
return false;
|
|
474
|
+
if (!options || options === true)
|
|
475
|
+
options = { trigger: !!options };
|
|
476
|
+
let url = this.root + (fragment = this.getFragment(fragment || ""));
|
|
477
|
+
fragment = fragment.replace(pathStripper, "");
|
|
478
|
+
if (this.fragment === fragment)
|
|
479
|
+
return;
|
|
480
|
+
this.fragment = fragment;
|
|
481
|
+
if (fragment === "" && url !== "/")
|
|
482
|
+
url = url.slice(0, -1);
|
|
483
|
+
if (this._hasPushState) {
|
|
484
|
+
this.history[options.replace ? "replaceState" : "pushState"]({}, document.title, url);
|
|
485
|
+
} else if (this._wantsHashChange) {
|
|
486
|
+
this._updateHash(this.location, fragment, options.replace);
|
|
487
|
+
} else {
|
|
488
|
+
return this.location.assign(url);
|
|
338
489
|
}
|
|
490
|
+
if (options.trigger)
|
|
491
|
+
return this.loadUrl(fragment);
|
|
339
492
|
}
|
|
340
493
|
// Update the hash location, either replacing the current entry, or adding
|
|
341
494
|
// a new one to the browser history.
|
|
342
|
-
_updateHash(
|
|
343
|
-
if (
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
} else
|
|
347
|
-
|
|
495
|
+
_updateHash(location, fragment, replace) {
|
|
496
|
+
if (replace) {
|
|
497
|
+
const href = location.href.replace(/(javascript:|#).*$/, "");
|
|
498
|
+
location.replace(`${href}#${fragment}`);
|
|
499
|
+
} else {
|
|
500
|
+
location.hash = `#${fragment}`;
|
|
501
|
+
}
|
|
348
502
|
}
|
|
349
503
|
// add some features to History
|
|
350
504
|
// a generic callback for any changes
|
|
351
|
-
onChange(
|
|
352
|
-
this.route(/^(.*?)$/,
|
|
505
|
+
onChange(callback) {
|
|
506
|
+
this.route(/^(.*?)$/, callback);
|
|
353
507
|
}
|
|
354
508
|
// checks if the browser has pushstate support
|
|
355
509
|
hasPushState() {
|
|
356
|
-
if (!this.started)
|
|
510
|
+
if (!this.started) {
|
|
357
511
|
throw new Error("only available after LocationBar.start()");
|
|
512
|
+
}
|
|
358
513
|
return this._hasPushState;
|
|
359
514
|
}
|
|
360
515
|
}
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
516
|
+
const routeStripper = /^[#\/]|\s+$/g;
|
|
517
|
+
const rootStripper = /^\/+|\/+$/g;
|
|
518
|
+
const trailingSlash = /\/$/;
|
|
519
|
+
const pathStripper = /#.*$/;
|
|
520
|
+
class BrowserLocation {
|
|
521
|
+
constructor(options = {}) {
|
|
522
|
+
this.path = options.path || "";
|
|
523
|
+
this.options = extend({
|
|
524
|
+
pushState: false,
|
|
366
525
|
root: "/"
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
|
|
526
|
+
}, options);
|
|
527
|
+
this.locationBar = new History();
|
|
528
|
+
this.locationBar.onChange((path) => {
|
|
529
|
+
this.handleURL(`/${path || ""}`);
|
|
530
|
+
});
|
|
531
|
+
this.locationBar.start(options);
|
|
370
532
|
}
|
|
371
533
|
/**
|
|
372
534
|
* Get the current URL
|
|
@@ -378,33 +540,46 @@ class xt {
|
|
|
378
540
|
* Set the current URL without triggering any events
|
|
379
541
|
* back to the router. Add a new entry in browser's history.
|
|
380
542
|
*/
|
|
381
|
-
setURL(
|
|
382
|
-
this.path !==
|
|
543
|
+
setURL(path, options = {}) {
|
|
544
|
+
if (this.path !== path) {
|
|
545
|
+
this.path = path;
|
|
546
|
+
this.locationBar.update(path, extend({ trigger: true }, options));
|
|
547
|
+
}
|
|
383
548
|
}
|
|
384
549
|
/**
|
|
385
550
|
* Set the current URL without triggering any events
|
|
386
551
|
* back to the router. Replace the latest entry in broser's history.
|
|
387
552
|
*/
|
|
388
|
-
replaceURL(
|
|
389
|
-
this.path !==
|
|
553
|
+
replaceURL(path, options = {}) {
|
|
554
|
+
if (this.path !== path) {
|
|
555
|
+
this.path = path;
|
|
556
|
+
this.locationBar.update(path, extend({ trigger: true, replace: true }, options));
|
|
557
|
+
}
|
|
390
558
|
}
|
|
391
559
|
/**
|
|
392
560
|
* Setup a URL change handler
|
|
393
561
|
* @param {Function} callback
|
|
394
562
|
*/
|
|
395
|
-
onChange(
|
|
396
|
-
this.changeCallback =
|
|
563
|
+
onChange(callback) {
|
|
564
|
+
this.changeCallback = callback;
|
|
397
565
|
}
|
|
398
566
|
/**
|
|
399
567
|
* Given a path, generate a URL appending root
|
|
400
568
|
* if pushState is used and # if hash state is used
|
|
401
569
|
*/
|
|
402
|
-
formatURL(
|
|
570
|
+
formatURL(path) {
|
|
403
571
|
if (this.locationBar.hasPushState()) {
|
|
404
|
-
let
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
572
|
+
let rootURL = this.options.root;
|
|
573
|
+
if (path !== "") {
|
|
574
|
+
rootURL = rootURL.replace(/\/$/, "");
|
|
575
|
+
}
|
|
576
|
+
return rootURL + path;
|
|
577
|
+
} else {
|
|
578
|
+
if (path[0] === "/") {
|
|
579
|
+
path = path.substr(1);
|
|
580
|
+
}
|
|
581
|
+
return `#${path}`;
|
|
582
|
+
}
|
|
408
583
|
}
|
|
409
584
|
/**
|
|
410
585
|
* When we use pushState with a custom root option,
|
|
@@ -414,8 +589,12 @@ class xt {
|
|
|
414
589
|
* - LocationBar expects all .update() calls to be called without root
|
|
415
590
|
* - this method is public so that we could dispatch URLs without root in router
|
|
416
591
|
*/
|
|
417
|
-
removeRoot(
|
|
418
|
-
|
|
592
|
+
removeRoot(url) {
|
|
593
|
+
if (this.options.pushState && this.options.root && this.options.root !== "/") {
|
|
594
|
+
return url.replace(this.options.root, "");
|
|
595
|
+
} else {
|
|
596
|
+
return url;
|
|
597
|
+
}
|
|
419
598
|
}
|
|
420
599
|
/**
|
|
421
600
|
* Stop listening to URL changes and link clicks
|
|
@@ -432,182 +611,298 @@ class xt {
|
|
|
432
611
|
|
|
433
612
|
@private
|
|
434
613
|
*/
|
|
435
|
-
handleURL(
|
|
436
|
-
this.path =
|
|
614
|
+
handleURL(url) {
|
|
615
|
+
this.path = url;
|
|
616
|
+
if (this.changeCallback) {
|
|
617
|
+
this.changeCallback(url);
|
|
618
|
+
}
|
|
437
619
|
}
|
|
438
620
|
}
|
|
439
|
-
class
|
|
440
|
-
constructor({ path
|
|
441
|
-
this.path =
|
|
621
|
+
class MemoryLocation {
|
|
622
|
+
constructor({ path }) {
|
|
623
|
+
this.path = path || "";
|
|
442
624
|
}
|
|
443
625
|
getURL() {
|
|
444
626
|
return this.path;
|
|
445
627
|
}
|
|
446
|
-
setURL(
|
|
447
|
-
this.path !==
|
|
628
|
+
setURL(path, options) {
|
|
629
|
+
if (this.path !== path) {
|
|
630
|
+
this.path = path;
|
|
631
|
+
this.handleURL(this.getURL(), options);
|
|
632
|
+
}
|
|
448
633
|
}
|
|
449
|
-
replaceURL(
|
|
450
|
-
this.path !==
|
|
634
|
+
replaceURL(path, options) {
|
|
635
|
+
if (this.path !== path) {
|
|
636
|
+
this.setURL(path, options);
|
|
637
|
+
}
|
|
451
638
|
}
|
|
452
|
-
onChange(
|
|
453
|
-
this.changeCallback =
|
|
639
|
+
onChange(callback) {
|
|
640
|
+
this.changeCallback = callback;
|
|
454
641
|
}
|
|
455
|
-
handleURL(
|
|
456
|
-
this.path =
|
|
642
|
+
handleURL(url, options = {}) {
|
|
643
|
+
this.path = url;
|
|
644
|
+
options = extend({ trigger: true }, options);
|
|
645
|
+
if (this.changeCallback && options.trigger) {
|
|
646
|
+
this.changeCallback(url);
|
|
647
|
+
}
|
|
457
648
|
}
|
|
458
|
-
removeRoot(
|
|
459
|
-
return
|
|
649
|
+
removeRoot(url) {
|
|
650
|
+
return url;
|
|
460
651
|
}
|
|
461
|
-
formatURL(
|
|
462
|
-
return
|
|
652
|
+
formatURL(url) {
|
|
653
|
+
return url;
|
|
463
654
|
}
|
|
464
655
|
}
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
656
|
+
const TRANSITION_REDIRECTED = "TransitionRedirected";
|
|
657
|
+
const TRANSITION_CANCELLED = "TransitionCancelled";
|
|
658
|
+
function runError(router2, transition2, err) {
|
|
659
|
+
router2.middleware.forEach((m) => {
|
|
660
|
+
m.error && m.error(transition2, err);
|
|
469
661
|
});
|
|
470
662
|
}
|
|
471
|
-
function
|
|
472
|
-
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
|
|
663
|
+
function transition(options) {
|
|
664
|
+
options = options || {};
|
|
665
|
+
const router2 = options.router;
|
|
666
|
+
const log = router2.log;
|
|
667
|
+
const logError = router2.logError;
|
|
668
|
+
const path = options.path;
|
|
669
|
+
const match = options.match;
|
|
670
|
+
const routes = match.routes;
|
|
671
|
+
const params = match.params;
|
|
672
|
+
const pathname = match.pathname;
|
|
673
|
+
const query = match.query;
|
|
674
|
+
const id = options.id;
|
|
675
|
+
const startTime = Date.now();
|
|
676
|
+
log("---");
|
|
677
|
+
log("Transition #" + id, "to", path);
|
|
678
|
+
log("Transition #" + id, "routes:", routes.map((r) => r.name));
|
|
679
|
+
log("Transition #" + id, "params:", params);
|
|
680
|
+
log("Transition #" + id, "query:", query);
|
|
681
|
+
let resolve2, reject;
|
|
682
|
+
const promise = new Promise(function(res, rej) {
|
|
683
|
+
resolve2 = res;
|
|
684
|
+
reject = rej;
|
|
478
685
|
});
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}).catch(function(
|
|
482
|
-
|
|
686
|
+
promise.then(function() {
|
|
687
|
+
log("Transition #" + id, "completed in", Date.now() - startTime + "ms");
|
|
688
|
+
}).catch(function(err) {
|
|
689
|
+
if (err.type !== TRANSITION_REDIRECTED && err.type !== TRANSITION_CANCELLED) {
|
|
690
|
+
log("Transition #" + id, "FAILED");
|
|
691
|
+
logError(err);
|
|
692
|
+
}
|
|
483
693
|
});
|
|
484
|
-
let
|
|
485
|
-
const
|
|
486
|
-
id
|
|
694
|
+
let cancelled = false;
|
|
695
|
+
const transition2 = {
|
|
696
|
+
id,
|
|
487
697
|
prev: {
|
|
488
|
-
routes:
|
|
489
|
-
path:
|
|
490
|
-
pathname:
|
|
491
|
-
params:
|
|
492
|
-
query:
|
|
698
|
+
routes: clone(router2.state.routes) || [],
|
|
699
|
+
path: router2.state.path || "",
|
|
700
|
+
pathname: router2.state.pathname || "",
|
|
701
|
+
params: clone(router2.state.params) || {},
|
|
702
|
+
query: clone(router2.state.query) || {}
|
|
493
703
|
},
|
|
494
|
-
routes:
|
|
495
|
-
path
|
|
496
|
-
pathname
|
|
497
|
-
params:
|
|
498
|
-
query:
|
|
499
|
-
redirectTo: function(...
|
|
500
|
-
return
|
|
704
|
+
routes: clone(routes),
|
|
705
|
+
path,
|
|
706
|
+
pathname,
|
|
707
|
+
params: clone(params),
|
|
708
|
+
query: clone(query),
|
|
709
|
+
redirectTo: function(...args) {
|
|
710
|
+
return router2.transitionTo(...args);
|
|
501
711
|
},
|
|
502
712
|
retry: function() {
|
|
503
|
-
return
|
|
713
|
+
return router2.transitionTo(path);
|
|
504
714
|
},
|
|
505
|
-
cancel: function(
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
715
|
+
cancel: function(err) {
|
|
716
|
+
if (router2.state.activeTransition !== transition2) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (transition2.isCancelled) {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
router2.state.activeTransition = null;
|
|
723
|
+
transition2.isCancelled = true;
|
|
724
|
+
cancelled = true;
|
|
725
|
+
if (!err) {
|
|
726
|
+
err = new Error(TRANSITION_CANCELLED);
|
|
727
|
+
err.type = TRANSITION_CANCELLED;
|
|
728
|
+
}
|
|
729
|
+
if (err.type === TRANSITION_CANCELLED) {
|
|
730
|
+
log("Transition #" + id, "cancelled");
|
|
731
|
+
}
|
|
732
|
+
if (err.type === TRANSITION_REDIRECTED) {
|
|
733
|
+
log("Transition #" + id, "redirected");
|
|
734
|
+
}
|
|
735
|
+
router2.middleware.forEach((m) => {
|
|
736
|
+
m.cancel && m.cancel(transition2, err);
|
|
737
|
+
});
|
|
738
|
+
reject(err);
|
|
509
739
|
},
|
|
510
740
|
followRedirects: function() {
|
|
511
|
-
return
|
|
512
|
-
|
|
741
|
+
return promise.catch(function(reason) {
|
|
742
|
+
if (router2.state.activeTransition) {
|
|
743
|
+
return router2.state.activeTransition.followRedirects();
|
|
744
|
+
}
|
|
745
|
+
return Promise.reject(reason);
|
|
513
746
|
});
|
|
514
747
|
},
|
|
515
|
-
then:
|
|
516
|
-
catch:
|
|
748
|
+
then: promise.then.bind(promise),
|
|
749
|
+
catch: promise.catch.bind(promise)
|
|
517
750
|
};
|
|
518
|
-
|
|
519
|
-
|
|
751
|
+
router2.middleware.forEach((m) => {
|
|
752
|
+
m.before && m.before(transition2);
|
|
520
753
|
});
|
|
521
|
-
function
|
|
522
|
-
let
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
754
|
+
function callNext(i, prevResult) {
|
|
755
|
+
let middleware;
|
|
756
|
+
let middlewareName;
|
|
757
|
+
if (cancelled) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if (i < router2.middleware.length) {
|
|
761
|
+
middleware = router2.middleware[i];
|
|
762
|
+
middlewareName = middleware.name || "anonymous";
|
|
763
|
+
log("Transition #" + id, "resolving middleware:", middlewareName);
|
|
764
|
+
let middlewarePromise;
|
|
765
|
+
try {
|
|
766
|
+
middlewarePromise = middleware.resolve ? middleware.resolve(transition2, prevResult) : prevResult;
|
|
767
|
+
invariant(transition2 !== middlewarePromise, "Middleware %s returned a transition which resulted in a deadlock", middlewareName);
|
|
768
|
+
} catch (err) {
|
|
769
|
+
router2.state.activeTransition = null;
|
|
770
|
+
runError(router2, transition2, err);
|
|
771
|
+
return reject(err);
|
|
772
|
+
}
|
|
773
|
+
Promise.resolve(middlewarePromise).then(function(result) {
|
|
774
|
+
callNext(i + 1, result);
|
|
775
|
+
}).catch(function(err) {
|
|
776
|
+
log("Transition #" + id, "resolving middleware:", middlewareName, "FAILED");
|
|
777
|
+
router2.state.activeTransition = null;
|
|
778
|
+
runError(router2, transition2, err);
|
|
779
|
+
reject(err);
|
|
780
|
+
});
|
|
781
|
+
} else {
|
|
782
|
+
router2.state = {
|
|
783
|
+
activeTransition: null,
|
|
784
|
+
routes,
|
|
785
|
+
path,
|
|
786
|
+
pathname,
|
|
787
|
+
params,
|
|
788
|
+
query
|
|
789
|
+
};
|
|
790
|
+
router2.middleware.forEach((m) => {
|
|
791
|
+
m.done && m.done(transition2);
|
|
792
|
+
});
|
|
793
|
+
resolve2();
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (!options.noop) {
|
|
797
|
+
Promise.resolve().then(() => callNext(0));
|
|
798
|
+
} else {
|
|
799
|
+
resolve2();
|
|
800
|
+
}
|
|
801
|
+
if (options.noop) {
|
|
802
|
+
transition2.noop = true;
|
|
803
|
+
}
|
|
804
|
+
return transition2;
|
|
550
805
|
}
|
|
551
|
-
function
|
|
552
|
-
const
|
|
553
|
-
|
|
806
|
+
function intercept(el, fn) {
|
|
807
|
+
const cb = delegate(el, "click", function(e, el2) {
|
|
808
|
+
if (clickable(e, el2))
|
|
809
|
+
fn(e, el2);
|
|
554
810
|
});
|
|
555
|
-
return function() {
|
|
556
|
-
|
|
811
|
+
return function dispose() {
|
|
812
|
+
undelegate(el, "click", cb);
|
|
557
813
|
};
|
|
558
814
|
}
|
|
559
|
-
function
|
|
560
|
-
var
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
if (((
|
|
565
|
-
return
|
|
566
|
-
|
|
815
|
+
function link(element) {
|
|
816
|
+
var _a;
|
|
817
|
+
element = { parentNode: element };
|
|
818
|
+
const root = document;
|
|
819
|
+
while ((element = element.parentNode) && element !== document) {
|
|
820
|
+
if (((_a = element.tagName) == null ? void 0 : _a.toLowerCase()) === "a") {
|
|
821
|
+
return element;
|
|
822
|
+
}
|
|
823
|
+
if (element === root) {
|
|
567
824
|
return;
|
|
825
|
+
}
|
|
568
826
|
}
|
|
569
827
|
}
|
|
570
|
-
function
|
|
571
|
-
return
|
|
572
|
-
const
|
|
573
|
-
|
|
828
|
+
function delegate(el, type, fn) {
|
|
829
|
+
return bindEvent(el, type, function(e) {
|
|
830
|
+
const target = e.target || e.srcElement;
|
|
831
|
+
const el2 = link(target);
|
|
832
|
+
if (el2) {
|
|
833
|
+
fn(e, el2);
|
|
834
|
+
}
|
|
574
835
|
});
|
|
575
836
|
}
|
|
576
|
-
function
|
|
577
|
-
|
|
837
|
+
function undelegate(el, type, fn) {
|
|
838
|
+
unbindEvent(el, type, fn);
|
|
578
839
|
}
|
|
579
|
-
function
|
|
580
|
-
if (
|
|
840
|
+
function clickable(e, el) {
|
|
841
|
+
if (which(e) !== 1)
|
|
581
842
|
return;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
843
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey)
|
|
844
|
+
return;
|
|
845
|
+
if (e.defaultPrevented)
|
|
846
|
+
return;
|
|
847
|
+
if (el.target)
|
|
848
|
+
return;
|
|
849
|
+
if (el.getAttribute("data-bypass") !== null)
|
|
850
|
+
return;
|
|
851
|
+
const href = el.getAttribute("href");
|
|
852
|
+
if (!href || href.length === 0)
|
|
853
|
+
return;
|
|
854
|
+
if (href[0] === "#")
|
|
855
|
+
return;
|
|
856
|
+
if (href.indexOf("http://") === 0 || href.indexOf("https://") === 0)
|
|
857
|
+
return;
|
|
858
|
+
if (href.indexOf("mailto:") === 0)
|
|
859
|
+
return;
|
|
860
|
+
if (href.indexOf("javascript:") === 0)
|
|
861
|
+
return;
|
|
862
|
+
return true;
|
|
585
863
|
}
|
|
586
|
-
function
|
|
587
|
-
|
|
864
|
+
function which(e) {
|
|
865
|
+
e = e || window.event;
|
|
866
|
+
return e.which === null ? e.button : e.which;
|
|
588
867
|
}
|
|
589
|
-
function
|
|
590
|
-
|
|
591
|
-
|
|
868
|
+
function defineLogger(router2, method, fn) {
|
|
869
|
+
if (fn === true)
|
|
870
|
+
return;
|
|
871
|
+
router2[method] = typeof fn === "function" ? fn : () => {
|
|
872
|
+
};
|
|
592
873
|
}
|
|
593
|
-
var
|
|
594
|
-
parse(
|
|
595
|
-
return
|
|
596
|
-
const
|
|
597
|
-
|
|
874
|
+
var qs = {
|
|
875
|
+
parse(querystring) {
|
|
876
|
+
return querystring.split("&").reduce((acc, pair) => {
|
|
877
|
+
const parts = pair.split("=");
|
|
878
|
+
acc[parts[0]] = decodeURIComponent(parts[1]);
|
|
879
|
+
return acc;
|
|
598
880
|
}, {});
|
|
599
881
|
},
|
|
600
|
-
stringify(
|
|
601
|
-
return Object.keys(
|
|
882
|
+
stringify(params) {
|
|
883
|
+
return Object.keys(params).reduce((acc, key) => {
|
|
884
|
+
if (params[key] !== void 0) {
|
|
885
|
+
acc.push(key + "=" + encodeURIComponent(params[key]));
|
|
886
|
+
}
|
|
887
|
+
return acc;
|
|
888
|
+
}, []).join("&");
|
|
602
889
|
}
|
|
603
890
|
};
|
|
604
|
-
class
|
|
605
|
-
constructor(
|
|
606
|
-
this.nextId = 1
|
|
891
|
+
class Router {
|
|
892
|
+
constructor(options = {}) {
|
|
893
|
+
this.nextId = 1;
|
|
894
|
+
this.state = {};
|
|
895
|
+
this.middleware = [];
|
|
896
|
+
this.options = extend({
|
|
607
897
|
location: "browser",
|
|
608
|
-
logError:
|
|
609
|
-
qs
|
|
610
|
-
},
|
|
898
|
+
logError: true,
|
|
899
|
+
qs
|
|
900
|
+
}, options);
|
|
901
|
+
defineLogger(this, "log", this.options.log);
|
|
902
|
+
defineLogger(this, "logError", this.options.logError);
|
|
903
|
+
if (options.routes) {
|
|
904
|
+
this.map(options.routes);
|
|
905
|
+
}
|
|
611
906
|
}
|
|
612
907
|
/**
|
|
613
908
|
* Add a middleware
|
|
@@ -615,9 +910,11 @@ class Mt {
|
|
|
615
910
|
* @return {Object} router
|
|
616
911
|
* @api public
|
|
617
912
|
*/
|
|
618
|
-
use(
|
|
619
|
-
const
|
|
620
|
-
|
|
913
|
+
use(middleware, options = {}) {
|
|
914
|
+
const m = typeof middleware === "function" ? { resolve: middleware } : middleware;
|
|
915
|
+
typeof options.at === "number" ? this.middleware.splice(options.at, 0, m) : this.middleware.push(m);
|
|
916
|
+
m.create && m.create(this);
|
|
917
|
+
return this;
|
|
621
918
|
}
|
|
622
919
|
/**
|
|
623
920
|
* Add the route map
|
|
@@ -625,43 +922,59 @@ class Mt {
|
|
|
625
922
|
* @return {Object} router
|
|
626
923
|
* @api public
|
|
627
924
|
*/
|
|
628
|
-
map(
|
|
629
|
-
this.routes = Array.isArray(
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
925
|
+
map(routes) {
|
|
926
|
+
this.routes = Array.isArray(routes) ? arrayDsl(routes) : functionDsl(routes);
|
|
927
|
+
const matchers = this.matchers = [];
|
|
928
|
+
const dupes = {};
|
|
929
|
+
const abstracts = {};
|
|
930
|
+
eachBranch({ routes: this.routes }, [], (routes2) => {
|
|
931
|
+
let path = routes2.reduce((memo, r) => (
|
|
633
932
|
// reset if there's a leading slash, otherwise concat
|
|
634
933
|
// and keep resetting the trailing slash
|
|
635
|
-
(
|
|
934
|
+
(r.path[0] === "/" ? r.path : `${memo}/${r.path}`).replace(/\/$/, "")
|
|
636
935
|
), "");
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
936
|
+
if (path === "") {
|
|
937
|
+
path = "/";
|
|
938
|
+
}
|
|
939
|
+
const lastRoute = routes2[routes2.length - 1];
|
|
940
|
+
if (lastRoute.options.abstract) {
|
|
941
|
+
abstracts[path] = lastRoute.name;
|
|
641
942
|
return;
|
|
642
943
|
}
|
|
643
|
-
if (
|
|
644
|
-
let
|
|
645
|
-
|
|
646
|
-
if (
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
name: i[o],
|
|
651
|
-
path: o
|
|
944
|
+
if (lastRoute.path === "") {
|
|
945
|
+
let matcher;
|
|
946
|
+
matchers.some((m) => {
|
|
947
|
+
if (m.path === path) {
|
|
948
|
+
matcher = m;
|
|
949
|
+
return true;
|
|
950
|
+
}
|
|
652
951
|
});
|
|
952
|
+
if (matcher) {
|
|
953
|
+
matcher.routes = routes2;
|
|
954
|
+
} else if (abstracts[path]) {
|
|
955
|
+
matchers.push({
|
|
956
|
+
routes: routes2,
|
|
957
|
+
name: abstracts[path],
|
|
958
|
+
path
|
|
959
|
+
});
|
|
960
|
+
}
|
|
653
961
|
}
|
|
654
|
-
|
|
655
|
-
routes:
|
|
656
|
-
name:
|
|
657
|
-
path
|
|
658
|
-
})
|
|
659
|
-
|
|
660
|
-
|
|
962
|
+
matchers.push({
|
|
963
|
+
routes: routes2,
|
|
964
|
+
name: lastRoute.name,
|
|
965
|
+
path
|
|
966
|
+
});
|
|
967
|
+
if (dupes[path] && lastRoute.path !== "") {
|
|
968
|
+
throw new Error(`Routes ${dupes[path]} and ${lastRoute.name} have the same url path '${path}'`);
|
|
969
|
+
}
|
|
970
|
+
dupes[path] = lastRoute.name;
|
|
661
971
|
});
|
|
662
|
-
function
|
|
663
|
-
|
|
664
|
-
|
|
972
|
+
function eachBranch(node, memo, fn) {
|
|
973
|
+
node.routes.forEach((route) => {
|
|
974
|
+
fn(memo.concat(route));
|
|
975
|
+
if (route.routes.length) {
|
|
976
|
+
eachBranch(route, memo.concat(route), fn);
|
|
977
|
+
}
|
|
665
978
|
});
|
|
666
979
|
}
|
|
667
980
|
return this;
|
|
@@ -673,12 +986,18 @@ class Mt {
|
|
|
673
986
|
*
|
|
674
987
|
* @api public
|
|
675
988
|
*/
|
|
676
|
-
listen(
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
const
|
|
680
|
-
this.dispatch(
|
|
681
|
-
|
|
989
|
+
listen(path) {
|
|
990
|
+
const location = this.location = this.createLocation(path || "");
|
|
991
|
+
location.onChange((url) => {
|
|
992
|
+
const previousUrl = this.state.path;
|
|
993
|
+
this.dispatch(url).catch((err) => {
|
|
994
|
+
if (err && err.type === TRANSITION_CANCELLED) {
|
|
995
|
+
this.location.replaceURL(previousUrl, { trigger: false });
|
|
996
|
+
}
|
|
997
|
+
return err;
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
return this.dispatch(location.getURL());
|
|
682
1001
|
}
|
|
683
1002
|
/**
|
|
684
1003
|
* Transition to a different route. Passe in url or a route name followed by params and query
|
|
@@ -689,8 +1008,11 @@ class Mt {
|
|
|
689
1008
|
*
|
|
690
1009
|
* @api public
|
|
691
1010
|
*/
|
|
692
|
-
transitionTo(
|
|
693
|
-
|
|
1011
|
+
transitionTo(name, params, query) {
|
|
1012
|
+
if (this.state.activeTransition) {
|
|
1013
|
+
return this.replaceWith(name, params, query);
|
|
1014
|
+
}
|
|
1015
|
+
return this.doTransition("setURL", name, params, query);
|
|
694
1016
|
}
|
|
695
1017
|
/**
|
|
696
1018
|
* Like transitionTo, but doesn't leave an entry in the browser's history,
|
|
@@ -702,8 +1024,8 @@ class Mt {
|
|
|
702
1024
|
*
|
|
703
1025
|
* @api public
|
|
704
1026
|
*/
|
|
705
|
-
replaceWith(
|
|
706
|
-
return this.doTransition("replaceURL",
|
|
1027
|
+
replaceWith(name, params, query) {
|
|
1028
|
+
return this.doTransition("replaceURL", name, params, query);
|
|
707
1029
|
}
|
|
708
1030
|
/**
|
|
709
1031
|
* Create an href
|
|
@@ -714,23 +1036,35 @@ class Mt {
|
|
|
714
1036
|
*
|
|
715
1037
|
* @api public
|
|
716
1038
|
*/
|
|
717
|
-
generate(
|
|
718
|
-
|
|
719
|
-
let
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
1039
|
+
generate(name, params, query) {
|
|
1040
|
+
invariant(this.location, "call .listen() before using .generate()");
|
|
1041
|
+
let matcher;
|
|
1042
|
+
query = query || {};
|
|
1043
|
+
this.matchers.forEach((m) => {
|
|
1044
|
+
if (m.name === name) {
|
|
1045
|
+
matcher = m;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
if (!matcher) {
|
|
1049
|
+
throw new Error(`No route is named ${name}`);
|
|
1050
|
+
}
|
|
1051
|
+
const url = withQuery(this.options.qs, injectParams(matcher.path, params), query);
|
|
1052
|
+
return this.location.formatURL(url);
|
|
726
1053
|
}
|
|
727
1054
|
/**
|
|
728
1055
|
* Stop listening to URL changes
|
|
729
1056
|
* @api public
|
|
730
1057
|
*/
|
|
731
1058
|
destroy() {
|
|
732
|
-
|
|
733
|
-
|
|
1059
|
+
if (this.location && this.location.destroy) {
|
|
1060
|
+
this.location.destroy();
|
|
1061
|
+
}
|
|
1062
|
+
if (this.state.activeTransition) {
|
|
1063
|
+
this.state.activeTransition.cancel();
|
|
1064
|
+
}
|
|
1065
|
+
this.state = {};
|
|
1066
|
+
this.middleware.forEach((m) => {
|
|
1067
|
+
m.destroy && m.destroy(this);
|
|
734
1068
|
});
|
|
735
1069
|
}
|
|
736
1070
|
/**
|
|
@@ -742,20 +1076,37 @@ class Mt {
|
|
|
742
1076
|
*
|
|
743
1077
|
* @api public
|
|
744
1078
|
*/
|
|
745
|
-
isActive(
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
1079
|
+
isActive(name, params, query, exact) {
|
|
1080
|
+
const activeRoutes = this.state.routes || [];
|
|
1081
|
+
const activeParams = this.state.params;
|
|
1082
|
+
const activeQuery = this.state.query;
|
|
1083
|
+
let isActive = activeRoutes.some((route) => route.name === name) && (!exact || activeRoutes[activeRoutes.length - 1].name === name);
|
|
1084
|
+
isActive = isActive && (!params || keys(params).every((key) => activeParams[key] === params[key]));
|
|
1085
|
+
isActive = isActive && (!query || keys(query).every((key) => activeQuery[key] === query[key]));
|
|
1086
|
+
return isActive;
|
|
749
1087
|
}
|
|
750
1088
|
/**
|
|
751
1089
|
* @api private
|
|
752
1090
|
*/
|
|
753
|
-
doTransition(
|
|
754
|
-
const
|
|
755
|
-
let
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1091
|
+
doTransition(method, name, params, query) {
|
|
1092
|
+
const previousUrl = this.location.getURL();
|
|
1093
|
+
let url = name;
|
|
1094
|
+
if (url[0] !== "/") {
|
|
1095
|
+
url = this.generate(name, params, query);
|
|
1096
|
+
url = url.replace(/^#/, "/");
|
|
1097
|
+
}
|
|
1098
|
+
if (this.options.pushState) {
|
|
1099
|
+
url = this.location.removeRoot(url);
|
|
1100
|
+
}
|
|
1101
|
+
const transition2 = this.dispatch(url);
|
|
1102
|
+
transition2.catch((err) => {
|
|
1103
|
+
if (err && err.type === TRANSITION_CANCELLED) {
|
|
1104
|
+
this.location.replaceURL(previousUrl, { trigger: false });
|
|
1105
|
+
}
|
|
1106
|
+
return err;
|
|
1107
|
+
});
|
|
1108
|
+
this.location[method](url, { trigger: false });
|
|
1109
|
+
return transition2;
|
|
759
1110
|
}
|
|
760
1111
|
/**
|
|
761
1112
|
* Match the path against the routes
|
|
@@ -764,51 +1115,67 @@ class Mt {
|
|
|
764
1115
|
*
|
|
765
1116
|
* @api private
|
|
766
1117
|
*/
|
|
767
|
-
match(
|
|
768
|
-
|
|
769
|
-
let
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
1118
|
+
match(path) {
|
|
1119
|
+
path = (path || "").replace(/\/$/, "") || "/";
|
|
1120
|
+
let params;
|
|
1121
|
+
let routes = [];
|
|
1122
|
+
const pathWithoutQuery = withoutQuery(path);
|
|
1123
|
+
const qs2 = this.options.qs;
|
|
1124
|
+
this.matchers.some((matcher) => {
|
|
1125
|
+
params = extractParams(matcher.path, pathWithoutQuery);
|
|
1126
|
+
if (params) {
|
|
1127
|
+
routes = matcher.routes;
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
return {
|
|
1132
|
+
routes: routes.map(descriptor),
|
|
1133
|
+
params: params || {},
|
|
1134
|
+
pathname: pathWithoutQuery,
|
|
1135
|
+
query: extractQuery(qs2, path) || {}
|
|
779
1136
|
};
|
|
780
|
-
function
|
|
1137
|
+
function descriptor(route) {
|
|
781
1138
|
return {
|
|
782
|
-
name:
|
|
783
|
-
path:
|
|
784
|
-
params:
|
|
785
|
-
options:
|
|
1139
|
+
name: route.name,
|
|
1140
|
+
path: route.path,
|
|
1141
|
+
params: pick(params, extractParamNames(route.path)),
|
|
1142
|
+
options: clone(route.options)
|
|
786
1143
|
};
|
|
787
1144
|
}
|
|
788
1145
|
}
|
|
789
|
-
dispatch(
|
|
790
|
-
const
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
if (
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1146
|
+
dispatch(path) {
|
|
1147
|
+
const match = this.match(path);
|
|
1148
|
+
const query = match.query;
|
|
1149
|
+
const pathname = match.pathname;
|
|
1150
|
+
const activeTransition = this.state.activeTransition;
|
|
1151
|
+
if (activeTransition && activeTransition.pathname === pathname && isEqual$1(activeTransition.query, query)) {
|
|
1152
|
+
return activeTransition;
|
|
1153
|
+
}
|
|
1154
|
+
if (activeTransition) {
|
|
1155
|
+
const err = new Error(TRANSITION_REDIRECTED);
|
|
1156
|
+
err.type = TRANSITION_REDIRECTED;
|
|
1157
|
+
err.nextPath = path;
|
|
1158
|
+
activeTransition.cancel(err);
|
|
1159
|
+
}
|
|
1160
|
+
if (!activeTransition) {
|
|
1161
|
+
if (this.state.pathname === pathname && isEqual$1(this.state.query, query)) {
|
|
1162
|
+
return transition({
|
|
1163
|
+
id: this.nextId++,
|
|
1164
|
+
path,
|
|
1165
|
+
match,
|
|
1166
|
+
noop: true,
|
|
1167
|
+
router: this
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
const t = transition({
|
|
806
1172
|
id: this.nextId++,
|
|
807
|
-
path
|
|
808
|
-
match
|
|
1173
|
+
path,
|
|
1174
|
+
match,
|
|
809
1175
|
router: this
|
|
810
1176
|
});
|
|
811
|
-
|
|
1177
|
+
this.state.activeTransition = t;
|
|
1178
|
+
return t;
|
|
812
1179
|
}
|
|
813
1180
|
/**
|
|
814
1181
|
* Create the default location.
|
|
@@ -818,198 +1185,284 @@ class Mt {
|
|
|
818
1185
|
*
|
|
819
1186
|
* @api private
|
|
820
1187
|
*/
|
|
821
|
-
createLocation(
|
|
822
|
-
const
|
|
823
|
-
if (typeof
|
|
824
|
-
return
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
console.
|
|
1188
|
+
createLocation(path) {
|
|
1189
|
+
const location = this.options.location;
|
|
1190
|
+
if (typeof location !== "string") {
|
|
1191
|
+
return location;
|
|
1192
|
+
}
|
|
1193
|
+
if (location === "browser") {
|
|
1194
|
+
return new BrowserLocation(pick(this.options, ["pushState", "root"]));
|
|
1195
|
+
} else if (location === "memory") {
|
|
1196
|
+
return new MemoryLocation({ path });
|
|
1197
|
+
} else {
|
|
1198
|
+
throw new Error("Location can be `browser`, `memory` or a custom implementation");
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
log(...args) {
|
|
1202
|
+
console.info(...args);
|
|
1203
|
+
}
|
|
1204
|
+
logError(...args) {
|
|
1205
|
+
console.error(...args);
|
|
836
1206
|
}
|
|
837
1207
|
}
|
|
838
|
-
function
|
|
839
|
-
!
|
|
1208
|
+
function defaultClickHandler(event, link2, router2) {
|
|
1209
|
+
if (!link2.hasAttribute("download") && !link2.hasAttribute("data-phone-number")) {
|
|
1210
|
+
event.preventDefault();
|
|
1211
|
+
router2.transitionTo(router2.location.removeRoot(link2.getAttribute("href")));
|
|
1212
|
+
}
|
|
840
1213
|
}
|
|
841
|
-
function
|
|
842
|
-
return
|
|
1214
|
+
function interceptLinks(router2, el = document, clickHandler = defaultClickHandler) {
|
|
1215
|
+
return intercept(el, (event, link2) => clickHandler(event, link2, router2));
|
|
843
1216
|
}
|
|
844
|
-
const
|
|
845
|
-
let
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1217
|
+
const resolved = Promise.resolve();
|
|
1218
|
+
let routeElMap = /* @__PURE__ */ Object.create(null);
|
|
1219
|
+
let routeComponentMap = /* @__PURE__ */ Object.create(null);
|
|
1220
|
+
let router, rootOutlet, rootOutletEl;
|
|
1221
|
+
function parseNumber(value) {
|
|
1222
|
+
const n = parseFloat(value);
|
|
1223
|
+
const isNumeric = value == n;
|
|
1224
|
+
return isNumeric ? n : value;
|
|
849
1225
|
}
|
|
850
|
-
class
|
|
851
|
-
constructor(
|
|
852
|
-
this.key =
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1226
|
+
class TransitionValue {
|
|
1227
|
+
constructor(key, format) {
|
|
1228
|
+
this.key = key;
|
|
1229
|
+
this.format = format;
|
|
1230
|
+
}
|
|
1231
|
+
value(transition2) {
|
|
1232
|
+
let result = this.getValue(transition2);
|
|
1233
|
+
if (result !== void 0) {
|
|
1234
|
+
const format = this.format;
|
|
1235
|
+
if (format === "number") {
|
|
1236
|
+
result = parseNumber(result);
|
|
1237
|
+
} else if (typeof format === "function") {
|
|
1238
|
+
result = format(result);
|
|
1239
|
+
}
|
|
859
1240
|
}
|
|
860
|
-
return
|
|
1241
|
+
return result;
|
|
861
1242
|
}
|
|
862
1243
|
}
|
|
863
|
-
function
|
|
864
|
-
|
|
1244
|
+
function create(instance) {
|
|
1245
|
+
router = instance;
|
|
1246
|
+
rootOutlet = instance.options.outlet;
|
|
865
1247
|
}
|
|
866
|
-
function
|
|
867
|
-
|
|
1248
|
+
function destroy() {
|
|
1249
|
+
router = null;
|
|
1250
|
+
routeElMap = /* @__PURE__ */ Object.create(null);
|
|
1251
|
+
routeComponentMap = /* @__PURE__ */ Object.create(null);
|
|
1252
|
+
rootOutletEl = null;
|
|
868
1253
|
}
|
|
869
|
-
function
|
|
870
|
-
const
|
|
871
|
-
return
|
|
1254
|
+
function isEqual(obj1, obj2) {
|
|
1255
|
+
const keys1 = Object.keys(obj1);
|
|
1256
|
+
return keys1.length === Object.keys(obj2).length && keys1.every((key) => obj2[key] === obj1[key]);
|
|
872
1257
|
}
|
|
873
|
-
function
|
|
874
|
-
|
|
1258
|
+
function getOutlet(el) {
|
|
1259
|
+
const renderRoot = el.shadowRoot || el;
|
|
1260
|
+
return renderRoot.querySelector(el.constructor.outlet || "wj-router-outlet");
|
|
875
1261
|
}
|
|
876
|
-
function
|
|
877
|
-
if (
|
|
878
|
-
return
|
|
879
|
-
if (!
|
|
1262
|
+
function resolveRootOutlet() {
|
|
1263
|
+
if (rootOutletEl)
|
|
1264
|
+
return rootOutletEl;
|
|
1265
|
+
if (!rootOutlet)
|
|
880
1266
|
return document.body;
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1267
|
+
rootOutletEl = typeof rootOutlet === "string" ? document.querySelector(rootOutlet) : rootOutlet;
|
|
1268
|
+
if (!rootOutletEl) {
|
|
1269
|
+
throw new Error(`slick-router(wc): Invalid outlet option ${rootOutlet}`);
|
|
1270
|
+
}
|
|
1271
|
+
return rootOutletEl;
|
|
884
1272
|
}
|
|
885
|
-
function
|
|
886
|
-
let
|
|
887
|
-
|
|
888
|
-
if (
|
|
889
|
-
return
|
|
890
|
-
|
|
1273
|
+
function getParentEl(transition2, parentIndex) {
|
|
1274
|
+
let parent = transition2.routes[parentIndex];
|
|
1275
|
+
while (parent) {
|
|
1276
|
+
if (parent.options.component) {
|
|
1277
|
+
return routeElMap[parent.name];
|
|
1278
|
+
}
|
|
1279
|
+
parent = transition2.routes[--parentIndex];
|
|
891
1280
|
}
|
|
892
1281
|
}
|
|
893
|
-
function
|
|
894
|
-
let
|
|
895
|
-
const
|
|
896
|
-
for (
|
|
897
|
-
;
|
|
898
|
-
|
|
1282
|
+
function getChangingIndex(prevRoutes, currentRoutes) {
|
|
1283
|
+
let index, prev, current;
|
|
1284
|
+
const count = Math.max(prevRoutes.length, currentRoutes.length);
|
|
1285
|
+
for (index = 0; index < count; index++) {
|
|
1286
|
+
prev = prevRoutes[index];
|
|
1287
|
+
current = currentRoutes[index];
|
|
1288
|
+
if (!(prev && current) || prev.name !== current.name || !isEqual(prev.params, current.params)) {
|
|
1289
|
+
break;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return index;
|
|
899
1293
|
}
|
|
900
|
-
async function
|
|
901
|
-
for (let i = 0; i <
|
|
902
|
-
let
|
|
903
|
-
const { route
|
|
904
|
-
|
|
1294
|
+
async function runLifeCycle(transition2, routes, prefix, suffix) {
|
|
1295
|
+
for (let i = 0; i < routes.length; i++) {
|
|
1296
|
+
let result;
|
|
1297
|
+
const { route, el } = routes[i];
|
|
1298
|
+
const routeMethod = route.options[`${prefix}${suffix}`];
|
|
1299
|
+
if (typeof routeMethod === "function") {
|
|
1300
|
+
result = await routeMethod(transition2);
|
|
1301
|
+
if (result === false) {
|
|
1302
|
+
transition2.cancel();
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
if (transition2.isCancelled)
|
|
905
1306
|
break;
|
|
906
|
-
const
|
|
907
|
-
if (typeof
|
|
1307
|
+
const elMethod = el && el[`${prefix}Route${suffix}`];
|
|
1308
|
+
if (typeof elMethod === "function") {
|
|
1309
|
+
result = await elMethod.call(el, transition2);
|
|
1310
|
+
if (result === false) {
|
|
1311
|
+
transition2.cancel();
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
if (transition2.isCancelled)
|
|
908
1315
|
break;
|
|
909
1316
|
}
|
|
910
1317
|
}
|
|
911
|
-
function
|
|
912
|
-
return
|
|
1318
|
+
function resolveModule(value) {
|
|
1319
|
+
return value && value.__esModule ? value.default : value;
|
|
913
1320
|
}
|
|
914
|
-
async function
|
|
915
|
-
const
|
|
916
|
-
for (const
|
|
917
|
-
let
|
|
918
|
-
|
|
1321
|
+
async function resolveComponents(routes) {
|
|
1322
|
+
const result = [];
|
|
1323
|
+
for (const route of routes) {
|
|
1324
|
+
let el = route.options.reuse ? routeElMap[route.name] : void 0;
|
|
1325
|
+
let Component = route.options.component;
|
|
1326
|
+
if (!el && Component) {
|
|
1327
|
+
if (typeof Component === "function" && !(Component.prototype instanceof HTMLElement)) {
|
|
1328
|
+
Component = routeComponentMap[route.name] || (routeComponentMap[route.name] = resolveModule(await Component(route)));
|
|
1329
|
+
}
|
|
1330
|
+
el = typeof Component === "string" ? document.createElement(Component) : new Component();
|
|
1331
|
+
routeElMap[route.name] = el;
|
|
1332
|
+
el.$router = router;
|
|
1333
|
+
}
|
|
1334
|
+
result.push({ el, route });
|
|
919
1335
|
}
|
|
920
|
-
return
|
|
1336
|
+
return result;
|
|
921
1337
|
}
|
|
922
|
-
function
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1338
|
+
function applyProperties(transition2, el, properties) {
|
|
1339
|
+
if (properties) {
|
|
1340
|
+
Object.keys(properties).forEach((key) => {
|
|
1341
|
+
const value = properties[key];
|
|
1342
|
+
el[key] = value instanceof TransitionValue ? value.value(transition2) : value;
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
927
1345
|
}
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1346
|
+
const removedEls = /* @__PURE__ */ new WeakSet();
|
|
1347
|
+
const outletCurrentEl = /* @__PURE__ */ new WeakMap();
|
|
1348
|
+
async function renderElements(transition2, activated, changingIndex) {
|
|
1349
|
+
const { path, pathname, routes, params, query } = transition2;
|
|
1350
|
+
const routeState = { path, pathname, routes, params, query };
|
|
1351
|
+
for (let k = 0; k < changingIndex; k++) {
|
|
1352
|
+
const route = transition2.routes[k];
|
|
1353
|
+
const el = routeElMap[route.name];
|
|
1354
|
+
if (el) {
|
|
1355
|
+
el.$route = routeState;
|
|
1356
|
+
applyProperties(transition2, el, route.options.properties);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
for (let i = 0; i < activated.length; i++) {
|
|
1360
|
+
const { el, route } = activated[i];
|
|
1361
|
+
if (el) {
|
|
1362
|
+
const parentEl = getParentEl(transition2, changingIndex + i - 1);
|
|
1363
|
+
const outletEl = parentEl ? getOutlet(parentEl) : resolveRootOutlet();
|
|
1364
|
+
if (outletEl) {
|
|
1365
|
+
const currentEl = outletCurrentEl.get(outletEl) || outletEl.firstElementChild;
|
|
1366
|
+
if (currentEl) {
|
|
1367
|
+
outletEl.removeChild(currentEl);
|
|
1368
|
+
removedEls.add(currentEl);
|
|
1369
|
+
}
|
|
1370
|
+
el.$route = routeState;
|
|
1371
|
+
applyProperties(transition2, el, route.options.properties);
|
|
1372
|
+
outletEl.appendChild(el);
|
|
1373
|
+
outletCurrentEl.set(outletEl, el);
|
|
1374
|
+
await (el.updateComplete || resolved);
|
|
942
1375
|
}
|
|
943
1376
|
}
|
|
944
1377
|
}
|
|
945
1378
|
}
|
|
946
|
-
function
|
|
947
|
-
let
|
|
948
|
-
for (let
|
|
949
|
-
const { route
|
|
950
|
-
|
|
1379
|
+
function updateDOMTree(activated, deactivated) {
|
|
1380
|
+
let parentElRemoved;
|
|
1381
|
+
for (let routeIndex = deactivated.length - 1; routeIndex >= 0; routeIndex--) {
|
|
1382
|
+
const { route, el } = deactivated[routeIndex];
|
|
1383
|
+
if (!activated.some(({ route: activeRoute }) => activeRoute.name === route.name)) {
|
|
1384
|
+
if (el) {
|
|
1385
|
+
if (!parentElRemoved && !removedEls.has(el))
|
|
1386
|
+
el.remove();
|
|
1387
|
+
parentElRemoved = true;
|
|
1388
|
+
}
|
|
1389
|
+
routeElMap[route.name] = void 0;
|
|
1390
|
+
}
|
|
951
1391
|
}
|
|
952
1392
|
}
|
|
953
|
-
async function
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1393
|
+
async function resolve(transition2) {
|
|
1394
|
+
const prevRoutes = transition2.prev.routes;
|
|
1395
|
+
const changingIndex = getChangingIndex(prevRoutes, transition2.routes);
|
|
1396
|
+
const deactivated = [];
|
|
1397
|
+
for (let routeIndex = prevRoutes.length - 1; routeIndex >= changingIndex; routeIndex--) {
|
|
1398
|
+
const route = prevRoutes[routeIndex];
|
|
1399
|
+
deactivated.push({ el: routeElMap[route.name], route });
|
|
1400
|
+
}
|
|
1401
|
+
await runLifeCycle(transition2, deactivated, "before", "Leave");
|
|
1402
|
+
if (transition2.isCancelled)
|
|
960
1403
|
return;
|
|
961
|
-
const
|
|
962
|
-
await
|
|
1404
|
+
const activated = await resolveComponents(transition2.routes.slice(changingIndex));
|
|
1405
|
+
await runLifeCycle(transition2, activated, "before", "Enter");
|
|
1406
|
+
if (transition2.isCancelled)
|
|
1407
|
+
return;
|
|
1408
|
+
await renderElements(transition2, activated, changingIndex);
|
|
1409
|
+
updateDOMTree(activated, deactivated);
|
|
1410
|
+
transition2.activated = activated;
|
|
1411
|
+
transition2.deactivated = deactivated;
|
|
963
1412
|
}
|
|
964
|
-
function
|
|
965
|
-
|
|
1413
|
+
function done(transition2) {
|
|
1414
|
+
runLifeCycle(transition2, transition2.deactivated, "after", "Leave");
|
|
1415
|
+
runLifeCycle(transition2, transition2.activated, "after", "Enter");
|
|
966
1416
|
}
|
|
967
|
-
const
|
|
968
|
-
create
|
|
969
|
-
destroy
|
|
970
|
-
resolve
|
|
971
|
-
done
|
|
1417
|
+
const wc = {
|
|
1418
|
+
create,
|
|
1419
|
+
destroy,
|
|
1420
|
+
resolve,
|
|
1421
|
+
done
|
|
972
1422
|
};
|
|
973
|
-
let
|
|
974
|
-
function
|
|
975
|
-
window.dispatchEvent(new CustomEvent(`${
|
|
1423
|
+
let eventPrefix;
|
|
1424
|
+
function trigger(name, detail) {
|
|
1425
|
+
window.dispatchEvent(new CustomEvent(`${eventPrefix}${name}`, { detail }));
|
|
976
1426
|
}
|
|
977
|
-
const
|
|
978
|
-
create: function(
|
|
979
|
-
|
|
1427
|
+
const events = {
|
|
1428
|
+
create: function(router2) {
|
|
1429
|
+
eventPrefix = router2.options.eventPrefix || "router-";
|
|
980
1430
|
},
|
|
981
|
-
before: function(
|
|
982
|
-
|
|
1431
|
+
before: function(transition2) {
|
|
1432
|
+
trigger("before:transition", { transition: transition2 });
|
|
983
1433
|
},
|
|
984
|
-
done: function(
|
|
985
|
-
|
|
1434
|
+
done: function(transition2) {
|
|
1435
|
+
trigger("transition", { transition: transition2 });
|
|
986
1436
|
},
|
|
987
|
-
cancel: function(
|
|
988
|
-
|
|
1437
|
+
cancel: function(transition2, error) {
|
|
1438
|
+
if (error.type !== "TransitionRedirected") {
|
|
1439
|
+
trigger("abort", { transition: transition2, error });
|
|
1440
|
+
}
|
|
989
1441
|
},
|
|
990
|
-
error: function(
|
|
991
|
-
|
|
1442
|
+
error: function(transition2, error) {
|
|
1443
|
+
trigger("abort", { transition: transition2, error });
|
|
1444
|
+
trigger("error", { transition: transition2, error });
|
|
992
1445
|
}
|
|
993
1446
|
};
|
|
994
|
-
class
|
|
1447
|
+
class Routerx extends WJElement {
|
|
995
1448
|
constructor() {
|
|
996
1449
|
super();
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
let
|
|
1000
|
-
...
|
|
1001
|
-
var
|
|
1450
|
+
__publicField(this, "className", "Routerx");
|
|
1451
|
+
__publicField(this, "setBreadcrumb", (transition2) => {
|
|
1452
|
+
let breadcrumb = [
|
|
1453
|
+
...transition2.routes.filter((obj) => "breadcrumb" in obj.options).map((b, i) => {
|
|
1454
|
+
var _a, _b;
|
|
1002
1455
|
return {
|
|
1003
|
-
name:
|
|
1004
|
-
text:
|
|
1005
|
-
params: { ...
|
|
1006
|
-
path: this.router.generate(
|
|
1456
|
+
name: b.options.breadcrumbPath || b.name,
|
|
1457
|
+
text: b.options.breadcrumb instanceof Function ? (_b = (_a = b.options).breadcrumb) == null ? void 0 : _b.call(_a, transition2) : b.options.breadcrumb,
|
|
1458
|
+
params: { ...b.params, ...transition2.params },
|
|
1459
|
+
path: this.router.generate(b.name, { ...b.params, ...transition2.params })
|
|
1007
1460
|
};
|
|
1008
1461
|
})
|
|
1009
1462
|
];
|
|
1010
|
-
|
|
1463
|
+
transition2.breadcrumbs = breadcrumb;
|
|
1011
1464
|
});
|
|
1012
|
-
|
|
1465
|
+
__publicField(this, "resetScrollPosition", (transition2) => {
|
|
1013
1466
|
window.scrollTo(0, 0);
|
|
1014
1467
|
});
|
|
1015
1468
|
}
|
|
@@ -1020,28 +1473,58 @@ class se extends at {
|
|
|
1020
1473
|
this.isShadowRoot = "open";
|
|
1021
1474
|
}
|
|
1022
1475
|
afterDraw() {
|
|
1023
|
-
const
|
|
1024
|
-
|
|
1476
|
+
const htmlString = this.outerHTML;
|
|
1477
|
+
const parser = new DOMParser();
|
|
1478
|
+
const htmlDocument = parser.parseFromString(htmlString, "text/html");
|
|
1479
|
+
const rootElement = htmlDocument.querySelector("wj-router");
|
|
1480
|
+
const routes = this.parseElement(rootElement).root;
|
|
1481
|
+
this.router = new Router({
|
|
1025
1482
|
outlet: this.outlet || "wj-router-outlet",
|
|
1026
|
-
log:
|
|
1027
|
-
logError:
|
|
1483
|
+
log: false,
|
|
1484
|
+
logError: false,
|
|
1028
1485
|
root: this.root || "/",
|
|
1029
|
-
pushState:
|
|
1030
|
-
})
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1486
|
+
pushState: true
|
|
1487
|
+
});
|
|
1488
|
+
this.router.map(routes);
|
|
1489
|
+
this.router.use(this.setBreadcrumb);
|
|
1490
|
+
this.router.use(wc);
|
|
1491
|
+
this.router.use(routerLinks);
|
|
1492
|
+
this.router.use(events);
|
|
1493
|
+
this.router.use(this.resetScrollPosition);
|
|
1494
|
+
this.router.listen();
|
|
1495
|
+
this.unbindIntercept = interceptLinks(this.router);
|
|
1496
|
+
}
|
|
1497
|
+
parseElement(element) {
|
|
1498
|
+
const obj = {};
|
|
1499
|
+
const attributes = element.attributes;
|
|
1500
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
1501
|
+
const attributeName = attributes[i].name;
|
|
1502
|
+
const attributeValue = attributes[i].value;
|
|
1503
|
+
if (attributeName === "component" && attributeValue.indexOf(".js") > -1) {
|
|
1504
|
+
obj.component = () => import(new URL(attributeValue, import.meta.url).href);
|
|
1505
|
+
} else {
|
|
1506
|
+
if (attributeName !== "shadow") {
|
|
1507
|
+
obj[attributeName] = attributeValue;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
const children = [];
|
|
1512
|
+
const childElements = Array.from(element.children);
|
|
1513
|
+
childElements.forEach((childElement) => {
|
|
1514
|
+
children.push(this.parseElement(childElement));
|
|
1515
|
+
});
|
|
1516
|
+
if (children.length > 0 && element.tagName === "WJ-ROUTE") {
|
|
1517
|
+
obj.children = children;
|
|
1518
|
+
} else {
|
|
1519
|
+
obj.root = children;
|
|
1037
1520
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1521
|
+
return obj;
|
|
1522
|
+
}
|
|
1523
|
+
beforeDisconnect() {
|
|
1524
|
+
this.unbindIntercept();
|
|
1042
1525
|
}
|
|
1043
1526
|
}
|
|
1044
|
-
customElements.get("wj-router") || window.customElements.define("wj-router",
|
|
1527
|
+
customElements.get("wj-router") || window.customElements.define("wj-router", Routerx);
|
|
1045
1528
|
export {
|
|
1046
|
-
|
|
1529
|
+
Routerx
|
|
1047
1530
|
};
|