@webority/ui-elements 0.156.0 → 0.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WuiCarousel-BdhJLo1m.js +1 -0
- package/dist/{WuiCommentThread-BmRsl0K1.js → WuiCommentThread-CnwvJUDn.js} +1 -1
- package/dist/{WuiContextMenu-sPTmEEVn.js → WuiContextMenu-Re2CG8yT.js} +1 -1
- package/dist/{WuiMentionInput-8Xjkzdqg.js → WuiMentionInput-HwsLGhyr.js} +1 -1
- package/dist/{WuiPhone-BVNVerap.js → WuiPhone-NdIYg_Gb.js} +1 -1
- package/dist/{WuiSelect-BPWPI07i.js → WuiSelect-CWul-aM1.js} +2 -2
- package/dist/{WuiTree-0Yqu199O.js → WuiTree-JK4JqcBr.js} +1 -1
- package/dist/chips-DD_C4G0w.js +2 -0
- package/dist/elements/carousel.js +1 -1
- package/dist/elements/comment-thread.js +1 -1
- package/dist/elements/context-menu.js +1 -1
- package/dist/elements/mention-input.js +1 -1
- package/dist/elements/phone.js +1 -1
- package/dist/elements/select.js +1 -1
- package/dist/elements/tree.js +1 -1
- package/dist/listboxKeyNav-Bxkq7dvu.js +1 -0
- package/dist/search-DMniXhEK.js +1 -0
- package/dist/ui-chart.global.js +2 -2
- package/dist/ui-chart.js +2 -2
- package/dist/ui-elements/carousel.global.js +1 -1
- package/dist/ui-elements/code-block.global.js +1 -1
- package/dist/ui-elements/command-palette.global.js +1 -1
- package/dist/ui-elements/comment-thread.global.js +1 -1
- package/dist/ui-elements/consent-banner.global.js +1 -1
- package/dist/ui-elements/context-menu.global.js +1 -1
- package/dist/ui-elements/date-range.global.js +1 -1
- package/dist/ui-elements/drawer.global.js +1 -1
- package/dist/ui-elements/glyphs.global.js +1 -1
- package/dist/ui-elements/image-crop.global.js +1 -1
- package/dist/ui-elements/inline-edit.global.js +1 -1
- package/dist/ui-elements/kanban.global.js +1 -1
- package/dist/ui-elements/lead-popup.global.js +1 -1
- package/dist/ui-elements/lightbox.global.js +1 -1
- package/dist/ui-elements/markdown.global.js +1 -1
- package/dist/ui-elements/org-tree.global.js +1 -1
- package/dist/ui-elements/phone.global.js +1 -1
- package/dist/ui-elements/resizable.global.js +1 -1
- package/dist/ui-elements/saved-views.global.js +1 -1
- package/dist/ui-elements/select-chips.global.js +2 -2
- package/dist/ui-elements/select-recents.global.js +1 -1
- package/dist/ui-elements/select-search.global.js +1 -1
- package/dist/ui-elements/slider.global.js +1 -1
- package/dist/ui-elements/sortable.global.js +1 -1
- package/dist/ui-elements/status-icon.global.js +1 -1
- package/dist/ui-elements/timepicker.global.js +1 -1
- package/dist/ui-elements/tour.global.js +1 -1
- package/dist/ui-elements/tree.global.js +1 -1
- package/dist/ui-elements/wizard.global.js +1 -1
- package/dist/ui-elements.global.js +3 -3
- package/dist/ui-elements.js +1 -1
- package/package.json +4 -4
- package/dist/WuiCarousel-DthhDxH-.js +0 -1
- package/dist/chips-Dr_W3avk.js +0 -2
- package/dist/listboxKeyNav-4LeEjKq6.js +0 -1
- package/dist/search-PZCXpBAn.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./elementBase-Cxeyx0tU.js";var t=Object.freeze({slide:(e,t)=>`${e} of ${t}`,status:(e,t,n)=>e===t?`Slide ${e} of ${n}`:`Slides ${e} to ${t} of ${n}`,dot:`Go to slide`,pause:`Pause`,play:`Play`}),n=120,r=class extends e{_page;_pages;_perView;_paused;_hover;_focus;_timer;_settleTimer;_status;_ready;_motion;_mutations;_resizer;_doc;_track;_onClick;_onKeyDown;_onScroll;_onEnter;_onLeave;_onFocusIn;_onFocusOut;_onVisibility;_onMotion;_tick;static get observedAttributes(){return[`autoplay`]}constructor(){super(),this._page=0,this._pages=1,this._perView=1,this._paused=!1,this._hover=!1,this._focus=!1,this._timer=null,this._settleTimer=null,this._status=``,this._ready=!1,this._motion=null,this._mutations=null,this._resizer=null,this._doc=null,this._track=null,this._onClick=e=>this._click(e),this._onKeyDown=e=>this._key(e),this._onScroll=()=>{this._settleTimer!==null&&clearTimeout(this._settleTimer),this._settleTimer=setTimeout(()=>this._settle(),n)},this._onEnter=()=>this._hold({hover:!0}),this._onLeave=()=>this._hold({hover:!1}),this._onFocusIn=()=>this._hold({focus:!0}),this._onFocusOut=e=>this._hold({focus:e.relatedTarget instanceof Node&&this.contains(e.relatedTarget)}),this._onVisibility=()=>this._sync(),this._onMotion=()=>this._sync(),this._tick=()=>{this._timer=null,this._go(this._page+1<this._pages?this._page+1:0)}}connectedCallback(){let e=this.querySelector(`.wui-carousel-track`);if(this._track=e instanceof HTMLElement?e:null,!this._track){this.ownerDocument.readyState===`loading`&&this.ownerDocument.addEventListener(`DOMContentLoaded`,()=>this.isConnected&&this.connectedCallback(),{once:!0});return}this._doc=this.ownerDocument;let t=this.getAttribute(`data-wui-style`);if(t){for(let e of t.split(`;`)){let t=e.indexOf(`:`);t>0&&this.style.setProperty(e.slice(0,t).trim(),e.slice(t+1).trim())}this.removeAttribute(`data-wui-style`)}this._motion=typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(prefers-reduced-motion: reduce)`):null,this._motion?.addEventListener(`change`,this._onMotion),this.addEventListener(`click`,this._onClick),this.addEventListener(`mouseenter`,this._onEnter),this.addEventListener(`mouseleave`,this._onLeave),this.addEventListener(`focusin`,this._onFocusIn),this.addEventListener(`focusout`,this._onFocusOut),this._track.addEventListener(`keydown`,this._onKeyDown),this._track.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._doc.addEventListener(`visibilitychange`,this._onVisibility),typeof MutationObserver<`u`&&(this._mutations=new MutationObserver(()=>this._refresh()),this._mutations.observe(this._track,{childList:!0})),typeof ResizeObserver<`u`&&(this._resizer=new ResizeObserver(()=>this._refresh()),this._resizer.observe(this._track)),this._ready=!0,this._refresh()}disconnectedCallback(){this._ready=!1,this._timer!==null&&clearTimeout(this._timer),this._settleTimer!==null&&clearTimeout(this._settleTimer),this._timer=null,this._motion?.removeEventListener(`change`,this._onMotion),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`mouseenter`,this._onEnter),this.removeEventListener(`mouseleave`,this._onLeave),this.removeEventListener(`focusin`,this._onFocusIn),this.removeEventListener(`focusout`,this._onFocusOut),this._track?.removeEventListener(`keydown`,this._onKeyDown),this._track?.removeEventListener(`scroll`,this._onScroll),this._doc?.removeEventListener(`visibilitychange`,this._onVisibility),this._mutations?.disconnect(),this._resizer?.disconnect(),this._mutations=this._resizer=this._motion=this._doc=null}attributeChangedCallback(){this._ready&&this._sync()}get paused(){return this._paused}set paused(e){this._paused=!!e,this._ready&&this._sync()}next(){this._page+1<this._pages?this._go(this._page+1):this.hasAttribute(`loop`)&&this._go(0)}prev(){this._page>0?this._go(this._page-1):this.hasAttribute(`loop`)&&this._go(this._pages-1)}goTo(e){this._go(Number(e))}_interval(){let e=Number.parseInt(this.getAttribute(`autoplay`)??``,10);return Math.max(e||0,0)}_slides(){let e=this._track;if(!e)throw Error(`WuiCarousel used before it was connected`);return Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.classList.contains(`wui-carousel-slide`))}_playing(){return this._interval()>0&&this._pages>1&&!this._paused&&!this._hover&&!this._focus&&!this._motion?.matches&&!this._doc?.hidden}_hold({hover:e=this._hover,focus:t=this._focus}){this._hover=e,this._focus=t,this._sync()}_click(e){let t=(e.target instanceof Element?e.target:null)?.closest(`.wui-carousel-pause, .wui-carousel-prev, .wui-carousel-next, .wui-carousel-dot`),n=t instanceof HTMLElement?t:null;if(!n||!this.contains(n))return;let r=this._track;if(!r)throw Error(`WuiCarousel used before it was connected`);r.contains(n)||(n.classList.contains(`wui-carousel-pause`)?(this._paused=!this._paused,this._hover=!1,this._focus=!1,this._sync()):n.getAttribute(`aria-disabled`)===`true`?e.preventDefault():n.classList.contains(`wui-carousel-prev`)?this.prev():n.classList.contains(`wui-carousel-next`)?this.next():this._go(Number(n.dataset.page)))}_key(e){if(e.target!==this._track||e.altKey||e.ctrlKey||e.metaKey)return;let t={ArrowRight:()=>this.next(),ArrowLeft:()=>this.prev(),Home:()=>this._go(0),End:()=>this._go(this._pages-1)}[e.key];t&&(e.preventDefault(),t())}_perViewNow(){let e=``;if(typeof window<`u`){let t=this._track;if(!t)throw Error(`WuiCarousel used before it was connected`);e=window.getComputedStyle(t).getPropertyValue(`--wui-carousel-view`)}return Math.max(Number.parseInt(e,10)||0,1)}_start(e){return Math.min(e*this._perView,Math.max(0,this._slides().length-this._perView))}_label(){let e=this._slides();return e.forEach((n,r)=>{let i=t.slide(r+1,e.length);n.getAttribute(`aria-label`)!==i&&n.setAttribute(`aria-label`,i)}),e.length}_refresh(){let e=this._label();this._perView=this._perViewNow();let n=Math.max(1,Math.ceil(e/this._perView)),r=this.querySelector(`.wui-carousel-dots`);if(r&&r.children.length!==n){let e=this.getAttribute(`dot-label`)||t.dot;r.replaceChildren(...Array.from({length:n},(t,n)=>{let r=this.ownerDocument.createElement(`button`);return r.type=`button`,r.className=`wui-carousel-dot`,r.dataset.page=String(n),r.setAttribute(`aria-label`,`${e} ${this._start(n)+1}`),r}))}this._pages=n,this._page=Math.min(this._page,n-1),this.toggleAttribute(`data-single`,n<=1),this._render(!1),this._sync()}_settle(){let e=this._track;if(!e)throw Error(`WuiCarousel used before it was connected`);let t=this._slides();if(!t.length)return;let n;if(e.scrollWidth>e.clientWidth&&e.scrollLeft+e.clientWidth>=e.scrollWidth-2)n=this._pages-1;else{let r=0,i=1/0;t.forEach((t,n)=>{let a=Math.abs(t.offsetLeft-e.scrollLeft);a<i&&(i=a,r=n)}),n=Math.min(this._pages-1,Math.round(r/this._perView))}n!==this._page&&(this._page=n,this._render(!0),this._sync())}_go(e){if(!Number.isInteger(e))return;this._page=Math.max(0,Math.min(this._pages-1,e));let t=this._track;if(!t)throw Error(`WuiCarousel used before it was connected`);let n=this._slides()[this._start(this._page)];if(n){let e=this._motion?.matches?`auto`:`smooth`;typeof t.scrollTo==`function`?t.scrollTo({left:n.offsetLeft,behavior:e}):t.scrollLeft=n.offsetLeft}this._render(!0),this._sync()}_render(e){let n=this.hasAttribute(`loop`);for(let e of this.querySelectorAll(`.wui-carousel-dot`))e instanceof HTMLElement&&(Number(e.dataset.page)===this._page?e.setAttribute(`aria-current`,`true`):e.removeAttribute(`aria-current`));this.querySelector(`.wui-carousel-prev`)?.setAttribute(`aria-disabled`,String(!n&&this._page===0)),this.querySelector(`.wui-carousel-next`)?.setAttribute(`aria-disabled`,String(!n&&this._page===this._pages-1));let r=this._slides().length,i=this._start(this._page)+1,a=Math.min(r,i+this._perView-1),o=t.status(i,a,r);if(o===this._status||(this._status=o,!e))return;let s=this.querySelector(`[data-wui-status]`);s&&!this._playing()&&(s.textContent=o),this.dispatchEvent(new CustomEvent(`wui:carousel:change`,{bubbles:!0,detail:{page:this._page,pages:this._pages}}))}_sync(){this._timer!==null&&clearTimeout(this._timer),this._timer=null;let e=this._interval(),n=this.querySelector(`.wui-carousel-pause`);if(n instanceof HTMLElement){n.hidden=e===0||this._pages<=1||!!this._motion?.matches;let r=this._paused?this.getAttribute(`play-label`)||t.play:this.getAttribute(`pause-label`)||t.pause,i=n.querySelector(`.wui-carousel-pause-text`);i&&i.textContent!==r&&(i.textContent=r),this.toggleAttribute(`data-paused`,this._paused)}this._playing()&&(this._timer=setTimeout(this._tick,e))}};export{r as t};
|
|
@@ -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-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
|
+
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-HwsLGhyr.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{t as e}from"./anchorOverlay-CXnWfezA.js";import{t}from"./elementBase-Cxeyx0tU.js";import{t as n}from"./listboxKeyNav-4LeEjKq6.js";var r=`[role="menuitem"]`,i=`.wui-context-menu-sub`,a=`input.wui-context-menu-search`,o=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,s=`data-open`,c=500,l=10,u=400,d=null,f=null,p=0,m=/* @__PURE__ */ new WeakMap;function h(e,t,n){let r=m.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return m.set(e,{region:t,cancel:n}),!0}var g=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,_=e=>`focus`in e,v=e=>[...e.childNodes].filter(e=>e.nodeType===Node.TEXT_NODE||e instanceof Element&&!e.matches(`.wui-context-menu-hint, .wui-context-menu-tick`)).map(e=>e.textContent).join(``),y=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),b=e=>[...e.children].filter(e=>e instanceof HTMLElement),x=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},S=e=>x(e,0),C=e=>x(e,1),w=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null},T=class extends t{_region;_origin;_returnFocus;_press;_swallowClick;_navPanel;_nav;_onContextMenu;_onContextMenuCapture;_onDocKeyDown;_onDocClick;_onPointerDown;_onPressMove;_onPressEnd;_onClickCapture;_onKeyDown;_onClick;_onInput;_onMouseMove;_onDismiss;_onPointerDownCapture;static get observedAttributes(){return[`disabled`,`open`]}constructor(){super(),this._region=null,this._origin=null,this._returnFocus=null,this._press=null,this._swallowClick=!1,this._navPanel=null,this._nav=n({getVisibleOptions:()=>this._rowsOf(this._navPanel),getActive:()=>{let e=document.activeElement,t=this._rowsOf(this._navPanel);return e?t.indexOf(e):-1},setActive:e=>this._rowsOf(this._navPanel)[e]?.focus({preventScroll:!0})}),this._onContextMenu=e=>this._handleContextMenu(e),this._onContextMenuCapture=e=>{this.isOpen&&!this._inPanel(e.target)&&!this._isKeyEcho()&&this.close()},this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._onDocClick=e=>this._handleDocClick(e),this._onPointerDown=e=>this._handlePointerDown(e),this._onPressMove=e=>{this._press&&Math.hypot(e.clientX-this._press.x,e.clientY-this._press.y)>l&&this._cancelPress()},this._onPressEnd=()=>this._cancelPress(),this._onClickCapture=e=>{if(this._swallowClick&&this._region){if(!(e.target instanceof Node))throw Error(`a click target is always a node`);this._region.contains(e.target)&&(this._swallowClick=!1,e.preventDefault(),e.stopImmediatePropagation())}},this._onKeyDown=e=>{this._inPanel(e.target)&&this._handleMenuKey(e)},this._onClick=e=>this._handleClick(e),this._onInput=e=>this._handleInput(e),this._onMouseMove=e=>{let t=w(g(e.target),r);t&&this._inPanel(t)&&!this._isDisabled(t)&&t!==document.activeElement&&t.focus({preventScroll:!0})},this._onDismiss=e=>{this.hasAttribute(`open`)||e.type===`scroll`&&this._inPanel(e.target)||this.close()},this._onPointerDownCapture=e=>{this._swallowClick=!1,this.isOpen&&!this.hasAttribute(`open`)&&!this._inPanel(e.target)&&this.close()}}connectedCallback(){this._teardown(),document.addEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.addEventListener(`contextmenu`,this._onContextMenu),document.addEventListener(`keydown`,this._onDocKeyDown),document.addEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.addEventListener(`pointerdown`,this._onPointerDown),document.addEventListener(`click`,this._onClickCapture,!0),document.addEventListener(`click`,this._onDocClick),window.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick),this.addEventListener(`input`,this._onInput),this.addEventListener(`mousemove`,this._onMouseMove),this._syncOpen()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){e===`open`?this.isConnected&&this._syncOpen():this.disabled&&this.close()}get target(){return this.getAttribute(`target`)}set target(e){e==null||e===``?this.removeAttribute(`target`):this.setAttribute(`target`,String(e))}get disabled(){return this.hasAttribute(`disabled`)}set disabled(e){this.toggleAttribute(`disabled`,!!e)}get isOpen(){return this._panel()?.hasAttribute(s)??!1}open(t,n,{region:r=this,origin:i=r,trigger:a=null,keyboard:o=!1}={}){let c=this._panel();if(!c)return!1;let l=new CustomEvent(`wui-context-menu:beforeopen`,{bubbles:!0,cancelable:!0,detail:{region:r,origin:i,trigger:a}});if(this.dispatchEvent(l),l.defaultPrevented)return!1;if(this._decorate(c),d&&d!==this&&d.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&_(e)?e:null}return this._region=r,this._origin=i,f=null,c.setAttribute(s,``),d=this,e({getBoundingClientRect:()=>({x:t,y:n,left:t,right:t,top:n,bottom:n,width:0,height:0,toJSON:()=>({})})},c,{clampHeight:!0}),window.addEventListener(`scroll`,this._onDismiss,!0),window.addEventListener(`resize`,this._onDismiss),window.addEventListener(`blur`,this._onDismiss),((o?this._rowsOf(c)[0]:null)??c).focus({preventScroll:!0}),this.dispatchEvent(new CustomEvent(`wui-context-menu:open`,{bubbles:!0,detail:{region:r,origin:i,x:t,y:n}})),!0}_syncOpen(){if(!this.hasAttribute(`open`)){this.close(this._inPanel(document.activeElement));return}let e=this.target?document.querySelector(this.target):this,t=e&&this._regionRect(e);e&&t&&this.open(t.left,t.top,{region:e,origin:e})}_regionRect(e){if(e!==this)return e.getBoundingClientRect();let t=[...this.children].filter(e=>e!==this._panel()).map(e=>e.getBoundingClientRect());return t.length?{left:Math.min(...t.map(e=>e.left)),top:Math.min(...t.map(e=>e.top))}:null}close(e=!1){let t=this._panel();if(!t?.hasAttribute(s))return;for(let e of y(t,i))this._setSub(e,!1);t.removeAttribute(s),d===this&&(d=null),window.removeEventListener(`scroll`,this._onDismiss,!0),window.removeEventListener(`resize`,this._onDismiss),window.removeEventListener(`blur`,this._onDismiss),this._nav.teardown();let n=this._returnFocus;this._returnFocus=null,e&&n?.isConnected&&n.focus({preventScroll:!0})}_panel(){return b(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?y(e,r).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&!t.closest(`[hidden]`)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=g(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(o))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=g(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=w(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return f?.menu===this&&this.isOpen&&performance.now()-f.at<u}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!m.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||h(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:g(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!m.has(e))return;if(e.key===`Enter`){let t=this._triggerFor(e.target);if(!t||!h(e,t.region,()=>this.close(!0)))return;e.preventDefault(),t.trigger.click();return}if(!(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey)||this._inPanel(e.target))return;let t=this._regionFor(e.target);if(!t||!h(e,t,()=>this.close(!0)))return;let n=g(e.target);if(!n)return;let r=n.getBoundingClientRect();this.open(r.left+Math.min(16,r.width/2),r.bottom,{region:t,origin:n,keyboard:!0})&&(e.preventDefault(),f={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!h(e,t.region,()=>this.close(!0)))return;let n=t.trigger.getBoundingClientRect();this.open(n.left,n.bottom,{region:t.region,origin:t.trigger,trigger:t.trigger,keyboard:e.detail===0})}_handlePointerDown(e){if(e.pointerType!==`touch`)return;let t=this._regionFor(e.target);if(!t||!h(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=g(e.target);this._press={x:n,y:r,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},c)},document.addEventListener(`pointermove`,this._onPressMove,{passive:!0}),document.addEventListener(`pointerup`,this._onPressEnd),document.addEventListener(`pointercancel`,this._onPressEnd),window.addEventListener(`scroll`,this._onPressEnd,!0)}_cancelPress(){this._press&&(clearTimeout(this._press.timer),this._press=null,document.removeEventListener(`pointermove`,this._onPressMove),document.removeEventListener(`pointerup`,this._onPressEnd),document.removeEventListener(`pointercancel`,this._onPressEnd),window.removeEventListener(`scroll`,this._onPressEnd,!0))}_handleMenuKey(e){if(!this.isOpen)return;let t=g(e.target);if(!t)return;if(t.matches(a)){this._handleSearchKey(e,t);return}let n=w(t,`[role="menu"]`);if(!n)return;let i=w(t,r),o=n.matches(`.wui-context-menu-subpanel`)?n.parentElement:null;if(e.key===`Escape`){if(e.preventDefault(),e.stopPropagation(),o)this._closeSubByKey(o);else{let e=this._openSubOf(n);e?this._closeSubByKey(e):this.close(!0)}}else if(e.key===`Tab`)this.close(!0);else if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),e.stopPropagation(),this._step(n,i,e.key===`ArrowDown`?1:-1);else if(e.key===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(e.key===`ArrowLeft`){if(!o)return;e.preventDefault(),this._closeSubByKey(o)}else e.key===`Enter`||e.key===` `?(e.preventDefault(),i?.click()):(this._navPanel=n,this._nav.handler(e))}_handleSearchKey(e,t){let n=w(t,i);if(!n)return;let r=this._rowsOf(C(n));e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closeSubByKey(n)):e.key===`ArrowDown`?(e.preventDefault(),r[0]?.focus({preventScroll:!0})):e.key===`ArrowUp`?(e.preventDefault(),r[r.length-1]?.focus({preventScroll:!0})):e.key===`Tab`&&this.close(!0)}_step(e,t,n){let r=this._rowsOf(e);if(!r.length)return;let i=t?r.indexOf(t):-1;r[i<0?n>0?0:r.length-1:(i+n+r.length)%r.length]?.focus({preventScroll:!0})}_subOf(e){return e.hasAttribute(`aria-haspopup`)&&e.parentElement?.matches(i)?e.parentElement:null}_openSubOf(e){return b(e).find(e=>e.matches(i)&&C(e).hasAttribute(s))??null}_openSub(e,t){let n=e.parentElement;if(!n)throw Error(`a submenu is always inside its menu panel`);for(let t of b(n))t!==e&&t.matches(i)&&this._closeSub(t);this._setSub(e,!0);let r=C(e).querySelector(`:scope > ${a}`),o=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;o?(o.value=``,this._filter(e,``),o.focus({preventScroll:!0})):t&&this._rowsOf(C(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of y(C(e),i))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),S(e).focus({preventScroll:!0})}_setSub(t,n){let r=S(t),i=C(t);i.toggleAttribute(s,n),r.setAttribute(`aria-expanded`,String(n)),n?e(r,i,{beside:!0}):i.removeAttribute(`data-side`)}_filter(e,t){let n=t.trim().toLowerCase();for(let t of b(C(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(r)?t.hidden=n!==``&&!v(t).toLowerCase().includes(n):t.matches(i)&&(t.hidden=n!==``&&!v(S(t)).toLowerCase().includes(n))}_handleInput(e){let t=g(e.target)?.closest(a);if(!(t instanceof HTMLInputElement))return;let n=w(t,i);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of y(e,r)){let e=t.getAttribute(`aria-checked`)===`true`,n=t.querySelector(`:scope > .wui-context-menu-tick`);if(e&&!n){let e=document.createElement(`span`);e.className=`wui-context-menu-tick`,e.setAttribute(`aria-hidden`,`true`),t.prepend(e)}else!e&&n&&n.remove();let r=t.querySelector(`:scope > .wui-context-menu-hint`),i=t.dataset.hint;if(i){let e=r??document.createElement(`span`);r||(e.className=`wui-context-menu-hint`,e.id=`wui-context-menu-hint-${++p}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=w(g(e.target),r);if(!t||!this._inPanel(t))return;if(this._isDisabled(t)){e.preventDefault(),e.stopPropagation();return}let n=this._subOf(t);n?(e.preventDefault(),this._openSub(n,e.detail===0)):(this.close(!0),this.dispatchEvent(new CustomEvent(`wui-context-menu:select`,{bubbles:!0,detail:{key:t.dataset.key??null,item:t,region:this._region,origin:this._origin}})))}_teardown(){this.close(),this._cancelPress(),document.removeEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.removeEventListener(`contextmenu`,this._onContextMenu),document.removeEventListener(`keydown`,this._onDocKeyDown),document.removeEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.removeEventListener(`pointerdown`,this._onPointerDown),document.removeEventListener(`click`,this._onClickCapture,!0),document.removeEventListener(`click`,this._onDocClick),window.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`input`,this._onInput),this.removeEventListener(`mousemove`,this._onMouseMove)}};export{T as t};
|
|
1
|
+
import{t as e}from"./anchorOverlay-CXnWfezA.js";import{t}from"./elementBase-Cxeyx0tU.js";import{t as n}from"./listboxKeyNav-Bxkq7dvu.js";var r=`[role="menuitem"]`,i=`.wui-context-menu-sub`,a=`input.wui-context-menu-search`,o=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,s=`data-open`,c=500,l=10,u=400,d=null,f=null,p=0,m=/* @__PURE__ */ new WeakMap;function h(e,t,n){let r=m.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return m.set(e,{region:t,cancel:n}),!0}var g=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,_=e=>`focus`in e,v=e=>[...e.childNodes].filter(e=>e.nodeType===Node.TEXT_NODE||e instanceof Element&&!e.matches(`.wui-context-menu-hint, .wui-context-menu-tick`)).map(e=>e.textContent).join(``),y=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),b=e=>[...e.children].filter(e=>e instanceof HTMLElement),x=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},S=e=>x(e,0),C=e=>x(e,1),w=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null},T=class extends t{_region;_origin;_returnFocus;_press;_swallowClick;_navPanel;_nav;_onContextMenu;_onContextMenuCapture;_onDocKeyDown;_onDocClick;_onPointerDown;_onPressMove;_onPressEnd;_onClickCapture;_onKeyDown;_onClick;_onInput;_onMouseMove;_onDismiss;_onPointerDownCapture;static get observedAttributes(){return[`disabled`,`open`]}constructor(){super(),this._region=null,this._origin=null,this._returnFocus=null,this._press=null,this._swallowClick=!1,this._navPanel=null,this._nav=n({getVisibleOptions:()=>this._rowsOf(this._navPanel),getActive:()=>{let e=document.activeElement,t=this._rowsOf(this._navPanel);return e?t.indexOf(e):-1},setActive:e=>this._rowsOf(this._navPanel)[e]?.focus({preventScroll:!0})}),this._onContextMenu=e=>this._handleContextMenu(e),this._onContextMenuCapture=e=>{this.isOpen&&!this._inPanel(e.target)&&!this._isKeyEcho()&&this.close()},this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._onDocClick=e=>this._handleDocClick(e),this._onPointerDown=e=>this._handlePointerDown(e),this._onPressMove=e=>{this._press&&Math.hypot(e.clientX-this._press.x,e.clientY-this._press.y)>l&&this._cancelPress()},this._onPressEnd=()=>this._cancelPress(),this._onClickCapture=e=>{if(this._swallowClick&&this._region){if(!(e.target instanceof Node))throw Error(`a click target is always a node`);this._region.contains(e.target)&&(this._swallowClick=!1,e.preventDefault(),e.stopImmediatePropagation())}},this._onKeyDown=e=>{this._inPanel(e.target)&&this._handleMenuKey(e)},this._onClick=e=>this._handleClick(e),this._onInput=e=>this._handleInput(e),this._onMouseMove=e=>{let t=w(g(e.target),r);t&&this._inPanel(t)&&!this._isDisabled(t)&&t!==document.activeElement&&t.focus({preventScroll:!0})},this._onDismiss=e=>{this.hasAttribute(`open`)||e.type===`scroll`&&this._inPanel(e.target)||this.close()},this._onPointerDownCapture=e=>{this._swallowClick=!1,this.isOpen&&!this.hasAttribute(`open`)&&!this._inPanel(e.target)&&this.close()}}connectedCallback(){this._teardown(),document.addEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.addEventListener(`contextmenu`,this._onContextMenu),document.addEventListener(`keydown`,this._onDocKeyDown),document.addEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.addEventListener(`pointerdown`,this._onPointerDown),document.addEventListener(`click`,this._onClickCapture,!0),document.addEventListener(`click`,this._onDocClick),window.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick),this.addEventListener(`input`,this._onInput),this.addEventListener(`mousemove`,this._onMouseMove),this._syncOpen()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){e===`open`?this.isConnected&&this._syncOpen():this.disabled&&this.close()}get target(){return this.getAttribute(`target`)}set target(e){e==null||e===``?this.removeAttribute(`target`):this.setAttribute(`target`,String(e))}get disabled(){return this.hasAttribute(`disabled`)}set disabled(e){this.toggleAttribute(`disabled`,!!e)}get isOpen(){return this._panel()?.hasAttribute(s)??!1}open(t,n,{region:r=this,origin:i=r,trigger:a=null,keyboard:o=!1}={}){let c=this._panel();if(!c)return!1;let l=new CustomEvent(`wui-context-menu:beforeopen`,{bubbles:!0,cancelable:!0,detail:{region:r,origin:i,trigger:a}});if(this.dispatchEvent(l),l.defaultPrevented)return!1;if(this._decorate(c),d&&d!==this&&d.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&_(e)?e:null}return this._region=r,this._origin=i,f=null,c.setAttribute(s,``),d=this,e({getBoundingClientRect:()=>({x:t,y:n,left:t,right:t,top:n,bottom:n,width:0,height:0,toJSON:()=>({})})},c,{clampHeight:!0}),window.addEventListener(`scroll`,this._onDismiss,!0),window.addEventListener(`resize`,this._onDismiss),window.addEventListener(`blur`,this._onDismiss),((o?this._rowsOf(c)[0]:null)??c).focus({preventScroll:!0}),this.dispatchEvent(new CustomEvent(`wui-context-menu:open`,{bubbles:!0,detail:{region:r,origin:i,x:t,y:n}})),!0}_syncOpen(){if(!this.hasAttribute(`open`)){this.close(this._inPanel(document.activeElement));return}let e=this.target?document.querySelector(this.target):this,t=e&&this._regionRect(e);e&&t&&this.open(t.left,t.top,{region:e,origin:e})}_regionRect(e){if(e!==this)return e.getBoundingClientRect();let t=[...this.children].filter(e=>e!==this._panel()).map(e=>e.getBoundingClientRect());return t.length?{left:Math.min(...t.map(e=>e.left)),top:Math.min(...t.map(e=>e.top))}:null}close(e=!1){let t=this._panel();if(!t?.hasAttribute(s))return;for(let e of y(t,i))this._setSub(e,!1);t.removeAttribute(s),d===this&&(d=null),window.removeEventListener(`scroll`,this._onDismiss,!0),window.removeEventListener(`resize`,this._onDismiss),window.removeEventListener(`blur`,this._onDismiss),this._nav.teardown();let n=this._returnFocus;this._returnFocus=null,e&&n?.isConnected&&n.focus({preventScroll:!0})}_panel(){return b(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?y(e,r).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&!t.closest(`[hidden]`)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=g(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(o))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=g(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=w(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return f?.menu===this&&this.isOpen&&performance.now()-f.at<u}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!m.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||h(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:g(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!m.has(e))return;if(e.key===`Enter`){let t=this._triggerFor(e.target);if(!t||!h(e,t.region,()=>this.close(!0)))return;e.preventDefault(),t.trigger.click();return}if(!(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey)||this._inPanel(e.target))return;let t=this._regionFor(e.target);if(!t||!h(e,t,()=>this.close(!0)))return;let n=g(e.target);if(!n)return;let r=n.getBoundingClientRect();this.open(r.left+Math.min(16,r.width/2),r.bottom,{region:t,origin:n,keyboard:!0})&&(e.preventDefault(),f={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!h(e,t.region,()=>this.close(!0)))return;let n=t.trigger.getBoundingClientRect();this.open(n.left,n.bottom,{region:t.region,origin:t.trigger,trigger:t.trigger,keyboard:e.detail===0})}_handlePointerDown(e){if(e.pointerType!==`touch`)return;let t=this._regionFor(e.target);if(!t||!h(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=g(e.target);this._press={x:n,y:r,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},c)},document.addEventListener(`pointermove`,this._onPressMove,{passive:!0}),document.addEventListener(`pointerup`,this._onPressEnd),document.addEventListener(`pointercancel`,this._onPressEnd),window.addEventListener(`scroll`,this._onPressEnd,!0)}_cancelPress(){this._press&&(clearTimeout(this._press.timer),this._press=null,document.removeEventListener(`pointermove`,this._onPressMove),document.removeEventListener(`pointerup`,this._onPressEnd),document.removeEventListener(`pointercancel`,this._onPressEnd),window.removeEventListener(`scroll`,this._onPressEnd,!0))}_handleMenuKey(e){if(!this.isOpen)return;let t=g(e.target);if(!t)return;if(t.matches(a)){this._handleSearchKey(e,t);return}let n=w(t,`[role="menu"]`);if(!n)return;let i=w(t,r),o=n.matches(`.wui-context-menu-subpanel`)?n.parentElement:null;if(e.key===`Escape`){if(e.preventDefault(),e.stopPropagation(),o)this._closeSubByKey(o);else{let e=this._openSubOf(n);e?this._closeSubByKey(e):this.close(!0)}}else if(e.key===`Tab`)this.close(!0);else if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),e.stopPropagation(),this._step(n,i,e.key===`ArrowDown`?1:-1);else if(e.key===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(e.key===`ArrowLeft`){if(!o)return;e.preventDefault(),this._closeSubByKey(o)}else e.key===`Enter`||e.key===` `?(e.preventDefault(),i?.click()):(this._navPanel=n,this._nav.handler(e))}_handleSearchKey(e,t){let n=w(t,i);if(!n)return;let r=this._rowsOf(C(n));e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closeSubByKey(n)):e.key===`ArrowDown`?(e.preventDefault(),r[0]?.focus({preventScroll:!0})):e.key===`ArrowUp`?(e.preventDefault(),r[r.length-1]?.focus({preventScroll:!0})):e.key===`Tab`&&this.close(!0)}_step(e,t,n){let r=this._rowsOf(e);if(!r.length)return;let i=t?r.indexOf(t):-1;r[i<0?n>0?0:r.length-1:(i+n+r.length)%r.length]?.focus({preventScroll:!0})}_subOf(e){return e.hasAttribute(`aria-haspopup`)&&e.parentElement?.matches(i)?e.parentElement:null}_openSubOf(e){return b(e).find(e=>e.matches(i)&&C(e).hasAttribute(s))??null}_openSub(e,t){let n=e.parentElement;if(!n)throw Error(`a submenu is always inside its menu panel`);for(let t of b(n))t!==e&&t.matches(i)&&this._closeSub(t);this._setSub(e,!0);let r=C(e).querySelector(`:scope > ${a}`),o=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;o?(o.value=``,this._filter(e,``),o.focus({preventScroll:!0})):t&&this._rowsOf(C(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of y(C(e),i))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),S(e).focus({preventScroll:!0})}_setSub(t,n){let r=S(t),i=C(t);i.toggleAttribute(s,n),r.setAttribute(`aria-expanded`,String(n)),n?e(r,i,{beside:!0}):i.removeAttribute(`data-side`)}_filter(e,t){let n=t.trim().toLowerCase();for(let t of b(C(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(r)?t.hidden=n!==``&&!v(t).toLowerCase().includes(n):t.matches(i)&&(t.hidden=n!==``&&!v(S(t)).toLowerCase().includes(n))}_handleInput(e){let t=g(e.target)?.closest(a);if(!(t instanceof HTMLInputElement))return;let n=w(t,i);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of y(e,r)){let e=t.getAttribute(`aria-checked`)===`true`,n=t.querySelector(`:scope > .wui-context-menu-tick`);if(e&&!n){let e=document.createElement(`span`);e.className=`wui-context-menu-tick`,e.setAttribute(`aria-hidden`,`true`),t.prepend(e)}else!e&&n&&n.remove();let r=t.querySelector(`:scope > .wui-context-menu-hint`),i=t.dataset.hint;if(i){let e=r??document.createElement(`span`);r||(e.className=`wui-context-menu-hint`,e.id=`wui-context-menu-hint-${++p}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=w(g(e.target),r);if(!t||!this._inPanel(t))return;if(this._isDisabled(t)){e.preventDefault(),e.stopPropagation();return}let n=this._subOf(t);n?(e.preventDefault(),this._openSub(n,e.detail===0)):(this.close(!0),this.dispatchEvent(new CustomEvent(`wui-context-menu:select`,{bubbles:!0,detail:{key:t.dataset.key??null,item:t,region:this._region,origin:this._origin}})))}_teardown(){this.close(),this._cancelPress(),document.removeEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.removeEventListener(`contextmenu`,this._onContextMenu),document.removeEventListener(`keydown`,this._onDocKeyDown),document.removeEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.removeEventListener(`pointerdown`,this._onPointerDown),document.removeEventListener(`click`,this._onClickCapture,!0),document.removeEventListener(`click`,this._onDocClick),window.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`input`,this._onInput),this.removeEventListener(`mousemove`,this._onMouseMove)}};export{T 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-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
|
+
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-Bxkq7dvu.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,4 +1,4 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{n as r,t as i}from"./countries-DQL9nAUt.js";import{t as a}from"./devWarn-DXdRWZs3.js";import{t as o}from"./elementBase-Cxeyx0tU.js";import{r as s,t as c}from"./fieldState-D-zQcXUS.js";import{t as l}from"./formMirror-9IpSgeZb.js";import{t as u}from"./iconGlyphs.g-DPqoOoXy.js";import{n as d}from"./listboxKeyNav-4LeEjKq6.js";var f={AD:[`Europe/Andorra`],AE:[`Asia/Dubai`],AF:[`Asia/Kabul`],AG:[`America/Antigua`],AI:[`America/Anguilla`],AL:[`Europe/Tirane`],AM:[`Asia/Yerevan`],AO:[`Africa/Luanda`],AR:[`America/Argentina/Buenos_Aires`,`America/Argentina/Catamarca`,`America/Argentina/ComodRivadavia`,`America/Argentina/Cordoba`,`America/Argentina/Jujuy`,`America/Argentina/La_Rioja`,`America/Argentina/Mendoza`,`America/Argentina/Rio_Gallegos`,`America/Argentina/Salta`,`America/Argentina/San_Juan`,`America/Argentina/San_Luis`,`America/Argentina/Tucuman`,`America/Argentina/Ushuaia`,`America/Buenos_Aires`,`America/Catamarca`,`America/Cordoba`,`America/Jujuy`,`America/Mendoza`,`America/Rosario`],AS:[`Pacific/Pago_Pago`,`Pacific/Samoa`,`US/Samoa`],AT:[`Europe/Vienna`],AU:[`Antarctica/Macquarie`,`Australia/Adelaide`,`Australia/Brisbane`,`Australia/Broken_Hill`,`Australia/Canberra`,`Australia/Currie`,`Australia/Darwin`,`Australia/Eucla`,`Australia/Hobart`,`Australia/LHI`,`Australia/Lindeman`,`Australia/Lord_Howe`,`Australia/Melbourne`,`Australia/NSW`,`Australia/North`,`Australia/Perth`,`Australia/Queensland`,`Australia/South`,`Australia/Sydney`,`Australia/Tasmania`,`Australia/Victoria`,`Australia/West`,`Australia/Yancowinna`],AW:[`America/Aruba`],AX:[`Europe/Mariehamn`],AZ:[`Asia/Baku`],BA:[`Europe/Sarajevo`],BB:[`America/Barbados`],BD:[`Asia/Dacca`,`Asia/Dhaka`],BE:[`Europe/Brussels`],BF:[`Africa/Ouagadougou`],BG:[`Europe/Sofia`],BH:[`Asia/Bahrain`],BI:[`Africa/Bujumbura`],BJ:[`Africa/Porto-Novo`],BL:[`America/St_Barthelemy`],BM:[`Atlantic/Bermuda`],BN:[`Asia/Brunei`],BO:[`America/La_Paz`],BQ:[`America/Kralendijk`],BR:[`America/Araguaina`,`America/Bahia`,`America/Belem`,`America/Boa_Vista`,`America/Campo_Grande`,`America/Cuiaba`,`America/Eirunepe`,`America/Fortaleza`,`America/Maceio`,`America/Manaus`,`America/Noronha`,`America/Porto_Acre`,`America/Porto_Velho`,`America/Recife`,`America/Rio_Branco`,`America/Santarem`,`America/Sao_Paulo`,`Brazil/DeNoronha`,`Brazil/East`,`Brazil/West`],BS:[`America/Nassau`],BT:[`Asia/Thimbu`,`Asia/Thimphu`],BW:[`Africa/Gaborone`],BY:[`Europe/Minsk`],BZ:[`America/Belize`],CA:/* @__PURE__ */ `America/Atikokan.America/Blanc-Sablon.America/Cambridge_Bay.America/Coral_Harbour.America/Creston.America/Dawson.America/Dawson_Creek.America/Edmonton.America/Fort_Nelson.America/Glace_Bay.America/Goose_Bay.America/Halifax.America/Inuvik.America/Iqaluit.America/Moncton.America/Montreal.America/Nipigon.America/Pangnirtung.America/Rainy_River.America/Rankin_Inlet.America/Regina.America/Resolute.America/St_Johns.America/Swift_Current.America/Thunder_Bay.America/Toronto.America/Vancouver.America/Whitehorse.America/Winnipeg.America/Yellowknife.Canada/Atlantic.Canada/Central.Canada/Eastern.Canada/Mountain.Canada/Newfoundland.Canada/Pacific.Canada/Saskatchewan.Canada/Yukon`.split(`.`),CC:[`Indian/Cocos`],CD:[`Africa/Kinshasa`,`Africa/Lubumbashi`],CF:[`Africa/Bangui`],CG:[`Africa/Brazzaville`],CH:[`Europe/Zurich`],CI:[`Africa/Abidjan`],CK:[`Pacific/Rarotonga`],CL:[`America/Coyhaique`,`America/Punta_Arenas`,`America/Santiago`,`Chile/Continental`,`Chile/EasterIsland`,`Pacific/Easter`],CM:[`Africa/Douala`],CN:[`Asia/Chongqing`,`Asia/Harbin`,`Asia/Kashgar`,`Asia/Shanghai`,`Asia/Urumqi`],CO:[`America/Bogota`],CR:[`America/Costa_Rica`],CU:[`America/Havana`],CV:[`Atlantic/Cape_Verde`],CW:[`America/Curacao`],CX:[`Indian/Christmas`],CY:[`Asia/Famagusta`,`Asia/Nicosia`,`Europe/Nicosia`],CZ:[`Europe/Prague`],DE:[`Europe/Berlin`,`Europe/Busingen`],DJ:[`Africa/Djibouti`],DK:[`Europe/Copenhagen`],DM:[`America/Dominica`],DO:[`America/Santo_Domingo`],DZ:[`Africa/Algiers`],EC:[`America/Guayaquil`,`Pacific/Galapagos`],EE:[`Europe/Tallinn`],EG:[`Africa/Cairo`],EH:[`Africa/El_Aaiun`],ER:[`Africa/Asmara`,`Africa/Asmera`],ES:[`Africa/Ceuta`,`Atlantic/Canary`,`Europe/Madrid`],ET:[`Africa/Addis_Ababa`],FI:[`Europe/Helsinki`],FJ:[`Pacific/Fiji`],FK:[`Atlantic/Stanley`],FM:[`Pacific/Chuuk`,`Pacific/Kosrae`,`Pacific/Pohnpei`,`Pacific/Ponape`,`Pacific/Truk`,`Pacific/Yap`],FO:[`Atlantic/Faeroe`,`Atlantic/Faroe`],FR:[`Europe/Paris`],GA:[`Africa/Libreville`],GB:[`Europe/Belfast`,`Europe/London`],GD:[`America/Grenada`],GE:[`Asia/Tbilisi`],GF:[`America/Cayenne`],GG:[`Europe/Guernsey`],GH:[`Africa/Accra`],GI:[`Europe/Gibraltar`],GL:[`America/Danmarkshavn`,`America/Godthab`,`America/Nuuk`,`America/Scoresbysund`,`America/Thule`],GM:[`Africa/Banjul`],GN:[`Africa/Conakry`],GP:[`America/Guadeloupe`],GQ:[`Africa/Malabo`],GR:[`Europe/Athens`],GT:[`America/Guatemala`],GU:[`Pacific/Guam`],GW:[`Africa/Bissau`],GY:[`America/Guyana`],HK:[`Asia/Hong_Kong`],HN:[`America/Tegucigalpa`],HR:[`Europe/Zagreb`],HT:[`America/Port-au-Prince`],HU:[`Europe/Budapest`],ID:[`Asia/Jakarta`,`Asia/Jayapura`,`Asia/Makassar`,`Asia/Pontianak`,`Asia/Ujung_Pandang`],IE:[`Europe/Dublin`],IL:[`Asia/Jerusalem`,`Asia/Tel_Aviv`],IM:[`Europe/Isle_of_Man`],IN:[`Asia/Calcutta`,`Asia/Kolkata`],IO:[`Indian/Chagos`],IQ:[`Asia/Baghdad`],IR:[`Asia/Tehran`],IS:[`Atlantic/Reykjavik`],IT:[`Europe/Rome`],JE:[`Europe/Jersey`],JM:[`America/Jamaica`],JO:[`Asia/Amman`],JP:[`Asia/Tokyo`],KE:[`Africa/Nairobi`],KG:[`Asia/Bishkek`],KH:[`Asia/Phnom_Penh`],KI:[`Pacific/Enderbury`,`Pacific/Kanton`,`Pacific/Kiritimati`,`Pacific/Tarawa`],KM:[`Indian/Comoro`],KN:[`America/St_Kitts`],KP:[`Asia/Pyongyang`],KR:[`Asia/Seoul`],KW:[`Asia/Kuwait`],KY:[`America/Cayman`],KZ:[`Asia/Almaty`,`Asia/Aqtau`,`Asia/Aqtobe`,`Asia/Atyrau`,`Asia/Oral`,`Asia/Qostanay`,`Asia/Qyzylorda`],LA:[`Asia/Vientiane`],LB:[`Asia/Beirut`],LC:[`America/St_Lucia`],LI:[`Europe/Vaduz`],LK:[`Asia/Colombo`],LR:[`Africa/Monrovia`],LS:[`Africa/Maseru`],LT:[`Europe/Vilnius`],LU:[`Europe/Luxembourg`],LV:[`Europe/Riga`],LY:[`Africa/Tripoli`],MA:[`Africa/Casablanca`],MC:[`Europe/Monaco`],MD:[`Europe/Chisinau`,`Europe/Tiraspol`],ME:[`Europe/Podgorica`],MF:[`America/Marigot`],MG:[`Indian/Antananarivo`],MH:[`Pacific/Kwajalein`,`Pacific/Majuro`],MK:[`Europe/Skopje`],ML:[`Africa/Bamako`,`Africa/Timbuktu`],MM:[`Asia/Rangoon`,`Asia/Yangon`],MN:[`Asia/Choibalsan`,`Asia/Hovd`,`Asia/Ulaanbaatar`,`Asia/Ulan_Bator`],MO:[`Asia/Macao`,`Asia/Macau`],MP:[`Pacific/Saipan`],MQ:[`America/Martinique`],MR:[`Africa/Nouakchott`],MS:[`America/Montserrat`],MT:[`Europe/Malta`],MU:[`Indian/Mauritius`],MV:[`Indian/Maldives`],MW:[`Africa/Blantyre`],MX:[`America/Bahia_Banderas`,`America/Cancun`,`America/Chihuahua`,`America/Ciudad_Juarez`,`America/Ensenada`,`America/Hermosillo`,`America/Matamoros`,`America/Mazatlan`,`America/Merida`,`America/Mexico_City`,`America/Monterrey`,`America/Ojinaga`,`America/Santa_Isabel`,`America/Tijuana`,`Mexico/BajaNorte`,`Mexico/BajaSur`,`Mexico/General`],MY:[`Asia/Kuala_Lumpur`,`Asia/Kuching`],MZ:[`Africa/Maputo`],NA:[`Africa/Windhoek`],NC:[`Pacific/Noumea`],NE:[`Africa/Niamey`],NF:[`Pacific/Norfolk`],NG:[`Africa/Lagos`],NI:[`America/Managua`],NL:[`Europe/Amsterdam`],NO:[`Europe/Oslo`],NP:[`Asia/Kathmandu`,`Asia/Katmandu`],NR:[`Pacific/Nauru`],NU:[`Pacific/Niue`],NZ:[`Pacific/Auckland`,`Pacific/Chatham`],OM:[`Asia/Muscat`],PA:[`America/Panama`],PE:[`America/Lima`],PF:[`Pacific/Gambier`,`Pacific/Marquesas`,`Pacific/Tahiti`],PG:[`Pacific/Bougainville`,`Pacific/Port_Moresby`],PH:[`Asia/Manila`],PK:[`Asia/Karachi`],PL:[`Europe/Warsaw`],PM:[`America/Miquelon`],PR:[`America/Puerto_Rico`],PS:[`Asia/Gaza`,`Asia/Hebron`],PT:[`Atlantic/Azores`,`Atlantic/Madeira`,`Europe/Lisbon`],PW:[`Pacific/Palau`],PY:[`America/Asuncion`],QA:[`Asia/Qatar`],RE:[`Indian/Reunion`],RO:[`Europe/Bucharest`],RS:[`Europe/Belgrade`],RU:/* @__PURE__ */ `Asia/Anadyr.Asia/Barnaul.Asia/Chita.Asia/Irkutsk.Asia/Kamchatka.Asia/Khandyga.Asia/Krasnoyarsk.Asia/Magadan.Asia/Novokuznetsk.Asia/Novosibirsk.Asia/Omsk.Asia/Sakhalin.Asia/Srednekolymsk.Asia/Tomsk.Asia/Ust-Nera.Asia/Vladivostok.Asia/Yakutsk.Asia/Yekaterinburg.Europe/Astrakhan.Europe/Kaliningrad.Europe/Kirov.Europe/Moscow.Europe/Samara.Europe/Saratov.Europe/Ulyanovsk.Europe/Volgograd`.split(`.`),RW:[`Africa/Kigali`],SA:[`Asia/Riyadh`],SB:[`Pacific/Guadalcanal`],SC:[`Indian/Mahe`],SD:[`Africa/Khartoum`],SE:[`Europe/Stockholm`],SG:[`Asia/Singapore`],SH:[`Atlantic/St_Helena`],SI:[`Europe/Ljubljana`],SJ:[`Arctic/Longyearbyen`,`Atlantic/Jan_Mayen`],SK:[`Europe/Bratislava`],SL:[`Africa/Freetown`],SM:[`Europe/San_Marino`],SN:[`Africa/Dakar`],SO:[`Africa/Mogadishu`],SR:[`America/Paramaribo`],SS:[`Africa/Juba`],ST:[`Africa/Sao_Tome`],SV:[`America/El_Salvador`],SX:[`America/Lower_Princes`],SY:[`Asia/Damascus`],SZ:[`Africa/Mbabane`],TC:[`America/Grand_Turk`],TD:[`Africa/Ndjamena`],TG:[`Africa/Lome`],TH:[`Asia/Bangkok`],TJ:[`Asia/Dushanbe`],TK:[`Pacific/Fakaofo`],TL:[`Asia/Dili`],TM:[`Asia/Ashgabat`,`Asia/Ashkhabad`],TN:[`Africa/Tunis`],TO:[`Pacific/Tongatapu`],TR:[`Asia/Istanbul`,`Europe/Istanbul`],TT:[`America/Port_of_Spain`],TV:[`Pacific/Funafuti`],TW:[`Asia/Taipei`],TZ:[`Africa/Dar_es_Salaam`],UA:[`Europe/Kiev`,`Europe/Kyiv`,`Europe/Simferopol`,`Europe/Uzhgorod`,`Europe/Zaporozhye`],UG:[`Africa/Kampala`],US:/* @__PURE__ */ `America/Adak.America/Anchorage.America/Atka.America/Boise.America/Chicago.America/Denver.America/Detroit.America/Fort_Wayne.America/Indiana/Indianapolis.America/Indiana/Knox.America/Indiana/Marengo.America/Indiana/Petersburg.America/Indiana/Tell_City.America/Indiana/Vevay.America/Indiana/Vincennes.America/Indiana/Winamac.America/Indianapolis.America/Juneau.America/Kentucky/Louisville.America/Kentucky/Monticello.America/Knox_IN.America/Los_Angeles.America/Louisville.America/Menominee.America/Metlakatla.America/New_York.America/Nome.America/North_Dakota/Beulah.America/North_Dakota/Center.America/North_Dakota/New_Salem.America/Phoenix.America/Shiprock.America/Sitka.America/Yakutat.Pacific/Honolulu.US/Alaska.US/Aleutian.US/Arizona.US/Central.US/East-Indiana.US/Eastern.US/Hawaii.US/Indiana-Starke.US/Michigan.US/Mountain.US/Pacific`.split(`.`),UY:[`America/Montevideo`],UZ:[`Asia/Samarkand`,`Asia/Tashkent`],VA:[`Europe/Vatican`],VC:[`America/St_Vincent`],VE:[`America/Caracas`],VG:[`America/Tortola`],VI:[`America/St_Thomas`,`America/Virgin`],VN:[`Asia/Ho_Chi_Minh`,`Asia/Saigon`],VU:[`Pacific/Efate`],WF:[`Pacific/Wallis`],WS:[`Pacific/Apia`],YE:[`Asia/Aden`],YT:[`Indian/Mayotte`],ZA:[`Africa/Johannesburg`],ZM:[`Africa/Lusaka`],ZW:[`Africa/Harare`]},p=new Set(i.map(([e])=>e)),m=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(f))for(let n of t)m.set(n,e);function h(e){let t=e===void 0?void 0:m.get(e);return t&&p.has(t)?t:null}function g(e){if(!e)return null;let t;try{t=new Intl.Locale(e).region}catch{return null}return t&&p.has(t)?t:null}function _(){let e;try{e=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{e=void 0}let t=typeof navigator>`u`?void 0:navigator.language;return h(e)||g(t)||null}function v(){return Promise.all([import(`./max-ByBKGsXq.js`),import(`./examples.mobile.json-GS1_MGh9.js`)]).then(([e,t])=>y(e,t.default||t))}function y(e,t){return{AsYouType:e.AsYouType,getExampleNumber:e.getExampleNumber,isSupportedCountry:e.isSupportedCountry,isValidPhoneNumber:e.isValidPhoneNumber,parsePhoneNumber:e.parsePhoneNumber,examples:t}}function b(e,t){return e.isSupportedCountry(t)}var x=e=>e?`wui-flag wui-flag-${String(e).toLowerCase()}`:`wui-flag`,S=e=>e?`+${r(e)}`:``,C=null,w=null;function T(){return C?Promise.resolve(C):(w||=v().then(e=>(C=e,C)).catch(e=>(a(`[@webority/ui-elements] <wui-phone> could not load its phone number metadata.`,e),null)),w)}function E(e,t){let n=`+${r(e)}`;return t?.startsWith(n)?t.slice(n.length).trimStart():null}function D(e,t){if(!C||!t||!e||!b(C,e))return t;try{return E(e,new C.AsYouType(e).input(`+${r(e)}${t}`))||t}catch{return t}}function O(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r++)if(/[0-9]/.test(e[r]??``)&&(n+=1,n===t))return r+1;return e.length}function k(e){if(!C||!e||!b(C,e))return null;try{return E(e,C.getExampleNumber(e,C.examples)?.formatInternational())||null}catch{return null}}function A(e){let t=k(e);return t?`For example ${t}`:null}function j(e){if(!C||!e)return null;try{if(!C.isValidPhoneNumber(e))return!1;let t=C.parsePhoneNumber(e)?.getType?.();return t===void 0||t===`MOBILE`||t===`FIXED_LINE_OR_MOBILE`}catch{return null}}function M(e){if(!C||!e||!b(C,e))return null;try{let t=C.getExampleNumber(e,C.examples);return t?.nationalNumber?t.nationalNumber.length:null}catch{return null}}function N(e,t,n){if(!C||!b(C,e))return null;try{let r=C.parsePhoneNumber(t,e),i=r?.nationalNumber;return!i||r.country!==e||i.length>n||!t.endsWith(i)?null:i}catch{return null}}function P(e){if(!C||!e?.trim().startsWith(`+`))return null;try{let t=new C.AsYouType;t.input(e.trim());let n=t.getCountry();return!n||!B(t)?null:{country:n,national:t.getNationalNumber()||``}}catch{return null}}function F(e,t){let n=String(t??``).trim();if(!n.startsWith(`+`))return null;let i=n.replace(/[^0-9]/g,``),a=String(r(e));return{country:e,national:i.startsWith(a)?i.slice(a.length):i}}var I=class extends o{static formAssociated=!0;static get observedAttributes(){return[`value`,`country`,`locked-country`,`placeholder`,`disabled`,`readonly`,`loading`,`required`,`aria-label`,`aria-describedby`]}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._defaultCountry=_()||``,this._country=this._defaultCountry,this._national=``,this._active=-1,this._committedValue=``,this._validateOnInput=!1}connectedCallback(){this._rendered?this._bindGlobal?.():this.render()}attributeChangedCallback(e,t,n){if(e===`value`)this.value=n;else if(this._rendered){if(e===`aria-label`){let t=this.querySelector(`input[type=tel]`);t&&(n==null?t.removeAttribute(e):t.setAttribute(e,n))}else if(e===`aria-describedby`)this._syncDescribedBy();else if(e===`country`){if(this._locked)return;let e=this.value;if(this._country=n||this._defaultCountry,this._suppressCountryRender)return;this.render(),this.value!==e&&(this._emitInput(),this._emitChange())}else this.render()}}formResetCallback(){this._validateOnInput=!1,this.value=this._defaultValue||``}get _locked(){return(this.getAttribute(`locked-country`)||``).toUpperCase()||null}get value(){return this._national&&this._country?`+${r(this._country)}${this._national}`:``}set value(e){let t=String(e??``).trim();this._locked&&(this._country=this._locked);let n=this._locked?null:P(t);if(n)this._country=n.country,this._national=n.national.replace(/[^0-9]/g,``);else if(t.startsWith(`+`)){let e=t.replace(/[^0-9]/g,``),n=String(r(this._locked||this.getAttribute(`country`)||this._country));n&&e.startsWith(n)&&(e=e.slice(n.length)),this._national=e}else this._national=t.replace(/[^0-9]/g,``);n&&this.getAttribute(`country`)!==this._country?this.setAttribute(`country`,this._country):this._rendered&&this.render(),this._committedValue=this.value,this._syncMirror()}_syncMirror(){l(this,this.value)}_syncDescribedBy(){let e=this.querySelector(`input[type=tel]`);if(!e)return;let t=[this.getAttribute(`aria-describedby`),this.querySelector(`[data-phone-error]`)?.id].filter(Boolean);t.length?e.setAttribute(`aria-describedby`,t.join(` `)):e.removeAttribute(`aria-describedby`)}_emitInput(){this.dispatchEvent(new Event(`input`,{bubbles:!0}))}_emitChange(){this._committedValue=this.value,this.dispatchEvent(new Event(`change`,{bubbles:!0}))}render(){this._defaultValue===void 0&&(this._defaultValue=this.getAttribute(`value`)||``),this._country=this._locked||this.getAttribute(`country`)||this._country;let e=this.getAttribute(`placeholder`)||A(this._country)||`Enter phone number`;this.id||=`wui-phone-${Math.random().toString(36).slice(2,9)}`;let t=`${this.id}-listbox`;this._listboxId=t;let n=this._locked?`<div class="phone-country-adornment"><span class="wui-phone-prefix"><span class="${x(this._country)}" data-flag aria-hidden="true"></span><span class="phone-dial" data-dial>${S(this._country)}</span></span></div>`:`<div class="phone-country-adornment">
|
|
1
|
+
import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{n as r,t as i}from"./countries-DQL9nAUt.js";import{t as a}from"./devWarn-DXdRWZs3.js";import{t as o}from"./elementBase-Cxeyx0tU.js";import{r as s,t as c}from"./fieldState-D-zQcXUS.js";import{t as l}from"./formMirror-9IpSgeZb.js";import{t as u}from"./iconGlyphs.g-DPqoOoXy.js";import{n as d}from"./listboxKeyNav-Bxkq7dvu.js";var f={AD:[`Europe/Andorra`],AE:[`Asia/Dubai`],AF:[`Asia/Kabul`],AG:[`America/Antigua`],AI:[`America/Anguilla`],AL:[`Europe/Tirane`],AM:[`Asia/Yerevan`],AO:[`Africa/Luanda`],AR:[`America/Argentina/Buenos_Aires`,`America/Argentina/Catamarca`,`America/Argentina/ComodRivadavia`,`America/Argentina/Cordoba`,`America/Argentina/Jujuy`,`America/Argentina/La_Rioja`,`America/Argentina/Mendoza`,`America/Argentina/Rio_Gallegos`,`America/Argentina/Salta`,`America/Argentina/San_Juan`,`America/Argentina/San_Luis`,`America/Argentina/Tucuman`,`America/Argentina/Ushuaia`,`America/Buenos_Aires`,`America/Catamarca`,`America/Cordoba`,`America/Jujuy`,`America/Mendoza`,`America/Rosario`],AS:[`Pacific/Pago_Pago`,`Pacific/Samoa`,`US/Samoa`],AT:[`Europe/Vienna`],AU:[`Antarctica/Macquarie`,`Australia/Adelaide`,`Australia/Brisbane`,`Australia/Broken_Hill`,`Australia/Canberra`,`Australia/Currie`,`Australia/Darwin`,`Australia/Eucla`,`Australia/Hobart`,`Australia/LHI`,`Australia/Lindeman`,`Australia/Lord_Howe`,`Australia/Melbourne`,`Australia/NSW`,`Australia/North`,`Australia/Perth`,`Australia/Queensland`,`Australia/South`,`Australia/Sydney`,`Australia/Tasmania`,`Australia/Victoria`,`Australia/West`,`Australia/Yancowinna`],AW:[`America/Aruba`],AX:[`Europe/Mariehamn`],AZ:[`Asia/Baku`],BA:[`Europe/Sarajevo`],BB:[`America/Barbados`],BD:[`Asia/Dacca`,`Asia/Dhaka`],BE:[`Europe/Brussels`],BF:[`Africa/Ouagadougou`],BG:[`Europe/Sofia`],BH:[`Asia/Bahrain`],BI:[`Africa/Bujumbura`],BJ:[`Africa/Porto-Novo`],BL:[`America/St_Barthelemy`],BM:[`Atlantic/Bermuda`],BN:[`Asia/Brunei`],BO:[`America/La_Paz`],BQ:[`America/Kralendijk`],BR:[`America/Araguaina`,`America/Bahia`,`America/Belem`,`America/Boa_Vista`,`America/Campo_Grande`,`America/Cuiaba`,`America/Eirunepe`,`America/Fortaleza`,`America/Maceio`,`America/Manaus`,`America/Noronha`,`America/Porto_Acre`,`America/Porto_Velho`,`America/Recife`,`America/Rio_Branco`,`America/Santarem`,`America/Sao_Paulo`,`Brazil/DeNoronha`,`Brazil/East`,`Brazil/West`],BS:[`America/Nassau`],BT:[`Asia/Thimbu`,`Asia/Thimphu`],BW:[`Africa/Gaborone`],BY:[`Europe/Minsk`],BZ:[`America/Belize`],CA:/* @__PURE__ */ `America/Atikokan.America/Blanc-Sablon.America/Cambridge_Bay.America/Coral_Harbour.America/Creston.America/Dawson.America/Dawson_Creek.America/Edmonton.America/Fort_Nelson.America/Glace_Bay.America/Goose_Bay.America/Halifax.America/Inuvik.America/Iqaluit.America/Moncton.America/Montreal.America/Nipigon.America/Pangnirtung.America/Rainy_River.America/Rankin_Inlet.America/Regina.America/Resolute.America/St_Johns.America/Swift_Current.America/Thunder_Bay.America/Toronto.America/Vancouver.America/Whitehorse.America/Winnipeg.America/Yellowknife.Canada/Atlantic.Canada/Central.Canada/Eastern.Canada/Mountain.Canada/Newfoundland.Canada/Pacific.Canada/Saskatchewan.Canada/Yukon`.split(`.`),CC:[`Indian/Cocos`],CD:[`Africa/Kinshasa`,`Africa/Lubumbashi`],CF:[`Africa/Bangui`],CG:[`Africa/Brazzaville`],CH:[`Europe/Zurich`],CI:[`Africa/Abidjan`],CK:[`Pacific/Rarotonga`],CL:[`America/Coyhaique`,`America/Punta_Arenas`,`America/Santiago`,`Chile/Continental`,`Chile/EasterIsland`,`Pacific/Easter`],CM:[`Africa/Douala`],CN:[`Asia/Chongqing`,`Asia/Harbin`,`Asia/Kashgar`,`Asia/Shanghai`,`Asia/Urumqi`],CO:[`America/Bogota`],CR:[`America/Costa_Rica`],CU:[`America/Havana`],CV:[`Atlantic/Cape_Verde`],CW:[`America/Curacao`],CX:[`Indian/Christmas`],CY:[`Asia/Famagusta`,`Asia/Nicosia`,`Europe/Nicosia`],CZ:[`Europe/Prague`],DE:[`Europe/Berlin`,`Europe/Busingen`],DJ:[`Africa/Djibouti`],DK:[`Europe/Copenhagen`],DM:[`America/Dominica`],DO:[`America/Santo_Domingo`],DZ:[`Africa/Algiers`],EC:[`America/Guayaquil`,`Pacific/Galapagos`],EE:[`Europe/Tallinn`],EG:[`Africa/Cairo`],EH:[`Africa/El_Aaiun`],ER:[`Africa/Asmara`,`Africa/Asmera`],ES:[`Africa/Ceuta`,`Atlantic/Canary`,`Europe/Madrid`],ET:[`Africa/Addis_Ababa`],FI:[`Europe/Helsinki`],FJ:[`Pacific/Fiji`],FK:[`Atlantic/Stanley`],FM:[`Pacific/Chuuk`,`Pacific/Kosrae`,`Pacific/Pohnpei`,`Pacific/Ponape`,`Pacific/Truk`,`Pacific/Yap`],FO:[`Atlantic/Faeroe`,`Atlantic/Faroe`],FR:[`Europe/Paris`],GA:[`Africa/Libreville`],GB:[`Europe/Belfast`,`Europe/London`],GD:[`America/Grenada`],GE:[`Asia/Tbilisi`],GF:[`America/Cayenne`],GG:[`Europe/Guernsey`],GH:[`Africa/Accra`],GI:[`Europe/Gibraltar`],GL:[`America/Danmarkshavn`,`America/Godthab`,`America/Nuuk`,`America/Scoresbysund`,`America/Thule`],GM:[`Africa/Banjul`],GN:[`Africa/Conakry`],GP:[`America/Guadeloupe`],GQ:[`Africa/Malabo`],GR:[`Europe/Athens`],GT:[`America/Guatemala`],GU:[`Pacific/Guam`],GW:[`Africa/Bissau`],GY:[`America/Guyana`],HK:[`Asia/Hong_Kong`],HN:[`America/Tegucigalpa`],HR:[`Europe/Zagreb`],HT:[`America/Port-au-Prince`],HU:[`Europe/Budapest`],ID:[`Asia/Jakarta`,`Asia/Jayapura`,`Asia/Makassar`,`Asia/Pontianak`,`Asia/Ujung_Pandang`],IE:[`Europe/Dublin`],IL:[`Asia/Jerusalem`,`Asia/Tel_Aviv`],IM:[`Europe/Isle_of_Man`],IN:[`Asia/Calcutta`,`Asia/Kolkata`],IO:[`Indian/Chagos`],IQ:[`Asia/Baghdad`],IR:[`Asia/Tehran`],IS:[`Atlantic/Reykjavik`],IT:[`Europe/Rome`],JE:[`Europe/Jersey`],JM:[`America/Jamaica`],JO:[`Asia/Amman`],JP:[`Asia/Tokyo`],KE:[`Africa/Nairobi`],KG:[`Asia/Bishkek`],KH:[`Asia/Phnom_Penh`],KI:[`Pacific/Enderbury`,`Pacific/Kanton`,`Pacific/Kiritimati`,`Pacific/Tarawa`],KM:[`Indian/Comoro`],KN:[`America/St_Kitts`],KP:[`Asia/Pyongyang`],KR:[`Asia/Seoul`],KW:[`Asia/Kuwait`],KY:[`America/Cayman`],KZ:[`Asia/Almaty`,`Asia/Aqtau`,`Asia/Aqtobe`,`Asia/Atyrau`,`Asia/Oral`,`Asia/Qostanay`,`Asia/Qyzylorda`],LA:[`Asia/Vientiane`],LB:[`Asia/Beirut`],LC:[`America/St_Lucia`],LI:[`Europe/Vaduz`],LK:[`Asia/Colombo`],LR:[`Africa/Monrovia`],LS:[`Africa/Maseru`],LT:[`Europe/Vilnius`],LU:[`Europe/Luxembourg`],LV:[`Europe/Riga`],LY:[`Africa/Tripoli`],MA:[`Africa/Casablanca`],MC:[`Europe/Monaco`],MD:[`Europe/Chisinau`,`Europe/Tiraspol`],ME:[`Europe/Podgorica`],MF:[`America/Marigot`],MG:[`Indian/Antananarivo`],MH:[`Pacific/Kwajalein`,`Pacific/Majuro`],MK:[`Europe/Skopje`],ML:[`Africa/Bamako`,`Africa/Timbuktu`],MM:[`Asia/Rangoon`,`Asia/Yangon`],MN:[`Asia/Choibalsan`,`Asia/Hovd`,`Asia/Ulaanbaatar`,`Asia/Ulan_Bator`],MO:[`Asia/Macao`,`Asia/Macau`],MP:[`Pacific/Saipan`],MQ:[`America/Martinique`],MR:[`Africa/Nouakchott`],MS:[`America/Montserrat`],MT:[`Europe/Malta`],MU:[`Indian/Mauritius`],MV:[`Indian/Maldives`],MW:[`Africa/Blantyre`],MX:[`America/Bahia_Banderas`,`America/Cancun`,`America/Chihuahua`,`America/Ciudad_Juarez`,`America/Ensenada`,`America/Hermosillo`,`America/Matamoros`,`America/Mazatlan`,`America/Merida`,`America/Mexico_City`,`America/Monterrey`,`America/Ojinaga`,`America/Santa_Isabel`,`America/Tijuana`,`Mexico/BajaNorte`,`Mexico/BajaSur`,`Mexico/General`],MY:[`Asia/Kuala_Lumpur`,`Asia/Kuching`],MZ:[`Africa/Maputo`],NA:[`Africa/Windhoek`],NC:[`Pacific/Noumea`],NE:[`Africa/Niamey`],NF:[`Pacific/Norfolk`],NG:[`Africa/Lagos`],NI:[`America/Managua`],NL:[`Europe/Amsterdam`],NO:[`Europe/Oslo`],NP:[`Asia/Kathmandu`,`Asia/Katmandu`],NR:[`Pacific/Nauru`],NU:[`Pacific/Niue`],NZ:[`Pacific/Auckland`,`Pacific/Chatham`],OM:[`Asia/Muscat`],PA:[`America/Panama`],PE:[`America/Lima`],PF:[`Pacific/Gambier`,`Pacific/Marquesas`,`Pacific/Tahiti`],PG:[`Pacific/Bougainville`,`Pacific/Port_Moresby`],PH:[`Asia/Manila`],PK:[`Asia/Karachi`],PL:[`Europe/Warsaw`],PM:[`America/Miquelon`],PR:[`America/Puerto_Rico`],PS:[`Asia/Gaza`,`Asia/Hebron`],PT:[`Atlantic/Azores`,`Atlantic/Madeira`,`Europe/Lisbon`],PW:[`Pacific/Palau`],PY:[`America/Asuncion`],QA:[`Asia/Qatar`],RE:[`Indian/Reunion`],RO:[`Europe/Bucharest`],RS:[`Europe/Belgrade`],RU:/* @__PURE__ */ `Asia/Anadyr.Asia/Barnaul.Asia/Chita.Asia/Irkutsk.Asia/Kamchatka.Asia/Khandyga.Asia/Krasnoyarsk.Asia/Magadan.Asia/Novokuznetsk.Asia/Novosibirsk.Asia/Omsk.Asia/Sakhalin.Asia/Srednekolymsk.Asia/Tomsk.Asia/Ust-Nera.Asia/Vladivostok.Asia/Yakutsk.Asia/Yekaterinburg.Europe/Astrakhan.Europe/Kaliningrad.Europe/Kirov.Europe/Moscow.Europe/Samara.Europe/Saratov.Europe/Ulyanovsk.Europe/Volgograd`.split(`.`),RW:[`Africa/Kigali`],SA:[`Asia/Riyadh`],SB:[`Pacific/Guadalcanal`],SC:[`Indian/Mahe`],SD:[`Africa/Khartoum`],SE:[`Europe/Stockholm`],SG:[`Asia/Singapore`],SH:[`Atlantic/St_Helena`],SI:[`Europe/Ljubljana`],SJ:[`Arctic/Longyearbyen`,`Atlantic/Jan_Mayen`],SK:[`Europe/Bratislava`],SL:[`Africa/Freetown`],SM:[`Europe/San_Marino`],SN:[`Africa/Dakar`],SO:[`Africa/Mogadishu`],SR:[`America/Paramaribo`],SS:[`Africa/Juba`],ST:[`Africa/Sao_Tome`],SV:[`America/El_Salvador`],SX:[`America/Lower_Princes`],SY:[`Asia/Damascus`],SZ:[`Africa/Mbabane`],TC:[`America/Grand_Turk`],TD:[`Africa/Ndjamena`],TG:[`Africa/Lome`],TH:[`Asia/Bangkok`],TJ:[`Asia/Dushanbe`],TK:[`Pacific/Fakaofo`],TL:[`Asia/Dili`],TM:[`Asia/Ashgabat`,`Asia/Ashkhabad`],TN:[`Africa/Tunis`],TO:[`Pacific/Tongatapu`],TR:[`Asia/Istanbul`,`Europe/Istanbul`],TT:[`America/Port_of_Spain`],TV:[`Pacific/Funafuti`],TW:[`Asia/Taipei`],TZ:[`Africa/Dar_es_Salaam`],UA:[`Europe/Kiev`,`Europe/Kyiv`,`Europe/Simferopol`,`Europe/Uzhgorod`,`Europe/Zaporozhye`],UG:[`Africa/Kampala`],US:/* @__PURE__ */ `America/Adak.America/Anchorage.America/Atka.America/Boise.America/Chicago.America/Denver.America/Detroit.America/Fort_Wayne.America/Indiana/Indianapolis.America/Indiana/Knox.America/Indiana/Marengo.America/Indiana/Petersburg.America/Indiana/Tell_City.America/Indiana/Vevay.America/Indiana/Vincennes.America/Indiana/Winamac.America/Indianapolis.America/Juneau.America/Kentucky/Louisville.America/Kentucky/Monticello.America/Knox_IN.America/Los_Angeles.America/Louisville.America/Menominee.America/Metlakatla.America/New_York.America/Nome.America/North_Dakota/Beulah.America/North_Dakota/Center.America/North_Dakota/New_Salem.America/Phoenix.America/Shiprock.America/Sitka.America/Yakutat.Pacific/Honolulu.US/Alaska.US/Aleutian.US/Arizona.US/Central.US/East-Indiana.US/Eastern.US/Hawaii.US/Indiana-Starke.US/Michigan.US/Mountain.US/Pacific`.split(`.`),UY:[`America/Montevideo`],UZ:[`Asia/Samarkand`,`Asia/Tashkent`],VA:[`Europe/Vatican`],VC:[`America/St_Vincent`],VE:[`America/Caracas`],VG:[`America/Tortola`],VI:[`America/St_Thomas`,`America/Virgin`],VN:[`Asia/Ho_Chi_Minh`,`Asia/Saigon`],VU:[`Pacific/Efate`],WF:[`Pacific/Wallis`],WS:[`Pacific/Apia`],YE:[`Asia/Aden`],YT:[`Indian/Mayotte`],ZA:[`Africa/Johannesburg`],ZM:[`Africa/Lusaka`],ZW:[`Africa/Harare`]},p=new Set(i.map(([e])=>e)),m=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(f))for(let n of t)m.set(n,e);function h(e){let t=e===void 0?void 0:m.get(e);return t&&p.has(t)?t:null}function g(e){if(!e)return null;let t;try{t=new Intl.Locale(e).region}catch{return null}return t&&p.has(t)?t:null}function _(){let e;try{e=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{e=void 0}let t=typeof navigator>`u`?void 0:navigator.language;return h(e)||g(t)||null}function v(){return Promise.all([import(`./max-ByBKGsXq.js`),import(`./examples.mobile.json-GS1_MGh9.js`)]).then(([e,t])=>y(e,t.default||t))}function y(e,t){return{AsYouType:e.AsYouType,getExampleNumber:e.getExampleNumber,isSupportedCountry:e.isSupportedCountry,isValidPhoneNumber:e.isValidPhoneNumber,parsePhoneNumber:e.parsePhoneNumber,examples:t}}function b(e,t){return e.isSupportedCountry(t)}var x=e=>e?`wui-flag wui-flag-${String(e).toLowerCase()}`:`wui-flag`,S=e=>e?`+${r(e)}`:``,C=null,w=null;function T(){return C?Promise.resolve(C):(w||=v().then(e=>(C=e,C)).catch(e=>(a(`[@webority/ui-elements] <wui-phone> could not load its phone number metadata.`,e),null)),w)}function E(e,t){let n=`+${r(e)}`;return t?.startsWith(n)?t.slice(n.length).trimStart():null}function D(e,t){if(!C||!t||!e||!b(C,e))return t;try{return E(e,new C.AsYouType(e).input(`+${r(e)}${t}`))||t}catch{return t}}function O(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r++)if(/[0-9]/.test(e[r]??``)&&(n+=1,n===t))return r+1;return e.length}function k(e){if(!C||!e||!b(C,e))return null;try{return E(e,C.getExampleNumber(e,C.examples)?.formatInternational())||null}catch{return null}}function A(e){let t=k(e);return t?`For example ${t}`:null}function j(e){if(!C||!e)return null;try{if(!C.isValidPhoneNumber(e))return!1;let t=C.parsePhoneNumber(e)?.getType?.();return t===void 0||t===`MOBILE`||t===`FIXED_LINE_OR_MOBILE`}catch{return null}}function M(e){if(!C||!e||!b(C,e))return null;try{let t=C.getExampleNumber(e,C.examples);return t?.nationalNumber?t.nationalNumber.length:null}catch{return null}}function N(e,t,n){if(!C||!b(C,e))return null;try{let r=C.parsePhoneNumber(t,e),i=r?.nationalNumber;return!i||r.country!==e||i.length>n||!t.endsWith(i)?null:i}catch{return null}}function P(e){if(!C||!e?.trim().startsWith(`+`))return null;try{let t=new C.AsYouType;t.input(e.trim());let n=t.getCountry();return!n||!B(t)?null:{country:n,national:t.getNationalNumber()||``}}catch{return null}}function F(e,t){let n=String(t??``).trim();if(!n.startsWith(`+`))return null;let i=n.replace(/[^0-9]/g,``),a=String(r(e));return{country:e,national:i.startsWith(a)?i.slice(a.length):i}}var I=class extends o{static formAssociated=!0;static get observedAttributes(){return[`value`,`country`,`locked-country`,`placeholder`,`disabled`,`readonly`,`loading`,`required`,`aria-label`,`aria-describedby`]}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._defaultCountry=_()||``,this._country=this._defaultCountry,this._national=``,this._active=-1,this._committedValue=``,this._validateOnInput=!1}connectedCallback(){this._rendered?this._bindGlobal?.():this.render()}attributeChangedCallback(e,t,n){if(e===`value`)this.value=n;else if(this._rendered){if(e===`aria-label`){let t=this.querySelector(`input[type=tel]`);t&&(n==null?t.removeAttribute(e):t.setAttribute(e,n))}else if(e===`aria-describedby`)this._syncDescribedBy();else if(e===`country`){if(this._locked)return;let e=this.value;if(this._country=n||this._defaultCountry,this._suppressCountryRender)return;this.render(),this.value!==e&&(this._emitInput(),this._emitChange())}else this.render()}}formResetCallback(){this._validateOnInput=!1,this.value=this._defaultValue||``}get _locked(){return(this.getAttribute(`locked-country`)||``).toUpperCase()||null}get value(){return this._national&&this._country?`+${r(this._country)}${this._national}`:``}set value(e){let t=String(e??``).trim();this._locked&&(this._country=this._locked);let n=this._locked?null:P(t);if(n)this._country=n.country,this._national=n.national.replace(/[^0-9]/g,``);else if(t.startsWith(`+`)){let e=t.replace(/[^0-9]/g,``),n=String(r(this._locked||this.getAttribute(`country`)||this._country));n&&e.startsWith(n)&&(e=e.slice(n.length)),this._national=e}else this._national=t.replace(/[^0-9]/g,``);n&&this.getAttribute(`country`)!==this._country?this.setAttribute(`country`,this._country):this._rendered&&this.render(),this._committedValue=this.value,this._syncMirror()}_syncMirror(){l(this,this.value)}_syncDescribedBy(){let e=this.querySelector(`input[type=tel]`);if(!e)return;let t=[this.getAttribute(`aria-describedby`),this.querySelector(`[data-phone-error]`)?.id].filter(Boolean);t.length?e.setAttribute(`aria-describedby`,t.join(` `)):e.removeAttribute(`aria-describedby`)}_emitInput(){this.dispatchEvent(new Event(`input`,{bubbles:!0}))}_emitChange(){this._committedValue=this.value,this.dispatchEvent(new Event(`change`,{bubbles:!0}))}render(){this._defaultValue===void 0&&(this._defaultValue=this.getAttribute(`value`)||``),this._country=this._locked||this.getAttribute(`country`)||this._country;let e=this.getAttribute(`placeholder`)||A(this._country)||`Enter phone number`;this.id||=`wui-phone-${Math.random().toString(36).slice(2,9)}`;let t=`${this.id}-listbox`;this._listboxId=t;let n=this._locked?`<div class="phone-country-adornment"><span class="wui-phone-prefix"><span class="${x(this._country)}" data-flag aria-hidden="true"></span><span class="phone-dial" data-dial>${S(this._country)}</span></span></div>`:`<div class="phone-country-adornment">
|
|
2
2
|
<button type="button" class="country-toggle" aria-label="Choose country" aria-haspopup="listbox" aria-expanded="false" aria-controls="${V(t)}"${this.hasAttribute(`disabled`)?` disabled`:``}>
|
|
3
3
|
<span class="${x(this._country)}" data-flag aria-hidden="true"></span>
|
|
4
4
|
${u(`chevron-down`,{className:`phone-chevron`})}
|
|
@@ -1,4 +1,4 @@
|
|
|
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,`&`).replace(/"/g,`"`).replace(/</g,`<`);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-Dcw-b5cB.js`),chips:()=>import(`./chips-Dr_W3avk.js`),search:()=>import(`./search-PZCXpBAn.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=`
|
|
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-Bxkq7dvu.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,`&`).replace(/"/g,`"`).replace(/</g,`<`);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-Dcw-b5cB.js`),chips:()=>import(`./chips-DD_C4G0w.js`),search:()=>import(`./search-DMniXhEK.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
2
|
<div class="wui-select${s}">
|
|
3
3
|
${S}${C}${n?`</div>`:`</button>`}
|
|
4
4
|
<div class="wui-select-menu wui-select-menu-fixed" hidden>
|
|
@@ -6,4 +6,4 @@ import{n as e,r as t,t as n}from"./anchorOverlay-CXnWfezA.js";import{i as r,n as
|
|
|
6
6
|
<div class="wui-select-options" role="listbox" id="${i(p)}" tabindex="-1"${n?` aria-multiselectable="true"`:``}></div>
|
|
7
7
|
</div>
|
|
8
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};
|
|
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){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._value===``?this._listOptions().some(e=>String(e.value)===``)?[``]:[]:[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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./devWarn-DXdRWZs3.js";import{t}from"./elementBase-Cxeyx0tU.js";import{n,t as r}from"./formMirror-9IpSgeZb.js";import{t as i}from"./iconGlyphs.g-DPqoOoXy.js";import{t as a}from"./listboxKeyNav-4LeEjKq6.js";import{l as o}from"./wuiHttp-DGbD7Fra.js";var s=[`none`,`single`,`multiple`],c=e=>s.some(t=>t===e),l=`parentId`,u=`Loading`,d=`Could not load. Try again.`,f=`:scope > input[data-wui-mirror]`,p=[`nodes`,`selection`,`selected`,`values`,`loadChildren`,`loadUrl`,`name`],m=0;function h(e,t,n){let r=document.createElement(e);t&&(r.className=t);for(let[e,t]of Object.entries(n??{}))t!=null&&r.setAttribute(e,String(t));return r}var g=class extends t{_uid;_seq;_roots;_byId;_prev;_staged;_els;_checked;_selected;_focusId;_loader;_list;_live;_ready;_nav;_onKeyDown;_onClick;_onFocusIn;static get observedAttributes(){return[`selection`,`selected`,`name`,`aria-label`,`loading-text`,`error-text`]}constructor(){super(),this._uid=`wui-tree-${++m}`,this._seq=0,this._roots=[],this._byId=/* @__PURE__ */ new Map,this._prev=null,this._staged=null,this._els=/* @__PURE__ */ new Map,this._checked=/* @__PURE__ */ new Set,this._selected=null,this._focusId=null,this._loader=null,this._list=null,this._live=null,this._ready=!1,this._nav=a({getVisibleOptions:()=>this._visible().map(e=>{let t=this._els.get(e.id)?.row;if(!t)throw Error(`Row for node "${e.id}" is not rendered.`);return t}),getActive:()=>this._visible().findIndex(e=>e.id===this._focusId),setActive:e=>this._focusNode(this._visible()[e]),onEnter:()=>{let e=this._focusId===null?void 0:this._byId.get(this._focusId);e&&this._activate(e)}}),this._onKeyDown=e=>this._handleKeyDown(e),this._onClick=e=>this._handleClick(e),this._onFocusIn=e=>{let t=this._nodeFrom(e.target);t&&t.id!==this._focusId&&this._setRoving(t)}}connectedCallback(){let e=/* @__PURE__ */ new Map;for(let t of p)Object.hasOwn(this,t)&&(e.set(t,Reflect.get(this,t)),Reflect.deleteProperty(this,t));if(!this._ready){this._ready=!0;let e=this._readScript();this.replaceChildren(),this._list=h(`ul`,`wui-tree`),this._list.setAttribute(`role`,`tree`),this._live=h(`div`,`visually-hidden`,{role:`status`,"aria-live":`polite`}),this.append(this._list,this._live),e&&this._adoptAll(e)}for(let[t,n]of e)Reflect.set(this,t,n);this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`click`,this._onClick),this.addEventListener(`focusin`,this._onFocusIn),this._render(),this._loadOpenNodes()}disconnectedCallback(){this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`focusin`,this._onFocusIn),this._nav.teardown()}attributeChangedCallback(e,t,n){e===`selected`&&(this._selected=n),this._ready&&this.isConnected&&this._render()}get nodes(){return this._roots.map(e=>e.raw)}set nodes(e){this._adoptAll(e??[]),this._render(),this._loadOpenNodes()}get selection(){let e=this.getAttribute(`selection`);return c(e)?e:`none`}set selection(e){this.setAttribute(`selection`,String(e))}get selected(){return this._selected}set selected(e){this._selected=e==null?null:String(e),this._render()}get values(){let e=[],t=n=>{for(let r of n)this._state(r)===`checked`&&e.push(r.id),r.children&&t(r.children)};return t(this._roots),[...e,...[...this._checked].filter(e=>!this._byId.has(e))]}set values(e){this._checked.clear();for(let t of e??[]){let e=this._byId.get(String(t));e?this._setChecked(e,!0):this._checked.add(String(t))}this._render()}get loadChildren(){return this._loader}set loadChildren(e){this._loader=typeof e==`function`?e:null}get loadUrl(){return this.getAttribute(`load-url`)}set loadUrl(e){e==null?this.removeAttribute(`load-url`):this.setAttribute(`load-url`,String(e))}get name(){return this.getAttribute(`name`)}set name(e){e==null?this.removeAttribute(`name`):this.setAttribute(`name`,String(e))}get loadingText(){return this.getAttribute(`loading-text`)??u}set loadingText(e){this.setAttribute(`loading-text`,String(e??``))}get errorText(){return this.getAttribute(`error-text`)??d}set errorText(e){this.setAttribute(`error-text`,String(e??``))}_readScript(){let t=this.querySelector(`:scope > script[type='application/json']`);if(!t)return null;try{return JSON.parse(t.textContent??``)}catch(t){return e(`[@webority/ui-elements] <wui-tree> could not read its JSON nodes:`,t instanceof Error?t.message:void 0),null}}_adoptAll(e){let t=this._byId;this._prev=t,this._byId=/* @__PURE__ */ new Map;let n;try{n=this._adoptStaged(e,null,1)}catch(e){throw this._byId=t,e}finally{this._prev=null}this._roots=n;for(let e of t.keys())this._byId.has(e)||this._checked.delete(e);for(let e of this._roots)this._passChecksDown(e);this._focusId&&!this._byId.has(this._focusId)&&(this._focusId=null)}_adoptStaged(e,t,n){let r=[],i=[];this._staged={ids:r,checks:i};try{let r=this._adopt(e,t,n);for(let e of i)this._checked.add(e);return r}catch(e){for(let e of r)this._byId.delete(e);throw e}finally{this._staged=null}}_adopt(e,t,n){if(!Array.isArray(e))throw Error(`<wui-tree> nodes must be an array.`);return e.map(e=>{let r=e?.id==null?``:String(e.id);if(!r)throw Error(`<wui-tree> every node needs an id.`);if(this._byId.has(r))throw Error(`<wui-tree> node id "${r}" is used twice.`);let i=this._prev?.get(r),a={id:r,raw:e,parent:t,level:n,seq:++this._seq,label:e.label==null?r:String(e.label),icon:e.icon||null,badge:e.badge==null||e.badge===``?null:String(e.badge),badgeTone:e.badgeTone||null,disabled:!!e.disabled,hasChildren:!!e.hasChildren,children:null,expanded:i?i.expanded:!!e.expanded,loading:!1,failed:!1};this._byId.set(r,a),this._staged?.ids.push(r);let o=e.children??(e.hasChildren?i?.children?.map(e=>e.raw):void 0);return Array.isArray(o)&&(a.children=this._adopt(o,a,n+1)),a.loading=!!i?.loading&&a.children===null&&a.hasChildren,e.checked&&!i&&this._staged?.checks.push(r),a})}_passChecksDown(e){e.children?.length&&this._checked.has(e.id)&&(this._checked.delete(e.id),this._setChecked(e,!0));for(let t of e.children??[])this._passChecksDown(t)}_loadOpenNodes(){queueMicrotask(()=>{if(this.isConnected)for(let e of[...this._byId.values()])e.expanded&&e.children===null&&e.hasChildren&&!e.loading&&this._load(e)})}_isBranch(e){return e.children?e.children.length>0:e.hasChildren}_visible(){let e=[],t=n=>{for(let r of n)e.push(r),r.expanded&&r.children&&t(r.children)};return t(this._roots),e}_state(e){if(e.children?.length){let t=0,n=0;for(let r of e.children){let e=this._state(r);e===`checked`?t++:e===`unchecked`&&n++}return t===e.children.length?`checked`:n===e.children.length?`unchecked`:`mixed`}return this._checked.has(e.id)?`checked`:`unchecked`}_setChecked(e,t){if(e.children?.length)for(let n of e.children)n.disabled||this._setChecked(n,t);else t?this._checked.add(e.id):this._checked.delete(e.id)}_nodeFrom(e){if(!(e instanceof Element))return null;let t=e.closest(`li.wui-tree-item`);if(!t)return null;for(let[e,n]of this._els)if(n.li===t)return this._byId.get(e)??null;return null}_emit(e,t){this.dispatchEvent(new CustomEvent(`wui-tree:${e}`,{detail:t,bubbles:!0,composed:!0}))}_announce(e){this._live&&(this._live.textContent=e)}_setRoving(e){let t=this._focusId===null?void 0:this._els.get(this._focusId);t&&(t.li.tabIndex=-1),this._focusId=e.id;let n=this._els.get(e.id);n&&(n.li.tabIndex=0)}_focusNode(e){e&&(this._setRoving(e),this._els.get(e.id)?.li.focus())}_activate(e){e.disabled||(this.selection===`single`&&(this._selected=e.id,this._render(),this._syncForm()),this._emit(`select`,{id:e.id,node:e.raw}))}_enabledLeaves(e){return e.disabled?[]:e.children?.length?e.children.flatMap(e=>this._enabledLeaves(e)):[e]}_toggleCheck(e){let t=this._enabledLeaves(e);if(!t.length)return;let n=!t.every(e=>this._checked.has(e.id));this._setChecked(e,n),this._render(),this._syncForm(),this._emit(`check`,{id:e.id,checked:n,values:this.values})}_toggleExpand(e){!e.disabled&&this._isBranch(e)&&(e.expanded?(e.expanded=!1,this._render()):this._expand(e))}_expand(e){e.expanded=!0,e.children===null?this._load(e):this._render()}async _load(e){if(e.loading)return;e.loading=!0,e.failed=!1,this._announce(this.loadingText),this._render();let t=[],n=null;try{t=await this._fetchChildren(e)}catch(e){n=e}let r=this._byId.get(e.id);if(!r)this._announce(``);else if(r.loading){if(r.loading=!1,!n)try{r.children=this._adoptStaged(t,r,r.level+1),this._passChecksDown(r),this._announce(``)}catch(e){n=e}n&&(r.failed=!0,r.expanded=!1,this._announce(this.errorText),this._emit(`error`,{id:r.id,message:n instanceof Error?n.message:String(n)})),this._render(),this._syncForm()}}async _fetchChildren(e){if(this._loader)return this._loader(e.raw);let t=this.getAttribute(`load-url`);if(!t)throw Error(`<wui-tree> has a node with children to load but no loadChildren or load-url.`);let n=new URL(t,window.location.href);n.searchParams.set(l,e.id);let r=await o(n.href,{headers:{Accept:`application/json`}});if(!r.ok)throw Error(`Loading children answered ${r.kind}.`);return JSON.parse(r.html)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=this._nodeFrom(t);n&&!n.disabled&&(this._focusNode(n),t.closest(`.wui-tree-toggle`)?this._toggleExpand(n):t.closest(`.wui-tree-check`)?(e.preventDefault(),this._toggleCheck(n)):this._activate(n))}_handleKeyDown(e){if(e.ctrlKey||e.metaKey||e.altKey)return;let t=this._nodeFrom(e.target);if(t&&e.target===this._els.get(t.id)?.li){if(e.key===`ArrowRight`){if(e.preventDefault(),!this._isBranch(t)||t.disabled)return;t.expanded?t.children?.length&&this._focusNode(t.children[0]):this._expand(t)}else e.key===`ArrowLeft`?(e.preventDefault(),t.expanded&&this._isBranch(t)&&!t.disabled?this._toggleExpand(t):t.parent&&this._focusNode(t.parent)):e.key===` `?(e.preventDefault(),this.selection===`multiple`?this._toggleCheck(t):this.selection===`single`&&this._activate(t)):this._nav.handler(e)}}_syncForm(){let e=this.selection;if(e===`multiple`)n(this,this.values);else if(e===`single`)r(this,this._selected??``);else for(let e of this.querySelectorAll(f))e.remove()}_render(){if(!this._list)return;let e=document.activeElement,t=!!e&&this._list.contains(e),n=this._visible();n.some(e=>e.id===this._focusId)||(this._focusId=(n.find(e=>e.id===this._selected)??n[0])?.id??null),this._els=/* @__PURE__ */ new Map;let r=this.getAttribute(`aria-label`);r?this._list.setAttribute(`aria-label`,r):this._list.removeAttribute(`aria-label`),this._list.replaceChildren(...this._buildLevel(this._roots)),t&&this._focusId&&this._els.get(this._focusId)?.li.focus(),this._syncForm()}_buildLevel(e){return e.map((t,n)=>this._buildItem(t,n+1,e.length))}_buildItem(e,t,n){let r=this.selection,a=this._isBranch(e),o=this._state(e),s=h(`li`,`wui-tree-item`,{role:`treeitem`,tabindex:e.id===this._focusId?0:-1,"aria-level":e.level,"aria-setsize":n,"aria-posinset":t,"aria-labelledby":`${this._uid}-${e.seq}`,"aria-describedby":e.badge?`${this._uid}-${e.seq}-badge`:null});a&&s.setAttribute(`aria-expanded`,String(e.expanded)),e.disabled&&s.setAttribute(`aria-disabled`,`true`),e.loading&&s.setAttribute(`aria-busy`,`true`),r===`single`&&s.setAttribute(`aria-selected`,String(e.id===this._selected)),r===`multiple`&&s.setAttribute(`aria-checked`,o===`mixed`?`mixed`:String(o===`checked`));let c=h(`div`,`wui-tree-row`,{role:`presentation`});c.style.setProperty(`--wui-tree-level`,String(e.level-1)),r===`single`&&e.id===this._selected&&c.classList.add(`wui-tree-row-selected`),e.failed&&c.classList.add(`wui-tree-row-error`);let l=h(`span`,a?`wui-tree-toggle`:`wui-tree-toggle wui-tree-toggle-leaf`,{"aria-hidden":`true`});if(a&&(l.innerHTML=i(`chevron-right`,{size:16})),c.append(l),r===`multiple`){let t=h(`input`,`form-check-input wui-tree-check`,{type:`checkbox`,tabindex:-1,"aria-hidden":`true`});t.checked=o===`checked`,t.indeterminate=o===`mixed`,t.disabled=e.disabled,t.addEventListener(`mousedown`,e=>e.preventDefault()),c.append(t)}if(e.icon){let t=h(`span`,`wui-tree-icon`,{"aria-hidden":`true`});t.innerHTML=i(e.icon,{size:16}),c.append(t)}let u=h(`span`,`wui-tree-label`,{id:`${this._uid}-${e.seq}`});if(u.textContent=e.label,c.append(u),e.badge){let t=h(`span`,`badge wui-tree-badge${e.badgeTone&&e.badgeTone!==`neutral`?` badge-${e.badgeTone}`:``}`,{id:`${this._uid}-${e.seq}-badge`});t.textContent=e.badge,c.append(t)}if(e.loading&&c.append(h(`span`,`wui-tree-spinner`,{"aria-hidden":`true`})),s.append(c),e.expanded&&e.children?.length){let t=h(`ul`,`wui-tree-group`,{role:`group`});t.append(...this._buildLevel(e.children)),s.append(t)}return this._els.set(e.id,{li:s,row:c}),s}};export{g as t};
|
|
1
|
+
import{t as e}from"./devWarn-DXdRWZs3.js";import{t}from"./elementBase-Cxeyx0tU.js";import{n,t as r}from"./formMirror-9IpSgeZb.js";import{t as i}from"./iconGlyphs.g-DPqoOoXy.js";import{t as a}from"./listboxKeyNav-Bxkq7dvu.js";import{l as o}from"./wuiHttp-DGbD7Fra.js";var s=[`none`,`single`,`multiple`],c=e=>s.some(t=>t===e),l=`parentId`,u=`Loading`,d=`Could not load. Try again.`,f=`:scope > input[data-wui-mirror]`,p=[`nodes`,`selection`,`selected`,`values`,`loadChildren`,`loadUrl`,`name`],m=0;function h(e,t,n){let r=document.createElement(e);t&&(r.className=t);for(let[e,t]of Object.entries(n??{}))t!=null&&r.setAttribute(e,String(t));return r}var g=class extends t{_uid;_seq;_roots;_byId;_prev;_staged;_els;_checked;_selected;_focusId;_loader;_list;_live;_ready;_nav;_onKeyDown;_onClick;_onFocusIn;static get observedAttributes(){return[`selection`,`selected`,`name`,`aria-label`,`loading-text`,`error-text`]}constructor(){super(),this._uid=`wui-tree-${++m}`,this._seq=0,this._roots=[],this._byId=/* @__PURE__ */ new Map,this._prev=null,this._staged=null,this._els=/* @__PURE__ */ new Map,this._checked=/* @__PURE__ */ new Set,this._selected=null,this._focusId=null,this._loader=null,this._list=null,this._live=null,this._ready=!1,this._nav=a({getVisibleOptions:()=>this._visible().map(e=>{let t=this._els.get(e.id)?.row;if(!t)throw Error(`Row for node "${e.id}" is not rendered.`);return t}),getActive:()=>this._visible().findIndex(e=>e.id===this._focusId),setActive:e=>this._focusNode(this._visible()[e]),onEnter:()=>{let e=this._focusId===null?void 0:this._byId.get(this._focusId);e&&this._activate(e)}}),this._onKeyDown=e=>this._handleKeyDown(e),this._onClick=e=>this._handleClick(e),this._onFocusIn=e=>{let t=this._nodeFrom(e.target);t&&t.id!==this._focusId&&this._setRoving(t)}}connectedCallback(){let e=/* @__PURE__ */ new Map;for(let t of p)Object.hasOwn(this,t)&&(e.set(t,Reflect.get(this,t)),Reflect.deleteProperty(this,t));if(!this._ready){this._ready=!0;let e=this._readScript();this.replaceChildren(),this._list=h(`ul`,`wui-tree`),this._list.setAttribute(`role`,`tree`),this._live=h(`div`,`visually-hidden`,{role:`status`,"aria-live":`polite`}),this.append(this._list,this._live),e&&this._adoptAll(e)}for(let[t,n]of e)Reflect.set(this,t,n);this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`click`,this._onClick),this.addEventListener(`focusin`,this._onFocusIn),this._render(),this._loadOpenNodes()}disconnectedCallback(){this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`focusin`,this._onFocusIn),this._nav.teardown()}attributeChangedCallback(e,t,n){e===`selected`&&(this._selected=n),this._ready&&this.isConnected&&this._render()}get nodes(){return this._roots.map(e=>e.raw)}set nodes(e){this._adoptAll(e??[]),this._render(),this._loadOpenNodes()}get selection(){let e=this.getAttribute(`selection`);return c(e)?e:`none`}set selection(e){this.setAttribute(`selection`,String(e))}get selected(){return this._selected}set selected(e){this._selected=e==null?null:String(e),this._render()}get values(){let e=[],t=n=>{for(let r of n)this._state(r)===`checked`&&e.push(r.id),r.children&&t(r.children)};return t(this._roots),[...e,...[...this._checked].filter(e=>!this._byId.has(e))]}set values(e){this._checked.clear();for(let t of e??[]){let e=this._byId.get(String(t));e?this._setChecked(e,!0):this._checked.add(String(t))}this._render()}get loadChildren(){return this._loader}set loadChildren(e){this._loader=typeof e==`function`?e:null}get loadUrl(){return this.getAttribute(`load-url`)}set loadUrl(e){e==null?this.removeAttribute(`load-url`):this.setAttribute(`load-url`,String(e))}get name(){return this.getAttribute(`name`)}set name(e){e==null?this.removeAttribute(`name`):this.setAttribute(`name`,String(e))}get loadingText(){return this.getAttribute(`loading-text`)??u}set loadingText(e){this.setAttribute(`loading-text`,String(e??``))}get errorText(){return this.getAttribute(`error-text`)??d}set errorText(e){this.setAttribute(`error-text`,String(e??``))}_readScript(){let t=this.querySelector(`:scope > script[type='application/json']`);if(!t)return null;try{return JSON.parse(t.textContent??``)}catch(t){return e(`[@webority/ui-elements] <wui-tree> could not read its JSON nodes:`,t instanceof Error?t.message:void 0),null}}_adoptAll(e){let t=this._byId;this._prev=t,this._byId=/* @__PURE__ */ new Map;let n;try{n=this._adoptStaged(e,null,1)}catch(e){throw this._byId=t,e}finally{this._prev=null}this._roots=n;for(let e of t.keys())this._byId.has(e)||this._checked.delete(e);for(let e of this._roots)this._passChecksDown(e);this._focusId&&!this._byId.has(this._focusId)&&(this._focusId=null)}_adoptStaged(e,t,n){let r=[],i=[];this._staged={ids:r,checks:i};try{let r=this._adopt(e,t,n);for(let e of i)this._checked.add(e);return r}catch(e){for(let e of r)this._byId.delete(e);throw e}finally{this._staged=null}}_adopt(e,t,n){if(!Array.isArray(e))throw Error(`<wui-tree> nodes must be an array.`);return e.map(e=>{let r=e?.id==null?``:String(e.id);if(!r)throw Error(`<wui-tree> every node needs an id.`);if(this._byId.has(r))throw Error(`<wui-tree> node id "${r}" is used twice.`);let i=this._prev?.get(r),a={id:r,raw:e,parent:t,level:n,seq:++this._seq,label:e.label==null?r:String(e.label),icon:e.icon||null,badge:e.badge==null||e.badge===``?null:String(e.badge),badgeTone:e.badgeTone||null,disabled:!!e.disabled,hasChildren:!!e.hasChildren,children:null,expanded:i?i.expanded:!!e.expanded,loading:!1,failed:!1};this._byId.set(r,a),this._staged?.ids.push(r);let o=e.children??(e.hasChildren?i?.children?.map(e=>e.raw):void 0);return Array.isArray(o)&&(a.children=this._adopt(o,a,n+1)),a.loading=!!i?.loading&&a.children===null&&a.hasChildren,e.checked&&!i&&this._staged?.checks.push(r),a})}_passChecksDown(e){e.children?.length&&this._checked.has(e.id)&&(this._checked.delete(e.id),this._setChecked(e,!0));for(let t of e.children??[])this._passChecksDown(t)}_loadOpenNodes(){queueMicrotask(()=>{if(this.isConnected)for(let e of[...this._byId.values()])e.expanded&&e.children===null&&e.hasChildren&&!e.loading&&this._load(e)})}_isBranch(e){return e.children?e.children.length>0:e.hasChildren}_visible(){let e=[],t=n=>{for(let r of n)e.push(r),r.expanded&&r.children&&t(r.children)};return t(this._roots),e}_state(e){if(e.children?.length){let t=0,n=0;for(let r of e.children){let e=this._state(r);e===`checked`?t++:e===`unchecked`&&n++}return t===e.children.length?`checked`:n===e.children.length?`unchecked`:`mixed`}return this._checked.has(e.id)?`checked`:`unchecked`}_setChecked(e,t){if(e.children?.length)for(let n of e.children)n.disabled||this._setChecked(n,t);else t?this._checked.add(e.id):this._checked.delete(e.id)}_nodeFrom(e){if(!(e instanceof Element))return null;let t=e.closest(`li.wui-tree-item`);if(!t)return null;for(let[e,n]of this._els)if(n.li===t)return this._byId.get(e)??null;return null}_emit(e,t){this.dispatchEvent(new CustomEvent(`wui-tree:${e}`,{detail:t,bubbles:!0,composed:!0}))}_announce(e){this._live&&(this._live.textContent=e)}_setRoving(e){let t=this._focusId===null?void 0:this._els.get(this._focusId);t&&(t.li.tabIndex=-1),this._focusId=e.id;let n=this._els.get(e.id);n&&(n.li.tabIndex=0)}_focusNode(e){e&&(this._setRoving(e),this._els.get(e.id)?.li.focus())}_activate(e){e.disabled||(this.selection===`single`&&(this._selected=e.id,this._render(),this._syncForm()),this._emit(`select`,{id:e.id,node:e.raw}))}_enabledLeaves(e){return e.disabled?[]:e.children?.length?e.children.flatMap(e=>this._enabledLeaves(e)):[e]}_toggleCheck(e){let t=this._enabledLeaves(e);if(!t.length)return;let n=!t.every(e=>this._checked.has(e.id));this._setChecked(e,n),this._render(),this._syncForm(),this._emit(`check`,{id:e.id,checked:n,values:this.values})}_toggleExpand(e){!e.disabled&&this._isBranch(e)&&(e.expanded?(e.expanded=!1,this._render()):this._expand(e))}_expand(e){e.expanded=!0,e.children===null?this._load(e):this._render()}async _load(e){if(e.loading)return;e.loading=!0,e.failed=!1,this._announce(this.loadingText),this._render();let t=[],n=null;try{t=await this._fetchChildren(e)}catch(e){n=e}let r=this._byId.get(e.id);if(!r)this._announce(``);else if(r.loading){if(r.loading=!1,!n)try{r.children=this._adoptStaged(t,r,r.level+1),this._passChecksDown(r),this._announce(``)}catch(e){n=e}n&&(r.failed=!0,r.expanded=!1,this._announce(this.errorText),this._emit(`error`,{id:r.id,message:n instanceof Error?n.message:String(n)})),this._render(),this._syncForm()}}async _fetchChildren(e){if(this._loader)return this._loader(e.raw);let t=this.getAttribute(`load-url`);if(!t)throw Error(`<wui-tree> has a node with children to load but no loadChildren or load-url.`);let n=new URL(t,window.location.href);n.searchParams.set(l,e.id);let r=await o(n.href,{headers:{Accept:`application/json`}});if(!r.ok)throw Error(`Loading children answered ${r.kind}.`);return JSON.parse(r.html)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=this._nodeFrom(t);n&&!n.disabled&&(this._focusNode(n),t.closest(`.wui-tree-toggle`)?this._toggleExpand(n):t.closest(`.wui-tree-check`)?(e.preventDefault(),this._toggleCheck(n)):this._activate(n))}_handleKeyDown(e){if(e.ctrlKey||e.metaKey||e.altKey)return;let t=this._nodeFrom(e.target);if(t&&e.target===this._els.get(t.id)?.li){if(e.key===`ArrowRight`){if(e.preventDefault(),!this._isBranch(t)||t.disabled)return;t.expanded?t.children?.length&&this._focusNode(t.children[0]):this._expand(t)}else e.key===`ArrowLeft`?(e.preventDefault(),t.expanded&&this._isBranch(t)&&!t.disabled?this._toggleExpand(t):t.parent&&this._focusNode(t.parent)):e.key===` `?(e.preventDefault(),this.selection===`multiple`?this._toggleCheck(t):this.selection===`single`&&this._activate(t)):this._nav.handler(e)}}_syncForm(){let e=this.selection;if(e===`multiple`)n(this,this.values);else if(e===`single`)r(this,this._selected??``);else for(let e of this.querySelectorAll(f))e.remove()}_render(){if(!this._list)return;let e=document.activeElement,t=!!e&&this._list.contains(e),n=this._visible();n.some(e=>e.id===this._focusId)||(this._focusId=(n.find(e=>e.id===this._selected)??n[0])?.id??null),this._els=/* @__PURE__ */ new Map;let r=this.getAttribute(`aria-label`);r?this._list.setAttribute(`aria-label`,r):this._list.removeAttribute(`aria-label`),this._list.replaceChildren(...this._buildLevel(this._roots)),t&&this._focusId&&this._els.get(this._focusId)?.li.focus(),this._syncForm()}_buildLevel(e){return e.map((t,n)=>this._buildItem(t,n+1,e.length))}_buildItem(e,t,n){let r=this.selection,a=this._isBranch(e),o=this._state(e),s=h(`li`,`wui-tree-item`,{role:`treeitem`,tabindex:e.id===this._focusId?0:-1,"aria-level":e.level,"aria-setsize":n,"aria-posinset":t,"aria-labelledby":`${this._uid}-${e.seq}`,"aria-describedby":e.badge?`${this._uid}-${e.seq}-badge`:null});a&&s.setAttribute(`aria-expanded`,String(e.expanded)),e.disabled&&s.setAttribute(`aria-disabled`,`true`),e.loading&&s.setAttribute(`aria-busy`,`true`),r===`single`&&s.setAttribute(`aria-selected`,String(e.id===this._selected)),r===`multiple`&&s.setAttribute(`aria-checked`,o===`mixed`?`mixed`:String(o===`checked`));let c=h(`div`,`wui-tree-row`,{role:`presentation`});c.style.setProperty(`--wui-tree-level`,String(e.level-1)),r===`single`&&e.id===this._selected&&c.classList.add(`wui-tree-row-selected`),e.failed&&c.classList.add(`wui-tree-row-error`);let l=h(`span`,a?`wui-tree-toggle`:`wui-tree-toggle wui-tree-toggle-leaf`,{"aria-hidden":`true`});if(a&&(l.innerHTML=i(`chevron-right`,{size:16})),c.append(l),r===`multiple`){let t=h(`input`,`form-check-input wui-tree-check`,{type:`checkbox`,tabindex:-1,"aria-hidden":`true`});t.checked=o===`checked`,t.indeterminate=o===`mixed`,t.disabled=e.disabled,t.addEventListener(`mousedown`,e=>e.preventDefault()),c.append(t)}if(e.icon){let t=h(`span`,`wui-tree-icon`,{"aria-hidden":`true`});t.innerHTML=i(e.icon,{size:16}),c.append(t)}let u=h(`span`,`wui-tree-label`,{id:`${this._uid}-${e.seq}`});if(u.textContent=e.label,c.append(u),e.badge){let t=h(`span`,`badge wui-tree-badge${e.badgeTone&&e.badgeTone!==`neutral`?` badge-${e.badgeTone}`:``}`,{id:`${this._uid}-${e.seq}-badge`});t.textContent=e.badge,c.append(t)}if(e.loading&&c.append(h(`span`,`wui-tree-spinner`,{"aria-hidden":`true`})),s.append(c),e.expanded&&e.children?.length){let t=h(`ul`,`wui-tree-group`,{role:`group`});t.append(...this._buildLevel(e.children)),s.append(t)}return this._els.set(e.id,{li:s,row:c}),s}};export{g as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{n as e,t}from"./fieldState-D-zQcXUS.js";import{t as n}from"./iconGlyphs.g-DPqoOoXy.js";import{a as r,i,n as a,r as o}from"./optionLabel-4xjXWy74.js";import{t as s}from"./customRule-Chp7YwFb.js";import{r as c}from"./WuiSelect-CWul-aM1.js";var l={enter:`Enter`,comma:`,`,space:` `,tab:`Tab`},u={enter:`
|
|
2
|
+
`,comma:`,`,space:` `,tab:` `},d=e=>l[e],ee=e=>u[e];function te(e,t){let n=[String(e??``)];for(let e of t)n=n.flatMap(t=>t.split(e));return n.map(e=>e.trim()).filter(Boolean)}var ne=(e,t)=>t.some(t=>String(e??``).includes(t));function f(e,t){if(e===null)throw TypeError(`The chip row needs ${t}, and it is not mounted.`);return e}var p=(e,t)=>{let n=document.createElement(e);return n.className=t,n};function m(){let l,u,m=null,h=null,g=null,_=null,v=null,y=null,b=null,x=null,S=!1,C=()=>f(h,`the draft input`),w=()=>l.mode===`tag`,T=()=>Array.isArray(l.value)?l.value.slice():[],E=()=>(l.getAttribute(`separators`)||`enter,comma`).split(`,`).map(e=>e.trim()).filter(Boolean),re=()=>new Set(E().map(d).filter(Boolean)),D=()=>{let e=parseInt(l.getAttribute(`max-tags`)??``,10)||0;return Math.max(e,0)},O=()=>{let e=D();return e>0&&T().length>=e},k=(e,t)=>!l.hasAttribute(`allow-duplicates`)&&e.some(e=>e.toLowerCase()===t.toLowerCase()),A=e=>(l.options||[]).find(t=>String(t.value)===String(e)),j=e=>{let t=e.trim().toLowerCase();return(l.options||[]).find(e=>String(e.value??``).toLowerCase()===t||i(e).trim().toLowerCase()===t)},ie=e=>{for(let t of E()){let n=ee(t)??t;if(ne(e,[n]))return te(e,[n])}return[e.trim()]},M=()=>h?h.value:l._query||``,ae=()=>w()||l.hasAttribute(`allow-custom`),N=()=>l.getAttribute(`placeholder`)||(w()?`Add…`:`Select…`),P=()=>{let e=l.getAttribute(`aria-label`);if(e)return e;let t=l.closest(`label`)?.textContent?.trim();if(t)return t;let n=l.id;return(n?[...document.querySelectorAll(`label[for]`)].find(e=>e instanceof HTMLLabelElement&&e.htmlFor===n):void 0)?.textContent?.trim()||(w()?`Add tags`:`Select`)},F=()=>{h&&(h.setAttribute(`aria-expanded`,String(!u.menu.hidden)),u.list.id&&h.setAttribute(`aria-controls`,u.list.id),h.setAttribute(`aria-label`,P()))},oe=()=>!e(l)&&!l.hasAttribute(`loading`),se=e=>{S=!0,C().setAttribute(`aria-invalid`,`true`),l.setError(e)},I=()=>{S&&(S=!1,C().removeAttribute(`aria-invalid`),l.setError(null))},L=(e,{quiet:t=!1,strip:n=!1}={})=>{let r=T(),i=r.slice(),a=D(),o=[],c=``,u=!1;for(let t of e){let e=(n?t.trim().replace(/,+$/,``):t).trim();if(!e)continue;if(a&&i.length>=a)break;let r=j(e);if(r){if(r.disabled){o.push(e),c||=r.disabledHint||l.getAttribute(`invalid-message`)||`That option is not available.`;continue}k(i,String(r.value))||i.push(String(r.value));continue}let d=s(l,e);d?(o.push(e),c||=d):k(i,e)||(i.push(e),u=!0)}i.length!==r.length&&(u?l.commit(i,{isCustom:!0}):l.commit(i)),C().value=o.join(`, `),c?t||se(c):I()},R=e=>{t(l)||L([C().value],e)},z=e=>l.commit(T().filter(t=>t!==e)),ce=()=>{let e=p(`span`,`wui-select-placeholder`);return e.textContent=l.getAttribute(`placeholder`)||`Select…`,e},B=e=>{let t=A(e),s=p(`span`,`chip chip-sm`),c=p(`span`,`chip-label`);if(c.innerHTML=t?o(t):a(e),s.append(c),oe()){let a=p(`button`,`chip-remove`);a.type=`button`,a.dataset.remove=e;let o=t?i(t):r(e);a.setAttribute(`aria-label`,`Remove ${o}`),a.innerHTML=n(`x`),s.append(a)}return s};function V(){if(!m)return;m.querySelector(`:scope > .chip-more`)?.remove();let e=[...m.querySelectorAll(`:scope > .chip`)].map(e=>{if(!(e instanceof HTMLElement))throw Error(`The chip row holds a node that is not an element.`);return e});for(let t of e)t.style.display=``;let t=e.at(-1);if(!l.hasAttribute(`collapse-chips`)||!t)return;let n=m.clientWidth,r=e=>e.offsetLeft+e.offsetWidth;if(r(t)<=n)return;let i=p(`span`,`chip chip-sm chip-more`);i.textContent=`+${e.length}`,t.after(i);let a=i.offsetWidth+6,o=0;for(let t of e)if(r(t)<=n-a)o+=1;else break;o<1&&(o=1);for(let t of e.slice(o))t.style.display=`none`;i.textContent=`+${e.length-o}`}function H(){if(!m)return!1;m.parentNode!==u.value&&u.value.append(m);for(let e of m.querySelectorAll(`:scope > .chip, :scope > .wui-select-placeholder`))e.remove();let e=T(),n=m,r=e=>{h?n.insertBefore(e,h):n.append(e)};w()||h||e.length||r(ce());for(let t of e)r(B(t));return h&&(h.placeholder=w()||!e.length?N():``,h.disabled=l.hasAttribute(`disabled`),h.readOnly=t(l),F()),w()||(f(_,`the footer text`).textContent=(l.getAttribute(`selected-text`)||`{n} selected`).replace(`{n}`,()=>String(e.length)),f(v,`the clear-all button`).textContent=l.getAttribute(`clear-all-label`)||`Clear all`),V(),!0}function U(e){if(e.key===`Backspace`){let t=h?!M():!M()&&!u.menu.hidden,n=T().at(-1);return!t||n===void 0?!1:(e.preventDefault(),z(n),!0)}if(!h)return!1;let t=h.value;if(e.key===`Escape`){if(!w())return!1;let n=!u.menu.hidden;return!n&&!t?!1:(n&&(e.preventDefault(),e.stopPropagation()),h.value=``,I(),l.closeMenu({focusControl:!1}),!0)}let n=!w()&&!t.trim(),r=re();return e.key===`Enter`&&r.has(`Enter`)?n||u.list.querySelector(`.is-active`)?!1:(e.preventDefault(),R(),!0):e.key===`,`&&r.has(`,`)?!n&&(e.preventDefault(),R({strip:!0}),!0):e.key===` `&&r.has(` `)&&t.trim()||e.key===`Tab`&&r.has(`Tab`)&&!n?(e.preventDefault(),R(),!0):!1}function W(e){let t=String(e.value);if(w()||h&&!A(t))return L([t]),!0;let n=T();return n.includes(t)?l.commit(n.filter(e=>e!==t)):h?L([t]):l.commit([...n,t]),h?.value&&(h.value=``,I()),!0}function G(e){if(!h)return null;let t=String(e??``).trim().replace(/,+$/,``).trim();if(!t||O()||j(t)||k(T(),t))return null;let n=l.getAttribute(`create-label`)||`Create '{text}'`;return{position:w()?`top`:`bottom`,label:n.replace(`{text}`,()=>t),value:t}}function K(e){let n=e.target,r=n instanceof Element?n.closest(`[data-remove]`):null;if(r instanceof HTMLElement){if(t(l))return;e.stopPropagation(),z(r.dataset.remove??``),h?.focus()}else h&&!t(l)&&h.focus()}function q(){I();let e=C().value.trim();!w()&&e&&u.menu.hidden&&(G(e)||c(l.options||[],e).length)&&l.openMenu()}function J(e){e.preventDefault(),t(l)||L(ie(e.clipboardData?.getData(`text/plain`)??``))}function Y(){C().value.trim()&&R({quiet:!0,strip:!0}),l.closeMenu({focusControl:!1})}function X(e){e.relatedTarget instanceof Node&&l.contains(e.relatedTarget)||Y()}function le(){return h?(Y(),!0):!1}function Z(){C().value.trim()&&R({strip:!0})}function Q(){t(l)||l.commit([])}function $(e){e.target!==h&&e.preventDefault()}function ue(e,t,n={}){l=e,u=t,m=p(`div`,`wui-select-chips`),m.addEventListener(`click`,K),u.value.append(m),ae()&&(h=p(`input`,`wui-select-draft`),h.type=`text`,h.setAttribute(`autocomplete`,`off`),h.setAttribute(`role`,`combobox`),h.setAttribute(`aria-autocomplete`,`list`),l.hasAttribute(`required`)&&h.setAttribute(`aria-required`,`true`),x=new MutationObserver(F),x.observe(u.menu,{attributes:!0,attributeFilter:[`hidden`]}),m.append(h),h.value=n.carry?.draft??``,u.input=h,h.addEventListener(`input`,q),h.addEventListener(`paste`,J),h.addEventListener(`blur`,X),m.addEventListener(`mousedown`,$),y=l.closest(`form`),y?.addEventListener(`submit`,Z,!0)),w()||(g=p(`div`,`wui-select-footer`),_=document.createElement(`span`),v=p(`button`,`wui-select-clear-all`),v.type=`button`,v.addEventListener(`click`,Q),g.append(_,v),u.menu.append(g)),typeof ResizeObserver<`u`&&(b=new ResizeObserver(V),b.observe(m)),H()}function de(){m?.removeEventListener(`click`,K),m?.removeEventListener(`mousedown`,$),h&&(h.removeEventListener(`input`,q),h.removeEventListener(`paste`,J),h.removeEventListener(`blur`,X),u.input=null),v&&v.removeEventListener(`click`,Q),y?.removeEventListener(`submit`,Z,!0),y=null,b?.disconnect(),b=null,x?.disconnect(),x=null,g?.remove(),m?.remove(),m=null,h=null,g=null,S=!1}return{mount:ue,onKey:U,onPick:W,renderValue:H,actionRow:G,onQuery:()=>!1,onBlur:le,teardown:de}}export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiCarousel-
|
|
1
|
+
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiCarousel-BdhJLo1m.js";e(`wui-carousel`,t);export{t as WuiCarousel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"../commentText-BnX7rA2-.js";import{n as r}from"../elementBase-Cxeyx0tU.js";import{t as i}from"../WuiCommentThread-
|
|
1
|
+
import{n as e,r as t,t as n}from"../commentText-BnX7rA2-.js";import{n as r}from"../elementBase-Cxeyx0tU.js";import{t as i}from"../WuiCommentThread-CnwvJUDn.js";import"./mention-input.js";r(`wui-comment-thread`,i);export{n as COMMENT_INTENTS,e as COMMENT_REACTIONS,t as COMMENT_TEXT,i as WuiCommentThread};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiContextMenu-
|
|
1
|
+
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiContextMenu-Re2CG8yT.js";e(`wui-context-menu`,t);export{t as WuiContextMenu};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../elementBase-Cxeyx0tU.js";import{i as t,n,r,t as i}from"../mentionText-BJsw_opZ.js";import{i as a,n as o,r as s,t as c}from"../WuiMentionInput-
|
|
1
|
+
import{n as e}from"../elementBase-Cxeyx0tU.js";import{i as t,n,r,t as i}from"../mentionText-BJsw_opZ.js";import{i as a,n as o,r as s,t as c}from"../WuiMentionInput-HwsLGhyr.js";e(`wui-mention-input`,a);export{i as MENTION_ID_PATTERN,c as MENTION_MAX_QUERY,o as MENTION_MAX_RESULTS,s as MENTION_TEXT,a as WuiMentionInput,n as mentionLabel,r as mentionTextFromValue,t as mentionValueFromText};
|
package/dist/elements/phone.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiPhone-
|
|
1
|
+
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiPhone-NdIYg_Gb.js";e(`wui-phone`,t);export{t as WuiPhone};
|
package/dist/elements/select.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiSelect-
|
|
1
|
+
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiSelect-CWul-aM1.js";e(`wui-select`,t);export{t as WuiSelect};
|
package/dist/elements/tree.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiTree-
|
|
1
|
+
import{n as e}from"../elementBase-Cxeyx0tU.js";import{t}from"../WuiTree-JK4JqcBr.js";e(`wui-tree`,t);export{t as WuiTree};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=e=>e.target instanceof Element?e.target.tagName:void 0;function t(t){let{getVisibleOptions:n,getActive:r,setActive:i,onEnter:a,onEscape:o,onTypeahead:s,typeaheadMs:c=500}=t,l=``,u=null,d=()=>{clearTimeout(u??void 0),u=null,l=``};return{handler:t=>{let f=n(),p=r(),m=e(t)===`INPUT`||e(t)===`TEXTAREA`;if(t.key===`ArrowDown`)t.preventDefault(),i(Math.min(p+1,f.length-1));else if(t.key===`ArrowUp`)t.preventDefault(),i(Math.max(p-1,0));else if(t.key===`Home`&&!m)t.preventDefault(),f.length&&i(0);else if(t.key===`End`&&!m)t.preventDefault(),f.length&&i(f.length-1);else if(t.key===`PageDown`&&!m){if(t.preventDefault(),!f.length)return;i(Math.min(Math.max(0,p)+8,f.length-1))}else if(t.key===`PageUp`&&!m){if(t.preventDefault(),!f.length)return;i(Math.max(Math.max(0,p)-8,0))}else if(t.key===`Enter`)a&&(t.preventDefault(),a(f[p],f));else if(t.key===`Escape`)o&&o();else if(t.key.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&e(t)!==`INPUT`&&e(t)!==`TEXTAREA`){t.preventDefault(),clearTimeout(u??void 0),l+=t.key.toLowerCase(),u=setTimeout(d,c);let e=f.findIndex(e=>e.textContent.trim().toLowerCase().startsWith(l));e>=0&&(i(e),s&&s(t.key,e,f))}},clearTypeahead:d,teardown:d}}function n(e,t){let n=e.querySelector(`.is-active`);n!==t&&(n?.classList.remove(`is-active`),t?.classList.add(`is-active`))}export{n,t};
|