@webority/ui-react 0.164.0 → 0.165.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +1 -1
  2. package/dist/canvas-kit/kit.js +206 -206
  3. package/dist/canvas-kit/manifest.json +1086 -406
  4. package/dist/canvas-kit/release.json +6 -6
  5. package/dist/components/AppAsyncBlock.js +1 -1
  6. package/dist/components/AppColorField.js +1 -1
  7. package/dist/components/AppDataTable.js +1 -1
  8. package/dist/components/AppDatePicker.js +1 -1
  9. package/dist/components/AppDateRangePicker.js +1 -1
  10. package/dist/components/AppDescriptions.js +1 -1
  11. package/dist/components/AppDropZone.js +1 -1
  12. package/dist/components/AppDropdown.js +1 -1
  13. package/dist/components/AppEntryGrid.js +1 -0
  14. package/dist/components/AppFileAttachment.js +1 -1
  15. package/dist/components/AppFilePicker.js +1 -1
  16. package/dist/components/AppFilterBar.js +1 -1
  17. package/dist/components/AppForm.js +1 -1
  18. package/dist/components/AppFormulaSteps.js +1 -0
  19. package/dist/components/AppImagePicker.js +1 -1
  20. package/dist/components/AppInput.js +1 -1
  21. package/dist/components/AppMentionInput.js +1 -1
  22. package/dist/components/AppMetricStrip.js +1 -1
  23. package/dist/components/AppModal.js +1 -1
  24. package/dist/components/AppNumberInput.js +1 -1
  25. package/dist/components/AppOtpInput.js +1 -1
  26. package/dist/components/AppPhoneNumberInput.js +1 -1
  27. package/dist/components/AppPopover.js +1 -1
  28. package/dist/components/AppRadioGroup.js +1 -1
  29. package/dist/components/AppRating.js +1 -1
  30. package/dist/components/AppRichText.js +1 -1
  31. package/dist/components/AppRowActions.js +1 -0
  32. package/dist/components/AppScoreScale.js +1 -1
  33. package/dist/components/AppSectionFeatures.js +1 -1
  34. package/dist/components/AppSectionLogos.js +1 -1
  35. package/dist/components/AppSelect.js +1 -1
  36. package/dist/components/AppShell.js +1 -1
  37. package/dist/components/AppSlider.js +1 -1
  38. package/dist/components/AppTextarea.js +1 -1
  39. package/dist/components/AppTimePicker.js +1 -1
  40. package/dist/components/AppToast.js +1 -1
  41. package/dist/guidance.json +212 -137
  42. package/dist/hookForm/index.js +1 -0
  43. package/dist/lib/CheckField.js +1 -1
  44. package/dist/lib/formFields.js +1 -0
  45. package/dist/lib/unsavedText.js +1 -0
  46. package/dist/types/components/AppAsyncBlock.d.ts +3 -3
  47. package/dist/types/components/AppChart.d.ts +12 -4
  48. package/dist/types/components/AppDataTable.d.ts +29 -2
  49. package/dist/types/components/AppDateRangePicker.d.ts +4 -0
  50. package/dist/types/components/AppDescriptions.d.ts +6 -0
  51. package/dist/types/components/AppEntryGrid.d.ts +122 -0
  52. package/dist/types/components/AppFilterBar.d.ts +12 -1
  53. package/dist/types/components/AppForm.d.ts +18 -0
  54. package/dist/types/components/AppFormulaSteps.d.ts +64 -0
  55. package/dist/types/components/AppMetricStrip.d.ts +5 -0
  56. package/dist/types/components/AppModal.d.ts +5 -0
  57. package/dist/types/components/AppRowActions.d.ts +40 -0
  58. package/dist/types/components/AppSectionFeatures.d.ts +5 -1
  59. package/dist/types/components/AppSectionLogos.d.ts +1 -0
  60. package/dist/types/components/AppShell.d.ts +2 -0
  61. package/dist/types/components/AppSlider.d.ts +5 -0
  62. package/dist/types/components/AppToast.d.ts +5 -0
  63. package/dist/types/hookForm/index.d.ts +14 -0
  64. package/dist/types/index.d.ts +7 -5
  65. package/dist/types/lib/formFields.d.ts +12 -0
  66. package/dist/types/lib/unsavedText.d.ts +5 -0
  67. package/dist/ui-react.js +1 -1
  68. package/dist/web-core/dist/errors/extractApiError.js +2 -0
  69. package/dist/web-core/dist/errors/requestPlatform.js +1 -0
  70. package/package.json +20 -9
  71. package/dist/components/AppResizable.js +0 -1
  72. package/dist/components/AppResizableHandle.js +0 -1
  73. package/dist/components/AppResizablePanel.js +0 -1
  74. package/dist/components/AppRollingNumber.js +0 -1
  75. package/dist/components/AppRowSwitch.js +0 -1
  76. package/dist/types/components/AppResizable.d.ts +0 -37
  77. package/dist/types/components/AppResizableHandle.d.ts +0 -14
  78. package/dist/types/components/AppResizablePanel.d.ts +0 -14
  79. package/dist/types/components/AppRollingNumber.d.ts +0 -30
  80. package/dist/types/components/AppRowSwitch.d.ts +0 -18
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "webority-web",
3
- "version": "0.164.0",
3
+ "version": "0.165.0",
4
4
  "platform": "Web",
5
5
  "kitModuleVersion": 2,
6
6
  "rendererProtocolVersion": 14,
7
7
  "library": {
8
8
  "name": "@webority/ui-react",
9
- "version": "0.164.0"
9
+ "version": "0.165.0"
10
10
  },
11
11
  "files": {
12
12
  "manifest.json": {
13
- "sha256": "00de08cc45a1cb06e9528be7b69e1df8fbfe808006acae6e85a8f849adfb88ab",
14
- "bytes": 1017644
13
+ "sha256": "2f537f16e2cbb1d06d5ec51f85e70b1d1eba5029563865e82d7f3b106eb669d3",
14
+ "bytes": 1042782
15
15
  },
16
16
  "kit.js": {
17
- "sha256": "b423c89fbd40bd3cd2fa22b2d48190e6ab11fbce2a59223dee3f34c529fb1bc8",
18
- "bytes": 9824141
17
+ "sha256": "bf46fab10ca47396c9d1c2af0ca9593e40f26863377ef94623cc81e384b842ff",
18
+ "bytes": 9843469
19
19
  },
20
20
  "kit.css": {
21
21
  "sha256": "13b14f71fb6ea024945f95cba617b4f1d49f44a65ba7c7ed05d2354805539ef6",
@@ -1 +1 @@
1
- import{splitMarkerProps as e}from"../lib/wuiMarker.js";import t from"./AppButton.js";import n from"./AppEmptyState.js";import r from"./AppProgress.js";import i from"./assertValidValue.js";import a from"./warnUnknownProps.js";import{jsx as o}from"react/jsx-runtime";function s(s){let{marker:c,props:l}=e(`AppAsyncBlock`,s),{state:u,children:d,empty:f,skeleton:p,className:m=``,loadingLabel:h=`Loading`,errorTitle:g=`Something went wrong`,retryLabel:_=`Retry`,emptyTitle:v=`Nothing to show yet`,...y}=l;a(`AppAsyncBlock`,y),i(`AppAsyncBlock`,`state.status`,u.status,[`idle`,`loading`,`error`,`empty`,`data`]);let b=`async-block${m?` ${m}`:``}`,x;switch(u.status){case`idle`:return null;case`loading`:x=p??/* @__PURE__ */ o(r,{value:0,indeterminate:!0,size:`sm`,label:h});break;case`error`:x=/* @__PURE__ */ o(n,{icon:`alert-circle`,title:g,description:u.error.message,action:/* @__PURE__ */ o(t,{variant:`soft`,onClick:()=>u.retry(),children:_})});break;case`empty`:x=f??/* @__PURE__ */ o(n,{icon:`inbox`,title:v});break;case`data`:x=d(u.data)}return/* @__PURE__ */ o(`div`,{className:b,"data-state":u.status,...c,...y,children:x})}export{s as default};
1
+ import{splitMarkerProps as e}from"../lib/wuiMarker.js";import t from"./AppButton.js";import n from"./AppEmptyState.js";import r from"./AppProgress.js";import i from"./assertValidValue.js";import a from"./warnUnknownProps.js";import{jsx as o}from"react/jsx-runtime";function s(s){let{marker:c,props:l}=e(`AppAsyncBlock`,s),{state:u,children:d,empty:f,skeleton:p,className:m=``,loadingLabel:h=`Loading`,errorTitle:g=`That didn't load`,retryLabel:_=`Try again`,emptyTitle:v=`Nothing here yet`,...y}=l;a(`AppAsyncBlock`,y),i(`AppAsyncBlock`,`state.status`,u.status,[`idle`,`loading`,`error`,`empty`,`data`]);let b=`async-block${m?` ${m}`:``}`,x;switch(u.status){case`idle`:return null;case`loading`:x=p??/* @__PURE__ */ o(r,{value:0,indeterminate:!0,size:`sm`,label:h});break;case`error`:x=/* @__PURE__ */ o(n,{icon:`alert-circle`,title:g,description:u.error.message,action:/* @__PURE__ */ o(t,{variant:`soft`,onClick:()=>u.retry(),children:_})});break;case`empty`:x=f??/* @__PURE__ */ o(n,{icon:`inbox`,title:v});break;case`data`:x=d(u.data)}return/* @__PURE__ */ o(`div`,{className:b,"data-state":u.status,...c,...y,children:x})}export{s as default};
@@ -1 +1 @@
1
- import e from"../lib/FieldMessage.js";import{FIELD_BUSY_CLASS as t}from"../lib/fieldState.js";import n from"../lib/fillLabel.js";import{splitMarkerProps as r}from"../lib/wuiMarker.js";import i from"./AppInfoTip.js";import a from"./AppRequiredMark.js";import o from"./assertValidValue.js";import s from"./warnUnknownProps.js";import{useId as c,useState as l}from"react";import{jsx as u,jsxs as d}from"react/jsx-runtime";var f=[`sm`,`md`,`lg`];function p(p){let{marker:m,props:h}=r(`AppColorField`,p),{value:g,defaultValue:_,onChange:v,label:y,required:b=!1,optional:x=!1,error:S,helperText:C,help:w,helpLabel:T=`More information`,colourLabel:E=`Colour`,colourPickerLabel:D=`{label}, colour picker`,optionalLabel:O=`(optional)`,name:k,id:A,disabled:j=!1,readOnly:M=!1,loading:N=!1,size:P=`md`,className:F=``,fieldClassName:I=``,...L}=h;s(`AppColorField`,L),o(`AppColorField`,`size`,P,f);let[R,z]=l(_??`#000000`),B=g===void 0?R:g,V=e=>{z(e),v?.(e)},H=c(),U=A||H,W=S?`${U}-error`:C?`${U}-hint`:void 0,G=e=>/^#[0-9a-f]{6}$/i.test(e),K=P===`sm`?` color-field-sm`:P===`lg`?` color-field-lg`:``,q=P===`sm`?` input-sm`:P===`lg`?` input-lg`:``;return/* @__PURE__ */ d(`div`,{...m,className:`field${I?` ${I}`:``}`,children:[y&&/* @__PURE__ */ d(`label`,{className:`label`,htmlFor:U,children:[y,x&&!b&&/* @__PURE__ */ u(`span`,{className:`label-optional`,children:` ${O}`}),b&&/* @__PURE__ */ u(a,{}),w&&/* @__PURE__ */ u(i,{label:T,children:w})]}),/* @__PURE__ */ d(`div`,{className:`color-field${K}`,children:[/* @__PURE__ */ u(`input`,{type:`color`,className:`color-field-swatch`,value:G(B)?B:`#000000`,onChange:e=>V(e.target.value),disabled:j||M||N,"aria-label":n(D,{label:y||E}),tabIndex:-1}),/* @__PURE__ */ u(`input`,{type:`text`,className:`input color-field-hex${q}${S?` error`:``}${N?` ${t}`:``}${F?` ${F}`:``}`,id:U,name:k,value:B,onChange:e=>V(e.target.value),placeholder:`#4F46E5`,spellCheck:!1,maxLength:7,required:b,disabled:j,readOnly:M||N,"aria-busy":N||void 0,"aria-invalid":S?`true`:`false`,"aria-describedby":W,...L})]}),/* @__PURE__ */ u(e,{error:S,hint:C,errorId:`${U}-error`,hintId:`${U}-hint`})]})}export{p as default};
1
+ import e from"../lib/FieldMessage.js";import{FIELD_BUSY_CLASS as t}from"../lib/fieldState.js";import n from"../lib/fillLabel.js";import{useFieldError as r}from"../lib/formFields.js";import{splitMarkerProps as i}from"../lib/wuiMarker.js";import a from"./AppInfoTip.js";import o from"./AppRequiredMark.js";import s from"./assertValidValue.js";import c from"./warnUnknownProps.js";import{useId as l,useState as u}from"react";import{jsx as d,jsxs as f}from"react/jsx-runtime";var p=[`sm`,`md`,`lg`];function m(m){let{marker:h,props:g}=i(`AppColorField`,m),{value:_,defaultValue:v,onChange:y,label:b,required:x=!1,optional:S=!1,error:C,helperText:w,help:T,helpLabel:E=`More information`,colourLabel:D=`Colour`,colourPickerLabel:O=`{label}, colour picker`,optionalLabel:k=`(optional)`,name:A,id:j,disabled:M=!1,readOnly:N=!1,loading:P=!1,size:F=`md`,className:I=``,fieldClassName:L=``,...R}=g,z=r(A),B=C??z;c(`AppColorField`,R),s(`AppColorField`,`size`,F,p);let[V,H]=u(v??`#000000`),U=_===void 0?V:_,W=e=>{H(e),y?.(e)},G=l(),K=j||G,q=B?`${K}-error`:w?`${K}-hint`:void 0,J=e=>/^#[0-9a-f]{6}$/i.test(e),Y=F===`sm`?` color-field-sm`:F===`lg`?` color-field-lg`:``,X=F===`sm`?` input-sm`:F===`lg`?` input-lg`:``;return/* @__PURE__ */ f(`div`,{...h,className:`field${L?` ${L}`:``}`,children:[b&&/* @__PURE__ */ f(`label`,{className:`label`,htmlFor:K,children:[b,S&&!x&&/* @__PURE__ */ d(`span`,{className:`label-optional`,children:` ${k}`}),x&&/* @__PURE__ */ d(o,{}),T&&/* @__PURE__ */ d(a,{label:E,children:T})]}),/* @__PURE__ */ f(`div`,{className:`color-field${Y}`,children:[/* @__PURE__ */ d(`input`,{type:`color`,className:`color-field-swatch`,value:J(U)?U:`#000000`,onChange:e=>W(e.target.value),disabled:M||N||P,"aria-label":n(O,{label:b||D}),tabIndex:-1}),/* @__PURE__ */ d(`input`,{type:`text`,className:`input color-field-hex${X}${B?` error`:``}${P?` ${t}`:``}${I?` ${I}`:``}`,id:K,name:A,value:U,onChange:e=>W(e.target.value),placeholder:`#4F46E5`,spellCheck:!1,maxLength:7,required:x,disabled:M,readOnly:N||P,"aria-busy":P||void 0,"aria-invalid":B?`true`:`false`,"aria-describedby":q,...R})]}),/* @__PURE__ */ d(e,{error:B,hint:w,errorId:`${K}-error`,hintId:`${K}-hint`})]})}export{m as default};
@@ -1 +1 @@
1
- import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/useElementEntry.js";import{splitMarkerProps as n}from"../lib/wuiMarker.js";import r from"./AppIcon.js";import i from"./AppSkeleton.js";import a from"./AppTablePagination.js";import o from"./assertValidValue.js";import s from"./warnUnknownProps.js";import{COLUMN_MAX_WIDTH as c,COLUMN_MIN_WIDTH as ee,DATA_TABLE_TEXT as l,PIN_AT_VAR as u,PIN_SIDES as d,ROW_HEIGHTS as te,ROW_MOVE_LIMIT as ne,ROW_SAVE_ERROR_CLASS as re,attachRowDrag as ie,attachScrollEdges as ae,groupCount as oe,groupItems as se,isImeSafeEnter as ce,measureRows as le,pinAtValue as ue,pinClasses as de,planPins as fe,playRowMoves as pe,rowOrderChanged as me,saveOutcomeText as he,settledRows as ge,syncTargets as _e,virtualRange as ve}from"@webority/ui-elements/helpers";import{Children as ye,Fragment as be,isValidElement as xe,useCallback as Se,useEffect as f,useLayoutEffect as Ce,useMemo as we,useRef as p,useState as m}from"react";import{Fragment as Te,jsx as h,jsxs as g}from"react/jsx-runtime";import{FORCED_STATE_CLASSES as Ee}from"@webority/theme/runtime";var De=()=>import(`@webority/ui-elements/elements/data-table`),Oe=[`comfortable`,`cozy`,`compact`],ke=[`auto`,`fixed`],Ae=[1,2,3,4];function _(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function je(e,t){if(e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`||xe(e)||Array.isArray(e))return e;throw Error(`AppDataTable: the value under "${t}" is not renderable; give that column a render function.`)}function Me(e,t){return je(_(e,t),t)}var v=()=>{try{return process.env.NODE_ENV!==`production`}catch{return!0}},y=/* @__PURE__ */ new Set;function b(t,n){!y.has(t)&&v()&&(y.add(t),e(`[@webority/ui-react] <AppDataTable> ${n}`))}var Ne=100,Pe=e=>{let t=typeof e==`object`&&e&&`id`in e?e.id:void 0;return typeof t==`string`||typeof t==`number`?t:void 0},Fe=()=>{},Ie=()=>({total:0,keys:[]}),Le=[],Re=(e,t,n)=>{let r=!!t?.(e),i=r?``:n?.(e)||``;return{state:r?`saving`:i?`error`:null,message:i}};function x(e){return e===`end`?`wui-cell-end`:e===`num`?`num`:e===`center`?`text-center`:``}function ze(e){return e===`center`?`44%`:e===`end`||e===`num`?`56%`:`60%`}function Be(e){return e==null||e===``?`-`:Array.isArray(e)?ye.toArray(e):typeof e==`boolean`?String(e):e}function Ve(e){if(!e||!(e.total>0))return!1;let t=e.pageSizes?.length?e.pageSizes:[e.pageSize];return e.total>Math.min(...t)}function He(e){t(`wui-data-table`,De);let{marker:ye,props:xe}=n(`AppDataTable`,e),{columns:v,rows:y=Le,rowKey:He=Pe,sort:Ue,onSort:We,loading:S=!1,skeletonRows:Ge=5,empty:Ke=`No records found.`,emptyFiltered:qe,sourceCount:Je,rowActions:C,rowActionsLabel:Ye,pagination:w,ariaLabel:Xe,className:Ze=``,wrapperClassName:Qe=``,selectable:T=!1,selectedIds:E,isRowSelectable:$e,onToggleRow:et,onToggleAll:tt,onSelectRange:nt,renderExpanded:rt,density:D=`comfortable`,tableLayout:it=`auto`,striped:at=!1,flush:ot=!1,pad:st,nameLines:O,headerTone:ct,rowDrag:k=!1,maxHeight:lt,stickyFirstColumn:ut=!1,stickyActions:dt=!1,stackOnMobile:A=!1,hiddenColumns:ft,rowStatus:pt,rowHref:j,onRowClick:mt,activeRowKey:ht,hoverRowKey:gt,resizableColumns:M=!1,viewKey:_t,groupBy:N,groupLabel:vt,virtual:P=!1,rowSaving:F,rowSaveError:I,...yt}=xe;s(`AppDataTable`,yt);let{style:bt,...xt}=yt,L=Se((e,t)=>{let n=He(e,t);if(n==null)throw Error(`AppDataTable: a row has no key. Pass rowKey, or give every row an id.`);return n},[He]),St=ft?.length?new Set(ft):null;v=St?v.filter(e=>!(e.hideable&&St.has(e.key))):v,o(`AppDataTable`,`density`,D,Oe),o(`AppDataTable`,`tableLayout`,it,ke),o(`AppDataTable`,`nameLines`,O,Ae);for(let e of v)o(`AppDataTable`,`column.pin`,e.pin,d);let Ct=[`table table-ledger`,D===`cozy`||D===`compact`?`wui-table-${D}`:``,at?`wui-table-striped`:``,ut?`wui-table-sticky-first`:``,dt?`wui-table-sticky-actions`:``,A?`wui-table-stack`:``,Ze].filter(Boolean).join(` `),R=typeof rt==`function`,[wt,Tt]=m(()=>/* @__PURE__ */ new Set),Et=e=>Tt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Dt=v.some(e=>typeof e.footer==`function`),z=typeof j==`function`||typeof mt==`function`,Ot=e=>!!(e.target instanceof Element&&e.target.closest(`a, button, input, select, textarea, label, [role='menu'], [role='menuitem'], .dropdown`)),kt=(e,t)=>{if(Ot(t)||(mt&&mt(e),!j))return;let n=j(e);n&&(t.ctrlKey||t.metaKey||t.button===1?window.open(n,`_blank`,`noopener`):window.location.assign(n))},B=lt!==void 0,At=[`table-wrap`,B?`wui-table-scroll`:``,ot?`wui-table-flush`:``,Qe].filter(Boolean).join(` `),jt={maxHeight:B?lt:void 0,"--wui-table-pad":st!=null&&!ot?`${st}px`:void 0,"--wui-name-lines":P?`1`:O?.toString(),"--wui-table-header-bg":ct??void 0},Mt=Object.values(jt).some(e=>e!==void 0)||bt!==void 0?{...jt,...bt}:void 0,Nt=Math.max(1,v.length+ +!!C+ +!!T+ +!!R),Pt=v.some(e=>e.pin===`start`||e.pin===`end`),Ft=Pt||M||!!N||P,V=+!!R+ +!!T,It=Pt?fe([...R?[`lead`]:[],...T?[`lead`]:[],...v.map(e=>e.pin===`start`||e.pin===`end`?e.pin:null),...C?[null]:[]]):[],H=(e,t=``)=>{let n=It[e];return n?{className:`${t.trim()} ${de(n)}`.trim(),style:{[u]:ue(n.side,n.ordinal)}}:{className:t,style:void 0}},U=(e,t)=>It[e]?{...t,...H(e).style}:t,Lt=v.length-1+ +!!C;_t&&!M&&b(`view-key`,"`viewKey` remembers resized widths: add `resizableColumns`."),P&&!B&&b(`virtual-height`,"`virtual` needs `maxHeight`: without a scroll box every row renders."),P&&(R||A)&&b(`virtual-shape`,"`virtual` takes rows of one height, so it is off with `renderExpanded` or `stackOnMobile`."),P&&O!==void 0&&O!==1&&b(`virtual-name-lines`,"`nameLines` is ignored with `virtual`: a virtual table shows one line per name."),!P&&y?.length>500&&b(`rows-without-virtual`,`renders more than 500 rows without virtual: add virtual with maxHeight, or page the data.`);let W=P&&B&&!R&&!A&&!S&&y?.length>0,G=(e,t)=>!$e||!!$e(e,t),Rt=T&&y?y.reduce((e,t,n)=>e+ +!!G(t,n),0):0,K=T&&y?y.reduce((e,t,n)=>e+(G(t,n)&&E?.has(L(t,n))?1:0),0):0,zt=Rt>0&&K===Rt,Bt=K>0&&!zt,Vt=e=>{e&&(e.indeterminate=Bt)},Ht=p(null),Ut=(e,t)=>{let n=Ht.current;Ht.current=e;let r=t&&n!==null?y.findIndex((e,t)=>L(e,t)===n):-1,i=y.findIndex((t,n)=>L(t,n)===e);if(r<0||i<0||r===i){et?.(e);return}let a=!E?.has(e),o=Math.min(r,i),s=y.slice(o,Math.max(r,i)+1).map((e,t)=>[e,o+t]).filter(([e,t])=>G(e,t)).map(([e,t])=>L(e,t)).filter(e=>(E?.has(e)||!1)!==a);if(nt)nt(s,a);else for(let e of s)et?.(e)},Wt=e=>{$e?(y||[]).forEach((t,n)=>{let r=L(t,n);G(t,n)&&(E?.has(r)||!1)!==e&&et?.(r)}):tt?.(e)},[Gt,Kt]=m(()=>/* @__PURE__ */ new Set),qt=e=>Kt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),q=we(()=>{let e=(y||[]).map((e,t)=>({row:e,i:t}));return N?se(e,({row:e})=>String(_(e,N)??``)).flatMap(e=>[{group:e,open:!Gt.has(e.key)},...Gt.has(e.key)?[]:e.items]):e},[y,N,Gt]),Jt=p(null),[J,Yt]=m(null),Xt=Se(e=>{Jt.current=e,Yt(e)},[]),Zt=p(null);f(()=>{let e=J;if(!e)return;let t=e=>{let t=e.target instanceof Element?e.target.closest(`.u-name`):null;t&&!t.title&&(t.scrollWidth>t.clientWidth||t.scrollHeight>t.clientHeight)&&(t.title=(t.textContent??``).trim())},n=e=>{let t=e.target instanceof Element?e.target.closest(`tbody > tr[aria-rowindex]`)?.getAttribute(`aria-rowindex`):null;Zt.current=t?Number(t)-2:null},r=t=>{t.relatedTarget instanceof Node&&e.contains(t.relatedTarget)||(Zt.current=null)};e.addEventListener(`mouseover`,t),e.addEventListener(`focusin`,t),e.addEventListener(`focusin`,n),e.addEventListener(`focusout`,r);let i=ae(e);return()=>{e.removeEventListener(`mouseover`,t),e.removeEventListener(`focusin`,t),e.removeEventListener(`focusin`,n),e.removeEventListener(`focusout`,r),i()}},[J]),f(()=>{if(!k||!J)return;let e=ie(J);return _e(document),e},[k,J]);let Qt=p(Ie);Ce(()=>{Qt.current=()=>({total:y?.length??0,keys:y?y.flatMap((e,t)=>{let n=L(e,t);return G(e,t)&&E?.has(n)?[String(n)]:[]}):[]})});let $t=p(!1);f(()=>{if(!$t.current&&($t.current=!0,K===0))return;let{total:e,keys:t}=Qt.current();Jt.current?.querySelector(`table`)?.dispatchEvent(new CustomEvent(`selectionchange`,{bubbles:!0,detail:{selected:K,total:e,keys:t}}))},[K]);let[en,tn]=m({top:0,height:0}),[Y,nn]=m(te[D]??te.comfortable);f(()=>{let e=J;if(!W||!e)return;let t=0,n=()=>{t=0;let n=e.querySelector(`:scope > table > thead`)?.getBoundingClientRect().height||0,r={top:Math.max(0,e.scrollTop-n),height:e.clientHeight};tn(e=>e.top===r.top&&e.height===r.height?e:r)},r=()=>{t||=requestAnimationFrame(n)};e.addEventListener(`scroll`,r,{passive:!0});let i=typeof ResizeObserver<`u`?new ResizeObserver(r):null;return i?.observe(e),n(),()=>{e.removeEventListener(`scroll`,r),i?.disconnect(),t&&cancelAnimationFrame(t)}},[W,J]);let rn=p(null);Ce(()=>{if(!W){rn.current=null;return}let e=`${D}:${y?.length??0}`;if(rn.current===e)return;rn.current=e;let t=(Jt.current?.querySelector(`:scope > table > tbody > tr:not(.wui-virtual-spacer, .wui-group-row)`))?.getBoundingClientRect().height;t!==void 0&&t>0&&Math.abs(t-Y)>.5&&nn(t)});let X={start:0,end:q.length,before:0,after:0};if(W){X=ve({scrollTop:en.top,viewport:en.height||Number.parseFloat(String(lt))||0,rowHeight:Y,count:q.length});let e=Zt.current;e!==null&&e>=0&&e<q.length&&(e<X.start&&X.start-e<=Ne&&(X={...X,start:e,before:e*Y}),e>=X.end&&e-X.end<Ne&&(X={...X,end:e+1,after:(q.length-e-1)*Y}))}let an=p(null),on=p(null),sn=p(null),cn=!P&&!S&&y?.length>0&&y.length<=ne;Ce(()=>{let e=an.current;if(!cn||!e){on.current=null,sn.current=null;return}let t=y.map((e,t)=>L(e,t));me(sn.current,t)&&pe(e.rows,on.current),on.current=le(e.rows),sn.current=t});let Z=typeof F==`function`||typeof I==`function`,ln=p(null),un=p(null),dn=v[0]?.key;f(()=>{if(!Z){un.current=null;return}let e=/* @__PURE__ */ new Map;(y||[]).forEach((t,n)=>{let r=dn===void 0?void 0:_(t,dn),i=typeof r==`string`||typeof r==`number`?String(r):``;e.set(L(t,n),{...Re(t,F,I),label:i})});let t=he(ge(un.current,e));un.current=e,t&&ln.current&&(ln.current.textContent=t)},[y,F,I,L,Z,dn]);let fn=qe!==void 0&&(Je===void 0||Je>0)?qe:Ke,pn=({group:e,open:t},n)=>{let i=_(e.items[0]?.row,N??``),a=e.items.map(e=>e.row);return/* @__PURE__ */ h(`tr`,{className:`wui-group-row`,"data-group-key":e.key,"aria-rowindex":W?n+2:void 0,children:/* @__PURE__ */ h(`th`,{className:`wui-group-cell`,scope:`rowgroup`,colSpan:Nt,children:/* @__PURE__ */ g(`button`,{type:`button`,className:`wui-group-toggle`,"aria-expanded":t,onClick:()=>qt(e.key),children:[/* @__PURE__ */ h(r,{name:`chevron-down`,size:16}),/* @__PURE__ */ h(`span`,{className:`wui-group-label`,children:vt?vt(i,a):Be(je(i,N??``))}),/* @__PURE__ */ h(`span`,{className:`wui-group-count`,"aria-hidden":`true`,children:oe(e.items.length)}),/* @__PURE__ */ h(`span`,{className:`visually-hidden wui-group-rows`,children:`, ${l.rows(e.items.length)}`})]})})},`group:${e.key}`)},mn=({row:e,i:t},n)=>{let i=L(e,t),a=R&&wt.has(i),o=ht!=null&&String(ht)===String(i),s=gt!=null&&String(gt)===String(i),c=String(i).replace(/[^a-z0-9]/gi,`_`),ee=H(0,`wui-expand-cell`),l=H(+!!R,`wui-select-cell`),u=Z?Re(e,F,I):null,d=G(e,t);return/* @__PURE__ */ g(be,{children:[/* @__PURE__ */ g(`tr`,{className:[T&&d&&E?.has(i)?`is-selected`:``,z?`wui-row-link`:``,o?`wui-row-active`:``,s?Ee.hover:``].filter(Boolean).join(` `)||void 0,"aria-current":o?`true`:void 0,"aria-rowindex":W?n+2:void 0,"aria-busy":u?.state===`saving`?`true`:void 0,"data-wui-save-state":u?.state||void 0,"data-status":pt?.(e)||void 0,"data-href":j?.(e)||void 0,"data-row-key":k?String(i):void 0,tabIndex:z?0:void 0,onClick:z?t=>kt(e,t):void 0,onAuxClick:z&&j?t=>t.button===1&&kt(e,t):void 0,onKeyDown:z?t=>{ce(t.nativeEvent)&&t.target===t.currentTarget&&kt(e,t)}:void 0,children:[R&&/* @__PURE__ */ h(`td`,{className:ee.className,style:ee.style,children:/* @__PURE__ */ h(`button`,{type:`button`,className:`wui-expand-toggle${a?` is-open`:``}`,"aria-expanded":a,"aria-controls":a?`${c}-expanded`:void 0,"aria-label":a?`Collapse row`:`Expand row`,onClick:()=>Et(i),children:/* @__PURE__ */ h(r,{name:`chevron-down`,size:16})})}),T&&/* @__PURE__ */ h(`td`,{className:l.className,style:l.style,children:/* @__PURE__ */ h(`input`,{type:`checkbox`,className:`wui-check`,checked:d&&(E?.has(i)||!1),disabled:!d,onChange:e=>Ut(i,e.nativeEvent instanceof MouseEvent&&e.nativeEvent.shiftKey),onMouseDown:e=>{e.shiftKey&&e.preventDefault()},"aria-label":`Select row`})}),v.map((t,n)=>{let r=t.rowHeader?`th`:`td`;return/* @__PURE__ */ g(r,{scope:t.rowHeader?`row`:void 0,className:H(V+n,(n===0?`wui-name-cell `:``)+(t.rowHeader?`wui-row-header `:``)+(t.nowrap?`text-nowrap `:``)+x(t.align)+(t.cellClassName?` ${t.cellClassName}`:``)).className,style:U(V+n,t.cellStyle),"data-label":A&&typeof t.label==`string`?t.label:void 0,children:[t.render?t.render(e):Be(Me(e,t.key)),n===0&&u?.state===`error`&&/* @__PURE__ */ h(`span`,{className:re,children:u.message})]},t.key)}),C&&/* @__PURE__ */ h(`td`,{children:/* @__PURE__ */ h(`div`,{className:`u-row-actions`,children:C(e)})})]}),a&&/* @__PURE__ */ h(`tr`,{className:`wui-row-expanded`,children:/* @__PURE__ */ h(`td`,{id:`${c}-expanded`,colSpan:Nt,children:rt?.(e)})})]},i)},hn=(e,t)=>`group`in e?pn(e,t):mn(e,t),gn=(e,t)=>W?/* @__PURE__ */ h(`tr`,{className:`wui-virtual-spacer`,"aria-hidden":`true`,hidden:t===0,children:/* @__PURE__ */ h(`td`,{colSpan:Nt,style:{height:t}})},e):null,Q=H(0,`wui-expand-cell`),$=H(+!!R,`wui-select-cell`),_n=()=>Array.from({length:Ge},(e,t)=>`skeleton-${t}`).map(e=>/* @__PURE__ */ g(`tr`,{children:[R&&/* @__PURE__ */ h(`td`,{className:Q.className,style:Q.style}),T&&/* @__PURE__ */ h(`td`,{className:$.className,style:$.style}),v.map((e,t)=>/* @__PURE__ */ h(`td`,{className:H(V+t,(t===0?`wui-name-cell `:``)+(e.nowrap?`text-nowrap `:``)+x(e.align)).className,style:U(V+t,void 0),"data-label":A&&typeof e.label==`string`?e.label:void 0,children:/* @__PURE__ */ h(i,{width:ze(e.align),height:12,radius:6})},e.key)),C&&/* @__PURE__ */ h(`td`,{children:/* @__PURE__ */ h(`div`,{className:`u-row-actions`,children:/* @__PURE__ */ h(i,{width:`32px`,height:12,radius:6})})})]},e));return/* @__PURE__ */ g(Te,{children:[/* @__PURE__ */ g(Ft?`wui-data-table`:`div`,{ref:Xt,...Ft?{class:At,resizable:M?``:void 0,"view-key":_t||void 0,"data-wui-row-drag":k?``:void 0}:{className:At,"data-wui-row-drag":k?``:void 0},style:Mt,tabIndex:0,...ye,...xt,children:[/* @__PURE__ */ g(`table`,{className:Ct,"aria-label":Xe,"aria-rowcount":W?q.length+1:void 0,style:it===`fixed`?{tableLayout:`fixed`}:void 0,children:[/* @__PURE__ */ h(`thead`,{children:/* @__PURE__ */ g(`tr`,{"aria-rowindex":W?1:void 0,children:[R&&/* @__PURE__ */ h(`th`,{className:Q.className,style:Q.style,children:/* @__PURE__ */ h(`span`,{className:`visually-hidden`,children:`Expand`})}),T&&/* @__PURE__ */ h(`th`,{className:$.className,style:$.style,children:/* @__PURE__ */ h(`input`,{ref:Vt,type:`checkbox`,className:`wui-check`,checked:zt,disabled:S,onChange:e=>Wt(e.target.checked),"aria-label":`Select all rows`})}),v.map((e,t)=>{let n=e.sortable?We:void 0,i=n!==void 0,a=Ue&&Ue.key===e.key,o=e.align===`num`||e.align===`end`,s=i&&/* @__PURE__ */ h(`span`,{className:`sort-icon${o?` wui-sort-lead`:``}`,children:/* @__PURE__ */ h(r,{name:`chevrons-up-down`,size:14})}),u=M&&t!==Lt,d=e.width||e.minWidth?{width:e.width,minWidth:e.minWidth}:void 0;return/* @__PURE__ */ g(`th`,{className:H(V+t,(i?`sortable `:``)+(t===0?`wui-name-cell `:``)+(e.nowrap?`text-nowrap `:``)+(e.grow?`wui-col-grow `:``)+(u?`wui-col-resizable `:``)+x(e.align)).className,style:U(V+t,d),"data-key":Ft?e.key:void 0,"aria-label":u&&typeof e.label==`string`?e.label:void 0,"data-pin":e.pin===`start`||e.pin===`end`?e.pin:void 0,tabIndex:i?0:void 0,"aria-sort":a?Ue?.dir===`asc`?`ascending`:`descending`:i?`none`:void 0,onClick:n?()=>{S||n(e.key)}:void 0,onKeyDown:n?t=>{t.target===t.currentTarget&&(ce(t.nativeEvent)||t.key===` `)&&(t.preventDefault(),S||n(e.key))}:void 0,children:[o&&s,e.label,!o&&s,u&&/* @__PURE__ */ h(`span`,{className:`wui-col-resize`,role:`separator`,"aria-orientation":`vertical`,"aria-valuemin":ee,"aria-valuemax":c,tabIndex:0,"aria-label":l.resize(typeof e.label==`string`?e.label:e.key)})]},e.key)}),C&&(Ye?/* @__PURE__ */ h(`th`,{className:`wui-cell-end`,children:Ye}):/* @__PURE__ */ h(`th`,{className:`wui-cell-end`,children:/* @__PURE__ */ h(`span`,{className:`visually-hidden`,children:`Actions`})}))]})}),/* @__PURE__ */ h(`tbody`,{ref:an,children:S?_n():y?.length?/* @__PURE__ */ g(Te,{children:[gn(`before`,X.before),q.slice(X.start,X.end).map((e,t)=>hn(e,X.start+t)),gn(`after`,X.after)]}):null}),Dt&&!S&&y?.length>0&&/* @__PURE__ */ h(`tfoot`,{children:/* @__PURE__ */ g(`tr`,{children:[R&&/* @__PURE__ */ h(`td`,{className:Q.className,style:Q.style}),T&&/* @__PURE__ */ h(`td`,{className:$.className,style:$.style}),v.map((e,t)=>/* @__PURE__ */ h(`td`,{className:H(V+t,(t===0?`wui-name-cell `:``)+(e.nowrap?`text-nowrap `:``)+x(e.align)).className,style:U(V+t,void 0),children:e.footer?e.footer(y):null},e.key)),C&&/* @__PURE__ */ h(`td`,{})]})})]}),!S&&!y?.length&&/* @__PURE__ */ h(`div`,{className:`tbl-empty-block`,children:typeof fn==`string`?/* @__PURE__ */ h(`div`,{className:`tbl-empty-plain`,children:fn}):fn})]}),Ve(w)&&/* @__PURE__ */ h(a,{page:w.page,totalPages:w.totalPages,total:w.total,pageSize:w.pageSize,onPageChange:S?Fe:w.setPage,onPageSizeChange:S?Fe:w.setPageSize,pageSizes:w.pageSizes,mode:w.mode,summary:w.summary}),Z&&/* @__PURE__ */ h(`div`,{ref:ln,className:`visually-hidden`,role:`status`,"aria-live":`polite`,"data-wui-table-status":``})]})}export{He as default};
1
+ import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/useElementEntry.js";import{splitMarkerProps as n}from"../lib/wuiMarker.js";import r from"./AppIcon.js";import i from"./AppInfoTip.js";import a from"./AppRowActions.js";import o from"./AppSkeleton.js";import s from"./AppTablePagination.js";import c from"./assertValidValue.js";import l from"./warnUnknownProps.js";import{COLUMN_MAX_WIDTH as ee,COLUMN_MIN_WIDTH as te,DATA_TABLE_TEXT as u,PIN_AT_VAR as d,PIN_SIDES as ne,ROW_HEIGHTS as f,ROW_MOVE_LIMIT as re,ROW_SAVE_ERROR_CLASS as ie,attachRowDrag as ae,attachScrollEdges as oe,groupCount as se,groupItems as ce,isImeSafeEnter as le,measureRows as ue,pinAtValue as de,pinClasses as fe,planPins as pe,playRowMoves as me,rowOrderChanged as he,saveOutcomeText as ge,settledRows as _e,syncTargets as ve,virtualRange as ye}from"@webority/ui-elements/helpers";import{Children as be,Fragment as xe,isValidElement as Se,useCallback as Ce,useEffect as p,useLayoutEffect as we,useMemo as Te,useRef as m,useState as h}from"react";import{Fragment as Ee,jsx as g,jsxs as _}from"react/jsx-runtime";import{FORCED_STATE_CLASSES as De}from"@webority/theme/runtime";var Oe=()=>import(`@webority/ui-elements/elements/data-table`),ke=[`comfortable`,`cozy`,`compact`],Ae=[`auto`,`fixed`],je=[1,2,3,4];function v(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function Me(e,t){if(e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`||Se(e)||Array.isArray(e))return e;throw Error(`AppDataTable: the value under "${t}" is not renderable; give that column a render function.`)}function Ne(e,t){return Me(v(e,t),t)}var y=()=>{try{return process.env.NODE_ENV!==`production`}catch{return!0}},b=/* @__PURE__ */ new Set;function x(t,n){!b.has(t)&&y()&&(b.add(t),e(`[@webority/ui-react] <AppDataTable> ${n}`))}var Pe=100,Fe=e=>{let t=typeof e==`object`&&e&&`id`in e?e.id:void 0;return typeof t==`string`||typeof t==`number`?t:void 0},Ie=()=>{},Le=()=>({total:0,keys:[]}),Re=[],ze=(e,t,n)=>{let r=!!t?.(e),i=r?``:n?.(e)||``;return{state:r?`saving`:i?`error`:null,message:i}};function Be(e){return e===`end`?`wui-cell-end`:e===`num`?`num`:e===`center`?`text-center`:``}function Ve(e){return e===`center`?`44%`:e===`end`||e===`num`?`56%`:`60%`}function He(e){return e==null||e===``?`-`:Array.isArray(e)?be.toArray(e):typeof e==`boolean`?String(e):e}function Ue(e){if(!e||!(e.total>0))return!1;let t=e.pageSizes?.length?e.pageSizes:[e.pageSize];return e.total>Math.min(...t)}function We(e){t(`wui-data-table`,Oe);let{marker:be,props:Se}=n(`AppDataTable`,e),{columns:y,rows:b=Re,rowKey:We=Fe,sort:Ge,onSort:Ke,loading:S=!1,refreshing:qe=!1,skeletonRows:Je=5,empty:Ye=`No records found.`,emptyFiltered:Xe,sourceCount:Ze,rowActions:C,linkComponent:Qe,rowActionsLabel:$e,pagination:w,ariaLabel:et,className:tt=``,wrapperClassName:nt=``,selectable:T=!1,selectedIds:E,isRowSelectable:rt,onToggleRow:it,onToggleAll:at,onSelectRange:ot,renderExpanded:st,singleExpand:ct=!1,density:D=`comfortable`,tableLayout:lt=`auto`,striped:ut=!1,flush:dt=!1,pad:ft,nameLines:O,headerTone:pt,rowDrag:k=!1,maxHeight:mt,stickyFirstColumn:ht=!1,stickyActions:gt=!1,equalActions:_t=!1,linkFirstColumn:vt=!1,stackOnMobile:A=!1,hiddenColumns:yt,rowStatus:bt,rowHref:j,onRowClick:xt,activeRowKey:St,hoverRowKey:Ct,resizableColumns:M=!1,viewKey:wt,groupBy:N,groupLabel:Tt,virtual:P=!1,rowSaving:F,rowSaveError:I,...Et}=Se;l(`AppDataTable`,Et);let{style:Dt,...Ot}=Et,L=Ce((e,t)=>{let n=We(e,t);if(n==null)throw Error(`AppDataTable: a row has no key. Pass rowKey, or give every row an id.`);return n},[We]),kt=yt?.length?new Set(yt):null;y=kt?y.filter(e=>!(e.hideable&&kt.has(e.key))):y,c(`AppDataTable`,`density`,D,ke),c(`AppDataTable`,`tableLayout`,lt,Ae),c(`AppDataTable`,`nameLines`,O,je);for(let e of y)c(`AppDataTable`,`column.pin`,e.pin,ne);let R=typeof j==`function`||typeof xt==`function`,At=[`table table-ledger`,D===`cozy`||D===`compact`?`wui-table-${D}`:``,ut?`wui-table-striped`:``,ht?`wui-table-sticky-first`:``,gt?`wui-table-sticky-actions`:``,_t?`wui-table-equal-actions`:``,A?`wui-table-stack`:``,vt&&R?`wui-table-link-first`:``,tt].filter(Boolean).join(` `),z=typeof st==`function`,[jt,Mt]=h(()=>/* @__PURE__ */ new Set),Nt=e=>Mt(t=>{if(t.has(e)){let n=new Set(t);return n.delete(e),n}return ct?/* @__PURE__ */ new Set([e]):new Set(t).add(e)}),Pt=y.some(e=>typeof e.footer==`function`),Ft=e=>!!(e.target instanceof Element&&e.target.closest(`a, button, input, select, textarea, label, [role='menu'], [role='menuitem'], .dropdown`)),It=(e,t)=>{if(Ft(t)||(xt&&xt(e),!j))return;let n=j(e);n&&(t.ctrlKey||t.metaKey||t.button===1?window.open(n,`_blank`,`noopener`):window.location.assign(n))},Lt=mt!==void 0,Rt=qe&&!S&&b.length>0,zt=[`table-wrap`,Lt?`wui-table-scroll`:``,dt?`wui-table-flush`:``,Rt?`wui-table-refreshing`:``,nt].filter(Boolean).join(` `),Bt={maxHeight:Lt?mt:void 0,"--wui-table-pad":ft!=null&&!dt?`${ft}px`:void 0,"--wui-name-lines":P?`1`:O?.toString(),"--wui-table-header-bg":pt??void 0},Vt=Object.values(Bt).some(e=>e!==void 0)||Dt!==void 0?{...Bt,...Dt}:void 0,Ht=Math.max(1,y.length+ +!!C+ +!!T+ +!!z),Ut=y.some(e=>e.pin===`start`||e.pin===`end`),Wt=Ut||M||!!N||P,B=+!!z+ +!!T,Gt=Ut?pe([...z?[`lead`]:[],...T?[`lead`]:[],...y.map(e=>e.pin===`start`||e.pin===`end`?e.pin:null),...C?[null]:[]]):[],V=(e,t=``)=>{let n=Gt[e];return n?{className:`${t.trim()} ${fe(n)}`.trim(),style:{[d]:de(n.side,n.ordinal)}}:{className:t,style:void 0}},H=(e,t)=>Gt[e]?{...t,...V(e).style}:t,Kt=y.length-1+ +!!C;wt&&!M&&x(`view-key`,"`viewKey` remembers resized widths: add `resizableColumns`."),P&&!Lt&&x(`virtual-height`,"`virtual` needs `maxHeight`: without a scroll box every row renders."),P&&(z||A)&&x(`virtual-shape`,"`virtual` takes rows of one height, so it is off with `renderExpanded` or `stackOnMobile`."),P&&O!==void 0&&O!==1&&x(`virtual-name-lines`,"`nameLines` is ignored with `virtual`: a virtual table shows one line per name."),vt&&!R&&x(`link-first-column`,"`linkFirstColumn` needs rowHref or onRowClick: the row is what opens."),ct&&typeof st!=`function`&&x(`single-expand`,"`singleExpand` needs renderExpanded: there are no rows to expand."),!P&&b?.length>500&&x(`rows-without-virtual`,`renders more than 500 rows without virtual: add virtual with maxHeight, or page the data.`);let U=P&&Lt&&!z&&!A&&!S&&b?.length>0,W=(e,t)=>!rt||!!rt(e,t),qt=T&&b?b.reduce((e,t,n)=>e+ +!!W(t,n),0):0,G=T&&b?b.reduce((e,t,n)=>e+(W(t,n)&&E?.has(L(t,n))?1:0),0):0,Jt=qt>0&&G===qt,Yt=G>0&&!Jt,Xt=e=>{e&&(e.indeterminate=Yt)},Zt=m(null),Qt=(e,t)=>{let n=Zt.current;Zt.current=e;let r=t&&n!==null?b.findIndex((e,t)=>L(e,t)===n):-1,i=b.findIndex((t,n)=>L(t,n)===e);if(r<0||i<0||r===i){it?.(e);return}let a=!E?.has(e),o=Math.min(r,i),s=b.slice(o,Math.max(r,i)+1).map((e,t)=>[e,o+t]).filter(([e,t])=>W(e,t)).map(([e,t])=>L(e,t)).filter(e=>(E?.has(e)||!1)!==a);if(ot)ot(s,a);else for(let e of s)it?.(e)},$t=e=>{rt?(b||[]).forEach((t,n)=>{let r=L(t,n);W(t,n)&&(E?.has(r)||!1)!==e&&it?.(r)}):at?.(e)},[en,tn]=h(()=>/* @__PURE__ */ new Set),nn=e=>tn(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),K=Te(()=>{let e=(b||[]).map((e,t)=>({row:e,i:t}));return N?ce(e,({row:e})=>String(v(e,N)??``)).flatMap(e=>[{group:e,open:!en.has(e.key)},...en.has(e.key)?[]:e.items]):e},[b,N,en]),rn=m(null),[q,an]=h(null),on=Ce(e=>{rn.current=e,an(e)},[]),sn=m(null);p(()=>{let e=q;if(!e)return;let t=e=>{let t=e.target instanceof Element?e.target.closest(`.u-name`):null;t&&!t.title&&(t.scrollWidth>t.clientWidth||t.scrollHeight>t.clientHeight)&&(t.title=(t.textContent??``).trim())},n=e=>{let t=e.target instanceof Element?e.target.closest(`tbody > tr[aria-rowindex]`)?.getAttribute(`aria-rowindex`):null;sn.current=t?Number(t)-2:null},r=t=>{t.relatedTarget instanceof Node&&e.contains(t.relatedTarget)||(sn.current=null)};e.addEventListener(`mouseover`,t),e.addEventListener(`focusin`,t),e.addEventListener(`focusin`,n),e.addEventListener(`focusout`,r);let i=oe(e);return()=>{e.removeEventListener(`mouseover`,t),e.removeEventListener(`focusin`,t),e.removeEventListener(`focusin`,n),e.removeEventListener(`focusout`,r),i()}},[q]),p(()=>{if(!k||!q)return;let e=ae(q);return ve(document),e},[k,q]);let cn=m(Le);we(()=>{cn.current=()=>({total:b?.length??0,keys:b?b.flatMap((e,t)=>{let n=L(e,t);return W(e,t)&&E?.has(n)?[String(n)]:[]}):[]})});let ln=m(!1);p(()=>{if(!ln.current&&(ln.current=!0,G===0))return;let{total:e,keys:t}=cn.current();rn.current?.querySelector(`table`)?.dispatchEvent(new CustomEvent(`selectionchange`,{bubbles:!0,detail:{selected:G,total:e,keys:t}}))},[G]);let[un,dn]=h({top:0,height:0}),[J,fn]=h(f[D]??f.comfortable);p(()=>{let e=q;if(!U||!e)return;let t=0,n=()=>{t=0;let n=e.querySelector(`:scope > table > thead`)?.getBoundingClientRect().height||0,r={top:Math.max(0,e.scrollTop-n),height:e.clientHeight};dn(e=>e.top===r.top&&e.height===r.height?e:r)},r=()=>{t||=requestAnimationFrame(n)};e.addEventListener(`scroll`,r,{passive:!0});let i=typeof ResizeObserver<`u`?new ResizeObserver(r):null;return i?.observe(e),n(),()=>{e.removeEventListener(`scroll`,r),i?.disconnect(),t&&cancelAnimationFrame(t)}},[U,q]);let pn=m(null);we(()=>{if(!U){pn.current=null;return}let e=`${D}:${b?.length??0}`;if(pn.current===e)return;pn.current=e;let t=(rn.current?.querySelector(`:scope > table > tbody > tr:not(.wui-virtual-spacer, .wui-group-row)`))?.getBoundingClientRect().height;t!==void 0&&t>0&&Math.abs(t-J)>.5&&fn(t)});let Y={start:0,end:K.length,before:0,after:0};if(U){Y=ye({scrollTop:un.top,viewport:un.height||Number.parseFloat(String(mt))||0,rowHeight:J,count:K.length});let e=sn.current;e!==null&&e>=0&&e<K.length&&(e<Y.start&&Y.start-e<=Pe&&(Y={...Y,start:e,before:e*J}),e>=Y.end&&e-Y.end<Pe&&(Y={...Y,end:e+1,after:(K.length-e-1)*J}))}let mn=m(null),hn=m(null),gn=m(null),_n=!P&&!S&&b?.length>0&&b.length<=re;we(()=>{let e=mn.current;if(!_n||!e){hn.current=null,gn.current=null;return}let t=b.map((e,t)=>L(e,t));he(gn.current,t)&&me(e.rows,hn.current),hn.current=ue(e.rows),gn.current=t});let X=typeof F==`function`||typeof I==`function`,vn=m(null),yn=m(null),Z=y[0]?.key;p(()=>{if(!X){yn.current=null;return}let e=/* @__PURE__ */ new Map;(b||[]).forEach((t,n)=>{let r=Z===void 0?void 0:v(t,Z),i=typeof r==`string`||typeof r==`number`?String(r):``;e.set(L(t,n),{...ze(t,F,I),label:i})});let t=ge(_e(yn.current,e));yn.current=e,t&&vn.current&&(vn.current.textContent=t)},[b,F,I,L,X,Z]);let bn=Xe!==void 0&&(Ze===void 0||Ze>0)?Xe:Ye,xn=({group:e,open:t},n)=>{let i=v(e.items[0]?.row,N??``),a=e.items.map(e=>e.row);return/* @__PURE__ */ g(`tr`,{className:`wui-group-row`,"data-group-key":e.key,"aria-rowindex":U?n+2:void 0,children:/* @__PURE__ */ g(`th`,{className:`wui-group-cell`,scope:`rowgroup`,colSpan:Ht,children:/* @__PURE__ */ _(`button`,{type:`button`,className:`wui-group-toggle`,"aria-expanded":t,onClick:()=>nn(e.key),children:[/* @__PURE__ */ g(r,{name:`chevron-down`,size:16}),/* @__PURE__ */ g(`span`,{className:`wui-group-label`,children:Tt?Tt(i,a):He(Me(i,N??``))}),/* @__PURE__ */ g(`span`,{className:`wui-group-count`,"aria-hidden":`true`,children:se(e.items.length)}),/* @__PURE__ */ g(`span`,{className:`visually-hidden wui-group-rows`,children:`, ${u.rows(e.items.length)}`})]})})},`group:${e.key}`)},Sn=({row:e,i:t},n)=>{let i=L(e,t),o=z&&jt.has(i),s=St!=null&&String(St)===String(i),c=Ct!=null&&String(Ct)===String(i),l=String(i).replace(/[^a-z0-9]/gi,`_`),ee=V(0,`wui-expand-cell`),te=V(+!!z,`wui-select-cell`),u=X?ze(e,F,I):null,d=W(e,t),ne=C?.(e);if(C&&!Array.isArray(ne))throw TypeError(`AppDataTable: rowActions returns a list of actions ({ key, label, icon, onClick or href }). It returned something else: restate the buttons as a list, see node scripts/codemods/row-actions.mjs --check.`);let f=Z===void 0?void 0:v(e,Z),re=typeof f==`string`||typeof f==`number`?`More actions for ${f}`:`More actions`;return/* @__PURE__ */ _(xe,{children:[/* @__PURE__ */ _(`tr`,{className:[T&&d&&E?.has(i)?`is-selected`:``,R?`wui-row-link`:``,s?`wui-row-active`:``,c?De.hover:``].filter(Boolean).join(` `)||void 0,"aria-current":s?`true`:void 0,"aria-rowindex":U?n+2:void 0,"aria-busy":u?.state===`saving`?`true`:void 0,"data-wui-save-state":u?.state||void 0,"data-status":bt?.(e)||void 0,"data-href":j?.(e)||void 0,"data-row-key":k?String(i):void 0,tabIndex:R?0:void 0,onClick:R?t=>It(e,t):void 0,onAuxClick:R&&j?t=>t.button===1&&It(e,t):void 0,onKeyDown:R?t=>{le(t.nativeEvent)&&t.target===t.currentTarget&&It(e,t)}:void 0,children:[z&&/* @__PURE__ */ g(`td`,{className:ee.className,style:ee.style,children:/* @__PURE__ */ g(`button`,{type:`button`,className:`wui-expand-toggle${o?` is-open`:``}`,"aria-expanded":o,"aria-controls":o?`${l}-expanded`:void 0,"aria-label":o?`Collapse row`:`Expand row`,onClick:()=>Nt(i),children:/* @__PURE__ */ g(r,{name:`chevron-down`,size:16})})}),T&&/* @__PURE__ */ g(`td`,{className:te.className,style:te.style,children:/* @__PURE__ */ g(`input`,{type:`checkbox`,className:`wui-check`,checked:d&&(E?.has(i)||!1),disabled:!d,onChange:e=>Qt(i,e.nativeEvent instanceof MouseEvent&&e.nativeEvent.shiftKey),onMouseDown:e=>{e.shiftKey&&e.preventDefault()},"aria-label":`Select row`})}),y.map((t,n)=>{let r=t.rowHeader?`th`:`td`;return/* @__PURE__ */ _(r,{scope:t.rowHeader?`row`:void 0,className:V(B+n,(n===0?`wui-name-cell `:``)+(t.rowHeader?`wui-row-header `:``)+(t.nowrap?`text-nowrap `:``)+Be(t.align)+(t.cellClassName?` ${t.cellClassName}`:``)).className,style:H(B+n,t.cellStyle),"data-label":A&&typeof t.label==`string`?t.label:void 0,children:[t.render?t.render(e):He(Ne(e,t.key)),n===0&&u?.state===`error`&&/* @__PURE__ */ g(`span`,{className:ie,children:u.message})]},t.key)}),C&&/* @__PURE__ */ g(`td`,{children:/* @__PURE__ */ g(a,{items:ne??[],menuLabel:re,linkComponent:Qe})})]}),o&&/* @__PURE__ */ g(`tr`,{className:`wui-row-expanded`,children:/* @__PURE__ */ g(`td`,{id:`${l}-expanded`,colSpan:Ht,children:st?.(e)})})]},i)},Cn=(e,t)=>`group`in e?xn(e,t):Sn(e,t),wn=(e,t)=>U?/* @__PURE__ */ g(`tr`,{className:`wui-virtual-spacer`,"aria-hidden":`true`,hidden:t===0,children:/* @__PURE__ */ g(`td`,{colSpan:Ht,style:{height:t}})},e):null,Q=V(0,`wui-expand-cell`),$=V(+!!z,`wui-select-cell`),Tn=()=>Array.from({length:Je},(e,t)=>`skeleton-${t}`).map(e=>/* @__PURE__ */ _(`tr`,{children:[z&&/* @__PURE__ */ g(`td`,{className:Q.className,style:Q.style}),T&&/* @__PURE__ */ g(`td`,{className:$.className,style:$.style}),y.map((e,t)=>/* @__PURE__ */ g(`td`,{className:V(B+t,(t===0?`wui-name-cell `:``)+(e.nowrap?`text-nowrap `:``)+Be(e.align)).className,style:H(B+t,void 0),"data-label":A&&typeof e.label==`string`?e.label:void 0,children:/* @__PURE__ */ g(o,{width:Ve(e.align),height:12,radius:6})},e.key)),C&&/* @__PURE__ */ g(`td`,{children:/* @__PURE__ */ g(`div`,{className:`u-row-actions`,children:/* @__PURE__ */ g(o,{width:`32px`,height:12,radius:6})})})]},e));return/* @__PURE__ */ _(Ee,{children:[/* @__PURE__ */ _(Wt?`wui-data-table`:`div`,{ref:on,...Wt?{class:zt,resizable:M?``:void 0,"view-key":wt||void 0,"data-wui-row-drag":k?``:void 0,"aria-busy":Rt||void 0}:{className:zt,"data-wui-row-drag":k?``:void 0,"aria-busy":Rt||void 0},style:Vt,tabIndex:0,...be,...Ot,children:[/* @__PURE__ */ _(`table`,{className:At,"aria-label":et,"aria-rowcount":U?K.length+1:void 0,style:lt===`fixed`?{tableLayout:`fixed`}:void 0,children:[/* @__PURE__ */ g(`thead`,{children:/* @__PURE__ */ _(`tr`,{"aria-rowindex":U?1:void 0,children:[z&&/* @__PURE__ */ g(`th`,{className:Q.className,style:Q.style,children:/* @__PURE__ */ g(`span`,{className:`visually-hidden`,children:`Expand`})}),T&&/* @__PURE__ */ g(`th`,{className:$.className,style:$.style,children:/* @__PURE__ */ g(`input`,{ref:Xt,type:`checkbox`,className:`wui-check`,checked:Jt,disabled:S,onChange:e=>$t(e.target.checked),"aria-label":`Select all rows`})}),y.map((e,t)=>{let n=e.sortable?Ke:void 0,a=n!==void 0,o=Ge&&Ge.key===e.key,s=e.align===`num`||e.align===`end`,c=a&&/* @__PURE__ */ g(`span`,{className:`sort-icon${s?` wui-sort-lead`:``}`,children:/* @__PURE__ */ g(r,{name:`chevrons-up-down`,size:14})}),l=M&&t!==Kt,d=e.width||e.minWidth?{width:e.width,minWidth:e.minWidth}:void 0;return/* @__PURE__ */ _(`th`,{className:V(B+t,(a?`sortable `:``)+(t===0?`wui-name-cell `:``)+(e.nowrap?`text-nowrap `:``)+(e.grow?`wui-col-grow `:``)+(l?`wui-col-resizable `:``)+Be(e.align)).className,style:H(B+t,d),"data-key":Wt?e.key:void 0,"aria-label":l&&typeof e.label==`string`?e.label:void 0,"data-pin":e.pin===`start`||e.pin===`end`?e.pin:void 0,tabIndex:a?0:void 0,"aria-sort":o?Ge?.dir===`asc`?`ascending`:`descending`:a?`none`:void 0,onClick:n?t=>{t.target instanceof Element&&t.target.closest(`.infotip`)||S||n(e.key)}:void 0,onKeyDown:n?t=>{t.target===t.currentTarget&&(le(t.nativeEvent)||t.key===` `)&&(t.preventDefault(),S||n(e.key))}:void 0,children:[s&&c,e.label,!s&&c,e.help?/* @__PURE__ */ g(i,{label:typeof e.label==`string`?e.label:void 0,children:e.help}):null,l&&/* @__PURE__ */ g(`span`,{className:`wui-col-resize`,role:`separator`,"aria-orientation":`vertical`,"aria-valuemin":te,"aria-valuemax":ee,tabIndex:0,"aria-label":u.resize(typeof e.label==`string`?e.label:e.key)})]},e.key)}),C&&($e?/* @__PURE__ */ g(`th`,{className:`wui-cell-end`,children:$e}):/* @__PURE__ */ g(`th`,{className:`wui-cell-end`,children:/* @__PURE__ */ g(`span`,{className:`visually-hidden`,children:`Actions`})}))]})}),/* @__PURE__ */ g(`tbody`,{ref:mn,children:S?Tn():b?.length?/* @__PURE__ */ _(Ee,{children:[wn(`before`,Y.before),K.slice(Y.start,Y.end).map((e,t)=>Cn(e,Y.start+t)),wn(`after`,Y.after)]}):null}),Pt&&!S&&b?.length>0&&/* @__PURE__ */ g(`tfoot`,{children:/* @__PURE__ */ _(`tr`,{children:[z&&/* @__PURE__ */ g(`td`,{className:Q.className,style:Q.style}),T&&/* @__PURE__ */ g(`td`,{className:$.className,style:$.style}),y.map((e,t)=>/* @__PURE__ */ g(`td`,{className:V(B+t,(t===0?`wui-name-cell `:``)+(e.nowrap?`text-nowrap `:``)+Be(e.align)).className,style:H(B+t,void 0),children:e.footer?e.footer(b):null},e.key)),C&&/* @__PURE__ */ g(`td`,{})]})})]}),!S&&!b?.length&&/* @__PURE__ */ g(`div`,{className:`tbl-empty-block`,children:typeof bn==`string`?/* @__PURE__ */ g(`div`,{className:`tbl-empty-plain`,children:bn}):bn})]}),Ue(w)&&/* @__PURE__ */ g(s,{page:w.page,totalPages:w.totalPages,total:w.total,pageSize:w.pageSize,onPageChange:S?Ie:w.setPage,onPageSizeChange:S?Ie:w.setPageSize,pageSizes:w.pageSizes,mode:w.mode,summary:w.summary}),X&&/* @__PURE__ */ g(`div`,{ref:vn,className:`visually-hidden`,role:`status`,"aria-live":`polite`,"data-wui-table-status":``})]})}export{We as default};
@@ -1 +1 @@
1
- import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/FieldMessage.js";import n from"../lib/useElementEntry.js";import{splitMarkerProps as r}from"../lib/wuiMarker.js";import i from"./AppInfoTip.js";import a from"./AppRequiredMark.js";import o from"./assertValidValue.js";import s from"./textOf.js";import c from"./useWuiControl.js";import l from"./warnUnknownProps.js";import{cloneElement as u,forwardRef as d,useId as f}from"react";import{jsx as p,jsxs as m}from"react/jsx-runtime";var h=[`sm`,`md`,`lg`],g=()=>import(`@webority/ui-elements/elements/datepicker`),_=d(function(d,_){let v=n(`wui-datepicker`,g),{marker:y,props:b}=r(`AppDatePicker`,d),{value:x,onChange:S,label:C,required:w=!1,optional:T=!1,optionalLabel:E=`(optional)`,helperText:D,error:O,name:k,min:A,max:j,placeholder:M=`Choose a date`,disabled:N,readOnly:P=!1,loading:F=!1,defaultValue:I,help:L,helpLabel:ee=`More information`,size:R,firstDay:z,displayFormat:B,id:V,ariaLabel:H,className:U=``,fieldClassName:W=``,...G}=b;l(`AppDatePicker`,G),o(`AppDatePicker`,`size`,R,h),typeof B==`string`&&B!==``&&/DD|YYYY|YY/.test(B)&&e(`[@webority/ui-react] <AppDatePicker> displayFormat "${B}" uses uppercase day or year tokens, which print as written; the tokens are yyyy, MMMM, MMM, MM, dd and d.`);let K=f(),q=V||K,{setRef:J}=c({ready:v,ref:_,value:x??(I===void 0?``:void 0),defaultValue:I,onChange:S}),Y=!C&&!O&&!D,X=O?`${q}-error`:void 0,Z=D?`${q}-hint`:void 0,Q=X||Z,$=/* @__PURE__ */ p(`wui-datepicker`,{ref:J,id:q,name:k,value:(x??I)||void 0,min:A,max:j,placeholder:M,size:R||void 0,"first-day":z==null?void 0:String(z),"display-format":B||void 0,"aria-label":H||s(C)||void 0,"aria-describedby":Q,"aria-invalid":O?`true`:void 0,disabled:N?``:void 0,readonly:P?``:void 0,loading:F?``:void 0,required:w?``:void 0,className:U||void 0,...G});return Y?u($,y):/* @__PURE__ */ m(`div`,{...y,className:`field${W?` ${W}`:``}`,children:[C&&/* @__PURE__ */ m(`label`,{className:`label`,htmlFor:q,children:[C,T&&!w&&/* @__PURE__ */ p(`span`,{className:`label-optional`,children:` ${E}`}),w&&/* @__PURE__ */ p(a,{}),L&&/* @__PURE__ */ p(i,{label:ee,children:L})]}),$,/* @__PURE__ */ p(t,{error:O,hint:D,errorId:X,hintId:Z})]})});export{_ as default};
1
+ import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/FieldMessage.js";import{useFieldError as n}from"../lib/formFields.js";import r from"../lib/useElementEntry.js";import{splitMarkerProps as i}from"../lib/wuiMarker.js";import a from"./AppInfoTip.js";import o from"./AppRequiredMark.js";import s from"./assertValidValue.js";import ee from"./textOf.js";import c from"./useWuiControl.js";import l from"./warnUnknownProps.js";import{cloneElement as u,forwardRef as d,useId as f}from"react";import{jsx as p,jsxs as m}from"react/jsx-runtime";var h=[`sm`,`md`,`lg`],g=()=>import(`@webority/ui-elements/elements/datepicker`),_=d(function(d,_){let v=r(`wui-datepicker`,g),{marker:y,props:b}=i(`AppDatePicker`,d),{value:x,onChange:te,label:S,required:C=!1,optional:w=!1,optionalLabel:T=`(optional)`,helperText:E,error:D,name:O,min:k,max:A,placeholder:j=`Choose a date`,disabled:M,readOnly:N=!1,loading:P=!1,defaultValue:F,help:I,helpLabel:ne=`More information`,size:L,firstDay:R,displayFormat:z,id:B,ariaLabel:V,className:H=``,fieldClassName:U=``,...W}=b,G=n(O),K=D??G;l(`AppDatePicker`,W),s(`AppDatePicker`,`size`,L,h),typeof z==`string`&&z!==``&&/DD|YYYY|YY/.test(z)&&e(`[@webority/ui-react] <AppDatePicker> displayFormat "${z}" uses uppercase day or year tokens, which print as written; the tokens are yyyy, MMMM, MMM, MM, dd and d.`);let q=f(),J=B||q,{setRef:Y}=c({ready:v,ref:_,value:x??(F===void 0?``:void 0),defaultValue:F,onChange:te}),X=!S&&!K&&!E,Z=K?`${J}-error`:void 0,Q=E?`${J}-hint`:void 0,re=Z||Q,$=/* @__PURE__ */ p(`wui-datepicker`,{ref:Y,id:J,name:O,value:(x??F)||void 0,min:k,max:A,placeholder:j,size:L||void 0,"first-day":R==null?void 0:String(R),"display-format":z||void 0,"aria-label":V||ee(S)||void 0,"aria-describedby":re,"aria-invalid":K?`true`:void 0,disabled:M?``:void 0,readonly:N?``:void 0,loading:P?``:void 0,required:C?``:void 0,className:H||void 0,...W});return X?u($,y):/* @__PURE__ */ m(`div`,{...y,className:`field${U?` ${U}`:``}`,children:[S&&/* @__PURE__ */ m(`label`,{className:`label`,htmlFor:J,children:[S,w&&!C&&/* @__PURE__ */ p(`span`,{className:`label-optional`,children:` ${T}`}),C&&/* @__PURE__ */ p(o,{}),I&&/* @__PURE__ */ p(a,{label:ne,children:I})]}),$,/* @__PURE__ */ p(t,{error:K,hint:E,errorId:Z,hintId:Q})]})});export{_ as default};
@@ -1 +1 @@
1
- import e from"../lib/FieldMessage.js";import t from"../lib/useElementEntry.js";import{splitMarkerProps as n}from"../lib/wuiMarker.js";import ee from"./AppInfoTip.js";import te from"./AppRequiredMark.js";import r from"./assertValidValue.js";import i from"./textOf.js";import a from"./useWuiControl.js";import o from"./warnUnknownProps.js";import{cloneElement as s,forwardRef as c,useEffect as ne,useId as re,useRef as ie}from"react";import{jsx as l,jsxs as u}from"react/jsx-runtime";var d=[`sm`,`md`,`lg`],f=()=>import(`@webority/ui-elements/elements/date-range`),p=e=>{if(e?.length)return e.every(e=>typeof e==`string`)?e.join(`,`):JSON.stringify(e)},m=c(function(c,m){let h=t(`wui-date-range`,f),{marker:g,props:_}=n(`AppDateRangePicker`,c),{start:v,end:y,defaultStart:b,defaultEnd:x,onChange:ae,label:S,help:C,helpLabel:w=`More information`,required:T=!1,optional:E=!1,optionalLabel:D=`(optional)`,helperText:O,error:k,startName:A,endName:j,min:M,max:N,placeholder:P=`Start to End`,disabled:F,readOnly:I=!1,loading:L=!1,size:R,firstDay:z,timeZone:oe,financialYearStart:B,presets:V,id:H,ariaLabel:U,className:W=``,fieldClassName:G=``,...K}=_;o(`AppDateRangePicker`,K),r(`AppDateRangePicker`,`size`,R,d);let q=re(),J=H||q,{setRef:se,innerRef:Y}=a({ready:h,ref:e=>{typeof m==`function`?m(e):m&&(m.current=e)},onChange:ae}),X=ie(!1);ne(()=>{if(!h)return;let e=Y.current;if(!e)return;let t=v===void 0?!X.current&&b!==void 0?b:e.value.start:v,n=y===void 0?!X.current&&x!==void 0?x:e.value.end:y;(e.value.start!==t||e.value.end!==n)&&(e.value={start:t,end:n}),X.current=!0},[h,v,y,b,x,Y]);let ce=!S&&!k&&!O,Z=k?`${J}-error`:void 0,Q=O?`${J}-hint`:void 0,le=Z||Q,$=/* @__PURE__ */ l(`wui-date-range`,{ref:se,id:J,"start-name":A,"end-name":j,min:M,max:N,placeholder:P,size:R||void 0,"first-day":z==null?void 0:String(z),"time-zone":oe||void 0,"financial-year-start":B==null?void 0:String(B),presets:p(V),"aria-label":U||i(S)||void 0,"aria-describedby":le,"aria-invalid":k?`true`:void 0,disabled:F?``:void 0,readonly:I?``:void 0,loading:L?``:void 0,required:T?``:void 0,className:W||void 0,...K});return ce?s($,g):/* @__PURE__ */ u(`div`,{...g,className:`field${G?` ${G}`:``}`,children:[S&&/* @__PURE__ */ u(`label`,{className:`label`,htmlFor:J,children:[S,E&&!T&&/* @__PURE__ */ l(`span`,{className:`label-optional`,children:` ${D}`}),T&&/* @__PURE__ */ l(te,{}),C&&/* @__PURE__ */ l(ee,{label:w,children:C})]}),$,/* @__PURE__ */ l(e,{error:k,hint:O,errorId:Z,hintId:Q})]})});export{m as default};
1
+ import e from"../lib/FieldMessage.js";import{useFieldError as t}from"../lib/formFields.js";import n from"../lib/useElementEntry.js";import{splitMarkerProps as ee}from"../lib/wuiMarker.js";import te from"./AppInfoTip.js";import ne from"./AppRequiredMark.js";import r from"./assertValidValue.js";import i from"./textOf.js";import a from"./useWuiControl.js";import o from"./warnUnknownProps.js";import{cloneElement as s,forwardRef as c,useEffect as l,useId as re,useRef as ie}from"react";import{jsx as u,jsxs as d}from"react/jsx-runtime";var ae=[`sm`,`md`,`lg`],oe=()=>import(`@webority/ui-elements/elements/date-range`),se=e=>{if(e?.length)return e.every(e=>typeof e==`string`)?e.join(`,`):JSON.stringify(e)},f=c(function(c,f){let p=n(`wui-date-range`,oe),{marker:m,props:h}=ee(`AppDateRangePicker`,c),{start:g,end:_,defaultStart:v,defaultEnd:y,onChange:b,open:x,onOpenChange:S,label:C,help:w,helpLabel:ce=`More information`,required:T=!1,optional:E=!1,optionalLabel:D=`(optional)`,helperText:O,error:k,startName:A,endName:j,min:M,max:N,placeholder:P=`Start to End`,disabled:F,readOnly:I=!1,loading:L=!1,size:R,firstDay:z,timeZone:B,financialYearStart:V,presets:le,id:H,ariaLabel:U,className:W=``,fieldClassName:G=``,...K}=h,ue=t(A),de=t(j),q=k??ue??de;o(`AppDateRangePicker`,K),r(`AppDateRangePicker`,`size`,R,ae);let fe=re(),J=H||fe,{setRef:pe,innerRef:Y}=a({ready:p,ref:e=>{typeof f==`function`?f(e):f&&(f.current=e)},onChange:b}),X=ie(!1);l(()=>{if(!p)return;let e=Y.current;if(!e)return;let t=g===void 0?!X.current&&v!==void 0?v:e.value.start:g,n=_===void 0?!X.current&&y!==void 0?y:e.value.end:_;(e.value.start!==t||e.value.end!==n)&&(e.value={start:t,end:n}),X.current=!0},[p,g,_,v,y,Y]),l(()=>{if(!p||x===void 0)return;let e=Y.current;e&&e.open!==x&&(e.open=x)},[p,x,Y]),l(()=>{let e=Y.current;if(!p||!e||!S)return;let t=t=>{t instanceof CustomEvent&&t.target===e&&S(!!t.detail?.open)};return e.addEventListener(`wui-date-range:openchange`,t),()=>e.removeEventListener(`wui-date-range:openchange`,t)},[p,S,Y]);let me=!C&&!q&&!O,Z=q?`${J}-error`:void 0,Q=O?`${J}-hint`:void 0,he=Z||Q,$=/* @__PURE__ */ u(`wui-date-range`,{ref:pe,id:J,"start-name":A,"end-name":j,min:M,max:N,placeholder:P,size:R||void 0,"first-day":z==null?void 0:String(z),"time-zone":B||void 0,"financial-year-start":V==null?void 0:String(V),presets:se(le),"aria-label":U||i(C)||void 0,"aria-describedby":he,"aria-invalid":q?`true`:void 0,disabled:F?``:void 0,readonly:I?``:void 0,loading:L?``:void 0,required:T?``:void 0,className:W||void 0,...K});return me?s($,m):/* @__PURE__ */ d(`div`,{...m,className:`field${G?` ${G}`:``}`,children:[C&&/* @__PURE__ */ d(`label`,{className:`label`,htmlFor:J,children:[C,E&&!T&&/* @__PURE__ */ u(`span`,{className:`label-optional`,children:` ${D}`}),T&&/* @__PURE__ */ u(ne,{}),w&&/* @__PURE__ */ u(te,{label:ce,children:w})]}),$,/* @__PURE__ */ u(e,{error:q,hint:O,errorId:Z,hintId:Q})]})});export{f as default};
@@ -1 +1 @@
1
- import{isEmpty as e}from"../lib/emptyValue.js";import{linkTarget as t}from"../lib/linkTarget.js";import{TargetLink as n}from"../lib/TargetLink.js";import{splitMarkerProps as r}from"../lib/wuiMarker.js";import i from"./assertValidValue.js";import a from"./renderIconProp.js";import o from"./warnUnknownProps.js";import{jsx as s,jsxs as c}from"react/jsx-runtime";var l=[`sm`,`md`],u=[`grid`,`summary`,`list`],d=[1,2,3,4];function f(e,t){if(typeof e==`string`)return`${e}-${t}`;throw Error("<AppDescriptions> an item whose label is not text needs a `key`.")}function p(p){let{marker:m,props:h}=r(`AppDescriptions`,p),{items:g=[],columns:_=2,size:v=`md`,bordered:y=!1,layout:b=`grid`,title:x,linkComponent:S,className:C=``,...w}=h;o(`AppDescriptions`,w),i(`AppDescriptions`,`columns`,_,d),i(`AppDescriptions`,`size`,v,l),i(`AppDescriptions`,`layout`,b,u);let T=[`descs`,`descs-col-${_}`,v&&v!==`md`?`descs-${v}`:``,y?`descs-bordered`:``,b===`summary`?`wui-descs-summary`:``,b===`list`?`wui-descs-list`:``,_===4?`wui-descs-col-4`:``,C].filter(Boolean).join(` `)||void 0;return/* @__PURE__ */ c(`div`,{className:T,...m,...w,children:[x&&/* @__PURE__ */ s(`div`,{className:`descs-title`,children:x}),/* @__PURE__ */ s(`dl`,{className:`descs-list`,children:g.map((r,i)=>{let o=e(r.value),l=Math.min(12,Math.max(1,r.span??1)),u=r.key??f(r.label,i),d=o?`-`:r.value,p=t(S,{href:r.href});return/* @__PURE__ */ c(`div`,{className:`descs-item${r.emphasis?` wui-descs-emphasis`:``} wui-descs-span-${l}`,children:[r.icon&&/* @__PURE__ */ s(`span`,{className:`wui-descs-icon`,children:a(r.icon,{size:16})}),/* @__PURE__ */ s(`dt`,{className:`descs-label`,children:r.label}),/* @__PURE__ */ s(`dd`,{className:`descs-value${o?` is-empty`:``}${r.multiline&&!o?` wui-pre-line`:``}`,children:r.href?/* @__PURE__ */ s(n,{link:p,className:`wui-descs-link`,children:d}):d})]},u)})})]})}export{p as default};
1
+ import{isEmpty as e}from"../lib/emptyValue.js";import{linkTarget as t}from"../lib/linkTarget.js";import{TargetLink as n}from"../lib/TargetLink.js";import{splitMarkerProps as r}from"../lib/wuiMarker.js";import i from"./assertValidValue.js";import a from"./renderIconProp.js";import o from"./warnUnknownProps.js";import{jsx as s,jsxs as c}from"react/jsx-runtime";var l=[`sm`,`md`],u=[`grid`,`summary`,`list`],d=[1,2,3,4];function f(e,t){if(typeof e==`string`)return`${e}-${t}`;throw Error("<AppDescriptions> an item whose label is not text needs a `key`.")}function p(p){let{marker:m,props:h}=r(`AppDescriptions`,p),{items:g=[],columns:_=2,size:v=`md`,bordered:y=!1,layout:b=`grid`,title:x,linkComponent:S,className:C=``,...w}=h;o(`AppDescriptions`,w),i(`AppDescriptions`,`columns`,_,d),i(`AppDescriptions`,`size`,v,l),i(`AppDescriptions`,`layout`,b,u);let T=[`descs`,`descs-col-${_}`,v&&v!==`md`?`descs-${v}`:``,y?`descs-bordered`:``,b===`summary`?`wui-descs-summary`:``,b===`list`?`wui-descs-list`:``,_===4?`wui-descs-col-4`:``,C].filter(Boolean).join(` `)||void 0;return/* @__PURE__ */ c(`div`,{className:T,...m,...w,children:[x&&/* @__PURE__ */ s(`div`,{className:`descs-title`,children:x}),/* @__PURE__ */ s(`dl`,{className:`descs-list`,children:g.map((r,i)=>{let o=e(r.value),l=Math.min(12,Math.max(1,r.span??1)),u=r.key??f(r.label,i),d=o?`-`:r.value,p=t(S,{href:r.href}),m=Object.fromEntries(Object.entries(r).filter(([e])=>e.startsWith(`data-`)));return/* @__PURE__ */ c(`div`,{className:`descs-item${r.emphasis?` wui-descs-emphasis`:``} wui-descs-span-${l}`,id:r.id,tabIndex:r.tabIndex,...m,children:[r.icon&&/* @__PURE__ */ s(`span`,{className:`wui-descs-icon`,children:a(r.icon,{size:16})}),/* @__PURE__ */ s(`dt`,{className:`descs-label`,children:r.label}),/* @__PURE__ */ s(`dd`,{className:`descs-value${o?` is-empty`:``}${r.multiline&&!o?` wui-pre-line`:``}`,children:r.href?/* @__PURE__ */ s(n,{link:p,className:`wui-descs-link`,children:d}):d})]},u)})})]})}export{p as default};
@@ -1 +1 @@
1
- import e from"../lib/FieldMessage.js";import t from"../lib/fillLabel.js";import n from"../lib/useFileDrop.js";import{splitMarkerProps as r}from"../lib/wuiMarker.js";import i from"./AppIcon.js";import a from"./warnUnknownProps.js";import{DEFAULT_MAX_SIZE_MB as o,acceptDroppedFiles as s,acceptLabel as c}from"@webority/ui-elements/helpers";import{useId as l,useState as u}from"react";import{jsx as d,jsxs as f}from"react/jsx-runtime";function p(p){let{marker:m,props:h}=r(`AppDropZone`,p),{label:g,id:_,onChange:v,multiple:y=!1,accept:b=``,maxSizeMb:x=o,error:S,helperText:C,disabled:w=!1,className:T=``,fieldClassName:E=``,style:D,browseLabel:O=`Click to upload`,dropLabel:k=`or drag & drop`,anyTypeText:A=`Any file type`,maxSizeText:j=`up to {size} MB`,...M}=h;a(`AppDropZone`,M);let[N,P]=u(``),F=l(),I=_||F,L=S||N,R=L?`${I}-error`:void 0,z=C&&!L?`${I}-hint`:void 0,B=R||z,V=b?c(b):A,H={accept:b,maxSizeMb:x,multiple:y},U=e=>{P(``);let[t]=e;p.multiple?p.onChange(e):t&&p.onChange(t)},W=e=>P(e.message),{dragOver:G,dropProps:K}=n({...H,disabled:w,onFiles:U,onReject:W}),q=e=>{let{files:t,rejections:n}=s(e,H);if(!t.length&&!n.length)return;t.length&&U(t);let[r]=n;r&&W(r)};return/* @__PURE__ */ f(`div`,{...m,className:`field${E?` ${E}`:``}`,children:[g?/* @__PURE__ */ d(`label`,{className:`label`,htmlFor:I,children:g}):null,/* @__PURE__ */ f(`div`,{className:`file-input file-input-tall${G?` dragging`:``}${L?` error`:``}${T?` ${T}`:``}`,style:D,"aria-disabled":w||void 0,...K,children:[/* @__PURE__ */ f(`label`,{htmlFor:I,className:`file-input-zone-label`,children:[/* @__PURE__ */ d(`span`,{className:`file-input-icon`,children:/* @__PURE__ */ d(i,{name:`upload`,size:24})}),/* @__PURE__ */ f(`span`,{className:`file-input-title`,children:[/* @__PURE__ */ d(`span`,{className:`browse`,children:O}),` ${k}`]}),/* @__PURE__ */ d(`span`,{className:`file-input-text`,children:x>0?`${V}, ${t(j,{size:x})}`:V})]}),/* @__PURE__ */ d(`input`,{id:I,type:`file`,"aria-describedby":B,accept:b,multiple:y||void 0,disabled:w||void 0,className:`visually-hidden`,onClick:e=>{e.currentTarget.value=``},onChange:e=>q(e.target.files),...M})]}),/* @__PURE__ */ d(e,{error:L,hint:C,errorId:R,hintId:z})]})}export{p as default};
1
+ import e from"../lib/FieldMessage.js";import t from"../lib/fillLabel.js";import{useFieldError as n}from"../lib/formFields.js";import r from"../lib/useFileDrop.js";import{splitMarkerProps as i}from"../lib/wuiMarker.js";import a from"./AppIcon.js";import o from"./warnUnknownProps.js";import{DEFAULT_MAX_SIZE_MB as s,acceptDroppedFiles as c,acceptLabel as l}from"@webority/ui-elements/helpers";import{useId as u,useState as d}from"react";import{jsx as f,jsxs as p}from"react/jsx-runtime";function m(m){let{marker:h,props:g}=i(`AppDropZone`,m),{label:_,name:v,id:y,onChange:b,multiple:x=!1,accept:S=``,maxSizeMb:C=s,error:w,helperText:T,disabled:E=!1,className:D=``,fieldClassName:O=``,style:k,browseLabel:A=`Click to upload`,dropLabel:j=`or drag & drop`,anyTypeText:M=`Any file type`,maxSizeText:N=`up to {size} MB`,...P}=g;o(`AppDropZone`,P);let F=n(v),I=w??F,[L,R]=d(``),z=u(),B=y||z,V=I||L,H=V?`${B}-error`:void 0,U=T&&!V?`${B}-hint`:void 0,W=H||U,G=S?l(S):M,K={accept:S,maxSizeMb:C,multiple:x},q=e=>{R(``);let[t]=e;m.multiple?m.onChange(e):t&&m.onChange(t)},J=e=>R(e.message),{dragOver:Y,dropProps:X}=r({...K,disabled:E,onFiles:q,onReject:J}),Z=e=>{let{files:t,rejections:n}=c(e,K);if(!t.length&&!n.length)return;t.length&&q(t);let[r]=n;r&&J(r)};return/* @__PURE__ */ p(`div`,{...h,className:`field${O?` ${O}`:``}`,children:[_?/* @__PURE__ */ f(`label`,{className:`label`,htmlFor:B,children:_}):null,/* @__PURE__ */ p(`div`,{className:`file-input file-input-tall${Y?` dragging`:``}${V?` error`:``}${D?` ${D}`:``}`,style:k,"aria-disabled":E||void 0,...X,children:[/* @__PURE__ */ p(`label`,{htmlFor:B,className:`file-input-zone-label`,children:[/* @__PURE__ */ f(`span`,{className:`file-input-icon`,children:/* @__PURE__ */ f(a,{name:`upload`,size:24})}),/* @__PURE__ */ p(`span`,{className:`file-input-title`,children:[/* @__PURE__ */ f(`span`,{className:`browse`,children:A}),` ${j}`]}),/* @__PURE__ */ f(`span`,{className:`file-input-text`,children:C>0?`${G}, ${t(N,{size:C})}`:G})]}),/* @__PURE__ */ f(`input`,{id:B,type:`file`,"aria-describedby":W,name:v,accept:S,multiple:x||void 0,disabled:E||void 0,className:`visually-hidden`,onClick:e=>{e.currentTarget.value=``},onChange:e=>Z(e.target.files),...P})]}),/* @__PURE__ */ f(e,{error:V,hint:T,errorId:H,hintId:U})]})}export{m as default};
@@ -1 +1 @@
1
- import{devWarn as e}from"../lib/devWarn.js";import{linkTarget as t}from"../lib/linkTarget.js";import{shortcutAria as n,shortcutChip as ee}from"../lib/shortcutChip.js";import{TargetLink as r}from"../lib/TargetLink.js";import i from"../lib/useElementEntry.js";import{TONES as a}from"../lib/vocabulary.js";import{splitMarkerProps as o}from"../lib/wuiMarker.js";import s from"./AppIcon.js";import c from"./assertValidValue.js";import l from"./renderIconProp.js";import te from"./warnUnknownProps.js";import ne from"./withTooltip.js";import{Fragment as re,useEffect as u,useId as d,useRef as f,useState as p}from"react";import{Fragment as m,jsx as h,jsxs as g}from"react/jsx-runtime";var _=[`sm`,`md`,`lg`,`xl`],v=[`neutral`],y=[`sm`,`md`,`lg`,`fit`],ie=()=>import(`@webority/ui-elements/elements/dropdown`),b=e=>e.description?/* @__PURE__ */ g(`span`,{className:`wui-dropdown-item-body`,children:[/* @__PURE__ */ h(`span`,{className:`wui-dropdown-item-label`,children:e.label}),/* @__PURE__ */ h(`span`,{className:`wui-dropdown-item-desc`,children:e.description})]}):e.label,x=!1;function S(){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!x&&(x=!0,e("[@webority/ui-react] <AppDropdown> icon-only toggle has no accessible name — pass `label` or `ariaLabel`."))}function C(x){i(`wui-dropdown`,ie);let{marker:C,props:ae}=o(`AppDropdown`,x),{icon:oe,iconSize:se,toggleClassName:ce,toggleVariant:w,menuWidth:T,label:E,ariaLabel:D,align:O=`end`,items:k=[],menuClassName:A=``,linkComponent:j,children:M,trigger:N,open:P,onOpenChange:le,searchable:F,searchPlaceholder:I,noMatchText:L,...R}=ae;if(te(`AppDropdown`,R),F&&M!=null)throw Error(`<AppDropdown> searchable filters items, so it takes items and no children.`);if(!F&&(I!==void 0||L!==void 0))throw Error(`<AppDropdown> searchPlaceholder and noMatchText need searchable.`);for(let e of k)if(c(`AppDropdown`,`items[].hiddenFrom`,e.hiddenFrom,_),c(`AppDropdown`,`items[].tone`,e.tone,a),F&&e.label!=null&&typeof e.label!=`string`)throw RangeError(`<AppDropdown> searchable filters rows by their text, so every item label must be a string.`);N||D||E||S(),c(`AppDropdown`,`toggleVariant`,w,v),c(`AppDropdown`,`menuWidth`,T,y),w&&!N&&e(`AppDropdown: toggleVariant needs a trigger; the icon toggle ignores it.`);let z=(ce??(N?`wui-dropdown-trigger`:`topbar-icon-btn`))+(N&&w===`neutral`?` wui-dropdown-trigger-neutral`:``),B=[`dropdown-menu`,O===`end`?`dropdown-menu-end`:``,T&&y.includes(T)?`wui-dropdown-menu-${T}`:``,F?`wui-dropdown-menu-searchable`:``,A].filter(Boolean).join(` `),[V,H]=p(``),U=f(null),W=I??`Search`,G=L??`No matches.`,K=V.trim().toLowerCase(),q=K?k.filter(e=>!e.divider&&e.header==null&&(typeof e.label==`string`?e.label:``).toLowerCase().includes(K)):k,J=oe??(N?void 0:`more-horizontal`),Y=d(),X=P!==void 0,[ue,de]=p(!1),Z=X?!!P:ue,Q=f(null);Q.current=(e,t)=>{X||de(e),le?.(e,t)};let $=f(null);return u(()=>{let e=$.current;if(!e)return;let t=t=>{if(t.target===e){if(!(t instanceof CustomEvent))throw TypeError(`<wui-dropdown> toggle arrived without its detail.`);t.preventDefault(),Q.current?.(t.detail.open,{source:t.detail.source})}};return e.addEventListener(`wui-dropdown-toggle`,t),()=>e.removeEventListener(`wui-dropdown-toggle`,t)},[]),u(()=>{F&&Z&&U.current?.focus(),Z||H(``)},[Z,F]),u(()=>{let e=U.current;if(!F||!e)return;let t=t=>{if(t.key===`ArrowDown`||t.key===`ArrowUp`){t.preventDefault(),t.stopPropagation();let n=Array.from(e.closest(`.dropdown-menu`)?.querySelectorAll(`.dropdown-item`)??[]);(t.key===`ArrowDown`?n[0]:n[n.length-1])?.focus()}else t.key!==`Tab`&&t.key!==`Escape`&&t.stopPropagation()};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[F]),/* @__PURE__ */ g(`wui-dropdown`,{...C,...R,ref:$,class:[`dropdown`,R.className].filter(Boolean).join(` `),align:O,open:Z?``:void 0,children:[/* @__PURE__ */ h(`button`,{type:`button`,id:Y,"data-wui-dropdown-trigger":!0,"aria-expanded":Z?`true`:`false`,className:z,title:E,"aria-label":D??(N?void 0:E),children:N??(J===void 0?null:/* @__PURE__ */ h(s,{name:J,size:se??20}))}),/* @__PURE__ */ g(`div`,{className:B,"aria-labelledby":Y,"data-wui-dropdown-menu":!0,popover:`auto`,children:[F?/* @__PURE__ */ g(`div`,{className:`wui-dropdown-search`,children:[/* @__PURE__ */ h(s,{name:`search`,size:14}),/* @__PURE__ */ h(`input`,{ref:U,type:`search`,className:`wui-dropdown-search-input`,autoComplete:`off`,placeholder:W,"aria-label":W,value:V,onChange:e=>H(e.target.value)})]}):null,M??q.map(e=>{if(e.to&&e.href)throw RangeError(`AppDropdown: an item takes to or href, not both.`);if(e.header!=null)return/* @__PURE__ */ h(`div`,{className:`dropdown-header`,children:e.header},e.key);if(e.divider)return/* @__PURE__ */ h(`hr`,{className:`dropdown-divider`},e.key);if(e.disabled)return/* @__PURE__ */ h(re,{children:ne(/* @__PURE__ */ g(`button`,{type:`button`,className:[`dropdown-item`,e.tone===`danger`&&`danger`,`wui-dropdown-item-disabled`].filter(Boolean).join(` `),"aria-disabled":`true`,children:[e.image?/* @__PURE__ */ h(`img`,{src:e.image,alt:``}):l(e.icon,{size:16}),b(e),e.disabledReason&&/* @__PURE__ */ g(`span`,{className:`visually-hidden wui-dropdown-item-reason`,children:[`: `,e.disabledReason]})]}),e.disabledReason,`auto`)},e.key);let i=[`dropdown-item`,e.tone===`danger`&&`danger`,e.hiddenFrom&&_.includes(e.hiddenFrom)&&`wui-hidden-from-${e.hiddenFrom}`].filter(Boolean).join(` `)||void 0,a=/* @__PURE__ */ g(m,{children:[e.image?/* @__PURE__ */ h(`img`,{src:e.image,alt:``}):l(e.icon,{size:16}),b(e),ee(e.shortcut)]}),o={className:i,onClick:e.onClick,"aria-keyshortcuts":n(e.shortcut)};return e.to?/* @__PURE__ */ h(r,{link:t(j,{to:e.to}),...o,children:a},e.key):e.href?/* @__PURE__ */ h(r,{link:t(j,{href:e.href,external:!0}),...o,children:a},e.key):/* @__PURE__ */ h(`button`,{type:`button`,...o,children:a},e.key)}),F&&K&&q.length===0?/* @__PURE__ */ h(`div`,{className:`wui-dropdown-empty`,role:`status`,children:G}):null]})]})}export{C as default};
1
+ import{devWarn as e}from"../lib/devWarn.js";import{linkTarget as t}from"../lib/linkTarget.js";import{shortcutAria as n,shortcutChip as ee}from"../lib/shortcutChip.js";import{TargetLink as r}from"../lib/TargetLink.js";import i from"../lib/useElementEntry.js";import{TONES as a}from"../lib/vocabulary.js";import{splitMarkerProps as o}from"../lib/wuiMarker.js";import s from"./AppIcon.js";import c from"./assertValidValue.js";import l from"./renderIconProp.js";import te from"./warnUnknownProps.js";import ne from"./withTooltip.js";import{Fragment as re,useEffect as u,useId as d,useRef as f,useState as p}from"react";import{Fragment as m,jsx as h,jsxs as g}from"react/jsx-runtime";var _=[`sm`,`md`,`lg`,`xl`],v=[`neutral`],y=[`sm`,`md`,`lg`,`fit`],ie=()=>import(`@webority/ui-elements/elements/dropdown`),b=e=>e.description?/* @__PURE__ */ g(`span`,{className:`wui-dropdown-item-body`,children:[/* @__PURE__ */ h(`span`,{className:`wui-dropdown-item-label`,children:e.label}),/* @__PURE__ */ h(`span`,{className:`wui-dropdown-item-desc`,children:e.description})]}):e.label,x=!1;function S(){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!x&&(x=!0,e("[@webority/ui-react] <AppDropdown> icon-only toggle has no accessible name — pass `label` or `ariaLabel`."))}function C(x){i(`wui-dropdown`,ie);let{marker:C,props:ae}=o(`AppDropdown`,x),{icon:oe,iconSize:se,toggleClassName:ce,toggleVariant:w,menuWidth:T,label:E,ariaLabel:D,align:O=`end`,items:k=[],menuClassName:A=``,linkComponent:j,children:M,trigger:N,open:P,onOpenChange:le,searchable:F,searchPlaceholder:I,noMatchText:L,...R}=ae;if(te(`AppDropdown`,R),F&&M!=null)throw Error(`<AppDropdown> searchable filters items, so it takes items and no children.`);if(!F&&(I!==void 0||L!==void 0))throw Error(`<AppDropdown> searchPlaceholder and noMatchText need searchable.`);for(let e of k)if(c(`AppDropdown`,`items[].hiddenFrom`,e.hiddenFrom,_),c(`AppDropdown`,`items[].tone`,e.tone,a),F&&e.label!=null&&typeof e.label!=`string`)throw RangeError(`<AppDropdown> searchable filters rows by their text, so every item label must be a string.`);N||D||E||S(),c(`AppDropdown`,`toggleVariant`,w,v),c(`AppDropdown`,`menuWidth`,T,y),w&&!N&&e(`AppDropdown: toggleVariant needs a trigger; the icon toggle ignores it.`);let z=(ce??(N?`wui-dropdown-trigger`:`topbar-icon-btn`))+(N&&w===`neutral`?` wui-dropdown-trigger-neutral`:``),B=[`dropdown-menu`,O===`end`?`dropdown-menu-end`:``,T&&y.includes(T)?`wui-dropdown-menu-${T}`:``,F?`wui-dropdown-menu-searchable`:``,A].filter(Boolean).join(` `),[V,H]=p(``),U=f(null),W=I??`Search`,G=L??`No matches.`,K=V.trim().toLowerCase(),q=K?k.filter(e=>!e.divider&&e.header==null&&(typeof e.label==`string`?e.label:``).toLowerCase().includes(K)):k,J=oe??(N?void 0:`more-horizontal`),Y=d(),X=P!==void 0,[ue,de]=p(!1),Z=X?!!P:ue,Q=f(null);Q.current=(e,t)=>{X||de(e),le?.(e,t)};let $=f(null);return u(()=>{let e=$.current;if(!e)return;let t=t=>{if(t.target===e){if(!(t instanceof CustomEvent))throw TypeError(`<wui-dropdown> toggle arrived without its detail.`);t.preventDefault(),Q.current?.(t.detail.open,{source:t.detail.source})}};return e.addEventListener(`wui-dropdown-toggle`,t),()=>e.removeEventListener(`wui-dropdown-toggle`,t)},[]),u(()=>{F&&Z&&U.current?.focus(),Z||H(``)},[Z,F]),u(()=>{let e=U.current;if(!F||!e)return;let t=t=>{if(t.key===`ArrowDown`||t.key===`ArrowUp`){t.preventDefault(),t.stopPropagation();let n=Array.from(e.closest(`.dropdown-menu`)?.querySelectorAll(`.dropdown-item`)??[]);(t.key===`ArrowDown`?n[0]:n[n.length-1])?.focus()}else t.key!==`Tab`&&t.key!==`Escape`&&t.stopPropagation()};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[F]),/* @__PURE__ */ g(`wui-dropdown`,{...C,...R,ref:$,class:[`dropdown`,R.className].filter(Boolean).join(` `),align:O,open:Z?``:void 0,children:[/* @__PURE__ */ h(`button`,{type:`button`,id:Y,"data-wui-dropdown-trigger":!0,"aria-expanded":Z?`true`:`false`,className:z,title:E,"aria-label":D??(N?void 0:E),children:N??(J===void 0?null:/* @__PURE__ */ h(s,{name:J,size:se??20}))}),/* @__PURE__ */ g(`div`,{className:B,"aria-labelledby":Y,"data-wui-dropdown-menu":!0,popover:`auto`,children:[F?/* @__PURE__ */ g(`div`,{className:`wui-dropdown-search`,children:[/* @__PURE__ */ h(s,{name:`search`,size:14}),/* @__PURE__ */ h(`input`,{ref:U,type:`search`,className:`wui-dropdown-search-input`,autoComplete:`off`,placeholder:W,"aria-label":W,value:V,onChange:e=>H(e.target.value)})]}):null,M??q.map(e=>{if(e.to&&e.href)throw RangeError(`AppDropdown: an item takes to or href, not both.`);if(e.header!=null)return/* @__PURE__ */ h(`div`,{className:`dropdown-header`,children:e.header},e.key);if(e.divider)return/* @__PURE__ */ h(`hr`,{className:`dropdown-divider`},e.key);if(e.disabled)return/* @__PURE__ */ h(re,{children:ne(/* @__PURE__ */ g(`button`,{type:`button`,className:[`dropdown-item`,e.tone===`danger`&&`danger`,`wui-dropdown-item-disabled`,e.hiddenFrom&&_.includes(e.hiddenFrom)&&`wui-hidden-from-${e.hiddenFrom}`].filter(Boolean).join(` `),"aria-disabled":`true`,children:[e.image?/* @__PURE__ */ h(`img`,{src:e.image,alt:``}):l(e.icon,{size:16}),b(e),e.disabledReason&&/* @__PURE__ */ g(`span`,{className:`visually-hidden wui-dropdown-item-reason`,children:[`: `,e.disabledReason]})]}),e.disabledReason,`auto`)},e.key);let i=[`dropdown-item`,e.tone===`danger`&&`danger`,e.hiddenFrom&&_.includes(e.hiddenFrom)&&`wui-hidden-from-${e.hiddenFrom}`].filter(Boolean).join(` `)||void 0,a=/* @__PURE__ */ g(m,{children:[e.image?/* @__PURE__ */ h(`img`,{src:e.image,alt:``}):l(e.icon,{size:16}),b(e),ee(e.shortcut)]}),o={className:i,onClick:e.onClick,"aria-keyshortcuts":n(e.shortcut)};return e.to?/* @__PURE__ */ h(r,{link:t(j,{to:e.to}),...o,children:a},e.key):e.href?/* @__PURE__ */ h(r,{link:t(j,{href:e.href,external:!0}),...o,children:a},e.key):/* @__PURE__ */ h(`button`,{type:`button`,...o,children:a},e.key)}),F&&K&&q.length===0?/* @__PURE__ */ h(`div`,{className:`wui-dropdown-empty`,role:`status`,children:G}):null]})]})}export{C as default};
@@ -0,0 +1 @@
1
+ import e from"../lib/useElementEntry.js";import{splitMarkerProps as t}from"../lib/wuiMarker.js";import n from"./AppIcon.js";import r from"./AppInfoTip.js";import i from"./AppKbd.js";import a from"./AppSpinner.js";import o from"./assertValidValue.js";import s from"./warnUnknownProps.js";import{Fragment as c,useEffect as l,useRef as u}from"react";import{Fragment as d,jsx as f,jsxs as p}from"react/jsx-runtime";var m=[`text`,`number`],h=[`clean`,`dirty`,`saving`,`saved`,`failed`],g=()=>import(`@webority/ui-elements/elements/entry-grid`);function _(_){e(`wui-entry-grid`,g);let{marker:v,props:y}=t(`AppEntryGrid`,_),{columns:b,rows:x,rowKey:S,activeRowKey:C,onActiveRowChange:w,renderCell:T,rowState:E,rowError:D,onCommitRow:O,onDiscardRow:k,onAddRow:A,renderRowDetail:j,hint:M=!0,label:N=`Entry lines`,addLabel:P=`Add line`,emptyLabel:F=`No lines yet`,statusLabel:I=`Status`,dirtyLabel:L=`Changed`,savingLabel:R=`Saving`,savedLabel:z=`Saved`,failedLabel:B=`Not saved`,commitNextLabel:V=`Save and go to the next line`,commitStayLabel:H=`Save`,discardLabel:U=`Discard changes`,moveLabel:W=`Move between lines`,className:G=``,...K}=y;s(`AppEntryGrid`,K);for(let e of b)o(`AppEntryGrid`,`columns[].kind`,e.kind,m);let q=x.map(e=>{let t=E?E(e):`clean`;return o(`AppEntryGrid`,`rowState()`,t,h),t}),J=u(null),Y=u({rows:x,rowKey:S,onCommitRow:O,onDiscardRow:k,onActiveRowChange:w,onAddRow:A});Y.current={rows:x,rowKey:S,onCommitRow:O,onDiscardRow:k,onActiveRowChange:w,onAddRow:A},l(()=>{let e=J.current;if(!e)return;let t=e=>{let t=e instanceof CustomEvent?e.detail?.rowKey:void 0,{rows:n,rowKey:r}=Y.current;return typeof t==`string`?n.find(e=>r(e)===t):void 0},n=e=>{let n=t(e),r=e instanceof CustomEvent?e.detail?.move:void 0;n!==void 0&&(r===`next`||r===`stay`)&&Y.current.onCommitRow?.(n,r)},r=e=>{let n=t(e);n!==void 0&&Y.current.onDiscardRow?.(n)},i=e=>{let n=t(e);n!==void 0&&Y.current.onActiveRowChange?.(Y.current.rowKey(n))},a=()=>Y.current.onAddRow?.();return e.addEventListener(`wui-entry-grid:commit`,n),e.addEventListener(`wui-entry-grid:discard`,r),e.addEventListener(`wui-entry-grid:active`,i),e.addEventListener(`wui-entry-grid:add`,a),()=>{e.removeEventListener(`wui-entry-grid:commit`,n),e.removeEventListener(`wui-entry-grid:discard`,r),e.removeEventListener(`wui-entry-grid:active`,i),e.removeEventListener(`wui-entry-grid:add`,a)}},[]);let X=e=>e===`dirty`?/* @__PURE__ */ f(`span`,{className:`wui-entry-grid-dot`,role:`img`,"aria-label":L}):e===`saving`?/* @__PURE__ */ f(a,{size:`sm`,label:R}):e===`saved`?/* @__PURE__ */ p(d,{children:[/* @__PURE__ */ f(n,{name:`tick-circle`,size:16}),/* @__PURE__ */ f(`span`,{className:`visually-hidden`,children:z})]}):e===`failed`?/* @__PURE__ */ p(d,{children:[/* @__PURE__ */ f(n,{name:`danger`,size:16}),/* @__PURE__ */ f(`span`,{className:`visually-hidden`,children:B})]}):null,Z=b.some(e=>e.footer),Q=b.length+1,$=e=>e.kind===`number`?`text-end`:void 0;return/* @__PURE__ */ p(`wui-entry-grid`,{ref:J,class:[`wui-entry-grid`,G].filter(Boolean).join(` `),"active-row":C??``,...v,...K,children:[/* @__PURE__ */ f(`div`,{className:`table-responsive wui-entry-grid-scroll`,children:/* @__PURE__ */ p(`table`,{className:`table wui-entry-grid-table`,"aria-label":N,children:[/* @__PURE__ */ f(`thead`,{children:/* @__PURE__ */ p(`tr`,{children:[/* @__PURE__ */ f(`th`,{scope:`col`,className:`wui-entry-grid-status`,children:/* @__PURE__ */ f(`span`,{className:`visually-hidden`,children:I})}),b.map(e=>/* @__PURE__ */ p(`th`,{scope:`col`,className:$(e),style:e.width===void 0?void 0:{width:e.width},children:[e.label,e.help?/* @__PURE__ */ f(r,{label:typeof e.label==`string`?e.label:void 0,children:e.help}):null]},e.key))]})}),/* @__PURE__ */ p(`tbody`,{children:[x.map((e,t)=>{let n=S(e),r=q[t]??`clean`,i=n===C,a=r===`failed`&&D!==void 0,o=i&&j!==void 0,s=[`wui-entry-grid-row`,i&&`is-active`,r!==`clean`&&`wui-entry-grid-row-${r}`].filter(Boolean).join(` `);return/* @__PURE__ */ p(c,{children:[/* @__PURE__ */ p(`tr`,{className:s,"data-row-key":n,"aria-current":i?`true`:void 0,children:[/* @__PURE__ */ f(`td`,{className:`wui-entry-grid-status`,children:X(r)}),b.map(t=>/* @__PURE__ */ f(`td`,{className:$(t),"data-kind":t.kind??`text`,children:T(e,t,i)},t.key))]}),a||o?/* @__PURE__ */ f(`tr`,{className:`wui-entry-grid-detail`,children:/* @__PURE__ */ p(`td`,{colSpan:Q,children:[a?/* @__PURE__ */ f(`div`,{className:`wui-entry-grid-error`,role:`alert`,children:D(e)}):null,o?j(e):null]})}):null]},n)}),x.length===0?/* @__PURE__ */ f(`tr`,{className:`wui-entry-grid-empty`,children:/* @__PURE__ */ f(`td`,{colSpan:Q,children:F})}):null]}),Z?/* @__PURE__ */ f(`tfoot`,{className:`wui-entry-grid-footer`,children:/* @__PURE__ */ p(`tr`,{children:[/* @__PURE__ */ f(`td`,{}),b.map(e=>/* @__PURE__ */ f(`td`,{className:$(e),children:e.footer?.(x)},e.key))]})}):null]})}),/* @__PURE__ */ p(`div`,{className:`wui-entry-grid-bar`,children:[A?/* @__PURE__ */ f(`button`,{type:`button`,className:`btn btn-sm btn-outline-primary wui-entry-grid-add`,children:P}):null,M?/* @__PURE__ */ p(`ul`,{className:`wui-entry-grid-hint`,children:[/* @__PURE__ */ p(`li`,{children:[/* @__PURE__ */ f(i,{children:`Enter`}),` ${V}`]}),/* @__PURE__ */ p(`li`,{children:[/* @__PURE__ */ f(i,{children:`Ctrl`}),`+`,/* @__PURE__ */ f(i,{children:`S`}),` ${H}`]}),/* @__PURE__ */ p(`li`,{children:[/* @__PURE__ */ f(i,{children:`Esc`}),` ${U}`]}),/* @__PURE__ */ p(`li`,{children:[/* @__PURE__ */ f(i,{children:`Ctrl`}),`+`,/* @__PURE__ */ f(i,{children:`↑`}),`/`,/* @__PURE__ */ f(i,{children:`↓`}),` ${W}`]})]}):null]})]})}export{_ as default};
@@ -1 +1 @@
1
- import e from"../lib/FieldMessage.js";import t from"../lib/FileItemRow.js";import{keyOf as n,linkOf as r,nameOf as i,sizeLabelOf as a,uploadErrorOf as o,uploadProgressOf as s,useItemUrl as c}from"../lib/fileItem.js";import l from"../lib/fillLabel.js";import{linkTarget as ee}from"../lib/linkTarget.js";import{TargetLink as u}from"../lib/TargetLink.js";import d from"../lib/useFileDrop.js";import{splitMarkerProps as f}from"../lib/wuiMarker.js";import p from"./AppIcon.js";import m from"./AppProgress.js";import h from"./warnUnknownProps.js";import{DEFAULT_IMAGE_ACCEPT as g,DEFAULT_MAX_SIZE_MB as _,acceptDroppedFiles as v,acceptLabel as y,isImageFile as b,isImageOnlyAccept as x}from"@webority/ui-elements/helpers";import{useId as S,useState as C}from"react";import{jsx as w,jsxs as T}from"react/jsx-runtime";function E(i){let{marker:a,props:o}=f(`AppFileAttachment`,i),{label:s=`Attachment`,value:c,name:l,onChange:ee,multiple:u=!1,accept:m=g,maxSizeMb:y=_,optional:E=!1,validate:A=!0,error:j,id:M,linkComponent:N,browseLabel:P=`Browse`,removeLabel:F=`Remove attachment`,uploadingLabel:te=`Uploading {name}`,maxSizeText:ne=`Up to {size} MB`,typesAndMaxSizeText:re=`{types}, up to {size} MB`,removeFileLabel:ie=`Remove {name}`,optionalLabel:ae=`(optional)`,dropTitle:oe,...I}=o;if(h(`AppFileAttachment`,I),!u&&Array.isArray(c))throw TypeError(`[@webority/ui-react] <AppFileAttachment> received a list of files as value without multiple. Pass one file (or null), or set multiple to take a list.`);let L=S(),R=M||L,[z,B]=C(``),V=Array.isArray(c)?c:c?[c]:[],H=x(m),U=e=>e instanceof File?b(e):H||b(O(e)),W=V[0],G=!u&&W!==void 0&&U(W)&&(W instanceof File||r(W)!==null)?W:void 0,K=D(m,y,ne,re),q=A?{accept:m,maxSizeMb:y,multiple:u}:{accept:``,maxSizeMb:0,multiple:u},J=e=>{i.multiple||i.onChange(e)},Y=e=>{i.multiple&&i.onChange(e)};function X(e){if(B(``),u){let t=Array.isArray(c)?c:c?[c]:[],r=new Set(t.map(n)),i=t.concat(e.filter(e=>!r.has(n(e))));Y(i)}else J(e[0]??null)}function se(e){if(!e.length)return;let{files:t,rejections:n}=v(e,q);t.length&&X(t),B(n[0]?.message??``)}let{dragOver:ce,dropProps:le}=d({...q,disabled:I.disabled,onFiles:X,onReject:e=>B(e.message)});function ue(e){let t=Array.from(e.target.files||[]);e.target.value=``,se(t)}function Z(e){B(``),u?Y(V.filter((t,n)=>n!==e)):J(null)}let Q=j||z,de=Q?`${R}-error`:void 0,fe=u||V.length===0,$=H?`image`:`file`,pe=oe??(u?`Add ${$}s`:`Add ${H?`an`:`a`} ${$}`);return/* @__PURE__ */ T(`div`,{...a,className:`field`,children:[/* @__PURE__ */ T(`label`,{className:`label`,htmlFor:R,children:[s,E&&/* @__PURE__ */ w(`span`,{className:`label-optional`,children:` ${ae}`})]}),/* @__PURE__ */ T(`label`,{className:`attach-drop${ce?` dragging`:``}`,htmlFor:R,style:fe?void 0:{display:`none`},...le,children:[/* @__PURE__ */ w(`span`,{className:`attach-drop-icon`,children:/* @__PURE__ */ w(p,{name:H?`image`:`file-text`,size:18})}),/* @__PURE__ */ T(`span`,{className:`attach-drop-copy`,children:[/* @__PURE__ */ w(`span`,{className:`attach-drop-title`,children:pe}),K&&/* @__PURE__ */ w(`span`,{className:`attach-drop-hint`,children:K})]}),/* @__PURE__ */ w(`span`,{className:`attach-drop-cta`,children:P})]}),/* @__PURE__ */ w(`input`,{id:R,type:`file`,className:`visually-hidden`,name:l,accept:m||void 0,multiple:u||void 0,"aria-describedby":de,onChange:ue,...I}),G?/* @__PURE__ */ w(k,{item:G,isImage:!0,linkComponent:N,onRemove:()=>Z(0),removeLabel:F,uploadingLabel:te}):V.length>0&&/* @__PURE__ */ w(`div`,{className:`attach-list`,children:V.map((e,r)=>/* @__PURE__ */ w(t,{item:e,isImage:U(e),linkComponent:N,onRemove:()=>Z(r),removeFileLabel:ie},n(e)))}),/* @__PURE__ */ w(e,{error:Q,errorId:`${R}-error`})]})}function D(e,t,n,r){let i=e?.trim()?y(e):``,a=t>0;return i&&a?l(r,{types:i,size:t}):a?l(n,{size:t}):i}function O({name:e,url:t}){return{...e===void 0?null:{name:e},...t===void 0?null:{url:t}}}function k({item:e,isImage:t,linkComponent:n,onRemove:d,removeLabel:f,uploadingLabel:h}){let g=c(e,t),_=i(e),v=a(e),y=s(e),b=o(e),x=r(e),S=e instanceof File?void 0:e.to,C=ee(n,{to:S,href:x??void 0,routeHref:!1});return/* @__PURE__ */ T(`div`,{className:b?`attach-preview wui-attach-failed`:`attach-preview`,children:[/* @__PURE__ */ T(`div`,{className:`attach-figure`,children:[/* @__PURE__ */ w(`img`,{src:g??void 0,alt:_}),/* @__PURE__ */ w(`button`,{type:`button`,className:`attach-remove`,"aria-label":f,onClick:d,children:/* @__PURE__ */ w(p,{name:`x`,size:18})})]}),/* @__PURE__ */ T(`div`,{className:`attach-meta`,children:[/* @__PURE__ */ w(`div`,{className:`attach-name`,children:x||S?/* @__PURE__ */ w(u,{link:C,children:_}):_}),v&&/* @__PURE__ */ w(`div`,{className:`attach-size`,children:v})]}),y!==null&&/* @__PURE__ */ w(m,{value:y,size:`sm`,label:l(h,{name:_}),className:`wui-attach-progress`}),b&&/* @__PURE__ */ w(`div`,{className:`wui-attach-error`,children:b})]})}export{E as default};
1
+ import e from"../lib/FieldMessage.js";import t from"../lib/FileItemRow.js";import{keyOf as n,linkOf as r,nameOf as i,sizeLabelOf as a,uploadErrorOf as o,uploadProgressOf as s,useItemUrl as c}from"../lib/fileItem.js";import l from"../lib/fillLabel.js";import{useFieldError as u}from"../lib/formFields.js";import{linkTarget as d}from"../lib/linkTarget.js";import{TargetLink as f}from"../lib/TargetLink.js";import p from"../lib/useFileDrop.js";import{splitMarkerProps as m}from"../lib/wuiMarker.js";import h from"./AppIcon.js";import g from"./AppProgress.js";import _ from"./warnUnknownProps.js";import{DEFAULT_IMAGE_ACCEPT as v,DEFAULT_MAX_SIZE_MB as y,acceptDroppedFiles as b,acceptLabel as x,isImageFile as S,isImageOnlyAccept as C}from"@webority/ui-elements/helpers";import{useId as w,useState as T}from"react";import{jsx as E,jsxs as D}from"react/jsx-runtime";function O(i){let{marker:a,props:o}=m(`AppFileAttachment`,i),{label:s=`Attachment`,value:c,name:l,onChange:d,multiple:f=!1,accept:g=v,maxSizeMb:x=y,optional:O=!1,validate:A=!0,error:j,id:M,linkComponent:N,browseLabel:ne=`Browse`,removeLabel:re=`Remove attachment`,uploadingLabel:ie=`Uploading {name}`,maxSizeText:ae=`Up to {size} MB`,typesAndMaxSizeText:oe=`{types}, up to {size} MB`,removeFileLabel:se=`Remove {name}`,optionalLabel:ce=`(optional)`,dropTitle:le,...P}=o,F=u(l),I=j??F;if(_(`AppFileAttachment`,P),!f&&Array.isArray(c))throw TypeError(`[@webority/ui-react] <AppFileAttachment> received a list of files as value without multiple. Pass one file (or null), or set multiple to take a list.`);let L=w(),R=M||L,[z,B]=T(``),V=Array.isArray(c)?c:c?[c]:[],H=C(g),U=e=>e instanceof File?S(e):H||S(te(e)),W=V[0],G=!f&&W!==void 0&&U(W)&&(W instanceof File||r(W)!==null)?W:void 0,K=ee(g,x,ae,oe),q=A?{accept:g,maxSizeMb:x,multiple:f}:{accept:``,maxSizeMb:0,multiple:f},J=e=>{i.multiple||i.onChange(e)},Y=e=>{i.multiple&&i.onChange(e)};function X(e){if(B(``),f){let t=Array.isArray(c)?c:c?[c]:[],r=new Set(t.map(n)),i=t.concat(e.filter(e=>!r.has(n(e))));Y(i)}else J(e[0]??null)}function ue(e){if(!e.length)return;let{files:t,rejections:n}=b(e,q);t.length&&X(t),B(n[0]?.message??``)}let{dragOver:de,dropProps:fe}=p({...q,disabled:P.disabled,onFiles:X,onReject:e=>B(e.message)});function pe(e){let t=Array.from(e.target.files||[]);e.target.value=``,ue(t)}function Z(e){B(``),f?Y(V.filter((t,n)=>n!==e)):J(null)}let Q=I||z,me=Q?`${R}-error`:void 0,he=f||V.length===0,$=H?`image`:`file`,ge=le??(f?`Add ${$}s`:`Add ${H?`an`:`a`} ${$}`);return/* @__PURE__ */ D(`div`,{...a,className:`field`,children:[/* @__PURE__ */ D(`label`,{className:`label`,htmlFor:R,children:[s,O&&/* @__PURE__ */ E(`span`,{className:`label-optional`,children:` ${ce}`})]}),/* @__PURE__ */ D(`label`,{className:`attach-drop${de?` dragging`:``}`,htmlFor:R,style:he?void 0:{display:`none`},...fe,children:[/* @__PURE__ */ E(`span`,{className:`attach-drop-icon`,children:/* @__PURE__ */ E(h,{name:H?`image`:`file-text`,size:18})}),/* @__PURE__ */ D(`span`,{className:`attach-drop-copy`,children:[/* @__PURE__ */ E(`span`,{className:`attach-drop-title`,children:ge}),K&&/* @__PURE__ */ E(`span`,{className:`attach-drop-hint`,children:K})]}),/* @__PURE__ */ E(`span`,{className:`attach-drop-cta`,children:ne})]}),/* @__PURE__ */ E(`input`,{id:R,type:`file`,className:`visually-hidden`,name:l,accept:g||void 0,multiple:f||void 0,"aria-describedby":me,onChange:pe,...P}),G?/* @__PURE__ */ E(k,{item:G,isImage:!0,linkComponent:N,onRemove:()=>Z(0),removeLabel:re,uploadingLabel:ie}):V.length>0&&/* @__PURE__ */ E(`div`,{className:`attach-list`,children:V.map((e,r)=>/* @__PURE__ */ E(t,{item:e,isImage:U(e),linkComponent:N,onRemove:()=>Z(r),removeFileLabel:se},n(e)))}),/* @__PURE__ */ E(e,{error:Q,errorId:`${R}-error`})]})}function ee(e,t,n,r){let i=e?.trim()?x(e):``,a=t>0;return i&&a?l(r,{types:i,size:t}):a?l(n,{size:t}):i}function te({name:e,url:t}){return{...e===void 0?null:{name:e},...t===void 0?null:{url:t}}}function k({item:e,isImage:t,linkComponent:n,onRemove:u,removeLabel:p,uploadingLabel:m}){let _=c(e,t),v=i(e),y=a(e),b=s(e),x=o(e),S=r(e),C=e instanceof File?void 0:e.to,w=d(n,{to:C,href:S??void 0,routeHref:!1});return/* @__PURE__ */ D(`div`,{className:x?`attach-preview wui-attach-failed`:`attach-preview`,children:[/* @__PURE__ */ D(`div`,{className:`attach-figure`,children:[/* @__PURE__ */ E(`img`,{src:_??void 0,alt:v}),/* @__PURE__ */ E(`button`,{type:`button`,className:`attach-remove`,"aria-label":p,onClick:u,children:/* @__PURE__ */ E(h,{name:`x`,size:18})})]}),/* @__PURE__ */ D(`div`,{className:`attach-meta`,children:[/* @__PURE__ */ E(`div`,{className:`attach-name`,children:S||C?/* @__PURE__ */ E(f,{link:w,children:v}):v}),y&&/* @__PURE__ */ E(`div`,{className:`attach-size`,children:y})]}),b!==null&&/* @__PURE__ */ E(g,{value:b,size:`sm`,label:l(m,{name:v}),className:`wui-attach-progress`}),x&&/* @__PURE__ */ E(`div`,{className:`wui-attach-error`,children:x})]})}export{O as default};
@@ -1 +1 @@
1
- import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/FieldMessage.js";import n from"../lib/FileItemRow.js";import{FIELD_SIZES as r}from"../lib/fieldState.js";import{keyOf as i}from"../lib/fileItem.js";import a from"../lib/fillLabel.js";import o from"../lib/useFileDrop.js";import{splitMarkerProps as ee}from"../lib/wuiMarker.js";import s from"./AppIcon.js";import te from"./AppInfoTip.js";import ne from"./AppRequiredMark.js";import re from"./AppSpinner.js";import c from"./assertValidValue.js";import ie from"./warnUnknownProps.js";import ae from"./withTooltip.js";import{DEFAULT_MAX_SIZE_MB as oe,acceptDroppedFiles as se,acceptLabel as l,isImageFile as u,isImageOnlyAccept as ce,isPdfFile as le}from"@webority/ui-elements/helpers";import{useEffect as d,useId as ue,useRef as de,useState as f}from"react";import{jsx as p,jsxs as m}from"react/jsx-runtime";var fe=[`dropzone`,`button`],pe={sm:` input-sm`,md:``,lg:` input-lg`},me={md:``,lg:` btn-lg`};function h(e){return e instanceof File?e:{url:e.url,...e.name===void 0?null:{name:e.name}}}function g(g){let{marker:he,props:ge}=ee(`AppFilePicker`,g),{label:_,value:v,name:_e,id:ve,onChange:ye,multiple:y=!1,variant:b=`dropzone`,buttonLabel:be=`Add file`,browseLabel:xe=`Click to upload`,dropLabel:Se=`or drag & drop`,maxSizeText:Ce=`up to {size} MB`,optionalLabel:we=`(optional)`,changeImageLabel:Te=`Change image`,changeFileLabel:Ee=`Change file`,maxFilesText:De=`Up to {count} files.`,removeFileLabel:Oe=`Remove {name}`,maxFiles:x,accept:S=`.jpg,.jpeg,.png`,maxSizeMb:C=oe,required:w,optional:ke=!1,error:Ae,helperText:T,help:E,helpLabel:je=`More information`,loading:D=!1,readOnly:O=!1,size:k,disabled:A=!1,className:j=``,fieldClassName:M=``,style:N,...P}=ge;if(ie(`AppFilePicker`,P),c(`AppFilePicker`,`variant`,b,fe),c(`AppFilePicker`,`size`,k,r),!y&&Array.isArray(v))throw TypeError(`[@webority/ui-react] <AppFilePicker> received a list of files as value without multiple. Pass one file (or null), or set multiple to take a list.`);let F=k===void 0?``:pe[k]??``,I=O?{"aria-readonly":`true`,"data-wui-readonly":``}:null,[Me,L]=f(null),[Ne,R]=f(null),[Pe,z]=f(``),B=de(null),Fe=ue(),V=ve||Fe,H=A||D;d(()=>{if(!y&&v instanceof File&&u(v)){let e=URL.createObjectURL(v);return L(e),()=>URL.revokeObjectURL(e)}L(null)},[v,y]);let U=y||Array.isArray(v)?void 0:v,W=U&&!u(h(U))&&le(h(U))?U instanceof File?U:U.url:null;d(()=>{if(!W){R(null);return}let t=!0,n=null;return import(`@webority/ui-elements/file-viewer`).then(e=>e.renderPdfFirstPage(typeof W==`string`?{url:W}:W)).then(e=>{t&&(n=URL.createObjectURL(e),R(n))}).catch(t=>e(`[AppFilePicker] the PDF preview failed:`,t?.message)),()=>{t=!1,R(null),n&&URL.revokeObjectURL(n)}},[W]);let G=y?Array.isArray(v)?v:v?[v]:[]:[],K=Ae||Pe,q=K?`${V}-error`:void 0,J=T&&!K?`${V}-hint`:void 0,Ie=q||J,Y=ce(S),Le=b===`button`,Re=`btn btn-outline-primary${(k===`md`||k===`lg`?me[k]:void 0)??` btn-sm`}`,ze=!y&&!!v,X=!!U&&(U instanceof File?u(U):Y||u(h(U))),Be=U?.name,Ve=U instanceof File?void 0:U?.url,He=X?Ve||Me:Ne,Z=X?`image`:`file`,Ue=_?`Change ${_}`:`Change ${Z}`,We=_?`Remove ${_}`:`Remove ${Z}`,Ge=_?`${_} preview`:`Selected ${Z} preview`,Ke={accept:S,maxSizeMb:C,multiple:y},qe=e=>{g.multiple||g.onChange(e)},Je=e=>{g.multiple&&g.onChange(e)},Ye=e=>{if(z(``),!y){qe(e[0]??null);return}let t=Array.isArray(v)?v:v?[v]:[],n=new Set(t.map(i)),r=[];for(let t of e)n.has(i(t))||(n.add(i(t)),r.push(t));let o=t.concat(r);x&&o.length>x&&(o=o.slice(0,x),z(a(De,{count:x}))),Je(o)},Xe=e=>z(e.message),{dragOver:Ze,dropProps:Qe}=o({...Ke,disabled:H||O,onFiles:Ye,onReject:Xe}),$e=e=>{if(O)return;let{files:t,rejections:n}=se(e,Ke);t.length&&Ye(t);let[r]=n;r&&Xe(r)},et=e=>$e(e.target.files),tt=e=>{O||(z(``),Je(G.filter((t,n)=>n!==e)))},nt=()=>{O||B.current?.click()},Q=D?/* @__PURE__ */ p(`span`,{className:`wui-file-busy`,children:/* @__PURE__ */ p(re,{size:`sm`})}):null,$=/* @__PURE__ */ p(`input`,{id:V,name:_e,ref:B,type:`file`,"aria-describedby":Ie,accept:S,multiple:y||void 0,disabled:H||void 0,className:`visually-hidden`,onClick:e=>{O?e.preventDefault():e.currentTarget.value=``},onChange:et,...P});return/* @__PURE__ */ m(`div`,{...he,className:`field${M?` ${M}`:``}`,children:[_?/* @__PURE__ */ m(`label`,{className:`label`,htmlFor:V,children:[_,ke&&!w&&/* @__PURE__ */ p(`span`,{className:`label-optional`,children:` ${we}`}),w&&/* @__PURE__ */ p(ne,{}),E&&/* @__PURE__ */ p(te,{label:je,children:E})]}):null,Le?/* @__PURE__ */ m(`div`,{className:`file-input wui-file-input-button-field${F}${K?` error`:``}${j?` ${j}`:``}`,style:N,"aria-busy":D||void 0,...I,children:[/* @__PURE__ */ m(`label`,{htmlFor:V,className:Re,children:[/* @__PURE__ */ p(s,{name:`paperclip`,size:16}),be]}),$,Q]}):ze?/* @__PURE__ */ m(`div`,{className:`file-preview${F}${K?` error`:``}${j?` ${j}`:``}`,style:N,"aria-busy":D||void 0,...I,children:[/* @__PURE__ */ m(`button`,{type:`button`,className:`file-preview-open`,"aria-label":Ue,onClick:nt,disabled:H||O,children:[He?/* @__PURE__ */ p(`img`,{src:He,alt:Ge,className:`file-preview-img`}):/* @__PURE__ */ m(`span`,{className:`file-preview-file`,children:[/* @__PURE__ */ p(s,{name:`file-text`,size:28}),/* @__PURE__ */ p(`span`,{className:`file-preview-file-name`,children:Be})]}),/* @__PURE__ */ p(`span`,{className:`file-preview-overlay`,children:/* @__PURE__ */ m(`span`,{className:`file-preview-cta`,children:[/* @__PURE__ */ p(s,{name:X?`image`:`file-text`,size:16}),` `,X?Te:Ee]})})]}),ae(/* @__PURE__ */ p(`button`,{type:`button`,className:`file-preview-remove`,"aria-label":We,onClick:()=>qe(null),disabled:H||O,children:/* @__PURE__ */ p(s,{name:`x`,size:16})}),We),$,Q]}):/* @__PURE__ */ m(`div`,{className:`file-input file-input-tall${F}${Ze?` dragging`:``}${K?` error`:``}${y&&G.length>0?` has-files`:``}${j?` ${j}`:``}`,style:N,"aria-busy":D||void 0,"aria-disabled":A||void 0,...I,...Qe,children:[/* @__PURE__ */ m(`label`,{htmlFor:V,className:`file-input-zone-label`,children:[/* @__PURE__ */ p(`span`,{className:`file-input-icon`,children:/* @__PURE__ */ p(s,{name:`upload`,size:24})}),/* @__PURE__ */ m(`span`,{className:`file-input-title`,children:[/* @__PURE__ */ p(`span`,{className:`browse`,children:xe}),` ${Se}`]}),/* @__PURE__ */ p(`span`,{className:`file-input-text`,children:C>0?`${l(S)}, ${a(Ce,{size:C})}`:l(S)})]}),$,Q,y&&G.length>0&&/* @__PURE__ */ p(`div`,{className:`attach-list`,children:G.map((e,t)=>/* @__PURE__ */ p(n,{item:e,isImage:e instanceof File?u(e):Y||u(h(e)),noun:`file`,removeFileLabel:Oe,readOnly:O,onRemove:()=>tt(t)},i(e)))})]}),/* @__PURE__ */ p(t,{error:K,hint:T,errorId:q,hintId:J})]})}export{g as default};
1
+ import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/FieldMessage.js";import n from"../lib/FileItemRow.js";import{FIELD_SIZES as r}from"../lib/fieldState.js";import{keyOf as i}from"../lib/fileItem.js";import a from"../lib/fillLabel.js";import{useFieldError as o}from"../lib/formFields.js";import ee from"../lib/useFileDrop.js";import{splitMarkerProps as te}from"../lib/wuiMarker.js";import s from"./AppIcon.js";import ne from"./AppInfoTip.js";import re from"./AppRequiredMark.js";import ie from"./AppSpinner.js";import ae from"./assertValidValue.js";import oe from"./warnUnknownProps.js";import se from"./withTooltip.js";import{DEFAULT_MAX_SIZE_MB as ce,acceptDroppedFiles as le,acceptLabel as c,isImageFile as l,isImageOnlyAccept as ue,isPdfFile as de}from"@webority/ui-elements/helpers";import{useEffect as u,useId as fe,useRef as pe,useState as d}from"react";import{jsx as f,jsxs as p}from"react/jsx-runtime";var me=[`dropzone`,`button`],he={sm:` input-sm`,md:``,lg:` input-lg`},ge={md:``,lg:` btn-lg`};function m(e){return e instanceof File?e:{url:e.url,...e.name===void 0?null:{name:e.name}}}function h(h){let{marker:_e,props:ve}=te(`AppFilePicker`,h),{label:g,value:_,name:v,id:ye,onChange:be,multiple:y=!1,variant:b=`dropzone`,buttonLabel:xe=`Add file`,browseLabel:Se=`Click to upload`,dropLabel:Ce=`or drag & drop`,maxSizeText:we=`up to {size} MB`,optionalLabel:Te=`(optional)`,changeImageLabel:Ee=`Change image`,changeFileLabel:De=`Change file`,maxFilesText:Oe=`Up to {count} files.`,removeFileLabel:ke=`Remove {name}`,maxFiles:x,accept:S=`.jpg,.jpeg,.png`,maxSizeMb:C=ce,required:w,optional:Ae=!1,error:je,helperText:T,help:E,helpLabel:Me=`More information`,loading:D=!1,readOnly:O=!1,size:k,disabled:A=!1,className:j=``,fieldClassName:M=``,style:N,...P}=ve,Ne=o(v),Pe=je??Ne;if(oe(`AppFilePicker`,P),ae(`AppFilePicker`,`variant`,b,me),ae(`AppFilePicker`,`size`,k,r),!y&&Array.isArray(_))throw TypeError(`[@webority/ui-react] <AppFilePicker> received a list of files as value without multiple. Pass one file (or null), or set multiple to take a list.`);let F=k===void 0?``:he[k]??``,I=O?{"aria-readonly":`true`,"data-wui-readonly":``}:null,[Fe,L]=d(null),[Ie,R]=d(null),[Le,z]=d(``),B=pe(null),Re=fe(),V=ye||Re,H=A||D;u(()=>{if(!y&&_ instanceof File&&l(_)){let e=URL.createObjectURL(_);return L(e),()=>URL.revokeObjectURL(e)}L(null)},[_,y]);let U=y||Array.isArray(_)?void 0:_,W=U&&!l(m(U))&&de(m(U))?U instanceof File?U:U.url:null;u(()=>{if(!W){R(null);return}let t=!0,n=null;return import(`@webority/ui-elements/file-viewer`).then(e=>e.renderPdfFirstPage(typeof W==`string`?{url:W}:W)).then(e=>{t&&(n=URL.createObjectURL(e),R(n))}).catch(t=>e(`[AppFilePicker] the PDF preview failed:`,t?.message)),()=>{t=!1,R(null),n&&URL.revokeObjectURL(n)}},[W]);let G=y?Array.isArray(_)?_:_?[_]:[]:[],K=Pe||Le,q=K?`${V}-error`:void 0,J=T&&!K?`${V}-hint`:void 0,ze=q||J,Be=ue(S),Ve=b===`button`,He=`btn btn-outline-primary${(k===`md`||k===`lg`?ge[k]:void 0)??` btn-sm`}`,Ue=!y&&!!_,Y=!!U&&(U instanceof File?l(U):Be||l(m(U))),We=U?.name,Ge=U instanceof File?void 0:U?.url,Ke=Y?Ge||Fe:Ie,X=Y?`image`:`file`,qe=g?`Change ${g}`:`Change ${X}`,Je=g?`Remove ${g}`:`Remove ${X}`,Ye=g?`${g} preview`:`Selected ${X} preview`,Xe={accept:S,maxSizeMb:C,multiple:y},Z=e=>{h.multiple||h.onChange(e)},Ze=e=>{h.multiple&&h.onChange(e)},Qe=e=>{if(z(``),!y){Z(e[0]??null);return}let t=Array.isArray(_)?_:_?[_]:[],n=new Set(t.map(i)),r=[];for(let t of e)n.has(i(t))||(n.add(i(t)),r.push(t));let o=t.concat(r);x&&o.length>x&&(o=o.slice(0,x),z(a(Oe,{count:x}))),Ze(o)},$e=e=>z(e.message),{dragOver:et,dropProps:tt}=ee({...Xe,disabled:H||O,onFiles:Qe,onReject:$e}),nt=e=>{if(O)return;let{files:t,rejections:n}=le(e,Xe);t.length&&Qe(t);let[r]=n;r&&$e(r)},rt=e=>nt(e.target.files),it=e=>{O||(z(``),Ze(G.filter((t,n)=>n!==e)))},at=()=>{O||B.current?.click()},Q=D?/* @__PURE__ */ f(`span`,{className:`wui-file-busy`,children:/* @__PURE__ */ f(ie,{size:`sm`})}):null,$=/* @__PURE__ */ f(`input`,{id:V,name:v,ref:B,type:`file`,"aria-describedby":ze,accept:S,multiple:y||void 0,disabled:H||void 0,className:`visually-hidden`,onClick:e=>{O?e.preventDefault():e.currentTarget.value=``},onChange:rt,...P});return/* @__PURE__ */ p(`div`,{..._e,className:`field${M?` ${M}`:``}`,children:[g?/* @__PURE__ */ p(`label`,{className:`label`,htmlFor:V,children:[g,Ae&&!w&&/* @__PURE__ */ f(`span`,{className:`label-optional`,children:` ${Te}`}),w&&/* @__PURE__ */ f(re,{}),E&&/* @__PURE__ */ f(ne,{label:Me,children:E})]}):null,Ve?/* @__PURE__ */ p(`div`,{className:`file-input wui-file-input-button-field${F}${K?` error`:``}${j?` ${j}`:``}`,style:N,"aria-busy":D||void 0,...I,children:[/* @__PURE__ */ p(`label`,{htmlFor:V,className:He,children:[/* @__PURE__ */ f(s,{name:`paperclip`,size:16}),xe]}),$,Q]}):Ue?/* @__PURE__ */ p(`div`,{className:`file-preview${F}${K?` error`:``}${j?` ${j}`:``}`,style:N,"aria-busy":D||void 0,...I,children:[/* @__PURE__ */ p(`button`,{type:`button`,className:`file-preview-open`,"aria-label":qe,onClick:at,disabled:H||O,children:[Ke?/* @__PURE__ */ f(`img`,{src:Ke,alt:Ye,className:`file-preview-img`}):/* @__PURE__ */ p(`span`,{className:`file-preview-file`,children:[/* @__PURE__ */ f(s,{name:`file-text`,size:28}),/* @__PURE__ */ f(`span`,{className:`file-preview-file-name`,children:We})]}),/* @__PURE__ */ f(`span`,{className:`file-preview-overlay`,children:/* @__PURE__ */ p(`span`,{className:`file-preview-cta`,children:[/* @__PURE__ */ f(s,{name:Y?`image`:`file-text`,size:16}),` `,Y?Ee:De]})})]}),se(/* @__PURE__ */ f(`button`,{type:`button`,className:`file-preview-remove`,"aria-label":Je,onClick:()=>Z(null),disabled:H||O,children:/* @__PURE__ */ f(s,{name:`x`,size:16})}),Je),$,Q]}):/* @__PURE__ */ p(`div`,{className:`file-input file-input-tall${F}${et?` dragging`:``}${K?` error`:``}${y&&G.length>0?` has-files`:``}${j?` ${j}`:``}`,style:N,"aria-busy":D||void 0,"aria-disabled":A||void 0,...I,...tt,children:[/* @__PURE__ */ p(`label`,{htmlFor:V,className:`file-input-zone-label`,children:[/* @__PURE__ */ f(`span`,{className:`file-input-icon`,children:/* @__PURE__ */ f(s,{name:`upload`,size:24})}),/* @__PURE__ */ p(`span`,{className:`file-input-title`,children:[/* @__PURE__ */ f(`span`,{className:`browse`,children:Se}),` ${Ce}`]}),/* @__PURE__ */ f(`span`,{className:`file-input-text`,children:C>0?`${c(S)}, ${a(we,{size:C})}`:c(S)})]}),$,Q,y&&G.length>0&&/* @__PURE__ */ f(`div`,{className:`attach-list`,children:G.map((e,t)=>/* @__PURE__ */ f(n,{item:e,isImage:e instanceof File?l(e):Be||l(m(e)),noun:`file`,removeFileLabel:ke,readOnly:O,onRemove:()=>it(t)},i(e)))})]}),/* @__PURE__ */ f(t,{error:K,hint:T,errorId:q,hintId:J})]})}export{h as default};
@@ -1 +1 @@
1
- import{emptyFacetValue as e,isFacetActive as t}from"../web-core/dist/query/listQuery.js";import{devWarn as n}from"../lib/devWarn.js";import r from"../lib/fillLabel.js";import i from"../lib/useElementEntry.js";import{splitMarkerProps as a}from"../lib/wuiMarker.js";import o from"./AppButton.js";import ee from"./AppChip.js";import s from"./AppDateRangePicker.js";import te from"./AppIcon.js";import c from"./AppSearch.js";import l from"./AppSegmented.js";import u from"./AppSelect.js";import ne from"./AppSwitch.js";import d from"./assertValidValue.js";import re from"./warnUnknownProps.js";import{isImeSafeEnter as ie}from"@webority/ui-elements/helpers";import{Fragment as ae,useEffect as f,useId as oe,useRef as p,useState as se,useSyncExternalStore as ce}from"react";import{Fragment as le,jsx as m,jsxs as h}from"react/jsx-runtime";var g=`(max-width: 575.98px)`,ue=3,_=2,de=e=>{let t=window.matchMedia?.(g);return t?.addEventListener(`change`,e),()=>t?.removeEventListener(`change`,e)},fe=()=>window.matchMedia?.(g).matches??!1,pe=[`enum`,`multiEnum`,`dateRange`,`text`],me=[`sm`,`md`],he=()=>import(`@webority/ui-elements/elements/filter-popover`),v=4,ge=e=>(e.type===`enum`||e.type===`multiEnum`)&&!e.options?.length,y=(e,t)=>e.options?.find(e=>e.value===t)?.label??t,_e=(e,t)=>JSON.stringify(e)===JSON.stringify(t),b=(e,t,n)=>/* @__PURE__ */ RangeError(`[@webority/ui-react] <AppFilterBar> facet "${e.key}" needs ${t}, received ${JSON.stringify(n)}.`),x=(e,t)=>{if(t==null)return``;if(typeof t==`string`)return t;throw b(e,`a string value`,t)},S=(e,t)=>{if(t==null)return[];if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t;throw b(e,`an array of strings`,t)},C=(e,t)=>{if(t==null)return{from:``,to:``};if(typeof t==`object`&&!Array.isArray(t)&&!(t instanceof Date)){let{from:e,to:n}=t;if((e===void 0||typeof e==`string`)&&(n===void 0||typeof n==`string`))return{from:e,to:n}}throw b(e,`a { from, to } date range`,t)};function ve(n,i,a){if(n.required||!t(n,i))return[];if(n.type===`enum`)return[{id:n.key,text:y(n,x(n,i)),clear:()=>e(n)}];if(n.type===`multiEnum`){let e=S(n,i);return e.map(t=>({id:`${n.key}:${t}`,text:y(n,t),clear:()=>e.filter(e=>e!==t)}))}if(n.type===`dateRange`){let t=C(n,i),o=t.from&&t.to?r(a.range,{from:t.from,to:t.to}):t.from?r(a.from,{date:t.from}):r(a.until,{date:t.to});return[{id:n.key,text:o,clear:()=>e(n)}]}return[]}var w=/* @__PURE__ */ new Set;function ye(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!w.has(e)&&(w.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets allLabel, which only an enum facet uses.`))}var T=/* @__PURE__ */ new Set;function be(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!T.has(e)&&(T.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets required, which only an enum facet uses.`))}var E=/* @__PURE__ */ new Set;function xe(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!E.has(e)&&(E.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets allLabel and required; a required facet has no All segment.`))}var D=/* @__PURE__ */ new Set;function Se(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!D.has(e)&&(D.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets presets, which only a dateRange facet uses.`))}function O(n){i(`wui-filter-popover`,he);let{marker:s,props:c}=a(`AppFilterBar`,n),{facets:l,value:u,onChange:g,inline:v=ue,floating:y=!1,apply:b=!1,size:x=`sm`,className:S=``,clearAllLabel:C=`Clear all`,filtersLabel:w=`Filters`,filtersActiveLabel:T=`Filters, {count} active`,keepOpenLabel:E=`Keep open`,appliesAtOnceText:D=`Changes apply at once.`,applyLabel:O=`Apply`,anyLabel:A=`Any`,removeChipLabel:Ce=`Remove {facet} filter {value}`,dateFromText:we=`From {date}`,dateUntilText:Te=`Until {date}`,dateRangeText:Ee=`{from} to {to}`,...j}=c;re(`AppFilterBar`,j),d(`AppFilterBar`,`size`,x,me);let M=x===`md`,De={range:Ee,from:we,until:Te},N=ce(de,fe,()=>!1),P=p(null),F=p(null),Oe=e=>{let t=P.current,n=F.current;t&&n&&(e.preventDefault(),t.open=!t.open,n.classList.remove(`wui-filter-more-panel-end`),t.open&&n.getBoundingClientRect().right>window.innerWidth-8&&n.classList.add(`wui-filter-more-panel-end`))},I=oe(),[L,R]=se({}),z=p(u);for(let e of l)d(`AppFilterBar`,`facets[].type`,e.type,pe);for(let e of l)e.allLabel!=null&&e.type!==`enum`&&ye(e.key),e.required&&e.type!==`enum`&&be(e.key),e.required&&e.allLabel!=null&&xe(e.key),e.presets!=null&&e.type!==`dateRange`&&Se(e.key);let B=l.filter(e=>!ge(e)),V=B.flatMap(e=>ve(e,u[e.key],De).map(t=>({...t,facet:e}))),H=B.filter(e=>!e.required&&t(e,u[e.key])),U=y||N?0:Math.max(0,v),W=B.slice(U),ke=W.filter(e=>H.includes(e)).length,G=!y&&W.length>0;f(()=>{if(!G)return;let e=e=>{let t=P.current;t?.open&&(e.type===`keydown`?e instanceof KeyboardEvent&&e.key===`Escape`:!e.composedPath().includes(t))&&(t.open=!1)};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,e)}},[G]),f(()=>{let e=z.current;z.current=u,R(t=>{let n=Object.entries(t).filter(([t])=>_e(e[t],u[t]));return n.length===Object.keys(t).length?t:Object.fromEntries(n)})},[u]);let K=e=>b&&!y&&(e.type===`text`||e.type===`dateRange`),q=e=>K(e)&&Object.hasOwn(L,e.key)?L[e.key]:u[e.key],J=e=>t=>K(e)?R(n=>({...n,[e.key]:t})):g(e.key,t),Y=()=>{for(let[e,t]of Object.entries(L))g(e,t);R({})},Ae=e=>{ie(e.nativeEvent)&&Y()},je=e=>{e.preventDefault(),Y()},X=(e,t)=>e.type===`text`&&K(e)?/* @__PURE__ */ m(`span`,{onKeyDownCapture:Ae,children:t}):t,Me=e=>/* @__PURE__ */ m(ae,{children:X(e,/* @__PURE__ */ m(k,{facet:e,value:q(e),onChange:J(e),medium:M,anyLabel:A}))},e.key),Z=e=>/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-field`,children:[/* @__PURE__ */ m(`span`,{className:`label`,"aria-hidden":`true`,children:e.label}),X(e,/* @__PURE__ */ m(k,{facet:e,value:q(e),onChange:J(e),floating:!0,medium:M,anyLabel:A}))]},e.key),Q=(e,t)=>t>0&&/* @__PURE__ */ m(`span`,{className:e,children:` (${t})`}),Ne=e=>/* @__PURE__ */ m(ee,{size:`sm`,label:`${e.facet.label}: ${e.text}`,removeLabel:r(Ce,{facet:e.facet.label,value:e.text}),onRemove:()=>g(e.facet.key,e.clear()),className:!y&&B.indexOf(e.facet)<U?`wui-filter-chip-inline`:void 0},e.id),Pe=/* @__PURE__ */ m(o,{variant:`ghost`,size:M?void 0:`sm`,onClick:()=>{for(let t of H)g(t.key,e(t));R({})},children:C});if(y){let e=V.slice(_),t=H.length;return/* @__PURE__ */ h(`div`,{className:`wui-filter-bar d-flex flex-wrap align-items-center gap-2${S?` ${S}`:``}`,...s,...j,children:[/* @__PURE__ */ h(`wui-filter-popover`,{class:`wui-filter-popover`,children:[/* @__PURE__ */ h(o,{variant:t>0?`outline`:`ghost`,size:M?void 0:`sm`,leftIcon:`filter`,className:`wui-filter-popover-trigger`,"aria-expanded":`false`,"aria-controls":I,"aria-label":t>0?r(T,{count:t}):void 0,children:[w,t>0&&/* @__PURE__ */ m(`span`,{className:`badge rounded-pill text-bg-primary ms-1`,children:t})]}),/* @__PURE__ */ h(`div`,{id:I,className:`wui-filter-popover-panel`,popover:`auto`,role:`dialog`,"aria-label":w,children:[/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-head`,children:[/* @__PURE__ */ m(`span`,{className:`wui-filter-popover-title`,children:w}),/* @__PURE__ */ m(ne,{label:E,id:`${I}-pin`})]}),/* @__PURE__ */ m(`div`,{className:`wui-filter-popover-grid`,children:B.map(Z)}),/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-foot`,children:[/* @__PURE__ */ m(`span`,{className:`wui-filter-popover-note`,children:D}),t>0&&Pe]})]})]}),V.slice(0,_).map(Ne),e.length>0&&/* @__PURE__ */ h(`span`,{className:`chip chip-sm wui-filter-popover-more`,title:e.map(e=>`${e.facet.label}: ${e.text}`).join(`, `),children:[`+`,e.length]})]})}let Fe=`wui-filter-bar d-flex flex-wrap align-items-center gap-2${N&&G?` wui-filter-bar--folded`:``}`,Ie=e=>`${e}${S?` ${S}`:``}`,$=/* @__PURE__ */ h(le,{children:[B.slice(0,U).map(Me),G&&/* @__PURE__ */ h(`details`,{ref:P,className:`wui-filter-more`,children:[/* @__PURE__ */ h(`summary`,{className:`btn btn-outline-primary${M?``:` btn-sm`} wui-filter-more-trigger`,onClick:Oe,children:[/* @__PURE__ */ m(te,{name:`filter`,size:14,className:`me-2`}),w,Q(`wui-filter-count-desktop`,ke),Q(`wui-filter-count-phone`,H.length)]}),/* @__PURE__ */ h(`div`,{ref:F,className:`wui-filter-more-panel`,children:[/* @__PURE__ */ m(`div`,{className:`wui-filter-more-head`,children:w}),W.map(Z)]})]}),V.map(Ne),H.length>0&&Pe]});return!b||!B.some(e=>e.type===`text`||e.type===`dateRange`)?/* @__PURE__ */ m(`div`,{className:Ie(Fe),...s,...j,children:$}):/* @__PURE__ */ h(`div`,{className:Ie(`wui-filter-form d-flex flex-wrap align-items-center gap-2`),...s,...j,children:[/* @__PURE__ */ m(`div`,{className:Fe,children:$}),/* @__PURE__ */ m(o,{type:`submit`,size:M?void 0:`sm`,onClick:je,children:O})]})}function k({facet:e,value:t,onChange:n,floating:r=!1,medium:i=!1,anyLabel:a}){if(e.type===`enum`){let o=e.options??[];return(e.required?o.length<=v:o.length<v)?/* @__PURE__ */ m(l,{label:e.label,name:e.key,size:i?`md`:`sm`,value:x(e,t),onChange:n,options:e.required?o:[{value:``,label:e.allLabel||`All`},...o]}):/* @__PURE__ */ m(u,{"aria-label":e.label,name:e.key,placeholder:r?a:e.label,clearable:!e.required,size:i?void 0:`sm`,value:x(e,t),onChange:n,options:o})}return e.type===`multiEnum`?/* @__PURE__ */ m(u,{mode:`multiple`,"aria-label":e.label,name:e.key,placeholder:r?a:e.label,size:i?void 0:`sm`,collapseChips:!0,value:S(e,t),onChange:n,options:e.options??[]}):e.type===`dateRange`?/* @__PURE__ */ m(s,{ariaLabel:e.label,startName:`${e.key}From`,endName:`${e.key}To`,placeholder:r?a:e.label,size:i?void 0:`sm`,presets:e.presets,start:C(e,t).from,end:C(e,t).to,onChange:e=>n({from:e.start??``,to:e.end??``})}):/* @__PURE__ */ m(c,{ariaLabel:e.label,name:e.key,placeholder:e.label,size:i?void 0:`sm`,value:x(e,t),onChange:n})}export{O as default};
1
+ import{emptyFacetValue as e,isFacetActive as t}from"../web-core/dist/query/listQuery.js";import{devWarn as n}from"../lib/devWarn.js";import r from"../lib/fillLabel.js";import i from"../lib/useElementEntry.js";import{splitMarkerProps as a}from"../lib/wuiMarker.js";import o from"./AppButton.js";import ee from"./AppChip.js";import s from"./AppDateRangePicker.js";import te from"./AppIcon.js";import c from"./AppSearch.js";import l from"./AppSegmented.js";import u from"./AppSelect.js";import ne from"./AppSwitch.js";import d from"./assertValidValue.js";import re from"./warnUnknownProps.js";import{isImeSafeEnter as ie}from"@webority/ui-elements/helpers";import{Fragment as ae,useEffect as f,useId as oe,useRef as p,useState as se,useSyncExternalStore as ce}from"react";import{Fragment as le,jsx as m,jsxs as h}from"react/jsx-runtime";var g=`(max-width: 575.98px)`,ue=3,_=2,de=e=>{let t=window.matchMedia?.(g);return t?.addEventListener(`change`,e),()=>t?.removeEventListener(`change`,e)},fe=()=>window.matchMedia?.(g).matches??!1,pe=[`enum`,`multiEnum`,`dateRange`,`text`],me=[`sm`,`md`],he=()=>import(`@webority/ui-elements/elements/filter-popover`),v=4,ge=e=>(e.type===`enum`||e.type===`multiEnum`)&&!e.options?.length,y=(e,t)=>e.options?.find(e=>e.value===t)?.label??t,_e=(e,t)=>JSON.stringify(e)===JSON.stringify(t),b=(e,t,n)=>/* @__PURE__ */ RangeError(`[@webority/ui-react] <AppFilterBar> facet "${e.key}" needs ${t}, received ${JSON.stringify(n)}.`),x=(e,t)=>{if(t==null)return``;if(typeof t==`string`)return t;throw b(e,`a string value`,t)},S=(e,t)=>{if(t==null)return[];if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t;throw b(e,`an array of strings`,t)},C=(e,t)=>{if(t==null)return{from:``,to:``};if(typeof t==`object`&&!Array.isArray(t)&&!(t instanceof Date)){let{from:e,to:n}=t;if((e===void 0||typeof e==`string`)&&(n===void 0||typeof n==`string`))return{from:e,to:n}}throw b(e,`a { from, to } date range`,t)};function ve(n,i,a){if(n.required||!t(n,i))return[];if(n.type===`enum`)return[{id:n.key,text:y(n,x(n,i)),clear:()=>e(n)}];if(n.type===`multiEnum`){let e=S(n,i);return e.map(t=>({id:`${n.key}:${t}`,text:y(n,t),clear:()=>e.filter(e=>e!==t)}))}if(n.type===`dateRange`){let t=C(n,i),o=t.from&&t.to?r(a.range,{from:t.from,to:t.to}):t.from?r(a.from,{date:t.from}):r(a.until,{date:t.to});return[{id:n.key,text:o,clear:()=>e(n)}]}return[]}var w=/* @__PURE__ */ new Set;function ye(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!w.has(e)&&(w.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets allLabel, which only an enum facet uses.`))}var T=/* @__PURE__ */ new Set;function be(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!T.has(e)&&(T.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets required, which only an enum facet uses.`))}var E=/* @__PURE__ */ new Set;function xe(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!E.has(e)&&(E.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets allLabel and required; a required facet has no All segment.`))}var D=/* @__PURE__ */ new Set;function Se(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!D.has(e)&&(D.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets presets, which only a dateRange facet uses.`))}var O=/* @__PURE__ */ new Set;function Ce(e){let t=!0;try{t=process.env.NODE_ENV!==`production`}catch{t=!0}t&&!O.has(e)&&(O.add(e),n(`[@webority/ui-react] <AppFilterBar> facet "${e}" sets count or icon on an option, which only an enum facet drawn as segments shows.`))}var we=e=>{let t=e.options?.length??0;return e.type===`enum`&&(e.required?t<=v:t<v)};function k(n){i(`wui-filter-popover`,he);let{marker:s,props:c}=a(`AppFilterBar`,n),{facets:l,value:u,onChange:g,onChangeMany:v,inline:y=ue,facetLabels:b=!1,floating:x=!1,apply:S=!1,size:C=`sm`,className:w=``,clearAllLabel:T=`Clear all`,filtersLabel:E=`Filters`,filtersActiveLabel:D=`Filters, {count} active`,keepOpenLabel:O=`Keep open`,appliesAtOnceText:k=`Changes apply at once.`,applyLabel:Te=`Apply`,anyLabel:j=`Any`,removeChipLabel:Ee=`Remove {facet} filter {value}`,dateFromText:De=`From {date}`,dateUntilText:Oe=`Until {date}`,dateRangeText:ke=`{from} to {to}`,...M}=c;re(`AppFilterBar`,M),d(`AppFilterBar`,`size`,C,me);let N=C===`md`,Ae={range:ke,from:De,until:Oe},P=ce(de,fe,()=>!1),F=p(null),I=p(null),je=e=>{let t=F.current,n=I.current;t&&n&&(e.preventDefault(),t.open=!t.open,n.classList.remove(`wui-filter-more-panel-end`),t.open&&n.getBoundingClientRect().right>window.innerWidth-8&&n.classList.add(`wui-filter-more-panel-end`))},L=oe(),[R,z]=se({}),B=p(u);for(let e of l)d(`AppFilterBar`,`facets[].type`,e.type,pe);for(let e of l)e.allLabel!=null&&e.type!==`enum`&&ye(e.key),e.required&&e.type!==`enum`&&be(e.key),e.required&&e.allLabel!=null&&xe(e.key),e.presets!=null&&e.type!==`dateRange`&&Se(e.key),e.options?.some(e=>e.count!=null||e.icon!=null)&&!we(e)&&Ce(e.key);let V=l.filter(e=>!ge(e)),H=V.flatMap(e=>ve(e,u[e.key],Ae).map(t=>({...t,facet:e}))),U=V.filter(e=>!e.required&&t(e,u[e.key])),W=x||P?0:Math.max(0,y),G=V.slice(W),Me=G.filter(e=>U.includes(e)).length,K=!x&&G.length>0;f(()=>{if(!K)return;let e=e=>{let t=F.current;t?.open&&(e.type===`keydown`?e instanceof KeyboardEvent&&e.key===`Escape`:!e.composedPath().includes(t))&&(t.open=!1)};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,e)}},[K]),f(()=>{let e=B.current;B.current=u,z(t=>{let n=Object.entries(t).filter(([t])=>_e(e[t],u[t]));return n.length===Object.keys(t).length?t:Object.fromEntries(n)})},[u]);let q=e=>S&&!x&&(e.type===`text`||e.type===`dateRange`),J=e=>q(e)&&Object.hasOwn(R,e.key)?R[e.key]:u[e.key],Y=e=>t=>q(e)?z(n=>({...n,[e.key]:t})):g(e.key,t),X=e=>{let t=Object.entries(e);if(t.length!==0){if(v)v(e);else for(let[e,n]of t)g(e,n)}},Z=()=>{X(R),z({})},Ne=e=>{ie(e.nativeEvent)&&Z()},Pe=e=>{e.preventDefault(),Z()},Q=(e,t)=>e.type===`text`&&q(e)?/* @__PURE__ */ m(`span`,{onKeyDownCapture:Ne,children:t}):t,Fe=(e,t)=>b?/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-field wui-filter-facet`,children:[/* @__PURE__ */ m(`span`,{className:`label`,"aria-hidden":`true`,children:e.label}),t]},e.key):t,Ie=e=>Fe(e,/* @__PURE__ */ m(ae,{children:Q(e,/* @__PURE__ */ m(A,{facet:e,value:J(e),onChange:Y(e),medium:N,anyLabel:j}))},e.key)),$=e=>/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-field`,children:[/* @__PURE__ */ m(`span`,{className:`label`,"aria-hidden":`true`,children:e.label}),Q(e,/* @__PURE__ */ m(A,{facet:e,value:J(e),onChange:Y(e),floating:!0,medium:N,anyLabel:j}))]},e.key),Le=(e,t)=>t>0&&/* @__PURE__ */ m(`span`,{className:e,children:` (${t})`}),Re=e=>/* @__PURE__ */ m(ee,{size:`sm`,label:`${e.facet.label}: ${e.text}`,removeLabel:r(Ee,{facet:e.facet.label,value:e.text}),onRemove:()=>g(e.facet.key,e.clear()),className:!x&&V.indexOf(e.facet)<W?`wui-filter-chip-inline`:void 0},e.id),ze=/* @__PURE__ */ m(o,{variant:`ghost`,size:N?void 0:`sm`,onClick:()=>{X(Object.fromEntries(U.map(t=>[t.key,e(t)]))),z({})},children:T});if(x){let e=H.slice(_),t=U.length;return/* @__PURE__ */ h(`div`,{className:`wui-filter-bar d-flex flex-wrap align-items-center gap-2${w?` ${w}`:``}`,...s,...M,children:[/* @__PURE__ */ h(`wui-filter-popover`,{class:`wui-filter-popover`,children:[/* @__PURE__ */ h(o,{variant:t>0?`outline`:`ghost`,size:N?void 0:`sm`,leftIcon:`filter`,className:`wui-filter-popover-trigger`,"aria-expanded":`false`,"aria-controls":L,"aria-label":t>0?r(D,{count:t}):void 0,children:[E,t>0&&/* @__PURE__ */ m(`span`,{className:`badge rounded-pill text-bg-primary ms-1`,children:t})]}),/* @__PURE__ */ h(`div`,{id:L,className:`wui-filter-popover-panel`,popover:`auto`,role:`dialog`,"aria-label":E,children:[/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-head`,children:[/* @__PURE__ */ m(`span`,{className:`wui-filter-popover-title`,children:E}),/* @__PURE__ */ m(ne,{label:O,id:`${L}-pin`})]}),/* @__PURE__ */ m(`div`,{className:`wui-filter-popover-grid`,children:V.map($)}),/* @__PURE__ */ h(`div`,{className:`wui-filter-popover-foot`,children:[/* @__PURE__ */ m(`span`,{className:`wui-filter-popover-note`,children:k}),t>0&&ze]})]})]}),H.slice(0,_).map(Re),e.length>0&&/* @__PURE__ */ h(`span`,{className:`chip chip-sm wui-filter-popover-more`,title:e.map(e=>`${e.facet.label}: ${e.text}`).join(`, `),children:[`+`,e.length]})]})}let Be=`wui-filter-bar d-flex flex-wrap align-items-center gap-2${P&&K?` wui-filter-bar--folded`:``}`,Ve=e=>`${e}${w?` ${w}`:``}`,He=/* @__PURE__ */ h(le,{children:[V.slice(0,W).map(Ie),K&&/* @__PURE__ */ h(`details`,{ref:F,className:`wui-filter-more`,children:[/* @__PURE__ */ h(`summary`,{className:`btn btn-outline-primary${N?``:` btn-sm`} wui-filter-more-trigger`,onClick:je,children:[/* @__PURE__ */ m(te,{name:`filter`,size:14,className:`me-2`}),E,Le(`wui-filter-count-desktop`,Me),Le(`wui-filter-count-phone`,U.length)]}),/* @__PURE__ */ h(`div`,{ref:I,className:`wui-filter-more-panel`,children:[/* @__PURE__ */ m(`div`,{className:`wui-filter-more-head`,children:E}),G.map($)]})]}),H.map(Re),U.length>0&&ze]});return!S||!V.some(e=>e.type===`text`||e.type===`dateRange`)?/* @__PURE__ */ m(`div`,{className:Ve(Be),...s,...M,children:He}):/* @__PURE__ */ h(`div`,{className:Ve(`wui-filter-form d-flex flex-wrap align-items-center gap-2`),...s,...M,children:[/* @__PURE__ */ m(`div`,{className:Be,children:He}),/* @__PURE__ */ m(o,{type:`submit`,size:N?void 0:`sm`,onClick:Pe,children:Te})]})}function A({facet:e,value:t,onChange:n,floating:r=!1,medium:i=!1,anyLabel:a}){if(e.type===`enum`){let o=e.options??[];return(e.required?o.length<=v:o.length<v)?/* @__PURE__ */ m(l,{label:e.label,name:e.key,size:i?`md`:`sm`,value:x(e,t),onChange:n,options:e.required?o:[{value:``,label:e.allLabel||`All`},...o]}):/* @__PURE__ */ m(u,{"aria-label":e.label,name:e.key,placeholder:r?a:e.label,clearable:!e.required,size:i?void 0:`sm`,value:x(e,t),onChange:n,options:o})}return e.type===`multiEnum`?/* @__PURE__ */ m(u,{mode:`multiple`,"aria-label":e.label,name:e.key,placeholder:r?a:e.label,size:i?void 0:`sm`,collapseChips:!0,value:S(e,t),onChange:n,options:e.options??[]}):e.type===`dateRange`?/* @__PURE__ */ m(s,{ariaLabel:e.label,startName:`${e.key}From`,endName:`${e.key}To`,placeholder:r?a:e.label,size:i?void 0:`sm`,presets:e.presets,start:C(e,t).from,end:C(e,t).to,onChange:e=>n({from:e.start??``,to:e.end??``})}):/* @__PURE__ */ m(c,{ariaLabel:e.label,name:e.key,placeholder:e.label,size:i?void 0:`sm`,value:x(e,t),onChange:n})}export{k as default};
@@ -1 +1 @@
1
- import{newIdempotencyKey as e}from"../web-core/dist/api/idempotencyKey.js";import{splitMarkerProps as t}from"../lib/wuiMarker.js";import n from"./warnUnknownProps.js";import{createContext as r,useCallback as i,useContext as a,useMemo as o,useRef as s,useState as c}from"react";import{jsx as l}from"react/jsx-runtime";var u=r(null);function d(){let e=a(u);if(e===null)throw Error(`useFormSubmit must be called inside an AppForm`);return e}function f(r){let{marker:a,props:d}=t(`AppForm`,r),{onSubmit:f,className:p,children:m,noValidate:h,action:g,method:_,encType:v,acceptCharset:y,...b}=d;n(`AppForm`,b);let[x,S]=c(!1),[C,w]=c(e),T=s(!1),E=i(async t=>{if(t.preventDefault(),!T.current){T.current=!0,S(!0);try{await f(t,{idempotencyKey:C})&&w(e())}finally{T.current=!1,S(!1)}}},[f,C]),D=o(()=>({submitting:x,idempotencyKey:C}),[x,C]);return/* @__PURE__ */ l(u.Provider,{value:D,children:/* @__PURE__ */ l(`form`,{...a,...b,noValidate:h,action:g,method:_,encType:v,acceptCharset:y,className:p,onSubmit:E,"aria-busy":x||void 0,children:m})})}export{u as FormSubmitContext,f as default,d as useFormSubmit};
1
+ import{newIdempotencyKey as e}from"../web-core/dist/api/idempotencyKey.js";import t from"../lib/focusField.js";import{FormFieldsContext as n,toFieldName as r}from"../lib/formFields.js";import{UNSAVED_TEXT as i}from"../lib/unsavedText.js";import{splitMarkerProps as a}from"../lib/wuiMarker.js";import o from"./AppConfirmDialog.js";import s from"./AppIcon.js";import c from"./warnUnknownProps.js";import{createContext as l,useCallback as u,useContext as d,useEffect as f,useMemo as p,useRef as m,useState as h}from"react";import{jsx as g,jsxs as _}from"react/jsx-runtime";var v=l(null);function y(){let e=d(v);if(e===null)throw Error(`useFormSubmit must be called inside an AppForm`);return e}var b=/* @__PURE__ */ new Set,x=/* @__PURE__ */ new Map;function S(l){let{marker:d,props:y}=a(`AppForm`,l),{onSubmit:S,onChange:C,className:w,children:T,noValidate:E,action:D,method:O,encType:k,acceptCharset:A,fieldErrors:j,formErrors:M,unsavedChanges:N,unsavedChangesMessage:ee,...P}=y;c(`AppForm`,P);let[F,I]=h(!1),[L,R]=h(e),z=m(!1),[B,V]=h(null),H=p(()=>new Map(Object.entries(j??{}).map(([e,t])=>[r(e),t])),[j]),U=JSON.stringify([...H].sort(([e],[t])=>e<t?-1:+(e>t))),[W,G]=h({key:U,names:b}),K=W.key===U?W.names:b,q=u(e=>{C?.(e);let t=e.target;if(!(t instanceof HTMLElement)||!(`name`in t)||typeof t.name!=`string`||t.name===``)return;let n=r(t.name);H.has(n)&&G(e=>{let t=e.key===U?e.names:b;return t.has(n)?e:{key:U,names:/* @__PURE__ */ new Set([...t,n])}})},[C,H,U]),[J,Y]=h(x),X=u(e=>(Y(t=>new Map(t).set(e,(t.get(e)??0)+1)),()=>{Y(t=>{let n=new Map(t),r=(t.get(e)??0)-1;return r>0?n.set(e,r):n.delete(e),n})}),[]),Z=u(e=>K.has(e)?void 0:H.get(e),[K,H]),Q=p(()=>({errorOf:Z,claim:X}),[Z,X]),$=[.../* @__PURE__ */ new Set([...M??[],...[...H].filter(([e])=>!J.has(e)).map(([,e])=>e)])],te=u(async t=>{if(t.preventDefault(),z.current)return;z.current=!0,I(!0);let n=t.currentTarget;try{await S(t,{idempotencyKey:L})?R(e()):V({form:n})}finally{z.current=!1,I(!1)}},[S,L]);f(()=>{if(B===null)return;let{form:e}=B;if(V(null),e.querySelector(`.wui-error-summary`)!==null)return;let n=[...e.querySelectorAll(`[name]`)].map(e=>e.getAttribute(`name`)).find(e=>e!==null&&H.has(r(e)));n!==void 0&&t(n)},[B,H]);let ne=p(()=>({submitting:F,idempotencyKey:L}),[F,L]);return/* @__PURE__ */ g(n.Provider,{value:Q,children:/* @__PURE__ */ _(v.Provider,{value:ne,children:[/* @__PURE__ */ _(`form`,{...d,...P,noValidate:E,action:D,method:O,encType:k,acceptCharset:A,className:w,onChange:q,onSubmit:te,"aria-busy":F||void 0,children:[$.length>0?/* @__PURE__ */ _(`div`,{role:`alert`,className:`alert alert-danger alert-has-icon`,"data-wui-form-errors":``,children:[/* @__PURE__ */ g(`span`,{className:`alert-icon`,children:/* @__PURE__ */ g(s,{name:`x`,size:11})}),/* @__PURE__ */ g(`div`,{className:`alert-content`,children:$.length===1?$[0]:$.map(e=>/* @__PURE__ */ g(`div`,{children:e},e))})]}):null,T]}),N?.blocked?/* @__PURE__ */ g(o,{open:!0,title:i.title,description:ee??i.message,confirmLabel:i.leaveLabel,onConfirm:N.discard,onClose:N.keep}):null]})})}export{v as FormSubmitContext,S as default,y as useFormSubmit};
@@ -0,0 +1 @@
1
+ import{splitMarkerProps as e}from"../lib/wuiMarker.js";import t from"./assertValidValue.js";import n from"./warnUnknownProps.js";import{jsx as r,jsxs as i}from"react/jsx-runtime";var a=[`plus`,`minus`,`times`,`divide`,`equal`],o={plus:`+`,minus:`−`,times:`×`,divide:`÷`,equal:`=`};function s(s){let{marker:c,props:l}=e(`AppFormulaSteps`,s),{steps:u=[],label:d=`Calculation`,plusLabel:f=`plus`,minusLabel:p=`minus`,timesLabel:m=`times`,divideLabel:h=`divided by`,equalLabel:g=`equals`,className:_=``,...v}=l;n(`AppFormulaSteps`,v);for(let e of u)t(`AppFormulaSteps`,`steps[].sign`,e.sign,a);let y={plus:f,minus:p,times:m,divide:h,equal:g},b=[`wui-formula-steps`,_].filter(Boolean).join(` `);return/* @__PURE__ */ r(`ol`,{className:b,"aria-label":d,...c,...v,children:u.map((e,t)=>/* @__PURE__ */ i(`li`,{className:e.sign===`equal`?`wui-formula-step wui-formula-step-total`:`wui-formula-step`,children:[/* @__PURE__ */ r(`span`,{className:`wui-formula-sign`,"aria-hidden":`true`,children:e.sign?o[e.sign]:null}),e.sign?/* @__PURE__ */ r(`span`,{className:`visually-hidden`,children:`${y[e.sign]} `}):null,/* @__PURE__ */ r(`span`,{className:`wui-formula-label`,children:e.label}),e.working?/* @__PURE__ */ r(`span`,{className:`wui-formula-working`,children:e.working}):null,/* @__PURE__ */ r(`span`,{className:`wui-formula-result`,children:e.result}),e.note?/* @__PURE__ */ r(`span`,{className:`wui-formula-note`,children:e.note}):null]},e.key??`${e.label}-${t}`))})}export{s as default};
@@ -1 +1 @@
1
- import e from"../lib/FieldMessage.js";import t from"../lib/fillLabel.js";import n from"../lib/useElementEntry.js";import ee from"../lib/useFileDrop.js";import{splitMarkerProps as te}from"../lib/wuiMarker.js";import ne from"./AppAlert.js";import r from"./AppButton.js";import i from"./AppIcon.js";import re from"./AppModal.js";import ie from"./AppRequiredMark.js";import a from"./assertValidValue.js";import ae from"./warnUnknownProps.js";import oe from"./withTooltip.js";import{AVATAR_ACCEPT as se,AVATAR_MAX_SIZE_MB as o,AVATAR_OUTPUT_SIZE as ce,AVATAR_OUTPUT_TYPE as s,AVATAR_PREVIEW_SIZES as c,AVATAR_TEXT as l,DEFAULT_IMAGE_ACCEPT as u,DEFAULT_MAX_SIZE_MB as d,avatarUnreadableMessage as f,validateFile as le}from"@webority/ui-elements/helpers";import{useCallback as ue,useEffect as de,useId as fe,useRef as pe,useState as p}from"react";import{Fragment as me,jsx as m,jsxs as h}from"react/jsx-runtime";var he=[`logo`,`avatar`],ge=[`overlay`,`buttons`],_e=[`stacked`,`inline`,`profile`],ve=[`initials`,`avatar`],ye=[`circle`,`rounded`,`square`],be=[`keep`,`image/webp`],xe=c.join(` `),Se=()=>import(`@webority/ui-elements/elements/image-crop`),Ce={logo:{controls:`overlay`,accept:u,maxSizeMb:d,crop:void 0,rotatable:!1,previews:!1,camera:!1,outputSize:void 0,outputType:`keep`,variant:`initials`,sizes:{sm:72,md:120,lg:160}},avatar:{controls:`buttons`,accept:se,maxSizeMb:o,crop:1,rotatable:!0,previews:!0,camera:!0,outputSize:ce,outputType:s,variant:`avatar`,sizes:{sm:64,md:96,lg:128}}},g=`That image could not be cropped. Choose another one.`,we=`That image could not be opened. Choose another one.`,Te={dialogSize:`lg`,dialogTitle:`Crop photo`,dialogSubtitle:`Drag the frame and zoom to choose what to keep.`,save:`Apply`,cancel:`Cancel`,cropFailed:g,unreadable:()=>we},Ee={dialogSize:void 0,dialogTitle:l.dialogTitle,dialogSubtitle:l.dialogSubtitle,save:l.save,cancel:l.cancel,cropFailed:l.cropFailed,unreadable:f};function _(se){n(`wui-image-crop`,Se);let{marker:o,props:ce}=te(`AppImagePicker`,se),{kind:s=`logo`,controls:c,value:u,fallback:d,variant:f,name:g,onChange:we,onRemove:_,removeName:v,loading:y=!1,disabled:De=!1,accept:Oe,maxSizeMb:ke,shape:b=`circle`,size:x=`md`,crop:Ae,rotatable:je,previews:Me,camera:Ne,outputSize:Pe,outputType:Fe,layout:S=`stacked`,title:Ie,subtitle:Le,overlayIcon:Re=`image`,overlayLabel:ze=`Update photo`,removeLabel:C=`Remove photo`,ariaLabel:Be,label:Ve,helperText:w,error:He,required:Ue=!1,optional:We=!1,optionalLabel:Ge=`(optional)`,dialogTitle:Ke,dialogSubtitle:qe,save:Je,cancel:Ye,cropFailed:Xe,unreadable:Ze,uploadLabel:Qe,changeLabel:$e,cameraLabel:et,className:T=``,fieldClassName:E=``,style:D,...O}=ce;ae(`AppImagePicker`,O),a(`AppImagePicker`,`kind`,s,he),a(`AppImagePicker`,`controls`,c,ge),a(`AppImagePicker`,`variant`,f,ve),a(`AppImagePicker`,`layout`,S,_e),a(`AppImagePicker`,`shape`,b,ye),a(`AppImagePicker`,`outputType`,Fe,be);let k=Ce[s]??Ce.logo,tt=Object.fromEntries(Object.entries({dialogTitle:Ke,dialogSubtitle:qe,save:Je,cancel:Ye,cropFailed:Xe,unreadable:Ze===void 0?void 0:e=>t(Ze,{name:e?.name??``})}).filter(([,e])=>e!==void 0)),A={...s===`avatar`?Ee:Te,...tt},j=k.sizes;a(`AppImagePicker`,`size`,typeof x==`string`?x:null,Object.keys(j));let nt=(c??k.controls)===`overlay`,rt=f??k.variant,M=Oe??k.accept,N=ke??k.maxSizeMb,P=Pe??k.outputSize,it=Fe??k.outputType,at=je??k.rotatable,ot=Me??k.previews,st=Ne??k.camera,F=Ae??k.crop,I=F===`free`?null:typeof F==`number`&&Number.isFinite(F)&&F>0?F:void 0;F!=null&&I===void 0&&a(`AppImagePicker`,`crop`,String(F),[`free`,`a positive number`]);let L=I!==void 0&&P===void 0,R=pe(null),ct=pe(null),z=pe(null),B=fe(),[V,lt]=p(null),[ut,dt]=p(!1),[ft,H]=p(!1),[pt,U]=p(``),[W,mt]=p(null),[G,ht]=p(!1),[gt,_t]=p(`loading`),[vt,yt]=p(``),bt=ue(e=>{if(z.current=e,!e)return;let t=()=>{_t(`ready`),e.querySelector(`.wui-crop-stage`)?.focus()},n=()=>_t(`error`);return e.addEventListener(`load`,t),e.addEventListener(`error`,n),()=>{e.removeEventListener(`load`,t),e.removeEventListener(`error`,n),z.current=null}},[]);de(()=>()=>{W&&URL.revokeObjectURL(W.url)},[W]),de(()=>()=>{V&&URL.revokeObjectURL(V)},[V]);let[xt,St]=p(u);u!==xt&&(St(u),lt(null),dt(!1),H(!1));let K=y||De,q=ut?null:V||(u&&!ft?u:null),Ct=!!q,J=He||pt,Y=w&&!J?`${B}-hint`:void 0,X=J?`${B}-error`:void 0,wt=X||Y,Tt=!K&&Ct&&(!!V||!!_||!!v),Et=Ct?$e??l.change:Qe??l.choose,Dt=typeof x==`number`?x:j[x]??j.md,Ot=()=>{K||R.current?.click()},kt=()=>{K||ct.current?.click()},At=e=>{if(g&&R.current&&typeof DataTransfer==`function`){let t=new DataTransfer;t.items.add(e),R.current.files=t.files}dt(!1),H(!1),lt(URL.createObjectURL(e)),we?.(e)},jt=e=>{let t=I!==void 0&&e.type!==`image/svg+xml`,n=le(e,{accept:M,maxSizeMb:t&&L?0:N});n?U(n):(U(``),t?(_t(`loading`),yt(``),mt({file:e,url:URL.createObjectURL(e)})):At(e))},{dragOver:Mt,dropProps:Nt}=ee({accept:M,maxSizeMb:L?0:N,disabled:K,onFiles:e=>{let t=e[0];if(!t)throw Error(`<AppImagePicker> received a drop with no file.`);jt(t)},onReject:({message:e})=>U(e)}),Pt=e=>{let t=it===`keep`?e.type:it;return P===void 0?{name:e.name,type:t,maxBytes:N>0?N*1024*1024:0}:{name:e.name||`photo`,type:t,size:P}},Ft=async()=>{if(!W)return;let{file:e}=W;ht(!0),yt(``);let t=null;try{t=await z.current?.toFile(Pt(e))}catch{t=null}if(ht(!1),!t)yt(A.cropFailed);else if(mt(null),L){let e=le(t,{accept:M,maxSizeMb:N});e?U(e):At(t)}else At(t)},It=()=>{G||mt(null)},Lt=e=>{let t=e.target.files?.[0];e.target.value=``,t&&jt(t)},Rt=()=>{lt(null),dt(!0),U(``),R.current&&(R.current.value=``),_?.()},Z=I!==void 0&&/* @__PURE__ */ h(re,{open:!!W,title:A.dialogTitle,subtitle:A.dialogSubtitle,size:A.dialogSize,staticBackdrop:!0,dismissible:!G,closeOnEscape:!G,onClose:It,footer:/* @__PURE__ */ h(me,{children:[/* @__PURE__ */ m(r,{type:`button`,variant:`soft`,disabled:G,onClick:It,children:A.cancel}),/* @__PURE__ */ m(r,{type:`button`,loading:G,disabled:gt!==`ready`,onClick:Ft,children:A.save})]}),children:[gt===`error`&&W&&/* @__PURE__ */ m(ne,{tone:`danger`,children:A.unreadable(W.file)}),vt&&/* @__PURE__ */ m(ne,{tone:`danger`,children:vt}),W&&gt!==`error`&&/* @__PURE__ */ m(`wui-image-crop`,{ref:bt,src:W.url,aspect:I??`free`,round:I===1&&b===`circle`,rotatable:at,previews:ot?xe:void 0})]}),zt=v&&/* @__PURE__ */ m(`input`,{type:`hidden`,name:v,value:`true`,disabled:!ut}),Q=Ve&&/* @__PURE__ */ h(`label`,{className:`label`,htmlFor:B,children:[Ve,We&&!Ue&&/* @__PURE__ */ m(`span`,{className:`label-optional`,children:` ${Ge}`}),Ue&&/* @__PURE__ */ m(ie,{})]}),Bt=/* @__PURE__ */ m(`input`,{id:B,ref:R,type:`file`,name:g,hidden:!0,accept:M,disabled:K,onChange:Lt});if(!nt){let t=Dt,n=st&&/* @__PURE__ */ h(`button`,{type:`button`,className:`btn btn-soft-primary btn-sm wui-image-picker-buttons-camera`,disabled:K,onClick:kt,children:[/* @__PURE__ */ m(i,{name:`camera`,size:16}),et??l.camera]}),ee={"--wui-avatar-size":`${t}px`,...D};return/* @__PURE__ */ h(`div`,{...o,className:`field wui-image-picker-field${E?` ${E}`:``}`,children:[Q,/* @__PURE__ */ h(`div`,{className:`wui-image-picker-buttons${Mt?` is-dragging`:``}${T?` ${T}`:``}`,style:ee,...Nt,children:[/* @__PURE__ */ h(`button`,{type:`button`,className:`wui-image-picker-buttons-face`,tabIndex:-1,"aria-label":Be??Et,"aria-describedby":wt,"aria-busy":y||void 0,disabled:K,onClick:Ot,...O,children:[q?/* @__PURE__ */ m(`img`,{className:`wui-image-picker-buttons-img`,src:q,alt:``,onError:()=>H(!0)}):/* @__PURE__ */ m(`span`,{className:`wui-image-picker-buttons-placeholder`,"aria-hidden":`true`,children:d||/* @__PURE__ */ m(i,{name:`user`,size:Math.round(t*.5)})}),/* @__PURE__ */ m(`span`,{className:`wui-image-picker-buttons-badge`,"aria-hidden":`true`,children:y?/* @__PURE__ */ m(i,{name:`refresh-cw`,size:14,className:`wui-spin`}):/* @__PURE__ */ m(i,{name:`camera`,size:14})})]}),/* @__PURE__ */ h(`div`,{className:`wui-image-picker-buttons-actions`,children:[/* @__PURE__ */ m(r,{variant:`soft`,size:`sm`,disabled:K,"aria-describedby":wt,onClick:Ot,children:Et}),n,/* @__PURE__ */ m(r,{tone:`danger`,variant:`soft`,size:`sm`,"data-wui-image-picker-remove":!0,hidden:!Tt,onClick:Rt,children:C})]}),Bt,st&&/* @__PURE__ */ m(`input`,{ref:ct,type:`file`,hidden:!0,accept:`image/*`,capture:`user`,disabled:K,onChange:Lt}),zt]}),/* @__PURE__ */ m(e,{error:J,hint:w,errorId:X,hintId:Y}),Z]})}let $=Dt,Vt=Math.max(14,Math.round($*.18)),Ht=Math.round($*.5),Ut=`wui-image-picker${rt===`avatar`?` wui-image-picker-avatar`:``}${b===`rounded`?` wui-image-picker-rounded`:b===`square`?` wui-image-picker-square`:``}${Mt?` is-dragging`:``}`,Wt=S===`inline`,Gt=S===`profile`,Kt=[`field`,`wui-image-picker-field`,Wt&&`wui-image-picker-field-inline`,Gt&&`wui-image-picker-field-profile`,T,E].filter(Boolean).join(` `),qt={"--wui-logo-size":`${$}px`},Jt=/* @__PURE__ */ h(`div`,{className:`wui-image-picker-shell`,style:qt,children:[/* @__PURE__ */ m(`button`,{type:`button`,className:Ut,onClick:Ot,disabled:K,"aria-busy":y||void 0,"aria-label":Be??`Upload photo`,"aria-describedby":X||Y,...Nt,...O,children:/* @__PURE__ */ h(`span`,{className:`wui-image-picker-ring`,"data-overlay-label":ze,children:[q?/* @__PURE__ */ m(`img`,{className:`wui-image-picker-img`,src:q,alt:``,onError:()=>H(!0)}):/* @__PURE__ */ m(`span`,{className:`wui-image-picker-logo`,children:d||rt===`avatar`&&/* @__PURE__ */ m(i,{name:`user`,size:Ht})}),y?/* @__PURE__ */ m(`span`,{className:`wui-image-picker-overlay is-loading`,"aria-hidden":`true`,children:/* @__PURE__ */ m(i,{name:`refresh-cw`,size:Vt,className:`wui-spin`})}):!De&&/* @__PURE__ */ h(`span`,{className:`wui-image-picker-overlay`,children:[/* @__PURE__ */ m(i,{name:Re,size:Vt}),/* @__PURE__ */ m(`span`,{children:ze})]})]})}),oe(/* @__PURE__ */ m(`button`,{type:`button`,className:`wui-image-picker-remove`,hidden:!Tt,"aria-label":C,"data-wui-image-picker-remove":!0,onClick:Rt,children:/* @__PURE__ */ m(i,{name:`x`,size:14})}),Tt?C:null),Bt,zt]}),Yt=w&&!J?/* @__PURE__ */ m(`div`,{className:`wui-image-picker-hint`,id:Y,children:w}):null,Xt=J?/* @__PURE__ */ m(e,{error:J,errorId:X}):null,Zt=/* @__PURE__ */ h(`div`,{className:`wui-image-picker-meta`,children:[Ie&&/* @__PURE__ */ m(`div`,{className:`wui-image-picker-title`,children:Ie}),Le&&/* @__PURE__ */ m(`div`,{className:`wui-image-picker-subtitle`,children:Le}),Yt,Xt]});return Wt?/* @__PURE__ */ h(`div`,{...o,className:Kt,style:D,children:[Q,/* @__PURE__ */ h(`div`,{className:`wui-image-picker-row`,children:[Jt,Zt]}),Z]}):Gt?/* @__PURE__ */ h(`div`,{...o,className:Kt,style:D,children:[Q,Jt,Zt,Z]}):/* @__PURE__ */ h(`div`,{...o,className:Kt,style:D,children:[Q,Jt,Yt,Xt,Z]})}export{_ as default};
1
+ import e from"../lib/FieldMessage.js";import t from"../lib/fillLabel.js";import{useFieldError as n}from"../lib/formFields.js";import ee from"../lib/useElementEntry.js";import te from"../lib/useFileDrop.js";import{splitMarkerProps as ne}from"../lib/wuiMarker.js";import re from"./AppAlert.js";import r from"./AppButton.js";import i from"./AppIcon.js";import ie from"./AppModal.js";import ae from"./AppRequiredMark.js";import a from"./assertValidValue.js";import oe from"./warnUnknownProps.js";import se from"./withTooltip.js";import{AVATAR_ACCEPT as ce,AVATAR_MAX_SIZE_MB as o,AVATAR_OUTPUT_SIZE as le,AVATAR_OUTPUT_TYPE as s,AVATAR_PREVIEW_SIZES as c,AVATAR_TEXT as l,DEFAULT_IMAGE_ACCEPT as u,DEFAULT_MAX_SIZE_MB as d,avatarUnreadableMessage as f,validateFile as ue}from"@webority/ui-elements/helpers";import{useCallback as de,useEffect as fe,useId as pe,useRef as me,useState as p}from"react";import{Fragment as he,jsx as m,jsxs as h}from"react/jsx-runtime";var ge=[`logo`,`avatar`],_e=[`overlay`,`buttons`],ve=[`stacked`,`inline`,`profile`],ye=[`initials`,`avatar`],be=[`circle`,`rounded`,`square`],xe=[`keep`,`image/webp`],Se=c.join(` `),Ce=()=>import(`@webority/ui-elements/elements/image-crop`),we={logo:{controls:`overlay`,accept:u,maxSizeMb:d,crop:void 0,rotatable:!1,previews:!1,camera:!1,outputSize:void 0,outputType:`keep`,variant:`initials`,sizes:{sm:72,md:120,lg:160}},avatar:{controls:`buttons`,accept:ce,maxSizeMb:o,crop:1,rotatable:!0,previews:!0,camera:!0,outputSize:le,outputType:s,variant:`avatar`,sizes:{sm:64,md:96,lg:128}}},g=`That image could not be cropped. Choose another one.`,Te=`That image could not be opened. Choose another one.`,Ee={dialogSize:`lg`,dialogTitle:`Crop photo`,dialogSubtitle:`Drag the frame and zoom to choose what to keep.`,save:`Apply`,cancel:`Cancel`,cropFailed:g,unreadable:()=>Te},De={dialogSize:void 0,dialogTitle:l.dialogTitle,dialogSubtitle:l.dialogSubtitle,save:l.save,cancel:l.cancel,cropFailed:l.cropFailed,unreadable:f};function Oe(ce){ee(`wui-image-crop`,Ce);let{marker:o,props:le}=ne(`AppImagePicker`,ce),{kind:s=`logo`,controls:c,value:u,fallback:d,variant:f,name:g,onChange:Te,onRemove:Oe,removeName:_,loading:v=!1,disabled:ke=!1,accept:Ae,maxSizeMb:je,shape:y=`circle`,size:b=`md`,crop:Me,rotatable:Ne,previews:Pe,camera:Fe,outputSize:Ie,outputType:Le,layout:x=`stacked`,title:Re,subtitle:ze,overlayIcon:Be=`image`,overlayLabel:Ve=`Update photo`,removeLabel:S=`Remove photo`,ariaLabel:He,label:Ue,helperText:C,error:We,required:Ge=!1,optional:Ke=!1,optionalLabel:qe=`(optional)`,dialogTitle:Je,dialogSubtitle:Ye,save:Xe,cancel:Ze,cropFailed:Qe,unreadable:$e,uploadLabel:et,changeLabel:tt,cameraLabel:nt,className:rt=``,fieldClassName:it=``,style:w,...T}=le,at=n(g),ot=We??at;oe(`AppImagePicker`,T),a(`AppImagePicker`,`kind`,s,ge),a(`AppImagePicker`,`controls`,c,_e),a(`AppImagePicker`,`variant`,f,ye),a(`AppImagePicker`,`layout`,x,ve),a(`AppImagePicker`,`shape`,y,be),a(`AppImagePicker`,`outputType`,Le,xe);let E=we[s]??we.logo,st=Object.fromEntries(Object.entries({dialogTitle:Je,dialogSubtitle:Ye,save:Xe,cancel:Ze,cropFailed:Qe,unreadable:$e===void 0?void 0:e=>t($e,{name:e?.name??``})}).filter(([,e])=>e!==void 0)),D={...s===`avatar`?De:Ee,...st},O=E.sizes;a(`AppImagePicker`,`size`,typeof b==`string`?b:null,Object.keys(O));let ct=(c??E.controls)===`overlay`,lt=f??E.variant,k=Ae??E.accept,A=je??E.maxSizeMb,j=Ie??E.outputSize,ut=Le??E.outputType,dt=Ne??E.rotatable,ft=Pe??E.previews,pt=Fe??E.camera,M=Me??E.crop,N=M===`free`?null:typeof M==`number`&&Number.isFinite(M)&&M>0?M:void 0;M!=null&&N===void 0&&a(`AppImagePicker`,`crop`,String(M),[`free`,`a positive number`]);let mt=N!==void 0&&j===void 0,P=me(null),ht=me(null),gt=me(null),F=pe(),[I,L]=p(null),[_t,R]=p(!1),[vt,z]=p(!1),[yt,B]=p(``),[V,H]=p(null),[U,bt]=p(!1),[W,G]=p(`loading`),[xt,K]=p(``),St=de(e=>{if(gt.current=e,!e)return;let t=()=>{G(`ready`),e.querySelector(`.wui-crop-stage`)?.focus()},n=()=>G(`error`);return e.addEventListener(`load`,t),e.addEventListener(`error`,n),()=>{e.removeEventListener(`load`,t),e.removeEventListener(`error`,n),gt.current=null}},[]);fe(()=>()=>{V&&URL.revokeObjectURL(V.url)},[V]),fe(()=>()=>{I&&URL.revokeObjectURL(I)},[I]);let[Ct,wt]=p(u);u!==Ct&&(wt(u),L(null),R(!1),z(!1));let q=v||ke,J=_t?null:I||(u&&!vt?u:null),Tt=!!J,Y=ot||yt,X=C&&!Y?`${F}-hint`:void 0,Z=Y?`${F}-error`:void 0,Et=Z||X,Dt=!q&&Tt&&(!!I||!!Oe||!!_),Ot=Tt?tt??l.change:et??l.choose,kt=typeof b==`number`?b:O[b]??O.md,At=()=>{q||P.current?.click()},jt=()=>{q||ht.current?.click()},Mt=e=>{if(g&&P.current&&typeof DataTransfer==`function`){let t=new DataTransfer;t.items.add(e),P.current.files=t.files}R(!1),z(!1),L(URL.createObjectURL(e)),Te?.(e)},Nt=e=>{let t=N!==void 0&&e.type!==`image/svg+xml`,n=ue(e,{accept:k,maxSizeMb:t&&mt?0:A});n?B(n):(B(``),t?(G(`loading`),K(``),H({file:e,url:URL.createObjectURL(e)})):Mt(e))},{dragOver:Pt,dropProps:Ft}=te({accept:k,maxSizeMb:mt?0:A,disabled:q,onFiles:e=>{let t=e[0];if(!t)throw Error(`<AppImagePicker> received a drop with no file.`);Nt(t)},onReject:({message:e})=>B(e)}),It=e=>{let t=ut===`keep`?e.type:ut;return j===void 0?{name:e.name,type:t,maxBytes:A>0?A*1024*1024:0}:{name:e.name||`photo`,type:t,size:j}},Lt=async()=>{if(!V)return;let{file:e}=V;bt(!0),K(``);let t=null;try{t=await gt.current?.toFile(It(e))}catch{t=null}if(bt(!1),!t)K(D.cropFailed);else if(H(null),mt){let e=ue(t,{accept:k,maxSizeMb:A});e?B(e):Mt(t)}else Mt(t)},Rt=()=>{U||H(null)},zt=e=>{let t=e.target.files?.[0];e.target.value=``,t&&Nt(t)},Bt=()=>{L(null),R(!0),B(``),P.current&&(P.current.value=``),Oe?.()},Q=N!==void 0&&/* @__PURE__ */ h(ie,{open:!!V,title:D.dialogTitle,subtitle:D.dialogSubtitle,size:D.dialogSize,staticBackdrop:!0,dismissible:!U,closeOnEscape:!U,onClose:Rt,footer:/* @__PURE__ */ h(he,{children:[/* @__PURE__ */ m(r,{type:`button`,variant:`soft`,disabled:U,onClick:Rt,children:D.cancel}),/* @__PURE__ */ m(r,{type:`button`,loading:U,disabled:W!==`ready`,onClick:Lt,children:D.save})]}),children:[W===`error`&&V&&/* @__PURE__ */ m(re,{tone:`danger`,children:D.unreadable(V.file)}),xt&&/* @__PURE__ */ m(re,{tone:`danger`,children:xt}),V&&W!==`error`&&/* @__PURE__ */ m(`wui-image-crop`,{ref:St,src:V.url,aspect:N??`free`,round:N===1&&y===`circle`,rotatable:dt,previews:ft?Se:void 0})]}),Vt=_&&/* @__PURE__ */ m(`input`,{type:`hidden`,name:_,value:`true`,disabled:!_t}),$=Ue&&/* @__PURE__ */ h(`label`,{className:`label`,htmlFor:F,children:[Ue,Ke&&!Ge&&/* @__PURE__ */ m(`span`,{className:`label-optional`,children:` ${qe}`}),Ge&&/* @__PURE__ */ m(ae,{})]}),Ht=/* @__PURE__ */ m(`input`,{id:F,ref:P,type:`file`,name:g,hidden:!0,accept:k,disabled:q,onChange:zt});if(!ct){let t=kt,n=pt&&/* @__PURE__ */ h(`button`,{type:`button`,className:`btn btn-soft-primary btn-sm wui-image-picker-buttons-camera`,disabled:q,onClick:jt,children:[/* @__PURE__ */ m(i,{name:`camera`,size:16}),nt??l.camera]}),ee={"--wui-avatar-size":`${t}px`,...w};return/* @__PURE__ */ h(`div`,{...o,className:`field wui-image-picker-field${it?` ${it}`:``}`,children:[$,/* @__PURE__ */ h(`div`,{className:`wui-image-picker-buttons${Pt?` is-dragging`:``}${rt?` ${rt}`:``}`,style:ee,...Ft,children:[/* @__PURE__ */ h(`button`,{type:`button`,className:`wui-image-picker-buttons-face`,tabIndex:-1,"aria-label":He??Ot,"aria-describedby":Et,"aria-busy":v||void 0,disabled:q,onClick:At,...T,children:[J?/* @__PURE__ */ m(`img`,{className:`wui-image-picker-buttons-img`,src:J,alt:``,onError:()=>z(!0)}):/* @__PURE__ */ m(`span`,{className:`wui-image-picker-buttons-placeholder`,"aria-hidden":`true`,children:d||/* @__PURE__ */ m(i,{name:`user`,size:Math.round(t*.5)})}),/* @__PURE__ */ m(`span`,{className:`wui-image-picker-buttons-badge`,"aria-hidden":`true`,children:v?/* @__PURE__ */ m(i,{name:`refresh-cw`,size:14,className:`wui-spin`}):/* @__PURE__ */ m(i,{name:`camera`,size:14})})]}),/* @__PURE__ */ h(`div`,{className:`wui-image-picker-buttons-actions`,children:[/* @__PURE__ */ m(r,{variant:`soft`,size:`sm`,disabled:q,"aria-describedby":Et,onClick:At,children:Ot}),n,/* @__PURE__ */ m(r,{tone:`danger`,variant:`soft`,size:`sm`,"data-wui-image-picker-remove":!0,hidden:!Dt,onClick:Bt,children:S})]}),Ht,pt&&/* @__PURE__ */ m(`input`,{ref:ht,type:`file`,hidden:!0,accept:`image/*`,capture:`user`,disabled:q,onChange:zt}),Vt]}),/* @__PURE__ */ m(e,{error:Y,hint:C,errorId:Z,hintId:X}),Q]})}let Ut=kt,Wt=Math.max(14,Math.round(Ut*.18)),Gt=Math.round(Ut*.5),Kt=`wui-image-picker${lt===`avatar`?` wui-image-picker-avatar`:``}${y===`rounded`?` wui-image-picker-rounded`:y===`square`?` wui-image-picker-square`:``}${Pt?` is-dragging`:``}`,qt=x===`inline`,Jt=x===`profile`,Yt=[`field`,`wui-image-picker-field`,qt&&`wui-image-picker-field-inline`,Jt&&`wui-image-picker-field-profile`,rt,it].filter(Boolean).join(` `),Xt={"--wui-logo-size":`${Ut}px`},Zt=/* @__PURE__ */ h(`div`,{className:`wui-image-picker-shell`,style:Xt,children:[/* @__PURE__ */ m(`button`,{type:`button`,className:Kt,onClick:At,disabled:q,"aria-busy":v||void 0,"aria-label":He??`Upload photo`,"aria-describedby":Z||X,...Ft,...T,children:/* @__PURE__ */ h(`span`,{className:`wui-image-picker-ring`,"data-overlay-label":Ve,children:[J?/* @__PURE__ */ m(`img`,{className:`wui-image-picker-img`,src:J,alt:``,onError:()=>z(!0)}):/* @__PURE__ */ m(`span`,{className:`wui-image-picker-logo`,children:d||lt===`avatar`&&/* @__PURE__ */ m(i,{name:`user`,size:Gt})}),v?/* @__PURE__ */ m(`span`,{className:`wui-image-picker-overlay is-loading`,"aria-hidden":`true`,children:/* @__PURE__ */ m(i,{name:`refresh-cw`,size:Wt,className:`wui-spin`})}):!ke&&/* @__PURE__ */ h(`span`,{className:`wui-image-picker-overlay`,children:[/* @__PURE__ */ m(i,{name:Be,size:Wt}),/* @__PURE__ */ m(`span`,{children:Ve})]})]})}),se(/* @__PURE__ */ m(`button`,{type:`button`,className:`wui-image-picker-remove`,hidden:!Dt,"aria-label":S,"data-wui-image-picker-remove":!0,onClick:Bt,children:/* @__PURE__ */ m(i,{name:`x`,size:14})}),Dt?S:null),Ht,Vt]}),Qt=C&&!Y?/* @__PURE__ */ m(`div`,{className:`wui-image-picker-hint`,id:X,children:C}):null,$t=Y?/* @__PURE__ */ m(e,{error:Y,errorId:Z}):null,en=/* @__PURE__ */ h(`div`,{className:`wui-image-picker-meta`,children:[Re&&/* @__PURE__ */ m(`div`,{className:`wui-image-picker-title`,children:Re}),ze&&/* @__PURE__ */ m(`div`,{className:`wui-image-picker-subtitle`,children:ze}),Qt,$t]});return qt?/* @__PURE__ */ h(`div`,{...o,className:Yt,style:w,children:[$,/* @__PURE__ */ h(`div`,{className:`wui-image-picker-row`,children:[Zt,en]}),Q]}):Jt?/* @__PURE__ */ h(`div`,{...o,className:Yt,style:w,children:[$,Zt,en,Q]}):/* @__PURE__ */ h(`div`,{...o,className:Yt,style:w,children:[$,Zt,Qt,$t,Q]})}export{Oe as default};
@@ -1 +1 @@
1
- import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/FieldMessage.js";import{FIELD_BUSY_CLASS as n,blockWhenReadOnly as ee}from"../lib/fieldState.js";import{splitMarkerProps as te}from"../lib/wuiMarker.js";import r from"./AppIcon.js";import ne from"./AppInfoTip.js";import re from"./AppPopover.js";import i from"./AppRequiredMark.js";import a from"./assertValidValue.js";import ie from"./warnUnknownProps.js";import{MASK_INPUT_TYPES as ae,MASK_NAMES as oe,attachInputMask as se,evaluatePassword as ce,formatMasked as le,isMaskPattern as ue,postedMasked as de}from"@webority/ui-elements/helpers";import{cloneElement as fe,forwardRef as pe,useEffect as o,useId as me,useRef as he,useState as s}from"react";import{jsx as c,jsxs as l}from"react/jsx-runtime";import{Form as u}from"react-bootstrap";var ge=[`sm`,`md`,`lg`],_e=[`bare`],ve=[`off`,`border`,`above`],ye=[`off`,`shown`];function d(e,t){if(t!=null&&t!==``&&t!==!1)throw Error(`<AppInput> controlOnly draws no field, so it takes no ${e}; draw the label or message on the page.`)}function be(e){return e==null||{...`minLength`in e&&{minLength:e.minLength??0},...`uppercase`in e&&{uppercase:e.uppercase??!1},...`lowercase`in e&&{lowercase:e.lowercase??!1},...`digit`in e&&{digit:e.digit??!1},...`special`in e&&{special:e.special??!1},...`uniqueChars`in e&&{uniqueChars:e.uniqueChars??0},...`customRules`in e&&{customRules:e.customRules??[]}}}var f=pe(function(pe,f){let{marker:xe,props:Se}=te(`AppInput`,pe),{label:p,required:m=!1,optional:h=!1,error:Ce,helperText:g,help:_,helpLabel:we=`More information`,type:v=`text`,size:y=`md`,leftIcon:b,rightIcon:x,onRightIconClick:Te,rightIconLabel:Ee,unit:S,id:De,name:Oe,className:ke=``,fieldClassName:C=``,disabled:w=!1,readOnly:T=!1,loading:E=!1,clearable:D=!1,clearLabel:Ae=`Clear`,optionalLabel:je=`(optional)`,requirementsTitle:Me=`Password requirements`,showPasswordLabel:Ne=`Show password`,hidePasswordLabel:Pe=`Hide password`,showCount:O=!1,maxLength:k,monospace:Fe=!1,prefix:A,suffix:j,action:Ie,floatingLabel:M=`off`,variant:Le,passwordRequirements:N=`off`,passwordPolicy:Re,requirementsPlacement:P=`auto`,mask:F,postFormatted:I=!1,onMaskChange:ze,controlOnly:Be=!1,value:L,...R}=Se;ie(`AppInput`,R);let{onChange:Ve,onBlur:He,onClick:Ue,onInput:z,...We}=R;a(`AppInput`,`size`,y,ge),a(`AppInput`,`variant`,Le,_e),a(`AppInput`,`floatingLabel`,M,ve),a(`AppInput`,`passwordRequirements`,N,ye),Be&&(d(`label`,p),d(`error`,Ce),d(`helperText`,g),d(`fieldClassName`,C),d(`showCount`,O),d(`help`,_),d(`optional`,h),d(`floatingLabel`,M===`off`?void 0:M),d(`passwordRequirements`,N===`shown`?N:void 0)),o(()=>{h&&m&&typeof process<`u`&&process.env.NODE_ENV!==`production`&&e(`AppInput: optional and required together; optional ignored`)},[h,m]),F!=null&&!ue(F)&&a(`AppInput`,`mask`,F,oe),F!=null&&a(`AppInput`,`type`,v,ae);let[B,Ge]=s(!1),[Ke,qe]=s(``),V=Ce||Ke,Je=me(),H=De||Je,U=v===`password`,Ye=U&&B?`text`:v,W=he(null),Xe=e=>{W.current=e,typeof f==`function`?f(e):f&&(f.current=e)},G=String(L??R.defaultValue??``),[Ze,K]=s(()=>!!G),[Qe,$e]=s(()=>G.length),et=D&&!w&&!T&&!E,q=D||O,J=U&&N===`shown`,[tt,nt]=s(G);o(()=>{J&&L!==void 0&&nt(String(L??``))},[L,J]),o(()=>{if(!q||L===void 0)return;let e=String(L??``);K(!!e),$e(e.length)},[L,q]);let rt=e=>{let t=e.currentTarget;K(!!t.value),$e(t.value.length),z?.(e)},it=e=>{J&&nt(e.currentTarget.value),q?rt(e):z?.(e)},at=F?{...L!==void 0&&{value:le(F,L)},...R.defaultValue!==void 0&&{defaultValue:le(F,R.defaultValue)}}:null,ot=he(ze);ot.current=ze,o(()=>{let e=W.current;if(F&&e)return se(e,{mask:F,postFormatted:I,onChange:(e,t)=>ot.current?.(e,t),onInvalidChange:qe})},[F,I]);let st=e=>F&&!I&&e?t=>{let n=t.currentTarget,ee=new Proxy(n,{get:(e,t)=>{if(t===`value`)return de(F,e.value);let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}});e(Object.create(t,{target:{value:ee}}))}:e,ct=et?/* @__PURE__ */ c(`button`,{type:`button`,className:`input-clear`,onClick:()=>{let e=W.current;if(!e)return;let t=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,`value`)?.set;t?t.call(e,``):e.value=``,e.dispatchEvent(new Event(`input`,{bubbles:!0})),K(!1),e.focus()},"aria-label":Ae,tabIndex:-1,hidden:!Ze,children:/* @__PURE__ */ c(r,{name:`x`,size:16})}):null,lt=V&&H?`${H}-error`:void 0,Y=g&&H?`${H}-hint`:void 0,X=J&&P===`inline`,ut=X&&H?`${H}-requirements`:void 0,dt=lt||(X?ut:Y),ft=[`input`,y===`sm`?`input-sm`:``,y===`lg`?`input-lg`:``,V?`error`:``,U?`pw`:``,S?`num-input`:``,!(M!==`off`&&p||A||j||S||U||x)&&D&&et?`has-clear`:``,Le===`bare`?`input-bare`:``,Fe?`wui-mono`:``,E?n:``,ke].filter(Boolean).join(` `),pt=ee(T||E),mt=pt?e=>{pt(e),Ue?.(e)}:Ue,ht=st(Ve),gt=st(He),_t=q||J?it:z,Z=/* @__PURE__ */ c(u.Control,{id:H,name:Oe,type:Ye,className:ft,disabled:w,readOnly:T||E,"aria-busy":E||void 0,required:m,"aria-invalid":V?`true`:`false`,"aria-describedby":dt,maxLength:k,...L===void 0?null:{value:L},...We,...mt?{onClick:mt}:null,...ht?{onChange:ht}:null,...gt?{onBlur:gt}:null,...at,placeholder:M===`off`?R.placeholder:` `,ref:Xe,..._t?{onInput:_t}:null}),Q=Re??!0,vt=Q&&typeof Q==`object`&&Q.title||Me,yt=J?ce(tt,be(Re)):null,bt=J?/* @__PURE__ */ c(`ul`,{className:`pw-criteria`,"aria-live":`polite`,id:ut,"aria-label":X?vt:void 0,children:yt?.map(e=>/* @__PURE__ */ l(`li`,{className:`pw-rule ${e.met?`met`:`unmet`}`,children:[/* @__PURE__ */ c(`span`,{className:`pw-mark`,"aria-hidden":`true`}),/* @__PURE__ */ c(`span`,{className:`pw-rule-text`,children:e.label}),/* @__PURE__ */ c(`span`,{className:`visually-hidden`,children:e.met?`: met`:`: not met`})]},e.key))}):null,$;if(M!==`off`&&p&&!U)$=/* @__PURE__ */ l(`div`,{className:M===`above`?`field-float wui-float-above`:`field-float`,children:[Z,/* @__PURE__ */ l(`label`,{className:`float-label`,htmlFor:H,children:[p,m&&/* @__PURE__ */ c(i,{})]})]});else if(Ie)$=/* @__PURE__ */ l(`div`,{className:`input-action-row`,children:[/* @__PURE__ */ l(`div`,{className:b?`input-icon`:`input-wrap`,children:[b&&/* @__PURE__ */ c(`span`,{className:`ic`,children:/* @__PURE__ */ c(r,{name:b,size:16})}),Z]}),/* @__PURE__ */ c(`div`,{className:`input-action`,children:Ie})]});else if(A||j)$=/* @__PURE__ */ l(`div`,{className:`input-affixed`,children:[A!=null&&/* @__PURE__ */ c(`span`,{className:`affix affix-pre`,children:A}),Z,j!=null&&/* @__PURE__ */ c(`span`,{className:`affix affix-suf`,children:j})]});else if(S)$=/* @__PURE__ */ l(`div`,{className:`input-with-unit`,children:[Z,/* @__PURE__ */ c(`span`,{className:`unit`,children:S})]});else if(U){let e=/* @__PURE__ */ l(`button`,{type:`button`,className:`pw-toggle${B?` pw-revealed`:``}`,onClick:()=>Ge(e=>!e),"aria-label":B?Pe:Ne,tabIndex:-1,children:[/* @__PURE__ */ c(r,{name:`eye`,size:18,className:`pw-eye`}),/* @__PURE__ */ c(r,{name:`eye-off`,size:18,className:`pw-eye-off`})]}),t=M!==`off`&&p?/* @__PURE__ */ c(`div`,{className:M===`above`?`field-float wui-float-above`:`field-float`,children:/* @__PURE__ */ l(`div`,{className:`input-wrap`,children:[Z,e,/* @__PURE__ */ l(`label`,{className:`float-label`,htmlFor:H,children:[p,m&&/* @__PURE__ */ c(i,{})]})]})}):/* @__PURE__ */ l(`div`,{className:b?`input-icon`:`input-wrap`,children:[b&&/* @__PURE__ */ c(`span`,{className:`ic`,children:/* @__PURE__ */ c(r,{name:b,size:16})}),Z,e]});$=J&&!X&&P!==`inline`?/* @__PURE__ */ c(re,{trigger:t,triggerType:`focus`,placement:P,title:vt,className:`pw-popover`,children:bt}):t}else $=x?/* @__PURE__ */ l(`div`,{className:`input-wrap`,children:[Z,/* @__PURE__ */ c(`button`,{type:`button`,className:`pw-toggle`,onClick:Te,disabled:!Te,tabIndex:-1,"aria-label":Ee||x,children:/* @__PURE__ */ c(r,{name:x,size:18})})]}):D?/* @__PURE__ */ l(`div`,{className:b?`input-icon`:`input-wrap`,children:[b&&/* @__PURE__ */ c(`span`,{className:`ic`,children:/* @__PURE__ */ c(r,{name:b,size:16})}),Z,ct]}):b?/* @__PURE__ */ l(`div`,{className:`input-icon`,children:[/* @__PURE__ */ c(`span`,{className:`ic`,children:/* @__PURE__ */ c(r,{name:b,size:16})}),Z]}):Z;return Be?fe($,xe):/* @__PURE__ */ l(u.Group,{...xe,className:`field${C?` ${C}`:``}`,children:[p&&M===`off`&&/* @__PURE__ */ l(u.Label,{className:`label`,htmlFor:H,children:[p,h&&!m&&/* @__PURE__ */ c(`span`,{className:`label-optional`,children:` ${je}`}),m&&/* @__PURE__ */ c(i,{}),_&&/* @__PURE__ */ c(ne,{label:we,children:_})]}),$,X&&/* @__PURE__ */ c(`div`,{className:`wui-pw-inline`,children:bt}),/* @__PURE__ */ c(t,{error:V,hint:X?null:g,errorId:lt,hintId:Y}),O&&/* @__PURE__ */ l(`div`,{className:`field-count${k&&Qe>=k?` at-limit`:``}`,children:[Qe,k?` / ${k}`:``]})]})});export{f as default};
1
+ import{devWarn as e}from"../lib/devWarn.js";import t from"../lib/FieldMessage.js";import{FIELD_BUSY_CLASS as n,blockWhenReadOnly as ee}from"../lib/fieldState.js";import{useFieldError as te}from"../lib/formFields.js";import{splitMarkerProps as ne}from"../lib/wuiMarker.js";import r from"./AppIcon.js";import re from"./AppInfoTip.js";import ie from"./AppPopover.js";import i from"./AppRequiredMark.js";import a from"./assertValidValue.js";import ae from"./warnUnknownProps.js";import{MASK_INPUT_TYPES as oe,MASK_NAMES as se,attachInputMask as ce,evaluatePassword as le,formatMasked as ue,isMaskPattern as de,postedMasked as fe}from"@webority/ui-elements/helpers";import{cloneElement as pe,forwardRef as me,useEffect as o,useId as he,useRef as s,useState as c}from"react";import{jsx as l,jsxs as u}from"react/jsx-runtime";import{Form as d}from"react-bootstrap";var ge=[`sm`,`md`,`lg`],_e=[`bare`],ve=[`off`,`border`,`above`],ye=[`off`,`shown`];function f(e,t){if(t!=null&&t!==``&&t!==!1)throw Error(`<AppInput> controlOnly draws no field, so it takes no ${e}; draw the label or message on the page.`)}function be(e){return e==null||{...`minLength`in e&&{minLength:e.minLength??0},...`uppercase`in e&&{uppercase:e.uppercase??!1},...`lowercase`in e&&{lowercase:e.lowercase??!1},...`digit`in e&&{digit:e.digit??!1},...`special`in e&&{special:e.special??!1},...`uniqueChars`in e&&{uniqueChars:e.uniqueChars??0},...`customRules`in e&&{customRules:e.customRules??[]}}}var p=me(function(me,p){let{marker:xe,props:Se}=ne(`AppInput`,me),{label:m,required:h=!1,optional:g=!1,error:Ce,helperText:_,help:v,helpLabel:we=`More information`,type:y=`text`,size:b=`md`,leftIcon:x,rightIcon:S,onRightIconClick:Te,rightIconLabel:Ee,unit:C,id:De,name:Oe,className:ke=``,fieldClassName:w=``,disabled:Ae=!1,readOnly:T=!1,loading:E=!1,clearable:D=!1,clearLabel:je=`Clear`,optionalLabel:Me=`(optional)`,requirementsTitle:Ne=`Password requirements`,showPasswordLabel:Pe=`Show password`,hidePasswordLabel:Fe=`Hide password`,showCount:O=!1,maxLength:k,monospace:Ie=!1,prefix:A,suffix:j,action:Le,floatingLabel:M=`off`,variant:Re,passwordRequirements:N=`off`,passwordPolicy:ze,requirementsPlacement:P=`auto`,mask:F,postFormatted:I=!1,onMaskChange:Be,controlOnly:Ve=!1,value:L,...R}=Se,He=te(Oe);ae(`AppInput`,R);let{onChange:Ue,onBlur:We,onClick:Ge,onInput:z,...Ke}=R;a(`AppInput`,`size`,b,ge),a(`AppInput`,`variant`,Re,_e),a(`AppInput`,`floatingLabel`,M,ve),a(`AppInput`,`passwordRequirements`,N,ye),Ve&&(f(`label`,m),f(`error`,Ce),f(`helperText`,_),f(`fieldClassName`,w),f(`showCount`,O),f(`help`,v),f(`optional`,g),f(`floatingLabel`,M===`off`?void 0:M),f(`passwordRequirements`,N===`shown`?N:void 0)),o(()=>{g&&h&&typeof process<`u`&&process.env.NODE_ENV!==`production`&&e(`AppInput: optional and required together; optional ignored`)},[g,h]),F!=null&&!de(F)&&a(`AppInput`,`mask`,F,se),F!=null&&a(`AppInput`,`type`,y,oe);let[B,qe]=c(!1),[Je,Ye]=c(``),V=Ce||Je||He,Xe=he(),H=De||Xe,U=y===`password`,Ze=U&&B?`text`:y,W=s(null),Qe=e=>{W.current=e,typeof p==`function`?p(e):p&&(p.current=e)},G=String(L??R.defaultValue??``),[$e,K]=c(()=>!!G),[et,tt]=c(()=>G.length),nt=D&&!Ae&&!T&&!E,q=D||O,J=U&&N===`shown`,[rt,it]=c(G);o(()=>{J&&L!==void 0&&it(String(L??``))},[L,J]),o(()=>{if(!q||L===void 0)return;let e=String(L??``);K(!!e),tt(e.length)},[L,q]);let at=e=>{let t=e.currentTarget;K(!!t.value),tt(t.value.length),z?.(e)},ot=e=>{J&&it(e.currentTarget.value),q?at(e):z?.(e)},st=F?{...L!==void 0&&{value:ue(F,L)},...R.defaultValue!==void 0&&{defaultValue:ue(F,R.defaultValue)}}:null,ct=s(Be);ct.current=Be,o(()=>{let e=W.current;if(F&&e)return ce(e,{mask:F,postFormatted:I,onChange:(e,t)=>ct.current?.(e,t),onInvalidChange:Ye})},[F,I]);let lt=e=>F&&!I&&e?t=>{let n=t.currentTarget,ee=new Proxy(n,{get:(e,t)=>{if(t===`value`)return fe(F,e.value);let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}});e(Object.create(t,{target:{value:ee}}))}:e,ut=nt?/* @__PURE__ */ l(`button`,{type:`button`,className:`input-clear`,onClick:()=>{let e=W.current;if(!e)return;let t=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,`value`)?.set;t?t.call(e,``):e.value=``,e.dispatchEvent(new Event(`input`,{bubbles:!0})),K(!1),e.focus()},"aria-label":je,tabIndex:-1,hidden:!$e,children:/* @__PURE__ */ l(r,{name:`x`,size:16})}):null,dt=V&&H?`${H}-error`:void 0,ft=_&&H?`${H}-hint`:void 0,Y=J&&P===`inline`,pt=Y&&H?`${H}-requirements`:void 0,mt=dt||(Y?pt:ft),ht=[`input`,b===`sm`?`input-sm`:``,b===`lg`?`input-lg`:``,V?`error`:``,U?`pw`:``,C?`num-input`:``,!(M!==`off`&&m||A||j||C||U||S)&&D&&nt?`has-clear`:``,Re===`bare`?`input-bare`:``,Ie?`wui-mono`:``,E?n:``,ke].filter(Boolean).join(` `),X=ee(T||E),gt=X?e=>{X(e),Ge?.(e)}:Ge,_t=lt(Ue),vt=lt(We),yt=q||J?ot:z,Z=/* @__PURE__ */ l(d.Control,{id:H,name:Oe,type:Ze,className:ht,disabled:Ae,readOnly:T||E,"aria-busy":E||void 0,required:h,"aria-invalid":V?`true`:`false`,"aria-describedby":mt,maxLength:k,...L===void 0?null:{value:L},...Ke,...gt?{onClick:gt}:null,..._t?{onChange:_t}:null,...vt?{onBlur:vt}:null,...st,placeholder:M===`off`?R.placeholder:` `,ref:Qe,...yt?{onInput:yt}:null}),Q=ze??!0,bt=Q&&typeof Q==`object`&&Q.title||Ne,xt=J?le(rt,be(ze)):null,St=J?/* @__PURE__ */ l(`ul`,{className:`pw-criteria`,"aria-live":`polite`,id:pt,"aria-label":Y?bt:void 0,children:xt?.map(e=>/* @__PURE__ */ u(`li`,{className:`pw-rule ${e.met?`met`:`unmet`}`,children:[/* @__PURE__ */ l(`span`,{className:`pw-mark`,"aria-hidden":`true`}),/* @__PURE__ */ l(`span`,{className:`pw-rule-text`,children:e.label}),/* @__PURE__ */ l(`span`,{className:`visually-hidden`,children:e.met?`: met`:`: not met`})]},e.key))}):null,$;if(M!==`off`&&m&&!U)$=/* @__PURE__ */ u(`div`,{className:M===`above`?`field-float wui-float-above`:`field-float`,children:[Z,/* @__PURE__ */ u(`label`,{className:`float-label`,htmlFor:H,children:[m,h&&/* @__PURE__ */ l(i,{})]})]});else if(Le)$=/* @__PURE__ */ u(`div`,{className:`input-action-row`,children:[/* @__PURE__ */ u(`div`,{className:x?`input-icon`:`input-wrap`,children:[x&&/* @__PURE__ */ l(`span`,{className:`ic`,children:/* @__PURE__ */ l(r,{name:x,size:16})}),Z]}),/* @__PURE__ */ l(`div`,{className:`input-action`,children:Le})]});else if(A||j)$=/* @__PURE__ */ u(`div`,{className:`input-affixed`,children:[A!=null&&/* @__PURE__ */ l(`span`,{className:`affix affix-pre`,children:A}),Z,j!=null&&/* @__PURE__ */ l(`span`,{className:`affix affix-suf`,children:j})]});else if(C)$=/* @__PURE__ */ u(`div`,{className:`input-with-unit`,children:[Z,/* @__PURE__ */ l(`span`,{className:`unit`,children:C})]});else if(U){let e=/* @__PURE__ */ u(`button`,{type:`button`,className:`pw-toggle${B?` pw-revealed`:``}`,onClick:()=>qe(e=>!e),"aria-label":B?Fe:Pe,tabIndex:-1,children:[/* @__PURE__ */ l(r,{name:`eye`,size:18,className:`pw-eye`}),/* @__PURE__ */ l(r,{name:`eye-off`,size:18,className:`pw-eye-off`})]}),t=M!==`off`&&m?/* @__PURE__ */ l(`div`,{className:M===`above`?`field-float wui-float-above`:`field-float`,children:/* @__PURE__ */ u(`div`,{className:`input-wrap`,children:[Z,e,/* @__PURE__ */ u(`label`,{className:`float-label`,htmlFor:H,children:[m,h&&/* @__PURE__ */ l(i,{})]})]})}):/* @__PURE__ */ u(`div`,{className:x?`input-icon`:`input-wrap`,children:[x&&/* @__PURE__ */ l(`span`,{className:`ic`,children:/* @__PURE__ */ l(r,{name:x,size:16})}),Z,e]});$=J&&!Y&&P!==`inline`?/* @__PURE__ */ l(ie,{trigger:t,triggerType:`focus`,placement:P,title:bt,className:`pw-popover`,children:St}):t}else $=S?/* @__PURE__ */ u(`div`,{className:`input-wrap`,children:[Z,/* @__PURE__ */ l(`button`,{type:`button`,className:`pw-toggle`,onClick:Te,disabled:!Te,tabIndex:-1,"aria-label":Ee||S,children:/* @__PURE__ */ l(r,{name:S,size:18})})]}):D?/* @__PURE__ */ u(`div`,{className:x?`input-icon`:`input-wrap`,children:[x&&/* @__PURE__ */ l(`span`,{className:`ic`,children:/* @__PURE__ */ l(r,{name:x,size:16})}),Z,ut]}):x?/* @__PURE__ */ u(`div`,{className:`input-icon`,children:[/* @__PURE__ */ l(`span`,{className:`ic`,children:/* @__PURE__ */ l(r,{name:x,size:16})}),Z]}):Z;return Ve?pe($,xe):/* @__PURE__ */ u(d.Group,{...xe,className:`field${w?` ${w}`:``}`,children:[m&&M===`off`&&/* @__PURE__ */ u(d.Label,{className:`label`,htmlFor:H,children:[m,g&&!h&&/* @__PURE__ */ l(`span`,{className:`label-optional`,children:` ${Me}`}),h&&/* @__PURE__ */ l(i,{}),v&&/* @__PURE__ */ l(re,{label:we,children:v})]}),$,Y&&/* @__PURE__ */ l(`div`,{className:`wui-pw-inline`,children:St}),/* @__PURE__ */ l(t,{error:V,hint:Y?null:_,errorId:dt,hintId:ft}),O&&/* @__PURE__ */ u(`div`,{className:`field-count${k&&et>=k?` at-limit`:``}`,children:[et,k?` / ${k}`:``]})]})});export{p as default};