@momo-kits/date-picker 0.0.32-beta → 0.0.32

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.
@@ -1 +1,60 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/datePicker/dist/datePicker/custom/ScrollCustom.js";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=(0,_getPrototypeOf2.default)(Derived),result;if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2.default)(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return(0,_possibleConstructorReturn2.default)(this,result);};}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}var ScrollCustom=function(_Component){(0,_inherits2.default)(ScrollCustom,_Component);var _super=_createSuper(ScrollCustom);function ScrollCustom(props){var _this;(0,_classCallCheck2.default)(this,ScrollCustom);_this=_super.call(this,props);var scrollEnabled=_this.props.scrollEnabled;_this.scrollEnabled=scrollEnabled;_this.state={scrollEnabled:_this.scrollEnabled};return _this;}(0,_createClass2.default)(ScrollCustom,[{key:"scrollTo",value:function scrollTo(event){if(event&&this.ScrollView&&this.ScrollView.scrollTo){this.ScrollView.scrollTo(event);}}},{key:"setScrollEnabled",value:function setScrollEnabled(enable){var scrollEnabled=this.state.scrollEnabled;if(enable!==scrollEnabled){this.setState({scrollEnabled:enable});}}},{key:"render",value:function render(){var _this2=this;var children=this.props.children;var scrollEnabled=this.state.scrollEnabled;return _react.default.createElement(_reactNative.ScrollView,(0,_extends2.default)({ref:function ref(refName){_this2.ScrollView=refName;}},this.props,{scrollEnabled:scrollEnabled,__source:{fileName:_jsxFileName,lineNumber:35,columnNumber:13}}),children);}}]);return ScrollCustom;}(_react.Component);ScrollCustom.defaultProps={removeClippedSubviews:false,showsHorizontalScrollIndicator:false,showsVerticalScrollIndicator:false,scrollEventThrottle:16,scrollEnabled:true};module.exports=ScrollCustom;
1
+ import React, { Component } from 'react';
2
+ import {
3
+ ScrollView
4
+ } from 'react-native';
5
+
6
+ class ScrollCustom extends Component {
7
+ constructor(props) {
8
+ super(props);
9
+ const { scrollEnabled } = this.props;
10
+ this.scrollEnabled = scrollEnabled;
11
+ this.state = {
12
+ scrollEnabled: this.scrollEnabled
13
+ };
14
+ }
15
+
16
+ scrollTo(event) {
17
+ if (event && this.ScrollView && this.ScrollView.scrollTo) {
18
+ this.ScrollView.scrollTo(event);
19
+ }
20
+ }
21
+
22
+ setScrollEnabled(enable) {
23
+ const { scrollEnabled } = this.state;
24
+ if (enable !== scrollEnabled) {
25
+ this.setState({
26
+ scrollEnabled: enable
27
+ });
28
+ }
29
+ }
30
+
31
+ render() {
32
+ const { children } = this.props;
33
+ const { scrollEnabled } = this.state;
34
+ return (
35
+ <ScrollView
36
+ ref={(refName) => {
37
+ this.ScrollView = refName;
38
+ }}
39
+ // eslint-disable-next-line react/jsx-props-no-spreading
40
+ {...this.props}
41
+ scrollEnabled={scrollEnabled}
42
+ >
43
+
44
+ {
45
+ children
46
+ }
47
+ </ScrollView>
48
+ );
49
+ }
50
+ }
51
+
52
+ ScrollCustom.defaultProps = {
53
+ removeClippedSubviews: false,
54
+ showsHorizontalScrollIndicator: false,
55
+ showsVerticalScrollIndicator: false,
56
+ scrollEventThrottle: 16,
57
+ scrollEnabled: true
58
+ };
59
+
60
+ module.exports = ScrollCustom;
@@ -1 +1,205 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var DatePickerHelper=function(){function DatePickerHelper(){(0,_classCallCheck2.default)(this,DatePickerHelper);}(0,_createClass2.default)(DatePickerHelper,null,[{key:"makeRange",value:function makeRange(min,max,isDouble){var array=[];for(var i=min;i<=max;i++){var string=String(i);var value=string.length===1&&isDouble?"0"+string:string;array.push(value);}return array;}},{key:"getCurrentDate",value:function getCurrentDate(format){if(format){var current=new Date();var day=current.getDate().toString();var month=(current.getMonth()+1).toString();var year=current.getFullYear().toString();return DatePickerHelper.toString(day,month,year,null,null,format);}return'';}},{key:"formatDate",value:function formatDate(date,format){if(date&&format){var _DatePickerHelper$get=DatePickerHelper.getDateTimeFromFormat(date,format),year=_DatePickerHelper$get.year,month=_DatePickerHelper$get.month,day=_DatePickerHelper$get.day,hour=_DatePickerHelper$get.hour,minute=_DatePickerHelper$get.minute,second=_DatePickerHelper$get.second;if(DatePickerHelper.checkValidDate(year,month,day)&&DatePickerHelper.checkValidTime(hour,minute,second)){return new Date(year,month,day,hour,minute,second);}return null;}return null;}},{key:"getDateTimeFromFormat",value:function getDateTimeFromFormat(date,format){if(date==null||format==null){return{year:null,month:null,day:null,hour:null,minute:null,second:null};}if(typeof date!=='string'){date=date.toString();}if(typeof format!=='string'){format=format.toString();}var normalized=date.replace(/[^a-zA-Z0-9]/g,'-');var normalizedFormat=format.replace(/[^a-zA-Z0-9]/g,'-');var formatItems=normalizedFormat.split('-');var dateItems=normalized.split('-');var monthIndex=formatItems.indexOf('MM');var dayIndex=formatItems.indexOf('dd');var yearIndex=formatItems.indexOf('YYYY');var hourIndex=formatItems.indexOf('hh');var minutesIndex=formatItems.indexOf('mm');var secondsIndex=formatItems.indexOf('ss');var today=new Date();var year=yearIndex>-1?dateItems==null?void 0:dateItems[yearIndex]:today.getFullYear();var month=monthIndex>-1?(dateItems==null?void 0:dateItems[monthIndex])-1:today.getMonth()===0?1:today.getMonth()-1;var day=dayIndex>-1?dateItems==null?void 0:dateItems[dayIndex]:today.getDate();var hour=hourIndex>-1?dateItems[hourIndex]:0;var minute=minutesIndex>-1?dateItems[minutesIndex]:0;var second=secondsIndex>-1?dateItems[secondsIndex]:0;return{year:year||null,month:month>=0?month:null,day:day||null,hour:hour||null,minute:minute||null,second:second||null};}},{key:"toString",value:function toString(day,month,year,hour,minute,format){if(day&&month&&year&&format){format=format.replace('YYYY',year);format=format.replace('MM',this.round(month));format=format.replace('dd',this.round(day));format=format.replace('hh',hour);format=format.replace('mm',minute);return format;}return null;}},{key:"checkValidDate",value:function checkValidDate(year,month,day){var months31=[0,2,4,6,7,9,11];var months30=[3,5,8,10];var months28=[1];var isLeap=year%4===0&&year%100!==0||year%400===0;if(year!=null&&month!=null&&day!=null){var isDayValid=day>0;var isMonthValid=months31.indexOf(month)!==-1&&day<=31||months30.indexOf(month)!==-1&&day<=30||months28.indexOf(month)!==-1&&day<=28||months28.indexOf(month)!==-1&&day<=29&&isLeap;return isDayValid&&isMonthValid;}return false;}},{key:"checkValidTime",value:function checkValidTime(hour,minute,second){if(hour>=0&&hour<24&&minute>=0&&minute<60&&second>=0&&second<60){return true;}return false;}},{key:"calculateDateSinceYearAgo",value:function calculateDateSinceYearAgo(yearAgo){var nowDate=new Date();nowDate=new Date(nowDate.getFullYear()-yearAgo,nowDate.getMonth(),nowDate.getDate());return nowDate;}},{key:"getMaxDate",value:function getMaxDate(){var month=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Date().getMonth();var year=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Date().getFullYear();var monthLength=[31,28,31,30,31,30,31,31,30,31,30,31];if(year%400===0||year%100!==0&&year%4===0){monthLength[1]=29;}return monthLength[month-1];}}]);return DatePickerHelper;}();exports.default=DatePickerHelper;DatePickerHelper.arrayRange=['00:00','00:30','01:00','01:30','02:00','02:30','03:00','03:30','04:00','04:30','05:00','05:30','06:00','06:30','07:00','07:30','08:00','08:30','09:00','09:30','10:00','10:30','11:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30','15:00','15:30','16:00','16:30','17:00','17:30','18:00','18:30','19:00','19:30','20:00','20:30','21:00','21:30','22:00','22:30','23:00','23:30'];DatePickerHelper.round=function(number){if(parseInt(number)>9){return number;}return"0"+number;};
1
+ /* eslint-disable prefer-template */
2
+ /* eslint-disable no-param-reassign */
3
+ export default class DatePickerHelper {
4
+ static arrayRange = [
5
+ '00:00',
6
+ '00:30',
7
+ '01:00',
8
+ '01:30',
9
+ '02:00',
10
+ '02:30',
11
+ '03:00',
12
+ '03:30',
13
+ '04:00',
14
+ '04:30',
15
+ '05:00',
16
+ '05:30',
17
+ '06:00',
18
+ '06:30',
19
+ '07:00',
20
+ '07:30',
21
+ '08:00',
22
+ '08:30',
23
+ '09:00',
24
+ '09:30',
25
+ '10:00',
26
+ '10:30',
27
+ '11:00',
28
+ '11:30',
29
+ '12:00',
30
+ '12:30',
31
+ '13:00',
32
+ '13:30',
33
+ '14:00',
34
+ '14:30',
35
+ '15:00',
36
+ '15:30',
37
+ '16:00',
38
+ '16:30',
39
+ '17:00',
40
+ '17:30',
41
+ '18:00',
42
+ '18:30',
43
+ '19:00',
44
+ '19:30',
45
+ '20:00',
46
+ '20:30',
47
+ '21:00',
48
+ '21:30',
49
+ '22:00',
50
+ '22:30',
51
+ '23:00',
52
+ '23:30'
53
+ ];
54
+
55
+ static makeRange(min, max, isDouble) {
56
+ const array = [];
57
+ // eslint-disable-next-line no-plusplus
58
+ for (let i = min; i <= max; i++) {
59
+ const string = String(i);
60
+ const value = string.length === 1 && isDouble ? `0${string}` : string;
61
+ array.push(value);
62
+ }
63
+ return array;
64
+ }
65
+
66
+ static getCurrentDate(format) {
67
+ if (format) {
68
+ const current = new Date();
69
+ const day = current.getDate().toString();
70
+ const month = (current.getMonth() + 1).toString();
71
+ const year = current.getFullYear().toString();
72
+ return DatePickerHelper.toString(day, month, year, null, null, format);
73
+ }
74
+ return '';
75
+ }
76
+
77
+ static formatDate(date, format) {
78
+ if (date && format) {
79
+ const {
80
+ year, month, day, hour, minute, second = 0
81
+ } = DatePickerHelper.getDateTimeFromFormat(date, format);
82
+ if (DatePickerHelper.checkValidDate(year, month, day)
83
+ && DatePickerHelper.checkValidTime(hour, minute, second)) {
84
+ return new Date(year, month, day, hour, minute, second);
85
+ }
86
+ return null;
87
+ }
88
+ return null;
89
+ }
90
+
91
+ static getDateTimeFromFormat(date, format) {
92
+ if (date == null || format == null) {
93
+ return {
94
+ year: null,
95
+ month: null,
96
+ day: null,
97
+ hour: null,
98
+ minute: null,
99
+ second: null,
100
+ };
101
+ }
102
+ if (typeof date !== 'string') {
103
+ date = date.toString();
104
+ }
105
+ if (typeof format !== 'string') {
106
+ format = format.toString();
107
+ }
108
+ const normalized = date.replace(/[^a-zA-Z0-9]/g, '-');
109
+ const normalizedFormat = format.replace(/[^a-zA-Z0-9]/g, '-');
110
+ const formatItems = normalizedFormat.split('-');
111
+ const dateItems = normalized.split('-');
112
+
113
+ const monthIndex = formatItems.indexOf('MM');
114
+ const dayIndex = formatItems.indexOf('dd');
115
+ const yearIndex = formatItems.indexOf('YYYY');
116
+ const hourIndex = formatItems.indexOf('hh');
117
+ const minutesIndex = formatItems.indexOf('mm');
118
+ const secondsIndex = formatItems.indexOf('ss');
119
+
120
+ const today = new Date();
121
+
122
+ const year = yearIndex > -1 ? dateItems?.[yearIndex] : today.getFullYear();
123
+ const month = monthIndex > -1 ? dateItems?.[monthIndex] - 1 : today.getMonth() === 0 ? 1 : today.getMonth() - 1;
124
+ const day = dayIndex > -1 ? dateItems?.[dayIndex] : today.getDate();
125
+
126
+ const hour = hourIndex > -1 ? dateItems[hourIndex] : 0;
127
+ const minute = minutesIndex > -1 ? dateItems[minutesIndex] : 0;
128
+ const second = secondsIndex > -1 ? dateItems[secondsIndex] : 0;
129
+
130
+ return {
131
+ year: year || null,
132
+ month: month >= 0 ? month : null,
133
+ day: day || null,
134
+ hour: hour || null,
135
+ minute: minute || null,
136
+ second: second || null,
137
+ };
138
+ }
139
+
140
+ static round = (number) => {
141
+ if (parseInt(number) > 9) {
142
+ return number;
143
+ }
144
+ return `0${number}`;
145
+ }
146
+
147
+ static toString(day, month, year, hour, minute, format) {
148
+ if (day && month && year && format) {
149
+ format = format.replace('YYYY', year);
150
+ format = format.replace('MM', this.round(month));
151
+ format = format.replace('dd', this.round(day));
152
+ format = format.replace('hh', hour);
153
+ format = format.replace('mm', minute);
154
+ return format;
155
+ }
156
+ return null;
157
+ }
158
+
159
+ static checkValidDate(y, m, d) {
160
+ const year = parseInt(y);
161
+ const month = parseInt(m);
162
+ const day = parseInt(d);
163
+ const months31 = [0, 2, 4, 6, 7, 9, 11];
164
+ const months30 = [3, 5, 8, 10];
165
+ const months28 = [1];
166
+ const isLeap = ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
167
+ if (year != null && month != null && day != null) {
168
+ const isDayValid = day > 0;
169
+ const isMonthValid = (months31.indexOf(parseInt(month)) != -1 && day <= 31)
170
+ || (months30.indexOf(month) != -1 && day <= 30)
171
+ || (months30.indexOf(month) != -1 && day <= 31)
172
+ || (months28.indexOf(month) != -1 && day <= 28)
173
+ || (months28.indexOf(month) != -1 && day <= 29 && isLeap);
174
+ return isDayValid && isMonthValid;
175
+ }
176
+ return false;
177
+ }
178
+
179
+ static checkValidTime(hour, minute, second) {
180
+ if ((hour >= 0 && hour < 24) && (minute >= 0 && minute < 60) && (second >= 0 && second < 60)) {
181
+ return true;
182
+ }
183
+ return false;
184
+ }
185
+
186
+ static calculateDateSinceYearAgo(yearAgo) {
187
+ let nowDate = new Date();
188
+ nowDate = new Date(nowDate.getFullYear() - yearAgo, nowDate.getMonth(), nowDate.getDate());
189
+ return nowDate;
190
+ }
191
+
192
+ static getMaxDate(month = new Date().getMonth(), year = new Date().getFullYear()) {
193
+ const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
194
+ // Adjust for leap years
195
+ if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
196
+ monthLength[1] = 29;
197
+ }
198
+
199
+ return monthLength[month - 1];
200
+ }
201
+
202
+ static capitalizeFirstLetter(string) {
203
+ return string.charAt(0).toUpperCase() + string.slice(1);
204
+ }
205
+ }
package/index.js CHANGED
@@ -1 +1,9 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"DatePicker",{enumerable:true,get:function get(){return _DatePicker.default;}});Object.defineProperty(exports,"DatePickerInput",{enumerable:true,get:function get(){return _DatePickerInput.default;}});var _DatePicker=_interopRequireDefault(require("./datePicker/DatePicker"));var _DatePickerInput=_interopRequireDefault(require("./datePicker/DatePickerInput"));
1
+ import DatePicker from './datePicker/DatePicker';
2
+ import DatePickerInput from './datePicker/DatePickerInput';
3
+ import ListPicker from './datePicker/ListPicker';
4
+
5
+ export {
6
+ DatePicker,
7
+ DatePickerInput,
8
+ ListPicker
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/date-picker",
3
- "version": "0.0.32-beta",
3
+ "version": "0.0.32",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},
@@ -8,16 +8,9 @@
8
8
  "react-native": ">=0.55",
9
9
  "prop-types": "^15.7.2",
10
10
  "react": "16.9.0",
11
- "lodash": "^4.17.15",
12
- "@momo-kits/core": "^0.0.5-beta"
11
+ "@momo-kits/core": ">=0.0.5-beta",
12
+ "lodash": "^4.17.15"
13
13
  },
14
- "devDependencies": {
15
- "metro-react-native-babel-preset": "^0.64.0",
16
- "@babel/core": "^7.12.9",
17
- "@babel/runtime": "^7.12.5"
18
- },
19
- "license": "MOMO",
20
- "jest": {
21
- "preset": "react-native"
22
- }
14
+ "devDependencies": {},
15
+ "license": "MoMo"
23
16
  }
package/publish.sh CHANGED
@@ -12,7 +12,7 @@ echo VERSION: $VERSION
12
12
  rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
13
 
14
14
  # #babel component to dist
15
- babel ./dist -d dist --copy-files
15
+ #babel ./dist -d dist --copy-files
16
16
 
17
17
  #copy option
18
18
  #cp -r ./src/ dist
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- echo '{"text": "@momo-kits/date-picker new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/date-picker"}'
29
+ curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/date-picker new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/date-picker"}'
package/babel.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports={presets:['module:metro-react-native-babel-preset']};