UNPKG

@obliczeniowo/elementary

Version:
193 lines (187 loc) 7.24 kB
import * as i0 from '@angular/core'; import { EventEmitter, Output, HostBinding, Input, Component, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import * as i1 from '@obliczeniowo/elementary/value-picker'; import { AbstractValueSetModel, ValuePickerModule } from '@obliczeniowo/elementary/value-picker'; import { of } from 'rxjs'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; const monthsDays = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; class DayPickerInterface extends AbstractValueSetModel { offset = 0; max = 31; columns = 7; _month; constructor(month) { super(); this.month = month; } init(current) { this.offset = current && Math.floor((this.set.findIndex(item => current?.value === item.value) || 0) / this.max) || 0; return of(); } set month(month) { this._month = month; this.set = new Array(monthsDays[this.month || 0]).fill(0).map((_, index) => { return { value: index + 1 }; }); } get month() { return this._month; } displayNextPrevious() { return of(this.set.length > this.max); } getNextSet() { const offset = this.offset + 1; if (offset * this.max < this.set.length - 1) { this.offset = offset; return of(true); } return of(false); } getPreviousSet() { if (this.offset) { this.offset = this.offset - 1; return of(true); } return of(false); } getCurrentSet() { return of(this.set.slice(this.offset * this.max, (this.offset + 1) * this.max)); } next(current) { if (!this.set) { return of(); } if (current) { const index = this.set.findIndex(item => item.value === current.value); return of(this.set[Math.min(index + 1, this.set.length - 1)]); } else if (!current) { return of(this.set?.[this.set.length - 1]); } return of(); } previous(current) { if (!this.set) { return of(); } if (current) { const index = this.set.findIndex(item => item.value === current.value); return of(this.set[Math.max(index - 1, 0)]); } else if (!current) { return of(this.set?.[0]); } return of(); } nextDisabled() { return of(this.max * this.offset + this.max >= (this.set.length || 0)); } previousDisabled() { return of(!this.offset || undefined); } selected(item, current) { return item.value === current?.value; } } class DayPickerComponent { _month; _current; model = new DayPickerInterface(); set month(month) { this._month = month; this.model.month = month; if (this._current && this.model.set.length < this._current.value) { this._current.value = this.model.set.length; } } get month() { return this._month; } set current(current) { this._current = current ? { value: current } : undefined; } disabled; changed = new EventEmitter(); onChange = (set) => { }; onTouched = () => { }; registerOnValidatorChange(fn) { this.onChange = fn; } writeValue(set) { this.current = set || this._current?.value || 1; } registerOnChange(onChange) { this.onChange = onChange; } registerOnTouched(onTouched) { this.onTouched = onTouched; } setDisabledState(isDisabled) { this.disabled = isDisabled; } onChanged(item) { this._current = item; this.changed.emit(item.value); this.onChange(item.value); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: DayPickerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: DayPickerComponent, isStandalone: false, selector: "obl-day-picker", inputs: { month: "month", current: "current", disabled: "disabled" }, outputs: { changed: "changed" }, host: { properties: { "class.disabled": "this.disabled" } }, providers: [ { provide: NG_VALUE_ACCESSOR, multi: true, useExisting: DayPickerComponent }, ], ngImport: i0, template: "<obl-value-picker\n [model]=\"model\"\n [current]=\"_current\"\n [disabled]=\"!!disabled\"\n (changed)=\"onChanged($event)\"\n></obl-value-picker>", styles: [""], dependencies: [{ kind: "component", type: i1.ValuePickerComponent, selector: "obl-value-picker", inputs: ["current", "items", "disabled", "placeholder", "model", "display", "picker"], outputs: ["changed"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: DayPickerComponent, decorators: [{ type: Component, args: [{ selector: 'obl-day-picker', providers: [ { provide: NG_VALUE_ACCESSOR, multi: true, useExisting: DayPickerComponent }, ], standalone: false, template: "<obl-value-picker\n [model]=\"model\"\n [current]=\"_current\"\n [disabled]=\"!!disabled\"\n (changed)=\"onChanged($event)\"\n></obl-value-picker>" }] }], propDecorators: { month: [{ type: Input }], current: [{ type: Input }], disabled: [{ type: HostBinding, args: ['class.disabled'] }, { type: Input }], changed: [{ type: Output }] } }); class DayPickerModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: DayPickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: DayPickerModule, declarations: [DayPickerComponent], imports: [CommonModule, ValuePickerModule], exports: [DayPickerComponent] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: DayPickerModule, imports: [CommonModule, ValuePickerModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: DayPickerModule, decorators: [{ type: NgModule, args: [{ declarations: [ DayPickerComponent ], imports: [ CommonModule, ValuePickerModule, ], exports: [ DayPickerComponent ] }] }] }); /** * Generated bundle index. Do not edit. */ export { DayPickerComponent, DayPickerModule }; //# sourceMappingURL=obliczeniowo-elementary-day-picker.mjs.map