@nice2dev/ui 1.4.14 → 1.4.15
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 +73 -0
- package/dist/{NiceColorPicker-BLwYNSXJ.cjs → NiceColorPicker-79rkvaSk.cjs} +1 -1
- package/dist/NiceDataGrid-B1AOjgjm.cjs +10 -0
- package/dist/NiceForm-fmePSeA9.cjs +1 -0
- package/dist/{NiceHtmlEditor-BzECmDO3.cjs → NiceHtmlEditor-By7R1wRo.cjs} +1 -1
- package/dist/{NiceMention-CYRqPKGU.cjs → NiceMention-i7n2BoMw.cjs} +1 -1
- package/dist/{NiceModuleLifecyclePanel-CiYbPcHV.cjs → NiceModuleLifecyclePanel-DVHQuhc-.cjs} +1 -1
- package/dist/{NicePagination-BAxwqeEd.cjs → NicePagination-D9JguOl0.cjs} +1 -1
- package/dist/NicePivotGrid-B_7iQJys.cjs +2 -0
- package/dist/NiceSavedQueryPanel-ChY4HwpM.cjs +587 -0
- package/dist/{NiceScheduler-BqYiHPvz.cjs → NiceScheduler-B2DamQ_L.cjs} +1 -1
- package/dist/backup/NiceBackupScheduler.mjs +171 -119
- package/dist/charts/NiceOrganizationChart.mjs +159 -59
- package/dist/charts/orgChartExport.mjs +71 -0
- package/dist/charts/tidyTree.mjs +43 -0
- package/dist/charts-C3Q3r8Yz.cjs +918 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.d.ts +9 -0
- package/dist/{core-lazy-BQexApr7.cjs → core-lazy-ChKRuEPb.cjs} +1 -1
- package/dist/data/NiceDataGrid.mjs +301 -320
- package/dist/data/NiceRowEditDialog.mjs +57 -0
- package/dist/data/NiceTreeGrid.mjs +478 -433
- package/dist/data.cjs +1 -1
- package/dist/data.d.ts +43 -2
- package/dist/{devops-cgRBnZVX.cjs → devops-o6Zm0VKB.cjs} +3 -3
- package/dist/devops.cjs +1 -1
- package/dist/editors/forms/NiceForm.mjs +216 -167
- package/dist/editors/inputs/NiceUpload.mjs +238 -238
- package/dist/editors.cjs +1 -1
- package/dist/editors.d.ts +13 -1
- package/dist/feedback.cjs +1 -1
- package/dist/index.cjs +254 -254
- package/dist/index.d.ts +198 -5
- package/dist/index.mjs +928 -920
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.d.ts +11 -1
- package/dist/navigation.cjs +1 -1
- package/dist/no-code/NiceDataMapper.mjs +398 -361
- package/dist/no-code-CN_q6TcB.cjs +331 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.d.ts +11 -1
- package/dist/style.css +1 -1
- package/dist/tools/NicePermissionMatrix.mjs +171 -138
- package/dist/tools/NiceRoleEditor.mjs +334 -297
- package/package.json +4 -4
- package/dist/NiceDataGrid-D3qRQSjy.cjs +0 -10
- package/dist/NiceForm-BWb4LTQJ.cjs +0 -1
- package/dist/NicePivotGrid-Cxu5PECg.cjs +0 -152
- package/dist/NiceSavedQueryPanel-C1nxEmMu.cjs +0 -587
- package/dist/charts-BzlvCCg9.cjs +0 -768
- package/dist/no-code-B1jzfUF5.cjs +0 -331
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),a=require("@nice2dev/ui-core"),b=require("react"),ze=require("./devops-cgRBnZVX.cjs"),Mt=require("react-dom");function ut(n,u,p,g){const m=g?.maxHeight??320,c=g?.anchorKey,x=b.useRef(null),[r,w]=b.useState(null),[i,s]=b.useState(!1),[d,_]=b.useState(""),y=b.useContext(a.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),k=b.useRef(p);k.current=p;const B=a.useInputEngine();return a.useOverlayFocus(x,{open:n,modal:!1,initialFocus:"none",onClose:()=>k.current(),closeHint:!1}),b.useLayoutEffect(()=>{if(!n||!u.current)return;_(ze.scopeThemeClass(u.current)),s(!1);const I=()=>{const E=u.current;if(!E)return;const h=E.getBoundingClientRect(),F=x.current?.offsetHeight??m;let A=h.bottom;A+F>window.innerHeight-8&&h.top-F>8&&(A=h.top-F);let J=h.left;J+h.width>window.innerWidth-8&&(J=Math.max(8,window.innerWidth-h.width-8)),w(O=>O&&O.left===J&&O.top===A&&O.width===h.width?O:{left:J,top:A,width:h.width})};I();const T=requestAnimationFrame(()=>{I(),s(!0)}),M=E=>{const h=E.target;h instanceof Node&&(x.current?.contains(h)||u.current?.contains(h))||k.current()},L=()=>k.current();return window.addEventListener("scroll",M,!0),window.addEventListener("resize",L),()=>{cancelAnimationFrame(T),window.removeEventListener("scroll",M,!0),window.removeEventListener("resize",L)}},[n,u,m,c]),b.useEffect(()=>{if(!n)return;const I=M=>{const L=M.target;u.current?.contains(L)||x.current?.contains(L)||(L instanceof Element?L:L?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||k.current()},T=M=>{if(M.key!=="Escape"||M.defaultPrevented)return;const L=B?.topOverlay();L&&L.element!==x.current||k.current()};return document.addEventListener("mousedown",I),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",T)}},[n,u,B]),{popupRef:x,coords:r,ready:i,themeClass:d,portalTarget:y}}const Xe=Object.assign(b.forwardRef(({label:n,checked:u=!1,indeterminate:p=!1,onChange:g,disabled:m,readOnly:c,loading:x,required:r,size:w="md",name:i,id:s,className:d,style:_,error:C,helperText:y,accessMode:k,displayStyle:B,showKeyboardHints:I,labelPlacement:T,errorPlacement:M,labelWidth:L,controlWidth:E,"data-testid":h},F)=>{const A=a.useNiceAccessMode(k,s),J=A==="hidden";(A==="disabled"||A==="readOnly")&&(m=!0);const{t:O}=a.useNiceTranslation(),Y=a.useControlId(s);a.useComponentDisplayClass("toggle",B);const H=b.useMemo(()=>[{key:"Space",description:O("shortcuts.toggle","Toggle")}],[O]),D=b.useCallback(l=>{l&&(l.indeterminate=p),typeof F=="function"?F(l):F&&(F.current=l)},[p,F]);return J?null:e.jsxs("div",{className:`nice-field nice-field--inline nice-field--${w} ${T==="left"?"nice-field--label-left":""} ${M==="right"?"nice-field--error-right":""} ${x?"nice-field--loading":""} ${d||""}`,style:{..._,...L!=null&&{"--nice-field-label-width":typeof L=="number"?`${L}px`:L},...E!=null&&{"--nice-field-control-width":typeof E=="number"?`${E}px`:E}},"data-testid":h,"aria-busy":x||void 0,children:[T==="left"&&n&&e.jsx("span",{className:`nice-field__label ${r?"nice-field__label--required":""}`,children:n}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("label",{className:`nice-checkbox ${w!=="md"?`nice-checkbox--${w}`:""} ${m||x?"nice-checkbox--disabled":""}`,htmlFor:Y,children:[e.jsx("input",{ref:D,id:Y,type:"checkbox",className:"nice-checkbox__input",name:i,checked:u,disabled:m||x,readOnly:c,"aria-invalid":!!C,onChange:l=>{c||x||g?.(l.target.checked)}}),e.jsx("span",{className:"nice-checkbox__box",children:e.jsx("svg",{viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:u?e.jsx("polyline",{points:"2 6 5 9 10 3"}):e.jsx("line",{x1:"2",y1:"6",x2:"10",y2:"6"})})}),T!=="left"&&n&&e.jsx("span",{children:n}),I&&e.jsx(a.NiceKeyboardHint,{shortcuts:H,size:"sm"})]}),x&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),M==="right"&&C&&e.jsx("div",{id:`${Y}-error`,className:"nice-field__error",role:"alert",children:C}),M==="right"&&!C&&y&&e.jsx("div",{id:`${Y}-helper`,className:"nice-field__helper",children:y})]}),M!=="right"&&C&&e.jsx("div",{id:`${Y}-error`,className:"nice-field__error",role:"alert",children:C}),M!=="right"&&!C&&y&&e.jsx("div",{id:`${Y}-helper`,className:"nice-field__helper",children:y})]})}),{displayName:"NiceCheckbox"}),Rt=Object.freeze(Object.defineProperty({__proto__:null,NiceCheckbox:Xe},Symbol.toStringTag,{value:"Module"})),et=Object.assign(b.forwardRef(({label:n,helperText:u,error:p,required:g,disabled:m,readOnly:c,size:x="md",name:r,id:w,className:i,style:s,accessMode:d,displayStyle:_,value:C,onChange:y,onBlur:k,onKeyDown:B,placeholder:I,min:T,max:M,step:L=1,precision:E,prefix:h,prefixType:F="label",prefixOptions:A,prefixValue:J,onPrefixChange:O,suffix:Y,showStepper:H=!0,submitOnEnter:D,onSubmit:l,showKeyboardHints:t,labelPlacement:o,errorPlacement:$,loading:N,labelWidth:S,controlWidth:P,formatPreset:f,format:ie,suffixType:ae="label",suffixOptions:v,suffixValue:te,onSuffixChange:j,suffixSeparator:G=!1,displayMode:Q},K)=>{const W=a.useNiceAccessMode(d,w),z=W==="hidden";W==="disabled"&&(m=!0),W==="readOnly"&&(c=!0);const{t:U}=a.useNiceTranslation(),V=a.useControlId(w),ee=a.useComponentDisplayStyle("input",_),pe=a.useComponentDisplayClass("input",_),[we,De]=b.useState(!1),[ue,Ne]=b.useState(null),Te=a.useDisplayModeEdit({enabled:Q,readOnly:c,disabled:m}),ke=b.useMemo(()=>{let q=3;return M!=null&&(q=String(Math.abs(Math.floor(M))).length),T!=null&&T<0&&(q+=1),E&&(q+=E+1),Math.max(3,q)+1},[M,T,E]),Ve=b.useCallback(q=>{if(ie)return ie(q);if(!f)return E!=null?q.toFixed(E):String(q);switch(f){case"integer":return Math.round(q).toLocaleString();case"decimal":return q.toLocaleString(void 0,{minimumFractionDigits:E??2,maximumFractionDigits:E??2});case"money":return q.toLocaleString(void 0,{minimumFractionDigits:E??2,maximumFractionDigits:E??2,useGrouping:!0});case"percent":return(q*100).toLocaleString(void 0,{minimumFractionDigits:E??0,maximumFractionDigits:E??2})+"%";default:return String(q)}},[ie,f,E]),Ie=b.useMemo(()=>we&&ue!==null?ue:C==null?"":we?E!=null?C.toFixed(E):String(C):Ve(C),[C,we,ue,Ve,E]),me=C!=null&&C<0,Me=!!(h||F==="select"&&A&&A.length>0),ge=me&&Me&&!we,Ue=ge?Ie.replace(/^[-−]/,""):Ie,$e=b.useCallback(q=>{let X=q;return T!==void 0&&(X=Math.max(T,X)),M!==void 0&&(X=Math.min(M,X)),E!==void 0&&(X=parseFloat(X.toFixed(E))),X},[T,M,E]),We=b.useCallback(q=>{const X=q.target.value;if(Ne(X),X===""||X==="-"||X==="."||X==="-."){X===""&&y?.(null);return}const de=parseFloat(X);if(!isNaN(de)){let R=de;T!==void 0&&(R=Math.max(T,R)),M!==void 0&&(R=Math.min(M,R)),y?.(R)}},[y,T,M]),se=b.useCallback(q=>{const X=$e(q);ve.current=X,Ne(null),y?.(X)},[y,$e]),re=b.useCallback(q=>se((ve.current??0)+q*L),[se,L]),Be=b.useCallback(()=>re(1),[re]),ye=b.useCallback(()=>re(-1),[re]),ve=b.useRef(C);ve.current=C;const xe=b.useRef(null),he=b.useCallback(()=>{xe.current&&(clearTimeout(xe.current),xe.current=null)},[]),Fe=b.useCallback(q=>{he();let X=300;const de=()=>{q(),X=Math.max(30,X*.82),xe.current=setTimeout(de,X)};xe.current=setTimeout(de,400)},[he]),Re=a.useSubmitOnEnter({enabled:D,onSubmit:l}),Ae=b.useCallback(q=>{if(Re(q),!c){const X=q.key==="ArrowUp"?1:q.key==="ArrowDown"?-1:q.key==="PageUp"?10:q.key==="PageDown"?-10:0;X?(q.preventDefault(),re(X)):q.key==="Home"&&T!==void 0?(q.preventDefault(),se(T)):q.key==="End"&&M!==void 0&&(q.preventDefault(),se(M))}B?.(q)},[Re,B,c,re,se,T,M]),Oe=b.useMemo(()=>{const q=[];return D&&q.push(a.COMMON_SHORTCUTS.submit),H&&(q.push({key:"ArrowUp",description:U("shortcuts.increment","Increase value")}),q.push({key:"ArrowDown",description:U("shortcuts.decrement","Decrease value")}),q.push({key:"PageUp",description:U("shortcuts.incrementBig","Increase by 10")}),q.push({key:"PageDown",description:U("shortcuts.decrementBig","Decrease by 10")}),T!==void 0&&q.push({key:"Home",description:U("shortcuts.toMinimum","Set to minimum")}),M!==void 0&&q.push({key:"End",description:U("shortcuts.toMaximum","Set to maximum")})),q},[D,H,T,M,U]);return z?null:e.jsxs("div",{className:`nice-field nice-field--${x} ${o==="left"?"nice-field--label-left":""} ${N?"nice-field--loading":""} ${i||""}`,style:{...s,...S!=null&&{"--nice-field-label-width":typeof S=="number"?`${S}px`:S},...P!=null&&{"--nice-field-control-width":typeof P=="number"?`${P}px`:P}},"aria-busy":N||void 0,children:[n&&e.jsxs("label",{htmlFor:V,className:`nice-field__label ${g?"nice-field__label--required":""}`,children:[n,t&&Oe.length>0&&e.jsx(a.NiceKeyboardHint,{shortcuts:Oe,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[Te.isDisplay?e.jsx(a.DisplayModeView,{value:C==null?"":h?e.jsxs(e.Fragment,{children:[h,Ie]}):Ie,placeholder:I,disabled:m,readOnly:c,onActivate:Te.enterEdit,ariaLabel:n}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:`nice-input nice-input--number nice-input--${x} nice-input--ds-${pe} ${G?"nice-input--suffix-sep":""} ${p?"nice-input--error":""} ${m?"nice-input--disabled":""} ${c?"nice-input--readonly":""}`,style:ee,children:[H&&!c&&e.jsx("button",{type:"button",className:"nice-input__clear nice-input__minus",onClick:ye,onMouseDown:()=>Fe(ye),onMouseUp:he,onMouseLeave:he,disabled:m,"aria-label":U("controls.decrement","Decrement"),children:e.jsx(a.NiceIcon,{name:"minus",size:16})}),F==="select"&&A&&A.length>0?e.jsxs(e.Fragment,{children:[ge&&e.jsx("span",{className:"nice-input__sign",children:"−"}),e.jsx("select",{className:"nice-input__suffix-select nice-input__icon--prefix",value:J??A[0]?.value,disabled:m,onChange:q=>{const X=q.target.value,de=A.find(Z=>Z.value===(J??A[0]?.value)),R=A.find(Z=>Z.value===X);O?.(X,de?.weight,R?.weight)},children:A.map(q=>e.jsx("option",{value:q.value,children:q.label},q.value))})]}):h?e.jsxs("span",{className:"nice-input__icon nice-input__icon--prefix",children:[ge&&e.jsx("span",{className:"nice-input__sign",children:"−"}),h]}):null,e.jsx("input",{ref:q=>{typeof K=="function"?K(q):K&&(K.current=q),Te.autoFocusRef(q)},id:V,className:"nice-input__native",type:!we&&(ie||f)?"text":"number",name:r,value:Ue,placeholder:I,min:T,max:M,step:L,disabled:m||N,readOnly:c,"aria-invalid":!!p,onChange:We,onFocus:q=>{De(!0),Ne(null),q.target.select()},onBlur:q=>{if(De(!1),Ne(null),C!=null&&E!==void 0){const X=parseFloat(C.toFixed(E));X!==C&&y?.(X)}Q&&Te.exitEdit(),k?.(q)},onKeyDown:Ae,style:{"--nice-input-number-width":`${ke}ch`}}),ae==="select"&&v&&v.length>0?e.jsx("select",{className:"nice-input__suffix-select nice-input__icon--suffix",value:te??v[0]?.value,disabled:m,onChange:q=>{const X=q.target.value,de=v.find(Z=>Z.value===(te??v[0]?.value)),R=v.find(Z=>Z.value===X);j?.(X,de?.weight,R?.weight)},children:v.map(q=>e.jsx("option",{value:q.value,children:q.label},q.value))}):Y?e.jsx("span",{className:"nice-input__icon nice-input__icon--suffix",children:Y}):null,H&&!c&&e.jsx("button",{type:"button",className:"nice-input__clear nice-input__plus",onClick:Be,onMouseDown:()=>Fe(Be),onMouseUp:he,onMouseLeave:he,disabled:m,"aria-label":U("controls.increment","Increment"),children:e.jsx(a.NiceIcon,{name:"plus",size:16})})]})}),N&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),$==="right"&&p&&e.jsx("div",{className:"nice-field__error",role:"alert",children:p}),$==="right"&&!p&&u&&e.jsx("div",{className:"nice-field__helper",children:u})]}),$!=="right"&&p&&e.jsx("div",{className:"nice-field__error",role:"alert",children:p}),$!=="right"&&!p&&u&&e.jsx("div",{className:"nice-field__helper",children:u})]})}),{displayName:"NiceNumberInput"}),Et=Object.freeze(Object.defineProperty({__proto__:null,NiceNumberInput:et},Symbol.toStringTag,{value:"Module"})),He=Object.assign(b.forwardRef(({label:n,"aria-label":u,helperText:p,error:g,required:m,disabled:c,size:x="md",name:r,id:w,className:i,style:s,accessMode:d,displayStyle:_,options:C,value:y,onChange:k,placeholder:B,multiple:I=!1,searchable:T=!0,clearable:M=!1,emptyText:L,maxHeight:E=240,optionsSource:h,valueField:F,labelField:A,virtualScroll:J,optionHeight:O=36,onSearch:Y,loading:H,renderOption:D,multipleAutosize:l=!1,showKeyboardHints:t,labelPlacement:o,errorPlacement:$,labelWidth:N,controlWidth:S,displayMode:P},f)=>{const ie=a.useNiceAccessMode(d,w),ae=ie==="hidden";(ie==="disabled"||ie==="readOnly")&&(c=!0);const{t:v}=a.useNiceTranslation(),te=a.useComponentDisplayStyle("input",_),j=a.useComponentDisplayClass("input",_),G=a.useControlId(w),Q=a.useDisplayModeEdit({enabled:P,disabled:c}),[K,W]=b.useState(!1),[z,U]=b.useState(""),[V,ee]=b.useState(-1),[pe,we]=b.useState(0),De=b.useRef(null),ue=b.useRef(null),[Ne,Te]=b.useState(null);b.useLayoutEffect(()=>{!H&&ue.current&&Te(ue.current.offsetWidth)},[H,y,_]);const[ke,Ve]=b.useState(null);b.useLayoutEffect(()=>{I&&!l&&ue.current&&ke==null&&Ve(ue.current.offsetWidth)},[I,l,ke]);const Ie=a.useNiceLookupSource(h??null,F??h?.keyField??"id",A??"name"),me=h?Ie.options:(C??[]).map(R=>typeof R=="string"?{value:R,label:R}:R),{popupRef:Me,coords:ge,ready:Ue,themeClass:$e,portalTarget:We}=ut(K,De,()=>{W(!1),U("")}),se=b.useMemo(()=>y?Array.isArray(y)?y:[y]:[],[y]),re=b.useMemo(()=>{if(!z&&!Y||Y)return me;const R=z.toLowerCase();return me.filter(Z=>Z.label.toLowerCase().includes(R)||String(Z.value).toLowerCase().includes(R))},[me,z,Y]),Be=b.useMemo(()=>{const R=new Map;for(const Z of re){const ne=Z.group||"";R.has(ne)||R.set(ne,[]),R.get(ne).push(Z)}return R},[re]),ye=b.useCallback(R=>{if(I){const Z=se.includes(R)?se.filter(ne=>ne!==R):[...se,R];k?.(Z)}else k?.(R),W(!1),U("")},[I,se,k]),ve=b.useCallback(()=>{const R=re.findIndex(Z=>se.includes(String(Z.value)));ee(R>=0?R:0),W(!0)},[re,se]),xe=b.useCallback(R=>ee(Z=>Math.max(0,Math.min(re.length-1,R(Z)))),[re.length]),he=b.useCallback(R=>{const Z=R.target instanceof HTMLInputElement;if(R.key==="Escape"){W(!1),U("");return}if((R.key==="Delete"||R.key==="Backspace")&&!Z&&M&&se.length>0){R.preventDefault(),k?.(I?[]:"");return}if(R.key==="Enter"||R.key===" "&&!Z){if(!K){ve(),R.preventDefault();return}V>=0&&re[V]&&(ye(re[V].value),R.preventDefault());return}const ne={ArrowDown:le=>le+1,ArrowUp:le=>le-1,PageDown:le=>le+10,PageUp:le=>le-10};Z||(ne.Home=()=>0,ne.End=()=>re.length-1);const fe=ne[R.key];fe&&(R.preventDefault(),K?xe(fe):ve())},[K,V,re,ye,ve,xe,M,se.length,k,I]),Fe=T||!!Y,Re=`${G}-listbox`,Ae=R=>`${G}-opt-${R}`,Oe=K&&V>=0&&re[V]?Ae(V):void 0;b.useLayoutEffect(()=>{const R=Me.current;if(!(!K||V<0||!R)){if(J){const Z=V*O;Z<R.scrollTop?R.scrollTop=Z:Z+O>R.scrollTop+R.clientHeight&&(R.scrollTop=Z+O-R.clientHeight);return}R.querySelector(`[data-nice-option-index="${V}"]`)?.scrollIntoView?.({block:"nearest"})}},[K,V,J,O,Me]),a.useIntent(["navigate","activate"],R=>{if(R.source==="keyboard")return!1;if(R.intent==="activate"){const Z=re[V];Z&&!Z.disabled&&ye(String(Z.value));return}if(R.direction!=="up"&&R.direction!=="down")return!1;xe(Z=>Z+(R.direction==="down"?1:-1))},{ref:Me,enabled:K&&Fe});const q=b.useMemo(()=>se.length===0?null:I?se.map(R=>me.find(Z=>Z.value===R)?.label||R).join(", "):me.find(R=>R.value===se[0])?.label||se[0],[se,me,I]),X=b.useCallback(R=>{R.stopPropagation(),k?.(I?[]:"")},[k,I]),de=b.useMemo(()=>[{key:"Enter",description:v("shortcuts.select","Select")},{key:"Space",description:v("shortcuts.openDropdown","Open dropdown")},a.COMMON_SHORTCUTS.moveUp,a.COMMON_SHORTCUTS.moveDown,a.COMMON_SHORTCUTS.cancel],[v]);return ae?null:e.jsxs("div",{className:`nice-field ${S==null?"nice-field--select-auto":""} nice-field--${x} ${o==="left"?"nice-field--label-left":""} ${H?"nice-field--loading":""} ${i||""}`,style:{...s,...N!=null&&{"--nice-field-label-width":typeof N=="number"?`${N}px`:N},...S!=null&&{"--nice-field-control-width":typeof S=="number"?`${S}px`:S},...H&&Ne!=null&&{"--nice-select-locked-width":`${Ne}px`}},"aria-busy":H||void 0,children:[n&&e.jsxs("label",{htmlFor:G,className:`nice-field__label ${m?"nice-field__label--required":""}`,children:[n,t&&e.jsx(a.NiceKeyboardHint,{shortcuts:de,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[Q.isDisplay?e.jsx(a.DisplayModeView,{value:q,placeholder:B||v("controls.select","Select..."),disabled:c,onActivate:()=>{Q.enterEdit(),W(!0)},ariaLabel:n??u}):e.jsxs("div",{className:"nice-select",ref:De,children:[e.jsxs("button",{ref:R=>{ue.current=R,typeof f=="function"?f(R):f&&(f.current=R)},type:"button",id:G,role:"combobox","aria-label":n?void 0:u,"aria-expanded":K,"aria-haspopup":"listbox","aria-controls":K?Re:void 0,"aria-activedescendant":Fe?void 0:Oe,"aria-invalid":!!g,"aria-keyshortcuts":M&&se.length>0?"Delete":void 0,className:`nice-select__trigger nice-select__trigger--${x} nice-select--ds-${j} ${K?"nice-select__trigger--open":""} ${g?"nice-select__trigger--error":""} ${c?"nice-select__trigger--disabled":""}`,style:{...te,...I&&!l&&ke!=null?{width:ke,maxWidth:ke,overflow:"hidden"}:{}},disabled:c,onClick:()=>K?W(!1):ve(),onKeyDown:he,children:[q?e.jsx("span",{style:I&&!l?{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}:void 0,children:q}):e.jsx("span",{className:"nice-select__placeholder",children:B||v("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[M&&se.length>0&&e.jsx("span",{className:"nice-input__clear",onClick:X,role:"presentation",children:e.jsx(a.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:`nice-select__chevron ${K?"nice-select__chevron--open":""}`,children:e.jsx(a.NiceIcon,{name:"chevron-down",size:16})})]})]}),K&&ge&&We&&Mt.createPortal(e.jsxs("div",{ref:Me,className:`nice-select__dropdown${$e?` ${$e}`:""}`,"data-theme":$e==="nice-dark"?"dark":$e==="nice-light"?"light":void 0,role:"listbox",id:Re,"aria-multiselectable":I||void 0,style:{maxHeight:E,position:"fixed",left:ge.left,top:ge.top,width:ge.width,minWidth:ge.width,zIndex:1e3,opacity:Ue?1:0,pointerEvents:Ue?void 0:"none"},onScroll:J?R=>we(R.currentTarget.scrollTop):void 0,children:[(T||Y)&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:z,onChange:R=>{U(R.target.value),ee(0),Y?.(R.target.value)},onKeyDown:he,placeholder:v("controls.search","Search..."),"aria-label":v("controls.search","Search..."),"aria-controls":Re,"aria-activedescendant":Oe,"aria-autocomplete":"list",autoFocus:!0})}),H&&e.jsx("div",{className:"nice-select__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm",style:{margin:"8px auto"}})}),!H&&re.length===0?e.jsx("div",{className:"nice-select__empty",children:L||v("controls.noResults","No results found")}):J&&!Array.from(Be.keys()).some(R=>R!=="")?(()=>{const Z=re.length*O,ne=Math.max(0,Math.floor(pe/O)-3),fe=Math.min(re.length,Math.ceil((pe+E)/O)+3),le=re.slice(ne,fe);return e.jsx("div",{style:{height:Z,position:"relative"},children:le.map((ce,It)=>{const Pe=ne+It,Ke=se.includes(ce.value);return e.jsx("div",{id:Ae(Pe),"data-nice-option-index":Pe,role:"option","aria-selected":Ke,"aria-disabled":ce.disabled||void 0,className:`nice-select__option ${Ke?"nice-select__option--selected":""} ${Pe===V?"nice-select__option--highlighted":""} ${ce.disabled?"nice-select__option--disabled":""}`,style:{position:"absolute",top:Pe*O,left:0,right:0,height:O,display:"flex",alignItems:"center",padding:"0 12px"},onClick:()=>!ce.disabled&&ye(String(ce.value)),onMouseEnter:()=>ee(Pe),children:D?D(ce,Ke):e.jsxs(e.Fragment,{children:[ce.icon&&e.jsx("span",{children:ce.icon}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{children:ce.label}),ce.description&&e.jsx("div",{className:"nice-select__option-desc",children:ce.description})]}),Ke&&e.jsx(a.NiceIcon,{name:"check",size:16,className:"nice-select__option-check"})]})},ce.value)})})})():Array.from(Be.entries()).map(([R,Z])=>e.jsxs(b.Fragment,{children:[R&&e.jsx("div",{className:"nice-select__group-label",children:R}),Z.map(ne=>{const fe=se.includes(ne.value),le=re.indexOf(ne);return e.jsx("div",{id:Ae(le),"data-nice-option-index":le,role:"option","aria-selected":fe,"aria-disabled":ne.disabled||void 0,className:`nice-select__option ${fe?"nice-select__option--selected":""} ${le===V?"nice-select__option--highlighted":""} ${ne.disabled?"nice-select__option--disabled":""}`,onClick:()=>!ne.disabled&&ye(String(ne.value)),onMouseEnter:()=>ee(le),children:D?D(ne,fe):e.jsxs(e.Fragment,{children:[ne.icon&&e.jsx("span",{children:ne.icon}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{children:ne.label}),ne.description&&e.jsx("div",{className:"nice-select__option-desc",children:ne.description})]}),fe&&e.jsx(a.NiceIcon,{name:"check",size:16,className:"nice-select__option-check"})]})},ne.value)})]},R))]}),We)]}),H&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),$==="right"&&g&&e.jsx("div",{id:`${G}-error`,className:"nice-field__error",role:"alert",children:g}),$==="right"&&!g&&p&&e.jsx("div",{id:`${G}-helper`,className:"nice-field__helper",children:p})]}),$!=="right"&&g&&e.jsx("div",{id:`${G}-error`,className:"nice-field__error",role:"alert",children:g}),$!=="right"&&!g&&p&&e.jsx("div",{id:`${G}-helper`,className:"nice-field__helper",children:p})]})}),{displayName:"NiceSelect"}),Dt=Object.freeze(Object.defineProperty({__proto__:null,NiceSelect:He},Symbol.toStringTag,{value:"Module"})),be=Object.assign(b.forwardRef(({label:n,helperText:u,error:p,required:g,disabled:m,readOnly:c,size:x="md",name:r,id:w,className:i,style:s,accessMode:d,displayStyle:_,variant:C,value:y,defaultValue:k,onChange:B,onBlur:I,onKeyDown:T,placeholder:M,type:L="text",maxLength:E,prefix:h,suffix:F,clearable:A,autoFocus:J,submitOnEnter:O,onSubmit:Y,showKeyboardHints:H,labelPlacement:D,errorPlacement:l,loading:t,labelWidth:o,controlWidth:$,displayMode:N,...S},P)=>{const f=a.useNiceAccessMode(d,w),ie=f==="hidden";f==="disabled"&&(m=!0),f==="readOnly"&&(c=!0);const{t:ae}=a.useNiceTranslation(),v=a.useControlId(w),te=a.useComponentDisplayStyle("input",_),j=a.useComponentDisplayClass("input",_),G=C==="filled"?"filled":C==="underlined"?"underlined":"",Q=b.useCallback(()=>B?.(""),[B]),K=a.useDisplayModeEdit({enabled:N,readOnly:c,disabled:m}),W=a.useSubmitOnEnter({enabled:O,onSubmit:Y}),z=b.useCallback(V=>{W(V),T?.(V)},[W,T]),U=b.useMemo(()=>{const V=[];return O&&V.push({key:"Enter",description:ae("shortcuts.submit","Submit")}),A&&V.push({key:"Escape",description:ae("shortcuts.clear","Clear")}),V},[O,A,ae]);return ie?null:e.jsxs("div",{className:`nice-field nice-field--${x} ${D==="left"?"nice-field--label-left":""} ${D==="inside"?"nice-field--label-inside":""} ${t?"nice-field--loading":""} ${i||""}`,style:{...s,...o!=null&&{"--nice-field-label-width":typeof o=="number"?`${o}px`:o},...$!=null&&{"--nice-field-control-width":typeof $=="number"?`${$}px`:$}},"aria-busy":t||void 0,"data-floating":D==="inside"&&y?"true":void 0,children:[n&&D!=="inside"&&e.jsxs("label",{htmlFor:v,className:`nice-field__label ${g?"nice-field__label--required":""}`,children:[n,H&&U.length>0&&e.jsx(a.NiceKeyboardHint,{shortcuts:U,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[K.isDisplay?e.jsx(a.DisplayModeView,{value:y??k??"",placeholder:M,disabled:m,readOnly:c,onActivate:K.enterEdit,ariaLabel:n}):e.jsxs("div",{className:`nice-input nice-input--${x} nice-input--ds-${G||j} ${p?"nice-input--error":""} ${m?"nice-input--disabled":""} ${c?"nice-input--readonly":""}`,style:C?void 0:te,children:[h&&e.jsx("span",{className:"nice-input__icon",children:h}),e.jsx("input",{ref:V=>{typeof P=="function"?P(V):P&&(P.current=V),K.autoFocusRef(V)},id:v,className:"nice-input__native",type:L,name:r,value:y,defaultValue:k,placeholder:M,disabled:m||t,readOnly:c,maxLength:E,autoFocus:J,"aria-invalid":!!p,"aria-describedby":p?`${v}-error`:u?`${v}-helper`:void 0,onChange:V=>B?.(V.target.value),onBlur:V=>{N&&K.exitEdit(),I?.(V)},onKeyDown:z,...S}),A&&y&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:Q,"aria-label":ae("controls.clear","Clear"),children:e.jsx(a.NiceIcon,{name:"close",size:14})}),F&&e.jsx("span",{className:"nice-input__icon",children:F}),n&&D==="inside"&&e.jsx("label",{htmlFor:v,className:`nice-input__floating-label ${g?"nice-input__floating-label--required":""}`,children:n})]}),t&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),l==="right"&&p&&e.jsx("div",{id:`${v}-error`,className:"nice-field__error",role:"alert",children:p}),l==="right"&&!p&&u&&e.jsx("div",{id:`${v}-helper`,className:"nice-field__helper",children:u})]}),l!=="right"&&p&&e.jsx("div",{id:`${v}-error`,className:"nice-field__error",role:"alert",children:p}),l!=="right"&&!p&&u&&e.jsx("div",{id:`${v}-helper`,className:"nice-field__helper",children:u})]})}),{displayName:"NiceTextInput"}),Bt=Object.freeze(Object.defineProperty({__proto__:null,NiceTextInput:be},Symbol.toStringTag,{value:"Module"})),mt=({code:n,language:u="typescript",lineNumbers:p=!0,livePreview:g=!1,showDiff:m=!1,previousCode:c,theme:x="light",copyable:r=!0,onCopy:w,className:i})=>{const{t:s}=a.useNiceTranslation(),[d,_]=b.useState(!1),C=async()=>{await navigator.clipboard.writeText(n),_(!0),w?.(),setTimeout(()=>_(!1),2e3)},y=n.split(`
|
|
2
|
-
`),k=()=>e.jsx("div",{className:"nice-code-preview__line-numbers",children:y.map((M,L)=>e.jsx("span",{children:L+1},L))}),B=()=>e.jsx("pre",{className:`nice-code-preview__code language-${u}`,children:e.jsx("code",{children:n})}),I=()=>c?e.jsxs("div",{className:"nice-code-preview__diff",children:[e.jsxs("div",{className:"nice-code-preview__diff-panel nice-code-preview__diff-panel--old",children:[e.jsx("h4",{children:s("codePreview.previous","Previous")}),e.jsx("pre",{children:c})]}),e.jsxs("div",{className:"nice-code-preview__diff-panel nice-code-preview__diff-panel--new",children:[e.jsx("h4",{children:s("codePreview.current","Current")}),e.jsx("pre",{children:n})]})]}):null,T=()=>u!=="html"?e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("p",{children:s("codePreview.livePreviewIsAvailableFor","Live preview is available for HTML only")})}):e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("iframe",{srcDoc:n,title:s("codePreview.livePreview","Live Preview"),sandbox:"allow-scripts"})});return e.jsxs("div",{className:`nice-code-preview nice-code-preview--${x} ${i||""}`,children:[e.jsxs("header",{className:"nice-code-preview__header",children:[e.jsx("span",{className:"nice-code-preview__language",children:u}),r&&e.jsx("button",{onClick:C,className:"nice-code-preview__copy-btn",children:d?e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"check",size:14})," ",s("codePreview.copied","Copied")]}):s("codePreview.copy","Copy")})]}),m&&c?I():e.jsxs("div",{className:"nice-code-preview__body",children:[p&&k(),B()]}),g&&e.jsxs("div",{className:"nice-code-preview__preview-section",children:[e.jsx("h4",{children:s("codePreview.preview","Preview")}),T()]})]})},Ft=[{target:".nice-lowcode-studio",titleKey:"tutorial.lowCodeStudio.intro.title",title:"Low-code studio",contentKey:"tutorial.lowCodeStudio.intro.content",content:"Drag components from the sidebar onto the canvas, then switch between Design, Preview and Code tabs to build and export your app.",placement:"auto"}],At={components:[],layout:{type:"flex"},styles:{}},Ye="application/x-nice-component";function Ot(n){const u=n.replace(/[^A-Za-z0-9]+(.)?/g,(p,g)=>g?g.toUpperCase():"");return/^[A-Za-z]/.test(u)?u.charAt(0).toUpperCase()+u.slice(1):`Component${u}`}function Pt(n,u){return["export function Page() {"," return ("," <>",...n.components.map(g=>{const m=Object.entries(g.props).map(([c,x])=>typeof x=="string"?` ${c}=${JSON.stringify(x)}`:` ${c}={${JSON.stringify(x)}}`);return` <${u(g.type)}${m.join("")} />`})," </>"," );","}"].join(`
|
|
3
|
-
`)}const Lt=({projectId:n,components:u=[],theme:p="light",onChange:g,onSave:m,renderComponent:c,className:x,tutorial:r})=>{const{t:w}=a.useNiceTranslation(),[i,s]=b.useState("design"),[d,_]=b.useState(At),[C,y]=b.useState(null),[k,B]=b.useState(!1),I=b.useRef(0),T=t=>u.find(o=>o.id===t),M=t=>T(t)?.name??t,L=t=>{const o=T(t)?.icon;return o?e.jsx(a.NiceIcon,{name:o,size:14}):null},E=t=>{const o={...d,components:t};_(o),g?.(o)},h=t=>{I.current+=1;const o={id:`${t.id}-${I.current}`,type:t.id,props:{...t.defaultProps}};E([...d.components,o]),y(o.id)},F=t=>{E(d.components.filter(o=>o.id!==t)),C===t&&y(null)},A=(t,o,$)=>E(d.components.map(N=>N.id===t?{...N,props:{...N.props,[o]:$}}:N)),J=t=>{Array.from(t.dataTransfer.types).includes(Ye)&&(t.preventDefault(),t.dataTransfer.dropEffect="copy",B(!0))},O=t=>{t.currentTarget.contains(t.relatedTarget)||B(!1)},Y=t=>{t.preventDefault(),B(!1);const o=T(t.dataTransfer.getData(Ye));o&&h(o)},H=(t,o,$)=>typeof $=="boolean"?e.jsx(Xe,{label:o,checked:$,onChange:N=>A(t,o,N)}):typeof $=="number"?e.jsx(et,{label:o,value:$,onChange:N=>A(t,o,N??0)}):typeof $=="string"?e.jsx(be,{label:o,value:$,onChange:N=>A(t,o,N)}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:o}),e.jsx("code",{children:JSON.stringify($)})]}),D=d.components.find(t=>t.id===C),l=[{id:"design",label:w("noCode.lowCodeStudio.design","Design")},{id:"preview",label:w("noCode.preview","Preview")},{id:"code",label:w("noCode.lowCodeStudio.code","Code")}];return e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-lowcode-studio nice-lowcode-studio--${p} ${x||""}`,menubar:e.jsxs("header",{className:"nice-lowcode-studio__header",children:[e.jsx("h1",{children:w("noCode.lowCodeStudio.title","Low-Code Studio")}),e.jsx("nav",{className:"nice-lowcode-studio__tabs",children:l.map(t=>e.jsx("button",{type:"button","aria-pressed":i===t.id,onClick:()=>s(t.id),className:`nice-lowcode-studio__tab ${i===t.id?"nice-lowcode-studio__tab--active":""}`,children:t.label},t.id))}),e.jsx("button",{type:"button",onClick:()=>m?.(d),children:w("save","Save")}),e.jsx(a.NiceTutorialButton,{steps:a.resolveTutorial(r,Ft)})]}),sidebar:e.jsxs("aside",{className:"nice-lowcode-studio__sidebar",children:[e.jsx("h2",{children:w("noCode.componentDesigner.palette","Component Palette")}),e.jsx("ul",{children:u.map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",draggable:!0,className:"nice-lowcode-studio__palette-item",title:w("noCode.lowCodeStudio.addHint","Drag onto the canvas, or click to add"),onDragStart:o=>{o.dataTransfer.setData(Ye,t.id),o.dataTransfer.effectAllowed="copy"},onClick:()=>h(t),children:[L(t.id),t.name]})},t.id))})]}),rightSidebar:e.jsxs("aside",{className:"nice-lowcode-studio__properties",children:[e.jsx("h2",{children:w("noCode.lowCodeStudio.properties","Properties")}),D?e.jsxs("div",{className:"nice-lowcode-studio__props",children:[e.jsx("h3",{children:M(D.type)}),Object.keys(D.props).length===0?e.jsx("p",{children:w("noCode.lowCodeStudio.noProps","This component has no properties")}):Object.entries(D.props).map(([t,o])=>e.jsx("div",{className:"nice-lowcode-studio__prop",children:H(D.id,t,o)},t))]}):e.jsx("p",{children:w("noCode.lowCodeStudio.selectHint","Select a component to edit its properties")})]}),children:e.jsxs("main",{className:"nice-lowcode-studio__canvas","data-project":n,children:[i==="design"&&e.jsx("div",{className:["nice-lowcode-studio__design-canvas",k&&"nice-lowcode-studio__design-canvas--over",d.components.length>0&&"nice-lowcode-studio__design-canvas--filled"].filter(Boolean).join(" "),onDragOver:J,onDragLeave:O,onDrop:Y,children:d.components.length===0?e.jsx("p",{children:w("noCode.componentDesigner.dragDrop","Drag components here")}):e.jsx("ul",{className:"nice-lowcode-studio__instances",children:d.components.map(t=>e.jsxs("li",{className:`nice-lowcode-studio__instance${t.id===C?" nice-lowcode-studio__instance--selected":""}`,children:[e.jsxs("button",{type:"button",className:"nice-lowcode-studio__instance-select","aria-pressed":t.id===C,onClick:()=>y(t.id),children:[L(t.type),M(t.type)]}),e.jsx("button",{type:"button","aria-label":`${w("remove","Remove")} ${M(t.type)}`,onClick:()=>F(t.id),children:e.jsx(a.NiceIcon,{name:"close",size:12})})]},t.id))})}),i==="preview"&&e.jsx("div",{className:`nice-lowcode-studio__preview${c?" nice-lowcode-studio__preview--live":""}`,children:c?d.components.map(t=>e.jsx(b.Fragment,{children:c(t)},t.id)):e.jsx("p",{children:w("noCode.lowCodeStudio.previewUnavailable","No preview: the app has not connected its components (renderComponent).")})}),i==="code"&&e.jsx("div",{className:"nice-lowcode-studio__code",children:e.jsx(mt,{code:d.components.length>0?Pt(d,t=>Ot(M(t))):w("noCode.lowCodeStudio.codeEmpty","// Add components to generate code"),language:"tsx",theme:p})})]})})},qt=[{target:".nice-component-designer",titleKey:"tutorial.componentDesigner.intro.title",title:"Component designer",contentKey:"tutorial.componentDesigner.intro.content",content:"Name your component, declare its props with types and requirements, and preview the generated TypeScript interface live.",placement:"auto"}],Ht=({component:n,propTypes:u=[],onChange:p,theme:g="light",className:m,tutorial:c})=>{const{t:x}=a.useNiceTranslation(),[r,w]=b.useState(n||{name:"NewComponent",props:[]}),i=s=>{const d={...r,...s};w(d),p?.(d)};return e.jsxs("div",{className:`nice-component-designer nice-component-designer--${g} ${m||""}`,style:{position:"relative"},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(a.NiceTutorialButton,{steps:a.resolveTutorial(c,qt)})}),e.jsxs("section",{className:"nice-component-designer__header",children:[e.jsx("input",{type:"text",value:r.name,onChange:s=>i({name:s.target.value}),placeholder:x("componentDesigner.componentName","Component Name")}),e.jsx("input",{type:"text",value:r.description||"",onChange:s=>i({description:s.target.value}),placeholder:x("componentDesigner.description","Description")})]}),e.jsxs("section",{className:"nice-component-designer__props",children:[e.jsx("h3",{children:x("componentDesigner.props","Props")}),r.props.map((s,d)=>e.jsxs("div",{className:"nice-component-designer__prop",children:[e.jsx("input",{type:"text",value:s.name,readOnly:!0}),e.jsx("span",{children:s.type}),s.required&&e.jsx("span",{children:x("componentDesigner.required","required")})]},d)),e.jsx("button",{onClick:()=>i({props:[...r.props,{name:"newProp",type:"string"}]}),children:x("componentDesigner.addProp","Add Prop")})]}),e.jsxs("section",{className:"nice-component-designer__preview",children:[e.jsx("h3",{children:x("componentDesigner.preview","Preview")}),e.jsx("pre",{children:`interface ${r.name}Props {
|
|
4
|
-
${r.props.map(s=>` ${s.name}${s.required?"":"?"}: ${s.type};`).join(`
|
|
5
|
-
`)}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const ${r.name}: React.FC<${r.name}Props> = (props) => {
|
|
9
|
-
return <div>Component</div>;
|
|
10
|
-
};`})]})]})},Vt=[{target:".nice-page-builder",titleKey:"tutorial.pageBuilder.intro.title",title:"Page builder",contentKey:"tutorial.pageBuilder.intro.content",content:"Drag components from the sidebar onto the responsive grid, switch the desktop/tablet/mobile preview, and save the layout.",placement:"auto"}],Ut=({initialLayout:n,components:u=[],grid:p={columns:12,gap:16,padding:24},onChange:g,onSave:m,theme:c="light",previewMode:x="desktop",className:r,tutorial:w})=>{const{t:i}=a.useNiceTranslation(),[s,d]=b.useState(n||{id:"page-1",name:"New Page",rows:[]}),[_,C]=b.useState(null),y=I=>{d(I),g?.(I)},k=()=>{const I={id:`row-${Date.now()}`,columns:[{id:`col-${Date.now()}`,width:12,components:[]}]};y({...s,rows:[...s.rows,I]})},B={desktop:"100%",tablet:"768px",mobile:"375px"}[x];return e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-page-builder nice-page-builder--${c} ${r||""}`,toolbar:e.jsxs("header",{className:"nice-page-builder__toolbar",children:[e.jsx("input",{type:"text",value:s.name,onChange:I=>y({...s,name:I.target.value})}),e.jsxs("div",{className:"nice-page-builder__preview-modes",children:[e.jsx("button",{className:`nice-page-builder__preview-mode ${x==="desktop"?"nice-page-builder__preview-mode--active":""}`,children:i("pageBuilder.desktop","Desktop")}),e.jsx("button",{className:`nice-page-builder__preview-mode ${x==="tablet"?"nice-page-builder__preview-mode--active":""}`,children:i("pageBuilder.tablet","Tablet")}),e.jsx("button",{className:`nice-page-builder__preview-mode ${x==="mobile"?"nice-page-builder__preview-mode--active":""}`,children:i("pageBuilder.mobile","Mobile")})]}),e.jsx("button",{onClick:()=>m?.(s),children:i("pageBuilder.save","Save")}),e.jsx(a.NiceTutorialButton,{steps:a.resolveTutorial(w,Vt)})]}),sidebar:e.jsxs("aside",{className:"nice-page-builder__sidebar",children:[e.jsx("h3",{children:i("pageBuilder.components","Components")}),e.jsx("ul",{className:"nice-page-builder__components",children:u.map(I=>e.jsxs("li",{draggable:!0,className:"nice-page-builder__component-item",children:[I.icon&&e.jsx(a.NiceIcon,{name:I.icon,size:14}),I.name]},I.id))})]}),rightSidebar:e.jsxs("aside",{className:"nice-page-builder__properties",children:[e.jsx("h3",{children:i("pageBuilder.properties","Properties")}),_?e.jsx("p",{children:i("pageBuilder.editPropertiesForSelectedComponent","Edit properties for selected component")}):e.jsx("p",{children:i("pageBuilder.selectAComponentToEdit","Select a component to edit")})]}),children:e.jsx("main",{className:"nice-page-builder__canvas",children:e.jsxs("div",{className:"nice-page-builder__viewport",style:{maxWidth:B},children:[s.rows.map(I=>e.jsx("div",{className:"nice-page-builder__row",children:I.columns.map(T=>e.jsx("div",{className:"nice-page-builder__column",style:{width:`${T.width/12*100}%`},children:T.components.length===0?e.jsx("div",{className:"nice-page-builder__dropzone",children:i("pageBuilder.dropComponentsHere","Drop components here")}):T.components.map(M=>e.jsx("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,className:`nice-page-builder__placed-component ${_===M.id?"nice-page-builder__placed-component--selected":""}`,onClick:()=>C(M.id),children:M.type},M.id))},T.id))},I.id)),e.jsx("button",{onClick:k,className:"nice-page-builder__add-row",children:i("pageBuilder.addRow","+ Add Row")})]})})})},Wt=[{target:".nice-state-designer",titleKey:"tutorial.stateDesigner.intro.title",title:"State designer",contentKey:"tutorial.stateDesigner.intro.content",content:"Model your store as slices with fields and actions, pick a target (e.g. Zustand) and export ready-to-use state-management code.",placement:"auto"}],Kt={id:"store-1",name:"AppStore",description:"Main application state store",slices:[{id:"slice-auth",name:"auth",description:"Authentication state",state:[{id:"f1",name:"user",type:"object",nullable:!0,description:"Current user"},{id:"f2",name:"isAuthenticated",type:"boolean",defaultValue:!1},{id:"f3",name:"token",type:"string",nullable:!0},{id:"f4",name:"loading",type:"boolean",defaultValue:!1},{id:"f5",name:"error",type:"string",nullable:!0}],actions:[{id:"a1",name:"login",description:"Authenticate user",async:!0,params:[{id:"p1",name:"email",type:"string",required:!0},{id:"p2",name:"password",type:"string",required:!0}],reducerSteps:[{id:"s1",type:"set",field:"loading",value:"true"},{id:"s2",type:"set",field:"error",value:"null"},{id:"s3",type:"set",field:"user",value:"response.user"},{id:"s4",type:"set",field:"token",value:"response.token"},{id:"s5",type:"set",field:"isAuthenticated",value:"true"},{id:"s6",type:"set",field:"loading",value:"false"}]},{id:"a2",name:"logout",description:"Clear user session",params:[],reducerSteps:[{id:"s1",type:"reset",field:"user"},{id:"s2",type:"set",field:"isAuthenticated",value:"false"},{id:"s3",type:"reset",field:"token"}]}],selectors:[{id:"sel1",name:"selectUser",expression:"state.auth.user",dependencies:["user"],memoized:!0},{id:"sel2",name:"selectIsLoggedIn",expression:"state.auth.isAuthenticated",dependencies:["isAuthenticated"]}]},{id:"slice-cart",name:"cart",description:"Shopping cart state",state:[{id:"f1",name:"items",type:"array",defaultValue:[],description:"Cart items"},{id:"f2",name:"total",type:"number",defaultValue:0},{id:"f3",name:"currency",type:"string",defaultValue:"USD"}],actions:[{id:"a1",name:"addItem",params:[{id:"p1",name:"item",type:"object",required:!0}],reducerSteps:[{id:"s1",type:"push",field:"items",value:"item"},{id:"s2",type:"update",field:"total",value:"state.total + item.price"}]},{id:"a2",name:"removeItem",params:[{id:"p1",name:"itemId",type:"string",required:!0}],reducerSteps:[{id:"s1",type:"remove",field:"items",value:"item.id !== itemId"}]},{id:"a3",name:"clearCart",params:[],reducerSteps:[{id:"s1",type:"set",field:"items",value:"[]"},{id:"s2",type:"set",field:"total",value:"0"}]}],selectors:[{id:"sel1",name:"selectCartItems",expression:"state.cart.items",dependencies:["items"]},{id:"sel2",name:"selectCartCount",expression:"state.cart.items.length",dependencies:["items"],memoized:!0},{id:"sel3",name:"selectCartTotal",expression:"state.cart.total",dependencies:["total"]}],computed:[{id:"c1",name:"itemCount",expression:"items.length",dependencies:["items"]}]}],middleware:[{type:"immer",enabled:!0},{type:"devtools",enabled:!0},{type:"persist",enabled:!0}],persist:{enabled:!0,key:"app-store",storage:"localStorage",whitelist:["auth.token","cart.items"],version:1},devtools:{enabled:!0,name:"AppStore",trace:!0}},Jt=[{id:"tpl-auth",name:"Authentication",description:"User authentication with token",icon:"lock",store:{slices:[{id:"auth",name:"auth",state:[{id:"user",name:"user",type:"object",nullable:!0},{id:"token",name:"token",type:"string",nullable:!0},{id:"isAuthenticated",name:"isAuthenticated",type:"boolean",defaultValue:!1}],actions:[],selectors:[]}]}},{id:"tpl-crud",name:"CRUD Entity",description:"Standard entity with loading states",icon:"box",store:{slices:[{id:"entity",name:"entity",state:[{id:"items",name:"items",type:"array",defaultValue:[]},{id:"selected",name:"selected",type:"object",nullable:!0},{id:"loading",name:"loading",type:"boolean",defaultValue:!1},{id:"error",name:"error",type:"string",nullable:!0}],actions:[],selectors:[]}]}},{id:"tpl-ui",name:"UI State",description:"Theme, sidebar, modal states",icon:"palette",store:{slices:[{id:"ui",name:"ui",state:[{id:"theme",name:"theme",type:"enum",defaultValue:"light"},{id:"sidebarOpen",name:"sidebarOpen",type:"boolean",defaultValue:!0},{id:"activeModal",name:"activeModal",type:"string",nullable:!0}],actions:[],selectors:[]}]}}],tt={string:"edit",number:"hash",boolean:"check",array:"clipboard",object:"box",date:"calendar",enum:"bar-chart",custom:"settings"},nt=n=>{const u=["import { create } from 'zustand'"];n.middleware?.some(i=>i.type==="devtools"&&i.enabled)&&u.push("import { devtools } from 'zustand/middleware'"),n.middleware?.some(i=>i.type==="persist"&&i.enabled)&&u.push("import { persist } from 'zustand/middleware'"),n.middleware?.some(i=>i.type==="immer"&&i.enabled)&&u.push("import { immer } from 'zustand/middleware/immer'");const p=[];n.slices.forEach(i=>{p.push(`interface ${it(i.name)}State {`),i.state.forEach(s=>{const d=rt(s.type,s.nullable);p.push(` ${s.name}: ${d};`)}),p.push("}"),p.push("")}),p.push("interface Actions {"),n.slices.forEach(i=>{i.actions.forEach(s=>{const d=s.params.map(C=>`${C.name}: ${rt(C.type)}`).join(", "),_=s.async?"Promise<void>":"void";p.push(` ${s.name}: (${d}) => ${_};`)})}),p.push("}");const g=n.slices.map(i=>`${it(i.name)}State`).join(" & ");p.push(""),p.push(`type StoreState = ${g} & Actions;`);const m=[];n.slices.forEach(i=>{i.state.forEach(s=>{const d=s.defaultValue!==void 0?JSON.stringify(s.defaultValue):s.nullable?"null":gt(s.type);m.push(` ${s.name}: ${d},`)})});const c=[];n.slices.forEach(i=>{i.actions.forEach(s=>{const d=s.params.map(C=>C.name).join(", "),_=s.async?"async ":"";c.push(` ${s.name}: ${_}(${d}) => {`),s.async?(c.push(" set({ loading: true, error: null });"),c.push(" try {"),c.push(" // TODO: API call"),c.push(` // const response = await api.${s.name}(${d});`),s.reducerSteps.forEach(C=>{C.type==="set"&&c.push(` set({ ${C.field}: ${C.value} });`)}),c.push(" } catch (error) {"),c.push(" set({ error: error.message, loading: false });"),c.push(" }")):(c.push(" set((state) => {"),s.reducerSteps.forEach(C=>{C.type==="set"?c.push(` state.${C.field} = ${C.value};`):C.type==="push"?c.push(` state.${C.field}.push(${C.value});`):C.type==="reset"&&c.push(` state.${C.field} = null;`)}),c.push(" });")),c.push(" },")})});let x="",r="";if(n.middleware?.some(i=>i.type==="immer"&&i.enabled)&&(x+="immer(",r=")"+r),n.middleware?.some(i=>i.type==="devtools"&&i.enabled)&&(x+="devtools(",r=`, { name: '${n.devtools?.name||n.name}' })`+r),n.persist?.enabled){x+="persist(";const i=[`name: '${n.persist.key}'`];n.persist.whitelist&&i.push(`partialize: (state) => ({ ${n.persist.whitelist.map(s=>s.split(".").pop()).join(", ")} })`),r=`, { ${i.join(", ")} })`+r}return`${u.join(`
|
|
11
|
-
`)}
|
|
12
|
-
|
|
13
|
-
// Types
|
|
14
|
-
${p.join(`
|
|
15
|
-
`)}
|
|
16
|
-
|
|
17
|
-
// Store
|
|
18
|
-
export const use${n.name} = create<StoreState>()(
|
|
19
|
-
${x}(set, get) => ({
|
|
20
|
-
// Initial State
|
|
21
|
-
${m.join(`
|
|
22
|
-
`)}
|
|
23
|
-
|
|
24
|
-
// Actions
|
|
25
|
-
${c.join(`
|
|
26
|
-
`)}
|
|
27
|
-
})${r}
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
// Selectors
|
|
31
|
-
${n.slices.flatMap(i=>i.selectors.map(s=>`export const ${s.name} = (state: StoreState) => ${s.expression.replace("state.","state.")};`)).join(`
|
|
32
|
-
`)}
|
|
33
|
-
`},it=n=>n.charAt(0).toUpperCase()+n.slice(1),rt=(n,u)=>{const p={string:"string",number:"number",boolean:"boolean",array:"unknown[]",object:"Record<string, unknown>",date:"Date",enum:"string",custom:"unknown"}[n];return u?`${p} | null`:p},gt=n=>({string:"''",number:"0",boolean:"false",array:"[]",object:"{}",date:"new Date()",enum:"''",custom:"null"})[n],xt=({store:n=Kt,templates:u=Jt,onStoreChange:p,onExport:g,onSave:m,tutorial:c,className:x,style:r,"data-testid":w})=>{const{t:i}=a.useNiceTranslation(),[s,d]=b.useState(n),[_,C]=b.useState("slices"),[y,k]=b.useState(s.slices[0]?.id||null),[B,I]=b.useState(null),[T,M]=b.useState("zustand"),[L,E]=b.useState(!1),[h,F]=b.useState(null),[A,J]=b.useState(""),[O,Y]=b.useState("string"),H=b.useMemo(()=>s.slices.find(v=>v.id===y),[s.slices,y]),D=b.useCallback(v=>{const te={...s,...v};d(te),p?.(te)},[s,p]),l=()=>{const v={id:`slice-${Date.now()}`,name:"newSlice",state:[],actions:[],selectors:[]};D({slices:[...s.slices,v]}),k(v.id)},t=()=>{if(!H||!A)return;const v={id:`field-${Date.now()}`,name:A,type:O,defaultValue:gt(O).replace(/'/g,"")},te=s.slices.map(j=>j.id===H.id?{...j,state:[...j.state,v]}:j);D({slices:te}),J("")},o=()=>{if(!H)return;const v={id:`action-${Date.now()}`,name:"newAction",params:[],reducerSteps:[]},te=s.slices.map(j=>j.id===H.id?{...j,actions:[...j.actions,v]}:j);D({slices:te}),I(v.id)},$=b.useCallback(()=>{let v="";T==="zustand"?v=nt(s):v=`// Export for ${T} coming soon...
|
|
34
|
-
// Store: ${s.name}`,g?.(v,T)},[s,T,g]),N=b.useMemo(()=>T==="zustand"?nt(s):`// ${T} export coming soon...`,[s,T]),S={bg:"var(--nice-bg-elevated, #1e1e1e)",cardBg:"var(--nice-bg-elevated, #252525)",border:"var(--nice-bg-tertiary, #333)",text:"var(--nice-text-primary, #e0e0e0)",textMuted:"var(--nice-text-muted, #888)",accent:"var(--nice-color-primary, #3b82f6)"},P=e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${S.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:18,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"folder",size:16})," ",i("stateDesigner.stateDesigner","State Designer")]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8},children:e.jsx("input",{type:"text",value:s.name,onChange:v=>D({name:v.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.cardBg,color:S.text,fontSize:14,fontWeight:600}})}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8,alignItems:"center"},children:[e.jsx(a.NiceTutorialButton,{steps:a.resolveTutorial(c,Wt)}),e.jsxs("button",{onClick:()=>E(!0),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${S.border}`,background:"transparent",color:S.text,cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"clipboard",size:14})," ",i("stateDesigner.templates","Templates")]}),e.jsxs("button",{onClick:()=>m?.(s),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"var(--nice-color-success, #22c55e)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13,fontWeight:500},children:[e.jsx(a.NiceIcon,{name:"save",size:14})," ",i("stateDesigner.save","Save")]})]})]}),f=e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${S.border}`,padding:"0 20px"},children:["slices","actions","selectors","settings","preview"].map(v=>e.jsxs("button",{onClick:()=>C(v),style:{padding:"12px 20px",border:"none",background:"transparent",color:_===v?S.text:S.textMuted,cursor:"pointer",fontSize:13,fontWeight:_===v?600:400,borderBottom:_===v?`2px solid ${S.accent}`:"2px solid transparent",marginBottom:-1},children:[v==="slices"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"box",size:14})," ",i("stateDesigner.slices","Slices")]}),v==="actions"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"zap",size:14})," ",i("stateDesigner.actions","Actions")]}),v==="selectors"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"target",size:14})," ",i("stateDesigner.selectors","Selectors")]}),v==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"settings",size:14})," ",i("stateDesigner.settings","Settings")]}),v==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"eye",size:14})," ",i("stateDesigner.preview","Preview")]})]},v))}),ae=_==="slices"||_==="actions"||_==="selectors"?e.jsxs("div",{style:{width:200,borderRight:`1px solid ${S.border}`,padding:12,display:"flex",flexDirection:"column",gap:8,height:"100%",boxSizing:"border-box"},children:[e.jsx("div",{style:{fontSize:11,color:S.textMuted,marginBottom:4},children:i("stateDesigner.slices2","SLICES")}),s.slices.map(v=>e.jsxs("button",{onClick:()=>k(v.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:y===v.id?S.accent+"30":S.cardBg,color:S.text,cursor:"pointer",textAlign:"left",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"box",size:14})," ",v.name,e.jsx("div",{style:{fontSize:10,color:S.textMuted},children:i("stateDesigner.fieldsActions","{state} fields • {actions} actions").replace("{state}",String(v.state.length)).replace("{actions}",String(v.actions.length))})]},v.id)),e.jsx("button",{onClick:l,style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${S.border}`,background:"transparent",color:S.textMuted,cursor:"pointer",fontSize:13},children:i("stateDesigner.addSlice","+ Add Slice")})]}):void 0;return e.jsxs(e.Fragment,{children:[e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-state-designer ${x||""}`,style:{background:S.bg,color:S.text,fontFamily:"system-ui, sans-serif",...r},"data-testid":w,menubar:P,toolbar:f,sidebar:ae,children:e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:20,boxSizing:"border-box"},children:[_==="slices"&&H&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20},children:[e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"box",size:16})," ",H.name]}),e.jsx("input",{type:"text",value:H.name,onChange:v=>{const te=s.slices.map(j=>j.id===H.id?{...j,name:v.target.value}:j);D({slices:te})},style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.cardBg,color:S.text,fontSize:13}})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("div",{style:{fontSize:12,color:S.textMuted,marginBottom:12},children:i("stateDesigner.stateFields","STATE FIELDS ({state})").replace("{state}",String(H.state.length))}),e.jsxs("div",{style:{border:`1px solid ${S.border}`,borderRadius:8,overflow:"hidden"},children:[H.state.map(v=>e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${S.border}`,display:"flex",alignItems:"center",gap:12},children:[e.jsx(a.NiceIcon,{name:tt[v.type],size:14}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,fontFamily:"monospace"},children:v.name}),e.jsxs("div",{style:{fontSize:11,color:S.textMuted},children:[v.type,v.nullable&&"?",v.defaultValue!==void 0&&` = ${JSON.stringify(v.defaultValue)}`]})]}),e.jsx("button",{onClick:()=>{const te=s.slices.map(j=>j.id===H.id?{...j,state:j.state.filter(G=>G.id!==v.id)}:j);D({slices:te})},"aria-label":i("stateDesigner.delete","Delete"),style:{padding:4,border:"none",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:14},children:e.jsx(a.NiceIcon,{name:"trash",size:14})})]},v.id)),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",alignItems:"center",gap:8,background:S.cardBg},children:[e.jsx("input",{type:"text",placeholder:"fieldName",value:A,onChange:v=>J(v.target.value),style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:13,fontFamily:"monospace"}}),e.jsx("select",{value:O,onChange:v=>Y(v.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:13},children:Object.keys(tt).map(v=>e.jsx("option",{value:v,children:v},v))}),e.jsx("button",{onClick:t,disabled:!A,style:{padding:"8px 16px",borderRadius:4,border:"none",background:A?S.accent:S.border,color:"var(--nice-color-white, #fff)",cursor:A?"pointer":"not-allowed",fontSize:13},children:i("stateDesigner.add","+ Add")})]})]})]})]}),_==="actions"&&H&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20},children:[e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"zap",size:16})," ",i("stateDesigner.actionsFor","Actions for {name}").replace("{name}",String(H.name))]}),e.jsx("button",{onClick:o,style:{padding:"6px 12px",borderRadius:4,border:"none",background:S.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:i("stateDesigner.addAction","+ Add Action")})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:H.actions.map(v=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,style:{padding:16,background:S.cardBg,borderRadius:8,border:`1px solid ${B===v.id?S.accent:S.border}`,cursor:"pointer"},onClick:()=>I(v.id),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:v.name}),v.async&&e.jsx("span",{style:{padding:"2px 6px",background:"var(--nice-accent-tint-12, #8b5cf620)",color:"var(--nice-color-accent, #8b5cf6)",borderRadius:4,fontSize:10},children:"async"}),e.jsxs("span",{style:{fontSize:11,color:S.textMuted},children:["(",v.params.map(te=>`${te.name}: ${te.type}`).join(", "),")"]})]}),v.description&&e.jsx("div",{style:{fontSize:12,color:S.textMuted,marginTop:4},children:v.description}),e.jsx("div",{style:{fontSize:11,color:S.textMuted,marginTop:8},children:i("stateDesigner.reducerSteps","{reducerSteps} reducer steps").replace("{reducerSteps}",String(v.reducerSteps.length))})]},v.id))})]}),_==="selectors"&&H&&e.jsxs("div",{children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20},children:e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"target",size:16})," ",i("stateDesigner.selectorsFor","Selectors for {name}").replace("{name}",String(H.name))]})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:H.selectors.map(v=>e.jsxs("div",{style:{padding:16,background:S.cardBg,borderRadius:8,border:`1px solid ${S.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:v.name}),v.memoized&&e.jsx("span",{style:{padding:"2px 6px",background:"var(--nice-success-tint-12, #22c55e20)",color:"var(--nice-color-success, #22c55e)",borderRadius:4,fontSize:10},children:i("stateDesigner.memoized","memoized")})]}),e.jsx("code",{style:{display:"block",marginTop:8,padding:8,background:S.bg,borderRadius:4,fontSize:12,color:"var(--nice-color-warning, #f59e0b)"},children:v.expression})]},v.id))})]}),_==="settings"&&e.jsxs("div",{style:{maxWidth:600},children:[e.jsx("h4",{style:{marginTop:0},children:i("stateDesigner.middleware","Middleware")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:24},children:s.middleware?.map(v=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,padding:12,background:S.cardBg,borderRadius:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:v.enabled,onChange:te=>{const j=s.middleware?.map(G=>G.type===v.type?{...G,enabled:te.target.checked}:G);D({middleware:j})}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,textTransform:"capitalize"},children:v.type}),e.jsxs("div",{style:{fontSize:11,color:S.textMuted},children:[v.type==="immer"&&i("stateDesigner.enableImmutableStateUpdates","Enable immutable state updates"),v.type==="devtools"&&i("stateDesigner.reduxDevtoolsIntegration","Redux DevTools integration"),v.type==="persist"&&i("stateDesigner.persistStateToStorage","Persist state to storage")]})]})]},v.type))}),s.persist?.enabled&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:i("stateDesigner.persistence","Persistence")}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:S.textMuted,marginBottom:4},children:i("stateDesigner.storageKey","Storage Key")}),e.jsx("input",{type:"text",value:s.persist.key,onChange:v=>D({persist:{...s.persist,key:v.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.cardBg,color:S.text,fontSize:13,width:"100%",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:S.textMuted,marginBottom:4},children:i("stateDesigner.storageType","Storage Type")}),e.jsxs("select",{value:s.persist.storage,onChange:v=>D({persist:{...s.persist,storage:v.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.cardBg,color:S.text,fontSize:13},children:[e.jsx("option",{value:"localStorage",children:"localStorage"}),e.jsx("option",{value:"sessionStorage",children:"sessionStorage"}),e.jsx("option",{value:"indexedDB",children:"indexedDB"})]})]})]})]})]}),_==="preview"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16},children:[e.jsxs("select",{value:T,onChange:v=>M(v.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.cardBg,color:S.text,fontSize:13},children:[e.jsx("option",{value:"zustand",children:i("stateDesigner.zustand","Zustand")}),e.jsx("option",{value:"redux-toolkit",children:i("stateDesigner.reduxToolkit","Redux Toolkit")}),e.jsx("option",{value:"jotai",children:i("stateDesigner.jotai","Jotai")}),e.jsx("option",{value:"recoil",children:i("stateDesigner.recoil","Recoil")}),e.jsx("option",{value:"mobx",children:i("stateDesigner.mobx","MobX")})]}),e.jsxs("button",{onClick:$,style:{padding:"8px 16px",borderRadius:4,border:"none",background:S.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",i("stateDesigner.export","Export")]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(N),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${S.border}`,background:"transparent",color:S.text,cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"clipboard",size:14})," ",i("stateDesigner.copy","Copy")]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:S.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:N})]})]})}),L&&e.jsx("div",{role:"presentation",style:{position:"fixed",inset:0,background:"var(--nice-overlay-70, rgba(0, 0, 0, 0.7))",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>E(!1),children:e.jsxs("div",{role:"presentation",style:{background:S.cardBg,borderRadius:12,padding:24,width:500,maxHeight:"80vh",overflow:"auto"},onClick:v=>v.stopPropagation(),children:[e.jsxs("h4",{style:{margin:"0 0 16px",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"clipboard",size:16})," ",i("stateDesigner.stateTemplates","State Templates")]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:u.map(v=>e.jsx("button",{onClick:()=>{v.store.slices&&D({slices:[...s.slices,...v.store.slices]}),E(!1)},style:{padding:16,borderRadius:8,border:`1px solid ${S.border}`,background:S.bg,color:S.text,cursor:"pointer",textAlign:"left"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(a.NiceIcon,{name:v.icon,size:24}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:v.name}),e.jsx("div",{style:{fontSize:12,color:S.textMuted},children:v.description})]})]})},v.id))})]})})]})},Gt=Object.freeze(Object.defineProperty({__proto__:null,NiceStateDesigner:xt},Symbol.toStringTag,{value:"Module"})),Yt={id:"api-1",name:"UserAPI",description:"User management API client",baseUrl:"https://api.example.com/v1",version:"1.0.0",endpoints:[{id:"ep-1",name:"getUsers",description:"Get list of users",method:"GET",path:"/users",tags:["users"],queryParams:[{id:"p1",name:"page",type:"number",defaultValue:1},{id:"p2",name:"limit",type:"number",defaultValue:10},{id:"p3",name:"search",type:"string"}],responses:[{status:200,description:"Success",schema:{type:"array",items:{type:"object"}}},{status:401,description:"Unauthorized"}],cache:{enabled:!0,ttl:60,strategy:"stale-while-revalidate"}},{id:"ep-2",name:"getUserById",description:"Get single user by ID",method:"GET",path:"/users/{id}",tags:["users"],pathParams:[{id:"p1",name:"id",type:"string",required:!0}],responses:[{status:200,description:"Success"},{status:404,description:"Not found"}],cache:{enabled:!0,ttl:300,strategy:"cache-first"}},{id:"ep-3",name:"createUser",description:"Create new user",method:"POST",path:"/users",tags:["users"],body:{contentType:"application/json",schema:{type:"object",properties:{name:{type:"string"},email:{type:"string"},role:{type:"string"}},required:["name","email"]}},responses:[{status:201,description:"Created"},{status:400,description:"Validation error"}],retry:{enabled:!0,maxAttempts:3,backoff:"exponential",retryOn:[500,502,503]}},{id:"ep-4",name:"updateUser",description:"Update user by ID",method:"PUT",path:"/users/{id}",tags:["users"],pathParams:[{id:"p1",name:"id",type:"string",required:!0}],body:{contentType:"application/json",schema:{type:"object",properties:{name:{type:"string"},email:{type:"string"}}}},responses:[{status:200,description:"Updated"},{status:404,description:"Not found"}]},{id:"ep-5",name:"deleteUser",description:"Delete user by ID",method:"DELETE",path:"/users/{id}",tags:["users"],pathParams:[{id:"p1",name:"id",type:"string",required:!0}],responses:[{status:204,description:"Deleted"},{status:404,description:"Not found"}]}],auth:{type:"bearer",tokenSource:"state.auth.token",headerName:"Authorization",prefix:"Bearer"},globalHeaders:{"Content-Type":"application/json",Accept:"application/json"},errorHandling:{globalErrorHandler:!0,retryOnNetworkError:!0,transformError:!0},cacheConfig:{enabled:!0,storage:"memory",defaultTTL:300}},je={GET:"var(--nice-color-success, #22c55e)",POST:"var(--nice-color-primary, #3b82f6)",PUT:"var(--nice-color-warning, #f59e0b)",PATCH:"var(--nice-color-accent, #8b5cf6)",DELETE:"var(--nice-color-error, #ef4444)",HEAD:"var(--nice-text-muted, #6b7280)",OPTIONS:"var(--nice-text-muted, #6b7280)"},Zt=n=>{const u=["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';"],p=[];n.endpoints.forEach(r=>{r.body?.schema&&p.push(`export interface ${Le(r.name)}Request ${ht(r.body.schema)}`),p.push(`export interface ${Le(r.name)}Response {
|
|
35
|
-
// TODO: Define response type based on schema
|
|
36
|
-
data: unknown;
|
|
37
|
-
}`)});const g=[];n.endpoints.forEach(r=>{const w=r.pathParams?.map(k=>`${k.name}: ${k.type}`).join(", ")||"",i=r.queryParams?.length?`params?: { ${r.queryParams.map(k=>`${k.name}${k.required?"":"?"}: ${k.type}`).join("; ")} }`:"",s=r.body?`data: ${Le(r.name)}Request`:"",d=[w,i,s].filter(Boolean).join(", ");let _=`'${r.path}'`;r.pathParams?.forEach(k=>{_=_.replace(`{${k.name}}`,`\${${k.name}}`)}),r.pathParams?.length&&(_="`"+_.slice(1,-1)+"`");const C=r.cache?.enabled?`
|
|
38
|
-
// Cache: ${r.cache.strategy}, TTL: ${r.cache.ttl}s`:"",y=r.retry?.enabled?`
|
|
39
|
-
// Retry: ${r.retry.maxAttempts} attempts, ${r.retry.backoff} backoff`:"";g.push(`
|
|
40
|
-
/**
|
|
41
|
-
* ${r.description||r.name}${C}${y}
|
|
42
|
-
*/
|
|
43
|
-
async ${r.name}(${d}): Promise<${Le(r.name)}Response> {
|
|
44
|
-
const response = await this.client.${r.method.toLowerCase()}<${Le(r.name)}Response>(
|
|
45
|
-
${_}${r.queryParams?.length?", { params }":""}${r.body?", data":""}
|
|
46
|
-
);
|
|
47
|
-
return response.data;
|
|
48
|
-
}`)});let m="";n.auth?.type==="bearer"&&(m=`
|
|
49
|
-
// Auth interceptor
|
|
50
|
-
this.client.interceptors.request.use((config) => {
|
|
51
|
-
const token = ${n.auth.tokenSource||"getToken()"};
|
|
52
|
-
if (token) {
|
|
53
|
-
config.headers['${n.auth.headerName||"Authorization"}'] = '${n.auth.prefix||"Bearer"} ' + token;
|
|
54
|
-
}
|
|
55
|
-
return config;
|
|
56
|
-
});`);const c=n.errorHandling?.globalErrorHandler?`
|
|
57
|
-
// Error interceptor
|
|
58
|
-
this.client.interceptors.response.use(
|
|
59
|
-
(response) => response,
|
|
60
|
-
(error) => {
|
|
61
|
-
// Transform and handle errors
|
|
62
|
-
const message = error.response?.data?.message || error.message;
|
|
63
|
-
console.error('[API Error]', message);
|
|
64
|
-
return Promise.reject(error);
|
|
65
|
-
}
|
|
66
|
-
);`:"";return`${u.join(`
|
|
67
|
-
`)}
|
|
68
|
-
|
|
69
|
-
// Types
|
|
70
|
-
${p.join(`
|
|
71
|
-
|
|
72
|
-
`)}
|
|
73
|
-
|
|
74
|
-
// API Client
|
|
75
|
-
export class ${n.name} {
|
|
76
|
-
private client: AxiosInstance;
|
|
77
|
-
|
|
78
|
-
constructor(baseURL: string = '${n.baseUrl}') {
|
|
79
|
-
this.client = axios.create({
|
|
80
|
-
baseURL,
|
|
81
|
-
headers: ${JSON.stringify(n.globalHeaders||{},null,8).replace(/\n/g,`
|
|
82
|
-
`)},
|
|
83
|
-
});
|
|
84
|
-
${m}${c}
|
|
85
|
-
}
|
|
86
|
-
${g.join("")}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Default instance
|
|
90
|
-
export const ${n.name.charAt(0).toLowerCase()+n.name.slice(1)} = new ${n.name}();
|
|
91
|
-
`},Le=n=>n.charAt(0).toUpperCase()+n.slice(1),ht=n=>n.type==="object"&&n.properties?`{
|
|
92
|
-
${Object.entries(n.properties).map(([p,g])=>{const m=n.required?.includes(p)?"":"?";return` ${p}${m}: ${ft(g)};`}).join(`
|
|
93
|
-
`)}
|
|
94
|
-
}`:"{}",ft=n=>{switch(n.type){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return n.items?`${ft(n.items)}[]`:"unknown[]";case"object":return n.properties?ht(n):"Record<string, unknown>";default:return"unknown"}},bt=({flow:n=Yt,dataSources:u=[],onFlowChange:p,onExport:g,onTest:m,onSave:c,className:x,style:r,"data-testid":w})=>{const{t:i}=a.useNiceTranslation(),[s,d]=b.useState(n),[_,C]=b.useState("endpoints"),[y,k]=b.useState(s.endpoints[0]?.id||null),[B,I]=b.useState(!1),[T,M]=b.useState(null),[L,E]=b.useState(!1),h=b.useMemo(()=>s.endpoints.find(t=>t.id===y),[s.endpoints,y]),F=b.useCallback(t=>{const o={...s,...t};d(o),p?.(o)},[s,p]),A=b.useCallback((t,o)=>{const $=s.endpoints.map(N=>N.id===t?{...N,...o}:N);F({endpoints:$})},[s.endpoints,F]),J=t=>{const o={id:`ep-${Date.now()}`,name:"newEndpoint",method:t,path:"/new-path",responses:[{status:200,description:i("apiFlow.success","Success")}]};F({endpoints:[...s.endpoints,o]}),k(o.id),I(!1)},O=t=>{F({endpoints:s.endpoints.filter(o=>o.id!==t)}),y===t&&k(s.endpoints[0]?.id||null)},Y=async()=>{h&&(E(!0),M(null),await new Promise(t=>setTimeout(t,1e3)),M({status:200,body:{message:i("apiFlow.mockResponse","Mock response"),timestamp:new Date().toISOString()}}),E(!1),m?.(h.id))},H=b.useMemo(()=>Zt(s),[s]),D=()=>{g?.(H)};b.useMemo(()=>{const t=new Set;return s.endpoints.forEach(o=>o.tags?.forEach($=>t.add($))),Array.from(t)},[s.endpoints]);const l={bg:"var(--nice-bg-elevated, #1e1e1e)",cardBg:"var(--nice-bg-elevated, #252525)",border:"var(--nice-bg-tertiary, #333)",text:"var(--nice-text-primary, #e0e0e0)",textMuted:"var(--nice-text-muted, #888)",accent:"var(--nice-color-primary, #3b82f6)"};return e.jsxs("div",{className:`nice-api-flow ${x||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:l.bg,color:l.text,fontFamily:"system-ui, sans-serif",...r},"data-testid":w,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${l.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:18},children:[e.jsx(a.NiceIcon,{name:"plug",size:16})," ",i("apiFlow.apiFlow","API Flow")]}),e.jsx("input",{type:"text",value:s.name,onChange:t=>F({name:t.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:14,fontWeight:600}}),e.jsx("input",{type:"text",value:s.baseUrl,onChange:t=>F({baseUrl:t.target.value}),placeholder:i("apiFlow.baseUrl","Base URL"),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,width:300}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>c?.(s),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"var(--nice-color-success, #22c55e)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13,fontWeight:500},children:[e.jsx(a.NiceIcon,{name:"save",size:14})," ",i("apiFlow.save","Save")]})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${l.border}`,padding:"0 20px"},children:["endpoints","auth","settings","test","preview"].map(t=>e.jsxs("button",{onClick:()=>C(t),style:{padding:"12px 20px",border:"none",background:"transparent",color:_===t?l.text:l.textMuted,cursor:"pointer",fontSize:13,fontWeight:_===t?600:400,borderBottom:_===t?`2px solid ${l.accent}`:"2px solid transparent",marginBottom:-1},children:[t==="endpoints"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"link",size:14})," ",i("apiFlow.endpoints","Endpoints")]}),t==="auth"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"lock",size:14})," ",i("apiFlow.auth","Auth")]}),t==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"settings",size:14})," ",i("apiFlow.settings","Settings")]}),t==="test"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"flask",size:14})," ",i("apiFlow.test","Test")]}),t==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"eye",size:14})," ",i("apiFlow.preview","Preview")]})]},t))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[_==="endpoints"&&e.jsxs("div",{style:{width:280,borderRight:`1px solid ${l.border}`,padding:12,display:"flex",flexDirection:"column",gap:4,overflow:"auto"},children:[e.jsx("div",{style:{fontSize:11,color:l.textMuted,marginBottom:8},children:i("apiFlow.endpoints2","ENDPOINTS ({endpoints})").replace("{endpoints}",String(s.endpoints.length))}),s.endpoints.map(t=>e.jsxs("button",{onClick:()=>k(t.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:y===t.id?l.accent+"30":l.cardBg,color:l.text,cursor:"pointer",textAlign:"left",display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{padding:"2px 6px",borderRadius:4,background:je[t.method]+"30",color:je[t.method],fontSize:10,fontWeight:600},children:t.method}),e.jsxs("div",{style:{flex:1,overflow:"hidden"},children:[e.jsx("div",{style:{fontFamily:"monospace",fontSize:12},children:t.name}),e.jsx("div",{style:{fontSize:10,color:l.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.path})]})]},t.id)),e.jsx("button",{onClick:()=>I(!0),style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${l.border}`,background:"transparent",color:l.textMuted,cursor:"pointer",fontSize:13,marginTop:8},children:i("apiFlow.addEndpoint2","+ Add Endpoint")})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[_==="endpoints"&&h&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[e.jsx("select",{value:h.method,onChange:t=>A(h.id,{method:t.target.value}),style:{padding:"8px 12px",borderRadius:6,border:"none",background:je[h.method]+"30",color:je[h.method],fontSize:13,fontWeight:600,cursor:"pointer"},children:["GET","POST","PUT","PATCH","DELETE"].map(t=>e.jsx("option",{value:t,children:t},t))}),e.jsx("input",{type:"text",value:h.path,onChange:t=>A(h.id,{path:t.target.value}),style:{flex:1,padding:"8px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:14,fontFamily:"monospace"}}),e.jsxs("button",{onClick:()=>O(h.id),style:{padding:"8px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"trash",size:14})," ",i("apiFlow.delete","Delete")]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:16,marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:l.textMuted,marginBottom:4},children:i("apiFlow.name","Name")}),e.jsx("input",{type:"text",value:h.name,onChange:t=>A(h.id,{name:t.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:l.textMuted,marginBottom:4},children:i("apiFlow.description","Description")}),e.jsx("input",{type:"text",value:h.description||"",onChange:t=>A(h.id,{description:t.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,boxSizing:"border-box"}})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsxs("h4",{style:{margin:"0 0 12px",display:"flex",alignItems:"center",gap:8},children:[e.jsx(a.NiceIcon,{name:"clipboard",size:14})," ",i("apiFlow.parameters","Parameters")]}),h.pathParams&&h.pathParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:l.textMuted,marginBottom:8},children:i("apiFlow.pathParameters","PATH PARAMETERS")}),h.pathParams.map(t=>e.jsxs("div",{style:{padding:12,background:l.cardBg,borderRadius:6,marginBottom:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("code",{style:{fontWeight:600},children:t.name}),e.jsx("span",{style:{color:l.textMuted,fontSize:12},children:t.type}),t.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)",fontSize:10},children:i("apiFlow.required","required")})]},t.id))]}),h.queryParams&&h.queryParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:l.textMuted,marginBottom:8},children:i("apiFlow.queryParameters","QUERY PARAMETERS")}),h.queryParams.map(t=>e.jsxs("div",{style:{padding:12,background:l.cardBg,borderRadius:6,marginBottom:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("code",{style:{fontWeight:600},children:t.name}),e.jsx("span",{style:{color:l.textMuted,fontSize:12},children:t.type}),t.defaultValue!==void 0&&e.jsxs("span",{style:{color:"var(--nice-color-warning, #f59e0b)",fontSize:11},children:["= ",JSON.stringify(t.defaultValue)]})]},t.id))]}),h.body&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:l.textMuted,marginBottom:8},children:i("apiFlow.requestBody","REQUEST BODY")}),e.jsxs("div",{style:{padding:12,background:l.cardBg,borderRadius:6},children:[e.jsxs("div",{style:{fontSize:12,marginBottom:8},children:["Content-Type: ",e.jsx("code",{children:h.body.contentType})]}),h.body.schema&&e.jsx("pre",{style:{margin:0,padding:12,background:l.bg,borderRadius:4,fontSize:11,overflow:"auto"},children:JSON.stringify(h.body.schema,null,2)})]})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsxs("h4",{style:{margin:"0 0 12px"},children:[e.jsx(a.NiceIcon,{name:"upload",size:16})," ",i("apiFlow.responses","Responses")]}),e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:h.responses.map(t=>e.jsxs("div",{style:{padding:12,background:l.cardBg,borderRadius:6,minWidth:120},children:[e.jsx("div",{style:{fontSize:18,fontWeight:600,color:t.status<300?"var(--nice-color-success, #22c55e)":t.status<400?"var(--nice-color-warning, #f59e0b)":"var(--nice-color-error, #ef4444)"},children:t.status}),e.jsx("div",{style:{fontSize:11,color:l.textMuted},children:t.description})]},t.status))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{style:{padding:16,background:l.cardBg,borderRadius:8},children:[e.jsxs("h5",{style:{margin:"0 0 12px",display:"flex",alignItems:"center",gap:8},children:[e.jsx("input",{type:"checkbox",checked:h.cache?.enabled||!1,onChange:t=>A(h.id,{cache:{...h.cache,enabled:t.target.checked}})}),e.jsx(a.NiceIcon,{name:"box",size:14})," ",i("apiFlow.cache","Cache")]}),h.cache?.enabled&&e.jsx("div",{style:{fontSize:12,color:l.textMuted},children:i("apiFlow.ttlSStrategy","TTL: {ttl}s • Strategy: {strategy}").replace("{ttl}",String(h.cache.ttl)).replace("{strategy}",String(h.cache.strategy))})]}),e.jsxs("div",{style:{padding:16,background:l.cardBg,borderRadius:8},children:[e.jsxs("h5",{style:{margin:"0 0 12px",display:"flex",alignItems:"center",gap:8},children:[e.jsx("input",{type:"checkbox",checked:h.retry?.enabled||!1,onChange:t=>A(h.id,{retry:{...h.retry,enabled:t.target.checked,maxAttempts:3,backoff:"exponential"}})}),e.jsx(a.NiceIcon,{name:"refresh",size:14})," ",i("apiFlow.retry","Retry")]}),h.retry?.enabled&&e.jsx("div",{style:{fontSize:12,color:l.textMuted},children:i("apiFlow.maxBackoff","Max: {maxAttempts} • {backoff} backoff").replace("{maxAttempts}",String(h.retry.maxAttempts)).replace("{backoff}",String(h.retry.backoff))})]})]})]}),_==="auth"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsxs("h4",{style:{marginTop:0},children:[e.jsx(a.NiceIcon,{name:"lock",size:16})," ",i("apiFlow.authentication","Authentication")]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:l.textMuted,marginBottom:8},children:i("apiFlow.authType","Auth Type")}),e.jsxs("select",{value:s.auth?.type||"none",onChange:t=>F({auth:{...s.auth,type:t.target.value}}),style:{padding:"10px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,width:"100%"},children:[e.jsx("option",{value:"none",children:i("apiFlow.none","None")}),e.jsx("option",{value:"bearer",children:i("apiFlow.bearerToken","Bearer Token")}),e.jsx("option",{value:"basic",children:i("apiFlow.basicAuth","Basic Auth")}),e.jsx("option",{value:"api-key",children:i("apiFlow.apiKey","API Key")}),e.jsx("option",{value:"oauth2",children:i("apiFlow.oauth20","OAuth 2.0")})]})]}),s.auth?.type==="bearer"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:l.textMuted,marginBottom:8},children:i("apiFlow.tokenSource","Token Source")}),e.jsx("input",{type:"text",value:s.auth.tokenSource||"",onChange:t=>F({auth:{...s.auth,tokenSource:t.target.value}}),placeholder:"state.auth.token",style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:l.textMuted,marginBottom:8},children:i("apiFlow.headerName","Header Name")}),e.jsx("input",{type:"text",value:s.auth.headerName||"Authorization",onChange:t=>F({auth:{...s.auth,headerName:t.target.value}}),style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,boxSizing:"border-box"}})]})]}),e.jsxs("h4",{children:[e.jsx(a.NiceIcon,{name:"globe",size:16})," ",i("apiFlow.globalHeaders","Global Headers")]}),e.jsx("div",{style:{padding:16,background:l.cardBg,borderRadius:8},children:Object.entries(s.globalHeaders||{}).map(([t,o])=>e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1},children:t}),e.jsx("span",{style:{color:l.textMuted},children:":"}),e.jsx("code",{style:{flex:2,color:"var(--nice-color-success, #22c55e)"},children:o})]},t))})]}),_==="settings"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsxs("h4",{style:{marginTop:0},children:[e.jsx(a.NiceIcon,{name:"settings",size:16})," ",i("apiFlow.globalSettings","Global Settings")]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h5",{children:i("apiFlow.errorHandling","Error Handling")}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:s.errorHandling?.globalErrorHandler||!1,onChange:t=>F({errorHandling:{...s.errorHandling,globalErrorHandler:t.target.checked}})}),i("apiFlow.globalErrorHandler","Global error handler")]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:s.errorHandling?.retryOnNetworkError||!1,onChange:t=>F({errorHandling:{...s.errorHandling,retryOnNetworkError:t.target.checked}})}),i("apiFlow.retryOnNetworkErrors","Retry on network errors")]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:s.errorHandling?.transformError||!1,onChange:t=>F({errorHandling:{...s.errorHandling,transformError:t.target.checked}})}),i("apiFlow.transformErrorResponses","Transform error responses")]})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h5",{children:i("apiFlow.defaultCacheSettings","Default Cache Settings")}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:s.cacheConfig?.enabled||!1,onChange:t=>F({cacheConfig:{...s.cacheConfig,enabled:t.target.checked}})}),i("apiFlow.enableCaching","Enable caching")]}),s.cacheConfig?.enabled&&e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:12,color:l.textMuted},children:i("apiFlow.storage","Storage")}),e.jsxs("select",{value:s.cacheConfig.storage,onChange:t=>F({cacheConfig:{...s.cacheConfig,storage:t.target.value}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13},children:[e.jsx("option",{value:"memory",children:i("apiFlow.memory","Memory")}),e.jsx("option",{value:"localStorage",children:"localStorage"}),e.jsx("option",{value:"sessionStorage",children:"sessionStorage"})]})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:12,color:l.textMuted},children:i("apiFlow.defaultTtlSeconds","Default TTL (seconds)")}),e.jsx("input",{type:"number",value:s.cacheConfig.defaultTTL,onChange:t=>F({cacheConfig:{...s.cacheConfig,defaultTTL:parseInt(t.target.value)}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:13,width:100}})]})]})]})]}),_==="test"&&h&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[e.jsx("span",{style:{padding:"4px 8px",borderRadius:4,background:je[h.method]+"30",color:je[h.method],fontSize:12,fontWeight:600},children:h.method}),e.jsxs("code",{style:{flex:1,fontSize:14},children:[s.baseUrl,h.path]}),e.jsx("button",{onClick:Y,disabled:L,style:{padding:"10px 20px",borderRadius:6,border:"none",background:l.accent,color:"var(--nice-color-white, #fff)",cursor:L?"not-allowed":"pointer",fontSize:13,fontWeight:500,opacity:L?.7:1},children:L?e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"clock",size:14})," ",i("apiFlow.testing","Testing...")]}):e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"rocket",size:14})," ",i("apiFlow.sendRequest","Send Request")]})})]}),T&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsx("span",{style:{fontSize:18,fontWeight:600,color:T.status<300?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"},children:T.status}),e.jsx("span",{style:{color:l.textMuted},children:T.status<300?i("apiFlow.ok","OK"):i("apiFlow.error","Error")})]}),e.jsx("pre",{style:{padding:16,background:l.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0},children:JSON.stringify(T.body,null,2)})]})]}),_==="preview"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("button",{onClick:D,style:{padding:"8px 16px",borderRadius:4,border:"none",background:l.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",i("apiFlow.export","Export")]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(H),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${l.border}`,background:"transparent",color:l.text,cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"clipboard",size:14})," ",i("apiFlow.copy","Copy")]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:l.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:H})]})]})]}),B&&e.jsx("div",{role:"presentation",style:{position:"fixed",inset:0,background:"var(--nice-overlay-70, rgba(0, 0, 0, 0.7))",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>I(!1),children:e.jsxs("div",{role:"presentation",style:{background:l.cardBg,borderRadius:12,padding:24,width:400},onClick:t=>t.stopPropagation(),children:[e.jsxs("h4",{style:{margin:"0 0 16px"},children:[e.jsx(a.NiceIcon,{name:"plus",size:16})," ",i("apiFlow.addEndpoint","Add Endpoint")]}),e.jsx("p",{style:{color:l.textMuted,fontSize:13,marginBottom:16},children:i("apiFlow.selectHttpMethodForNew","Select HTTP method for new endpoint:")}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["GET","POST","PUT","PATCH","DELETE"].map(t=>e.jsx("button",{onClick:()=>J(t),style:{padding:"12px 24px",borderRadius:6,border:"none",background:je[t]+"30",color:je[t],cursor:"pointer",fontSize:14,fontWeight:600},children:t},t))})]})})]})},Qt=Object.freeze(Object.defineProperty({__proto__:null,NiceAPIFlow:bt},Symbol.toStringTag,{value:"Module"})),Xt={id:"map-1",name:"UserToContact",description:"Transform User API response to Contact entity",sourceSchema:{name:"UserResponse",type:"object",fields:[{id:"s1",name:"id",path:"id",type:"number"},{id:"s2",name:"firstName",path:"firstName",type:"string"},{id:"s3",name:"lastName",path:"lastName",type:"string"},{id:"s4",name:"email",path:"email",type:"string"},{id:"s5",name:"phone",path:"phone",type:"string",nullable:!0},{id:"s6",name:"address",path:"address",type:"object",children:[{id:"s6a",name:"street",path:"address.street",type:"string"},{id:"s6b",name:"city",path:"address.city",type:"string"},{id:"s6c",name:"zipCode",path:"address.zipCode",type:"string"},{id:"s6d",name:"country",path:"address.country",type:"string"}]},{id:"s7",name:"metadata",path:"metadata",type:"object",children:[{id:"s7a",name:"createdAt",path:"metadata.createdAt",type:"date"},{id:"s7b",name:"updatedAt",path:"metadata.updatedAt",type:"date"}]}]},targetSchema:{name:"Contact",type:"object",fields:[{id:"t1",name:"contactId",path:"contactId",type:"string"},{id:"t2",name:"fullName",path:"fullName",type:"string"},{id:"t3",name:"emailAddress",path:"emailAddress",type:"string"},{id:"t4",name:"phoneNumber",path:"phoneNumber",type:"string",nullable:!0},{id:"t5",name:"location",path:"location",type:"string"},{id:"t6",name:"fullAddress",path:"fullAddress",type:"string"},{id:"t7",name:"createdDate",path:"createdDate",type:"string"},{id:"t8",name:"isActive",path:"isActive",type:"boolean"}]},fieldMappings:[{id:"m1",sourceField:"id",targetField:"contactId",transform:"tr-1"},{id:"m2",sourceField:"firstName,lastName",targetField:"fullName",transform:"tr-2"},{id:"m3",sourceField:"email",targetField:"emailAddress"},{id:"m4",sourceField:"phone",targetField:"phoneNumber",defaultValue:""},{id:"m5",sourceField:"address.city,address.country",targetField:"location",transform:"tr-3"},{id:"m6",sourceField:"address",targetField:"fullAddress",transform:"tr-4"},{id:"m7",sourceField:"metadata.createdAt",targetField:"createdDate",transform:"tr-5"},{id:"m8",sourceField:"",targetField:"isActive",defaultValue:!0}],transformations:[{id:"tr-1",name:"ID to String",type:"format",config:{format:"USR-{value}"}},{id:"tr-2",name:"Full Name",type:"concat",config:{separator:" "}},{id:"tr-3",name:"Location",type:"concat",config:{separator:", "}},{id:"tr-4",name:"Full Address",type:"custom",config:{expression:"`${address.street}, ${address.zipCode} ${address.city}, ${address.country}`"}},{id:"tr-5",name:"Format Date",type:"format",config:{format:"YYYY-MM-DD"}}],validationRules:[{id:"v1",field:"emailAddress",type:"required",message:"Email is required"},{id:"v2",field:"emailAddress",type:"pattern",value:"^\\S+@\\S+\\.\\S+$",message:"Invalid email format"},{id:"v3",field:"contactId",type:"required",message:"Contact ID is required"}]},st={string:"var(--nice-color-success, #22c55e)",number:"var(--nice-color-primary, #3b82f6)",boolean:"var(--nice-color-warning, #f59e0b)",date:"var(--nice-color-accent, #8b5cf6)",array:"var(--nice-color-info, #06b6d4)",object:"var(--nice-color-accent-pink, #ec4899)",any:"var(--nice-text-muted, #6b7280)"},ot={string:"edit",number:"hash",boolean:"check",date:"calendar",array:"clipboard",object:"box",any:"help"},at={direct:"arrow-right",format:"edit",convert:"refresh",concat:"link",split:"shuffle",calculate:"hash",lookup:"search",conditional:"help",custom:"settings"},en=n=>{const u=lt(n.sourceSchema),p=lt(n.targetSchema),g=n.fieldMappings.map(c=>{const x=n.transformations.find(i=>i.id===c.transform),r=c.targetField;if(!c.sourceField)return` result.${r} = ${JSON.stringify(c.defaultValue)};`;const w=c.sourceField.split(",").map(i=>i.trim());if(x)switch(x.type){case"concat":return` result.${r} = [${w.map(i=>`source.${i}`).join(", ")}].filter(Boolean).join('${x.config.separator||" "}');`;case"format":if(w.length===1){const i=x.config.format||"{value}";return i.includes("{value}")?` result.${r} = '${i}'.replace('{value}', String(source.${w[0]}));`:` result.${r} = formatDate(source.${w[0]}, '${i}');`}break;case"custom":return` result.${r} = ${x.config.expression?.replace(/(\w+)\.(\w+)/g,"source.$1.$2")};`;case"convert":return` result.${r} = ${x.config.convertTo}(source.${w[0]});`}if(w.length===1){const i=c.defaultValue!==void 0?` ?? ${JSON.stringify(c.defaultValue)}`:"";return` result.${r} = source.${w[0]}${i};`}return` // TODO: Manual mapping for ${r}`}),m=n.validationRules.map(c=>{switch(c.type){case"required":return` if (!data.${c.field}) errors.push('${c.message||c.field+" is required"}');`;case"pattern":return` if (data.${c.field} && !/${c.value}/.test(data.${c.field})) errors.push('${c.message||"Invalid format"}');`;default:return` // ${c.type} validation for ${c.field}`}});return`/**
|
|
95
|
-
* ${n.name}
|
|
96
|
-
* ${n.description||""}
|
|
97
|
-
* Auto-generated by NiceDataMapper
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
// Source Type
|
|
101
|
-
${u}
|
|
102
|
-
|
|
103
|
-
// Target Type
|
|
104
|
-
${p}
|
|
105
|
-
|
|
106
|
-
// Validation
|
|
107
|
-
export function validate${n.targetSchema.name}(data: ${n.targetSchema.name}): string[] {
|
|
108
|
-
const errors: string[] = [];
|
|
109
|
-
${m.join(`
|
|
110
|
-
`)}
|
|
111
|
-
return errors;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Mapper
|
|
115
|
-
export function ${n.name.charAt(0).toLowerCase()+n.name.slice(1)}(source: ${n.sourceSchema.name}): ${n.targetSchema.name} {
|
|
116
|
-
const result = {} as ${n.targetSchema.name};
|
|
117
|
-
|
|
118
|
-
${g.join(`
|
|
119
|
-
`)}
|
|
120
|
-
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Helper functions
|
|
125
|
-
function formatDate(date: string | Date, format: string): string {
|
|
126
|
-
const d = typeof date === 'string' ? new Date(date) : date;
|
|
127
|
-
const year = d.getFullYear();
|
|
128
|
-
const month = String(d.getMonth() + 1).padStart(2, '0');
|
|
129
|
-
const day = String(d.getDate()).padStart(2, '0');
|
|
130
|
-
return format
|
|
131
|
-
.replace('YYYY', String(year))
|
|
132
|
-
.replace('MM', month)
|
|
133
|
-
.replace('DD', day);
|
|
134
|
-
}
|
|
135
|
-
`},lt=(n,u)=>{const p=(m,c)=>{const x=" ".repeat(c),r=m.nullable?"?":"";if(m.type==="object"&&m.children){const i=m.children.map(s=>p(s,c+1)).join(`
|
|
136
|
-
`);return`${x}${m.name}${r}: {
|
|
137
|
-
${i}
|
|
138
|
-
${x}};`}const w={string:"string",number:"number",boolean:"boolean",date:"string | Date",array:"unknown[]",object:"Record<string, unknown>",any:"unknown"}[m.type];return`${x}${m.name}${r}: ${w};`},g=n.fields.map(m=>p(m,1)).join(`
|
|
139
|
-
`);return`interface ${n.name} {
|
|
140
|
-
${g}
|
|
141
|
-
}`},Ze=(n,u="")=>{const p=[];return n.forEach(g=>{p.push(g),g.children&&p.push(...Ze(g.children,g.path+"."))}),p},yt=({mapping:n=Xt,sourceSchemas:u=[],targetSchemas:p=[],onMappingChange:g,onExport:m,onTest:c,onSave:x,className:r,style:w,"data-testid":i})=>{const{t:s}=a.useNiceTranslation(),[d,_]=b.useState(n),[C,y]=b.useState("mapping"),[k,B]=b.useState(null),[I,T]=b.useState(""),[M,L]=b.useState(""),[E,h]=b.useState(null),F=b.useCallback(t=>{const o={...d,...t};_(o),g?.(o)},[d,g]),A=b.useMemo(()=>Ze(d.sourceSchema.fields),[d.sourceSchema.fields]),J=b.useMemo(()=>Ze(d.targetSchema.fields),[d.targetSchema.fields]),O=(t,o)=>{const $={id:`mapping-${Date.now()}`,sourceField:t,targetField:o};F({fieldMappings:[...d.fieldMappings,$]})},Y=t=>{F({fieldMappings:d.fieldMappings.filter(o=>o.id!==t)})},H=()=>{try{const t=JSON.parse(I),o={};d.fieldMappings.forEach($=>{if(!$.sourceField){o[$.targetField]=$.defaultValue;return}const N=$.sourceField.split(",").map(f=>f.trim()),S=f=>f.split(".").reduce((ie,ae)=>ie?.[ae],t),P=d.transformations.find(f=>f.id===$.transform);if(P?.type==="concat")o[$.targetField]=N.map(S).filter(Boolean).join(P.config.separator||" ");else if(P?.type==="format"&&N.length===1){const f=S(N[0]);o[$.targetField]=(P.config.format||"{value}").replace("{value}",String(f))}else N.length===1&&(o[$.targetField]=S(N[0])??$.defaultValue)}),L(JSON.stringify(o,null,2)),c?.(o)}catch(t){L(`Error: ${t.message}`)}},D=b.useMemo(()=>en(d),[d]),l={bg:"var(--nice-bg-elevated, #1e1e1e)",cardBg:"var(--nice-bg-elevated, #252525)",border:"var(--nice-bg-tertiary, #333)",text:"var(--nice-text-primary, #e0e0e0)",textMuted:"var(--nice-text-muted, #888)",accent:"var(--nice-color-primary, #3b82f6)"};return e.jsxs("div",{className:`nice-data-mapper ${r||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:l.bg,color:l.text,fontFamily:"system-ui, sans-serif",...w},"data-testid":i,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${l.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:18,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"refresh",size:16})," ",s("dataMapper.dataMapper","Data Mapper")]}),e.jsx("input",{type:"text",value:d.name,onChange:t=>F({name:t.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:14,fontWeight:600}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>x?.(d),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"var(--nice-color-success, #22c55e)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13,fontWeight:500},children:[e.jsx(a.NiceIcon,{name:"save",size:14})," ",s("dataMapper.save","Save")]})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${l.border}`,padding:"0 20px"},children:["mapping","transforms","validation","test","preview"].map(t=>e.jsxs("button",{onClick:()=>y(t),style:{padding:"12px 20px",border:"none",background:"transparent",color:C===t?l.text:l.textMuted,cursor:"pointer",fontSize:13,fontWeight:C===t?600:400,borderBottom:C===t?`2px solid ${l.accent}`:"2px solid transparent",marginBottom:-1},children:[t==="mapping"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"link",size:14})," ",s("dataMapper.mapping","Mapping")]}),t==="transforms"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"zap",size:14})," ",s("dataMapper.transforms","Transforms")]}),t==="validation"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"check",size:14})," ",s("dataMapper.validation","Validation")]}),t==="test"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"flask",size:14})," ",s("dataMapper.test","Test")]}),t==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"eye",size:14})," ",s("dataMapper.preview","Preview")]})]},t))}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[C==="mapping"&&e.jsxs("div",{style:{display:"flex",gap:24,height:"100%"},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"var(--nice-success-tint-12, #22c55e20)",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:[e.jsx(a.NiceIcon,{name:"download",size:14})," ",s("dataMapper.source","Source: {name}").replace("{name}",String(d.sourceSchema.name))]}),e.jsx("div",{style:{flex:1,border:`1px solid ${l.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:A.map(t=>{const o=t.path.split(".").length-1,$=d.fieldMappings.some(N=>N.sourceField.split(",").some(S=>S.trim()===t.path));return e.jsxs("div",{draggable:!0,onDragStart:()=>h(t.path),onDragEnd:()=>h(null),style:{padding:"10px 12px",paddingLeft:12+o*16,borderBottom:`1px solid ${l.border}`,display:"flex",alignItems:"center",gap:8,cursor:"grab",background:$?"var(--nice-success-tint-10, #22c55e10)":"transparent",opacity:t.type==="object"&&t.children?.7:1},children:[e.jsx("span",{style:{color:st[t.type],fontSize:14},children:e.jsx(a.NiceIcon,{name:ot[t.type],size:14})}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:t.name}),e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:t.type}),$&&e.jsx("span",{style:{marginLeft:"auto",color:"var(--nice-color-success, #22c55e)",fontSize:10},children:e.jsx(a.NiceIcon,{name:"check",size:14})})]},t.id)})})]}),e.jsxs("div",{style:{width:300,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:l.accent+"20",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:[e.jsx(a.NiceIcon,{name:"link",size:16})," ",s("dataMapper.mappings","Mappings ({fieldMappings})").replace("{fieldMappings}",String(d.fieldMappings.length))]}),e.jsx("div",{style:{flex:1,border:`1px solid ${l.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto",padding:8},children:d.fieldMappings.map(t=>{const o=d.transformations.find($=>$.id===t.transform);return e.jsxs("div",{style:{padding:8,background:l.cardBg,borderRadius:6,marginBottom:8,fontSize:11},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginBottom:4},children:[e.jsx("code",{style:{color:"var(--nice-color-success, #22c55e)"},children:t.sourceField||"(default)"}),e.jsx("span",{style:{color:l.textMuted},children:e.jsx(a.NiceIcon,{name:"arrow-right",size:12})}),e.jsx("code",{style:{color:"var(--nice-color-primary, #3b82f6)"},children:t.targetField}),e.jsx("button",{onClick:()=>Y(t.id),"aria-label":s("dataMapper.removeMapping","Remove mapping"),style:{marginLeft:"auto",padding:2,border:"none",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:10},children:e.jsx(a.NiceIcon,{name:"close",size:14})})]}),o&&e.jsxs("div",{style:{color:l.textMuted,display:"flex",alignItems:"center",gap:4},children:[e.jsx(a.NiceIcon,{name:at[o.type],size:14})," ",o.name]}),t.defaultValue!==void 0&&e.jsx("div",{style:{color:"var(--nice-color-warning, #f59e0b)"},children:s("dataMapper.default","Default: {defaultValue}").replace("{defaultValue}",String(JSON.stringify(t.defaultValue)))})]},t.id)})})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"var(--nice-primary-tint-12, #3b82f620)",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",s("dataMapper.target","Target: {name}").replace("{name}",String(d.targetSchema.name))]}),e.jsx("div",{style:{flex:1,border:`1px solid ${l.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:J.map(t=>{const o=t.path.split(".").length-1,$=d.fieldMappings.some(N=>N.targetField===t.path);return e.jsxs("div",{onDragOver:N=>N.preventDefault(),onDrop:()=>{E&&!$&&O(E,t.path)},style:{padding:"10px 12px",paddingLeft:12+o*16,borderBottom:`1px solid ${l.border}`,display:"flex",alignItems:"center",gap:8,background:E&&!$?l.accent+"10":$?"color-mix(in srgb, var(--nice-color-primary, #3b82f6) 6%, transparent)":"transparent",transition:"background 0.15s"},children:[e.jsx("span",{style:{color:st[t.type],fontSize:14},children:e.jsx(a.NiceIcon,{name:ot[t.type],size:14})}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:t.name}),e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:t.type}),t.nullable&&e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:"?"}),$&&e.jsx("span",{style:{marginLeft:"auto",color:"var(--nice-color-primary, #3b82f6)",fontSize:10},children:e.jsx(a.NiceIcon,{name:"check",size:14})})]},t.id)})})]})]}),C==="transforms"&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"zap",size:16})," ",s("dataMapper.transformations","Transformations")]}),e.jsx("button",{onClick:()=>{const t={id:`tr-${Date.now()}`,name:"New Transform",type:"direct",config:{}};F({transformations:[...d.transformations,t]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:l.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:s("dataMapper.addTransform","+ Add Transform")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:16},children:d.transformations.map(t=>e.jsxs("div",{style:{padding:16,background:l.cardBg,borderRadius:8,border:`1px solid ${l.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx("span",{style:{fontSize:20},children:e.jsx(a.NiceIcon,{name:at[t.type],size:20})}),e.jsx("input",{type:"text",value:t.name,onChange:o=>{const $=d.transformations.map(N=>N.id===t.id?{...N,name:o.target.value}:N);F({transformations:$})},style:{flex:1,padding:"6px 8px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:13,fontWeight:600}})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:l.textMuted,marginBottom:4},children:s("dataMapper.type","Type")}),e.jsxs("select",{value:t.type,onChange:o=>{const $=d.transformations.map(N=>N.id===t.id?{...N,type:o.target.value}:N);F({transformations:$})},style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12},children:[e.jsx("option",{value:"direct",children:s("dataMapper.direct","Direct")}),e.jsx("option",{value:"format",children:s("dataMapper.format","Format")}),e.jsx("option",{value:"convert",children:s("dataMapper.convert","Convert")}),e.jsx("option",{value:"concat",children:s("dataMapper.concatenate","Concatenate")}),e.jsx("option",{value:"split",children:s("dataMapper.split","Split")}),e.jsx("option",{value:"calculate",children:s("dataMapper.calculate","Calculate")}),e.jsx("option",{value:"lookup",children:s("dataMapper.lookup","Lookup")}),e.jsx("option",{value:"conditional",children:s("dataMapper.conditional","Conditional")}),e.jsx("option",{value:"custom",children:s("dataMapper.custom","Custom")})]})]}),(t.type==="format"||t.type==="concat")&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:l.textMuted,marginBottom:4},children:t.type==="format"?s("dataMapper.formatPattern","Format Pattern"):s("dataMapper.separator","Separator")}),e.jsx("input",{type:"text",value:t.type==="format"?t.config.format||"":t.config.separator||"",onChange:o=>{const $=d.transformations.map(N=>N.id===t.id?{...N,config:{...N.config,[t.type==="format"?"format":"separator"]:o.target.value}}:N);F({transformations:$})},placeholder:t.type==="format"?s("dataMapper.orYyyyMmDd","{value} or YYYY-MM-DD"):", ",style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12,fontFamily:"monospace",boxSizing:"border-box"}})]}),t.type==="custom"&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:l.textMuted,marginBottom:4},children:s("dataMapper.expression","Expression")}),e.jsx("textarea",{value:t.config.expression||"",onChange:o=>{const $=d.transformations.map(N=>N.id===t.id?{...N,config:{...N.config,expression:o.target.value}}:N);F({transformations:$})},rows:3,style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12,fontFamily:"monospace",resize:"vertical",boxSizing:"border-box"}})]})]},t.id))})]}),C==="validation"&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"check",size:16})," ",s("dataMapper.validationRules","Validation Rules")]}),e.jsx("button",{onClick:()=>{const t={id:`v-${Date.now()}`,field:"",type:"required",message:""};F({validationRules:[...d.validationRules,t]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:l.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:s("dataMapper.addRule","+ Add Rule")})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:d.validationRules.map(t=>e.jsxs("div",{style:{padding:16,background:l.cardBg,borderRadius:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsxs("select",{value:t.field,onChange:o=>{const $=d.validationRules.map(N=>N.id===t.id?{...N,field:o.target.value}:N);F({validationRules:$})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12},children:[e.jsx("option",{value:"",children:s("dataMapper.selectField","Select field...")}),J.map(o=>e.jsx("option",{value:o.path,children:o.path},o.id))]}),e.jsxs("select",{value:t.type,onChange:o=>{const $=d.validationRules.map(N=>N.id===t.id?{...N,type:o.target.value}:N);F({validationRules:$})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12},children:[e.jsx("option",{value:"required",children:s("dataMapper.required","Required")}),e.jsx("option",{value:"type",children:s("dataMapper.type","Type")}),e.jsx("option",{value:"min",children:s("dataMapper.min","Min")}),e.jsx("option",{value:"max",children:s("dataMapper.max","Max")}),e.jsx("option",{value:"pattern",children:s("dataMapper.pattern","Pattern")}),e.jsx("option",{value:"enum",children:s("dataMapper.enum","Enum")}),e.jsx("option",{value:"custom",children:s("dataMapper.custom","Custom")})]}),(t.type==="pattern"||t.type==="min"||t.type==="max")&&e.jsx("input",{type:"text",value:String(t.value||""),onChange:o=>{const $=d.validationRules.map(N=>N.id===t.id?{...N,value:o.target.value}:N);F({validationRules:$})},placeholder:s("dataMapper.value","Value"),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12,width:150}}),e.jsx("input",{type:"text",value:t.message||"",onChange:o=>{const $=d.validationRules.map(N=>N.id===t.id?{...N,message:o.target.value}:N);F({validationRules:$})},placeholder:s("dataMapper.errorMessage","Error message"),style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${l.border}`,background:l.bg,color:l.text,fontSize:12}}),e.jsx("button",{onClick:()=>{F({validationRules:d.validationRules.filter(o=>o.id!==t.id)})},"aria-label":s("dataMapper.delete","Delete"),style:{padding:6,border:"none",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:14},children:e.jsx(a.NiceIcon,{name:"trash",size:14})})]},t.id))})]}),C==="test"&&e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:20,height:"100%"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"download",size:16})," ",s("dataMapper.input","Input")]}),e.jsx("button",{onClick:()=>{const t={},o=($,N)=>{$.forEach(S=>{S.children&&S.type==="object"?(N[S.name]={},o(S.children,N[S.name])):N[S.name]={string:"sample",number:42,boolean:!0,date:new Date().toISOString(),array:[],object:{},any:null}[S.type]})};o(d.sourceSchema.fields,t),T(JSON.stringify(t,null,2))},style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${l.border}`,background:"transparent",color:l.text,cursor:"pointer",fontSize:11},children:s("dataMapper.generateSample","Generate Sample")})]}),e.jsx("textarea",{value:I,onChange:t=>T(t.target.value),placeholder:s("dataMapper.pasteJsonInputHere","Paste JSON input here..."),style:{flex:1,padding:12,borderRadius:8,border:`1px solid ${l.border}`,background:l.cardBg,color:l.text,fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",resize:"none"}})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsxs("h4",{style:{margin:0,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"upload",size:16})," ",s("dataMapper.output","Output")]}),e.jsxs("button",{onClick:H,style:{padding:"6px 16px",borderRadius:4,border:"none",background:l.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:[e.jsx(a.NiceIcon,{name:"refresh",size:14})," ",s("dataMapper.transform","Transform")]})]}),e.jsx("pre",{style:{flex:1,padding:12,borderRadius:8,background:l.cardBg,margin:0,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace"},children:M||"Run transform to see output"})]})]}),C==="preview"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("button",{onClick:()=>m?.(D),style:{padding:"8px 16px",borderRadius:4,border:"none",background:l.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",s("dataMapper.export","Export")]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(D),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${l.border}`,background:"transparent",color:l.text,cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"clipboard",size:14})," ",s("dataMapper.copy","Copy")]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:l.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:D})]})]})]})},tn=Object.freeze(Object.defineProperty({__proto__:null,NiceDataMapper:yt},Symbol.toStringTag,{value:"Module"})),nn=[{type:"ui-event",label:"UI Event",icon:"cursor",color:"var(--nice-color-primary, #3b82f6)",configSchema:[{name:"element",label:"Element Selector",type:"string",required:!0},{name:"event",label:"Event Type",type:"select",required:!0,options:[{value:"click",label:"Click"},{value:"change",label:"Change"},{value:"submit",label:"Submit"},{value:"focus",label:"Focus"},{value:"blur",label:"Blur"},{value:"keydown",label:"Key Down"},{value:"keyup",label:"Key Up"}]}]},{type:"api-response",label:"API Response",icon:"globe",color:"var(--nice-color-success, #22c55e)",configSchema:[{name:"endpoint",label:"Endpoint Pattern",type:"string",required:!0},{name:"method",label:"Method",type:"select",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"},{value:"*",label:"Any"}]},{name:"statusCode",label:"Status Code",type:"string"}]},{type:"websocket",label:"WebSocket",icon:"plug",color:"var(--nice-color-accent, #8b5cf6)",configSchema:[{name:"channel",label:"Channel",type:"string",required:!0},{name:"messageType",label:"Message Type",type:"string"}]},{type:"timer",label:"Timer",icon:"clock",color:"var(--nice-color-warning, #f59e0b)",configSchema:[{name:"interval",label:"Interval (ms)",type:"number",required:!0,default:1e3},{name:"repeat",label:"Repeat",type:"boolean",default:!0}]},{type:"state-change",label:"State Change",icon:"bar-chart",color:"var(--nice-color-accent-pink, #ec4899)",configSchema:[{name:"selector",label:"State Selector",type:"string",required:!0},{name:"deep",label:"Deep Compare",type:"boolean",default:!1}]},{type:"broadcast",label:"Broadcast",icon:"wifi",color:"var(--nice-color-info, #06b6d4)",configSchema:[{name:"eventName",label:"Event Name",type:"string",required:!0}]}],rn=[{type:"action",label:"Action",icon:"zap",color:"var(--nice-color-primary, #3b82f6)",configSchema:[{name:"actionType",label:"Action",type:"string",required:!0},{name:"payload",label:"Payload",type:"json"}]},{type:"transform",label:"Transform",icon:"refresh",color:"var(--nice-color-accent, #8b5cf6)",configSchema:[{name:"expression",label:"Transform Expression",type:"code",required:!0}]},{type:"dispatch",label:"Dispatch",icon:"upload",color:"var(--nice-color-success, #22c55e)",configSchema:[{name:"eventName",label:"Event Name",type:"string",required:!0},{name:"payload",label:"Payload",type:"json"}]},{type:"api-call",label:"API Call",icon:"globe",color:"var(--nice-color-warning, #f59e0b)",configSchema:[{name:"endpoint",label:"Endpoint",type:"string",required:!0},{name:"method",label:"Method",type:"select",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"}]},{name:"body",label:"Body",type:"json"}]},{type:"state-update",label:"State Update",icon:"bar-chart",color:"var(--nice-color-accent-pink, #ec4899)",configSchema:[{name:"path",label:"State Path",type:"string",required:!0},{name:"value",label:"Value Expression",type:"code"}]},{type:"notification",label:"Notification",icon:"bell",color:"var(--nice-color-info, #06b6d4)",configSchema:[{name:"type",label:"Type",type:"select",options:[{value:"success",label:"Success"},{value:"error",label:"Error"},{value:"warning",label:"Warning"},{value:"info",label:"Info"}]},{name:"message",label:"Message",type:"string",required:!0},{name:"duration",label:"Duration (ms)",type:"number",default:3e3}]},{type:"log",label:"Console Log",icon:"edit",color:"var(--nice-text-muted, #6b7280)",configSchema:[{name:"level",label:"Level",type:"select",options:[{value:"log",label:"Log"},{value:"warn",label:"Warn"},{value:"error",label:"Error"},{value:"debug",label:"Debug"}]},{name:"message",label:"Message",type:"string"}]},{type:"delay",label:"Delay",icon:"clock",color:"var(--nice-accent, #a855f7)",configSchema:[{name:"duration",label:"Duration (ms)",type:"number",required:!0,default:1e3}]},{type:"branch",label:"Conditional Branch",icon:"shuffle",color:"var(--nice-info, #14b8a6)",configSchema:[{name:"condition",label:"Condition",type:"code",required:!0},{name:"trueBranch",label:"If True",type:"string"},{name:"falseBranch",label:"If False",type:"string"}]}],sn=[{id:"flow-1",name:"Form Submit Handler",description:"Handle form submission with validation",enabled:!0,source:{id:"src-1",type:"ui-event",config:{element:"#contact-form",event:"submit"}},handlers:[{id:"h-1",type:"transform",config:{expression:"(event) => event.formData"}},{id:"h-2",type:"api-call",config:{endpoint:"/api/contact",method:"POST",body:"{{data}}"},modifiers:[{type:"debounce",value:500,unit:"ms"}]},{id:"h-3",type:"notification",config:{type:"success",message:"Form submitted successfully!"}}],errorHandler:{id:"err-1",type:"notification",config:{type:"error",message:"Failed to submit form"}}},{id:"flow-2",name:"Real-time Updates",description:"Handle WebSocket messages",enabled:!0,source:{id:"src-2",type:"websocket",config:{channel:"notifications",messageType:"update"}},handlers:[{id:"h-4",type:"state-update",config:{path:"notifications",value:"(state, data) => [...state.notifications, data]"}},{id:"h-5",type:"notification",config:{type:"info",message:"{{data.title}}",duration:5e3}}]},{id:"flow-3",name:"Auto-save Draft",description:"Periodically save form draft",enabled:!1,source:{id:"src-3",type:"timer",config:{interval:3e4,repeat:!0}},handlers:[{id:"h-6",type:"transform",config:{expression:"() => getFormData()"}},{id:"h-7",type:"api-call",config:{endpoint:"/api/draft",method:"PUT"},condition:{field:"isDirty",operator:"eq",value:!0}},{id:"h-8",type:"log",config:{level:"debug",message:"Draft saved"}}]}],on=n=>{const u=n.filter(g=>g.enabled);return`/**
|
|
142
|
-
* Generated Event Orchestration
|
|
143
|
-
* @generated by NiceEventOrchestrator
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
import { createEventBus, EventHandler, EventSource } from '@nice2dev/events';
|
|
147
|
-
|
|
148
|
-
// Event Bus Instance
|
|
149
|
-
export const eventBus = createEventBus();
|
|
150
|
-
|
|
151
|
-
// Event Types
|
|
152
|
-
${u.map(g=>`export type ${g.name.replace(/\s+/g,"")}Event = {
|
|
153
|
-
source: '${g.source.type}';
|
|
154
|
-
payload: unknown;
|
|
155
|
-
};`).join(`
|
|
156
|
-
|
|
157
|
-
`)}
|
|
158
|
-
|
|
159
|
-
// Event Handlers
|
|
160
|
-
${u.map(g=>{const m=JSON.stringify(g.source.config,null,2),c=g.handlers.flatMap(x=>x.modifiers||[]).map(x=>`.${x.type}(${x.value})`).join("");return`
|
|
161
|
-
/**
|
|
162
|
-
* ${g.name}
|
|
163
|
-
* ${g.description||""}
|
|
164
|
-
*/
|
|
165
|
-
export const ${g.name.replace(/\s+/g,"").toLowerCase()}Handler = eventBus
|
|
166
|
-
.on('${g.source.type}', ${m})${c}
|
|
167
|
-
.pipe(
|
|
168
|
-
${g.handlers.map((x,r)=>` // Step ${r+1}: ${x.type}
|
|
169
|
-
async (event) => {
|
|
170
|
-
${ct(x)}
|
|
171
|
-
},`).join(`
|
|
172
|
-
`)}
|
|
173
|
-
)
|
|
174
|
-
${g.errorHandler?`.catch(async (error) => {
|
|
175
|
-
${ct(g.errorHandler)}
|
|
176
|
-
})`:""};`}).join(`
|
|
177
|
-
`)}
|
|
178
|
-
|
|
179
|
-
// Initialize all handlers
|
|
180
|
-
export function initEventOrchestration() {
|
|
181
|
-
${u.map(g=>` ${g.name.replace(/\s+/g,"").toLowerCase()}Handler.start();`).join(`
|
|
182
|
-
`)}
|
|
183
|
-
console.log('Event orchestration initialized');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Cleanup
|
|
187
|
-
export function destroyEventOrchestration() {
|
|
188
|
-
${u.map(g=>` ${g.name.replace(/\s+/g,"").toLowerCase()}Handler.stop();`).join(`
|
|
189
|
-
`)}
|
|
190
|
-
}
|
|
191
|
-
`},ct=n=>{switch(n.type){case"action":return`dispatch({ type: '${n.config.actionType}', payload: ${JSON.stringify(n.config.payload)} });`;case"transform":return`return (${n.config.expression})(event);`;case"dispatch":return`eventBus.emit('${n.config.eventName}', ${JSON.stringify(n.config.payload)});`;case"api-call":return`await fetch('${n.config.endpoint}', { method: '${n.config.method}', body: JSON.stringify(event.payload) });`;case"state-update":return`updateState('${n.config.path}', ${n.config.value});`;case"notification":return`showNotification({ type: '${n.config.type}', message: '${n.config.message}' });`;case"log":return`console.${n.config.level||"log"}('${n.config.message}', event);`;case"delay":return`await new Promise(r => setTimeout(r, ${n.config.duration}));`;case"branch":return`if (${n.config.condition}) { /* true branch */ } else { /* false branch */ }`;default:return"// Unknown handler type"}},vt=({flows:n=sn,eventSources:u=nn,eventHandlers:p=rn,onFlowsChange:g,onExport:m,onTest:c,className:x,style:r,"data-testid":w})=>{const{t:i}=a.useNiceTranslation(),[s,d]=b.useState(n),[_,C]=b.useState(s[0]?.id??null),[y,k]=b.useState("visual"),[B,I]=b.useState(!1),[T,M]=b.useState(""),[L,E]=b.useState(new Set),h=b.useMemo(()=>s.find(o=>o.id===_),[s,_]),F=b.useMemo(()=>on(s),[s]),A=b.useCallback((o,$)=>{d(N=>{const S=N.map(P=>P.id===o?{...P,...$}:P);return g?.(S),S})},[g]),J=()=>{if(!T.trim())return;const o={id:`flow-${Date.now()}`,name:T,enabled:!0,source:{id:`src-${Date.now()}`,type:"ui-event",config:{element:"",event:"click"}},handlers:[]};d($=>{const N=[...$,o];return g?.(N),N}),C(o.id),I(!1),M("")},O=o=>{d($=>{const N=$.filter(S=>S.id!==o);return g?.(N),N}),_===o&&C(s[0]?.id??null)},Y=o=>{if(!h)return;const $=p.find(P=>P.type===o),N={};$?.configSchema.forEach(P=>{P.default!==void 0&&(N[P.name]=P.default)});const S={id:`handler-${Date.now()}`,type:o,config:N};A(h.id,{handlers:[...h.handlers,S]}),E(P=>new Set([...P,S.id]))},H=(o,$)=>{h&&A(h.id,{handlers:h.handlers.map(N=>N.id===o?{...N,...$}:N)})},D=o=>{h&&A(h.id,{handlers:h.handlers.filter($=>$.id!==o)})},l=(o,$)=>{if(!h)return;const N=h.handlers.find(f=>f.id===o);if(!N)return;const P=N.modifiers?.find(f=>f.type===$)?N.modifiers?.filter(f=>f.type!==$):[...N.modifiers||[],{type:$,value:500,unit:"ms"}];H(o,{modifiers:P})},t={bg:"var(--nice-bg-elevated, #1e1e1e)",cardBg:"var(--nice-bg-elevated, #252525)",border:"var(--nice-bg-tertiary, #333)",text:"var(--nice-text-primary, #e0e0e0)",textMuted:"var(--nice-text-muted, #888)"};return e.jsxs("div",{className:`nice-event-orchestrator ${x||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:t.bg,color:t.text,fontFamily:"system-ui, sans-serif",...r},"data-testid":w,children:[e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:16,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"zap",size:16})," ",i("eventOrchestrator.eventOrchestrator","Event Orchestrator")]}),e.jsx("div",{style:{display:"flex",border:`1px solid ${t.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(o=>e.jsxs("button",{onClick:()=>k(o),style:{padding:"6px 12px",border:"none",background:y===o?t.cardBg:"transparent",color:t.text,cursor:"pointer",fontSize:12,textTransform:"capitalize",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:o==="visual"?"palette":o==="code"?"edit":"grid",size:14})," ",o]},o))}),e.jsxs("button",{onClick:()=>m?.(F),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"var(--nice-color-success, #22c55e)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13,fontWeight:500,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",i("eventOrchestrator.export","Export")]})]}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(y==="visual"||y==="split")&&e.jsxs("div",{style:{width:240,borderRight:`1px solid ${t.border}`,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600},children:i("eventOrchestrator.eventFlows","Event Flows")}),e.jsx("button",{onClick:()=>I(!0),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[s.map(o=>{const $=u.find(N=>N.type===o.source.type);return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,onClick:()=>C(o.id),style:{padding:12,background:_===o.id?t.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${_===o.id?t.border:"transparent"}`,opacity:o.enabled?1:.5},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(a.NiceIcon,{name:$?.icon??"zap",size:16}),e.jsx("span",{style:{flex:1,fontSize:13,fontWeight:500},children:o.name}),e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:o.enabled?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"}})]}),e.jsx("div",{style:{fontSize:10,color:t.textMuted,marginTop:4},children:o.handlers.length!==1?i("eventOrchestrator.handlersMany","{handlers} handlers").replace("{handlers}",String(o.handlers.length)):i("eventOrchestrator.handlersOne","{handlers} handler").replace("{handlers}",String(o.handlers.length))})]},o.id)}),B&&e.jsxs("div",{style:{padding:12,background:t.cardBg,borderRadius:6,border:"1px solid var(--nice-primary, #3b82f6)"},children:[e.jsx("input",{type:"text",value:T,onChange:o=>M(o.target.value),placeholder:i("eventOrchestrator.flowName","Flow name..."),autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:o=>o.key==="Enter"&&J()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>I(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:11},children:i("eventOrchestrator.cancel","Cancel")}),e.jsx("button",{onClick:J,style:{flex:1,padding:6,borderRadius:4,border:"none",background:"var(--nice-color-primary, #3b82f6)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:11},children:i("eventOrchestrator.add","Add")})]})]})]})]}),(y==="visual"||y==="split")&&h&&e.jsxs("div",{style:{flex:y==="split"?1:2,overflow:"auto",padding:20},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsx("input",{type:"text",value:h.name,onChange:o=>A(h.id,{name:o.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${t.border}`,background:t.cardBg,color:t.text,fontSize:16,fontWeight:600}}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:h.enabled,onChange:o=>A(h.id,{enabled:o.target.checked})}),e.jsx("span",{style:{fontSize:12},children:i("eventOrchestrator.enabled","Enabled")})]}),e.jsxs("button",{onClick:()=>c?.(h.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"play",size:14})," ",i("eventOrchestrator.test","Test")]}),e.jsx("button",{onClick:()=>O(h.id),"aria-label":i("eventOrchestrator.delete","Delete"),style:{padding:"8px 12px",borderRadius:6,border:"1px solid var(--nice-danger, #ef4444)",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:12},children:e.jsx(a.NiceIcon,{name:"trash",size:14})})]}),e.jsxs("div",{style:{padding:16,background:t.cardBg,borderRadius:8,marginBottom:16,borderLeft:`4px solid ${u.find(o=>o.type===h.source.type)?.color??"var(--nice-text-muted, #888)"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx(a.NiceIcon,{name:u.find(o=>o.type===h.source.type)?.icon??"zap",size:20}),e.jsx("span",{style:{fontWeight:600},children:i("eventOrchestrator.eventSource","Event Source")})]}),e.jsx("select",{value:h.source.type,onChange:o=>A(h.id,{source:{...h.source,type:o.target.value,config:{}}}),style:{width:"100%",padding:10,borderRadius:6,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:13,marginBottom:12},children:u.map(o=>e.jsx("option",{value:o.type,children:o.label},o.type))}),u.find(o=>o.type===h.source.type)?.configSchema.map(o=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsxs("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:[o.label," ",o.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)"},children:"*"})]}),o.type==="select"?e.jsx("select",{value:String(h.source.config[o.name]??""),onChange:$=>A(h.id,{source:{...h.source,config:{...h.source.config,[o.name]:$.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:o.options?.map($=>e.jsx("option",{value:$.value,children:$.label},$.value))}):e.jsx("input",{type:o.type==="number"?"number":"text",value:String(h.source.config[o.name]??""),onChange:$=>A(h.id,{source:{...h.source,config:{...h.source.config,[o.name]:o.type==="number"?Number($.target.value):$.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,boxSizing:"border-box"}})]},o.name))]}),e.jsx("div",{style:{textAlign:"center",color:t.textMuted,marginBottom:16},children:e.jsx(a.NiceIcon,{name:"arrow-down",size:16})}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[h.handlers.map((o,$)=>{const N=p.find(P=>P.type===o.type),S=L.has(o.id);return e.jsxs(b.Fragment,{children:[e.jsxs("div",{style:{padding:16,background:t.cardBg,borderRadius:8,borderLeft:`4px solid ${N?.color??"var(--nice-text-muted, #888)"}`},children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":L.has(o.id),onKeyDown:a.clickOnActivationKey,style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},onClick:()=>E(P=>{const f=new Set(P);return f.has(o.id)?f.delete(o.id):f.add(o.id),f}),children:[e.jsx(a.NiceIcon,{name:N?.icon??"zap",size:16}),e.jsxs("span",{style:{fontWeight:500},children:[$+1,". ",N?.label??o.type]}),o.modifiers?.map(P=>e.jsxs("span",{style:{padding:"2px 6px",background:"var(--nice-accent-tint-12, #8b5cf620)",color:"var(--nice-color-accent, #8b5cf6)",borderRadius:4,fontSize:10},children:[P.type,": ",P.value,"ms"]},P.type)),e.jsx("span",{style:{marginLeft:"auto",color:t.textMuted,display:"inline-flex",alignItems:"center"},children:e.jsx(a.NiceIcon,{name:S?"chevron-down":"chevron-right",size:14})})]}),S&&e.jsxs("div",{style:{marginTop:12,paddingTop:12,borderTop:`1px solid ${t.border}`},children:[e.jsx("select",{value:o.type,onChange:P=>H(o.id,{type:P.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,marginBottom:12},children:p.map(P=>e.jsx("option",{value:P.type,children:P.label},P.type))}),N?.configSchema.map(P=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:P.label}),P.type==="code"?e.jsx("textarea",{value:String(o.config[P.name]??""),onChange:f=>H(o.id,{config:{...o.config,[P.name]:f.target.value}}),rows:3,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontFamily:"monospace",fontSize:11,resize:"vertical",boxSizing:"border-box"}}):P.type==="select"?e.jsx("select",{value:String(o.config[P.name]??""),onChange:f=>H(o.id,{config:{...o.config,[P.name]:f.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:P.options?.map(f=>e.jsx("option",{value:f.value,children:f.label},f.value))}):e.jsx("input",{type:P.type==="number"?"number":"text",value:String(o.config[P.name]??""),onChange:f=>H(o.id,{config:{...o.config,[P.name]:P.type==="number"?Number(f.target.value):f.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,boxSizing:"border-box"}})]},P.name)),e.jsxs("div",{style:{marginTop:12},children:[e.jsx("div",{style:{fontSize:11,color:t.textMuted,marginBottom:8},children:i("eventOrchestrator.modifiers","Modifiers")}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["debounce","throttle","delay","retry","once"].map(P=>e.jsx("button",{onClick:()=>l(o.id,P),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${o.modifiers?.some(f=>f.type===P)?"var(--nice-color-accent, #8b5cf6)":t.border}`,background:o.modifiers?.some(f=>f.type===P)?"var(--nice-accent-tint-12, #8b5cf620)":"transparent",color:t.text,cursor:"pointer",fontSize:11},children:P},P))})]}),e.jsxs("button",{onClick:()=>D(o.id),style:{marginTop:12,padding:"6px 12px",borderRadius:4,border:"1px solid var(--nice-danger, #ef4444)",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"trash",size:14})," ",i("eventOrchestrator.removeHandler","Remove Handler")]})]})]}),$<h.handlers.length-1&&e.jsx("div",{style:{textAlign:"center",color:t.textMuted},children:e.jsx(a.NiceIcon,{name:"arrow-down",size:16})})]},o.id)}),e.jsxs("div",{style:{padding:16,border:`1px dashed ${t.border}`,borderRadius:8,textAlign:"center"},children:[e.jsx("div",{style:{fontSize:12,color:t.textMuted,marginBottom:12},children:i("eventOrchestrator.addHandler","Add Handler")}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center"},children:p.map(o=>e.jsxs("button",{onClick:()=>Y(o.type),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${o.color}`,background:`${o.color}20`,color:t.text,cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:o.icon,size:14})," ",o.label]},o.type))})]})]})]}),(y==="code"||y==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"var(--nice-bg-canvas, #0d1117)",borderLeft:y==="split"?`1px solid ${t.border}`:void 0},children:e.jsx("pre",{style:{margin:0,fontFamily:"Consolas, Monaco, monospace",fontSize:12,lineHeight:1.5,color:"var(--nice-text-primary, #e6edf3)",whiteSpace:"pre-wrap"},children:F})})]})]})},an=Object.freeze(Object.defineProperty({__proto__:null,NiceEventOrchestrator:vt},Symbol.toStringTag,{value:"Module"})),ln=[{target:".nice-test-builder",titleKey:"tutorial.testBuilder.intro.title",title:"Test builder",contentKey:"tutorial.testBuilder.intro.content",content:"Build test suites visually: add cases and interaction steps with assertions, run them, and export to a ready-to-run .test.tsx file.",placement:"auto"}],Je={render:{label:"Render",icon:"palette",color:"var(--nice-color-primary, #3b82f6)"},click:{label:"Click",icon:"cursor",color:"var(--nice-color-success, #22c55e)",hasTarget:!0},type:{label:"Type",icon:"terminal",color:"var(--nice-color-warning, #f59e0b)",hasTarget:!0,hasValue:!0},select:{label:"Select",icon:"clipboard",color:"var(--nice-color-accent, #8b5cf6)",hasTarget:!0,hasValue:!0},hover:{label:"Hover",icon:"cursor",color:"var(--nice-color-accent-pink, #ec4899)",hasTarget:!0},focus:{label:"Focus",icon:"target",color:"var(--nice-color-info, #06b6d4)",hasTarget:!0},blur:{label:"Blur",icon:"forward",color:"var(--nice-text-muted, #6b7280)",hasTarget:!0},submit:{label:"Submit",icon:"upload",color:"var(--nice-info, #14b8a6)",hasTarget:!0},keypress:{label:"Key Press",icon:"terminal",color:"var(--nice-accent, #a855f7)",hasValue:!0},wait:{label:"Wait",icon:"clock",color:"var(--nice-warning, #f97316)",hasValue:!0},scroll:{label:"Scroll",icon:"file",color:"var(--nice-success, #84cc16)",hasTarget:!0},drag:{label:"Drag & Drop",icon:"cursor",color:"var(--nice-color-warning, #eab308)",hasTarget:!0,hasValue:!0},assert:{label:"Assert",icon:"check",color:"var(--nice-color-success, #22c55e)",hasTarget:!0,hasValue:!0},snapshot:{label:"Snapshot",icon:"camera",color:"var(--nice-color-primary, #3b82f6)"},"a11y-check":{label:"A11y Check",icon:"accessibility",color:"var(--nice-color-accent, #8b5cf6)"}},cn=[{id:"suite-1",name:"Button Component Tests",componentName:"NiceButton",setup:{mocks:[{name:"onClick",type:"function"}]},tests:[{id:"test-1",name:"renders with correct text",type:"unit",steps:[{id:"step-1",action:"render"},{id:"step-2",action:"assert",target:"button",value:{matcher:"toHaveTextContent",expected:"Click me"}}]},{id:"test-2",name:"calls onClick when clicked",type:"unit",steps:[{id:"step-3",action:"render"},{id:"step-4",action:"click",target:"button"},{id:"step-5",action:"assert",value:{mock:"onClick",matcher:"toHaveBeenCalled"}}]},{id:"test-3",name:"is disabled when loading",type:"unit",steps:[{id:"step-6",action:"render"},{id:"step-7",action:"assert",target:"button",value:{matcher:"toHaveAttribute",expected:["disabled","true"]}}]}]},{id:"suite-2",name:"Form Integration Tests",componentName:"ContactForm",setup:{mocks:[{name:"api.submit",type:"api",returnValue:{success:!0}}],providers:[{name:"FormProvider",props:{}}]},tests:[{id:"test-4",name:"submits form with valid data",type:"integration",steps:[{id:"step-8",action:"render"},{id:"step-9",action:"type",target:'input[name="email"]',value:"test@example.com"},{id:"step-10",action:"type",target:'input[name="message"]',value:"Hello!"},{id:"step-11",action:"click",target:'button[type="submit"]'},{id:"step-12",action:"wait",value:{type:"api",timeout:1e3}},{id:"step-13",action:"assert",target:".success-message",value:{matcher:"toBeInTheDocument"}}]},{id:"test-5",name:"shows validation errors",type:"integration",steps:[{id:"step-14",action:"render"},{id:"step-15",action:"click",target:'button[type="submit"]'},{id:"step-16",action:"assert",target:".error",value:{matcher:"toHaveTextContent",expected:"Email is required"}}]}]}],dn=n=>n.map(u=>{const p=new Set(["import { render, screen, fireEvent, waitFor } from '@testing-library/react';","import userEvent from '@testing-library/user-event';",`import { ${u.componentName} } from './${u.componentName}';`]);u.setup?.mocks.forEach(r=>{r.type==="api"&&(p.add("import { rest } from 'msw';"),p.add("import { setupServer } from 'msw/node';"))});const g=u.setup?.mocks.map(r=>r.type==="function"?`const ${r.name} = jest.fn();`:r.type==="api"?`// API mock: ${r.name}`:"").filter(Boolean).join(`
|
|
192
|
-
`),c=u.setup?.providers&&u.setup.providers.length>0?`const Wrapper = ({ children }) => (
|
|
193
|
-
${u.setup.providers.map(r=>`<${r.name}>`).join(`
|
|
194
|
-
`)}
|
|
195
|
-
{children}
|
|
196
|
-
${u.setup.providers.reverse().map(r=>`</${r.name}>`).join(`
|
|
197
|
-
`)}
|
|
198
|
-
);`:"",x=u.tests.map(r=>{const w=r.skip?".skip":r.only?".only":"",i=r.steps.map(s=>pn(s,u)).join(`
|
|
199
|
-
`);return`
|
|
200
|
-
it${w}('${r.name}', async () => {
|
|
201
|
-
${i}
|
|
202
|
-
});`}).join(`
|
|
203
|
-
`);return`/**
|
|
204
|
-
* ${u.name}
|
|
205
|
-
* @generated by NiceTestBuilder
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
${Array.from(p).join(`
|
|
209
|
-
`)}
|
|
210
|
-
|
|
211
|
-
describe('${u.componentName}', () => {
|
|
212
|
-
${g?` // Mocks
|
|
213
|
-
${g}
|
|
214
|
-
`:""}
|
|
215
|
-
${c?` ${c}
|
|
216
|
-
`:""}
|
|
217
|
-
beforeEach(() => {
|
|
218
|
-
jest.clearAllMocks();
|
|
219
|
-
});
|
|
220
|
-
${x}
|
|
221
|
-
});
|
|
222
|
-
`}).join(`
|
|
223
|
-
|
|
224
|
-
`),pn=(n,u)=>{switch(Je[n.action],n.action){case"render":{const p=u.setup?.providers&&u.setup.providers.length>0,g=u.setup?.props?` {...${JSON.stringify(u.setup.props)}}`:"";return p?`render(<${u.componentName}${g} />, { wrapper: Wrapper });`:`render(<${u.componentName}${g} />);`}case"click":return`await userEvent.click(screen.getByRole('${n.target?.replace(/[[\]'"]/g,"")}'));`;case"type":return`await userEvent.type(screen.getByRole('textbox', { name: /${n.target}/ }), '${n.value}');`;case"select":return`await userEvent.selectOptions(screen.getByRole('combobox'), '${n.value}');`;case"hover":return`await userEvent.hover(screen.getByRole('${n.target}'));`;case"focus":return`screen.getByRole('${n.target}').focus();`;case"blur":return`screen.getByRole('${n.target}').blur();`;case"submit":return"fireEvent.submit(screen.getByRole('form'));";case"wait":if(typeof n.value=="object"&&n.value!==null){const p=n.value;return p.type==="timeout"?`await new Promise(r => setTimeout(r, ${p.value}));`:`await waitFor(() => expect(/* condition */).toBeTruthy(), { timeout: ${p.timeout??1e3} });`}return`await new Promise(r => setTimeout(r, ${n.value}));`;case"assert":if(typeof n.value=="object"&&n.value!==null){const p=n.value;if(p.mock)return`expect(${p.mock}).${p.matcher}(${p.expected?JSON.stringify(p.expected):""});`;const g=n.target?`screen.getByRole('${n.target}')`:"result",m=p.expected!==void 0?JSON.stringify(p.expected):"";return`expect(${g}).${p.matcher}(${m});`}return`expect(screen.getByRole('${n.target}')).toBeInTheDocument();`;case"snapshot":return"expect(container).toMatchSnapshot();";case"a11y-check":return`const results = await axe(container);
|
|
225
|
-
expect(results).toHaveNoViolations();`;default:return`// ${n.action}: ${JSON.stringify(n)}`}},jt=({componentName:n="MyComponent",testSuites:u=cn,availableMocks:p=[],onSuitesChange:g,onExport:m,onRun:c,onRunAll:x,tutorial:r,className:w,style:i,"data-testid":s})=>{const{t:d}=a.useNiceTranslation(),[_,C]=b.useState(u),[y,k]=b.useState(_[0]?.id??null),[B,I]=b.useState(null),[T,M]=b.useState("visual"),[L,E]=b.useState(!1),[h,F]=b.useState(""),[A,J]=b.useState(new Set),O=b.useMemo(()=>_.find(j=>j.id===y),[_,y]);b.useMemo(()=>O?.tests.find(j=>j.id===B),[O,B]);const Y=b.useMemo(()=>dn(_),[_]),H=b.useCallback((j,G)=>{C(Q=>{const K=Q.map(W=>W.id===j?{...W,...G}:W);return g?.(K),K})},[g]),D=()=>{if(!h.trim())return;const j={id:`suite-${Date.now()}`,name:h,componentName:n,tests:[]};C(G=>{const Q=[...G,j];return g?.(Q),Q}),k(j.id),E(!1),F("")},l=j=>{C(G=>{const Q=G.filter(K=>K.id!==j);return g?.(Q),Q}),y===j&&k(_[0]?.id??null)},t=()=>{if(!O)return;const j={id:`test-${Date.now()}`,name:"New test",type:"unit",steps:[{id:`step-${Date.now()}`,action:"render"}]};H(O.id,{tests:[...O.tests,j]}),I(j.id),J(G=>new Set([...G,j.id]))},o=(j,G)=>{O&&H(O.id,{tests:O.tests.map(Q=>Q.id===j?{...Q,...G}:Q)})},$=j=>{O&&(H(O.id,{tests:O.tests.filter(G=>G.id!==j)}),B===j&&I(null))},N=(j,G)=>{if(!O)return;const Q=O.tests.find(W=>W.id===j);if(!Q)return;const K={id:`step-${Date.now()}`,action:G};o(j,{steps:[...Q.steps,K]})},S=(j,G,Q)=>{if(!O)return;const K=O.tests.find(W=>W.id===j);K&&o(j,{steps:K.steps.map(W=>W.id===G?{...W,...Q}:W)})},P=(j,G)=>{if(!O)return;const Q=O.tests.find(K=>K.id===j);Q&&o(j,{steps:Q.steps.filter(K=>K.id!==G)})},f={bg:"var(--nice-bg-elevated, #1e1e1e)",cardBg:"var(--nice-bg-elevated, #252525)",border:"var(--nice-bg-tertiary, #333)",text:"var(--nice-text-primary, #e0e0e0)",textMuted:"var(--nice-text-muted, #888)"},ie=b.useMemo(()=>{const j=_.reduce((Q,K)=>Q+K.tests.length,0),G=_.reduce((Q,K)=>Q+K.tests.filter(W=>W.skip).length,0);return{total:j,skipped:G}},[_]),ae=e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${f.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:16},children:[e.jsx(a.NiceIcon,{name:"flask",size:16})," ",d("testBuilder.testBuilder","Test Builder")]}),e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:d("testBuilder.testsSkipped","{total} tests • {skipped} skipped").replace("{total}",String(ie.total)).replace("{skipped}",String(ie.skipped))}),e.jsx("div",{style:{display:"flex",border:`1px solid ${f.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(j=>e.jsxs("button",{onClick:()=>M(j),style:{padding:"6px 12px",border:"none",background:T===j?f.cardBg:"transparent",color:f.text,cursor:"pointer",fontSize:12,textTransform:"capitalize"},children:[e.jsx(a.NiceIcon,{name:j==="visual"?"palette":j==="code"?"edit":"grid",size:14})," ",j]},j))}),e.jsxs("button",{onClick:x,style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${f.border}`,background:"transparent",color:f.text,cursor:"pointer",fontSize:13},children:[e.jsx(a.NiceIcon,{name:"play",size:14})," ",d("testBuilder.runAll","Run All")]}),e.jsxs("button",{onClick:()=>m?.(Y),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"var(--nice-color-success, #22c55e)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13,fontWeight:500},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",d("testBuilder.export","Export")]}),e.jsx(a.NiceTutorialButton,{steps:a.resolveTutorial(r,ln)})]}),te=T==="visual"||T==="split"?e.jsxs("div",{style:{width:220,borderRight:`1px solid ${f.border}`,display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${f.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600},children:d("testBuilder.testSuites","Test Suites")}),e.jsx("button",{onClick:()=>E(!0),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${f.border}`,background:"transparent",color:f.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[_.map(j=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,onClick:()=>{k(j.id),I(null)},style:{padding:12,background:y===j.id?f.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${y===j.id?f.border:"transparent"}`},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:j.name}),e.jsx("div",{style:{fontSize:10,color:f.textMuted,marginTop:4},children:j.tests.length!==1?d("testBuilder.testsMany","{componentName} • {tests} tests").replace("{componentName}",String(j.componentName)).replace("{tests}",String(j.tests.length)):d("testBuilder.testsOne","{componentName} • {tests} test").replace("{componentName}",String(j.componentName)).replace("{tests}",String(j.tests.length))})]},j.id)),L&&e.jsxs("div",{style:{padding:12,background:f.cardBg,borderRadius:6,border:"1px solid var(--nice-primary, #3b82f6)"},children:[e.jsx("input",{type:"text",value:h,onChange:j=>F(j.target.value),placeholder:d("testBuilder.suiteName","Suite name..."),autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${f.border}`,background:f.bg,color:f.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:j=>j.key==="Enter"&&D()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>E(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${f.border}`,background:"transparent",color:f.text,cursor:"pointer",fontSize:11},children:d("testBuilder.cancel","Cancel")}),e.jsx("button",{onClick:D,style:{flex:1,padding:6,borderRadius:4,border:"none",background:"var(--nice-color-primary, #3b82f6)",color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:11},children:d("testBuilder.add","Add")})]})]})]})]}):void 0;return e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-test-builder ${w||""}`,style:{background:f.bg,color:f.text,fontFamily:"system-ui, sans-serif",...i},"data-testid":s,menubar:ae,sidebar:te,children:e.jsxs("div",{style:{display:"flex",height:"100%",overflow:"hidden"},children:[(T==="visual"||T==="split")&&O&&e.jsxs("div",{style:{flex:T==="split"?1:2,overflow:"auto",padding:20},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsx("input",{type:"text",value:O.name,onChange:j=>H(O.id,{name:j.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${f.border}`,background:f.cardBg,color:f.text,fontSize:16,fontWeight:600}}),e.jsxs("button",{onClick:()=>c?.(O.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${f.border}`,background:"transparent",color:f.text,cursor:"pointer",fontSize:12},children:[e.jsx(a.NiceIcon,{name:"play",size:14})," ",d("testBuilder.runSuite","Run Suite")]}),e.jsx("button",{onClick:()=>l(O.id),"aria-label":d("testBuilder.delete","Delete"),style:{padding:"8px 12px",borderRadius:6,border:"1px solid var(--nice-danger, #ef4444)",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:12},children:e.jsx(a.NiceIcon,{name:"trash",size:14})})]}),e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:f.textMuted,marginBottom:6},children:d("testBuilder.component","Component")}),e.jsx("input",{type:"text",value:O.componentName,onChange:j=>H(O.id,{componentName:j.target.value}),style:{width:200,padding:8,borderRadius:4,border:`1px solid ${f.border}`,background:f.cardBg,color:f.text,fontSize:13}})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[O.tests.map((j,G)=>{const Q=A.has(j.id),K={unit:{color:"var(--nice-color-primary, #3b82f6)",icon:"puzzle"},integration:{color:"var(--nice-color-success, #22c55e)",icon:"link"},e2e:{color:"var(--nice-color-accent, #8b5cf6)",icon:"globe"},snapshot:{color:"var(--nice-color-warning, #f59e0b)",icon:"camera"},accessibility:{color:"var(--nice-color-accent-pink, #ec4899)",icon:"accessibility"}};return e.jsxs("div",{style:{background:f.cardBg,borderRadius:8,border:`1px solid ${B===j.id?"var(--nice-color-primary, #3b82f6)":f.border}`,overflow:"hidden"},children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":A.has(j.id),onKeyDown:a.clickOnActivationKey,style:{padding:12,display:"flex",alignItems:"center",gap:8,cursor:"pointer",borderLeft:`4px solid ${K[j.type].color}`},onClick:()=>{I(j.id),J(W=>{const z=new Set(W);return z.has(j.id)?z.delete(j.id):z.add(j.id),z})},children:[e.jsx("span",{children:e.jsx(a.NiceIcon,{name:K[j.type].icon,size:14})}),e.jsxs("span",{style:{fontWeight:500,opacity:j.skip?.5:1},children:[G+1,". ",j.name]}),j.skip&&e.jsx("span",{style:{padding:"2px 6px",background:"var(--nice-warning-tint-20, #f59e0b30)",color:"var(--nice-color-warning, #f59e0b)",borderRadius:4,fontSize:10},children:d("testBuilder.skipped","SKIPPED")}),j.only&&e.jsx("span",{style:{padding:"2px 6px",background:"color-mix(in srgb, var(--nice-color-accent, #8b5cf6) 19%, transparent)",color:"var(--nice-color-accent, #8b5cf6)",borderRadius:4,fontSize:10},children:d("testBuilder.only","ONLY")}),e.jsx("span",{style:{marginLeft:"auto",fontSize:11,color:f.textMuted},children:j.steps.length!==1?d("testBuilder.stepsMany","{steps} steps").replace("{steps}",String(j.steps.length)):d("testBuilder.stepsOne","{steps} step").replace("{steps}",String(j.steps.length))}),e.jsx("span",{style:{color:f.textMuted},children:e.jsx(a.NiceIcon,{name:Q?"chevron-down":"chevron-right",size:14})})]}),Q&&e.jsxs("div",{style:{padding:16,borderTop:`1px solid ${f.border}`},children:[e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:f.textMuted,marginBottom:4},children:d("testBuilder.testName","Test Name")}),e.jsx("input",{type:"text",value:j.name,onChange:W=>o(j.id,{name:W.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${f.border}`,background:f.bg,color:f.text,fontSize:12,boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:f.textMuted,marginBottom:4},children:d("testBuilder.type","Type")}),e.jsxs("select",{value:j.type,onChange:W=>o(j.id,{type:W.target.value}),style:{padding:8,borderRadius:4,border:`1px solid ${f.border}`,background:f.bg,color:f.text,fontSize:12},children:[e.jsx("option",{value:"unit",children:d("testBuilder.unit","Unit")}),e.jsx("option",{value:"integration",children:d("testBuilder.integration","Integration")}),e.jsx("option",{value:"e2e",children:"E2E"}),e.jsx("option",{value:"snapshot",children:d("testBuilder.snapshot","Snapshot")}),e.jsx("option",{value:"accessibility",children:"A11y"})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:j.skip??!1,onChange:W=>o(j.id,{skip:W.target.checked,only:!1})}),d("testBuilder.skip","Skip")]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:j.only??!1,onChange:W=>o(j.id,{only:W.target.checked,skip:!1})}),d("testBuilder.only2","Only")]})]})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,color:f.textMuted,marginBottom:8},children:d("testBuilder.steps","Steps")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:j.steps.map((W,z)=>{const U=Je[W.action];return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:10,background:f.bg,borderRadius:6,borderLeft:`3px solid ${U.color}`},children:[e.jsx("span",{style:{width:20,textAlign:"center",fontSize:11,color:f.textMuted},children:z+1}),e.jsx("span",{children:e.jsx(a.NiceIcon,{name:U.icon,size:14})}),e.jsx("select",{value:W.action,onChange:V=>S(j.id,W.id,{action:V.target.value}),style:{padding:6,borderRadius:4,border:`1px solid ${f.border}`,background:f.cardBg,color:f.text,fontSize:11},children:Object.entries(Je).map(([V,ee])=>e.jsx("option",{value:V,children:ee.label},V))}),U.hasTarget&&e.jsx("input",{type:"text",value:W.target??"",onChange:V=>S(j.id,W.id,{target:V.target.value}),placeholder:d("testBuilder.targetSelector","Target selector"),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${f.border}`,background:f.cardBg,color:f.text,fontSize:11}}),U.hasValue&&W.action!=="assert"&&e.jsx("input",{type:"text",value:typeof W.value=="string"?W.value:"",onChange:V=>S(j.id,W.id,{value:V.target.value}),placeholder:d("testBuilder.value","Value"),style:{width:120,padding:6,borderRadius:4,border:`1px solid ${f.border}`,background:f.cardBg,color:f.text,fontSize:11}}),e.jsx("button",{onClick:()=>P(j.id,W.id),"aria-label":d("testBuilder.removeStep","Remove step"),style:{padding:4,borderRadius:4,border:"none",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:12},children:e.jsx(a.NiceIcon,{name:"close",size:14})})]},W.id)})})]}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:Object.entries(Je).slice(0,8).map(([W,z])=>e.jsxs("button",{onClick:()=>N(j.id,W),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${z.color}40`,background:`${z.color}20`,color:f.text,cursor:"pointer",fontSize:10},children:[e.jsx(a.NiceIcon,{name:z.icon,size:14})," ",z.label]},W))}),e.jsx("div",{style:{marginTop:16,display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>$(j.id),style:{padding:"6px 12px",borderRadius:4,border:"1px solid var(--nice-danger, #ef4444)",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:11},children:[e.jsx(a.NiceIcon,{name:"trash",size:14})," ",d("testBuilder.deleteTest","Delete Test")]})})]})]},j.id)}),e.jsx("button",{onClick:t,style:{padding:16,borderRadius:8,border:`1px dashed ${f.border}`,background:"transparent",color:f.textMuted,cursor:"pointer",fontSize:13},children:d("testBuilder.addTest","+ Add Test")})]})]}),(T==="code"||T==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"var(--nice-bg-canvas, #0d1117)",borderLeft:T==="split"?`1px solid ${f.border}`:void 0},children:e.jsx("pre",{style:{margin:0,fontFamily:"Consolas, Monaco, monospace",fontSize:12,lineHeight:1.5,color:"var(--nice-text-primary, #e6edf3)",whiteSpace:"pre-wrap"},children:Y})})]})})},un=Object.freeze(Object.defineProperty({__proto__:null,NiceTestBuilder:jt},Symbol.toStringTag,{value:"Module"})),mn=[],gn=[{id:"react",name:"React",icon:"settings",description:"React component templates",templates:[{id:"react-component",name:"React Component",description:"Basic React functional component",category:"components",icon:"box",engine:"handlebars",variables:[{id:"componentName",name:"componentName",type:"string",required:!0,defaultValue:"MyComponent"},{id:"withProps",name:"withProps",type:"boolean",defaultValue:!0},{id:"withTests",name:"withTests",type:"boolean",defaultValue:!0},{id:"withStory",name:"withStory",type:"boolean",defaultValue:!1}],files:[{id:"component",name:"{{componentName}}.tsx",path:"src/components/{{componentName}}",language:"typescript",content:`import React from 'react';
|
|
226
|
-
{{#if withProps}}
|
|
227
|
-
export interface {{componentName}}Props {
|
|
228
|
-
children?: React.ReactNode;
|
|
229
|
-
className?: string;
|
|
230
|
-
}
|
|
231
|
-
{{/if}}
|
|
232
|
-
|
|
233
|
-
export const {{componentName}}: React.FC{{#if withProps}}<{{componentName}}Props>{{/if}} = ({{#if withProps}}{ children, className }{{/if}}) => {
|
|
234
|
-
return (
|
|
235
|
-
<div className={className}>
|
|
236
|
-
{children}
|
|
237
|
-
</div>
|
|
238
|
-
);
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
export default {{componentName}};
|
|
242
|
-
`},{id:"test",name:"{{componentName}}.test.tsx",path:"src/components/{{componentName}}",language:"typescript",condition:"withTests === true",content:`import { render, screen } from '@testing-library/react';
|
|
243
|
-
import { {{componentName}} } from './{{componentName}}';
|
|
244
|
-
|
|
245
|
-
describe('{{componentName}}', () => {
|
|
246
|
-
it('renders children', () => {
|
|
247
|
-
render(<{{componentName}}>Test Content</{{componentName}}>);
|
|
248
|
-
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
`},{id:"story",name:"{{componentName}}.stories.tsx",path:"src/components/{{componentName}}",language:"typescript",condition:"withStory === true",content:`import type { Meta, StoryObj } from '@storybook/react';
|
|
252
|
-
import { {{componentName}} } from './{{componentName}}';
|
|
253
|
-
|
|
254
|
-
const meta: Meta<typeof {{componentName}}> = {
|
|
255
|
-
title: 'Components/{{componentName}}',
|
|
256
|
-
component: {{componentName}},
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
export default meta;
|
|
260
|
-
type Story = StoryObj<typeof {{componentName}}>;
|
|
261
|
-
|
|
262
|
-
export const Default: Story = {
|
|
263
|
-
args: {},
|
|
264
|
-
};
|
|
265
|
-
`},{id:"index",name:"index.ts",path:"src/components/{{componentName}}",language:"typescript",content:`export { {{componentName}} } from './{{componentName}}';
|
|
266
|
-
export type { {{componentName}}Props } from './{{componentName}}';
|
|
267
|
-
`}]}]},{id:"nextjs",name:"Next.js",icon:"play",description:"Next.js page and API templates",templates:[{id:"nextjs-page",name:"Next.js Page",description:"Next.js App Router page",category:"pages",icon:"file",engine:"handlebars",variables:[{id:"pageName",name:"pageName",type:"string",required:!0,defaultValue:"about"},{id:"withMetadata",name:"withMetadata",type:"boolean",defaultValue:!0},{id:"withLoading",name:"withLoading",type:"boolean",defaultValue:!1},{id:"withError",name:"withError",type:"boolean",defaultValue:!1}],files:[{id:"page",name:"page.tsx",path:"app/{{pageName}}",language:"typescript",content:`{{#if withMetadata}}
|
|
268
|
-
import type { Metadata } from 'next';
|
|
269
|
-
|
|
270
|
-
export const metadata: Metadata = {
|
|
271
|
-
title: '{{pageName}}',
|
|
272
|
-
description: '{{pageName}} page',
|
|
273
|
-
};
|
|
274
|
-
{{/if}}
|
|
275
|
-
|
|
276
|
-
export default function {{pascalCase pageName}}Page() {
|
|
277
|
-
return (
|
|
278
|
-
<main>
|
|
279
|
-
<h1>{{pageName}}</h1>
|
|
280
|
-
</main>
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
`},{id:"loading",name:"loading.tsx",path:"app/{{pageName}}",language:"typescript",condition:"withLoading === true",content:`export default function Loading() {
|
|
284
|
-
return <div>Loading...</div>;
|
|
285
|
-
}
|
|
286
|
-
`},{id:"error",name:"error.tsx",path:"app/{{pageName}}",language:"typescript",condition:"withError === true",content:`'use client';
|
|
287
|
-
|
|
288
|
-
export default function Error({
|
|
289
|
-
error,
|
|
290
|
-
reset,
|
|
291
|
-
}: {
|
|
292
|
-
error: Error & { digest?: string };
|
|
293
|
-
reset: () => void;
|
|
294
|
-
}) {
|
|
295
|
-
return (
|
|
296
|
-
<div>
|
|
297
|
-
<h2>Something went wrong!</h2>
|
|
298
|
-
<button onClick={reset}>Try again</button>
|
|
299
|
-
</div>
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
`}]},{id:"nextjs-api",name:"Next.js API Route",description:"Next.js App Router API handler",category:"api",icon:"plug",engine:"handlebars",variables:[{id:"routeName",name:"routeName",type:"string",required:!0,defaultValue:"users"},{id:"methods",name:"methods",type:"array",defaultValue:["GET","POST"]}],files:[{id:"route",name:"route.ts",path:"app/api/{{routeName}}",language:"typescript",content:`import { NextResponse } from 'next/server';
|
|
303
|
-
|
|
304
|
-
{{#if (includes methods 'GET')}}
|
|
305
|
-
export async function GET() {
|
|
306
|
-
return NextResponse.json({ message: 'GET {{routeName}}' });
|
|
307
|
-
}
|
|
308
|
-
{{/if}}
|
|
309
|
-
|
|
310
|
-
{{#if (includes methods 'POST')}}
|
|
311
|
-
export async function POST(request: Request) {
|
|
312
|
-
const body = await request.json();
|
|
313
|
-
return NextResponse.json({ message: 'POST {{routeName}}', data: body });
|
|
314
|
-
}
|
|
315
|
-
{{/if}}
|
|
316
|
-
|
|
317
|
-
{{#if (includes methods 'PUT')}}
|
|
318
|
-
export async function PUT(request: Request) {
|
|
319
|
-
const body = await request.json();
|
|
320
|
-
return NextResponse.json({ message: 'PUT {{routeName}}', data: body });
|
|
321
|
-
}
|
|
322
|
-
{{/if}}
|
|
323
|
-
|
|
324
|
-
{{#if (includes methods 'DELETE')}}
|
|
325
|
-
export async function DELETE() {
|
|
326
|
-
return NextResponse.json({ message: 'DELETE {{routeName}}' });
|
|
327
|
-
}
|
|
328
|
-
{{/if}}
|
|
329
|
-
`}]}]}],dt=(n,u,p)=>{let g=n;Object.entries(u).forEach(([x,r])=>{const w=new RegExp(`\\{\\{\\s*${x}\\s*\\}\\}`,"g");g=g.replace(w,String(r));const i=new RegExp(`\\{\\{\\s*pascalCase\\s+${x}\\s*\\}\\}`,"g");if(typeof r=="string"){const s=r.charAt(0).toUpperCase()+r.slice(1);g=g.replace(i,s)}});const m=/\{\{#if\s+([^}]+)\}\}([\s\S]*?)\{\{\/if\}\}/g;g=g.replace(m,(x,r,w)=>{const i=r.trim(),s=i.match(/(\w+)\s*===?\s*(\w+|true|false|'[^']*'|"[^"]*")/);if(s){const[,_,C]=s,y=u[_];let k=C;return C==="true"?k=!0:C==="false"?k=!1:(C.startsWith("'")||C.startsWith('"'))&&(k=C.slice(1,-1)),y===k?w:""}return u[i]?w:""});const c=/\{\{#if\s+\(includes\s+(\w+)\s+'([^']+)'\)\}\}([\s\S]*?)\{\{\/if\}\}/g;return g=g.replace(c,(x,r,w,i)=>{const s=u[r];return Array.isArray(s)&&s.includes(w)?i:""}),g},xn=(n,u)=>{try{const p=n.split(/\s*(===|!==|==|!=)\s*/);if(p.length===3){const[g,m,c]=p,x=u[g.trim()],r=c.trim();let w=r;switch(r==="true"?w=!0:r==="false"?w=!1:(r.startsWith("'")||r.startsWith('"'))&&(w=r.slice(1,-1)),m){case"===":case"==":return x===w;case"!==":case"!=":return x!==w}}return!!u[n.trim()]}catch{return!0}},St=({templates:n,defaultTemplates:u,onTemplatesChange:p,presets:g=gn,selectedTemplate:m,defaultSelectedTemplate:c,onSelectedTemplateChange:x,defaultEngine:r="handlebars",showLibrary:w=!0,onTemplateSelect:i,onTemplateCreate:s,onTemplateUpdate:d,onTemplateDelete:_,onGenerate:C,onExport:y,onImport:k,className:B,style:I,"data-testid":T="nice-code-template"})=>{const{t:M}=a.useNiceTranslation(),L=n!==void 0&&p!==void 0,[E,h]=a.useControllableState({value:L?n:void 0,defaultValue:L?u:u??n,fallbackValue:mn,onChange:p,componentName:"NiceCodeTemplate"});ze.useIgnoredPropChangeWarning("NiceCodeTemplate","templates","onTemplatesChange",n,L);const F=m!==void 0&&x!==void 0,[A,J]=a.useControllableState({value:F?m:void 0,defaultValue:F?c:c??m,fallbackValue:null,onChange:x,componentName:"NiceCodeTemplate"});ze.useIgnoredPropChangeWarning("NiceCodeTemplate","selectedTemplate","onSelectedTemplateChange",m,F);const[O,Y]=b.useState({}),[H,D]=b.useState("editor"),[l,t]=b.useState(null),[o,$]=b.useState(!1),[N,S]=b.useState(!1),P=b.useMemo(()=>{const z=g.flatMap(U=>U.templates);return[...E,...z]},[E,g]),f=b.useMemo(()=>P.find(z=>z.id===A),[P,A]),ie=b.useMemo(()=>f?.files.find(z=>z.id===l)||f?.files[0],[f,l]);b.useEffect(()=>{if(f){const z={};f.variables.forEach(U=>{z[U.name]=U.defaultValue??""}),Y(z),t(f.files[0]?.id||null)}},[f]);const ae=b.useMemo(()=>f?f.files.filter(z=>z.condition?xn(z.condition,O):!0).map(z=>({path:dt(`${z.path}/${z.name}`,O,f.engine),content:dt(z.content,O,f.engine),language:z.language})):[],[f,O]),v=b.useCallback(z=>{J(z.id),i?.(z)},[i,J]),te=b.useCallback(()=>{C?.(ae,O)},[ae,O,C]),j=b.useCallback(()=>{const z={id:a.createId(),name:"New Template",description:M("codeTemplate.customTemplate","Custom template"),category:"custom",icon:"file",engine:r,variables:[{id:"1",name:"name",type:"string",required:!0,defaultValue:"MyName"}],files:[{id:"1",name:"{{name}}.ts",path:"src",language:"typescript",content:`// {{name}}
|
|
330
|
-
export const {{name}} = {};`}]};h(U=>[...U,z]),J(z.id),$(!1),s?.(z)},[r,s,h,J,M]),G=b.useCallback((z,U)=>{if(!f)return;const V={...f,files:f.files.map(ee=>ee.id===z?{...ee,content:U}:ee)};h(ee=>ee.map(pe=>pe.id===V.id?V:pe)),d?.(V)},[f,d,h]),Q=b.useCallback(()=>{if(!f)return;const z={id:a.createId(),name:"new-file.ts",path:"src",language:"typescript",content:`// New file
|
|
331
|
-
`},U={...f,files:[...f.files,z]};h(V=>V.map(ee=>ee.id===U.id?U:ee)),t(z.id),d?.(U)},[f,d,h]),K=b.useCallback(z=>{if(!f)return;const U={...f,files:f.files.filter(V=>V.id!==z)};h(V=>V.map(ee=>ee.id===U.id?U:ee)),t(U.files[0]?.id||null),d?.(U)},[f,d,h]),W=z=>{const U=O[z.name];switch(z.type){case"boolean":return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!U,onChange:V=>Y(ee=>({...ee,[z.name]:V.target.checked}))}),e.jsx("span",{children:z.name})]});case"select":return e.jsx("select",{value:String(U),onChange:V=>Y(ee=>({...ee,[z.name]:V.target.value})),style:{width:"100%",padding:"8px 12px",background:"var(--nice-text-secondary, #374151)",border:"1px solid var(--nice-border-color, #4b5563)",borderRadius:6,color:"var(--nice-text-inverse, #fff)"},children:z.options?.map(V=>e.jsx("option",{value:V,children:V},V))});case"array":return e.jsx("input",{type:"text",value:Array.isArray(U)?U.join(", "):"",onChange:V=>Y(ee=>({...ee,[z.name]:V.target.value.split(",").map(pe=>pe.trim())})),placeholder:M("codeTemplate.value1Value2Value3","value1, value2, value3"),style:{width:"100%",padding:"8px 12px",background:"var(--nice-text-secondary, #374151)",border:"1px solid var(--nice-border-color, #4b5563)",borderRadius:6,color:"var(--nice-text-inverse, #fff)"}});case"number":return e.jsx("input",{type:"number",value:Number(U),onChange:V=>Y(ee=>({...ee,[z.name]:Number(V.target.value)})),style:{width:"100%",padding:"8px 12px",background:"var(--nice-text-secondary, #374151)",border:"1px solid var(--nice-border-color, #4b5563)",borderRadius:6,color:"var(--nice-text-inverse, #fff)"}});default:return e.jsx("input",{type:"text",value:String(U??""),onChange:V=>Y(ee=>({...ee,[z.name]:V.target.value})),style:{width:"100%",padding:"8px 12px",background:"var(--nice-text-secondary, #374151)",border:"1px solid var(--nice-border-color, #4b5563)",borderRadius:6,color:"var(--nice-text-inverse, #fff)"}})}};return e.jsxs("div",{className:`nice-code-template ${B||""}`,style:{display:"flex",height:"100%",background:"var(--nice-bg-canvas, #0d1117)",color:"var(--nice-text-primary, #e6edf3)",fontFamily:"system-ui, sans-serif",...I},"data-testid":T,children:[w&&e.jsxs("div",{style:{width:280,borderRight:"1px solid var(--nice-border, #30363d)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #30363d)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("span",{style:{fontWeight:500,display:"flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"book",size:16})," ",M("codeTemplate.templates","Templates")]}),e.jsx("button",{onClick:j,style:{padding:"4px 8px",background:"var(--nice-color-primary, #3b82f6)",border:"none",borderRadius:4,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:12},children:M("codeTemplate.new","+ New")})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[E.length>0&&e.jsxs("div",{style:{padding:8},children:[e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)",padding:"8px 8px 4px",fontWeight:500},children:M("codeTemplate.custom","CUSTOM")}),E.map(z=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,onClick:()=>v(z),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:A===z.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",display:"flex",alignItems:"center",gap:10},children:[e.jsx(a.NiceIcon,{name:z.icon||"file",size:16}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:z.name}),e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)"},children:z.category})]})]},z.id))]}),g.map(z=>e.jsxs("div",{style:{padding:8},children:[e.jsxs("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)",padding:"8px 8px 4px",fontWeight:500,display:"flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:z.icon,size:12}),z.name.toUpperCase()]}),z.templates.map(U=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,onClick:()=>v(U),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:A===U.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",display:"flex",alignItems:"center",gap:10},children:[e.jsx(a.NiceIcon,{name:U.icon||"file",size:16}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:U.name}),e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)"},children:U.description})]})]},U.id))]},z.id))]})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #30363d)",background:"var(--nice-bg-elevated, #161b22)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx(a.NiceIcon,{name:f.icon||"file",size:24}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:f.name}),e.jsx("div",{style:{fontSize:12,color:"var(--nice-text-muted, #8b949e)"},children:f.description})]})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsxs("button",{onClick:()=>y?.(f,"json"),style:{padding:"6px 12px",background:"var(--nice-text-secondary, #374151)",border:"none",borderRadius:6,color:"var(--nice-text-inverse, #fff)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"upload",size:14})," ",M("codeTemplate.export","Export")]}),e.jsxs("button",{onClick:te,style:{padding:"6px 16px",background:"var(--nice-color-success, #22c55e)",border:"none",borderRadius:6,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:12,fontWeight:500,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"zap",size:14})," ",M("codeTemplate.generate","Generate")]})]})]}),e.jsx("div",{style:{display:"flex",borderBottom:"1px solid var(--nice-border, #30363d)",background:"var(--nice-bg-elevated, #161b22)"},children:["variables","editor","preview"].map(z=>e.jsxs("button",{onClick:()=>D(z),style:{padding:"10px 20px",background:H===z?"var(--nice-bg-canvas, #0d1117)":"transparent",border:"none",borderBottom:H===z?"2px solid var(--nice-primary, #3b82f6)":"2px solid transparent",color:H===z?"var(--nice-text-primary, #fff)":"var(--nice-text-muted, #8b949e)",cursor:"pointer",textTransform:"capitalize"},children:[z==="variables"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"settings",size:14})," "]}),z==="editor"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"edit",size:14})," "]}),z==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(a.NiceIcon,{name:"eye",size:14})," "]}),z]},z))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[H==="variables"&&e.jsx("div",{style:{flex:1,padding:20,overflow:"auto"},children:e.jsxs("div",{style:{maxWidth:500},children:[e.jsx("h3",{style:{marginBottom:20},children:M("codeTemplate.templateVariables","Template Variables")}),f.variables.map(z=>e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("label",{style:{display:"block",fontSize:12,color:"var(--nice-text-muted, #8b949e)",marginBottom:4},children:[z.name,z.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)"},children:" *"})]}),W(z),z.description&&e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #6b7280)",marginTop:4},children:z.description})]},z.id))]})}),H==="editor"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{width:200,borderRight:"1px solid var(--nice-border, #30363d)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--nice-border, #30363d)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--nice-text-muted, #8b949e)"},children:M("codeTemplate.files","Files")}),e.jsx("button",{onClick:Q,style:{padding:"2px 6px",background:"var(--nice-text-secondary, #374151)",border:"none",borderRadius:4,color:"var(--nice-text-inverse, #fff)",cursor:"pointer",fontSize:12},children:"+"})]}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:f.files.map(z=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a.clickOnActivationKey,onClick:()=>t(z.id),style:{padding:"8px 12px",cursor:"pointer",background:l===z.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",borderLeft:l===z.id?"2px solid var(--nice-primary, #3b82f6)":"2px solid transparent",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("div",{style:{fontSize:12,overflow:"hidden",textOverflow:"ellipsis"},children:z.name}),e.jsx("button",{"aria-label":M("codeTemplate.removeFile","Remove file"),onClick:U=>{U.stopPropagation(),K(z.id)},style:{background:"none",border:"none",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:12,opacity:.7,display:"inline-flex",alignItems:"center"},children:e.jsx(a.NiceIcon,{name:"close",size:14})})]},z.id))})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:ie&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--nice-border, #30363d)",background:"var(--nice-bg-elevated, #161b22)",fontSize:12},children:[ie.path,"/",ie.name,ie.condition&&e.jsx("span",{style:{color:"var(--nice-color-warning, #f59e0b)",marginLeft:8},children:M("codeTemplate.if","(if: {condition})").replace("{condition}",String(ie.condition))})]}),e.jsx("textarea",{value:ie.content,onChange:z=>G(ie.id,z.target.value),style:{flex:1,padding:16,background:"var(--nice-bg-canvas, #0d1117)",color:"var(--nice-text-primary, #e6edf3)",border:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:13,lineHeight:1.5,resize:"none"}})]})})]}),H==="preview"&&e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--nice-border, #30363d)",background:"var(--nice-bg-elevated, #161b22)"},children:e.jsx("span",{style:{fontSize:12,color:"var(--nice-text-muted, #8b949e)"},children:M("codeTemplate.fileSWillBeGenerated","{generatedFiles} file(s) will be generated").replace("{generatedFiles}",String(ae.length))})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:ae.map((z,U)=>e.jsxs("div",{style:{borderBottom:"1px solid var(--nice-border, #30363d)"},children:[e.jsxs("div",{style:{padding:"8px 16px",background:"var(--nice-bg-secondary, #1f2937)",fontFamily:"monospace",fontSize:12,color:"var(--nice-text-muted, #8b949e)",display:"flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"file",size:14})," ",z.path]}),e.jsx("pre",{style:{margin:0,padding:16,background:"var(--nice-bg-canvas, #0d1117)",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:12,lineHeight:1.5,overflow:"auto"},children:z.content})]},U))})]})]})]}):e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"var(--nice-text-muted, #8b949e)"},children:[e.jsx("span",{style:{marginBottom:16},children:e.jsx(a.NiceIcon,{name:"book",size:64})}),e.jsx("span",{style:{fontSize:18},children:M("codeTemplate.selectATemplate","Select a template")}),e.jsx("span",{style:{fontSize:12,marginTop:4},children:M("codeTemplate.chooseFromTheLibraryOr","Choose from the library or create a new template")}),e.jsxs("button",{onClick:j,style:{marginTop:20,padding:"10px 20px",background:"var(--nice-color-primary, #3b82f6)",border:"none",borderRadius:6,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(a.NiceIcon,{name:"plus",size:14})," ",M("codeTemplate.createTemplate","Create Template")]})]})})]})},hn=Object.freeze(Object.defineProperty({__proto__:null,NiceCodeTemplate:St},Symbol.toStringTag,{value:"Module"})),wt=["read","filter","map","aggregate","set","if","forEach","write","callScript","return"],fn=["&&","||","==","!=",">=","<=",">","<","+","-","*","/","!","(",")"];function bn(n){const u=[];let p=0;for(;p<n.length;){const g=n[p];if(/\s/.test(g)){p++;continue}if(/[0-9]/.test(g)||g==="."&&/[0-9]/.test(n[p+1]??"")){let c=p;for(;c<n.length&&/[0-9.]/.test(n[c]);)c++;u.push({t:"num",v:Number(n.slice(p,c))}),p=c;continue}if(g==="'"||g==='"'){let c=p+1,x="";for(;c<n.length&&n[c]!==g;)x+=n[c]==="\\"&&c+1<n.length?n[++c]:n[c],c++;if(c>=n.length)throw new Error("unterminated string");u.push({t:"str",v:x}),p=c+1;continue}if(/[A-Za-z_$]/.test(g)){let c=p;for(;c<n.length&&/[A-Za-z0-9_$.]/.test(n[c]);)c++;u.push({t:"id",v:n.slice(p,c)}),p=c;continue}const m=fn.find(c=>n.startsWith(c,p));if(!m)throw new Error(`unexpected "${g}"`);u.push({t:"op",v:m}),p+=m.length}return u}function Se(n,u){let p=n;for(const g of u.split(".")){if(p==null)return;p=p[g]}return p}const oe=n=>typeof n=="number"?n:Number(n);function _e(n,u){const p=bn(n);let g=0;const m=()=>p[g],c=y=>{const k=p[g];if(!k||y!==void 0&&!(k.t==="op"&&k.v===y))throw new Error(y?`expected "${y}"`:"unexpected end");return g++,k},x=y=>m()?.t==="op"&&m()?.v===y,r=()=>{const y=c();if(y.t==="num")return y.v;if(y.t==="str")return y.v.includes("{{")?y.v.replace(/\{\{\s*([A-Za-z0-9_$.]+)\s*\}\}/g,(k,B)=>{const I=Se(u,B);return I==null?"":String(I)}):y.v;if(y.t==="id")return y.v==="true"?!0:y.v==="false"?!1:y.v==="null"?null:Se(u,y.v);if(y.v==="("){const k=_();return c(")"),k}if(y.v==="-")return-oe(r());if(y.v==="!")return!r();throw new Error(`unexpected "${y.v}"`)},w=()=>{let y=r();for(;x("*")||x("/");){const k=c().v,B=r();y=k==="*"?oe(y)*oe(B):oe(y)/oe(B)}return y},i=()=>{let y=w();for(;x("+")||x("-");){const k=c().v,B=w();y=k==="+"?typeof y=="string"||typeof B=="string"?`${y??""}${B??""}`:oe(y)+oe(B):oe(y)-oe(B)}return y},s=()=>{let y=i();for(;["==","!=",">=","<=",">","<"].some(x);){const k=String(c().v),B=i();y=Ce(y,k,B)}return y},d=()=>{let y=s();for(;x("&&");){c();const k=s();y=!!y&&!!k}return y};function _(){let y=d();for(;x("||");){c();const k=d();y=!!y||!!k}return y}if(p.length===0)return;const C=_();if(g<p.length)throw new Error(`unexpected "${String(p[g].v)}"`);return C}function pt(n,u){return n==null||u===null||u===void 0?n==null&&u==null:typeof n==typeof u?n===u:typeof n=="number"||typeof u=="number"?oe(n)===oe(u):String(n)===String(u)}function Ce(n,u,p){switch(u){case"==":return pt(n,p);case"!=":return!pt(n,p);case">":return oe(n)>oe(p);case">=":return oe(n)>=oe(p);case"<":return oe(n)<oe(p);default:return oe(n)<=oe(p)}}function Ge(n,u,p){return(n??[]).every(g=>{const m=Se(u,g.field);if(g.op==="empty")return m==null||m==="";if(g.op==="notEmpty")return!(m==null||m==="");const c=_e(g.value??"",{...p,...u});switch(g.op){case"eq":return Ce(m,"==",c);case"neq":return Ce(m,"!=",c);case"gt":return Ce(m,">",c);case"gte":return Ce(m,">=",c);case"lt":return Ce(m,"<",c);case"lte":return Ce(m,"<=",c);case"contains":return String(m??"").toLowerCase().includes(String(c??"").toLowerCase())}return!1})}function Nt(n){const u=[],p=new Set,g=(x,r,w)=>{if(!(r===void 0||r.trim()===""))try{_e(r,{})}catch(i){u.push({stepId:x,message:`${w}: ${i.message}`})}},m=(x,r,w)=>{(!r||!r.trim())&&u.push({stepId:x,message:`${w} is required`})},c=x=>{for(const r of x){p.has(r.id)&&u.push({stepId:r.id,message:`duplicate step id ${r.id}`}),p.add(r.id);const w=i=>i?.forEach(s=>{m(r.id,s.field,"condition field"),g(r.id,s.value,"condition value")});switch(r.type){case"read":m(r.id,r.source,"source"),m(r.id,r.into,"variable"),w(r.where);break;case"filter":m(r.id,r.from,"input"),m(r.id,r.into,"variable"),w(r.where);break;case"map":m(r.id,r.from,"input"),m(r.id,r.into,"variable"),r.fields.forEach(i=>{m(r.id,i.target,"target field"),g(r.id,i.expression,`field ${i.target}`)});break;case"aggregate":m(r.id,r.from,"input"),m(r.id,r.into,"variable"),r.measures.forEach(i=>m(r.id,i.name,"measure name"));break;case"set":m(r.id,r.variable,"variable"),g(r.id,r.expression,"value");break;case"if":w(r.when),c(r.then),c(r.else??[]);break;case"forEach":m(r.id,r.from,"input"),m(r.id,r.as,"item variable"),c(r.steps);break;case"write":m(r.id,r.target,"target"),m(r.id,r.from,"input");break;case"callScript":m(r.id,r.script,"script"),Object.entries(r.args??{}).forEach(([i,s])=>g(r.id,s,`argument ${i}`));break;case"return":g(r.id,r.expression,"value");break}}};return c(n.steps),u}const qe=Symbol("returned");async function kt(n,u,p={},g={}){const m={...p},c=[],x=g.maxSteps??1e4;let r;const w=s=>{const d=Se(m,s);return Array.isArray(d)?d:[]},i=async s=>{for(const d of s){if(c.length>=x)throw new Error(`more than ${x} steps — stopped`);switch(c.push(d.id),d.type){case"read":{const _=await u.read(d.source);m[d.into]=_.filter(C=>Ge(d.where,C,m));break}case"filter":m[d.into]=w(d.from).filter(_=>Ge(d.where,_,m));break;case"map":m[d.into]=w(d.from).map(_=>{const C={};for(const y of d.fields)C[y.target]=_e(y.expression,{...m,..._});return C});break;case"aggregate":m[d.into]=yn(w(d.from),d.groupBy??[],d.measures);break;case"set":m[d.variable]=_e(d.expression,m);break;case"if":{const _=Ge(d.when,m,m)?d.then:d.else??[];if(await i(_)===qe)return qe;break}case"forEach":for(const _ of w(d.from))if(m[d.as]=_,await i(d.steps)===qe)return qe;break;case"write":await u.write?.(d.target,w(d.from),d.mode??"insert");break;case"callScript":{const _={};for(const[y,k]of Object.entries(d.args??{}))_[y]=_e(k,m);const C=await u.callScript?.(d.script,_);d.into&&(m[d.into]=C);break}case"return":return r=_e(d.expression,m),qe}}};return await i(n.steps),{value:r,variables:m,trace:c}}function yn(n,u,p){const g=new Map;for(const m of n){const c=JSON.stringify(u.map(x=>Se(m,x)));g.set(c,[...g.get(c)??[],m])}return g.size===0&&u.length===0&&g.set("[]",[]),[...g.values()].map(m=>{const c={};u.forEach(x=>{c[x]=Se(m[0]??{},x)});for(const x of p){const r=m.map(w=>oe(Se(w,x.field??""))).filter(w=>!Number.isNaN(w));c[x.name]=x.op==="count"?m.length:x.op==="sum"?r.reduce((w,i)=>w+i,0):x.op==="avg"?r.length?r.reduce((w,i)=>w+i,0)/r.length:0:x.op==="min"?r.length?Math.min(...r):void 0:r.length?Math.max(...r):void 0}return c})}const vn={read:"database",filter:"filter",map:"shuffle",aggregate:"bar-chart",set:"edit",if:"git-branch",forEach:"repeat",write:"save",callScript:"code",return:"arrow-left"},jn=["eq","neq","gt","gte","lt","lte","contains","empty","notEmpty"],$t={eq:"=",neq:"≠",gt:">",gte:"≥",lt:"<",lte:"≤",contains:"∋",empty:"∅",notEmpty:"≠ ∅"};let Sn=0;const wn=n=>`${n}-${Date.now().toString(36)}-${(Sn++).toString(36)}`;function Ct(n){const u=wn(n);switch(n){case"read":return{id:u,type:n,source:"",into:"rows"};case"filter":return{id:u,type:n,from:"rows",where:[],into:"rows"};case"map":return{id:u,type:n,from:"rows",fields:[],into:"rows"};case"aggregate":return{id:u,type:n,from:"rows",groupBy:[],measures:[],into:"totals"};case"set":return{id:u,type:n,variable:"",expression:""};case"if":return{id:u,type:n,when:[],then:[],else:[]};case"forEach":return{id:u,type:n,from:"rows",as:"row",steps:[]};case"write":return{id:u,type:n,target:"",from:"rows",mode:"insert"};case"callScript":return{id:u,type:n,script:"",args:{}};case"return":return{id:u,type:n,expression:""}}}const Ee=n=>n.type==="if"?["then","else"]:n.type==="forEach"?["steps"]:[];function Qe(n,u,p){const g=[];for(const m of n){if(m.id===u){p&&g.push(p);continue}let c=m;for(const x of Ee(m)){const r=m[x];r&&(c={...c,[x]:Qe(r,u,p)})}g.push(c)}return g}function _t(n,u,p){if(!p.afterId&&!p.parentId)return[...n,u];const g=[];for(const m of n){let c=m;if(m.id===p.parentId&&p.branch){const x=m[p.branch]??[];c={...c,[p.branch]:[...x,u]}}else for(const x of Ee(m)){const r=m[x];r&&(c={...c,[x]:_t(r,u,p)})}g.push(c),m.id===p.afterId&&g.push(u)}return g}function zt(n,u,p){const g=n.findIndex(m=>m.id===u);if(g>=0){const m=g+p;if(m<0||m>=n.length)return[...n];const c=[...n];return[c[g],c[m]]=[c[m],c[g]],c}return n.map(m=>{let c=m;for(const x of Ee(m)){const r=m[x];r&&(c={...c,[x]:zt(r,u,p)})}return c})}function Tt(n,u){for(const p of n){if(p.id===u)return p;for(const g of Ee(p)){const m=Tt(p[g]??[],u);if(m)return m}}}function Nn(n){switch(n.type){case"read":return`${n.source||"?"} → ${n.into}`;case"filter":return`${n.from} (${n.where.length}) → ${n.into}`;case"map":return`${n.from} → ${n.into} (${n.fields.length})`;case"aggregate":return`${n.from} → ${n.into}`;case"set":return`${n.variable||"?"} = ${n.expression}`;case"if":return`${n.when.map(u=>`${u.field} ${$t[u.op]} ${u.value??""}`).join(", ")}`;case"forEach":return`${n.as} ∈ ${n.from}`;case"write":return`${n.from} → ${n.target||"?"} (${n.mode??"insert"})`;case"callScript":return`${n.script||"?"}${n.into?` → ${n.into}`:""}`;case"return":return n.expression}}const kn=({value:n,defaultValue:u,onChange:p,dataSources:g=[],scripts:m=[],io:c,readOnly:x=!1,className:r,style:w,id:i,"data-testid":s})=>{const{t:d}=a.useNiceTranslation(),[_,C]=a.useControllableState({value:n,defaultValue:u,fallbackValue:{steps:[]},onChange:p,componentName:"NiceNoCodeScriptEditor"}),[y,k]=b.useState(null),[B,I]=b.useState("read"),[T,M]=b.useState(null),L=b.useMemo(()=>Nt(_),[_]),E=new Set(L.map(D=>D.stepId)),h=y?Tt(_.steps,y):void 0,F=D=>d(`noCode.step.${D}`,D),A=_.steps,J=D=>C({..._,steps:D}),O=D=>J(Qe(A,D.id,D)),Y=D=>{const l=Ct(B);J(_t(A,l,D)),k(l.id)},H=(D,l)=>e.jsx("ol",{className:"nice-nocode-script__list",style:{paddingLeft:l?16:0},children:D.map(t=>e.jsxs("li",{className:"nice-nocode-script__item",children:[e.jsxs("button",{type:"button",className:`nice-nocode-script__step${y===t.id?" nice-nocode-script__step--selected":""}${E.has(t.id)?" nice-nocode-script__step--issue":""}`,"aria-pressed":y===t.id,onClick:()=>k(t.id),children:[e.jsx(a.NiceIcon,{name:vn[t.type],size:14}),e.jsx("span",{className:"nice-nocode-script__type",children:F(t.type)}),e.jsx("span",{className:"nice-nocode-script__summary",children:Nn(t)}),E.has(t.id)&&e.jsx(a.NiceIcon,{name:"warning",size:12})]}),Ee(t).map(o=>{const $=t[o]??[];return e.jsxs("div",{className:"nice-nocode-script__branch",children:[e.jsx("span",{className:"nice-nocode-script__branch-label",children:d(`noCode.branch.${o}`,o==="then"?"Then":o==="else"?"Else":"Steps")}),$.length>0&&H($,l+1)]},o)})]},t.id))});return e.jsxs("div",{id:i,className:`nice-nocode-script${r?` ${r}`:""}`,style:w,"data-testid":s,children:[e.jsxs("div",{className:"nice-nocode-script__steps",children:[!x&&e.jsxs("div",{className:"nice-nocode-script__toolbar",children:[e.jsx(He,{"aria-label":d("noCode.addStep","Add step"),value:B,options:wt.map(D=>({value:D,label:F(D)})),onChange:D=>I(String(D)),size:"sm"}),e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>Y({afterId:h?.id}),children:[e.jsx(a.NiceIcon,{name:"plus",size:14})," ",d("noCode.addStep","Add step")]}),h&&Ee(h).map(D=>e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>Y({parentId:h.id,branch:D}),children:[e.jsx(a.NiceIcon,{name:"plus",size:14})," ",D==="else"?d("noCode.addElse","Add to else"):d("noCode.addInside","Add inside")]},D)),c&&e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:async()=>{try{const D=await kt(_,c);M(JSON.stringify(D.value??D.variables,null,2))}catch(D){M(`${d("noCode.error","Error")}: ${D.message}`)}},children:[e.jsx(a.NiceIcon,{name:"play",size:14})," ",d("noCode.run","Run")]})]}),A.length===0?e.jsx("p",{className:"nice-nocode-script__empty",children:d("noCode.noSteps","No steps yet — add the first one.")}):H(A,0),L.length>0&&e.jsxs("div",{className:"nice-nocode-script__issues",role:"status",children:[e.jsx("strong",{children:d("noCode.issues","Problems")}),e.jsx("ul",{children:L.map((D,l)=>e.jsx("li",{children:D.message},l))})]}),T!==null&&e.jsx("pre",{className:"nice-nocode-script__result","aria-label":d("noCode.result","Result"),children:T})]}),e.jsx("div",{className:"nice-nocode-script__inspector",children:h?e.jsx($n,{step:h,onChange:O,onRemove:()=>{J(Qe(A,h.id,null)),k(null)},onMove:D=>J(zt(A,h.id,D)),dataSources:g,scripts:m,readOnly:x}):e.jsx("p",{className:"nice-nocode-script__empty",children:d("noCode.pickStep","Pick a step to set it up.")})})]})};function $n({step:n,onChange:u,onRemove:p,onMove:g,dataSources:m,scripts:c,readOnly:x}){const{t:r}=a.useNiceTranslation(),w=k=>u({...n,...k}),i=(k,B,I)=>e.jsx(be,{label:k,value:String(n[B]??""),onChange:T=>w({[B]:T}),readOnly:x,size:"sm"}),s=k=>{const B=n[k]??[],I=T=>w({[k]:T});return e.jsxs("fieldset",{className:"nice-nocode-script__rows",children:[e.jsx("legend",{children:r("noCode.field.where","Conditions")}),B.map((T,M)=>e.jsxs("div",{className:"nice-nocode-script__row",children:[e.jsx(be,{label:r("noCode.field.field","Field"),labelPlacement:"inside",value:T.field,onChange:L=>I(B.map((E,h)=>h===M?{...E,field:L}:E)),readOnly:x,size:"sm"}),e.jsx(He,{"aria-label":r("noCode.field.op","Operator"),value:T.op,options:jn.map(L=>({value:L,label:L==="contains"||L==="empty"||L==="notEmpty"?r(`noCode.op.${L}`,L):$t[L]})),onChange:L=>I(B.map((E,h)=>h===M?{...E,op:String(L)}:E)),size:"sm"}),T.op!=="empty"&&T.op!=="notEmpty"&&e.jsx(be,{label:r("noCode.field.expression","Value"),labelPlacement:"inside",value:T.value??"",onChange:L=>I(B.map((E,h)=>h===M?{...E,value:L}:E)),readOnly:x,size:"sm"}),!x&&e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.removeRow","Remove"),onClick:()=>I(B.filter((L,E)=>E!==M)),children:e.jsx(a.NiceIcon,{name:"close",size:12})})]},M)),!x&&e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>I([...B,{field:"",op:"eq",value:""}]),children:[e.jsx(a.NiceIcon,{name:"plus",size:12})," ",r("noCode.addRow","Add")]})]})},d=(k,B,I,T)=>e.jsxs("fieldset",{className:"nice-nocode-script__rows",children:[e.jsx("legend",{children:k}),B.map(([M,L],E)=>e.jsxs("div",{className:"nice-nocode-script__row",children:[e.jsx(be,{label:T[0],labelPlacement:"inside",value:M,onChange:h=>I(B.map((F,A)=>A===E?[h,F[1]]:F)),readOnly:x,size:"sm"}),e.jsx(be,{label:T[1],labelPlacement:"inside",value:L,onChange:h=>I(B.map((F,A)=>A===E?[F[0],h]:F)),readOnly:x,size:"sm"}),!x&&e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.removeRow","Remove"),onClick:()=>I(B.filter((h,F)=>F!==E)),children:e.jsx(a.NiceIcon,{name:"close",size:12})})]},E)),!x&&e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>I([...B,["",""]]),children:[e.jsx(a.NiceIcon,{name:"plus",size:12})," ",r("noCode.addRow","Add")]})]}),_=r("noCode.field.into","Into variable"),C=r("noCode.field.from","Input variable");let y;switch(n.type){case"read":y=e.jsxs(e.Fragment,{children:[i(r("noCode.field.source","Data source"),"source"),s("where"),i(_,"into")]});break;case"filter":y=e.jsxs(e.Fragment,{children:[i(C,"from"),s("where"),i(_,"into")]});break;case"map":y=e.jsxs(e.Fragment,{children:[i(C,"from"),d(r("noCode.field.fields","Fields"),n.fields.map(k=>[k.target,k.expression]),k=>w({fields:k.map(([B,I])=>({target:B,expression:I}))}),[r("noCode.field.target","Target"),r("noCode.field.expression","Value")]),i(_,"into")]});break;case"aggregate":y=e.jsxs(e.Fragment,{children:[i(C,"from"),e.jsx(be,{label:r("noCode.field.groupBy","Group by"),value:(n.groupBy??[]).join(", "),onChange:k=>w({groupBy:k.split(",").map(B=>B.trim()).filter(Boolean)}),readOnly:x,size:"sm"}),d(r("noCode.field.measures","Measures"),n.measures.map(k=>[k.name,`${k.op}${k.field?`(${k.field})`:""}`]),k=>w({measures:k.map(([B,I])=>{const T=/^(count|sum|avg|min|max)(?:\(([^)]*)\))?$/.exec(I.trim());return{name:B,op:T?.[1]??"count",...T?.[2]?{field:T[2]}:{}}})}),[r("noCode.field.name","Name"),r("noCode.field.measure","Measure: sum(field)")]),i(_,"into")]});break;case"set":y=e.jsxs(e.Fragment,{children:[i(r("noCode.field.variable","Variable"),"variable"),i(r("noCode.field.expression","Value"),"expression")]});break;case"if":y=s("when");break;case"forEach":y=e.jsxs(e.Fragment,{children:[i(C,"from"),i(r("noCode.field.as","Item variable"),"as")]});break;case"write":y=e.jsxs(e.Fragment,{children:[i(r("noCode.field.target","Target"),"target"),i(C,"from"),e.jsx(He,{label:r("noCode.field.mode","Mode"),value:n.mode??"insert",options:["insert","update","upsert","delete"],onChange:k=>w({mode:String(k)}),size:"sm"})]});break;case"callScript":y=e.jsxs(e.Fragment,{children:[i(r("noCode.field.script","Script"),"script"),d(r("noCode.field.args","Arguments"),Object.entries(n.args??{}),k=>w({args:Object.fromEntries(k)}),[r("noCode.field.name","Name"),r("noCode.field.expression","Value")]),i(_,"into")]});break;case"return":y=i(r("noCode.field.expression","Value"),"expression");break}return e.jsxs("div",{className:"nice-nocode-script__form",children:[e.jsxs("div",{className:"nice-nocode-script__form-head",children:[e.jsx("strong",{children:r(`noCode.step.${n.type}`,n.type)}),!x&&e.jsxs("span",{className:"nice-nocode-script__form-actions",children:[e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.moveUp","Move up"),onClick:()=>g(-1),children:e.jsx(a.NiceIcon,{name:"arrow-up",size:14})}),e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.moveDown","Move down"),onClick:()=>g(1),children:e.jsx(a.NiceIcon,{name:"arrow-down",size:14})}),e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.removeStep","Remove step"),onClick:p,children:e.jsx(a.NiceIcon,{name:"trash",size:14})})]})]}),y]})}exports.NICE_NO_CODE_STEP_TYPES=wt;exports.NiceAPIFlow=bt;exports.NiceAPIFlow$1=Qt;exports.NiceCheckbox=Xe;exports.NiceCheckbox$1=Rt;exports.NiceCodePreview=mt;exports.NiceCodeTemplate=St;exports.NiceCodeTemplate$1=hn;exports.NiceComponentDesigner=Ht;exports.NiceDataMapper=yt;exports.NiceDataMapper$1=tn;exports.NiceEventOrchestrator=vt;exports.NiceEventOrchestrator$1=an;exports.NiceLowCodeStudio=Lt;exports.NiceNoCodeScriptEditor=kn;exports.NiceNumberInput=et;exports.NiceNumberInput$1=Et;exports.NicePageBuilder=Ut;exports.NiceSelect=He;exports.NiceSelect$1=Dt;exports.NiceStateDesigner=xt;exports.NiceStateDesigner$1=Gt;exports.NiceTestBuilder=jt;exports.NiceTestBuilder$1=un;exports.NiceTextInput=be;exports.NiceTextInput$1=Bt;exports.evaluateNoCodeExpression=_e;exports.newNoCodeStep=Ct;exports.noCodeConditionsHold=Ge;exports.noCodePath=Se;exports.runNoCodeScript=kt;exports.useAnchoredPopup=ut;exports.validateNoCodeScript=Nt;
|