@nice2dev/ui 1.1.10 → 1.2.1
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 +183 -0
- package/README.md +12 -20
- package/dist/NiceApiExplorer.doc-CFJndg5h.js +25 -0
- package/dist/NiceApiExplorer.doc-TEx67kV5.cjs +1 -0
- package/dist/NiceBPMNDesigner.doc-6lK1pXRq.js +32 -0
- package/dist/NiceBPMNDesigner.doc-BY8t7qOi.cjs +8 -0
- package/dist/NiceBackupDiffViewer.doc-CYvOeX19.js +25 -0
- package/dist/NiceBackupDiffViewer.doc-ChQaZCg1.cjs +1 -0
- package/dist/NiceBackupList.doc-BdQCw0_D.cjs +1 -0
- package/dist/NiceBackupList.doc-BwjIAoqz.js +25 -0
- package/dist/NiceBackupRestoreDialog.doc-B2iiqTps.cjs +1 -0
- package/dist/NiceBackupRestoreDialog.doc-DuXSGJiD.js +25 -0
- package/dist/NiceBackupScheduler.doc-BpY45181.js +31 -0
- package/dist/NiceBackupScheduler.doc-ByeL3iH1.cjs +7 -0
- package/dist/NiceBackupStatusBadge.doc-BA3dYgiW.cjs +1 -0
- package/dist/NiceBackupStatusBadge.doc-CxwkVarP.js +25 -0
- package/dist/NiceBackupTagEditor.doc-Bej1KHco.cjs +7 -0
- package/dist/NiceBackupTagEditor.doc-CNy4uNws.js +31 -0
- package/dist/NiceBottomSheet.doc-keq-Fzlz.cjs +8 -0
- package/dist/NiceBottomSheet.doc-v-UPUKQk.js +32 -0
- package/dist/NiceBranchManager.doc-BTyRjX7X.cjs +6 -0
- package/dist/NiceBranchManager.doc-Cz4SyEqE.js +30 -0
- package/dist/NiceButton-3AcJJ15c.cjs +1 -0
- package/dist/NiceButton-5tWvfXKl.cjs +1 -0
- package/dist/NiceButton-DHSgQT1_.js +112 -0
- package/dist/NiceButton-vkI07DP0.js +88 -0
- package/dist/NiceCodeEditor-B8At55f5.js +1179 -0
- package/dist/NiceCodeEditor-BJSEzhcY.cjs +260 -0
- package/dist/NiceCodeEditor-VGIDWSkS.js +1181 -0
- package/dist/NiceCodeEditor-qX39PSnQ.cjs +260 -0
- package/dist/NiceColorPicker-CQhhjZ8w.cjs +1 -0
- package/dist/NiceColorPicker-Cbop7VMu.js +491 -0
- package/dist/NiceColorPicker-DCgmE-3H.cjs +1 -0
- package/dist/NiceColorPicker-DK30kJgy.js +486 -0
- package/dist/NiceColorPicker-DtPFxDKM.cjs +1 -0
- package/dist/NiceColorPicker-bNJBAU_c.js +598 -0
- package/dist/NiceConnectorConfigForm.doc-BKrDuhXw.cjs +7 -0
- package/dist/NiceConnectorConfigForm.doc-BsHeXz3M.js +31 -0
- package/dist/NiceDataBranchGraph.doc-Axidz41W.js +29 -0
- package/dist/NiceDataBranchGraph.doc-sjLmrrtE.cjs +5 -0
- package/dist/NiceDataBranchManager.doc-B1-Rp2X4.cjs +6 -0
- package/dist/NiceDataBranchManager.doc-GUqfTFvW.js +30 -0
- package/dist/NiceDataConflictResolver.doc-CjQryrTu.cjs +5 -0
- package/dist/NiceDataConflictResolver.doc-L-TcnQMX.js +29 -0
- package/dist/NiceDataDiffViewer.doc-BzGrf0U-.cjs +6 -0
- package/dist/NiceDataDiffViewer.doc-goxhSldH.js +30 -0
- package/dist/NiceDataGrid-BDEIbuBS.js +2218 -0
- package/dist/NiceDataGrid-BOCJr6XF.js +2217 -0
- package/dist/NiceDataGrid-BV5Oh-gy.cjs +10 -0
- package/dist/NiceDataGrid-CS5aB-EN.cjs +10 -0
- package/dist/NiceDataGrid-Dd7SI-M6.cjs +10 -0
- package/dist/NiceDataGrid-DjZchXYG.js +2217 -0
- package/dist/NiceDataMapper.doc-QmnmnvVq.js +30 -0
- package/dist/NiceDataMapper.doc-ytGVtYVr.cjs +6 -0
- package/dist/NiceDataMergeBuilder.doc-BcmzKxh2.cjs +6 -0
- package/dist/NiceDataMergeBuilder.doc-BvYa4aUJ.js +30 -0
- package/dist/NiceDataSnapshot.doc-C73K1biG.cjs +6 -0
- package/dist/NiceDataSnapshot.doc-hU7wnOzM.js +30 -0
- package/dist/NiceDesktopViews.doc-DJjYlyP2.cjs +1 -0
- package/dist/NiceDesktopViews.doc-ly-VUAJj.js +25 -0
- package/dist/NiceDeviceControlCard.doc-BZIo92-w.cjs +1 -0
- package/dist/NiceDeviceControlCard.doc-DIzZcW9L.js +25 -0
- package/dist/NiceDocumentViewer-B9VIVKyw.js +726 -0
- package/dist/NiceDocumentViewer-CDXAmPp7.cjs +180 -0
- package/dist/NiceDocumentationViewer.doc-BSNGa7a_.js +25 -0
- package/dist/NiceDocumentationViewer.doc-CrwlvPFg.cjs +1 -0
- package/dist/NiceEnergyChart.doc-DW-jllDV.cjs +1 -0
- package/dist/NiceEnergyChart.doc-DnEehTff.js +25 -0
- package/dist/NiceFeatureGate.doc-DN17uS_B.cjs +3 -0
- package/dist/NiceFeatureGate.doc-DNfFSRrh.js +27 -0
- package/dist/NiceForm-BCEXovJR.cjs +1 -0
- package/dist/NiceForm-BcN4p2kG.cjs +1 -0
- package/dist/NiceForm-D7oyWHXg.js +4820 -0
- package/dist/NiceForm-DUhxXArr.js +4817 -0
- package/dist/NiceForm-tIXS-M6b.js +4770 -0
- package/dist/NiceForm-uCeVmTrD.cjs +1 -0
- package/dist/NiceFormItem.doc-BJwEnDz2.js +36 -0
- package/dist/NiceFormItem.doc-Ck3PgaPD.cjs +12 -0
- package/dist/NiceGantt-CTbqCuwv.cjs +1 -0
- package/dist/NiceGantt-Dao7pN9z.js +328 -0
- package/dist/NiceGantt.doc-B6YZcJvG.cjs +11 -0
- package/dist/NiceGantt.doc-DsI1QXly.js +48 -0
- package/dist/NiceGitBlame.doc-BQ2KvGkD.js +30 -0
- package/dist/NiceGitBlame.doc-DuTSjZVN.cjs +6 -0
- package/dist/NiceGitDiffViewer.doc-D24AGos_.js +30 -0
- package/dist/NiceGitDiffViewer.doc-D9FVquBC.cjs +6 -0
- package/dist/NiceGitGraph.doc-C-8VGMIz.js +29 -0
- package/dist/NiceGitGraph.doc-eRvTmefl.cjs +5 -0
- package/dist/NiceGitHooks.doc-DCTVw7HX.cjs +5 -0
- package/dist/NiceGitHooks.doc-OCFj5w6v.js +29 -0
- package/dist/NiceHtmlEditor-BYk1roA4.cjs +10 -0
- package/dist/NiceHtmlEditor-C5kLeF9H.cjs +10 -0
- package/dist/NiceHtmlEditor-CFVMIC5L.js +848 -0
- package/dist/NiceHtmlEditor-DUwcqj5N.cjs +10 -0
- package/dist/NiceHtmlEditor-DiAphF1k.js +889 -0
- package/dist/NiceHtmlEditor-mWebBmy1.js +849 -0
- package/dist/NiceInstanceMonitor.doc-BSDZp5xa.js +31 -0
- package/dist/NiceInstanceMonitor.doc-HVbLufnh.cjs +7 -0
- package/dist/NiceLocaleManager.doc-CbVHDEWu.js +25 -0
- package/dist/NiceLocaleManager.doc-XH6hMW0Z.cjs +1 -0
- package/dist/NiceLockButton.doc-BMhSj3TB.cjs +1 -0
- package/dist/NiceLockButton.doc-DvHGhcfm.js +25 -0
- package/dist/NiceLoginForm-BHyDY7br.cjs +1 -0
- package/dist/NiceLoginForm-BuxFY2Rk.js +750 -0
- package/dist/NiceLoginForm-DQe77Isv.js +747 -0
- package/dist/NiceLoginForm-NBCo-DUZ.cjs +1 -0
- package/dist/NiceLoginForm.css +1 -0
- package/dist/NiceMAM.doc-CsQ57saR.cjs +8 -0
- package/dist/NiceMAM.doc-hjW7buTH.js +32 -0
- package/dist/NiceMention--3P3vO-W.cjs +430 -0
- package/dist/NiceMention-CA7CL5BI.js +11263 -0
- package/dist/NiceMention-CHcKRl-L.cjs +430 -0
- package/dist/NiceMention-Co2cqkVM.js +11316 -0
- package/dist/NiceMention-DJD0BLcp.js +11269 -0
- package/dist/NiceMention-DcaUEMSg.cjs +430 -0
- package/dist/NiceMention.css +1 -1
- package/dist/NiceModal-C4p8a82e.cjs +1 -0
- package/dist/NiceModal-TNlkaL_i.js +85 -0
- package/dist/NiceModuleLifecyclePanel-BWbKdVC_.js +7054 -0
- package/dist/NiceModuleLifecyclePanel-CZHIzvkE.cjs +1 -0
- package/dist/NiceModuleLifecyclePanel-DV3F_QdI.cjs +1 -0
- package/dist/NiceModuleLifecyclePanel-OC9YK2kG.js +7052 -0
- package/dist/NiceModuleLifecyclePanel-_OcfDmtC.cjs +1 -0
- package/dist/NiceModuleLifecyclePanel-gaZkIEtK.js +6825 -0
- package/dist/NiceModuleLifecyclePanel.css +1 -1
- package/dist/NiceNetworkDiscoveryPanel.doc-B0RtGaS3.js +25 -0
- package/dist/NiceNetworkDiscoveryPanel.doc-BFgFZI5G.cjs +1 -0
- package/dist/NicePagination-8XsBbMNx.js +165 -0
- package/dist/NicePagination-B3nZDZem.js +165 -0
- package/dist/NicePagination-B8rg1Y67.cjs +1 -0
- package/dist/NicePagination-CkOoXf0f.js +165 -0
- package/dist/NicePagination-D7lek1G7.cjs +1 -0
- package/dist/NicePagination-OjTEfZJE.cjs +1 -0
- package/dist/NicePipelineEditor.doc-CjqDKe2x.js +29 -0
- package/dist/NicePipelineEditor.doc-DZ0pTVTp.cjs +5 -0
- package/dist/NicePipelineMonitor.doc-C88-TagI.cjs +5 -0
- package/dist/NicePipelineMonitor.doc-CFtH4XJx.js +29 -0
- package/dist/NicePivotGrid-BJRSciWl.js +1183 -0
- package/dist/NicePivotGrid-BaZa2YZW.js +1157 -0
- package/dist/NicePivotGrid-CS1dPmNI.cjs +152 -0
- package/dist/NicePivotGrid-D2AxqDzJ.js +1183 -0
- package/dist/NicePivotGrid-DxQ6Py9D.cjs +152 -0
- package/dist/NicePivotGrid-DyOPhPO8.cjs +152 -0
- package/dist/NiceRoomGrid.doc-DJPVUQVg.cjs +8 -0
- package/dist/NiceRoomGrid.doc-DLHJS_Wb.js +32 -0
- package/dist/NiceSavedQueryPanel-B5HhqlAI.cjs +586 -0
- package/dist/NiceSavedQueryPanel-BC84uRfh.cjs +586 -0
- package/dist/NiceSavedQueryPanel-CMStDOKe.js +5125 -0
- package/dist/NiceSavedQueryPanel-CMfcODIO.js +5120 -0
- package/dist/NiceSavedQueryPanel-D2i34e_b.cjs +586 -0
- package/dist/NiceSavedQueryPanel-mPO2THs7.js +5142 -0
- package/dist/NiceSavedQueryPanel.css +1 -1
- package/dist/NiceSceneBar.doc-09sc3yuF.cjs +1 -0
- package/dist/NiceSceneBar.doc-DLePMuVU.js +25 -0
- package/dist/NiceSceneSelector.doc-CPzCAy-d.cjs +7 -0
- package/dist/NiceSceneSelector.doc-FCLZvPc0.js +31 -0
- package/dist/NiceScheduler-7gP7vcLy.cjs +5 -0
- package/dist/NiceScheduler-BAJRzFQN.js +1690 -0
- package/dist/NiceScheduler-Cy7F9tgH.js +1693 -0
- package/dist/NiceScheduler-DquRUZxD.cjs +5 -0
- package/dist/NiceScheduler-dJ7gHDv7.cjs +5 -0
- package/dist/NiceScheduler-l8N4yCWd.js +1716 -0
- package/dist/NiceSchedulerViews.doc-C9opZpgg.cjs +1 -0
- package/dist/NiceSchedulerViews.doc-Dy7ZH1iL.js +25 -0
- package/dist/NiceSelect-CZR8Zu_k.js +420 -0
- package/dist/NiceSelect-DIKGbaJo.cjs +1 -0
- package/dist/NiceSelect-DZB1Rs9x.js +435 -0
- package/dist/NiceSelect-tMz9QQUs.cjs +1 -0
- package/dist/NiceSensorGaugePanel.doc-BHirbWLn.cjs +8 -0
- package/dist/NiceSensorGaugePanel.doc-DjKmooI6.js +32 -0
- package/dist/NiceSpotlight.doc-BVZFfDVI.cjs +10 -0
- package/dist/NiceSpotlight.doc-JqwkzrEm.js +34 -0
- package/dist/NiceStateDesigner.doc-CfnwiwfU.js +29 -0
- package/dist/NiceStateDesigner.doc-DV4zEC50.cjs +5 -0
- package/dist/NiceStepper.doc-5VjaLM6r.js +31 -0
- package/dist/NiceStepper.doc-f8lYpr33.cjs +7 -0
- package/dist/NiceStreamDashboard.doc-74KUXya1.cjs +8 -0
- package/dist/NiceStreamDashboard.doc-k8PQfCM0.js +32 -0
- package/dist/NiceTaskInbox.doc-CHrxthqp.js +32 -0
- package/dist/NiceTaskInbox.doc-CdCTfgBq.cjs +8 -0
- package/dist/NiceTestBuilder.doc-BoBzLfa0.js +30 -0
- package/dist/NiceTestBuilder.doc-Cj1fNTvk.cjs +6 -0
- package/dist/NiceTranscoder.doc-Dnirl3wg.cjs +7 -0
- package/dist/NiceTranscoder.doc-cInCYZh7.js +31 -0
- package/dist/NiceVideoAnnotator.doc-C1iEi7OM.cjs +7 -0
- package/dist/NiceVideoAnnotator.doc-C8zyfKH_.js +31 -0
- package/dist/NiceVideoEditor.doc-C6mhEb-q.cjs +7 -0
- package/dist/NiceVideoEditor.doc-lrwmKjqj.js +31 -0
- package/dist/NiceWindow-BEov3s9F.js +2094 -0
- package/dist/NiceWindow-CDt6PCEg.cjs +1 -0
- package/dist/NiceWindow-CWN8OCHF.js +2109 -0
- package/dist/NiceWindow-Dd8qjkIW.cjs +1 -0
- package/dist/NiceWindow.css +1 -1
- package/dist/charts-Bo2WAI5T.cjs +768 -0
- package/dist/charts-ByrdMeQP.js +4767 -0
- package/dist/charts-C047IMVn.cjs +768 -0
- package/dist/charts-CCXSb3xk.js +4752 -0
- package/dist/charts-CqETcUhH.js +4752 -0
- package/dist/charts-DouiiHOT.cjs +768 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.css +1 -1
- package/dist/charts.d.ts +28 -18
- package/dist/charts.mjs +1 -1
- package/dist/core-B8eBUE4m.js +438 -0
- package/dist/core-BL-KmGYC.js +795 -0
- package/dist/core-Chg-oYCr.cjs +1 -0
- package/dist/core-CxBnKAhs.cjs +1 -0
- package/dist/core-D_LRh59n.js +795 -0
- package/dist/core-lBFqvT0V.cjs +1 -0
- package/dist/core-lazy-Bh2yg4Et.js +351 -0
- package/dist/core-lazy-CkWKjfc6.cjs +1 -0
- package/dist/data-branching-Dak1_ZKR.cjs +1 -0
- package/dist/data-branching-DiLAO4Qt.js +6386 -0
- package/dist/data-branching-Km4lc8P_.cjs +1 -0
- package/dist/data-branching-YQtJJEtn.js +6273 -0
- package/dist/data-branching.cjs +1 -1
- package/dist/data-branching.mjs +1 -1
- package/dist/data.cjs +1 -1
- package/dist/data.d.ts +22 -69
- package/dist/data.mjs +3 -3
- package/dist/devops-D5yIDM3e.js +8312 -0
- package/dist/devops-DkVluHBp.cjs +17 -0
- package/dist/devops-rVpB0ZAX.cjs +17 -0
- package/dist/devops-zsMUueTd.js +8648 -0
- package/dist/devops.cjs +1 -1
- package/dist/devops.d.ts +3 -3
- package/dist/devops.mjs +1 -1
- package/dist/editors.cjs +1 -1
- package/dist/editors.d.ts +106 -63
- package/dist/editors.mjs +55 -54
- package/dist/feedback.cjs +1 -1
- package/dist/feedback.d.ts +76 -2
- package/dist/feedback.mjs +10 -9
- package/dist/index.cjs +261 -261
- package/dist/index.css +1 -1
- package/dist/index.d.ts +831 -433
- package/dist/index.mjs +27339 -26540
- package/dist/injectStyleOnce-BzC_BCs_.js +9 -0
- package/dist/injectStyleOnce-DeWaxcdf.cjs +1 -0
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.d.ts +9 -7
- package/dist/lazy.mjs +55 -55
- package/dist/navigation.cjs +1 -1
- package/dist/navigation.css +1 -0
- package/dist/navigation.d.ts +99 -43
- package/dist/navigation.mjs +504 -547
- package/dist/no-code-6WyYb3hL.cjs +331 -0
- package/dist/no-code-BH5oVFC6.js +8186 -0
- package/dist/no-code-CnHG5_Vn.js +8186 -0
- package/dist/no-code-DMKlg1Zl.cjs +331 -0
- package/dist/no-code-DiTEnuRv.js +8288 -0
- package/dist/no-code-wG9c0z_T.cjs +331 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.css +1 -1
- package/dist/no-code.d.ts +25 -18
- package/dist/no-code.mjs +3 -3
- package/dist/overlays.cjs +1 -1
- package/dist/overlays.d.ts +36 -30
- package/dist/overlays.mjs +24 -490
- package/dist/pickerCommons-0vyK1Knv.js +547 -0
- package/dist/pickerCommons-BCRiHDE_.cjs +1 -0
- package/dist/pickerCommons-BFbItm8o.cjs +1 -0
- package/dist/pickerCommons-BHirHJyn.js +548 -0
- package/dist/pickerCommons-Bt8JIaTN.cjs +1 -0
- package/dist/pickerCommons-DkumQ3KE.js +548 -0
- package/dist/pickerCommons.css +1 -1
- package/dist/style.css +15 -9
- package/package.json +4 -6
- package/css/legacy-bg-text-aliases.css +0 -87
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),s=require("@nice2dev/ui-core"),g=require("react"),ae=require("./devops-Bt6EsfPa.cjs"),ye=g.forwardRef(({label:r,checked:S=!1,indeterminate:y=!1,onChange:v,disabled:$,readOnly:b,loading:w,required:u,size:C="md",name:i,id:m,className:k,style:E,error:j,helperText:M,accessMode:q,displayStyle:_,showKeyboardHints:B,labelPlacement:O,errorPlacement:F,labelWidth:U,controlWidth:l},z)=>{const A=s.useNiceAccessMode(q,m),H=A==="hidden";(A==="disabled"||A==="readOnly")&&($=!0);const{t:I}=s.useNiceTranslation(),G=s.useControlId(m);s.useComponentDisplayClass("toggle",_);const R=g.useMemo(()=>[{key:"Space",description:I("shortcuts.toggle","Toggle")}],[I]),Y=g.useCallback(c=>{c&&(c.indeterminate=y),typeof z=="function"?z(c):z&&(z.current=c)},[y,z]);return H?null:e.jsxs("div",{className:`nice-field nice-field--inline nice-field--${C} ${O==="left"?"nice-field--label-left":""} ${F==="right"?"nice-field--error-right":""} ${w?"nice-field--loading":""} ${k||""}`,style:{...E,...U!=null&&{"--nice-field-label-width":typeof U=="number"?`${U}px`:U},...l!=null&&{"--nice-field-control-width":typeof l=="number"?`${l}px`:l}},"aria-busy":w||void 0,children:[O==="left"&&r&&e.jsx("span",{className:`nice-field__label ${u?"nice-field__label--required":""}`,children:r}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("label",{className:`nice-checkbox ${C!=="md"?`nice-checkbox--${C}`:""} ${$||w?"nice-checkbox--disabled":""}`,htmlFor:G,children:[e.jsx("input",{ref:Y,id:G,type:"checkbox",className:"nice-checkbox__input",name:i,checked:S,disabled:$||w,readOnly:b,"aria-invalid":!!j,onChange:c=>{b||w||v?.(c.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:S?e.jsx("polyline",{points:"2 6 5 9 10 3"}):e.jsx("line",{x1:"2",y1:"6",x2:"10",y2:"6"})})}),O!=="left"&&r&&e.jsx("span",{children:r}),B&&e.jsx(s.NiceKeyboardHint,{shortcuts:R,size:"sm"})]}),w&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),F==="right"&&j&&e.jsx("div",{id:`${G}-error`,className:"nice-field__error",role:"alert",children:j}),F==="right"&&!j&&M&&e.jsx("div",{id:`${G}-helper`,className:"nice-field__helper",children:M})]}),F!=="right"&&j&&e.jsx("div",{id:`${G}-error`,className:"nice-field__error",role:"alert",children:j}),F!=="right"&&!j&&M&&e.jsx("div",{id:`${G}-helper`,className:"nice-field__helper",children:M})]})});ye.displayName="NiceCheckbox";const it=Object.freeze(Object.defineProperty({__proto__:null,NiceCheckbox:ye},Symbol.toStringTag,{value:"Module"})),be=g.forwardRef(({label:r,helperText:S,error:y,required:v,disabled:$,readOnly:b,size:w="md",name:u,id:C,className:i,style:m,accessMode:k,displayStyle:E,value:j,onChange:M,onBlur:q,onKeyDown:_,placeholder:B,min:O,max:F,step:U=1,precision:l,prefix:z,prefixType:A="label",prefixOptions:H,prefixValue:I,onPrefixChange:G,suffix:R,showStepper:Y=!0,submitOnEnter:c,onSubmit:n,showKeyboardHints:t,labelPlacement:d,errorPlacement:h,loading:o,labelWidth:N,controlWidth:a,formatPreset:Q,format:ee,suffixType:x="label",suffixOptions:W,suffixValue:p,onSuffixChange:K,suffixSeparator:Z=!1,displayMode:X},D)=>{const f=s.useNiceAccessMode(k,C),P=f==="hidden";f==="disabled"&&($=!0),f==="readOnly"&&(b=!0);const{t:L}=s.useNiceTranslation(),V=s.useControlId(C),oe=s.useComponentDisplayStyle("input",E),Ye=s.useComponentDisplayClass("input",E),[le,Ne]=g.useState(!1),[je,Se]=g.useState(null),ue=s.useDisplayModeEdit({enabled:X,readOnly:b,disabled:$}),Ze=g.useMemo(()=>{let T=3;return F!=null&&(T=String(Math.abs(Math.floor(F))).length),O!=null&&O<0&&(T+=1),l&&(T+=l+1),Math.max(3,T)+1},[F,O,l]),$e=g.useCallback(T=>{if(ee)return ee(T);if(!Q)return l!=null?T.toFixed(l):String(T);switch(Q){case"integer":return Math.round(T).toLocaleString();case"decimal":return T.toLocaleString(void 0,{minimumFractionDigits:l??2,maximumFractionDigits:l??2});case"money":return T.toLocaleString(void 0,{minimumFractionDigits:l??2,maximumFractionDigits:l??2,useGrouping:!0});case"percent":return(T*100).toLocaleString(void 0,{minimumFractionDigits:l??0,maximumFractionDigits:l??2})+"%";default:return String(T)}},[ee,Q,l]),me=g.useMemo(()=>le&&je!==null?je:j==null?"":le?l!=null?j.toFixed(l):String(j):$e(j),[j,le,je,$e,l]),Qe=j!=null&&j<0,Xe=!!(z||A==="select"&&H&&H.length>0),ke=Qe&&Xe&&!le,et=ke?me.replace(/^[-−]/,""):me,xe=g.useCallback(T=>{let J=T;return O!==void 0&&(J=Math.max(O,J)),F!==void 0&&(J=Math.min(F,J)),l!==void 0&&(J=parseFloat(J.toFixed(l))),J},[O,F,l]),tt=g.useCallback(T=>{const J=T.target.value;if(Se(J),J===""||J==="-"||J==="."||J==="-."){J===""&&M?.(null);return}const te=parseFloat(J);if(!isNaN(te)){let ne=te;O!==void 0&&(ne=Math.max(O,ne)),F!==void 0&&(ne=Math.min(F,ne)),M?.(ne)}},[M,O,F]),ge=g.useCallback(()=>{const T=de.current,J=xe((T??0)+U);de.current=J,M?.(J)},[U,M,xe]),he=g.useCallback(()=>{const T=de.current,J=xe((T??0)-U);de.current=J,M?.(J)},[U,M,xe]),de=g.useRef(j);de.current=j;const ce=g.useRef(null),se=g.useCallback(()=>{ce.current&&(clearTimeout(ce.current),ce.current=null)},[]),Ce=g.useCallback(T=>{se();let J=300;const te=()=>{T(),J=Math.max(30,J*.82),ce.current=setTimeout(te,J)};ce.current=setTimeout(te,400)},[se]),ze=s.useSubmitOnEnter({enabled:c,onSubmit:n}),nt=g.useCallback(T=>{ze(T),T.key==="ArrowUp"?(T.preventDefault(),ge()):T.key==="ArrowDown"&&(T.preventDefault(),he()),_?.(T)},[ze,_,ge,he]),Te=g.useMemo(()=>{const T=[];return c&&T.push(s.COMMON_SHORTCUTS.submit),Y&&(T.push({key:"ArrowUp",description:L("shortcuts.increment","Increase value")}),T.push({key:"ArrowDown",description:L("shortcuts.decrement","Decrease value")})),T},[c,Y,L]);return P?null:e.jsxs("div",{className:`nice-field nice-field--${w} ${d==="left"?"nice-field--label-left":""} ${o?"nice-field--loading":""} ${i||""}`,style:{...m,...N!=null&&{"--nice-field-label-width":typeof N=="number"?`${N}px`:N},...a!=null&&{"--nice-field-control-width":typeof a=="number"?`${a}px`:a}},"aria-busy":o||void 0,children:[r&&e.jsxs("label",{htmlFor:V,className:`nice-field__label ${v?"nice-field__label--required":""}`,children:[r,t&&Te.length>0&&e.jsx(s.NiceKeyboardHint,{shortcuts:Te,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[ue.isDisplay?e.jsx(s.DisplayModeView,{value:j==null?"":z?e.jsxs(e.Fragment,{children:[z,me]}):me,placeholder:B,disabled:$,readOnly:b,onActivate:ue.enterEdit,ariaLabel:r}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:`nice-input nice-input--number nice-input--${w} nice-input--ds-${Ye} ${Z?"nice-input--suffix-sep":""} ${y?"nice-input--error":""} ${$?"nice-input--disabled":""} ${b?"nice-input--readonly":""}`,style:oe,children:[Y&&!b&&e.jsx("button",{type:"button",className:"nice-input__clear nice-input__minus",onClick:he,onMouseDown:()=>Ce(he),onMouseUp:se,onMouseLeave:se,disabled:$,"aria-label":L("controls.decrement","Decrement"),children:e.jsx(s.NiceIcon,{name:"minus",size:16})}),A==="select"&&H&&H.length>0?e.jsxs(e.Fragment,{children:[ke&&e.jsx("span",{className:"nice-input__sign",children:"−"}),e.jsx("select",{className:"nice-input__suffix-select nice-input__icon--prefix",value:I??H[0]?.value,disabled:$,onChange:T=>{const J=T.target.value,te=H.find(re=>re.value===(I??H[0]?.value)),ne=H.find(re=>re.value===J);G?.(J,te?.weight,ne?.weight)},children:H.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]}):z?e.jsxs("span",{className:"nice-input__icon nice-input__icon--prefix",children:[ke&&e.jsx("span",{className:"nice-input__sign",children:"−"}),z]}):null,e.jsx("input",{ref:T=>{typeof D=="function"?D(T):D&&(D.current=T),ue.autoFocusRef(T)},id:V,className:"nice-input__native",type:!le&&(ee||Q)?"text":"number",name:u,value:et,placeholder:B,min:O,max:F,step:U,disabled:$||o,readOnly:b,"aria-invalid":!!y,onChange:tt,onFocus:T=>{Ne(!0),Se(null),T.target.select()},onBlur:T=>{if(Ne(!1),Se(null),j!=null&&l!==void 0){const J=parseFloat(j.toFixed(l));J!==j&&M?.(J)}X&&ue.exitEdit(),q?.(T)},onKeyDown:nt,style:{width:`${Ze}ch`}}),x==="select"&&W&&W.length>0?e.jsx("select",{className:"nice-input__suffix-select nice-input__icon--suffix",value:p??W[0]?.value,disabled:$,onChange:T=>{const J=T.target.value,te=W.find(re=>re.value===(p??W[0]?.value)),ne=W.find(re=>re.value===J);K?.(J,te?.weight,ne?.weight)},children:W.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))}):R?e.jsx("span",{className:"nice-input__icon nice-input__icon--suffix",children:R}):null,Y&&!b&&e.jsx("button",{type:"button",className:"nice-input__clear nice-input__plus",onClick:ge,onMouseDown:()=>Ce(ge),onMouseUp:se,onMouseLeave:se,disabled:$,"aria-label":L("controls.increment","Increment"),children:e.jsx(s.NiceIcon,{name:"plus",size:16})})]})}),o&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),h==="right"&&y&&e.jsx("div",{className:"nice-field__error",role:"alert",children:y}),h==="right"&&!y&&S&&e.jsx("div",{className:"nice-field__helper",children:S})]}),h!=="right"&&y&&e.jsx("div",{className:"nice-field__error",role:"alert",children:y}),h!=="right"&&!y&&S&&e.jsx("div",{className:"nice-field__helper",children:S})]})});be.displayName="NiceNumberInput";const rt=Object.freeze(Object.defineProperty({__proto__:null,NiceNumberInput:be},Symbol.toStringTag,{value:"Module"})),ve=g.forwardRef(({label:r,helperText:S,error:y,required:v,disabled:$,readOnly:b,size:w="md",name:u,id:C,className:i,style:m,accessMode:k,displayStyle:E,variant:j,value:M,defaultValue:q,onChange:_,onBlur:B,onKeyDown:O,placeholder:F,type:U="text",maxLength:l,prefix:z,suffix:A,clearable:H,autoFocus:I,submitOnEnter:G,onSubmit:R,showKeyboardHints:Y,labelPlacement:c,errorPlacement:n,loading:t,labelWidth:d,controlWidth:h,displayMode:o,...N},a)=>{const Q=s.useNiceAccessMode(k,C),ee=Q==="hidden";Q==="disabled"&&($=!0),Q==="readOnly"&&(b=!0);const{t:x}=s.useNiceTranslation(),W=s.useControlId(C),p=s.useComponentDisplayStyle("input",E),K=s.useComponentDisplayClass("input",E),Z=j==="filled"?"filled":j==="underlined"?"underlined":"",X=g.useCallback(()=>_?.(""),[_]),D=s.useDisplayModeEdit({enabled:o,readOnly:b,disabled:$}),f=s.useSubmitOnEnter({enabled:G,onSubmit:R}),P=g.useCallback(V=>{f(V),O?.(V)},[f,O]),L=g.useMemo(()=>{const V=[];return G&&V.push({key:"Enter",description:x("shortcuts.submit","Submit")}),H&&V.push({key:"Escape",description:x("shortcuts.clear","Clear")}),V},[G,H,x]);return ee?null:e.jsxs("div",{className:`nice-field nice-field--${w} ${c==="left"?"nice-field--label-left":""} ${c==="inside"?"nice-field--label-inside":""} ${t?"nice-field--loading":""} ${i||""}`,style:{...m,...d!=null&&{"--nice-field-label-width":typeof d=="number"?`${d}px`:d},...h!=null&&{"--nice-field-control-width":typeof h=="number"?`${h}px`:h}},"aria-busy":t||void 0,"data-floating":c==="inside"&&M?"true":void 0,children:[r&&c!=="inside"&&e.jsxs("label",{htmlFor:W,className:`nice-field__label ${v?"nice-field__label--required":""}`,children:[r,Y&&L.length>0&&e.jsx(s.NiceKeyboardHint,{shortcuts:L,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[D.isDisplay?e.jsx(s.DisplayModeView,{value:M??q??"",placeholder:F,disabled:$,readOnly:b,onActivate:D.enterEdit,ariaLabel:r}):e.jsxs("div",{className:`nice-input nice-input--${w} nice-input--ds-${Z||K} ${y?"nice-input--error":""} ${$?"nice-input--disabled":""} ${b?"nice-input--readonly":""}`,style:j?void 0:p,children:[z&&e.jsx("span",{className:"nice-input__icon",children:z}),e.jsx("input",{ref:V=>{typeof a=="function"?a(V):a&&(a.current=V),D.autoFocusRef(V)},id:W,className:"nice-input__native",type:U,name:u,value:M,defaultValue:q,placeholder:F,disabled:$||t,readOnly:b,maxLength:l,autoFocus:I,"aria-invalid":!!y,"aria-describedby":y?`${W}-error`:S?`${W}-helper`:void 0,onChange:V=>_?.(V.target.value),onBlur:V=>{o&&D.exitEdit(),B?.(V)},onKeyDown:P,...N}),H&&M&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:X,"aria-label":x("controls.clear","Clear"),children:e.jsx(s.NiceIcon,{name:"close",size:14})}),A&&e.jsx("span",{className:"nice-input__icon",children:A}),r&&c==="inside"&&e.jsx("label",{htmlFor:W,className:`nice-input__floating-label ${v?"nice-input__floating-label--required":""}`,children:r})]}),t&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),n==="right"&&y&&e.jsx("div",{id:`${W}-error`,className:"nice-field__error",role:"alert",children:y}),n==="right"&&!y&&S&&e.jsx("div",{id:`${W}-helper`,className:"nice-field__helper",children:S})]}),n!=="right"&&y&&e.jsx("div",{id:`${W}-error`,className:"nice-field__error",role:"alert",children:y}),n!=="right"&&!y&&S&&e.jsx("div",{id:`${W}-helper`,className:"nice-field__helper",children:S})]})});ve.displayName="NiceTextInput";const ot=Object.freeze(Object.defineProperty({__proto__:null,NiceTextInput:ve},Symbol.toStringTag,{value:"Module"})),Oe=({code:r,language:S="typescript",lineNumbers:y=!0,livePreview:v=!1,showDiff:$=!1,previousCode:b,theme:w="light",copyable:u=!0,onCopy:C,className:i})=>{const[m,k]=g.useState(!1),E=async()=>{await navigator.clipboard.writeText(r),k(!0),C?.(),setTimeout(()=>k(!1),2e3)},j=r.split(`
|
|
2
|
+
`),M=()=>e.jsx("div",{className:"nice-code-preview__line-numbers",children:j.map((O,F)=>e.jsx("span",{children:F+1},F))}),q=()=>e.jsx("pre",{className:`nice-code-preview__code language-${S}`,children:e.jsx("code",{children:r})}),_=()=>b?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:"Previous"}),e.jsx("pre",{children:b})]}),e.jsxs("div",{className:"nice-code-preview__diff-panel nice-code-preview__diff-panel--new",children:[e.jsx("h4",{children:"Current"}),e.jsx("pre",{children:r})]})]}):null,B=()=>S!=="html"?e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("p",{children:"Live preview is available for HTML only"})}):e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("iframe",{srcDoc:r,title:"Live Preview",sandbox:"allow-scripts"})});return e.jsxs("div",{className:`nice-code-preview nice-code-preview--${w} ${i||""}`,children:[e.jsxs("header",{className:"nice-code-preview__header",children:[e.jsx("span",{className:"nice-code-preview__language",children:S}),u&&e.jsx("button",{onClick:E,className:"nice-code-preview__copy-btn",children:m?e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"check",size:14})," Copied"]}):"Copy"})]}),$&&b?_():e.jsxs("div",{className:"nice-code-preview__body",children:[y&&M(),q()]}),v&&e.jsxs("div",{className:"nice-code-preview__preview-section",children:[e.jsx("h4",{children:"Preview"}),B()]})]})},st=[{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:{}},we="application/x-nice-component";function lt(r){const S=r.replace(/[^A-Za-z0-9]+(.)?/g,(y,v)=>v?v.toUpperCase():"");return/^[A-Za-z]/.test(S)?S.charAt(0).toUpperCase()+S.slice(1):`Component${S}`}function dt(r,S){return["export function Page() {"," return ("," <>",...r.components.map(v=>{const $=Object.entries(v.props).map(([b,w])=>typeof w=="string"?` ${b}=${JSON.stringify(w)}`:` ${b}={${JSON.stringify(w)}}`);return` <${S(v.type)}${$.join("")} />`})," </>"," );","}"].join(`
|
|
3
|
+
`)}const ct=({projectId:r,components:S=[],theme:y="light",onChange:v,onSave:$,renderComponent:b,className:w,tutorial:u})=>{const{t:C}=s.useNiceTranslation(),[i,m]=g.useState("design"),[k,E]=g.useState(at),[j,M]=g.useState(null),[q,_]=g.useState(!1),B=g.useRef(0),O=t=>S.find(d=>d.id===t),F=t=>O(t)?.name??t,U=t=>{const d=O(t)?.icon;return d?e.jsx(s.NiceIcon,{name:d,size:14}):null},l=t=>{const d={...k,components:t};E(d),v?.(d)},z=t=>{B.current+=1;const d={id:`${t.id}-${B.current}`,type:t.id,props:{...t.defaultProps}};l([...k.components,d]),M(d.id)},A=t=>{l(k.components.filter(d=>d.id!==t)),j===t&&M(null)},H=(t,d,h)=>l(k.components.map(o=>o.id===t?{...o,props:{...o.props,[d]:h}}:o)),I=t=>{Array.from(t.dataTransfer.types).includes(we)&&(t.preventDefault(),t.dataTransfer.dropEffect="copy",_(!0))},G=t=>{t.currentTarget.contains(t.relatedTarget)||_(!1)},R=t=>{t.preventDefault(),_(!1);const d=O(t.dataTransfer.getData(we));d&&z(d)},Y=(t,d,h)=>typeof h=="boolean"?e.jsx(ye,{label:d,checked:h,onChange:o=>H(t,d,o)}):typeof h=="number"?e.jsx(be,{label:d,value:h,onChange:o=>H(t,d,o??0)}):typeof h=="string"?e.jsx(ve,{label:d,value:h,onChange:o=>H(t,d,o)}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:d}),e.jsx("code",{children:JSON.stringify(h)})]}),c=k.components.find(t=>t.id===j),n=[{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(ae.NiceAppShell,{flush:!0,className:`nice-lowcode-studio nice-lowcode-studio--${y} ${w||""}`,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:n.map(t=>e.jsx("button",{type:"button","aria-pressed":i===t.id,onClick:()=>m(t.id),className:i===t.id?"active":"",children:t.label},t.id))}),e.jsx("button",{type:"button",onClick:()=>$?.(k),children:C("save","Save")}),e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(u,st)})]}),sidebar:e.jsxs("aside",{className:"nice-lowcode-studio__sidebar",children:[e.jsx("h2",{children:C("noCode.componentDesigner.palette","Component Palette")}),e.jsx("ul",{children:S.map(t=>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(we,t.id),d.dataTransfer.effectAllowed="copy"},onClick:()=>z(t),children:[U(t.id),t.name]})},t.id))})]}),rightSidebar:e.jsxs("aside",{className:"nice-lowcode-studio__properties",children:[e.jsx("h2",{children:C("noCode.lowCodeStudio.properties","Properties")}),c?e.jsxs("div",{className:"nice-lowcode-studio__props",children:[e.jsx("h3",{children:F(c.type)}),Object.keys(c.props).length===0?e.jsx("p",{children:C("noCode.lowCodeStudio.noProps","This component has no properties")}):Object.entries(c.props).map(([t,d])=>e.jsx("div",{className:"nice-lowcode-studio__prop",children:Y(c.id,t,d)},t))]}):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":r,children:[i==="design"&&e.jsx("div",{className:["nice-lowcode-studio__design-canvas",q&&"nice-lowcode-studio__design-canvas--over",k.components.length>0&&"nice-lowcode-studio__design-canvas--filled"].filter(Boolean).join(" "),onDragOver:I,onDragLeave:G,onDrop:R,children:k.components.length===0?e.jsx("p",{children:C("noCode.componentDesigner.dragDrop","Drag components here")}):e.jsx("ul",{className:"nice-lowcode-studio__instances",children:k.components.map(t=>e.jsxs("li",{className:`nice-lowcode-studio__instance${t.id===j?" nice-lowcode-studio__instance--selected":""}`,children:[e.jsxs("button",{type:"button",className:"nice-lowcode-studio__instance-select","aria-pressed":t.id===j,onClick:()=>M(t.id),children:[U(t.type),F(t.type)]}),e.jsx("button",{type:"button","aria-label":`${C("remove","Remove")} ${F(t.type)}`,onClick:()=>A(t.id),children:e.jsx(s.NiceIcon,{name:"close",size:12})})]},t.id))})}),i==="preview"&&e.jsx("div",{className:`nice-lowcode-studio__preview${b?" nice-lowcode-studio__preview--live":""}`,children:b?k.components.map(t=>e.jsx(g.Fragment,{children:b(t)},t.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(Oe,{code:k.components.length>0?dt(k,t=>lt(F(t))):C("noCode.lowCodeStudio.codeEmpty","// Add components to generate code"),language:"tsx",theme:y})})]})})},pt=[{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"}],ut=({component:r,propTypes:S=[],onChange:y,theme:v="light",className:$,tutorial:b})=>{const[w,u]=g.useState(r||{name:"NewComponent",props:[]}),C=i=>{const m={...w,...i};u(m),y?.(m)};return e.jsxs("div",{className:`nice-component-designer nice-component-designer--${v} ${$||""}`,style:{position:"relative"},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(b,pt)})}),e.jsxs("section",{className:"nice-component-designer__header",children:[e.jsx("input",{type:"text",value:w.name,onChange:i=>C({name:i.target.value}),placeholder:"Component Name"}),e.jsx("input",{type:"text",value:w.description||"",onChange:i=>C({description:i.target.value}),placeholder:"Description"})]}),e.jsxs("section",{className:"nice-component-designer__props",children:[e.jsx("h3",{children:"Props"}),w.props.map((i,m)=>e.jsxs("div",{className:"nice-component-designer__prop",children:[e.jsx("input",{type:"text",value:i.name,readOnly:!0}),e.jsx("span",{children:i.type}),i.required&&e.jsx("span",{children:"required"})]},m)),e.jsx("button",{onClick:()=>C({props:[...w.props,{name:"newProp",type:"string"}]}),children:"Add Prop"})]}),e.jsxs("section",{className:"nice-component-designer__preview",children:[e.jsx("h3",{children:"Preview"}),e.jsx("pre",{children:`interface ${w.name}Props {
|
|
4
|
+
${w.props.map(i=>` ${i.name}${i.required?"":"?"}: ${i.type};`).join(`
|
|
5
|
+
`)}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ${w.name}: React.FC<${w.name}Props> = (props) => {
|
|
9
|
+
return <div>Component</div>;
|
|
10
|
+
};`})]})]})},mt=[{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"}],xt=({initialLayout:r,components:S=[],grid:y={columns:12,gap:16,padding:24},onChange:v,onSave:$,theme:b="light",previewMode:w="desktop",className:u,tutorial:C})=>{const[i,m]=g.useState(r||{id:"page-1",name:"New Page",rows:[]}),[k,E]=g.useState(null),j=_=>{m(_),v?.(_)},M=()=>{const _={id:`row-${Date.now()}`,columns:[{id:`col-${Date.now()}`,width:12,components:[]}]};j({...i,rows:[...i.rows,_]})},q={desktop:"100%",tablet:"768px",mobile:"375px"}[w];return e.jsx(ae.NiceAppShell,{flush:!0,className:`nice-page-builder nice-page-builder--${b} ${u||""}`,toolbar:e.jsxs("header",{className:"nice-page-builder__toolbar",children:[e.jsx("input",{type:"text",value:i.name,onChange:_=>j({...i,name:_.target.value})}),e.jsxs("div",{className:"nice-page-builder__preview-modes",children:[e.jsx("button",{className:w==="desktop"?"active":"",children:"Desktop"}),e.jsx("button",{className:w==="tablet"?"active":"",children:"Tablet"}),e.jsx("button",{className:w==="mobile"?"active":"",children:"Mobile"})]}),e.jsx("button",{onClick:()=>$?.(i),children:"Save"}),e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(C,mt)})]}),sidebar:e.jsxs("aside",{className:"nice-page-builder__sidebar",children:[e.jsx("h3",{children:"Components"}),e.jsx("ul",{className:"nice-page-builder__components",children:S.map(_=>e.jsxs("li",{draggable:!0,className:"nice-page-builder__component-item",children:[_.icon&&e.jsx(s.NiceIcon,{name:_.icon,size:14}),_.name]},_.id))})]}),rightSidebar:e.jsxs("aside",{className:"nice-page-builder__properties",children:[e.jsx("h3",{children:"Properties"}),k?e.jsx("p",{children:"Edit properties for selected component"}):e.jsx("p",{children:"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:q},children:[i.rows.map(_=>e.jsx("div",{className:"nice-page-builder__row",children:_.columns.map(B=>e.jsx("div",{className:"nice-page-builder__column",style:{width:`${B.width/12*100}%`},children:B.components.length===0?e.jsx("div",{className:"nice-page-builder__dropzone",children:"Drop components here"}):B.components.map(O=>e.jsx("div",{className:`nice-page-builder__placed-component ${k===O.id?"selected":""}`,onClick:()=>E(O.id),children:O.type},O.id))},B.id))},_.id)),e.jsx("button",{onClick:M,className:"nice-page-builder__add-row",children:"+ Add Row"})]})})})},gt=[{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"}],ht={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}},ft=[{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:[]}]}}],Ie={string:"edit",number:"hash",boolean:"check",array:"clipboard",object:"box",date:"calendar",enum:"bar-chart",custom:"settings"},Re=r=>{const S=["import { create } from 'zustand'"];r.middleware?.some(i=>i.type==="devtools"&&i.enabled)&&S.push("import { devtools } from 'zustand/middleware'"),r.middleware?.some(i=>i.type==="persist"&&i.enabled)&&S.push("import { persist } from 'zustand/middleware'"),r.middleware?.some(i=>i.type==="immer"&&i.enabled)&&S.push("import { immer } from 'zustand/middleware/immer'");const y=[];r.slices.forEach(i=>{y.push(`interface ${_e(i.name)}State {`),i.state.forEach(m=>{const k=Be(m.type,m.nullable);y.push(` ${m.name}: ${k};`)}),y.push("}"),y.push("")}),y.push("interface Actions {"),r.slices.forEach(i=>{i.actions.forEach(m=>{const k=m.params.map(j=>`${j.name}: ${Be(j.type)}`).join(", "),E=m.async?"Promise<void>":"void";y.push(` ${m.name}: (${k}) => ${E};`)})}),y.push("}");const v=r.slices.map(i=>`${_e(i.name)}State`).join(" & ");y.push(""),y.push(`type StoreState = ${v} & Actions;`);const $=[];r.slices.forEach(i=>{i.state.forEach(m=>{const k=m.defaultValue!==void 0?JSON.stringify(m.defaultValue):m.nullable?"null":Le(m.type);$.push(` ${m.name}: ${k},`)})});const b=[];r.slices.forEach(i=>{i.actions.forEach(m=>{const k=m.params.map(j=>j.name).join(", "),E=m.async?"async ":"";b.push(` ${m.name}: ${E}(${k}) => {`),m.async?(b.push(" set({ loading: true, error: null });"),b.push(" try {"),b.push(" // TODO: API call"),b.push(` // const response = await api.${m.name}(${k});`),m.reducerSteps.forEach(j=>{j.type==="set"&&b.push(` set({ ${j.field}: ${j.value} });`)}),b.push(" } catch (error) {"),b.push(" set({ error: error.message, loading: false });"),b.push(" }")):(b.push(" set((state) => {"),m.reducerSteps.forEach(j=>{j.type==="set"?b.push(` state.${j.field} = ${j.value};`):j.type==="push"?b.push(` state.${j.field}.push(${j.value});`):j.type==="reset"&&b.push(` state.${j.field} = null;`)}),b.push(" });")),b.push(" },")})});let w="",u="";if(r.middleware?.some(i=>i.type==="immer"&&i.enabled)&&(w+="immer(",u=")"+u),r.middleware?.some(i=>i.type==="devtools"&&i.enabled)&&(w+="devtools(",u=`, { name: '${r.devtools?.name||r.name}' })`+u),r.persist?.enabled){w+="persist(";const i=[`name: '${r.persist.key}'`];r.persist.whitelist&&i.push(`partialize: (state) => ({ ${r.persist.whitelist.map(m=>m.split(".").pop()).join(", ")} })`),u=`, { ${i.join(", ")} })`+u}return`${S.join(`
|
|
11
|
+
`)}
|
|
12
|
+
|
|
13
|
+
// Types
|
|
14
|
+
${y.join(`
|
|
15
|
+
`)}
|
|
16
|
+
|
|
17
|
+
// Store
|
|
18
|
+
export const use${r.name} = create<StoreState>()(
|
|
19
|
+
${w}(set, get) => ({
|
|
20
|
+
// Initial State
|
|
21
|
+
${$.join(`
|
|
22
|
+
`)}
|
|
23
|
+
|
|
24
|
+
// Actions
|
|
25
|
+
${b.join(`
|
|
26
|
+
`)}
|
|
27
|
+
})${u}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Selectors
|
|
31
|
+
${r.slices.flatMap(i=>i.selectors.map(m=>`export const ${m.name} = (state: StoreState) => ${m.expression.replace("state.","state.")};`)).join(`
|
|
32
|
+
`)}
|
|
33
|
+
`},_e=r=>r.charAt(0).toUpperCase()+r.slice(1),Be=(r,S)=>{const y={string:"string",number:"number",boolean:"boolean",array:"unknown[]",object:"Record<string, unknown>",date:"Date",enum:"string",custom:"unknown"}[r];return S?`${y} | null`:y},Le=r=>({string:"''",number:"0",boolean:"false",array:"[]",object:"{}",date:"new Date()",enum:"''",custom:"null"})[r],Ve=({store:r=ht,templates:S=ft,onStoreChange:y,onExport:v,onSave:$,tutorial:b,className:w,style:u,"data-testid":C})=>{const[i,m]=g.useState(r),[k,E]=g.useState("slices"),[j,M]=g.useState(i.slices[0]?.id||null),[q,_]=g.useState(null),[B,O]=g.useState("zustand"),[F,U]=g.useState(!1),[l,z]=g.useState(null),[A,H]=g.useState(""),[I,G]=g.useState("string"),R=g.useMemo(()=>i.slices.find(x=>x.id===j),[i.slices,j]),Y=g.useCallback(x=>{const W={...i,...x};m(W),y?.(W)},[i,y]),c=()=>{const x={id:`slice-${Date.now()}`,name:"newSlice",state:[],actions:[],selectors:[]};Y({slices:[...i.slices,x]}),M(x.id)},n=()=>{if(!R||!A)return;const x={id:`field-${Date.now()}`,name:A,type:I,defaultValue:Le(I).replace(/'/g,"")},W=i.slices.map(p=>p.id===R.id?{...p,state:[...p.state,x]}:p);Y({slices:W}),H("")},t=()=>{if(!R)return;const x={id:`action-${Date.now()}`,name:"newAction",params:[],reducerSteps:[]},W=i.slices.map(p=>p.id===R.id?{...p,actions:[...p.actions,x]}:p);Y({slices:W}),_(x.id)},d=g.useCallback(()=>{let x="";B==="zustand"?x=Re(i):x=`// Export for ${B} coming soon...
|
|
34
|
+
// Store: ${i.name}`,v?.(x,B)},[i,B,v]),h=g.useMemo(()=>B==="zustand"?Re(i):`// ${B} export coming soon...`,[i,B]),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)",accent:"var(--nice-color-primary, #3b82f6)"},N=e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${o.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})," State Designer"]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8},children:e.jsx("input",{type:"text",value:i.name,onChange:x=>Y({name:x.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.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(b,gt)}),e.jsxs("button",{onClick:()=>U(!0),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:"clipboard",size:14})," Templates"]}),e.jsxs("button",{onClick:()=>$?.(i),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})," Save"]})]})]}),a=e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${o.border}`,padding:"0 20px"},children:["slices","actions","selectors","settings","preview"].map(x=>e.jsxs("button",{onClick:()=>E(x),style:{padding:"12px 20px",border:"none",background:"transparent",color:k===x?o.text:o.textMuted,cursor:"pointer",fontSize:13,fontWeight:k===x?600:400,borderBottom:k===x?`2px solid ${o.accent}`:"2px solid transparent",marginBottom:-1},children:[x==="slices"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"box",size:14})," Slices"]}),x==="actions"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"zap",size:14})," Actions"]}),x==="selectors"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"target",size:14})," Selectors"]}),x==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"settings",size:14})," Settings"]}),x==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," Preview"]})]},x))}),ee=k==="slices"||k==="actions"||k==="selectors"?e.jsxs("div",{style:{width:200,borderRight:`1px solid ${o.border}`,padding:12,display:"flex",flexDirection:"column",gap:8,height:"100%",boxSizing:"border-box"},children:[e.jsx("div",{style:{fontSize:11,color:o.textMuted,marginBottom:4},children:"SLICES"}),i.slices.map(x=>e.jsxs("button",{onClick:()=>M(x.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:j===x.id?o.accent+"30":o.cardBg,color:o.text,cursor:"pointer",textAlign:"left",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"box",size:14})," ",x.name,e.jsxs("div",{style:{fontSize:10,color:o.textMuted},children:[x.state.length," fields • ",x.actions.length," actions"]})]},x.id)),e.jsx("button",{onClick:c,style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${o.border}`,background:"transparent",color:o.textMuted,cursor:"pointer",fontSize:13},children:"+ Add Slice"})]}):void 0;return e.jsxs(e.Fragment,{children:[e.jsx(ae.NiceAppShell,{flush:!0,className:`nice-state-designer ${w||""}`,style:{background:o.bg,color:o.text,fontFamily:"system-ui, sans-serif",...u},"data-testid":C,menubar:N,toolbar:a,sidebar:ee,children:e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:20,boxSizing:"border-box"},children:[k==="slices"&&R&&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})," ",R.name]}),e.jsx("input",{type:"text",value:R.name,onChange:x=>{const W=i.slices.map(p=>p.id===R.id?{...p,name:x.target.value}:p);Y({slices:W})},style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13}})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsxs("div",{style:{fontSize:12,color:o.textMuted,marginBottom:12},children:["STATE FIELDS (",R.state.length,")"]}),e.jsxs("div",{style:{border:`1px solid ${o.border}`,borderRadius:8,overflow:"hidden"},children:[R.state.map(x=>e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${o.border}`,display:"flex",alignItems:"center",gap:12},children:[e.jsx(s.NiceIcon,{name:Ie[x.type],size:14}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,fontFamily:"monospace"},children:x.name}),e.jsxs("div",{style:{fontSize:11,color:o.textMuted},children:[x.type,x.nullable&&"?",x.defaultValue!==void 0&&` = ${JSON.stringify(x.defaultValue)}`]})]}),e.jsx("button",{onClick:()=>{const W=i.slices.map(p=>p.id===R.id?{...p,state:p.state.filter(K=>K.id!==x.id)}:p);Y({slices:W})},"aria-label":"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})})]},x.id)),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",alignItems:"center",gap:8,background:o.cardBg},children:[e.jsx("input",{type:"text",placeholder:"fieldName",value:A,onChange:x=>H(x.target.value),style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:13,fontFamily:"monospace"}}),e.jsx("select",{value:I,onChange:x=>G(x.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:13},children:Object.keys(Ie).map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("button",{onClick:n,disabled:!A,style:{padding:"8px 16px",borderRadius:4,border:"none",background:A?o.accent:o.border,color:"var(--nice-text-on-primary, #fff)",cursor:A?"pointer":"not-allowed",fontSize:13},children:"+ Add"})]})]})]})]}),k==="actions"&&R&&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})," Actions for ",R.name]}),e.jsx("button",{onClick:t,style:{padding:"6px 12px",borderRadius:4,border:"none",background:o.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:12},children:"+ Add Action"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:R.actions.map(x=>e.jsxs("div",{style:{padding:16,background:o.cardBg,borderRadius:8,border:`1px solid ${q===x.id?o.accent:o.border}`,cursor:"pointer"},onClick:()=>_(x.id),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:x.name}),x.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:o.textMuted},children:["(",x.params.map(W=>`${W.name}: ${W.type}`).join(", "),")"]})]}),x.description&&e.jsx("div",{style:{fontSize:12,color:o.textMuted,marginTop:4},children:x.description}),e.jsxs("div",{style:{fontSize:11,color:o.textMuted,marginTop:8},children:[x.reducerSteps.length," reducer steps"]})]},x.id))})]}),k==="selectors"&&R&&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})," Selectors for ",R.name]})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:R.selectors.map(x=>e.jsxs("div",{style:{padding:16,background:o.cardBg,borderRadius:8,border:`1px solid ${o.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:x.name}),x.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:"memoized"})]}),e.jsx("code",{style:{display:"block",marginTop:8,padding:8,background:o.bg,borderRadius:4,fontSize:12,color:"var(--nice-color-warning, #f59e0b)"},children:x.expression})]},x.id))})]}),k==="settings"&&e.jsxs("div",{style:{maxWidth:600},children:[e.jsx("h4",{style:{marginTop:0},children:"Middleware"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:24},children:i.middleware?.map(x=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,padding:12,background:o.cardBg,borderRadius:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:x.enabled,onChange:W=>{const p=i.middleware?.map(K=>K.type===x.type?{...K,enabled:W.target.checked}:K);Y({middleware:p})}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,textTransform:"capitalize"},children:x.type}),e.jsxs("div",{style:{fontSize:11,color:o.textMuted},children:[x.type==="immer"&&"Enable immutable state updates",x.type==="devtools"&&"Redux DevTools integration",x.type==="persist"&&"Persist state to storage"]})]})]},x.type))}),i.persist?.enabled&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"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:o.textMuted,marginBottom:4},children:"Storage Key"}),e.jsx("input",{type:"text",value:i.persist.key,onChange:x=>Y({persist:{...i.persist,key:x.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13,width:"100%",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:o.textMuted,marginBottom:4},children:"Storage Type"}),e.jsxs("select",{value:i.persist.storage,onChange:x=>Y({persist:{...i.persist,storage:x.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.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"})]})]})]})]})]}),k==="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:B,onChange:x=>O(x.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13},children:[e.jsx("option",{value:"zustand",children:"Zustand"}),e.jsx("option",{value:"redux-toolkit",children:"Redux Toolkit"}),e.jsx("option",{value:"jotai",children:"Jotai"}),e.jsx("option",{value:"recoil",children:"Recoil"}),e.jsx("option",{value:"mobx",children:"MobX"})]}),e.jsxs("button",{onClick:d,style:{padding:"8px 16px",borderRadius:4,border:"none",background:o.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," Export"]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(h),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," Copy"]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:o.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:h})]})]})}),F&&e.jsx("div",{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:()=>U(!1),children:e.jsxs("div",{style:{background:o.cardBg,borderRadius:12,padding:24,width:500,maxHeight:"80vh",overflow:"auto"},onClick:x=>x.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})," State Templates"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:S.map(x=>e.jsx("button",{onClick:()=>{x.store.slices&&Y({slices:[...i.slices,...x.store.slices]}),U(!1)},style:{padding:16,borderRadius:8,border:`1px solid ${o.border}`,background:o.bg,color:o.text,cursor:"pointer",textAlign:"left"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(s.NiceIcon,{name:x.icon,size:24}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:x.name}),e.jsx("div",{style:{fontSize:12,color:o.textMuted},children:x.description})]})]})},x.id))})]})})]})},yt=Object.freeze(Object.defineProperty({__proto__:null,NiceStateDesigner:Ve},Symbol.toStringTag,{value:"Module"})),bt={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}},ie={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)"},vt=r=>{const S=["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';"],y=[];r.endpoints.forEach(u=>{u.body?.schema&&y.push(`export interface ${pe(u.name)}Request ${qe(u.body.schema)}`),y.push(`export interface ${pe(u.name)}Response {
|
|
35
|
+
// TODO: Define response type based on schema
|
|
36
|
+
data: unknown;
|
|
37
|
+
}`)});const v=[];r.endpoints.forEach(u=>{const C=u.pathParams?.map(q=>`${q.name}: ${q.type}`).join(", ")||"",i=u.queryParams?.length?`params?: { ${u.queryParams.map(q=>`${q.name}${q.required?"":"?"}: ${q.type}`).join("; ")} }`:"",m=u.body?`data: ${pe(u.name)}Request`:"",k=[C,i,m].filter(Boolean).join(", ");let E=`'${u.path}'`;u.pathParams?.forEach(q=>{E=E.replace(`{${q.name}}`,`\${${q.name}}`)}),u.pathParams?.length&&(E="`"+E.slice(1,-1)+"`");const j=u.cache?.enabled?`
|
|
38
|
+
// Cache: ${u.cache.strategy}, TTL: ${u.cache.ttl}s`:"",M=u.retry?.enabled?`
|
|
39
|
+
// Retry: ${u.retry.maxAttempts} attempts, ${u.retry.backoff} backoff`:"";v.push(`
|
|
40
|
+
/**
|
|
41
|
+
* ${u.description||u.name}${j}${M}
|
|
42
|
+
*/
|
|
43
|
+
async ${u.name}(${k}): Promise<${pe(u.name)}Response> {
|
|
44
|
+
const response = await this.client.${u.method.toLowerCase()}<${pe(u.name)}Response>(
|
|
45
|
+
${E}${u.queryParams?.length?", { params }":""}${u.body?", data":""}
|
|
46
|
+
);
|
|
47
|
+
return response.data;
|
|
48
|
+
}`)});let $="";r.auth?.type==="bearer"&&($=`
|
|
49
|
+
// Auth interceptor
|
|
50
|
+
this.client.interceptors.request.use((config) => {
|
|
51
|
+
const token = ${r.auth.tokenSource||"getToken()"};
|
|
52
|
+
if (token) {
|
|
53
|
+
config.headers['${r.auth.headerName||"Authorization"}'] = '${r.auth.prefix||"Bearer"} ' + token;
|
|
54
|
+
}
|
|
55
|
+
return config;
|
|
56
|
+
});`);const b=r.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`${S.join(`
|
|
67
|
+
`)}
|
|
68
|
+
|
|
69
|
+
// Types
|
|
70
|
+
${y.join(`
|
|
71
|
+
|
|
72
|
+
`)}
|
|
73
|
+
|
|
74
|
+
// API Client
|
|
75
|
+
export class ${r.name} {
|
|
76
|
+
private client: AxiosInstance;
|
|
77
|
+
|
|
78
|
+
constructor(baseURL: string = '${r.baseUrl}') {
|
|
79
|
+
this.client = axios.create({
|
|
80
|
+
baseURL,
|
|
81
|
+
headers: ${JSON.stringify(r.globalHeaders||{},null,8).replace(/\n/g,`
|
|
82
|
+
`)},
|
|
83
|
+
});
|
|
84
|
+
${$}${b}
|
|
85
|
+
}
|
|
86
|
+
${v.join("")}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Default instance
|
|
90
|
+
export const ${r.name.charAt(0).toLowerCase()+r.name.slice(1)} = new ${r.name}();
|
|
91
|
+
`},pe=r=>r.charAt(0).toUpperCase()+r.slice(1),qe=r=>r.type==="object"&&r.properties?`{
|
|
92
|
+
${Object.entries(r.properties).map(([y,v])=>{const $=r.required?.includes(y)?"":"?";return` ${y}${$}: ${Ue(v)};`}).join(`
|
|
93
|
+
`)}
|
|
94
|
+
}`:"{}",Ue=r=>{switch(r.type){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return r.items?`${Ue(r.items)}[]`:"unknown[]";case"object":return r.properties?qe(r):"Record<string, unknown>";default:return"unknown"}},He=({flow:r=bt,dataSources:S=[],onFlowChange:y,onExport:v,onTest:$,onSave:b,className:w,style:u,"data-testid":C})=>{const[i,m]=g.useState(r),[k,E]=g.useState("endpoints"),[j,M]=g.useState(i.endpoints[0]?.id||null),[q,_]=g.useState(!1),[B,O]=g.useState(null),[F,U]=g.useState(!1),l=g.useMemo(()=>i.endpoints.find(n=>n.id===j),[i.endpoints,j]),z=g.useCallback(n=>{const t={...i,...n};m(t),y?.(t)},[i,y]),A=g.useCallback((n,t)=>{const d=i.endpoints.map(h=>h.id===n?{...h,...t}:h);z({endpoints:d})},[i.endpoints,z]),H=n=>{const t={id:`ep-${Date.now()}`,name:"newEndpoint",method:n,path:"/new-path",responses:[{status:200,description:"Success"}]};z({endpoints:[...i.endpoints,t]}),M(t.id),_(!1)},I=n=>{z({endpoints:i.endpoints.filter(t=>t.id!==n)}),j===n&&M(i.endpoints[0]?.id||null)},G=async()=>{l&&(U(!0),O(null),await new Promise(n=>setTimeout(n,1e3)),O({status:200,body:{message:"Mock response",timestamp:new Date().toISOString()}}),U(!1),$?.(l.id))},R=g.useMemo(()=>vt(i),[i]),Y=()=>{v?.(R)};g.useMemo(()=>{const n=new Set;return i.endpoints.forEach(t=>t.tags?.forEach(d=>n.add(d))),Array.from(n)},[i.endpoints]);const c={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 ${w||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:c.bg,color:c.text,fontFamily:"system-ui, sans-serif",...u},"data-testid":C,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${c.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})," API Flow"]}),e.jsx("input",{type:"text",value:i.name,onChange:n=>z({name:n.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:14,fontWeight:600}}),e.jsx("input",{type:"text",value:i.baseUrl,onChange:n=>z({baseUrl:n.target.value}),placeholder:"Base URL",style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13,width:300}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>b?.(i),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})," Save"]})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${c.border}`,padding:"0 20px"},children:["endpoints","auth","settings","test","preview"].map(n=>e.jsxs("button",{onClick:()=>E(n),style:{padding:"12px 20px",border:"none",background:"transparent",color:k===n?c.text:c.textMuted,cursor:"pointer",fontSize:13,fontWeight:k===n?600:400,borderBottom:k===n?`2px solid ${c.accent}`:"2px solid transparent",marginBottom:-1},children:[n==="endpoints"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"link",size:14})," Endpoints"]}),n==="auth"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"lock",size:14})," Auth"]}),n==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"settings",size:14})," Settings"]}),n==="test"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"flask",size:14})," Test"]}),n==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," Preview"]})]},n))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[k==="endpoints"&&e.jsxs("div",{style:{width:280,borderRight:`1px solid ${c.border}`,padding:12,display:"flex",flexDirection:"column",gap:4,overflow:"auto"},children:[e.jsxs("div",{style:{fontSize:11,color:c.textMuted,marginBottom:8},children:["ENDPOINTS (",i.endpoints.length,")"]}),i.endpoints.map(n=>e.jsxs("button",{onClick:()=>M(n.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:j===n.id?c.accent+"30":c.cardBg,color:c.text,cursor:"pointer",textAlign:"left",display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{padding:"2px 6px",borderRadius:4,background:ie[n.method]+"30",color:ie[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:c.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n.path})]})]},n.id)),e.jsx("button",{onClick:()=>_(!0),style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${c.border}`,background:"transparent",color:c.textMuted,cursor:"pointer",fontSize:13,marginTop:8},children:"+ Add Endpoint"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[k==="endpoints"&&l&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[e.jsx("select",{value:l.method,onChange:n=>A(l.id,{method:n.target.value}),style:{padding:"8px 12px",borderRadius:6,border:"none",background:ie[l.method]+"30",color:ie[l.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:l.path,onChange:n=>A(l.id,{path:n.target.value}),style:{flex:1,padding:"8px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:14,fontFamily:"monospace"}}),e.jsxs("button",{onClick:()=>I(l.id),style:{padding:"8px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:"transparent",color:"var(--nice-color-error, #ef4444)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"trash",size:14})," 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:c.textMuted,marginBottom:4},children:"Name"}),e.jsx("input",{type:"text",value:l.name,onChange:n=>A(l.id,{name:n.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:c.textMuted,marginBottom:4},children:"Description"}),e.jsx("input",{type:"text",value:l.description||"",onChange:n=>A(l.id,{description:n.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:c.cardBg,color:c.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})," Parameters"]}),l.pathParams&&l.pathParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:c.textMuted,marginBottom:8},children:"PATH PARAMETERS"}),l.pathParams.map(n=>e.jsxs("div",{style:{padding:12,background:c.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:c.textMuted,fontSize:12},children:n.type}),n.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)",fontSize:10},children:"required"})]},n.id))]}),l.queryParams&&l.queryParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:c.textMuted,marginBottom:8},children:"QUERY PARAMETERS"}),l.queryParams.map(n=>e.jsxs("div",{style:{padding:12,background:c.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:c.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))]}),l.body&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:c.textMuted,marginBottom:8},children:"REQUEST BODY"}),e.jsxs("div",{style:{padding:12,background:c.cardBg,borderRadius:6},children:[e.jsxs("div",{style:{fontSize:12,marginBottom:8},children:["Content-Type: ",e.jsx("code",{children:l.body.contentType})]}),l.body.schema&&e.jsx("pre",{style:{margin:0,padding:12,background:c.bg,borderRadius:4,fontSize:11,overflow:"auto"},children:JSON.stringify(l.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})," Responses"]}),e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:l.responses.map(n=>e.jsxs("div",{style:{padding:12,background:c.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:c.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:c.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:l.cache?.enabled||!1,onChange:n=>A(l.id,{cache:{...l.cache,enabled:n.target.checked}})}),e.jsx(s.NiceIcon,{name:"box",size:14})," Cache"]}),l.cache?.enabled&&e.jsxs("div",{style:{fontSize:12,color:c.textMuted},children:["TTL: ",l.cache.ttl,"s • Strategy: ",l.cache.strategy]})]}),e.jsxs("div",{style:{padding:16,background:c.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:l.retry?.enabled||!1,onChange:n=>A(l.id,{retry:{...l.retry,enabled:n.target.checked,maxAttempts:3,backoff:"exponential"}})}),e.jsx(s.NiceIcon,{name:"refresh",size:14})," Retry"]}),l.retry?.enabled&&e.jsxs("div",{style:{fontSize:12,color:c.textMuted},children:["Max: ",l.retry.maxAttempts," • ",l.retry.backoff," ","backoff"]})]})]})]}),k==="auth"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsxs("h4",{style:{marginTop:0},children:[e.jsx(s.NiceIcon,{name:"lock",size:16})," Authentication"]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:c.textMuted,marginBottom:8},children:"Auth Type"}),e.jsxs("select",{value:i.auth?.type||"none",onChange:n=>z({auth:{...i.auth,type:n.target.value}}),style:{padding:"10px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13,width:"100%"},children:[e.jsx("option",{value:"none",children:"None"}),e.jsx("option",{value:"bearer",children:"Bearer Token"}),e.jsx("option",{value:"basic",children:"Basic Auth"}),e.jsx("option",{value:"api-key",children:"API Key"}),e.jsx("option",{value:"oauth2",children:"OAuth 2.0"})]})]}),i.auth?.type==="bearer"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:c.textMuted,marginBottom:8},children:"Token Source"}),e.jsx("input",{type:"text",value:i.auth.tokenSource||"",onChange:n=>z({auth:{...i.auth,tokenSource:n.target.value}}),placeholder:"state.auth.token",style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:c.textMuted,marginBottom:8},children:"Header Name"}),e.jsx("input",{type:"text",value:i.auth.headerName||"Authorization",onChange:n=>z({auth:{...i.auth,headerName:n.target.value}}),style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13,boxSizing:"border-box"}})]})]}),e.jsxs("h4",{children:[e.jsx(s.NiceIcon,{name:"globe",size:16})," Global Headers"]}),e.jsx("div",{style:{padding:16,background:c.cardBg,borderRadius:8},children:Object.entries(i.globalHeaders||{}).map(([n,t])=>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:c.textMuted},children:":"}),e.jsx("code",{style:{flex:2,color:"var(--nice-color-success, #22c55e)"},children:t})]},n))})]}),k==="settings"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsxs("h4",{style:{marginTop:0},children:[e.jsx(s.NiceIcon,{name:"settings",size:16})," Global Settings"]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h5",{children:"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:i.errorHandling?.globalErrorHandler||!1,onChange:n=>z({errorHandling:{...i.errorHandling,globalErrorHandler:n.target.checked}})}),"Global error handler"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:i.errorHandling?.retryOnNetworkError||!1,onChange:n=>z({errorHandling:{...i.errorHandling,retryOnNetworkError:n.target.checked}})}),"Retry on network errors"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:i.errorHandling?.transformError||!1,onChange:n=>z({errorHandling:{...i.errorHandling,transformError:n.target.checked}})}),"Transform error responses"]})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h5",{children:"Default Cache Settings"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:i.cacheConfig?.enabled||!1,onChange:n=>z({cacheConfig:{...i.cacheConfig,enabled:n.target.checked}})}),"Enable caching"]}),i.cacheConfig?.enabled&&e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:12,color:c.textMuted},children:"Storage"}),e.jsxs("select",{value:i.cacheConfig.storage,onChange:n=>z({cacheConfig:{...i.cacheConfig,storage:n.target.value}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13},children:[e.jsx("option",{value:"memory",children:"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:c.textMuted},children:"Default TTL (seconds)"}),e.jsx("input",{type:"number",value:i.cacheConfig.defaultTTL,onChange:n=>z({cacheConfig:{...i.cacheConfig,defaultTTL:parseInt(n.target.value)}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${c.border}`,background:c.cardBg,color:c.text,fontSize:13,width:100}})]})]})]})]}),k==="test"&&l&&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:ie[l.method]+"30",color:ie[l.method],fontSize:12,fontWeight:600},children:l.method}),e.jsxs("code",{style:{flex:1,fontSize:14},children:[i.baseUrl,l.path]}),e.jsx("button",{onClick:G,disabled:F,style:{padding:"10px 20px",borderRadius:6,border:"none",background:c.accent,color:"var(--nice-text-on-primary, #fff)",cursor:F?"not-allowed":"pointer",fontSize:13,fontWeight:500,opacity:F?.7:1},children:F?e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"clock",size:14})," Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"rocket",size:14})," Send Request"]})})]}),B&&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:B.status<300?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"},children:B.status}),e.jsx("span",{style:{color:c.textMuted},children:B.status<300?"OK":"Error"})]}),e.jsx("pre",{style:{padding:16,background:c.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0},children:JSON.stringify(B.body,null,2)})]})]}),k==="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:Y,style:{padding:"8px 16px",borderRadius:4,border:"none",background:c.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," Export"]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(R),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${c.border}`,background:"transparent",color:c.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," Copy"]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:c.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:R})]})]})]}),q&&e.jsx("div",{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:()=>_(!1),children:e.jsxs("div",{style:{background:c.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})," Add Endpoint"]}),e.jsx("p",{style:{color:c.textMuted,fontSize:13,marginBottom:16},children:"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:()=>H(n),style:{padding:"12px 24px",borderRadius:6,border:"none",background:ie[n]+"30",color:ie[n],cursor:"pointer",fontSize:14,fontWeight:600},children:n},n))})]})})]})},jt=Object.freeze(Object.defineProperty({__proto__:null,NiceAPIFlow:He},Symbol.toStringTag,{value:"Module"})),St={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"}]},De={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)"},Ee={string:"edit",number:"hash",boolean:"check",date:"calendar",array:"clipboard",object:"box",any:"help"},Me={direct:"arrow-right",format:"edit",convert:"refresh",concat:"link",split:"shuffle",calculate:"hash",lookup:"search",conditional:"help",custom:"settings"},kt=r=>{const S=Fe(r.sourceSchema),y=Fe(r.targetSchema),v=r.fieldMappings.map(b=>{const w=r.transformations.find(i=>i.id===b.transform),u=b.targetField;if(!b.sourceField)return` result.${u} = ${JSON.stringify(b.defaultValue)};`;const C=b.sourceField.split(",").map(i=>i.trim());if(w)switch(w.type){case"concat":return` result.${u} = [${C.map(i=>`source.${i}`).join(", ")}].filter(Boolean).join('${w.config.separator||" "}');`;case"format":if(C.length===1){const i=w.config.format||"{value}";return i.includes("{value}")?` result.${u} = '${i}'.replace('{value}', String(source.${C[0]}));`:` result.${u} = formatDate(source.${C[0]}, '${i}');`}break;case"custom":return` result.${u} = ${w.config.expression?.replace(/(\w+)\.(\w+)/g,"source.$1.$2")};`;case"convert":return` result.${u} = ${w.config.convertTo}(source.${C[0]});`}if(C.length===1){const i=b.defaultValue!==void 0?` ?? ${JSON.stringify(b.defaultValue)}`:"";return` result.${u} = source.${C[0]}${i};`}return` // TODO: Manual mapping for ${u}`}),$=r.validationRules.map(b=>{switch(b.type){case"required":return` if (!data.${b.field}) errors.push('${b.message||b.field+" is required"}');`;case"pattern":return` if (data.${b.field} && !/${b.value}/.test(data.${b.field})) errors.push('${b.message||"Invalid format"}');`;default:return` // ${b.type} validation for ${b.field}`}});return`/**
|
|
95
|
+
* ${r.name}
|
|
96
|
+
* ${r.description||""}
|
|
97
|
+
* Auto-generated by NiceDataMapper
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
// Source Type
|
|
101
|
+
${S}
|
|
102
|
+
|
|
103
|
+
// Target Type
|
|
104
|
+
${y}
|
|
105
|
+
|
|
106
|
+
// Validation
|
|
107
|
+
export function validate${r.targetSchema.name}(data: ${r.targetSchema.name}): string[] {
|
|
108
|
+
const errors: string[] = [];
|
|
109
|
+
${$.join(`
|
|
110
|
+
`)}
|
|
111
|
+
return errors;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Mapper
|
|
115
|
+
export function ${r.name.charAt(0).toLowerCase()+r.name.slice(1)}(source: ${r.sourceSchema.name}): ${r.targetSchema.name} {
|
|
116
|
+
const result = {} as ${r.targetSchema.name};
|
|
117
|
+
|
|
118
|
+
${v.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
|
+
`},Fe=(r,S)=>{const y=($,b)=>{const w=" ".repeat(b),u=$.nullable?"?":"";if($.type==="object"&&$.children){const i=$.children.map(m=>y(m,b+1)).join(`
|
|
136
|
+
`);return`${w}${$.name}${u}: {
|
|
137
|
+
${i}
|
|
138
|
+
${w}};`}const C={string:"string",number:"number",boolean:"boolean",date:"string | Date",array:"unknown[]",object:"Record<string, unknown>",any:"unknown"}[$.type];return`${w}${$.name}${u}: ${C};`},v=r.fields.map($=>y($,1)).join(`
|
|
139
|
+
`);return`interface ${r.name} {
|
|
140
|
+
${v}
|
|
141
|
+
}`},We=({mapping:r=St,sourceSchemas:S=[],targetSchemas:y=[],onMappingChange:v,onExport:$,onTest:b,onSave:w,className:u,style:C,"data-testid":i})=>{const[m,k]=g.useState(r),[E,j]=g.useState("mapping"),[M,q]=g.useState(null),[_,B]=g.useState(""),[O,F]=g.useState(""),[U,l]=g.useState(null),z=g.useCallback(t=>{const d={...m,...t};k(d),v?.(d)},[m,v]),A=(t,d="")=>{const h=[];return t.forEach(o=>{h.push(o),o.children&&h.push(...A(o.children,o.path+"."))}),h},H=g.useMemo(()=>A(m.sourceSchema.fields),[m.sourceSchema.fields]),I=g.useMemo(()=>A(m.targetSchema.fields),[m.targetSchema.fields]),G=(t,d)=>{const h={id:`mapping-${Date.now()}`,sourceField:t,targetField:d};z({fieldMappings:[...m.fieldMappings,h]})},R=t=>{z({fieldMappings:m.fieldMappings.filter(d=>d.id!==t)})},Y=()=>{try{const t=JSON.parse(_),d={};m.fieldMappings.forEach(h=>{if(!h.sourceField){d[h.targetField]=h.defaultValue;return}const o=h.sourceField.split(",").map(Q=>Q.trim()),N=Q=>Q.split(".").reduce((ee,x)=>ee?.[x],t),a=m.transformations.find(Q=>Q.id===h.transform);if(a?.type==="concat")d[h.targetField]=o.map(N).filter(Boolean).join(a.config.separator||" ");else if(a?.type==="format"&&o.length===1){const Q=N(o[0]);d[h.targetField]=(a.config.format||"{value}").replace("{value}",String(Q))}else o.length===1&&(d[h.targetField]=N(o[0])??h.defaultValue)}),F(JSON.stringify(d,null,2)),b?.(d)}catch(t){F(`Error: ${t.message}`)}},c=g.useMemo(()=>kt(m),[m]),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)",accent:"var(--nice-color-primary, #3b82f6)"};return e.jsxs("div",{className:`nice-data-mapper ${u||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:n.bg,color:n.text,fontFamily:"system-ui, sans-serif",...C},"data-testid":i,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${n.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})," Data Mapper"]}),e.jsx("input",{type:"text",value:m.name,onChange:t=>z({name:t.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.cardBg,color:n.text,fontSize:14,fontWeight:600}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>w?.(m),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})," Save"]})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${n.border}`,padding:"0 20px"},children:["mapping","transforms","validation","test","preview"].map(t=>e.jsxs("button",{onClick:()=>j(t),style:{padding:"12px 20px",border:"none",background:"transparent",color:E===t?n.text:n.textMuted,cursor:"pointer",fontSize:13,fontWeight:E===t?600:400,borderBottom:E===t?`2px solid ${n.accent}`:"2px solid transparent",marginBottom:-1},children:[t==="mapping"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"link",size:14})," Mapping"]}),t==="transforms"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"zap",size:14})," Transforms"]}),t==="validation"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"check",size:14})," Validation"]}),t==="test"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"flask",size:14})," Test"]}),t==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," Preview"]})]},t))}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[E==="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})," Source: ",m.sourceSchema.name]}),e.jsx("div",{style:{flex:1,border:`1px solid ${n.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:H.map(t=>{const d=t.path.split(".").length-1,h=m.fieldMappings.some(o=>o.sourceField.split(",").some(N=>N.trim()===t.path));return e.jsxs("div",{draggable:!0,onDragStart:()=>l(t.path),onDragEnd:()=>l(null),style:{padding:"10px 12px",paddingLeft:12+d*16,borderBottom:`1px solid ${n.border}`,display:"flex",alignItems:"center",gap:8,cursor:"grab",background:h?"var(--nice-success-tint-10, #22c55e10)":"transparent",opacity:t.type==="object"&&t.children?.7:1},children:[e.jsx("span",{style:{color:De[t.type],fontSize:14},children:e.jsx(s.NiceIcon,{name:Ee[t.type],size:14})}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:t.name}),e.jsx("span",{style:{fontSize:10,color:n.textMuted},children:t.type}),h&&e.jsx("span",{style:{marginLeft:"auto",color:"var(--nice-color-success, #22c55e)",fontSize:10},children:e.jsx(s.NiceIcon,{name:"check",size:14})})]},t.id)})})]}),e.jsxs("div",{style:{width:300,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:n.accent+"20",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:[e.jsx(s.NiceIcon,{name:"link",size:16})," Mappings (",m.fieldMappings.length,")"]}),e.jsx("div",{style:{flex:1,border:`1px solid ${n.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto",padding:8},children:m.fieldMappings.map(t=>{const d=m.transformations.find(h=>h.id===t.transform);return e.jsxs("div",{style:{padding:8,background:n.cardBg,borderRadius:6,marginBottom:8,fontSize:11},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginBottom:4},children:[e.jsx("code",{style:{color:"var(--nice-color-success, #22c55e)"},children:t.sourceField||"(default)"}),e.jsx("span",{style:{color:n.textMuted},children:"→"}),e.jsx("code",{style:{color:"var(--nice-color-primary, #3b82f6)"},children:t.targetField}),e.jsx("button",{onClick:()=>R(t.id),"aria-label":"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})})]}),d&&e.jsxs("div",{style:{color:n.textMuted,display:"flex",alignItems:"center",gap:4},children:[e.jsx(s.NiceIcon,{name:Me[d.type],size:14})," ",d.name]}),t.defaultValue!==void 0&&e.jsxs("div",{style:{color:"var(--nice-color-warning, #f59e0b)"},children:["Default: ",JSON.stringify(t.defaultValue)]})]},t.id)})})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"var(--nice-primary-tint-12, #3b82f620)",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," Target: ",m.targetSchema.name]}),e.jsx("div",{style:{flex:1,border:`1px solid ${n.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:I.map(t=>{const d=t.path.split(".").length-1,h=m.fieldMappings.some(o=>o.targetField===t.path);return e.jsxs("div",{onDragOver:o=>o.preventDefault(),onDrop:()=>{U&&!h&&G(U,t.path)},style:{padding:"10px 12px",paddingLeft:12+d*16,borderBottom:`1px solid ${n.border}`,display:"flex",alignItems:"center",gap:8,background:U&&!h?n.accent+"10":h?"#3b82f610":"transparent",transition:"background 0.15s"},children:[e.jsx("span",{style:{color:De[t.type],fontSize:14},children:e.jsx(s.NiceIcon,{name:Ee[t.type],size:14})}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:t.name}),e.jsx("span",{style:{fontSize:10,color:n.textMuted},children:t.type}),t.nullable&&e.jsx("span",{style:{fontSize:10,color:n.textMuted},children:"?"}),h&&e.jsx("span",{style:{marginLeft:"auto",color:"var(--nice-color-primary, #3b82f6)",fontSize:10},children:e.jsx(s.NiceIcon,{name:"check",size:14})})]},t.id)})})]})]}),E==="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})," Transformations"]}),e.jsx("button",{onClick:()=>{const t={id:`tr-${Date.now()}`,name:"New Transform",type:"direct",config:{}};z({transformations:[...m.transformations,t]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:n.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:12},children:"+ Add Transform"})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:16},children:m.transformations.map(t=>e.jsxs("div",{style:{padding:16,background:n.cardBg,borderRadius:8,border:`1px solid ${n.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:Me[t.type],size:20})}),e.jsx("input",{type:"text",value:t.name,onChange:d=>{const h=m.transformations.map(o=>o.id===t.id?{...o,name:d.target.value}:o);z({transformations:h})},style:{flex:1,padding:"6px 8px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:13,fontWeight:600}})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:"Type"}),e.jsxs("select",{value:t.type,onChange:d=>{const h=m.transformations.map(o=>o.id===t.id?{...o,type:d.target.value}:o);z({transformations:h})},style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:[e.jsx("option",{value:"direct",children:"Direct"}),e.jsx("option",{value:"format",children:"Format"}),e.jsx("option",{value:"convert",children:"Convert"}),e.jsx("option",{value:"concat",children:"Concatenate"}),e.jsx("option",{value:"split",children:"Split"}),e.jsx("option",{value:"calculate",children:"Calculate"}),e.jsx("option",{value:"lookup",children:"Lookup"}),e.jsx("option",{value:"conditional",children:"Conditional"}),e.jsx("option",{value:"custom",children:"Custom"})]})]}),(t.type==="format"||t.type==="concat")&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:t.type==="format"?"Format Pattern":"Separator"}),e.jsx("input",{type:"text",value:t.type==="format"?t.config.format||"":t.config.separator||"",onChange:d=>{const h=m.transformations.map(o=>o.id===t.id?{...o,config:{...o.config,[t.type==="format"?"format":"separator"]:d.target.value}}:o);z({transformations:h})},placeholder:t.type==="format"?"{value} or YYYY-MM-DD":", ",style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,fontFamily:"monospace",boxSizing:"border-box"}})]}),t.type==="custom"&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:"Expression"}),e.jsx("textarea",{value:t.config.expression||"",onChange:d=>{const h=m.transformations.map(o=>o.id===t.id?{...o,config:{...o.config,expression:d.target.value}}:o);z({transformations:h})},rows:3,style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,fontFamily:"monospace",resize:"vertical",boxSizing:"border-box"}})]})]},t.id))})]}),E==="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})," Validation Rules"]}),e.jsx("button",{onClick:()=>{const t={id:`v-${Date.now()}`,field:"",type:"required",message:""};z({validationRules:[...m.validationRules,t]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:n.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:12},children:"+ Add Rule"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:m.validationRules.map(t=>e.jsxs("div",{style:{padding:16,background:n.cardBg,borderRadius:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsxs("select",{value:t.field,onChange:d=>{const h=m.validationRules.map(o=>o.id===t.id?{...o,field:d.target.value}:o);z({validationRules:h})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:[e.jsx("option",{value:"",children:"Select field..."}),I.map(d=>e.jsx("option",{value:d.path,children:d.path},d.id))]}),e.jsxs("select",{value:t.type,onChange:d=>{const h=m.validationRules.map(o=>o.id===t.id?{...o,type:d.target.value}:o);z({validationRules:h})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:[e.jsx("option",{value:"required",children:"Required"}),e.jsx("option",{value:"type",children:"Type"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"}),e.jsx("option",{value:"pattern",children:"Pattern"}),e.jsx("option",{value:"enum",children:"Enum"}),e.jsx("option",{value:"custom",children:"Custom"})]}),(t.type==="pattern"||t.type==="min"||t.type==="max")&&e.jsx("input",{type:"text",value:String(t.value||""),onChange:d=>{const h=m.validationRules.map(o=>o.id===t.id?{...o,value:d.target.value}:o);z({validationRules:h})},placeholder:"Value",style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12,width:150}}),e.jsx("input",{type:"text",value:t.message||"",onChange:d=>{const h=m.validationRules.map(o=>o.id===t.id?{...o,message:d.target.value}:o);z({validationRules:h})},placeholder:"Error message",style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12}}),e.jsx("button",{onClick:()=>{z({validationRules:m.validationRules.filter(d=>d.id!==t.id)})},"aria-label":"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})})]},t.id))})]}),E==="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})," Input"]}),e.jsx("button",{onClick:()=>{const t={},d=(h,o)=>{h.forEach(N=>{N.children&&N.type==="object"?(o[N.name]={},d(N.children,o[N.name])):o[N.name]={string:"sample",number:42,boolean:!0,date:new Date().toISOString(),array:[],object:{},any:null}[N.type]})};d(m.sourceSchema.fields,t),B(JSON.stringify(t,null,2))},style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${n.border}`,background:"transparent",color:n.text,cursor:"pointer",fontSize:11},children:"Generate Sample"})]}),e.jsx("textarea",{value:_,onChange:t=>B(t.target.value),placeholder:"Paste JSON input here...",style:{flex:1,padding:12,borderRadius:8,border:`1px solid ${n.border}`,background:n.cardBg,color:n.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})," Output"]}),e.jsxs("button",{onClick:Y,style:{padding:"6px 16px",borderRadius:4,border:"none",background:n.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:12},children:[e.jsx(s.NiceIcon,{name:"refresh",size:14})," Transform"]})]}),e.jsx("pre",{style:{flex:1,padding:12,borderRadius:8,background:n.cardBg,margin:0,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace"},children:O||"Run transform to see output"})]})]}),E==="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:()=>$?.(c),style:{padding:"8px 16px",borderRadius:4,border:"none",background:n.accent,color:"var(--nice-text-on-primary, #fff)",cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"upload",size:14})," Export"]}),e.jsxs("button",{onClick:()=>navigator.clipboard.writeText(c),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${n.border}`,background:"transparent",color:n.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"clipboard",size:14})," Copy"]})]}),e.jsx("pre",{style:{flex:1,padding:16,background:n.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:c})]})]})]})},wt=Object.freeze(Object.defineProperty({__proto__:null,NiceDataMapper:We},Symbol.toStringTag,{value:"Module"})),Nt=[{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}]}],$t=[{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"}]}],Ct=[{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"}}]}],zt=r=>{const S=r.filter(v=>v.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
|
+
${S.map(v=>`export type ${v.name.replace(/\s+/g,"")}Event = {
|
|
153
|
+
source: '${v.source.type}';
|
|
154
|
+
payload: unknown;
|
|
155
|
+
};`).join(`
|
|
156
|
+
|
|
157
|
+
`)}
|
|
158
|
+
|
|
159
|
+
// Event Handlers
|
|
160
|
+
${S.map(v=>{const $=JSON.stringify(v.source.config,null,2),b=v.handlers.flatMap(w=>w.modifiers||[]).map(w=>`.${w.type}(${w.value})`).join("");return`
|
|
161
|
+
/**
|
|
162
|
+
* ${v.name}
|
|
163
|
+
* ${v.description||""}
|
|
164
|
+
*/
|
|
165
|
+
export const ${v.name.replace(/\s+/g,"").toLowerCase()}Handler = eventBus
|
|
166
|
+
.on('${v.source.type}', ${$})${b}
|
|
167
|
+
.pipe(
|
|
168
|
+
${v.handlers.map((w,u)=>` // Step ${u+1}: ${w.type}
|
|
169
|
+
async (event) => {
|
|
170
|
+
${Ae(w)}
|
|
171
|
+
},`).join(`
|
|
172
|
+
`)}
|
|
173
|
+
)
|
|
174
|
+
${v.errorHandler?`.catch(async (error) => {
|
|
175
|
+
${Ae(v.errorHandler)}
|
|
176
|
+
})`:""};`}).join(`
|
|
177
|
+
`)}
|
|
178
|
+
|
|
179
|
+
// Initialize all handlers
|
|
180
|
+
export function initEventOrchestration() {
|
|
181
|
+
${S.map(v=>` ${v.name.replace(/\s+/g,"").toLowerCase()}Handler.start();`).join(`
|
|
182
|
+
`)}
|
|
183
|
+
console.log('Event orchestration initialized');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Cleanup
|
|
187
|
+
export function destroyEventOrchestration() {
|
|
188
|
+
${S.map(v=>` ${v.name.replace(/\s+/g,"").toLowerCase()}Handler.stop();`).join(`
|
|
189
|
+
`)}
|
|
190
|
+
}
|
|
191
|
+
`},Ae=r=>{switch(r.type){case"action":return`dispatch({ type: '${r.config.actionType}', payload: ${JSON.stringify(r.config.payload)} });`;case"transform":return`return (${r.config.expression})(event);`;case"dispatch":return`eventBus.emit('${r.config.eventName}', ${JSON.stringify(r.config.payload)});`;case"api-call":return`await fetch('${r.config.endpoint}', { method: '${r.config.method}', body: JSON.stringify(event.payload) });`;case"state-update":return`updateState('${r.config.path}', ${r.config.value});`;case"notification":return`showNotification({ type: '${r.config.type}', message: '${r.config.message}' });`;case"log":return`console.${r.config.level||"log"}('${r.config.message}', event);`;case"delay":return`await new Promise(r => setTimeout(r, ${r.config.duration}));`;case"branch":return`if (${r.config.condition}) { /* true branch */ } else { /* false branch */ }`;default:return"// Unknown handler type"}},Je=({flows:r=Ct,eventSources:S=Nt,eventHandlers:y=$t,onFlowsChange:v,onExport:$,onTest:b,className:w,style:u,"data-testid":C})=>{const[i,m]=g.useState(r),[k,E]=g.useState(i[0]?.id??null),[j,M]=g.useState("visual"),[q,_]=g.useState(!1),[B,O]=g.useState(""),[F,U]=g.useState(new Set),l=g.useMemo(()=>i.find(t=>t.id===k),[i,k]),z=g.useMemo(()=>zt(i),[i]),A=g.useCallback((t,d)=>{m(h=>{const o=h.map(N=>N.id===t?{...N,...d}:N);return v?.(o),o})},[v]),H=()=>{if(!B.trim())return;const t={id:`flow-${Date.now()}`,name:B,enabled:!0,source:{id:`src-${Date.now()}`,type:"ui-event",config:{element:"",event:"click"}},handlers:[]};m(d=>{const h=[...d,t];return v?.(h),h}),E(t.id),_(!1),O("")},I=t=>{m(d=>{const h=d.filter(o=>o.id!==t);return v?.(h),h}),k===t&&E(i[0]?.id??null)},G=t=>{if(!l)return;const d=y.find(N=>N.type===t),h={};d?.configSchema.forEach(N=>{N.default!==void 0&&(h[N.name]=N.default)});const o={id:`handler-${Date.now()}`,type:t,config:h};A(l.id,{handlers:[...l.handlers,o]}),U(N=>new Set([...N,o.id]))},R=(t,d)=>{l&&A(l.id,{handlers:l.handlers.map(h=>h.id===t?{...h,...d}:h)})},Y=t=>{l&&A(l.id,{handlers:l.handlers.filter(d=>d.id!==t)})},c=(t,d)=>{if(!l)return;const h=l.handlers.find(a=>a.id===t);if(!h)return;const N=h.modifiers?.find(a=>a.type===d)?h.modifiers?.filter(a=>a.type!==d):[...h.modifiers||[],{type:d,value:500,unit:"ms"}];R(t,{modifiers:N})},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 ${w||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:n.bg,color:n.text,fontFamily:"system-ui, sans-serif",...u},"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})," Event Orchestrator"]}),e.jsx("div",{style:{display:"flex",border:`1px solid ${n.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(t=>e.jsxs("button",{onClick:()=>M(t),style:{padding:"6px 12px",border:"none",background:j===t?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:t==="visual"?"palette":t==="code"?"edit":"grid",size:14})," ",t]},t))}),e.jsxs("button",{onClick:()=>$?.(z),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})," 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:"Event Flows"}),e.jsx("button",{onClick:()=>_(!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:[i.map(t=>{const d=S.find(h=>h.type===t.source.type);return e.jsxs("div",{onClick:()=>E(t.id),style:{padding:12,background:k===t.id?n.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${k===t.id?n.border:"transparent"}`,opacity:t.enabled?1:.5},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(s.NiceIcon,{name:d?.icon??"zap",size:16}),e.jsx("span",{style:{flex:1,fontSize:13,fontWeight:500},children:t.name}),e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:t.enabled?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"}})]}),e.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:4},children:[t.handlers.length," handler",t.handlers.length!==1?"s":""]})]},t.id)}),q&&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:B,onChange:t=>O(t.target.value),placeholder:"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:t=>t.key==="Enter"&&H()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>_(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${n.border}`,background:"transparent",color:n.text,cursor:"pointer",fontSize:11},children:"Cancel"}),e.jsx("button",{onClick:H,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:"Add"})]})]})]})]}),(j==="visual"||j==="split")&&l&&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:l.name,onChange:t=>A(l.id,{name:t.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:l.enabled,onChange:t=>A(l.id,{enabled:t.target.checked})}),e.jsx("span",{style:{fontSize:12},children:"Enabled"})]}),e.jsxs("button",{onClick:()=>b?.(l.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})," Test"]}),e.jsx("button",{onClick:()=>I(l.id),"aria-label":"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 ${S.find(t=>t.type===l.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:S.find(t=>t.type===l.source.type)?.icon??"zap",size:20}),e.jsx("span",{style:{fontWeight:600},children:"Event Source"})]}),e.jsx("select",{value:l.source.type,onChange:t=>A(l.id,{source:{...l.source,type:t.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:S.map(t=>e.jsx("option",{value:t.type,children:t.label},t.type))}),S.find(t=>t.type===l.source.type)?.configSchema.map(t=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsxs("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:[t.label," ",t.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)"},children:"*"})]}),t.type==="select"?e.jsx("select",{value:String(l.source.config[t.name]??""),onChange:d=>A(l.id,{source:{...l.source,config:{...l.source.config,[t.name]:d.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:t.options?.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))}):e.jsx("input",{type:t.type==="number"?"number":"text",value:String(l.source.config[t.name]??""),onChange:d=>A(l.id,{source:{...l.source,config:{...l.source.config,[t.name]:t.type==="number"?Number(d.target.value):d.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"}})]},t.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:[l.handlers.map((t,d)=>{const h=y.find(N=>N.type===t.type),o=F.has(t.id);return e.jsxs(g.Fragment,{children:[e.jsxs("div",{style:{padding:16,background:n.cardBg,borderRadius:8,borderLeft:`4px solid ${h?.color??"var(--nice-text-muted, #888)"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},onClick:()=>U(N=>{const a=new Set(N);return a.has(t.id)?a.delete(t.id):a.add(t.id),a}),children:[e.jsx(s.NiceIcon,{name:h?.icon??"zap",size:16}),e.jsxs("span",{style:{fontWeight:500},children:[d+1,". ",h?.label??t.type]}),t.modifiers?.map(N=>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:[N.type,": ",N.value,"ms"]},N.type)),e.jsx("span",{style:{marginLeft:"auto",color:n.textMuted,display:"inline-flex",alignItems:"center"},children:e.jsx(s.NiceIcon,{name:o?"chevron-down":"chevron-right",size:14})})]}),o&&e.jsxs("div",{style:{marginTop:12,paddingTop:12,borderTop:`1px solid ${n.border}`},children:[e.jsx("select",{value:t.type,onChange:N=>R(t.id,{type:N.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:y.map(N=>e.jsx("option",{value:N.type,children:N.label},N.type))}),h?.configSchema.map(N=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:n.textMuted,marginBottom:4},children:N.label}),N.type==="code"?e.jsx("textarea",{value:String(t.config[N.name]??""),onChange:a=>R(t.id,{config:{...t.config,[N.name]:a.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"}}):N.type==="select"?e.jsx("select",{value:String(t.config[N.name]??""),onChange:a=>R(t.id,{config:{...t.config,[N.name]:a.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${n.border}`,background:n.bg,color:n.text,fontSize:12},children:N.options?.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}):e.jsx("input",{type:N.type==="number"?"number":"text",value:String(t.config[N.name]??""),onChange:a=>R(t.id,{config:{...t.config,[N.name]:N.type==="number"?Number(a.target.value):a.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"}})]},N.name)),e.jsxs("div",{style:{marginTop:12},children:[e.jsx("div",{style:{fontSize:11,color:n.textMuted,marginBottom:8},children:"Modifiers"}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["debounce","throttle","delay","retry","once"].map(N=>e.jsx("button",{onClick:()=>c(t.id,N),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${t.modifiers?.some(a=>a.type===N)?"var(--nice-color-accent, #8b5cf6)":n.border}`,background:t.modifiers?.some(a=>a.type===N)?"var(--nice-accent-tint-12, #8b5cf620)":"transparent",color:n.text,cursor:"pointer",fontSize:11},children:N},N))})]}),e.jsxs("button",{onClick:()=>Y(t.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})," Remove Handler"]})]})]}),d<l.handlers.length-1&&e.jsx("div",{style:{textAlign:"center",color:n.textMuted},children:e.jsx(s.NiceIcon,{name:"arrow-down",size:16})})]},t.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:"Add Handler"}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center"},children:y.map(t=>e.jsxs("button",{onClick:()=>G(t.type),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${t.color}`,background:`${t.color}20`,color:n.text,cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(s.NiceIcon,{name:t.icon,size:14})," ",t.label]},t.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:z})})]})]})},Tt=Object.freeze(Object.defineProperty({__proto__:null,NiceEventOrchestrator:Je},Symbol.toStringTag,{value:"Module"})),It=[{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"}],fe={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)"}},Rt=[{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"}}]}]}],_t=r=>r.map(S=>{const y=new Set(["import { render, screen, fireEvent, waitFor } from '@testing-library/react';","import userEvent from '@testing-library/user-event';",`import { ${S.componentName} } from './${S.componentName}';`]);S.setup?.mocks.forEach(u=>{u.type==="api"&&(y.add("import { rest } from 'msw';"),y.add("import { setupServer } from 'msw/node';"))});const v=S.setup?.mocks.map(u=>u.type==="function"?`const ${u.name} = jest.fn();`:u.type==="api"?`// API mock: ${u.name}`:"").filter(Boolean).join(`
|
|
192
|
+
`),b=S.setup?.providers&&S.setup.providers.length>0?`const Wrapper = ({ children }) => (
|
|
193
|
+
${S.setup.providers.map(u=>`<${u.name}>`).join(`
|
|
194
|
+
`)}
|
|
195
|
+
{children}
|
|
196
|
+
${S.setup.providers.reverse().map(u=>`</${u.name}>`).join(`
|
|
197
|
+
`)}
|
|
198
|
+
);`:"",w=S.tests.map(u=>{const C=u.skip?".skip":u.only?".only":"",i=u.steps.map(m=>Bt(m,S)).join(`
|
|
199
|
+
`);return`
|
|
200
|
+
it${C}('${u.name}', async () => {
|
|
201
|
+
${i}
|
|
202
|
+
});`}).join(`
|
|
203
|
+
`);return`/**
|
|
204
|
+
* ${S.name}
|
|
205
|
+
* @generated by NiceTestBuilder
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
${Array.from(y).join(`
|
|
209
|
+
`)}
|
|
210
|
+
|
|
211
|
+
describe('${S.componentName}', () => {
|
|
212
|
+
${v?` // Mocks
|
|
213
|
+
${v}
|
|
214
|
+
`:""}
|
|
215
|
+
${b?` ${b}
|
|
216
|
+
`:""}
|
|
217
|
+
beforeEach(() => {
|
|
218
|
+
jest.clearAllMocks();
|
|
219
|
+
});
|
|
220
|
+
${w}
|
|
221
|
+
});
|
|
222
|
+
`}).join(`
|
|
223
|
+
|
|
224
|
+
`),Bt=(r,S)=>{switch(fe[r.action],r.action){case"render":{const y=S.setup?.providers&&S.setup.providers.length>0,v=S.setup?.props?` {...${JSON.stringify(S.setup.props)}}`:"";return y?`render(<${S.componentName}${v} />, { wrapper: Wrapper });`:`render(<${S.componentName}${v} />);`}case"click":return`await userEvent.click(screen.getByRole('${r.target?.replace(/[[\]'"]/g,"")}'));`;case"type":return`await userEvent.type(screen.getByRole('textbox', { name: /${r.target}/ }), '${r.value}');`;case"select":return`await userEvent.selectOptions(screen.getByRole('combobox'), '${r.value}');`;case"hover":return`await userEvent.hover(screen.getByRole('${r.target}'));`;case"focus":return`screen.getByRole('${r.target}').focus();`;case"blur":return`screen.getByRole('${r.target}').blur();`;case"submit":return"fireEvent.submit(screen.getByRole('form'));";case"wait":if(typeof r.value=="object"&&r.value!==null){const y=r.value;return y.type==="timeout"?`await new Promise(r => setTimeout(r, ${y.value}));`:`await waitFor(() => expect(/* condition */).toBeTruthy(), { timeout: ${y.timeout??1e3} });`}return`await new Promise(r => setTimeout(r, ${r.value}));`;case"assert":if(typeof r.value=="object"&&r.value!==null){const y=r.value;if(y.mock)return`expect(${y.mock}).${y.matcher}(${y.expected?JSON.stringify(y.expected):""});`;const v=r.target?`screen.getByRole('${r.target}')`:"result",$=y.expected!==void 0?JSON.stringify(y.expected):"";return`expect(${v}).${y.matcher}(${$});`}return`expect(screen.getByRole('${r.target}')).toBeInTheDocument();`;case"snapshot":return"expect(container).toMatchSnapshot();";case"a11y-check":return`const results = await axe(container);
|
|
225
|
+
expect(results).toHaveNoViolations();`;default:return`// ${r.action}: ${JSON.stringify(r)}`}},Ke=({componentName:r="MyComponent",testSuites:S=Rt,availableMocks:y=[],onSuitesChange:v,onExport:$,onRun:b,onRunAll:w,tutorial:u,className:C,style:i,"data-testid":m})=>{const[k,E]=g.useState(S),[j,M]=g.useState(k[0]?.id??null),[q,_]=g.useState(null),[B,O]=g.useState("visual"),[F,U]=g.useState(!1),[l,z]=g.useState(""),[A,H]=g.useState(new Set),I=g.useMemo(()=>k.find(p=>p.id===j),[k,j]);g.useMemo(()=>I?.tests.find(p=>p.id===q),[I,q]);const G=g.useMemo(()=>_t(k),[k]),R=g.useCallback((p,K)=>{E(Z=>{const X=Z.map(D=>D.id===p?{...D,...K}:D);return v?.(X),X})},[v]),Y=()=>{if(!l.trim())return;const p={id:`suite-${Date.now()}`,name:l,componentName:r,tests:[]};E(K=>{const Z=[...K,p];return v?.(Z),Z}),M(p.id),U(!1),z("")},c=p=>{E(K=>{const Z=K.filter(X=>X.id!==p);return v?.(Z),Z}),j===p&&M(k[0]?.id??null)},n=()=>{if(!I)return;const p={id:`test-${Date.now()}`,name:"New test",type:"unit",steps:[{id:`step-${Date.now()}`,action:"render"}]};R(I.id,{tests:[...I.tests,p]}),_(p.id),H(K=>new Set([...K,p.id]))},t=(p,K)=>{I&&R(I.id,{tests:I.tests.map(Z=>Z.id===p?{...Z,...K}:Z)})},d=p=>{I&&(R(I.id,{tests:I.tests.filter(K=>K.id!==p)}),q===p&&_(null))},h=(p,K)=>{if(!I)return;const Z=I.tests.find(D=>D.id===p);if(!Z)return;const X={id:`step-${Date.now()}`,action:K};t(p,{steps:[...Z.steps,X]})},o=(p,K,Z)=>{if(!I)return;const X=I.tests.find(D=>D.id===p);X&&t(p,{steps:X.steps.map(D=>D.id===K?{...D,...Z}:D)})},N=(p,K)=>{if(!I)return;const Z=I.tests.find(X=>X.id===p);Z&&t(p,{steps:Z.steps.filter(X=>X.id!==K)})},a={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=g.useMemo(()=>{const p=k.reduce((Z,X)=>Z+X.tests.length,0),K=k.reduce((Z,X)=>Z+X.tests.filter(D=>D.skip).length,0);return{total:p,skipped:K}},[k]),ee=e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${a.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})," Test Builder"]}),e.jsxs("div",{style:{fontSize:12,color:a.textMuted},children:[Q.total," tests • ",Q.skipped," skipped"]}),e.jsx("div",{style:{display:"flex",border:`1px solid ${a.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(p=>e.jsxs("button",{onClick:()=>O(p),style:{padding:"6px 12px",border:"none",background:B===p?a.cardBg:"transparent",color:a.text,cursor:"pointer",fontSize:12,textTransform:"capitalize"},children:[e.jsx(s.NiceIcon,{name:p==="visual"?"palette":p==="code"?"edit":"grid",size:14})," ",p]},p))}),e.jsxs("button",{onClick:w,style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${a.border}`,background:"transparent",color:a.text,cursor:"pointer",fontSize:13},children:[e.jsx(s.NiceIcon,{name:"play",size:14})," Run All"]}),e.jsxs("button",{onClick:()=>$?.(G),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})," Export"]}),e.jsx(s.NiceTutorialButton,{steps:s.resolveTutorial(u,It)})]}),W=B==="visual"||B==="split"?e.jsxs("div",{style:{width:220,borderRight:`1px solid ${a.border}`,display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${a.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600},children:"Test Suites"}),e.jsx("button",{onClick:()=>U(!0),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${a.border}`,background:"transparent",color:a.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[k.map(p=>e.jsxs("div",{onClick:()=>{M(p.id),_(null)},style:{padding:12,background:j===p.id?a.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${j===p.id?a.border:"transparent"}`},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:p.name}),e.jsxs("div",{style:{fontSize:10,color:a.textMuted,marginTop:4},children:[p.componentName," • ",p.tests.length," test",p.tests.length!==1?"s":""]})]},p.id)),F&&e.jsxs("div",{style:{padding:12,background:a.cardBg,borderRadius:6,border:"1px solid var(--nice-primary, #3b82f6)"},children:[e.jsx("input",{type:"text",value:l,onChange:p=>z(p.target.value),placeholder:"Suite name...",autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${a.border}`,background:a.bg,color:a.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:p=>p.key==="Enter"&&Y()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>U(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${a.border}`,background:"transparent",color:a.text,cursor:"pointer",fontSize:11},children:"Cancel"}),e.jsx("button",{onClick:Y,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:"Add"})]})]})]})]}):void 0;return e.jsx(ae.NiceAppShell,{flush:!0,className:`nice-test-builder ${C||""}`,style:{background:a.bg,color:a.text,fontFamily:"system-ui, sans-serif",...i},"data-testid":m,menubar:ee,sidebar:W,children:e.jsxs("div",{style:{display:"flex",height:"100%",overflow:"hidden"},children:[(B==="visual"||B==="split")&&I&&e.jsxs("div",{style:{flex:B==="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:I.name,onChange:p=>R(I.id,{name:p.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${a.border}`,background:a.cardBg,color:a.text,fontSize:16,fontWeight:600}}),e.jsxs("button",{onClick:()=>b?.(I.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${a.border}`,background:"transparent",color:a.text,cursor:"pointer",fontSize:12},children:[e.jsx(s.NiceIcon,{name:"play",size:14})," Run Suite"]}),e.jsx("button",{onClick:()=>c(I.id),"aria-label":"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:a.textMuted,marginBottom:6},children:"Component"}),e.jsx("input",{type:"text",value:I.componentName,onChange:p=>R(I.id,{componentName:p.target.value}),style:{width:200,padding:8,borderRadius:4,border:`1px solid ${a.border}`,background:a.cardBg,color:a.text,fontSize:13}})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[I.tests.map((p,K)=>{const Z=A.has(p.id),X={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:a.cardBg,borderRadius:8,border:`1px solid ${q===p.id?"var(--nice-color-primary, #3b82f6)":a.border}`,overflow:"hidden"},children:[e.jsxs("div",{style:{padding:12,display:"flex",alignItems:"center",gap:8,cursor:"pointer",borderLeft:`4px solid ${X[p.type].color}`},onClick:()=>{_(p.id),H(D=>{const f=new Set(D);return f.has(p.id)?f.delete(p.id):f.add(p.id),f})},children:[e.jsx("span",{children:e.jsx(s.NiceIcon,{name:X[p.type].icon,size:14})}),e.jsxs("span",{style:{fontWeight:500,opacity:p.skip?.5:1},children:[K+1,". ",p.name]}),p.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:"SKIPPED"}),p.only&&e.jsx("span",{style:{padding:"2px 6px",background:"#8b5cf630",color:"var(--nice-color-accent, #8b5cf6)",borderRadius:4,fontSize:10},children:"ONLY"}),e.jsxs("span",{style:{marginLeft:"auto",fontSize:11,color:a.textMuted},children:[p.steps.length," step",p.steps.length!==1?"s":""]}),e.jsx("span",{style:{color:a.textMuted},children:e.jsx(s.NiceIcon,{name:Z?"chevron-down":"chevron-right",size:14})})]}),Z&&e.jsxs("div",{style:{padding:16,borderTop:`1px solid ${a.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:a.textMuted,marginBottom:4},children:"Test Name"}),e.jsx("input",{type:"text",value:p.name,onChange:D=>t(p.id,{name:D.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${a.border}`,background:a.bg,color:a.text,fontSize:12,boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:a.textMuted,marginBottom:4},children:"Type"}),e.jsxs("select",{value:p.type,onChange:D=>t(p.id,{type:D.target.value}),style:{padding:8,borderRadius:4,border:`1px solid ${a.border}`,background:a.bg,color:a.text,fontSize:12},children:[e.jsx("option",{value:"unit",children:"Unit"}),e.jsx("option",{value:"integration",children:"Integration"}),e.jsx("option",{value:"e2e",children:"E2E"}),e.jsx("option",{value:"snapshot",children:"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:p.skip??!1,onChange:D=>t(p.id,{skip:D.target.checked,only:!1})}),"Skip"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:p.only??!1,onChange:D=>t(p.id,{only:D.target.checked,skip:!1})}),"Only"]})]})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,color:a.textMuted,marginBottom:8},children:"Steps"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:p.steps.map((D,f)=>{const P=fe[D.action];return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:10,background:a.bg,borderRadius:6,borderLeft:`3px solid ${P.color}`},children:[e.jsx("span",{style:{width:20,textAlign:"center",fontSize:11,color:a.textMuted},children:f+1}),e.jsx("span",{children:e.jsx(s.NiceIcon,{name:P.icon,size:14})}),e.jsx("select",{value:D.action,onChange:L=>o(p.id,D.id,{action:L.target.value}),style:{padding:6,borderRadius:4,border:`1px solid ${a.border}`,background:a.cardBg,color:a.text,fontSize:11},children:Object.entries(fe).map(([L,V])=>e.jsx("option",{value:L,children:V.label},L))}),P.hasTarget&&e.jsx("input",{type:"text",value:D.target??"",onChange:L=>o(p.id,D.id,{target:L.target.value}),placeholder:"Target selector",style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${a.border}`,background:a.cardBg,color:a.text,fontSize:11}}),P.hasValue&&D.action!=="assert"&&e.jsx("input",{type:"text",value:typeof D.value=="string"?D.value:"",onChange:L=>o(p.id,D.id,{value:L.target.value}),placeholder:"Value",style:{width:120,padding:6,borderRadius:4,border:`1px solid ${a.border}`,background:a.cardBg,color:a.text,fontSize:11}}),e.jsx("button",{onClick:()=>N(p.id,D.id),"aria-label":"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})})]},D.id)})})]}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:Object.entries(fe).slice(0,8).map(([D,f])=>e.jsxs("button",{onClick:()=>h(p.id,D),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${f.color}40`,background:`${f.color}20`,color:a.text,cursor:"pointer",fontSize:10},children:[e.jsx(s.NiceIcon,{name:f.icon,size:14})," ",f.label]},D))}),e.jsx("div",{style:{marginTop:16,display:"flex",gap:8},children:e.jsxs("button",{onClick:()=>d(p.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})," Delete Test"]})})]})]},p.id)}),e.jsx("button",{onClick:n,style:{padding:16,borderRadius:8,border:`1px dashed ${a.border}`,background:"transparent",color:a.textMuted,cursor:"pointer",fontSize:13},children:"+ Add Test"})]})]}),(B==="code"||B==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"var(--nice-bg-canvas, #0d1117)",borderLeft:B==="split"?`1px solid ${a.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:G})})]})})},Dt=Object.freeze(Object.defineProperty({__proto__:null,NiceTestBuilder:Ke},Symbol.toStringTag,{value:"Module"})),Et=[],Mt=[{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
|
+
`}]}]}],Pe=(r,S,y)=>{let v=r;Object.entries(S).forEach(([w,u])=>{const C=new RegExp(`\\{\\{\\s*${w}\\s*\\}\\}`,"g");v=v.replace(C,String(u));const i=new RegExp(`\\{\\{\\s*pascalCase\\s+${w}\\s*\\}\\}`,"g");if(typeof u=="string"){const m=u.charAt(0).toUpperCase()+u.slice(1);v=v.replace(i,m)}});const $=/\{\{#if\s+([^}]+)\}\}([\s\S]*?)\{\{\/if\}\}/g;v=v.replace($,(w,u,C)=>{const i=u.trim(),m=i.match(/(\w+)\s*===?\s*(\w+|true|false|'[^']*'|"[^"]*")/);if(m){const[,E,j]=m,M=S[E];let q=j;return j==="true"?q=!0:j==="false"?q=!1:(j.startsWith("'")||j.startsWith('"'))&&(q=j.slice(1,-1)),M===q?C:""}return S[i]?C:""});const b=/\{\{#if\s+\(includes\s+(\w+)\s+'([^']+)'\)\}\}([\s\S]*?)\{\{\/if\}\}/g;return v=v.replace(b,(w,u,C,i)=>{const m=S[u];return Array.isArray(m)&&m.includes(C)?i:""}),v},Ft=(r,S)=>{try{const y=r.split(/\s*(===|!==|==|!=)\s*/);if(y.length===3){const[v,$,b]=y,w=S[v.trim()],u=b.trim();let C=u;switch(u==="true"?C=!0:u==="false"?C=!1:(u.startsWith("'")||u.startsWith('"'))&&(C=u.slice(1,-1)),$){case"===":case"==":return w===C;case"!==":case"!=":return w!==C}}return!!S[r.trim()]}catch{return!0}},Ge=({templates:r,defaultTemplates:S,onTemplatesChange:y,presets:v=Mt,selectedTemplate:$,defaultSelectedTemplate:b,onSelectedTemplateChange:w,defaultEngine:u="handlebars",showLibrary:C=!0,onTemplateSelect:i,onTemplateCreate:m,onTemplateUpdate:k,onTemplateDelete:E,onGenerate:j,onExport:M,onImport:q,className:_,style:B,"data-testid":O="nice-code-template"})=>{const F=r!==void 0&&y!==void 0,[U,l]=s.useControllableState({value:F?r:void 0,defaultValue:F?S:S??r,fallbackValue:Et,onChange:y,componentName:"NiceCodeTemplate"});ae.useIgnoredPropChangeWarning("NiceCodeTemplate","templates","onTemplatesChange",r,F);const z=$!==void 0&&w!==void 0,[A,H]=s.useControllableState({value:z?$:void 0,defaultValue:z?b:b??$,fallbackValue:null,onChange:w,componentName:"NiceCodeTemplate"});ae.useIgnoredPropChangeWarning("NiceCodeTemplate","selectedTemplate","onSelectedTemplateChange",$,z);const[I,G]=g.useState({}),[R,Y]=g.useState("editor"),[c,n]=g.useState(null),[t,d]=g.useState(!1),[h,o]=g.useState(!1),N=g.useMemo(()=>{const f=v.flatMap(P=>P.templates);return[...U,...f]},[U,v]),a=g.useMemo(()=>N.find(f=>f.id===A),[N,A]),Q=g.useMemo(()=>a?.files.find(f=>f.id===c)||a?.files[0],[a,c]);g.useEffect(()=>{if(a){const f={};a.variables.forEach(P=>{f[P.name]=P.defaultValue??""}),G(f),n(a.files[0]?.id||null)}},[a]);const ee=g.useMemo(()=>a?a.files.filter(f=>f.condition?Ft(f.condition,I):!0).map(f=>({path:Pe(`${f.path}/${f.name}`,I,a.engine),content:Pe(f.content,I,a.engine),language:f.language})):[],[a,I]),x=g.useCallback(f=>{H(f.id),i?.(f)},[i,H]),W=g.useCallback(()=>{j?.(ee,I)},[ee,I,j]),p=g.useCallback(()=>{const f={id:crypto.randomUUID(),name:"New Template",description:"Custom template",category:"custom",icon:"file",engine:u,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}} = {};`}]};l(P=>[...P,f]),H(f.id),d(!1),m?.(f)},[u,m,l,H]),K=g.useCallback((f,P)=>{if(!a)return;const L={...a,files:a.files.map(V=>V.id===f?{...V,content:P}:V)};l(V=>V.map(oe=>oe.id===L.id?L:oe)),k?.(L)},[a,k,l]),Z=g.useCallback(()=>{if(!a)return;const f={id:crypto.randomUUID(),name:"new-file.ts",path:"src",language:"typescript",content:`// New file
|
|
331
|
+
`},P={...a,files:[...a.files,f]};l(L=>L.map(V=>V.id===P.id?P:V)),n(f.id),k?.(P)},[a,k,l]),X=g.useCallback(f=>{if(!a)return;const P={...a,files:a.files.filter(L=>L.id!==f)};l(L=>L.map(V=>V.id===P.id?P:V)),n(P.files[0]?.id||null),k?.(P)},[a,k,l]),D=f=>{const P=I[f.name];switch(f.type){case"boolean":return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!P,onChange:L=>G(V=>({...V,[f.name]:L.target.checked}))}),e.jsx("span",{children:f.name})]});case"select":return e.jsx("select",{value:String(P),onChange:L=>G(V=>({...V,[f.name]:L.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:f.options?.map(L=>e.jsx("option",{value:L,children:L},L))});case"array":return e.jsx("input",{type:"text",value:Array.isArray(P)?P.join(", "):"",onChange:L=>G(V=>({...V,[f.name]:L.target.value.split(",").map(oe=>oe.trim())})),placeholder:"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(P),onChange:L=>G(V=>({...V,[f.name]:Number(L.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(P??""),onChange:L=>G(V=>({...V,[f.name]:L.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 ${_||""}`,style:{display:"flex",height:"100%",background:"var(--nice-bg-canvas, #0d1117)",color:"var(--nice-text-primary, #e6edf3)",fontFamily:"system-ui, sans-serif",...B},"data-testid":O,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})," Templates"]}),e.jsx("button",{onClick:p,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:"+ New"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[U.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:"CUSTOM"}),U.map(f=>e.jsxs("div",{onClick:()=>x(f),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:A===f.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:f.icon||"file",size:16}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:f.name}),e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)"},children:f.category})]})]},f.id))]}),v.map(f=>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:f.icon,size:12}),f.name.toUpperCase()]}),f.templates.map(P=>e.jsxs("div",{onClick:()=>x(P),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:A===P.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:P.icon||"file",size:16}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:P.name}),e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #8b949e)"},children:P.description})]})]},P.id))]},f.id))]})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:a?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:a.icon||"file",size:24}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:a.name}),e.jsx("div",{style:{fontSize:12,color:"var(--nice-text-muted, #8b949e)"},children:a.description})]})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsxs("button",{onClick:()=>M?.(a,"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})," Export"]}),e.jsxs("button",{onClick:W,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})," 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(f=>e.jsxs("button",{onClick:()=>Y(f),style:{padding:"10px 20px",background:R===f?"var(--nice-bg-canvas, #0d1117)":"transparent",border:"none",borderBottom:R===f?"2px solid var(--nice-primary, #3b82f6)":"2px solid transparent",color:R===f?"var(--nice-text-primary, #fff)":"var(--nice-text-muted, #8b949e)",cursor:"pointer",textTransform:"capitalize"},children:[f==="variables"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"settings",size:14})," "]}),f==="editor"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"edit",size:14})," "]}),f==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(s.NiceIcon,{name:"eye",size:14})," "]}),f]},f))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[R==="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:"Template Variables"}),a.variables.map(f=>e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("label",{style:{display:"block",fontSize:12,color:"var(--nice-text-muted, #8b949e)",marginBottom:4},children:[f.name,f.required&&e.jsx("span",{style:{color:"var(--nice-color-error, #ef4444)"},children:" *"})]}),D(f),f.description&&e.jsx("div",{style:{fontSize:11,color:"var(--nice-text-muted, #6b7280)",marginTop:4},children:f.description})]},f.id))]})}),R==="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:"Files"}),e.jsx("button",{onClick:Z,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:a.files.map(f=>e.jsxs("div",{onClick:()=>n(f.id),style:{padding:"8px 12px",cursor:"pointer",background:c===f.id?"var(--nice-primary-tint-15, rgba(59, 130, 246, 0.15))":"transparent",borderLeft:c===f.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:f.name}),e.jsx("button",{"aria-label":"Remove file",onClick:P=>{P.stopPropagation(),X(f.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})})]},f.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.jsxs("span",{style:{color:"var(--nice-color-warning, #f59e0b)",marginLeft:8},children:["(if: ",Q.condition,")"]})]}),e.jsx("textarea",{value:Q.content,onChange:f=>K(Q.id,f.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"}})]})})]}),R==="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.jsxs("span",{style:{fontSize:12,color:"var(--nice-text-muted, #8b949e)"},children:[ee.length," file(s) will be generated"]})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:ee.map((f,P)=>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})," ",f.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:f.content})]},P))})]})]})]}):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:"Select a template"}),e.jsx("span",{style:{fontSize:12,marginTop:4},children:"Choose from the library or create a new template"}),e.jsxs("button",{onClick:p,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})," Create Template"]})]})})]})},At=Object.freeze(Object.defineProperty({__proto__:null,NiceCodeTemplate:Ge},Symbol.toStringTag,{value:"Module"}));exports.NiceAPIFlow=He;exports.NiceAPIFlow$1=jt;exports.NiceCheckbox=ye;exports.NiceCheckbox$1=it;exports.NiceCodePreview=Oe;exports.NiceCodeTemplate=Ge;exports.NiceCodeTemplate$1=At;exports.NiceComponentDesigner=ut;exports.NiceDataMapper=We;exports.NiceDataMapper$1=wt;exports.NiceEventOrchestrator=Je;exports.NiceEventOrchestrator$1=Tt;exports.NiceLowCodeStudio=ct;exports.NiceNumberInput=be;exports.NiceNumberInput$1=rt;exports.NicePageBuilder=xt;exports.NiceStateDesigner=Ve;exports.NiceStateDesigner$1=yt;exports.NiceTestBuilder=Ke;exports.NiceTestBuilder$1=Dt;exports.NiceTextInput=ve;exports.NiceTextInput$1=ot;
|