@lemonadejs/calendar 3.4.0 → 3.4.2

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
@@ -17,15 +17,17 @@ declare namespace Calendar {
17
17
  /** Calendar value will be a excel-like number or a ISO string. Default false */
18
18
  numeric?: boolean;
19
19
  /** Bind the calendar to na HTML input element */
20
- input?: HTMLElement | object;
21
- /** Onchange event */
22
- onchange?: (self: object, value: string) => void;
23
- /** On update event */
24
- onupdate?: (self: object, value: string) => void;
20
+ input?: HTMLElement | object | 'auto';
25
21
  /** Footer **/
26
22
  footer?: boolean;
27
23
  /** Show hour and minute picker **/
28
24
  time?: boolean;
25
+ /** LemonadeJS on change event */
26
+ onchange?: (self: object, value: string) => void;
27
+ /** LemonadeJS on update event */
28
+ onupdate?: (self: object, value: string) => void;
29
+ /** React dedicated onChange event */
30
+ onChange?: (e: Event) => void;
29
31
  }
30
32
 
31
33
  interface Instance {
package/dist/index.js CHANGED
@@ -558,7 +558,7 @@ if (! Modal && typeof (require) === 'function') {
558
558
  if (! Array.isArray(v)) {
559
559
  v = v.split(',');
560
560
  }
561
- self.rangeValues = v;
561
+ self.rangeValues = [...v];
562
562
 
563
563
  if (v[0] && typeof(v[0]) === 'string' && v[0].indexOf('-')) {
564
564
  self.rangeValues[0] = dateToNum(v[0]);
@@ -590,26 +590,32 @@ if (! Modal && typeof (require) === 'function') {
590
590
  setDate(d);
591
591
  }
592
592
 
593
+ let autoInput = null;
594
+
593
595
  const getInput = function() {
594
596
  let input = self.input;
595
597
  if (input && input.current) {
596
598
  input = input.current;
597
- }
598
- return input;
599
- }
600
-
601
- const applyValue = function(reset) {
602
- if (reset) {
603
- self.value = '';
604
- destroyRange();
605
599
  } else {
606
- // Set the internal value
607
- self.value = renderValue();
608
- }
609
- if (self.input) {
610
- let input = getInput();
611
- input.value = self.value;
600
+ if (input === 'auto') {
601
+ if (! autoInput) {
602
+ autoInput = document.createElement('input');
603
+ autoInput.type = 'text';
604
+ if (self.class) {
605
+ autoInput.class = self.class;
606
+ }
607
+ if (self.name) {
608
+ autoInput.name = self.name;
609
+ }
610
+ if (self.placeholder) {
611
+ autoInput.placeholder = self.placeholder;
612
+ }
613
+ self.el.parentNode.insertBefore(autoInput, self.el);
614
+ }
615
+ input = autoInput;
616
+ }
612
617
  }
618
+ return input;
613
619
  }
614
620
 
615
621
  /**
@@ -678,12 +684,11 @@ if (! Modal && typeof (require) === 'function') {
678
684
  if (! (input && e.target.getAttribute('readonly') === null)) {
679
685
  self.content.focus();
680
686
  }
681
-
682
- // Update the internal date values
683
- updateValue(self.value);
684
687
  // Populate components
685
688
  self.hours = views.hours();
686
689
  self.minutes = views.minutes();
690
+ // Update the internal date values
691
+ updateValue(self.value);
687
692
  }
688
693
  }
689
694
 
@@ -700,12 +705,12 @@ if (! Modal && typeof (require) === 'function') {
700
705
  }
701
706
 
702
707
  self.reset = function() {
703
- applyValue(true);
708
+ self.setValue('');
704
709
  self.close();
705
710
  }
706
711
 
707
712
  self.update = function() {
708
- applyValue();
713
+ self.setValue(renderValue());
709
714
  self.close();
710
715
  }
711
716
 
@@ -728,16 +733,19 @@ if (! Modal && typeof (require) === 'function') {
728
733
  }
729
734
 
730
735
  self.setValue = function(v) {
731
- // Destroy range
732
- destroyRange();
733
736
  // Update the internal controllers
734
737
  updateValue(v);
735
- // Update value
736
- self.value = v;
738
+ // Destroy range
739
+ destroyRange();
737
740
  // Update input
738
741
  if (self.input) {
739
742
  let input = getInput();
740
- input.value = self.value;
743
+ input.value = v;
744
+ }
745
+
746
+ if (v !== self.value) {
747
+ // Update value
748
+ self.value = v;
741
749
  }
742
750
  }
743
751
 
@@ -754,14 +762,20 @@ if (! Modal && typeof (require) === 'function') {
754
762
  if (typeof (self.onupdate) === 'function') {
755
763
  self.onupdate(self, self.value);
756
764
  }
765
+ if (typeof(self.onChange) === 'function') {
766
+ let input = getInput();
767
+ if (input) {
768
+ input.dispatchEvent(new Event('change', {bubbles: true, cancelable: true}));
769
+ }
770
+ }
771
+
772
+ self.setValue(self.value);
757
773
  } else if (prop === 'options') {
758
774
  self.content.focus();
759
775
  }
760
776
  }
761
777
 
762
778
  self.onload = function() {
763
- // Update the internal date values
764
- updateValue(self.value);
765
779
  // Populate components
766
780
  self.hours = views.hours();
767
781
  self.minutes = views.minutes();
@@ -788,14 +802,21 @@ if (! Modal && typeof (require) === 'function') {
788
802
  input.addEventListener('click', self.open);
789
803
  input.addEventListener('blur', blur);
790
804
 
805
+ if (self.onChange) {
806
+ input.addEventListener('change', self.onChange);
807
+ }
808
+
791
809
  // Retrieve the value
792
810
  if (self.value) {
793
811
  input.value = self.value;
794
- } else if (input.value) {
812
+ } else if (input.value && input.value !== self.value) {
795
813
  self.value = input.value;
796
814
  }
797
815
  }
798
816
 
817
+ // Update the internal date values
818
+ updateValue(self.value);
819
+
799
820
  /**
800
821
  * Handler keyboard
801
822
  * @param {object} e - event
@@ -861,14 +882,17 @@ if (! Modal && typeof (require) === 'function') {
861
882
 
862
883
  return `<div class="lm-calendar" :value="self.value">
863
884
  <div class="lm-calendar-options">
864
- <button onclick="self.reset">Reset</button>
865
- <button onclick="self.update">Done</button>
885
+ <button type="button" onclick="self.reset">Reset</button>
886
+ <button type="button" onclick="self.update">Done</button>
866
887
  </div>
867
888
  <div class="lm-calendar-container" data-view="{{self.view}}">
868
889
  <div class="lm-calendar-header">
869
890
  <div>
870
- <div class="lm-calendar-labels"><button onclick="self.setView" data-view="months">{{self.month}}</button> <button onclick="self.setView" data-view="years">{{self.year}}</button></div>
871
- <div class="lm-calendar-navigation"><button type="button" class="material-icons lm-ripple" onclick="self.prev" tabindex="0">arrow_drop_up</button> <button type="button" class="material-icons lm-ripple" onclick="self.next" tabindex="0">arrow_drop_down</button></div>
891
+ <div class="lm-calendar-labels"><button type="button" onclick="self.setView" data-view="months">{{self.month}}</button> <button type="button" onclick="self.setView" data-view="years">{{self.year}}</button></div>
892
+ <div class="lm-calendar-navigation">
893
+ <button type="button" class="material-icons lm-ripple" onclick="self.prev" tabindex="0">arrow_drop_up</button>
894
+ <button type="button" class="material-icons lm-ripple" onclick="self.next" tabindex="0">arrow_drop_down</button>
895
+ </div>
872
896
  </div>
873
897
  <div class="lm-calendar-weekdays" :loop="self.weekdays"><div>{{self.title}}</div></div>
874
898
  </div>
package/dist/react.js CHANGED
@@ -2,7 +2,6 @@
2
2
  import React, { useRef, useEffect } from "react";
3
3
  import Component from './index';
4
4
 
5
-
6
5
  // @ts-ignore
7
6
  export default React.forwardRef((props, mainReference) => {
8
7
  // Dom element
@@ -13,21 +12,27 @@ export default React.forwardRef((props, mainReference) => {
13
12
 
14
13
  useEffect(() => {
15
14
  // @ts-ignore
16
- if (!Ref.current.innerHTML) {
17
- mainReference.current = Component(Ref.current, options);
18
- }
19
- }, []);
20
-
21
- useEffect(() => {
22
- for (let key in props) {
23
- if (props.hasOwnProperty(key) && mainReference.current.hasOwnProperty(key)) {
24
- if (props[key] !== mainReference.current[key]) {
25
- mainReference.current[key] = props[key];
15
+ if (Ref.current.innerHTML) {
16
+ for (let key in props) {
17
+ if (key === 'onchange' || key === 'onload') {
18
+ continue;
19
+ }
20
+ if (props.hasOwnProperty(key) && mainReference.current.hasOwnProperty(key)) {
21
+ if (props[key] !== mainReference.current[key]) {
22
+ mainReference.current[key] = props[key];
23
+ }
26
24
  }
27
25
  }
28
26
  }
29
27
  }, [props])
30
28
 
29
+ useEffect(() => {
30
+ // @ts-ignore
31
+ if (! Ref.current.innerHTML) {
32
+ mainReference.current = Component(Ref.current, options);
33
+ }
34
+ }, []);
35
+
31
36
  let prop = {
32
37
  ref: Ref,
33
38
  style: { height: '100%', width: '100%' }
package/dist/vue.js CHANGED
@@ -5,13 +5,13 @@ import component from "./index";
5
5
  export default {
6
6
  inheritAttrs: false,
7
7
  mounted() {
8
- let options = {
9
- ...this.$attrs
10
- };
11
-
12
- this.el = this.$refs.container;
13
-
14
- this.current = component(this.$refs.container, options);
8
+ this.$nextTick(() => {
9
+ let options = {
10
+ ...this.$attrs
11
+ };
12
+
13
+ this.current = component(this.$refs.container, options);
14
+ });
15
15
  },
16
16
  setup() {
17
17
  let containerProps = {
@@ -33,10 +33,12 @@ export default {
33
33
  },
34
34
  methods: {
35
35
  updateState() {
36
- for (let key in this.$attrs) {
37
- if (this.$attrs.hasOwnProperty(key) && this.current.hasOwnProperty(key)) {
38
- if (this.$attrs[key] !== this.current[key]) {
39
- this.current[key] = this.$attrs[key];
36
+ if (this.current) {
37
+ for (let key in this.$attrs) {
38
+ if (this.$attrs.hasOwnProperty(key) && this.current.hasOwnProperty(key)) {
39
+ if (this.$attrs[key] !== this.current[key]) {
40
+ this.current[key] = this.$attrs[key];
41
+ }
40
42
  }
41
43
  }
42
44
  }
package/package.json CHANGED
@@ -19,5 +19,5 @@
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "3.4.0"
22
+ "version": "3.4.2"
23
23
  }