@webority/ui-elements 0.174.1 → 0.175.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/{WuiCodeBlock-BJ14DaLH.js → WuiCodeBlock-BWYZ1S70.js} +1 -1
  2. package/dist/{WuiCommentThread-ChTsQWet.js → WuiCommentThread-C5n933uz.js} +1 -1
  3. package/dist/WuiContextMenu-DEWYYFRG.js +1 -0
  4. package/dist/{WuiDataTable-3Vd8EAMV.js → WuiDataTable-Ble3hl5L.js} +1 -1
  5. package/dist/{WuiDatePicker-CPr0Yni3.js → WuiDatePicker-3D33rzH4.js} +1 -1
  6. package/dist/{WuiDateRange-DvuE4wfG.js → WuiDateRange-qTncGobM.js} +1 -1
  7. package/dist/{WuiDropdown-5-6E5Q9d.js → WuiDropdown-6g074v1T.js} +1 -1
  8. package/dist/{WuiGantt-DJat5idS.js → WuiGantt-BqNhYIr6.js} +1 -1
  9. package/dist/{WuiInlineEdit-Bfe_m5px.js → WuiInlineEdit-BwB-w61N.js} +1 -1
  10. package/dist/{WuiLightbox-CuzbFBck.js → WuiLightbox-DpHJAMO3.js} +1 -1
  11. package/dist/{WuiMentionInput-Dmtm3N62.js → WuiMentionInput-DJv-WwW6.js} +1 -1
  12. package/dist/{WuiOrgTree-DYMNCGTh.js → WuiOrgTree-DWSk_LHd.js} +1 -1
  13. package/dist/{WuiPhone-BEyz-J2q.js → WuiPhone-CBge7oVA.js} +1 -1
  14. package/dist/WuiSelect-D89S-POU.js +1 -0
  15. package/dist/{WuiTimePicker-Bcc1PfCT.js → WuiTimePicker-DYLFaWDc.js} +1 -1
  16. package/dist/{WuiTour-C71Wmed-.js → WuiTour-BU00-6Lf.js} +1 -1
  17. package/dist/{WuiTree-BQk23SSF.js → WuiTree-CIOM1G59.js} +1 -1
  18. package/dist/WuiTreePicker-DLddmEgG.js +1 -0
  19. package/dist/{WuiWizardStep-Uag__kTu.js → WuiWizardStep-gFtuUzsL.js} +1 -1
  20. package/dist/{chips-BaB5xZXq.js → chips-_rw5Aev4.js} +1 -1
  21. package/dist/copyText-sHWcpcPm.js +1 -0
  22. package/dist/{drawerDiscard-DGmosZR2.js → drawerDiscard-D_n8guAp.js} +1 -1
  23. package/dist/elements/code-block.js +1 -1
  24. package/dist/elements/comment-thread.js +1 -1
  25. package/dist/elements/context-menu.js +1 -1
  26. package/dist/elements/data-table.js +1 -1
  27. package/dist/elements/date-range.js +1 -1
  28. package/dist/elements/datepicker.js +1 -1
  29. package/dist/elements/dropdown.js +1 -1
  30. package/dist/elements/gantt.js +1 -1
  31. package/dist/elements/inline-edit.js +1 -1
  32. package/dist/elements/lightbox.js +1 -1
  33. package/dist/elements/mention-input.js +1 -1
  34. package/dist/elements/org-tree.js +1 -1
  35. package/dist/elements/phone.js +1 -1
  36. package/dist/elements/select.js +1 -1
  37. package/dist/elements/timepicker.js +1 -1
  38. package/dist/elements/tour.js +1 -1
  39. package/dist/elements/tree-picker.js +1 -1
  40. package/dist/elements/tree.js +1 -1
  41. package/dist/elements/wizard.js +1 -1
  42. package/dist/{fileViewer.g-DupSpQYS.js → fileViewer.g-D_zLw_p-.js} +1 -1
  43. package/dist/{fileViewerImage-CCtdOYm3.js → fileViewerImage-DnzDd-rQ.js} +1 -1
  44. package/dist/{fileViewerMedia-Dbwn694I.js → fileViewerMedia-Dm99qAjY.js} +1 -1
  45. package/dist/{fileViewerPdf-Lu6vcnYW.js → fileViewerPdf-Tb26qdtM.js} +3 -3
  46. package/dist/helpers.js +1 -1
  47. package/dist/{iconGlyphs.g-Dj8sa1HF.js → iconGlyphs.g-a9FtjPXh.js} +1 -1
  48. package/dist/imeSafeEnter-DeO_3lXy.js +1 -0
  49. package/dist/{listboxKeyNav-DtlIOryj.js → listboxKeyNav-DNtuh6Ob.js} +1 -1
  50. package/dist/{menuKeyNav-CstMzU08.js → menuKeyNav-BCHtqitp.js} +1 -1
  51. package/dist/{optionLabel-CghX6DYo.js → optionLabel-wbpl8OTJ.js} +1 -1
  52. package/dist/{search-Cj1eEPIN.js → search-D-lfoHy9.js} +1 -1
  53. package/dist/server.js +1 -1
  54. package/dist/{themeTransition-CRnGw929.js → themeTransition-DBv2olsl.js} +1 -1
  55. package/dist/ui-calendar.global.js +1 -1
  56. package/dist/ui-calendar.js +1 -1
  57. package/dist/ui-chart.global.js +1 -1
  58. package/dist/ui-chart.js +1 -1
  59. package/dist/ui-consent-banner.global.js +1 -1
  60. package/dist/ui-elements/carousel.global.js +1 -1
  61. package/dist/ui-elements/code-block.global.js +1 -1
  62. package/dist/ui-elements/command-palette.global.js +2 -2
  63. package/dist/ui-elements/comment-thread.global.js +1 -1
  64. package/dist/ui-elements/consent-banner.global.js +1 -1
  65. package/dist/ui-elements/context-menu.global.js +1 -1
  66. package/dist/ui-elements/date-range.global.js +1 -1
  67. package/dist/ui-elements/date-time.global.js +1 -1
  68. package/dist/ui-elements/datepicker.global.js +1 -1
  69. package/dist/ui-elements/drawer.global.js +1 -1
  70. package/dist/ui-elements/dropdown.global.js +1 -1
  71. package/dist/ui-elements/entry-grid.global.js +2 -2
  72. package/dist/ui-elements/gantt.global.js +1 -1
  73. package/dist/ui-elements/glyphs.global.js +1 -1
  74. package/dist/ui-elements/image-crop.global.js +1 -1
  75. package/dist/ui-elements/inline-edit.global.js +1 -1
  76. package/dist/ui-elements/kanban.global.js +1 -1
  77. package/dist/ui-elements/lead-popup.global.js +2 -2
  78. package/dist/ui-elements/lightbox.global.js +1 -1
  79. package/dist/ui-elements/markdown.global.js +3 -3
  80. package/dist/ui-elements/org-tree.global.js +1 -1
  81. package/dist/ui-elements/phone.global.js +1 -1
  82. package/dist/ui-elements/popover.global.js +1 -1
  83. package/dist/ui-elements/saved-views.global.js +1 -1
  84. package/dist/ui-elements/select-chips.global.js +1 -1
  85. package/dist/ui-elements/select-recents.global.js +1 -1
  86. package/dist/ui-elements/select-search.global.js +1 -1
  87. package/dist/ui-elements/select-window.global.js +1 -1
  88. package/dist/ui-elements/slider.global.js +1 -1
  89. package/dist/ui-elements/sortable.global.js +1 -1
  90. package/dist/ui-elements/status-icon.global.js +1 -1
  91. package/dist/ui-elements/table-export.global.js +1 -1
  92. package/dist/ui-elements/timepicker.global.js +1 -1
  93. package/dist/ui-elements/tour.global.js +1 -1
  94. package/dist/ui-elements/tree-picker.global.js +1 -1
  95. package/dist/ui-elements/tree.global.js +1 -1
  96. package/dist/ui-elements/wizard.global.js +1 -1
  97. package/dist/ui-elements.global.js +1 -1
  98. package/dist/ui-elements.js +1 -1
  99. package/dist/ui-file-viewer.global.js +4 -4
  100. package/dist/ui-file-viewer.js +1 -1
  101. package/dist/ui-lead-popup.global.js +1 -1
  102. package/dist/ui-rich-text.global.js +53 -53
  103. package/dist/ui-rich-text.js +51 -51
  104. package/dist/ui-tour.global.js +1 -1
  105. package/package.json +5 -5
  106. package/types/codeHighlight.d.ts +2 -1
  107. package/types/copyText.d.ts +2 -3
  108. package/types/global/shared.d.ts +47 -46
  109. package/types/imeSafeEnter.d.ts +7 -0
  110. package/types/razor-js/modules/api.d.ts +8 -5
  111. package/types/razor-js/modules/look.d.ts +4 -5
  112. package/types/razor-js/modules/pageListeners.d.ts +1 -1
  113. package/types/razor-js/webority-ui.d.ts +14 -38
  114. package/dist/WuiContextMenu-T-pkqJdV.js +0 -1
  115. package/dist/WuiSelect-C_nfrNr5.js +0 -1
  116. package/dist/WuiTreePicker-DP1lCno3.js +0 -1
  117. package/dist/copyText-Q-QZKBmx.js +0 -1
  118. package/dist/imeSafeEnter-DPs9qL3S.js +0 -1
@@ -1 +1 @@
1
- import{n as e,t}from"./buttonClass-C8BRtTk8.js";import{t as n}from"./hasOwn-CJsplJ62.js";import{n as r,t as i}from"./copyText-Q-QZKBmx.js";import{t as a}from"./elementBase-Cxeyx0tU.js";import{t as o}from"./iconGlyphs.g-Dj8sa1HF.js";import{r as s}from"./textStore-DBplASiZ.js";import{t as c}from"./codeBlock.g-BCF2IlK-.js";Object.freeze([`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`razor`,`css`]);var l=Object.freeze({text:``,json:`JSON`,js:`JavaScript`,cs:`C#`,sql:`SQL`,bash:`Bash`,http:`HTTP`,html:`HTML`,razor:`Razor`,css:`CSS`}),u=e=>RegExp(`\\b(?:${e.join(`|`)})\\b`),d=`(?![\\s\\S])`,f=RegExp(`/\\*[\\s\\S]*?(?:\\*/|${d})`).source,p=[[`attr`,/"(?:[^"\\\n]|\\.)*"(?=\s*:)/],[`string`,/"(?:[^"\\\n]|\\.)*"?/],[`number`,/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/],[`literal`,u([`true`,`false`,`null`])],[`punct`,/[{}[\],:]/]],m=[[`comment`,RegExp(`//[^\\n]*|${f}`)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?/],[`number`,/\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?n?)\b/],[`keyword`,u(/* @__PURE__ */ `async.await.break.case.catch.class.const.continue.default.delete.do.else.export.extends.finally.for.from.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.yield`.split(`.`))],[`literal`,u([`true`,`false`,`null`,`undefined`,`NaN`,`Infinity`])],[`function`,/(?<![\w$])[A-Za-z_$][\w$]*(?=\s*\()/],[`type`,/(?<![\w$])[A-Z][\w$]*/],[`punct`,/[{}()[\];,]/]],h=[[`comment`,RegExp(`//[^\\n]*|${f}`)],[`string`,/@"(?:[^"]|"")*"?|\$@?"(?:[^"\\\n]|\\.)*"?|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`number`,/\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?[fFdDmMlLuU]{0,2}\b/],[`keyword`,u(/* @__PURE__ */ `abstract.as.async.await.base.bool.break.byte.case.catch.char.checked.class.const.continue.decimal.default.delegate.do.double.else.enum.event.explicit.extern.finally.fixed.float.for.foreach.get.goto.if.implicit.in.init.int.interface.internal.is.lock.long.namespace.new.object.operator.out.override.params.private.protected.public.readonly.record.ref.required.return.sbyte.sealed.set.short.sizeof.static.string.struct.switch.this.throw.try.typeof.uint.ulong.unchecked.unsafe.ushort.using.var.virtual.void.volatile.when.while.with`.split(`.`))],[`literal`,u([`true`,`false`,`null`])],[`function`,/(?<!\w)[A-Za-z_]\w*(?=\s*\()/],[`type`,/(?<!\w)[A-Z]\w*/],[`punct`,/[{}()[\];,]/]],g=[[`comment`,RegExp(`--[^\\n]*|${f}`)],[`string`,/'(?:[^']|'')*'?/],[`variable`,/@@?\w+/],[`number`,/\b\d+(?:\.\d+)?\b/],[`keyword`,u(/* @__PURE__ */ `add.all.alter.and.as.asc.begin.between.by.case.check.column.commit.constraint.create.cross.database.declare.default.delete.desc.distinct.drop.else.end.exec.execute.exists.foreign.from.full.function.group.having.if.in.index.inner.insert.into.is.join.key.left.like.limit.not.null.offset.on.or.order.outer.over.partition.primary.procedure.references.return.returns.right.rollback.select.set.table.then.top.transaction.union.unique.update.values.view.when.where.while.with`.split(`.`))],[`literal`,u([`true`,`false`])],[`type`,u([`bigint`,`bit`,`char`,`date`,`datetime`,`datetime2`,`decimal`,`float`,`int`,`money`,`nchar`,`numeric`,`nvarchar`,`real`,`smallint`,`text`,`time`,`tinyint`,`uniqueidentifier`,`varchar`])],[`function`,/\b[A-Za-z_]\w*(?=\s*\()/],[`punct`,/[(),;]/]],_=[[`comment`,/(?<![^\s;|&(])#[^\n]*/],[`string`,/"(?:[^"\\]|\\[\s\S])*"?|'[^']*'?/],[`variable`,/\$(?:\{[^}\n]*\}?|[A-Za-z_]\w*|[0-9@#?$!*-])/],[`attr`,/(?<![\w-])--?[A-Za-z][\w-]*/],[`number`,/(?<![\w.-])\d+(?:\.\d+)?\b/],[`keyword`,u([`case`,`do`,`done`,`elif`,`else`,`esac`,`exit`,`export`,`fi`,`for`,`function`,`if`,`in`,`local`,`return`,`select`,`then`,`until`,`while`])],[`function`,u(/* @__PURE__ */ `awk.az.cat.cd.chmod.chown.cp.curl.docker.dotnet.echo.gcloud.git.grep.kubectl.ls.mkdir.mv.npm.npx.pnpm.rm.sed.source.sudo.wget`.split(`.`))],[`punct`,/[|&;<>(){}[\]]+/]],v=[[`comment`,/^#[^\n]*/m],[`keyword`,/^(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(?= )/m],[`literal`,/HTTP\/\d(?:\.\d)?/],[`number`,/(?<=^HTTP\/\d(?:\.\d)? )\d{3}\b/m],[`function`,/(?<=^[A-Z]+ )\S+/m],[`attr`,/^[A-Za-z][\w-]*(?=:)/m],[`string`,/(?<=^[A-Za-z][\w-]*:[ \t]*)[^\n]+/m]],y=[[`comment`,RegExp(`<!--[\\s\\S]*?(?:-->|${d})`)],[`keyword`,/<![A-Za-z][^>]*>?/],[`tag`,/<\/?[A-Za-z][^<>]*>?/],[`literal`,/&#?\w+;/]],b={json:p,js:m,cs:h,sql:g,bash:_,http:v,css:[[`comment`,new RegExp(f)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`keyword`,/@[\w-]+|!important/],[`attr`,/[\w-]+(?=\s*:[^{};]*[;}])/],[`number`,/#[0-9a-fA-F]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:%|[A-Za-z]{1,4})?/],[`function`,/[\w-]+(?=\()/],[`type`,/[.#](?!\d)[A-Za-z_][\w-]*/],[`punct`,/[{}();:,]/]],html:y,htmlTag:[[`tag`,/^<\/?[\w:.-]+/],[`string`,/"[^"]*"?|'[^']*'?/],[`attr`,/(?<=\s)[^\s=<>/"']+/],[`punct`,/\/?>|=/]]},x=e=>n(b,e),S=/* @__PURE__ */ new Map;function C(e){let t=S.get(e);if(!t){let n=b[e],r=e===`sql`?`gi`:`g`,i=n.map(([,e])=>`(${e.source})`).join(`|`);t={re:new RegExp(i,`${r}m`),types:n.map(([e])=>e)},S.set(e,t)}return t}function w(e,t,n){if(!n)return;let r=e[e.length-1];r&&r[0]===t?r[1]+=n:e.push([t,n])}function T(e,t,n=[]){let{re:r,types:i}=C(e),a=0;for(let o of t.matchAll(r)){let r=o[0];if(!r)continue;w(n,`plain`,t.slice(a,o.index));let s=i.findIndex((e,t)=>o[t+1]!==void 0);e===`html`&&i[s]===`tag`?T(`htmlTag`,r,n):w(n,i[s]??`plain`,r),a=o.index+r.length}return w(n,`plain`,t.slice(a)),n}function E(e){let t=/\r?\n\r?\n/.exec(e);if(!t)return T(`http`,e);let n=t[0]??``,r=T(`http`,e.slice(0,t.index+n.length)),i=e.slice(t.index+n.length),a=i.trimStart()[0];return a===`{`||a===`[`?T(`json`,i,r):a===`<`?T(`html`,i,r):(w(r,`plain`,i),r)}function D(e,t){let n=String(e??``);if(!n||n.length>1e5)return n?[[`plain`,n]]:[];if(t===`http`)return E(n);let r=t===`razor`?`html`:t;return!x(r)||r===`htmlTag`?[[`plain`,n]]:T(r,n)}function O(e,t){let n=[],r=[n];for(let[i,a]of D(e,t))a.split(/\r\n|\r|\n/).forEach((e,t)=>{t>0&&(n=[],r.push(n)),e&&n.push([i,e])});return r.length>1&&n.length===0&&r.pop(),r}var k=()=>s(`codeBlock`,c);function A(e){return n(l,e)}var j=class extends a{_title;_view;_codeEl;_copyIcon;_copyText;_chrome=null;_copied=!1;_observer=null;_timer=0;_cancelFrame=null;constructor(){super();let e=this.ownerDocument;this._title=e.createElement(`span`),this._title.className=`wui-code-title`,this._view=e.createElement(`div`),this._codeEl=e.createElement(`code`),this._copyIcon=e.createElement(`span`),this._copyIcon.className=`wui-code-copy-icon`,this._copyText=e.createElement(`span`)}static get observedAttributes(){return[`language`,`line-numbers`,`wrap`,`label`,`copy-label`,`copied-label`]}connectedCallback(){this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._chrome?.contains(e.target))&&this._schedule()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._cancelPending()}attributeChangedCallback(){this.isConnected&&this._render()}_source(){return Array.from(this.children).find(e=>e.classList.contains(`wui-code-source`))}_code(){return(this._source()?.textContent??``).replace(/\r?\n$/,``)}_schedule(){if(this._cancelFrame)return;let e=()=>{this._cancelFrame=null,this._render()};if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(e);this._cancelFrame=()=>cancelAnimationFrame(t)}else{let t=!0;queueMicrotask(()=>{t&&e()}),this._cancelFrame=()=>{t=!1}}}_cancelPending(){this._cancelFrame?.(),this._cancelFrame=null}_render(){if(!this._source())return;this._cancelPending();let e=this.ownerDocument;this._chrome||this._build(e);let t=this.getAttribute(`language`),n=t!==null&&A(t)?t:`text`,r=this.getAttribute(`label`)||``,i=O(this._code(),n);this._title.textContent=r||l[n],this._view.setAttribute(`aria-label`,r||k().label),this._view.style.setProperty(`--wui-code-digits`,String(String(i.length).length)),this._codeEl.replaceChildren(...i.map(t=>M(e,t))),this._copied||(this._copyText.textContent=this._copyLabel()),this.setAttribute(`data-wui-ready`,``),this._observer?.takeRecords()}_build(e){let t=e.createElement(`div`);t.className=`wui-code-chrome`,t.append(this._bar(e));let n=this._view;n.className=`wui-code-view`,n.setAttribute(`role`,`region`),n.tabIndex=0;let r=e.createElement(`pre`);r.className=`wui-code-pre`,r.append(this._codeEl),n.append(r),t.append(n),this._chrome=t,this.append(t)}_bar(n){let a=n.createElement(`div`);a.className=`wui-code-bar`;let o=n.createElement(`button`);return o.type=`button`,o.className=`${e(`primary`,`ghost`,`sm`)} wui-code-copy`,o.dataset.wui=t,o.setAttribute(`aria-live`,`polite`),this._setCopied(!1),o.append(this._copyIcon,this._copyText),o.addEventListener(`click`,async()=>{await r(this._code())&&(this._setCopied(!0),clearTimeout(this._timer),this._timer=window.setTimeout(()=>this._setCopied(!1),i))}),a.append(this._title,o),a}_setCopied(e){this._copied=e;let t=o(e?`check`:`files`,{size:14});this._copyIcon.replaceChildren(...t?[t]:[]),this._copyText.textContent=this._copyLabel()}_copyLabel(){return this._copied?this.getAttribute(`copied-label`)||k().copiedLabel:this.getAttribute(`copy-label`)||k().copyLabel}};function M(e,t){let n=e.createElement(`span`);n.className=`wui-code-line`;for(let[r,i]of t){if(r===`plain`){n.append(i);continue}let t=e.createElement(`span`);t.className=`wui-code-t-${r}`,t.textContent=i,n.append(t)}return n}export{j as t};
1
+ import{n as e,t}from"./buttonClass-C8BRtTk8.js";import{t as n}from"./hasOwn-CJsplJ62.js";import{n as r,t as i}from"./copyText-sHWcpcPm.js";import{t as a}from"./elementBase-Cxeyx0tU.js";import{t as o}from"./iconGlyphs.g-a9FtjPXh.js";import{r as s}from"./textStore-DBplASiZ.js";import{t as c}from"./codeBlock.g-BCF2IlK-.js";Object.freeze([`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`razor`,`css`]);var l=Object.freeze({text:``,json:`JSON`,js:`JavaScript`,cs:`C#`,sql:`SQL`,bash:`Bash`,http:`HTTP`,html:`HTML`,razor:`Razor`,css:`CSS`}),u=e=>RegExp(`\\b(?:${e.join(`|`)})\\b`),d=`(?![\\s\\S])`,f=RegExp(`/\\*[\\s\\S]*?(?:\\*/|${d})`).source,p=[[`attr`,/"(?:[^"\\\n]|\\.)*"(?=\s*:)/],[`string`,/"(?:[^"\\\n]|\\.)*"?/],[`number`,/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/],[`literal`,u([`true`,`false`,`null`])],[`punct`,/[{}[\],:]/]],m=[[`comment`,RegExp(`//[^\\n]*|${f}`)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?/],[`number`,/\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?n?)\b/],[`keyword`,u(/* @__PURE__ */ `async.await.break.case.catch.class.const.continue.default.delete.do.else.export.extends.finally.for.from.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.yield`.split(`.`))],[`literal`,u([`true`,`false`,`null`,`undefined`,`NaN`,`Infinity`])],[`function`,/(?<![\w$])[A-Za-z_$][\w$]*(?=\s*\()/],[`type`,/(?<![\w$])[A-Z][\w$]*/],[`punct`,/[{}()[\];,]/]],h=[[`comment`,RegExp(`//[^\\n]*|${f}`)],[`string`,/@"(?:[^"]|"")*"?|\$@?"(?:[^"\\\n]|\\.)*"?|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`number`,/\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?[fFdDmMlLuU]{0,2}\b/],[`keyword`,u(/* @__PURE__ */ `abstract.as.async.await.base.bool.break.byte.case.catch.char.checked.class.const.continue.decimal.default.delegate.do.double.else.enum.event.explicit.extern.finally.fixed.float.for.foreach.get.goto.if.implicit.in.init.int.interface.internal.is.lock.long.namespace.new.object.operator.out.override.params.private.protected.public.readonly.record.ref.required.return.sbyte.sealed.set.short.sizeof.static.string.struct.switch.this.throw.try.typeof.uint.ulong.unchecked.unsafe.ushort.using.var.virtual.void.volatile.when.while.with`.split(`.`))],[`literal`,u([`true`,`false`,`null`])],[`function`,/(?<!\w)[A-Za-z_]\w*(?=\s*\()/],[`type`,/(?<!\w)[A-Z]\w*/],[`punct`,/[{}()[\];,]/]],g=[[`comment`,RegExp(`--[^\\n]*|${f}`)],[`string`,/'(?:[^']|'')*'?/],[`variable`,/@@?\w+/],[`number`,/\b\d+(?:\.\d+)?\b/],[`keyword`,u(/* @__PURE__ */ `add.all.alter.and.as.asc.begin.between.by.case.check.column.commit.constraint.create.cross.database.declare.default.delete.desc.distinct.drop.else.end.exec.execute.exists.foreign.from.full.function.group.having.if.in.index.inner.insert.into.is.join.key.left.like.limit.not.null.offset.on.or.order.outer.over.partition.primary.procedure.references.return.returns.right.rollback.select.set.table.then.top.transaction.union.unique.update.values.view.when.where.while.with`.split(`.`))],[`literal`,u([`true`,`false`])],[`type`,u([`bigint`,`bit`,`char`,`date`,`datetime`,`datetime2`,`decimal`,`float`,`int`,`money`,`nchar`,`numeric`,`nvarchar`,`real`,`smallint`,`text`,`time`,`tinyint`,`uniqueidentifier`,`varchar`])],[`function`,/\b[A-Za-z_]\w*(?=\s*\()/],[`punct`,/[(),;]/]],_=[[`comment`,/(?<![^\s;|&(])#[^\n]*/],[`string`,/"(?:[^"\\]|\\[\s\S])*"?|'[^']*'?/],[`variable`,/\$(?:\{[^}\n]*\}?|[A-Za-z_]\w*|[0-9@#?$!*-])/],[`attr`,/(?<![\w-])--?[A-Za-z][\w-]*/],[`number`,/(?<![\w.-])\d+(?:\.\d+)?\b/],[`keyword`,u([`case`,`do`,`done`,`elif`,`else`,`esac`,`exit`,`export`,`fi`,`for`,`function`,`if`,`in`,`local`,`return`,`select`,`then`,`until`,`while`])],[`function`,u(/* @__PURE__ */ `awk.az.cat.cd.chmod.chown.cp.curl.docker.dotnet.echo.gcloud.git.grep.kubectl.ls.mkdir.mv.npm.npx.pnpm.rm.sed.source.sudo.wget`.split(`.`))],[`punct`,/[|&;<>(){}[\]]+/]],v=[[`comment`,/^#[^\n]*/m],[`keyword`,/^(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(?= )/m],[`literal`,/HTTP\/\d(?:\.\d)?/],[`number`,/(?<=^HTTP\/\d(?:\.\d)? )\d{3}\b/m],[`function`,/(?<=^[A-Z]+ )\S+/m],[`attr`,/^[A-Za-z][\w-]*(?=:)/m],[`string`,/(?<=^[A-Za-z][\w-]*:[ \t]*)[^\n]+/m]],y=[[`comment`,RegExp(`<!--[\\s\\S]*?(?:-->|${d})`)],[`keyword`,/<![A-Za-z][^>]*>?/],[`tag`,/<\/?[A-Za-z][^<>]*>?/],[`literal`,/&#?\w+;/]],b={json:p,js:m,cs:h,sql:g,bash:_,http:v,css:[[`comment`,new RegExp(f)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`keyword`,/@[\w-]+|!important/],[`attr`,/[\w-]+(?=\s*:[^{};]*[;}])/],[`number`,/#[0-9a-fA-F]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:%|[A-Za-z]{1,4})?/],[`function`,/[\w-]+(?=\()/],[`type`,/[.#](?!\d)[A-Za-z_][\w-]*/],[`punct`,/[{}();:,]/]],html:y,htmlTag:[[`tag`,/^<\/?[\w:.-]+/],[`string`,/"[^"]*"?|'[^']*'?/],[`attr`,/(?<=\s)[^\s=<>/"']+/],[`punct`,/\/?>|=/]]},x=e=>n(b,e),S=/* @__PURE__ */ new Map;function C(e){let t=S.get(e);if(!t){let n=b[e],r=e===`sql`?`gi`:`g`,i=n.map(([,e])=>`(${e.source})`).join(`|`);t={re:new RegExp(i,`${r}m`),types:n.map(([e])=>e)},S.set(e,t)}return t}function w(e,t,n){if(!n)return;let r=e[e.length-1];r&&r[0]===t?r[1]+=n:e.push([t,n])}function T(e,t,n=[]){let{re:r,types:i}=C(e),a=0;for(let o of t.matchAll(r)){let r=o[0];if(!r)continue;w(n,`plain`,t.slice(a,o.index));let s=i.findIndex((e,t)=>o[t+1]!==void 0);e===`html`&&i[s]===`tag`?T(`htmlTag`,r,n):w(n,i[s]??`plain`,r),a=o.index+r.length}return w(n,`plain`,t.slice(a)),n}function E(e){let t=/\r?\n\r?\n/.exec(e);if(!t)return T(`http`,e);let n=t[0]??``,r=T(`http`,e.slice(0,t.index+n.length)),i=e.slice(t.index+n.length),a=i.trimStart()[0];return a===`{`||a===`[`?T(`json`,i,r):a===`<`?T(`html`,i,r):(w(r,`plain`,i),r)}function D(e,t){let n=String(e??``);if(!n||n.length>1e5)return n?[[`plain`,n]]:[];if(t===`http`)return E(n);let r=t===`razor`?`html`:t;return!x(r)||r===`htmlTag`?[[`plain`,n]]:T(r,n)}function O(e,t){let n=[],r=[n];for(let[i,a]of D(e,t))a.split(/\r\n|\r|\n/).forEach((e,t)=>{t>0&&(n=[],r.push(n)),e&&n.push([i,e])});return r.length>1&&n.length===0&&r.pop(),r}var k=()=>s(`codeBlock`,c);function A(e){return n(l,e)}var j=class extends a{_title;_view;_codeEl;_copyIcon;_copyText;_chrome=null;_copied=!1;_observer=null;_timer=0;_cancelFrame=null;constructor(){super();let e=this.ownerDocument;this._title=e.createElement(`span`),this._title.className=`wui-code-title`,this._view=e.createElement(`div`),this._codeEl=e.createElement(`code`),this._copyIcon=e.createElement(`span`),this._copyIcon.className=`wui-code-copy-icon`,this._copyText=e.createElement(`span`)}static get observedAttributes(){return[`language`,`line-numbers`,`wrap`,`label`,`copy-label`,`copied-label`]}connectedCallback(){this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._chrome?.contains(e.target))&&this._schedule()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._cancelPending()}attributeChangedCallback(){this.isConnected&&this._render()}_source(){return Array.from(this.children).find(e=>e.classList.contains(`wui-code-source`))}_code(){return(this._source()?.textContent??``).replace(/\r?\n$/,``)}_schedule(){if(this._cancelFrame)return;let e=()=>{this._cancelFrame=null,this._render()};if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(e);this._cancelFrame=()=>cancelAnimationFrame(t)}else{let t=!0;queueMicrotask(()=>{t&&e()}),this._cancelFrame=()=>{t=!1}}}_cancelPending(){this._cancelFrame?.(),this._cancelFrame=null}_render(){if(!this._source())return;this._cancelPending();let e=this.ownerDocument;this._chrome||this._build(e);let t=this.getAttribute(`language`),n=t!==null&&A(t)?t:`text`,r=this.getAttribute(`label`)||``,i=O(this._code(),n);this._title.textContent=r||l[n],this._view.setAttribute(`aria-label`,r||k().label),this._view.style.setProperty(`--wui-code-digits`,String(String(i.length).length)),this._codeEl.replaceChildren(...i.map(t=>M(e,t))),this._copied||(this._copyText.textContent=this._copyLabel()),this.setAttribute(`data-wui-ready`,``),this._observer?.takeRecords()}_build(e){let t=e.createElement(`div`);t.className=`wui-code-chrome`,t.append(this._bar(e));let n=this._view;n.className=`wui-code-view`,n.setAttribute(`role`,`region`),n.tabIndex=0;let r=e.createElement(`pre`);r.className=`wui-code-pre`,r.append(this._codeEl),n.append(r),t.append(n),this._chrome=t,this.append(t)}_bar(n){let a=n.createElement(`div`);a.className=`wui-code-bar`;let o=n.createElement(`button`);return o.type=`button`,o.className=`${e(`primary`,`ghost`,`sm`)} wui-code-copy`,o.dataset.wui=t,o.setAttribute(`aria-live`,`polite`),this._setCopied(!1),o.append(this._copyIcon,this._copyText),o.addEventListener(`click`,async()=>{await r(this._code())&&(this._setCopied(!0),clearTimeout(this._timer),this._timer=window.setTimeout(()=>this._setCopied(!1),i))}),a.append(this._title,o),a}_setCopied(e){this._copied=e;let t=o(e?`check`:`files`,{size:14});this._copyIcon.replaceChildren(...t?[t]:[]),this._copyText.textContent=this._copyLabel()}_copyLabel(){return this._copied?this.getAttribute(`copied-label`)||k().copiedLabel:this.getAttribute(`copy-label`)||k().copyLabel}};function M(e,t){let n=e.createElement(`span`);n.className=`wui-code-line`;for(let[r,i]of t){if(r===`plain`){n.append(i);continue}let t=e.createElement(`span`);t.className=`wui-code-t-${r}`,t.textContent=i,n.append(t)}return n}export{j as t};
@@ -1 +1 @@
1
- import{n as e,t}from"./buttonClass-C8BRtTk8.js";import{n}from"./commentText-NWsssKvj.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{t as i}from"./hasOwn-CJsplJ62.js";import{a,l as o,s}from"./nativeOverlay-BHD2QV02.js";import{n as c,t as l}from"./rtl-g7G8Bsib.js";import{t as u}from"./serverHtml-BC6tAyAl.js";import{d}from"./wuiHttp-BWf9dDsZ.js";import{r as f,t as p}from"./textStore-DBplASiZ.js";import{n as m,t as h}from"./httpFailure.g-DBKzEpAf.js";import{r as g}from"./WuiMentionInput-Dmtm3N62.js";var _=`[data-wui-items]`,v=`[data-wui-picker]`,y=`[data-wui-composer]`,b=`[data-wui-comment]`,x=`[data-wui-live]`,S=()=>f(`commentThread`,m),C=e=>({forbidden:S().forbiddenMessage,client:S().failedClientMessage,validation:S().validationMessage,server:S().failedServerMessage,network:f(`httpFailure`,h).networkText})[e],w=e=>({post:S().donePostText,reply:S().doneReplyText,edit:S().doneEditText,delete:S().doneDeleteText,react:``})[e],T=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:S().failedServerMessage},E=e=>e instanceof Element?e:null,D=e=>`disabled`in e&&e.disabled===!0,O=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},k=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},A=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},j=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],M=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(i(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=k(this,`${y} wui-mention-input`,g);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:j(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=A(E(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!D(t)){let e=t.closest(v),n=e?this._pickerFor?.comment:t.closest(b);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=A(E(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||D(n))return;let r=n.closest(b);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=O(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(A(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=k(this,v,HTMLElement),n=E(e.target),r=c(e.key,l(this));if(this._pickerFor&&t?.contains(n)){let i=j(t,`[data-wui-emoji]`,HTMLElement),a=n instanceof HTMLElement?i.indexOf(n):-1;e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closePicker(!0)):r===`ArrowRight`||r===`ArrowLeft`?(e.preventDefault(),i[(a+(r===`ArrowRight`?1:-1)+i.length)%i.length]?.focus()):e.key===`Tab`&&this._closePicker(!1);return}if(e.key!==`Escape`)return;let i=A(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(i&&this.contains(i)){e.preventDefault(),e.stopPropagation(),this._closeSlot(i,!0);return}let a=A(n,`[data-wui-comment-confirm]`,HTMLElement);a&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(a.closest(b),!0))}_onSubmitKey(e){let t=k(A(E(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!D(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=k(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:p(S().replyToText,{author:r}),placeholder:S().replyPlaceholder,value:``,send:S().replyLabel,opener:t})}_openEditor(e,t){let n=k(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=k(O(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:S().editCommentLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:S().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`,S().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=k(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=k(e,`:scope > .wui-comment-row`,HTMLElement),n=k(t,`[data-wui-comment-confirm]`,HTMLElement),r=k(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),k(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=k(e,`:scope > .wui-comment-row`,HTMLElement),r=k(n,`[data-wui-comment-confirm]`,HTMLElement),i=k(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&k(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let n=k(this,v,HTMLElement);n&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),o(t,n,{mode:`auto`,onClosed:()=>this._pickerClosed()}),k(n,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;let n=k(this,v,HTMLElement);n&&a(n),this._pickerClosed(),e&&t.button.isConnected&&t.button.focus()}_pickerClosed(){let e=k(this,v,HTMLElement),t=this._pickerFor;!t||e&&s(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=A(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,S().emptyBodyMessage),n?.focus();return}let i=t.closest(b);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:O(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:O(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??k(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),w(e)&&this._announce(w(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:T(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:S().failedClientMessage};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await d(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||C(r.kind)||S().failedServerMessage}}_swapItems(e){let t=k(this,_,HTMLElement);if(!t||!e.trim())return;let n=u(e),r=k(n,_,HTMLElement);t.replaceChildren(...r?r.childNodes:n.childNodes)}_restoreFocus(e,t,n){let r=this.ownerDocument,i=r.activeElement;if(i&&i!==r.body&&i.isConnected&&this.contains(i)&&!D(i))return;let a=e=>e?j(this,b,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>k(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=k(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=k(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=j(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??k(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=k(this,`${y} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=k(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=k(this,`:scope > ${x}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{M as t};
1
+ import{n as e,t}from"./buttonClass-C8BRtTk8.js";import{n}from"./commentText-NWsssKvj.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{t as i}from"./hasOwn-CJsplJ62.js";import{a,l as o,s}from"./nativeOverlay-BHD2QV02.js";import{n as c,t as l}from"./rtl-g7G8Bsib.js";import{t as u}from"./serverHtml-BC6tAyAl.js";import{d}from"./wuiHttp-BWf9dDsZ.js";import{r as f,t as p}from"./textStore-DBplASiZ.js";import{n as m,t as h}from"./httpFailure.g-DBKzEpAf.js";import{r as g}from"./WuiMentionInput-DJv-WwW6.js";var _=`[data-wui-items]`,v=`[data-wui-picker]`,y=`[data-wui-composer]`,b=`[data-wui-comment]`,x=`[data-wui-live]`,S=()=>f(`commentThread`,m),C=e=>({forbidden:S().forbiddenMessage,client:S().failedClientMessage,validation:S().validationMessage,server:S().failedServerMessage,network:f(`httpFailure`,h).networkText})[e],w=e=>({post:S().donePostText,reply:S().doneReplyText,edit:S().doneEditText,delete:S().doneDeleteText,react:``})[e],T=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:S().failedServerMessage},E=e=>e instanceof Element?e:null,D=e=>`disabled`in e&&e.disabled===!0,O=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},k=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},A=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},j=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],M=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(i(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=k(this,`${y} wui-mention-input`,g);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:j(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=A(E(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!D(t)){let e=t.closest(v),n=e?this._pickerFor?.comment:t.closest(b);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=A(E(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||D(n))return;let r=n.closest(b);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=O(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(A(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=k(this,v,HTMLElement),n=E(e.target),r=c(e.key,l(this));if(this._pickerFor&&t?.contains(n)){let i=j(t,`[data-wui-emoji]`,HTMLElement),a=n instanceof HTMLElement?i.indexOf(n):-1;e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closePicker(!0)):r===`ArrowRight`||r===`ArrowLeft`?(e.preventDefault(),i[(a+(r===`ArrowRight`?1:-1)+i.length)%i.length]?.focus()):e.key===`Tab`&&this._closePicker(!1);return}if(e.key!==`Escape`)return;let i=A(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(i&&this.contains(i)){e.preventDefault(),e.stopPropagation(),this._closeSlot(i,!0);return}let a=A(n,`[data-wui-comment-confirm]`,HTMLElement);a&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(a.closest(b),!0))}_onSubmitKey(e){let t=k(A(E(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!D(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=k(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:p(S().replyToText,{author:r}),placeholder:S().replyPlaceholder,value:``,send:S().replyLabel,opener:t})}_openEditor(e,t){let n=k(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=k(O(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:S().editCommentLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:S().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`,S().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=k(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=k(e,`:scope > .wui-comment-row`,HTMLElement),n=k(t,`[data-wui-comment-confirm]`,HTMLElement),r=k(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),k(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=k(e,`:scope > .wui-comment-row`,HTMLElement),r=k(n,`[data-wui-comment-confirm]`,HTMLElement),i=k(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&k(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let n=k(this,v,HTMLElement);n&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),o(t,n,{mode:`auto`,onClosed:()=>this._pickerClosed()}),k(n,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;let n=k(this,v,HTMLElement);n&&a(n),this._pickerClosed(),e&&t.button.isConnected&&t.button.focus()}_pickerClosed(){let e=k(this,v,HTMLElement),t=this._pickerFor;!t||e&&s(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=A(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,S().emptyBodyMessage),n?.focus();return}let i=t.closest(b);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:O(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:O(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??k(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),w(e)&&this._announce(w(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:T(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:S().failedClientMessage};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await d(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||C(r.kind)||S().failedServerMessage}}_swapItems(e){let t=k(this,_,HTMLElement);if(!t||!e.trim())return;let n=u(e),r=k(n,_,HTMLElement);t.replaceChildren(...r?r.childNodes:n.childNodes)}_restoreFocus(e,t,n){let r=this.ownerDocument,i=r.activeElement;if(i&&i!==r.body&&i.isConnected&&this.contains(i)&&!D(i))return;let a=e=>e?j(this,b,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>k(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=k(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=k(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=j(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??k(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=k(this,`${y} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=k(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=k(this,`:scope > ${x}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{M as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./imeSafeEnter-DeO_3lXy.js";import{t as n}from"./isDrawn-BbF4phmB.js";import{t as r}from"./menuKeyNav-BCHtqitp.js";import{a as i,l as a,s as o}from"./nativeOverlay-BHD2QV02.js";import{n as s,t as c}from"./rtl-g7G8Bsib.js";var l=`[role="menuitem"]`,u=`.wui-context-menu-sub`,d=`input.wui-context-menu-search`,f=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,p=500,m=10,h=400,g=null,_=null,v=0;function y(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 b=/* @__PURE__ */ new WeakMap;function x(e,t,n){let r=b.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return b.set(e,{region:t,cancel:n}),!0}var S=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,C=e=>`focus`in e,w=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(``),T=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),E=e=>[...e.children].filter(e=>e instanceof HTMLElement),D=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},O=e=>D(e,0),k=e=>D(e,1),A=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null};function j(e,t){return!(e instanceof Node)||e.contains(t)}var M=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)>m&&this._cancelPress()},this._onPressEnd=e=>{(e.type!==`scroll`||!this._press||j(e.target,this._press.region))&&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`)&&A(S(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=A(S(e.target),l);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)&&j(e.target,this._region??this))&&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),g&&g!==this&&g.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&C(e)?e:null}this._region=n,this._origin=i,_=null,g=this,this._unbindKeys?.(),this._unbindKeys=r(l,{items:()=>this._menuRows()}),this._anchor?.remove();let d=this.hasAttribute(`open`);return this._anchor=y(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 T(t,u))this._setSub(e,!1);g===this&&(g=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=S(document.activeElement);if(!e||e.matches(d))return[];let t=A(e,`[role="menu"]`);return t?this._rowsOf(t):[]}_panel(){return E(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?T(e,l).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&n(t)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=S(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(f))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=S(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=A(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return _?.menu===this&&this.isOpen&&performance.now()-_.at<h}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!b.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||x(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:S(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!b.has(e))return;if(t(e)){let t=this._triggerFor(e.target);if(!t||!x(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||!x(e,n,()=>this.close(!0)))return;let r=S(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(),_={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!x(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||!x(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=S(e.target);this._press={x:n,y:r,region:t,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},p)},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=S(e.target);if(!n)return;if(n.matches(d)){this._handleSearchKey(e,n);return}let r=A(n,`[role="menu"]`);if(!r)return;let i=A(n,l),a=r.matches(`.wui-context-menu-subpanel`)?r.parentElement:null,o=s(e.key,c(this));if(e.key===`Tab`)this.close(!0);else if(o===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(o===`ArrowLeft`){if(!a)return;e.preventDefault(),this._closeSubByKey(a)}else(t(e)||e.key===` `)&&(e.preventDefault(),i?.click())}_handleSearchKey(e,t){let n=A(t,u);if(!n)return;let r=this._rowsOf(k(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(u)?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 E(n))t!==e&&t.matches(u)&&this._closeSub(t);this._setSub(e,!0);let r=k(e).querySelector(`:scope > ${d}`),i=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;i?(i.value=``,this._filter(e,``),i.focus({preventScroll:!0})):t&&this._rowsOf(k(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of T(k(e),u))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),O(e).focus({preventScroll:!0})}_setSub(e,t){let n=k(e);t?(a(O(e),n,{mode:`auto`,beside:!0,onClosed:()=>this._onSubClosed(e)}),O(e).setAttribute(`aria-expanded`,String(o(n)))):o(n)?i(n):this._onSubClosed(e)}_onSubClosed(e){let t=k(e);if(o(t))return;let n=O(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 E(k(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(l)?t.hidden=n!==``&&!w(t).toLowerCase().includes(n):t.matches(u)&&(t.hidden=n!==``&&!w(O(t)).toLowerCase().includes(n))}_handleInput(e){let t=S(e.target)?.closest(d);if(!(t instanceof HTMLInputElement))return;let n=A(t,u);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of T(e,l)){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-${++v}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=A(S(e.target),l);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[...T(e,u)].reverse())i(k(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{M 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-VB3nBucm.js";import{t as h}from"./dom-DMQu--xV.js";import{t as g}from"./elementBase-Cxeyx0tU.js";import{t as _}from"./imeSafeEnter-DPs9qL3S.js";import{t as v}from"./svgNodes-CyPS2oFH.js";function y(){return import(`./tableExport-D1OdFVQj.js`).then(e=>e.r)}var b=`.wui-col-resize`,x=`.wui-group-row, .wui-virtual-spacer`,S=`.wui-select-cell, .wui-expand-cell`;function C(){return v({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`}]])}function w(e){if(e==null)throw TypeError(`Missing DOM node`);return e}function T(e,t){if(e instanceof t)return e;throw TypeError(`Missing DOM node`)}var E=e=>{let t=h(e,b);return t instanceof HTMLElement?t:null},D=e=>e.hasAttribute(`data-wui-skeleton`)||!!e.querySelector(`:scope > td > .skeleton`),O=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=E(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(S)?`lead`:null});if(!i.some(e=>e===`start`||e===`end`))return;let a=p(i);a.forEach((e,t)=>{e&&this._ro?.observe(w(r[t]))});let o=e=>w(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(`${x}, .wui-row-expanded`)||e.cells.length!==r.length||a.forEach((t,n)=>{if(!t)return;let r=w(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(S))}_handles(e){let n=this._headCells(e),r=this._resizable(n);n.forEach((e,n)=>{if(!r[n]||e.querySelector(b))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(x)&&!D(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(b);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(S))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(b);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(w(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=E(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=E(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=w(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(b)!==null;if(this._swallowClick||t){e.stopPropagation(),(t||this._swallowClick)&&e.preventDefault(),this._swallowClick=!1;return}let n=h(e.target,`[data-wui-table-export], [data-wui-density]`);if(n&&this.contains(n)){e.preventDefault(),n.hasAttribute(`data-wui-density`)?this._setDensity(n.getAttribute(`data-wui-density`)??``):this._export(n.getAttribute(`data-wui-table-export`)??``);return}if(!this.hasAttribute(`group-by`))return;let r=h(e.target,`.wui-group-toggle`)?.closest(`.wui-group-row`);if(!(r instanceof HTMLTableRowElement)||!this.contains(r))return;let i=r.dataset.groupKey;this._collapsed.has(i)?this._collapsed.delete(i):this._collapsed.add(i),this._showGroup(r,!this._collapsed.has(i));let a=this._table;a&&this.hasAttribute(`virtual`)&&(this._virtual(a,!0),this._mo?.takeRecords())}async _export(e){if(e!==`csv`&&e!==`xlsx`)return;let t=this.querySelector(`:scope > table`);if(!(t instanceof HTMLTableElement))return;let n=Array.from(t.tBodies[0]?.rows??[]).filter(e=>!e.hidden&&!e.matches(`.wui-group-row, .wui-virtual-spacer, .wui-row-expanded`)&&!D(e)),r=/* @__PURE__ */ new Set;for(let e of n)for(let[t,n]of Array.from(e.cells).entries())(n.matches(S)||n.querySelector(`.u-row-actions`))&&r.add(t);let i=e=>Array.from(e).filter((e,t)=>!r.has(t)).map(e=>{let t=e.cloneNode(!0);if(!(t instanceof Element))return``;for(let e of t.querySelectorAll(`.visually-hidden, .wui-col-resize, .infotip`))e.remove();return(t.textContent??``).replace(/\s+/g,` `).trim()}),a=i(t.tHead?.rows[0]?.cells??[]),o=n.map(e=>i(e.cells)),s=this.getAttribute(`export-name`)??`table`,{downloadTable:c,tableCsv:l,tableXlsx:u}=await y();e===`csv`?c([l(a,o)],`text/csv;charset=utf-8`,`${s}.csv`):c([u(a,o)],`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`${s}.xlsx`)}_setDensity(e){let t=this.querySelector(`:scope > table`);if(t instanceof HTMLTableElement){t.classList.remove(`wui-table-cozy`,`wui-table-compact`),(e===`cozy`||e===`compact`)&&t.classList.add(`wui-table-${e}`);for(let t of this.querySelectorAll(`[data-wui-density]`))t.setAttribute(`aria-pressed`,String(t.getAttribute(`data-wui-density`)===e))}}_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(x));if(a.some(D))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),T(t.querySelector(`.wui-group-cell`),HTMLTableCellElement).colSpan=n.length,T(t.querySelector(`.wui-group-count`),HTMLElement).textContent=c(e.items.length),T(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.replaceChildren(C());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(x);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);w(this._top.cells[0]).colSpan=t,w(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=w(this._items[e]);n.classList.contains(`wui-virtual-off`)!==t&&n.classList.toggle(`wui-virtual-off`,t)}this._range=i;let l=w(this._top),u=w(this._bottom);l.hidden=i.before===0,u.hidden=i.after===0,w(l.cells[0]).style.height=`${i.before}px`,w(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{O 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-VB3nBucm.js";import{t as h}from"./dom-DMQu--xV.js";import{t as g}from"./elementBase-Cxeyx0tU.js";import{n as _}from"./imeSafeEnter-DeO_3lXy.js";import{t as v}from"./svgNodes-CyPS2oFH.js";function y(){return import(`./tableExport-D1OdFVQj.js`).then(e=>e.r)}var b=`.wui-col-resize`,x=`.wui-group-row, .wui-virtual-spacer`,S=`.wui-select-cell, .wui-expand-cell`;function C(){return v({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`}]])}function w(e){if(e==null)throw TypeError(`Missing DOM node`);return e}function T(e,t){if(e instanceof t)return e;throw TypeError(`Missing DOM node`)}var E=e=>{let t=h(e,b);return t instanceof HTMLElement?t:null},D=e=>e.hasAttribute(`data-wui-skeleton`)||!!e.querySelector(`:scope > td > .skeleton`),O=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=E(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(S)?`lead`:null});if(!i.some(e=>e===`start`||e===`end`))return;let a=p(i);a.forEach((e,t)=>{e&&this._ro?.observe(w(r[t]))});let o=e=>w(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(`${x}, .wui-row-expanded`)||e.cells.length!==r.length||a.forEach((t,n)=>{if(!t)return;let r=w(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(S))}_handles(e){let n=this._headCells(e),r=this._resizable(n);n.forEach((e,n)=>{if(!r[n]||e.querySelector(b))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(x)&&!D(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(b);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(S))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(b);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(w(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=E(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=E(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=w(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(b)!==null;if(this._swallowClick||t){e.stopPropagation(),(t||this._swallowClick)&&e.preventDefault(),this._swallowClick=!1;return}let n=h(e.target,`[data-wui-table-export], [data-wui-density]`);if(n&&this.contains(n)){e.preventDefault(),n.hasAttribute(`data-wui-density`)?this._setDensity(n.getAttribute(`data-wui-density`)??``):this._export(n.getAttribute(`data-wui-table-export`)??``);return}if(!this.hasAttribute(`group-by`))return;let r=h(e.target,`.wui-group-toggle`)?.closest(`.wui-group-row`);if(!(r instanceof HTMLTableRowElement)||!this.contains(r))return;let i=r.dataset.groupKey;this._collapsed.has(i)?this._collapsed.delete(i):this._collapsed.add(i),this._showGroup(r,!this._collapsed.has(i));let a=this._table;a&&this.hasAttribute(`virtual`)&&(this._virtual(a,!0),this._mo?.takeRecords())}async _export(e){if(e!==`csv`&&e!==`xlsx`)return;let t=this.querySelector(`:scope > table`);if(!(t instanceof HTMLTableElement))return;let n=Array.from(t.tBodies[0]?.rows??[]).filter(e=>!e.hidden&&!e.matches(`.wui-group-row, .wui-virtual-spacer, .wui-row-expanded`)&&!D(e)),r=/* @__PURE__ */ new Set;for(let e of n)for(let[t,n]of Array.from(e.cells).entries())(n.matches(S)||n.querySelector(`.u-row-actions`))&&r.add(t);let i=e=>Array.from(e).filter((e,t)=>!r.has(t)).map(e=>{let t=e.cloneNode(!0);if(!(t instanceof Element))return``;for(let e of t.querySelectorAll(`.visually-hidden, .wui-col-resize, .infotip`))e.remove();return(t.textContent??``).replace(/\s+/g,` `).trim()}),a=i(t.tHead?.rows[0]?.cells??[]),o=n.map(e=>i(e.cells)),s=this.getAttribute(`export-name`)??`table`,{downloadTable:c,tableCsv:l,tableXlsx:u}=await y();e===`csv`?c([l(a,o)],`text/csv;charset=utf-8`,`${s}.csv`):c([u(a,o)],`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`${s}.xlsx`)}_setDensity(e){let t=this.querySelector(`:scope > table`);if(t instanceof HTMLTableElement){t.classList.remove(`wui-table-cozy`,`wui-table-compact`),(e===`cozy`||e===`compact`)&&t.classList.add(`wui-table-${e}`);for(let t of this.querySelectorAll(`[data-wui-density]`))t.setAttribute(`aria-pressed`,String(t.getAttribute(`data-wui-density`)===e))}}_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(x));if(a.some(D))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),T(t.querySelector(`.wui-group-cell`),HTMLTableCellElement).colSpan=n.length,T(t.querySelector(`.wui-group-count`),HTMLElement).textContent=c(e.items.length),T(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.replaceChildren(C());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(x);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);w(this._top.cells[0]).colSpan=t,w(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=w(this._items[e]);n.classList.contains(`wui-virtual-off`)!==t&&n.classList.toggle(`wui-virtual-off`,t)}this._range=i;let l=w(this._top),u=w(this._bottom);l.hidden=i.before===0,u.hidden=i.after===0,w(l.cells[0]).style.height=`${i.before}px`,w(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{O as t};
@@ -1 +1 @@
1
- import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./calendarMath-CT99RyhR.js";import{i as f,r as p}from"./dom-DMQu--xV.js";import{t as m}from"./elementBase-Cxeyx0tU.js";import{r as h,t as g}from"./fieldState-D-zQcXUS.js";import{_,b as v,g as y}from"./formatters-DTW53DjY.js";import{t as b}from"./formMirror-9IpSgeZb.js";import{t as x}from"./iconGlyphs.g-Dj8sa1HF.js";import{a as S,l as C,s as w}from"./nativeOverlay-BHD2QV02.js";import{n as T,t as E}from"./rtl-g7G8Bsib.js";import{r as D}from"./textStore-DBplASiZ.js";import{t as O}from"./datePicker.g-sGQE8c3n.js";var k=()=>D(`datePicker`,O),A=e=>e-(e%10+10)%10-1,j=class extends m{static formAssociated=!0;static get observedAttributes(){return[`value`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`disabled-weekdays`,`display-format`,`mode`,`size`,`aria-label`,`aria-describedby`,`aria-invalid`]}_internals;_value;_defaultValue;_rendered;_viewY;_viewM;_mode;_focus;_gridFocus;_slide;_viewNavigated;_openFn;_closeFn;_onKeyBound;_closingQuietly;get _open(){return f(this._openFn,`open missing`)}get _close(){return f(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._gridFocus=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&&w(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||``,b(this,this._value),this._syncTrigger()}_firstDay(){return c(this)}_monthOnly(){return this.getAttribute(`mode`)===`month`}_yearOnly(){return this.getAttribute(`mode`)===`year`}_monthKey(e){return e&&this.hasAttribute(`value-as-date`)?e.slice(0,7):e}_monthStored(e){return this.hasAttribute(`value-as-date`)?`${e}-01`:e}_parts(e){if(this._yearOnly()){let t=a(e);return t?{y:t.y,m:0,d:1}:null}if(!this._monthOnly())return l(e);let n=t(this._monthKey(e));return n?{y:n.y,m:n.m,d:1}:null}_placeholder(){return this.getAttribute(`placeholder`)||(this._yearOnly()?k().yearPlaceholder:this._monthOnly()?k().monthPlaceholder:k().placeholder)}_label(t){let n=this.getAttribute(`display-format`);return this._yearOnly()?s(t,n):this._monthOnly()?e(this._monthKey(t)||``,n):i(t,n)}render(){this._dropPanel(),this._defaultValue===void 0&&(this._defaultValue=this.getAttribute(`value`)||``,this._value=this._defaultValue||this._value);let e=this._placeholder(),t=this._parts(this._value);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`:``,i=this.getAttribute(`aria-label`),a=this.getAttribute(`aria-describedby`);this.replaceChildren(p(`div`,{class:`datepicker`},p(`button`,{type:`button`,class:`input datepicker-trigger${r}${t?` has-value`:``}`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-invalid":this.hasAttribute(`aria-invalid`)?`true`:void 0,disabled:this.hasAttribute(`disabled`)?!0:void 0,"aria-label":i,"aria-describedby":a},p(`span`,{"data-trigger-label":!0,class:t?``:`wui-select-placeholder`},t?this._label(this._value):e),x(`calendar-dots`)),p(`div`,{class:`datepicker-pop`,role:`dialog`,popover:`auto`}))),this._rendered=!0,h(this,this.querySelector(`.datepicker-trigger`)),b(this,this._value),this._wire()}_syncFormValue(){b(this,this._value)}_syncTrigger(){let e=this.querySelector(`.datepicker-trigger`),t=this.querySelector(`[data-trigger-label]`);if(!(t instanceof HTMLSpanElement))return;let n=this._parts(this._value);t.textContent=n?this._label(this._value):this._placeholder(),t.classList.toggle(`wui-select-placeholder`,!n),e?.classList.toggle(`has-value`,!!n),h(this,e)}_limits(){if(this._yearOnly()){let e=a(this.getAttribute(`min`)),t=a(this.getAttribute(`max`)),n=e?e.y:-1/0,r=t?t.y:1/0;return{dayDisabled:()=>!0,monthDisabled:()=>!0,yearDisabled:e=>e<n||e>r}}if(this._monthOnly()){let e=t(this._monthKey(this.getAttribute(`min`))),n=t(this._monthKey(this.getAttribute(`max`))),r=e?e.y*12+e.m:-1/0,i=n?n.y*12+n.m:1/0,a=e?e.y:-1/0,o=n?n.y:1/0;return{dayDisabled:()=>!0,monthDisabled:(e,t)=>{let n=e*12+t;return n<r||n>i},yearDisabled:e=>e<a||e>o}}let e=l(this.getAttribute(`min`)),n=l(this.getAttribute(`max`)),r=e?new Date(e.y,e.m,e.d).getTime():-1/0,i=n?new Date(n.y,n.m,n.d).getTime():1/0,s=/* @__PURE__ */ new Set;for(let e of(this.getAttribute(`disabled-weekdays`)||``).split(`,`)){let t=e.trim();/^[0-6]$/.test(t)&&s.add(Number(t))}return{dayDisabled:(e,t,n)=>{let a=new Date(e,t,n),o=a.getTime();return o<r||o>i||s.has(a.getDay())},monthDisabled:(e,t)=>{let n=new Date(e,t,1).getTime();return new Date(e,t,o(e,t)).getTime()<r||n>i},yearDisabled:e=>{let t=new Date(e,0,1).getTime();return new Date(e,11,31).getTime()<r||t>i}}}_dropPanel(){let e=this.querySelector(`.datepicker-pop`);if(e instanceof HTMLDivElement){this._closingQuietly=!0;try{S(e)}finally{this._closingQuietly=!1}}}_renderView(){let e=this.querySelector(`.datepicker-pop`);e instanceof HTMLDivElement&&(this._mode===`months`?e.replaceChildren(...this._monthsNodes()):this._mode===`years`?e.replaceChildren(...this._yearsNodes()):e.replaceChildren(...this._daysNodes()),this._focusActive())}_daysNodes(){let e=this._firstDay(),t=(new Date(this._viewY,this._viewM,1).getDay()-e+7)%7,n=o(this._viewY,this._viewM),r=l(this._value),i=/* @__PURE__ */ new Date,{dayDisabled:a}=this._limits(),s=this._focus||r||{y:this._viewY,m:this._viewM,d:1},c=(e,t,n,o)=>{let c=d(e,t,n),l=r&&r.y===e&&r.m===t&&r.d===n,u=i.getFullYear()===e&&i.getMonth()===t&&i.getDate()===n,f=s.y===e&&s.m===t&&s.d===n,m=a(e,t,n),h=[`datepicker-day`,o?`is-outside`:``,u?`is-today`:``,l?`is-selected`:``].filter(Boolean).join(` `);return p(`button`,{type:`button`,class:h,"data-iso":c,role:`gridcell`,tabindex:f&&!m?`0`:`-1`,"aria-selected":l?`true`:void 0,disabled:m?!0:void 0,"aria-disabled":m?`true`:void 0},n)},f=[],m=u(this._viewY,this._viewM-1),h=o(m.y,m.m);for(let e=t-1;e>=0;e--)f.push(c(m.y,m.m,h-e,!0));for(let e=1;e<=n;e++)f.push(c(this._viewY,this._viewM,e,!1));let y=u(this._viewY,this._viewM+1),b=(7-(t+n)%7)%7;for(let e=1;e<=b;e++)f.push(c(y.y,y.m,e,!0));let S=a(i.getFullYear(),i.getMonth(),i.getDate()),C=g(this)?null:p(`button`,{type:`button`,class:`datepicker-link`,"data-clear":!0},k().clearLabel),w=Array.from({length:7},(t,n)=>p(`span`,null,v((n+e)%7,`min`)));return[p(`div`,{class:`datepicker-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":`-1`,"aria-label":k().previousMonth},x(`chevron-left`)),p(`button`,{type:`button`,class:`datepicker-month`,"data-view":`months`,"aria-label":k().chooseMonthYearLabel},`${_(this._viewM)} ${this._viewY}`),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":`1`,"aria-label":k().nextMonth},x(`chevron-right`))),p(`div`,{class:`datepicker-weekdays`},...w),p(`div`,{class:`datepicker-grid${this._slide?` ${this._slide}`:``}`,role:`grid`},...f),p(`div`,{class:`datepicker-foot`},p(`button`,{type:`button`,class:`datepicker-link`,"data-today":!0,disabled:S?!0:void 0},k().todayLabel),C)]}_clearFoot(e){return!e||g(this)?[]:[p(`div`,{class:`datepicker-foot`},p(`button`,{type:`button`,class:`datepicker-link`,"data-clear":!0},k().clearLabel))]}_monthsNodes(){let e=this._parts(this._value),t=/* @__PURE__ */ new Date,{monthDisabled:n}=this._limits(),r=[];for(let i=0;i<12;i++){let a=e&&e.y===this._viewY&&e.m===i,o=t.getFullYear()===this._viewY&&t.getMonth()===i,s=n(this._viewY,i),c=[`datepicker-cell`,o?`is-today`:``,a?`is-selected`:``].filter(Boolean).join(` `);r.push(p(`button`,{type:`button`,class:c,"data-month":i,tabindex:this._monthOnly()?this._viewY*12+i===this._gridFocus&&!s?0:-1:void 0,disabled:s?!0:void 0},y(i)))}return[p(`div`,{class:`datepicker-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-year":`-1`,"aria-label":k().previousYearLabel},x(`chevron-left`)),p(`button`,{type:`button`,class:`datepicker-month`,"data-view":`years`,"aria-label":k().chooseYearLabel},this._viewY),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-year":`1`,"aria-label":k().nextYearLabel},x(`chevron-right`))),p(`div`,{class:`datepicker-cells`},...r),...this._clearFoot(this._monthOnly())]}_yearsNodes(){let e=this._parts(this._value),t=(/* @__PURE__ */ new Date()).getFullYear(),{yearDisabled:n}=this._limits(),r=A(this._viewY),i=[];for(let a=0;a<12;a++){let o=r+a,s=e&&e.y===o,c=t===o,l=n(o),u=[`datepicker-cell`,c?`is-today`:``,s?`is-selected`:``].filter(Boolean).join(` `);i.push(p(`button`,{type:`button`,class:u,"data-year":o,tabindex:this._yearOnly()?o===this._gridFocus&&!l?0:-1:void 0,disabled:l?!0:void 0},o))}return[p(`div`,{class:`datepicker-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-decade":`-1`,"aria-label":k().previousDecadeLabel},x(`chevron-left`)),p(`span`,{class:`datepicker-month`},`${r+1} to ${r+10}`),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-decade":`1`,"aria-label":k().nextDecadeLabel},x(`chevron-right`))),p(`div`,{class:`datepicker-cells`},...i),...this._clearFoot(this._yearOnly())]}_gridKind(){if(this._monthOnly()){let{monthDisabled:e}=this._limits(),t=e=>e-Math.floor(e/12)*12;return{view:`months`,attr:`month`,per:12,page:12,lo:e=>e*12,unit:(e,t)=>e*12+t,cell:t,disabled:n=>e(Math.floor(n/12),t(n)),iso:e=>this._monthStored(n(Math.floor(e/12),t(e)))}}if(this._yearOnly()){let{yearDisabled:e}=this._limits();return{view:`years`,attr:`year`,per:1,page:10,lo:A,unit:e=>e,cell:e=>e,disabled:e,iso:r}}return null}_gridFocusCell(e){let t=e.lo(this._viewY),n=e=>e!==null&&e>=t&&e<t+12,r=this._parts(this._value),i=/* @__PURE__ */ new Date,a=[r?e.unit(r.y,r.m):null,e.unit(i.getFullYear(),i.getMonth())];for(let t of a)if(n(t)&&!e.disabled(t))return t;for(let n=t;n<t+12;n++)if(!e.disabled(n))return n;return null}_syncGridFocus(){let e=this._gridKind();e&&(this._gridFocus=this._gridFocusCell(e))}_focusActive(){let e=this.querySelector(`.datepicker-pop`);if(!(e instanceof HTMLDivElement))return;let t=e.querySelector(`[tabindex="0"]`)||e.querySelector(`.is-selected`)||e.querySelector(`.datepicker-day:not(:disabled), .datepicker-cell:not(:disabled)`);t instanceof HTMLElement&&e.contains(document.activeElement)&&t.focus()}_setFocus(e,t,n,r){let{y:i,m:a}=u(e,t);this._focus={y:i,m:a,d:n};let o=i!==this._viewY||a!==this._viewM;this._viewY=i,this._viewM=a,this._slide=o&&r||``,this._renderView(),this._slide=``;let s=this.querySelector(`.datepicker-day[data-iso="${d(i,a,n)}"]`);s instanceof HTMLButtonElement&&s.focus()}_seek(e,t,n,r){let{dayDisabled:i}=this._limits(),a=new Date(e,t,n);for(let e=0;e<400;e++,a.setDate(a.getDate()+r))if(!i(a.getFullYear(),a.getMonth(),a.getDate()))return new Date(a);return null}_onGridKey(e,t){let n=(e,n)=>{for(let r=0;r<100*t.per;r++,e+=n)if(!t.disabled(e))return e;return null},r=(e,t)=>{let r=n(t>0?e:e+11,t);return r!==null&&r>=e&&r<e+12?r:null},i=e=>{this._viewY=Math.floor(e/t.per),this._gridFocus=e,this._renderView();let n=this.querySelector(`.datepicker-cell[data-${t.attr}="${t.cell(e)}"]`);n instanceof HTMLButtonElement&&n.focus()},a=r=>{e.preventDefault();let a=t.lo(this._viewY),o=n((this._gridFocus??(r<0?a+12:a-1))+r,r<0?-1:1);o!==null&&i(o)};switch(T(e.key,E(this))){case`ArrowLeft`:a(-1);break;case`ArrowRight`:a(1);break;case`ArrowUp`:a(-3);break;case`ArrowDown`:a(3);break;case`Home`:{e.preventDefault();let n=r(t.lo(this._viewY),1);n!==null&&i(n);break}case`End`:{e.preventDefault();let n=r(t.lo(this._viewY),-1);n!==null&&i(n);break}case`PageUp`:case`PageDown`:{e.preventDefault();let n=(this._gridFocus??t.lo(this._viewY))+(e.key===`PageUp`?-1:1)*t.page,a=t.disabled(n)?r(t.lo(Math.floor(n/t.per)),1):n;a!==null&&i(a);break}case`Enter`:case` `:{e.preventDefault();let n=this._gridFocus;n!==null&&!t.disabled(n)&&(this.value=t.iso(n),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close());break}}}_onKey(e){let t=this._gridKind();if(t&&this._mode===t.view){this._onGridKey(e,t);return}if(this._mode!==`days`)return;let n=this._focus||l(this._value)||{y:this._viewY,m:this._viewM,d:1},r=(e,t,n,r,i)=>{let a=this._seek(e,t,n,r);a&&this._setFocus(a.getFullYear(),a.getMonth(),a.getDate(),i)},i=(t,i,a=t<0?-1:1)=>{e.preventDefault(),r(n.y,n.m,n.d+t,a,i)};switch(T(e.key,E(this))){case`ArrowLeft`:i(-1,`slide-prev`);break;case`ArrowRight`:i(1,`slide-next`);break;case`ArrowUp`:i(-7,`slide-prev`);break;case`ArrowDown`:i(7,`slide-next`);break;case`Home`:i(-((new Date(n.y,n.m,n.d).getDay()-this._firstDay()+7)%7),`slide-prev`,1);break;case`End`:i(6-(new Date(n.y,n.m,n.d).getDay()-this._firstDay()+7)%7,`slide-next`,-1);break;case`PageUp`:{e.preventDefault();let t=u(n.y,n.m-(e.shiftKey?12:1));r(t.y,t.m,Math.min(n.d,o(t.y,t.m)),-1,`slide-prev`);break}case`PageDown`:{e.preventDefault();let t=u(n.y,n.m+(e.shiftKey?12:1));r(t.y,t.m,Math.min(n.d,o(t.y,t.m)),1,`slide-next`);break}case`Enter`:case` `:e.preventDefault(),this._limits().dayDisabled(n.y,n.m,n.d)||(this.value=d(n.y,n.m,n.d),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close());return}}_wire(){let e=this.querySelector(`.datepicker-trigger`),t=this.querySelector(`.datepicker-pop`),i=this.querySelector(`.datepicker`);if(!(e instanceof HTMLButtonElement)||!(t instanceof HTMLDivElement))return;let a=()=>w(t),o=()=>{i?.classList.remove(`open`),e.setAttribute(`aria-expanded`,`false`),this._closingQuietly||e.focus()};this._openFn=()=>{if(g(this))return;let n=/* @__PURE__ */ new Date,r=this._parts(this._value),s=this._gridKind();if(s)this._viewY=r?r.y:n.getFullYear(),this._mode=s.view,this._focus=null,this._gridFocus=this._gridFocusCell(s);else{(r||!this._viewNavigated)&&(this._viewY=n.getFullYear(),this._viewM=n.getMonth()),this._mode=`days`;let e=n.getFullYear()===this._viewY&&n.getMonth()===this._viewM,t=r&&r.y===this._viewY&&r.m===this._viewM;if(this._focus=t?r:{y:this._viewY,m:this._viewM,d:e?n.getDate():1},this._limits().dayDisabled(this._focus.y,this._focus.m,this._focus.d)){let e=this._focus,t=[1,-1].map(t=>this._seek(e.y,e.m,e.d,t)).find(t=>t&&t.getMonth()===e.m);t&&(this._focus={y:t.getFullYear(),m:t.getMonth(),d:t.getDate()})}}if(this._renderView(),C(e,t,{mode:`auto`,clampHeight:!0,onClosed:o}),!a())return;i?.classList.add(`open`),e.setAttribute(`aria-expanded`,`true`);let c=t.querySelector(`[tabindex="0"]`);c instanceof HTMLElement&&c.focus()},this._closeFn=()=>{S(t)},e.addEventListener(`click`,()=>a()?this._close():this._open()),t.addEventListener(`click`,e=>{let t=e.target;if(!(t instanceof Element))throw Error(`click target is not an element`);let i=t.closest(`[data-nav]`);if(i instanceof HTMLElement){this._viewNavigated=!0,this._slide=Number(i.dataset.nav)<0?`slide-prev`:`slide-next`;let e=u(this._viewY,this._viewM+Number(i.dataset.nav));this._viewY=e.y,this._viewM=e.m,this._focus={y:e.y,m:e.m,d:1},this._renderView(),this._slide=``;return}let a=t.closest(`[data-nav-year]`);if(a instanceof HTMLElement){this._viewY+=Number(a.dataset.navYear),this._syncGridFocus(),this._renderView();return}let o=t.closest(`[data-nav-decade]`);if(o instanceof HTMLElement){this._viewY+=Number(o.dataset.navDecade)*10,this._syncGridFocus(),this._renderView();return}let s=t.closest(`[data-view]`);if(s instanceof HTMLElement){this._mode=s.dataset.view,this._renderView();return}let c=t.closest(`[data-month]`);if(c instanceof HTMLButtonElement&&!c.disabled){if(this._monthOnly()){this.value=this._monthStored(n(this._viewY,Number(c.dataset.month))),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}this._viewNavigated=!0,this._viewM=Number(c.dataset.month),this._mode=`days`,this._focus={y:this._viewY,m:this._viewM,d:1},this._renderView();return}let l=t.closest(`[data-year]`);if(l instanceof HTMLButtonElement&&!l.disabled){if(this._yearOnly()){this.value=r(Number(l.dataset.year)),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}this._viewNavigated=!0,this._viewY=Number(l.dataset.year),this._mode=`months`,this._syncGridFocus(),this._renderView();return}if(t.closest(`[data-today]`)){let e=/* @__PURE__ */ new Date;if(this._limits().dayDisabled(e.getFullYear(),e.getMonth(),e.getDate()))return;this.value=d(e.getFullYear(),e.getMonth(),e.getDate()),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}if(t.closest(`[data-clear]`)){this.value=``,this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}let f=t.closest(`.datepicker-day[data-iso]`);f instanceof HTMLButtonElement&&!f.disabled&&(this.value=f.dataset.iso,this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close())}),this._onKeyBound=e=>{a()&&this._onKey(e)},t.addEventListener(`keydown`,this._onKeyBound),this._syncFormValue()}};export{j as t};
1
+ import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./calendarMath-CT99RyhR.js";import{i as f,r as p}from"./dom-DMQu--xV.js";import{t as m}from"./elementBase-Cxeyx0tU.js";import{r as h,t as g}from"./fieldState-D-zQcXUS.js";import{_,b as v,g as y}from"./formatters-DTW53DjY.js";import{t as b}from"./formMirror-9IpSgeZb.js";import{t as x}from"./iconGlyphs.g-a9FtjPXh.js";import{a as S,l as C,s as w}from"./nativeOverlay-BHD2QV02.js";import{n as T,t as E}from"./rtl-g7G8Bsib.js";import{r as D}from"./textStore-DBplASiZ.js";import{t as O}from"./datePicker.g-sGQE8c3n.js";var k=()=>D(`datePicker`,O),A=e=>e-(e%10+10)%10-1,j=class extends m{static formAssociated=!0;static get observedAttributes(){return[`value`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`disabled-weekdays`,`display-format`,`mode`,`size`,`aria-label`,`aria-describedby`,`aria-invalid`]}_internals;_value;_defaultValue;_rendered;_viewY;_viewM;_mode;_focus;_gridFocus;_slide;_viewNavigated;_openFn;_closeFn;_onKeyBound;_closingQuietly;get _open(){return f(this._openFn,`open missing`)}get _close(){return f(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._gridFocus=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&&w(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||``,b(this,this._value),this._syncTrigger()}_firstDay(){return c(this)}_monthOnly(){return this.getAttribute(`mode`)===`month`}_yearOnly(){return this.getAttribute(`mode`)===`year`}_monthKey(e){return e&&this.hasAttribute(`value-as-date`)?e.slice(0,7):e}_monthStored(e){return this.hasAttribute(`value-as-date`)?`${e}-01`:e}_parts(e){if(this._yearOnly()){let t=a(e);return t?{y:t.y,m:0,d:1}:null}if(!this._monthOnly())return l(e);let n=t(this._monthKey(e));return n?{y:n.y,m:n.m,d:1}:null}_placeholder(){return this.getAttribute(`placeholder`)||(this._yearOnly()?k().yearPlaceholder:this._monthOnly()?k().monthPlaceholder:k().placeholder)}_label(t){let n=this.getAttribute(`display-format`);return this._yearOnly()?s(t,n):this._monthOnly()?e(this._monthKey(t)||``,n):i(t,n)}render(){this._dropPanel(),this._defaultValue===void 0&&(this._defaultValue=this.getAttribute(`value`)||``,this._value=this._defaultValue||this._value);let e=this._placeholder(),t=this._parts(this._value);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`:``,i=this.getAttribute(`aria-label`),a=this.getAttribute(`aria-describedby`);this.replaceChildren(p(`div`,{class:`datepicker`},p(`button`,{type:`button`,class:`input datepicker-trigger${r}${t?` has-value`:``}`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-invalid":this.hasAttribute(`aria-invalid`)?`true`:void 0,disabled:this.hasAttribute(`disabled`)?!0:void 0,"aria-label":i,"aria-describedby":a},p(`span`,{"data-trigger-label":!0,class:t?``:`wui-select-placeholder`},t?this._label(this._value):e),x(`calendar-dots`)),p(`div`,{class:`datepicker-pop`,role:`dialog`,popover:`auto`}))),this._rendered=!0,h(this,this.querySelector(`.datepicker-trigger`)),b(this,this._value),this._wire()}_syncFormValue(){b(this,this._value)}_syncTrigger(){let e=this.querySelector(`.datepicker-trigger`),t=this.querySelector(`[data-trigger-label]`);if(!(t instanceof HTMLSpanElement))return;let n=this._parts(this._value);t.textContent=n?this._label(this._value):this._placeholder(),t.classList.toggle(`wui-select-placeholder`,!n),e?.classList.toggle(`has-value`,!!n),h(this,e)}_limits(){if(this._yearOnly()){let e=a(this.getAttribute(`min`)),t=a(this.getAttribute(`max`)),n=e?e.y:-1/0,r=t?t.y:1/0;return{dayDisabled:()=>!0,monthDisabled:()=>!0,yearDisabled:e=>e<n||e>r}}if(this._monthOnly()){let e=t(this._monthKey(this.getAttribute(`min`))),n=t(this._monthKey(this.getAttribute(`max`))),r=e?e.y*12+e.m:-1/0,i=n?n.y*12+n.m:1/0,a=e?e.y:-1/0,o=n?n.y:1/0;return{dayDisabled:()=>!0,monthDisabled:(e,t)=>{let n=e*12+t;return n<r||n>i},yearDisabled:e=>e<a||e>o}}let e=l(this.getAttribute(`min`)),n=l(this.getAttribute(`max`)),r=e?new Date(e.y,e.m,e.d).getTime():-1/0,i=n?new Date(n.y,n.m,n.d).getTime():1/0,s=/* @__PURE__ */ new Set;for(let e of(this.getAttribute(`disabled-weekdays`)||``).split(`,`)){let t=e.trim();/^[0-6]$/.test(t)&&s.add(Number(t))}return{dayDisabled:(e,t,n)=>{let a=new Date(e,t,n),o=a.getTime();return o<r||o>i||s.has(a.getDay())},monthDisabled:(e,t)=>{let n=new Date(e,t,1).getTime();return new Date(e,t,o(e,t)).getTime()<r||n>i},yearDisabled:e=>{let t=new Date(e,0,1).getTime();return new Date(e,11,31).getTime()<r||t>i}}}_dropPanel(){let e=this.querySelector(`.datepicker-pop`);if(e instanceof HTMLDivElement){this._closingQuietly=!0;try{S(e)}finally{this._closingQuietly=!1}}}_renderView(){let e=this.querySelector(`.datepicker-pop`);e instanceof HTMLDivElement&&(this._mode===`months`?e.replaceChildren(...this._monthsNodes()):this._mode===`years`?e.replaceChildren(...this._yearsNodes()):e.replaceChildren(...this._daysNodes()),this._focusActive())}_daysNodes(){let e=this._firstDay(),t=(new Date(this._viewY,this._viewM,1).getDay()-e+7)%7,n=o(this._viewY,this._viewM),r=l(this._value),i=/* @__PURE__ */ new Date,{dayDisabled:a}=this._limits(),s=this._focus||r||{y:this._viewY,m:this._viewM,d:1},c=(e,t,n,o)=>{let c=d(e,t,n),l=r&&r.y===e&&r.m===t&&r.d===n,u=i.getFullYear()===e&&i.getMonth()===t&&i.getDate()===n,f=s.y===e&&s.m===t&&s.d===n,m=a(e,t,n),h=[`datepicker-day`,o?`is-outside`:``,u?`is-today`:``,l?`is-selected`:``].filter(Boolean).join(` `);return p(`button`,{type:`button`,class:h,"data-iso":c,role:`gridcell`,tabindex:f&&!m?`0`:`-1`,"aria-selected":l?`true`:void 0,disabled:m?!0:void 0,"aria-disabled":m?`true`:void 0},n)},f=[],m=u(this._viewY,this._viewM-1),h=o(m.y,m.m);for(let e=t-1;e>=0;e--)f.push(c(m.y,m.m,h-e,!0));for(let e=1;e<=n;e++)f.push(c(this._viewY,this._viewM,e,!1));let y=u(this._viewY,this._viewM+1),b=(7-(t+n)%7)%7;for(let e=1;e<=b;e++)f.push(c(y.y,y.m,e,!0));let S=a(i.getFullYear(),i.getMonth(),i.getDate()),C=g(this)?null:p(`button`,{type:`button`,class:`datepicker-link`,"data-clear":!0},k().clearLabel),w=Array.from({length:7},(t,n)=>p(`span`,null,v((n+e)%7,`min`)));return[p(`div`,{class:`datepicker-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":`-1`,"aria-label":k().previousMonth},x(`chevron-left`)),p(`button`,{type:`button`,class:`datepicker-month`,"data-view":`months`,"aria-label":k().chooseMonthYearLabel},`${_(this._viewM)} ${this._viewY}`),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":`1`,"aria-label":k().nextMonth},x(`chevron-right`))),p(`div`,{class:`datepicker-weekdays`},...w),p(`div`,{class:`datepicker-grid${this._slide?` ${this._slide}`:``}`,role:`grid`},...f),p(`div`,{class:`datepicker-foot`},p(`button`,{type:`button`,class:`datepicker-link`,"data-today":!0,disabled:S?!0:void 0},k().todayLabel),C)]}_clearFoot(e){return!e||g(this)?[]:[p(`div`,{class:`datepicker-foot`},p(`button`,{type:`button`,class:`datepicker-link`,"data-clear":!0},k().clearLabel))]}_monthsNodes(){let e=this._parts(this._value),t=/* @__PURE__ */ new Date,{monthDisabled:n}=this._limits(),r=[];for(let i=0;i<12;i++){let a=e&&e.y===this._viewY&&e.m===i,o=t.getFullYear()===this._viewY&&t.getMonth()===i,s=n(this._viewY,i),c=[`datepicker-cell`,o?`is-today`:``,a?`is-selected`:``].filter(Boolean).join(` `);r.push(p(`button`,{type:`button`,class:c,"data-month":i,tabindex:this._monthOnly()?this._viewY*12+i===this._gridFocus&&!s?0:-1:void 0,disabled:s?!0:void 0},y(i)))}return[p(`div`,{class:`datepicker-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-year":`-1`,"aria-label":k().previousYearLabel},x(`chevron-left`)),p(`button`,{type:`button`,class:`datepicker-month`,"data-view":`years`,"aria-label":k().chooseYearLabel},this._viewY),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-year":`1`,"aria-label":k().nextYearLabel},x(`chevron-right`))),p(`div`,{class:`datepicker-cells`},...r),...this._clearFoot(this._monthOnly())]}_yearsNodes(){let e=this._parts(this._value),t=(/* @__PURE__ */ new Date()).getFullYear(),{yearDisabled:n}=this._limits(),r=A(this._viewY),i=[];for(let a=0;a<12;a++){let o=r+a,s=e&&e.y===o,c=t===o,l=n(o),u=[`datepicker-cell`,c?`is-today`:``,s?`is-selected`:``].filter(Boolean).join(` `);i.push(p(`button`,{type:`button`,class:u,"data-year":o,tabindex:this._yearOnly()?o===this._gridFocus&&!l?0:-1:void 0,disabled:l?!0:void 0},o))}return[p(`div`,{class:`datepicker-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-decade":`-1`,"aria-label":k().previousDecadeLabel},x(`chevron-left`)),p(`span`,{class:`datepicker-month`},`${r+1} to ${r+10}`),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav-decade":`1`,"aria-label":k().nextDecadeLabel},x(`chevron-right`))),p(`div`,{class:`datepicker-cells`},...i),...this._clearFoot(this._yearOnly())]}_gridKind(){if(this._monthOnly()){let{monthDisabled:e}=this._limits(),t=e=>e-Math.floor(e/12)*12;return{view:`months`,attr:`month`,per:12,page:12,lo:e=>e*12,unit:(e,t)=>e*12+t,cell:t,disabled:n=>e(Math.floor(n/12),t(n)),iso:e=>this._monthStored(n(Math.floor(e/12),t(e)))}}if(this._yearOnly()){let{yearDisabled:e}=this._limits();return{view:`years`,attr:`year`,per:1,page:10,lo:A,unit:e=>e,cell:e=>e,disabled:e,iso:r}}return null}_gridFocusCell(e){let t=e.lo(this._viewY),n=e=>e!==null&&e>=t&&e<t+12,r=this._parts(this._value),i=/* @__PURE__ */ new Date,a=[r?e.unit(r.y,r.m):null,e.unit(i.getFullYear(),i.getMonth())];for(let t of a)if(n(t)&&!e.disabled(t))return t;for(let n=t;n<t+12;n++)if(!e.disabled(n))return n;return null}_syncGridFocus(){let e=this._gridKind();e&&(this._gridFocus=this._gridFocusCell(e))}_focusActive(){let e=this.querySelector(`.datepicker-pop`);if(!(e instanceof HTMLDivElement))return;let t=e.querySelector(`[tabindex="0"]`)||e.querySelector(`.is-selected`)||e.querySelector(`.datepicker-day:not(:disabled), .datepicker-cell:not(:disabled)`);t instanceof HTMLElement&&e.contains(document.activeElement)&&t.focus()}_setFocus(e,t,n,r){let{y:i,m:a}=u(e,t);this._focus={y:i,m:a,d:n};let o=i!==this._viewY||a!==this._viewM;this._viewY=i,this._viewM=a,this._slide=o&&r||``,this._renderView(),this._slide=``;let s=this.querySelector(`.datepicker-day[data-iso="${d(i,a,n)}"]`);s instanceof HTMLButtonElement&&s.focus()}_seek(e,t,n,r){let{dayDisabled:i}=this._limits(),a=new Date(e,t,n);for(let e=0;e<400;e++,a.setDate(a.getDate()+r))if(!i(a.getFullYear(),a.getMonth(),a.getDate()))return new Date(a);return null}_onGridKey(e,t){let n=(e,n)=>{for(let r=0;r<100*t.per;r++,e+=n)if(!t.disabled(e))return e;return null},r=(e,t)=>{let r=n(t>0?e:e+11,t);return r!==null&&r>=e&&r<e+12?r:null},i=e=>{this._viewY=Math.floor(e/t.per),this._gridFocus=e,this._renderView();let n=this.querySelector(`.datepicker-cell[data-${t.attr}="${t.cell(e)}"]`);n instanceof HTMLButtonElement&&n.focus()},a=r=>{e.preventDefault();let a=t.lo(this._viewY),o=n((this._gridFocus??(r<0?a+12:a-1))+r,r<0?-1:1);o!==null&&i(o)};switch(T(e.key,E(this))){case`ArrowLeft`:a(-1);break;case`ArrowRight`:a(1);break;case`ArrowUp`:a(-3);break;case`ArrowDown`:a(3);break;case`Home`:{e.preventDefault();let n=r(t.lo(this._viewY),1);n!==null&&i(n);break}case`End`:{e.preventDefault();let n=r(t.lo(this._viewY),-1);n!==null&&i(n);break}case`PageUp`:case`PageDown`:{e.preventDefault();let n=(this._gridFocus??t.lo(this._viewY))+(e.key===`PageUp`?-1:1)*t.page,a=t.disabled(n)?r(t.lo(Math.floor(n/t.per)),1):n;a!==null&&i(a);break}case`Enter`:case` `:{e.preventDefault();let n=this._gridFocus;n!==null&&!t.disabled(n)&&(this.value=t.iso(n),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close());break}}}_onKey(e){let t=this._gridKind();if(t&&this._mode===t.view){this._onGridKey(e,t);return}if(this._mode!==`days`)return;let n=this._focus||l(this._value)||{y:this._viewY,m:this._viewM,d:1},r=(e,t,n,r,i)=>{let a=this._seek(e,t,n,r);a&&this._setFocus(a.getFullYear(),a.getMonth(),a.getDate(),i)},i=(t,i,a=t<0?-1:1)=>{e.preventDefault(),r(n.y,n.m,n.d+t,a,i)};switch(T(e.key,E(this))){case`ArrowLeft`:i(-1,`slide-prev`);break;case`ArrowRight`:i(1,`slide-next`);break;case`ArrowUp`:i(-7,`slide-prev`);break;case`ArrowDown`:i(7,`slide-next`);break;case`Home`:i(-((new Date(n.y,n.m,n.d).getDay()-this._firstDay()+7)%7),`slide-prev`,1);break;case`End`:i(6-(new Date(n.y,n.m,n.d).getDay()-this._firstDay()+7)%7,`slide-next`,-1);break;case`PageUp`:{e.preventDefault();let t=u(n.y,n.m-(e.shiftKey?12:1));r(t.y,t.m,Math.min(n.d,o(t.y,t.m)),-1,`slide-prev`);break}case`PageDown`:{e.preventDefault();let t=u(n.y,n.m+(e.shiftKey?12:1));r(t.y,t.m,Math.min(n.d,o(t.y,t.m)),1,`slide-next`);break}case`Enter`:case` `:e.preventDefault(),this._limits().dayDisabled(n.y,n.m,n.d)||(this.value=d(n.y,n.m,n.d),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close());return}}_wire(){let e=this.querySelector(`.datepicker-trigger`),t=this.querySelector(`.datepicker-pop`),i=this.querySelector(`.datepicker`);if(!(e instanceof HTMLButtonElement)||!(t instanceof HTMLDivElement))return;let a=()=>w(t),o=()=>{i?.classList.remove(`open`),e.setAttribute(`aria-expanded`,`false`),this._closingQuietly||e.focus()};this._openFn=()=>{if(g(this))return;let n=/* @__PURE__ */ new Date,r=this._parts(this._value),s=this._gridKind();if(s)this._viewY=r?r.y:n.getFullYear(),this._mode=s.view,this._focus=null,this._gridFocus=this._gridFocusCell(s);else{(r||!this._viewNavigated)&&(this._viewY=n.getFullYear(),this._viewM=n.getMonth()),this._mode=`days`;let e=n.getFullYear()===this._viewY&&n.getMonth()===this._viewM,t=r&&r.y===this._viewY&&r.m===this._viewM;if(this._focus=t?r:{y:this._viewY,m:this._viewM,d:e?n.getDate():1},this._limits().dayDisabled(this._focus.y,this._focus.m,this._focus.d)){let e=this._focus,t=[1,-1].map(t=>this._seek(e.y,e.m,e.d,t)).find(t=>t&&t.getMonth()===e.m);t&&(this._focus={y:t.getFullYear(),m:t.getMonth(),d:t.getDate()})}}if(this._renderView(),C(e,t,{mode:`auto`,clampHeight:!0,onClosed:o}),!a())return;i?.classList.add(`open`),e.setAttribute(`aria-expanded`,`true`);let c=t.querySelector(`[tabindex="0"]`);c instanceof HTMLElement&&c.focus()},this._closeFn=()=>{S(t)},e.addEventListener(`click`,()=>a()?this._close():this._open()),t.addEventListener(`click`,e=>{let t=e.target;if(!(t instanceof Element))throw Error(`click target is not an element`);let i=t.closest(`[data-nav]`);if(i instanceof HTMLElement){this._viewNavigated=!0,this._slide=Number(i.dataset.nav)<0?`slide-prev`:`slide-next`;let e=u(this._viewY,this._viewM+Number(i.dataset.nav));this._viewY=e.y,this._viewM=e.m,this._focus={y:e.y,m:e.m,d:1},this._renderView(),this._slide=``;return}let a=t.closest(`[data-nav-year]`);if(a instanceof HTMLElement){this._viewY+=Number(a.dataset.navYear),this._syncGridFocus(),this._renderView();return}let o=t.closest(`[data-nav-decade]`);if(o instanceof HTMLElement){this._viewY+=Number(o.dataset.navDecade)*10,this._syncGridFocus(),this._renderView();return}let s=t.closest(`[data-view]`);if(s instanceof HTMLElement){this._mode=s.dataset.view,this._renderView();return}let c=t.closest(`[data-month]`);if(c instanceof HTMLButtonElement&&!c.disabled){if(this._monthOnly()){this.value=this._monthStored(n(this._viewY,Number(c.dataset.month))),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}this._viewNavigated=!0,this._viewM=Number(c.dataset.month),this._mode=`days`,this._focus={y:this._viewY,m:this._viewM,d:1},this._renderView();return}let l=t.closest(`[data-year]`);if(l instanceof HTMLButtonElement&&!l.disabled){if(this._yearOnly()){this.value=r(Number(l.dataset.year)),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}this._viewNavigated=!0,this._viewY=Number(l.dataset.year),this._mode=`months`,this._syncGridFocus(),this._renderView();return}if(t.closest(`[data-today]`)){let e=/* @__PURE__ */ new Date;if(this._limits().dayDisabled(e.getFullYear(),e.getMonth(),e.getDate()))return;this.value=d(e.getFullYear(),e.getMonth(),e.getDate()),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}if(t.closest(`[data-clear]`)){this.value=``,this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close();return}let f=t.closest(`.datepicker-day[data-iso]`);f instanceof HTMLButtonElement&&!f.disabled&&(this.value=f.dataset.iso,this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close())}),this._onKeyBound=e=>{a()&&this._onKey(e)},t.addEventListener(`keydown`,this._onKeyBound),this._syncFormValue()}};export{j as t};
@@ -1 +1 @@
1
- import{i as e,n as t,r as n,s as r,t as i,u as a}from"./calendarMath-CT99RyhR.js";import{n as o}from"./devWarn-DXdRWZs3.js";import{r as s,t as c}from"./textStore-DBplASiZ.js";import{t as l}from"./dateRangePicker.g-Pnc37vgX.js";import{n as u,r as d,t as f}from"./zone-BR02ZkHF.js";import{r as p}from"./dom-DMQu--xV.js";import{t as m}from"./elementBase-Cxeyx0tU.js";import{r as h,t as g}from"./fieldState-D-zQcXUS.js";import{_,b as v}from"./formatters-DTW53DjY.js";import{t as y}from"./iconGlyphs.g-Dj8sa1HF.js";import{a as b,l as x,s as S}from"./nativeOverlay-BHD2QV02.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(e,t=/* @__PURE__ */ new Date,{timeZone:n=f,financialYearStart:i=C}={}){if(!O(e))return null;let a=r(d(n,t));if(!a)throw Error(`today missing`);let{y:o,m:c,d:u}=a,p=(e,t,n)=>D(new Date(Date.UTC(e,t,n))),m=s(`dateRangePicker`,l)[T[e]];switch(e){case`today`:return{label:m,start:p(o,c,u),end:p(o,c,u)};case`yesterday`:return{label:m,start:p(o,c,u-1),end:p(o,c,u-1)};case`last7Days`:return{label:m,start:p(o,c,u-6),end:p(o,c,u)};case`last30Days`:return{label:m,start:p(o,c,u-29),end:p(o,c,u)};case`thisMonth`:return{label:m,start:p(o,c,1),end:p(o,c+1,0)};case`lastMonth`:return{label:m,start:p(o,c-1,1),end:p(o,c,0)};case`thisFinancialYear`:{let e=i-1,t=c>=e?o:o-1;return{label:m,start:p(t,e,1),end:p(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(e,t=/* @__PURE__ */ new Date,n={}){let i=String(e??``).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 e of a)if(typeof e==`string`){let r=k(e,t,n);r?o.push(r):A(`"${e}" is not one of ${w.join(`, `)}`)}else j(e)&&typeof e.label==`string`&&e.label&&typeof e.start==`string`&&typeof e.end==`string`&&r(e.start)&&r(e.end)?o.push({label:e.label,start:e.start,end:e.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 m{static formAssociated=!0;_internals;_start;_end;_hover;_viewY;_viewM;get open(){return this.querySelector(`.daterange`)?.classList.contains(`open`)??!1}set open(e){e?!g(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 n(this)}_label(){let t=this.getAttribute(`placeholder`)||N().placeholder;return!this._start&&!this._end?{text:t,empty:!0}:{text:c(N().rangeText,{start:e(this._start)||N().startLabel,end:e(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 e=r(this._start);e&&(this._viewY=e.y,this._viewM=e.m);let t=this.getAttribute(`size`),n=t===`sm`?` wui-input-sm`:t===`lg`?` wui-input-lg`:t===`xl`?` wui-input-xl`:``,{text:i,empty:a}=this._label(),o=this.getAttribute(`aria-label`),s=this.getAttribute(`aria-describedby`),c=p(`button`,{type:`button`,class:`input daterange-trigger${n}${a?``:` has-value`}`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-invalid":this.hasAttribute(`aria-invalid`)?`true`:null,disabled:this.hasAttribute(`disabled`),"aria-label":o||null,"aria-describedby":s||null},p(`span`,{"data-range-label":!0,class:a?`wui-select-placeholder`:``},i),y(`calendar`));this.replaceChildren(p(`div`,{class:`daterange`},c,p(`div`,{class:`daterange-pop`,role:`dialog`,popover:`auto`}))),h(this,this.querySelector(`.daterange-trigger`)),this._rendered=!0,this._syncMirrors(),this._wire()}formResetCallback(){this.value={start:this._defaultStart||``,end:this._defaultEnd||``}}_syncTrigger(){let e=this.querySelector(`.daterange-trigger`),t=this.querySelector(`[data-range-label]`);if(!t)return;let{text:n,empty:r}=this._label();t.textContent=n,t.classList.toggle(`wui-select-placeholder`,r),e?.classList.toggle(`has-value`,!r)}_syncMirrors(){let e=this.getAttribute(`start-name`)||this.getAttribute(`name`),t=this.getAttribute(`end-name`);this._mirror(`start`,e,this._start),this._mirror(`end`,t,this._end)}_mirror(e,t,n){if(!t)return;let r=this.querySelector(`input[type="hidden"][data-range-mirror="${e}"]`),i;r instanceof HTMLInputElement?i=r:(i=document.createElement(`input`),i.type=`hidden`,i.setAttribute(`data-range-mirror`,e),this.appendChild(i)),i.name=t,i.value=n||``,i.disabled=this.hasAttribute(`disabled`)}_limits(){let e=r(this.getAttribute(`min`)),t=r(this.getAttribute(`max`)),n=e?new Date(e.y,e.m,e.d).getTime():-1/0,i=t?new Date(t.y,t.m,t.d).getTime():1/0;return(e,t,r)=>{let a=new Date(e,t,r).getTime();return a<n||a>i}}_monthHtml(e,n){let r=this._firstDay(),o=(new Date(e,n,1).getDay()-r+7)%7,s=t(e,n),c=this._limits(),l=Array.from({length:7},(e,t)=>p(`span`,null,v((t+r)%7,`min`))),u=(e,t,n,r)=>{let i=a(e,t,n),o=c(e,t,n),s=[`datepicker-day`,r?`is-outside`:``].filter(Boolean).join(` `);return p(`button`,{type:`button`,class:s,"data-iso":i,disabled:o},n)},d=[],f=i(e,n-1),m=t(f.y,f.m);for(let e=o-1;e>=0;e--)d.push(u(f.y,f.m,m-e,!0));for(let t=1;t<=s;t++)d.push(u(e,n,t,!1));let h=i(e,n+1),g=(7-(o+s)%7)%7;for(let e=1;e<=g;e++)d.push(u(h.y,h.m,e,!0));return p(`div`,{class:`daterange-cal`},p(`div`,{class:`datepicker-month-label`},`${_(n)} ${e}`),p(`div`,{class:`datepicker-weekdays`},...l),p(`div`,{class:`datepicker-grid`,role:`grid`},...d))}_presetOptions(){let e=this.getAttribute(`time-zone`),t=f;e!==null&&(u(e)?t=e:o(`[@webority/ui-elements] <wui-date-range> time-zone="${e}" is not a time zone this browser knows; India Standard Time is used.`));let n=this.getAttribute(`financial-year-start`),r=4;if(n!==null){let e=Number(n);Number.isInteger(e)&&e>=1&&e<=12?r=e:o(`[@webority/ui-elements] <wui-date-range> financial-year-start="${n}" must be a month number from 1 to 12; April (4) is used.`)}return{timeZone:t,financialYearStart:r}}_presetsHtml(){if(!this._presetList?.length)return null;let e=this._limits(),t=t=>{let n=r(t);if(!n)throw Error(`Expected a preset date, found "${t}".`);return e(n.y,n.m,n.d)},n=this._presetList.map((e,n)=>p(`button`,{type:`button`,class:`wui-daterange-preset`,"data-preset":n,disabled:t(e.start)||t(e.end)},e.label));return p(`div`,{class:`wui-daterange-presets`,role:`group`,"aria-label":N().quickRangesLabel},...n)}_renderView(){let e=this.querySelector(`.daterange-pop`);if(!e)return;let t=i(this._viewY,this._viewM+1),n=this._presetsHtml(),r=[p(`div`,{class:`daterange-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":-1,"aria-label":N().previousMonthLabel},y(`chevron-left`)),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":1,"aria-label":N().nextMonthLabel},y(`chevron-right`))),p(`div`,{class:`daterange-cals`},this._monthHtml(this._viewY,this._viewM),this._monthHtml(t.y,t.m)),p(`div`,{class:`datepicker-foot`},p(`span`,{class:`daterange-hint`,"data-range-hint":!0}),p(`button`,{type:`button`,class:`datepicker-link`,"data-clear":!0},N().clearLabel))];e.classList.toggle(`wui-daterange-pop--presets`,n!==null),e.replaceChildren(...n?[n,p(`div`,{class:`wui-daterange-main`},...r)]:r),this._paint()}_paint(){let t=this.querySelector(`.daterange-pop`);if(!t)return;let n=this._start?new Date(this._start).getTime():null,r=this._end;n&&!this._end&&this._hover&&new Date(this._hover).getTime()>=n&&(r=this._hover);let i=r?new Date(r).getTime():null;for(let e of F(t,`.datepicker-day[data-iso]`)){let t=new Date(e.dataset.iso??``).getTime(),r=n!=null&&t===n,a=i!=null&&t===i,o=n!=null&&i!=null&&t>n&&t<i;e.classList.toggle(`is-range-start`,r),e.classList.toggle(`is-range-end`,a),e.classList.toggle(`in-range`,o)}F(t,`[data-preset]`).forEach(e=>{let t=this._presetList?.[Number(e.dataset.preset)],n=!!t&&t.start===this._start&&t.end===this._end;e.classList.toggle(`is-active`,n),e.setAttribute(`aria-pressed`,String(n))});let a=t.querySelector(`[data-range-hint]`);a&&(a.textContent=this._start?this._end?c(N().rangeText,{start:e(this._start),end:e(this._end)}):N().pickEndDateLabel:N().pickStartDateLabel)}_pick(e){!this._start||this._start&&this._end?(this._start=e,this._end=``,this._hover=``,this._syncTrigger(),this._syncMirrors(),this._paint()):new Date(e).getTime()<new Date(this._start).getTime()?(this._start=e,this._syncTrigger(),this._syncMirrors(),this._paint(),this.dispatchEvent(new Event(`change`,{bubbles:!0}))):(this._end=e,this._syncTrigger(),this._syncMirrors(),this._paint(),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close())}_applyPreset({start:e,end:t}){this._start=e,this._end=t,this._hover=``,this._syncTrigger(),this._syncMirrors(),this._paint(),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close()}_dropPanel(){let e=this.querySelector(`.daterange-pop`);e instanceof HTMLDivElement&&b(e)}_wire(){let e=this.querySelector(`.daterange-trigger`),t=this.querySelector(`.daterange-pop`),n=this.querySelector(`.daterange`);if(!(e instanceof HTMLButtonElement)||!(t instanceof HTMLDivElement))return;let a=()=>S(t),o=()=>{this._hover=``,n?.classList.remove(`open`),e.setAttribute(`aria-expanded`,`false`),this.dispatchEvent(new CustomEvent(`wui-date-range:openchange`,{bubbles:!0,detail:{open:!1}}))};this._open=()=>{let i=r(this._start);if(i)this._viewY=i.y,this._viewM=i.m;else{let e=/* @__PURE__ */ new Date;this._viewY=e.getFullYear(),this._viewM=e.getMonth()}this._presetList=M(this.getAttribute(`presets`),/* @__PURE__ */ new Date,this._presetOptions()),this._renderView(),x(e,t,{mode:`auto`,clampHeight:!0,onClosed:o}),a()&&(n?.classList.add(`open`),e.setAttribute(`aria-expanded`,`true`),this.dispatchEvent(new CustomEvent(`wui-date-range:openchange`,{bubbles:!0,detail:{open:!0}})))},this._close=()=>{b(t)},e.addEventListener(`click`,()=>{a()?this._close():g(this)||this._open()}),t.addEventListener(`click`,e=>{let t=P(e),n=t.closest(`[data-nav]`);if(n instanceof HTMLElement){let e=i(this._viewY,this._viewM+Number(n.dataset.nav));this._viewY=e.y,this._viewM=e.m,this._renderView();return}if(t.closest(`[data-clear]`)){this._start=``,this._end=``,this._hover=``,this._syncTrigger(),this._syncMirrors(),this._renderView(),this.dispatchEvent(new Event(`change`,{bubbles:!0}));return}let r=t.closest(`[data-preset]`);if(r instanceof HTMLButtonElement&&!r.disabled){let e=this._presetList?.[Number(r.dataset.preset)];e&&this._applyPreset(e);return}let a=t.closest(`.datepicker-day[data-iso]`);if(a instanceof HTMLButtonElement&&!a.disabled){let e=a.dataset.iso;e!==void 0&&this._pick(e)}}),t.addEventListener(`mouseover`,e=>{let t=P(e).closest(`.datepicker-day[data-iso]`),n=t instanceof HTMLButtonElement?t.dataset.iso:void 0;n!==void 0&&this._start&&!this._end&&(this._hover=n,this._paint())}),this._syncMirrors()}};export{I as t};
1
+ import{i as e,n as t,r as n,s as r,t as i,u as a}from"./calendarMath-CT99RyhR.js";import{n as o}from"./devWarn-DXdRWZs3.js";import{r as s,t as c}from"./textStore-DBplASiZ.js";import{t as l}from"./dateRangePicker.g-Pnc37vgX.js";import{n as u,r as d,t as f}from"./zone-BR02ZkHF.js";import{r as p}from"./dom-DMQu--xV.js";import{t as m}from"./elementBase-Cxeyx0tU.js";import{r as h,t as g}from"./fieldState-D-zQcXUS.js";import{_,b as v}from"./formatters-DTW53DjY.js";import{t as y}from"./iconGlyphs.g-a9FtjPXh.js";import{a as b,l as x,s as S}from"./nativeOverlay-BHD2QV02.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(e,t=/* @__PURE__ */ new Date,{timeZone:n=f,financialYearStart:i=C}={}){if(!O(e))return null;let a=r(d(n,t));if(!a)throw Error(`today missing`);let{y:o,m:c,d:u}=a,p=(e,t,n)=>D(new Date(Date.UTC(e,t,n))),m=s(`dateRangePicker`,l)[T[e]];switch(e){case`today`:return{label:m,start:p(o,c,u),end:p(o,c,u)};case`yesterday`:return{label:m,start:p(o,c,u-1),end:p(o,c,u-1)};case`last7Days`:return{label:m,start:p(o,c,u-6),end:p(o,c,u)};case`last30Days`:return{label:m,start:p(o,c,u-29),end:p(o,c,u)};case`thisMonth`:return{label:m,start:p(o,c,1),end:p(o,c+1,0)};case`lastMonth`:return{label:m,start:p(o,c-1,1),end:p(o,c,0)};case`thisFinancialYear`:{let e=i-1,t=c>=e?o:o-1;return{label:m,start:p(t,e,1),end:p(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(e,t=/* @__PURE__ */ new Date,n={}){let i=String(e??``).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 e of a)if(typeof e==`string`){let r=k(e,t,n);r?o.push(r):A(`"${e}" is not one of ${w.join(`, `)}`)}else j(e)&&typeof e.label==`string`&&e.label&&typeof e.start==`string`&&typeof e.end==`string`&&r(e.start)&&r(e.end)?o.push({label:e.label,start:e.start,end:e.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 m{static formAssociated=!0;_internals;_start;_end;_hover;_viewY;_viewM;get open(){return this.querySelector(`.daterange`)?.classList.contains(`open`)??!1}set open(e){e?!g(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 n(this)}_label(){let t=this.getAttribute(`placeholder`)||N().placeholder;return!this._start&&!this._end?{text:t,empty:!0}:{text:c(N().rangeText,{start:e(this._start)||N().startLabel,end:e(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 e=r(this._start);e&&(this._viewY=e.y,this._viewM=e.m);let t=this.getAttribute(`size`),n=t===`sm`?` wui-input-sm`:t===`lg`?` wui-input-lg`:t===`xl`?` wui-input-xl`:``,{text:i,empty:a}=this._label(),o=this.getAttribute(`aria-label`),s=this.getAttribute(`aria-describedby`),c=p(`button`,{type:`button`,class:`input daterange-trigger${n}${a?``:` has-value`}`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-invalid":this.hasAttribute(`aria-invalid`)?`true`:null,disabled:this.hasAttribute(`disabled`),"aria-label":o||null,"aria-describedby":s||null},p(`span`,{"data-range-label":!0,class:a?`wui-select-placeholder`:``},i),y(`calendar`));this.replaceChildren(p(`div`,{class:`daterange`},c,p(`div`,{class:`daterange-pop`,role:`dialog`,popover:`auto`}))),h(this,this.querySelector(`.daterange-trigger`)),this._rendered=!0,this._syncMirrors(),this._wire()}formResetCallback(){this.value={start:this._defaultStart||``,end:this._defaultEnd||``}}_syncTrigger(){let e=this.querySelector(`.daterange-trigger`),t=this.querySelector(`[data-range-label]`);if(!t)return;let{text:n,empty:r}=this._label();t.textContent=n,t.classList.toggle(`wui-select-placeholder`,r),e?.classList.toggle(`has-value`,!r)}_syncMirrors(){let e=this.getAttribute(`start-name`)||this.getAttribute(`name`),t=this.getAttribute(`end-name`);this._mirror(`start`,e,this._start),this._mirror(`end`,t,this._end)}_mirror(e,t,n){if(!t)return;let r=this.querySelector(`input[type="hidden"][data-range-mirror="${e}"]`),i;r instanceof HTMLInputElement?i=r:(i=document.createElement(`input`),i.type=`hidden`,i.setAttribute(`data-range-mirror`,e),this.appendChild(i)),i.name=t,i.value=n||``,i.disabled=this.hasAttribute(`disabled`)}_limits(){let e=r(this.getAttribute(`min`)),t=r(this.getAttribute(`max`)),n=e?new Date(e.y,e.m,e.d).getTime():-1/0,i=t?new Date(t.y,t.m,t.d).getTime():1/0;return(e,t,r)=>{let a=new Date(e,t,r).getTime();return a<n||a>i}}_monthHtml(e,n){let r=this._firstDay(),o=(new Date(e,n,1).getDay()-r+7)%7,s=t(e,n),c=this._limits(),l=Array.from({length:7},(e,t)=>p(`span`,null,v((t+r)%7,`min`))),u=(e,t,n,r)=>{let i=a(e,t,n),o=c(e,t,n),s=[`datepicker-day`,r?`is-outside`:``].filter(Boolean).join(` `);return p(`button`,{type:`button`,class:s,"data-iso":i,disabled:o},n)},d=[],f=i(e,n-1),m=t(f.y,f.m);for(let e=o-1;e>=0;e--)d.push(u(f.y,f.m,m-e,!0));for(let t=1;t<=s;t++)d.push(u(e,n,t,!1));let h=i(e,n+1),g=(7-(o+s)%7)%7;for(let e=1;e<=g;e++)d.push(u(h.y,h.m,e,!0));return p(`div`,{class:`daterange-cal`},p(`div`,{class:`datepicker-month-label`},`${_(n)} ${e}`),p(`div`,{class:`datepicker-weekdays`},...l),p(`div`,{class:`datepicker-grid`,role:`grid`},...d))}_presetOptions(){let e=this.getAttribute(`time-zone`),t=f;e!==null&&(u(e)?t=e:o(`[@webority/ui-elements] <wui-date-range> time-zone="${e}" is not a time zone this browser knows; India Standard Time is used.`));let n=this.getAttribute(`financial-year-start`),r=4;if(n!==null){let e=Number(n);Number.isInteger(e)&&e>=1&&e<=12?r=e:o(`[@webority/ui-elements] <wui-date-range> financial-year-start="${n}" must be a month number from 1 to 12; April (4) is used.`)}return{timeZone:t,financialYearStart:r}}_presetsHtml(){if(!this._presetList?.length)return null;let e=this._limits(),t=t=>{let n=r(t);if(!n)throw Error(`Expected a preset date, found "${t}".`);return e(n.y,n.m,n.d)},n=this._presetList.map((e,n)=>p(`button`,{type:`button`,class:`wui-daterange-preset`,"data-preset":n,disabled:t(e.start)||t(e.end)},e.label));return p(`div`,{class:`wui-daterange-presets`,role:`group`,"aria-label":N().quickRangesLabel},...n)}_renderView(){let e=this.querySelector(`.daterange-pop`);if(!e)return;let t=i(this._viewY,this._viewM+1),n=this._presetsHtml(),r=[p(`div`,{class:`daterange-head`},p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":-1,"aria-label":N().previousMonthLabel},y(`chevron-left`)),p(`button`,{type:`button`,class:`datepicker-nav-btn`,"data-nav":1,"aria-label":N().nextMonthLabel},y(`chevron-right`))),p(`div`,{class:`daterange-cals`},this._monthHtml(this._viewY,this._viewM),this._monthHtml(t.y,t.m)),p(`div`,{class:`datepicker-foot`},p(`span`,{class:`daterange-hint`,"data-range-hint":!0}),p(`button`,{type:`button`,class:`datepicker-link`,"data-clear":!0},N().clearLabel))];e.classList.toggle(`wui-daterange-pop--presets`,n!==null),e.replaceChildren(...n?[n,p(`div`,{class:`wui-daterange-main`},...r)]:r),this._paint()}_paint(){let t=this.querySelector(`.daterange-pop`);if(!t)return;let n=this._start?new Date(this._start).getTime():null,r=this._end;n&&!this._end&&this._hover&&new Date(this._hover).getTime()>=n&&(r=this._hover);let i=r?new Date(r).getTime():null;for(let e of F(t,`.datepicker-day[data-iso]`)){let t=new Date(e.dataset.iso??``).getTime(),r=n!=null&&t===n,a=i!=null&&t===i,o=n!=null&&i!=null&&t>n&&t<i;e.classList.toggle(`is-range-start`,r),e.classList.toggle(`is-range-end`,a),e.classList.toggle(`in-range`,o)}F(t,`[data-preset]`).forEach(e=>{let t=this._presetList?.[Number(e.dataset.preset)],n=!!t&&t.start===this._start&&t.end===this._end;e.classList.toggle(`is-active`,n),e.setAttribute(`aria-pressed`,String(n))});let a=t.querySelector(`[data-range-hint]`);a&&(a.textContent=this._start?this._end?c(N().rangeText,{start:e(this._start),end:e(this._end)}):N().pickEndDateLabel:N().pickStartDateLabel)}_pick(e){!this._start||this._start&&this._end?(this._start=e,this._end=``,this._hover=``,this._syncTrigger(),this._syncMirrors(),this._paint()):new Date(e).getTime()<new Date(this._start).getTime()?(this._start=e,this._syncTrigger(),this._syncMirrors(),this._paint(),this.dispatchEvent(new Event(`change`,{bubbles:!0}))):(this._end=e,this._syncTrigger(),this._syncMirrors(),this._paint(),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close())}_applyPreset({start:e,end:t}){this._start=e,this._end=t,this._hover=``,this._syncTrigger(),this._syncMirrors(),this._paint(),this.dispatchEvent(new Event(`change`,{bubbles:!0})),this._close()}_dropPanel(){let e=this.querySelector(`.daterange-pop`);e instanceof HTMLDivElement&&b(e)}_wire(){let e=this.querySelector(`.daterange-trigger`),t=this.querySelector(`.daterange-pop`),n=this.querySelector(`.daterange`);if(!(e instanceof HTMLButtonElement)||!(t instanceof HTMLDivElement))return;let a=()=>S(t),o=()=>{this._hover=``,n?.classList.remove(`open`),e.setAttribute(`aria-expanded`,`false`),this.dispatchEvent(new CustomEvent(`wui-date-range:openchange`,{bubbles:!0,detail:{open:!1}}))};this._open=()=>{let i=r(this._start);if(i)this._viewY=i.y,this._viewM=i.m;else{let e=/* @__PURE__ */ new Date;this._viewY=e.getFullYear(),this._viewM=e.getMonth()}this._presetList=M(this.getAttribute(`presets`),/* @__PURE__ */ new Date,this._presetOptions()),this._renderView(),x(e,t,{mode:`auto`,clampHeight:!0,onClosed:o}),a()&&(n?.classList.add(`open`),e.setAttribute(`aria-expanded`,`true`),this.dispatchEvent(new CustomEvent(`wui-date-range:openchange`,{bubbles:!0,detail:{open:!0}})))},this._close=()=>{b(t)},e.addEventListener(`click`,()=>{a()?this._close():g(this)||this._open()}),t.addEventListener(`click`,e=>{let t=P(e),n=t.closest(`[data-nav]`);if(n instanceof HTMLElement){let e=i(this._viewY,this._viewM+Number(n.dataset.nav));this._viewY=e.y,this._viewM=e.m,this._renderView();return}if(t.closest(`[data-clear]`)){this._start=``,this._end=``,this._hover=``,this._syncTrigger(),this._syncMirrors(),this._renderView(),this.dispatchEvent(new Event(`change`,{bubbles:!0}));return}let r=t.closest(`[data-preset]`);if(r instanceof HTMLButtonElement&&!r.disabled){let e=this._presetList?.[Number(r.dataset.preset)];e&&this._applyPreset(e);return}let a=t.closest(`.datepicker-day[data-iso]`);if(a instanceof HTMLButtonElement&&!a.disabled){let e=a.dataset.iso;e!==void 0&&this._pick(e)}}),t.addEventListener(`mouseover`,e=>{let t=P(e).closest(`.datepicker-day[data-iso]`),n=t instanceof HTMLButtonElement?t.dataset.iso:void 0;n!==void 0&&this._start&&!this._end&&(this._hover=n,this._paint())}),this._syncMirrors()}};export{I 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-BHD2QV02.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-BCHtqitp.js";import{a as r,l as i,s as a}from"./nativeOverlay-BHD2QV02.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 +1 @@
1
- import{n as e}from"./buttonClass-C8BRtTk8.js";import{t}from"./devWarn-DXdRWZs3.js";import{i as n,r}from"./dom-DMQu--xV.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{a,c as o,d as s,f as c,i as l,l as u,m as d,n as f,o as p,p as m,s as h,t as g,u as _}from"./initials-Qb6ITcri.js";import{t as v}from"./avatarNode-BaEvz5Xr.js";import{t as y}from"./iconGlyphs.g-Dj8sa1HF.js";import{n as b,r as x,t as S}from"./textStore-DBplASiZ.js";import{t as C}from"./hasOwn-CJsplJ62.js";import{a as w,l as T}from"./nativeOverlay-BHD2QV02.js";import{n as E,t as D}from"./rtl-g7G8Bsib.js";import{t as O}from"./gantt.g-TdTxeruW.js";var k=`data-wui-gantt-pick`,A=e=>`${e}px`,j=(e,t,n)=>{let i=r(`div`,{class:`wui-gantt-table-cell`},n);return i.setAttribute(`role`,t),i.dataset.col=e,i};function M(e){let t=e.text,n=r(`div`,{class:`wui-gantt-table`});n.setAttribute(`role`,`table`),n.setAttribute(`aria-label`,e.title);let i=r(`div`);i.setAttribute(`role`,`rowgroup`);let a=r(`div`,{class:`wui-gantt-table-row`});a.dataset.kind=`head`,a.setAttribute(`role`,`row`),a.style.height=A(e.headHeight),a.append(j(`name`,`columnheader`,t.tableName),j(`owner`,`columnheader`,t.detailsOwner),j(`start`,`columnheader`,t.tableStart),j(`end`,`columnheader`,t.tableEnd),j(`done`,`columnheader`,t.detailsDone)),i.append(a);let o=r(`div`);o.setAttribute(`role`,`rowgroup`);for(let n of e.rows){if(n.height===0)continue;let i=n.row;if(n.kind===`group`){let i=n.group;if(!i)continue;let a=r(`div`,{class:`wui-gantt-table-row`});a.dataset.kind=`group`,a.dataset.wuiGanttGroup=i.name,a.setAttribute(`role`,`row`),a.style.height=A(n.height);let s=r(`div`,{class:`wui-gantt-table-cell wui-gantt-table-group`});s.setAttribute(`role`,`rowheader`);let c=r(`button`,{class:`wui-gantt-group-toggle`});c.type=`button`,c.setAttribute(`aria-expanded`,String(!i.folded)),c.setAttribute(`aria-label`,S(i.folded?t.unfoldLabel:t.foldLabel,{group:i.name})),c.setAttribute(e.focusAttr,`group:${i.name}`);let l=y(i.folded?`chevron-right`:`chevron-down`,{size:16});c.replaceChildren(...l?[l]:[]),s.append(c,r(`span`,null,i.name),r(`span`,null,b(t,`groupSummary`,i.count,{percent:i.percent}))),a.append(s),o.append(a);continue}let a=r(`div`,{class:`wui-gantt-table-row`});a.dataset.kind=i.end===void 0?`milestone`:`bar`,a.dataset.wuiGanttKey=i.key,a.dataset.wuiGanttPick=i.key,i.key===e.selected&&(a.dataset.selected=`true`),a.setAttribute(`role`,`row`),a.style.height=A(n.height);let s=j(`name`,`rowheader`,i.name);s.title=i.name;let c=j(`owner`,`cell`,``);i.owner&&(c.title=i.owner,c.replaceChildren(...[v({initials:g(i.owner)},`avatar-xs`)].filter(e=>e!==null)),c.append(r(`span`,{class:`visually-hidden`},i.owner)));let l=j(`start`,`cell`,i.start===void 0?``:p(u(i.start))),d=j(`end`,`cell`,i.end===void 0?``:p(u(i.end))),f=j(`done`,`cell`,i.end===void 0?``:`${i.progress??0}%`);a.append(s,c,l,d,f),o.append(a)}let s=e.skeleton;for(let e=0;s&&e<s.rows;e+=1){let e=r(`div`,{class:`wui-gantt-table-row`});e.dataset.kind=`skeleton`,e.setAttribute(`role`,`row`),e.setAttribute(`aria-hidden`,`true`),e.style.height=A(s.rowHeight);let t=r(`span`,{class:`wui-gantt-skeleton`});t.style.height=A(s.barHeight),e.append(t),o.append(e)}return n.append(i,o),n}var N=()=>x(`gantt`,O),P=`wui-gantt:zoom-change`,F=`wui-gantt:from-change`,I=`wui-gantt:fold-change`,L=`wui-gantt:select`,R=`wui-gantt:add-task`,z=`wui-gantt:retry`,B=`data-wui-gantt-focus`,V=`bar:`,H=`http://www.w3.org/2000/svg`,U=[`day`,`week`,`month`],W=3,G=16,K=300,q=[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`,`Escape`,`Enter`,` `],J=0,Y=e=>`${e}px`;function X(e){return typeof e==`object`&&!!e&&`rows`in e&&Array.isArray(e.rows)&&`title`in e&&typeof e.title==`string`}function Z(e){let t=N();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 Q=e=>e.progress??0,$=e=>e.status??`notStarted`,ee=(e,t)=>(e??[]).join(`\0`)===(t??[]).join(`\0`),te=class extends i{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(),J+=1,this.uid=`wui-gantt-${J}`,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(C(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&&=(w(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?u(e.from):null),n(!ee(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(P,{zoom:e}),this._controlled?this._syncRadios():(this._zoom=e,this._fromMs=this._fromMs===null?null:s(e,this._fromMs),this._draw())}_setFrom(e){this._emit(F,{from:h(e)}),this._controlled||(this._fromMs=e,this._draw())}_setFolded(e){let t=new Set(this._folded);t.delete(e)||t.add(e),this._emit(I,{folded:[...t]}),this._controlled||(this._folded=t,this._draw())}_setSelected(e){this._emit(L,{key:e}),this._focusAfter=`${V}${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=U.find(e=>e===t.value);n&&this._setZoom(n)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[${B}]`);if(n instanceof HTMLElement&&this.contains(n)){this._activate(n.getAttribute(B)??``,n);return}let r=t.closest(`[${k}]`);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(V)){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(R):e===`retry`?this._emit(z):n&&e===`nav:earlier`?this._setFrom(_(n.zoom,n.fromMs,-1)):n&&e===`nav:later`?this._setFrom(_(n.zoom,n.fromMs,1)):n&&e===`nav:today`?this._setFrom(d(n.zoom,n.todayMs)):e.startsWith(`zoom:`)&&t.click()}_bars(){return[...this.querySelectorAll(`.wui-gantt-lane [${B}^="${V}"]`)].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||!q.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(B)?.startsWith(V))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(e.key,D(this))){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[n.length-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(B)??``,t)}}_focusToken(){let e=document.activeElement;return e instanceof HTMLElement&&this.contains(e)?e.getAttribute(B):null}_draw(){if(this._card&&=(w(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`,N().errorText)]}if(this.replaceChildren(...r),this._card){let e=n(this._barByKey(this._selected??void 0),`selected gantt bar`);this.append(this._card),T(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(`[${B}]`)].find(t=>t.getAttribute(B)===e);i instanceof HTMLElement&&(e.startsWith(V)?this._focusBar(i):i.focus())}_compose(){let e=this._spec;if(!X(e))throw TypeError("<wui-gantt> has no spec: set the `spec` property or add a JSON script child.");this._seed(e),m(e);let t=e.layout??`table`,n=l[t],i=N(),p=u(e.today??c()),h=this._zoom,g=s(h,this._fromMs??d(h,p)),_={layout:t,zoom:h,fromMs:g,todayMs:p};this._resolved=_,this._specRows=e.rows;let v=e.rows.some(e=>e.start!==void 0),y=(e.state??`ready`)===`ready`&&!v?`empty`:e.state??`ready`;this.dataset.state=y,this.dataset.zoom=h,this.dataset.layout=t,y===`loading`?this.setAttribute(`aria-busy`,`true`):this.removeAttribute(`aria-busy`);let b=y===`ready`?o({...e,folded:[...this._folded],selected:this._selected},_):null,x=b?.axis??a(t,h,g),S=r(`div`,{class:`wui-gantt-lane`});S.style.width=Y(x.width),b?this._fillLane(S,e,b):y===`loading`&&(S.style.height=Y(W*n.rowH));let C=[];y===`loading`&&C.push(this._fillSkeleton(S,e,n)),y===`empty`&&C.push(this._emptyBlock(e)),y===`error`&&C.push(this._stateBlock(`error`,e.errorText||i.errorText));let w=this._head(x),T=r(`div`,{class:`wui-gantt-plot`});T.append(w,S);let E=r(`div`,{class:`wui-gantt-scroller`});if(t===`table`){let t=M({title:e.title,rows:b?.rows??[],headHeight:2*f.tierH,selected:this._selected,text:i,focusAttr:B,skeleton:y===`loading`?{rows:W,rowHeight:n.rowH,barHeight:n.barH}:void 0});E.append(t,T)}else E.append(T);return[this._toolbar(e,y===`ready`),E,...C,this._legend(t)]}_toolbar(e,t){let n=r(`div`,{class:`wui-gantt-toolbar`});return t&&n.append(r(`p`,{class:`wui-gantt-count`},this._countText(e.rows))),n.append(this._scale(),this._nav()),n}_countText(e){let t=N(),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,u(e.start??``)),a=Math.max(a,u(e.end??e.start??``));return[b(t,`summaryTasks`,n.length-r),b(t,`summaryMilestones`,r),S(t.summaryRange,{from:p(i),to:p(a)})].join(`, `)}_scale(){let e=N(),t=r(`div`,{class:`segmented segmented-sm wui-gantt-scale`});t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-label`,e.scaleLabel),t.append(Object.assign(r(`span`,{class:`segmented-thumb`}),{ariaHidden:`true`}));let n={day:e.dayLabel,week:e.weekLabel,month:e.monthLabel};for(let e of U){let i=r(`label`,{class:`segmented-option`}),a=r(`input`,{class:`segmented-input`});a.type=`radio`,a.name=`${this.uid}-scale`,a.value=e,a.checked=e===this._zoom,a.setAttribute(B,`zoom:${e}`),i.append(a,n[e]),t.append(i)}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=Y(n.offsetWidth),t.style.transform=`translateX(${n.offsetLeft}px)`,t.style.opacity=`1`)}_nav(){let t=N(),n=r(`div`,{class:`wui-gantt-nav`}),i=(t,n,i)=>{let a=r(`button`,{class:e(`neutral`,`soft`,`sm`)});a.type=`button`,a.setAttribute(`aria-label`,n),a.setAttribute(B,t);let o=y(i,{size:16});return a.replaceChildren(...o?[o]:[]),a},a=r(`button`,{class:e(`neutral`,`soft`,`sm`)},t.todayLabel);return a.type=`button`,a.setAttribute(B,`nav:today`),n.append(i(`nav:earlier`,t.earlierLabel,`chevron-left`),i(`nav:later`,t.laterLabel,`chevron-right`),a),n}_head(e){let t=r(`div`,{class:`wui-gantt-head`});t.style.width=Y(e.width),t.setAttribute(`aria-hidden`,`true`);let n=(e,t)=>{let n=r(`div`,{class:`wui-gantt-tier ${t}`});for(let t of e){let e=r(`div`,{class:t.weekend?`wui-gantt-cell wui-gantt-cell-weekend`:`wui-gantt-cell`});e.style.left=Y(t.x),e.style.width=Y(t.w),t.sub&&e.append(r(`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=N(),n=r(`div`,{class:`wui-gantt-legend`});n.setAttribute(`role`,`list`),n.setAttribute(`aria-label`,t.legendLabel);let i=(e,t)=>{let i=r(`span`,null);i.setAttribute(`role`,`listitem`),i.append(e,t),n.append(i)};for(let e of[`done`,`inProgress`,`atRisk`,`notStarted`]){let t=r(`span`,{class:`wui-gantt-swatch`});t.dataset.status=e,i(t,Z(e))}let a=r(`span`,{class:`wui-gantt-swatch`});if(a.dataset.kind=`milestone`,i(a,t.milestoneLabel),e===`table`){let e=r(`span`,{class:`wui-gantt-legend-note`},t.legendRemaining);e.setAttribute(`role`,`listitem`),n.append(e)}return n}_stateBlock(t,n){let i=N(),a=r(`div`,{class:`wui-gantt-state`});if(t===`error`){a.setAttribute(`role`,`alert`),a.append(r(`p`,null,n));let t=r(`button`,{class:e(`neutral`,`soft`,`sm`)},i.retryLabel);t.type=`button`,t.setAttribute(B,`retry`),a.append(t)}else a.append(r(`p`,null,n));return a}_emptyBlock(t){let n=N(),i=r(`div`,{class:`wui-gantt-state`});if(i.append(r(`p`,{class:`fw-semibold`},n.emptyTitle),r(`p`,null,t.emptyText||n.emptyText)),t.addTask){let t=r(`button`,{class:e(`primary`,`solid`,`sm`)},n.addTaskLabel);t.type=`button`,t.setAttribute(B,`add`),i.append(t)}return i}_fillSkeleton(e,t,n){let i=r(`div`,{class:`visually-hidden`},t.loadingText||N().loadingText);i.setAttribute(`role`,`status`);for(let t=0;t<W;t+=1){let i=r(`div`,{class:`wui-gantt-skeleton`});i.style.top=Y(t*n.rowH+n.barTop),i.style.left=Y(40+t*60),i.style.width=Y(240),i.style.height=Y(n.barH),i.setAttribute(`aria-hidden`,`true`),e.append(i)}return i}_fillLane(e,t,n){let i=N(),{axis:a}=n,o=n.layout===`table`;e.style.height=Y(n.height),e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,t.title);let s=r(`p`,{class:`visually-hidden`},o?i.helpTextTable:i.helpText);s.id=`${this.uid}-help`,e.setAttribute(`aria-describedby`,s.id);let c=(e,t,n,i,a)=>{let o=r(`div`,{class:e});return o.setAttribute(`aria-hidden`,`true`),o.style.left=Y(t),o.style.top=Y(n),o.style.width=Y(i),o.style.height=Y(a),o},l=[s];for(let e of n.rows){if(e.height===0)continue;let t=c(`wui-gantt-row`,0,e.top,a.width,e.height);o&&e.kind!==`group`&&e.row.key===this._selected&&(t.dataset.selected=`true`),l.push(t)}for(let e of a.weekendX)l.push(c(`wui-gantt-weekend`,e,0,a.ppd,n.height));for(let e of a.gridX)l.push(c(`wui-gantt-grid`,e,0,1,n.height));if(n.today.inWindow){l.push(c(`wui-gantt-today`,n.today.x-1,0,2,n.height));let e=r(`div`,{class:`wui-gantt-today-flag rounded-pill`},i.todayLabel);e.style.left=Y(n.today.x),l.push(e)}let u=new Map(t.rows.map(e=>[e.key,e]));for(let e of n.rows){if(e.hidden)continue;let t=r(`div`,{class:`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,u,n):this._drawBar(t,e,u,n),l.push(t)}l.push(this._deps(n)),this._card=o?null:this._details(n,u),e.append(...l);let d=e.querySelector(`[${B}^="${V}"]`);d instanceof HTMLElement&&(d.tabIndex=0)}_names(e,t){return(e.dependsOn??[]).map(e=>t.get(e)?.name??e).join(`, `)}_barSentence(e,t){let n=N(),r=this._names(e,t);if(e.end===void 0){let t=p(u(e.start??``));return r?S(n.milestoneBarLabel,{name:e.name,date:t,names:r}):`${e.name}, ${t}, ${n.milestoneLabel.toLowerCase()}`}let i=S(n.barLabel,{name:e.name,start:p(u(e.start??``)),end:p(u(e.end)),percent:Q(e),status:Z($(e)).toLowerCase()});return r?S(n.barLabelAfter,{label:i,names:r}):i}_focusable(e,t,n,i){let a=r(`button`,{class:t});a.type=`button`;let o=this._barSentence(e,n);return a.setAttribute(`aria-label`,o),a.title=o,a.tabIndex=-1,a.dataset.status=$(e),a.dataset.wuiGanttKey=e.key,a.setAttribute(B,`${V}${e.key}`),i?a.setAttribute(`aria-pressed`,String(this._selected===e.key)):a.setAttribute(`aria-expanded`,String(this._selected===e.key)),this._selected===e.key&&(a.dataset.selected=`true`),a}_afterLabel(e,t,n,i){let a=r(`span`,{class:`wui-gantt-label wui-gantt-label-surface`},e);return a.style.left=Y(t),a.style.top=Y(n),a.style.height=Y(i),a}_drawBar(e,t,n,i){let{row:a}=t,{geometry:o}=i,s=i.layout===`table`,c=this._focusable(a,`wui-gantt-bar rounded-2`,n,s),l=t.top+o.barTop;c.style.left=Y(t.x),c.style.width=Y(t.w),c.style.top=Y(l),c.style.height=Y(o.barH);let u=Q(a),d=r(`span`,{class:`wui-gantt-bar-progress`});if(d.style.width=`${u}%`,c.append(d),e.append(c),s)return;let f=`${a.name} ${u}%`;t.place===`inside`?c.append(r(`span`,{class:`wui-gantt-bar-label`},f)):e.append(this._afterLabel(f,t.x+t.w+G,l,o.barH))}_drawMilestone(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=f.milestone/2,c=t.top+(a.rowH-f.milestone)/2,l=this._focusable(i,`wui-gantt-milestone`,n,o);if(l.style.left=Y(t.x-s),l.style.top=Y(c),l.style.width=Y(f.milestone),l.style.height=Y(f.milestone),e.append(l),o)return;let d=this._afterLabel(`${i.name}, ${p(u(i.start??``))}`,t.x+f.milestone,t.top+a.barTop,a.barH);t.flip&&(d.style.left=``,d.style.right=Y(r.axis.width-(t.x-f.milestone))),e.append(d)}_drawGroup(e,t,n){let i=N(),a=t.group;if(!a)return;if(n.layout===`lanes`){let n=r(`div`,{class:`wui-gantt-group wui-gantt-label wui-gantt-label-surface`});n.dataset.wuiGanttGroup=a.name,n.style.left=Y(8),n.style.top=Y(t.top+6);let o=r(`button`,{class:`wui-gantt-group-toggle`});o.type=`button`,o.setAttribute(`aria-expanded`,String(!a.folded)),o.setAttribute(`aria-label`,S(a.folded?i.unfoldLabel:i.foldLabel,{group:a.name})),o.setAttribute(B,`group:${a.name}`);let s=y(a.folded?`chevron-right`:`chevron-down`,{size:16});o.replaceChildren(...s?[s]:[]),n.append(o,r(`span`,null,a.name),r(`span`,null,b(i,`groupSummary`,a.count,{percent:a.percent}))),e.append(n)}let o=r(`div`,{class:`wui-gantt-group-summary`});o.dataset.wuiGanttGroup=a.name,o.style.left=Y(t.x),o.style.width=Y(t.w),o.style.top=Y(t.top+n.geometry.groupBarTop),o.style.height=Y(f.groupBarH),e.append(o)}_deps(e){let t=document.createElementNS(H,`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(H,`path`);e.setAttribute(`d`,n.d),e.setAttribute(`fill`,`none`);let r=document.createElementNS(H,`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 i=this._selected,a=i===null?void 0:t.rows.find(e=>e.row.key===i&&e.kind!==`group`&&!e.hidden);if(!a)return null;let o=N(),{row:s}=a,c=r(`div`,{class:`wui-gantt-details`});c.setAttribute(`role`,`group`),c.setAttribute(`aria-label`,s.name),c.style.width=Y(K);let l=r(`dl`),d=(e,t)=>{l.append(r(`dt`,null,e),r(`dd`,null,t))},f=p(u(s.start??``));s.owner&&d(o.detailsOwner,s.owner),d(o.detailsDates,s.end===void 0?f:S(o.detailsRange,{start:f,end:p(u(s.end))})),s.end!==void 0&&d(o.detailsDone,`${Q(s)}%, ${Z($(s))}`);let m=this._names(s,n);m&&d(o.detailsStartsAfter,m);let h=r(`button`,{class:e(`neutral`,`ghost`,`sm`)},o.detailsCloseLabel);return h.type=`button`,h.setAttribute(B,`close`),c.append(r(`h3`,{class:`h6`},s.name),l,h),c}};export{te as t};
1
+ import{n as e}from"./buttonClass-C8BRtTk8.js";import{t}from"./devWarn-DXdRWZs3.js";import{i as n,r}from"./dom-DMQu--xV.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{a,c as o,d as s,f as c,i as l,l as u,m as d,n as f,o as p,p as m,s as h,t as g,u as _}from"./initials-Qb6ITcri.js";import{t as v}from"./avatarNode-BaEvz5Xr.js";import{t as y}from"./iconGlyphs.g-a9FtjPXh.js";import{n as b,r as x,t as S}from"./textStore-DBplASiZ.js";import{t as C}from"./hasOwn-CJsplJ62.js";import{a as w,l as T}from"./nativeOverlay-BHD2QV02.js";import{n as E,t as D}from"./rtl-g7G8Bsib.js";import{t as O}from"./gantt.g-TdTxeruW.js";var k=`data-wui-gantt-pick`,A=e=>`${e}px`,j=(e,t,n)=>{let i=r(`div`,{class:`wui-gantt-table-cell`},n);return i.setAttribute(`role`,t),i.dataset.col=e,i};function M(e){let t=e.text,n=r(`div`,{class:`wui-gantt-table`});n.setAttribute(`role`,`table`),n.setAttribute(`aria-label`,e.title);let i=r(`div`);i.setAttribute(`role`,`rowgroup`);let a=r(`div`,{class:`wui-gantt-table-row`});a.dataset.kind=`head`,a.setAttribute(`role`,`row`),a.style.height=A(e.headHeight),a.append(j(`name`,`columnheader`,t.tableName),j(`owner`,`columnheader`,t.detailsOwner),j(`start`,`columnheader`,t.tableStart),j(`end`,`columnheader`,t.tableEnd),j(`done`,`columnheader`,t.detailsDone)),i.append(a);let o=r(`div`);o.setAttribute(`role`,`rowgroup`);for(let n of e.rows){if(n.height===0)continue;let i=n.row;if(n.kind===`group`){let i=n.group;if(!i)continue;let a=r(`div`,{class:`wui-gantt-table-row`});a.dataset.kind=`group`,a.dataset.wuiGanttGroup=i.name,a.setAttribute(`role`,`row`),a.style.height=A(n.height);let s=r(`div`,{class:`wui-gantt-table-cell wui-gantt-table-group`});s.setAttribute(`role`,`rowheader`);let c=r(`button`,{class:`wui-gantt-group-toggle`});c.type=`button`,c.setAttribute(`aria-expanded`,String(!i.folded)),c.setAttribute(`aria-label`,S(i.folded?t.unfoldLabel:t.foldLabel,{group:i.name})),c.setAttribute(e.focusAttr,`group:${i.name}`);let l=y(i.folded?`chevron-right`:`chevron-down`,{size:16});c.replaceChildren(...l?[l]:[]),s.append(c,r(`span`,null,i.name),r(`span`,null,b(t,`groupSummary`,i.count,{percent:i.percent}))),a.append(s),o.append(a);continue}let a=r(`div`,{class:`wui-gantt-table-row`});a.dataset.kind=i.end===void 0?`milestone`:`bar`,a.dataset.wuiGanttKey=i.key,a.dataset.wuiGanttPick=i.key,i.key===e.selected&&(a.dataset.selected=`true`),a.setAttribute(`role`,`row`),a.style.height=A(n.height);let s=j(`name`,`rowheader`,i.name);s.title=i.name;let c=j(`owner`,`cell`,``);i.owner&&(c.title=i.owner,c.replaceChildren(...[v({initials:g(i.owner)},`avatar-xs`)].filter(e=>e!==null)),c.append(r(`span`,{class:`visually-hidden`},i.owner)));let l=j(`start`,`cell`,i.start===void 0?``:p(u(i.start))),d=j(`end`,`cell`,i.end===void 0?``:p(u(i.end))),f=j(`done`,`cell`,i.end===void 0?``:`${i.progress??0}%`);a.append(s,c,l,d,f),o.append(a)}let s=e.skeleton;for(let e=0;s&&e<s.rows;e+=1){let e=r(`div`,{class:`wui-gantt-table-row`});e.dataset.kind=`skeleton`,e.setAttribute(`role`,`row`),e.setAttribute(`aria-hidden`,`true`),e.style.height=A(s.rowHeight);let t=r(`span`,{class:`wui-gantt-skeleton`});t.style.height=A(s.barHeight),e.append(t),o.append(e)}return n.append(i,o),n}var N=()=>x(`gantt`,O),P=`wui-gantt:zoom-change`,F=`wui-gantt:from-change`,I=`wui-gantt:fold-change`,L=`wui-gantt:select`,R=`wui-gantt:add-task`,z=`wui-gantt:retry`,B=`data-wui-gantt-focus`,V=`bar:`,H=`http://www.w3.org/2000/svg`,U=[`day`,`week`,`month`],W=3,G=16,K=300,q=[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`,`Escape`,`Enter`,` `],J=0,Y=e=>`${e}px`;function X(e){return typeof e==`object`&&!!e&&`rows`in e&&Array.isArray(e.rows)&&`title`in e&&typeof e.title==`string`}function Z(e){let t=N();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 Q=e=>e.progress??0,$=e=>e.status??`notStarted`,ee=(e,t)=>(e??[]).join(`\0`)===(t??[]).join(`\0`),te=class extends i{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(),J+=1,this.uid=`wui-gantt-${J}`,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(C(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&&=(w(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?u(e.from):null),n(!ee(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(P,{zoom:e}),this._controlled?this._syncRadios():(this._zoom=e,this._fromMs=this._fromMs===null?null:s(e,this._fromMs),this._draw())}_setFrom(e){this._emit(F,{from:h(e)}),this._controlled||(this._fromMs=e,this._draw())}_setFolded(e){let t=new Set(this._folded);t.delete(e)||t.add(e),this._emit(I,{folded:[...t]}),this._controlled||(this._folded=t,this._draw())}_setSelected(e){this._emit(L,{key:e}),this._focusAfter=`${V}${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=U.find(e=>e===t.value);n&&this._setZoom(n)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[${B}]`);if(n instanceof HTMLElement&&this.contains(n)){this._activate(n.getAttribute(B)??``,n);return}let r=t.closest(`[${k}]`);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(V)){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(R):e===`retry`?this._emit(z):n&&e===`nav:earlier`?this._setFrom(_(n.zoom,n.fromMs,-1)):n&&e===`nav:later`?this._setFrom(_(n.zoom,n.fromMs,1)):n&&e===`nav:today`?this._setFrom(d(n.zoom,n.todayMs)):e.startsWith(`zoom:`)&&t.click()}_bars(){return[...this.querySelectorAll(`.wui-gantt-lane [${B}^="${V}"]`)].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||!q.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(B)?.startsWith(V))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(e.key,D(this))){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[n.length-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(B)??``,t)}}_focusToken(){let e=document.activeElement;return e instanceof HTMLElement&&this.contains(e)?e.getAttribute(B):null}_draw(){if(this._card&&=(w(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`,N().errorText)]}if(this.replaceChildren(...r),this._card){let e=n(this._barByKey(this._selected??void 0),`selected gantt bar`);this.append(this._card),T(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(`[${B}]`)].find(t=>t.getAttribute(B)===e);i instanceof HTMLElement&&(e.startsWith(V)?this._focusBar(i):i.focus())}_compose(){let e=this._spec;if(!X(e))throw TypeError("<wui-gantt> has no spec: set the `spec` property or add a JSON script child.");this._seed(e),m(e);let t=e.layout??`table`,n=l[t],i=N(),p=u(e.today??c()),h=this._zoom,g=s(h,this._fromMs??d(h,p)),_={layout:t,zoom:h,fromMs:g,todayMs:p};this._resolved=_,this._specRows=e.rows;let v=e.rows.some(e=>e.start!==void 0),y=(e.state??`ready`)===`ready`&&!v?`empty`:e.state??`ready`;this.dataset.state=y,this.dataset.zoom=h,this.dataset.layout=t,y===`loading`?this.setAttribute(`aria-busy`,`true`):this.removeAttribute(`aria-busy`);let b=y===`ready`?o({...e,folded:[...this._folded],selected:this._selected},_):null,x=b?.axis??a(t,h,g),S=r(`div`,{class:`wui-gantt-lane`});S.style.width=Y(x.width),b?this._fillLane(S,e,b):y===`loading`&&(S.style.height=Y(W*n.rowH));let C=[];y===`loading`&&C.push(this._fillSkeleton(S,e,n)),y===`empty`&&C.push(this._emptyBlock(e)),y===`error`&&C.push(this._stateBlock(`error`,e.errorText||i.errorText));let w=this._head(x),T=r(`div`,{class:`wui-gantt-plot`});T.append(w,S);let E=r(`div`,{class:`wui-gantt-scroller`});if(t===`table`){let t=M({title:e.title,rows:b?.rows??[],headHeight:2*f.tierH,selected:this._selected,text:i,focusAttr:B,skeleton:y===`loading`?{rows:W,rowHeight:n.rowH,barHeight:n.barH}:void 0});E.append(t,T)}else E.append(T);return[this._toolbar(e,y===`ready`),E,...C,this._legend(t)]}_toolbar(e,t){let n=r(`div`,{class:`wui-gantt-toolbar`});return t&&n.append(r(`p`,{class:`wui-gantt-count`},this._countText(e.rows))),n.append(this._scale(),this._nav()),n}_countText(e){let t=N(),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,u(e.start??``)),a=Math.max(a,u(e.end??e.start??``));return[b(t,`summaryTasks`,n.length-r),b(t,`summaryMilestones`,r),S(t.summaryRange,{from:p(i),to:p(a)})].join(`, `)}_scale(){let e=N(),t=r(`div`,{class:`segmented segmented-sm wui-gantt-scale`});t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-label`,e.scaleLabel),t.append(Object.assign(r(`span`,{class:`segmented-thumb`}),{ariaHidden:`true`}));let n={day:e.dayLabel,week:e.weekLabel,month:e.monthLabel};for(let e of U){let i=r(`label`,{class:`segmented-option`}),a=r(`input`,{class:`segmented-input`});a.type=`radio`,a.name=`${this.uid}-scale`,a.value=e,a.checked=e===this._zoom,a.setAttribute(B,`zoom:${e}`),i.append(a,n[e]),t.append(i)}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=Y(n.offsetWidth),t.style.transform=`translateX(${n.offsetLeft}px)`,t.style.opacity=`1`)}_nav(){let t=N(),n=r(`div`,{class:`wui-gantt-nav`}),i=(t,n,i)=>{let a=r(`button`,{class:e(`neutral`,`soft`,`sm`)});a.type=`button`,a.setAttribute(`aria-label`,n),a.setAttribute(B,t);let o=y(i,{size:16});return a.replaceChildren(...o?[o]:[]),a},a=r(`button`,{class:e(`neutral`,`soft`,`sm`)},t.todayLabel);return a.type=`button`,a.setAttribute(B,`nav:today`),n.append(i(`nav:earlier`,t.earlierLabel,`chevron-left`),i(`nav:later`,t.laterLabel,`chevron-right`),a),n}_head(e){let t=r(`div`,{class:`wui-gantt-head`});t.style.width=Y(e.width),t.setAttribute(`aria-hidden`,`true`);let n=(e,t)=>{let n=r(`div`,{class:`wui-gantt-tier ${t}`});for(let t of e){let e=r(`div`,{class:t.weekend?`wui-gantt-cell wui-gantt-cell-weekend`:`wui-gantt-cell`});e.style.left=Y(t.x),e.style.width=Y(t.w),t.sub&&e.append(r(`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=N(),n=r(`div`,{class:`wui-gantt-legend`});n.setAttribute(`role`,`list`),n.setAttribute(`aria-label`,t.legendLabel);let i=(e,t)=>{let i=r(`span`,null);i.setAttribute(`role`,`listitem`),i.append(e,t),n.append(i)};for(let e of[`done`,`inProgress`,`atRisk`,`notStarted`]){let t=r(`span`,{class:`wui-gantt-swatch`});t.dataset.status=e,i(t,Z(e))}let a=r(`span`,{class:`wui-gantt-swatch`});if(a.dataset.kind=`milestone`,i(a,t.milestoneLabel),e===`table`){let e=r(`span`,{class:`wui-gantt-legend-note`},t.legendRemaining);e.setAttribute(`role`,`listitem`),n.append(e)}return n}_stateBlock(t,n){let i=N(),a=r(`div`,{class:`wui-gantt-state`});if(t===`error`){a.setAttribute(`role`,`alert`),a.append(r(`p`,null,n));let t=r(`button`,{class:e(`neutral`,`soft`,`sm`)},i.retryLabel);t.type=`button`,t.setAttribute(B,`retry`),a.append(t)}else a.append(r(`p`,null,n));return a}_emptyBlock(t){let n=N(),i=r(`div`,{class:`wui-gantt-state`});if(i.append(r(`p`,{class:`fw-semibold`},n.emptyTitle),r(`p`,null,t.emptyText||n.emptyText)),t.addTask){let t=r(`button`,{class:e(`primary`,`solid`,`sm`)},n.addTaskLabel);t.type=`button`,t.setAttribute(B,`add`),i.append(t)}return i}_fillSkeleton(e,t,n){let i=r(`div`,{class:`visually-hidden`},t.loadingText||N().loadingText);i.setAttribute(`role`,`status`);for(let t=0;t<W;t+=1){let i=r(`div`,{class:`wui-gantt-skeleton`});i.style.top=Y(t*n.rowH+n.barTop),i.style.left=Y(40+t*60),i.style.width=Y(240),i.style.height=Y(n.barH),i.setAttribute(`aria-hidden`,`true`),e.append(i)}return i}_fillLane(e,t,n){let i=N(),{axis:a}=n,o=n.layout===`table`;e.style.height=Y(n.height),e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,t.title);let s=r(`p`,{class:`visually-hidden`},o?i.helpTextTable:i.helpText);s.id=`${this.uid}-help`,e.setAttribute(`aria-describedby`,s.id);let c=(e,t,n,i,a)=>{let o=r(`div`,{class:e});return o.setAttribute(`aria-hidden`,`true`),o.style.left=Y(t),o.style.top=Y(n),o.style.width=Y(i),o.style.height=Y(a),o},l=[s];for(let e of n.rows){if(e.height===0)continue;let t=c(`wui-gantt-row`,0,e.top,a.width,e.height);o&&e.kind!==`group`&&e.row.key===this._selected&&(t.dataset.selected=`true`),l.push(t)}for(let e of a.weekendX)l.push(c(`wui-gantt-weekend`,e,0,a.ppd,n.height));for(let e of a.gridX)l.push(c(`wui-gantt-grid`,e,0,1,n.height));if(n.today.inWindow){l.push(c(`wui-gantt-today`,n.today.x-1,0,2,n.height));let e=r(`div`,{class:`wui-gantt-today-flag rounded-pill`},i.todayLabel);e.style.left=Y(n.today.x),l.push(e)}let u=new Map(t.rows.map(e=>[e.key,e]));for(let e of n.rows){if(e.hidden)continue;let t=r(`div`,{class:`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,u,n):this._drawBar(t,e,u,n),l.push(t)}l.push(this._deps(n)),this._card=o?null:this._details(n,u),e.append(...l);let d=e.querySelector(`[${B}^="${V}"]`);d instanceof HTMLElement&&(d.tabIndex=0)}_names(e,t){return(e.dependsOn??[]).map(e=>t.get(e)?.name??e).join(`, `)}_barSentence(e,t){let n=N(),r=this._names(e,t);if(e.end===void 0){let t=p(u(e.start??``));return r?S(n.milestoneBarLabel,{name:e.name,date:t,names:r}):`${e.name}, ${t}, ${n.milestoneLabel.toLowerCase()}`}let i=S(n.barLabel,{name:e.name,start:p(u(e.start??``)),end:p(u(e.end)),percent:Q(e),status:Z($(e)).toLowerCase()});return r?S(n.barLabelAfter,{label:i,names:r}):i}_focusable(e,t,n,i){let a=r(`button`,{class:t});a.type=`button`;let o=this._barSentence(e,n);return a.setAttribute(`aria-label`,o),a.title=o,a.tabIndex=-1,a.dataset.status=$(e),a.dataset.wuiGanttKey=e.key,a.setAttribute(B,`${V}${e.key}`),i?a.setAttribute(`aria-pressed`,String(this._selected===e.key)):a.setAttribute(`aria-expanded`,String(this._selected===e.key)),this._selected===e.key&&(a.dataset.selected=`true`),a}_afterLabel(e,t,n,i){let a=r(`span`,{class:`wui-gantt-label wui-gantt-label-surface`},e);return a.style.left=Y(t),a.style.top=Y(n),a.style.height=Y(i),a}_drawBar(e,t,n,i){let{row:a}=t,{geometry:o}=i,s=i.layout===`table`,c=this._focusable(a,`wui-gantt-bar rounded-2`,n,s),l=t.top+o.barTop;c.style.left=Y(t.x),c.style.width=Y(t.w),c.style.top=Y(l),c.style.height=Y(o.barH);let u=Q(a),d=r(`span`,{class:`wui-gantt-bar-progress`});if(d.style.width=`${u}%`,c.append(d),e.append(c),s)return;let f=`${a.name} ${u}%`;t.place===`inside`?c.append(r(`span`,{class:`wui-gantt-bar-label`},f)):e.append(this._afterLabel(f,t.x+t.w+G,l,o.barH))}_drawMilestone(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=f.milestone/2,c=t.top+(a.rowH-f.milestone)/2,l=this._focusable(i,`wui-gantt-milestone`,n,o);if(l.style.left=Y(t.x-s),l.style.top=Y(c),l.style.width=Y(f.milestone),l.style.height=Y(f.milestone),e.append(l),o)return;let d=this._afterLabel(`${i.name}, ${p(u(i.start??``))}`,t.x+f.milestone,t.top+a.barTop,a.barH);t.flip&&(d.style.left=``,d.style.right=Y(r.axis.width-(t.x-f.milestone))),e.append(d)}_drawGroup(e,t,n){let i=N(),a=t.group;if(!a)return;if(n.layout===`lanes`){let n=r(`div`,{class:`wui-gantt-group wui-gantt-label wui-gantt-label-surface`});n.dataset.wuiGanttGroup=a.name,n.style.left=Y(8),n.style.top=Y(t.top+6);let o=r(`button`,{class:`wui-gantt-group-toggle`});o.type=`button`,o.setAttribute(`aria-expanded`,String(!a.folded)),o.setAttribute(`aria-label`,S(a.folded?i.unfoldLabel:i.foldLabel,{group:a.name})),o.setAttribute(B,`group:${a.name}`);let s=y(a.folded?`chevron-right`:`chevron-down`,{size:16});o.replaceChildren(...s?[s]:[]),n.append(o,r(`span`,null,a.name),r(`span`,null,b(i,`groupSummary`,a.count,{percent:a.percent}))),e.append(n)}let o=r(`div`,{class:`wui-gantt-group-summary`});o.dataset.wuiGanttGroup=a.name,o.style.left=Y(t.x),o.style.width=Y(t.w),o.style.top=Y(t.top+n.geometry.groupBarTop),o.style.height=Y(f.groupBarH),e.append(o)}_deps(e){let t=document.createElementNS(H,`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(H,`path`);e.setAttribute(`d`,n.d),e.setAttribute(`fill`,`none`);let r=document.createElementNS(H,`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 i=this._selected,a=i===null?void 0:t.rows.find(e=>e.row.key===i&&e.kind!==`group`&&!e.hidden);if(!a)return null;let o=N(),{row:s}=a,c=r(`div`,{class:`wui-gantt-details`});c.setAttribute(`role`,`group`),c.setAttribute(`aria-label`,s.name),c.style.width=Y(K);let l=r(`dl`),d=(e,t)=>{l.append(r(`dt`,null,e),r(`dd`,null,t))},f=p(u(s.start??``));s.owner&&d(o.detailsOwner,s.owner),d(o.detailsDates,s.end===void 0?f:S(o.detailsRange,{start:f,end:p(u(s.end))})),s.end!==void 0&&d(o.detailsDone,`${Q(s)}%, ${Z($(s))}`);let m=this._names(s,n);m&&d(o.detailsStartsAfter,m);let h=r(`button`,{class:e(`neutral`,`ghost`,`sm`)},o.detailsCloseLabel);return h.type=`button`,h.setAttribute(B,`close`),c.append(r(`h3`,{class:`h6`},s.name),l,h),c}};export{te as t};
@@ -1 +1 @@
1
- import{i as e}from"./calendarMath-CT99RyhR.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-DTW53DjY.js";import{t as o}from"./imeSafeEnter-DPs9qL3S.js";import{n as s,t as c}from"./inlineEditText-DRBhMnam.js";import{d as l}from"./wuiHttp-BWf9dDsZ.js";import{r as u,t as d}from"./textStore-DBplASiZ.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?{nodes:[...e.childNodes].map(e=>e.cloneNode(!0)),empty:e.hasAttribute(`data-wui-empty`)}:null}_restoreShown(e){let t=this.querySelector(g);t&&(t.replaceChildren(...e.nodes),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-CT99RyhR.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-DTW53DjY.js";import{n as o}from"./imeSafeEnter-DeO_3lXy.js";import{n as s,t as c}from"./inlineEditText-DRBhMnam.js";import{d as l}from"./wuiHttp-BWf9dDsZ.js";import{r as u,t as d}from"./textStore-DBplASiZ.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?{nodes:[...e.childNodes].map(e=>e.cloneNode(!0)),empty:e.hasAttribute(`data-wui-empty`)}:null}_restoreShown(e){let t=this.querySelector(g);t&&(t.replaceChildren(...e.nodes),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};