@yuafox/easepick2-lock-plugin 2.0.0

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/LICENSE.md ADDED
@@ -0,0 +1,5 @@
1
+ # Software License Agreement
2
+
3
+ Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
4
+
5
+ Copyright © 2021-2022, [Rinat G.](https://github.com/wakirin)
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @easepick/lock-plugin
2
+
3
+ [![npm version](https://badge.fury.io/js/@easepick%2Flock-plugin.svg)](https://www.npmjs.com/package/@easepick/lock-plugin)
4
+
5
+ > This package does not need to be installed if you are using [@easepick/bundle](https://easepick.com/packages/bundle).
6
+
7
+ Adds the ability to disable days for selection.
8
+
9
+
10
+ ## Documentation
11
+
12
+ [https://easepick.com/packages/lock-plugin](https://easepick.com/packages/lock-plugin)
13
+
14
+
15
+ ## Options
16
+
17
+ | Name | Type | Default | Description
18
+ | --- | :---: | :---: | ---
19
+ | minDate | Date <br/> string <br/> number | null | The minimum/earliest date that can be selected. <br/> Date Object or Unix Timestamp (with milliseconds) or ISO String.
20
+ | maxDate | Date <br/> string <br/> number | null | The maximum/latest date that can be selected. <br/> Date Object or Unix Timestamp (with milliseconds) or ISO String.
21
+ | minDays | number | null | The minimum days of the selected range.
22
+ | maxDays | number | null | The maximum days of the selected range.
23
+ | selectForward | boolean | false | Select second date after the first selected date.
24
+ | selectBackward | boolean | false | Select second date before the first selected date.
25
+ | presets | boolean | true | Disable unallowed presets (when PresetPlugin is included).
26
+ | inseparable | boolean | false | Disable date range selection with locked days.
27
+ | filter | function | null | Lock days by custom function.
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ :host{--color-fg-locked:#9e9e9e;--color-bg-locked:#ffab91;--color-bg-unavailable:#f9f9f9}.container.lock-plugin .calendars .calendar:first-child>.header.no-previous-month .previous-button,.container.lock-plugin .calendars .calendar:last-child>.header.no-next-month .next-button{visibility:hidden}.container.lock-plugin .calendar>.days-grid>.day.not-available{background-color:var(--color-bg-unavailable);color:var(--color-fg-locked);font-style:italic;pointer-events:none}.container.lock-plugin .calendar>.days-grid>.day.locked{background-color:transparent;border:1px solid var(--color-border-locked);color:var(--color-fg-locked);pointer-events:none}.container.lock-plugin .calendar>.days-grid>.day.locked:not(.start):not(.end){background-image:repeating-linear-gradient(135deg,transparent,var(--color-bg-locked) 2px,transparent 2px,transparent 4px);font-style:italic}.container.lock-plugin .calendar>.months-grid>.month.locked,.container.lock-plugin .calendar>.years-grid>.year.locked{background-color:transparent;border:1px solid var(--color-border-locked);color:var(--color-fg-locked);pointer-events:none}.container.lock-plugin .preset-plugin-container>button:disabled{color:var(--color-fg-locked);pointer-events:none}
@@ -0,0 +1,98 @@
1
+ import { BasePlugin, IPlugin } from '@yuafox/easepick2-base-plugin';
2
+ import { ILockConfig } from './interface';
3
+ import './index.scss';
4
+ export declare class LockPlugin extends BasePlugin implements IPlugin {
5
+ priority: number;
6
+ binds: {
7
+ onView: any;
8
+ };
9
+ options: ILockConfig;
10
+ /**
11
+ * Returns plugin name
12
+ *
13
+ * @returns String
14
+ */
15
+ getName(): string;
16
+ /**
17
+ * - Called automatically via BasePlugin.attach() -
18
+ * The function execute on initialize the picker
19
+ */
20
+ onAttach(): void;
21
+ /**
22
+ * - Called automatically via BasePlugin.attach() -
23
+ * The function execute on initialize the picker
24
+ */
25
+ onDetach(): void;
26
+ /**
27
+ * Function `view` event
28
+ * Mark day elements as locked
29
+ *
30
+ * @param event
31
+ */
32
+ private onView;
33
+ /**
34
+ * Checks availability date
35
+ *
36
+ * @param date
37
+ * @param start
38
+ * @returns Boolean
39
+ */
40
+ private dateIsNotAvailable;
41
+ /**
42
+ * Checks the date range for availability
43
+ *
44
+ * @param date1
45
+ * @param date2
46
+ * @returns Boolean
47
+ */
48
+ private rangeIsNotAvailable;
49
+ /**
50
+ * Handle `minDate` option
51
+ *
52
+ * @param date
53
+ * @returns Boolean
54
+ */
55
+ private lockMinDate;
56
+ /**
57
+ * Handle `maxDate` option
58
+ *
59
+ * @param date
60
+ * @returns Boolean
61
+ */
62
+ private lockMaxDate;
63
+ /**
64
+ * Handle `minDays` option
65
+ *
66
+ * @param date
67
+ * @returns Boolean
68
+ */
69
+ private lockMinDays;
70
+ /**
71
+ * Handle `maxDays` option
72
+ *
73
+ * @param date
74
+ * @returns Boolean
75
+ */
76
+ private lockMaxDays;
77
+ /**
78
+ * Handle `selectForward` option
79
+ *
80
+ * @param date
81
+ * @returns Boolean
82
+ */
83
+ private lockSelectForward;
84
+ /**
85
+ * Handle `selectBackward` option
86
+ *
87
+ * @param date
88
+ * @returns Boolean
89
+ */
90
+ private lockSelectBackward;
91
+ /**
92
+ * Handle `filter` option
93
+ *
94
+ * @param date
95
+ * @returns Boolean
96
+ */
97
+ private testFilter;
98
+ }
@@ -0,0 +1 @@
1
+ import{DateTime as t}from"@yuafox/easepick2-datetime";import{BasePlugin as i}from"@yuafox/easepick2-base-plugin";class e 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.maxDate instanceof t&&this.picker.options.calendars>1&&this.picker.calendars[0].isSame(this.options.maxDate,"month"))){const t=this.picker.calendars[0].clone().subtract(1,"month");this.picker.gotoDate(t)}if((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:e,target:s,date:a}=i.detail;if("CalendarHeader"===e&&(this.options.minDate instanceof t&&a.isSameOrBefore(this.options.minDate,"month")&&s.classList.add("no-previous-month"),this.options.maxDate instanceof t&&a.isSameOrAfter(this.options.maxDate,"month")&&s.classList.add("no-next-month")),"CalendarMonth"===e){if(this.options.minDate instanceof t){const i=new t(new Date(this.options.minDate.getFullYear(),this.options.minDate.getMonth(),1));a.getTime()<i.getTime()&&s.classList.add("locked")}if(this.options.maxDate instanceof t){const i=new t(new Date(this.options.maxDate.getFullYear(),this.options.maxDate.getMonth(),1));a.getTime()>i.getTime()&&s.classList.add("locked")}}if("CalendarYear"===e&&(this.options.minDate instanceof t&&a.getFullYear()<this.options.minDate.getFullYear()&&s.classList.add("locked"),this.options.maxDate instanceof t&&a.getFullYear()>this.options.maxDate.getFullYear()&&s.classList.add("locked")),"CalendarDay"===e){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"),i=a.clone().add(this.options.minDays-1,"day");let e=!1,o=!1;for(;t.isBefore(a,"day");){if(this.testFilter(t)){e=!0;break}t.add(1,"day")}for(;i.isAfter(a,"day");){if(this.testFilter(i)){o=!0;break}i.subtract(1,"day")}e&&o&&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"===e){const i=new t(Number(s.dataset.start)),e=new t(Number(s.dataset.end)),a=e.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(e)||this.lockMaxDate(e)||this.rangeIsNotAvailable(i,e))&&s.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 e=(t.isSameOrBefore(i,"day")?t:i).clone(),s=(i.isSameOrAfter(t,"day")?i:t).clone();for(;e.isSameOrBefore(s,"day");){if(this.testFilter(e))return!0;e.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 e=i.clone().subtract(this.options.minDays-1,"day"),s=i.clone().add(this.options.minDays-1,"day");return t.isBetween(e,s)}return!1}lockMaxDays(t,i){if(this.options.maxDays&&i){const e=i.clone().subtract(this.options.maxDays,"day"),s=i.clone().add(this.options.maxDays,"day");return!t.isBetween(e,s)}return!1}lockSelectForward(t){if(1===this.picker.datePicked.length&&this.options.selectForward){const i=this.picker.datePicked[0].clone();return t.isBefore(i,"day")}return!1}lockSelectBackward(t){if(1===this.picker.datePicked.length&&this.options.selectBackward){const i=this.picker.datePicked[0].clone();return t.isAfter(i,"day")}return!1}testFilter(t){return"function"==typeof this.options.filter&&this.options.filter(t,this.picker.datePicked)}}export{e as LockPlugin};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Package: @yuafox/easepick2-lock-plugin
4
+ * Version: 2.0.0
5
+ * https://github.com/YuaFox/easepick2
6
+ * Copyright 2026 YuaFox
7
+ *
8
+ * Licensed under the terms of GNU General Public License Version 2 or later. (http://www.gnu.org/licenses/gpl.html)
9
+ */
10
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@yuafox/easepick2-datetime"),require("@yuafox/easepick2-base-plugin")):"function"==typeof define&&define.amd?define(["exports","@yuafox/easepick2-datetime","@yuafox/easepick2-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.maxDate instanceof e.DateTime&&this.picker.options.calendars>1&&this.picker.calendars[0].isSame(this.options.maxDate,"month"))){const t=this.picker.calendars[0].clone().subtract(1,"month");this.picker.gotoDate(t)}if((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")),"CalendarMonth"===i){if(this.options.minDate instanceof e.DateTime){const t=new e.DateTime(new Date(this.options.minDate.getFullYear(),this.options.minDate.getMonth(),1));a.getTime()<t.getTime()&&s.classList.add("locked")}if(this.options.maxDate instanceof e.DateTime){const t=new e.DateTime(new Date(this.options.maxDate.getFullYear(),this.options.maxDate.getMonth(),1));a.getTime()>t.getTime()&&s.classList.add("locked")}}if("CalendarYear"===i&&(this.options.minDate instanceof e.DateTime&&a.getFullYear()<this.options.minDate.getFullYear()&&s.classList.add("locked"),this.options.maxDate instanceof e.DateTime&&a.getFullYear()>this.options.maxDate.getFullYear()&&s.classList.add("locked")),"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,o=!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)){o=!0;break}e.subtract(1,"day")}i&&o&&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"),o=this.options.minDays&&a<this.options.minDays,n=this.options.maxDays&&a>this.options.maxDays;(o||n||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.isBefore(e,"day")}return!1}lockSelectBackward(t){if(1===this.picker.datePicked.length&&this.options.selectBackward){const e=this.picker.datePicked[0].clone();return t.isAfter(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})}));
@@ -0,0 +1,18 @@
1
+ import { DateTime } from '@yuafox/easepick2-datetime';
2
+ import { IBaseConfig } from '@yuafox/easepick2-base-plugin';
3
+ export interface ILockConfig extends IBaseConfig {
4
+ minDate?: Date | string | number;
5
+ maxDate?: Date | string | number;
6
+ minDays?: number;
7
+ maxDays?: number;
8
+ selectForward?: boolean;
9
+ selectBackward?: boolean;
10
+ presets?: boolean;
11
+ inseparable?: boolean;
12
+ filter?: (date: DateTime | DateTime[], picked: DateTime[]) => boolean;
13
+ }
14
+ declare module '@yuafox/easepick2-core/dist/types' {
15
+ interface IPickerConfig {
16
+ LockPlugin?: ILockConfig;
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@yuafox/easepick2-lock-plugin",
3
+ "description": "Lock plugin for easepick2.",
4
+ "version": "2.0.0",
5
+ "main": "dist/index.umd.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "dependencies": {
9
+ "@yuafox/easepick2-base-plugin": "^2.0.0"
10
+ },
11
+ "author": {
12
+ "name": "YuaFox"
13
+ },
14
+ "license": "GPL-2.0-or-later",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/YuaFox/easepick2.git",
18
+ "directory": "packages/lock-plugin"
19
+ },
20
+ "homepage": "https://github.com/YuaFox/easepick2",
21
+ "bugs": {
22
+ "url": "https://github.com/YuaFox/easepick2/issues"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ]
27
+ }