@ezuikit/control-date-picker 0.0.1-alpha.1 → 1.0.0-beta.1
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 +62 -0
- package/dist/index.js +3 -229
- package/dist/index.umd.js +8 -379
- package/dist/style.css +5 -0
- package/dist/style.js +6 -0
- package/dist/types/index.d.ts +748 -28
- package/package.json +22 -15
- package/dist/index.mjs +0 -228
package/package.json
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezuikit/control-date-picker",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "date picker",
|
|
5
|
-
"title": "date
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "date picker control for ezviz",
|
|
5
|
+
"title": "date-picker",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
|
-
"module": "dist/index.mjs",
|
|
9
8
|
"scripts": {
|
|
10
9
|
"dev": "cross-env NODE_ENV=development rollup --config rollup.config.mjs --watch",
|
|
11
|
-
"build": "npm run clean && cross-env NODE_ENV=production rollup --config rollup.config.mjs",
|
|
12
|
-
"clean": "rimraf dist"
|
|
10
|
+
"build": "npm run clean && cross-env NODE_ENV=production rollup --config rollup.config.mjs && npm run docs",
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"types": "tsc src/index.ts --emitDeclarationOnly --declaration --declarationDir dist/types --esModuleInterop",
|
|
13
|
+
"docs": "typedoc --tsconfig typedoc.config.js"
|
|
13
14
|
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"date picker",
|
|
16
|
-
"日期选择器"
|
|
17
|
-
],
|
|
18
15
|
"files": [
|
|
19
16
|
"dist"
|
|
20
17
|
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"time-line",
|
|
20
|
+
"time line",
|
|
21
|
+
"control",
|
|
22
|
+
"ezuikit",
|
|
23
|
+
"ezviz"
|
|
24
|
+
],
|
|
21
25
|
"author": "Ezviz-OpenBiz",
|
|
22
|
-
"license": "
|
|
26
|
+
"license": "",
|
|
23
27
|
"dependencies": {
|
|
24
|
-
"@ezuikit/utils-tools": "
|
|
25
|
-
"deepmerge": "^4.3.1"
|
|
28
|
+
"@ezuikit/utils-tools": "2.0.1",
|
|
29
|
+
"deepmerge": "^4.3.1",
|
|
30
|
+
"@skax/picker": "1.1.5",
|
|
31
|
+
"@ezuikit/utils-i18n": "2.0.0",
|
|
32
|
+
"@skax/delegate": "4.0.1"
|
|
26
33
|
},
|
|
27
34
|
"devDependencies": {
|
|
28
35
|
"@common/rollup": "workspace:*"
|
|
29
36
|
},
|
|
30
37
|
"publishConfig": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
40
|
}
|
|
34
41
|
}
|
package/dist/index.mjs
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @ezuikit/control-date-picker v0.0.1-alpha.1
|
|
3
|
-
* Copyright (c) 2025-10-08 Ezviz-OpenBiz
|
|
4
|
-
* Released under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
7
|
-
try {
|
|
8
|
-
var info = gen[key](arg);
|
|
9
|
-
var value = info.value;
|
|
10
|
-
} catch (error) {
|
|
11
|
-
reject(error);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (info.done) {
|
|
15
|
-
resolve(value);
|
|
16
|
-
} else {
|
|
17
|
-
Promise.resolve(value).then(_next, _throw);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function _async_to_generator(fn) {
|
|
21
|
-
return function() {
|
|
22
|
-
var self = this, args = arguments;
|
|
23
|
-
return new Promise(function(resolve, reject) {
|
|
24
|
-
var gen = fn.apply(self, args);
|
|
25
|
-
function _next(value) {
|
|
26
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
27
|
-
}
|
|
28
|
-
function _throw(err) {
|
|
29
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
30
|
-
}
|
|
31
|
-
_next(undefined);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
class AppendJS {
|
|
36
|
-
static loadScript(src) {
|
|
37
|
-
return _async_to_generator(function*() {
|
|
38
|
-
return yield new Promise((resolve, reject)=>{
|
|
39
|
-
if (AppendJS.LoadedScr.includes(src)) {
|
|
40
|
-
return resolve(src);
|
|
41
|
-
}
|
|
42
|
-
if (AppendJS.LoadingScrQueue[src]) {
|
|
43
|
-
return AppendJS.LoadingScrQueue[src].push(resolve);
|
|
44
|
-
} else {
|
|
45
|
-
AppendJS.LoadingScrQueue[src] = [
|
|
46
|
-
resolve
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
let link;
|
|
50
|
-
if (src.includes('.js')) {
|
|
51
|
-
link = document.createElement('script');
|
|
52
|
-
link.src = src;
|
|
53
|
-
link.async = true;
|
|
54
|
-
} else if (src.includes('.css')) {
|
|
55
|
-
link = document.createElement('link');
|
|
56
|
-
link.rel = 'stylesheet';
|
|
57
|
-
link.href = src;
|
|
58
|
-
}
|
|
59
|
-
link.onload = ()=>{
|
|
60
|
-
AppendJS.LoadedScr.push(src);
|
|
61
|
-
AppendJS.LoadingScrQueue[src].forEach((resolve)=>resolve(src));
|
|
62
|
-
AppendJS.LoadingScrQueue[src] = [];
|
|
63
|
-
};
|
|
64
|
-
link.onerror = ()=>reject(new Error('Failed to load ' + src));
|
|
65
|
-
document.head.appendChild(link);
|
|
66
|
-
});
|
|
67
|
-
})();
|
|
68
|
-
}
|
|
69
|
-
static loadScriptsBatch(srcArr) {
|
|
70
|
-
return _async_to_generator(function*() {
|
|
71
|
-
return yield Promise.all(srcArr.map(AppendJS.loadScript));
|
|
72
|
-
})();
|
|
73
|
-
}
|
|
74
|
-
static remove(src) {
|
|
75
|
-
src.forEach((item)=>{
|
|
76
|
-
const link = document.querySelector(`script[src="${item}"]`) || document.querySelector(`link[href="${item}"]`);
|
|
77
|
-
if (link) {
|
|
78
|
-
link.remove();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
static clear() {
|
|
83
|
-
AppendJS.remove(AppendJS.LoadedScr);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/** 已经加载完的js/css */ AppendJS.LoadedScr = [];
|
|
87
|
-
/** 正在加载的js/css */ AppendJS.LoadingScrQueue = {};
|
|
88
|
-
|
|
89
|
-
const DEFAULT_OPTIONS = {
|
|
90
|
-
staticPath: '.',
|
|
91
|
-
place: 'top-right',
|
|
92
|
-
language: 'zh-CN',
|
|
93
|
-
current: new Date(),
|
|
94
|
-
maxDate: new Date()
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* 日期选择器
|
|
98
|
-
*/ class DatePicker {
|
|
99
|
-
_init() {
|
|
100
|
-
// 因为挂载在行内,需要父标签设置 position: relative;
|
|
101
|
-
this.$container.style.cssText += `;position: relative;`;
|
|
102
|
-
this.$container.classList.add(`datepicker-inline-${this.options.place}`);
|
|
103
|
-
AppendJS.loadScriptsBatch([
|
|
104
|
-
`${this.options.staticPath}/rec/jquery.min.js`,
|
|
105
|
-
`${this.options.staticPath}/rec/datepicker.min.css`
|
|
106
|
-
]).then(()=>{
|
|
107
|
-
AppendJS.loadScriptsBatch([
|
|
108
|
-
`${this.options.staticPath}/rec/datepicker.js`
|
|
109
|
-
]).then(()=>{
|
|
110
|
-
AppendJS.loadScriptsBatch([
|
|
111
|
-
`${this.options.staticPath}/rec/datepicker.zh-CN.js`,
|
|
112
|
-
`${this.options.staticPath}/rec/datepicker.en-US.js`
|
|
113
|
-
]).then(()=>{
|
|
114
|
-
window.$(this.$container).datepicker({
|
|
115
|
-
date: this.options.current,
|
|
116
|
-
language: this.options.language,
|
|
117
|
-
endDate: this.options.maxDate,
|
|
118
|
-
inline: true
|
|
119
|
-
});
|
|
120
|
-
this.hide();
|
|
121
|
-
window.$(this.$container).on('pick.datepicker', (e)=>{
|
|
122
|
-
var _this__date, _this__date1, _this__date2, _this__date3, _this__date4, _this__date5;
|
|
123
|
-
if (e.view === 'year' && ((_this__date = this._date) == null ? void 0 : _this__date.getFullYear()) !== e.date.getFullYear()) {
|
|
124
|
-
this.options.onYearChange == null ? void 0 : this.options.onYearChange.call(this.options, e.date);
|
|
125
|
-
} else if (e.view === 'month' && (((_this__date1 = this._date) == null ? void 0 : _this__date1.getMonth()) !== e.date.getMonth() || ((_this__date2 = this._date) == null ? void 0 : _this__date2.getFullYear()) !== e.date.getFullYear())) {
|
|
126
|
-
this.options.onMonthChange == null ? void 0 : this.options.onMonthChange.call(this.options, e.date);
|
|
127
|
-
} else if ([
|
|
128
|
-
'day',
|
|
129
|
-
'pick'
|
|
130
|
-
].includes(e.view || e.type) && (((_this__date3 = this._date) == null ? void 0 : _this__date3.getDate()) !== e.date.getDate() || ((_this__date4 = this._date) == null ? void 0 : _this__date4.getMonth()) !== e.date.getMonth() || ((_this__date5 = this._date) == null ? void 0 : _this__date5.getFullYear()) !== e.date.getFullYear())) {
|
|
131
|
-
if (this._change) {
|
|
132
|
-
this.options.onChange == null ? void 0 : this.options.onChange.call(this.options, e.date);
|
|
133
|
-
}
|
|
134
|
-
this._date = new Date(e.date.getTime());
|
|
135
|
-
}
|
|
136
|
-
if (e.view === 'day') this.hide();
|
|
137
|
-
this._change = true;
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* 获取日期
|
|
145
|
-
*/ get date() {
|
|
146
|
-
return this._date;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 设置日期, change = true 时触发 onChange 事件
|
|
150
|
-
*
|
|
151
|
-
* @param date 设置的日期
|
|
152
|
-
* @param change 是否触发 onChange 事件
|
|
153
|
-
*/ setDate(date, change = true) {
|
|
154
|
-
const $datepicker = this.$container.querySelector(`.datepicker-inline`);
|
|
155
|
-
if ($datepicker) {
|
|
156
|
-
this._change = change;
|
|
157
|
-
window.$(this.$container).datepicker('setDate', date);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* 隐藏面板, 会触发 onPanelChange 事件
|
|
162
|
-
*/ hide() {
|
|
163
|
-
const $datepicker = this.$container.querySelector(`.datepicker-inline`);
|
|
164
|
-
if ($datepicker) {
|
|
165
|
-
if (this._open) {
|
|
166
|
-
this._open = false;
|
|
167
|
-
this.options.onPanelChange == null ? void 0 : this.options.onPanelChange.call(this.options, false, this._date);
|
|
168
|
-
}
|
|
169
|
-
$datepicker.classList.add('datepicker-hide');
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* 显示面板, 会触发 onPanelChange 事件
|
|
174
|
-
*/ show() {
|
|
175
|
-
const $datepicker = this.$container.querySelector(`.datepicker-inline`);
|
|
176
|
-
if ($datepicker) {
|
|
177
|
-
var _window_$_datepicker, _window_$;
|
|
178
|
-
if (!this._open) {
|
|
179
|
-
this._open = true;
|
|
180
|
-
this.options.onPanelChange == null ? void 0 : this.options.onPanelChange.call(this.options, true, this._date);
|
|
181
|
-
}
|
|
182
|
-
if (this._date) this.setDate(this._date, false);
|
|
183
|
-
(_window_$_datepicker = (_window_$ = window.$(this.$container)).datepicker) == null ? void 0 : _window_$_datepicker.call(_window_$, 'showView');
|
|
184
|
-
if (this.options.place === 'bottom-left') {
|
|
185
|
-
$datepicker.style.cssText += `top: ${this.$container.clientHeight + 10}px; bottom: auto; right: auto; left: 0px`;
|
|
186
|
-
} else {
|
|
187
|
-
$datepicker.style.cssText += `bottom: ${this.$container.clientHeight + 10}px; top: auto`;
|
|
188
|
-
}
|
|
189
|
-
$datepicker.classList.remove('datepicker-hide');
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* 销毁
|
|
194
|
-
*/ destroy() {
|
|
195
|
-
this.hide();
|
|
196
|
-
this._date = undefined;
|
|
197
|
-
window.$(this.$container).datepicker('destroy');
|
|
198
|
-
// AppendJS.remove([
|
|
199
|
-
// `${this.options.staticPath}/rec/jquery.min.js`,
|
|
200
|
-
// `${this.options.staticPath}/rec/datepicker.min.css`,
|
|
201
|
-
// `${this.options.staticPath}/rec/datepicker.js`,
|
|
202
|
-
// `${this.options.staticPath}/rec/datepicker.zh-CN.js`,
|
|
203
|
-
// `${this.options.staticPath}/rec/datepicker.en-US.js`,
|
|
204
|
-
// ]);
|
|
205
|
-
}
|
|
206
|
-
constructor(container, options){
|
|
207
|
-
this._open = false;
|
|
208
|
-
this._change = true;
|
|
209
|
-
this.$container = container;
|
|
210
|
-
this.options = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
211
|
-
this.options.staticPath = (this.options.staticPath || '').replace(/\/$/, '');
|
|
212
|
-
if (this.options.current) {
|
|
213
|
-
this._date = this.options.current;
|
|
214
|
-
}
|
|
215
|
-
this._init();
|
|
216
|
-
this.$container.addEventListener('click', ()=>{
|
|
217
|
-
if (this._open) this.hide();
|
|
218
|
-
else this.show();
|
|
219
|
-
});
|
|
220
|
-
document.body.addEventListener('click', (e)=>{
|
|
221
|
-
if (!this.$container.contains(e.target)) {
|
|
222
|
-
this.hide();
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export { DatePicker as default };
|