@nice2dev/ui 1.4.13 → 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 +108 -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 +670 -551
- package/dist/data/NiceTreeView.mjs +222 -180
- package/dist/data/treeRowDrop.mjs +130 -0
- package/dist/data.cjs +1 -1
- package/dist/data.d.ts +68 -5
- 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 +293 -8
- package/dist/index.mjs +980 -966
- 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-BSZhE-_l.cjs +0 -587
- package/dist/charts-BzlvCCg9.cjs +0 -768
- package/dist/no-code-B1jzfUF5.cjs +0 -331
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),s=require("@nice2dev/ui-core"),v=require("react"),ze=require("./devops-o6Zm0VKB.cjs"),Mt=require("react-dom"),Xe=Object.assign(v.forwardRef(({label:t,helperText:p,error:c,required:m,disabled:u,readOnly:l,size:h="md",name:r,id:C,className:i,style:a,accessMode:f,displayStyle:x,value:w,onChange:j,onBlur:_,onKeyDown:A,placeholder:I,min:M,max:R,step:P=1,precision:B,prefix:b,prefixType:H="label",prefixOptions:O,prefixValue:J,onPrefixChange:D,suffix:Y,showStepper:q=!0,submitOnEnter:F,onSubmit:$,showKeyboardHints:n,labelPlacement:d,errorPlacement:S,loading:g,labelWidth:y,controlWidth:z,formatPreset:o,format:Q,suffixType:oe="label",suffixOptions:N,suffixValue:ne,onSuffixChange:k,suffixSeparator:G=!1,displayMode:X},K)=>{const W=s.useNiceAccessMode(f,C),T=W==="hidden";W==="disabled"&&(u=!0),W==="readOnly"&&(l=!0);const{t:U}=s.useNiceTranslation(),V=s.useControlId(C),te=s.useComponentDisplayStyle("input",x),pe=s.useComponentDisplayClass("input",x),[we,Ee]=v.useState(!1),[ue,Ne]=v.useState(null),Te=s.useDisplayModeEdit({enabled:X,readOnly:l,disabled:u}),ke=v.useMemo(()=>{let L=3;return R!=null&&(L=String(Math.abs(Math.floor(R))).length),M!=null&&M<0&&(L+=1),B&&(L+=B+1),Math.max(3,L)+1},[R,M,B]),He=v.useCallback(L=>{if(Q)return Q(L);if(!o)return B!=null?L.toFixed(B):String(L);switch(o){case"integer":return Math.round(L).toLocaleString();case"decimal":return L.toLocaleString(void 0,{minimumFractionDigits:B??2,maximumFractionDigits:B??2});case"money":return L.toLocaleString(void 0,{minimumFractionDigits:B??2,maximumFractionDigits:B??2,useGrouping:!0});case"percent":return(L*100).toLocaleString(void 0,{minimumFractionDigits:B??0,maximumFractionDigits:B??2})+"%";default:return String(L)}},[Q,o,B]),Ie=v.useMemo(()=>we&&ue!==null?ue:w==null?"":we?B!=null?w.toFixed(B):String(w):He(w),[w,we,ue,He,B]),me=w!=null&&w<0,Me=!!(b||H==="select"&&O&&O.length>0),ge=me&&Me&&!we,Ue=ge?Ie.replace(/^[-−]/,""):Ie,$e=v.useCallback(L=>{let ee=L;return M!==void 0&&(ee=Math.max(M,ee)),R!==void 0&&(ee=Math.min(R,ee)),B!==void 0&&(ee=parseFloat(ee.toFixed(B))),ee},[M,R,B]),We=v.useCallback(L=>{const ee=L.target.value;if(Ne(ee),ee===""||ee==="-"||ee==="."||ee==="-."){ee===""&&j?.(null);return}const de=parseFloat(ee);if(!isNaN(de)){let E=de;M!==void 0&&(E=Math.max(M,E)),R!==void 0&&(E=Math.min(R,E)),j?.(E)}},[j,M,R]),se=v.useCallback(L=>{const ee=$e(L);ve.current=ee,Ne(null),j?.(ee)},[j,$e]),re=v.useCallback(L=>se((ve.current??0)+L*P),[se,P]),Be=v.useCallback(()=>re(1),[re]),ye=v.useCallback(()=>re(-1),[re]),ve=v.useRef(w);ve.current=w;const xe=v.useRef(null),he=v.useCallback(()=>{xe.current&&(clearTimeout(xe.current),xe.current=null)},[]),Fe=v.useCallback(L=>{he();let ee=300;const de=()=>{L(),ee=Math.max(30,ee*.82),xe.current=setTimeout(de,ee)};xe.current=setTimeout(de,400)},[he]),Re=s.useSubmitOnEnter({enabled:F,onSubmit:$}),Ae=v.useCallback(L=>{if(Re(L),!l){const ee=L.key==="ArrowUp"?1:L.key==="ArrowDown"?-1:L.key==="PageUp"?10:L.key==="PageDown"?-10:0;ee?(L.preventDefault(),re(ee)):L.key==="Home"&&M!==void 0?(L.preventDefault(),se(M)):L.key==="End"&&R!==void 0&&(L.preventDefault(),se(R))}A?.(L)},[Re,A,l,re,se,M,R]),Oe=v.useMemo(()=>{const L=[];return F&&L.push(s.COMMON_SHORTCUTS.submit),q&&(L.push({key:"ArrowUp",description:U("shortcuts.increment","Increase value")}),L.push({key:"ArrowDown",description:U("shortcuts.decrement","Decrease value")}),L.push({key:"PageUp",description:U("shortcuts.incrementBig","Increase by 10")}),L.push({key:"PageDown",description:U("shortcuts.decrementBig","Decrease by 10")}),M!==void 0&&L.push({key:"Home",description:U("shortcuts.toMinimum","Set to minimum")}),R!==void 0&&L.push({key:"End",description:U("shortcuts.toMaximum","Set to maximum")})),L},[F,q,M,R,U]);return T?null:e.jsxs("div",{className:`nice-field nice-field--${h} ${d==="left"?"nice-field--label-left":""} ${g?"nice-field--loading":""} ${i||""}`,style:{...a,...y!=null&&{"--nice-field-label-width":typeof y=="number"?`${y}px`:y},...z!=null&&{"--nice-field-control-width":typeof z=="number"?`${z}px`:z}},"aria-busy":g||void 0,children:[t&&e.jsxs("label",{htmlFor:V,className:`nice-field__label ${m?"nice-field__label--required":""}`,children:[t,n&&Oe.length>0&&e.jsx(s.NiceKeyboardHint,{shortcuts:Oe,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[Te.isDisplay?e.jsx(s.DisplayModeView,{value:w==null?"":b?e.jsxs(e.Fragment,{children:[b,Ie]}):Ie,placeholder:I,disabled:u,readOnly:l,onActivate:Te.enterEdit,ariaLabel:t}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:`nice-input nice-input--number nice-input--${h} nice-input--ds-${pe} ${G?"nice-input--suffix-sep":""} ${c?"nice-input--error":""} ${u?"nice-input--disabled":""} ${l?"nice-input--readonly":""}`,style:te,children:[q&&!l&&e.jsx("button",{type:"button",className:"nice-input__clear nice-input__minus",onClick:ye,onMouseDown:()=>Fe(ye),onMouseUp:he,onMouseLeave:he,disabled:u,"aria-label":U("controls.decrement","Decrement"),children:e.jsx(s.NiceIcon,{name:"minus",size:16})}),H==="select"&&O&&O.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??O[0]?.value,disabled:u,onChange:L=>{const ee=L.target.value,de=O.find(Z=>Z.value===(J??O[0]?.value)),E=O.find(Z=>Z.value===ee);D?.(ee,de?.weight,E?.weight)},children:O.map(L=>e.jsx("option",{value:L.value,children:L.label},L.value))})]}):b?e.jsxs("span",{className:"nice-input__icon nice-input__icon--prefix",children:[ge&&e.jsx("span",{className:"nice-input__sign",children:"−"}),b]}):null,e.jsx("input",{ref:L=>{typeof K=="function"?K(L):K&&(K.current=L),Te.autoFocusRef(L)},id:V,className:"nice-input__native",type:!we&&(Q||o)?"text":"number",name:r,value:Ue,placeholder:I,min:M,max:R,step:P,disabled:u||g,readOnly:l,"aria-invalid":!!c,onChange:We,onFocus:L=>{Ee(!0),Ne(null),L.target.select()},onBlur:L=>{if(Ee(!1),Ne(null),w!=null&&B!==void 0){const ee=parseFloat(w.toFixed(B));ee!==w&&j?.(ee)}X&&Te.exitEdit(),_?.(L)},onKeyDown:Ae,style:{"--nice-input-number-width":`${ke}ch`}}),oe==="select"&&N&&N.length>0?e.jsx("select",{className:"nice-input__suffix-select nice-input__icon--suffix",value:ne??N[0]?.value,disabled:u,onChange:L=>{const ee=L.target.value,de=N.find(Z=>Z.value===(ne??N[0]?.value)),E=N.find(Z=>Z.value===ee);k?.(ee,de?.weight,E?.weight)},children:N.map(L=>e.jsx("option",{value:L.value,children:L.label},L.value))}):Y?e.jsx("span",{className:"nice-input__icon nice-input__icon--suffix",children:Y}):null,q&&!l&&e.jsx("button",{type:"button",className:"nice-input__clear nice-input__plus",onClick:Be,onMouseDown:()=>Fe(Be),onMouseUp:he,onMouseLeave:he,disabled:u,"aria-label":U("controls.increment","Increment"),children:e.jsx(s.NiceIcon,{name:"plus",size:16})})]})}),g&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),S==="right"&&c&&e.jsx("div",{className:"nice-field__error",role:"alert",children:c}),S==="right"&&!c&&p&&e.jsx("div",{className:"nice-field__helper",children:p})]}),S!=="right"&&c&&e.jsx("div",{className:"nice-field__error",role:"alert",children:c}),S!=="right"&&!c&&p&&e.jsx("div",{className:"nice-field__helper",children:p})]})}),{displayName:"NiceNumberInput"}),Rt=Object.freeze(Object.defineProperty({__proto__:null,NiceNumberInput:Xe},Symbol.toStringTag,{value:"Module"}));function ut(t,p,c,m){const u=m?.maxHeight??320,l=m?.anchorKey,h=v.useRef(null),[r,C]=v.useState(null),[i,a]=v.useState(!1),[f,x]=v.useState(""),j=v.useContext(s.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),_=v.useRef(c);_.current=c;const A=s.useInputEngine();return s.useOverlayFocus(h,{open:t,modal:!1,initialFocus:"none",onClose:()=>_.current(),closeHint:!1}),v.useLayoutEffect(()=>{if(!t||!p.current)return;x(ze.scopeThemeClass(p.current)),a(!1);const I=()=>{const B=p.current;if(!B)return;const b=B.getBoundingClientRect(),H=h.current?.offsetHeight??u;let O=b.bottom;O+H>window.innerHeight-8&&b.top-H>8&&(O=b.top-H);let J=b.left;J+b.width>window.innerWidth-8&&(J=Math.max(8,window.innerWidth-b.width-8)),C(D=>D&&D.left===J&&D.top===O&&D.width===b.width?D:{left:J,top:O,width:b.width})};I();const M=requestAnimationFrame(()=>{I(),a(!0)}),R=B=>{const b=B.target;b instanceof Node&&(h.current?.contains(b)||p.current?.contains(b))||_.current()},P=()=>_.current();return window.addEventListener("scroll",R,!0),window.addEventListener("resize",P),()=>{cancelAnimationFrame(M),window.removeEventListener("scroll",R,!0),window.removeEventListener("resize",P)}},[t,p,u,l]),v.useEffect(()=>{if(!t)return;const I=R=>{const P=R.target;p.current?.contains(P)||h.current?.contains(P)||(P instanceof Element?P:P?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||_.current()},M=R=>{if(R.key!=="Escape"||R.defaultPrevented)return;const P=A?.topOverlay();P&&P.element!==h.current||_.current()};return document.addEventListener("mousedown",I),document.addEventListener("keydown",M),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",M)}},[t,p,A]),{popupRef:h,coords:r,ready:i,themeClass:f,portalTarget:j}}const et=Object.assign(v.forwardRef(({label:t,checked:p=!1,indeterminate:c=!1,onChange:m,disabled:u,readOnly:l,loading:h,required:r,size:C="md",name:i,id:a,className:f,style:x,error:w,helperText:j,accessMode:_,displayStyle:A,showKeyboardHints:I,labelPlacement:M,errorPlacement:R,labelWidth:P,controlWidth:B,"data-testid":b},H)=>{const O=s.useNiceAccessMode(_,a),J=O==="hidden";(O==="disabled"||O==="readOnly")&&(u=!0);const{t:D}=s.useNiceTranslation(),Y=s.useControlId(a);s.useComponentDisplayClass("toggle",A);const q=v.useMemo(()=>[{key:"Space",description:D("shortcuts.toggle","Toggle")}],[D]),F=v.useCallback($=>{$&&($.indeterminate=c),typeof H=="function"?H($):H&&(H.current=$)},[c,H]);return J?null:e.jsxs("div",{className:`nice-field nice-field--inline nice-field--${C} ${M==="left"?"nice-field--label-left":""} ${R==="right"?"nice-field--error-right":""} ${h?"nice-field--loading":""} ${f||""}`,style:{...x,...P!=null&&{"--nice-field-label-width":typeof P=="number"?`${P}px`:P},...B!=null&&{"--nice-field-control-width":typeof B=="number"?`${B}px`:B}},"data-testid":b,"aria-busy":h||void 0,children:[M==="left"&&t&&e.jsx("span",{className:`nice-field__label ${r?"nice-field__label--required":""}`,children:t}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("label",{className:`nice-checkbox ${C!=="md"?`nice-checkbox--${C}`:""} ${u||h?"nice-checkbox--disabled":""}`,htmlFor:Y,children:[e.jsx("input",{ref:F,id:Y,type:"checkbox",className:"nice-checkbox__input",name:i,checked:p,disabled:u||h,readOnly:l,"aria-invalid":!!w,onChange:$=>{l||h||m?.($.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:p?e.jsx("polyline",{points:"2 6 5 9 10 3"}):e.jsx("line",{x1:"2",y1:"6",x2:"10",y2:"6"})})}),M!=="left"&&t&&e.jsx("span",{children:t}),I&&e.jsx(s.NiceKeyboardHint,{shortcuts:q,size:"sm"})]}),h&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),R==="right"&&w&&e.jsx("div",{id:`${Y}-error`,className:"nice-field__error",role:"alert",children:w}),R==="right"&&!w&&j&&e.jsx("div",{id:`${Y}-helper`,className:"nice-field__helper",children:j})]}),R!=="right"&&w&&e.jsx("div",{id:`${Y}-error`,className:"nice-field__error",role:"alert",children:w}),R!=="right"&&!w&&j&&e.jsx("div",{id:`${Y}-helper`,className:"nice-field__helper",children:j})]})}),{displayName:"NiceCheckbox"}),Dt=Object.freeze(Object.defineProperty({__proto__:null,NiceCheckbox:et},Symbol.toStringTag,{value:"Module"})),Ve=Object.assign(v.forwardRef(({label:t,"aria-label":p,helperText:c,error:m,required:u,disabled:l,size:h="md",name:r,id:C,className:i,style:a,accessMode:f,displayStyle:x,options:w,value:j,onChange:_,placeholder:A,multiple:I=!1,searchable:M=!0,clearable:R=!1,emptyText:P,maxHeight:B=240,optionsSource:b,valueField:H,labelField:O,virtualScroll:J,optionHeight:D=36,onSearch:Y,loading:q,renderOption:F,multipleAutosize:$=!1,showKeyboardHints:n,labelPlacement:d,errorPlacement:S,labelWidth:g,controlWidth:y,displayMode:z},o)=>{const Q=s.useNiceAccessMode(f,C),oe=Q==="hidden";(Q==="disabled"||Q==="readOnly")&&(l=!0);const{t:N}=s.useNiceTranslation(),ne=s.useComponentDisplayStyle("input",x),k=s.useComponentDisplayClass("input",x),G=s.useControlId(C),X=s.useDisplayModeEdit({enabled:z,disabled:l}),[K,W]=v.useState(!1),[T,U]=v.useState(""),[V,te]=v.useState(-1),[pe,we]=v.useState(0),Ee=v.useRef(null),ue=v.useRef(null),[Ne,Te]=v.useState(null);v.useLayoutEffect(()=>{!q&&ue.current&&Te(ue.current.offsetWidth)},[q,j,x]);const[ke,He]=v.useState(null);v.useLayoutEffect(()=>{I&&!$&&ue.current&&ke==null&&He(ue.current.offsetWidth)},[I,$,ke]);const Ie=s.useNiceLookupSource(b??null,H??b?.keyField??"id",O??"name"),me=b?Ie.options:(w??[]).map(E=>typeof E=="string"?{value:E,label:E}:E),{popupRef:Me,coords:ge,ready:Ue,themeClass:$e,portalTarget:We}=ut(K,Ee,()=>{W(!1),U("")}),se=v.useMemo(()=>j?Array.isArray(j)?j:[j]:[],[j]),re=v.useMemo(()=>{if(!T&&!Y||Y)return me;const E=T.toLowerCase();return me.filter(Z=>Z.label.toLowerCase().includes(E)||String(Z.value).toLowerCase().includes(E))},[me,T,Y]),Be=v.useMemo(()=>{const E=new Map;for(const Z of re){const ie=Z.group||"";E.has(ie)||E.set(ie,[]),E.get(ie).push(Z)}return E},[re]),ye=v.useCallback(E=>{if(I){const Z=se.includes(E)?se.filter(ie=>ie!==E):[...se,E];_?.(Z)}else _?.(E),W(!1),U("")},[I,se,_]),ve=v.useCallback(()=>{const E=re.findIndex(Z=>se.includes(String(Z.value)));te(E>=0?E:0),W(!0)},[re,se]),xe=v.useCallback(E=>te(Z=>Math.max(0,Math.min(re.length-1,E(Z)))),[re.length]),he=v.useCallback(E=>{const Z=E.target instanceof HTMLInputElement;if(E.key==="Escape"){W(!1),U("");return}if((E.key==="Delete"||E.key==="Backspace")&&!Z&&R&&se.length>0){E.preventDefault(),_?.(I?[]:"");return}if(E.key==="Enter"||E.key===" "&&!Z){if(!K){ve(),E.preventDefault();return}V>=0&&re[V]&&(ye(re[V].value),E.preventDefault());return}const ie={ArrowDown:le=>le+1,ArrowUp:le=>le-1,PageDown:le=>le+10,PageUp:le=>le-10};Z||(ie.Home=()=>0,ie.End=()=>re.length-1);const fe=ie[E.key];fe&&(E.preventDefault(),K?xe(fe):ve())},[K,V,re,ye,ve,xe,R,se.length,_,I]),Fe=M||!!Y,Re=`${G}-listbox`,Ae=E=>`${G}-opt-${E}`,Oe=K&&V>=0&&re[V]?Ae(V):void 0;v.useLayoutEffect(()=>{const E=Me.current;if(!(!K||V<0||!E)){if(J){const Z=V*D;Z<E.scrollTop?E.scrollTop=Z:Z+D>E.scrollTop+E.clientHeight&&(E.scrollTop=Z+D-E.clientHeight);return}E.querySelector(`[data-nice-option-index="${V}"]`)?.scrollIntoView?.({block:"nearest"})}},[K,V,J,D,Me]),s.useIntent(["navigate","activate"],E=>{if(E.source==="keyboard")return!1;if(E.intent==="activate"){const Z=re[V];Z&&!Z.disabled&&ye(String(Z.value));return}if(E.direction!=="up"&&E.direction!=="down")return!1;xe(Z=>Z+(E.direction==="down"?1:-1))},{ref:Me,enabled:K&&Fe});const L=v.useMemo(()=>se.length===0?null:I?se.map(E=>me.find(Z=>Z.value===E)?.label||E).join(", "):me.find(E=>E.value===se[0])?.label||se[0],[se,me,I]),ee=v.useCallback(E=>{E.stopPropagation(),_?.(I?[]:"")},[_,I]),de=v.useMemo(()=>[{key:"Enter",description:N("shortcuts.select","Select")},{key:"Space",description:N("shortcuts.openDropdown","Open dropdown")},s.COMMON_SHORTCUTS.moveUp,s.COMMON_SHORTCUTS.moveDown,s.COMMON_SHORTCUTS.cancel],[N]);return oe?null:e.jsxs("div",{className:`nice-field ${y==null?"nice-field--select-auto":""} nice-field--${h} ${d==="left"?"nice-field--label-left":""} ${q?"nice-field--loading":""} ${i||""}`,style:{...a,...g!=null&&{"--nice-field-label-width":typeof g=="number"?`${g}px`:g},...y!=null&&{"--nice-field-control-width":typeof y=="number"?`${y}px`:y},...q&&Ne!=null&&{"--nice-select-locked-width":`${Ne}px`}},"aria-busy":q||void 0,children:[t&&e.jsxs("label",{htmlFor:G,className:`nice-field__label ${u?"nice-field__label--required":""}`,children:[t,n&&e.jsx(s.NiceKeyboardHint,{shortcuts:de,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[X.isDisplay?e.jsx(s.DisplayModeView,{value:L,placeholder:A||N("controls.select","Select..."),disabled:l,onActivate:()=>{X.enterEdit(),W(!0)},ariaLabel:t??p}):e.jsxs("div",{className:"nice-select",ref:Ee,children:[e.jsxs("button",{ref:E=>{ue.current=E,typeof o=="function"?o(E):o&&(o.current=E)},type:"button",id:G,role:"combobox","aria-label":t?void 0:p,"aria-expanded":K,"aria-haspopup":"listbox","aria-controls":K?Re:void 0,"aria-activedescendant":Fe?void 0:Oe,"aria-invalid":!!m,"aria-keyshortcuts":R&&se.length>0?"Delete":void 0,className:`nice-select__trigger nice-select__trigger--${h} nice-select--ds-${k} ${K?"nice-select__trigger--open":""} ${m?"nice-select__trigger--error":""} ${l?"nice-select__trigger--disabled":""}`,style:{...ne,...I&&!$&&ke!=null?{width:ke,maxWidth:ke,overflow:"hidden"}:{}},disabled:l,onClick:()=>K?W(!1):ve(),onKeyDown:he,children:[L?e.jsx("span",{style:I&&!$?{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}:void 0,children:L}):e.jsx("span",{className:"nice-select__placeholder",children:A||N("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[R&&se.length>0&&e.jsx("span",{className:"nice-input__clear",onClick:ee,role:"presentation",children:e.jsx(s.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:`nice-select__chevron ${K?"nice-select__chevron--open":""}`,children:e.jsx(s.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:B,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?E=>we(E.currentTarget.scrollTop):void 0,children:[(M||Y)&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:T,onChange:E=>{U(E.target.value),te(0),Y?.(E.target.value)},onKeyDown:he,placeholder:N("controls.search","Search..."),"aria-label":N("controls.search","Search..."),"aria-controls":Re,"aria-activedescendant":Oe,"aria-autocomplete":"list",autoFocus:!0})}),q&&e.jsx("div",{className:"nice-select__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm",style:{margin:"8px auto"}})}),!q&&re.length===0?e.jsx("div",{className:"nice-select__empty",children:P||N("controls.noResults","No results found")}):J&&!Array.from(Be.keys()).some(E=>E!=="")?(()=>{const Z=re.length*D,ie=Math.max(0,Math.floor(pe/D)-3),fe=Math.min(re.length,Math.ceil((pe+B)/D)+3),le=re.slice(ie,fe);return e.jsx("div",{style:{height:Z,position:"relative"},children:le.map((ce,It)=>{const Pe=ie+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*D,left:0,right:0,height:D,display:"flex",alignItems:"center",padding:"0 12px"},onClick:()=>!ce.disabled&&ye(String(ce.value)),onMouseEnter:()=>te(Pe),children:F?F(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(s.NiceIcon,{name:"check",size:16,className:"nice-select__option-check"})]})},ce.value)})})})():Array.from(Be.entries()).map(([E,Z])=>e.jsxs(v.Fragment,{children:[E&&e.jsx("div",{className:"nice-select__group-label",children:E}),Z.map(ie=>{const fe=se.includes(ie.value),le=re.indexOf(ie);return e.jsx("div",{id:Ae(le),"data-nice-option-index":le,role:"option","aria-selected":fe,"aria-disabled":ie.disabled||void 0,className:`nice-select__option ${fe?"nice-select__option--selected":""} ${le===V?"nice-select__option--highlighted":""} ${ie.disabled?"nice-select__option--disabled":""}`,onClick:()=>!ie.disabled&&ye(String(ie.value)),onMouseEnter:()=>te(le),children:F?F(ie,fe):e.jsxs(e.Fragment,{children:[ie.icon&&e.jsx("span",{children:ie.icon}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{children:ie.label}),ie.description&&e.jsx("div",{className:"nice-select__option-desc",children:ie.description})]}),fe&&e.jsx(s.NiceIcon,{name:"check",size:16,className:"nice-select__option-check"})]})},ie.value)})]},E))]}),We)]}),q&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),S==="right"&&m&&e.jsx("div",{id:`${G}-error`,className:"nice-field__error",role:"alert",children:m}),S==="right"&&!m&&c&&e.jsx("div",{id:`${G}-helper`,className:"nice-field__helper",children:c})]}),S!=="right"&&m&&e.jsx("div",{id:`${G}-error`,className:"nice-field__error",role:"alert",children:m}),S!=="right"&&!m&&c&&e.jsx("div",{id:`${G}-helper`,className:"nice-field__helper",children:c})]})}),{displayName:"NiceSelect"}),Et=Object.freeze(Object.defineProperty({__proto__:null,NiceSelect:Ve},Symbol.toStringTag,{value:"Module"})),be=Object.assign(v.forwardRef(({label:t,helperText:p,error:c,required:m,disabled:u,readOnly:l,size:h="md",name:r,id:C,className:i,style:a,accessMode:f,displayStyle:x,variant:w,value:j,defaultValue:_,onChange:A,onBlur:I,onKeyDown:M,placeholder:R,type:P="text",maxLength:B,prefix:b,suffix:H,clearable:O,autoFocus:J,submitOnEnter:D,onSubmit:Y,showKeyboardHints:q,labelPlacement:F,errorPlacement:$,loading:n,labelWidth:d,controlWidth:S,displayMode:g,...y},z)=>{const o=s.useNiceAccessMode(f,C),Q=o==="hidden";o==="disabled"&&(u=!0),o==="readOnly"&&(l=!0);const{t:oe}=s.useNiceTranslation(),N=s.useControlId(C),ne=s.useComponentDisplayStyle("input",x),k=s.useComponentDisplayClass("input",x),G=w==="filled"?"filled":w==="underlined"?"underlined":"",X=v.useCallback(()=>A?.(""),[A]),K=s.useDisplayModeEdit({enabled:g,readOnly:l,disabled:u}),W=s.useSubmitOnEnter({enabled:D,onSubmit:Y}),T=v.useCallback(V=>{W(V),M?.(V)},[W,M]),U=v.useMemo(()=>{const V=[];return D&&V.push({key:"Enter",description:oe("shortcuts.submit","Submit")}),O&&V.push({key:"Escape",description:oe("shortcuts.clear","Clear")}),V},[D,O,oe]);return Q?null:e.jsxs("div",{className:`nice-field nice-field--${h} ${F==="left"?"nice-field--label-left":""} ${F==="inside"?"nice-field--label-inside":""} ${n?"nice-field--loading":""} ${i||""}`,style:{...a,...d!=null&&{"--nice-field-label-width":typeof d=="number"?`${d}px`:d},...S!=null&&{"--nice-field-control-width":typeof S=="number"?`${S}px`:S}},"aria-busy":n||void 0,"data-floating":F==="inside"&&j?"true":void 0,children:[t&&F!=="inside"&&e.jsxs("label",{htmlFor:N,className:`nice-field__label ${m?"nice-field__label--required":""}`,children:[t,q&&U.length>0&&e.jsx(s.NiceKeyboardHint,{shortcuts:U,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[K.isDisplay?e.jsx(s.DisplayModeView,{value:j??_??"",placeholder:R,disabled:u,readOnly:l,onActivate:K.enterEdit,ariaLabel:t}):e.jsxs("div",{className:`nice-input nice-input--${h} nice-input--ds-${G||k} ${c?"nice-input--error":""} ${u?"nice-input--disabled":""} ${l?"nice-input--readonly":""}`,style:w?void 0:ne,children:[b&&e.jsx("span",{className:"nice-input__icon",children:b}),e.jsx("input",{ref:V=>{typeof z=="function"?z(V):z&&(z.current=V),K.autoFocusRef(V)},id:N,className:"nice-input__native",type:P,name:r,value:j,defaultValue:_,placeholder:R,disabled:u||n,readOnly:l,maxLength:B,autoFocus:J,"aria-invalid":!!c,"aria-describedby":c?`${N}-error`:p?`${N}-helper`:void 0,onChange:V=>A?.(V.target.value),onBlur:V=>{g&&K.exitEdit(),I?.(V)},onKeyDown:T,...y}),O&&j&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:X,"aria-label":oe("controls.clear","Clear"),children:e.jsx(s.NiceIcon,{name:"close",size:14})}),H&&e.jsx("span",{className:"nice-input__icon",children:H}),t&&F==="inside"&&e.jsx("label",{htmlFor:N,className:`nice-input__floating-label ${m?"nice-input__floating-label--required":""}`,children:t})]}),n&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),$==="right"&&c&&e.jsx("div",{id:`${N}-error`,className:"nice-field__error",role:"alert",children:c}),$==="right"&&!c&&p&&e.jsx("div",{id:`${N}-helper`,className:"nice-field__helper",children:p})]}),$!=="right"&&c&&e.jsx("div",{id:`${N}-error`,className:"nice-field__error",role:"alert",children:c}),$!=="right"&&!c&&p&&e.jsx("div",{id:`${N}-helper`,className:"nice-field__helper",children:p})]})}),{displayName:"NiceTextInput"}),Bt=Object.freeze(Object.defineProperty({__proto__:null,NiceTextInput:be},Symbol.toStringTag,{value:"Module"})),mt=({code:t,language:p="typescript",lineNumbers:c=!0,livePreview:m=!1,showDiff:u=!1,previousCode:l,theme:h="light",copyable:r=!0,onCopy:C,className:i})=>{const{t:a}=s.useNiceTranslation(),[f,x]=v.useState(!1),w=async()=>{await navigator.clipboard.writeText(t),x(!0),C?.(),setTimeout(()=>x(!1),2e3)},j=t.split(`
|
|
2
|
+
`),_=()=>e.jsx("div",{className:"nice-code-preview__line-numbers",children:j.map((R,P)=>e.jsx("span",{children:P+1},P))}),A=()=>e.jsx("pre",{className:`nice-code-preview__code language-${p}`,children:e.jsx("code",{children:t})}),I=()=>l?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:a("codePreview.previous","Previous")}),e.jsx("pre",{children:l})]}),e.jsxs("div",{className:"nice-code-preview__diff-panel nice-code-preview__diff-panel--new",children:[e.jsx("h4",{children:a("codePreview.current","Current")}),e.jsx("pre",{children:t})]})]}):null,M=()=>p!=="html"?e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("p",{children:a("codePreview.livePreviewIsAvailableFor","Live preview is available for HTML only")})}):e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("iframe",{srcDoc:t,title:a("codePreview.livePreview","Live Preview"),sandbox:"allow-scripts"})});return e.jsxs("div",{className:`nice-code-preview nice-code-preview--${h} ${i||""}`,children:[e.jsxs("header",{className:"nice-code-preview__header",children:[e.jsx("span",{className:"nice-code-preview__language",children:p}),r&&e.jsx("button",{onClick:w,className:"nice-code-preview__copy-btn",children:f?e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"check",size:14})," ",a("codePreview.copied","Copied")]}):a("codePreview.copy","Copy")})]}),u&&l?I():e.jsxs("div",{className:"nice-code-preview__body",children:[c&&_(),A()]}),m&&e.jsxs("div",{className:"nice-code-preview__preview-section",children:[e.jsx("h4",{children:a("codePreview.preview","Preview")}),M()]})]})},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(t){const p=t.replace(/[^A-Za-z0-9]+(.)?/g,(c,m)=>m?m.toUpperCase():"");return/^[A-Za-z]/.test(p)?p.charAt(0).toUpperCase()+p.slice(1):`Component${p}`}function Pt(t,p){return["export function Page() {"," return ("," <>",...t.components.map(m=>{const u=Object.entries(m.props).map(([l,h])=>typeof h=="string"?` ${l}=${JSON.stringify(h)}`:` ${l}={${JSON.stringify(h)}}`);return` <${p(m.type)}${u.join("")} />`})," </>"," );","}"].join(`
|
|
3
|
+
`)}const Lt=({projectId:t,components:p=[],theme:c="light",onChange:m,onSave:u,renderComponent:l,className:h,tutorial:r})=>{const{t:C}=s.useNiceTranslation(),[i,a]=v.useState("design"),[f,x]=v.useState(At),[w,j]=v.useState(null),[_,A]=v.useState(!1),I=v.useRef(0),M=n=>p.find(d=>d.id===n),R=n=>M(n)?.name??n,P=n=>{const d=M(n)?.icon;return d?e.jsx(s.NiceIcon,{name:d,size:14}):null},B=n=>{const d={...f,components:n};x(d),m?.(d)},b=n=>{I.current+=1;const d={id:`${n.id}-${I.current}`,type:n.id,props:{...n.defaultProps}};B([...f.components,d]),j(d.id)},H=n=>{B(f.components.filter(d=>d.id!==n)),w===n&&j(null)},O=(n,d,S)=>B(f.components.map(g=>g.id===n?{...g,props:{...g.props,[d]:S}}:g)),J=n=>{Array.from(n.dataTransfer.types).includes(Ye)&&(n.preventDefault(),n.dataTransfer.dropEffect="copy",A(!0))},D=n=>{n.currentTarget.contains(n.relatedTarget)||A(!1)},Y=n=>{n.preventDefault(),A(!1);const d=M(n.dataTransfer.getData(Ye));d&&b(d)},q=(n,d,S)=>typeof S=="boolean"?e.jsx(et,{label:d,checked:S,onChange:g=>O(n,d,g)}):typeof S=="number"?e.jsx(Xe,{label:d,value:S,onChange:g=>O(n,d,g??0)}):typeof S=="string"?e.jsx(be,{label:d,value:S,onChange:g=>O(n,d,g)}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:d}),e.jsx("code",{children:JSON.stringify(S)})]}),F=f.components.find(n=>n.id===w),$=[{id:"design",label:C("noCode.lowCodeStudio.design","Design")},{id:"preview",label:C("noCode.preview","Preview")},{id:"code",label:C("noCode.lowCodeStudio.code","Code")}];return e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-lowcode-studio nice-lowcode-studio--${c} ${h||""}`,menubar:e.jsxs("header",{className:"nice-lowcode-studio__header",children:[e.jsx("h1",{children:C("noCode.lowCodeStudio.title","Low-Code Studio")}),e.jsx("nav",{className:"nice-lowcode-studio__tabs",children:$.map(n=>e.jsx("button",{type:"button","aria-pressed":i===n.id,onClick:()=>a(n.id),className:`nice-lowcode-studio__tab ${i===n.id?"nice-lowcode-studio__tab--active":""}`,children:n.label},n.id))}),e.jsx("button",{type:"button",onClick:()=>u?.(f),children:C("save","Save")}),e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(r,Ft)})]}),sidebar:e.jsxs("aside",{className:"nice-lowcode-studio__sidebar",children:[e.jsx("h2",{children:C("noCode.componentDesigner.palette","Component Palette")}),e.jsx("ul",{children:p.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",draggable:!0,className:"nice-lowcode-studio__palette-item",title:C("noCode.lowCodeStudio.addHint","Drag onto the canvas, or click to add"),onDragStart:d=>{d.dataTransfer.setData(Ye,n.id),d.dataTransfer.effectAllowed="copy"},onClick:()=>b(n),children:[P(n.id),n.name]})},n.id))})]}),rightSidebar:e.jsxs("aside",{className:"nice-lowcode-studio__properties",children:[e.jsx("h2",{children:C("noCode.lowCodeStudio.properties","Properties")}),F?e.jsxs("div",{className:"nice-lowcode-studio__props",children:[e.jsx("h3",{children:R(F.type)}),Object.keys(F.props).length===0?e.jsx("p",{children:C("noCode.lowCodeStudio.noProps","This component has no properties")}):Object.entries(F.props).map(([n,d])=>e.jsx("div",{className:"nice-lowcode-studio__prop",children:q(F.id,n,d)},n))]}):e.jsx("p",{children:C("noCode.lowCodeStudio.selectHint","Select a component to edit its properties")})]}),children:e.jsxs("main",{className:"nice-lowcode-studio__canvas","data-project":t,children:[i==="design"&&e.jsx("div",{className:["nice-lowcode-studio__design-canvas",_&&"nice-lowcode-studio__design-canvas--over",f.components.length>0&&"nice-lowcode-studio__design-canvas--filled"].filter(Boolean).join(" "),onDragOver:J,onDragLeave:D,onDrop:Y,children:f.components.length===0?e.jsx("p",{children:C("noCode.componentDesigner.dragDrop","Drag components here")}):e.jsx("ul",{className:"nice-lowcode-studio__instances",children:f.components.map(n=>e.jsxs("li",{className:`nice-lowcode-studio__instance${n.id===w?" nice-lowcode-studio__instance--selected":""}`,children:[e.jsxs("button",{type:"button",className:"nice-lowcode-studio__instance-select","aria-pressed":n.id===w,onClick:()=>j(n.id),children:[P(n.type),R(n.type)]}),e.jsx("button",{type:"button","aria-label":`${C("remove","Remove")} ${R(n.type)}`,onClick:()=>H(n.id),children:e.jsx(s.NiceIcon,{name:"close",size:12})})]},n.id))})}),i==="preview"&&e.jsx("div",{className:`nice-lowcode-studio__preview${l?" nice-lowcode-studio__preview--live":""}`,children:l?f.components.map(n=>e.jsx(v.Fragment,{children:l(n)},n.id)):e.jsx("p",{children:C("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:f.components.length>0?Pt(f,n=>Ot(R(n))):C("noCode.lowCodeStudio.codeEmpty","// Add components to generate code"),language:"tsx",theme:c})})]})})},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"}],Vt=({component:t,propTypes:p=[],onChange:c,theme:m="light",className:u,tutorial:l})=>{const{t:h}=s.useNiceTranslation(),[r,C]=v.useState(t||{name:"NewComponent",props:[]}),i=a=>{const f={...r,...a};C(f),c?.(f)};return e.jsxs("div",{className:`nice-component-designer nice-component-designer--${m} ${u||""}`,style:{position:"relative"},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(l,qt)})}),e.jsxs("section",{className:"nice-component-designer__header",children:[e.jsx("input",{type:"text",value:r.name,onChange:a=>i({name:a.target.value}),placeholder:h("componentDesigner.componentName","Component Name")}),e.jsx("input",{type:"text",value:r.description||"",onChange:a=>i({description:a.target.value}),placeholder:h("componentDesigner.description","Description")})]}),e.jsxs("section",{className:"nice-component-designer__props",children:[e.jsx("h3",{children:h("componentDesigner.props","Props")}),r.props.map((a,f)=>e.jsxs("div",{className:"nice-component-designer__prop",children:[e.jsx("input",{type:"text",value:a.name,readOnly:!0}),e.jsx("span",{children:a.type}),a.required&&e.jsx("span",{children:h("componentDesigner.required","required")})]},f)),e.jsx("button",{onClick:()=>i({props:[...r.props,{name:"newProp",type:"string"}]}),children:h("componentDesigner.addProp","Add Prop")})]}),e.jsxs("section",{className:"nice-component-designer__preview",children:[e.jsx("h3",{children:h("componentDesigner.preview","Preview")}),e.jsx("pre",{children:`interface ${r.name}Props {
|
|
4
|
+
${r.props.map(a=>` ${a.name}${a.required?"":"?"}: ${a.type};`).join(`
|
|
5
|
+
`)}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ${r.name}: React.FC<${r.name}Props> = (props) => {
|
|
9
|
+
return <div>Component</div>;
|
|
10
|
+
};`})]})]})},Ht=[{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:t,components:p=[],grid:c={columns:12,gap:16,padding:24},onChange:m,onSave:u,theme:l="light",previewMode:h="desktop",className:r,tutorial:C})=>{const{t:i}=s.useNiceTranslation(),[a,f]=v.useState(t||{id:"page-1",name:"New Page",rows:[]}),[x,w]=v.useState(null),j=I=>{f(I),m?.(I)},_=()=>{const I={id:`row-${Date.now()}`,columns:[{id:`col-${Date.now()}`,width:12,components:[]}]};j({...a,rows:[...a.rows,I]})},A={desktop:"100%",tablet:"768px",mobile:"375px"}[h];return e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-page-builder nice-page-builder--${l} ${r||""}`,toolbar:e.jsxs("header",{className:"nice-page-builder__toolbar",children:[e.jsx("input",{type:"text",value:a.name,onChange:I=>j({...a,name:I.target.value})}),e.jsxs("div",{className:"nice-page-builder__preview-modes",children:[e.jsx("button",{className:`nice-page-builder__preview-mode ${h==="desktop"?"nice-page-builder__preview-mode--active":""}`,children:i("pageBuilder.desktop","Desktop")}),e.jsx("button",{className:`nice-page-builder__preview-mode ${h==="tablet"?"nice-page-builder__preview-mode--active":""}`,children:i("pageBuilder.tablet","Tablet")}),e.jsx("button",{className:`nice-page-builder__preview-mode ${h==="mobile"?"nice-page-builder__preview-mode--active":""}`,children:i("pageBuilder.mobile","Mobile")})]}),e.jsx("button",{onClick:()=>u?.(a),children:i("pageBuilder.save","Save")}),e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(C,Ht)})]}),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:p.map(I=>e.jsxs("li",{draggable:!0,className:"nice-page-builder__component-item",children:[I.icon&&e.jsx(s.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")}),x?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:A},children:[a.rows.map(I=>e.jsx("div",{className:"nice-page-builder__row",children:I.columns.map(M=>e.jsx("div",{className:"nice-page-builder__column",style:{width:`${M.width/12*100}%`},children:M.components.length===0?e.jsx("div",{className:"nice-page-builder__dropzone",children:i("pageBuilder.dropComponentsHere","Drop components here")}):M.components.map(R=>e.jsx("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,className:`nice-page-builder__placed-component ${x===R.id?"nice-page-builder__placed-component--selected":""}`,onClick:()=>w(R.id),children:R.type},R.id))},M.id))},I.id)),e.jsx("button",{onClick:_,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=t=>{const p=["import { create } from 'zustand'"];t.middleware?.some(i=>i.type==="devtools"&&i.enabled)&&p.push("import { devtools } from 'zustand/middleware'"),t.middleware?.some(i=>i.type==="persist"&&i.enabled)&&p.push("import { persist } from 'zustand/middleware'"),t.middleware?.some(i=>i.type==="immer"&&i.enabled)&&p.push("import { immer } from 'zustand/middleware/immer'");const c=[];t.slices.forEach(i=>{c.push(`interface ${it(i.name)}State {`),i.state.forEach(a=>{const f=rt(a.type,a.nullable);c.push(` ${a.name}: ${f};`)}),c.push("}"),c.push("")}),c.push("interface Actions {"),t.slices.forEach(i=>{i.actions.forEach(a=>{const f=a.params.map(w=>`${w.name}: ${rt(w.type)}`).join(", "),x=a.async?"Promise<void>":"void";c.push(` ${a.name}: (${f}) => ${x};`)})}),c.push("}");const m=t.slices.map(i=>`${it(i.name)}State`).join(" & ");c.push(""),c.push(`type StoreState = ${m} & Actions;`);const u=[];t.slices.forEach(i=>{i.state.forEach(a=>{const f=a.defaultValue!==void 0?JSON.stringify(a.defaultValue):a.nullable?"null":gt(a.type);u.push(` ${a.name}: ${f},`)})});const l=[];t.slices.forEach(i=>{i.actions.forEach(a=>{const f=a.params.map(w=>w.name).join(", "),x=a.async?"async ":"";l.push(` ${a.name}: ${x}(${f}) => {`),a.async?(l.push(" set({ loading: true, error: null });"),l.push(" try {"),l.push(" // TODO: API call"),l.push(` // const response = await api.${a.name}(${f});`),a.reducerSteps.forEach(w=>{w.type==="set"&&l.push(` set({ ${w.field}: ${w.value} });`)}),l.push(" } catch (error) {"),l.push(" set({ error: error.message, loading: false });"),l.push(" }")):(l.push(" set((state) => {"),a.reducerSteps.forEach(w=>{w.type==="set"?l.push(` state.${w.field} = ${w.value};`):w.type==="push"?l.push(` state.${w.field}.push(${w.value});`):w.type==="reset"&&l.push(` state.${w.field} = null;`)}),l.push(" });")),l.push(" },")})});let h="",r="";if(t.middleware?.some(i=>i.type==="immer"&&i.enabled)&&(h+="immer(",r=")"+r),t.middleware?.some(i=>i.type==="devtools"&&i.enabled)&&(h+="devtools(",r=`, { name: '${t.devtools?.name||t.name}' })`+r),t.persist?.enabled){h+="persist(";const i=[`name: '${t.persist.key}'`];t.persist.whitelist&&i.push(`partialize: (state) => ({ ${t.persist.whitelist.map(a=>a.split(".").pop()).join(", ")} })`),r=`, { ${i.join(", ")} })`+r}return`${p.join(`
|
|
11
|
+
`)}
|
|
12
|
+
|
|
13
|
+
// Types
|
|
14
|
+
${c.join(`
|
|
15
|
+
`)}
|
|
16
|
+
|
|
17
|
+
// Store
|
|
18
|
+
export const use${t.name} = create<StoreState>()(
|
|
19
|
+
${h}(set, get) => ({
|
|
20
|
+
// Initial State
|
|
21
|
+
${u.join(`
|
|
22
|
+
`)}
|
|
23
|
+
|
|
24
|
+
// Actions
|
|
25
|
+
${l.join(`
|
|
26
|
+
`)}
|
|
27
|
+
})${r}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Selectors
|
|
31
|
+
${t.slices.flatMap(i=>i.selectors.map(a=>`export const ${a.name} = (state: StoreState) => ${a.expression.replace("state.","state.")};`)).join(`
|
|
32
|
+
`)}
|
|
33
|
+
`},it=t=>t.charAt(0).toUpperCase()+t.slice(1),rt=(t,p)=>{const c={string:"string",number:"number",boolean:"boolean",array:"unknown[]",object:"Record<string, unknown>",date:"Date",enum:"string",custom:"unknown"}[t];return p?`${c} | null`:c},gt=t=>({string:"''",number:"0",boolean:"false",array:"[]",object:"{}",date:"new Date()",enum:"''",custom:"null"})[t],xt=({store:t=Kt,templates:p=Jt,onStoreChange:c,onExport:m,onSave:u,tutorial:l,className:h,style:r,"data-testid":C})=>{const{t:i}=s.useNiceTranslation(),[a,f]=v.useState(t),[x,w]=v.useState("slices"),[j,_]=v.useState(a.slices[0]?.id||null),[A,I]=v.useState(null),[M,R]=v.useState("zustand"),[P,B]=v.useState(!1),[b,H]=v.useState(null),[O,J]=v.useState(""),[D,Y]=v.useState("string"),q=v.useMemo(()=>a.slices.find(N=>N.id===j),[a.slices,j]),F=v.useCallback(N=>{const ne={...a,...N};f(ne),c?.(ne)},[a,c]),$=()=>{const N={id:`slice-${Date.now()}`,name:"newSlice",state:[],actions:[],selectors:[]};F({slices:[...a.slices,N]}),_(N.id)},n=()=>{if(!q||!O)return;const N={id:`field-${Date.now()}`,name:O,type:D,defaultValue:gt(D).replace(/'/g,"")},ne=a.slices.map(k=>k.id===q.id?{...k,state:[...k.state,N]}:k);F({slices:ne}),J("")},d=()=>{if(!q)return;const N={id:`action-${Date.now()}`,name:"newAction",params:[],reducerSteps:[]},ne=a.slices.map(k=>k.id===q.id?{...k,actions:[...k.actions,N]}:k);F({slices:ne}),I(N.id)},S=v.useCallback(()=>{let N="";M==="zustand"?N=nt(a):N=`// Export for ${M} coming soon...
|
|
34
|
+
// Store: ${a.name}`,m?.(N,M)},[a,M,m]),g=v.useMemo(()=>M==="zustand"?nt(a):`// ${M} export coming soon...`,[a,M]),y={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)"},z=e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${y.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(s.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:a.name,onChange:N=>F({name:N.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.cardBg,color:y.text,fontSize:14,fontWeight:600}})}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8,alignItems:"center"},children:[e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(l,Wt)}),e.jsxs("button",{onClick:()=>B(!0),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${y.border}`,background:"transparent",color:y.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," ",i("stateDesigner.templates","Templates")]}),e.jsxs("button",{onClick:()=>u?.(a),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(s.NiceIcon,{name:"save",size:14})," ",i("stateDesigner.save","Save")]})]})]}),o=e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${y.border}`,padding:"0 20px"},children:["slices","actions","selectors","settings","preview"].map(N=>e.jsxs("button",{onClick:()=>w(N),style:{padding:"12px 20px",border:"none",background:"transparent",color:x===N?y.text:y.textMuted,cursor:"pointer",fontSize:13,fontWeight:x===N?600:400,borderBottom:x===N?`2px solid ${y.accent}`:"2px solid transparent",marginBottom:-1},children:[N==="slices"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"box",size:14})," ",i("stateDesigner.slices","Slices")]}),N==="actions"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"zap",size:14})," ",i("stateDesigner.actions","Actions")]}),N==="selectors"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"target",size:14})," ",i("stateDesigner.selectors","Selectors")]}),N==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"settings",size:14})," ",i("stateDesigner.settings","Settings")]}),N==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," ",i("stateDesigner.preview","Preview")]})]},N))}),oe=x==="slices"||x==="actions"||x==="selectors"?e.jsxs("div",{style:{width:200,borderRight:`1px solid ${y.border}`,padding:12,display:"flex",flexDirection:"column",gap:8,height:"100%",boxSizing:"border-box"},children:[e.jsx("div",{style:{fontSize:11,color:y.textMuted,marginBottom:4},children:i("stateDesigner.slices2","SLICES")}),a.slices.map(N=>e.jsxs("button",{onClick:()=>_(N.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:j===N.id?y.accent+"30":y.cardBg,color:y.text,cursor:"pointer",textAlign:"left",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"box",size:14})," ",N.name,e.jsx("div",{style:{fontSize:10,color:y.textMuted},children:i("stateDesigner.fieldsActions","{state} fields • {actions} actions").replace("{state}",String(N.state.length)).replace("{actions}",String(N.actions.length))})]},N.id)),e.jsx("button",{onClick:$,style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${y.border}`,background:"transparent",color:y.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 ${h||""}`,style:{background:y.bg,color:y.text,fontFamily:"system-ui, sans-serif",...r},"data-testid":C,menubar:z,toolbar:o,sidebar:oe,children:e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:20,boxSizing:"border-box"},children:[x==="slices"&&q&&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(s.NiceIcon,{name:"box",size:16})," ",q.name]}),e.jsx("input",{type:"text",value:q.name,onChange:N=>{const ne=a.slices.map(k=>k.id===q.id?{...k,name:N.target.value}:k);F({slices:ne})},style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.cardBg,color:y.text,fontSize:13}})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("div",{style:{fontSize:12,color:y.textMuted,marginBottom:12},children:i("stateDesigner.stateFields","STATE FIELDS ({state})").replace("{state}",String(q.state.length))}),e.jsxs("div",{style:{border:`1px solid ${y.border}`,borderRadius:8,overflow:"hidden"},children:[q.state.map(N=>e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${y.border}`,display:"flex",alignItems:"center",gap:12},children:[e.jsx(s.NiceIcon,{name:tt[N.type],size:14}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,fontFamily:"monospace"},children:N.name}),e.jsxs("div",{style:{fontSize:11,color:y.textMuted},children:[N.type,N.nullable&&"?",N.defaultValue!==void 0&&` = ${JSON.stringify(N.defaultValue)}`]})]}),e.jsx("button",{onClick:()=>{const ne=a.slices.map(k=>k.id===q.id?{...k,state:k.state.filter(G=>G.id!==N.id)}:k);F({slices:ne})},"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(s.NiceIcon,{name:"trash",size:14})})]},N.id)),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",alignItems:"center",gap:8,background:y.cardBg},children:[e.jsx("input",{type:"text",placeholder:"fieldName",value:O,onChange:N=>J(N.target.value),style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.bg,color:y.text,fontSize:13,fontFamily:"monospace"}}),e.jsx("select",{value:D,onChange:N=>Y(N.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.bg,color:y.text,fontSize:13},children:Object.keys(tt).map(N=>e.jsx("option",{value:N,children:N},N))}),e.jsx("button",{onClick:n,disabled:!O,style:{padding:"8px 16px",borderRadius:4,border:"none",background:O?y.accent:y.border,color:"var(--nice-color-white, #fff)",cursor:O?"pointer":"not-allowed",fontSize:13},children:i("stateDesigner.add","+ Add")})]})]})]})]}),x==="actions"&&q&&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(s.NiceIcon,{name:"zap",size:16})," ",i("stateDesigner.actionsFor","Actions for {name}").replace("{name}",String(q.name))]}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",borderRadius:4,border:"none",background:y.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:q.actions.map(N=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,style:{padding:16,background:y.cardBg,borderRadius:8,border:`1px solid ${A===N.id?y.accent:y.border}`,cursor:"pointer"},onClick:()=>I(N.id),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:N.name}),N.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:y.textMuted},children:["(",N.params.map(ne=>`${ne.name}: ${ne.type}`).join(", "),")"]})]}),N.description&&e.jsx("div",{style:{fontSize:12,color:y.textMuted,marginTop:4},children:N.description}),e.jsx("div",{style:{fontSize:11,color:y.textMuted,marginTop:8},children:i("stateDesigner.reducerSteps","{reducerSteps} reducer steps").replace("{reducerSteps}",String(N.reducerSteps.length))})]},N.id))})]}),x==="selectors"&&q&&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(s.NiceIcon,{name:"target",size:16})," ",i("stateDesigner.selectorsFor","Selectors for {name}").replace("{name}",String(q.name))]})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:q.selectors.map(N=>e.jsxs("div",{style:{padding:16,background:y.cardBg,borderRadius:8,border:`1px solid ${y.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:N.name}),N.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:y.bg,borderRadius:4,fontSize:12,color:"var(--nice-color-warning, #f59e0b)"},children:N.expression})]},N.id))})]}),x==="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:a.middleware?.map(N=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,padding:12,background:y.cardBg,borderRadius:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:N.enabled,onChange:ne=>{const k=a.middleware?.map(G=>G.type===N.type?{...G,enabled:ne.target.checked}:G);F({middleware:k})}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,textTransform:"capitalize"},children:N.type}),e.jsxs("div",{style:{fontSize:11,color:y.textMuted},children:[N.type==="immer"&&i("stateDesigner.enableImmutableStateUpdates","Enable immutable state updates"),N.type==="devtools"&&i("stateDesigner.reduxDevtoolsIntegration","Redux DevTools integration"),N.type==="persist"&&i("stateDesigner.persistStateToStorage","Persist state to storage")]})]})]},N.type))}),a.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:y.textMuted,marginBottom:4},children:i("stateDesigner.storageKey","Storage Key")}),e.jsx("input",{type:"text",value:a.persist.key,onChange:N=>F({persist:{...a.persist,key:N.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.cardBg,color:y.text,fontSize:13,width:"100%",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:y.textMuted,marginBottom:4},children:i("stateDesigner.storageType","Storage Type")}),e.jsxs("select",{value:a.persist.storage,onChange:N=>F({persist:{...a.persist,storage:N.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.cardBg,color:y.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"})]})]})]})]})]}),x==="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:M,onChange:N=>R(N.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${y.border}`,background:y.cardBg,color:y.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:S,style:{padding:"8px 16px",borderRadius:4,border:"none",background:y.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," ",i("stateDesigner.export","Export")]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(g),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${y.border}`,background:"transparent",color:y.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," ",i("stateDesigner.copy","Copy")]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:y.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:g})]})]})}),P&&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:()=>B(!1),children:e.jsxs("div",{role:"presentation",style:{background:y.cardBg,borderRadius:12,padding:24,width:500,maxHeight:"80vh",overflow:"auto"},onClick:N=>N.stopPropagation(),children:[e.jsxs("h4",{style:{margin:"0 0 16px",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:16})," ",i("stateDesigner.stateTemplates","State Templates")]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:p.map(N=>e.jsx("button",{onClick:()=>{N.store.slices&&F({slices:[...a.slices,...N.store.slices]}),B(!1)},style:{padding:16,borderRadius:8,border:`1px solid ${y.border}`,background:y.bg,color:y.text,cursor:"pointer",textAlign:"left"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(s.NiceIcon,{name:N.icon,size:24}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:N.name}),e.jsx("div",{style:{fontSize:12,color:y.textMuted},children:N.description})]})]})},N.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=t=>{const p=["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';"],c=[];t.endpoints.forEach(r=>{r.body?.schema&&c.push(`export interface ${Le(r.name)}Request ${ht(r.body.schema)}`),c.push(`export interface ${Le(r.name)}Response {
|
|
35
|
+
// TODO: Define response type based on schema
|
|
36
|
+
data: unknown;
|
|
37
|
+
}`)});const m=[];t.endpoints.forEach(r=>{const C=r.pathParams?.map(_=>`${_.name}: ${_.type}`).join(", ")||"",i=r.queryParams?.length?`params?: { ${r.queryParams.map(_=>`${_.name}${_.required?"":"?"}: ${_.type}`).join("; ")} }`:"",a=r.body?`data: ${Le(r.name)}Request`:"",f=[C,i,a].filter(Boolean).join(", ");let x=`'${r.path}'`;r.pathParams?.forEach(_=>{x=x.replace(`{${_.name}}`,`\${${_.name}}`)}),r.pathParams?.length&&(x="`"+x.slice(1,-1)+"`");const w=r.cache?.enabled?`
|
|
38
|
+
// Cache: ${r.cache.strategy}, TTL: ${r.cache.ttl}s`:"",j=r.retry?.enabled?`
|
|
39
|
+
// Retry: ${r.retry.maxAttempts} attempts, ${r.retry.backoff} backoff`:"";m.push(`
|
|
40
|
+
/**
|
|
41
|
+
* ${r.description||r.name}${w}${j}
|
|
42
|
+
*/
|
|
43
|
+
async ${r.name}(${f}): Promise<${Le(r.name)}Response> {
|
|
44
|
+
const response = await this.client.${r.method.toLowerCase()}<${Le(r.name)}Response>(
|
|
45
|
+
${x}${r.queryParams?.length?", { params }":""}${r.body?", data":""}
|
|
46
|
+
);
|
|
47
|
+
return response.data;
|
|
48
|
+
}`)});let u="";t.auth?.type==="bearer"&&(u=`
|
|
49
|
+
// Auth interceptor
|
|
50
|
+
this.client.interceptors.request.use((config) => {
|
|
51
|
+
const token = ${t.auth.tokenSource||"getToken()"};
|
|
52
|
+
if (token) {
|
|
53
|
+
config.headers['${t.auth.headerName||"Authorization"}'] = '${t.auth.prefix||"Bearer"} ' + token;
|
|
54
|
+
}
|
|
55
|
+
return config;
|
|
56
|
+
});`);const l=t.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`${p.join(`
|
|
67
|
+
`)}
|
|
68
|
+
|
|
69
|
+
// Types
|
|
70
|
+
${c.join(`
|
|
71
|
+
|
|
72
|
+
`)}
|
|
73
|
+
|
|
74
|
+
// API Client
|
|
75
|
+
export class ${t.name} {
|
|
76
|
+
private client: AxiosInstance;
|
|
77
|
+
|
|
78
|
+
constructor(baseURL: string = '${t.baseUrl}') {
|
|
79
|
+
this.client = axios.create({
|
|
80
|
+
baseURL,
|
|
81
|
+
headers: ${JSON.stringify(t.globalHeaders||{},null,8).replace(/\n/g,`
|
|
82
|
+
`)},
|
|
83
|
+
});
|
|
84
|
+
${u}${l}
|
|
85
|
+
}
|
|
86
|
+
${m.join("")}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Default instance
|
|
90
|
+
export const ${t.name.charAt(0).toLowerCase()+t.name.slice(1)} = new ${t.name}();
|
|
91
|
+
`},Le=t=>t.charAt(0).toUpperCase()+t.slice(1),ht=t=>t.type==="object"&&t.properties?`{
|
|
92
|
+
${Object.entries(t.properties).map(([c,m])=>{const u=t.required?.includes(c)?"":"?";return` ${c}${u}: ${ft(m)};`}).join(`
|
|
93
|
+
`)}
|
|
94
|
+
}`:"{}",ft=t=>{switch(t.type){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return t.items?`${ft(t.items)}[]`:"unknown[]";case"object":return t.properties?ht(t):"Record<string, unknown>";default:return"unknown"}},bt=({flow:t=Yt,dataSources:p=[],onFlowChange:c,onExport:m,onTest:u,onSave:l,className:h,style:r,"data-testid":C})=>{const{t:i}=s.useNiceTranslation(),[a,f]=v.useState(t),[x,w]=v.useState("endpoints"),[j,_]=v.useState(a.endpoints[0]?.id||null),[A,I]=v.useState(!1),[M,R]=v.useState(null),[P,B]=v.useState(!1),b=v.useMemo(()=>a.endpoints.find(n=>n.id===j),[a.endpoints,j]),H=v.useCallback(n=>{const d={...a,...n};f(d),c?.(d)},[a,c]),O=v.useCallback((n,d)=>{const S=a.endpoints.map(g=>g.id===n?{...g,...d}:g);H({endpoints:S})},[a.endpoints,H]),J=n=>{const d={id:`ep-${Date.now()}`,name:"newEndpoint",method:n,path:"/new-path",responses:[{status:200,description:i("apiFlow.success","Success")}]};H({endpoints:[...a.endpoints,d]}),_(d.id),I(!1)},D=n=>{H({endpoints:a.endpoints.filter(d=>d.id!==n)}),j===n&&_(a.endpoints[0]?.id||null)},Y=async()=>{b&&(B(!0),R(null),await new Promise(n=>setTimeout(n,1e3)),R({status:200,body:{message:i("apiFlow.mockResponse","Mock response"),timestamp:new Date().toISOString()}}),B(!1),u?.(b.id))},q=v.useMemo(()=>Zt(a),[a]),F=()=>{m?.(q)};v.useMemo(()=>{const n=new Set;return a.endpoints.forEach(d=>d.tags?.forEach(S=>n.add(S))),Array.from(n)},[a.endpoints]);const $={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 ${h||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:$.bg,color:$.text,fontFamily:"system-ui, sans-serif",...r},"data-testid":C,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${$.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:18},children:[e.jsx(s.NiceIcon,{name:"plug",size:16})," ",i("apiFlow.apiFlow","API Flow")]}),e.jsx("input",{type:"text",value:a.name,onChange:n=>H({name:n.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:14,fontWeight:600}}),e.jsx("input",{type:"text",value:a.baseUrl,onChange:n=>H({baseUrl:n.target.value}),placeholder:i("apiFlow.baseUrl","Base URL"),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:13,width:300}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>l?.(a),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(s.NiceIcon,{name:"save",size:14})," ",i("apiFlow.save","Save")]})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${$.border}`,padding:"0 20px"},children:["endpoints","auth","settings","test","preview"].map(n=>e.jsxs("button",{onClick:()=>w(n),style:{padding:"12px 20px",border:"none",background:"transparent",color:x===n?$.text:$.textMuted,cursor:"pointer",fontSize:13,fontWeight:x===n?600:400,borderBottom:x===n?`2px solid ${$.accent}`:"2px solid transparent",marginBottom:-1},children:[n==="endpoints"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"link",size:14})," ",i("apiFlow.endpoints","Endpoints")]}),n==="auth"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"lock",size:14})," ",i("apiFlow.auth","Auth")]}),n==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"settings",size:14})," ",i("apiFlow.settings","Settings")]}),n==="test"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"flask",size:14})," ",i("apiFlow.test","Test")]}),n==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," ",i("apiFlow.preview","Preview")]})]},n))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[x==="endpoints"&&e.jsxs("div",{style:{width:280,borderRight:`1px solid ${$.border}`,padding:12,display:"flex",flexDirection:"column",gap:4,overflow:"auto"},children:[e.jsx("div",{style:{fontSize:11,color:$.textMuted,marginBottom:8},children:i("apiFlow.endpoints2","ENDPOINTS ({endpoints})").replace("{endpoints}",String(a.endpoints.length))}),a.endpoints.map(n=>e.jsxs("button",{onClick:()=>_(n.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:j===n.id?$.accent+"30":$.cardBg,color:$.text,cursor:"pointer",textAlign:"left",display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{padding:"2px 6px",borderRadius:4,background:je[n.method]+"30",color:je[n.method],fontSize:10,fontWeight:600},children:n.method}),e.jsxs("div",{style:{flex:1,overflow:"hidden"},children:[e.jsx("div",{style:{fontFamily:"monospace",fontSize:12},children:n.name}),e.jsx("div",{style:{fontSize:10,color:$.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n.path})]})]},n.id)),e.jsx("button",{onClick:()=>I(!0),style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${$.border}`,background:"transparent",color:$.textMuted,cursor:"pointer",fontSize:13,marginTop:8},children:i("apiFlow.addEndpoint2","+ Add Endpoint")})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[x==="endpoints"&&b&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[e.jsx("select",{value:b.method,onChange:n=>O(b.id,{method:n.target.value}),style:{padding:"8px 12px",borderRadius:6,border:"none",background:je[b.method]+"30",color:je[b.method],fontSize:13,fontWeight:600,cursor:"pointer"},children:["GET","POST","PUT","PATCH","DELETE"].map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx("input",{type:"text",value:b.path,onChange:n=>O(b.id,{path:n.target.value}),style:{flex:1,padding:"8px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:14,fontFamily:"monospace"}}),e.jsxs("button",{onClick:()=>D(b.id),style:{padding:"8px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:13},children:[e.jsx(s.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:$.textMuted,marginBottom:4},children:i("apiFlow.name","Name")}),e.jsx("input",{type:"text",value:b.name,onChange:n=>O(b.id,{name:n.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:$.textMuted,marginBottom:4},children:i("apiFlow.description","Description")}),e.jsx("input",{type:"text",value:b.description||"",onChange:n=>O(b.id,{description:n.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:$.cardBg,color:$.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(s.NiceIcon,{name:"clipboard",size:14})," ",i("apiFlow.parameters","Parameters")]}),b.pathParams&&b.pathParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:$.textMuted,marginBottom:8},children:i("apiFlow.pathParameters","PATH PARAMETERS")}),b.pathParams.map(n=>e.jsxs("div",{style:{padding:12,background:$.cardBg,borderRadius:6,marginBottom:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("code",{style:{fontWeight:600},children:n.name}),e.jsx("span",{style:{color:$.textMuted,fontSize:12},children:n.type}),n.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)",fontSize:10},children:i("apiFlow.required","required")})]},n.id))]}),b.queryParams&&b.queryParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:$.textMuted,marginBottom:8},children:i("apiFlow.queryParameters","QUERY PARAMETERS")}),b.queryParams.map(n=>e.jsxs("div",{style:{padding:12,background:$.cardBg,borderRadius:6,marginBottom:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("code",{style:{fontWeight:600},children:n.name}),e.jsx("span",{style:{color:$.textMuted,fontSize:12},children:n.type}),n.defaultValue!==void 0&&e.jsxs("span",{style:{color:"var(--nice-color-warning, #f59e0b)",fontSize:11},children:["= ",JSON.stringify(n.defaultValue)]})]},n.id))]}),b.body&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:$.textMuted,marginBottom:8},children:i("apiFlow.requestBody","REQUEST BODY")}),e.jsxs("div",{style:{padding:12,background:$.cardBg,borderRadius:6},children:[e.jsxs("div",{style:{fontSize:12,marginBottom:8},children:["Content-Type: ",e.jsx("code",{children:b.body.contentType})]}),b.body.schema&&e.jsx("pre",{style:{margin:0,padding:12,background:$.bg,borderRadius:4,fontSize:11,overflow:"auto"},children:JSON.stringify(b.body.schema,null,2)})]})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsxs("h4",{style:{margin:"0 0 12px"},children:[e.jsx(s.NiceIcon,{name:"upload",size:16})," ",i("apiFlow.responses","Responses")]}),e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:b.responses.map(n=>e.jsxs("div",{style:{padding:12,background:$.cardBg,borderRadius:6,minWidth:120},children:[e.jsx("div",{style:{fontSize:18,fontWeight:600,color:n.status<300?"var(--nice-color-success, #22c55e)":n.status<400?"var(--nice-color-warning, #f59e0b)":"var(--nice-color-error, #ef4444)"},children:n.status}),e.jsx("div",{style:{fontSize:11,color:$.textMuted},children:n.description})]},n.status))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{style:{padding:16,background:$.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:b.cache?.enabled||!1,onChange:n=>O(b.id,{cache:{...b.cache,enabled:n.target.checked}})}),e.jsx(s.NiceIcon,{name:"box",size:14})," ",i("apiFlow.cache","Cache")]}),b.cache?.enabled&&e.jsx("div",{style:{fontSize:12,color:$.textMuted},children:i("apiFlow.ttlSStrategy","TTL: {ttl}s • Strategy: {strategy}").replace("{ttl}",String(b.cache.ttl)).replace("{strategy}",String(b.cache.strategy))})]}),e.jsxs("div",{style:{padding:16,background:$.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:b.retry?.enabled||!1,onChange:n=>O(b.id,{retry:{...b.retry,enabled:n.target.checked,maxAttempts:3,backoff:"exponential"}})}),e.jsx(s.NiceIcon,{name:"refresh",size:14})," ",i("apiFlow.retry","Retry")]}),b.retry?.enabled&&e.jsx("div",{style:{fontSize:12,color:$.textMuted},children:i("apiFlow.maxBackoff","Max: {maxAttempts} • {backoff} backoff").replace("{maxAttempts}",String(b.retry.maxAttempts)).replace("{backoff}",String(b.retry.backoff))})]})]})]}),x==="auth"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsxs("h4",{style:{marginTop:0},children:[e.jsx(s.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:$.textMuted,marginBottom:8},children:i("apiFlow.authType","Auth Type")}),e.jsxs("select",{value:a.auth?.type||"none",onChange:n=>H({auth:{...a.auth,type:n.target.value}}),style:{padding:"10px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:$.cardBg,color:$.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")})]})]}),a.auth?.type==="bearer"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:$.textMuted,marginBottom:8},children:i("apiFlow.tokenSource","Token Source")}),e.jsx("input",{type:"text",value:a.auth.tokenSource||"",onChange:n=>H({auth:{...a.auth,tokenSource:n.target.value}}),placeholder:"state.auth.token",style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:$.textMuted,marginBottom:8},children:i("apiFlow.headerName","Header Name")}),e.jsx("input",{type:"text",value:a.auth.headerName||"Authorization",onChange:n=>H({auth:{...a.auth,headerName:n.target.value}}),style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:13,boxSizing:"border-box"}})]})]}),e.jsxs("h4",{children:[e.jsx(s.NiceIcon,{name:"globe",size:16})," ",i("apiFlow.globalHeaders","Global Headers")]}),e.jsx("div",{style:{padding:16,background:$.cardBg,borderRadius:8},children:Object.entries(a.globalHeaders||{}).map(([n,d])=>e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1},children:n}),e.jsx("span",{style:{color:$.textMuted},children:":"}),e.jsx("code",{style:{flex:2,color:"var(--nice-color-success, #22c55e)"},children:d})]},n))})]}),x==="settings"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsxs("h4",{style:{marginTop:0},children:[e.jsx(s.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:a.errorHandling?.globalErrorHandler||!1,onChange:n=>H({errorHandling:{...a.errorHandling,globalErrorHandler:n.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:a.errorHandling?.retryOnNetworkError||!1,onChange:n=>H({errorHandling:{...a.errorHandling,retryOnNetworkError:n.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:a.errorHandling?.transformError||!1,onChange:n=>H({errorHandling:{...a.errorHandling,transformError:n.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:a.cacheConfig?.enabled||!1,onChange:n=>H({cacheConfig:{...a.cacheConfig,enabled:n.target.checked}})}),i("apiFlow.enableCaching","Enable caching")]}),a.cacheConfig?.enabled&&e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:12,color:$.textMuted},children:i("apiFlow.storage","Storage")}),e.jsxs("select",{value:a.cacheConfig.storage,onChange:n=>H({cacheConfig:{...a.cacheConfig,storage:n.target.value}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${$.border}`,background:$.cardBg,color:$.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:$.textMuted},children:i("apiFlow.defaultTtlSeconds","Default TTL (seconds)")}),e.jsx("input",{type:"number",value:a.cacheConfig.defaultTTL,onChange:n=>H({cacheConfig:{...a.cacheConfig,defaultTTL:parseInt(n.target.value)}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${$.border}`,background:$.cardBg,color:$.text,fontSize:13,width:100}})]})]})]})]}),x==="test"&&b&&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[b.method]+"30",color:je[b.method],fontSize:12,fontWeight:600},children:b.method}),e.jsxs("code",{style:{flex:1,fontSize:14},children:[a.baseUrl,b.path]}),e.jsx("button",{onClick:Y,disabled:P,style:{padding:"10px 20px",borderRadius:6,border:"none",background:$.accent,color:"var(--nice-color-white, #fff)",cursor:P?"not-allowed":"pointer",fontSize:13,fontWeight:500,opacity:P?.7:1},children:P?e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"clock",size:14})," ",i("apiFlow.testing","Testing...")]}):e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"rocket",size:14})," ",i("apiFlow.sendRequest","Send Request")]})})]}),M&&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:M.status<300?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"},children:M.status}),e.jsx("span",{style:{color:$.textMuted},children:M.status<300?i("apiFlow.ok","OK"):i("apiFlow.error","Error")})]}),e.jsx("pre",{style:{padding:16,background:$.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0},children:JSON.stringify(M.body,null,2)})]})]}),x==="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:F,style:{padding:"8px 16px",borderRadius:4,border:"none",background:$.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," ",i("apiFlow.export","Export")]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(q),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${$.border}`,background:"transparent",color:$.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," ",i("apiFlow.copy","Copy")]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:$.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:q})]})]})]}),A&&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:$.cardBg,borderRadius:12,padding:24,width:400},onClick:n=>n.stopPropagation(),children:[e.jsxs("h4",{style:{margin:"0 0 16px"},children:[e.jsx(s.NiceIcon,{name:"plus",size:16})," ",i("apiFlow.addEndpoint","Add Endpoint")]}),e.jsx("p",{style:{color:$.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(n=>e.jsx("button",{onClick:()=>J(n),style:{padding:"12px 24px",borderRadius:6,border:"none",background:je[n]+"30",color:je[n],cursor:"pointer",fontSize:14,fontWeight:600},children:n},n))})]})})]})},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=t=>{const p=lt(t.sourceSchema),c=lt(t.targetSchema),m=t.fieldMappings.map(l=>{const h=t.transformations.find(i=>i.id===l.transform),r=l.targetField;if(!l.sourceField)return` result.${r} = ${JSON.stringify(l.defaultValue)};`;const C=l.sourceField.split(",").map(i=>i.trim());if(h)switch(h.type){case"concat":return` result.${r} = [${C.map(i=>`source.${i}`).join(", ")}].filter(Boolean).join('${h.config.separator||" "}');`;case"format":if(C.length===1){const i=h.config.format||"{value}";return i.includes("{value}")?` result.${r} = '${i}'.replace('{value}', String(source.${C[0]}));`:` result.${r} = formatDate(source.${C[0]}, '${i}');`}break;case"custom":return` result.${r} = ${h.config.expression?.replace(/(\w+)\.(\w+)/g,"source.$1.$2")};`;case"convert":return` result.${r} = ${h.config.convertTo}(source.${C[0]});`}if(C.length===1){const i=l.defaultValue!==void 0?` ?? ${JSON.stringify(l.defaultValue)}`:"";return` result.${r} = source.${C[0]}${i};`}return` // TODO: Manual mapping for ${r}`}),u=t.validationRules.map(l=>{switch(l.type){case"required":return` if (!data.${l.field}) errors.push('${l.message||l.field+" is required"}');`;case"pattern":return` if (data.${l.field} && !/${l.value}/.test(data.${l.field})) errors.push('${l.message||"Invalid format"}');`;default:return` // ${l.type} validation for ${l.field}`}});return`/**
|
|
95
|
+
* ${t.name}
|
|
96
|
+
* ${t.description||""}
|
|
97
|
+
* Auto-generated by NiceDataMapper
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
// Source Type
|
|
101
|
+
${p}
|
|
102
|
+
|
|
103
|
+
// Target Type
|
|
104
|
+
${c}
|
|
105
|
+
|
|
106
|
+
// Validation
|
|
107
|
+
export function validate${t.targetSchema.name}(data: ${t.targetSchema.name}): string[] {
|
|
108
|
+
const errors: string[] = [];
|
|
109
|
+
${u.join(`
|
|
110
|
+
`)}
|
|
111
|
+
return errors;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Mapper
|
|
115
|
+
export function ${t.name.charAt(0).toLowerCase()+t.name.slice(1)}(source: ${t.sourceSchema.name}): ${t.targetSchema.name} {
|
|
116
|
+
const result = {} as ${t.targetSchema.name};
|
|
117
|
+
|
|
118
|
+
${m.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=(t,p)=>{const c=(u,l)=>{const h=" ".repeat(l),r=u.nullable?"?":"";if(u.type==="object"&&u.children){const i=u.children.map(a=>c(a,l+1)).join(`
|
|
136
|
+
`);return`${h}${u.name}${r}: {
|
|
137
|
+
${i}
|
|
138
|
+
${h}};`}const C={string:"string",number:"number",boolean:"boolean",date:"string | Date",array:"unknown[]",object:"Record<string, unknown>",any:"unknown"}[u.type];return`${h}${u.name}${r}: ${C};`},m=t.fields.map(u=>c(u,1)).join(`
|
|
139
|
+
`);return`interface ${t.name} {
|
|
140
|
+
${m}
|
|
141
|
+
}`},Ze=(t,p="")=>{const c=[];return t.forEach(m=>{c.push(m),m.children&&c.push(...Ze(m.children,m.path+"."))}),c},yt=({mapping:t,defaultMapping:p,mode:c="full",sourceSchemas:m=[],targetSchemas:u=[],onMappingChange:l,onExport:h,onTest:r,onSave:C,className:i,style:a,"data-testid":f})=>{const{t:x}=s.useNiceTranslation(),[w,j]=s.useControllableState({value:t,defaultValue:p,fallbackValue:Xt,onChange:l,componentName:"NiceDataMapper"}),[_,A]=v.useState("mapping"),I=c==="mapping"?"mapping":_,[M,R]=v.useState(null),[P,B]=v.useState(""),[b,H]=v.useState(""),[O,J]=v.useState(null),D=v.useCallback(g=>{j({...w,...g})},[w,j]),Y=v.useMemo(()=>Ze(w.sourceSchema.fields),[w.sourceSchema.fields]),q=v.useMemo(()=>Ze(w.targetSchema.fields),[w.targetSchema.fields]),F=(g,y)=>{const z={id:`mapping-${Date.now()}`,sourceField:g,targetField:y};D({fieldMappings:[...w.fieldMappings,z]})},$=g=>{D({fieldMappings:w.fieldMappings.filter(y=>y.id!==g)})},n=()=>{try{const g=JSON.parse(P),y={};w.fieldMappings.forEach(z=>{if(!z.sourceField){y[z.targetField]=z.defaultValue;return}const o=z.sourceField.split(",").map(N=>N.trim()),Q=N=>N.split(".").reduce((ne,k)=>ne?.[k],g),oe=w.transformations.find(N=>N.id===z.transform);if(oe?.type==="concat")y[z.targetField]=o.map(Q).filter(Boolean).join(oe.config.separator||" ");else if(oe?.type==="format"&&o.length===1){const N=Q(o[0]);y[z.targetField]=(oe.config.format||"{value}").replace("{value}",String(N))}else o.length===1&&(y[z.targetField]=Q(o[0])??z.defaultValue)}),H(JSON.stringify(y,null,2)),r?.(y)}catch(g){H(`Error: ${g.message}`)}},d=v.useMemo(()=>en(w),[w]),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)"};return e.jsxs("div",{className:`nice-data-mapper ${i||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:S.bg,color:S.text,fontFamily:"system-ui, sans-serif",...a},"data-testid":f,children:[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(s.NiceIcon,{name:"refresh",size:16})," ",x("dataMapper.dataMapper","Data Mapper")]}),c!=="mapping"&&e.jsx("input",{type:"text","aria-label":x("dataMapper.name","Mapping name"),value:w.name,onChange:g=>D({name:g.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.cardBg,color:S.text,fontSize:14,fontWeight:600}}),c!=="mapping"&&e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsxs("button",{type:"button",onClick:()=>C?.(w),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(s.NiceIcon,{name:"save",size:14})," ",x("dataMapper.save","Save")]})})]}),c!=="mapping"&&e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${S.border}`,padding:"0 20px"},children:["mapping","transforms","validation","test","preview"].map(g=>e.jsxs("button",{onClick:()=>A(g),style:{padding:"12px 20px",border:"none",background:"transparent",color:I===g?S.text:S.textMuted,cursor:"pointer",fontSize:13,fontWeight:I===g?600:400,borderBottom:I===g?`2px solid ${S.accent}`:"2px solid transparent",marginBottom:-1},children:[g==="mapping"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"link",size:14})," ",x("dataMapper.mapping","Mapping")]}),g==="transforms"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"zap",size:14})," ",x("dataMapper.transforms","Transforms")]}),g==="validation"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"check",size:14})," ",x("dataMapper.validation","Validation")]}),g==="test"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"flask",size:14})," ",x("dataMapper.test","Test")]}),g==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," ",x("dataMapper.preview","Preview")]})]},g))}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[I==="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(s.NiceIcon,{name:"download",size:14})," ",x("dataMapper.source","Source: {name}").replace("{name}",String(w.sourceSchema.name))]}),e.jsx("div",{style:{flex:1,border:`1px solid ${S.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:Y.map(g=>{const y=g.path.split(".").length-1,z=w.fieldMappings.some(o=>o.sourceField.split(",").some(Q=>Q.trim()===g.path));return e.jsxs("div",{draggable:!0,onDragStart:()=>J(g.path),onDragEnd:()=>J(null),style:{padding:"10px 12px",paddingLeft:12+y*16,borderBottom:`1px solid ${S.border}`,display:"flex",alignItems:"center",gap:8,cursor:"grab",background:z?"var(--nice-success-tint-10, #22c55e10)":"transparent",opacity:g.type==="object"&&g.children?.7:1},children:[e.jsx("span",{style:{color:st[g.type],fontSize:14},children:e.jsx(s.NiceIcon,{name:ot[g.type],size:14})}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:g.name}),e.jsx("span",{style:{fontSize:10,color:S.textMuted},children:g.type}),z&&e.jsx("span",{style:{marginLeft:"auto",color:"var(--nice-color-success, #22c55e)",fontSize:10},children:e.jsx(s.NiceIcon,{name:"check",size:14})}),!(g.type==="object"&&g.children)&&e.jsxs("select",{"aria-label":x("dataMapper.mapTo","Map {field} to").replace("{field}",g.name),value:"",onChange:o=>{o.target.value&&F(g.path,o.target.value)},style:{marginLeft:z?4:"auto",maxWidth:130,fontSize:11,background:S.cardBg,color:S.text,border:`1px solid ${S.border}`,borderRadius:4},children:[e.jsx("option",{value:"",children:x("dataMapper.mapToPlaceholder","Map to…")}),q.filter(o=>!(o.type==="object"&&o.children)&&!w.fieldMappings.some(Q=>Q.targetField===o.path)).map(o=>e.jsx("option",{value:o.path,children:o.path},o.id))]})]},g.id)})})]}),e.jsxs("div",{style:{width:300,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:S.accent+"20",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:[e.jsx(s.NiceIcon,{name:"link",size:16})," ",x("dataMapper.mappings","Mappings ({fieldMappings})").replace("{fieldMappings}",String(w.fieldMappings.length))]}),e.jsx("div",{style:{flex:1,border:`1px solid ${S.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto",padding:8},children:w.fieldMappings.map(g=>{const y=w.transformations.find(z=>z.id===g.transform);return e.jsxs("div",{style:{padding:8,background:S.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:g.sourceField||"(default)"}),e.jsx("span",{style:{color:S.textMuted},children:e.jsx(s.NiceIcon,{name:"arrow-right",size:12})}),e.jsx("code",{style:{color:"var(--nice-color-primary, #3b82f6)"},children:g.targetField}),e.jsx("button",{onClick:()=>$(g.id),"aria-label":x("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(s.NiceIcon,{name:"close",size:14})})]}),y&&e.jsxs("div",{style:{color:S.textMuted,display:"flex",alignItems:"center",gap:4},children:[e.jsx(s.NiceIcon,{name:at[y.type],size:14})," ",y.name]}),g.defaultValue!==void 0&&e.jsx("div",{style:{color:"var(--nice-color-warning, #f59e0b)"},children:x("dataMapper.default","Default: {defaultValue}").replace("{defaultValue}",String(JSON.stringify(g.defaultValue)))})]},g.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(s.NiceIcon,{name:"upload",size:14})," ",x("dataMapper.target","Target: {name}").replace("{name}",String(w.targetSchema.name))]}),e.jsx("div",{style:{flex:1,border:`1px solid ${S.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:q.map(g=>{const y=g.path.split(".").length-1,z=w.fieldMappings.some(o=>o.targetField===g.path);return e.jsxs("div",{onDragOver:o=>o.preventDefault(),onDrop:()=>{O&&!z&&F(O,g.path)},style:{padding:"10px 12px",paddingLeft:12+y*16,borderBottom:`1px solid ${S.border}`,display:"flex",alignItems:"center",gap:8,background:O&&!z?S.accent+"10":z?"color-mix(in srgb, var(--nice-color-primary, #3b82f6) 6%, transparent)":"transparent",transition:"background 0.15s"},children:[e.jsx("span",{style:{color:st[g.type],fontSize:14},children:e.jsx(s.NiceIcon,{name:ot[g.type],size:14})}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:g.name}),e.jsx("span",{style:{fontSize:10,color:S.textMuted},children:g.type}),g.nullable&&e.jsx("span",{style:{fontSize:10,color:S.textMuted},children:"?"}),z&&e.jsx("span",{style:{marginLeft:"auto",color:"var(--nice-color-primary, #3b82f6)",fontSize:10},children:e.jsx(s.NiceIcon,{name:"check",size:14})})]},g.id)})})]})]}),I==="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(s.NiceIcon,{name:"zap",size:16})," ",x("dataMapper.transformations","Transformations")]}),e.jsx("button",{onClick:()=>{const g={id:`tr-${Date.now()}`,name:"New Transform",type:"direct",config:{}};D({transformations:[...w.transformations,g]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:S.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:x("dataMapper.addTransform","+ Add Transform")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:16},children:w.transformations.map(g=>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,marginBottom:12},children:[e.jsx("span",{style:{fontSize:20},children:e.jsx(s.NiceIcon,{name:at[g.type],size:20})}),e.jsx("input",{type:"text",value:g.name,onChange:y=>{const z=w.transformations.map(o=>o.id===g.id?{...o,name:y.target.value}:o);D({transformations:z})},style:{flex:1,padding:"6px 8px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:13,fontWeight:600}})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:S.textMuted,marginBottom:4},children:x("dataMapper.type","Type")}),e.jsxs("select",{value:g.type,onChange:y=>{const z=w.transformations.map(o=>o.id===g.id?{...o,type:y.target.value}:o);D({transformations:z})},style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12},children:[e.jsx("option",{value:"direct",children:x("dataMapper.direct","Direct")}),e.jsx("option",{value:"format",children:x("dataMapper.format","Format")}),e.jsx("option",{value:"convert",children:x("dataMapper.convert","Convert")}),e.jsx("option",{value:"concat",children:x("dataMapper.concatenate","Concatenate")}),e.jsx("option",{value:"split",children:x("dataMapper.split","Split")}),e.jsx("option",{value:"calculate",children:x("dataMapper.calculate","Calculate")}),e.jsx("option",{value:"lookup",children:x("dataMapper.lookup","Lookup")}),e.jsx("option",{value:"conditional",children:x("dataMapper.conditional","Conditional")}),e.jsx("option",{value:"custom",children:x("dataMapper.custom","Custom")})]})]}),(g.type==="format"||g.type==="concat")&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:S.textMuted,marginBottom:4},children:g.type==="format"?x("dataMapper.formatPattern","Format Pattern"):x("dataMapper.separator","Separator")}),e.jsx("input",{type:"text",value:g.type==="format"?g.config.format||"":g.config.separator||"",onChange:y=>{const z=w.transformations.map(o=>o.id===g.id?{...o,config:{...o.config,[g.type==="format"?"format":"separator"]:y.target.value}}:o);D({transformations:z})},placeholder:g.type==="format"?x("dataMapper.orYyyyMmDd","{value} or YYYY-MM-DD"):", ",style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12,fontFamily:"monospace",boxSizing:"border-box"}})]}),g.type==="custom"&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:S.textMuted,marginBottom:4},children:x("dataMapper.expression","Expression")}),e.jsx("textarea",{value:g.config.expression||"",onChange:y=>{const z=w.transformations.map(o=>o.id===g.id?{...o,config:{...o.config,expression:y.target.value}}:o);D({transformations:z})},rows:3,style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12,fontFamily:"monospace",resize:"vertical",boxSizing:"border-box"}})]})]},g.id))})]}),I==="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(s.NiceIcon,{name:"check",size:16})," ",x("dataMapper.validationRules","Validation Rules")]}),e.jsx("button",{onClick:()=>{const g={id:`v-${Date.now()}`,field:"",type:"required",message:""};D({validationRules:[...w.validationRules,g]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:S.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:x("dataMapper.addRule","+ Add Rule")})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:w.validationRules.map(g=>e.jsxs("div",{style:{padding:16,background:S.cardBg,borderRadius:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsxs("select",{value:g.field,onChange:y=>{const z=w.validationRules.map(o=>o.id===g.id?{...o,field:y.target.value}:o);D({validationRules:z})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12},children:[e.jsx("option",{value:"",children:x("dataMapper.selectField","Select field...")}),q.map(y=>e.jsx("option",{value:y.path,children:y.path},y.id))]}),e.jsxs("select",{value:g.type,onChange:y=>{const z=w.validationRules.map(o=>o.id===g.id?{...o,type:y.target.value}:o);D({validationRules:z})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12},children:[e.jsx("option",{value:"required",children:x("dataMapper.required","Required")}),e.jsx("option",{value:"type",children:x("dataMapper.type","Type")}),e.jsx("option",{value:"min",children:x("dataMapper.min","Min")}),e.jsx("option",{value:"max",children:x("dataMapper.max","Max")}),e.jsx("option",{value:"pattern",children:x("dataMapper.pattern","Pattern")}),e.jsx("option",{value:"enum",children:x("dataMapper.enum","Enum")}),e.jsx("option",{value:"custom",children:x("dataMapper.custom","Custom")})]}),(g.type==="pattern"||g.type==="min"||g.type==="max")&&e.jsx("input",{type:"text",value:String(g.value||""),onChange:y=>{const z=w.validationRules.map(o=>o.id===g.id?{...o,value:y.target.value}:o);D({validationRules:z})},placeholder:x("dataMapper.value","Value"),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12,width:150}}),e.jsx("input",{type:"text",value:g.message||"",onChange:y=>{const z=w.validationRules.map(o=>o.id===g.id?{...o,message:y.target.value}:o);D({validationRules:z})},placeholder:x("dataMapper.errorMessage","Error message"),style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${S.border}`,background:S.bg,color:S.text,fontSize:12}}),e.jsx("button",{onClick:()=>{D({validationRules:w.validationRules.filter(y=>y.id!==g.id)})},"aria-label":x("dataMapper.delete","Delete"),style:{padding:6,border:"none",background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:14},children:e.jsx(s.NiceIcon,{name:"trash",size:14})})]},g.id))})]}),I==="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(s.NiceIcon,{name:"download",size:16})," ",x("dataMapper.input","Input")]}),e.jsx("button",{onClick:()=>{const g={},y=(z,o)=>{z.forEach(Q=>{Q.children&&Q.type==="object"?(o[Q.name]={},y(Q.children,o[Q.name])):o[Q.name]={string:"sample",number:42,boolean:!0,date:new Date().toISOString(),array:[],object:{},any:null}[Q.type]})};y(w.sourceSchema.fields,g),B(JSON.stringify(g,null,2))},style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${S.border}`,background:"transparent",color:S.text,cursor:"pointer",fontSize:11},children:x("dataMapper.generateSample","Generate Sample")})]}),e.jsx("textarea",{value:P,onChange:g=>B(g.target.value),placeholder:x("dataMapper.pasteJsonInputHere","Paste JSON input here..."),style:{flex:1,padding:12,borderRadius:8,border:`1px solid ${S.border}`,background:S.cardBg,color:S.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(s.NiceIcon,{name:"upload",size:16})," ",x("dataMapper.output","Output")]}),e.jsxs("button",{onClick:n,style:{padding:"6px 16px",borderRadius:4,border:"none",background:S.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:12},children:[e.jsx(s.NiceIcon,{name:"refresh",size:14})," ",x("dataMapper.transform","Transform")]})]}),e.jsx("pre",{style:{flex:1,padding:12,borderRadius:8,background:S.cardBg,margin:0,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace"},children:b||"Run transform to see output"})]})]}),I==="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:()=>h?.(d),style:{padding:"8px 16px",borderRadius:4,border:"none",background:S.accent,color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," ",x("dataMapper.export","Export")]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(d),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${S.border}`,background:"transparent",color:S.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," ",x("dataMapper.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: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=t=>{const p=t.filter(m=>m.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
|
+
${p.map(m=>`export type ${m.name.replace(/\s+/g,"")}Event = {
|
|
153
|
+
source: '${m.source.type}';
|
|
154
|
+
payload: unknown;
|
|
155
|
+
};`).join(`
|
|
156
|
+
|
|
157
|
+
`)}
|
|
158
|
+
|
|
159
|
+
// Event Handlers
|
|
160
|
+
${p.map(m=>{const u=JSON.stringify(m.source.config,null,2),l=m.handlers.flatMap(h=>h.modifiers||[]).map(h=>`.${h.type}(${h.value})`).join("");return`
|
|
161
|
+
/**
|
|
162
|
+
* ${m.name}
|
|
163
|
+
* ${m.description||""}
|
|
164
|
+
*/
|
|
165
|
+
export const ${m.name.replace(/\s+/g,"").toLowerCase()}Handler = eventBus
|
|
166
|
+
.on('${m.source.type}', ${u})${l}
|
|
167
|
+
.pipe(
|
|
168
|
+
${m.handlers.map((h,r)=>` // Step ${r+1}: ${h.type}
|
|
169
|
+
async (event) => {
|
|
170
|
+
${ct(h)}
|
|
171
|
+
},`).join(`
|
|
172
|
+
`)}
|
|
173
|
+
)
|
|
174
|
+
${m.errorHandler?`.catch(async (error) => {
|
|
175
|
+
${ct(m.errorHandler)}
|
|
176
|
+
})`:""};`}).join(`
|
|
177
|
+
`)}
|
|
178
|
+
|
|
179
|
+
// Initialize all handlers
|
|
180
|
+
export function initEventOrchestration() {
|
|
181
|
+
${p.map(m=>` ${m.name.replace(/\s+/g,"").toLowerCase()}Handler.start();`).join(`
|
|
182
|
+
`)}
|
|
183
|
+
console.log('Event orchestration initialized');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Cleanup
|
|
187
|
+
export function destroyEventOrchestration() {
|
|
188
|
+
${p.map(m=>` ${m.name.replace(/\s+/g,"").toLowerCase()}Handler.stop();`).join(`
|
|
189
|
+
`)}
|
|
190
|
+
}
|
|
191
|
+
`},ct=t=>{switch(t.type){case"action":return`dispatch({ type: '${t.config.actionType}', payload: ${JSON.stringify(t.config.payload)} });`;case"transform":return`return (${t.config.expression})(event);`;case"dispatch":return`eventBus.emit('${t.config.eventName}', ${JSON.stringify(t.config.payload)});`;case"api-call":return`await fetch('${t.config.endpoint}', { method: '${t.config.method}', body: JSON.stringify(event.payload) });`;case"state-update":return`updateState('${t.config.path}', ${t.config.value});`;case"notification":return`showNotification({ type: '${t.config.type}', message: '${t.config.message}' });`;case"log":return`console.${t.config.level||"log"}('${t.config.message}', event);`;case"delay":return`await new Promise(r => setTimeout(r, ${t.config.duration}));`;case"branch":return`if (${t.config.condition}) { /* true branch */ } else { /* false branch */ }`;default:return"// Unknown handler type"}},vt=({flows:t=sn,eventSources:p=nn,eventHandlers:c=rn,onFlowsChange:m,onExport:u,onTest:l,className:h,style:r,"data-testid":C})=>{const{t:i}=s.useNiceTranslation(),[a,f]=v.useState(t),[x,w]=v.useState(a[0]?.id??null),[j,_]=v.useState("visual"),[A,I]=v.useState(!1),[M,R]=v.useState(""),[P,B]=v.useState(new Set),b=v.useMemo(()=>a.find(d=>d.id===x),[a,x]),H=v.useMemo(()=>on(a),[a]),O=v.useCallback((d,S)=>{f(g=>{const y=g.map(z=>z.id===d?{...z,...S}:z);return m?.(y),y})},[m]),J=()=>{if(!M.trim())return;const d={id:`flow-${Date.now()}`,name:M,enabled:!0,source:{id:`src-${Date.now()}`,type:"ui-event",config:{element:"",event:"click"}},handlers:[]};f(S=>{const g=[...S,d];return m?.(g),g}),w(d.id),I(!1),R("")},D=d=>{f(S=>{const g=S.filter(y=>y.id!==d);return m?.(g),g}),x===d&&w(a[0]?.id??null)},Y=d=>{if(!b)return;const S=c.find(z=>z.type===d),g={};S?.configSchema.forEach(z=>{z.default!==void 0&&(g[z.name]=z.default)});const y={id:`handler-${Date.now()}`,type:d,config:g};O(b.id,{handlers:[...b.handlers,y]}),B(z=>new Set([...z,y.id]))},q=(d,S)=>{b&&O(b.id,{handlers:b.handlers.map(g=>g.id===d?{...g,...S}:g)})},F=d=>{b&&O(b.id,{handlers:b.handlers.filter(S=>S.id!==d)})},$=(d,S)=>{if(!b)return;const g=b.handlers.find(o=>o.id===d);if(!g)return;const z=g.modifiers?.find(o=>o.type===S)?g.modifiers?.filter(o=>o.type!==S):[...g.modifiers||[],{type:S,value:500,unit:"ms"}];q(d,{modifiers:z})},n={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 ${h||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:n.bg,color:n.text,fontFamily:"system-ui, sans-serif",...r},"data-testid":C,children:[e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${n.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(s.NiceIcon,{name:"zap",size:16})," ",i("eventOrchestrator.eventOrchestrator","Event Orchestrator")]}),e.jsx("div",{style:{display:"flex",border:`1px solid ${n.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(d=>e.jsxs("button",{onClick:()=>_(d),style:{padding:"6px 12px",border:"none",background:j===d?n.cardBg:"transparent",color:n.text,cursor:"pointer",fontSize:12,textTransform:"capitalize",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(s.NiceIcon,{name:d==="visual"?"palette":d==="code"?"edit":"grid",size:14})," ",d]},d))}),e.jsxs("button",{onClick:()=>u?.(H),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(s.NiceIcon,{name:"upload",size:14})," ",i("eventOrchestrator.export","Export")]})]}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(j==="visual"||j==="split")&&e.jsxs("div",{style:{width:240,borderRight:`1px solid ${n.border}`,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${n.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 ${n.border}`,background:"transparent",color:n.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[a.map(d=>{const S=p.find(g=>g.type===d.source.type);return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,onClick:()=>w(d.id),style:{padding:12,background:x===d.id?n.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${x===d.id?n.border:"transparent"}`,opacity:d.enabled?1:.5},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(s.NiceIcon,{name:S?.icon??"zap",size:16}),e.jsx("span",{style:{flex:1,fontSize:13,fontWeight:500},children:d.name}),e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:d.enabled?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"}})]}),e.jsx("div",{style:{fontSize:10,color:n.textMuted,marginTop:4},children:d.handlers.length!==1?i("eventOrchestrator.handlersMany","{handlers} handlers").replace("{handlers}",String(d.handlers.length)):i("eventOrchestrator.handlersOne","{handlers} handler").replace("{handlers}",String(d.handlers.length))})]},d.id)}),A&&e.jsxs("div",{style:{padding:12,background:n.cardBg,borderRadius:6,border:"1px solid var(--nice-primary, #3b82f6)"},children:[e.jsx("input",{type:"text",value:M,onChange:d=>R(d.target.value),placeholder:i("eventOrchestrator.flowName","Flow name..."),autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:d=>d.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 ${n.border}`,background:"transparent",color:n.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")})]})]})]})]}),(j==="visual"||j==="split")&&b&&e.jsxs("div",{style:{flex:j==="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:b.name,onChange:d=>O(b.id,{name:d.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${n.border}`,background:n.cardBg,color:n.text,fontSize:16,fontWeight:600}}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:b.enabled,onChange:d=>O(b.id,{enabled:d.target.checked})}),e.jsx("span",{style:{fontSize:12},children:i("eventOrchestrator.enabled","Enabled")})]}),e.jsxs("button",{onClick:()=>l?.(b.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${n.border}`,background:"transparent",color:n.text,cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(s.NiceIcon,{name:"play",size:14})," ",i("eventOrchestrator.test","Test")]}),e.jsx("button",{onClick:()=>D(b.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(s.NiceIcon,{name:"trash",size:14})})]}),e.jsxs("div",{style:{padding:16,background:n.cardBg,borderRadius:8,marginBottom:16,borderLeft:`4px solid ${p.find(d=>d.type===b.source.type)?.color??"var(--nice-text-muted, #888)"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx(s.NiceIcon,{name:p.find(d=>d.type===b.source.type)?.icon??"zap",size:20}),e.jsx("span",{style:{fontWeight:600},children:i("eventOrchestrator.eventSource","Event Source")})]}),e.jsx("select",{value:b.source.type,onChange:d=>O(b.id,{source:{...b.source,type:d.target.value,config:{}}}),style:{width:"100%",padding:10,borderRadius:6,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:13,marginBottom:12},children:p.map(d=>e.jsx("option",{value:d.type,children:d.label},d.type))}),p.find(d=>d.type===b.source.type)?.configSchema.map(d=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsxs("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:[d.label," ",d.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)"},children:"*"})]}),d.type==="select"?e.jsx("select",{value:String(b.source.config[d.name]??""),onChange:S=>O(b.id,{source:{...b.source,config:{...b.source.config,[d.name]:S.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:d.options?.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))}):e.jsx("input",{type:d.type==="number"?"number":"text",value:String(b.source.config[d.name]??""),onChange:S=>O(b.id,{source:{...b.source,config:{...b.source.config,[d.name]:d.type==="number"?Number(S.target.value):S.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,boxSizing:"border-box"}})]},d.name))]}),e.jsx("div",{style:{textAlign:"center",color:n.textMuted,marginBottom:16},children:e.jsx(s.NiceIcon,{name:"arrow-down",size:16})}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[b.handlers.map((d,S)=>{const g=c.find(z=>z.type===d.type),y=P.has(d.id);return e.jsxs(v.Fragment,{children:[e.jsxs("div",{style:{padding:16,background:n.cardBg,borderRadius:8,borderLeft:`4px solid ${g?.color??"var(--nice-text-muted, #888)"}`},children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":P.has(d.id),onKeyDown:s.clickOnActivationKey,style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},onClick:()=>B(z=>{const o=new Set(z);return o.has(d.id)?o.delete(d.id):o.add(d.id),o}),children:[e.jsx(s.NiceIcon,{name:g?.icon??"zap",size:16}),e.jsxs("span",{style:{fontWeight:500},children:[S+1,". ",g?.label??d.type]}),d.modifiers?.map(z=>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:[z.type,": ",z.value,"ms"]},z.type)),e.jsx("span",{style:{marginLeft:"auto",color:n.textMuted,display:"inline-flex",alignItems:"center"},children:e.jsx(s.NiceIcon,{name:y?"chevron-down":"chevron-right",size:14})})]}),y&&e.jsxs("div",{style:{marginTop:12,paddingTop:12,borderTop:`1px solid ${n.border}`},children:[e.jsx("select",{value:d.type,onChange:z=>q(d.id,{type:z.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,marginBottom:12},children:c.map(z=>e.jsx("option",{value:z.type,children:z.label},z.type))}),g?.configSchema.map(z=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:z.label}),z.type==="code"?e.jsx("textarea",{value:String(d.config[z.name]??""),onChange:o=>q(d.id,{config:{...d.config,[z.name]:o.target.value}}),rows:3,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontFamily:"monospace",fontSize:11,resize:"vertical",boxSizing:"border-box"}}):z.type==="select"?e.jsx("select",{value:String(d.config[z.name]??""),onChange:o=>q(d.id,{config:{...d.config,[z.name]:o.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:z.options?.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))}):e.jsx("input",{type:z.type==="number"?"number":"text",value:String(d.config[z.name]??""),onChange:o=>q(d.id,{config:{...d.config,[z.name]:z.type==="number"?Number(o.target.value):o.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,boxSizing:"border-box"}})]},z.name)),e.jsxs("div",{style:{marginTop:12},children:[e.jsx("div",{style:{fontSize:11,color:n.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(z=>e.jsx("button",{onClick:()=>$(d.id,z),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${d.modifiers?.some(o=>o.type===z)?"var(--nice-color-accent, #8b5cf6)":n.border}`,background:d.modifiers?.some(o=>o.type===z)?"var(--nice-accent-tint-12, #8b5cf620)":"transparent",color:n.text,cursor:"pointer",fontSize:11},children:z},z))})]}),e.jsxs("button",{onClick:()=>F(d.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(s.NiceIcon,{name:"trash",size:14})," ",i("eventOrchestrator.removeHandler","Remove Handler")]})]})]}),S<b.handlers.length-1&&e.jsx("div",{style:{textAlign:"center",color:n.textMuted},children:e.jsx(s.NiceIcon,{name:"arrow-down",size:16})})]},d.id)}),e.jsxs("div",{style:{padding:16,border:`1px dashed ${n.border}`,borderRadius:8,textAlign:"center"},children:[e.jsx("div",{style:{fontSize:12,color:n.textMuted,marginBottom:12},children:i("eventOrchestrator.addHandler","Add Handler")}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center"},children:c.map(d=>e.jsxs("button",{onClick:()=>Y(d.type),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${d.color}`,background:`${d.color}20`,color:n.text,cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(s.NiceIcon,{name:d.icon,size:14})," ",d.label]},d.type))})]})]})]}),(j==="code"||j==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"var(--nice-bg-canvas, #0d1117)",borderLeft:j==="split"?`1px solid ${n.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:H})})]})]})},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=t=>t.map(p=>{const c=new Set(["import { render, screen, fireEvent, waitFor } from '@testing-library/react';","import userEvent from '@testing-library/user-event';",`import { ${p.componentName} } from './${p.componentName}';`]);p.setup?.mocks.forEach(r=>{r.type==="api"&&(c.add("import { rest } from 'msw';"),c.add("import { setupServer } from 'msw/node';"))});const m=p.setup?.mocks.map(r=>r.type==="function"?`const ${r.name} = jest.fn();`:r.type==="api"?`// API mock: ${r.name}`:"").filter(Boolean).join(`
|
|
192
|
+
`),l=p.setup?.providers&&p.setup.providers.length>0?`const Wrapper = ({ children }) => (
|
|
193
|
+
${p.setup.providers.map(r=>`<${r.name}>`).join(`
|
|
194
|
+
`)}
|
|
195
|
+
{children}
|
|
196
|
+
${p.setup.providers.reverse().map(r=>`</${r.name}>`).join(`
|
|
197
|
+
`)}
|
|
198
|
+
);`:"",h=p.tests.map(r=>{const C=r.skip?".skip":r.only?".only":"",i=r.steps.map(a=>pn(a,p)).join(`
|
|
199
|
+
`);return`
|
|
200
|
+
it${C}('${r.name}', async () => {
|
|
201
|
+
${i}
|
|
202
|
+
});`}).join(`
|
|
203
|
+
`);return`/**
|
|
204
|
+
* ${p.name}
|
|
205
|
+
* @generated by NiceTestBuilder
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
${Array.from(c).join(`
|
|
209
|
+
`)}
|
|
210
|
+
|
|
211
|
+
describe('${p.componentName}', () => {
|
|
212
|
+
${m?` // Mocks
|
|
213
|
+
${m}
|
|
214
|
+
`:""}
|
|
215
|
+
${l?` ${l}
|
|
216
|
+
`:""}
|
|
217
|
+
beforeEach(() => {
|
|
218
|
+
jest.clearAllMocks();
|
|
219
|
+
});
|
|
220
|
+
${h}
|
|
221
|
+
});
|
|
222
|
+
`}).join(`
|
|
223
|
+
|
|
224
|
+
`),pn=(t,p)=>{switch(Je[t.action],t.action){case"render":{const c=p.setup?.providers&&p.setup.providers.length>0,m=p.setup?.props?` {...${JSON.stringify(p.setup.props)}}`:"";return c?`render(<${p.componentName}${m} />, { wrapper: Wrapper });`:`render(<${p.componentName}${m} />);`}case"click":return`await userEvent.click(screen.getByRole('${t.target?.replace(/[[\]'"]/g,"")}'));`;case"type":return`await userEvent.type(screen.getByRole('textbox', { name: /${t.target}/ }), '${t.value}');`;case"select":return`await userEvent.selectOptions(screen.getByRole('combobox'), '${t.value}');`;case"hover":return`await userEvent.hover(screen.getByRole('${t.target}'));`;case"focus":return`screen.getByRole('${t.target}').focus();`;case"blur":return`screen.getByRole('${t.target}').blur();`;case"submit":return"fireEvent.submit(screen.getByRole('form'));";case"wait":if(typeof t.value=="object"&&t.value!==null){const c=t.value;return c.type==="timeout"?`await new Promise(r => setTimeout(r, ${c.value}));`:`await waitFor(() => expect(/* condition */).toBeTruthy(), { timeout: ${c.timeout??1e3} });`}return`await new Promise(r => setTimeout(r, ${t.value}));`;case"assert":if(typeof t.value=="object"&&t.value!==null){const c=t.value;if(c.mock)return`expect(${c.mock}).${c.matcher}(${c.expected?JSON.stringify(c.expected):""});`;const m=t.target?`screen.getByRole('${t.target}')`:"result",u=c.expected!==void 0?JSON.stringify(c.expected):"";return`expect(${m}).${c.matcher}(${u});`}return`expect(screen.getByRole('${t.target}')).toBeInTheDocument();`;case"snapshot":return"expect(container).toMatchSnapshot();";case"a11y-check":return`const results = await axe(container);
|
|
225
|
+
expect(results).toHaveNoViolations();`;default:return`// ${t.action}: ${JSON.stringify(t)}`}},jt=({componentName:t="MyComponent",testSuites:p=cn,availableMocks:c=[],onSuitesChange:m,onExport:u,onRun:l,onRunAll:h,tutorial:r,className:C,style:i,"data-testid":a})=>{const{t:f}=s.useNiceTranslation(),[x,w]=v.useState(p),[j,_]=v.useState(x[0]?.id??null),[A,I]=v.useState(null),[M,R]=v.useState("visual"),[P,B]=v.useState(!1),[b,H]=v.useState(""),[O,J]=v.useState(new Set),D=v.useMemo(()=>x.find(k=>k.id===j),[x,j]);v.useMemo(()=>D?.tests.find(k=>k.id===A),[D,A]);const Y=v.useMemo(()=>dn(x),[x]),q=v.useCallback((k,G)=>{w(X=>{const K=X.map(W=>W.id===k?{...W,...G}:W);return m?.(K),K})},[m]),F=()=>{if(!b.trim())return;const k={id:`suite-${Date.now()}`,name:b,componentName:t,tests:[]};w(G=>{const X=[...G,k];return m?.(X),X}),_(k.id),B(!1),H("")},$=k=>{w(G=>{const X=G.filter(K=>K.id!==k);return m?.(X),X}),j===k&&_(x[0]?.id??null)},n=()=>{if(!D)return;const k={id:`test-${Date.now()}`,name:"New test",type:"unit",steps:[{id:`step-${Date.now()}`,action:"render"}]};q(D.id,{tests:[...D.tests,k]}),I(k.id),J(G=>new Set([...G,k.id]))},d=(k,G)=>{D&&q(D.id,{tests:D.tests.map(X=>X.id===k?{...X,...G}:X)})},S=k=>{D&&(q(D.id,{tests:D.tests.filter(G=>G.id!==k)}),A===k&&I(null))},g=(k,G)=>{if(!D)return;const X=D.tests.find(W=>W.id===k);if(!X)return;const K={id:`step-${Date.now()}`,action:G};d(k,{steps:[...X.steps,K]})},y=(k,G,X)=>{if(!D)return;const K=D.tests.find(W=>W.id===k);K&&d(k,{steps:K.steps.map(W=>W.id===G?{...W,...X}:W)})},z=(k,G)=>{if(!D)return;const X=D.tests.find(K=>K.id===k);X&&d(k,{steps:X.steps.filter(K=>K.id!==G)})},o={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)"},Q=v.useMemo(()=>{const k=x.reduce((X,K)=>X+K.tests.length,0),G=x.reduce((X,K)=>X+K.tests.filter(W=>W.skip).length,0);return{total:k,skipped:G}},[x]),oe=e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${o.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsxs("h3",{style:{margin:0,fontSize:16},children:[e.jsx(s.NiceIcon,{name:"flask",size:16})," ",f("testBuilder.testBuilder","Test Builder")]}),e.jsx("div",{style:{fontSize:12,color:o.textMuted},children:f("testBuilder.testsSkipped","{total} tests • {skipped} skipped").replace("{total}",String(Q.total)).replace("{skipped}",String(Q.skipped))}),e.jsx("div",{style:{display:"flex",border:`1px solid ${o.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(k=>e.jsxs("button",{onClick:()=>R(k),style:{padding:"6px 12px",border:"none",background:M===k?o.cardBg:"transparent",color:o.text,cursor:"pointer",fontSize:12,textTransform:"capitalize"},children:[e.jsx(s.NiceIcon,{name:k==="visual"?"palette":k==="code"?"edit":"grid",size:14})," ",k]},k))}),e.jsxs("button",{onClick:h,style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"play",size:14})," ",f("testBuilder.runAll","Run All")]}),e.jsxs("button",{onClick:()=>u?.(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(s.NiceIcon,{name:"upload",size:14})," ",f("testBuilder.export","Export")]}),e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(r,ln)})]}),ne=M==="visual"||M==="split"?e.jsxs("div",{style:{width:220,borderRight:`1px solid ${o.border}`,display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${o.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600},children:f("testBuilder.testSuites","Test Suites")}),e.jsx("button",{onClick:()=>B(!0),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[x.map(k=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,onClick:()=>{_(k.id),I(null)},style:{padding:12,background:j===k.id?o.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${j===k.id?o.border:"transparent"}`},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:k.name}),e.jsx("div",{style:{fontSize:10,color:o.textMuted,marginTop:4},children:k.tests.length!==1?f("testBuilder.testsMany","{componentName} • {tests} tests").replace("{componentName}",String(k.componentName)).replace("{tests}",String(k.tests.length)):f("testBuilder.testsOne","{componentName} • {tests} test").replace("{componentName}",String(k.componentName)).replace("{tests}",String(k.tests.length))})]},k.id)),P&&e.jsxs("div",{style:{padding:12,background:o.cardBg,borderRadius:6,border:"1px solid var(--nice-primary, #3b82f6)"},children:[e.jsx("input",{type:"text",value:b,onChange:k=>H(k.target.value),placeholder:f("testBuilder.suiteName","Suite name..."),autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:k=>k.key==="Enter"&&F()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>B(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:11},children:f("testBuilder.cancel","Cancel")}),e.jsx("button",{onClick:F,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:f("testBuilder.add","Add")})]})]})]})]}):void 0;return e.jsx(ze.NiceAppShell,{flush:!0,className:`nice-test-builder ${C||""}`,style:{background:o.bg,color:o.text,fontFamily:"system-ui, sans-serif",...i},"data-testid":a,menubar:oe,sidebar:ne,children:e.jsxs("div",{style:{display:"flex",height:"100%",overflow:"hidden"},children:[(M==="visual"||M==="split")&&D&&e.jsxs("div",{style:{flex:M==="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:D.name,onChange:k=>q(D.id,{name:k.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:16,fontWeight:600}}),e.jsxs("button",{onClick:()=>l?.(D.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:12},children:[e.jsx(s.NiceIcon,{name:"play",size:14})," ",f("testBuilder.runSuite","Run Suite")]}),e.jsx("button",{onClick:()=>$(D.id),"aria-label":f("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(s.NiceIcon,{name:"trash",size:14})})]}),e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:o.textMuted,marginBottom:6},children:f("testBuilder.component","Component")}),e.jsx("input",{type:"text",value:D.componentName,onChange:k=>q(D.id,{componentName:k.target.value}),style:{width:200,padding:8,borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13}})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[D.tests.map((k,G)=>{const X=O.has(k.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:o.cardBg,borderRadius:8,border:`1px solid ${A===k.id?"var(--nice-color-primary, #3b82f6)":o.border}`,overflow:"hidden"},children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":O.has(k.id),onKeyDown:s.clickOnActivationKey,style:{padding:12,display:"flex",alignItems:"center",gap:8,cursor:"pointer",borderLeft:`4px solid ${K[k.type].color}`},onClick:()=>{I(k.id),J(W=>{const T=new Set(W);return T.has(k.id)?T.delete(k.id):T.add(k.id),T})},children:[e.jsx("span",{children:e.jsx(s.NiceIcon,{name:K[k.type].icon,size:14})}),e.jsxs("span",{style:{fontWeight:500,opacity:k.skip?.5:1},children:[G+1,". ",k.name]}),k.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:f("testBuilder.skipped","SKIPPED")}),k.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:f("testBuilder.only","ONLY")}),e.jsx("span",{style:{marginLeft:"auto",fontSize:11,color:o.textMuted},children:k.steps.length!==1?f("testBuilder.stepsMany","{steps} steps").replace("{steps}",String(k.steps.length)):f("testBuilder.stepsOne","{steps} step").replace("{steps}",String(k.steps.length))}),e.jsx("span",{style:{color:o.textMuted},children:e.jsx(s.NiceIcon,{name:X?"chevron-down":"chevron-right",size:14})})]}),X&&e.jsxs("div",{style:{padding:16,borderTop:`1px solid ${o.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:o.textMuted,marginBottom:4},children:f("testBuilder.testName","Test Name")}),e.jsx("input",{type:"text",value:k.name,onChange:W=>d(k.id,{name:W.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:12,boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:o.textMuted,marginBottom:4},children:f("testBuilder.type","Type")}),e.jsxs("select",{value:k.type,onChange:W=>d(k.id,{type:W.target.value}),style:{padding:8,borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:12},children:[e.jsx("option",{value:"unit",children:f("testBuilder.unit","Unit")}),e.jsx("option",{value:"integration",children:f("testBuilder.integration","Integration")}),e.jsx("option",{value:"e2e",children:"E2E"}),e.jsx("option",{value:"snapshot",children:f("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:k.skip??!1,onChange:W=>d(k.id,{skip:W.target.checked,only:!1})}),f("testBuilder.skip","Skip")]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:k.only??!1,onChange:W=>d(k.id,{only:W.target.checked,skip:!1})}),f("testBuilder.only2","Only")]})]})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,color:o.textMuted,marginBottom:8},children:f("testBuilder.steps","Steps")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:k.steps.map((W,T)=>{const U=Je[W.action];return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:10,background:o.bg,borderRadius:6,borderLeft:`3px solid ${U.color}`},children:[e.jsx("span",{style:{width:20,textAlign:"center",fontSize:11,color:o.textMuted},children:T+1}),e.jsx("span",{children:e.jsx(s.NiceIcon,{name:U.icon,size:14})}),e.jsx("select",{value:W.action,onChange:V=>y(k.id,W.id,{action:V.target.value}),style:{padding:6,borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:11},children:Object.entries(Je).map(([V,te])=>e.jsx("option",{value:V,children:te.label},V))}),U.hasTarget&&e.jsx("input",{type:"text",value:W.target??"",onChange:V=>y(k.id,W.id,{target:V.target.value}),placeholder:f("testBuilder.targetSelector","Target selector"),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:11}}),U.hasValue&&W.action!=="assert"&&e.jsx("input",{type:"text",value:typeof W.value=="string"?W.value:"",onChange:V=>y(k.id,W.id,{value:V.target.value}),placeholder:f("testBuilder.value","Value"),style:{width:120,padding:6,borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:11}}),e.jsx("button",{onClick:()=>z(k.id,W.id),"aria-label":f("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(s.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,T])=>e.jsxs("button",{onClick:()=>g(k.id,W),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${T.color}40`,background:`${T.color}20`,color:o.text,cursor:"pointer",fontSize:10},children:[e.jsx(s.NiceIcon,{name:T.icon,size:14})," ",T.label]},W))}),e.jsx("div",{style:{marginTop:16,display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>S(k.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(s.NiceIcon,{name:"trash",size:14})," ",f("testBuilder.deleteTest","Delete Test")]})})]})]},k.id)}),e.jsx("button",{onClick:n,style:{padding:16,borderRadius:8,border:`1px dashed ${o.border}`,background:"transparent",color:o.textMuted,cursor:"pointer",fontSize:13},children:f("testBuilder.addTest","+ Add Test")})]})]}),(M==="code"||M==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"var(--nice-bg-canvas, #0d1117)",borderLeft:M==="split"?`1px solid ${o.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=(t,p,c)=>{let m=t;Object.entries(p).forEach(([h,r])=>{const C=new RegExp(`\\{\\{\\s*${h}\\s*\\}\\}`,"g");m=m.replace(C,String(r));const i=new RegExp(`\\{\\{\\s*pascalCase\\s+${h}\\s*\\}\\}`,"g");if(typeof r=="string"){const a=r.charAt(0).toUpperCase()+r.slice(1);m=m.replace(i,a)}});const u=/\{\{#if\s+([^}]+)\}\}([\s\S]*?)\{\{\/if\}\}/g;m=m.replace(u,(h,r,C)=>{const i=r.trim(),a=i.match(/(\w+)\s*===?\s*(\w+|true|false|'[^']*'|"[^"]*")/);if(a){const[,x,w]=a,j=p[x];let _=w;return w==="true"?_=!0:w==="false"?_=!1:(w.startsWith("'")||w.startsWith('"'))&&(_=w.slice(1,-1)),j===_?C:""}return p[i]?C:""});const l=/\{\{#if\s+\(includes\s+(\w+)\s+'([^']+)'\)\}\}([\s\S]*?)\{\{\/if\}\}/g;return m=m.replace(l,(h,r,C,i)=>{const a=p[r];return Array.isArray(a)&&a.includes(C)?i:""}),m},xn=(t,p)=>{try{const c=t.split(/\s*(===|!==|==|!=)\s*/);if(c.length===3){const[m,u,l]=c,h=p[m.trim()],r=l.trim();let C=r;switch(r==="true"?C=!0:r==="false"?C=!1:(r.startsWith("'")||r.startsWith('"'))&&(C=r.slice(1,-1)),u){case"===":case"==":return h===C;case"!==":case"!=":return h!==C}}return!!p[t.trim()]}catch{return!0}},St=({templates:t,defaultTemplates:p,onTemplatesChange:c,presets:m=gn,selectedTemplate:u,defaultSelectedTemplate:l,onSelectedTemplateChange:h,defaultEngine:r="handlebars",showLibrary:C=!0,onTemplateSelect:i,onTemplateCreate:a,onTemplateUpdate:f,onTemplateDelete:x,onGenerate:w,onExport:j,onImport:_,className:A,style:I,"data-testid":M="nice-code-template"})=>{const{t:R}=s.useNiceTranslation(),P=t!==void 0&&c!==void 0,[B,b]=s.useControllableState({value:P?t:void 0,defaultValue:P?p:p??t,fallbackValue:mn,onChange:c,componentName:"NiceCodeTemplate"});ze.useIgnoredPropChangeWarning("NiceCodeTemplate","templates","onTemplatesChange",t,P);const H=u!==void 0&&h!==void 0,[O,J]=s.useControllableState({value:H?u:void 0,defaultValue:H?l:l??u,fallbackValue:null,onChange:h,componentName:"NiceCodeTemplate"});ze.useIgnoredPropChangeWarning("NiceCodeTemplate","selectedTemplate","onSelectedTemplateChange",u,H);const[D,Y]=v.useState({}),[q,F]=v.useState("editor"),[$,n]=v.useState(null),[d,S]=v.useState(!1),[g,y]=v.useState(!1),z=v.useMemo(()=>{const T=m.flatMap(U=>U.templates);return[...B,...T]},[B,m]),o=v.useMemo(()=>z.find(T=>T.id===O),[z,O]),Q=v.useMemo(()=>o?.files.find(T=>T.id===$)||o?.files[0],[o,$]);v.useEffect(()=>{if(o){const T={};o.variables.forEach(U=>{T[U.name]=U.defaultValue??""}),Y(T),n(o.files[0]?.id||null)}},[o]);const oe=v.useMemo(()=>o?o.files.filter(T=>T.condition?xn(T.condition,D):!0).map(T=>({path:dt(`${T.path}/${T.name}`,D,o.engine),content:dt(T.content,D,o.engine),language:T.language})):[],[o,D]),N=v.useCallback(T=>{J(T.id),i?.(T)},[i,J]),ne=v.useCallback(()=>{w?.(oe,D)},[oe,D,w]),k=v.useCallback(()=>{const T={id:s.createId(),name:"New Template",description:R("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}} = {};`}]};b(U=>[...U,T]),J(T.id),S(!1),a?.(T)},[r,a,b,J,R]),G=v.useCallback((T,U)=>{if(!o)return;const V={...o,files:o.files.map(te=>te.id===T?{...te,content:U}:te)};b(te=>te.map(pe=>pe.id===V.id?V:pe)),f?.(V)},[o,f,b]),X=v.useCallback(()=>{if(!o)return;const T={id:s.createId(),name:"new-file.ts",path:"src",language:"typescript",content:`// New file
|
|
331
|
+
`},U={...o,files:[...o.files,T]};b(V=>V.map(te=>te.id===U.id?U:te)),n(T.id),f?.(U)},[o,f,b]),K=v.useCallback(T=>{if(!o)return;const U={...o,files:o.files.filter(V=>V.id!==T)};b(V=>V.map(te=>te.id===U.id?U:te)),n(U.files[0]?.id||null),f?.(U)},[o,f,b]),W=T=>{const U=D[T.name];switch(T.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(te=>({...te,[T.name]:V.target.checked}))}),e.jsx("span",{children:T.name})]});case"select":return e.jsx("select",{value:String(U),onChange:V=>Y(te=>({...te,[T.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:T.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(te=>({...te,[T.name]:V.target.value.split(",").map(pe=>pe.trim())})),placeholder:R("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(te=>({...te,[T.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(te=>({...te,[T.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 ${A||""}`,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":M,children:[C&&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(s.NiceIcon,{name:"book",size:16})," ",R("codeTemplate.templates","Templates")]}),e.jsx("button",{onClick:k,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:R("codeTemplate.new","+ New")})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[B.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:R("codeTemplate.custom","CUSTOM")}),B.map(T=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,onClick:()=>N(T),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:O===T.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",display:"flex",alignItems:"center",gap:10},children:[e.jsx(s.NiceIcon,{name:T.icon||"file",size:16}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:T.name}),e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)"},children:T.category})]})]},T.id))]}),m.map(T=>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(s.NiceIcon,{name:T.icon,size:12}),T.name.toUpperCase()]}),T.templates.map(U=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,onClick:()=>N(U),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:O===U.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",display:"flex",alignItems:"center",gap:10},children:[e.jsx(s.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))]},T.id))]})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:o?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(s.NiceIcon,{name:o.icon||"file",size:24}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:o.name}),e.jsx("div",{style:{fontSize:12,color:"var(--nice-text-muted, #8b949e)"},children:o.description})]})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsxs("button",{onClick:()=>j?.(o,"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(s.NiceIcon,{name:"upload",size:14})," ",R("codeTemplate.export","Export")]}),e.jsxs("button",{onClick:ne,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(s.NiceIcon,{name:"zap",size:14})," ",R("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(T=>e.jsxs("button",{onClick:()=>F(T),style:{padding:"10px 20px",background:q===T?"var(--nice-bg-canvas, #0d1117)":"transparent",border:"none",borderBottom:q===T?"2px solid var(--nice-primary, #3b82f6)":"2px solid transparent",color:q===T?"var(--nice-text-primary, #fff)":"var(--nice-text-muted, #8b949e)",cursor:"pointer",textTransform:"capitalize"},children:[T==="variables"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"settings",size:14})," "]}),T==="editor"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"edit",size:14})," "]}),T==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," "]}),T]},T))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[q==="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:R("codeTemplate.templateVariables","Template Variables")}),o.variables.map(T=>e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("label",{style:{display:"block",fontSize:12,color:"var(--nice-text-muted, #8b949e)",marginBottom:4},children:[T.name,T.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)"},children:" *"})]}),W(T),T.description&&e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #6b7280)",marginTop:4},children:T.description})]},T.id))]})}),q==="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:R("codeTemplate.files","Files")}),e.jsx("button",{onClick:X,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:o.files.map(T=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s.clickOnActivationKey,onClick:()=>n(T.id),style:{padding:"8px 12px",cursor:"pointer",background:$===T.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",borderLeft:$===T.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:T.name}),e.jsx("button",{"aria-label":R("codeTemplate.removeFile","Remove file"),onClick:U=>{U.stopPropagation(),K(T.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(s.NiceIcon,{name:"close",size:14})})]},T.id))})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:Q&&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:[Q.path,"/",Q.name,Q.condition&&e.jsx("span",{style:{color:"var(--nice-color-warning, #f59e0b)",marginLeft:8},children:R("codeTemplate.if","(if: {condition})").replace("{condition}",String(Q.condition))})]}),e.jsx("textarea",{value:Q.content,onChange:T=>G(Q.id,T.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"}})]})})]}),q==="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:R("codeTemplate.fileSWillBeGenerated","{generatedFiles} file(s) will be generated").replace("{generatedFiles}",String(oe.length))})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:oe.map((T,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(s.NiceIcon,{name:"file",size:14})," ",T.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:T.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(s.NiceIcon,{name:"book",size:64})}),e.jsx("span",{style:{fontSize:18},children:R("codeTemplate.selectATemplate","Select a template")}),e.jsx("span",{style:{fontSize:12,marginTop:4},children:R("codeTemplate.chooseFromTheLibraryOr","Choose from the library or create a new template")}),e.jsxs("button",{onClick:k,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(s.NiceIcon,{name:"plus",size:14})," ",R("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(t){const p=[];let c=0;for(;c<t.length;){const m=t[c];if(/\s/.test(m)){c++;continue}if(/[0-9]/.test(m)||m==="."&&/[0-9]/.test(t[c+1]??"")){let l=c;for(;l<t.length&&/[0-9.]/.test(t[l]);)l++;p.push({t:"num",v:Number(t.slice(c,l))}),c=l;continue}if(m==="'"||m==='"'){let l=c+1,h="";for(;l<t.length&&t[l]!==m;)h+=t[l]==="\\"&&l+1<t.length?t[++l]:t[l],l++;if(l>=t.length)throw new Error("unterminated string");p.push({t:"str",v:h}),c=l+1;continue}if(/[A-Za-z_$]/.test(m)){let l=c;for(;l<t.length&&/[A-Za-z0-9_$.]/.test(t[l]);)l++;p.push({t:"id",v:t.slice(c,l)}),c=l;continue}const u=fn.find(l=>t.startsWith(l,c));if(!u)throw new Error(`unexpected "${m}"`);p.push({t:"op",v:u}),c+=u.length}return p}function Se(t,p){let c=t;for(const m of p.split(".")){if(c==null)return;c=c[m]}return c}const ae=t=>typeof t=="number"?t:Number(t);function _e(t,p){const c=bn(t);let m=0;const u=()=>c[m],l=j=>{const _=c[m];if(!_||j!==void 0&&!(_.t==="op"&&_.v===j))throw new Error(j?`expected "${j}"`:"unexpected end");return m++,_},h=j=>u()?.t==="op"&&u()?.v===j,r=()=>{const j=l();if(j.t==="num")return j.v;if(j.t==="str")return j.v.includes("{{")?j.v.replace(/\{\{\s*([A-Za-z0-9_$.]+)\s*\}\}/g,(_,A)=>{const I=Se(p,A);return I==null?"":String(I)}):j.v;if(j.t==="id")return j.v==="true"?!0:j.v==="false"?!1:j.v==="null"?null:Se(p,j.v);if(j.v==="("){const _=x();return l(")"),_}if(j.v==="-")return-ae(r());if(j.v==="!")return!r();throw new Error(`unexpected "${j.v}"`)},C=()=>{let j=r();for(;h("*")||h("/");){const _=l().v,A=r();j=_==="*"?ae(j)*ae(A):ae(j)/ae(A)}return j},i=()=>{let j=C();for(;h("+")||h("-");){const _=l().v,A=C();j=_==="+"?typeof j=="string"||typeof A=="string"?`${j??""}${A??""}`:ae(j)+ae(A):ae(j)-ae(A)}return j},a=()=>{let j=i();for(;["==","!=",">=","<=",">","<"].some(h);){const _=String(l().v),A=i();j=Ce(j,_,A)}return j},f=()=>{let j=a();for(;h("&&");){l();const _=a();j=!!j&&!!_}return j};function x(){let j=f();for(;h("||");){l();const _=f();j=!!j||!!_}return j}if(c.length===0)return;const w=x();if(m<c.length)throw new Error(`unexpected "${String(c[m].v)}"`);return w}function pt(t,p){return t==null||p===null||p===void 0?t==null&&p==null:typeof t==typeof p?t===p:typeof t=="number"||typeof p=="number"?ae(t)===ae(p):String(t)===String(p)}function Ce(t,p,c){switch(p){case"==":return pt(t,c);case"!=":return!pt(t,c);case">":return ae(t)>ae(c);case">=":return ae(t)>=ae(c);case"<":return ae(t)<ae(c);default:return ae(t)<=ae(c)}}function Ge(t,p,c){return(t??[]).every(m=>{const u=Se(p,m.field);if(m.op==="empty")return u==null||u==="";if(m.op==="notEmpty")return!(u==null||u==="");const l=_e(m.value??"",{...c,...p});switch(m.op){case"eq":return Ce(u,"==",l);case"neq":return Ce(u,"!=",l);case"gt":return Ce(u,">",l);case"gte":return Ce(u,">=",l);case"lt":return Ce(u,"<",l);case"lte":return Ce(u,"<=",l);case"contains":return String(u??"").toLowerCase().includes(String(l??"").toLowerCase())}return!1})}function Nt(t){const p=[],c=new Set,m=(h,r,C)=>{if(!(r===void 0||r.trim()===""))try{_e(r,{})}catch(i){p.push({stepId:h,message:`${C}: ${i.message}`})}},u=(h,r,C)=>{(!r||!r.trim())&&p.push({stepId:h,message:`${C} is required`})},l=h=>{for(const r of h){c.has(r.id)&&p.push({stepId:r.id,message:`duplicate step id ${r.id}`}),c.add(r.id);const C=i=>i?.forEach(a=>{u(r.id,a.field,"condition field"),m(r.id,a.value,"condition value")});switch(r.type){case"read":u(r.id,r.source,"source"),u(r.id,r.into,"variable"),C(r.where);break;case"filter":u(r.id,r.from,"input"),u(r.id,r.into,"variable"),C(r.where);break;case"map":u(r.id,r.from,"input"),u(r.id,r.into,"variable"),r.fields.forEach(i=>{u(r.id,i.target,"target field"),m(r.id,i.expression,`field ${i.target}`)});break;case"aggregate":u(r.id,r.from,"input"),u(r.id,r.into,"variable"),r.measures.forEach(i=>u(r.id,i.name,"measure name"));break;case"set":u(r.id,r.variable,"variable"),m(r.id,r.expression,"value");break;case"if":C(r.when),l(r.then),l(r.else??[]);break;case"forEach":u(r.id,r.from,"input"),u(r.id,r.as,"item variable"),l(r.steps);break;case"write":u(r.id,r.target,"target"),u(r.id,r.from,"input");break;case"callScript":u(r.id,r.script,"script"),Object.entries(r.args??{}).forEach(([i,a])=>m(r.id,a,`argument ${i}`));break;case"return":m(r.id,r.expression,"value");break}}};return l(t.steps),p}const qe=Symbol("returned");async function kt(t,p,c={},m={}){const u={...c},l=[],h=m.maxSteps??1e4;let r;const C=a=>{const f=Se(u,a);return Array.isArray(f)?f:[]},i=async a=>{for(const f of a){if(l.length>=h)throw new Error(`more than ${h} steps — stopped`);switch(l.push(f.id),f.type){case"read":{const x=await p.read(f.source);u[f.into]=x.filter(w=>Ge(f.where,w,u));break}case"filter":u[f.into]=C(f.from).filter(x=>Ge(f.where,x,u));break;case"map":u[f.into]=C(f.from).map(x=>{const w={};for(const j of f.fields)w[j.target]=_e(j.expression,{...u,...x});return w});break;case"aggregate":u[f.into]=yn(C(f.from),f.groupBy??[],f.measures);break;case"set":u[f.variable]=_e(f.expression,u);break;case"if":{const x=Ge(f.when,u,u)?f.then:f.else??[];if(await i(x)===qe)return qe;break}case"forEach":for(const x of C(f.from))if(u[f.as]=x,await i(f.steps)===qe)return qe;break;case"write":await p.write?.(f.target,C(f.from),f.mode??"insert");break;case"callScript":{const x={};for(const[j,_]of Object.entries(f.args??{}))x[j]=_e(_,u);const w=await p.callScript?.(f.script,x);f.into&&(u[f.into]=w);break}case"return":return r=_e(f.expression,u),qe}}};return await i(t.steps),{value:r,variables:u,trace:l}}function yn(t,p,c){const m=new Map;for(const u of t){const l=JSON.stringify(p.map(h=>Se(u,h)));m.set(l,[...m.get(l)??[],u])}return m.size===0&&p.length===0&&m.set("[]",[]),[...m.values()].map(u=>{const l={};p.forEach(h=>{l[h]=Se(u[0]??{},h)});for(const h of c){const r=u.map(C=>ae(Se(C,h.field??""))).filter(C=>!Number.isNaN(C));l[h.name]=h.op==="count"?u.length:h.op==="sum"?r.reduce((C,i)=>C+i,0):h.op==="avg"?r.length?r.reduce((C,i)=>C+i,0)/r.length:0:h.op==="min"?r.length?Math.min(...r):void 0:r.length?Math.max(...r):void 0}return l})}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=t=>`${t}-${Date.now().toString(36)}-${(Sn++).toString(36)}`;function Ct(t){const p=wn(t);switch(t){case"read":return{id:p,type:t,source:"",into:"rows"};case"filter":return{id:p,type:t,from:"rows",where:[],into:"rows"};case"map":return{id:p,type:t,from:"rows",fields:[],into:"rows"};case"aggregate":return{id:p,type:t,from:"rows",groupBy:[],measures:[],into:"totals"};case"set":return{id:p,type:t,variable:"",expression:""};case"if":return{id:p,type:t,when:[],then:[],else:[]};case"forEach":return{id:p,type:t,from:"rows",as:"row",steps:[]};case"write":return{id:p,type:t,target:"",from:"rows",mode:"insert"};case"callScript":return{id:p,type:t,script:"",args:{}};case"return":return{id:p,type:t,expression:""}}}const De=t=>t.type==="if"?["then","else"]:t.type==="forEach"?["steps"]:[];function Qe(t,p,c){const m=[];for(const u of t){if(u.id===p){c&&m.push(c);continue}let l=u;for(const h of De(u)){const r=u[h];r&&(l={...l,[h]:Qe(r,p,c)})}m.push(l)}return m}function _t(t,p,c){if(!c.afterId&&!c.parentId)return[...t,p];const m=[];for(const u of t){let l=u;if(u.id===c.parentId&&c.branch){const h=u[c.branch]??[];l={...l,[c.branch]:[...h,p]}}else for(const h of De(u)){const r=u[h];r&&(l={...l,[h]:_t(r,p,c)})}m.push(l),u.id===c.afterId&&m.push(p)}return m}function zt(t,p,c){const m=t.findIndex(u=>u.id===p);if(m>=0){const u=m+c;if(u<0||u>=t.length)return[...t];const l=[...t];return[l[m],l[u]]=[l[u],l[m]],l}return t.map(u=>{let l=u;for(const h of De(u)){const r=u[h];r&&(l={...l,[h]:zt(r,p,c)})}return l})}function Tt(t,p){for(const c of t){if(c.id===p)return c;for(const m of De(c)){const u=Tt(c[m]??[],p);if(u)return u}}}function Nn(t){switch(t.type){case"read":return`${t.source||"?"} → ${t.into}`;case"filter":return`${t.from} (${t.where.length}) → ${t.into}`;case"map":return`${t.from} → ${t.into} (${t.fields.length})`;case"aggregate":return`${t.from} → ${t.into}`;case"set":return`${t.variable||"?"} = ${t.expression}`;case"if":return`${t.when.map(p=>`${p.field} ${$t[p.op]} ${p.value??""}`).join(", ")}`;case"forEach":return`${t.as} ∈ ${t.from}`;case"write":return`${t.from} → ${t.target||"?"} (${t.mode??"insert"})`;case"callScript":return`${t.script||"?"}${t.into?` → ${t.into}`:""}`;case"return":return t.expression}}const kn=({value:t,defaultValue:p,onChange:c,dataSources:m=[],scripts:u=[],io:l,readOnly:h=!1,className:r,style:C,id:i,"data-testid":a})=>{const{t:f}=s.useNiceTranslation(),[x,w]=s.useControllableState({value:t,defaultValue:p,fallbackValue:{steps:[]},onChange:c,componentName:"NiceNoCodeScriptEditor"}),[j,_]=v.useState(null),[A,I]=v.useState("read"),[M,R]=v.useState(null),P=v.useMemo(()=>Nt(x),[x]),B=new Set(P.map(F=>F.stepId)),b=j?Tt(x.steps,j):void 0,H=F=>f(`noCode.step.${F}`,F),O=x.steps,J=F=>w({...x,steps:F}),D=F=>J(Qe(O,F.id,F)),Y=F=>{const $=Ct(A);J(_t(O,$,F)),_($.id)},q=(F,$)=>e.jsx("ol",{className:"nice-nocode-script__list",style:{paddingLeft:$?16:0},children:F.map(n=>e.jsxs("li",{className:"nice-nocode-script__item",children:[e.jsxs("button",{type:"button",className:`nice-nocode-script__step${j===n.id?" nice-nocode-script__step--selected":""}${B.has(n.id)?" nice-nocode-script__step--issue":""}`,"aria-pressed":j===n.id,onClick:()=>_(n.id),children:[e.jsx(s.NiceIcon,{name:vn[n.type],size:14}),e.jsx("span",{className:"nice-nocode-script__type",children:H(n.type)}),e.jsx("span",{className:"nice-nocode-script__summary",children:Nn(n)}),B.has(n.id)&&e.jsx(s.NiceIcon,{name:"warning",size:12})]}),De(n).map(d=>{const S=n[d]??[];return e.jsxs("div",{className:"nice-nocode-script__branch",children:[e.jsx("span",{className:"nice-nocode-script__branch-label",children:f(`noCode.branch.${d}`,d==="then"?"Then":d==="else"?"Else":"Steps")}),S.length>0&&q(S,$+1)]},d)})]},n.id))});return e.jsxs("div",{id:i,className:`nice-nocode-script${r?` ${r}`:""}`,style:C,"data-testid":a,children:[e.jsxs("div",{className:"nice-nocode-script__steps",children:[!h&&e.jsxs("div",{className:"nice-nocode-script__toolbar",children:[e.jsx(Ve,{"aria-label":f("noCode.addStep","Add step"),value:A,options:wt.map(F=>({value:F,label:H(F)})),onChange:F=>I(String(F)),size:"sm"}),e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>Y({afterId:b?.id}),children:[e.jsx(s.NiceIcon,{name:"plus",size:14})," ",f("noCode.addStep","Add step")]}),b&&De(b).map(F=>e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>Y({parentId:b.id,branch:F}),children:[e.jsx(s.NiceIcon,{name:"plus",size:14})," ",F==="else"?f("noCode.addElse","Add to else"):f("noCode.addInside","Add inside")]},F)),l&&e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:async()=>{try{const F=await kt(x,l);R(JSON.stringify(F.value??F.variables,null,2))}catch(F){R(`${f("noCode.error","Error")}: ${F.message}`)}},children:[e.jsx(s.NiceIcon,{name:"play",size:14})," ",f("noCode.run","Run")]})]}),O.length===0?e.jsx("p",{className:"nice-nocode-script__empty",children:f("noCode.noSteps","No steps yet — add the first one.")}):q(O,0),P.length>0&&e.jsxs("div",{className:"nice-nocode-script__issues",role:"status",children:[e.jsx("strong",{children:f("noCode.issues","Problems")}),e.jsx("ul",{children:P.map((F,$)=>e.jsx("li",{children:F.message},$))})]}),M!==null&&e.jsx("pre",{className:"nice-nocode-script__result","aria-label":f("noCode.result","Result"),children:M})]}),e.jsx("div",{className:"nice-nocode-script__inspector",children:b?e.jsx($n,{step:b,onChange:D,onRemove:()=>{J(Qe(O,b.id,null)),_(null)},onMove:F=>J(zt(O,b.id,F)),dataSources:m,scripts:u,readOnly:h}):e.jsx("p",{className:"nice-nocode-script__empty",children:f("noCode.pickStep","Pick a step to set it up.")})})]})};function $n({step:t,onChange:p,onRemove:c,onMove:m,dataSources:u,scripts:l,readOnly:h}){const{t:r}=s.useNiceTranslation(),C=_=>p({...t,..._}),i=(_,A,I)=>e.jsx(be,{label:_,value:String(t[A]??""),onChange:M=>C({[A]:M}),readOnly:h,size:"sm"}),a=_=>{const A=t[_]??[],I=M=>C({[_]:M});return e.jsxs("fieldset",{className:"nice-nocode-script__rows",children:[e.jsx("legend",{children:r("noCode.field.where","Conditions")}),A.map((M,R)=>e.jsxs("div",{className:"nice-nocode-script__row",children:[e.jsx(be,{label:r("noCode.field.field","Field"),labelPlacement:"inside",value:M.field,onChange:P=>I(A.map((B,b)=>b===R?{...B,field:P}:B)),readOnly:h,size:"sm"}),e.jsx(Ve,{"aria-label":r("noCode.field.op","Operator"),value:M.op,options:jn.map(P=>({value:P,label:P==="contains"||P==="empty"||P==="notEmpty"?r(`noCode.op.${P}`,P):$t[P]})),onChange:P=>I(A.map((B,b)=>b===R?{...B,op:String(P)}:B)),size:"sm"}),M.op!=="empty"&&M.op!=="notEmpty"&&e.jsx(be,{label:r("noCode.field.expression","Value"),labelPlacement:"inside",value:M.value??"",onChange:P=>I(A.map((B,b)=>b===R?{...B,value:P}:B)),readOnly:h,size:"sm"}),!h&&e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.removeRow","Remove"),onClick:()=>I(A.filter((P,B)=>B!==R)),children:e.jsx(s.NiceIcon,{name:"close",size:12})})]},R)),!h&&e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>I([...A,{field:"",op:"eq",value:""}]),children:[e.jsx(s.NiceIcon,{name:"plus",size:12})," ",r("noCode.addRow","Add")]})]})},f=(_,A,I,M)=>e.jsxs("fieldset",{className:"nice-nocode-script__rows",children:[e.jsx("legend",{children:_}),A.map(([R,P],B)=>e.jsxs("div",{className:"nice-nocode-script__row",children:[e.jsx(be,{label:M[0],labelPlacement:"inside",value:R,onChange:b=>I(A.map((H,O)=>O===B?[b,H[1]]:H)),readOnly:h,size:"sm"}),e.jsx(be,{label:M[1],labelPlacement:"inside",value:P,onChange:b=>I(A.map((H,O)=>O===B?[H[0],b]:H)),readOnly:h,size:"sm"}),!h&&e.jsx("button",{type:"button",className:"nice-nocode-script__icon-btn","aria-label":r("noCode.removeRow","Remove"),onClick:()=>I(A.filter((b,H)=>H!==B)),children:e.jsx(s.NiceIcon,{name:"close",size:12})})]},B)),!h&&e.jsxs("button",{type:"button",className:"nice-nocode-script__btn",onClick:()=>I([...A,["",""]]),children:[e.jsx(s.NiceIcon,{name:"plus",size:12})," ",r("noCode.addRow","Add")]})]}),x=r("noCode.field.into","Into variable"),w=r("noCode.field.from","Input variable");let j;switch(t.type){case"read":j=e.jsxs(e.Fragment,{children:[i(r("noCode.field.source","Data source"),"source"),a("where"),i(x,"into")]});break;case"filter":j=e.jsxs(e.Fragment,{children:[i(w,"from"),a("where"),i(x,"into")]});break;case"map":j=e.jsxs(e.Fragment,{children:[i(w,"from"),f(r("noCode.field.fields","Fields"),t.fields.map(_=>[_.target,_.expression]),_=>C({fields:_.map(([A,I])=>({target:A,expression:I}))}),[r("noCode.field.target","Target"),r("noCode.field.expression","Value")]),i(x,"into")]});break;case"aggregate":j=e.jsxs(e.Fragment,{children:[i(w,"from"),e.jsx(be,{label:r("noCode.field.groupBy","Group by"),value:(t.groupBy??[]).join(", "),onChange:_=>C({groupBy:_.split(",").map(A=>A.trim()).filter(Boolean)}),readOnly:h,size:"sm"}),f(r("noCode.field.measures","Measures"),t.measures.map(_=>[_.name,`${_.op}${_.field?`(${_.field})`:""}`]),_=>C({measures:_.map(([A,I])=>{const M=/^(count|sum|avg|min|max)(?:\(([^)]*)\))?$/.exec(I.trim());return{name:A,op:M?.[1]??"count",...M?.[2]?{field:M[2]}:{}}})}),[r("noCode.field.name","Name"),r("noCode.field.measure","Measure: sum(field)")]),i(x,"into")]});break;case"set":j=e.jsxs(e.Fragment,{children:[i(r("noCode.field.variable","Variable"),"variable"),i(r("noCode.field.expression","Value"),"expression")]});break;case"if":j=a("when");break;case"forEach":j=e.jsxs(e.Fragment,{children:[i(w,"from"),i(r("noCode.field.as","Item variable"),"as")]});break;case"write":j=e.jsxs(e.Fragment,{children:[i(r("noCode.field.target","Target"),"target"),i(w,"from"),e.jsx(Ve,{label:r("noCode.field.mode","Mode"),value:t.mode??"insert",options:["insert","update","upsert","delete"],onChange:_=>C({mode:String(_)}),size:"sm"})]});break;case"callScript":j=e.jsxs(e.Fragment,{children:[i(r("noCode.field.script","Script"),"script"),f(r("noCode.field.args","Arguments"),Object.entries(t.args??{}),_=>C({args:Object.fromEntries(_)}),[r("noCode.field.name","Name"),r("noCode.field.expression","Value")]),i(x,"into")]});break;case"return":j=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.${t.type}`,t.type)}),!h&&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:()=>m(-1),children:e.jsx(s.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:()=>m(1),children:e.jsx(s.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:c,children:e.jsx(s.NiceIcon,{name:"trash",size:14})})]})]}),j]})}exports.NICE_NO_CODE_STEP_TYPES=wt;exports.NiceAPIFlow=bt;exports.NiceAPIFlow$1=Qt;exports.NiceCheckbox=et;exports.NiceCheckbox$1=Dt;exports.NiceCodePreview=mt;exports.NiceCodeTemplate=St;exports.NiceCodeTemplate$1=hn;exports.NiceComponentDesigner=Vt;exports.NiceDataMapper=yt;exports.NiceDataMapper$1=tn;exports.NiceEventOrchestrator=vt;exports.NiceEventOrchestrator$1=an;exports.NiceLowCodeStudio=Lt;exports.NiceNoCodeScriptEditor=kn;exports.NiceNumberInput=Xe;exports.NiceNumberInput$1=Rt;exports.NicePageBuilder=Ut;exports.NiceSelect=Ve;exports.NiceSelect$1=Et;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;
|