1 | import { getLocaleFirstDayOfWeek, CommonModule } from '@angular/common';
|
2 | import { EventEmitter, Component, ChangeDetectionStrategy, forwardRef, ViewEncapsulation, Inject, LOCALE_ID, Input, Output, NgModule } from '@angular/core';
|
3 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
4 | import { implicitToExplicitTz, explicitToImplicitTz } from '@bmat/angular-luxon';
|
5 | import { DateTime } from 'luxon';
|
6 | import { BehaviorSubject } from 'rxjs';
|
7 | import { OwlDateTimeModule, OwlNativeDateTimeModule, OWL_DATE_TIME_FORMATS } from 'ng-pick-datetime';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function coerceDate(v, zone = 'utc') {
|
19 | if (!v) {
|
20 | return null;
|
21 | }
|
22 |
|
23 | const instant = DateTime.fromISO(v, { zone });
|
24 | if (!instant.isValid) {
|
25 | return null;
|
26 | }
|
27 | return explicitToImplicitTz(instant);
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | class MomentInBoundComponent {
|
34 | |
35 |
|
36 |
|
37 | constructor(locale) {
|
38 | this.innerValue$ = new BehaviorSubject(null);
|
39 | |
40 |
|
41 |
|
42 | this.momentSelect = new EventEmitter();
|
43 | this.firstDayOfWeek = getLocaleFirstDayOfWeek(locale);
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 | set value(v) {
|
50 | this.innerValue$.next(coerceDate(v, this.timezone));
|
51 | }
|
52 | |
53 |
|
54 |
|
55 |
|
56 | set startTime(v) {
|
57 |
|
58 | const next = new Date(v);
|
59 | if (!Number.isNaN(next.getTime())) {
|
60 | this.calendarMin = next;
|
61 | }
|
62 | }
|
63 | |
64 |
|
65 |
|
66 |
|
67 | set endTime(v) {
|
68 |
|
69 | const next = new Date(v);
|
70 | if (!Number.isNaN(next.getTime())) {
|
71 | this.calendarMax = next;
|
72 | }
|
73 | }
|
74 | |
75 |
|
76 |
|
77 |
|
78 | onDateTimeChange(e) {
|
79 |
|
80 | let nextValue = null;
|
81 | if (e.value && !Number.isNaN(e.value.getTime())) {
|
82 | nextValue = implicitToExplicitTz(e.value, this.timezone || 'utc').toISO();
|
83 | }
|
84 | if (this._onChangeCb) {
|
85 | this._onChangeCb(nextValue);
|
86 | }
|
87 | this.momentSelect.emit(nextValue);
|
88 | }
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 | writeValue(v) {
|
95 | this.innerValue$.next(coerceDate(v, this.timezone));
|
96 | }
|
97 | |
98 |
|
99 |
|
100 |
|
101 | registerOnChange(fn) {
|
102 | this._onChangeCb = fn;
|
103 | }
|
104 | |
105 |
|
106 |
|
107 |
|
108 | registerOnTouched(fn) {
|
109 | this._onTouchedCb = fn;
|
110 | }
|
111 | |
112 |
|
113 |
|
114 |
|
115 | setDisabledState(disabled) {
|
116 | this.disabled = disabled;
|
117 | }
|
118 |
|
119 | |
120 |
|
121 |
|
122 | onFocusin() {
|
123 | if (this._onTouchedCb) {
|
124 | this._onTouchedCb();
|
125 | }
|
126 | }
|
127 | }
|
128 | MomentInBoundComponent.decorators = [
|
129 | { type: Component, args: [{
|
130 | selector: 'bm-moment-in-bound',
|
131 | template: "<input\n (dateTimeChange)=\"onDateTimeChange($event)\"\n (focusin)=\"onFocusin()\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n [disabled]=\"disabled\"\n [max]=\"calendarMax\"\n [min]=\"calendarMin\"\n [name]=\"name\"\n [owlDateTime]=\"rangePicker\"\n [owlDateTimeTrigger]=\"rangePicker\"\n [readonly]=\"readonly\"\n [required]=\"required\"\n [value]=\"innerValue$ | async\"\n class=\"moment-in-bound__input\"\n i18n-placeholder\n placeholder=\"Pick date/time\"\n selectMode=\"single\"\n type=\"text\"\n/>\n<owl-date-time\n [disabled]=\"disabled || readonly\"\n [firstDayOfWeek]=\"firstDayOfWeek\"\n [hour12Timer]=\"false\"\n [showSecondsTimer]=\"true\"\n #rangePicker\n pickerType=\"both\"\n></owl-date-time>\n<span class=\"moment-in-bound__icon\"><i class=\"far fa-clock\"></i></span>\n",
|
132 | changeDetection: ChangeDetectionStrategy.OnPush,
|
133 | providers: [
|
134 | {
|
135 | provide: NG_VALUE_ACCESSOR,
|
136 |
|
137 | useExisting: forwardRef(( |
138 |
|
139 |
|
140 | () => MomentInBoundComponent)),
|
141 | multi: true,
|
142 | },
|
143 | ],
|
144 |
|
145 | encapsulation: ViewEncapsulation.None,
|
146 | styles: [".owl-dialog-container{position:relative;pointer-events:auto;box-sizing:border-box;display:block;padding:1.5em;border-radius:2px;overflow:auto;background:#fff;color:rgba(0,0,0,.87);width:100%;height:100%;outline:0}.owl-dt-container{box-sizing:border-box;display:block;font-size:1rem;background:#fff;pointer-events:auto;z-index:1000}.owl-dt-container *{box-sizing:border-box}.owl-dt-container-row{border-bottom:1px solid rgba(0,0,0,.12)}.owl-dt-container-row:last-child{border-bottom:none}.owl-dt-calendar{display:flex;flex-direction:column;width:100%}.owl-dt-calendar-control{display:flex;align-items:center;font-size:1em;width:100%;padding:.5em;color:#000}.owl-dt-calendar-control .owl-dt-calendar-control-content{flex:1 1 auto;display:flex;justify-content:center;align-items:center}.owl-dt-calendar-control .owl-dt-calendar-control-content .owl-dt-calendar-control-button{padding:0 .8em}.owl-dt-calendar-control .owl-dt-calendar-control-content .owl-dt-calendar-control-button:hover{background-color:rgba(0,0,0,.12)}.owl-dt-calendar-main{display:flex;flex-direction:column;flex:1 1 auto;padding:0 .5em .5em;outline:0}.owl-dt-calendar-view{display:block;flex:1 1 auto}.owl-dt-calendar-multi-year-view{display:flex;align-items:center}.owl-dt-calendar-multi-year-view .owl-dt-calendar-table{width:calc(100% - 3em)}.owl-dt-calendar-multi-year-view .owl-dt-calendar-table .owl-dt-calendar-header th{padding-bottom:.25em}.owl-dt-calendar-table{width:100%;border-collapse:initial;border-spacing:1px}.owl-dt-calendar-table .owl-dt-calendar-header{color:rgba(0,0,0,.4)}.owl-dt-calendar-table .owl-dt-calendar-header .owl-dt-weekdays th{font-size:.7em;font-weight:400;text-align:center;padding-bottom:1em}.owl-dt-calendar-table .owl-dt-calendar-header .owl-dt-calendar-table-divider{position:relative;height:1px;padding-bottom:.5em}.owl-dt-calendar-table .owl-dt-calendar-header .owl-dt-calendar-table-divider:after{content:'';position:absolute;top:0;left:-.5em;right:-.5em;height:1px;background:rgba(0,0,0,.12)}.owl-dt-calendar-table .owl-dt-calendar-cell{position:relative;line-height:0;text-align:center;outline:0;color:rgba(0,0,0,.85)}.owl-dt-calendar-table .owl-dt-calendar-cell-content{position:absolute;top:5%;left:5%;display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:90%;height:90%;font-size:.8em;line-height:1;border:1px solid transparent;color:inherit;cursor:pointer}.owl-dt-calendar-table .owl-dt-calendar-cell-selected,.owl-dt-calendar-table .owl-dt-calendar-cell:not(.owl-dt-calendar-cell-in-range)>.owl-dt-calendar-cell-out{height:100%;left:0;top:0;width:100%}.owl-dt-calendar-table .owl-dt-calendar-cell:not(.owl-dt-calendar-cell-in-range)>.owl-dt-calendar-cell-out{background-color:#edf2f5}.owl-dt-calendar-table .owl-dt-calendar-cell-today:not(.owl-dt-calendar-cell-selected){border-color:rgba(0,0,0,.4)}.owl-dt-calendar-table .owl-dt-calendar-cell-selected{background-color:#0091ff;color:#fff}.owl-dt-calendar-table .owl-dt-calendar-cell-selected.owl-dt-calendar-cell-today{box-shadow:inset 0 0 0 1px rgba(255,255,255,.85)}.owl-dt-calendar-table .owl-dt-calendar-cell-disabled{cursor:default}.owl-dt-calendar-table .owl-dt-calendar-cell-disabled>.owl-dt-calendar-cell-content:not(.owl-dt-calendar-cell-selected){color:rgba(0,0,0,.4)}.owl-dt-calendar-table .owl-dt-calendar-cell-disabled>.owl-dt-calendar-cell-content.owl-dt-calendar-cell-selected{opacity:.2}.owl-dt-calendar-table .owl-dt-calendar-cell-disabled>.owl-dt-calendar-cell-today:not(.owl-dt-calendar-cell-selected){border-color:rgba(0,0,0,.2)}.owl-dt-calendar-table .owl-dt-calendar-cell-active:focus>.owl-dt-calendar-cell-content:not(.owl-dt-calendar-cell-selected),.owl-dt-calendar-table :not(.owl-dt-calendar-cell-disabled):hover>.owl-dt-calendar-cell-content:not(.owl-dt-calendar-cell-selected){background-color:rgba(0,0,0,.04)}.owl-dt-calendar-table .owl-dt-calendar-cell-in-range{background:#add9fe}.owl-dt-control-button{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;margin:0;padding:0;background-color:transparent;font-size:1em;color:inherit}.owl-dt-control-button .owl-dt-control-button-content{position:relative;display:inline-flex;justify-content:center;align-items:center;outline:0}.owl-dt-control-period-button .owl-dt-control-button-content{height:1.5em;padding:0 .5em;border-radius:3px;transition:background-color .1s linear}.owl-dt-control-period-button:hover>.owl-dt-control-button-content{background-color:rgba(0,0,0,.12)}.owl-dt-control-period-button .owl-dt-control-button-arrow{display:flex;justify-content:center;align-items:center;width:1em;height:1em;margin:.1em;transition:transform .2s;transition:transform .2s,-webkit-transform .2s}.owl-dt-control-arrow-button .owl-dt-control-button-content{padding:0;border-radius:50%;width:1.5em;height:1.5em}.owl-dt-control-arrow-button[disabled]{color:rgba(0,0,0,.4);cursor:default}.owl-dt-control-arrow-button svg{width:50%;height:50%;fill:currentColor}.owl-dt-inline-container,.owl-dt-popup-container{position:relative;width:18.5em;box-shadow:0 5px 5px -3px rgba(0,0,0,.2),0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12)}.owl-dt-inline-container .owl-dt-calendar,.owl-dt-popup-container .owl-dt-calendar{width:100%;height:20.25em}.owl-dt-dialog-container{max-height:95vh;margin:-1.5em}.owl-dt-dialog-container .owl-dt-calendar{min-width:250px;min-height:330px;max-width:750px;max-height:750px}@media all and (orientation:landscape){.owl-dt-dialog-container .owl-dt-calendar{width:58vh;height:62vh}}@media all and (orientation:portrait){.owl-dt-dialog-container .owl-dt-calendar{width:80vw;height:80vw}}.owl-dt-container-buttons{display:flex;width:100%;height:2em;color:#3f51b5}.owl-dt-container-control-button{font-size:1em;width:50%;height:100%;border-radius:0}.owl-dt-container-control-button .owl-dt-control-button-content{height:100%;width:100%;transition:background-color .1s linear}.owl-dt-container-control-button:hover .owl-dt-control-button-content{background-color:rgba(0,0,0,.1)}.owl-dt-container-info{padding:0 .5em;cursor:pointer}.owl-dt-container-info .owl-dt-container-range{outline:0}.owl-dt-container-info .owl-dt-container-range .owl-dt-container-range-content{display:flex;justify-content:space-between;padding:.5em 0;font-size:.8em}.owl-dt-container-info .owl-dt-container-range:last-child{border-top:1px solid rgba(0,0,0,.12)}.owl-dt-container-info .owl-dt-container-info-active{color:#3f51b5}.owl-dt-container-disabled,.owl-dt-trigger-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none;cursor:default!important}.owl-dt-calendar-only-current-month .owl-dt-calendar-cell-out{visibility:hidden;cursor:default}.owl-dt-inline{display:inline-block}.owl-dt-control{outline:0;cursor:pointer}.owl-dt-control .owl-dt-control-content{outline:0}.owl-dt-control:focus>.owl-dt-control-content{background-color:rgba(0,0,0,.12)}.owl-dt-control:not(:-moz-focusring):focus>.owl-dt-control-content{box-shadow:none}.owl-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.owl-dt-timer{display:flex;justify-content:center;width:100%;height:7em;padding:.5em;outline:0}.owl-dt-timer-box{position:relative;display:inline-flex;flex-direction:column;align-items:center;width:25%;height:100%}.owl-dt-timer-content{flex:1 1 auto;display:flex;justify-content:center;align-items:center;width:100%;margin:.2em 0}.owl-dt-timer-content .owl-dt-timer-input{display:block;width:2em;text-align:center;border:1px solid rgba(0,0,0,.5);border-radius:3px;outline:0;font-size:1.2em;padding:.2em}.owl-dt-timer-divider{display:inline-block;align-self:flex-end;position:absolute;width:.6em;height:100%;left:-.3em}.owl-dt-timer-divider::after,.owl-dt-timer-divider::before{content:'';display:inline-block;width:.35em;height:.35em;position:absolute;left:50%;border-radius:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%);background-color:currentColor}.owl-dt-timer-divider::before{top:35%}.owl-dt-timer-divider::after{bottom:35%}bm-moment-in-bound{background-color:#fff;border-radius:4px;border:1px solid #e0e0e0;align-items:center;box-sizing:border-box;color:var(--moment-in-bound-text-color,rgba(0,0,0,.54));display:inline-flex;flex-wrap:nowrap;height:2.5em;justify-content:space-between;overflow-x:hidden;position:relative;text-align:left;width:16em;width:var(--moment-in-bound-width,16em)}.moment-in-bound__input{background:0 0;border:0;box-sizing:border-box;height:100%;max-width:100%;padding:0 3em 0 1em}.moment-in-bound__icon{color:var(--moment-in-bound-icon-color,#000);cursor:pointer;pointer-events:none;position:absolute;right:1em;top:0;bottom:0;display:flex;align-items:center}"]
|
147 | }] }
|
148 | ];
|
149 |
|
150 | MomentInBoundComponent.ctorParameters = () => [
|
151 | { type: String, decorators: [{ type: Inject, args: [LOCALE_ID,] }] }
|
152 | ];
|
153 | MomentInBoundComponent.propDecorators = {
|
154 | value: [{ type: Input }],
|
155 | ariaLabel: [{ type: Input, args: ['aria-label',] }],
|
156 | ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
|
157 | disabled: [{ type: Input }],
|
158 | name: [{ type: Input }],
|
159 | readonly: [{ type: Input }],
|
160 | required: [{ type: Input }],
|
161 | timezone: [{ type: Input }],
|
162 | startTime: [{ type: Input }],
|
163 | endTime: [{ type: Input }],
|
164 | momentSelect: [{ type: Output }]
|
165 | };
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | const MY_NATIVE_FORMATS = {
|
176 | fullPickerInput: {
|
177 | year: '2-digit',
|
178 | month: '2-digit',
|
179 | day: '2-digit',
|
180 | hour: 'numeric',
|
181 | minute: 'numeric',
|
182 | second: 'numeric',
|
183 | },
|
184 | datePickerInput: { year: '2-digit', month: 'numeric', day: 'numeric' },
|
185 | timePickerInput: { hour: 'numeric', minute: 'numeric' },
|
186 | monthYearLabel: { year: '2-digit', month: 'short' },
|
187 | dateA11yLabel: { year: '2-digit', month: 'long', day: 'numeric' },
|
188 | monthYearA11yLabel: { year: '2-digit', month: 'long' },
|
189 | };
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | const ɵ0 = MY_NATIVE_FORMATS;
|
196 | class MomentInBoundComponentModule {
|
197 | }
|
198 | MomentInBoundComponentModule.decorators = [
|
199 | { type: NgModule, args: [{
|
200 | imports: [CommonModule, OwlDateTimeModule, OwlNativeDateTimeModule],
|
201 | declarations: [MomentInBoundComponent],
|
202 | exports: [MomentInBoundComponent],
|
203 | providers: [{ provide: OWL_DATE_TIME_FORMATS, useValue: ɵ0 }],
|
204 | },] }
|
205 | ];
|
206 |
|
207 | export { MY_NATIVE_FORMATS, MomentInBoundComponent, MomentInBoundComponentModule };
|
208 |
|