@webority/ui-elements 0.152.0 → 0.154.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/{WuiCodeBlock-DHpmEskS.js → WuiCodeBlock-cLLbSBK4.js} +1 -1
- package/dist/{WuiCommandPalette-DqHh4lH6.js → WuiCommandPalette-Dpz0DXKJ.js} +1 -1
- package/dist/{WuiDataTable-B4BYCd_s.js → WuiDataTable-8nQDiTHE.js} +1 -1
- package/dist/{WuiLeadPopup-YN4YCbOe.js → WuiLeadPopup-BmZG0Fk_.js} +1 -1
- package/dist/{WuiOnboardingChecklist-Cx-TgpBY.js → WuiOnboardingChecklist-C-nllg2h.js} +1 -1
- package/dist/{WuiResizable-DQZdQVCz.js → WuiResizable-KvfLtbCw.js} +1 -1
- package/dist/{WuiSavedViews-UaiP6YNG.js → WuiSavedViews-Br9YKOVU.js} +1 -1
- package/dist/{WuiSelect-DBPre2oe.js → WuiSelect-BPWPI07i.js} +1 -1
- package/dist/{chips-Dony2fgq.js → chips-Dr_W3avk.js} +1 -1
- package/dist/copyText-Q-QZKBmx.js +1 -0
- package/dist/dataTable-CcH1lBIM.js +1 -0
- package/dist/{drawerDiscard-C0yRSl1I.js → drawerDiscard-Cra-QhD5.js} +1 -1
- package/dist/elements/code-block.js +1 -1
- package/dist/elements/command-palette.js +1 -1
- package/dist/elements/data-table.js +1 -1
- package/dist/elements/filter-popover.js +1 -1
- package/dist/elements/kanban.js +1 -1
- package/dist/elements/lead-popup.js +1 -1
- package/dist/elements/onboarding-checklist.js +1 -1
- package/dist/elements/resizable.js +1 -1
- package/dist/elements/saved-views.js +1 -1
- package/dist/elements/select.js +1 -1
- package/dist/filterPopover-CaHWe9V0.js +1 -0
- package/dist/helpers.js +1 -1
- package/dist/{kanban-Dz8m-17x.js → kanban-CDaks135.js} +1 -1
- package/dist/{kanbanModel-C2IOPJ8L.js → kanbanModel-BaT75e-b.js} +1 -1
- package/dist/recents-Dcw-b5cB.js +1 -0
- package/dist/{search-C8xIzt6h.js → search-PZCXpBAn.js} +1 -1
- package/dist/server.js +1 -1
- package/dist/{themeTransition-9LQC6fx8.js → themeTransition-CfrJtERx.js} +1 -1
- 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 +2 -2
- 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 +2 -2
- 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 +1 -1
- 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/dist/ui-file-viewer.global.js +1 -1
- package/dist/ui-file-viewer.js +1 -1
- package/dist/ui-lead-popup.global.js +1 -1
- package/package.json +4 -4
- package/types/copyText.d.ts +1 -1
- package/types/themeTransition.d.ts +1 -1
- package/dist/copyText-DM5HhXjf.js +0 -1
- package/dist/dataTable-B-7oAeii.js +0 -1
- package/dist/filterPopover-D8BOb-Hz.js +0 -1
- package/dist/recents-CmLLdV8O.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./devWarn-DXdRWZs3.js";import{t as n}from"./elementBase-Cxeyx0tU.js";import{m as r}from"./formatters-ljfITOZ3.js";import{c as i,d as a,f as o,h as s,l as c,m as l,o as u,p as d}from"./kanbanModel-C2IOPJ8L.js";import{l as f}from"./wuiHttp-DGbD7Fra.js";var p=u.failed,m=`[data-wui-column]`,h=`[data-wui-body]`,g=`[data-wui-card]`,_=`[data-wui-count]`,v=`[data-wui-summary]`,y=`[data-wui-empty]`,b=`[data-wui-drop-note]`,x=`[data-wui-live]`,S=`[data-wui-help]`,C=`[data-wui-switch]`,w=`[data-wui-scroller]`,T=`[data-wui-collapse]`,E=`[data-wui-more]`,D=`data-wui-visible-limit`,O=`data-wui-overflow`,k=`input, select, textarea, [contenteditable=""], [contenteditable="true"], [data-wui-no-drag]`,A=`[data-wui-load-more]`,j=`data-wui-more-url`,M=`data-wui-total`,N=`data-wui-unloaded`,P=48,F=16,I=160,L=e=>e.getAttribute(`data-wui-column`),R=e=>e.getAttribute(`data-wui-card`),z=e=>e instanceof HTMLElement&&!!e.hidden||e.hasAttribute(`hidden`),B=e=>z(e)||e.hasAttribute(O),V=e=>e instanceof Element?e:null,H=e=>typeof e==`object`&&e&&`name`in e?e.name:void 0,U=e=>typeof e==`object`&&e&&`message`in e?e.message:void 0,W=(e,t,n)=>{let r=e.querySelector(t);return r instanceof n?r:null},G=(e,t,n)=>[...e.querySelectorAll(t)].filter(e=>e instanceof n),K=(e,t,n)=>{let r=e.closest(t);return r instanceof n?r:null},q=()=>window.WUI??null,J=(e,t)=>{e&&q()?.toast(e,{variant:t})},Y=class extends n{constructor(){super(),this._wired=!1,this._filter=null,this._expanded=/* @__PURE__ */ new Set,this._revealed=/* @__PURE__ */ new Set,this._press=null,this._drag=null,this._kbd=null,this._suppressClick=!1,this._observer=null,this._refreshQueued=!1,this._scrollTimer=0,this._onPointerMove=e=>this._pointerMove(e),this._onPointerUp=e=>this._pointerUp(e),this._onPointerCancel=()=>this._endPointer(!1),this._onDocKeyDown=e=>{e.key===`Escape`&&this._drag&&(e.preventDefault(),this._endPointer(!1))},this._onScroll=()=>{clearTimeout(this._scrollTimer),this._scrollTimer=setTimeout(()=>this._syncSwitcherFromScroll(),80)},this.addEventListener(`pointerdown`,e=>this._pointerDown(e)),this.addEventListener(`keydown`,e=>this._keyDown(e)),this.addEventListener(`click`,e=>this._click(e),!0),this.addEventListener(`scroll`,e=>{e.target instanceof Element&&this._loadOnScroll(e.target)},!0),this.addEventListener(`dragstart`,e=>{V(e.target)?.closest(g)&&e.preventDefault()}),this.addEventListener(`touchmove`,e=>{this._drag&&e.preventDefault()},{passive:!1})}_controlled(){return this.hasAttribute(`controlled`)}connectedCallback(){if(!this._wired){this._wired=!0,this._scroller()?.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._restoreCollapsed();for(let e of this._allCards())this._prepareCard(e);if(typeof MutationObserver==`function`){this._observer=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e instanceof HTMLElement&&e.matches(g)&&this._prepareCard(e);this._queueRefresh()});for(let e of this.querySelectorAll(h))this._observer.observe(e,{childList:!0})}this.refresh()}}disconnectedCallback(){this._endPointer(!1),this._observer?.disconnect(),this._observer=null,this._scroller()?.removeEventListener(`scroll`,this._onScroll),clearTimeout(this._scrollTimer),this._wired=!1}setFilter(e){if(e!=null&&typeof e!=`function`)throw TypeError(`wui-kanban setFilter: pass a function or null.`);if(this._filter=e,!e)for(let e of this._allCards())e.hidden=!1;this.refresh()}refresh(){if(this._controlled())return;this._refreshQueued=!1;let e=this._summaryFormat();for(let t of this._columns()){let n=L(t),i=o(t.getAttribute(D)),a=[],s=[];for(let e of this._cardsIn(t))this._filter&&(e.hidden=this._filter(e)===!1),z(e)?e.removeAttribute(O):(a.push(e),s.push(e.getAttribute(`data-wui-value`)));let d=this._expanded.has(n),f=c(a.map(R),i,d,this._revealed);for(let e of a)e.toggleAttribute(O,f.has(R(e)));let p=this._unloadedIn(t),m=String(a.length+p);for(let e of this._countsOf(t))e.textContent!==m&&(e.textContent=m);let h=W(t,y,HTMLElement);if(h&&(h.hidden=a.length>0),e){let n=t.querySelector(v);n&&(n.textContent=r(l(s),e))}let g=W(t,E,HTMLElement);if(g){g.hidden=i==null||(d?a.length<=i:f.size===0),g.setAttribute(`aria-expanded`,d?`true`:`false`);let e=d?u.fewer:u.more(f.size);g.textContent!==e&&(g.textContent=e)}let _=W(t,A,HTMLButtonElement);if(_&&(_.hidden=p<=0,!t.hasAttribute(`data-wui-loading`))){_.disabled=!1;let e=u.loadMore(p);_.textContent!==e&&(_.textContent=e)}}}moveCard(e,t,n){let r=this._cardByKey(e);if(!r)throw Error(`wui-kanban moveCard: no card "${String(e)}" on this board.`);if(!this._columnByKey(t))throw Error(`wui-kanban moveCard: no column "${String(t)}" on this board.`);return this._commit(r,t,n)}_columns(){return G(this,m,HTMLElement)}_columnByKey(e){return this._columns().find(t=>L(t)===e)||null}_columnOf(e){return K(e,m,HTMLElement)}_titleOf(e){return(e.querySelector(`.wui-kanban-title`)?.textContent||L(e)||``).replace(/\s+/g,` `).trim()}_bodyOf(e){return W(e,h,HTMLElement)}_cardsIn(e){let t=this._bodyOf(e);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.matches(g)):[]}_visibleCardsIn(e){return this._cardsIn(e).filter(e=>!B(e))}_allCards(){return G(this,`${h} > ${g}`,HTMLElement)}_cardByKey(e){return this._allCards().find(t=>R(t)===e)||null}_countsOf(e){let t=L(e),n=[...this.querySelectorAll(C)].filter(e=>e.getAttribute(`data-wui-switch`)===t);return[...e.querySelectorAll(_),...n.flatMap(e=>[...e.querySelectorAll(_)])]}_scroller(){return W(this,w,HTMLElement)}_summaryFormat(){let e=this.getAttribute(`summary-format`);return e?a(e,this.getAttribute(`summary-unit`)):null}_queueRefresh(){this._refreshQueued||(this._refreshQueued=!0,queueMicrotask(()=>{this._refreshQueued&&this.refresh()}))}_prepareCard(e){let t=this.querySelector(S);t?.id&&!e.hasAttribute(`aria-describedby`)&&e.setAttribute(`aria-describedby`,t.id),e.hasAttribute(`tabindex`)||(e.tabIndex=0)}_announce(e){let t=W(this,x,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}_fire(e,t,n=!1){return this.dispatchEvent(new CustomEvent(e,{bubbles:!0,cancelable:n,detail:t}))}_canLift(e){let t=i(e),n=this.hasAttribute(`readonly`);return n||e.hasAttribute(`data-wui-locked`)?(this._announce(u.locked(t)),this._fire(`wui:kanban:locked`,{key:R(e),card:e,reason:n?`readonly`:`locked`},!0),!1):e.getAttribute(`aria-busy`)!==`true`||(this._announce(u.busy),J(u.busy,`info`),!1)}_check(e,t,n){if(t===n)return{ok:!1,source:!0,reason:null};let r=this._columnByKey(t),i=this._columnByKey(n),a=u.refused(r?this._titleOf(r):String(t),i?this._titleOf(i):String(n)),o=i?.getAttribute(`data-accept-from`),s=o?.split(/\s+/).filter(Boolean)??[];if(o!=null&&!s.includes(t))return{ok:!1,reason:a};if(typeof this.accept==`function`){let r=this.accept(e,t,n);if(r===!1)return{ok:!1,reason:a};if(typeof r==`string`&&r)return{ok:!1,reason:r}}return{ok:!0,reason:null}}_markTargets(e,t){let n=i(e),r=/* @__PURE__ */ new Map;for(let i of this._columns()){let a=L(i),o=this._check(e,t,a);r.set(a,o),i.setAttribute(`data-wui-drop`,o.source?`source`:o.ok?`ok`:`refused`);let s=W(i,b,HTMLElement);s&&!o.source&&(s.textContent=o.ok?u.dropHere(n,this._titleOf(i)):o.reason,s.hidden=!1)}return r}_clearTargets(){for(let e of this._columns()){e.removeAttribute(`data-wui-drop`),e.removeAttribute(`data-wui-over`),e.removeAttribute(`data-wui-target`);let t=W(e,b,HTMLElement);t&&(t.hidden=!0,t.textContent=``)}}async _commit(e,t,n){let r=this._columnOf(e);if(!r)throw Error(`wui-kanban: the card is not inside a column.`);let a=L(r),o=this._columnByKey(t),s=i(e);if(a===t||!this._canLift(e))return!1;let c=this._check(e,a,t);if(!c.ok)return this._announce(c.reason),J(c.reason,`info`),!1;if(!o)throw Error(`wui-kanban: no column "${String(t)}" on this board.`);let l=this._cardsIn(o),d=Number.isInteger(n)?Math.max(0,Math.min(n??0,l.length)):l.length,m={key:R(e),card:e,from:a,to:t,index:d},h=e.contains(document.activeElement);if(this._controlled())return this._fire(`wui:kanban:move`,m),this._announce(u.moved(s,this._titleOf(o))),h&&this._refocusSoon(m.key),!0;if(!this._fire(`wui:kanban:move`,m,!0))return!1;let g=o.hasAttribute(D)&&!this._revealed.has(m.key);g&&this._revealed.add(m.key);let _={parent:e.parentNode,next:e.nextSibling,column:r,revealed:g},v=this._bodyOf(o);if(!v)throw Error(`wui-kanban: the target column has no body.`);v.insertBefore(e,l[d]||null),h&&this._focusMoved(e),this.refresh();let y=o.getAttribute(`data-wui-step`);if(y)return this._runStep(e,m,_,y,o.getAttribute(`data-wui-step-size`));let b=this.getAttribute(`move-url`);if(!b)return this._announce(u.moved(s,this._titleOf(o))),this._fire(`wui:kanban:moved`,{...m,result:null}),!0;this._lock(e,!0),this._announce(u.saving(s,this._titleOf(o)));let x=new URLSearchParams({card:String(m.key),from:String(a),to:String(t),index:String(d)}),S=await f(b,{method:`POST`,body:x});if(this._lock(e,!1),S.kind===`session`)return!1;if(S.ok){let t=this._applyFragment(S.html)||e;return J(S.message,`success`),this._announce(u.moved(i(t),this._titleOf(o))),this._fire(`wui:kanban:moved`,{...m,card:t,result:S}),!0}return this._rollback(e,_),S.kind!==`aborted`&&J(S.message||p[S.kind]||u.failed.server,`danger`),this._fire(`wui:kanban:failed`,{...m,kind:S.kind,status:S.status,message:S.message}),!1}async _runStep(e,t,n,r,a){let o=i(e),s=this._columnByKey(t.to),c=new URLSearchParams({card:String(t.key),from:String(t.from),to:String(t.to)}).toString(),l=r+(r.includes(`?`)?`&`:`?`)+c;this._lock(e,!0);let d;try{let t=window.WUI?.modal?.load;if(typeof t!=`function`)throw Error(`<wui-kanban> data-wui-step needs the Razor script webority-ui.js (WUI.modal.load).`);d=await(await t(l,{trigger:e,size:a||void 0})).closed}catch(r){return this._lock(e,!1),this._rollback(e,n),H(r)!==`AbortError`&&J(u.failed.server,`danger`),this._fire(`wui:kanban:failed`,{...t,kind:`step`,status:0,message:U(r)??null}),!1}if(d?.status!==`success`)return this._lock(e,!1),this._rollback(e,n),this._announce(u.cancelled(o)),this._fire(`wui:kanban:failed`,{...t,kind:`dismissed`,status:0,message:null}),!1;let p=e,m=this.getAttribute(`card-url`);if(m){let n=await f(`${m}${m.includes(`?`)?`&`:`?`}${new URLSearchParams({card:String(t.key)})}`);n.ok&&(p=this._applyFragment(n.html)||e)}if(this._lock(p,!1),!s)throw Error(`wui-kanban: no column "${String(t.to)}" on this board.`);return this._announce(u.moved(i(p),this._titleOf(s))),this._fire(`wui:kanban:moved`,{...t,card:p,result:d}),!0}_lock(e,t){t?(e.setAttribute(`aria-busy`,`true`),e.setAttribute(`data-wui-saving`,``)):(e.removeAttribute(`aria-busy`),e.removeAttribute(`data-wui-saving`))}_rollback(e,t){let n=e.contains(document.activeElement),r=t.next&&t.next.parentNode===t.parent?t.next:null;if(t.revealed&&this._revealed.delete(R(e)),!t.parent)throw Error(`wui-kanban: the card had no parent to go back to.`);t.parent.insertBefore(e,r),n&&e.focus(),this.refresh(),this._announce(u.rolledBack(i(e),this._titleOf(t.column)))}_applyFragment(t){if(!t)return null;let n=document.createElement(`template`);n.innerHTML=t;for(let t of n.content.querySelectorAll(`script`))e(`[@webority/ui-elements] A kanban fragment carried a script tag; it was removed, not run.`),t.remove();let r=null;for(let e of G(n.content,g,HTMLElement)){if(e.closest(`template`))continue;let t=this._cardByKey(R(e));if(!t)continue;let n=t.contains(document.activeElement);t.dispatchEvent(new CustomEvent(`wui:teardown`,{bubbles:!0})),t.hidden&&(e.hidden=!0),t.replaceWith(e),this._prepareCard(e),n&&e.focus(),r??=e}for(let e of G(n.content,`template[data-wui-kanban-summary]`,HTMLTemplateElement))this._columnByKey(e.getAttribute(`data-wui-kanban-summary`))?.querySelector(v)?.replaceChildren(e.content.cloneNode(!0));return this.refresh(),q()?.refresh(),r}_refocusSoon(e){let t=()=>{let t=this._cardByKey(e);t&&this._focusMoved(t)};typeof requestAnimationFrame==`function`?requestAnimationFrame(t):setTimeout(t,0)}_focusMoved(e){e.focus({preventScroll:!0}),e.scrollIntoView?.({block:`nearest`})}_pointerDown(e){if(e.button!==0||e.isPrimary===!1||this._drag||this._kbd)return;let t=V(e.target),n=t?K(t,g,HTMLElement):null;if(!n||!this.contains(n)||t?.closest(k))return;let r={card:n,id:e.pointerId,x:e.clientX,y:e.clientY,type:e.pointerType,timer:0};this._press=r,e.pointerType===`touch`&&(r.timer=setTimeout(()=>{this._press===r&&this._startDrag(r,r.x,r.y)},400)),window.addEventListener(`pointermove`,this._onPointerMove),window.addEventListener(`pointerup`,this._onPointerUp),window.addEventListener(`pointercancel`,this._onPointerCancel)}_pointerMove(e){let t=this._press;if(t&&e.pointerId===t.id){if(!this._drag){if(!(Math.hypot(e.clientX-t.x,e.clientY-t.y)>6))return;if(t.type===`touch`){this._endPointer(!1);return}if(this._startDrag(t,e.clientX,e.clientY),!this._drag)return}this._dragTo(e.clientX,e.clientY)}}_pointerUp(e){this._press&&e.pointerId===this._press.id&&this._endPointer(!!this._drag)}_startDrag(e,t,n){let r=e.card;if(!this._canLift(r)){this._endPointer(!1);return}let a=this._columnOf(r);if(!a)throw Error(`wui-kanban: the card is not inside a column.`);let o=L(a),s=r.getBoundingClientRect(),c=r.cloneNode(!0);if(!(c instanceof HTMLElement))return;let l=c;for(let e of[l,...l.querySelectorAll(`[id]`)])e.removeAttribute(`id`);l.removeAttribute(`data-wui-card`),l.removeAttribute(`tabindex`),l.setAttribute(`aria-hidden`,`true`),l.classList.add(`wui-kanban-ghost`),l.style.width=`${s.width}px`,this.appendChild(l),r.setAttribute(`data-wui-dragging`,``),this.setAttribute(`data-wui-dragging`,``),this._drag={card:r,from:o,ghost:l,dx:t-s.left,dy:n-s.top,x:t,y:n,over:null,verdicts:this._markTargets(r,o)},this._announce(u.lifted(i(r),this._titleOf(a))),document.addEventListener(`keydown`,this._onDocKeyDown),this._dragTo(t,n)}_dragTo(e,t){let n=this._drag;if(!n)throw Error(`wui-kanban: no drag in progress.`);n.x=e,n.y=t,n.ghost.style.transform=`translate(${e-n.dx}px, ${t-n.dy}px)`;let r=this._columnAt(e,t);r!==n.over&&(n.over?.removeAttribute(`data-wui-over`),r?.setAttribute(`data-wui-over`,``),n.over=r),this._autoScroll(e,t,r)}_columnAt(e,t){for(let n of this._columns()){let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom)return n}return null}_indexAt(e,t){let n=this._visibleCardsIn(e).filter(e=>e!==this._drag?.card).find(e=>{let n=e.getBoundingClientRect();return t<n.top+n.height/2}),r=this._cardsIn(e).filter(e=>e!==this._drag?.card);return n?r.indexOf(n):r.length}_autoScroll(e,t,n){let r=this._scroller();if(r){let t=r.getBoundingClientRect();t.width>0&&(e<t.left+P?r.scrollBy?.({left:-16}):e>t.right-P&&r.scrollBy?.({left:F}))}if(n&&this._scrollColumn(n,t))return;let i=window.innerHeight||0;i>0&&(t<P?window.scrollBy?.({top:-16}):t>i-P&&window.scrollBy?.({top:F}))}_scrollColumn(e,t){let n=this._bodyOf(e);if(!n||e.hasAttribute(`data-collapsed`)||n.scrollHeight<=n.clientHeight)return!1;let r=n.getBoundingClientRect();return t<r.top+P&&n.scrollTop>0?(n.scrollBy?.({top:-16}),!0):t>r.bottom-P&&n.scrollTop+n.clientHeight<n.scrollHeight-1&&(n.scrollBy?.({top:F}),!0)}_endPointer(e){let t=this._press,n=this._drag;if(t&&clearTimeout(t.timer||void 0),this._press=null,this._drag=null,window.removeEventListener(`pointermove`,this._onPointerMove),window.removeEventListener(`pointerup`,this._onPointerUp),window.removeEventListener(`pointercancel`,this._onPointerCancel),document.removeEventListener(`keydown`,this._onDocKeyDown),!n)return;n.ghost.remove(),n.card.removeAttribute(`data-wui-dragging`),this.removeAttribute(`data-wui-dragging`),this._suppressClick=!0,setTimeout(()=>{this._suppressClick=!1},0);let r=n.over;if(this._clearTargets(),!e||!r){this._announce(u.cancelled(i(n.card)));return}let a=L(r),o=n.verdicts.get(a);o?.source?this._announce(u.cancelled(i(n.card))):o?.ok?this._commit(n.card,a,this._indexAt(r,n.y)):(this._announce(o?.reason),J(o?.reason,`info`))}_click(e){let t=V(e.target);if(this._suppressClick&&t?.closest(g)){e.preventDefault(),e.stopPropagation(),this._suppressClick=!1;return}let n=t?.closest(T);if(n&&this.contains(n)){let e=K(n,m,HTMLElement);e&&this._setCollapsed(e,!e.hasAttribute(`data-collapsed`),!0);return}let r=t?.closest(A);if(r&&this.contains(r)){this._controlled()||this._loadMore(K(r,m,HTMLElement));return}let i=t?.closest(E);if(i&&this.contains(i)){this._controlled()||this._toggleMore(K(i,m,HTMLElement));return}let a=t?.closest(C);a&&this.contains(a)&&this._showColumn(a.getAttribute(`data-wui-switch`))}_keyDown(e){let t=this._kbd;if(t){this._liftedKey(e,t);return}let n=e.target instanceof HTMLElement?e.target:null;if(!n?.matches(g)||!this.contains(n))return;let r=this._columnOf(n);switch(e.key){case` `:case`Spacebar`:{if(e.preventDefault(),!this._canLift(n))return;if(!r)throw Error(`wui-kanban: the card is not inside a column.`);let t=L(r),a=this._columns();this._kbd={card:n,from:t,target:a.indexOf(r),verdicts:this._markTargets(n,t)},n.setAttribute(`data-wui-lifted`,``),this.setAttribute(`data-wui-dragging`,``),r.setAttribute(`data-wui-target`,``),this._announce(u.lifted(i(n),this._titleOf(r)));return}case`ArrowDown`:case`ArrowUp`:{if(!r)throw Error(`wui-kanban: the card is not inside a column.`);let t=this._visibleCardsIn(r),i=t[t.indexOf(n)+(e.key===`ArrowDown`?1:-1)];i&&(e.preventDefault(),i.focus());return}case`ArrowLeft`:case`ArrowRight`:{let t=this._columns(),n=e.key===`ArrowRight`?1:-1;for(let i=(r?t.indexOf(r):-1)+n;i>=0&&i<t.length;i+=n){let n=t[i],r=n?this._visibleCardsIn(n)[0]:void 0;if(r&&n&&!n.hasAttribute(`data-collapsed`)){e.preventDefault(),r.focus();return}}return}}}_liftedKey(e,t){let n=this._columns();switch(e.key){case`ArrowLeft`:case`ArrowRight`:{e.preventDefault();let r=t.target+(e.key===`ArrowRight`?1:-1);if(r<0||r>=n.length)return;n[t.target]?.removeAttribute(`data-wui-target`),t.target=r;let i=n[r];if(!i)return;i.setAttribute(`data-wui-target`,``),this._showColumn(L(i),!1);let a=t.verdicts.get(L(i));if(!a)throw Error(`wui-kanban: no verdict for the column.`);let o=this._titleOf(i);this._announce(a.source?u.overSource(o):a.ok?u.over(o,this._cardsIn(i).filter(e=>!z(e)).length):u.overRefused(o,a.reason??``));return}case` `:case`Spacebar`:case`Enter`:{e.preventDefault();let r=n[t.target];if(!r)throw Error(`wui-kanban: the lifted card has no target column.`);let a=L(r),o=t.verdicts.get(a);if(!o)throw Error(`wui-kanban: no verdict for the column.`);if(!o.source&&!o.ok){this._announce(o.reason);return}this._endKeyboard(),o.source?this._announce(u.cancelled(i(t.card))):this._commit(t.card,a);return}case`Escape`:case`Tab`:e.key===`Escape`&&e.preventDefault(),this._endKeyboard(),this._showColumn(t.from,!1),this._announce(u.cancelled(i(t.card)));return}}_endKeyboard(){let e=this._kbd;this._kbd=null,e&&(e.card.removeAttribute(`data-wui-lifted`),this.removeAttribute(`data-wui-dragging`),this._clearTargets())}_restoreCollapsed(){let e=d(this.getAttribute(`board-id`));for(let t of this._columns()){let n=L(t);t.hasAttribute(`data-collapsible`)&&Object.hasOwn(e,String(n))&&this._setCollapsed(t,e[String(n)],!1)}}_setCollapsed(e,t,n){let r=L(e);e.toggleAttribute(`data-collapsed`,t);let i=this._titleOf(e);for(let n of e.querySelectorAll(T))n.setAttribute(`aria-expanded`,t?`false`:`true`),n.setAttribute(`aria-label`,t?u.expand(i):u.collapse(i));n&&(s(this.getAttribute(`board-id`),r,t),this._fire(`wui:kanban:collapse`,{column:r,collapsed:t}))}_toggleMore(e){if(!e)return;let t=L(e);if(this._expanded.delete(t))for(let t of this._cardsIn(e))this._revealed.delete(R(t));else this._expanded.add(t);this.refresh()}_unloadedIn(e){return e.hasAttribute(j)?(e.hasAttribute(N)||e.setAttribute(N,String(Math.max(0,Number(e.getAttribute(M))-this._cardsIn(e).length))),Number(e.getAttribute(N))):0}async _loadMore(e){if(!e)throw Error(`wui-kanban: the load-more button is outside a column.`);let n=Number(e.getAttribute(N));if(e.hasAttribute(`data-wui-loading`)||!(n>0))return;e.setAttribute(`data-wui-loading`,``);let r=W(e,A,HTMLButtonElement);r&&(r.disabled=!0,r.textContent=u.loading);let i=new URL(String(e.getAttribute(j)),document.baseURI);i.searchParams.set(`skip`,String(this._cardsIn(e).length));let a=0,o=!1;try{let t=await f(i.toString());if(t.ok){let r=document.createElement(`template`);r.innerHTML=t.html;let i=this._bodyOf(e);for(let e of[...r.content.children])if(e.matches(g)&&!this._cardByKey(R(e))){if(!i)throw Error(`wui-kanban: the column has no body.`);i.append(e),a++}let s=t.response?.headers.get(`Wui-Kanban-Remaining`)??``;e.setAttribute(N,String(/^\d+$/.test(s)?Number(s):Math.max(0,n-a))),o=!0}}catch(e){t(`[@webority/ui-elements] A kanban column could not load its next cards.`,e)}e.removeAttribute(`data-wui-loading`),this.refresh(),o?this._fire(`wui:kanban:loaded`,{key:L(e),added:a}):J(u.loadFailed,`danger`)}_loadOnScroll(e){if(this._controlled()||!e.matches(h))return;let t=K(e,m,HTMLElement);t?.hasAttribute(j)&&e.scrollTop+e.clientHeight>=e.scrollHeight-I&&this._loadMore(t)}_isPhone(){return typeof matchMedia==`function`&&matchMedia(`(max-width: 767.98px)`).matches}_showColumn(e,t=!0){for(let t of this.querySelectorAll(C))t.getAttribute(`data-wui-switch`)===e?t.setAttribute(`aria-current`,`true`):t.removeAttribute(`aria-current`);let n=this._columnByKey(e),r=this._scroller();if(!n||!r||!t&&!this._isPhone())return;let i=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches;r.scrollTo?.({left:n.offsetLeft-r.offsetLeft,behavior:i?`auto`:`smooth`})}_syncSwitcherFromScroll(){let e=this._scroller();if(!e||!this._isPhone())return;let t=e.clientWidth||1,n=this._columns()[Math.round(e.scrollLeft/t)];if(n)for(let e of this.querySelectorAll(C))e.getAttribute(`data-wui-switch`)===L(n)?e.setAttribute(`aria-current`,`true`):e.removeAttribute(`aria-current`)}};export{Y as t};
|
|
1
|
+
import{n as e,t}from"./devWarn-DXdRWZs3.js";import{t as n}from"./elementBase-Cxeyx0tU.js";import{m as r}from"./formatters-ljfITOZ3.js";import{c as i,d as a,f as o,h as s,l as c,m as l,o as u,p as d}from"./kanbanModel-BaT75e-b.js";import{l as f}from"./wuiHttp-DGbD7Fra.js";var p=u.failed,m=`[data-wui-column]`,h=`[data-wui-body]`,g=`[data-wui-card]`,_=`[data-wui-count]`,v=`[data-wui-summary]`,y=`[data-wui-empty]`,b=`[data-wui-drop-note]`,x=`[data-wui-live]`,S=`[data-wui-help]`,C=`[data-wui-switch]`,w=`[data-wui-scroller]`,T=`[data-wui-collapse]`,E=`[data-wui-more]`,D=`data-wui-visible-limit`,O=`data-wui-overflow`,k=`input, select, textarea, [contenteditable=""], [contenteditable="true"], [data-wui-no-drag]`,A=`[data-wui-load-more]`,j=`data-wui-more-url`,M=`data-wui-total`,N=`data-wui-unloaded`,P=48,F=16,I=160,L=e=>e.getAttribute(`data-wui-column`),R=e=>e.getAttribute(`data-wui-card`),z=e=>e instanceof HTMLElement&&!!e.hidden||e.hasAttribute(`hidden`),B=e=>z(e)||e.hasAttribute(O),V=e=>e instanceof Element?e:null,H=e=>typeof e==`object`&&e&&`name`in e?e.name:void 0,U=e=>typeof e==`object`&&e&&`message`in e?e.message:void 0,W=(e,t,n)=>{let r=e.querySelector(t);return r instanceof n?r:null},G=(e,t,n)=>[...e.querySelectorAll(t)].filter(e=>e instanceof n),K=(e,t,n)=>{let r=e.closest(t);return r instanceof n?r:null},q=()=>window.WUI??null,J=(e,t)=>{e&&q()?.toast(e,{variant:t})},Y=class extends n{constructor(){super(),this._wired=!1,this._filter=null,this._expanded=/* @__PURE__ */ new Set,this._revealed=/* @__PURE__ */ new Set,this._press=null,this._drag=null,this._kbd=null,this._suppressClick=!1,this._observer=null,this._refreshQueued=!1,this._scrollTimer=0,this._onPointerMove=e=>this._pointerMove(e),this._onPointerUp=e=>this._pointerUp(e),this._onPointerCancel=()=>this._endPointer(!1),this._onDocKeyDown=e=>{e.key===`Escape`&&this._drag&&(e.preventDefault(),this._endPointer(!1))},this._onScroll=()=>{clearTimeout(this._scrollTimer),this._scrollTimer=setTimeout(()=>this._syncSwitcherFromScroll(),80)},this.addEventListener(`pointerdown`,e=>this._pointerDown(e)),this.addEventListener(`keydown`,e=>this._keyDown(e)),this.addEventListener(`click`,e=>this._click(e),!0),this.addEventListener(`scroll`,e=>{e.target instanceof Element&&this._loadOnScroll(e.target)},!0),this.addEventListener(`dragstart`,e=>{V(e.target)?.closest(g)&&e.preventDefault()}),this.addEventListener(`touchmove`,e=>{this._drag&&e.preventDefault()},{passive:!1})}_controlled(){return this.hasAttribute(`controlled`)}connectedCallback(){if(!this._wired){this._wired=!0,this._scroller()?.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._restoreCollapsed();for(let e of this._allCards())this._prepareCard(e);if(typeof MutationObserver==`function`){this._observer=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e instanceof HTMLElement&&e.matches(g)&&this._prepareCard(e);this._queueRefresh()});for(let e of this.querySelectorAll(h))this._observer.observe(e,{childList:!0})}this.refresh()}}disconnectedCallback(){this._endPointer(!1),this._observer?.disconnect(),this._observer=null,this._scroller()?.removeEventListener(`scroll`,this._onScroll),clearTimeout(this._scrollTimer),this._wired=!1}setFilter(e){if(e!=null&&typeof e!=`function`)throw TypeError(`wui-kanban setFilter: pass a function or null.`);if(this._filter=e,!e)for(let e of this._allCards())e.hidden=!1;this.refresh()}refresh(){if(this._controlled())return;this._refreshQueued=!1;let e=this._summaryFormat();for(let t of this._columns()){let n=L(t),i=o(t.getAttribute(D)),a=[],s=[];for(let e of this._cardsIn(t))this._filter&&(e.hidden=this._filter(e)===!1),z(e)?e.removeAttribute(O):(a.push(e),s.push(e.getAttribute(`data-wui-value`)));let d=this._expanded.has(n),f=c(a.map(R),i,d,this._revealed);for(let e of a)e.toggleAttribute(O,f.has(R(e)));let p=this._unloadedIn(t),m=String(a.length+p);for(let e of this._countsOf(t))e.textContent!==m&&(e.textContent=m);let h=W(t,y,HTMLElement);if(h&&(h.hidden=a.length>0),e){let n=t.querySelector(v);n&&(n.textContent=r(l(s),e))}let g=W(t,E,HTMLElement);if(g){g.hidden=i==null||(d?a.length<=i:f.size===0),g.setAttribute(`aria-expanded`,d?`true`:`false`);let e=d?u.fewer:u.more(f.size);g.textContent!==e&&(g.textContent=e)}let _=W(t,A,HTMLButtonElement);if(_&&(_.hidden=p<=0,!t.hasAttribute(`data-wui-loading`))){_.disabled=!1;let e=u.loadMore(p);_.textContent!==e&&(_.textContent=e)}}}moveCard(e,t,n){let r=this._cardByKey(e);if(!r)throw Error(`wui-kanban moveCard: no card "${String(e)}" on this board.`);if(!this._columnByKey(t))throw Error(`wui-kanban moveCard: no column "${String(t)}" on this board.`);return this._commit(r,t,n)}_columns(){return G(this,m,HTMLElement)}_columnByKey(e){return this._columns().find(t=>L(t)===e)||null}_columnOf(e){return K(e,m,HTMLElement)}_titleOf(e){return(e.querySelector(`.wui-kanban-title`)?.textContent||L(e)||``).replace(/\s+/g,` `).trim()}_bodyOf(e){return W(e,h,HTMLElement)}_cardsIn(e){let t=this._bodyOf(e);return t?[...t.children].filter(e=>e instanceof HTMLElement&&e.matches(g)):[]}_visibleCardsIn(e){return this._cardsIn(e).filter(e=>!B(e))}_allCards(){return G(this,`${h} > ${g}`,HTMLElement)}_cardByKey(e){return this._allCards().find(t=>R(t)===e)||null}_countsOf(e){let t=L(e),n=[...this.querySelectorAll(C)].filter(e=>e.getAttribute(`data-wui-switch`)===t);return[...e.querySelectorAll(_),...n.flatMap(e=>[...e.querySelectorAll(_)])]}_scroller(){return W(this,w,HTMLElement)}_summaryFormat(){let e=this.getAttribute(`summary-format`);return e?a(e,this.getAttribute(`summary-unit`)):null}_queueRefresh(){this._refreshQueued||(this._refreshQueued=!0,queueMicrotask(()=>{this._refreshQueued&&this.refresh()}))}_prepareCard(e){let t=this.querySelector(S);t?.id&&!e.hasAttribute(`aria-describedby`)&&e.setAttribute(`aria-describedby`,t.id),e.hasAttribute(`tabindex`)||(e.tabIndex=0)}_announce(e){let t=W(this,x,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}_fire(e,t,n=!1){return this.dispatchEvent(new CustomEvent(e,{bubbles:!0,cancelable:n,detail:t}))}_canLift(e){let t=i(e),n=this.hasAttribute(`readonly`);return n||e.hasAttribute(`data-wui-locked`)?(this._announce(u.locked(t)),this._fire(`wui:kanban:locked`,{key:R(e),card:e,reason:n?`readonly`:`locked`},!0),!1):e.getAttribute(`aria-busy`)!==`true`||(this._announce(u.busy),J(u.busy,`info`),!1)}_check(e,t,n){if(t===n)return{ok:!1,source:!0,reason:null};let r=this._columnByKey(t),i=this._columnByKey(n),a=u.refused(r?this._titleOf(r):String(t),i?this._titleOf(i):String(n)),o=i?.getAttribute(`data-accept-from`),s=o?.split(/\s+/).filter(Boolean)??[];if(o!=null&&!s.includes(t))return{ok:!1,reason:a};if(typeof this.accept==`function`){let r=this.accept(e,t,n);if(r===!1)return{ok:!1,reason:a};if(typeof r==`string`&&r)return{ok:!1,reason:r}}return{ok:!0,reason:null}}_markTargets(e,t){let n=i(e),r=/* @__PURE__ */ new Map;for(let i of this._columns()){let a=L(i),o=this._check(e,t,a);r.set(a,o),i.setAttribute(`data-wui-drop`,o.source?`source`:o.ok?`ok`:`refused`);let s=W(i,b,HTMLElement);s&&!o.source&&(s.textContent=o.ok?u.dropHere(n,this._titleOf(i)):o.reason,s.hidden=!1)}return r}_clearTargets(){for(let e of this._columns()){e.removeAttribute(`data-wui-drop`),e.removeAttribute(`data-wui-over`),e.removeAttribute(`data-wui-target`);let t=W(e,b,HTMLElement);t&&(t.hidden=!0,t.textContent=``)}}async _commit(e,t,n){let r=this._columnOf(e);if(!r)throw Error(`wui-kanban: the card is not inside a column.`);let a=L(r),o=this._columnByKey(t),s=i(e);if(a===t||!this._canLift(e))return!1;let c=this._check(e,a,t);if(!c.ok)return this._announce(c.reason),J(c.reason,`info`),!1;if(!o)throw Error(`wui-kanban: no column "${String(t)}" on this board.`);let l=this._cardsIn(o),d=Number.isInteger(n)?Math.max(0,Math.min(n??0,l.length)):l.length,m={key:R(e),card:e,from:a,to:t,index:d},h=e.contains(document.activeElement);if(this._controlled())return this._fire(`wui:kanban:move`,m),this._announce(u.moved(s,this._titleOf(o))),h&&this._refocusSoon(m.key),!0;if(!this._fire(`wui:kanban:move`,m,!0))return!1;let g=o.hasAttribute(D)&&!this._revealed.has(m.key);g&&this._revealed.add(m.key);let _={parent:e.parentNode,next:e.nextSibling,column:r,revealed:g},v=this._bodyOf(o);if(!v)throw Error(`wui-kanban: the target column has no body.`);v.insertBefore(e,l[d]||null),h&&this._focusMoved(e),this.refresh();let y=o.getAttribute(`data-wui-step`);if(y)return this._runStep(e,m,_,y,o.getAttribute(`data-wui-step-size`));let b=this.getAttribute(`move-url`);if(!b)return this._announce(u.moved(s,this._titleOf(o))),this._fire(`wui:kanban:moved`,{...m,result:null}),!0;this._lock(e,!0),this._announce(u.saving(s,this._titleOf(o)));let x=new URLSearchParams({card:String(m.key),from:String(a),to:String(t),index:String(d)}),S=await f(b,{method:`POST`,body:x});if(this._lock(e,!1),S.kind===`session`)return!1;if(S.ok){let t=this._applyFragment(S.html)||e;return J(S.message,`success`),this._announce(u.moved(i(t),this._titleOf(o))),this._fire(`wui:kanban:moved`,{...m,card:t,result:S}),!0}return this._rollback(e,_),S.kind!==`aborted`&&J(S.message||p[S.kind]||u.failed.server,`danger`),this._fire(`wui:kanban:failed`,{...m,kind:S.kind,status:S.status,message:S.message}),!1}async _runStep(e,t,n,r,a){let o=i(e),s=this._columnByKey(t.to),c=new URLSearchParams({card:String(t.key),from:String(t.from),to:String(t.to)}).toString(),l=r+(r.includes(`?`)?`&`:`?`)+c;this._lock(e,!0);let d;try{let t=window.WUI?.modal?.load;if(typeof t!=`function`)throw Error(`<wui-kanban> data-wui-step needs the Razor script webority-ui.js (WUI.modal.load).`);d=await(await t(l,{trigger:e,size:a||void 0})).closed}catch(r){return this._lock(e,!1),this._rollback(e,n),H(r)!==`AbortError`&&J(u.failed.server,`danger`),this._fire(`wui:kanban:failed`,{...t,kind:`step`,status:0,message:U(r)??null}),!1}if(d?.status!==`success`)return this._lock(e,!1),this._rollback(e,n),this._announce(u.cancelled(o)),this._fire(`wui:kanban:failed`,{...t,kind:`dismissed`,status:0,message:null}),!1;let p=e,m=this.getAttribute(`card-url`);if(m){let n=await f(`${m}${m.includes(`?`)?`&`:`?`}${new URLSearchParams({card:String(t.key)})}`);n.ok&&(p=this._applyFragment(n.html)||e)}if(this._lock(p,!1),!s)throw Error(`wui-kanban: no column "${String(t.to)}" on this board.`);return this._announce(u.moved(i(p),this._titleOf(s))),this._fire(`wui:kanban:moved`,{...t,card:p,result:d}),!0}_lock(e,t){t?(e.setAttribute(`aria-busy`,`true`),e.setAttribute(`data-wui-saving`,``)):(e.removeAttribute(`aria-busy`),e.removeAttribute(`data-wui-saving`))}_rollback(e,t){let n=e.contains(document.activeElement),r=t.next&&t.next.parentNode===t.parent?t.next:null;if(t.revealed&&this._revealed.delete(R(e)),!t.parent)throw Error(`wui-kanban: the card had no parent to go back to.`);t.parent.insertBefore(e,r),n&&e.focus(),this.refresh(),this._announce(u.rolledBack(i(e),this._titleOf(t.column)))}_applyFragment(t){if(!t)return null;let n=document.createElement(`template`);n.innerHTML=t;for(let t of n.content.querySelectorAll(`script`))e(`[@webority/ui-elements] A kanban fragment carried a script tag; it was removed, not run.`),t.remove();let r=null;for(let e of G(n.content,g,HTMLElement)){if(e.closest(`template`))continue;let t=this._cardByKey(R(e));if(!t)continue;let n=t.contains(document.activeElement);t.dispatchEvent(new CustomEvent(`wui:teardown`,{bubbles:!0})),t.hidden&&(e.hidden=!0),t.replaceWith(e),this._prepareCard(e),n&&e.focus(),r??=e}for(let e of G(n.content,`template[data-wui-kanban-summary]`,HTMLTemplateElement))this._columnByKey(e.getAttribute(`data-wui-kanban-summary`))?.querySelector(v)?.replaceChildren(e.content.cloneNode(!0));return this.refresh(),q()?.refresh(),r}_refocusSoon(e){let t=()=>{let t=this._cardByKey(e);t&&this._focusMoved(t)};typeof requestAnimationFrame==`function`?requestAnimationFrame(t):setTimeout(t,0)}_focusMoved(e){e.focus({preventScroll:!0}),e.scrollIntoView?.({block:`nearest`})}_pointerDown(e){if(e.button!==0||e.isPrimary===!1||this._drag||this._kbd)return;let t=V(e.target),n=t?K(t,g,HTMLElement):null;if(!n||!this.contains(n)||t?.closest(k))return;let r={card:n,id:e.pointerId,x:e.clientX,y:e.clientY,type:e.pointerType,timer:0};this._press=r,e.pointerType===`touch`&&(r.timer=setTimeout(()=>{this._press===r&&this._startDrag(r,r.x,r.y)},400)),window.addEventListener(`pointermove`,this._onPointerMove),window.addEventListener(`pointerup`,this._onPointerUp),window.addEventListener(`pointercancel`,this._onPointerCancel)}_pointerMove(e){let t=this._press;if(t&&e.pointerId===t.id){if(!this._drag){if(!(Math.hypot(e.clientX-t.x,e.clientY-t.y)>6))return;if(t.type===`touch`){this._endPointer(!1);return}if(this._startDrag(t,e.clientX,e.clientY),!this._drag)return}this._dragTo(e.clientX,e.clientY)}}_pointerUp(e){this._press&&e.pointerId===this._press.id&&this._endPointer(!!this._drag)}_startDrag(e,t,n){let r=e.card;if(!this._canLift(r)){this._endPointer(!1);return}let a=this._columnOf(r);if(!a)throw Error(`wui-kanban: the card is not inside a column.`);let o=L(a),s=r.getBoundingClientRect(),c=r.cloneNode(!0);if(!(c instanceof HTMLElement))return;let l=c;for(let e of[l,...l.querySelectorAll(`[id]`)])e.removeAttribute(`id`);l.removeAttribute(`data-wui-card`),l.removeAttribute(`tabindex`),l.setAttribute(`aria-hidden`,`true`),l.classList.add(`wui-kanban-ghost`),l.style.width=`${s.width}px`,this.appendChild(l),r.setAttribute(`data-wui-dragging`,``),this.setAttribute(`data-wui-dragging`,``),this._drag={card:r,from:o,ghost:l,dx:t-s.left,dy:n-s.top,x:t,y:n,over:null,verdicts:this._markTargets(r,o)},this._announce(u.lifted(i(r),this._titleOf(a))),document.addEventListener(`keydown`,this._onDocKeyDown),this._dragTo(t,n)}_dragTo(e,t){let n=this._drag;if(!n)throw Error(`wui-kanban: no drag in progress.`);n.x=e,n.y=t,n.ghost.style.transform=`translate(${e-n.dx}px, ${t-n.dy}px)`;let r=this._columnAt(e,t);r!==n.over&&(n.over?.removeAttribute(`data-wui-over`),r?.setAttribute(`data-wui-over`,``),n.over=r),this._autoScroll(e,t,r)}_columnAt(e,t){for(let n of this._columns()){let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom)return n}return null}_indexAt(e,t){let n=this._visibleCardsIn(e).filter(e=>e!==this._drag?.card).find(e=>{let n=e.getBoundingClientRect();return t<n.top+n.height/2}),r=this._cardsIn(e).filter(e=>e!==this._drag?.card);return n?r.indexOf(n):r.length}_autoScroll(e,t,n){let r=this._scroller();if(r){let t=r.getBoundingClientRect();t.width>0&&(e<t.left+P?r.scrollBy?.({left:-16}):e>t.right-P&&r.scrollBy?.({left:F}))}if(n&&this._scrollColumn(n,t))return;let i=window.innerHeight||0;i>0&&(t<P?window.scrollBy?.({top:-16}):t>i-P&&window.scrollBy?.({top:F}))}_scrollColumn(e,t){let n=this._bodyOf(e);if(!n||e.hasAttribute(`data-collapsed`)||n.scrollHeight<=n.clientHeight)return!1;let r=n.getBoundingClientRect();return t<r.top+P&&n.scrollTop>0?(n.scrollBy?.({top:-16}),!0):t>r.bottom-P&&n.scrollTop+n.clientHeight<n.scrollHeight-1&&(n.scrollBy?.({top:F}),!0)}_endPointer(e){let t=this._press,n=this._drag;if(t&&clearTimeout(t.timer||void 0),this._press=null,this._drag=null,window.removeEventListener(`pointermove`,this._onPointerMove),window.removeEventListener(`pointerup`,this._onPointerUp),window.removeEventListener(`pointercancel`,this._onPointerCancel),document.removeEventListener(`keydown`,this._onDocKeyDown),!n)return;n.ghost.remove(),n.card.removeAttribute(`data-wui-dragging`),this.removeAttribute(`data-wui-dragging`),this._suppressClick=!0,setTimeout(()=>{this._suppressClick=!1},0);let r=n.over;if(this._clearTargets(),!e||!r){this._announce(u.cancelled(i(n.card)));return}let a=L(r),o=n.verdicts.get(a);o?.source?this._announce(u.cancelled(i(n.card))):o?.ok?this._commit(n.card,a,this._indexAt(r,n.y)):(this._announce(o?.reason),J(o?.reason,`info`))}_click(e){let t=V(e.target);if(this._suppressClick&&t?.closest(g)){e.preventDefault(),e.stopPropagation(),this._suppressClick=!1;return}let n=t?.closest(T);if(n&&this.contains(n)){let e=K(n,m,HTMLElement);e&&this._setCollapsed(e,!e.hasAttribute(`data-collapsed`),!0);return}let r=t?.closest(A);if(r&&this.contains(r)){this._controlled()||this._loadMore(K(r,m,HTMLElement));return}let i=t?.closest(E);if(i&&this.contains(i)){this._controlled()||this._toggleMore(K(i,m,HTMLElement));return}let a=t?.closest(C);a&&this.contains(a)&&this._showColumn(a.getAttribute(`data-wui-switch`))}_keyDown(e){let t=this._kbd;if(t){this._liftedKey(e,t);return}let n=e.target instanceof HTMLElement?e.target:null;if(!n?.matches(g)||!this.contains(n))return;let r=this._columnOf(n);switch(e.key){case` `:case`Spacebar`:{if(e.preventDefault(),!this._canLift(n))return;if(!r)throw Error(`wui-kanban: the card is not inside a column.`);let t=L(r),a=this._columns();this._kbd={card:n,from:t,target:a.indexOf(r),verdicts:this._markTargets(n,t)},n.setAttribute(`data-wui-lifted`,``),this.setAttribute(`data-wui-dragging`,``),r.setAttribute(`data-wui-target`,``),this._announce(u.lifted(i(n),this._titleOf(r)));return}case`ArrowDown`:case`ArrowUp`:{if(!r)throw Error(`wui-kanban: the card is not inside a column.`);let t=this._visibleCardsIn(r),i=t[t.indexOf(n)+(e.key===`ArrowDown`?1:-1)];i&&(e.preventDefault(),i.focus());return}case`ArrowLeft`:case`ArrowRight`:{let t=this._columns(),n=e.key===`ArrowRight`?1:-1;for(let i=(r?t.indexOf(r):-1)+n;i>=0&&i<t.length;i+=n){let n=t[i],r=n?this._visibleCardsIn(n)[0]:void 0;if(r&&n&&!n.hasAttribute(`data-collapsed`)){e.preventDefault(),r.focus();return}}return}}}_liftedKey(e,t){let n=this._columns();switch(e.key){case`ArrowLeft`:case`ArrowRight`:{e.preventDefault();let r=t.target+(e.key===`ArrowRight`?1:-1);if(r<0||r>=n.length)return;n[t.target]?.removeAttribute(`data-wui-target`),t.target=r;let i=n[r];if(!i)return;i.setAttribute(`data-wui-target`,``),this._showColumn(L(i),!1);let a=t.verdicts.get(L(i));if(!a)throw Error(`wui-kanban: no verdict for the column.`);let o=this._titleOf(i);this._announce(a.source?u.overSource(o):a.ok?u.over(o,this._cardsIn(i).filter(e=>!z(e)).length):u.overRefused(o,a.reason??``));return}case` `:case`Spacebar`:case`Enter`:{e.preventDefault();let r=n[t.target];if(!r)throw Error(`wui-kanban: the lifted card has no target column.`);let a=L(r),o=t.verdicts.get(a);if(!o)throw Error(`wui-kanban: no verdict for the column.`);if(!o.source&&!o.ok){this._announce(o.reason);return}this._endKeyboard(),o.source?this._announce(u.cancelled(i(t.card))):this._commit(t.card,a);return}case`Escape`:case`Tab`:e.key===`Escape`&&e.preventDefault(),this._endKeyboard(),this._showColumn(t.from,!1),this._announce(u.cancelled(i(t.card)));return}}_endKeyboard(){let e=this._kbd;this._kbd=null,e&&(e.card.removeAttribute(`data-wui-lifted`),this.removeAttribute(`data-wui-dragging`),this._clearTargets())}_restoreCollapsed(){let e=d(this.getAttribute(`board-id`));for(let t of this._columns()){let n=L(t);t.hasAttribute(`data-collapsible`)&&Object.hasOwn(e,String(n))&&this._setCollapsed(t,e[String(n)],!1)}}_setCollapsed(e,t,n){let r=L(e);e.toggleAttribute(`data-collapsed`,t);let i=this._titleOf(e);for(let n of e.querySelectorAll(T))n.setAttribute(`aria-expanded`,t?`false`:`true`),n.setAttribute(`aria-label`,t?u.expand(i):u.collapse(i));n&&(s(this.getAttribute(`board-id`),r,t),this._fire(`wui:kanban:collapse`,{column:r,collapsed:t}))}_toggleMore(e){if(!e)return;let t=L(e);if(this._expanded.delete(t))for(let t of this._cardsIn(e))this._revealed.delete(R(t));else this._expanded.add(t);this.refresh()}_unloadedIn(e){return e.hasAttribute(j)?(e.hasAttribute(N)||e.setAttribute(N,String(Math.max(0,Number(e.getAttribute(M))-this._cardsIn(e).length))),Number(e.getAttribute(N))):0}async _loadMore(e){if(!e)throw Error(`wui-kanban: the load-more button is outside a column.`);let n=Number(e.getAttribute(N));if(e.hasAttribute(`data-wui-loading`)||!(n>0))return;e.setAttribute(`data-wui-loading`,``);let r=W(e,A,HTMLButtonElement);r&&(r.disabled=!0,r.textContent=u.loading);let i=new URL(String(e.getAttribute(j)),document.baseURI);i.searchParams.set(`skip`,String(this._cardsIn(e).length));let a=0,o=!1;try{let t=await f(i.toString());if(t.ok){let r=document.createElement(`template`);r.innerHTML=t.html;let i=this._bodyOf(e);for(let e of[...r.content.children])if(e.matches(g)&&!this._cardByKey(R(e))){if(!i)throw Error(`wui-kanban: the column has no body.`);i.append(e),a++}let s=t.response?.headers.get(`Wui-Kanban-Remaining`)??``;e.setAttribute(N,String(/^\d+$/.test(s)?Number(s):Math.max(0,n-a))),o=!0}}catch(e){t(`[@webority/ui-elements] A kanban column could not load its next cards.`,e)}e.removeAttribute(`data-wui-loading`),this.refresh(),o?this._fire(`wui:kanban:loaded`,{key:L(e),added:a}):J(u.loadFailed,`danger`)}_loadOnScroll(e){if(this._controlled()||!e.matches(h))return;let t=K(e,m,HTMLElement);t?.hasAttribute(j)&&e.scrollTop+e.clientHeight>=e.scrollHeight-I&&this._loadMore(t)}_isPhone(){return typeof matchMedia==`function`&&matchMedia(`(max-width: 767.98px)`).matches}_showColumn(e,t=!0){for(let t of this.querySelectorAll(C))t.getAttribute(`data-wui-switch`)===e?t.setAttribute(`aria-current`,`true`):t.removeAttribute(`aria-current`);let n=this._columnByKey(e),r=this._scroller();if(!n||!r||!t&&!this._isPhone())return;let i=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches;r.scrollTo?.({left:n.offsetLeft-r.offsetLeft,behavior:i?`auto`:`smooth`})}_syncSwitcherFromScroll(){let e=this._scroller();if(!e||!this._isPhone())return;let t=e.clientWidth||1,n=this._columns()[Math.round(e.scrollLeft/t)];if(n)for(let e of this.querySelectorAll(C))e.getAttribute(`data-wui-switch`)===L(n)?e.setAttribute(`aria-current`,`true`):e.removeAttribute(`aria-current`)}};export{Y as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,o as t}from"./formatters-ljfITOZ3.js";var n=Object.freeze([`neutral`,`primary`,`info`,`success`,`warning`,`danger`]),r=Object.freeze([`number`,`currency`,`compact`]),i=`wui-kanban:`,a=`(max-width: 767.98px)`,o=400,s=6,c=Object.freeze({help:`Press Space to pick up the card. Use the Left and Right arrow keys to choose a column, then Space to drop it, or Escape to cancel.`,empty:`Nothing here`,collapse:e=>`Collapse ${e}`,expand:e=>`Expand ${e}`,lifted:(e,t)=>`Picked up ${e} in ${t}. Use the Left and Right arrow keys to choose a column.`,over:(e,t)=>`${e}, ${t===1?`1 card`:`${t} cards`}. Drop allowed.`,overSource:e=>`${e}, where the card started.`,overRefused:(e,t)=>`${e}. ${t}`,dropHere:(e,t)=>`Drop here to move ${e} to ${t}.`,refused:(e,t)=>`Cards in ${e} cannot move to ${t}.`,moved:(e,t)=>`Moved ${e} to ${t}.`,saving:(e,t)=>`Moving ${e} to ${t}.`,cancelled:e=>`${e} was not moved.`,rolledBack:(e,t)=>`${e} went back to ${t}.`,locked:e=>`${e} cannot be moved.`,more:e=>`Show ${e} more`,fewer:`Show fewer`,loadMore:e=>`Show more (${e})`,loading:`Loading…`,loadFailed:`More cards could not be loaded. Try again.`,swipeHint:`Swipe sideways or tap a column`,busy:`This card is still saving. Try again in a moment.`,failed:Object.freeze({forbidden:`You do not have permission to move this card.`,client:`This card could not be moved. Refresh the board and try again.`,validation:`This card could not be moved. Refresh the board and try again.`,server:`Something went wrong on our side, so the card went back. Try again in a moment.`,network:`Could not reach the server, so the card went back. Check your connection and try again.`})}),l=e=>typeof e==`object`&&!!e,u=e=>{let t=l(e)?e.collapsed:void 0;return l(t)?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,!!t])):{}};function d(e){if(e==null||e===``)return null;let t=typeof e==`number`?e:Number(e);if(!Number.isInteger(t)||t<1)throw TypeError(`Unsupported kanban visible limit "${String(e)}". Use a whole number of 1 or more.`);return t}function f(e,t,n,r){let i=/* @__PURE__ */ new Set;if(t==null||n)return i;let a=0;for(let n of e)r.has(n)||(a<t?a++:i.add(n));return i}function p(e){let t=(e.getAttribute(`aria-label`)||e.textContent||``).replace(/\s+/g,` `).trim();return t.length>80?`${t.slice(0,79)}…`:t||e.getAttribute(`data-wui-card`)||`Card`}function m(e){return e?`${i}${e}`:null}function h(e,t=globalThis.localStorage){let n=m(e);if(!n||!t)return{};try{return u(JSON.parse(t.getItem(n)||`null`))}catch{return{}}}function g(e,t,n,r=globalThis.localStorage){let i=m(e);if(!i||!r)return;let a={...h(e,r),[String(t)]:!!n};try{r.setItem(i,JSON.stringify({collapsed:a}))}catch{}}function _(n,i){if(!r.includes(n))throw TypeError(`Unsupported kanban summary format "${String(n)}". Use ${r.join(`, `)}.`);if(i!=null&&i!==``&&!e(i))throw TypeError(`Unsupported kanban summary unit "${String(i)}". Use ${t.join(`, `)}.`);return n===`currency`?{style:`currency`,unit:i||`rupees`}:n===`compact`?{style:`compact`,currency:`INR`,unit:i||`rupees`}:{style:`number`,decimals:0}}function v(e){let t=0;for(let n of e){if(n==null||n===``)continue;let e=typeof n==`number`?n:Number(n);Number.isFinite(e)&&(t+=e)}return t}export{r as a,p as c,_ as d,d as f,g as h,i,f as l,v as m,o as n,c as o,h as p,a as r,n as s,s as t,m as u};
|
|
1
|
+
import{h as e,o as t}from"./formatters-ljfITOZ3.js";var n=Object.freeze([`neutral`,`primary`,`info`,`success`,`warning`,`danger`]),r=Object.freeze([`number`,`currency`,`compact`]),i=`wui-kanban:`,a=`(max-width: 767.98px)`,o=400,s=6,c=Object.freeze({help:`Press Space to pick up the card. Use the Left and Right arrow keys to choose a column, then Space to drop it, or Escape to cancel.`,empty:`Nothing here`,collapse:e=>`Collapse ${e}`,expand:e=>`Expand ${e}`,lifted:(e,t)=>`Picked up ${e} in ${t}. Use the Left and Right arrow keys to choose a column.`,over:(e,t)=>`${e}, ${t===1?`1 card`:`${t} cards`}. Drop allowed.`,overSource:e=>`${e}, where the card started.`,overRefused:(e,t)=>`${e}. ${t}`,dropHere:(e,t)=>`Drop here to move ${e} to ${t}.`,refused:(e,t)=>`Cards in ${e} cannot move to ${t}.`,moved:(e,t)=>`Moved ${e} to ${t}.`,saving:(e,t)=>`Moving ${e} to ${t}.`,cancelled:e=>`${e} was not moved.`,rolledBack:(e,t)=>`${e} went back to ${t}.`,locked:e=>`${e} cannot be moved.`,more:e=>`Show ${e} more`,fewer:`Show fewer`,loadMore:e=>`Show more (${e})`,loading:`Loading…`,loadFailed:`More cards could not be loaded. Try again.`,swipeHint:`Swipe sideways or tap a column`,busy:`This card is still saving. Try again in a moment.`,failed:Object.freeze({forbidden:`You do not have permission to move this card.`,client:`This card could not be moved. Refresh the board and try again.`,validation:`This card could not be moved. Refresh the board and try again.`,server:`Something went wrong on our side, so the card went back. Try again in a moment.`,network:`Could not reach the server, so the card went back. Check your connection and try again.`})}),l=e=>typeof e==`object`&&!!e,u=e=>{let t=l(e)?e.collapsed:void 0;return l(t)?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,!!t])):{}};function d(e){if(e==null||e===``)return null;let t=typeof e==`number`?e:Number(e);if(!Number.isInteger(t)||t<1)throw TypeError(`Unsupported kanban visible limit "${String(e)}". Use a whole number of 1 or more.`);return t}function f(e,t,n,r){let i=/* @__PURE__ */ new Set;if(t==null||n)return i;let a=0;for(let n of e)r.has(n)||(a<t?a++:i.add(n));return i}function p(e){let t=(e.getAttribute(`aria-label`)||e.textContent||``).replace(/\s+/g,` `).trim();return t.length>80?`${t.slice(0,79)}…`:t||e.getAttribute(`data-wui-card`)||`Card`}function m(e){return e?`${i}${e}`:null}function h(e,t=globalThis.localStorage){let n=m(e);if(!n||!t)return{};try{return u(JSON.parse(t.getItem(n)||`null`))}catch{return{}}}function g(e,t,n,r=globalThis.localStorage){let i=m(e);if(!i||!r)return;let a={...h(e,r),[String(t)]:!!n};try{r.setItem(i,JSON.stringify({collapsed:a}))}catch(e){if(!(e instanceof DOMException))throw e}}function _(n,i){if(!r.includes(n))throw TypeError(`Unsupported kanban summary format "${String(n)}". Use ${r.join(`, `)}.`);if(i!=null&&i!==``&&!e(i))throw TypeError(`Unsupported kanban summary unit "${String(i)}". Use ${t.join(`, `)}.`);return n===`currency`?{style:`currency`,unit:i||`rupees`}:n===`compact`?{style:`compact`,currency:`INR`,unit:i||`rupees`}:{style:`number`,decimals:0}}function v(e){let t=0;for(let n of e){if(n==null||n===``)continue;let e=typeof n==`number`?n:Number(n);Number.isFinite(e)&&(t+=e)}return t}export{r as a,p as c,_ as d,d as f,g as h,i,f as l,v as m,o as n,c as o,h as p,a as r,n as s,s as t,m as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./devWarn-DXdRWZs3.js";var t=`Recent`,n=5,r=20;function i(){let i,a=null,o=()=>i.getAttribute(`recents-key`)??``,s=()=>i.mode!==`tag`&&o()!==``,c=(t,n)=>{t!==a&&(a=t,e(`<wui-select> recents-limit "${t}" ${n}.`))},l=()=>{let e=i.getAttribute(`recents-limit`);if(e===null)return n;let t=Number(e);return!Number.isInteger(t)||t<1?(c(e,`is not a whole number from 1 to 20; 5 is used`),n):t>r?(c(e,`is over 20; 20 is used`),r):t},u=()=>{let e;try{e=JSON.parse(globalThis.localStorage?.getItem(o())??`[]`)}catch{return[]}return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]},d=e=>{try{globalThis.localStorage?.setItem(o(),JSON.stringify(e))}catch(e){if(!(e instanceof DOMException))throw e}};return{mount(t){i=t,i.mode===`tag`?e(`<wui-select> recents-key is not used in mode "tag"; it is ignored.`):o()===``&&e(`<wui-select> recents-key is empty; no recents are kept.`)},onPick(e,t){if(!s()||t?.isCustom)return!1;let n=String(e.value);return n===``||Array.isArray(i.value)&&i.value.includes(n)||d([n,...u().filter(e=>e!==n)].slice(0,l())),!1},recents(e){if(!s())return null;let n=l(),r=[];for(let t of u()){let i=e.find(e=>String(e.value)===t);if(i&&!i.disabled&&r.push(i),r.length===n)break}return r.length?{label:i.getAttribute(`recents-label`)||t,options:r}:null},teardown(){}}}export{i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./devWarn-DXdRWZs3.js";import{i as t}from"./optionLabel-4xjXWy74.js";import{t as n}from"./customRule-Chp7YwFb.js";import{n as r}from"./WuiSelect-
|
|
1
|
+
import{n as e}from"./devWarn-DXdRWZs3.js";import{i as t}from"./optionLabel-4xjXWy74.js";import{t as n}from"./customRule-Chp7YwFb.js";import{n as r}from"./WuiSelect-BPWPI07i.js";var i=(e,n)=>{let r=n.toLowerCase(),i=e.getAttribute(`value-label`);return i&&String(e.value??``)!==``&&i.toLowerCase()===r?!0:e.options.some(e=>t(e).toLowerCase()===r||String(e.value??``).toLowerCase()===r)};function a(){let t,a,o=0,s,c=null,l=null,u=``,d=null,f=!1,p=()=>r(t),m=()=>typeof t.loadOptions!=`function`&&!t.getAttribute(`source`),h=(e,n,r)=>{let i=t.getAttribute(e);if(i==null||i.trim()===``)return n;let a=Number(i);return r(a)?a:n},g=()=>h(`min-chars`,1,e=>Number.isInteger(e)&&e>=0),_=()=>h(`debounce`,250,e=>Number.isFinite(e)&&e>=0),v=()=>{c?.abort(),c=null};function y(e,n){if(typeof t.loadOptions==`function`)return t.loadOptions(e,{signal:n});let r=t.getAttribute(`source`);if(r===null)throw Error(`search source attribute missing`);let i=`${r}${r.includes(`?`)?`&`:`?`}q=${encodeURIComponent(e)}`;return fetch(i,{signal:n,credentials:`same-origin`,headers:{Accept:`application/json`}}).then(e=>{if(!e.ok)throw Error(`search request failed with status ${e.status}`);return e.json()})}function b(n,r,i){r?(e(`wui-select: search failed`,i),t.setPartOptions([]),t.setStatus(`empty`)):(t.setPartOptions(n),t.setStatus(n.length?`idle`:`empty`))}async function x(e,t,n){let r=[],i=!1,a=null;try{if(r=await y(e,n),!Array.isArray(r))throw TypeError(`search results must be an array`)}catch(e){i=!0,a=e??/* @__PURE__ */ Error(`search failed`)}finally{t===o&&(c=null,b(r,i,a))}}function S(e){let n=o;v(),m()?(f=!0,t.setStatus(`loading`)):(c=new AbortController,t.setStatus(`loading`),x(e,n,c.signal))}let C=(e,n)=>t.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:n}}));function w(e){o+=1,v(),clearTimeout(s),s=void 0,e.trim().length<g()?(t.setPartOptions([]),t.setStatus(`hint`)):(C(e,o),S(e))}return{mount(e,n,r={}){t=e,a=n;let i=a.search?.value??``;a.search&&r.carry?.query&&i===``&&(a.search.value=r.carry.query),i.trim()!==``&&t._onQueryChange(i)},onQuery(e){if(o+=1,v(),clearTimeout(s),s=void 0,u=e,d=null,f=!1,!p())return!1;if(e.trim().length<g())return t.setPartOptions([]),t.setStatus(`hint`),!0;let n=o;return s=setTimeout(()=>{s=void 0,C(e,n),S(e)},_()),!0},onOpen(){if(p()){if(d!==null){let e=d;d=null,w(e)}else g()===0&&t._query.trim()===``&&w(``)}},onOptions(){f&&(f=!1,t.setStatus(t.options.length?`idle`:`empty`))},onBlur(){if(t.mode!==`search`||!t.hasAttribute(`allow-custom`))return!1;let e=(a.search?.value??``).trim();if(!e||e===String(t.value)||i(t,e))return!1;let r=n(t,e);return r?(t.setError(r),!1):(t.commit(e,{isCustom:!0}),!0)},actionRow(e){if(l=null,t.mode===`tag`||!t.hasAttribute(`allow-custom`))return null;let n=e.trim();return!n||i(t,n)?null:(l={position:`bottom`,label:(t.getAttribute(`add-label`)??`Add '{query}'`).replaceAll(`{query}`,n),value:n},l)},onPick(e){if(!l||e.value!==l.value||e.label!==l.label)return!1;let n=l.value;return l=null,t.commit(n,{isCustom:!0}),!0},renderValue(){let e=t.value;if(!e||t.options.some(t=>String(t.value)===String(e)))return!1;let n=t.getAttribute(`value-label`);return n?(a.value.classList.remove(`wui-select-placeholder`),a.value.textContent=n,!0):!1},teardown(){(s!==void 0||c!==null||f)&&(d=u),f=!1,o+=1,clearTimeout(s),s=void 0,v(),l=null}}}export{a as default};
|
package/dist/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,S as t,T as n,_ as r,a as i,b as a,c as o,d as s,f as c,g as l,h as u,i as d,l as f,m as p,n as m,o as h,p as g,r as _,s as v,t as y,u as b,v as x,w as S,x as C,y as w}from"./drawerDiscard-
|
|
1
|
+
import{C as e,S as t,T as n,_ as r,a as i,b as a,c as o,d as s,f as c,g as l,h as u,i as d,l as f,m as p,n as m,o as h,p as g,r as _,s as v,t as y,u as b,v as x,w as S,x as C,y as w}from"./drawerDiscard-Cra-QhD5.js";import{r as T}from"./dom-Do1pAA12.js";import{a as E,c as D,d as O,i as k,l as A,n as j,o as M,r as N,s as P,t as F,u as I}from"./wuiHttp-DGbD7Fra.js";var L=31536e3,R=/* @__PURE__ */ new WeakMap,z=e=>e>99?`99+`:String(e),B=(e,t)=>Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{${t}}`,()=>String(n)),e);function V(e,t,n=document){try{n.cookie=`${e}=${t?`1`:`0`}; Path=/; Max-Age=${L}; SameSite=Lax`}catch(e){if(!(e instanceof DOMException&&e.name===`SecurityError`))throw e}}function H(e,t,n,r=document){try{let i=`${e}=`,a=r.cookie.split(`;`).map(e=>e.trim()).find(e=>e.startsWith(i)),o=new Set(a?a.slice(i.length).split(`.`).filter(Boolean):[]);n?o.add(t):o.delete(t),r.cookie=`${e}=${[...o].join(`.`)}; Path=/; Max-Age=${L}; SameSite=Lax`}catch(e){if(!(e instanceof DOMException&&e.name===`SecurityError`))throw e}}var U=e=>{let t=document.createElement(`template`);return t.innerHTML=e,t.content},W=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},G=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},K=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],q=e=>{if(!(e.target instanceof Element))throw Error(`event target is not an element`);return e.target},J=e=>{let t=e.getAttribute(`href`);if(t===null)throw Error(`search hit has no href`);return t},Y=(e,t)=>{let n=document.createElement(`div`);return n.className=e,n.textContent=t,n};function X(e,t){let n=W(e,`.wui-bell-trigger`,HTMLElement),r=W(e,`.wui-bell-count`,HTMLElement),i=W(e,`[data-wui-bell-live]`,HTMLElement),a=W(e,`[data-wui-bell-list]`,HTMLElement),o=()=>T(a,`bell list missing`),s=W(e,`.wui-bell-menu`,HTMLElement),{src:c,readAction:l}=e.dataset,u=e.dataset.label||`Notifications`,d=e.dataset.emptyText||`You are all caught up.`,f=e.dataset.loadingText??`Loading…`,p=e.dataset.noUnreadText??`No unread notifications`,m=e.dataset.unreadText??`{count} unread notifications`,h=e.dataset.bellLabel??`{label}, {count} unread`,g=Number(e.dataset.pollSeconds??60),_=P(),v=Number(e.dataset.unread)||0,y=(t,a=!0)=>{let o=Math.max(0,Number(t)||0),s=o!==v;v=o,e.dataset.unread=String(o),r&&(r.textContent=z(o),r.hidden=o===0),n?.setAttribute(`aria-label`,o===0?u:B(h,{label:u,count:z(o)})),a&&s&&i&&(i.textContent=o===0?p:B(m,{count:z(o)}))},b=()=>s?.classList.contains(`show`)??!1,x=()=>{let e=Y(`wui-bell-state`,`Could not load notifications. `),t=document.createElement(`button`);t.type=`button`,t.className=`btn btn-link btn-sm`,t.dataset.wuiBellRetry=``,t.textContent=`Retry`,e.append(t),o().replaceChildren(e)},S=async t=>{if(t&&(o().setAttribute(`aria-busy`,`true`),o().querySelector(`.wui-bell-item`)||o().replaceChildren(Y(`wui-bell-state`,f))),c===void 0)throw Error(`bell has no data-src`);let n=await _.run(c);if(n.kind===`aborted`||n.kind===`stale`||n.kind===`session`)return;if(o().removeAttribute(`aria-busy`),!n.ok){t&&x();return}let r=U(n.html),i=W(r,`[data-wui-unread]`,HTMLElement),a=i?Number(i.getAttribute(`data-wui-unread`)):v;y(a),(t||b())&&(r.querySelector(`.wui-bell-item`)?o().replaceChildren(r):o().replaceChildren(Y(`wui-bell-state`,d))),e.dispatchEvent(new CustomEvent(`wui:notifications:loaded`,{bubbles:!0,detail:{unread:a}}))};e.addEventListener(`show.bs.dropdown`,()=>S(!0)),e.addEventListener(`click`,async e=>{let t=q(e);if(t.closest(`[data-wui-bell-retry]`)){await S(!0);return}let n=G(t,`[data-wui-bell-read]`,HTMLButtonElement);if(!n||!l)return;n.disabled=!0;let r=await A(l,{method:`POST`});n.disabled=!1,r.ok&&(y(0),await S(!0))});let C=null,w=()=>{g>0&&C===null&&(C=setInterval(()=>S(b()),g*1e3))},E=()=>{C!==null&&clearInterval(C),C=null},D=()=>{document.hidden?E():(S(b()),w())};return g>0&&(document.addEventListener(`visibilitychange`,D),document.hidden||w()),t.push(()=>{E(),_.abort(),document.removeEventListener(`visibilitychange`,D)}),{setUnread:e=>y(e),refresh:()=>S(b())}}var Z=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),Q=(e,t,n)=>`${e}${e.includes(`?`)?`&`:`?`}${encodeURIComponent(t)}=${encodeURIComponent(n)}`;function ee(e,t){let n=T(W(e,`input.search-input`,HTMLInputElement),`search input missing`),r=W(e,`.wui-topsearch-results`,HTMLElement),i=()=>T(r,`search results missing`),a=W(e,`.wui-topsearch-open`,HTMLElement),o=W(e,`[data-wui-topsearch-live]`,HTMLElement),{src:s,param:c=`q`,resultsHref:l}=e.dataset,u=Number(e.dataset.minChars??2),d=Number(e.dataset.debounceMs??250),f=e.dataset.noResultsText??`No results`,p=e.dataset.resultsCountText??`{count} results`,m=e.dataset.resultCountText??`{count} result`,h=P(),g,_=-1,v=()=>K(i(),`.wui-topsearch-hit`,HTMLElement),y=e=>{let t=v();_=t.length===0?-1:(e+t.length)%t.length,t.forEach((e,t)=>{let n=t===_;e.classList.toggle(`is-active`,n),e.setAttribute(`aria-selected`,n?`true`:`false`)});let r=_>=0?t[_]:void 0;r?(n.setAttribute(`aria-activedescendant`,r.id),r.scrollIntoView?.({block:`nearest`})):n.removeAttribute(`aria-activedescendant`)},b=()=>{i().hidden=!0,n.setAttribute(`aria-expanded`,`false`),n.removeAttribute(`aria-activedescendant`),_=-1},x=()=>{i().hidden=!1,n.setAttribute(`aria-expanded`,`true`)},S=t=>{e.classList.toggle(`is-open`,t),a?.setAttribute(`aria-expanded`,t?`true`:`false`)},C=t=>{let n=new CustomEvent(`wui:search:select`,{bubbles:!0,cancelable:!0,detail:{href:t}});e.dispatchEvent(n)&&window.location.assign(t)},w=async t=>{if(e.classList.add(`is-loading`),s===void 0)throw Error(`search has no data-src`);let n=await h.run(Q(s,c,t));if(n.kind!==`aborted`&&n.kind!==`stale`&&n.kind!==`session`){if(e.classList.remove(`is-loading`),n.ok){let e=U(n.html),t=W(e,`[data-wui-count]`,HTMLElement);i().replaceChildren(e),v().forEach((e,t)=>{e.id=`${i().id}-opt-${t}`});let r=t?Number(t.getAttribute(`data-wui-count`)):v().length;o&&(o.textContent=r===0?f:B(r===1?m:p,{count:r}))}else i().replaceChildren(Y(`wui-topsearch-empty`,`Search is unavailable right now.`));_=-1,x()}};n.addEventListener(`input`,()=>{clearTimeout(g);let t=n.value.trim();t.length<u?(h.abort(),e.classList.remove(`is-loading`),i().replaceChildren(),b()):g=setTimeout(()=>w(t),d)}),n.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`||t.key===`ArrowUp`){if(i().hidden||v().length===0)return;t.preventDefault(),y(_+(t.key===`ArrowDown`?1:-1))}else if(t.key===`Enter`){let e=v(),r=_>=0?e[_]:void 0;!i().hidden&&r?(t.preventDefault(),C(J(r))):l&&n.value.trim()!==``&&(t.preventDefault(),C(Q(l,c,n.value.trim())))}else t.key===`Escape`&&(i().hidden?e.classList.contains(`is-open`)&&(t.preventDefault(),t.stopPropagation(),S(!1),a?.focus()):(t.preventDefault(),t.stopPropagation(),b()))}),i().addEventListener(`click`,e=>{let t=G(q(e),`.wui-topsearch-hit`,HTMLElement);!t||e.ctrlKey||e.metaKey||e.shiftKey||e.button===1||(e.preventDefault(),C(J(t)))}),a?.addEventListener(`click`,()=>{let t=!e.classList.contains(`is-open`);S(t),t&&n.focus()});let E=e=>{e.key!==`/`||e.ctrlKey||e.metaKey||e.altKey||Z(e.target)||(e.preventDefault(),S(!0),n.focus())},D=t=>{t.target instanceof Node&&e.contains(t.target)||(b(),e.classList.contains(`is-open`)&&S(!1))};document.addEventListener(`keydown`,E),document.addEventListener(`pointerdown`,D),t.push(()=>{clearTimeout(g),h.abort(),document.removeEventListener(`keydown`,E),document.removeEventListener(`pointerdown`,D)})}function te(e){let t=[],n=e.dataset.wuiCollapsedCookie;n&&e.addEventListener(`wui:shell:collapse`,e=>{V(n,!!e.detail?.collapsed)});let r=e.dataset.wuiFoldedCookie;r&&e.addEventListener(`wui:shell:nav-fold`,e=>{H(r,e.detail?.key,!!e.detail?.folded)}),e.addEventListener(`click`,t=>{q(t).closest(`[data-wui-tabbar-more]`)&&W(e,`[data-app-shell-menu]`,HTMLElement)?.click()});let i=W(e,`[data-wui-bell]`,HTMLElement),a=i?X(i,t):null,o=W(e,`[data-wui-topsearch]`,HTMLElement);o&&ee(o,t);let s={el:e,setUnread(e){T(a,`WUI.shell: this <app-shell> has no <app-shell-notifications>.`).setUnread(e)},refreshNotifications(){return T(a,`WUI.shell: this <app-shell> has no <app-shell-notifications>.`).refresh()},get collapsed(){return e.classList.contains(`collapsed`)},set collapsed(t){if(!!t===e.classList.contains(`collapsed`))return;let n=W(e,`[data-app-shell-collapse]`,HTMLElement);n?n.click():e.classList.toggle(`collapsed`,!!t)}};R.set(e,s);let c=n=>{if(n.target===e||n.target instanceof Node&&n.target.contains(e)){for(let e of t)e();R.delete(e),delete e.dataset.wuiPartsWired,document.removeEventListener(`wui:teardown`,c)}};return document.addEventListener(`wui:teardown`,c),s}function $(e=document){let t=[];e instanceof HTMLElement&&e.matches(`[data-app-shell]`)&&t.push(e),t.push(...K(e,`[data-app-shell]`,HTMLElement));for(let e of t)e.dataset.wuiPartsWired||(e.dataset.wuiPartsWired=`1`,te(e))}function ne(e){let t=G(e,`[data-app-shell]`,HTMLElement);return t?(R.has(t)||$(t),R.get(t)??null):null}export{f as CONFIRM_DIALOG_ID,b as CONFIRM_TONES,F as CSRF_META_NAME,j as DEFAULT_CSRF_HEADER,y as DISCARD_EVENT,m as DISCARD_TEXT,s as FLASH_STORAGE_KEY,c as FLASH_VARIANTS,N as HTTP_KINDS,g as SERVER_ACTION_TEXT,I as TOAST_ACTION_METHODS,C as TOAST_ACTION_MS,i as UNSAVED_TEXT,k as WUI_HEADERS,E as classifyStatus,l as closeRemotePane,M as configureCsrf,p as confirmAction,_ as createDiscardPrompt,P as createRequestQueue,h as formValues,S as getServerTable,ne as getShell,d as initDrawerDiscard,r as initRemoteModals,u as initServerActions,n as initServerTables,$ as initShellParts,v as initUnsavedChanges,x as loadRemoteDrawer,w as loadRemoteModal,a as loadRemotePane,O as parseToastAction,D as readCsrf,o as resetUnsavedChanges,t as runToastAction,e as showResultToast,A as wuiFetch};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e,t}from"./dom-Do1pAA12.js";import{t as n}from"./devWarn-DXdRWZs3.js";var r=`wui:row-drop`,i=`is-drop-over`,a=`application/x-wui-rows`,o=`wui-row-dragging`,s=`[data-wui-drop-target]`,c=`tbody tr[data-row-key]`,l=`input, button, a, select, textarea, label`,u=`.wui-select-cell .wui-check`,d=/* @__PURE__ */ new WeakMap,f=/* @__PURE__ */ new WeakSet,p=null,m=null;function h(e){let t=e.querySelector(u);return t instanceof HTMLInputElement&&t.checked}function g(e){let t=[];for(let n of e.querySelectorAll(`tbody tr`))n instanceof HTMLElement&&h(n)&&t.push(n.dataset.rowKey);return t}function _(e,n){return t(e,n)}function v(e,t){let n=_(e,t);return n instanceof HTMLElement?n:null}function y(e){let t=e.textContent;if(t===null)throw Error(`A drop target has no text content.`);return t.trim()}var b=e=>typeof e==`object`&&!!e&&`selected`in e&&typeof e.selected==`number`;function x(){p=null,document.body.classList.remove(o);for(let e of document.querySelectorAll(`${s}.${i}`))e.classList.remove(i)}function S(e,t,n){e.dispatchEvent(new CustomEvent(r,{bubbles:!0,detail:{keys:t,target:n.dataset.wuiDropTarget}}))}function C(t){let n=v(t.target,s);if(!n||!p)return;t.preventDefault();let r=e(t.dataTransfer,`A drag event arrived without its DataTransfer.`);r.dropEffect=`move`,n.classList.add(i)}function ee(e){let t=v(e.target,s);!t||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||t.classList.remove(i)}function w(e){let t=v(e.target,s);if(!t||!p)return;e.preventDefault(),t.classList.remove(i);let{root:n,keys:r}=p;S(n,r,t),x()}function T(e){let t=v(e.target,s);t&&m?.keys.length&&(e.preventDefault(),S(m.root,m.keys,t))}function te(e){(e.key===`Enter`||e.key===` `)&&T(e)}function E(e){f.has(e)||(f.add(e),e.addEventListener(`dragover`,C),e.addEventListener(`dragenter`,C),e.addEventListener(`dragleave`,ee),e.addEventListener(`drop`,w),e.addEventListener(`click`,T),e.addEventListener(`keydown`,te))}function D(t){let n=d.get(t);if(n)return n;E(t.ownerDocument||t);let r=e=>{let n=v(e.target,c);if(!n||!t.contains(n))return;let r=_(e.target,l);r&&n.contains(r)||(n.draggable=!0)},i=n=>{let r=v(n.target,c);if(!r||!t.contains(r))return;let i=h(r)?g(t):[r.dataset.rowKey],s=e(n.dataTransfer,`A drag event arrived without its DataTransfer.`);s.setData(a,JSON.stringify(i)),s.setData(`text/plain`,i.join(`,`)),s.effectAllowed=`move`,p={root:t,keys:i},document.body.classList.add(o)},s=e=>{let n=e instanceof CustomEvent?e.detail:void 0;if(b(n)){let{keys:e}=n;n.selected>0?m={root:t,keys:Array.isArray(e)?e:g(t)}:n.selected===0&&(m=null)}O(document)};t.addEventListener(`pointerdown`,r),t.addEventListener(`dragstart`,i),t.addEventListener(`dragend`,x),t.addEventListener(`selectionchange`,s);let u=()=>{t.removeEventListener(`pointerdown`,r),t.removeEventListener(`dragstart`,i),t.removeEventListener(`dragend`,x),t.removeEventListener(`selectionchange`,s),d.delete(t)};return d.set(t,u),u}function O(e=document){let t=e.querySelector(`[data-wui-row-drag] tbody tr ${u}:checked`)!==null;for(let n of e.querySelectorAll(s)){n.tagName!==`BUTTON`&&(n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`)),t?n.removeAttribute(`aria-disabled`):n.setAttribute(`aria-disabled`,`true`);let e=n.getAttribute(`data-wui-drop-label`)||y(n);n.setAttribute(`aria-label`,`Move to ${e}`)}for(let t of e.querySelectorAll(`.wui-drop-tray`))t.hasAttribute(`role`)||(t.setAttribute(`role`,`toolbar`),t.setAttribute(`aria-label`,`Move to`))}var k=[`light`,`dark`,`auto`],ne=[`wave`,`circle`,`slide`,`blinds`,`fade`,`none`],A=`wave`,j=`theme`,M={wave:1100,circle:700,slide:600,blinds:900,fade:350,none:0},N=`wui-theme-switching`,P=`wui:theme:change`,F=`(prefers-color-scheme: dark)`,I=e=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(e).matches,L=e=>k.some(t=>t===e);function R(e){return e===`dark`||e===`auto`&&I(F)?`dark`:`light`}function z(e=j){let t=null;try{t=window.localStorage.getItem(e)}catch{}return L(t)?t:`auto`}function B(e,t=j){try{window.localStorage.setItem(t,e)}catch{}}function V(e){let t=document.documentElement,n=R(e);t.setAttribute(`data-theme`,e),t.setAttribute(`data-bs-theme`,n),document.dispatchEvent(new CustomEvent(P,{detail:{mode:n,preference:e}}))}var H=`(function(k){var m;try{m=localStorage.getItem(k)}catch{m=null}if(m!=='light'&&m!=='dark')m='auto';var r=document.documentElement,q=window.matchMedia?window.matchMedia('(prefers-color-scheme: dark)'):null;function s(){var t=r.getAttribute('data-theme');r.setAttribute('data-bs-theme',t==='auto'?(q&&q.matches?'dark':'light'):t)}r.setAttribute('data-theme',m);s();if(q&&q.addEventListener)q.addEventListener('change',function(){if(r.getAttribute('data-theme')==='auto')s()})})(`;function U(e=j){return`${H}${JSON.stringify(String(e)).replace(/</g,`\\u003c`)})`}function W(e,{includeAuto:t=!1}={}){return e===`light`?`dark`:e===`dark`&&t?`auto`:`light`}function G(e){if(typeof window>`u`||typeof window.matchMedia!=`function`)return()=>{};let t=window.matchMedia(F),n=()=>e(t.matches?`dark`:`light`);return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)}var K=60,q=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,J=e=>e.toFixed(1),Y=(e,t)=>`${J(e)}px ${J(t)}px`,X={amplitude:22,segments:36,cycles:1.5,ripples:2},Z=6,re=(e,t,n,r,i)=>{let{amplitude:a,segments:o,cycles:s}=X,c=n*(t+2*a),l=i?t+a-c:c-a,u=i?t+2*a:-2*a,d=[Y(0,u)];for(let t=0;t<=o;t++){let n=e*t/o,i=l+a*Math.sin(2*Math.PI*s*t/o+r);d.push(Y(n,i))}return d.push(Y(e,u)),`polygon(${d.join(`, `)})`},ie=(e,t,n,r)=>{let i=t/Z,a=[];for(let t=0;t<Z;t++){let o=t*i,s=i*n,c=r?o+i-s:o,l=r?o+i:o+s;a.push(Y(0,c),Y(e,c),Y(e,l),Y(0,l))}return`polygon(${a.join(`, `)})`};function Q(e,{width:t,height:n,to:r=`dark`,origin:i}){let a=r===`dark`,o=[];for(let r=0;r<=K;r++){let s=r/K,c=q(s);switch(e){case`circle`:{let e=i?.x??t/2,r=i?.y??n/2,a=Math.hypot(Math.max(e,t-e),Math.max(r,n-r));o.push({clipPath:`circle(${J(a*c)}px at ${J(e)}px ${J(r)}px)`});break}case`slide`:{let e=n*(1-c);o.push({clipPath:a?`inset(${J(e)}px 0px 0px 0px)`:`inset(0px 0px ${J(e)}px 0px)`});break}case`blinds`:o.push({clipPath:ie(t,n,c,a)});break;case`fade`:o.push({clipPath:`none`,opacity:c});break;case`none`:return[];default:o.push({clipPath:re(t,n,c,s*X.ripples*2*Math.PI,a)})}}return o}var $=e=>{e instanceof DOMException&&(e.name===`AbortError`||e.name===`InvalidStateError`)||n(`[@webority/ui-elements] The theme view transition failed:`,e)};function ae(e,{effect:t=A,to:n,origin:r,duration:i}={}){let a=document.documentElement,o=n!==void 0&&a.getAttribute(`data-bs-theme`)===n;if(t===`none`||o||I(`(prefers-reduced-motion: reduce)`)||typeof document.startViewTransition!=`function`||typeof a.animate!=`function`)return e(),Promise.resolve(!1);a.classList.add(N);let s=document.startViewTransition(e),c=i??M[t]??M.wave;return s.ready.then(()=>{let e=Q(t,{width:window.innerWidth,height:window.innerHeight,to:n,origin:r});a.animate(e,{duration:c,easing:`linear`,fill:`both`,pseudoElement:`::view-transition-new(root)`})}).catch($),s.finished.catch($).finally(()=>a.classList.remove(N)).then(()=>!0)}export{r as _,M as a,V as c,R as d,B as f,G as g,ae as h,ne as i,W as l,Q as m,j as n,k as o,U as p,P as r,N as s,A as t,z as u,D as v,O as y};
|
|
1
|
+
import{r as e,t}from"./dom-Do1pAA12.js";import{t as n}from"./devWarn-DXdRWZs3.js";var r=`wui:row-drop`,i=`is-drop-over`,a=`application/x-wui-rows`,o=`wui-row-dragging`,s=`[data-wui-drop-target]`,c=`tbody tr[data-row-key]`,l=`input, button, a, select, textarea, label`,u=`.wui-select-cell .wui-check`,d=/* @__PURE__ */ new WeakMap,f=/* @__PURE__ */ new WeakSet,p=null,m=null;function h(e){let t=e.querySelector(u);return t instanceof HTMLInputElement&&t.checked}function g(e){let t=[];for(let n of e.querySelectorAll(`tbody tr`))n instanceof HTMLElement&&h(n)&&t.push(n.dataset.rowKey);return t}function _(e,n){return t(e,n)}function v(e,t){let n=_(e,t);return n instanceof HTMLElement?n:null}function y(e){let t=e.textContent;if(t===null)throw Error(`A drop target has no text content.`);return t.trim()}var b=e=>typeof e==`object`&&!!e&&`selected`in e&&typeof e.selected==`number`;function x(){p=null,document.body.classList.remove(o);for(let e of document.querySelectorAll(`${s}.${i}`))e.classList.remove(i)}function S(e,t,n){e.dispatchEvent(new CustomEvent(r,{bubbles:!0,detail:{keys:t,target:n.dataset.wuiDropTarget}}))}function C(t){let n=v(t.target,s);if(!n||!p)return;t.preventDefault();let r=e(t.dataTransfer,`A drag event arrived without its DataTransfer.`);r.dropEffect=`move`,n.classList.add(i)}function ee(e){let t=v(e.target,s);!t||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||t.classList.remove(i)}function w(e){let t=v(e.target,s);if(!t||!p)return;e.preventDefault(),t.classList.remove(i);let{root:n,keys:r}=p;S(n,r,t),x()}function T(e){let t=v(e.target,s);t&&m?.keys.length&&(e.preventDefault(),S(m.root,m.keys,t))}function te(e){(e.key===`Enter`||e.key===` `)&&T(e)}function E(e){f.has(e)||(f.add(e),e.addEventListener(`dragover`,C),e.addEventListener(`dragenter`,C),e.addEventListener(`dragleave`,ee),e.addEventListener(`drop`,w),e.addEventListener(`click`,T),e.addEventListener(`keydown`,te))}function D(t){let n=d.get(t);if(n)return n;E(t.ownerDocument||t);let r=e=>{let n=v(e.target,c);if(!n||!t.contains(n))return;let r=_(e.target,l);r&&n.contains(r)||(n.draggable=!0)},i=n=>{let r=v(n.target,c);if(!r||!t.contains(r))return;let i=h(r)?g(t):[r.dataset.rowKey],s=e(n.dataTransfer,`A drag event arrived without its DataTransfer.`);s.setData(a,JSON.stringify(i)),s.setData(`text/plain`,i.join(`,`)),s.effectAllowed=`move`,p={root:t,keys:i},document.body.classList.add(o)},s=e=>{let n=e instanceof CustomEvent?e.detail:void 0;if(b(n)){let{keys:e}=n;n.selected>0?m={root:t,keys:Array.isArray(e)?e:g(t)}:n.selected===0&&(m=null)}O(document)};t.addEventListener(`pointerdown`,r),t.addEventListener(`dragstart`,i),t.addEventListener(`dragend`,x),t.addEventListener(`selectionchange`,s);let u=()=>{t.removeEventListener(`pointerdown`,r),t.removeEventListener(`dragstart`,i),t.removeEventListener(`dragend`,x),t.removeEventListener(`selectionchange`,s),d.delete(t)};return d.set(t,u),u}function O(e=document){let t=e.querySelector(`[data-wui-row-drag] tbody tr ${u}:checked`)!==null;for(let n of e.querySelectorAll(s)){n.tagName!==`BUTTON`&&(n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`)),t?n.removeAttribute(`aria-disabled`):n.setAttribute(`aria-disabled`,`true`);let e=n.getAttribute(`data-wui-drop-label`)||y(n);n.setAttribute(`aria-label`,`Move to ${e}`)}for(let t of e.querySelectorAll(`.wui-drop-tray`))t.hasAttribute(`role`)||(t.setAttribute(`role`,`toolbar`),t.setAttribute(`aria-label`,`Move to`))}var k=[`light`,`dark`,`auto`],ne=[`wave`,`circle`,`slide`,`blinds`,`fade`,`none`],A=`wave`,j=`theme`,M={wave:1100,circle:700,slide:600,blinds:900,fade:350,none:0},N=`wui-theme-switching`,P=`wui:theme:change`,F=`(prefers-color-scheme: dark)`,I=e=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(e).matches,L=e=>k.some(t=>t===e);function R(e){return e===`dark`||e===`auto`&&I(F)?`dark`:`light`}function z(e=j){let t=null;try{t=window.localStorage.getItem(e)}catch(e){if(!(e instanceof DOMException))throw e}return L(t)?t:`auto`}function B(e,t=j){try{window.localStorage.setItem(t,e)}catch(e){if(!(e instanceof DOMException))throw e}}function V(e){let t=document.documentElement,n=R(e);t.setAttribute(`data-theme`,e),t.setAttribute(`data-bs-theme`,n),document.dispatchEvent(new CustomEvent(P,{detail:{mode:n,preference:e}}))}var H=`(function(k){var m;try{m=localStorage.getItem(k)}catch{m=null}if(m!=='light'&&m!=='dark')m='auto';var r=document.documentElement,q=window.matchMedia?window.matchMedia('(prefers-color-scheme: dark)'):null;function s(){var t=r.getAttribute('data-theme');r.setAttribute('data-bs-theme',t==='auto'?(q&&q.matches?'dark':'light'):t)}r.setAttribute('data-theme',m);s();if(q&&q.addEventListener)q.addEventListener('change',function(){if(r.getAttribute('data-theme')==='auto')s()})})(`;function U(e=j){return`${H}${JSON.stringify(String(e)).replace(/</g,`\\u003c`)})`}function W(e,{includeAuto:t=!1}={}){return e===`light`?`dark`:e===`dark`&&t?`auto`:`light`}function G(e){if(typeof window>`u`||typeof window.matchMedia!=`function`)return()=>{};let t=window.matchMedia(F),n=()=>e(t.matches?`dark`:`light`);return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)}var K=60,q=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,J=e=>e.toFixed(1),Y=(e,t)=>`${J(e)}px ${J(t)}px`,X={amplitude:22,segments:36,cycles:1.5,ripples:2},Z=6,re=(e,t,n,r,i)=>{let{amplitude:a,segments:o,cycles:s}=X,c=n*(t+2*a),l=i?t+a-c:c-a,u=i?t+2*a:-2*a,d=[Y(0,u)];for(let t=0;t<=o;t++){let n=e*t/o,i=l+a*Math.sin(2*Math.PI*s*t/o+r);d.push(Y(n,i))}return d.push(Y(e,u)),`polygon(${d.join(`, `)})`},ie=(e,t,n,r)=>{let i=t/Z,a=[];for(let t=0;t<Z;t++){let o=t*i,s=i*n,c=r?o+i-s:o,l=r?o+i:o+s;a.push(Y(0,c),Y(e,c),Y(e,l),Y(0,l))}return`polygon(${a.join(`, `)})`};function Q(e,{width:t,height:n,to:r=`dark`,origin:i}){let a=r===`dark`,o=[];for(let r=0;r<=K;r++){let s=r/K,c=q(s);switch(e){case`circle`:{let e=i?.x??t/2,r=i?.y??n/2,a=Math.hypot(Math.max(e,t-e),Math.max(r,n-r));o.push({clipPath:`circle(${J(a*c)}px at ${J(e)}px ${J(r)}px)`});break}case`slide`:{let e=n*(1-c);o.push({clipPath:a?`inset(${J(e)}px 0px 0px 0px)`:`inset(0px 0px ${J(e)}px 0px)`});break}case`blinds`:o.push({clipPath:ie(t,n,c,a)});break;case`fade`:o.push({clipPath:`none`,opacity:c});break;case`none`:return[];default:o.push({clipPath:re(t,n,c,s*X.ripples*2*Math.PI,a)})}}return o}var $=e=>{e instanceof DOMException&&(e.name===`AbortError`||e.name===`InvalidStateError`)||n(`[@webority/ui-elements] The theme view transition failed:`,e)};function ae(e,{effect:t=A,to:n,origin:r,duration:i}={}){let a=document.documentElement,o=n!==void 0&&a.getAttribute(`data-bs-theme`)===n;if(t===`none`||o||I(`(prefers-reduced-motion: reduce)`)||typeof document.startViewTransition!=`function`||typeof a.animate!=`function`)return e(),Promise.resolve(!1);a.classList.add(N);let s=document.startViewTransition(e),c=i??M[t]??M.wave;return s.ready.then(()=>{let e=Q(t,{width:window.innerWidth,height:window.innerHeight,to:n,origin:r});a.animate(e,{duration:c,easing:`linear`,fill:`both`,pseudoElement:`::view-transition-new(root)`})}).catch($),s.finished.catch($).finally(()=>a.classList.remove(N)).then(()=>!0)}export{r as _,M as a,V as c,R as d,B as f,G as g,ae as h,ne as i,W as l,Q as m,j as n,k as o,U as p,P as r,N as s,A as t,z as u,D as v,O as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=globalThis.WeborityUiElementsInternal?.version;if(r!==`0.
|
|
1
|
+
(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=globalThis.WeborityUiElementsInternal?.version;if(r!==`0.154.0`)throw Error(`[webority-ui] carousel expects ui-elements 0.154.0 but the page loaded `+r+`.`);var i=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`}),a=120,o=class extends n.ElementBase{_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(),a)},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 e>0?e: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`)}let t=Number.parseInt(e,10);return t>=1?t: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((t,n)=>{let r=i.slide(n+1,e.length);t.getAttribute(`aria-label`)!==r&&t.setAttribute(`aria-label`,r)}),e.length}_refresh(){let e=this._label();this._perView=this._perViewNow();let t=Math.max(1,Math.ceil(e/this._perView)),n=this.querySelector(`.wui-carousel-dots`);if(n&&n.children.length!==t){let e=this.getAttribute(`dot-label`)||i.dot;n.replaceChildren(...Array.from({length:t},(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=t,this._page=Math.min(this._page,t-1),this.toggleAttribute(`data-single`,t<=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 t=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(!t&&this._page===0)),this.querySelector(`.wui-carousel-next`)?.setAttribute(`aria-disabled`,String(!t&&this._page===this._pages-1));let n=this._slides().length,r=this._start(this._page)+1,a=Math.min(n,r+this._perView-1),o=i.status(r,a,n);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(),t=this.querySelector(`.wui-carousel-pause`);if(t instanceof HTMLElement){t.hidden=e===0||this._pages<=1||!!this._motion?.matches;let n=this._paused?this.getAttribute(`play-label`)||i.play:this.getAttribute(`pause-label`)||i.pause,r=t.querySelector(`.wui-carousel-pause-text`);r&&r.textContent!==n&&(r.textContent=n),this.toggleAttribute(`data-paused`,this._paused)}this._playing()&&(this._timer=setTimeout(this._tick,e))}};(0,t.defineElement)(`wui-carousel`,o),e.WuiCarousel=o})(this.WeborityUiElements=this.WeborityUiElements||{},WeborityUiElementsInternal.modules.defineElement,WeborityUiElementsInternal.modules.elementBase);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=globalThis.WeborityUiElementsInternal?.version;if(o!==`0.
|
|
1
|
+
(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=globalThis.WeborityUiElementsInternal?.version;if(o!==`0.154.0`)throw Error(`[webority-ui] code-block expects ui-elements 0.154.0 but the page loaded `+o+`.`);Object.freeze([`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`]);var s=Object.freeze({text:``,json:`JSON`,js:`JavaScript`,cs:`C#`,sql:`SQL`,bash:`Bash`,http:`HTTP`,html:`HTML`,css:`CSS`}),c=e=>RegExp(`\\b(?:${e.join(`|`)})\\b`),l=`(?![\\s\\S])`,u=RegExp(`/\\*[\\s\\S]*?(?:\\*/|${l})`).source,d=[[`attr`,/"(?:[^"\\\n]|\\.)*"(?=\s*:)/],[`string`,/"(?:[^"\\\n]|\\.)*"?/],[`number`,/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/],[`literal`,c([`true`,`false`,`null`])],[`punct`,/[{}[\],:]/]],f=[[`comment`,RegExp(`//[^\\n]*|${u}`)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?/],[`number`,/\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?n?)\b/],[`keyword`,c(`async.await.break.case.catch.class.const.continue.default.delete.do.else.export.extends.finally.for.from.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.yield`.split(`.`))],[`literal`,c([`true`,`false`,`null`,`undefined`,`NaN`,`Infinity`])],[`function`,/(?<![\w$])[A-Za-z_$][\w$]*(?=\s*\()/],[`type`,/(?<![\w$])[A-Z][\w$]*/],[`punct`,/[{}()[\];,]/]],p=[[`comment`,RegExp(`//[^\\n]*|${u}`)],[`string`,/@"(?:[^"]|"")*"?|\$@?"(?:[^"\\\n]|\\.)*"?|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`number`,/\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?[fFdDmMlLuU]{0,2}\b/],[`keyword`,c(`abstract.as.async.await.base.bool.break.byte.case.catch.char.checked.class.const.continue.decimal.default.delegate.do.double.else.enum.event.explicit.extern.finally.fixed.float.for.foreach.get.goto.if.implicit.in.init.int.interface.internal.is.lock.long.namespace.new.object.operator.out.override.params.private.protected.public.readonly.record.ref.required.return.sbyte.sealed.set.short.sizeof.static.string.struct.switch.this.throw.try.typeof.uint.ulong.unchecked.unsafe.ushort.using.var.virtual.void.volatile.when.while.with`.split(`.`))],[`literal`,c([`true`,`false`,`null`])],[`function`,/(?<!\w)[A-Za-z_]\w*(?=\s*\()/],[`type`,/(?<!\w)[A-Z]\w*/],[`punct`,/[{}()[\];,]/]],m=[[`comment`,RegExp(`--[^\\n]*|${u}`)],[`string`,/'(?:[^']|'')*'?/],[`variable`,/@@?\w+/],[`number`,/\b\d+(?:\.\d+)?\b/],[`keyword`,c(`add.all.alter.and.as.asc.begin.between.by.case.check.column.commit.constraint.create.cross.database.declare.default.delete.desc.distinct.drop.else.end.exec.execute.exists.foreign.from.full.function.group.having.if.in.index.inner.insert.into.is.join.key.left.like.limit.not.null.offset.on.or.order.outer.over.partition.primary.procedure.references.return.returns.right.rollback.select.set.table.then.top.transaction.union.unique.update.values.view.when.where.while.with`.split(`.`))],[`literal`,c([`true`,`false`])],[`type`,c([`bigint`,`bit`,`char`,`date`,`datetime`,`datetime2`,`decimal`,`float`,`int`,`money`,`nchar`,`numeric`,`nvarchar`,`real`,`smallint`,`text`,`time`,`tinyint`,`uniqueidentifier`,`varchar`])],[`function`,/\b[A-Za-z_]\w*(?=\s*\()/],[`punct`,/[(),;]/]],h=[[`comment`,/(?<![^\s;|&(])#[^\n]*/],[`string`,/"(?:[^"\\]|\\[\s\S])*"?|'[^']*'?/],[`variable`,/\$(?:\{[^}\n]*\}?|[A-Za-z_]\w*|[0-9@#?$!*-])/],[`attr`,/(?<![\w-])--?[A-Za-z][\w-]*/],[`number`,/(?<![\w.-])\d+(?:\.\d+)?\b/],[`keyword`,c([`case`,`do`,`done`,`elif`,`else`,`esac`,`exit`,`export`,`fi`,`for`,`function`,`if`,`in`,`local`,`return`,`select`,`then`,`until`,`while`])],[`function`,c(`awk.az.cat.cd.chmod.chown.cp.curl.docker.dotnet.echo.gcloud.git.grep.kubectl.ls.mkdir.mv.npm.npx.pnpm.rm.sed.source.sudo.wget`.split(`.`))],[`punct`,/[|&;<>(){}[\]]+/]],g=[[`comment`,/^#[^\n]*/m],[`keyword`,/^(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(?= )/m],[`literal`,/HTTP\/\d(?:\.\d)?/],[`number`,/(?<=^HTTP\/\d(?:\.\d)? )\d{3}\b/m],[`function`,/(?<=^[A-Z]+ )\S+/m],[`attr`,/^[A-Za-z][\w-]*(?=:)/m],[`string`,/(?<=^[A-Za-z][\w-]*:[ \t]*)[^\n]+/m]],_=[[`comment`,RegExp(`<!--[\\s\\S]*?(?:-->|${l})`)],[`keyword`,/<![A-Za-z][^>]*>?/],[`tag`,/<\/?[A-Za-z][^<>]*>?/],[`literal`,/&#?\w+;/]],v={json:d,js:f,cs:p,sql:m,bash:h,http:g,css:[[`comment`,new RegExp(u)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`keyword`,/@[\w-]+|!important/],[`attr`,/[\w-]+(?=\s*:[^{};]*[;}])/],[`number`,/#[0-9a-fA-F]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:%|[A-Za-z]{1,4})?/],[`function`,/[\w-]+(?=\()/],[`type`,/[.#](?!\d)[A-Za-z_][\w-]*/],[`punct`,/[{}();:,]/]],html:_,htmlTag:[[`tag`,/^<\/?[\w:.-]+/],[`string`,/"[^"]*"?|'[^']*'?/],[`attr`,/(?<=\s)[^\s=<>/"']+/],[`punct`,/\/?>|=/]]},y=e=>Object.hasOwn(v,e),b=new Map;function x(e){let t=b.get(e);if(!t){let n=v[e],r=e===`sql`?`gi`:`g`,i=n.map(([,e])=>`(${e.source})`).join(`|`);t={re:new RegExp(i,`${r}m`),types:n.map(([e])=>e)},b.set(e,t)}return t}function S(e,t,n){if(!n)return;let r=e[e.length-1];r&&r[0]===t?r[1]+=n:e.push([t,n])}function C(e,t,n=[]){let{re:r,types:i}=x(e),a=0;for(let o of t.matchAll(r)){let r=o[0];if(!r)continue;S(n,`plain`,t.slice(a,o.index));let s=i.findIndex((e,t)=>o[t+1]!==void 0);e===`html`&&i[s]===`tag`?C(`htmlTag`,r,n):S(n,i[s]??`plain`,r),a=o.index+r.length}return S(n,`plain`,t.slice(a)),n}function w(e){let t=/\r?\n\r?\n/.exec(e);if(!t)return C(`http`,e);let n=t[0]??``,r=C(`http`,e.slice(0,t.index+n.length)),i=e.slice(t.index+n.length),a=i.trimStart()[0];return a===`{`||a===`[`?C(`json`,i,r):a===`<`?C(`html`,i,r):(S(r,`plain`,i),r)}function T(e,t){let n=String(e??``);return!n||n.length>1e5?n?[[`plain`,n]]:[]:t===`http`?w(n):!y(t)||t===`htmlTag`?[[`plain`,n]]:C(t,n)}function E(e,t){let n=[],r=[n];for(let[i,a]of T(e,t))a.split(/\r\n|\r|\n/).forEach((e,t)=>{t>0&&(n=[],r.push(n)),e&&n.push([i,e])});return r.length>1&&n.length===0&&r.pop(),r}function D(e){return Object.hasOwn(s,e)}var O=class extends i.ElementBase{_title;_view;_codeEl;_copyIcon;_copyText;_chrome=null;_copied=!1;_observer=null;_timer=0;_cancelFrame=null;constructor(){super();let e=this.ownerDocument;this._title=e.createElement(`span`),this._title.className=`wui-code-title`,this._view=e.createElement(`div`),this._codeEl=e.createElement(`code`),this._copyIcon=e.createElement(`span`),this._copyIcon.className=`wui-code-copy-icon`,this._copyText=e.createElement(`span`)}static get observedAttributes(){return[`language`,`line-numbers`,`wrap`,`label`,`copy-label`,`copied-label`]}connectedCallback(){this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._chrome?.contains(e.target))&&this._schedule()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._cancelPending()}attributeChangedCallback(){this.isConnected&&this._render()}_source(){return Array.from(this.children).find(e=>e.classList.contains(`wui-code-source`))}_code(){return(this._source()?.textContent??``).replace(/\r?\n$/,``)}_schedule(){if(this._cancelFrame)return;let e=()=>{this._cancelFrame=null,this._render()};if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(e);this._cancelFrame=()=>cancelAnimationFrame(t)}else{let t=!0;queueMicrotask(()=>{t&&e()}),this._cancelFrame=()=>{t=!1}}}_cancelPending(){this._cancelFrame?.(),this._cancelFrame=null}_render(){if(!this._source())return;this._cancelPending();let e=this.ownerDocument;this._chrome||this._build(e);let t=this.getAttribute(`language`),n=t!==null&&D(t)?t:`text`,r=this.getAttribute(`label`)||``,i=E(this._code(),n);this._title.textContent=r||s[n],this._view.setAttribute(`aria-label`,r||`Code`),this._view.style.setProperty(`--wui-code-digits`,String(String(i.length).length)),this._codeEl.replaceChildren(...i.map(t=>k(e,t))),this._copied||(this._copyText.textContent=this._copyLabel()),this.setAttribute(`data-wui-ready`,``),this._observer?.takeRecords()}_build(e){let t=e.createElement(`div`);t.className=`wui-code-chrome`,t.append(this._bar(e));let n=this._view;n.className=`wui-code-view`,n.setAttribute(`role`,`region`),n.tabIndex=0;let r=e.createElement(`pre`);r.className=`wui-code-pre`,r.append(this._codeEl),n.append(r),t.append(n),this._chrome=t,this.append(t)}_bar(e){let t=e.createElement(`div`);t.className=`wui-code-bar`;let i=e.createElement(`button`);return i.type=`button`,i.className=`${(0,n.buttonClass)(`primary`,`ghost`,`sm`)} wui-code-copy`,i.dataset.wui=n.APP_BUTTON_MARKER,i.setAttribute(`aria-live`,`polite`),this._setCopied(!1),i.append(this._copyIcon,this._copyText),i.addEventListener(`click`,async()=>{await(0,r.copyTextToClipboard)(this._code())&&(this._setCopied(!0),clearTimeout(this._timer),this._timer=window.setTimeout(()=>this._setCopied(!1),r.COPY_FEEDBACK_MS))}),t.append(this._title,i),t}_setCopied(e){this._copied=e,this._copyIcon.innerHTML=(0,a.glyphSvg)(e?`check`:`files`,{size:14}),this._copyText.textContent=this._copyLabel()}_copyLabel(){return this._copied?this.getAttribute(`copied-label`)||`Copied`:this.getAttribute(`copy-label`)||`Copy`}};function k(e,t){let n=e.createElement(`span`);n.className=`wui-code-line`;for(let[r,i]of t){if(r===`plain`){n.append(i);continue}let t=e.createElement(`span`);t.className=`wui-code-t-${r}`,t.textContent=i,n.append(t)}return n}(0,t.defineElement)(`wui-code-block`,O),e.WuiCodeBlock=O})(this.WeborityUiElements=this.WeborityUiElements||{},WeborityUiElementsInternal.modules.defineElement,WeborityUiElementsInternal.modules.buttonClass,WeborityUiElementsInternal.modules.copyText,WeborityUiElementsInternal.modules.elementBase,WeborityUiElementsInternal.modules.iconGlyphs);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=globalThis.WeborityUiElementsInternal?.version;if(a!==`0.
|
|
2
|
-
`),a=i!==this._lastIds;this._lastIds=i;let o=!n&&(this._userChose||!a)?r.find(e=>e.id===this._activeId):null;o||(this._userChose=!1,this._setKeyboard(!1)),this._setActive(o??r[0]??null,n)}_input(){let e=this.querySelector(`[role="combobox"]`);return e instanceof HTMLInputElement?e:null}_optionFrom(e,t=!1){let n=h(e,o);return n&&this.contains(n)&&!this._isHidden(n)&&(t||!this._isDisabled(n))?n:null}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_isHidden(e){return e.hidden!==!1||(h(e,`[role="group"]`)?.hidden??!1)!==!1}_selectableOptions(){return _(this,o,HTMLElement).filter(e=>!this._isHidden(e)&&!this._isDisabled(e))}_setActive(e,t){this._activeId=e?e.id:null;for(let t of _(this,o,HTMLElement))t.setAttribute(`aria-selected`,t===e?`true`:`false`);let n=this._input();n&&(e?n.setAttribute(`aria-activedescendant`,e.id):n.removeAttribute(`aria-activedescendant`)),e&&t&&e.scrollIntoView({block:`nearest`})}_move(e){let t=this._selectableOptions();if(!t.length)return;let n=t.findIndex(e=>e.id===this._activeId),r=n<0?e>0?0:t.length-1:(n+e+t.length)%t.length;this._userChose=!0,this._setKeyboard(!0),this._setActive(t[r]??null,!0)}_setKeyboard(e){this.toggleAttribute(`data-keyboard`,e)}_handleKeyDown(e){let t=this._input();if(t&&e.target===t){if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),this._move(e.key===`ArrowDown`?1:-1);else if(e.key===`Tab`&&this._groupActive()&&this._tabs().length)e.preventDefault(),this._cycleGroup(e.shiftKey?-1:1);else if(e.key===`Backspace`&&!e.isComposing&&this._path.length&&!t.value)e.preventDefault(),this._goTo(this._path.slice(0,-1));else if(e.key===`Enter`&&!e.isComposing){let t=this._selectableOptions().find(e=>e.id===this._activeId);if(!t)return;e.preventDefault(),this._select(t)}}}_select(e){this._remember(e),this.dispatchEvent(new CustomEvent(`wui-command-palette:select`,{bubbles:!0,cancelable:!0,detail:{key:e.dataset.key??null,groupKey:e.dataset.groupKey??null,id:e.id}}))&&(e.dataset.opens?this._open(e.dataset.opens):e.dataset.href&&this._navigate(e.dataset.href))}_open(e){let t=_(this,`.wui-cmd-page`,HTMLElement).find(t=>t.dataset.page===e);this._goTo([...this._path,{key:e,label:t?.dataset.label??e}])}_goTo(e){this._input()?.focus(),this.dispatchEvent(new CustomEvent(`wui-command-palette:navigate`,{bubbles:!0,cancelable:!0,detail:{path:e}}))&&(this._path=e,this._restart())}_tabs(){return _(this,p,HTMLElement)}_groupActive(){return this.hasAttribute(`group-filter`)&&this._path.length===0}_pickGroup(e){this._group=e,this._applyFilter(),this.refresh()}_cycleGroup(e){let t=this._tabs().map(e=>e.dataset.groupTab||null),n=Math.max(0,t.indexOf(this._group));this._pickGroup(t[(n+e+t.length)%t.length]??null)}_syncTabs(){if(!this.hasAttribute(`group-filter`))return;let e=g(this,`.wui-cmd-tabs`,HTMLElement);e&&(e.hidden=!this._groupActive());for(let e of this._tabs())e.setAttribute(`aria-selected`,String((e.dataset.groupTab||null)===this._group))}_restart(){this._group=null;let e=this._input();e&&(e.value=``),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}_reset(){this.hasAttribute(`path`)||(this._path=[],this._restart())}_readPath(){let e=this.getAttribute(`path`);if(e==null)return;let t=JSON.parse(e);this._path=Array.isArray(t)?t.filter(e=>e&&typeof e.key==`string`&&typeof e.label==`string`):[]}_renderCrumbs(){let e=g(this,`.wui-cmd-crumbs`,HTMLElement);if(!e)return;let t=this.getAttribute(`root-label`)??c,n=JSON.stringify([t,this._path]);if(e.hidden=this._path.length===0,n===this._crumbSig)return;this._crumbSig=n;let r=g(e,`.wui-cmd-trail`,HTMLElement);if(!r)return;let i=[t,...this._path.map(e=>e.label)];r.replaceChildren(...i.map((e,t)=>{let n=document.createElement(`li`),r=t===i.length-1,a=document.createElement(r?`span`:`button`);if(a.className=`wui-cmd-crumb`,a.textContent=e,r)a.setAttribute(`aria-current`,`page`);else{if(!(a instanceof HTMLButtonElement))throw Error(`breadcrumb button missing`);a.type=`button`,a.dataset.depth=String(t)}return n.append(a),n}))}_recentsHost(){return g(this,`.wui-cmd-recents`,HTMLElement)}_realOptions(){let e=this._recentsHost();return _(this,o,HTMLElement).filter(t=>!e?.contains(t))}_recentEntries(){let e=this.getAttribute(`recents-key`);if(!e)return[];let t;try{t=JSON.parse(globalThis.localStorage?.getItem(e)??`[]`)}catch{return[]}return Array.isArray(t)?t.filter(e=>e&&typeof e.g==`string`&&typeof e.k==`string`):[]}_recentsLimit(){let e=Number.parseInt(this.getAttribute(`recents-limit`)??``,10);return Number.isFinite(e)&&e>0?Math.min(e,d):u}_remember(e){let t=this.getAttribute(`recents-key`),{groupKey:n,key:r,opens:i}=e.dataset;if(!t||i||n==null||r==null)return;let a=[{g:n,k:r},...this._recentEntries().filter(e=>e.g!==n||e.k!==r)];try{globalThis.localStorage?.setItem(t,JSON.stringify(a.slice(0,this._recentsLimit())))}catch{}}_renderRecents(){let e=this._recentsHost();if(!e)return;let t=this._input(),n=this._groupActive()?this._group:null,r=this._path.length===0&&!(t?.value??``).trim()?this._recentEntries().filter(e=>!n||e.g===n):[],i=this._realOptions(),a=[];for(let e of r){let t=i.find(t=>t.dataset.groupKey===e.g&&t.dataset.key===e.k);if(t&&!t.dataset.opens&&!this._isDisabled(t)&&a.push(t),a.length>=this._recentsLimit())break}if(!a.length){e.firstChild&&e.replaceChildren();return}let o=`${this._recentsId}-label`,s=document.createElement(`div`);s.className=`wui-cmd-group`,s.setAttribute(`role`,`group`),s.setAttribute(`aria-labelledby`,o);let c=document.createElement(`div`);c.className=`wui-cmd-group-label`,c.setAttribute(`role`,`presentation`),c.id=o,c.textContent=this.getAttribute(`recents-label`)??l,s.append(c);for(let e of a){let t=e.cloneNode(!0);if(!(t instanceof HTMLElement))throw Error(`recent option copy is not an element`);t.id=`${this._recentsId}-${e.id}`,t.hidden=!1,t.removeAttribute(`aria-selected`),s.append(t)}e.replaceChildren(s)}_inScope(e,t){return!t||(h(e,`.wui-cmd-page`)?.dataset.page??null)===(this._path.at(-1)?.key??null)}_navigate(e){window.location.assign(e)}_applyFilter(){let e=this._input(),t=(e?e.value:``).trim(),n=t.toLowerCase(),a=this.highlight,s=_(this,`.wui-cmd-page`,HTMLElement),c=s.length>0,l=this._path.at(-1)?.key??null;for(let e of s)e.hidden=e.dataset.page!==l;let u=this._groupActive()?this._group:null,d=0;for(let e of this._realOptions()){let o=g(e,`.wui-cmd-item-label`,HTMLElement),s=e.dataset.label??o?.textContent??``,l=(e.dataset.keywords??``).split(/\s+/).filter(Boolean),f=!n||s.toLowerCase().includes(n)||l.some(e=>e.toLowerCase().includes(n)),p=this._inScope(e,c)&&(!u||e.dataset.groupKey===u)&&f;e.hidden=!p,p&&d++,o&&(o.innerHTML=(0,i.matchSegments)(s,a?t:``).map(e=>e.match?`<mark class="wui-cmd-mark">${(0,r.escapeHtml)(e.text)}</mark>`:(0,r.escapeHtml)(e.text)).join(``))}let f=this._recentsHost();for(let e of _(this,`[role="group"]`,HTMLElement))f?.contains(e)||(e.hidden=!_(e,o,HTMLElement).some(e=>!e.hidden));let p=g(this,`[role="listbox"]`,HTMLElement);p&&(p.hidden=d===0);let m=g(this,`.wui-cmd-empty`,HTMLElement);m&&(m.textContent=n&&d===0?this.emptyText:``)}_teardown(){this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`mousedown`,this._onMouseDown),this.removeEventListener(`mousemove`,this._onMouseMove),this.removeEventListener(`input`,this._onInput),this._modal?.removeEventListener(`hidden.bs.modal`,this._onModalHidden),this._modal=null}};(0,t.defineElement)(`wui-command-palette`,v),e.WuiCommandPalette=v})(this.WeborityUiElements=this.WeborityUiElements||{},WeborityUiElementsInternal.modules.defineElement,WeborityUiElementsInternal.modules.elementBase,WeborityUiElementsInternal.modules.optionLabel,WeborityUiElementsInternal.modules.textMatch);
|
|
1
|
+
(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=globalThis.WeborityUiElementsInternal?.version;if(a!==`0.154.0`)throw Error(`[webority-ui] command-palette expects ui-elements 0.154.0 but the page loaded `+a+`.`);var o=`[role="option"]`,s=`No results`,c=`All`,l=`Recent`,u=5,d=20,f=`.wui-cmd-back, [data-depth]`,p=`[data-group-tab]`,m=0;function h(e,t){if(!(e instanceof Element))return null;let n=e.closest(t);return n instanceof HTMLElement?n:null}var g=(e,t,n)=>{let r=e.querySelector(t);return r instanceof n?r:null},_=(e,t,n)=>[...e.querySelectorAll(t)].filter(e=>e instanceof n),v=class extends n.ElementBase{_path;_group;_crumbSig;_modal;_recentsId;_onModalHidden;_activeId;_lastQuery;_lastIds;_userChose;_onKeyDown;_onClick;_onMouseDown;_onMouseMove;_onInput;static get observedAttributes(){return[`filter`,`group-filter`,`highlight`,`empty-text`,`path`,`root-label`,`recents-key`,`recents-limit`,`recents-label`]}constructor(){super(),this._path=[],this._group=null,this._crumbSig=null,this._modal=null,this._recentsId=`wui-cmd-recents-${++m}`,this._onModalHidden=()=>{this._setKeyboard(!1),this._reset()},this._activeId=null,this._lastQuery=null,this._lastIds=null,this._userChose=!1,this._onKeyDown=e=>this._handleKeyDown(e),this._onClick=e=>{let t=h(e.target,f);if(t&&this.contains(t)){let e=t.matches(`.wui-cmd-back`)?this._path.length-1:Number(t.dataset.depth);this._goTo(this._path.slice(0,e));return}let n=h(e.target,p);if(n&&this.contains(n)){this._pickGroup(n.dataset.groupTab||null);return}let r=this._optionFrom(e.target);r&&this._select(r)},this._onMouseDown=e=>{let t=h(e.target,f),n=h(e.target,p);(t&&this.contains(t)||n&&this.contains(n)||this._optionFrom(e.target,!0))&&e.preventDefault()},this._onMouseMove=e=>{let t=this._optionFrom(e.target);t&&t.id!==this._activeId&&(this._setKeyboard(!1),this._userChose=!0,this._setActive(t,!1))},this._onInput=e=>{this.hasAttribute(`filter`)&&e.target===this._input()&&(this._group=null,this._applyFilter(),this.refresh())}}connectedCallback(){this._teardown(),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`click`,this._onClick),this.addEventListener(`mousedown`,this._onMouseDown),this.addEventListener(`mousemove`,this._onMouseMove),this.addEventListener(`input`,this._onInput),this._modal=this.closest(`.modal`),this._modal?.addEventListener(`hidden.bs.modal`,this._onModalHidden),this._readPath(),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){this.isConnected&&(e===`path`&&this._readPath(),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh())}get filter(){return this.hasAttribute(`filter`)}set filter(e){this.toggleAttribute(`filter`,!!e)}get highlight(){return this.getAttribute(`highlight`)!==`false`}set highlight(e){this.setAttribute(`highlight`,e?`true`:`false`)}get emptyText(){return this.getAttribute(`empty-text`)??s}set emptyText(e){this.setAttribute(`empty-text`,String(e??``))}refresh(){this._renderRecents(),this._renderCrumbs(),this._syncTabs();let e=this._input(),t=e?e.value:``,n=t!==this._lastQuery;this._lastQuery=t;let r=this._selectableOptions(),i=r.map(e=>e.id).join(`
|
|
2
|
+
`),a=i!==this._lastIds;this._lastIds=i;let o=!n&&(this._userChose||!a)?r.find(e=>e.id===this._activeId):null;o||(this._userChose=!1,this._setKeyboard(!1)),this._setActive(o??r[0]??null,n)}_input(){let e=this.querySelector(`[role="combobox"]`);return e instanceof HTMLInputElement?e:null}_optionFrom(e,t=!1){let n=h(e,o);return n&&this.contains(n)&&!this._isHidden(n)&&(t||!this._isDisabled(n))?n:null}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_isHidden(e){return e.hidden!==!1||(h(e,`[role="group"]`)?.hidden??!1)!==!1}_selectableOptions(){return _(this,o,HTMLElement).filter(e=>!this._isHidden(e)&&!this._isDisabled(e))}_setActive(e,t){this._activeId=e?e.id:null;for(let t of _(this,o,HTMLElement))t.setAttribute(`aria-selected`,t===e?`true`:`false`);let n=this._input();n&&(e?n.setAttribute(`aria-activedescendant`,e.id):n.removeAttribute(`aria-activedescendant`)),e&&t&&e.scrollIntoView({block:`nearest`})}_move(e){let t=this._selectableOptions();if(!t.length)return;let n=t.findIndex(e=>e.id===this._activeId),r=n<0?e>0?0:t.length-1:(n+e+t.length)%t.length;this._userChose=!0,this._setKeyboard(!0),this._setActive(t[r]??null,!0)}_setKeyboard(e){this.toggleAttribute(`data-keyboard`,e)}_handleKeyDown(e){let t=this._input();if(t&&e.target===t){if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),this._move(e.key===`ArrowDown`?1:-1);else if(e.key===`Tab`&&this._groupActive()&&this._tabs().length)e.preventDefault(),this._cycleGroup(e.shiftKey?-1:1);else if(e.key===`Backspace`&&!e.isComposing&&this._path.length&&!t.value)e.preventDefault(),this._goTo(this._path.slice(0,-1));else if(e.key===`Enter`&&!e.isComposing){let t=this._selectableOptions().find(e=>e.id===this._activeId);if(!t)return;e.preventDefault(),this._select(t)}}}_select(e){this._remember(e),this.dispatchEvent(new CustomEvent(`wui-command-palette:select`,{bubbles:!0,cancelable:!0,detail:{key:e.dataset.key??null,groupKey:e.dataset.groupKey??null,id:e.id}}))&&(e.dataset.opens?this._open(e.dataset.opens):e.dataset.href&&this._navigate(e.dataset.href))}_open(e){let t=_(this,`.wui-cmd-page`,HTMLElement).find(t=>t.dataset.page===e);this._goTo([...this._path,{key:e,label:t?.dataset.label??e}])}_goTo(e){this._input()?.focus(),this.dispatchEvent(new CustomEvent(`wui-command-palette:navigate`,{bubbles:!0,cancelable:!0,detail:{path:e}}))&&(this._path=e,this._restart())}_tabs(){return _(this,p,HTMLElement)}_groupActive(){return this.hasAttribute(`group-filter`)&&this._path.length===0}_pickGroup(e){this._group=e,this._applyFilter(),this.refresh()}_cycleGroup(e){let t=this._tabs().map(e=>e.dataset.groupTab||null),n=Math.max(0,t.indexOf(this._group));this._pickGroup(t[(n+e+t.length)%t.length]??null)}_syncTabs(){if(!this.hasAttribute(`group-filter`))return;let e=g(this,`.wui-cmd-tabs`,HTMLElement);e&&(e.hidden=!this._groupActive());for(let e of this._tabs())e.setAttribute(`aria-selected`,String((e.dataset.groupTab||null)===this._group))}_restart(){this._group=null;let e=this._input();e&&(e.value=``),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}_reset(){this.hasAttribute(`path`)||(this._path=[],this._restart())}_readPath(){let e=this.getAttribute(`path`);if(e==null)return;let t=JSON.parse(e);this._path=Array.isArray(t)?t.filter(e=>e&&typeof e.key==`string`&&typeof e.label==`string`):[]}_renderCrumbs(){let e=g(this,`.wui-cmd-crumbs`,HTMLElement);if(!e)return;let t=this.getAttribute(`root-label`)??c,n=JSON.stringify([t,this._path]);if(e.hidden=this._path.length===0,n===this._crumbSig)return;this._crumbSig=n;let r=g(e,`.wui-cmd-trail`,HTMLElement);if(!r)return;let i=[t,...this._path.map(e=>e.label)];r.replaceChildren(...i.map((e,t)=>{let n=document.createElement(`li`),r=t===i.length-1,a=document.createElement(r?`span`:`button`);if(a.className=`wui-cmd-crumb`,a.textContent=e,r)a.setAttribute(`aria-current`,`page`);else{if(!(a instanceof HTMLButtonElement))throw Error(`breadcrumb button missing`);a.type=`button`,a.dataset.depth=String(t)}return n.append(a),n}))}_recentsHost(){return g(this,`.wui-cmd-recents`,HTMLElement)}_realOptions(){let e=this._recentsHost();return _(this,o,HTMLElement).filter(t=>!e?.contains(t))}_recentEntries(){let e=this.getAttribute(`recents-key`);if(!e)return[];let t;try{t=JSON.parse(globalThis.localStorage?.getItem(e)??`[]`)}catch{return[]}return Array.isArray(t)?t.filter(e=>e&&typeof e.g==`string`&&typeof e.k==`string`):[]}_recentsLimit(){let e=Number.parseInt(this.getAttribute(`recents-limit`)??``,10);return Number.isFinite(e)&&e>0?Math.min(e,d):u}_remember(e){let t=this.getAttribute(`recents-key`),{groupKey:n,key:r,opens:i}=e.dataset;if(!t||i||n==null||r==null)return;let a=[{g:n,k:r},...this._recentEntries().filter(e=>e.g!==n||e.k!==r)];try{globalThis.localStorage?.setItem(t,JSON.stringify(a.slice(0,this._recentsLimit())))}catch(e){if(!(e instanceof DOMException))throw e}}_renderRecents(){let e=this._recentsHost();if(!e)return;let t=this._input(),n=this._groupActive()?this._group:null,r=this._path.length===0&&!(t?.value??``).trim()?this._recentEntries().filter(e=>!n||e.g===n):[],i=this._realOptions(),a=[];for(let e of r){let t=i.find(t=>t.dataset.groupKey===e.g&&t.dataset.key===e.k);if(t&&!t.dataset.opens&&!this._isDisabled(t)&&a.push(t),a.length>=this._recentsLimit())break}if(!a.length){e.firstChild&&e.replaceChildren();return}let o=`${this._recentsId}-label`,s=document.createElement(`div`);s.className=`wui-cmd-group`,s.setAttribute(`role`,`group`),s.setAttribute(`aria-labelledby`,o);let c=document.createElement(`div`);c.className=`wui-cmd-group-label`,c.setAttribute(`role`,`presentation`),c.id=o,c.textContent=this.getAttribute(`recents-label`)??l,s.append(c);for(let e of a){let t=e.cloneNode(!0);if(!(t instanceof HTMLElement))throw Error(`recent option copy is not an element`);t.id=`${this._recentsId}-${e.id}`,t.hidden=!1,t.removeAttribute(`aria-selected`),s.append(t)}e.replaceChildren(s)}_inScope(e,t){return!t||(h(e,`.wui-cmd-page`)?.dataset.page??null)===(this._path.at(-1)?.key??null)}_navigate(e){window.location.assign(e)}_applyFilter(){let e=this._input(),t=(e?e.value:``).trim(),n=t.toLowerCase(),a=this.highlight,s=_(this,`.wui-cmd-page`,HTMLElement),c=s.length>0,l=this._path.at(-1)?.key??null;for(let e of s)e.hidden=e.dataset.page!==l;let u=this._groupActive()?this._group:null,d=0;for(let e of this._realOptions()){let o=g(e,`.wui-cmd-item-label`,HTMLElement),s=e.dataset.label??o?.textContent??``,l=(e.dataset.keywords??``).split(/\s+/).filter(Boolean),f=!n||s.toLowerCase().includes(n)||l.some(e=>e.toLowerCase().includes(n)),p=this._inScope(e,c)&&(!u||e.dataset.groupKey===u)&&f;e.hidden=!p,p&&d++,o&&(o.innerHTML=(0,i.matchSegments)(s,a?t:``).map(e=>e.match?`<mark class="wui-cmd-mark">${(0,r.escapeHtml)(e.text)}</mark>`:(0,r.escapeHtml)(e.text)).join(``))}let f=this._recentsHost();for(let e of _(this,`[role="group"]`,HTMLElement))f?.contains(e)||(e.hidden=!_(e,o,HTMLElement).some(e=>!e.hidden));let p=g(this,`[role="listbox"]`,HTMLElement);p&&(p.hidden=d===0);let m=g(this,`.wui-cmd-empty`,HTMLElement);m&&(m.textContent=n&&d===0?this.emptyText:``)}_teardown(){this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`mousedown`,this._onMouseDown),this.removeEventListener(`mousemove`,this._onMouseMove),this.removeEventListener(`input`,this._onInput),this._modal?.removeEventListener(`hidden.bs.modal`,this._onModalHidden),this._modal=null}};(0,t.defineElement)(`wui-command-palette`,v),e.WuiCommandPalette=v})(this.WeborityUiElements=this.WeborityUiElements||{},WeborityUiElementsInternal.modules.defineElement,WeborityUiElementsInternal.modules.elementBase,WeborityUiElementsInternal.modules.optionLabel,WeborityUiElementsInternal.modules.textMatch);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=globalThis.WeborityUiElementsInternal?.version;if(u!==`0.152.0`)throw Error(`[webority-ui] comment-thread expects ui-elements 0.152.0 but the page loaded `+u+`.`);var d=Object.freeze([`👍`,`❤️`,`🎉`,`😄`,`👀`,`🙏`]),f=Object.freeze([`post`,`reply`,`edit`,`delete`,`react`]),p=`This did not go through. Refresh the page and try again.`,m=`Something went wrong on our side. Try again in a moment.`,h=Object.freeze({forbidden:`You do not have permission to do this.`,client:p,validation:`This was not accepted. Check it and try again.`,server:m,network:`Could not reach the server. Check your connection and try again.`}),g=Object.freeze({listName:`Comments`,empty:`No comments yet.`,deleted:`This comment was deleted.`,edited:`Edited`,reply:`Reply`,edit:`Edit`,delete:`Delete`,cancel:`Cancel`,save:`Save`,post:`Comment`,confirmDelete:`Delete this comment?`,composerLabel:`Add a comment`,composerPlaceholder:`Write a comment. Type @ to mention someone.`,replyLabel:e=>`Reply to ${e}`,replyPlaceholder:`Write a reply`,editLabel:`Edit comment`,repliesName:e=>`Replies to ${e}`,reactions:`Reactions`,addReaction:`Add a reaction`,pickerName:`Choose a reaction`,emptyBody:`Write something first.`,done:Object.freeze({post:`Comment posted.`,reply:`Reply posted.`,edit:`Comment saved.`,delete:`Comment deleted.`,react:``}),failed:h}),_=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`:`${(0,s.formatNumber)(e,{decimals:0})} people`}. Up and down to choose, Enter to mention.`,mentioned:e=>`Mentioned ${e}.`}),v=`[data-wui-control]`,y=`[data-wui-field]`,b=`[data-wui-menu]`,x=`[data-wui-live]`,S=0,C=e=>!!(e&&l.MENTION_ID_PATTERN.test(String(e.value??``))&&(0,l.mentionLabel)(e.label)!==``);function w(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`input-sm`,n===`sm`),t.classList.toggle(`input-lg`,n===`lg`)}function T(e,t){t.readOnly=(0,o.isReadOnly)(e)||e.hasAttribute(`loading`)}function E(e){let t=e.ownerDocument;e.id||=`wui-mention-${++S}`;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`),T(e,n),w(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`)??_.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 D=class extends i.ElementBase{_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(v)||E(this);let e=this._requireControl(),t=this.querySelector(y)?.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`?(T(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(T(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?w(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return(0,l.mentionValueFromText)(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=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(C):[],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(v)}_menu(){return this.querySelector(b)}_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}=(0,l.mentionTextFromValue)(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(y);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||(0,o.isInert)(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=>(0,l.mentionLabel)(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)}`,o=await(0,a.wuiFetch)(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!o.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let s=this.ownerDocument.createElement(`template`);s.innerHTML=o.html,this._peopleProp=[...s.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(C),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return!(!e||e.hidden)}_renderMenu(){let e=this._menu(),t=this._control();if(!e||!t||!this._query)return;this._syncState();let r=this.ownerDocument;if(e.replaceChildren(),this._results.forEach((t,n)=>{let i=r.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${e.id}-${n}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(n),t.src){let e=r.createElement(`img`);e.className=`wui-mention-option-photo`,e.src=t.src,e.alt=``,i.appendChild(e)}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=(0,l.mentionLabel)(t.label),a.appendChild(o),t.description){let e=r.createElement(`span`);e.className=`wui-mention-option-description`,e.textContent=String(t.description),a.appendChild(e)}i.appendChild(a),e.appendChild(i)}),!this._results.length){let t=r.createElement(`div`);t.className=`wui-mention-empty`,t.textContent=this.loading?_.searching:this._searchFailed?_.searchFailed:`${_.noMatch} “${this._query.text}”`,e.appendChild(t)}let i=this._isOpen();e.hidden=!1,i||(0,n.bindReanchor)(this,this._reposition),this._position(),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?_.found(this._results.length):this._searchFailed?_.searchFailed:`${_.noMatch}.`)}_syncState(){let e=this._control();e&&(0,o.syncFieldState)(this,e)}_position(){(0,n.anchorOverlay)(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`),(0,n.unbindReanchor)(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`);(0,c.moveActiveRow)(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=(0,l.mentionLabel)(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(_.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(x);t&&(t.textContent=``,t.textContent=e)}},O=`[data-wui-items]`,k=`[data-wui-picker]`,A=`[data-wui-composer]`,j=`[data-wui-comment]`,M=`[data-wui-live]`,N=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:m},P=e=>e instanceof Element?e:null,F=e=>`disabled`in e&&e.disabled===!0,I=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},L=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},R=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},z=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],B=class extends i.ElementBase{_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&&!L(this,k,HTMLElement)?.contains(P(e.target))&&!this._pickerFor.button.contains(P(e.target))&&this._closePicker(!1)},this._repositionPicker=()=>{this._pickerFor&&(0,n.anchorOverlay)(this._pickerFor.button,L(this,k,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=L(this,`${A} wui-mention-input`,D);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:z(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:d}_onClick(e){let t=R(P(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!F(t)){let e=t.closest(k),n=e?this._pickerFor?.comment:t.closest(j);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=R(P(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||F(n))return;let r=n.closest(j);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=I(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(R(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=L(this,k,HTMLElement),n=P(e.target);if(this._pickerFor&&t?.contains(n)){let r=z(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=R(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=R(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(j),!0))}_onSubmitKey(e){let t=L(R(P(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!F(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=L(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:g.replyLabel(r),placeholder:g.replyPlaceholder,value:``,send:g.reply,opener:t})}_openEditor(e,t){let n=L(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=L(I(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:g.editLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:g.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 c=o.createElement(`div`);c.className=`wui-comment-form-actions`,c.append(this._button(`primary`,`solid`,`sm`,`send`,i),this._button(`primary`,`ghost`,`sm`,`cancel`,g.cancel));let l=o.createElement(`div`);l.className=`wui-comment-error`,l.setAttribute(`data-wui-error`,``),l.hidden=!0,e.replaceChildren(s,c,l),this._handPeople(s),e.hidden=!1,this._openers??=new WeakMap,this._openers.set(e,a),s.focus();let u=s.querySelector(`textarea`);u?.setSelectionRange(u.value.length,u.value.length)}_button(e,t,n,i,a){let o=this.ownerDocument.createElement(`button`);return o.type=`button`,o.className=(0,r.buttonClass)(e,t,n),o.dataset.wui=r.APP_BUTTON_MARKER,o.setAttribute(`data-wui-action`,i),o.textContent=a,o}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=L(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=L(e,`:scope > .wui-comment-row`,HTMLElement),n=L(t,`[data-wui-confirm]`,HTMLElement),r=L(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),L(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=L(e,`:scope > .wui-comment-row`,HTMLElement),r=L(n,`[data-wui-confirm]`,HTMLElement),i=L(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&L(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let r=L(this,k,HTMLElement);r&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),r.hidden=!1,(0,n.anchorOverlay)(t,r),(0,n.bindReanchor)(this,this._repositionPicker),this.ownerDocument.addEventListener(`click`,this._onDocClick,!0),L(r,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;this._pickerFor=null;let r=L(this,k,HTMLElement);r&&(r.hidden=!0),t.button.setAttribute(`aria-expanded`,`false`),(0,n.unbindReanchor)(this),this.ownerDocument.removeEventListener(`click`,this._onDocClick,!0),e&&t.button.isConnected&&t.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=R(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,g.emptyBody),n?.focus();return}let i=t.closest(j);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:I(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:I(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??L(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 c=t.commentId??null,l=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),g.done[e]&&this._announce(g.done[e]),this.dispatchEvent(new CustomEvent(`wui:comment-thread:done`,{bubbles:!0,detail:{intent:e,commentId:c,parentId:l}}))):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:N(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:p};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await(0,a.wuiFetch)(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||g.failed[r.kind]||`Something went wrong on our side. Try again in a moment.`}}_swapItems(e){let t=L(this,O,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=L(n.content,O,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)&&!F(i))return;let a=e=>e?z(this,j,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>L(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=L(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=L(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=z(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??L(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=L(this,`${A} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=L(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=L(this,`:scope > ${M}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};(0,t.defineElement)(`wui-mention-input`,D),(0,t.defineElement)(`wui-comment-thread`,B),e.COMMENT_INTENTS=f,e.COMMENT_REACTIONS=d,e.COMMENT_TEXT=g,e.WuiCommentThread=B})(this.WeborityUiElements=this.WeborityUiElements||{},WeborityUiElementsInternal.modules.defineElement,WeborityUiElementsInternal.modules.anchorOverlay,WeborityUiElementsInternal.modules.buttonClass,WeborityUiElementsInternal.modules.elementBase,WeborityUiElementsInternal.modules.wuiHttp,WeborityUiElementsInternal.modules.fieldState,WeborityUiElementsInternal.modules.formatters,WeborityUiElementsInternal.modules.listboxKeyNav,WeborityUiElementsInternal.modules.mentionText);
|
|
1
|
+
(function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=globalThis.WeborityUiElementsInternal?.version;if(u!==`0.154.0`)throw Error(`[webority-ui] comment-thread expects ui-elements 0.154.0 but the page loaded `+u+`.`);var d=Object.freeze([`👍`,`❤️`,`🎉`,`😄`,`👀`,`🙏`]),f=Object.freeze([`post`,`reply`,`edit`,`delete`,`react`]),p=`This did not go through. Refresh the page and try again.`,m=`Something went wrong on our side. Try again in a moment.`,h=Object.freeze({forbidden:`You do not have permission to do this.`,client:p,validation:`This was not accepted. Check it and try again.`,server:m,network:`Could not reach the server. Check your connection and try again.`}),g=Object.freeze({listName:`Comments`,empty:`No comments yet.`,deleted:`This comment was deleted.`,edited:`Edited`,reply:`Reply`,edit:`Edit`,delete:`Delete`,cancel:`Cancel`,save:`Save`,post:`Comment`,confirmDelete:`Delete this comment?`,composerLabel:`Add a comment`,composerPlaceholder:`Write a comment. Type @ to mention someone.`,replyLabel:e=>`Reply to ${e}`,replyPlaceholder:`Write a reply`,editLabel:`Edit comment`,repliesName:e=>`Replies to ${e}`,reactions:`Reactions`,addReaction:`Add a reaction`,pickerName:`Choose a reaction`,emptyBody:`Write something first.`,done:Object.freeze({post:`Comment posted.`,reply:`Reply posted.`,edit:`Comment saved.`,delete:`Comment deleted.`,react:``}),failed:h}),_=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`:`${(0,s.formatNumber)(e,{decimals:0})} people`}. Up and down to choose, Enter to mention.`,mentioned:e=>`Mentioned ${e}.`}),v=`[data-wui-control]`,y=`[data-wui-field]`,b=`[data-wui-menu]`,x=`[data-wui-live]`,S=0,C=e=>!!(e&&l.MENTION_ID_PATTERN.test(String(e.value??``))&&(0,l.mentionLabel)(e.label)!==``);function w(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`input-sm`,n===`sm`),t.classList.toggle(`input-lg`,n===`lg`)}function T(e,t){t.readOnly=(0,o.isReadOnly)(e)||e.hasAttribute(`loading`)}function E(e){let t=e.ownerDocument;e.id||=`wui-mention-${++S}`;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`),T(e,n),w(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`)??_.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 D=class extends i.ElementBase{_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(v)||E(this);let e=this._requireControl(),t=this.querySelector(y)?.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`?(T(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(T(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?w(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return(0,l.mentionValueFromText)(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=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(C):[],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(v)}_menu(){return this.querySelector(b)}_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}=(0,l.mentionTextFromValue)(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(y);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||(0,o.isInert)(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=>(0,l.mentionLabel)(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)}`,o=await(0,a.wuiFetch)(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!o.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let s=this.ownerDocument.createElement(`template`);s.innerHTML=o.html,this._peopleProp=[...s.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(C),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return!(!e||e.hidden)}_renderMenu(){let e=this._menu(),t=this._control();if(!e||!t||!this._query)return;this._syncState();let r=this.ownerDocument;if(e.replaceChildren(),this._results.forEach((t,n)=>{let i=r.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${e.id}-${n}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(n),t.src){let e=r.createElement(`img`);e.className=`wui-mention-option-photo`,e.src=t.src,e.alt=``,i.appendChild(e)}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=(0,l.mentionLabel)(t.label),a.appendChild(o),t.description){let e=r.createElement(`span`);e.className=`wui-mention-option-description`,e.textContent=String(t.description),a.appendChild(e)}i.appendChild(a),e.appendChild(i)}),!this._results.length){let t=r.createElement(`div`);t.className=`wui-mention-empty`,t.textContent=this.loading?_.searching:this._searchFailed?_.searchFailed:`${_.noMatch} “${this._query.text}”`,e.appendChild(t)}let i=this._isOpen();e.hidden=!1,i||(0,n.bindReanchor)(this,this._reposition),this._position(),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?_.found(this._results.length):this._searchFailed?_.searchFailed:`${_.noMatch}.`)}_syncState(){let e=this._control();e&&(0,o.syncFieldState)(this,e)}_position(){(0,n.anchorOverlay)(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`),(0,n.unbindReanchor)(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`);(0,c.moveActiveRow)(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=(0,l.mentionLabel)(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(_.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(x);t&&(t.textContent=``,t.textContent=e)}},O=`[data-wui-items]`,k=`[data-wui-picker]`,A=`[data-wui-composer]`,j=`[data-wui-comment]`,M=`[data-wui-live]`,N=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:m},P=e=>e instanceof Element?e:null,F=e=>`disabled`in e&&e.disabled===!0,I=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},L=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},R=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},z=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],B=class extends i.ElementBase{_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&&!L(this,k,HTMLElement)?.contains(P(e.target))&&!this._pickerFor.button.contains(P(e.target))&&this._closePicker(!1)},this._repositionPicker=()=>{this._pickerFor&&(0,n.anchorOverlay)(this._pickerFor.button,L(this,k,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=L(this,`${A} wui-mention-input`,D);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:z(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:d}_onClick(e){let t=R(P(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!F(t)){let e=t.closest(k),n=e?this._pickerFor?.comment:t.closest(j);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=R(P(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||F(n))return;let r=n.closest(j);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=I(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(R(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=L(this,k,HTMLElement),n=P(e.target);if(this._pickerFor&&t?.contains(n)){let r=z(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=R(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=R(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(j),!0))}_onSubmitKey(e){let t=L(R(P(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!F(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=L(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:g.replyLabel(r),placeholder:g.replyPlaceholder,value:``,send:g.reply,opener:t})}_openEditor(e,t){let n=L(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=L(I(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:g.editLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:g.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 c=o.createElement(`div`);c.className=`wui-comment-form-actions`,c.append(this._button(`primary`,`solid`,`sm`,`send`,i),this._button(`primary`,`ghost`,`sm`,`cancel`,g.cancel));let l=o.createElement(`div`);l.className=`wui-comment-error`,l.setAttribute(`data-wui-error`,``),l.hidden=!0,e.replaceChildren(s,c,l),this._handPeople(s),e.hidden=!1,this._openers??=new WeakMap,this._openers.set(e,a),s.focus();let u=s.querySelector(`textarea`);u?.setSelectionRange(u.value.length,u.value.length)}_button(e,t,n,i,a){let o=this.ownerDocument.createElement(`button`);return o.type=`button`,o.className=(0,r.buttonClass)(e,t,n),o.dataset.wui=r.APP_BUTTON_MARKER,o.setAttribute(`data-wui-action`,i),o.textContent=a,o}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=L(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=L(e,`:scope > .wui-comment-row`,HTMLElement),n=L(t,`[data-wui-confirm]`,HTMLElement),r=L(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),L(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=L(e,`:scope > .wui-comment-row`,HTMLElement),r=L(n,`[data-wui-confirm]`,HTMLElement),i=L(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&L(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let r=L(this,k,HTMLElement);r&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),r.hidden=!1,(0,n.anchorOverlay)(t,r),(0,n.bindReanchor)(this,this._repositionPicker),this.ownerDocument.addEventListener(`click`,this._onDocClick,!0),L(r,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;this._pickerFor=null;let r=L(this,k,HTMLElement);r&&(r.hidden=!0),t.button.setAttribute(`aria-expanded`,`false`),(0,n.unbindReanchor)(this),this.ownerDocument.removeEventListener(`click`,this._onDocClick,!0),e&&t.button.isConnected&&t.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=R(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,g.emptyBody),n?.focus();return}let i=t.closest(j);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:I(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:I(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??L(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 c=t.commentId??null,l=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),g.done[e]&&this._announce(g.done[e]),this.dispatchEvent(new CustomEvent(`wui:comment-thread:done`,{bubbles:!0,detail:{intent:e,commentId:c,parentId:l}}))):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:N(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:p};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await(0,a.wuiFetch)(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||g.failed[r.kind]||`Something went wrong on our side. Try again in a moment.`}}_swapItems(e){let t=L(this,O,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=L(n.content,O,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)&&!F(i))return;let a=e=>e?z(this,j,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>L(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=L(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=L(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=z(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??L(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=L(this,`${A} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=L(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=L(this,`:scope > ${M}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};(0,t.defineElement)(`wui-mention-input`,D),(0,t.defineElement)(`wui-comment-thread`,B),e.COMMENT_INTENTS=f,e.COMMENT_REACTIONS=d,e.COMMENT_TEXT=g,e.WuiCommentThread=B})(this.WeborityUiElements=this.WeborityUiElements||{},WeborityUiElementsInternal.modules.defineElement,WeborityUiElementsInternal.modules.anchorOverlay,WeborityUiElementsInternal.modules.buttonClass,WeborityUiElementsInternal.modules.elementBase,WeborityUiElementsInternal.modules.wuiHttp,WeborityUiElementsInternal.modules.fieldState,WeborityUiElementsInternal.modules.formatters,WeborityUiElementsInternal.modules.listboxKeyNav,WeborityUiElementsInternal.modules.mentionText);
|