@bootkit/ng0 0.0.0-alpha.3 → 0.0.0-alpha.31
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/common/index.d.ts +271 -7
- package/components/accordion/index.d.ts +1 -1
- package/components/backdrop/index.d.ts +12 -0
- package/components/button/index.d.ts +48 -0
- package/components/card/index.d.ts +27 -0
- package/components/code/index.d.ts +35 -0
- package/components/confirmation/index.d.ts +66 -0
- package/components/dropdown/index.d.ts +140 -0
- package/components/form-field/index.d.ts +24 -41
- package/components/list/index.d.ts +259 -0
- package/components/modal/index.d.ts +22 -4
- package/components/nav/index.d.ts +23 -19
- package/components/pagination/index.d.ts +35 -9
- package/components/popover/index.d.ts +1 -1
- package/components/select/index.d.ts +159 -0
- package/components/sidenav/index.d.ts +59 -0
- package/components/stepper/index.d.ts +26 -0
- package/components/table/index.d.ts +273 -0
- package/components/toast/index.d.ts +1 -1
- package/components/tooltip/index.d.ts +1 -1
- package/components/vertical-menu/index.d.ts +61 -0
- package/data/index.d.ts +145 -45
- package/date/index.d.ts +34 -0
- package/fesm2022/bootkit-ng0-common.mjs +295 -12
- package/fesm2022/bootkit-ng0-common.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-accordion.mjs +13 -13
- package/fesm2022/bootkit-ng0-components-accordion.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-backdrop.mjs +46 -0
- package/fesm2022/bootkit-ng0-components-backdrop.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-button.mjs +119 -0
- package/fesm2022/bootkit-ng0-components-button.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-card.mjs +62 -0
- package/fesm2022/bootkit-ng0-components-card.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-code.mjs +70 -0
- package/fesm2022/bootkit-ng0-components-code.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-collapse.mjs +14 -14
- package/fesm2022/bootkit-ng0-components-collapse.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-confirmation.mjs +167 -0
- package/fesm2022/bootkit-ng0-components-confirmation.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-dropdown.mjs +302 -0
- package/fesm2022/bootkit-ng0-components-dropdown.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-form-field.mjs +61 -83
- package/fesm2022/bootkit-ng0-components-form-field.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-list.mjs +563 -0
- package/fesm2022/bootkit-ng0-components-list.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-modal.mjs +40 -23
- package/fesm2022/bootkit-ng0-components-modal.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-nav.mjs +58 -59
- package/fesm2022/bootkit-ng0-components-nav.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-offcanvas.mjs +9 -9
- package/fesm2022/bootkit-ng0-components-offcanvas.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-overlay.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-pagination.mjs +58 -23
- package/fesm2022/bootkit-ng0-components-pagination.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-popover.mjs +10 -10
- package/fesm2022/bootkit-ng0-components-popover.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-select.mjs +446 -0
- package/fesm2022/bootkit-ng0-components-select.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-sidenav.mjs +153 -0
- package/fesm2022/bootkit-ng0-components-sidenav.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-stepper.mjs +91 -0
- package/fesm2022/bootkit-ng0-components-stepper.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-table.mjs +461 -0
- package/fesm2022/bootkit-ng0-components-table.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-toast.mjs +7 -7
- package/fesm2022/bootkit-ng0-components-toast.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-tooltip.mjs +8 -8
- package/fesm2022/bootkit-ng0-components-tooltip.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-vertical-menu.mjs +161 -0
- package/fesm2022/bootkit-ng0-components-vertical-menu.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-data.mjs +180 -90
- package/fesm2022/bootkit-ng0-data.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-date.mjs +50 -0
- package/fesm2022/bootkit-ng0-date.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-file.mjs +50 -0
- package/fesm2022/bootkit-ng0-file.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-form.mjs +514 -0
- package/fesm2022/bootkit-ng0-form.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-http.mjs +224 -176
- package/fesm2022/bootkit-ng0-http.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-layouts-layout1.mjs +138 -0
- package/fesm2022/bootkit-ng0-layouts-layout1.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-localization-locales.mjs +101 -0
- package/fesm2022/bootkit-ng0-localization-locales.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-localization.mjs +347 -105
- package/fesm2022/bootkit-ng0-localization.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-platform-browser.mjs +51 -0
- package/fesm2022/bootkit-ng0-platform-browser.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-routing.mjs +80 -0
- package/fesm2022/bootkit-ng0-routing.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-script.mjs +59 -0
- package/fesm2022/bootkit-ng0-script.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-security.mjs +17 -15
- package/fesm2022/bootkit-ng0-security.mjs.map +1 -1
- package/file/index.d.ts +22 -0
- package/form/index.d.ts +127 -0
- package/http/index.d.ts +138 -37
- package/layouts/layout1/index.d.ts +92 -0
- package/localization/index.d.ts +180 -41
- package/localization/locales/index.d.ts +7 -0
- package/package.json +94 -14
- package/platform/browser/index.d.ts +22 -0
- package/routing/index.d.ts +124 -0
- package/script/index.d.ts +27 -0
- package/security/index.d.ts +3 -9
|
@@ -1,89 +1,178 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { signal } from '@angular/core';
|
|
2
|
+
import { of, catchError, tap, Observable } from 'rxjs';
|
|
3
|
+
import { getEnumValues } from '@bootkit/ng0/common';
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* DataRequest class represents a request for data with pagination, filtering, sorting, and field selection.
|
|
7
|
+
* It is used to encapsulate the parameters needed to fetch data from a data source.
|
|
8
|
+
* It can be used with various data sources such as HTTP services, in-memory arrays, etc.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
3
11
|
class DataRequest {
|
|
4
|
-
|
|
5
|
-
pageSize;
|
|
6
|
-
computeTotal;
|
|
12
|
+
page;
|
|
7
13
|
filters;
|
|
8
14
|
sort;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
this.filters = filters;
|
|
14
|
-
this.sort = sort;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.filters.push(new DataRequestFilter(field, value, operator));
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
sortDescending(field) {
|
|
21
|
-
this.sort = new DataRequestSort(field, false);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
sortAscending(field) {
|
|
25
|
-
this.sort = new DataRequestSort(field, true);
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
static all() {
|
|
29
|
-
return new DataRequest(0, 1000000, false);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
class DataRequestSort {
|
|
33
|
-
field;
|
|
34
|
-
asc;
|
|
35
|
-
constructor(field, asc = true) {
|
|
36
|
-
this.field = field;
|
|
37
|
-
this.asc = asc;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
class DataRequestFilter {
|
|
41
|
-
field;
|
|
42
|
-
value;
|
|
43
|
-
operator;
|
|
44
|
-
constructor(field, value, operator = DataRequestFilterOperator.EQ) {
|
|
45
|
-
this.field = field;
|
|
46
|
-
this.value = value;
|
|
47
|
-
this.operator = operator;
|
|
15
|
+
select;
|
|
16
|
+
computeTotal;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.page = options?.page;
|
|
19
|
+
this.filters = options?.filters;
|
|
20
|
+
this.sort = options?.sort;
|
|
21
|
+
this.select = options?.select;
|
|
22
|
+
this.computeTotal = options?.computeTotal;
|
|
48
23
|
}
|
|
49
24
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})(DataRequestFilterOperator || (DataRequestFilterOperator = {}));
|
|
25
|
+
// export enum DataRequestFilterOperator {
|
|
26
|
+
// EQ = 0,
|
|
27
|
+
// NEQ = 1,
|
|
28
|
+
// LT = 2,
|
|
29
|
+
// LTE = 3,
|
|
30
|
+
// GT = 4,
|
|
31
|
+
// GTE = 5,
|
|
32
|
+
// LI = 6,
|
|
33
|
+
// SW = 7,
|
|
34
|
+
// }
|
|
61
35
|
|
|
62
36
|
class DataResult {
|
|
63
|
-
request;
|
|
64
37
|
data;
|
|
65
38
|
total;
|
|
66
|
-
constructor(
|
|
67
|
-
this.request = request;
|
|
39
|
+
constructor(data, total) {
|
|
68
40
|
this.data = data;
|
|
69
41
|
this.total = total;
|
|
70
42
|
}
|
|
71
43
|
}
|
|
72
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Abstract base class for data sources.
|
|
47
|
+
* This class provides a common interface for loading data from various sources.
|
|
48
|
+
*/
|
|
73
49
|
class DataSource {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
50
|
+
_isLoading = signal(false, ...(ngDevMode ? [{ debugName: "_isLoading" }] : []));
|
|
51
|
+
/**
|
|
52
|
+
* Indicates whether the data source is currently loading data.
|
|
53
|
+
*/
|
|
54
|
+
isLoading = this._isLoading.asReadonly();
|
|
77
55
|
constructor() {
|
|
78
56
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An implementation of DataSource that uses an array as the data source.
|
|
61
|
+
* This is useful for static data or when you want to manage the data manually.
|
|
62
|
+
*/
|
|
63
|
+
class LocalDataSource extends DataSource {
|
|
64
|
+
items;
|
|
65
|
+
type = 'local';
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new LocalDataSource.
|
|
68
|
+
* @param items The array of items to be used as the data source.
|
|
69
|
+
*/
|
|
70
|
+
constructor(items) {
|
|
71
|
+
super();
|
|
72
|
+
this.items = items;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a LocalDataSource from enum values.
|
|
76
|
+
* @param enumClass The enum class to extract values from.
|
|
77
|
+
* @returns A LocalDataSource containing the enum values.
|
|
78
|
+
*/
|
|
79
|
+
static fromEnum(enumClass) {
|
|
80
|
+
return new LocalDataSource(getEnumValues(enumClass));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Loads data from the local array based on the provided DataRequest.
|
|
84
|
+
* @param request The DataRequest containing filtering, sorting, and pagination information.
|
|
85
|
+
* @returns An observable of DataResult containing the requested data.
|
|
86
|
+
*/
|
|
87
|
+
load(request) {
|
|
88
|
+
let filteredValues = [...this.items];
|
|
89
|
+
let result;
|
|
90
|
+
// Filtering
|
|
91
|
+
// if (Array.isArray(request.filters) && request.filters.length > 0) {
|
|
92
|
+
// request.filters.forEach(filter => {
|
|
93
|
+
// if (!filter.filterBy) {
|
|
94
|
+
// throw Error('A filterBy function must be provided for LocalDataSource filters.');
|
|
95
|
+
// }
|
|
96
|
+
// let isPassedByFilter = getFilterFunction(filter);
|
|
97
|
+
// for (let i = 0; i < filteredValues.length; i++) {
|
|
98
|
+
// let row = filteredValues[i];
|
|
99
|
+
// if (!isPassedByFilter(row[filter.field], filter.value)) {
|
|
100
|
+
// filteredValues.splice(i, 1);
|
|
101
|
+
// i--; // Adjust index after removal
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
104
|
+
// });
|
|
105
|
+
// }
|
|
106
|
+
// Pagination
|
|
107
|
+
if (request.page) {
|
|
108
|
+
let startItemIndex = (request.page.zeroBased ? request.page.index : request.page.index - 1) * request.page.size;
|
|
109
|
+
result = filteredValues.slice(startItemIndex, startItemIndex + request.page.size);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
result = filteredValues;
|
|
113
|
+
}
|
|
114
|
+
// Sorting
|
|
115
|
+
if (request.sort) {
|
|
116
|
+
}
|
|
117
|
+
let dataResult = new DataResult(result, filteredValues.length);
|
|
118
|
+
// this._loading = true;
|
|
119
|
+
// return of(result).pipe(
|
|
120
|
+
// delay(5000),
|
|
121
|
+
// tap(x => this._loading = false)
|
|
122
|
+
// );
|
|
123
|
+
return of(dataResult);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function getFilterFunction(requestfilter) {
|
|
127
|
+
let operator = requestfilter.operator || 'contains';
|
|
128
|
+
let caseSensitive = requestfilter.caseSensitive || false;
|
|
129
|
+
// if (requestfilter.value === undefined || requestfilter.value === null) {
|
|
130
|
+
// return (item: any) => true; // No filter applied
|
|
131
|
+
// }
|
|
132
|
+
switch (requestfilter.operator) {
|
|
133
|
+
case 'contains':
|
|
134
|
+
return caseSensitive ?
|
|
135
|
+
(item, filter) => item.includes(filter) :
|
|
136
|
+
(item, filter) => item.toLowerCase().includes(filter.toLowerCase());
|
|
137
|
+
case 'startsWith':
|
|
138
|
+
return caseSensitive ?
|
|
139
|
+
(item, filter) => item.startsWith(filter) :
|
|
140
|
+
(item, filter) => item.toLowerCase().startsWith(filter.toLowerCase());
|
|
141
|
+
case 'endsWith':
|
|
142
|
+
return caseSensitive ?
|
|
143
|
+
(item, filter) => item.endsWith(filter) :
|
|
144
|
+
(item, filter) => item.toLowerCase().endsWith(filter.toLowerCase());
|
|
145
|
+
case 'eq':
|
|
146
|
+
if (typeof requestfilter.value === 'string') {
|
|
147
|
+
return caseSensitive ?
|
|
148
|
+
(item, filter) => item == filter :
|
|
149
|
+
(item, filter) => item.toString().toLowerCase() === filter.toLowerCase();
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return (item, filter) => item === filter;
|
|
153
|
+
}
|
|
154
|
+
case 'lt':
|
|
155
|
+
return (item, filter) => item < filter;
|
|
156
|
+
case 'lte':
|
|
157
|
+
return (item, filter) => item <= filter;
|
|
158
|
+
case 'gt':
|
|
159
|
+
return (item, filter) => item > filter;
|
|
160
|
+
case 'gte':
|
|
161
|
+
return (item, filter) => item >= filter;
|
|
162
|
+
case 'ne':
|
|
163
|
+
return (item, filter) => item !== filter;
|
|
164
|
+
default:
|
|
165
|
+
throw new Error(`filter operator: ${operator} is not implemented in ArrayDataSource.`);
|
|
82
166
|
}
|
|
83
167
|
}
|
|
84
168
|
|
|
85
|
-
|
|
169
|
+
/**
|
|
170
|
+
* RemoteDataSource is a DataSource that loads data asynchronously using a DataLoader function.
|
|
171
|
+
* It is used to fetch data from a remote source, such as an API.
|
|
172
|
+
*/
|
|
173
|
+
class RemoteDataSource extends DataSource {
|
|
86
174
|
loader;
|
|
175
|
+
type = 'remote';
|
|
87
176
|
constructor(loader) {
|
|
88
177
|
super();
|
|
89
178
|
this.loader = loader;
|
|
@@ -92,38 +181,39 @@ class AsyncDataSource extends DataSource {
|
|
|
92
181
|
}
|
|
93
182
|
}
|
|
94
183
|
load(request) {
|
|
95
|
-
this.
|
|
96
|
-
return this.loader(request).pipe(
|
|
97
|
-
this.
|
|
184
|
+
this._isLoading.set(true);
|
|
185
|
+
return this.loader(request).pipe(catchError(err => {
|
|
186
|
+
this._isLoading.set(false);
|
|
187
|
+
throw err;
|
|
188
|
+
}), tap(res => {
|
|
189
|
+
this._isLoading.set(false);
|
|
98
190
|
}));
|
|
99
191
|
}
|
|
100
192
|
}
|
|
101
193
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Converts a DataSourceLike to a DataSource instance.
|
|
196
|
+
* @param source The data source to convert.
|
|
197
|
+
* @returns A DataSource instance.
|
|
198
|
+
*/
|
|
199
|
+
function dataSourceAttribute(source) {
|
|
200
|
+
if (Array.isArray(source)) {
|
|
201
|
+
return new LocalDataSource(source);
|
|
107
202
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
let result = this.items.slice(startItem, startItem + request.pageSize);
|
|
111
|
-
return of(new DataResult(request, result, this.items.length));
|
|
203
|
+
else if (typeof source == 'function') {
|
|
204
|
+
return new RemoteDataSource(source);
|
|
112
205
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (idx > -1) {
|
|
116
|
-
this.items.splice(idx, 1);
|
|
117
|
-
this.changeSubject.next(0);
|
|
118
|
-
}
|
|
206
|
+
else if (source instanceof DataSource) {
|
|
207
|
+
return source;
|
|
119
208
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.changeSubject.next(0);
|
|
209
|
+
else if (source === undefined || source === null) {
|
|
210
|
+
return new LocalDataSource([]);
|
|
123
211
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
212
|
+
else if (typeof source === 'object') {
|
|
213
|
+
return LocalDataSource.fromEnum(source);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
throw new Error('Invalid data source.');
|
|
127
217
|
}
|
|
128
218
|
}
|
|
129
219
|
|
|
@@ -132,7 +222,7 @@ function toDataResult(dr) {
|
|
|
132
222
|
return new Observable(subscriber => {
|
|
133
223
|
source.subscribe({
|
|
134
224
|
next(event) {
|
|
135
|
-
subscriber.next(new DataResult(
|
|
225
|
+
subscriber.next(new DataResult(event));
|
|
136
226
|
},
|
|
137
227
|
error(error) {
|
|
138
228
|
subscriber.error(error);
|
|
@@ -149,5 +239,5 @@ function toDataResult(dr) {
|
|
|
149
239
|
* Generated bundle index. Do not edit.
|
|
150
240
|
*/
|
|
151
241
|
|
|
152
|
-
export {
|
|
242
|
+
export { DataRequest, DataResult, DataSource, LocalDataSource, RemoteDataSource, dataSourceAttribute, toDataResult };
|
|
153
243
|
//# sourceMappingURL=bootkit-ng0-data.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootkit-ng0-data.mjs","sources":["../../../projects/ng0/data/data-request.ts","../../../projects/ng0/data/data-result.ts","../../../projects/ng0/data/data-source.ts","../../../projects/ng0/data/async-data-source.ts","../../../projects/ng0/data/array-data-source.ts","../../../projects/ng0/data/data-result-operator.ts","../../../projects/ng0/data/bootkit-ng0-data.ts"],"sourcesContent":["export class DataRequest {\r\n constructor(\r\n public pageIndex = 0,\r\n public pageSize = 10,\r\n public computeTotal = true,\r\n public filters: DataRequestFilter[] = [],\r\n public sort?: DataRequestSort,\r\n ) { }\r\n\r\n public addFilter(field: string, value: string, operator: DataRequestFilterOperator = DataRequestFilterOperator.EQ) {\r\n this.filters.push(new DataRequestFilter(field, value, operator));\r\n return this;\r\n }\r\n\r\n public sortDescending(field: string) {\r\n this.sort = new DataRequestSort(field, false);\r\n return this;\r\n }\r\n\r\n public sortAscending(field: string) {\r\n this.sort = new DataRequestSort(field, true);\r\n return this;\r\n }\r\n\r\n public static all() {\r\n return new DataRequest(0, 1000000, false);\r\n }\r\n}\r\n\r\nexport class DataRequestSort {\r\n constructor(\r\n public field: string,\r\n public asc = true) {\r\n }\r\n}\r\n\r\nexport class DataRequestFilter {\r\n constructor(\r\n public field: string,\r\n public value?: string,\r\n public operator: DataRequestFilterOperator = DataRequestFilterOperator.EQ) {\r\n }\r\n}\r\n\r\nexport enum DataRequestFilterOperator {\r\n EQ = 0,\r\n NEQ = 1, \r\n LT = 2,\r\n LTE = 3,\r\n GT = 4,\r\n\tGTE = 5,\r\n LI = 6,\r\n SW = 7,\r\n}\r\n","import { DataRequest } from \"./data-request\";\r\n\r\nexport class DataResult<T = any> {\r\n constructor(\r\n public readonly request: DataRequest,\r\n public readonly data: T[],\r\n public readonly total?: number) {\r\n }\r\n}\r\n","import { Observable, Subject } from \"rxjs\";\r\nimport { DataRequest } from \"./data-request\";\r\nimport { DataResult } from \"./data-result\";\r\n\r\nexport abstract class DataSource<T=any> {\r\n protected _loading = false;\r\n protected changeSubject = new Subject();\r\n public readonly change = this.changeSubject.asObservable();\r\n\r\n constructor() {\r\n }\r\n\r\n get loading() { return this._loading; }\r\n protected setLoading(value: boolean) {\r\n this._loading = value;\r\n }\r\n\r\n // get data() { return this._data; }\r\n // protected set data(value: any[] | undefined) {\r\n // this._data = value;\r\n // }\r\n\r\n // get totallRecords() { return this._totallRecords; }\r\n // protected set totallRecords(value: number | undefined) {\r\n // this._totallRecords= value;\r\n // }\r\n\r\n abstract load(request: DataRequest): Observable<DataResult>;\r\n}\r\n","import { Observable, tap } from \"rxjs\";\r\nimport { DataRequest } from \"./data-request\";\r\nimport { DataResult } from \"./data-result\";\r\nimport { DataSource } from \"./data-source\";\r\n\r\nexport type DataLoaderFunc = (request: DataRequest) => Observable<DataResult>;\r\n\r\nexport class AsyncDataSource extends DataSource {\r\n constructor(private readonly loader: DataLoaderFunc) {\r\n super();\r\n\r\n if (typeof loader !== 'function') {\r\n throw 'Invalid data loader';\r\n }\r\n }\r\n\r\n load(request: DataRequest) {\r\n this.setLoading(true);\r\n\r\n return this.loader(request).pipe(\r\n tap(res => {\r\n this.setLoading(false);\r\n })\r\n )\r\n }\r\n}\r\n","import { of } from \"rxjs\";\r\nimport { DataRequest } from \"./data-request\";\r\nimport { DataResult } from \"./data-result\";\r\nimport { DataSource } from \"./data-source\";\r\n\r\nexport class ArrayDataSource extends DataSource {\r\n constructor(private items: any[]) {\r\n super();\r\n }\r\n\r\n load(request: DataRequest) {\r\n var startItem = request.pageIndex * request.pageSize;\r\n let result = this.items.slice(startItem, startItem + request.pageSize);\r\n return of(new DataResult(request, result, this.items.length));\r\n }\r\n\r\n remove(item: any) {\r\n var idx = this.items!.findIndex(x => x === item);\r\n if (idx > -1) {\r\n this.items.splice(idx, 1);\r\n this.changeSubject.next(0);\r\n }\r\n }\r\n\r\n insert(item: any) {\r\n var idx = this.items.push(item);\r\n this.changeSubject.next(0);\r\n }\r\n\r\n set(items: any[]) {\r\n this.items = items;\r\n this.changeSubject.next(0);\r\n }\r\n}\r\n","import { Observable } from \"rxjs\";\r\nimport { DataResult } from \"./data-result\";\r\nimport { DataRequest } from \"./data-request\";\r\n\r\nexport function toDataResult<T=any>(dr: DataRequest) {\r\n return function (source: Observable<any>): Observable<DataResult<T>> {\r\n return new Observable(subscriber => {\r\n source.subscribe({\r\n next(event) {\r\n subscriber.next(new DataResult(dr, event));\r\n },\r\n error(error) {\r\n subscriber.error(error);\r\n },\r\n complete() {\r\n subscriber.complete();\r\n }\r\n });\r\n });\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;MAAa,WAAW,CAAA;AAET,IAAA,SAAA;AACA,IAAA,QAAA;AACA,IAAA,YAAA;AACA,IAAA,OAAA;AACA,IAAA,IAAA;AALX,IAAA,WAAA,CACW,SAAY,GAAA,CAAC,EACb,QAAA,GAAW,EAAE,EACb,YAAe,GAAA,IAAI,EACnB,OAAA,GAA+B,EAAE,EACjC,IAAsB,EAAA;QAJtB,IAAS,CAAA,SAAA,GAAT,SAAS;QACT,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAY,CAAA,YAAA,GAAZ,YAAY;QACZ,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAI,CAAA,IAAA,GAAJ,IAAI;;IAGR,SAAS,CAAC,KAAa,EAAE,KAAa,EAAE,QAAsC,GAAA,yBAAyB,CAAC,EAAE,EAAA;AAC7G,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAChE,QAAA,OAAO,IAAI;;AAGR,IAAA,cAAc,CAAC,KAAa,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AC,IAAI,CAAC,CAAC,CAAC;;AAE7B;;AC7BK,SAAU,YAAY,CAAQ,EAAe,EAAA;AACjD,IAAA,OAAO,UAAU,MAAuB,EAAA;AACtC,QAAA,OAAO,IAAI,UAAU,CAAC,UAAU,IAAG;YACjC,MAAM,CAAC,SAAS,CAAC;AACf,gBAAA,IAAI,CAAC,KAAK,EAAA;oBACR,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;iBAC3C;AACD,gBAAA,KAAK,CAAC,KAAK,EAAA;AACT,oBAAA,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC;iBACxB;gBACD,QAAQ,GAAA;oBACN,UAAU,CAAC,QAAQ,EAAE;;AAExB,aAAA,CAAC;AACJ,SAAC,CAAC;AACJ,KAAC;AACH;;ACpBA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"bootkit-ng0-data.mjs","sources":["../../../projects/ng0/data/data-request.ts","../../../projects/ng0/data/data-result.ts","../../../projects/ng0/data/data-source.ts","../../../projects/ng0/data/local-data-source.ts","../../../projects/ng0/data/remote-data-source.ts","../../../projects/ng0/data/data-source-attribute.ts","../../../projects/ng0/data/data-result-operator.ts","../../../projects/ng0/data/bootkit-ng0-data.ts"],"sourcesContent":["import { FilterPredicate } from \"@bootkit/ng0/common\";\r\n\r\n/**\r\n * DataRequest class represents a request for data with pagination, filtering, sorting, and field selection.\r\n * It is used to encapsulate the parameters needed to fetch data from a data source.\r\n * It can be used with various data sources such as HTTP services, in-memory arrays, etc.\r\n * \r\n */\r\nexport class DataRequest {\r\n public page?: DataRequestPage;\r\n public filters?: DataRequestFilter[];\r\n public sort?: DataRequestSort;\r\n public select?: string[];\r\n public computeTotal?: boolean;\r\n\r\n constructor(options?: {\r\n page?: DataRequestPage,\r\n filters?: DataRequestFilter[],\r\n sort?: DataRequestSort,\r\n select?: string[],\r\n computeTotal?: boolean,\r\n }) {\r\n this.page = options?.page;\r\n this.filters = options?.filters;\r\n this.sort = options?.sort;\r\n this.select = options?.select;\r\n this.computeTotal = options?.computeTotal;\r\n }\r\n}\r\n\r\n/**\r\n * Represents a data request page.\r\n */\r\nexport interface DataRequestPage {\r\n /**\r\n * Index of the page.\r\n * If zeroBased is true, the index starts from 0.\r\n */\r\n index: number;\r\n\r\n /**\r\n * Size of the page, i.e., number of items in each page.\r\n */\r\n size: number;\r\n\r\n /**\r\n * Indicates if the index is zero-based.\r\n */\r\n zeroBased: boolean;\r\n}\r\n\r\n/**\r\n * Represents a sorting option in a DataRequest.\r\n * @property field The field to sort by.\r\n * @property asc Whether to sort in ascending order.\r\n */\r\nexport interface DataRequestSort {\r\n field: string;\r\n asc?: boolean\r\n}\r\n\r\n/**\r\n * Represents a filter in a DataRequest.\r\n */\r\nexport interface DataRequestFilter {\r\n /**\r\n * The field to filter by.\r\n * It can be a string representing the property name of the data items.\r\n */\r\n field?: string;\r\n\r\n /**\r\n * The value to filter by.\r\n * It can be a string, number, or any other type depending on the field.\r\n */\r\n value?: string;\r\n\r\n /**\r\n * The operator to use for filtering.\r\n * It can be one of the standard filter operators like Contains, StartsWith, EndsWith, Equals, etc.\r\n */\r\n operator?: string;\r\n\r\n /**\r\n * Indicates if the filter is case-sensitive. only for text columns.\r\n * Default is false.\r\n */\r\n caseSensitive?: boolean;\r\n\r\n /**\r\n * A custom filter function to apply for filtering.\r\n */\r\n filterBy?: FilterPredicate;\r\n}\r\n\r\n// export enum DataRequestFilterOperator {\r\n// EQ = 0,\r\n// NEQ = 1,\r\n// LT = 2,\r\n// LTE = 3,\r\n// GT = 4,\r\n// GTE = 5,\r\n// LI = 6,\r\n// SW = 7,\r\n// }\r\n","export class DataResult<T = any> {\r\n constructor(\r\n public readonly data: T[],\r\n public readonly total?: number) {\r\n }\r\n}\r\n","import { Observable } from \"rxjs\";\r\nimport { DataRequest } from \"./data-request\";\r\nimport { DataResult } from \"./data-result\";\r\nimport { signal } from \"@angular/core\";\r\n\r\n/**\r\n * DataLoader is a function that takes a DataRequest and returns an Observable of DataResult.\r\n * It is used by RemoteDataSource to load data asynchronously.\r\n */\r\nexport type DataLoader<T = any> = (request: DataRequest) => Observable<DataResult<T>>;\r\n\r\n\r\n/**\r\n * Abstract base class for data sources.\r\n * This class provides a common interface for loading data from various sources.\r\n */\r\nexport abstract class DataSource<T = any> {\r\n public abstract readonly type: 'local' | 'remote';\r\n protected _isLoading = signal(false);\r\n\r\n /**\r\n * Indicates whether the data source is currently loading data.\r\n */\r\n public isLoading = this._isLoading.asReadonly();\r\n\r\n constructor() {\r\n }\r\n\r\n /**\r\n * Loads data from the data source.\r\n * @param request The data request object containing pagination, sorting, and filtering information.\r\n */\r\n abstract load(request: DataRequest): Observable<DataResult>;\r\n}\r\n\r\n/**\r\n * DataSourceLike is a type that can be used to represent any data source\r\n * that can be used with the table, autocomplete, dropdown and any component that requires data.\r\n * It can be an array of data, a function that returns an observable of data,\r\n * or an instance of DataSource.\r\n */\r\nexport type DataSourceLike<T = any> =\r\n Array<any> |\r\n DataLoader<T> |\r\n DataSource<T> |\r\n Record<string, string | number> | // enum: extract enum or object values\r\n undefined |\r\n null;\r\n","import { of } from \"rxjs\";\r\nimport { DataRequest, DataRequestFilter } from \"./data-request\";\r\nimport { DataResult } from \"./data-result\";\r\nimport { DataSource } from \"./data-source\";\r\nimport { getEnumValues } from \"@bootkit/ng0/common\";\r\n\r\n/**\r\n * An implementation of DataSource that uses an array as the data source.\r\n * This is useful for static data or when you want to manage the data manually.\r\n */\r\nexport class LocalDataSource extends DataSource {\r\n readonly type = 'local';\r\n\r\n /**\r\n * Creates a new LocalDataSource.\r\n * @param items The array of items to be used as the data source. \r\n */\r\n constructor(private items: any[]) {\r\n super();\r\n }\r\n\r\n /**\r\n * Creates a LocalDataSource from enum values.\r\n * @param enumClass The enum class to extract values from.\r\n * @returns A LocalDataSource containing the enum values.\r\n */\r\n public static fromEnum(enumClass: Record<string, string | number>): LocalDataSource {\r\n return new LocalDataSource(getEnumValues(enumClass));\r\n }\r\n\r\n /**\r\n * Loads data from the local array based on the provided DataRequest.\r\n * @param request The DataRequest containing filtering, sorting, and pagination information.\r\n * @returns An observable of DataResult containing the requested data. \r\n */\r\n load(request: DataRequest) {\r\n let filteredValues = [...this.items];\r\n let result: any[];\r\n\r\n // Filtering\r\n // if (Array.isArray(request.filters) && request.filters.length > 0) {\r\n // request.filters.forEach(filter => {\r\n // if (!filter.filterBy) {\r\n // throw Error('A filterBy function must be provided for LocalDataSource filters.');\r\n // }\r\n\r\n // let isPassedByFilter = getFilterFunction(filter);\r\n\r\n // for (let i = 0; i < filteredValues.length; i++) {\r\n // let row = filteredValues[i];\r\n // if (!isPassedByFilter(row[filter.field], filter.value)) {\r\n // filteredValues.splice(i, 1);\r\n // i--; // Adjust index after removal\r\n // }\r\n // }\r\n // });\r\n // }\r\n\r\n // Pagination\r\n if (request.page) {\r\n let startItemIndex = (request.page.zeroBased ? request.page.index : request.page.index - 1) * request.page.size;\r\n result = filteredValues.slice(startItemIndex, startItemIndex + request.page.size);\r\n } else {\r\n result = filteredValues;\r\n }\r\n\r\n // Sorting\r\n if (request.sort) {\r\n\r\n }\r\n\r\n let dataResult = new DataResult(result, filteredValues.length);\r\n\r\n // this._loading = true;\r\n // return of(result).pipe(\r\n // delay(5000),\r\n // tap(x => this._loading = false)\r\n // );\r\n return of(dataResult);\r\n }\r\n}\r\n\r\nfunction getFilterFunction(requestfilter: DataRequestFilter): (cellValue: any, filterValue: any) => boolean {\r\n let operator = requestfilter.operator || 'contains';\r\n let caseSensitive = requestfilter.caseSensitive || false;\r\n\r\n // if (requestfilter.value === undefined || requestfilter.value === null) {\r\n // return (item: any) => true; // No filter applied\r\n // }\r\n\r\n switch (requestfilter.operator) {\r\n case 'contains':\r\n return caseSensitive ?\r\n (item: string, filter: string) => item.includes(filter) :\r\n (item: string, filter: string) => item.toLowerCase().includes(filter.toLowerCase());\r\n\r\n case 'startsWith':\r\n return caseSensitive ?\r\n (item: string, filter: string) => item.startsWith(filter) :\r\n (item: string, filter: string) => item.toLowerCase().startsWith(filter.toLowerCase());\r\n\r\n case 'endsWith':\r\n return caseSensitive ?\r\n (item: string, filter: string) => item.endsWith(filter) :\r\n (item: string, filter: string) => item.toLowerCase().endsWith(filter.toLowerCase());\r\n\r\n case 'eq':\r\n if (typeof requestfilter.value === 'string') {\r\n return caseSensitive ?\r\n (item: string, filter: string) => item == filter :\r\n (item: string, filter: string) => item.toString().toLowerCase() === filter.toLowerCase();\r\n } else {\r\n return (item: any, filter: any) => item === filter;\r\n }\r\n\r\n case 'lt':\r\n return (item: any, filter: any) => item < filter;\r\n\r\n case 'lte':\r\n return (item: any, filter: any) => item <= filter;\r\n\r\n case 'gt':\r\n return (item: any, filter: any) => item > filter;\r\n\r\n case 'gte':\r\n return (item: any, filter: any) => item >= filter;\r\n\r\n case 'ne':\r\n return (item: any, filter: any) => item !== filter;\r\n\r\n default:\r\n throw new Error(`filter operator: ${operator} is not implemented in ArrayDataSource.`);\r\n }\r\n}","import { catchError, Observable, tap } from \"rxjs\";\r\nimport { DataRequest } from \"./data-request\";\r\nimport { DataLoader, DataSource } from \"./data-source\";\r\n\r\n\r\n/**\r\n * RemoteDataSource is a DataSource that loads data asynchronously using a DataLoader function.\r\n * It is used to fetch data from a remote source, such as an API.\r\n */\r\nexport class RemoteDataSource extends DataSource {\r\n readonly type = 'remote';\r\n\r\n constructor(private readonly loader: DataLoader) {\r\n super();\r\n\r\n if (typeof loader !== 'function') {\r\n throw 'Invalid data loader';\r\n }\r\n }\r\n\r\n load(request: DataRequest) {\r\n this._isLoading.set(true);\r\n\r\n return this.loader(request).pipe(\r\n catchError(err => {\r\n this._isLoading.set(false);\r\n throw err;\r\n }),\r\n tap(res => {\r\n this._isLoading.set(false);\r\n })\r\n )\r\n }\r\n}\r\n","import { LocalDataSource } from \"./local-data-source\";\r\nimport { RemoteDataSource } from \"./remote-data-source\";\r\nimport { DataSource, DataSourceLike } from \"./data-source\";\r\n\r\n/**\r\n * Converts a DataSourceLike to a DataSource instance.\r\n * @param source The data source to convert.\r\n * @returns A DataSource instance.\r\n */\r\nexport function dataSourceAttribute<T>(source: DataSourceLike): DataSource<T> {\r\n if (Array.isArray(source)) {\r\n return new LocalDataSource(source);\r\n } else if (typeof source == 'function') {\r\n return new RemoteDataSource(source);\r\n } else if (source instanceof DataSource) {\r\n return source;\r\n } else if (source === undefined || source === null) {\r\n return new LocalDataSource([]);\r\n } else if (typeof source === 'object') {\r\n return LocalDataSource.fromEnum(source);\r\n } else {\r\n throw new Error('Invalid data source.');\r\n }\r\n}\r\n","import { Observable } from \"rxjs\";\r\nimport { DataResult } from \"./data-result\";\r\nimport { DataRequest } from \"./data-request\";\r\n\r\nexport function toDataResult<T=any>(dr: DataRequest) {\r\n return function (source: Observable<any>): Observable<DataResult<T>> {\r\n return new Observable(subscriber => {\r\n source.subscribe({\r\n next(event) {\r\n subscriber.next(new DataResult(event));\r\n },\r\n error(error) {\r\n subscriber.error(error);\r\n },\r\n complete() {\r\n subscriber.complete();\r\n }\r\n });\r\n });\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAEA;;;;;AAKG;MACU,WAAW,CAAA;AACb,IAAA,IAAI;AACJ,IAAA,OAAO;AACP,IAAA,IAAI;AACJ,IAAA,MAAM;AACN,IAAA,YAAY;AAEnB,IAAA,WAAA,CAAY,OAMX,EAAA;AACG,QAAA,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI;AACzB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO;AAC/B,QAAA,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI;AACzB,QAAA,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM;AAC7B,QAAA,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY;IAC7C;AACH;AAmED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;MCxGa,UAAU,CAAA;A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gBACD,QAAQ,GAAA;oBACN,UAAU,CAAC,QAAQ,EAAE;gBACvB;AACD,aAAA,CAAC;AACJ,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;ACpBA;;AAEG;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const f = Math.floor;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a time span in months, days, hours, minutes, seconds, and milliseconds.
|
|
4
|
+
* Provides methods to create a TimeSpan from a total number of milliseconds.
|
|
5
|
+
* @example
|
|
6
|
+
* const span = TimeSpan.fromMilliseconds(123456789);
|
|
7
|
+
* console.log(span); // TimeSpan { months: 0, days: 1, hours: 10, minutes: 17, seconds: 36, milliseconds: 789 }
|
|
8
|
+
*/
|
|
9
|
+
class TimeSpan {
|
|
10
|
+
months;
|
|
11
|
+
days;
|
|
12
|
+
hours;
|
|
13
|
+
minutes;
|
|
14
|
+
seconds;
|
|
15
|
+
milliseconds;
|
|
16
|
+
/** Milliseconds per second */
|
|
17
|
+
static msPerSecond = 1000;
|
|
18
|
+
/** Milliseconds per minute */
|
|
19
|
+
static msPerMinute = this.msPerSecond * 60;
|
|
20
|
+
/** Milliseconds per hour */
|
|
21
|
+
static msPerHour = this.msPerMinute * 60;
|
|
22
|
+
/** Milliseconds per day */
|
|
23
|
+
static msPerDay = this.msPerHour * 24;
|
|
24
|
+
/** Milliseconds per month */
|
|
25
|
+
static msPerMonth = this.msPerDay * 30;
|
|
26
|
+
constructor(months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0) {
|
|
27
|
+
this.months = months;
|
|
28
|
+
this.days = days;
|
|
29
|
+
this.hours = hours;
|
|
30
|
+
this.minutes = minutes;
|
|
31
|
+
this.seconds = seconds;
|
|
32
|
+
this.milliseconds = milliseconds;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a TimeSpan from a total number of milliseconds.
|
|
36
|
+
* @param ms The total number of milliseconds.
|
|
37
|
+
* @returns A TimeSpan representing the equivalent time span.
|
|
38
|
+
*/
|
|
39
|
+
static fromMilliseconds(ms) {
|
|
40
|
+
const months = f(ms / TimeSpan.msPerMonth), days = f((ms % TimeSpan.msPerMonth) / TimeSpan.msPerDay), hours = f((ms % TimeSpan.msPerDay) / TimeSpan.msPerHour), minutes = f((ms % TimeSpan.msPerHour) / TimeSpan.msPerMinute), seconds = f((ms % TimeSpan.msPerMinute) / TimeSpan.msPerSecond), milliseconds = (ms % TimeSpan.msPerSecond);
|
|
41
|
+
return new TimeSpan(months, days, hours, minutes, seconds, milliseconds);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generated bundle index. Do not edit.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export { TimeSpan };
|
|
50
|
+
//# sourceMappingURL=bootkit-ng0-date.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootkit-ng0-date.mjs","sources":["../../../projects/ng0/date/time-span.ts","../../../projects/ng0/date/bootkit-ng0-date.ts"],"sourcesContent":["const f = Math.floor;\r\n\r\n/**\r\n * Represents a time span in months, days, hours, minutes, seconds, and milliseconds.\r\n * Provides methods to create a TimeSpan from a total number of milliseconds.\r\n * @example\r\n * const span = TimeSpan.fromMilliseconds(123456789);\r\n * console.log(span); // TimeSpan { months: 0, days: 1, hours: 10, minutes: 17, seconds: 36, milliseconds: 789 }\r\n */\r\nexport class TimeSpan {\r\n /** Milliseconds per second */\r\n public static readonly msPerSecond = 1000;\r\n\r\n /** Milliseconds per minute */\r\n public static readonly msPerMinute = this.msPerSecond * 60;\r\n\r\n /** Milliseconds per hour */\r\n public static readonly msPerHour = this.msPerMinute * 60;\r\n\r\n /** Milliseconds per day */\r\n public static readonly msPerDay = this.msPerHour * 24;\r\n\r\n /** Milliseconds per month */\r\n public static readonly msPerMonth = this.msPerDay * 30;\r\n\r\n constructor(\r\n public readonly months: number = 0,\r\n public readonly days: number = 0,\r\n public readonly hours: number = 0,\r\n public readonly minutes: number = 0,\r\n public readonly seconds: number = 0,\r\n public readonly milliseconds: number = 0) {\r\n }\r\n\r\n /**\r\n * Creates a TimeSpan from a total number of milliseconds.\r\n * @param ms The total number of milliseconds.\r\n * @returns A TimeSpan representing the equivalent time span.\r\n */\r\n static fromMilliseconds(ms: number): TimeSpan {\r\n const months = f(ms / TimeSpan.msPerMonth),\r\n days = f((ms % TimeSpan.msPerMonth) / TimeSpan.msPerDay),\r\n hours = f((ms % TimeSpan.msPerDay) / TimeSpan.msPerHour),\r\n minutes = f((ms % TimeSpan.msPerHour) / TimeSpan.msPerMinute),\r\n seconds = f((ms % TimeSpan.msPerMinute) / TimeSpan.msPerSecond),\r\n milliseconds = (ms % TimeSpan.msPerSecond);\r\n return new TimeSpan(months, days, hours, minutes, seconds, milliseconds);\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK;AAEpB;;;;;;AAMG;MACU,QAAQ,CAAA;AAiBD,IAAA,MAAA;AACA,IAAA,IAAA;AACA,IAAA,KAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA,YAAA;;AApBX,IAAA,OAAgB,WAAW,GAAG,IAAI;;IAGlC,OAAgB,WAAW,GAAG,IAAI,CAAC,WAAW,GAAG,EAAE;;IAGnD,OAAgB,SAAS,GAAG,IAAI,CAAC,WAAW,GAAG,EAAE;;IAGjD,OAAgB,QAAQ,GAAG,IAAI,CAAC,SAAS,GAAG,EAAE;;IAG9C,OAAgB,UAAU,GAAG,IAAI,CAAC,QAAQ,GAAG,EAAE;AAEtD,IAAA,WAAA,CACkB,SAAiB,CAAC,EAClB,IAAA,GAAe,CAAC,EAChB,KAAA,GAAgB,CAAC,EACjB,OAAA,GAAkB,CAAC,EACnB,OAAA,GAAkB,CAAC,EACnB,eAAuB,CAAC,EAAA;QALxB,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,KAAK,GAAL,KAAK;QACL,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,YAAY,GAAZ,YAAY;IAC9B;AAEA;;;;AAIG;IACH,OAAO,gBAAgB,CAAC,EAAU,EAAA;AAChC,QAAA,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,EACxC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,QAAQ,CAAC,EACxD,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,CAAC,EACxD,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,WAAW,CAAC,EAC7D,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,WAAW,CAAC,EAC/D,YAAY,IAAI,EAAE,GAAG,QAAQ,CAAC,WAAW,CAAC;AAC5C,QAAA,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC;IAC1E;;;AC/CF;;AAEG;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saves a Blob as a file in the user's browser.
|
|
3
|
+
* This function is only available in browsers that support the Blob API.
|
|
4
|
+
* @param blob
|
|
5
|
+
* @param fileName
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
function saveBlob(blob, fileName) {
|
|
9
|
+
const url = window.URL.createObjectURL(blob);
|
|
10
|
+
const a = document.createElement('a');
|
|
11
|
+
a.href = url;
|
|
12
|
+
a.download = fileName;
|
|
13
|
+
document.body.appendChild(a);
|
|
14
|
+
a.click();
|
|
15
|
+
a.remove();
|
|
16
|
+
window.URL.revokeObjectURL(url);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Triggers downloading a file from a given URL.
|
|
20
|
+
* @param url
|
|
21
|
+
* @param fileName
|
|
22
|
+
*/
|
|
23
|
+
function downloadFile(url, fileName) {
|
|
24
|
+
const a = document.createElement('a');
|
|
25
|
+
a.href = url;
|
|
26
|
+
a.download = fileName;
|
|
27
|
+
document.body.appendChild(a);
|
|
28
|
+
a.click();
|
|
29
|
+
a.remove();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a File object to a Base64 string.
|
|
33
|
+
* @param file The File object to convert.
|
|
34
|
+
* @return A Promise that resolves to the Base64 string representation of the file.
|
|
35
|
+
*/
|
|
36
|
+
function convertFileToBase64(file) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const reader = new FileReader();
|
|
39
|
+
reader.readAsDataURL(file);
|
|
40
|
+
reader.onload = () => resolve(reader.result);
|
|
41
|
+
reader.onerror = error => reject(error);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generated bundle index. Do not edit.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export { convertFileToBase64, downloadFile, saveBlob };
|
|
50
|
+
//# sourceMappingURL=bootkit-ng0-file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootkit-ng0-file.mjs","sources":["../../../projects/ng0/file/utils.ts","../../../projects/ng0/file/bootkit-ng0-file.ts"],"sourcesContent":["\r\n/**\r\n * Saves a Blob as a file in the user's browser.\r\n * This function is only available in browsers that support the Blob API.\r\n * @param blob \r\n * @param fileName \r\n * \r\n */\r\nexport function saveBlob(blob: Blob, fileName: string): void {\r\n const url = window.URL.createObjectURL(blob);\r\n const a = document.createElement('a');\r\n a.href = url;\r\n a.download = fileName;\r\n document.body.appendChild(a);\r\n a.click();\r\n a.remove();\r\n window.URL.revokeObjectURL(url);\r\n}\r\n\r\n/**\r\n * Triggers downloading a file from a given URL.\r\n * @param url \r\n * @param fileName \r\n */\r\nexport function downloadFile(url: string, fileName: string): void {\r\n const a = document.createElement('a');\r\n a.href = url;\r\n a.download = fileName;\r\n document.body.appendChild(a);\r\n a.click();\r\n a.remove();\r\n}\r\n\r\n/**\r\n * Converts a File object to a Base64 string.\r\n * @param file The File object to convert.\r\n * @return A Promise that resolves to the Base64 string representation of the file.\r\n */\r\nexport function convertFileToBase64(file: File): Promise<string | ArrayBuffer | null> {\r\n return new Promise((resolve, reject) => {\r\n const reader = new FileReader();\r\n reader.readAsDataURL(file);\r\n reader.onload = () => resolve(reader.result);\r\n reader.onerror = error => reject(error);\r\n });\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AACA;;;;;;AAMG;AACG,SAAU,QAAQ,CAAC,IAAU,EAAE,QAAgB,EAAA;IACnD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC;IAC5C,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC;AACrC,IAAA,CAAC,CAAC,IAAI,GAAG,GAAG;AACZ,IAAA,CAAC,CAAC,QAAQ,GAAG,QAAQ;AACrB,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC,KAAK,EAAE;IACT,CAAC,CAAC,MAAM,EAAE;AACV,IAAA,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC;AACjC;AAEA;;;;AAIG;AACG,SAAU,YAAY,CAAC,GAAW,EAAE,QAAgB,EAAA;IACxD,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC;AACrC,IAAA,CAAC,CAAC,IAAI,GAAG,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