@nrk/core-datepicker
Advanced tools
Comparing version 3.0.5 to 3.0.6
@@ -177,21 +177,2 @@ 'use strict'; | ||
/** | ||
* escapeHTML | ||
* @param {String} str A string with potential html tokens | ||
* @return {String} Escaped HTML string according to OWASP recommendation | ||
*/ | ||
var ESCAPE_MAP = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'/': '/', | ||
'\'': ''' | ||
}; | ||
function escapeHTML(str) { | ||
return String(str || '').replace(/[&<>"'/]/g, function (_char) { | ||
return ESCAPE_MAP[_char]; | ||
}); | ||
} | ||
/** | ||
* closest | ||
@@ -530,3 +511,3 @@ * @param {Element} element Element to traverse up from | ||
return [].forEach.call(document.getElementsByTagName(css), function (el) { | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el, self._date); | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el); | ||
}); | ||
@@ -536,2 +517,4 @@ }; | ||
function button(self, el) { | ||
if (!el.value) return; // Skip buttons without a set value | ||
el.type = 'button'; // Ensure forms are not submitted by datepicker-buttons | ||
@@ -559,3 +542,3 @@ | ||
if (!table.firstElementChild) { | ||
table.innerHTML = "\n <caption></caption><thead><tr><th>".concat(self.days.map(escapeHTML).join('</th><th>'), "</th></tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'), "</tr>")), "</tbody>"); | ||
table.innerHTML = "\n <caption></caption><thead><tr>".concat(Array(8).join('</th><th>'), "</tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'), "</tr>")), "</tbody>"); | ||
} | ||
@@ -568,2 +551,5 @@ | ||
table.caption.textContent = "".concat(self.months[month], ", ").concat(self.year); | ||
queryAll('th', table).forEach(function (th, day) { | ||
return th.textContent = self.days[day]; | ||
}); | ||
queryAll('button', table).forEach(function (button) { | ||
@@ -588,8 +574,10 @@ var isSelected = !self.diff(day); | ||
if (!select.firstElementChild) { | ||
select._autofill = true; | ||
select.innerHTML = self.months.map(function (name, month) { | ||
return "<option value=\"y-".concat(month + 1, "-d\">").concat(escapeHTML(name), "</option>"); | ||
return "<option value=\"y-".concat(month + 1, "-d\"></option>"); | ||
}).join(''); | ||
} | ||
queryAll(select.children).forEach(function (option) { | ||
queryAll(select.children).forEach(function (option, month) { | ||
if (select._autofill) option.textContent = self.months[month]; | ||
option.disabled = self.disabled(option.value); | ||
@@ -596,0 +584,0 @@ option.selected = !self.diff(option.value); |
@@ -1,2 +0,2 @@ | ||
import { addStyle, closest, escapeHTML, dispatchEvent, queryAll } from '../utils' | ||
import { addStyle, closest, dispatchEvent, queryAll } from '../utils' | ||
import parse from '@nrk/simple-date-parse' | ||
@@ -20,2 +20,3 @@ | ||
} | ||
disconnectedCallback () { | ||
@@ -27,2 +28,3 @@ this._date = this._disabled = null // Garbage collection | ||
} | ||
attributeChangedCallback () { | ||
@@ -38,2 +40,3 @@ if (!this._date) return // Only render after connectedCallback | ||
} | ||
handleEvent (event) { | ||
@@ -54,6 +57,9 @@ if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || (event.type === 'keydown' && !KEYS[event.keyCode])) return | ||
} | ||
diff (val) { return this.parse(val).getTime() - this.timestamp } | ||
parse (val, from) { return parse(val, from || this._date) } | ||
get disabled () { return this._disabled || Function.prototype } | ||
set disabled (fn) { | ||
@@ -65,13 +71,25 @@ this._disabled = typeof fn === 'function' ? (val) => fn(this.parse(val), this) : () => fn // Auto parse dates | ||
get timestamp () { return String(this._date.getTime()) } | ||
get year () { return String(this._date.getFullYear()) } // Stringify for consistency and for truthy '0' | ||
get month () { return pad(this._date.getMonth() + 1) } | ||
get day () { return pad(this._date.getDate()) } | ||
get hour () { return pad(this._date.getHours()) } | ||
get minute () { return pad(this._date.getMinutes()) } | ||
get second () { return pad(this._date.getSeconds()) } | ||
get date () { return parse(this.getAttribute('timestamp') || this._date || Date.now()) } | ||
set date (val) { return this.setAttribute('timestamp', this.parse(val).getTime()) } | ||
set months (val) { this.setAttribute('months', [].concat(val).join(',')) } | ||
get months () { return (this.getAttribute('months') || MONTHS).split(/\s*,\s*/) } | ||
set days (val) { this.setAttribute('days', [].concat(val).join(',')) } | ||
get days () { return (this.getAttribute('days') || DAYS).split(/\s*,\s*/) } | ||
@@ -82,6 +100,7 @@ } | ||
const forEach = (css, self, fn) => [].forEach.call(document.getElementsByTagName(css), (el) => { | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el, self._date) | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el) | ||
}) | ||
function button (self, el) { | ||
if (!el.value) return // Skip buttons without a set value | ||
el.type = 'button' // Ensure forms are not submitted by datepicker-buttons | ||
@@ -107,3 +126,3 @@ el.disabled = self.disabled(el.value) | ||
table.innerHTML = ` | ||
<caption></caption><thead><tr><th>${self.days.map(escapeHTML).join('</th><th>')}</th></tr></thead> | ||
<caption></caption><thead><tr>${Array(8).join('</th><th>')}</tr></thead> | ||
<tbody>${Array(7).join(`<tr>${Array(8).join('<td><button type="button"></button></td>')}</tr>`)}</tbody>` | ||
@@ -117,2 +136,3 @@ } | ||
queryAll('th', table).forEach((th, day) => (th.textContent = self.days[day])) | ||
queryAll('button', table).forEach((button) => { | ||
@@ -137,8 +157,10 @@ const isSelected = !self.diff(day) | ||
if (!select.firstElementChild) { | ||
select._autofill = true | ||
select.innerHTML = self.months.map((name, month) => | ||
`<option value="y-${month + 1}-d">${escapeHTML(name)}</option>` | ||
`<option value="y-${month + 1}-d"></option>` | ||
).join('') | ||
} | ||
queryAll(select.children).forEach((option) => { | ||
queryAll(select.children).forEach((option, month) => { | ||
if (select._autofill) option.textContent = self.months[month] | ||
option.disabled = self.disabled(option.value) | ||
@@ -145,0 +167,0 @@ option.selected = !self.diff(option.value) |
@@ -6,5 +6,5 @@ import CoreDatepicker from './core-datepicker.js' | ||
export default customElementToReact(CoreDatepicker, { | ||
props: ['disabled', 'months', 'days'], | ||
props: ['disabled'], | ||
customEvents: ['datepicker.change', 'datepicker.click.day'], | ||
suffix: version | ||
}) |
@@ -183,21 +183,2 @@ (function (global, factory) { | ||
/** | ||
* escapeHTML | ||
* @param {String} str A string with potential html tokens | ||
* @return {String} Escaped HTML string according to OWASP recommendation | ||
*/ | ||
var ESCAPE_MAP = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'/': '/', | ||
'\'': ''' | ||
}; | ||
function escapeHTML(str) { | ||
return String(str || '').replace(/[&<>"'/]/g, function (_char) { | ||
return ESCAPE_MAP[_char]; | ||
}); | ||
} | ||
/** | ||
* closest | ||
@@ -536,3 +517,3 @@ * @param {Element} element Element to traverse up from | ||
return [].forEach.call(document.getElementsByTagName(css), function (el) { | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el, self._date); | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el); | ||
}); | ||
@@ -542,2 +523,4 @@ }; | ||
function button(self, el) { | ||
if (!el.value) return; // Skip buttons without a set value | ||
el.type = 'button'; // Ensure forms are not submitted by datepicker-buttons | ||
@@ -565,3 +548,3 @@ | ||
if (!table.firstElementChild) { | ||
table.innerHTML = "\n <caption></caption><thead><tr><th>".concat(self.days.map(escapeHTML).join('</th><th>'), "</th></tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'), "</tr>")), "</tbody>"); | ||
table.innerHTML = "\n <caption></caption><thead><tr>".concat(Array(8).join('</th><th>'), "</tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'), "</tr>")), "</tbody>"); | ||
} | ||
@@ -574,2 +557,5 @@ | ||
table.caption.textContent = "".concat(self.months[month], ", ").concat(self.year); | ||
queryAll('th', table).forEach(function (th, day) { | ||
return th.textContent = self.days[day]; | ||
}); | ||
queryAll('button', table).forEach(function (button) { | ||
@@ -594,8 +580,10 @@ var isSelected = !self.diff(day); | ||
if (!select.firstElementChild) { | ||
select._autofill = true; | ||
select.innerHTML = self.months.map(function (name, month) { | ||
return "<option value=\"y-".concat(month + 1, "-d\">").concat(escapeHTML(name), "</option>"); | ||
return "<option value=\"y-".concat(month + 1, "-d\"></option>"); | ||
}).join(''); | ||
} | ||
queryAll(select.children).forEach(function (option) { | ||
queryAll(select.children).forEach(function (option, month) { | ||
if (select._autofill) option.textContent = self.months[month]; | ||
option.disabled = self.disabled(option.value); | ||
@@ -606,3 +594,3 @@ option.selected = !self.diff(option.value); | ||
var version = "3.0.5"; | ||
var version = "3.0.6"; | ||
@@ -741,3 +729,3 @@ /** | ||
var coreDatepicker = customElementToReact(CoreDatepicker, { | ||
props: ['disabled', 'months', 'days'], | ||
props: ['disabled'], | ||
customEvents: ['datepicker.change', 'datepicker.click.day'], | ||
@@ -744,0 +732,0 @@ suffix: version |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-datepicker v3.0.5 - Copyright (c) 2017-2019 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).coreDatepicker=e()}(this,function(){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(t,e,n){return(i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&c(i,n.prototype),i}).apply(null,arguments)}function s(t){var r="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||(e=t,-1===Function.toString.call(e).indexOf("[native code]")))return t;var e;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return i(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,t)})(t)}function d(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var t="undefined"!=typeof window;t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform));t&&!window.Element.prototype.toggleAttribute&&(window.Element.prototype.toggleAttribute=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!this.hasAttribute(t);return!e===this.hasAttribute(t)&&this[e?"setAttribute":"removeAttribute"](t,""),e}),t||global.HTMLElement||(global.HTMLElement=function(){return function t(){o(this,t)}}());var e={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function n(t){return String(t||"").replace(/[&<>"'/]/g,function(t){return e[t]})}var r,l,f=(r="undefined"==typeof window?{}:window.Element.prototype,l=r.matches||r.msMatchesSelector||r.webkitMatchesSelector,r.closest?function(t,e){return t.closest(e)}:function(t,e){for(;t;t=t.parentElement)if(l.call(t,e))return t;return null});function h(t,e){var n,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[i])return!0;t[i]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:r}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,r);var o=t.dispatchEvent(n);return t[i]=null,o}function y(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document;if(t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var p,m=(function(t,e){var b,v,w,k;t.exports=(b={year:"FullYear",month:"Month",week:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds"},v=/([+-]\s*\d+)\s*(second|minute|hour|day|week|month|year)|(mon)|(tue)|(wed)|(thu)|(fri)|(sat)|(sun)/g,w=/([-\dy]+)[-/.]([\dm]+)[-/.]([\dd]+)/,k=/([\dh]+):([\dm]+):?([\ds]+)?/,function(t,e){if(isFinite(t))return new Date(Number(t));var n=String(t).toLowerCase(),i=new Date(isFinite(e)&&-1===n.indexOf("now")?Number(e):Date.now()),r=n.match(w)||[],o=r[1];void 0===o&&(o="y");var a=r[2];void 0===a&&(a="m");var u=r[3];void 0===u&&(u="d");var c=n.match(k)||[],s=c[1];void 0===s&&(s="h");var d=c[2];void 0===d&&(d="m");var l=c[3];void 0===l&&(l="s");var f={year:o,month:a,day:u,hour:s,minute:d,second:l};Object.keys(f).forEach(function(t){var e="month"===t?1:0,r=String(i["get"+b[t]]()+e);f[t]=f[t].replace(/[^-\d]+/g,function(t,e,n){return e?r.substr(r.length-n.length+e,t.length):r.substr(0,Math.max(0,r.length-n.length+t.length))})-e});var h=new Date(f.year,Math.min(12,f.month+1),0).getDate();for(i.setFullYear(f.year,Math.min(11,f.month),Math.max(1,Math.min(h,f.day))),i.setHours(Math.min(24,f.hour),Math.min(59,f.minute),Math.min(59,f.second));null!==(f=v.exec(n));){var y=f[2],p=String(f[1]).replace(/\s/g,"")*("week"===y?7:1),m=f.slice(2).indexOf(f[0]),g=i.getDate();y?i["set"+b[y]](i["get"+b[y]]()+p):i.setDate(i.getDate()-(i.getDay()||7)+m),"month"!==y&&"year"!==y||g===i.getDate()||i.setDate(0)}return i})}(p={exports:{}},p.exports),p.exports),g={year:"*-m-d",month:"y-*-d",day:"y-m-*",hour:"*:m",minute:"h:*",second:"h:m:*",timestamp:"*",null:"*"},b={33:"-1month",34:"+1month",35:"y-m-99",36:"y-m-1",37:"-1day",38:"-1week",39:"+1day",40:"+1week"},v=function(t){function e(){return o(this,e),d(this,u(e).apply(this,arguments))}var n,r,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(e,s(HTMLElement)),n=e,i=[{key:"observedAttributes",get:function(){return["timestamp","months","days"]}}],(r=[{key:"connectedCallback",value:function(){var t,e,n,r,i=this;this._date=this.date,document.addEventListener("click",this),document.addEventListener("change",this),document.addEventListener("keydown",this),setTimeout(function(){return i.attributeChangedCallback()}),t=this.nodeName,e="".concat(this.nodeName,"{display:block}"),n="style-".concat(t.toLowerCase()),r=e.replace(/\/\*[^!][^*]*\*\//g,"").replace(/\s*(^|[:;,{}]|$)\s*/g,"$1"),document.getElementById(n)||document.head.insertAdjacentHTML("afterbegin",'<style id="'.concat(n,'">').concat(r,"</style>"))}},{key:"disconnectedCallback",value:function(){this._date=this._disabled=null,document.removeEventListener("click",this),document.removeEventListener("change",this),document.removeEventListener("keydown",this)}},{key:"attributeChangedCallback",value:function(){if(this._date){if(this.disabled(this.date)&&!this.disabled(this._date))return this.date=this._date;this.diff(this.date)&&h(this,"datepicker.change",this._date=this.date),k("button",this,E),k("select",this,M),k("input",this,_),k("table",this,A)}}},{key:"handleEvent",value:function(t){if(!(t.defaultPrevented||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey||"keydown"===t.type&&!b[t.keyCode])&&(this.contains(t.target)||f(t.target,'[for="'.concat(this.id,'"]'))))if("change"===t.type)this.date=g[t.target.getAttribute("data-type")].replace("*",t.target.value);else if("click"===t.type){var e=f(t.target,"button[value]"),n=f(t.target,"table");e&&(this.date=e.value),e&&n&&h(this,"datepicker.click.day")}else"keydown"===t.type&&f(t.target,"table")&&(this.date=b[t.keyCode],this.querySelector("[autofocus]").focus(),t.preventDefault())}},{key:"diff",value:function(t){return this.parse(t).getTime()-this.timestamp}},{key:"parse",value:function(t,e){return m(t,e||this._date)}},{key:"disabled",get:function(){return this._disabled||Function.prototype},set:function(e){var n=this;this._disabled="function"==typeof e?function(t){return e(n.parse(t),n)}:function(){return e},this.attributeChangedCallback()}},{key:"timestamp",get:function(){return String(this._date.getTime())}},{key:"year",get:function(){return String(this._date.getFullYear())}},{key:"month",get:function(){return w(this._date.getMonth()+1)}},{key:"day",get:function(){return w(this._date.getDate())}},{key:"hour",get:function(){return w(this._date.getHours())}},{key:"minute",get:function(){return w(this._date.getMinutes())}},{key:"second",get:function(){return w(this._date.getSeconds())}},{key:"date",get:function(){return m(this.getAttribute("timestamp")||this._date||Date.now())},set:function(t){return this.setAttribute("timestamp",this.parse(t).getTime())}},{key:"months",set:function(t){this.setAttribute("months",[].concat(t).join(","))},get:function(){return(this.getAttribute("months")||"januar,februar,mars,april,mai,juni,juli,august,september,oktober,november,desember").split(/\s*,\s*/)}},{key:"days",set:function(t){this.setAttribute("days",[].concat(t).join(","))},get:function(){return(this.getAttribute("days")||"man,tirs,ons,tors,fre,lør,søn").split(/\s*,\s*/)}}])&&a(n.prototype,r),i&&a(n,i),e}(),w=function(t){return"0".concat(t).slice(-2)},k=function(t,e,n){return[].forEach.call(document.getElementsByTagName(t),function(t){(e.contains(t)||e.id===t.getAttribute(e.external))&&n(e,t,e._date)})};function E(t,e){e.type="button",e.disabled=t.disabled(e.value)}function _(t,e){var n=e.getAttribute("data-type")||e.getAttribute("type");"radio"===n||"checkbox"===n?(e.disabled=t.disabled(e.value),e.checked=!t.diff(e.value)):g[n]&&(e.setAttribute("type","number"),e.setAttribute("data-type",n),e.value=t[n])}function A(i,t){t.firstElementChild||(t.innerHTML="\n <caption></caption><thead><tr><th>".concat(i.days.map(n).join("</th><th>"),"</th></tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'),"</tr>")),"</tbody>"));var o=new Date,a=i.date.getMonth(),u=i.parse("y-m-1 mon");t.caption.textContent="".concat(i.months[a],", ").concat(i.year),y("button",t).forEach(function(t){var e=!i.diff(u),n=u.getDate(),r=u.getMonth();t.textContent=n,t.value="".concat(u.getFullYear(),"-").concat(r+1,"-").concat(n),t.disabled=i.disabled(u),t.tabIndex=e-1,t.setAttribute("data-adjacent",a!==r),t.setAttribute("aria-label","".concat(n,". ").concat(i.months[r])),t.setAttribute("aria-current",u.getDate()===o.getDate()&&u.getMonth()===o.getMonth()&&u.getFullYear()===o.getFullYear()&&"date"),t.toggleAttribute("autofocus",e),u.setDate(n+1)})}function M(e,t){t.firstElementChild||(t.innerHTML=e.months.map(function(t,e){return'<option value="y-'.concat(e+1,'-d">').concat(n(t),"</option>")}).join("")),y(t.children).forEach(function(t){t.disabled=e.disabled(t.value),t.selected=!e.diff(t.value)})}return v}),window.customElements.define("core-datepicker",coreDatepicker); | ||
/*! @nrk/core-datepicker v3.0.6 - Copyright (c) 2017-2019 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).coreDatepicker=e()}(this,function(){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e,n){return(r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,n){var i=[null];i.push.apply(i,e);var r=new(Function.bind.apply(t,i));return n&&c(r,n.prototype),r}).apply(null,arguments)}function s(t){var i="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||(e=t,-1===Function.toString.call(e).indexOf("[native code]")))return t;var e;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(t))return i.get(t);i.set(t,n)}function n(){return r(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,t)})(t)}function d(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var t="undefined"!=typeof window;t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform));t&&!window.Element.prototype.toggleAttribute&&(window.Element.prototype.toggleAttribute=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!this.hasAttribute(t);return!e===this.hasAttribute(t)&&this[e?"setAttribute":"removeAttribute"](t,""),e}),t||global.HTMLElement||(global.HTMLElement=function(){return function t(){o(this,t)}}());var e,n,l=(e="undefined"==typeof window?{}:window.Element.prototype,n=e.matches||e.msMatchesSelector||e.webkitMatchesSelector,e.closest?function(t,e){return t.closest(e)}:function(t,e){for(;t;t=t.parentElement)if(n.call(t,e))return t;return null});function f(t,e){var n,i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},r="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[r])return!0;t[r]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:i}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,i);var o=t.dispatchEvent(n);return t[r]=null,o}function h(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document;if(t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var i,y=(function(t,e){var b,v,w,k;t.exports=(b={year:"FullYear",month:"Month",week:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds"},v=/([+-]\s*\d+)\s*(second|minute|hour|day|week|month|year)|(mon)|(tue)|(wed)|(thu)|(fri)|(sat)|(sun)/g,w=/([-\dy]+)[-/.]([\dm]+)[-/.]([\dd]+)/,k=/([\dh]+):([\dm]+):?([\ds]+)?/,function(t,e){if(isFinite(t))return new Date(Number(t));var n=String(t).toLowerCase(),r=new Date(isFinite(e)&&-1===n.indexOf("now")?Number(e):Date.now()),i=n.match(w)||[],o=i[1];void 0===o&&(o="y");var a=i[2];void 0===a&&(a="m");var u=i[3];void 0===u&&(u="d");var c=n.match(k)||[],s=c[1];void 0===s&&(s="h");var d=c[2];void 0===d&&(d="m");var l=c[3];void 0===l&&(l="s");var f={year:o,month:a,day:u,hour:s,minute:d,second:l};Object.keys(f).forEach(function(t){var e="month"===t?1:0,i=String(r["get"+b[t]]()+e);f[t]=f[t].replace(/[^-\d]+/g,function(t,e,n){return e?i.substr(i.length-n.length+e,t.length):i.substr(0,Math.max(0,i.length-n.length+t.length))})-e});var h=new Date(f.year,Math.min(12,f.month+1),0).getDate();for(r.setFullYear(f.year,Math.min(11,f.month),Math.max(1,Math.min(h,f.day))),r.setHours(Math.min(24,f.hour),Math.min(59,f.minute),Math.min(59,f.second));null!==(f=v.exec(n));){var y=f[2],m=String(f[1]).replace(/\s/g,"")*("week"===y?7:1),p=f.slice(2).indexOf(f[0]),g=r.getDate();y?r["set"+b[y]](r["get"+b[y]]()+m):r.setDate(r.getDate()-(r.getDay()||7)+p),"month"!==y&&"year"!==y||g===r.getDate()||r.setDate(0)}return r})}(i={exports:{}},i.exports),i.exports),m={year:"*-m-d",month:"y-*-d",day:"y-m-*",hour:"*:m",minute:"h:*",second:"h:m:*",timestamp:"*",null:"*"},p={33:"-1month",34:"+1month",35:"y-m-99",36:"y-m-1",37:"-1day",38:"-1week",39:"+1day",40:"+1week"},g=function(t){function e(){return o(this,e),d(this,u(e).apply(this,arguments))}var n,i,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(e,s(HTMLElement)),n=e,r=[{key:"observedAttributes",get:function(){return["timestamp","months","days"]}}],(i=[{key:"connectedCallback",value:function(){var t,e,n,i,r=this;this._date=this.date,document.addEventListener("click",this),document.addEventListener("change",this),document.addEventListener("keydown",this),setTimeout(function(){return r.attributeChangedCallback()}),t=this.nodeName,e="".concat(this.nodeName,"{display:block}"),n="style-".concat(t.toLowerCase()),i=e.replace(/\/\*[^!][^*]*\*\//g,"").replace(/\s*(^|[:;,{}]|$)\s*/g,"$1"),document.getElementById(n)||document.head.insertAdjacentHTML("afterbegin",'<style id="'.concat(n,'">').concat(i,"</style>"))}},{key:"disconnectedCallback",value:function(){this._date=this._disabled=null,document.removeEventListener("click",this),document.removeEventListener("change",this),document.removeEventListener("keydown",this)}},{key:"attributeChangedCallback",value:function(){if(this._date){if(this.disabled(this.date)&&!this.disabled(this._date))return this.date=this._date;this.diff(this.date)&&f(this,"datepicker.change",this._date=this.date),v("button",this,w),v("select",this,_),v("input",this,k),v("table",this,E)}}},{key:"handleEvent",value:function(t){if(!(t.defaultPrevented||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey||"keydown"===t.type&&!p[t.keyCode])&&(this.contains(t.target)||l(t.target,'[for="'.concat(this.id,'"]'))))if("change"===t.type)this.date=m[t.target.getAttribute("data-type")].replace("*",t.target.value);else if("click"===t.type){var e=l(t.target,"button[value]"),n=l(t.target,"table");e&&(this.date=e.value),e&&n&&f(this,"datepicker.click.day")}else"keydown"===t.type&&l(t.target,"table")&&(this.date=p[t.keyCode],this.querySelector("[autofocus]").focus(),t.preventDefault())}},{key:"diff",value:function(t){return this.parse(t).getTime()-this.timestamp}},{key:"parse",value:function(t,e){return y(t,e||this._date)}},{key:"disabled",get:function(){return this._disabled||Function.prototype},set:function(e){var n=this;this._disabled="function"==typeof e?function(t){return e(n.parse(t),n)}:function(){return e},this.attributeChangedCallback()}},{key:"timestamp",get:function(){return String(this._date.getTime())}},{key:"year",get:function(){return String(this._date.getFullYear())}},{key:"month",get:function(){return b(this._date.getMonth()+1)}},{key:"day",get:function(){return b(this._date.getDate())}},{key:"hour",get:function(){return b(this._date.getHours())}},{key:"minute",get:function(){return b(this._date.getMinutes())}},{key:"second",get:function(){return b(this._date.getSeconds())}},{key:"date",get:function(){return y(this.getAttribute("timestamp")||this._date||Date.now())},set:function(t){return this.setAttribute("timestamp",this.parse(t).getTime())}},{key:"months",set:function(t){this.setAttribute("months",[].concat(t).join(","))},get:function(){return(this.getAttribute("months")||"januar,februar,mars,april,mai,juni,juli,august,september,oktober,november,desember").split(/\s*,\s*/)}},{key:"days",set:function(t){this.setAttribute("days",[].concat(t).join(","))},get:function(){return(this.getAttribute("days")||"man,tirs,ons,tors,fre,lør,søn").split(/\s*,\s*/)}}])&&a(n.prototype,i),r&&a(n,r),e}(),b=function(t){return"0".concat(t).slice(-2)},v=function(t,e,n){return[].forEach.call(document.getElementsByTagName(t),function(t){(e.contains(t)||e.id===t.getAttribute(e.external))&&n(e,t)})};function w(t,e){e.value&&(e.type="button",e.disabled=t.disabled(e.value))}function k(t,e){var n=e.getAttribute("data-type")||e.getAttribute("type");"radio"===n||"checkbox"===n?(e.disabled=t.disabled(e.value),e.checked=!t.diff(e.value)):m[n]&&(e.setAttribute("type","number"),e.setAttribute("data-type",n),e.value=t[n])}function E(r,t){t.firstElementChild||(t.innerHTML="\n <caption></caption><thead><tr>".concat(Array(8).join("</th><th>"),"</tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'),"</tr>")),"</tbody>"));var o=new Date,a=r.date.getMonth(),u=r.parse("y-m-1 mon");t.caption.textContent="".concat(r.months[a],", ").concat(r.year),h("th",t).forEach(function(t,e){return t.textContent=r.days[e]}),h("button",t).forEach(function(t){var e=!r.diff(u),n=u.getDate(),i=u.getMonth();t.textContent=n,t.value="".concat(u.getFullYear(),"-").concat(i+1,"-").concat(n),t.disabled=r.disabled(u),t.tabIndex=e-1,t.setAttribute("data-adjacent",a!==i),t.setAttribute("aria-label","".concat(n,". ").concat(r.months[i])),t.setAttribute("aria-current",u.getDate()===o.getDate()&&u.getMonth()===o.getMonth()&&u.getFullYear()===o.getFullYear()&&"date"),t.toggleAttribute("autofocus",e),u.setDate(n+1)})}function _(n,i){i.firstElementChild||(i._autofill=!0,i.innerHTML=n.months.map(function(t,e){return'<option value="y-'.concat(e+1,'-d"></option>')}).join("")),h(i.children).forEach(function(t,e){i._autofill&&(t.textContent=n.months[e]),t.disabled=n.disabled(t.value),t.selected=!n.diff(t.value)})}return g}),window.customElements.define("core-datepicker",coreDatepicker); | ||
//# sourceMappingURL=core-datepicker.min.js.map |
38
jsx.js
@@ -181,21 +181,2 @@ 'use strict'; | ||
/** | ||
* escapeHTML | ||
* @param {String} str A string with potential html tokens | ||
* @return {String} Escaped HTML string according to OWASP recommendation | ||
*/ | ||
var ESCAPE_MAP = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'/': '/', | ||
'\'': ''' | ||
}; | ||
function escapeHTML(str) { | ||
return String(str || '').replace(/[&<>"'/]/g, function (_char) { | ||
return ESCAPE_MAP[_char]; | ||
}); | ||
} | ||
/** | ||
* closest | ||
@@ -534,3 +515,3 @@ * @param {Element} element Element to traverse up from | ||
return [].forEach.call(document.getElementsByTagName(css), function (el) { | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el, self._date); | ||
if (self.contains(el) || self.id === el.getAttribute(self.external)) fn(self, el); | ||
}); | ||
@@ -540,2 +521,4 @@ }; | ||
function button(self, el) { | ||
if (!el.value) return; // Skip buttons without a set value | ||
el.type = 'button'; // Ensure forms are not submitted by datepicker-buttons | ||
@@ -563,3 +546,3 @@ | ||
if (!table.firstElementChild) { | ||
table.innerHTML = "\n <caption></caption><thead><tr><th>".concat(self.days.map(escapeHTML).join('</th><th>'), "</th></tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'), "</tr>")), "</tbody>"); | ||
table.innerHTML = "\n <caption></caption><thead><tr>".concat(Array(8).join('</th><th>'), "</tr></thead>\n <tbody>").concat(Array(7).join("<tr>".concat(Array(8).join('<td><button type="button"></button></td>'), "</tr>")), "</tbody>"); | ||
} | ||
@@ -572,2 +555,5 @@ | ||
table.caption.textContent = "".concat(self.months[month], ", ").concat(self.year); | ||
queryAll('th', table).forEach(function (th, day) { | ||
return th.textContent = self.days[day]; | ||
}); | ||
queryAll('button', table).forEach(function (button) { | ||
@@ -592,8 +578,10 @@ var isSelected = !self.diff(day); | ||
if (!select.firstElementChild) { | ||
select._autofill = true; | ||
select.innerHTML = self.months.map(function (name, month) { | ||
return "<option value=\"y-".concat(month + 1, "-d\">").concat(escapeHTML(name), "</option>"); | ||
return "<option value=\"y-".concat(month + 1, "-d\"></option>"); | ||
}).join(''); | ||
} | ||
queryAll(select.children).forEach(function (option) { | ||
queryAll(select.children).forEach(function (option, month) { | ||
if (select._autofill) option.textContent = self.months[month]; | ||
option.disabled = self.disabled(option.value); | ||
@@ -604,3 +592,3 @@ option.selected = !self.diff(option.value); | ||
var version = "3.0.5"; | ||
var version = "3.0.6"; | ||
@@ -739,3 +727,3 @@ /** | ||
var coreDatepicker = customElementToReact(CoreDatepicker, { | ||
props: ['disabled', 'months', 'days'], | ||
props: ['disabled'], | ||
customEvents: ['datepicker.change', 'datepicker.click.day'], | ||
@@ -742,0 +730,0 @@ suffix: version |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-datepicker.cjs.js", |
Sorry, the diff of this file is not supported yet
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
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
0
169272
11
2114