x4js 1.5.24 → 1.5.26
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/lib/cjs/index.js +9 -9
- package/lib/cjs/index.js.map +4 -4
- package/lib/esm/index.js.map +7 -0
- package/lib/esm/index.mjs +132 -119
- package/lib/esm/index.mjs.map +3 -3
- package/lib/src/application.ts +13 -2
- package/lib/src/router.ts +4 -0
- package/lib/src/version.ts +1 -1
- package/lib/types/application.d.ts +4 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/index.mjs
CHANGED
|
@@ -3480,6 +3480,126 @@ var Settings = class {
|
|
|
3480
3480
|
};
|
|
3481
3481
|
__name(Settings, "Settings");
|
|
3482
3482
|
|
|
3483
|
+
// src/router.ts
|
|
3484
|
+
function parseRoute(str, loose = false) {
|
|
3485
|
+
if (str instanceof RegExp) {
|
|
3486
|
+
return {
|
|
3487
|
+
keys: null,
|
|
3488
|
+
pattern: str
|
|
3489
|
+
};
|
|
3490
|
+
}
|
|
3491
|
+
const arr = str.split("/");
|
|
3492
|
+
let keys = [];
|
|
3493
|
+
let pattern = "";
|
|
3494
|
+
if (arr[0] == "") {
|
|
3495
|
+
arr.shift();
|
|
3496
|
+
}
|
|
3497
|
+
for (const tmp of arr) {
|
|
3498
|
+
const c = tmp[0];
|
|
3499
|
+
if (c === "*") {
|
|
3500
|
+
keys.push("wild");
|
|
3501
|
+
pattern += "/(.*)";
|
|
3502
|
+
} else if (c === ":") {
|
|
3503
|
+
const o = tmp.indexOf("?", 1);
|
|
3504
|
+
const ext = tmp.indexOf(".", 1);
|
|
3505
|
+
keys.push(tmp.substring(1, o >= 0 ? o : ext >= 0 ? ext : tmp.length));
|
|
3506
|
+
pattern += o >= 0 && ext < 0 ? "(?:/([^/]+?))?" : "/([^/]+?)";
|
|
3507
|
+
if (ext >= 0) {
|
|
3508
|
+
pattern += (o >= 0 ? "?" : "") + "\\" + tmp.substring(ext);
|
|
3509
|
+
}
|
|
3510
|
+
} else {
|
|
3511
|
+
pattern += "/" + tmp;
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
return {
|
|
3515
|
+
keys,
|
|
3516
|
+
pattern: new RegExp(`^${pattern}${loose ? "(?=$|/)" : "/?$"}`, "i")
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
__name(parseRoute, "parseRoute");
|
|
3520
|
+
var Router = class extends EventSource {
|
|
3521
|
+
m_routes;
|
|
3522
|
+
m_useHash;
|
|
3523
|
+
constructor(useHash = true) {
|
|
3524
|
+
super();
|
|
3525
|
+
this.m_routes = [];
|
|
3526
|
+
this.m_useHash = useHash;
|
|
3527
|
+
window.addEventListener("popstate", (event) => {
|
|
3528
|
+
const url = this._getLocation();
|
|
3529
|
+
const found = this._find(url);
|
|
3530
|
+
found.handlers.forEach((h) => {
|
|
3531
|
+
h(found.params, url);
|
|
3532
|
+
});
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3535
|
+
get(uri, handler) {
|
|
3536
|
+
let { keys, pattern } = parseRoute(uri);
|
|
3537
|
+
this.m_routes.push({ keys, pattern, handler });
|
|
3538
|
+
}
|
|
3539
|
+
init() {
|
|
3540
|
+
this.navigate(this._getLocation());
|
|
3541
|
+
}
|
|
3542
|
+
_getLocation() {
|
|
3543
|
+
return this.m_useHash ? "/" + x4document.location.hash.substring(1) : x4document.location.pathname;
|
|
3544
|
+
}
|
|
3545
|
+
navigate(uri, notify = true) {
|
|
3546
|
+
if (!uri.startsWith("/")) {
|
|
3547
|
+
uri = "/" + uri;
|
|
3548
|
+
}
|
|
3549
|
+
const found = this._find(uri);
|
|
3550
|
+
if (!found || found.handlers.length == 0) {
|
|
3551
|
+
console.log("route not found: " + uri);
|
|
3552
|
+
this.signal("error", EvError(404, "route not found"));
|
|
3553
|
+
return;
|
|
3554
|
+
}
|
|
3555
|
+
if (this.m_useHash) {
|
|
3556
|
+
while (uri.startsWith("/")) {
|
|
3557
|
+
uri = uri.substring(1);
|
|
3558
|
+
}
|
|
3559
|
+
window.history.pushState({}, "", "#" + uri);
|
|
3560
|
+
} else {
|
|
3561
|
+
window.history.pushState({}, "", uri);
|
|
3562
|
+
}
|
|
3563
|
+
if (notify) {
|
|
3564
|
+
found.handlers.forEach((h) => {
|
|
3565
|
+
h(found.params, uri);
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
_find(url) {
|
|
3570
|
+
let matches = [];
|
|
3571
|
+
let params = {};
|
|
3572
|
+
let handlers = [];
|
|
3573
|
+
for (const tmp of this.m_routes) {
|
|
3574
|
+
if (!tmp.keys) {
|
|
3575
|
+
matches = tmp.pattern.exec(url);
|
|
3576
|
+
if (!matches) {
|
|
3577
|
+
continue;
|
|
3578
|
+
}
|
|
3579
|
+
if (matches["groups"]) {
|
|
3580
|
+
for (const k in matches["groups"]) {
|
|
3581
|
+
params[k] = matches["groups"][k];
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
handlers = [...handlers, tmp.handler];
|
|
3585
|
+
} else if (tmp.keys.length > 0) {
|
|
3586
|
+
matches = tmp.pattern.exec(url);
|
|
3587
|
+
if (matches === null) {
|
|
3588
|
+
continue;
|
|
3589
|
+
}
|
|
3590
|
+
for (let j = 0; j < tmp.keys.length; ) {
|
|
3591
|
+
params[tmp.keys[j]] = matches[++j];
|
|
3592
|
+
}
|
|
3593
|
+
handlers = [...handlers, tmp.handler];
|
|
3594
|
+
} else if (tmp.pattern.test(url)) {
|
|
3595
|
+
handlers = [...handlers, tmp.handler];
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
return { params, handlers };
|
|
3599
|
+
}
|
|
3600
|
+
};
|
|
3601
|
+
__name(Router, "Router");
|
|
3602
|
+
|
|
3483
3603
|
// src/application.ts
|
|
3484
3604
|
var _x4_touch_time = Symbol();
|
|
3485
3605
|
var _Application = class extends BaseComponent {
|
|
@@ -3497,6 +3617,7 @@ var _Application = class extends BaseComponent {
|
|
|
3497
3617
|
m_user_data;
|
|
3498
3618
|
m_touch_time;
|
|
3499
3619
|
m_touch_count;
|
|
3620
|
+
m_router;
|
|
3500
3621
|
constructor(props) {
|
|
3501
3622
|
console.assert(_Application.self === null, "application is a singleton");
|
|
3502
3623
|
super(props);
|
|
@@ -3508,7 +3629,8 @@ var _Application = class extends BaseComponent {
|
|
|
3508
3629
|
this.m_user_data = {};
|
|
3509
3630
|
this.m_touch_time = 0;
|
|
3510
3631
|
this.m_touch_count = 0;
|
|
3511
|
-
|
|
3632
|
+
this.m_router = null;
|
|
3633
|
+
x4app = _Application.self = this;
|
|
3512
3634
|
if ("onload" in globalThis) {
|
|
3513
3635
|
globalThis.addEventListener("load", () => {
|
|
3514
3636
|
this.ApplicationCreated();
|
|
@@ -3520,6 +3642,12 @@ var _Application = class extends BaseComponent {
|
|
|
3520
3642
|
ApplicationCreated() {
|
|
3521
3643
|
this.setTitle("");
|
|
3522
3644
|
}
|
|
3645
|
+
get router() {
|
|
3646
|
+
if (!this.m_router) {
|
|
3647
|
+
this.m_router = new Router();
|
|
3648
|
+
}
|
|
3649
|
+
return this.m_router;
|
|
3650
|
+
}
|
|
3523
3651
|
get app_name() {
|
|
3524
3652
|
return this.m_app_name;
|
|
3525
3653
|
}
|
|
@@ -3605,6 +3733,7 @@ var _Application = class extends BaseComponent {
|
|
|
3605
3733
|
var Application = _Application;
|
|
3606
3734
|
__name(Application, "Application");
|
|
3607
3735
|
__publicField(Application, "self", null);
|
|
3736
|
+
var x4app;
|
|
3608
3737
|
|
|
3609
3738
|
// src/layout.ts
|
|
3610
3739
|
var AbsLayout = class extends Container {
|
|
@@ -14126,123 +14255,6 @@ var Rating = class extends HLayout {
|
|
|
14126
14255
|
};
|
|
14127
14256
|
__name(Rating, "Rating");
|
|
14128
14257
|
|
|
14129
|
-
// src/router.ts
|
|
14130
|
-
function parseRoute(str, loose = false) {
|
|
14131
|
-
if (str instanceof RegExp) {
|
|
14132
|
-
return {
|
|
14133
|
-
keys: null,
|
|
14134
|
-
pattern: str
|
|
14135
|
-
};
|
|
14136
|
-
}
|
|
14137
|
-
const arr = str.split("/");
|
|
14138
|
-
let keys = [];
|
|
14139
|
-
let pattern = "";
|
|
14140
|
-
if (arr[0] == "") {
|
|
14141
|
-
arr.shift();
|
|
14142
|
-
}
|
|
14143
|
-
for (const tmp of arr) {
|
|
14144
|
-
const c = tmp[0];
|
|
14145
|
-
if (c === "*") {
|
|
14146
|
-
keys.push("wild");
|
|
14147
|
-
pattern += "/(.*)";
|
|
14148
|
-
} else if (c === ":") {
|
|
14149
|
-
const o = tmp.indexOf("?", 1);
|
|
14150
|
-
const ext = tmp.indexOf(".", 1);
|
|
14151
|
-
keys.push(tmp.substring(1, o >= 0 ? o : ext >= 0 ? ext : tmp.length));
|
|
14152
|
-
pattern += o >= 0 && ext < 0 ? "(?:/([^/]+?))?" : "/([^/]+?)";
|
|
14153
|
-
if (ext >= 0) {
|
|
14154
|
-
pattern += (o >= 0 ? "?" : "") + "\\" + tmp.substring(ext);
|
|
14155
|
-
}
|
|
14156
|
-
} else {
|
|
14157
|
-
pattern += "/" + tmp;
|
|
14158
|
-
}
|
|
14159
|
-
}
|
|
14160
|
-
return {
|
|
14161
|
-
keys,
|
|
14162
|
-
pattern: new RegExp(`^${pattern}${loose ? "(?=$|/)" : "/?$"}`, "i")
|
|
14163
|
-
};
|
|
14164
|
-
}
|
|
14165
|
-
__name(parseRoute, "parseRoute");
|
|
14166
|
-
var Router = class extends EventSource {
|
|
14167
|
-
m_routes;
|
|
14168
|
-
m_useHash;
|
|
14169
|
-
constructor(useHash = true) {
|
|
14170
|
-
super();
|
|
14171
|
-
this.m_routes = [];
|
|
14172
|
-
this.m_useHash = useHash;
|
|
14173
|
-
window.addEventListener("popstate", (event) => {
|
|
14174
|
-
const url = this._getLocation();
|
|
14175
|
-
const found = this._find(url);
|
|
14176
|
-
found.handlers.forEach((h) => {
|
|
14177
|
-
h(found.params, url);
|
|
14178
|
-
});
|
|
14179
|
-
});
|
|
14180
|
-
}
|
|
14181
|
-
get(uri, handler) {
|
|
14182
|
-
let { keys, pattern } = parseRoute(uri);
|
|
14183
|
-
this.m_routes.push({ keys, pattern, handler });
|
|
14184
|
-
}
|
|
14185
|
-
init() {
|
|
14186
|
-
this.navigate(this._getLocation());
|
|
14187
|
-
}
|
|
14188
|
-
_getLocation() {
|
|
14189
|
-
return this.m_useHash ? "/" + x4document.location.hash.substring(1) : x4document.location.pathname;
|
|
14190
|
-
}
|
|
14191
|
-
navigate(uri, notify = true) {
|
|
14192
|
-
const found = this._find(uri);
|
|
14193
|
-
if (!found || found.handlers.length == 0) {
|
|
14194
|
-
console.log("route not found: " + uri);
|
|
14195
|
-
this.signal("error", EvError(404, "route not found"));
|
|
14196
|
-
return;
|
|
14197
|
-
}
|
|
14198
|
-
if (this.m_useHash) {
|
|
14199
|
-
while (uri.startsWith("/")) {
|
|
14200
|
-
uri = uri.substring(1);
|
|
14201
|
-
}
|
|
14202
|
-
window.history.pushState({}, "", "#" + uri);
|
|
14203
|
-
} else {
|
|
14204
|
-
window.history.pushState({}, "", uri);
|
|
14205
|
-
}
|
|
14206
|
-
if (notify) {
|
|
14207
|
-
found.handlers.forEach((h) => {
|
|
14208
|
-
h(found.params, uri);
|
|
14209
|
-
});
|
|
14210
|
-
}
|
|
14211
|
-
}
|
|
14212
|
-
_find(url) {
|
|
14213
|
-
let matches = [];
|
|
14214
|
-
let params = {};
|
|
14215
|
-
let handlers = [];
|
|
14216
|
-
for (const tmp of this.m_routes) {
|
|
14217
|
-
if (!tmp.keys) {
|
|
14218
|
-
matches = tmp.pattern.exec(url);
|
|
14219
|
-
if (!matches) {
|
|
14220
|
-
continue;
|
|
14221
|
-
}
|
|
14222
|
-
if (matches["groups"]) {
|
|
14223
|
-
for (const k in matches["groups"]) {
|
|
14224
|
-
params[k] = matches["groups"][k];
|
|
14225
|
-
}
|
|
14226
|
-
}
|
|
14227
|
-
handlers = [...handlers, tmp.handler];
|
|
14228
|
-
} else if (tmp.keys.length > 0) {
|
|
14229
|
-
matches = tmp.pattern.exec(url);
|
|
14230
|
-
if (matches === null) {
|
|
14231
|
-
continue;
|
|
14232
|
-
}
|
|
14233
|
-
for (let j = 0; j < tmp.keys.length; ) {
|
|
14234
|
-
params[tmp.keys[j]] = matches[++j];
|
|
14235
|
-
}
|
|
14236
|
-
handlers = [...handlers, tmp.handler];
|
|
14237
|
-
} else if (tmp.pattern.test(url)) {
|
|
14238
|
-
handlers = [...handlers, tmp.handler];
|
|
14239
|
-
}
|
|
14240
|
-
}
|
|
14241
|
-
return { params, handlers };
|
|
14242
|
-
}
|
|
14243
|
-
};
|
|
14244
|
-
__name(Router, "Router");
|
|
14245
|
-
|
|
14246
14258
|
// src/sidebarview.ts
|
|
14247
14259
|
var SideBarView = class extends CardView {
|
|
14248
14260
|
m_sidebar;
|
|
@@ -15556,7 +15568,7 @@ function setupWSMessaging(closeCB) {
|
|
|
15556
15568
|
__name(setupWSMessaging, "setupWSMessaging");
|
|
15557
15569
|
|
|
15558
15570
|
// src/version.ts
|
|
15559
|
-
var x4js_version = "1.5.
|
|
15571
|
+
var x4js_version = "1.5.26";
|
|
15560
15572
|
export {
|
|
15561
15573
|
AbsLayout,
|
|
15562
15574
|
Application,
|
|
@@ -15727,6 +15739,7 @@ export {
|
|
|
15727
15739
|
sprintf,
|
|
15728
15740
|
sql_date_formatter,
|
|
15729
15741
|
waitFontLoading,
|
|
15742
|
+
x4app,
|
|
15730
15743
|
x4js_version
|
|
15731
15744
|
};
|
|
15732
15745
|
/**
|