@paperless/angular 0.1.0-alpha.130 → 0.1.0-alpha.131

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,10 +1,315 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, HostListener, Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
3
- import { NG_VALUE_ACCESSOR } from '@angular/forms';
2
+ import { Component, EventEmitter, Input, Output, ViewChild, Directive, HostListener, ChangeDetectionStrategy, NgModule } from '@angular/core';
3
+ import { FormControl, FormGroup, FormArray, NG_VALUE_ACCESSOR } from '@angular/forms';
4
4
  import { __decorate } from 'tslib';
5
- import { fromEvent } from 'rxjs';
5
+ import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy';
6
+ import { timer, fromEvent } from 'rxjs';
7
+ import { startWith, pairwise, map, filter, debounce } from 'rxjs/operators';
6
8
 
7
- class ValueAccessor {
9
+ class FormBaseComponent {
10
+ constructor() {
11
+ this.markedDirty = false;
12
+ }
13
+ scrollToFirstError() {
14
+ const invalidInputs = Array.from(document.getElementsByClassName('ng-invalid'))
15
+ .filter((e) => e?.nodeName?.toLowerCase() !== 'form')
16
+ .sort((a, b) => a.scrollTop - b.scrollTop);
17
+ const first = invalidInputs[0];
18
+ if (first) {
19
+ first.scrollIntoView({
20
+ behavior: 'smooth',
21
+ block: 'center',
22
+ inline: 'center',
23
+ });
24
+ }
25
+ }
26
+ markControlDirty(control) {
27
+ if (control instanceof FormControl) {
28
+ control.markAsDirty({ onlySelf: true });
29
+ control.markAsTouched({ onlySelf: true });
30
+ }
31
+ else if (control instanceof FormGroup) {
32
+ control.markAsDirty();
33
+ control.markAsTouched();
34
+ this.markAllDirty(control);
35
+ }
36
+ else if (control instanceof FormArray) {
37
+ control.markAsDirty();
38
+ control.markAsTouched();
39
+ for (const child of control?.controls) {
40
+ this.markControlDirty(child);
41
+ }
42
+ }
43
+ control.updateValueAndValidity();
44
+ }
45
+ markAllDirty(formGroup) {
46
+ this.markedDirty = true;
47
+ for (const field of Object.keys(formGroup.controls)) {
48
+ const control = formGroup.get(field);
49
+ this.markControlDirty(control);
50
+ }
51
+ }
52
+ getControlError(control) {
53
+ if (!this.hasControlError(control)) {
54
+ return;
55
+ }
56
+ return this.firstControlError(control);
57
+ }
58
+ hasControlError(control, showChildErrors = true) {
59
+ return (control?.dirty && this.firstControlError(control, showChildErrors));
60
+ }
61
+ firstControlError(control, showChildErrors = true) {
62
+ if (control instanceof FormGroup && showChildErrors) {
63
+ const errors = Object.keys(control.controls)
64
+ .map((key) => this.firstControlError(control.controls[key]))
65
+ .filter((val) => !!val);
66
+ return errors[0];
67
+ }
68
+ if (!control?.errors) {
69
+ return;
70
+ }
71
+ const keys = Object.keys(control.errors);
72
+ let err;
73
+ for (const key of keys) {
74
+ if (control.errors[key]) {
75
+ err = key;
76
+ break;
77
+ }
78
+ }
79
+ return err;
80
+ }
81
+ resetControl(control) {
82
+ control.setErrors(null);
83
+ control.reset();
84
+ control.markAsPristine();
85
+ if (control instanceof FormGroup) {
86
+ this.resetForm(control);
87
+ }
88
+ else if (control instanceof FormArray) {
89
+ for (const child of control?.controls) {
90
+ this.resetControl(child);
91
+ }
92
+ }
93
+ }
94
+ resetForm(formGroup) {
95
+ for (const field of Object.keys(formGroup.controls)) {
96
+ const control = formGroup.get(field);
97
+ this.resetControl(control);
98
+ }
99
+ this.markedDirty = false;
100
+ }
101
+ }
102
+ FormBaseComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FormBaseComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
103
+ FormBaseComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: FormBaseComponent, selector: "ng-component", ngImport: i0, template: ``, isInline: true });
104
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FormBaseComponent, decorators: [{
105
+ type: Component,
106
+ args: [{
107
+ template: ``,
108
+ }]
109
+ }] });
110
+
111
+ let BaseTableComponent = class BaseTableComponent extends FormBaseComponent {
112
+ constructor() {
113
+ super();
114
+ this.quickFilters = [];
115
+ this.pageSizeDefault = 12;
116
+ this._defaultTableValues = {
117
+ pageSize: this.pageSizeDefault,
118
+ page: 1,
119
+ quickFilter: null,
120
+ query: '',
121
+ selectedRows: [],
122
+ };
123
+ this.defaultTableValues = {};
124
+ }
125
+ get pageSize() {
126
+ if (!this.tableOptions) {
127
+ return this._defaultTableValues.pageSize;
128
+ }
129
+ return this.tableOptions.get('pageSize')?.value;
130
+ }
131
+ get page() {
132
+ if (!this.tableOptions) {
133
+ return this._defaultTableValues.page;
134
+ }
135
+ return this.tableOptions.get('page')?.value;
136
+ }
137
+ get quickFilter() {
138
+ if (!this.tableOptions) {
139
+ return this._defaultTableValues.quickFilter;
140
+ }
141
+ return this.tableOptions.get('quickFilter')?.value;
142
+ }
143
+ set quickFilter(quickFilter) {
144
+ this.tableValues = {
145
+ quickFilter,
146
+ };
147
+ }
148
+ get query() {
149
+ if (!this.tableOptions) {
150
+ return this._defaultTableValues.query;
151
+ }
152
+ return this.tableOptions.get('query')?.value;
153
+ }
154
+ set query(query) {
155
+ this.tableValues = {
156
+ query,
157
+ };
158
+ }
159
+ get selectedRows() {
160
+ if (!this.tableOptions) {
161
+ return this._defaultTableValues.selectedRows;
162
+ }
163
+ return this.tableOptions.get('selectedRows')?.value;
164
+ }
165
+ set selectedRows(selectedRows) {
166
+ this.tableValues = {
167
+ selectedRows,
168
+ };
169
+ }
170
+ // setter
171
+ get parsedDefaultTableValues() {
172
+ return {
173
+ ...this._defaultTableValues,
174
+ ...this.defaultTableValues,
175
+ pageSize: this.defaultTableValues?.pageSize || this.pageSizeDefault,
176
+ };
177
+ }
178
+ get tableValues() {
179
+ return this.tableOptions?.value;
180
+ }
181
+ set tableValues(values) {
182
+ this._setTableValues({
183
+ ...this.tableValues,
184
+ ...values,
185
+ });
186
+ }
187
+ ngOnInit() {
188
+ this.tableOptions = new FormGroup({
189
+ pageSize: new FormControl(this.parsedDefaultTableValues.pageSize),
190
+ page: new FormControl(this.parsedDefaultTableValues.page),
191
+ quickFilter: new FormControl(this.parsedDefaultTableValues.quickFilter),
192
+ query: new FormControl(this.parsedDefaultTableValues.query),
193
+ selectedRows: new FormControl(this.parsedDefaultTableValues.selectedRows),
194
+ });
195
+ this.tableOptions.valueChanges
196
+ .pipe(untilDestroyed(this), startWith(this.tableOptions.value), pairwise(), map(([previous, next]) => this._getChanges(previous, next)), filter((changes) => !!changes), debounce((changes) => {
197
+ if (changes?.query && Object.keys(changes)?.length === 1) {
198
+ return timer(300);
199
+ }
200
+ return timer(0);
201
+ }), filter((changes) => !(changes?.selected &&
202
+ Object.keys(changes)?.length === 1)))
203
+ .subscribe((changes) => {
204
+ if (changes?.page) {
205
+ this._refresh();
206
+ return;
207
+ }
208
+ this._resetPageOrRefresh();
209
+ });
210
+ this._refresh();
211
+ }
212
+ resetTable(emitEvent = true, forceRefresh = null) {
213
+ this._setTableValues(this.parsedDefaultTableValues, emitEvent);
214
+ if (forceRefresh) {
215
+ this._refresh();
216
+ }
217
+ }
218
+ _refresh() {
219
+ console.warn('Not implemented');
220
+ }
221
+ _resetPageOrRefresh() {
222
+ if (!this.tableOptions) {
223
+ return;
224
+ }
225
+ if (this.page !== 1) {
226
+ this.tableOptions.get('page')?.setValue(1);
227
+ return;
228
+ }
229
+ this._refresh();
230
+ }
231
+ _setTableValues(data, emitEvent = true) {
232
+ this.tableOptions?.setValue(data, { emitEvent });
233
+ }
234
+ _getChanges(previous, next) {
235
+ const changes = {};
236
+ let key;
237
+ for (key in next) {
238
+ if (JSON.stringify(previous[key]) !== JSON.stringify(next[key])) {
239
+ changes[key] = next[key];
240
+ }
241
+ }
242
+ return Object.keys(changes).length ? changes : null;
243
+ }
244
+ };
245
+ BaseTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseTableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
246
+ BaseTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: BaseTableComponent, selector: "ng-component", usesInheritance: true, ngImport: i0, template: ``, isInline: true });
247
+ BaseTableComponent = __decorate([
248
+ UntilDestroy({ checkProperties: true })
249
+ ], BaseTableComponent);
250
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseTableComponent, decorators: [{
251
+ type: Component,
252
+ args: [{
253
+ template: ``,
254
+ }]
255
+ }], ctorParameters: function () { return []; } });
256
+
257
+ class BaseUploadComponent {
258
+ constructor() {
259
+ this.uploaded = false;
260
+ this.fileChange = new EventEmitter();
261
+ this._loading = false;
262
+ }
263
+ set loading(value) {
264
+ this._loading = value;
265
+ }
266
+ get loading() {
267
+ return this._loading;
268
+ }
269
+ onChange($event) {
270
+ const target = $event.target;
271
+ const file = target.files?.[0];
272
+ if (file) {
273
+ this._loading = true;
274
+ const reader = new FileReader();
275
+ reader.onload = (e) => this.onLoad(file, e?.currentTarget?.result);
276
+ reader.readAsDataURL(file);
277
+ }
278
+ }
279
+ onLoad(file, result) {
280
+ this.fileChange.next({
281
+ fileId: this.fileId,
282
+ result,
283
+ file,
284
+ });
285
+ if (this.uploaderInput?.nativeElement) {
286
+ this.uploaderInput.nativeElement.value = '';
287
+ }
288
+ this.file = file;
289
+ this._loading = false;
290
+ }
291
+ }
292
+ BaseUploadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseUploadComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
293
+ BaseUploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: BaseUploadComponent, selector: "ng-component", inputs: { fileId: "fileId", uploaded: "uploaded", loading: "loading" }, outputs: { fileChange: "fileChange" }, viewQueries: [{ propertyName: "uploaderInput", first: true, predicate: ["uploaderInput"], descendants: true }], ngImport: i0, template: ``, isInline: true });
294
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseUploadComponent, decorators: [{
295
+ type: Component,
296
+ args: [{
297
+ template: ``,
298
+ }]
299
+ }], propDecorators: { fileId: [{
300
+ type: Input
301
+ }], uploaded: [{
302
+ type: Input
303
+ }], loading: [{
304
+ type: Input
305
+ }], fileChange: [{
306
+ type: Output
307
+ }], uploaderInput: [{
308
+ type: ViewChild,
309
+ args: ['uploaderInput']
310
+ }] } });
311
+
312
+ class BaseValueAccessor {
8
313
  constructor(el) {
9
314
  this.el = el;
10
315
  this.onChange = () => {
@@ -34,9 +339,9 @@ class ValueAccessor {
34
339
  this.onTouched = fn;
35
340
  }
36
341
  }
37
- ValueAccessor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: ValueAccessor, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
38
- ValueAccessor.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: ValueAccessor, host: { listeners: { "focusout": "_handleBlurEvent()" } }, ngImport: i0 });
39
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: ValueAccessor, decorators: [{
342
+ BaseValueAccessor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseValueAccessor, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
343
+ BaseValueAccessor.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: BaseValueAccessor, host: { listeners: { "focusout": "_handleBlurEvent()" } }, ngImport: i0 });
344
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseValueAccessor, decorators: [{
40
345
  type: Directive,
41
346
  args: [{}]
42
347
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { _handleBlurEvent: [{
@@ -44,7 +349,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
44
349
  args: ['focusout']
45
350
  }] } });
46
351
 
47
- class PageSizeSelectDirective extends ValueAccessor {
352
+ class PageSizeSelectDirective extends BaseValueAccessor {
48
353
  constructor(el) {
49
354
  super(el);
50
355
  }
@@ -82,7 +387,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
82
387
  }]
83
388
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
84
389
 
85
- class PaginationDirective extends ValueAccessor {
390
+ class PaginationDirective extends BaseValueAccessor {
86
391
  constructor(el) {
87
392
  super(el);
88
393
  }
@@ -120,7 +425,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
120
425
  }]
121
426
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
122
427
 
123
- class TableFooterDirective extends ValueAccessor {
428
+ class TableFooterDirective extends BaseValueAccessor {
124
429
  constructor(el) {
125
430
  super(el);
126
431
  this.lastValue = {
@@ -169,7 +474,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
169
474
  }]
170
475
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
171
476
 
172
- class TableHeaderDirective extends ValueAccessor {
477
+ class TableHeaderDirective extends BaseValueAccessor {
173
478
  constructor(el) {
174
479
  super(el);
175
480
  this.lastValue = {
@@ -1556,5 +1861,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
1556
1861
  * Generated bundle index. Do not edit.
1557
1862
  */
1558
1863
 
1559
- export { CUSTOM_DIRECTIVES, PAccordion, PAvatar, PAvatarGroup, PButton, PCardBody, PCardContainer, PCardHeader, PContentSlider, PCounter, PDivider, PDropdown, PDropdownMenuContainer, PDropdownMenuItem, PHelper, PIcon, PIllustration, PInfoPanel, PInputGroup, PLayout, PLoader, PModal, PModalBackdrop, PModalBody, PModalContainer, PModalFooter, PModalHeader, PNavbar, PNavigationItem, PPageSizeSelect, PPagination, PPaginationItem, PProfile, PSegmentContainer, PSegmentItem, PSliderIndicator, PStatus, PStepper, PStepperItem, PStepperLine, PTabGroup, PTabItem, PTable, PTableBody, PTableContainer, PTableDefinition, PTableFooter, PTableHeader, PTableRow, PTag, PTooltip, PageSizeSelectDirective, PaginationDirective, PaperlessModule, TableFooterDirective, TableHeaderDirective };
1864
+ export { BaseTableComponent, BaseUploadComponent, BaseValueAccessor, CUSTOM_DIRECTIVES, FormBaseComponent, PAccordion, PAvatar, PAvatarGroup, PButton, PCardBody, PCardContainer, PCardHeader, PContentSlider, PCounter, PDivider, PDropdown, PDropdownMenuContainer, PDropdownMenuItem, PHelper, PIcon, PIllustration, PInfoPanel, PInputGroup, PLayout, PLoader, PModal, PModalBackdrop, PModalBody, PModalContainer, PModalFooter, PModalHeader, PNavbar, PNavigationItem, PPageSizeSelect, PPagination, PPaginationItem, PProfile, PSegmentContainer, PSegmentItem, PSliderIndicator, PStatus, PStepper, PStepperItem, PStepperLine, PTabGroup, PTabItem, PTable, PTableBody, PTableContainer, PTableDefinition, PTableFooter, PTableHeader, PTableRow, PTag, PTooltip, PageSizeSelectDirective, PaginationDirective, PaperlessModule, TableFooterDirective, TableHeaderDirective };
1560
1865
  //# sourceMappingURL=paperless-angular.mjs.map