@smileid/web-components 11.0.2 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/dist/components/smart-camera-web/src/README.md +0 -1
- package/dist/esm/{DocumentCaptureScreens-CRx5ymqY.js → DocumentCaptureScreens-DHAfE8VG.js} +191 -185
- package/dist/esm/DocumentCaptureScreens-DHAfE8VG.js.map +1 -0
- package/dist/esm/{EndUserConsent-D4fd1ovG.js → EndUserConsent-DE6OBSGG.js} +65 -63
- package/dist/esm/EndUserConsent-DE6OBSGG.js.map +1 -0
- package/dist/esm/{Navigation-CTjK6tLU.js → Navigation-kjll5SgE.js} +17 -9
- package/dist/esm/Navigation-kjll5SgE.js.map +1 -0
- package/dist/esm/{SelfieCaptureScreens-DuQjKt_K.js → SelfieCaptureScreens-DaREKFi4.js} +3087 -3177
- package/dist/esm/SelfieCaptureScreens-DaREKFi4.js.map +1 -0
- package/dist/esm/{TotpConsent-CQU5jQi4.js → TotpConsent-DsMJhXD8.js} +13 -9
- package/dist/esm/TotpConsent-DsMJhXD8.js.map +1 -0
- package/dist/esm/combobox.js +20 -19
- package/dist/esm/combobox.js.map +1 -1
- package/dist/esm/document.js +1 -1
- package/dist/esm/end-user-consent.js +1 -1
- package/dist/esm/index-LJce6hoU.js +1360 -0
- package/dist/esm/index-LJce6hoU.js.map +1 -0
- package/dist/esm/localisation.js +21 -0
- package/dist/esm/localisation.js.map +1 -0
- package/dist/esm/main.js +34 -17
- package/dist/esm/main.js.map +1 -1
- package/dist/esm/navigation.js +1 -1
- package/dist/esm/{package-C_cKNrUu.js → package-BoRHLVSv.js} +25 -40
- package/dist/esm/package-BoRHLVSv.js.map +1 -0
- package/dist/esm/selfie.js +1 -1
- package/dist/esm/smart-camera-web.js +22 -18
- package/dist/esm/smart-camera-web.js.map +1 -1
- package/dist/esm/totp-consent.js +1 -1
- package/dist/smart-camera-web.js +136 -177
- package/dist/smart-camera-web.js.map +1 -1
- package/dist/src/components/combobox/src/index.js +424 -1
- package/dist/src/components/document/src/index.js +1422 -1
- package/dist/src/components/end-user-consent/src/index.js +1573 -1
- package/dist/src/components/selfie/src/index.js +1220 -1
- package/dist/src/components/signature-pad/src/index.js +787 -1
- package/dist/src/components/smart-camera-web/src/SmartCameraWeb.js +2753 -1
- package/dist/src/components/totp-consent/src/index.js +1292 -1
- package/dist/types/combobox.d.ts +2 -2
- package/dist/types/document.d.ts +2 -2
- package/dist/types/end-user-consent.d.ts +2 -2
- package/dist/types/locale.d.ts +19 -0
- package/dist/types/localisation.d.ts +21 -0
- package/dist/types/main.d.ts +35 -26
- package/dist/types/navigation.d.ts +2 -2
- package/dist/types/selfie.d.ts +2 -2
- package/dist/types/signature-pad.d.ts +2 -2
- package/dist/types/smart-camera-web.d.ts +2 -2
- package/dist/types/totp-consent.d.ts +2 -2
- package/lib/components/camera-permission/CameraPermission.js +8 -3
- package/lib/components/combobox/src/Combobox.js +4 -2
- package/lib/components/document/src/DocumentCaptureScreens.js +4 -3
- package/lib/components/document/src/DocumentCaptureScreens.stories.js +37 -13
- package/lib/components/document/src/document-capture/DocumentCapture.js +20 -14
- package/lib/components/document/src/document-capture/DocumentCapture.stories.js +11 -2
- package/lib/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +16 -11
- package/lib/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +14 -5
- package/lib/components/document/src/document-capture-review/DocumentCaptureReview.js +11 -7
- package/lib/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +14 -5
- package/lib/components/end-user-consent/src/EndUserConsent.js +30 -29
- package/lib/components/end-user-consent/src/EndUserConsent.stories.js +12 -2
- package/lib/components/navigation/src/Navigation.js +15 -2
- package/lib/components/navigation/src/Navigation.stories.js +20 -4
- package/lib/components/selfie/src/SelfieCaptureScreens.js +3 -7
- package/lib/components/selfie/src/SelfieCaptureScreens.stories.js +16 -4
- package/lib/components/selfie/src/selfie-capture/SelfieCapture.js +23 -16
- package/lib/components/selfie/src/selfie-capture/SelfieCapture.stories.js +19 -7
- package/lib/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +16 -11
- package/lib/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +14 -5
- package/lib/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +10 -5
- package/lib/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +14 -5
- package/lib/components/selfie/src/selfie-capture-wrapper/SelfieCaptureWrapper.tsx +2 -2
- package/lib/components/selfie/src/smartselfie-capture/SmartSelfieCapture.stories.js +47 -0
- package/lib/components/selfie/src/smartselfie-capture/SmartSelfieCapture.tsx +2 -2
- package/lib/components/selfie/src/smartselfie-capture/components/CaptureControls.tsx +5 -2
- package/lib/components/selfie/src/smartselfie-capture/hooks/useCamera.ts +4 -4
- package/lib/components/selfie/src/smartselfie-capture/hooks/useFaceCapture.ts +6 -5
- package/lib/components/selfie/src/smartselfie-capture/utils/alertMessages.ts +11 -9
- package/lib/components/selfie/src/smartselfie-capture/utils/imageCapture.ts +3 -1
- package/lib/components/signature-pad/package-lock.json +11 -9
- package/lib/components/signature-pad/package.json +1 -1
- package/lib/components/totp-consent/src/TotpConsent.js +8 -3
- package/lib/domain/camera/src/SmartCamera.js +7 -22
- package/lib/domain/constants/src/Constants.js +28 -0
- package/lib/domain/file-upload/src/SmartFileUpload.js +9 -10
- package/lib/domain/localisation/index.js +456 -0
- package/package.json +13 -7
- package/dist/esm/DocumentCaptureScreens-CRx5ymqY.js.map +0 -1
- package/dist/esm/EndUserConsent-D4fd1ovG.js.map +0 -1
- package/dist/esm/Navigation-CTjK6tLU.js.map +0 -1
- package/dist/esm/SelfieCaptureScreens-DuQjKt_K.js.map +0 -1
- package/dist/esm/TotpConsent-CQU5jQi4.js.map +0 -1
- package/dist/esm/package-C_cKNrUu.js.map +0 -1
|
@@ -1,2 +1,425 @@
|
|
|
1
|
-
(()=>{function b(o){let t=[...Array(30)].map(()=>Math.random().toString(36)[3]).join("");return"".concat(o,"-").concat(t)}function f(o){let t=o.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}function x(o){return o&&o.clientHeight<o.scrollHeight}function E(o,t){let{offsetHeight:e,offsetTop:i}=o,{offsetHeight:s,scrollTop:n}=t,r=i<n,c=i+e>n+s;r?t.scrollTo(0,i):c&&t.scrollTo(0,i-s+e)}var a=class extends HTMLElement{constructor(){super(),this.handleRoaming=this.handleRoaming.bind(this)}connectedCallback(){this.trigger=this.querySelector("smileid-combobox-trigger"),document.addEventListener("click",this.handleRoaming),this.addEventListener("focusout",this.handleRoaming),this.addEventListener("blur",this.handleRoaming)}disconnectedCallback(){document.removeEventListener("click",this.handleRoaming),this.removeEventListener("focusout",this.handleRoaming),this.removeEventListener("blur",this.handleRoaming)}handleRoaming(t){let e=t.relatedTarget||t.target;this.contains(e)||this.trigger.getAttribute("expanded")==="true"&&this.trigger.setAttribute("expanded","false")}},l=class extends HTMLElement{constructor(){super(),this.handleKeyUp=this.handleKeyUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleSelection=this.handleSelection.bind(this),this.toggleExpansionState=this.toggleExpansionState.bind(this)}get type(){return this.getAttribute("type")||"text"}get label(){return this.getAttribute("label")||""}get value(){return this.getAttribute("value")||""}get disabled(){return this.hasAttribute("disabled")}connectedCallback(){if(!this.label)throw new Error("<combobox-trigger>: a label attribute is required");this.innerHTML="".concat(this.type==="text"?"\n <div>\n <input ".concat(this.value?'value="'.concat(this.value,'" '):"").concat(this.disabled?" disabled ":"",'type="text" placeholder="').concat(this.label,'" />\n <button ').concat(this.disabled?"disabled ":"","tabindex='-1' type='button'>\n <span class=\"visually-hidden\">Toggle</span>\n </button>\n </div>\n "):"<button ".concat(this.disabled?"disabled ":"",'type="button">').concat(this.value||this.label,"</button>")),this.setAttribute("expanded",!1),this.inputTrigger=this.querySelector("input"),this.buttonTrigger=this.querySelector("button"),this.buttonTrigger.setAttribute("aria-expanded",!1),this.buttonTrigger.setAttribute("role","combobox"),this.buttonTrigger.addEventListener("keydown",this.handleKeyDown),this.buttonTrigger.addEventListener("click",this.toggleExpansionState),this.inputTrigger&&(this.inputTrigger.setAttribute("aria-expanded",!1),this.inputTrigger.setAttribute("role","combobox"),this.inputTrigger.addEventListener("keydown",this.handleKeyDown),this.inputTrigger.addEventListener("keyup",this.handleKeyUp),this.inputTrigger.addEventListener("change",t=>t.stopPropagation())),this.listbox=this.parentElement.querySelector("smileid-combobox-listbox"),this.options=Array.from(this.parentElement.querySelectorAll("smileid-combobox-option")),this.options.forEach(t=>{t.addEventListener("combobox.option.select",this.handleSelection)})}disconnectedCallback(){this.buttonTrigger.removeEventListener("keydown",this.handleKeyDown),this.buttonTrigger.removeEventListener("click",this.toggleExpansionState),this.inputTrigger&&(this.inputTrigger.removeEventListener("keydown",this.handleKeyDown),this.inputTrigger.removeEventListener("keyup",this.handleKeyUp),this.inputTrigger.removeEventListener("change",t=>t.stopPropagation())),this.options&&this.options.forEach(t=>{t.removeEventListener("combobox.option.select",this.handleSelection)})}handleKeyDown(t){if(t.ctrlKey||t.shiftKey)return;let{key:e}=t;switch(e){case"Enter":case"Space":case" ":if(this.getAttribute("expanded")==="true")if(this.inputTrigger&&(e==="Space"||e===" "))this.resetListbox();else{t.preventDefault();let i=this.buttonTrigger.getAttribute("aria-activedescendant");i&&document.getElementById(i).click()}else t.preventDefault(),this.toggleExpansionState();break;case"Esc":case"Escape":t.preventDefault(),this.getAttribute("expanded")==="true"&&this.toggleExpansionState();break;case"Down":case"ArrowDown":t.preventDefault(),this.getAttribute("expanded")!=="true"?(this.toggleExpansionState(),this.focusListbox("First")):this.focusListbox("Down");break;case"Up":case"ArrowUp":t.preventDefault(),this.getAttribute("expanded")!=="true"?(this.toggleExpansionState(),this.focusListbox("Last")):this.focusListbox("Up");break;case"Left":case"ArrowLeft":case"Right":case"ArrowRight":case"Home":case"End":this.resetListbox();break;case"Tab":break;default:break}}handleKeyUp(t){let{key:e}=t,i=s=>s.length===1&&s.match(/\S| /);(t.key==="Escape"||t.key==="Esc")&&(t.preventDefault(),this.getAttribute("expanded")==="true"?this.toggleExpansionState():this.inputTrigger&&(this.inputTrigger.value="",this.listbox.dispatchEvent(new CustomEvent("combobox.listbox.filter",{detail:""})))),(i(e)||e==="Backspace")&&(this.resetListbox(),this.filterListbox(t.target.value))}toggleExpansionState(){let t=this.getAttribute("expanded")==="true";this.setAttribute("expanded",!t),this.buttonTrigger.setAttribute("aria-expanded",!t),this.inputTrigger&&this.inputTrigger.setAttribute("aria-expanded",!t)}handleSelection(t){this.inputTrigger?this.inputTrigger.value=t.detail.label:this.buttonTrigger.textContent=t.detail.label,this.toggleExpansionState(),this.parentElement.dispatchEvent(new CustomEvent("combobox.change",{detail:{value:t.detail.value}}))}filterListbox(t){this.getAttribute("expanded")!=="true"&&this.toggleExpansionState(),this.listbox.dispatchEvent(new CustomEvent("combobox.listbox.filter",{detail:t}))}focusListbox(t){this.resetListbox(),this.listbox.dispatchEvent(new CustomEvent("combobox.listbox.focus",{detail:{direction:t}}))}resetListbox(){this.listbox.dispatchEvent(new CustomEvent("combobox.listbox.reset"))}},h=class extends HTMLElement{constructor(){super(),this.handleFilter=this.handleFilter.bind(this),this.handleFocus=this.handleFocus.bind(this),this.handleReset=this.handleReset.bind(this),this.handleOptionSelection=this.handleOptionSelection.bind(this)}get emptyLabel(){return this.getAttribute("empty-label")}get emptyState(){return"\n <p id='empty-state' style=\"text-align: center;\">\n ".concat(this.emptyLabel||"No items","\n </p>\n ")}connectedCallback(){this.setAttribute("role","listbox"),this.setAttribute("id",b("listbox")),this.addEventListener("combobox.listbox.filter",this.handleFilter),this.addEventListener("combobox.listbox.focus",this.handleFocus),this.addEventListener("combobox.listbox.reset",this.handleReset),this.triggers=Array.from(this.parentElement.querySelectorAll("smileid-combobox-trigger input, smileid-combobox-trigger button")),this.triggers.forEach(t=>t.setAttribute("aria-controls",this.getAttribute("id"))),this.optionNodes=Array.from(this.querySelectorAll("smileid-combobox-option")),this.selectedNode=this.optionNodes.find(t=>!t.hasAttribute("hidden")&&t.hasAttribute("aria-selected"))||this.optionNodes.filter(t=>!t.hasAttribute("hidden"))[0],this.selectedNode.setAttribute("tabindex","0"),this.optionNodes.forEach(t=>{t.addEventListener("combobox.option.select",this.handleOptionSelection)}),this.optionNodes.length===0&&(this.innerHTML=this.emptyState)}disconnectedCallback(){this.removeEventListener("combobox.listbox.filter",this.handleFilter),this.removeEventListener("combobox.listbox.focus",this.handleFocus),this.removeEventListener("combobox.listbox.reset",this.handleReset),this.optionNodes.forEach(t=>{t.removeEventListener("combobox.option.select",this.handleOptionSelection)})}static get observedAttributes(){return["search-term"]}attributeChangedCallback(t,e,i){switch(t){case"search-term":e&&!i?this.optionNodes.forEach(s=>{s.removeAttribute("hidden")}):i&&this.filterNodes(i);break;default:break}}filterNodes(t){this.optionNodes.forEach(s=>{let n=s.getAttribute("value").toLowerCase(),r=s.getAttribute("label").toLowerCase();n.includes(t.toLowerCase())||r.includes(t.toLowerCase())?s.removeAttribute("hidden"):s.setAttribute("hidden",!0)});let e=this.optionNodes.find(s=>!s.hasAttribute("hidden")),i=this.querySelector("#empty-state");!e&&!i?this.insertAdjacentHTML("afterbegin",this.emptyState):e&&i&&this.removeChild(i)}handleFilter(t){let e=t.detail;this.setAttribute("search-term",e)}handleFocus(t){this.setSelected(t.detail.direction)}handleReset(){this.optionNodes.forEach(t=>t.setAttribute("tabindex","-1"))}handleOptionSelection(t){this.triggers.filter(i=>i.tagName==="INPUT")[0]&&this.setAttribute("search-term",t.detail.label)}setSelected(t){let e=this.optionNodes.filter(r=>!r.hasAttribute("hidden"));this.selectedNode.setAttribute("tabindex","0");let i=e.findIndex(r=>r===this.selectedNode),s=e.length-1,n;switch(t){case"First":n=0;break;case"Last":n=s;break;case"Up":i===0?n=s:n=i-1;break;default:i===s?n=0:n=i+1;break}i!==n&&this.swapSelected(this.selectedNode,e[n])}swapSelected(t,e){t.setAttribute("tabindex","-1"),e.setAttribute("tabindex","0"),this.selectedNode=e,x(this)&&E(this.selectedNode,this),f(e)||e.scrollIntoView({behavior:"smooth",block:"nearest"}),this.triggers.forEach(i=>i.setAttribute("aria-activedescendant",e.id))}},d=class extends HTMLElement{connectedCallback(){this.setAttribute("role","option"),this.setAttribute("tabindex","-1"),this.setAttribute("id",b("option")),this.options=Array.from(this.parentElement.querySelectorAll("smileid-combobox-option")),this.addEventListener("click",this.select)}disconnectedCallback(){this.removeEventListener("click",this.select)}get value(){return this.getAttribute("value")}get label(){return this.getAttribute("label")}select(){let t=this.options.find(e=>e.getAttribute("aria-selected"));t&&t.removeAttribute("aria-selected"),this.setAttribute("aria-selected",!0),this.dispatchEvent(new CustomEvent("combobox.option.select",{detail:{id:this.getAttribute("id"),label:this.label,value:this.value}}))}},u=a,g=l,p=h,m=d;"customElements"in window&&!window.customElements.get("smileid-combobox")&&(window.customElements.define("smileid-combobox",u),window.customElements.define("smileid-combobox-trigger",g),window.customElements.define("smileid-combobox-listbox",p),window.customElements.define("smileid-combobox-option",m));})();
|
|
1
|
+
(() => {
|
|
2
|
+
function b(o) {
|
|
3
|
+
let t = [...Array(30)].map(() => Math.random().toString(36)[3]).join('');
|
|
4
|
+
return ''.concat(o, '-').concat(t);
|
|
5
|
+
}
|
|
6
|
+
function f(o) {
|
|
7
|
+
let t = o.getBoundingClientRect();
|
|
8
|
+
return (
|
|
9
|
+
t.top >= 0 &&
|
|
10
|
+
t.left >= 0 &&
|
|
11
|
+
t.bottom <=
|
|
12
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
13
|
+
t.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function x(o) {
|
|
17
|
+
return o && o.clientHeight < o.scrollHeight;
|
|
18
|
+
}
|
|
19
|
+
function E(o, t) {
|
|
20
|
+
let { offsetHeight: e, offsetTop: i } = o,
|
|
21
|
+
{ offsetHeight: s, scrollTop: n } = t,
|
|
22
|
+
r = i < n,
|
|
23
|
+
c = i + e > n + s;
|
|
24
|
+
r ? t.scrollTo(0, i) : c && t.scrollTo(0, i - s + e);
|
|
25
|
+
}
|
|
26
|
+
var a = class extends HTMLElement {
|
|
27
|
+
constructor() {
|
|
28
|
+
(super(), (this.handleRoaming = this.handleRoaming.bind(this)));
|
|
29
|
+
}
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
((this.trigger = this.querySelector('smileid-combobox-trigger')),
|
|
32
|
+
document.addEventListener('click', this.handleRoaming),
|
|
33
|
+
this.addEventListener('focusout', this.handleRoaming),
|
|
34
|
+
this.addEventListener('blur', this.handleRoaming));
|
|
35
|
+
}
|
|
36
|
+
disconnectedCallback() {
|
|
37
|
+
(document.removeEventListener('click', this.handleRoaming),
|
|
38
|
+
this.removeEventListener('focusout', this.handleRoaming),
|
|
39
|
+
this.removeEventListener('blur', this.handleRoaming));
|
|
40
|
+
}
|
|
41
|
+
handleRoaming(t) {
|
|
42
|
+
let e = t.relatedTarget || t.target;
|
|
43
|
+
this.contains(e) ||
|
|
44
|
+
(this.trigger.getAttribute('expanded') === 'true' &&
|
|
45
|
+
this.trigger.setAttribute('expanded', 'false'));
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
l = class extends HTMLElement {
|
|
49
|
+
constructor() {
|
|
50
|
+
(super(),
|
|
51
|
+
(this.handleKeyUp = this.handleKeyUp.bind(this)),
|
|
52
|
+
(this.handleKeyDown = this.handleKeyDown.bind(this)),
|
|
53
|
+
(this.handleSelection = this.handleSelection.bind(this)),
|
|
54
|
+
(this.toggleExpansionState = this.toggleExpansionState.bind(this)));
|
|
55
|
+
}
|
|
56
|
+
get type() {
|
|
57
|
+
return this.getAttribute('type') || 'text';
|
|
58
|
+
}
|
|
59
|
+
get label() {
|
|
60
|
+
return this.getAttribute('label') || '';
|
|
61
|
+
}
|
|
62
|
+
get value() {
|
|
63
|
+
return this.getAttribute('value') || '';
|
|
64
|
+
}
|
|
65
|
+
get disabled() {
|
|
66
|
+
return this.hasAttribute('disabled');
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
if (!this.label)
|
|
70
|
+
throw new Error('<combobox-trigger>: a label attribute is required');
|
|
71
|
+
((this.innerHTML = ''.concat(
|
|
72
|
+
this.type === 'text'
|
|
73
|
+
? '\n <div>\n <input '
|
|
74
|
+
.concat(this.value ? 'value="'.concat(this.value, '" ') : '')
|
|
75
|
+
.concat(
|
|
76
|
+
this.disabled ? ' disabled ' : '',
|
|
77
|
+
'type="text" placeholder="',
|
|
78
|
+
)
|
|
79
|
+
.concat(this.label, '" />\n <button ')
|
|
80
|
+
.concat(
|
|
81
|
+
this.disabled ? 'disabled ' : '',
|
|
82
|
+
"tabindex='-1' type='button'>\n <span class=\"visually-hidden\">Toggle</span>\n </button>\n </div>\n ",
|
|
83
|
+
)
|
|
84
|
+
: '<button '
|
|
85
|
+
.concat(this.disabled ? 'disabled ' : '', 'type="button">')
|
|
86
|
+
.concat(this.value || this.label, '</button>'),
|
|
87
|
+
)),
|
|
88
|
+
this.setAttribute('expanded', !1),
|
|
89
|
+
(this.inputTrigger = this.querySelector('input')),
|
|
90
|
+
(this.buttonTrigger = this.querySelector('button')),
|
|
91
|
+
this.buttonTrigger.setAttribute('aria-expanded', !1),
|
|
92
|
+
this.buttonTrigger.setAttribute('role', 'combobox'),
|
|
93
|
+
this.buttonTrigger.addEventListener('keydown', this.handleKeyDown),
|
|
94
|
+
this.buttonTrigger.addEventListener(
|
|
95
|
+
'click',
|
|
96
|
+
this.toggleExpansionState,
|
|
97
|
+
),
|
|
98
|
+
this.inputTrigger &&
|
|
99
|
+
(this.inputTrigger.setAttribute('aria-expanded', !1),
|
|
100
|
+
this.inputTrigger.setAttribute('role', 'combobox'),
|
|
101
|
+
this.inputTrigger.addEventListener('keydown', this.handleKeyDown),
|
|
102
|
+
this.inputTrigger.addEventListener('keyup', this.handleKeyUp),
|
|
103
|
+
this.inputTrigger.addEventListener('change', (t) =>
|
|
104
|
+
t.stopPropagation(),
|
|
105
|
+
)),
|
|
106
|
+
(this.listbox = this.parentElement.querySelector(
|
|
107
|
+
'smileid-combobox-listbox',
|
|
108
|
+
)),
|
|
109
|
+
(this.options = Array.from(
|
|
110
|
+
this.parentElement.querySelectorAll('smileid-combobox-option'),
|
|
111
|
+
)),
|
|
112
|
+
this.options.forEach((t) => {
|
|
113
|
+
t.addEventListener('combobox.option.select', this.handleSelection);
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
disconnectedCallback() {
|
|
117
|
+
(this.buttonTrigger.removeEventListener('keydown', this.handleKeyDown),
|
|
118
|
+
this.buttonTrigger.removeEventListener(
|
|
119
|
+
'click',
|
|
120
|
+
this.toggleExpansionState,
|
|
121
|
+
),
|
|
122
|
+
this.inputTrigger &&
|
|
123
|
+
(this.inputTrigger.removeEventListener(
|
|
124
|
+
'keydown',
|
|
125
|
+
this.handleKeyDown,
|
|
126
|
+
),
|
|
127
|
+
this.inputTrigger.removeEventListener('keyup', this.handleKeyUp),
|
|
128
|
+
this.inputTrigger.removeEventListener('change', (t) =>
|
|
129
|
+
t.stopPropagation(),
|
|
130
|
+
)),
|
|
131
|
+
this.options &&
|
|
132
|
+
this.options.forEach((t) => {
|
|
133
|
+
t.removeEventListener(
|
|
134
|
+
'combobox.option.select',
|
|
135
|
+
this.handleSelection,
|
|
136
|
+
);
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
handleKeyDown(t) {
|
|
140
|
+
if (t.ctrlKey || t.shiftKey) return;
|
|
141
|
+
let { key: e } = t;
|
|
142
|
+
switch (e) {
|
|
143
|
+
case 'Enter':
|
|
144
|
+
case 'Space':
|
|
145
|
+
case ' ':
|
|
146
|
+
if (this.getAttribute('expanded') === 'true')
|
|
147
|
+
if (this.inputTrigger && (e === 'Space' || e === ' '))
|
|
148
|
+
this.resetListbox();
|
|
149
|
+
else {
|
|
150
|
+
t.preventDefault();
|
|
151
|
+
let i = this.buttonTrigger.getAttribute(
|
|
152
|
+
'aria-activedescendant',
|
|
153
|
+
);
|
|
154
|
+
i && document.getElementById(i).click();
|
|
155
|
+
}
|
|
156
|
+
else (t.preventDefault(), this.toggleExpansionState());
|
|
157
|
+
break;
|
|
158
|
+
case 'Esc':
|
|
159
|
+
case 'Escape':
|
|
160
|
+
(t.preventDefault(),
|
|
161
|
+
this.getAttribute('expanded') === 'true' &&
|
|
162
|
+
this.toggleExpansionState());
|
|
163
|
+
break;
|
|
164
|
+
case 'Down':
|
|
165
|
+
case 'ArrowDown':
|
|
166
|
+
(t.preventDefault(),
|
|
167
|
+
this.getAttribute('expanded') !== 'true'
|
|
168
|
+
? (this.toggleExpansionState(), this.focusListbox('First'))
|
|
169
|
+
: this.focusListbox('Down'));
|
|
170
|
+
break;
|
|
171
|
+
case 'Up':
|
|
172
|
+
case 'ArrowUp':
|
|
173
|
+
(t.preventDefault(),
|
|
174
|
+
this.getAttribute('expanded') !== 'true'
|
|
175
|
+
? (this.toggleExpansionState(), this.focusListbox('Last'))
|
|
176
|
+
: this.focusListbox('Up'));
|
|
177
|
+
break;
|
|
178
|
+
case 'Left':
|
|
179
|
+
case 'ArrowLeft':
|
|
180
|
+
case 'Right':
|
|
181
|
+
case 'ArrowRight':
|
|
182
|
+
case 'Home':
|
|
183
|
+
case 'End':
|
|
184
|
+
this.resetListbox();
|
|
185
|
+
break;
|
|
186
|
+
case 'Tab':
|
|
187
|
+
break;
|
|
188
|
+
default:
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
handleKeyUp(t) {
|
|
193
|
+
let { key: e } = t,
|
|
194
|
+
i = (s) => s.length === 1 && s.match(/\S| /);
|
|
195
|
+
((t.key === 'Escape' || t.key === 'Esc') &&
|
|
196
|
+
(t.preventDefault(),
|
|
197
|
+
this.getAttribute('expanded') === 'true'
|
|
198
|
+
? this.toggleExpansionState()
|
|
199
|
+
: this.inputTrigger &&
|
|
200
|
+
((this.inputTrigger.value = ''),
|
|
201
|
+
this.listbox.dispatchEvent(
|
|
202
|
+
new CustomEvent('combobox.listbox.filter', { detail: '' }),
|
|
203
|
+
))),
|
|
204
|
+
(i(e) || e === 'Backspace') &&
|
|
205
|
+
(this.resetListbox(), this.filterListbox(t.target.value)));
|
|
206
|
+
}
|
|
207
|
+
toggleExpansionState() {
|
|
208
|
+
let t = this.getAttribute('expanded') === 'true';
|
|
209
|
+
(this.setAttribute('expanded', !t),
|
|
210
|
+
this.buttonTrigger.setAttribute('aria-expanded', !t),
|
|
211
|
+
this.inputTrigger &&
|
|
212
|
+
this.inputTrigger.setAttribute('aria-expanded', !t));
|
|
213
|
+
}
|
|
214
|
+
handleSelection(t) {
|
|
215
|
+
(this.inputTrigger
|
|
216
|
+
? (this.inputTrigger.value = t.detail.label)
|
|
217
|
+
: (this.buttonTrigger.textContent = t.detail.label),
|
|
218
|
+
this.toggleExpansionState(),
|
|
219
|
+
this.parentElement.dispatchEvent(
|
|
220
|
+
new CustomEvent('combobox.change', {
|
|
221
|
+
detail: { value: t.detail.value },
|
|
222
|
+
}),
|
|
223
|
+
));
|
|
224
|
+
}
|
|
225
|
+
filterListbox(t) {
|
|
226
|
+
(this.getAttribute('expanded') !== 'true' &&
|
|
227
|
+
this.toggleExpansionState(),
|
|
228
|
+
this.listbox.dispatchEvent(
|
|
229
|
+
new CustomEvent('combobox.listbox.filter', { detail: t }),
|
|
230
|
+
));
|
|
231
|
+
}
|
|
232
|
+
focusListbox(t) {
|
|
233
|
+
(this.resetListbox(),
|
|
234
|
+
this.listbox.dispatchEvent(
|
|
235
|
+
new CustomEvent('combobox.listbox.focus', {
|
|
236
|
+
detail: { direction: t },
|
|
237
|
+
}),
|
|
238
|
+
));
|
|
239
|
+
}
|
|
240
|
+
resetListbox() {
|
|
241
|
+
this.listbox.dispatchEvent(new CustomEvent('combobox.listbox.reset'));
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
h = class extends HTMLElement {
|
|
245
|
+
constructor() {
|
|
246
|
+
(super(),
|
|
247
|
+
(this.handleFilter = this.handleFilter.bind(this)),
|
|
248
|
+
(this.handleFocus = this.handleFocus.bind(this)),
|
|
249
|
+
(this.handleReset = this.handleReset.bind(this)),
|
|
250
|
+
(this.handleOptionSelection = this.handleOptionSelection.bind(this)));
|
|
251
|
+
}
|
|
252
|
+
get emptyLabel() {
|
|
253
|
+
return this.getAttribute('empty-label');
|
|
254
|
+
}
|
|
255
|
+
get emptyState() {
|
|
256
|
+
return '\n <p id=\'empty-state\' style="text-align: center;">\n '.concat(
|
|
257
|
+
this.emptyLabel || 'No items',
|
|
258
|
+
'\n </p>\n ',
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
connectedCallback() {
|
|
262
|
+
(this.setAttribute('role', 'listbox'),
|
|
263
|
+
this.setAttribute('id', b('listbox')),
|
|
264
|
+
this.addEventListener('combobox.listbox.filter', this.handleFilter),
|
|
265
|
+
this.addEventListener('combobox.listbox.focus', this.handleFocus),
|
|
266
|
+
this.addEventListener('combobox.listbox.reset', this.handleReset),
|
|
267
|
+
(this.triggers = Array.from(
|
|
268
|
+
this.parentElement.querySelectorAll(
|
|
269
|
+
'smileid-combobox-trigger input, smileid-combobox-trigger button',
|
|
270
|
+
),
|
|
271
|
+
)),
|
|
272
|
+
this.triggers.forEach((t) =>
|
|
273
|
+
t.setAttribute('aria-controls', this.getAttribute('id')),
|
|
274
|
+
),
|
|
275
|
+
(this.optionNodes = Array.from(
|
|
276
|
+
this.querySelectorAll('smileid-combobox-option'),
|
|
277
|
+
)),
|
|
278
|
+
(this.selectedNode =
|
|
279
|
+
this.optionNodes.find(
|
|
280
|
+
(t) =>
|
|
281
|
+
!t.hasAttribute('hidden') && t.hasAttribute('aria-selected'),
|
|
282
|
+
) || this.optionNodes.filter((t) => !t.hasAttribute('hidden'))[0]),
|
|
283
|
+
this.selectedNode.setAttribute('tabindex', '0'),
|
|
284
|
+
this.optionNodes.forEach((t) => {
|
|
285
|
+
t.addEventListener(
|
|
286
|
+
'combobox.option.select',
|
|
287
|
+
this.handleOptionSelection,
|
|
288
|
+
);
|
|
289
|
+
}),
|
|
290
|
+
this.optionNodes.length === 0 && (this.innerHTML = this.emptyState));
|
|
291
|
+
}
|
|
292
|
+
disconnectedCallback() {
|
|
293
|
+
(this.removeEventListener('combobox.listbox.filter', this.handleFilter),
|
|
294
|
+
this.removeEventListener('combobox.listbox.focus', this.handleFocus),
|
|
295
|
+
this.removeEventListener('combobox.listbox.reset', this.handleReset),
|
|
296
|
+
this.optionNodes.forEach((t) => {
|
|
297
|
+
t.removeEventListener(
|
|
298
|
+
'combobox.option.select',
|
|
299
|
+
this.handleOptionSelection,
|
|
300
|
+
);
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
|
+
static get observedAttributes() {
|
|
304
|
+
return ['search-term'];
|
|
305
|
+
}
|
|
306
|
+
attributeChangedCallback(t, e, i) {
|
|
307
|
+
switch (t) {
|
|
308
|
+
case 'search-term':
|
|
309
|
+
e && !i
|
|
310
|
+
? this.optionNodes.forEach((s) => {
|
|
311
|
+
s.removeAttribute('hidden');
|
|
312
|
+
})
|
|
313
|
+
: i && this.filterNodes(i);
|
|
314
|
+
break;
|
|
315
|
+
default:
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
filterNodes(t) {
|
|
320
|
+
this.optionNodes.forEach((s) => {
|
|
321
|
+
let n = s.getAttribute('value').toLowerCase(),
|
|
322
|
+
r = s.getAttribute('label').toLowerCase();
|
|
323
|
+
n.includes(t.toLowerCase()) || r.includes(t.toLowerCase())
|
|
324
|
+
? s.removeAttribute('hidden')
|
|
325
|
+
: s.setAttribute('hidden', !0);
|
|
326
|
+
});
|
|
327
|
+
let e = this.optionNodes.find((s) => !s.hasAttribute('hidden')),
|
|
328
|
+
i = this.querySelector('#empty-state');
|
|
329
|
+
!e && !i
|
|
330
|
+
? this.insertAdjacentHTML('afterbegin', this.emptyState)
|
|
331
|
+
: e && i && this.removeChild(i);
|
|
332
|
+
}
|
|
333
|
+
handleFilter(t) {
|
|
334
|
+
let e = t.detail;
|
|
335
|
+
this.setAttribute('search-term', e);
|
|
336
|
+
}
|
|
337
|
+
handleFocus(t) {
|
|
338
|
+
this.setSelected(t.detail.direction);
|
|
339
|
+
}
|
|
340
|
+
handleReset() {
|
|
341
|
+
this.optionNodes.forEach((t) => t.setAttribute('tabindex', '-1'));
|
|
342
|
+
}
|
|
343
|
+
handleOptionSelection(t) {
|
|
344
|
+
this.triggers.filter((i) => i.tagName === 'INPUT')[0] &&
|
|
345
|
+
this.setAttribute('search-term', t.detail.label);
|
|
346
|
+
}
|
|
347
|
+
setSelected(t) {
|
|
348
|
+
let e = this.optionNodes.filter((r) => !r.hasAttribute('hidden'));
|
|
349
|
+
this.selectedNode.setAttribute('tabindex', '0');
|
|
350
|
+
let i = e.findIndex((r) => r === this.selectedNode),
|
|
351
|
+
s = e.length - 1,
|
|
352
|
+
n;
|
|
353
|
+
switch (t) {
|
|
354
|
+
case 'First':
|
|
355
|
+
n = 0;
|
|
356
|
+
break;
|
|
357
|
+
case 'Last':
|
|
358
|
+
n = s;
|
|
359
|
+
break;
|
|
360
|
+
case 'Up':
|
|
361
|
+
i === 0 ? (n = s) : (n = i - 1);
|
|
362
|
+
break;
|
|
363
|
+
default:
|
|
364
|
+
i === s ? (n = 0) : (n = i + 1);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
i !== n && this.swapSelected(this.selectedNode, e[n]);
|
|
368
|
+
}
|
|
369
|
+
swapSelected(t, e) {
|
|
370
|
+
(t.setAttribute('tabindex', '-1'),
|
|
371
|
+
e.setAttribute('tabindex', '0'),
|
|
372
|
+
(this.selectedNode = e),
|
|
373
|
+
x(this) && E(this.selectedNode, this),
|
|
374
|
+
f(e) || e.scrollIntoView({ behavior: 'smooth', block: 'nearest' }),
|
|
375
|
+
this.triggers.forEach((i) =>
|
|
376
|
+
i.setAttribute('aria-activedescendant', e.id),
|
|
377
|
+
));
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
d = class extends HTMLElement {
|
|
381
|
+
connectedCallback() {
|
|
382
|
+
(this.setAttribute('role', 'option'),
|
|
383
|
+
this.setAttribute('tabindex', '-1'),
|
|
384
|
+
this.setAttribute('id', b('option')),
|
|
385
|
+
(this.options = Array.from(
|
|
386
|
+
this.parentElement.querySelectorAll('smileid-combobox-option'),
|
|
387
|
+
)),
|
|
388
|
+
this.addEventListener('click', this.select));
|
|
389
|
+
}
|
|
390
|
+
disconnectedCallback() {
|
|
391
|
+
this.removeEventListener('click', this.select);
|
|
392
|
+
}
|
|
393
|
+
get value() {
|
|
394
|
+
return this.getAttribute('value');
|
|
395
|
+
}
|
|
396
|
+
get label() {
|
|
397
|
+
return this.getAttribute('label');
|
|
398
|
+
}
|
|
399
|
+
select() {
|
|
400
|
+
let t = this.options.find((e) => e.getAttribute('aria-selected'));
|
|
401
|
+
(t && t.removeAttribute('aria-selected'),
|
|
402
|
+
this.setAttribute('aria-selected', !0),
|
|
403
|
+
this.dispatchEvent(
|
|
404
|
+
new CustomEvent('combobox.option.select', {
|
|
405
|
+
detail: {
|
|
406
|
+
id: this.getAttribute('id'),
|
|
407
|
+
label: this.label,
|
|
408
|
+
value: this.value,
|
|
409
|
+
},
|
|
410
|
+
}),
|
|
411
|
+
));
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
u = a,
|
|
415
|
+
g = l,
|
|
416
|
+
p = h,
|
|
417
|
+
m = d;
|
|
418
|
+
'customElements' in window &&
|
|
419
|
+
!window.customElements.get('smileid-combobox') &&
|
|
420
|
+
(window.customElements.define('smileid-combobox', u),
|
|
421
|
+
window.customElements.define('smileid-combobox-trigger', g),
|
|
422
|
+
window.customElements.define('smileid-combobox-listbox', p),
|
|
423
|
+
window.customElements.define('smileid-combobox-option', m));
|
|
424
|
+
})();
|
|
2
425
|
//# sourceMappingURL=index.js.map
|