@lemonadejs/calendar 5.2.1 → 5.3.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/index.d.ts CHANGED
@@ -37,7 +37,7 @@ declare namespace Calendar {
37
37
  /** Update view on mouse wheel. Default: true */
38
38
  wheel?: boolean;
39
39
  /** Bind the calendar to na HTML input element */
40
- input?: HTMLElement | 'auto';
40
+ input?: HTMLInputElement | 'auto';
41
41
  /** Create events and assing the calendar classes for the input. Default true */
42
42
  initInput?: boolean;
43
43
  /** Change value event */
package/dist/index.js CHANGED
@@ -51,7 +51,7 @@ if (! Modal && typeof (require) === 'function') {
51
51
  }
52
52
  }
53
53
 
54
- const Helpers = (function() {
54
+ const Helpers = (function () {
55
55
  const component = {};
56
56
 
57
57
  // Excel like dates
@@ -60,22 +60,22 @@ if (! Modal && typeof (require) === 'function') {
60
60
  const millisecondsPerDay = 86400000;
61
61
 
62
62
  // Transform in two digits
63
- component.two = function(value) {
63
+ component.two = function (value) {
64
64
  value = '' + value;
65
65
  if (value.length === 1) {
66
66
  value = '0' + value;
67
67
  }
68
68
  return value;
69
- }
69
+ };
70
70
 
71
- component.isValidDate = function(d) {
71
+ component.isValidDate = function (d) {
72
72
  return d instanceof Date && !isNaN(d.getTime());
73
- }
73
+ };
74
74
 
75
- component.isValidDateFormat = function(date, format) {
75
+ component.isValidDateFormat = function(date) {
76
76
  if (typeof date === 'string') {
77
77
  // Check format: YYYY-MM-DD using regex
78
- const match = date.match(/^(\d{4})-(\d{2})-(\d{2})$/);
78
+ const match = date.substring(0, 10).match(/^(\d{4})-(\d{2})-(\d{2})$/);
79
79
  if (match) {
80
80
  const year = Number(match[1]);
81
81
  const month = Number(match[2]) - 1;
@@ -105,7 +105,7 @@ if (! Modal && typeof (require) === 'function') {
105
105
  i = date[4];
106
106
  s = date[5];
107
107
  } else {
108
- if (! date) {
108
+ if (!date) {
109
109
  date = new Date();
110
110
  }
111
111
  y = date.getUTCFullYear();
@@ -119,12 +119,14 @@ if (! Modal && typeof (require) === 'function') {
119
119
  if (dateOnly === true) {
120
120
  return component.two(y) + '-' + component.two(m) + '-' + component.two(d);
121
121
  } else {
122
- return component.two(y) + '-' + component.two(m) + '-' + component.two(d) + ' ' + component.two(h) + ':' + component.two(i) + ':' + component.two(s);
122
+ return (
123
+ component.two(y) + '-' + component.two(m) + '-' + component.two(d) + ' ' + component.two(h) + ':' + component.two(i) + ':' + component.two(s)
124
+ );
123
125
  }
124
- }
126
+ };
125
127
 
126
128
  component.toArray = function (value) {
127
- let date = value.split(((value.indexOf('T') !== -1) ? 'T' : ' '));
129
+ let date = value.split(value.indexOf('T') !== -1 ? 'T' : ' ');
128
130
  let time = date[1];
129
131
 
130
132
  date = date[0].split('-');
@@ -140,14 +142,14 @@ if (! Modal && typeof (require) === 'function') {
140
142
  i = parseInt(time[1]);
141
143
  }
142
144
  return [y, m, d, h, i, 0];
143
- }
145
+ };
144
146
 
145
- component.arrayToStringDate = function(arr) {
147
+ component.arrayToStringDate = function (arr) {
146
148
  return component.toString(arr, false);
147
- }
149
+ };
148
150
 
149
- component.dateToNum = function(jsDate) {
150
- if (typeof(jsDate) === 'string') {
151
+ component.dateToNum = function (jsDate) {
152
+ if (typeof jsDate === 'string') {
151
153
  jsDate = new Date(jsDate + ' GMT+0');
152
154
  }
153
155
  let jsDateInMilliseconds = jsDate.getTime();
@@ -157,9 +159,9 @@ if (! Modal && typeof (require) === 'function') {
157
159
  jsDateInMilliseconds -= excelInitialTime;
158
160
 
159
161
  return jsDateInMilliseconds / millisecondsPerDay;
160
- }
162
+ };
161
163
 
162
- component.numToDate = function(excelSerialNumber, asArray) {
164
+ component.numToDate = function (excelSerialNumber, asArray) {
163
165
  // allow 0; only bail on null/undefined/empty
164
166
  if (excelSerialNumber === null || excelSerialNumber === undefined || excelSerialNumber === '') {
165
167
  return '';
@@ -196,10 +198,10 @@ if (! Modal && typeof (require) === 'function') {
196
198
  ];
197
199
 
198
200
  return asArray ? arr : component.toString(arr, false);
199
- }
201
+ };
200
202
 
201
203
  component.prettify = function (d, texts) {
202
- if (! texts) {
204
+ if (!texts) {
203
205
  texts = {
204
206
  justNow: 'Just now',
205
207
  xMinutesAgo: '{0}m ago',
@@ -208,7 +210,7 @@ if (! Modal && typeof (require) === 'function') {
208
210
  xWeeksAgo: '{0}w ago',
209
211
  xMonthsAgo: '{0} mon ago',
210
212
  xYearsAgo: '{0}y ago',
211
- }
213
+ };
212
214
  }
213
215
 
214
216
  if (d.indexOf('GMT') === -1 && d.indexOf('Z') === -1) {
@@ -221,24 +223,29 @@ if (! Modal && typeof (require) === 'function') {
221
223
 
222
224
  const format = (t, o) => {
223
225
  return t.replace('{0}', o);
224
- }
226
+ };
225
227
 
226
- if (! total) {
228
+ if (!total) {
227
229
  return texts.justNow;
228
230
  } else if (total < 90) {
229
231
  return format(texts.xMinutesAgo, total);
230
- } else if (total < 1440) { // One day
232
+ } else if (total < 1440) {
233
+ // One day
231
234
  return format(texts.xHoursAgo, Math.round(total / 60));
232
- } else if (total < 20160) { // 14 days
235
+ } else if (total < 20160) {
236
+ // 14 days
233
237
  return format(texts.xDaysAgo, Math.round(total / 1440));
234
- } else if (total < 43200) { // 30 days
238
+ } else if (total < 43200) {
239
+ // 30 days
235
240
  return format(texts.xWeeksAgo, Math.round(total / 10080));
236
- } else if (total < 1036800) { // 24 months
241
+ } else if (total < 1036800) {
242
+ // 24 months
237
243
  return format(texts.xMonthsAgo, Math.round(total / 43200));
238
- } else { // 24 months+
244
+ } else {
245
+ // 24 months+
239
246
  return format(texts.xYearsAgo, Math.round(total / 525600));
240
247
  }
241
- }
248
+ };
242
249
 
243
250
  component.prettifyAll = function () {
244
251
  let elements = document.querySelectorAll('.prettydate');
@@ -253,7 +260,7 @@ if (! Modal && typeof (require) === 'function') {
253
260
  }
254
261
  }
255
262
  }
256
- }
263
+ };
257
264
 
258
265
  // Compatibility with jSuites
259
266
  component.now = component.toString;
@@ -261,17 +268,17 @@ if (! Modal && typeof (require) === 'function') {
261
268
  const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
262
269
  const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
263
270
 
264
- const translate = function(t) {
265
- if (typeof(document) !== "undefined" && document.dictionary) {
271
+ const translate = function (t) {
272
+ if (typeof document !== 'undefined' && document.dictionary) {
266
273
  return document.dictionary[t] || t;
267
274
  } else {
268
275
  return t;
269
276
  }
270
- }
277
+ };
271
278
 
272
279
  Object.defineProperty(component, 'weekdays', {
273
280
  get: function () {
274
- return weekdays.map(function(v) {
281
+ return weekdays.map(function (v) {
275
282
  return translate(v);
276
283
  });
277
284
  },
@@ -279,15 +286,15 @@ if (! Modal && typeof (require) === 'function') {
279
286
 
280
287
  Object.defineProperty(component, 'weekdaysShort', {
281
288
  get: function () {
282
- return weekdays.map(function(v) {
283
- return translate(v).substring(0,3);
289
+ return weekdays.map(function (v) {
290
+ return translate(v).substring(0, 3);
284
291
  });
285
292
  },
286
293
  });
287
294
 
288
295
  Object.defineProperty(component, 'months', {
289
296
  get: function () {
290
- return months.map(function(v) {
297
+ return months.map(function (v) {
291
298
  return translate(v);
292
299
  });
293
300
  },
@@ -295,8 +302,8 @@ if (! Modal && typeof (require) === 'function') {
295
302
 
296
303
  Object.defineProperty(component, 'monthsShort', {
297
304
  get: function () {
298
- return months.map(function(v) {
299
- return translate(v).substring(0,3);
305
+ return months.map(function (v) {
306
+ return translate(v).substring(0, 3);
300
307
  });
301
308
  },
302
309
  });
@@ -2880,6 +2887,9 @@ if (! Modal && typeof (require) === 'function') {
2880
2887
  return Component;
2881
2888
  }());
2882
2889
 
2890
+ // Aditional Helpers
2891
+ Helpers.getDate = Mask.getDate;
2892
+
2883
2893
  const isNumber = function (num) {
2884
2894
  if (typeof(num) === 'string') {
2885
2895
  num = num.trim();
@@ -3154,13 +3164,26 @@ if (! Modal && typeof (require) === 'function') {
3154
3164
  // Update the headers of the calendar
3155
3165
  let value = d.toISOString().substring(0,10).split('-');
3156
3166
  let time = d.toISOString().substring(11,19).split(':');
3157
- // Update the month label
3158
- self.month = Helpers.months[parseInt(value[1])-1];
3159
- // Update the year label
3160
- self.year = parseInt(value[0]);
3161
- // Hour
3162
- self.hour = parseInt(time[0]);
3163
- self.minute = parseInt(time[1]);
3167
+ let month = Helpers.months[parseInt(value[1])-1];
3168
+ let year = parseInt(value[0]);
3169
+ let hour = parseInt(time[0]);
3170
+ let minute = parseInt(time[1]);
3171
+
3172
+ if (self.month !== month) {
3173
+ // Update the month label
3174
+ self.month = month;
3175
+ }
3176
+ if (self.year !== year) {
3177
+ // Update the year label
3178
+ self.year = year;
3179
+
3180
+ }
3181
+ if (self.hour !== hour) {
3182
+ self.hour = hour;
3183
+ }
3184
+ if (self.minute !== minute) {
3185
+ self.minute = minute;
3186
+ }
3164
3187
 
3165
3188
  // Load data
3166
3189
  if (! self.view) {
@@ -3360,7 +3383,7 @@ if (! Modal && typeof (require) === 'function') {
3360
3383
 
3361
3384
  const renderValue = function() {
3362
3385
  let value = null;
3363
- if (self.range) {
3386
+ if (self.range === true) {
3364
3387
  if (Array.isArray(self.rangeValues)) {
3365
3388
  if (self.numeric) {
3366
3389
  value = self.rangeValues;
@@ -3381,7 +3404,7 @@ if (! Modal && typeof (require) === 'function') {
3381
3404
  }
3382
3405
 
3383
3406
  const updateValue = function(v) {
3384
- if (self.range) {
3407
+ if (self.range === true) {
3385
3408
  if (v) {
3386
3409
  if (! Array.isArray(v)) {
3387
3410
  v = v.toString().split(',');
@@ -3441,7 +3464,7 @@ if (! Modal && typeof (require) === 'function') {
3441
3464
  let input = getInput();
3442
3465
  let value = self.value;
3443
3466
  if (input) {
3444
- let v;
3467
+ let v = value;
3445
3468
  if (input.tagName === 'INPUT' || input.tagName === 'TEXTAREA') {
3446
3469
  isEditable = !input.hasAttribute('readonly') && !input.hasAttribute('disabled');
3447
3470
  v = input.value;
@@ -3450,9 +3473,21 @@ if (! Modal && typeof (require) === 'function') {
3450
3473
  v = input.textContent;
3451
3474
  }
3452
3475
 
3453
- let tmp = Mask.extractDateFromString(v, self.format);
3454
- if (tmp) {
3455
- value = tmp;
3476
+ let ret = v;
3477
+ if (ret && Number(ret) == ret) {
3478
+ ret = Helpers.numToDate(ret);
3479
+ }
3480
+
3481
+ // Try a formatted date
3482
+ if (ret && ! Helpers.isValidDateFormat(ret)) {
3483
+ let tmp = Mask.extractDateFromString(ret, self.format);
3484
+ if (tmp) {
3485
+ ret = tmp;
3486
+ }
3487
+ }
3488
+
3489
+ if (ret !== value) {
3490
+ value = ret;
3456
3491
  }
3457
3492
  }
3458
3493
 
@@ -3687,42 +3722,46 @@ if (! Modal && typeof (require) === 'function') {
3687
3722
  }
3688
3723
 
3689
3724
  self.setValue = function(v) {
3690
- // Destroy range
3691
- destroyRange();
3692
- // Update the internal controllers
3693
- updateValue(v);
3694
3725
  // Events
3695
3726
  if (v !== self.value) {
3696
3727
  // Update value
3697
3728
  self.value = v;
3698
- // Events
3699
- Dispatch.call(self, change, 'change', {
3700
- instance: self,
3701
- value: self.value,
3702
- });
3703
- // Update input
3704
- let input = getInput();
3705
- if (input) {
3706
- if (self.format && v) {
3707
- if (self.range) {
3708
- if (v[0]) {
3709
- v[0] = Mask.render(v[0], self.format);
3710
- }
3711
- if (v[1]) {
3712
- v[1] = Mask.render(v[1], self.format);
3713
- }
3714
- } else {
3715
- v = Mask.render(v, self.format);
3729
+ }
3730
+ }
3731
+
3732
+ const dispatchOnChangeEvent = function() {
3733
+ // Destroy range
3734
+ destroyRange();
3735
+ // Update the internal controllers
3736
+ updateValue(self.value);
3737
+ // Events
3738
+ Dispatch.call(self, change, 'change', {
3739
+ instance: self,
3740
+ value: self.value,
3741
+ });
3742
+ // Update input
3743
+ let input = getInput();
3744
+ if (input) {
3745
+ let v = self.value;
3746
+ if (self.format && v) {
3747
+ if (self.range === true) {
3748
+ if (v[0]) {
3749
+ v[0] = Mask.render(v[0], self.format);
3750
+ }
3751
+ if (v[1]) {
3752
+ v[1] = Mask.render(v[1], self.format);
3716
3753
  }
3754
+ } else {
3755
+ v = Mask.render(v, self.format);
3717
3756
  }
3718
- // Update input value
3719
- input.value = v;
3720
- // Dispatch event
3721
- Dispatch.call(input, null, 'change', {
3722
- instance: self,
3723
- value: self.value,
3724
- });
3725
3757
  }
3758
+ // Update input value
3759
+ input.value = v;
3760
+ // Dispatch event
3761
+ Dispatch.call(input, null, 'change', {
3762
+ instance: self,
3763
+ value: self.value,
3764
+ });
3726
3765
  }
3727
3766
  }
3728
3767
 
@@ -3734,6 +3773,8 @@ if (! Modal && typeof (require) === 'function') {
3734
3773
  }
3735
3774
  }
3736
3775
 
3776
+ self.helpers = Helpers;
3777
+
3737
3778
  onchange(function(prop) {
3738
3779
  if (prop === 'view') {
3739
3780
  if (typeof(views[self.view]) === 'function') {
@@ -3741,12 +3782,18 @@ if (! Modal && typeof (require) === 'function') {
3741
3782
  self.options = views[self.view].call(self, date);
3742
3783
  }
3743
3784
  } else if (prop === 'value') {
3744
- self.setValue(self.value);
3785
+ dispatchOnChangeEvent();
3745
3786
  } else if (prop === 'startingDay') {
3746
- self.weekdays = getWeekdays(self.startingDay);
3787
+ self.weekdays = getWeekdays(self.startingDay ?? 0);
3747
3788
  }
3748
3789
  });
3749
3790
 
3791
+ // Input
3792
+ if (self.input === 'auto') {
3793
+ self.input = document.createElement('input');
3794
+ self.input.type = 'text';
3795
+ }
3796
+
3750
3797
  onload(function() {
3751
3798
  if (self.type !== "inline") {
3752
3799
  // Create modal instance
@@ -3769,11 +3816,11 @@ if (! Modal && typeof (require) === 'function') {
3769
3816
  self.range = true;
3770
3817
  }
3771
3818
 
3819
+ let ret;
3820
+
3772
3821
  // Create input controls
3773
3822
  if (self.input && self.initInput !== false) {
3774
- if (self.input === 'auto') {
3775
- self.input = document.createElement('input');
3776
- self.input.type = 'text';
3823
+ if (! self.input.parentNode) {
3777
3824
  self.el.parentNode.insertBefore(self.input, self.el);
3778
3825
  }
3779
3826
 
@@ -3797,13 +3844,21 @@ if (! Modal && typeof (require) === 'function') {
3797
3844
  if (self.value) {
3798
3845
  input.value = self.value;
3799
3846
  } else if (input.value && input.value !== self.value) {
3800
- self.value = input.value;
3847
+ // Correct format
3848
+ if (self.format) {
3849
+ input.value = Helpers.getDate(input.value, self.format);
3850
+ }
3851
+ ret = input.value;
3801
3852
  }
3802
3853
  }
3803
3854
  }
3804
3855
 
3805
3856
  // Update the internal date values
3806
- updateValue(self.value);
3857
+ if (ret) {
3858
+ self.value = ret;
3859
+ } else {
3860
+ updateValue(self.value);
3861
+ }
3807
3862
 
3808
3863
  /**
3809
3864
  * Handler keyboard
@@ -3886,7 +3941,7 @@ if (! Modal && typeof (require) === 'function') {
3886
3941
  const hours = views.hours();
3887
3942
  const minutes = views.minutes();
3888
3943
 
3889
- return render => render`<div class="lm-calendar" :value="self.value" data-grid="{{self.grid}}" data-type="{{self.type}}" data-disabled="{{self.disabled}}">
3944
+ return render => render`<div class="lm-calendar" :value="self.value" data-grid="{{self.grid}}" data-type="{{self.type}}" data-disabled="{{self.disabled}}" data-starting-day="{{self.startingDay}}">
3890
3945
  <div class="lm-calendar-options">
3891
3946
  <button type="button" onclick="self.reset">${T('Reset')}</button>
3892
3947
  <button type="button" onclick="${update}">${T('Done')}</button>
@@ -3907,7 +3962,7 @@ if (! Modal && typeof (require) === 'function') {
3907
3962
  </div>
3908
3963
  <div class="lm-calendar-footer" data-visible="{{self.footer}}">
3909
3964
  <div class="lm-calendar-time" data-visible="{{self.time}}"><select :loop="${hours}" :bind="self.hour" class="lm-calendar-control"><option value="{{self.value}}">{{self.title}}</option></select>:<select :loop="${minutes}" :bind="self.minute" class="lm-calendar-control"><option value="{{self.value}}">{{self.title}}</option></select></div>
3910
- <div class="lm-calendar-update"><input type="button" value="${T('Update')}" onclick="${update}" class="lm-ripple"></div>
3965
+ <div class="lm-calendar-update"><input type="button" value="${T('Update')}" onclick="${update}" class="lm-ripple lm-input"></div>
3911
3966
  </div>
3912
3967
  </div>
3913
3968
  </div>`
package/dist/style.css CHANGED
@@ -69,6 +69,7 @@
69
69
  padding: 4px;
70
70
  background-color: transparent;
71
71
  font-weight: bold;
72
+ color: var(--lm-font-color);
72
73
  }
73
74
 
74
75
  .lm-calendar-navigation {
@@ -78,7 +79,7 @@
78
79
  }
79
80
 
80
81
  .lm-calendar-navigation i:hover {
81
- background-color: var(--lm-background-color-hover, #ebebeb);
82
+ background-color: var(--lm-background-color-highlight, #ebebeb);
82
83
  color: #000;
83
84
  }
84
85
 
@@ -243,8 +244,6 @@
243
244
  }
244
245
 
245
246
  .lm-calendar-footer input {
246
- border: transparent;
247
- padding: 8px;
248
247
  width: 100%;
249
248
  cursor: pointer;
250
249
  background-color: var(--lm-border-color-light, #e9e9e9);
@@ -325,7 +324,7 @@
325
324
  }
326
325
 
327
326
  .lm-ripple:hover {
328
- background: var(--lm-background-color-hover, #ebebeb) radial-gradient(circle, transparent 1%, var(--lm-background-color-hover, #ebebeb) 1%) center/15000%;
327
+ background: var(--lm-background-color-highlight, #ebebeb) radial-gradient(circle, transparent 1%, var(--lm-background-color-highlight, #ebebeb) 1%) center/15000%;
329
328
  }
330
329
 
331
330
  .lm-ripple:active {
package/package.json CHANGED
@@ -14,10 +14,10 @@
14
14
  "javascript plugins"
15
15
  ],
16
16
  "dependencies": {
17
- "lemonadejs": "^5.2.0",
18
- "@lemonadejs/modal": "^5.2.0"
17
+ "lemonadejs": "^5.3.1",
18
+ "@lemonadejs/modal": "^5.3.0"
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "5.2.1"
22
+ "version": "5.3.0"
23
23
  }