Socket
Socket
Sign inDemoInstall

@primer/view-components

Package Overview
Dependencies
Maintainers
8
Versions
5358
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@primer/view-components - npm Package Compare versions

Comparing version 0.0.37 to 0.0.38

app/components/primer/clipboard_copy_component.d.ts

2

app/assets/javascripts/primer_view_components.js

@@ -1,2 +0,2 @@

const t=!!navigator.userAgent.match(/Macintosh/);class e{constructor(e,n){this.input=e,this.list=n,this.isComposing=!1,n.id||(n.id=`combobox-${Math.random().toString().slice(2,6)}`),this.keyboardEventHandler=e=>function(e,n){if(e.shiftKey||e.metaKey||e.altKey)return;if(!t&&e.ctrlKey)return;if(n.isComposing)return;switch(e.key){case"Enter":case"Tab":(function(t,e){const n=e.querySelector('[aria-selected="true"]');return!!n&&("true"===n.getAttribute("aria-disabled")||n.click(),!0)})(n.input,n.list)&&e.preventDefault();break;case"Escape":n.clearSelection();break;case"ArrowDown":n.navigate(1),e.preventDefault();break;case"ArrowUp":n.navigate(-1),e.preventDefault();break;case"n":t&&e.ctrlKey&&(n.navigate(1),e.preventDefault());break;case"p":t&&e.ctrlKey&&(n.navigate(-1),e.preventDefault());break;default:if(e.ctrlKey)break;n.clearSelection()}}(e,this),this.compositionEventHandler=t=>function(t,e){e.isComposing="compositionstart"===t.type;if(!document.getElementById(e.input.getAttribute("aria-controls")||""))return;e.clearSelection()}(t,this),this.inputHandler=this.clearSelection.bind(this),e.setAttribute("role","combobox"),e.setAttribute("aria-controls",n.id),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("aria-haspopup","listbox")}destroy(){this.clearSelection(),this.stop(),this.input.removeAttribute("role"),this.input.removeAttribute("aria-controls"),this.input.removeAttribute("aria-expanded"),this.input.removeAttribute("aria-autocomplete"),this.input.removeAttribute("aria-haspopup")}start(){this.input.setAttribute("aria-expanded","true"),this.input.addEventListener("compositionstart",this.compositionEventHandler),this.input.addEventListener("compositionend",this.compositionEventHandler),this.input.addEventListener("input",this.inputHandler),this.input.addEventListener("keydown",this.keyboardEventHandler),this.list.addEventListener("click",n)}stop(){this.clearSelection(),this.input.setAttribute("aria-expanded","false"),this.input.removeEventListener("compositionstart",this.compositionEventHandler),this.input.removeEventListener("compositionend",this.compositionEventHandler),this.input.removeEventListener("input",this.inputHandler),this.input.removeEventListener("keydown",this.keyboardEventHandler),this.list.removeEventListener("click",n)}navigate(t=1){const e=Array.from(this.list.querySelectorAll('[aria-selected="true"]')).filter(i)[0],n=Array.from(this.list.querySelectorAll('[role="option"]')).filter(i),s=n.indexOf(e);if(s===n.length-1&&1===t||0===s&&-1===t)return this.clearSelection(),void this.input.focus();let o=1===t?0:n.length-1;if(e&&s>=0){const e=s+t;e>=0&&e<n.length&&(o=e)}const a=n[o];if(a)for(const t of n)a===t?(this.input.setAttribute("aria-activedescendant",a.id),a.setAttribute("aria-selected","true"),r(this.list,a)):t.setAttribute("aria-selected","false")}clearSelection(){this.input.removeAttribute("aria-activedescendant");for(const t of this.list.querySelectorAll('[aria-selected="true"]'))t.setAttribute("aria-selected","false")}}function n(t){if(!(t.target instanceof Element))return;const e=t.target.closest('[role="option"]');e&&"true"!==e.getAttribute("aria-disabled")&&function(t){t.dispatchEvent(new CustomEvent("combobox-commit",{bubbles:!0}))}(e)}function i(t){return!t.hidden&&!(t instanceof HTMLInputElement&&"hidden"===t.type)&&(t.offsetWidth>0||t.offsetHeight>0)}function r(t,e){(function(t,e){const n=t.scrollTop,i=n+t.clientHeight,r=e.offsetTop,s=r+e.clientHeight;return r>=n&&s<=i})(t,e)||(t.scrollTop=e.offsetTop)}class s extends CustomEvent{constructor(t,e){super(t,e),this.relatedTarget=e.relatedTarget}}const o=new WeakMap;function a(t,e){const n=new XMLHttpRequest;return n.open("GET",e,!0),n.setRequestHeader("Accept","text/fragment+html"),function(t,e){const n=o.get(t);n&&n.abort();o.set(t,e);const i=()=>o.delete(t),r=function(t){return new Promise(((e,n)=>{t.onload=function(){t.status>=200&&t.status<300?e(t.responseText):n(new Error(t.responseText))},t.onerror=n,t.send()}))}(e);return r.then(i,i),r}(t,n)}class c{constructor(t,n,i){this.container=t,this.input=n,this.results=i,this.combobox=new e(n,i),this.results.hidden=!0,this.input.setAttribute("autocomplete","off"),this.input.setAttribute("spellcheck","false"),this.interactingWithList=!1,this.onInputChange=function(t,e=0){let n;return function(...i){clearTimeout(n),n=window.setTimeout((()=>{clearTimeout(n),t(...i)}),e)}}(this.onInputChange.bind(this),300),this.onResultsMouseDown=this.onResultsMouseDown.bind(this),this.onInputBlur=this.onInputBlur.bind(this),this.onInputFocus=this.onInputFocus.bind(this),this.onKeydown=this.onKeydown.bind(this),this.onCommit=this.onCommit.bind(this),this.input.addEventListener("keydown",this.onKeydown),this.input.addEventListener("focus",this.onInputFocus),this.input.addEventListener("blur",this.onInputBlur),this.input.addEventListener("input",this.onInputChange),this.results.addEventListener("mousedown",this.onResultsMouseDown),this.results.addEventListener("combobox-commit",this.onCommit)}destroy(){this.input.removeEventListener("keydown",this.onKeydown),this.input.removeEventListener("focus",this.onInputFocus),this.input.removeEventListener("blur",this.onInputBlur),this.input.removeEventListener("input",this.onInputChange),this.results.removeEventListener("mousedown",this.onResultsMouseDown),this.results.removeEventListener("combobox-commit",this.onCommit)}onKeydown(t){if("Escape"===t.key&&this.container.open)this.container.open=!1,t.stopPropagation(),t.preventDefault();else if(t.altKey&&"ArrowUp"===t.key&&this.container.open)this.container.open=!1,t.stopPropagation(),t.preventDefault();else if(t.altKey&&"ArrowDown"===t.key&&!this.container.open){if(!this.input.value.trim())return;this.container.open=!0,t.stopPropagation(),t.preventDefault()}}onInputFocus(){this.fetchResults()}onInputBlur(){this.interactingWithList?this.interactingWithList=!1:this.container.open=!1}onCommit({target:t}){const e=t;if(!(e instanceof HTMLElement))return;if(this.container.open=!1,e instanceof HTMLAnchorElement)return;const n=e.getAttribute("data-autocomplete-value")||e.textContent;this.container.value=n}onResultsMouseDown(){this.interactingWithList=!0}onInputChange(){this.container.removeAttribute("value"),this.fetchResults()}identifyOptions(){let t=0;for(const e of this.results.querySelectorAll('[role="option"]:not([id])'))e.id=`${this.results.id}-option-${t++}`}fetchResults(){const t=this.input.value.trim();if(!t)return void(this.container.open=!1);const e=this.container.src;if(!e)return;const n=new URL(e,window.location.href),i=new URLSearchParams(n.search.slice(1));i.append("q",t),n.search=i.toString(),this.container.dispatchEvent(new CustomEvent("loadstart")),a(this.input,n.toString()).then((t=>{this.results.innerHTML=t,this.identifyOptions();const e=!!this.results.querySelector('[role="option"]');this.container.open=e,this.container.dispatchEvent(new CustomEvent("load")),this.container.dispatchEvent(new CustomEvent("loadend"))})).catch((()=>{this.container.dispatchEvent(new CustomEvent("error")),this.container.dispatchEvent(new CustomEvent("loadend"))}))}open(){this.results.hidden&&(this.combobox.start(),this.results.hidden=!1)}close(){this.results.hidden||(this.combobox.stop(),this.results.hidden=!0)}}const u=new WeakMap;class l extends HTMLElement{constructor(){super()}connectedCallback(){const t=this.getAttribute("for");if(!t)return;const e=this.querySelector("input"),n=document.getElementById(t);e instanceof HTMLInputElement&&n&&(u.set(this,new c(this,e,n)),n.setAttribute("role","listbox"))}disconnectedCallback(){const t=u.get(this);t&&(t.destroy(),u.delete(this))}get src(){return this.getAttribute("src")||""}set src(t){this.setAttribute("src",t)}get value(){return this.getAttribute("value")||""}set value(t){this.setAttribute("value",t)}get open(){return this.hasAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}static get observedAttributes(){return["open","value"]}attributeChangedCallback(t,e,n){if(e===n)return;const i=u.get(this);if(i)switch(t){case"open":null===n?i.close():i.open();break;case"value":null!==n&&(i.input.value=n),this.dispatchEvent(new s("auto-complete-change",{bubbles:!0,relatedTarget:i.input}))}}}window.customElements.get("auto-complete")||(window.AutocompleteElement=l,window.customElements.define("auto-complete",l));class h extends HTMLElement{constructor(){super(),this.addEventListener("keydown",(t=>{const e=t.target;if(!(e instanceof HTMLElement))return;if("tab"!==e.getAttribute("role")&&!e.closest('[role="tablist"]'))return;const n=Array.from(this.querySelectorAll('[role="tablist"] [role="tab"]')),i=n.indexOf(n.find((t=>t.matches('[aria-selected="true"]'))));if("ArrowRight"===t.code){let t=i+1;t>=n.length&&(t=0),d(this,t)}else if("ArrowLeft"===t.code){let t=i-1;t<0&&(t=n.length-1),d(this,t)}else"Home"===t.code?(d(this,0),t.preventDefault()):"End"===t.code&&(d(this,n.length-1),t.preventDefault())})),this.addEventListener("click",(t=>{const e=Array.from(this.querySelectorAll('[role="tablist"] [role="tab"]'));if(!(t.target instanceof Element))return;const n=t.target.closest('[role="tab"]');if(!n||!n.closest('[role="tablist"]'))return;d(this,e.indexOf(n))}))}connectedCallback(){for(const t of this.querySelectorAll('[role="tablist"] [role="tab"]'))t.hasAttribute("aria-selected")||t.setAttribute("aria-selected","false"),t.hasAttribute("tabindex")||("true"===t.getAttribute("aria-selected")?t.setAttribute("tabindex","0"):t.setAttribute("tabindex","-1"))}}function d(t,e){const n=t.querySelectorAll('[role="tablist"] [role="tab"]'),i=t.querySelectorAll('[role="tabpanel"]'),r=n[e],s=i[e];if(!!t.dispatchEvent(new CustomEvent("tab-container-change",{bubbles:!0,cancelable:!0,detail:{relatedTarget:s}}))){for(const t of n)t.setAttribute("aria-selected","false"),t.setAttribute("tabindex","-1");for(const t of i)t.hidden=!0,t.hasAttribute("tabindex")||t.hasAttribute("data-tab-container-no-tabstop")||t.setAttribute("tabindex","0");r.setAttribute("aria-selected","true"),r.setAttribute("tabindex","0"),r.focus(),s.hidden=!1,t.dispatchEvent(new CustomEvent("tab-container-changed",{bubbles:!0,detail:{relatedTarget:s}}))}}window.customElements.get("tab-container")||(window.TabContainerElement=h,window.customElements.define("tab-container",h));const m=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],p=["January","February","March","April","May","June","July","August","September","October","November","December"];function f(t){return"0".concat(t).slice(-2)}function b(t,e){const n=t.getDay(),i=t.getDate(),r=t.getMonth(),s=t.getFullYear(),o=t.getHours(),a=t.getMinutes(),c=t.getSeconds();return e.replace(/%([%aAbBcdeHIlmMpPSwyYZz])/g,(function(e){let u;switch(e[1]){case"%":return"%";case"a":return m[n].slice(0,3);case"A":return m[n];case"b":return p[r].slice(0,3);case"B":return p[r];case"c":return t.toString();case"d":return f(i);case"e":return String(i);case"H":return f(o);case"I":return f(b(t,"%l"));case"l":return String(0===o||12===o?12:(o+12)%12);case"m":return f(r+1);case"M":return f(a);case"p":return o>11?"PM":"AM";case"P":return o>11?"pm":"am";case"S":return f(c);case"w":return String(n);case"y":return f(s%100);case"Y":return String(s);case"Z":return u=t.toString().match(/\((\w+)\)$/),u?u[1]:"";case"z":return u=t.toString().match(/\w([+-]\d\d\d\d) /),u?u[1]:""}return""}))}function g(t){let e;return function(){if(e)return e;if("Intl"in window)try{return e=new Intl.DateTimeFormat(void 0,t),e}catch(t){if(!(t instanceof RangeError))throw t}}}let w=null;const v=g({day:"numeric",month:"short"});function y(){if(null!==w)return w;const t=v();if(t){const e=t.format(new Date(0));return w=!!e.match(/^\d/),w}return!1}let A=null;const E=g({day:"numeric",month:"short",year:"numeric"});function M(t){const e=t.closest("[lang]");return e instanceof HTMLElement&&e.lang?e.lang:"default"}const T=new WeakMap;class k extends HTMLElement{static get observedAttributes(){return["datetime","day","format","lang","hour","minute","month","second","title","weekday","year"]}connectedCallback(){const t=this.getFormattedTitle();t&&!this.hasAttribute("title")&&this.setAttribute("title",t);const e=this.getFormattedDate();e&&(this.textContent=e)}attributeChangedCallback(t,e,n){const i=this.getFormattedTitle();if("datetime"===t){const t=Date.parse(n);isNaN(t)?T.delete(this):T.set(this,new Date(t))}const r=this.getFormattedTitle(),s=this.getAttribute("title");"title"===t||!r||s&&s!==i||this.setAttribute("title",r);const o=this.getFormattedDate();o&&(this.textContent=o)}get date(){return T.get(this)}getFormattedTitle(){const t=this.date;if(!t)return;const e=C();if(e)return e.format(t);try{return t.toLocaleString()}catch(e){if(e instanceof RangeError)return t.toString();throw e}}getFormattedDate(){}}const C=g({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"}),L=new WeakMap;class D extends k{attributeChangedCallback(t,e,n){"hour"!==t&&"minute"!==t&&"second"!==t&&"time-zone-name"!==t||L.delete(this),super.attributeChangedCallback(t,e,n)}getFormattedDate(){const t=this.date;if(!t)return;const e=function(t,e){const n={weekday:{short:"%a",long:"%A"},day:{numeric:"%e","2-digit":"%d"},month:{short:"%b",long:"%B"},year:{numeric:"%Y","2-digit":"%y"}};let i=y()?"weekday day month year":"weekday month day, year";for(const e in n){const r=n[e][t.getAttribute(e)];i=i.replace(e,r||"")}return i=i.replace(/(\s,)|(,\s$)/,""),b(e,i).replace(/\s+/," ").trim()}(this,t)||"",n=function(t,e){const n={},i=t.getAttribute("hour");"numeric"!==i&&"2-digit"!==i||(n.hour=i);const r=t.getAttribute("minute");"numeric"!==r&&"2-digit"!==r||(n.minute=r);const s=t.getAttribute("second");"numeric"!==s&&"2-digit"!==s||(n.second=s);const o=t.getAttribute("time-zone-name");"short"!==o&&"long"!==o||(n.timeZoneName=o);if(0===Object.keys(n).length)return;let a=L.get(t);a||(a=g(n),L.set(t,a));const c=a();if(c)return c.format(e);return b(e,n.second?"%H:%M:%S":"%H:%M")}(this,t)||"";return"".concat(e," ").concat(n).trim()}}window.customElements.get("local-time")||(window.LocalTimeElement=D,window.customElements.define("local-time",D));class S{constructor(t,e){this.date=t,this.locale=e}toString(){const t=this.timeElapsed();if(t)return t;{const t=this.timeAhead();return t||"on ".concat(this.formatDate())}}timeElapsed(){const t=(new Date).getTime()-this.date.getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24);return t>=0&&r<30?this.timeAgoFromMs(t):null}timeAhead(){const t=this.date.getTime()-(new Date).getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24);return t>=0&&r<30?this.timeUntil():null}timeAgo(){const t=(new Date).getTime()-this.date.getTime();return this.timeAgoFromMs(t)}timeAgoFromMs(t){const e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),s=Math.round(r/30),o=Math.round(s/12);return t<0||e<10?x(this.locale,0,"second"):e<45?x(this.locale,-e,"second"):e<90||n<45?x(this.locale,-n,"minute"):n<90||i<24?x(this.locale,-i,"hour"):i<36||r<30?x(this.locale,-r,"day"):s<18?x(this.locale,-s,"month"):x(this.locale,-o,"year")}microTimeAgo(){const t=(new Date).getTime()-this.date.getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),s=Math.round(r/30),o=Math.round(s/12);return n<1?"1m":n<60?"".concat(n,"m"):i<24?"".concat(i,"h"):r<365?"".concat(r,"d"):"".concat(o,"y")}timeUntil(){const t=this.date.getTime()-(new Date).getTime();return this.timeUntilFromMs(t)}timeUntilFromMs(t){const e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),s=Math.round(r/30),o=Math.round(s/12);return s>=18||s>=12?x(this.locale,o,"year"):r>=45||r>=30?x(this.locale,s,"month"):i>=36||i>=24?x(this.locale,r,"day"):n>=90||n>=45?x(this.locale,i,"hour"):e>=90||e>=45?x(this.locale,n,"minute"):x(this.locale,e>=10?e:0,"second")}microTimeUntil(){const t=this.date.getTime()-(new Date).getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),s=Math.round(r/30),o=Math.round(s/12);return r>=365?"".concat(o,"y"):i>=24?"".concat(r,"d"):n>=60?"".concat(i,"h"):n>1?"".concat(n,"m"):"1m"}formatDate(){let t=y()?"%e %b":"%b %e";var e;return e=this.date,(new Date).getUTCFullYear()!==e.getUTCFullYear()&&(t+=function(){if(null!==A)return A;const t=E();if(t){const e=t.format(new Date(0));return A=!!e.match(/\d,/),A}return!0}()?", %Y":" %Y"),b(this.date,t)}formatTime(){const t=H();return t?t.format(this.date):b(this.date,"%l:%M%P")}}function x(t,e,n){const i=function(t,e){if("Intl"in window&&"RelativeTimeFormat"in window.Intl)try{return new Intl.RelativeTimeFormat(t,e)}catch(t){if(!(t instanceof RangeError))throw t}}(t,{numeric:"auto"});return i?i.format(e,n):function(t,e){if(0===t)switch(e){case"year":case"quarter":case"month":case"week":return"this ".concat(e);case"day":return"today";case"hour":case"minute":return"in 0 ".concat(e,"s");case"second":return"now"}else if(1===t)switch(e){case"year":case"quarter":case"month":case"week":return"next ".concat(e);case"day":return"tomorrow";case"hour":case"minute":case"second":return"in 1 ".concat(e)}else if(-1===t)switch(e){case"year":case"quarter":case"month":case"week":return"last ".concat(e);case"day":return"yesterday";case"hour":case"minute":case"second":return"1 ".concat(e," ago")}else if(t>1)switch(e){case"year":case"quarter":case"month":case"week":case"day":case"hour":case"minute":case"second":return"in ".concat(t," ").concat(e,"s")}else if(t<-1)switch(e){case"year":case"quarter":case"month":case"week":case"day":case"hour":case"minute":case"second":return"".concat(-t," ").concat(e,"s ago")}throw new RangeError("Invalid unit argument for format() '".concat(e,"'"))}(e,n)}const H=g({hour:"numeric",minute:"2-digit"});class F extends k{getFormattedDate(){const t=this.date;if(t)return new S(t,M(this)).toString()}connectedCallback(){I.push(this),q||(R(),q=setInterval(R,6e4)),super.connectedCallback()}disconnectedCallback(){const t=I.indexOf(this);-1!==t&&I.splice(t,1),I.length||q&&(clearInterval(q),q=null)}}const I=[];let q;function R(){let t,e,n;for(e=0,n=I.length;e<n;e++)t=I[e],t.textContent=t.getFormattedDate()||""}window.customElements.get("relative-time")||(window.RelativeTimeElement=F,window.customElements.define("relative-time",F));class K extends F{getFormattedDate(){const t=this.getAttribute("format"),e=this.date;if(e)return"micro"===t?new S(e,M(this)).microTimeAgo():new S(e,M(this)).timeAgo()}}window.customElements.get("time-ago")||(window.TimeAgoElement=K,window.customElements.define("time-ago",K));class U extends F{getFormattedDate(){const t=this.getAttribute("format"),e=this.date;if(e)return"micro"===t?new S(e,M(this)).microTimeUntil():new S(e,M(this)).timeUntil()}}window.customElements.get("time-until")||(window.TimeUntilElement=U,window.customElements.define("time-until",U));
const t=!!navigator.userAgent.match(/Macintosh/);class e{constructor(e,n){this.input=e,this.list=n,this.isComposing=!1,n.id||(n.id=`combobox-${Math.random().toString().slice(2,6)}`),this.keyboardEventHandler=e=>function(e,n){if(e.shiftKey||e.metaKey||e.altKey)return;if(!t&&e.ctrlKey)return;if(n.isComposing)return;switch(e.key){case"Enter":case"Tab":(function(t,e){const n=e.querySelector('[aria-selected="true"]');return!!n&&("true"===n.getAttribute("aria-disabled")||n.click(),!0)})(n.input,n.list)&&e.preventDefault();break;case"Escape":n.clearSelection();break;case"ArrowDown":n.navigate(1),e.preventDefault();break;case"ArrowUp":n.navigate(-1),e.preventDefault();break;case"n":t&&e.ctrlKey&&(n.navigate(1),e.preventDefault());break;case"p":t&&e.ctrlKey&&(n.navigate(-1),e.preventDefault());break;default:if(e.ctrlKey)break;n.clearSelection()}}(e,this),this.compositionEventHandler=t=>function(t,e){e.isComposing="compositionstart"===t.type;if(!document.getElementById(e.input.getAttribute("aria-controls")||""))return;e.clearSelection()}(t,this),this.inputHandler=this.clearSelection.bind(this),e.setAttribute("role","combobox"),e.setAttribute("aria-controls",n.id),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("aria-haspopup","listbox")}destroy(){this.clearSelection(),this.stop(),this.input.removeAttribute("role"),this.input.removeAttribute("aria-controls"),this.input.removeAttribute("aria-expanded"),this.input.removeAttribute("aria-autocomplete"),this.input.removeAttribute("aria-haspopup")}start(){this.input.setAttribute("aria-expanded","true"),this.input.addEventListener("compositionstart",this.compositionEventHandler),this.input.addEventListener("compositionend",this.compositionEventHandler),this.input.addEventListener("input",this.inputHandler),this.input.addEventListener("keydown",this.keyboardEventHandler),this.list.addEventListener("click",n)}stop(){this.clearSelection(),this.input.setAttribute("aria-expanded","false"),this.input.removeEventListener("compositionstart",this.compositionEventHandler),this.input.removeEventListener("compositionend",this.compositionEventHandler),this.input.removeEventListener("input",this.inputHandler),this.input.removeEventListener("keydown",this.keyboardEventHandler),this.list.removeEventListener("click",n)}navigate(t=1){const e=Array.from(this.list.querySelectorAll('[aria-selected="true"]')).filter(i)[0],n=Array.from(this.list.querySelectorAll('[role="option"]')).filter(i),o=n.indexOf(e);if(o===n.length-1&&1===t||0===o&&-1===t)return this.clearSelection(),void this.input.focus();let s=1===t?0:n.length-1;if(e&&o>=0){const e=o+t;e>=0&&e<n.length&&(s=e)}const a=n[s];if(a)for(const t of n)a===t?(this.input.setAttribute("aria-activedescendant",a.id),a.setAttribute("aria-selected","true"),r(this.list,a)):t.setAttribute("aria-selected","false")}clearSelection(){this.input.removeAttribute("aria-activedescendant");for(const t of this.list.querySelectorAll('[aria-selected="true"]'))t.setAttribute("aria-selected","false")}}function n(t){if(!(t.target instanceof Element))return;const e=t.target.closest('[role="option"]');e&&"true"!==e.getAttribute("aria-disabled")&&function(t){t.dispatchEvent(new CustomEvent("combobox-commit",{bubbles:!0}))}(e)}function i(t){return!t.hidden&&!(t instanceof HTMLInputElement&&"hidden"===t.type)&&(t.offsetWidth>0||t.offsetHeight>0)}function r(t,e){(function(t,e){const n=t.scrollTop,i=n+t.clientHeight,r=e.offsetTop,o=r+e.clientHeight;return r>=n&&o<=i})(t,e)||(t.scrollTop=e.offsetTop)}class o extends CustomEvent{constructor(t,e){super(t,e),this.relatedTarget=e.relatedTarget}}const s=new WeakMap;function a(t,e){const n=new XMLHttpRequest;return n.open("GET",e,!0),n.setRequestHeader("Accept","text/fragment+html"),function(t,e){const n=s.get(t);n&&n.abort();s.set(t,e);const i=()=>s.delete(t),r=function(t){return new Promise(((e,n)=>{t.onload=function(){t.status>=200&&t.status<300?e(t.responseText):n(new Error(t.responseText))},t.onerror=n,t.send()}))}(e);return r.then(i,i),r}(t,n)}class c{constructor(t,n,i){this.container=t,this.input=n,this.results=i,this.combobox=new e(n,i),this.results.hidden=!0,this.input.setAttribute("autocomplete","off"),this.input.setAttribute("spellcheck","false"),this.interactingWithList=!1,this.onInputChange=function(t,e=0){let n;return function(...i){clearTimeout(n),n=window.setTimeout((()=>{clearTimeout(n),t(...i)}),e)}}(this.onInputChange.bind(this),300),this.onResultsMouseDown=this.onResultsMouseDown.bind(this),this.onInputBlur=this.onInputBlur.bind(this),this.onInputFocus=this.onInputFocus.bind(this),this.onKeydown=this.onKeydown.bind(this),this.onCommit=this.onCommit.bind(this),this.input.addEventListener("keydown",this.onKeydown),this.input.addEventListener("focus",this.onInputFocus),this.input.addEventListener("blur",this.onInputBlur),this.input.addEventListener("input",this.onInputChange),this.results.addEventListener("mousedown",this.onResultsMouseDown),this.results.addEventListener("combobox-commit",this.onCommit)}destroy(){this.input.removeEventListener("keydown",this.onKeydown),this.input.removeEventListener("focus",this.onInputFocus),this.input.removeEventListener("blur",this.onInputBlur),this.input.removeEventListener("input",this.onInputChange),this.results.removeEventListener("mousedown",this.onResultsMouseDown),this.results.removeEventListener("combobox-commit",this.onCommit)}onKeydown(t){if("Escape"===t.key&&this.container.open)this.container.open=!1,t.stopPropagation(),t.preventDefault();else if(t.altKey&&"ArrowUp"===t.key&&this.container.open)this.container.open=!1,t.stopPropagation(),t.preventDefault();else if(t.altKey&&"ArrowDown"===t.key&&!this.container.open){if(!this.input.value.trim())return;this.container.open=!0,t.stopPropagation(),t.preventDefault()}}onInputFocus(){this.fetchResults()}onInputBlur(){this.interactingWithList?this.interactingWithList=!1:this.container.open=!1}onCommit({target:t}){const e=t;if(!(e instanceof HTMLElement))return;if(this.container.open=!1,e instanceof HTMLAnchorElement)return;const n=e.getAttribute("data-autocomplete-value")||e.textContent;this.container.value=n}onResultsMouseDown(){this.interactingWithList=!0}onInputChange(){this.container.removeAttribute("value"),this.fetchResults()}identifyOptions(){let t=0;for(const e of this.results.querySelectorAll('[role="option"]:not([id])'))e.id=`${this.results.id}-option-${t++}`}fetchResults(){const t=this.input.value.trim();if(!t)return void(this.container.open=!1);const e=this.container.src;if(!e)return;const n=new URL(e,window.location.href),i=new URLSearchParams(n.search.slice(1));i.append("q",t),n.search=i.toString(),this.container.dispatchEvent(new CustomEvent("loadstart")),a(this.input,n.toString()).then((t=>{this.results.innerHTML=t,this.identifyOptions();const e=!!this.results.querySelector('[role="option"]');this.container.open=e,this.container.dispatchEvent(new CustomEvent("load")),this.container.dispatchEvent(new CustomEvent("loadend"))})).catch((()=>{this.container.dispatchEvent(new CustomEvent("error")),this.container.dispatchEvent(new CustomEvent("loadend"))}))}open(){this.results.hidden&&(this.combobox.start(),this.results.hidden=!1)}close(){this.results.hidden||(this.combobox.stop(),this.results.hidden=!0)}}const u=new WeakMap;class l extends HTMLElement{constructor(){super()}connectedCallback(){const t=this.getAttribute("for");if(!t)return;const e=this.querySelector("input"),n=document.getElementById(t);e instanceof HTMLInputElement&&n&&(u.set(this,new c(this,e,n)),n.setAttribute("role","listbox"))}disconnectedCallback(){const t=u.get(this);t&&(t.destroy(),u.delete(this))}get src(){return this.getAttribute("src")||""}set src(t){this.setAttribute("src",t)}get value(){return this.getAttribute("value")||""}set value(t){this.setAttribute("value",t)}get open(){return this.hasAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}static get observedAttributes(){return["open","value"]}attributeChangedCallback(t,e,n){if(e===n)return;const i=u.get(this);if(i)switch(t){case"open":null===n?i.close():i.open();break;case"value":null!==n&&(i.input.value=n),this.dispatchEvent(new o("auto-complete-change",{bubbles:!0,relatedTarget:i.input}))}}}function d(t){if("clipboard"in navigator)return navigator.clipboard.writeText(t.textContent);const e=getSelection();if(null==e)return Promise.reject(new Error);e.removeAllRanges();const n=document.createRange();return n.selectNodeContents(t),e.addRange(n),document.execCommand("copy"),e.removeAllRanges(),Promise.resolve()}function h(t){if("clipboard"in navigator)return navigator.clipboard.writeText(t);const e=document.body;if(!e)return Promise.reject(new Error);const n=function(t){const e=document.createElement("pre");return e.style.width="1px",e.style.height="1px",e.style.position="fixed",e.style.top="5px",e.textContent=t,e}(t);return e.appendChild(n),d(n),e.removeChild(n),Promise.resolve()}function m(t){const e=t.getAttribute("for"),n=t.getAttribute("value");function i(){t.dispatchEvent(new CustomEvent("clipboard-copy",{bubbles:!0}))}if(n)h(n).then(i);else if(e){const n="getRootNode"in Element.prototype?t.getRootNode():t.ownerDocument;if(!(n instanceof Document||"ShadowRoot"in window&&n instanceof ShadowRoot))return;const o=n.getElementById(e);o&&(r=o,r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement?h(r.value):r instanceof HTMLAnchorElement&&r.hasAttribute("href")?h(r.href):d(r)).then(i)}var r}function p(t){const e=t.currentTarget;e instanceof HTMLElement&&m(e)}function f(t){if(" "===t.key||"Enter"===t.key){const e=t.currentTarget;e instanceof HTMLElement&&(t.preventDefault(),m(e))}}function b(t){t.currentTarget.addEventListener("keydown",f)}function g(t){t.currentTarget.removeEventListener("keydown",f)}window.customElements.get("auto-complete")||(window.AutocompleteElement=l,window.customElements.define("auto-complete",l));class w extends HTMLElement{constructor(){super(),this.addEventListener("click",p),this.addEventListener("focus",b),this.addEventListener("blur",g)}connectedCallback(){this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.hasAttribute("role")||this.setAttribute("role","button")}get value(){return this.getAttribute("value")||""}set value(t){this.setAttribute("value",t)}}function v(t){""===t.style.display||"block"===t.style.display?t.style.display="none":t.style.display="block"}function y(t){const[e,n]=t.querySelectorAll(".octicon");e&&v(e),n&&v(n)}window.customElements.get("clipboard-copy")||(window.ClipboardCopyElement=w,window.customElements.define("clipboard-copy",w)),document.addEventListener("clipboard-copy",(function({target:t}){t instanceof HTMLElement&&(y(t),setTimeout(y,2e3,t))}));class E extends HTMLElement{constructor(){super(),this.addEventListener("keydown",(t=>{const e=t.target;if(!(e instanceof HTMLElement))return;if("tab"!==e.getAttribute("role")&&!e.closest('[role="tablist"]'))return;const n=Array.from(this.querySelectorAll('[role="tablist"] [role="tab"]')),i=n.indexOf(n.find((t=>t.matches('[aria-selected="true"]'))));if("ArrowRight"===t.code){let t=i+1;t>=n.length&&(t=0),A(this,t)}else if("ArrowLeft"===t.code){let t=i-1;t<0&&(t=n.length-1),A(this,t)}else"Home"===t.code?(A(this,0),t.preventDefault()):"End"===t.code&&(A(this,n.length-1),t.preventDefault())})),this.addEventListener("click",(t=>{const e=Array.from(this.querySelectorAll('[role="tablist"] [role="tab"]'));if(!(t.target instanceof Element))return;const n=t.target.closest('[role="tab"]');if(!n||!n.closest('[role="tablist"]'))return;A(this,e.indexOf(n))}))}connectedCallback(){for(const t of this.querySelectorAll('[role="tablist"] [role="tab"]'))t.hasAttribute("aria-selected")||t.setAttribute("aria-selected","false"),t.hasAttribute("tabindex")||("true"===t.getAttribute("aria-selected")?t.setAttribute("tabindex","0"):t.setAttribute("tabindex","-1"))}}function A(t,e){const n=t.querySelectorAll('[role="tablist"] [role="tab"]'),i=t.querySelectorAll('[role="tabpanel"]'),r=n[e],o=i[e];if(!!t.dispatchEvent(new CustomEvent("tab-container-change",{bubbles:!0,cancelable:!0,detail:{relatedTarget:o}}))){for(const t of n)t.setAttribute("aria-selected","false"),t.setAttribute("tabindex","-1");for(const t of i)t.hidden=!0,t.hasAttribute("tabindex")||t.hasAttribute("data-tab-container-no-tabstop")||t.setAttribute("tabindex","0");r.setAttribute("aria-selected","true"),r.setAttribute("tabindex","0"),r.focus(),o.hidden=!1,t.dispatchEvent(new CustomEvent("tab-container-changed",{bubbles:!0,detail:{relatedTarget:o}}))}}window.customElements.get("tab-container")||(window.TabContainerElement=E,window.customElements.define("tab-container",E));const M=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],T=["January","February","March","April","May","June","July","August","September","October","November","December"];function k(t){return"0".concat(t).slice(-2)}function L(t,e){const n=t.getDay(),i=t.getDate(),r=t.getMonth(),o=t.getFullYear(),s=t.getHours(),a=t.getMinutes(),c=t.getSeconds();return e.replace(/%([%aAbBcdeHIlmMpPSwyYZz])/g,(function(e){let u;switch(e[1]){case"%":return"%";case"a":return M[n].slice(0,3);case"A":return M[n];case"b":return T[r].slice(0,3);case"B":return T[r];case"c":return t.toString();case"d":return k(i);case"e":return String(i);case"H":return k(s);case"I":return k(L(t,"%l"));case"l":return String(0===s||12===s?12:(s+12)%12);case"m":return k(r+1);case"M":return k(a);case"p":return s>11?"PM":"AM";case"P":return s>11?"pm":"am";case"S":return k(c);case"w":return String(n);case"y":return k(o%100);case"Y":return String(o);case"Z":return u=t.toString().match(/\((\w+)\)$/),u?u[1]:"";case"z":return u=t.toString().match(/\w([+-]\d\d\d\d) /),u?u[1]:""}return""}))}function x(t){let e;return function(){if(e)return e;if("Intl"in window)try{return e=new Intl.DateTimeFormat(void 0,t),e}catch(t){if(!(t instanceof RangeError))throw t}}}let C=null;const S=x({day:"numeric",month:"short"});function D(){if(null!==C)return C;const t=S();if(t){const e=t.format(new Date(0));return C=!!e.match(/^\d/),C}return!1}let H=null;const I=x({day:"numeric",month:"short",year:"numeric"});function F(t){const e=t.closest("[lang]");return e instanceof HTMLElement&&e.lang?e.lang:"default"}const R=new WeakMap;class q extends HTMLElement{static get observedAttributes(){return["datetime","day","format","lang","hour","minute","month","second","title","weekday","year"]}connectedCallback(){const t=this.getFormattedTitle();t&&!this.hasAttribute("title")&&this.setAttribute("title",t);const e=this.getFormattedDate();e&&(this.textContent=e)}attributeChangedCallback(t,e,n){const i=this.getFormattedTitle();if("datetime"===t){const t=Date.parse(n);isNaN(t)?R.delete(this):R.set(this,new Date(t))}const r=this.getFormattedTitle(),o=this.getAttribute("title");"title"===t||!r||o&&o!==i||this.setAttribute("title",r);const s=this.getFormattedDate();s&&(this.textContent=s)}get date(){return R.get(this)}getFormattedTitle(){const t=this.date;if(!t)return;const e=K();if(e)return e.format(t);try{return t.toLocaleString()}catch(e){if(e instanceof RangeError)return t.toString();throw e}}getFormattedDate(){}}const K=x({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"}),U=new WeakMap;class P extends q{attributeChangedCallback(t,e,n){"hour"!==t&&"minute"!==t&&"second"!==t&&"time-zone-name"!==t||U.delete(this),super.attributeChangedCallback(t,e,n)}getFormattedDate(){const t=this.date;if(!t)return;const e=function(t,e){const n={weekday:{short:"%a",long:"%A"},day:{numeric:"%e","2-digit":"%d"},month:{short:"%b",long:"%B"},year:{numeric:"%Y","2-digit":"%y"}};let i=D()?"weekday day month year":"weekday month day, year";for(const e in n){const r=n[e][t.getAttribute(e)];i=i.replace(e,r||"")}return i=i.replace(/(\s,)|(,\s$)/,""),L(e,i).replace(/\s+/," ").trim()}(this,t)||"",n=function(t,e){const n={},i=t.getAttribute("hour");"numeric"!==i&&"2-digit"!==i||(n.hour=i);const r=t.getAttribute("minute");"numeric"!==r&&"2-digit"!==r||(n.minute=r);const o=t.getAttribute("second");"numeric"!==o&&"2-digit"!==o||(n.second=o);const s=t.getAttribute("time-zone-name");"short"!==s&&"long"!==s||(n.timeZoneName=s);if(0===Object.keys(n).length)return;let a=U.get(t);a||(a=x(n),U.set(t,a));const c=a();if(c)return c.format(e);return L(e,n.second?"%H:%M:%S":"%H:%M")}(this,t)||"";return"".concat(e," ").concat(n).trim()}}window.customElements.get("local-time")||(window.LocalTimeElement=P,window.customElements.define("local-time",P));class B{constructor(t,e){this.date=t,this.locale=e}toString(){const t=this.timeElapsed();if(t)return t;{const t=this.timeAhead();return t||"on ".concat(this.formatDate())}}timeElapsed(){const t=(new Date).getTime()-this.date.getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24);return t>=0&&r<30?this.timeAgoFromMs(t):null}timeAhead(){const t=this.date.getTime()-(new Date).getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24);return t>=0&&r<30?this.timeUntil():null}timeAgo(){const t=(new Date).getTime()-this.date.getTime();return this.timeAgoFromMs(t)}timeAgoFromMs(t){const e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),o=Math.round(r/30),s=Math.round(o/12);return t<0||e<10?W(this.locale,0,"second"):e<45?W(this.locale,-e,"second"):e<90||n<45?W(this.locale,-n,"minute"):n<90||i<24?W(this.locale,-i,"hour"):i<36||r<30?W(this.locale,-r,"day"):o<18?W(this.locale,-o,"month"):W(this.locale,-s,"year")}microTimeAgo(){const t=(new Date).getTime()-this.date.getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),o=Math.round(r/30),s=Math.round(o/12);return n<1?"1m":n<60?"".concat(n,"m"):i<24?"".concat(i,"h"):r<365?"".concat(r,"d"):"".concat(s,"y")}timeUntil(){const t=this.date.getTime()-(new Date).getTime();return this.timeUntilFromMs(t)}timeUntilFromMs(t){const e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),o=Math.round(r/30),s=Math.round(o/12);return o>=18||o>=12?W(this.locale,s,"year"):r>=45||r>=30?W(this.locale,o,"month"):i>=36||i>=24?W(this.locale,r,"day"):n>=90||n>=45?W(this.locale,i,"hour"):e>=90||e>=45?W(this.locale,n,"minute"):W(this.locale,e>=10?e:0,"second")}microTimeUntil(){const t=this.date.getTime()-(new Date).getTime(),e=Math.round(t/1e3),n=Math.round(e/60),i=Math.round(n/60),r=Math.round(i/24),o=Math.round(r/30),s=Math.round(o/12);return r>=365?"".concat(s,"y"):i>=24?"".concat(r,"d"):n>=60?"".concat(i,"h"):n>1?"".concat(n,"m"):"1m"}formatDate(){let t=D()?"%e %b":"%b %e";var e;return e=this.date,(new Date).getUTCFullYear()!==e.getUTCFullYear()&&(t+=function(){if(null!==H)return H;const t=I();if(t){const e=t.format(new Date(0));return H=!!e.match(/\d,/),H}return!0}()?", %Y":" %Y"),L(this.date,t)}formatTime(){const t=N();return t?t.format(this.date):L(this.date,"%l:%M%P")}}function W(t,e,n){const i=function(t,e){if("Intl"in window&&"RelativeTimeFormat"in window.Intl)try{return new Intl.RelativeTimeFormat(t,e)}catch(t){if(!(t instanceof RangeError))throw t}}(t,{numeric:"auto"});return i?i.format(e,n):function(t,e){if(0===t)switch(e){case"year":case"quarter":case"month":case"week":return"this ".concat(e);case"day":return"today";case"hour":case"minute":return"in 0 ".concat(e,"s");case"second":return"now"}else if(1===t)switch(e){case"year":case"quarter":case"month":case"week":return"next ".concat(e);case"day":return"tomorrow";case"hour":case"minute":case"second":return"in 1 ".concat(e)}else if(-1===t)switch(e){case"year":case"quarter":case"month":case"week":return"last ".concat(e);case"day":return"yesterday";case"hour":case"minute":case"second":return"1 ".concat(e," ago")}else if(t>1)switch(e){case"year":case"quarter":case"month":case"week":case"day":case"hour":case"minute":case"second":return"in ".concat(t," ").concat(e,"s")}else if(t<-1)switch(e){case"year":case"quarter":case"month":case"week":case"day":case"hour":case"minute":case"second":return"".concat(-t," ").concat(e,"s ago")}throw new RangeError("Invalid unit argument for format() '".concat(e,"'"))}(e,n)}const N=x({hour:"numeric",minute:"2-digit"});class O extends q{getFormattedDate(){const t=this.date;if(t)return new B(t,F(this)).toString()}connectedCallback(){Y.push(this),$||(z(),$=setInterval(z,6e4)),super.connectedCallback()}disconnectedCallback(){const t=Y.indexOf(this);-1!==t&&Y.splice(t,1),Y.length||$&&(clearInterval($),$=null)}}const Y=[];let $;function z(){let t,e,n;for(e=0,n=Y.length;e<n;e++)t=Y[e],t.textContent=t.getFormattedDate()||""}window.customElements.get("relative-time")||(window.RelativeTimeElement=O,window.customElements.define("relative-time",O));class Z extends O{getFormattedDate(){const t=this.getAttribute("format"),e=this.date;if(e)return"micro"===t?new B(e,F(this)).microTimeAgo():new B(e,F(this)).timeAgo()}}window.customElements.get("time-ago")||(window.TimeAgoElement=Z,window.customElements.define("time-ago",Z));class j extends O{getFormattedDate(){const t=this.getAttribute("format"),e=this.date;if(e)return"micro"===t?new B(e,F(this)).microTimeUntil():new B(e,F(this)).timeUntil()}}window.customElements.get("time-until")||(window.TimeUntilElement=j,window.customElements.define("time-until",j));
//# sourceMappingURL=primer_view_components.js.map
import './auto_complete/auto_complete';
import './clipboard_copy_component';
import './tab_container_component';
import './time_ago_component';
import './auto_complete/auto_complete';
import './clipboard_copy_component';
import './tab_container_component';
import './time_ago_component';

@@ -5,2 +5,28 @@ # CHANGELOG

## 0.0.38
* Extract `BaseButton` component.
*Manuel Puyol*
* Add default `aria-label` of "Close" to `CloseButton` component.
*Kate Higa*
* Set button variants in the `ButtonGroup` parent.
*Manuel Puyol*
* **Breaking change**: Rename `ButtonGroupComponent` to `ButtonGroup` and promote it to beta.
*Manuel Puyol*
* **Breaking change**: Do not provide default for `Heading` and improve documentation.
*Kate Higa*
* **Breaking change**: Don't allow `StateComponent` to be a link.
*Kate Higa*
## 0.0.37

@@ -7,0 +33,0 @@

{
"name": "@primer/view-components",
"version": "0.0.37",
"version": "0.0.38",
"description": "ViewComponents for the Primer Design System",

@@ -33,2 +33,3 @@ "main": "app/assets/javascripts/primer_view_components.js",

"@github/auto-complete-element": "^3.0.2",
"@github/clipboard-copy-element": "^1.1.2",
"@github/tab-container-element": "^3.1.0",

@@ -35,0 +36,0 @@ "@github/time-elements": "^3.1.1"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc