@webority/ui-elements 0.150.0 → 0.153.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.
Files changed (110) hide show
  1. package/dist/{WuiCommentThread-By-u3c5S.js → WuiCommentThread-BmRsl0K1.js} +1 -1
  2. package/dist/{WuiDataTable-D8UW2DMH.js → WuiDataTable-B4BYCd_s.js} +1 -1
  3. package/dist/WuiInlineEdit-BlBuWkHG.js +1 -0
  4. package/dist/{WuiLightbox-D7Nf1SbH.js → WuiLightbox-C2A14vHx.js} +1 -1
  5. package/dist/{WuiMarkdown-N96OX-To.js → WuiMarkdown-BXY0QKaO.js} +1 -1
  6. package/dist/{WuiMentionInput-BFB57FZI.js → WuiMentionInput-8Xjkzdqg.js} +1 -1
  7. package/dist/{WuiNotificationCenter-C6e13nCh.js → WuiNotificationCenter-ClkCTUnp.js} +1 -1
  8. package/dist/{WuiOverflow-CeLUmJR-.js → WuiOverflow-B0wA6aDe.js} +1 -1
  9. package/dist/{WuiPhone-rtex3VDC.js → WuiPhone-BVNVerap.js} +1 -1
  10. package/dist/{WuiRelativeTime-RdC80Zii.js → WuiRelativeTime-DyeUQOQ8.js} +1 -1
  11. package/dist/{WuiRollingNumber-YRMeRCGW.js → WuiRollingNumber-sfgNzaP0.js} +1 -1
  12. package/dist/WuiSavedViews-UaiP6YNG.js +1 -0
  13. package/dist/WuiSelect-DBPre2oe.js +9 -0
  14. package/dist/WuiTour-Cx61ijsm.js +1 -0
  15. package/dist/{WuiTree-ZD9GGmtg.js → WuiTree-0Yqu199O.js} +1 -1
  16. package/dist/{chips-2yXiMhK4.js → chips-Dony2fgq.js} +1 -1
  17. package/dist/{dataTable-D23oUOhU.js → dataTable-B-7oAeii.js} +1 -1
  18. package/dist/{drawerDiscard-CUN8L47U.js → drawerDiscard-C0yRSl1I.js} +1 -1
  19. package/dist/elements/comment-thread.js +1 -1
  20. package/dist/elements/data-table.js +1 -1
  21. package/dist/elements/inline-edit.js +1 -1
  22. package/dist/elements/kanban.js +1 -1
  23. package/dist/elements/lightbox.js +1 -1
  24. package/dist/elements/markdown.js +1 -1
  25. package/dist/elements/mention-input.js +1 -1
  26. package/dist/elements/notification-center.js +1 -1
  27. package/dist/elements/overflow.js +1 -1
  28. package/dist/elements/phone.js +1 -1
  29. package/dist/elements/relative-time.js +1 -1
  30. package/dist/elements/rolling-number.js +1 -1
  31. package/dist/elements/saved-views.js +1 -1
  32. package/dist/elements/select.js +1 -1
  33. package/dist/elements/tour.js +1 -1
  34. package/dist/elements/tree.js +1 -1
  35. package/dist/{fileViewerImage-tzF4DDq7.js → fileViewerImage-Bt1jeArm.js} +1 -1
  36. package/dist/{fileViewerPdf-BLMhF8NT.js → fileViewerPdf-CdaDuaRJ.js} +1 -1
  37. package/dist/formatters-ljfITOZ3.js +1 -0
  38. package/dist/helpers.js +1 -1
  39. package/dist/{inlineEditText-H7Pr8IU9.js → inlineEditText-CsLCQbcg.js} +1 -1
  40. package/dist/{kanban-CJ587-XT.js → kanban-Dz8m-17x.js} +1 -1
  41. package/dist/{kanbanModel-BdqSa1lJ.js → kanbanModel-C2IOPJ8L.js} +1 -1
  42. package/dist/{notificationDays-BKVW7xYD.js → notificationDays-BIWczft0.js} +1 -1
  43. package/dist/{relativeTime-YTAOONRy.js → relativeTime-BahImc8F.js} +1 -1
  44. package/dist/{search-BXcvm716.js → search-C8xIzt6h.js} +1 -1
  45. package/dist/server.js +1 -1
  46. package/dist/ui-calendar.global.js +1 -1
  47. package/dist/ui-calendar.js +1 -1
  48. package/dist/ui-chart.global.js +2 -2
  49. package/dist/ui-chart.js +2 -2
  50. package/dist/ui-elements/carousel.global.js +1 -1
  51. package/dist/ui-elements/code-block.global.js +1 -1
  52. package/dist/ui-elements/command-palette.global.js +1 -1
  53. package/dist/ui-elements/comment-thread.global.js +1 -1
  54. package/dist/ui-elements/consent-banner.global.js +1 -1
  55. package/dist/ui-elements/context-menu.global.js +1 -1
  56. package/dist/ui-elements/date-range.global.js +1 -1
  57. package/dist/ui-elements/drawer.global.js +1 -1
  58. package/dist/ui-elements/glyphs.global.js +1 -1
  59. package/dist/ui-elements/image-crop.global.js +1 -1
  60. package/dist/ui-elements/inline-edit.global.js +1 -1
  61. package/dist/ui-elements/kanban.global.js +1 -1
  62. package/dist/ui-elements/lead-popup.global.js +1 -1
  63. package/dist/ui-elements/lightbox.global.js +1 -1
  64. package/dist/ui-elements/markdown.global.js +2 -2
  65. package/dist/ui-elements/org-tree.global.js +1 -1
  66. package/dist/ui-elements/phone.global.js +2 -2
  67. package/dist/ui-elements/resizable.global.js +1 -1
  68. package/dist/ui-elements/saved-views.global.js +1 -1
  69. package/dist/ui-elements/select-chips.global.js +1 -1
  70. package/dist/ui-elements/select-recents.global.js +1 -1
  71. package/dist/ui-elements/select-search.global.js +1 -1
  72. package/dist/ui-elements/slider.global.js +1 -1
  73. package/dist/ui-elements/sortable.global.js +1 -1
  74. package/dist/ui-elements/status-icon.global.js +1 -1
  75. package/dist/ui-elements/timepicker.global.js +1 -1
  76. package/dist/ui-elements/tour.global.js +1 -1
  77. package/dist/ui-elements/tree.global.js +1 -1
  78. package/dist/ui-elements/wizard.global.js +1 -1
  79. package/dist/ui-elements.global.js +9 -9
  80. package/dist/ui-elements.js +1 -1
  81. package/dist/ui-file-viewer.global.js +1 -1
  82. package/dist/ui-file-viewer.js +1 -1
  83. package/dist/ui-tour.global.js +1 -1
  84. package/dist/{wuiHttp-523iN_RF.js → wuiHttp-DGbD7Fra.js} +1 -1
  85. package/package.json +4 -3
  86. package/types/WuiCommentThread.d.ts +2 -2
  87. package/types/WuiImageCrop.d.ts +4 -4
  88. package/types/WuiSelect.d.ts +9 -0
  89. package/types/WuiTour.d.ts +1 -1
  90. package/types/chartSpec.d.ts +20 -20
  91. package/types/fileValidation.d.ts +2 -2
  92. package/types/fileViewerPdf.d.ts +3 -3
  93. package/types/formatters.d.ts +19 -14
  94. package/types/inputMask.d.ts +3 -3
  95. package/types/kanban.d.ts +1 -1
  96. package/types/listQuery.d.ts +10 -10
  97. package/types/razor-js/modules/api.d.ts +3 -0
  98. package/types/razor-js/modules/buttons.d.ts +1 -0
  99. package/types/razor-js/modules/widgets.d.ts +1 -0
  100. package/types/razor-js/webority-ui.d.ts +3 -0
  101. package/types/select/list.d.ts +8 -8
  102. package/types/server/remoteModal.d.ts +12 -12
  103. package/types/server/wuiHttp.d.ts +5 -5
  104. package/types/stepperHeader.d.ts +2 -2
  105. package/types/themeTransition.d.ts +2 -2
  106. package/dist/WuiInlineEdit-r55qgh8A.js +0 -1
  107. package/dist/WuiSavedViews-DtyAoZKb.js +0 -1
  108. package/dist/WuiSelect-D9ABfsdZ.js +0 -9
  109. package/dist/WuiTour-CrIFLmSK.js +0 -1
  110. package/dist/formatters-C3V6M5zV.js +0 -1
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{n as r,t as i}from"./buttonClass-GtEi8hAY.js";import{a,i as o,n as s,r as c}from"./commentText-BnX7rA2-.js";import{t as l}from"./elementBase-Cxeyx0tU.js";import{l as u}from"./wuiHttp-523iN_RF.js";import{i as d}from"./WuiMentionInput-BFB57FZI.js";var f=`[data-wui-items]`,p=`[data-wui-picker]`,m=`[data-wui-composer]`,h=`[data-wui-comment]`,g=`[data-wui-live]`,_=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:a},v=e=>e instanceof Element?e:null,y=e=>`disabled`in e&&e.disabled===!0,b=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},x=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},S=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},C=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],w=class extends l{_wired;_busy;_peopleProp;_pickerFor;_onDocClick;_repositionPicker;_openers;constructor(){super(),this._wired=!1,this._busy=!1,this._peopleProp=null,this._pickerFor=null,this._onClick=this._onClick.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onSubmitKey=this._onSubmitKey.bind(this),this._onDocClick=e=>{this._pickerFor&&!x(this,p,HTMLElement)?.contains(v(e.target))&&!this._pickerFor.button.contains(v(e.target))&&this._closePicker(!1)},this._repositionPicker=()=>{this._pickerFor&&n(this._pickerFor.button,x(this,p,HTMLElement))}}connectedCallback(){if(Object.hasOwn(this,`people`)){let e=this.people;Reflect.deleteProperty(this,`people`),this.people=e}if(this._wired)return;this._wired=!0,this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`wui:mention-input:submit`,this._onSubmitKey),customElements.upgrade(this);let e=x(this,`${m} wui-mention-input`,d);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:C(this,`:scope > [data-wui-people] > wui-option`,HTMLElement).map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0}))}set people(e){this._peopleProp=Array.isArray(e)?e:[];for(let e of this.querySelectorAll(`wui-mention-input`))e.people=this._peopleProp}_handPeople(e){!e||this.hasAttribute(`remote`)||this.hasAttribute(`source`)||(e.people=this.people)}_applyComposerPlaceholder(e){let t=this.getAttribute(`composer-placeholder`);e&&t!=null&&e.setAttribute(`placeholder`,t)}_reactionChoices(){let e=this.getAttribute(`reaction-choices`),t=e?e.split(/\s+/).filter(Boolean):[];return t.length?t:s}_onClick(e){let t=S(v(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!y(t)){let e=t.closest(p),n=e?this._pickerFor?.comment:t.closest(h);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=S(v(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||y(n))return;let r=n.closest(h);switch(n.getAttribute(`data-wui-action`)){case`reply`:this._openReply(r,n);break;case`edit`:this._openEditor(r,n);break;case`delete`:this._askDelete(r);break;case`cancel-delete`:this._closeConfirm(r,!0);break;case`confirm-delete`:{let e=b(r,`comment`);this._send(`delete`,{commentId:e.getAttribute(`data-wui-comment`)},{comment:e,scope:e});break}case`react-menu`:this._pickerFor?.button===n?this._closePicker(!0):this._openPicker(r,n);break;case`cancel`:this._closeSlot(S(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=x(this,p,HTMLElement),n=v(e.target);if(this._pickerFor&&t?.contains(n)){let r=C(t,`[data-wui-emoji]`,HTMLElement),i=n instanceof HTMLElement?r.indexOf(n):-1;e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closePicker(!0)):e.key===`ArrowRight`||e.key===`ArrowLeft`?(e.preventDefault(),r[(i+(e.key===`ArrowRight`?1:-1)+r.length)%r.length]?.focus()):e.key===`Tab`&&this._closePicker(!1);return}if(e.key!==`Escape`)return;let r=S(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=S(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(h),!0))}_onSubmitKey(e){let t=x(S(v(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!y(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=x(e,`:scope > [data-wui-reply]`,HTMLElement);if(!n)return;if(!n.hidden){n.querySelector(`wui-mention-input`)?.focus();return}let r=e?.querySelector(`.wui-comment-author`)?.textContent?.trim()||``;this._fillSlot(n,{label:c.replyLabel(r),placeholder:c.replyPlaceholder,value:``,send:c.reply,opener:t})}_openEditor(e,t){let n=x(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=x(b(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:c.editLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:c.save,opener:t})}_fillSlot(e,{label:t,placeholder:n,value:r,send:i,opener:a}){let o=this.ownerDocument,s=o.createElement(`wui-mention-input`);s.className=`wui-mention-input`,s.setAttribute(`label`,t),n&&s.setAttribute(`placeholder`,n),s.setAttribute(`rows`,`2`),s.setAttribute(`value`,r);for(let e of[`remote`,`source`,`min-chars`,`debounce`]){let t=this.getAttribute(e);t!=null&&s.setAttribute(e,t)}let l=o.createElement(`div`);l.className=`wui-comment-form-actions`,l.append(this._button(`primary`,`solid`,`sm`,`send`,i),this._button(`primary`,`ghost`,`sm`,`cancel`,c.cancel));let u=o.createElement(`div`);u.className=`wui-comment-error`,u.setAttribute(`data-wui-error`,``),u.hidden=!0,e.replaceChildren(s,l,u),this._handPeople(s),e.hidden=!1,this._openers??=/* @__PURE__ */ new WeakMap,this._openers.set(e,a),s.focus();let d=s.querySelector(`textarea`);d?.setSelectionRange(d.value.length,d.value.length)}_button(e,t,n,a,o){let s=this.ownerDocument.createElement(`button`);return s.type=`button`,s.className=r(e,t,n),s.dataset.wui=i,s.setAttribute(`data-wui-action`,a),s.textContent=o,s}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=x(e.parentElement,`:scope > [data-wui-text]`,HTMLElement);t&&(t.hidden=!1)}let n=this._openers?.get(e);t&&n?.isConnected&&n.focus()}_askDelete(e){let t=x(e,`:scope > .wui-comment-row`,HTMLElement),n=x(t,`[data-wui-confirm]`,HTMLElement),r=x(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),x(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=x(e,`:scope > .wui-comment-row`,HTMLElement),r=x(n,`[data-wui-confirm]`,HTMLElement),i=x(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&x(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(t,r){let i=x(this,p,HTMLElement);i&&t&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:t,button:r},r.setAttribute(`aria-expanded`,`true`),i.hidden=!1,n(r,i),e(this,this._repositionPicker),this.ownerDocument.addEventListener(`click`,this._onDocClick,!0),x(i,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let n=this._pickerFor;if(!n)return;this._pickerFor=null;let r=x(this,p,HTMLElement);r&&(r.hidden=!0),n.button.setAttribute(`aria-expanded`,`false`),t(this),this.ownerDocument.removeEventListener(`click`,this._onDocClick,!0),e&&n.button.isConnected&&n.button.focus()}_react(e,t){t&&!this.hasAttribute(`no-reactions`)&&this._send(`react`,{commentId:e.getAttribute(`data-wui-comment`),emoji:t},{comment:e,scope:e})}_sendFrom(e){let t=S(e,`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement);if(!t)return;let n=t.querySelector(`wui-mention-input`),r=n?.value??``;if(!r.trim()){this._showError(t,c.emptyBody),n?.focus();return}let i=t.closest(h);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:b(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:b(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t})}async _send(e,t,{comment:n,scope:r,form:i}){if(this._busy)return;this._busy=!0,this.setAttribute(`aria-busy`,`true`);let a=i??x(n,`:scope > .wui-comment-row`,HTMLElement)??this;this._showError(a,null);let o=[...r.querySelectorAll(`button, textarea`)].filter(e=>e instanceof HTMLButtonElement||e instanceof HTMLTextAreaElement).filter(e=>!e.disabled);for(let e of o)e.disabled=!0;let s=await this._persist({intent:e,...t});for(let e of o)e.isConnected&&(e.disabled=!1);this._busy=!1,this.removeAttribute(`aria-busy`);let l=t.commentId??null,u=t.parentId??null;s.ok?(s.html!=null&&this._swapItems(s.html),e===`post`?i?.querySelector(`wui-mention-input`)?.clear():i?.isConnected&&this._closeSlot(i,!1),e===`delete`&&n?.isConnected&&this._closeConfirm(n,!1),this._restoreFocus(e,t,i),c.done[e]&&this._announce(c.done[e]),this.dispatchEvent(new CustomEvent(`wui:comment-thread:done`,{bubbles:!0,detail:{intent:e,commentId:l,parentId:u}}))):s.kind!==`session`&&s.kind!==`aborted`&&(this._showError(a.isConnected?a:this,s.message),this._announce(s.message),this.dispatchEvent(new CustomEvent(`wui:comment-thread:failed`,{bubbles:!0,detail:{intent:e,kind:s.kind,message:s.message}})))}async _persist(e){if(this.hasAttribute(`controlled`)){if(typeof this.submit!=`function`)return{ok:!0,html:null};try{return await this.submit(e),{ok:!0,html:null}}catch(e){return{ok:!1,kind:`server`,message:_(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:o};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await u(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||c.failed[r.kind]||`Something went wrong on our side. Try again in a moment.`}}_swapItems(e){let t=x(this,f,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=x(n.content,f,HTMLElement);t.replaceChildren(...r?r.childNodes:n.content.childNodes)}_restoreFocus(e,t,n){let r=this.ownerDocument,i=r.activeElement;if(i&&i!==r.body&&i.isConnected&&this.contains(i)&&!y(i))return;let a=e=>e?C(this,h,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>x(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=x(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=x(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=C(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??x(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=x(this,`${m} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=x(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=x(this,`:scope > ${g}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{w as t};
1
+ import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{n as r,t as i}from"./buttonClass-GtEi8hAY.js";import{a,i as o,n as s,r as c}from"./commentText-BnX7rA2-.js";import{t as l}from"./elementBase-Cxeyx0tU.js";import{l as u}from"./wuiHttp-DGbD7Fra.js";import{i as d}from"./WuiMentionInput-8Xjkzdqg.js";var f=`[data-wui-items]`,p=`[data-wui-picker]`,m=`[data-wui-composer]`,h=`[data-wui-comment]`,g=`[data-wui-live]`,_=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:a},v=e=>e instanceof Element?e:null,y=e=>`disabled`in e&&e.disabled===!0,b=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},x=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},S=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},C=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],w=class extends l{_wired;_busy;_peopleProp;_pickerFor;_onDocClick;_repositionPicker;_openers;constructor(){super(),this._wired=!1,this._busy=!1,this._peopleProp=null,this._pickerFor=null,this._onClick=this._onClick.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onSubmitKey=this._onSubmitKey.bind(this),this._onDocClick=e=>{this._pickerFor&&!x(this,p,HTMLElement)?.contains(v(e.target))&&!this._pickerFor.button.contains(v(e.target))&&this._closePicker(!1)},this._repositionPicker=()=>{this._pickerFor&&n(this._pickerFor.button,x(this,p,HTMLElement))}}connectedCallback(){if(Object.hasOwn(this,`people`)){let e=this.people;Reflect.deleteProperty(this,`people`),this.people=e}if(this._wired)return;this._wired=!0,this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`wui:mention-input:submit`,this._onSubmitKey),customElements.upgrade(this);let e=x(this,`${m} wui-mention-input`,d);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:C(this,`:scope > [data-wui-people] > wui-option`,HTMLElement).map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0}))}set people(e){this._peopleProp=Array.isArray(e)?e:[];for(let e of this.querySelectorAll(`wui-mention-input`))e.people=this._peopleProp}_handPeople(e){!e||this.hasAttribute(`remote`)||this.hasAttribute(`source`)||(e.people=this.people)}_applyComposerPlaceholder(e){let t=this.getAttribute(`composer-placeholder`);e&&t!=null&&e.setAttribute(`placeholder`,t)}_reactionChoices(){let e=this.getAttribute(`reaction-choices`),t=e?e.split(/\s+/).filter(Boolean):[];return t.length?t:s}_onClick(e){let t=S(v(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!y(t)){let e=t.closest(p),n=e?this._pickerFor?.comment:t.closest(h);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=S(v(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||y(n))return;let r=n.closest(h);switch(n.getAttribute(`data-wui-action`)){case`reply`:this._openReply(r,n);break;case`edit`:this._openEditor(r,n);break;case`delete`:this._askDelete(r);break;case`cancel-delete`:this._closeConfirm(r,!0);break;case`confirm-delete`:{let e=b(r,`comment`);this._send(`delete`,{commentId:e.getAttribute(`data-wui-comment`)},{comment:e,scope:e});break}case`react-menu`:this._pickerFor?.button===n?this._closePicker(!0):this._openPicker(r,n);break;case`cancel`:this._closeSlot(S(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=x(this,p,HTMLElement),n=v(e.target);if(this._pickerFor&&t?.contains(n)){let r=C(t,`[data-wui-emoji]`,HTMLElement),i=n instanceof HTMLElement?r.indexOf(n):-1;e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closePicker(!0)):e.key===`ArrowRight`||e.key===`ArrowLeft`?(e.preventDefault(),r[(i+(e.key===`ArrowRight`?1:-1)+r.length)%r.length]?.focus()):e.key===`Tab`&&this._closePicker(!1);return}if(e.key!==`Escape`)return;let r=S(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=S(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(h),!0))}_onSubmitKey(e){let t=x(S(v(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!y(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=x(e,`:scope > [data-wui-reply]`,HTMLElement);if(!n)return;if(!n.hidden){n.querySelector(`wui-mention-input`)?.focus();return}let r=e?.querySelector(`.wui-comment-author`)?.textContent?.trim()||``;this._fillSlot(n,{label:c.replyLabel(r),placeholder:c.replyPlaceholder,value:``,send:c.reply,opener:t})}_openEditor(e,t){let n=x(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=x(b(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:c.editLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:c.save,opener:t})}_fillSlot(e,{label:t,placeholder:n,value:r,send:i,opener:a}){let o=this.ownerDocument,s=o.createElement(`wui-mention-input`);s.className=`wui-mention-input`,s.setAttribute(`label`,t),n&&s.setAttribute(`placeholder`,n),s.setAttribute(`rows`,`2`),s.setAttribute(`value`,r);for(let e of[`remote`,`source`,`min-chars`,`debounce`]){let t=this.getAttribute(e);t!=null&&s.setAttribute(e,t)}let l=o.createElement(`div`);l.className=`wui-comment-form-actions`,l.append(this._button(`primary`,`solid`,`sm`,`send`,i),this._button(`primary`,`ghost`,`sm`,`cancel`,c.cancel));let u=o.createElement(`div`);u.className=`wui-comment-error`,u.setAttribute(`data-wui-error`,``),u.hidden=!0,e.replaceChildren(s,l,u),this._handPeople(s),e.hidden=!1,this._openers??=/* @__PURE__ */ new WeakMap,this._openers.set(e,a),s.focus();let d=s.querySelector(`textarea`);d?.setSelectionRange(d.value.length,d.value.length)}_button(e,t,n,a,o){let s=this.ownerDocument.createElement(`button`);return s.type=`button`,s.className=r(e,t,n),s.dataset.wui=i,s.setAttribute(`data-wui-action`,a),s.textContent=o,s}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=x(e.parentElement,`:scope > [data-wui-text]`,HTMLElement);t&&(t.hidden=!1)}let n=this._openers?.get(e);t&&n?.isConnected&&n.focus()}_askDelete(e){let t=x(e,`:scope > .wui-comment-row`,HTMLElement),n=x(t,`[data-wui-confirm]`,HTMLElement),r=x(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),x(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=x(e,`:scope > .wui-comment-row`,HTMLElement),r=x(n,`[data-wui-confirm]`,HTMLElement),i=x(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&x(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(t,r){let i=x(this,p,HTMLElement);i&&t&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:t,button:r},r.setAttribute(`aria-expanded`,`true`),i.hidden=!1,n(r,i),e(this,this._repositionPicker),this.ownerDocument.addEventListener(`click`,this._onDocClick,!0),x(i,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let n=this._pickerFor;if(!n)return;this._pickerFor=null;let r=x(this,p,HTMLElement);r&&(r.hidden=!0),n.button.setAttribute(`aria-expanded`,`false`),t(this),this.ownerDocument.removeEventListener(`click`,this._onDocClick,!0),e&&n.button.isConnected&&n.button.focus()}_react(e,t){t&&!this.hasAttribute(`no-reactions`)&&this._send(`react`,{commentId:e.getAttribute(`data-wui-comment`),emoji:t},{comment:e,scope:e})}_sendFrom(e){let t=S(e,`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement);if(!t)return;let n=t.querySelector(`wui-mention-input`),r=n?.value??``;if(!r.trim()){this._showError(t,c.emptyBody),n?.focus();return}let i=t.closest(h);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:b(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:b(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t})}async _send(e,t,{comment:n,scope:r,form:i}){if(this._busy)return;this._busy=!0,this.setAttribute(`aria-busy`,`true`);let a=i??x(n,`:scope > .wui-comment-row`,HTMLElement)??this;this._showError(a,null);let o=[...r.querySelectorAll(`button, textarea`)].filter(e=>e instanceof HTMLButtonElement||e instanceof HTMLTextAreaElement).filter(e=>!e.disabled);for(let e of o)e.disabled=!0;let s=await this._persist({intent:e,...t});for(let e of o)e.isConnected&&(e.disabled=!1);this._busy=!1,this.removeAttribute(`aria-busy`);let l=t.commentId??null,u=t.parentId??null;s.ok?(s.html!=null&&this._swapItems(s.html),e===`post`?i?.querySelector(`wui-mention-input`)?.clear():i?.isConnected&&this._closeSlot(i,!1),e===`delete`&&n?.isConnected&&this._closeConfirm(n,!1),this._restoreFocus(e,t,i),c.done[e]&&this._announce(c.done[e]),this.dispatchEvent(new CustomEvent(`wui:comment-thread:done`,{bubbles:!0,detail:{intent:e,commentId:l,parentId:u}}))):s.kind!==`session`&&s.kind!==`aborted`&&(this._showError(a.isConnected?a:this,s.message),this._announce(s.message),this.dispatchEvent(new CustomEvent(`wui:comment-thread:failed`,{bubbles:!0,detail:{intent:e,kind:s.kind,message:s.message}})))}async _persist(e){if(this.hasAttribute(`controlled`)){if(typeof this.submit!=`function`)return{ok:!0,html:null};try{return await this.submit(e),{ok:!0,html:null}}catch(e){return{ok:!1,kind:`server`,message:_(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:o};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await u(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||c.failed[r.kind]||`Something went wrong on our side. Try again in a moment.`}}_swapItems(e){let t=x(this,f,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=x(n.content,f,HTMLElement);t.replaceChildren(...r?r.childNodes:n.content.childNodes)}_restoreFocus(e,t,n){let r=this.ownerDocument,i=r.activeElement;if(i&&i!==r.body&&i.isConnected&&this.contains(i)&&!y(i))return;let a=e=>e?C(this,h,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>x(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=x(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=x(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=C(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??x(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=x(this,`${m} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=x(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=x(this,`:scope > ${g}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{w as t};
@@ -1 +1 @@
1
- import{C as e,M as t,S as n,T as r,_ as i,b as a,c as o,g as s,h as c,i as l,j as u,r as d,t as f}from"./dataTable-D23oUOhU.js";import{t as p}from"./dom-Do1pAA12.js";import{t as m}from"./elementBase-Cxeyx0tU.js";var h=`.wui-col-resize`,g=`.wui-group-row, .wui-virtual-spacer`,_=`.wui-select-cell, .wui-expand-cell`,v=`<svg class="wui-icon" data-icon="chevron-down" data-wui="AppIcon" width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="1.5" d="M19.92 8.95l-6.52 6.52c-.77.77-2.03.77-2.8 0L4.08 8.95"></path></svg>`;function y(e){if(e==null)throw TypeError(`Missing DOM node`);return e}function b(e,t){if(e instanceof t)return e;throw TypeError(`Missing DOM node`)}var x=e=>{let t=p(e,h);return t instanceof HTMLElement?t:null},S=e=>e.hasAttribute(`data-wui-skeleton`)||!!e.querySelector(`:scope > td > .skeleton`),C=class extends m{_frame;_headDirty;_rowsDirty;_frozenSig;_natural;_widths;_collapsed;_groupOrder;_items;_range;_drag;_userSized;_swallowClick;_mo;_ro;_fonts;_onPointerDown;_onKeyDown;_onClick;_onDblClick;_onScroll;_onFonts;_top=null;_bottom=null;_rowHeight=0;constructor(){super(),this._frame=0,this._headDirty=!0,this._rowsDirty=!0,this._frozenSig=null,this._natural=[],this._widths={},this._collapsed=/* @__PURE__ */ new Set,this._groupOrder=[],this._items=[],this._range=null,this._drag=null,this._userSized=!1,this._swallowClick=!1,this._mo=null,this._ro=null,this._fonts=null,this._onPointerDown=e=>this._startDrag(e),this._onKeyDown=e=>this._key(e),this._onClick=e=>this._click(e),this._onDblClick=e=>{let t=x(e.target);t&&this.contains(t)&&this._reset(t.closest(`th`))},this._onScroll=()=>{this.hasAttribute(`virtual`)&&this._schedule()},this._onFonts=()=>{this._userSized||this._drag||this._frozenSig===null||!this.hasAttribute(`resizable`)||(this._frozenSig=null,this._schedule())}}connectedCallback(){this._widths=r(this.getAttribute(`view-key`)),this.addEventListener(`pointerdown`,this._onPointerDown,!0),this.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick,!0),this.addEventListener(`dblclick`,this._onDblClick),this.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._fonts=this.ownerDocument.fonts??null,this._fonts?.addEventListener(`loadingdone`,this._onFonts),typeof MutationObserver<`u`&&(this._mo=new MutationObserver(e=>this._mutated(e)),this._mo.observe(this,{childList:!0,subtree:!0})),typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(()=>this._schedule()),this._ro.observe(this)),this._headDirty=!0,this._rowsDirty=!0,this._schedule()}disconnectedCallback(){this.removeEventListener(`pointerdown`,this._onPointerDown,!0),this.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick,!0),this.removeEventListener(`dblclick`,this._onDblClick),this.removeEventListener(`scroll`,this._onScroll),this._fonts?.removeEventListener(`loadingdone`,this._onFonts),this._fonts=null,this._mo?.disconnect(),this._ro?.disconnect(),this._mo=null,this._ro=null,this._frame&&cancelAnimationFrame(this._frame),this._frame=0,this._drag=null}refresh(){this._headDirty=!0,this._rowsDirty=!0,this._run()}get _table(){let e=this.querySelector(`:scope > table`);return e instanceof HTMLTableElement?e:null}_headCells(e){let t=e.tHead?.rows[0];return t?[...t.cells]:[]}_schedule(){this._frame||=requestAnimationFrame(()=>{this._frame=0,this._run()})}_mutated(e){for(let t of e){let e=t.target instanceof Element?t.target:t.target.parentElement;e&&((e.closest(`thead`)||e===this._table||e===this)&&(this._headDirty=!0),(e.closest(`tbody, tfoot`)||e===this._table||e===this)&&(this._rowsDirty=!0))}this._schedule()}_run(){let e=this._table;if(!e)return;let t=this._headDirty,n=this._rowsDirty;this._headDirty=!1,this._rowsDirty=!1,n&&this.hasAttribute(`group-by`)&&this._group(e),this._pins(e,t||n),this.hasAttribute(`resizable`)&&(t&&this._handles(e),this._layout(e)),this.hasAttribute(`virtual`)&&this._virtual(e,t||n),this._mo?.takeRecords()}_pins(t,r){let i=this._headCells(t),o=i.map(e=>{let t=e.dataset.pin;return t===`start`||t===`end`?t:e.matches(_)?`lead`:null});if(!o.some(e=>e===`start`||e===`end`))return;let s=e(o);s.forEach((e,t)=>{e&&this._ro?.observe(y(i[t]))});let c=e=>y(i[e]).getBoundingClientRect().width,u=0;s.forEach((e,r)=>{e?.side===`start`&&(this._setVar(t,n(`start`,e.ordinal),u),u+=c(r))}),u=0;for(let e=s.length-1;e>=0;e--){let r=s[e];r?.side===`end`&&(this._setVar(t,n(`end`,r.ordinal),u),u+=c(e))}if(r)for(let e of t.rows)e.matches(`${g}, .wui-row-expanded`)||e.cells.length!==i.length||s.forEach((t,n)=>{if(!t)return;let r=y(e.cells[n]);r.classList.contains(`wui-pin-${t.side}`)||r.classList.add(`wui-pin-${t.side}`),t.edge&&!r.classList.contains(`wui-pin-${t.side}-edge`)&&r.classList.add(`wui-pin-${t.side}-edge`);let i=a(t.side,t.ordinal);r.style.getPropertyValue(`--wui-pin-at`)!==i&&r.style.setProperty(l,i)})}_setVar(e,t,n){let r=`${Math.round(n*100)/100}px`;e.style.getPropertyValue(t)!==r&&e.style.setProperty(t,r)}_resizable(e){return e.map((t,n)=>n<e.length-1&&!t.matches(_))}_handles(e){let t=this._headCells(e),n=this._resizable(t);t.forEach((e,t)=>{if(!n[t]||e.querySelector(h))return;let r=e.ownerDocument.createElement(`span`);r.className=`wui-col-resize`,r.setAttribute(`role`,`separator`),r.setAttribute(`aria-orientation`,`vertical`),r.setAttribute(`aria-valuemin`,`48`),r.setAttribute(`aria-valuemax`,String(f)),r.setAttribute(`tabindex`,`0`);let i=(e.textContent??``).trim();r.setAttribute(`aria-label`,d.resize(i)),i&&!e.hasAttribute(`aria-label`)&&e.setAttribute(`aria-label`,i),e.classList.add(`wui-col-resizable`),e.appendChild(r)})}_hasRows(e){for(let t of e.tBodies)for(let e of t.rows)if(!e.matches(g)&&!S(e))return!0;return!1}_signature(e){return e.map(e=>e.dataset.key||(e.textContent??``).trim()).join(``)}_layout(e){let t=this._headCells(e),n=this._signature(t);t.length&&n!==this._frozenSig&&(this._hasRows(e)?this._freeze(e,t,n):this._applyRemembered(t))}_applyRemembered(e){for(let t of e){let e=t.dataset.key&&this._widths[t.dataset.key];e&&(t.style.width=`${e}px`);let n=t.querySelector(h);n&&this._handleValue(n,c(e||t.getBoundingClientRect().width))}}_freeze(e,t,n){e.style.tableLayout=``,e.style.width=``,e.removeAttribute(`data-wui-fixed`);for(let e of t)e.hasAttribute(`data-wui-width`)&&(e.style.width=``,e.removeAttribute(`data-wui-width`));this._natural=t.map(e=>e.getBoundingClientRect().width),t.forEach((e,n)=>{if(n===t.length-1||e.matches(_))return;let r=e.dataset.key&&this._widths[e.dataset.key];this._setWidth(e,r||this._natural[n])}),e.style.tableLayout=`fixed`,e.setAttribute(`data-wui-fixed`,``),this._frozenSig=n,this._fitTable(e,t)}_setWidth(e,t){let n=c(t);e.style.width=`${n}px`,e.setAttribute(`data-wui-width`,``);let r=e.querySelector(h);return r&&this._handleValue(r,n),n}_handleValue(e,t){e.setAttribute(`aria-valuenow`,String(t)),e.setAttribute(`aria-valuetext`,d.width(t))}_fitTable(e,t){let n=t.length-1,r=this._natural[n]||0;for(let e=0;e<n;e++)r+=Number.parseFloat(y(t[e]).style.width)||this._natural[e]||0;e.style.width=`max(100%, ${Math.round(r)}px)`}_ensureFrozen(e){let t=this._headCells(e),n=this._signature(t);return n!==this._frozenSig&&this._freeze(e,t,n),t}_resizeTo(e,t,n){let r=this._table;if(!r)return;let i=this._ensureFrozen(r);this._userSized=!0,this._setWidth(e,t),this._fitTable(r,i),n&&this._remember(e),this._pins(r,!1)}_remember(e){let n=e.dataset.key;n&&(this._widths={...this._widths,[n]:Number.parseFloat(e.style.width)},t(this.getAttribute(`view-key`),this._widths))}_reset(e){let n=this._table;if(!e||!n)return;let r=this._ensureFrozen(n);this._userSized=!0;let i=e.dataset.key;if(i&&i in this._widths){let{[i]:e,...n}=this._widths;this._widths=n,t(this.getAttribute(`view-key`),this._widths)}this._setWidth(e,this._natural[r.indexOf(e)]||0),this._fitTable(n,r),this._pins(n,!1)}_rtl(){return getComputedStyle(this).direction===`rtl`}_startDrag(e){let t=x(e.target);if(!t||!this.contains(t)||e.button!==0)return;e.preventDefault(),e.stopPropagation();let n=t.closest(`th`),r=this._table;if(!n||!r)return;this._ensureFrozen(r);let i={th:n,x:e.clientX,from:n.getBoundingClientRect().width,dir:this._rtl()?-1:1,moved:!1};this._drag=i,t.setPointerCapture?.(e.pointerId),t.classList.add(`is-dragging`);let a=e=>{let t=(e.clientX-i.x)*i.dir;Math.abs(t)>1&&(i.moved=!0),this._resizeTo(n,i.from+t,!1)},o=e=>{t.removeEventListener(`pointermove`,a),t.removeEventListener(`pointerup`,o),t.removeEventListener(`pointercancel`,o),t.classList.remove(`is-dragging`),this._drag=null,e.type===`pointercancel`?this._resizeTo(n,i.from,!1):i.moved&&this._remember(n),this._swallowClick=!0,setTimeout(()=>{this._swallowClick=!1},0)};t.addEventListener(`pointermove`,a),t.addEventListener(`pointerup`,o),t.addEventListener(`pointercancel`,o)}_key(e){let t=x(e.target);if(!t||!this.contains(t))return;let n=t.closest(`th`);if(e.key===`Enter`||e.key===` `){e.preventDefault(),e.stopPropagation();return}if(e.key===`Home`){e.preventDefault(),e.stopPropagation(),this._reset(n);return}if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let r=this._table;if(!r)return;this._ensureFrozen(r);let i=y(n),a=e.shiftKey?50:10,o=e.key===`ArrowRight`!==this._rtl(),s=Number.parseFloat(i.style.width)||i.getBoundingClientRect().width;this._resizeTo(i,s+(o?a:-a),!0)}_click(e){let t=e.target instanceof Element&&e.target.closest(h)!==null;if(this._swallowClick||t){e.stopPropagation(),(t||this._swallowClick)&&e.preventDefault(),this._swallowClick=!1;return}if(!this.hasAttribute(`group-by`))return;let n=p(e.target,`.wui-group-toggle`)?.closest(`.wui-group-row`);if(!(n instanceof HTMLTableRowElement)||!this.contains(n))return;let r=n.dataset.groupKey;this._collapsed.has(r)?this._collapsed.delete(r):this._collapsed.add(r),this._showGroup(n,!this._collapsed.has(r));let i=this._table;i&&this.hasAttribute(`virtual`)&&(this._virtual(i,!0),this._mo?.takeRecords())}_group(e){let t=this.getAttribute(`group-by`),n=this._headCells(e),r=n.findIndex(e=>e.dataset.key===t);if(r<0)throw Error(`<wui-data-table group-by="${t}"> needs a header cell with data-key="${t}".`);let a=e.tBodies[0];if(!a)return;let o=[...a.rows].filter(e=>!e.matches(g));if(o.some(S))return;let c=this.ownerDocument,l=/* @__PURE__ */ new Map;for(let e of a.querySelectorAll(`:scope > tr.wui-group-row`))e instanceof HTMLTableRowElement&&l.set(e.dataset.groupKey,e);let u=i(o,e=>e.dataset.group??e.cells[r]?.textContent?.trim()??``,this._groupOrder);this._groupOrder=u.map(e=>e.key);let f=c.createDocumentFragment(),p=u.map(e=>{let t=l.get(e.key)??this._groupRow(c,e.key);return l.delete(e.key),b(t.querySelector(`.wui-group-cell`),HTMLTableCellElement).colSpan=n.length,b(t.querySelector(`.wui-group-count`),HTMLElement).textContent=s(e.items.length),b(t.querySelector(`.wui-group-rows`),HTMLElement).textContent=`, ${d.rows(e.items.length)}`,f.append(t,...e.items),[t,e.key]});for(let e of l.values())e.remove();a.insertBefore(f,this._bottom?.parentNode===a?this._bottom:null);for(let[e,t]of p)this._showGroup(e,!this._collapsed.has(t))}_groupRow(e,t){let n=e.createElement(`tr`);n.className=`wui-group-row`,n.dataset.groupKey=t;let r=e.createElement(`th`);r.className=`wui-group-cell`,r.scope=`rowgroup`;let i=e.createElement(`button`);i.type=`button`,i.className=`wui-group-toggle`,i.innerHTML=v;let a=e.createElement(`span`);a.className=`wui-group-label`,a.textContent=t;let o=e.createElement(`span`);o.className=`wui-group-count`,o.setAttribute(`aria-hidden`,`true`);let s=e.createElement(`span`);return s.className=`visually-hidden wui-group-rows`,i.append(a,o,s),r.append(i),n.append(r),n}_showGroup(e,t){if(e){e.querySelector(`.wui-group-toggle`)?.setAttribute(`aria-expanded`,String(t));for(let n=e.nextElementSibling;n&&!n.matches(g);n=n.nextElementSibling)n instanceof HTMLElement&&(n.hidden=!t)}}_spacer(e,t){if(t?.parentNode===e)return t;let n=e.ownerDocument,r=n.createElement(`tr`);return r.className=`wui-virtual-spacer`,r.setAttribute(`aria-hidden`,`true`),r.append(n.createElement(`td`)),r}_virtual(e,t){let n=e.tBodies[0];if(!n)return;if(t){this._top=this._spacer(n,this._top),this._bottom=this._spacer(n,this._bottom),n.firstElementChild!==this._top&&n.insertBefore(this._top,n.firstChild),n.lastElementChild!==this._bottom&&n.append(this._bottom);let t=Math.max(1,this._headCells(e).length);y(this._top.cells[0]).colSpan=t,y(this._bottom.cells[0]).colSpan=t,this._items=[...n.rows].filter(e=>!e.classList.contains(`wui-virtual-spacer`)&&!e.hidden),this._range=null,e.setAttribute(`aria-rowcount`,String(this._items.length+1)),e.tHead?.rows[0]?.setAttribute(`aria-rowindex`,`1`),this._items.forEach((e,t)=>{e.setAttribute(`aria-rowindex`,String(t+2))}),this._rowHeight>0||(this._rowHeight=this._measureRow(e))}let r=e.tHead?.getBoundingClientRect().height||0,i=u({scrollTop:this.scrollTop-r,viewport:this.clientHeight,rowHeight:this._rowHeight,count:this._items.length}),a=this._range;if(a&&a.start===i.start&&a.end===i.end)return;let o=a?Math.min(a.start,i.start):0,s=a?Math.max(a.end,i.end):this._items.length;for(let e=o;e<s;e++){let t=e<i.start||e>=i.end,n=y(this._items[e]);n.classList.contains(`wui-virtual-off`)!==t&&n.classList.toggle(`wui-virtual-off`,t)}this._range=i;let c=y(this._top),l=y(this._bottom);c.hidden=i.before===0,l.hidden=i.after===0,y(c.cells[0]).style.height=`${i.before}px`,y(l.cells[0]).style.height=`${i.after}px`}_measureRow(e){let t=this._items.find(e=>!e.classList.contains(`wui-group-row`)&&!e.classList.contains(`wui-virtual-off`))?.getBoundingClientRect().height??0;return t>0?t:e.classList.contains(`wui-table-compact`)?o.compact:e.classList.contains(`wui-table-cozy`)?o.cozy:o.comfortable}};export{C as t};
1
+ import{C as e,M as t,S as n,T as r,_ as i,b as a,c as o,g as s,h as c,i as l,j as u,r as d,t as f}from"./dataTable-B-7oAeii.js";import{t as p}from"./dom-Do1pAA12.js";import{t as m}from"./elementBase-Cxeyx0tU.js";var h=`.wui-col-resize`,g=`.wui-group-row, .wui-virtual-spacer`,_=`.wui-select-cell, .wui-expand-cell`,v=`<svg class="wui-icon" data-icon="chevron-down" data-wui="AppIcon" width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="1.5" d="M19.92 8.95l-6.52 6.52c-.77.77-2.03.77-2.8 0L4.08 8.95"></path></svg>`;function y(e){if(e==null)throw TypeError(`Missing DOM node`);return e}function b(e,t){if(e instanceof t)return e;throw TypeError(`Missing DOM node`)}var x=e=>{let t=p(e,h);return t instanceof HTMLElement?t:null},S=e=>e.hasAttribute(`data-wui-skeleton`)||!!e.querySelector(`:scope > td > .skeleton`),C=class extends m{_frame;_headDirty;_rowsDirty;_frozenSig;_natural;_widths;_collapsed;_groupOrder;_items;_range;_drag;_userSized;_swallowClick;_mo;_ro;_fonts;_onPointerDown;_onKeyDown;_onClick;_onDblClick;_onScroll;_onFonts;_top=null;_bottom=null;_rowHeight=0;constructor(){super(),this._frame=0,this._headDirty=!0,this._rowsDirty=!0,this._frozenSig=null,this._natural=[],this._widths={},this._collapsed=/* @__PURE__ */ new Set,this._groupOrder=[],this._items=[],this._range=null,this._drag=null,this._userSized=!1,this._swallowClick=!1,this._mo=null,this._ro=null,this._fonts=null,this._onPointerDown=e=>this._startDrag(e),this._onKeyDown=e=>this._key(e),this._onClick=e=>this._click(e),this._onDblClick=e=>{let t=x(e.target);t&&this.contains(t)&&this._reset(t.closest(`th`))},this._onScroll=()=>{this.hasAttribute(`virtual`)&&this._schedule()},this._onFonts=()=>{this._userSized||this._drag||this._frozenSig===null||!this.hasAttribute(`resizable`)||(this._frozenSig=null,this._schedule())}}connectedCallback(){this._widths=r(this.getAttribute(`view-key`)),this.addEventListener(`pointerdown`,this._onPointerDown,!0),this.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick,!0),this.addEventListener(`dblclick`,this._onDblClick),this.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._fonts=this.ownerDocument.fonts??null,this._fonts?.addEventListener(`loadingdone`,this._onFonts),typeof MutationObserver<`u`&&(this._mo=new MutationObserver(e=>this._mutated(e)),this._mo.observe(this,{childList:!0,subtree:!0})),typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(()=>this._schedule()),this._ro.observe(this)),this._headDirty=!0,this._rowsDirty=!0,this._schedule()}disconnectedCallback(){this.removeEventListener(`pointerdown`,this._onPointerDown,!0),this.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick,!0),this.removeEventListener(`dblclick`,this._onDblClick),this.removeEventListener(`scroll`,this._onScroll),this._fonts?.removeEventListener(`loadingdone`,this._onFonts),this._fonts=null,this._mo?.disconnect(),this._ro?.disconnect(),this._mo=null,this._ro=null,this._frame&&cancelAnimationFrame(this._frame),this._frame=0,this._drag=null}refresh(){this._headDirty=!0,this._rowsDirty=!0,this._run()}get _table(){let e=this.querySelector(`:scope > table`);return e instanceof HTMLTableElement?e:null}_headCells(e){let t=e.tHead?.rows[0];return t?[...t.cells]:[]}_schedule(){this._frame||=requestAnimationFrame(()=>{this._frame=0,this._run()})}_mutated(e){for(let t of e){let e=t.target instanceof Element?t.target:t.target.parentElement;e&&((e.closest(`thead`)||e===this._table||e===this)&&(this._headDirty=!0),(e.closest(`tbody, tfoot`)||e===this._table||e===this)&&(this._rowsDirty=!0))}this._schedule()}_run(){let e=this._table;if(!e)return;let t=this._headDirty,n=this._rowsDirty;this._headDirty=!1,this._rowsDirty=!1,n&&this.hasAttribute(`group-by`)&&this._group(e),this._pins(e,t||n),this.hasAttribute(`resizable`)&&(t&&this._handles(e),this._layout(e)),this.hasAttribute(`virtual`)&&this._virtual(e,t||n),this._mo?.takeRecords()}_pins(t,r){let i=this._headCells(t),o=i.map(e=>{let t=e.dataset.pin;return t===`start`||t===`end`?t:e.matches(_)?`lead`:null});if(!o.some(e=>e===`start`||e===`end`))return;let s=e(o);s.forEach((e,t)=>{e&&this._ro?.observe(y(i[t]))});let c=e=>y(i[e]).getBoundingClientRect().width,u=0;s.forEach((e,r)=>{e?.side===`start`&&(this._setVar(t,n(`start`,e.ordinal),u),u+=c(r))}),u=0;for(let e=s.length-1;e>=0;e--){let r=s[e];r?.side===`end`&&(this._setVar(t,n(`end`,r.ordinal),u),u+=c(e))}if(r)for(let e of t.rows)e.matches(`${g}, .wui-row-expanded`)||e.cells.length!==i.length||s.forEach((t,n)=>{if(!t)return;let r=y(e.cells[n]);r.classList.contains(`wui-pin-${t.side}`)||r.classList.add(`wui-pin-${t.side}`),t.edge&&!r.classList.contains(`wui-pin-${t.side}-edge`)&&r.classList.add(`wui-pin-${t.side}-edge`);let i=a(t.side,t.ordinal);r.style.getPropertyValue(`--wui-pin-at`)!==i&&r.style.setProperty(l,i)})}_setVar(e,t,n){let r=`${Math.round(n*100)/100}px`;e.style.getPropertyValue(t)!==r&&e.style.setProperty(t,r)}_resizable(e){return e.map((t,n)=>n<e.length-1&&!t.matches(_))}_handles(e){let t=this._headCells(e),n=this._resizable(t);t.forEach((e,t)=>{if(!n[t]||e.querySelector(h))return;let r=e.ownerDocument.createElement(`span`);r.className=`wui-col-resize`,r.setAttribute(`role`,`separator`),r.setAttribute(`aria-orientation`,`vertical`),r.setAttribute(`aria-valuemin`,`48`),r.setAttribute(`aria-valuemax`,String(f)),r.setAttribute(`tabindex`,`0`);let i=(e.textContent??``).trim();r.setAttribute(`aria-label`,d.resize(i)),i&&!e.hasAttribute(`aria-label`)&&e.setAttribute(`aria-label`,i),e.classList.add(`wui-col-resizable`),e.appendChild(r)})}_hasRows(e){for(let t of e.tBodies)for(let e of t.rows)if(!e.matches(g)&&!S(e))return!0;return!1}_signature(e){return e.map(e=>e.dataset.key||(e.textContent??``).trim()).join(``)}_layout(e){let t=this._headCells(e),n=this._signature(t);t.length&&n!==this._frozenSig&&(this._hasRows(e)?this._freeze(e,t,n):this._applyRemembered(t))}_applyRemembered(e){for(let t of e){let e=t.dataset.key&&this._widths[t.dataset.key];e&&(t.style.width=`${e}px`);let n=t.querySelector(h);n&&this._handleValue(n,c(e||t.getBoundingClientRect().width))}}_freeze(e,t,n){e.style.tableLayout=``,e.style.width=``,e.removeAttribute(`data-wui-fixed`);for(let e of t)e.hasAttribute(`data-wui-width`)&&(e.style.width=``,e.removeAttribute(`data-wui-width`));this._natural=t.map(e=>e.getBoundingClientRect().width),t.forEach((e,n)=>{if(n===t.length-1||e.matches(_))return;let r=e.dataset.key&&this._widths[e.dataset.key];this._setWidth(e,r||this._natural[n])}),e.style.tableLayout=`fixed`,e.setAttribute(`data-wui-fixed`,``),this._frozenSig=n,this._fitTable(e,t)}_setWidth(e,t){let n=c(t);e.style.width=`${n}px`,e.setAttribute(`data-wui-width`,``);let r=e.querySelector(h);return r&&this._handleValue(r,n),n}_handleValue(e,t){e.setAttribute(`aria-valuenow`,String(t)),e.setAttribute(`aria-valuetext`,d.width(t))}_fitTable(e,t){let n=t.length-1,r=this._natural[n]||0;for(let e=0;e<n;e++)r+=Number.parseFloat(y(t[e]).style.width)||this._natural[e]||0;e.style.width=`max(100%, ${Math.round(r)}px)`}_ensureFrozen(e){let t=this._headCells(e),n=this._signature(t);return n!==this._frozenSig&&this._freeze(e,t,n),t}_resizeTo(e,t,n){let r=this._table;if(!r)return;let i=this._ensureFrozen(r);this._userSized=!0,this._setWidth(e,t),this._fitTable(r,i),n&&this._remember(e),this._pins(r,!1)}_remember(e){let n=e.dataset.key;n&&(this._widths={...this._widths,[n]:Number.parseFloat(e.style.width)},t(this.getAttribute(`view-key`),this._widths))}_reset(e){let n=this._table;if(!e||!n)return;let r=this._ensureFrozen(n);this._userSized=!0;let i=e.dataset.key;if(i&&i in this._widths){let{[i]:e,...n}=this._widths;this._widths=n,t(this.getAttribute(`view-key`),this._widths)}this._setWidth(e,this._natural[r.indexOf(e)]||0),this._fitTable(n,r),this._pins(n,!1)}_rtl(){return getComputedStyle(this).direction===`rtl`}_startDrag(e){let t=x(e.target);if(!t||!this.contains(t)||e.button!==0)return;e.preventDefault(),e.stopPropagation();let n=t.closest(`th`),r=this._table;if(!n||!r)return;this._ensureFrozen(r);let i={th:n,x:e.clientX,from:n.getBoundingClientRect().width,dir:this._rtl()?-1:1,moved:!1};this._drag=i,t.setPointerCapture?.(e.pointerId),t.classList.add(`is-dragging`);let a=e=>{let t=(e.clientX-i.x)*i.dir;Math.abs(t)>1&&(i.moved=!0),this._resizeTo(n,i.from+t,!1)},o=e=>{t.removeEventListener(`pointermove`,a),t.removeEventListener(`pointerup`,o),t.removeEventListener(`pointercancel`,o),t.classList.remove(`is-dragging`),this._drag=null,e.type===`pointercancel`?this._resizeTo(n,i.from,!1):i.moved&&this._remember(n),this._swallowClick=!0,setTimeout(()=>{this._swallowClick=!1},0)};t.addEventListener(`pointermove`,a),t.addEventListener(`pointerup`,o),t.addEventListener(`pointercancel`,o)}_key(e){let t=x(e.target);if(!t||!this.contains(t))return;let n=t.closest(`th`);if(e.key===`Enter`||e.key===` `){e.preventDefault(),e.stopPropagation();return}if(e.key===`Home`){e.preventDefault(),e.stopPropagation(),this._reset(n);return}if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let r=this._table;if(!r)return;this._ensureFrozen(r);let i=y(n),a=e.shiftKey?50:10,o=e.key===`ArrowRight`!==this._rtl(),s=Number.parseFloat(i.style.width)||i.getBoundingClientRect().width;this._resizeTo(i,s+(o?a:-a),!0)}_click(e){let t=e.target instanceof Element&&e.target.closest(h)!==null;if(this._swallowClick||t){e.stopPropagation(),(t||this._swallowClick)&&e.preventDefault(),this._swallowClick=!1;return}if(!this.hasAttribute(`group-by`))return;let n=p(e.target,`.wui-group-toggle`)?.closest(`.wui-group-row`);if(!(n instanceof HTMLTableRowElement)||!this.contains(n))return;let r=n.dataset.groupKey;this._collapsed.has(r)?this._collapsed.delete(r):this._collapsed.add(r),this._showGroup(n,!this._collapsed.has(r));let i=this._table;i&&this.hasAttribute(`virtual`)&&(this._virtual(i,!0),this._mo?.takeRecords())}_group(e){let t=this.getAttribute(`group-by`),n=this._headCells(e),r=n.findIndex(e=>e.dataset.key===t);if(r<0)throw Error(`<wui-data-table group-by="${t}"> needs a header cell with data-key="${t}".`);let a=e.tBodies[0];if(!a)return;let o=[...a.rows].filter(e=>!e.matches(g));if(o.some(S))return;let c=this.ownerDocument,l=/* @__PURE__ */ new Map;for(let e of a.querySelectorAll(`:scope > tr.wui-group-row`))e instanceof HTMLTableRowElement&&l.set(e.dataset.groupKey,e);let u=i(o,e=>e.dataset.group??e.cells[r]?.textContent?.trim()??``,this._groupOrder);this._groupOrder=u.map(e=>e.key);let f=c.createDocumentFragment(),p=u.map(e=>{let t=l.get(e.key)??this._groupRow(c,e.key);return l.delete(e.key),b(t.querySelector(`.wui-group-cell`),HTMLTableCellElement).colSpan=n.length,b(t.querySelector(`.wui-group-count`),HTMLElement).textContent=s(e.items.length),b(t.querySelector(`.wui-group-rows`),HTMLElement).textContent=`, ${d.rows(e.items.length)}`,f.append(t,...e.items),[t,e.key]});for(let e of l.values())e.remove();a.insertBefore(f,this._bottom?.parentNode===a?this._bottom:null);for(let[e,t]of p)this._showGroup(e,!this._collapsed.has(t))}_groupRow(e,t){let n=e.createElement(`tr`);n.className=`wui-group-row`,n.dataset.groupKey=t;let r=e.createElement(`th`);r.className=`wui-group-cell`,r.scope=`rowgroup`;let i=e.createElement(`button`);i.type=`button`,i.className=`wui-group-toggle`,i.innerHTML=v;let a=e.createElement(`span`);a.className=`wui-group-label`,a.textContent=t;let o=e.createElement(`span`);o.className=`wui-group-count`,o.setAttribute(`aria-hidden`,`true`);let s=e.createElement(`span`);return s.className=`visually-hidden wui-group-rows`,i.append(a,o,s),r.append(i),n.append(r),n}_showGroup(e,t){if(e){e.querySelector(`.wui-group-toggle`)?.setAttribute(`aria-expanded`,String(t));for(let n=e.nextElementSibling;n&&!n.matches(g);n=n.nextElementSibling)n instanceof HTMLElement&&(n.hidden=!t)}}_spacer(e,t){if(t?.parentNode===e)return t;let n=e.ownerDocument,r=n.createElement(`tr`);return r.className=`wui-virtual-spacer`,r.setAttribute(`aria-hidden`,`true`),r.append(n.createElement(`td`)),r}_virtual(e,t){let n=e.tBodies[0];if(!n)return;if(t){this._top=this._spacer(n,this._top),this._bottom=this._spacer(n,this._bottom),n.firstElementChild!==this._top&&n.insertBefore(this._top,n.firstChild),n.lastElementChild!==this._bottom&&n.append(this._bottom);let t=Math.max(1,this._headCells(e).length);y(this._top.cells[0]).colSpan=t,y(this._bottom.cells[0]).colSpan=t,this._items=[...n.rows].filter(e=>!e.classList.contains(`wui-virtual-spacer`)&&!e.hidden),this._range=null,e.setAttribute(`aria-rowcount`,String(this._items.length+1)),e.tHead?.rows[0]?.setAttribute(`aria-rowindex`,`1`),this._items.forEach((e,t)=>{e.setAttribute(`aria-rowindex`,String(t+2))}),this._rowHeight>0||(this._rowHeight=this._measureRow(e))}let r=e.tHead?.getBoundingClientRect().height||0,i=u({scrollTop:this.scrollTop-r,viewport:this.clientHeight,rowHeight:this._rowHeight,count:this._items.length}),a=this._range;if(a&&a.start===i.start&&a.end===i.end)return;let o=a?Math.min(a.start,i.start):0,s=a?Math.max(a.end,i.end):this._items.length;for(let e=o;e<s;e++){let t=e<i.start||e>=i.end,n=y(this._items[e]);n.classList.contains(`wui-virtual-off`)!==t&&n.classList.toggle(`wui-virtual-off`,t)}this._range=i;let c=y(this._top),l=y(this._bottom);c.hidden=i.before===0,l.hidden=i.after===0,y(c.cells[0]).style.height=`${i.before}px`,y(l.cells[0]).style.height=`${i.after}px`}_measureRow(e){let t=this._items.find(e=>!e.classList.contains(`wui-group-row`)&&!e.classList.contains(`wui-virtual-off`))?.getBoundingClientRect().height??0;return t>0?t:e.classList.contains(`wui-table-compact`)?o.compact:e.classList.contains(`wui-table-cozy`)?o.cozy:o.comfortable}};export{C as t};
@@ -0,0 +1 @@
1
+ import{o as e}from"./calendarMath-D6UUgYTD.js";import{t}from"./elementBase-Cxeyx0tU.js";import"./formatters-ljfITOZ3.js";import{n,r,t as i}from"./inlineEditText-CsLCQbcg.js";import{l as a}from"./wuiHttp-DGbD7Fra.js";var o=e=>r.some(t=>t===e),s=`[data-wui-display]`,c=`[data-wui-value]`,l=`[data-wui-editor]`,u=`[data-wui-control]`,d=`[data-wui-error]`,f=`[data-wui-live]`,p=`[aria-expanded="true"]`,m=/* @__PURE__ */ new Set([`select`,`date`]),h=e=>{let t=(typeof e==`object`||typeof e==`function`)&&e!==null&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:n.failed.server},g=e=>e instanceof HTMLElement&&typeof(`value`in e?e.value:void 0)==`string`,_=(e,t)=>{let n=e?.querySelector(t)??null;return n instanceof HTMLElement?n:null},v=class extends t{_wired;_editing;_busy;_draft;_pressed;_popupOpen;_savedTimer;static get observedAttributes(){return[`disabled`]}constructor(){super(),this._wired=!1,this._editing=!1,this._busy=!1,this._draft=null,this._pressed=!1,this._popupOpen=!1,this._savedTimer=null,this._onClick=this._onClick.bind(this),this._onKeyCapture=this._onKeyCapture.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onChange=this._onChange.bind(this)}connectedCallback(){this._wired||(this._wired=!0,this.addEventListener(`click`,this._onClick),this.addEventListener(`auxclick`,this._onClick),this.addEventListener(`keydown`,this._onKeyCapture,!0),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`focusout`,this._onFocusOut),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`change`,this._onChange))}disconnectedCallback(){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,this._releasePress()}attributeChangedCallback(e){e===`disabled`&&this.hasAttribute(`disabled`)&&this.cancel()}edit(){if(this._editing||this._busy||this.hasAttribute(`disabled`))return;let e=_(this,s),t=_(this,l),n=this._control();e&&t&&n&&(this._editing=!0,this._setState(null),n.value=this._draft??this._value(),t.hidden=!1,this.setAttribute(`data-wui-editing`,``),this._focusControl(n),e.hidden=!0)}cancel(){this._editing&&(this._draft=null,this._setError(null),this.getAttribute(`data-wui-state`)===`error`&&this._setState(null),this._close())}_onClick(e){e.stopPropagation();let t=e.target instanceof Node?e.target:null;e.type===`click`&&!this._editing&&this.querySelector(s)?.contains(t)&&this.edit()}_onKeyCapture(){this._popupOpen=!!(this._editing&&this.querySelector(l)?.querySelector(p))}_onKeyDown(e){if(!this._editing){(e.key===`Enter`||e.key===` `)&&e.stopPropagation();return}if(e.stopPropagation(),this._popupOpen)return;if(e.key===`Escape`){e.preventDefault(),this.cancel();return}let t=this._type();e.key!==`Enter`||m.has(t)||(t!==`textarea`||e.ctrlKey||e.metaKey)&&(e.preventDefault(),this._commit(this._control()?.value??``))}_onFocusOut(e){if(!this._editing||this._pressed)return;let t=e.relatedTarget instanceof Node?e.relatedTarget:null;t&&this.contains(t)||document.hasFocus()&&this._commit(this._control()?.value??``)}_onPointerDown(){this._editing&&(this._pressed=!0,document.addEventListener(`pointerup`,this._onPointerUp,!0),document.addEventListener(`pointercancel`,this._onPointerUp,!0))}_onPointerUp(){this._releasePress(),setTimeout(()=>{this._pressed=!1,this._editing&&!this.contains(document.activeElement)&&document.hasFocus()&&this._commit(this._control()?.value??``)},0)}_releasePress(){document.removeEventListener(`pointerup`,this._onPointerUp,!0),document.removeEventListener(`pointercancel`,this._onPointerUp,!0)}_onChange(e){if(!this._editing||!m.has(this._type()))return;let t=this._control();t&&e.target===t&&queueMicrotask(()=>this._commit(t.value))}async _commit(e){if(!this._editing||this._busy)return;let t=this._value();if(e===t){this.cancel();return}let r=typeof this.validate==`function`?this.validate(e):null;if(r){this._setError(r),this._announce(r);return}let a=this.hasAttribute(`controlled`);this._draft=null,this._setError(null),this._busy=!0,this._setState(`saving`),this.setAttribute(`aria-busy`,`true`);let o=a?null:this._readShown();a||this._showValue(e),this._close();let s=await this._persist(e,a);this._busy=!1,this.removeAttribute(`aria-busy`);let c=this.getAttribute(`label`)||``;s.ok?(this.setAttribute(`value`,e),!a&&s.text&&this._showText(s.text,!1),this._setState(`saved`),this._savedTimer=setTimeout(()=>this._setState(null),i),this._announce(n.saved(c)),this._fire(`wui:inline-edit:saved`,{value:e,previous:t})):(o&&this._restoreShown(o),s.kind===`session`||s.kind===`aborted`?this._setState(null):(this._draft=e,this._setState(`error`),this._setError(s.message),this._announce(n.notSaved(c,s.message)),this._fire(`wui:inline-edit:failed`,{value:e,previous:t,kind:s.kind,message:s.message})))}async _persist(e,t){if(t){if(typeof this.save!=`function`)return{ok:!0};try{return await this.save(e),{ok:!0}}catch(e){return{ok:!1,kind:`server`,message:h(e)}}}let r=this.getAttribute(`action`);if(!r)return{ok:!0};let i=new URLSearchParams({[this.getAttribute(`name`)||`value`]:e}),o=await a(r,{method:`POST`,body:i});if(o.ok)return{ok:!0,text:o.html.trim()};let s=n.failed;return{ok:!1,kind:o.kind,message:o.message||s[o.kind]||n.failed.server}}_close(){let e=_(this,s),t=_(this,l),n=this.contains(document.activeElement);this._editing=!1,this.removeAttribute(`data-wui-editing`),t&&(t.hidden=!0),e&&(e.hidden=!1),_(t,p)?.click(),n&&e?.focus()}_focusControl(e){if(!m.has(this._type())){e.focus(),e.select?.();return}let t=_(e,`button`);t&&(t.focus(),t.getAttribute(`aria-expanded`)!==`true`&&t.click())}_showValue(t){if(t===``){this._showText(this.getAttribute(`placeholder`)||`-`,!0);return}let n=this._type(),r=t;if(n===`date`)r=e(t)||t;else if(n===`select`){let e=[...this._control()?.querySelectorAll(`[data-value]`)??[]].find(e=>e.getAttribute(`data-value`)===t);e&&(r=(e.textContent??``).trim())}this._showText(r,!1)}_readShown(){let e=this.querySelector(c);return e?{html:e.innerHTML,empty:e.hasAttribute(`data-wui-empty`)}:null}_restoreShown(e){let t=this.querySelector(c);t&&(t.innerHTML=e.html,t.toggleAttribute(`data-wui-empty`,e.empty))}_showText(e,t){let n=this.querySelector(c);n&&(n.textContent=e,n.toggleAttribute(`data-wui-empty`,t))}_setError(e){let t=_(this,d),n=this._control();t&&(t.textContent=e||``,t.hidden=!e),e?n?.setAttribute(`aria-invalid`,`true`):n?.removeAttribute(`aria-invalid`)}_setState(e){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,e?this.setAttribute(`data-wui-state`,e):this.removeAttribute(`data-wui-state`)}_announce(e){let t=this.querySelector(f);t&&e&&(t.textContent=``,t.textContent=e)}_fire(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t}))}_control(){let e=this.querySelector(u);return g(e)?e:null}_value(){return this.getAttribute(`value`)??``}_type(){let e=this.getAttribute(`type`);return o(e)?e:`text`}};export{v as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{f as t}from"./formatters-C3V6M5zV.js";import{t as n}from"./iconGlyphs.g-DPqoOoXy.js";var r=`a.wui-lightbox-item`,i=1,a=4,o=.5,s=2,c=50,l=6,u=300,d=300;function f(e){return Number.isFinite(e)?Math.min(a,Math.max(i,e)):i}function p(e,t,n,r){let i=(e,n)=>Math.max(0,(e*t-n)/2),a=i(r.width,n.width),o=i(r.height,n.height);return{x:Math.min(a,Math.max(-a,e.x)),y:Math.min(o,Math.max(-o,e.y))}}function m(e,t){return Math.abs(e)<c||Math.abs(e)<Math.abs(t)*1.5?0:e<0?1:-1}function h(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}function g(e,t,n={}){let r=document.createElement(e);r.className=t;for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r}function _(e,t,r){let i=g(`button`,`u-action wui-lightbox-btn ${r}`,{type:`button`,"aria-label":t,title:t});return i.style.setProperty(`--wui-action-size`,`40px`),i.innerHTML=n(e,{size:20}),i}var v=class extends e{_ui;_index;_zoom;_pan;_pointers;_gesture;_lastTap;_returnTo;_lockedOverflow;_onClick;static get observedAttributes(){return[`open-index`]}constructor(){super(),this._ui=null,this._index=0,this._zoom=i,this._pan={x:0,y:0},this._pointers=/* @__PURE__ */ new Map,this._gesture=null,this._lastTap=-1/0,this._returnTo=null,this._lockedOverflow=null,this._onClick=e=>{if(e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;let t=e.target,n=t instanceof Element?t.closest(r):null;if(!(n instanceof HTMLAnchorElement)||!this.contains(n))return;let i=this._links().indexOf(n);i<0||(e.preventDefault(),this.open(i))}}get _view(){if(!this._ui)throw Error(`<wui-lightbox> viewer is not open.`);return this._ui}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get label(){return this.getAttribute(`label`)||`Image viewer`}set label(e){this.setAttribute(`label`,String(e??``))}get layout(){return this.getAttribute(`layout`)===`single`?`single`:`gallery`}set layout(e){if(e===`single`)this.setAttribute(`layout`,`single`);else if(e===`gallery`||e===``)this.removeAttribute(`layout`);else throw Error(`<wui-lightbox> layout must be "gallery" or "single", received "${e}".`)}get isOpen(){return this._ui!==null}connectedCallback(){this.addEventListener(`click`,this._onClick),this._syncOpenIndex()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this._teardown()}attributeChangedCallback(){this.isConnected&&this._syncOpenIndex()}_syncOpenIndex(){let e=this.getAttribute(`open-index`);e===null?this.close():this.open(Number(e))}_links(){return[...this.querySelectorAll(r)].filter(e=>e instanceof HTMLAnchorElement)}_items(){return this._links().map(e=>{let t=e.getAttribute(`href`)??``;return{link:e,src:t,alt:e.querySelector(`img`)?.getAttribute(`alt`)??``,caption:e.dataset.caption??``,name:e.dataset.name||h(t)}})}open(e=0){let t=this._items();if(!t.length)return!1;if(!this._ui){let t=document.activeElement;this._returnTo=t instanceof HTMLElement||t instanceof SVGElement?t:null,this._build(),this.dispatchEvent(new CustomEvent(`wui-lightbox:open`,{bubbles:!0,detail:{index:e}}))}return this._show(e,t),this._view.close.focus(),!0}close(){if(!this._ui)return;let e=this._index,t=this._links()[e]??this._returnTo;this._teardown(),t?.isConnected&&t.focus(),this._returnTo=null,this.dispatchEvent(new CustomEvent(`wui-lightbox:close`,{bubbles:!0,detail:{index:e}}))}_teardown(){this._ui&&(this._ui.root.remove(),this._ui=null,this._pointers.clear(),this._gesture=null,this._lockedOverflow!==null&&(document.documentElement.style.overflow=this._lockedOverflow,this._lockedOverflow=null))}_build(){let e=g(`div`,`wui-lightbox-overlay`,{role:`dialog`,"aria-modal":`true`,"aria-label":this.label,tabindex:`-1`}),t=g(`div`,`wui-lightbox-bar`),r=g(`span`,`wui-lightbox-count`,{"aria-live":`polite`}),i=g(`div`,`wui-lightbox-tools`),a=_(`zoom-out`,`Zoom out`,`wui-lightbox-zoom-out`),s=_(`zoom-in`,`Zoom in`,`wui-lightbox-zoom-in`),c=g(`a`,`u-action wui-lightbox-btn wui-lightbox-download`,{"aria-label":`Download`,title:`Download`});c.style.setProperty(`--wui-action-size`,`40px`),c.innerHTML=n(`download`,{size:20}),c.hidden=!this.download;let l=_(`x`,`Close`,`wui-lightbox-close`);i.append(a,s,c,l),t.append(r,i);let u=g(`div`,`wui-lightbox-stage`),d=_(`chevron-left`,`Previous image`,`wui-lightbox-nav wui-lightbox-prev`),f=_(`chevron-right`,`Next image`,`wui-lightbox-nav wui-lightbox-next`),p=g(`img`,`wui-lightbox-image`,{decoding:`async`,draggable:`false`,alt:``}),m=g(`p`,`wui-lightbox-status`,{role:`status`});u.append(p,m,d,f);let h=g(`p`,`wui-lightbox-caption`);e.append(t,u,h);let v={root:e,count:r,zoomOut:a,zoomIn:s,download:c,close:l,stage:u,prev:d,next:f,image:p,status:m,caption:h};this._ui=v,l.addEventListener(`click`,()=>this.close()),d.addEventListener(`click`,()=>this.step(-1)),f.addEventListener(`click`,()=>this.step(1)),a.addEventListener(`click`,()=>this._setZoom(this._zoom-o)),s.addEventListener(`click`,()=>this._setZoom(this._zoom+o)),e.addEventListener(`keydown`,e=>this._onKeyDown(e)),u.addEventListener(`pointerdown`,e=>this._onPointerDown(e)),u.addEventListener(`pointermove`,e=>this._onPointerMove(e)),u.addEventListener(`pointerup`,e=>this._onPointerEnd(e,!0)),u.addEventListener(`pointercancel`,e=>this._onPointerEnd(e,!1)),u.addEventListener(`wheel`,e=>this._onWheel(e),{passive:!1}),p.addEventListener(`load`,()=>{this._ui===v&&(m.textContent=``,u.removeAttribute(`aria-busy`),p.hidden=!1,this._applyTransform())}),p.addEventListener(`error`,()=>{this._ui===v&&(u.removeAttribute(`aria-busy`),p.hidden=!0,m.textContent=`This image can't be shown.`)}),this.append(e),this._lockedOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`}step(e){if(!this._ui||!e)return;let t=this._items();t.length<2||this._show((this._index+e+t.length)%t.length,t)}_show(e,n){let r=this._view,a=Math.min(n.length-1,Math.max(0,Math.trunc(Number(e))||0)),o=n[a];if(!o)throw Error(`<wui-lightbox> image missing.`);let s=a!==this._index||!r.image.getAttribute(`src`);if(this._index=a,this._zoom=i,this._pan={x:0,y:0},r.count.textContent=`${t(a+1,{decimals:0})} of ${t(n.length,{decimals:0})}`,r.caption.textContent=o.caption,r.caption.hidden=!o.caption,r.download.href=o.src,r.download.setAttribute(`download`,o.name),r.prev.hidden=r.next.hidden=n.length<2,r.stage.setAttribute(`aria-busy`,`true`),r.status.textContent=``,r.image.hidden=!1,r.image.alt=o.alt||o.caption,r.image.src=o.src,this._applyTransform(),this._syncZoomButtons(),n.length>1){let e=n[(a+1)%n.length],t=n[(a-1+n.length)%n.length];if(!e||!t)throw Error(`<wui-lightbox> neighbour image missing.`);for(let n of[e,t])new Image().src=n.src}s&&this.dispatchEvent(new CustomEvent(`wui-lightbox:change`,{bubbles:!0,detail:{index:a}}))}_syncZoomButtons(){let e=this._view;e.zoomOut.disabled=this._zoom<=i,e.zoomIn.disabled=this._zoom>=a;let t=document.activeElement;(t===e.zoomOut||t===e.zoomIn)&&t instanceof HTMLButtonElement&&t.disabled&&e.close.focus()}_setZoom(e){this._ui&&(this._zoom=f(e),this._pan=this._clampedPan(this._pan),this._applyTransform(),this._syncZoomButtons())}_clampedPan(e){let{stage:t,image:n}=this._view;return p(e,this._zoom,{width:t.clientWidth,height:t.clientHeight},{width:n.offsetWidth,height:n.offsetHeight})}_applyTransform(){let{image:e,stage:t}=this._view;e.style.transform=`translate(${this._pan.x}px, ${this._pan.y}px) scale(${this._zoom})`,t.classList.toggle(`wui-lightbox-zoomed`,this._zoom>i)}_onKeyDown(e){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),this.close();else if(e.key===`Tab`)this._trapTab(e);else if(e.key===`ArrowLeft`||e.key===`ArrowRight`)e.preventDefault(),this.step(e.key===`ArrowRight`?1:-1);else if(e.key===`Home`||e.key===`End`){e.preventDefault();let t=this._items();this._show(e.key===`Home`?0:t.length-1,t)}else e.key===`+`||e.key===`=`?(e.preventDefault(),this._setZoom(this._zoom+o)):e.key===`-`?(e.preventDefault(),this._setZoom(this._zoom-o)):e.key===`0`&&(e.preventDefault(),this._setZoom(i))}_trapTab(e){let t=this._view.root,n=[...t.querySelectorAll(`button, a[href]`)].filter(e=>e instanceof HTMLElement&&!e.hidden&&!(e instanceof HTMLButtonElement&&e.disabled));if(!n.length){e.preventDefault();return}let r=n[0],i=n[n.length-1];if(!r||!i)throw Error(`<wui-lightbox> focus stops missing.`);let a=document.activeElement;e.shiftKey&&(a===r||!t.contains(a))?(e.preventDefault(),i.focus()):e.shiftKey||a!==i&&t.contains(a)||(e.preventDefault(),r.focus())}_onWheel(e){e.preventDefault(),this._setZoom(this._zoom*(e.deltaY<0?1.15:1/1.15))}_onPointerDown(e){let t=e.target;if(t instanceof Element&&t.closest(`.wui-lightbox-nav`))return;let n=this._view;if(n.stage.setPointerCapture?.(e.pointerId),this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this._pointers.size===2){let e=[...this._pointers.values()],t=e[0],n=e[1];if(!t||!n)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._gesture={kind:`pinch`,distance:Math.hypot(t.x-n.x,t.y-n.y)||1,zoom:this._zoom}}else this._pointers.size===1&&(this._gesture={kind:`drag`,startX:e.clientX,startY:e.clientY,startTime:e.timeStamp,pan:{...this._pan},onImage:e.target===n.image,moved:!1})}_onPointerMove(e){let t=this._gesture;if(t&&this._pointers.has(e.pointerId)){if(this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.kind===`pinch`&&this._pointers.size===2){let e=[...this._pointers.values()],n=e[0],r=e[1];if(!n||!r)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._setZoom(t.zoom*Math.hypot(n.x-r.x,n.y-r.y)/t.distance)}else if(t.kind===`drag`){let n=e.clientX-t.startX,r=e.clientY-t.startY;Math.hypot(n,r)>l&&(t.moved=!0),this._zoom>i&&(this._pan=this._clampedPan({x:t.pan.x+n,y:t.pan.y+r}),this._view.stage.classList.add(`is-dragging`),this._applyTransform())}}}_onPointerEnd(e,t){let n=this._gesture;if(this._pointers.delete(e.pointerId),this._ui?.stage.classList.remove(`is-dragging`),!n)return;if(n.kind===`pinch`){this._pointers.size<2&&(this._gesture=null);return}if(this._gesture=null,!t)return;let r=e.clientX-n.startX,a=e.clientY-n.startY;n.moved?this._zoom===i&&this.step(m(r,a)):e.timeStamp-n.startTime>u||(n.onImage?e.timeStamp-this._lastTap<d?(this._lastTap=-1/0,this._setZoom(this._zoom>i?i:s)):this._lastTap=e.timeStamp:this.close())}};export{v as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{f as t}from"./formatters-ljfITOZ3.js";import{t as n}from"./iconGlyphs.g-DPqoOoXy.js";var r=`a.wui-lightbox-item`,i=1,a=4,o=.5,s=2,c=50,l=6,u=300,d=300;function f(e){return Number.isFinite(e)?Math.min(a,Math.max(i,e)):i}function p(e,t,n,r){let i=(e,n)=>Math.max(0,(e*t-n)/2),a=i(r.width,n.width),o=i(r.height,n.height);return{x:Math.min(a,Math.max(-a,e.x)),y:Math.min(o,Math.max(-o,e.y))}}function m(e,t){return Math.abs(e)<c||Math.abs(e)<Math.abs(t)*1.5?0:e<0?1:-1}function h(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}function g(e,t,n={}){let r=document.createElement(e);r.className=t;for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r}function _(e,t,r){let i=g(`button`,`u-action wui-lightbox-btn ${r}`,{type:`button`,"aria-label":t,title:t});return i.style.setProperty(`--wui-action-size`,`40px`),i.innerHTML=n(e,{size:20}),i}var v=class extends e{_ui;_index;_zoom;_pan;_pointers;_gesture;_lastTap;_returnTo;_lockedOverflow;_onClick;static get observedAttributes(){return[`open-index`]}constructor(){super(),this._ui=null,this._index=0,this._zoom=i,this._pan={x:0,y:0},this._pointers=/* @__PURE__ */ new Map,this._gesture=null,this._lastTap=-1/0,this._returnTo=null,this._lockedOverflow=null,this._onClick=e=>{if(e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;let t=e.target,n=t instanceof Element?t.closest(r):null;if(!(n instanceof HTMLAnchorElement)||!this.contains(n))return;let i=this._links().indexOf(n);i<0||(e.preventDefault(),this.open(i))}}get _view(){if(!this._ui)throw Error(`<wui-lightbox> viewer is not open.`);return this._ui}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get label(){return this.getAttribute(`label`)||`Image viewer`}set label(e){this.setAttribute(`label`,String(e??``))}get layout(){return this.getAttribute(`layout`)===`single`?`single`:`gallery`}set layout(e){if(e===`single`)this.setAttribute(`layout`,`single`);else if(e===`gallery`||e===``)this.removeAttribute(`layout`);else throw Error(`<wui-lightbox> layout must be "gallery" or "single", received "${e}".`)}get isOpen(){return this._ui!==null}connectedCallback(){this.addEventListener(`click`,this._onClick),this._syncOpenIndex()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this._teardown()}attributeChangedCallback(){this.isConnected&&this._syncOpenIndex()}_syncOpenIndex(){let e=this.getAttribute(`open-index`);e===null?this.close():this.open(Number(e))}_links(){return[...this.querySelectorAll(r)].filter(e=>e instanceof HTMLAnchorElement)}_items(){return this._links().map(e=>{let t=e.getAttribute(`href`)??``;return{link:e,src:t,alt:e.querySelector(`img`)?.getAttribute(`alt`)??``,caption:e.dataset.caption??``,name:e.dataset.name||h(t)}})}open(e=0){let t=this._items();if(!t.length)return!1;if(!this._ui){let t=document.activeElement;this._returnTo=t instanceof HTMLElement||t instanceof SVGElement?t:null,this._build(),this.dispatchEvent(new CustomEvent(`wui-lightbox:open`,{bubbles:!0,detail:{index:e}}))}return this._show(e,t),this._view.close.focus(),!0}close(){if(!this._ui)return;let e=this._index,t=this._links()[e]??this._returnTo;this._teardown(),t?.isConnected&&t.focus(),this._returnTo=null,this.dispatchEvent(new CustomEvent(`wui-lightbox:close`,{bubbles:!0,detail:{index:e}}))}_teardown(){this._ui&&(this._ui.root.remove(),this._ui=null,this._pointers.clear(),this._gesture=null,this._lockedOverflow!==null&&(document.documentElement.style.overflow=this._lockedOverflow,this._lockedOverflow=null))}_build(){let e=g(`div`,`wui-lightbox-overlay`,{role:`dialog`,"aria-modal":`true`,"aria-label":this.label,tabindex:`-1`}),t=g(`div`,`wui-lightbox-bar`),r=g(`span`,`wui-lightbox-count`,{"aria-live":`polite`}),i=g(`div`,`wui-lightbox-tools`),a=_(`zoom-out`,`Zoom out`,`wui-lightbox-zoom-out`),s=_(`zoom-in`,`Zoom in`,`wui-lightbox-zoom-in`),c=g(`a`,`u-action wui-lightbox-btn wui-lightbox-download`,{"aria-label":`Download`,title:`Download`});c.style.setProperty(`--wui-action-size`,`40px`),c.innerHTML=n(`download`,{size:20}),c.hidden=!this.download;let l=_(`x`,`Close`,`wui-lightbox-close`);i.append(a,s,c,l),t.append(r,i);let u=g(`div`,`wui-lightbox-stage`),d=_(`chevron-left`,`Previous image`,`wui-lightbox-nav wui-lightbox-prev`),f=_(`chevron-right`,`Next image`,`wui-lightbox-nav wui-lightbox-next`),p=g(`img`,`wui-lightbox-image`,{decoding:`async`,draggable:`false`,alt:``}),m=g(`p`,`wui-lightbox-status`,{role:`status`});u.append(p,m,d,f);let h=g(`p`,`wui-lightbox-caption`);e.append(t,u,h);let v={root:e,count:r,zoomOut:a,zoomIn:s,download:c,close:l,stage:u,prev:d,next:f,image:p,status:m,caption:h};this._ui=v,l.addEventListener(`click`,()=>this.close()),d.addEventListener(`click`,()=>this.step(-1)),f.addEventListener(`click`,()=>this.step(1)),a.addEventListener(`click`,()=>this._setZoom(this._zoom-o)),s.addEventListener(`click`,()=>this._setZoom(this._zoom+o)),e.addEventListener(`keydown`,e=>this._onKeyDown(e)),u.addEventListener(`pointerdown`,e=>this._onPointerDown(e)),u.addEventListener(`pointermove`,e=>this._onPointerMove(e)),u.addEventListener(`pointerup`,e=>this._onPointerEnd(e,!0)),u.addEventListener(`pointercancel`,e=>this._onPointerEnd(e,!1)),u.addEventListener(`wheel`,e=>this._onWheel(e),{passive:!1}),p.addEventListener(`load`,()=>{this._ui===v&&(m.textContent=``,u.removeAttribute(`aria-busy`),p.hidden=!1,this._applyTransform())}),p.addEventListener(`error`,()=>{this._ui===v&&(u.removeAttribute(`aria-busy`),p.hidden=!0,m.textContent=`This image can't be shown.`)}),this.append(e),this._lockedOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`}step(e){if(!this._ui||!e)return;let t=this._items();t.length<2||this._show((this._index+e+t.length)%t.length,t)}_show(e,n){let r=this._view,a=Math.min(n.length-1,Math.max(0,Math.trunc(Number(e))||0)),o=n[a];if(!o)throw Error(`<wui-lightbox> image missing.`);let s=a!==this._index||!r.image.getAttribute(`src`);if(this._index=a,this._zoom=i,this._pan={x:0,y:0},r.count.textContent=`${t(a+1,{decimals:0})} of ${t(n.length,{decimals:0})}`,r.caption.textContent=o.caption,r.caption.hidden=!o.caption,r.download.href=o.src,r.download.setAttribute(`download`,o.name),r.prev.hidden=r.next.hidden=n.length<2,r.stage.setAttribute(`aria-busy`,`true`),r.status.textContent=``,r.image.hidden=!1,r.image.alt=o.alt||o.caption,r.image.src=o.src,this._applyTransform(),this._syncZoomButtons(),n.length>1){let e=n[(a+1)%n.length],t=n[(a-1+n.length)%n.length];if(!e||!t)throw Error(`<wui-lightbox> neighbour image missing.`);for(let n of[e,t])new Image().src=n.src}s&&this.dispatchEvent(new CustomEvent(`wui-lightbox:change`,{bubbles:!0,detail:{index:a}}))}_syncZoomButtons(){let e=this._view;e.zoomOut.disabled=this._zoom<=i,e.zoomIn.disabled=this._zoom>=a;let t=document.activeElement;(t===e.zoomOut||t===e.zoomIn)&&t instanceof HTMLButtonElement&&t.disabled&&e.close.focus()}_setZoom(e){this._ui&&(this._zoom=f(e),this._pan=this._clampedPan(this._pan),this._applyTransform(),this._syncZoomButtons())}_clampedPan(e){let{stage:t,image:n}=this._view;return p(e,this._zoom,{width:t.clientWidth,height:t.clientHeight},{width:n.offsetWidth,height:n.offsetHeight})}_applyTransform(){let{image:e,stage:t}=this._view;e.style.transform=`translate(${this._pan.x}px, ${this._pan.y}px) scale(${this._zoom})`,t.classList.toggle(`wui-lightbox-zoomed`,this._zoom>i)}_onKeyDown(e){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),this.close();else if(e.key===`Tab`)this._trapTab(e);else if(e.key===`ArrowLeft`||e.key===`ArrowRight`)e.preventDefault(),this.step(e.key===`ArrowRight`?1:-1);else if(e.key===`Home`||e.key===`End`){e.preventDefault();let t=this._items();this._show(e.key===`Home`?0:t.length-1,t)}else e.key===`+`||e.key===`=`?(e.preventDefault(),this._setZoom(this._zoom+o)):e.key===`-`?(e.preventDefault(),this._setZoom(this._zoom-o)):e.key===`0`&&(e.preventDefault(),this._setZoom(i))}_trapTab(e){let t=this._view.root,n=[...t.querySelectorAll(`button, a[href]`)].filter(e=>e instanceof HTMLElement&&!e.hidden&&!(e instanceof HTMLButtonElement&&e.disabled));if(!n.length){e.preventDefault();return}let r=n[0],i=n[n.length-1];if(!r||!i)throw Error(`<wui-lightbox> focus stops missing.`);let a=document.activeElement;e.shiftKey&&(a===r||!t.contains(a))?(e.preventDefault(),i.focus()):e.shiftKey||a!==i&&t.contains(a)||(e.preventDefault(),r.focus())}_onWheel(e){e.preventDefault(),this._setZoom(this._zoom*(e.deltaY<0?1.15:1/1.15))}_onPointerDown(e){let t=e.target;if(t instanceof Element&&t.closest(`.wui-lightbox-nav`))return;let n=this._view;if(n.stage.setPointerCapture?.(e.pointerId),this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this._pointers.size===2){let e=[...this._pointers.values()],t=e[0],n=e[1];if(!t||!n)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._gesture={kind:`pinch`,distance:Math.hypot(t.x-n.x,t.y-n.y)||1,zoom:this._zoom}}else this._pointers.size===1&&(this._gesture={kind:`drag`,startX:e.clientX,startY:e.clientY,startTime:e.timeStamp,pan:{...this._pan},onImage:e.target===n.image,moved:!1})}_onPointerMove(e){let t=this._gesture;if(t&&this._pointers.has(e.pointerId)){if(this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.kind===`pinch`&&this._pointers.size===2){let e=[...this._pointers.values()],n=e[0],r=e[1];if(!n||!r)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._setZoom(t.zoom*Math.hypot(n.x-r.x,n.y-r.y)/t.distance)}else if(t.kind===`drag`){let n=e.clientX-t.startX,r=e.clientY-t.startY;Math.hypot(n,r)>l&&(t.moved=!0),this._zoom>i&&(this._pan=this._clampedPan({x:t.pan.x+n,y:t.pan.y+r}),this._view.stage.classList.add(`is-dragging`),this._applyTransform())}}}_onPointerEnd(e,t){let n=this._gesture;if(this._pointers.delete(e.pointerId),this._ui?.stage.classList.remove(`is-dragging`),!n)return;if(n.kind===`pinch`){this._pointers.size<2&&(this._gesture=null);return}if(this._gesture=null,!t)return;let r=e.clientX-n.startX,a=e.clientY-n.startY;n.moved?this._zoom===i&&this.step(m(r,a)):e.timeStamp-n.startTime>u||(n.onImage?e.timeStamp-this._lastTap<d?(this._lastTap=-1/0,this._setZoom(this._zoom>i?i:s)):this._lastTap=e.timeStamp:this.close())}};export{v as t};
@@ -1,4 +1,4 @@
1
1
  import{t as e}from"./elementBase-Cxeyx0tU.js";var t=/\[([^[\]\n]+)\](?!\()/g,n=/* @__PURE__ */ new Set(`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`),r=/\[([^\]\n]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,i=/!\[([^\]\n]*)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,a=new RegExp(t.source,`y`),o=e=>/[\p{L}\p{N}]/u.test(e);function s(e,t){let n=0;for(let r=t-1;r>=0&&e.charAt(r)===`\\`;--r)n+=1;return n%2==1}function c(e,t,n){let r=n.length===1;for(let i=e.indexOf(n,t);i!==-1;i=e.indexOf(n,i+1)){let a=i>t&&!/\s/.test(e.charAt(t))&&!/\s/.test(e.charAt(i-1)),c=r&&(e.charAt(i+1)===n||e.charAt(i-1)===n),l=n===`_`&&o(e.charAt(i+n.length));if(a&&!c&&!l&&!s(e,i))return i}return-1}function l(e,t){let s=t?.isCitation,u=[],d=``,f=()=>{d&&=(u.push({type:`text`,text:d}),``)},p=0;for(;p<e.length;){let m=e.charAt(p),h=e.charAt(p+1);if(m===`\\`&&n.has(h)){d+=h,p+=2;continue}if(m==="`"){let t=e.indexOf("`",p+1);if(t>p+1){f(),u.push({type:`code`,text:e.slice(p+1,t)}),p=t+1;continue}}let g=m+h;if(g===`**`||g===`__`||g===`~~`){let n=c(e,p+2,g);if(n!==-1&&!(g===`__`&&o(e.charAt(p-1)))){f();let r=l(e.slice(p+2,n),t);g===`~~`?u.push({type:`strike`,children:r}):u.push({type:`strong`,children:r}),p=n+2;continue}d+=g,p+=2}else{if(m===`*`||m===`_`){let n=c(e,p+1,m);if(n!==-1&&!(m===`_`&&o(e.charAt(p-1)))){f(),u.push({type:`em`,children:l(e.slice(p+1,n),t)}),p=n+1;continue}}if(m===`[`){r.lastIndex=p;let t=r.exec(e);if(t){let e=t[1],n=t[2];if(e===void 0||n===void 0)throw Error(`The link pattern always captures its label and href`);f(),u.push({type:`link`,href:n,children:l(e)}),p+=t[0].length;continue}if(s){a.lastIndex=p;let t=a.exec(e);if(t){let e=t[1];if(e===void 0)throw Error(`The citation pattern always captures its inner text`);if(s(e)){f(),u.push({type:`citation`,text:e}),p+=t[0].length;continue}}}}if(m===`!`){i.lastIndex=p;let t=i.exec(e);if(t){let e=t[1];if(e===void 0)throw Error(`The image pattern always captures its alt text`);f(),u.push({type:`image`,children:l(e)}),p+=t[0].length;continue}}d+=m,p+=1}}return f(),u.map((e,t)=>({...e,key:t}))}var u=/^[a-z][a-z0-9+.-]*:[a-z0-9_-]+\/[a-z0-9_.~-]+$/i,d=/^https?:/i,f=/^(mailto|tel):/i,p=/^(?:\/(?![/\\])|#|\?|\.{1,2}\/)/,m=/^https:\/\/[^/?#@\\\s]+$/i,h=/^[a-z][a-z0-9+.-]*:/i;function g(e){if(typeof e!=`string`)return null;let t=e.endsWith(`/`)?e.slice(0,-1):e;return m.test(t)?t:null}function ee(e,t,n,r,i){if(n&&(t===`page`||u.test(e))){let t=n(e);if(t!=null)return{kind:`app`,target:t}}if(t===`app`)return null;let a=i==null?null:g(i),o=a===null?e:_(e,a);return o===null?null:p.test(o)?{kind:`page`,href:o}:t===`page`&&!(d.test(o)&&r&&y(o,r))?null:d.test(o)?{kind:r&&y(o,r)?`page`:`web`,href:o}:f.test(o)?{kind:`contact`,href:o}:null}function _(e,t){if(h.test(e))return e;if(e.startsWith(`//`))return`https:${e}`;if(e===``)return null;let n=e.indexOf(`#`),r=n<0?``:e.slice(n),i=n<0?e:e.slice(0,n),a=i.indexOf(`?`),o=a<0?i:i.slice(0,a),s=a<0?``:i.slice(a);return o===``?`${t}${s}${r}`:`${t}${v(o.startsWith(`/`)?o:`/${o}`)}${s}${r}`}function v(e){let t=e.split(`/`),n=[];return t.forEach((e,r)=>{let i=r===t.length-1;e===`.`?i&&n.push(``):e===`..`?(n.length>1&&n.pop(),i&&n.push(``)):n.push(e)}),n.join(`/`)}function y(e,t){if(e.slice(0,t.length).toLowerCase()!==t.toLowerCase())return!1;let n=e[t.length];return n===void 0||n===`/`||n===`?`||n===`#`}function b(e){return typeof e!=`string`||!e.startsWith(`/`)||e[1]===`/`||e[1]===`\\`?null:e}var x=/^\s*```/,S=/^\s*```\s*(\S*)/,C=/^\s{0,3}(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/,w=/^\s*([-*_])(\s*\1){2,}\s*$/,T=/^(\s*)[-*+]\s+(.*)$/,E=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,D=/^\s*>\s?(.*)$/,O=/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/,k=[1,2,3,4,5,6],A=e=>e.includes(`|`);function j(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}function M(e,t){let n=e[t];if(n===void 0)throw Error(`startsTable was called past the last source line`);let r=e[t+1];return r!==void 0&&A(n)&&r.includes(`|`)&&O.test(r)}function N(e,t){let n=e[t];if(n===void 0)throw Error(`startsBlock was called past the last source line`);return x.test(n)||D.test(n)||T.test(n)||E.test(n)||C.test(n)||w.test(n)||M(e,t)}function P(e){let t=e.replace(/\t/g,` `).length;return Math.min(Math.floor(t/2),4)}function F(e){let t=E.exec(e);if(t){let e=t[1],n=t[2],r=t[3];if(e===void 0||n===void 0||r===void 0)throw Error(`The ordered list pattern always captures its indent, number and text`);return{text:r,depth:P(e),ordered:!0,number:Number(n)}}let n=T.exec(e);if(n){let e=n[1],t=n[2];if(e===void 0||t===void 0)throw Error(`The bullet list pattern always captures its indent and text`);return{text:t,depth:P(e),ordered:!1,number:0}}return null}function I(e){let t=(e??``).replace(/\r\n?/g,`
2
2
  `).split(`
3
3
  `),n=[],r=0;for(;r<t.length;){let e=t[r];if(e===void 0)throw Error(`parseMarkdown read past the last source line`);if(!e.trim()){r+=1;continue}if(x.test(e)){let i=S.exec(e)?.[1]||null,a=[];for(r+=1;r<t.length;){let e=t[r];if(e===void 0)throw Error(`parseMarkdown read past the last source line`);if(x.test(e))break;a.push(e),r+=1}r+=1,n.push({type:`code`,text:a.join(`
4
- `),language:i});continue}if(M(t,r)){let i=j(e),a=[];for(r+=2;r<t.length;){let e=t[r];if(e===void 0)throw Error(`parseMarkdown read past the last source line`);if(!e.trim()||!A(e))break;a.push(j(e)),r+=1}n.push({type:`table`,header:i,rows:a});continue}if(w.test(e)){n.push({type:`rule`}),r+=1;continue}let i=C.exec(e);if(i){let e=i[1],t=i[2];if(e===void 0||t===void 0)throw Error(`The heading pattern always captures its hashes and text`);let a=k[e.length-1];if(a===void 0)throw Error(`The heading pattern always captures one to six hashes`);n.push({type:`heading`,level:a,text:t}),r+=1;continue}if(D.test(e)){let e=[];for(;r<t.length;){let n=t[r];if(n===void 0)throw Error(`parseMarkdown read past the last source line`);let i=D.exec(n);if(!i)break;let a=i[1];if(a===void 0)throw Error(`The quote pattern always captures its text`);e.push(a),r+=1}n.push({type:`quote`,lines:e});continue}let a=F(e);if(a){let e=[];for(;r<t.length;){let n=t[r];if(n===void 0)throw Error(`parseMarkdown read past the last source line`);if(!n.trim())break;let i=F(n);if(i){if(i.depth===0&&i.ordered!==a.ordered)break;e.push(i)}else if(N(t,r))break;else{let t=e[e.length-1];if(t===void 0)throw Error(`A list continuation line follows a list with no item`);t.text+=` ${n.trim()}`}r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length;){let e=t[r];if(e===void 0)throw Error(`parseMarkdown read past the last source line`);if(!e.trim()||N(t,r))break;o.push(e),r+=1}n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var L=[`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`],R=[`app`,`web`,`page`],z=e=>e!==void 0&&R.includes(e);function B(e,t,n,r,i=null){let a=V(e.ownerDocument,n,r).map((e,n)=>{let r=t[n],i=r?.sig===e.sig?r.nodes:null;return{sig:e.sig,nodes:i??e.build()}}),o=new Set(a.flatMap(e=>e.nodes));for(let e of t)for(let t of e.nodes)o.has(t)||t.parentNode?.removeChild(t);let s=i;for(let t of a.flatMap(e=>e.nodes))(t.parentNode!==e||t.previousSibling!==s)&&e.insertBefore(t,s?s.nextSibling:e.firstChild),s=t;return a}function V(e,t,n){let r={doc:e,links:z(n.links)?n.links:`web`,headings:n.headings===`text`?`text`:`outline`,resolveLink:n.resolveLink,isCitation:n.isCitation,figureText:typeof n.figureText==`function`?n.figureText:void 0,base:typeof n.base==`string`?n.base:void 0},i=n.resolverGeneration??0;return I(t).map(e=>({sig:`${JSON.stringify(e)}|${r.links}|${r.headings}|${r.base??``}|${i}`,build:()=>W(r,e)}))}var H=class extends e{_drawn;_blocks;_observer;_connected;_resolveLink;_isCitation;_resolverGeneration;_figureText;static get observedAttributes(){return[`links`,`headings`,`base`]}constructor(){super(),this._drawn=[],this._blocks=[],this._observer=null,this._connected=!1,this._resolveLink=void 0,this._isCitation=void 0,this._resolverGeneration=0,this._figureText=void 0}connectedCallback(){this._connected=!0,this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._drawn.some(t=>t.contains(e.target)))&&this._render()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._connected=!1,this._observer?.disconnect(),this._observer=null}get resolveLink(){return this._resolveLink}set resolveLink(e){this._resolveLink=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}get base(){return this.getAttribute(`base`)??void 0}set base(e){e==null?this.removeAttribute(`base`):this.setAttribute(`base`,String(e))}get isCitation(){return this._isCitation}set isCitation(e){this._isCitation=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}get figureText(){return this._figureText}set figureText(e){this._figureText=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}attributeChangedCallback(e,t,n){t!==n&&this._connected&&this._render()}_source(){return Array.from(this.children).find(e=>e instanceof HTMLPreElement&&e.classList.contains(`wui-markdown-source`))}_render(){let e=this._source();e&&(this._blocks=B(this,this._blocks,e.textContent??``,{links:this.getAttribute(`links`)??void 0,headings:this.getAttribute(`headings`)??void 0,base:this.getAttribute(`base`)??void 0,resolveLink:this._resolveLink,isCitation:this._isCitation,figureText:this._figureText,resolverGeneration:this._resolverGeneration},e),this._drawn=this._blocks.flatMap(e=>e.nodes),e.hidden=!0,this._observer?.takeRecords())}};function U(e,t,n=[]){let r=e.createElement(t);return r.append(...n),r}function W(e,t){switch(t.type){case`paragraph`:return[U(e.doc,`p`,G(e,t.lines))];case`heading`:return[K(e,t)];case`list`:return q(e,t.items);case`table`:return[Y(e,t)];case`code`:return[X(e.doc,t)];case`quote`:return[U(e.doc,`blockquote`,G(e,t.lines))];case`rule`:return[e.doc.createElement(`hr`)];default:return[]}}function G(e,t){let n=[];return t.forEach((t,r)=>{r>0&&n.push(e.doc.createElement(`br`)),n.push(...Z(e,t))}),n}function K(e,t){let n=Z(e,t.text);if(e.headings===`text`){let t=U(e.doc,`p`,n);return t.className=`fw-semibold`,t}return U(e.doc,`h2`,n)}function q(e,t){let n=[];for(let r=0;r<t.length;){let i=J(e,t,r);n.push(i.list),r=i.next}return n}function J(e,t,n){let r=t[n];if(!r)throw Error(`List run starts past its items.`);let{depth:i,ordered:a,number:o}=r,s=e.doc.createElement(a?`ol`:`ul`);a&&o!==1&&s.setAttribute(`start`,String(o));let c=null,l=n,u=t[l];for(;u&&u.depth>=i;){if(u.depth===i)c=U(e.doc,`li`,Z(e,u.text)),s.append(c),l+=1;else{let n=J(e,t,l);if(!c)throw Error(`Nested list has no item before it.`);c.append(n.list),l=n.next}u=t[l]}return{list:s,next:l}}function Y(e,t){let n=t.header.map(t=>{let n=U(e.doc,`th`,Z(e,t));return n.setAttribute(`scope`,`col`),n}),r=t.rows.map(n=>U(e.doc,`tr`,t.header.map((t,r)=>U(e.doc,`td`,Z(e,n[r]??``))))),i=U(e.doc,`table`,[U(e.doc,`thead`,[U(e.doc,`tr`,n)]),U(e.doc,`tbody`,r)]);i.className=`table`;let a=U(e.doc,`div`,[i]);return a.className=`table-responsive`,a}function X(e,t){let n=U(e,`pre`,[U(e,`code`,[e.createTextNode(t.text)])]);n.className=`wui-code-source`;let r=U(e,`wui-code-block`,[n]);return r.className=`wui-code-block`,r.setAttribute(`language`,t.language!==null&&L.includes(t.language)?t.language:`text`),r}function Z(e,t){return Q(e,l(t,{isCitation:e.isCitation}))}function Q(e,t){return t.flatMap(t=>te(e,t))}function te(e,t){let{doc:n}=e;switch(t.type){case`code`:return[U(n,`code`,[n.createTextNode(t.text)])];case`strong`:return[U(n,`strong`,Q(e,t.children))];case`em`:return[U(n,`em`,Q(e,t.children))];case`strike`:return[U(n,`del`,Q(e,t.children))];case`image`:return[n.createTextNode(`[`),...Q(e,t.children),n.createTextNode(`]`)];case`link`:return ne(e,t);case`citation`:return[ie(n,t.text)];case`text`:return e.figureText?re(e,e.figureText,t.text):[n.createTextNode(t.text)];default:{let e=Reflect.get(t,`text`);return[n.createTextNode(String(e))]}}}function ne(e,t){let n=Q(e,t.children),r=ee(t.href,e.links,e.resolveLink,globalThis.location?.origin,e.base);if(!r)return n;if(r.kind===`app`){let t=b(r.target);return t?[$(e.doc,t,n,!1)]:n}return[$(e.doc,r.href,n,r.kind===`web`)]}function re(e,t,n){return t(n).map(t=>t.kind===`sub`||t.kind===`sup`?U(e.doc,t.kind,[e.doc.createTextNode(t.text)]):e.doc.createTextNode(t.text))}function ie(e,t){let n=e.createElement(`span`);n.className=`chip primary chip-outline chip-sm chip-clickable wui-markdown-citation`,n.setAttribute(`data-wui`,`AppChip`);let r=e.createElement(`button`);r.type=`button`,r.className=`chip-body`,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,()=>{r.dispatchEvent(new CustomEvent(`wui-markdown-citation`,{bubbles:!0,detail:{citation:t}}))});let i=e.createElement(`span`);return i.className=`chip-label`,i.textContent=t,r.append(i),n.append(r),n}function $(e,t,n,r){let i=U(e,`span`,n);i.className=`wui-link__label`;let a=U(e,`a`,[i]);return a.className=`wui-link wui-link--static`,a.setAttribute(`data-wui`,`AppLink`),a.setAttribute(`href`,t),r&&(a.setAttribute(`target`,`_blank`),a.setAttribute(`rel`,`noopener noreferrer`)),a}export{H as t};
4
+ `),language:i});continue}if(M(t,r)){let i=j(e),a=[];for(r+=2;r<t.length;){let e=t[r];if(e===void 0)throw Error(`parseMarkdown read past the last source line`);if(!e.trim()||!A(e))break;a.push(j(e)),r+=1}n.push({type:`table`,header:i,rows:a});continue}if(w.test(e)){n.push({type:`rule`}),r+=1;continue}let i=C.exec(e);if(i){let e=i[1],t=i[2];if(e===void 0||t===void 0)throw Error(`The heading pattern always captures its hashes and text`);let a=k[e.length-1];if(a===void 0)throw Error(`The heading pattern always captures one to six hashes`);n.push({type:`heading`,level:a,text:t}),r+=1;continue}if(D.test(e)){let e=[];for(;r<t.length;){let n=t[r];if(n===void 0)throw Error(`parseMarkdown read past the last source line`);let i=D.exec(n);if(!i)break;let a=i[1];if(a===void 0)throw Error(`The quote pattern always captures its text`);e.push(a),r+=1}n.push({type:`quote`,lines:e});continue}let a=F(e);if(a){let e=[];for(;r<t.length;){let n=t[r];if(n===void 0)throw Error(`parseMarkdown read past the last source line`);if(!n.trim())break;let i=F(n);if(i){if(i.depth===0&&i.ordered!==a.ordered)break;e.push(i)}else if(N(t,r))break;else{let t=e[e.length-1];if(t===void 0)throw Error(`A list continuation line follows a list with no item`);t.text+=` ${n.trim()}`}r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length;){let e=t[r];if(e===void 0)throw Error(`parseMarkdown read past the last source line`);if(!e.trim()||N(t,r))break;o.push(e),r+=1}n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var L=[`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`],R=[`app`,`web`,`page`],z=e=>e!==void 0&&R.includes(e);function B(e,t,n,r,i=null){let a=V(e.ownerDocument,n,r).map((e,n)=>{let r=t[n],i=r?.sig===e.sig?r.nodes:null;return{sig:e.sig,nodes:i??e.build()}}),o=new Set(a.flatMap(e=>e.nodes));for(let e of t)for(let t of e.nodes)o.has(t)||t.parentNode?.removeChild(t);let s=i;for(let t of a.flatMap(e=>e.nodes))(t.parentNode!==e||t.previousSibling!==s)&&e.insertBefore(t,s?s.nextSibling:e.firstChild),s=t;return a}function V(e,t,n){let r={doc:e,links:z(n.links)?n.links:`web`,headings:n.headings===`text`?`text`:`outline`,resolveLink:n.resolveLink,isCitation:n.isCitation,figureText:typeof n.figureText==`function`?n.figureText:void 0,base:typeof n.base==`string`?n.base:void 0},i=n.resolverGeneration??0;return I(t).map(e=>({sig:`${JSON.stringify(e)}|${r.links}|${r.headings}|${r.base??``}|${i}`,build:()=>W(r,e)}))}var H=class extends e{_drawn;_blocks;_observer;_connected;_resolveLink;_isCitation;_resolverGeneration;_figureText;static get observedAttributes(){return[`links`,`headings`,`base`]}constructor(){super(),this._drawn=[],this._blocks=[],this._observer=null,this._connected=!1,this._resolveLink=void 0,this._isCitation=void 0,this._resolverGeneration=0,this._figureText=void 0}connectedCallback(){this._connected=!0,this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._drawn.some(t=>t.contains(e.target)))&&this._render()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._connected=!1,this._observer?.disconnect(),this._observer=null}get resolveLink(){return this._resolveLink}set resolveLink(e){this._resolveLink=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}get base(){return this.getAttribute(`base`)??void 0}set base(e){e==null?this.removeAttribute(`base`):this.setAttribute(`base`,String(e))}get isCitation(){return this._isCitation}set isCitation(e){this._isCitation=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}get figureText(){return this._figureText}set figureText(e){this._figureText=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}attributeChangedCallback(e,t,n){t!==n&&this._connected&&this._render()}_source(){return Array.from(this.children).find(e=>e instanceof HTMLPreElement&&e.classList.contains(`wui-markdown-source`))}_render(){let e=this._source();e&&(this._blocks=B(this,this._blocks,e.textContent??``,{links:this.getAttribute(`links`)??void 0,headings:this.getAttribute(`headings`)??void 0,base:this.getAttribute(`base`)??void 0,resolveLink:this._resolveLink,isCitation:this._isCitation,figureText:this._figureText,resolverGeneration:this._resolverGeneration},e),this._drawn=this._blocks.flatMap(e=>e.nodes),e.hidden=!0,this._observer?.takeRecords())}};function U(e,t,n=[]){let r=e.createElement(t);return r.append(...n),r}function W(e,t){switch(t.type){case`paragraph`:return[U(e.doc,`p`,G(e,t.lines))];case`heading`:return[K(e,t)];case`list`:return q(e,t.items);case`table`:return[Y(e,t)];case`code`:return[X(e.doc,t)];case`quote`:return[U(e.doc,`blockquote`,G(e,t.lines))];case`rule`:return[e.doc.createElement(`hr`)];default:return[]}}function G(e,t){let n=[];return t.forEach((t,r)=>{r>0&&n.push(e.doc.createElement(`br`)),n.push(...Z(e,t))}),n}function K(e,t){let n=Z(e,t.text);if(e.headings===`text`){let t=U(e.doc,`p`,n);return t.className=`fw-semibold`,t}return U(e.doc,`h2`,n)}function q(e,t){let n=[];for(let r=0;r<t.length;){let i=J(e,t,r);n.push(i.list),r=i.next}return n}function J(e,t,n){let r=t[n];if(!r)throw Error(`List run starts past its items.`);let{depth:i,ordered:a,number:o}=r,s=e.doc.createElement(a?`ol`:`ul`);a&&o!==1&&s.setAttribute(`start`,String(o));let c=null,l=n,u=t[l];for(;u&&u.depth>=i;){if(u.depth===i)c=U(e.doc,`li`,Z(e,u.text)),s.append(c),l+=1;else{let n=J(e,t,l);if(!c)throw Error(`Nested list has no item before it.`);c.append(n.list),l=n.next}u=t[l]}return{list:s,next:l}}function Y(e,t){let n=t.header.map(t=>{let n=U(e.doc,`th`,Z(e,t));return n.setAttribute(`scope`,`col`),n}),r=t.rows.map(n=>U(e.doc,`tr`,t.header.map((t,r)=>U(e.doc,`td`,Z(e,n[r]??``))))),i=U(e.doc,`table`,[U(e.doc,`thead`,[U(e.doc,`tr`,n)]),U(e.doc,`tbody`,r)]);i.className=`table`;let a=U(e.doc,`div`,[i]);return a.className=`table-responsive`,a}function X(e,t){let n=U(e,`pre`,[U(e,`code`,[e.createTextNode(t.text)])]);n.className=`wui-code-source`;let r=U(e,`wui-code-block`,[n]);return r.className=`wui-code-block`,r.setAttribute(`language`,t.language!==null&&L.includes(t.language)?t.language:`text`),r}function Z(e,t){return Q(e,l(t,{isCitation:e.isCitation}))}function Q(e,t){return t.flatMap(t=>te(e,t))}function te(e,t){let{doc:n}=e;switch(t.type){case`code`:return[U(n,`code`,[n.createTextNode(t.text)])];case`strong`:return[U(n,`strong`,Q(e,t.children))];case`em`:return[U(n,`em`,Q(e,t.children))];case`strike`:return[U(n,`del`,Q(e,t.children))];case`image`:return[n.createTextNode(`[`),...Q(e,t.children),n.createTextNode(`]`)];case`link`:return ne(e,t);case`citation`:return[ie(n,t.text)];case`text`:return e.figureText?re(e,e.figureText,t.text):[n.createTextNode(t.text)];default:throw Error(`wui-markdown: unknown inline token ${JSON.stringify(t)}`)}}function ne(e,t){let n=Q(e,t.children),r=ee(t.href,e.links,e.resolveLink,globalThis.location?.origin,e.base);if(!r)return n;if(r.kind===`app`){let t=b(r.target);return t?[$(e.doc,t,n,!1)]:n}return[$(e.doc,r.href,n,r.kind===`web`)]}function re(e,t,n){return t(n).map(t=>t.kind===`sub`||t.kind===`sup`?U(e.doc,t.kind,[e.doc.createTextNode(t.text)]):e.doc.createTextNode(t.text))}function ie(e,t){let n=e.createElement(`span`);n.className=`chip primary chip-outline chip-sm chip-clickable wui-markdown-citation`,n.setAttribute(`data-wui`,`AppChip`);let r=e.createElement(`button`);r.type=`button`,r.className=`chip-body`,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,()=>{r.dispatchEvent(new CustomEvent(`wui-markdown-citation`,{bubbles:!0,detail:{citation:t}}))});let i=e.createElement(`span`);return i.className=`chip-label`,i.textContent=t,r.append(i),n.append(r),n}function $(e,t,n,r){let i=U(e,`span`,n);i.className=`wui-link__label`;let a=U(e,`a`,[i]);return a.className=`wui-link wui-link--static`,a.setAttribute(`data-wui`,`AppLink`),a.setAttribute(`href`,t),r&&(a.setAttribute(`target`,`_blank`),a.setAttribute(`rel`,`noopener noreferrer`)),a}export{H as t};
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{n as i,r as a,t as o}from"./fieldState-D-zQcXUS.js";import{f as s}from"./formatters-C3V6M5zV.js";import{n as c}from"./listboxKeyNav-4LeEjKq6.js";import{i as l,n as u,r as d,t as f}from"./mentionText-BJsw_opZ.js";import{l as p}from"./wuiHttp-523iN_RF.js";var m=8,h=40,g=Object.freeze({listName:`People`,searching:`Searching…`,noMatch:`No one matches`,searchFailed:`Couldn't load people. Keep typing to try again.`,found:e=>`${e===1?`1 person`:`${s(e,{decimals:0})} people`}. Up and down to choose, Enter to mention.`,mentioned:e=>`Mentioned ${e}.`}),_=`[data-wui-control]`,v=`[data-wui-field]`,y=`[data-wui-menu]`,b=`[data-wui-live]`,x=0,S=e=>!!(e&&f.test(String(e.value??``))&&u(e.label)!==``);function C(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`input-sm`,n===`sm`),t.classList.toggle(`input-lg`,n===`lg`)}function w(e,t){t.readOnly=i(e)||e.hasAttribute(`loading`)}function T(e){let t=e.ownerDocument;e.id||=`wui-mention-${++x}`;let n=t.createElement(`textarea`);n.id=`${e.id}-text`,n.className=`form-control textarea wui-mention-input-text`,n.rows=Number(e.getAttribute(`rows`))>0?Number(e.getAttribute(`rows`)):3,n.setAttribute(`data-wui-control`,``),n.setAttribute(`aria-autocomplete`,`list`),n.setAttribute(`aria-controls`,`${e.id}-people`);let r=e.getAttribute(`label`);r&&n.setAttribute(`aria-label`,r);let i=e.getAttribute(`placeholder`);i&&(n.placeholder=i);for(let t of[`aria-describedby`,`aria-invalid`]){let r=e.getAttribute(t);r&&n.setAttribute(t,r)}n.disabled=e.hasAttribute(`disabled`),w(e,n),C(e,n),e.appendChild(n);let a=e.getAttribute(`name`);if(a){let n=t.createElement(`input`);n.type=`hidden`,n.name=a,n.value=e.getAttribute(`value`)??``,n.setAttribute(`data-wui-field`,``),e.appendChild(n)}let o=t.createElement(`div`);o.className=`wui-mention-menu`,o.id=`${e.id}-people`,o.setAttribute(`role`,`listbox`),o.setAttribute(`aria-label`,e.getAttribute(`people-label`)??g.listName),o.setAttribute(`data-wui-menu`,``),o.hidden=!0,e.appendChild(o);let s=t.createElement(`span`);s.className=`visually-hidden`,s.setAttribute(`data-wui-live`,``),s.setAttribute(`aria-live`,`polite`),s.setAttribute(`aria-atomic`,`true`),e.appendChild(s)}var E=class extends r{_wired;_pendingValue;_text;_mentions;_peopleProp;_declared;_loading;_searchFailed;_query;_results;_active;_timer;_searchSeq;_lastSearch;_abort;_onMenuDown;_reposition;_reanchor;_reanchorScroll;static get observedAttributes(){return[`disabled`,`readonly`,`loading`,`size`,`aria-invalid`,`aria-describedby`]}constructor(){super(),this._wired=!1,this._text=``,this._mentions=[],this._peopleProp=null,this._declared=null,this._loading=!1,this._searchFailed=!1,this._query=null,this._results=[],this._active=-1,this._timer=void 0,this._searchSeq=0,this._abort=null,this._onInput=this._onInput.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onCaret=this._onCaret.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onMenuDown=e=>e.preventDefault(),this._onMenuClick=this._onMenuClick.bind(this),this._reposition=()=>{this._isOpen()&&this._position()}}connectedCallback(){for(let e of[`people`,`loading`,`searchFailed`,`value`])if(Object.hasOwn(this,e)){let t=Reflect.get(this,e);Reflect.deleteProperty(this,e),Reflect.set(this,e,t)}if(this._wired)return;this._wired=!0,this.querySelector(_)||T(this);let e=this._requireControl(),t=this.querySelector(v)?.value??this.getAttribute(`value`)??``;this._pendingValue===void 0?this._load(t):this._load(this._pendingValue),this._pendingValue=void 0,this._syncState(),e.addEventListener(`input`,this._onInput),e.addEventListener(`keydown`,this._onKeyDown),e.addEventListener(`click`,this._onCaret),e.addEventListener(`keyup`,this._onCaret),this.addEventListener(`focusout`,this._onFocusOut);let n=this._requireMenu();n.addEventListener(`mousedown`,this._onMenuDown),n.addEventListener(`click`,this._onMenuClick),n.addEventListener(`mousemove`,e=>{let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&Number(t.dataset.index)!==this._active&&this._setActive(Number(t.dataset.index),{reveal:!1})})}disconnectedCallback(){this._close(),clearTimeout(this._timer),this._abort?.abort()}attributeChangedCallback(e,t,n){let r=this._control();r&&(e===`disabled`?(r.disabled=n!==null,n!==null&&this._close()):e===`readonly`?(w(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(w(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?C(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return l(this._text,this._mentions)}set value(e){let t=e==null?``:String(e);this._wired?t!==this.value&&this._load(t):this._pendingValue=t}get mentions(){let e=/* @__PURE__ */ new Set,t=[];for(let n of[...this._mentions].sort((e,t)=>e.start-t.start))e.has(n.id)||(e.add(n.id),t.push({id:n.id,label:n.label}));return t}get people(){return this._peopleProp?this._peopleProp:(this._declared||=[...this.querySelectorAll(`[data-wui-people] > wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})),this._declared)}set people(e){this._peopleProp=Array.isArray(e)?e.filter(S):[],this._searchFailed=!1,(this._isOpen()||this._query!==null)&&this._refresh()}get searchFailed(){return this._searchFailed}set searchFailed(e){this._searchFailed=!!e,this._query!==null&&this._renderMenu()}get loading(){return this._loading||this.hasAttribute(`loading`)}set loading(e){this._loading=!!e,this.toggleAttribute(`loading`,this._loading),this._query!==null&&this._renderMenu()}focus(e){this._control()?.focus(e)}clear(){this._load(``),this._emit()}_control(){return this.querySelector(_)}_menu(){return this.querySelector(y)}_requireControl(){let e=this._control();if(!e)throw Error(`<wui-mention-input> has no text box.`);return e}_requireMenu(){let e=this._menu();if(!e)throw Error(`<wui-mention-input> has no people list.`);return e}_load(e){let{text:t,mentions:n}=d(e);this._text=t,this._mentions=n;let r=this._control();r&&(r.defaultValue=t,r.value=t),this._syncField(),this._close()}_syncField(){let e=this.querySelector(v);e&&(e.value=this.value)}_emit(){this._syncField(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,detail:{value:this.value,mentions:this.mentions}}))}_onInput(){let e=this._requireControl(),t=e.value,n=this._text,r=t.length-n.length,i=Math.min(n.length,t.length),a=Math.max(0,Math.min(i,e.selectionEnd-Math.max(r,0))),o=0;for(;o<a&&n[o]===t[o];)o++;let s=0;for(;s<i-o&&n[n.length-1-s]===t[t.length-1-s];)s++;let c=n.length-s;this._mentions=this._mentions.filter(e=>e.end<=o||e.start>=c).map(e=>e.start>=c?{...e,start:e.start+r,end:e.end+r}:e),this._text=t,this._emit(),this._onCaret()}_onCaret(e){if(e instanceof KeyboardEvent&&e.type===`keyup`&&[`ArrowUp`,`ArrowDown`,`Enter`,`Tab`,`Escape`].includes(e.key))return;let t=this._queryAtCaret();t?this._query&&t.text===this._query.text&&t.start===this._query.start||(this._query=t,this._refresh()):this._close()}_queryAtCaret(){let e=this._control();if(!e||o(this)||e.selectionStart!==e.selectionEnd)return null;let t=e.selectionStart,n=this._text,r=n.lastIndexOf(`@`,t-1);if(r<0||r>0&&!/[\s([{"'“‘]/.test(n.charAt(r-1)))return null;let i=n.slice(r+1,t);return i.length>40||/[\n@]/.test(i)||/^\s/.test(i)||/\s{2}/.test(i)||this._mentions.some(e=>r>=e.start&&r<e.end)?null:{start:r,end:t,text:i}}_refresh(){if(!this._query)return;let e=this.hasAttribute(`remote`)||this.hasAttribute(`source`);if(e&&this._query.text.length<this._minChars()){this._results=[],this._close();return}e&&!this._answered(this._query.text)&&this._search(this._query.text);let t=this._query.text.toLowerCase(),n=e?this.people:this.people.filter(e=>u(e.label).toLowerCase().includes(t));this._results=n.slice(0,8),this._renderMenu()}_answered(e){return this._lastSearch===e}_minChars(){let e=this.getAttribute(`min-chars`),t=e==null||e===``?1:Number(e);return Number.isFinite(t)&&t>=0?t:1}_debounce(){let e=this.getAttribute(`debounce`),t=e==null||e===``?250:Number(e);return Number.isFinite(t)&&t>=0?t:250}_search(e){this._lastSearch=e,clearTimeout(this._timer);let t=++this._searchSeq;this._timer=setTimeout(()=>{let n=this.getAttribute(`source`);n?this._fetchPeople(n,e,t):this.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:t}}))},this._debounce())}async _fetchPeople(e,t,n){this._abort?.abort();let r=new AbortController;this._abort=r,this.loading=!0;let i=`${e}${e.includes(`?`)?`&`:`?`}q=${encodeURIComponent(t)}`,a=await p(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!a.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let o=this.ownerDocument.createElement(`template`);o.innerHTML=a.html,this._peopleProp=[...o.content.querySelectorAll(`wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})).filter(S),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return!(!e||e.hidden)}_renderMenu(){let t=this._menu(),n=this._control();if(!t||!n||!this._query)return;this._syncState();let r=this.ownerDocument;if(t.replaceChildren(),this._results.forEach((e,n)=>{let i=r.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${t.id}-${n}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(n),e.src){let t=r.createElement(`img`);t.className=`wui-mention-option-photo`,t.src=e.src,t.alt=``,i.appendChild(t)}let a=r.createElement(`span`);a.className=`wui-mention-option-text`;let o=r.createElement(`span`);if(o.className=`wui-mention-option-label`,o.textContent=u(e.label),a.appendChild(o),e.description){let t=r.createElement(`span`);t.className=`wui-mention-option-description`,t.textContent=String(e.description),a.appendChild(t)}i.appendChild(a),t.appendChild(i)}),!this._results.length){let e=r.createElement(`div`);e.className=`wui-mention-empty`,e.textContent=this.loading?g.searching:this._searchFailed?g.searchFailed:`${g.noMatch} “${this._query.text}”`,t.appendChild(e)}let i=this._isOpen();t.hidden=!1,i||e(this,this._reposition),this._position(),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?g.found(this._results.length):this._searchFailed?g.searchFailed:`${g.noMatch}.`)}_syncState(){let e=this._control();e&&a(this,e)}_position(){n(this._control(),this._menu())}_close(){this._query=null,this._lastSearch=void 0,clearTimeout(this._timer);let e=this._menu();e&&!e.hidden&&(e.hidden=!0,e.replaceChildren()),this._active=-1,this._control()?.removeAttribute(`aria-activedescendant`),t(this)}_setActive(e,{reveal:t=!0}={}){let n=this._requireMenu(),r=[...n.querySelectorAll(`.wui-mention-option`)];this._active=e>=0&&e<r.length?e:-1;let i=this._active>=0?r[this._active]??null:null;for(let e of r)e.setAttribute(`aria-selected`,e===i?`true`:`false`);c(n,i),i?(t&&i.scrollIntoView?.({block:`nearest`}),this._requireControl().setAttribute(`aria-activedescendant`,i.id)):this._requireControl().removeAttribute(`aria-activedescendant`)}_onKeyDown(e){if(this._isOpen()&&this._query){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=this._results.length;if(!t)return;let n=e.key===`ArrowDown`?1:-1;this._setActive((this._active+n+t)%t);return}if((e.key===`Enter`||e.key===`Tab`)&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&this._active>=0){e.preventDefault(),this._pick(this._results[this._active]);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this._close();return}}e.key===`Enter`&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),this.dispatchEvent(new CustomEvent(`wui:mention-input:submit`,{bubbles:!0,detail:{value:this.value}}))):e.key===`Backspace`&&this._removeWholeMention(e)}_removeWholeMention(e){let t=this._requireControl();if(t.selectionStart!==t.selectionEnd)return;let n=t.selectionStart,r=this._mentions.find(e=>e.end===n);r&&(e.preventDefault(),this._replace(r.start,r.end,``))}_onMenuClick(e){let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&this._pick(this._results[Number(t.dataset.index)])}_pick(e){if(!e||!this._query)return;let t=u(e.label),{start:n,end:r}=this._query,i=this._text.slice(r),a=`@${t}${/^\s/.test(i)?``:` `}`;this._replace(n,r,a,{id:String(e.value),label:t}),this._announce(g.mentioned(t))}_replace(e,t,n,r){let i=this._requireControl(),a=n.length-(t-e);this._mentions=this._mentions.filter(n=>n.end<=e||n.start>=t).map(e=>e.start>=t?{...e,start:e.start+a,end:e.end+a}:e),r&&this._mentions.push({start:e,end:e+1+r.label.length,id:r.id,label:r.label}),this._text=this._text.slice(0,e)+n+this._text.slice(t),i.value=this._text;let o=e+n.length;i.setSelectionRange(o,o),this._close(),i.focus(),this._emit()}_onFocusOut(e){e.relatedTarget instanceof Node&&this.contains(e.relatedTarget)||this._close()}_announce(e){let t=this.querySelector(b);t&&(t.textContent=``,t.textContent=e)}};export{E as i,m as n,g as r,h as t};
1
+ import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{n as i,r as a,t as o}from"./fieldState-D-zQcXUS.js";import{f as s}from"./formatters-ljfITOZ3.js";import{n as c}from"./listboxKeyNav-4LeEjKq6.js";import{i as l,n as u,r as d,t as f}from"./mentionText-BJsw_opZ.js";import{l as p}from"./wuiHttp-DGbD7Fra.js";var m=8,h=40,g=Object.freeze({listName:`People`,searching:`Searching…`,noMatch:`No one matches`,searchFailed:`Couldn't load people. Keep typing to try again.`,found:e=>`${e===1?`1 person`:`${s(e,{decimals:0})} people`}. Up and down to choose, Enter to mention.`,mentioned:e=>`Mentioned ${e}.`}),_=`[data-wui-control]`,v=`[data-wui-field]`,y=`[data-wui-menu]`,b=`[data-wui-live]`,x=0,S=e=>!!(e&&f.test(String(e.value??``))&&u(e.label)!==``);function C(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`input-sm`,n===`sm`),t.classList.toggle(`input-lg`,n===`lg`)}function w(e,t){t.readOnly=i(e)||e.hasAttribute(`loading`)}function T(e){let t=e.ownerDocument;e.id||=`wui-mention-${++x}`;let n=t.createElement(`textarea`);n.id=`${e.id}-text`,n.className=`form-control textarea wui-mention-input-text`,n.rows=Number(e.getAttribute(`rows`))>0?Number(e.getAttribute(`rows`)):3,n.setAttribute(`data-wui-control`,``),n.setAttribute(`aria-autocomplete`,`list`),n.setAttribute(`aria-controls`,`${e.id}-people`);let r=e.getAttribute(`label`);r&&n.setAttribute(`aria-label`,r);let i=e.getAttribute(`placeholder`);i&&(n.placeholder=i);for(let t of[`aria-describedby`,`aria-invalid`]){let r=e.getAttribute(t);r&&n.setAttribute(t,r)}n.disabled=e.hasAttribute(`disabled`),w(e,n),C(e,n),e.appendChild(n);let a=e.getAttribute(`name`);if(a){let n=t.createElement(`input`);n.type=`hidden`,n.name=a,n.value=e.getAttribute(`value`)??``,n.setAttribute(`data-wui-field`,``),e.appendChild(n)}let o=t.createElement(`div`);o.className=`wui-mention-menu`,o.id=`${e.id}-people`,o.setAttribute(`role`,`listbox`),o.setAttribute(`aria-label`,e.getAttribute(`people-label`)??g.listName),o.setAttribute(`data-wui-menu`,``),o.hidden=!0,e.appendChild(o);let s=t.createElement(`span`);s.className=`visually-hidden`,s.setAttribute(`data-wui-live`,``),s.setAttribute(`aria-live`,`polite`),s.setAttribute(`aria-atomic`,`true`),e.appendChild(s)}var E=class extends r{_wired;_pendingValue;_text;_mentions;_peopleProp;_declared;_loading;_searchFailed;_query;_results;_active;_timer;_searchSeq;_lastSearch;_abort;_onMenuDown;_reposition;_reanchor;_reanchorScroll;static get observedAttributes(){return[`disabled`,`readonly`,`loading`,`size`,`aria-invalid`,`aria-describedby`]}constructor(){super(),this._wired=!1,this._text=``,this._mentions=[],this._peopleProp=null,this._declared=null,this._loading=!1,this._searchFailed=!1,this._query=null,this._results=[],this._active=-1,this._timer=void 0,this._searchSeq=0,this._abort=null,this._onInput=this._onInput.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onCaret=this._onCaret.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onMenuDown=e=>e.preventDefault(),this._onMenuClick=this._onMenuClick.bind(this),this._reposition=()=>{this._isOpen()&&this._position()}}connectedCallback(){for(let e of[`people`,`loading`,`searchFailed`,`value`])if(Object.hasOwn(this,e)){let t=Reflect.get(this,e);Reflect.deleteProperty(this,e),Reflect.set(this,e,t)}if(this._wired)return;this._wired=!0,this.querySelector(_)||T(this);let e=this._requireControl(),t=this.querySelector(v)?.value??this.getAttribute(`value`)??``;this._pendingValue===void 0?this._load(t):this._load(this._pendingValue),this._pendingValue=void 0,this._syncState(),e.addEventListener(`input`,this._onInput),e.addEventListener(`keydown`,this._onKeyDown),e.addEventListener(`click`,this._onCaret),e.addEventListener(`keyup`,this._onCaret),this.addEventListener(`focusout`,this._onFocusOut);let n=this._requireMenu();n.addEventListener(`mousedown`,this._onMenuDown),n.addEventListener(`click`,this._onMenuClick),n.addEventListener(`mousemove`,e=>{let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&Number(t.dataset.index)!==this._active&&this._setActive(Number(t.dataset.index),{reveal:!1})})}disconnectedCallback(){this._close(),clearTimeout(this._timer),this._abort?.abort()}attributeChangedCallback(e,t,n){let r=this._control();r&&(e===`disabled`?(r.disabled=n!==null,n!==null&&this._close()):e===`readonly`?(w(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(w(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?C(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return l(this._text,this._mentions)}set value(e){let t=e==null?``:String(e);this._wired?t!==this.value&&this._load(t):this._pendingValue=t}get mentions(){let e=/* @__PURE__ */ new Set,t=[];for(let n of[...this._mentions].sort((e,t)=>e.start-t.start))e.has(n.id)||(e.add(n.id),t.push({id:n.id,label:n.label}));return t}get people(){return this._peopleProp?this._peopleProp:(this._declared||=[...this.querySelectorAll(`[data-wui-people] > wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})),this._declared)}set people(e){this._peopleProp=Array.isArray(e)?e.filter(S):[],this._searchFailed=!1,(this._isOpen()||this._query!==null)&&this._refresh()}get searchFailed(){return this._searchFailed}set searchFailed(e){this._searchFailed=!!e,this._query!==null&&this._renderMenu()}get loading(){return this._loading||this.hasAttribute(`loading`)}set loading(e){this._loading=!!e,this.toggleAttribute(`loading`,this._loading),this._query!==null&&this._renderMenu()}focus(e){this._control()?.focus(e)}clear(){this._load(``),this._emit()}_control(){return this.querySelector(_)}_menu(){return this.querySelector(y)}_requireControl(){let e=this._control();if(!e)throw Error(`<wui-mention-input> has no text box.`);return e}_requireMenu(){let e=this._menu();if(!e)throw Error(`<wui-mention-input> has no people list.`);return e}_load(e){let{text:t,mentions:n}=d(e);this._text=t,this._mentions=n;let r=this._control();r&&(r.defaultValue=t,r.value=t),this._syncField(),this._close()}_syncField(){let e=this.querySelector(v);e&&(e.value=this.value)}_emit(){this._syncField(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,detail:{value:this.value,mentions:this.mentions}}))}_onInput(){let e=this._requireControl(),t=e.value,n=this._text,r=t.length-n.length,i=Math.min(n.length,t.length),a=Math.max(0,Math.min(i,e.selectionEnd-Math.max(r,0))),o=0;for(;o<a&&n[o]===t[o];)o++;let s=0;for(;s<i-o&&n[n.length-1-s]===t[t.length-1-s];)s++;let c=n.length-s;this._mentions=this._mentions.filter(e=>e.end<=o||e.start>=c).map(e=>e.start>=c?{...e,start:e.start+r,end:e.end+r}:e),this._text=t,this._emit(),this._onCaret()}_onCaret(e){if(e instanceof KeyboardEvent&&e.type===`keyup`&&[`ArrowUp`,`ArrowDown`,`Enter`,`Tab`,`Escape`].includes(e.key))return;let t=this._queryAtCaret();t?this._query&&t.text===this._query.text&&t.start===this._query.start||(this._query=t,this._refresh()):this._close()}_queryAtCaret(){let e=this._control();if(!e||o(this)||e.selectionStart!==e.selectionEnd)return null;let t=e.selectionStart,n=this._text,r=n.lastIndexOf(`@`,t-1);if(r<0||r>0&&!/[\s([{"'“‘]/.test(n.charAt(r-1)))return null;let i=n.slice(r+1,t);return i.length>40||/[\n@]/.test(i)||/^\s/.test(i)||/\s{2}/.test(i)||this._mentions.some(e=>r>=e.start&&r<e.end)?null:{start:r,end:t,text:i}}_refresh(){if(!this._query)return;let e=this.hasAttribute(`remote`)||this.hasAttribute(`source`);if(e&&this._query.text.length<this._minChars()){this._results=[],this._close();return}e&&!this._answered(this._query.text)&&this._search(this._query.text);let t=this._query.text.toLowerCase(),n=e?this.people:this.people.filter(e=>u(e.label).toLowerCase().includes(t));this._results=n.slice(0,8),this._renderMenu()}_answered(e){return this._lastSearch===e}_minChars(){let e=this.getAttribute(`min-chars`),t=e==null||e===``?1:Number(e);return Number.isFinite(t)&&t>=0?t:1}_debounce(){let e=this.getAttribute(`debounce`),t=e==null||e===``?250:Number(e);return Number.isFinite(t)&&t>=0?t:250}_search(e){this._lastSearch=e,clearTimeout(this._timer);let t=++this._searchSeq;this._timer=setTimeout(()=>{let n=this.getAttribute(`source`);n?this._fetchPeople(n,e,t):this.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:t}}))},this._debounce())}async _fetchPeople(e,t,n){this._abort?.abort();let r=new AbortController;this._abort=r,this.loading=!0;let i=`${e}${e.includes(`?`)?`&`:`?`}q=${encodeURIComponent(t)}`,a=await p(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!a.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let o=this.ownerDocument.createElement(`template`);o.innerHTML=a.html,this._peopleProp=[...o.content.querySelectorAll(`wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})).filter(S),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return!(!e||e.hidden)}_renderMenu(){let t=this._menu(),n=this._control();if(!t||!n||!this._query)return;this._syncState();let r=this.ownerDocument;if(t.replaceChildren(),this._results.forEach((e,n)=>{let i=r.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${t.id}-${n}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(n),e.src){let t=r.createElement(`img`);t.className=`wui-mention-option-photo`,t.src=e.src,t.alt=``,i.appendChild(t)}let a=r.createElement(`span`);a.className=`wui-mention-option-text`;let o=r.createElement(`span`);if(o.className=`wui-mention-option-label`,o.textContent=u(e.label),a.appendChild(o),e.description){let t=r.createElement(`span`);t.className=`wui-mention-option-description`,t.textContent=String(e.description),a.appendChild(t)}i.appendChild(a),t.appendChild(i)}),!this._results.length){let e=r.createElement(`div`);e.className=`wui-mention-empty`,e.textContent=this.loading?g.searching:this._searchFailed?g.searchFailed:`${g.noMatch} “${this._query.text}”`,t.appendChild(e)}let i=this._isOpen();t.hidden=!1,i||e(this,this._reposition),this._position(),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?g.found(this._results.length):this._searchFailed?g.searchFailed:`${g.noMatch}.`)}_syncState(){let e=this._control();e&&a(this,e)}_position(){n(this._control(),this._menu())}_close(){this._query=null,this._lastSearch=void 0,clearTimeout(this._timer);let e=this._menu();e&&!e.hidden&&(e.hidden=!0,e.replaceChildren()),this._active=-1,this._control()?.removeAttribute(`aria-activedescendant`),t(this)}_setActive(e,{reveal:t=!0}={}){let n=this._requireMenu(),r=[...n.querySelectorAll(`.wui-mention-option`)];this._active=e>=0&&e<r.length?e:-1;let i=this._active>=0?r[this._active]??null:null;for(let e of r)e.setAttribute(`aria-selected`,e===i?`true`:`false`);c(n,i),i?(t&&i.scrollIntoView?.({block:`nearest`}),this._requireControl().setAttribute(`aria-activedescendant`,i.id)):this._requireControl().removeAttribute(`aria-activedescendant`)}_onKeyDown(e){if(this._isOpen()&&this._query){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=this._results.length;if(!t)return;let n=e.key===`ArrowDown`?1:-1;this._setActive((this._active+n+t)%t);return}if((e.key===`Enter`||e.key===`Tab`)&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&this._active>=0){e.preventDefault(),this._pick(this._results[this._active]);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this._close();return}}e.key===`Enter`&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),this.dispatchEvent(new CustomEvent(`wui:mention-input:submit`,{bubbles:!0,detail:{value:this.value}}))):e.key===`Backspace`&&this._removeWholeMention(e)}_removeWholeMention(e){let t=this._requireControl();if(t.selectionStart!==t.selectionEnd)return;let n=t.selectionStart,r=this._mentions.find(e=>e.end===n);r&&(e.preventDefault(),this._replace(r.start,r.end,``))}_onMenuClick(e){let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&this._pick(this._results[Number(t.dataset.index)])}_pick(e){if(!e||!this._query)return;let t=u(e.label),{start:n,end:r}=this._query,i=this._text.slice(r),a=`@${t}${/^\s/.test(i)?``:` `}`;this._replace(n,r,a,{id:String(e.value),label:t}),this._announce(g.mentioned(t))}_replace(e,t,n,r){let i=this._requireControl(),a=n.length-(t-e);this._mentions=this._mentions.filter(n=>n.end<=e||n.start>=t).map(e=>e.start>=t?{...e,start:e.start+a,end:e.end+a}:e),r&&this._mentions.push({start:e,end:e+1+r.label.length,id:r.id,label:r.label}),this._text=this._text.slice(0,e)+n+this._text.slice(t),i.value=this._text;let o=e+n.length;i.setSelectionRange(o,o),this._close(),i.focus(),this._emit()}_onFocusOut(e){e.relatedTarget instanceof Node&&this.contains(e.relatedTarget)||this._close()}_announce(e){let t=this.querySelector(b);t&&(t.textContent=``,t.textContent=e)}};export{E as i,m as n,g as r,h as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{c as t,i as n,n as r,s as i}from"./notificationDays-BKVW7xYD.js";import{l as a}from"./wuiHttp-523iN_RF.js";var o=`.wui-notification-center-trigger`,s=`.wui-notification-center-panel`,c=`.wui-notification-center-count`,l=`.wui-notification-center-live`,u=`.wui-notification-center-markall`,d=`.wui-notification-center-item`,f=`wui-notification-center-item-read`,p=`.wui-notification-center-unread-label`,m=`.app-tabs`,h=`.wui-notification-center-tabs [role='tablist']`,g=`.wui-notification-center-tabs [role='tab']`,_=`.wui-notification-center-empty`,v={ArrowDown:1,ArrowUp:-1,Home:`first`,End:`last`},y=e=>!!e,b=e=>Object.hasOwn(r.failed,e),x=(e,t)=>{let n=e.querySelector(t);return n instanceof HTMLElement?n:null},S=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),C=class extends e{constructor(){super(),this._doc=null,this._unread=0,this._busy=!1,this._onClick=e=>this._click(e),this._onKeyDown=e=>this._key(e),this._onOutside=e=>{e.composedPath().includes(this)||this.close()},this._onFocusOut=e=>{let t=e.relatedTarget;t instanceof Node&&!this.contains(t)&&this.close()}}connectedCallback(){this._doc=this.ownerDocument,this._unread=this._initialUnread(),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this._doc.addEventListener(`mousedown`,this._onOutside),this.addEventListener(`focusout`,this._onFocusOut),this._syncOpen(),this.isOpen&&this._layoutTabs()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeyDown),this._doc?.removeEventListener(`mousedown`,this._onOutside),this.removeEventListener(`focusout`,this._onFocusOut),this._doc=null}get isOpen(){return this.hasAttribute(`open`)}open(){this.isOpen||(this.setAttribute(`open`,``),this._syncOpen(),this._layoutTabs(),x(this,s)?.focus(),this._announceToggle())}close({restoreFocus:e=!1}={}){this.isOpen&&(this.removeAttribute(`open`),this._syncOpen(),e&&x(this,o)?.focus(),this._announceToggle())}toggle(){this.isOpen?this.close():this.open()}_announceToggle(){this.dispatchEvent(new CustomEvent(`wui:notification-center:toggle`,{bubbles:!0,detail:{open:this.isOpen}}))}_syncOpen(){this.querySelector(o)?.setAttribute(`aria-expanded`,this.isOpen?`true`:`false`)}_initialUnread(){let e=Number.parseInt(this.getAttribute(`unread`)??``,10);return Number.isInteger(e)&&e>=0?e:this.querySelectorAll(`${d}:not(.${f}):not([data-archived="true"])`).length}_click(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(g);if(n instanceof HTMLElement&&this.contains(n)){if(this.hasAttribute(`controlled`))return;this._pickTab(n);return}let r=t.closest(`${o}, ${u}, ${d}`);r instanceof HTMLElement&&this.contains(r)&&(r.matches(o)?this.toggle():this.hasAttribute(`controlled`)||(r.matches(u)?this._markAll():this._markItem(r)))}_key(e){if(e.key===`Escape`&&this.isOpen){e.preventDefault(),e.stopPropagation(),this.close({restoreFocus:!0});return}if(!this.isOpen)return;let t=e.target;if(!(t instanceof Element))throw Error(`Keyboard event target is not an element.`);if(!this.querySelector(s)?.contains(t)||t.closest(m))return;let n=v[e.key];if(n===void 0)return;let r=S(this,d).filter(e=>!e.closest(`[hidden]`));if(r.length===0)return;let i=t.closest(d),a=i instanceof HTMLElement?r.indexOf(i):-1,o;o=n===`first`?0:n===`last`?r.length-1:a===-1?n===1?0:r.length-1:Math.min(r.length-1,Math.max(0,a+n)),e.preventDefault(),r[o]?.focus()}_markItem(e){e.classList.contains(f)||(this._applyRead(e),e.dataset.archived!==`true`&&(this._unread=Math.max(0,this._unread-1)),this._render(),this._say(t(this._unread)),this._emitRead([e.dataset.id].filter(y),!1))}async _markAll(){if(this._busy)return;let e=S(this,`${d}:not(.${f})`);if(e.length===0&&this._unread===0)return;let t=e.map(e=>e.dataset.id).filter(y),n=this.getAttribute(`read-action`);if(n){this._setBusy(!0);let e=new URLSearchParams;for(let n of t)e.append(`ids`,n);let i=await a(n,{method:`POST`,body:e});if(this._setBusy(!1),!i.ok){if(i.kind===`session`||i.kind===`aborted`)return;let e=i.kind,t=i.message||(b(e)?r.failed[e]:r.failed.server);this._say(t),this.dispatchEvent(new CustomEvent(`wui:notification-center:failed`,{bubbles:!0,detail:{kind:e,message:t}}));return}}for(let t of e)this._applyRead(t);this._unread=0,this._render(),this._say(r.allRead),this._emitRead(t,!0)}_pickTab(e){let t=e.closest(h);if(t instanceof HTMLElement){for(let n of S(t,g)){let t=n===e;n.classList.toggle(`active`,t),n.setAttribute(`aria-selected`,t?`true`:`false`),n.setAttribute(`tabindex`,t?`0`:`-1`)}this._layoutTabs(),this._filterItems(e.dataset.key)}}_layoutTabs(){for(let e of S(this,h)){let t=x(e,`.app-tab.active`);t&&(e.style.setProperty(`--wui-tab-x`,`${t.offsetLeft}px`),e.style.setProperty(`--wui-tab-w`,`${t.offsetWidth}px`)),e.setAttribute(`data-wui-tabs`,``)}}_filterItems(e){let t=!1;for(let n of S(this,d)){let r=n.dataset.archived===`true`,i=n.classList.contains(f),a=e===`archived`?r:!r&&(e!==`unread`||!i);a&&(t=!0);let o=n.closest(`li`);o&&(o.hidden=!a)}for(let e of S(this,`.wui-notification-center-list section`))e.hidden=[...e.querySelectorAll(`li`)].every(e=>e.hidden);let n=x(this,_);n&&(n.hidden=t)}_applyRead(e){e.classList.add(f),e.querySelector(p)?.remove()}_setBusy(e){this._busy=e;let t=this.querySelector(u);t instanceof HTMLButtonElement&&(t.disabled=e||this._unread===0,e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`))}_render(){let e=x(this,c);e&&(e.textContent=n(this._unread),e.hidden=this._unread===0),this.querySelector(o)?.setAttribute(`aria-label`,i(this.getAttribute(`label`)||r.label,this._unread));let t=this.querySelector(u);t instanceof HTMLButtonElement&&(t.disabled=this._unread===0)}_say(e){let t=this.querySelector(l);t&&(t.textContent=e)}_emitRead(e,t){this.dispatchEvent(new CustomEvent(`wui:notification-center:read`,{bubbles:!0,detail:{ids:e,all:t}}))}};export{C as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{c as t,i as n,n as r,s as i}from"./notificationDays-BIWczft0.js";import{l as a}from"./wuiHttp-DGbD7Fra.js";var o=`.wui-notification-center-trigger`,s=`.wui-notification-center-panel`,c=`.wui-notification-center-count`,l=`.wui-notification-center-live`,u=`.wui-notification-center-markall`,d=`.wui-notification-center-item`,f=`wui-notification-center-item-read`,p=`.wui-notification-center-unread-label`,m=`.app-tabs`,h=`.wui-notification-center-tabs [role='tablist']`,g=`.wui-notification-center-tabs [role='tab']`,_=`.wui-notification-center-empty`,v={ArrowDown:1,ArrowUp:-1,Home:`first`,End:`last`},y=e=>!!e,b=e=>Object.hasOwn(r.failed,e),x=(e,t)=>{let n=e.querySelector(t);return n instanceof HTMLElement?n:null},S=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),C=class extends e{constructor(){super(),this._doc=null,this._unread=0,this._busy=!1,this._onClick=e=>this._click(e),this._onKeyDown=e=>this._key(e),this._onOutside=e=>{e.composedPath().includes(this)||this.close()},this._onFocusOut=e=>{let t=e.relatedTarget;t instanceof Node&&!this.contains(t)&&this.close()}}connectedCallback(){this._doc=this.ownerDocument,this._unread=this._initialUnread(),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this._doc.addEventListener(`mousedown`,this._onOutside),this.addEventListener(`focusout`,this._onFocusOut),this._syncOpen(),this.isOpen&&this._layoutTabs()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeyDown),this._doc?.removeEventListener(`mousedown`,this._onOutside),this.removeEventListener(`focusout`,this._onFocusOut),this._doc=null}get isOpen(){return this.hasAttribute(`open`)}open(){this.isOpen||(this.setAttribute(`open`,``),this._syncOpen(),this._layoutTabs(),x(this,s)?.focus(),this._announceToggle())}close({restoreFocus:e=!1}={}){this.isOpen&&(this.removeAttribute(`open`),this._syncOpen(),e&&x(this,o)?.focus(),this._announceToggle())}toggle(){this.isOpen?this.close():this.open()}_announceToggle(){this.dispatchEvent(new CustomEvent(`wui:notification-center:toggle`,{bubbles:!0,detail:{open:this.isOpen}}))}_syncOpen(){this.querySelector(o)?.setAttribute(`aria-expanded`,this.isOpen?`true`:`false`)}_initialUnread(){let e=Number.parseInt(this.getAttribute(`unread`)??``,10);return Number.isInteger(e)&&e>=0?e:this.querySelectorAll(`${d}:not(.${f}):not([data-archived="true"])`).length}_click(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(g);if(n instanceof HTMLElement&&this.contains(n)){if(this.hasAttribute(`controlled`))return;this._pickTab(n);return}let r=t.closest(`${o}, ${u}, ${d}`);r instanceof HTMLElement&&this.contains(r)&&(r.matches(o)?this.toggle():this.hasAttribute(`controlled`)||(r.matches(u)?this._markAll():this._markItem(r)))}_key(e){if(e.key===`Escape`&&this.isOpen){e.preventDefault(),e.stopPropagation(),this.close({restoreFocus:!0});return}if(!this.isOpen)return;let t=e.target;if(!(t instanceof Element))throw Error(`Keyboard event target is not an element.`);if(!this.querySelector(s)?.contains(t)||t.closest(m))return;let n=v[e.key];if(n===void 0)return;let r=S(this,d).filter(e=>!e.closest(`[hidden]`));if(r.length===0)return;let i=t.closest(d),a=i instanceof HTMLElement?r.indexOf(i):-1,o;o=n===`first`?0:n===`last`?r.length-1:a===-1?n===1?0:r.length-1:Math.min(r.length-1,Math.max(0,a+n)),e.preventDefault(),r[o]?.focus()}_markItem(e){e.classList.contains(f)||(this._applyRead(e),e.dataset.archived!==`true`&&(this._unread=Math.max(0,this._unread-1)),this._render(),this._say(t(this._unread)),this._emitRead([e.dataset.id].filter(y),!1))}async _markAll(){if(this._busy)return;let e=S(this,`${d}:not(.${f})`);if(e.length===0&&this._unread===0)return;let t=e.map(e=>e.dataset.id).filter(y),n=this.getAttribute(`read-action`);if(n){this._setBusy(!0);let e=new URLSearchParams;for(let n of t)e.append(`ids`,n);let i=await a(n,{method:`POST`,body:e});if(this._setBusy(!1),!i.ok){if(i.kind===`session`||i.kind===`aborted`)return;let e=i.kind,t=i.message||(b(e)?r.failed[e]:r.failed.server);this._say(t),this.dispatchEvent(new CustomEvent(`wui:notification-center:failed`,{bubbles:!0,detail:{kind:e,message:t}}));return}}for(let t of e)this._applyRead(t);this._unread=0,this._render(),this._say(r.allRead),this._emitRead(t,!0)}_pickTab(e){let t=e.closest(h);if(t instanceof HTMLElement){for(let n of S(t,g)){let t=n===e;n.classList.toggle(`active`,t),n.setAttribute(`aria-selected`,t?`true`:`false`),n.setAttribute(`tabindex`,t?`0`:`-1`)}this._layoutTabs(),this._filterItems(e.dataset.key)}}_layoutTabs(){for(let e of S(this,h)){let t=x(e,`.app-tab.active`);t&&(e.style.setProperty(`--wui-tab-x`,`${t.offsetLeft}px`),e.style.setProperty(`--wui-tab-w`,`${t.offsetWidth}px`)),e.setAttribute(`data-wui-tabs`,``)}}_filterItems(e){let t=!1;for(let n of S(this,d)){let r=n.dataset.archived===`true`,i=n.classList.contains(f),a=e===`archived`?r:!r&&(e!==`unread`||!i);a&&(t=!0);let o=n.closest(`li`);o&&(o.hidden=!a)}for(let e of S(this,`.wui-notification-center-list section`))e.hidden=[...e.querySelectorAll(`li`)].every(e=>e.hidden);let n=x(this,_);n&&(n.hidden=t)}_applyRead(e){e.classList.add(f),e.querySelector(p)?.remove()}_setBusy(e){this._busy=e;let t=this.querySelector(u);t instanceof HTMLButtonElement&&(t.disabled=e||this._unread===0,e?t.setAttribute(`aria-busy`,`true`):t.removeAttribute(`aria-busy`))}_render(){let e=x(this,c);e&&(e.textContent=n(this._unread),e.hidden=this._unread===0),this.querySelector(o)?.setAttribute(`aria-label`,i(this.getAttribute(`label`)||r.label,this._unread));let t=this.querySelector(u);t instanceof HTMLButtonElement&&(t.disabled=this._unread===0)}_say(e){let t=this.querySelector(l);t&&(t.textContent=e)}_emitRead(e,t){this.dispatchEvent(new CustomEvent(`wui:notification-center:read`,{bubbles:!0,detail:{ids:e,all:t}}))}};export{C as t};
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{t as r}from"./elementBase-Cxeyx0tU.js";var i=`data-wui-overflow-hidden`,a=`[aria-selected="true"], .active`,o=`.chip-body, input, a[href], button:not(.chip-remove)`,s=1,c=0,l=e=>Number.parseFloat(e)||0,u=e=>e.nodeType===1,d=e=>{let t=e.getAttribute(`data-overflow-label`);if(t)return t;let n=[],r=e=>{for(let t of e.childNodes)if(t.nodeType===3){let e=t.textContent?.trim();e&&n.push(e)}else u(t)&&!t.matches(`svg, img, [aria-hidden='true']`)&&r(t)};return r(e),n.join(` `)},f=e=>{if(e.matches(`button, a[href], label, input`))return e;let t=e.querySelector(o);return t instanceof HTMLElement?t:null},p=class extends r{constructor(){super(),this._hiddenKey=``,this._ro=null,this._mo=null,this._observedList=null,this._doc=null,this._onDocDown=e=>{!this._menu.hidden&&!e.composedPath().includes(this)&&this._close(!1)}}connectedCallback(){this.classList.add(`wui-overflow`),this._build(),this._doc=this.ownerDocument,this._doc.addEventListener(`pointerdown`,this._onDocDown,!0),typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(()=>this.layout()),this._ro.observe(this)),typeof MutationObserver<`u`&&(this._mo=new MutationObserver(()=>this.layout()),this._watch()),this.layout()}disconnectedCallback(){this._ro?.disconnect(),this._mo?.disconnect(),this._ro=null,this._mo=null,this._observedList=null,this._doc?.removeEventListener(`pointerdown`,this._onDocDown,!0),this._doc=null,t(this)}static get observedAttributes(){return[`label`]}attributeChangedCallback(){let e=this._more?.firstChild;e&&(e.textContent=this._label())}_label(){return this.getAttribute(`label`)||`More`}_list(){let e=this.querySelector(`[data-wui-overflow-list]`);return e instanceof HTMLElement?e:null}_items(e){return[...e.children].filter(e=>!e.hasAttribute(`data-wui-overflow-skip`))}_build(){if(this._more)return;let e=`wui-overflow-menu-${++c}`,t=this.ownerDocument.createElement(`button`);t.type=`button`,t.className=`wui-overflow-more`,t.hidden=!0,t.setAttribute(`aria-haspopup`,`menu`),t.setAttribute(`aria-expanded`,`false`),t.setAttribute(`aria-controls`,e),t.append(this._label());let n=this.ownerDocument.createElement(`div`);n.className=`wui-overflow-menu`,n.id=e,n.setAttribute(`role`,`menu`),n.hidden=!0,this.append(t,n),this._more=t,this._menu=n,t.addEventListener(`click`,()=>this._menu.hidden?this._open(!1):this._close(!0)),t.addEventListener(`keydown`,e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),this._open(!0))}),n.addEventListener(`keydown`,e=>this._onMenuKey(e))}_watch(){let e=this._list();this._mo&&e!==this._observedList&&(this._mo.disconnect(),this._observedList=e,e&&this._mo.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`class`,`aria-selected`,`disabled`,`aria-disabled`,`data-overflow-label`]}))}layout(){let e=this._list();if(this._watch(),!e||!this._more)return;let t=this._items(e);for(let e of t)e.removeAttribute(i);this._more.hidden=!0;let n=this.clientWidth,r=[];if(n>0&&t.length){let i=getComputedStyle(e),o=l(i.columnGap),c=l(i.paddingLeft)+l(i.paddingRight)+l(i.borderLeftWidth)+l(i.borderRightWidth),u=t.map(e=>e.offsetWidth);if(u.reduce((e,t)=>e+t,0)+o*(t.length-1)>n-c+s){this._more.hidden=!1;let e=n-c-this._more.offsetWidth-l(getComputedStyle(this).columnGap),i=this.hasAttribute(`keep`)?this.getAttribute(`keep`):a,s=/* @__PURE__ */ new Set,d=0,f=0,p=i?t.filter(e=>e.matches(i)):[];for(let n of p){let r=d+(u[t.indexOf(n)]??0)+(f?o:0);r>e||(s.add(n),d=r,f+=1)}for(let n=0;n<t.length;n+=1){let r=t[n];if(!r||s.has(r))continue;let i=d+(u[n]??0)+(f?o:0);if(i>e)break;s.add(r),d=i,f+=1}r=t.filter(e=>!s.has(e))}}for(let e of r)e.setAttribute(i,``);this._more.hidden=r.length===0,r.length?this._menu.hidden||this._fill(r):this._close(!1);let o=r.map(e=>t.indexOf(e)).join(`,`);o!==this._hiddenKey&&(this._hiddenKey=o,this.dispatchEvent(new CustomEvent(`wui-overflow-change`,{bubbles:!0,detail:{hidden:r.length}})))}_hiddenItems(){let e=this._list();return e?this._items(e).filter(e=>e.hasAttribute(i)):[]}_fill(e){this._menu.replaceChildren();for(let t of e){let e=this.ownerDocument.createElement(`button`);e.type=`button`,e.className=`wui-overflow-item`,e.tabIndex=-1;let n=t.querySelector(`input[type=checkbox], input[type=radio]`);n instanceof HTMLInputElement?(e.setAttribute(`role`,n.type===`radio`?`menuitemradio`:`menuitemcheckbox`),e.setAttribute(`aria-checked`,String(n.checked))):e.setAttribute(`role`,`menuitem`);let r=f(t),i=!r||`disabled`in r&&r.disabled||r.getAttribute(`aria-disabled`)===`true`||t.matches(`.disabled, [aria-disabled='true']`);i&&e.setAttribute(`aria-disabled`,`true`),e.textContent=d(t),e.addEventListener(`click`,()=>{i||r&&this._choose(t,r)}),this._menu.append(e)}}_choose(e,t){this._close(!1),t.click(),this.layout();let n=!e.hasAttribute(i)&&e.matches(`button, a[href]`)?e:this._more;n.hidden||n.focus()}_open(t){let r=this._hiddenItems();if(!r.length)return;this._fill(r),this._menu.hidden=!1,this._more.setAttribute(`aria-expanded`,`true`);let i=()=>n(this._more,this._menu);if(i(),e(this,i),t){let e=this._menu.firstElementChild;e instanceof HTMLElement&&e.focus()}}_close(e){this._menu&&!this._menu.hidden&&(this._menu.hidden=!0,this._more.setAttribute(`aria-expanded`,`false`),t(this),e&&this._more.focus())}_onMenuKey(e){let t=[...this._menu.children].filter(e=>e instanceof HTMLElement),n=this.ownerDocument.activeElement,r=n instanceof HTMLElement?t.indexOf(n):-1,i=null;if(e.key===`ArrowDown`)i=t[(r+1)%t.length];else if(e.key===`ArrowUp`)i=t[(r-1+t.length)%t.length];else if(e.key===`Home`)i=t[0];else if(e.key===`End`)i=t[t.length-1];else if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this._close(!0);return}else if(e.key===`Tab`){this._close(!1);return}else return;e.preventDefault(),i?.focus()}};export{p as t};
1
+ import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{t as r}from"./elementBase-Cxeyx0tU.js";var i=`data-wui-overflow-hidden`,a=`[aria-selected="true"], .active`,o=`.chip-body, input, a[href], button:not(.chip-remove)`,s=1,c=0,l=e=>Number.parseFloat(e)||0,u=e=>e.nodeType===1,d=e=>{let t=e.getAttribute(`data-overflow-label`);if(t)return t;let n=[],r=e=>{for(let t of e.childNodes)if(t.nodeType===3){let e=t.textContent?.trim();e&&n.push(e)}else u(t)&&!t.matches(`svg, img, [aria-hidden='true']`)&&r(t)};return r(e),n.join(` `)},f=e=>{if(e.matches(`button, a[href], label, input`))return e;let t=e.querySelector(o);return t instanceof HTMLElement?t:null},p=class extends r{constructor(){super(),this._hiddenKey=``,this._ro=null,this._mo=null,this._observedList=null,this._doc=null,this._onDocDown=e=>{!this._menu.hidden&&!e.composedPath().includes(this)&&this._close(!1)}}connectedCallback(){this.classList.add(`wui-overflow`),this._build(),this._doc=this.ownerDocument,this._doc.addEventListener(`pointerdown`,this._onDocDown,!0),typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(()=>this.layout()),this._ro.observe(this)),typeof MutationObserver<`u`&&(this._mo=new MutationObserver(()=>this.layout()),this._watch()),this.layout()}disconnectedCallback(){this._ro?.disconnect(),this._mo?.disconnect(),this._ro=null,this._mo=null,this._observedList=null,this._doc?.removeEventListener(`pointerdown`,this._onDocDown,!0),this._doc=null,t(this)}static get observedAttributes(){return[`label`]}attributeChangedCallback(){let e=this._more?.firstChild;e&&(e.textContent=this._label())}_label(){return this.getAttribute(`label`)||`More`}_list(){let e=this.querySelector(`[data-wui-overflow-list]`);return e instanceof HTMLElement?e:null}_items(e){return[...e.children].filter(e=>!e.hasAttribute(`data-wui-overflow-skip`))}_build(){if(this._more)return;let e=`wui-overflow-menu-${++c}`,t=this.ownerDocument.createElement(`button`);t.type=`button`,t.className=`wui-overflow-more`,t.hidden=!0,t.setAttribute(`aria-haspopup`,`menu`),t.setAttribute(`aria-expanded`,`false`),t.setAttribute(`aria-controls`,e),t.append(this._label());let n=this.ownerDocument.createElement(`div`);n.className=`wui-overflow-menu`,n.id=e,n.setAttribute(`role`,`menu`),n.hidden=!0,this.append(t,n),this._more=t,this._menu=n,t.addEventListener(`click`,()=>this._menu.hidden?this._open(!1):this._close(!0)),t.addEventListener(`keydown`,e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),this._open(!0))}),n.addEventListener(`keydown`,e=>this._onMenuKey(e))}_watch(){let e=this._list();this._mo&&e!==this._observedList&&(this._mo.disconnect(),this._observedList=e,e&&this._mo.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`class`,`aria-selected`,`disabled`,`aria-disabled`,`data-overflow-label`]}))}layout(){let e=this._list();if(this._watch(),!e||!this._more)return;let t=this._items(e);for(let e of t)e.removeAttribute(i);this._more.hidden=!0;let n=this.clientWidth,r=[];if(t.length&&n<=0&&this.getClientRects().length>0)r=t;else if(n>0&&t.length){let i=getComputedStyle(e),o=l(i.columnGap),c=l(i.paddingLeft)+l(i.paddingRight)+l(i.borderLeftWidth)+l(i.borderRightWidth),u=t.map(e=>e.offsetWidth);if(u.reduce((e,t)=>e+t,0)+o*(t.length-1)>n-c+s){this._more.hidden=!1;let e=n-c-this._more.offsetWidth-l(getComputedStyle(this).columnGap),i=this.hasAttribute(`keep`)?this.getAttribute(`keep`):a,s=/* @__PURE__ */ new Set,d=0,f=0,p=i?t.filter(e=>e.matches(i)):[];for(let n of p){let r=d+(u[t.indexOf(n)]??0)+(f?o:0);r>e||(s.add(n),d=r,f+=1)}for(let n=0;n<t.length;n+=1){let r=t[n];if(!r||s.has(r))continue;let i=d+(u[n]??0)+(f?o:0);if(i>e)break;s.add(r),d=i,f+=1}r=t.filter(e=>!s.has(e))}}for(let e of r)e.setAttribute(i,``);this._more.hidden=r.length===0,r.length?this._menu.hidden||this._fill(r):this._close(!1);let o=r.map(e=>t.indexOf(e)).join(`,`);o!==this._hiddenKey&&(this._hiddenKey=o,this.dispatchEvent(new CustomEvent(`wui-overflow-change`,{bubbles:!0,detail:{hidden:r.length}})))}_hiddenItems(){let e=this._list();return e?this._items(e).filter(e=>e.hasAttribute(i)):[]}_fill(e){this._menu.replaceChildren();for(let t of e){let e=this.ownerDocument.createElement(`button`);e.type=`button`,e.className=`wui-overflow-item`,e.tabIndex=-1;let n=t.querySelector(`input[type=checkbox], input[type=radio]`);n instanceof HTMLInputElement?(e.setAttribute(`role`,n.type===`radio`?`menuitemradio`:`menuitemcheckbox`),e.setAttribute(`aria-checked`,String(n.checked))):e.setAttribute(`role`,`menuitem`);let r=f(t),i=!r||`disabled`in r&&r.disabled||r.getAttribute(`aria-disabled`)===`true`||t.matches(`.disabled, [aria-disabled='true']`);i&&e.setAttribute(`aria-disabled`,`true`),e.textContent=d(t),e.addEventListener(`click`,()=>{i||r&&this._choose(t,r)}),this._menu.append(e)}}_choose(e,t){this._close(!1),t.click(),this.layout();let n=!e.hasAttribute(i)&&e.matches(`button, a[href]`)?e:this._more;n.hidden||n.focus()}_open(t){let r=this._hiddenItems();if(!r.length)return;this._fill(r),this._menu.hidden=!1,this._more.setAttribute(`aria-expanded`,`true`);let i=()=>n(this._more,this._menu);if(i(),e(this,i),t){let e=this._menu.firstElementChild;e instanceof HTMLElement&&e.focus()}}_close(e){this._menu&&!this._menu.hidden&&(this._menu.hidden=!0,this._more.setAttribute(`aria-expanded`,`false`),t(this),e&&this._more.focus())}_onMenuKey(e){let t=[...this._menu.children].filter(e=>e instanceof HTMLElement),n=this.ownerDocument.activeElement,r=n instanceof HTMLElement?t.indexOf(n):-1,i=null;if(e.key===`ArrowDown`)i=t[(r+1)%t.length];else if(e.key===`ArrowUp`)i=t[(r-1+t.length)%t.length];else if(e.key===`Home`)i=t[0];else if(e.key===`End`)i=t[t.length-1];else if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this._close(!0);return}else if(e.key===`Tab`){this._close(!1);return}else return;e.preventDefault(),i?.focus()}};export{p as t};
@@ -13,4 +13,4 @@ import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{n as r,t as
13
13
  <div class="phone-input-wrap">
14
14
  ${n}
15
15
  <input type="tel" class="input" placeholder="${V(e)}" value="${V(D(this._country,this._national))}"${this.getAttribute(`aria-label`)?` aria-label="${V(this.getAttribute(`aria-label`))}"`:``}${this.getAttribute(`aria-describedby`)?` aria-describedby="${V(this.getAttribute(`aria-describedby`))}"`:``}${this.hasAttribute(`required`)?` required aria-required="true"`:``}${this.hasAttribute(`disabled`)?` disabled`:``}${c(this)?` readonly`:``} />
16
- </div>`,this._rendered=!0,s(this,this.querySelector(`input.input`)),l(this,this.value),this._wire()}_ensureItems(){let e=R(this.querySelector(`.country-list-scroll`),HTMLElement);if(!e||e.querySelector(`.country-dropdown-item`))return;let t=this._listboxId,n=i.map(([e,n,r],i)=>`<button type="button" role="option" id="${V(`${t}-opt-${i}`)}" class="country-dropdown-item${e===this._country?` selected`:``}" data-iso="${e}" aria-selected="${e===this._country}"><span class="${x(e)}" aria-hidden="true"></span><span class="country-name-text">${n}<span class="country-code-text">+${r}</span></span></button>`).join(``);e.insertAdjacentHTML(`afterbegin`,n)}_itemEls(){return[...this.querySelectorAll(`.country-dropdown-item`)].filter(e=>e instanceof HTMLElement)}_visibleItems(){return this._itemEls().filter(e=>!e.hidden)}_wire(){this._teardown();let i=R(this.querySelector(`.country-toggle`),HTMLButtonElement),a=L(R(this.querySelector(`.phone-input-wrap`),HTMLElement),`phone input wrapper`),o=R(this.querySelector(`.country-dropdown-menu`),HTMLElement),s=R(this.querySelector(`.dropdown-search-input`),HTMLInputElement),l=R(this.querySelector(`.country-list-scroll`),HTMLElement),u=R(this.querySelector(`.country-empty`),HTMLElement),f=L(R(this.querySelector(`input[type=tel]`),HTMLInputElement),`phone input`),p=R(this.querySelector(`[data-flag]`),HTMLElement),m=R(this.querySelector(`[data-dial]`),HTMLElement),h=()=>!!o&&!L(o,`country menu`).hidden,g=()=>{n(a||i,o)},_=(e,{reveal:t=!0}={})=>{let n=this._visibleItems();this._active=e,d(L(l,`country list`),e>=0&&n[e]||null);let r=e>=0?n[e]:void 0;r?(t&&r.scrollIntoView({block:`nearest`}),s?.setAttribute(`aria-activedescendant`,r.id)):s?.removeAttribute(`aria-activedescendant`)},v=()=>{h()&&g()},y=()=>{if(c(this))return;this._ensureItems(),L(o,`country menu`).hidden=!1,L(i,`country toggle`).setAttribute(`aria-expanded`,`true`);let t=L(s,`country search`);t.value=``,S(``),g(),e(this,v),t.focus(),_(this._visibleItems().findIndex(e=>e.classList.contains(`selected`)))},b=()=>{L(o,`country menu`).hidden=!0,L(i,`country toggle`).setAttribute(`aria-expanded`,`false`),_(-1),t(this)},S=e=>{let t=e.trim().toLowerCase(),n=0;for(let e of this._itemEls()){let r=!t||(e.textContent??``).toLowerCase().includes(t);e.hidden=!r,r&&(n+=1)}u&&(u.hidden=n>0)},C=e=>{this._country=e,this.getAttribute(`country`)!==e&&(this._suppressCountryRender=!0,this.setAttribute(`country`,e),this._suppressCountryRender=!1),p&&(p.className=x(e)),m&&(m.textContent=`+${r(e)}`);for(let t of this._itemEls()){let n=t.dataset.iso===e;t.classList.toggle(`selected`,n),t.setAttribute(`aria-selected`,String(n))}this.getAttribute(`placeholder`)||(f.placeholder=A(e)||`Enter phone number`),this._national&&(f.value=D(e,this._national)),b(),this._syncMirror(),this._emitChange(),this._validateOnInput&&E(I()),f.focus()},w=e=>{let t=this._visibleItems();if(e.key===`ArrowDown`){if(e.preventDefault(),!h()){y();return}_(Math.min(this._active+1,t.length-1))}else if(e.key===`ArrowUp`){if(e.preventDefault(),!h())return;_(Math.max(this._active-1,0))}else if(e.key===`Enter`){e.preventDefault();let n=t[this._active];h()&&n?.dataset.iso&&C(n.dataset.iso)}else e.key===`Escape`&&h()&&(e.preventDefault(),e.stopPropagation(),b(),L(i,`country toggle`).focus())};i?.addEventListener(`click`,()=>h()?b():y()),i?.addEventListener(`keydown`,e=>{h()?w(e):(e.key===`ArrowDown`||e.key===`Enter`||e.key===` `)&&(e.preventDefault(),y())}),s&&s.addEventListener(`input`,()=>{S(s.value);let e=this._visibleItems();_(e.length?0:-1)}),l?.addEventListener(`click`,e=>{let t=R(z(e).closest(`.country-dropdown-item`),HTMLElement);t?.dataset.iso&&C(t.dataset.iso)}),l?.addEventListener(`mousemove`,e=>{let t=R(z(e).closest(`.country-dropdown-item`),HTMLElement);t&&!t.classList.contains(`is-active`)&&_(this._visibleItems().indexOf(t),{reveal:!1})}),l?.addEventListener(`mouseleave`,()=>_(-1)),o?.addEventListener(`keydown`,w);let E=e=>{f.classList.toggle(`is-invalid`,e),e?f.setAttribute(`aria-invalid`,`true`):f.removeAttribute(`aria-invalid`);let t=R(this.querySelector(`[data-phone-error]`),HTMLElement);if(e&&!this.hasAttribute(`external-error`)){t||(t=document.createElement(`div`),t.className=`field-error`,t.id=`${this.id}-phone-error`,t.setAttribute(`data-phone-error`,``),a.after(t));let e=k(this._country);t.textContent=this._country?e?`Enter a valid phone number, e.g. ${e}`:`Enter a valid phone number`:`Choose a country`}else t?.remove();this._syncDescribedBy()},I=()=>this._national.length>0&&(!this._country||j(this.value)===!1);f.addEventListener(`input`,e=>{e.stopPropagation();let t=f.selectionStart??f.value.length,n=f.value.slice(0,t).replace(/[^0-9]/g,``).length,r=f.value.replace(/[^0-9]/g,``),i=M(this._country);if(i&&r.length>i){let e=N(this._country,r,i);e?(n=Math.max(0,n-(r.length-e.length)),r=e):r=r.slice(0,i)}this._national=r;let a=D(this._country,this._national);if(f.value!==a){f.value=a;let e=O(a,Math.min(n,r.length));f.setSelectionRange(e,e)}this._syncMirror(),this._emitInput(),this._validateOnInput&&E(I())}),f.addEventListener(`change`,e=>e.stopPropagation()),f.addEventListener(`blur`,()=>{let e=I();E(e),e&&(this._validateOnInput=!0),this.value!==this._committedValue&&this._emitChange()}),f.addEventListener(`paste`,e=>{let t=e.clipboardData?.getData(`text`),n=this._locked?F(this._locked,t):P(t);n&&(e.preventDefault(),this._national=n.national.replace(/[^0-9]/g,``),n.country===this._country?f.value=D(this._country,this._national):(this._country=n.country,this.setAttribute(`country`,n.country)),this._syncMirror(),this._emitInput(),this._emitChange(),this._validateOnInput&&f.isConnected&&E(I()),R(this.querySelector(`input[type=tel]`),HTMLInputElement)?.focus())}),this._bindGlobal=()=>{this._teardownGlobals?.(),this._onDocClick=e=>{h()&&!e.composedPath().includes(this)&&b()},document.addEventListener(`click`,this._onDocClick),h()&&e(this,v)},this._teardownGlobals=()=>{this._onDocClick&&=(document.removeEventListener(`click`,this._onDocClick),null),t(this)},this._bindGlobal(),this._validateOnInput&&E(I()),T().then(e=>{if(e&&f.isConnected&&(this._national&&(f.value=D(this._country,this._national)),!this.getAttribute(`placeholder`))){let e=A(this._country);e&&(f.placeholder=e)}}),this._syncMirror()}_teardown(){this._teardownGlobals?.()}disconnectedCallback(){this._teardown()}};function L(e,t){if(e==null)throw Error(`${t} missing`);return e}function R(e,t){return e instanceof t?e:null}function z(e){if(!(e.target instanceof Element))throw Error(`Event target is not an element`);return e.target}function B(e){return typeof Reflect.get(e,`getNationalNumber`)==`function`}var V=e=>String(e??``).replace(/"/g,`&quot;`).replace(/</g,`&lt;`);export{I as t};
16
+ </div>`,this._rendered=!0,s(this,this.querySelector(`input.input`)),l(this,this.value),this._wire()}_ensureItems(){let e=R(this.querySelector(`.country-list-scroll`),HTMLElement);if(!e||e.querySelector(`.country-dropdown-item`))return;let t=this._listboxId,n=i.map(([e,n,r],i)=>`<button type="button" role="option" id="${V(`${t}-opt-${i}`)}" class="country-dropdown-item${e===this._country?` selected`:``}" data-iso="${e}" aria-selected="${e===this._country}"><span class="${x(e)}" aria-hidden="true"></span><span class="country-name-text">${n}<span class="country-code-text">+${r}</span></span></button>`).join(``);e.insertAdjacentHTML(`afterbegin`,n)}_itemEls(){return[...this.querySelectorAll(`.country-dropdown-item`)].filter(e=>e instanceof HTMLElement)}_visibleItems(){return this._itemEls().filter(e=>!e.hidden)}_wire(){this._teardown();let i=R(this.querySelector(`.country-toggle`),HTMLButtonElement),a=L(R(this.querySelector(`.phone-input-wrap`),HTMLElement),`phone input wrapper`),o=R(this.querySelector(`.country-dropdown-menu`),HTMLElement),s=R(this.querySelector(`.dropdown-search-input`),HTMLInputElement),l=R(this.querySelector(`.country-list-scroll`),HTMLElement),u=R(this.querySelector(`.country-empty`),HTMLElement),f=L(R(this.querySelector(`input[type=tel]`),HTMLInputElement),`phone input`),p=R(this.querySelector(`[data-flag]`),HTMLElement),m=R(this.querySelector(`[data-dial]`),HTMLElement),h=()=>!!o&&!L(o,`country menu`).hidden,g=()=>{n(a||i,o)},_=(e,{reveal:t=!0}={})=>{let n=this._visibleItems();this._active=e,d(L(l,`country list`),e>=0&&n[e]||null);let r=e>=0?n[e]:void 0;r?(t&&r.scrollIntoView({block:`nearest`}),s?.setAttribute(`aria-activedescendant`,r.id)):s?.removeAttribute(`aria-activedescendant`)},v=()=>{h()&&g()},y=()=>{if(c(this))return;this._ensureItems(),L(o,`country menu`).hidden=!1,L(i,`country toggle`).setAttribute(`aria-expanded`,`true`);let t=L(s,`country search`);t.value=``,S(``),g(),e(this,v),t.focus(),_(this._visibleItems().findIndex(e=>e.classList.contains(`selected`)))},b=()=>{L(o,`country menu`).hidden=!0,L(i,`country toggle`).setAttribute(`aria-expanded`,`false`),_(-1),t(this)},S=e=>{let t=e.trim().toLowerCase(),n=0;for(let e of this._itemEls()){let r=!t||(e.textContent??``).toLowerCase().includes(t);e.hidden=!r,r&&(n+=1)}u&&(u.hidden=n>0)},C=e=>{this._country=e,this.getAttribute(`country`)!==e&&(this._suppressCountryRender=!0,this.setAttribute(`country`,e),this._suppressCountryRender=!1),p&&(p.className=x(e)),m&&(m.textContent=`+${r(e)}`);for(let t of this._itemEls()){let n=t.dataset.iso===e;t.classList.toggle(`selected`,n),t.setAttribute(`aria-selected`,String(n))}this.getAttribute(`placeholder`)||(f.placeholder=A(e)||`Enter phone number`),this._national&&(f.value=D(e,this._national)),b(),this._syncMirror(),this._emitChange(),this._validateOnInput&&E(I()),f.focus()},w=e=>{let t=this._visibleItems();if(e.key===`ArrowDown`){if(e.preventDefault(),!h()){y();return}_(Math.min(this._active+1,t.length-1))}else if(e.key===`ArrowUp`){if(e.preventDefault(),!h())return;_(Math.max(this._active-1,0))}else if(e.key===`Enter`){e.preventDefault();let n=t[this._active];h()&&n?.dataset.iso&&C(n.dataset.iso)}else e.key===`Escape`&&h()&&(e.preventDefault(),e.stopPropagation(),b(),L(i,`country toggle`).focus())};i?.addEventListener(`click`,()=>h()?b():y()),i?.addEventListener(`keydown`,e=>{h()?w(e):(e.key===`ArrowDown`||e.key===`Enter`||e.key===` `)&&(e.preventDefault(),y())}),s&&s.addEventListener(`input`,()=>{S(s.value);let e=this._visibleItems();_(e.length?0:-1)}),l?.addEventListener(`click`,e=>{let t=R(z(e).closest(`.country-dropdown-item`),HTMLElement);t?.dataset.iso&&C(t.dataset.iso)}),l?.addEventListener(`mousemove`,e=>{let t=R(z(e).closest(`.country-dropdown-item`),HTMLElement);t&&!t.classList.contains(`is-active`)&&_(this._visibleItems().indexOf(t),{reveal:!1})}),l?.addEventListener(`mouseleave`,()=>_(-1)),o?.addEventListener(`keydown`,w);let E=e=>{f.classList.toggle(`is-invalid`,e),e?f.setAttribute(`aria-invalid`,`true`):f.removeAttribute(`aria-invalid`);let t=R(this.querySelector(`[data-phone-error]`),HTMLElement);if(e&&!this.hasAttribute(`external-error`)){t||(t=document.createElement(`div`),t.className=`field-error`,t.id=`${this.id}-phone-error`,t.setAttribute(`data-phone-error`,``),a.after(t));let e=k(this._country);t.textContent=this._country?e?`Enter a valid phone number, e.g. ${e}`:`Enter a valid phone number`:`Choose a country`}else t?.remove();this._syncDescribedBy()},I=()=>this._national.length>0&&(!this._country||j(this.value)===!1);f.addEventListener(`input`,e=>{e.stopPropagation();let t=f.selectionStart??f.value.length,n=f.value.slice(0,t).replace(/[^0-9]/g,``).length,r=f.value.replace(/[^0-9]/g,``),i=M(this._country);if(i&&r.length>i){let e=N(this._country,r,i);e?(n=Math.max(0,n-(r.length-e.length)),r=e):r=r.slice(0,i)}this._national=r;let a=D(this._country,this._national);if(f.value!==a){f.value=a;let e=O(a,Math.min(n,r.length));f.setSelectionRange(e,e)}this._syncMirror(),this._emitInput(),this._validateOnInput&&E(I())}),f.addEventListener(`change`,e=>e.stopPropagation()),f.addEventListener(`blur`,()=>{let e=I();E(e),e&&(this._validateOnInput=!0),this.value!==this._committedValue&&this._emitChange()}),f.addEventListener(`paste`,e=>{let t=e.clipboardData?.getData(`text`),n=this._locked?F(this._locked,t):P(t);n&&(e.preventDefault(),this._national=n.national.replace(/[^0-9]/g,``),n.country===this._country?f.value=D(this._country,this._national):(this._country=n.country,this.setAttribute(`country`,n.country)),this._syncMirror(),this._emitInput(),this._emitChange(),this._validateOnInput&&f.isConnected&&E(I()),R(this.querySelector(`input[type=tel]`),HTMLInputElement)?.focus())}),this._bindGlobal=()=>{this._teardownGlobals?.(),this._onDocClick=e=>{h()&&!e.composedPath().includes(this)&&b()},document.addEventListener(`click`,this._onDocClick),h()&&e(this,v)},this._teardownGlobals=()=>{this._onDocClick&&=(document.removeEventListener(`click`,this._onDocClick),null),t(this)},this._bindGlobal(),this._validateOnInput&&E(I()),T().then(e=>{if(e&&f.isConnected&&(this._national&&(f.value=D(this._country,this._national)),!this.getAttribute(`placeholder`))){let e=A(this._country);e&&(f.placeholder=e)}}),this._syncMirror()}_teardown(){this._teardownGlobals?.()}disconnectedCallback(){this._teardown()}};function L(e,t){if(e==null)throw Error(`${t} missing`);return e}function R(e,t){return e instanceof t?e:null}function z(e){if(!(e.target instanceof Element))throw Error(`Event target is not an element`);return e.target}function B(e){return`getNationalNumber`in e&&typeof e.getNationalNumber==`function`}var V=e=>String(e??``).replace(/"/g,`&quot;`).replace(/</g,`&lt;`);export{I as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./relativeTime-YTAOONRy.js";var n=3e4,r=/* @__PURE__ */ new Set,i=null,a=()=>{if(!(typeof document<`u`&&document.hidden))for(let e of r)e.refresh()},o=e=>{r.add(e),r.size===1&&(i=setInterval(a,n),document.addEventListener(`visibilitychange`,a))},s=e=>{r.delete(e),r.size===0&&(clearInterval(i??void 0),i=null,document.removeEventListener(`visibilitychange`,a))},c=class extends e{_observer;constructor(){super(),this._observer=null}connectedCallback(){this.refresh(),o(this),this._observer=new MutationObserver(()=>this.refresh()),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`datetime`]})}disconnectedCallback(){s(this),this._observer?.disconnect(),this._observer=null}refresh(){let e=this.querySelector(`time[datetime]`);if(!(e instanceof HTMLTimeElement))return;let n=t(e.getAttribute(`datetime`));e.textContent!==n&&(e.textContent=n)}};export{c as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./relativeTime-BahImc8F.js";var n=3e4,r=/* @__PURE__ */ new Set,i=null,a=()=>{if(!(typeof document<`u`&&document.hidden))for(let e of r)e.refresh()},o=e=>{r.add(e),r.size===1&&(i=setInterval(a,n),document.addEventListener(`visibilitychange`,a))},s=e=>{r.delete(e),r.size===0&&(clearInterval(i??void 0),i=null,document.removeEventListener(`visibilitychange`,a))},c=class extends e{_observer;constructor(){super(),this._observer=null}connectedCallback(){this.refresh(),o(this),this._observer=new MutationObserver(()=>this.refresh()),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`datetime`]})}disconnectedCallback(){s(this),this._observer?.disconnect(),this._observer=null}refresh(){let e=this.querySelector(`time[datetime]`);if(!(e instanceof HTMLTimeElement))return;let n=t(e.getAttribute(`datetime`));e.textContent!==n&&(e.textContent=n)}};export{c as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{m as t}from"./formatters-C3V6M5zV.js";var n=/^[0-9]$/,r=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=class extends e{_connected;_signature;_digits;_reels;_roll;_onRollEnd;static get observedAttributes(){return[`value`,`format`,`unit`,`decimals`,`duration`]}constructor(){super(),this._connected=!1,this._signature=null,this._digits=[],this._reels=[],this._roll=null,this._onRollEnd=e=>{e.target instanceof Element&&e.target.classList.contains(`wui-rolling-number-reel`)&&this.removeAttribute(`data-rolling`)}}connectedCallback(){this._connected=!0;let e=this.querySelector(`.wui-rolling-number-roll`);this._roll=e instanceof HTMLElement?e:null,this._roll?.addEventListener(`transitionend`,this._onRollEnd),this._draw(!1)}disconnectedCallback(){this._connected=!1,this._roll?.removeEventListener(`transitionend`,this._onRollEnd)}attributeChangedCallback(){this._connected&&this._draw(!0)}_text(){let e=this.getAttribute(`value`),n=e===null||e.trim()===``?NaN:Number(e);if(!Number.isFinite(n))return null;let r=this.getAttribute(`decimals`);return t(n,{style:this.getAttribute(`format`)||`number`,unit:this.getAttribute(`unit`)||void 0,decimals:r===null||r===``?void 0:Number(r)})}_showText(e){let t=this.querySelector(`.wui-rolling-number-text`);t instanceof HTMLElement&&t.textContent!==e&&(t.firstChild?t.firstChild.nodeValue=e:t.append(e))}_clear(e){e.replaceChildren(),this.removeAttribute(`data-ready`),this._signature=null,this._digits=[],this._reels=[]}_draw(e){let t=this.querySelector(`.wui-rolling-number-roll`);if(!(t instanceof HTMLElement))return;let i=this._text();if(i===null||(this._showText(i),r())){this._clear(t);return}this.toggleAttribute(`data-rolling`,e);let a=Number(this.getAttribute(`duration`));this.getAttribute(`duration`)&&Number.isFinite(a)&&a>=0?this.style.setProperty(`--wui-roll-duration`,`${a}ms`):this.style.removeProperty(`--wui-roll-duration`);let o=[...i],s=o.filter(e=>n.test(e)).map(Number),c=o.map(e=>n.test(e)?`#`:e).join(``);if(e&&c===this._signature){this._reels.forEach((e,t)=>{e.style.setProperty(`--wui-roll-digit`,String(s[t]))}),this._digits=s;return}let l=this._digits,u=[],d=[],f=0;for(let t of o){if(!n.test(t)){let e=document.createElement(`span`);e.className=`wui-rolling-number-char`,e.textContent=t,d.push(e);continue}let r=document.createElement(`span`);r.className=`wui-rolling-number-digit`;let i=document.createElement(`span`);i.className=`wui-rolling-number-reel`;for(let e=0;e<10;e+=1){let t=document.createElement(`span`);t.textContent=String(e),i.append(t)}let a=s.length-1-f,o=e?l[l.length-1-a]??0:s[f];i.style.setProperty(`--wui-roll-digit`,String(o)),r.append(i),d.push(r),u.push(i),f+=1}t.replaceChildren(...d),e&&(t.offsetWidth,u.forEach((e,t)=>{e.style.setProperty(`--wui-roll-digit`,String(s[t]))})),this._signature=c,this._digits=s,this._reels=u,this.setAttribute(`data-ready`,``)}};export{i as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{m as t}from"./formatters-ljfITOZ3.js";var n=/^[0-9]$/,r=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=class extends e{_connected;_signature;_digits;_reels;_roll;_onRollEnd;static get observedAttributes(){return[`value`,`format`,`unit`,`decimals`,`duration`]}constructor(){super(),this._connected=!1,this._signature=null,this._digits=[],this._reels=[],this._roll=null,this._onRollEnd=e=>{e.target instanceof Element&&e.target.classList.contains(`wui-rolling-number-reel`)&&this.removeAttribute(`data-rolling`)}}connectedCallback(){this._connected=!0;let e=this.querySelector(`.wui-rolling-number-roll`);this._roll=e instanceof HTMLElement?e:null,this._roll?.addEventListener(`transitionend`,this._onRollEnd),this._draw(!1)}disconnectedCallback(){this._connected=!1,this._roll?.removeEventListener(`transitionend`,this._onRollEnd)}attributeChangedCallback(){this._connected&&this._draw(!0)}_text(){let e=this.getAttribute(`value`),n=e===null||e.trim()===``?NaN:Number(e);if(!Number.isFinite(n))return null;let r=this.getAttribute(`decimals`);return t(n,{style:this.getAttribute(`format`)||`number`,unit:this.getAttribute(`unit`)||void 0,decimals:r===null||r===``?void 0:Number(r)})}_showText(e){let t=this.querySelector(`.wui-rolling-number-text`);t instanceof HTMLElement&&t.textContent!==e&&(t.firstChild?t.firstChild.nodeValue=e:t.append(e))}_clear(e){e.replaceChildren(),this.removeAttribute(`data-ready`),this._signature=null,this._digits=[],this._reels=[]}_draw(e){let t=this.querySelector(`.wui-rolling-number-roll`);if(!(t instanceof HTMLElement))return;let i=this._text();if(i===null||(this._showText(i),r())){this._clear(t);return}this.toggleAttribute(`data-rolling`,e);let a=Number(this.getAttribute(`duration`));this.getAttribute(`duration`)&&Number.isFinite(a)&&a>=0?this.style.setProperty(`--wui-roll-duration`,`${a}ms`):this.style.removeProperty(`--wui-roll-duration`);let o=[...i],s=o.filter(e=>n.test(e)).map(Number),c=o.map(e=>n.test(e)?`#`:e).join(``);if(e&&c===this._signature){this._reels.forEach((e,t)=>{e.style.setProperty(`--wui-roll-digit`,String(s[t]))}),this._digits=s;return}let l=this._digits,u=[],d=[],f=0;for(let t of o){if(!n.test(t)){let e=document.createElement(`span`);e.className=`wui-rolling-number-char`,e.textContent=t,d.push(e);continue}let r=document.createElement(`span`);r.className=`wui-rolling-number-digit`;let i=document.createElement(`span`);i.className=`wui-rolling-number-reel`;for(let e=0;e<10;e+=1){let t=document.createElement(`span`);t.textContent=String(e),i.append(t)}let a=s.length-1-f,o=e?l[l.length-1-a]??0:s[f];i.style.setProperty(`--wui-roll-digit`,String(o)),r.append(i),d.push(r),u.push(i),f+=1}t.replaceChildren(...d),e&&(t.offsetWidth,u.forEach((e,t)=>{e.style.setProperty(`--wui-roll-digit`,String(s[t]))})),this._signature=c,this._digits=s,this._reels=u,this.setAttribute(`data-ready`,``)}};export{i as t};
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{t as n}from"./elementBase-Cxeyx0tU.js";import{l as r}from"./wuiHttp-DGbD7Fra.js";var i=`wui-saved-views:`,a=20,o=0,s=e=>typeof e==`object`&&!!e&&`name`in e&&typeof e.name==`string`&&`query`in e&&typeof e.query==`string`,c=class extends n{static get observedAttributes(){return[`key`,`mode`,`action`,`can-share`]}_doc=null;_dom=null;_views;_open;_busy;_error;_trigger;_onTriggerClick;_onKeyDown;_onPointerDown;_onSubmit;constructor(){super(),this._views=[],this._open=!1,this._busy=!1,this._error=null,this._onTriggerClick=()=>this._setOpen(!this._open),this._onKeyDown=e=>{this._open&&e.target instanceof Node&&this.contains(e.target)&&(e.key===`Escape`?(e.stopPropagation(),this._setOpen(!1),this._trigger?.focus()):(e.key===`ArrowDown`||e.key===`ArrowUp`)&&this._ui.menu.contains(e.target)&&!(e.target instanceof Element&&/input|textarea/i.test(e.target.tagName))&&(e.preventDefault(),e.stopPropagation()))},this._onPointerDown=e=>{this._open&&!e.composedPath().includes(this)&&this._setOpen(!1)},this._onSubmit=async e=>{e.preventDefault();let t=this._ui.input.value.trim();if(!t)return;if(this._server()){if(this._busy)return;let e={name:t,query:this._ownerDoc.location.search};this._canShare()&&(e.shared=String(this._ui.share.checked)),await this._request(`save`,e)&&(this._ui.input.value=``,this._ui.share.checked=!1);return}let n=this._ownerDoc.location.search;this._commit([{name:t,query:n},...this._views.filter(e=>e.name!==t)].slice(0,a)),this._ui.input.value=``}}get _ownerDoc(){if(!this._doc)throw Error(`wui-saved-views is not connected`);return this._doc}get _ui(){if(!this._dom)throw Error(`wui-saved-views is not built`);return this._dom}connectedCallback(){this._doc=this.ownerDocument,this._trigger||this._build(),window.addEventListener(`keydown`,this._onKeyDown,!0),this._reload()}disconnectedCallback(){this._setOpen(!1),window.removeEventListener(`keydown`,this._onKeyDown,!0),this._doc=null}attributeChangedCallback(){this._doc&&this._trigger&&this._reload()}_reload(){this._server()?(this._views=[],this._render(),this._request(`list`)):(this._views=this._load(),this._render())}_server(){return this.getAttribute(`mode`)===`server`&&!!this.getAttribute(`action`)&&!!this.getAttribute(`key`)}_canShare(){return this._server()&&this.getAttribute(`can-share`)===`true`}async _request(e,t={}){let n=this.getAttribute(`action`)??``,i=this.getAttribute(`key`)??``,a=n,o;e===`list`?a+=(n.includes(`?`)?`&`:`?`)+new URLSearchParams({intent:`list`,key:i}):o={method:`POST`,body:new URLSearchParams({intent:e,key:i,...t})},this._busy=!0,this._render();let c=await r(a,o);if(this._busy=!1,this._doc===null)return!1;if(c.ok){let e=new DOMParser().parseFromString(c.html,`text/html`);return this._views=[...e.querySelectorAll(`[data-wui-saved-views-items] > li`)].filter(e=>e instanceof HTMLLIElement).map(e=>({name:e.dataset.name,query:e.dataset.query,shared:e.dataset.shared===`true`})).filter(s),this._error=null,this._render(),!0}return this._error=c.message||`The views could not be updated. Try again.`,this._render(),!1}_build(){let n=this._ownerDoc;this.classList.add(`dropdown`),this._trigger=n.createElement(`button`),this._trigger.type=`button`,this._trigger.className=e(`neutral`,`outline`,`sm`),this._trigger.dataset.wui=t,this._trigger.textContent=`Views`,this._trigger.setAttribute(`aria-haspopup`,`true`),this._trigger.setAttribute(`aria-expanded`,`false`),this._trigger.addEventListener(`click`,this._onTriggerClick);let r=n.createElement(`div`);r.className=`dropdown-menu`;let i=n.createElement(`div`);i.className=`dropdown-divider`;let a=n.createElement(`input`);a.type=`text`,a.className=`form-control form-control-sm`,a.setAttribute(`aria-label`,`View name`),a.placeholder=`Name this view`;let s=n.createElement(`button`);s.type=`submit`,s.className=e(`primary`,`solid`,`sm`),s.dataset.wui=t,s.textContent=`Save this view`;let c=n.createElement(`form`);c.className=`d-flex gap-2 px-3 py-2`,c.append(a,s),c.addEventListener(`submit`,this._onSubmit);let l=n.createElement(`input`);l.type=`checkbox`,l.className=`form-check-input`,l.setAttribute(`role`,`switch`),l.id=`wui-saved-views-share-${o++}`;let u=n.createElement(`label`);u.className=`form-check-label`,u.htmlFor=l.id,u.textContent=`Share with the team`;let d=n.createElement(`div`);d.className=`form-check form-switch mb-0`,d.append(l,u);let f=n.createElement(`div`);f.className=`px-3 pb-2`,f.hidden=!0,f.append(d),this._dom={menu:r,divider:i,form:c,input:a,save:s,shareRow:f,share:l},this.append(this._trigger,r)}_render(){let e=this._ownerDoc,t=this._ui,n=[];for(let t of this._views){let r=e.createElement(`a`);if(r.className=`dropdown-item`,r.setAttribute(`href`,e.location.pathname+t.query),r.textContent=t.name,t.shared){let t=e.createElement(`span`);t.className=`badge text-bg-secondary ms-2`,t.textContent=`Shared`,r.append(t)}let i=e.createElement(`button`);i.type=`button`,i.className=`btn btn-link btn-sm`,i.textContent=`Delete`,i.setAttribute(`aria-label`,`Delete ${t.name}`),i.disabled=this._busy,i.addEventListener(`click`,()=>this._server()?this._request(`delete`,{name:t.name}):this._commit(this._views.filter(e=>e.name!==t.name))),n.push(r,i)}if(this._error){let t=e.createElement(`div`);t.className=`dropdown-item-text text-danger small`,t.setAttribute(`role`,`alert`),t.textContent=this._error,n.push(t)}t.save.disabled=this._busy,t.share.disabled=this._busy,t.shareRow.hidden=!this._canShare(),t.menu.replaceChildren(...n,t.divider,t.form,t.shareRow)}_commit(e){this._views=e,this._write(e),this._render()}_setOpen(e){e!==this._open&&(this._open=e,this._ui.menu.classList.toggle(`show`,e),this._trigger?.setAttribute(`aria-expanded`,String(e)),e?this._ownerDoc.addEventListener(`pointerdown`,this._onPointerDown,!0):this._ownerDoc.removeEventListener(`pointerdown`,this._onPointerDown,!0))}_storage(){let e=this.getAttribute(`key`);if(!e)return null;try{let t=this._ownerDoc.defaultView;return t?{store:t.localStorage,key:i+e}:null}catch{return null}}_load(){let e=this._storage();if(!e)return[];try{let t=JSON.parse(e.store.getItem(e.key)??`[]`);return Array.isArray(t)?t.filter(s).slice(0,a):[]}catch{return[]}}_write(e){let t=this._storage();if(t)try{t.store.setItem(t.key,JSON.stringify(e))}catch{}}};export{c as t};
@@ -0,0 +1,9 @@
1
+ import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{i as r,n as i,r as a,t as o}from"./optionLabel-4xjXWy74.js";import{n as s}from"./devWarn-DXdRWZs3.js";import{r as c}from"./dom-Do1pAA12.js";import{t as l}from"./elementBase-Cxeyx0tU.js";import{r as u,t as d}from"./fieldState-D-zQcXUS.js";import{n as f,t as p}from"./formMirror-9IpSgeZb.js";import{n as m}from"./loader-ByHAB1wi.js";import{t as h}from"./iconGlyphs.g-DPqoOoXy.js";import{n as g,t as _}from"./listboxKeyNav-4LeEjKq6.js";var v=e=>{let t=String(e??``).trim();return/^(https?:)?\/\//i.test(t)||/^\/(?!\/)/.test(t)||/^data:image\/(png|jpe?g|gif|webp|avif);/i.test(t)?t:``},y=(e,t=`wui-opt-avatar`)=>{let n=v(e.avatar);return!n&&!e.initials?``:`<span class="avatar ${t}" aria-hidden="true"><span class="avatar-face">${i(e.initials??``)}</span>${n?`<img class="avatar-img" src="${b(n)}" alt="" />`:``}</span>`},b=e=>String(e??``).replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`);function x(e,t){let n=String(t??``).trim().toLowerCase();return n?e.filter(e=>[r(e),e.description,e.meta].some(e=>String(e??``).toLowerCase().includes(n))):e}var S=/* @__PURE__ */ new WeakMap;function C(e,t,n={}){let{selected:r=[],query:a=``,status:o=`idle`,emptyText:s=`No matches`,searchingText:c=`Searching…`,hintText:l=`Type to search…`,actionRow:u=[],recents:d=null}=n,f=new Set(r.map(String)),p=x(t,a),m=e.id,h=0,g=()=>`${m}-opt-${h++}`,_=e=>`<button type="button" role="option" id="${i(g())}" class="wui-select-option wui-select-add" data-value="${i(e.value)}" data-custom="true" aria-selected="false">${i(e.label)}</button>`,v=u.filter(e=>e.position===`top`).map(_).join(``),y=d?.options.length?`<div class="wui-select-group">${i(d.label)}</div>${d.options.map(e=>w(e,g(),f.has(String(e.value)))).join(``)}<div class="wui-select-sep" aria-hidden="true"></div>`:``,b=``,C=``;for(let e of p)e.group&&e.group!==b&&(C+=`<div class="wui-select-group">${i(e.group)}</div>`),b=e.group??``,C+=w(e,g(),f.has(String(e.value)));let T=u.filter(e=>e.position===`bottom`).map(_).join(``),E=``;o===`loading`?E=`<div class="wui-select-loading"><span class="wui-select-spinner spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>${i(c)}</div>`:o===`hint`?E=`<div class="wui-select-hint">${i(l)}</div>`:(o===`empty`||p.length===0&&u.length===0)&&(E=`<div class="wui-select-empty">${i(s)}</div>`);let D=v+y+C+T+E;S.get(e)!==D&&(S.set(e,D),e.innerHTML=D)}function w(e,t,n){let r=!!e.disabled,o=r&&e.disabledHint?` title="${i(e.disabledHint)}"`:``,s=`id="${i(t)}" role="option" data-value="${i(e.value)}" aria-selected="${n}"${r?` aria-disabled="true"`:``}${o}`,c=`<span class="wui-select-check" aria-hidden="true">${h(`check`)}</span>`;if(!e.description&&!e.meta)return`<button type="button" class="wui-select-option${n?` selected`:``}" ${s}>${y(e)}<span class="wui-select-opt-name">${a(e)}</span>${c}</button>`;let l=e.description?`<span class="wui-select-opt-desc">${i(e.description)}</span>`:``,u=e.meta?`<span class="wui-select-opt-meta">${i(e.meta)}</span>`:``;return`<div class="wui-select-option wui-select-option-rich${n?` selected`:``}" ${s}>${y(e)}<span class="wui-select-option-text"><span class="wui-opt-label">${a(e)}</span>${l}</span>${u}${c}</div>`}var T=Object.freeze([`single`,`multiple`,`search`,`tag`,`country`]),E=e=>e===`multiple`||e===`tag`,D={recents:()=>import(`./recents-CmLLdV8O.js`),chips:()=>import(`./chips-Dony2fgq.js`),search:()=>import(`./search-C8xIzt6h.js`),country:()=>import(`./country-x5lqC5Xu.js`)};function O(e){let t=Object.hasOwn(D,e)?D[e]:void 0;return t?t():Promise.reject(/* @__PURE__ */ Error(`Unknown <wui-select> part: ${e}.`))}var k=e=>typeof e.loadOptions==`function`||!!e.getAttribute(`source`)||e.hasAttribute(`remote`),A=class extends l{static formAssociated=!0;_internals;_value;_optionsProp;_partOptions;_known;_loadOptionsFn;_validateFn;_declared;_query;_ownsFilter;_active;_status;_error;_nav;_parts;_partSig;_partsMounted;_partToken;_rendered;_searchShown;_defaultValue;_warnedMode;_warnedDensity;_reposition;_hoverTimer;_hoverOpened;_onHoverOver;_onHoverOut;_onDocClick;_bindGlobal=()=>{throw Error(`The select is not wired.`)};_reanchor;_reanchorScroll;static get observedAttributes(){return/* @__PURE__ */ `mode.value.placeholder.search-placeholder.empty-text.searchable.clearable.disabled.readonly.loading.required.size.density.icon.prefix.open.open-on-hover.aria-label.aria-describedby.aria-invalid.min-chars.debounce.source.remote.allow-custom.add-label.searching-text.hint-text.value-label.value-avatar.value-initials.max-tags.allow-duplicates.separators.pattern.invalid-message.create-label.collapse-chips.selected-text.clear-all-label.countries.suggested.suggested-label.all-countries-label.recents-key.recents-limit.recents-label`.split(`.`)}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._value=``,this._optionsProp=null,this._partOptions=null,this._known=/* @__PURE__ */ new Map,this._loadOptionsFn=null,this._validateFn=null,this._declared=void 0,this._query=``,this._ownsFilter=!1,this._active=-1,this._status=`idle`,this._error=``,this._nav=null,this._parts=null,this._partSig=``,this._partsMounted=!1,this._partToken=0,this._rendered=!1,this._searchShown=!1,this._defaultValue=void 0,this._warnedMode=null,this._reposition=()=>{this._menuOpen()&&this._place()},this._hoverTimer=null,this._hoverOpened=!1,this._onHoverOver=e=>{e.pointerType===`mouse`&&this._hoverZone(e.target)&&(this._clearHover(),!this._menuOpen()&&this._hoverEligible()&&(this._hoverTimer=setTimeout(()=>{this._hoverTimer=null,!this._menuOpen()&&this._hoverEligible()&&(this._open({focus:!1}),this._hoverOpened=!0)},P)))},this._onHoverOut=e=>{e.pointerType===`mouse`&&this._hoverZone(e.target)&&!this._hoverZone(e.relatedTarget)&&(this._clearHover(),this._menuOpen()&&this.hasAttribute(`open-on-hover`)&&(this._hoverTimer=setTimeout(()=>{this._hoverTimer=null,this._close()},F)))}}connectedCallback(){this.addEventListener(`pointerover`,this._onHoverOver),this.addEventListener(`pointerout`,this._onHoverOut),this._rendered?this._bindGlobal():this.render(),this._ensureParts(),this._mountParts()}disconnectedCallback(){this.removeEventListener(`pointerover`,this._onHoverOver),this.removeEventListener(`pointerout`,this._onHoverOut),this._clearHover(),this._teardown(),this._teardownParts()}attributeChangedCallback(e,t,n){e===`value`?(this._value=V(n,E(this.mode)),this._applyValue()):e===`aria-invalid`?this._syncInvalid():e===`open`?this._rendered&&(this.hasAttribute(`open`)?this._open({focus:!1}):this._close({force:!0})):e===`open-on-hover`?this.hasAttribute(`open-on-hover`)||this._clearHover():(e===`mode`&&(this._value=V(this._value,E(this.mode)),this._partOptions=null,this._known.clear(),this._ensureParts()),(e===`source`||e===`remote`||e===`recents-key`)&&this._ensureParts(),z.has(e)?this._rendered&&(this._drawValue(),this.renderList()):R.has(e)?this._remountParts():this._rendered&&this.render())}formResetCallback(){if(this.value=this._defaultValue??``,!this._rendered)return;let e=this._refs();e.input&&(e.input.value=``,e.input.removeAttribute(`aria-invalid`)),e.search&&(e.search.value=``),this.setError(``),this._query!==``&&this._onQueryChange(``)}get mode(){let e=this.getAttribute(`mode`);return e===null?`single`:M(e)?e:(e!==this._warnedMode&&(this._warnedMode=e,s(`<wui-select> mode "${e}" is not one of ${T.join(`, `)}; it is treated as "single".`)),`single`)}_checkDensity(){let e=this.getAttribute(`density`);e===null||N.includes(e)||e===this._warnedDensity||(this._warnedDensity=e,s(`<wui-select> density "${e}" is not one of ${N.join(`, `)}; it is treated as "comfortable".`))}set mode(e){this.setAttribute(`mode`,String(e))}get value(){return Array.isArray(this._value)?this._value.slice():this._value}set value(e){this._value=V(e,E(this.mode)),this._applyValue()}get options(){return this._readOptions()}set options(e){this._optionsProp=Array.isArray(e)?e:null,this.mode!==`country`&&(this._partOptions=null);for(let e of this._activePartsList())e.onOptions?.();if(this._rendered){if(this.mode===`single`&&this.getAttribute(`searchable`)===null&&this._autoSearch()!==this._searchShown){this.render();return}this._drawValue(),this.renderList()}}get loadOptions(){return this._loadOptionsFn}set loadOptions(e){this._loadOptionsFn=typeof e==`function`?e:null,this._ensureParts()}get validate(){return this._validateFn}set validate(e){this._validateFn=typeof e==`function`?e:null}commit(e,t={}){this.value=e,this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,detail:{isCustom:!!t.isCustom}}))}setPartOptions(e){this._partOptions=Array.isArray(e)?e:null,this._drawValue(),this.renderList()}setStatus(e){this._status=e,this.renderList()}setError(e){this._error=e?String(e):``,this._syncError()}openMenu(){d(this)||this._open({focus:!1})}closeMenu({focusControl:e=!1}={}){this._close(),e&&this._refs().control?.focus()}renderList(){let e=this._refs();e.list&&(C(e.list,this._listOptions(),{selected:this._selectedValues(),query:this._ownsFilter?``:this._query,status:this._status,emptyText:this.getAttribute(`empty-text`)||`No matches`,searchingText:this.getAttribute(`searching-text`)||`Searching…`,hintText:this.getAttribute(`hint-text`)||void 0,actionRow:this._actionRows(),recents:this._recents()}),this._active>=this._visible().length&&(this._active=-1),this._active>=0&&this._setActive(this._active,{reveal:!1}),this._menuOpen()&&this._place())}render(){let e=this._carry();this._teardownParts(),this._snapshotDeclared();let t=this.mode;this._checkDensity();let n=E(t),r=t===`tag`,a=n&&(r||this.hasAttribute(`allow-custom`));this._value=V(this._value,n),this._defaultValue===void 0&&n&&this._value.length===0&&(this._value=this._declaredSelected()),n||this._preselect(),this._defaultValue===void 0&&(this._defaultValue=V(this._value,n));let o=this.getAttribute(`size`),s=o===`sm`?` wui-select-sm`:o===`lg`?` wui-select-lg`:``,c=this.getAttribute(`icon`),l=this.getAttribute(`prefix`),d=this.hasAttribute(`clearable`),f=this.hasAttribute(`disabled`);this.id||=`wui-select-${Math.random().toString(36).slice(2,9)}`;let p=`${this.id}-listbox`,m=`${this.id}-entry-error`,g=this.getAttribute(`aria-describedby`)?.trim(),_=g?`${g} ${m}`:m,v=this.hasAttribute(`aria-invalid`)||this._error?` aria-invalid="true"`:``,y=this.hasAttribute(`required`)&&!a?` aria-required="true"`:``,b=` aria-label="${i(this._accessibleName())}" aria-describedby="${i(_)}"${v}${y}`,x=a?``:` role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="${i(p)}"`,S=n?`<div class="input wui-select-control wui-select-multi"${x}${b}${f?` aria-disabled="true"`:r?``:` tabindex="0"`}>`:`<button type="button" class="input wui-select-control"${x}${b}${f?` disabled`:``}>`,C=`${c?h(c,{className:`wui-select-icon`}):``}${l?`<span class="wui-select-prefix">${i(l)}</span>`:``}<span class="wui-select-value" data-label></span>${d?`<span class="wui-select-reset" role="button" aria-label="Clear selection" hidden>${h(`x`)}</span>`:``}${h(`chevron-down`,{className:`wui-select-caret`})}`,w=this.getAttribute(`searchable`),T=w===null?t===`multiple`||t===`country`||this._autoSearch():w!==`false`,D=t===`search`||T&&!a;this._searchShown=D;let O=this.getAttribute(`search-placeholder`)||(t===`country`?`Search countries…`:`Search…`),k=D?`<div class="wui-select-search">${h(`search`)}<input class="wui-select-input" placeholder="${i(O)}" aria-label="${i(O)}" aria-autocomplete="list" /><button type="button" class="wui-select-clear" aria-label="Clear search" hidden>${h(`x`)}</button></div>`:``;this.innerHTML=`
2
+ <div class="wui-select${s}">
3
+ ${S}${C}${n?`</div>`:`</button>`}
4
+ <div class="wui-select-menu wui-select-menu-fixed" hidden>
5
+ ${k}
6
+ <div class="wui-select-options" role="listbox" id="${i(p)}" tabindex="-1"${n?` aria-multiselectable="true"`:``}></div>
7
+ </div>
8
+ </div>
9
+ <div class="field-error wui-select-error" id="${i(m)}" aria-live="polite"${this._error?``:` hidden`}>${i(this._error)}</div>`,this._rendered=!0,this._syncMirror(),this._syncValidity(),this._drawValue(),this._syncReset(),this.renderList(),this._wire(),u(this,this.querySelector(`.wui-select-control`)),this._mountParts(e)}_accessibleName(){return this.getAttribute(`aria-label`)||this.getAttribute(`placeholder`)||`Select`}_snapshotDeclared(){if(this._declared)return;let e=[...this.querySelectorAll(`:scope > wui-option`)];e.length&&(this._declared=e.map(e=>{let t={value:e.getAttribute(`value`)??Y(e).trim(),label:e.innerHTML,[o]:!0,selected:e.hasAttribute(`selected`)};for(let[n,r]of B){let i=e.getAttribute(n);i&&(t[r]=i)}return e.hasAttribute(`disabled`)&&(t.disabled=!0),t}))}_readOptions(){return this.mode===`country`?this._partOptions||[]:this._partOptions?this._partOptions:this._optionsProp?this._optionsProp:(this._snapshotDeclared(),this._declared||[])}_listOptions(){let e=this._readOptions(),t=this.getAttribute(`value-label`);if(this.mode!==`search`||!t||this._value===``)return e;let n=String(this._value);return e.some(e=>String(e.value)===n)?e:[...e,{value:n,label:t}]}_declaredSelected(){return this._optionsProp?[]:(this._declared??[]).filter(e=>e.selected).map(e=>String(e.value))}_preselect(){let e=this._readOptions(),t=this._value!==``&&e.find(e=>String(e.value)===this._value)||e.find(e=>`selected`in e&&!!e.selected);t&&(this._value=String(t.value))}_optionFor(e){if(e===``)return;let t=String(e),n=this._readOptions().find(e=>String(e.value)===t);return n?(this._known.set(t,n),n):this._known.get(t)}_placeholder(){return this.getAttribute(`placeholder`)||L[this.mode]}_hasValue(){return Array.isArray(this._value)?this._value.length>0:this._value!==``}_selectedValues(){return Array.isArray(this._value)?this._value:this._hasValue()?[this._value]:[]}_applyValue(){this._syncMirror(),this._syncValidity(),this._rendered&&(this._drawValue(),this._syncReset(),this.renderList())}_syncMirror(){E(this.mode)?f(this,this._selectedValues()):p(this,this._value)}_drawValue(){let e=this._refs();if(!e.value)return;let t=E(this.mode),n=t?void 0:this._optionFor(this._value);this._syncTitle(n),this._syncValueAvatar(),this._activePartsList().some(e=>e.renderValue?.()===!0)||(t?(e.value.classList.remove(`wui-select-placeholder`),e.value.textContent=``):(e.value.classList.toggle(`wui-select-placeholder`,!n),e.value.innerHTML=n?a(n):i(this._placeholder())))}_syncTitle(e){let t=this.querySelector(`.wui-select-control`);if(!t)return;let n=e&&!this.hasAttribute(`title`)?r(e).trim():``;n?t.setAttribute(`title`,n):t.removeAttribute(`title`)}_syncValueAvatar(){let e=this.querySelector(`.wui-select-control`);if(!e)return;e.querySelector(`:scope > .wui-select-value-avatar`)?.remove();let t=!E(this.mode)&&this._hasValue()?y({avatar:this.getAttribute(`value-avatar`),initials:this.getAttribute(`value-initials`)},`avatar-xs`):``;e.classList.toggle(`wui-has-value-avatar`,!!t),t&&e.insertAdjacentHTML(`afterbegin`,`<span class="wui-select-value-avatar" aria-hidden="true">${t}</span>`)}_syncValidity(){let e=this._internals;if(typeof e?.setValidity==`function`){if(this.hasAttribute(`required`)&&!this._hasValue()){let t=this.querySelector(`.wui-select-control`);e.setValidity({valueMissing:!0},`Please fill in this field.`,t instanceof HTMLElement?t:void 0)}else e.setValidity({})}}_syncReset(){let e=q(this,`.wui-select-reset`,HTMLElement);e&&(e.hidden=!(this.hasAttribute(`clearable`)&&this._hasValue()&&!d(this)))}_syncInvalid(){let e=this.querySelector(`.wui-select-control`);e&&(this.hasAttribute(`aria-invalid`)||this._error?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`))}_syncError(){let e=q(this,`.wui-select-error`,HTMLElement);e&&(e.textContent=this._error,e.hidden=!this._error),this._syncInvalid()}_refs(){return{control:q(this,`.wui-select-control`,HTMLElement),value:q(this,`.wui-select-value`,HTMLElement),menu:q(this,`.wui-select-menu`,HTMLElement),list:q(this,`.wui-select-options`,HTMLElement),search:q(this,`.wui-select-search input`,HTMLInputElement),input:q(this,`.wui-select-draft`,HTMLInputElement)}}_menuOpen(){let e=q(this,`.wui-select-menu`,HTMLElement);return e!==null&&!e.hidden}_hoverZone(e){if(!(e instanceof Element))return!1;let t=e.closest(`.wui-select-control, .wui-select-menu`);return t!==null&&this.contains(t)}_hoverEligible(){if(!this.hasAttribute(`open-on-hover`)||d(this)||this.mode===`tag`)return!1;let e=this._refs();return e.search===null&&e.input===null}_clearHover(){this._hoverTimer!==null&&clearTimeout(this._hoverTimer),this._hoverTimer=null}_autoSearch(){return this.mode===`single`&&this.getAttribute(`searchable`)===null&&this._readOptions().length>I}_visible(){let e=this._refs();return e.list?J(e.list,`.wui-select-option`):[]}_setActive(e,{reveal:t=!0}={}){let n=this._refs();if(!n.list||!n.control)return;let r=this._visible();this._active=e;let i=e>=0?r[e]??null:null;g(n.list,i),i?(t&&i.scrollIntoView({block:`nearest`}),n.control.setAttribute(`aria-activedescendant`,i.id)):n.control.removeAttribute(`aria-activedescendant`)}_actionRows(){let e=[];for(let t of this._activePartsList()){let n=t.actionRow?.(this._query);n&&e.push(n)}return e}_recents(){if(this._query.trim()!==``)return null;for(let e of this._activePartsList()){let t=e.recents?.(this._listOptions());if(t)return t}return null}_place(){let e=this._refs();if(!e.control||!e.menu)return;let t=this.hasAttribute(`open`)?{below:!0}:{};if(this.getAttribute(`density`)===`compact`){let r=e.control.getBoundingClientRect();e.menu.style.width=`max-content`,e.menu.style.minWidth=`${r.width}px`,e.menu.style.maxWidth=`280px`,n(e.control,e.menu,t)}else n(e.control,e.menu,{matchWidth:!0,...t})}_open({focus:t=!0}={}){let n=this._refs();if(!n.menu||!n.control)return;let r=!n.menu.hidden;n.menu.hidden=!1,n.control.setAttribute(`aria-expanded`,`true`),n.control.classList.add(`open`),this._query=n.input?n.input.value:``,this._ownsFilter=this._ownsFilter&&this._query!==``;let i=q(this,`.wui-select-search .wui-select-clear`,HTMLElement);if(i&&(i.hidden=!0),n.search&&(n.search.value=``),this.renderList(),e(this,this._reposition),t&&(n.search?.focus(),this._setActive(this._visible().findIndex(e=>e.classList.contains(`selected`)))),!r){this.dispatchEvent(new CustomEvent(`wui-select:open`,{bubbles:!0}));for(let e of this._activePartsList())e.onOpen?.()}}_close({force:e=!1}={}){if(!e&&this.hasAttribute(`open`))return;let n=this._refs();if(!n.menu||!n.control)return;this._hoverOpened=!1;let r=!n.menu.hidden;n.menu.hidden=!0,n.control.setAttribute(`aria-expanded`,`false`),n.control.classList.remove(`open`),this._setActive(-1),this._nav?.clearTypeahead(),t(this),r&&this.dispatchEvent(new CustomEvent(`wui-select:close`,{bubbles:!0}))}_onQueryChange(e){this._query=e,this._setActive(-1);let t=q(this,`.wui-select-search .wui-select-clear`,HTMLElement);t&&(t.hidden=!e);let n=!1;for(let t of this._activePartsList())t.onQuery?.(e)===!0&&(n=!0);this._ownsFilter=n,this.renderList()}_pick(e){if(e.getAttribute(`aria-disabled`)===`true`)return;let t=e.dataset.custom===`true`,n=e.dataset.value??``,r=t?{value:n,label:Y(e).trim()}:this._listOptions().find(e=>String(e.value)===n)??{value:n,label:n},i=this._activePartsList().some(e=>e.onPick?.(r,{isCustom:t})===!0);E(this.mode)||(i||this.commit(n,{isCustom:t}),this._close(),this._refs().control?.focus())}_draftOpens(){return this.mode===`multiple`?this.hasAttribute(`allow-custom`):this.mode===`tag`&&k(this)}_onKeyDown(e){if(!d(this)){for(let t of this._activePartsList())if(t.onKey?.(e)===!0)return;if(!this._menuOpen()){if(e.target instanceof HTMLInputElement){if(e.key!==`ArrowDown`||!this._draftOpens())return;this._open({focus:!1})}else{(e.key===`ArrowDown`||e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this._open({focus:!0}));return}}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation()),c(this._nav,`Listbox keys are not wired.`).handler(e)}}_wire(){this._teardown();let t=this._refs(),n=t.control,r=t.list;if(!n||!t.menu||!r)return;let i=c(q(this,`.wui-select`,HTMLElement),`The select wrapper is missing.`),a=q(this,`.wui-select-search .wui-select-clear`,HTMLElement),o=q(this,`.wui-select-reset`,HTMLElement);this._nav=_({getVisibleOptions:()=>this._visible(),getActive:()=>this._active,setActive:e=>this._setActive(e),onEnter:(e,t)=>{if(e)this._pick(e);else if(this._query.trim()!==``){let e=t.find(e=>e.dataset.custom===`true`);if(e)this._pick(e);else if(t.length===1){let e=t[0];e&&this._pick(e)}}},onEscape:()=>{this._nav?.clearTypeahead(),this._close(),n.focus()}}),i.addEventListener(`keydown`,e=>this._onKeyDown(e)),i.addEventListener(`input`,e=>{let t=e.target;if(!(t instanceof HTMLInputElement)||!t.matches(`.wui-select-input, .wui-select-draft`))return;this._onQueryChange(t.value);let n=t.matches(`.wui-select-draft`),r=this._visible().length>0||this._actionRows().length>0;n&&r&&!this._menuOpen()&&!d(this)&&this._draftOpens()&&this._open({focus:!1})}),i.addEventListener(`focusout`,e=>{let t=e.relatedTarget;t instanceof Node&&this.contains(t)||!this._activePartsList().some(e=>e.onBlur?.()===!0)&&t&&this._close()}),a?.addEventListener(`click`,()=>{let e=c(t.search,`The search input is missing.`);e.value=``,this._onQueryChange(``),e.focus()}),n.addEventListener(`click`,e=>{if(!(e.target instanceof Element&&e.target.closest(`[data-remove]`))){if(this.mode===`tag`){if(d(this))return;this._refs().input?.focus(),!this._menuOpen()&&this._draftOpens()&&this._open({focus:!1})}else e.target instanceof HTMLInputElement?!this._menuOpen()&&!d(this)&&this._open({focus:!1}):(this._clearHover(),this._hoverOpened&&this._menuOpen()?(this._hoverOpened=!1,this._open({focus:!0})):this._menuOpen()?this._close():d(this)||this._open({focus:!0}))}}),o?.addEventListener(`click`,e=>{e.stopPropagation(),this.commit(E(this.mode)?[]:``),this._close(),n.focus()}),r.addEventListener(`click`,e=>{let r=K(e).closest(`.wui-select-option`);if(r instanceof HTMLElement&&(this._pick(r),E(this.mode))){let e=this.querySelector(`.wui-select-draft`);(t.search??(e instanceof HTMLElement?e:n)).focus()}}),r.addEventListener(`mousedown`,e=>{E(this.mode)&&e.target instanceof Element&&e.target.closest(`.wui-select-option`)&&e.preventDefault()}),r.addEventListener(`mousemove`,e=>{let t=K(e).closest(`.wui-select-option`);t instanceof HTMLElement&&!t.classList.contains(`is-active`)&&this._setActive(this._visible().indexOf(t),{reveal:!1})}),r.addEventListener(`mouseleave`,()=>this._setActive(-1)),r.addEventListener(`error`,e=>{let t=e.target;t instanceof Element&&t.classList.contains(`avatar-img`)&&t.remove()},!0),this._bindGlobal=()=>{this._teardown(),this._onDocClick=e=>{this._menuOpen()&&!e.composedPath().includes(this)&&this._close()},document.addEventListener(`click`,this._onDocClick),this._menuOpen()&&e(this,this._reposition)},this.hasAttribute(`open`)&&this._open({focus:!1}),this._bindGlobal()}_teardown(){this._onDocClick&&=(document.removeEventListener(`click`,this._onDocClick),null),t(this),this._nav?.teardown()}_activePartsList(){return this._partsMounted?c(this._parts,`The mounted parts are missing.`):[]}_ensureParts(){if(!this.isConnected)return;let e=U(this,this.mode),t=e.join(`,`);if(t===this._partSig)return;this._teardownParts(),this._parts=null,this._partSig=t;let n=++this._partToken;Promise.all(e.map(e=>X(this,e))).then(e=>{n===this._partToken&&(this._parts=e.filter(e=>e!==null),this._mountParts())})}_mountParts(e={draft:``,query:``}){if(!this._parts||this._partsMounted||!this._rendered||!this.isConnected)return;this._partsMounted=!0;let t=j(this._refs());for(let n of this._parts)n.mount(this,t,{carry:e});this._drawValue(),this.renderList()}_teardownParts(){let e=this._activePartsList();this._partsMounted=!1;for(let t of e)t.teardown()}_remountParts(){if(!this._partsMounted)return;let e=this._carry();this._teardownParts(),this._mountParts(e)}_carry(){let e=this._refs();return{draft:e.input?.value??``,query:e.search?.value??``}}},j=e=>{let{control:t,value:n,menu:r,list:i}=e;return{control:c(t,`control missing`),value:c(n,`value missing`),menu:c(r,`menu missing`),list:c(i,`list missing`),search:e.search,input:e.input}},M=e=>T.includes(e),N=[`comfortable`,`compact`],P=150,F=250,I=10,L={single:`Select…`,search:`Select…`,multiple:`Select…`,tag:`Add…`,country:`Select country`},R=/* @__PURE__ */ new Set([`countries`,`suggested`,`suggested-label`,`all-countries-label`,`max-tags`,`pattern`,`collapse-chips`,`source`,`remote`,`min-chars`]),z=/* @__PURE__ */ new Set([`separators`,`allow-duplicates`,`invalid-message`,`create-label`,`add-label`,`selected-text`,`clear-all-label`,`value-label`,`value-avatar`,`value-initials`,`hint-text`,`recents-key`,`recents-limit`,`recents-label`]),B=[[`icon`,`icon`],[`description`,`description`],[`meta`,`meta`],[`group`,`group`],[`avatar`,`avatar`],[`initials`,`initials`],[`disabled-hint`,`disabledHint`]],V=(e,t)=>t?Array.isArray(e)?e.map(String):e==null||e===``?[]:String(e).split(`,`).map(e=>e.trim()).filter(Boolean):Array.isArray(e)?e.length?String(e[0]):``:e==null?``:String(e),H=(e,t)=>t===`multiple`?[`chips`]:t===`search`?[`search`]:t===`country`?[`country`]:t===`tag`?k(e)?[`chips`,`search`]:[`chips`]:[],U=(e,t)=>e.hasAttribute(`recents-key`)?[`recents`,...H(e,t)]:H(e,t),W=`This control could not load. Reload the page.`,G=e=>typeof e==`object`&&!!e&&`default`in e&&typeof e.default==`function`,K=e=>{if(e.target instanceof Element)return e.target;throw Error(`The event target is not an element.`)},q=(e,t,n)=>{let r=e.querySelector(t);return r instanceof n?r:null},J=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),Y=e=>{let t=e.textContent;if(t===null)throw Error(`The element has no text.`);return t},X=(e,t)=>O(t).then(e=>{if(!G(e))throw Error(`The part ${t} has no default export.`);return e.default()}).catch(()=>(document.dispatchEvent(new CustomEvent(m,{bubbles:!0,composed:!0,detail:{chunk:t}})),e.setError(W),null));export{k as n,x as r,A as t};