@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,323 @@
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) => { var _a; return ((_a = e === null || e === void 0 ? void 0 : e.nodeName) === null || _a === void 0 ? void 0 : _a.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 === null || control === void 0 ? void 0 : 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 === null || control === void 0 ? void 0 : 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 === null || control === void 0 ? void 0 : 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 === null || control === void 0 ? void 0 : 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
+ var _a;
127
+ if (!this.tableOptions) {
128
+ return this._defaultTableValues.pageSize;
129
+ }
130
+ return (_a = this.tableOptions.get('pageSize')) === null || _a === void 0 ? void 0 : _a.value;
131
+ }
132
+ get page() {
133
+ var _a;
134
+ if (!this.tableOptions) {
135
+ return this._defaultTableValues.page;
136
+ }
137
+ return (_a = this.tableOptions.get('page')) === null || _a === void 0 ? void 0 : _a.value;
138
+ }
139
+ get quickFilter() {
140
+ var _a;
141
+ if (!this.tableOptions) {
142
+ return this._defaultTableValues.quickFilter;
143
+ }
144
+ return (_a = this.tableOptions.get('quickFilter')) === null || _a === void 0 ? void 0 : _a.value;
145
+ }
146
+ set quickFilter(quickFilter) {
147
+ this.tableValues = {
148
+ quickFilter,
149
+ };
150
+ }
151
+ get query() {
152
+ var _a;
153
+ if (!this.tableOptions) {
154
+ return this._defaultTableValues.query;
155
+ }
156
+ return (_a = this.tableOptions.get('query')) === null || _a === void 0 ? void 0 : _a.value;
157
+ }
158
+ set query(query) {
159
+ this.tableValues = {
160
+ query,
161
+ };
162
+ }
163
+ get selectedRows() {
164
+ var _a;
165
+ if (!this.tableOptions) {
166
+ return this._defaultTableValues.selectedRows;
167
+ }
168
+ return (_a = this.tableOptions.get('selectedRows')) === null || _a === void 0 ? void 0 : _a.value;
169
+ }
170
+ set selectedRows(selectedRows) {
171
+ this.tableValues = {
172
+ selectedRows,
173
+ };
174
+ }
175
+ // setter
176
+ get parsedDefaultTableValues() {
177
+ var _a;
178
+ return Object.assign(Object.assign(Object.assign({}, this._defaultTableValues), this.defaultTableValues), { pageSize: ((_a = this.defaultTableValues) === null || _a === void 0 ? void 0 : _a.pageSize) || this.pageSizeDefault });
179
+ }
180
+ get tableValues() {
181
+ var _a;
182
+ return (_a = this.tableOptions) === null || _a === void 0 ? void 0 : _a.value;
183
+ }
184
+ set tableValues(values) {
185
+ this._setTableValues(Object.assign(Object.assign({}, this.tableValues), values));
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
+ var _a;
198
+ if ((changes === null || changes === void 0 ? void 0 : changes.query) && ((_a = Object.keys(changes)) === null || _a === void 0 ? void 0 : _a.length) === 1) {
199
+ return timer(300);
200
+ }
201
+ return timer(0);
202
+ }), filter((changes) => {
203
+ var _a;
204
+ return !((changes === null || changes === void 0 ? void 0 : changes.selected) &&
205
+ ((_a = Object.keys(changes)) === null || _a === void 0 ? void 0 : _a.length) === 1);
206
+ }))
207
+ .subscribe((changes) => {
208
+ if (changes === null || changes === void 0 ? void 0 : changes.page) {
209
+ this._refresh();
210
+ return;
211
+ }
212
+ this._resetPageOrRefresh();
213
+ });
214
+ this._refresh();
215
+ }
216
+ resetTable(emitEvent = true, forceRefresh = null) {
217
+ this._setTableValues(this.parsedDefaultTableValues, emitEvent);
218
+ if (forceRefresh) {
219
+ this._refresh();
220
+ }
221
+ }
222
+ _refresh() {
223
+ console.warn('Not implemented');
224
+ }
225
+ _resetPageOrRefresh() {
226
+ var _a;
227
+ if (!this.tableOptions) {
228
+ return;
229
+ }
230
+ if (this.page !== 1) {
231
+ (_a = this.tableOptions.get('page')) === null || _a === void 0 ? void 0 : _a.setValue(1);
232
+ return;
233
+ }
234
+ this._refresh();
235
+ }
236
+ _setTableValues(data, emitEvent = true) {
237
+ var _a;
238
+ (_a = this.tableOptions) === null || _a === void 0 ? void 0 : _a.setValue(data, { emitEvent });
239
+ }
240
+ _getChanges(previous, next) {
241
+ const changes = {};
242
+ let key;
243
+ for (key in next) {
244
+ if (JSON.stringify(previous[key]) !== JSON.stringify(next[key])) {
245
+ changes[key] = next[key];
246
+ }
247
+ }
248
+ return Object.keys(changes).length ? changes : null;
249
+ }
250
+ };
251
+ BaseTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseTableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
252
+ BaseTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: BaseTableComponent, selector: "ng-component", usesInheritance: true, ngImport: i0, template: ``, isInline: true });
253
+ BaseTableComponent = __decorate([
254
+ UntilDestroy({ checkProperties: true })
255
+ ], BaseTableComponent);
256
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseTableComponent, decorators: [{
257
+ type: Component,
258
+ args: [{
259
+ template: ``,
260
+ }]
261
+ }], ctorParameters: function () { return []; } });
262
+
263
+ class BaseUploadComponent {
264
+ constructor() {
265
+ this.uploaded = false;
266
+ this.fileChange = new EventEmitter();
267
+ this._loading = false;
268
+ }
269
+ set loading(value) {
270
+ this._loading = value;
271
+ }
272
+ get loading() {
273
+ return this._loading;
274
+ }
275
+ onChange($event) {
276
+ var _a;
277
+ const target = $event.target;
278
+ const file = (_a = target.files) === null || _a === void 0 ? void 0 : _a[0];
279
+ if (file) {
280
+ this._loading = true;
281
+ const reader = new FileReader();
282
+ reader.onload = (e) => { var _a; return this.onLoad(file, (_a = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _a === void 0 ? void 0 : _a.result); };
283
+ reader.readAsDataURL(file);
284
+ }
285
+ }
286
+ onLoad(file, result) {
287
+ var _a;
288
+ this.fileChange.next({
289
+ fileId: this.fileId,
290
+ result,
291
+ file,
292
+ });
293
+ if ((_a = this.uploaderInput) === null || _a === void 0 ? void 0 : _a.nativeElement) {
294
+ this.uploaderInput.nativeElement.value = '';
295
+ }
296
+ this.file = file;
297
+ this._loading = false;
298
+ }
299
+ }
300
+ BaseUploadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseUploadComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
301
+ 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 });
302
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseUploadComponent, decorators: [{
303
+ type: Component,
304
+ args: [{
305
+ template: ``,
306
+ }]
307
+ }], propDecorators: { fileId: [{
308
+ type: Input
309
+ }], uploaded: [{
310
+ type: Input
311
+ }], loading: [{
312
+ type: Input
313
+ }], fileChange: [{
314
+ type: Output
315
+ }], uploaderInput: [{
316
+ type: ViewChild,
317
+ args: ['uploaderInput']
318
+ }] } });
319
+
320
+ class BaseValueAccessor {
8
321
  constructor(el) {
9
322
  this.el = el;
10
323
  this.onChange = () => {
@@ -34,9 +347,9 @@ class ValueAccessor {
34
347
  this.onTouched = fn;
35
348
  }
36
349
  }
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: [{
350
+ BaseValueAccessor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseValueAccessor, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
351
+ BaseValueAccessor.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: BaseValueAccessor, host: { listeners: { "focusout": "_handleBlurEvent()" } }, ngImport: i0 });
352
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BaseValueAccessor, decorators: [{
40
353
  type: Directive,
41
354
  args: [{}]
42
355
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { _handleBlurEvent: [{
@@ -44,7 +357,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
44
357
  args: ['focusout']
45
358
  }] } });
46
359
 
47
- class PageSizeSelectDirective extends ValueAccessor {
360
+ class PageSizeSelectDirective extends BaseValueAccessor {
48
361
  constructor(el) {
49
362
  super(el);
50
363
  }
@@ -82,7 +395,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
82
395
  }]
83
396
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
84
397
 
85
- class PaginationDirective extends ValueAccessor {
398
+ class PaginationDirective extends BaseValueAccessor {
86
399
  constructor(el) {
87
400
  super(el);
88
401
  }
@@ -120,7 +433,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
120
433
  }]
121
434
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
122
435
 
123
- class TableFooterDirective extends ValueAccessor {
436
+ class TableFooterDirective extends BaseValueAccessor {
124
437
  constructor(el) {
125
438
  super(el);
126
439
  this.lastValue = {
@@ -166,7 +479,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
166
479
  }]
167
480
  }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
168
481
 
169
- class TableHeaderDirective extends ValueAccessor {
482
+ class TableHeaderDirective extends BaseValueAccessor {
170
483
  constructor(el) {
171
484
  super(el);
172
485
  this.lastValue = {
@@ -1550,5 +1863,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
1550
1863
  * Generated bundle index. Do not edit.
1551
1864
  */
1552
1865
 
1553
- 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 };
1866
+ 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 };
1554
1867
  //# sourceMappingURL=paperless-angular.mjs.map