@cedx/base 0.5.0 → 0.6.0
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/ReadMe.md +1 -1
- package/lib/Data/PaginatedList.d.ts +35 -0
- package/lib/Data/PaginatedList.d.ts.map +1 -0
- package/lib/Data/PaginatedList.js +28 -0
- package/lib/Data/Pagination.d.ts +57 -0
- package/lib/Data/Pagination.d.ts.map +1 -0
- package/lib/Data/Pagination.js +74 -0
- package/lib/UI/Component.d.ts +24 -0
- package/lib/UI/Component.d.ts.map +1 -0
- package/lib/UI/Component.js +29 -0
- package/lib/UI/MenuActivator.d.ts +1 -1
- package/lib/UI/MenuActivator.js +1 -1
- package/lib/UI/ThemeDropdown.d.ts +6 -0
- package/lib/UI/ThemeDropdown.d.ts.map +1 -1
- package/lib/UI/ThemeDropdown.js +11 -2
- package/package.json +3 -2
- package/src/Client/Data/PaginatedList.ts +47 -0
- package/src/Client/Data/Pagination.ts +90 -0
- package/src/Client/UI/Component.ts +34 -0
- package/src/Client/UI/MenuActivator.ts +1 -1
- package/src/Client/UI/ThemeDropdown.ts +12 -2
- package/lib/UI/ActionBar.d.ts +0 -25
- package/lib/UI/ActionBar.d.ts.map +0 -1
- package/lib/UI/ActionBar.js +0 -25
- package/src/Client/Data/Pagination.new +0 -130
- package/src/Client/UI/ActionBar.ts +0 -41
package/ReadMe.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Belin.io Base
|
|
2
|
-
   
|
|
3
3
|
|
|
4
4
|
Base library by [Cédric Belin](https://belin.io), full stack developer,
|
|
5
5
|
implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Pagination } from "./Pagination.js";
|
|
2
|
+
/**
|
|
3
|
+
* A list with information relevant to the pagination of its items.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PaginatedList<T> extends Array<T> {
|
|
6
|
+
/**
|
|
7
|
+
* The information relevant to the pagination of the list items.
|
|
8
|
+
*/
|
|
9
|
+
pagination: Pagination;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new paginated list.
|
|
12
|
+
* @param options An object providing values to initialize this instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(options?: PaginatedListOptions<T>);
|
|
15
|
+
/**
|
|
16
|
+
* Creates an empty paginated list.
|
|
17
|
+
* @param itemsPerPage The number of items per page.
|
|
18
|
+
* @returns An empty paginated list with the specified number of items per page.
|
|
19
|
+
*/
|
|
20
|
+
static empty<T>(itemsPerPage: number): PaginatedList<T>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Defines the options of a {@link PaginatedList} instance.
|
|
24
|
+
*/
|
|
25
|
+
export type PaginatedListOptions<T> = Partial<{
|
|
26
|
+
/**
|
|
27
|
+
* The list items.
|
|
28
|
+
*/
|
|
29
|
+
items: T[];
|
|
30
|
+
/**
|
|
31
|
+
* The information relevant to the pagination of the list items.
|
|
32
|
+
*/
|
|
33
|
+
pagination: Pagination;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=PaginatedList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaginatedList.d.ts","sourceRoot":"","sources":["../../src/Client/Data/PaginatedList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IAE7C;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;;OAGG;gBACS,OAAO,GAAE,oBAAoB,CAAC,CAAC,CAAM;IAMjD;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;CAGvD;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,OAAO,CAAC;IAE7C;;OAEG;IACH,KAAK,EAAE,CAAC,EAAE,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Pagination } from "./Pagination.js";
|
|
2
|
+
/**
|
|
3
|
+
* A list with information relevant to the pagination of its items.
|
|
4
|
+
*/
|
|
5
|
+
export class PaginatedList extends Array {
|
|
6
|
+
/**
|
|
7
|
+
* The information relevant to the pagination of the list items.
|
|
8
|
+
*/
|
|
9
|
+
pagination;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new paginated list.
|
|
12
|
+
* @param options An object providing values to initialize this instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
super();
|
|
16
|
+
for (const item of options.items ?? [])
|
|
17
|
+
this.push(item);
|
|
18
|
+
this.pagination = options.pagination ?? new Pagination;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates an empty paginated list.
|
|
22
|
+
* @param itemsPerPage The number of items per page.
|
|
23
|
+
* @returns An empty paginated list with the specified number of items per page.
|
|
24
|
+
*/
|
|
25
|
+
static empty(itemsPerPage) {
|
|
26
|
+
return new this({ pagination: new Pagination({ itemsPerPage }) });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents information relevant to the pagination of data items.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Pagination {
|
|
5
|
+
/**
|
|
6
|
+
* The one-based current page number.
|
|
7
|
+
*/
|
|
8
|
+
currentPageIndex: number;
|
|
9
|
+
/**
|
|
10
|
+
* The number of items per page.
|
|
11
|
+
*/
|
|
12
|
+
itemsPerPage: number;
|
|
13
|
+
/**
|
|
14
|
+
* The total number of items.
|
|
15
|
+
*/
|
|
16
|
+
totalItemCount: number;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new pagination.
|
|
19
|
+
* @param options An object providing values to initialize this instance.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options?: PaginationOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Value indicating whether a next page exists.
|
|
24
|
+
*/
|
|
25
|
+
get hasNextPage(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Value indicating whether a previous page exists.
|
|
28
|
+
*/
|
|
29
|
+
get hasPreviousPage(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The one-based last page number.
|
|
32
|
+
*/
|
|
33
|
+
get lastPageIndex(): number;
|
|
34
|
+
/**
|
|
35
|
+
* The data limit.
|
|
36
|
+
*/
|
|
37
|
+
get limit(): number;
|
|
38
|
+
/**
|
|
39
|
+
* The data offset.
|
|
40
|
+
*/
|
|
41
|
+
get offset(): number;
|
|
42
|
+
/**
|
|
43
|
+
* The search parameters corresponding to this object.
|
|
44
|
+
*/
|
|
45
|
+
get searchParams(): URLSearchParams;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new pagination from the HTTP headers of the specified response.
|
|
48
|
+
* @param response A server response.
|
|
49
|
+
* @returns The pagination corresponding to the HTTP headers of the specified response.
|
|
50
|
+
*/
|
|
51
|
+
static fromResponse(response: Response): Pagination;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Defines the options of a {@link Pagination} instance.
|
|
55
|
+
*/
|
|
56
|
+
export type PaginationOptions = Partial<Pick<Pagination, "currentPageIndex" | "itemsPerPage" | "totalItemCount">>;
|
|
57
|
+
//# sourceMappingURL=Pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../../src/Client/Data/Pagination.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAU;IAEtB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;gBACS,OAAO,GAAE,iBAAsB;IAM3C;;OAEG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,eAAe,CAElC;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU;CAOnD;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,GAAC,cAAc,GAAC,gBAAgB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents information relevant to the pagination of data items.
|
|
3
|
+
*/
|
|
4
|
+
export class Pagination {
|
|
5
|
+
/**
|
|
6
|
+
* The one-based current page number.
|
|
7
|
+
*/
|
|
8
|
+
currentPageIndex;
|
|
9
|
+
/**
|
|
10
|
+
* The number of items per page.
|
|
11
|
+
*/
|
|
12
|
+
itemsPerPage;
|
|
13
|
+
/**
|
|
14
|
+
* The total number of items.
|
|
15
|
+
*/
|
|
16
|
+
totalItemCount;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new pagination.
|
|
19
|
+
* @param options An object providing values to initialize this instance.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.currentPageIndex = Math.max(1, options.currentPageIndex ?? 1);
|
|
23
|
+
this.itemsPerPage = Math.max(1, Math.min(1000, options.itemsPerPage ?? 25));
|
|
24
|
+
this.totalItemCount = Math.max(0, options.totalItemCount ?? 0);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Value indicating whether a next page exists.
|
|
28
|
+
*/
|
|
29
|
+
get hasNextPage() {
|
|
30
|
+
return this.currentPageIndex < this.totalItemCount;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Value indicating whether a previous page exists.
|
|
34
|
+
*/
|
|
35
|
+
get hasPreviousPage() {
|
|
36
|
+
return this.currentPageIndex > 1;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The one-based last page number.
|
|
40
|
+
*/
|
|
41
|
+
get lastPageIndex() {
|
|
42
|
+
return Math.ceil(this.totalItemCount / this.itemsPerPage);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The data limit.
|
|
46
|
+
*/
|
|
47
|
+
get limit() {
|
|
48
|
+
return this.itemsPerPage;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The data offset.
|
|
52
|
+
*/
|
|
53
|
+
get offset() {
|
|
54
|
+
return (this.currentPageIndex - 1) * this.itemsPerPage;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The search parameters corresponding to this object.
|
|
58
|
+
*/
|
|
59
|
+
get searchParams() {
|
|
60
|
+
return new URLSearchParams({ page: this.currentPageIndex.toString(), perPage: this.itemsPerPage.toString() });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new pagination from the HTTP headers of the specified response.
|
|
64
|
+
* @param response A server response.
|
|
65
|
+
* @returns The pagination corresponding to the HTTP headers of the specified response.
|
|
66
|
+
*/
|
|
67
|
+
static fromResponse(response) {
|
|
68
|
+
return new this({
|
|
69
|
+
currentPageIndex: Number(response.headers.get("X-Pagination-Current-Page") ?? "1"),
|
|
70
|
+
itemsPerPage: Number(response.headers.get("X-Pagination-Per-Page") ?? "25"),
|
|
71
|
+
totalItemCount: Number(response.headers.get("X-Pagination-Total-Count") ?? "0")
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LitElement, type CSSResultGroup } from "lit";
|
|
2
|
+
/**
|
|
3
|
+
* The optional base class for UI components. Alternatively, components may extend {@link LitElement} directly.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class Component extends LitElement {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* The component styles.
|
|
9
|
+
*/
|
|
10
|
+
static styles: CSSResultGroup;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new component.
|
|
13
|
+
* @param options Value indicating whether this component uses a shadow root.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: {
|
|
16
|
+
shadowRoot?: boolean;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Returns the node into which this component should render.
|
|
20
|
+
* @returns The node into which this component should render.
|
|
21
|
+
*/
|
|
22
|
+
protected createRenderRoot(): DocumentFragment | HTMLElement;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Component.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,KAAK,cAAc,EAAC,MAAM,KAAK,CAAC;AAEpD;;GAEG;AACH,8BAAsB,SAAU,SAAQ,UAAU;;IAEjD;;OAEG;IACH,OAAgB,MAAM,EAAE,cAAc,CAAiC;IAOvE;;;OAGG;gBACS,OAAO,GAAE;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAM;IAKhD;;;OAGG;cACgB,gBAAgB,IAAI,gBAAgB,GAAC,WAAW;CAGnE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
/**
|
|
3
|
+
* The optional base class for UI components. Alternatively, components may extend {@link LitElement} directly.
|
|
4
|
+
*/
|
|
5
|
+
export class Component extends LitElement {
|
|
6
|
+
/**
|
|
7
|
+
* The component styles.
|
|
8
|
+
*/
|
|
9
|
+
static styles = [document.adoptedStyleSheets];
|
|
10
|
+
/**
|
|
11
|
+
* Value indicating whether this component uses a shadow root.
|
|
12
|
+
*/
|
|
13
|
+
#useShadowRoot;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new component.
|
|
16
|
+
* @param options Value indicating whether this component uses a shadow root.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
super();
|
|
20
|
+
this.#useShadowRoot = options.shadowRoot ?? false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the node into which this component should render.
|
|
24
|
+
* @returns The node into which this component should render.
|
|
25
|
+
*/
|
|
26
|
+
createRenderRoot() {
|
|
27
|
+
return this.#useShadowRoot ? super.createRenderRoot() : this;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/lib/UI/MenuActivator.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AppTheme } from "#Html/AppTheme.js";
|
|
1
2
|
/**
|
|
2
3
|
* A dropdown menu for switching the application theme.
|
|
3
4
|
*/
|
|
@@ -7,6 +8,11 @@ export declare class ThemeDropdown extends HTMLElement {
|
|
|
7
8
|
* Creates a new theme dropdown.
|
|
8
9
|
*/
|
|
9
10
|
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* The current application theme.
|
|
13
|
+
*/
|
|
14
|
+
get theme(): AppTheme;
|
|
15
|
+
set theme(value: AppTheme);
|
|
10
16
|
/**
|
|
11
17
|
* Method invoked when this component is connected.
|
|
12
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../src/Client/UI/ThemeDropdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../src/Client/UI/ThemeDropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAU,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAiB7C;;OAEG;;IAeH;;OAEG;IACH,IAAI,KAAK,IAAI,QAAQ,CAEpB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,QAAQ,EAGxB;IAED;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;OAEG;IACH,WAAW,IAAI,IAAI;CAsBnB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
|
package/lib/UI/ThemeDropdown.js
CHANGED
|
@@ -31,6 +31,16 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
31
31
|
static {
|
|
32
32
|
customElements.define("theme-dropdown", this);
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The current application theme.
|
|
36
|
+
*/
|
|
37
|
+
get theme() {
|
|
38
|
+
return this.#theme;
|
|
39
|
+
}
|
|
40
|
+
set theme(value) {
|
|
41
|
+
localStorage.setItem(this.#storageKey, this.#theme = value);
|
|
42
|
+
this.#applyTheme();
|
|
43
|
+
}
|
|
34
44
|
/**
|
|
35
45
|
* Method invoked when this component is connected.
|
|
36
46
|
*/
|
|
@@ -65,7 +75,6 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
65
75
|
*/
|
|
66
76
|
#setTheme(event) {
|
|
67
77
|
const button = event.target.closest("button");
|
|
68
|
-
|
|
69
|
-
this.#applyTheme();
|
|
78
|
+
this.theme = button.dataset.theme;
|
|
70
79
|
}
|
|
71
80
|
}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"name": "@cedx/base",
|
|
8
8
|
"repository": "cedx/base",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.6.0",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@playwright/browser-chromium": "^1.54.2",
|
|
13
13
|
"@types/bootstrap": "^5.2.10",
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"library"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"bootstrap": ">=5.3.0"
|
|
53
|
+
"bootstrap": ">=5.3.0",
|
|
54
|
+
"lit": ">=3.3.0"
|
|
54
55
|
},
|
|
55
56
|
"publishConfig": {
|
|
56
57
|
"access": "public"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {Pagination} from "./Pagination.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A list with information relevant to the pagination of its items.
|
|
5
|
+
*/
|
|
6
|
+
export class PaginatedList<T> extends Array<T> {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The information relevant to the pagination of the list items.
|
|
10
|
+
*/
|
|
11
|
+
pagination: Pagination;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new paginated list.
|
|
15
|
+
* @param options An object providing values to initialize this instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(options: PaginatedListOptions<T> = {}) {
|
|
18
|
+
super();
|
|
19
|
+
for (const item of options.items ?? []) this.push(item);
|
|
20
|
+
this.pagination = options.pagination ?? new Pagination;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates an empty paginated list.
|
|
25
|
+
* @param itemsPerPage The number of items per page.
|
|
26
|
+
* @returns An empty paginated list with the specified number of items per page.
|
|
27
|
+
*/
|
|
28
|
+
static empty<T>(itemsPerPage: number): PaginatedList<T> {
|
|
29
|
+
return new this({pagination: new Pagination({itemsPerPage})});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Defines the options of a {@link PaginatedList} instance.
|
|
35
|
+
*/
|
|
36
|
+
export type PaginatedListOptions<T> = Partial<{
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The list items.
|
|
40
|
+
*/
|
|
41
|
+
items: T[];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The information relevant to the pagination of the list items.
|
|
45
|
+
*/
|
|
46
|
+
pagination: Pagination;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents information relevant to the pagination of data items.
|
|
3
|
+
*/
|
|
4
|
+
export class Pagination {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one-based current page number.
|
|
8
|
+
*/
|
|
9
|
+
currentPageIndex: number;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The number of items per page.
|
|
13
|
+
*/
|
|
14
|
+
itemsPerPage: number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The total number of items.
|
|
18
|
+
*/
|
|
19
|
+
totalItemCount: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new pagination.
|
|
23
|
+
* @param options An object providing values to initialize this instance.
|
|
24
|
+
*/
|
|
25
|
+
constructor(options: PaginationOptions = {}) {
|
|
26
|
+
this.currentPageIndex = Math.max(1, options.currentPageIndex ?? 1);
|
|
27
|
+
this.itemsPerPage = Math.max(1, Math.min(1000, options.itemsPerPage ?? 25));
|
|
28
|
+
this.totalItemCount = Math.max(0, options.totalItemCount ?? 0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Value indicating whether a next page exists.
|
|
33
|
+
*/
|
|
34
|
+
get hasNextPage(): boolean {
|
|
35
|
+
return this.currentPageIndex < this.totalItemCount;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Value indicating whether a previous page exists.
|
|
40
|
+
*/
|
|
41
|
+
get hasPreviousPage(): boolean {
|
|
42
|
+
return this.currentPageIndex > 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The one-based last page number.
|
|
47
|
+
*/
|
|
48
|
+
get lastPageIndex(): number {
|
|
49
|
+
return Math.ceil(this.totalItemCount / this.itemsPerPage);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The data limit.
|
|
54
|
+
*/
|
|
55
|
+
get limit(): number {
|
|
56
|
+
return this.itemsPerPage;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The data offset.
|
|
61
|
+
*/
|
|
62
|
+
get offset(): number {
|
|
63
|
+
return (this.currentPageIndex - 1) * this.itemsPerPage;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The search parameters corresponding to this object.
|
|
68
|
+
*/
|
|
69
|
+
get searchParams(): URLSearchParams {
|
|
70
|
+
return new URLSearchParams({page: this.currentPageIndex.toString(), perPage: this.itemsPerPage.toString()});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new pagination from the HTTP headers of the specified response.
|
|
75
|
+
* @param response A server response.
|
|
76
|
+
* @returns The pagination corresponding to the HTTP headers of the specified response.
|
|
77
|
+
*/
|
|
78
|
+
static fromResponse(response: Response): Pagination {
|
|
79
|
+
return new this({
|
|
80
|
+
currentPageIndex: Number(response.headers.get("X-Pagination-Current-Page") ?? "1"),
|
|
81
|
+
itemsPerPage: Number(response.headers.get("X-Pagination-Per-Page") ?? "25"),
|
|
82
|
+
totalItemCount: Number(response.headers.get("X-Pagination-Total-Count") ?? "0")
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Defines the options of a {@link Pagination} instance.
|
|
89
|
+
*/
|
|
90
|
+
export type PaginationOptions = Partial<Pick<Pagination, "currentPageIndex"|"itemsPerPage"|"totalItemCount">>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {LitElement, type CSSResultGroup} from "lit";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The optional base class for UI components. Alternatively, components may extend {@link LitElement} directly.
|
|
5
|
+
*/
|
|
6
|
+
export abstract class Component extends LitElement {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The component styles.
|
|
10
|
+
*/
|
|
11
|
+
static override styles: CSSResultGroup = [document.adoptedStyleSheets];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Value indicating whether this component uses a shadow root.
|
|
15
|
+
*/
|
|
16
|
+
readonly #useShadowRoot: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new component.
|
|
20
|
+
* @param options Value indicating whether this component uses a shadow root.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options: {shadowRoot?: boolean} = {}) {
|
|
23
|
+
super();
|
|
24
|
+
this.#useShadowRoot = options.shadowRoot ?? false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the node into which this component should render.
|
|
29
|
+
* @returns The node into which this component should render.
|
|
30
|
+
*/
|
|
31
|
+
protected override createRenderRoot(): DocumentFragment|HTMLElement {
|
|
32
|
+
return this.#useShadowRoot ? super.createRenderRoot() : this;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -37,6 +37,17 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
37
37
|
customElements.define("theme-dropdown", this);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The current application theme.
|
|
42
|
+
*/
|
|
43
|
+
get theme(): AppTheme {
|
|
44
|
+
return this.#theme;
|
|
45
|
+
}
|
|
46
|
+
set theme(value: AppTheme) {
|
|
47
|
+
localStorage.setItem(this.#storageKey, this.#theme = value);
|
|
48
|
+
this.#applyTheme();
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
/**
|
|
41
52
|
* Method invoked when this component is connected.
|
|
42
53
|
*/
|
|
@@ -75,8 +86,7 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
75
86
|
*/
|
|
76
87
|
#setTheme(event: Event): void {
|
|
77
88
|
const button = (event.target as HTMLElement).closest("button")!;
|
|
78
|
-
|
|
79
|
-
this.#applyTheme();
|
|
89
|
+
this.theme = button.dataset.theme as AppTheme;
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
92
|
|
package/lib/UI/ActionBar.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An action bar located under the navigation bar.
|
|
3
|
-
*/
|
|
4
|
-
export declare class ActionBar extends HTMLElement {
|
|
5
|
-
/**
|
|
6
|
-
* Method invoked when this component is connected.
|
|
7
|
-
*/
|
|
8
|
-
connectedCallback(): void;
|
|
9
|
-
/**
|
|
10
|
-
* Method invoked when this component is disconnected.
|
|
11
|
-
*/
|
|
12
|
-
disconnectedCallback(): void;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Declaration merging.
|
|
16
|
-
*/
|
|
17
|
-
declare global {
|
|
18
|
-
/**
|
|
19
|
-
* The map of HTML tag names.
|
|
20
|
-
*/
|
|
21
|
-
interface HTMLElementTagNameMap {
|
|
22
|
-
"action-bar": ActionBar;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=ActionBar.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ActionBar.d.ts","sourceRoot":"","sources":["../../src/Client/UI/ActionBar.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;IASzC;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAMzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAG5B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,YAAY,EAAE,SAAS,CAAC;KACxB;CACD"}
|
package/lib/UI/ActionBar.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An action bar located under the navigation bar.
|
|
3
|
-
*/
|
|
4
|
-
export class ActionBar extends HTMLElement {
|
|
5
|
-
/**
|
|
6
|
-
* Registers the component.
|
|
7
|
-
*/
|
|
8
|
-
static {
|
|
9
|
-
customElements.define("action-bar", this);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Method invoked when this component is connected.
|
|
13
|
-
*/
|
|
14
|
-
connectedCallback() {
|
|
15
|
-
const navbarHeight = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--navbar-height"));
|
|
16
|
-
const mainOffset = this.offsetHeight + (Number.isNaN(navbarHeight) ? 0 : navbarHeight);
|
|
17
|
-
document.documentElement.style.setProperty("--main-offset", `${mainOffset}px`);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Method invoked when this component is disconnected.
|
|
21
|
-
*/
|
|
22
|
-
disconnectedCallback() {
|
|
23
|
-
document.documentElement.style.removeProperty("--main-offset");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents information relevant to the pagination of data items.
|
|
3
|
-
*/
|
|
4
|
-
export class Pagination {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The current page number.
|
|
8
|
-
*/
|
|
9
|
-
currentPage: number;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The number of items per page.
|
|
13
|
-
*/
|
|
14
|
-
itemsPerPage: number;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The total number of items.
|
|
18
|
-
*/
|
|
19
|
-
totalItemCount: number;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new pagination.
|
|
23
|
-
* @param options An object providing values to initialize this instance.
|
|
24
|
-
*/
|
|
25
|
-
constructor(options: PaginationOptions = {}) {
|
|
26
|
-
this.currentPage = Math.max(1, options.currentPage ?? 1);
|
|
27
|
-
this.itemsPerPage = Math.max(1, Math.min(1000, options.itemsPerPage ?? 25));
|
|
28
|
-
this.totalItemCount = Math.max(0, options.totalItemCount ?? 0);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The last page number.
|
|
33
|
-
*/
|
|
34
|
-
get lastPage(): number {
|
|
35
|
-
return Math.ceil(this.totalItemCount / this.itemsPerPage);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The data limit.
|
|
40
|
-
*/
|
|
41
|
-
get limit(): number {
|
|
42
|
-
return this.itemsPerPage;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The data offset.
|
|
47
|
-
*/
|
|
48
|
-
get offset(): number {
|
|
49
|
-
return (this.currentPage - 1) * this.itemsPerPage;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The search parameters corresponding to this object.
|
|
54
|
-
*/
|
|
55
|
-
get searchParams(): URLSearchParams {
|
|
56
|
-
return new URLSearchParams({page: this.currentPage.toString(), perPage: this.itemsPerPage.toString()});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Creates a new pagination from the HTTP headers of the specified response.
|
|
61
|
-
* @param response A server response.
|
|
62
|
-
* @returns The pagination corresponding to the HTTP headers of the specified response.
|
|
63
|
-
*/
|
|
64
|
-
static fromResponse(response: Response): Pagination {
|
|
65
|
-
return new this({
|
|
66
|
-
currentPage: Number(response.headers.get("X-Pagination-Current-Page") ?? "1"),
|
|
67
|
-
itemsPerPage: Number(response.headers.get("X-Pagination-Per-Page") ?? "25"),
|
|
68
|
-
totalItemCount: Number(response.headers.get("X-Pagination-Total-Count") ?? "0")
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Defines the options of a {@link Pagination} instance.
|
|
75
|
-
*/
|
|
76
|
-
export type PaginationOptions = Partial<Pick<Pagination, "currentPage"|"itemsPerPage"|"totalItemCount">>;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* A list with information relevant to the pagination of its items.
|
|
80
|
-
*/
|
|
81
|
-
export class PaginatedList<T> implements Iterable<T, void, void> {
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The list items.
|
|
85
|
-
*/
|
|
86
|
-
items: T[];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The information relevant to the pagination of the list items.
|
|
90
|
-
*/
|
|
91
|
-
pagination: Pagination;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Creates a new paginated list.
|
|
95
|
-
* @param options An object providing values to initialize this instance.
|
|
96
|
-
*/
|
|
97
|
-
constructor(options: PaginatedListOptions<T> = {}) {
|
|
98
|
-
this.items = options.items ?? [];
|
|
99
|
-
this.pagination = options.pagination ?? new Pagination;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The number of items in this list.
|
|
104
|
-
*/
|
|
105
|
-
get length(): number {
|
|
106
|
-
return this.items.length;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Creates an empty paginated list.
|
|
111
|
-
* @param itemsPerPage The number of items per page.
|
|
112
|
-
* @returns An empty paginated list with the specified number of items per page.
|
|
113
|
-
*/
|
|
114
|
-
static empty<T>(itemsPerPage: number): PaginatedList<T> {
|
|
115
|
-
return new this({pagination: new Pagination({itemsPerPage})});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Returns a new iterator that allows iterating the items of this list.
|
|
120
|
-
* @returns An iterator over the items of this list.
|
|
121
|
-
*/
|
|
122
|
-
*[Symbol.iterator](): Generator<T, void, void> {
|
|
123
|
-
for (const item of this.items) yield item;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Defines the options of a {@link PaginatedList} instance.
|
|
129
|
-
*/
|
|
130
|
-
export type PaginatedListOptions<T> = Partial<Pick<PaginatedList<T>, "items"|"pagination">>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An action bar located under the navigation bar.
|
|
3
|
-
*/
|
|
4
|
-
export class ActionBar extends HTMLElement {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Registers the component.
|
|
8
|
-
*/
|
|
9
|
-
static {
|
|
10
|
-
customElements.define("action-bar", this);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Method invoked when this component is connected.
|
|
15
|
-
*/
|
|
16
|
-
connectedCallback(): void {
|
|
17
|
-
const navbarHeight = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--navbar-height"));
|
|
18
|
-
const mainOffset = this.offsetHeight + (Number.isNaN(navbarHeight) ? 0 : navbarHeight);
|
|
19
|
-
document.documentElement.style.setProperty("--main-offset", `${mainOffset}px`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Method invoked when this component is disconnected.
|
|
24
|
-
*/
|
|
25
|
-
disconnectedCallback(): void {
|
|
26
|
-
document.documentElement.style.removeProperty("--main-offset");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Declaration merging.
|
|
32
|
-
*/
|
|
33
|
-
declare global {
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The map of HTML tag names.
|
|
37
|
-
*/
|
|
38
|
-
interface HTMLElementTagNameMap {
|
|
39
|
-
"action-bar": ActionBar;
|
|
40
|
-
}
|
|
41
|
-
}
|