@lemonadejs/calendar 3.4.2 → 3.5.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
@@ -10,6 +10,8 @@ declare namespace Calendar {
10
10
  interface Options {
11
11
  /** Calendar type */
12
12
  type?: 'default' | 'inline';
13
+ /** Date format */
14
+ format?: string;
13
15
  /** Range picker */
14
16
  range?: boolean;
15
17
  /** Value */
@@ -18,10 +20,14 @@ declare namespace Calendar {
18
20
  numeric?: boolean;
19
21
  /** Bind the calendar to na HTML input element */
20
22
  input?: HTMLElement | object | 'auto';
21
- /** Footer **/
23
+ /** Footer. Default: true **/
22
24
  footer?: boolean;
23
25
  /** Show hour and minute picker **/
24
26
  time?: boolean;
27
+ /** Show grid mode. Default: false */
28
+ grid?: boolean;
29
+ /** Update view on mouse wheel. Default: true */
30
+ wheel?: boolean;
25
31
  /** LemonadeJS on change event */
26
32
  onchange?: (self: object, value: string) => void;
27
33
  /** LemonadeJS on update event */
package/dist/index.js CHANGED
@@ -13,31 +13,88 @@ if (! Modal && typeof (require) === 'function') {
13
13
  var Modal = require('@lemonadejs/modal');
14
14
  }
15
15
 
16
- ; (function (global, factory) {
17
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
18
- typeof define === 'function' && define.amd ? define(factory) :
19
- global.Calendar = factory();
20
- }(this, (function () {
21
-
22
- // Weekdays
23
- const Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
16
+ const Helpers = (function() {
17
+ const component = {};
24
18
 
25
- // Months
26
- const Months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
19
+ component.weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
20
+ component.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
27
21
 
28
22
  // Excel like dates
29
23
  const excelInitialTime = Date.UTC(1900, 0, 0);
30
24
  const excelLeapYearBug = Date.UTC(1900, 1, 29);
31
25
  const millisecondsPerDay = 86400000;
32
26
 
33
- function isValidDate(d) {
27
+ // Transform in two digits
28
+ component.Two = function(value) {
29
+ value = '' + value;
30
+ if (value.length === 1) {
31
+ value = '0' + value;
32
+ }
33
+ return value;
34
+ }
35
+
36
+ component.isValidDate = function(d) {
34
37
  return d instanceof Date && !isNaN(d.getTime());
35
38
  }
36
39
 
37
- /**
38
- * Date to number
39
- */
40
- const dateToNum = function (jsDate) {
40
+ component.toString = function (date, dateOnly) {
41
+ let y = null;
42
+ let m = null;
43
+ let d = null;
44
+ let h = null;
45
+ let i = null;
46
+ let s = null;
47
+
48
+ if (Array.isArray(date)) {
49
+ y = date[0];
50
+ m = date[1];
51
+ d = date[2];
52
+ h = date[3];
53
+ i = date[4];
54
+ s = date[5];
55
+ } else {
56
+ if (! date) {
57
+ date = new Date();
58
+ }
59
+ y = date.getFullYear();
60
+ m = date.getMonth() + 1;
61
+ d = date.getDate();
62
+ h = date.getHours();
63
+ i = date.getMinutes();
64
+ s = date.getSeconds();
65
+ }
66
+
67
+ if (dateOnly === true) {
68
+ return component.Two(y) + '-' + component.Two(m) + '-' + component.Two(d);
69
+ } else {
70
+ return component.Two(y) + '-' + component.Two(m) + '-' + component.Two(d) + ' ' + component.Two(h) + ':' + component.Two(i) + ':' + component.Two(s);
71
+ }
72
+ }
73
+
74
+ component.toArray = function (value) {
75
+ let date = value.split(((value.indexOf('T') !== -1) ? 'T' : ' '));
76
+ let time = date[1];
77
+
78
+ date = date[0].split('-');
79
+ let y = parseInt(date[0]);
80
+ let m = parseInt(date[1]);
81
+ let d = parseInt(date[2]);
82
+ let h = 0;
83
+ let i = 0;
84
+
85
+ if (time) {
86
+ time = time.split(':');
87
+ h = parseInt(time[0]);
88
+ i = parseInt(time[1]);
89
+ }
90
+ return [y, m, d, h, i, 0];
91
+ }
92
+
93
+ component.arrayToStringDate = function(arr) {
94
+ return component.toString(arr, true);
95
+ }
96
+
97
+ component.dateToNum = function(jsDate) {
41
98
  if (typeof(jsDate) === 'string') {
42
99
  jsDate = new Date(jsDate + ' GMT+0');
43
100
  }
@@ -50,7 +107,7 @@ if (! Modal && typeof (require) === 'function') {
50
107
  return jsDateInMilliseconds / millisecondsPerDay;
51
108
  }
52
109
 
53
- const numToDate = function (excelSerialNumber, asString) {
110
+ component.numToDate = function(excelSerialNumber, asString){
54
111
  if (! excelSerialNumber) {
55
112
  return '';
56
113
  }
@@ -64,20 +121,29 @@ if (! Modal && typeof (require) === 'function') {
64
121
 
65
122
  let arr = [
66
123
  d.getUTCFullYear(),
67
- Two(d.getUTCMonth() + 1),
68
- Two(d.getUTCDate()),
69
- Two(d.getUTCHours()),
70
- Two(d.getUTCMinutes()),
71
- Two(d.getUTCSeconds()),
124
+ component.Two(d.getUTCMonth() + 1),
125
+ component.Two(d.getUTCDate()),
126
+ component.Two(d.getUTCHours()),
127
+ component.Two(d.getUTCMinutes()),
128
+ component.Two(d.getUTCSeconds()),
72
129
  ];
73
130
 
74
131
  if (asString) {
75
- return arrayToStringDate(arr);
132
+ return component.arrayToStringDate(arr);
76
133
  } else {
77
134
  return arr;
78
135
  }
79
136
  }
80
137
 
138
+ return component;
139
+ })();
140
+
141
+ ; (function (global, factory) {
142
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
143
+ typeof define === 'function' && define.amd ? define(factory) :
144
+ global.Calendar = factory();
145
+ }(this, (function () {
146
+
81
147
  const isNumber = function (num) {
82
148
  if (typeof(num) === 'string') {
83
149
  num = num.trim();
@@ -85,10 +151,6 @@ if (! Modal && typeof (require) === 'function') {
85
151
  return !isNaN(num) && num !== null && num !== '';
86
152
  }
87
153
 
88
- const arrayToStringDate = function(arr) {
89
- return [arr[0],Two(arr[1]),Two(arr[2])].join('-');
90
- }
91
-
92
154
  /**
93
155
  * Create a data calendar object based on the view
94
156
  */
@@ -120,7 +182,7 @@ if (! Modal && typeof (require) === 'function') {
120
182
  let result = [];
121
183
  for (let i = 0; i < 12; i++) {
122
184
  let item = {
123
- title: Months[i].substring(0,3),
185
+ title: Helpers.months[i].substring(0,3),
124
186
  value: i
125
187
  }
126
188
  // Add the item to the data
@@ -155,7 +217,7 @@ if (! Modal && typeof (require) === 'function') {
155
217
  let item = {
156
218
  title: day,
157
219
  value: i,
158
- number: dateToNum(tmp.toString())
220
+ number: Helpers.dateToNum(tmp.toString())
159
221
  }
160
222
  // Add the item to the date
161
223
  result.push(item);
@@ -165,7 +227,7 @@ if (! Modal && typeof (require) === 'function') {
165
227
  item.grey = true;
166
228
  } else {
167
229
  // Check for data
168
- let d = [ year, Two(month+1), Two(day)].join('-');
230
+ let d = [ year, Helpers.Two(month+1), Helpers.Two(day)].join('-');
169
231
  if (data && data[d]) {
170
232
  item.data = data[d];
171
233
  }
@@ -205,7 +267,7 @@ if (! Modal && typeof (require) === 'function') {
205
267
  let result = [];
206
268
  for (let i = 0; i < 24; i++) {
207
269
  let item = {
208
- title: Two(i),
270
+ title: Helpers.Two(i),
209
271
  value: i
210
272
  };
211
273
  result.push(item);
@@ -216,7 +278,7 @@ if (! Modal && typeof (require) === 'function') {
216
278
  let result = [];
217
279
  for (let i = 0; i < 60; i=i+5) {
218
280
  let item = {
219
- title: Two(i),
281
+ title: Helpers.Two(i),
220
282
  value: i
221
283
  };
222
284
  result.push(item);
@@ -230,7 +292,7 @@ if (! Modal && typeof (require) === 'function') {
230
292
  let data = {};
231
293
  if (Array.isArray(this.data)) {
232
294
  this.data.map(function (v) {
233
- let d = year + '-' + Two(month + 1);
295
+ let d = year + '-' + Helpers.Two(month + 1);
234
296
  if (v.date.substring(0, 7) === d) {
235
297
  if (!data[v.date]) {
236
298
  data[v.date] = [];
@@ -241,9 +303,10 @@ if (! Modal && typeof (require) === 'function') {
241
303
  }
242
304
  return data;
243
305
  }
306
+
244
307
  // Get the short weekdays name
245
308
  const getWeekdays = function() {
246
- return Weekdays.map(w => {
309
+ return Helpers.weekdays.map(w => {
247
310
  return { title: w.substring(0, 1) };
248
311
  })
249
312
  }
@@ -268,14 +331,6 @@ if (! Modal && typeof (require) === 'function') {
268
331
  return position;
269
332
  }
270
333
 
271
- // Transform in two digits
272
- const Two = function(value) {
273
- value = '' + value;
274
- if (value.length === 1) {
275
- value = '0' + value;
276
- }
277
- return value;
278
- }
279
334
 
280
335
  const Calendar = function() {
281
336
  let self = this;
@@ -310,7 +365,7 @@ if (! Modal && typeof (require) === 'function') {
310
365
  // Update the headers of the calendar
311
366
  let value = d.toISOString().substring(0,10).split('-');
312
367
  // Update the month label
313
- self.month = Months[parseInt(value[1])-1];
368
+ self.month = Helpers.months[parseInt(value[1])-1];
314
369
  // Update the year label
315
370
  self.year = parseInt(value[0]);
316
371
  // Load data
@@ -478,7 +533,7 @@ if (! Modal && typeof (require) === 'function') {
478
533
  if (self.view === 'days' && self.range) {
479
534
  let d = getDate();
480
535
  // Date to number
481
- let number = dateToNum(d);
536
+ let number = Helpers.dateToNum(d);
482
537
  // Start a new range
483
538
  if (self.rangeValues && (self.rangeValues[0] >= number || self.rangeValues[1])) {
484
539
  destroyRange();
@@ -538,15 +593,15 @@ if (! Modal && typeof (require) === 'function') {
538
593
  value = self.rangeValues;
539
594
  } else {
540
595
  value = [
541
- numToDate(self.rangeValues[0], true),
542
- numToDate(self.rangeValues[1], true)
596
+ Helpers.numToDate(self.rangeValues[0], true),
597
+ Helpers.numToDate(self.rangeValues[1], true)
543
598
  ];
544
599
  }
545
600
  }
546
601
  } else {
547
602
  value = getDate();
548
603
  if (self.numeric) {
549
- value = dateToNum(value);
604
+ value = Helpers.dateToNum(value);
550
605
  }
551
606
  }
552
607
  return value;
@@ -561,10 +616,10 @@ if (! Modal && typeof (require) === 'function') {
561
616
  self.rangeValues = [...v];
562
617
 
563
618
  if (v[0] && typeof(v[0]) === 'string' && v[0].indexOf('-')) {
564
- self.rangeValues[0] = dateToNum(v[0]);
619
+ self.rangeValues[0] = Helpers.dateToNum(v[0]);
565
620
  }
566
621
  if (v[1] && typeof(v[1]) === 'string' && v[1].indexOf('-')) {
567
- self.rangeValues[1] = dateToNum(v[1]);
622
+ self.rangeValues[1] = Helpers.dateToNum(v[1]);
568
623
  }
569
624
 
570
625
  v = v[0];
@@ -573,11 +628,11 @@ if (! Modal && typeof (require) === 'function') {
573
628
 
574
629
  let d;
575
630
  if (v) {
576
- v = isNumber(v) ? numToDate(v, true) : v;
631
+ v = isNumber(v) ? Helpers.numToDate(v, true) : v;
577
632
  d = new Date(v);
578
633
  }
579
634
  // if no date is defined
580
- if (! isValidDate(d)) {
635
+ if (! Helpers.isValidDate(d)) {
581
636
  d = new Date();
582
637
  }
583
638
  // Update my index
@@ -632,6 +687,10 @@ if (! Modal && typeof (require) === 'function') {
632
687
  setDate(value);
633
688
  // Back to the days
634
689
  self.view = 'days';
690
+ } else {
691
+ if (! self.range) {
692
+ self.update();
693
+ }
635
694
  }
636
695
  }
637
696
 
@@ -840,6 +899,10 @@ if (! Modal && typeof (require) === 'function') {
840
899
  self.update();
841
900
  }
842
901
  prevent = true;
902
+ } else {
903
+ if (self.input) {
904
+ jSuites.mask(e);
905
+ }
843
906
  }
844
907
 
845
908
  if (prevent) {
@@ -853,12 +916,14 @@ if (! Modal && typeof (require) === 'function') {
853
916
  * @param {object} e - mouse event
854
917
  */
855
918
  self.content.addEventListener('wheel', function(e){
856
- if (e.deltaY < 0) {
857
- self.prev();
858
- } else {
859
- self.next();
919
+ if (self.wheel !== false) {
920
+ if (e.deltaY < 0) {
921
+ self.prev();
922
+ } else {
923
+ self.next();
924
+ }
925
+ e.preventDefault();
860
926
  }
861
- e.preventDefault();
862
927
  });
863
928
 
864
929
  /**
@@ -866,8 +931,10 @@ if (! Modal && typeof (require) === 'function') {
866
931
  * @param {object} e - mouse event
867
932
  */
868
933
  self.content.addEventListener('mouseover', function(e){
869
- if (e.target.lemon) {
870
- updateRange(e.target.lemon.self);
934
+ let parent = e.target.parentNode
935
+ if (parent === self.content) {
936
+ let index = Array.prototype.indexOf.call(parent.children, e.target);
937
+ updateRange(self.options[index]);
871
938
  }
872
939
  });
873
940
 
@@ -880,7 +947,7 @@ if (! Modal && typeof (require) === 'function') {
880
947
  });
881
948
  }
882
949
 
883
- return `<div class="lm-calendar" :value="self.value">
950
+ return `<div class="lm-calendar" :value="self.value" data-grid="{{self.grid}}">
884
951
  <div class="lm-calendar-options">
885
952
  <button type="button" onclick="self.reset">Reset</button>
886
953
  <button type="button" onclick="self.update">Done</button>
@@ -907,7 +974,10 @@ if (! Modal && typeof (require) === 'function') {
907
974
  </div>`
908
975
  }
909
976
 
977
+ // Register the LemonadeJS Component
910
978
  lemonade.setComponents({ Calendar: Calendar });
979
+ // Register the web component
980
+ lemonade.createWebComponent('calendar', Calendar);
911
981
 
912
982
  return function (root, options) {
913
983
  if (typeof (root) === 'object') {
package/dist/react.d.ts CHANGED
@@ -1,13 +1,18 @@
1
1
  /**
2
2
  * Official Type definitions for the LemonadeJS plugins
3
- * https://lemonadejs.net
3
+ * https://lemonadejs.net/docs/plugins/calendar
4
4
  * Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
5
  */
6
6
  import Component from './index';
7
+
7
8
  interface Calendar {
9
+ ref?: MutableRefObject<undefined>;
8
10
  (): any
9
11
  [key: string]: any
10
12
  }
11
13
 
12
- declare function Calendar<Calendar>(props: Component.Options): any;
14
+ type Props = IntrinsicAttributes & Component.Options & Calendar;
15
+
16
+ declare function Calendar<Calendar>(props: Props): any;
17
+
13
18
  export default Calendar;
package/dist/style.css CHANGED
@@ -57,6 +57,7 @@
57
57
  border: 0;
58
58
  padding: 4px;
59
59
  background-color: transparent;
60
+ font-weight: bold;
60
61
  }
61
62
 
62
63
  .lm-calendar-navigation button {
@@ -74,27 +75,28 @@
74
75
  .lm-calendar-weekdays {
75
76
  display: none;
76
77
  grid-template-columns: repeat(7, 1fr);
77
- grid-gap: 2px;
78
- padding: 0 10px 0 10px;
78
+ padding: 0 8px 0 8px;
79
79
  font-size: 0.8em;
80
80
  }
81
81
 
82
82
  .lm-calendar-container[data-view="days"] .lm-calendar-weekdays {
83
83
  display: grid;
84
+ align-items: center;
85
+ flex: 1;
84
86
  }
85
87
 
86
88
  .lm-calendar-weekdays > div {
87
89
  display: inline-block;
88
- padding: 10px;
90
+ padding: 6px;
89
91
  box-sizing: border-box;
90
92
  text-align: center;
91
93
  font-weight: bold;
94
+ line-height: 2em;
92
95
  }
93
96
 
94
97
  .lm-calendar-content {
95
98
  display: grid;
96
99
  grid-template-columns: repeat(7, 1fr);
97
- grid-gap: 0;
98
100
  padding: 8px;
99
101
  font-size: 0.8em;
100
102
  outline: none;
@@ -108,7 +110,7 @@
108
110
  flex-direction: column;
109
111
  justify-content: center;
110
112
  align-items: center;
111
- padding: 10px;
113
+ padding: 6px;
112
114
  cursor: pointer;
113
115
  border-radius: 100px;
114
116
  background-origin: padding-box;
@@ -171,8 +173,8 @@
171
173
  position: absolute;
172
174
  left: 0;
173
175
  right: 0;
174
- top: 8px;
175
- bottom: 8px;
176
+ top: calc(25%);
177
+ height: 50%;
176
178
  background-color: var(--lm-main-color-alpha, #2196f388);
177
179
  }
178
180
 
@@ -193,7 +195,7 @@
193
195
  margin: 0 10px 0 10px;
194
196
  padding: 8px 0 8px 0;
195
197
  line-height: 34px;
196
- border-top: 1px solid var(--lm-border-color, #ccc);
198
+ border-top: 1px solid var(--lm-border-color-light, #e9e9e9);
197
199
  }
198
200
 
199
201
  .lm-calendar-footer[data-visible="false"] {
@@ -221,6 +223,7 @@
221
223
  padding: 8px;
222
224
  width: 100%;
223
225
  cursor: pointer;
226
+ background-color: var(--lm-border-color-light, #e9e9e9);
224
227
  }
225
228
 
226
229
  .lm-calendar-input {
@@ -267,3 +270,25 @@
267
270
  .lm-dark-mode .lm-calendar-footer select:focus {
268
271
  background-color: #3a3a45;
269
272
  }
273
+
274
+ .lm-calendar[data-grid="true"] .lm-calendar-weekdays {
275
+ padding: 0;
276
+ }
277
+
278
+ .lm-calendar[data-grid="true"] .lm-calendar-content {
279
+ border-top: 1px solid transparent;
280
+ border-left: 1px solid transparent;
281
+ border-right: 1px solid #ccc;
282
+ border-bottom: 1px solid #ccc;
283
+ padding: 0;
284
+ }
285
+
286
+ .lm-calendar[data-grid="true"] .lm-calendar-content > div {
287
+ border-top: 1px solid #ccc;
288
+ border-left: 1px solid #ccc;
289
+ border-right: 1px solid transparent;
290
+ border-bottom: 1px solid transparent;
291
+ border-radius: 0;
292
+ justify-content: start;
293
+ align-items: end;
294
+ }
package/package.json CHANGED
@@ -14,10 +14,10 @@
14
14
  "javascript plugins"
15
15
  ],
16
16
  "dependencies": {
17
- "lemonadejs": "^4.2.2",
18
- "@lemonadejs/modal": "^2.8.1"
17
+ "lemonadejs": "^4.3.3",
18
+ "@lemonadejs/modal": "^3.2.0"
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "3.4.2"
22
+ "version": "3.5.0"
23
23
  }