@cedx/ui 0.10.0 → 0.12.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.
@@ -61,4 +61,37 @@ export type PaginationOptions = Partial<{
61
61
  */
62
62
  totalItemCount: number;
63
63
  }>;
64
+ /**
65
+ * A list with information relevant to the pagination of its items.
66
+ */
67
+ export declare class PaginatedList<T> extends Array<T> {
68
+ /**
69
+ * The information relevant to the pagination of list items.
70
+ */
71
+ pagination: Pagination;
72
+ /**
73
+ * Creates a new paginated list.
74
+ * @param options An object providing values to initialize this instance.
75
+ */
76
+ constructor(options?: PaginatedListOptions<T>);
77
+ /**
78
+ * Creates an empty paginated list.
79
+ * @param itemsPerPage The number of items per page.
80
+ * @returns An empty paginated list with the specified number of items per page.
81
+ */
82
+ static empty<T>(itemsPerPage: number): PaginatedList<T>;
83
+ }
84
+ /**
85
+ * Defines the options of a {@link PaginatedList} instance.
86
+ */
87
+ export type PaginatedListOptions<T> = Partial<{
88
+ /**
89
+ * The list items.
90
+ */
91
+ items: T[];
92
+ /**
93
+ * The information relevant to the pagination of list items.
94
+ */
95
+ pagination: Pagination;
96
+ }>;
64
97
  //# sourceMappingURL=Pagination.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../Sources/Client/Pagination.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAU;;IAiBtB;;;OAGG;gBACS,OAAO,GAAE,iBAAsB;IAM3C;;OAEG;IACH,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IACD,IAAI,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAEjC;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IACD,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAE7B;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,cAAc,IAAI,MAAM,CAE3B;IACD,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,EAE/B;CACD;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACvB,CAAC,CAAC"}
1
+ {"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../Sources/Client/Pagination.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAU;;IAiBtB;;;OAGG;gBACS,OAAO,GAAE,iBAAsB;IAM3C;;OAEG;IACH,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IACD,IAAI,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAEjC;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IACD,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAE7B;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,cAAc,IAAI,MAAM,CAE3B;IACD,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,EAE/B;CACD;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACvB,CAAC,CAAC;AAEH;;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"}
@@ -81,3 +81,30 @@ export class Pagination {
81
81
  this.#totalItemCount = Math.max(0, value);
82
82
  }
83
83
  }
84
+ /**
85
+ * A list with information relevant to the pagination of its items.
86
+ */
87
+ export class PaginatedList extends Array {
88
+ /**
89
+ * The information relevant to the pagination of list items.
90
+ */
91
+ pagination;
92
+ /**
93
+ * Creates a new paginated list.
94
+ * @param options An object providing values to initialize this instance.
95
+ */
96
+ constructor(options = {}) {
97
+ super();
98
+ for (const item of options.items ?? [])
99
+ this.push(item);
100
+ this.pagination = options.pagination ?? new Pagination;
101
+ }
102
+ /**
103
+ * Creates an empty paginated list.
104
+ * @param itemsPerPage The number of items per page.
105
+ * @returns An empty paginated list with the specified number of items per page.
106
+ */
107
+ static empty(itemsPerPage) {
108
+ return new this({ pagination: new Pagination({ itemsPerPage }) });
109
+ }
110
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts the first character of the specified string to uppercase.
3
+ * @param value The string to process.
4
+ * @param culture The current culture.
5
+ * @returns The processed string.
6
+ */
7
+ export declare function capitalize(value: string, culture?: Intl.Locale | string): string;
8
+ /**
9
+ * Truncates the specified string to the given number of characters.
10
+ * @param value The string to be truncated.
11
+ * @param length The maximum length.
12
+ * @param ellipsis The ellipsis to append to the truncated text.
13
+ * @returns The truncated string.
14
+ */
15
+ export declare function truncate(value: string, length: number, ellipsis?: string): string;
16
+ //# sourceMappingURL=String.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../Sources/Client/String.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,MAAM,GAAC,MAA2B,GAAG,MAAM,CAElG;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAEhF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Converts the first character of the specified string to uppercase.
3
+ * @param value The string to process.
4
+ * @param culture The current culture.
5
+ * @returns The processed string.
6
+ */
7
+ export function capitalize(value, culture = navigator.language) {
8
+ return value.length ? value.charAt(0).toLocaleUpperCase(culture) + value.slice(1) : "";
9
+ }
10
+ /**
11
+ * Truncates the specified string to the given number of characters.
12
+ * @param value The string to be truncated.
13
+ * @param length The maximum length.
14
+ * @param ellipsis The ellipsis to append to the truncated text.
15
+ * @returns The truncated string.
16
+ */
17
+ export function truncate(value, length, ellipsis = "...") {
18
+ return value.length > length ? value.slice(0, length) + ellipsis : value;
19
+ }
@@ -0,0 +1,59 @@
1
+ package Belin.UI;
2
+
3
+ import coconut.ui.View;
4
+ import js.Browser;
5
+ import js.Syntax;
6
+ import js.html.Element;
7
+ import js.html.InputElement;
8
+ import js.html.TextAreaElement;
9
+
10
+ /** Counts the number of characters in a form control. **/
11
+ class CharacterCounter extends View {
12
+
13
+ /** The maximum number of allowed characters. **/
14
+ @:attribute var maxLength = -1;
15
+
16
+ /** The CSS selector used to target the form control. **/
17
+ @:attribute var target: String;
18
+
19
+ /** The number of remaining characters. **/
20
+ @:computed var remaining: Int = maxLength >= 0 ? maxLength - value : Syntax.code("Number.MAX_SAFE_INTEGER");
21
+
22
+ /** The current number of characters. **/
23
+ @:state var value = 0;
24
+
25
+ /** The associated form control. **/
26
+ var element: Null<Element> = null;
27
+
28
+ /** Counts the number of characters in the associated form control. **/
29
+ function countCharacters() switch Type.getClass(element) {
30
+ case InputElement: value = (cast element: InputElement).value.length;
31
+ case TextAreaElement: value = (cast element: TextAreaElement).value.length;
32
+ }
33
+
34
+ /** Renders this view. **/
35
+ function render() '
36
+ <span class=${{
37
+ badge: true,
38
+ "bg-danger": maxLength >= 0 && remaining < 0,
39
+ "bg-success": maxLength >= 0 && remaining >= 0,
40
+ "text-bg-secondary": maxLength < 0
41
+ }}>
42
+ $value
43
+ <if ${maxLength >= 0}>/$maxLength</if>
44
+ </span>
45
+ ';
46
+
47
+ /** Method invoked after this view is mounted. **/
48
+ override function viewDidMount() {
49
+ element = Browser.document.querySelector(target);
50
+ element.addEventListener("change", countCharacters);
51
+ element.addEventListener("input", countCharacters);
52
+
53
+ Callback.defer(countCharacters);
54
+ beforeUnmounting(() -> {
55
+ element.removeEventListener("change", countCharacters);
56
+ element.removeEventListener("input", countCharacters);
57
+ });
58
+ }
59
+ }
@@ -0,0 +1,80 @@
1
+ package Belin.UI;
2
+
3
+ import coconut.ui.View;
4
+ import js.html.Element;
5
+ import js.html.Event;
6
+ import core.data.Pagination;
7
+
8
+ /** Displays links relevant to the pagination of data items. **/
9
+ class Pager extends View {
10
+
11
+ /** The pager alignment. **/
12
+ @:attribute var alignment: PagerAlignment = Center;
13
+
14
+ /** The handler invoked when the current page has been changed. **/
15
+ @:attribute var onNavigate: Callback<Int>;
16
+
17
+ /** The underlying pagination model. **/
18
+ @:attribute var pagination: Pagination;
19
+
20
+ /** The number of items displayed around the active item. **/
21
+ @:attribute var sideItems: Int = 1;
22
+
23
+ /** Navigates to the specified page. **/
24
+ public function navigate(page: Int, ?event: Event) {
25
+ if (event != null) (cast event.currentTarget: Element).blur();
26
+ if (page >= 1 && page <= pagination.pageCount && page != pagination.page) onNavigate.invoke(page);
27
+ }
28
+
29
+ /** Gets the list of buttons to display. **/
30
+ function getItems() {
31
+ final start = Std.int(Math.max(1, pagination.page - sideItems));
32
+ final end = Std.int(Math.min(pagination.pageCount, pagination.page + sideItems));
33
+
34
+ final items = [];
35
+ if (start > 1) items.push(1);
36
+ if (start > 2) items.push(0);
37
+ for (index in start...(end + 1)) items.push(index);
38
+ if (end < pagination.pageCount - 1) items.push(0);
39
+ if (end < pagination.pageCount) items.push(pagination.pageCount);
40
+ return items;
41
+ }
42
+
43
+ /** Renders this view. **/
44
+ function render() '
45
+ <if ${pagination.pageCount > 1}>
46
+ <nav>
47
+ <ul class=${['pagination justify-content-$alignment' => true]}>
48
+ <li class=${{disabled: pagination.page <= 1, "page-item": true}}>
49
+ <button class="page-link" onclick=${navigate(pagination.page - 1, event)} type=${Button}>
50
+ <i class="icon">chevron_left</i><span class="d-none d-sm-inline ms-1">Précédent</span>
51
+ </button>
52
+ </li>
53
+ <for ${index in getItems()}>
54
+ <li class=${{active: index == pagination.page, disabled: index == 0, "page-item": true}}>
55
+ <button class="page-link" onclick=${navigate(index, event)} type=${Button}>${index == 0 ? "..." : index}</button>
56
+ </li>
57
+ </for>
58
+ <li class=${{disabled: pagination.page >= pagination.pageCount, "page-item": true}}>
59
+ <button class="page-link" onclick=${navigate(pagination.page + 1, event)} type=${Button}>
60
+ <span class="d-none d-sm-inline me-1">Suivant</span><i class="icon">chevron_right</i>
61
+ </button>
62
+ </li>
63
+ </ul>
64
+ </nav>
65
+ </if>
66
+ ';
67
+ }
68
+
69
+ /** Defines the alignment of a pager. **/
70
+ enum abstract PagerAlignment(String) {
71
+
72
+ /** The pager is aligned to the end. **/
73
+ var End = "end";
74
+
75
+ /** The pager is aligned to the center. **/
76
+ var Center = "center";
77
+
78
+ /** The pager is aligned to the start. **/
79
+ var Start = "start";
80
+ }
@@ -114,3 +114,49 @@ export type PaginationOptions = Partial<{
114
114
  */
115
115
  totalItemCount: number;
116
116
  }>;
117
+
118
+ /**
119
+ * A list with information relevant to the pagination of its items.
120
+ */
121
+ export class PaginatedList<T> extends Array<T> {
122
+
123
+ /**
124
+ * The information relevant to the pagination of list items.
125
+ */
126
+ pagination: Pagination;
127
+
128
+ /**
129
+ * Creates a new paginated list.
130
+ * @param options An object providing values to initialize this instance.
131
+ */
132
+ constructor(options: PaginatedListOptions<T> = {}) {
133
+ super();
134
+ for (const item of options.items ?? []) this.push(item);
135
+ this.pagination = options.pagination ?? new Pagination;
136
+ }
137
+
138
+ /**
139
+ * Creates an empty paginated list.
140
+ * @param itemsPerPage The number of items per page.
141
+ * @returns An empty paginated list with the specified number of items per page.
142
+ */
143
+ static empty<T>(itemsPerPage: number): PaginatedList<T> {
144
+ return new this({pagination: new Pagination({itemsPerPage})});
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Defines the options of a {@link PaginatedList} instance.
150
+ */
151
+ export type PaginatedListOptions<T> = Partial<{
152
+
153
+ /**
154
+ * The list items.
155
+ */
156
+ items: T[];
157
+
158
+ /**
159
+ * The information relevant to the pagination of list items.
160
+ */
161
+ pagination: Pagination;
162
+ }>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Converts the first character of the specified string to uppercase.
3
+ * @param value The string to process.
4
+ * @param culture The current culture.
5
+ * @returns The processed string.
6
+ */
7
+ export function capitalize(value: string, culture: Intl.Locale|string = navigator.language): string {
8
+ return value.length ? value.charAt(0).toLocaleUpperCase(culture) + value.slice(1) : "";
9
+ }
10
+
11
+ /**
12
+ * Truncates the specified string to the given number of characters.
13
+ * @param value The string to be truncated.
14
+ * @param length The maximum length.
15
+ * @param ellipsis The ellipsis to append to the truncated text.
16
+ * @returns The truncated string.
17
+ */
18
+ export function truncate(value: string, length: number, ellipsis = "..."): string {
19
+ return value.length > length ? value.slice(0, length) + ellipsis : value;
20
+ }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "name": "@cedx/ui",
8
8
  "repository": "CedX/UI",
9
9
  "type": "module",
10
- "version": "0.10.0",
10
+ "version": "0.12.0",
11
11
  "allowScripts": {
12
12
  "esbuild": true,
13
13
  "playwright-firefox": true