@easepick/lock-plugin
Advanced tools
Comparing version 1.0.1-beta.0 to 1.0.1-beta.1
@@ -1,263 +0,1 @@ | ||
import { DateTime } from '@easepick/datetime'; | ||
import { BasePlugin } from '@easepick/base-plugin'; | ||
class LockPlugin extends BasePlugin { | ||
priority = 1; | ||
binds = { | ||
onView: this.onView.bind(this), | ||
}; | ||
options = { | ||
minDate: null, | ||
maxDate: null, | ||
minDays: null, | ||
maxDays: null, | ||
selectForward: null, | ||
selectBackward: null, | ||
presets: true, | ||
inseparable: false, | ||
filter: null, | ||
}; | ||
/** | ||
* Returns plugin name | ||
* | ||
* @returns String | ||
*/ | ||
getName() { | ||
return 'LockPlugin'; | ||
} | ||
/** | ||
* - Called automatically via BasePlugin.attach() - | ||
* The function execute on initialize the picker | ||
*/ | ||
onAttach() { | ||
if (this.options.minDate) { | ||
this.options.minDate = new DateTime(this.options.minDate, this.picker.options.format, this.picker.options.lang); | ||
} | ||
if (this.options.maxDate) { | ||
this.options.maxDate = new DateTime(this.options.maxDate, this.picker.options.format, this.picker.options.lang); | ||
} | ||
if (this.options.minDays | ||
|| this.options.maxDays | ||
|| this.options.selectForward | ||
|| this.options.selectBackward) { | ||
if (!this.picker.options.plugins.includes('RangePlugin')) { | ||
const list = ['minDays', 'maxDays', 'selectForward', 'selectBackward']; | ||
console.warn(`${this.getName()}: options ${list.join(', ')} required RangePlugin.`); | ||
} | ||
} | ||
this.picker.on('view', this.binds.onView); | ||
} | ||
/** | ||
* - Called automatically via BasePlugin.attach() - | ||
* The function execute on initialize the picker | ||
*/ | ||
onDetach() { | ||
this.picker.off('view', this.binds.onView); | ||
} | ||
/** | ||
* Function `view` event | ||
* Mark day elements as locked | ||
* | ||
* @param event | ||
*/ | ||
onView(event) { | ||
const { view, target, date } = event.detail; | ||
if (view === 'CalendarHeader') { | ||
if (this.options.minDate instanceof DateTime) { | ||
if (date.isSameOrBefore(this.options.minDate, 'month')) { | ||
target.classList.add('no-previous-month'); | ||
} | ||
} | ||
if (this.options.maxDate instanceof DateTime) { | ||
if (date.isSameOrAfter(this.options.maxDate, 'month')) { | ||
target.classList.add('no-next-month'); | ||
} | ||
} | ||
} | ||
if (view === 'CalendarDay') { | ||
const dateFrom = this.picker.datePicked.length ? this.picker.datePicked[0] : null; | ||
if (this.testFilter(date)) { | ||
target.classList.add('locked'); | ||
return; | ||
} | ||
if (this.options.inseparable) { | ||
if (this.options.minDays) { | ||
const date1 = date.clone().subtract(this.options.minDays - 1, 'day'); | ||
const date2 = date.clone().add(this.options.minDays - 1, 'day'); | ||
let lockedInPrevDays = false; | ||
let lockedInNextDays = false; | ||
while (date1.isBefore(date, 'day')) { | ||
if (this.testFilter(date1)) { | ||
lockedInPrevDays = true; | ||
break; | ||
} | ||
date1.add(1, 'day'); | ||
} | ||
while (date2.isAfter(date, 'day')) { | ||
if (this.testFilter(date2)) { | ||
lockedInNextDays = true; | ||
break; | ||
} | ||
date2.subtract(1, 'day'); | ||
} | ||
if (lockedInPrevDays && lockedInNextDays) { | ||
target.classList.add('not-available'); | ||
} | ||
} | ||
if (this.rangeIsNotAvailable(date, dateFrom)) { | ||
target.classList.add('not-available'); | ||
} | ||
} | ||
if (this.dateIsNotAvailable(date, dateFrom)) { | ||
target.classList.add('not-available'); | ||
} | ||
} | ||
if (this.options.presets && view === 'PresetPluginButton') { | ||
const startDate = new DateTime(Number(target.dataset.start)); | ||
const endDate = new DateTime(Number(target.dataset.end)); | ||
const diff = endDate.diff(startDate, 'day'); | ||
const lessMinDays = this.options.minDays && diff < this.options.minDays; | ||
const moreMaxDays = this.options.maxDays && diff > this.options.maxDays; | ||
if (lessMinDays || moreMaxDays | ||
|| this.lockMinDate(startDate) | ||
|| this.lockMaxDate(startDate) | ||
|| this.lockMinDate(endDate) | ||
|| this.lockMaxDate(endDate) | ||
|| this.rangeIsNotAvailable(startDate, endDate)) { | ||
target.setAttribute('disabled', 'disabled'); | ||
} | ||
} | ||
} | ||
/** | ||
* Checks availability date | ||
* | ||
* @param date | ||
* @param start | ||
* @returns Boolean | ||
*/ | ||
dateIsNotAvailable(date, start) { | ||
return this.lockMinDate(date) | ||
|| this.lockMaxDate(date) | ||
|| this.lockMinDays(date, start) | ||
|| this.lockMaxDays(date, start) | ||
|| this.lockSelectForward(date) | ||
|| this.lockSelectBackward(date); | ||
} | ||
/** | ||
* Checks the date range for availability | ||
* | ||
* @param date1 | ||
* @param date2 | ||
* @returns Boolean | ||
*/ | ||
rangeIsNotAvailable(date1, date2) { | ||
if (!date1 || !date2) | ||
return false; | ||
const start = (date1.isSameOrBefore(date2, 'day') ? date1 : date2).clone(); | ||
const end = (date2.isSameOrAfter(date1, 'day') ? date2 : date1).clone(); | ||
while (start.isSameOrBefore(end, 'day')) { | ||
if (this.testFilter(start)) { | ||
return true; | ||
} | ||
start.add(1, 'day'); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `minDate` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMinDate(date) { | ||
return this.options.minDate instanceof DateTime | ||
? date.isBefore(this.options.minDate, 'day') | ||
: false; | ||
} | ||
/** | ||
* Handle `maxDate` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMaxDate(date) { | ||
return this.options.maxDate instanceof DateTime | ||
? date.isAfter(this.options.maxDate, 'day') | ||
: false; | ||
} | ||
/** | ||
* Handle `minDays` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMinDays(date, start) { | ||
if (this.options.minDays && start) { | ||
const minPrev = start | ||
.clone() | ||
.subtract(this.options.minDays - 1, 'day'); | ||
const minNext = start | ||
.clone() | ||
.add(this.options.minDays - 1, 'day'); | ||
return date.isBetween(minPrev, minNext); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `maxDays` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMaxDays(date, start) { | ||
if (this.options.maxDays && start) { | ||
const maxPrev = start | ||
.clone() | ||
.subtract(this.options.maxDays, 'day'); | ||
const maxNext = start | ||
.clone() | ||
.add(this.options.maxDays, 'day'); | ||
return !date.isBetween(maxPrev, maxNext); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `selectForward` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockSelectForward(date) { | ||
if (this.picker.datePicked.length === 1 && this.options.selectForward) { | ||
const start = this.picker.datePicked[0].clone(); | ||
return date.isAfter(start, 'day'); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `selectBackward` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockSelectBackward(date) { | ||
if (this.picker.datePicked.length === 1 && this.options.selectBackward) { | ||
const start = this.picker.datePicked[0].clone(); | ||
return date.isBefore(start, 'day'); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `filter` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
testFilter(date) { | ||
return typeof this.options.filter === 'function' | ||
? this.options.filter(date, this.picker.datePicked) | ||
: false; | ||
} | ||
} | ||
export { LockPlugin }; | ||
import{DateTime as t}from"@easepick/datetime";import{BasePlugin as i}from"@easepick/base-plugin";class s extends i{priority=1;binds={onView:this.onView.bind(this)};options={minDate:null,maxDate:null,minDays:null,maxDays:null,selectForward:null,selectBackward:null,presets:!0,inseparable:!1,filter:null};getName(){return"LockPlugin"}onAttach(){if(this.options.minDate&&(this.options.minDate=new t(this.options.minDate,this.picker.options.format,this.picker.options.lang)),this.options.maxDate&&(this.options.maxDate=new t(this.options.maxDate,this.picker.options.format,this.picker.options.lang)),(this.options.minDays||this.options.maxDays||this.options.selectForward||this.options.selectBackward)&&!this.picker.options.plugins.includes("RangePlugin")){const t=["minDays","maxDays","selectForward","selectBackward"];console.warn(`${this.getName()}: options ${t.join(", ")} required RangePlugin.`)}this.picker.on("view",this.binds.onView)}onDetach(){this.picker.off("view",this.binds.onView)}onView(i){const{view:s,target:e,date:a}=i.detail;if("CalendarHeader"===s&&(this.options.minDate instanceof t&&a.isSameOrBefore(this.options.minDate,"month")&&e.classList.add("no-previous-month"),this.options.maxDate instanceof t&&a.isSameOrAfter(this.options.maxDate,"month")&&e.classList.add("no-next-month")),"CalendarDay"===s){const t=this.picker.datePicked.length?this.picker.datePicked[0]:null;if(this.testFilter(a))return void e.classList.add("locked");if(this.options.inseparable){if(this.options.minDays){const t=a.clone().subtract(this.options.minDays-1,"day"),i=a.clone().add(this.options.minDays-1,"day");let s=!1,o=!1;for(;t.isBefore(a,"day");){if(this.testFilter(t)){s=!0;break}t.add(1,"day")}for(;i.isAfter(a,"day");){if(this.testFilter(i)){o=!0;break}i.subtract(1,"day")}s&&o&&e.classList.add("not-available")}this.rangeIsNotAvailable(a,t)&&e.classList.add("not-available")}this.dateIsNotAvailable(a,t)&&e.classList.add("not-available")}if(this.options.presets&&"PresetPluginButton"===s){const i=new t(Number(e.dataset.start)),s=new t(Number(e.dataset.end)),a=s.diff(i,"day"),o=this.options.minDays&&a<this.options.minDays,n=this.options.maxDays&&a>this.options.maxDays;(o||n||this.lockMinDate(i)||this.lockMaxDate(i)||this.lockMinDate(s)||this.lockMaxDate(s)||this.rangeIsNotAvailable(i,s))&&e.setAttribute("disabled","disabled")}}dateIsNotAvailable(t,i){return this.lockMinDate(t)||this.lockMaxDate(t)||this.lockMinDays(t,i)||this.lockMaxDays(t,i)||this.lockSelectForward(t)||this.lockSelectBackward(t)}rangeIsNotAvailable(t,i){if(!t||!i)return!1;const s=(t.isSameOrBefore(i,"day")?t:i).clone(),e=(i.isSameOrAfter(t,"day")?i:t).clone();for(;s.isSameOrBefore(e,"day");){if(this.testFilter(s))return!0;s.add(1,"day")}return!1}lockMinDate(i){return this.options.minDate instanceof t&&i.isBefore(this.options.minDate,"day")}lockMaxDate(i){return this.options.maxDate instanceof t&&i.isAfter(this.options.maxDate,"day")}lockMinDays(t,i){if(this.options.minDays&&i){const s=i.clone().subtract(this.options.minDays-1,"day"),e=i.clone().add(this.options.minDays-1,"day");return t.isBetween(s,e)}return!1}lockMaxDays(t,i){if(this.options.maxDays&&i){const s=i.clone().subtract(this.options.maxDays,"day"),e=i.clone().add(this.options.maxDays,"day");return!t.isBetween(s,e)}return!1}lockSelectForward(t){if(1===this.picker.datePicked.length&&this.options.selectForward){const i=this.picker.datePicked[0].clone();return t.isAfter(i,"day")}return!1}lockSelectBackward(t){if(1===this.picker.datePicked.length&&this.options.selectBackward){const i=this.picker.datePicked[0].clone();return t.isBefore(i,"day")}return!1}testFilter(t){return"function"==typeof this.options.filter&&this.options.filter(t,this.picker.datePicked)}}export{s as LockPlugin}; |
/** | ||
* @license | ||
* Package: @easepick/lock-plugin | ||
* Version: 1.0.0 | ||
* Version: 1.0.1-beta.0 | ||
* https://easepick.com/ | ||
@@ -10,271 +10,2 @@ * Copyright 2022 Rinat G. | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@easepick/datetime'), require('@easepick/base-plugin')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@easepick/datetime', '@easepick/base-plugin'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.easepick = global.easepick || {}, global.easepick, global.easepick)); | ||
})(this, (function (exports, datetime, basePlugin) { 'use strict'; | ||
class LockPlugin extends basePlugin.BasePlugin { | ||
priority = 1; | ||
binds = { | ||
onView: this.onView.bind(this), | ||
}; | ||
options = { | ||
minDate: null, | ||
maxDate: null, | ||
minDays: null, | ||
maxDays: null, | ||
selectForward: null, | ||
selectBackward: null, | ||
presets: true, | ||
inseparable: false, | ||
filter: null, | ||
}; | ||
/** | ||
* Returns plugin name | ||
* | ||
* @returns String | ||
*/ | ||
getName() { | ||
return 'LockPlugin'; | ||
} | ||
/** | ||
* - Called automatically via BasePlugin.attach() - | ||
* The function execute on initialize the picker | ||
*/ | ||
onAttach() { | ||
if (this.options.minDate) { | ||
this.options.minDate = new datetime.DateTime(this.options.minDate, this.picker.options.format, this.picker.options.lang); | ||
} | ||
if (this.options.maxDate) { | ||
this.options.maxDate = new datetime.DateTime(this.options.maxDate, this.picker.options.format, this.picker.options.lang); | ||
} | ||
if (this.options.minDays | ||
|| this.options.maxDays | ||
|| this.options.selectForward | ||
|| this.options.selectBackward) { | ||
if (!this.picker.options.plugins.includes('RangePlugin')) { | ||
const list = ['minDays', 'maxDays', 'selectForward', 'selectBackward']; | ||
console.warn(`${this.getName()}: options ${list.join(', ')} required RangePlugin.`); | ||
} | ||
} | ||
this.picker.on('view', this.binds.onView); | ||
} | ||
/** | ||
* - Called automatically via BasePlugin.attach() - | ||
* The function execute on initialize the picker | ||
*/ | ||
onDetach() { | ||
this.picker.off('view', this.binds.onView); | ||
} | ||
/** | ||
* Function `view` event | ||
* Mark day elements as locked | ||
* | ||
* @param event | ||
*/ | ||
onView(event) { | ||
const { view, target, date } = event.detail; | ||
if (view === 'CalendarHeader') { | ||
if (this.options.minDate instanceof datetime.DateTime) { | ||
if (date.isSameOrBefore(this.options.minDate, 'month')) { | ||
target.classList.add('no-previous-month'); | ||
} | ||
} | ||
if (this.options.maxDate instanceof datetime.DateTime) { | ||
if (date.isSameOrAfter(this.options.maxDate, 'month')) { | ||
target.classList.add('no-next-month'); | ||
} | ||
} | ||
} | ||
if (view === 'CalendarDay') { | ||
const dateFrom = this.picker.datePicked.length ? this.picker.datePicked[0] : null; | ||
if (this.testFilter(date)) { | ||
target.classList.add('locked'); | ||
return; | ||
} | ||
if (this.options.inseparable) { | ||
if (this.options.minDays) { | ||
const date1 = date.clone().subtract(this.options.minDays - 1, 'day'); | ||
const date2 = date.clone().add(this.options.minDays - 1, 'day'); | ||
let lockedInPrevDays = false; | ||
let lockedInNextDays = false; | ||
while (date1.isBefore(date, 'day')) { | ||
if (this.testFilter(date1)) { | ||
lockedInPrevDays = true; | ||
break; | ||
} | ||
date1.add(1, 'day'); | ||
} | ||
while (date2.isAfter(date, 'day')) { | ||
if (this.testFilter(date2)) { | ||
lockedInNextDays = true; | ||
break; | ||
} | ||
date2.subtract(1, 'day'); | ||
} | ||
if (lockedInPrevDays && lockedInNextDays) { | ||
target.classList.add('not-available'); | ||
} | ||
} | ||
if (this.rangeIsNotAvailable(date, dateFrom)) { | ||
target.classList.add('not-available'); | ||
} | ||
} | ||
if (this.dateIsNotAvailable(date, dateFrom)) { | ||
target.classList.add('not-available'); | ||
} | ||
} | ||
if (this.options.presets && view === 'PresetPluginButton') { | ||
const startDate = new datetime.DateTime(Number(target.dataset.start)); | ||
const endDate = new datetime.DateTime(Number(target.dataset.end)); | ||
const diff = endDate.diff(startDate, 'day'); | ||
const lessMinDays = this.options.minDays && diff < this.options.minDays; | ||
const moreMaxDays = this.options.maxDays && diff > this.options.maxDays; | ||
if (lessMinDays || moreMaxDays | ||
|| this.lockMinDate(startDate) | ||
|| this.lockMaxDate(startDate) | ||
|| this.lockMinDate(endDate) | ||
|| this.lockMaxDate(endDate) | ||
|| this.rangeIsNotAvailable(startDate, endDate)) { | ||
target.setAttribute('disabled', 'disabled'); | ||
} | ||
} | ||
} | ||
/** | ||
* Checks availability date | ||
* | ||
* @param date | ||
* @param start | ||
* @returns Boolean | ||
*/ | ||
dateIsNotAvailable(date, start) { | ||
return this.lockMinDate(date) | ||
|| this.lockMaxDate(date) | ||
|| this.lockMinDays(date, start) | ||
|| this.lockMaxDays(date, start) | ||
|| this.lockSelectForward(date) | ||
|| this.lockSelectBackward(date); | ||
} | ||
/** | ||
* Checks the date range for availability | ||
* | ||
* @param date1 | ||
* @param date2 | ||
* @returns Boolean | ||
*/ | ||
rangeIsNotAvailable(date1, date2) { | ||
if (!date1 || !date2) | ||
return false; | ||
const start = (date1.isSameOrBefore(date2, 'day') ? date1 : date2).clone(); | ||
const end = (date2.isSameOrAfter(date1, 'day') ? date2 : date1).clone(); | ||
while (start.isSameOrBefore(end, 'day')) { | ||
if (this.testFilter(start)) { | ||
return true; | ||
} | ||
start.add(1, 'day'); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `minDate` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMinDate(date) { | ||
return this.options.minDate instanceof datetime.DateTime | ||
? date.isBefore(this.options.minDate, 'day') | ||
: false; | ||
} | ||
/** | ||
* Handle `maxDate` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMaxDate(date) { | ||
return this.options.maxDate instanceof datetime.DateTime | ||
? date.isAfter(this.options.maxDate, 'day') | ||
: false; | ||
} | ||
/** | ||
* Handle `minDays` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMinDays(date, start) { | ||
if (this.options.minDays && start) { | ||
const minPrev = start | ||
.clone() | ||
.subtract(this.options.minDays - 1, 'day'); | ||
const minNext = start | ||
.clone() | ||
.add(this.options.minDays - 1, 'day'); | ||
return date.isBetween(minPrev, minNext); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `maxDays` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockMaxDays(date, start) { | ||
if (this.options.maxDays && start) { | ||
const maxPrev = start | ||
.clone() | ||
.subtract(this.options.maxDays, 'day'); | ||
const maxNext = start | ||
.clone() | ||
.add(this.options.maxDays, 'day'); | ||
return !date.isBetween(maxPrev, maxNext); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `selectForward` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockSelectForward(date) { | ||
if (this.picker.datePicked.length === 1 && this.options.selectForward) { | ||
const start = this.picker.datePicked[0].clone(); | ||
return date.isAfter(start, 'day'); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `selectBackward` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
lockSelectBackward(date) { | ||
if (this.picker.datePicked.length === 1 && this.options.selectBackward) { | ||
const start = this.picker.datePicked[0].clone(); | ||
return date.isBefore(start, 'day'); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Handle `filter` option | ||
* | ||
* @param date | ||
* @returns Boolean | ||
*/ | ||
testFilter(date) { | ||
return typeof this.options.filter === 'function' | ||
? this.options.filter(date, this.picker.datePicked) | ||
: false; | ||
} | ||
} | ||
exports.LockPlugin = LockPlugin; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@easepick/datetime"),require("@easepick/base-plugin")):"function"==typeof define&&define.amd?define(["exports","@easepick/datetime","@easepick/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).easepick=t.easepick||{},t.easepick,t.easepick)}(this,(function(t,e,i){"use strict";class s extends i.BasePlugin{priority=1;binds={onView:this.onView.bind(this)};options={minDate:null,maxDate:null,minDays:null,maxDays:null,selectForward:null,selectBackward:null,presets:!0,inseparable:!1,filter:null};getName(){return"LockPlugin"}onAttach(){if(this.options.minDate&&(this.options.minDate=new e.DateTime(this.options.minDate,this.picker.options.format,this.picker.options.lang)),this.options.maxDate&&(this.options.maxDate=new e.DateTime(this.options.maxDate,this.picker.options.format,this.picker.options.lang)),(this.options.minDays||this.options.maxDays||this.options.selectForward||this.options.selectBackward)&&!this.picker.options.plugins.includes("RangePlugin")){const t=["minDays","maxDays","selectForward","selectBackward"];console.warn(`${this.getName()}: options ${t.join(", ")} required RangePlugin.`)}this.picker.on("view",this.binds.onView)}onDetach(){this.picker.off("view",this.binds.onView)}onView(t){const{view:i,target:s,date:a}=t.detail;if("CalendarHeader"===i&&(this.options.minDate instanceof e.DateTime&&a.isSameOrBefore(this.options.minDate,"month")&&s.classList.add("no-previous-month"),this.options.maxDate instanceof e.DateTime&&a.isSameOrAfter(this.options.maxDate,"month")&&s.classList.add("no-next-month")),"CalendarDay"===i){const t=this.picker.datePicked.length?this.picker.datePicked[0]:null;if(this.testFilter(a))return void s.classList.add("locked");if(this.options.inseparable){if(this.options.minDays){const t=a.clone().subtract(this.options.minDays-1,"day"),e=a.clone().add(this.options.minDays-1,"day");let i=!1,n=!1;for(;t.isBefore(a,"day");){if(this.testFilter(t)){i=!0;break}t.add(1,"day")}for(;e.isAfter(a,"day");){if(this.testFilter(e)){n=!0;break}e.subtract(1,"day")}i&&n&&s.classList.add("not-available")}this.rangeIsNotAvailable(a,t)&&s.classList.add("not-available")}this.dateIsNotAvailable(a,t)&&s.classList.add("not-available")}if(this.options.presets&&"PresetPluginButton"===i){const t=new e.DateTime(Number(s.dataset.start)),i=new e.DateTime(Number(s.dataset.end)),a=i.diff(t,"day"),n=this.options.minDays&&a<this.options.minDays,o=this.options.maxDays&&a>this.options.maxDays;(n||o||this.lockMinDate(t)||this.lockMaxDate(t)||this.lockMinDate(i)||this.lockMaxDate(i)||this.rangeIsNotAvailable(t,i))&&s.setAttribute("disabled","disabled")}}dateIsNotAvailable(t,e){return this.lockMinDate(t)||this.lockMaxDate(t)||this.lockMinDays(t,e)||this.lockMaxDays(t,e)||this.lockSelectForward(t)||this.lockSelectBackward(t)}rangeIsNotAvailable(t,e){if(!t||!e)return!1;const i=(t.isSameOrBefore(e,"day")?t:e).clone(),s=(e.isSameOrAfter(t,"day")?e:t).clone();for(;i.isSameOrBefore(s,"day");){if(this.testFilter(i))return!0;i.add(1,"day")}return!1}lockMinDate(t){return this.options.minDate instanceof e.DateTime&&t.isBefore(this.options.minDate,"day")}lockMaxDate(t){return this.options.maxDate instanceof e.DateTime&&t.isAfter(this.options.maxDate,"day")}lockMinDays(t,e){if(this.options.minDays&&e){const i=e.clone().subtract(this.options.minDays-1,"day"),s=e.clone().add(this.options.minDays-1,"day");return t.isBetween(i,s)}return!1}lockMaxDays(t,e){if(this.options.maxDays&&e){const i=e.clone().subtract(this.options.maxDays,"day"),s=e.clone().add(this.options.maxDays,"day");return!t.isBetween(i,s)}return!1}lockSelectForward(t){if(1===this.picker.datePicked.length&&this.options.selectForward){const e=this.picker.datePicked[0].clone();return t.isAfter(e,"day")}return!1}lockSelectBackward(t){if(1===this.picker.datePicked.length&&this.options.selectBackward){const e=this.picker.datePicked[0].clone();return t.isBefore(e,"day")}return!1}testFilter(t){return"function"==typeof this.options.filter&&this.options.filter(t,this.picker.datePicked)}}t.LockPlugin=s,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@easepick/lock-plugin", | ||
"description": "Plugin for easepick.", | ||
"version": "1.0.1-beta.0", | ||
"version": "1.0.1-beta.1", | ||
"main": "dist/index.umd.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/index.esm.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12541
157
2