@nice2dev/ui 1.4.26 → 1.4.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # [1.0.27] — 2026-06-07
2
2
 
3
+ ## 1.4.27
4
+
5
+ ### Patch Changes
6
+
7
+ - 7523286: NicePixelEditor (round 44, 1.4.27).
8
+
9
+ - **View → Full screen**: the editor covers the screen (Esc leaves it). Menus, dialogs, selects and
10
+ colour pickers stay visible meanwhile.
11
+ - **View → Animations**: the bottom panel is titled Animations and hidden at start (new
12
+ `defaultShowAnimations`); it has a close button. **View → Properties** shows or hides the right
13
+ panel (new `defaultShowProperties`).
14
+ - **Grouped tools**: one button per group shows its last-used tool, and a small corner arrow lists
15
+ the rest (Draw: pencil / dither, Fill: bucket / gradient, Shapes: line / rectangle / ellipse,
16
+ Select: select / move). Eleven buttons used to run into the Animations panel and hide the last
17
+ ones. The lists open with the keyboard too.
18
+ - **Colour picker**: it picked a colour away from the pointer. A click was divided by the canvas's
19
+ own 150 px while CSS showed it at another size; it now uses the displayed size, follows a drag
20
+ and has arrow keys.
21
+ - **Eyedropper**: it samples what is on screen (every visible layer), not the active layer only,
22
+ and the pointer maps correctly on a zoomed or CSS-scaled canvas.
23
+ - **Right panel**: it scrolls inside the editor (it ran past the Animations panel) and narrows in
24
+ small containers. The brush sliders keep their values inside the panel.
25
+ - **Filters menu**: Filter gallery… and Adjustments… apply the filters and adjustments of
26
+ NicePhotoEditor to the active layer of the frame (inside the selection when there is one), with
27
+ a preview and one undo step. NicePhotoEditor stays the simple retouch app.
28
+ - **Brush presets**: the presets of the removed NiceBrushEngine (hard / soft round, calligraphy,
29
+ airbrush, watercolour), scaled to pixel art; new exports `PIXEL_BRUSH_PRESETS`,
30
+ `matchBrushPreset`, type `PixelBrushConfig`.
31
+ - **ui-core / ui**: new `useNiceFullscreen(ref)` (Fullscreen API, window-covering fallback) and
32
+ `NicePortalTargetProvider` (overlays portal into a given element, such as the fullscreen one).
33
+ `NiceColorPicker` portals to the theme's portal host like `NiceColorPalette`.
34
+ - The NicePixelEditor doc lists its real props.
35
+
36
+ - Updated dependencies [7523286]
37
+ - @nice2dev/ui-core@1.4.27
38
+ - @nice2dev/i18n@1.4.27
39
+
3
40
  ## 1.4.26
4
41
 
5
42
  ### Patch Changes
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),M=require("@nice2dev/ui-core"),k=require("react"),he=require("react-dom"),fe=require("./devops-o6Zm0VKB.cjs"),ge=["#ef4444","#f97316","#f59e0b","#84cc16","#10b981","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#ec4899","#64748b","#1e293b"];function ve(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function xe(a){const u=/^#?([0-9a-f]{6})$/i.exec(a.trim());if(!u)return{r:0,g:0,b:0};const h=parseInt(u[1],16);return{r:h>>16&255,g:h>>8&255,b:h&255}}function be(a,u,h){const p=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${p(a)}${p(u)}${p(h)}`}function _e(a,u,h){const p=a/255,t=u/255,i=h/255,r=Math.max(p,t,i),x=Math.min(p,t,i),d=(r+x)/2;let o=0,c=0;if(r!==x){const _=r-x;switch(c=d>.5?_/(2-r-x):_/(r+x),r){case p:o=(t-i)/_+(t<i?6:0);break;case t:o=(i-p)/_+2;break;case i:o=(p-t)/_+4;break}o*=60}return{h:Math.round(o),s:Math.round(c*100),l:Math.round(d*100)}}function ke(a,u,h){const p=u/100,t=h/100,i=(1-Math.abs(2*t-1))*p,r=i*(1-Math.abs(a/60%2-1)),x=t-i/2;let d=0,o=0,c=0;return a<60?[d,o,c]=[i,r,0]:a<120?[d,o,c]=[r,i,0]:a<180?[d,o,c]=[0,i,r]:a<240?[d,o,c]=[0,r,i]:a<300?[d,o,c]=[r,0,i]:[d,o,c]=[i,0,r],{r:Math.round((d+x)*255),g:Math.round((o+x)*255),b:Math.round((c+x)*255)}}function ye(a,u,h){const p=a/255,t=u/255,i=h/255,r=Math.max(p,t,i),x=Math.min(p,t,i),d=r-x;let o=0;d!==0&&(r===p?o=(t-i)/d%6:r===t?o=(i-p)/d+2:o=(p-t)/d+4,o*=60,o<0&&(o+=360));const c=r===0?0:d/r;return{h:Math.round(o),s:Math.round(c*100),v:Math.round(r*100)}}function Ne(a,u,h){const p=u/100,t=h/100,i=t*p,r=i*(1-Math.abs(a/60%2-1)),x=t-i;let d=0,o=0,c=0;return a<60?[d,o,c]=[i,r,0]:a<120?[d,o,c]=[r,i,0]:a<180?[d,o,c]=[0,i,r]:a<240?[d,o,c]=[0,r,i]:a<300?[d,o,c]=[r,0,i]:[d,o,c]=[i,0,r],{r:Math.round((d+x)*255),g:Math.round((o+x)*255),b:Math.round((c+x)*255)}}function je(a){let u=a.trim();const h=/var\([^,]+,\s*(#[0-9a-fA-F]{3,8})\s*\)/.exec(u);h&&(u=h[1]);const p=/^#?([0-9a-f]{3})$/i.exec(u);p&&(u=`#${p[1].split("").map(r=>r+r).join("")}`);const t=/^#?([0-9a-f]{6})$/i.exec(u),i=/^#?([0-9a-f]{8})$/i.exec(u);if(i){const r=i[1];return{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16),a:parseInt(r.slice(6,8),16)/255}}if(t){const r=parseInt(t[1],16);return{r:r>>16&255,g:r>>8&255,b:r&255,a:1}}return{r:0,g:0,b:0,a:1}}function Me(a,u,h,p,t){const i=x=>Math.max(0,Math.min(255,Math.round(x))).toString(16).padStart(2,"0"),r=`#${i(a)}${i(u)}${i(h)}`;return t?`${r}${i(p*255)}`:r}const Pe=Object.assign(k.forwardRef(({label:a,helperText:u,error:h,required:p,disabled:t,id:i,className:r,style:x,accessMode:d,displayStyle:o,value:c="#3b82f6",onChange:_,presets:B=ge,showInput:X=!1,showRandom:Y=!1,withAlpha:S=!1,compact:I=!1,showKeyboardHints:J,size:Q="md",labelPlacement:Z,errorPlacement:T,labelWidth:L,controlWidth:D,loading:O},F)=>{const A=M.useNiceAccessMode(d,i),W=A==="hidden";(A==="disabled"||A==="readOnly")&&(t=!0);const{t:v}=M.useNiceTranslation(),$=M.useControlId(i);M.useComponentDisplayClass("input",o);const ee=k.useCallback(()=>{t||_?.(ve())},[t,_]),[P,C]=k.useState(!1),[q,te]=k.useState(null),[K,re]=k.useState(""),ne=k.useContext(M.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),U=k.useRef(null),E=k.useRef(null);k.useLayoutEffect(()=>{if(!P||!E.current)return;re(fe.scopeThemeClass(E.current));const m=()=>{const l=E.current?.getBoundingClientRect();if(!l)return;const N=280,w=360;let b=l.left,j=l.bottom+6;b+N>window.innerWidth-8&&(b=Math.max(8,window.innerWidth-N-8)),j+w>window.innerHeight-8&&(j=Math.max(8,l.top-w-6)),te({left:b,top:j})};return m(),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[P]),k.useEffect(()=>{if(!P)return;const m=l=>{const N=l.target;U.current?.contains(N)||E.current?.contains(N)||C(!1)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[P]),M.useOverlayFocus(U,{open:P,modal:!1,onClose:()=>C(!1)});const V=k.useRef(null);M.useRovingFocus(V,{orientation:"grid",itemSelector:".nice-color-picker__preset",wrap:!0});const ie=k.useMemo(()=>[{key:"Enter",description:v("shortcuts.openPicker","Open color picker")},{key:"Arrow keys",description:v("shortcuts.navigatePresets","Navigate presets")}],[v]);return W?null:n.jsxs("div",{className:`nice-field nice-field--${Q} ${Z==="left"?"nice-field--label-left":""} ${I?"nice-color-picker--compact":""} ${O?"nice-field--loading":""} ${r||""}`,style:{...x,...L!=null&&{"--nice-field-label-width":typeof L=="number"?`${L}px`:L},...D!=null&&{"--nice-field-control-width":typeof D=="number"?`${D}px`:D}},"aria-busy":O||void 0,children:[a&&n.jsxs("label",{htmlFor:$,className:`nice-field__label ${p?"nice-field__label--required":""}`,children:[a,J&&n.jsx(M.NiceKeyboardHint,{shortcuts:ie,size:"sm"})]}),n.jsx("div",{className:"nice-field__control",children:n.jsxs("div",{className:"nice-color-picker",children:[n.jsxs("div",{className:"nice-color-picker__preview-row",children:[n.jsx("div",{ref:E,className:"nice-color-picker__swatch",id:$,style:{background:c},onClick:m=>{m.stopPropagation(),t||C(l=>!l)},onKeyDown:m=>{!t&&(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),C(l=>!l))},role:"button",tabIndex:t?-1:0,"aria-disabled":t||void 0,"aria-label":v("colorPicker.openPalette","Open color palette"),"aria-haspopup":"dialog","aria-expanded":P,children:n.jsx("input",{ref:m=>{typeof F=="function"?F(m):F&&(F.current=m)},type:"hidden",value:c,disabled:t,readOnly:!0})}),X&&n.jsx("div",{className:"nice-input nice-input--sm",style:I?{flex:1,minWidth:0}:{width:100},children:n.jsx("input",{className:"nice-input__native",type:"text",value:c,disabled:t,onChange:m=>_?.(m.target.value),maxLength:S?9:7,"aria-label":v("colorPicker.hexValue","Hex value")})}),Y&&!I&&n.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-color-picker__random",onClick:ee,disabled:t,title:v("colorPicker.random","Random"),"aria-label":v("colorPicker.random","Random"),style:{fontSize:"0.65rem",textTransform:"uppercase",letterSpacing:"0.05em"},children:v("colorPicker.random","Random")}),O&&n.jsx("span",{className:"nice-field__spinner",children:n.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),T==="right"&&h&&n.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:h}),T==="right"&&!h&&u&&n.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:u})]}),P&&q&&typeof document<"u"&&he.createPortal(n.jsx("div",{ref:U,className:`nice-color-picker__popup nice-color-picker__popup--portal ${K}`,"data-theme":K==="nice-dark"?"dark":K==="nice-light"?"light":void 0,role:"dialog","aria-label":v("colorPicker.palette","Color palette"),style:{position:"fixed",left:q.left,top:q.top},onClick:m=>m.stopPropagation(),children:(()=>{const m=je(c),l={r:m.r,g:m.g,b:m.b},N=S?m.a:1,w=_e(l.r,l.g,l.b),b=ye(l.r,l.g,l.b),j=(e,f,g,s=N)=>_?.(Me(e,f,g,s,S)),oe=(e,f,g)=>j(e,f,g),se=(e,f,g)=>{const s=ke(e,f,g);j(s.r,s.g,s.b)},z=(e,f,g)=>{const s=Ne(e,f,g);j(s.r,s.g,s.b)},G=e=>j(l.r,l.g,l.b,e),ae=e=>{if(t)return;const f=e.currentTarget,g=y=>{const R=f.getBoundingClientRect(),ue=Math.max(0,Math.min(R.width,y.clientX-R.left)),pe=Math.max(0,Math.min(R.height,y.clientY-R.top)),de=Math.round(ue/R.width*100),me=100-Math.round(pe/R.height*100);z(b.h,de,me)};g(e);const s=()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",s)};document.addEventListener("pointermove",g),document.addEventListener("pointerup",s)},ce=`hsl(${b.h}, 100%, 50%)`,le=e=>{if(t)return;const f=e.shiftKey?10:1;let{s:g,v:s}=b;if(e.key==="ArrowLeft")g-=f;else if(e.key==="ArrowRight")g+=f;else if(e.key==="ArrowDown")s-=f;else if(e.key==="ArrowUp")s+=f;else if(e.key==="PageDown")s-=10;else if(e.key==="PageUp")s+=10;else if(e.key==="Home")g=0;else if(e.key==="End")g=100;else return;e.preventDefault(),z(b.h,Math.max(0,Math.min(100,g)),Math.max(0,Math.min(100,s)))},H={h:v("colorPicker.hue","Hue"),s:v("colorPicker.saturation","Saturation"),l:v("colorPicker.lightness","Lightness"),r:v("colorPicker.red","Red"),g:v("colorPicker.green","Green"),b:v("colorPicker.blue","Blue")};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"nice-color-picker__popup-header",children:n.jsx("input",{type:"text",className:"nice-input__native nice-color-picker__popup-hex",value:c,disabled:t,onChange:e=>_?.(e.target.value),maxLength:S?9:7,"aria-label":v("colorPicker.hexValue","Hex value")})}),n.jsx("input",{type:"range",min:0,max:360,value:b.h,disabled:t,onChange:e=>z(Number(e.target.value),b.s,b.v),className:"nice-color-picker__hue-slider","aria-label":v("colorPicker.hue","Hue")}),n.jsx("div",{className:"nice-color-picker__sv",style:{background:`linear-gradient(to top, var(--nice-text, #000), transparent), linear-gradient(to right, var(--nice-bg, #FFF), ${ce})`},onPointerDown:ae,onKeyDown:le,role:"slider",tabIndex:t?-1:0,"aria-label":v("colorPicker.svPalette","Saturation/value palette"),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":b.s,"aria-valuetext":`${H.s} ${b.s}%, ${v("colorPicker.brightness","Brightness")} ${b.v}%`,children:n.jsx("span",{className:"nice-color-picker__sv-marker",style:{left:`${b.s}%`,top:`${100-b.v}%`}})}),n.jsxs("div",{className:"nice-color-picker__sliders",children:[n.jsx("div",{className:"nice-color-picker__slider-col",children:["h","s","l"].map(e=>{const f=e==="h"?360:100,g=w[e],s=y=>se(e==="h"?y:w.h,e==="s"?y:w.s,e==="l"?y:w.l);return n.jsxs("div",{className:"nice-color-picker__slider-row",children:[n.jsx("label",{className:"nice-color-picker__slider-label",children:e.toUpperCase()}),n.jsx("input",{type:"range",min:0,max:f,value:g,disabled:t,onChange:y=>s(Number(y.target.value)),"aria-label":H[e]}),n.jsx("input",{type:"number",min:0,max:f,value:g,disabled:t,onChange:y=>s(Number(y.target.value)||0),className:"nice-input__native nice-color-picker__slider-num","aria-label":H[e]})]},e)})}),n.jsx("div",{className:"nice-color-picker__slider-col",children:["r","g","b"].map(e=>{const f=l[e],g=s=>oe(e==="r"?s:l.r,e==="g"?s:l.g,e==="b"?s:l.b);return n.jsxs("div",{className:"nice-color-picker__slider-row",children:[n.jsx("label",{className:"nice-color-picker__slider-label",children:e.toUpperCase()}),n.jsx("input",{type:"range",min:0,max:255,value:f,disabled:t,onChange:s=>g(Number(s.target.value)),"aria-label":H[e]}),n.jsx("input",{type:"number",min:0,max:255,value:f,disabled:t,onChange:s=>g(Number(s.target.value)||0),className:"nice-input__native nice-color-picker__slider-num","aria-label":H[e]})]},e)})})]}),S&&n.jsxs("div",{className:"nice-color-picker__alpha-row",children:[n.jsx("label",{className:"nice-color-picker__slider-label",children:"A"}),n.jsx("input",{type:"range",min:0,max:100,value:Math.round(N*100),disabled:t,onChange:e=>G(Number(e.target.value)/100),className:"nice-color-picker__alpha-slider",style:{background:`linear-gradient(to right, transparent, rgb(${l.r},${l.g},${l.b}))`},"aria-label":v("colorPicker.alpha","Alpha")}),n.jsx("input",{type:"number",min:0,max:100,value:Math.round(N*100),disabled:t,onChange:e=>G((Number(e.target.value)||0)/100),className:"nice-input__native nice-color-picker__slider-num","aria-label":v("colorPicker.alpha","Alpha")})]}),B.length>0&&n.jsx("div",{ref:V,className:"nice-color-picker__popup-presets",role:"group","aria-label":v("colorPicker.presets","Preset colors"),children:B.map(e=>n.jsx("div",{className:`nice-color-picker__preset ${c===e?"nice-color-picker__preset--active":""}`,style:{background:e},onClick:()=>{_?.(e),C(!1)},role:"button","aria-label":e,"aria-pressed":c===e,onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),_?.(e),C(!1))}},e))})]})})()}),ne??document.body)]})}),T!=="right"&&h&&n.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:h}),T!=="right"&&!h&&u&&n.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:u})]})}),{displayName:"NiceColorPicker"});exports.NiceColorPicker=Pe;exports.hexToRgb=xe;exports.rgbToHex=be;
@@ -1,4 +1,4 @@
1
- "use strict";const t=require("react/jsx-runtime"),v=require("@nice2dev/ui-core"),r=require("react"),pn=require("react-dom"),Vi=require("./devops-o6Zm0VKB.cjs"),Ui=require("./NicePagination-CnKYyKI5.cjs"),ys=require("./no-code-DPc82kyy.cjs"),Hi=require("./NiceForm-DM2tARZT.cjs"),Ji=require("./NiceAlert-RVTgQxCE.cjs"),Yi=require("./NiceModal-BRVzjuUN.cjs"),Xi=[],Qi=[{target:".nice-filterbuilder",titleKey:"tutorial.filterBuilder.intro.title",title:"Filter builder",contentKey:"tutorial.filterBuilder.intro.content",content:"Build complex AND/OR filter trees: add conditions and nested groups, choose fields and operators, and save reusable presets.",placement:"auto"}],Zi=[{value:"=",label:"Equals"},{value:"<>",label:"Not Equals"},{value:"<",label:"Less Than"},{value:"<=",label:"Less or Equal"},{value:">",label:"Greater Than"},{value:">=",label:"Greater or Equal"},{value:"contains",label:"Contains"},{value:"notcontains",label:"Not Contains"},{value:"startswith",label:"Starts With"},{value:"endswith",label:"Ends With"},{value:"isblank",label:"Is Blank"},{value:"isnotblank",label:"Is Not Blank"}],ea=({condition:l,fields:x,onChange:f,onRemove:y})=>{const{t:b}=v.useNiceTranslation(),h=x.find(g=>g.field===l.field),N=l.operator==="isblank"||l.operator==="isnotblank",C=h?.operators||Zi;return t.jsxs("div",{className:"nice-filterbuilder__condition",children:[t.jsx("select",{className:"nice-filterbuilder__select",value:l.field,onChange:g=>f({...l,field:g.target.value,value:""}),children:x.map(g=>t.jsx("option",{value:g.field,children:g.label},g.field))}),t.jsx("select",{className:"nice-filterbuilder__select",value:l.operator,onChange:g=>f({...l,operator:g.target.value}),children:C.map(g=>t.jsx("option",{value:g.value,children:g.label},g.value))}),!N&&(h?.options?t.jsxs("select",{className:"nice-filterbuilder__select",value:String(l.value??""),onChange:g=>f({...l,value:g.target.value}),children:[t.jsx("option",{value:"",children:"--"}),h.options.map(g=>t.jsx("option",{value:g.value,children:g.label},g.value))]}):h?.type==="boolean"?t.jsxs("select",{className:"nice-filterbuilder__select",value:String(l.value??""),onChange:g=>f({...l,value:g.target.value==="true"}),children:[t.jsx("option",{value:"true",children:b("filterBuilder.true","True")}),t.jsx("option",{value:"false",children:b("filterBuilder.false","False")})]}):t.jsx("input",{className:"nice-filterbuilder__input",type:h?.type==="number"?"number":h?.type==="date"?"date":"text",value:String(l.value??""),onChange:g=>f({...l,value:h?.type==="number"?Number(g.target.value):g.target.value})})),t.jsx("button",{"aria-label":b("filterBuilder.close","Close"),className:"nice-filterbuilder__remove",onClick:y,children:t.jsx(v.NiceIcon,{name:"close",size:14})})]})},vs=({group:l,fields:x,onChange:f,onRemove:y,depth:b,maxDepth:h})=>{const{t:N}=v.useNiceTranslation(),[C,g]=r.useState(!1),q=()=>f({...l,logic:l.logic==="and"?"or":"and"}),F=l.items.filter(S=>S.type==="condition").length,T=l.items.length-F,de=[F?`${F} condition${F>1?"s":""}`:"",T?`${T} group${T>1?"s":""}`:""].filter(Boolean).join(" · ")||"empty",ue=()=>{const S={type:"condition",field:x[0]?.field||"",operator:"=",value:""};f({...l,items:[...l.items,S]})},fe=()=>{if(b>=h)return;const S={type:"group",logic:"and",items:[]};f({...l,items:[...l.items,S]})},M=(S,R)=>{const w=[...l.items];w[S]=R,f({...l,items:w})},te=S=>{f({...l,items:l.items.filter((R,w)=>w!==S)})};return t.jsxs("div",{className:`nice-filterbuilder__group nice-filterbuilder__group--depth-${Math.min(b,3)}`,children:[t.jsxs("div",{className:"nice-filterbuilder__group-header",children:[t.jsx("button",{type:"button",className:"nice-filterbuilder__collapse",onClick:()=>g(S=>!S),"aria-expanded":!C,title:C?N("filterBuilder.expandGroup","Expand group"):N("filterBuilder.collapseGroup","Collapse group"),children:t.jsx(v.NiceIcon,{name:C?"chevron-right":"chevron-down",size:"sm"})}),t.jsx("button",{className:"nice-filterbuilder__logic",onClick:q,title:N("filterBuilder.matchClickToSwitch","Match {mode} — click to switch to {other}").replace("{mode}",l.logic==="and"?N("filterBuilder.matchAll","ALL"):N("filterBuilder.matchAny","ANY")).replace("{other}",l.logic==="and"?"OR":"AND"),children:l.logic.toUpperCase()}),C?t.jsx("span",{className:"nice-filterbuilder__summary",children:de}):t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"nice-btn nice-btn--sm",onClick:ue,children:N("filterBuilder.condition","+ Condition")}),b<h&&t.jsx("button",{className:"nice-btn nice-btn--sm",onClick:fe,children:N("filterBuilder.group","+ Group")})]}),y&&t.jsx("button",{"aria-label":N("filterBuilder.close","Close"),className:"nice-filterbuilder__remove",onClick:y,children:t.jsx(v.NiceIcon,{name:"close",size:14})})]}),!C&&t.jsx("div",{className:"nice-filterbuilder__group-body",children:l.items.map((S,R)=>t.jsx(r.Fragment,{children:S.type==="condition"?t.jsx(ea,{condition:S,fields:x,onChange:w=>M(R,w),onRemove:()=>te(R)}):t.jsx(vs,{group:S,fields:x,onChange:w=>M(R,w),onRemove:()=>te(R),depth:b+1,maxDepth:h})},R))})]})},xn=({fields:l=Xi,value:x,defaultValue:f,onChange:y,maxDepth:b=3,presets:h,onSavePreset:N,onDeletePreset:C,tutorial:g,className:q,style:F,"data-testid":T})=>{const{t:de}=v.useNiceTranslation(),[ue,fe]=v.useControllableState({value:x,defaultValue:f,fallbackValue:{type:"group",logic:"and",items:[]},onChange:y,componentName:"NiceFilterBuilder"}),[M,te]=r.useState(""),S=r.useCallback(w=>{const Qe=h?.find(ze=>ze.name===w);Qe&&fe(structuredClone(Qe.filter))},[h,fe]),R=r.useCallback(()=>{!M.trim()||!N||(N({name:M.trim(),filter:structuredClone(ue)}),te(""))},[M,ue,N]);return t.jsxs("div",{className:`nice-filterbuilder ${q||""}`,style:{position:"relative",...F},"data-testid":T,children:[t.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:t.jsx(v.NiceTutorialButton,{steps:v.resolveTutorial(g,Qi)})}),(h?.length||N)&&t.jsxs("div",{className:"nice-filterbuilder__presets",children:[h&&h.length>0&&t.jsx("div",{className:"nice-filterbuilder__preset-list",children:h.map(w=>t.jsxs("span",{className:"nice-filterbuilder__preset-tag",children:[t.jsx("button",{type:"button",className:"nice-filterbuilder__preset-btn",onClick:()=>S(w.name),children:w.name}),C&&t.jsx("button",{"aria-label":de("filterBuilder.close","Close"),type:"button",className:"nice-filterbuilder__preset-del",onClick:()=>C(w.name),children:t.jsx(v.NiceIcon,{name:"close",size:14})})]},w.name))}),N&&t.jsxs("div",{className:"nice-filterbuilder__preset-save",children:[t.jsx("input",{className:"nice-filterbuilder__input",value:M,onChange:w=>te(w.target.value),placeholder:de("filterBuilder.presetName","Preset name...")}),t.jsx("button",{className:"nice-btn nice-btn--sm",onClick:R,disabled:!M.trim(),children:de("filterBuilder.save","Save")})]})]}),t.jsx(vs,{group:ue,fields:l,onChange:fe,depth:0,maxDepth:b})]})};process.env.NODE_ENV!=="production"&&(xn.displayName="NiceFilterBuilder");const js="nice-datagrid-";function mn(l){if(typeof window>"u")return null;try{const x=window.localStorage.getItem(js+l);return x?JSON.parse(x):null}catch{return null}}function _s(l,x){if(!(typeof window>"u"))try{window.localStorage.setItem(js+l,x)}catch{}}function Ns(l){const x={};return Object.keys(l.columnWidths).length>0&&(x.columnWidths=l.columnWidths),l.columnOrder&&l.columnOrder.length>0&&(x.columnOrder=l.columnOrder),l.hiddenColumns&&l.hiddenColumns.length>0&&(x.hiddenColumns=l.hiddenColumns),l.sortField&&l.sortDirection&&(x.sortField=l.sortField,x.sortDirection=l.sortDirection),l.pageSize!==void 0&&(x.pageSize=l.pageSize),l.expandedGroups.size>0&&(x.expandedGroups=Array.from(l.expandedGroups)),x}function Cs(l,x,f){const y=l.map(b=>b[x]).filter(b=>typeof b=="number");if(y.length===0)return f==="count"?"0":"";switch(f){case"sum":return y.reduce((b,h)=>b+h,0).toLocaleString();case"avg":return(y.reduce((b,h)=>b+h,0)/y.length).toLocaleString(void 0,{maximumFractionDigits:2});case"count":return String(l.length);case"min":return Math.min(...y).toLocaleString();case"max":return Math.max(...y).toLocaleString()}}function Ss(l,x){const f=/^([^#0,.]*)([#0,]+(?:\.[#0]+)?)(.*)$/.exec(x);if(!f)return String(l);const[,y,b,h]=f,[N,C=""]=b.split("."),g=new Intl.NumberFormat(void 0,{useGrouping:N.includes(","),minimumIntegerDigits:Math.min(21,Math.max(1,(N.match(/0/g)??[]).length)),minimumFractionDigits:(C.match(/0/g)??[]).length,maximumFractionDigits:C.length}).format(l);return`${y}${g}${h}`}function gn(l,x,f=40){let y=f;return l.querySelectorAll(`[data-field="${x.replace(/["\\]/g,"\\$&")}"]`).forEach(h=>{let N=h.scrollWidth;const C=typeof document.createRange=="function"?document.createRange():null;if(C&&typeof C.getBoundingClientRect=="function"){C.selectNodeContents(h);const g=C.getBoundingClientRect().width;if(g>0){const q=window.getComputedStyle(h),F=(parseFloat(q.paddingLeft)||0)+(parseFloat(q.paddingRight)||0);N=Math.ceil(g+F)}}y=Math.max(y,N)}),y}function hn(l,x){const f=new Map(l.map(b=>[b.field,b])),y=[];for(const b of x){const h=f.get(b);h&&(y.push(h),f.delete(b))}return[...y,...l.filter(b=>f.has(b.field))]}function ws(l,x){const f=[];for(const y of l){const b=x.find(N=>N.columns.includes(y))??null,h=f[f.length-1];h&&h.group===b?h.span+=1:f.push({group:b,span:1})}return f}function Xe(l){return l.includes(",")||l.includes('"')||l.includes(`
1
+ "use strict";const t=require("react/jsx-runtime"),v=require("@nice2dev/ui-core"),r=require("react"),pn=require("react-dom"),Vi=require("./devops-o6Zm0VKB.cjs"),Ui=require("./NicePagination-CnKYyKI5.cjs"),ys=require("./no-code-DPc82kyy.cjs"),Hi=require("./NiceForm-B8dX4aLD.cjs"),Ji=require("./NiceAlert-RVTgQxCE.cjs"),Yi=require("./NiceModal-BRVzjuUN.cjs"),Xi=[],Qi=[{target:".nice-filterbuilder",titleKey:"tutorial.filterBuilder.intro.title",title:"Filter builder",contentKey:"tutorial.filterBuilder.intro.content",content:"Build complex AND/OR filter trees: add conditions and nested groups, choose fields and operators, and save reusable presets.",placement:"auto"}],Zi=[{value:"=",label:"Equals"},{value:"<>",label:"Not Equals"},{value:"<",label:"Less Than"},{value:"<=",label:"Less or Equal"},{value:">",label:"Greater Than"},{value:">=",label:"Greater or Equal"},{value:"contains",label:"Contains"},{value:"notcontains",label:"Not Contains"},{value:"startswith",label:"Starts With"},{value:"endswith",label:"Ends With"},{value:"isblank",label:"Is Blank"},{value:"isnotblank",label:"Is Not Blank"}],ea=({condition:l,fields:x,onChange:f,onRemove:y})=>{const{t:b}=v.useNiceTranslation(),h=x.find(g=>g.field===l.field),N=l.operator==="isblank"||l.operator==="isnotblank",C=h?.operators||Zi;return t.jsxs("div",{className:"nice-filterbuilder__condition",children:[t.jsx("select",{className:"nice-filterbuilder__select",value:l.field,onChange:g=>f({...l,field:g.target.value,value:""}),children:x.map(g=>t.jsx("option",{value:g.field,children:g.label},g.field))}),t.jsx("select",{className:"nice-filterbuilder__select",value:l.operator,onChange:g=>f({...l,operator:g.target.value}),children:C.map(g=>t.jsx("option",{value:g.value,children:g.label},g.value))}),!N&&(h?.options?t.jsxs("select",{className:"nice-filterbuilder__select",value:String(l.value??""),onChange:g=>f({...l,value:g.target.value}),children:[t.jsx("option",{value:"",children:"--"}),h.options.map(g=>t.jsx("option",{value:g.value,children:g.label},g.value))]}):h?.type==="boolean"?t.jsxs("select",{className:"nice-filterbuilder__select",value:String(l.value??""),onChange:g=>f({...l,value:g.target.value==="true"}),children:[t.jsx("option",{value:"true",children:b("filterBuilder.true","True")}),t.jsx("option",{value:"false",children:b("filterBuilder.false","False")})]}):t.jsx("input",{className:"nice-filterbuilder__input",type:h?.type==="number"?"number":h?.type==="date"?"date":"text",value:String(l.value??""),onChange:g=>f({...l,value:h?.type==="number"?Number(g.target.value):g.target.value})})),t.jsx("button",{"aria-label":b("filterBuilder.close","Close"),className:"nice-filterbuilder__remove",onClick:y,children:t.jsx(v.NiceIcon,{name:"close",size:14})})]})},vs=({group:l,fields:x,onChange:f,onRemove:y,depth:b,maxDepth:h})=>{const{t:N}=v.useNiceTranslation(),[C,g]=r.useState(!1),q=()=>f({...l,logic:l.logic==="and"?"or":"and"}),F=l.items.filter(S=>S.type==="condition").length,T=l.items.length-F,de=[F?`${F} condition${F>1?"s":""}`:"",T?`${T} group${T>1?"s":""}`:""].filter(Boolean).join(" · ")||"empty",ue=()=>{const S={type:"condition",field:x[0]?.field||"",operator:"=",value:""};f({...l,items:[...l.items,S]})},fe=()=>{if(b>=h)return;const S={type:"group",logic:"and",items:[]};f({...l,items:[...l.items,S]})},M=(S,R)=>{const w=[...l.items];w[S]=R,f({...l,items:w})},te=S=>{f({...l,items:l.items.filter((R,w)=>w!==S)})};return t.jsxs("div",{className:`nice-filterbuilder__group nice-filterbuilder__group--depth-${Math.min(b,3)}`,children:[t.jsxs("div",{className:"nice-filterbuilder__group-header",children:[t.jsx("button",{type:"button",className:"nice-filterbuilder__collapse",onClick:()=>g(S=>!S),"aria-expanded":!C,title:C?N("filterBuilder.expandGroup","Expand group"):N("filterBuilder.collapseGroup","Collapse group"),children:t.jsx(v.NiceIcon,{name:C?"chevron-right":"chevron-down",size:"sm"})}),t.jsx("button",{className:"nice-filterbuilder__logic",onClick:q,title:N("filterBuilder.matchClickToSwitch","Match {mode} — click to switch to {other}").replace("{mode}",l.logic==="and"?N("filterBuilder.matchAll","ALL"):N("filterBuilder.matchAny","ANY")).replace("{other}",l.logic==="and"?"OR":"AND"),children:l.logic.toUpperCase()}),C?t.jsx("span",{className:"nice-filterbuilder__summary",children:de}):t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"nice-btn nice-btn--sm",onClick:ue,children:N("filterBuilder.condition","+ Condition")}),b<h&&t.jsx("button",{className:"nice-btn nice-btn--sm",onClick:fe,children:N("filterBuilder.group","+ Group")})]}),y&&t.jsx("button",{"aria-label":N("filterBuilder.close","Close"),className:"nice-filterbuilder__remove",onClick:y,children:t.jsx(v.NiceIcon,{name:"close",size:14})})]}),!C&&t.jsx("div",{className:"nice-filterbuilder__group-body",children:l.items.map((S,R)=>t.jsx(r.Fragment,{children:S.type==="condition"?t.jsx(ea,{condition:S,fields:x,onChange:w=>M(R,w),onRemove:()=>te(R)}):t.jsx(vs,{group:S,fields:x,onChange:w=>M(R,w),onRemove:()=>te(R),depth:b+1,maxDepth:h})},R))})]})},xn=({fields:l=Xi,value:x,defaultValue:f,onChange:y,maxDepth:b=3,presets:h,onSavePreset:N,onDeletePreset:C,tutorial:g,className:q,style:F,"data-testid":T})=>{const{t:de}=v.useNiceTranslation(),[ue,fe]=v.useControllableState({value:x,defaultValue:f,fallbackValue:{type:"group",logic:"and",items:[]},onChange:y,componentName:"NiceFilterBuilder"}),[M,te]=r.useState(""),S=r.useCallback(w=>{const Qe=h?.find(ze=>ze.name===w);Qe&&fe(structuredClone(Qe.filter))},[h,fe]),R=r.useCallback(()=>{!M.trim()||!N||(N({name:M.trim(),filter:structuredClone(ue)}),te(""))},[M,ue,N]);return t.jsxs("div",{className:`nice-filterbuilder ${q||""}`,style:{position:"relative",...F},"data-testid":T,children:[t.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:t.jsx(v.NiceTutorialButton,{steps:v.resolveTutorial(g,Qi)})}),(h?.length||N)&&t.jsxs("div",{className:"nice-filterbuilder__presets",children:[h&&h.length>0&&t.jsx("div",{className:"nice-filterbuilder__preset-list",children:h.map(w=>t.jsxs("span",{className:"nice-filterbuilder__preset-tag",children:[t.jsx("button",{type:"button",className:"nice-filterbuilder__preset-btn",onClick:()=>S(w.name),children:w.name}),C&&t.jsx("button",{"aria-label":de("filterBuilder.close","Close"),type:"button",className:"nice-filterbuilder__preset-del",onClick:()=>C(w.name),children:t.jsx(v.NiceIcon,{name:"close",size:14})})]},w.name))}),N&&t.jsxs("div",{className:"nice-filterbuilder__preset-save",children:[t.jsx("input",{className:"nice-filterbuilder__input",value:M,onChange:w=>te(w.target.value),placeholder:de("filterBuilder.presetName","Preset name...")}),t.jsx("button",{className:"nice-btn nice-btn--sm",onClick:R,disabled:!M.trim(),children:de("filterBuilder.save","Save")})]})]}),t.jsx(vs,{group:ue,fields:l,onChange:fe,depth:0,maxDepth:b})]})};process.env.NODE_ENV!=="production"&&(xn.displayName="NiceFilterBuilder");const js="nice-datagrid-";function mn(l){if(typeof window>"u")return null;try{const x=window.localStorage.getItem(js+l);return x?JSON.parse(x):null}catch{return null}}function _s(l,x){if(!(typeof window>"u"))try{window.localStorage.setItem(js+l,x)}catch{}}function Ns(l){const x={};return Object.keys(l.columnWidths).length>0&&(x.columnWidths=l.columnWidths),l.columnOrder&&l.columnOrder.length>0&&(x.columnOrder=l.columnOrder),l.hiddenColumns&&l.hiddenColumns.length>0&&(x.hiddenColumns=l.hiddenColumns),l.sortField&&l.sortDirection&&(x.sortField=l.sortField,x.sortDirection=l.sortDirection),l.pageSize!==void 0&&(x.pageSize=l.pageSize),l.expandedGroups.size>0&&(x.expandedGroups=Array.from(l.expandedGroups)),x}function Cs(l,x,f){const y=l.map(b=>b[x]).filter(b=>typeof b=="number");if(y.length===0)return f==="count"?"0":"";switch(f){case"sum":return y.reduce((b,h)=>b+h,0).toLocaleString();case"avg":return(y.reduce((b,h)=>b+h,0)/y.length).toLocaleString(void 0,{maximumFractionDigits:2});case"count":return String(l.length);case"min":return Math.min(...y).toLocaleString();case"max":return Math.max(...y).toLocaleString()}}function Ss(l,x){const f=/^([^#0,.]*)([#0,]+(?:\.[#0]+)?)(.*)$/.exec(x);if(!f)return String(l);const[,y,b,h]=f,[N,C=""]=b.split("."),g=new Intl.NumberFormat(void 0,{useGrouping:N.includes(","),minimumIntegerDigits:Math.min(21,Math.max(1,(N.match(/0/g)??[]).length)),minimumFractionDigits:(C.match(/0/g)??[]).length,maximumFractionDigits:C.length}).format(l);return`${y}${g}${h}`}function gn(l,x,f=40){let y=f;return l.querySelectorAll(`[data-field="${x.replace(/["\\]/g,"\\$&")}"]`).forEach(h=>{let N=h.scrollWidth;const C=typeof document.createRange=="function"?document.createRange():null;if(C&&typeof C.getBoundingClientRect=="function"){C.selectNodeContents(h);const g=C.getBoundingClientRect().width;if(g>0){const q=window.getComputedStyle(h),F=(parseFloat(q.paddingLeft)||0)+(parseFloat(q.paddingRight)||0);N=Math.ceil(g+F)}}y=Math.max(y,N)}),y}function hn(l,x){const f=new Map(l.map(b=>[b.field,b])),y=[];for(const b of x){const h=f.get(b);h&&(y.push(h),f.delete(b))}return[...y,...l.filter(b=>f.has(b.field))]}function ws(l,x){const f=[];for(const y of l){const b=x.find(N=>N.columns.includes(y))??null,h=f[f.length-1];h&&h.group===b?h.span+=1:f.push({group:b,span:1})}return f}function Xe(l){return l.includes(",")||l.includes('"')||l.includes(`
2
2
  `)?`"${l.replace(/"/g,'""')}"`:l}const ta=[];function ks(l,x){return l.filter(f=>!f.hidden&&f.field!==x).map(f=>{let y="text";return f.dataType==="number"||f.dataType==="currency"||f.dataType==="percent"?y="number":f.dataType==="boolean"?y="checkbox":f.dataType==="date"&&(y="date"),{field:f.field,label:f.header,type:y,required:f.validation?.required}})}function Ms({isNew:l=!1,title:x,items:f=ta,data:y,columns:b=2,formProps:h,onFieldChange:N,onSubmit:C,onClose:g,error:q,saving:F=!1}){const{t:T}=v.useNiceTranslation();return t.jsxs(Yi.NiceModal,{open:!0,onClose:g,title:x??(l?T("datagrid.addRow","Add row"):T("datagrid.editRow","Edit row")),size:"lg",children:[q?t.jsx(Ji.NiceAlert,{variant:"error",children:q}):null,t.jsx(Hi.NiceForm,{items:f,data:y,columns:b,showActions:!0,submitLabel:l?T("controls.add","Add"):T("controls.save","Save"),cancelLabel:T("controls.cancel","Cancel"),onCancel:g,...h,disabled:F||h?.disabled,onFieldChange:N,onSubmit:C})]})}const be={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},na=()=>t.jsx("svg",{...be,children:t.jsx("polyline",{points:"6 15 12 9 18 15"})}),Je=()=>t.jsx("svg",{...be,children:t.jsx("polyline",{points:"6 9 12 15 18 9"})}),sa=()=>t.jsxs("svg",{...be,style:{opacity:.55},children:[t.jsx("polyline",{points:"6 10 12 5 18 10"}),t.jsx("polyline",{points:"6 14 12 19 18 14"})]}),jt=()=>t.jsx("svg",{...be,children:t.jsx("polyline",{points:"9 6 15 12 9 18"})}),ia=()=>t.jsxs("svg",{...be,children:[t.jsx("polyline",{points:"3 17 9 11 13 15 21 7"}),t.jsx("polyline",{points:"14 7 21 7 21 14"})]}),aa=()=>t.jsxs("svg",{...be,children:[t.jsx("polyline",{points:"3 7 9 13 13 9 21 17"}),t.jsx("polyline",{points:"14 17 21 17 21 10"})]}),ra=()=>t.jsx("svg",{...be,children:t.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})}),la=40,Ye=l=>l.stopPropagation(),oa=[];function ca(l){return typeof l=="boolean"?l?t.jsx(v.NiceIcon,{name:"check",size:16,className:"nice-datagrid__bool-icon nice-datagrid__bool-icon--true",title:"true"}):t.jsx(v.NiceIcon,{name:"close",size:16,className:"nice-datagrid__bool-icon nice-datagrid__bool-icon--false",title:"false"}):String(l??"")}function bn({columns:l=oa,data:x,keyField:f="id",dataSource:y,sortable:b=!0,sortField:h,sortDirection:N,onSort:C,showAdvancedFilter:g,advancedFilter:q,onAdvancedFilterChange:F,filterFields:T,filterPresets:de,onSaveFilterPreset:ue,onDeleteFilterPreset:fe,selectable:M,selectedKeys:te,onSelectionChange:S,pagination:R,pageSize:w=10,page:Qe,onPageChange:ze,totalRows:yn,autoPagination:ne=!1,stickyHeader:_t=!0,stickyFooter:Ds=!0,searchable:vn,searchPlaceholder:Is,virtualScroll:Q,rowHeight:V=40,groupBy:Nt,groupRender:Ze,onCellEdit:L,editMode:Re="inline",formItems:zs,formColumns:Rs=2,editFormTitle:Es,formProps:As,onRowEdit:et,onRowAdd:tt,onRowDelete:ye,confirmDelete:nt,bulkActions:Ct,onBulkDelete:St,exportCsv:jn,exportFilename:_n="export",detailRow:U,expandedRowKeys:Ts,onExpandedRowChange:wt,columnReorder:Os,onColumnReorder:Nn,columnResize:kt,rowDraggable:z,onRowReorder:st,striped:$s,compact:Fs,size:Mt,loading:Ls,emptyText:Ps,toolbar:Cn,onRowClick:pe,pinnedTopKeys:Dt,pinnedBottomKeys:It,colSpan:Sn,showStatusBar:Bs,contextMenuItems:it,onContextMenuAction:Gs,printFriendly:Ks,keyboardNavigation:Ee,focusedCell:Ws,onFocusedCellChange:zt,cellRangeSelection:wn,selectedCellRange:qs,onCellRangeChange:Rt,clipboard:me,clipboardFormat:Et="text",onBeforeCopy:kn,onCopy:Mn,onPaste:At,quickFilters:se,activeQuickFilters:Vs,onQuickFilterChange:Tt,columnGroups:Ot,stateStorageKey:J,initialState:Us,onStateChange:Dn,flashRowKeys:$t,flashDuration:In=500,autoFitColumns:Ft,showColumnStats:Ae,rowIndicator:Te,frozenRows:Hs,className:Js,style:Ys,accessMode:Xs,id:Qs,displayStyle:zn,disabled:Zs,readOnly:Rn,error:Lt}){const Pt=v.useNiceAccessMode(Xs,Qs),ei=Pt==="hidden",ve=Zs||Pt==="disabled",Oe=Rn||ve||Pt==="readOnly",ie=!!ye&&!Oe,ge=Math.max(0,Math.floor(Hs??0)),{t:p}=v.useNiceTranslation();v.useComponentDisplayStyle("table",zn),v.useComponentDisplayClass("table",zn);const D=v.useNiceDataSource(y??null,{autoLoad:!!y,defaultPageSize:w}),k=!!y,Bt=r.useMemo(()=>k?D.data:x??[],[k,D.data,x]),at=k?D.loading:Ls,[O]=r.useState(()=>Us??(J?mn(J):null)),[En,An]=r.useState(()=>({field:O?.sortField??"",dir:O?.sortDirection??null})),[ti,ni]=r.useState(1),[si,Gt]=r.useState(new Set),[rt,ii]=r.useState(""),[ai,ri]=r.useState({type:"group",logic:"and",items:[]}),[Tn,On]=r.useState(!1),ae=q??ai,$n=e=>{F?F(e):ri(e)},li=r.useMemo(()=>T??l.filter(e=>e.filterable!==!1&&e.field).map(e=>({field:String(e.field),label:String(e.header??e.field)})),[T,l]),he=ae.items.length,[lt,Fn]=r.useState(O?.pageSize??w),[re,Kt]=r.useState(null),[ot,$e]=r.useState(null),[je,_e]=r.useState(null),[Wt,Ln]=r.useState(()=>new Set(O?.expandedGroups??[])),[qt,oi]=r.useState(0),ct=r.useRef(null),[ci,di]=r.useState(new Set),dt=Ts??ci,[Fe,Vt]=r.useState(()=>O?.columnWidths??{}),[Ne,Ce]=r.useState(null),[Se,Ut]=r.useState(null),[Ht,Jt]=r.useState(null),[ui,fi]=r.useState(null),[pi,mi]=r.useState(null),[gi,hi]=r.useState([]),[we,Yt]=r.useState(null),Xt=r.useRef(null),[ut,Qt]=r.useState(()=>O?.hiddenColumns??[]),[Le,Pn]=r.useState(()=>O?.columnOrder??null),[Zt,en]=r.useState(null),[Bn,ft]=r.useState(null),tn=r.useRef(null),[xi,Gn]=r.useState(new Set),[Pe,nn]=r.useState(null),Kn=r.useRef(null),[bi,yi]=r.useState({}),le=r.useRef(null),[vi,ji]=r.useState(w);r.useEffect(()=>{if(!ne)return;const e=ct.current;if(!e||typeof ResizeObserver>"u")return;const n=()=>{const i=e.clientHeight;if(i<=0)return;const a=Math.max(1,Math.floor(i/V)-1);ji(o=>o===a?o:a),k&&D.setPageSize(a)};n();const s=new ResizeObserver(n);return s.observe(e),()=>s.disconnect()},[ne,V,k]);const K=Ws??ui,P=qs??pi,Y=Vs??gi,Wn=r.useRef(J);r.useEffect(()=>{if(Wn.current===J)return;Wn.current=J;const e=J?mn(J):null;e&&(Vt(e.columnWidths??{}),Ln(new Set(e.expandedGroups??[])),Qt(e.hiddenColumns??[]),Pn(e.columnOrder??null),An({field:e.sortField??"",dir:e.sortDirection??null}),e.pageSize!==void 0&&Fn(e.pageSize))},[J]),r.useEffect(()=>{!k||!O||(O.sortField&&O.sortDirection&&D.setSortField(O.sortField,O.sortDirection),O.pageSize!==void 0&&!ne&&D.setPageSize(O.pageSize))},[]),r.useEffect(()=>{if(!$t?.size)return;Gn(new Set($t));const e=setTimeout(()=>Gn(new Set),In);return()=>clearTimeout(e)},[$t,In]),r.useEffect(()=>{if(!Se)return;const e=()=>Ut(null);return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[Se]);const _i=r.useCallback((e,n)=>{it?.length&&(e.preventDefault(),Ut({x:e.clientX,y:e.clientY,row:n}))},[it]),qn=r.useCallback(e=>{const n=new Set(dt);n.has(e)?n.delete(e):n.add(e),wt?wt(n):di(n)},[dt,wt]),Ni=r.useCallback((e,n)=>{if(!kt)return;n.preventDefault();const s=n.clientX,a=n.target.closest("th")?.offsetWidth??100,o=u=>{const d=Math.max(40,a+u.clientX-s);Vt(_=>({..._,[e]:d}))},c=()=>{document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",c)};document.addEventListener("mousemove",o),document.addEventListener("mouseup",c)},[kt]),X=k?D.sort[0]?.field??"":h??En.field,W=k?D.sort[0]?.direction??null:N??En.dir,ke=k?D.page:Qe??ti,I=te??si,Z=r.useMemo(()=>Le?hn(l,Le):l,[l,Le]),$=r.useMemo(()=>Z.filter(e=>!e.hidden&&!ut.includes(e.field)),[Z,ut]),sn=r.useMemo(()=>$.filter(e=>e.pinned==="left"),[$]),pt=r.useMemo(()=>$.filter(e=>e.pinned==="right"),[$]),Vn=r.useMemo(()=>$.filter(e=>!e.pinned),[$]),j=r.useMemo(()=>[...sn,...Vn,...pt],[sn,Vn,pt]),Ci=r.useMemo(()=>$.some(e=>e.aggregate),[$]),Be=sn.length>0||pt.length>0,an=r.useMemo(()=>{if(!Ot?.length)return null;const e=ws(j.map(n=>n.field),Ot);return e.some(n=>n.group)?e:null},[Ot,j]),Ge=r.useCallback((e,n)=>{k?n?D.setSortField(e,n):D.setSort([]):C?C(e,n):An({field:e,dir:n})},[k,D,C]),Un=r.useCallback(e=>{Ge(e,X===e?W==="asc"?"desc":W==="desc"?null:"asc":"asc")},[X,W,Ge]),B=r.useMemo(()=>{if(k)return Bt;let e=[...Bt];if(rt){const n=rt.toLowerCase();e=e.filter(s=>$.some(i=>String(s[i.field]??"").toLowerCase().includes(n)))}return ae.items.length>0&&(e=e.filter(n=>v.matchesFilterGroup(n,ae))),!C&&X&&W&&e.sort((n,s)=>{const i=n[X]??"",a=s[X]??"",o=typeof i=="number"?i-a:String(i).localeCompare(String(a));return W==="desc"?-o:o}),e},[Bt,rt,ae,$,X,W,C,k]),mt=k?D.totalCount:yn??B.length,oe=ne?vi:k?D.pageSize:lt,rn=Math.max(1,Math.ceil(mt/oe)),H=k?B:R&&!yn?B.slice((ke-1)*oe,ke*oe):B,Ke=r.useCallback(e=>{k?D.setPage(e):ze?ze(e):ni(e)},[k,D,ze]);v.useIntent(["pagePrev","pageNext"],e=>{const n=ke+(e.intent==="pageNext"?1:-1);if(e.source==="keyboard"||n<1||n>rn)return!1;Ke(n)},{ref:le,enabled:!!R}),v.useInputHints(le,[{intent:"pagePrev",label:p("input.intent.pagePrev","Previous page")},{intent:"pageNext",label:p("input.intent.pageNext","Next page")}],{enabled:!!R&&rn>1});const We=JSON.stringify(Ns({columnWidths:Fe,sortField:X,sortDirection:W,pageSize:ne?void 0:oe,expandedGroups:Wt,hiddenColumns:ut,columnOrder:Le??void 0})),Hn=r.useRef(Dn);Hn.current=Dn;const ln=r.useRef(J);ln.current=J;const gt=r.useRef(null),qe=r.useRef(null),ht=r.useCallback(e=>{gt.current=e,qe.current=null,ln.current&&_s(ln.current,e),Hn.current?.(JSON.parse(e))},[]);r.useEffect(()=>{if(gt.current===null){gt.current=We;return}if(We===gt.current){qe.current=null;return}qe.current=We;const e=setTimeout(()=>ht(We),300);return()=>clearTimeout(e)},[We,ht]),r.useEffect(()=>()=>{qe.current!==null&&ht(qe.current)},[ht]);const on=r.useCallback(()=>{Yt(null),Xt.current?.focus()},[]),ee=ys.useAnchoredPopup(we!==null,Xt,on),Jn=ee.popupRef,Yn=ee.ready;r.useEffect(()=>{we===null||!Yn||Jn.current?.querySelector('[role="menuitem"]:not(:disabled)')?.focus()},[we,Yn,Jn]);const Si=r.useCallback(e=>{const n=le.current;if(!n)return;const s=l.find(a=>a.field===e),i=gn(n,e,s?.minWidth??40);Vt(a=>({...a,[e]:i}))},[l]),Xn=r.useId(),wi=r.useCallback(()=>nn(null),[]),xe=ys.useAnchoredPopup(Pe!==null,Kn,wi,{anchorKey:Pe}),Qn=(e,n)=>{Kn.current=e.currentTarget,nn(n)},Zn=e=>nn(n=>n===e?null:n),es=r.useCallback((e,n)=>{const s=Z.findIndex(c=>c.field===e),i=Z.findIndex(c=>c.field===n);if(s<0||i<0||s===i||(Z[s].pinned??null)!==(Z[i].pinned??null))return;const a=Z.map(c=>c.field).filter(c=>c!==e),o=a.indexOf(n)+(s<i?1:0);a.splice(o,0,e),Pn(a),Nn?.(hn(l,a))},[Z,l,Nn]);r.useEffect(()=>{const e=tn.current;e&&(tn.current=null,le.current?.querySelector(`thead th[data-field="${e.replace(/["\\]/g,"\\$&")}"]`)?.focus())},[Le]);const ki=e=>{ae.items.some(s=>s.type==="condition"&&s.field===e)||$n({...ae,items:[...ae.items,{type:"condition",field:e,operator:"contains",value:""}]}),On(!0)},Mi=e=>{e(),on()},Di=e=>{const n=Array.from(e.currentTarget.querySelectorAll('[role="menuitem"]:not(:disabled)'));if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault();const s=e.key==="ArrowDown"?1:-1,i=n.indexOf(document.activeElement),a=i<0?s>0?0:n.length-1:(i+s+n.length)%n.length;n[a]?.focus()}else e.key==="Tab"&&Yt(null)},Me=r.useMemo(()=>H.map(e=>String(e[f])),[H,f]),De=Me.length>0&&Me.every(e=>I.has(e)),ts=Me.some(e=>I.has(e)),ns=r.useCallback(()=>{const e=new Set(I);De?Me.forEach(n=>e.delete(n)):Me.forEach(n=>e.add(n)),S?S(e):Gt(e)},[De,Me,I,S]),ss=r.useCallback(e=>{const n=new Set(I);n.has(e)?n.delete(e):n.add(e),S?S(n):Gt(n)},[I,S]),Ii=({field:e})=>X!==e||!W?t.jsx("span",{className:"nice-table__sort-icon",children:t.jsx(sa,{})}):t.jsx("span",{className:"nice-table__sort-icon",children:W==="asc"?t.jsx(na,{}):t.jsx(Je,{})}),E=r.useMemo(()=>{if(!Nt)return H.map((s,i)=>({type:"data",row:s,key:String(s[f]??i)}));const e=new Map;H.forEach(s=>{const i=s[Nt];e.has(i)||e.set(i,[]),e.get(i).push(s)});const n=[];return e.forEach((s,i)=>{const a=`__group_${String(i)}`,o=Wt.has(a);n.push({type:"group",value:i,rows:s,expanded:o,key:a}),o&&s.forEach((c,u)=>n.push({type:"data",row:c,key:String(c[f]??`${a}_${u}`)}))}),n},[H,Nt,f,Wt]),{pinnedTopRows:cn,pinnedBottomRows:zi,normalRows:dn}=r.useMemo(()=>{if(!Dt?.size&&!It?.size)return{pinnedTopRows:[],pinnedBottomRows:[],normalRows:E};const e=[],n=[],s=[];for(const i of E){if(i.type==="data"){const a=i.key;if(Dt?.has(a)){e.push(i);continue}if(It?.has(a)){n.push(i);continue}}s.push(i)}return{pinnedTopRows:e,pinnedBottomRows:n,normalRows:s}},[E,Dt,It]),is=r.useCallback(e=>{Ln(n=>{const s=new Set(n);return s.has(e)?s.delete(e):s.add(e),s})},[]),as=r.useMemo(()=>{if(!Q)return E;const e=ct.current?.clientHeight??400,n=Math.ceil(e/V),s=Math.max(0,Math.floor(qt/V)-3),i=Math.min(E.length-1,s+n+6),a=E.slice(s,i+1).map((c,u)=>({...c,_vIdx:s+u}));return[...E.slice(0,Math.min(ge,s)).map((c,u)=>({...c,_vIdx:u})),...a]},[Q,E,qt,V,ge]),Ve=r.useMemo(()=>ge>0?[...cn,...dn].slice(0,ge).map(e=>e.key):[],[ge,cn,dn]),[Ri,Ei]=r.useState([]);r.useLayoutEffect(()=>{if(Q||Ve.length===0)return;const e=ct.current?.querySelector("table");if(!e)return;const n=Array.from(e.tBodies[0]?.rows??[]);let s=_t?e.tHead?.offsetHeight??0:0;const i=Ve.map(a=>{const o=s;return s+=n.find(c=>c.dataset.rowKey===a)?.offsetHeight??0,o});Ei(a=>a.length===i.length&&a.every((o,c)=>o===i[c])?a:i)},[Q,Ve,_t,Fe,j,an]);const rs=e=>{const n=Ve.indexOf(e);return n<0?{className:""}:{className:n===Ve.length-1?"nice-datagrid__row--frozen nice-datagrid__row--frozen-last":"nice-datagrid__row--frozen",style:{position:"sticky",top:Ri[n]??0,zIndex:2}}};r.useLayoutEffect(()=>{const e=le.current;if(!Ft||!e)return;const n={};for(const s of j)s.width===void 0&&Fe[s.field]===void 0&&(n[s.field]=gn(e,s.field,s.minWidth??40));yi(s=>{const i=Object.keys(n);return i.length===Object.keys(s).length&&i.every(o=>Math.abs((s[o]??-1/0)-n[o])<=1)?s:n})},[Ft,j,Fe,as]);const Ie=e=>Fe[e.field]||e.width||(Ft?bi[e.field]:void 0),xt=r.useCallback((e,n,s)=>{!L||Oe||(Kt({rowKey:e,field:n}),$e(s))},[L,Oe]),ls=r.useCallback(()=>{re&&L&&L(re.rowKey,re.field,ot),Kt(null),$e(null)},[re,ot,L]),Ai=r.useCallback(()=>{Kt(null),$e(null)},[]),Ti=r.useCallback((e,n)=>{!ye||Oe||(nt?Jt({key:e,row:n}):ye(e,n))},[ye,Oe,nt]),Oi=r.useCallback(()=>{const e=Ht;Jt(null),e&&ye?.(e.key,e.row)},[Ht,ye]),$i=r.useCallback(()=>Jt(null),[]),Ue=`nice-datagrid__actions-col${pt.length>0?" nice-datagrid__actions-col--sticky":""}`,os=(e,n)=>t.jsx("button",{type:"button",className:"nice-btn nice-btn--xs nice-btn--ghost nice-datagrid__row-delete","aria-label":p("controls.delete","Delete"),title:p("controls.delete","Delete"),onClick:s=>{s.stopPropagation(),Ti(e,n)},onDoubleClick:Ye,onKeyDown:Ye,children:t.jsx(v.NiceIcon,{name:"trash",size:14})}),Fi=r.useCallback(()=>{const e=$,n=e.map(u=>Xe(u.header)).join(","),s=B.map(u=>e.map(d=>Xe(String(u[d.field]??""))).join(",")),i=[n,...s].join(`
3
3
  `),a=new Blob(["\uFEFF"+i],{type:"text/csv;charset=utf-8;"}),o=URL.createObjectURL(a),c=document.createElement("a");c.href=o,c.download=`${_n}.csv`,c.click(),URL.revokeObjectURL(o)},[$,B,_n]),bt=r.useCallback(e=>{zt?zt(e):fi(e)},[zt]),yt=r.useCallback(e=>{Rt?Rt(e):mi(e)},[Rt]),G=r.useMemo(()=>E.filter(e=>e.type==="data").map(e=>e.key),[E]),Li=r.useCallback(e=>{if(e.target!==e.currentTarget||!Ee||re||!K)return;const n=G.indexOf(K.rowKey),s=j.findIndex(c=>c.field===K.field);if(n<0||s<0)return;let i=n,a=s;switch(e.key){case"ArrowUp":i=Math.max(0,n-1);break;case"ArrowDown":i=Math.min(G.length-1,n+1);break;case"ArrowLeft":a=Math.max(0,s-1);break;case"ArrowRight":a=Math.min(j.length-1,s+1);break;case"Tab":{const c=s+(e.shiftKey?-1:1);if(c<0||c>=j.length)return;a=c;break}case"Enter":{const c=j[s];if(c.editable&&L){const u=H.find(d=>String(d[f])===K.rowKey);u&&xt(K.rowKey,c.field,u[c.field])}return}case"Escape":bt(null),yt(null);return;case"Home":e.ctrlKey&&(i=0),a=0;break;case"End":e.ctrlKey&&(i=G.length-1),a=j.length-1;break;case"PageUp":i=Math.max(0,n-lt);break;case"PageDown":i=Math.min(G.length-1,n+lt);break;default:return}e.preventDefault();const o={rowKey:G[i],field:j[a].field};if(bt(o),e.shiftKey&&wn){const c=P?.start??K;yt({start:c,end:o})}else yt(null)},[Ee,re,K,G,j,wn,P,bt,yt,L,H,f,xt,lt]),cs=r.useCallback(()=>{let e=[],n=[];if(P){const s=G.indexOf(P.start.rowKey),i=G.indexOf(P.end.rowKey),a=Math.min(s,i),o=Math.max(s,i),c=j.findIndex(m=>m.field===P.start.field),u=j.findIndex(m=>m.field===P.end.field),d=Math.min(c,u),_=Math.max(c,u);n=j.slice(d,_+1).map(m=>m.field),e=H.filter(m=>{const A=G.indexOf(String(m[f]));return A>=a&&A<=o})}else I.size>0&&(e=H.filter(s=>I.has(String(s[f]))),n=j.map(s=>s.field));return{rows:e,fields:n}},[P,G,j,H,f,I]),ds=r.useCallback((e,n,s)=>{const i=j.filter(a=>n.includes(a.field));switch(s){case"json":return JSON.stringify(e.map(a=>Object.fromEntries(n.map(o=>[o,a[o]]))),null,2);case"csv":{const a=i.map(c=>Xe(c.header)).join(","),o=e.map(c=>i.map(u=>Xe(String(c[u.field]??""))).join(",")).join(`
4
4
  `);return a+`