@bootkit/ng0 0.0.0-alpha.2 → 0.0.0-alpha.21

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.
Files changed (99) hide show
  1. package/common/index.d.ts +118 -6
  2. package/components/accordion/index.d.ts +1 -1
  3. package/components/backdrop/index.d.ts +12 -0
  4. package/components/button/index.d.ts +48 -0
  5. package/components/card/index.d.ts +27 -0
  6. package/components/code/index.d.ts +35 -0
  7. package/components/confirmation/index.d.ts +66 -0
  8. package/components/dropdown/index.d.ts +78 -0
  9. package/components/form-field/index.d.ts +72 -0
  10. package/components/list/index.d.ts +127 -0
  11. package/components/modal/index.d.ts +22 -4
  12. package/components/nav/index.d.ts +23 -19
  13. package/components/pagination/index.d.ts +35 -9
  14. package/components/popover/index.d.ts +1 -1
  15. package/components/select/index.d.ts +116 -0
  16. package/components/sidenav/index.d.ts +59 -0
  17. package/components/stepper/index.d.ts +26 -0
  18. package/components/table/index.d.ts +273 -0
  19. package/components/toast/index.d.ts +1 -1
  20. package/components/tooltip/index.d.ts +1 -1
  21. package/components/vertical-menu/index.d.ts +61 -0
  22. package/data/index.d.ts +258 -46
  23. package/date/index.d.ts +34 -0
  24. package/fesm2022/bootkit-ng0-common.mjs +89 -11
  25. package/fesm2022/bootkit-ng0-common.mjs.map +1 -1
  26. package/fesm2022/bootkit-ng0-components-accordion.mjs +13 -13
  27. package/fesm2022/bootkit-ng0-components-accordion.mjs.map +1 -1
  28. package/fesm2022/bootkit-ng0-components-backdrop.mjs +46 -0
  29. package/fesm2022/bootkit-ng0-components-backdrop.mjs.map +1 -0
  30. package/fesm2022/bootkit-ng0-components-button.mjs +119 -0
  31. package/fesm2022/bootkit-ng0-components-button.mjs.map +1 -0
  32. package/fesm2022/bootkit-ng0-components-card.mjs +62 -0
  33. package/fesm2022/bootkit-ng0-components-card.mjs.map +1 -0
  34. package/fesm2022/bootkit-ng0-components-code.mjs +70 -0
  35. package/fesm2022/bootkit-ng0-components-code.mjs.map +1 -0
  36. package/fesm2022/bootkit-ng0-components-collapse.mjs +14 -14
  37. package/fesm2022/bootkit-ng0-components-collapse.mjs.map +1 -1
  38. package/fesm2022/bootkit-ng0-components-confirmation.mjs +167 -0
  39. package/fesm2022/bootkit-ng0-components-confirmation.mjs.map +1 -0
  40. package/fesm2022/bootkit-ng0-components-dropdown.mjs +189 -0
  41. package/fesm2022/bootkit-ng0-components-dropdown.mjs.map +1 -0
  42. package/fesm2022/bootkit-ng0-components-form-field.mjs +147 -0
  43. package/fesm2022/bootkit-ng0-components-form-field.mjs.map +1 -0
  44. package/fesm2022/bootkit-ng0-components-list.mjs +331 -0
  45. package/fesm2022/bootkit-ng0-components-list.mjs.map +1 -0
  46. package/fesm2022/bootkit-ng0-components-modal.mjs +40 -23
  47. package/fesm2022/bootkit-ng0-components-modal.mjs.map +1 -1
  48. package/fesm2022/bootkit-ng0-components-nav.mjs +58 -59
  49. package/fesm2022/bootkit-ng0-components-nav.mjs.map +1 -1
  50. package/fesm2022/bootkit-ng0-components-offcanvas.mjs +9 -9
  51. package/fesm2022/bootkit-ng0-components-offcanvas.mjs.map +1 -1
  52. package/fesm2022/bootkit-ng0-components-overlay.mjs.map +1 -1
  53. package/fesm2022/bootkit-ng0-components-pagination.mjs +58 -23
  54. package/fesm2022/bootkit-ng0-components-pagination.mjs.map +1 -1
  55. package/fesm2022/bootkit-ng0-components-popover.mjs +10 -10
  56. package/fesm2022/bootkit-ng0-components-popover.mjs.map +1 -1
  57. package/fesm2022/bootkit-ng0-components-select.mjs +427 -0
  58. package/fesm2022/bootkit-ng0-components-select.mjs.map +1 -0
  59. package/fesm2022/bootkit-ng0-components-sidenav.mjs +153 -0
  60. package/fesm2022/bootkit-ng0-components-sidenav.mjs.map +1 -0
  61. package/fesm2022/bootkit-ng0-components-stepper.mjs +91 -0
  62. package/fesm2022/bootkit-ng0-components-stepper.mjs.map +1 -0
  63. package/fesm2022/bootkit-ng0-components-table.mjs +461 -0
  64. package/fesm2022/bootkit-ng0-components-table.mjs.map +1 -0
  65. package/fesm2022/bootkit-ng0-components-toast.mjs +7 -7
  66. package/fesm2022/bootkit-ng0-components-toast.mjs.map +1 -1
  67. package/fesm2022/bootkit-ng0-components-tooltip.mjs +8 -8
  68. package/fesm2022/bootkit-ng0-components-tooltip.mjs.map +1 -1
  69. package/fesm2022/bootkit-ng0-components-vertical-menu.mjs +161 -0
  70. package/fesm2022/bootkit-ng0-components-vertical-menu.mjs.map +1 -0
  71. package/fesm2022/bootkit-ng0-data.mjs +291 -90
  72. package/fesm2022/bootkit-ng0-data.mjs.map +1 -1
  73. package/fesm2022/bootkit-ng0-date.mjs +50 -0
  74. package/fesm2022/bootkit-ng0-date.mjs.map +1 -0
  75. package/fesm2022/bootkit-ng0-file.mjs +50 -0
  76. package/fesm2022/bootkit-ng0-file.mjs.map +1 -0
  77. package/fesm2022/bootkit-ng0-form.mjs +514 -0
  78. package/fesm2022/bootkit-ng0-form.mjs.map +1 -0
  79. package/fesm2022/bootkit-ng0-http.mjs +225 -179
  80. package/fesm2022/bootkit-ng0-http.mjs.map +1 -1
  81. package/fesm2022/bootkit-ng0-localization-locales.mjs +115 -0
  82. package/fesm2022/bootkit-ng0-localization-locales.mjs.map +1 -0
  83. package/fesm2022/bootkit-ng0-localization.mjs +481 -0
  84. package/fesm2022/bootkit-ng0-localization.mjs.map +1 -0
  85. package/fesm2022/bootkit-ng0-platform-browser.mjs +51 -0
  86. package/fesm2022/bootkit-ng0-platform-browser.mjs.map +1 -0
  87. package/fesm2022/bootkit-ng0-script.mjs +59 -0
  88. package/fesm2022/bootkit-ng0-script.mjs.map +1 -0
  89. package/fesm2022/bootkit-ng0-security.mjs +17 -15
  90. package/fesm2022/bootkit-ng0-security.mjs.map +1 -1
  91. package/file/index.d.ts +22 -0
  92. package/form/index.d.ts +127 -0
  93. package/http/index.d.ts +141 -40
  94. package/localization/index.d.ts +305 -0
  95. package/localization/locales/index.d.ts +7 -0
  96. package/package.json +90 -10
  97. package/platform/browser/index.d.ts +22 -0
  98. package/script/index.d.ts +27 -0
  99. package/security/index.d.ts +3 -9
@@ -1,89 +1,216 @@
1
- import { Subject, tap, of, Observable } from 'rxjs';
1
+ import { Subject, of, catchError, tap, Observable } from 'rxjs';
2
+ import { signal } from '@angular/core';
3
+ import { getEnumValues } from '@bootkit/ng0/common';
2
4
 
3
- class DataRequest {
4
- pageIndex;
5
- pageSize;
6
- computeTotal;
7
- filters;
8
- sort;
9
- constructor(pageIndex = 0, pageSize = 10, computeTotal = true, filters = [], sort) {
10
- this.pageIndex = pageIndex;
11
- this.pageSize = pageSize;
12
- this.computeTotal = computeTotal;
13
- this.filters = filters;
14
- this.sort = sort;
15
- }
16
- addFilter(field, value, operator = DataRequestFilterOperator.EQ) {
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
- }
5
+ /**
6
+ * Default value comparer function.
7
+ * @param a
8
+ * @param b
9
+ * @returns true if a === b else returns false
10
+ */
11
+ function defaultBooleanValueComparer(a, b) {
12
+ return a === b;
31
13
  }
32
- class DataRequestSort {
33
- field;
34
- asc;
35
- constructor(field, asc = true) {
36
- this.field = field;
37
- this.asc = asc;
14
+ function BooleanValueComparerAttribute(v) {
15
+ if (typeof v === 'function')
16
+ return v;
17
+ if (typeof v === 'string') {
18
+ return (a, b) => {
19
+ let a2 = typeof a === 'object' && a != null ? a[v] : a;
20
+ let b2 = typeof b === 'object' && b != null ? b[v] : b;
21
+ return a2 === b2;
22
+ };
38
23
  }
24
+ throw Error('invalid boolean value comparer');
39
25
  }
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;
26
+
27
+ /**
28
+ * DataRequest class represents a request for data with pagination, filtering, sorting, and field selection.
29
+ * It is used to encapsulate the parameters needed to fetch data from a data source.
30
+ * It can be used with various data sources such as HTTP services, in-memory arrays, etc.
31
+ *
32
+ */
33
+ class DataRequest {
34
+ page;
35
+ filters;
36
+ sort;
37
+ select;
38
+ computeTotal;
39
+ constructor(options) {
40
+ this.page = options?.page;
41
+ this.filters = options?.filters;
42
+ this.sort = options?.sort;
43
+ this.select = options?.select;
44
+ this.computeTotal = options?.computeTotal;
48
45
  }
49
46
  }
50
- var DataRequestFilterOperator;
51
- (function (DataRequestFilterOperator) {
52
- DataRequestFilterOperator[DataRequestFilterOperator["EQ"] = 0] = "EQ";
53
- DataRequestFilterOperator[DataRequestFilterOperator["NEQ"] = 1] = "NEQ";
54
- DataRequestFilterOperator[DataRequestFilterOperator["LT"] = 2] = "LT";
55
- DataRequestFilterOperator[DataRequestFilterOperator["LTE"] = 3] = "LTE";
56
- DataRequestFilterOperator[DataRequestFilterOperator["GT"] = 4] = "GT";
57
- DataRequestFilterOperator[DataRequestFilterOperator["GTE"] = 5] = "GTE";
58
- DataRequestFilterOperator[DataRequestFilterOperator["LI"] = 6] = "LI";
59
- DataRequestFilterOperator[DataRequestFilterOperator["SW"] = 7] = "SW";
60
- })(DataRequestFilterOperator || (DataRequestFilterOperator = {}));
47
+ // export enum DataRequestFilterOperator {
48
+ // EQ = 0,
49
+ // NEQ = 1,
50
+ // LT = 2,
51
+ // LTE = 3,
52
+ // GT = 4,
53
+ // GTE = 5,
54
+ // LI = 6,
55
+ // SW = 7,
56
+ // }
61
57
 
62
58
  class DataResult {
63
- request;
64
59
  data;
65
60
  total;
66
- constructor(request, data, total) {
67
- this.request = request;
61
+ constructor(data, total) {
68
62
  this.data = data;
69
63
  this.total = total;
70
64
  }
71
65
  }
72
66
 
67
+ /**
68
+ * Abstract base class for data sources.
69
+ * This class provides a common interface for loading data from various sources.
70
+ */
73
71
  class DataSource {
74
- _loading = false;
75
72
  changeSubject = new Subject();
73
+ loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : []));
74
+ /**
75
+ *
76
+ */
76
77
  change = this.changeSubject.asObservable();
77
- constructor() {
78
+ /**
79
+ * Indicates whether the data source is currently loading data.
80
+ */
81
+ isLoading = this.loading.asReadonly();
82
+ }
83
+
84
+ /**
85
+ * An implementation of DataSource that uses an array as the data source.
86
+ * This is useful for static data or when you want to manage the data manually.
87
+ */
88
+ class LocalDataSource extends DataSource {
89
+ items;
90
+ type = 'local';
91
+ valueExtractor = (signal);
92
+ // public valueComparer = signal<ValueComparerFunction>
93
+ constructor(items) {
94
+ super();
95
+ this.items = items;
96
+ }
97
+ /**
98
+ * Creates a LocalDataSource from enum values.
99
+ * @param enumClass The enum class to extract values from.
100
+ * @returns A LocalDataSource containing the enum values.
101
+ */
102
+ static fromEnum(enumClass) {
103
+ return new LocalDataSource(getEnumValues(enumClass));
104
+ }
105
+ load(request) {
106
+ let filteredValues = [...this.items];
107
+ let result;
108
+ // Filtering
109
+ if (Array.isArray(request.filters) && request.filters.length > 0) {
110
+ request.filters.forEach(filter => {
111
+ if (!filter.field) {
112
+ throw Error('DataRequestFilter "field" cannot be null.');
113
+ }
114
+ let isPassedByFilter = getFilterFunction(filter);
115
+ for (let i = 0; i < filteredValues.length; i++) {
116
+ let row = filteredValues[i];
117
+ if (!isPassedByFilter(row[filter.field], filter.value)) {
118
+ filteredValues.splice(i, 1);
119
+ i--; // Adjust index after removal
120
+ }
121
+ }
122
+ });
123
+ }
124
+ // Pagination
125
+ if (request.page) {
126
+ let startItemIndex = (request.page.zeroBased ? request.page.index : request.page.index - 1) * request.page.size;
127
+ result = filteredValues.slice(startItemIndex, startItemIndex + request.page.size);
128
+ }
129
+ else {
130
+ result = filteredValues;
131
+ }
132
+ // Sorting
133
+ if (request.sort) {
134
+ }
135
+ let dataResult = new DataResult(result, filteredValues.length);
136
+ // this._loading = true;
137
+ // return of(result).pipe(
138
+ // delay(5000),
139
+ // tap(x => this._loading = false)
140
+ // );
141
+ return of(dataResult);
142
+ }
143
+ remove(index) {
144
+ if (index < 0) {
145
+ throw Error('Invalid index');
146
+ }
147
+ this.items.splice(index, 1);
148
+ this.changeSubject.next({ changes: [{ type: 'remove', index, count: 1 }] });
149
+ }
150
+ insert(index, ...items) {
151
+ this.items.splice(index, 0, ...items);
152
+ this.changeSubject.next({ changes: [{ type: 'insert', items, index }] });
78
153
  }
79
- get loading() { return this._loading; }
80
- setLoading(value) {
81
- this._loading = value;
154
+ push(...items) {
155
+ let insertIndex = this.items.length;
156
+ this.items.push(items);
157
+ this.changeSubject.next({ changes: [{ type: 'insert', items, index: insertIndex }] });
158
+ }
159
+ replace(index, newValue) {
160
+ this.items[index] = newValue;
161
+ this.changeSubject.next({ changes: [{ type: 'replace', value: newValue, index }] });
162
+ }
163
+ }
164
+ function getFilterFunction(requestfilter) {
165
+ let operator = requestfilter.operator || 'contains';
166
+ let caseSensitive = requestfilter.caseSensitive || false;
167
+ // if (requestfilter.value === undefined || requestfilter.value === null) {
168
+ // return (item: any) => true; // No filter applied
169
+ // }
170
+ switch (requestfilter.operator) {
171
+ case 'contains':
172
+ return caseSensitive ?
173
+ (item, filter) => item.includes(filter) :
174
+ (item, filter) => item.toLowerCase().includes(filter.toLowerCase());
175
+ case 'startsWith':
176
+ return caseSensitive ?
177
+ (item, filter) => item.startsWith(filter) :
178
+ (item, filter) => item.toLowerCase().startsWith(filter.toLowerCase());
179
+ case 'endsWith':
180
+ return caseSensitive ?
181
+ (item, filter) => item.endsWith(filter) :
182
+ (item, filter) => item.toLowerCase().endsWith(filter.toLowerCase());
183
+ case 'eq':
184
+ if (typeof requestfilter.value === 'string') {
185
+ return caseSensitive ?
186
+ (item, filter) => item == filter :
187
+ (item, filter) => item.toString().toLowerCase() === filter.toLowerCase();
188
+ }
189
+ else {
190
+ return (item, filter) => item === filter;
191
+ }
192
+ case 'lt':
193
+ return (item, filter) => item < filter;
194
+ case 'lte':
195
+ return (item, filter) => item <= filter;
196
+ case 'gt':
197
+ return (item, filter) => item > filter;
198
+ case 'gte':
199
+ return (item, filter) => item >= filter;
200
+ case 'ne':
201
+ return (item, filter) => item !== filter;
202
+ default:
203
+ throw new Error(`filter operator: ${operator} is not implemented in ArrayDataSource.`);
82
204
  }
83
205
  }
84
206
 
85
- class AsyncDataSource extends DataSource {
207
+ /**
208
+ * RemoteDataSource is a DataSource that loads data asynchronously using a DataLoader function.
209
+ * It is used to fetch data from a remote source, such as an API.
210
+ */
211
+ class RemoteDataSource extends DataSource {
86
212
  loader;
213
+ type = 'remote';
87
214
  constructor(loader) {
88
215
  super();
89
216
  this.loader = loader;
@@ -92,38 +219,39 @@ class AsyncDataSource extends DataSource {
92
219
  }
93
220
  }
94
221
  load(request) {
95
- this.setLoading(true);
96
- return this.loader(request).pipe(tap(res => {
97
- this.setLoading(false);
222
+ this.loading.set(true);
223
+ return this.loader(request).pipe(catchError(err => {
224
+ this.loading.set(false);
225
+ throw err;
226
+ }), tap(res => {
227
+ this.loading.set(false);
98
228
  }));
99
229
  }
100
230
  }
101
231
 
102
- class ArrayDataSource extends DataSource {
103
- items;
104
- constructor(items) {
105
- super();
106
- this.items = items;
232
+ /**
233
+ * Converts a DataSourceLike to a DataSource instance.
234
+ * @param source The data source to convert.
235
+ * @returns A DataSource instance.
236
+ */
237
+ function dataSourceAttribute(source) {
238
+ if (Array.isArray(source)) {
239
+ return new LocalDataSource(source);
107
240
  }
108
- load(request) {
109
- var startItem = request.pageIndex * request.pageSize;
110
- let result = this.items.slice(startItem, startItem + request.pageSize);
111
- return of(new DataResult(request, result, this.items.length));
112
- }
113
- remove(item) {
114
- var idx = this.items.findIndex(x => x === item);
115
- if (idx > -1) {
116
- this.items.splice(idx, 1);
117
- this.changeSubject.next(0);
118
- }
241
+ else if (typeof source == 'function') {
242
+ return new RemoteDataSource(source);
119
243
  }
120
- insert(item) {
121
- var idx = this.items.push(item);
122
- this.changeSubject.next(0);
244
+ else if (source instanceof DataSource) {
245
+ return source;
123
246
  }
124
- set(items) {
125
- this.items = items;
126
- this.changeSubject.next(0);
247
+ else if (source === undefined || source === null) {
248
+ return new LocalDataSource([]);
249
+ }
250
+ else if (typeof source === 'object') {
251
+ return LocalDataSource.fromEnum(source);
252
+ }
253
+ else {
254
+ throw new Error('Invalid data source.');
127
255
  }
128
256
  }
129
257
 
@@ -132,7 +260,7 @@ function toDataResult(dr) {
132
260
  return new Observable(subscriber => {
133
261
  source.subscribe({
134
262
  next(event) {
135
- subscriber.next(new DataResult(dr, event));
263
+ subscriber.next(new DataResult(event));
136
264
  },
137
265
  error(error) {
138
266
  subscriber.error(error);
@@ -145,9 +273,82 @@ function toDataResult(dr) {
145
273
  };
146
274
  }
147
275
 
276
+ /**
277
+ * Default value extractor function.
278
+ * @param a The input value
279
+ * @returns the input value
280
+ */
281
+ function defaultValueExtractor(a) {
282
+ return a;
283
+ }
284
+ /**
285
+ * Converts a ValueExtractorLike to a ValueExtractorFunction.
286
+ * @param v The value extractor to convert.
287
+ * @returns A function that extracts the desired value.
288
+ */
289
+ function ValueExtractorAttribute(v) {
290
+ if (typeof v === 'function')
291
+ return v;
292
+ if (typeof v === 'string') {
293
+ return (item) => item ? item[v] : undefined;
294
+ }
295
+ throw Error('invalid value extractor');
296
+ }
297
+
298
+ /**
299
+ * Default value comparer function.
300
+ * @param a
301
+ * @param b
302
+ * @returns -1 if a < b, 1 if a > b, 0 if a === b
303
+ */
304
+ function defaultValueComparer(a, b) {
305
+ return a === b ? 0 : a < b ? -1 : 1;
306
+ }
307
+ /**
308
+ * Converts a ValueComparerLike to a ValueComparerFunction.
309
+ * @param v The value comparer to convert.
310
+ * @returns A function that compares two values.
311
+ */
312
+ function ValueComparerAttribute(v) {
313
+ if (typeof v === 'function')
314
+ return v;
315
+ if (typeof v === 'string') {
316
+ return (a, b) => a?.[v] === b?.[v] ? 0 : a?.[v] < b?.[v] ? -1 : 1;
317
+ }
318
+ throw Error('invalid value comparer');
319
+ }
320
+
321
+ /**
322
+ * A filter predicate that checks if a string contains the filter criteria (case insensitive).
323
+ * @param item The item to test against the filter.
324
+ * @param criteria The filter criteria.
325
+ * @returns True if the item matches the filter, false otherwise.
326
+ */
327
+ const stringFilter = (item, criteria) => {
328
+ if (criteria == null || criteria == '' || item == null || item === '') {
329
+ return true;
330
+ }
331
+ return item.toString().toLowerCase().includes(criteria.toString().toLowerCase());
332
+ };
333
+ /**
334
+ * Converts a FilterPredicateLike to a FilterPredicate function.
335
+ * If the input is a string, it creates a predicate that checks the property with that name.
336
+ * @param v The FilterPredicateLike to convert.
337
+ * @returns The corresponding FilterPredicate function.
338
+ */
339
+ function FilterPredicateAttribute(v) {
340
+ if (typeof v === 'function')
341
+ return v;
342
+ if (typeof v === 'string') {
343
+ let predicate = (item, criteria) => stringFilter(item?.[v], criteria);
344
+ return predicate;
345
+ }
346
+ throw Error('invalid filter predicate');
347
+ }
348
+
148
349
  /**
149
350
  * Generated bundle index. Do not edit.
150
351
  */
151
352
 
152
- export { ArrayDataSource, AsyncDataSource, DataRequest, DataRequestFilter, DataRequestFilterOperator, DataRequestSort, DataResult, DataSource, toDataResult };
353
+ export { BooleanValueComparerAttribute, DataRequest, DataResult, DataSource, FilterPredicateAttribute, LocalDataSource, RemoteDataSource, ValueComparerAttribute, ValueExtractorAttribute, dataSourceAttribute, defaultBooleanValueComparer, defaultValueComparer, defaultValueExtractor, stringFilter, toDataResult };
153
354
  //# 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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C;AACJ,KAAC;AACH;;ACpBA;;AAEG;;;;"}
1
+ {"version":3,"file":"bootkit-ng0-data.mjs","sources":["../../../projects/ng0/data/boolean-value-comparer.ts","../../../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/value-extractor.ts","../../../projects/ng0/data/value-comparer.ts","../../../projects/ng0/data/filter.ts","../../../projects/ng0/data/bootkit-ng0-data.ts"],"sourcesContent":["/**\r\n * Boolean value comparer function type.\r\n * @param a First value to compare.\r\n * @param b Second value to compare.\r\n * @returns true if a is considered equal to b else returns false\r\n */\r\nexport type BooleanValueComparer = (a: any, b: any) => boolean;\r\n\r\n/**\r\n * Boolean value comparer can be a function or a string representing the property name to compare.\r\n */\r\nexport type BooleanValueComparerLike = BooleanValueComparer | string;\r\n\r\n/**\r\n * Default value comparer function.\r\n * @param a \r\n * @param b \r\n * @returns true if a === b else returns false\r\n */\r\nexport function defaultBooleanValueComparer(a: any, b: any): boolean {\r\n return a === b;\r\n}\r\n\r\nexport function BooleanValueComparerAttribute(v: BooleanValueComparerLike): BooleanValueComparer {\r\n if (typeof v === 'function')\r\n return v;\r\n if (typeof v === 'string') {\r\n return (a: any, b: any) => {\r\n \r\n let a2 = typeof a === 'object' && a != null ? a[v] : a;\r\n let b2 = typeof b === 'object' && b != null ? b[v] : b;\r\n return a2 === b2;\r\n }\r\n }\r\n\r\n throw Error('invalid boolean value comparer');\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// 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, Subject } 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\nexport interface DataSourceChange {\r\n type: 'insert' | 'replace' | 'remove';\r\n}\r\n\r\nexport interface DataSourceItemInsert extends DataSourceChange {\r\n type: 'insert'\r\n\r\n /** Insert index */\r\n index?: number;\r\n items: any[];\r\n}\r\n\r\nexport interface DataSourceItemReplace extends DataSourceChange {\r\n type: 'replace'\r\n index: number;\r\n value: any;\r\n}\r\n\r\nexport interface DataSourceItemRemove extends DataSourceChange {\r\n type: 'remove'\r\n index: number;\r\n count?: number\r\n}\r\n\r\n\r\nexport interface DataSourceChangeEvent {\r\n changes: Array<DataSourceItemInsert | DataSourceItemReplace | DataSourceItemRemove>\r\n}\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 abstract readonly type: 'local' | 'remote'; \r\n \r\n protected changeSubject = new Subject<DataSourceChangeEvent>();\r\n protected loading = signal(false);\r\n\r\n /**\r\n * \r\n */\r\n public readonly change = this.changeSubject.asObservable();\r\n\r\n /**\r\n * Indicates whether the data source is currently loading data.\r\n */\r\n public isLoading = this.loading.asReadonly();\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 { signal } from \"@angular/core\";\r\nimport { ValueExtractor } from \"./value-extractor\";\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 public valueExtractor = signal<ValueExtractor>\r\n // public valueComparer = signal<ValueComparerFunction>\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 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.field) {\r\n throw Error('DataRequestFilter \"field\" cannot be null.');\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 public remove(index: any) {\r\n if (index < 0) {\r\n throw Error('Invalid index');\r\n }\r\n\r\n this.items.splice(index, 1);\r\n this.changeSubject.next({ changes: [{ type: 'remove', index, count: 1 }] });\r\n }\r\n\r\n public insert(index: number, ...items: any[]) {\r\n this.items.splice(index, 0, ...items);\r\n this.changeSubject.next({ changes: [{ type: 'insert', items, index }] });\r\n }\r\n\r\n public push(...items: any[]) {\r\n let insertIndex = this.items.length;\r\n this.items.push(items);\r\n this.changeSubject.next({ changes: [{ type: 'insert', items, index: insertIndex }] });\r\n }\r\n\r\n public replace(index: number, newValue: any) {\r\n this.items[index] = newValue;\r\n this.changeSubject.next({ changes: [{ type: 'replace', value: newValue, index }] });\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.loading.set(true);\r\n\r\n return this.loader(request).pipe(\r\n catchError(err => {\r\n this.loading.set(false);\r\n throw err;\r\n }),\r\n tap(res => {\r\n this.loading.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","/**\r\n * Value extractor function type.\r\n */\r\nexport type ValueExtractor = (a: any) => any;\r\n\r\n/**\r\n * Value extractor can be a function or a string representing the property name to extract.\r\n */\r\nexport type ValueExtractorLike = ValueExtractor | string;\r\n\r\n\r\n/**\r\n * Default value extractor function.\r\n * @param a The input value\r\n * @returns the input value\r\n */\r\nexport function defaultValueExtractor(a: any): any {\r\n return a;\r\n}\r\n\r\n/**\r\n * Converts a ValueExtractorLike to a ValueExtractorFunction.\r\n * @param v The value extractor to convert.\r\n * @returns A function that extracts the desired value.\r\n */\r\nexport function ValueExtractorAttribute(v: ValueExtractorLike): ValueExtractor {\r\n if (typeof v === 'function')\r\n return v;\r\n if (typeof v === 'string') {\r\n return (item: any) => item ? item[v] : undefined;\r\n }\r\n\r\n throw Error('invalid value extractor');\r\n}\r\n","/**\r\n * A comparison function type that defines an ordering relation between two values.\r\n * @param a The first value to compare.\r\n * @param b The second value to compare.\r\n * @returns\r\n * - A negative number if `a` should come before `b`\r\n * - A positive number if `a` should come after `b`\r\n * - Zero if `a` and `b` are considered equal\r\n */\r\nexport type ValueComparer = (a: any, b: any) => number;\r\n\r\n/**\r\n * Value comparer can be a function or a string representing the property name to compare.\r\n */\r\nexport type ValueComparerLike = ValueComparer | string;\r\n\r\n/**\r\n * Default value comparer function.\r\n * @param a \r\n * @param b \r\n * @returns -1 if a < b, 1 if a > b, 0 if a === b\r\n */\r\nexport function defaultValueComparer(a: any, b: any): number {\r\n return a === b ? 0 : a < b ? -1 : 1;\r\n}\r\n\r\n/**\r\n * Converts a ValueComparerLike to a ValueComparerFunction.\r\n * @param v The value comparer to convert.\r\n * @returns A function that compares two values.\r\n */\r\nexport function ValueComparerAttribute(v: ValueComparerLike): ValueComparer {\r\n if (typeof v === 'function')\r\n return v;\r\n if (typeof v === 'string') {\r\n return (a: any, b: any) => a?.[v] === b?.[v] ? 0 : a?.[v] < b?.[v] ? -1 : 1;\r\n }\r\n\r\n throw Error('invalid value comparer');\r\n}\r\n","/**\r\n * Filter predicate function type.\r\n * @param item The item to test against the filter.\r\n * @param params Additional parameters to pass to the filter function.\r\n * @returns True if the item matches the filter, false otherwise.\r\n */\r\nexport type FilterPredicate = (item: any, ...params: any[]) => boolean;\r\n\r\n/**\r\n * Filter predicate can be a function or a string representing the property name to filter.\r\n */\r\nexport type FilterPredicateLike = FilterPredicate | string;\r\n\r\n/**\r\n * A filter predicate that checks if a string contains the filter criteria (case insensitive).\r\n * @param item The item to test against the filter.\r\n * @param criteria The filter criteria.\r\n * @returns True if the item matches the filter, false otherwise.\r\n */\r\nexport const stringFilter: FilterPredicate = (item: string, criteria?: string) => {\r\n if (criteria == null || criteria == '' || item == null || item === '') {\r\n return true;\r\n }\r\n\r\n return item.toString().toLowerCase().includes(criteria.toString().toLowerCase());\r\n}\r\n\r\n/**\r\n * Converts a FilterPredicateLike to a FilterPredicate function.\r\n * If the input is a string, it creates a predicate that checks the property with that name.\r\n * @param v The FilterPredicateLike to convert.\r\n * @returns The corresponding FilterPredicate function.\r\n */\r\nexport function FilterPredicateAttribute(v: FilterPredicateLike): FilterPredicate {\r\n if (typeof v === 'function')\r\n return v;\r\n if (typeof v === 'string') {\r\n let predicate: FilterPredicate = (item: any, criteria?: string) => stringFilter(item?.[v], criteria);\r\n return predicate;\r\n }\r\n\r\n throw Error('invalid filter predicate');\r\n}\r\n","/**\n * Generated bundle index. Do not edit.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CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC;AACpG,QAAA,OAAO,SAAS;IACpB;AAEA,IAAA,MAAM,KAAK,CAAC,0BAA0B,CAAC;AAC3C;;AC1CA;;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,QAA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