@cedx/ui 0.11.0 → 0.13.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.
@@ -43,6 +43,13 @@ export declare class Pagination {
43
43
  */
44
44
  get totalItemCount(): number;
45
45
  set totalItemCount(value: number);
46
+ /**
47
+ * Creates a new pagination from the specified query.
48
+ * @param query The search parameters providing the query.
49
+ * @param maxItemsPerPage The maximum number of items allowed per page.
50
+ * @returns The pagination corresponding to the specified query.
51
+ */
52
+ static fromQuery(query: URLSearchParams, maxItemsPerPage?: number): Pagination;
46
53
  }
47
54
  /**
48
55
  * Defines the options of a {@link Pagination} instance.
@@ -61,4 +68,37 @@ export type PaginationOptions = Partial<{
61
68
  */
62
69
  totalItemCount: number;
63
70
  }>;
71
+ /**
72
+ * A list with information relevant to the pagination of its items.
73
+ */
74
+ export declare class PaginatedList<T> extends Array<T> {
75
+ /**
76
+ * The information relevant to the pagination of list items.
77
+ */
78
+ pagination: Pagination;
79
+ /**
80
+ * Creates a new paginated list.
81
+ * @param options An object providing values to initialize this instance.
82
+ */
83
+ constructor(options?: PaginatedListOptions<T>);
84
+ /**
85
+ * Creates an empty paginated list.
86
+ * @param itemsPerPage The number of items per page.
87
+ * @returns An empty paginated list with the specified number of items per page.
88
+ */
89
+ static empty<T>(itemsPerPage: number): PaginatedList<T>;
90
+ }
91
+ /**
92
+ * Defines the options of a {@link PaginatedList} instance.
93
+ */
94
+ export type PaginatedListOptions<T> = Partial<{
95
+ /**
96
+ * The list items.
97
+ */
98
+ items: T[];
99
+ /**
100
+ * The information relevant to the pagination of list items.
101
+ */
102
+ pagination: Pagination;
103
+ }>;
64
104
  //# 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,iBAAs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I,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;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,SAAO,GAAG,UAAU;CAQ5E;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"}
@@ -80,4 +80,45 @@ export class Pagination {
80
80
  set totalItemCount(value) {
81
81
  this.#totalItemCount = Math.max(0, value);
82
82
  }
83
+ /**
84
+ * Creates a new pagination from the specified query.
85
+ * @param query The search parameters providing the query.
86
+ * @param maxItemsPerPage The maximum number of items allowed per page.
87
+ * @returns The pagination corresponding to the specified query.
88
+ */
89
+ static fromQuery(query, maxItemsPerPage = 1000) {
90
+ const currentPage = Number(query.get("Page") ?? "1");
91
+ const itemsPerPage = Number(query.get("PerPage") ?? "25");
92
+ return new this({
93
+ currentPageIndex: (Number.isNaN(currentPage) ? 1 : currentPage) - 1,
94
+ itemsPerPage: Math.min(maxItemsPerPage, Number.isNaN(itemsPerPage) ? 25 : itemsPerPage)
95
+ });
96
+ }
97
+ }
98
+ /**
99
+ * A list with information relevant to the pagination of its items.
100
+ */
101
+ export class PaginatedList extends Array {
102
+ /**
103
+ * The information relevant to the pagination of list items.
104
+ */
105
+ pagination;
106
+ /**
107
+ * Creates a new paginated list.
108
+ * @param options An object providing values to initialize this instance.
109
+ */
110
+ constructor(options = {}) {
111
+ super();
112
+ for (const item of options.items ?? [])
113
+ this.push(item);
114
+ this.pagination = options.pagination ?? new Pagination;
115
+ }
116
+ /**
117
+ * Creates an empty paginated list.
118
+ * @param itemsPerPage The number of items per page.
119
+ * @returns An empty paginated list with the specified number of items per page.
120
+ */
121
+ static empty(itemsPerPage) {
122
+ return new this({ pagination: new Pagination({ itemsPerPage }) });
123
+ }
83
124
  }
@@ -92,6 +92,21 @@ export class Pagination {
92
92
  set totalItemCount(value: number) {
93
93
  this.#totalItemCount = Math.max(0, value);
94
94
  }
95
+
96
+ /**
97
+ * Creates a new pagination from the specified query.
98
+ * @param query The search parameters providing the query.
99
+ * @param maxItemsPerPage The maximum number of items allowed per page.
100
+ * @returns The pagination corresponding to the specified query.
101
+ */
102
+ static fromQuery(query: URLSearchParams, maxItemsPerPage = 1000): Pagination {
103
+ const currentPage = Number(query.get("Page") ?? "1");
104
+ const itemsPerPage = Number(query.get("PerPage") ?? "25");
105
+ return new this({
106
+ currentPageIndex: (Number.isNaN(currentPage) ? 1 : currentPage) - 1,
107
+ itemsPerPage: Math.min(maxItemsPerPage, Number.isNaN(itemsPerPage) ? 25 : itemsPerPage)
108
+ });
109
+ }
95
110
  }
96
111
 
97
112
  /**
@@ -114,3 +129,49 @@ export type PaginationOptions = Partial<{
114
129
  */
115
130
  totalItemCount: number;
116
131
  }>;
132
+
133
+ /**
134
+ * A list with information relevant to the pagination of its items.
135
+ */
136
+ export class PaginatedList<T> extends Array<T> {
137
+
138
+ /**
139
+ * The information relevant to the pagination of list items.
140
+ */
141
+ pagination: Pagination;
142
+
143
+ /**
144
+ * Creates a new paginated list.
145
+ * @param options An object providing values to initialize this instance.
146
+ */
147
+ constructor(options: PaginatedListOptions<T> = {}) {
148
+ super();
149
+ for (const item of options.items ?? []) this.push(item);
150
+ this.pagination = options.pagination ?? new Pagination;
151
+ }
152
+
153
+ /**
154
+ * Creates an empty paginated list.
155
+ * @param itemsPerPage The number of items per page.
156
+ * @returns An empty paginated list with the specified number of items per page.
157
+ */
158
+ static empty<T>(itemsPerPage: number): PaginatedList<T> {
159
+ return new this({pagination: new Pagination({itemsPerPage})});
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Defines the options of a {@link PaginatedList} instance.
165
+ */
166
+ export type PaginatedListOptions<T> = Partial<{
167
+
168
+ /**
169
+ * The list items.
170
+ */
171
+ items: T[];
172
+
173
+ /**
174
+ * The information relevant to the pagination of list items.
175
+ */
176
+ pagination: Pagination;
177
+ }>;
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.11.0",
10
+ "version": "0.13.0",
11
11
  "allowScripts": {
12
12
  "esbuild": true,
13
13
  "playwright-firefox": true