@lemonadejs/calendar 3.4.2 → 3.6.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
@@ -19,64 +19,130 @@ if (! Modal && typeof (require) === 'function') {
19
19
  global.Calendar = factory();
20
20
  }(this, (function () {
21
21
 
22
- // Weekdays
23
- const Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
22
+ const Helpers = (function() {
23
+ const component = {};
24
24
 
25
- // Months
26
- const Months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
25
+ component.weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
26
+ component.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
27
27
 
28
- // Excel like dates
29
- const excelInitialTime = Date.UTC(1900, 0, 0);
30
- const excelLeapYearBug = Date.UTC(1900, 1, 29);
31
- const millisecondsPerDay = 86400000;
28
+ // Excel like dates
29
+ const excelInitialTime = Date.UTC(1900, 0, 0);
30
+ const excelLeapYearBug = Date.UTC(1900, 1, 29);
31
+ const millisecondsPerDay = 86400000;
32
32
 
33
- function isValidDate(d) {
34
- return d instanceof Date && !isNaN(d.getTime());
35
- }
33
+ // Transform in two digits
34
+ component.Two = function(value) {
35
+ value = '' + value;
36
+ if (value.length === 1) {
37
+ value = '0' + value;
38
+ }
39
+ return value;
40
+ }
36
41
 
37
- /**
38
- * Date to number
39
- */
40
- const dateToNum = function (jsDate) {
41
- if (typeof(jsDate) === 'string') {
42
- jsDate = new Date(jsDate + ' GMT+0');
42
+ component.isValidDate = function(d) {
43
+ return d instanceof Date && !isNaN(d.getTime());
43
44
  }
44
- let jsDateInMilliseconds = jsDate.getTime();
45
- if (jsDateInMilliseconds >= excelLeapYearBug) {
46
- jsDateInMilliseconds += millisecondsPerDay;
45
+
46
+ component.toString = function (date, dateOnly) {
47
+ let y = null;
48
+ let m = null;
49
+ let d = null;
50
+ let h = null;
51
+ let i = null;
52
+ let s = null;
53
+
54
+ if (Array.isArray(date)) {
55
+ y = date[0];
56
+ m = date[1];
57
+ d = date[2];
58
+ h = date[3];
59
+ i = date[4];
60
+ s = date[5];
61
+ } else {
62
+ if (! date) {
63
+ date = new Date();
64
+ }
65
+ y = date.getFullYear();
66
+ m = date.getMonth() + 1;
67
+ d = date.getDate();
68
+ h = date.getHours();
69
+ i = date.getMinutes();
70
+ s = date.getSeconds();
71
+ }
72
+
73
+ if (dateOnly === true) {
74
+ return component.Two(y) + '-' + component.Two(m) + '-' + component.Two(d);
75
+ } else {
76
+ return component.Two(y) + '-' + component.Two(m) + '-' + component.Two(d) + ' ' + component.Two(h) + ':' + component.Two(i) + ':' + component.Two(s);
77
+ }
47
78
  }
48
- jsDateInMilliseconds -= excelInitialTime;
49
79
 
50
- return jsDateInMilliseconds / millisecondsPerDay;
51
- }
80
+ component.toArray = function (value) {
81
+ let date = value.split(((value.indexOf('T') !== -1) ? 'T' : ' '));
82
+ let time = date[1];
83
+
84
+ date = date[0].split('-');
85
+ let y = parseInt(date[0]);
86
+ let m = parseInt(date[1]);
87
+ let d = parseInt(date[2]);
88
+ let h = 0;
89
+ let i = 0;
52
90
 
53
- const numToDate = function (excelSerialNumber, asString) {
54
- if (! excelSerialNumber) {
55
- return '';
91
+ if (time) {
92
+ time = time.split(':');
93
+ h = parseInt(time[0]);
94
+ i = parseInt(time[1]);
95
+ }
96
+ return [y, m, d, h, i, 0];
56
97
  }
57
98
 
58
- let jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
59
- if (jsDateInMilliseconds >= excelLeapYearBug) {
60
- jsDateInMilliseconds -= millisecondsPerDay;
99
+ component.arrayToStringDate = function(arr) {
100
+ return component.toString(arr, true);
61
101
  }
62
102
 
63
- const d = new Date(jsDateInMilliseconds);
103
+ component.dateToNum = function(jsDate) {
104
+ if (typeof(jsDate) === 'string') {
105
+ jsDate = new Date(jsDate + ' GMT+0');
106
+ }
107
+ let jsDateInMilliseconds = jsDate.getTime();
108
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
109
+ jsDateInMilliseconds += millisecondsPerDay;
110
+ }
111
+ jsDateInMilliseconds -= excelInitialTime;
64
112
 
65
- let arr = [
66
- d.getUTCFullYear(),
67
- Two(d.getUTCMonth() + 1),
68
- Two(d.getUTCDate()),
69
- Two(d.getUTCHours()),
70
- Two(d.getUTCMinutes()),
71
- Two(d.getUTCSeconds()),
72
- ];
113
+ return jsDateInMilliseconds / millisecondsPerDay;
114
+ }
73
115
 
74
- if (asString) {
75
- return arrayToStringDate(arr);
76
- } else {
77
- return arr;
116
+ component.numToDate = function(excelSerialNumber, asString){
117
+ if (! excelSerialNumber) {
118
+ return '';
119
+ }
120
+
121
+ let jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
122
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
123
+ jsDateInMilliseconds -= millisecondsPerDay;
124
+ }
125
+
126
+ const d = new Date(jsDateInMilliseconds);
127
+
128
+ let arr = [
129
+ d.getUTCFullYear(),
130
+ component.Two(d.getUTCMonth() + 1),
131
+ component.Two(d.getUTCDate()),
132
+ component.Two(d.getUTCHours()),
133
+ component.Two(d.getUTCMinutes()),
134
+ component.Two(d.getUTCSeconds()),
135
+ ];
136
+
137
+ if (asString) {
138
+ return component.arrayToStringDate(arr);
139
+ } else {
140
+ return arr;
141
+ }
78
142
  }
79
- }
143
+
144
+ return component;
145
+ })();
80
146
 
81
147
  const isNumber = function (num) {
82
148
  if (typeof(num) === 'string') {
@@ -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,11 @@ if (! Modal && typeof (require) === 'function') {
840
899
  self.update();
841
900
  }
842
901
  prevent = true;
902
+ } else {
903
+ if (self.input) {
904
+ // TODO: mask
905
+ //jSuites.mask(e);
906
+ }
843
907
  }
844
908
 
845
909
  if (prevent) {
@@ -853,12 +917,14 @@ if (! Modal && typeof (require) === 'function') {
853
917
  * @param {object} e - mouse event
854
918
  */
855
919
  self.content.addEventListener('wheel', function(e){
856
- if (e.deltaY < 0) {
857
- self.prev();
858
- } else {
859
- self.next();
920
+ if (self.wheel !== false) {
921
+ if (e.deltaY < 0) {
922
+ self.prev();
923
+ } else {
924
+ self.next();
925
+ }
926
+ e.preventDefault();
860
927
  }
861
- e.preventDefault();
862
928
  });
863
929
 
864
930
  /**
@@ -866,8 +932,10 @@ if (! Modal && typeof (require) === 'function') {
866
932
  * @param {object} e - mouse event
867
933
  */
868
934
  self.content.addEventListener('mouseover', function(e){
869
- if (e.target.lemon) {
870
- updateRange(e.target.lemon.self);
935
+ let parent = e.target.parentNode
936
+ if (parent === self.content) {
937
+ let index = Array.prototype.indexOf.call(parent.children, e.target);
938
+ updateRange(self.options[index]);
871
939
  }
872
940
  });
873
941
 
@@ -880,7 +948,7 @@ if (! Modal && typeof (require) === 'function') {
880
948
  });
881
949
  }
882
950
 
883
- return `<div class="lm-calendar" :value="self.value">
951
+ return `<div class="lm-calendar" :value="self.value" data-grid="{{self.grid}}">
884
952
  <div class="lm-calendar-options">
885
953
  <button type="button" onclick="self.reset">Reset</button>
886
954
  <button type="button" onclick="self.update">Done</button>
@@ -907,7 +975,10 @@ if (! Modal && typeof (require) === 'function') {
907
975
  </div>`
908
976
  }
909
977
 
978
+ // Register the LemonadeJS Component
910
979
  lemonade.setComponents({ Calendar: Calendar });
980
+ // Register the web component
981
+ lemonade.createWebComponent('calendar', Calendar);
911
982
 
912
983
  return function (root, options) {
913
984
  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
@@ -8,6 +8,10 @@
8
8
  position: relative;
9
9
  }
10
10
 
11
+ .lm-calendar button {
12
+ cursor: pointer;
13
+ }
14
+
11
15
  .lm-calendar .lm-modal {
12
16
  min-width: initial;
13
17
  min-height: initial;
@@ -57,10 +61,16 @@
57
61
  border: 0;
58
62
  padding: 4px;
59
63
  background-color: transparent;
64
+ font-weight: bold;
65
+ }
66
+
67
+ .lm-calendar-navigation {
68
+ display: grid;
69
+ grid-template-columns: repeat(2, 1fr);
70
+ gap: 6px;
60
71
  }
61
72
 
62
73
  .lm-calendar-navigation button {
63
- cursor: pointer;
64
74
  padding: 8px;
65
75
  border: 0;
66
76
  border-radius: 24px;
@@ -74,27 +84,28 @@
74
84
  .lm-calendar-weekdays {
75
85
  display: none;
76
86
  grid-template-columns: repeat(7, 1fr);
77
- grid-gap: 2px;
78
- padding: 0 10px 0 10px;
87
+ padding: 0 8px 0 8px;
79
88
  font-size: 0.8em;
80
89
  }
81
90
 
82
91
  .lm-calendar-container[data-view="days"] .lm-calendar-weekdays {
83
92
  display: grid;
93
+ align-items: center;
94
+ flex: 1;
84
95
  }
85
96
 
86
97
  .lm-calendar-weekdays > div {
87
98
  display: inline-block;
88
- padding: 10px;
99
+ padding: 6px;
89
100
  box-sizing: border-box;
90
101
  text-align: center;
91
102
  font-weight: bold;
103
+ line-height: 2em;
92
104
  }
93
105
 
94
106
  .lm-calendar-content {
95
107
  display: grid;
96
108
  grid-template-columns: repeat(7, 1fr);
97
- grid-gap: 0;
98
109
  padding: 8px;
99
110
  font-size: 0.8em;
100
111
  outline: none;
@@ -108,7 +119,7 @@
108
119
  flex-direction: column;
109
120
  justify-content: center;
110
121
  align-items: center;
111
- padding: 10px;
122
+ padding: 6px;
112
123
  cursor: pointer;
113
124
  border-radius: 100px;
114
125
  background-origin: padding-box;
@@ -171,8 +182,8 @@
171
182
  position: absolute;
172
183
  left: 0;
173
184
  right: 0;
174
- top: 8px;
175
- bottom: 8px;
185
+ top: calc(25%);
186
+ height: 50%;
176
187
  background-color: var(--lm-main-color-alpha, #2196f388);
177
188
  }
178
189
 
@@ -193,7 +204,7 @@
193
204
  margin: 0 10px 0 10px;
194
205
  padding: 8px 0 8px 0;
195
206
  line-height: 34px;
196
- border-top: 1px solid var(--lm-border-color, #ccc);
207
+ border-top: 1px solid var(--lm-border-color-light, #e9e9e9);
197
208
  }
198
209
 
199
210
  .lm-calendar-footer[data-visible="false"] {
@@ -221,6 +232,7 @@
221
232
  padding: 8px;
222
233
  width: 100%;
223
234
  cursor: pointer;
235
+ background-color: var(--lm-border-color-light, #e9e9e9);
224
236
  }
225
237
 
226
238
  .lm-calendar-input {
@@ -267,3 +279,25 @@
267
279
  .lm-dark-mode .lm-calendar-footer select:focus {
268
280
  background-color: #3a3a45;
269
281
  }
282
+
283
+ .lm-calendar[data-grid="true"] .lm-calendar-weekdays {
284
+ padding: 0;
285
+ }
286
+
287
+ .lm-calendar[data-grid="true"] .lm-calendar-content {
288
+ border-top: 1px solid transparent;
289
+ border-left: 1px solid transparent;
290
+ border-right: 1px solid #ccc;
291
+ border-bottom: 1px solid #ccc;
292
+ padding: 0;
293
+ }
294
+
295
+ .lm-calendar[data-grid="true"] .lm-calendar-content > div {
296
+ border-top: 1px solid #ccc;
297
+ border-left: 1px solid #ccc;
298
+ border-right: 1px solid transparent;
299
+ border-bottom: 1px solid transparent;
300
+ border-radius: 0;
301
+ justify-content: start;
302
+ align-items: end;
303
+ }
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.3.0"
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "3.4.2"
22
+ "version": "3.6.0"
23
23
  }