lddatetimepicker 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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +5 -2
- package/index.js +18 -11
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.14
|
|
4
|
+
|
|
5
|
+
- fix: `change` is now fired based on the picked value instead of on the host input string.
|
|
6
|
+
- typing or pasting a valid datetime into the host input used to update the picker silently,
|
|
7
|
+
since the input value was written back before `update` compared against it.
|
|
8
|
+
- fix: `change` is now fired in host-less mode ( `container` without `host` ) as well.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## v0.0.13
|
|
12
|
+
|
|
13
|
+
- support getting config by `config` call without parameter.
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## v0.0.12
|
|
4
17
|
|
|
5
18
|
- support config with time option
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2026 zbryikt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -59,8 +59,11 @@ Constructor options:
|
|
|
59
59
|
- `on(n, cb)`
|
|
60
60
|
- `update()`
|
|
61
61
|
- `value()`
|
|
62
|
-
- `config(opt)`: update configuration.
|
|
63
|
-
-
|
|
62
|
+
- `config(opt)`: update configuration.
|
|
63
|
+
- following options are supported:
|
|
64
|
+
- `suppress`: see constructor option for this option.
|
|
65
|
+
- `time`: see constructor option for `time`
|
|
66
|
+
- return current config ( `suppress` and `time` ) when calling without option.
|
|
64
67
|
|
|
65
68
|
|
|
66
69
|
## License
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
? 'fixed'
|
|
17
17
|
: opt.container ? 'out-place' : 'in-place';
|
|
18
18
|
this.evthdr = {};
|
|
19
|
+
this._value = null;
|
|
19
20
|
if (_c = opt.container) {
|
|
20
21
|
if (!(typeof _c === 'object' && _c.isOn && _c.toggle && _c.node)) {
|
|
21
22
|
throw new Error("[lddatetimepicker] `isOn`, `toggle` and `node` are all required within `container` option.");
|
|
@@ -162,10 +163,8 @@
|
|
|
162
163
|
});
|
|
163
164
|
if (this.host) {
|
|
164
165
|
_handler = debounce(function(){
|
|
165
|
-
var
|
|
166
|
+
var e;
|
|
166
167
|
try {
|
|
167
|
-
ret = dayjs(this$.host.value).format('YYYY-MM-DDTHH:mm:ssZ');
|
|
168
|
-
this$.host.value = ret;
|
|
169
168
|
return this$.value(this$.host.value);
|
|
170
169
|
} catch (e$) {
|
|
171
170
|
return e = e$;
|
|
@@ -176,12 +175,13 @@
|
|
|
176
175
|
}
|
|
177
176
|
if (this.host && this.host.value) {
|
|
178
177
|
try {
|
|
179
|
-
this.host.value = dayjs(this.host.value).format('YYYY-MM-DDTHH:mm:ssZ');
|
|
178
|
+
this.host.value = this._value = dayjs(this.host.value).format('YYYY-MM-DDTHH:mm:ssZ');
|
|
180
179
|
this.value(this.host.value);
|
|
181
180
|
} catch (e$) {
|
|
182
181
|
e = e$;
|
|
183
182
|
}
|
|
184
183
|
} else {
|
|
184
|
+
this._value = this.value();
|
|
185
185
|
this.update();
|
|
186
186
|
}
|
|
187
187
|
return this;
|
|
@@ -335,7 +335,7 @@
|
|
|
335
335
|
}
|
|
336
336
|
},
|
|
337
337
|
update: function(now){
|
|
338
|
-
var ref$, y, m, start, ny, nm, nd, ty, tm, td, sy, sm, sd,
|
|
338
|
+
var ref$, y, m, start, ny, nm, nd, ty, tm, td, sy, sm, sd, nv;
|
|
339
339
|
now = now || this.cur;
|
|
340
340
|
ref$ = [now.year(), now.month()], y = ref$[0], m = ref$[1];
|
|
341
341
|
now = dayjs(new Date(now.year(), now.month(), 1));
|
|
@@ -363,13 +363,13 @@
|
|
|
363
363
|
n.classList.toggle('today', ty === dy && tm === dm && td === dd);
|
|
364
364
|
return n.classList.toggle('selected', sy === dy && sm === dm && sd === dd);
|
|
365
365
|
});
|
|
366
|
+
nv = this.value();
|
|
366
367
|
if (this.host) {
|
|
367
|
-
ov = this.host.value;
|
|
368
|
-
nv = this.value();
|
|
369
368
|
this.host.value = nv;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
369
|
+
}
|
|
370
|
+
if (nv !== this._value) {
|
|
371
|
+
this._value = nv;
|
|
372
|
+
return this.fire('change', nv);
|
|
373
373
|
}
|
|
374
374
|
},
|
|
375
375
|
value: function(v){
|
|
@@ -391,7 +391,14 @@
|
|
|
391
391
|
return this.update();
|
|
392
392
|
},
|
|
393
393
|
config: function(cfg){
|
|
394
|
-
cfg == null
|
|
394
|
+
if (cfg == null) {
|
|
395
|
+
return {
|
|
396
|
+
suppress: !!this._suppress,
|
|
397
|
+
time: {
|
|
398
|
+
enabled: !!this._enabled.time
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
395
402
|
if (cfg.suppress != null) {
|
|
396
403
|
this._suppress = cfg.suppress;
|
|
397
404
|
}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var t;(t=function(t){var e,s,n
|
|
1
|
+
!function(){var t;(t=function(t){var e,s,i,n=this;if(this.opt=t=null==t?{}:t,this._suppress=t.suppress,this._enabled={time:!(null!=t.time)||t.time},this._zmgr=t.zmgr||null,this._mode="in-place"===(e=t.mode)||"out-place"===e||"fixed"===e?t.mode:t.fixed?"fixed":t.container?"out-place":"in-place",this.evthdr={},this._value=null,i=t.container){if(!("object"==typeof i&&i.isOn&&i.toggle&&i.node))throw new Error("[lddatetimepicker] `isOn`, `toggle` and `node` are all required within `container` option.");this._toggle=i.toggle,this.isOn=i.isOn,this._container=i.node,this._pos=i.position}if(this.hdr={mouseup:function(t){if(t.target!==n.host)return n._toggle(!1),document.removeEventListener("mouseup",n.hdr.mouseup),document.removeEventListener("keydown",n.hdr.keydown)},keydown:function(t){var e;if(n.isOn()&&(13===(e=t.keyCode)||27===e||37===e||38===e||39===e||40===e)&&n.sel)return 13===e||27===e?n.toggle(!1):(t.stopPropagation(),t.preventDefault(),n.sel=37===e?n.sel.subtract(1,"day"):39===e?n.sel.add(1,"day"):38===e?n.sel.subtract(7,"day"):40===e?n.sel.add(7,"day"):void 0,n.cur=n.sel,n.update())}},i=document.createElement("div"),t.host&&(this.host="string"==typeof t.host?document.querySelector(t.host):t.host,this.host.addEventListener("mouseup",function(t){if(!n._suppress)return n.toggle()})),i.innerHTML='<div class="lddtp"><div>\n <div class="lddtp-h">\n <div class="lddtp-a" data-action="-"></div>\n <div class="lddtp-f"><select class="lddtp-month-sel"></select></div>\n <div class="lddtp-f"><input class="lddtp-year-sel" type="number"/></div>\n <div class="lddtp-a" data-action="+"></div>\n </div>\n <div class="lddtp-ds">\n </div>\n <div class="lddtp-t">\n <div class="lddtp-f"><select class="lddtp-hour-sel"></select></div>\n <div><b>:</b></div>\n <div class="lddtp-f"><select class="lddtp-minute-sel"></select></div>\n </div>\n <div class="lddtp-c"></div>\n</div></div>',this.root=s=i.querySelector(".lddtp"),this._container?(this._container.appendChild(i),this.root.classList.add("static","bare")):"out-place"===this._mode?document.body.appendChild(i):"fixed"!==this._mode&&this.host?this.host&&this.host.parentNode.insertBefore(i,t.host.nextSibling):(document.body.appendChild(i),this.root.classList.toggle("fixed")),this.root.addEventListener("mouseup",function(t){return t.stopPropagation()}),this.n={ds:s.querySelector(".lddtp-ds"),t:s.querySelector(".lddtp-t"),sel:{year:s.querySelector(".lddtp-year-sel"),month:s.querySelector(".lddtp-month-sel"),hour:s.querySelector(".lddtp-hour-sel"),minute:s.querySelector(".lddtp-minute-sel")}},this.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.wdays=["SUN","MON","TUE","WED","THR","FRI","SAT"],this.n.ds.innerHTML=[0,1,2,3,4,5,6].map(function(t){return'<div class="lddtp-w">'+n.wdays[t]+"</div>"}).join("")+[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41].map(function(t){return'<div class="lddtp-d"></div>'}).join(""),(e=this.n).dh=Array.from(s.querySelectorAll(".lddtp-w")),e.dc=Array.from(s.querySelectorAll(".lddtp-d")),e=[0,1,2].map(function(){return dayjs()}),this.cur=e[0],this.today=e[1],this.sel=e[2],this.n.sel.month.innerHTML=this.months.map(function(t){return'<option value="'+t+'">'+t+"</option>"}).join(""),(t=this.n.sel.year).setAttribute("min",1900),t.setAttribute("max",2300),t.setAttribute("value",this.today.year()),this.n.sel.hour.innerHTML=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23].map(function(t){return'<option value="'+t+'">'+(""+t).padStart(2,"0")+"</option>"}).join(""),this.n.sel.minute.innerHTML=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59].map(function(t){return'<option value="'+t+'">'+(""+t).padStart(2,"0")+"</option>"}).join(""),this.root.addEventListener("click",function(t){return"fixed"===n._mode&&t.target.classList.contains("fixed")?n.toggle(!1):(t=t.target).classList.contains("lddtp-d")?(n.sel=dayjs(new Date(t.date.year,t.date.month,t.date.date,n.sel.hour(),n.sel.minute())),n.update(n.cur)):"-"===t.getAttribute("data-action")?(n.cur=n.cur.subtract(1,"month"),n.update(n.cur)):"+"===t.getAttribute("data-action")?(n.cur=n.cur.add(1,"month"),n.update(n.cur)):t.classList.contains("lddtp-c")?n.toggle(!1):void 0}),this.n.sel.minute.addEventListener("change",function(t){return n.sel=n.sel.minute(t.target.value),n.update()}),this.n.sel.hour.addEventListener("change",function(t){return n.sel=n.sel.hour(t.target.value),n.update()}),this.n.sel.year.addEventListener("change",function(t){return n.cur=dayjs(new Date(n.n.sel.year.value,n.months.indexOf(n.n.sel.month.value),1)),n.update(n.cur)}),this.n.sel.month.addEventListener("change",function(t){return n.cur=dayjs(new Date(n.n.sel.year.value,n.months.indexOf(n.n.sel.month.value),1)),n.update(n.cur)}),this.host&&(i=debounce(function(){try{return n.value(n.host.value)}catch(t){return t}}),this.host.addEventListener("change",i),this.host.addEventListener("input",i)),this.host&&this.host.value)try{this.host.value=this._value=dayjs(this.host.value).format("YYYY-MM-DDTHH:mm:ssZ"),this.value(this.host.value)}catch(t){0}else this._value=this.value(),this.update();return this}).prototype=((t,e)=>{var s,i={}.hasOwnProperty;for(s in e)i.call(e,s)&&(t[s]=e[s]);return t})(Object.create(Object.prototype),{on:function(t,s){var i=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=i.evthdr)[t]||(e[t]=[])).push(s)})},fire:function(t){for(var e,s,i,n,o=[],d=[],l=1,r=arguments.length;l<r;++l)d.push(arguments[l]);for(e=d,l=0,i=(s=this.evthdr[t]||[]).length;l<i;++l)n=s[l],o.push(n.apply(this,e));return o},isOn:function(){return this.root.classList.contains("active")},_toggle:function(t){t=t||!(null!=t)&&!this.isOn();return this._zmgr&&(t?this.root.style.zIndex=this._zmgr.add():this._zmgr.remove(this.root.style.zIndex)),this.root.classList.toggle("active",t)},toggle:function(t){var e,s,i,n,o,d,l,r,a,h,u,c,p,m,v;if(t=0===arguments.length?!this.isOn():t){if(this.isOn()||(document.addEventListener("mouseup",this.hdr.mouseup),document.addEventListener("keydown",this.hdr.keydown)),this._toggle(!0),"fixed"!==this._mode){for(t=this.root,e=(s=this.host).parentNode,s=s.getBoundingClientRect(),i=t.getBoundingClientRect(),o=(n=[0,0])[0],d=(n=[null,null])[0],l=n[1],r=!0;e&&e.getAttribute&&(a=getComputedStyle(e),"BODY"===e.nodeName&&(d=d||document.scrollingElement),["overflow","overflow-y","overflow-x"].filter(y).length&&(d=d||e),"BODY"!==e.nodeName&&"static"===a.position||l||(l=e,d)||(r=!1),!d||!l);)e=e.parentNode;return(h=l.getBoundingClientRect(),v=d.getBoundingClientRect(),u={left:d.scrollLeft,top:d.scrollTop},m="fixed"===this._mode?{left:0,top:0}:{left:document.scrollingElement.scrollLeft,top:document.scrollingElement.scrollTop},p=this._container?this._container.getBoundingClientRect():i,c=s.y+s.height+p.height>window.innerHeight+m.top?s.y-p.height+m.top-2:s.y+s.height+m.top+2,p=s.x+p.width>window.innerWidth+m.left?s.x+s.width-+m.left+p.width:s.x+m.left,m=s.y+s.height+i.height>v.y+v.height+u.top?s.y-h.y-i.height+(r?u.top:0)-2:s.y-h.y+s.height+(r?u.top:0)+2,v=s.x+i.width>v.x+v.width+u.left?s.x-h.x+s.width-i.width+(r?u.left:0):s.x-h.x+(r?u.left:0),this._pos)?this._pos({x:p,y:c,vx:p,vy:c,ix:v,iy:m}):(o=(n="out-place"===this._mode?(o=(n=[p,c])[0],n[1],n):[v,m])[0],t.style.transform="translate("+o+"px, "+n[1]+"px)",(n=t.style).top=0,n.left=0,this.render())}}else this._toggle(!1),document.removeEventListener("mouseup",this.hdr.mouseup),document.removeEventListener("keydown",this.hdr.keydown);function y(t){return"visible"!==a[t]}},update:function(t){s=[(t=t||this.cur).year(),t.month()];var o,e,d,l,r,a,h,u,s,c=s[1];if(t=dayjs(new Date(t.year(),t.month(),1)),o=t.subtract(t.day(),"day"),t=(s=[t.year(),t.month(),t.date()])[0],e=s[1],s=[this.today.year(),this.today.month(),this.today.date()],d=s[0],l=s[1],r=s[2],s=this.sel?[this.sel.year(),this.sel.month(),this.sel.date()]:[null,null,null],a=s[0],h=s[1],u=s[2],this.n.sel.month.value=this.months[e],this.n.sel.year.value=t,this.n.sel.minute.value=this.sel.minute(),this.n.sel.hour.value=this.sel.hour(),this.n.dc.map(function(t,e){var e=o.add(e,"day"),s=[e.year(),e.month(),e.date()],i=s[0],n=s[1],s=s[2];return t.date={year:i,month:n,date:s},t.innerText=e.date(),t.classList.toggle("dim",e.month()!==c),t.classList.toggle("today",d===i&&l===n&&r===s),t.classList.toggle("selected",a===i&&h===n&&u===s)}),s=this.value(),this.host&&(this.host.value=s),s!==this._value)return this._value=s,this.fire("change",s)},value:function(t){return arguments.length?((t=dayjs(t)).isValid()||(t=this._last||dayjs()),this._last=this.cur,this.sel=this.cur=t,this.update()):this._enabled.time?dayjs(new Date(this.sel.year(),this.sel.month(),this.sel.date(),this.sel.hour(),this.sel.minute())).format("YYYY-MM-DDTHH:mm:ssZ"):dayjs(new Date(this.sel.year(),this.sel.month(),this.sel.date())).format("YYYY-MM-DD")},config:function(t){return null==t?{suppress:!!this._suppress,time:{enabled:!!this._enabled.time}}:(null!=t.suppress&&(this._suppress=t.suppress),null!=t.time?(this._enabled.time=t.time,this.render()):void 0)},render:function(){return this.n.t.style.display=this._enabled.time?"":"none"}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.lddatetimepicker=t)}.call(this);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"lddatetimepicker","version":"0.0.
|
|
1
|
+
{"name":"lddatetimepicker","version":"0.0.14","description":"vanilla date/time picker","browser":"index.min.js","main":"index.js","scripts":{"start":"npx server -r web -o true"},"homepage":"https://github.com/loadingio/lddatetimepicker","repository":{"type":"git","url":"https://github.com/loadingio/lddatetimepicker"},"keywords":["date","time","datetime","datepicker","datetimepicker"],"author":"zbryikt","license":"MIT","devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"^1.0.1","@zbryikt/template":"^2.4.1","bootstrap":"^4.6.1","dayjs":"^1.11.0","fedep":"^1.6.0","ldcover":"^3.5.6","ldview":"^1.7.1","livescript":"^1.6.0","proxise":"^1.0.1","stylus":"^0.57.0","uglify-js":"^3.15.3","uglifycss":"^0.0.29","zmgr":"^2.2.3"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["@loadingio/bootstrap.ext","@loadingio/debounce.js","@loadingio/ldquery","dayjs","bootstrap","ldcover","ldview","zmgr","proxise"]},"dependencies":{"@loadingio/ldquery":"^3.0.6"}}
|