@webority/ui-elements 0.170.1 → 0.171.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{WuiCodeBlock-DTckR_z3.js → WuiCodeBlock-Du-JZO3A.js} +1 -1
- package/dist/{WuiCommandPalette-CSzl5yGf.js → WuiCommandPalette-BKW0e-ho.js} +1 -1
- package/dist/{WuiCommentThread-RB100aB1.js → WuiCommentThread-DZEYOHsk.js} +1 -1
- package/dist/{WuiContextMenu-ClMVFeos.js → WuiContextMenu-DvYwIicr.js} +1 -1
- package/dist/{WuiDatePicker-u0oZ6fJj.js → WuiDatePicker-DxPethoe.js} +1 -1
- package/dist/{WuiDateRange-CtWUcQ-g.js → WuiDateRange-zPmNewOW.js} +1 -1
- package/dist/{WuiDrawer-n8WlVPq_.js → WuiDrawer-BMkPnEFz.js} +1 -1
- package/dist/{WuiDropdown-D2jEbCfv.js → WuiDropdown-B9WeT-gH.js} +1 -1
- package/dist/{WuiGantt-BsQUCR2U.js → WuiGantt-DaEgtdOU.js} +1 -1
- package/dist/{WuiHoverCard-DmApQa9R.js → WuiHoverCard-D6JBAqdW.js} +1 -1
- package/dist/{WuiLightbox-cm5eHcMK.js → WuiLightbox-BnLEEkj1.js} +1 -1
- package/dist/{WuiMentionInput-D7HC7U2Q.js → WuiMentionInput-DvKw8MXS.js} +1 -1
- package/dist/{WuiModal-DuBerYTv.js → WuiModal-DMGgOCBU.js} +1 -1
- package/dist/{WuiNavigationMenu-VG-ZJstT.js → WuiNavigationMenu-CfD0FWvt.js} +1 -1
- package/dist/{WuiNotificationCenter-hluDIzO8.js → WuiNotificationCenter-DgcJYPV3.js} +1 -1
- package/dist/{WuiPhone-C03OuI7-.js → WuiPhone-BFb_LjJa.js} +1 -1
- package/dist/{WuiPopover-BxQj74kE.js → WuiPopover-BYO_H-fk.js} +1 -1
- package/dist/{WuiSelect-DpZbgU4v.js → WuiSelect-iE3EVUWK.js} +1 -1
- package/dist/{WuiShortcuts-CSFOyAKI.js → WuiShortcuts-Crj8lFVz.js} +1 -1
- package/dist/WuiTimePicker-BsnPOYNw.js +9 -0
- package/dist/{WuiTour-Beop0n-H.js → WuiTour-C2CRQvS7.js} +1 -1
- package/dist/{WuiTree-DGclk55_.js → WuiTree-DGZSXgBh.js} +1 -1
- package/dist/{WuiTreePicker-CBhasmC5.js → WuiTreePicker-CkTfNUQx.js} +1 -1
- package/dist/{WuiWhatsNew-BtWJkzTv.js → WuiWhatsNew-DjnQWqlF.js} +1 -1
- package/dist/{WuiWizardStep-Ce6O_8oc.js → WuiWizardStep-CryQ5BlK.js} +1 -1
- package/dist/{avatarHtml-BtbN7cA5.js → avatarHtml-BWlA0cm-.js} +1 -1
- package/dist/{chips-IbfKMhVk.js → chips-B4ZNRO-h.js} +1 -1
- package/dist/drawerDiscard-B4OcoR8S.js +1 -0
- package/dist/elements/code-block.js +1 -1
- package/dist/elements/command-palette.js +1 -1
- package/dist/elements/comment-thread.js +1 -1
- package/dist/elements/context-menu.js +1 -1
- package/dist/elements/date-range.js +1 -1
- package/dist/elements/datepicker.js +1 -1
- package/dist/elements/drawer.js +1 -1
- package/dist/elements/dropdown.js +1 -1
- package/dist/elements/filter-popover.js +1 -1
- package/dist/elements/gantt.js +1 -1
- package/dist/elements/hover-card.js +1 -1
- package/dist/elements/lightbox.js +1 -1
- package/dist/elements/mention-input.js +1 -1
- package/dist/elements/modal.js +1 -1
- package/dist/elements/navigation-menu.js +1 -1
- package/dist/elements/notification-center.js +1 -1
- package/dist/elements/phone.js +1 -1
- package/dist/elements/popover.js +1 -1
- package/dist/elements/select.js +1 -1
- package/dist/elements/shortcuts.js +1 -1
- package/dist/elements/timepicker.js +1 -1
- package/dist/elements/tour.js +1 -1
- package/dist/elements/tree-picker.js +1 -1
- package/dist/elements/tree.js +1 -1
- package/dist/elements/whats-new.js +1 -1
- package/dist/elements/wizard.js +1 -1
- package/dist/fileViewer.g-D5lbrn8g.js +1 -0
- package/dist/{fileViewerImage-DT0a9KaL.js → fileViewerImage-uL9m83k1.js} +1 -1
- package/dist/{fileViewerMedia-BFNxdaYX.js → fileViewerMedia-cfmycjzl.js} +1 -1
- package/dist/{fileViewerPdf-Boo6uXQO.js → fileViewerPdf-BsSc-9fL.js} +1 -1
- package/dist/{filterPopover-BVBxgtc5.js → filterPopover-C_oDfQBg.js} +1 -1
- package/dist/helpers.js +1 -1
- package/dist/iconGlyphs.g-BUF97bUu.js +1 -0
- package/dist/nativeOverlay-DGady-wN.js +1 -0
- package/dist/{optionLabel-B2cU4Ax0.js → optionLabel-CWMhBkdO.js} +1 -1
- package/dist/{search-BVox4aaA.js → search-w5M6FzD9.js} +1 -1
- package/dist/server.js +1 -1
- package/dist/text/en.json +1 -0
- package/dist/text.js +1 -1
- package/dist/{themeTransition-CDB0Mx61.js → themeTransition-CA1qzCZk.js} +1 -1
- package/dist/timePicker.g-IEczeE48.js +1 -0
- package/dist/ui-elements/carousel.global.js +1 -1
- package/dist/ui-elements/code-block.global.js +1 -1
- package/dist/ui-elements/command-palette.global.js +1 -1
- package/dist/ui-elements/comment-thread.global.js +1 -1
- package/dist/ui-elements/consent-banner.global.js +1 -1
- package/dist/ui-elements/context-menu.global.js +1 -1
- package/dist/ui-elements/date-range.global.js +1 -1
- package/dist/ui-elements/drawer.global.js +1 -1
- package/dist/ui-elements/dropdown.global.js +1 -1
- package/dist/ui-elements/entry-grid.global.js +1 -1
- package/dist/ui-elements/gantt.global.js +1 -1
- package/dist/ui-elements/glyphs.global.js +1 -1
- package/dist/ui-elements/image-crop.global.js +1 -1
- package/dist/ui-elements/inline-edit.global.js +1 -1
- package/dist/ui-elements/kanban.global.js +1 -1
- package/dist/ui-elements/lead-popup.global.js +1 -1
- package/dist/ui-elements/lightbox.global.js +1 -1
- package/dist/ui-elements/markdown.global.js +1 -1
- package/dist/ui-elements/org-tree.global.js +1 -1
- package/dist/ui-elements/phone.global.js +1 -1
- package/dist/ui-elements/popover.global.js +1 -1
- package/dist/ui-elements/saved-views.global.js +1 -1
- package/dist/ui-elements/select-chips.global.js +1 -1
- package/dist/ui-elements/select-recents.global.js +1 -1
- package/dist/ui-elements/select-search.global.js +1 -1
- package/dist/ui-elements/select-window.global.js +1 -1
- package/dist/ui-elements/slider.global.js +1 -1
- package/dist/ui-elements/sortable.global.js +1 -1
- package/dist/ui-elements/status-icon.global.js +1 -1
- package/dist/ui-elements/timepicker.global.js +6 -6
- package/dist/ui-elements/tour.global.js +1 -1
- package/dist/ui-elements/tree-picker.global.js +1 -1
- package/dist/ui-elements/tree.global.js +1 -1
- package/dist/ui-elements/wizard.global.js +1 -1
- package/dist/ui-elements.global.js +8 -8
- package/dist/ui-elements.js +1 -1
- package/dist/ui-file-viewer.global.js +1 -1
- package/dist/ui-file-viewer.js +1 -1
- package/package.json +5 -5
- package/types/WuiTimePicker.d.ts +3 -1
- package/types/nativeOverlay.d.ts +1 -1
- package/types/server/remoteModal.d.ts +6 -2
- package/types/text/web/timePicker.g.d.ts +1 -0
- package/dist/WuiTimePicker-BxcImgm1.js +0 -9
- package/dist/drawerDiscard-CM6a_8-l.js +0 -1
- package/dist/fileViewer.g-DQ-YkF8l.js +0 -1
- package/dist/iconGlyphs.g-DxSJLQJ8.js +0 -1
- package/dist/nativeOverlay-D3VmY8qn.js +0 -1
- package/dist/timePicker.g-DM61i-ZE.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{n,t as r}from"./copyText-Q-QZKBmx.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{t as a}from"./iconGlyphs.g-
|
|
1
|
+
import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{n,t as r}from"./copyText-Q-QZKBmx.js";import{t as i}from"./elementBase-Cxeyx0tU.js";import{t as a}from"./iconGlyphs.g-BUF97bUu.js";import{r as o}from"./textStore-opIEM4lu.js";import{t as s}from"./codeBlock.g-BCF2IlK-.js";Object.freeze([`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`razor`,`css`]);var c=Object.freeze({text:``,json:`JSON`,js:`JavaScript`,cs:`C#`,sql:`SQL`,bash:`Bash`,http:`HTTP`,html:`HTML`,razor:`Razor`,css:`CSS`}),l=e=>RegExp(`\\b(?:${e.join(`|`)})\\b`),u=`(?![\\s\\S])`,d=RegExp(`/\\*[\\s\\S]*?(?:\\*/|${u})`).source,f=[[`attr`,/"(?:[^"\\\n]|\\.)*"(?=\s*:)/],[`string`,/"(?:[^"\\\n]|\\.)*"?/],[`number`,/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/],[`literal`,l([`true`,`false`,`null`])],[`punct`,/[{}[\],:]/]],p=[[`comment`,RegExp(`//[^\\n]*|${d}`)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?/],[`number`,/\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?n?)\b/],[`keyword`,l(/* @__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`,l([`true`,`false`,`null`,`undefined`,`NaN`,`Infinity`])],[`function`,/(?<![\w$])[A-Za-z_$][\w$]*(?=\s*\()/],[`type`,/(?<![\w$])[A-Z][\w$]*/],[`punct`,/[{}()[\];,]/]],m=[[`comment`,RegExp(`//[^\\n]*|${d}`)],[`string`,/@"(?:[^"]|"")*"?|\$@?"(?:[^"\\\n]|\\.)*"?|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`number`,/\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?[fFdDmMlLuU]{0,2}\b/],[`keyword`,l(/* @__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`,l([`true`,`false`,`null`])],[`function`,/(?<!\w)[A-Za-z_]\w*(?=\s*\()/],[`type`,/(?<!\w)[A-Z]\w*/],[`punct`,/[{}()[\];,]/]],h=[[`comment`,RegExp(`--[^\\n]*|${d}`)],[`string`,/'(?:[^']|'')*'?/],[`variable`,/@@?\w+/],[`number`,/\b\d+(?:\.\d+)?\b/],[`keyword`,l(/* @__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`,l([`true`,`false`])],[`type`,l([`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`,/[(),;]/]],g=[[`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`,l([`case`,`do`,`done`,`elif`,`else`,`esac`,`exit`,`export`,`fi`,`for`,`function`,`if`,`in`,`local`,`return`,`select`,`then`,`until`,`while`])],[`function`,l(/* @__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`,/[|&;<>(){}[\]]+/]],_=[[`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]],v=[[`comment`,RegExp(`<!--[\\s\\S]*?(?:-->|${u})`)],[`keyword`,/<![A-Za-z][^>]*>?/],[`tag`,/<\/?[A-Za-z][^<>]*>?/],[`literal`,/&#?\w+;/]],y={json:f,js:p,cs:m,sql:h,bash:g,http:_,css:[[`comment`,new RegExp(d)],[`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:v,htmlTag:[[`tag`,/^<\/?[\w:.-]+/],[`string`,/"[^"]*"?|'[^']*'?/],[`attr`,/(?<=\s)[^\s=<>/"']+/],[`punct`,/\/?>|=/]]},b=e=>Object.hasOwn(y,e),x=/* @__PURE__ */ new Map;function S(e){let t=x.get(e);if(!t){let n=y[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)},x.set(e,t)}return t}function C(e,t,n){if(!n)return;let r=e[e.length-1];r&&r[0]===t?r[1]+=n:e.push([t,n])}function w(e,t,n=[]){let{re:r,types:i}=S(e),a=0;for(let o of t.matchAll(r)){let r=o[0];if(!r)continue;C(n,`plain`,t.slice(a,o.index));let s=i.findIndex((e,t)=>o[t+1]!==void 0);e===`html`&&i[s]===`tag`?w(`htmlTag`,r,n):C(n,i[s]??`plain`,r),a=o.index+r.length}return C(n,`plain`,t.slice(a)),n}function T(e){let t=/\r?\n\r?\n/.exec(e);if(!t)return w(`http`,e);let n=t[0]??``,r=w(`http`,e.slice(0,t.index+n.length)),i=e.slice(t.index+n.length),a=i.trimStart()[0];return a===`{`||a===`[`?w(`json`,i,r):a===`<`?w(`html`,i,r):(C(r,`plain`,i),r)}function E(e,t){let n=String(e??``);if(!n||n.length>1e5)return n?[[`plain`,n]]:[];if(t===`http`)return T(n);let r=t===`razor`?`html`:t;return!b(r)||r===`htmlTag`?[[`plain`,n]]:w(r,n)}function D(e,t){let n=[],r=[n];for(let[i,a]of E(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 O=()=>o(`codeBlock`,s);function k(e){return Object.hasOwn(c,e)}var A=class extends i{_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&&k(t)?t:`text`,r=this.getAttribute(`label`)||``,i=D(this._code(),n);this._title.textContent=r||c[n],this._view.setAttribute(`aria-label`,r||O().label),this._view.style.setProperty(`--wui-code-digits`,String(String(i.length).length)),this._codeEl.replaceChildren(...i.map(t=>j(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(i){let a=i.createElement(`div`);a.className=`wui-code-bar`;let o=i.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 n(this._code())&&(this._setCopied(!0),clearTimeout(this._timer),this._timer=window.setTimeout(()=>this._setCopied(!1),r))}),a.append(this._title,o),a}_setCopied(e){this._copied=e,this._copyIcon.innerHTML=a(e?`check`:`files`,{size:14}),this._copyText.textContent=this._copyLabel()}_copyLabel(){return this._copied?this.getAttribute(`copied-label`)||O().copiedLabel:this.getAttribute(`copy-label`)||O().copyLabel}};function j(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{A as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./optionLabel-
|
|
1
|
+
import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t}from"./optionLabel-CWMhBkdO.js";import{r as n}from"./textStore-opIEM4lu.js";import{t as r}from"./commandPalette.g-DFWnCufa.js";import{t as i}from"./textMatch-wdY7XLIc.js";var a=`[role="option"]`,o=()=>n(`commandPalette`,r),s=5,c=20,l=`.wui-cmd-back, [data-depth]`,u=`[data-group-tab]`,d=0;function f(e,t){if(!(e instanceof Element))return null;let n=e.closest(t);return n instanceof HTMLElement?n:null}var p=(e,t,n)=>{let r=e.querySelector(t);return r instanceof n?r:null},m=(e,t,n)=>[...e.querySelectorAll(t)].filter(e=>e instanceof n),h=class extends e{_path;_group;_crumbSig;_modal;_recentsId;_onModalClosed;_activeId;_lastQuery;_lastIds;_userChose;_onKeyDown;_onClick;_onMouseDown;_onMouseMove;_onInput;static get observedAttributes(){return[`filter`,`group-filter`,`highlight`,`empty-text`,`path`,`root-label`,`recents-key`,`recents-limit`,`recents-label`]}constructor(){super(),this._path=[],this._group=null,this._crumbSig=null,this._modal=null,this._recentsId=`wui-cmd-recents-${++d}`,this._onModalClosed=()=>{this._setKeyboard(!1),this._reset(),this.hasAttribute(`path`)&&this._restart()},this._activeId=null,this._lastQuery=null,this._lastIds=null,this._userChose=!1,this._onKeyDown=e=>this._handleKeyDown(e),this._onClick=e=>{let t=f(e.target,l);if(t&&this.contains(t)){let e=t.matches(`.wui-cmd-back`)?this._path.length-1:Number(t.dataset.depth);this._goTo(this._path.slice(0,e));return}let n=f(e.target,u);if(n&&this.contains(n)){this._pickGroup(n.dataset.groupTab||null);return}let r=this._optionFrom(e.target);r&&this._select(r)},this._onMouseDown=e=>{let t=f(e.target,l),n=f(e.target,u);(t&&this.contains(t)||n&&this.contains(n)||this._optionFrom(e.target,!0))&&e.preventDefault()},this._onMouseMove=e=>{let t=this._optionFrom(e.target);t&&t.id!==this._activeId&&(this._setKeyboard(!1),this._userChose=!0,this._setActive(t,!1))},this._onInput=e=>{this.hasAttribute(`filter`)&&e.target===this._input()&&(this._group=null,this._applyFilter(),this.refresh())}}connectedCallback(){this._teardown(),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`click`,this._onClick),this.addEventListener(`mousedown`,this._onMouseDown),this.addEventListener(`mousemove`,this._onMouseMove),this.addEventListener(`input`,this._onInput),this._modal=this.closest(`wui-modal`),this._modal?.addEventListener(`wui-modal-closed`,this._onModalClosed),this._readPath(),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){this.isConnected&&(e===`path`&&this._readPath(),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh())}get filter(){return this.hasAttribute(`filter`)}set filter(e){this.toggleAttribute(`filter`,!!e)}get highlight(){return this.getAttribute(`highlight`)!==`false`}set highlight(e){this.setAttribute(`highlight`,e?`true`:`false`)}get emptyText(){return this.getAttribute(`empty-text`)??o().emptyText}set emptyText(e){this.setAttribute(`empty-text`,String(e??``))}refresh(){this._renderRecents(),this._renderCrumbs(),this._syncTabs();let e=this._input(),t=e?e.value:``,n=t!==this._lastQuery;this._lastQuery=t;let r=this._selectableOptions(),i=r.map(e=>e.id).join(`
|
|
2
2
|
`),a=i!==this._lastIds;this._lastIds=i;let o=!n&&(this._userChose||!a)?r.find(e=>e.id===this._activeId):null;o||(this._userChose=!1,this._setKeyboard(!1)),this._setActive(o??r[0]??null,n)}_input(){let e=this.querySelector(`[role="combobox"]`);return e instanceof HTMLInputElement?e:null}_optionFrom(e,t=!1){let n=f(e,a);return n&&this.contains(n)&&!this._isHidden(n)&&(t||!this._isDisabled(n))?n:null}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_isHidden(e){return e.hidden!==!1||(f(e,`[role="group"]`)?.hidden??!1)!==!1}_selectableOptions(){return m(this,a,HTMLElement).filter(e=>!this._isHidden(e)&&!this._isDisabled(e))}_setActive(e,t){this._activeId=e?e.id:null;for(let t of m(this,a,HTMLElement))t.setAttribute(`aria-selected`,t===e?`true`:`false`);let n=this._input();n&&(e?n.setAttribute(`aria-activedescendant`,e.id):n.removeAttribute(`aria-activedescendant`)),e&&t&&e.scrollIntoView({block:`nearest`})}_move(e){let t=this._selectableOptions();if(!t.length)return;let n=t.findIndex(e=>e.id===this._activeId),r=n<0?e>0?0:t.length-1:(n+e+t.length)%t.length;this._userChose=!0,this._setKeyboard(!0),this._setActive(t[r]??null,!0)}_setKeyboard(e){this.toggleAttribute(`data-keyboard`,e)}_handleKeyDown(e){let t=this._input();if(t&&e.target===t){if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),this._move(e.key===`ArrowDown`?1:-1);else if(e.key===`Tab`&&this._groupActive()&&this._tabs().length)e.preventDefault(),this._cycleGroup(e.shiftKey?-1:1);else if(e.key===`Backspace`&&!e.isComposing&&this._path.length&&!t.value)e.preventDefault(),this._goTo(this._path.slice(0,-1));else if(e.key===`Enter`&&!e.isComposing){let t=this._selectableOptions().find(e=>e.id===this._activeId);if(!t)return;e.preventDefault(),this._select(t)}}}_select(e){this._remember(e),this.dispatchEvent(new CustomEvent(`wui-command-palette:select`,{bubbles:!0,cancelable:!0,detail:{key:e.dataset.key??null,groupKey:e.dataset.groupKey??null,id:e.id}}))&&(e.dataset.opens?this._open(e.dataset.opens):e.dataset.href&&this._navigate(e.dataset.href))}_open(e){let t=m(this,`.wui-cmd-page`,HTMLElement).find(t=>t.dataset.page===e);this._goTo([...this._path,{key:e,label:t?.dataset.label??e}])}_goTo(e){this._input()?.focus(),this.dispatchEvent(new CustomEvent(`wui-command-palette:navigate`,{bubbles:!0,cancelable:!0,detail:{path:e}}))&&(this._path=e,this._restart())}_tabs(){return m(this,u,HTMLElement)}_groupActive(){return this.hasAttribute(`group-filter`)&&this._path.length===0}_pickGroup(e){this._group=e,this._applyFilter(),this.refresh()}_cycleGroup(e){let t=this._tabs().map(e=>e.dataset.groupTab||null),n=Math.max(0,t.indexOf(this._group));this._pickGroup(t[(n+e+t.length)%t.length]??null)}_syncTabs(){if(!this.hasAttribute(`group-filter`))return;let e=p(this,`.wui-cmd-tabs`,HTMLElement);e&&(e.hidden=!this._groupActive());for(let e of this._tabs())e.setAttribute(`aria-selected`,String((e.dataset.groupTab||null)===this._group))}_restart(){this._group=null;let e=this._input();e&&(e.value=``),this.hasAttribute(`filter`)&&this._applyFilter(),this.refresh()}_reset(){this.hasAttribute(`path`)||(this._path=[],this._restart())}_readPath(){let e=this.getAttribute(`path`);if(e==null)return;let t=JSON.parse(e);this._path=Array.isArray(t)?t.filter(e=>e&&typeof e.key==`string`&&typeof e.label==`string`):[]}_renderCrumbs(){let e=p(this,`.wui-cmd-crumbs`,HTMLElement);if(!e)return;let t=this.getAttribute(`root-label`)??o().rootLabel,n=JSON.stringify([t,this._path]);if(e.hidden=this._path.length===0,n===this._crumbSig)return;this._crumbSig=n;let r=p(e,`.wui-cmd-trail`,HTMLElement);if(!r)return;let i=[t,...this._path.map(e=>e.label)];r.replaceChildren(...i.map((e,t)=>{let n=document.createElement(`li`),r=t===i.length-1,a=document.createElement(r?`span`:`button`);if(a.className=`wui-cmd-crumb`,a.textContent=e,r)a.setAttribute(`aria-current`,`page`);else{if(!(a instanceof HTMLButtonElement))throw Error(`breadcrumb button missing`);a.type=`button`,a.dataset.depth=String(t)}return n.append(a),n}))}_recentsHost(){return p(this,`.wui-cmd-recents`,HTMLElement)}_realOptions(){let e=this._recentsHost();return m(this,a,HTMLElement).filter(t=>!e?.contains(t))}_recentEntries(){let e=this.getAttribute(`recents-key`);if(!e)return[];let t;try{t=JSON.parse(globalThis.localStorage?.getItem(e)??`[]`)}catch{return[]}return Array.isArray(t)?t.filter(e=>e&&typeof e.g==`string`&&typeof e.k==`string`):[]}_recentsLimit(){let e=Number.parseInt(this.getAttribute(`recents-limit`)??``,10);return Number.isFinite(e)&&e>0?Math.min(e,c):s}_remember(e){let t=this.getAttribute(`recents-key`),{groupKey:n,key:r,opens:i}=e.dataset;if(!t||i||n==null||r==null)return;let a=[{g:n,k:r},...this._recentEntries().filter(e=>e.g!==n||e.k!==r)];try{globalThis.localStorage?.setItem(t,JSON.stringify(a.slice(0,this._recentsLimit())))}catch(e){if(!(e instanceof DOMException))throw e}}_renderRecents(){let e=this._recentsHost();if(!e)return;let t=this._input(),n=this._groupActive()?this._group:null,r=this._path.length===0&&!(t?.value??``).trim()?this._recentEntries().filter(e=>!n||e.g===n):[],i=this._realOptions(),a=[];for(let e of r){let t=i.find(t=>t.dataset.groupKey===e.g&&t.dataset.key===e.k);if(t&&!t.dataset.opens&&!this._isDisabled(t)&&a.push(t),a.length>=this._recentsLimit())break}if(!a.length){e.firstChild&&e.replaceChildren();return}let s=`${this._recentsId}-label`,c=document.createElement(`div`);c.className=`wui-cmd-group`,c.setAttribute(`role`,`group`),c.setAttribute(`aria-labelledby`,s);let l=document.createElement(`div`);l.className=`wui-cmd-group-label`,l.setAttribute(`role`,`presentation`),l.id=s,l.textContent=this.getAttribute(`recents-label`)??o().recentsLabel,c.append(l);for(let e of a){let t=e.cloneNode(!0);if(!(t instanceof HTMLElement))throw Error(`recent option copy is not an element`);t.id=`${this._recentsId}-${e.id}`,t.hidden=!1,t.removeAttribute(`aria-selected`),c.append(t)}e.replaceChildren(c)}_inScope(e,t){return!t||(f(e,`.wui-cmd-page`)?.dataset.page??null)===(this._path.at(-1)?.key??null)}_navigate(e){window.location.assign(e)}_applyFilter(){let e=this._input(),n=(e?e.value:``).trim(),r=n.toLowerCase(),o=this.highlight,s=m(this,`.wui-cmd-page`,HTMLElement),c=s.length>0,l=this._path.at(-1)?.key??null;for(let e of s)e.hidden=e.dataset.page!==l;let u=this._groupActive()?this._group:null,d=0;for(let e of this._realOptions()){let a=p(e,`.wui-cmd-item-label`,HTMLElement),s=e.dataset.label??a?.textContent??``,l=(e.dataset.keywords??``).split(/\s+/).filter(Boolean),f=!r||s.toLowerCase().includes(r)||l.some(e=>e.toLowerCase().includes(r)),m=this._inScope(e,c)&&(!u||e.dataset.groupKey===u)&&f;e.hidden=!m,m&&d++,a&&(a.innerHTML=i(s,o?n:``).map(e=>e.match?`<mark class="wui-cmd-mark">${t(e.text)}</mark>`:t(e.text)).join(``))}let f=this._recentsHost();for(let e of m(this,`[role="group"]`,HTMLElement))f?.contains(e)||(e.hidden=!m(e,a,HTMLElement).some(e=>!e.hidden));let h=p(this,`[role="listbox"]`,HTMLElement);h&&(h.hidden=d===0);let g=p(this,`.wui-cmd-empty`,HTMLElement);g&&(g.textContent=r&&d===0?this.emptyText:``)}_teardown(){this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`mousedown`,this._onMouseDown),this.removeEventListener(`mousemove`,this._onMouseMove),this.removeEventListener(`input`,this._onInput),this._modal?.removeEventListener(`wui-modal-closed`,this._onModalClosed),this._modal=null}};export{h as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{n}from"./commentText-NWsssKvj.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,l as a,s as o}from"./nativeOverlay-D3VmY8qn.js";import{l as s}from"./wuiHttp-DGbD7Fra.js";import{r as c,t as l}from"./textStore-opIEM4lu.js";import{n as u,t as d}from"./httpFailure.g-DBKzEpAf.js";import{r as f}from"./WuiMentionInput-D7HC7U2Q.js";var p=`[data-wui-items]`,m=`[data-wui-picker]`,h=`[data-wui-composer]`,g=`[data-wui-comment]`,_=`[data-wui-live]`,v=()=>c(`commentThread`,u),y=e=>({forbidden:v().forbiddenMessage,client:v().failedClientMessage,validation:v().validationMessage,server:v().failedServerMessage,network:c(`httpFailure`,d).networkText})[e],b=e=>({post:v().donePostText,reply:v().doneReplyText,edit:v().doneEditText,delete:v().doneDeleteText,react:``})[e],x=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:v().failedServerMessage},S=e=>e instanceof Element?e:null,C=e=>`disabled`in e&&e.disabled===!0,w=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},T=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},E=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},D=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],O=class extends r{_wired;_busy;_peopleProp;_pickerFor;_openers;constructor(){super(),this._wired=!1,this._busy=!1,this._peopleProp=null,this._pickerFor=null,this._onClick=this._onClick.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onSubmitKey=this._onSubmitKey.bind(this)}connectedCallback(){if(Object.hasOwn(this,`people`)){let e=this.people;Reflect.deleteProperty(this,`people`),this.people=e}if(this._wired)return;this._wired=!0,this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`wui:mention-input:submit`,this._onSubmitKey),customElements.upgrade(this);let e=T(this,`${h} wui-mention-input`,f);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:D(this,`:scope > [data-wui-people] > wui-option`,HTMLElement).map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0}))}set people(e){this._peopleProp=Array.isArray(e)?e:[];for(let e of this.querySelectorAll(`wui-mention-input`))e.people=this._peopleProp}_handPeople(e){!e||this.hasAttribute(`remote`)||this.hasAttribute(`source`)||(e.people=this.people)}_applyComposerPlaceholder(e){let t=this.getAttribute(`composer-placeholder`);e&&t!=null&&e.setAttribute(`placeholder`,t)}_reactionChoices(){let e=this.getAttribute(`reaction-choices`),t=e?e.split(/\s+/).filter(Boolean):[];return t.length?t:n}_onClick(e){let t=E(S(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!C(t)){let e=t.closest(m),n=e?this._pickerFor?.comment:t.closest(g);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=E(S(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||C(n))return;let r=n.closest(g);switch(n.getAttribute(`data-wui-action`)){case`reply`:this._openReply(r,n);break;case`edit`:this._openEditor(r,n);break;case`delete`:this._askDelete(r);break;case`cancel-delete`:this._closeConfirm(r,!0);break;case`confirm-delete`:{let e=w(r,`comment`);this._send(`delete`,{commentId:e.getAttribute(`data-wui-comment`)},{comment:e,scope:e});break}case`react-menu`:this._pickerFor?.button===n?this._closePicker(!0):this._openPicker(r,n);break;case`cancel`:this._closeSlot(E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=T(this,m,HTMLElement),n=S(e.target);if(this._pickerFor&&t?.contains(n)){let r=D(t,`[data-wui-emoji]`,HTMLElement),i=n instanceof HTMLElement?r.indexOf(n):-1;e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closePicker(!0)):e.key===`ArrowRight`||e.key===`ArrowLeft`?(e.preventDefault(),r[(i+(e.key===`ArrowRight`?1:-1)+r.length)%r.length]?.focus()):e.key===`Tab`&&this._closePicker(!1);return}if(e.key!==`Escape`)return;let r=E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=E(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(g),!0))}_onSubmitKey(e){let t=T(E(S(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!C(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=T(e,`:scope > [data-wui-reply]`,HTMLElement);if(!n)return;if(!n.hidden){n.querySelector(`wui-mention-input`)?.focus();return}let r=e?.querySelector(`.wui-comment-author`)?.textContent?.trim()||``;this._fillSlot(n,{label:l(v().replyToText,{author:r}),placeholder:v().replyPlaceholder,value:``,send:v().replyLabel,opener:t})}_openEditor(e,t){let n=T(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=T(w(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:v().editCommentLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:v().saveLabel,opener:t})}_fillSlot(e,{label:t,placeholder:n,value:r,send:i,opener:a}){let o=this.ownerDocument,s=o.createElement(`wui-mention-input`);s.className=`wui-mention-input`,s.setAttribute(`label`,t),n&&s.setAttribute(`placeholder`,n),s.setAttribute(`rows`,`2`),s.setAttribute(`value`,r);for(let e of[`remote`,`source`,`min-chars`,`debounce`]){let t=this.getAttribute(e);t!=null&&s.setAttribute(e,t)}let c=o.createElement(`div`);c.className=`wui-comment-form-actions`,c.append(this._button(`primary`,`solid`,`sm`,`send`,i),this._button(`primary`,`ghost`,`sm`,`cancel`,v().cancelLabel));let l=o.createElement(`div`);l.className=`wui-comment-error`,l.setAttribute(`data-wui-error`,``),l.hidden=!0,e.replaceChildren(s,c,l),this._handPeople(s),e.hidden=!1,this._openers??=/* @__PURE__ */ new WeakMap,this._openers.set(e,a),s.focus();let u=s.querySelector(`textarea`);u?.setSelectionRange(u.value.length,u.value.length)}_button(n,r,i,a,o){let s=this.ownerDocument.createElement(`button`);return s.type=`button`,s.className=e(n,r,i),s.dataset.wui=t,s.setAttribute(`data-wui-action`,a),s.textContent=o,s}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=T(e.parentElement,`:scope > [data-wui-text]`,HTMLElement);t&&(t.hidden=!1)}let n=this._openers?.get(e);t&&n?.isConnected&&n.focus()}_askDelete(e){let t=T(e,`:scope > .wui-comment-row`,HTMLElement),n=T(t,`[data-wui-confirm]`,HTMLElement),r=T(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),T(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=T(e,`:scope > .wui-comment-row`,HTMLElement),r=T(n,`[data-wui-confirm]`,HTMLElement),i=T(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&T(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let n=T(this,m,HTMLElement);n&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),a(t,n,{mode:`auto`,onClosed:()=>this._pickerClosed()}),T(n,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;let n=T(this,m,HTMLElement);n&&i(n),this._pickerClosed(),e&&t.button.isConnected&&t.button.focus()}_pickerClosed(){let e=T(this,m,HTMLElement),t=this._pickerFor;!t||e&&o(e)||(this._pickerFor=null,t.button.setAttribute(`aria-expanded`,`false`))}_react(e,t){t&&!this.hasAttribute(`no-reactions`)&&this._send(`react`,{commentId:e.getAttribute(`data-wui-comment`),emoji:t},{comment:e,scope:e})}_sendFrom(e){let t=E(e,`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement);if(!t)return;let n=t.querySelector(`wui-mention-input`),r=n?.value??``;if(!r.trim()){this._showError(t,v().emptyBodyMessage),n?.focus();return}let i=t.closest(g);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:w(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:w(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t})}async _send(e,t,{comment:n,scope:r,form:i}){if(this._busy)return;this._busy=!0,this.setAttribute(`aria-busy`,`true`);let a=i??T(n,`:scope > .wui-comment-row`,HTMLElement)??this;this._showError(a,null);let o=[...r.querySelectorAll(`button, textarea`)].filter(e=>e instanceof HTMLButtonElement||e instanceof HTMLTextAreaElement).filter(e=>!e.disabled);for(let e of o)e.disabled=!0;let s=await this._persist({intent:e,...t});for(let e of o)e.isConnected&&(e.disabled=!1);this._busy=!1,this.removeAttribute(`aria-busy`);let c=t.commentId??null,l=t.parentId??null;s.ok?(s.html!=null&&this._swapItems(s.html),e===`post`?i?.querySelector(`wui-mention-input`)?.clear():i?.isConnected&&this._closeSlot(i,!1),e===`delete`&&n?.isConnected&&this._closeConfirm(n,!1),this._restoreFocus(e,t,i),b(e)&&this._announce(b(e)),this.dispatchEvent(new CustomEvent(`wui:comment-thread:done`,{bubbles:!0,detail:{intent:e,commentId:c,parentId:l}}))):s.kind!==`session`&&s.kind!==`aborted`&&(this._showError(a.isConnected?a:this,s.message),this._announce(s.message),this.dispatchEvent(new CustomEvent(`wui:comment-thread:failed`,{bubbles:!0,detail:{intent:e,kind:s.kind,message:s.message}})))}async _persist(e){if(this.hasAttribute(`controlled`)){if(typeof this.submit!=`function`)return{ok:!0,html:null};try{return await this.submit(e),{ok:!0,html:null}}catch(e){return{ok:!1,kind:`server`,message:x(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:v().failedClientMessage};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await s(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||y(r.kind)||v().failedServerMessage}}_swapItems(e){let t=T(this,p,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=T(n.content,p,HTMLElement);t.replaceChildren(...r?r.childNodes:n.content.childNodes)}_restoreFocus(e,t,n){let r=this.ownerDocument,i=r.activeElement;if(i&&i!==r.body&&i.isConnected&&this.contains(i)&&!C(i))return;let a=e=>e?D(this,g,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>T(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=T(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=T(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=D(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??T(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=T(this,`${h} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=T(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=T(this,`:scope > ${_}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{O as t};
|
|
1
|
+
import{n as e,t}from"./buttonClass-GtEi8hAY.js";import{n}from"./commentText-NWsssKvj.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,l as a,s as o}from"./nativeOverlay-DGady-wN.js";import{l as s}from"./wuiHttp-DGbD7Fra.js";import{r as c,t as l}from"./textStore-opIEM4lu.js";import{n as u,t as d}from"./httpFailure.g-DBKzEpAf.js";import{r as f}from"./WuiMentionInput-DvKw8MXS.js";var p=`[data-wui-items]`,m=`[data-wui-picker]`,h=`[data-wui-composer]`,g=`[data-wui-comment]`,_=`[data-wui-live]`,v=()=>c(`commentThread`,u),y=e=>({forbidden:v().forbiddenMessage,client:v().failedClientMessage,validation:v().validationMessage,server:v().failedServerMessage,network:c(`httpFailure`,d).networkText})[e],b=e=>({post:v().donePostText,reply:v().doneReplyText,edit:v().doneEditText,delete:v().doneDeleteText,react:``})[e],x=e=>{let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;return typeof t==`string`&&t?t:v().failedServerMessage},S=e=>e instanceof Element?e:null,C=e=>`disabled`in e&&e.disabled===!0,w=(e,t)=>{if(e==null)throw Error(`${t} missing`);return e},T=(e,t,n)=>{let r=e?.querySelector(t);return r instanceof n?r:null},E=(e,t,n)=>{let r=e?.closest(t);return r instanceof n?r:null},D=(e,t,n)=>e?[...e.querySelectorAll(t)].filter(e=>e instanceof n):[],O=class extends r{_wired;_busy;_peopleProp;_pickerFor;_openers;constructor(){super(),this._wired=!1,this._busy=!1,this._peopleProp=null,this._pickerFor=null,this._onClick=this._onClick.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onSubmitKey=this._onSubmitKey.bind(this)}connectedCallback(){if(Object.hasOwn(this,`people`)){let e=this.people;Reflect.deleteProperty(this,`people`),this.people=e}if(this._wired)return;this._wired=!0,this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`wui:mention-input:submit`,this._onSubmitKey),customElements.upgrade(this);let e=T(this,`${h} wui-mention-input`,f);this._handPeople(e),this._applyComposerPlaceholder(e)}disconnectedCallback(){this._closePicker(!1)}get people(){return this._peopleProp?this._peopleProp:D(this,`:scope > [data-wui-people] > wui-option`,HTMLElement).map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0}))}set people(e){this._peopleProp=Array.isArray(e)?e:[];for(let e of this.querySelectorAll(`wui-mention-input`))e.people=this._peopleProp}_handPeople(e){!e||this.hasAttribute(`remote`)||this.hasAttribute(`source`)||(e.people=this.people)}_applyComposerPlaceholder(e){let t=this.getAttribute(`composer-placeholder`);e&&t!=null&&e.setAttribute(`placeholder`,t)}_reactionChoices(){let e=this.getAttribute(`reaction-choices`),t=e?e.split(/\s+/).filter(Boolean):[];return t.length?t:n}_onClick(e){let t=E(S(e.target),`[data-wui-emoji]`,HTMLElement);if(t&&this.contains(t)&&!C(t)){let e=t.closest(m),n=e?this._pickerFor?.comment:t.closest(g);e&&this._closePicker(!0),n&&this._react(n,t.getAttribute(`data-wui-emoji`));return}let n=E(S(e.target),`[data-wui-action]`,HTMLElement);if(!n||!this.contains(n)||C(n))return;let r=n.closest(g);switch(n.getAttribute(`data-wui-action`)){case`reply`:this._openReply(r,n);break;case`edit`:this._openEditor(r,n);break;case`delete`:this._askDelete(r);break;case`cancel-delete`:this._closeConfirm(r,!0);break;case`confirm-delete`:{let e=w(r,`comment`);this._send(`delete`,{commentId:e.getAttribute(`data-wui-comment`)},{comment:e,scope:e});break}case`react-menu`:this._pickerFor?.button===n?this._closePicker(!0):this._openPicker(r,n);break;case`cancel`:this._closeSlot(E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement),!0);break;case`post`:case`send`:this._sendFrom(n)}}_onKeyDown(e){let t=T(this,m,HTMLElement),n=S(e.target);if(this._pickerFor&&t?.contains(n)){let r=D(t,`[data-wui-emoji]`,HTMLElement),i=n instanceof HTMLElement?r.indexOf(n):-1;e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closePicker(!0)):e.key===`ArrowRight`||e.key===`ArrowLeft`?(e.preventDefault(),r[(i+(e.key===`ArrowRight`?1:-1)+r.length)%r.length]?.focus()):e.key===`Tab`&&this._closePicker(!1);return}if(e.key!==`Escape`)return;let r=E(n,`[data-wui-reply], [data-wui-editor]`,HTMLElement);if(r&&this.contains(r)){e.preventDefault(),e.stopPropagation(),this._closeSlot(r,!0);return}let i=E(n,`[data-wui-confirm]`,HTMLElement);i&&(e.preventDefault(),e.stopPropagation(),this._closeConfirm(i.closest(g),!0))}_onSubmitKey(e){let t=T(E(S(e.target),`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement),`[data-wui-action="send"], [data-wui-action="post"]`,HTMLElement);t&&!C(t)&&this._sendFrom(t)}_openReply(e,t){if(this.hasAttribute(`no-replies`))return;let n=T(e,`:scope > [data-wui-reply]`,HTMLElement);if(!n)return;if(!n.hidden){n.querySelector(`wui-mention-input`)?.focus();return}let r=e?.querySelector(`.wui-comment-author`)?.textContent?.trim()||``;this._fillSlot(n,{label:l(v().replyToText,{author:r}),placeholder:v().replyPlaceholder,value:``,send:v().replyLabel,opener:t})}_openEditor(e,t){let n=T(e,`:scope > .wui-comment-row [data-wui-editor]`,HTMLElement);if(!n?.hidden)return;let r=T(w(n.parentElement,`comment row`),`:scope > [data-wui-text]`,HTMLElement);r&&(r.hidden=!0),this._fillSlot(n,{label:v().editCommentLabel,placeholder:``,value:e?.getAttribute(`data-value`)??``,send:v().saveLabel,opener:t})}_fillSlot(e,{label:t,placeholder:n,value:r,send:i,opener:a}){let o=this.ownerDocument,s=o.createElement(`wui-mention-input`);s.className=`wui-mention-input`,s.setAttribute(`label`,t),n&&s.setAttribute(`placeholder`,n),s.setAttribute(`rows`,`2`),s.setAttribute(`value`,r);for(let e of[`remote`,`source`,`min-chars`,`debounce`]){let t=this.getAttribute(e);t!=null&&s.setAttribute(e,t)}let c=o.createElement(`div`);c.className=`wui-comment-form-actions`,c.append(this._button(`primary`,`solid`,`sm`,`send`,i),this._button(`primary`,`ghost`,`sm`,`cancel`,v().cancelLabel));let l=o.createElement(`div`);l.className=`wui-comment-error`,l.setAttribute(`data-wui-error`,``),l.hidden=!0,e.replaceChildren(s,c,l),this._handPeople(s),e.hidden=!1,this._openers??=/* @__PURE__ */ new WeakMap,this._openers.set(e,a),s.focus();let u=s.querySelector(`textarea`);u?.setSelectionRange(u.value.length,u.value.length)}_button(n,r,i,a,o){let s=this.ownerDocument.createElement(`button`);return s.type=`button`,s.className=e(n,r,i),s.dataset.wui=t,s.setAttribute(`data-wui-action`,a),s.textContent=o,s}_closeSlot(e,t){if(!e||e.hidden)return;if(e.hidden=!0,e.replaceChildren(),e.hasAttribute(`data-wui-editor`)){let t=T(e.parentElement,`:scope > [data-wui-text]`,HTMLElement);t&&(t.hidden=!1)}let n=this._openers?.get(e);t&&n?.isConnected&&n.focus()}_askDelete(e){let t=T(e,`:scope > .wui-comment-row`,HTMLElement),n=T(t,`[data-wui-confirm]`,HTMLElement),r=T(t,`[data-wui-actions]`,HTMLElement);n&&(n.hidden=!1,r&&(r.hidden=!0),T(n,`[data-wui-action="cancel-delete"]`,HTMLElement)?.focus())}_closeConfirm(e,t){let n=T(e,`:scope > .wui-comment-row`,HTMLElement),r=T(n,`[data-wui-confirm]`,HTMLElement),i=T(n,`[data-wui-actions]`,HTMLElement);r&&(r.hidden=!0),i&&(i.hidden=!1),t&&T(i,`[data-wui-action="delete"]`,HTMLElement)?.focus()}_openPicker(e,t){let n=T(this,m,HTMLElement);n&&e&&!this.hasAttribute(`no-reactions`)&&(this._closePicker(!1),this._pickerFor={comment:e,button:t},t.setAttribute(`aria-expanded`,`true`),a(t,n,{mode:`auto`,onClosed:()=>this._pickerClosed()}),T(n,`[data-wui-emoji]`,HTMLElement)?.focus())}_closePicker(e){let t=this._pickerFor;if(!t)return;let n=T(this,m,HTMLElement);n&&i(n),this._pickerClosed(),e&&t.button.isConnected&&t.button.focus()}_pickerClosed(){let e=T(this,m,HTMLElement),t=this._pickerFor;!t||e&&o(e)||(this._pickerFor=null,t.button.setAttribute(`aria-expanded`,`false`))}_react(e,t){t&&!this.hasAttribute(`no-reactions`)&&this._send(`react`,{commentId:e.getAttribute(`data-wui-comment`),emoji:t},{comment:e,scope:e})}_sendFrom(e){let t=E(e,`[data-wui-reply], [data-wui-editor], [data-wui-composer]`,HTMLElement);if(!t)return;let n=t.querySelector(`wui-mention-input`),r=n?.value??``;if(!r.trim()){this._showError(t,v().emptyBodyMessage),n?.focus();return}let i=t.closest(g);t.hasAttribute(`data-wui-composer`)?this._send(`post`,{body:r},{scope:t,form:t}):t.hasAttribute(`data-wui-reply`)?this._send(`reply`,{parentId:w(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t}):this._send(`edit`,{commentId:w(i,`comment`).getAttribute(`data-wui-comment`),body:r},{comment:i,scope:t,form:t})}async _send(e,t,{comment:n,scope:r,form:i}){if(this._busy)return;this._busy=!0,this.setAttribute(`aria-busy`,`true`);let a=i??T(n,`:scope > .wui-comment-row`,HTMLElement)??this;this._showError(a,null);let o=[...r.querySelectorAll(`button, textarea`)].filter(e=>e instanceof HTMLButtonElement||e instanceof HTMLTextAreaElement).filter(e=>!e.disabled);for(let e of o)e.disabled=!0;let s=await this._persist({intent:e,...t});for(let e of o)e.isConnected&&(e.disabled=!1);this._busy=!1,this.removeAttribute(`aria-busy`);let c=t.commentId??null,l=t.parentId??null;s.ok?(s.html!=null&&this._swapItems(s.html),e===`post`?i?.querySelector(`wui-mention-input`)?.clear():i?.isConnected&&this._closeSlot(i,!1),e===`delete`&&n?.isConnected&&this._closeConfirm(n,!1),this._restoreFocus(e,t,i),b(e)&&this._announce(b(e)),this.dispatchEvent(new CustomEvent(`wui:comment-thread:done`,{bubbles:!0,detail:{intent:e,commentId:c,parentId:l}}))):s.kind!==`session`&&s.kind!==`aborted`&&(this._showError(a.isConnected?a:this,s.message),this._announce(s.message),this.dispatchEvent(new CustomEvent(`wui:comment-thread:failed`,{bubbles:!0,detail:{intent:e,kind:s.kind,message:s.message}})))}async _persist(e){if(this.hasAttribute(`controlled`)){if(typeof this.submit!=`function`)return{ok:!0,html:null};try{return await this.submit(e),{ok:!0,html:null}}catch(e){return{ok:!1,kind:`server`,message:x(e)}}}let t=this.getAttribute(`action`);if(!t)return{ok:!1,kind:`client`,message:v().failedClientMessage};let n=new URLSearchParams;for(let[t,r]of Object.entries(e))r!=null&&n.set(t,r);let r=await s(t,{method:`POST`,body:n});return r.ok?{ok:!0,html:r.html}:{ok:!1,kind:r.kind,message:r.message||y(r.kind)||v().failedServerMessage}}_swapItems(e){let t=T(this,p,HTMLElement);if(!t||!e.trim())return;let n=this.ownerDocument.createElement(`template`);n.innerHTML=e;let r=T(n.content,p,HTMLElement);t.replaceChildren(...r?r.childNodes:n.content.childNodes)}_restoreFocus(e,t,n){let r=this.ownerDocument,i=r.activeElement;if(i&&i!==r.body&&i.isConnected&&this.contains(i)&&!C(i))return;let a=e=>e?D(this,g,HTMLElement).find(t=>t.getAttribute(`data-wui-comment`)===e):null,o=e=>T(a(e),`:scope > .wui-comment-row`,HTMLElement),s=null;if(e===`post`)s=n?.querySelector(`textarea`);else if(e===`reply`)s=T(o(t.parentId),`[data-wui-action="reply"]`,HTMLElement);else if(e===`edit`)s=T(o(t.commentId),`[data-wui-action="edit"]`,HTMLElement);else if(e===`react`){let e=o(t.commentId);s=D(e,`button[data-wui-emoji]`,HTMLButtonElement).find(e=>e.getAttribute(`data-wui-emoji`)===t.emoji)??T(e,`[data-wui-action="react-menu"]`,HTMLElement)}s??=T(this,`${h} textarea`,HTMLTextAreaElement),s?.focus()}_showError(e,t){let n=T(e,`:scope > [data-wui-error], :scope > .wui-comment-main > [data-wui-error]`,HTMLElement);n&&(n.textContent=t||``,n.hidden=!t)}_announce(e){let t=T(this,`:scope > ${_}`,HTMLElement);t&&e&&(t.textContent=``,t.textContent=e)}};export{O as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./imeSafeEnter-DPs9qL3S.js";import{t as n}from"./isDrawn-BbF4phmB.js";import{t as r}from"./menuKeyNav-CstMzU08.js";import{a as i,l as a,s as o}from"./nativeOverlay-D3VmY8qn.js";var s=`[role="menuitem"]`,c=`.wui-context-menu-sub`,l=`input.wui-context-menu-search`,u=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,d=500,f=10,p=400,m=null,h=null,g=0;function _(e,t,n){let r=document.createElement(`span`);return r.setAttribute(`aria-hidden`,`true`),r.style.cssText=n?`position:absolute;left:${e+window.scrollX}px;top:${t+window.scrollY}px;width:0;height:0;`:`position:fixed;left:${e}px;top:${t}px;width:0;height:0;`,document.body.append(r),r}var v=/* @__PURE__ */ new WeakMap;function y(e,t,n){let r=v.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return v.set(e,{region:t,cancel:n}),!0}var b=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,x=e=>`focus`in e,S=e=>[...e.childNodes].filter(e=>e.nodeType===Node.TEXT_NODE||e instanceof Element&&!e.matches(`.wui-context-menu-hint, .wui-context-menu-tick`)).map(e=>e.textContent).join(``),C=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),w=e=>[...e.children].filter(e=>e instanceof HTMLElement),T=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},E=e=>T(e,0),D=e=>T(e,1),O=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null},k=class extends e{_region;_origin;_returnFocus;_press;_swallowClick;_unbindKeys;_anchor;_closingByKey;_onContextMenu;_onContextMenuCapture;_onDocKeyDown;_onDocClick;_onPointerDown;_onPressMove;_onPressEnd;_onClickCapture;_onKeyDown;_onClick;_onInput;_onMouseMove;_onDismiss;_onPointerDownCapture;static get observedAttributes(){return[`disabled`,`open`]}constructor(){super(),this._region=null,this._origin=null,this._returnFocus=null,this._press=null,this._swallowClick=!1,this._unbindKeys=null,this._anchor=null,this._closingByKey=!1,this._onContextMenu=e=>this._handleContextMenu(e),this._onContextMenuCapture=e=>{this.isOpen&&!this._inPanel(e.target)&&!this._isKeyEcho()&&this.close()},this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._onDocClick=e=>this._handleDocClick(e),this._onPointerDown=e=>this._handlePointerDown(e),this._onPressMove=e=>{this._press&&Math.hypot(e.clientX-this._press.x,e.clientY-this._press.y)>f&&this._cancelPress()},this._onPressEnd=()=>this._cancelPress(),this._onClickCapture=e=>{if(this._swallowClick&&this._region){if(!(e.target instanceof Node))throw Error(`a click target is always a node`);this._region.contains(e.target)&&(this._swallowClick=!1,e.preventDefault(),e.stopImmediatePropagation())}},this._onKeyDown=e=>{if(this.isOpen&&this._inPanel(e.target)){if(e.key===`Escape`){if(e.stopPropagation(),this.hasAttribute(`open`)&&O(b(e.target),`[role="menu"]`)===this._panel()){e.preventDefault(),this.close(!0);return}this._closingByKey=!0}this._handleMenuKey(e)}},this._onClick=e=>this._handleClick(e),this._onInput=e=>this._handleInput(e),this._onMouseMove=e=>{let t=O(b(e.target),s);t&&this._inPanel(t)&&!this._isDisabled(t)&&t!==document.activeElement&&t.focus({preventScroll:!0})},this._onDismiss=e=>{this.hasAttribute(`open`)||e.type===`scroll`&&this._inPanel(e.target)||this.close()},this._onPointerDownCapture=()=>{this._swallowClick=!1}}connectedCallback(){this._teardown(),document.addEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.addEventListener(`contextmenu`,this._onContextMenu),document.addEventListener(`keydown`,this._onDocKeyDown),document.addEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.addEventListener(`pointerdown`,this._onPointerDown),document.addEventListener(`click`,this._onClickCapture,!0),document.addEventListener(`click`,this._onDocClick),window.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick),this.addEventListener(`input`,this._onInput),this.addEventListener(`mousemove`,this._onMouseMove),this._syncOpen()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){e===`open`?this.isConnected&&this._syncOpen():this.disabled&&this.close()}get target(){return this.getAttribute(`target`)}set target(e){e==null||e===``?this.removeAttribute(`target`):this.setAttribute(`target`,String(e))}get disabled(){return this.hasAttribute(`disabled`)}set disabled(e){this.toggleAttribute(`disabled`,!!e)}get isOpen(){let e=this._panel();return!!e&&o(e)}open(e,t,{region:n=this,origin:i=n,trigger:s=null,keyboard:c=!1}={}){let l=this._panel();if(!l)return!1;let u=new CustomEvent(`wui-context-menu:beforeopen`,{bubbles:!0,cancelable:!0,detail:{region:n,origin:i,trigger:s}});if(this.dispatchEvent(u),u.defaultPrevented)return!1;if(this._decorate(l),m&&m!==this&&m.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&x(e)?e:null}this._region=n,this._origin=i,h=null,m=this,this._unbindKeys?.(),this._unbindKeys=r(l,{items:()=>this._menuRows()}),this._anchor?.remove();let d=this.hasAttribute(`open`);return this._anchor=_(e,t,d),a(this._anchor,l,{mode:d?`manual`:`auto`,keepOffscreen:d,clampHeight:!0,onClosed:()=>this._onPanelClosed()}),window.addEventListener(`scroll`,this._onDismiss,!0),window.addEventListener(`resize`,this._onDismiss),window.addEventListener(`blur`,this._onDismiss),queueMicrotask(()=>{o(l)&&((c?this._rowsOf(l)[0]:null)??l).focus({preventScroll:!0})}),this.dispatchEvent(new CustomEvent(`wui-context-menu:open`,{bubbles:!0,detail:{region:n,origin:i,x:e,y:t}})),!0}_syncOpen(){if(!this.hasAttribute(`open`)){this.close(this._inPanel(document.activeElement));return}let e=this.target?document.querySelector(this.target):this,t=e&&this._regionRect(e);e&&t&&this.open(t.left,t.top,{region:e,origin:e})}_regionRect(e){if(e!==this)return e.getBoundingClientRect();let t=[...this.children].filter(e=>e!==this._panel()).map(e=>e.getBoundingClientRect());return t.length?{left:Math.min(...t.map(e=>e.left)),top:Math.min(...t.map(e=>e.top))}:null}close(e=!1){let t=this._panel();t&&o(t)&&(e&&(this._closingByKey=!0),i(t))}_finish(e){let t=this._panel();if(t)for(let e of C(t,c))this._setSub(e,!1);m===this&&(m=null),window.removeEventListener(`scroll`,this._onDismiss,!0),window.removeEventListener(`resize`,this._onDismiss),window.removeEventListener(`blur`,this._onDismiss),this._unbindKeys?.(),this._unbindKeys=null,this._anchor?.remove(),this._anchor=null;let n=this._returnFocus;this._returnFocus=null,e&&n?.isConnected&&n.focus({preventScroll:!0})}_onPanelClosed(){let e=this._panel();if(!e||o(e))return;let t=this._closingByKey;this._closingByKey=!1,this._finish(t)}_menuRows(){let e=b(document.activeElement);if(!e||e.matches(l))return[];let t=O(e,`[role="menu"]`);return t?this._rowsOf(t):[]}_panel(){return w(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?C(e,s).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&n(t)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=b(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(u))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=b(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=O(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return h?.menu===this&&this.isOpen&&performance.now()-h.at<p}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!v.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||y(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:b(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!v.has(e))return;if(t(e)){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;e.preventDefault(),t.trigger.click();return}if(!(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey)||this._inPanel(e.target))return;let n=this._regionFor(e.target);if(!n||!y(e,n,()=>this.close(!0)))return;let r=b(e.target);if(!r)return;let i=r.getBoundingClientRect();this.open(i.left+Math.min(16,i.width/2),i.bottom,{region:n,origin:r,keyboard:!0})&&(e.preventDefault(),h={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;let n=t.trigger.getBoundingClientRect();this.open(n.left,n.bottom,{region:t.region,origin:t.trigger,trigger:t.trigger,keyboard:e.detail===0})}_handlePointerDown(e){if(e.pointerType!==`touch`)return;let t=this._regionFor(e.target);if(!t||!y(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=b(e.target);this._press={x:n,y:r,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},d)},document.addEventListener(`pointermove`,this._onPressMove,{passive:!0}),document.addEventListener(`pointerup`,this._onPressEnd),document.addEventListener(`pointercancel`,this._onPressEnd),window.addEventListener(`scroll`,this._onPressEnd,!0)}_cancelPress(){this._press&&(clearTimeout(this._press.timer),this._press=null,document.removeEventListener(`pointermove`,this._onPressMove),document.removeEventListener(`pointerup`,this._onPressEnd),document.removeEventListener(`pointercancel`,this._onPressEnd),window.removeEventListener(`scroll`,this._onPressEnd,!0))}_handleMenuKey(e){if(!this.isOpen)return;let n=b(e.target);if(!n)return;if(n.matches(l)){this._handleSearchKey(e,n);return}let r=O(n,`[role="menu"]`);if(!r)return;let i=O(n,s),a=r.matches(`.wui-context-menu-subpanel`)?r.parentElement:null;if(e.key===`Tab`)this.close(!0);else if(e.key===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(e.key===`ArrowLeft`){if(!a)return;e.preventDefault(),this._closeSubByKey(a)}else(t(e)||e.key===` `)&&(e.preventDefault(),i?.click())}_handleSearchKey(e,t){let n=O(t,c);if(!n)return;let r=this._rowsOf(D(n));e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closeSubByKey(n)):e.key===`ArrowDown`?(e.preventDefault(),r[0]?.focus({preventScroll:!0})):e.key===`ArrowUp`?(e.preventDefault(),r[r.length-1]?.focus({preventScroll:!0})):e.key===`Tab`&&this.close(!0)}_subOf(e){return e.hasAttribute(`aria-haspopup`)&&e.parentElement?.matches(c)?e.parentElement:null}_openSub(e,t){let n=e.parentElement;if(!n)throw Error(`a submenu is always inside its menu panel`);for(let t of w(n))t!==e&&t.matches(c)&&this._closeSub(t);this._setSub(e,!0);let r=D(e).querySelector(`:scope > ${l}`),i=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;i?(i.value=``,this._filter(e,``),i.focus({preventScroll:!0})):t&&this._rowsOf(D(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of C(D(e),c))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),E(e).focus({preventScroll:!0})}_setSub(e,t){let n=D(e);t?(a(E(e),n,{mode:`auto`,beside:!0,onClosed:()=>this._onSubClosed(e)}),E(e).setAttribute(`aria-expanded`,String(o(n)))):o(n)?i(n):this._onSubClosed(e)}_onSubClosed(e){let t=D(e);if(o(t))return;let n=E(e);n.setAttribute(`aria-expanded`,`false`),t.removeAttribute(`data-side`);let r=this._closingByKey;this._closingByKey=!1,r&&n.focus({preventScroll:!0})}_filter(e,t){let n=t.trim().toLowerCase();for(let t of w(D(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(s)?t.hidden=n!==``&&!S(t).toLowerCase().includes(n):t.matches(c)&&(t.hidden=n!==``&&!S(E(t)).toLowerCase().includes(n))}_handleInput(e){let t=b(e.target)?.closest(l);if(!(t instanceof HTMLInputElement))return;let n=O(t,c);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of C(e,s)){let e=t.getAttribute(`aria-checked`)===`true`,n=t.querySelector(`:scope > .wui-context-menu-tick`);if(e&&!n){let e=document.createElement(`span`);e.className=`wui-context-menu-tick`,e.setAttribute(`aria-hidden`,`true`),t.prepend(e)}else!e&&n&&n.remove();let r=t.querySelector(`:scope > .wui-context-menu-hint`),i=t.dataset.hint;if(i){let e=r??document.createElement(`span`);r||(e.className=`wui-context-menu-hint`,e.id=`wui-context-menu-hint-${++g}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=O(b(e.target),s);if(!t||!this._inPanel(t))return;if(this._isDisabled(t)){e.preventDefault(),e.stopPropagation();return}let n=this._subOf(t);n?(e.preventDefault(),this._openSub(n,e.detail===0)):(this.close(!0),this.dispatchEvent(new CustomEvent(`wui-context-menu:select`,{bubbles:!0,detail:{key:t.dataset.key??null,item:t,region:this._region,origin:this._origin}})))}_teardown(){let e=this._panel();if(this._closingByKey=!1,e){for(let t of[...C(e,c)].reverse())i(D(t));i(e)}this._anchor&&this._finish(!1),this._cancelPress(),document.removeEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.removeEventListener(`contextmenu`,this._onContextMenu),document.removeEventListener(`keydown`,this._onDocKeyDown),document.removeEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.removeEventListener(`pointerdown`,this._onPointerDown),document.removeEventListener(`click`,this._onClickCapture,!0),document.removeEventListener(`click`,this._onDocClick),window.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`input`,this._onInput),this.removeEventListener(`mousemove`,this._onMouseMove)}};export{k as t};
|
|
1
|
+
import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./imeSafeEnter-DPs9qL3S.js";import{t as n}from"./isDrawn-BbF4phmB.js";import{t as r}from"./menuKeyNav-CstMzU08.js";import{a as i,l as a,s as o}from"./nativeOverlay-DGady-wN.js";var s=`[role="menuitem"]`,c=`.wui-context-menu-sub`,l=`input.wui-context-menu-search`,u=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,d=500,f=10,p=400,m=null,h=null,g=0;function _(e,t,n){let r=document.createElement(`span`);return r.setAttribute(`aria-hidden`,`true`),r.style.cssText=n?`position:absolute;left:${e+window.scrollX}px;top:${t+window.scrollY}px;width:0;height:0;`:`position:fixed;left:${e}px;top:${t}px;width:0;height:0;`,document.body.append(r),r}var v=/* @__PURE__ */ new WeakMap;function y(e,t,n){let r=v.get(e);if(r){if(r.region===t||t.contains(r.region))return!1;r.cancel()}return v.set(e,{region:t,cancel:n}),!0}var b=e=>e instanceof Element?e:e instanceof Node?e.parentElement:null,x=e=>`focus`in e,S=e=>[...e.childNodes].filter(e=>e.nodeType===Node.TEXT_NODE||e instanceof Element&&!e.matches(`.wui-context-menu-hint, .wui-context-menu-tick`)).map(e=>e.textContent).join(``),C=(e,t)=>[...e.querySelectorAll(t)].filter(e=>e instanceof HTMLElement),w=e=>[...e.children].filter(e=>e instanceof HTMLElement),T=(e,t)=>{let n=e.children[t];if(!(n instanceof HTMLElement))throw Error(`a submenu holds its opener and then its panel`);return n},E=e=>T(e,0),D=e=>T(e,1),O=(e,t)=>{let n=e?.closest(t);return n instanceof HTMLElement?n:null},k=class extends e{_region;_origin;_returnFocus;_press;_swallowClick;_unbindKeys;_anchor;_closingByKey;_onContextMenu;_onContextMenuCapture;_onDocKeyDown;_onDocClick;_onPointerDown;_onPressMove;_onPressEnd;_onClickCapture;_onKeyDown;_onClick;_onInput;_onMouseMove;_onDismiss;_onPointerDownCapture;static get observedAttributes(){return[`disabled`,`open`]}constructor(){super(),this._region=null,this._origin=null,this._returnFocus=null,this._press=null,this._swallowClick=!1,this._unbindKeys=null,this._anchor=null,this._closingByKey=!1,this._onContextMenu=e=>this._handleContextMenu(e),this._onContextMenuCapture=e=>{this.isOpen&&!this._inPanel(e.target)&&!this._isKeyEcho()&&this.close()},this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._onDocClick=e=>this._handleDocClick(e),this._onPointerDown=e=>this._handlePointerDown(e),this._onPressMove=e=>{this._press&&Math.hypot(e.clientX-this._press.x,e.clientY-this._press.y)>f&&this._cancelPress()},this._onPressEnd=()=>this._cancelPress(),this._onClickCapture=e=>{if(this._swallowClick&&this._region){if(!(e.target instanceof Node))throw Error(`a click target is always a node`);this._region.contains(e.target)&&(this._swallowClick=!1,e.preventDefault(),e.stopImmediatePropagation())}},this._onKeyDown=e=>{if(this.isOpen&&this._inPanel(e.target)){if(e.key===`Escape`){if(e.stopPropagation(),this.hasAttribute(`open`)&&O(b(e.target),`[role="menu"]`)===this._panel()){e.preventDefault(),this.close(!0);return}this._closingByKey=!0}this._handleMenuKey(e)}},this._onClick=e=>this._handleClick(e),this._onInput=e=>this._handleInput(e),this._onMouseMove=e=>{let t=O(b(e.target),s);t&&this._inPanel(t)&&!this._isDisabled(t)&&t!==document.activeElement&&t.focus({preventScroll:!0})},this._onDismiss=e=>{this.hasAttribute(`open`)||e.type===`scroll`&&this._inPanel(e.target)||this.close()},this._onPointerDownCapture=()=>{this._swallowClick=!1}}connectedCallback(){this._teardown(),document.addEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.addEventListener(`contextmenu`,this._onContextMenu),document.addEventListener(`keydown`,this._onDocKeyDown),document.addEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.addEventListener(`pointerdown`,this._onPointerDown),document.addEventListener(`click`,this._onClickCapture,!0),document.addEventListener(`click`,this._onDocClick),window.addEventListener(`keydown`,this._onKeyDown,!0),this.addEventListener(`click`,this._onClick),this.addEventListener(`input`,this._onInput),this.addEventListener(`mousemove`,this._onMouseMove),this._syncOpen()}disconnectedCallback(){this._teardown()}attributeChangedCallback(e){e===`open`?this.isConnected&&this._syncOpen():this.disabled&&this.close()}get target(){return this.getAttribute(`target`)}set target(e){e==null||e===``?this.removeAttribute(`target`):this.setAttribute(`target`,String(e))}get disabled(){return this.hasAttribute(`disabled`)}set disabled(e){this.toggleAttribute(`disabled`,!!e)}get isOpen(){let e=this._panel();return!!e&&o(e)}open(e,t,{region:n=this,origin:i=n,trigger:s=null,keyboard:c=!1}={}){let l=this._panel();if(!l)return!1;let u=new CustomEvent(`wui-context-menu:beforeopen`,{bubbles:!0,cancelable:!0,detail:{region:n,origin:i,trigger:s}});if(this.dispatchEvent(u),u.defaultPrevented)return!1;if(this._decorate(l),m&&m!==this&&m.close(!0),!this.isOpen){let e=document.activeElement;this._returnFocus=e&&e!==document.body&&!this._inPanel(e)&&x(e)?e:null}this._region=n,this._origin=i,h=null,m=this,this._unbindKeys?.(),this._unbindKeys=r(l,{items:()=>this._menuRows()}),this._anchor?.remove();let d=this.hasAttribute(`open`);return this._anchor=_(e,t,d),a(this._anchor,l,{mode:d?`manual`:`auto`,keepOffscreen:d,clampHeight:!0,onClosed:()=>this._onPanelClosed()}),window.addEventListener(`scroll`,this._onDismiss,!0),window.addEventListener(`resize`,this._onDismiss),window.addEventListener(`blur`,this._onDismiss),queueMicrotask(()=>{o(l)&&((c?this._rowsOf(l)[0]:null)??l).focus({preventScroll:!0})}),this.dispatchEvent(new CustomEvent(`wui-context-menu:open`,{bubbles:!0,detail:{region:n,origin:i,x:e,y:t}})),!0}_syncOpen(){if(!this.hasAttribute(`open`)){this.close(this._inPanel(document.activeElement));return}let e=this.target?document.querySelector(this.target):this,t=e&&this._regionRect(e);e&&t&&this.open(t.left,t.top,{region:e,origin:e})}_regionRect(e){if(e!==this)return e.getBoundingClientRect();let t=[...this.children].filter(e=>e!==this._panel()).map(e=>e.getBoundingClientRect());return t.length?{left:Math.min(...t.map(e=>e.left)),top:Math.min(...t.map(e=>e.top))}:null}close(e=!1){let t=this._panel();t&&o(t)&&(e&&(this._closingByKey=!0),i(t))}_finish(e){let t=this._panel();if(t)for(let e of C(t,c))this._setSub(e,!1);m===this&&(m=null),window.removeEventListener(`scroll`,this._onDismiss,!0),window.removeEventListener(`resize`,this._onDismiss),window.removeEventListener(`blur`,this._onDismiss),this._unbindKeys?.(),this._unbindKeys=null,this._anchor?.remove(),this._anchor=null;let n=this._returnFocus;this._returnFocus=null,e&&n?.isConnected&&n.focus({preventScroll:!0})}_onPanelClosed(){let e=this._panel();if(!e||o(e))return;let t=this._closingByKey;this._closingByKey=!1,this._finish(t)}_menuRows(){let e=b(document.activeElement);if(!e||e.matches(l))return[];let t=O(e,`[role="menu"]`);return t?this._rowsOf(t):[]}_panel(){return w(this).find(e=>e.getAttribute(`role`)===`menu`)??null}_inPanel(e){return e instanceof Node&&!!this._panel()?.contains(e)}_rowsOf(e){return e?C(e,s).filter(t=>t.closest(`[role="menu"]`)===e&&!this._isDisabled(t)&&n(t)):[]}_isDisabled(e){return e.getAttribute(`aria-disabled`)===`true`}_regionFor(e){let t=b(e);if(!t||this.disabled||!this._panel()||this._inPanel(t)||t.closest(u))return null;let n=this.target;return n?t.closest(n):this.contains(t)?this:null}_triggerFor(e){let t=b(e),n=this.getAttribute(`trigger`);if(!t||!n||this._inPanel(t))return null;let r=O(t,n),i=r&&this._regionFor(r);return r&&i?{trigger:r,region:i}:null}_isKeyEcho(){return h?.menu===this&&this.isOpen&&performance.now()-h.at<p}_handleContextMenu(e){if(this._inPanel(e.target)){e.preventDefault();return}if(e.defaultPrevented&&!v.has(e))return;let t=this._regionFor(e.target);t&&(this._isKeyEcho()?e.preventDefault():e.shiftKey||y(e,t,()=>this.close(!0))&&this.open(e.clientX,e.clientY,{region:t,origin:b(e.target)})&&e.preventDefault())}_handleDocKeyDown(e){if(e.defaultPrevented&&!v.has(e))return;if(t(e)){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;e.preventDefault(),t.trigger.click();return}if(!(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey)||this._inPanel(e.target))return;let n=this._regionFor(e.target);if(!n||!y(e,n,()=>this.close(!0)))return;let r=b(e.target);if(!r)return;let i=r.getBoundingClientRect();this.open(i.left+Math.min(16,i.width/2),i.bottom,{region:n,origin:r,keyboard:!0})&&(e.preventDefault(),h={menu:this,at:performance.now()})}_handleDocClick(e){let t=this._triggerFor(e.target);if(!t||!y(e,t.region,()=>this.close(!0)))return;let n=t.trigger.getBoundingClientRect();this.open(n.left,n.bottom,{region:t.region,origin:t.trigger,trigger:t.trigger,keyboard:e.detail===0})}_handlePointerDown(e){if(e.pointerType!==`touch`)return;let t=this._regionFor(e.target);if(!t||!y(e,t,()=>this._cancelPress()))return;this._cancelPress();let{clientX:n,clientY:r}=e,i=b(e.target);this._press={x:n,y:r,timer:setTimeout(()=>{this._cancelPress(),this.open(n,r,{region:t,origin:i})&&(this._swallowClick=!0)},d)},document.addEventListener(`pointermove`,this._onPressMove,{passive:!0}),document.addEventListener(`pointerup`,this._onPressEnd),document.addEventListener(`pointercancel`,this._onPressEnd),window.addEventListener(`scroll`,this._onPressEnd,!0)}_cancelPress(){this._press&&(clearTimeout(this._press.timer),this._press=null,document.removeEventListener(`pointermove`,this._onPressMove),document.removeEventListener(`pointerup`,this._onPressEnd),document.removeEventListener(`pointercancel`,this._onPressEnd),window.removeEventListener(`scroll`,this._onPressEnd,!0))}_handleMenuKey(e){if(!this.isOpen)return;let n=b(e.target);if(!n)return;if(n.matches(l)){this._handleSearchKey(e,n);return}let r=O(n,`[role="menu"]`);if(!r)return;let i=O(n,s),a=r.matches(`.wui-context-menu-subpanel`)?r.parentElement:null;if(e.key===`Tab`)this.close(!0);else if(e.key===`ArrowRight`){let t=i&&this._subOf(i);if(!t)return;e.preventDefault(),this._openSub(t,!0)}else if(e.key===`ArrowLeft`){if(!a)return;e.preventDefault(),this._closeSubByKey(a)}else(t(e)||e.key===` `)&&(e.preventDefault(),i?.click())}_handleSearchKey(e,t){let n=O(t,c);if(!n)return;let r=this._rowsOf(D(n));e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),this._closeSubByKey(n)):e.key===`ArrowDown`?(e.preventDefault(),r[0]?.focus({preventScroll:!0})):e.key===`ArrowUp`?(e.preventDefault(),r[r.length-1]?.focus({preventScroll:!0})):e.key===`Tab`&&this.close(!0)}_subOf(e){return e.hasAttribute(`aria-haspopup`)&&e.parentElement?.matches(c)?e.parentElement:null}_openSub(e,t){let n=e.parentElement;if(!n)throw Error(`a submenu is always inside its menu panel`);for(let t of w(n))t!==e&&t.matches(c)&&this._closeSub(t);this._setSub(e,!0);let r=D(e).querySelector(`:scope > ${l}`),i=e.hasAttribute(`data-searchable`)&&r instanceof HTMLInputElement?r:null;i?(i.value=``,this._filter(e,``),i.focus({preventScroll:!0})):t&&this._rowsOf(D(e))[0]?.focus({preventScroll:!0})}_closeSub(e){for(let t of C(D(e),c))this._setSub(t,!1);this._setSub(e,!1)}_closeSubByKey(e){this._closeSub(e),E(e).focus({preventScroll:!0})}_setSub(e,t){let n=D(e);t?(a(E(e),n,{mode:`auto`,beside:!0,onClosed:()=>this._onSubClosed(e)}),E(e).setAttribute(`aria-expanded`,String(o(n)))):o(n)?i(n):this._onSubClosed(e)}_onSubClosed(e){let t=D(e);if(o(t))return;let n=E(e);n.setAttribute(`aria-expanded`,`false`),t.removeAttribute(`data-side`);let r=this._closingByKey;this._closingByKey=!1,r&&n.focus({preventScroll:!0})}_filter(e,t){let n=t.trim().toLowerCase();for(let t of w(D(e)))t.tagName===`HR`?t.hidden=n!==``:t.matches(s)?t.hidden=n!==``&&!S(t).toLowerCase().includes(n):t.matches(c)&&(t.hidden=n!==``&&!S(E(t)).toLowerCase().includes(n))}_handleInput(e){let t=b(e.target)?.closest(l);if(!(t instanceof HTMLInputElement))return;let n=O(t,c);n?.hasAttribute(`data-searchable`)&&this._inPanel(n)&&this._filter(n,t.value)}_decorate(e){for(let t of C(e,s)){let e=t.getAttribute(`aria-checked`)===`true`,n=t.querySelector(`:scope > .wui-context-menu-tick`);if(e&&!n){let e=document.createElement(`span`);e.className=`wui-context-menu-tick`,e.setAttribute(`aria-hidden`,`true`),t.prepend(e)}else!e&&n&&n.remove();let r=t.querySelector(`:scope > .wui-context-menu-hint`),i=t.dataset.hint;if(i){let e=r??document.createElement(`span`);r||(e.className=`wui-context-menu-hint`,e.id=`wui-context-menu-hint-${++g}`,t.append(e)),e.textContent=i,t.setAttribute(`aria-describedby`,e.id)}else r&&(r.remove(),t.removeAttribute(`aria-describedby`))}}_handleClick(e){let t=O(b(e.target),s);if(!t||!this._inPanel(t))return;if(this._isDisabled(t)){e.preventDefault(),e.stopPropagation();return}let n=this._subOf(t);n?(e.preventDefault(),this._openSub(n,e.detail===0)):(this.close(!0),this.dispatchEvent(new CustomEvent(`wui-context-menu:select`,{bubbles:!0,detail:{key:t.dataset.key??null,item:t,region:this._region,origin:this._origin}})))}_teardown(){let e=this._panel();if(this._closingByKey=!1,e){for(let t of[...C(e,c)].reverse())i(D(t));i(e)}this._anchor&&this._finish(!1),this._cancelPress(),document.removeEventListener(`contextmenu`,this._onContextMenuCapture,!0),document.removeEventListener(`contextmenu`,this._onContextMenu),document.removeEventListener(`keydown`,this._onDocKeyDown),document.removeEventListener(`pointerdown`,this._onPointerDownCapture,!0),document.removeEventListener(`pointerdown`,this._onPointerDown),document.removeEventListener(`click`,this._onClickCapture,!0),document.removeEventListener(`click`,this._onDocClick),window.removeEventListener(`keydown`,this._onKeyDown,!0),this.removeEventListener(`click`,this._onClick),this.removeEventListener(`input`,this._onInput),this.removeEventListener(`mousemove`,this._onMouseMove)}};export{k as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
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-DIoh4HjR.js";import{r as f}from"./dom-Do1pAA12.js";import{t as p}from"./elementBase-Cxeyx0tU.js";import{r as m,t as h}from"./fieldState-D-zQcXUS.js";import{_ as g,b as _,g as v}from"./formatters-CMTSYlW9.js";import{t as y}from"./formMirror-9IpSgeZb.js";import{t as b}from"./iconGlyphs.g-
|
|
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-DIoh4HjR.js";import{r as f}from"./dom-Do1pAA12.js";import{t as p}from"./elementBase-Cxeyx0tU.js";import{r as m,t as h}from"./fieldState-D-zQcXUS.js";import{_ as g,b as _,g as v}from"./formatters-CMTSYlW9.js";import{t as y}from"./formMirror-9IpSgeZb.js";import{t as b}from"./iconGlyphs.g-BUF97bUu.js";import{a as x,l as S,s as C}from"./nativeOverlay-DGady-wN.js";import{n as w}from"./optionLabel-CWMhBkdO.js";import{r as T}from"./textStore-opIEM4lu.js";import{t as E}from"./datePicker.g-VdBlhA2G.js";var D=()=>T(`datePicker`,E),O=e=>e-(e%10+10)%10-1,k=class extends p{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&&C(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||``,y(this,this._value),this._syncTrigger()}_firstDay(){return c(this)}_monthOnly(){return this.getAttribute(`mode`)===`month`}_yearOnly(){return this.getAttribute(`mode`)===`year`}_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(e);return n?{y:n.y,m:n.m,d:1}:null}_placeholder(){return this.getAttribute(`placeholder`)||(this._yearOnly()?D().yearPlaceholder:this._monthOnly()?D().monthPlaceholder:D().placeholder)}_label(t){let n=this.getAttribute(`display-format`);return this._yearOnly()?s(t,n):this._monthOnly()?e(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.innerHTML=`
|
|
2
2
|
<div class="datepicker">
|
|
3
3
|
<button type="button" class="input datepicker-trigger${r}${t?` has-value`:``}" aria-haspopup="dialog" aria-expanded="false"${this.hasAttribute(`aria-invalid`)?` aria-invalid="true"`:``}${this.hasAttribute(`disabled`)?` disabled`:``}${i?` aria-label="${w(i)}"`:``}${a?` aria-describedby="${w(a)}"`:``}>
|
|
4
4
|
<span data-trigger-label class="${t?``:`wui-select-placeholder`}">${w(t?this._label(this._value):e)}</span>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,s as r,t as i,u as a}from"./calendarMath-DIoh4HjR.js";import{n as o}from"./devWarn-DXdRWZs3.js";import{r as s,t as c}from"./textStore-opIEM4lu.js";import{t as l}from"./dateRangePicker.g-Pnc37vgX.js";import{C as u,S as d,_ as f,b as p,x as m}from"./formatters-CMTSYlW9.js";import{t as h}from"./elementBase-Cxeyx0tU.js";import{r as g,t as _}from"./fieldState-D-zQcXUS.js";import{t as v}from"./iconGlyphs.g-
|
|
1
|
+
import{i as e,n as t,r as n,s as r,t as i,u as a}from"./calendarMath-DIoh4HjR.js";import{n as o}from"./devWarn-DXdRWZs3.js";import{r as s,t as c}from"./textStore-opIEM4lu.js";import{t as l}from"./dateRangePicker.g-Pnc37vgX.js";import{C as u,S as d,_ as f,b as p,x as m}from"./formatters-CMTSYlW9.js";import{t as h}from"./elementBase-Cxeyx0tU.js";import{r as g,t as _}from"./fieldState-D-zQcXUS.js";import{t as v}from"./iconGlyphs.g-BUF97bUu.js";import{a as y,l as b,s as x}from"./nativeOverlay-DGady-wN.js";import{n as S}from"./optionLabel-CWMhBkdO.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=m,financialYearStart:i=C}={}){if(!O(e))return null;let a=r(u(n,t));if(!a)throw Error(`today missing`);let{y:o,m:c,d}=a,f=(e,t,n)=>D(new Date(Date.UTC(e,t,n))),p=s(`dateRangePicker`,l)[T[e]];switch(e){case`today`:return{label:p,start:f(o,c,d),end:f(o,c,d)};case`yesterday`:return{label:p,start:f(o,c,d-1),end:f(o,c,d-1)};case`last7Days`:return{label:p,start:f(o,c,d-6),end:f(o,c,d)};case`last30Days`:return{label:p,start:f(o,c,d-29),end:f(o,c,d)};case`thisMonth`:return{label:p,start:f(o,c,1),end:f(o,c+1,0)};case`lastMonth`:return{label:p,start:f(o,c-1,1),end:f(o,c,0)};case`thisFinancialYear`:{let e=i-1,t=c>=e?o:o-1;return{label:p,start:f(t,e,1),end:f(t+1,e,0)}}default:return null}}function A(e){o(`[@webority/ui-elements] <wui-date-range> presets: ${e}`)}function j(e){return typeof e==`object`&&!!e}function M(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 h{static formAssociated=!0;_internals;_start;_end;_hover;_viewY;_viewM;get open(){return this.querySelector(`.daterange`)?.classList.contains(`open`)??!1}set open(e){e?!_(this)&&!this.open&&this._open?.():this.open&&this._close?.()}static get observedAttributes(){return[`start`,`end`,`min`,`max`,`placeholder`,`disabled`,`readonly`,`loading`,`first-day`,`size`,`aria-label`,`aria-describedby`,`name`,`start-name`,`end-name`,`presets`,`time-zone`,`financial-year-start`,`aria-invalid`]}constructor(){super();try{this._internals=this.attachInternals()}catch{this._internals=null}this._start=``,this._end=``,this._hover=``;let e=new Date(2e3,0,1);this._viewY=e.getFullYear(),this._viewM=e.getMonth()}connectedCallback(){this._rendered||this.render()}disconnectedCallback(){this._dropPanel()}attributeChangedCallback(e,t,n){e===`aria-invalid`?this._syncInvalid():this._rendered&&(e===`start`||e===`end`?(this._start=this.getAttribute(`start`)||``,this._end=this.getAttribute(`end`)||``,this._syncTrigger(),this._syncMirrors()):this.render())}_syncInvalid(){let e=this.querySelector(`.daterange-trigger`);e&&(this.hasAttribute(`aria-invalid`)?e.setAttribute(`aria-invalid`,`true`):e.removeAttribute(`aria-invalid`))}get value(){return{start:this._start,end:this._end}}set value(e){this._start=e?.start||``,this._end=e?.end||``,this._syncTrigger(),this._syncMirrors()}_firstDay(){return 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`);this.innerHTML=`
|
|
2
2
|
<div class="daterange">
|
|
3
3
|
<button type="button" class="input daterange-trigger${n}${a?``:` has-value`}" aria-haspopup="dialog" aria-expanded="false"${this.hasAttribute(`aria-invalid`)?` aria-invalid="true"`:``}${this.hasAttribute(`disabled`)?` disabled`:``}${o?` aria-label="${S(o)}"`:``}${s?` aria-describedby="${S(s)}"`:``}>
|
|
4
4
|
<span data-range-label class="${a?`wui-select-placeholder`:``}">${S(i)}</span>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./dom-Do1pAA12.js";import{t}from"./elementBase-Cxeyx0tU.js";import{h as n,o as r,p as i,u as a}from"./nativeOverlay-
|
|
1
|
+
import{r as e}from"./dom-Do1pAA12.js";import{t}from"./elementBase-Cxeyx0tU.js";import{h as n,o as r,p as i,u as a}from"./nativeOverlay-DGady-wN.js";import{r as o,t as s}from"./textStore-opIEM4lu.js";import{t as c}from"./drawer.g-B-zYKBfQ.js";var l=[50,90],u=10,d=100;function f(e,t=l){let n=Array.isArray(e)?e:String(e??``).split(`,`),r=[];for(let e of n){if(typeof e==`string`&&e.trim()===``)return t;let n=Number(e);if(!Number.isFinite(n)||n<u||n>d)return t;r.includes(n)||r.push(n)}return r.length?r.sort((e,t)=>e-t):t}function p(e){let{points:t,index:n,visible:r,velocity:i,canDismiss:a}=e,o=a?-1:0;if(Math.abs(i)>=.5)return i>0?Math.max(n-1,o):Math.min(n+1,t.length-1);let s=t[0];if(a&&s!==void 0&&r<s/2)return-1;let c=0;for(let e=1;e<t.length;e++){let n=t[e],i=t[c];if(n===void 0||i===void 0)throw Error(`snap point missing`);Math.abs(n-r)<Math.abs(i-r)&&(c=e)}return c}var m=()=>o(`drawer`,c),h=`(max-width: 767.98px)`,g=4;function _(e,t){let n=e[t];if(n===void 0)throw RangeError(`no snap point at ${t}`);return n}var v=class extends t{_doc;_media;_shown;_trigger;_returnTo;_release;_snap;_drag;_onMedia;_onPointerDown;_onPointerMove;_onPointerUp;_onKeyDown;_onTransitionEnd;_settled;static get observedAttributes(){return[`open`,`snap-points`,`no-sheet`]}constructor(){super(),this._doc=null,this._media=null,this._shown=!1,this._trigger=null,this._returnTo=null,this._release=null,this._snap=0,this._drag=null,this._onMedia=()=>this._syncMode(),this._onPointerDown=e=>this._pointerDown(e),this._onPointerMove=e=>this._pointerMove(e),this._onPointerUp=e=>this._pointerUp(e),this._onKeyDown=e=>this._keyDown(e),this._onTransitionEnd=e=>{e.target===this._panel()&&e.propertyName===`transform`&&this.isOpen&&this._announce()},this._settled=!1}connectedCallback(){this._doc=this.ownerDocument,n(this._doc),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`pointerdown`,this._onPointerDown),this.addEventListener(`transitionend`,this._onTransitionEnd),this._media=typeof matchMedia==`function`?matchMedia(h):null,this._media?.addEventListener?.(`change`,this._onMedia),this._syncMode(),this._applyPoints(),this.hasAttribute(`open`)&&this._open()}disconnectedCallback(){this._endDrag(),this._teardown(),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`pointerdown`,this._onPointerDown),this.removeEventListener(`transitionend`,this._onTransitionEnd),this._media?.removeEventListener?.(`change`,this._onMedia),this._media=null,this._doc=null}attributeChangedCallback(e){this._doc&&(e===`open`?this.hasAttribute(`open`)?this._open():this._close():e===`no-sheet`?this._syncMode():(this._snap=Math.min(this._snap,this._points().length-1),this._applyPoints()))}get isOpen(){return this.hasAttribute(`open`)}show(e){this._trigger=e??null,this.setAttribute(`open`,``)}hide(){this.removeAttribute(`open`)}_points(){return f(this.getAttribute(`snap-points`),l)}_sheet(){return!!this._media?.matches&&!this.hasAttribute(`no-sheet`)}_syncMode(){this.setAttribute(`data-mode`,this._sheet()?`sheet`:`side`)}_applyPoints(){let t=this._points();this._snap=Math.min(Math.max(this._snap,0),t.length-1),this.style.setProperty(`--wui-drawer-max`,String(t[t.length-1])),this.style.setProperty(`--wui-drawer-snap`,String(t[this._snap])),this.setAttribute(`data-snap`,String(this._snap));let n=this.querySelector(`.wui-drawer-handle`);if(!(n instanceof Element))return;let r=e(t[this._snap],`The drawer has no snap point to report.`);n.setAttribute(`aria-valuemin`,String(t[0])),n.setAttribute(`aria-valuemax`,String(t[t.length-1])),n.setAttribute(`aria-valuenow`,String(r)),n.setAttribute(`aria-valuetext`,s(m().screenText,{now:r}))}_setSnap(e){let t=this._points(),n=Math.min(Math.max(e,0),t.length-1),r=n!==this._snap;this._snap=n,this._applyPoints(),r&&this.dispatchEvent(new CustomEvent(`wui-drawer-snap`,{bubbles:!0,detail:{index:n,percent:t[n]}}))}_open(){if(this._shown)return;let e=this._dialog();this._shown=!0,this._settled=null;let t=Number.parseInt(this.getAttribute(`default-snap`)??`0`,10);this._snap=Number.isFinite(t)?t:0,this._syncMode(),this._applyPoints(),this.dispatchEvent(new CustomEvent(`wui-drawer-open`,{bubbles:!0,detail:{trigger:this._trigger}})),this._returnTo=this._trigger,this._trigger=null,this._release=a(e,{escape:this._dismissible(),backdrop:this._dismissible(),focus:this._sheet()?`panel`:`first-control`,onRequestClose:e=>this._requestClose(e)}),this._settle()}_close(){if(!this._shown)return;this._endDrag(),this._shown=!1,this._settled=null;let e=this._release;this._release=null;let t=this._dialog();r(t).then(()=>{e?.(),i(this._returnTo,t),this._returnTo=null,this._announce()})}_teardown(){this._shown=!1;let e=this._release;this._release=null,e&&(e(),this._panel()?.close())}_settle(){(this._panel()?.getAnimations?.()??[]).length||this._announce()}_announce(){let e=this.isOpen;e!==this._settled&&(this._settled=e,this.dispatchEvent(new CustomEvent(e?`wui-drawer-opened`:`wui-drawer-closed`,{bubbles:!0})))}_document(){let e=this._doc;if(!e)throw TypeError(`wui-drawer is not connected`);return e}_panel(){let e=this.querySelector(`.wui-drawer-panel`);return e instanceof HTMLDialogElement?e:null}_dialog(){let e=this._panel();if(!e)throw TypeError(`wui-drawer has no dialog panel`);return e}_dismissible(){return!this.hasAttribute(`static`)&&!this.hasAttribute(`no-dismiss`)}_requestClose(e){let t=this.dispatchEvent(new CustomEvent(`wui-drawer-close`,{bubbles:!0,cancelable:!0,detail:{reason:e}}));return t&&this.hide(),t}_keyDown(e){e.target instanceof Element&&e.target.closest(`.wui-drawer-handle`)&&this._sheet()&&this._handleKey(e)}_handleKey(e){let t=this._points().length-1,n={ArrowUp:this._snap+1,ArrowDown:this._snap-1,Home:0,End:t};if(!(e.key in n))return;let r=n[e.key];r!==void 0&&(e.preventDefault(),this._setSnap(r))}_pointerDown(e){if(!this.isOpen||!this._sheet()||(e.button??0)!==0)return;let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[data-wui-drawer-grip]`);n instanceof HTMLElement&&!t.closest(`button`)&&(this._drag={grip:n,id:e.pointerId,startY:e.clientY,lastY:e.clientY,lastT:e.timeStamp,velocity:0,moved:!1},n.setPointerCapture?.(e.pointerId),n.addEventListener(`pointermove`,this._onPointerMove),n.addEventListener(`pointerup`,this._onPointerUp),n.addEventListener(`pointercancel`,this._onPointerUp))}_viewport(){let e=this._document().defaultView;if(!e)throw TypeError(`wui-drawer has no window`);return e.innerHeight}_pointerMove(e){let t=this._drag;if(!t||e.pointerId!==t.id)return;let n=e.clientY-t.startY;if(!t.moved&&Math.abs(n)<g)return;t.moved=!0,this.classList.add(`is-dragging`);let r=e.timeStamp-t.lastT;r>0&&(t.velocity=(e.clientY-t.lastY)/r),t.lastY=e.clientY,t.lastT=e.timeStamp;let i=this._points(),a=(_(i,i.length-1)-_(i,this._snap))/100*this._viewport();t.offset=Math.max(n,-a),this.style.setProperty(`--wui-drawer-drag`,`${t.offset}px`)}_pointerUp(e){let t=this._drag;if(!t||e.pointerId!==t.id)return;let{moved:n,velocity:r,offset:i=0}=t;if(this._endDrag(),!n)return;let a=this._points(),o=this._viewport(),s=(_(a,this._snap)/100*o-i)/(o/100),c=this._dismissible(),l=p({points:a,index:this._snap,visible:s,velocity:r,canDismiss:c});l>=0?this._setSnap(l):this._requestClose(`drag`)}_endDrag(){let e=this._drag;e&&(this._drag=null,e.grip.releasePointerCapture?.(e.id),e.grip.removeEventListener(`pointermove`,this._onPointerMove),e.grip.removeEventListener(`pointerup`,this._onPointerUp),e.grip.removeEventListener(`pointercancel`,this._onPointerUp),this.classList.remove(`is-dragging`),this.style.removeProperty(`--wui-drawer-drag`))}};export{v as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-Cxeyx0tU.js";import{t}from"./isDrawn-BbF4phmB.js";import{t as n}from"./menuKeyNav-CstMzU08.js";import{a as r,l as i,s as a}from"./nativeOverlay-
|
|
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-DGady-wN.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-GtEi8hAY.js";import{t}from"./devWarn-DXdRWZs3.js";import{r as n}from"./dom-Do1pAA12.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,c as a,d as o,f as s,i as c,l,m as u,n as d,o as f,p,s as m,t as h,u as g}from"./initials-Qb6ITcri.js";import{t as _}from"./avatarHtml-BtbN7cA5.js";import{t as v}from"./iconGlyphs.g-DxSJLQJ8.js";import{n as y,r as b,t as x}from"./textStore-opIEM4lu.js";import{a as S,l as C}from"./nativeOverlay-D3VmY8qn.js";import{t as w}from"./gantt.g-TdTxeruW.js";var T=`data-wui-gantt-pick`,E=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},D=e=>`${e}px`,O=(e,t,n)=>{let r=E(`div`,`wui-gantt-table-cell`,n);return r.setAttribute(`role`,t),r.dataset.col=e,r};function k(e){let t=e.text,n=E(`div`,`wui-gantt-table`);n.setAttribute(`role`,`table`),n.setAttribute(`aria-label`,e.title);let r=E(`div`);r.setAttribute(`role`,`rowgroup`);let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=`head`,i.setAttribute(`role`,`row`),i.style.height=D(e.headHeight),i.append(O(`name`,`columnheader`,t.tableName),O(`owner`,`columnheader`,t.detailsOwner),O(`start`,`columnheader`,t.tableStart),O(`end`,`columnheader`,t.tableEnd),O(`done`,`columnheader`,t.detailsDone)),r.append(i);let a=E(`div`);a.setAttribute(`role`,`rowgroup`);for(let n of e.rows){if(n.height===0)continue;let r=n.row;if(n.kind===`group`){let r=n.group;if(!r)continue;let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=`group`,i.dataset.wuiGanttGroup=r.name,i.setAttribute(`role`,`row`),i.style.height=D(n.height);let o=E(`div`,`wui-gantt-table-cell wui-gantt-table-group`);o.setAttribute(`role`,`rowheader`);let s=E(`button`,`wui-gantt-group-toggle`);s.type=`button`,s.setAttribute(`aria-expanded`,String(!r.folded)),s.setAttribute(`aria-label`,x(r.folded?t.unfoldLabel:t.foldLabel,{group:r.name})),s.setAttribute(e.focusAttr,`group:${r.name}`),s.innerHTML=v(r.folded?`chevron-right`:`chevron-down`,{size:16}),o.append(s,E(`span`,null,r.name),E(`span`,null,y(t,`groupSummary`,r.count,{percent:r.percent}))),i.append(o),a.append(i);continue}let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=r.end===void 0?`milestone`:`bar`,i.dataset.wuiGanttKey=r.key,i.dataset.wuiGanttPick=r.key,r.key===e.selected&&(i.dataset.selected=`true`),i.setAttribute(`role`,`row`),i.style.height=D(n.height);let o=O(`name`,`rowheader`,r.name);o.title=r.name;let s=O(`owner`,`cell`,``);r.owner&&(s.title=r.owner,s.innerHTML=_({initials:h(r.owner)},`avatar-xs`),s.append(E(`span`,`visually-hidden`,r.owner)));let c=O(`start`,`cell`,r.start===void 0?``:f(l(r.start))),u=O(`end`,`cell`,r.end===void 0?``:f(l(r.end))),d=O(`done`,`cell`,r.end===void 0?``:`${r.progress??0}%`);i.append(o,s,c,u,d),a.append(i)}let o=e.skeleton;for(let e=0;o&&e<o.rows;e+=1){let e=E(`div`,`wui-gantt-table-row`);e.dataset.kind=`skeleton`,e.setAttribute(`role`,`row`),e.setAttribute(`aria-hidden`,`true`),e.style.height=D(o.rowHeight);let t=E(`span`,`wui-gantt-skeleton`);t.style.height=D(o.barHeight),e.append(t),a.append(e)}return n.append(r,a),n}var A=()=>b(`gantt`,w),j=`wui-gantt:zoom-change`,M=`wui-gantt:from-change`,N=`wui-gantt:fold-change`,P=`wui-gantt:select`,F=`wui-gantt:add-task`,I=`wui-gantt:retry`,L=`data-wui-gantt-focus`,R=`bar:`,z=`http://www.w3.org/2000/svg`,B=[`day`,`week`,`month`],V=3,H=16,U=300,W=[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`,`Escape`,`Enter`,` `],G=0,K=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},q=e=>`${e}px`;function J(e){return typeof e==`object`&&!!e&&`rows`in e&&Array.isArray(e.rows)&&`title`in e&&typeof e.title==`string`}function Y(e){let t=A();switch(e){case`done`:return t.statusDone;case`inProgress`:return t.statusInProgress;case`atRisk`:return t.statusAtRisk;case`notStarted`:return t.statusNotStarted;default:throw RangeError(`Unknown gantt status ${String(e)}.`)}}var X=e=>e.progress??0,Z=e=>e.status??`notStarted`,Q=(e,t)=>(e??[]).join(`\0`)===(t??[]).join(`\0`),$=class extends r{uid;_spec=null;_prev=null;_zoom=`week`;_fromMs=null;_folded=/* @__PURE__ */ new Set;_selected=null;_controlled=!1;_awaitingSpec=!1;_connected=!1;_focusAfter=null;_resolved=null;_specRows=[];_card=null;_onClick;_onKeyDown;_onChange;constructor(){super(),G+=1,this.uid=`wui-gantt-${G}`,this._onClick=e=>this._handleClick(e),this._onKeyDown=e=>this._handleKeyDown(e),this._onChange=e=>this._handleChange(e)}get spec(){return this._spec}set spec(e){this._spec=e??null,this._connected&&this._draw()}connectedCallback(){if(Object.hasOwn(this,`spec`)){let e=this.spec;delete this.spec,this._spec=e??null}this._spec??=this._readScript(),this._spec==null&&!this.querySelector(`:scope > script[type='application/json']`)&&(this._awaitingSpec=!0,queueMicrotask(()=>{this._awaitingSpec=!1,this._connected&&this._draw()})),this.classList.add(`wui-gantt`),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`change`,this._onChange),this._connected=!0,this._draw()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`change`,this._onChange),this._card&&=(S(this._card),this._card.remove(),null),this._connected=!1}_readScript(){let e=this.querySelector(`:scope > script[type="application/json"]`);if(!(e instanceof HTMLScriptElement))return null;try{return JSON.parse(String(e.textContent))}catch(e){return t(`[@webority/ui-elements] <wui-gantt> could not read its JSON spec:`,e instanceof Error?e.message:void 0),null}}_seed(e){let t=this._prev;this._controlled=e.controlled===!0;let n=e=>this._controlled||t===null||e;n(t?.zoom!==e.zoom)&&(this._zoom=e.zoom??`week`),n(t?.from!==e.from)&&(this._fromMs=e.from?l(e.from):null),n(!Q(t?.folded,e.folded))&&(this._folded=new Set(e.folded??[])),n(t?.selected!==e.selected)&&(this._selected=e.selected??null),this._prev=e}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_setZoom(e){this._emit(j,{zoom:e}),this._controlled?this._syncRadios():(this._zoom=e,this._fromMs=this._fromMs===null?null:o(e,this._fromMs),this._draw())}_setFrom(e){this._emit(M,{from:m(e)}),this._controlled||(this._fromMs=e,this._draw())}_setFolded(e){let t=new Set(this._folded);t.delete(e)||t.add(e),this._emit(N,{folded:[...t]}),this._controlled||(this._folded=t,this._draw())}_setSelected(e){this._emit(P,{key:e}),this._focusAfter=`${R}${e??this._selected??``}`,this._controlled||(this._selected=e),this._draw()}_syncRadios(){for(let e of this.querySelectorAll(`.segmented-input`))e.checked=e.value===this._zoom}_handleChange(e){let t=e.target;if(!(t instanceof HTMLInputElement)||!t.matches(`.wui-gantt-scale .segmented-input`))return;let n=B.find(e=>e===t.value);n&&this._setZoom(n)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[${L}]`);if(n instanceof HTMLElement&&this.contains(n)){this._activate(n.getAttribute(L)??``,n);return}let r=t.closest(`[${T}]`);if(!(r instanceof HTMLElement)||!this.contains(r))return;let i=r.getAttribute(`data-wui-gantt-pick`)??``;this._setSelected(i===this._selected?null:i)}_activate(e,t){let n=this._resolved;if(e.startsWith(R)){let t=e.slice(4);this._setSelected(t===this._selected?null:t)}else e.startsWith(`group:`)?this._setFolded(e.slice(6)):e===`close`?this._setSelected(null):e===`add`?this._emit(F):e===`retry`?this._emit(I):n&&e===`nav:earlier`?this._setFrom(g(n.zoom,n.fromMs,-1)):n&&e===`nav:later`?this._setFrom(g(n.zoom,n.fromMs,1)):n&&e===`nav:today`?this._setFrom(u(n.zoom,n.todayMs)):e.startsWith(`zoom:`)&&t.click()}_bars(){return[...this.querySelectorAll(`.wui-gantt-lane [${L}^="${R}"]`)].filter(e=>e instanceof HTMLElement)}_focusBar(e){if(e){for(let t of this._bars())t.tabIndex=t===e?0:-1;e.focus()}}_barByKey(e){return e===void 0?void 0:this._bars().find(t=>t.dataset.wuiGanttKey===e)}_handleKeyDown(e){if(e.ctrlKey||e.metaKey||e.altKey||!W.includes(e.key))return;if(e.key===`Escape`){if(this._selected===null)return;e.preventDefault(),this._setSelected(null);return}let t=e.target;if(!(t instanceof HTMLElement)||!t.getAttribute(L)?.startsWith(R))return;let n=this._bars(),r=n.indexOf(t),i=t.dataset.wuiGanttKey,a=this._specRows.find(e=>e.key===i);switch(e.preventDefault(),e.key){case`ArrowDown`:this._focusBar(n[r+1]);break;case`ArrowUp`:this._focusBar(n[r-1]);break;case`Home`:this._focusBar(n[0]);break;case`End`:this._focusBar(n.at(-1));break;case`ArrowLeft`:this._focusBar((a?.dependsOn??[]).map(e=>this._barByKey(e)).find(e=>e));break;case`ArrowRight`:this._focusBar(this._specRows.filter(e=>e.dependsOn?.includes(i??``)).map(e=>this._barByKey(e.key)).find(e=>e));break;default:this._activate(t.getAttribute(L)??``,t)}}_focusToken(){let e=document.activeElement;return e instanceof HTMLElement&&this.contains(e)?e.getAttribute(L):null}_draw(){if(this._card&&=(S(this._card),this._card.remove(),null),this._spec==null&&this._awaitingSpec)return;let e=this._focusAfter??this._focusToken();this._focusAfter=null;let r;try{r=this._compose()}catch(e){t(`[@webority/ui-elements] <wui-gantt> could not draw its spec:`,e instanceof Error?e.message:void 0),this._resolved=null,this._specRows=[],this._card=null,this.dataset.state=`error`,this.removeAttribute(`aria-busy`),r=[this._stateBlock(`error`,A().errorText)]}if(this.replaceChildren(...r),this._card){let e=n(this._barByKey(this._selected??void 0),`selected gantt bar`);this.append(this._card),C(e,this._card,{mode:`manual`,side:`auto`,align:`start`,flipAlign:!0,gap:4,keepOffscreen:!0})}if(this._placeThumb(),e===null)return;let i=[...this.querySelectorAll(`[${L}]`)].find(t=>t.getAttribute(L)===e);i instanceof HTMLElement&&(e.startsWith(R)?this._focusBar(i):i.focus())}_compose(){let e=this._spec;if(!J(e))throw TypeError("<wui-gantt> has no spec: set the `spec` property or add a JSON script child.");this._seed(e),p(e);let t=e.layout??`table`,n=c[t],r=A(),f=l(e.today??s()),m=this._zoom,h=o(m,this._fromMs??u(m,f)),g={layout:t,zoom:m,fromMs:h,todayMs:f};this._resolved=g,this._specRows=e.rows;let _=e.rows.some(e=>e.start!==void 0),v=(e.state??`ready`)===`ready`&&!_?`empty`:e.state??`ready`;this.dataset.state=v,this.dataset.zoom=m,this.dataset.layout=t,v===`loading`?this.setAttribute(`aria-busy`,`true`):this.removeAttribute(`aria-busy`);let y=v===`ready`?a({...e,folded:[...this._folded],selected:this._selected},g):null,b=y?.axis??i(t,m,h),x=K(`div`,`wui-gantt-lane`);x.style.width=q(b.width),y?this._fillLane(x,e,y):v===`loading`&&(x.style.height=q(V*n.rowH));let S=[];v===`loading`&&S.push(this._fillSkeleton(x,e,n)),v===`empty`&&S.push(this._emptyBlock(e)),v===`error`&&S.push(this._stateBlock(`error`,e.errorText||r.errorText));let C=this._head(b),w=K(`div`,`wui-gantt-plot`);w.append(C,x);let T=K(`div`,`wui-gantt-scroller`);if(t===`table`){let t=k({title:e.title,rows:y?.rows??[],headHeight:2*d.tierH,selected:this._selected,text:r,focusAttr:L,skeleton:v===`loading`?{rows:V,rowHeight:n.rowH,barHeight:n.barH}:void 0});T.append(t,w)}else T.append(w);return[this._toolbar(e,v===`ready`),T,...S,this._legend(t)]}_toolbar(e,t){let n=K(`div`,`wui-gantt-toolbar`);return t&&n.append(K(`p`,`wui-gantt-count`,this._countText(e.rows))),n.append(this._scale(),this._nav()),n}_countText(e){let t=A(),n=e.filter(e=>e.start!==void 0),r=n.filter(e=>e.end===void 0).length,i=1/0,a=-1/0;for(let e of n)i=Math.min(i,l(e.start??``)),a=Math.max(a,l(e.end??e.start??``));return[y(t,`summaryTasks`,n.length-r),y(t,`summaryMilestones`,r),x(t.summaryRange,{from:f(i),to:f(a)})].join(`, `)}_scale(){let e=A(),t=K(`div`,`segmented segmented-sm wui-gantt-scale`);t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-label`,e.scaleLabel),t.append(Object.assign(K(`span`,`segmented-thumb`),{ariaHidden:`true`}));let n={day:e.dayLabel,week:e.weekLabel,month:e.monthLabel};for(let e of B){let r=K(`label`,`segmented-option`),i=K(`input`,`segmented-input`);i.type=`radio`,i.name=`${this.uid}-scale`,i.value=e,i.checked=e===this._zoom,i.setAttribute(L,`zoom:${e}`),r.append(i,n[e]),t.append(r)}return t}_placeThumb(){let e=this.querySelector(`.wui-gantt-scale`),t=e?.querySelector(`.segmented-thumb`),n=e?.querySelector(`.segmented-option:has(.segmented-input:checked)`);e instanceof HTMLElement&&t instanceof HTMLElement&&n instanceof HTMLElement&&e.offsetWidth&&(t.style.width=q(n.offsetWidth),t.style.transform=`translateX(${n.offsetLeft}px)`,t.style.opacity=`1`)}_nav(){let t=A(),n=K(`div`,`wui-gantt-nav`),r=(t,n,r)=>{let i=K(`button`,e(`neutral`,`soft`,`sm`));return i.type=`button`,i.setAttribute(`aria-label`,n),i.setAttribute(L,t),i.innerHTML=v(r,{size:16}),i},i=K(`button`,e(`neutral`,`soft`,`sm`),t.todayLabel);return i.type=`button`,i.setAttribute(L,`nav:today`),n.append(r(`nav:earlier`,t.earlierLabel,`chevron-left`),r(`nav:later`,t.laterLabel,`chevron-right`),i),n}_head(e){let t=K(`div`,`wui-gantt-head`);t.style.width=q(e.width),t.setAttribute(`aria-hidden`,`true`);let n=(e,t)=>{let n=K(`div`,`wui-gantt-tier ${t}`);for(let t of e){let e=K(`div`,t.weekend?`wui-gantt-cell wui-gantt-cell-weekend`:`wui-gantt-cell`);e.style.left=q(t.x),e.style.width=q(t.w),t.sub&&e.append(K(`small`,null,t.sub)),e.append(t.label),n.append(e)}return n};return t.append(n(e.top,`wui-gantt-tier-top`),n(e.bottom,`wui-gantt-tier-bottom`)),t}_legend(e){let t=A(),n=K(`div`,`wui-gantt-legend`);n.setAttribute(`role`,`list`),n.setAttribute(`aria-label`,t.legendLabel);let r=(e,t)=>{let r=K(`span`,null);r.setAttribute(`role`,`listitem`),r.append(e,t),n.append(r)};for(let e of[`done`,`inProgress`,`atRisk`,`notStarted`]){let t=K(`span`,`wui-gantt-swatch`);t.dataset.status=e,r(t,Y(e))}let i=K(`span`,`wui-gantt-swatch`);if(i.dataset.kind=`milestone`,r(i,t.milestoneLabel),e===`table`){let e=K(`span`,`wui-gantt-legend-note`,t.legendRemaining);e.setAttribute(`role`,`listitem`),n.append(e)}return n}_stateBlock(t,n){let r=A(),i=K(`div`,`wui-gantt-state`);if(t===`error`){i.setAttribute(`role`,`alert`),i.append(K(`p`,null,n));let t=K(`button`,e(`neutral`,`soft`,`sm`),r.retryLabel);t.type=`button`,t.setAttribute(L,`retry`),i.append(t)}else i.append(K(`p`,null,n));return i}_emptyBlock(t){let n=A(),r=K(`div`,`wui-gantt-state`);if(r.append(K(`p`,`fw-semibold`,n.emptyTitle),K(`p`,null,t.emptyText||n.emptyText)),t.addTask){let t=K(`button`,e(`primary`,`solid`,`sm`),n.addTaskLabel);t.type=`button`,t.setAttribute(L,`add`),r.append(t)}return r}_fillSkeleton(e,t,n){let r=K(`div`,`visually-hidden`,t.loadingText||A().loadingText);r.setAttribute(`role`,`status`);for(let t=0;t<V;t+=1){let r=K(`div`,`wui-gantt-skeleton`);r.style.top=q(t*n.rowH+n.barTop),r.style.left=q(40+t*60),r.style.width=q(240),r.style.height=q(n.barH),r.setAttribute(`aria-hidden`,`true`),e.append(r)}return r}_fillLane(e,t,n){let r=A(),{axis:i}=n,a=n.layout===`table`;e.style.height=q(n.height),e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,t.title);let o=K(`p`,`visually-hidden`,a?r.helpTextTable:r.helpText);o.id=`${this.uid}-help`,e.setAttribute(`aria-describedby`,o.id);let s=(e,t,n,r,i)=>{let a=K(`div`,e);return a.setAttribute(`aria-hidden`,`true`),a.style.left=q(t),a.style.top=q(n),a.style.width=q(r),a.style.height=q(i),a},c=[o];for(let e of n.rows){if(e.height===0)continue;let t=s(`wui-gantt-row`,0,e.top,i.width,e.height);a&&e.kind!==`group`&&e.row.key===this._selected&&(t.dataset.selected=`true`),c.push(t)}for(let e of i.weekendX)c.push(s(`wui-gantt-weekend`,e,0,i.ppd,n.height));for(let e of i.gridX)c.push(s(`wui-gantt-grid`,e,0,1,n.height));if(n.today.inWindow){c.push(s(`wui-gantt-today`,n.today.x-1,0,2,n.height));let e=K(`div`,`wui-gantt-today-flag rounded-pill`,r.todayLabel);e.style.left=q(n.today.x),c.push(e)}let l=new Map(t.rows.map(e=>[e.key,e]));for(let e of n.rows){if(e.hidden)continue;let t=K(`div`,`wui-gantt-item`);t.setAttribute(`role`,`listitem`),t.style.display=`contents`,e.kind===`group`?this._drawGroup(t,e,n):e.kind===`milestone`?this._drawMilestone(t,e,l,n):this._drawBar(t,e,l,n),c.push(t)}c.push(this._deps(n)),this._card=a?null:this._details(n,l),e.append(...c);let u=e.querySelector(`[${L}^="${R}"]`);u instanceof HTMLElement&&(u.tabIndex=0)}_names(e,t){return(e.dependsOn??[]).map(e=>t.get(e)?.name??e).join(`, `)}_barSentence(e,t){let n=A(),r=this._names(e,t);if(e.end===void 0){let t=f(l(e.start??``));return r?x(n.milestoneBarLabel,{name:e.name,date:t,names:r}):`${e.name}, ${t}, ${n.milestoneLabel.toLowerCase()}`}let i=x(n.barLabel,{name:e.name,start:f(l(e.start??``)),end:f(l(e.end)),percent:X(e),status:Y(Z(e)).toLowerCase()});return r?x(n.barLabelAfter,{label:i,names:r}):i}_focusable(e,t,n,r){let i=K(`button`,t);i.type=`button`;let a=this._barSentence(e,n);return i.setAttribute(`aria-label`,a),i.title=a,i.tabIndex=-1,i.dataset.status=Z(e),i.dataset.wuiGanttKey=e.key,i.setAttribute(L,`${R}${e.key}`),r?i.setAttribute(`aria-pressed`,String(this._selected===e.key)):i.setAttribute(`aria-expanded`,String(this._selected===e.key)),this._selected===e.key&&(i.dataset.selected=`true`),i}_afterLabel(e,t,n,r){let i=K(`span`,`wui-gantt-label wui-gantt-label-surface`,e);return i.style.left=q(t),i.style.top=q(n),i.style.height=q(r),i}_drawBar(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=this._focusable(i,`wui-gantt-bar rounded-2`,n,o),c=t.top+a.barTop;s.style.left=q(t.x),s.style.width=q(t.w),s.style.top=q(c),s.style.height=q(a.barH);let l=X(i),u=K(`span`,`wui-gantt-bar-progress`);if(u.style.width=`${l}%`,s.append(u),e.append(s),o)return;let d=`${i.name} ${l}%`;t.place===`inside`?s.append(K(`span`,`wui-gantt-bar-label`,d)):e.append(this._afterLabel(d,t.x+t.w+H,c,a.barH))}_drawMilestone(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=d.milestone/2,c=t.top+(a.rowH-d.milestone)/2,u=this._focusable(i,`wui-gantt-milestone`,n,o);if(u.style.left=q(t.x-s),u.style.top=q(c),u.style.width=q(d.milestone),u.style.height=q(d.milestone),e.append(u),o)return;let p=this._afterLabel(`${i.name}, ${f(l(i.start??``))}`,t.x+d.milestone,t.top+a.barTop,a.barH);t.flip&&(p.style.left=``,p.style.right=q(r.axis.width-(t.x-d.milestone))),e.append(p)}_drawGroup(e,t,n){let r=A(),i=t.group;if(!i)return;if(n.layout===`lanes`){let n=K(`div`,`wui-gantt-group wui-gantt-label wui-gantt-label-surface`);n.dataset.wuiGanttGroup=i.name,n.style.left=q(8),n.style.top=q(t.top+6);let a=K(`button`,`wui-gantt-group-toggle`);a.type=`button`,a.setAttribute(`aria-expanded`,String(!i.folded)),a.setAttribute(`aria-label`,x(i.folded?r.unfoldLabel:r.foldLabel,{group:i.name})),a.setAttribute(L,`group:${i.name}`),a.innerHTML=v(i.folded?`chevron-right`:`chevron-down`,{size:16}),n.append(a,K(`span`,null,i.name),K(`span`,null,y(r,`groupSummary`,i.count,{percent:i.percent}))),e.append(n)}let a=K(`div`,`wui-gantt-group-summary`);a.dataset.wuiGanttGroup=i.name,a.style.left=q(t.x),a.style.width=q(t.w),a.style.top=q(t.top+n.geometry.groupBarTop),a.style.height=q(d.groupBarH),e.append(a)}_deps(e){let t=document.createElementNS(z,`svg`);t.setAttribute(`class`,`wui-gantt-deps`),t.setAttribute(`aria-hidden`,`true`),t.setAttribute(`width`,String(e.axis.width)),t.setAttribute(`height`,String(e.height));for(let n of e.arrows){let e=document.createElementNS(z,`path`);e.setAttribute(`d`,n.d),e.setAttribute(`fill`,`none`);let r=document.createElementNS(z,`polygon`);r.setAttribute(`points`,n.head),e.dataset.from=n.fromKey,e.dataset.to=n.toKey,t.append(e,r)}return t}_details(t,n){let r=this._selected,i=r===null?void 0:t.rows.find(e=>e.row.key===r&&e.kind!==`group`&&!e.hidden);if(!i)return null;let a=A(),{row:o}=i,s=K(`div`,`wui-gantt-details`);s.setAttribute(`role`,`group`),s.setAttribute(`aria-label`,o.name),s.style.width=q(U);let c=K(`dl`),u=(e,t)=>{c.append(K(`dt`,null,e),K(`dd`,null,t))},d=f(l(o.start??``));o.owner&&u(a.detailsOwner,o.owner),u(a.detailsDates,o.end===void 0?d:x(a.detailsRange,{start:d,end:f(l(o.end))})),o.end!==void 0&&u(a.detailsDone,`${X(o)}%, ${Y(Z(o))}`);let p=this._names(o,n);p&&u(a.detailsStartsAfter,p);let m=K(`button`,e(`neutral`,`ghost`,`sm`),a.detailsCloseLabel);return m.type=`button`,m.setAttribute(L,`close`),s.append(K(`h3`,`h6`,o.name),c,m),s}};export{$ as t};
|
|
1
|
+
import{n as e}from"./buttonClass-GtEi8hAY.js";import{t}from"./devWarn-DXdRWZs3.js";import{r as n}from"./dom-Do1pAA12.js";import{t as r}from"./elementBase-Cxeyx0tU.js";import{a as i,c as a,d as o,f as s,i as c,l,m as u,n as d,o as f,p,s as m,t as h,u as g}from"./initials-Qb6ITcri.js";import{t as _}from"./avatarHtml-BWlA0cm-.js";import{t as v}from"./iconGlyphs.g-BUF97bUu.js";import{n as y,r as b,t as x}from"./textStore-opIEM4lu.js";import{a as S,l as C}from"./nativeOverlay-DGady-wN.js";import{t as w}from"./gantt.g-TdTxeruW.js";var T=`data-wui-gantt-pick`,E=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},D=e=>`${e}px`,O=(e,t,n)=>{let r=E(`div`,`wui-gantt-table-cell`,n);return r.setAttribute(`role`,t),r.dataset.col=e,r};function k(e){let t=e.text,n=E(`div`,`wui-gantt-table`);n.setAttribute(`role`,`table`),n.setAttribute(`aria-label`,e.title);let r=E(`div`);r.setAttribute(`role`,`rowgroup`);let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=`head`,i.setAttribute(`role`,`row`),i.style.height=D(e.headHeight),i.append(O(`name`,`columnheader`,t.tableName),O(`owner`,`columnheader`,t.detailsOwner),O(`start`,`columnheader`,t.tableStart),O(`end`,`columnheader`,t.tableEnd),O(`done`,`columnheader`,t.detailsDone)),r.append(i);let a=E(`div`);a.setAttribute(`role`,`rowgroup`);for(let n of e.rows){if(n.height===0)continue;let r=n.row;if(n.kind===`group`){let r=n.group;if(!r)continue;let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=`group`,i.dataset.wuiGanttGroup=r.name,i.setAttribute(`role`,`row`),i.style.height=D(n.height);let o=E(`div`,`wui-gantt-table-cell wui-gantt-table-group`);o.setAttribute(`role`,`rowheader`);let s=E(`button`,`wui-gantt-group-toggle`);s.type=`button`,s.setAttribute(`aria-expanded`,String(!r.folded)),s.setAttribute(`aria-label`,x(r.folded?t.unfoldLabel:t.foldLabel,{group:r.name})),s.setAttribute(e.focusAttr,`group:${r.name}`),s.innerHTML=v(r.folded?`chevron-right`:`chevron-down`,{size:16}),o.append(s,E(`span`,null,r.name),E(`span`,null,y(t,`groupSummary`,r.count,{percent:r.percent}))),i.append(o),a.append(i);continue}let i=E(`div`,`wui-gantt-table-row`);i.dataset.kind=r.end===void 0?`milestone`:`bar`,i.dataset.wuiGanttKey=r.key,i.dataset.wuiGanttPick=r.key,r.key===e.selected&&(i.dataset.selected=`true`),i.setAttribute(`role`,`row`),i.style.height=D(n.height);let o=O(`name`,`rowheader`,r.name);o.title=r.name;let s=O(`owner`,`cell`,``);r.owner&&(s.title=r.owner,s.innerHTML=_({initials:h(r.owner)},`avatar-xs`),s.append(E(`span`,`visually-hidden`,r.owner)));let c=O(`start`,`cell`,r.start===void 0?``:f(l(r.start))),u=O(`end`,`cell`,r.end===void 0?``:f(l(r.end))),d=O(`done`,`cell`,r.end===void 0?``:`${r.progress??0}%`);i.append(o,s,c,u,d),a.append(i)}let o=e.skeleton;for(let e=0;o&&e<o.rows;e+=1){let e=E(`div`,`wui-gantt-table-row`);e.dataset.kind=`skeleton`,e.setAttribute(`role`,`row`),e.setAttribute(`aria-hidden`,`true`),e.style.height=D(o.rowHeight);let t=E(`span`,`wui-gantt-skeleton`);t.style.height=D(o.barHeight),e.append(t),a.append(e)}return n.append(r,a),n}var A=()=>b(`gantt`,w),j=`wui-gantt:zoom-change`,M=`wui-gantt:from-change`,N=`wui-gantt:fold-change`,P=`wui-gantt:select`,F=`wui-gantt:add-task`,I=`wui-gantt:retry`,L=`data-wui-gantt-focus`,R=`bar:`,z=`http://www.w3.org/2000/svg`,B=[`day`,`week`,`month`],V=3,H=16,U=300,W=[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`,`Escape`,`Enter`,` `],G=0,K=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},q=e=>`${e}px`;function J(e){return typeof e==`object`&&!!e&&`rows`in e&&Array.isArray(e.rows)&&`title`in e&&typeof e.title==`string`}function Y(e){let t=A();switch(e){case`done`:return t.statusDone;case`inProgress`:return t.statusInProgress;case`atRisk`:return t.statusAtRisk;case`notStarted`:return t.statusNotStarted;default:throw RangeError(`Unknown gantt status ${String(e)}.`)}}var X=e=>e.progress??0,Z=e=>e.status??`notStarted`,Q=(e,t)=>(e??[]).join(`\0`)===(t??[]).join(`\0`),$=class extends r{uid;_spec=null;_prev=null;_zoom=`week`;_fromMs=null;_folded=/* @__PURE__ */ new Set;_selected=null;_controlled=!1;_awaitingSpec=!1;_connected=!1;_focusAfter=null;_resolved=null;_specRows=[];_card=null;_onClick;_onKeyDown;_onChange;constructor(){super(),G+=1,this.uid=`wui-gantt-${G}`,this._onClick=e=>this._handleClick(e),this._onKeyDown=e=>this._handleKeyDown(e),this._onChange=e=>this._handleChange(e)}get spec(){return this._spec}set spec(e){this._spec=e??null,this._connected&&this._draw()}connectedCallback(){if(Object.hasOwn(this,`spec`)){let e=this.spec;delete this.spec,this._spec=e??null}this._spec??=this._readScript(),this._spec==null&&!this.querySelector(`:scope > script[type='application/json']`)&&(this._awaitingSpec=!0,queueMicrotask(()=>{this._awaitingSpec=!1,this._connected&&this._draw()})),this.classList.add(`wui-gantt`),this.addEventListener(`click`,this._onClick),this.addEventListener(`keydown`,this._onKeyDown),this.addEventListener(`change`,this._onChange),this._connected=!0,this._draw()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this.removeEventListener(`keydown`,this._onKeyDown),this.removeEventListener(`change`,this._onChange),this._card&&=(S(this._card),this._card.remove(),null),this._connected=!1}_readScript(){let e=this.querySelector(`:scope > script[type="application/json"]`);if(!(e instanceof HTMLScriptElement))return null;try{return JSON.parse(String(e.textContent))}catch(e){return t(`[@webority/ui-elements] <wui-gantt> could not read its JSON spec:`,e instanceof Error?e.message:void 0),null}}_seed(e){let t=this._prev;this._controlled=e.controlled===!0;let n=e=>this._controlled||t===null||e;n(t?.zoom!==e.zoom)&&(this._zoom=e.zoom??`week`),n(t?.from!==e.from)&&(this._fromMs=e.from?l(e.from):null),n(!Q(t?.folded,e.folded))&&(this._folded=new Set(e.folded??[])),n(t?.selected!==e.selected)&&(this._selected=e.selected??null),this._prev=e}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_setZoom(e){this._emit(j,{zoom:e}),this._controlled?this._syncRadios():(this._zoom=e,this._fromMs=this._fromMs===null?null:o(e,this._fromMs),this._draw())}_setFrom(e){this._emit(M,{from:m(e)}),this._controlled||(this._fromMs=e,this._draw())}_setFolded(e){let t=new Set(this._folded);t.delete(e)||t.add(e),this._emit(N,{folded:[...t]}),this._controlled||(this._folded=t,this._draw())}_setSelected(e){this._emit(P,{key:e}),this._focusAfter=`${R}${e??this._selected??``}`,this._controlled||(this._selected=e),this._draw()}_syncRadios(){for(let e of this.querySelectorAll(`.segmented-input`))e.checked=e.value===this._zoom}_handleChange(e){let t=e.target;if(!(t instanceof HTMLInputElement)||!t.matches(`.wui-gantt-scale .segmented-input`))return;let n=B.find(e=>e===t.value);n&&this._setZoom(n)}_handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`[${L}]`);if(n instanceof HTMLElement&&this.contains(n)){this._activate(n.getAttribute(L)??``,n);return}let r=t.closest(`[${T}]`);if(!(r instanceof HTMLElement)||!this.contains(r))return;let i=r.getAttribute(`data-wui-gantt-pick`)??``;this._setSelected(i===this._selected?null:i)}_activate(e,t){let n=this._resolved;if(e.startsWith(R)){let t=e.slice(4);this._setSelected(t===this._selected?null:t)}else e.startsWith(`group:`)?this._setFolded(e.slice(6)):e===`close`?this._setSelected(null):e===`add`?this._emit(F):e===`retry`?this._emit(I):n&&e===`nav:earlier`?this._setFrom(g(n.zoom,n.fromMs,-1)):n&&e===`nav:later`?this._setFrom(g(n.zoom,n.fromMs,1)):n&&e===`nav:today`?this._setFrom(u(n.zoom,n.todayMs)):e.startsWith(`zoom:`)&&t.click()}_bars(){return[...this.querySelectorAll(`.wui-gantt-lane [${L}^="${R}"]`)].filter(e=>e instanceof HTMLElement)}_focusBar(e){if(e){for(let t of this._bars())t.tabIndex=t===e?0:-1;e.focus()}}_barByKey(e){return e===void 0?void 0:this._bars().find(t=>t.dataset.wuiGanttKey===e)}_handleKeyDown(e){if(e.ctrlKey||e.metaKey||e.altKey||!W.includes(e.key))return;if(e.key===`Escape`){if(this._selected===null)return;e.preventDefault(),this._setSelected(null);return}let t=e.target;if(!(t instanceof HTMLElement)||!t.getAttribute(L)?.startsWith(R))return;let n=this._bars(),r=n.indexOf(t),i=t.dataset.wuiGanttKey,a=this._specRows.find(e=>e.key===i);switch(e.preventDefault(),e.key){case`ArrowDown`:this._focusBar(n[r+1]);break;case`ArrowUp`:this._focusBar(n[r-1]);break;case`Home`:this._focusBar(n[0]);break;case`End`:this._focusBar(n.at(-1));break;case`ArrowLeft`:this._focusBar((a?.dependsOn??[]).map(e=>this._barByKey(e)).find(e=>e));break;case`ArrowRight`:this._focusBar(this._specRows.filter(e=>e.dependsOn?.includes(i??``)).map(e=>this._barByKey(e.key)).find(e=>e));break;default:this._activate(t.getAttribute(L)??``,t)}}_focusToken(){let e=document.activeElement;return e instanceof HTMLElement&&this.contains(e)?e.getAttribute(L):null}_draw(){if(this._card&&=(S(this._card),this._card.remove(),null),this._spec==null&&this._awaitingSpec)return;let e=this._focusAfter??this._focusToken();this._focusAfter=null;let r;try{r=this._compose()}catch(e){t(`[@webority/ui-elements] <wui-gantt> could not draw its spec:`,e instanceof Error?e.message:void 0),this._resolved=null,this._specRows=[],this._card=null,this.dataset.state=`error`,this.removeAttribute(`aria-busy`),r=[this._stateBlock(`error`,A().errorText)]}if(this.replaceChildren(...r),this._card){let e=n(this._barByKey(this._selected??void 0),`selected gantt bar`);this.append(this._card),C(e,this._card,{mode:`manual`,side:`auto`,align:`start`,flipAlign:!0,gap:4,keepOffscreen:!0})}if(this._placeThumb(),e===null)return;let i=[...this.querySelectorAll(`[${L}]`)].find(t=>t.getAttribute(L)===e);i instanceof HTMLElement&&(e.startsWith(R)?this._focusBar(i):i.focus())}_compose(){let e=this._spec;if(!J(e))throw TypeError("<wui-gantt> has no spec: set the `spec` property or add a JSON script child.");this._seed(e),p(e);let t=e.layout??`table`,n=c[t],r=A(),f=l(e.today??s()),m=this._zoom,h=o(m,this._fromMs??u(m,f)),g={layout:t,zoom:m,fromMs:h,todayMs:f};this._resolved=g,this._specRows=e.rows;let _=e.rows.some(e=>e.start!==void 0),v=(e.state??`ready`)===`ready`&&!_?`empty`:e.state??`ready`;this.dataset.state=v,this.dataset.zoom=m,this.dataset.layout=t,v===`loading`?this.setAttribute(`aria-busy`,`true`):this.removeAttribute(`aria-busy`);let y=v===`ready`?a({...e,folded:[...this._folded],selected:this._selected},g):null,b=y?.axis??i(t,m,h),x=K(`div`,`wui-gantt-lane`);x.style.width=q(b.width),y?this._fillLane(x,e,y):v===`loading`&&(x.style.height=q(V*n.rowH));let S=[];v===`loading`&&S.push(this._fillSkeleton(x,e,n)),v===`empty`&&S.push(this._emptyBlock(e)),v===`error`&&S.push(this._stateBlock(`error`,e.errorText||r.errorText));let C=this._head(b),w=K(`div`,`wui-gantt-plot`);w.append(C,x);let T=K(`div`,`wui-gantt-scroller`);if(t===`table`){let t=k({title:e.title,rows:y?.rows??[],headHeight:2*d.tierH,selected:this._selected,text:r,focusAttr:L,skeleton:v===`loading`?{rows:V,rowHeight:n.rowH,barHeight:n.barH}:void 0});T.append(t,w)}else T.append(w);return[this._toolbar(e,v===`ready`),T,...S,this._legend(t)]}_toolbar(e,t){let n=K(`div`,`wui-gantt-toolbar`);return t&&n.append(K(`p`,`wui-gantt-count`,this._countText(e.rows))),n.append(this._scale(),this._nav()),n}_countText(e){let t=A(),n=e.filter(e=>e.start!==void 0),r=n.filter(e=>e.end===void 0).length,i=1/0,a=-1/0;for(let e of n)i=Math.min(i,l(e.start??``)),a=Math.max(a,l(e.end??e.start??``));return[y(t,`summaryTasks`,n.length-r),y(t,`summaryMilestones`,r),x(t.summaryRange,{from:f(i),to:f(a)})].join(`, `)}_scale(){let e=A(),t=K(`div`,`segmented segmented-sm wui-gantt-scale`);t.setAttribute(`role`,`radiogroup`),t.setAttribute(`aria-label`,e.scaleLabel),t.append(Object.assign(K(`span`,`segmented-thumb`),{ariaHidden:`true`}));let n={day:e.dayLabel,week:e.weekLabel,month:e.monthLabel};for(let e of B){let r=K(`label`,`segmented-option`),i=K(`input`,`segmented-input`);i.type=`radio`,i.name=`${this.uid}-scale`,i.value=e,i.checked=e===this._zoom,i.setAttribute(L,`zoom:${e}`),r.append(i,n[e]),t.append(r)}return t}_placeThumb(){let e=this.querySelector(`.wui-gantt-scale`),t=e?.querySelector(`.segmented-thumb`),n=e?.querySelector(`.segmented-option:has(.segmented-input:checked)`);e instanceof HTMLElement&&t instanceof HTMLElement&&n instanceof HTMLElement&&e.offsetWidth&&(t.style.width=q(n.offsetWidth),t.style.transform=`translateX(${n.offsetLeft}px)`,t.style.opacity=`1`)}_nav(){let t=A(),n=K(`div`,`wui-gantt-nav`),r=(t,n,r)=>{let i=K(`button`,e(`neutral`,`soft`,`sm`));return i.type=`button`,i.setAttribute(`aria-label`,n),i.setAttribute(L,t),i.innerHTML=v(r,{size:16}),i},i=K(`button`,e(`neutral`,`soft`,`sm`),t.todayLabel);return i.type=`button`,i.setAttribute(L,`nav:today`),n.append(r(`nav:earlier`,t.earlierLabel,`chevron-left`),r(`nav:later`,t.laterLabel,`chevron-right`),i),n}_head(e){let t=K(`div`,`wui-gantt-head`);t.style.width=q(e.width),t.setAttribute(`aria-hidden`,`true`);let n=(e,t)=>{let n=K(`div`,`wui-gantt-tier ${t}`);for(let t of e){let e=K(`div`,t.weekend?`wui-gantt-cell wui-gantt-cell-weekend`:`wui-gantt-cell`);e.style.left=q(t.x),e.style.width=q(t.w),t.sub&&e.append(K(`small`,null,t.sub)),e.append(t.label),n.append(e)}return n};return t.append(n(e.top,`wui-gantt-tier-top`),n(e.bottom,`wui-gantt-tier-bottom`)),t}_legend(e){let t=A(),n=K(`div`,`wui-gantt-legend`);n.setAttribute(`role`,`list`),n.setAttribute(`aria-label`,t.legendLabel);let r=(e,t)=>{let r=K(`span`,null);r.setAttribute(`role`,`listitem`),r.append(e,t),n.append(r)};for(let e of[`done`,`inProgress`,`atRisk`,`notStarted`]){let t=K(`span`,`wui-gantt-swatch`);t.dataset.status=e,r(t,Y(e))}let i=K(`span`,`wui-gantt-swatch`);if(i.dataset.kind=`milestone`,r(i,t.milestoneLabel),e===`table`){let e=K(`span`,`wui-gantt-legend-note`,t.legendRemaining);e.setAttribute(`role`,`listitem`),n.append(e)}return n}_stateBlock(t,n){let r=A(),i=K(`div`,`wui-gantt-state`);if(t===`error`){i.setAttribute(`role`,`alert`),i.append(K(`p`,null,n));let t=K(`button`,e(`neutral`,`soft`,`sm`),r.retryLabel);t.type=`button`,t.setAttribute(L,`retry`),i.append(t)}else i.append(K(`p`,null,n));return i}_emptyBlock(t){let n=A(),r=K(`div`,`wui-gantt-state`);if(r.append(K(`p`,`fw-semibold`,n.emptyTitle),K(`p`,null,t.emptyText||n.emptyText)),t.addTask){let t=K(`button`,e(`primary`,`solid`,`sm`),n.addTaskLabel);t.type=`button`,t.setAttribute(L,`add`),r.append(t)}return r}_fillSkeleton(e,t,n){let r=K(`div`,`visually-hidden`,t.loadingText||A().loadingText);r.setAttribute(`role`,`status`);for(let t=0;t<V;t+=1){let r=K(`div`,`wui-gantt-skeleton`);r.style.top=q(t*n.rowH+n.barTop),r.style.left=q(40+t*60),r.style.width=q(240),r.style.height=q(n.barH),r.setAttribute(`aria-hidden`,`true`),e.append(r)}return r}_fillLane(e,t,n){let r=A(),{axis:i}=n,a=n.layout===`table`;e.style.height=q(n.height),e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,t.title);let o=K(`p`,`visually-hidden`,a?r.helpTextTable:r.helpText);o.id=`${this.uid}-help`,e.setAttribute(`aria-describedby`,o.id);let s=(e,t,n,r,i)=>{let a=K(`div`,e);return a.setAttribute(`aria-hidden`,`true`),a.style.left=q(t),a.style.top=q(n),a.style.width=q(r),a.style.height=q(i),a},c=[o];for(let e of n.rows){if(e.height===0)continue;let t=s(`wui-gantt-row`,0,e.top,i.width,e.height);a&&e.kind!==`group`&&e.row.key===this._selected&&(t.dataset.selected=`true`),c.push(t)}for(let e of i.weekendX)c.push(s(`wui-gantt-weekend`,e,0,i.ppd,n.height));for(let e of i.gridX)c.push(s(`wui-gantt-grid`,e,0,1,n.height));if(n.today.inWindow){c.push(s(`wui-gantt-today`,n.today.x-1,0,2,n.height));let e=K(`div`,`wui-gantt-today-flag rounded-pill`,r.todayLabel);e.style.left=q(n.today.x),c.push(e)}let l=new Map(t.rows.map(e=>[e.key,e]));for(let e of n.rows){if(e.hidden)continue;let t=K(`div`,`wui-gantt-item`);t.setAttribute(`role`,`listitem`),t.style.display=`contents`,e.kind===`group`?this._drawGroup(t,e,n):e.kind===`milestone`?this._drawMilestone(t,e,l,n):this._drawBar(t,e,l,n),c.push(t)}c.push(this._deps(n)),this._card=a?null:this._details(n,l),e.append(...c);let u=e.querySelector(`[${L}^="${R}"]`);u instanceof HTMLElement&&(u.tabIndex=0)}_names(e,t){return(e.dependsOn??[]).map(e=>t.get(e)?.name??e).join(`, `)}_barSentence(e,t){let n=A(),r=this._names(e,t);if(e.end===void 0){let t=f(l(e.start??``));return r?x(n.milestoneBarLabel,{name:e.name,date:t,names:r}):`${e.name}, ${t}, ${n.milestoneLabel.toLowerCase()}`}let i=x(n.barLabel,{name:e.name,start:f(l(e.start??``)),end:f(l(e.end)),percent:X(e),status:Y(Z(e)).toLowerCase()});return r?x(n.barLabelAfter,{label:i,names:r}):i}_focusable(e,t,n,r){let i=K(`button`,t);i.type=`button`;let a=this._barSentence(e,n);return i.setAttribute(`aria-label`,a),i.title=a,i.tabIndex=-1,i.dataset.status=Z(e),i.dataset.wuiGanttKey=e.key,i.setAttribute(L,`${R}${e.key}`),r?i.setAttribute(`aria-pressed`,String(this._selected===e.key)):i.setAttribute(`aria-expanded`,String(this._selected===e.key)),this._selected===e.key&&(i.dataset.selected=`true`),i}_afterLabel(e,t,n,r){let i=K(`span`,`wui-gantt-label wui-gantt-label-surface`,e);return i.style.left=q(t),i.style.top=q(n),i.style.height=q(r),i}_drawBar(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=this._focusable(i,`wui-gantt-bar rounded-2`,n,o),c=t.top+a.barTop;s.style.left=q(t.x),s.style.width=q(t.w),s.style.top=q(c),s.style.height=q(a.barH);let l=X(i),u=K(`span`,`wui-gantt-bar-progress`);if(u.style.width=`${l}%`,s.append(u),e.append(s),o)return;let d=`${i.name} ${l}%`;t.place===`inside`?s.append(K(`span`,`wui-gantt-bar-label`,d)):e.append(this._afterLabel(d,t.x+t.w+H,c,a.barH))}_drawMilestone(e,t,n,r){let{row:i}=t,{geometry:a}=r,o=r.layout===`table`,s=d.milestone/2,c=t.top+(a.rowH-d.milestone)/2,u=this._focusable(i,`wui-gantt-milestone`,n,o);if(u.style.left=q(t.x-s),u.style.top=q(c),u.style.width=q(d.milestone),u.style.height=q(d.milestone),e.append(u),o)return;let p=this._afterLabel(`${i.name}, ${f(l(i.start??``))}`,t.x+d.milestone,t.top+a.barTop,a.barH);t.flip&&(p.style.left=``,p.style.right=q(r.axis.width-(t.x-d.milestone))),e.append(p)}_drawGroup(e,t,n){let r=A(),i=t.group;if(!i)return;if(n.layout===`lanes`){let n=K(`div`,`wui-gantt-group wui-gantt-label wui-gantt-label-surface`);n.dataset.wuiGanttGroup=i.name,n.style.left=q(8),n.style.top=q(t.top+6);let a=K(`button`,`wui-gantt-group-toggle`);a.type=`button`,a.setAttribute(`aria-expanded`,String(!i.folded)),a.setAttribute(`aria-label`,x(i.folded?r.unfoldLabel:r.foldLabel,{group:i.name})),a.setAttribute(L,`group:${i.name}`),a.innerHTML=v(i.folded?`chevron-right`:`chevron-down`,{size:16}),n.append(a,K(`span`,null,i.name),K(`span`,null,y(r,`groupSummary`,i.count,{percent:i.percent}))),e.append(n)}let a=K(`div`,`wui-gantt-group-summary`);a.dataset.wuiGanttGroup=i.name,a.style.left=q(t.x),a.style.width=q(t.w),a.style.top=q(t.top+n.geometry.groupBarTop),a.style.height=q(d.groupBarH),e.append(a)}_deps(e){let t=document.createElementNS(z,`svg`);t.setAttribute(`class`,`wui-gantt-deps`),t.setAttribute(`aria-hidden`,`true`),t.setAttribute(`width`,String(e.axis.width)),t.setAttribute(`height`,String(e.height));for(let n of e.arrows){let e=document.createElementNS(z,`path`);e.setAttribute(`d`,n.d),e.setAttribute(`fill`,`none`);let r=document.createElementNS(z,`polygon`);r.setAttribute(`points`,n.head),e.dataset.from=n.fromKey,e.dataset.to=n.toKey,t.append(e,r)}return t}_details(t,n){let r=this._selected,i=r===null?void 0:t.rows.find(e=>e.row.key===r&&e.kind!==`group`&&!e.hidden);if(!i)return null;let a=A(),{row:o}=i,s=K(`div`,`wui-gantt-details`);s.setAttribute(`role`,`group`),s.setAttribute(`aria-label`,o.name),s.style.width=q(U);let c=K(`dl`),u=(e,t)=>{c.append(K(`dt`,null,e),K(`dd`,null,t))},d=f(l(o.start??``));o.owner&&u(a.detailsOwner,o.owner),u(a.detailsDates,o.end===void 0?d:x(a.detailsRange,{start:d,end:f(l(o.end))})),o.end!==void 0&&u(a.detailsDone,`${X(o)}%, ${Y(Z(o))}`);let p=this._names(o,n);p&&u(a.detailsStartsAfter,p);let m=K(`button`,e(`neutral`,`ghost`,`sm`),a.detailsCloseLabel);return m.type=`button`,m.setAttribute(L,`close`),s.append(K(`h3`,`h6`,o.name),c,m),s}};export{$ as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-Cxeyx0tU.js";import{a as t,l as n,s as r}from"./nativeOverlay-
|
|
1
|
+
import{t as e}from"./elementBase-Cxeyx0tU.js";import{a as t,l as n,s as r}from"./nativeOverlay-DGady-wN.js";var i=300,a=150,o=`.wui-hover-card-trigger`,s=`.wui-hover-card-panel`,c=`a[href],button,input,select,textarea,[tabindex]`,l=0;function u(e,t){let n=e.querySelector(t);return n instanceof HTMLElement?n:null}var d=class extends e{_doc;_timer;_described;_refocusing;_onOver;_onOut;_onFocusIn;_onFocusOut;_onKeyDown;static get observedAttributes(){return[`open`]}constructor(){super(),this._doc=null,this._timer=null,this._described=null,this._refocusing=!1,this._onOver=e=>{if(e.pointerType===`touch`||e.pointerType===`pen`)return;let t=this._zone(e.target);t===`panel`?this._clear():t===`trigger`&&this._schedule(!0)},this._onOut=e=>{e.pointerType!==`touch`&&e.pointerType!==`pen`&&this._zone(e.target)&&!this._zone(e.relatedTarget)&&this._schedule(!1)},this._onFocusIn=e=>{this._refocusing||(this._zone(e.target)===`trigger`?this._schedule(!0):this._zone(e.target)===`panel`&&this._clear())},this._onFocusOut=e=>{this._zone(e.target)&&!this._zone(e.relatedTarget)&&this._schedule(!1)},this._onKeyDown=e=>{if(e.key!==`Escape`||!this.isOpen||this.hasAttribute(`open`))return;e.preventDefault();let t=this._zone(this.ownerDocument.activeElement)===`panel`;this._clear(),this._setOpen(!1),t&&(this._refocusing=!0,this._anchor?.focus(),this._refocusing=!1)}}get isOpen(){let e=this._panel;return e!==null&&r(e)}connectedCallback(){this._doc=this.ownerDocument,this.addEventListener(`pointerover`,this._onOver),this.addEventListener(`pointerout`,this._onOut),this.addEventListener(`focusin`,this._onFocusIn),this.addEventListener(`focusout`,this._onFocusOut),this._syncOpen()}attributeChangedCallback(){this.isConnected&&this._syncOpen()}disconnectedCallback(){this._clear();let e=this._panel;e&&t(e),this.removeEventListener(`pointerover`,this._onOver),this.removeEventListener(`pointerout`,this._onOut),this.removeEventListener(`focusin`,this._onFocusIn),this.removeEventListener(`focusout`,this._onFocusOut),this._doc=null}get _trigger(){return u(this,o)}get _panel(){return u(this,s)}get _anchor(){let e=this._trigger;return e?u(e,c)??e:null}_zone(e){if(!(e instanceof Node)||!this.contains(e))return null;let t=e instanceof Element?e:e.parentElement;return this._panel?.contains(t)?`panel`:this._trigger?.contains(t)?`trigger`:null}_delay(e,t){let n=Number(this.getAttribute(e));return this.hasAttribute(e)&&Number.isFinite(n)&&n>=0?n:t}_clear(){this._timer!==null&&clearTimeout(this._timer),this._timer=null}_syncOpen(){this._clear(),this._setOpen(this.hasAttribute(`open`))}_schedule(e){if(!e&&this.hasAttribute(`open`)||(this._clear(),this.isOpen===e))return;let t=e?this._delay(`open-delay`,i):this._delay(`close-delay`,a);this._timer=setTimeout(()=>{this._timer=null,this._setOpen(e)},t)}_setOpen(e){let r=this._panel;if(!r||this.isOpen===e)return;if(!e){t(r);return}let i=this._trigger;if(!i)throw Error(`wui-hover-card: panel without a trigger`);n(i,r,{mode:`manual`,clampHeight:!0,keepOffscreen:this.hasAttribute(`open`),onClosed:()=>this._closed()}),this._doc?.addEventListener(`keydown`,this._onKeyDown,!0),this._describe(r),this.dispatchEvent(new CustomEvent(`wui:hover-card:open`,{bubbles:!0}))}_closed(){this._doc?.removeEventListener(`keydown`,this._onKeyDown,!0),this._described?.removeAttribute(`aria-describedby`),this._described=null,this.dispatchEvent(new CustomEvent(`wui:hover-card:close`,{bubbles:!0}))}_describe(e){let t=this._anchor;t&&(e.id||=`wui-hover-card-${++l}`,t.setAttribute(`aria-describedby`,e.id),this._described=t)}};export{d as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-Cxeyx0tU.js";import{f as t}from"./formatters-CMTSYlW9.js";import{t as n}from"./iconGlyphs.g-
|
|
1
|
+
import{t as e}from"./elementBase-Cxeyx0tU.js";import{f as t}from"./formatters-CMTSYlW9.js";import{t as n}from"./iconGlyphs.g-BUF97bUu.js";import{u as r}from"./nativeOverlay-DGady-wN.js";import{r as i,t as a}from"./textStore-opIEM4lu.js";import{t as o}from"./lightbox.g-DDrycPou.js";var s=`a.wui-lightbox-item`,c=1,l=4,u=.5,d=2,f=50,p=6,m=300,h=300;function g(e){return Number.isFinite(e)?Math.min(l,Math.max(c,e)):c}function _(e,t,n,r){let i=(e,n)=>Math.max(0,(e*t-n)/2),a=i(r.width,n.width),o=i(r.height,n.height);return{x:Math.min(a,Math.max(-a,e.x)),y:Math.min(o,Math.max(-o,e.y))}}function v(e,t){return Math.abs(e)<f||Math.abs(e)<Math.abs(t)*1.5?0:e<0?1:-1}function y(e){let t=(String(e??``).split(/[?#]/)[0]??``).split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}function b(e,t,n={}){let r=document.createElement(e);r.className=t;for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r}var x=()=>i(`lightbox`,o);function S(e,t,r){let i=b(`button`,`u-action wui-lightbox-btn ${r}`,{type:`button`,"aria-label":t,title:t});return i.style.setProperty(`--wui-action-size`,`40px`),i.innerHTML=n(e,{size:20}),i}var C=class extends e{_ui;_index;_zoom;_pan;_pointers;_gesture;_lastTap;_returnTo;_release;_onClick;static get observedAttributes(){return[`open-index`]}constructor(){super(),this._ui=null,this._index=0,this._zoom=c,this._pan={x:0,y:0},this._pointers=/* @__PURE__ */ new Map,this._gesture=null,this._lastTap=-1/0,this._returnTo=null,this._release=null,this._onClick=e=>{if(e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;let t=e.target,n=t instanceof Element?t.closest(s):null;if(!(n instanceof HTMLAnchorElement)||!this.contains(n))return;let r=this._links().indexOf(n);r<0||(e.preventDefault(),this.open(r))}}get _view(){if(!this._ui)throw Error(`<wui-lightbox> viewer is not open.`);return this._ui}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get label(){return this.getAttribute(`label`)||x().label}set label(e){this.setAttribute(`label`,String(e??``))}get layout(){return this.getAttribute(`layout`)===`single`?`single`:`gallery`}set layout(e){if(e===`single`)this.setAttribute(`layout`,`single`);else if(e===`gallery`||e===``)this.removeAttribute(`layout`);else throw Error(`<wui-lightbox> layout must be "gallery" or "single", received "${e}".`)}get isOpen(){return this._ui!==null}connectedCallback(){this.addEventListener(`click`,this._onClick),this._syncOpenIndex()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this._teardown()}attributeChangedCallback(){this.isConnected&&this._syncOpenIndex()}_syncOpenIndex(){let e=this.getAttribute(`open-index`);e===null?this.close():this.open(Number(e))}_links(){return[...this.querySelectorAll(s)].filter(e=>e instanceof HTMLAnchorElement)}_items(){return this._links().map(e=>{let t=e.getAttribute(`href`)??``;return{link:e,src:t,alt:e.querySelector(`img`)?.getAttribute(`alt`)??``,caption:e.dataset.caption??``,name:e.dataset.name||y(t)}})}open(e=0){let t=this._items();if(!t.length)return!1;if(!this._ui){let t=document.activeElement;this._returnTo=t instanceof HTMLElement||t instanceof SVGElement?t:null,this._build(),this.dispatchEvent(new CustomEvent(`wui-lightbox:open`,{bubbles:!0,detail:{index:e}}))}return this._show(e,t),!0}close(){if(!this._ui)return;let e=this._index,t=this._links()[e]??this._returnTo;this._teardown(),t?.isConnected&&t.focus(),this._returnTo=null,this.dispatchEvent(new CustomEvent(`wui-lightbox:close`,{bubbles:!0,detail:{index:e}}))}_teardown(){this._ui&&(this._release?.(),this._release=null,this._ui.root.open&&this._ui.root.close(),this._ui.root.remove(),this._ui=null,this._pointers.clear(),this._gesture=null)}_build(){let e=b(`dialog`,`wui-lightbox-overlay`,{role:`dialog`,"aria-label":this.label,tabindex:`-1`}),t=b(`div`,`wui-lightbox-bar`),i=b(`span`,`wui-lightbox-count`,{"aria-live":`polite`}),a=b(`div`,`wui-lightbox-tools`),o=S(`zoom-out`,x().zoomOutLabel,`wui-lightbox-zoom-out`),s=S(`zoom-in`,x().zoomInLabel,`wui-lightbox-zoom-in`),c=b(`a`,`u-action wui-lightbox-btn wui-lightbox-download`,{"aria-label":x().downloadLabel,title:x().downloadLabel});c.style.setProperty(`--wui-action-size`,`40px`),c.innerHTML=n(`download`,{size:20}),c.hidden=!this.download;let l=S(`x`,x().closeLabel,`wui-lightbox-close`);a.append(o,s,c,l),t.append(i,a);let d=b(`div`,`wui-lightbox-stage`),f=S(`chevron-left`,x().previousImageLabel,`wui-lightbox-nav wui-lightbox-prev`),p=S(`chevron-right`,x().nextImageLabel,`wui-lightbox-nav wui-lightbox-next`),m=b(`img`,`wui-lightbox-image`,{decoding:`async`,draggable:`false`,alt:``}),h=b(`p`,`wui-lightbox-status`,{role:`status`});d.append(m,h,f,p);let g=b(`p`,`wui-lightbox-caption`);e.append(t,d,g);let _={root:e,count:i,zoomOut:o,zoomIn:s,download:c,close:l,stage:d,prev:f,next:p,image:m,status:h,caption:g};this._ui=_,l.addEventListener(`click`,()=>this.close()),f.addEventListener(`click`,()=>this.step(-1)),p.addEventListener(`click`,()=>this.step(1)),o.addEventListener(`click`,()=>this._setZoom(this._zoom-u)),s.addEventListener(`click`,()=>this._setZoom(this._zoom+u)),e.addEventListener(`keydown`,e=>this._onKeyDown(e)),d.addEventListener(`pointerdown`,e=>this._onPointerDown(e)),d.addEventListener(`pointermove`,e=>this._onPointerMove(e)),d.addEventListener(`pointerup`,e=>this._onPointerEnd(e,!0)),d.addEventListener(`pointercancel`,e=>this._onPointerEnd(e,!1)),d.addEventListener(`wheel`,e=>this._onWheel(e),{passive:!1}),m.addEventListener(`load`,()=>{this._ui===_&&(h.textContent=``,d.removeAttribute(`aria-busy`),m.hidden=!1,this._applyTransform())}),m.addEventListener(`error`,()=>{this._ui===_&&(d.removeAttribute(`aria-busy`),m.hidden=!0,h.textContent=x().imageFailedMessage)}),this.append(e),this._release=r(e,{escape:!0,backdrop:!1,focus:`panel`,onRequestClose:()=>this.close()})}step(e){if(!this._ui||!e)return;let t=this._items();t.length<2||this._show((this._index+e+t.length)%t.length,t)}_show(e,n){let r=this._view,i=Math.min(n.length-1,Math.max(0,Math.trunc(Number(e))||0)),o=n[i];if(!o)throw Error(`<wui-lightbox> image missing.`);let s=i!==this._index||!r.image.getAttribute(`src`);if(this._index=i,this._zoom=c,this._pan={x:0,y:0},r.count.textContent=a(x().countText,{position:t(i+1,{decimals:0}),total:t(n.length,{decimals:0})}),r.caption.textContent=o.caption,r.caption.hidden=!o.caption,r.download.href=o.src,r.download.setAttribute(`download`,o.name),r.prev.hidden=r.next.hidden=n.length<2,r.stage.setAttribute(`aria-busy`,`true`),r.status.textContent=``,r.image.hidden=!1,r.image.alt=o.alt||o.caption,r.image.src=o.src,this._applyTransform(),this._syncZoomButtons(),n.length>1){let e=n[(i+1)%n.length],t=n[(i-1+n.length)%n.length];if(!e||!t)throw Error(`<wui-lightbox> neighbour image missing.`);for(let n of[e,t])new Image().src=n.src}s&&this.dispatchEvent(new CustomEvent(`wui-lightbox:change`,{bubbles:!0,detail:{index:i}}))}_syncZoomButtons(){let e=this._view;e.zoomOut.disabled=this._zoom<=c,e.zoomIn.disabled=this._zoom>=l;let t=document.activeElement;(t===e.zoomOut||t===e.zoomIn)&&t instanceof HTMLButtonElement&&t.disabled&&e.close.focus()}_setZoom(e){this._ui&&(this._zoom=g(e),this._pan=this._clampedPan(this._pan),this._applyTransform(),this._syncZoomButtons())}_clampedPan(e){let{stage:t,image:n}=this._view;return _(e,this._zoom,{width:t.clientWidth,height:t.clientHeight},{width:n.offsetWidth,height:n.offsetHeight})}_applyTransform(){let{image:e,stage:t}=this._view;e.style.transform=`translate(${this._pan.x}px, ${this._pan.y}px) scale(${this._zoom})`,t.classList.toggle(`wui-lightbox-zoomed`,this._zoom>c)}_onKeyDown(e){if(e.key===`ArrowLeft`||e.key===`ArrowRight`)e.preventDefault(),this.step(e.key===`ArrowRight`?1:-1);else if(e.key===`Home`||e.key===`End`){e.preventDefault();let t=this._items();this._show(e.key===`Home`?0:t.length-1,t)}else e.key===`+`||e.key===`=`?(e.preventDefault(),this._setZoom(this._zoom+u)):e.key===`-`?(e.preventDefault(),this._setZoom(this._zoom-u)):e.key===`0`&&(e.preventDefault(),this._setZoom(c))}_onWheel(e){e.preventDefault(),this._setZoom(this._zoom*(e.deltaY<0?1.15:1/1.15))}_onPointerDown(e){let t=e.target;if(t instanceof Element&&t.closest(`.wui-lightbox-nav`))return;let n=this._view;if(n.stage.setPointerCapture?.(e.pointerId),this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this._pointers.size===2){let e=[...this._pointers.values()],t=e[0],n=e[1];if(!t||!n)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._gesture={kind:`pinch`,distance:Math.hypot(t.x-n.x,t.y-n.y)||1,zoom:this._zoom}}else this._pointers.size===1&&(this._gesture={kind:`drag`,startX:e.clientX,startY:e.clientY,startTime:e.timeStamp,pan:{...this._pan},onImage:e.target===n.image,moved:!1})}_onPointerMove(e){let t=this._gesture;if(t&&this._pointers.has(e.pointerId)){if(this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.kind===`pinch`&&this._pointers.size===2){let e=[...this._pointers.values()],n=e[0],r=e[1];if(!n||!r)throw Error(`<wui-lightbox> pinch needs two pointers.`);this._setZoom(t.zoom*Math.hypot(n.x-r.x,n.y-r.y)/t.distance)}else if(t.kind===`drag`){let n=e.clientX-t.startX,r=e.clientY-t.startY;Math.hypot(n,r)>p&&(t.moved=!0),this._zoom>c&&(this._pan=this._clampedPan({x:t.pan.x+n,y:t.pan.y+r}),this._view.stage.classList.add(`is-dragging`),this._applyTransform())}}}_onPointerEnd(e,t){let n=this._gesture;if(this._pointers.delete(e.pointerId),this._ui?.stage.classList.remove(`is-dragging`),!n)return;if(n.kind===`pinch`){this._pointers.size<2&&(this._gesture=null);return}if(this._gesture=null,!t)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;n.moved?this._zoom===c&&this.step(v(r,i)):e.timeStamp-n.startTime>m||(n.onImage?e.timeStamp-this._lastTap<h?(this._lastTap=-1/0,this._setZoom(this._zoom>c?c:d)):this._lastTap=e.timeStamp:this.close())}};export{C as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t,r as n,t as r}from"./fieldState-D-zQcXUS.js";import{f as i}from"./formatters-CMTSYlW9.js";import{t as a}from"./imeSafeEnter-DPs9qL3S.js";import{n as o}from"./listboxKeyNav-DtlIOryj.js";import{i as s,n as c,r as l,t as u}from"./mentionText-BJsw_opZ.js";import{a as d,l as f,s as p}from"./nativeOverlay-D3VmY8qn.js";import{l as m}from"./wuiHttp-DGbD7Fra.js";import{n as h,r as g,t as _}from"./textStore-opIEM4lu.js";import{t as v}from"./mentionInput.g-DJo6d2Gm.js";var y=8,b=40,x=()=>g(`mentionInput`,v),S=`[data-wui-control]`,C=`[data-wui-field]`,w=`[data-wui-menu]`,T=`[data-wui-live]`,E=0,D=e=>!!(e&&u.test(String(e.value??``))&&c(e.label)!==``);function O(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`wui-input-sm`,n===`sm`),t.classList.toggle(`wui-input-lg`,n===`lg`),t.classList.toggle(`wui-input-xl`,n===`xl`)}function k(e,n){n.readOnly=t(e)||e.hasAttribute(`loading`)}function A(e){let t=e.ownerDocument;e.id||=`wui-mention-${++E}`;let n=t.createElement(`textarea`);n.id=`${e.id}-text`,n.className=`form-control textarea wui-mention-input-text`,n.rows=Number(e.getAttribute(`rows`))>0?Number(e.getAttribute(`rows`)):3,n.setAttribute(`data-wui-control`,``),n.setAttribute(`aria-autocomplete`,`list`),n.setAttribute(`aria-controls`,`${e.id}-people`);let r=e.getAttribute(`label`);r&&n.setAttribute(`aria-label`,r);let i=e.getAttribute(`placeholder`);i&&(n.placeholder=i);for(let t of[`aria-describedby`,`aria-invalid`]){let r=e.getAttribute(t);r&&n.setAttribute(t,r)}n.disabled=e.hasAttribute(`disabled`),k(e,n),O(e,n),e.appendChild(n);let a=e.getAttribute(`name`);if(a){let n=t.createElement(`input`);n.type=`hidden`,n.name=a,n.value=e.getAttribute(`value`)??``,n.setAttribute(`data-wui-field`,``),e.appendChild(n)}let o=t.createElement(`div`);o.className=`wui-mention-menu`,o.id=`${e.id}-people`,o.setAttribute(`role`,`listbox`),o.setAttribute(`aria-label`,e.getAttribute(`people-label`)??x().listNameLabel),o.setAttribute(`data-wui-menu`,``),o.setAttribute(`popover`,`manual`),e.appendChild(o);let s=t.createElement(`span`);s.className=`visually-hidden`,s.setAttribute(`data-wui-live`,``),s.setAttribute(`aria-live`,`polite`),s.setAttribute(`aria-atomic`,`true`),e.appendChild(s)}var j=class extends e{_wired;_pendingValue;_text;_mentions;_peopleProp;_declared;_loading;_searchFailed;_query;_results;_active;_timer;_searchSeq;_lastSearch;_abort;_onMenuDown;static get observedAttributes(){return[`disabled`,`readonly`,`loading`,`size`,`aria-invalid`,`aria-describedby`]}constructor(){super(),this._wired=!1,this._text=``,this._mentions=[],this._peopleProp=null,this._declared=null,this._loading=!1,this._searchFailed=!1,this._query=null,this._results=[],this._active=-1,this._timer=void 0,this._searchSeq=0,this._abort=null,this._onInput=this._onInput.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onCaret=this._onCaret.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onMenuDown=e=>e.preventDefault(),this._onMenuClick=this._onMenuClick.bind(this)}connectedCallback(){for(let e of[`people`,`loading`,`searchFailed`,`value`])if(Object.hasOwn(this,e)){let t=Reflect.get(this,e);Reflect.deleteProperty(this,e),Reflect.set(this,e,t)}if(this._wired)return;this._wired=!0,this.querySelector(S)||A(this);let e=this._requireControl(),t=this.querySelector(C)?.value??this.getAttribute(`value`)??``;this._pendingValue===void 0?this._load(t):this._load(this._pendingValue),this._pendingValue=void 0,this._syncState(),e.addEventListener(`input`,this._onInput),e.addEventListener(`keydown`,this._onKeyDown),e.addEventListener(`click`,this._onCaret),e.addEventListener(`keyup`,this._onCaret),this.addEventListener(`focusout`,this._onFocusOut);let n=this._requireMenu();n.addEventListener(`mousedown`,this._onMenuDown),n.addEventListener(`click`,this._onMenuClick),n.addEventListener(`mousemove`,e=>{let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&Number(t.dataset.index)!==this._active&&this._setActive(Number(t.dataset.index),{reveal:!1})})}disconnectedCallback(){this._close(),clearTimeout(this._timer),this._abort?.abort()}attributeChangedCallback(e,t,n){let r=this._control();r&&(e===`disabled`?(r.disabled=n!==null,n!==null&&this._close()):e===`readonly`?(k(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(k(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?O(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return s(this._text,this._mentions)}set value(e){let t=e==null?``:String(e);this._wired?t!==this.value&&this._load(t):this._pendingValue=t}get mentions(){let e=/* @__PURE__ */ new Set,t=[];for(let n of[...this._mentions].sort((e,t)=>e.start-t.start))e.has(n.id)||(e.add(n.id),t.push({id:n.id,label:n.label}));return t}get people(){return this._peopleProp?this._peopleProp:(this._declared||=[...this.querySelectorAll(`[data-wui-people] > wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})),this._declared)}set people(e){this._peopleProp=Array.isArray(e)?e.filter(D):[],this._searchFailed=!1,(this._isOpen()||this._query!==null)&&this._refresh()}get searchFailed(){return this._searchFailed}set searchFailed(e){this._searchFailed=!!e,this._query!==null&&this._renderMenu()}get loading(){return this._loading||this.hasAttribute(`loading`)}set loading(e){this._loading=!!e,this.toggleAttribute(`loading`,this._loading),this._query!==null&&this._renderMenu()}focus(e){this._control()?.focus(e)}clear(){this._load(``),this._emit()}_control(){return this.querySelector(S)}_menu(){return this.querySelector(w)}_requireControl(){let e=this._control();if(!e)throw Error(`<wui-mention-input> has no text box.`);return e}_requireMenu(){let e=this._menu();if(!e)throw Error(`<wui-mention-input> has no people list.`);return e}_load(e){let{text:t,mentions:n}=l(e);this._text=t,this._mentions=n;let r=this._control();r&&(r.defaultValue=t,r.value=t),this._syncField(),this._close()}_syncField(){let e=this.querySelector(C);e&&(e.value=this.value)}_emit(){this._syncField(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,detail:{value:this.value,mentions:this.mentions}}))}_onInput(){let e=this._requireControl(),t=e.value,n=this._text,r=t.length-n.length,i=Math.min(n.length,t.length),a=Math.max(0,Math.min(i,e.selectionEnd-Math.max(r,0))),o=0;for(;o<a&&n[o]===t[o];)o++;let s=0;for(;s<i-o&&n[n.length-1-s]===t[t.length-1-s];)s++;let c=n.length-s;this._mentions=this._mentions.filter(e=>e.end<=o||e.start>=c).map(e=>e.start>=c?{...e,start:e.start+r,end:e.end+r}:e),this._text=t,this._emit(),this._onCaret()}_onCaret(e){if(e instanceof KeyboardEvent&&e.type===`keyup`&&[`ArrowUp`,`ArrowDown`,`Enter`,`Tab`,`Escape`].includes(e.key))return;let t=this._queryAtCaret();t?this._query&&t.text===this._query.text&&t.start===this._query.start||(this._query=t,this._refresh()):this._close()}_queryAtCaret(){let e=this._control();if(!e||r(this)||e.selectionStart!==e.selectionEnd)return null;let t=e.selectionStart,n=this._text,i=n.lastIndexOf(`@`,t-1);if(i<0||i>0&&!/[\s([{"'“‘]/.test(n.charAt(i-1)))return null;let a=n.slice(i+1,t);return a.length>40||/[\n@]/.test(a)||/^\s/.test(a)||/\s{2}/.test(a)||this._mentions.some(e=>i>=e.start&&i<e.end)?null:{start:i,end:t,text:a}}_refresh(){if(!this._query)return;let e=this.hasAttribute(`remote`)||this.hasAttribute(`source`);if(e&&this._query.text.length<this._minChars()){this._results=[],this._close();return}e&&!this._answered(this._query.text)&&this._search(this._query.text);let t=this._query.text.toLowerCase(),n=e?this.people:this.people.filter(e=>c(e.label).toLowerCase().includes(t));this._results=n.slice(0,8),this._renderMenu()}_answered(e){return this._lastSearch===e}_minChars(){let e=this.getAttribute(`min-chars`),t=e==null||e===``?1:Number(e);return Number.isFinite(t)&&t>=0?t:1}_debounce(){let e=this.getAttribute(`debounce`),t=e==null||e===``?250:Number(e);return Number.isFinite(t)&&t>=0?t:250}_search(e){this._lastSearch=e,clearTimeout(this._timer);let t=++this._searchSeq;this._timer=setTimeout(()=>{let n=this.getAttribute(`source`);n?this._fetchPeople(n,e,t):this.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:t}}))},this._debounce())}async _fetchPeople(e,t,n){this._abort?.abort();let r=new AbortController;this._abort=r,this.loading=!0;let i=`${e}${e.includes(`?`)?`&`:`?`}q=${encodeURIComponent(t)}`,a=await m(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!a.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let o=this.ownerDocument.createElement(`template`);o.innerHTML=a.html,this._peopleProp=[...o.content.querySelectorAll(`wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})).filter(D),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return e!==null&&p(e)}_renderMenu(){let e=this._menu(),t=this._control();if(!e||!t||!this._query)return;this._syncState();let n=this.ownerDocument;if(e.replaceChildren(),this._results.forEach((t,r)=>{let i=n.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${e.id}-${r}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(r),t.src){let e=n.createElement(`img`);e.className=`wui-mention-option-photo`,e.src=t.src,e.alt=``,i.appendChild(e)}let a=n.createElement(`span`);a.className=`wui-mention-option-text`;let o=n.createElement(`span`);if(o.className=`wui-mention-option-label`,o.textContent=c(t.label),a.appendChild(o),t.description){let e=n.createElement(`span`);e.className=`wui-mention-option-description`,e.textContent=String(t.description),a.appendChild(e)}i.appendChild(a),e.appendChild(i)}),!this._results.length){let t=n.createElement(`div`);t.className=`wui-mention-empty`,t.textContent=this.loading?x().searchingLabel:this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel} “${this._query.text}”`,e.appendChild(t)}f(t,e,{mode:`manual`}),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?h(x(),`foundText`,this._results.length,{count:i(this._results.length,{decimals:0})}):this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel}.`)}_syncState(){let e=this._control();e&&n(this,e)}_close(){this._query=null,this._lastSearch=void 0,clearTimeout(this._timer);let e=this._menu();if(e){let t=p(e);d(e),t&&e.replaceChildren()}this._active=-1,this._control()?.removeAttribute(`aria-activedescendant`)}_setActive(e,{reveal:t=!0}={}){let n=this._requireMenu(),r=[...n.querySelectorAll(`.wui-mention-option`)];this._active=e>=0&&e<r.length?e:-1;let i=this._active>=0?r[this._active]??null:null;for(let e of r)e.setAttribute(`aria-selected`,e===i?`true`:`false`);o(n,i),i?(t&&i.scrollIntoView?.({block:`nearest`}),this._requireControl().setAttribute(`aria-activedescendant`,i.id)):this._requireControl().removeAttribute(`aria-activedescendant`)}_onKeyDown(e){if(this._isOpen()&&this._query){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=this._results.length;if(!t)return;let n=e.key===`ArrowDown`?1:-1;this._setActive((this._active+n+t)%t);return}if((a(e)||e.key===`Tab`)&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&this._active>=0){e.preventDefault(),this._pick(this._results[this._active]);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this._close();return}}a(e)&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),this.dispatchEvent(new CustomEvent(`wui:mention-input:submit`,{bubbles:!0,detail:{value:this.value}}))):e.key===`Backspace`&&this._removeWholeMention(e)}_removeWholeMention(e){let t=this._requireControl();if(t.selectionStart!==t.selectionEnd)return;let n=t.selectionStart,r=this._mentions.find(e=>e.end===n);r&&(e.preventDefault(),this._replace(r.start,r.end,``))}_onMenuClick(e){let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&this._pick(this._results[Number(t.dataset.index)])}_pick(e){if(!e||!this._query)return;let t=c(e.label),{start:n,end:r}=this._query,i=this._text.slice(r),a=`@${t}${/^\s/.test(i)?``:` `}`;this._replace(n,r,a,{id:String(e.value),label:t}),this._announce(_(x().mentioned,{label:t}))}_replace(e,t,n,r){let i=this._requireControl(),a=n.length-(t-e);this._mentions=this._mentions.filter(n=>n.end<=e||n.start>=t).map(e=>e.start>=t?{...e,start:e.start+a,end:e.end+a}:e),r&&this._mentions.push({start:e,end:e+1+r.label.length,id:r.id,label:r.label}),this._text=this._text.slice(0,e)+n+this._text.slice(t),i.value=this._text;let o=e+n.length;i.setSelectionRange(o,o),this._close(),i.focus(),this._emit()}_onFocusOut(e){e.relatedTarget instanceof Node&&this.contains(e.relatedTarget)||this._close()}_announce(e){let t=this.querySelector(T);t&&(t.textContent=``,t.textContent=e)}};export{y as n,j as r,b as t};
|
|
1
|
+
import{t as e}from"./elementBase-Cxeyx0tU.js";import{n as t,r as n,t as r}from"./fieldState-D-zQcXUS.js";import{f as i}from"./formatters-CMTSYlW9.js";import{t as a}from"./imeSafeEnter-DPs9qL3S.js";import{n as o}from"./listboxKeyNav-DtlIOryj.js";import{i as s,n as c,r as l,t as u}from"./mentionText-BJsw_opZ.js";import{a as d,l as f,s as p}from"./nativeOverlay-DGady-wN.js";import{l as m}from"./wuiHttp-DGbD7Fra.js";import{n as h,r as g,t as _}from"./textStore-opIEM4lu.js";import{t as v}from"./mentionInput.g-DJo6d2Gm.js";var y=8,b=40,x=()=>g(`mentionInput`,v),S=`[data-wui-control]`,C=`[data-wui-field]`,w=`[data-wui-menu]`,T=`[data-wui-live]`,E=0,D=e=>!!(e&&u.test(String(e.value??``))&&c(e.label)!==``);function O(e,t){let n=e.getAttribute(`size`);t.classList.toggle(`wui-input-sm`,n===`sm`),t.classList.toggle(`wui-input-lg`,n===`lg`),t.classList.toggle(`wui-input-xl`,n===`xl`)}function k(e,n){n.readOnly=t(e)||e.hasAttribute(`loading`)}function A(e){let t=e.ownerDocument;e.id||=`wui-mention-${++E}`;let n=t.createElement(`textarea`);n.id=`${e.id}-text`,n.className=`form-control textarea wui-mention-input-text`,n.rows=Number(e.getAttribute(`rows`))>0?Number(e.getAttribute(`rows`)):3,n.setAttribute(`data-wui-control`,``),n.setAttribute(`aria-autocomplete`,`list`),n.setAttribute(`aria-controls`,`${e.id}-people`);let r=e.getAttribute(`label`);r&&n.setAttribute(`aria-label`,r);let i=e.getAttribute(`placeholder`);i&&(n.placeholder=i);for(let t of[`aria-describedby`,`aria-invalid`]){let r=e.getAttribute(t);r&&n.setAttribute(t,r)}n.disabled=e.hasAttribute(`disabled`),k(e,n),O(e,n),e.appendChild(n);let a=e.getAttribute(`name`);if(a){let n=t.createElement(`input`);n.type=`hidden`,n.name=a,n.value=e.getAttribute(`value`)??``,n.setAttribute(`data-wui-field`,``),e.appendChild(n)}let o=t.createElement(`div`);o.className=`wui-mention-menu`,o.id=`${e.id}-people`,o.setAttribute(`role`,`listbox`),o.setAttribute(`aria-label`,e.getAttribute(`people-label`)??x().listNameLabel),o.setAttribute(`data-wui-menu`,``),o.setAttribute(`popover`,`manual`),e.appendChild(o);let s=t.createElement(`span`);s.className=`visually-hidden`,s.setAttribute(`data-wui-live`,``),s.setAttribute(`aria-live`,`polite`),s.setAttribute(`aria-atomic`,`true`),e.appendChild(s)}var j=class extends e{_wired;_pendingValue;_text;_mentions;_peopleProp;_declared;_loading;_searchFailed;_query;_results;_active;_timer;_searchSeq;_lastSearch;_abort;_onMenuDown;static get observedAttributes(){return[`disabled`,`readonly`,`loading`,`size`,`aria-invalid`,`aria-describedby`]}constructor(){super(),this._wired=!1,this._text=``,this._mentions=[],this._peopleProp=null,this._declared=null,this._loading=!1,this._searchFailed=!1,this._query=null,this._results=[],this._active=-1,this._timer=void 0,this._searchSeq=0,this._abort=null,this._onInput=this._onInput.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onCaret=this._onCaret.bind(this),this._onFocusOut=this._onFocusOut.bind(this),this._onMenuDown=e=>e.preventDefault(),this._onMenuClick=this._onMenuClick.bind(this)}connectedCallback(){for(let e of[`people`,`loading`,`searchFailed`,`value`])if(Object.hasOwn(this,e)){let t=Reflect.get(this,e);Reflect.deleteProperty(this,e),Reflect.set(this,e,t)}if(this._wired)return;this._wired=!0,this.querySelector(S)||A(this);let e=this._requireControl(),t=this.querySelector(C)?.value??this.getAttribute(`value`)??``;this._pendingValue===void 0?this._load(t):this._load(this._pendingValue),this._pendingValue=void 0,this._syncState(),e.addEventListener(`input`,this._onInput),e.addEventListener(`keydown`,this._onKeyDown),e.addEventListener(`click`,this._onCaret),e.addEventListener(`keyup`,this._onCaret),this.addEventListener(`focusout`,this._onFocusOut);let n=this._requireMenu();n.addEventListener(`mousedown`,this._onMenuDown),n.addEventListener(`click`,this._onMenuClick),n.addEventListener(`mousemove`,e=>{let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&Number(t.dataset.index)!==this._active&&this._setActive(Number(t.dataset.index),{reveal:!1})})}disconnectedCallback(){this._close(),clearTimeout(this._timer),this._abort?.abort()}attributeChangedCallback(e,t,n){let r=this._control();r&&(e===`disabled`?(r.disabled=n!==null,n!==null&&this._close()):e===`readonly`?(k(this,r),n!==null&&this._close(),this._syncState()):e===`loading`?(k(this,r),this._syncState(),this._query!==null&&this._renderMenu()):e===`size`?O(this,r):n===null?r.removeAttribute(e):r.setAttribute(e,n))}get value(){return s(this._text,this._mentions)}set value(e){let t=e==null?``:String(e);this._wired?t!==this.value&&this._load(t):this._pendingValue=t}get mentions(){let e=/* @__PURE__ */ new Set,t=[];for(let n of[...this._mentions].sort((e,t)=>e.start-t.start))e.has(n.id)||(e.add(n.id),t.push({id:n.id,label:n.label}));return t}get people(){return this._peopleProp?this._peopleProp:(this._declared||=[...this.querySelectorAll(`[data-wui-people] > wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})),this._declared)}set people(e){this._peopleProp=Array.isArray(e)?e.filter(D):[],this._searchFailed=!1,(this._isOpen()||this._query!==null)&&this._refresh()}get searchFailed(){return this._searchFailed}set searchFailed(e){this._searchFailed=!!e,this._query!==null&&this._renderMenu()}get loading(){return this._loading||this.hasAttribute(`loading`)}set loading(e){this._loading=!!e,this.toggleAttribute(`loading`,this._loading),this._query!==null&&this._renderMenu()}focus(e){this._control()?.focus(e)}clear(){this._load(``),this._emit()}_control(){return this.querySelector(S)}_menu(){return this.querySelector(w)}_requireControl(){let e=this._control();if(!e)throw Error(`<wui-mention-input> has no text box.`);return e}_requireMenu(){let e=this._menu();if(!e)throw Error(`<wui-mention-input> has no people list.`);return e}_load(e){let{text:t,mentions:n}=l(e);this._text=t,this._mentions=n;let r=this._control();r&&(r.defaultValue=t,r.value=t),this._syncField(),this._close()}_syncField(){let e=this.querySelector(C);e&&(e.value=this.value)}_emit(){this._syncField(),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,detail:{value:this.value,mentions:this.mentions}}))}_onInput(){let e=this._requireControl(),t=e.value,n=this._text,r=t.length-n.length,i=Math.min(n.length,t.length),a=Math.max(0,Math.min(i,e.selectionEnd-Math.max(r,0))),o=0;for(;o<a&&n[o]===t[o];)o++;let s=0;for(;s<i-o&&n[n.length-1-s]===t[t.length-1-s];)s++;let c=n.length-s;this._mentions=this._mentions.filter(e=>e.end<=o||e.start>=c).map(e=>e.start>=c?{...e,start:e.start+r,end:e.end+r}:e),this._text=t,this._emit(),this._onCaret()}_onCaret(e){if(e instanceof KeyboardEvent&&e.type===`keyup`&&[`ArrowUp`,`ArrowDown`,`Enter`,`Tab`,`Escape`].includes(e.key))return;let t=this._queryAtCaret();t?this._query&&t.text===this._query.text&&t.start===this._query.start||(this._query=t,this._refresh()):this._close()}_queryAtCaret(){let e=this._control();if(!e||r(this)||e.selectionStart!==e.selectionEnd)return null;let t=e.selectionStart,n=this._text,i=n.lastIndexOf(`@`,t-1);if(i<0||i>0&&!/[\s([{"'“‘]/.test(n.charAt(i-1)))return null;let a=n.slice(i+1,t);return a.length>40||/[\n@]/.test(a)||/^\s/.test(a)||/\s{2}/.test(a)||this._mentions.some(e=>i>=e.start&&i<e.end)?null:{start:i,end:t,text:a}}_refresh(){if(!this._query)return;let e=this.hasAttribute(`remote`)||this.hasAttribute(`source`);if(e&&this._query.text.length<this._minChars()){this._results=[],this._close();return}e&&!this._answered(this._query.text)&&this._search(this._query.text);let t=this._query.text.toLowerCase(),n=e?this.people:this.people.filter(e=>c(e.label).toLowerCase().includes(t));this._results=n.slice(0,8),this._renderMenu()}_answered(e){return this._lastSearch===e}_minChars(){let e=this.getAttribute(`min-chars`),t=e==null||e===``?1:Number(e);return Number.isFinite(t)&&t>=0?t:1}_debounce(){let e=this.getAttribute(`debounce`),t=e==null||e===``?250:Number(e);return Number.isFinite(t)&&t>=0?t:250}_search(e){this._lastSearch=e,clearTimeout(this._timer);let t=++this._searchSeq;this._timer=setTimeout(()=>{let n=this.getAttribute(`source`);n?this._fetchPeople(n,e,t):this.dispatchEvent(new CustomEvent(`search`,{bubbles:!0,detail:{query:e,seq:t}}))},this._debounce())}async _fetchPeople(e,t,n){this._abort?.abort();let r=new AbortController;this._abort=r,this.loading=!0;let i=`${e}${e.includes(`?`)?`&`:`?`}q=${encodeURIComponent(t)}`,a=await m(i,{signal:r.signal});if(n!==this._searchSeq)return;if(this._abort=null,!a.ok){this._peopleProp=[],this._searchFailed=!0,this.loading=!1,this._refresh();return}this._searchFailed=!1;let o=this.ownerDocument.createElement(`template`);o.innerHTML=a.html,this._peopleProp=[...o.content.querySelectorAll(`wui-option`)].map(e=>({value:e.getAttribute(`value`)??``,label:(e.textContent??``).trim(),description:e.getAttribute(`data-description`)||void 0,src:e.getAttribute(`data-src`)||void 0})).filter(D),this.loading=!1,this._refresh()}_isOpen(){let e=this._menu();return e!==null&&p(e)}_renderMenu(){let e=this._menu(),t=this._control();if(!e||!t||!this._query)return;this._syncState();let n=this.ownerDocument;if(e.replaceChildren(),this._results.forEach((t,r)=>{let i=n.createElement(`div`);if(i.className=`wui-mention-option`,i.id=`${e.id}-${r}`,i.setAttribute(`role`,`option`),i.setAttribute(`aria-selected`,`false`),i.dataset.index=String(r),t.src){let e=n.createElement(`img`);e.className=`wui-mention-option-photo`,e.src=t.src,e.alt=``,i.appendChild(e)}let a=n.createElement(`span`);a.className=`wui-mention-option-text`;let o=n.createElement(`span`);if(o.className=`wui-mention-option-label`,o.textContent=c(t.label),a.appendChild(o),t.description){let e=n.createElement(`span`);e.className=`wui-mention-option-description`,e.textContent=String(t.description),a.appendChild(e)}i.appendChild(a),e.appendChild(i)}),!this._results.length){let t=n.createElement(`div`);t.className=`wui-mention-empty`,t.textContent=this.loading?x().searchingLabel:this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel} “${this._query.text}”`,e.appendChild(t)}f(t,e,{mode:`manual`}),this._setActive(this._results.length?0:-1),this.loading||this._announce(this._results.length?h(x(),`foundText`,this._results.length,{count:i(this._results.length,{decimals:0})}):this._searchFailed?x().searchFailedMessage:`${x().noMatchLabel}.`)}_syncState(){let e=this._control();e&&n(this,e)}_close(){this._query=null,this._lastSearch=void 0,clearTimeout(this._timer);let e=this._menu();if(e){let t=p(e);d(e),t&&e.replaceChildren()}this._active=-1,this._control()?.removeAttribute(`aria-activedescendant`)}_setActive(e,{reveal:t=!0}={}){let n=this._requireMenu(),r=[...n.querySelectorAll(`.wui-mention-option`)];this._active=e>=0&&e<r.length?e:-1;let i=this._active>=0?r[this._active]??null:null;for(let e of r)e.setAttribute(`aria-selected`,e===i?`true`:`false`);o(n,i),i?(t&&i.scrollIntoView?.({block:`nearest`}),this._requireControl().setAttribute(`aria-activedescendant`,i.id)):this._requireControl().removeAttribute(`aria-activedescendant`)}_onKeyDown(e){if(this._isOpen()&&this._query){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=this._results.length;if(!t)return;let n=e.key===`ArrowDown`?1:-1;this._setActive((this._active+n+t)%t);return}if((a(e)||e.key===`Tab`)&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&this._active>=0){e.preventDefault(),this._pick(this._results[this._active]);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this._close();return}}a(e)&&(e.ctrlKey||e.metaKey)?(e.preventDefault(),this.dispatchEvent(new CustomEvent(`wui:mention-input:submit`,{bubbles:!0,detail:{value:this.value}}))):e.key===`Backspace`&&this._removeWholeMention(e)}_removeWholeMention(e){let t=this._requireControl();if(t.selectionStart!==t.selectionEnd)return;let n=t.selectionStart,r=this._mentions.find(e=>e.end===n);r&&(e.preventDefault(),this._replace(r.start,r.end,``))}_onMenuClick(e){let t=e.target instanceof Element?e.target.closest(`.wui-mention-option`):null;t&&this._pick(this._results[Number(t.dataset.index)])}_pick(e){if(!e||!this._query)return;let t=c(e.label),{start:n,end:r}=this._query,i=this._text.slice(r),a=`@${t}${/^\s/.test(i)?``:` `}`;this._replace(n,r,a,{id:String(e.value),label:t}),this._announce(_(x().mentioned,{label:t}))}_replace(e,t,n,r){let i=this._requireControl(),a=n.length-(t-e);this._mentions=this._mentions.filter(n=>n.end<=e||n.start>=t).map(e=>e.start>=t?{...e,start:e.start+a,end:e.end+a}:e),r&&this._mentions.push({start:e,end:e+1+r.label.length,id:r.id,label:r.label}),this._text=this._text.slice(0,e)+n+this._text.slice(t),i.value=this._text;let o=e+n.length;i.setSelectionRange(o,o),this._close(),i.focus(),this._emit()}_onFocusOut(e){e.relatedTarget instanceof Node&&this.contains(e.relatedTarget)||this._close()}_announce(e){let t=this.querySelector(T);t&&(t.textContent=``,t.textContent=e)}};export{y as n,j as r,b as t};
|