@anglr/datetime 6.0.0 → 6.1.0-beta.20230104111018
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/changelog.md +19 -0
- package/es2015/src/directives/datePickerInput/datePickerInput.directive.js +37 -0
- package/es2015/src/directives/datePickerInput/datePickerInput.directive.js.map +1 -0
- package/es2015/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.js +325 -0
- package/es2015/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.js.map +1 -0
- package/es2015/src/directives/dateTimePickerInput/dateTimePickerInput.directive.js +29 -0
- package/es2015/src/directives/dateTimePickerInput/dateTimePickerInput.directive.js.map +1 -0
- package/es2015/src/directives/index.js +4 -0
- package/es2015/src/directives/index.js.map +1 -1
- package/es2015/src/directives/withNow/withNow.directive.js +44 -0
- package/es2015/src/directives/withNow/withNow.directive.js.map +1 -0
- package/es2015/src/directives/withToday/withToday.directive.js +6 -6
- package/es2015/src/directives/withToday/withToday.directive.js.map +1 -1
- package/es2015/src/misc/utils.js +52 -0
- package/es2015/src/misc/utils.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTime/dateTime.directive.js +32 -12
- package/es2015/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -1
- package/es2020/src/directives/datePickerInput/datePickerInput.directive.js +37 -0
- package/es2020/src/directives/datePickerInput/datePickerInput.directive.js.map +1 -0
- package/es2020/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.js +322 -0
- package/es2020/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.js.map +1 -0
- package/es2020/src/directives/dateTimePickerInput/dateTimePickerInput.directive.js +29 -0
- package/es2020/src/directives/dateTimePickerInput/dateTimePickerInput.directive.js.map +1 -0
- package/es2020/src/directives/index.js +4 -0
- package/es2020/src/directives/index.js.map +1 -1
- package/es2020/src/directives/withNow/withNow.directive.js +44 -0
- package/es2020/src/directives/withNow/withNow.directive.js.map +1 -0
- package/es2020/src/directives/withToday/withToday.directive.js +6 -6
- package/es2020/src/directives/withToday/withToday.directive.js.map +1 -1
- package/es2020/src/misc/utils.js +52 -0
- package/es2020/src/misc/utils.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTime/dateTime.directive.js +32 -12
- package/es2020/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -1
- package/package.json +1 -1
- package/src/directives/datePickerInput/datePickerInput.directive.d.ts +12 -0
- package/src/directives/datePickerInput/datePickerInput.directive.d.ts.map +1 -0
- package/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.d.ts +86 -0
- package/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.d.ts.map +1 -0
- package/src/directives/dateTimePickerInput/dateTimePickerInput.directive.d.ts +11 -0
- package/src/directives/dateTimePickerInput/dateTimePickerInput.directive.d.ts.map +1 -0
- package/src/directives/index.d.ts +4 -0
- package/src/directives/index.d.ts.map +1 -1
- package/src/directives/withNow/withNow.directive.d.ts +22 -0
- package/src/directives/withNow/withNow.directive.d.ts.map +1 -0
- package/src/directives/withToday/withToday.directive.d.ts +3 -2
- package/src/directives/withToday/withToday.directive.d.ts.map +1 -1
- package/src/misc/utils.d.ts +18 -1
- package/src/misc/utils.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts +19 -6
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts.map +1 -1
- package/version.bak +1 -1
- package/es2015/src/legacy/selector/components/inputDateTime/inputDateTime.component.js +0 -488
- package/es2015/src/legacy/selector/components/inputDateTime/inputDateTime.component.js.map +0 -1
- package/es2015/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js +0 -367
- package/es2015/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js.map +0 -1
- package/es2020/src/legacy/selector/components/inputDateTime/inputDateTime.component.js +0 -488
- package/es2020/src/legacy/selector/components/inputDateTime/inputDateTime.component.js.map +0 -1
- package/es2020/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js +0 -367
- package/es2020/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.js.map +0 -1
- package/src/legacy/selector/components/inputDateTime/inputDateTime.component.css +0 -9
- package/src/legacy/selector/components/inputDateTime/inputDateTime.component.d.ts +0 -1
- package/src/legacy/selector/components/inputDateTime/inputDateTime.component.d.ts.map +0 -1
- package/src/legacy/selector/components/inputDateTime/inputDateTime.component.html +0 -10
- package/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.css +0 -9
- package/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.d.ts +0 -1
- package/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.d.ts.map +0 -1
- package/src/legacy/selector/components/simpleInputDateTime/simpleInputDateTime.component.html +0 -9
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Directive, Inject, Optional } from '@angular/core';
|
|
3
|
+
import { BindThis } from '@jscrpt/common';
|
|
4
|
+
import { Subscription } from 'rxjs';
|
|
5
|
+
import { DATE_API, DATE_TIME_INPUT } from '../../misc/tokens';
|
|
6
|
+
import { parseDateTime, parseRawInput } from '../../misc/utils';
|
|
7
|
+
import { DateTimePickerSADirective, DateTimeSADirective } from '../../modules';
|
|
8
|
+
import { DatePositionParserService, DateValueProvider } from '../../services';
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
import * as i1 from "../../modules";
|
|
11
|
+
import * as i2 from "../../services";
|
|
12
|
+
/**
|
|
13
|
+
* Directive that adds handler for date time input, which allows navigation using keyboard and checking restriction of value
|
|
14
|
+
*/
|
|
15
|
+
export class DateTimeInputHandlerSADirective {
|
|
16
|
+
//######################### constructor #########################
|
|
17
|
+
constructor(input, dateApi, dateTimeData, parserSvc, valueProvider, picker) {
|
|
18
|
+
this.input = input;
|
|
19
|
+
this.dateApi = dateApi;
|
|
20
|
+
this.dateTimeData = dateTimeData;
|
|
21
|
+
this.parserSvc = parserSvc;
|
|
22
|
+
this.valueProvider = valueProvider;
|
|
23
|
+
this.picker = picker;
|
|
24
|
+
//######################### protected properties #########################
|
|
25
|
+
/**
|
|
26
|
+
* Subscriptions created during initialization
|
|
27
|
+
*/
|
|
28
|
+
this.initSubscriptions = new Subscription();
|
|
29
|
+
this.parser = parserSvc.createParser(this.dateTimeData.customFormat);
|
|
30
|
+
this.initSubscriptions.add(this.dateTimeData.customFormatChanges.subscribe(() => this.parser = parserSvc.createParser(this.dateTimeData.customFormat)));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets input element as html input
|
|
34
|
+
*/
|
|
35
|
+
get inputElement() {
|
|
36
|
+
if (this.input.element.nodeName == 'INPUT') {
|
|
37
|
+
return this.input.element;
|
|
38
|
+
}
|
|
39
|
+
throw new Error('You cant use DateTimeInputHandlerSADirective without input element!');
|
|
40
|
+
}
|
|
41
|
+
//######################### public methods - implementation of OnInit #########################
|
|
42
|
+
/**
|
|
43
|
+
* Initialize component
|
|
44
|
+
*/
|
|
45
|
+
ngOnInit() {
|
|
46
|
+
this.input.element.addEventListener('keydown', this.handleKeyboard);
|
|
47
|
+
this.input.element.addEventListener('keypress', this.handleKeypress);
|
|
48
|
+
this.input.element.addEventListener('select', this.handleSelect);
|
|
49
|
+
this.input.element.addEventListener('click', this.handleClick);
|
|
50
|
+
}
|
|
51
|
+
//######################### public methods - implementation of OnDestroy #########################
|
|
52
|
+
/**
|
|
53
|
+
* Called when component is destroyed
|
|
54
|
+
*/
|
|
55
|
+
ngOnDestroy() {
|
|
56
|
+
this.initSubscriptions.unsubscribe();
|
|
57
|
+
this.input.element.removeEventListener('keydown', this.handleKeyboard);
|
|
58
|
+
this.input.element.removeEventListener('keypress', this.handleKeypress);
|
|
59
|
+
this.input.element.removeEventListener('select', this.handleSelect);
|
|
60
|
+
this.input.element.removeEventListener('click', this.handleClick);
|
|
61
|
+
}
|
|
62
|
+
//######################### protected methods #########################
|
|
63
|
+
/**
|
|
64
|
+
* Handles selection of text inside of input
|
|
65
|
+
*/
|
|
66
|
+
handleSelect() {
|
|
67
|
+
this.runWithValue(() => {
|
|
68
|
+
//handles when all text is selected
|
|
69
|
+
if (this.inputElement.selectionStart == 0 && this.inputElement.selectionEnd == this.inputElement.value.length) {
|
|
70
|
+
const result = this.parser.parse(this.inputElement.value, this.inputElement.selectionStart);
|
|
71
|
+
this.inputElement.selectionStart = result.positionFrom;
|
|
72
|
+
this.inputElement.selectionEnd = result.positionTo;
|
|
73
|
+
}
|
|
74
|
+
}, () => {
|
|
75
|
+
//TODO: add support for ranges
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Handles click event inside of input
|
|
80
|
+
*/
|
|
81
|
+
handleClick() {
|
|
82
|
+
this.runWithValue(() => {
|
|
83
|
+
const result = this.parser.parse(this.inputElement.value, this.inputElement.selectionStart ?? 0);
|
|
84
|
+
this.inputElement.selectionStart = result.positionFrom;
|
|
85
|
+
this.inputElement.selectionEnd = result.positionTo;
|
|
86
|
+
}, () => {
|
|
87
|
+
//TODO: add support for ranges
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Handles keyboard events
|
|
92
|
+
* @param event - Keyboard event that occured
|
|
93
|
+
*/
|
|
94
|
+
handleKeypress(event) {
|
|
95
|
+
const selectionStart = this.inputElement.selectionStart ?? 0;
|
|
96
|
+
const selectionEnd = this.inputElement.selectionEnd ?? 0;
|
|
97
|
+
const newRawValueArray = this.inputElement.value.split('');
|
|
98
|
+
newRawValueArray.splice(selectionStart, selectionEnd - selectionStart);
|
|
99
|
+
newRawValueArray.splice(selectionStart, 0, ...event.key);
|
|
100
|
+
const newRawValue = newRawValueArray.join('');
|
|
101
|
+
const [parsedValue] = parseRawInput(newRawValue, this.dateApi, this.dateTimeData, this.valueProvider);
|
|
102
|
+
this.runWithValue(parsedValue => {
|
|
103
|
+
if (this.minMaxConstraintTest(parsedValue)) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
}
|
|
107
|
+
}, () => {
|
|
108
|
+
//TODO: add support for ranges
|
|
109
|
+
}, parsedValue);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Handles keyboard events
|
|
113
|
+
* @param event - Keyboard event that occured
|
|
114
|
+
*/
|
|
115
|
+
handleKeyboard(event) {
|
|
116
|
+
this.runWithValue(parsedValue => {
|
|
117
|
+
const selectionStart = this.inputElement.selectionStart ?? 0;
|
|
118
|
+
switch (event.key) {
|
|
119
|
+
case 'ArrowRight':
|
|
120
|
+
case 'ArrowLeft':
|
|
121
|
+
{
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
event.stopPropagation();
|
|
124
|
+
const result = event.key == 'ArrowLeft' ? this.parser.previous(this.inputElement.value, selectionStart) : this.parser.next(this.inputElement.value, selectionStart);
|
|
125
|
+
if (result) {
|
|
126
|
+
this.inputElement.selectionStart = result.positionFrom;
|
|
127
|
+
this.inputElement.selectionEnd = result.positionTo;
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case 'ArrowUp':
|
|
132
|
+
case 'ArrowDown':
|
|
133
|
+
{
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
event.stopPropagation();
|
|
136
|
+
let result = this.parser.parse(this.inputElement.value, selectionStart);
|
|
137
|
+
const selectionStartNew = result.positionFrom;
|
|
138
|
+
this.stepChangeValue(parsedValue, result.part, event.key == 'ArrowUp');
|
|
139
|
+
result = this.parser.parse(this.inputElement.value, selectionStartNew);
|
|
140
|
+
this.inputElement.selectionStart = result.positionFrom;
|
|
141
|
+
this.inputElement.selectionEnd = result.positionTo;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case 'Tab':
|
|
145
|
+
{
|
|
146
|
+
const result = event.shiftKey ? this.parser.previous(this.inputElement.value, selectionStart) : this.parser.next(this.inputElement.value, selectionStart);
|
|
147
|
+
if (result) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
this.inputElement.selectionStart = result.positionFrom;
|
|
151
|
+
this.inputElement.selectionEnd = result.positionTo;
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
case 'a':
|
|
156
|
+
{
|
|
157
|
+
if (event.ctrlKey) {
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case 'Backspace':
|
|
164
|
+
{
|
|
165
|
+
this.input.value = null;
|
|
166
|
+
this.input.valueChange.next();
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case 'Escape':
|
|
170
|
+
{
|
|
171
|
+
this.picker?.hidePicker();
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case ' ':
|
|
175
|
+
{
|
|
176
|
+
if (event.ctrlKey) {
|
|
177
|
+
this.picker?.showPicker();
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, () => {
|
|
183
|
+
//TODO: add support for ranges
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Tests whether are min or max constraint broken, returns true if constraint is broken
|
|
188
|
+
* @param value - Value to be tested
|
|
189
|
+
*/
|
|
190
|
+
minMaxConstraintTest(value) {
|
|
191
|
+
return (!!this.dateTimeData.minDateTime && value.isBefore(this.dateTimeData.minDateTime)) ||
|
|
192
|
+
(!!this.dateTimeData.maxDateTime && value.isAfter(this.dateTimeData.maxDateTime));
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Runs code with check whether min max constrains was broken
|
|
196
|
+
* @param value - Value to be used checked for constrains
|
|
197
|
+
* @param code - Code that should be executed which can change current value
|
|
198
|
+
*/
|
|
199
|
+
withMinMaxConstraint(value, code) {
|
|
200
|
+
value.updateOriginal();
|
|
201
|
+
code();
|
|
202
|
+
//min value constraint failure
|
|
203
|
+
if (this.minMaxConstraintTest(value)) {
|
|
204
|
+
value.resetOriginal();
|
|
205
|
+
}
|
|
206
|
+
//value has changed, change input value
|
|
207
|
+
if (!value.isSame(value.originalValue)) {
|
|
208
|
+
this.input.value = value.value;
|
|
209
|
+
this.input.valueChange.next();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Runs code for existing and valid value of date time
|
|
214
|
+
* @param singleValueCode - Code to be run when only single value can be inside of date time
|
|
215
|
+
* @param rangeValueCode - Code to be run when range value can be inside of date time
|
|
216
|
+
* @param parsedValueDefault - Default parsed value to be used
|
|
217
|
+
*/
|
|
218
|
+
runWithValue(singleValueCode, rangeValueCode, parsedValueDefault) {
|
|
219
|
+
const parsedValue = parsedValueDefault ?? parseDateTime(this.input.value, this.dateApi, null, this.dateTimeData.customFormat);
|
|
220
|
+
if (!parsedValue) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (Array.isArray(parsedValue)) {
|
|
224
|
+
rangeValueCode(parsedValue);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
//do nothing for invalid value
|
|
228
|
+
if (!parsedValue.isValid()) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
singleValueCode(parsedValue);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Changes current value of date for for specified part by single step
|
|
236
|
+
* @param value - Value to be used checked for constrains
|
|
237
|
+
* @param part - Part of date that should be changed
|
|
238
|
+
* @param increment - Indication whether value should be incremented or decremented
|
|
239
|
+
*/
|
|
240
|
+
stepChangeValue(value, part, increment) {
|
|
241
|
+
switch (part) {
|
|
242
|
+
case 'y':
|
|
243
|
+
case 'Y':
|
|
244
|
+
{
|
|
245
|
+
this.withMinMaxConstraint(value, () => increment ? value.addYears(1) : value.subtractYears(1));
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case 'Q':
|
|
249
|
+
{
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 'M':
|
|
253
|
+
{
|
|
254
|
+
this.withMinMaxConstraint(value, () => increment ? value.addMonths(1) : value.subtractMonths(1));
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case 'w':
|
|
258
|
+
{
|
|
259
|
+
this.withMinMaxConstraint(value, () => increment ? value.addWeeks(1) : value.subtractWeeks(1));
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case 'd':
|
|
263
|
+
case 'D':
|
|
264
|
+
{
|
|
265
|
+
this.withMinMaxConstraint(value, () => increment ? value.addDays(1) : value.subtractDays(1));
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case 'H':
|
|
269
|
+
{
|
|
270
|
+
this.withMinMaxConstraint(value, () => increment ? value.addHours(1) : value.subtractHours(1));
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case 'm':
|
|
274
|
+
{
|
|
275
|
+
this.withMinMaxConstraint(value, () => increment ? value.addMinutes(1) : value.subtractMinutes(1));
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
DateTimeInputHandlerSADirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: DateTimeInputHandlerSADirective, deps: [{ token: DATE_TIME_INPUT }, { token: DATE_API }, { token: i1.DateTimeSADirective }, { token: i2.DatePositionParserService }, { token: i2.DateValueProvider }, { token: i1.DateTimePickerSADirective, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
|
|
282
|
+
DateTimeInputHandlerSADirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.4", type: DateTimeInputHandlerSADirective, isStandalone: true, selector: "[dateTime][withHandler]", ngImport: i0 });
|
|
283
|
+
__decorate([
|
|
284
|
+
BindThis,
|
|
285
|
+
__metadata("design:type", Function),
|
|
286
|
+
__metadata("design:paramtypes", []),
|
|
287
|
+
__metadata("design:returntype", void 0)
|
|
288
|
+
], DateTimeInputHandlerSADirective.prototype, "handleSelect", null);
|
|
289
|
+
__decorate([
|
|
290
|
+
BindThis,
|
|
291
|
+
__metadata("design:type", Function),
|
|
292
|
+
__metadata("design:paramtypes", []),
|
|
293
|
+
__metadata("design:returntype", void 0)
|
|
294
|
+
], DateTimeInputHandlerSADirective.prototype, "handleClick", null);
|
|
295
|
+
__decorate([
|
|
296
|
+
BindThis,
|
|
297
|
+
__metadata("design:type", Function),
|
|
298
|
+
__metadata("design:paramtypes", [KeyboardEvent]),
|
|
299
|
+
__metadata("design:returntype", void 0)
|
|
300
|
+
], DateTimeInputHandlerSADirective.prototype, "handleKeypress", null);
|
|
301
|
+
__decorate([
|
|
302
|
+
BindThis,
|
|
303
|
+
__metadata("design:type", Function),
|
|
304
|
+
__metadata("design:paramtypes", [KeyboardEvent]),
|
|
305
|
+
__metadata("design:returntype", void 0)
|
|
306
|
+
], DateTimeInputHandlerSADirective.prototype, "handleKeyboard", null);
|
|
307
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: DateTimeInputHandlerSADirective, decorators: [{
|
|
308
|
+
type: Directive,
|
|
309
|
+
args: [{
|
|
310
|
+
selector: '[dateTime][withHandler]',
|
|
311
|
+
standalone: true,
|
|
312
|
+
}]
|
|
313
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
314
|
+
type: Inject,
|
|
315
|
+
args: [DATE_TIME_INPUT]
|
|
316
|
+
}] }, { type: undefined, decorators: [{
|
|
317
|
+
type: Inject,
|
|
318
|
+
args: [DATE_API]
|
|
319
|
+
}] }, { type: i1.DateTimeSADirective }, { type: i2.DatePositionParserService }, { type: i2.DateValueProvider }, { type: i1.DateTimePickerSADirective, decorators: [{
|
|
320
|
+
type: Optional
|
|
321
|
+
}] }]; }, propDecorators: { handleSelect: [], handleClick: [], handleKeypress: [], handleKeyboard: [] } });
|
|
322
|
+
//# sourceMappingURL=dateTimeInputHandler.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeInputHandler.directive.js","sourceRoot":"","sources":["../../../../src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAqB,QAAQ,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAU,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,MAAM,CAAC;AAGlC,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAC,yBAAyB,EAAE,mBAAmB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAA6C,yBAAyB,EAAE,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;;;;AAExH;;GAEG;AAMH,MAAM,OAAO,+BAA+B;IA2BxC,iEAAiE;IACjE,YAA+C,KAA2B,EAClC,OAAuB,EACzC,YAAwC,EACxC,SAAoC,EACpC,aAAuC,EAC3B,MAAyC;QAL5B,UAAK,GAAL,KAAK,CAAsB;QAClC,YAAO,GAAP,OAAO,CAAgB;QACzC,iBAAY,GAAZ,YAAY,CAA4B;QACxC,cAAS,GAAT,SAAS,CAA2B;QACpC,kBAAa,GAAb,aAAa,CAA0B;QAC3B,WAAM,GAAN,MAAM,CAAmC;QA/B3E,0EAA0E;QAE1E;;WAEG;QACO,sBAAiB,GAAiB,IAAI,YAAY,EAAE,CAAC;QA4B3D,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACrE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,C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KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;oBAEnG,MAAM;iBACT;SACJ;IACL,CAAC;;4HA1WQ,+BAA+B,kBA4BpB,eAAe,aACf,QAAQ;gHA7BnB,+BAA+B;AAuExC;IAAC,QAAQ;;;;mEAkBR;AAKD;IAAC,QAAQ;;;;kEAcR;AAMD;IAAC,QAAQ;;qCACuB,aAAa;;qEAwB5C;AAMD;IAAC,QAAQ;;qCACuB,aAAa;;qEA+F5C;2FAjPQ,+BAA+B;kBAL3C,SAAS;mBACV;oBACI,QAAQ,EAAE,yBAAyB;oBACnC,UAAU,EAAE,IAAI;iBACnB;;0BA6BgB,MAAM;2BAAC,eAAe;;0BACtB,MAAM;2BAAC,QAAQ;;0BAIf,QAAQ;4CAuCX,YAAY,MAuBZ,WAAW,MAoBX,cAAc,MA+Bd,cAAc","sourcesContent":["import {Directive, Inject, OnDestroy, OnInit, Optional} from '@angular/core';\nimport {Action1, BindThis} from '@jscrpt/common';\nimport {Subscription} from 'rxjs';\n\nimport {DateTimeInput} from '../../interfaces';\nimport {DATE_API, DATE_TIME_INPUT} from '../../misc/tokens';\nimport {DateTimeObjectValue} from '../../misc/types';\nimport {parseDateTime, parseRawInput} from '../../misc/utils';\nimport {DateTimePickerSADirective, DateTimeSADirective} from '../../modules';\nimport {DateApi, DateApiObject, DatePositionParser, DatePositionParserService, DateValueProvider} from '../../services';\n\n/**\n * Directive that adds handler for date time input, which allows navigation using keyboard and checking restriction of value\n */\n@Directive(\n{\n selector: '[dateTime][withHandler]',\n standalone: true,\n})\nexport class DateTimeInputHandlerSADirective<TDate = unknown> implements OnInit, OnDestroy\n{\n //######################### protected properties #########################\n\n /**\n * Subscriptions created during initialization\n */\n protected initSubscriptions: Subscription = new Subscription();\n\n /**\n * Instance of parser created for specific format\n */\n protected parser: DatePositionParser;\n\n /**\n * Gets input element as html input\n */\n protected get inputElement(): HTMLInputElement\n {\n if(this.input.element.nodeName == 'INPUT')\n {\n return this.input.element as HTMLInputElement;\n }\n\n throw new Error('You cant use DateTimeInputHandlerSADirective without input element!');\n }\n\n //######################### constructor #########################\n constructor(@Inject(DATE_TIME_INPUT) protected input: DateTimeInput<TDate>,\n @Inject(DATE_API) protected dateApi: DateApi<TDate>,\n protected dateTimeData: DateTimeSADirective<TDate>,\n protected parserSvc: DatePositionParserService,\n protected valueProvider: DateValueProvider<TDate>,\n @Optional() protected picker?: DateTimePickerSADirective<TDate>,)\n {\n this.parser = parserSvc.createParser(this.dateTimeData.customFormat);\n this.initSubscriptions.add(this.dateTimeData.customFormatChanges.subscribe(() => this.parser = parserSvc.createParser(this.dateTimeData.customFormat)));\n }\n\n //######################### public methods - implementation of OnInit #########################\n \n /**\n * Initialize component\n */\n public ngOnInit(): void\n {\n this.input.element.addEventListener('keydown', this.handleKeyboard);\n this.input.element.addEventListener('keypress', this.handleKeypress);\n this.input.element.addEventListener('select', this.handleSelect);\n this.input.element.addEventListener('click', this.handleClick);\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.initSubscriptions.unsubscribe();\n this.input.element.removeEventListener('keydown', this.handleKeyboard);\n this.input.element.removeEventListener('keypress', this.handleKeypress);\n this.input.element.removeEventListener('select', this.handleSelect);\n this.input.element.removeEventListener('click', this.handleClick);\n }\n\n //######################### protected methods #########################\n\n /**\n * Handles selection of text inside of input\n */\n @BindThis\n protected handleSelect(): void\n {\n this.runWithValue(() =>\n {\n //handles when all text is selected\n if(this.inputElement.selectionStart == 0 && this.inputElement.selectionEnd == this.inputElement.value.length)\n {\n const result = this.parser.parse(this.inputElement.value, this.inputElement.selectionStart);\n \n this.inputElement.selectionStart = result.positionFrom;\n this.inputElement.selectionEnd = result.positionTo;\n }\n },\n () =>\n {\n //TODO: add support for ranges\n });\n }\n\n /**\n * Handles click event inside of input\n */\n @BindThis\n protected handleClick(): void\n {\n this.runWithValue(() =>\n {\n const result = this.parser.parse(this.inputElement.value, this.inputElement.selectionStart ?? 0);\n \n this.inputElement.selectionStart = result.positionFrom;\n this.inputElement.selectionEnd = result.positionTo;\n },\n () =>\n {\n //TODO: add support for ranges\n });\n }\n\n /**\n * Handles keyboard events\n * @param event - Keyboard event that occured\n */\n @BindThis\n protected handleKeypress(event: KeyboardEvent): void\n {\n const selectionStart = this.inputElement.selectionStart ?? 0;\n const selectionEnd = this.inputElement.selectionEnd ?? 0;\n const newRawValueArray = this.inputElement.value.split('');\n newRawValueArray.splice(selectionStart , selectionEnd - selectionStart);\n newRawValueArray.splice(selectionStart, 0, ...event.key);\n const newRawValue = newRawValueArray.join('');\n\n const [parsedValue] = parseRawInput(newRawValue, this.dateApi, this.dateTimeData, this.valueProvider);\n\n this.runWithValue(parsedValue =>\n {\n if(this.minMaxConstraintTest(parsedValue))\n {\n event.preventDefault();\n event.stopPropagation();\n }\n },\n () =>\n {\n //TODO: add support for ranges\n },\n parsedValue);\n }\n\n /**\n * Handles keyboard events\n * @param event - Keyboard event that occured\n */\n @BindThis\n protected handleKeyboard(event: KeyboardEvent): void\n {\n this.runWithValue(parsedValue =>\n {\n const selectionStart = this.inputElement.selectionStart ?? 0;\n\n switch(event.key)\n {\n case 'ArrowRight':\n case 'ArrowLeft':\n {\n event.preventDefault();\n event.stopPropagation();\n \n const result = event.key == 'ArrowLeft' ? this.parser.previous(this.inputElement.value, selectionStart) : this.parser.next(this.inputElement.value, selectionStart);\n \n if(result)\n {\n this.inputElement.selectionStart = result.positionFrom;\n this.inputElement.selectionEnd = result.positionTo;\n }\n \n break;\n }\n case 'ArrowUp':\n case 'ArrowDown':\n {\n event.preventDefault();\n event.stopPropagation();\n \n let result = this.parser.parse(this.inputElement.value, selectionStart);\n const selectionStartNew = result.positionFrom;\n \n this.stepChangeValue(parsedValue, result.part, event.key == 'ArrowUp');\n \n result = this.parser.parse(this.inputElement.value, selectionStartNew);\n \n this.inputElement.selectionStart = result.positionFrom;\n this.inputElement.selectionEnd = result.positionTo;\n \n break;\n }\n case 'Tab':\n {\n const result = event.shiftKey ? this.parser.previous(this.inputElement.value, selectionStart) : this.parser.next(this.inputElement.value, selectionStart);\n \n if(result)\n {\n event.preventDefault();\n event.stopPropagation();\n \n this.inputElement.selectionStart = result.positionFrom;\n this.inputElement.selectionEnd = result.positionTo;\n }\n \n break;\n }\n case 'a':\n {\n if(event.ctrlKey)\n {\n event.preventDefault();\n event.stopPropagation();\n }\n \n break;\n }\n case 'Backspace':\n {\n this.input.value = null;\n this.input.valueChange.next();\n \n break;\n }\n case 'Escape':\n {\n this.picker?.hidePicker();\n \n break;\n }\n case ' ':\n {\n if(event.ctrlKey)\n {\n this.picker?.showPicker();\n }\n \n break;\n }\n }\n },\n () =>\n {\n //TODO: add support for ranges\n });\n }\n\n /**\n * Tests whether are min or max constraint broken, returns true if constraint is broken\n * @param value - Value to be tested\n */\n protected minMaxConstraintTest(value: DateApiObject<TDate>): boolean\n {\n return (!!this.dateTimeData.minDateTime && value.isBefore(this.dateTimeData.minDateTime)) ||\n (!!this.dateTimeData.maxDateTime && value.isAfter(this.dateTimeData.maxDateTime));\n }\n\n /**\n * Runs code with check whether min max constrains was broken\n * @param value - Value to be used checked for constrains\n * @param code - Code that should be executed which can change current value\n */\n protected withMinMaxConstraint(value: DateApiObject<TDate>, code: () => void): void\n {\n value.updateOriginal();\n\n code();\n\n //min value constraint failure\n if(this.minMaxConstraintTest(value))\n {\n value.resetOriginal();\n }\n\n //value has changed, change input value\n if(!value.isSame(value.originalValue))\n {\n this.input.value = value.value;\n this.input.valueChange.next();\n }\n }\n\n /**\n * Runs code for existing and valid value of date time\n * @param singleValueCode - Code to be run when only single value can be inside of date time\n * @param rangeValueCode - Code to be run when range value can be inside of date time\n * @param parsedValueDefault - Default parsed value to be used\n */\n protected runWithValue(singleValueCode: Action1<DateApiObject<TDate>>, rangeValueCode: Action1<[DateApiObject<TDate> | null, DateApiObject<TDate> | null]>, parsedValueDefault?: DateTimeObjectValue<TDate>|undefined|null): void\n {\n const parsedValue = parsedValueDefault ?? parseDateTime(this.input.value, this.dateApi, null, this.dateTimeData.customFormat);\n\n if(!parsedValue)\n {\n return;\n }\n\n if(Array.isArray(parsedValue))\n {\n rangeValueCode(parsedValue);\n }\n else\n {\n //do nothing for invalid value\n if(!parsedValue.isValid())\n {\n return;\n }\n\n singleValueCode(parsedValue);\n }\n }\n\n /**\n * Changes current value of date for for specified part by single step\n * @param value - Value to be used checked for constrains\n * @param part - Part of date that should be changed\n * @param increment - Indication whether value should be incremented or decremented\n */\n protected stepChangeValue(value: DateApiObject<TDate>, part: string, increment: boolean): void\n {\n switch(part)\n {\n case 'y':\n case 'Y':\n {\n this.withMinMaxConstraint(value, () => increment ? value.addYears(1) : value.subtractYears(1));\n\n break;\n }\n case 'Q':\n {\n break;\n }\n case 'M':\n {\n this.withMinMaxConstraint(value, () => increment ? value.addMonths(1) : value.subtractMonths(1));\n\n break;\n }\n case 'w':\n {\n this.withMinMaxConstraint(value, () => increment ? value.addWeeks(1) : value.subtractWeeks(1));\n\n break;\n }\n case 'd':\n case 'D':\n {\n this.withMinMaxConstraint(value, () => increment ? value.addDays(1) : value.subtractDays(1));\n\n break;\n }\n case 'H':\n {\n this.withMinMaxConstraint(value, () => increment ? value.addHours(1) : value.subtractHours(1));\n\n break;\n }\n case 'm':\n {\n this.withMinMaxConstraint(value, () => increment ? value.addMinutes(1) : value.subtractMinutes(1));\n\n break;\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Directive } from '@angular/core';
|
|
2
|
+
import { DatePickerInputSADirective } from '../datePickerInput/datePickerInput.directive';
|
|
3
|
+
import { WithTimeSADirective } from '../withTime/withTime.directive';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
import * as i1 from "../datePickerInput/datePickerInput.directive";
|
|
6
|
+
import * as i2 from "../withTime/withTime.directive";
|
|
7
|
+
/**
|
|
8
|
+
* Directive that combines date time picker with date time input
|
|
9
|
+
*/
|
|
10
|
+
export class DateTimePickerInputSADirective {
|
|
11
|
+
}
|
|
12
|
+
DateTimePickerInputSADirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: DateTimePickerInputSADirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
13
|
+
DateTimePickerInputSADirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.4", type: DateTimePickerInputSADirective, isStandalone: true, selector: "input[dateTime][dateTimePickerInput]", hostDirectives: [{ directive: i1.DatePickerInputSADirective }, { directive: i2.WithTimeSADirective }], ngImport: i0 });
|
|
14
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: DateTimePickerInputSADirective, decorators: [{
|
|
15
|
+
type: Directive,
|
|
16
|
+
args: [{
|
|
17
|
+
selector: 'input[dateTime][dateTimePickerInput]',
|
|
18
|
+
standalone: true,
|
|
19
|
+
hostDirectives: [
|
|
20
|
+
{
|
|
21
|
+
directive: DatePickerInputSADirective,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
directive: WithTimeSADirective,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
}]
|
|
28
|
+
}] });
|
|
29
|
+
//# sourceMappingURL=dateTimePickerInput.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimePickerInput.directive.js","sourceRoot":"","sources":["../../../../src/directives/dateTimePickerInput/dateTimePickerInput.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAExC,OAAO,EAAC,0BAA0B,EAAC,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;;;;AAEnE;;GAEG;AAeH,MAAM,OAAO,8BAA8B;;2HAA9B,8BAA8B;+GAA9B,8BAA8B;2FAA9B,8BAA8B;kBAd1C,SAAS;mBACV;oBACI,QAAQ,EAAE,sCAAsC;oBAChD,UAAU,EAAE,IAAI;oBAChB,cAAc,EACd;wBACI;4BACI,SAAS,EAAE,0BAA0B;yBACxC;wBACD;4BACI,SAAS,EAAE,mBAAmB;yBACjC;qBACJ;iBACJ","sourcesContent":["import {Directive} from '@angular/core';\n\nimport {DatePickerInputSADirective} from '../datePickerInput/datePickerInput.directive';\nimport {WithTimeSADirective} from '../withTime/withTime.directive';\n\n/**\n * Directive that combines date time picker with date time input\n */\n@Directive(\n{\n selector: 'input[dateTime][dateTimePickerInput]',\n standalone: true,\n hostDirectives:\n [\n {\n directive: DatePickerInputSADirective,\n },\n {\n directive: WithTimeSADirective,\n },\n ],\n})\nexport class DateTimePickerInputSADirective\n{\n}"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export * from './datePickerInput/datePickerInput.directive';
|
|
2
|
+
export * from './dateTimeInputHandler/dateTimeInputHandler.directive';
|
|
3
|
+
export * from './dateTimePickerInput/dateTimePickerInput.directive';
|
|
1
4
|
export * from './simpleDatePickerInput/simpleDatePickerInput.directive';
|
|
2
5
|
export * from './simpleDateTimeInputHandler/simpleDateTimeInputHandler.directive';
|
|
3
6
|
export * from './simpleDateTimePickerInput/simpleDateTimePickerInput.directive';
|
|
7
|
+
export * from './withNow/withNow.directive';
|
|
4
8
|
export * from './withTime/withTime.directive';
|
|
5
9
|
export * from './withToday/withToday.directive';
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/directives/index.ts"],"names":[],"mappings":"AAAA,cAAc,yDAAyD,CAAC;AACxE,cAAc,mEAAmE,CAAC;AAClF,cAAc,iEAAiE,CAAC;AAChF,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC","sourcesContent":["export * from './simpleDatePickerInput/simpleDatePickerInput.directive';\nexport * from './simpleDateTimeInputHandler/simpleDateTimeInputHandler.directive';\nexport * from './simpleDateTimePickerInput/simpleDateTimePickerInput.directive';\nexport * from './withTime/withTime.directive';\nexport * from './withToday/withToday.directive';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/directives/index.ts"],"names":[],"mappings":"AAAA,cAAc,6CAA6C,CAAC;AAC5D,cAAc,uDAAuD,CAAC;AACtE,cAAc,qDAAqD,CAAC;AACpE,cAAc,yDAAyD,CAAC;AACxE,cAAc,mEAAmE,CAAC;AAClF,cAAc,iEAAiE,CAAC;AAChF,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC","sourcesContent":["export * from './datePickerInput/datePickerInput.directive';\nexport * from './dateTimeInputHandler/dateTimeInputHandler.directive';\nexport * from './dateTimePickerInput/dateTimePickerInput.directive';\nexport * from './simpleDatePickerInput/simpleDatePickerInput.directive';\nexport * from './simpleDateTimeInputHandler/simpleDateTimeInputHandler.directive';\nexport * from './simpleDateTimePickerInput/simpleDateTimePickerInput.directive';\nexport * from './withNow/withNow.directive';\nexport * from './withTime/withTime.directive';\nexport * from './withToday/withToday.directive';\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Directive, Inject } from '@angular/core';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { DATE_API } from '../../misc/tokens';
|
|
4
|
+
import { DateTimeInputSADirective } from '../../modules';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
import * as i1 from "../../modules";
|
|
7
|
+
/**
|
|
8
|
+
* Directive that sets current date and time as day and time for empty date time on focus
|
|
9
|
+
*/
|
|
10
|
+
export class WithNowSADirective {
|
|
11
|
+
//######################### constructor #########################
|
|
12
|
+
constructor(input, dateApi) {
|
|
13
|
+
//######################### protected fields #########################
|
|
14
|
+
/**
|
|
15
|
+
* Subscriptions created during initialization
|
|
16
|
+
*/
|
|
17
|
+
this.initSubscriptions = new Subscription();
|
|
18
|
+
this.initSubscriptions.add(input.focus.subscribe(() => {
|
|
19
|
+
if (!input.value) {
|
|
20
|
+
input.value = dateApi.now().value;
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
//######################### public methods - implementation of OnDestroy #########################
|
|
25
|
+
/**
|
|
26
|
+
* Called when component is destroyed
|
|
27
|
+
*/
|
|
28
|
+
ngOnDestroy() {
|
|
29
|
+
this.initSubscriptions.unsubscribe();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
WithNowSADirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: WithNowSADirective, deps: [{ token: i1.DateTimeInputSADirective }, { token: DATE_API }], target: i0.ɵɵFactoryTarget.Directive });
|
|
33
|
+
WithNowSADirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.4", type: WithNowSADirective, isStandalone: true, selector: "[dateTime][withNow]", ngImport: i0 });
|
|
34
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: WithNowSADirective, decorators: [{
|
|
35
|
+
type: Directive,
|
|
36
|
+
args: [{
|
|
37
|
+
selector: '[dateTime][withNow]',
|
|
38
|
+
standalone: true,
|
|
39
|
+
}]
|
|
40
|
+
}], ctorParameters: function () { return [{ type: i1.DateTimeInputSADirective }, { type: undefined, decorators: [{
|
|
41
|
+
type: Inject,
|
|
42
|
+
args: [DATE_API]
|
|
43
|
+
}] }]; } });
|
|
44
|
+
//# sourceMappingURL=withNow.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withNow.directive.js","sourceRoot":"","sources":["../../../../src/directives/withNow/withNow.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAY,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,MAAM,CAAC;AAElC,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;;;AAGvD;;GAEG;AAMH,MAAM,OAAO,kBAAkB;IAS3B,iEAAiE;IACjE,YAAY,KAAsC,EACpB,OAAuB;QATrD,sEAAsE;QAEtE;;WAEG;QACO,sBAAiB,GAAiB,IAAI,YAAY,EAAE,CAAC;QAM3D,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;YAElD,IAAG,CAAC,KAAK,CAAC,KAAK,EACf;gBACI,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;aACrC;QACL,CAAC,CAAC,CAAC,CAAC;IACR,CAAC;IAED,kGAAkG;IAElG;;OAEG;IACI,WAAW;QAEd,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;;+GA9BQ,kBAAkB,0DAWP,QAAQ;mGAXnB,kBAAkB;2FAAlB,kBAAkB;kBAL9B,SAAS;mBACV;oBACI,QAAQ,EAAE,qBAAqB;oBAC/B,UAAU,EAAE,IAAI;iBACnB;;0BAYgB,MAAM;2BAAC,QAAQ","sourcesContent":["import {Directive, Inject, OnDestroy} from '@angular/core';\nimport {Subscription} from 'rxjs';\n\nimport {DATE_API} from '../../misc/tokens';\nimport {DateTimeInputSADirective} from '../../modules';\nimport {DateApi} from '../../services';\n\n/**\n * Directive that sets current date and time as day and time for empty date time on focus\n */\n@Directive(\n{\n selector: '[dateTime][withNow]',\n standalone: true,\n})\nexport class WithNowSADirective<TDate = unknown> implements OnDestroy\n{\n //######################### protected fields #########################\n\n /**\n * Subscriptions created during initialization\n */\n protected initSubscriptions: Subscription = new Subscription();\n\n //######################### constructor #########################\n constructor(input: DateTimeInputSADirective<TDate>,\n @Inject(DATE_API) dateApi: DateApi<TDate>,)\n {\n this.initSubscriptions.add(input.focus.subscribe(() =>\n {\n if(!input.value)\n {\n input.value = dateApi.now().value;\n }\n }));\n }\n \n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.initSubscriptions.unsubscribe();\n }\n}"]}
|
|
@@ -5,19 +5,19 @@ import { DateTimeInputSADirective } from '../../modules';
|
|
|
5
5
|
import * as i0 from "@angular/core";
|
|
6
6
|
import * as i1 from "../../modules";
|
|
7
7
|
/**
|
|
8
|
-
* Directive that sets today as day for empty date time on focus
|
|
8
|
+
* Directive that sets today (start of a day) as day for empty date time on focus
|
|
9
9
|
*/
|
|
10
10
|
export class WithTodaySADirective {
|
|
11
11
|
//######################### constructor #########################
|
|
12
12
|
constructor(input, dateApi) {
|
|
13
|
-
//#########################
|
|
13
|
+
//######################### protected fields #########################
|
|
14
14
|
/**
|
|
15
15
|
* Subscriptions created during initialization
|
|
16
16
|
*/
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this.initSubscriptions = new Subscription();
|
|
18
|
+
this.initSubscriptions.add(input.focus.subscribe(() => {
|
|
19
19
|
if (!input.value) {
|
|
20
|
-
input.value = dateApi.now().value;
|
|
20
|
+
input.value = dateApi.now().startOfDay().value;
|
|
21
21
|
}
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
@@ -26,7 +26,7 @@ export class WithTodaySADirective {
|
|
|
26
26
|
* Called when component is destroyed
|
|
27
27
|
*/
|
|
28
28
|
ngOnDestroy() {
|
|
29
|
-
this.
|
|
29
|
+
this.initSubscriptions.unsubscribe();
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
WithTodaySADirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: WithTodaySADirective, deps: [{ token: i1.DateTimeInputSADirective }, { token: DATE_API }], target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withToday.directive.js","sourceRoot":"","sources":["../../../../src/directives/withToday/withToday.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAY,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,MAAM,CAAC;AAElC,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;;;AAGvD;;GAEG;AAMH,MAAM,OAAO,oBAAoB;IAS7B,iEAAiE;IACjE,YAAY,KAAsC,EACpB,OAAuB;QATrD,
|
|
1
|
+
{"version":3,"file":"withToday.directive.js","sourceRoot":"","sources":["../../../../src/directives/withToday/withToday.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAY,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,MAAM,CAAC;AAElC,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;;;AAGvD;;GAEG;AAMH,MAAM,OAAO,oBAAoB;IAS7B,iEAAiE;IACjE,YAAY,KAAsC,EACpB,OAAuB;QATrD,sEAAsE;QAEtE;;WAEG;QACO,sBAAiB,GAAiB,IAAI,YAAY,EAAE,CAAC;QAM3D,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;YAElD,IAAG,CAAC,KAAK,CAAC,KAAK,EACf;gBACI,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC;aAClD;QACL,CAAC,CAAC,CAAC,CAAC;IACR,CAAC;IAED,kGAAkG;IAElG;;OAEG;IACI,WAAW;QAEd,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;;iHA9BQ,oBAAoB,0DAWT,QAAQ;qGAXnB,oBAAoB;2FAApB,oBAAoB;kBALhC,SAAS;mBACV;oBACI,QAAQ,EAAE,uBAAuB;oBACjC,UAAU,EAAE,IAAI;iBACnB;;0BAYgB,MAAM;2BAAC,QAAQ","sourcesContent":["import {Directive, Inject, OnDestroy} from '@angular/core';\nimport {Subscription} from 'rxjs';\n\nimport {DATE_API} from '../../misc/tokens';\nimport {DateTimeInputSADirective} from '../../modules';\nimport {DateApi} from '../../services';\n\n/**\n * Directive that sets today (start of a day) as day for empty date time on focus\n */\n@Directive(\n{\n selector: '[dateTime][withToday]',\n standalone: true,\n})\nexport class WithTodaySADirective<TDate = unknown> implements OnDestroy\n{\n //######################### protected fields #########################\n\n /**\n * Subscriptions created during initialization\n */\n protected initSubscriptions: Subscription = new Subscription();\n\n //######################### constructor #########################\n constructor(input: DateTimeInputSADirective<TDate>,\n @Inject(DATE_API) dateApi: DateApi<TDate>,)\n {\n this.initSubscriptions.add(input.focus.subscribe(() =>\n {\n if(!input.value)\n {\n input.value = dateApi.now().startOfDay().value;\n }\n }));\n }\n \n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.initSubscriptions.unsubscribe();\n }\n}"]}
|
package/es2020/src/misc/utils.js
CHANGED
|
@@ -108,4 +108,56 @@ export function getSingleDateTimeValue(value) {
|
|
|
108
108
|
}
|
|
109
109
|
return value;
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Parses raw value into internal value and value
|
|
113
|
+
* @param rawValue - Raw value to be parsed
|
|
114
|
+
* @param dateApi - Date api for manipulation with date
|
|
115
|
+
* @param dateTimeData - Object storing information about format
|
|
116
|
+
* @param valueProvider - Provider used for obtaining rounded value according format
|
|
117
|
+
*/
|
|
118
|
+
export function parseRawInput(rawValue, dateApi, dateTimeData, valueProvider) {
|
|
119
|
+
if (!rawValue) {
|
|
120
|
+
return [null, null];
|
|
121
|
+
}
|
|
122
|
+
const internalValue = getInternalValue(rawValue, dateApi, dateTimeData, valueProvider);
|
|
123
|
+
const value = formatDateTime(internalValue, dateTimeData.valueFormat, dateTimeData.customFormat);
|
|
124
|
+
return [internalValue, value];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets internal value and fix lowest time difference
|
|
128
|
+
* @param value - Value to be get as internal value
|
|
129
|
+
* @param dateApi - Date api for manipulation with date
|
|
130
|
+
* @param dateTimeData - Object storing information about format
|
|
131
|
+
* @param valueProvider - Provider used for obtaining rounded value according format
|
|
132
|
+
*/
|
|
133
|
+
export function getInternalValue(value, dateApi, dateTimeData, valueProvider) {
|
|
134
|
+
let internalValue = parseDateTime(value, dateApi, null, dateTimeData.customFormat);
|
|
135
|
+
if (isBlank(internalValue)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
//update for specified format, round value
|
|
139
|
+
//ranged value
|
|
140
|
+
if (Array.isArray(internalValue)) {
|
|
141
|
+
const [from, to] = internalValue;
|
|
142
|
+
if (from) {
|
|
143
|
+
const val = valueProvider.getValue(from.value, dateTimeData.customFormat).from;
|
|
144
|
+
if (val) {
|
|
145
|
+
internalValue[0] = dateApi.getValue(val, dateTimeData.customFormat);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (to) {
|
|
149
|
+
const val = valueProvider.getValue(to.value, dateTimeData.customFormat).to;
|
|
150
|
+
if (val) {
|
|
151
|
+
internalValue[1] = dateApi.getValue(val, dateTimeData.customFormat);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const val = valueProvider.getValue(internalValue.value, dateTimeData.customFormat).from;
|
|
157
|
+
if (val) {
|
|
158
|
+
internalValue = dateApi.getValue(val, dateTimeData.customFormat);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return internalValue;
|
|
162
|
+
}
|
|
111
163
|
//# sourceMappingURL=utils.js.map
|