@rt-tools/ui-kit 0.0.12 → 0.0.14
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.
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Input, Attribute, Optional, Directive, Pipe, Injectable, inject, InjectionToken, HostBinding, ChangeDetectionStrategy, Component, contentChild, TemplateRef, input, booleanAttribute, output, viewChild, signal, computed, numberAttribute, Injector, ViewEncapsulation, model, DestroyRef, effect, HostListener, ElementRef, forwardRef, ChangeDetectorRef, untracked, ViewContainerRef, afterNextRender } from '@angular/core';
|
|
3
|
-
import { PlatformService, WINDOW, checkIsMatchingValues, SanitizePipe, RtIconOutlinedDirective, RtHideTooltipDirective, transformArrayInput, RtScrollToElementDirective, RtNavigationDirective, isString, isNumber, areArraysEqual, EmptyToDashPipe, LIST_SORT_ORDER_ENUM, FILTER_OPERATOR_TYPE_ENUM, FILTER_OPERATORS, isDate, transformStringInput, BreakpointService, DeviceDetectorService, OSTypes, RtScrollDirective, BreakStringPipe, EntityToStringPipe, OVERLAY_POSITIONS, areArraysEqualUnordered, checkIsEntityInArrayByKey, sortByAlphabet, RtEscapeKeyDirective, POSITION_ENUM } from '@rt-tools/utils';
|
|
4
|
-
import { Observable, ReplaySubject, share, Subject, merge, of, noop } from 'rxjs';
|
|
5
1
|
import { NgStyle, NgClass, NgComponentOutlet, NgTemplateOutlet, AsyncPipe, TitleCasePipe, DOCUMENT } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { inject, HostBinding, ChangeDetectionStrategy, Component, Injectable, Directive, contentChild, TemplateRef, input, booleanAttribute, output, viewChild, signal, computed, numberAttribute, InjectionToken, Injector, ViewEncapsulation, model, DestroyRef, effect, HostListener, ElementRef, forwardRef, ChangeDetectorRef, untracked, ViewContainerRef, afterNextRender } from '@angular/core';
|
|
6
4
|
import * as i1 from '@angular/forms';
|
|
7
5
|
import { FormControl, Validators, ReactiveFormsModule, FormBuilder, FormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
|
|
8
6
|
import * as i5 from '@angular/material/button';
|
|
@@ -14,6 +12,9 @@ import * as i3 from '@angular/material/input';
|
|
|
14
12
|
import { MatInputModule, MatInput, MatFormField as MatFormField$1, MatLabel } from '@angular/material/input';
|
|
15
13
|
import * as i4 from '@angular/material/select';
|
|
16
14
|
import { MatSelectModule, MatSelect } from '@angular/material/select';
|
|
15
|
+
import { BlockDirective, ElemDirective, WINDOW, IDBStorageService, ModDirective, PlatformService } from '@rt-tools/core';
|
|
16
|
+
import { checkIsMatchingValues, SanitizePipe, RtIconOutlinedDirective, RtHideTooltipDirective, transformArrayInput, RtScrollToElementDirective, RtNavigationDirective, isString, isNumber, areArraysEqual, EmptyToDashPipe, LIST_SORT_ORDER_ENUM, FILTER_OPERATOR_TYPE_ENUM, FILTER_OPERATORS, isDate, transformStringInput, BreakpointService, DeviceDetectorService, OSTypes, RtScrollDirective, BreakStringPipe, EntityToStringPipe, OVERLAY_POSITIONS, areArraysEqualUnordered, checkIsEntityInArrayByKey, sortByAlphabet, RtEscapeKeyDirective, POSITION_ENUM } from '@rt-tools/utils';
|
|
17
|
+
import { ReplaySubject, share, Subject, merge, of, noop } from 'rxjs';
|
|
17
18
|
import { filter, map, delay, tap, take, switchMap, debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
|
18
19
|
import { MatListItem, MatNavList, MatListItemIcon, MatListItemTitle } from '@angular/material/list';
|
|
19
20
|
import * as i1$2 from '@angular/material/sidenav';
|
|
@@ -46,631 +47,6 @@ import { computePosition, offset, flip, shift } from '@floating-ui/dom';
|
|
|
46
47
|
import { MAT_SNACK_BAR_DATA, MatSnackBarRef, MatSnackBar } from '@angular/material/snack-bar';
|
|
47
48
|
import { ImageCropperComponent } from 'ngx-image-cropper';
|
|
48
49
|
|
|
49
|
-
const BEM_MODULE_CONFIG = {
|
|
50
|
-
separators: {
|
|
51
|
-
el: '__',
|
|
52
|
-
mod: '--',
|
|
53
|
-
val: '--',
|
|
54
|
-
},
|
|
55
|
-
ignoreValues: false,
|
|
56
|
-
modCase: 'kebab',
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function modNameHandler(str) {
|
|
60
|
-
switch (BEM_MODULE_CONFIG.modCase) {
|
|
61
|
-
case 'kebab':
|
|
62
|
-
return str
|
|
63
|
-
? str
|
|
64
|
-
.replace(/[A-Z]/g, function (s) {
|
|
65
|
-
return '-' + s.toLowerCase();
|
|
66
|
-
})
|
|
67
|
-
.replace(/$-/, '')
|
|
68
|
-
: '';
|
|
69
|
-
case 'snake':
|
|
70
|
-
return str
|
|
71
|
-
? str
|
|
72
|
-
.replace(/[A-Z]/g, function (s) {
|
|
73
|
-
return '_' + s.toLowerCase();
|
|
74
|
-
})
|
|
75
|
-
.replace(/$-/, '')
|
|
76
|
-
: '';
|
|
77
|
-
default:
|
|
78
|
-
return str;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function generateClass(blockName, elemName, modName, modValue) {
|
|
82
|
-
if (BEM_MODULE_CONFIG.ignoreValues) {
|
|
83
|
-
modValue = !!modValue;
|
|
84
|
-
}
|
|
85
|
-
if (typeof modValue !== 'string' && typeof modValue !== 'boolean') {
|
|
86
|
-
modValue = !!modValue;
|
|
87
|
-
}
|
|
88
|
-
let cls = blockName;
|
|
89
|
-
if (elemName) {
|
|
90
|
-
cls += BEM_MODULE_CONFIG.separators.el + elemName;
|
|
91
|
-
}
|
|
92
|
-
if (modName) {
|
|
93
|
-
modName = modNameHandler(modName);
|
|
94
|
-
cls += BEM_MODULE_CONFIG.separators.mod + modName;
|
|
95
|
-
if (typeof modValue !== 'boolean' && modValue != null) {
|
|
96
|
-
cls += BEM_MODULE_CONFIG.separators.val + modValue;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return cls;
|
|
100
|
-
}
|
|
101
|
-
function parseMods(mods) {
|
|
102
|
-
if (typeof mods === 'string') {
|
|
103
|
-
mods = mods.split(/\s+/);
|
|
104
|
-
}
|
|
105
|
-
if (Array.isArray(mods)) {
|
|
106
|
-
const modsObj = {};
|
|
107
|
-
mods.forEach((key) => {
|
|
108
|
-
if (key) {
|
|
109
|
-
modsObj[key] = true;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
mods = modsObj;
|
|
113
|
-
}
|
|
114
|
-
else if (typeof mods !== 'object') {
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
117
|
-
return mods;
|
|
118
|
-
}
|
|
119
|
-
function setMods(blockName, elemName, mods, oldMods, element, renderer) {
|
|
120
|
-
Object.keys(mods).forEach((key) => {
|
|
121
|
-
if (oldMods[key]) {
|
|
122
|
-
if (mods[key] === oldMods[key]) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
renderer.removeClass(element.nativeElement, generateClass(blockName, elemName, key, oldMods[key]));
|
|
126
|
-
}
|
|
127
|
-
if (mods[key]) {
|
|
128
|
-
renderer.addClass(element.nativeElement, generateClass(blockName, elemName, key, mods[key]));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
Object.keys(oldMods).forEach((key) => {
|
|
132
|
-
if (!(key in mods) && oldMods[key]) {
|
|
133
|
-
renderer.removeClass(element.nativeElement, generateClass(blockName, elemName, key, oldMods[key]));
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class BlockDirective {
|
|
139
|
-
#mods = {};
|
|
140
|
-
#modSerialized = '';
|
|
141
|
-
constructor(element, renderer, name, elem) {
|
|
142
|
-
this.element = element;
|
|
143
|
-
this.renderer = renderer;
|
|
144
|
-
this.name = name;
|
|
145
|
-
this.elem = elem;
|
|
146
|
-
if (!elem && !(element.nativeElement instanceof Comment)) {
|
|
147
|
-
renderer.addClass(element.nativeElement, generateClass(name));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
ngOnChanges() {
|
|
151
|
-
if (JSON.stringify(this.rtMod) !== this.#modSerialized && !this.elem) {
|
|
152
|
-
this.#modSerialized = JSON.stringify(this.rtMod);
|
|
153
|
-
let mods = this.rtMod;
|
|
154
|
-
const { renderer, element, name } = this;
|
|
155
|
-
mods = parseMods(mods);
|
|
156
|
-
if (!(element.nativeElement instanceof Comment)) {
|
|
157
|
-
setMods(name, '', mods, this.#mods || {}, element, renderer);
|
|
158
|
-
}
|
|
159
|
-
this.#mods = this.#mods === mods ? Object.assign({}, mods) : mods;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: BlockDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: 'rtBlock', attribute: true }, { token: 'rtElem', attribute: true, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
163
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.1", type: BlockDirective, isStandalone: true, selector: "[rtBlock]", inputs: { rtMod: "rtMod" }, usesOnChanges: true, ngImport: i0 }); }
|
|
164
|
-
}
|
|
165
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: BlockDirective, decorators: [{
|
|
166
|
-
type: Directive,
|
|
167
|
-
args: [{
|
|
168
|
-
selector: '[rtBlock]',
|
|
169
|
-
}]
|
|
170
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: undefined, decorators: [{
|
|
171
|
-
type: Attribute,
|
|
172
|
-
args: ['rtBlock']
|
|
173
|
-
}] }, { type: undefined, decorators: [{
|
|
174
|
-
type: Optional
|
|
175
|
-
}, {
|
|
176
|
-
type: Attribute,
|
|
177
|
-
args: ['rtElem']
|
|
178
|
-
}] }], propDecorators: { rtMod: [{
|
|
179
|
-
type: Input
|
|
180
|
-
}] } });
|
|
181
|
-
|
|
182
|
-
class ConcatClassesPipe {
|
|
183
|
-
transform(classes) {
|
|
184
|
-
// eslint-disable-next-line
|
|
185
|
-
const validClassList = classes.flat().filter((className) => typeof className === 'string' && !!className.trim());
|
|
186
|
-
return validClassList.join(' ');
|
|
187
|
-
}
|
|
188
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: ConcatClassesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
189
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.1", ngImport: i0, type: ConcatClassesPipe, isStandalone: true, name: "concatClasses" }); }
|
|
190
|
-
}
|
|
191
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: ConcatClassesPipe, decorators: [{
|
|
192
|
-
type: Pipe,
|
|
193
|
-
args: [{
|
|
194
|
-
name: 'concatClasses',
|
|
195
|
-
}]
|
|
196
|
-
}] });
|
|
197
|
-
|
|
198
|
-
class ElemDirective {
|
|
199
|
-
#mods = {};
|
|
200
|
-
#modSerialized = '';
|
|
201
|
-
constructor(element, renderer, name, rtBlock) {
|
|
202
|
-
this.element = element;
|
|
203
|
-
this.renderer = renderer;
|
|
204
|
-
this.name = name;
|
|
205
|
-
this.rtBlock = rtBlock;
|
|
206
|
-
this.blockName = rtBlock.name;
|
|
207
|
-
renderer.addClass(element.nativeElement, generateClass(rtBlock.name, name));
|
|
208
|
-
}
|
|
209
|
-
ngOnChanges() {
|
|
210
|
-
if (JSON.stringify(this.rtMod) !== this.#modSerialized) {
|
|
211
|
-
this.#modSerialized = JSON.stringify(this.rtMod);
|
|
212
|
-
let mods = this.rtMod;
|
|
213
|
-
const { renderer, element, blockName, name } = this;
|
|
214
|
-
mods = parseMods(mods);
|
|
215
|
-
setMods(blockName, name, mods, this.#mods || {}, element, renderer);
|
|
216
|
-
this.#mods = this.#mods === mods ? Object.assign({}, mods) : mods;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: ElemDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: 'rtElem', attribute: true }, { token: BlockDirective }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
220
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.1", type: ElemDirective, isStandalone: true, selector: "[rtElem]", inputs: { rtMod: "rtMod" }, usesOnChanges: true, ngImport: i0 }); }
|
|
221
|
-
}
|
|
222
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: ElemDirective, decorators: [{
|
|
223
|
-
type: Directive,
|
|
224
|
-
args: [{
|
|
225
|
-
selector: '[rtElem]',
|
|
226
|
-
}]
|
|
227
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: undefined, decorators: [{
|
|
228
|
-
type: Attribute,
|
|
229
|
-
args: ['rtElem']
|
|
230
|
-
}] }, { type: BlockDirective }], propDecorators: { rtMod: [{
|
|
231
|
-
type: Input
|
|
232
|
-
}] } });
|
|
233
|
-
|
|
234
|
-
class ModDirective {
|
|
235
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: ModDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
236
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.1", type: ModDirective, isStandalone: true, selector: "[rtMod]", ngImport: i0 }); }
|
|
237
|
-
}
|
|
238
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: ModDirective, decorators: [{
|
|
239
|
-
type: Directive,
|
|
240
|
-
args: [{
|
|
241
|
-
selector: '[rtMod]',
|
|
242
|
-
}]
|
|
243
|
-
}] });
|
|
244
|
-
|
|
245
|
-
var STORAGE_TYPES_ENUM;
|
|
246
|
-
(function (STORAGE_TYPES_ENUM) {
|
|
247
|
-
STORAGE_TYPES_ENUM["LOCAL"] = "local";
|
|
248
|
-
STORAGE_TYPES_ENUM["SESSION"] = "session";
|
|
249
|
-
STORAGE_TYPES_ENUM["IN_MEMORY"] = "inMemory";
|
|
250
|
-
STORAGE_TYPES_ENUM["CUSTOM"] = "custom";
|
|
251
|
-
})(STORAGE_TYPES_ENUM || (STORAGE_TYPES_ENUM = {}));
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* A service that implements the `Storage` interface using an in-memory map.
|
|
255
|
-
* This service provides a fallback storage solution when `localStorage`
|
|
256
|
-
* or `sessionStorage` is not available, such as in server-side rendering (SSR) scenarios.
|
|
257
|
-
*
|
|
258
|
-
* @Injectable
|
|
259
|
-
*/
|
|
260
|
-
class InMemoryStorageService {
|
|
261
|
-
/**
|
|
262
|
-
* Private in-memory storage map used to store key-value pairs.
|
|
263
|
-
* The keys are strings, the values are strings.
|
|
264
|
-
* The map is private and cannot be accessed directly.
|
|
265
|
-
* Instead, the public methods of the service should be used to interact with the storage.
|
|
266
|
-
* The map is initialized as an empty map.
|
|
267
|
-
*
|
|
268
|
-
* @type {Map<string, string>}
|
|
269
|
-
* @private
|
|
270
|
-
* @internal
|
|
271
|
-
* @readonly
|
|
272
|
-
*/
|
|
273
|
-
#storage = new Map();
|
|
274
|
-
/**
|
|
275
|
-
* Returns the number of key-value pairs currently stored.
|
|
276
|
-
*
|
|
277
|
-
* @returns the number of items in storage
|
|
278
|
-
* @public
|
|
279
|
-
*/
|
|
280
|
-
get length() {
|
|
281
|
-
return this.#storage.size;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Retrieves the value associated with the given key.
|
|
285
|
-
*
|
|
286
|
-
* @param key - The name of the key to retrieve the value for
|
|
287
|
-
* @returns the value associated with the key, or `null` if the key does not exist
|
|
288
|
-
* @public
|
|
289
|
-
* @returns string | null
|
|
290
|
-
*/
|
|
291
|
-
getItem(key) {
|
|
292
|
-
return this.#storage.get(key) || null;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Adds or updates the key-value pair in the storage.
|
|
296
|
-
*
|
|
297
|
-
* @param key - The name of the key to create or update
|
|
298
|
-
* @param data - The value to associate with the key
|
|
299
|
-
* @public
|
|
300
|
-
* @returns void
|
|
301
|
-
*/
|
|
302
|
-
setItem(key, data) {
|
|
303
|
-
this.#storage.set(key, data);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Retrieves the key at the specified index.
|
|
307
|
-
*
|
|
308
|
-
* @param index - The index of the key to retrieve
|
|
309
|
-
* @returns the key at the specified index, or `null` if the index is out of bounds
|
|
310
|
-
* @public
|
|
311
|
-
* @returns string | null
|
|
312
|
-
*/
|
|
313
|
-
key(index) {
|
|
314
|
-
return Array.from(this.#storage.keys())[index] || null;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Removes the key-value pair associated with the given key.
|
|
318
|
-
*
|
|
319
|
-
* @param key - The name of the key to remove
|
|
320
|
-
* @public
|
|
321
|
-
* @returns void
|
|
322
|
-
*/
|
|
323
|
-
removeItem(key) {
|
|
324
|
-
this.#storage.delete(key);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Clears all key-value pairs from the storage.
|
|
328
|
-
*
|
|
329
|
-
* @public
|
|
330
|
-
* @returns void
|
|
331
|
-
*/
|
|
332
|
-
clear() {
|
|
333
|
-
this.#storage.clear();
|
|
334
|
-
}
|
|
335
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: InMemoryStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
336
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: InMemoryStorageService }); }
|
|
337
|
-
}
|
|
338
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: InMemoryStorageService, decorators: [{
|
|
339
|
-
type: Injectable
|
|
340
|
-
}] });
|
|
341
|
-
|
|
342
|
-
class JsonConverter {
|
|
343
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
|
-
convertTo(data) {
|
|
345
|
-
let parsedData;
|
|
346
|
-
try {
|
|
347
|
-
parsedData = JSON.stringify(data);
|
|
348
|
-
}
|
|
349
|
-
catch (e) {
|
|
350
|
-
// eslint-disable-next-line no-console
|
|
351
|
-
console.error(e);
|
|
352
|
-
parsedData = 'null';
|
|
353
|
-
}
|
|
354
|
-
return parsedData;
|
|
355
|
-
}
|
|
356
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
|
-
convertFrom(data) {
|
|
358
|
-
if (typeof data === 'string') {
|
|
359
|
-
try {
|
|
360
|
-
return JSON.parse(data);
|
|
361
|
-
}
|
|
362
|
-
catch (e) {
|
|
363
|
-
// eslint-disable-next-line no-console
|
|
364
|
-
console.error(e);
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Factory for creating or returning `localStorage`.
|
|
374
|
-
* Returns `localStorage` global object if the application is running in a browser,
|
|
375
|
-
* otherwise returns null.
|
|
376
|
-
*
|
|
377
|
-
* @returns localStorage or null
|
|
378
|
-
*/
|
|
379
|
-
function localStorageFactory() {
|
|
380
|
-
return inject(PlatformService).isPlatformBrowser ? localStorage : null;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Factory for creating or returning `sessionStorage`.
|
|
384
|
-
* Returns `sessionStorage` global object if the application is running in a browser,
|
|
385
|
-
* otherwise returns null.
|
|
386
|
-
*
|
|
387
|
-
* @returns sessionStorage or null
|
|
388
|
-
*/
|
|
389
|
-
function sessionStorageFactory() {
|
|
390
|
-
return inject(PlatformService).isPlatformBrowser ? sessionStorage : null;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Factory for creating `InMemoryStorageService`.
|
|
394
|
-
* Returns a new instance of InMemoryStorageService.
|
|
395
|
-
*
|
|
396
|
-
* @returns a new instance of InMemoryStorageService
|
|
397
|
-
*/
|
|
398
|
-
function inMemoryStorageFactory() {
|
|
399
|
-
return new InMemoryStorageService();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const CUSTOM_STORAGE = new InjectionToken('CUSTOM_STORAGE');
|
|
403
|
-
|
|
404
|
-
const IN_MEMORY_STORAGE = new InjectionToken('IN_MEMORY_STORAGE');
|
|
405
|
-
|
|
406
|
-
const LOCAL_STORAGE = new InjectionToken('LOCAL_STORAGE');
|
|
407
|
-
|
|
408
|
-
const SESSION_STORAGE = new InjectionToken('SESSION_STORAGE');
|
|
409
|
-
|
|
410
|
-
const defaultStorageConfig = {
|
|
411
|
-
ctx: STORAGE_TYPES_ENUM.LOCAL,
|
|
412
|
-
storageRef: null,
|
|
413
|
-
converter: new JsonConverter(),
|
|
414
|
-
};
|
|
415
|
-
/**
|
|
416
|
-
* A service for managing data storage across different storage types,
|
|
417
|
-
* including `localStorage`, `sessionStorage`, and an in-memory storage fallback.
|
|
418
|
-
* The service supports custom storage types and data conversion through configurable converters.
|
|
419
|
-
*
|
|
420
|
-
* @Injectable
|
|
421
|
-
*/
|
|
422
|
-
class StorageService {
|
|
423
|
-
#platformService = inject(PlatformService);
|
|
424
|
-
#localStorageRef = inject(LOCAL_STORAGE);
|
|
425
|
-
#sessionStorageRef = inject(SESSION_STORAGE);
|
|
426
|
-
#inMemoryStorageRef = inject(IN_MEMORY_STORAGE);
|
|
427
|
-
#customStorageRef = inject(CUSTOM_STORAGE, { optional: true });
|
|
428
|
-
/**
|
|
429
|
-
* Retrieves an item from the specified storage context.
|
|
430
|
-
*
|
|
431
|
-
* @param key - The key of the item to retrieve.
|
|
432
|
-
* @param config - Optional configuration for the storage context and data conversion.
|
|
433
|
-
* @returns The retrieved item, converted from storage if a converter is provided, or `null` if the item does not exist.
|
|
434
|
-
*/
|
|
435
|
-
getItem(key, config) {
|
|
436
|
-
const fullConfig = { ...defaultStorageConfig, ...config };
|
|
437
|
-
const item = this.#storage(fullConfig.ctx)?.getItem(key);
|
|
438
|
-
return fullConfig.converter?.convertFrom(item) ?? item ?? null;
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Stores an item in the specified storage context.
|
|
442
|
-
*
|
|
443
|
-
* @param key - The key to associate with the stored item.
|
|
444
|
-
* @param data - The data to store, which will be converted if a converter is provided.
|
|
445
|
-
* @param config - Optional configuration for the storage context and data conversion.
|
|
446
|
-
*/
|
|
447
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
448
|
-
setItem(key, data, config) {
|
|
449
|
-
const fullConfig = { ...defaultStorageConfig, ...config };
|
|
450
|
-
const parsedValue = fullConfig.converter?.convertTo(data) ?? data;
|
|
451
|
-
this.#storage(fullConfig.ctx)?.setItem(key, parsedValue);
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Checks if a given key exists in the specified storage context.
|
|
455
|
-
*
|
|
456
|
-
* @param key - The key to check for.
|
|
457
|
-
* @param ctx - The storage context to search in (local, session, or in-memory).
|
|
458
|
-
* @returns `true` if the key exists, `false` otherwise.
|
|
459
|
-
*/
|
|
460
|
-
hasKey(key, ctx = defaultStorageConfig.ctx) {
|
|
461
|
-
return Object.prototype.hasOwnProperty.call(this.#storage(ctx), key);
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Executes callback functions based on whether a key exists in the specified storage context.
|
|
465
|
-
*
|
|
466
|
-
* @param key - The key to check for.
|
|
467
|
-
* @param onHas - The callback to execute if the key exists.
|
|
468
|
-
* @param onHasNot - The optional callback to execute if the key does not exist.
|
|
469
|
-
* @param config - Optional configuration for the storage context and data conversion.
|
|
470
|
-
*/
|
|
471
|
-
onHasKey(key, onHas, onHasNot, config) {
|
|
472
|
-
const fullConfig = { ...defaultStorageConfig, ...config };
|
|
473
|
-
if (this.hasKey(key, fullConfig.ctx)) {
|
|
474
|
-
onHas(this.getItem(key, fullConfig));
|
|
475
|
-
}
|
|
476
|
-
else if (onHasNot !== void 0) {
|
|
477
|
-
onHasNot();
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Removes an item from the specified storage context.
|
|
482
|
-
*
|
|
483
|
-
* @param key - The key of the item to remove.
|
|
484
|
-
* @param ctx - The storage context from which to remove the item.
|
|
485
|
-
*/
|
|
486
|
-
removeItem(key, ctx = defaultStorageConfig.ctx) {
|
|
487
|
-
this.#storage(ctx)?.removeItem(key);
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Clears all items from the specified storage context.
|
|
491
|
-
*
|
|
492
|
-
* @param ctx - The storage context to clear.
|
|
493
|
-
*/
|
|
494
|
-
clear(ctx = defaultStorageConfig.ctx) {
|
|
495
|
-
this.#storage(ctx)?.clear();
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Returns the appropriate storage reference based on the storage context and platform.
|
|
499
|
-
*
|
|
500
|
-
* @param ctx - The storage context to use (local, session, custom, or in-memory).
|
|
501
|
-
* @returns The corresponding `Storage` object, or `null` if not available.
|
|
502
|
-
*/
|
|
503
|
-
#storage(ctx) {
|
|
504
|
-
if (this.#platformService.isPlatformBrowser) {
|
|
505
|
-
switch (ctx) {
|
|
506
|
-
case 'local':
|
|
507
|
-
return this.#localStorageRef;
|
|
508
|
-
case 'session':
|
|
509
|
-
return this.#sessionStorageRef;
|
|
510
|
-
case 'custom':
|
|
511
|
-
return this.#customStorageRef;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Fallback to in-memory storage when the platform is not a browser (e.g., SSR).
|
|
516
|
-
*/
|
|
517
|
-
return this.#inMemoryStorageRef;
|
|
518
|
-
}
|
|
519
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: StorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
520
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: StorageService }); }
|
|
521
|
-
}
|
|
522
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: StorageService, decorators: [{
|
|
523
|
-
type: Injectable
|
|
524
|
-
}] });
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Returns the set of dependency-injection providers
|
|
528
|
-
* required to setup storages in an application.
|
|
529
|
-
*
|
|
530
|
-
* @usageNotes
|
|
531
|
-
*
|
|
532
|
-
* This function sets up the essential storage services needed for
|
|
533
|
-
* working with `localStorage`, `sessionStorage`, and an in-memory storage solution.
|
|
534
|
-
* It includes providers for each type of storage, ensuring that the appropriate
|
|
535
|
-
* storage service is injected based on the platform or specific use case.
|
|
536
|
-
*
|
|
537
|
-
* The function is particularly useful in scenarios where the application may be
|
|
538
|
-
* running on the server-side (SSR). In such cases, instead of using `localStorage`
|
|
539
|
-
* and `sessionStorage`, which are only available in the browser, the `InMemoryStorageService`
|
|
540
|
-
* can be used as a fallback, ensuring that the application still functions correctly.
|
|
541
|
-
*
|
|
542
|
-
* ```typescript
|
|
543
|
-
* bootstrapApplication(RootComponent, {
|
|
544
|
-
* providers: [
|
|
545
|
-
* provideRtStorage()
|
|
546
|
-
* ]
|
|
547
|
-
* });
|
|
548
|
-
* ```
|
|
549
|
-
*
|
|
550
|
-
* @publicApi
|
|
551
|
-
*/
|
|
552
|
-
function provideRtStorage() {
|
|
553
|
-
return [
|
|
554
|
-
InMemoryStorageService,
|
|
555
|
-
{
|
|
556
|
-
provide: LOCAL_STORAGE,
|
|
557
|
-
useFactory: localStorageFactory,
|
|
558
|
-
},
|
|
559
|
-
{
|
|
560
|
-
provide: SESSION_STORAGE,
|
|
561
|
-
useFactory: sessionStorageFactory,
|
|
562
|
-
},
|
|
563
|
-
{
|
|
564
|
-
provide: IN_MEMORY_STORAGE,
|
|
565
|
-
useFactory: inMemoryStorageFactory,
|
|
566
|
-
},
|
|
567
|
-
StorageService,
|
|
568
|
-
];
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
class IDBStorageService {
|
|
572
|
-
#windowRef = inject(WINDOW);
|
|
573
|
-
#context;
|
|
574
|
-
constructor() {
|
|
575
|
-
this.#context = new Observable((observer) => {
|
|
576
|
-
if ('indexedDB' in this.#windowRef && 'open' in this.#windowRef.indexedDB) {
|
|
577
|
-
const openRequest = this.#windowRef.indexedDB.open('use-idb', 1);
|
|
578
|
-
openRequest.onerror = () => observer.error(openRequest.error);
|
|
579
|
-
openRequest.onsuccess = () => observer.next(openRequest.result);
|
|
580
|
-
openRequest.onupgradeneeded = () => openRequest.result.createObjectStore('idb');
|
|
581
|
-
}
|
|
582
|
-
else {
|
|
583
|
-
observer.error('IndexedDB not supported');
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
get(key) {
|
|
588
|
-
return new Observable((observer) => {
|
|
589
|
-
this.#context.subscribe((db) => {
|
|
590
|
-
const transaction = db.transaction('idb', 'readonly');
|
|
591
|
-
const store = transaction.objectStore('idb');
|
|
592
|
-
const request = store.get(key);
|
|
593
|
-
request.onsuccess = () => observer.next(request.result);
|
|
594
|
-
request.onerror = () => observer.error(request.error);
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
set(key, value) {
|
|
599
|
-
return new Observable((observer) => {
|
|
600
|
-
this.#context.subscribe((db) => {
|
|
601
|
-
const transaction = db.transaction('idb', 'readwrite');
|
|
602
|
-
const store = transaction.objectStore('idb');
|
|
603
|
-
const request = store.put(value, key);
|
|
604
|
-
request.onsuccess = () => observer.next();
|
|
605
|
-
request.onerror = () => observer.error(request.error);
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
remove(key) {
|
|
610
|
-
return new Observable((observer) => {
|
|
611
|
-
this.#context.subscribe((db) => {
|
|
612
|
-
const transaction = db.transaction('idb', 'readwrite');
|
|
613
|
-
const store = transaction.objectStore('idb');
|
|
614
|
-
const request = store.delete(key);
|
|
615
|
-
request.onsuccess = () => observer.next();
|
|
616
|
-
request.onerror = () => observer.error(request.error);
|
|
617
|
-
});
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: IDBStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
621
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: IDBStorageService }); }
|
|
622
|
-
}
|
|
623
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: IDBStorageService, decorators: [{
|
|
624
|
-
type: Injectable
|
|
625
|
-
}], ctorParameters: () => [] });
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
* Factory for creating `IDBStorageService`.
|
|
629
|
-
* Returns a new instance of IDBStorageService.
|
|
630
|
-
*
|
|
631
|
-
* @returns a new instance of IDBStorageService
|
|
632
|
-
*/
|
|
633
|
-
function iDBStorageFactory() {
|
|
634
|
-
return new IDBStorageService();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* Injection token for IDBStorageService.
|
|
639
|
-
*/
|
|
640
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
641
|
-
const IDB_STORAGE_SERVICE_TOKEN = new InjectionToken('IDB_STORAGE_SERVICE_TOKEN');
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* Returns the set of dependency-injection providers
|
|
645
|
-
* required to set up storages in an application.
|
|
646
|
-
*
|
|
647
|
-
* @usageNotes
|
|
648
|
-
*
|
|
649
|
-
* This function sets up the essential storage services needed for
|
|
650
|
-
* working with `idb storage` solution.
|
|
651
|
-
* It includes providers for each type of storage, ensuring that the appropriate
|
|
652
|
-
* storage service is injected based on the platform or specific use case.
|
|
653
|
-
*
|
|
654
|
-
* ```typescript
|
|
655
|
-
* bootstrapApplication(RootComponent, {
|
|
656
|
-
* providers: [
|
|
657
|
-
* provideRtIDBStorage()
|
|
658
|
-
* ]
|
|
659
|
-
* });
|
|
660
|
-
* ```
|
|
661
|
-
*
|
|
662
|
-
* @publicApi
|
|
663
|
-
*/
|
|
664
|
-
function provideRtIDBStorage() {
|
|
665
|
-
return [
|
|
666
|
-
{
|
|
667
|
-
provide: IDB_STORAGE_SERVICE_TOKEN,
|
|
668
|
-
useFactory: iDBStorageFactory,
|
|
669
|
-
},
|
|
670
|
-
IDBStorageService,
|
|
671
|
-
];
|
|
672
|
-
}
|
|
673
|
-
|
|
674
50
|
class RtuiModalComponent {
|
|
675
51
|
constructor() {
|
|
676
52
|
this.data = inject(MAT_DIALOG_DATA);
|
|
@@ -5139,11 +4515,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImpor
|
|
|
5139
4515
|
/**
|
|
5140
4516
|
* Public API Surface of rt-tools
|
|
5141
4517
|
*/
|
|
5142
|
-
//
|
|
4518
|
+
// ui-kit
|
|
5143
4519
|
|
|
5144
4520
|
/**
|
|
5145
4521
|
* Generated bundle index. Do not edit.
|
|
5146
4522
|
*/
|
|
5147
4523
|
|
|
5148
|
-
export { ASIDE_BUTTONS_ENUM, ASIDE_REF, AsideRef, BUTTON_APPEARANCE, BUTTON_COLOR, BUTTON_SIZE,
|
|
4524
|
+
export { ASIDE_BUTTONS_ENUM, ASIDE_REF, AsideRef, BUTTON_APPEARANCE, BUTTON_COLOR, BUTTON_SIZE, DEFAULT_PAGE_MODEL, DEFAULT_PAGE_SIZE, INFO_BADGE_SIZE_ENUM, INFO_BADGE_TYPE_ENUM, MODAL_WINDOW_SIZE_ENUM, RTUI_TABLE_COMPONENT_TOKEN, RTUI_TABLE_STOP_ROW_CLICK_ATTRIBUTE, RtActionBarService, RtAsideService, RtDynamicListSelectorsDirective, RtModalService, RtPopoverDirective, RtSnackBarService, RtTableConfigService, RtTableSelectorsDirective, RtuiActionBarComponent, RtuiActionBarContainerComponent, RtuiAsideContainerComponent, RtuiAsideContainerHeaderDirective, RtuiButtonComponent, RtuiClearButtonComponent, RtuiCustomTableCellsDirective, RtuiDynamicInputAdditionalControlDirective, RtuiDynamicInputComponent, RtuiDynamicListComponent, RtuiDynamicListCustomTableCellsDirective, RtuiDynamicListRowActionsDirective, RtuiDynamicListRowAdditionalActionsDirective, RtuiDynamicListToolbarActionsDirective, RtuiDynamicListToolbarSelectorsDirective, RtuiDynamicSelectorAdditionalControlDirective, RtuiDynamicSelectorComponent, RtuiDynamicSelectorItemAdditionalControlDirective, RtuiDynamicSelectorListActionsComponent, RtuiDynamicSelectorPlaceholderComponent, RtuiDynamicSelectorSelectedListComponent, RtuiFileUploadComponent, RtuiHeaderCenterDirective, RtuiHeaderComponent, RtuiHeaderLeftDirective, RtuiHeaderRightDirective, RtuiImageUploadComponent, RtuiInfoBadgeComponent, RtuiModalComponent, RtuiMultiButtonComponent, RtuiMultiSelectorPopupComponent, RtuiPaginationComponent, RtuiRoundIconButtonComponent, RtuiScrollableContainerComponent, RtuiScrollableContainerContentDirective, RtuiScrollableContainerFooterDirective, RtuiScrollableContainerHeaderDirective, RtuiSideMenuComponent, RtuiSideMenuFooterDirective, RtuiSideMenuHeaderDirective, RtuiSnackBarComponent, RtuiSpinnerComponent, RtuiStopTableRowClickDirective, RtuiTableAdditionalRowActionsDirective, RtuiTableComponent, RtuiTableRowActionsDirective, RtuiTableRowClickDirective, RtuiToggleComponent, RtuiToolbarCenterDirective, RtuiToolbarComponent, RtuiToolbarLeftDirective, RtuiToolbarRightDirective, TABLE_COLUMN_FILTER_TYPES_ENUM, TABLE_COLUMN_TYPES_ENUM, TEXT_CELL_COLOR_ENUM, TOGGLE_SIZE_TYPE_ENUM, darkenHexColor, ddServices, getColorBasedOnBackground, progressDecreaseAnimation, progressIncreaseAnimation, provideRtUi };
|
|
5149
4525
|
//# sourceMappingURL=rt-tools-ui-kit.mjs.map
|