@progressive-development/pd-calendar 0.0.12 → 0.0.14
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/package.json +1 -1
- package/src/PdCalendar.js +26 -33
package/package.json
CHANGED
package/src/PdCalendar.js
CHANGED
|
@@ -48,9 +48,7 @@ export class PdCalendar extends LitElement {
|
|
|
48
48
|
numberClass: { type: String },
|
|
49
49
|
|
|
50
50
|
_currentDate: { type: Object },
|
|
51
|
-
_viewType: { type: Number }
|
|
52
|
-
_latestDate: { type: Object },
|
|
53
|
-
_earliestDate: { type: Object },
|
|
51
|
+
_viewType: { type: Number }
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -178,33 +176,15 @@ export class PdCalendar extends LitElement {
|
|
|
178
176
|
this.data = {};
|
|
179
177
|
this._viewType = VIEW_MONTH;
|
|
180
178
|
this.numberClass = "top-left";
|
|
179
|
+
|
|
180
|
+
this._currentMonthNavNr = 0;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
connectedCallback() {
|
|
184
184
|
super.connectedCallback();
|
|
185
185
|
|
|
186
186
|
// get latest possible date
|
|
187
|
-
const ref = this.refDate || new Date();
|
|
188
|
-
if (this.nextMonthConstraint >= 0) {
|
|
189
|
-
const tmpDate = new Date(
|
|
190
|
-
ref.getFullYear(),
|
|
191
|
-
ref.getMonth() + 1,
|
|
192
|
-
0
|
|
193
|
-
);
|
|
194
|
-
tmpDate.setMonth(tmpDate.getMonth() + (this.nextMonthConstraint - 1));
|
|
195
|
-
this._latestDate = tmpDate;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// get earliest possible date
|
|
199
|
-
if (this.prevMonthConstraint >= 0) {
|
|
200
|
-
const tmpDate = new Date(
|
|
201
|
-
ref.getFullYear(),
|
|
202
|
-
ref.getMonth() + 1,
|
|
203
|
-
0
|
|
204
|
-
);
|
|
205
|
-
tmpDate.setMonth(tmpDate.getMonth() - (this.prevMonthConstraint));
|
|
206
|
-
this._earliestDate = tmpDate;
|
|
207
|
-
}
|
|
187
|
+
const ref = this.refDate || new Date();
|
|
208
188
|
|
|
209
189
|
// initialize date values with current date
|
|
210
190
|
this._initFromDate(ref);
|
|
@@ -261,6 +241,7 @@ export class PdCalendar extends LitElement {
|
|
|
261
241
|
?selectEnabled="${infoTxt !== undefined}"
|
|
262
242
|
?special="${special}"
|
|
263
243
|
numberClass="${this.numberClass}"
|
|
244
|
+
@select-date="${this._forwardEvent}"
|
|
264
245
|
></pd-calendar-cell>
|
|
265
246
|
`);
|
|
266
247
|
}
|
|
@@ -317,6 +298,7 @@ export class PdCalendar extends LitElement {
|
|
|
317
298
|
},
|
|
318
299
|
})
|
|
319
300
|
);
|
|
301
|
+
this._currentMonthNavNr += 1;
|
|
320
302
|
this._initFromDate(newDate);
|
|
321
303
|
}
|
|
322
304
|
}
|
|
@@ -336,14 +318,12 @@ export class PdCalendar extends LitElement {
|
|
|
336
318
|
},
|
|
337
319
|
})
|
|
338
320
|
);
|
|
321
|
+
this._currentMonthNavNr -= 1;
|
|
339
322
|
this._initFromDate(newDate);
|
|
340
323
|
}
|
|
341
324
|
}
|
|
342
325
|
|
|
343
326
|
_initFromDate(date) {
|
|
344
|
-
|
|
345
|
-
console.log("Init date with: ", date);
|
|
346
|
-
|
|
347
327
|
this._monthName = date.toLocaleString('default', { month: 'long' });
|
|
348
328
|
this._year = date.getFullYear();
|
|
349
329
|
this._daysFromPreviousMonth = PdCalendar._getPreviousMonthDays(date);
|
|
@@ -370,16 +350,29 @@ export class PdCalendar extends LitElement {
|
|
|
370
350
|
}
|
|
371
351
|
|
|
372
352
|
_checkNextMonthConstraint() {
|
|
373
|
-
if (this.
|
|
374
|
-
return this.
|
|
353
|
+
if (this.nextMonthConstraint > 0) {
|
|
354
|
+
return this.nextMonthConstraint > this._currentMonthNavNr;
|
|
355
|
+
}
|
|
356
|
+
if (this.nextMonthConstraint === -1) {
|
|
357
|
+
return true;
|
|
375
358
|
}
|
|
376
|
-
return
|
|
359
|
+
return false;
|
|
377
360
|
}
|
|
378
361
|
|
|
379
362
|
_checkPrevMonthConstraint() {
|
|
380
|
-
if (this.
|
|
381
|
-
return
|
|
363
|
+
if (this._currentMonthNavNr > 0 || this.prevMonthConstraint === -1) {
|
|
364
|
+
return true;
|
|
382
365
|
}
|
|
383
|
-
return
|
|
366
|
+
return this.prevMonthConstraint > (this._currentMonthNavNr * -1);
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Forward Event from Calendar Cell, could be refactored
|
|
371
|
+
_forwardEvent(e) {
|
|
372
|
+
this.dispatchEvent(
|
|
373
|
+
new CustomEvent('select-date', {
|
|
374
|
+
detail: e.detail
|
|
375
|
+
})
|
|
376
|
+
);
|
|
384
377
|
}
|
|
385
378
|
}
|