silentium-components 0.0.4 → 0.0.6
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/CHANGELOG.md +22 -0
- package/dist/silentium-components.cjs +134 -483
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +8 -190
- package/dist/silentium-components.js +130 -467
- package/dist/silentium-components.js.map +1 -1
- package/dist/silentium-components.min.js +1 -1
- package/dist/silentium-components.min.mjs +1 -1
- package/dist/silentium-components.min.mjs.map +1 -1
- package/dist/silentium-components.mjs +130 -467
- package/dist/silentium-components.mjs.map +1 -1
- package/docs/assets/js/index.mjs +3 -3
- package/docs/build.sh +3 -4
- package/docs/index.html +3 -3
- package/docs/pages/behaviors/deadline.html +60 -0
- package/docs/pages/behaviors/dirty.html +4 -4
- package/docs/pages/behaviors/loading.html +6 -6
- package/docs/pages/behaviors.html +5 -0
- package/docs/pages/structures/hash-table.html +4 -4
- package/docs/routes.json +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +7 -5
- package/src/behaviors/Deadline._value.test.ts +27 -0
- package/src/behaviors/Deadline.test.ts +28 -0
- package/src/behaviors/Deadline.ts +49 -0
- package/src/behaviors/Dirty.test.ts +5 -5
- package/src/behaviors/Dirty.ts +48 -54
- package/src/behaviors/Loading.test.ts +8 -8
- package/src/behaviors/Loading.ts +21 -31
- package/src/behaviors/Path.index.test.ts +5 -5
- package/src/behaviors/Path.nested.test.ts +5 -5
- package/src/behaviors/Path.test.ts +5 -5
- package/src/behaviors/Path.ts +26 -30
- package/src/behaviors/index.ts +1 -1
- package/src/controls/GroupActiveClass.test.ts +16 -13
- package/src/controls/GroupActiveClass.ts +19 -22
- package/src/controls/index.ts +0 -5
- package/src/index.ts +0 -2
- package/src/navigation/Router.test.ts +47 -0
- package/src/navigation/Router.ts +43 -111
- package/src/navigation/index.ts +0 -6
- package/src/structures/HashTable.test.ts +5 -5
- package/src/structures/HashTable.ts +14 -25
- package/src/system/RegexpMatched.test.ts +14 -0
- package/src/system/RegexpMatched.ts +17 -0
- package/src/system/index.ts +1 -0
- package/dist/patron-components.cjs +0 -372
- package/dist/patron-components.cjs.map +0 -1
- package/dist/patron-components.d.ts +0 -158
- package/dist/patron-components.js +0 -358
- package/dist/patron-components.js.map +0 -1
- package/dist/patron-components.min.js +0 -1
- package/dist/patron-components.min.mjs +0 -2
- package/dist/patron-components.min.mjs.map +0 -1
- package/dist/patron-components.mjs +0 -358
- package/dist/patron-components.mjs.map +0 -1
- package/src/behaviors/Touched.ts +0 -1
- package/src/controls/ComputedElement.ts +0 -51
- package/src/controls/Input.ts +0 -40
- package/src/controls/Link.ts +0 -53
- package/src/controls/Text.ts +0 -16
- package/src/controls/Visible.ts +0 -16
- package/src/jsdom/JSDomDocument.ts +0 -15
- package/src/jsdom/JSDomElement.ts +0 -28
- package/src/jsdom/JSDomQuerySelector.ts +0 -28
- package/src/navigation/CurrentPage.ts +0 -27
- package/src/navigation/Navigation.default.test.ts +0 -53
- package/src/navigation/Navigation.main.test.ts +0 -46
- package/src/navigation/Navigation.ts +0 -92
- package/src/navigation/Navigation.wildcard.test.ts +0 -52
- package/src/navigation/PageFetchTransport.ts +0 -26
- package/src/navigation/RouteDisplay.ts +0 -18
- package/src/navigation/RoutePageType.ts +0 -3
- package/src/page/EntryPointPage.ts +0 -20
- package/src/page/Page.ts +0 -12
- package/src/page/PageFake.ts +0 -8
- package/src/page/index.ts +0 -2
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { GuestType, SourceWithPool, SourceWithPoolType } from "silentium";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated move to web api
|
|
5
|
-
*/
|
|
6
|
-
export class CurrentPage implements SourceWithPoolType<string> {
|
|
7
|
-
private source: SourceWithPoolType<string>;
|
|
8
|
-
|
|
9
|
-
public constructor() {
|
|
10
|
-
const correctUrl = location.href.replace(location.origin, "");
|
|
11
|
-
this.source = new SourceWithPool(correctUrl);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public give(value: string): this {
|
|
15
|
-
this.source.give(value);
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public value(guest: GuestType<string>) {
|
|
20
|
-
this.source.value(guest);
|
|
21
|
-
return guest;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public pool() {
|
|
25
|
-
return this.source.pool();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { give, GuestType, PrivateClass, SourceWithPool } from "silentium";
|
|
2
|
-
import { expect, test } from "vitest";
|
|
3
|
-
import { PageFake } from "../page/PageFake";
|
|
4
|
-
import { Navigation } from "./Navigation";
|
|
5
|
-
import { RoutePageTransportType } from "./PageFetchTransport";
|
|
6
|
-
|
|
7
|
-
class FakeTransport implements RoutePageTransportType {
|
|
8
|
-
constructor(
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
basePath = null,
|
|
11
|
-
private template = "null",
|
|
12
|
-
) {}
|
|
13
|
-
content(guest: GuestType<string>): void {
|
|
14
|
-
give(this.template, guest);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
test("navigation", () => {
|
|
19
|
-
const pageLoading = new SourceWithPool(false);
|
|
20
|
-
const basePath = new SourceWithPool("/some/path/#");
|
|
21
|
-
const currentPage = new SourceWithPool("/some/path/unknown-page");
|
|
22
|
-
const display = {
|
|
23
|
-
display(content: string) {
|
|
24
|
-
expect(content).toBe("default.html");
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const navigation = new Navigation(
|
|
29
|
-
pageLoading,
|
|
30
|
-
basePath,
|
|
31
|
-
currentPage,
|
|
32
|
-
display,
|
|
33
|
-
new PrivateClass(FakeTransport),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
navigation.routes([
|
|
37
|
-
{
|
|
38
|
-
url: "/",
|
|
39
|
-
template: "main.html",
|
|
40
|
-
aliases: ["/some/path/"],
|
|
41
|
-
page: new PageFake(),
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
url: "",
|
|
45
|
-
template: "default.html",
|
|
46
|
-
aliases: ["/some/path/"],
|
|
47
|
-
page: new PageFake(),
|
|
48
|
-
default: true,
|
|
49
|
-
},
|
|
50
|
-
]);
|
|
51
|
-
|
|
52
|
-
expect(true).toBe(true);
|
|
53
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { give, GuestType, PrivateClass, SourceWithPool } from "silentium";
|
|
2
|
-
import { expect, test } from "vitest";
|
|
3
|
-
import { PageFake } from "../page/PageFake";
|
|
4
|
-
import { Navigation } from "./Navigation";
|
|
5
|
-
import { RoutePageTransportType } from "./PageFetchTransport";
|
|
6
|
-
|
|
7
|
-
class FakeTransport implements RoutePageTransportType {
|
|
8
|
-
constructor(
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
basePath = null,
|
|
11
|
-
private template = "null",
|
|
12
|
-
) {}
|
|
13
|
-
content(guest: GuestType<string>): void {
|
|
14
|
-
give(this.template, guest);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
test("navigation", () => {
|
|
19
|
-
const pageLoading = new SourceWithPool(false);
|
|
20
|
-
const basePath = new SourceWithPool("/some/path/#");
|
|
21
|
-
const currentPage = new SourceWithPool("/some/path/");
|
|
22
|
-
const display = {
|
|
23
|
-
display(content: string) {
|
|
24
|
-
expect(content).toBe("main.html");
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const navigation = new Navigation(
|
|
29
|
-
pageLoading,
|
|
30
|
-
basePath,
|
|
31
|
-
currentPage,
|
|
32
|
-
display,
|
|
33
|
-
new PrivateClass(FakeTransport),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
navigation.routes([
|
|
37
|
-
{
|
|
38
|
-
url: "/",
|
|
39
|
-
template: "main.html",
|
|
40
|
-
aliases: ["/some/path/"],
|
|
41
|
-
page: new PageFake(),
|
|
42
|
-
},
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
expect(true).toBe(true);
|
|
46
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SourceAll,
|
|
3
|
-
Patron,
|
|
4
|
-
PrivateType,
|
|
5
|
-
SourceType,
|
|
6
|
-
value,
|
|
7
|
-
give,
|
|
8
|
-
SourceWithPoolType,
|
|
9
|
-
} from "silentium";
|
|
10
|
-
import { RoutePageTransportType } from "src/navigation/PageFetchTransport";
|
|
11
|
-
import { RouteDisplayType } from "src/navigation/RouteDisplay";
|
|
12
|
-
import { RoutePageType } from "src/navigation/RoutePageType";
|
|
13
|
-
|
|
14
|
-
export interface RouteDocument {
|
|
15
|
-
url: string;
|
|
16
|
-
template: string;
|
|
17
|
-
aliases?: string[];
|
|
18
|
-
page: RoutePageType;
|
|
19
|
-
default?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class Navigation {
|
|
23
|
-
public constructor(
|
|
24
|
-
private loading: SourceWithPoolType<boolean>,
|
|
25
|
-
private basePath: SourceType<string>,
|
|
26
|
-
private currentPage: SourceWithPoolType<string>,
|
|
27
|
-
private display: RouteDisplayType,
|
|
28
|
-
private pageTransport: PrivateType<RoutePageTransportType>,
|
|
29
|
-
) {}
|
|
30
|
-
|
|
31
|
-
public routes(routes: RouteDocument[]) {
|
|
32
|
-
const defaultRoute = routes.find((route) => route.default);
|
|
33
|
-
const all = new SourceAll<{
|
|
34
|
-
basePath: string;
|
|
35
|
-
currentPage: string;
|
|
36
|
-
}>();
|
|
37
|
-
value(this.basePath, new Patron(all.guestKey("basePath")));
|
|
38
|
-
value(this.currentPage, new Patron(all.guestKey("currentPage")));
|
|
39
|
-
|
|
40
|
-
all.value(
|
|
41
|
-
new Patron(({ basePath, currentPage }) => {
|
|
42
|
-
const urlWithoutBasePath = currentPage.replace(basePath, "");
|
|
43
|
-
const routeMatchedToAlias = routes.find(
|
|
44
|
-
(route) =>
|
|
45
|
-
route.aliases &&
|
|
46
|
-
(route.aliases.includes(currentPage) ||
|
|
47
|
-
route.aliases.includes(urlWithoutBasePath)),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
if (routeMatchedToAlias) {
|
|
51
|
-
const correctUrl = basePath + routeMatchedToAlias.url;
|
|
52
|
-
|
|
53
|
-
if (correctUrl !== currentPage) {
|
|
54
|
-
give(correctUrl, this.currentPage);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let route = routes.find((route) => {
|
|
60
|
-
if (route.url.indexOf("*") >= 0) {
|
|
61
|
-
const regexp = new RegExp(
|
|
62
|
-
route.url.replaceAll("*", ".*").replaceAll("/", "/"),
|
|
63
|
-
);
|
|
64
|
-
return regexp.test(urlWithoutBasePath);
|
|
65
|
-
}
|
|
66
|
-
return route.url.replaceAll("*", "") === urlWithoutBasePath;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
if (!route && defaultRoute) {
|
|
70
|
-
route = defaultRoute;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (route) {
|
|
74
|
-
const basePathWithoutHash = basePath
|
|
75
|
-
.replace("/#", "")
|
|
76
|
-
.replace("#", "")
|
|
77
|
-
.replace(/[^/]+\.html$/, "");
|
|
78
|
-
give(true, this.loading);
|
|
79
|
-
this.pageTransport
|
|
80
|
-
.get(basePathWithoutHash, route.template)
|
|
81
|
-
.content((templateContent) => {
|
|
82
|
-
this.display.display(templateContent);
|
|
83
|
-
route.page.mounted();
|
|
84
|
-
give(false, this.loading);
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
throw new Error("No matching route in Navigation");
|
|
88
|
-
}
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { give, GuestType, PrivateClass, SourceWithPool } from "silentium";
|
|
2
|
-
import { expect, test } from "vitest";
|
|
3
|
-
import { PageFake } from "../page/PageFake";
|
|
4
|
-
import { Navigation } from "./Navigation";
|
|
5
|
-
import { RoutePageTransportType } from "./PageFetchTransport";
|
|
6
|
-
|
|
7
|
-
class FakeTransport implements RoutePageTransportType {
|
|
8
|
-
constructor(
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
basePath = null,
|
|
11
|
-
private template = "null",
|
|
12
|
-
) {}
|
|
13
|
-
content(guest: GuestType<string>): void {
|
|
14
|
-
give(this.template, guest);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
test("navigation", () => {
|
|
19
|
-
const pageLoading = new SourceWithPool(false);
|
|
20
|
-
const basePath = new SourceWithPool("/some/path/#");
|
|
21
|
-
const currentPage = new SourceWithPool("/some/path/catalog/information");
|
|
22
|
-
const display = {
|
|
23
|
-
display(content: string) {
|
|
24
|
-
expect(content).toBe("catalog.html");
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const navigation = new Navigation(
|
|
29
|
-
pageLoading,
|
|
30
|
-
basePath,
|
|
31
|
-
currentPage,
|
|
32
|
-
display,
|
|
33
|
-
new PrivateClass(FakeTransport),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
navigation.routes([
|
|
37
|
-
{
|
|
38
|
-
url: "/",
|
|
39
|
-
template: "default.html",
|
|
40
|
-
aliases: ["/some/path/"],
|
|
41
|
-
page: new PageFake(),
|
|
42
|
-
default: true,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
url: "/catalog*",
|
|
46
|
-
template: "catalog.html",
|
|
47
|
-
page: new PageFake(),
|
|
48
|
-
},
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
expect(true).toBe(true);
|
|
52
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { give, GuestType } from "silentium";
|
|
2
|
-
|
|
3
|
-
export interface RoutePageTransportType {
|
|
4
|
-
content(guest: GuestType<string>): void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Not needed anymore same thing in web api existed
|
|
9
|
-
* @deprecated
|
|
10
|
-
*/
|
|
11
|
-
export class PageFetchTransport implements RoutePageTransportType {
|
|
12
|
-
public constructor(
|
|
13
|
-
private basePath: string,
|
|
14
|
-
private template: string,
|
|
15
|
-
) {}
|
|
16
|
-
|
|
17
|
-
public content(guest: GuestType<string>): void {
|
|
18
|
-
fetch(this.basePath + "/" + this.template)
|
|
19
|
-
.then((result) => {
|
|
20
|
-
return result.text();
|
|
21
|
-
})
|
|
22
|
-
.then((result) => {
|
|
23
|
-
give(result, guest);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface RouteDisplayType {
|
|
2
|
-
display(content: string): void;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Renders content on selector
|
|
7
|
-
* @deprecated move to web api
|
|
8
|
-
*/
|
|
9
|
-
export class RouteDisplay implements RouteDisplayType {
|
|
10
|
-
public constructor(private selector: string) {}
|
|
11
|
-
|
|
12
|
-
public display(content: string): void {
|
|
13
|
-
const contentEl = document.querySelector(this.selector);
|
|
14
|
-
if (contentEl) {
|
|
15
|
-
contentEl.innerHTML = content;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { RoutePageType } from "../navigation";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated not needed
|
|
5
|
-
*/
|
|
6
|
-
export class EntryPointPage implements RoutePageType {
|
|
7
|
-
public constructor(
|
|
8
|
-
private title: string,
|
|
9
|
-
private entryPointUrl: string,
|
|
10
|
-
) {}
|
|
11
|
-
|
|
12
|
-
public mounted() {
|
|
13
|
-
document.title = this.title;
|
|
14
|
-
import(this.entryPointUrl).then((module) => {
|
|
15
|
-
if (module.main) {
|
|
16
|
-
module.main();
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/page/Page.ts
DELETED
package/src/page/PageFake.ts
DELETED
package/src/page/index.ts
DELETED