bookingsync-calendar-widget 2.0.2 → 2.0.3
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/bookingsync-calendar-widget.js +6288 -6269
- package/dist/bookingsync-calendar-widget.min.js +1 -1
- package/package.json +22 -25
- package/src/calendar.js +27 -14
- package/src/styles/calendar.scss +1 -0
- package/src/utils.js +9 -0
- package/CHANGELOG.md +0 -218
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bookingsync-calendar-widget",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "BookingSync Calendar Widget",
|
|
5
5
|
"main": "dist/bookingsync-calendar-widget.js",
|
|
6
6
|
"module": "src/bookingsync-calendar-widget.js",
|
|
@@ -15,51 +15,48 @@
|
|
|
15
15
|
"start": "webpack serve --open --config webpack.dev.js",
|
|
16
16
|
"test": "karma start karma.config.js --colors",
|
|
17
17
|
"test-ci": "karma start karma.config.js --single-run true",
|
|
18
|
-
"lint:js": "eslint ./*.js src
|
|
18
|
+
"lint:js": "eslint ./*.js src",
|
|
19
19
|
"mock-server": "node nodemon-start.js",
|
|
20
20
|
"preversion": "npm run lint:js && npm run test-ci",
|
|
21
21
|
"version": "npm run build && npm run dev && git add -A dist",
|
|
22
22
|
"postversion": "git push && git push --tags && rm -rf build/temp"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"npm-check-updates": "^11.8.5",
|
|
26
25
|
"popper.js": "^1.16.1",
|
|
27
26
|
"strtime": "^1.1.2",
|
|
28
27
|
"widget-utils": "0.5.0"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"@babel/cli": "^7.
|
|
32
|
-
"@babel/core": "^7.
|
|
30
|
+
"@babel/cli": "^7.16.0",
|
|
31
|
+
"@babel/core": "^7.16.0",
|
|
33
32
|
"@babel/polyfill": "^7.12.1",
|
|
34
|
-
"@babel/preset-env": "^7.
|
|
33
|
+
"@babel/preset-env": "^7.16.4",
|
|
35
34
|
"assert": "^2.0.0",
|
|
36
|
-
"babel-
|
|
37
|
-
"babel-loader": "^8.2.2",
|
|
35
|
+
"babel-loader": "^8.2.3",
|
|
38
36
|
"chai": "^4.3.4",
|
|
39
|
-
"css-loader": "^6.
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"eslint-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"karma": "^6.3.4",
|
|
37
|
+
"css-loader": "^6.5.1",
|
|
38
|
+
"eslint": "^8.4.1",
|
|
39
|
+
"eslint-webpack-plugin": "^3.1.1",
|
|
40
|
+
"json-server": "0.17.0",
|
|
41
|
+
"karma": "^6.3.9",
|
|
45
42
|
"karma-chai": "^0.1.0",
|
|
46
43
|
"karma-chrome-launcher": "^3.1.0",
|
|
47
44
|
"karma-mocha": "^2.0.1",
|
|
48
45
|
"karma-webpack": "5.0.0",
|
|
49
|
-
"mocha": "9.1.
|
|
50
|
-
"node-sass": "^
|
|
51
|
-
"nodemon": "^2.0.
|
|
52
|
-
"sass-loader": "^12.
|
|
53
|
-
"sinon": "^
|
|
54
|
-
"style-loader": "^3.
|
|
46
|
+
"mocha": "9.1.3",
|
|
47
|
+
"node-sass": "^7.0.0",
|
|
48
|
+
"nodemon": "^2.0.15",
|
|
49
|
+
"sass-loader": "^12.3.0",
|
|
50
|
+
"sinon": "^12.0.1",
|
|
51
|
+
"style-loader": "^3.3.1",
|
|
55
52
|
"tether": "2.0.0",
|
|
56
|
-
"timezone-mock": "1.2.
|
|
53
|
+
"timezone-mock": "1.2.2",
|
|
57
54
|
"util": "^0.12.4",
|
|
58
|
-
"webpack": "^5.
|
|
59
|
-
"webpack-cli": "^4.
|
|
60
|
-
"webpack-dev-server": "4.
|
|
55
|
+
"webpack": "^5.65.0",
|
|
56
|
+
"webpack-cli": "^4.9.1",
|
|
57
|
+
"webpack-dev-server": "4.6.0",
|
|
61
58
|
"webpack-merge": "^5.8.0",
|
|
62
|
-
"yargs": "17.
|
|
59
|
+
"yargs": "17.3.0"
|
|
63
60
|
},
|
|
64
61
|
"repository": {
|
|
65
62
|
"type": "git",
|
package/src/calendar.js
CHANGED
|
@@ -15,7 +15,7 @@ import locales from './locales';
|
|
|
15
15
|
import { strftime } from 'strtime';
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
|
-
dateToIso, isLater, isCurrent, validationOfCell, tFormatter, dateToArray
|
|
18
|
+
dateToIso, isLater, isCurrent, validationOfCell, tFormatter, dateToArray, monthDiff
|
|
19
19
|
} from './utils';
|
|
20
20
|
|
|
21
21
|
import styles from './styles/calendar.scss';
|
|
@@ -56,7 +56,7 @@ export default class Calendar extends Emitter {
|
|
|
56
56
|
|
|
57
57
|
this.opts.lang = (this.opts.lang && this.opts.lang in locales) ? this.opts.lang : 'en-US';
|
|
58
58
|
this.locale = locales[this.opts.lang];
|
|
59
|
-
this.format = this.opts.formatDate || this.locale.formatDate || '%
|
|
59
|
+
this.format = this.opts.formatDate || this.locale.formatDate || '%m/%d/%Y';
|
|
60
60
|
this.opts.startOfWeek = this.opts.startOfWeek || this.locale.startOfWeek;
|
|
61
61
|
|
|
62
62
|
let { currentDate } = this.opts;
|
|
@@ -105,18 +105,16 @@ export default class Calendar extends Emitter {
|
|
|
105
105
|
this.addBtnsEvents();
|
|
106
106
|
|
|
107
107
|
if (this.opts.selectable && this.opts.elStartAt && this.opts.elEndAt) {
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
this.opts.elStartAt.addEventListener('input', () => {
|
|
108
|
+
if (!this.opts.rentalId) {
|
|
111
109
|
this.inputsToValues();
|
|
112
|
-
}
|
|
110
|
+
}
|
|
113
111
|
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
this.on('maps-loaded', () => this.inputsToValues());
|
|
113
|
+
this.opts.elStartAt.addEventListener('input', () => this.inputsToValues());
|
|
114
|
+
this.opts.elEndAt.addEventListener('input', () => this.inputsToValues());
|
|
117
115
|
}
|
|
118
116
|
|
|
119
|
-
if (this.opts.rentalId) {
|
|
117
|
+
if (this.opts.rentalId && !this.opts.isDropDown) {
|
|
120
118
|
this.loadMaps(this.opts.rentalId);
|
|
121
119
|
}
|
|
122
120
|
|
|
@@ -559,7 +557,7 @@ export default class Calendar extends Emitter {
|
|
|
559
557
|
|
|
560
558
|
const tooltipPosition = (this.isReverseSelectable) ? left : right;
|
|
561
559
|
|
|
562
|
-
if (tooltipPosition && !this.hasValidRange) {
|
|
560
|
+
if (tooltipPosition && this.el.contains(cell) && !this.hasValidRange) {
|
|
563
561
|
this.dom.tooltip = this.el.appendChild(elementFromString(templates.tooltip));
|
|
564
562
|
this.dom.tooltip.querySelector('span').innerHTML = invalidRangeMessage;
|
|
565
563
|
|
|
@@ -846,20 +844,21 @@ export default class Calendar extends Emitter {
|
|
|
846
844
|
}
|
|
847
845
|
|
|
848
846
|
loadMaps(id) {
|
|
847
|
+
this.logger('loading maps');
|
|
849
848
|
this.toggleLoading();
|
|
850
849
|
|
|
851
850
|
const onSuccess = (maps) => {
|
|
852
|
-
this.toggleLoading();
|
|
853
|
-
|
|
854
851
|
if (isArray(maps.data) && maps.data[0].attributes) {
|
|
855
852
|
if (this.opts.disableAvailabityMap) {
|
|
856
853
|
maps.data[0].attributes.availability = maps.data[0].attributes.availability.replace(/[0-9]/g, '0');
|
|
857
854
|
}
|
|
858
855
|
this.opts.currency = this.opts.currency || maps.data[0].attributes.currency;
|
|
859
|
-
this.emit('maps-loaded', maps);
|
|
860
856
|
this.addMaps(maps.data[0].attributes);
|
|
861
857
|
this.mapsLoaded = true;
|
|
858
|
+
this.toggleLoading();
|
|
859
|
+
this.emit('maps-loaded', maps);
|
|
862
860
|
} else {
|
|
861
|
+
this.toggleLoading();
|
|
863
862
|
this.logger('expects json-api data format', 'error');
|
|
864
863
|
}
|
|
865
864
|
};
|
|
@@ -997,6 +996,10 @@ export default class Calendar extends Emitter {
|
|
|
997
996
|
}
|
|
998
997
|
|
|
999
998
|
inputsToValues() {
|
|
999
|
+
if (this.opts.elStartAt.value === '' && this.opts.elEndAt.value === '') {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1000
1003
|
const selectionStart = dateToArray(this.opts.elStartAt.value, this.format, this.locale);
|
|
1001
1004
|
const selectionEnd = dateToArray(this.opts.elEndAt.value, this.format, this.locale);
|
|
1002
1005
|
const { currentDate } = this.opts;
|
|
@@ -1005,10 +1008,20 @@ export default class Calendar extends Emitter {
|
|
|
1005
1008
|
|
|
1006
1009
|
if (isArray(selectionStart) && isArray(selectionEnd)) {
|
|
1007
1010
|
if (isLater(currentDate, selectionStart) && isLater(selectionStart, selectionEnd)) {
|
|
1011
|
+
const monthDifference = monthDiff(
|
|
1012
|
+
dateToIso(this.opts.yearStart, this.opts.monthStart, 1),
|
|
1013
|
+
dateToIso(...selectionEnd)
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
const { tree } = this.createTree(this.opts.yearStart, this.opts.monthStart, monthDifference);
|
|
1017
|
+
|
|
1018
|
+
this.cTree.addTree(tree);
|
|
1008
1019
|
this.selectionStart = selectionStart;
|
|
1009
1020
|
this.selectionEnd = selectionEnd;
|
|
1010
1021
|
this.recoverSelections();
|
|
1011
1022
|
this.completeSelection();
|
|
1023
|
+
this.destroyMonths();
|
|
1024
|
+
this.renderMonths(selectionEnd[0], selectionEnd[1]);
|
|
1012
1025
|
} else {
|
|
1013
1026
|
this.logger(`invalid range: "[${selectionStart}]" "[${selectionEnd}]"`, 'warn');
|
|
1014
1027
|
return false;
|
package/src/styles/calendar.scss
CHANGED
package/src/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* global console */
|
|
1
2
|
import { strftime, strptime } from 'strtime';
|
|
2
3
|
import { is } from 'widget-utils';
|
|
3
4
|
|
|
@@ -21,12 +22,16 @@ export const dateToArray = (val, format, locale) => {
|
|
|
21
22
|
try {
|
|
22
23
|
const date = strptime(val, format, locale);
|
|
23
24
|
const a = strftime(date, '%Y-%m-%d').split('-');
|
|
25
|
+
|
|
24
26
|
return [
|
|
25
27
|
parseInt(a[0]), // year
|
|
26
28
|
parseInt(a[1] - 1), // month index
|
|
27
29
|
parseInt(a[2]) // day
|
|
28
30
|
];
|
|
29
31
|
} catch(e) {
|
|
32
|
+
if (is(e.message)) {
|
|
33
|
+
console.log(e.message);
|
|
34
|
+
}
|
|
30
35
|
return false;
|
|
31
36
|
}
|
|
32
37
|
};
|
|
@@ -35,6 +40,10 @@ export const isLater = (start, end) => dateToIso(...start, true) < dateToIso(...
|
|
|
35
40
|
|
|
36
41
|
export const isCurrent = (start, end) => dateToIso(...start, true) == dateToIso(...end, true);
|
|
37
42
|
|
|
43
|
+
export const monthDiff = (start, end) => {
|
|
44
|
+
return end.getMonth() - start.getMonth() + (12 * (end.getFullYear() - start.getFullYear()));
|
|
45
|
+
};
|
|
46
|
+
|
|
38
47
|
export const validationOfCell = (cell) => {
|
|
39
48
|
if (is(cell.dataset.enabled) || is(cell.dataset.availableIn) || is(cell.dataset.availableOut)) {
|
|
40
49
|
return true;
|
package/CHANGELOG.md
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
All notable changes to this project will be documented in this file.
|
|
3
|
-
|
|
4
|
-
## [2.0.2] - 2021-09-10
|
|
5
|
-
### Fixed
|
|
6
|
-
- issue when data start from a past date that would set current date as unavailable
|
|
7
|
-
|
|
8
|
-
## [2.0.1] - 2021-09-10
|
|
9
|
-
### Reverted
|
|
10
|
-
- show minStay & maxStay
|
|
11
|
-
### Fixed
|
|
12
|
-
- min/max stay: get the biggest value from the range instead of first cell's
|
|
13
|
-
- issue when yesterday's cell is available and today's not
|
|
14
|
-
- issue on today's cell when the calendar has no rental
|
|
15
|
-
|
|
16
|
-
## [2.0.0] - 2021-09-01
|
|
17
|
-
### Added
|
|
18
|
-
- cancel selection when clicking on the first selected date
|
|
19
|
-
- select in both direction on mouseover
|
|
20
|
-
- show tooltip if selection is not valid (minstay or booked)
|
|
21
|
-
- invalid selection stays highlighted until you select new dates
|
|
22
|
-
### Updated
|
|
23
|
-
- hover handler moved to JS
|
|
24
|
-
|
|
25
|
-
## [1.5.0] - 2021-05-28
|
|
26
|
-
### Added
|
|
27
|
-
- css var() for date ranges bg-color & color
|
|
28
|
-
### Updated
|
|
29
|
-
- date ranges style, linar gradients no longer used
|
|
30
|
-
### Fixed
|
|
31
|
-
- css class naming (bookingsyncCalendarWidget => BookingSyncCalendarWidget__calendar)
|
|
32
|
-
|
|
33
|
-
## [1.4.8] - 2021-05-26
|
|
34
|
-
### Fixed
|
|
35
|
-
- `maxStay` blocking highlight range
|
|
36
|
-
|
|
37
|
-
## [1.4.7] - 2021-03-04
|
|
38
|
-
### Added
|
|
39
|
-
- `nl-NL` language
|
|
40
|
-
|
|
41
|
-
## [1.4.6] - 2020-10-30
|
|
42
|
-
### Added
|
|
43
|
-
- `maxStay` option to limit the number of selectable nights
|
|
44
|
-
- Russian and Polish languages
|
|
45
|
-
|
|
46
|
-
## [1.4.5] - 2020-01-23
|
|
47
|
-
### Fixed
|
|
48
|
-
- inputsToValues method was called too early
|
|
49
|
-
|
|
50
|
-
## [1.4.4] - 2020-01-03
|
|
51
|
-
### Added
|
|
52
|
-
- inputsToValues method (reads inputs values to set dates selection)
|
|
53
|
-
|
|
54
|
-
## [1.4.3] - 2019-12-02
|
|
55
|
-
### Fixed
|
|
56
|
-
- GMT +00 issue
|
|
57
|
-
|
|
58
|
-
## [1.4.2] - 2019-08-24
|
|
59
|
-
### Updated
|
|
60
|
-
- Removed `Open Sans` font
|
|
61
|
-
### Fixed
|
|
62
|
-
- Now fully working on IE11 / Edge
|
|
63
|
-
|
|
64
|
-
## [1.4.1] - 2019-07-16
|
|
65
|
-
### Updated
|
|
66
|
-
- Moved Reset styles to `widget-utils` module
|
|
67
|
-
|
|
68
|
-
## [1.4.0] - 2019-07-16
|
|
69
|
-
### Fixed
|
|
70
|
-
- Global variables
|
|
71
|
-
### Updated
|
|
72
|
-
- Namespace `BookingSyncCalendarWidget` to `bookingsyncCalendarWidget`
|
|
73
|
-
|
|
74
|
-
## [1.3.4] - 2019-07-09
|
|
75
|
-
### Fixed
|
|
76
|
-
- Day-1 Timezone issue
|
|
77
|
-
|
|
78
|
-
## [1.3.3] - 2019-06-21
|
|
79
|
-
### Added
|
|
80
|
-
- Export `Popper.js`
|
|
81
|
-
### Fixed
|
|
82
|
-
- Input touch event on Android devices
|
|
83
|
-
|
|
84
|
-
## [1.3.2] - 2019-06-06
|
|
85
|
-
### Fixed
|
|
86
|
-
- `hiddenElFormat` now removes the attribute `name` of the visible input
|
|
87
|
-
|
|
88
|
-
## [1.3.0] - 2019-03-31
|
|
89
|
-
### Added
|
|
90
|
-
- `resetSelectionOnEscape` Resets selection with Escape key
|
|
91
|
-
- Option `enableAllDays` Force past days/months to be selectable
|
|
92
|
-
### Fixed
|
|
93
|
-
- Past days were not disabled within the current month
|
|
94
|
-
### Updated
|
|
95
|
-
- Webpack Config, dev version under `bookingsync-calendar-widget.dev.js`, production version unminified under `bookingsync-calendar-widget.js`
|
|
96
|
-
- Demo `index.html`
|
|
97
|
-
- README
|
|
98
|
-
|
|
99
|
-
## [1.2.4] - 2019-01-18
|
|
100
|
-
### Updated
|
|
101
|
-
- `disableAvailabityMap` & `allowShorterMinStaySelection` default values
|
|
102
|
-
- README.md
|
|
103
|
-
|
|
104
|
-
## [1.2.3] - 2019-01-15
|
|
105
|
-
### Fixed
|
|
106
|
-
- Update single-input value on init
|
|
107
|
-
|
|
108
|
-
## [1.2.2] - 2019-01-12
|
|
109
|
-
### Added
|
|
110
|
-
- Expose `widget-utils` under `window.BookingSyncWidgetUtils`
|
|
111
|
-
### Fixed
|
|
112
|
-
- CHANGELOG.md
|
|
113
|
-
|
|
114
|
-
## [1.2.1] - 2019-01-11
|
|
115
|
-
### Added
|
|
116
|
-
- Option `disableAvailabityMap` & `allowShorterMinStaySelection`
|
|
117
|
-
|
|
118
|
-
## [1.2.0] - 2018-12-27
|
|
119
|
-
### Added
|
|
120
|
-
- Option `singleInputDateFormat`
|
|
121
|
-
- Cancel selection on invalid day click
|
|
122
|
-
- Locales aliases (eg: `en` = `en-US`)
|
|
123
|
-
### Fixed
|
|
124
|
-
- Minor fixes
|
|
125
|
-
|
|
126
|
-
## [1.1.0] - 2018-12-27
|
|
127
|
-
### Added
|
|
128
|
-
- Single input with date range value
|
|
129
|
-
- Single input example in `index.html`
|
|
130
|
-
- Default classes for inputs
|
|
131
|
-
### Fixed
|
|
132
|
-
- Minor fixes
|
|
133
|
-
|
|
134
|
-
## [1.0.0] - 2018-10-2
|
|
135
|
-
### Changed
|
|
136
|
-
- `TetherDrop` to `Popper.js`
|
|
137
|
-
- Use lang `en-US` as default instead of browser lang
|
|
138
|
-
### Added
|
|
139
|
-
- Use string date parser (e.g. %Y-%m-%d)
|
|
140
|
-
- Hidden inputs with different date format (optionnal)
|
|
141
|
-
- Use locale with country code
|
|
142
|
-
### Fixed
|
|
143
|
-
- Minor fixes
|
|
144
|
-
|
|
145
|
-
## [0.3.0] - 2018-09-18
|
|
146
|
-
### Fixed
|
|
147
|
-
- Switch from `Yarn` to `Npm`
|
|
148
|
-
- Migrate to `CircleCI v2`, `WebPack v3` and `Babel v7`
|
|
149
|
-
- Fix `currency` and `API calls`
|
|
150
|
-
- Add `date-range` from inputs
|
|
151
|
-
- Update `eslint` rules
|
|
152
|
-
|
|
153
|
-
## [0.2.4] - 2017-08-14
|
|
154
|
-
### Fixed
|
|
155
|
-
- handling adding js-script with async attribute
|
|
156
|
-
|
|
157
|
-
## [0.2.3] - 2017-08-14
|
|
158
|
-
### Fixed
|
|
159
|
-
- minor fixes
|
|
160
|
-
|
|
161
|
-
## [0.2.2] - 2017-08-14
|
|
162
|
-
### Fixed
|
|
163
|
-
- dist file
|
|
164
|
-
|
|
165
|
-
## [0.2.1] - 2017-07-10
|
|
166
|
-
### Fixed
|
|
167
|
-
- Chrome Number formatting
|
|
168
|
-
|
|
169
|
-
## [0.1.1] - 2017-02-23
|
|
170
|
-
### Added
|
|
171
|
-
- Dispatch 'change' event on inputs.
|
|
172
|
-
|
|
173
|
-
### Changed
|
|
174
|
-
- 'currencyFormatter' moved to 'widget-utils' module.
|
|
175
|
-
### Fixed
|
|
176
|
-
- 'onSelectionCompleted' call back params.
|
|
177
|
-
|
|
178
|
-
## [0.1.0] - 2017-02-20
|
|
179
|
-
### Added
|
|
180
|
-
- Display currency from maps request.
|
|
181
|
-
- Locale based price and currency format.
|
|
182
|
-
- Currency to locale (as fallback).
|
|
183
|
-
- `onSelectionCompleted` callback.
|
|
184
|
-
- Prices are rounded now.
|
|
185
|
-
- Better Logger.
|
|
186
|
-
- Tests.
|
|
187
|
-
|
|
188
|
-
### Changed
|
|
189
|
-
- Scripts for mocks.
|
|
190
|
-
- Styles for rates:
|
|
191
|
-
- smaller font,
|
|
192
|
-
- month min-width was increased to 27rem to accommodate prices.
|
|
193
|
-
|
|
194
|
-
## [0.0.17] - 2017-02-14
|
|
195
|
-
### Added
|
|
196
|
-
- New styles for view with rates and min-stay.
|
|
197
|
-
|
|
198
|
-
### Changed
|
|
199
|
-
- Translations for `rate` and `minStay` to use interpolations with numbers.
|
|
200
|
-
|
|
201
|
-
## [0.0.16] - 2017-02-03
|
|
202
|
-
### Added
|
|
203
|
-
- `VERSION` property on `BookingSyncCalendar` global.
|
|
204
|
-
- More event loggers.
|
|
205
|
-
- CHANGELOG.md to track changes.
|
|
206
|
-
|
|
207
|
-
### Changed
|
|
208
|
-
- Minor style changes
|
|
209
|
-
|
|
210
|
-
### Fixed
|
|
211
|
-
- Maps offset bug
|
|
212
|
-
|
|
213
|
-
## [0.0.14] - 2017-02-02
|
|
214
|
-
### Added
|
|
215
|
-
- Filled README.md with params, events and examples.
|
|
216
|
-
|
|
217
|
-
### Fixed
|
|
218
|
-
- Timezone offset in calculating start of the month.
|