@nuitee/booking-widget 1.0.4 → 1.0.5

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/README.md CHANGED
@@ -94,15 +94,15 @@ widget.open();
94
94
  No bundler: load the script and CSS from the CDN, then create the widget.
95
95
 
96
96
  ```html
97
- <link rel="stylesheet" href="https://cdn.thehotelplanet.com/booking-widget/v1.0.0/dist/booking-widget.css">
98
- <script src="https://cdn.thehotelplanet.com/booking-widget/v1.0.0/dist/booking-widget-standalone.js"></script>
97
+ <link rel="stylesheet" href="https://cdn.thehotelplanet.com/booking-widget/v1.0.5/dist/booking-widget.css">
98
+ <script src="https://cdn.thehotelplanet.com/booking-widget/v1.0.5/dist/booking-widget-standalone.js"></script>
99
99
 
100
100
  <div id="booking-widget-container"></div>
101
101
 
102
102
  <script>
103
103
  const widget = new BookingWidget({
104
104
  containerId: 'booking-widget-container',
105
- cssUrl: 'https://cdn.thehotelplanet.com/booking-widget/v1.0.0/dist/booking-widget.css',
105
+ cssUrl: 'https://cdn.thehotelplanet.com/booking-widget/v1.0.5/dist/booking-widget.css',
106
106
  propertyKey: 'your-property-key',
107
107
  onOpen: () => console.log('Opened'),
108
108
  onClose: () => console.log('Closed'),
@@ -872,6 +872,7 @@ if (typeof window !== 'undefined') {
872
872
  var styles = { '--primary': primary, '--primary-fg': primaryFg, '--bg': bg, '--fg': fg, '--card-fg': fg };
873
873
  if (primaryRgb) styles['--primary-rgb'] = primaryRgb[0] + ', ' + primaryRgb[1] + ', ' + primaryRgb[2];
874
874
  styles['--card'] = c.card || (bgHsl ? 'hsl(' + bgHsl[0] + ', ' + bgHsl[1] + '%, ' + Math.min(95, bgHsl[2] + 2) + '%)' : bg);
875
+ styles['--card-solid'] = styles['--card'];
875
876
  if (bgHsl) {
876
877
  styles['--secondary'] = 'hsl(' + bgHsl[0] + ', ' + bgHsl[1] + '%, ' + Math.min(95, bgHsl[2] + 10) + '%)';
877
878
  styles['--border'] = 'hsl(' + bgHsl[0] + ', ' + bgHsl[1] + '%, ' + Math.min(95, bgHsl[2] + 14) + '%)';
@@ -1262,17 +1263,24 @@ if (typeof window !== 'undefined') {
1262
1263
  }
1263
1264
 
1264
1265
  injectCSS() {
1265
- if (document.getElementById('booking-widget-styles')) return;
1266
-
1267
- if (this.options.cssUrl) {
1268
- const link = document.createElement('link');
1269
- link.id = 'booking-widget-styles';
1270
- link.rel = 'stylesheet';
1271
- link.href = this.options.cssUrl;
1272
- document.head.appendChild(link);
1273
- } else {
1274
- // Inline CSS would go here in a real bundle
1275
- console.warn('CSS not loaded. Please include booking-widget.css or provide cssUrl option.');
1266
+ if (!document.getElementById('booking-widget-styles')) {
1267
+ if (this.options.cssUrl) {
1268
+ const link = document.createElement('link');
1269
+ link.id = 'booking-widget-styles';
1270
+ link.rel = 'stylesheet';
1271
+ link.href = this.options.cssUrl;
1272
+ document.head.appendChild(link);
1273
+ } else {
1274
+ // Inline CSS would go here in a real bundle
1275
+ console.warn('CSS not loaded. Please include booking-widget.css or provide cssUrl option.');
1276
+ }
1277
+ }
1278
+
1279
+ if (!document.getElementById('booking-widget-overrides')) {
1280
+ const style = document.createElement('style');
1281
+ style.id = 'booking-widget-overrides';
1282
+ style.textContent = '.booking-widget-modal .confirm-icon { font-size: 1em; }';
1283
+ document.head.appendChild(style);
1276
1284
  }
1277
1285
  }
1278
1286
 
@@ -1494,10 +1502,17 @@ if (typeof window !== 'undefined') {
1494
1502
  this.render();
1495
1503
  }
1496
1504
 
1497
- initCalendar() {
1498
- const now = new Date();
1499
- this.calendarMonth = now.getMonth();
1500
- this.calendarYear = now.getFullYear();
1505
+ // force=true resets the view when the user opens the picker.
1506
+ // - If a check-in date is already selected, starts from that month/year.
1507
+ // - Otherwise starts from today.
1508
+ // force=false (default) preserves the current month/year so mid-pick re-renders
1509
+ // don't snap the calendar back to the current month.
1510
+ initCalendar(force = false) {
1511
+ if (force || this.calendarMonth === null || this.calendarYear === null) {
1512
+ const anchor = this.state.checkIn || new Date();
1513
+ this.calendarMonth = anchor.getMonth();
1514
+ this.calendarYear = anchor.getFullYear();
1515
+ }
1501
1516
  // If we have check-in but no check-out, next click sets check-out; otherwise next click sets check-in (allows changing check-in when both are set)
1502
1517
  this.pickState = (this.state.checkIn && !this.state.checkOut) ? 1 : 0;
1503
1518
  }
@@ -1506,7 +1521,7 @@ if (typeof window !== 'undefined') {
1506
1521
  const popup = this.widget.querySelector('.calendar-popup');
1507
1522
  popup.classList.toggle('open');
1508
1523
  if (popup.classList.contains('open')) {
1509
- this.initCalendar();
1524
+ this.initCalendar(true);
1510
1525
  this.renderCalendar();
1511
1526
  }
1512
1527
  }
@@ -1562,10 +1577,14 @@ if (typeof window !== 'undefined') {
1562
1577
 
1563
1578
  pickDate(y, m, d) {
1564
1579
  const date = new Date(y, m, d);
1580
+ // Save the current view so render() cannot shift the calendar.
1581
+ const savedMonth = this.calendarMonth;
1582
+ const savedYear = this.calendarYear;
1565
1583
  if (this.pickState === 0 || (this.state.checkIn && date <= this.state.checkIn)) {
1566
1584
  this.state.checkIn = date; this.state.checkOut = null; this.pickState = 1;
1567
1585
  this.render();
1568
- this.initCalendar();
1586
+ // Restore view after render (render calls initCalendar which may reset month/year).
1587
+ if (savedMonth !== null) { this.calendarMonth = savedMonth; this.calendarYear = savedYear; }
1569
1588
  this.pickState = 1;
1570
1589
  const popup = this.widget.querySelector('.calendar-popup');
1571
1590
  if (popup) popup.classList.add('open');
@@ -84,6 +84,7 @@ function deriveWidgetStyles(c) {
84
84
  var styles = { '--primary': primary, '--primary-fg': primaryFg, '--bg': bg, '--fg': fg, '--card-fg': fg };
85
85
  if (primaryRgb) styles['--primary-rgb'] = primaryRgb[0] + ', ' + primaryRgb[1] + ', ' + primaryRgb[2];
86
86
  styles['--card'] = c.card || (bgHsl ? 'hsl(' + bgHsl[0] + ', ' + bgHsl[1] + '%, ' + Math.min(95, bgHsl[2] + 2) + '%)' : bg);
87
+ styles['--card-solid'] = styles['--card'];
87
88
  if (bgHsl) {
88
89
  styles['--secondary'] = 'hsl(' + bgHsl[0] + ', ' + bgHsl[1] + '%, ' + Math.min(95, bgHsl[2] + 10) + '%)';
89
90
  styles['--border'] = 'hsl(' + bgHsl[0] + ', ' + bgHsl[1] + '%, ' + Math.min(95, bgHsl[2] + 14) + '%)';
@@ -511,13 +512,20 @@ class BookingWidget {
511
512
  }
512
513
 
513
514
  injectCSS() {
514
- if (document.getElementById('booking-widget-styles')) return;
515
-
516
- const link = document.createElement('link');
517
- link.id = 'booking-widget-styles';
518
- link.rel = 'stylesheet';
519
- link.href = this.options.cssUrl || './booking-widget.css';
520
- document.head.appendChild(link);
515
+ if (!document.getElementById('booking-widget-styles')) {
516
+ const link = document.createElement('link');
517
+ link.id = 'booking-widget-styles';
518
+ link.rel = 'stylesheet';
519
+ link.href = this.options.cssUrl || './booking-widget.css';
520
+ document.head.appendChild(link);
521
+ }
522
+
523
+ if (!document.getElementById('booking-widget-overrides')) {
524
+ const style = document.createElement('style');
525
+ style.id = 'booking-widget-overrides';
526
+ style.textContent = '.booking-widget-modal .confirm-icon { font-size: 1em; }';
527
+ document.head.appendChild(style);
528
+ }
521
529
  }
522
530
 
523
531
  // ===== Render =====
@@ -763,10 +771,17 @@ class BookingWidget {
763
771
  }
764
772
 
765
773
  // --- Calendar ---
766
- initCalendar() {
767
- const now = new Date();
768
- this.calendarMonth = now.getMonth();
769
- this.calendarYear = now.getFullYear();
774
+ // force=true resets the view when the user opens the picker.
775
+ // - If a check-in date is already selected, starts from that month/year.
776
+ // - Otherwise starts from today.
777
+ // force=false (default) preserves the current month/year so mid-pick re-renders
778
+ // don't snap the calendar back to the current month.
779
+ initCalendar(force = false) {
780
+ if (force || this.calendarMonth === null || this.calendarYear === null) {
781
+ const anchor = this.state.checkIn || new Date();
782
+ this.calendarMonth = anchor.getMonth();
783
+ this.calendarYear = anchor.getFullYear();
784
+ }
770
785
  // If we have check-in but no check-out, next click sets check-out; otherwise next click sets check-in (allows changing check-in when both are set)
771
786
  this.pickState = (this.state.checkIn && !this.state.checkOut) ? 1 : 0;
772
787
  }
@@ -775,7 +790,7 @@ class BookingWidget {
775
790
  const popup = this.widget.querySelector('.calendar-popup');
776
791
  popup.classList.toggle('open');
777
792
  if (popup.classList.contains('open')) {
778
- this.initCalendar();
793
+ this.initCalendar(true);
779
794
  this.renderCalendar();
780
795
  }
781
796
  }
@@ -831,6 +846,9 @@ class BookingWidget {
831
846
 
832
847
  pickDate(y, m, d) {
833
848
  const date = new Date(y, m, d);
849
+ // Save the current view so render() cannot shift the calendar.
850
+ const savedMonth = this.calendarMonth;
851
+ const savedYear = this.calendarYear;
834
852
  if (this.pickState === 0 || (this.state.checkIn && date <= this.state.checkIn)) {
835
853
  this.state.checkIn = date; this.state.checkOut = null; this.pickState = 1;
836
854
  } else {
@@ -838,9 +856,9 @@ class BookingWidget {
838
856
  this.widget.querySelector('.calendar-popup').classList.remove('open');
839
857
  }
840
858
  this.render();
859
+ // Restore view after render (render calls initCalendar which may reset month/year).
860
+ if (savedMonth !== null) { this.calendarMonth = savedMonth; this.calendarYear = savedYear; }
841
861
  if (this.pickState === 1) {
842
- this.initCalendar();
843
- this.pickState = 1;
844
862
  const popup = this.widget.querySelector('.calendar-popup');
845
863
  if (popup) popup.classList.add('open');
846
864
  this.renderCalendar();
@@ -399,8 +399,6 @@ const BookingWidget = ({
399
399
  setCalendarOpen(false);
400
400
  }
401
401
  if (pickState === 0) {
402
- setCalendarMonth(new Date().getMonth());
403
- setCalendarYear(new Date().getFullYear());
404
402
  setPickState(1);
405
403
  }
406
404
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuitee/booking-widget",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A beautiful, customizable booking widget modal that can be embedded in any website. Supports vanilla JavaScript, React, and Vue.js.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",