@electra-ui/helpers 0.0.0-stage → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/fesm2022/electra-ui-helpers.mjs +1847 -0
- package/fesm2022/electra-ui-helpers.mjs.map +1 -0
- package/package.json +29 -4
- package/types/electra-ui-helpers.d.ts +614 -0
|
@@ -0,0 +1,1847 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, ChangeDetectorRef, Pipe, QueryList, NgZone, Renderer2, Injectable, ElementRef, Input, Directive, EventEmitter, booleanAttribute, Output, HostBinding, InjectionToken, Injector, afterEveryRender } from '@angular/core';
|
|
3
|
+
import { eAssert, eDefaultProp } from '@electra-ui/core';
|
|
4
|
+
import { DomSanitizer } from '@angular/platform-browser';
|
|
5
|
+
import { defer, isObservable, BehaviorSubject, shareReplay, merge as merge$1, Observable, asyncScheduler, race, concat, timer, mapTo, of, EMPTY, Subject, startWith, takeUntil, ReplaySubject } from 'rxjs';
|
|
6
|
+
import * as operators from 'rxjs/operators';
|
|
7
|
+
import { filter, throttleTime, map, observeOn, switchMap, debounceTime, tap, first, shareReplay as shareReplay$1, delay } from 'rxjs/operators';
|
|
8
|
+
import { v4 } from 'uuid';
|
|
9
|
+
import { __decorate, __metadata } from 'tslib';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Этот пайп позволяет снизить кол-во вызовов функций которые вызываются из шаблона,
|
|
13
|
+
* когда входящие аргументы не меняются.
|
|
14
|
+
*
|
|
15
|
+
* @button <ng-container *ngIf="firstArg | eCallFunc : someMethod">SomeValue</ng-container>
|
|
16
|
+
* @button <ng-container>{{firstArg | eCallFunc : someMethod : secondArg}}</ng-container>
|
|
17
|
+
*/
|
|
18
|
+
class ElectraCallFuncPipe {
|
|
19
|
+
// with Ivy you can inject EmbeddedViewRef directly
|
|
20
|
+
constructor() {
|
|
21
|
+
this.context = inject(ChangeDetectorRef).context;
|
|
22
|
+
}
|
|
23
|
+
transform(param, fn, ...params) {
|
|
24
|
+
const invoke = fn;
|
|
25
|
+
return invoke.apply(this.context, [param, ...params]);
|
|
26
|
+
}
|
|
27
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraCallFuncPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
28
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: ElectraCallFuncPipe, isStandalone: true, name: "eCallFunc" }); }
|
|
29
|
+
}
|
|
30
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraCallFuncPipe, decorators: [{
|
|
31
|
+
type: Pipe,
|
|
32
|
+
args: [{ name: 'eCallFunc', standalone: true }]
|
|
33
|
+
}], ctorParameters: () => [] });
|
|
34
|
+
|
|
35
|
+
class ElectraPluckPipe {
|
|
36
|
+
transform(input, key, defaultValue = null) {
|
|
37
|
+
if (!input || typeof input !== 'object') {
|
|
38
|
+
eAssert.assert(false, 'ePluck in input instead of object or array, get ' + input);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (key == null) {
|
|
42
|
+
throw new Error('ePluck in key instead of valid key, get ' + key);
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(key)) {
|
|
45
|
+
let result = input;
|
|
46
|
+
for (const k of key) {
|
|
47
|
+
if (k === '__proto__' || k === 'constructor' || k === 'prototype') {
|
|
48
|
+
return defaultValue;
|
|
49
|
+
}
|
|
50
|
+
// nosemgrep: доступ только для чтения, опасные ключи отфильтрованы выше
|
|
51
|
+
result = result?.[k]; // nosemgrep
|
|
52
|
+
}
|
|
53
|
+
return result ?? defaultValue;
|
|
54
|
+
}
|
|
55
|
+
return input?.[key] ?? defaultValue;
|
|
56
|
+
}
|
|
57
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraPluckPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
58
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: ElectraPluckPipe, isStandalone: true, name: "ePluck" }); }
|
|
59
|
+
}
|
|
60
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraPluckPipe, decorators: [{
|
|
61
|
+
type: Pipe,
|
|
62
|
+
args: [{
|
|
63
|
+
name: 'ePluck',
|
|
64
|
+
standalone: true,
|
|
65
|
+
}]
|
|
66
|
+
}] });
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Этот пайп можно использовать для приведения типов переменных контекста ng-template,
|
|
70
|
+
* чтобы ввести хотя бы какую-то проверку типа шаблона для таких ссылок.
|
|
71
|
+
*
|
|
72
|
+
* @button <ng-template let-someArg><span *ngIf="someArg | eToType : typeName"></span></ng-template>
|
|
73
|
+
*/
|
|
74
|
+
class ElectraToTypePipe {
|
|
75
|
+
transform(value, _typeSource) {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraToTypePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
79
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: ElectraToTypePipe, isStandalone: true, name: "eToType" }); }
|
|
80
|
+
}
|
|
81
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraToTypePipe, decorators: [{
|
|
82
|
+
type: Pipe,
|
|
83
|
+
args: [{ name: 'eToType', standalone: true }]
|
|
84
|
+
}] });
|
|
85
|
+
|
|
86
|
+
class ElectraSanitizerPipe {
|
|
87
|
+
constructor() {
|
|
88
|
+
this.sanitizer = inject(DomSanitizer);
|
|
89
|
+
}
|
|
90
|
+
transform(value, method) {
|
|
91
|
+
return this.sanitizer[method](value);
|
|
92
|
+
}
|
|
93
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSanitizerPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
94
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: ElectraSanitizerPipe, isStandalone: true, name: "eSanitizer" }); }
|
|
95
|
+
}
|
|
96
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSanitizerPipe, decorators: [{
|
|
97
|
+
type: Pipe,
|
|
98
|
+
args: [{
|
|
99
|
+
name: 'eSanitizer',
|
|
100
|
+
standalone: true,
|
|
101
|
+
}]
|
|
102
|
+
}] });
|
|
103
|
+
|
|
104
|
+
class ElectraToObservablePipe {
|
|
105
|
+
transform(value, operators = []) {
|
|
106
|
+
if (typeof value?.then === 'function') {
|
|
107
|
+
value = defer(() => value);
|
|
108
|
+
}
|
|
109
|
+
if (!isObservable(value)) {
|
|
110
|
+
if (!this.subject$$ || this.lastOperators !== operators) {
|
|
111
|
+
this.subject$$ = new BehaviorSubject(value);
|
|
112
|
+
this.lastObservable$$ = this.addOperatorsToObservable(this.subject$$, (this.lastOperators = operators)).pipe(shareReplay(1));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.subject$$.next(value);
|
|
116
|
+
}
|
|
117
|
+
return this.lastObservable$$;
|
|
118
|
+
}
|
|
119
|
+
return this.addOperatorsToObservable(value, operators);
|
|
120
|
+
}
|
|
121
|
+
addOperatorsToObservable($, operators) {
|
|
122
|
+
const operatorsArray = (operators ?? [])
|
|
123
|
+
.map(operator => {
|
|
124
|
+
if (typeof operator === 'string')
|
|
125
|
+
return this.getOperatorFunction(operator);
|
|
126
|
+
if (Array.isArray(operator)) {
|
|
127
|
+
const [key, ...args] = operator;
|
|
128
|
+
return this.getOperatorFunctionByKey(key, args);
|
|
129
|
+
}
|
|
130
|
+
return operator;
|
|
131
|
+
})
|
|
132
|
+
.filter(Boolean);
|
|
133
|
+
return operators?.length ? $.pipe(...operatorsArray) : $;
|
|
134
|
+
}
|
|
135
|
+
getOperatorFunction(str) {
|
|
136
|
+
const result = this.parseFunctionString(str);
|
|
137
|
+
if (!result)
|
|
138
|
+
return null;
|
|
139
|
+
return this.getOperatorFunctionByKey(result.functionName, result?.args);
|
|
140
|
+
}
|
|
141
|
+
getOperatorFunctionByKey(key, args) {
|
|
142
|
+
const method = operators[key];
|
|
143
|
+
if (typeof method !== 'function')
|
|
144
|
+
return null;
|
|
145
|
+
return method(...args);
|
|
146
|
+
}
|
|
147
|
+
parseFunctionString(str) {
|
|
148
|
+
const regex = /^(\w+)\((.*)\)$/;
|
|
149
|
+
const match = str.match(regex);
|
|
150
|
+
if (!match) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const functionName = match[1];
|
|
154
|
+
const argsString = match[2].trim();
|
|
155
|
+
const args = argsString ? argsString.split(',').map(arg => JSON.parse(arg.trim())) : [];
|
|
156
|
+
return { functionName, args };
|
|
157
|
+
}
|
|
158
|
+
ngOnDestroy() {
|
|
159
|
+
this.subject$$?.complete();
|
|
160
|
+
this.subject$$?.unsubscribe();
|
|
161
|
+
}
|
|
162
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraToObservablePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
163
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: ElectraToObservablePipe, isStandalone: true, name: "eToObservable" }); }
|
|
164
|
+
}
|
|
165
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraToObservablePipe, decorators: [{
|
|
166
|
+
type: Pipe,
|
|
167
|
+
args: [{ name: 'eToObservable', standalone: true }]
|
|
168
|
+
}] });
|
|
169
|
+
|
|
170
|
+
function hideOverflowElements(parent, childItem, options = {}) {
|
|
171
|
+
const containerRect = parent.getBoundingClientRect();
|
|
172
|
+
const boxRect = childItem.getBoundingClientRect();
|
|
173
|
+
// Проверка на пересечение по вертикали и горизонтали
|
|
174
|
+
const isOverflowingVertically = boxRect.bottom + (options.reserveSpace?.y ?? 0) > containerRect.bottom;
|
|
175
|
+
const isOverflowingHorizontally = boxRect.right + (options.reserveSpace?.x ?? 0) > containerRect.right;
|
|
176
|
+
// Скрываем элемент, если он выходит за границы контейнера
|
|
177
|
+
if (isOverflowingVertically || isOverflowingHorizontally) {
|
|
178
|
+
if (childItem.style.display !== 'none')
|
|
179
|
+
childItem.style.display = 'none';
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// Восстанавливаем видимость элемента
|
|
183
|
+
if (childItem.style.display)
|
|
184
|
+
childItem.style.display = '';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function eHostDirective(directive, options) {
|
|
189
|
+
const inputs = options?.inputs && Object.entries(options.inputs).map(([oldName, newName]) => `${oldName}: ${newName}`);
|
|
190
|
+
const outputs = options?.outputs && Object.entries(options.outputs).map(([oldName, newName]) => `${oldName}: ${newName}`);
|
|
191
|
+
return {
|
|
192
|
+
directive,
|
|
193
|
+
inputs,
|
|
194
|
+
outputs,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* sort number, string, date by asc or desc
|
|
200
|
+
* */
|
|
201
|
+
function eSort(x, y, asc = true) {
|
|
202
|
+
const a = x instanceof Date ? Number(x) : x;
|
|
203
|
+
const b = y instanceof Date ? Number(y) : y;
|
|
204
|
+
let result = 0;
|
|
205
|
+
if (a === b) {
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
209
|
+
result = a.localeCompare(b);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
result = a > b ? 1 : -1;
|
|
213
|
+
}
|
|
214
|
+
if (!asc) {
|
|
215
|
+
if (result === -1)
|
|
216
|
+
result = 1;
|
|
217
|
+
else if (result === 1)
|
|
218
|
+
result = -1;
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
function eEmptyQueryList() {
|
|
223
|
+
return new QueryList();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
class Compare {
|
|
227
|
+
static isTruthy(value) {
|
|
228
|
+
return Boolean(value) === true;
|
|
229
|
+
}
|
|
230
|
+
static isFalsy(value) {
|
|
231
|
+
return Boolean(value) === false;
|
|
232
|
+
}
|
|
233
|
+
static isUndefined(value) {
|
|
234
|
+
return value === undefined;
|
|
235
|
+
}
|
|
236
|
+
static isNullish(value) {
|
|
237
|
+
return value == null;
|
|
238
|
+
}
|
|
239
|
+
static isNotNullish(value) {
|
|
240
|
+
return value != null;
|
|
241
|
+
}
|
|
242
|
+
static isNull(value) {
|
|
243
|
+
return value === null;
|
|
244
|
+
}
|
|
245
|
+
static isEqualDates(a, b) {
|
|
246
|
+
return a === b || a.getTime() === b.getTime();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Фильтрует значения, которые являются неправдивыми (falsy).
|
|
252
|
+
* @returns Оператор, который можно использовать с Observable.
|
|
253
|
+
*/
|
|
254
|
+
function filterFalsy() {
|
|
255
|
+
return filter(Compare.isFalsy);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Использует первый observable, который будет излучен в заданном промежутке времени.
|
|
259
|
+
* @param time - время в миллисекундах
|
|
260
|
+
* @param sources - массив источников Observable
|
|
261
|
+
* @returns Observable, который эмитирует первое значение из источников.
|
|
262
|
+
*/
|
|
263
|
+
function raceEmit(time, ...sources) {
|
|
264
|
+
return merge$1(...sources).pipe(throttleTime(time));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Создает Observable, который излучает изменения размера элемента.
|
|
268
|
+
* @param elements - массив элементов, для которых должны быть отслеживаны изменения размера.
|
|
269
|
+
* @returns Observable, который эмитирует массив событий изменения размера.
|
|
270
|
+
*/
|
|
271
|
+
function eElementResized$(...elements) {
|
|
272
|
+
return new Observable((subscriber) => {
|
|
273
|
+
const resizeObserver = new ResizeObserver((entries) => subscriber.next(entries));
|
|
274
|
+
elements.forEach(elem => resizeObserver.observe(elem));
|
|
275
|
+
return () => resizeObserver.disconnect();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Фильтрует значения, которые являются истинными (truthy).
|
|
280
|
+
* @returns Оператор, который можно использовать с Observable.
|
|
281
|
+
*/
|
|
282
|
+
function filterTruthy() {
|
|
283
|
+
return filter(Compare.isTruthy);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Фильтрует значения, которые не являются нулевыми или неопределенными.
|
|
287
|
+
* @returns Оператор, который можно использовать с Observable.
|
|
288
|
+
*/
|
|
289
|
+
function filterNotNullish() {
|
|
290
|
+
return filter(Compare.isNotNullish);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Фильтрует значения, которые являются нулевыми или неопределенными.
|
|
294
|
+
* @returns Оператор, который можно использовать с Observable.
|
|
295
|
+
*/
|
|
296
|
+
function filterNullish() {
|
|
297
|
+
return filter(Compare.isNullish);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Преобразует неопределенные значения в null.
|
|
301
|
+
* @returns Оператор, который можно использовать с Observable.
|
|
302
|
+
*/
|
|
303
|
+
function mapUndefinedToNull() {
|
|
304
|
+
return map((v) => (Compare.isUndefined(v) ? null : v));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Перемещает выполнение функции на указанное количество итераций в цикле событий.
|
|
308
|
+
* @param count - Количество итераций цикла событий для перемещения.
|
|
309
|
+
* @returns Оператор, который можно использовать с Observable для продолжения цепочки.
|
|
310
|
+
*/
|
|
311
|
+
function moveInEventLoopIteration(count) {
|
|
312
|
+
return (source) => {
|
|
313
|
+
if (!count)
|
|
314
|
+
return source;
|
|
315
|
+
source = source.pipe(observeOn(asyncScheduler, 0));
|
|
316
|
+
if (count > 1) {
|
|
317
|
+
source = source.pipe(moveInEventLoopIteration(count - 1));
|
|
318
|
+
}
|
|
319
|
+
return source;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function eRaceInEmit(inner, reloadTime) {
|
|
323
|
+
const repeat$ = new BehaviorSubject(void 0);
|
|
324
|
+
let result = repeat$.pipe(switchMap(() => {
|
|
325
|
+
return race(...inner);
|
|
326
|
+
}));
|
|
327
|
+
if (Compare.isNotNullish(reloadTime))
|
|
328
|
+
result = result.pipe(debounceTime(reloadTime));
|
|
329
|
+
return result.pipe(tap(() => repeat$.next()));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function eFromMutationObserver$(target, config) {
|
|
333
|
+
return new Observable(observer => {
|
|
334
|
+
const mutation = new MutationObserver(mutations => {
|
|
335
|
+
observer.next(mutations);
|
|
336
|
+
});
|
|
337
|
+
mutation.observe(target, config);
|
|
338
|
+
return () => {
|
|
339
|
+
mutation.disconnect();
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
class ElectraFormControlHelpers {
|
|
345
|
+
static getDisabled$(origin) {
|
|
346
|
+
return origin.statusChanges.pipe(map(() => this.getDisabled(origin)));
|
|
347
|
+
}
|
|
348
|
+
static getValidators$(origin) {
|
|
349
|
+
return origin.statusChanges.pipe(map(() => this.getValidators(origin)));
|
|
350
|
+
}
|
|
351
|
+
static getAsyncValidators$(origin) {
|
|
352
|
+
return origin.statusChanges.pipe(map(() => this.getAsyncValidators(origin)));
|
|
353
|
+
}
|
|
354
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- public API: consumers rely on the `any` default inference (e.g. Observable<boolean> fallback in doc-base getValueFromControl$)
|
|
355
|
+
static getValue$(origin) {
|
|
356
|
+
return origin.valueChanges.pipe(map(() => this.getValue(origin)));
|
|
357
|
+
}
|
|
358
|
+
static getDisabled(origin) {
|
|
359
|
+
return origin.disabled;
|
|
360
|
+
}
|
|
361
|
+
static isTouched(origin) {
|
|
362
|
+
return origin.touched;
|
|
363
|
+
}
|
|
364
|
+
static isDirty(origin) {
|
|
365
|
+
return origin.dirty;
|
|
366
|
+
}
|
|
367
|
+
static getValidators(origin) {
|
|
368
|
+
return origin?._rawValidators ?? null;
|
|
369
|
+
}
|
|
370
|
+
static getAsyncValidators(origin) {
|
|
371
|
+
return origin?._rawAsyncValidators ?? null;
|
|
372
|
+
}
|
|
373
|
+
static getValue(origin) {
|
|
374
|
+
return origin.value;
|
|
375
|
+
}
|
|
376
|
+
static syncStates(origin, bidirectional, ...others) {
|
|
377
|
+
const all = [origin, ...others];
|
|
378
|
+
return concat(timer(0).pipe(map(() => origin)), bidirectional
|
|
379
|
+
? merge$1(...all.map(control => control.statusChanges.pipe(mapTo(control))))
|
|
380
|
+
: origin.statusChanges.pipe(mapTo(origin))).pipe(map(origin => {
|
|
381
|
+
(bidirectional ? all : others).forEach(control => {
|
|
382
|
+
const disabled = this.getDisabled(origin);
|
|
383
|
+
if (disabled === control.disabled)
|
|
384
|
+
return;
|
|
385
|
+
if (disabled) {
|
|
386
|
+
control.disable();
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
control.enable();
|
|
390
|
+
}
|
|
391
|
+
this.syncControlVisualStates(origin, control);
|
|
392
|
+
});
|
|
393
|
+
return this.getDisabled(origin);
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
static syncValidators(origin, bidirectional, ...others) {
|
|
397
|
+
const all = [origin, ...others];
|
|
398
|
+
return concat(of(this.getValidators(origin)), bidirectional ? merge$1(...all.map(control => this.getValidators$(control))) : this.getValidators$(origin)).pipe(tap(validators => {
|
|
399
|
+
(bidirectional ? all : others).forEach(control => {
|
|
400
|
+
control.setValidators(validators);
|
|
401
|
+
});
|
|
402
|
+
}));
|
|
403
|
+
}
|
|
404
|
+
static syncAllValidators(origin, bidirectional, ...others) {
|
|
405
|
+
return merge$1(this.syncValidators(origin, bidirectional, ...others), this.syncAsyncValidators(origin, bidirectional, ...others));
|
|
406
|
+
}
|
|
407
|
+
static syncAsyncValidators(origin, bidirectional, ...others) {
|
|
408
|
+
const all = [origin, ...others];
|
|
409
|
+
return concat(of(this.getAsyncValidators(origin)), bidirectional
|
|
410
|
+
? merge$1(...all.map(control => this.getAsyncValidators$(control)))
|
|
411
|
+
: this.getAsyncValidators$(origin)).pipe(tap(asyncValidators => {
|
|
412
|
+
(bidirectional ? all : others).forEach(control => {
|
|
413
|
+
control.setAsyncValidators(asyncValidators);
|
|
414
|
+
});
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
static setValue(control, newValue, options) {
|
|
418
|
+
const currentValue = this.getValue(control);
|
|
419
|
+
if (currentValue === newValue)
|
|
420
|
+
return;
|
|
421
|
+
control.setValue(newValue, options);
|
|
422
|
+
}
|
|
423
|
+
static setDisabled(control, disabled, options) {
|
|
424
|
+
if (disabled === control.disabled)
|
|
425
|
+
return;
|
|
426
|
+
if (!disabled)
|
|
427
|
+
control.enable(options);
|
|
428
|
+
else
|
|
429
|
+
control.disable(options);
|
|
430
|
+
}
|
|
431
|
+
static syncControlVisualStates(control, other) {
|
|
432
|
+
if (control.pristine)
|
|
433
|
+
other.markAsPristine();
|
|
434
|
+
if (control.dirty)
|
|
435
|
+
other.markAsDirty();
|
|
436
|
+
if (control.touched)
|
|
437
|
+
other.markAsTouched();
|
|
438
|
+
if (control.untouched)
|
|
439
|
+
other.markAsUntouched();
|
|
440
|
+
if (control.pending)
|
|
441
|
+
other.markAsPending();
|
|
442
|
+
}
|
|
443
|
+
static syncValues(origin, fromOrigin, fromOthers, ...others) {
|
|
444
|
+
return merge$1(timer(0).pipe(first(), map(() => this.getValue(origin)), tap((valueFromOrigin) => {
|
|
445
|
+
const value = fromOrigin(valueFromOrigin);
|
|
446
|
+
others.forEach(control => {
|
|
447
|
+
this.setValue(control, value);
|
|
448
|
+
this.syncControlVisualStates(origin, control);
|
|
449
|
+
});
|
|
450
|
+
})), this.getValue$(origin).pipe(filter(() => Boolean(fromOrigin)), tap((valueFromOrigin) => {
|
|
451
|
+
const value = fromOrigin(valueFromOrigin);
|
|
452
|
+
others.forEach(control => {
|
|
453
|
+
this.setValue(control, value);
|
|
454
|
+
this.syncControlVisualStates(origin, control);
|
|
455
|
+
});
|
|
456
|
+
})), fromOthers
|
|
457
|
+
? merge$1(...others.map(control => this.getValue$(control))).pipe(filter(() => Boolean(fromOthers)), tap((valueFromOther) => {
|
|
458
|
+
const value = fromOthers(valueFromOther);
|
|
459
|
+
this.setValue(origin, value);
|
|
460
|
+
}))
|
|
461
|
+
: EMPTY).pipe(map(() => this.getValue(origin)));
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function ElectraLogExecution(options = {}) {
|
|
466
|
+
const { enabled = true, logArguments = true, logResult = true, logExecutionTime = true } = options;
|
|
467
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
468
|
+
return (target, propertyKey, descriptor) => {
|
|
469
|
+
const originalMethod = descriptor.value;
|
|
470
|
+
if (!enabled)
|
|
471
|
+
return descriptor;
|
|
472
|
+
if (descriptor.set) {
|
|
473
|
+
const originalSetter = descriptor.set;
|
|
474
|
+
descriptor.set = function (value) {
|
|
475
|
+
const className = target.constructor.name;
|
|
476
|
+
const propertyName = propertyKey;
|
|
477
|
+
const fullPropertyName = `${className}.${propertyName}`;
|
|
478
|
+
console.log(`Вызов сеттера: ${fullPropertyName}`);
|
|
479
|
+
if (logArguments) {
|
|
480
|
+
console.log('Аргумент:', value);
|
|
481
|
+
}
|
|
482
|
+
const startTime = performance.now();
|
|
483
|
+
originalSetter.call(this, value);
|
|
484
|
+
if (logExecutionTime) {
|
|
485
|
+
const endTime = performance.now();
|
|
486
|
+
console.log(`Время выполнения: ${endTime - startTime} мс`);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
else if (descriptor.value) {
|
|
491
|
+
descriptor.value = function (...args) {
|
|
492
|
+
const className = target.constructor.name;
|
|
493
|
+
const functionName = propertyKey || target.constructor.name;
|
|
494
|
+
const fullFunctionName = propertyKey ? `${className}.${functionName}` : functionName;
|
|
495
|
+
console.log('%s Вызов функции', fullFunctionName);
|
|
496
|
+
if (logArguments) {
|
|
497
|
+
console.log('%s Аргументы:', fullFunctionName, args);
|
|
498
|
+
}
|
|
499
|
+
const startTime = performance.now();
|
|
500
|
+
let result = originalMethod.apply(this, args);
|
|
501
|
+
if (result instanceof Promise) {
|
|
502
|
+
result = result.then(res => {
|
|
503
|
+
if (logResult) {
|
|
504
|
+
console.log('%s Результат:', fullFunctionName, res);
|
|
505
|
+
}
|
|
506
|
+
if (logExecutionTime) {
|
|
507
|
+
const endTime = performance.now();
|
|
508
|
+
console.log('%s Время выполнения: %s мс', fullFunctionName, endTime - startTime);
|
|
509
|
+
}
|
|
510
|
+
return res;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
else if (result instanceof Observable) {
|
|
514
|
+
result = result.pipe(tap(res => {
|
|
515
|
+
if (logResult) {
|
|
516
|
+
console.log('%s Результат:', fullFunctionName, res);
|
|
517
|
+
}
|
|
518
|
+
if (logExecutionTime) {
|
|
519
|
+
const endTime = performance.now();
|
|
520
|
+
console.log('%s Время выполнения: %s мс', fullFunctionName, endTime - startTime);
|
|
521
|
+
}
|
|
522
|
+
}));
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
if (logResult) {
|
|
526
|
+
console.log('%s Результат:', fullFunctionName, result);
|
|
527
|
+
}
|
|
528
|
+
if (logExecutionTime) {
|
|
529
|
+
const endTime = performance.now();
|
|
530
|
+
console.log('%s Время выполнения: %s мс', fullFunctionName, endTime - startTime);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return result;
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
return descriptor;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Coerce the target value to a boolean value. `null`, `undefined` and 'false' (string)
|
|
542
|
+
* will be coerced to `false`. Any other value will be coerced to `true`.
|
|
543
|
+
*
|
|
544
|
+
* If target property has accessors (getter/setter), it will delegate the coercion to the setter.
|
|
545
|
+
* If target property doesn't have accessors, it will create them.
|
|
546
|
+
*
|
|
547
|
+
* This is a decorator factory, it should be used as a decorator (`@CoerceBoolean()`) without
|
|
548
|
+
* executing it as a function in a class definition.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```
|
|
552
|
+
* class MyClass {
|
|
553
|
+
* @ElectraCoerceBoolean()
|
|
554
|
+
* myProp;
|
|
555
|
+
* }
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
function ElectraCoerceBoolean() {
|
|
559
|
+
return function (target, key, propertyDescriptor) {
|
|
560
|
+
// Choose the strategy based on whether accessors are defined for target property
|
|
561
|
+
// If accessors are defined, leverage them, otherwise create them
|
|
562
|
+
!!propertyDescriptor && !!propertyDescriptor.set
|
|
563
|
+
? coerceUsingAccessors(propertyDescriptor)
|
|
564
|
+
: coerceWithoutAccessors(target, key);
|
|
565
|
+
};
|
|
566
|
+
/**
|
|
567
|
+
* If accessors are defined in the property descriptor,
|
|
568
|
+
* we wrap the original setter in our custom setter that
|
|
569
|
+
* includes a condition for not allowing null, undefined
|
|
570
|
+
* or 'false' (string) values.
|
|
571
|
+
*/
|
|
572
|
+
function coerceUsingAccessors(propertyDescriptor) {
|
|
573
|
+
const original = propertyDescriptor.set;
|
|
574
|
+
propertyDescriptor.set = function (next) {
|
|
575
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
576
|
+
// @ts-ignore
|
|
577
|
+
original.apply(this, [coerceValue(next)]);
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* If no accessors are defined in the property descriptor,
|
|
582
|
+
* we define our own get and set accessors for the property.
|
|
583
|
+
*/
|
|
584
|
+
function coerceWithoutAccessors(target, key) {
|
|
585
|
+
const getter = function () {
|
|
586
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
587
|
+
// @ts-ignore
|
|
588
|
+
return this['__' + key];
|
|
589
|
+
};
|
|
590
|
+
const setter = function (next) {
|
|
591
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
592
|
+
// @ts-ignore
|
|
593
|
+
this['__' + key] = coerceValue(next);
|
|
594
|
+
};
|
|
595
|
+
Object.defineProperty(target, key, {
|
|
596
|
+
get: getter,
|
|
597
|
+
set: setter,
|
|
598
|
+
enumerable: true,
|
|
599
|
+
configurable: true,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Coerce the value to boolean according to the following rules:
|
|
604
|
+
* `null`, `undefined` and `'false'` (string) will be coerced to `false`.
|
|
605
|
+
* Any other value will be coerced to `true`.
|
|
606
|
+
*
|
|
607
|
+
* @param {any} next - The value to coerce.
|
|
608
|
+
* @returns {boolean} - The coerced value.
|
|
609
|
+
*/
|
|
610
|
+
function coerceValue(next) {
|
|
611
|
+
return next !== null && next !== undefined && `${next}` !== 'false';
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Функция eExecuteAfterFrames вызывает переданный коллбэк cb после заданного количества кадров frame, используя requestAnimationFrame.
|
|
617
|
+
* */
|
|
618
|
+
function eExecuteAfterFrames(cb, frames = ELECTRA_DEFAULT_FRAMES_NUMBER) {
|
|
619
|
+
if (frames <= 0) {
|
|
620
|
+
cb();
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
requestAnimationFrame(() => eExecuteAfterFrames(cb, frames - 1));
|
|
624
|
+
}
|
|
625
|
+
const ELECTRA_DEFAULT_FRAMES_NUMBER = 3;
|
|
626
|
+
|
|
627
|
+
function eGenerateId() {
|
|
628
|
+
return v4();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function eStyleGetVars(obj) {
|
|
632
|
+
return Object.entries(obj).reduce((base, [key, value]) => {
|
|
633
|
+
key = eStyleToSnake(key);
|
|
634
|
+
if (key.startsWith('--'))
|
|
635
|
+
key = key.replace(/^--/, '');
|
|
636
|
+
if (key.startsWith('e'))
|
|
637
|
+
key = key.replace(/^e-/, '');
|
|
638
|
+
key = `--e-${key}`;
|
|
639
|
+
base[key] = Compare.isNullish(value) ? '' : (value?.toString() ?? '');
|
|
640
|
+
return base;
|
|
641
|
+
}, {});
|
|
642
|
+
}
|
|
643
|
+
function eStyleToSnake(str) {
|
|
644
|
+
return str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function eFormatNumber(num, precision, decimal = 'never') {
|
|
648
|
+
if (precision === Infinity) {
|
|
649
|
+
switch (decimal) {
|
|
650
|
+
case 'not-zero':
|
|
651
|
+
return num.toString().replace(/\.0+$/, '');
|
|
652
|
+
case 'never':
|
|
653
|
+
return Math.round(num).toString();
|
|
654
|
+
default:
|
|
655
|
+
return num.toString();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
switch (decimal) {
|
|
659
|
+
case 'not-zero':
|
|
660
|
+
return (Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision)).toString();
|
|
661
|
+
case 'always':
|
|
662
|
+
return num.toFixed(precision);
|
|
663
|
+
case 'never':
|
|
664
|
+
default:
|
|
665
|
+
return Math.round(num).toString();
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- динамический deep-equal:
|
|
670
|
+
диспетчер по тегу Object.prototype.toString; narrowing по строковому тегу
|
|
671
|
+
в TS невыразим без редизайна, поэтому внутренние any остаются осознанно. */
|
|
672
|
+
function isEqual(a, b) {
|
|
673
|
+
const toString = Object.prototype.toString, getPrototypeOf = Object.getPrototypeOf, getOwnProperties = Object.getOwnPropertySymbols
|
|
674
|
+
? (obj) => Object.keys(obj).concat(Object.getOwnPropertySymbols(obj))
|
|
675
|
+
: Object.keys;
|
|
676
|
+
const refs = [];
|
|
677
|
+
function checkEquality(a, b, refs) {
|
|
678
|
+
let aElements, bElements, element;
|
|
679
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
680
|
+
// @ts-ignore
|
|
681
|
+
const aType = toString.call(a),
|
|
682
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
683
|
+
// @ts-ignore
|
|
684
|
+
bType = toString.call(b);
|
|
685
|
+
if (a === b)
|
|
686
|
+
return true;
|
|
687
|
+
if (a == null || b == null)
|
|
688
|
+
return false;
|
|
689
|
+
if (refs.indexOf(a) > -1 && refs.indexOf(b) > -1)
|
|
690
|
+
return true;
|
|
691
|
+
refs.push(a, b);
|
|
692
|
+
if (aType !== bType)
|
|
693
|
+
return false;
|
|
694
|
+
aElements = getOwnProperties(a);
|
|
695
|
+
bElements = getOwnProperties(b);
|
|
696
|
+
if (aElements.length !== bElements.length ||
|
|
697
|
+
aElements.some(key => !checkEquality(a[key], b[key], refs))) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
701
|
+
// @ts-ignore
|
|
702
|
+
switch (aType.slice(8, -1)) {
|
|
703
|
+
case 'Symbol':
|
|
704
|
+
return a.valueOf() === b.valueOf();
|
|
705
|
+
case 'Date':
|
|
706
|
+
case 'Number':
|
|
707
|
+
return +a === +b || (+a !== +a && +b !== +b);
|
|
708
|
+
case 'RegExp':
|
|
709
|
+
case 'Function':
|
|
710
|
+
case 'String':
|
|
711
|
+
case 'Boolean':
|
|
712
|
+
return '' + a === '' + b;
|
|
713
|
+
case 'Set':
|
|
714
|
+
case 'Map': {
|
|
715
|
+
aElements = Array.from(a.entries());
|
|
716
|
+
bElements = Array.from(b.entries());
|
|
717
|
+
for (let i = 0; i < aElements.length; i++) {
|
|
718
|
+
if (!checkEquality(aElements[i], bElements[i], refs)) {
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
725
|
+
// @ts-expect-error
|
|
726
|
+
// eslint-disable-next-line no-fallthrough
|
|
727
|
+
case 'ArrayBuffer':
|
|
728
|
+
a = new Uint8Array(a);
|
|
729
|
+
b = new Uint8Array(b);
|
|
730
|
+
// falls through to be handled as an Array
|
|
731
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
732
|
+
// @ts-expect-error
|
|
733
|
+
// eslint-disable-next-line no-fallthrough
|
|
734
|
+
case 'DataView':
|
|
735
|
+
a = new Uint8Array(a.buffer);
|
|
736
|
+
b = new Uint8Array(b.buffer);
|
|
737
|
+
// FALLS THROUGH to 2
|
|
738
|
+
case 'Float32Array':
|
|
739
|
+
case 'Float64Array':
|
|
740
|
+
case 'Int8Array':
|
|
741
|
+
case 'Int16Array':
|
|
742
|
+
case 'Int32Array':
|
|
743
|
+
case 'Uint8Array':
|
|
744
|
+
case 'Uint16Array':
|
|
745
|
+
case 'Uint32Array':
|
|
746
|
+
case 'Uint8ClampedArray':
|
|
747
|
+
case 'Array':
|
|
748
|
+
if (a.length !== b.length)
|
|
749
|
+
return false;
|
|
750
|
+
for (element = 0; element < a.length; element++) {
|
|
751
|
+
if (!(element in a) && !(element in b))
|
|
752
|
+
continue;
|
|
753
|
+
if (!(element in a) !== !(element in b) || !checkEquality(a[element], b[element], refs))
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
return true;
|
|
757
|
+
case 'Object':
|
|
758
|
+
return checkEquality(getPrototypeOf(a), getPrototypeOf(b), refs);
|
|
759
|
+
default:
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return checkEquality(a, b, refs);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Deep-merge plain-объектов с мутацией первого аргумента; later-аргументы
|
|
768
|
+
* переопределяют по ключу. Всё, что не plain-объект, заменяется целиком:
|
|
769
|
+
* массивы — копией (replace, не по-индексу), Date/Map/Set/RegExp — клоном
|
|
770
|
+
* с содержимым, функции и инстансы классов — по ссылке. Конфликт типов
|
|
771
|
+
* решается в пользу источника (source-wins) без броска.
|
|
772
|
+
*/
|
|
773
|
+
function merge(object, ...sources) {
|
|
774
|
+
const target = object;
|
|
775
|
+
for (const source of sources) {
|
|
776
|
+
for (const [key, val] of Object.entries(source)) {
|
|
777
|
+
if (key === `__proto__`) {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
target[key] = mergeValue(target[key], val);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return object;
|
|
784
|
+
}
|
|
785
|
+
function mergeValue(target, val) {
|
|
786
|
+
if (val === null || typeof val !== `object`) {
|
|
787
|
+
return val;
|
|
788
|
+
}
|
|
789
|
+
if (Array.isArray(val)) {
|
|
790
|
+
return [...val];
|
|
791
|
+
}
|
|
792
|
+
if (val instanceof Date) {
|
|
793
|
+
return new Date(val.getTime());
|
|
794
|
+
}
|
|
795
|
+
if (val instanceof Map) {
|
|
796
|
+
return new Map(val);
|
|
797
|
+
}
|
|
798
|
+
if (val instanceof Set) {
|
|
799
|
+
return new Set(val);
|
|
800
|
+
}
|
|
801
|
+
if (val instanceof RegExp) {
|
|
802
|
+
return structuredClone(val);
|
|
803
|
+
}
|
|
804
|
+
if (!isPlainObject(val)) {
|
|
805
|
+
return val;
|
|
806
|
+
}
|
|
807
|
+
if (isPlainObject(target)) {
|
|
808
|
+
return merge(target, val);
|
|
809
|
+
}
|
|
810
|
+
return merge({}, val);
|
|
811
|
+
}
|
|
812
|
+
function isPlainObject(v) {
|
|
813
|
+
if (typeof v !== `object` || v === null) {
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
const proto = Object.getPrototypeOf(v);
|
|
817
|
+
return proto === Object.prototype || proto === null;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function orderBy(collection, iteratees, orders = []) {
|
|
821
|
+
// Clone the collection to avoid mutating the input
|
|
822
|
+
const sortedCollection = [...collection];
|
|
823
|
+
// Sort the collection based on multiple criteria
|
|
824
|
+
return sortedCollection.sort((a, b) => {
|
|
825
|
+
for (let i = 0; i < iteratees.length; i++) {
|
|
826
|
+
const iteratee = iteratees[i];
|
|
827
|
+
const order = orders[i] || 'asc';
|
|
828
|
+
const valueA = typeof iteratee === 'function' ? iteratee(a) : a[iteratee];
|
|
829
|
+
const valueB = typeof iteratee === 'function' ? iteratee(b) : b[iteratee];
|
|
830
|
+
if (valueA !== valueB) {
|
|
831
|
+
const sortOrder = order === 'asc' ? 1 : -1;
|
|
832
|
+
return valueA > valueB ? sortOrder : -sortOrder;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
// If all iteratees consider the elements equal, maintain their order.
|
|
836
|
+
return 0;
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function difference(array, ...values) {
|
|
841
|
+
if (!array || !Array.isArray(array) || array.length === 0) {
|
|
842
|
+
return [];
|
|
843
|
+
}
|
|
844
|
+
if (!values || values.length === 0) {
|
|
845
|
+
return [...array];
|
|
846
|
+
}
|
|
847
|
+
// Объединяем все массивы значений в один для упрощения исключения.
|
|
848
|
+
const excludeValues = [].concat(...values);
|
|
849
|
+
// Фильтруем основной массив, исключая элементы, присутствующие в excludeValues.
|
|
850
|
+
// Используется SameValueZero сравнение через includes.
|
|
851
|
+
const result = array.filter(item => !excludeValues.includes(item));
|
|
852
|
+
return result;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function eHasChanges(changes, names, ignoreFirstChange = false) {
|
|
856
|
+
if (!changes)
|
|
857
|
+
return false;
|
|
858
|
+
const nameArray = Array.isArray(names) ? names : [names];
|
|
859
|
+
return nameArray.some(name => {
|
|
860
|
+
return (name in changes &&
|
|
861
|
+
!(ignoreFirstChange && changes[name].isFirstChange()) &&
|
|
862
|
+
changes[name].previousValue !== changes[name].currentValue);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
function eInvertObject(obj) {
|
|
867
|
+
const invertedObj = {};
|
|
868
|
+
for (const key in obj) {
|
|
869
|
+
if (obj[key]) {
|
|
870
|
+
const value = obj[key];
|
|
871
|
+
if (value == null || (value && typeof value === 'object') || typeof value === 'function')
|
|
872
|
+
throw new Error('Passed to eInvertObject values that has not primitive value');
|
|
873
|
+
invertedObj[value] = key;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
return invertedObj;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function eCreateResizeObservable(element) {
|
|
880
|
+
return new Observable(observer => {
|
|
881
|
+
// Создаем новый ResizeObserver
|
|
882
|
+
const resizeObserver = new ResizeObserver(entries => {
|
|
883
|
+
// Передаем изменения в observable
|
|
884
|
+
observer.next(entries);
|
|
885
|
+
});
|
|
886
|
+
// Начинаем наблюдение за изменениями размеров указанного элемента
|
|
887
|
+
resizeObserver.observe(element);
|
|
888
|
+
// Возвращаем функцию очистки, которая будет вызвана при завершении подписки
|
|
889
|
+
return () => {
|
|
890
|
+
resizeObserver.disconnect();
|
|
891
|
+
};
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function watchObject(obj, subject) {
|
|
896
|
+
const createHandler = (_target) => {
|
|
897
|
+
return {
|
|
898
|
+
set(target, property, value) {
|
|
899
|
+
// Если новое значение - объект, оборачиваем его в прокси
|
|
900
|
+
if (typeof value === 'object' && value !== null) {
|
|
901
|
+
target[property] = new Proxy(value, createHandler(value));
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
target[property] = value;
|
|
905
|
+
}
|
|
906
|
+
// subject.next(structuredClone(target));
|
|
907
|
+
subject.next(proxy);
|
|
908
|
+
return true;
|
|
909
|
+
},
|
|
910
|
+
deleteProperty(target, property) {
|
|
911
|
+
delete target[property];
|
|
912
|
+
// subject.next(structuredClone(target));
|
|
913
|
+
subject.next(proxy);
|
|
914
|
+
return true;
|
|
915
|
+
},
|
|
916
|
+
};
|
|
917
|
+
};
|
|
918
|
+
// Рекурсивно оборачиваем все вложенные объекты в прокси
|
|
919
|
+
const recursiveProxy = (obj) => {
|
|
920
|
+
Object.keys(obj).forEach(key => {
|
|
921
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
922
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
923
|
+
// @ts-ignore
|
|
924
|
+
obj[key] = new Proxy(obj[key], createHandler(obj[key]));
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
return new Proxy(obj, createHandler(obj));
|
|
928
|
+
};
|
|
929
|
+
const proxy = recursiveProxy(obj);
|
|
930
|
+
return proxy;
|
|
931
|
+
}
|
|
932
|
+
class ElectraProxyObject extends BehaviorSubject {
|
|
933
|
+
constructor(obj) {
|
|
934
|
+
super(null);
|
|
935
|
+
const watched = watchObject(obj, this);
|
|
936
|
+
this.next(watched);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
class ElectraSetSubject extends Set {
|
|
941
|
+
constructor() {
|
|
942
|
+
super(...arguments);
|
|
943
|
+
this.subject$$ = new Subject();
|
|
944
|
+
this.changes$ = this.subject$$.pipe(map(() => this));
|
|
945
|
+
this.$ = concat(of(this), this.changes$);
|
|
946
|
+
}
|
|
947
|
+
add(value) {
|
|
948
|
+
super.add(value);
|
|
949
|
+
return this;
|
|
950
|
+
}
|
|
951
|
+
delete(key) {
|
|
952
|
+
return super.delete(key);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
class ElectraMapSubject extends Map {
|
|
957
|
+
constructor() {
|
|
958
|
+
super(...arguments);
|
|
959
|
+
this.$$ = new BehaviorSubject(void 0);
|
|
960
|
+
this.value = this.$$.pipe(map(() => this));
|
|
961
|
+
}
|
|
962
|
+
set(key, value) {
|
|
963
|
+
this.$$.next();
|
|
964
|
+
return super.set(key, value);
|
|
965
|
+
}
|
|
966
|
+
delete(key) {
|
|
967
|
+
this.$$.next();
|
|
968
|
+
return super.delete(key);
|
|
969
|
+
}
|
|
970
|
+
clear() {
|
|
971
|
+
this.$$.next();
|
|
972
|
+
return super.clear();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
class ElectraMapWithChildrenSubject {
|
|
977
|
+
constructor(identityMatcher, getChildren) {
|
|
978
|
+
this.identityMatcher = identityMatcher;
|
|
979
|
+
this.getChildren = getChildren;
|
|
980
|
+
this.store = new ElectraMapSubject();
|
|
981
|
+
}
|
|
982
|
+
get(item) {
|
|
983
|
+
return this.getEntity(item)?.[1] ?? null;
|
|
984
|
+
}
|
|
985
|
+
getEntity(item) {
|
|
986
|
+
return [...this.store.entries()].find(([, i]) => this.identityMatcher(i.item, item)) ?? null;
|
|
987
|
+
}
|
|
988
|
+
add(item, { parentItem, }) {
|
|
989
|
+
if (this.has(item))
|
|
990
|
+
return false;
|
|
991
|
+
const parent = parentItem && this.get(parentItem);
|
|
992
|
+
if (parentItem && !parent)
|
|
993
|
+
return false;
|
|
994
|
+
const storedItem = {
|
|
995
|
+
item,
|
|
996
|
+
level: parent ? parent?.level + 1 : 0,
|
|
997
|
+
parent: parent ?? null,
|
|
998
|
+
};
|
|
999
|
+
this.store.set(eGenerateId(), storedItem);
|
|
1000
|
+
this.getChildren(item)?.forEach(child => this.add(child, {
|
|
1001
|
+
parentItem: item,
|
|
1002
|
+
}));
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
remove(item) {
|
|
1006
|
+
const storedItem = this.getEntity(item);
|
|
1007
|
+
if (!storedItem)
|
|
1008
|
+
return false;
|
|
1009
|
+
this.store.delete(storedItem[0]);
|
|
1010
|
+
return true;
|
|
1011
|
+
}
|
|
1012
|
+
has(item) {
|
|
1013
|
+
return ([...this.store.values()].findIndex(storedItem => this.identityMatcher(storedItem.item, item)) !== -1);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
class ElectraOverflowService {
|
|
1018
|
+
constructor() {
|
|
1019
|
+
this.set = new ElectraSetSubject();
|
|
1020
|
+
this.zone = inject(NgZone);
|
|
1021
|
+
this.renderer = inject(Renderer2);
|
|
1022
|
+
this.destroyPrevious$$ = new Subject();
|
|
1023
|
+
this.updatedItems$$ = new Subject();
|
|
1024
|
+
this.changes$$ = new BehaviorSubject(void null);
|
|
1025
|
+
this.mutation$$ = new Subject();
|
|
1026
|
+
this.active = true;
|
|
1027
|
+
this.items$ = this.updatedItems$$.pipe(startWith(), map(() => [...this.set]), shareReplay$1(1));
|
|
1028
|
+
this.hiddenItems$ = this.items$.pipe(map(arr => arr.filter(i => i.html.style.display === 'none')));
|
|
1029
|
+
}
|
|
1030
|
+
disable() {
|
|
1031
|
+
this.active = false;
|
|
1032
|
+
this.destroyPrevious();
|
|
1033
|
+
this.set.forEach(childItem => {
|
|
1034
|
+
this.renderer.setStyle(childItem.html, 'display', '');
|
|
1035
|
+
this.renderer.setStyle(childItem.html, 'visibility', '');
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
destroyPrevious() {
|
|
1039
|
+
this.destroyPrevious$$.next();
|
|
1040
|
+
this.observer?.disconnect();
|
|
1041
|
+
}
|
|
1042
|
+
enable() {
|
|
1043
|
+
this.active = true;
|
|
1044
|
+
this.init(this.host);
|
|
1045
|
+
}
|
|
1046
|
+
init(host, options = {}) {
|
|
1047
|
+
this.reserveSpace = options.reserveSpace;
|
|
1048
|
+
this.destroyPrevious();
|
|
1049
|
+
if (!host)
|
|
1050
|
+
return;
|
|
1051
|
+
this.host = host;
|
|
1052
|
+
this.observer = new MutationObserver(() => this.mutation$$.next());
|
|
1053
|
+
this.observer.observe(host, { childList: true, subtree: true });
|
|
1054
|
+
let block = false;
|
|
1055
|
+
if (this.host)
|
|
1056
|
+
this.zone.runOutsideAngular(() => {
|
|
1057
|
+
merge$1(this.set.changes$.pipe(switchMap(() => [...this.set.values()].map(childItem => eCreateResizeObservable(childItem.html)))), this.mutation$$.pipe(filter(() => !block),
|
|
1058
|
+
// block all other mutations invokes while we finish
|
|
1059
|
+
tap(() => (block = true))), eCreateResizeObservable(host), this.changes$$)
|
|
1060
|
+
.pipe(filter(() => this.active), switchMap(() => concat(...[...this.set].map((childItem, idx) => of({ childItem, idx }))).pipe(tap(({ childItem, idx }) => {
|
|
1061
|
+
if (this.host && this.active)
|
|
1062
|
+
this.updateHost(this.host, childItem.html, idx);
|
|
1063
|
+
}))),
|
|
1064
|
+
// unblock next iteration
|
|
1065
|
+
delay(0), tap(() => (block = false)), takeUntil(this.destroyPrevious$$))
|
|
1066
|
+
.subscribe();
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
ngOnDestroy() {
|
|
1070
|
+
this.observer?.disconnect();
|
|
1071
|
+
}
|
|
1072
|
+
add(childItem) {
|
|
1073
|
+
if (this.active)
|
|
1074
|
+
this.unVisible(childItem.html);
|
|
1075
|
+
this.set.add(childItem);
|
|
1076
|
+
this.changes$$.next();
|
|
1077
|
+
}
|
|
1078
|
+
delete(childItem) {
|
|
1079
|
+
this.set.delete(childItem);
|
|
1080
|
+
this.changes$$.next();
|
|
1081
|
+
}
|
|
1082
|
+
unVisible(childItem) {
|
|
1083
|
+
this.renderer.setStyle(childItem, 'visibility', 'hidden');
|
|
1084
|
+
}
|
|
1085
|
+
visible(childItem) {
|
|
1086
|
+
this.renderer.setStyle(childItem, 'visibility', 'visible');
|
|
1087
|
+
}
|
|
1088
|
+
show(childItem) {
|
|
1089
|
+
childItem.style.removeProperty('display');
|
|
1090
|
+
}
|
|
1091
|
+
updateHost(host, childItem, idx) {
|
|
1092
|
+
this.unVisible(childItem);
|
|
1093
|
+
childItem.style.order = idx.toString();
|
|
1094
|
+
this.show(childItem);
|
|
1095
|
+
hideOverflowElements(host, childItem, {
|
|
1096
|
+
reserveSpace: this.reserveSpace,
|
|
1097
|
+
});
|
|
1098
|
+
this.visible(childItem);
|
|
1099
|
+
this.updatedItems$$.next();
|
|
1100
|
+
}
|
|
1101
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1102
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowService }); }
|
|
1103
|
+
}
|
|
1104
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowService, decorators: [{
|
|
1105
|
+
type: Injectable
|
|
1106
|
+
}] });
|
|
1107
|
+
|
|
1108
|
+
class ElectraOverflowHostDirective {
|
|
1109
|
+
constructor() {
|
|
1110
|
+
this.active = true;
|
|
1111
|
+
this.overflowService = inject(ElectraOverflowService);
|
|
1112
|
+
this.hiddenElements$ = this.overflowService.hiddenItems$;
|
|
1113
|
+
this.element = inject(ElementRef);
|
|
1114
|
+
}
|
|
1115
|
+
get calculatedHost() {
|
|
1116
|
+
return this.host ?? this.element.nativeElement;
|
|
1117
|
+
}
|
|
1118
|
+
ngOnInit() {
|
|
1119
|
+
this.init();
|
|
1120
|
+
}
|
|
1121
|
+
ngOnChanges(changes) {
|
|
1122
|
+
if (this.active) {
|
|
1123
|
+
if (changes['host'] || changes['reserveSpace'])
|
|
1124
|
+
this.init();
|
|
1125
|
+
if (changes['active'])
|
|
1126
|
+
this.overflowService.enable();
|
|
1127
|
+
}
|
|
1128
|
+
else
|
|
1129
|
+
this.overflowService.disable();
|
|
1130
|
+
}
|
|
1131
|
+
init() {
|
|
1132
|
+
this.overflowService.init(this.calculatedHost, {
|
|
1133
|
+
reserveSpace: this.reserveSpace,
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowHostDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1137
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraOverflowHostDirective, isStandalone: true, selector: "[eOverflowHost]", inputs: { host: "host", active: "active", reserveSpace: "reserveSpace" }, providers: [ElectraOverflowService], exportAs: ["eOverflowHost"], usesOnChanges: true, ngImport: i0 }); }
|
|
1138
|
+
}
|
|
1139
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowHostDirective, decorators: [{
|
|
1140
|
+
type: Directive,
|
|
1141
|
+
args: [{
|
|
1142
|
+
selector: '[eOverflowHost]',
|
|
1143
|
+
exportAs: 'eOverflowHost',
|
|
1144
|
+
standalone: true,
|
|
1145
|
+
providers: [ElectraOverflowService],
|
|
1146
|
+
}]
|
|
1147
|
+
}], propDecorators: { host: [{
|
|
1148
|
+
type: Input
|
|
1149
|
+
}], active: [{
|
|
1150
|
+
type: Input
|
|
1151
|
+
}], reserveSpace: [{
|
|
1152
|
+
type: Input
|
|
1153
|
+
}] } });
|
|
1154
|
+
|
|
1155
|
+
class ElectraOverflowItemDirective {
|
|
1156
|
+
get hidden() {
|
|
1157
|
+
return this.hidden_;
|
|
1158
|
+
}
|
|
1159
|
+
constructor() {
|
|
1160
|
+
this.elementRef = inject((ElementRef));
|
|
1161
|
+
this.overflowService = inject(ElectraOverflowService);
|
|
1162
|
+
this.html = this.elementRef.nativeElement;
|
|
1163
|
+
this.hidden_ = false;
|
|
1164
|
+
this.overflowService.add(this);
|
|
1165
|
+
}
|
|
1166
|
+
ngOnDestroy() {
|
|
1167
|
+
this.overflowService.delete(this);
|
|
1168
|
+
}
|
|
1169
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowItemDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1170
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraOverflowItemDirective, isStandalone: true, selector: "[eOverflowItem]", exportAs: ["eOverflowItem"], ngImport: i0 }); }
|
|
1171
|
+
}
|
|
1172
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraOverflowItemDirective, decorators: [{
|
|
1173
|
+
type: Directive,
|
|
1174
|
+
args: [{
|
|
1175
|
+
selector: '[eOverflowItem]',
|
|
1176
|
+
exportAs: 'eOverflowItem',
|
|
1177
|
+
standalone: true,
|
|
1178
|
+
}]
|
|
1179
|
+
}], ctorParameters: () => [] });
|
|
1180
|
+
|
|
1181
|
+
class ElectraStringifyDirective {
|
|
1182
|
+
constructor() {
|
|
1183
|
+
this.stringify = i => i?.toString() ?? '';
|
|
1184
|
+
}
|
|
1185
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraStringifyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1186
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraStringifyDirective, isStandalone: true, selector: "[eStringify]", inputs: { stringify: "stringify" }, ngImport: i0 }); }
|
|
1187
|
+
}
|
|
1188
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraStringifyDirective, decorators: [{
|
|
1189
|
+
type: Directive,
|
|
1190
|
+
args: [{
|
|
1191
|
+
selector: '[eStringify]',
|
|
1192
|
+
standalone: true,
|
|
1193
|
+
}]
|
|
1194
|
+
}], propDecorators: { stringify: [{
|
|
1195
|
+
type: Input
|
|
1196
|
+
}] } });
|
|
1197
|
+
|
|
1198
|
+
class ElectraIdentityMatcherDirective {
|
|
1199
|
+
constructor() {
|
|
1200
|
+
this.identityMatcher = (a, b) => a === b;
|
|
1201
|
+
}
|
|
1202
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraIdentityMatcherDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1203
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraIdentityMatcherDirective, isStandalone: true, selector: "[eIdentityMatcher]", inputs: { identityMatcher: "identityMatcher" }, ngImport: i0 }); }
|
|
1204
|
+
}
|
|
1205
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraIdentityMatcherDirective, decorators: [{
|
|
1206
|
+
type: Directive,
|
|
1207
|
+
args: [{
|
|
1208
|
+
standalone: true,
|
|
1209
|
+
selector: '[eIdentityMatcher]',
|
|
1210
|
+
}]
|
|
1211
|
+
}], propDecorators: { identityMatcher: [{
|
|
1212
|
+
type: Input
|
|
1213
|
+
}] } });
|
|
1214
|
+
|
|
1215
|
+
class ElectraDisabledDirective {
|
|
1216
|
+
constructor() {
|
|
1217
|
+
this._disabled = false;
|
|
1218
|
+
this.disabledChange = new EventEmitter();
|
|
1219
|
+
}
|
|
1220
|
+
get disabled() {
|
|
1221
|
+
return this._disabled;
|
|
1222
|
+
}
|
|
1223
|
+
set disabled(value) {
|
|
1224
|
+
this._disabled = booleanAttribute(value);
|
|
1225
|
+
this.disabledChange.emit(this._disabled);
|
|
1226
|
+
}
|
|
1227
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraDisabledDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1228
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraDisabledDirective, isStandalone: true, selector: "[eDisabled]", inputs: { disabled: "disabled" }, outputs: { disabledChange: "disabledChange" }, host: { properties: { "attr.disabled": "this.disabled" } }, ngImport: i0 }); }
|
|
1229
|
+
}
|
|
1230
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraDisabledDirective, decorators: [{
|
|
1231
|
+
type: Directive,
|
|
1232
|
+
args: [{
|
|
1233
|
+
selector: '[eDisabled]',
|
|
1234
|
+
standalone: true,
|
|
1235
|
+
}]
|
|
1236
|
+
}], propDecorators: { disabled: [{
|
|
1237
|
+
type: Input
|
|
1238
|
+
}, {
|
|
1239
|
+
type: HostBinding,
|
|
1240
|
+
args: ['attr.disabled']
|
|
1241
|
+
}], disabledChange: [{
|
|
1242
|
+
type: Output
|
|
1243
|
+
}] } });
|
|
1244
|
+
|
|
1245
|
+
function eDisabledHostDirective(options) {
|
|
1246
|
+
return eHostDirective(ElectraDisabledDirective, options);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
const ELECTRA_DEFAULT_SIZE = new InjectionToken('' + 'default size for size derective');
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* наш ли это
|
|
1253
|
+
* выкидавать error
|
|
1254
|
+
* передавать размер потомку
|
|
1255
|
+
* */
|
|
1256
|
+
class ElectraSizeDirective {
|
|
1257
|
+
constructor() {
|
|
1258
|
+
this.defaultSize = inject(ELECTRA_DEFAULT_SIZE, {
|
|
1259
|
+
self: true,
|
|
1260
|
+
optional: false,
|
|
1261
|
+
});
|
|
1262
|
+
this.size = this.defaultSize;
|
|
1263
|
+
}
|
|
1264
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSizeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1265
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraSizeDirective, isStandalone: true, selector: "[eSize]", inputs: { size: "size" }, host: { properties: { "attr.data-size": "this.size" } }, ngImport: i0 }); }
|
|
1266
|
+
}
|
|
1267
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSizeDirective, decorators: [{
|
|
1268
|
+
type: Directive,
|
|
1269
|
+
args: [{
|
|
1270
|
+
selector: '[eSize]',
|
|
1271
|
+
standalone: true,
|
|
1272
|
+
}]
|
|
1273
|
+
}], propDecorators: { size: [{
|
|
1274
|
+
type: Input
|
|
1275
|
+
}, {
|
|
1276
|
+
type: HostBinding,
|
|
1277
|
+
args: ['attr.data-size']
|
|
1278
|
+
}] } });
|
|
1279
|
+
|
|
1280
|
+
function eSetDefaultSize(size) {
|
|
1281
|
+
return {
|
|
1282
|
+
provide: ELECTRA_DEFAULT_SIZE,
|
|
1283
|
+
useValue: size,
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
class ElectraElementRefDirective {
|
|
1288
|
+
constructor() {
|
|
1289
|
+
this.ref = inject(ElementRef);
|
|
1290
|
+
}
|
|
1291
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraElementRefDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1292
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraElementRefDirective, isStandalone: true, selector: "[eElementRef]", exportAs: ["eElementRef"], ngImport: i0 }); }
|
|
1293
|
+
}
|
|
1294
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraElementRefDirective, decorators: [{
|
|
1295
|
+
type: Directive,
|
|
1296
|
+
args: [{
|
|
1297
|
+
selector: '[eElementRef]',
|
|
1298
|
+
standalone: true,
|
|
1299
|
+
exportAs: 'eElementRef',
|
|
1300
|
+
}]
|
|
1301
|
+
}] });
|
|
1302
|
+
|
|
1303
|
+
class ElectraHtmlRefDirective {
|
|
1304
|
+
get ref() {
|
|
1305
|
+
return inject(ElectraElementRefDirective).ref.nativeElement;
|
|
1306
|
+
}
|
|
1307
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraHtmlRefDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1308
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraHtmlRefDirective, isStandalone: true, selector: "[eHtmlRef]", exportAs: ["eHtmlRef"], hostDirectives: [{ directive: ElectraElementRefDirective }], ngImport: i0 }); }
|
|
1309
|
+
}
|
|
1310
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraHtmlRefDirective, decorators: [{
|
|
1311
|
+
type: Directive,
|
|
1312
|
+
args: [{
|
|
1313
|
+
selector: '[eHtmlRef]',
|
|
1314
|
+
standalone: true,
|
|
1315
|
+
exportAs: 'eHtmlRef',
|
|
1316
|
+
hostDirectives: [ElectraElementRefDirective],
|
|
1317
|
+
}]
|
|
1318
|
+
}] });
|
|
1319
|
+
|
|
1320
|
+
const ELECTRA_SELECTED_INDEX_ITEMS = new InjectionToken('items for correct selected index');
|
|
1321
|
+
const ELECTRA_SELECTED_INDEX_INITIAL = new InjectionToken('initial selected index');
|
|
1322
|
+
const ELECTRA_INDEX_SELECT_FN = new InjectionToken('func to select by index');
|
|
1323
|
+
const ELECTRA_ALL_INDEXES_READY = new InjectionToken('all indexes ready');
|
|
1324
|
+
|
|
1325
|
+
/**
|
|
1326
|
+
* Observable abstraction over ngOnDestroy for use with takeUntil
|
|
1327
|
+
*/
|
|
1328
|
+
class ElectraDestroyService extends ReplaySubject {
|
|
1329
|
+
constructor() {
|
|
1330
|
+
super(1);
|
|
1331
|
+
this.cb = new Set();
|
|
1332
|
+
}
|
|
1333
|
+
ngOnDestroy() {
|
|
1334
|
+
this.next();
|
|
1335
|
+
this.complete();
|
|
1336
|
+
this.cb.forEach((cb) => cb());
|
|
1337
|
+
this.cb.clear();
|
|
1338
|
+
}
|
|
1339
|
+
addCallback(cb) {
|
|
1340
|
+
this.cb.add(cb);
|
|
1341
|
+
}
|
|
1342
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraDestroyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1343
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraDestroyService }); }
|
|
1344
|
+
}
|
|
1345
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraDestroyService, decorators: [{
|
|
1346
|
+
type: Injectable
|
|
1347
|
+
}], ctorParameters: () => [] });
|
|
1348
|
+
|
|
1349
|
+
class ElectraSyncParentDirective {
|
|
1350
|
+
constructor() {
|
|
1351
|
+
this.sync$$ = new Subject();
|
|
1352
|
+
this.sync$ = this.sync$$.asObservable();
|
|
1353
|
+
this.destroy$ = inject(ElectraDestroyService);
|
|
1354
|
+
this.cdRef = inject(ChangeDetectorRef, {
|
|
1355
|
+
host: true,
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
ngOnInit() {
|
|
1359
|
+
this.sync$$
|
|
1360
|
+
.pipe(debounceTime(0), tap(() => {
|
|
1361
|
+
this.detectChanges();
|
|
1362
|
+
}), takeUntil(this.destroy$))
|
|
1363
|
+
.subscribe();
|
|
1364
|
+
}
|
|
1365
|
+
detectChanges() {
|
|
1366
|
+
this.cdRef.detectChanges();
|
|
1367
|
+
}
|
|
1368
|
+
markForCheck() {
|
|
1369
|
+
this.cdRef.markForCheck();
|
|
1370
|
+
}
|
|
1371
|
+
sync() {
|
|
1372
|
+
this.sync$$.next();
|
|
1373
|
+
}
|
|
1374
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSyncParentDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1375
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraSyncParentDirective, isStandalone: true, selector: "[eSyncParent]", providers: [ElectraDestroyService], ngImport: i0 }); }
|
|
1376
|
+
}
|
|
1377
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSyncParentDirective, decorators: [{
|
|
1378
|
+
type: Directive,
|
|
1379
|
+
args: [{
|
|
1380
|
+
selector: '[eSyncParent]',
|
|
1381
|
+
standalone: true,
|
|
1382
|
+
providers: [ElectraDestroyService],
|
|
1383
|
+
}]
|
|
1384
|
+
}] });
|
|
1385
|
+
|
|
1386
|
+
class ElectraSyncChildDirective {
|
|
1387
|
+
constructor() {
|
|
1388
|
+
this.cdRef = inject(ChangeDetectorRef, {
|
|
1389
|
+
self: true,
|
|
1390
|
+
});
|
|
1391
|
+
this.destroy$ = inject(ElectraDestroyService);
|
|
1392
|
+
this.syncParentDirective = inject(ElectraSyncParentDirective);
|
|
1393
|
+
this.set = new Set([this.cdRef]);
|
|
1394
|
+
}
|
|
1395
|
+
ngAfterViewInit() {
|
|
1396
|
+
// for dynamic add element to parent
|
|
1397
|
+
this.syncParentDirective.sync$
|
|
1398
|
+
.pipe(tap(() => {
|
|
1399
|
+
this.set.forEach(cdRef => cdRef.markForCheck());
|
|
1400
|
+
}), debounceTime(0), tap(() => {
|
|
1401
|
+
this.set.forEach(cdRef => cdRef.detectChanges());
|
|
1402
|
+
}), takeUntil(this.destroy$))
|
|
1403
|
+
.subscribe();
|
|
1404
|
+
}
|
|
1405
|
+
addCdRef(cdRef) {
|
|
1406
|
+
this.set.add(cdRef);
|
|
1407
|
+
}
|
|
1408
|
+
deleteCdRef(cdRef) {
|
|
1409
|
+
this.set.delete(cdRef);
|
|
1410
|
+
}
|
|
1411
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSyncChildDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1412
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraSyncChildDirective, isStandalone: true, selector: "[eSyncChild]", providers: [ElectraDestroyService], ngImport: i0 }); }
|
|
1413
|
+
}
|
|
1414
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSyncChildDirective, decorators: [{
|
|
1415
|
+
type: Directive,
|
|
1416
|
+
args: [{
|
|
1417
|
+
selector: '[eSyncChild]',
|
|
1418
|
+
standalone: true,
|
|
1419
|
+
providers: [ElectraDestroyService],
|
|
1420
|
+
}]
|
|
1421
|
+
}] });
|
|
1422
|
+
|
|
1423
|
+
class ElectraSyncOnChange {
|
|
1424
|
+
constructor() {
|
|
1425
|
+
this.syncParentDirective = inject(ElectraSyncParentDirective);
|
|
1426
|
+
}
|
|
1427
|
+
ngOnChanges() {
|
|
1428
|
+
this.syncParentDirective.sync();
|
|
1429
|
+
}
|
|
1430
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSyncOnChange, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1431
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraSyncOnChange, isStandalone: true, usesOnChanges: true, ngImport: i0 }); }
|
|
1432
|
+
}
|
|
1433
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSyncOnChange, decorators: [{
|
|
1434
|
+
type: Directive
|
|
1435
|
+
}] });
|
|
1436
|
+
|
|
1437
|
+
class ElectraStoreByIndexDirective {
|
|
1438
|
+
constructor() {
|
|
1439
|
+
this.map = new Map();
|
|
1440
|
+
this.changes$$ = new Subject();
|
|
1441
|
+
this.changes$ = this.changes$$.asObservable();
|
|
1442
|
+
}
|
|
1443
|
+
delete(idx) {
|
|
1444
|
+
this.map.delete(idx);
|
|
1445
|
+
this.changes$$.next();
|
|
1446
|
+
}
|
|
1447
|
+
entries() {
|
|
1448
|
+
return this.map.entries();
|
|
1449
|
+
}
|
|
1450
|
+
get(idx) {
|
|
1451
|
+
return this.map.get(idx);
|
|
1452
|
+
}
|
|
1453
|
+
set(idx, item) {
|
|
1454
|
+
this.map.set(idx, item);
|
|
1455
|
+
this.changes$$.next();
|
|
1456
|
+
}
|
|
1457
|
+
ngOnDestroy() {
|
|
1458
|
+
this.map.clear();
|
|
1459
|
+
}
|
|
1460
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraStoreByIndexDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1461
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraStoreByIndexDirective, isStandalone: true, selector: "[eStoreByIndex]", providers: [], ngImport: i0 }); }
|
|
1462
|
+
}
|
|
1463
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraStoreByIndexDirective, decorators: [{
|
|
1464
|
+
type: Directive,
|
|
1465
|
+
args: [{
|
|
1466
|
+
selector: '[eStoreByIndex]',
|
|
1467
|
+
standalone: true,
|
|
1468
|
+
providers: [], // Регистрируем сервис на уровне директивы
|
|
1469
|
+
}]
|
|
1470
|
+
}] });
|
|
1471
|
+
|
|
1472
|
+
class ElectraMutationObserverService {
|
|
1473
|
+
constructor() {
|
|
1474
|
+
this.observers = new Map();
|
|
1475
|
+
this.observersSubjects = new Map();
|
|
1476
|
+
}
|
|
1477
|
+
get$(element) {
|
|
1478
|
+
return this.observersSubjects.get(element)?.asObservable() ?? EMPTY;
|
|
1479
|
+
}
|
|
1480
|
+
observe(element, callback, config = { childList: true, subtree: true }) {
|
|
1481
|
+
if (this.observers.has(element)) {
|
|
1482
|
+
console.warn(`MutationObserver already exists for element.`);
|
|
1483
|
+
return this;
|
|
1484
|
+
}
|
|
1485
|
+
const subject = new Subject();
|
|
1486
|
+
this.observersSubjects.set(element, subject);
|
|
1487
|
+
const observer = new MutationObserver((mutations, observer) => {
|
|
1488
|
+
callback(mutations, observer);
|
|
1489
|
+
subject.next({ mutations, observer });
|
|
1490
|
+
});
|
|
1491
|
+
observer.observe(element, config);
|
|
1492
|
+
this.observers.set(element, observer);
|
|
1493
|
+
return this;
|
|
1494
|
+
}
|
|
1495
|
+
disconnect(element) {
|
|
1496
|
+
const observer = this.observers.get(element);
|
|
1497
|
+
if (observer) {
|
|
1498
|
+
observer.disconnect();
|
|
1499
|
+
this.cleanupObserver(element);
|
|
1500
|
+
}
|
|
1501
|
+
else {
|
|
1502
|
+
console.warn(`No MutationObserver found for element.`);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
disconnectAll() {
|
|
1506
|
+
this.observers.forEach((observer, element) => {
|
|
1507
|
+
observer.disconnect();
|
|
1508
|
+
this.cleanupObserver(element);
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
cleanupObserver(element) {
|
|
1512
|
+
this.observers.delete(element);
|
|
1513
|
+
const subject = this.observersSubjects.get(element);
|
|
1514
|
+
if (subject) {
|
|
1515
|
+
subject.complete();
|
|
1516
|
+
this.observersSubjects.delete(element);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
ngOnDestroy() {
|
|
1520
|
+
this.disconnectAll();
|
|
1521
|
+
}
|
|
1522
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraMutationObserverService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1523
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraMutationObserverService }); }
|
|
1524
|
+
}
|
|
1525
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraMutationObserverService, decorators: [{
|
|
1526
|
+
type: Injectable
|
|
1527
|
+
}] });
|
|
1528
|
+
|
|
1529
|
+
class ElectraCurrentIndexDirective {
|
|
1530
|
+
constructor() {
|
|
1531
|
+
this.el = inject(ElementRef);
|
|
1532
|
+
this.mutationObserverService = inject(ElectraMutationObserverService);
|
|
1533
|
+
this.indexSubject = new BehaviorSubject(-1);
|
|
1534
|
+
this.lengthSubject = new BehaviorSubject(0);
|
|
1535
|
+
this.lastIndexSubject = new BehaviorSubject(-1);
|
|
1536
|
+
this.cdRef = inject(ChangeDetectorRef);
|
|
1537
|
+
this.index$ = this.indexSubject.asObservable();
|
|
1538
|
+
this.lastIndex$ = this.lastIndexSubject.asObservable();
|
|
1539
|
+
this.length$ = this.lengthSubject.asObservable();
|
|
1540
|
+
}
|
|
1541
|
+
get index() {
|
|
1542
|
+
return this.indexSubject.value;
|
|
1543
|
+
}
|
|
1544
|
+
get lastIndex() {
|
|
1545
|
+
return this.lastIndexSubject.value;
|
|
1546
|
+
}
|
|
1547
|
+
get length() {
|
|
1548
|
+
return this.lastIndexSubject.value;
|
|
1549
|
+
}
|
|
1550
|
+
get isFirst() {
|
|
1551
|
+
return this.index === 0;
|
|
1552
|
+
}
|
|
1553
|
+
get isLast() {
|
|
1554
|
+
return this.index === this.lastIndex;
|
|
1555
|
+
}
|
|
1556
|
+
ngOnInit() {
|
|
1557
|
+
this.updateIndexes();
|
|
1558
|
+
// Подписываемся на изменения в DOM через ElectraMutationObserverService
|
|
1559
|
+
this.mutationObserverService.observe(this.el.nativeElement.parentNode, () => this.updateIndexes());
|
|
1560
|
+
}
|
|
1561
|
+
ngOnDestroy() {
|
|
1562
|
+
this.mutationObserverService.disconnectAll();
|
|
1563
|
+
}
|
|
1564
|
+
updateIndexes() {
|
|
1565
|
+
const parent = this.el.nativeElement.parentNode;
|
|
1566
|
+
const index = Array.prototype.indexOf.call(parent.children, this.el.nativeElement);
|
|
1567
|
+
const lastIndex = parent.children.length - 1;
|
|
1568
|
+
this.indexSubject.next(index);
|
|
1569
|
+
this.lastIndexSubject.next(lastIndex);
|
|
1570
|
+
this.lengthSubject.next(parent.children.length);
|
|
1571
|
+
this.cdRef.markForCheck();
|
|
1572
|
+
}
|
|
1573
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraCurrentIndexDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1574
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraCurrentIndexDirective, isStandalone: true, selector: "[eCurrentIndex]", providers: [ElectraMutationObserverService], ngImport: i0 }); }
|
|
1575
|
+
}
|
|
1576
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraCurrentIndexDirective, decorators: [{
|
|
1577
|
+
type: Directive,
|
|
1578
|
+
args: [{
|
|
1579
|
+
selector: '[eCurrentIndex]',
|
|
1580
|
+
standalone: true,
|
|
1581
|
+
providers: [ElectraMutationObserverService], // Регистрируем сервис на уровне директивы
|
|
1582
|
+
}]
|
|
1583
|
+
}] });
|
|
1584
|
+
|
|
1585
|
+
const ELECTRA_STORE_ITEM = new InjectionToken('get item for store');
|
|
1586
|
+
|
|
1587
|
+
class ElectraAddToStoreDirective {
|
|
1588
|
+
constructor() {
|
|
1589
|
+
this.store = inject(ElectraStoreByIndexDirective);
|
|
1590
|
+
this.currentIndexDirective = inject(ElectraCurrentIndexDirective);
|
|
1591
|
+
this.injector = inject(Injector);
|
|
1592
|
+
}
|
|
1593
|
+
ngAfterViewInit() {
|
|
1594
|
+
afterEveryRender(() => {
|
|
1595
|
+
this.updateIndexIfChange();
|
|
1596
|
+
}, {
|
|
1597
|
+
injector: this.injector,
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
ngOnDestroy() {
|
|
1601
|
+
if (Compare.isNotNullish(this.previousIndex))
|
|
1602
|
+
this.store.delete(this.previousIndex);
|
|
1603
|
+
}
|
|
1604
|
+
updateIndexIfChange() {
|
|
1605
|
+
// block when not change > return false
|
|
1606
|
+
if (this.previousIndex === this.currentIndexDirective.index)
|
|
1607
|
+
return false;
|
|
1608
|
+
// remove previous index item
|
|
1609
|
+
if (Compare.isNotNullish(this.previousIndex))
|
|
1610
|
+
this.store.delete(this.previousIndex);
|
|
1611
|
+
// get item
|
|
1612
|
+
const item = this.injector.get(ELECTRA_STORE_ITEM);
|
|
1613
|
+
if (!item) {
|
|
1614
|
+
throw new Error('Can not get item with token ELECTRA_STORE_ITEM');
|
|
1615
|
+
}
|
|
1616
|
+
// save new item
|
|
1617
|
+
this.store.set(this.currentIndexDirective.index, item);
|
|
1618
|
+
// update previous index
|
|
1619
|
+
this.previousIndex = this.currentIndexDirective.index;
|
|
1620
|
+
return true;
|
|
1621
|
+
}
|
|
1622
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraAddToStoreDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1623
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraAddToStoreDirective, isStandalone: true, selector: "[eIndexStorage]", ngImport: i0 }); }
|
|
1624
|
+
}
|
|
1625
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraAddToStoreDirective, decorators: [{
|
|
1626
|
+
type: Directive,
|
|
1627
|
+
args: [{
|
|
1628
|
+
selector: '[eIndexStorage]',
|
|
1629
|
+
standalone: true,
|
|
1630
|
+
}]
|
|
1631
|
+
}] });
|
|
1632
|
+
|
|
1633
|
+
class ElectraSelectedIndexDirective {
|
|
1634
|
+
constructor() {
|
|
1635
|
+
this.initial_index = inject(ELECTRA_SELECTED_INDEX_INITIAL, {
|
|
1636
|
+
host: true,
|
|
1637
|
+
optional: true,
|
|
1638
|
+
}) ?? 0;
|
|
1639
|
+
this.destroy$ = inject(ElectraDestroyService);
|
|
1640
|
+
this.allIndexesReady$ = inject(ELECTRA_ALL_INDEXES_READY, {
|
|
1641
|
+
host: true,
|
|
1642
|
+
optional: true,
|
|
1643
|
+
});
|
|
1644
|
+
this.selectAfterViewInit$ = new ReplaySubject();
|
|
1645
|
+
this.store = inject(ElectraStoreByIndexDirective, {
|
|
1646
|
+
host: true,
|
|
1647
|
+
optional: true,
|
|
1648
|
+
});
|
|
1649
|
+
this.selectedIndex_ = this.initial_index;
|
|
1650
|
+
this.selectedIndexChange = new EventEmitter();
|
|
1651
|
+
this.selector = inject(ELECTRA_INDEX_SELECT_FN);
|
|
1652
|
+
this.syncParentDirective = inject(ElectraSyncParentDirective, {
|
|
1653
|
+
host: true,
|
|
1654
|
+
optional: true,
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
get selectedIndex() {
|
|
1658
|
+
return this.selectedIndex_;
|
|
1659
|
+
}
|
|
1660
|
+
set selectedIndex(idx) {
|
|
1661
|
+
this.selectedIndex_ = idx;
|
|
1662
|
+
this.selectAfterViewInit(idx);
|
|
1663
|
+
}
|
|
1664
|
+
ngAfterViewInit() {
|
|
1665
|
+
this.initSelectInvoker();
|
|
1666
|
+
this.initIfWeHasStoreUpdaterOnChangesItems();
|
|
1667
|
+
}
|
|
1668
|
+
selectAfterViewInit(idx) {
|
|
1669
|
+
this.selectAfterViewInit$.next(idx);
|
|
1670
|
+
}
|
|
1671
|
+
select(idx) {
|
|
1672
|
+
return this.selector(idx);
|
|
1673
|
+
}
|
|
1674
|
+
setIndex(idx) {
|
|
1675
|
+
this.selectedIndexChange.emit((this.selectedIndex_ = idx));
|
|
1676
|
+
this.syncParentDirective?.sync();
|
|
1677
|
+
}
|
|
1678
|
+
initSelectInvoker() {
|
|
1679
|
+
// after load all indexes or after timer for safe update index
|
|
1680
|
+
const root$ = (this.allIndexesReady$ ?? timer(50));
|
|
1681
|
+
root$
|
|
1682
|
+
.pipe(debounceTime(0), switchMap(() => this.selectAfterViewInit$), tap(idx => this.select(idx)), takeUntil(this.destroy$))
|
|
1683
|
+
.subscribe();
|
|
1684
|
+
}
|
|
1685
|
+
initIfWeHasStoreUpdaterOnChangesItems() {
|
|
1686
|
+
this.store?.changes$
|
|
1687
|
+
.pipe(debounceTime(0), tap(() => {
|
|
1688
|
+
// -1 — сентинел «выбрать нечего» (все пункты disabled или значение
|
|
1689
|
+
// вне диапазона): повторные select(-1) на каждое изменение store
|
|
1690
|
+
// лишь спамят консоль, ничего не выбирая
|
|
1691
|
+
if (this.selectedIndex_ >= 0) {
|
|
1692
|
+
this.select(this.selectedIndex_);
|
|
1693
|
+
}
|
|
1694
|
+
}), takeUntil(this.destroy$))
|
|
1695
|
+
.subscribe();
|
|
1696
|
+
}
|
|
1697
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSelectedIndexDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1698
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraSelectedIndexDirective, isStandalone: true, selector: "[eSelectedIndex]", inputs: { selectedIndex: "selectedIndex" }, outputs: { selectedIndexChange: "selectedIndexChange" }, providers: [ElectraDestroyService], ngImport: i0 }); }
|
|
1699
|
+
}
|
|
1700
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraSelectedIndexDirective, decorators: [{
|
|
1701
|
+
type: Directive,
|
|
1702
|
+
args: [{
|
|
1703
|
+
selector: '[eSelectedIndex]',
|
|
1704
|
+
standalone: true,
|
|
1705
|
+
providers: [ElectraDestroyService],
|
|
1706
|
+
}]
|
|
1707
|
+
}], propDecorators: { selectedIndex: [{
|
|
1708
|
+
type: Input
|
|
1709
|
+
}], selectedIndexChange: [{
|
|
1710
|
+
type: Output
|
|
1711
|
+
}] } });
|
|
1712
|
+
|
|
1713
|
+
const ELECTRA_APPEARANCE_DEFAULT_VALUE = new InjectionToken('appearance token');
|
|
1714
|
+
|
|
1715
|
+
class ElectraAppearanceDirective {
|
|
1716
|
+
constructor() {
|
|
1717
|
+
this.default_value = inject(ELECTRA_APPEARANCE_DEFAULT_VALUE, {
|
|
1718
|
+
optional: true,
|
|
1719
|
+
});
|
|
1720
|
+
this.appearance = this.default_value ?? 'primary';
|
|
1721
|
+
}
|
|
1722
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraAppearanceDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1723
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraAppearanceDirective, isStandalone: true, selector: "[eAppearance]", inputs: { appearance: "appearance" }, host: { properties: { "attr.data-appearance": "this.appearance" } }, providers: [ElectraDestroyService], ngImport: i0 }); }
|
|
1724
|
+
}
|
|
1725
|
+
__decorate([
|
|
1726
|
+
eDefaultProp(),
|
|
1727
|
+
__metadata("design:type", String)
|
|
1728
|
+
], ElectraAppearanceDirective.prototype, "appearance", void 0);
|
|
1729
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraAppearanceDirective, decorators: [{
|
|
1730
|
+
type: Directive,
|
|
1731
|
+
args: [{
|
|
1732
|
+
selector: '[eAppearance]',
|
|
1733
|
+
standalone: true,
|
|
1734
|
+
providers: [ElectraDestroyService],
|
|
1735
|
+
}]
|
|
1736
|
+
}], propDecorators: { appearance: [{
|
|
1737
|
+
type: Input
|
|
1738
|
+
}, {
|
|
1739
|
+
type: HostBinding,
|
|
1740
|
+
args: ['attr.data-appearance']
|
|
1741
|
+
}] } });
|
|
1742
|
+
|
|
1743
|
+
const ELECTRA_APPEARANCE_TYPE_DEFAULT_VALUE = new InjectionToken('appearance type default value');
|
|
1744
|
+
|
|
1745
|
+
class ElectraAppearanceTypeDirective {
|
|
1746
|
+
constructor() {
|
|
1747
|
+
this.default_value = inject(ELECTRA_APPEARANCE_TYPE_DEFAULT_VALUE, {
|
|
1748
|
+
optional: true,
|
|
1749
|
+
});
|
|
1750
|
+
this.appearanceType = this.default_value ?? 'ghost';
|
|
1751
|
+
}
|
|
1752
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraAppearanceTypeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1753
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraAppearanceTypeDirective, isStandalone: true, selector: "[eAppearanceType]", inputs: { appearanceType: "appearanceType" }, host: { properties: { "attr.data-appearance-type": "this.appearanceType" } }, providers: [ElectraDestroyService], ngImport: i0 }); }
|
|
1754
|
+
}
|
|
1755
|
+
__decorate([
|
|
1756
|
+
eDefaultProp(),
|
|
1757
|
+
__metadata("design:type", String)
|
|
1758
|
+
], ElectraAppearanceTypeDirective.prototype, "appearanceType", void 0);
|
|
1759
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraAppearanceTypeDirective, decorators: [{
|
|
1760
|
+
type: Directive,
|
|
1761
|
+
args: [{
|
|
1762
|
+
selector: '[eAppearanceType]',
|
|
1763
|
+
standalone: true,
|
|
1764
|
+
providers: [ElectraDestroyService],
|
|
1765
|
+
}]
|
|
1766
|
+
}], propDecorators: { appearanceType: [{
|
|
1767
|
+
type: Input
|
|
1768
|
+
}, {
|
|
1769
|
+
type: HostBinding,
|
|
1770
|
+
args: ['attr.data-appearance-type']
|
|
1771
|
+
}] } });
|
|
1772
|
+
|
|
1773
|
+
class ElectraHasValueDirective {
|
|
1774
|
+
constructor() {
|
|
1775
|
+
this.hasValue = new EventEmitter();
|
|
1776
|
+
this.hasVal$ = concat(defer(() => of(this.hasVal)), this.hasValue.asObservable()).pipe(shareReplay$1(1));
|
|
1777
|
+
this.empty$ = this.hasVal$.pipe(map(() => this.empty));
|
|
1778
|
+
this.elRef = inject((ElementRef));
|
|
1779
|
+
this.mutationObserverService = inject(ElectraMutationObserverService, {
|
|
1780
|
+
self: true,
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
get hasVal() {
|
|
1784
|
+
return !!this.elRef.nativeElement.childNodes.length;
|
|
1785
|
+
}
|
|
1786
|
+
get empty() {
|
|
1787
|
+
return !this.hasVal;
|
|
1788
|
+
}
|
|
1789
|
+
ngOnInit() {
|
|
1790
|
+
this.emit();
|
|
1791
|
+
this.mutationObserverService.observe(this.elRef.nativeElement, () => {
|
|
1792
|
+
this.emit();
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
emit() {
|
|
1796
|
+
this.hasValue.emit(!!this.elRef.nativeElement.childNodes.length);
|
|
1797
|
+
}
|
|
1798
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraHasValueDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1799
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraHasValueDirective, isStandalone: true, selector: "[eHasValue]:not(ng-content):not(ng-template):not(ng-container)", outputs: { hasValue: "hasValue" }, providers: [ElectraMutationObserverService], exportAs: ["eHasValue"], ngImport: i0 }); }
|
|
1800
|
+
}
|
|
1801
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraHasValueDirective, decorators: [{
|
|
1802
|
+
type: Directive,
|
|
1803
|
+
args: [{
|
|
1804
|
+
selector: '[eHasValue]:not(ng-content):not(ng-template):not(ng-container)',
|
|
1805
|
+
standalone: true,
|
|
1806
|
+
providers: [ElectraMutationObserverService],
|
|
1807
|
+
exportAs: 'eHasValue',
|
|
1808
|
+
}]
|
|
1809
|
+
}], propDecorators: { hasValue: [{
|
|
1810
|
+
type: Output
|
|
1811
|
+
}] } });
|
|
1812
|
+
|
|
1813
|
+
class ElectraTestIdDirective {
|
|
1814
|
+
get testId() {
|
|
1815
|
+
return this.generateMainTestId + (this.testIdPostfix ? `--${this.testIdPostfix}` : '');
|
|
1816
|
+
}
|
|
1817
|
+
set testId(value) {
|
|
1818
|
+
this.testIdPostfix = value;
|
|
1819
|
+
}
|
|
1820
|
+
get generateMainTestId() {
|
|
1821
|
+
return this.testId_;
|
|
1822
|
+
}
|
|
1823
|
+
set generateMainTestId(value) {
|
|
1824
|
+
this.testId_ = value;
|
|
1825
|
+
}
|
|
1826
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraTestIdDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1827
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: ElectraTestIdDirective, isStandalone: true, selector: "[eTestId]", inputs: { testId: "testId" }, host: { properties: { "attr.data-testid": "this.testId" } }, ngImport: i0 }); }
|
|
1828
|
+
}
|
|
1829
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ElectraTestIdDirective, decorators: [{
|
|
1830
|
+
type: Directive,
|
|
1831
|
+
args: [{
|
|
1832
|
+
selector: '[eTestId]',
|
|
1833
|
+
standalone: true,
|
|
1834
|
+
}]
|
|
1835
|
+
}], propDecorators: { testId: [{
|
|
1836
|
+
type: Input
|
|
1837
|
+
}, {
|
|
1838
|
+
type: HostBinding,
|
|
1839
|
+
args: ['attr.data-testid']
|
|
1840
|
+
}] } });
|
|
1841
|
+
|
|
1842
|
+
/**
|
|
1843
|
+
* Generated bundle index. Do not edit.
|
|
1844
|
+
*/
|
|
1845
|
+
|
|
1846
|
+
export { Compare, ELECTRA_ALL_INDEXES_READY, ELECTRA_APPEARANCE_DEFAULT_VALUE, ELECTRA_APPEARANCE_TYPE_DEFAULT_VALUE, ELECTRA_DEFAULT_FRAMES_NUMBER, ELECTRA_DEFAULT_SIZE, ELECTRA_INDEX_SELECT_FN, ELECTRA_SELECTED_INDEX_INITIAL, ELECTRA_SELECTED_INDEX_ITEMS, ELECTRA_STORE_ITEM, ElectraAddToStoreDirective, ElectraAppearanceDirective, ElectraAppearanceTypeDirective, ElectraCallFuncPipe, ElectraCoerceBoolean, ElectraCurrentIndexDirective, ElectraDestroyService, ElectraDisabledDirective, ElectraElementRefDirective, ElectraFormControlHelpers, ElectraHasValueDirective, ElectraHtmlRefDirective, ElectraIdentityMatcherDirective, ElectraLogExecution, ElectraMapSubject, ElectraMapWithChildrenSubject, ElectraMutationObserverService, ElectraOverflowHostDirective, ElectraOverflowItemDirective, ElectraPluckPipe, ElectraProxyObject, ElectraSanitizerPipe, ElectraSelectedIndexDirective, ElectraSetSubject, ElectraSizeDirective, ElectraStoreByIndexDirective, ElectraStringifyDirective, ElectraSyncChildDirective, ElectraSyncOnChange, ElectraSyncParentDirective, ElectraTestIdDirective, ElectraToObservablePipe, ElectraToTypePipe, difference, eCreateResizeObservable, eDisabledHostDirective, eElementResized$, eEmptyQueryList, eExecuteAfterFrames, eFormatNumber, eFromMutationObserver$, eGenerateId, eHasChanges, eHostDirective, eInvertObject, eRaceInEmit, eSetDefaultSize, eSort, eStyleGetVars, eStyleToSnake, filterFalsy, filterNotNullish, filterNullish, filterTruthy, hideOverflowElements, isEqual, mapUndefinedToNull, merge, moveInEventLoopIteration, orderBy, raceEmit, watchObject };
|
|
1847
|
+
//# sourceMappingURL=electra-ui-helpers.mjs.map
|