@codeyam/codeyam-cli 0.1.11 → 0.1.13
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/analyzer-template/.build-info.json +8 -8
- package/analyzer-template/log.txt +3 -3
- package/analyzer-template/package.json +2 -2
- package/analyzer-template/packages/ai/package.json +1 -1
- package/analyzer-template/packages/aws/package.json +1 -1
- package/analyzer-template/packages/database/package.json +1 -1
- package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +42 -16
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +3 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +44 -16
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -1
- package/codeyam-cli/src/cli.js +9 -0
- package/codeyam-cli/src/cli.js.map +1 -1
- package/codeyam-cli/src/commands/__tests__/editor.isolateArgs.test.js +51 -0
- package/codeyam-cli/src/commands/__tests__/editor.isolateArgs.test.js.map +1 -0
- package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js +11 -0
- package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js.map +1 -1
- package/codeyam-cli/src/commands/editor.js +1360 -201
- package/codeyam-cli/src/commands/editor.js.map +1 -1
- package/codeyam-cli/src/commands/editorIsolateArgs.js +25 -0
- package/codeyam-cli/src/commands/editorIsolateArgs.js.map +1 -0
- package/codeyam-cli/src/commands/telemetry.js +37 -0
- package/codeyam-cli/src/commands/telemetry.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +893 -1
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js +76 -0
- package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js +100 -0
- package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js +76 -3
- package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js +261 -0
- package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js +75 -1
- package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorMigration.test.js +435 -0
- package/codeyam-cli/src/utils/__tests__/editorMigration.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +441 -17
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +67 -0
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js +143 -0
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js +66 -0
- package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js +53 -0
- package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +67 -9
- package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js +118 -0
- package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js +40 -1
- package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/telemetry.test.js +159 -0
- package/codeyam-cli/src/utils/__tests__/telemetry.test.js.map +1 -0
- package/codeyam-cli/src/utils/analysisRunner.js +3 -1
- package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
- package/codeyam-cli/src/utils/editorAudit.js +145 -0
- package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
- package/codeyam-cli/src/utils/editorBroadcastViewport.js +26 -0
- package/codeyam-cli/src/utils/editorBroadcastViewport.js.map +1 -0
- package/codeyam-cli/src/utils/editorDeleteScenario.js +67 -0
- package/codeyam-cli/src/utils/editorDeleteScenario.js.map +1 -0
- package/codeyam-cli/src/utils/editorEntityChangeStatus.js +13 -7
- package/codeyam-cli/src/utils/editorEntityChangeStatus.js.map +1 -1
- package/codeyam-cli/src/utils/editorEntityHelpers.js +129 -0
- package/codeyam-cli/src/utils/editorEntityHelpers.js.map +1 -0
- package/codeyam-cli/src/utils/editorLoaderHelpers.js +40 -1
- package/codeyam-cli/src/utils/editorLoaderHelpers.js.map +1 -1
- package/codeyam-cli/src/utils/editorMigration.js +224 -0
- package/codeyam-cli/src/utils/editorMigration.js.map +1 -0
- package/codeyam-cli/src/utils/editorScenarios.js +163 -2
- package/codeyam-cli/src/utils/editorScenarios.js.map +1 -1
- package/codeyam-cli/src/utils/editorSeedAdapter.js +253 -4
- package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -1
- package/codeyam-cli/src/utils/editorShouldRevalidate.js +21 -0
- package/codeyam-cli/src/utils/editorShouldRevalidate.js.map +1 -0
- package/codeyam-cli/src/utils/entityChangeStatus.js +19 -2
- package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -1
- package/codeyam-cli/src/utils/entityChangeStatus.server.js +7 -3
- package/codeyam-cli/src/utils/entityChangeStatus.server.js.map +1 -1
- package/codeyam-cli/src/utils/fileWatcher.js +38 -0
- package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
- package/codeyam-cli/src/utils/install-skills.js +9 -0
- package/codeyam-cli/src/utils/install-skills.js.map +1 -1
- package/codeyam-cli/src/utils/routePatternMatching.js +129 -0
- package/codeyam-cli/src/utils/routePatternMatching.js.map +1 -0
- package/codeyam-cli/src/utils/scenarioCoverage.js +8 -9
- package/codeyam-cli/src/utils/scenarioCoverage.js.map +1 -1
- package/codeyam-cli/src/utils/scenariosManifest.js +18 -10
- package/codeyam-cli/src/utils/scenariosManifest.js.map +1 -1
- package/codeyam-cli/src/utils/telemetry.js +106 -0
- package/codeyam-cli/src/utils/telemetry.js.map +1 -0
- package/codeyam-cli/src/utils/telemetryMiddleware.js +22 -0
- package/codeyam-cli/src/utils/telemetryMiddleware.js.map +1 -0
- package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js +35 -0
- package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js.map +1 -0
- package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js +61 -0
- package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js.map +1 -1
- package/codeyam-cli/src/webserver/app/types/editor.js +8 -0
- package/codeyam-cli/src/webserver/app/types/editor.js.map +1 -0
- package/codeyam-cli/src/webserver/backgroundServer.js +18 -4
- package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CzTDWkF2.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-BcgbViKV.js → EntityItem-BFbq6iFk.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CQgyEGV-.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-CQIG2qda.js → EntityTypeIcon-B6OMi58N.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-DuYodzo1.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-CXo9EeCl.js +25 -0
- package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DYCNb2It.js +3 -0
- package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-BU_OAEMP.js → LoadingDots-By5zI316.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-ceAyBX-H.js → LogViewer-CZgY3sxX.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-BzHcG7SE.js → ReportIssueModal-CnYYwRDw.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-CDoF7ZpU.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-TSD3C211.js → ScenarioViewer-DrnfvaLL.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/Spinner-Df3UCi8k.js +34 -0
- package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CK7-NaPZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-DRKR9T0U.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{_index-DLxKhri3.js → _index-ClR-g3tY.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BcY3q6nt.js → activity.(_tab)-DTH6ydEA.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{addon-web-links-Duc5hnl7.js → addon-web-links-74hnHF59.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{agent-transcripts-Bni3iiUj.js → agent-transcripts-B8CYhCO9.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-rename-scenario-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-seed-state-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-prompt-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{book-open-BYOypzCa.js → book-open-CLaoh4ac.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-C_Pmso5S.js → chevron-down-BZ2DZxbW.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{chunk-JZWAC4HX-C4pqxYJB.js → chunk-JZWAC4HX-BBXArFPl.js} +13 -21
- package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BVMi9VA5.js → circle-check-CT4unAk-.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{copy-n2FB0_Sw.js → copy-zK0B6Nu-.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-CC6AbExI.js → createLucideIcon-DJB0YQJL.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-CkXFP_i-.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor._tab-DPw7NZHc.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-CjC3_6JI.js +58 -0
- package/codeyam-cli/src/webserver/build/client/assets/editorPreview-DBa7T2FK.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-DwCV5__E.js → entity._sha._-BqAN7hyG.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-BOi8kpwd.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-Dg1NhIms.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-CJX6kkkV.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-BMvVHNXU.js → entity._sha_.edit._scenarioId-BhVjZhKg.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{entry.client-DTvKq3TY.js → entry.client-_gzKltPN.js} +6 -6
- package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-Daa96Fr1.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/files-CV_17tZS.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/git-D-YXmMbR.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/globals-DRvOjyO3.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{index-yHOVb4rc.js → index-Blo6EK8G.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{index-10oVnAAH.js → index-BsX0F-9C.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{index-BcvgDzbZ.js → index-CCrgCshv.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/jsx-runtime-D_zvdyIk.js +9 -0
- package/codeyam-cli/src/webserver/build/client/assets/labs-Byazq8Pv.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-DaAZ_H2w.js → loader-circle-DVQ0oHR7.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-75b1b319.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{memory-9gnxSZlb.js → memory-b-VmA2Vj.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{pause-f5-1lKBt.js → pause-DGcndCAa.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{root-DBjt6o04.js → root-F-k2uYj5.js} +15 -15
- package/codeyam-cli/src/webserver/build/client/assets/{search-Di64LWVb.js → search-C0Uw0bcK.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/settings-OoNgHIfW.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/simulations-Bcemfu8a.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{terminal-Br7MOqts.js → terminal-BgMmG7R9.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-BLdiCuG-.js → triangle-alert-Cs87hJYK.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-BR3Rs7JY.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-C14nCb1q.js → useLastLogLine-BxxP_XF9.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/useReportContext-BermyNU5.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/useToast-a_QN_W9_.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/analysisRunner-lv2ooewK.js +13 -0
- package/codeyam-cli/src/webserver/build/server/assets/{index-DsZjKspK.js → index-Im3Smyei.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/init-BjuAFKGM.js +10 -0
- package/codeyam-cli/src/webserver/build/server/assets/progress-CHTtrxFG.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/server-build-CNjF0B9B.js +551 -0
- package/codeyam-cli/src/webserver/build/server/index.js +1 -1
- package/codeyam-cli/src/webserver/build-info.json +5 -5
- package/codeyam-cli/src/webserver/editorProxy.js +112 -13
- package/codeyam-cli/src/webserver/editorProxy.js.map +1 -1
- package/codeyam-cli/src/webserver/mockStateEvents.js +28 -0
- package/codeyam-cli/src/webserver/mockStateEvents.js.map +1 -0
- package/codeyam-cli/src/webserver/server.js +41 -0
- package/codeyam-cli/src/webserver/server.js.map +1 -1
- package/codeyam-cli/src/webserver/terminalServer.js +74 -8
- package/codeyam-cli/src/webserver/terminalServer.js.map +1 -1
- package/codeyam-cli/templates/editor-step-hook.py +104 -20
- package/codeyam-cli/templates/nextjs-prisma-sqlite/seed-adapter.ts +42 -7
- package/codeyam-cli/templates/seed-adapters/supabase.ts +282 -0
- package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +62 -0
- package/package.json +2 -1
- package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +44 -16
- package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/CopyButton-BPXZwM4t.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-g3saevPb.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-Bu6c6aDe.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-DYFW3lDD.js +0 -25
- package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DLeucoVX.js +0 -3
- package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-BED4B6sP.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bb5uFQ5V.js +0 -34
- package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-C8OKAR5x.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-oAf2Kqsf.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-Ii3inc0_.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/editor-16o0AIFV.js +0 -15
- package/codeyam-cli/src/webserver/build/client/assets/editorPreview-7Uga8I59.js +0 -41
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-BwKcai0j.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-CHMiAog3.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-p9hhkjJM.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-cPo8LiG3.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/files-BZrlFE1F.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/git-DdZcvjGh.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/globals-CQPR0pFR.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/labs-Zk7ryIM1.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-76e7b62c.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/settings-0OrEMU6J.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/simulations-DWT-CvLy.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-C-_hOl_g.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useReportContext-O-jkvSPx.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useToast-9FIWuYfK.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/init-DdqKD2p4.js +0 -10
- package/codeyam-cli/src/webserver/build/server/assets/server-build-CKKeWtVK.js +0 -444
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as V,w as re,u as oe,r as i}from"./chunk-JZWAC4HX-BBXArFPl.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as le,S as W}from"./Spinner-Df3UCi8k.js";import{u as ce}from"./useLastLogLine-BxxP_XF9.js";import{V as de}from"./ViewportInspectBar-DRKR9T0U.js";import{u as he,S as xe}from"./useCustomSizes-BR3Rs7JY.js";import{c as me}from"./cy-logo-cli-DcX-ZS3p.js";import{I as E}from"./InlineSpinner-DuYodzo1.js";import{a as ue,T as pe,D as ge}from"./editorPreview-DBa7T2FK.js";import{S as fe}from"./SafeScreenshot-CDoF7ZpU.js";import"./preload-helper-ckwbz45p.js";function ve({scenarios:w,currentScenarioId:r,entitySha:s,cacheBuster:l}){const c=V();return w.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:e.jsx("p",{className:"text-gray-500 text-sm",children:"No scenarios found"})}):e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:w.map(o=>{var j,u;const g=o.id===r,f=(u=(j=o.metadata)==null?void 0:j.screenshotPaths)==null?void 0:u[0];return e.jsxs("button",{onClick:()=>{c(`/entity/${s}/scenarios/${o.id}/dev`)},className:`w-full text-left rounded-lg overflow-hidden border transition-colors cursor-pointer flex ${g?"border-[#005c75] bg-[#1a3a44]":"border-[#3d3d3d] bg-[#252525] hover:border-[#555]"}`,children:[e.jsx("div",{className:"w-24 h-20 shrink-0 bg-[#1a1a1a]",children:e.jsx(fe,{screenshotPath:f,cacheBuster:l,alt:o.name,className:"w-full h-full object-cover object-top"})}),e.jsxs("div",{className:"p-2.5 min-w-0 flex-1",children:[e.jsxs("div",{className:"text-white text-sm font-medium truncate",children:[g&&e.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-[#005c75] mr-1.5 relative top-[-1px]"}),o.name]}),o.description&&e.jsx("div",{className:"text-gray-400 text-xs mt-1 line-clamp-2",children:o.description})]})]},o.id)})})}const I=[{name:"Mobile",width:375,height:667},{name:"Tablet",width:768,height:1024},{name:"Laptop",width:1024,height:768},{name:"Desktop",width:1440,height:900}],De=re(function(){const{entity:r,scenario:s,analysis:l,projectSlug:c}=oe(),o=V(),g=i.useRef(null),f=i.useRef(null),[j,u]=i.useState(null),[A,M]=i.useState(1440),[n,N]=i.useState({name:"Desktop",width:1440,height:900}),[H,y]=i.useState(!1),[S,U]=i.useState(null),[d,k]=i.useState("chat"),[F,q]=i.useState(0),[D,$]=i.useState(null),K=i.useCallback(t=>{$(t||null),q(a=>a+1)},[]),{customSizes:_,addCustomSize:Y}=he(c),v=i.useMemo(()=>[...I,..._],[_]),{interactiveServerUrl:h,isStarting:C,isLoading:z,showIframe:B,iframeKey:G,onIframeLoad:J}=le({analysisId:l==null?void 0:l.id,scenarioId:s==null?void 0:s.id,scenarioName:s==null?void 0:s.name,projectSlug:c,enabled:!0,refreshTrigger:F}),O=i.useMemo(()=>ue(h,D),[h,D]),{lastLine:b}=ce(c,C||z),Q=()=>{o(`/entity/${r.sha}`)},X=(t,a)=>{M(t);const m=v.find(T=>T.width===t&&T.height===a);u(m||null),N({name:(m==null?void 0:m.name)||"Custom",width:t,height:a})},R=t=>{u(t),M(t.width),N({name:t.name,width:t.width,height:t.height})},Z=t=>{Y(t,n.width,n.height??900),y(!1),N(a=>({...a,name:t}))},ee=()=>{var a;k("chat"),(a=f.current)==null||a.sendInput("Create a new scenario for this entity based on the work we've just done. Create a name and description that reflects what the live preview is showing. Use the scenario data you've changed to create a new scenario in the database. If the data structure was fixed in any way you need to update that in the database as well and backfill all existing scenarios, then save to the database and capture a screenshot. Remember the database is at `.codeyam/db.sqlite3`, the scenarios table has all scenarios and the analyses table contains the scenariosDataStructure is its metadata.")},x=((l==null?void 0:l.scenarios)||[]).filter(t=>{var a;return!((a=t.metadata)!=null&&a.sameAsDefault)}),p=x.findIndex(t=>t.id===(s==null?void 0:s.id)),te=p+1,se=x.length,L=p>0,P=p<x.length-1,ae=()=>{if(L){const t=x[p-1];o(`/entity/${r.sha}/scenarios/${t.id}/dev`)}},ne=()=>{if(P){const t=x[p+1];o(`/entity/${r.sha}/scenarios/${t.id}/dev`)}},ie=C||z||!B;return e.jsxs("div",{className:"fixed inset-0 bg-[#2d2d2d] flex flex-col",children:[e.jsxs("div",{className:"bg-[#3d3d3d] h-12 flex items-center px-4 gap-4 shrink-0 z-20",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("img",{src:me,alt:"CodeYam",className:"h-6 brightness-0 invert"}),e.jsx("span",{className:"text-white font-medium text-sm whitespace-nowrap",children:r.name}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{onClick:ae,disabled:!L,className:`${L?"text-white hover:text-gray-300":"text-gray-600 cursor-not-allowed"} transition-colors`,"aria-label":"Previous scenario",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 15L7.5 10L12.5 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsxs("span",{className:"text-gray-400 text-sm",children:[te,"/",se]}),e.jsx("button",{onClick:ne,disabled:!P,className:`${P?"text-white hover:text-gray-300":"text-gray-600 cursor-not-allowed"} transition-colors`,"aria-label":"Next scenario",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M7.5 15L12.5 10L7.5 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-2 min-w-0",children:[e.jsx("span",{className:"text-white font-semibold text-xs whitespace-nowrap shrink-0",children:s==null?void 0:s.name}),(s==null?void 0:s.description)&&e.jsxs("div",{className:"relative group min-w-0",children:[e.jsx("span",{className:"text-gray-400 text-xs truncate block",children:s.description}),e.jsx("div",{className:"absolute left-0 top-full mt-1 hidden group-hover:block z-50 bg-black text-white text-xs px-3 py-2 rounded shadow-lg max-w-md",children:s.description})]})]}),e.jsx("span",{className:"bg-[#005c75] text-white text-[10px] font-bold px-2 py-0.5 rounded uppercase tracking-wider ml-2",children:"Dev Mode"})]}),e.jsx("button",{onClick:Q,className:"text-white hover:text-gray-300 transition-colors ml-4","aria-label":"Close dev mode",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M15 5L5 15M5 5L15 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"bg-[#e5e7eb] border-b border-[rgba(0,0,0,0.1)] shrink-0 z-10 h-6 flex items-center justify-center relative",children:[e.jsx("div",{className:"absolute inset-0 flex justify-center",children:e.jsx("div",{style:{maxWidth:`${I[I.length-1].width}px`,width:"100%"},children:e.jsx(de,{currentViewportWidth:A,currentPresetName:n.name,onDevicePresetClick:R,devicePresets:v,hideLabel:!0,onHoverChange:U,lightMode:!0})})}),e.jsxs("div",{className:"relative z-10 flex items-center gap-2",children:[e.jsxs("div",{className:"relative w-28 h-5",children:[e.jsxs("div",{className:"absolute inset-0 bg-white text-gray-900 text-xs px-2 rounded flex items-center justify-between pointer-events-none border border-gray-300",children:[e.jsx("span",{className:"leading-none",children:(S==null?void 0:S.name)||n.name}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:"shrink-0",children:e.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsxs("select",{value:n.name,onChange:t=>{const a=v.find(m=>m.name===t.target.value);a&&R(a)},className:"relative w-full h-full opacity-0 cursor-pointer",children:[v.map(t=>e.jsx("option",{value:t.name,children:t.name},t.name)),n.name==="Custom"&&e.jsx("option",{value:"Custom",children:"Custom"})]})]}),e.jsx("input",{type:"number",value:n.width,onChange:t=>{const a=parseInt(t.target.value,10);!isNaN(a)&&a>0&&X(a,n.height??900)},className:"bg-white text-gray-900 text-xs px-1 rounded border border-gray-300 outline-none w-16 text-center h-5 leading-none",min:"200",max:"3840"}),e.jsx("span",{className:"text-gray-400 text-xs h-5 flex items-center leading-none",children:"x"}),e.jsx("span",{className:"bg-gray-100 text-gray-600 text-xs px-1 rounded w-14 text-center h-5 flex items-center justify-center leading-none",children:n.height??900}),n.name==="Custom"&&e.jsx("button",{onClick:()=>y(!0),className:"bg-white text-gray-900 text-xs px-2 rounded h-5 flex items-center leading-none border border-gray-300 hover:bg-gray-50 transition-colors",children:"Save"})]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center overflow-auto p-8",style:{backgroundImage:`
|
|
2
|
+
linear-gradient(45deg, #ebebeb 25%, transparent 25%),
|
|
3
|
+
linear-gradient(-45deg, #ebebeb 25%, transparent 25%),
|
|
4
|
+
linear-gradient(45deg, transparent 75%, #ebebeb 75%),
|
|
5
|
+
linear-gradient(-45deg, transparent 75%, #ebebeb 75%)
|
|
6
|
+
`,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#fafafa"},children:h?e.jsxs("div",{className:"relative bg-white w-full h-full",style:{maxWidth:`${n.width}px`,maxHeight:`${n.height}px`},children:[ie&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 bg-white rounded-lg p-8 shadow-sm w-[500px] h-[300px]",children:[e.jsx("div",{className:"mb-4",children:e.jsx(W,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-black leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Loading Preview"}),e.jsx("p",{className:"text-sm text-[#666] leading-5 m-0 font-['IBM_Plex_Sans']",children:"Waiting for the dev server to be ready"}),b&&e.jsxs("p",{className:"text-xs font-mono text-[#005c75] text-center leading-5 m-0 mt-3 font-['IBM_Plex_Mono'] uppercase",children:[e.jsx(E,{}),b]})]})]})}),e.jsx("iframe",{ref:g,src:O||h,className:"w-full h-full border-none",title:`Dev mode preview: ${s==null?void 0:s.name}`,onLoad:J,style:{opacity:B?1:0}},G)]}):e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 w-[500px] h-[300px] bg-white rounded-lg p-8 shadow-sm",children:[e.jsx("div",{className:"mb-4",children:e.jsx(W,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-black leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Starting Dev Mode"}),e.jsx("p",{className:"text-sm text-[#666] leading-5 m-0 font-['IBM_Plex_Sans']",children:"Setting up a sandboxed environment with live preview"}),b&&e.jsxs("p",{className:"text-xs font-mono text-[#005c75] text-center leading-5 m-0 mt-3 font-['IBM_Plex_Mono'] uppercase",children:[e.jsx(E,{}),b]})]})]})})]}),e.jsxs("aside",{className:"w-[50%] min-w-[400px] max-w-[800px] bg-[#1e1e1e] border-l border-[#3d3d3d] shrink-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"border-b border-[#3d3d3d] px-4 shrink-0 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-0",children:[e.jsxs("button",{onClick:()=>k("chat"),className:`px-3 py-2 text-xs font-medium transition-colors relative cursor-pointer ${d==="chat"?"text-white":"text-gray-500 hover:text-gray-300"}`,children:["Chat",d==="chat"&&e.jsx("span",{className:"absolute bottom-0 left-3 right-3 h-0.5 bg-[#005c75]"})]}),e.jsxs("button",{onClick:()=>k("scenarios"),className:`px-3 py-2 text-xs font-medium transition-colors relative cursor-pointer ${d==="scenarios"?"text-white":"text-gray-500 hover:text-gray-300"}`,children:["Scenarios",d==="scenarios"&&e.jsx("span",{className:"absolute bottom-0 left-3 right-3 h-0.5 bg-[#005c75]"})]})]}),d==="chat"&&e.jsx("button",{onClick:ee,disabled:!h,className:"px-3 py-1 text-[11px] font-medium rounded bg-[#005c75] text-white hover:bg-[#004a5c] transition-colors disabled:bg-gray-600 disabled:text-gray-400 disabled:cursor-not-allowed cursor-pointer",children:"Save Scenario"})]}),e.jsx("div",{style:{display:d==="chat"?"flex":"none"},className:"flex-1 overflow-hidden flex-col",children:e.jsx(pe,{ref:f,entityName:r.name,entityType:r.entityType,entitySha:r.sha,entityFilePath:r.filePath||r.localFilePath,scenarioName:s==null?void 0:s.name,scenarioDescription:s==null?void 0:s.description,analysisId:l==null?void 0:l.id,projectSlug:c,onRefreshPreview:K})}),d==="scenarios"&&e.jsx(ve,{scenarios:x,currentScenarioId:s==null?void 0:s.id,entitySha:r.sha,cacheBuster:0})]})]}),e.jsx(ge,{serverUrl:h,isStarting:C,projectSlug:c}),H&&e.jsx(xe,{width:n.width,height:n.height??900,onSave:Z,onCancel:()=>y(!1)})]})});export{De as default};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{w as X,u as Z,a as ee,b as te,r as i}from"./chunk-JZWAC4HX-BBXArFPl.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as se,S as z}from"./Spinner-Df3UCi8k.js";import{u as ne}from"./useLastLogLine-BxxP_XF9.js";import{V as ae}from"./ViewportInspectBar-DRKR9T0U.js";import{u as ie,S as re}from"./useCustomSizes-BR3Rs7JY.js";import{c as oe}from"./cy-logo-cli-DcX-ZS3p.js";import{I as B}from"./InlineSpinner-DuYodzo1.js";const N=[{name:"Mobile",width:375,height:667},{name:"Tablet",width:768,height:1024},{name:"Laptop",width:1024,height:768},{name:"Desktop",width:1920,height:1080}],ve=X(function(){const{entity:o,scenario:s,analysis:l,projectSlug:p}=Z(),f=ee();te();const[ce,y]=i.useState(null),[E,k]=i.useState(1920),[a,v]=i.useState({name:"Desktop",width:1920,height:1080}),[W,b]=i.useState(!1),[w,D]=i.useState(null),{customSizes:C,addCustomSize:R}=ie(p),h=i.useMemo(()=>[...N,...C],[C]),x=i.useRef(null),[H,U]=i.useState(1),m=i.useCallback(()=>{if(!x.current)return;const t=32,n=x.current.clientWidth-t,r=x.current.clientHeight-t,_=a.width,g=a.height??900,Q=Math.min(1,n/_,r/g);U(Q)},[a.width,a.height]);i.useEffect(()=>(m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)),[m]);const{interactiveServerUrl:L,isStarting:I,isLoading:M,showIframe:P,iframeKey:V,onIframeLoad:T}=se({analysisId:l==null?void 0:l.id,scenarioId:s==null?void 0:s.id,scenarioName:s==null?void 0:s.name,projectSlug:p,enabled:!0}),{lastLine:u}=ne(p,I||M),A=()=>{f(`/entity/${o.sha}`)},F=(t,n)=>{k(t);const r=h.find(g=>g.width===t&&g.height===n);y(r||null),v({name:(r==null?void 0:r.name)||"Custom",width:t,height:n})},$=t=>{y(t),k(t.width),v({name:t.name,width:t.width,height:t.height})},K=t=>{R(t,a.width,a.height??900),b(!1),v(n=>({...n,name:t}))},c=((l==null?void 0:l.scenarios)||[]).filter(t=>{var n;return!((n=t.metadata)!=null&&n.sameAsDefault)}),d=c.findIndex(t=>t.id===(s==null?void 0:s.id)),O=d+1,Y=c.length,j=d>0,S=d<c.length-1,q=()=>{if(j){const t=c[d-1],n=encodeURIComponent(`/entity/${o.sha}/scenarios/${t.id}/fullscreen`);f(`/entity/${o.sha}/scenarios/${t.id}/fullscreen?from=${n}`)}},G=()=>{if(S){const t=c[d+1],n=encodeURIComponent(`/entity/${o.sha}/scenarios/${t.id}/fullscreen`);f(`/entity/${o.sha}/scenarios/${t.id}/fullscreen?from=${n}`)}},J=I||M||!P;return e.jsxs("div",{className:"fixed inset-0 bg-[#2d2d2d] flex flex-col",children:[e.jsxs("div",{className:"bg-[#3d3d3d] h-12 flex items-center px-4 gap-4 shrink-0 z-20",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("img",{src:oe,alt:"CodeYam",className:"h-6 brightness-0 invert"}),e.jsx("span",{className:"text-white font-medium text-sm whitespace-nowrap",children:o.name}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{onClick:q,disabled:!j,className:`${j?"text-white hover:text-gray-300":"text-gray-600 cursor-not-allowed"} transition-colors`,"aria-label":"Previous scenario",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 15L7.5 10L12.5 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsxs("span",{className:"text-gray-400 text-sm",children:[O,"/",Y]}),e.jsx("button",{onClick:G,disabled:!S,className:`${S?"text-white hover:text-gray-300":"text-gray-600 cursor-not-allowed"} transition-colors`,"aria-label":"Next scenario",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M7.5 15L12.5 10L7.5 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-2 min-w-0",children:[e.jsx("span",{className:"text-white font-semibold text-xs whitespace-nowrap shrink-0",children:s==null?void 0:s.name}),(s==null?void 0:s.description)&&e.jsxs("div",{className:"relative group min-w-0",children:[e.jsx("span",{className:"text-gray-400 text-xs truncate block",children:s.description}),e.jsx("div",{className:"absolute left-0 top-full mt-1 hidden group-hover:block z-50 bg-black text-white text-xs px-3 py-2 rounded shadow-lg max-w-md",children:s.description})]})]})]}),e.jsx("button",{onClick:A,className:"text-white hover:text-gray-300 transition-colors ml-4","aria-label":"Close fullscreen",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M15 5L5 15M5 5L15 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),e.jsxs("div",{className:"bg-[#e5e7eb] border-b border-[rgba(0,0,0,0.1)] shrink-0 z-10 h-6 flex items-center justify-center relative",children:[e.jsx("div",{className:"absolute inset-0 flex justify-center",children:e.jsx("div",{style:{maxWidth:`${N[N.length-1].width}px`,width:"100%"},children:e.jsx(ae,{currentViewportWidth:E,currentPresetName:a.name,onDevicePresetClick:$,devicePresets:h,hideLabel:!0,onHoverChange:D,lightMode:!0})})}),e.jsxs("div",{className:"relative z-10 flex items-center gap-2",children:[e.jsxs("div",{className:"relative w-28 h-5",children:[e.jsxs("div",{className:"absolute inset-0 bg-white text-gray-900 text-xs px-2 rounded flex items-center justify-between pointer-events-none border border-gray-300",children:[e.jsx("span",{className:"leading-none",children:(w==null?void 0:w.name)||a.name}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:"shrink-0",children:e.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsxs("select",{value:a.name,onChange:t=>{const n=h.find(r=>r.name===t.target.value);n&&$(n)},className:"relative w-full h-full opacity-0 cursor-pointer",children:[h.map(t=>e.jsx("option",{value:t.name,children:t.name},t.name)),a.name==="Custom"&&e.jsx("option",{value:"Custom",children:"Custom"})]})]}),e.jsx("input",{type:"number",value:a.width,onChange:t=>{const n=parseInt(t.target.value,10);!isNaN(n)&&n>0&&F(n,a.height??900)},className:"bg-white text-gray-900 text-xs px-1 rounded border border-gray-300 outline-none w-16 text-center h-5 leading-none",min:"200",max:"3840"}),e.jsx("span",{className:"text-gray-400 text-xs h-5 flex items-center leading-none",children:"×"}),e.jsx("span",{className:"bg-gray-100 text-gray-600 text-xs px-1 rounded w-14 text-center h-5 flex items-center justify-center leading-none",children:a.height??900}),a.name==="Custom"&&e.jsx("button",{onClick:()=>b(!0),className:"bg-white text-gray-900 text-xs px-2 rounded h-5 flex items-center leading-none border border-gray-300 hover:bg-gray-50 transition-colors",children:"Save"})]})]}),e.jsx("div",{ref:x,className:"flex-1 flex items-center justify-center overflow-hidden p-4",style:{backgroundImage:`
|
|
2
|
+
linear-gradient(45deg, #ebebeb 25%, transparent 25%),
|
|
3
|
+
linear-gradient(-45deg, #ebebeb 25%, transparent 25%),
|
|
4
|
+
linear-gradient(45deg, transparent 75%, #ebebeb 75%),
|
|
5
|
+
linear-gradient(-45deg, transparent 75%, #ebebeb 75%)
|
|
6
|
+
`,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#fafafa"},children:L?e.jsxs("div",{className:"relative bg-white",style:{width:`${a.width}px`,height:`${a.height??900}px`,transform:`scale(${H})`,transformOrigin:"center center"},children:[J&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 bg-white rounded-lg p-8 shadow-sm w-[500px] h-[300px]",children:[e.jsx("div",{className:"mb-4",children:e.jsx(z,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-black leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Starting Interactive Mode"}),e.jsx("p",{className:"text-sm text-[#666] leading-5 m-0 font-['IBM_Plex_Sans']",children:"Setting up a sandboxed environment for your component"}),u&&e.jsxs("p",{className:"text-xs font-mono text-[#005c75] text-center leading-5 m-0 mt-3 font-['IBM_Plex_Mono'] uppercase",children:[e.jsx(B,{}),u]})]})]})}),e.jsx("iframe",{src:L,className:"w-full h-full border-none",title:`Interactive preview: ${s==null?void 0:s.name}`,onLoad:T,style:{opacity:P?1:0}},V)]}):e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 w-[500px] h-[300px] bg-white rounded-lg p-8 shadow-sm",children:[e.jsx("div",{className:"mb-4",children:e.jsx(z,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-black leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Starting Interactive Mode"}),e.jsx("p",{className:"text-sm text-[#666] leading-5 m-0 font-['IBM_Plex_Sans']",children:"Setting up a sandboxed environment for your component"}),u&&e.jsxs("p",{className:"text-xs font-mono text-[#005c75] text-center leading-5 m-0 mt-3 font-['IBM_Plex_Mono'] uppercase",children:[e.jsx(B,{}),u]})]})]})}),W&&e.jsx(re,{width:a.width,height:a.height??900,onSave:K,onCancel:()=>b(!1)})]})});export{ve as default};
|
package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-CJX6kkkV.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{r as a,w as Z,u as ee,a as te,L as v}from"./chunk-JZWAC4HX-BBXArFPl.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{W as se,u as re,I as ae}from"./InteractivePreview-CXo9EeCl.js";import{u as ne}from"./Spinner-Df3UCi8k.js";import{c as oe}from"./executionFlowCoverage-BWhdfn70.js";import"./preload-helper-ckwbz45p.js";import"./useLastLogLine-BxxP_XF9.js";import"./InlineSpinner-DuYodzo1.js";function ie({executionFlows:t,selections:r,onChange:n,disabled:i=!1}){const x=a.useCallback(s=>r.some(o=>o.flowId===s),[r]),p=a.useCallback(s=>{x(s.id)?n(r.filter(o=>o.flowId!==s.id)):n([...r,{flowId:s.id,flowName:s.name}])},[r,n,x]);return t.length===0?e.jsx("div",{className:"text-sm text-gray-500 py-2",children:"No execution flows found."}):e.jsx("div",{className:"space-y-3",children:t.map(s=>{const o=x(s.id),I=s.usedInScenarios.length>0;return e.jsxs("div",{className:"border-b border-gray-100 pb-3 last:border-0 last:pb-0",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>p(s),disabled:i,className:"mt-0.5 h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono text-sm font-medium text-gray-900",children:s.name}),!I&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-amber-100 text-amber-700 rounded",children:"uncovered"}),s.blocksOtherFlows&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-purple-100 text-purple-700 rounded",children:"blocking"}),s.impact==="high"&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-red-100 text-red-700 rounded",children:"high impact"})]}),s.description&&e.jsx("p",{className:"text-xs text-gray-500 mt-0.5 m-0",children:s.description})]})]}),o&&s.requiredValues.length>0&&e.jsxs("div",{className:"ml-6 mt-2 p-2 bg-gray-50 rounded text-xs",children:[e.jsx("span",{className:"text-gray-700 font-medium",children:"Required values:"}),e.jsx("ul",{className:"m-0 mt-1 pl-4 space-y-0.5",children:s.requiredValues.map((h,E)=>e.jsxs("li",{className:"text-gray-600",children:[e.jsx("code",{className:"bg-gray-100 px-1 rounded",children:h.attributePath})," ",e.jsx("span",{className:"text-gray-400",children:h.comparison})," ",e.jsx("code",{className:"bg-gray-100 px-1 rounded",children:h.value})]},E))})]})]},s.id)})})}const be=({data:t})=>[{title:t!=null&&t.entity?`Create Scenario - ${t.entity.name} - CodeYam`:"Create Scenario - CodeYam"},{name:"description",content:"Create a new scenario"}];function ce(){var W;const{analysis:t,defaultScenario:r,entity:n,entitySha:i,projectSlug:x}=ee(),p=te(),{iframeRef:s}=re(),[o,I]=a.useState(""),[h,E]=a.useState(400),[b,P]=a.useState(!1),[U,R]=a.useState(!1),[G,$]=a.useState(!1),[M,L]=a.useState(null),[F,l]=a.useState(null),[d,H]=a.useState([]),D=a.useMemo(()=>{var c;return!((c=t==null?void 0:t.metadata)!=null&&c.executionFlows)||!(t!=null&&t.scenarios)?[]:oe(t.metadata.executionFlows,t.scenarios).executionFlows},[t]),{interactiveServerUrl:y,isStarting:J,isLoading:_,showIframe:q,iframeKey:B,onIframeLoad:V}=ne({analysisId:t==null?void 0:t.id,scenarioId:r==null?void 0:r.id,scenarioName:r==null?void 0:r.name,projectSlug:x,enabled:!0}),Y=a.useCallback(async()=>{var m,c,T,z;if(!o.trim()&&d.length===0){L("Please describe how you want to change the scenario or select execution flows");return}R(!0),L(null),l("Generating scenario with AI...");try{const u=await fetch("/api/generate-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:o,existingScenarios:t.scenarios,scenariosDataStructure:(m=t.metadata)==null?void 0:m.scenariosDataStructure,flowSelections:d.length>0?d:void 0})}),N=await u.json();if(!u.ok||!N.success)throw new Error(N.error||"Failed to generate scenario data");console.log("[CreateScenario] AI generated scenario:",N.data);const g=N.data;if(!g.name||!g.data)throw new Error("AI response missing required fields (name or data)");l("Saving new scenario..."),$(!0);const X={name:g.name,description:g.description||o,metadata:{data:g.data,interactiveExamplePath:(c=r.metadata)==null?void 0:c.interactiveExamplePath}},Q=[...t.scenarios||[],X],O=await fetch("/api/save-scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({analysis:t,scenarios:Q})}),C=await O.json();if(!O.ok||!C.success)throw new Error(C.error||"Failed to save scenario");console.log("[CreateScenario] Scenario saved:",C);const f=(z=(T=C.analysis)==null?void 0:T.scenarios)==null?void 0:z.find(k=>k.name===g.name);if(!(f!=null&&f.id)){console.warn("[CreateScenario] Could not find saved scenario ID, navigating to entity page"),l("Scenario created! Redirecting..."),setTimeout(()=>void p(`/entity/${i}`),1e3);return}if(y){l("Capturing screenshot...");const k=await fetch("/api/capture-screenshot",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({serverUrl:y,scenarioId:f.id,projectId:t.projectId,viewportWidth:1440})}),A=await k.json();!k.ok||!A.success?(console.error("[CreateScenario] Capture failed:",A),l("Scenario created! (Screenshot capture failed)")):l("Scenario created and captured!")}else l("Scenario created!");setTimeout(()=>{p(`/entity/${i}/scenarios/${f.id}`)},1e3)}catch(u){console.error("[CreateScenario] Error:",u),L(u instanceof Error?u.message:String(u)),l(null)}finally{R(!1),$(!1)}},[o,d,t,r,i,y,p]),j=U||G,K=a.useCallback(()=>{P(!0)},[]),w=a.useCallback(m=>{if(!b)return;const c=m.clientX;c>=250&&c<=600&&E(c)},[b]),S=a.useCallback(()=>{P(!1)},[]);return a.useEffect(()=>(b?(document.addEventListener("mousemove",w),document.addEventListener("mouseup",S)):(document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",S)),()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",S)}),[b,w,S]),e.jsxs("div",{className:"h-screen bg-white flex flex-col overflow-hidden",children:[e.jsx("header",{className:"bg-white border-b border-gray-200 shrink-0 relative h-[54px]",children:e.jsxs("div",{className:"flex items-end h-full px-6 gap-6",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1 pb-[14px]",children:[e.jsx("button",{onClick:()=>void p(`/entity/${i}`),className:"no-underline shrink-0 bg-transparent border-none cursor-pointer p-0 flex items-center",title:"Back",children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 17 17",fill:"none",children:e.jsx("path",{d:"M13 8.5H4M4 8.5L8.5 4M4 8.5L8.5 13",stroke:"#005c75",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("h1",{className:"text-base font-semibold text-black m-0 leading-[20px] shrink-0",children:n==null?void 0:n.name}),e.jsx("span",{className:"text-xs text-[#9e9e9e] font-mono font-normal whitespace-nowrap overflow-hidden text-ellipsis min-w-0",title:n==null?void 0:n.filePath,children:n==null?void 0:n.filePath})]}),e.jsxs("div",{className:"flex items-end gap-8 shrink-0",children:[e.jsx(v,{to:`/entity/${i}/scenarios`,className:"relative pb-[17px] px-2 text-sm transition-colors cursor-pointer no-underline font-medium border-b-2",style:{color:"#005C75",borderColor:"#005C75"},children:e.jsxs("span",{className:"flex items-center gap-2",children:["Scenarios",e.jsx("span",{className:"inline-flex items-center justify-center px-2 py-0.5 text-xs font-semibold rounded-full bg-[#cbf3fa] text-[#005c75]",children:((W=t==null?void 0:t.scenarios)==null?void 0:W.length)||0})]})}),e.jsx(v,{to:`/entity/${i}/related`,className:"relative pb-[17px] px-2 text-sm transition-colors cursor-pointer no-underline font-normal hover:text-gray-700",style:{color:"#9ca3af"},children:"Related Entities"}),e.jsx(v,{to:`/entity/${i}/code`,className:"relative pb-[17px] px-2 text-sm transition-colors cursor-pointer no-underline font-normal hover:text-gray-700",style:{color:"#9ca3af"},children:"Code"}),e.jsx(v,{to:`/entity/${i}/data`,className:"relative pb-[17px] px-2 text-sm transition-colors cursor-pointer no-underline font-normal hover:text-gray-700",style:{color:"#9ca3af"},children:"Data Structure"}),e.jsx(v,{to:`/entity/${i}/history`,className:"relative pb-[17px] px-2 text-sm transition-colors cursor-pointer no-underline font-normal hover:text-gray-700",style:{color:"#9ca3af"},children:"History"})]})]})}),e.jsxs("div",{className:"flex flex-1 gap-0 min-h-0 relative",children:[e.jsxs("aside",{className:"bg-white border-r border-gray-200 overflow-y-auto shrink-0 p-6 flex flex-col",style:{width:`${h}px`},children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-2",children:"Default Scenario Preview"}),e.jsx("p",{className:"text-sm text-gray-600 leading-relaxed",children:"The preview on the right shows the Default Scenario. Select execution flows and/or describe how you'd like to change it."})]}),D.length>0&&e.jsxs("details",{className:"mb-4 border border-gray-200 rounded-lg",children:[e.jsxs("summary",{className:"px-3 py-2 text-sm font-medium text-gray-700 cursor-pointer hover:bg-gray-50 rounded-lg",children:["Select Execution Flows"," ",d.length>0&&e.jsxs("span",{className:"text-blue-600",children:["(",d.length," selected)"]})]}),e.jsx("div",{className:"px-3 pb-3 pt-1 border-t border-gray-100",children:e.jsx(ie,{executionFlows:D,selections:d,onChange:H,disabled:j})})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"prompt",className:"block text-sm font-medium text-gray-700 mb-2",children:"Describe your scenario"}),e.jsx("textarea",{id:"prompt",value:o,onChange:m=>I(m.target.value),placeholder:"e.g., Show an empty state with no items...",className:"w-full h-32 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm resize-none",disabled:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("button",{onClick:()=>void Y(),disabled:j||!o.trim()&&d.length===0,className:"w-full px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium cursor-pointer transition-colors hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed",children:j?"Creating...":"Create Scenario"}),F&&e.jsx("div",{className:"text-xs text-blue-600 bg-blue-50 px-2 py-1.5 rounded",children:F}),M&&e.jsx("div",{className:"text-xs text-red-600 bg-red-50 px-2 py-1.5 rounded",children:M})]})]}),e.jsxs("div",{onMouseDown:K,style:{width:"20px",position:"absolute",top:0,left:`${h-10}px`,bottom:0,cursor:"col-resize",touchAction:"none",userSelect:"none",zIndex:100,pointerEvents:"auto"},children:[e.jsx("div",{style:{position:"absolute",left:"10px",top:0,bottom:0,width:"1px",background:b?"#005c75":"rgba(0,0,0,0.1)",transition:"background 0.15s ease"}}),e.jsx("div",{style:{position:"absolute",top:"50%",left:"10px",transform:"translate(-50%, -50%)",width:"8px",height:"40px",background:"#fff",border:"1px solid rgba(0,0,0,0.15)",borderRadius:"4px",cursor:"col-resize"}})]}),e.jsx("main",{className:"flex-1 overflow-auto flex items-center justify-center min-w-0",style:{backgroundImage:`
|
|
2
|
+
linear-gradient(45deg, #ebebeb 25%, transparent 25%),
|
|
3
|
+
linear-gradient(-45deg, #ebebeb 25%, transparent 25%),
|
|
4
|
+
linear-gradient(45deg, transparent 75%, #ebebeb 75%),
|
|
5
|
+
linear-gradient(-45deg, transparent 75%, #ebebeb 75%)
|
|
6
|
+
`,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#fafafa"},children:e.jsx(ae,{scenarioId:r.id||r.name,scenarioName:r.name,iframeUrl:y,isStarting:J,isLoading:_,showIframe:q,iframeKey:B,onIframeLoad:V,projectSlug:x,defaultWidth:1440,defaultHeight:900})})]})]})}const fe=Z(function(){return e.jsx(se,{children:e.jsx(ce,{})})});export{fe as default,be as meta};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r as l,w as Y,u as K,a as Q,L as z}from"./chunk-JZWAC4HX-BBXArFPl.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{W as X,u as Z,I as ee}from"./InteractivePreview-CXo9EeCl.js";import{u as te}from"./Spinner-Df3UCi8k.js";import"./preload-helper-ckwbz45p.js";import"./useLastLogLine-BxxP_XF9.js";import"./InlineSpinner-DuYodzo1.js";function U(t,n,r){if(Array.isArray(t)){if(!isNaN(parseInt(n)))return t[parseInt(n)];for(const s of t)if(s.name===n||s.title===n||s.id===n)return s}return t[n]}function q(t){return t&&(typeof t=="object"||Array.isArray(t))}function re(t){return Array.isArray(t)?t.length:void 0}function ne(t){const{data:n,structure:r}=t;if(!(!n&&!r)){if(Array.isArray(r))return Array.isArray(n)?n.map((s,d)=>d.toString()):[];if(typeof r=="object")return[...new Set([...Object.keys(n),...Object.keys(r)])].sort((d,o)=>{const p=q(n[d]),c=q(n[o]);return p&&!c?1:!p&&c?-1:d.localeCompare(o)});if(typeof n=="object")return Object.keys(n).sort((d,o)=>d.localeCompare(o))}}function se({scenarioFormData:t,handleInputChange:n}){return e.jsxs("div",{className:"p-3 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid w-full max-w-sm items-center gap-1.5",children:[e.jsx("label",{htmlFor:"name",className:"text-sm font-medium text-gray-700",children:"Name"}),e.jsx("input",{type:"text",id:"name",placeholder:"Name",name:"name",value:t.name,onChange:n,required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{className:"grid w-full gap-1.5 pt-2",children:[e.jsx("label",{htmlFor:"description",className:"text-sm font-medium text-gray-700",children:"Description"}),e.jsx("textarea",{placeholder:"Type your message here.",id:"description",name:"description",value:t.description,onChange:n,required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 min-h-[100px]"})]}),e.jsx("button",{type:"submit",className:"mt-3 w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 font-medium",children:"Save Name & Description"})]})}function ae({path:t,namedPath:n,isArray:r,count:s,onClick:d}){const o=l.useCallback(()=>{d&&d(t)},[d,t]);return e.jsxs("div",{className:"bg-blue-50 p-3 rounded-lg flex items-center justify-between cursor-pointer group hover:bg-blue-100 transition-colors border border-blue-200",onClick:o,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[r&&e.jsx("svg",{className:"w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})}),e.jsxs("div",{className:"capitalize font-medium text-gray-900",children:[n[n.length-1],s!==void 0&&` (${s})`]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[r&&e.jsx("svg",{className:"w-5 h-5 text-red-500 opacity-0 group-hover:opacity-100 transition-opacity",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),e.jsx("svg",{className:"w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})]})}var V=(t=>(t.STRING="string",t.NUMBER="number",t.BOOLEAN="boolean",t.UNION="union",t.OBJECT="object",t.ARRAY="array",t))(V||{});const oe=({name:t,value:n,options:r,onChange:s})=>{const d=l.useCallback(o=>{s({target:{name:t,value:o.target.value}})},[t,s]);return e.jsx("select",{name:t,value:n,onChange:d,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:r.map((o,p)=>e.jsx("option",{value:o.trim(),children:o.trim()},p))})},ie=({name:t,value:n,onChange:r})=>{const s=l.useCallback(d=>{const o=d.target.checked;r({target:{name:t,value:o}})},[t,r]);return e.jsx("label",{className:"flex items-center gap-2 cursor-pointer",children:e.jsx("input",{type:"checkbox",name:t,checked:n,onChange:s,className:`w-10 h-6 rounded-full appearance-none cursor-pointer transition-colors relative
|
|
2
2
|
bg-gray-300 checked:bg-blue-600
|
|
3
3
|
after:content-[''] after:absolute after:top-1 after:left-1 after:w-4 after:h-4
|
|
4
4
|
after:bg-white after:rounded-full after:transition-transform
|
|
5
|
-
checked:after:translate-x-4`})})};function le({dataType:t,path:n,value:r,onChange:s}){const d=l.useMemo(()=>n[n.length-1],[n]),o=l.useMemo(()=>n.join("-"),[n]),p=l.useCallback(j=>{s(n,j.target.value)},[s,n]),c=l.useCallback(j=>{s(n,j.target.value)},[s,n]);return e.jsxs("div",{className:"grid w-full max-w-sm items-center gap-1.5",children:[e.jsx("label",{htmlFor:o,className:"capitalize text-sm font-medium text-gray-700",children:d==="~~codeyam-code~~"?"Dynamic Field":d}),t.includes("|")?e.jsx(oe,{name:o,value:r,options:t.split("|"),onChange:p}):t===V.BOOLEAN?e.jsx(ie,{name:o,value:r??!1,onChange:c}):e.jsx("input",{id:o,name:o,type:"text",value:JSON.stringify(r??"").replace(/"/g,""),onChange:p,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"},`Input-${o}`)]})}const ce="Default Scenario";function de({analysis:t,scenarioName:n,dataItem:r,onResult:s,onGenerateData:d}){const[o,p]=l.useState(!1),[c,j]=l.useState(""),k=l.useCallback(async()=>{if(!d){console.error("onGenerateData prop is required for AI data generation");return}p(!0);try{const u=t.scenarios.find(b=>b.name===n);if(!u)throw new Error("Scenario not found");const A=t.scenarios.find(b=>b.name===ce),I=await d(c,r);if(!I){console.error("Error getting AI guess for scenario data"),p(!1);return}const w=(b,v)=>{const L=Object.assign({},b);return x(b)&&x(v)&&Object.keys(v).forEach(N=>{x(v[N])?N in b?L[N]=w(b[N],v[N]):Object.assign(L,{[N]:v[N]}):Object.assign(L,{[N]:v[N]})}),L},x=b=>b&&typeof b=="object"&&!Array.isArray(b);u.metadata.data=w(w((A==null?void 0:A.metadata.data)||{},u.metadata.data),I.data||{}),s(u),p(!1),j("")}catch(u){console.error("Error generating AI data:",u),p(!1)}},[t,c,r,n,s,d]),g=l.useCallback(u=>{j(u.target.value)},[]);return e.jsxs("div",{className:"w-full p-3 flex flex-col gap-2 rounded-lg border-2 border-blue-200 text-sm bg-blue-50",children:[e.jsx("div",{className:"font-medium text-gray-700",children:"Describe the data changes to the AI"}),e.jsx("textarea",{className:"peer w-full h-16 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Type your message here.",onChange:g,value:c}),e.jsx("button",{type:"button",disabled:o,className:`w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-400 disabled:cursor-not-allowed font-medium ${c.length>0?"flex":"hidden peer-focus-within:flex"} items-center justify-center gap-2`,onClick:()=>void k(),children:o?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Please wait"]}):"Generate Data"})]})}function ue({namedPath:t,path:n,last:r,onClick:s}){const d=l.useCallback(()=>s(r?n.slice(0,-1):n),[r,n,s]);return e.jsx("div",{className:"capitalize cursor-pointer hover:text-blue-600 transition-colors",onClick:d,children:t[t.length-1]})}function me({dataItem:t,onClick:n}){const r=l.useCallback(()=>n([]),[n]),s=l.useMemo(()=>t.namedPath.length>=2?t.namedPath.length-2:0,[t]);return e.jsxs("div",{className:"text-sm flex items-center gap-2 py-3 px-2 border-b border-t border-gray-300 bg-gray-50",children:[e.jsx("svg",{className:"w-4 h-4 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:r,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),t.namedPath.length>2&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{children:"..."}),e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]}),t.namedPath.slice(s).map((d,o)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ue,{namedPath:t.namedPath.slice(0,o+s+1),path:t.path.slice(0,o+s+1),last:o+s===t.namedPath.length-1,onClick:n}),o+s<t.namedPath.length-1&&e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},`path-${d}-${o+s}`))]})}function F({analysis:t,scenarioName:n,dataItem:r,onClick:s,onChange:d,onAIResult:o,onGenerateData:p,saveFeedback:c}){const j=l.useMemo(()=>r.data,[r]),k=l.useMemo(()=>ne(r),[r]);return e.jsxs("div",{className:"w-full flex flex-col gap-6 px-3 mt-3",children:[r.path.length>0&&e.jsx(me,{dataItem:r,onClick:s}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{analysis:t,scenarioName:n,dataItem:r,onResult:o,onGenerateData:p}),k==null?void 0:k.map((g,u)=>{var I;if(q(j[g])){let w=g;isNaN(Number(g))||(w=j[g].name??j[g].title??j[g].id??`${r.path[r.path.length-1].replace(/s$/,"")} ${parseInt(g)+1}`);const x=[...r.path,g],b=[...r.namedPath,w];return e.jsx(ae,{path:x,namedPath:b,isArray:Array.isArray(j),count:re(j[g]),onClick:s},`data-${g}-${u}`)}if(g==="id")return null;const A=[...r.path,g];return e.jsx(le,{dataType:((I=r.structure)==null?void 0:I[g])??"string",path:A,value:j[g],onChange:d},`InputField-${A.join("-")}`)})]}),e.jsx("input",{type:"hidden",name:"recapture",id:"recapture-input",value:"false"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",onClick:()=>{const g=document.getElementById("recapture-input");g&&(g.value="false")},disabled:c==null?void 0:c.isSaving,className:"flex-1 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:c!=null&&c.isSaving?"Saving...":"Save Changes"}),e.jsx("button",{type:"submit",onClick:()=>{const g=document.getElementById("recapture-input");g&&(g.value="true")},disabled:c==null?void 0:c.isSaving,className:"flex-1 px-4 py-2 bg-gray-100 text-gray-700 border border-gray-300 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:"Save & Recapture"})]}),(c==null?void 0:c.message)&&!(c!=null&&c.isSaving)&&e.jsx("div",{className:`mt-3 p-3 rounded-md text-sm font-medium ${c.isError?"bg-red-50 text-red-700 border border-red-200":"bg-green-50 text-green-700 border border-green-200"}`,children:c.message})]})}function H({title:t,children:n,defaultOpen:r=!1,borderT:s=!1,borderB:d=!1}){const[o,p]=l.useState(r),c=[];return s&&c.push("border-t"),d&&c.push("border-b"),e.jsxs("div",{className:`${c.join(" ")} border-gray-300`,children:[e.jsxs("button",{type:"button",onClick:()=>p(!o),className:"w-full px-4 py-3 flex items-center justify-between bg-gray-50 hover:bg-gray-100 transition-colors text-left font-semibold text-gray-900",children:[e.jsx("span",{children:t}),e.jsx("svg",{className:`transition-transform ${o?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",maxWidth:"20px",maxHeight:"20px",flexShrink:0},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),o&&e.jsx("div",{className:"px-4 py-3",children:n})]})}const ge=({currentScenario:t,defaultScenario:n,dataStructure:r,analysis:s,shouldCreateNewScenario:d,onSave:o,onNavigate:p,iframeRef:c,onGenerateData:j,saveFeedback:k})=>{const g=l.useCallback((i,a)=>{const h=Object.assign({},i),f=m=>m&&typeof m=="object"&&!Array.isArray(m);return f(i)&&f(a)&&Object.keys(a).forEach(m=>{f(a[m])?m in i?h[m]=g(i[m],a[m]):Object.assign(h,{[m]:a[m]}):Object.assign(h,{[m]:a[m]})}),h},[]),[u,A]=l.useState({name:t.name,description:t.description,data:g(n.metadata.data,t.metadata.data)}),[I,w]=l.useState(null),x=l.useMemo(()=>({...u.data}),[u]),b=l.useMemo(()=>({...x.mockData?{"Retrieved Data":x.mockData}:{},...x.argumentsData?{"Function Arguments":x.argumentsData}:{}}),[x]),v=l.useMemo(()=>{const i={...r.arguments?{"Function Arguments":r.arguments}:{},...r.dataForMocks?{"Retrieved Data":r.dataForMocks}:{}};return Object.keys(i).reduce((a,h)=>{if(h.includes(".")){const[f,m]=h.split(".");a[f]||(a[f]={}),a[f][m]=i[h]}else a[h]=i[h];return a},{})},[r]),L=l.useCallback(async i=>{i.preventDefault();const a=i.target.querySelector('input[name="recapture"]'),h=(a==null?void 0:a.value)==="true",f={mockData:u.data.mockData??{},argumentsData:u.data.argumentsData??[]};console.log("[ScenarioEditor] Saving scenario data:",{scenarioName:u.name,shouldRecapture:h,dataToSave:f,rawFormData:u.data,iframePayload:{arguments:x.argumentsData??[],...x.mockData??{}}}),console.log("[ScenarioEditor] Full dataToSave JSON:",JSON.stringify(f,null,2).substring(0,1e3));const m=s==null?void 0:s.scenarios.map(S=>!d&&S.name===t.name?{...S,name:u.name,description:u.description,metadata:{...S.metadata,data:f}}:S);d&&m.push({name:u.name,description:u.description,metadata:{data:f,interactiveExamplePath:s==null?void 0:s.scenarios[0].metadata.interactiveExamplePath}}),console.log("[ScenarioEditor] Updated scenarios to save:",m),o&&await o(m,{recapture:h}),p&&p(u.name)},[s,t.name,u,x,d,o,p]),N=l.useCallback(i=>{A(a=>({...a,[i.target.name]:i.target.value}))},[]),M=l.useCallback(i=>{w(a=>{if(!a)return null;for(const h of[{arguments:i.metadata.data.argumentsData},i.metadata.data.mockData]){let f=h;for(const m of a.path)if(f=U(f,m),!f)break;f&&(a.data=f)}return{...a}}),A({name:i.name,description:i.description,data:i.metadata.data})},[]),W=l.useCallback((i,a)=>{A(h=>{for(const f of[{"Function Arguments":h.data.argumentsData},{"Retrieved Data":h.data.mockData}]){let m=f;for(const S of i.slice(0,-1))if(m=U(m,S),!m)break;if(m){const S=m[i[i.length-1]];w(C=>C?(C.namedPath[C.namedPath.length-1]===S&&(C.namedPath[C.namedPath.length-1]=a.toString()),C.data[i[i.length-1]]=a,{...C}):null),m[i[i.length-1]]=a}}return{...h}})},[]),J=l.useCallback(i=>{var m,S,C;if(i.length===0){w(null);return}let a=b;const h=[];let f=v;for(const E of i){if(h.push(isNaN(parseInt(E))?E:((m=a[E])==null?void 0:m.name)??((S=a[E])==null?void 0:S.title)??((C=a[E])==null?void 0:C.id)??E),a=U(a,E),!a){console.log("Data not found",a,E),w(null);return}Array.isArray(f)?f=f[0]:f=f[E]}w({path:i,namedPath:h,data:a,structure:f})},[b,v]);return l.useEffect(()=>{const i=a=>{var h;a.data.type==="codeyam-log"&&((h=a.data.data)!=null&&h.includes("Error"))&&console.error("[ScenarioEditor] Error from iframe:",a.data.data)};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[]),l.useEffect(()=>{var i;if((i=c==null?void 0:c.current)!=null&&i.contentWindow){const a={arguments:x.argumentsData??[],...x.mockData??{}},h={type:"codeyam-override-data",name:t.name,data:JSON.stringify(a)};console.log("[ScenarioEditor] → SENDING codeyam-override-data:",{type:h.type,name:h.name,dataPreview:JSON.stringify(a).substring(0,200)+"...",fullData:a}),c.current.contentWindow.postMessage(h,"*")}},[x,t,c]),e.jsx("form",{method:"post",onSubmit:i=>void L(i),children:I?e.jsx(F,{analysis:s,scenarioName:u.name,dataItem:I,onClick:J,onChange:W,onAIResult:M,onGenerateData:j,saveFeedback:k}):e.jsxs(e.Fragment,{children:[e.jsx(H,{title:"Edit Name and Description",borderT:!0,children:e.jsx(se,{scenarioFormData:u,handleInputChange:N})}),t.metadata.data&&e.jsx(H,{title:"Edit Scenario Data",defaultOpen:!0,borderT:!0,borderB:!0,children:e.jsx(F,{analysis:s,scenarioName:u.name,dataItem:{path:[],namedPath:[],data:b,structure:v},onClick:J,onChange:W,onAIResult:M,onGenerateData:j,saveFeedback:k})})]})})},we=({data:t})=>[{title:t!=null&&t.scenario?`Edit ${t.scenario.name} - CodeYam`:"Edit Scenario - CodeYam"},{name:"description",content:"Edit scenario data"}];function he(){var E,_,G;const t=K(),n=t.analysis,r=t.scenario,s=t.defaultScenario,d=t.entitySha,o=t.projectSlug,p=Q(),{iframeRef:c}=Z(),[j,k]=l.useState(!1),[g,u]=l.useState(null),[A,I]=l.useState(null),[w,x]=l.useState(!1),[b,v]=l.useState(!1),[L,N]=l.useState(null),{interactiveServerUrl:M,isStarting:W,isLoading:J,showIframe:i,iframeKey:a,onIframeLoad:h}=te({analysisId:n==null?void 0:n.id,scenarioId:r==null?void 0:r.id,scenarioName:r==null?void 0:r.name,projectSlug:o,enabled:!0}),f=l.useCallback(async(P,y)=>{k(!0),u(null),I(null),console.log("[EditScenario] Starting save with options:",y),console.log("[EditScenario] Scenarios to save:",P);try{const D={analysis:n,scenarios:P};console.log("[EditScenario] Sending to /api/save-scenarios:",{analysisId:n.id,scenarioCount:P.length,scenarioNames:P.map(R=>R.name)});const T=await fetch("/api/save-scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)}),B=await T.json();if(console.log("[EditScenario] API response:",B),!T.ok||!B.success)throw new Error(B.error||"Failed to save scenarios");if(console.log("[EditScenario] Scenarios saved successfully"),y!=null&&y.recapture&&r.id&&M){console.log("[EditScenario] ========== DIRECT CAPTURE START =========="),console.log("[EditScenario] Taking screenshot from running server",{scenarioId:r.id,projectId:n.projectId,serverUrl:M}),u("Changes saved. Capturing screenshot...");const R={serverUrl:M,scenarioId:r.id,projectId:n.projectId,viewportWidth:1440};console.log("[EditScenario] Capture request body:",R);const $=await fetch("/api/capture-screenshot",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)});console.log("[EditScenario] Capture response status:",$.status);const O=await $.json();if(console.log("[EditScenario] Capture response body:",O),!$.ok||!O.success)throw console.error("[EditScenario] Capture failed:",O),new Error(O.error||"Failed to capture screenshot");console.log("[EditScenario] Screenshot captured successfully:",O),console.log("[EditScenario] ========== DIRECT CAPTURE COMPLETE =========="),u("Recapture successful")}else if(y!=null&&y.recapture&&!M){console.log("[EditScenario] No running server, using queued recapture");const R=new FormData;R.append("analysisId",n.id||""),R.append("scenarioId",r.id||"");const $=await fetch("/api/recapture-scenario",{method:"POST",body:R}),O=await $.json();if(!$.ok||!O.success)throw new Error(O.error||"Failed to trigger recapture");console.log("Recapture queued:",O),I(O.jobId),u("Changes saved. Screenshot recapture queued.")}else u("Changes saved successfully.")}catch(D){console.error("Error saving scenarios:",D),u(`Error: ${D instanceof Error?D.message:String(D)}`)}finally{k(!1)}},[n,r.id,M]),m=l.useCallback(P=>{},[]),S=l.useCallback(async(P,y)=>{var B;const D=await fetch("/api/generate-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:P,existingScenarios:n.scenarios,scenariosDataStructure:(B=n.metadata)==null?void 0:B.scenariosDataStructure,editingMockName:r.name,editingMockData:y==null?void 0:y.data})}),T=await D.json();if(!D.ok||!T.success)throw new Error(T.error||"Failed to generate scenario data");return T.data},[n,r.name]),C=l.useCallback(async()=>{var P;if(!r.id){N("Cannot delete scenario without ID");return}x(!0),N(null);try{const y=await fetch("/api/delete-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:r.id,screenshotPaths:((P=r.metadata)==null?void 0:P.screenshotPaths)||[]})}),D=await y.json();if(!y.ok||!D.success)throw new Error(D.error||"Failed to delete scenario");p(`/entity/${d}`)}catch(y){console.error("[EditScenario] Error deleting scenario:",y),N(y instanceof Error?y.message:"Failed to delete scenario"),v(!1)}finally{x(!1)}},[r.id,(E=r.metadata)==null?void 0:E.screenshotPaths,d,p]);return e.jsxs("div",{className:"h-screen bg-gray-50 flex flex-col",children:[e.jsxs("header",{className:"bg-white border-b border-gray-200 px-8 py-6 shrink-0",children:[e.jsx("div",{className:"mb-4",children:e.jsxs(z,{to:`/entity/${d}`,className:"text-blue-600 no-underline text-sm font-medium transition-colors hover:text-blue-700 hover:underline",children:["← Back to ",(_=n.entity)==null?void 0:_.name]})}),e.jsxs("h1",{className:"text-[32px] font-bold text-gray-900 m-0 mb-3",children:["Edit Scenario: ",r.name]}),r.description&&e.jsx("p",{className:"text-gray-600 text-[15px] leading-relaxed m-0",children:r.description})]}),e.jsxs("div",{className:"flex flex-1 gap-0 min-h-0",children:[e.jsxs("aside",{className:"w-[400px] bg-white border-r border-gray-200 overflow-y-auto shrink-0",children:[e.jsx(ge,{currentScenario:r,defaultScenario:s,dataStructure:((G=n.metadata)==null?void 0:G.scenariosDataStructure)||{},analysis:n,shouldCreateNewScenario:!1,onSave:f,onNavigate:m,iframeRef:c,onGenerateData:S,saveFeedback:{isSaving:j,message:g,isError:(g==null?void 0:g.startsWith("Error"))??!1}}),g==="Recapture successful"&&e.jsx("div",{className:"px-4 pb-4",children:e.jsx(z,{to:`/entity/${d}`,className:"text-blue-600 hover:text-blue-700 hover:underline text-sm",children:"View updated screenshot on entity page →"})}),e.jsxs("div",{className:"border-t border-gray-200 p-4 mt-4",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:"Permanently remove this scenario and its screenshots."}),b?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-sm text-red-600 font-medium",children:['Are you sure you want to delete "',r.name,'"?']}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>void C(),disabled:w,className:"flex-1 px-4 py-2 bg-red-600 text-white rounded-md text-sm font-medium hover:bg-red-700 disabled:bg-red-400 disabled:cursor-not-allowed transition-colors",children:w?"Deleting...":"Yes, Delete"}),e.jsx("button",{onClick:()=>v(!1),disabled:w,className:"flex-1 px-4 py-2 bg-gray-100 text-gray-700 border border-gray-300 rounded-md text-sm font-medium hover:bg-gray-200 disabled:opacity-50 transition-colors",children:"Cancel"})]})]}):e.jsx("button",{onClick:()=>v(!0),className:"w-full px-4 py-2 bg-red-50 text-red-600 border border-red-200 rounded-md text-sm font-medium hover:bg-red-100 transition-colors",children:"Delete Scenario"}),L&&e.jsx("div",{className:"mt-3 text-sm text-red-600 bg-red-50 px-3 py-2 rounded-md",children:L})]})]}),e.jsx("main",{className:"flex-1 bg-gray-100 overflow-auto flex flex-col min-w-0",children:e.jsx(ee,{scenarioId:r.id||r.name,scenarioName:r.name,iframeUrl:M,isStarting:W,isLoading:J,showIframe:i,iframeKey:a,onIframeLoad:h,projectSlug:o,defaultWidth:1440,defaultHeight:900})})]})]})}const Ne=Y(function(){return e.jsx(X,{children:e.jsx(he,{})})});export{Ne as default,we as meta};
|
|
5
|
+
checked:after:translate-x-4`})})};function le({dataType:t,path:n,value:r,onChange:s}){const d=l.useMemo(()=>n[n.length-1],[n]),o=l.useMemo(()=>n.join("-"),[n]),p=l.useCallback(j=>{s(n,j.target.value)},[s,n]),c=l.useCallback(j=>{s(n,j.target.value)},[s,n]);return e.jsxs("div",{className:"grid w-full max-w-sm items-center gap-1.5",children:[e.jsx("label",{htmlFor:o,className:"capitalize text-sm font-medium text-gray-700",children:d==="~~codeyam-code~~"?"Dynamic Field":d}),t.includes("|")?e.jsx(oe,{name:o,value:r,options:t.split("|"),onChange:p}):t===V.BOOLEAN?e.jsx(ie,{name:o,value:r??!1,onChange:c}):e.jsx("input",{id:o,name:o,type:"text",value:JSON.stringify(r??"").replace(/"/g,""),onChange:p,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"},`Input-${o}`)]})}const ce="Default Scenario";function de({analysis:t,scenarioName:n,dataItem:r,onResult:s,onGenerateData:d}){const[o,p]=l.useState(!1),[c,j]=l.useState(""),k=l.useCallback(async()=>{if(!d){console.error("onGenerateData prop is required for AI data generation");return}p(!0);try{const u=t.scenarios.find(b=>b.name===n);if(!u)throw new Error("Scenario not found");const A=t.scenarios.find(b=>b.name===ce),I=await d(c,r);if(!I){console.error("Error getting AI guess for scenario data"),p(!1);return}const w=(b,v)=>{const L=Object.assign({},b);return x(b)&&x(v)&&Object.keys(v).forEach(N=>{x(v[N])?N in b?L[N]=w(b[N],v[N]):Object.assign(L,{[N]:v[N]}):Object.assign(L,{[N]:v[N]})}),L},x=b=>b&&typeof b=="object"&&!Array.isArray(b);u.metadata.data=w(w((A==null?void 0:A.metadata.data)||{},u.metadata.data),I.data||{}),s(u),p(!1),j("")}catch(u){console.error("Error generating AI data:",u),p(!1)}},[t,c,r,n,s,d]),g=l.useCallback(u=>{j(u.target.value)},[]);return e.jsxs("div",{className:"w-full p-3 flex flex-col gap-2 rounded-lg border-2 border-blue-200 text-sm bg-blue-50",children:[e.jsx("div",{className:"font-medium text-gray-700",children:"Describe the data changes to the AI"}),e.jsx("textarea",{className:"peer w-full h-16 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Type your message here.",onChange:g,value:c}),e.jsx("button",{type:"button",disabled:o,className:`w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-400 disabled:cursor-not-allowed font-medium ${c.length>0?"flex":"hidden peer-focus-within:flex"} items-center justify-center gap-2`,onClick:()=>void k(),children:o?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Please wait"]}):"Generate Data"})]})}function ue({namedPath:t,path:n,last:r,onClick:s}){const d=l.useCallback(()=>s(r?n.slice(0,-1):n),[r,n,s]);return e.jsx("div",{className:"capitalize cursor-pointer hover:text-blue-600 transition-colors",onClick:d,children:t[t.length-1]})}function me({dataItem:t,onClick:n}){const r=l.useCallback(()=>n([]),[n]),s=l.useMemo(()=>t.namedPath.length>=2?t.namedPath.length-2:0,[t]);return e.jsxs("div",{className:"text-sm flex items-center gap-2 py-3 px-2 border-b border-t border-gray-300 bg-gray-50",children:[e.jsx("svg",{className:"w-4 h-4 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:r,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),t.namedPath.length>2&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{children:"..."}),e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]}),t.namedPath.slice(s).map((d,o)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ue,{namedPath:t.namedPath.slice(0,o+s+1),path:t.path.slice(0,o+s+1),last:o+s===t.namedPath.length-1,onClick:n}),o+s<t.namedPath.length-1&&e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},`path-${d}-${o+s}`))]})}function F({analysis:t,scenarioName:n,dataItem:r,onClick:s,onChange:d,onAIResult:o,onGenerateData:p,saveFeedback:c}){const j=l.useMemo(()=>r.data,[r]),k=l.useMemo(()=>ne(r),[r]);return e.jsxs("div",{className:"w-full flex flex-col gap-6 px-3 mt-3",children:[r.path.length>0&&e.jsx(me,{dataItem:r,onClick:s}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{analysis:t,scenarioName:n,dataItem:r,onResult:o,onGenerateData:p}),k==null?void 0:k.map((g,u)=>{var I;if(q(j[g])){let w=g;isNaN(Number(g))||(w=j[g].name??j[g].title??j[g].id??`${r.path[r.path.length-1].replace(/s$/,"")} ${parseInt(g)+1}`);const x=[...r.path,g],b=[...r.namedPath,w];return e.jsx(ae,{path:x,namedPath:b,isArray:Array.isArray(j),count:re(j[g]),onClick:s},`data-${g}-${u}`)}if(g==="id")return null;const A=[...r.path,g];return e.jsx(le,{dataType:((I=r.structure)==null?void 0:I[g])??"string",path:A,value:j[g],onChange:d},`InputField-${A.join("-")}`)})]}),e.jsx("input",{type:"hidden",name:"recapture",id:"recapture-input",value:"false"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",onClick:()=>{const g=document.getElementById("recapture-input");g&&(g.value="false")},disabled:c==null?void 0:c.isSaving,className:"flex-1 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:c!=null&&c.isSaving?"Saving...":"Save Changes"}),e.jsx("button",{type:"submit",onClick:()=>{const g=document.getElementById("recapture-input");g&&(g.value="true")},disabled:c==null?void 0:c.isSaving,className:"flex-1 px-4 py-2 bg-gray-100 text-gray-700 border border-gray-300 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:"Save & Recapture"})]}),(c==null?void 0:c.message)&&!(c!=null&&c.isSaving)&&e.jsx("div",{className:`mt-3 p-3 rounded-md text-sm font-medium ${c.isError?"bg-red-50 text-red-700 border border-red-200":"bg-green-50 text-green-700 border border-green-200"}`,children:c.message})]})}function H({title:t,children:n,defaultOpen:r=!1,borderT:s=!1,borderB:d=!1}){const[o,p]=l.useState(r),c=[];return s&&c.push("border-t"),d&&c.push("border-b"),e.jsxs("div",{className:`${c.join(" ")} border-gray-300`,children:[e.jsxs("button",{type:"button",onClick:()=>p(!o),className:"w-full px-4 py-3 flex items-center justify-between bg-gray-50 hover:bg-gray-100 transition-colors text-left font-semibold text-gray-900",children:[e.jsx("span",{children:t}),e.jsx("svg",{className:`transition-transform ${o?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",maxWidth:"20px",maxHeight:"20px",flexShrink:0},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),o&&e.jsx("div",{className:"px-4 py-3",children:n})]})}const ge=({currentScenario:t,defaultScenario:n,dataStructure:r,analysis:s,shouldCreateNewScenario:d,onSave:o,onNavigate:p,iframeRef:c,onGenerateData:j,saveFeedback:k})=>{const g=l.useCallback((i,a)=>{const h=Object.assign({},i),f=m=>m&&typeof m=="object"&&!Array.isArray(m);return f(i)&&f(a)&&Object.keys(a).forEach(m=>{f(a[m])?m in i?h[m]=g(i[m],a[m]):Object.assign(h,{[m]:a[m]}):Object.assign(h,{[m]:a[m]})}),h},[]),[u,A]=l.useState({name:t.name,description:t.description,data:g(n.metadata.data,t.metadata.data)}),[I,w]=l.useState(null),x=l.useMemo(()=>({...u.data}),[u]),b=l.useMemo(()=>({...x.mockData?{"Retrieved Data":x.mockData}:{},...x.argumentsData?{"Function Arguments":x.argumentsData}:{}}),[x]),v=l.useMemo(()=>{const i={...r.arguments?{"Function Arguments":r.arguments}:{},...r.dataForMocks?{"Retrieved Data":r.dataForMocks}:{}};return Object.keys(i).reduce((a,h)=>{if(h.includes(".")){const[f,m]=h.split(".");a[f]||(a[f]={}),a[f][m]=i[h]}else a[h]=i[h];return a},{})},[r]),L=l.useCallback(async i=>{i.preventDefault();const a=i.target.querySelector('input[name="recapture"]'),h=(a==null?void 0:a.value)==="true",f={mockData:u.data.mockData??{},argumentsData:u.data.argumentsData??[]};console.log("[ScenarioEditor] Saving scenario data:",{scenarioName:u.name,shouldRecapture:h,dataToSave:f,rawFormData:u.data,iframePayload:{arguments:x.argumentsData??[],...x.mockData??{}}}),console.log("[ScenarioEditor] Full dataToSave JSON:",JSON.stringify(f,null,2).substring(0,1e3));const m=s==null?void 0:s.scenarios.map(S=>!d&&S.name===t.name?{...S,name:u.name,description:u.description,metadata:{...S.metadata,data:f}}:S);d&&m.push({name:u.name,description:u.description,metadata:{data:f,interactiveExamplePath:s==null?void 0:s.scenarios[0].metadata.interactiveExamplePath}}),console.log("[ScenarioEditor] Updated scenarios to save:",m),o&&await o(m,{recapture:h}),p&&p(u.name)},[s,t.name,u,x,d,o,p]),N=l.useCallback(i=>{A(a=>({...a,[i.target.name]:i.target.value}))},[]),M=l.useCallback(i=>{w(a=>{if(!a)return null;for(const h of[{arguments:i.metadata.data.argumentsData},i.metadata.data.mockData]){let f=h;for(const m of a.path)if(f=U(f,m),!f)break;f&&(a.data=f)}return{...a}}),A({name:i.name,description:i.description,data:i.metadata.data})},[]),W=l.useCallback((i,a)=>{A(h=>{for(const f of[{"Function Arguments":h.data.argumentsData},{"Retrieved Data":h.data.mockData}]){let m=f;for(const S of i.slice(0,-1))if(m=U(m,S),!m)break;if(m){const S=m[i[i.length-1]];w(C=>C?(C.namedPath[C.namedPath.length-1]===S&&(C.namedPath[C.namedPath.length-1]=a.toString()),C.data[i[i.length-1]]=a,{...C}):null),m[i[i.length-1]]=a}}return{...h}})},[]),J=l.useCallback(i=>{var m,S,C;if(i.length===0){w(null);return}let a=b;const h=[];let f=v;for(const E of i){if(h.push(isNaN(parseInt(E))?E:((m=a[E])==null?void 0:m.name)??((S=a[E])==null?void 0:S.title)??((C=a[E])==null?void 0:C.id)??E),a=U(a,E),!a){console.log("Data not found",a,E),w(null);return}Array.isArray(f)?f=f[0]:f=f[E]}w({path:i,namedPath:h,data:a,structure:f})},[b,v]);return l.useEffect(()=>{const i=a=>{var h;a.data.type==="codeyam-log"&&((h=a.data.data)!=null&&h.includes("Error"))&&console.error("[ScenarioEditor] Error from iframe:",a.data.data)};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[]),l.useEffect(()=>{var i;if((i=c==null?void 0:c.current)!=null&&i.contentWindow){const a={arguments:x.argumentsData??[],...x.mockData??{}},h={type:"codeyam-override-data",name:t.name,data:JSON.stringify(a)};console.log("[ScenarioEditor] → SENDING codeyam-override-data:",{type:h.type,name:h.name,dataPreview:JSON.stringify(a).substring(0,200)+"...",fullData:a}),c.current.contentWindow.postMessage(h,"*")}},[x,t,c]),e.jsx("form",{method:"post",onSubmit:i=>void L(i),children:I?e.jsx(F,{analysis:s,scenarioName:u.name,dataItem:I,onClick:J,onChange:W,onAIResult:M,onGenerateData:j,saveFeedback:k}):e.jsxs(e.Fragment,{children:[e.jsx(H,{title:"Edit Name and Description",borderT:!0,children:e.jsx(se,{scenarioFormData:u,handleInputChange:N})}),t.metadata.data&&e.jsx(H,{title:"Edit Scenario Data",defaultOpen:!0,borderT:!0,borderB:!0,children:e.jsx(F,{analysis:s,scenarioName:u.name,dataItem:{path:[],namedPath:[],data:b,structure:v},onClick:J,onChange:W,onAIResult:M,onGenerateData:j,saveFeedback:k})})]})})},Ne=({data:t})=>[{title:t!=null&&t.scenario?`Edit ${t.scenario.name} - CodeYam`:"Edit Scenario - CodeYam"},{name:"description",content:"Edit scenario data"}];function he(){var E,_,G;const t=K(),n=t.analysis,r=t.scenario,s=t.defaultScenario,d=t.entitySha,o=t.projectSlug,p=Q(),{iframeRef:c}=Z(),[j,k]=l.useState(!1),[g,u]=l.useState(null),[A,I]=l.useState(null),[w,x]=l.useState(!1),[b,v]=l.useState(!1),[L,N]=l.useState(null),{interactiveServerUrl:M,isStarting:W,isLoading:J,showIframe:i,iframeKey:a,onIframeLoad:h}=te({analysisId:n==null?void 0:n.id,scenarioId:r==null?void 0:r.id,scenarioName:r==null?void 0:r.name,projectSlug:o,enabled:!0}),f=l.useCallback(async(P,y)=>{k(!0),u(null),I(null),console.log("[EditScenario] Starting save with options:",y),console.log("[EditScenario] Scenarios to save:",P);try{const D={analysis:n,scenarios:P};console.log("[EditScenario] Sending to /api/save-scenarios:",{analysisId:n.id,scenarioCount:P.length,scenarioNames:P.map(R=>R.name)});const T=await fetch("/api/save-scenarios",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)}),B=await T.json();if(console.log("[EditScenario] API response:",B),!T.ok||!B.success)throw new Error(B.error||"Failed to save scenarios");if(console.log("[EditScenario] Scenarios saved successfully"),y!=null&&y.recapture&&r.id&&M){console.log("[EditScenario] ========== DIRECT CAPTURE START =========="),console.log("[EditScenario] Taking screenshot from running server",{scenarioId:r.id,projectId:n.projectId,serverUrl:M}),u("Changes saved. Capturing screenshot...");const R={serverUrl:M,scenarioId:r.id,projectId:n.projectId,viewportWidth:1440};console.log("[EditScenario] Capture request body:",R);const $=await fetch("/api/capture-screenshot",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)});console.log("[EditScenario] Capture response status:",$.status);const O=await $.json();if(console.log("[EditScenario] Capture response body:",O),!$.ok||!O.success)throw console.error("[EditScenario] Capture failed:",O),new Error(O.error||"Failed to capture screenshot");console.log("[EditScenario] Screenshot captured successfully:",O),console.log("[EditScenario] ========== DIRECT CAPTURE COMPLETE =========="),u("Recapture successful")}else if(y!=null&&y.recapture&&!M){console.log("[EditScenario] No running server, using queued recapture");const R=new FormData;R.append("analysisId",n.id||""),R.append("scenarioId",r.id||"");const $=await fetch("/api/recapture-scenario",{method:"POST",body:R}),O=await $.json();if(!$.ok||!O.success)throw new Error(O.error||"Failed to trigger recapture");console.log("Recapture queued:",O),I(O.jobId),u("Changes saved. Screenshot recapture queued.")}else u("Changes saved successfully.")}catch(D){console.error("Error saving scenarios:",D),u(`Error: ${D instanceof Error?D.message:String(D)}`)}finally{k(!1)}},[n,r.id,M]),m=l.useCallback(P=>{},[]),S=l.useCallback(async(P,y)=>{var B;const D=await fetch("/api/generate-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:P,existingScenarios:n.scenarios,scenariosDataStructure:(B=n.metadata)==null?void 0:B.scenariosDataStructure,editingMockName:r.name,editingMockData:y==null?void 0:y.data})}),T=await D.json();if(!D.ok||!T.success)throw new Error(T.error||"Failed to generate scenario data");return T.data},[n,r.name]),C=l.useCallback(async()=>{var P;if(!r.id){N("Cannot delete scenario without ID");return}x(!0),N(null);try{const y=await fetch("/api/delete-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:r.id,screenshotPaths:((P=r.metadata)==null?void 0:P.screenshotPaths)||[]})}),D=await y.json();if(!y.ok||!D.success)throw new Error(D.error||"Failed to delete scenario");p(`/entity/${d}`)}catch(y){console.error("[EditScenario] Error deleting scenario:",y),N(y instanceof Error?y.message:"Failed to delete scenario"),v(!1)}finally{x(!1)}},[r.id,(E=r.metadata)==null?void 0:E.screenshotPaths,d,p]);return e.jsxs("div",{className:"h-screen bg-gray-50 flex flex-col",children:[e.jsxs("header",{className:"bg-white border-b border-gray-200 px-8 py-6 shrink-0",children:[e.jsx("div",{className:"mb-4",children:e.jsxs(z,{to:`/entity/${d}`,className:"text-blue-600 no-underline text-sm font-medium transition-colors hover:text-blue-700 hover:underline",children:["← Back to ",(_=n.entity)==null?void 0:_.name]})}),e.jsxs("h1",{className:"text-[32px] font-bold text-gray-900 m-0 mb-3",children:["Edit Scenario: ",r.name]}),r.description&&e.jsx("p",{className:"text-gray-600 text-[15px] leading-relaxed m-0",children:r.description})]}),e.jsxs("div",{className:"flex flex-1 gap-0 min-h-0",children:[e.jsxs("aside",{className:"w-[400px] bg-white border-r border-gray-200 overflow-y-auto shrink-0",children:[e.jsx(ge,{currentScenario:r,defaultScenario:s,dataStructure:((G=n.metadata)==null?void 0:G.scenariosDataStructure)||{},analysis:n,shouldCreateNewScenario:!1,onSave:f,onNavigate:m,iframeRef:c,onGenerateData:S,saveFeedback:{isSaving:j,message:g,isError:(g==null?void 0:g.startsWith("Error"))??!1}}),g==="Recapture successful"&&e.jsx("div",{className:"px-4 pb-4",children:e.jsx(z,{to:`/entity/${d}`,className:"text-blue-600 hover:text-blue-700 hover:underline text-sm",children:"View updated screenshot on entity page →"})}),e.jsxs("div",{className:"border-t border-gray-200 p-4 mt-4",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-3",children:"Permanently remove this scenario and its screenshots."}),b?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-sm text-red-600 font-medium",children:['Are you sure you want to delete "',r.name,'"?']}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>void C(),disabled:w,className:"flex-1 px-4 py-2 bg-red-600 text-white rounded-md text-sm font-medium hover:bg-red-700 disabled:bg-red-400 disabled:cursor-not-allowed transition-colors",children:w?"Deleting...":"Yes, Delete"}),e.jsx("button",{onClick:()=>v(!1),disabled:w,className:"flex-1 px-4 py-2 bg-gray-100 text-gray-700 border border-gray-300 rounded-md text-sm font-medium hover:bg-gray-200 disabled:opacity-50 transition-colors",children:"Cancel"})]})]}):e.jsx("button",{onClick:()=>v(!0),className:"w-full px-4 py-2 bg-red-50 text-red-600 border border-red-200 rounded-md text-sm font-medium hover:bg-red-100 transition-colors",children:"Delete Scenario"}),L&&e.jsx("div",{className:"mt-3 text-sm text-red-600 bg-red-50 px-3 py-2 rounded-md",children:L})]})]}),e.jsx("main",{className:"flex-1 bg-gray-100 overflow-auto flex flex-col min-w-0",children:e.jsx(ee,{scenarioId:r.id||r.name,scenarioName:r.name,iframeUrl:M,isStarting:W,isLoading:J,showIframe:i,iframeKey:a,onIframeLoad:h,projectSlug:o,defaultWidth:1440,defaultHeight:900})})]})]})}const ve=Y(function(){return e.jsx(X,{children:e.jsx(he,{})})});export{ve as default,Ne as meta};
|