@webority/ui-elements 0.168.0 → 0.169.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/dist/{WuiCommentThread-AYovTYSA.js → WuiCommentThread-RB100aB1.js} +1 -1
  2. package/dist/{WuiContextMenu-CyejQsef.js → WuiContextMenu-ClMVFeos.js} +1 -1
  3. package/dist/{WuiDataTable-BniN81KC.js → WuiDataTable-D0tGIVtG.js} +1 -1
  4. package/dist/{WuiDatePicker-q0s8tL_E.js → WuiDatePicker-BiZciUAZ.js} +1 -1
  5. package/dist/{WuiDateRange-p2r5A9CY.js → WuiDateRange-DSq6Mj4v.js} +1 -1
  6. package/dist/{WuiDrawer-CQ7nRHUD.js → WuiDrawer-n8WlVPq_.js} +1 -1
  7. package/dist/{WuiDropdown-BQC04Q48.js → WuiDropdown-D2jEbCfv.js} +1 -1
  8. package/dist/{WuiEntryGrid-DPAYNu1v.js → WuiEntryGrid-Bm5_MizA.js} +1 -1
  9. package/dist/WuiGantt-BsQUCR2U.js +1 -0
  10. package/dist/{WuiHoverCard-DRZh88zM.js → WuiHoverCard-DmApQa9R.js} +1 -1
  11. package/dist/{WuiInlineEdit-CEjs5Ruk.js → WuiInlineEdit-C64O31MF.js} +1 -1
  12. package/dist/{WuiLightbox-DDQAOabU.js → WuiLightbox-cm5eHcMK.js} +1 -1
  13. package/dist/{WuiMentionInput-CkhrCz_2.js → WuiMentionInput-D7HC7U2Q.js} +1 -1
  14. package/dist/{WuiModal-BRILsSMq.js → WuiModal-DuBerYTv.js} +1 -1
  15. package/dist/{WuiNavigationMenu-BCnqv7e-.js → WuiNavigationMenu-VG-ZJstT.js} +1 -1
  16. package/dist/{WuiNotificationCenter-BCXT3Y7m.js → WuiNotificationCenter-hluDIzO8.js} +1 -1
  17. package/dist/{WuiOverflow-DtetLQHW.js → WuiOverflow-MzrZwzud.js} +1 -1
  18. package/dist/{WuiPhone-B6jgFRSi.js → WuiPhone-C03OuI7-.js} +1 -1
  19. package/dist/{WuiPopover-BzVxNSs1.js → WuiPopover-BxQj74kE.js} +1 -1
  20. package/dist/{WuiRelativeTime-DTGKGHbK.js → WuiRelativeTime-CujAFS_w.js} +1 -1
  21. package/dist/WuiSelect-DpZbgU4v.js +9 -0
  22. package/dist/{WuiShortcuts-DSjwaZx7.js → WuiShortcuts-CSFOyAKI.js} +1 -1
  23. package/dist/{WuiTimePicker-C5XouoR7.js → WuiTimePicker-BxcImgm1.js} +1 -1
  24. package/dist/{WuiTour-BDOGWyNA.js → WuiTour-Beop0n-H.js} +1 -1
  25. package/dist/WuiTree-DGclk55_.js +1 -0
  26. package/dist/WuiTreePicker-CBhasmC5.js +1 -0
  27. package/dist/{WuiWhatsNew-DOo54GiH.js → WuiWhatsNew-BtWJkzTv.js} +1 -1
  28. package/dist/anchorOverlay-DSzkGQPi.js +1 -0
  29. package/dist/avatarHtml-BtbN7cA5.js +1 -0
  30. package/dist/{calendarMath-CFjBxJYM.js → calendarMath-ChZ_s7HH.js} +1 -1
  31. package/dist/{chips-CemguTKJ.js → chips-IbfKMhVk.js} +1 -1
  32. package/dist/{dataTable-CKz4Oncc.js → dataTable-sRTzep19.js} +1 -1
  33. package/dist/{drawerDiscard-BjykHS_G.js → drawerDiscard-CIZZuKmY.js} +1 -1
  34. package/dist/elements/comment-thread.js +1 -1
  35. package/dist/elements/context-menu.js +1 -1
  36. package/dist/elements/data-table.js +1 -1
  37. package/dist/elements/date-range.js +1 -1
  38. package/dist/elements/datepicker.js +1 -1
  39. package/dist/elements/drawer.js +1 -1
  40. package/dist/elements/dropdown.js +1 -1
  41. package/dist/elements/entry-grid.js +1 -1
  42. package/dist/elements/filter-popover.js +1 -1
  43. package/dist/elements/gantt.js +1 -0
  44. package/dist/elements/hover-card.js +1 -1
  45. package/dist/elements/inline-edit.js +1 -1
  46. package/dist/elements/kanban.js +1 -1
  47. package/dist/elements/lightbox.js +1 -1
  48. package/dist/elements/mention-input.js +1 -1
  49. package/dist/elements/modal.js +1 -1
  50. package/dist/elements/navigation-menu.js +1 -1
  51. package/dist/elements/notification-center.js +1 -1
  52. package/dist/elements/overflow.js +1 -1
  53. package/dist/elements/phone.js +1 -1
  54. package/dist/elements/popover.js +1 -1
  55. package/dist/elements/relative-time.js +1 -1
  56. package/dist/elements/select.js +1 -1
  57. package/dist/elements/shortcuts.js +1 -1
  58. package/dist/elements/timepicker.js +1 -1
  59. package/dist/elements/tour.js +1 -1
  60. package/dist/elements/tree-picker.js +1 -0
  61. package/dist/elements/tree.js +1 -1
  62. package/dist/elements/whats-new.js +1 -1
  63. package/dist/{fileViewer.g-B5XQ5WKr.js → fileViewer.g-DQ-YkF8l.js} +1 -1
  64. package/dist/{fileViewerImage-B0Q9zdgW.js → fileViewerImage-DT0a9KaL.js} +1 -1
  65. package/dist/{fileViewerMedia-D3fdG-Ti.js → fileViewerMedia-BFNxdaYX.js} +1 -1
  66. package/dist/{fileViewerPdf-DeRWa1JE.js → fileViewerPdf-Boo6uXQO.js} +1 -1
  67. package/dist/{filterPopover-DmeVG4_N.js → filterPopover-BVBxgtc5.js} +1 -1
  68. package/dist/{formatters-Dy4kQQ_h.js → formatters-CMTSYlW9.js} +1 -1
  69. package/dist/gantt.g-TdTxeruW.js +1 -0
  70. package/dist/helpers.js +1 -1
  71. package/dist/initials-Qb6ITcri.js +1 -0
  72. package/dist/{inlineEditText-BUO5sZxN.js → inlineEditText-5FT8SGqR.js} +1 -1
  73. package/dist/{kanban-CEZmyYFY.js → kanban-CRRLqNn_.js} +1 -1
  74. package/dist/{kanbanModel-Dp5c1rTs.js → kanbanModel-sAwpMCpn.js} +1 -1
  75. package/dist/listboxKeyNav-DtlIOryj.js +1 -0
  76. package/dist/loader-Cf_ozcXz.js +1 -0
  77. package/dist/{nativeOverlay-C1Rw2gIW.js → nativeOverlay-D3VmY8qn.js} +1 -1
  78. package/dist/{notificationDays-B7cbYu4q.js → notificationDays-DQlrEZ3z.js} +1 -1
  79. package/dist/{relativeTime-CdFw-ekO.js → relativeTime-CQuwuwZ-.js} +1 -1
  80. package/dist/search-BVox4aaA.js +1 -0
  81. package/dist/server.js +1 -1
  82. package/dist/text/en.json +145 -0
  83. package/dist/text.js +1 -1
  84. package/dist/treePicker.g-BR35ru5f.js +1 -0
  85. package/dist/ui-chart.global.js +2 -2
  86. package/dist/ui-chart.js +2 -2
  87. package/dist/ui-elements/carousel.global.js +1 -1
  88. package/dist/ui-elements/code-block.global.js +1 -1
  89. package/dist/ui-elements/command-palette.global.js +1 -1
  90. package/dist/ui-elements/comment-thread.global.js +1 -1
  91. package/dist/ui-elements/consent-banner.global.js +1 -1
  92. package/dist/ui-elements/context-menu.global.js +1 -1
  93. package/dist/ui-elements/date-range.global.js +1 -1
  94. package/dist/ui-elements/drawer.global.js +1 -1
  95. package/dist/ui-elements/dropdown.global.js +1 -1
  96. package/dist/ui-elements/entry-grid.global.js +2 -2
  97. package/dist/ui-elements/gantt.global.js +1 -0
  98. package/dist/ui-elements/glyphs.global.js +1 -1
  99. package/dist/ui-elements/image-crop.global.js +1 -1
  100. package/dist/ui-elements/inline-edit.global.js +1 -1
  101. package/dist/ui-elements/kanban.global.js +1 -1
  102. package/dist/ui-elements/lead-popup.global.js +1 -1
  103. package/dist/ui-elements/lightbox.global.js +1 -1
  104. package/dist/ui-elements/markdown.global.js +1 -1
  105. package/dist/ui-elements/org-tree.global.js +1 -1
  106. package/dist/ui-elements/phone.global.js +1 -1
  107. package/dist/ui-elements/popover.global.js +1 -1
  108. package/dist/ui-elements/saved-views.global.js +1 -1
  109. package/dist/ui-elements/select-chips.global.js +1 -1
  110. package/dist/ui-elements/select-recents.global.js +1 -1
  111. package/dist/ui-elements/select-search.global.js +1 -1
  112. package/dist/ui-elements/select-window.global.js +1 -0
  113. package/dist/ui-elements/slider.global.js +1 -1
  114. package/dist/ui-elements/sortable.global.js +1 -1
  115. package/dist/ui-elements/status-icon.global.js +1 -1
  116. package/dist/ui-elements/timepicker.global.js +1 -1
  117. package/dist/ui-elements/tour.global.js +1 -1
  118. package/dist/ui-elements/tree-picker.global.js +1 -0
  119. package/dist/ui-elements/tree.global.js +1 -1
  120. package/dist/ui-elements/wizard.global.js +1 -1
  121. package/dist/ui-elements.global.js +21 -21
  122. package/dist/ui-elements.js +1 -1
  123. package/dist/ui-file-viewer.global.js +1 -1
  124. package/dist/ui-file-viewer.js +1 -1
  125. package/dist/ui-tour.global.js +1 -1
  126. package/dist/window-BZWK3rQk.js +1 -0
  127. package/package.json +13 -5
  128. package/types/WuiGantt.d.ts +70 -0
  129. package/types/WuiSelect.d.ts +9 -0
  130. package/types/WuiTree.d.ts +37 -2
  131. package/types/WuiTreePicker.d.ts +64 -0
  132. package/types/chartSpec.d.ts +1 -1
  133. package/types/elements/gantt.d.ts +2 -0
  134. package/types/elements/tree-picker.d.ts +2 -0
  135. package/types/formatters.d.ts +6 -4
  136. package/types/ganttLayout.d.ts +116 -0
  137. package/types/ganttTable.d.ts +24 -0
  138. package/types/ganttTypes.d.ts +43 -0
  139. package/types/global/parts/select-window.d.ts +1 -0
  140. package/types/global/shared.d.ts +4 -0
  141. package/types/globals.d.ts +5 -1
  142. package/types/helpers.d.ts +3 -0
  143. package/types/index.d.ts +5 -1
  144. package/types/initials.d.ts +5 -0
  145. package/types/listboxKeyNav.d.ts +13 -0
  146. package/types/select/list.d.ts +58 -2
  147. package/types/select/window.d.ts +39 -0
  148. package/types/select/windowLoad.d.ts +1 -0
  149. package/types/select/windowLoadGlobal.d.ts +1 -0
  150. package/types/select/windowThreshold.d.ts +1 -0
  151. package/types/select/windowed.d.ts +2 -0
  152. package/types/text/web/catalogue.g.d.ts +12 -0
  153. package/types/text/web/gantt.g.d.ts +47 -0
  154. package/types/text/web/idleTimeoutDialog.g.d.ts +7 -0
  155. package/types/text/web/index.g.d.ts +6 -0
  156. package/types/text/web/loadMore.g.d.ts +8 -0
  157. package/types/text/web/queryBuilder.g.d.ts +59 -0
  158. package/types/text/web/transferList.g.d.ts +18 -0
  159. package/types/text/web/treePicker.g.d.ts +12 -0
  160. package/types/treePicker/treeKeys.d.ts +46 -0
  161. package/types/treePicker/treePickerView.d.ts +31 -0
  162. package/types/treePicker/treeState.d.ts +42 -0
  163. package/dist/WuiSelect-CMHoPHlx.js +0 -9
  164. package/dist/WuiTree-CeYbyaCx.js +0 -1
  165. package/dist/anchorOverlay-B8fu8hjz.js +0 -1
  166. package/dist/listboxKeyNav-CF7tMDGG.js +0 -1
  167. package/dist/loader-CQJFj96n.js +0 -1
  168. package/dist/search-Cj1YQUwK.js +0 -1
@@ -1 +1 @@
1
- import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{n}from"./commentText-NWsssKvj.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,l as a,s as o}from"./nativeOverlay-C1Rw2gIW.js";import{l as s}from"./wuiHttp-DGbD7Fra.js";import{r as c,t as l}from"./textStore-opIEM4lu.js";import{n as u,t as d}from"./httpFailure.g-DBKzEpAf.js";import{r as f}from"./WuiMentionInput-CkhrCz_2.js";var p=`[data-wui-items]`,m=`[data-wui-picker]`,h=`[data-wui-composer]`,g=`[data-wui-comment]`,_=`[data-wui-live]`,v=()=>c(`commentThread`,u),y=e=>({forbidden:v().forbiddenMessage,client:v().failedClientMessage,validation:v().validationMessage,server:v().failedServerMessage,network:c(`httpFailure`,d).networkText})[e],b=e=>({post:v().donePostText,reply:v().doneReplyText,edit:v().doneEditText,delete:v().doneDeleteText,react:``})[e],x=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:v().failedServerMessage},S=e=>e instanceof Element?e:null,C=e=>`disabled`in e&&e.disabled===!0,w=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},T=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},E=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},D=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],O=class extends r{_wired;_busy;_peopleProp;_pickerFor;_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)}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=T(this,`${h} wui-mention-input`,f);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:D(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:n}_onClick(e){let t=E(S(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!C(t)){let e=t.closest(m),n=e?this._pickerFor?.comment:t.closest(g);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=E(S(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||C(n))return;let r=n.closest(g);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=w(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(E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=T(this,m,HTMLElement),n=S(e.target);if(this._pickerFor&&t?.contains(n)){let r=D(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=E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=E(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(g),!0))}_onSubmitKey(e){let t=T(E(S(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!C(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=T(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:l(v().replyToText,{author:r}),placeholder:v().replyPlaceholder,value:``,send:v().replyLabel,opener:t})}_openEditor(e,t){let n=T(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=T(w(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:v().editCommentLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:v().saveLabel,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`,v().cancelLabel));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??=/* @__PURE__ */ new WeakMap,this._openers.set(e,a),s.focus();let u=s.querySelector(`textarea`);u?.setSelectionRange(u.value.length,u.value.length)}_button(n,r,i,a,o){let s=this.ownerDocument.createElement(`button`);return s.type=`button`,s.className=e(n,r,i),s.dataset.wui=t,s.setAttribute(`data-wui-action`,a),s.textContent=o,s}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=T(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=T(e,`:scope > .wui-comment-row`,HTMLElement),n=T(t,`[data-wui-confirm]`,HTMLElement),r=T(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),T(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=T(e,`:scope > .wui-comment-row`,HTMLElement),r=T(n,`[data-wui-confirm]`,HTMLElement),i=T(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&T(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let n=T(this,m,HTMLElement);n&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),a(t,n,{mode:`auto`,onClosed:()=>this._pickerClosed()}),T(n,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;let n=T(this,m,HTMLElement);n&&i(n),this._pickerClosed(),e&&t.button.isConnected&&t.button.focus()}_pickerClosed(){let e=T(this,m,HTMLElement),t=this._pickerFor;!t||e&&o(e)||(this._pickerFor=null,t.button.setAttribute(`aria-expanded`,`false`))}_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=E(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,v().emptyBodyMessage),n?.focus();return}let i=t.closest(g);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:w(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:w(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??T(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),b(e)&&this._announce(b(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:x(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:v().failedClientMessage};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await s(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||y(r.kind)||v().failedServerMessage}}_swapItems(e){let t=T(this,p,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=T(n.content,p,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)&&!C(i))return;let a=e=>e?D(this,g,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>T(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=T(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=T(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=D(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??T(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=T(this,`${h} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=T(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=T(this,`:scope > ${_}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{O as t};
1
+ import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{n}from"./commentText-NWsssKvj.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,l as a,s as o}from"./nativeOverlay-D3VmY8qn.js";import{l as s}from"./wuiHttp-DGbD7Fra.js";import{r as c,t as l}from"./textStore-opIEM4lu.js";import{n as u,t as d}from"./httpFailure.g-DBKzEpAf.js";import{r as f}from"./WuiMentionInput-D7HC7U2Q.js";var p=`[data-wui-items]`,m=`[data-wui-picker]`,h=`[data-wui-composer]`,g=`[data-wui-comment]`,_=`[data-wui-live]`,v=()=>c(`commentThread`,u),y=e=>({forbidden:v().forbiddenMessage,client:v().failedClientMessage,validation:v().validationMessage,server:v().failedServerMessage,network:c(`httpFailure`,d).networkText})[e],b=e=>({post:v().donePostText,reply:v().doneReplyText,edit:v().doneEditText,delete:v().doneDeleteText,react:``})[e],x=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:v().failedServerMessage},S=e=>e instanceof Element?e:null,C=e=>`disabled`in e&&e.disabled===!0,w=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},T=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},E=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},D=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],O=class extends r{_wired;_busy;_peopleProp;_pickerFor;_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)}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=T(this,`${h} wui-mention-input`,f);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:D(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:n}_onClick(e){let t=E(S(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!C(t)){let e=t.closest(m),n=e?this._pickerFor?.comment:t.closest(g);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=E(S(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||C(n))return;let r=n.closest(g);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=w(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(E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=T(this,m,HTMLElement),n=S(e.target);if(this._pickerFor&&t?.contains(n)){let r=D(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=E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=E(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(g),!0))}_onSubmitKey(e){let t=T(E(S(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!C(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=T(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:l(v().replyToText,{author:r}),placeholder:v().replyPlaceholder,value:``,send:v().replyLabel,opener:t})}_openEditor(e,t){let n=T(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=T(w(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:v().editCommentLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:v().saveLabel,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`,v().cancelLabel));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??=/* @__PURE__ */ new WeakMap,this._openers.set(e,a),s.focus();let u=s.querySelector(`textarea`);u?.setSelectionRange(u.value.length,u.value.length)}_button(n,r,i,a,o){let s=this.ownerDocument.createElement(`button`);return s.type=`button`,s.className=e(n,r,i),s.dataset.wui=t,s.setAttribute(`data-wui-action`,a),s.textContent=o,s}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=T(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=T(e,`:scope > .wui-comment-row`,HTMLElement),n=T(t,`[data-wui-confirm]`,HTMLElement),r=T(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),T(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=T(e,`:scope > .wui-comment-row`,HTMLElement),r=T(n,`[data-wui-confirm]`,HTMLElement),i=T(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&T(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let n=T(this,m,HTMLElement);n&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),a(t,n,{mode:`auto`,onClosed:()=>this._pickerClosed()}),T(n,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;let n=T(this,m,HTMLElement);n&&i(n),this._pickerClosed(),e&&t.button.isConnected&&t.button.focus()}_pickerClosed(){let e=T(this,m,HTMLElement),t=this._pickerFor;!t||e&&o(e)||(this._pickerFor=null,t.button.setAttribute(`aria-expanded`,`false`))}_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=E(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,v().emptyBodyMessage),n?.focus();return}let i=t.closest(g);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:w(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:w(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??T(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),b(e)&&this._announce(b(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:x(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:v().failedClientMessage};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await s(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||y(r.kind)||v().failedServerMessage}}_swapItems(e){let t=T(this,p,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=T(n.content,p,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)&&!C(i))return;let a=e=>e?D(this,g,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>T(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=T(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=T(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=D(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??T(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=T(this,`${h} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=T(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=T(this,`:scope > ${_}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{O as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./imeSafeEnter-DPs9qL3S.js";import{t as n}from"./isDrawn-BbF4phmB.js";import{t as r}from"./menuKeyNav-CstMzU08.js";import{a as i,l as a,s as o}from"./nativeOverlay-C1Rw2gIW.js";var s=`[role="menuitem"]`,c=`.wui-context-menu-sub`,l=`input.wui-context-menu-search`,u=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,d=500,f=10,p=400,m=null,h=null,g=0;function _(e,t,n){let r=document.createElement(`span`);return r.setAttribute(`aria-hidden`,`true`),r.style.cssText=n?`position:absolute;left:${e+window.scrollX}px;top:${t+window.scrollY}px;width:0;height:0;`:`position:fixed;left:${e}px;top:${t}px;width:0;height:0;`,document.body.append(r),r}var v=/* @__PURE__ */ new WeakMap;function y(e,t,n){let r=v.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return v.set(e,{region:t,cancel:n}),!0}var b=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,x=e=>`focus`in e,S=e=>[...e.childNodes].filter(e=>e.nodeType===Node.TEXT_NODE||e instanceof Element&&!e.matches(`.wui-context-menu-hint, .wui-context-menu-tick`)).map(e=>e.textContent).join(``),C=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),w=e=>[...e.children].filter(e=>e instanceof HTMLElement),T=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},E=e=>T(e,0),D=e=>T(e,1),O=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null},k=class extends e{_region;_origin;_returnFocus;_press;_swallowClick;_unbindKeys;_anchor;_closingByKey;_onContextMenu;_onContextMenuCapture;_onDocKeyDown;_onDocClick;_onPointerDown;_onPressMove;_onPressEnd;_onClickCapture;_onKeyDown;_onClick;_onInput;_onMouseMove;_onDismiss;_onPointerDownCapture;static get observedAttributes(){return[`disabled`,`open`]}constructor(){super(),this._region=null,this._origin=null,this._returnFocus=null,this._press=null,this._swallowClick=!1,this._unbindKeys=null,this._anchor=null,this._closingByKey=!1,this._onContextMenu=e=>this._handleContextMenu(e),this._onContextMenuCapture=e=>{this.isOpen&&!this._inPanel(e.target)&&!this._isKeyEcho()&&this.close()},this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._onDocClick=e=>this._handleDocClick(e),this._onPointerDown=e=>this._handlePointerDown(e),this._onPressMove=e=>{this._press&&Math.hypot(e.clientX-this._press.x,e.clientY-this._press.y)>f&&this._cancelPress()},this._onPressEnd=()=>this._cancelPress(),this._onClickCapture=e=>{if(this._swallowClick&&this._region){if(!(e.target instanceof Node))throw Error(`a click target is always a node`);this._region.contains(e.target)&&(this._swallowClick=!1,e.preventDefault(),e.stopImmediatePropagation())}},this._onKeyDown=e=>{if(this.isOpen&&this._inPanel(e.target)){if(e.key===`Escape`){if(e.stopPropagation(),this.hasAttribute(`open`)&&O(b(e.target),`[role="menu"]`)===this._panel()){e.preventDefault(),this.close(!0);return}this._closingByKey=!0}this._handleMenuKey(e)}},this._onClick=e=>this._handleClick(e),this._onInput=e=>this._handleInput(e),this._onMouseMove=e=>{let t=O(b(e.target),s);t&&this._inPanel(t)&&!this._isDisabled(t)&&t!==document.activeElement&&t.focus({preventScroll:!0})},this._onDismiss=e=>{this.hasAttribute(`open`)||e.type===`scroll`&&this._inPanel(e.target)||this.close()},this._onPointerDownCapture=()=>{this._swallowClick=!1}}connectedCallback(){this._teardown(),document.addEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.addEventListener(`contextmenu`,this._onContextMenu),document.addEventListener(`keydown`,this._onDocKeyDown),document.addEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.addEventListener(`pointerdown`,this._onPointerDown),document.addEventListener(`click`,this._onClickCapture,!0),document.addEventListener(`click`,this._onDocClick),window.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick),this.addEventListener(`input`,this._onInput),this.addEventListener(`mousemove`,this._onMouseMove),this._syncOpen()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){e===`open`?this.isConnected&&this._syncOpen():this.disabled&&this.close()}get target(){return this.getAttribute(`target`)}set target(e){e==null||e===``?this.removeAttribute(`target`):this.setAttribute(`target`,String(e))}get disabled(){return this.hasAttribute(`disabled`)}set disabled(e){this.toggleAttribute(`disabled`,!!e)}get isOpen(){let e=this._panel();return!!e&&o(e)}open(e,t,{region:n=this,origin:i=n,trigger:s=null,keyboard:c=!1}={}){let l=this._panel();if(!l)return!1;let u=new CustomEvent(`wui-context-menu:beforeopen`,{bubbles:!0,cancelable:!0,detail:{region:n,origin:i,trigger:s}});if(this.dispatchEvent(u),u.defaultPrevented)return!1;if(this._decorate(l),m&&m!==this&&m.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&x(e)?e:null}this._region=n,this._origin=i,h=null,m=this,this._unbindKeys?.(),this._unbindKeys=r(l,{items:()=>this._menuRows()}),this._anchor?.remove();let d=this.hasAttribute(`open`);return this._anchor=_(e,t,d),a(this._anchor,l,{mode:d?`manual`:`auto`,keepOffscreen:d,clampHeight:!0,onClosed:()=>this._onPanelClosed()}),window.addEventListener(`scroll`,this._onDismiss,!0),window.addEventListener(`resize`,this._onDismiss),window.addEventListener(`blur`,this._onDismiss),queueMicrotask(()=>{o(l)&&((c?this._rowsOf(l)[0]:null)??l).focus({preventScroll:!0})}),this.dispatchEvent(new CustomEvent(`wui-context-menu:open`,{bubbles:!0,detail:{region:n,origin:i,x:e,y:t}})),!0}_syncOpen(){if(!this.hasAttribute(`open`)){this.close(this._inPanel(document.activeElement));return}let e=this.target?document.querySelector(this.target):this,t=e&&this._regionRect(e);e&&t&&this.open(t.left,t.top,{region:e,origin:e})}_regionRect(e){if(e!==this)return e.getBoundingClientRect();let t=[...this.children].filter(e=>e!==this._panel()).map(e=>e.getBoundingClientRect());return t.length?{left:Math.min(...t.map(e=>e.left)),top:Math.min(...t.map(e=>e.top))}:null}close(e=!1){let t=this._panel();t&&o(t)&&(e&&(this._closingByKey=!0),i(t))}_finish(e){let t=this._panel();if(t)for(let e of C(t,c))this._setSub(e,!1);m===this&&(m=null),window.removeEventListener(`scroll`,this._onDismiss,!0),window.removeEventListener(`resize`,this._onDismiss),window.removeEventListener(`blur`,this._onDismiss),this._unbindKeys?.(),this._unbindKeys=null,this._anchor?.remove(),this._anchor=null;let n=this._returnFocus;this._returnFocus=null,e&&n?.isConnected&&n.focus({preventScroll:!0})}_onPanelClosed(){let e=this._panel();if(!e||o(e))return;let t=this._closingByKey;this._closingByKey=!1,this._finish(t)}_menuRows(){let e=b(document.activeElement);if(!e||e.matches(l))return[];let t=O(e,`[role="menu"]`);return t?this._rowsOf(t):[]}_panel(){return w(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?C(e,s).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&n(t)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=b(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(u))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=b(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=O(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return h?.menu===this&&this.isOpen&&performance.now()-h.at<p}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!v.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||y(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:b(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!v.has(e))return;if(t(e)){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;e.preventDefault(),t.trigger.click();return}if(!(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey)||this._inPanel(e.target))return;let n=this._regionFor(e.target);if(!n||!y(e,n,()=>this.close(!0)))return;let r=b(e.target);if(!r)return;let i=r.getBoundingClientRect();this.open(i.left+Math.min(16,i.width/2),i.bottom,{region:n,origin:r,keyboard:!0})&&(e.preventDefault(),h={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;let n=t.trigger.getBoundingClientRect();this.open(n.left,n.bottom,{region:t.region,origin:t.trigger,trigger:t.trigger,keyboard:e.detail===0})}_handlePointerDown(e){if(e.pointerType!==`touch`)return;let t=this._regionFor(e.target);if(!t||!y(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=b(e.target);this._press={x:n,y:r,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},d)},document.addEventListener(`pointermove`,this._onPressMove,{passive:!0}),document.addEventListener(`pointerup`,this._onPressEnd),document.addEventListener(`pointercancel`,this._onPressEnd),window.addEventListener(`scroll`,this._onPressEnd,!0)}_cancelPress(){this._press&&(clearTimeout(this._press.timer),this._press=null,document.removeEventListener(`pointermove`,this._onPressMove),document.removeEventListener(`pointerup`,this._onPressEnd),document.removeEventListener(`pointercancel`,this._onPressEnd),window.removeEventListener(`scroll`,this._onPressEnd,!0))}_handleMenuKey(e){if(!this.isOpen)return;let n=b(e.target);if(!n)return;if(n.matches(l)){this._handleSearchKey(e,n);return}let r=O(n,`[role="menu"]`);if(!r)return;let i=O(n,s),a=r.matches(`.wui-context-menu-subpanel`)?r.parentElement:null;if(e.key===`Tab`)this.close(!0);else if(e.key===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(e.key===`ArrowLeft`){if(!a)return;e.preventDefault(),this._closeSubByKey(a)}else(t(e)||e.key===` `)&&(e.preventDefault(),i?.click())}_handleSearchKey(e,t){let n=O(t,c);if(!n)return;let r=this._rowsOf(D(n));e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closeSubByKey(n)):e.key===`ArrowDown`?(e.preventDefault(),r[0]?.focus({preventScroll:!0})):e.key===`ArrowUp`?(e.preventDefault(),r[r.length-1]?.focus({preventScroll:!0})):e.key===`Tab`&&this.close(!0)}_subOf(e){return e.hasAttribute(`aria-haspopup`)&&e.parentElement?.matches(c)?e.parentElement:null}_openSub(e,t){let n=e.parentElement;if(!n)throw Error(`a submenu is always inside its menu panel`);for(let t of w(n))t!==e&&t.matches(c)&&this._closeSub(t);this._setSub(e,!0);let r=D(e).querySelector(`:scope > ${l}`),i=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;i?(i.value=``,this._filter(e,``),i.focus({preventScroll:!0})):t&&this._rowsOf(D(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of C(D(e),c))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),E(e).focus({preventScroll:!0})}_setSub(e,t){let n=D(e);t?(a(E(e),n,{mode:`auto`,beside:!0,onClosed:()=>this._onSubClosed(e)}),E(e).setAttribute(`aria-expanded`,String(o(n)))):o(n)?i(n):this._onSubClosed(e)}_onSubClosed(e){let t=D(e);if(o(t))return;let n=E(e);n.setAttribute(`aria-expanded`,`false`),t.removeAttribute(`data-side`);let r=this._closingByKey;this._closingByKey=!1,r&&n.focus({preventScroll:!0})}_filter(e,t){let n=t.trim().toLowerCase();for(let t of w(D(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(s)?t.hidden=n!==``&&!S(t).toLowerCase().includes(n):t.matches(c)&&(t.hidden=n!==``&&!S(E(t)).toLowerCase().includes(n))}_handleInput(e){let t=b(e.target)?.closest(l);if(!(t instanceof HTMLInputElement))return;let n=O(t,c);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of C(e,s)){let e=t.getAttribute(`aria-checked`)===`true`,n=t.querySelector(`:scope > .wui-context-menu-tick`);if(e&&!n){let e=document.createElement(`span`);e.className=`wui-context-menu-tick`,e.setAttribute(`aria-hidden`,`true`),t.prepend(e)}else!e&&n&&n.remove();let r=t.querySelector(`:scope > .wui-context-menu-hint`),i=t.dataset.hint;if(i){let e=r??document.createElement(`span`);r||(e.className=`wui-context-menu-hint`,e.id=`wui-context-menu-hint-${++g}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=O(b(e.target),s);if(!t||!this._inPanel(t))return;if(this._isDisabled(t)){e.preventDefault(),e.stopPropagation();return}let n=this._subOf(t);n?(e.preventDefault(),this._openSub(n,e.detail===0)):(this.close(!0),this.dispatchEvent(new CustomEvent(`wui-context-menu:select`,{bubbles:!0,detail:{key:t.dataset.key??null,item:t,region:this._region,origin:this._origin}})))}_teardown(){let e=this._panel();if(this._closingByKey=!1,e){for(let t of[...C(e,c)].reverse())i(D(t));i(e)}this._anchor&&this._finish(!1),this._cancelPress(),document.removeEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.removeEventListener(`contextmenu`,this._onContextMenu),document.removeEventListener(`keydown`,this._onDocKeyDown),document.removeEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.removeEventListener(`pointerdown`,this._onPointerDown),document.removeEventListener(`click`,this._onClickCapture,!0),document.removeEventListener(`click`,this._onDocClick),window.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`input`,this._onInput),this.removeEventListener(`mousemove`,this._onMouseMove)}};export{k as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./imeSafeEnter-DPs9qL3S.js";import{t as n}from"./isDrawn-BbF4phmB.js";import{t as r}from"./menuKeyNav-CstMzU08.js";import{a as i,l as a,s as o}from"./nativeOverlay-D3VmY8qn.js";var s=`[role="menuitem"]`,c=`.wui-context-menu-sub`,l=`input.wui-context-menu-search`,u=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,d=500,f=10,p=400,m=null,h=null,g=0;function _(e,t,n){let r=document.createElement(`span`);return r.setAttribute(`aria-hidden`,`true`),r.style.cssText=n?`position:absolute;left:${e+window.scrollX}px;top:${t+window.scrollY}px;width:0;height:0;`:`position:fixed;left:${e}px;top:${t}px;width:0;height:0;`,document.body.append(r),r}var v=/* @__PURE__ */ new WeakMap;function y(e,t,n){let r=v.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return v.set(e,{region:t,cancel:n}),!0}var b=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,x=e=>`focus`in e,S=e=>[...e.childNodes].filter(e=>e.nodeType===Node.TEXT_NODE||e instanceof Element&&!e.matches(`.wui-context-menu-hint, .wui-context-menu-tick`)).map(e=>e.textContent).join(``),C=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),w=e=>[...e.children].filter(e=>e instanceof HTMLElement),T=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},E=e=>T(e,0),D=e=>T(e,1),O=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null},k=class extends e{_region;_origin;_returnFocus;_press;_swallowClick;_unbindKeys;_anchor;_closingByKey;_onContextMenu;_onContextMenuCapture;_onDocKeyDown;_onDocClick;_onPointerDown;_onPressMove;_onPressEnd;_onClickCapture;_onKeyDown;_onClick;_onInput;_onMouseMove;_onDismiss;_onPointerDownCapture;static get observedAttributes(){return[`disabled`,`open`]}constructor(){super(),this._region=null,this._origin=null,this._returnFocus=null,this._press=null,this._swallowClick=!1,this._unbindKeys=null,this._anchor=null,this._closingByKey=!1,this._onContextMenu=e=>this._handleContextMenu(e),this._onContextMenuCapture=e=>{this.isOpen&&!this._inPanel(e.target)&&!this._isKeyEcho()&&this.close()},this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._onDocClick=e=>this._handleDocClick(e),this._onPointerDown=e=>this._handlePointerDown(e),this._onPressMove=e=>{this._press&&Math.hypot(e.clientX-this._press.x,e.clientY-this._press.y)>f&&this._cancelPress()},this._onPressEnd=()=>this._cancelPress(),this._onClickCapture=e=>{if(this._swallowClick&&this._region){if(!(e.target instanceof Node))throw Error(`a click target is always a node`);this._region.contains(e.target)&&(this._swallowClick=!1,e.preventDefault(),e.stopImmediatePropagation())}},this._onKeyDown=e=>{if(this.isOpen&&this._inPanel(e.target)){if(e.key===`Escape`){if(e.stopPropagation(),this.hasAttribute(`open`)&&O(b(e.target),`[role="menu"]`)===this._panel()){e.preventDefault(),this.close(!0);return}this._closingByKey=!0}this._handleMenuKey(e)}},this._onClick=e=>this._handleClick(e),this._onInput=e=>this._handleInput(e),this._onMouseMove=e=>{let t=O(b(e.target),s);t&&this._inPanel(t)&&!this._isDisabled(t)&&t!==document.activeElement&&t.focus({preventScroll:!0})},this._onDismiss=e=>{this.hasAttribute(`open`)||e.type===`scroll`&&this._inPanel(e.target)||this.close()},this._onPointerDownCapture=()=>{this._swallowClick=!1}}connectedCallback(){this._teardown(),document.addEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.addEventListener(`contextmenu`,this._onContextMenu),document.addEventListener(`keydown`,this._onDocKeyDown),document.addEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.addEventListener(`pointerdown`,this._onPointerDown),document.addEventListener(`click`,this._onClickCapture,!0),document.addEventListener(`click`,this._onDocClick),window.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick),this.addEventListener(`input`,this._onInput),this.addEventListener(`mousemove`,this._onMouseMove),this._syncOpen()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){e===`open`?this.isConnected&&this._syncOpen():this.disabled&&this.close()}get target(){return this.getAttribute(`target`)}set target(e){e==null||e===``?this.removeAttribute(`target`):this.setAttribute(`target`,String(e))}get disabled(){return this.hasAttribute(`disabled`)}set disabled(e){this.toggleAttribute(`disabled`,!!e)}get isOpen(){let e=this._panel();return!!e&&o(e)}open(e,t,{region:n=this,origin:i=n,trigger:s=null,keyboard:c=!1}={}){let l=this._panel();if(!l)return!1;let u=new CustomEvent(`wui-context-menu:beforeopen`,{bubbles:!0,cancelable:!0,detail:{region:n,origin:i,trigger:s}});if(this.dispatchEvent(u),u.defaultPrevented)return!1;if(this._decorate(l),m&&m!==this&&m.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&x(e)?e:null}this._region=n,this._origin=i,h=null,m=this,this._unbindKeys?.(),this._unbindKeys=r(l,{items:()=>this._menuRows()}),this._anchor?.remove();let d=this.hasAttribute(`open`);return this._anchor=_(e,t,d),a(this._anchor,l,{mode:d?`manual`:`auto`,keepOffscreen:d,clampHeight:!0,onClosed:()=>this._onPanelClosed()}),window.addEventListener(`scroll`,this._onDismiss,!0),window.addEventListener(`resize`,this._onDismiss),window.addEventListener(`blur`,this._onDismiss),queueMicrotask(()=>{o(l)&&((c?this._rowsOf(l)[0]:null)??l).focus({preventScroll:!0})}),this.dispatchEvent(new CustomEvent(`wui-context-menu:open`,{bubbles:!0,detail:{region:n,origin:i,x:e,y:t}})),!0}_syncOpen(){if(!this.hasAttribute(`open`)){this.close(this._inPanel(document.activeElement));return}let e=this.target?document.querySelector(this.target):this,t=e&&this._regionRect(e);e&&t&&this.open(t.left,t.top,{region:e,origin:e})}_regionRect(e){if(e!==this)return e.getBoundingClientRect();let t=[...this.children].filter(e=>e!==this._panel()).map(e=>e.getBoundingClientRect());return t.length?{left:Math.min(...t.map(e=>e.left)),top:Math.min(...t.map(e=>e.top))}:null}close(e=!1){let t=this._panel();t&&o(t)&&(e&&(this._closingByKey=!0),i(t))}_finish(e){let t=this._panel();if(t)for(let e of C(t,c))this._setSub(e,!1);m===this&&(m=null),window.removeEventListener(`scroll`,this._onDismiss,!0),window.removeEventListener(`resize`,this._onDismiss),window.removeEventListener(`blur`,this._onDismiss),this._unbindKeys?.(),this._unbindKeys=null,this._anchor?.remove(),this._anchor=null;let n=this._returnFocus;this._returnFocus=null,e&&n?.isConnected&&n.focus({preventScroll:!0})}_onPanelClosed(){let e=this._panel();if(!e||o(e))return;let t=this._closingByKey;this._closingByKey=!1,this._finish(t)}_menuRows(){let e=b(document.activeElement);if(!e||e.matches(l))return[];let t=O(e,`[role="menu"]`);return t?this._rowsOf(t):[]}_panel(){return w(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?C(e,s).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&n(t)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=b(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(u))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=b(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=O(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return h?.menu===this&&this.isOpen&&performance.now()-h.at<p}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!v.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||y(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:b(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!v.has(e))return;if(t(e)){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;e.preventDefault(),t.trigger.click();return}if(!(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey)||this._inPanel(e.target))return;let n=this._regionFor(e.target);if(!n||!y(e,n,()=>this.close(!0)))return;let r=b(e.target);if(!r)return;let i=r.getBoundingClientRect();this.open(i.left+Math.min(16,i.width/2),i.bottom,{region:n,origin:r,keyboard:!0})&&(e.preventDefault(),h={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;let n=t.trigger.getBoundingClientRect();this.open(n.left,n.bottom,{region:t.region,origin:t.trigger,trigger:t.trigger,keyboard:e.detail===0})}_handlePointerDown(e){if(e.pointerType!==`touch`)return;let t=this._regionFor(e.target);if(!t||!y(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=b(e.target);this._press={x:n,y:r,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},d)},document.addEventListener(`pointermove`,this._onPressMove,{passive:!0}),document.addEventListener(`pointerup`,this._onPressEnd),document.addEventListener(`pointercancel`,this._onPressEnd),window.addEventListener(`scroll`,this._onPressEnd,!0)}_cancelPress(){this._press&&(clearTimeout(this._press.timer),this._press=null,document.removeEventListener(`pointermove`,this._onPressMove),document.removeEventListener(`pointerup`,this._onPressEnd),document.removeEventListener(`pointercancel`,this._onPressEnd),window.removeEventListener(`scroll`,this._onPressEnd,!0))}_handleMenuKey(e){if(!this.isOpen)return;let n=b(e.target);if(!n)return;if(n.matches(l)){this._handleSearchKey(e,n);return}let r=O(n,`[role="menu"]`);if(!r)return;let i=O(n,s),a=r.matches(`.wui-context-menu-subpanel`)?r.parentElement:null;if(e.key===`Tab`)this.close(!0);else if(e.key===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(e.key===`ArrowLeft`){if(!a)return;e.preventDefault(),this._closeSubByKey(a)}else(t(e)||e.key===` `)&&(e.preventDefault(),i?.click())}_handleSearchKey(e,t){let n=O(t,c);if(!n)return;let r=this._rowsOf(D(n));e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closeSubByKey(n)):e.key===`ArrowDown`?(e.preventDefault(),r[0]?.focus({preventScroll:!0})):e.key===`ArrowUp`?(e.preventDefault(),r[r.length-1]?.focus({preventScroll:!0})):e.key===`Tab`&&this.close(!0)}_subOf(e){return e.hasAttribute(`aria-haspopup`)&&e.parentElement?.matches(c)?e.parentElement:null}_openSub(e,t){let n=e.parentElement;if(!n)throw Error(`a submenu is always inside its menu panel`);for(let t of w(n))t!==e&&t.matches(c)&&this._closeSub(t);this._setSub(e,!0);let r=D(e).querySelector(`:scope > ${l}`),i=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;i?(i.value=``,this._filter(e,``),i.focus({preventScroll:!0})):t&&this._rowsOf(D(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of C(D(e),c))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),E(e).focus({preventScroll:!0})}_setSub(e,t){let n=D(e);t?(a(E(e),n,{mode:`auto`,beside:!0,onClosed:()=>this._onSubClosed(e)}),E(e).setAttribute(`aria-expanded`,String(o(n)))):o(n)?i(n):this._onSubClosed(e)}_onSubClosed(e){let t=D(e);if(o(t))return;let n=E(e);n.setAttribute(`aria-expanded`,`false`),t.removeAttribute(`data-side`);let r=this._closingByKey;this._closingByKey=!1,r&&n.focus({preventScroll:!0})}_filter(e,t){let n=t.trim().toLowerCase();for(let t of w(D(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(s)?t.hidden=n!==``&&!S(t).toLowerCase().includes(n):t.matches(c)&&(t.hidden=n!==``&&!S(E(t)).toLowerCase().includes(n))}_handleInput(e){let t=b(e.target)?.closest(l);if(!(t instanceof HTMLInputElement))return;let n=O(t,c);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of C(e,s)){let e=t.getAttribute(`aria-checked`)===`true`,n=t.querySelector(`:scope > .wui-context-menu-tick`);if(e&&!n){let e=document.createElement(`span`);e.className=`wui-context-menu-tick`,e.setAttribute(`aria-hidden`,`true`),t.prepend(e)}else!e&&n&&n.remove();let r=t.querySelector(`:scope > .wui-context-menu-hint`),i=t.dataset.hint;if(i){let e=r??document.createElement(`span`);r||(e.className=`wui-context-menu-hint`,e.id=`wui-context-menu-hint-${++g}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=O(b(e.target),s);if(!t||!this._inPanel(t))return;if(this._isDisabled(t)){e.preventDefault(),e.stopPropagation();return}let n=this._subOf(t);n?(e.preventDefault(),this._openSub(n,e.detail===0)):(this.close(!0),this.dispatchEvent(new CustomEvent(`wui-context-menu:select`,{bubbles:!0,detail:{key:t.dataset.key??null,item:t,region:this._region,origin:this._origin}})))}_teardown(){let e=this._panel();if(this._closingByKey=!1,e){for(let t of[...C(e,c)].reverse())i(D(t));i(e)}this._anchor&&this._finish(!1),this._cancelPress(),document.removeEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.removeEventListener(`contextmenu`,this._onContextMenu),document.removeEventListener(`keydown`,this._onDocKeyDown),document.removeEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.removeEventListener(`pointerdown`,this._onPointerDown),document.removeEventListener(`click`,this._onClickCapture,!0),document.removeEventListener(`click`,this._onDocClick),window.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`input`,this._onInput),this.removeEventListener(`mousemove`,this._onMouseMove)}};export{k as t};
@@ -1 +1 @@
1
- import{C as e,D as t,E as n,F as r,I as i,P as a,_ as o,g as s,h as c,m as l,r as u,s as d,t as f,w as p,x as m}from"./dataTable-CKz4Oncc.js";import{t as h}from"./dom-Do1pAA12.js";import{t as g}from"./elementBase-Cxeyx0tU.js";import{t as _}from"./imeSafeEnter-DPs9qL3S.js";var v=`.wui-col-resize`,y=`.wui-group-row, .wui-virtual-spacer`,b=`.wui-select-cell, .wui-expand-cell`,x=`<svg class="wui-icon" data-icon="chevron-down" data-wui="AppIcon" width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="1.5" d="M19.92 8.95l-6.52 6.52c-.77.77-2.03.77-2.8 0L4.08 8.95"></path></svg>`;function S(e){if(e==null)throw TypeError(`Missing DOM node`);return e}function C(e,t){if(e instanceof t)return e;throw TypeError(`Missing DOM node`)}var w=e=>{let t=h(e,v);return t instanceof HTMLElement?t:null},T=e=>e.hasAttribute(`data-wui-skeleton`)||!!e.querySelector(`:scope > td > .skeleton`),E=class extends g{_frame;_headDirty;_rowsDirty;_frozenSig;_natural;_widths;_collapsed;_groupOrder;_items;_range;_drag;_userSized;_swallowClick;_mo;_ro;_fonts;_onPointerDown;_onKeyDown;_onClick;_onDblClick;_onScroll;_onFonts;_top=null;_bottom=null;_rowHeight=0;constructor(){super(),this._frame=0,this._headDirty=!0,this._rowsDirty=!0,this._frozenSig=null,this._natural=[],this._widths={},this._collapsed=/* @__PURE__ */ new Set,this._groupOrder=[],this._items=[],this._range=null,this._drag=null,this._userSized=!1,this._swallowClick=!1,this._mo=null,this._ro=null,this._fonts=null,this._onPointerDown=e=>this._startDrag(e),this._onKeyDown=e=>this._key(e),this._onClick=e=>this._click(e),this._onDblClick=e=>{let t=w(e.target);t&&this.contains(t)&&this._reset(t.closest(`th`))},this._onScroll=()=>{this.hasAttribute(`virtual`)&&this._schedule()},this._onFonts=()=>{this._userSized||this._drag||this._frozenSig===null||!this.hasAttribute(`resizable`)||(this._frozenSig=null,this._schedule())}}connectedCallback(){this._widths=n(this.getAttribute(`view-key`)),this.addEventListener(`pointerdown`,this._onPointerDown,!0),this.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick,!0),this.addEventListener(`dblclick`,this._onDblClick),this.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._fonts=this.ownerDocument.fonts??null,this._fonts?.addEventListener(`loadingdone`,this._onFonts),typeof MutationObserver<`u`&&(this._mo=new MutationObserver(e=>this._mutated(e)),this._mo.observe(this,{childList:!0,subtree:!0})),typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(()=>this._schedule()),this._ro.observe(this)),this._headDirty=!0,this._rowsDirty=!0,this._schedule()}disconnectedCallback(){this.removeEventListener(`pointerdown`,this._onPointerDown,!0),this.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick,!0),this.removeEventListener(`dblclick`,this._onDblClick),this.removeEventListener(`scroll`,this._onScroll),this._fonts?.removeEventListener(`loadingdone`,this._onFonts),this._fonts=null,this._mo?.disconnect(),this._ro?.disconnect(),this._mo=null,this._ro=null,this._frame&&cancelAnimationFrame(this._frame),this._frame=0,this._drag=null}refresh(){this._headDirty=!0,this._rowsDirty=!0,this._run()}get _table(){let e=this.querySelector(`:scope > table`);return e instanceof HTMLTableElement?e:null}_headCells(e){let t=e.tHead?.rows[0];return t?[...t.cells]:[]}_schedule(){this._frame||=requestAnimationFrame(()=>{this._frame=0,this._run()})}_mutated(e){for(let t of e){let e=t.target instanceof Element?t.target:t.target.parentElement;e&&((e.closest(`thead`)||e===this._table||e===this)&&(this._headDirty=!0),(e.closest(`tbody, tfoot`)||e===this._table||e===this)&&(this._rowsDirty=!0))}this._schedule()}_run(){let e=this._table;if(!e)return;let t=this._headDirty,n=this._rowsDirty;this._headDirty=!1,this._rowsDirty=!1,n&&this.hasAttribute(`group-by`)&&this._group(e),this._pins(e,t||n),this.hasAttribute(`resizable`)&&(t&&this._handles(e),this._layout(e)),this.hasAttribute(`virtual`)&&this._virtual(e,t||n),this._mo?.takeRecords()}_pins(t,n){let r=this._headCells(t),i=r.map(e=>{let t=e.dataset.pin;return t===`start`||t===`end`?t:e.matches(b)?`lead`:null});if(!i.some(e=>e===`start`||e===`end`))return;let a=p(i);a.forEach((e,t)=>{e&&this._ro?.observe(S(r[t]))});let o=e=>S(r[e]).getBoundingClientRect().width,s=0;a.forEach((n,r)=>{n?.side===`start`&&(this._setVar(t,e(`start`,n.ordinal),s),s+=o(r))}),s=0;for(let n=a.length-1;n>=0;n--){let r=a[n];r?.side===`end`&&(this._setVar(t,e(`end`,r.ordinal),s),s+=o(n))}if(n)for(let e of t.rows)e.matches(`${y}, .wui-row-expanded`)||e.cells.length!==r.length||a.forEach((t,n)=>{if(!t)return;let r=S(e.cells[n]);r.classList.contains(`wui-pin-${t.side}`)||r.classList.add(`wui-pin-${t.side}`),t.edge&&!r.classList.contains(`wui-pin-${t.side}-edge`)&&r.classList.add(`wui-pin-${t.side}-edge`);let i=m(t.side,t.ordinal);r.style.getPropertyValue(`--wui-pin-at`)!==i&&r.style.setProperty(u,i)})}_setVar(e,t,n){let r=`${Math.round(n*100)/100}px`;e.style.getPropertyValue(t)!==r&&e.style.setProperty(t,r)}_resizable(e){return e.map((t,n)=>n<e.length-1&&!t.matches(b))}_handles(e){let n=this._headCells(e),r=this._resizable(n);n.forEach((e,n)=>{if(!r[n]||e.querySelector(v))return;let i=e.ownerDocument.createElement(`span`);i.className=`wui-col-resize`,i.setAttribute(`role`,`separator`),i.setAttribute(`aria-orientation`,`vertical`),i.setAttribute(`aria-valuemin`,`48`),i.setAttribute(`aria-valuemax`,String(f)),i.setAttribute(`tabindex`,`0`);let a=(e.textContent??``).trim();i.setAttribute(`aria-label`,t(a)),a&&!e.hasAttribute(`aria-label`)&&e.setAttribute(`aria-label`,a),e.classList.add(`wui-col-resizable`),e.appendChild(i)})}_hasRows(e){for(let t of e.tBodies)for(let e of t.rows)if(!e.matches(y)&&!T(e))return!0;return!1}_signature(e){return e.map(e=>e.dataset.key||(e.textContent??``).trim()).join(``)}_layout(e){let t=this._headCells(e),n=this._signature(t);t.length&&n!==this._frozenSig&&(this._hasRows(e)?this._freeze(e,t,n):this._applyRemembered(t))}_applyRemembered(e){for(let t of e){let e=t.dataset.key&&this._widths[t.dataset.key];e&&(t.style.width=`${e}px`);let n=t.querySelector(v);n&&this._handleValue(n,l(e||t.getBoundingClientRect().width))}}_freeze(e,t,n){e.style.tableLayout=``,e.style.width=``,e.removeAttribute(`data-wui-fixed`);for(let e of t)e.hasAttribute(`data-wui-width`)&&(e.style.width=``,e.removeAttribute(`data-wui-width`));this._natural=t.map(e=>e.getBoundingClientRect().width),t.forEach((e,n)=>{if(n===t.length-1||e.matches(b))return;let r=e.dataset.key&&this._widths[e.dataset.key];this._setWidth(e,r||this._natural[n])}),e.style.tableLayout=`fixed`,e.setAttribute(`data-wui-fixed`,``),this._frozenSig=n,this._fitTable(e,t)}_setWidth(e,t){let n=l(t);e.style.width=`${n}px`,e.setAttribute(`data-wui-width`,``);let r=e.querySelector(v);return r&&this._handleValue(r,n),n}_handleValue(e,t){e.setAttribute(`aria-valuenow`,String(t)),e.setAttribute(`aria-valuetext`,r(t))}_fitTable(e,t){let n=t.length-1,r=this._natural[n]||0;for(let e=0;e<n;e++)r+=Number.parseFloat(S(t[e]).style.width)||this._natural[e]||0;e.style.width=`max(100%, ${Math.round(r)}px)`}_ensureFrozen(e){let t=this._headCells(e),n=this._signature(t);return n!==this._frozenSig&&this._freeze(e,t,n),t}_resizeTo(e,t,n){let r=this._table;if(!r)return;let i=this._ensureFrozen(r);this._userSized=!0,this._setWidth(e,t),this._fitTable(r,i),n&&this._remember(e),this._pins(r,!1)}_remember(e){let t=e.dataset.key;t&&(this._widths={...this._widths,[t]:Number.parseFloat(e.style.width)},i(this.getAttribute(`view-key`),this._widths))}_reset(e){let t=this._table;if(!e||!t)return;let n=this._ensureFrozen(t);this._userSized=!0;let r=e.dataset.key;if(r&&r in this._widths){let{[r]:e,...t}=this._widths;this._widths=t,i(this.getAttribute(`view-key`),this._widths)}this._setWidth(e,this._natural[n.indexOf(e)]||0),this._fitTable(t,n),this._pins(t,!1)}_rtl(){return getComputedStyle(this).direction===`rtl`}_startDrag(e){let t=w(e.target);if(!t||!this.contains(t)||e.button!==0)return;e.preventDefault(),e.stopPropagation();let n=t.closest(`th`),r=this._table;if(!n||!r)return;this._ensureFrozen(r);let i={th:n,x:e.clientX,from:n.getBoundingClientRect().width,dir:this._rtl()?-1:1,moved:!1};this._drag=i,t.setPointerCapture?.(e.pointerId),t.classList.add(`is-dragging`);let a=e=>{let t=(e.clientX-i.x)*i.dir;Math.abs(t)>1&&(i.moved=!0),this._resizeTo(n,i.from+t,!1)},o=e=>{t.removeEventListener(`pointermove`,a),t.removeEventListener(`pointerup`,o),t.removeEventListener(`pointercancel`,o),t.classList.remove(`is-dragging`),this._drag=null,e.type===`pointercancel`?this._resizeTo(n,i.from,!1):i.moved&&this._remember(n),this._swallowClick=!0,setTimeout(()=>{this._swallowClick=!1},0)};t.addEventListener(`pointermove`,a),t.addEventListener(`pointerup`,o),t.addEventListener(`pointercancel`,o)}_key(e){let t=w(e.target);if(!t||!this.contains(t))return;let n=t.closest(`th`);if(_(e)||e.key===` `){e.preventDefault(),e.stopPropagation();return}if(e.key===`Home`){e.preventDefault(),e.stopPropagation(),this._reset(n);return}if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let r=this._table;if(!r)return;this._ensureFrozen(r);let i=S(n),a=e.shiftKey?50:10,o=e.key===`ArrowRight`!==this._rtl(),s=Number.parseFloat(i.style.width)||i.getBoundingClientRect().width;this._resizeTo(i,s+(o?a:-a),!0)}_click(e){let t=e.target instanceof Element&&e.target.closest(v)!==null;if(this._swallowClick||t){e.stopPropagation(),(t||this._swallowClick)&&e.preventDefault(),this._swallowClick=!1;return}if(!this.hasAttribute(`group-by`))return;let n=h(e.target,`.wui-group-toggle`)?.closest(`.wui-group-row`);if(!(n instanceof HTMLTableRowElement)||!this.contains(n))return;let r=n.dataset.groupKey;this._collapsed.has(r)?this._collapsed.delete(r):this._collapsed.add(r),this._showGroup(n,!this._collapsed.has(r));let i=this._table;i&&this.hasAttribute(`virtual`)&&(this._virtual(i,!0),this._mo?.takeRecords())}_group(e){let t=this.getAttribute(`group-by`),n=this._headCells(e),r=n.findIndex(e=>e.dataset.key===t);if(r<0)throw Error(`<wui-data-table group-by="${t}"> needs a header cell with data-key="${t}".`);let i=e.tBodies[0];if(!i)return;let a=[...i.rows].filter(e=>!e.matches(y));if(a.some(T))return;let l=this.ownerDocument,u=/* @__PURE__ */ new Map;for(let e of i.querySelectorAll(`:scope > tr.wui-group-row`))e instanceof HTMLTableRowElement&&u.set(e.dataset.groupKey,e);let d=this.closest(`[data-wui-server]`)?[]:this._groupOrder,f=s(a,e=>e.dataset.group??e.cells[r]?.textContent?.trim()??``,d);this._groupOrder=f.map(e=>e.key);let p=l.createDocumentFragment(),m=f.map(e=>{let t=u.get(e.key)??this._groupRow(l,e.key);return u.delete(e.key),C(t.querySelector(`.wui-group-cell`),HTMLTableCellElement).colSpan=n.length,C(t.querySelector(`.wui-group-count`),HTMLElement).textContent=c(e.items.length),C(t.querySelector(`.wui-group-rows`),HTMLElement).textContent=`, ${o(e.items.length)}`,p.append(t,...e.items),[t,e.key]});for(let e of u.values())e.remove();i.insertBefore(p,this._bottom?.parentNode===i?this._bottom:null);for(let[e,t]of m)this._showGroup(e,!this._collapsed.has(t))}_groupRow(e,t){let n=e.createElement(`tr`);n.className=`wui-group-row`,n.dataset.groupKey=t;let r=e.createElement(`th`);r.className=`wui-group-cell`,r.scope=`rowgroup`;let i=e.createElement(`button`);i.type=`button`,i.className=`wui-group-toggle`,i.innerHTML=x;let a=e.createElement(`span`);a.className=`wui-group-label`,a.textContent=t;let o=e.createElement(`span`);o.className=`wui-group-count`,o.setAttribute(`aria-hidden`,`true`);let s=e.createElement(`span`);return s.className=`visually-hidden wui-group-rows`,i.append(a,o,s),r.append(i),n.append(r),n}_showGroup(e,t){if(e){e.querySelector(`.wui-group-toggle`)?.setAttribute(`aria-expanded`,String(t));for(let n=e.nextElementSibling;n&&!n.matches(y);n=n.nextElementSibling)n instanceof HTMLElement&&(n.hidden=!t)}}_spacer(e,t){if(t?.parentNode===e)return t;let n=e.ownerDocument,r=n.createElement(`tr`);return r.className=`wui-virtual-spacer`,r.setAttribute(`aria-hidden`,`true`),r.append(n.createElement(`td`)),r}_virtual(e,t){let n=e.tBodies[0];if(!n)return;if(t){this._top=this._spacer(n,this._top),this._bottom=this._spacer(n,this._bottom),n.firstElementChild!==this._top&&n.insertBefore(this._top,n.firstChild),n.lastElementChild!==this._bottom&&n.append(this._bottom);let t=Math.max(1,this._headCells(e).length);S(this._top.cells[0]).colSpan=t,S(this._bottom.cells[0]).colSpan=t,this._items=[...n.rows].filter(e=>!e.classList.contains(`wui-virtual-spacer`)&&!e.hidden),this._range=null,e.setAttribute(`aria-rowcount`,String(this._items.length+1)),e.tHead?.rows[0]?.setAttribute(`aria-rowindex`,`1`),this._items.forEach((e,t)=>{e.setAttribute(`aria-rowindex`,String(t+2))}),this._rowHeight>0||(this._rowHeight=this._measureRow(e))}let r=e.tHead?.getBoundingClientRect().height||0,i=a({scrollTop:this.scrollTop-r,viewport:this.clientHeight,rowHeight:this._rowHeight,count:this._items.length}),o=this._range;if(o&&o.start===i.start&&o.end===i.end)return;let s=o?Math.min(o.start,i.start):0,c=o?Math.max(o.end,i.end):this._items.length;for(let e=s;e<c;e++){let t=e<i.start||e>=i.end,n=S(this._items[e]);n.classList.contains(`wui-virtual-off`)!==t&&n.classList.toggle(`wui-virtual-off`,t)}this._range=i;let l=S(this._top),u=S(this._bottom);l.hidden=i.before===0,u.hidden=i.after===0,S(l.cells[0]).style.height=`${i.before}px`,S(u.cells[0]).style.height=`${i.after}px`}_measureRow(e){let t=this._items.find(e=>!e.classList.contains(`wui-group-row`)&&!e.classList.contains(`wui-virtual-off`))?.getBoundingClientRect().height??0;return t>0?t:e.classList.contains(`wui-table-compact`)?d.compact:e.classList.contains(`wui-table-cozy`)?d.cozy:d.comfortable}};export{E as t};
1
+ import{C as e,D as t,E as n,F as r,I as i,P as a,_ as o,g as s,h as c,m as l,r as u,s as d,t as f,w as p,x as m}from"./dataTable-sRTzep19.js";import{t as h}from"./dom-Do1pAA12.js";import{t as g}from"./elementBase-Cxeyx0tU.js";import{t as _}from"./imeSafeEnter-DPs9qL3S.js";var v=`.wui-col-resize`,y=`.wui-group-row, .wui-virtual-spacer`,b=`.wui-select-cell, .wui-expand-cell`,x=`<svg class="wui-icon" data-icon="chevron-down" data-wui="AppIcon" width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="1.5" d="M19.92 8.95l-6.52 6.52c-.77.77-2.03.77-2.8 0L4.08 8.95"></path></svg>`;function S(e){if(e==null)throw TypeError(`Missing DOM node`);return e}function C(e,t){if(e instanceof t)return e;throw TypeError(`Missing DOM node`)}var w=e=>{let t=h(e,v);return t instanceof HTMLElement?t:null},T=e=>e.hasAttribute(`data-wui-skeleton`)||!!e.querySelector(`:scope > td > .skeleton`),E=class extends g{_frame;_headDirty;_rowsDirty;_frozenSig;_natural;_widths;_collapsed;_groupOrder;_items;_range;_drag;_userSized;_swallowClick;_mo;_ro;_fonts;_onPointerDown;_onKeyDown;_onClick;_onDblClick;_onScroll;_onFonts;_top=null;_bottom=null;_rowHeight=0;constructor(){super(),this._frame=0,this._headDirty=!0,this._rowsDirty=!0,this._frozenSig=null,this._natural=[],this._widths={},this._collapsed=/* @__PURE__ */ new Set,this._groupOrder=[],this._items=[],this._range=null,this._drag=null,this._userSized=!1,this._swallowClick=!1,this._mo=null,this._ro=null,this._fonts=null,this._onPointerDown=e=>this._startDrag(e),this._onKeyDown=e=>this._key(e),this._onClick=e=>this._click(e),this._onDblClick=e=>{let t=w(e.target);t&&this.contains(t)&&this._reset(t.closest(`th`))},this._onScroll=()=>{this.hasAttribute(`virtual`)&&this._schedule()},this._onFonts=()=>{this._userSized||this._drag||this._frozenSig===null||!this.hasAttribute(`resizable`)||(this._frozenSig=null,this._schedule())}}connectedCallback(){this._widths=n(this.getAttribute(`view-key`)),this.addEventListener(`pointerdown`,this._onPointerDown,!0),this.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick,!0),this.addEventListener(`dblclick`,this._onDblClick),this.addEventListener(`scroll`,this._onScroll,{passive:!0}),this._fonts=this.ownerDocument.fonts??null,this._fonts?.addEventListener(`loadingdone`,this._onFonts),typeof MutationObserver<`u`&&(this._mo=new MutationObserver(e=>this._mutated(e)),this._mo.observe(this,{childList:!0,subtree:!0})),typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(()=>this._schedule()),this._ro.observe(this)),this._headDirty=!0,this._rowsDirty=!0,this._schedule()}disconnectedCallback(){this.removeEventListener(`pointerdown`,this._onPointerDown,!0),this.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick,!0),this.removeEventListener(`dblclick`,this._onDblClick),this.removeEventListener(`scroll`,this._onScroll),this._fonts?.removeEventListener(`loadingdone`,this._onFonts),this._fonts=null,this._mo?.disconnect(),this._ro?.disconnect(),this._mo=null,this._ro=null,this._frame&&cancelAnimationFrame(this._frame),this._frame=0,this._drag=null}refresh(){this._headDirty=!0,this._rowsDirty=!0,this._run()}get _table(){let e=this.querySelector(`:scope > table`);return e instanceof HTMLTableElement?e:null}_headCells(e){let t=e.tHead?.rows[0];return t?[...t.cells]:[]}_schedule(){this._frame||=requestAnimationFrame(()=>{this._frame=0,this._run()})}_mutated(e){for(let t of e){let e=t.target instanceof Element?t.target:t.target.parentElement;e&&((e.closest(`thead`)||e===this._table||e===this)&&(this._headDirty=!0),(e.closest(`tbody, tfoot`)||e===this._table||e===this)&&(this._rowsDirty=!0))}this._schedule()}_run(){let e=this._table;if(!e)return;let t=this._headDirty,n=this._rowsDirty;this._headDirty=!1,this._rowsDirty=!1,n&&this.hasAttribute(`group-by`)&&this._group(e),this._pins(e,t||n),this.hasAttribute(`resizable`)&&(t&&this._handles(e),this._layout(e)),this.hasAttribute(`virtual`)&&this._virtual(e,t||n),this._mo?.takeRecords()}_pins(t,n){let r=this._headCells(t),i=r.map(e=>{let t=e.dataset.pin;return t===`start`||t===`end`?t:e.matches(b)?`lead`:null});if(!i.some(e=>e===`start`||e===`end`))return;let a=p(i);a.forEach((e,t)=>{e&&this._ro?.observe(S(r[t]))});let o=e=>S(r[e]).getBoundingClientRect().width,s=0;a.forEach((n,r)=>{n?.side===`start`&&(this._setVar(t,e(`start`,n.ordinal),s),s+=o(r))}),s=0;for(let n=a.length-1;n>=0;n--){let r=a[n];r?.side===`end`&&(this._setVar(t,e(`end`,r.ordinal),s),s+=o(n))}if(n)for(let e of t.rows)e.matches(`${y}, .wui-row-expanded`)||e.cells.length!==r.length||a.forEach((t,n)=>{if(!t)return;let r=S(e.cells[n]);r.classList.contains(`wui-pin-${t.side}`)||r.classList.add(`wui-pin-${t.side}`),t.edge&&!r.classList.contains(`wui-pin-${t.side}-edge`)&&r.classList.add(`wui-pin-${t.side}-edge`);let i=m(t.side,t.ordinal);r.style.getPropertyValue(`--wui-pin-at`)!==i&&r.style.setProperty(u,i)})}_setVar(e,t,n){let r=`${Math.round(n*100)/100}px`;e.style.getPropertyValue(t)!==r&&e.style.setProperty(t,r)}_resizable(e){return e.map((t,n)=>n<e.length-1&&!t.matches(b))}_handles(e){let n=this._headCells(e),r=this._resizable(n);n.forEach((e,n)=>{if(!r[n]||e.querySelector(v))return;let i=e.ownerDocument.createElement(`span`);i.className=`wui-col-resize`,i.setAttribute(`role`,`separator`),i.setAttribute(`aria-orientation`,`vertical`),i.setAttribute(`aria-valuemin`,`48`),i.setAttribute(`aria-valuemax`,String(f)),i.setAttribute(`tabindex`,`0`);let a=(e.textContent??``).trim();i.setAttribute(`aria-label`,t(a)),a&&!e.hasAttribute(`aria-label`)&&e.setAttribute(`aria-label`,a),e.classList.add(`wui-col-resizable`),e.appendChild(i)})}_hasRows(e){for(let t of e.tBodies)for(let e of t.rows)if(!e.matches(y)&&!T(e))return!0;return!1}_signature(e){return e.map(e=>e.dataset.key||(e.textContent??``).trim()).join(``)}_layout(e){let t=this._headCells(e),n=this._signature(t);t.length&&n!==this._frozenSig&&(this._hasRows(e)?this._freeze(e,t,n):this._applyRemembered(t))}_applyRemembered(e){for(let t of e){let e=t.dataset.key&&this._widths[t.dataset.key];e&&(t.style.width=`${e}px`);let n=t.querySelector(v);n&&this._handleValue(n,l(e||t.getBoundingClientRect().width))}}_freeze(e,t,n){e.style.tableLayout=``,e.style.width=``,e.removeAttribute(`data-wui-fixed`);for(let e of t)e.hasAttribute(`data-wui-width`)&&(e.style.width=``,e.removeAttribute(`data-wui-width`));this._natural=t.map(e=>e.getBoundingClientRect().width),t.forEach((e,n)=>{if(n===t.length-1||e.matches(b))return;let r=e.dataset.key&&this._widths[e.dataset.key];this._setWidth(e,r||this._natural[n])}),e.style.tableLayout=`fixed`,e.setAttribute(`data-wui-fixed`,``),this._frozenSig=n,this._fitTable(e,t)}_setWidth(e,t){let n=l(t);e.style.width=`${n}px`,e.setAttribute(`data-wui-width`,``);let r=e.querySelector(v);return r&&this._handleValue(r,n),n}_handleValue(e,t){e.setAttribute(`aria-valuenow`,String(t)),e.setAttribute(`aria-valuetext`,r(t))}_fitTable(e,t){let n=t.length-1,r=this._natural[n]||0;for(let e=0;e<n;e++)r+=Number.parseFloat(S(t[e]).style.width)||this._natural[e]||0;e.style.width=`max(100%, ${Math.round(r)}px)`}_ensureFrozen(e){let t=this._headCells(e),n=this._signature(t);return n!==this._frozenSig&&this._freeze(e,t,n),t}_resizeTo(e,t,n){let r=this._table;if(!r)return;let i=this._ensureFrozen(r);this._userSized=!0,this._setWidth(e,t),this._fitTable(r,i),n&&this._remember(e),this._pins(r,!1)}_remember(e){let t=e.dataset.key;t&&(this._widths={...this._widths,[t]:Number.parseFloat(e.style.width)},i(this.getAttribute(`view-key`),this._widths))}_reset(e){let t=this._table;if(!e||!t)return;let n=this._ensureFrozen(t);this._userSized=!0;let r=e.dataset.key;if(r&&r in this._widths){let{[r]:e,...t}=this._widths;this._widths=t,i(this.getAttribute(`view-key`),this._widths)}this._setWidth(e,this._natural[n.indexOf(e)]||0),this._fitTable(t,n),this._pins(t,!1)}_rtl(){return getComputedStyle(this).direction===`rtl`}_startDrag(e){let t=w(e.target);if(!t||!this.contains(t)||e.button!==0)return;e.preventDefault(),e.stopPropagation();let n=t.closest(`th`),r=this._table;if(!n||!r)return;this._ensureFrozen(r);let i={th:n,x:e.clientX,from:n.getBoundingClientRect().width,dir:this._rtl()?-1:1,moved:!1};this._drag=i,t.setPointerCapture?.(e.pointerId),t.classList.add(`is-dragging`);let a=e=>{let t=(e.clientX-i.x)*i.dir;Math.abs(t)>1&&(i.moved=!0),this._resizeTo(n,i.from+t,!1)},o=e=>{t.removeEventListener(`pointermove`,a),t.removeEventListener(`pointerup`,o),t.removeEventListener(`pointercancel`,o),t.classList.remove(`is-dragging`),this._drag=null,e.type===`pointercancel`?this._resizeTo(n,i.from,!1):i.moved&&this._remember(n),this._swallowClick=!0,setTimeout(()=>{this._swallowClick=!1},0)};t.addEventListener(`pointermove`,a),t.addEventListener(`pointerup`,o),t.addEventListener(`pointercancel`,o)}_key(e){let t=w(e.target);if(!t||!this.contains(t))return;let n=t.closest(`th`);if(_(e)||e.key===` `){e.preventDefault(),e.stopPropagation();return}if(e.key===`Home`){e.preventDefault(),e.stopPropagation(),this._reset(n);return}if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let r=this._table;if(!r)return;this._ensureFrozen(r);let i=S(n),a=e.shiftKey?50:10,o=e.key===`ArrowRight`!==this._rtl(),s=Number.parseFloat(i.style.width)||i.getBoundingClientRect().width;this._resizeTo(i,s+(o?a:-a),!0)}_click(e){let t=e.target instanceof Element&&e.target.closest(v)!==null;if(this._swallowClick||t){e.stopPropagation(),(t||this._swallowClick)&&e.preventDefault(),this._swallowClick=!1;return}if(!this.hasAttribute(`group-by`))return;let n=h(e.target,`.wui-group-toggle`)?.closest(`.wui-group-row`);if(!(n instanceof HTMLTableRowElement)||!this.contains(n))return;let r=n.dataset.groupKey;this._collapsed.has(r)?this._collapsed.delete(r):this._collapsed.add(r),this._showGroup(n,!this._collapsed.has(r));let i=this._table;i&&this.hasAttribute(`virtual`)&&(this._virtual(i,!0),this._mo?.takeRecords())}_group(e){let t=this.getAttribute(`group-by`),n=this._headCells(e),r=n.findIndex(e=>e.dataset.key===t);if(r<0)throw Error(`<wui-data-table group-by="${t}"> needs a header cell with data-key="${t}".`);let i=e.tBodies[0];if(!i)return;let a=[...i.rows].filter(e=>!e.matches(y));if(a.some(T))return;let l=this.ownerDocument,u=/* @__PURE__ */ new Map;for(let e of i.querySelectorAll(`:scope > tr.wui-group-row`))e instanceof HTMLTableRowElement&&u.set(e.dataset.groupKey,e);let d=this.closest(`[data-wui-server]`)?[]:this._groupOrder,f=s(a,e=>e.dataset.group??e.cells[r]?.textContent?.trim()??``,d);this._groupOrder=f.map(e=>e.key);let p=l.createDocumentFragment(),m=f.map(e=>{let t=u.get(e.key)??this._groupRow(l,e.key);return u.delete(e.key),C(t.querySelector(`.wui-group-cell`),HTMLTableCellElement).colSpan=n.length,C(t.querySelector(`.wui-group-count`),HTMLElement).textContent=c(e.items.length),C(t.querySelector(`.wui-group-rows`),HTMLElement).textContent=`, ${o(e.items.length)}`,p.append(t,...e.items),[t,e.key]});for(let e of u.values())e.remove();i.insertBefore(p,this._bottom?.parentNode===i?this._bottom:null);for(let[e,t]of m)this._showGroup(e,!this._collapsed.has(t))}_groupRow(e,t){let n=e.createElement(`tr`);n.className=`wui-group-row`,n.dataset.groupKey=t;let r=e.createElement(`th`);r.className=`wui-group-cell`,r.scope=`rowgroup`;let i=e.createElement(`button`);i.type=`button`,i.className=`wui-group-toggle`,i.innerHTML=x;let a=e.createElement(`span`);a.className=`wui-group-label`,a.textContent=t;let o=e.createElement(`span`);o.className=`wui-group-count`,o.setAttribute(`aria-hidden`,`true`);let s=e.createElement(`span`);return s.className=`visually-hidden wui-group-rows`,i.append(a,o,s),r.append(i),n.append(r),n}_showGroup(e,t){if(e){e.querySelector(`.wui-group-toggle`)?.setAttribute(`aria-expanded`,String(t));for(let n=e.nextElementSibling;n&&!n.matches(y);n=n.nextElementSibling)n instanceof HTMLElement&&(n.hidden=!t)}}_spacer(e,t){if(t?.parentNode===e)return t;let n=e.ownerDocument,r=n.createElement(`tr`);return r.className=`wui-virtual-spacer`,r.setAttribute(`aria-hidden`,`true`),r.append(n.createElement(`td`)),r}_virtual(e,t){let n=e.tBodies[0];if(!n)return;if(t){this._top=this._spacer(n,this._top),this._bottom=this._spacer(n,this._bottom),n.firstElementChild!==this._top&&n.insertBefore(this._top,n.firstChild),n.lastElementChild!==this._bottom&&n.append(this._bottom);let t=Math.max(1,this._headCells(e).length);S(this._top.cells[0]).colSpan=t,S(this._bottom.cells[0]).colSpan=t,this._items=[...n.rows].filter(e=>!e.classList.contains(`wui-virtual-spacer`)&&!e.hidden),this._range=null,e.setAttribute(`aria-rowcount`,String(this._items.length+1)),e.tHead?.rows[0]?.setAttribute(`aria-rowindex`,`1`),this._items.forEach((e,t)=>{e.setAttribute(`aria-rowindex`,String(t+2))}),this._rowHeight>0||(this._rowHeight=this._measureRow(e))}let r=e.tHead?.getBoundingClientRect().height||0,i=a({scrollTop:this.scrollTop-r,viewport:this.clientHeight,rowHeight:this._rowHeight,count:this._items.length}),o=this._range;if(o&&o.start===i.start&&o.end===i.end)return;let s=o?Math.min(o.start,i.start):0,c=o?Math.max(o.end,i.end):this._items.length;for(let e=s;e<c;e++){let t=e<i.start||e>=i.end,n=S(this._items[e]);n.classList.contains(`wui-virtual-off`)!==t&&n.classList.toggle(`wui-virtual-off`,t)}this._range=i;let l=S(this._top),u=S(this._bottom);l.hidden=i.before===0,u.hidden=i.after===0,S(l.cells[0]).style.height=`${i.before}px`,S(u.cells[0]).style.height=`${i.after}px`}_measureRow(e){let t=this._items.find(e=>!e.classList.contains(`wui-group-row`)&&!e.classList.contains(`wui-virtual-off`))?.getBoundingClientRect().height??0;return t>0?t:e.classList.contains(`wui-table-compact`)?d.compact:e.classList.contains(`wui-table-cozy`)?d.cozy:d.comfortable}};export{E as t};
@@ -1,4 +1,4 @@
1
- import{a as e,i as t,n,o as r,r as i,t as a}from"./calendarMath-CFjBxJYM.js";import{r as o}from"./dom-Do1pAA12.js";import{t as s}from"./elementBase-Cxeyx0tU.js";import{r as c,t as l}from"./fieldState-D-zQcXUS.js";import{_ as u,b as d,g as f}from"./formatters-Dy4kQQ_h.js";import{t as p}from"./formMirror-9IpSgeZb.js";import{t as m}from"./iconGlyphs.g-DxSJLQJ8.js";import{a as h,l as g,s as _}from"./nativeOverlay-C1Rw2gIW.js";import{n as v}from"./optionLabel-B2cU4Ax0.js";import{r as y}from"./textStore-opIEM4lu.js";import{t as b}from"./datePicker.g-CT9FBY21.js";var x=()=>y(`datePicker`,b),S=class extends s{static formAssociated=!0;static get observedAttributes(){return[`value`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`disabled-weekdays`,`display-format`,`size`,`aria-label`,`aria-describedby`,`aria-invalid`]}_internals;_value;_defaultValue;_rendered;_viewY;_viewM;_mode;_focus;_slide;_viewNavigated;_openFn;_closeFn;_onKeyBound;_closingQuietly;get _open(){return o(this._openFn,`open missing`)}get _close(){return o(this._closeFn,`close missing`)}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._value=``;let e=new Date(2e3,0,1);this._viewY=e.getFullYear(),this._viewM=e.getMonth(),this._mode=`days`,this._focus=null,this._slide=``}connectedCallback(){this._rendered||this.render()}disconnectedCallback(){this._dropPanel()}attributeChangedCallback(e,t,n){if(e===`aria-invalid`)this._syncInvalid();else if(this._rendered){if(e===`value`)this._value=n||``,this._syncFormValue(),this._syncTrigger();else if(e===`display-format`)this._syncTrigger();else if(e===`first-day`){let e=this.querySelector(`.datepicker-pop`);e instanceof HTMLDivElement&&_(e)&&this._renderView()}else this.render()}}_syncInvalid(){let e=this.querySelector(`.datepicker-trigger`);e instanceof HTMLButtonElement&&(this.hasAttribute(`aria-invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`))}formResetCallback(){this.value=this._defaultValue||``}get value(){return this._value}set value(e){this._value=e||``,p(this,this._value),this._syncTrigger()}_firstDay(){return i(this)}render(){this._dropPanel(),this._defaultValue===void 0&&(this._defaultValue=this.getAttribute(`value`)||``,this._value=this._defaultValue||this._value);let n=this.getAttribute(`placeholder`)||x().placeholder,r=e(this._value);r&&(this._viewY=r.y,this._viewM=r.m);let i=this.getAttribute(`size`),a=i===`sm`?` wui-input-sm`:i===`lg`?` wui-input-lg`:i===`xl`?` wui-input-xl`:``,o=this.getAttribute(`aria-label`),s=this.getAttribute(`aria-describedby`);this.innerHTML=`
1
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./calendarMath-ChZ_s7HH.js";import{r as o}from"./dom-Do1pAA12.js";import{t as s}from"./elementBase-Cxeyx0tU.js";import{r as c,t as l}from"./fieldState-D-zQcXUS.js";import{_ as u,b as d,g as f}from"./formatters-CMTSYlW9.js";import{t as p}from"./formMirror-9IpSgeZb.js";import{t as m}from"./iconGlyphs.g-DxSJLQJ8.js";import{a as h,l as g,s as _}from"./nativeOverlay-D3VmY8qn.js";import{n as v}from"./optionLabel-B2cU4Ax0.js";import{r as y}from"./textStore-opIEM4lu.js";import{t as b}from"./datePicker.g-CT9FBY21.js";var x=()=>y(`datePicker`,b),S=class extends s{static formAssociated=!0;static get observedAttributes(){return[`value`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`disabled-weekdays`,`display-format`,`size`,`aria-label`,`aria-describedby`,`aria-invalid`]}_internals;_value;_defaultValue;_rendered;_viewY;_viewM;_mode;_focus;_slide;_viewNavigated;_openFn;_closeFn;_onKeyBound;_closingQuietly;get _open(){return o(this._openFn,`open missing`)}get _close(){return o(this._closeFn,`close missing`)}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._value=``;let e=new Date(2e3,0,1);this._viewY=e.getFullYear(),this._viewM=e.getMonth(),this._mode=`days`,this._focus=null,this._slide=``}connectedCallback(){this._rendered||this.render()}disconnectedCallback(){this._dropPanel()}attributeChangedCallback(e,t,n){if(e===`aria-invalid`)this._syncInvalid();else if(this._rendered){if(e===`value`)this._value=n||``,this._syncFormValue(),this._syncTrigger();else if(e===`display-format`)this._syncTrigger();else if(e===`first-day`){let e=this.querySelector(`.datepicker-pop`);e instanceof HTMLDivElement&&_(e)&&this._renderView()}else this.render()}}_syncInvalid(){let e=this.querySelector(`.datepicker-trigger`);e instanceof HTMLButtonElement&&(this.hasAttribute(`aria-invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`))}formResetCallback(){this.value=this._defaultValue||``}get value(){return this._value}set value(e){this._value=e||``,p(this,this._value),this._syncTrigger()}_firstDay(){return i(this)}render(){this._dropPanel(),this._defaultValue===void 0&&(this._defaultValue=this.getAttribute(`value`)||``,this._value=this._defaultValue||this._value);let n=this.getAttribute(`placeholder`)||x().placeholder,r=e(this._value);r&&(this._viewY=r.y,this._viewM=r.m);let i=this.getAttribute(`size`),a=i===`sm`?` wui-input-sm`:i===`lg`?` wui-input-lg`:i===`xl`?` wui-input-xl`:``,o=this.getAttribute(`aria-label`),s=this.getAttribute(`aria-describedby`);this.innerHTML=`
2
2
  <div class="datepicker">
3
3
  <button type="button" class="input datepicker-trigger${a}${r?` has-value`:``}" aria-haspopup="dialog" aria-expanded="false"${this.hasAttribute(`aria-invalid`)?` aria-invalid="true"`:``}${this.hasAttribute(`disabled`)?` disabled`:``}${o?` aria-label="${v(o)}"`:``}${s?` aria-describedby="${v(s)}"`:``}>
4
4
  <span data-trigger-label class="${r?``:`wui-select-placeholder`}">${v(r?t(this._value,this.getAttribute(`display-format`)):n)}</span>
@@ -1,4 +1,4 @@
1
- import{a as e,i as t,n,o as r,r as i,t as a}from"./calendarMath-CFjBxJYM.js";import{n as o}from"./devWarn-DXdRWZs3.js";import{r as s,t as c}from"./textStore-opIEM4lu.js";import{t as l}from"./dateRangePicker.g-Pnc37vgX.js";import{C as u,S as d,_ as f,b as p,x as m}from"./formatters-Dy4kQQ_h.js";import{t as h}from"./elementBase-Cxeyx0tU.js";import{r as g,t as _}from"./fieldState-D-zQcXUS.js";import{t as v}from"./iconGlyphs.g-DxSJLQJ8.js";import{a as y,l as b,s as x}from"./nativeOverlay-C1Rw2gIW.js";import{n as S}from"./optionLabel-B2cU4Ax0.js";var C=4,w=[`today`,`yesterday`,`last7Days`,`last30Days`,`thisMonth`,`lastMonth`,`thisFinancialYear`],T={today:`todayLabel`,yesterday:`yesterdayLabel`,last7Days:`last7DaysLabel`,last30Days:`last30DaysLabel`,thisMonth:`thisMonthLabel`,lastMonth:`lastMonthLabel`,thisFinancialYear:`thisFinancialYearLabel`},E=e=>String(e).padStart(2,`0`),D=e=>`${e.getUTCFullYear()}-${E(e.getUTCMonth()+1)}-${E(e.getUTCDate())}`;function O(e){return w.includes(e)}function k(t,n=/* @__PURE__ */ new Date,{timeZone:r=m,financialYearStart:i=C}={}){if(!O(t))return null;let a=e(u(r,n));if(!a)throw Error(`today missing`);let{y:o,m:c,d}=a,f=(e,t,n)=>D(new Date(Date.UTC(e,t,n))),p=s(`dateRangePicker`,l)[T[t]];switch(t){case`today`:return{label:p,start:f(o,c,d),end:f(o,c,d)};case`yesterday`:return{label:p,start:f(o,c,d-1),end:f(o,c,d-1)};case`last7Days`:return{label:p,start:f(o,c,d-6),end:f(o,c,d)};case`last30Days`:return{label:p,start:f(o,c,d-29),end:f(o,c,d)};case`thisMonth`:return{label:p,start:f(o,c,1),end:f(o,c+1,0)};case`lastMonth`:return{label:p,start:f(o,c-1,1),end:f(o,c,0)};case`thisFinancialYear`:{let e=i-1,t=c>=e?o:o-1;return{label:p,start:f(t,e,1),end:f(t+1,e,0)}}default:return null}}function A(e){o(`[@webority/ui-elements] <wui-date-range> presets: ${e}`)}function j(e){return typeof e==`object`&&!!e}function M(t,n=/* @__PURE__ */ new Date,r={}){let i=String(t??``).trim();if(!i)return[];let a;if(i.startsWith(`[`))try{a=JSON.parse(i)}catch{return A(`the attribute is not valid JSON`),[]}else a=i.split(`,`).map(e=>e.trim());let o=[];for(let t of a)if(typeof t==`string`){let e=k(t,n,r);e?o.push(e):A(`"${t}" is not one of ${w.join(`, `)}`)}else j(t)&&typeof t.label==`string`&&t.label&&typeof t.start==`string`&&typeof t.end==`string`&&e(t.start)&&e(t.end)?o.push({label:t.label,start:t.start,end:t.end}):A(`an item needs a label and ISO start and end dates, or a preset name`);return o}var N=()=>s(`dateRangePicker`,l);function P(e){if(!(e.target instanceof Element))throw Error(`Expected the event target to be an element.`);return e.target}function F(e,t){return[...e.querySelectorAll(t)].map(e=>{if(!(e instanceof HTMLElement))throw Error(`Expected every "${t}" to be an HTML element.`);return e})}var I=class extends h{static formAssociated=!0;_internals;_start;_end;_hover;_viewY;_viewM;get open(){return this.querySelector(`.daterange`)?.classList.contains(`open`)??!1}set open(e){e?!_(this)&&!this.open&&this._open?.():this.open&&this._close?.()}static get observedAttributes(){return[`start`,`end`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`size`,`aria-label`,`aria-describedby`,`name`,`start-name`,`end-name`,`presets`,`time-zone`,`financial-year-start`,`aria-invalid`]}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._start=``,this._end=``,this._hover=``;let e=new Date(2e3,0,1);this._viewY=e.getFullYear(),this._viewM=e.getMonth()}connectedCallback(){this._rendered||this.render()}disconnectedCallback(){this._dropPanel()}attributeChangedCallback(e,t,n){e===`aria-invalid`?this._syncInvalid():this._rendered&&(e===`start`||e===`end`?(this._start=this.getAttribute(`start`)||``,this._end=this.getAttribute(`end`)||``,this._syncTrigger(),this._syncMirrors()):this.render())}_syncInvalid(){let e=this.querySelector(`.daterange-trigger`);e&&(this.hasAttribute(`aria-invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`))}get value(){return{start:this._start,end:this._end}}set value(e){this._start=e?.start||``,this._end=e?.end||``,this._syncTrigger(),this._syncMirrors()}_firstDay(){return i(this)}_label(){let e=this.getAttribute(`placeholder`)||N().placeholder;return!this._start&&!this._end?{text:e,empty:!0}:{text:c(N().rangeText,{start:t(this._start)||N().startLabel,end:t(this._end)||N().endLabel}),empty:!1}}render(){this._dropPanel(),this._defaultStart===void 0&&(this._defaultStart=this.getAttribute(`start`)||``,this._defaultEnd=this.getAttribute(`end`)||``,this._start=this._defaultStart||this._start,this._end=this._defaultEnd||this._end);let t=e(this._start);t&&(this._viewY=t.y,this._viewM=t.m);let n=this.getAttribute(`size`),r=n===`sm`?` wui-input-sm`:n===`lg`?` wui-input-lg`:n===`xl`?` wui-input-xl`:``,{text:i,empty:a}=this._label(),o=this.getAttribute(`aria-label`),s=this.getAttribute(`aria-describedby`);this.innerHTML=`
1
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./calendarMath-ChZ_s7HH.js";import{n as o}from"./devWarn-DXdRWZs3.js";import{r as s,t as c}from"./textStore-opIEM4lu.js";import{t as l}from"./dateRangePicker.g-Pnc37vgX.js";import{C as u,S as d,_ as f,b as p,x as m}from"./formatters-CMTSYlW9.js";import{t as h}from"./elementBase-Cxeyx0tU.js";import{r as g,t as _}from"./fieldState-D-zQcXUS.js";import{t as v}from"./iconGlyphs.g-DxSJLQJ8.js";import{a as y,l as b,s as x}from"./nativeOverlay-D3VmY8qn.js";import{n as S}from"./optionLabel-B2cU4Ax0.js";var C=4,w=[`today`,`yesterday`,`last7Days`,`last30Days`,`thisMonth`,`lastMonth`,`thisFinancialYear`],T={today:`todayLabel`,yesterday:`yesterdayLabel`,last7Days:`last7DaysLabel`,last30Days:`last30DaysLabel`,thisMonth:`thisMonthLabel`,lastMonth:`lastMonthLabel`,thisFinancialYear:`thisFinancialYearLabel`},E=e=>String(e).padStart(2,`0`),D=e=>`${e.getUTCFullYear()}-${E(e.getUTCMonth()+1)}-${E(e.getUTCDate())}`;function O(e){return w.includes(e)}function k(t,n=/* @__PURE__ */ new Date,{timeZone:r=m,financialYearStart:i=C}={}){if(!O(t))return null;let a=e(u(r,n));if(!a)throw Error(`today missing`);let{y:o,m:c,d}=a,f=(e,t,n)=>D(new Date(Date.UTC(e,t,n))),p=s(`dateRangePicker`,l)[T[t]];switch(t){case`today`:return{label:p,start:f(o,c,d),end:f(o,c,d)};case`yesterday`:return{label:p,start:f(o,c,d-1),end:f(o,c,d-1)};case`last7Days`:return{label:p,start:f(o,c,d-6),end:f(o,c,d)};case`last30Days`:return{label:p,start:f(o,c,d-29),end:f(o,c,d)};case`thisMonth`:return{label:p,start:f(o,c,1),end:f(o,c+1,0)};case`lastMonth`:return{label:p,start:f(o,c-1,1),end:f(o,c,0)};case`thisFinancialYear`:{let e=i-1,t=c>=e?o:o-1;return{label:p,start:f(t,e,1),end:f(t+1,e,0)}}default:return null}}function A(e){o(`[@webority/ui-elements] <wui-date-range> presets: ${e}`)}function j(e){return typeof e==`object`&&!!e}function M(t,n=/* @__PURE__ */ new Date,r={}){let i=String(t??``).trim();if(!i)return[];let a;if(i.startsWith(`[`))try{a=JSON.parse(i)}catch{return A(`the attribute is not valid JSON`),[]}else a=i.split(`,`).map(e=>e.trim());let o=[];for(let t of a)if(typeof t==`string`){let e=k(t,n,r);e?o.push(e):A(`"${t}" is not one of ${w.join(`, `)}`)}else j(t)&&typeof t.label==`string`&&t.label&&typeof t.start==`string`&&typeof t.end==`string`&&e(t.start)&&e(t.end)?o.push({label:t.label,start:t.start,end:t.end}):A(`an item needs a label and ISO start and end dates, or a preset name`);return o}var N=()=>s(`dateRangePicker`,l);function P(e){if(!(e.target instanceof Element))throw Error(`Expected the event target to be an element.`);return e.target}function F(e,t){return[...e.querySelectorAll(t)].map(e=>{if(!(e instanceof HTMLElement))throw Error(`Expected every "${t}" to be an HTML element.`);return e})}var I=class extends h{static formAssociated=!0;_internals;_start;_end;_hover;_viewY;_viewM;get open(){return this.querySelector(`.daterange`)?.classList.contains(`open`)??!1}set open(e){e?!_(this)&&!this.open&&this._open?.():this.open&&this._close?.()}static get observedAttributes(){return[`start`,`end`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`size`,`aria-label`,`aria-describedby`,`name`,`start-name`,`end-name`,`presets`,`time-zone`,`financial-year-start`,`aria-invalid`]}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._start=``,this._end=``,this._hover=``;let e=new Date(2e3,0,1);this._viewY=e.getFullYear(),this._viewM=e.getMonth()}connectedCallback(){this._rendered||this.render()}disconnectedCallback(){this._dropPanel()}attributeChangedCallback(e,t,n){e===`aria-invalid`?this._syncInvalid():this._rendered&&(e===`start`||e===`end`?(this._start=this.getAttribute(`start`)||``,this._end=this.getAttribute(`end`)||``,this._syncTrigger(),this._syncMirrors()):this.render())}_syncInvalid(){let e=this.querySelector(`.daterange-trigger`);e&&(this.hasAttribute(`aria-invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`))}get value(){return{start:this._start,end:this._end}}set value(e){this._start=e?.start||``,this._end=e?.end||``,this._syncTrigger(),this._syncMirrors()}_firstDay(){return i(this)}_label(){let e=this.getAttribute(`placeholder`)||N().placeholder;return!this._start&&!this._end?{text:e,empty:!0}:{text:c(N().rangeText,{start:t(this._start)||N().startLabel,end:t(this._end)||N().endLabel}),empty:!1}}render(){this._dropPanel(),this._defaultStart===void 0&&(this._defaultStart=this.getAttribute(`start`)||``,this._defaultEnd=this.getAttribute(`end`)||``,this._start=this._defaultStart||this._start,this._end=this._defaultEnd||this._end);let t=e(this._start);t&&(this._viewY=t.y,this._viewM=t.m);let n=this.getAttribute(`size`),r=n===`sm`?` wui-input-sm`:n===`lg`?` wui-input-lg`:n===`xl`?` wui-input-xl`:``,{text:i,empty:a}=this._label(),o=this.getAttribute(`aria-label`),s=this.getAttribute(`aria-describedby`);this.innerHTML=`
2
2
  <div class="daterange">
3
3
  <button type="button" class="input daterange-trigger${r}${a?``:` has-value`}" aria-haspopup="dialog" aria-expanded="false"${this.hasAttribute(`aria-invalid`)?` aria-invalid="true"`:``}${this.hasAttribute(`disabled`)?` disabled`:``}${o?` aria-label="${S(o)}"`:``}${s?` aria-describedby="${S(s)}"`:``}>
4
4
  <span data-range-label class="${a?`wui-select-placeholder`:``}">${S(i)}</span>
@@ -1 +1 @@
1
- import{r as e}from"./dom-Do1pAA12.js";import{t}from"./elementBase-Cxeyx0tU.js";import{h as n,o as r,p as i,u as a}from"./nativeOverlay-C1Rw2gIW.js";import{r as o,t as s}from"./textStore-opIEM4lu.js";import{t as c}from"./drawer.g-B-zYKBfQ.js";var l=[50,90],u=10,d=100;function f(e,t=l){let n=Array.isArray(e)?e:String(e??``).split(`,`),r=[];for(let e of n){if(typeof e==`string`&&e.trim()===``)return t;let n=Number(e);if(!Number.isFinite(n)||n<u||n>d)return t;r.includes(n)||r.push(n)}return r.length?r.sort((e,t)=>e-t):t}function p(e){let{points:t,index:n,visible:r,velocity:i,canDismiss:a}=e,o=a?-1:0;if(Math.abs(i)>=.5)return i>0?Math.max(n-1,o):Math.min(n+1,t.length-1);let s=t[0];if(a&&s!==void 0&&r<s/2)return-1;let c=0;for(let e=1;e<t.length;e++){let n=t[e],i=t[c];if(n===void 0||i===void 0)throw Error(`snap point missing`);Math.abs(n-r)<Math.abs(i-r)&&(c=e)}return c}var m=()=>o(`drawer`,c),h=`(max-width: 767.98px)`,g=4;function _(e,t){let n=e[t];if(n===void 0)throw RangeError(`no snap point at ${t}`);return n}var v=class extends t{_doc;_media;_shown;_trigger;_returnTo;_release;_snap;_drag;_onMedia;_onPointerDown;_onPointerMove;_onPointerUp;_onKeyDown;_onTransitionEnd;_settled;static get observedAttributes(){return[`open`,`snap-points`,`no-sheet`]}constructor(){super(),this._doc=null,this._media=null,this._shown=!1,this._trigger=null,this._returnTo=null,this._release=null,this._snap=0,this._drag=null,this._onMedia=()=>this._syncMode(),this._onPointerDown=e=>this._pointerDown(e),this._onPointerMove=e=>this._pointerMove(e),this._onPointerUp=e=>this._pointerUp(e),this._onKeyDown=e=>this._keyDown(e),this._onTransitionEnd=e=>{e.target===this._panel()&&e.propertyName===`transform`&&this.isOpen&&this._announce()},this._settled=!1}connectedCallback(){this._doc=this.ownerDocument,n(this._doc),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`transitionend`,this._onTransitionEnd),this._media=typeof matchMedia==`function`?matchMedia(h):null,this._media?.addEventListener?.(`change`,this._onMedia),this._syncMode(),this._applyPoints(),this.hasAttribute(`open`)&&this._open()}disconnectedCallback(){this._endDrag(),this._teardown(),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`pointerdown`,this._onPointerDown),this.removeEventListener(`transitionend`,this._onTransitionEnd),this._media?.removeEventListener?.(`change`,this._onMedia),this._media=null,this._doc=null}attributeChangedCallback(e){this._doc&&(e===`open`?this.hasAttribute(`open`)?this._open():this._close():e===`no-sheet`?this._syncMode():(this._snap=Math.min(this._snap,this._points().length-1),this._applyPoints()))}get isOpen(){return this.hasAttribute(`open`)}show(e){this._trigger=e??null,this.setAttribute(`open`,``)}hide(){this.removeAttribute(`open`)}_points(){return f(this.getAttribute(`snap-points`),l)}_sheet(){return!!this._media?.matches&&!this.hasAttribute(`no-sheet`)}_syncMode(){this.setAttribute(`data-mode`,this._sheet()?`sheet`:`side`)}_applyPoints(){let t=this._points();this._snap=Math.min(Math.max(this._snap,0),t.length-1),this.style.setProperty(`--wui-drawer-max`,String(t[t.length-1])),this.style.setProperty(`--wui-drawer-snap`,String(t[this._snap])),this.setAttribute(`data-snap`,String(this._snap));let n=this.querySelector(`.wui-drawer-handle`);if(!(n instanceof Element))return;let r=e(t[this._snap],`The drawer has no snap point to report.`);n.setAttribute(`aria-valuemin`,String(t[0])),n.setAttribute(`aria-valuemax`,String(t[t.length-1])),n.setAttribute(`aria-valuenow`,String(r)),n.setAttribute(`aria-valuetext`,s(m().screenText,{now:r}))}_setSnap(e){let t=this._points(),n=Math.min(Math.max(e,0),t.length-1),r=n!==this._snap;this._snap=n,this._applyPoints(),r&&this.dispatchEvent(new CustomEvent(`wui-drawer-snap`,{bubbles:!0,detail:{index:n,percent:t[n]}}))}_open(){if(this._shown)return;let e=this._dialog();this._shown=!0,this._settled=null;let t=Number.parseInt(this.getAttribute(`default-snap`)??`0`,10);this._snap=Number.isFinite(t)?t:0,this._syncMode(),this._applyPoints(),this.dispatchEvent(new CustomEvent(`wui-drawer-open`,{bubbles:!0,detail:{trigger:this._trigger}})),this._returnTo=this._trigger,this._trigger=null,this._release=a(e,{escape:this._dismissible(),backdrop:this._dismissible(),focus:this._sheet()?`panel`:`first-control`,onRequestClose:e=>this._requestClose(e)}),this._settle()}_close(){if(!this._shown)return;this._endDrag(),this._shown=!1,this._settled=null;let e=this._release;this._release=null;let t=this._dialog();r(t).then(()=>{e?.(),i(this._returnTo,t),this._returnTo=null,this._announce()})}_teardown(){this._shown=!1;let e=this._release;this._release=null,e&&(e(),this._panel()?.close())}_settle(){(this._panel()?.getAnimations?.()??[]).length||this._announce()}_announce(){let e=this.isOpen;e!==this._settled&&(this._settled=e,this.dispatchEvent(new CustomEvent(e?`wui-drawer-opened`:`wui-drawer-closed`,{bubbles:!0})))}_document(){let e=this._doc;if(!e)throw TypeError(`wui-drawer is not connected`);return e}_panel(){let e=this.querySelector(`.wui-drawer-panel`);return e instanceof HTMLDialogElement?e:null}_dialog(){let e=this._panel();if(!e)throw TypeError(`wui-drawer has no dialog panel`);return e}_dismissible(){return!this.hasAttribute(`static`)&&!this.hasAttribute(`no-dismiss`)}_requestClose(e){let t=this.dispatchEvent(new CustomEvent(`wui-drawer-close`,{bubbles:!0,cancelable:!0,detail:{reason:e}}));return t&&this.hide(),t}_keyDown(e){e.target instanceof Element&&e.target.closest(`.wui-drawer-handle`)&&this._sheet()&&this._handleKey(e)}_handleKey(e){let t=this._points().length-1,n={ArrowUp:this._snap+1,ArrowDown:this._snap-1,Home:0,End:t};if(!(e.key in n))return;let r=n[e.key];r!==void 0&&(e.preventDefault(),this._setSnap(r))}_pointerDown(e){if(!this.isOpen||!this._sheet()||(e.button??0)!==0)return;let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[data-wui-drawer-grip]`);n instanceof HTMLElement&&!t.closest(`button`)&&(this._drag={grip:n,id:e.pointerId,startY:e.clientY,lastY:e.clientY,lastT:e.timeStamp,velocity:0,moved:!1},n.setPointerCapture?.(e.pointerId),n.addEventListener(`pointermove`,this._onPointerMove),n.addEventListener(`pointerup`,this._onPointerUp),n.addEventListener(`pointercancel`,this._onPointerUp))}_viewport(){let e=this._document().defaultView;if(!e)throw TypeError(`wui-drawer has no window`);return e.innerHeight}_pointerMove(e){let t=this._drag;if(!t||e.pointerId!==t.id)return;let n=e.clientY-t.startY;if(!t.moved&&Math.abs(n)<g)return;t.moved=!0,this.classList.add(`is-dragging`);let r=e.timeStamp-t.lastT;r>0&&(t.velocity=(e.clientY-t.lastY)/r),t.lastY=e.clientY,t.lastT=e.timeStamp;let i=this._points(),a=(_(i,i.length-1)-_(i,this._snap))/100*this._viewport();t.offset=Math.max(n,-a),this.style.setProperty(`--wui-drawer-drag`,`${t.offset}px`)}_pointerUp(e){let t=this._drag;if(!t||e.pointerId!==t.id)return;let{moved:n,velocity:r,offset:i=0}=t;if(this._endDrag(),!n)return;let a=this._points(),o=this._viewport(),s=(_(a,this._snap)/100*o-i)/(o/100),c=this._dismissible(),l=p({points:a,index:this._snap,visible:s,velocity:r,canDismiss:c});l>=0?this._setSnap(l):this._requestClose(`drag`)}_endDrag(){let e=this._drag;e&&(this._drag=null,e.grip.releasePointerCapture?.(e.id),e.grip.removeEventListener(`pointermove`,this._onPointerMove),e.grip.removeEventListener(`pointerup`,this._onPointerUp),e.grip.removeEventListener(`pointercancel`,this._onPointerUp),this.classList.remove(`is-dragging`),this.style.removeProperty(`--wui-drawer-drag`))}};export{v as t};
1
+ import{r as e}from"./dom-Do1pAA12.js";import{t}from"./elementBase-Cxeyx0tU.js";import{h as n,o as r,p as i,u as a}from"./nativeOverlay-D3VmY8qn.js";import{r as o,t as s}from"./textStore-opIEM4lu.js";import{t as c}from"./drawer.g-B-zYKBfQ.js";var l=[50,90],u=10,d=100;function f(e,t=l){let n=Array.isArray(e)?e:String(e??``).split(`,`),r=[];for(let e of n){if(typeof e==`string`&&e.trim()===``)return t;let n=Number(e);if(!Number.isFinite(n)||n<u||n>d)return t;r.includes(n)||r.push(n)}return r.length?r.sort((e,t)=>e-t):t}function p(e){let{points:t,index:n,visible:r,velocity:i,canDismiss:a}=e,o=a?-1:0;if(Math.abs(i)>=.5)return i>0?Math.max(n-1,o):Math.min(n+1,t.length-1);let s=t[0];if(a&&s!==void 0&&r<s/2)return-1;let c=0;for(let e=1;e<t.length;e++){let n=t[e],i=t[c];if(n===void 0||i===void 0)throw Error(`snap point missing`);Math.abs(n-r)<Math.abs(i-r)&&(c=e)}return c}var m=()=>o(`drawer`,c),h=`(max-width: 767.98px)`,g=4;function _(e,t){let n=e[t];if(n===void 0)throw RangeError(`no snap point at ${t}`);return n}var v=class extends t{_doc;_media;_shown;_trigger;_returnTo;_release;_snap;_drag;_onMedia;_onPointerDown;_onPointerMove;_onPointerUp;_onKeyDown;_onTransitionEnd;_settled;static get observedAttributes(){return[`open`,`snap-points`,`no-sheet`]}constructor(){super(),this._doc=null,this._media=null,this._shown=!1,this._trigger=null,this._returnTo=null,this._release=null,this._snap=0,this._drag=null,this._onMedia=()=>this._syncMode(),this._onPointerDown=e=>this._pointerDown(e),this._onPointerMove=e=>this._pointerMove(e),this._onPointerUp=e=>this._pointerUp(e),this._onKeyDown=e=>this._keyDown(e),this._onTransitionEnd=e=>{e.target===this._panel()&&e.propertyName===`transform`&&this.isOpen&&this._announce()},this._settled=!1}connectedCallback(){this._doc=this.ownerDocument,n(this._doc),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`transitionend`,this._onTransitionEnd),this._media=typeof matchMedia==`function`?matchMedia(h):null,this._media?.addEventListener?.(`change`,this._onMedia),this._syncMode(),this._applyPoints(),this.hasAttribute(`open`)&&this._open()}disconnectedCallback(){this._endDrag(),this._teardown(),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`pointerdown`,this._onPointerDown),this.removeEventListener(`transitionend`,this._onTransitionEnd),this._media?.removeEventListener?.(`change`,this._onMedia),this._media=null,this._doc=null}attributeChangedCallback(e){this._doc&&(e===`open`?this.hasAttribute(`open`)?this._open():this._close():e===`no-sheet`?this._syncMode():(this._snap=Math.min(this._snap,this._points().length-1),this._applyPoints()))}get isOpen(){return this.hasAttribute(`open`)}show(e){this._trigger=e??null,this.setAttribute(`open`,``)}hide(){this.removeAttribute(`open`)}_points(){return f(this.getAttribute(`snap-points`),l)}_sheet(){return!!this._media?.matches&&!this.hasAttribute(`no-sheet`)}_syncMode(){this.setAttribute(`data-mode`,this._sheet()?`sheet`:`side`)}_applyPoints(){let t=this._points();this._snap=Math.min(Math.max(this._snap,0),t.length-1),this.style.setProperty(`--wui-drawer-max`,String(t[t.length-1])),this.style.setProperty(`--wui-drawer-snap`,String(t[this._snap])),this.setAttribute(`data-snap`,String(this._snap));let n=this.querySelector(`.wui-drawer-handle`);if(!(n instanceof Element))return;let r=e(t[this._snap],`The drawer has no snap point to report.`);n.setAttribute(`aria-valuemin`,String(t[0])),n.setAttribute(`aria-valuemax`,String(t[t.length-1])),n.setAttribute(`aria-valuenow`,String(r)),n.setAttribute(`aria-valuetext`,s(m().screenText,{now:r}))}_setSnap(e){let t=this._points(),n=Math.min(Math.max(e,0),t.length-1),r=n!==this._snap;this._snap=n,this._applyPoints(),r&&this.dispatchEvent(new CustomEvent(`wui-drawer-snap`,{bubbles:!0,detail:{index:n,percent:t[n]}}))}_open(){if(this._shown)return;let e=this._dialog();this._shown=!0,this._settled=null;let t=Number.parseInt(this.getAttribute(`default-snap`)??`0`,10);this._snap=Number.isFinite(t)?t:0,this._syncMode(),this._applyPoints(),this.dispatchEvent(new CustomEvent(`wui-drawer-open`,{bubbles:!0,detail:{trigger:this._trigger}})),this._returnTo=this._trigger,this._trigger=null,this._release=a(e,{escape:this._dismissible(),backdrop:this._dismissible(),focus:this._sheet()?`panel`:`first-control`,onRequestClose:e=>this._requestClose(e)}),this._settle()}_close(){if(!this._shown)return;this._endDrag(),this._shown=!1,this._settled=null;let e=this._release;this._release=null;let t=this._dialog();r(t).then(()=>{e?.(),i(this._returnTo,t),this._returnTo=null,this._announce()})}_teardown(){this._shown=!1;let e=this._release;this._release=null,e&&(e(),this._panel()?.close())}_settle(){(this._panel()?.getAnimations?.()??[]).length||this._announce()}_announce(){let e=this.isOpen;e!==this._settled&&(this._settled=e,this.dispatchEvent(new CustomEvent(e?`wui-drawer-opened`:`wui-drawer-closed`,{bubbles:!0})))}_document(){let e=this._doc;if(!e)throw TypeError(`wui-drawer is not connected`);return e}_panel(){let e=this.querySelector(`.wui-drawer-panel`);return e instanceof HTMLDialogElement?e:null}_dialog(){let e=this._panel();if(!e)throw TypeError(`wui-drawer has no dialog panel`);return e}_dismissible(){return!this.hasAttribute(`static`)&&!this.hasAttribute(`no-dismiss`)}_requestClose(e){let t=this.dispatchEvent(new CustomEvent(`wui-drawer-close`,{bubbles:!0,cancelable:!0,detail:{reason:e}}));return t&&this.hide(),t}_keyDown(e){e.target instanceof Element&&e.target.closest(`.wui-drawer-handle`)&&this._sheet()&&this._handleKey(e)}_handleKey(e){let t=this._points().length-1,n={ArrowUp:this._snap+1,ArrowDown:this._snap-1,Home:0,End:t};if(!(e.key in n))return;let r=n[e.key];r!==void 0&&(e.preventDefault(),this._setSnap(r))}_pointerDown(e){if(!this.isOpen||!this._sheet()||(e.button??0)!==0)return;let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[data-wui-drawer-grip]`);n instanceof HTMLElement&&!t.closest(`button`)&&(this._drag={grip:n,id:e.pointerId,startY:e.clientY,lastY:e.clientY,lastT:e.timeStamp,velocity:0,moved:!1},n.setPointerCapture?.(e.pointerId),n.addEventListener(`pointermove`,this._onPointerMove),n.addEventListener(`pointerup`,this._onPointerUp),n.addEventListener(`pointercancel`,this._onPointerUp))}_viewport(){let e=this._document().defaultView;if(!e)throw TypeError(`wui-drawer has no window`);return e.innerHeight}_pointerMove(e){let t=this._drag;if(!t||e.pointerId!==t.id)return;let n=e.clientY-t.startY;if(!t.moved&&Math.abs(n)<g)return;t.moved=!0,this.classList.add(`is-dragging`);let r=e.timeStamp-t.lastT;r>0&&(t.velocity=(e.clientY-t.lastY)/r),t.lastY=e.clientY,t.lastT=e.timeStamp;let i=this._points(),a=(_(i,i.length-1)-_(i,this._snap))/100*this._viewport();t.offset=Math.max(n,-a),this.style.setProperty(`--wui-drawer-drag`,`${t.offset}px`)}_pointerUp(e){let t=this._drag;if(!t||e.pointerId!==t.id)return;let{moved:n,velocity:r,offset:i=0}=t;if(this._endDrag(),!n)return;let a=this._points(),o=this._viewport(),s=(_(a,this._snap)/100*o-i)/(o/100),c=this._dismissible(),l=p({points:a,index:this._snap,visible:s,velocity:r,canDismiss:c});l>=0?this._setSnap(l):this._requestClose(`drag`)}_endDrag(){let e=this._drag;e&&(this._drag=null,e.grip.releasePointerCapture?.(e.id),e.grip.removeEventListener(`pointermove`,this._onPointerMove),e.grip.removeEventListener(`pointerup`,this._onPointerUp),e.grip.removeEventListener(`pointercancel`,this._onPointerUp),this.classList.remove(`is-dragging`),this.style.removeProperty(`--wui-drawer-drag`))}};export{v as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./isDrawn-BbF4phmB.js";import{t as n}from"./menuKeyNav-CstMzU08.js";import{a as r,l as i,s as a}from"./nativeOverlay-C1Rw2gIW.js";var o=`[data-wui-dropdown-trigger]`,s=`[data-wui-dropdown-menu]`,c=`.dropdown-item`,l=`[data-wui-keep-open]`,u=2,d=150,f=class extends e{_unbindKeys;_rect;_pendingFocus;_pressOpen;_settling;_settleTimer;_endSettle;_onSettleScroll;_onClick;_onPointerDown;_onKeyDown;_onScroll;_onResize;_onClosed;static get observedAttributes(){return[`open`,`align`]}constructor(){super(),this._unbindKeys=null,this._rect=null,this._pendingFocus=!1,this._pressOpen=null,this._settling=!1,this._settleTimer=null,this._endSettle=()=>this._stopSettling(),this._onSettleScroll=()=>this._armQuiet(),this._onClick=e=>this._click(e),this._onPointerDown=e=>{e.target instanceof Element&&e.target.closest(o)&&(this._pressOpen=this.isOpen)},this._onKeyDown=e=>this._key(e),this._onScroll=()=>this._scrolled(),this._onResize=()=>{this._request(!1,`resize`)},this._onClosed=()=>this._dismissed()}connectedCallback(){this.addEventListener(`click`,this._onClick),this.addEventListener(`pointerdown`,this._onPointerDown,{capture:!0}),this.addEventListener(`keydown`,this._onKeyDown),this._trigger()?.setAttribute(`aria-expanded`,String(this.isOpen)),this.isOpen&&this._sync()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`pointerdown`,this._onPointerDown,{capture:!0}),this.removeEventListener(`keydown`,this._onKeyDown),this._stop();let e=this._menu();e&&r(e)}attributeChangedCallback(e){e===`open`&&this.isConnected&&this._sync()}get isOpen(){return this.hasAttribute(`open`)}show(){this.isOpen||this._request(!0,`trigger`)}hide(){this.isOpen&&this._request(!1,`trigger`)}_request(e,t){let n=this.dispatchEvent(new CustomEvent(`wui-dropdown-toggle`,{bubbles:!0,cancelable:!0,detail:{open:e,source:t}}));return n&&this._apply(e),n}_apply(e){e?this.setAttribute(`open`,``):this.removeAttribute(`open`)}_dismissed(){if(!this.isConnected||!this.isOpen)return;let e=this._menu()?.contains(this.ownerDocument.activeElement)??!1;this.dispatchEvent(new CustomEvent(`wui-dropdown-toggle`,{bubbles:!0,detail:{open:!1,source:`dismiss`}})),this.removeAttribute(`open`),e&&this._trigger()?.focus()}_sync(){let{trigger:e,menu:t}=this._markup();this.isOpen?this._open(e,t):this._close(e,t)}_open(e,t){a(t)||(this._pendingFocus&&this._startSettling(),i(this._anchor(e),t,{mode:`auto`,alignEnd:this.getAttribute(`align`)===`end`,onClosed:this._onClosed,scrollSettling:()=>this._settling}),e.setAttribute(`aria-expanded`,`true`),this._rect=this._anchor(e).getBoundingClientRect(),this._unbindKeys=n(t,{items:()=>this._rows(t)}),window.addEventListener(`scroll`,this._onScroll,{capture:!0,passive:!0}),window.addEventListener(`resize`,this._onResize),this._pendingFocus&&(this._pendingFocus=!1,queueMicrotask(()=>{this.isOpen&&a(t)&&this._rows(t)[0]?.focus()})))}_close(e,t){this._pendingFocus=!1,this._stop(),e.setAttribute(`aria-expanded`,`false`),r(t)}_stop(){this._stopSettling(),this._unbindKeys?.(),this._unbindKeys=null,window.removeEventListener(`scroll`,this._onScroll,{capture:!0}),window.removeEventListener(`resize`,this._onResize)}_startSettling(){this._settling=!0,this.ownerDocument.addEventListener(`scroll`,this._onSettleScroll,{capture:!0,passive:!0}),this.ownerDocument.addEventListener(`scrollend`,this._endSettle,{capture:!0}),this._armQuiet()}_armQuiet(){this._settleTimer!==null&&clearTimeout(this._settleTimer),this._settleTimer=setTimeout(this._endSettle,d)}_stopSettling(){if(this._settling&&(this._settling=!1,this._settleTimer!==null&&clearTimeout(this._settleTimer),this._settleTimer=null,this.ownerDocument.removeEventListener(`scroll`,this._onSettleScroll,{capture:!0}),this.ownerDocument.removeEventListener(`scrollend`,this._endSettle,{capture:!0}),this.isConnected)){let{trigger:e}=this._markup();this._rect=this._anchor(e).getBoundingClientRect()}}_scrolled(){if(this._settling)return;let{trigger:e}=this._markup(),t=this._anchor(e).getBoundingClientRect(),n=this._rect;(!n||Math.abs(t.top-n.top)>u||Math.abs(t.left-n.left)>u)&&this._request(!1,`scroll`)}_click(e){let t=e.target;if(!(t instanceof Element))return;let n=this._pressOpen;this._pressOpen=null;let r=t.closest(o);if(r&&this.contains(r)){if((n??this.isOpen)&&!this.isOpen)return;this._request(!this.isOpen,`trigger`);return}let i=this._menu(),a=t.closest(c);if(!i||!a||!i.contains(a)||a.getAttribute(`aria-disabled`)===`true`)return;let s=a.closest(l);s&&i.contains(s)||this.isOpen&&this._request(!1,`select`)}_key(e){if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=e.target;if(t instanceof Element&&this._trigger()?.contains(t)){if(this.isOpen){let t=this._menu(),n=t?this._rows(t):[],r=e.key===`ArrowDown`?n[0]:n[n.length-1];if(!r)return;e.preventDefault(),r.focus()}else e.key===`ArrowDown`&&(e.preventDefault(),this._pendingFocus=!0,this._request(!0,`trigger`))}}_trigger(){return this.querySelector(o)}_anchor(e){return(e.closest(`[data-wui-overflow-hidden]`)?.closest(`wui-overflow`))?.querySelector(`:scope > .wui-overflow-more`)??e}_menu(){return this.querySelector(s)}_rows(e){return Array.from(e.querySelectorAll(c)).filter(t)}_markup(){let e=this._trigger(),t=this._menu();if(!e||!t)throw RangeError(`<wui-dropdown> needs a [data-wui-dropdown-trigger] control and a [data-wui-dropdown-menu] panel.`);return{trigger:e,menu:t}}};export{f as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./isDrawn-BbF4phmB.js";import{t as n}from"./menuKeyNav-CstMzU08.js";import{a as r,l as i,s as a}from"./nativeOverlay-D3VmY8qn.js";var o=`[data-wui-dropdown-trigger]`,s=`[data-wui-dropdown-menu]`,c=`.dropdown-item`,l=`[data-wui-keep-open]`,u=2,d=150,f=class extends e{_unbindKeys;_rect;_pendingFocus;_pressOpen;_settling;_settleTimer;_endSettle;_onSettleScroll;_onClick;_onPointerDown;_onKeyDown;_onScroll;_onResize;_onClosed;static get observedAttributes(){return[`open`,`align`]}constructor(){super(),this._unbindKeys=null,this._rect=null,this._pendingFocus=!1,this._pressOpen=null,this._settling=!1,this._settleTimer=null,this._endSettle=()=>this._stopSettling(),this._onSettleScroll=()=>this._armQuiet(),this._onClick=e=>this._click(e),this._onPointerDown=e=>{e.target instanceof Element&&e.target.closest(o)&&(this._pressOpen=this.isOpen)},this._onKeyDown=e=>this._key(e),this._onScroll=()=>this._scrolled(),this._onResize=()=>{this._request(!1,`resize`)},this._onClosed=()=>this._dismissed()}connectedCallback(){this.addEventListener(`click`,this._onClick),this.addEventListener(`pointerdown`,this._onPointerDown,{capture:!0}),this.addEventListener(`keydown`,this._onKeyDown),this._trigger()?.setAttribute(`aria-expanded`,String(this.isOpen)),this.isOpen&&this._sync()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`pointerdown`,this._onPointerDown,{capture:!0}),this.removeEventListener(`keydown`,this._onKeyDown),this._stop();let e=this._menu();e&&r(e)}attributeChangedCallback(e){e===`open`&&this.isConnected&&this._sync()}get isOpen(){return this.hasAttribute(`open`)}show(){this.isOpen||this._request(!0,`trigger`)}hide(){this.isOpen&&this._request(!1,`trigger`)}_request(e,t){let n=this.dispatchEvent(new CustomEvent(`wui-dropdown-toggle`,{bubbles:!0,cancelable:!0,detail:{open:e,source:t}}));return n&&this._apply(e),n}_apply(e){e?this.setAttribute(`open`,``):this.removeAttribute(`open`)}_dismissed(){if(!this.isConnected||!this.isOpen)return;let e=this._menu()?.contains(this.ownerDocument.activeElement)??!1;this.dispatchEvent(new CustomEvent(`wui-dropdown-toggle`,{bubbles:!0,detail:{open:!1,source:`dismiss`}})),this.removeAttribute(`open`),e&&this._trigger()?.focus()}_sync(){let{trigger:e,menu:t}=this._markup();this.isOpen?this._open(e,t):this._close(e,t)}_open(e,t){a(t)||(this._pendingFocus&&this._startSettling(),i(this._anchor(e),t,{mode:`auto`,alignEnd:this.getAttribute(`align`)===`end`,onClosed:this._onClosed,scrollSettling:()=>this._settling}),e.setAttribute(`aria-expanded`,`true`),this._rect=this._anchor(e).getBoundingClientRect(),this._unbindKeys=n(t,{items:()=>this._rows(t)}),window.addEventListener(`scroll`,this._onScroll,{capture:!0,passive:!0}),window.addEventListener(`resize`,this._onResize),this._pendingFocus&&(this._pendingFocus=!1,queueMicrotask(()=>{this.isOpen&&a(t)&&this._rows(t)[0]?.focus()})))}_close(e,t){this._pendingFocus=!1,this._stop(),e.setAttribute(`aria-expanded`,`false`),r(t)}_stop(){this._stopSettling(),this._unbindKeys?.(),this._unbindKeys=null,window.removeEventListener(`scroll`,this._onScroll,{capture:!0}),window.removeEventListener(`resize`,this._onResize)}_startSettling(){this._settling=!0,this.ownerDocument.addEventListener(`scroll`,this._onSettleScroll,{capture:!0,passive:!0}),this.ownerDocument.addEventListener(`scrollend`,this._endSettle,{capture:!0}),this._armQuiet()}_armQuiet(){this._settleTimer!==null&&clearTimeout(this._settleTimer),this._settleTimer=setTimeout(this._endSettle,d)}_stopSettling(){if(this._settling&&(this._settling=!1,this._settleTimer!==null&&clearTimeout(this._settleTimer),this._settleTimer=null,this.ownerDocument.removeEventListener(`scroll`,this._onSettleScroll,{capture:!0}),this.ownerDocument.removeEventListener(`scrollend`,this._endSettle,{capture:!0}),this.isConnected)){let{trigger:e}=this._markup();this._rect=this._anchor(e).getBoundingClientRect()}}_scrolled(){if(this._settling)return;let{trigger:e}=this._markup(),t=this._anchor(e).getBoundingClientRect(),n=this._rect;(!n||Math.abs(t.top-n.top)>u||Math.abs(t.left-n.left)>u)&&this._request(!1,`scroll`)}_click(e){let t=e.target;if(!(t instanceof Element))return;let n=this._pressOpen;this._pressOpen=null;let r=t.closest(o);if(r&&this.contains(r)){if((n??this.isOpen)&&!this.isOpen)return;this._request(!this.isOpen,`trigger`);return}let i=this._menu(),a=t.closest(c);if(!i||!a||!i.contains(a)||a.getAttribute(`aria-disabled`)===`true`)return;let s=a.closest(l);s&&i.contains(s)||this.isOpen&&this._request(!1,`select`)}_key(e){if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=e.target;if(t instanceof Element&&this._trigger()?.contains(t)){if(this.isOpen){let t=this._menu(),n=t?this._rows(t):[],r=e.key===`ArrowDown`?n[0]:n[n.length-1];if(!r)return;e.preventDefault(),r.focus()}else e.key===`ArrowDown`&&(e.preventDefault(),this._pendingFocus=!0,this._request(!0,`trigger`))}}_trigger(){return this.querySelector(o)}_anchor(e){return(e.closest(`[data-wui-overflow-hidden]`)?.closest(`wui-overflow`))?.querySelector(`:scope > .wui-overflow-more`)??e}_menu(){return this.querySelector(s)}_rows(e){return Array.from(e.querySelectorAll(c)).filter(t)}_markup(){let e=this._trigger(),t=this._menu();if(!e||!t)throw RangeError(`<wui-dropdown> needs a [data-wui-dropdown-trigger] control and a [data-wui-dropdown-menu] panel.`);return{trigger:e,menu:t}}};export{f as t};
@@ -1,3 +1,3 @@
1
1
  import{t as e}from"./dom-Do1pAA12.js";import{t}from"./elementBase-Cxeyx0tU.js";var n=`tbody > tr.wui-entry-grid-row[data-row-key]`,r=`input, select, textarea, button, [tabindex]:not([tabindex="-1"])`,i=class extends t{_onKeyDown;_onFocusIn;_onClick;_pendingCell=null;_ready=!1;_onPointerDown=t=>{if(t.button!==0)return;let n=this._ownRow(t.target),r=n?.dataset.rowKey;if(!n||r===void 0||r===this.getAttribute(`active-row`))return;let i=e(t.target,`td`),a=i?Array.from(n.children).indexOf(i):-1;this._pendingCell=a>=0?a:null,this._emit(`active`,{rowKey:r})};_onPaste=t=>{let n=this._ownRow(t.target),r=n?.dataset.rowKey,i=e(t.target,`td[data-column-key]`)?.getAttribute(`data-column-key`);if(!n||r===void 0||!i)return;let a=t.clipboardData?.getData(`text/plain`)??``;if(!/[\t\r\n]/.test(a))return;let o=a.replace(/\r\n/g,`
2
2
  `).split(`
3
- `);o[o.length-1]===``&&o.pop(),t.preventDefault(),this._emit(`paste`,{rowKey:r,columnKey:i,rows:o.map(e=>e.split(` `))})};constructor(){super(),this._onKeyDown=e=>this._keyDown(e),this._onFocusIn=e=>this._focusIn(e),this._onClick=t=>{this._owns(e(t.target,`.wui-entry-grid-add`))&&this._emit(`add`,{});let n=e(t.target,`thead th[data-sortable]`),r=n?.getAttribute(`data-column-key`);this._owns(n)&&r&&this._emit(`sort`,{columnKey:r})}}static get observedAttributes(){return[`active-row`]}connectedCallback(){this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`focusin`,this._onFocusIn),this.addEventListener(`click`,this._onClick),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`paste`,this._onPaste),this._ready=!0}disconnectedCallback(){this._ready=!1,this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`focusin`,this._onFocusIn),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`pointerdown`,this._onPointerDown),this.removeEventListener(`paste`,this._onPaste)}attributeChangedCallback(e,t,n){t!==n&&this._ready&&queueMicrotask(()=>this._focusActiveRow())}_owns(t){return e(t,`wui-entry-grid`)===this}_rows(){return[...this.querySelectorAll(n)].filter(e=>e instanceof HTMLElement&&this._owns(e))}_ownRow(t){let r=e(t,n);return r instanceof HTMLElement&&this._owns(r)?r:null}_emit(e,t){this.dispatchEvent(new CustomEvent(`wui-entry-grid:${e}`,{detail:t,bubbles:!0,composed:!0}))}_focusActiveRow(){let e=this.getAttribute(`active-row`),t=this._pendingCell;if(this._pendingCell=null,!this.isConnected||!e)return;let n=this._rows().find(t=>t.dataset.rowKey===e);n&&!n.contains(this.ownerDocument.activeElement)&&((t===null?void 0:n.children[t])?.querySelector(r)??n.querySelector(r))?.focus()}_keyDown(t){if(t.defaultPrevented||t.isComposing||t.keyCode===229)return;let n=e(t.target,`thead th[data-sortable]`),r=n?.getAttribute(`data-column-key`);if(this._owns(n)&&r&&(t.key===`Enter`||t.key===` `)){t.preventDefault(),this._emit(`sort`,{columnKey:r});return}let i=this._ownRow(t.target),a=i?.dataset.rowKey;if(!i||a===void 0)return;let o=t.target instanceof Element?t.target:null,s=t.ctrlKey||t.metaKey;if(t.ctrlKey&&t.key===`Delete`||t.metaKey&&t.key===`Backspace`){if(!this.hasAttribute(`removable`))return;t.preventDefault(),this._emit(`remove`,{rowKey:a})}else if(t.key===`Enter`){if(s||t.shiftKey||t.altKey||o?.closest(`textarea, button`)||o?.getAttribute(`aria-expanded`)===`true`)return;t.preventDefault(),this._emit(`commit`,{rowKey:a,move:`next`})}else if(s&&t.key.toLowerCase()===`s`)t.preventDefault(),this._emit(`commit`,{rowKey:a,move:`stay`});else if(t.key===`Escape`){if(o?.getAttribute(`aria-expanded`)===`true`)return;t.preventDefault(),this._emit(`discard`,{rowKey:a})}else if(s&&(t.key===`ArrowUp`||t.key===`ArrowDown`)){t.preventDefault();let e=this._rows(),n=e[e.indexOf(i)+(t.key===`ArrowUp`?-1:1)]?.dataset.rowKey;n!==void 0&&this._emit(`active`,{rowKey:n})}}_focusIn(t){let n=this._ownRow(t.target),r=n?.dataset.rowKey;n&&r!==void 0&&(t.target instanceof HTMLInputElement&&e(t.target,`td[data-kind="number"]`)&&t.target.select(),r!==this.getAttribute(`active-row`)&&this._emit(`active`,{rowKey:r}))}};export{i as t};
3
+ `);o[o.length-1]===``&&o.pop(),t.preventDefault(),this._emit(`paste`,{rowKey:r,columnKey:i,rows:o.map(e=>e.split(` `))})};constructor(){super(),this._onKeyDown=e=>this._keyDown(e),this._onFocusIn=e=>this._focusIn(e),this._onClick=t=>{this._owns(e(t.target,`.wui-entry-grid-add`))&&this._emit(`add`,{});let n=e(t.target,`thead th[data-sortable]`),r=n?.getAttribute(`data-column-key`);this._owns(n)&&r&&this._emit(`sort`,{columnKey:r})}}static get observedAttributes(){return[`active-row`]}connectedCallback(){this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`focusin`,this._onFocusIn),this.addEventListener(`click`,this._onClick),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`paste`,this._onPaste),this._ready=!0}disconnectedCallback(){this._ready=!1,this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`focusin`,this._onFocusIn),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`pointerdown`,this._onPointerDown),this.removeEventListener(`paste`,this._onPaste)}attributeChangedCallback(e,t,n){t!==n&&this._ready&&queueMicrotask(()=>this._focusActiveRow())}_owns(t){return e(t,`wui-entry-grid`)===this}_rows(){return[...this.querySelectorAll(n)].filter(e=>e instanceof HTMLElement&&this._owns(e))}_ownRow(t){let r=e(t,n);return r instanceof HTMLElement&&this._owns(r)?r:null}_emit(e,t){this.dispatchEvent(new CustomEvent(`wui-entry-grid:${e}`,{detail:t,bubbles:!0,composed:!0}))}_focusActiveRow(){let e=this.getAttribute(`active-row`),t=this._pendingCell;if(this._pendingCell=null,!this.isConnected||!e)return;let n=this._rows().find(t=>t.dataset.rowKey===e);n&&!n.contains(this.ownerDocument.activeElement)&&((t===null?void 0:n.children[t])?.querySelector(r)??n.querySelector(r))?.focus()}_keyDown(t){if(t.defaultPrevented||t.isComposing||t.keyCode===229)return;let n=e(t.target,`thead th[data-sortable]`),r=n?.getAttribute(`data-column-key`);if(this._owns(n)&&r&&(t.key===`Enter`||t.key===` `)){t.preventDefault(),this._emit(`sort`,{columnKey:r});return}let i=this._ownRow(t.target),a=i?.dataset.rowKey;if(!i||a===void 0)return;let o=t.target instanceof Element?t.target:null,s=t.ctrlKey||t.metaKey;if(t.ctrlKey&&t.key===`Delete`||t.metaKey&&t.key===`Backspace`){if(!this.hasAttribute(`removable`))return;t.preventDefault(),this._emit(`remove`,{rowKey:a})}else if(t.key===`Enter`){if(s||t.shiftKey||t.altKey||o?.closest(`textarea, button`)||o?.getAttribute(`aria-expanded`)===`true`)return;t.preventDefault(),this._emit(`commit`,{rowKey:a,move:`next`})}else if(s&&t.key.toLowerCase()===`s`)t.preventDefault(),this._emit(`commit`,{rowKey:a,move:`stay`});else if(t.key===`Escape`){if(o?.getAttribute(`aria-expanded`)===`true`)return;t.preventDefault(),this._emit(`discard`,{rowKey:a})}else if(s&&(t.key===`ArrowUp`||t.key===`ArrowDown`)){t.preventDefault();let n=this._rows(),r=n[n.indexOf(i)+(t.key===`ArrowUp`?-1:1)]?.dataset.rowKey;if(r!==void 0){let n=e(t.target,`td`),a=n?Array.from(i.children).indexOf(n):-1;this._pendingCell=a>=0?a:null,this._emit(`active`,{rowKey:r})}}}_focusIn(t){let n=this._ownRow(t.target),r=n?.dataset.rowKey;n&&r!==void 0&&(t.target instanceof HTMLInputElement&&e(t.target,`td[data-kind="number"]`)&&t.target.select(),r!==this.getAttribute(`active-row`)&&this._emit(`active`,{rowKey:r}))}};export{i as t};
@@ -0,0 +1 @@
1
+ import{n as e}from"./buttonClass-GtEi8hAY.js";import{t}from"./devWarn-DXdRWZs3.js";import{r as n}from"./dom-Do1pAA12.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,c as a,d as o,f as s,i as c,l,m as u,n as d,o as f,p,s as m,t as h,u as g}from"./initials-Qb6ITcri.js";import{t as _}from"./avatarHtml-BtbN7cA5.js";import{t as v}from"./iconGlyphs.g-DxSJLQJ8.js";import{n as y,r as b,t as x}from"./textStore-opIEM4lu.js";import{a as S,l as C}from"./nativeOverlay-D3VmY8qn.js";import{t as w}from"./gantt.g-TdTxeruW.js";var T=`data-wui-gantt-pick`,E=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},D=e=>`${e}px`,O=(e,t,n)=>{let r=E(`div`,`wui-gantt-table-cell`,n);return r.setAttribute(`role`,t),r.dataset.col=e,r};function k(e){let t=e.text,n=E(`div`,`wui-gantt-table`);n.setAttribute(`role`,`table`),n.setAttribute(`aria-label`,e.title);let r=E(`div`);r.setAttribute(`role`,`rowgroup`);let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=`head`,i.setAttribute(`role`,`row`),i.style.height=D(e.headHeight),i.append(O(`name`,`columnheader`,t.tableName),O(`owner`,`columnheader`,t.detailsOwner),O(`start`,`columnheader`,t.tableStart),O(`end`,`columnheader`,t.tableEnd),O(`done`,`columnheader`,t.detailsDone)),r.append(i);let a=E(`div`);a.setAttribute(`role`,`rowgroup`);for(let n of e.rows){if(n.height===0)continue;let r=n.row;if(n.kind===`group`){let r=n.group;if(!r)continue;let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=`group`,i.dataset.wuiGanttGroup=r.name,i.setAttribute(`role`,`row`),i.style.height=D(n.height);let o=E(`div`,`wui-gantt-table-cell wui-gantt-table-group`);o.setAttribute(`role`,`rowheader`);let s=E(`button`,`wui-gantt-group-toggle`);s.type=`button`,s.setAttribute(`aria-expanded`,String(!r.folded)),s.setAttribute(`aria-label`,x(r.folded?t.unfoldLabel:t.foldLabel,{group:r.name})),s.setAttribute(e.focusAttr,`group:${r.name}`),s.innerHTML=v(r.folded?`chevron-right`:`chevron-down`,{size:16}),o.append(s,E(`span`,null,r.name),E(`span`,null,y(t,`groupSummary`,r.count,{percent:r.percent}))),i.append(o),a.append(i);continue}let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=r.end===void 0?`milestone`:`bar`,i.dataset.wuiGanttKey=r.key,i.dataset.wuiGanttPick=r.key,r.key===e.selected&&(i.dataset.selected=`true`),i.setAttribute(`role`,`row`),i.style.height=D(n.height);let o=O(`name`,`rowheader`,r.name);o.title=r.name;let s=O(`owner`,`cell`,``);r.owner&&(s.title=r.owner,s.innerHTML=_({initials:h(r.owner)},`avatar-xs`),s.append(E(`span`,`visually-hidden`,r.owner)));let c=O(`start`,`cell`,r.start===void 0?``:f(l(r.start))),u=O(`end`,`cell`,r.end===void 0?``:f(l(r.end))),d=O(`done`,`cell`,r.end===void 0?``:`${r.progress??0}%`);i.append(o,s,c,u,d),a.append(i)}let o=e.skeleton;for(let e=0;o&&e<o.rows;e+=1){let e=E(`div`,`wui-gantt-table-row`);e.dataset.kind=`skeleton`,e.setAttribute(`role`,`row`),e.setAttribute(`aria-hidden`,`true`),e.style.height=D(o.rowHeight);let t=E(`span`,`wui-gantt-skeleton`);t.style.height=D(o.barHeight),e.append(t),a.append(e)}return n.append(r,a),n}var A=()=>b(`gantt`,w),j=`wui-gantt:zoom-change`,M=`wui-gantt:from-change`,N=`wui-gantt:fold-change`,P=`wui-gantt:select`,F=`wui-gantt:add-task`,I=`wui-gantt:retry`,L=`data-wui-gantt-focus`,R=`bar:`,z=`http://www.w3.org/2000/svg`,B=[`day`,`week`,`month`],V=3,H=16,U=300,W=[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`,`Escape`,`Enter`,` `],G=0,K=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},q=e=>`${e}px`;function J(e){return typeof e==`object`&&!!e&&`rows`in e&&Array.isArray(e.rows)&&`title`in e&&typeof e.title==`string`}function Y(e){let t=A();switch(e){case`done`:return t.statusDone;case`inProgress`:return t.statusInProgress;case`atRisk`:return t.statusAtRisk;case`notStarted`:return t.statusNotStarted;default:throw RangeError(`Unknown gantt status ${String(e)}.`)}}var X=e=>e.progress??0,Z=e=>e.status??`notStarted`,Q=(e,t)=>(e??[]).join(`\0`)===(t??[]).join(`\0`),$=class extends r{uid;_spec=null;_prev=null;_zoom=`week`;_fromMs=null;_folded=/* @__PURE__ */ new Set;_selected=null;_controlled=!1;_awaitingSpec=!1;_connected=!1;_focusAfter=null;_resolved=null;_specRows=[];_card=null;_onClick;_onKeyDown;_onChange;constructor(){super(),G+=1,this.uid=`wui-gantt-${G}`,this._onClick=e=>this._handleClick(e),this._onKeyDown=e=>this._handleKeyDown(e),this._onChange=e=>this._handleChange(e)}get spec(){return this._spec}set spec(e){this._spec=e??null,this._connected&&this._draw()}connectedCallback(){if(Object.hasOwn(this,`spec`)){let e=this.spec;delete this.spec,this._spec=e??null}this._spec??=this._readScript(),this._spec==null&&!this.querySelector(`:scope > script[type='application/json']`)&&(this._awaitingSpec=!0,queueMicrotask(()=>{this._awaitingSpec=!1,this._connected&&this._draw()})),this.classList.add(`wui-gantt`),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`change`,this._onChange),this._connected=!0,this._draw()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`change`,this._onChange),this._card&&=(S(this._card),this._card.remove(),null),this._connected=!1}_readScript(){let e=this.querySelector(`:scope > script[type="application/json"]`);if(!(e instanceof HTMLScriptElement))return null;try{return JSON.parse(String(e.textContent))}catch(e){return t(`[@webority/ui-elements] <wui-gantt> could not read its JSON spec:`,e instanceof Error?e.message:void 0),null}}_seed(e){let t=this._prev;this._controlled=e.controlled===!0;let n=e=>this._controlled||t===null||e;n(t?.zoom!==e.zoom)&&(this._zoom=e.zoom??`week`),n(t?.from!==e.from)&&(this._fromMs=e.from?l(e.from):null),n(!Q(t?.folded,e.folded))&&(this._folded=new Set(e.folded??[])),n(t?.selected!==e.selected)&&(this._selected=e.selected??null),this._prev=e}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_setZoom(e){this._emit(j,{zoom:e}),this._controlled?this._syncRadios():(this._zoom=e,this._fromMs=this._fromMs===null?null:o(e,this._fromMs),this._draw())}_setFrom(e){this._emit(M,{from:m(e)}),this._controlled||(this._fromMs=e,this._draw())}_setFolded(e){let t=new Set(this._folded);t.delete(e)||t.add(e),this._emit(N,{folded:[...t]}),this._controlled||(this._folded=t,this._draw())}_setSelected(e){this._emit(P,{key:e}),this._focusAfter=`${R}${e??this._selected??``}`,this._controlled||(this._selected=e),this._draw()}_syncRadios(){for(let e of this.querySelectorAll(`.segmented-input`))e.checked=e.value===this._zoom}_handleChange(e){let t=e.target;if(!(t instanceof HTMLInputElement)||!t.matches(`.wui-gantt-scale .segmented-input`))return;let n=B.find(e=>e===t.value);n&&this._setZoom(n)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[${L}]`);if(n instanceof HTMLElement&&this.contains(n)){this._activate(n.getAttribute(L)??``,n);return}let r=t.closest(`[${T}]`);if(!(r instanceof HTMLElement)||!this.contains(r))return;let i=r.getAttribute(`data-wui-gantt-pick`)??``;this._setSelected(i===this._selected?null:i)}_activate(e,t){let n=this._resolved;if(e.startsWith(R)){let t=e.slice(4);this._setSelected(t===this._selected?null:t)}else e.startsWith(`group:`)?this._setFolded(e.slice(6)):e===`close`?this._setSelected(null):e===`add`?this._emit(F):e===`retry`?this._emit(I):n&&e===`nav:earlier`?this._setFrom(g(n.zoom,n.fromMs,-1)):n&&e===`nav:later`?this._setFrom(g(n.zoom,n.fromMs,1)):n&&e===`nav:today`?this._setFrom(u(n.zoom,n.todayMs)):e.startsWith(`zoom:`)&&t.click()}_bars(){return[...this.querySelectorAll(`.wui-gantt-lane [${L}^="${R}"]`)].filter(e=>e instanceof HTMLElement)}_focusBar(e){if(e){for(let t of this._bars())t.tabIndex=t===e?0:-1;e.focus()}}_barByKey(e){return e===void 0?void 0:this._bars().find(t=>t.dataset.wuiGanttKey===e)}_handleKeyDown(e){if(e.ctrlKey||e.metaKey||e.altKey||!W.includes(e.key))return;if(e.key===`Escape`){if(this._selected===null)return;e.preventDefault(),this._setSelected(null);return}let t=e.target;if(!(t instanceof HTMLElement)||!t.getAttribute(L)?.startsWith(R))return;let n=this._bars(),r=n.indexOf(t),i=t.dataset.wuiGanttKey,a=this._specRows.find(e=>e.key===i);switch(e.preventDefault(),e.key){case`ArrowDown`:this._focusBar(n[r+1]);break;case`ArrowUp`:this._focusBar(n[r-1]);break;case`Home`:this._focusBar(n[0]);break;case`End`:this._focusBar(n.at(-1));break;case`ArrowLeft`:this._focusBar((a?.dependsOn??[]).map(e=>this._barByKey(e)).find(e=>e));break;case`ArrowRight`:this._focusBar(this._specRows.filter(e=>e.dependsOn?.includes(i??``)).map(e=>this._barByKey(e.key)).find(e=>e));break;default:this._activate(t.getAttribute(L)??``,t)}}_focusToken(){let e=document.activeElement;return e instanceof HTMLElement&&this.contains(e)?e.getAttribute(L):null}_draw(){if(this._card&&=(S(this._card),this._card.remove(),null),this._spec==null&&this._awaitingSpec)return;let e=this._focusAfter??this._focusToken();this._focusAfter=null;let r;try{r=this._compose()}catch(e){t(`[@webority/ui-elements] <wui-gantt> could not draw its spec:`,e instanceof Error?e.message:void 0),this._resolved=null,this._specRows=[],this._card=null,this.dataset.state=`error`,this.removeAttribute(`aria-busy`),r=[this._stateBlock(`error`,A().errorText)]}if(this.replaceChildren(...r),this._card){let e=n(this._barByKey(this._selected??void 0),`selected gantt bar`);this.append(this._card),C(e,this._card,{mode:`manual`,side:`auto`,align:`start`,flipAlign:!0,gap:4,keepOffscreen:!0})}if(this._placeThumb(),e===null)return;let i=[...this.querySelectorAll(`[${L}]`)].find(t=>t.getAttribute(L)===e);i instanceof HTMLElement&&(e.startsWith(R)?this._focusBar(i):i.focus())}_compose(){let e=this._spec;if(!J(e))throw TypeError("<wui-gantt> has no spec: set the `spec` property or add a JSON script child.");this._seed(e),p(e);let t=e.layout??`table`,n=c[t],r=A(),f=l(e.today??s()),m=this._zoom,h=o(m,this._fromMs??u(m,f)),g={layout:t,zoom:m,fromMs:h,todayMs:f};this._resolved=g,this._specRows=e.rows;let _=e.rows.some(e=>e.start!==void 0),v=(e.state??`ready`)===`ready`&&!_?`empty`:e.state??`ready`;this.dataset.state=v,this.dataset.zoom=m,this.dataset.layout=t,v===`loading`?this.setAttribute(`aria-busy`,`true`):this.removeAttribute(`aria-busy`);let y=v===`ready`?a({...e,folded:[...this._folded],selected:this._selected},g):null,b=y?.axis??i(t,m,h),x=K(`div`,`wui-gantt-lane`);x.style.width=q(b.width),y?this._fillLane(x,e,y):v===`loading`&&(x.style.height=q(V*n.rowH));let S=[];v===`loading`&&S.push(this._fillSkeleton(x,e,n)),v===`empty`&&S.push(this._emptyBlock(e)),v===`error`&&S.push(this._stateBlock(`error`,e.errorText||r.errorText));let C=this._head(b),w=K(`div`,`wui-gantt-plot`);w.append(C,x);let T=K(`div`,`wui-gantt-scroller`);if(t===`table`){let t=k({title:e.title,rows:y?.rows??[],headHeight:2*d.tierH,selected:this._selected,text:r,focusAttr:L,skeleton:v===`loading`?{rows:V,rowHeight:n.rowH,barHeight:n.barH}:void 0});T.append(t,w)}else T.append(w);return[this._toolbar(e,v===`ready`),T,...S,this._legend(t)]}_toolbar(e,t){let n=K(`div`,`wui-gantt-toolbar`);return t&&n.append(K(`p`,`wui-gantt-count`,this._countText(e.rows))),n.append(this._scale(),this._nav()),n}_countText(e){let t=A(),n=e.filter(e=>e.start!==void 0),r=n.filter(e=>e.end===void 0).length,i=1/0,a=-1/0;for(let e of n)i=Math.min(i,l(e.start??``)),a=Math.max(a,l(e.end??e.start??``));return[y(t,`summaryTasks`,n.length-r),y(t,`summaryMilestones`,r),x(t.summaryRange,{from:f(i),to:f(a)})].join(`, `)}_scale(){let e=A(),t=K(`div`,`segmented segmented-sm wui-gantt-scale`);t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-label`,e.scaleLabel),t.append(Object.assign(K(`span`,`segmented-thumb`),{ariaHidden:`true`}));let n={day:e.dayLabel,week:e.weekLabel,month:e.monthLabel};for(let e of B){let r=K(`label`,`segmented-option`),i=K(`input`,`segmented-input`);i.type=`radio`,i.name=`${this.uid}-scale`,i.value=e,i.checked=e===this._zoom,i.setAttribute(L,`zoom:${e}`),r.append(i,n[e]),t.append(r)}return t}_placeThumb(){let e=this.querySelector(`.wui-gantt-scale`),t=e?.querySelector(`.segmented-thumb`),n=e?.querySelector(`.segmented-option:has(.segmented-input:checked)`);e instanceof HTMLElement&&t instanceof HTMLElement&&n instanceof HTMLElement&&e.offsetWidth&&(t.style.width=q(n.offsetWidth),t.style.transform=`translateX(${n.offsetLeft}px)`,t.style.opacity=`1`)}_nav(){let t=A(),n=K(`div`,`wui-gantt-nav`),r=(t,n,r)=>{let i=K(`button`,e(`neutral`,`soft`,`sm`));return i.type=`button`,i.setAttribute(`aria-label`,n),i.setAttribute(L,t),i.innerHTML=v(r,{size:16}),i},i=K(`button`,e(`neutral`,`soft`,`sm`),t.todayLabel);return i.type=`button`,i.setAttribute(L,`nav:today`),n.append(r(`nav:earlier`,t.earlierLabel,`chevron-left`),r(`nav:later`,t.laterLabel,`chevron-right`),i),n}_head(e){let t=K(`div`,`wui-gantt-head`);t.style.width=q(e.width),t.setAttribute(`aria-hidden`,`true`);let n=(e,t)=>{let n=K(`div`,`wui-gantt-tier ${t}`);for(let t of e){let e=K(`div`,t.weekend?`wui-gantt-cell wui-gantt-cell-weekend`:`wui-gantt-cell`);e.style.left=q(t.x),e.style.width=q(t.w),t.sub&&e.append(K(`small`,null,t.sub)),e.append(t.label),n.append(e)}return n};return t.append(n(e.top,`wui-gantt-tier-top`),n(e.bottom,`wui-gantt-tier-bottom`)),t}_legend(e){let t=A(),n=K(`div`,`wui-gantt-legend`);n.setAttribute(`role`,`list`),n.setAttribute(`aria-label`,t.legendLabel);let r=(e,t)=>{let r=K(`span`,null);r.setAttribute(`role`,`listitem`),r.append(e,t),n.append(r)};for(let e of[`done`,`inProgress`,`atRisk`,`notStarted`]){let t=K(`span`,`wui-gantt-swatch`);t.dataset.status=e,r(t,Y(e))}let i=K(`span`,`wui-gantt-swatch`);if(i.dataset.kind=`milestone`,r(i,t.milestoneLabel),e===`table`){let e=K(`span`,`wui-gantt-legend-note`,t.legendRemaining);e.setAttribute(`role`,`listitem`),n.append(e)}return n}_stateBlock(t,n){let r=A(),i=K(`div`,`wui-gantt-state`);if(t===`error`){i.setAttribute(`role`,`alert`),i.append(K(`p`,null,n));let t=K(`button`,e(`neutral`,`soft`,`sm`),r.retryLabel);t.type=`button`,t.setAttribute(L,`retry`),i.append(t)}else i.append(K(`p`,null,n));return i}_emptyBlock(t){let n=A(),r=K(`div`,`wui-gantt-state`);if(r.append(K(`p`,`fw-semibold`,n.emptyTitle),K(`p`,null,t.emptyText||n.emptyText)),t.addTask){let t=K(`button`,e(`primary`,`solid`,`sm`),n.addTaskLabel);t.type=`button`,t.setAttribute(L,`add`),r.append(t)}return r}_fillSkeleton(e,t,n){let r=K(`div`,`visually-hidden`,t.loadingText||A().loadingText);r.setAttribute(`role`,`status`);for(let t=0;t<V;t+=1){let r=K(`div`,`wui-gantt-skeleton`);r.style.top=q(t*n.rowH+n.barTop),r.style.left=q(40+t*60),r.style.width=q(240),r.style.height=q(n.barH),r.setAttribute(`aria-hidden`,`true`),e.append(r)}return r}_fillLane(e,t,n){let r=A(),{axis:i}=n,a=n.layout===`table`;e.style.height=q(n.height),e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,t.title);let o=K(`p`,`visually-hidden`,a?r.helpTextTable:r.helpText);o.id=`${this.uid}-help`,e.setAttribute(`aria-describedby`,o.id);let s=(e,t,n,r,i)=>{let a=K(`div`,e);return a.setAttribute(`aria-hidden`,`true`),a.style.left=q(t),a.style.top=q(n),a.style.width=q(r),a.style.height=q(i),a},c=[o];for(let e of n.rows){if(e.height===0)continue;let t=s(`wui-gantt-row`,0,e.top,i.width,e.height);a&&e.kind!==`group`&&e.row.key===this._selected&&(t.dataset.selected=`true`),c.push(t)}for(let e of i.weekendX)c.push(s(`wui-gantt-weekend`,e,0,i.ppd,n.height));for(let e of i.gridX)c.push(s(`wui-gantt-grid`,e,0,1,n.height));if(n.today.inWindow){c.push(s(`wui-gantt-today`,n.today.x-1,0,2,n.height));let e=K(`div`,`wui-gantt-today-flag rounded-pill`,r.todayLabel);e.style.left=q(n.today.x),c.push(e)}let l=new Map(t.rows.map(e=>[e.key,e]));for(let e of n.rows){if(e.hidden)continue;let t=K(`div`,`wui-gantt-item`);t.setAttribute(`role`,`listitem`),t.style.display=`contents`,e.kind===`group`?this._drawGroup(t,e,n):e.kind===`milestone`?this._drawMilestone(t,e,l,n):this._drawBar(t,e,l,n),c.push(t)}c.push(this._deps(n)),this._card=a?null:this._details(n,l),e.append(...c);let u=e.querySelector(`[${L}^="${R}"]`);u instanceof HTMLElement&&(u.tabIndex=0)}_names(e,t){return(e.dependsOn??[]).map(e=>t.get(e)?.name??e).join(`, `)}_barSentence(e,t){let n=A(),r=this._names(e,t);if(e.end===void 0){let t=f(l(e.start??``));return r?x(n.milestoneBarLabel,{name:e.name,date:t,names:r}):`${e.name}, ${t}, ${n.milestoneLabel.toLowerCase()}`}let i=x(n.barLabel,{name:e.name,start:f(l(e.start??``)),end:f(l(e.end)),percent:X(e),status:Y(Z(e)).toLowerCase()});return r?x(n.barLabelAfter,{label:i,names:r}):i}_focusable(e,t,n,r){let i=K(`button`,t);i.type=`button`;let a=this._barSentence(e,n);return i.setAttribute(`aria-label`,a),i.title=a,i.tabIndex=-1,i.dataset.status=Z(e),i.dataset.wuiGanttKey=e.key,i.setAttribute(L,`${R}${e.key}`),r?i.setAttribute(`aria-pressed`,String(this._selected===e.key)):i.setAttribute(`aria-expanded`,String(this._selected===e.key)),this._selected===e.key&&(i.dataset.selected=`true`),i}_afterLabel(e,t,n,r){let i=K(`span`,`wui-gantt-label wui-gantt-label-surface`,e);return i.style.left=q(t),i.style.top=q(n),i.style.height=q(r),i}_drawBar(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=this._focusable(i,`wui-gantt-bar rounded-2`,n,o),c=t.top+a.barTop;s.style.left=q(t.x),s.style.width=q(t.w),s.style.top=q(c),s.style.height=q(a.barH);let l=X(i),u=K(`span`,`wui-gantt-bar-progress`);if(u.style.width=`${l}%`,s.append(u),e.append(s),o)return;let d=`${i.name} ${l}%`;t.place===`inside`?s.append(K(`span`,`wui-gantt-bar-label`,d)):e.append(this._afterLabel(d,t.x+t.w+H,c,a.barH))}_drawMilestone(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=d.milestone/2,c=t.top+(a.rowH-d.milestone)/2,u=this._focusable(i,`wui-gantt-milestone`,n,o);if(u.style.left=q(t.x-s),u.style.top=q(c),u.style.width=q(d.milestone),u.style.height=q(d.milestone),e.append(u),o)return;let p=this._afterLabel(`${i.name}, ${f(l(i.start??``))}`,t.x+d.milestone,t.top+a.barTop,a.barH);t.flip&&(p.style.left=``,p.style.right=q(r.axis.width-(t.x-d.milestone))),e.append(p)}_drawGroup(e,t,n){let r=A(),i=t.group;if(!i)return;if(n.layout===`lanes`){let n=K(`div`,`wui-gantt-group wui-gantt-label wui-gantt-label-surface`);n.dataset.wuiGanttGroup=i.name,n.style.left=q(8),n.style.top=q(t.top+6);let a=K(`button`,`wui-gantt-group-toggle`);a.type=`button`,a.setAttribute(`aria-expanded`,String(!i.folded)),a.setAttribute(`aria-label`,x(i.folded?r.unfoldLabel:r.foldLabel,{group:i.name})),a.setAttribute(L,`group:${i.name}`),a.innerHTML=v(i.folded?`chevron-right`:`chevron-down`,{size:16}),n.append(a,K(`span`,null,i.name),K(`span`,null,y(r,`groupSummary`,i.count,{percent:i.percent}))),e.append(n)}let a=K(`div`,`wui-gantt-group-summary`);a.dataset.wuiGanttGroup=i.name,a.style.left=q(t.x),a.style.width=q(t.w),a.style.top=q(t.top+n.geometry.groupBarTop),a.style.height=q(d.groupBarH),e.append(a)}_deps(e){let t=document.createElementNS(z,`svg`);t.setAttribute(`class`,`wui-gantt-deps`),t.setAttribute(`aria-hidden`,`true`),t.setAttribute(`width`,String(e.axis.width)),t.setAttribute(`height`,String(e.height));for(let n of e.arrows){let e=document.createElementNS(z,`path`);e.setAttribute(`d`,n.d),e.setAttribute(`fill`,`none`);let r=document.createElementNS(z,`polygon`);r.setAttribute(`points`,n.head),e.dataset.from=n.fromKey,e.dataset.to=n.toKey,t.append(e,r)}return t}_details(t,n){let r=this._selected,i=r===null?void 0:t.rows.find(e=>e.row.key===r&&e.kind!==`group`&&!e.hidden);if(!i)return null;let a=A(),{row:o}=i,s=K(`div`,`wui-gantt-details`);s.setAttribute(`role`,`group`),s.setAttribute(`aria-label`,o.name),s.style.width=q(U);let c=K(`dl`),u=(e,t)=>{c.append(K(`dt`,null,e),K(`dd`,null,t))},d=f(l(o.start??``));o.owner&&u(a.detailsOwner,o.owner),u(a.detailsDates,o.end===void 0?d:x(a.detailsRange,{start:d,end:f(l(o.end))})),o.end!==void 0&&u(a.detailsDone,`${X(o)}%, ${Y(Z(o))}`);let p=this._names(o,n);p&&u(a.detailsStartsAfter,p);let m=K(`button`,e(`neutral`,`ghost`,`sm`),a.detailsCloseLabel);return m.type=`button`,m.setAttribute(L,`close`),s.append(K(`h3`,`h6`,o.name),c,m),s}};export{$ as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{a as t,l as n,s as r}from"./nativeOverlay-C1Rw2gIW.js";var i=300,a=150,o=`.wui-hover-card-trigger`,s=`.wui-hover-card-panel`,c=`a[href],button,input,select,textarea,[tabindex]`,l=0;function u(e,t){let n=e.querySelector(t);return n instanceof HTMLElement?n:null}var d=class extends e{_doc;_timer;_described;_refocusing;_onOver;_onOut;_onFocusIn;_onFocusOut;_onKeyDown;static get observedAttributes(){return[`open`]}constructor(){super(),this._doc=null,this._timer=null,this._described=null,this._refocusing=!1,this._onOver=e=>{if(e.pointerType===`touch`||e.pointerType===`pen`)return;let t=this._zone(e.target);t===`panel`?this._clear():t===`trigger`&&this._schedule(!0)},this._onOut=e=>{e.pointerType!==`touch`&&e.pointerType!==`pen`&&this._zone(e.target)&&!this._zone(e.relatedTarget)&&this._schedule(!1)},this._onFocusIn=e=>{this._refocusing||(this._zone(e.target)===`trigger`?this._schedule(!0):this._zone(e.target)===`panel`&&this._clear())},this._onFocusOut=e=>{this._zone(e.target)&&!this._zone(e.relatedTarget)&&this._schedule(!1)},this._onKeyDown=e=>{if(e.key!==`Escape`||!this.isOpen||this.hasAttribute(`open`))return;e.preventDefault();let t=this._zone(this.ownerDocument.activeElement)===`panel`;this._clear(),this._setOpen(!1),t&&(this._refocusing=!0,this._anchor?.focus(),this._refocusing=!1)}}get isOpen(){let e=this._panel;return e!==null&&r(e)}connectedCallback(){this._doc=this.ownerDocument,this.addEventListener(`pointerover`,this._onOver),this.addEventListener(`pointerout`,this._onOut),this.addEventListener(`focusin`,this._onFocusIn),this.addEventListener(`focusout`,this._onFocusOut),this._syncOpen()}attributeChangedCallback(){this.isConnected&&this._syncOpen()}disconnectedCallback(){this._clear();let e=this._panel;e&&t(e),this.removeEventListener(`pointerover`,this._onOver),this.removeEventListener(`pointerout`,this._onOut),this.removeEventListener(`focusin`,this._onFocusIn),this.removeEventListener(`focusout`,this._onFocusOut),this._doc=null}get _trigger(){return u(this,o)}get _panel(){return u(this,s)}get _anchor(){let e=this._trigger;return e?u(e,c)??e:null}_zone(e){if(!(e instanceof Node)||!this.contains(e))return null;let t=e instanceof Element?e:e.parentElement;return this._panel?.contains(t)?`panel`:this._trigger?.contains(t)?`trigger`:null}_delay(e,t){let n=Number(this.getAttribute(e));return this.hasAttribute(e)&&Number.isFinite(n)&&n>=0?n:t}_clear(){this._timer!==null&&clearTimeout(this._timer),this._timer=null}_syncOpen(){this._clear(),this._setOpen(this.hasAttribute(`open`))}_schedule(e){if(!e&&this.hasAttribute(`open`)||(this._clear(),this.isOpen===e))return;let t=e?this._delay(`open-delay`,i):this._delay(`close-delay`,a);this._timer=setTimeout(()=>{this._timer=null,this._setOpen(e)},t)}_setOpen(e){let r=this._panel;if(!r||this.isOpen===e)return;if(!e){t(r);return}let i=this._trigger;if(!i)throw Error(`wui-hover-card: panel without a trigger`);n(i,r,{mode:`manual`,clampHeight:!0,keepOffscreen:this.hasAttribute(`open`),onClosed:()=>this._closed()}),this._doc?.addEventListener(`keydown`,this._onKeyDown,!0),this._describe(r),this.dispatchEvent(new CustomEvent(`wui:hover-card:open`,{bubbles:!0}))}_closed(){this._doc?.removeEventListener(`keydown`,this._onKeyDown,!0),this._described?.removeAttribute(`aria-describedby`),this._described=null,this.dispatchEvent(new CustomEvent(`wui:hover-card:close`,{bubbles:!0}))}_describe(e){let t=this._anchor;t&&(e.id||=`wui-hover-card-${++l}`,t.setAttribute(`aria-describedby`,e.id),this._described=t)}};export{d as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{a as t,l as n,s as r}from"./nativeOverlay-D3VmY8qn.js";var i=300,a=150,o=`.wui-hover-card-trigger`,s=`.wui-hover-card-panel`,c=`a[href],button,input,select,textarea,[tabindex]`,l=0;function u(e,t){let n=e.querySelector(t);return n instanceof HTMLElement?n:null}var d=class extends e{_doc;_timer;_described;_refocusing;_onOver;_onOut;_onFocusIn;_onFocusOut;_onKeyDown;static get observedAttributes(){return[`open`]}constructor(){super(),this._doc=null,this._timer=null,this._described=null,this._refocusing=!1,this._onOver=e=>{if(e.pointerType===`touch`||e.pointerType===`pen`)return;let t=this._zone(e.target);t===`panel`?this._clear():t===`trigger`&&this._schedule(!0)},this._onOut=e=>{e.pointerType!==`touch`&&e.pointerType!==`pen`&&this._zone(e.target)&&!this._zone(e.relatedTarget)&&this._schedule(!1)},this._onFocusIn=e=>{this._refocusing||(this._zone(e.target)===`trigger`?this._schedule(!0):this._zone(e.target)===`panel`&&this._clear())},this._onFocusOut=e=>{this._zone(e.target)&&!this._zone(e.relatedTarget)&&this._schedule(!1)},this._onKeyDown=e=>{if(e.key!==`Escape`||!this.isOpen||this.hasAttribute(`open`))return;e.preventDefault();let t=this._zone(this.ownerDocument.activeElement)===`panel`;this._clear(),this._setOpen(!1),t&&(this._refocusing=!0,this._anchor?.focus(),this._refocusing=!1)}}get isOpen(){let e=this._panel;return e!==null&&r(e)}connectedCallback(){this._doc=this.ownerDocument,this.addEventListener(`pointerover`,this._onOver),this.addEventListener(`pointerout`,this._onOut),this.addEventListener(`focusin`,this._onFocusIn),this.addEventListener(`focusout`,this._onFocusOut),this._syncOpen()}attributeChangedCallback(){this.isConnected&&this._syncOpen()}disconnectedCallback(){this._clear();let e=this._panel;e&&t(e),this.removeEventListener(`pointerover`,this._onOver),this.removeEventListener(`pointerout`,this._onOut),this.removeEventListener(`focusin`,this._onFocusIn),this.removeEventListener(`focusout`,this._onFocusOut),this._doc=null}get _trigger(){return u(this,o)}get _panel(){return u(this,s)}get _anchor(){let e=this._trigger;return e?u(e,c)??e:null}_zone(e){if(!(e instanceof Node)||!this.contains(e))return null;let t=e instanceof Element?e:e.parentElement;return this._panel?.contains(t)?`panel`:this._trigger?.contains(t)?`trigger`:null}_delay(e,t){let n=Number(this.getAttribute(e));return this.hasAttribute(e)&&Number.isFinite(n)&&n>=0?n:t}_clear(){this._timer!==null&&clearTimeout(this._timer),this._timer=null}_syncOpen(){this._clear(),this._setOpen(this.hasAttribute(`open`))}_schedule(e){if(!e&&this.hasAttribute(`open`)||(this._clear(),this.isOpen===e))return;let t=e?this._delay(`open-delay`,i):this._delay(`close-delay`,a);this._timer=setTimeout(()=>{this._timer=null,this._setOpen(e)},t)}_setOpen(e){let r=this._panel;if(!r||this.isOpen===e)return;if(!e){t(r);return}let i=this._trigger;if(!i)throw Error(`wui-hover-card: panel without a trigger`);n(i,r,{mode:`manual`,clampHeight:!0,keepOffscreen:this.hasAttribute(`open`),onClosed:()=>this._closed()}),this._doc?.addEventListener(`keydown`,this._onKeyDown,!0),this._describe(r),this.dispatchEvent(new CustomEvent(`wui:hover-card:open`,{bubbles:!0}))}_closed(){this._doc?.removeEventListener(`keydown`,this._onKeyDown,!0),this._described?.removeAttribute(`aria-describedby`),this._described=null,this.dispatchEvent(new CustomEvent(`wui:hover-card:close`,{bubbles:!0}))}_describe(e){let t=this._anchor;t&&(e.id||=`wui-hover-card-${++l}`,t.setAttribute(`aria-describedby`,e.id),this._described=t)}};export{d as t};
@@ -1 +1 @@
1
- import{i as e}from"./calendarMath-CFjBxJYM.js";import{n as t,r as n,t as r}from"./digitGrouping-CCPI3HK3.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{o as a}from"./formatters-Dy4kQQ_h.js";import{t as o}from"./imeSafeEnter-DPs9qL3S.js";import{n as s,t as c}from"./inlineEditText-BUO5sZxN.js";import{l}from"./wuiHttp-DGbD7Fra.js";import{r as u,t as d}from"./textStore-opIEM4lu.js";import{t as f}from"./inlineEdit.g-ZxRNYq0t.js";var p=()=>u(`inlineEdit`,f),m=e=>s.some(t=>t===e),h=`[data-wui-display]`,g=`[data-wui-value]`,_=`[data-wui-editor]`,v=`[data-wui-control]`,y=`[data-wui-error]`,b=`[data-wui-live]`,x=`[aria-expanded="true"]`,S=/* @__PURE__ */ new Set([`select`,`date`]),C=e=>{let t=(typeof e==`object`||typeof e==`function`)&&e!==null&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:p().serverMessage},w=e=>e instanceof HTMLElement&&typeof(`value`in e?e.value:void 0)==`string`,T=(e,t)=>{let n=e?.querySelector(t)??null;return n instanceof HTMLElement?n:null},E=class extends i{_wired;_editing;_busy;_draft;_pressed;_popupOpen;_savedTimer;static get observedAttributes(){return[`disabled`]}constructor(){super(),this._wired=!1,this._editing=!1,this._busy=!1,this._draft=null,this._pressed=!1,this._popupOpen=!1,this._savedTimer=null,this._onClick=this._onClick.bind(this),this._onKeyCapture=this._onKeyCapture.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onChange=this._onChange.bind(this)}connectedCallback(){this._wired||(this._wired=!0,this._grouping(),this.addEventListener(`click`,this._onClick),this.addEventListener(`auxclick`,this._onClick),this.addEventListener(`keydown`,this._onKeyCapture,!0),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`focusout`,this._onFocusOut),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`change`,this._onChange))}disconnectedCallback(){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,this._releasePress()}attributeChangedCallback(e){e===`disabled`&&this.hasAttribute(`disabled`)&&this.cancel()}edit(){if(this._editing||this._busy||this.hasAttribute(`disabled`))return;let e=T(this,h),t=T(this,_),n=this._control();e&&t&&n&&(this._editing=!0,this._setState(null),n.value=this._draft??this._value(),t.hidden=!1,this.setAttribute(`data-wui-editing`,``),this._focusControl(n),e.hidden=!0)}cancel(){this._editing&&(this._draft=null,this._setError(null),this.getAttribute(`data-wui-state`)===`error`&&this._setState(null),this._close())}_onClick(e){e.stopPropagation();let t=e.target instanceof Node?e.target:null;e.type===`click`&&!this._editing&&this.querySelector(h)?.contains(t)&&this.edit()}_onKeyCapture(){this._popupOpen=!!(this._editing&&this.querySelector(_)?.querySelector(x))}_onKeyDown(e){if(!this._editing){(o(e)||e.key===` `)&&e.stopPropagation();return}if(e.stopPropagation(),this._popupOpen)return;if(e.key===`Escape`){e.preventDefault(),this.cancel();return}let t=this._type();e.key!==`Enter`||S.has(t)||(t!==`textarea`||e.ctrlKey||e.metaKey)&&(e.preventDefault(),this._commit(this._control()?.value??``))}_onFocusOut(e){if(!this._editing||this._pressed)return;let t=e.relatedTarget instanceof Node?e.relatedTarget:null;t&&this.contains(t)||document.hasFocus()&&this._commit(this._control()?.value??``)}_onPointerDown(){this._editing&&(this._pressed=!0,document.addEventListener(`pointerup`,this._onPointerUp,!0),document.addEventListener(`pointercancel`,this._onPointerUp,!0))}_onPointerUp(){this._releasePress(),setTimeout(()=>{this._pressed=!1,this._editing&&!this.contains(document.activeElement)&&document.hasFocus()&&this._commit(this._control()?.value??``)},0)}_releasePress(){document.removeEventListener(`pointerup`,this._onPointerUp,!0),document.removeEventListener(`pointercancel`,this._onPointerUp,!0)}_onChange(e){if(!this._editing||!S.has(this._type()))return;let t=this._control();t&&e.target===t&&queueMicrotask(()=>this._commit(t.value))}async _commit(e){if(!this._editing||this._busy)return;let t=this._value();if(e===t){this.cancel();return}let n=typeof this.validate==`function`?this.validate(e):null;if(n){this._setError(n),this._announce(n);return}let r=this.hasAttribute(`controlled`);this._draft=null,this._setError(null),this._busy=!0,this._setState(`saving`),this.setAttribute(`aria-busy`,`true`);let i=r?null:this._readShown();r||this._showValue(e),this._close();let a=await this._persist(e,r);this._busy=!1,this.removeAttribute(`aria-busy`);let o=this.getAttribute(`label`)||``;a.ok?(this.setAttribute(`value`,e),!r&&a.text&&this._showText(a.text,!1),this._setState(`saved`),this._savedTimer=setTimeout(()=>this._setState(null),c),this._announce(d(p().savedText,{label:o})),this._fire(`wui:inline-edit:saved`,{value:e,previous:t})):(i&&this._restoreShown(i),a.kind===`session`||a.kind===`aborted`?this._setState(null):(this._draft=e,this._setState(`error`),this._setError(a.message),this._announce(d(p().notSavedText,{label:o,reason:a.message})),this._fire(`wui:inline-edit:failed`,{value:e,previous:t,kind:a.kind,message:a.message})))}async _persist(e,t){if(t){if(typeof this.save!=`function`)return{ok:!0};try{return await this.save(e),{ok:!0}}catch(e){return{ok:!1,kind:`server`,message:C(e)}}}let n=this.getAttribute(`action`);if(!n)return{ok:!0};let r=new URLSearchParams({[this.getAttribute(`name`)||`value`]:e}),i=await l(n,{method:`POST`,body:r});if(i.ok)return{ok:!0,text:i.html.trim()};let a={forbidden:p().forbiddenMessage,client:p().clientMessage,validation:p().validationMessage,server:p().serverMessage,network:p().networkMessage};return{ok:!1,kind:i.kind,message:i.message||a[i.kind]||p().serverMessage}}_close(){let e=T(this,h),t=T(this,_),n=this.contains(document.activeElement);this._editing=!1,this.removeAttribute(`data-wui-editing`),t&&(t.hidden=!0),e&&(e.hidden=!1),T(t,x)?.click(),n&&e?.focus()}_focusControl(e){if(!S.has(this._type())){e.focus(),e.select?.();return}let t=T(e,`button`);t&&(t.focus(),t.getAttribute(`aria-expanded`)!==`true`&&t.click())}_showValue(t){if(t===``){this._showText(this.getAttribute(`placeholder`)||a(),!0);return}let n=this._type(),i=t;if(n===`date`)i=e(t)||t;else if(n===`select`){let e=[...this._control()?.querySelectorAll(`[data-value]`)??[]].find(e=>e.getAttribute(`data-value`)===t);e&&(i=(e.textContent??``).trim())}else n===`number`&&this._grouping()===`indian`&&(i=r(t));this._showText(i,!1)}_readShown(){let e=this.querySelector(g);return e?{html:e.innerHTML,empty:e.hasAttribute(`data-wui-empty`)}:null}_restoreShown(e){let t=this.querySelector(g);t&&(t.innerHTML=e.html,t.toggleAttribute(`data-wui-empty`,e.empty))}_showText(e,t){let n=this.querySelector(g);n&&(n.textContent=e,n.toggleAttribute(`data-wui-empty`,t))}_setError(e){let t=T(this,y),n=this._control();t&&(t.textContent=e||``,t.hidden=!e),e?n?.setAttribute(`aria-invalid`,`true`):n?.removeAttribute(`aria-invalid`)}_setState(e){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,e?this.setAttribute(`data-wui-state`,e):this.removeAttribute(`data-wui-state`)}_announce(e){let t=this.querySelector(b);t&&e&&(t.textContent=``,t.textContent=e)}_fire(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t}))}_control(){let e=this.querySelector(v);return w(e)?e:null}_value(){return this.getAttribute(`value`)??``}_type(){let e=this.getAttribute(`type`);return m(e)?e:`text`}_grouping(){let e=this.getAttribute(`grouping`)??`none`;if(!n(e))throw Error(t(e));return e}};export{E as t};
1
+ import{i as e}from"./calendarMath-ChZ_s7HH.js";import{n as t,r as n,t as r}from"./digitGrouping-CCPI3HK3.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{o as a}from"./formatters-CMTSYlW9.js";import{t as o}from"./imeSafeEnter-DPs9qL3S.js";import{n as s,t as c}from"./inlineEditText-5FT8SGqR.js";import{l}from"./wuiHttp-DGbD7Fra.js";import{r as u,t as d}from"./textStore-opIEM4lu.js";import{t as f}from"./inlineEdit.g-ZxRNYq0t.js";var p=()=>u(`inlineEdit`,f),m=e=>s.some(t=>t===e),h=`[data-wui-display]`,g=`[data-wui-value]`,_=`[data-wui-editor]`,v=`[data-wui-control]`,y=`[data-wui-error]`,b=`[data-wui-live]`,x=`[aria-expanded="true"]`,S=/* @__PURE__ */ new Set([`select`,`date`]),C=e=>{let t=(typeof e==`object`||typeof e==`function`)&&e!==null&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:p().serverMessage},w=e=>e instanceof HTMLElement&&typeof(`value`in e?e.value:void 0)==`string`,T=(e,t)=>{let n=e?.querySelector(t)??null;return n instanceof HTMLElement?n:null},E=class extends i{_wired;_editing;_busy;_draft;_pressed;_popupOpen;_savedTimer;static get observedAttributes(){return[`disabled`]}constructor(){super(),this._wired=!1,this._editing=!1,this._busy=!1,this._draft=null,this._pressed=!1,this._popupOpen=!1,this._savedTimer=null,this._onClick=this._onClick.bind(this),this._onKeyCapture=this._onKeyCapture.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onChange=this._onChange.bind(this)}connectedCallback(){this._wired||(this._wired=!0,this._grouping(),this.addEventListener(`click`,this._onClick),this.addEventListener(`auxclick`,this._onClick),this.addEventListener(`keydown`,this._onKeyCapture,!0),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`focusout`,this._onFocusOut),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`change`,this._onChange))}disconnectedCallback(){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,this._releasePress()}attributeChangedCallback(e){e===`disabled`&&this.hasAttribute(`disabled`)&&this.cancel()}edit(){if(this._editing||this._busy||this.hasAttribute(`disabled`))return;let e=T(this,h),t=T(this,_),n=this._control();e&&t&&n&&(this._editing=!0,this._setState(null),n.value=this._draft??this._value(),t.hidden=!1,this.setAttribute(`data-wui-editing`,``),this._focusControl(n),e.hidden=!0)}cancel(){this._editing&&(this._draft=null,this._setError(null),this.getAttribute(`data-wui-state`)===`error`&&this._setState(null),this._close())}_onClick(e){e.stopPropagation();let t=e.target instanceof Node?e.target:null;e.type===`click`&&!this._editing&&this.querySelector(h)?.contains(t)&&this.edit()}_onKeyCapture(){this._popupOpen=!!(this._editing&&this.querySelector(_)?.querySelector(x))}_onKeyDown(e){if(!this._editing){(o(e)||e.key===` `)&&e.stopPropagation();return}if(e.stopPropagation(),this._popupOpen)return;if(e.key===`Escape`){e.preventDefault(),this.cancel();return}let t=this._type();e.key!==`Enter`||S.has(t)||(t!==`textarea`||e.ctrlKey||e.metaKey)&&(e.preventDefault(),this._commit(this._control()?.value??``))}_onFocusOut(e){if(!this._editing||this._pressed)return;let t=e.relatedTarget instanceof Node?e.relatedTarget:null;t&&this.contains(t)||document.hasFocus()&&this._commit(this._control()?.value??``)}_onPointerDown(){this._editing&&(this._pressed=!0,document.addEventListener(`pointerup`,this._onPointerUp,!0),document.addEventListener(`pointercancel`,this._onPointerUp,!0))}_onPointerUp(){this._releasePress(),setTimeout(()=>{this._pressed=!1,this._editing&&!this.contains(document.activeElement)&&document.hasFocus()&&this._commit(this._control()?.value??``)},0)}_releasePress(){document.removeEventListener(`pointerup`,this._onPointerUp,!0),document.removeEventListener(`pointercancel`,this._onPointerUp,!0)}_onChange(e){if(!this._editing||!S.has(this._type()))return;let t=this._control();t&&e.target===t&&queueMicrotask(()=>this._commit(t.value))}async _commit(e){if(!this._editing||this._busy)return;let t=this._value();if(e===t){this.cancel();return}let n=typeof this.validate==`function`?this.validate(e):null;if(n){this._setError(n),this._announce(n);return}let r=this.hasAttribute(`controlled`);this._draft=null,this._setError(null),this._busy=!0,this._setState(`saving`),this.setAttribute(`aria-busy`,`true`);let i=r?null:this._readShown();r||this._showValue(e),this._close();let a=await this._persist(e,r);this._busy=!1,this.removeAttribute(`aria-busy`);let o=this.getAttribute(`label`)||``;a.ok?(this.setAttribute(`value`,e),!r&&a.text&&this._showText(a.text,!1),this._setState(`saved`),this._savedTimer=setTimeout(()=>this._setState(null),c),this._announce(d(p().savedText,{label:o})),this._fire(`wui:inline-edit:saved`,{value:e,previous:t})):(i&&this._restoreShown(i),a.kind===`session`||a.kind===`aborted`?this._setState(null):(this._draft=e,this._setState(`error`),this._setError(a.message),this._announce(d(p().notSavedText,{label:o,reason:a.message})),this._fire(`wui:inline-edit:failed`,{value:e,previous:t,kind:a.kind,message:a.message})))}async _persist(e,t){if(t){if(typeof this.save!=`function`)return{ok:!0};try{return await this.save(e),{ok:!0}}catch(e){return{ok:!1,kind:`server`,message:C(e)}}}let n=this.getAttribute(`action`);if(!n)return{ok:!0};let r=new URLSearchParams({[this.getAttribute(`name`)||`value`]:e}),i=await l(n,{method:`POST`,body:r});if(i.ok)return{ok:!0,text:i.html.trim()};let a={forbidden:p().forbiddenMessage,client:p().clientMessage,validation:p().validationMessage,server:p().serverMessage,network:p().networkMessage};return{ok:!1,kind:i.kind,message:i.message||a[i.kind]||p().serverMessage}}_close(){let e=T(this,h),t=T(this,_),n=this.contains(document.activeElement);this._editing=!1,this.removeAttribute(`data-wui-editing`),t&&(t.hidden=!0),e&&(e.hidden=!1),T(t,x)?.click(),n&&e?.focus()}_focusControl(e){if(!S.has(this._type())){e.focus(),e.select?.();return}let t=T(e,`button`);t&&(t.focus(),t.getAttribute(`aria-expanded`)!==`true`&&t.click())}_showValue(t){if(t===``){this._showText(this.getAttribute(`placeholder`)||a(),!0);return}let n=this._type(),i=t;if(n===`date`)i=e(t)||t;else if(n===`select`){let e=[...this._control()?.querySelectorAll(`[data-value]`)??[]].find(e=>e.getAttribute(`data-value`)===t);e&&(i=(e.textContent??``).trim())}else n===`number`&&this._grouping()===`indian`&&(i=r(t));this._showText(i,!1)}_readShown(){let e=this.querySelector(g);return e?{html:e.innerHTML,empty:e.hasAttribute(`data-wui-empty`)}:null}_restoreShown(e){let t=this.querySelector(g);t&&(t.innerHTML=e.html,t.toggleAttribute(`data-wui-empty`,e.empty))}_showText(e,t){let n=this.querySelector(g);n&&(n.textContent=e,n.toggleAttribute(`data-wui-empty`,t))}_setError(e){let t=T(this,y),n=this._control();t&&(t.textContent=e||``,t.hidden=!e),e?n?.setAttribute(`aria-invalid`,`true`):n?.removeAttribute(`aria-invalid`)}_setState(e){clearTimeout(this._savedTimer??void 0),this._savedTimer=null,e?this.setAttribute(`data-wui-state`,e):this.removeAttribute(`data-wui-state`)}_announce(e){let t=this.querySelector(b);t&&e&&(t.textContent=``,t.textContent=e)}_fire(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t}))}_control(){let e=this.querySelector(v);return w(e)?e:null}_value(){return this.getAttribute(`value`)??``}_type(){let e=this.getAttribute(`type`);return m(e)?e:`text`}_grouping(){let e=this.getAttribute(`grouping`)??`none`;if(!n(e))throw Error(t(e));return e}};export{E as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{f as t}from"./formatters-Dy4kQQ_h.js";import{t as n}from"./iconGlyphs.g-DxSJLQJ8.js";import{u as r}from"./nativeOverlay-C1Rw2gIW.js";import{r as i,t as a}from"./textStore-opIEM4lu.js";import{t as o}from"./lightbox.g-DDrycPou.js";var s=`a.wui-lightbox-item`,c=1,l=4,u=.5,d=2,f=50,p=6,m=300,h=300;function g(e){return Number.isFinite(e)?Math.min(l,Math.max(c,e)):c}function _(e,t,n,r){let i=(e,n)=>Math.max(0,(e*t-n)/2),a=i(r.width,n.width),o=i(r.height,n.height);return{x:Math.min(a,Math.max(-a,e.x)),y:Math.min(o,Math.max(-o,e.y))}}function v(e,t){return Math.abs(e)<f||Math.abs(e)<Math.abs(t)*1.5?0:e<0?1:-1}function y(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}function b(e,t,n={}){let r=document.createElement(e);r.className=t;for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r}var x=()=>i(`lightbox`,o);function S(e,t,r){let i=b(`button`,`u-action wui-lightbox-btn ${r}`,{type:`button`,"aria-label":t,title:t});return i.style.setProperty(`--wui-action-size`,`40px`),i.innerHTML=n(e,{size:20}),i}var C=class extends e{_ui;_index;_zoom;_pan;_pointers;_gesture;_lastTap;_returnTo;_release;_onClick;static get observedAttributes(){return[`open-index`]}constructor(){super(),this._ui=null,this._index=0,this._zoom=c,this._pan={x:0,y:0},this._pointers=/* @__PURE__ */ new Map,this._gesture=null,this._lastTap=-1/0,this._returnTo=null,this._release=null,this._onClick=e=>{if(e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;let t=e.target,n=t instanceof Element?t.closest(s):null;if(!(n instanceof HTMLAnchorElement)||!this.contains(n))return;let r=this._links().indexOf(n);r<0||(e.preventDefault(),this.open(r))}}get _view(){if(!this._ui)throw Error(`<wui-lightbox> viewer is not open.`);return this._ui}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get label(){return this.getAttribute(`label`)||x().label}set label(e){this.setAttribute(`label`,String(e??``))}get layout(){return this.getAttribute(`layout`)===`single`?`single`:`gallery`}set layout(e){if(e===`single`)this.setAttribute(`layout`,`single`);else if(e===`gallery`||e===``)this.removeAttribute(`layout`);else throw Error(`<wui-lightbox> layout must be "gallery" or "single", received "${e}".`)}get isOpen(){return this._ui!==null}connectedCallback(){this.addEventListener(`click`,this._onClick),this._syncOpenIndex()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this._teardown()}attributeChangedCallback(){this.isConnected&&this._syncOpenIndex()}_syncOpenIndex(){let e=this.getAttribute(`open-index`);e===null?this.close():this.open(Number(e))}_links(){return[...this.querySelectorAll(s)].filter(e=>e instanceof HTMLAnchorElement)}_items(){return this._links().map(e=>{let t=e.getAttribute(`href`)??``;return{link:e,src:t,alt:e.querySelector(`img`)?.getAttribute(`alt`)??``,caption:e.dataset.caption??``,name:e.dataset.name||y(t)}})}open(e=0){let t=this._items();if(!t.length)return!1;if(!this._ui){let t=document.activeElement;this._returnTo=t instanceof HTMLElement||t instanceof SVGElement?t:null,this._build(),this.dispatchEvent(new CustomEvent(`wui-lightbox:open`,{bubbles:!0,detail:{index:e}}))}return this._show(e,t),!0}close(){if(!this._ui)return;let e=this._index,t=this._links()[e]??this._returnTo;this._teardown(),t?.isConnected&&t.focus(),this._returnTo=null,this.dispatchEvent(new CustomEvent(`wui-lightbox:close`,{bubbles:!0,detail:{index:e}}))}_teardown(){this._ui&&(this._release?.(),this._release=null,this._ui.root.open&&this._ui.root.close(),this._ui.root.remove(),this._ui=null,this._pointers.clear(),this._gesture=null)}_build(){let e=b(`dialog`,`wui-lightbox-overlay`,{role:`dialog`,"aria-label":this.label,tabindex:`-1`}),t=b(`div`,`wui-lightbox-bar`),i=b(`span`,`wui-lightbox-count`,{"aria-live":`polite`}),a=b(`div`,`wui-lightbox-tools`),o=S(`zoom-out`,x().zoomOutLabel,`wui-lightbox-zoom-out`),s=S(`zoom-in`,x().zoomInLabel,`wui-lightbox-zoom-in`),c=b(`a`,`u-action wui-lightbox-btn wui-lightbox-download`,{"aria-label":x().downloadLabel,title:x().downloadLabel});c.style.setProperty(`--wui-action-size`,`40px`),c.innerHTML=n(`download`,{size:20}),c.hidden=!this.download;let l=S(`x`,x().closeLabel,`wui-lightbox-close`);a.append(o,s,c,l),t.append(i,a);let d=b(`div`,`wui-lightbox-stage`),f=S(`chevron-left`,x().previousImageLabel,`wui-lightbox-nav wui-lightbox-prev`),p=S(`chevron-right`,x().nextImageLabel,`wui-lightbox-nav wui-lightbox-next`),m=b(`img`,`wui-lightbox-image`,{decoding:`async`,draggable:`false`,alt:``}),h=b(`p`,`wui-lightbox-status`,{role:`status`});d.append(m,h,f,p);let g=b(`p`,`wui-lightbox-caption`);e.append(t,d,g);let _={root:e,count:i,zoomOut:o,zoomIn:s,download:c,close:l,stage:d,prev:f,next:p,image:m,status:h,caption:g};this._ui=_,l.addEventListener(`click`,()=>this.close()),f.addEventListener(`click`,()=>this.step(-1)),p.addEventListener(`click`,()=>this.step(1)),o.addEventListener(`click`,()=>this._setZoom(this._zoom-u)),s.addEventListener(`click`,()=>this._setZoom(this._zoom+u)),e.addEventListener(`keydown`,e=>this._onKeyDown(e)),d.addEventListener(`pointerdown`,e=>this._onPointerDown(e)),d.addEventListener(`pointermove`,e=>this._onPointerMove(e)),d.addEventListener(`pointerup`,e=>this._onPointerEnd(e,!0)),d.addEventListener(`pointercancel`,e=>this._onPointerEnd(e,!1)),d.addEventListener(`wheel`,e=>this._onWheel(e),{passive:!1}),m.addEventListener(`load`,()=>{this._ui===_&&(h.textContent=``,d.removeAttribute(`aria-busy`),m.hidden=!1,this._applyTransform())}),m.addEventListener(`error`,()=>{this._ui===_&&(d.removeAttribute(`aria-busy`),m.hidden=!0,h.textContent=x().imageFailedMessage)}),this.append(e),this._release=r(e,{escape:!0,backdrop:!1,focus:`panel`,onRequestClose:()=>this.close()})}step(e){if(!this._ui||!e)return;let t=this._items();t.length<2||this._show((this._index+e+t.length)%t.length,t)}_show(e,n){let r=this._view,i=Math.min(n.length-1,Math.max(0,Math.trunc(Number(e))||0)),o=n[i];if(!o)throw Error(`<wui-lightbox> image missing.`);let s=i!==this._index||!r.image.getAttribute(`src`);if(this._index=i,this._zoom=c,this._pan={x:0,y:0},r.count.textContent=a(x().countText,{position:t(i+1,{decimals:0}),total:t(n.length,{decimals:0})}),r.caption.textContent=o.caption,r.caption.hidden=!o.caption,r.download.href=o.src,r.download.setAttribute(`download`,o.name),r.prev.hidden=r.next.hidden=n.length<2,r.stage.setAttribute(`aria-busy`,`true`),r.status.textContent=``,r.image.hidden=!1,r.image.alt=o.alt||o.caption,r.image.src=o.src,this._applyTransform(),this._syncZoomButtons(),n.length>1){let e=n[(i+1)%n.length],t=n[(i-1+n.length)%n.length];if(!e||!t)throw Error(`<wui-lightbox> neighbour image missing.`);for(let n of[e,t])new Image().src=n.src}s&&this.dispatchEvent(new CustomEvent(`wui-lightbox:change`,{bubbles:!0,detail:{index:i}}))}_syncZoomButtons(){let e=this._view;e.zoomOut.disabled=this._zoom<=c,e.zoomIn.disabled=this._zoom>=l;let t=document.activeElement;(t===e.zoomOut||t===e.zoomIn)&&t instanceof HTMLButtonElement&&t.disabled&&e.close.focus()}_setZoom(e){this._ui&&(this._zoom=g(e),this._pan=this._clampedPan(this._pan),this._applyTransform(),this._syncZoomButtons())}_clampedPan(e){let{stage:t,image:n}=this._view;return _(e,this._zoom,{width:t.clientWidth,height:t.clientHeight},{width:n.offsetWidth,height:n.offsetHeight})}_applyTransform(){let{image:e,stage:t}=this._view;e.style.transform=`translate(${this._pan.x}px, ${this._pan.y}px) scale(${this._zoom})`,t.classList.toggle(`wui-lightbox-zoomed`,this._zoom>c)}_onKeyDown(e){if(e.key===`ArrowLeft`||e.key===`ArrowRight`)e.preventDefault(),this.step(e.key===`ArrowRight`?1:-1);else if(e.key===`Home`||e.key===`End`){e.preventDefault();let t=this._items();this._show(e.key===`Home`?0:t.length-1,t)}else e.key===`+`||e.key===`=`?(e.preventDefault(),this._setZoom(this._zoom+u)):e.key===`-`?(e.preventDefault(),this._setZoom(this._zoom-u)):e.key===`0`&&(e.preventDefault(),this._setZoom(c))}_onWheel(e){e.preventDefault(),this._setZoom(this._zoom*(e.deltaY<0?1.15:1/1.15))}_onPointerDown(e){let t=e.target;if(t instanceof Element&&t.closest(`.wui-lightbox-nav`))return;let n=this._view;if(n.stage.setPointerCapture?.(e.pointerId),this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this._pointers.size===2){let e=[...this._pointers.values()],t=e[0],n=e[1];if(!t||!n)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._gesture={kind:`pinch`,distance:Math.hypot(t.x-n.x,t.y-n.y)||1,zoom:this._zoom}}else this._pointers.size===1&&(this._gesture={kind:`drag`,startX:e.clientX,startY:e.clientY,startTime:e.timeStamp,pan:{...this._pan},onImage:e.target===n.image,moved:!1})}_onPointerMove(e){let t=this._gesture;if(t&&this._pointers.has(e.pointerId)){if(this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.kind===`pinch`&&this._pointers.size===2){let e=[...this._pointers.values()],n=e[0],r=e[1];if(!n||!r)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._setZoom(t.zoom*Math.hypot(n.x-r.x,n.y-r.y)/t.distance)}else if(t.kind===`drag`){let n=e.clientX-t.startX,r=e.clientY-t.startY;Math.hypot(n,r)>p&&(t.moved=!0),this._zoom>c&&(this._pan=this._clampedPan({x:t.pan.x+n,y:t.pan.y+r}),this._view.stage.classList.add(`is-dragging`),this._applyTransform())}}}_onPointerEnd(e,t){let n=this._gesture;if(this._pointers.delete(e.pointerId),this._ui?.stage.classList.remove(`is-dragging`),!n)return;if(n.kind===`pinch`){this._pointers.size<2&&(this._gesture=null);return}if(this._gesture=null,!t)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;n.moved?this._zoom===c&&this.step(v(r,i)):e.timeStamp-n.startTime>m||(n.onImage?e.timeStamp-this._lastTap<h?(this._lastTap=-1/0,this._setZoom(this._zoom>c?c:d)):this._lastTap=e.timeStamp:this.close())}};export{C as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{f as t}from"./formatters-CMTSYlW9.js";import{t as n}from"./iconGlyphs.g-DxSJLQJ8.js";import{u as r}from"./nativeOverlay-D3VmY8qn.js";import{r as i,t as a}from"./textStore-opIEM4lu.js";import{t as o}from"./lightbox.g-DDrycPou.js";var s=`a.wui-lightbox-item`,c=1,l=4,u=.5,d=2,f=50,p=6,m=300,h=300;function g(e){return Number.isFinite(e)?Math.min(l,Math.max(c,e)):c}function _(e,t,n,r){let i=(e,n)=>Math.max(0,(e*t-n)/2),a=i(r.width,n.width),o=i(r.height,n.height);return{x:Math.min(a,Math.max(-a,e.x)),y:Math.min(o,Math.max(-o,e.y))}}function v(e,t){return Math.abs(e)<f||Math.abs(e)<Math.abs(t)*1.5?0:e<0?1:-1}function y(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}function b(e,t,n={}){let r=document.createElement(e);r.className=t;for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r}var x=()=>i(`lightbox`,o);function S(e,t,r){let i=b(`button`,`u-action wui-lightbox-btn ${r}`,{type:`button`,"aria-label":t,title:t});return i.style.setProperty(`--wui-action-size`,`40px`),i.innerHTML=n(e,{size:20}),i}var C=class extends e{_ui;_index;_zoom;_pan;_pointers;_gesture;_lastTap;_returnTo;_release;_onClick;static get observedAttributes(){return[`open-index`]}constructor(){super(),this._ui=null,this._index=0,this._zoom=c,this._pan={x:0,y:0},this._pointers=/* @__PURE__ */ new Map,this._gesture=null,this._lastTap=-1/0,this._returnTo=null,this._release=null,this._onClick=e=>{if(e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;let t=e.target,n=t instanceof Element?t.closest(s):null;if(!(n instanceof HTMLAnchorElement)||!this.contains(n))return;let r=this._links().indexOf(n);r<0||(e.preventDefault(),this.open(r))}}get _view(){if(!this._ui)throw Error(`<wui-lightbox> viewer is not open.`);return this._ui}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get label(){return this.getAttribute(`label`)||x().label}set label(e){this.setAttribute(`label`,String(e??``))}get layout(){return this.getAttribute(`layout`)===`single`?`single`:`gallery`}set layout(e){if(e===`single`)this.setAttribute(`layout`,`single`);else if(e===`gallery`||e===``)this.removeAttribute(`layout`);else throw Error(`<wui-lightbox> layout must be "gallery" or "single", received "${e}".`)}get isOpen(){return this._ui!==null}connectedCallback(){this.addEventListener(`click`,this._onClick),this._syncOpenIndex()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this._teardown()}attributeChangedCallback(){this.isConnected&&this._syncOpenIndex()}_syncOpenIndex(){let e=this.getAttribute(`open-index`);e===null?this.close():this.open(Number(e))}_links(){return[...this.querySelectorAll(s)].filter(e=>e instanceof HTMLAnchorElement)}_items(){return this._links().map(e=>{let t=e.getAttribute(`href`)??``;return{link:e,src:t,alt:e.querySelector(`img`)?.getAttribute(`alt`)??``,caption:e.dataset.caption??``,name:e.dataset.name||y(t)}})}open(e=0){let t=this._items();if(!t.length)return!1;if(!this._ui){let t=document.activeElement;this._returnTo=t instanceof HTMLElement||t instanceof SVGElement?t:null,this._build(),this.dispatchEvent(new CustomEvent(`wui-lightbox:open`,{bubbles:!0,detail:{index:e}}))}return this._show(e,t),!0}close(){if(!this._ui)return;let e=this._index,t=this._links()[e]??this._returnTo;this._teardown(),t?.isConnected&&t.focus(),this._returnTo=null,this.dispatchEvent(new CustomEvent(`wui-lightbox:close`,{bubbles:!0,detail:{index:e}}))}_teardown(){this._ui&&(this._release?.(),this._release=null,this._ui.root.open&&this._ui.root.close(),this._ui.root.remove(),this._ui=null,this._pointers.clear(),this._gesture=null)}_build(){let e=b(`dialog`,`wui-lightbox-overlay`,{role:`dialog`,"aria-label":this.label,tabindex:`-1`}),t=b(`div`,`wui-lightbox-bar`),i=b(`span`,`wui-lightbox-count`,{"aria-live":`polite`}),a=b(`div`,`wui-lightbox-tools`),o=S(`zoom-out`,x().zoomOutLabel,`wui-lightbox-zoom-out`),s=S(`zoom-in`,x().zoomInLabel,`wui-lightbox-zoom-in`),c=b(`a`,`u-action wui-lightbox-btn wui-lightbox-download`,{"aria-label":x().downloadLabel,title:x().downloadLabel});c.style.setProperty(`--wui-action-size`,`40px`),c.innerHTML=n(`download`,{size:20}),c.hidden=!this.download;let l=S(`x`,x().closeLabel,`wui-lightbox-close`);a.append(o,s,c,l),t.append(i,a);let d=b(`div`,`wui-lightbox-stage`),f=S(`chevron-left`,x().previousImageLabel,`wui-lightbox-nav wui-lightbox-prev`),p=S(`chevron-right`,x().nextImageLabel,`wui-lightbox-nav wui-lightbox-next`),m=b(`img`,`wui-lightbox-image`,{decoding:`async`,draggable:`false`,alt:``}),h=b(`p`,`wui-lightbox-status`,{role:`status`});d.append(m,h,f,p);let g=b(`p`,`wui-lightbox-caption`);e.append(t,d,g);let _={root:e,count:i,zoomOut:o,zoomIn:s,download:c,close:l,stage:d,prev:f,next:p,image:m,status:h,caption:g};this._ui=_,l.addEventListener(`click`,()=>this.close()),f.addEventListener(`click`,()=>this.step(-1)),p.addEventListener(`click`,()=>this.step(1)),o.addEventListener(`click`,()=>this._setZoom(this._zoom-u)),s.addEventListener(`click`,()=>this._setZoom(this._zoom+u)),e.addEventListener(`keydown`,e=>this._onKeyDown(e)),d.addEventListener(`pointerdown`,e=>this._onPointerDown(e)),d.addEventListener(`pointermove`,e=>this._onPointerMove(e)),d.addEventListener(`pointerup`,e=>this._onPointerEnd(e,!0)),d.addEventListener(`pointercancel`,e=>this._onPointerEnd(e,!1)),d.addEventListener(`wheel`,e=>this._onWheel(e),{passive:!1}),m.addEventListener(`load`,()=>{this._ui===_&&(h.textContent=``,d.removeAttribute(`aria-busy`),m.hidden=!1,this._applyTransform())}),m.addEventListener(`error`,()=>{this._ui===_&&(d.removeAttribute(`aria-busy`),m.hidden=!0,h.textContent=x().imageFailedMessage)}),this.append(e),this._release=r(e,{escape:!0,backdrop:!1,focus:`panel`,onRequestClose:()=>this.close()})}step(e){if(!this._ui||!e)return;let t=this._items();t.length<2||this._show((this._index+e+t.length)%t.length,t)}_show(e,n){let r=this._view,i=Math.min(n.length-1,Math.max(0,Math.trunc(Number(e))||0)),o=n[i];if(!o)throw Error(`<wui-lightbox> image missing.`);let s=i!==this._index||!r.image.getAttribute(`src`);if(this._index=i,this._zoom=c,this._pan={x:0,y:0},r.count.textContent=a(x().countText,{position:t(i+1,{decimals:0}),total:t(n.length,{decimals:0})}),r.caption.textContent=o.caption,r.caption.hidden=!o.caption,r.download.href=o.src,r.download.setAttribute(`download`,o.name),r.prev.hidden=r.next.hidden=n.length<2,r.stage.setAttribute(`aria-busy`,`true`),r.status.textContent=``,r.image.hidden=!1,r.image.alt=o.alt||o.caption,r.image.src=o.src,this._applyTransform(),this._syncZoomButtons(),n.length>1){let e=n[(i+1)%n.length],t=n[(i-1+n.length)%n.length];if(!e||!t)throw Error(`<wui-lightbox> neighbour image missing.`);for(let n of[e,t])new Image().src=n.src}s&&this.dispatchEvent(new CustomEvent(`wui-lightbox:change`,{bubbles:!0,detail:{index:i}}))}_syncZoomButtons(){let e=this._view;e.zoomOut.disabled=this._zoom<=c,e.zoomIn.disabled=this._zoom>=l;let t=document.activeElement;(t===e.zoomOut||t===e.zoomIn)&&t instanceof HTMLButtonElement&&t.disabled&&e.close.focus()}_setZoom(e){this._ui&&(this._zoom=g(e),this._pan=this._clampedPan(this._pan),this._applyTransform(),this._syncZoomButtons())}_clampedPan(e){let{stage:t,image:n}=this._view;return _(e,this._zoom,{width:t.clientWidth,height:t.clientHeight},{width:n.offsetWidth,height:n.offsetHeight})}_applyTransform(){let{image:e,stage:t}=this._view;e.style.transform=`translate(${this._pan.x}px, ${this._pan.y}px) scale(${this._zoom})`,t.classList.toggle(`wui-lightbox-zoomed`,this._zoom>c)}_onKeyDown(e){if(e.key===`ArrowLeft`||e.key===`ArrowRight`)e.preventDefault(),this.step(e.key===`ArrowRight`?1:-1);else if(e.key===`Home`||e.key===`End`){e.preventDefault();let t=this._items();this._show(e.key===`Home`?0:t.length-1,t)}else e.key===`+`||e.key===`=`?(e.preventDefault(),this._setZoom(this._zoom+u)):e.key===`-`?(e.preventDefault(),this._setZoom(this._zoom-u)):e.key===`0`&&(e.preventDefault(),this._setZoom(c))}_onWheel(e){e.preventDefault(),this._setZoom(this._zoom*(e.deltaY<0?1.15:1/1.15))}_onPointerDown(e){let t=e.target;if(t instanceof Element&&t.closest(`.wui-lightbox-nav`))return;let n=this._view;if(n.stage.setPointerCapture?.(e.pointerId),this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this._pointers.size===2){let e=[...this._pointers.values()],t=e[0],n=e[1];if(!t||!n)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._gesture={kind:`pinch`,distance:Math.hypot(t.x-n.x,t.y-n.y)||1,zoom:this._zoom}}else this._pointers.size===1&&(this._gesture={kind:`drag`,startX:e.clientX,startY:e.clientY,startTime:e.timeStamp,pan:{...this._pan},onImage:e.target===n.image,moved:!1})}_onPointerMove(e){let t=this._gesture;if(t&&this._pointers.has(e.pointerId)){if(this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.kind===`pinch`&&this._pointers.size===2){let e=[...this._pointers.values()],n=e[0],r=e[1];if(!n||!r)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._setZoom(t.zoom*Math.hypot(n.x-r.x,n.y-r.y)/t.distance)}else if(t.kind===`drag`){let n=e.clientX-t.startX,r=e.clientY-t.startY;Math.hypot(n,r)>p&&(t.moved=!0),this._zoom>c&&(this._pan=this._clampedPan({x:t.pan.x+n,y:t.pan.y+r}),this._view.stage.classList.add(`is-dragging`),this._applyTransform())}}}_onPointerEnd(e,t){let n=this._gesture;if(this._pointers.delete(e.pointerId),this._ui?.stage.classList.remove(`is-dragging`),!n)return;if(n.kind===`pinch`){this._pointers.size<2&&(this._gesture=null);return}if(this._gesture=null,!t)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;n.moved?this._zoom===c&&this.step(v(r,i)):e.timeStamp-n.startTime>m||(n.onImage?e.timeStamp-this._lastTap<h?(this._lastTap=-1/0,this._setZoom(this._zoom>c?c:d)):this._lastTap=e.timeStamp:this.close())}};export{C as t};
@@ -1 +1 @@
1
- import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t,r as n,t as r}from"./fieldState-D-zQcXUS.js";import{f as i}from"./formatters-Dy4kQQ_h.js";import{t as a}from"./imeSafeEnter-DPs9qL3S.js";import{n as o}from"./listboxKeyNav-CF7tMDGG.js";import{i as s,n as c,r as l,t as u}from"./mentionText-BJsw_opZ.js";import{a as d,l as f,s as p}from"./nativeOverlay-C1Rw2gIW.js";import{l as m}from"./wuiHttp-DGbD7Fra.js";import{n as h,r as g,t as _}from"./textStore-opIEM4lu.js";import{t as v}from"./mentionInput.g-DJo6d2Gm.js";var y=8,b=40,x=()=>g(`mentionInput`,v),S=`[data-wui-control]`,C=`[data-wui-field]`,w=`[data-wui-menu]`,T=`[data-wui-live]`,E=0,D=e=>!!(e&&u.test(String(e.value??``))&&c(e.label)!==``);function O(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`wui-input-sm`,n===`sm`),t.classList.toggle(`wui-input-lg`,n===`lg`),t.classList.toggle(`wui-input-xl`,n===`xl`)}function k(e,n){n.readOnly=t(e)||e.hasAttribute(`loading`)}function A(e){let t=e.ownerDocument;e.id||=`wui-mention-${++E}`;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`),k(e,n),O(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`)??x().listNameLabel),o.setAttribute(`data-wui-menu`,``),o.setAttribute(`popover`,`manual`),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 j=class extends e{_wired;_pendingValue;_text;_mentions;_peopleProp;_declared;_loading;_searchFailed;_query;_results;_active;_timer;_searchSeq;_lastSearch;_abort;_onMenuDown;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)}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(S)||A(this);let e=this._requireControl(),t=this.querySelector(C)?.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`?(k(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(k(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?O(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return s(this._text,this._mentions)}set value(e){let t=e==null?``:String(e);this._wired?t!==this.value&&this._load(t):this._pendingValue=t}get mentions(){let e=/* @__PURE__ */ new Set,t=[];for(let n of[...this._mentions].sort((e,t)=>e.start-t.start))e.has(n.id)||(e.add(n.id),t.push({id:n.id,label:n.label}));return t}get people(){return this._peopleProp?this._peopleProp:(this._declared||=[...this.querySelectorAll(`[data-wui-people] > wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})),this._declared)}set people(e){this._peopleProp=Array.isArray(e)?e.filter(D):[],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(S)}_menu(){return this.querySelector(w)}_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}=l(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(C);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||r(this)||e.selectionStart!==e.selectionEnd)return null;let t=e.selectionStart,n=this._text,i=n.lastIndexOf(`@`,t-1);if(i<0||i>0&&!/[\s([{"'“‘]/.test(n.charAt(i-1)))return null;let a=n.slice(i+1,t);return a.length>40||/[\n@]/.test(a)||/^\s/.test(a)||/\s{2}/.test(a)||this._mentions.some(e=>i>=e.start&&i<e.end)?null:{start:i,end:t,text:a}}_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=>c(e.label).toLowerCase().includes(t));this._results=n.slice(0,8),this._renderMenu()}_answered(e){return this._lastSearch===e}_minChars(){let e=this.getAttribute(`min-chars`),t=e==null||e===``?1:Number(e);return Number.isFinite(t)&&t>=0?t:1}_debounce(){let e=this.getAttribute(`debounce`),t=e==null||e===``?250:Number(e);return Number.isFinite(t)&&t>=0?t:250}_search(e){this._lastSearch=e,clearTimeout(this._timer);let t=++this._searchSeq;this._timer=setTimeout(()=>{let n=this.getAttribute(`source`);n?this._fetchPeople(n,e,t):this.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:t}}))},this._debounce())}async _fetchPeople(e,t,n){this._abort?.abort();let r=new AbortController;this._abort=r,this.loading=!0;let i=`${e}${e.includes(`?`)?`&`:`?`}q=${encodeURIComponent(t)}`,a=await m(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!a.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let o=this.ownerDocument.createElement(`template`);o.innerHTML=a.html,this._peopleProp=[...o.content.querySelectorAll(`wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})).filter(D),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return e!==null&&p(e)}_renderMenu(){let e=this._menu(),t=this._control();if(!e||!t||!this._query)return;this._syncState();let n=this.ownerDocument;if(e.replaceChildren(),this._results.forEach((t,r)=>{let i=n.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${e.id}-${r}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(r),t.src){let e=n.createElement(`img`);e.className=`wui-mention-option-photo`,e.src=t.src,e.alt=``,i.appendChild(e)}let a=n.createElement(`span`);a.className=`wui-mention-option-text`;let o=n.createElement(`span`);if(o.className=`wui-mention-option-label`,o.textContent=c(t.label),a.appendChild(o),t.description){let e=n.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=n.createElement(`div`);t.className=`wui-mention-empty`,t.textContent=this.loading?x().searchingLabel:this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel} “${this._query.text}”`,e.appendChild(t)}f(t,e,{mode:`manual`}),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?h(x(),`foundText`,this._results.length,{count:i(this._results.length,{decimals:0})}):this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel}.`)}_syncState(){let e=this._control();e&&n(this,e)}_close(){this._query=null,this._lastSearch=void 0,clearTimeout(this._timer);let e=this._menu();if(e){let t=p(e);d(e),t&&e.replaceChildren()}this._active=-1,this._control()?.removeAttribute(`aria-activedescendant`)}_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`);o(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((a(e)||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}}a(e)&&(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=c(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(_(x().mentioned,{label: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(T);t&&(t.textContent=``,t.textContent=e)}};export{y as n,j as r,b as t};
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t,r as n,t as r}from"./fieldState-D-zQcXUS.js";import{f as i}from"./formatters-CMTSYlW9.js";import{t as a}from"./imeSafeEnter-DPs9qL3S.js";import{n as o}from"./listboxKeyNav-DtlIOryj.js";import{i as s,n as c,r as l,t as u}from"./mentionText-BJsw_opZ.js";import{a as d,l as f,s as p}from"./nativeOverlay-D3VmY8qn.js";import{l as m}from"./wuiHttp-DGbD7Fra.js";import{n as h,r as g,t as _}from"./textStore-opIEM4lu.js";import{t as v}from"./mentionInput.g-DJo6d2Gm.js";var y=8,b=40,x=()=>g(`mentionInput`,v),S=`[data-wui-control]`,C=`[data-wui-field]`,w=`[data-wui-menu]`,T=`[data-wui-live]`,E=0,D=e=>!!(e&&u.test(String(e.value??``))&&c(e.label)!==``);function O(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`wui-input-sm`,n===`sm`),t.classList.toggle(`wui-input-lg`,n===`lg`),t.classList.toggle(`wui-input-xl`,n===`xl`)}function k(e,n){n.readOnly=t(e)||e.hasAttribute(`loading`)}function A(e){let t=e.ownerDocument;e.id||=`wui-mention-${++E}`;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`),k(e,n),O(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`)??x().listNameLabel),o.setAttribute(`data-wui-menu`,``),o.setAttribute(`popover`,`manual`),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 j=class extends e{_wired;_pendingValue;_text;_mentions;_peopleProp;_declared;_loading;_searchFailed;_query;_results;_active;_timer;_searchSeq;_lastSearch;_abort;_onMenuDown;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)}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(S)||A(this);let e=this._requireControl(),t=this.querySelector(C)?.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`?(k(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(k(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?O(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return s(this._text,this._mentions)}set value(e){let t=e==null?``:String(e);this._wired?t!==this.value&&this._load(t):this._pendingValue=t}get mentions(){let e=/* @__PURE__ */ new Set,t=[];for(let n of[...this._mentions].sort((e,t)=>e.start-t.start))e.has(n.id)||(e.add(n.id),t.push({id:n.id,label:n.label}));return t}get people(){return this._peopleProp?this._peopleProp:(this._declared||=[...this.querySelectorAll(`[data-wui-people] > wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})),this._declared)}set people(e){this._peopleProp=Array.isArray(e)?e.filter(D):[],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(S)}_menu(){return this.querySelector(w)}_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}=l(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(C);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||r(this)||e.selectionStart!==e.selectionEnd)return null;let t=e.selectionStart,n=this._text,i=n.lastIndexOf(`@`,t-1);if(i<0||i>0&&!/[\s([{"'“‘]/.test(n.charAt(i-1)))return null;let a=n.slice(i+1,t);return a.length>40||/[\n@]/.test(a)||/^\s/.test(a)||/\s{2}/.test(a)||this._mentions.some(e=>i>=e.start&&i<e.end)?null:{start:i,end:t,text:a}}_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=>c(e.label).toLowerCase().includes(t));this._results=n.slice(0,8),this._renderMenu()}_answered(e){return this._lastSearch===e}_minChars(){let e=this.getAttribute(`min-chars`),t=e==null||e===``?1:Number(e);return Number.isFinite(t)&&t>=0?t:1}_debounce(){let e=this.getAttribute(`debounce`),t=e==null||e===``?250:Number(e);return Number.isFinite(t)&&t>=0?t:250}_search(e){this._lastSearch=e,clearTimeout(this._timer);let t=++this._searchSeq;this._timer=setTimeout(()=>{let n=this.getAttribute(`source`);n?this._fetchPeople(n,e,t):this.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:t}}))},this._debounce())}async _fetchPeople(e,t,n){this._abort?.abort();let r=new AbortController;this._abort=r,this.loading=!0;let i=`${e}${e.includes(`?`)?`&`:`?`}q=${encodeURIComponent(t)}`,a=await m(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!a.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let o=this.ownerDocument.createElement(`template`);o.innerHTML=a.html,this._peopleProp=[...o.content.querySelectorAll(`wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})).filter(D),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return e!==null&&p(e)}_renderMenu(){let e=this._menu(),t=this._control();if(!e||!t||!this._query)return;this._syncState();let n=this.ownerDocument;if(e.replaceChildren(),this._results.forEach((t,r)=>{let i=n.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${e.id}-${r}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(r),t.src){let e=n.createElement(`img`);e.className=`wui-mention-option-photo`,e.src=t.src,e.alt=``,i.appendChild(e)}let a=n.createElement(`span`);a.className=`wui-mention-option-text`;let o=n.createElement(`span`);if(o.className=`wui-mention-option-label`,o.textContent=c(t.label),a.appendChild(o),t.description){let e=n.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=n.createElement(`div`);t.className=`wui-mention-empty`,t.textContent=this.loading?x().searchingLabel:this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel} “${this._query.text}”`,e.appendChild(t)}f(t,e,{mode:`manual`}),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?h(x(),`foundText`,this._results.length,{count:i(this._results.length,{decimals:0})}):this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel}.`)}_syncState(){let e=this._control();e&&n(this,e)}_close(){this._query=null,this._lastSearch=void 0,clearTimeout(this._timer);let e=this._menu();if(e){let t=p(e);d(e),t&&e.replaceChildren()}this._active=-1,this._control()?.removeAttribute(`aria-activedescendant`)}_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`);o(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((a(e)||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}}a(e)&&(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=c(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(_(x().mentioned,{label: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(T);t&&(t.textContent=``,t.textContent=e)}};export{y as n,j as r,b as t};