@ev-core/aurelia-v1-flatpickr 0.6.5 → 2.0.0
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/dist/commonjs/attributes/flatpickr.d.ts +8 -23
- package/dist/commonjs/attributes/flatpickr.js +33 -135
- package/dist/commonjs/attributes/flatpickr.js.map +1 -1
- package/dist/native-modules/attributes/flatpickr.d.ts +8 -23
- package/dist/native-modules/attributes/flatpickr.js +35 -137
- package/dist/native-modules/attributes/flatpickr.js.map +1 -1
- package/package.json +7 -6
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import { BindingEngine } from
|
|
2
|
-
import '
|
|
3
|
-
import { Instance
|
|
4
|
-
|
|
5
|
-
export interface Instance extends FPInstance {
|
|
6
|
-
}
|
|
7
|
-
export interface Options extends FPOptions {
|
|
8
|
-
}
|
|
9
|
-
import { DateParseValues } from "@ev-core/core";
|
|
10
|
-
export interface IOptions extends Options {
|
|
11
|
-
}
|
|
1
|
+
import { BindingEngine } from 'aurelia-framework';
|
|
2
|
+
import { DateParseValues } from '@ev-core/core';
|
|
3
|
+
import { DatepickerType, Instance, Options } from '@ev-core/au-core-flatpickr';
|
|
4
|
+
export type { DatepickerType, IOptions, Instance, Options } from '@ev-core/au-core-flatpickr';
|
|
12
5
|
export declare class FlatpickrCustomAttribute {
|
|
13
6
|
private readonly element;
|
|
14
7
|
private readonly _be;
|
|
8
|
+
private readonly host;
|
|
15
9
|
minDate?: DateParseValues;
|
|
16
10
|
maxDate?: DateParseValues;
|
|
17
|
-
private resetPicker;
|
|
18
|
-
rangeElement: HTMLInputElement;
|
|
19
11
|
dateFormat: string;
|
|
20
12
|
use24H: boolean;
|
|
21
13
|
locale: string;
|
|
22
14
|
el: Instance;
|
|
23
15
|
value: Date | string;
|
|
24
|
-
valueChanged(date: Date, prevDate?: Date): void;
|
|
25
16
|
rangeValue: Date | string;
|
|
26
17
|
options: Options;
|
|
27
18
|
rangeElementId: string;
|
|
@@ -29,8 +20,7 @@ export declare class FlatpickrCustomAttribute {
|
|
|
29
20
|
private onChange;
|
|
30
21
|
private onClose;
|
|
31
22
|
type: DatepickerType;
|
|
32
|
-
|
|
33
|
-
refresh(): void;
|
|
23
|
+
valueChanged(date: Date): void;
|
|
34
24
|
constructor(element: HTMLInputElement, _be: BindingEngine);
|
|
35
25
|
private _refreshSubscribers;
|
|
36
26
|
setupSubscribers(): void;
|
|
@@ -40,12 +30,7 @@ export declare class FlatpickrCustomAttribute {
|
|
|
40
30
|
attached(): void;
|
|
41
31
|
destroy(): void;
|
|
42
32
|
detached(): void;
|
|
43
|
-
|
|
44
|
-
getTypeOptions(type: DatepickerType): Options;
|
|
45
|
-
buildOptions(o?: Options): Options;
|
|
46
|
-
init(o?: Options): void;
|
|
47
|
-
getDateStr(date: Date): string;
|
|
33
|
+
refresh(): void;
|
|
48
34
|
reset(o: Options): void;
|
|
35
|
+
private hostConfig;
|
|
49
36
|
}
|
|
50
|
-
type DatepickerType = 'date' | 'date-time' | 'time';
|
|
51
|
-
export {};
|
|
@@ -3,34 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FlatpickrCustomAttribute = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const aurelia_framework_1 = require("aurelia-framework");
|
|
6
|
-
const flatpickr_1 = tslib_1.__importDefault(require("flatpickr"));
|
|
7
|
-
const rangePlugin_1 = tslib_1.__importDefault(require("flatpickr/dist/plugins/rangePlugin"));
|
|
8
|
-
require("flatpickr/dist/l10n/no");
|
|
9
6
|
const core_1 = require("@ev-core/core");
|
|
10
|
-
const
|
|
11
|
-
locale: 'no',
|
|
12
|
-
time_24hr: true,
|
|
13
|
-
dateFormat: 'Y.m.d H:i',
|
|
14
|
-
weekNumbers: true,
|
|
15
|
-
closeOnSelect: true,
|
|
16
|
-
};
|
|
17
|
-
const dateTimeOptions = {
|
|
18
|
-
enableTime: true,
|
|
19
|
-
noCalendar: false,
|
|
20
|
-
time_24hr: true,
|
|
21
|
-
dateFormat: 'Y.m.d H:i'
|
|
22
|
-
};
|
|
23
|
-
const dateOpts = {
|
|
24
|
-
enableTime: false,
|
|
25
|
-
noCalendar: false,
|
|
26
|
-
dateFormat: 'Y.m.d'
|
|
27
|
-
};
|
|
28
|
-
const timeOptions = {
|
|
29
|
-
enableTime: true,
|
|
30
|
-
noCalendar: true,
|
|
31
|
-
time_24hr: true,
|
|
32
|
-
dateFormat: 'H.i'
|
|
33
|
-
};
|
|
7
|
+
const au_core_flatpickr_1 = require("@ev-core/au-core-flatpickr");
|
|
34
8
|
const observedPropKeys = [
|
|
35
9
|
(0, core_1.nameof)(e => e.type),
|
|
36
10
|
(0, core_1.nameof)(e => e.dateFormat),
|
|
@@ -41,35 +15,13 @@ const observedPropKeys = [
|
|
|
41
15
|
(0, core_1.nameof)(e => e.options),
|
|
42
16
|
];
|
|
43
17
|
let FlatpickrCustomAttribute = class FlatpickrCustomAttribute {
|
|
44
|
-
valueChanged(date
|
|
45
|
-
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const isSetByPicker = this.el.selectedDates?.some(e => e == date) ?? false;
|
|
49
|
-
if (isSetByPicker) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this.el.setDate(date);
|
|
53
|
-
this.el.jumpToDate(date);
|
|
54
|
-
}
|
|
55
|
-
refresh() {
|
|
56
|
-
aurelia_framework_1.PLATFORM.global.clearTimeout(this.refreshTimer);
|
|
57
|
-
this.refreshTimer = aurelia_framework_1.PLATFORM.global.setTimeout(() => {
|
|
58
|
-
const opts = this.buildOptions(this.options);
|
|
59
|
-
this.el.set(opts);
|
|
60
|
-
if (this.type === 'date') {
|
|
61
|
-
const currentDate = typeof (this.value) === 'string' ? new Date(this.value) : this.value;
|
|
62
|
-
if (currentDate instanceof Date) {
|
|
63
|
-
currentDate.setHours(0, 0, 0, 0);
|
|
64
|
-
}
|
|
65
|
-
this.el.setDate(currentDate);
|
|
66
|
-
}
|
|
67
|
-
}, 10);
|
|
18
|
+
valueChanged(date) {
|
|
19
|
+
this.host.applyExternalDate(date);
|
|
68
20
|
}
|
|
69
21
|
constructor(element, _be) {
|
|
70
22
|
this.element = element;
|
|
71
23
|
this._be = _be;
|
|
72
|
-
this.
|
|
24
|
+
this.host = new au_core_flatpickr_1.FlatpickrHost();
|
|
73
25
|
this.use24H = true;
|
|
74
26
|
this.locale = 'no';
|
|
75
27
|
this.type = 'date-time';
|
|
@@ -77,7 +29,7 @@ let FlatpickrCustomAttribute = class FlatpickrCustomAttribute {
|
|
|
77
29
|
}
|
|
78
30
|
setupSubscribers() {
|
|
79
31
|
this._refreshSubscribers = observedPropKeys.map(key => {
|
|
80
|
-
return this._be.propertyObserver(this, key).subscribe((
|
|
32
|
+
return this._be.propertyObserver(this, key).subscribe(() => {
|
|
81
33
|
this.refresh();
|
|
82
34
|
});
|
|
83
35
|
});
|
|
@@ -91,101 +43,47 @@ let FlatpickrCustomAttribute = class FlatpickrCustomAttribute {
|
|
|
91
43
|
this.disposeSubscribers();
|
|
92
44
|
}
|
|
93
45
|
attached() {
|
|
94
|
-
this.init();
|
|
46
|
+
this.el = this.host.init(this.element, this.hostConfig());
|
|
95
47
|
this.setupSubscribers();
|
|
96
48
|
}
|
|
97
49
|
destroy() {
|
|
98
50
|
this.unbind();
|
|
99
|
-
this.
|
|
51
|
+
this.host.destroy();
|
|
100
52
|
}
|
|
101
53
|
detached() {
|
|
102
54
|
this.destroy();
|
|
103
55
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
let value = sliced[0];
|
|
107
|
-
if (!this.el.config.enableTime && value instanceof Date) {
|
|
108
|
-
value.setHours(this.el.config.defaultHour);
|
|
109
|
-
}
|
|
110
|
-
this.value = value;
|
|
111
|
-
this.element.value = this.value ? this.getDateStr(this.value) : '';
|
|
112
|
-
if (sliced.length > 1) {
|
|
113
|
-
this.rangeValue = sliced[1];
|
|
114
|
-
if (this.rangeElement)
|
|
115
|
-
this.rangeElement.value = this.getDateStr(this.rangeValue);
|
|
116
|
-
}
|
|
117
|
-
if (this.onUpdate) {
|
|
118
|
-
aurelia_framework_1.PLATFORM.global.setTimeout(() => { this.onUpdate({ value }); }, 0);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
getTypeOptions(type) {
|
|
122
|
-
switch (type) {
|
|
123
|
-
case 'date':
|
|
124
|
-
return dateOpts;
|
|
125
|
-
case 'date-time':
|
|
126
|
-
return dateTimeOptions;
|
|
127
|
-
case 'time':
|
|
128
|
-
return timeOptions;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
buildOptions(o) {
|
|
132
|
-
let opts = Object.assign({}, defaultOpts, this.options ?? {}, this.getTypeOptions(this.type));
|
|
133
|
-
if (this.locale) {
|
|
134
|
-
opts.locale = this.locale;
|
|
135
|
-
}
|
|
136
|
-
if (this.dateFormat) {
|
|
137
|
-
opts.dateFormat = this.dateFormat;
|
|
138
|
-
}
|
|
139
|
-
opts.time_24hr = this.use24H;
|
|
140
|
-
if (this.minDate) {
|
|
141
|
-
opts.minDate = (0, core_1.dateParse)(this.minDate);
|
|
142
|
-
}
|
|
143
|
-
if (this.maxDate) {
|
|
144
|
-
opts.maxDate = (0, core_1.dateParse)(this.maxDate);
|
|
145
|
-
}
|
|
146
|
-
console.log(opts);
|
|
147
|
-
console.log(this);
|
|
148
|
-
return opts;
|
|
149
|
-
}
|
|
150
|
-
init(o) {
|
|
151
|
-
let opts = this.buildOptions(o);
|
|
152
|
-
if (this.value) {
|
|
153
|
-
opts.defaultDate = [this.value, this.rangeValue]
|
|
154
|
-
.filter(e => e)
|
|
155
|
-
.map(e => typeof (e) === 'string' ? new Date(e) : e);
|
|
156
|
-
}
|
|
157
|
-
opts.onClose = (dates, currentDateString, instance, data) => {
|
|
158
|
-
if (this.onClose) {
|
|
159
|
-
this.onClose({ dates, currentDateString, instance, data });
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
opts.onValueUpdate = (dates, currentDateString, instance, data) => {
|
|
163
|
-
this.setDates(dates, currentDateString, instance, data);
|
|
164
|
-
};
|
|
165
|
-
opts.onChange = (dates, currentDateString, instance, data) => {
|
|
166
|
-
if (this.onChange) {
|
|
167
|
-
this.onChange({ dates, currentDateString, instance, data });
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
opts.plugins = [];
|
|
171
|
-
if (this.rangeElementId) {
|
|
172
|
-
this.rangeElement = aurelia_framework_1.DOM.getElementById(this.rangeElementId);
|
|
173
|
-
if (this.rangeElement) {
|
|
174
|
-
opts.mode = 'range';
|
|
175
|
-
}
|
|
176
|
-
opts.plugins.push((0, rangePlugin_1.default)({ input: this.rangeElement }));
|
|
177
|
-
}
|
|
178
|
-
this.el = (0, flatpickr_1.default)(this.element, opts);
|
|
179
|
-
}
|
|
180
|
-
getDateStr(date) {
|
|
181
|
-
const self = this.el;
|
|
182
|
-
return self.formatDate(date, self.config.dateFormat);
|
|
56
|
+
refresh() {
|
|
57
|
+
this.host.refresh(this.hostConfig());
|
|
183
58
|
}
|
|
184
59
|
reset(o) {
|
|
185
60
|
this.destroy();
|
|
186
|
-
this.init(o);
|
|
61
|
+
this.el = this.host.init(this.element, { ...this.hostConfig(), options: o });
|
|
187
62
|
this.el.redraw();
|
|
188
63
|
}
|
|
64
|
+
hostConfig() {
|
|
65
|
+
return {
|
|
66
|
+
type: this.type,
|
|
67
|
+
options: this.options,
|
|
68
|
+
locale: this.locale,
|
|
69
|
+
dateFormat: this.dateFormat,
|
|
70
|
+
use24H: this.use24H,
|
|
71
|
+
minDate: this.minDate,
|
|
72
|
+
maxDate: this.maxDate,
|
|
73
|
+
value: this.value,
|
|
74
|
+
rangeValue: this.rangeValue,
|
|
75
|
+
rangeElementId: this.rangeElementId,
|
|
76
|
+
onClose: this.onClose,
|
|
77
|
+
onChange: this.onChange,
|
|
78
|
+
onUpdate: this.onUpdate,
|
|
79
|
+
onDates: ({ value, rangeValue }) => {
|
|
80
|
+
this.value = value;
|
|
81
|
+
if (rangeValue !== undefined) {
|
|
82
|
+
this.rangeValue = rangeValue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
189
87
|
};
|
|
190
88
|
exports.FlatpickrCustomAttribute = FlatpickrCustomAttribute;
|
|
191
89
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/attributes/flatpickr.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../src/attributes/flatpickr.ts"],"names":[],"mappings":";;;;AAAA,yDAAmH;AACnH,wCAAwD;AACxD,kEAMoC;AAIpC,MAAM,gBAAgB,GAAG;IACrB,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACnD,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/C,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/C,IAAA,aAAM,EAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;CACnD,CAAC;AAIK,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAkBjC,YAAY,CAAC,IAAU;QACnB,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,YACqB,OAAyB,EACzB,GAAkB;QADlB,YAAO,GAAP,OAAO,CAAkB;QACzB,QAAG,GAAH,GAAG,CAAe;QAvBtB,SAAI,GAAG,IAAI,iCAAa,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;AAC3D;IAAT,4BAAQ;;uDAAsB;AACrB;IAAT,4BAAQ;;4DAA2B;AAC1B;IAAT,4BAAQ;;yDAAkB;AACjB;IAAT,4BAAQ;;gEAAwB;AACf;IAAjB,4BAAQ;;0DAA8D;AACrD;IAAjB,4BAAQ;;0DAA+C;AACtC;IAAjB,4BAAQ;;yDAA8C;AAC7C;IAAT,4BAAQ;;sDAAoC;mCAhBpC,wBAAwB;IAFpC,IAAA,mCAAe,EAAC,YAAY,CAAC;IAC7B,IAAA,0BAAM,EAAC,uBAAG,CAAC,OAAO,EAAE,iCAAa,CAAC;6CAwBD,gBAAgB;QACpB,iCAAa;GAxB9B,wBAAwB,CA6FpC","file":"flatpickr.js","sourceRoot":"../../../src/"}
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import { BindingEngine } from
|
|
2
|
-
import '
|
|
3
|
-
import { Instance
|
|
4
|
-
|
|
5
|
-
export interface Instance extends FPInstance {
|
|
6
|
-
}
|
|
7
|
-
export interface Options extends FPOptions {
|
|
8
|
-
}
|
|
9
|
-
import { DateParseValues } from "@ev-core/core";
|
|
10
|
-
export interface IOptions extends Options {
|
|
11
|
-
}
|
|
1
|
+
import { BindingEngine } from 'aurelia-framework';
|
|
2
|
+
import { DateParseValues } from '@ev-core/core';
|
|
3
|
+
import { DatepickerType, Instance, Options } from '@ev-core/au-core-flatpickr';
|
|
4
|
+
export type { DatepickerType, IOptions, Instance, Options } from '@ev-core/au-core-flatpickr';
|
|
12
5
|
export declare class FlatpickrCustomAttribute {
|
|
13
6
|
private readonly element;
|
|
14
7
|
private readonly _be;
|
|
8
|
+
private readonly host;
|
|
15
9
|
minDate?: DateParseValues;
|
|
16
10
|
maxDate?: DateParseValues;
|
|
17
|
-
private resetPicker;
|
|
18
|
-
rangeElement: HTMLInputElement;
|
|
19
11
|
dateFormat: string;
|
|
20
12
|
use24H: boolean;
|
|
21
13
|
locale: string;
|
|
22
14
|
el: Instance;
|
|
23
15
|
value: Date | string;
|
|
24
|
-
valueChanged(date: Date, prevDate?: Date): void;
|
|
25
16
|
rangeValue: Date | string;
|
|
26
17
|
options: Options;
|
|
27
18
|
rangeElementId: string;
|
|
@@ -29,8 +20,7 @@ export declare class FlatpickrCustomAttribute {
|
|
|
29
20
|
private onChange;
|
|
30
21
|
private onClose;
|
|
31
22
|
type: DatepickerType;
|
|
32
|
-
|
|
33
|
-
refresh(): void;
|
|
23
|
+
valueChanged(date: Date): void;
|
|
34
24
|
constructor(element: HTMLInputElement, _be: BindingEngine);
|
|
35
25
|
private _refreshSubscribers;
|
|
36
26
|
setupSubscribers(): void;
|
|
@@ -40,12 +30,7 @@ export declare class FlatpickrCustomAttribute {
|
|
|
40
30
|
attached(): void;
|
|
41
31
|
destroy(): void;
|
|
42
32
|
detached(): void;
|
|
43
|
-
|
|
44
|
-
getTypeOptions(type: DatepickerType): Options;
|
|
45
|
-
buildOptions(o?: Options): Options;
|
|
46
|
-
init(o?: Options): void;
|
|
47
|
-
getDateStr(date: Date): string;
|
|
33
|
+
refresh(): void;
|
|
48
34
|
reset(o: Options): void;
|
|
35
|
+
private hostConfig;
|
|
49
36
|
}
|
|
50
|
-
type DatepickerType = 'date' | 'date-time' | 'time';
|
|
51
|
-
export {};
|
|
@@ -1,33 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { inject, DOM, bindable, bindingMode, customAttribute,
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import 'flatpickr/dist/l10n/no';
|
|
6
|
-
import { dateParse, nameof } from "@ev-core/core";
|
|
7
|
-
const defaultOpts = {
|
|
8
|
-
locale: 'no',
|
|
9
|
-
time_24hr: true,
|
|
10
|
-
dateFormat: 'Y.m.d H:i',
|
|
11
|
-
weekNumbers: true,
|
|
12
|
-
closeOnSelect: true,
|
|
13
|
-
};
|
|
14
|
-
const dateTimeOptions = {
|
|
15
|
-
enableTime: true,
|
|
16
|
-
noCalendar: false,
|
|
17
|
-
time_24hr: true,
|
|
18
|
-
dateFormat: 'Y.m.d H:i'
|
|
19
|
-
};
|
|
20
|
-
const dateOpts = {
|
|
21
|
-
enableTime: false,
|
|
22
|
-
noCalendar: false,
|
|
23
|
-
dateFormat: 'Y.m.d'
|
|
24
|
-
};
|
|
25
|
-
const timeOptions = {
|
|
26
|
-
enableTime: true,
|
|
27
|
-
noCalendar: true,
|
|
28
|
-
time_24hr: true,
|
|
29
|
-
dateFormat: 'H.i'
|
|
30
|
-
};
|
|
2
|
+
import { inject, DOM, bindable, bindingMode, customAttribute, BindingEngine } from 'aurelia-framework';
|
|
3
|
+
import { nameof } from '@ev-core/core';
|
|
4
|
+
import { FlatpickrHost } from '@ev-core/au-core-flatpickr';
|
|
31
5
|
const observedPropKeys = [
|
|
32
6
|
nameof(e => e.type),
|
|
33
7
|
nameof(e => e.dateFormat),
|
|
@@ -38,35 +12,13 @@ const observedPropKeys = [
|
|
|
38
12
|
nameof(e => e.options),
|
|
39
13
|
];
|
|
40
14
|
let FlatpickrCustomAttribute = class FlatpickrCustomAttribute {
|
|
41
|
-
valueChanged(date
|
|
42
|
-
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const isSetByPicker = this.el.selectedDates?.some(e => e == date) ?? false;
|
|
46
|
-
if (isSetByPicker) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this.el.setDate(date);
|
|
50
|
-
this.el.jumpToDate(date);
|
|
51
|
-
}
|
|
52
|
-
refresh() {
|
|
53
|
-
PLATFORM.global.clearTimeout(this.refreshTimer);
|
|
54
|
-
this.refreshTimer = PLATFORM.global.setTimeout(() => {
|
|
55
|
-
const opts = this.buildOptions(this.options);
|
|
56
|
-
this.el.set(opts);
|
|
57
|
-
if (this.type === 'date') {
|
|
58
|
-
const currentDate = typeof (this.value) === 'string' ? new Date(this.value) : this.value;
|
|
59
|
-
if (currentDate instanceof Date) {
|
|
60
|
-
currentDate.setHours(0, 0, 0, 0);
|
|
61
|
-
}
|
|
62
|
-
this.el.setDate(currentDate);
|
|
63
|
-
}
|
|
64
|
-
}, 10);
|
|
15
|
+
valueChanged(date) {
|
|
16
|
+
this.host.applyExternalDate(date);
|
|
65
17
|
}
|
|
66
18
|
constructor(element, _be) {
|
|
67
19
|
this.element = element;
|
|
68
20
|
this._be = _be;
|
|
69
|
-
this.
|
|
21
|
+
this.host = new FlatpickrHost();
|
|
70
22
|
this.use24H = true;
|
|
71
23
|
this.locale = 'no';
|
|
72
24
|
this.type = 'date-time';
|
|
@@ -74,7 +26,7 @@ let FlatpickrCustomAttribute = class FlatpickrCustomAttribute {
|
|
|
74
26
|
}
|
|
75
27
|
setupSubscribers() {
|
|
76
28
|
this._refreshSubscribers = observedPropKeys.map(key => {
|
|
77
|
-
return this._be.propertyObserver(this, key).subscribe((
|
|
29
|
+
return this._be.propertyObserver(this, key).subscribe(() => {
|
|
78
30
|
this.refresh();
|
|
79
31
|
});
|
|
80
32
|
});
|
|
@@ -88,101 +40,47 @@ let FlatpickrCustomAttribute = class FlatpickrCustomAttribute {
|
|
|
88
40
|
this.disposeSubscribers();
|
|
89
41
|
}
|
|
90
42
|
attached() {
|
|
91
|
-
this.init();
|
|
43
|
+
this.el = this.host.init(this.element, this.hostConfig());
|
|
92
44
|
this.setupSubscribers();
|
|
93
45
|
}
|
|
94
46
|
destroy() {
|
|
95
47
|
this.unbind();
|
|
96
|
-
this.
|
|
48
|
+
this.host.destroy();
|
|
97
49
|
}
|
|
98
50
|
detached() {
|
|
99
51
|
this.destroy();
|
|
100
52
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
let value = sliced[0];
|
|
104
|
-
if (!this.el.config.enableTime && value instanceof Date) {
|
|
105
|
-
value.setHours(this.el.config.defaultHour);
|
|
106
|
-
}
|
|
107
|
-
this.value = value;
|
|
108
|
-
this.element.value = this.value ? this.getDateStr(this.value) : '';
|
|
109
|
-
if (sliced.length > 1) {
|
|
110
|
-
this.rangeValue = sliced[1];
|
|
111
|
-
if (this.rangeElement)
|
|
112
|
-
this.rangeElement.value = this.getDateStr(this.rangeValue);
|
|
113
|
-
}
|
|
114
|
-
if (this.onUpdate) {
|
|
115
|
-
PLATFORM.global.setTimeout(() => { this.onUpdate({ value }); }, 0);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
getTypeOptions(type) {
|
|
119
|
-
switch (type) {
|
|
120
|
-
case 'date':
|
|
121
|
-
return dateOpts;
|
|
122
|
-
case 'date-time':
|
|
123
|
-
return dateTimeOptions;
|
|
124
|
-
case 'time':
|
|
125
|
-
return timeOptions;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
buildOptions(o) {
|
|
129
|
-
let opts = Object.assign({}, defaultOpts, this.options ?? {}, this.getTypeOptions(this.type));
|
|
130
|
-
if (this.locale) {
|
|
131
|
-
opts.locale = this.locale;
|
|
132
|
-
}
|
|
133
|
-
if (this.dateFormat) {
|
|
134
|
-
opts.dateFormat = this.dateFormat;
|
|
135
|
-
}
|
|
136
|
-
opts.time_24hr = this.use24H;
|
|
137
|
-
if (this.minDate) {
|
|
138
|
-
opts.minDate = dateParse(this.minDate);
|
|
139
|
-
}
|
|
140
|
-
if (this.maxDate) {
|
|
141
|
-
opts.maxDate = dateParse(this.maxDate);
|
|
142
|
-
}
|
|
143
|
-
console.log(opts);
|
|
144
|
-
console.log(this);
|
|
145
|
-
return opts;
|
|
146
|
-
}
|
|
147
|
-
init(o) {
|
|
148
|
-
let opts = this.buildOptions(o);
|
|
149
|
-
if (this.value) {
|
|
150
|
-
opts.defaultDate = [this.value, this.rangeValue]
|
|
151
|
-
.filter(e => e)
|
|
152
|
-
.map(e => typeof (e) === 'string' ? new Date(e) : e);
|
|
153
|
-
}
|
|
154
|
-
opts.onClose = (dates, currentDateString, instance, data) => {
|
|
155
|
-
if (this.onClose) {
|
|
156
|
-
this.onClose({ dates, currentDateString, instance, data });
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
opts.onValueUpdate = (dates, currentDateString, instance, data) => {
|
|
160
|
-
this.setDates(dates, currentDateString, instance, data);
|
|
161
|
-
};
|
|
162
|
-
opts.onChange = (dates, currentDateString, instance, data) => {
|
|
163
|
-
if (this.onChange) {
|
|
164
|
-
this.onChange({ dates, currentDateString, instance, data });
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
opts.plugins = [];
|
|
168
|
-
if (this.rangeElementId) {
|
|
169
|
-
this.rangeElement = DOM.getElementById(this.rangeElementId);
|
|
170
|
-
if (this.rangeElement) {
|
|
171
|
-
opts.mode = 'range';
|
|
172
|
-
}
|
|
173
|
-
opts.plugins.push(rangePlugin({ input: this.rangeElement }));
|
|
174
|
-
}
|
|
175
|
-
this.el = flatpickr(this.element, opts);
|
|
176
|
-
}
|
|
177
|
-
getDateStr(date) {
|
|
178
|
-
const self = this.el;
|
|
179
|
-
return self.formatDate(date, self.config.dateFormat);
|
|
53
|
+
refresh() {
|
|
54
|
+
this.host.refresh(this.hostConfig());
|
|
180
55
|
}
|
|
181
56
|
reset(o) {
|
|
182
57
|
this.destroy();
|
|
183
|
-
this.init(o);
|
|
58
|
+
this.el = this.host.init(this.element, { ...this.hostConfig(), options: o });
|
|
184
59
|
this.el.redraw();
|
|
185
60
|
}
|
|
61
|
+
hostConfig() {
|
|
62
|
+
return {
|
|
63
|
+
type: this.type,
|
|
64
|
+
options: this.options,
|
|
65
|
+
locale: this.locale,
|
|
66
|
+
dateFormat: this.dateFormat,
|
|
67
|
+
use24H: this.use24H,
|
|
68
|
+
minDate: this.minDate,
|
|
69
|
+
maxDate: this.maxDate,
|
|
70
|
+
value: this.value,
|
|
71
|
+
rangeValue: this.rangeValue,
|
|
72
|
+
rangeElementId: this.rangeElementId,
|
|
73
|
+
onClose: this.onClose,
|
|
74
|
+
onChange: this.onChange,
|
|
75
|
+
onUpdate: this.onUpdate,
|
|
76
|
+
onDates: ({ value, rangeValue }) => {
|
|
77
|
+
this.value = value;
|
|
78
|
+
if (rangeValue !== undefined) {
|
|
79
|
+
this.rangeValue = rangeValue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
186
84
|
};
|
|
187
85
|
__decorate([
|
|
188
86
|
bindable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/attributes/flatpickr.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/attributes/flatpickr.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAc,MAAM,mBAAmB,CAAC;AACnH,OAAO,EAAmB,MAAM,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAEH,aAAa,EAIhB,MAAM,4BAA4B,CAAC;AAIpC,MAAM,gBAAgB,GAAG;IACrB,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACnD,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/C,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/C,MAAM,CAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;CACnD,CAAC;AAIK,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAkBjC,YAAY,CAAC,IAAU;QACnB,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,YACqB,OAAyB,EACzB,GAAkB;QADlB,YAAO,GAAP,OAAO,CAAkB;QACzB,QAAG,GAAH,GAAG,CAAe;QAvBtB,SAAI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AAT,QAAQ;;uDAAsB;AACrB;IAAT,QAAQ;;4DAA2B;AAC1B;IAAT,QAAQ;;yDAAkB;AACjB;IAAT,QAAQ;;gEAAwB;AACf;IAAjB,QAAQ;;0DAA8D;AACrD;IAAjB,QAAQ;;0DAA+C;AACtC;IAAjB,QAAQ;;yDAA8C;AAC7C;IAAT,QAAQ;;sDAAoC;AAhBpC,wBAAwB;IAFpC,eAAe,CAAC,YAAY,CAAC;IAC7B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC;qCAwBD,gBAAgB;QACpB,aAAa;GAxB9B,wBAAwB,CA6FpC","file":"flatpickr.js","sourceRoot":"../../../src/"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ev-core/aurelia-v1-flatpickr",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "Aurelia v1 Flatpickr attribute plugin.",
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"@ev-core/au-core-flatpickr": "2.0.0",
|
|
7
|
+
"@ev-core/core": "2.0.0",
|
|
8
|
+
"flatpickr": "^4.0.0"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"aurelia-binding": "^1.0.0 || ^2.0.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"server-destroy": "^1.0.1",
|
|
45
45
|
"socket.io": "^4.8.1",
|
|
46
46
|
"text": "requirejs/text",
|
|
47
|
-
"typescript": "^5.9.
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
48
|
"typescript-eslint": "^8.38.0"
|
|
49
49
|
},
|
|
50
50
|
"overrides": {
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"glob-parent": "^6.0.0",
|
|
54
54
|
"micromatch": "^4.0.0"
|
|
55
55
|
},
|
|
56
|
+
"types": "dist/native-modules/index.d.ts",
|
|
56
57
|
"main": "dist/commonjs/index.js",
|
|
57
58
|
"module": "dist/native-modules/index.js",
|
|
58
59
|
"files": [
|